@magicbell/webpush
Advanced tools
Comparing version 1.3.0 to 1.3.1
/** | ||
* @license @magicbell/webpush v1.3.0 | ||
* @license @magicbell/webpush v1.3.1 | ||
* | ||
@@ -4,0 +4,0 @@ * Copyright (c) MagicBell Inc. and its affiliates. |
/** | ||
* @license @magicbell/webpush v1.3.0 | ||
* @license @magicbell/webpush v1.3.1 | ||
* | ||
@@ -105,3 +105,6 @@ * Copyright (c) MagicBell Inc. and its affiliates. | ||
const subscriptions = await api.getSubscriptions(__spreadProps(__spreadValues({}, options), { baseURL })); | ||
const currentPushSubscriptionEndpoint = await ((_a = navigator.serviceWorker) == null ? void 0 : _a.ready.then((sw) => sw.pushManager.getSubscription()).then((x) => x == null ? void 0 : x.endpoint)); | ||
const currentPushSubscriptionEndpoint = await ((_a = navigator.serviceWorker) == null ? void 0 : _a.ready.then((sw) => { | ||
var _a2; | ||
return (_a2 = sw.pushManager) == null ? void 0 : _a2.getSubscription(); | ||
}).then((x) => x == null ? void 0 : x.endpoint)); | ||
return Boolean(currentPushSubscriptionEndpoint) && subscriptions.some((subscription) => subscription.device_token === currentPushSubscriptionEndpoint); | ||
@@ -108,0 +111,0 @@ } |
/** | ||
* @license @magicbell/webpush v1.3.0 | ||
* @license @magicbell/webpush v1.3.1 | ||
* | ||
@@ -10,3 +10,3 @@ * Copyright (c) MagicBell Inc. and its affiliates. | ||
"use strict";var w=Object.defineProperty,y=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var b=(e,i,t)=>i in e?w(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t,o=(e,i)=>{for(var t in i||(i={}))v.call(i,t)&&b(e,t,i[t]);if(h)for(var t of h(i))S.call(i,t)&&b(e,t,i[t]);return e},a=(e,i)=>y(e,_(i));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});let c=null,g="";const u={async getConfig({token:e,project:i,baseURL:t}){const n=[e,i,t].join("-");return c&&g===n?c:fetch(`${t}/web_push_subscriptions?access_token=${e}&project=${i}`,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"}}).then(r=>r.json()).then(r=>(c=r.push_subscription,g=n,c))},async getSubscriptions({token:e,project:i,baseURL:t}){const n=await this.getConfig({token:e,project:i,baseURL:t});if(!n.project.api_key)throw new Error("Missing API key");const r={accept:"application/json","content-type":"application/json","x-magicbell-api-key":n.project.api_key};return n.user.email?r["x-magicbell-user-email"]=n.user.email:n.user.external_id&&(r["x-magicbell-user-external-id"]=n.user.external_id),n.user.hmac&&(r["x-magicbell-user-hmac"]=n.user.hmac),fetch(`${t}/push_subscriptions`,{method:"GET",headers:r}).then(s=>s.json()).then(s=>(s==null?void 0:s.push_subscriptions)||[])},async updateSubscription({token:e,project:i,baseURL:t},n){return fetch(`${t}/web_push_subscriptions?access_token=${e}&project=${i}`,{method:"POST",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({web_push_subscription:{data:n}})}).then(r=>r.json()).then(r=>r.web_push_subscription)}};function d(){return typeof window>"u"||typeof navigator>"u"?!1:"PushManager"in window&&"serviceWorker"in navigator}async function j(e){await u.getConfig(a(o({},e),{baseURL:e.host||location.origin}))}async function l({path:e="/sw.js"}={}){return navigator.serviceWorker.controller||await navigator.serviceWorker.register(e),navigator.serviceWorker.ready}async function k(e){var r;const i=e.host||location.origin,t=await u.getSubscriptions(a(o({},e),{baseURL:i})),n=await((r=navigator.serviceWorker)==null?void 0:r.ready.then(s=>s.pushManager.getSubscription()).then(s=>s==null?void 0:s.endpoint));return Boolean(n)&&t.some(s=>s.device_token===n)}async function m(e){if(!d())throw new Error("Push notifications are not supported in this browser");const i=e.host||location.origin,t=await u.getConfig(a(o({},e),{baseURL:i})),n=await l({path:e.serviceWorkerPath}),r=await n.pushManager.getSubscription();r&&await r.unsubscribe().catch(()=>{});const s=t.project.vapid_public_key.replace(/=/g,""),p=await n.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:s}).then(f=>f.toJSON());if(!("endpoint"in p))throw new Error("Failed to subscribe to push notifications, browser did not return an subscription endpoint.");await u.updateSubscription(a(o({},e),{baseURL:i}),p)}exports.isSubscribed=k;exports.isSupported=d;exports.prefetchConfig=j;exports.registerServiceWorker=l;exports.subscribe=m; | ||
"use strict";var w=Object.defineProperty,y=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var b=(e,i,t)=>i in e?w(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t,a=(e,i)=>{for(var t in i||(i={}))v.call(i,t)&&b(e,t,i[t]);if(h)for(var t of h(i))S.call(i,t)&&b(e,t,i[t]);return e},c=(e,i)=>y(e,_(i));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});let u=null,g="";const p={async getConfig({token:e,project:i,baseURL:t}){const n=[e,i,t].join("-");return u&&g===n?u:fetch(`${t}/web_push_subscriptions?access_token=${e}&project=${i}`,{method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"}}).then(r=>r.json()).then(r=>(u=r.push_subscription,g=n,u))},async getSubscriptions({token:e,project:i,baseURL:t}){const n=await this.getConfig({token:e,project:i,baseURL:t});if(!n.project.api_key)throw new Error("Missing API key");const r={accept:"application/json","content-type":"application/json","x-magicbell-api-key":n.project.api_key};return n.user.email?r["x-magicbell-user-email"]=n.user.email:n.user.external_id&&(r["x-magicbell-user-external-id"]=n.user.external_id),n.user.hmac&&(r["x-magicbell-user-hmac"]=n.user.hmac),fetch(`${t}/push_subscriptions`,{method:"GET",headers:r}).then(s=>s.json()).then(s=>(s==null?void 0:s.push_subscriptions)||[])},async updateSubscription({token:e,project:i,baseURL:t},n){return fetch(`${t}/web_push_subscriptions?access_token=${e}&project=${i}`,{method:"POST",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({web_push_subscription:{data:n}})}).then(r=>r.json()).then(r=>r.web_push_subscription)}};function d(){return typeof window>"u"||typeof navigator>"u"?!1:"PushManager"in window&&"serviceWorker"in navigator}async function j(e){await p.getConfig(c(a({},e),{baseURL:e.host||location.origin}))}async function l({path:e="/sw.js"}={}){return navigator.serviceWorker.controller||await navigator.serviceWorker.register(e),navigator.serviceWorker.ready}async function k(e){var r;const i=e.host||location.origin,t=await p.getSubscriptions(c(a({},e),{baseURL:i})),n=await((r=navigator.serviceWorker)==null?void 0:r.ready.then(s=>{var o;return(o=s.pushManager)==null?void 0:o.getSubscription()}).then(s=>s==null?void 0:s.endpoint));return Boolean(n)&&t.some(s=>s.device_token===n)}async function m(e){if(!d())throw new Error("Push notifications are not supported in this browser");const i=e.host||location.origin,t=await p.getConfig(c(a({},e),{baseURL:i})),n=await l({path:e.serviceWorkerPath}),r=await n.pushManager.getSubscription();r&&await r.unsubscribe().catch(()=>{});const s=t.project.vapid_public_key.replace(/=/g,""),o=await n.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:s}).then(f=>f.toJSON());if(!("endpoint"in o))throw new Error("Failed to subscribe to push notifications, browser did not return an subscription endpoint.");await p.updateSubscription(c(a({},e),{baseURL:i}),o)}exports.isSubscribed=k;exports.isSupported=d;exports.prefetchConfig=j;exports.registerServiceWorker=l;exports.subscribe=m; | ||
//# sourceMappingURL=magicbell-webpush.cjs.min.js.map |
/** | ||
* @license @magicbell/webpush v1.3.0 | ||
* @license @magicbell/webpush v1.3.1 | ||
* | ||
@@ -103,3 +103,6 @@ * Copyright (c) MagicBell Inc. and its affiliates. | ||
const subscriptions = await api.getSubscriptions(__spreadProps(__spreadValues({}, options), { baseURL })); | ||
const currentPushSubscriptionEndpoint = await ((_a = navigator.serviceWorker) == null ? void 0 : _a.ready.then((sw) => sw.pushManager.getSubscription()).then((x) => x == null ? void 0 : x.endpoint)); | ||
const currentPushSubscriptionEndpoint = await ((_a = navigator.serviceWorker) == null ? void 0 : _a.ready.then((sw) => { | ||
var _a2; | ||
return (_a2 = sw.pushManager) == null ? void 0 : _a2.getSubscription(); | ||
}).then((x) => x == null ? void 0 : x.endpoint)); | ||
return Boolean(currentPushSubscriptionEndpoint) && subscriptions.some((subscription) => subscription.device_token === currentPushSubscriptionEndpoint); | ||
@@ -106,0 +109,0 @@ } |
/** | ||
* @license @magicbell/webpush v1.3.0 | ||
* @license @magicbell/webpush v1.3.1 | ||
* | ||
@@ -14,3 +14,3 @@ * Copyright (c) MagicBell Inc. and its affiliates. | ||
var y = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable; | ||
var b = (e, i, n) => i in e ? f(e, i, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[i] = n, o = (e, i) => { | ||
var b = (e, i, n) => i in e ? f(e, i, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[i] = n, a = (e, i) => { | ||
for (var n in i || (i = {})) | ||
@@ -22,8 +22,8 @@ y.call(i, n) && b(e, n, i[n]); | ||
return e; | ||
}, a = (e, i) => l(e, w(i)); | ||
let c = null, g = ""; | ||
const p = { | ||
}, c = (e, i) => l(e, w(i)); | ||
let p = null, g = ""; | ||
const u = { | ||
async getConfig({ token: e, project: i, baseURL: n }) { | ||
const t = [e, i, n].join("-"); | ||
return c && g === t ? c : fetch(`${n}/web_push_subscriptions?access_token=${e}&project=${i}`, { | ||
return p && g === t ? p : fetch(`${n}/web_push_subscriptions?access_token=${e}&project=${i}`, { | ||
method: "GET", | ||
@@ -34,3 +34,3 @@ headers: { | ||
} | ||
}).then((r) => r.json()).then((r) => (c = r.push_subscription, g = t, c)); | ||
}).then((r) => r.json()).then((r) => (p = r.push_subscription, g = t, p)); | ||
}, | ||
@@ -70,3 +70,3 @@ async getSubscriptions({ token: e, project: i, baseURL: n }) { | ||
async function S(e) { | ||
await p.getConfig(a(o({}, e), { baseURL: e.host || location.origin })); | ||
await u.getConfig(c(a({}, e), { baseURL: e.host || location.origin })); | ||
} | ||
@@ -78,3 +78,6 @@ async function j({ path: e = "/sw.js" } = {}) { | ||
var r; | ||
const i = e.host || location.origin, n = await p.getSubscriptions(a(o({}, e), { baseURL: i })), t = await ((r = navigator.serviceWorker) == null ? void 0 : r.ready.then((s) => s.pushManager.getSubscription()).then((s) => s == null ? void 0 : s.endpoint)); | ||
const i = e.host || location.origin, n = await u.getSubscriptions(c(a({}, e), { baseURL: i })), t = await ((r = navigator.serviceWorker) == null ? void 0 : r.ready.then((s) => { | ||
var o; | ||
return (o = s.pushManager) == null ? void 0 : o.getSubscription(); | ||
}).then((s) => s == null ? void 0 : s.endpoint)); | ||
return Boolean(t) && n.some((s) => s.device_token === t); | ||
@@ -85,9 +88,9 @@ } | ||
throw new Error("Push notifications are not supported in this browser"); | ||
const i = e.host || location.origin, n = await p.getConfig(a(o({}, e), { baseURL: i })), t = await j({ path: e.serviceWorkerPath }), r = await t.pushManager.getSubscription(); | ||
const i = e.host || location.origin, n = await u.getConfig(c(a({}, e), { baseURL: i })), t = await j({ path: e.serviceWorkerPath }), r = await t.pushManager.getSubscription(); | ||
r && await r.unsubscribe().catch(() => { | ||
}); | ||
const s = n.project.vapid_public_key.replace(/=/g, ""), u = await t.pushManager.subscribe({ userVisibleOnly: !0, applicationServerKey: s }).then((d) => d.toJSON()); | ||
if (!("endpoint" in u)) | ||
const s = n.project.vapid_public_key.replace(/=/g, ""), o = await t.pushManager.subscribe({ userVisibleOnly: !0, applicationServerKey: s }).then((d) => d.toJSON()); | ||
if (!("endpoint" in o)) | ||
throw new Error("Failed to subscribe to push notifications, browser did not return an subscription endpoint."); | ||
await p.updateSubscription(a(o({}, e), { baseURL: i }), u); | ||
await u.updateSubscription(c(a({}, e), { baseURL: i }), o); | ||
} | ||
@@ -94,0 +97,0 @@ export { |
{ | ||
"name": "@magicbell/webpush", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "MagicBell WebPush SDK", | ||
@@ -5,0 +5,0 @@ "author": "MagicBell <bot@magicbell.io> (https://magicbell.com)", |
@@ -110,3 +110,3 @@ type RequestOptions = { | ||
const currentPushSubscriptionEndpoint = await navigator.serviceWorker?.ready | ||
.then((sw) => sw.pushManager.getSubscription()) | ||
.then((sw) => sw.pushManager?.getSubscription()) | ||
.then((x) => x?.endpoint); | ||
@@ -113,0 +113,0 @@ return ( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76021
555