@pusher/push-notifications-web
Advanced tools
Comparing version 0.11.0 to 0.12.0
{ | ||
"name": "@pusher/push-notifications-web", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"description": "", | ||
"main": "dist/push-notifications-esm.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "build:esm": "rollup -c ./rollup/esm.js", |
@@ -38,2 +38,8 @@ import doRequest from './do-request'; | ||
if (!window.isSecureContext) { | ||
throw new Error( | ||
'Pusher Beams relies on Service Workers, which only work in secure contexts. Check that your page is being served from localhost/over HTTPS' | ||
); | ||
} | ||
if (!('serviceWorker' in navigator)) { | ||
@@ -136,2 +142,10 @@ throw new Error( | ||
_throwIfNotStarted(message) { | ||
if (!this.deviceId) { | ||
throw new Error( | ||
`${message}. SDK not registered with Beams. Did you call .start?` | ||
); | ||
} | ||
} | ||
async start() { | ||
@@ -167,2 +181,3 @@ if (!isSupportedBrowser()) { | ||
async addDeviceInterest(interest) { | ||
this._throwIfNotStarted('Could not add Device Interest'); | ||
validateInterestName(interest); | ||
@@ -181,2 +196,3 @@ | ||
async removeDeviceInterest(interest) { | ||
this._throwIfNotStarted('Could not remove Device Interest'); | ||
validateInterestName(interest); | ||
@@ -195,2 +211,4 @@ | ||
async getDeviceInterests() { | ||
this._throwIfNotStarted('Could not get Device Interests'); | ||
const path = `${this._baseURL}/device_api/v1/instances/${encodeURIComponent( | ||
@@ -207,2 +225,4 @@ this.instanceId | ||
async setDeviceInterests(interests) { | ||
this._throwIfNotStarted('Could not set Device Interests'); | ||
if (interests === undefined || interests === null) { | ||
@@ -240,2 +260,3 @@ throw new Error('interests argument is required'); | ||
async clearDeviceInterests() { | ||
this._throwIfNotStarted('Could not clear Device Interests'); | ||
await this.setDeviceInterests([]); | ||
@@ -461,13 +482,13 @@ } | ||
const isOpera = winNav.userAgent.indexOf('OPR') > -1; | ||
const isIEedge = winNav.userAgent.indexOf('Edg') > -1; | ||
const isEdge = winNav.userAgent.indexOf('Edg') > -1; | ||
const isFirefox = winNav.userAgent.indexOf('Firefox') > -1; | ||
const isChrome = | ||
isChromium && vendorName === 'Google Inc.' && !isIEedge && !isOpera; | ||
isChromium && vendorName === 'Google Inc.' && !isEdge && !isOpera; | ||
const isSupported = isChrome || isOpera || isFirefox; | ||
const isSupported = isChrome || isOpera || isFirefox || isEdge; | ||
if (!isSupported) { | ||
console.warn( | ||
'Whilst in Beta, Pusher Web Push Notifications only supports Chrome, Firefox and Opera.' | ||
'Whilst in Beta, Pusher Web Push Notifications supports Chrome, Firefox, Edge and Opera.' | ||
); | ||
@@ -474,0 +495,0 @@ } |
@@ -50,2 +50,10 @@ import * as PusherPushNotifications from './push-notifications'; | ||
test('will throw if the SDK is loaded from a context that is not secure', () => { | ||
setUpGlobals({ isSecureContext: false }); | ||
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f'; | ||
return expect(PusherPushNotifications.init({ instanceId })).rejects.toThrow( | ||
'Pusher Beams relies on Service Workers, which only work in secure contexts' | ||
); | ||
}); | ||
test('will throw if ServiceWorkerRegistration not supported', () => { | ||
@@ -182,2 +190,19 @@ setUpGlobals({ serviceWorkerSupport: false }); | ||
}); | ||
test('should fail if SDK is not started', () => { | ||
// Emulate a fresh SDK, where start has not been called | ||
devicestatestore.default = makeDeviceStateStore({ | ||
deviceId: null, | ||
token: null, | ||
userId: null, | ||
}); | ||
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f'; | ||
const interest = 'some-interest'; | ||
return expect( | ||
PusherPushNotifications.init({ | ||
instanceId, | ||
}).then(beamsClient => beamsClient.addDeviceInterest(interest)) | ||
).rejects.toThrow('SDK not registered with Beams. Did you call .start?'); | ||
}); | ||
}); | ||
@@ -255,2 +280,19 @@ | ||
}); | ||
test('should fail if SDK is not started', () => { | ||
// Emulate a fresh SDK, where start has not been called | ||
devicestatestore.default = makeDeviceStateStore({ | ||
deviceId: null, | ||
token: null, | ||
userId: null, | ||
}); | ||
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f'; | ||
const interest = 'some-interest'; | ||
return expect( | ||
PusherPushNotifications.init({ | ||
instanceId, | ||
}).then(beamsClient => beamsClient.removeDeviceInterest(interest)) | ||
).rejects.toThrow('SDK not registered with Beams. Did you call .start?'); | ||
}); | ||
}); | ||
@@ -291,2 +333,18 @@ | ||
}); | ||
test('should fail if SDK is not started', () => { | ||
// Emulate a fresh SDK, where start has not been called | ||
devicestatestore.default = makeDeviceStateStore({ | ||
deviceId: null, | ||
token: null, | ||
userId: null, | ||
}); | ||
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f'; | ||
return expect( | ||
PusherPushNotifications.init({ | ||
instanceId, | ||
}).then(beamsClient => beamsClient.getDeviceInterests()) | ||
).rejects.toThrow('SDK not registered with Beams. Did you call .start?'); | ||
}); | ||
}); | ||
@@ -433,2 +491,18 @@ | ||
}); | ||
test('should fail if SDK is not started', () => { | ||
// Emulate a fresh SDK, where start has not been called | ||
devicestatestore.default = makeDeviceStateStore({ | ||
deviceId: null, | ||
token: null, | ||
userId: null, | ||
}); | ||
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f'; | ||
return expect( | ||
PusherPushNotifications.init({ | ||
instanceId, | ||
}).then(beamsClient => beamsClient.setDeviceInterests([])) | ||
).rejects.toThrow('SDK not registered with Beams. Did you call .start?'); | ||
}); | ||
}); | ||
@@ -464,2 +538,18 @@ | ||
}); | ||
test('should fail if SDK is not started', () => { | ||
// Emulate a fresh SDK, where start has not been called | ||
devicestatestore.default = makeDeviceStateStore({ | ||
deviceId: null, | ||
token: null, | ||
userId: null, | ||
}); | ||
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f'; | ||
return expect( | ||
PusherPushNotifications.init({ | ||
instanceId, | ||
}).then(beamsClient => beamsClient.clearDeviceInterests()) | ||
).rejects.toThrow('SDK not registered with Beams. Did you call .start?'); | ||
}); | ||
}); | ||
@@ -472,2 +562,3 @@ }); | ||
webPushSupport = true, | ||
isSecureContext = true, | ||
}) => { | ||
@@ -489,2 +580,3 @@ if (indexedDBSupport) { | ||
} | ||
global.window.isSecureContext = isSecureContext; | ||
}; | ||
@@ -491,0 +583,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
269548
34
7150
10