@pusher/push-notifications-web
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -10,2 +10,6 @@ # Changelog | ||
## [1.0.2](https://github.com/pusher/push-notifications-web/compare/1.0.1...1.0.2) - 2020-08-24 | ||
- Fix bug in service worker where analytics events would cause runtime errors | ||
if a notification had been overridden using the `onNotificationReceived` handler | ||
## [1.0.1](https://github.com/pusher/push-notifications-web/compare/1.0.0...1.0.1) - 2020-07-22 | ||
@@ -16,3 +20,2 @@ - Fix bug in service worker which generated invalid open/delivery events due to | ||
## [1.0.0](https://github.com/pusher/push-notifications-web/compare/0.9.0...1.0.0) - 2020-07-22 | ||
- General availability (GA) release. |
@@ -0,1 +1,4 @@ | ||
// SDK version: v1.0.1 | ||
// Git commit: c3858ad495ef22fd72fb543f4be65412b4f5ff23 | ||
'use strict'; | ||
@@ -1233,6 +1236,10 @@ | ||
eventType = _ref.eventType, pusherMetadata = _ref.pusherMetadata; | ||
console.log('reporting', { | ||
eventType: eventType, | ||
pusherMetadata: pusherMetadata | ||
}); | ||
instanceId = pusherMetadata.instanceId, publishId = pusherMetadata.publishId, hasDisplayableContent = pusherMetadata.hasDisplayableContent, hasData = pusherMetadata.hasData; | ||
if (!(!instanceId || !publishId)) { | ||
_context.next = 4; | ||
_context.next = 5; | ||
break; | ||
@@ -1243,21 +1250,21 @@ } | ||
case 4: | ||
case 5: | ||
deviceStateStore = new DeviceStateStore(instanceId); | ||
_context.next = 7; | ||
_context.next = 8; | ||
return deviceStateStore.connect(); | ||
case 7: | ||
_context.next = 9; | ||
case 8: | ||
_context.next = 10; | ||
return deviceStateStore.getDeviceId(); | ||
case 9: | ||
case 10: | ||
deviceId = _context.sent; | ||
_context.next = 12; | ||
_context.next = 13; | ||
return deviceStateStore.getUserId(); | ||
case 12: | ||
case 13: | ||
_context.t0 = _context.sent; | ||
if (_context.t0) { | ||
_context.next = 15; | ||
_context.next = 16; | ||
break; | ||
@@ -1268,8 +1275,8 @@ } | ||
case 15: | ||
case 16: | ||
userId = _context.t0; | ||
_context.next = 18; | ||
_context.next = 19; | ||
return self.PusherPushNotifications._hasVisibleClient(); | ||
case 18: | ||
case 19: | ||
appInBackground = !_context.sent; | ||
@@ -1291,15 +1298,15 @@ path = "".concat(self.PusherPushNotifications._endpoint(instanceId), "/reporting_api/v2/instances/").concat(instanceId, "/events"); | ||
}; | ||
_context.prev = 21; | ||
_context.next = 24; | ||
_context.prev = 22; | ||
_context.next = 25; | ||
return doRequest(options); | ||
case 24: | ||
_context.next = 28; | ||
case 25: | ||
_context.next = 29; | ||
break; | ||
case 26: | ||
_context.prev = 26; | ||
_context.t1 = _context["catch"](21); | ||
case 27: | ||
_context.prev = 27; | ||
_context.t1 = _context["catch"](22); | ||
case 28: | ||
case 29: | ||
case "end": | ||
@@ -1309,3 +1316,3 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[21, 26]]); | ||
}, _callee, null, [[22, 27]]); | ||
})); | ||
@@ -1348,2 +1355,3 @@ | ||
customerPayload.data = customerData; | ||
var pusherMetadata = payload.data.pusher; | ||
@@ -1355,3 +1363,3 @@ var handleNotification = | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee2(payload) { | ||
regenerator.mark(function _callee2(payloadFromCallback) { | ||
var hideNotificationIfSiteHasFocus, title, body, icon, options; | ||
@@ -1362,3 +1370,3 @@ return regenerator.wrap(function _callee2$(_context2) { | ||
case 0: | ||
hideNotificationIfSiteHasFocus = payload.notification.hide_notification_if_site_has_focus === true; | ||
hideNotificationIfSiteHasFocus = payloadFromCallback.notification.hide_notification_if_site_has_focus === true; | ||
_context2.t0 = hideNotificationIfSiteHasFocus; | ||
@@ -1386,5 +1394,5 @@ | ||
case 8: | ||
title = payload.notification.title || ''; | ||
body = payload.notification.body || ''; | ||
icon = payload.notification.icon; | ||
title = payloadFromCallback.notification.title || ''; | ||
body = payloadFromCallback.notification.body || ''; | ||
icon = payloadFromCallback.notification.icon; | ||
options = { | ||
@@ -1394,3 +1402,6 @@ body: body, | ||
data: { | ||
pusherPayload: payload | ||
pusher: { | ||
customerPayload: payloadFromCallback, | ||
pusherMetadata: pusherMetadata | ||
} | ||
} | ||
@@ -1420,8 +1431,8 @@ }; | ||
} else { | ||
e.waitUntil(handleNotification(payload)); | ||
e.waitUntil(handleNotification(customerPayload)); | ||
} | ||
}); | ||
self.addEventListener('notificationclick', function (e) { | ||
var payload = e.notification.data.pusherPayload; | ||
var isPusherNotification = payload !== undefined; | ||
var pusher = e.notification.data.pusher; | ||
var isPusherNotification = pusher !== undefined; | ||
@@ -1432,7 +1443,7 @@ if (isPusherNotification) { | ||
eventType: 'open', | ||
pusherMetadata: payload.data.pusher | ||
pusherMetadata: pusher.pusherMetadata | ||
}); | ||
if (payload.notification.deep_link) { | ||
e.waitUntil(clients.openWindow(payload.notification.deep_link)); | ||
if (pusher.customerPayload.notification.deep_link) { | ||
e.waitUntil(clients.openWindow(pusher.customerPayload.notification.deep_link)); | ||
} | ||
@@ -1439,0 +1450,0 @@ |
{ | ||
"name": "@pusher/push-notifications-web", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -10,3 +10,3 @@ "main": "dist/push-notifications-esm.js", | ||
"build:cdn": "rollup -c ./rollup/cdn.js", | ||
"build:sw": "rollup -c ./rollup/service-worker.js", | ||
"build:sw": "rollup -c ./rollup/service-worker.js && node ./scripts/add-version-to-service-worker.js", | ||
"format": "prettier ./src/**/*.js --write", | ||
@@ -13,0 +13,0 @@ "lint": "eslint ./src/**/*.js && prettier ./src/**/*.js -l", |
@@ -9,2 +9,3 @@ # Release Process | ||
7. `git tag <VERSION e.g. 1.2.3>` | ||
8. `git push` | ||
8. `git push --tags` | ||
@@ -11,0 +12,0 @@ 9. `npm run publish-please` |
@@ -114,5 +114,8 @@ /* eslint-env serviceworker */ | ||
const handleNotification = async payload => { | ||
const pusherMetadata = payload.data.pusher; | ||
const handleNotification = async payloadFromCallback => { | ||
const hideNotificationIfSiteHasFocus = | ||
payload.notification.hide_notification_if_site_has_focus === true; | ||
payloadFromCallback.notification.hide_notification_if_site_has_focus === | ||
true; | ||
if ( | ||
@@ -125,5 +128,5 @@ hideNotificationIfSiteHasFocus && | ||
const title = payload.notification.title || ''; | ||
const body = payload.notification.body || ''; | ||
const icon = payload.notification.icon; | ||
const title = payloadFromCallback.notification.title || ''; | ||
const body = payloadFromCallback.notification.body || ''; | ||
const icon = payloadFromCallback.notification.icon; | ||
@@ -133,3 +136,8 @@ const options = { | ||
icon, | ||
data: { pusherPayload: payload }, | ||
data: { | ||
pusher: { | ||
customerPayload: payloadFromCallback, | ||
pusherMetadata, | ||
}, | ||
}, | ||
}; | ||
@@ -147,3 +155,3 @@ | ||
} else { | ||
e.waitUntil(handleNotification(payload)); | ||
e.waitUntil(handleNotification(customerPayload)); | ||
} | ||
@@ -153,5 +161,5 @@ }); | ||
self.addEventListener('notificationclick', e => { | ||
const { pusherPayload: payload } = e.notification.data; | ||
const { pusher } = e.notification.data; | ||
const isPusherNotification = payload !== undefined; | ||
const isPusherNotification = pusher !== undefined; | ||
if (isPusherNotification) { | ||
@@ -161,7 +169,9 @@ // Report analytics event, best effort | ||
eventType: 'open', | ||
pusherMetadata: payload.data.pusher, | ||
pusherMetadata: pusher.pusherMetadata, | ||
}); | ||
if (payload.notification.deep_link) { | ||
e.waitUntil(clients.openWindow(payload.notification.deep_link)); | ||
if (pusher.customerPayload.notification.deep_link) { | ||
e.waitUntil( | ||
clients.openWindow(pusher.customerPayload.notification.deep_link) | ||
); | ||
} | ||
@@ -168,0 +178,0 @@ e.notification.close(); |
@@ -108,16 +108,17 @@ import { makeDeviceStateStore } from '../test-utils/fake-device-state-store'; | ||
data: { | ||
pusherPayload: { | ||
notification: { | ||
title: TEST_NOTIFICATION_TITLE, | ||
body: TEST_NOTIFICATION_BODY, | ||
icon: TEST_NOTIFICATION_ICON, | ||
}, | ||
data: { | ||
pusher: { | ||
instanceId: TEST_INSTANCE_ID, | ||
publishId: TEST_PUBLISH_ID, | ||
hasDisplayableContent: true, | ||
hasData: false, | ||
pusher: { | ||
customerPayload: { | ||
notification: { | ||
title: TEST_NOTIFICATION_TITLE, | ||
body: TEST_NOTIFICATION_BODY, | ||
icon: TEST_NOTIFICATION_ICON, | ||
}, | ||
data: {}, | ||
}, | ||
pusherMetadata: { | ||
instanceId: TEST_INSTANCE_ID, | ||
publishId: TEST_PUBLISH_ID, | ||
hasDisplayableContent: true, | ||
hasData: false, | ||
}, | ||
}, | ||
@@ -219,3 +220,28 @@ }, | ||
const notification = shownNotifications[0]; | ||
expect(notification.options.body).toEqual('Body has been changed'); | ||
expect(notification).toEqual({ | ||
title: TEST_NOTIFICATION_TITLE, | ||
options: { | ||
icon: TEST_NOTIFICATION_ICON, | ||
body: 'Body has been changed', // Notification body should have changed | ||
data: { | ||
pusher: { | ||
customerPayload: { | ||
notification: { | ||
title: TEST_NOTIFICATION_TITLE, | ||
body: 'Body has been changed', // Here too | ||
icon: TEST_NOTIFICATION_ICON, | ||
}, | ||
data: {}, // Pusher metadata has been stripped | ||
}, | ||
pusherMetadata: { | ||
// But still embedded in the notification, out of band | ||
instanceId: TEST_INSTANCE_ID, | ||
publishId: TEST_PUBLISH_ID, | ||
hasDisplayableContent: true, | ||
hasData: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
@@ -229,13 +255,17 @@ | ||
data: { | ||
pusherPayload: { | ||
notification: { | ||
title: 'Hi!', | ||
body: 'This is a notification!', | ||
deep_link: 'https://pusher.com', | ||
}, | ||
data: { | ||
pusher: { | ||
publishId: 'some-publish-id', | ||
pusher: { | ||
customerPayload: { | ||
notification: { | ||
title: 'Hi!', | ||
body: 'This is a notification!', | ||
deep_link: 'https://pusher.com', | ||
}, | ||
data: {}, | ||
}, | ||
pusherMetadata: { | ||
instanceId: TEST_INSTANCE_ID, | ||
publishId: TEST_PUBLISH_ID, | ||
hasDisplayableContent: true, | ||
hasData: false, | ||
}, | ||
}, | ||
@@ -401,16 +431,17 @@ }, | ||
data: { | ||
pusherPayload: { | ||
notification: { | ||
title: 'Hi!', | ||
body: 'This is a notification!', | ||
deep_link: 'https://pusher.com', | ||
}, | ||
data: { | ||
pusher: { | ||
instanceId: TEST_INSTANCE_ID, | ||
publishId: TEST_PUBLISH_ID, | ||
hasDisplayableContent: true, | ||
hasData: false, | ||
pusher: { | ||
customerPayload: { | ||
notification: { | ||
title: 'Hi!', | ||
body: 'This is a notification!', | ||
deep_link: 'https://pusher.com', | ||
}, | ||
data: {}, | ||
}, | ||
pusherMetadata: { | ||
instanceId: TEST_INSTANCE_ID, | ||
publishId: TEST_PUBLISH_ID, | ||
hasDisplayableContent: true, | ||
hasData: false, | ||
}, | ||
}, | ||
@@ -417,0 +448,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
339780
40
9186
7
14