Skip to content

Commit

Permalink
chore: renamed notification payload property
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Jul 20, 2023
1 parent 5c9ecaf commit 6b09d58
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The `create` method is used to send web push notifications. The `data` payload m

| Property | Description | Required |
|---|---|---|
|`dataNotification` | The payload text for the push notification. | yes |
|`notification` | The data payload for the push notification. | yes |
| `subscriptionService` | The name of the service where subscriptions are registered. | yes |
| `subscriptionProperty` | The name of the key where subscriptions are regitered. It can be an array of subscriptions or a single subscription object | yes |
| `subscriptionFilter` | The filter you wish to apply when retrieving subscriptions. | no |
Expand Down
4 changes: 2 additions & 2 deletions example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ window.unsubscribe = async () => {
}
window.sendNotification = async () => {
// Setup notification params
const dataNotification = {
const notification = {
title: 'feathers-webpush example title',
body: 'feathers-webpush example body',
icon: 'https://s3.eu-central-1.amazonaws.com/kalisioscope/kalisio/kalisio-icon-256x256.png',
url: 'https://kalisio.com/'
}
// Send webpush notification
api.service('push').create({
dataNotification: dataNotification,
notification,
subscriptionService: 'users',
subscriptionProperty: 'subscriptions'
})
Expand Down
9 changes: 5 additions & 4 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ export class Service {

async create (data, params) {
// check required data object
if (!data.dataNotification) throw new BadRequest('feathers-webpush:create: expected missing \'data.dataNotification\' parameter')
if (!data.notification) throw new BadRequest('feathers-webpush:create: expected missing \'data.notification\' parameter')
if (!data.subscriptionService) throw new BadRequest('feathers-webpush:create: expected missing \'data.subscriptionService\' parameter')
if (!data.subscriptionProperty) throw new BadRequest('feathers-webpush:create: expected missing \'data.subscriptionProperty\' parameter')
debug(`method 'create' called with 'dataNotification': ${data.dataNotification}, 'subscriptionService': ${data.subscriptionService}, 'subscriptionFilter': ${data.subscriptionFilter} and 'subscriptionProperty': ${data.subscriptionProperty}`)
debug(`method 'create' called with subscription service ${data.subscriptionService}, subscription property ${data.subscriptionProperty} and subscription filter:`, data.subscriptionFilter)
debug(`method 'create' called with notification payload:`, data.notification)

// Set data
let { dataNotification, subscriptionService, subscriptionProperty, subscriptionFilter = {} } = data
let { notification, subscriptionService, subscriptionProperty, subscriptionFilter = {} } = data
_.isEmpty(subscriptionFilter) ? subscriptionFilter = { paginate: false } : subscriptionFilter = { paginate: false, query: subscriptionFilter }

// Retrieve and filter subscriptions service from specified service
Expand All @@ -60,7 +61,7 @@ export class Service {
if (!subscription.keys.p256dh) throw new BadRequest('feathers-webpush:create: expected missing \'subscription.keys.p256dh\' parameter')
// Send webpush notification
try {
const response = await webpush.sendNotification(subscription, JSON.stringify(dataNotification))
const response = await webpush.sendNotification(subscription, JSON.stringify(notification))
debug('webpush notification send:', subscription.endpoint)
webpushNotificationSend.succesful.push(response)
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('feathers-webpush:service', () => {
})
it('send webpush notifications', async () => {
const response = await service.create({
dataNotification: { title: 'title' },
notification: { title: 'title' },
subscriptionService: 'users',
subscriptionProperty: 'subscriptions'
})
Expand Down

0 comments on commit 6b09d58

Please sign in to comment.