@notiblast/web 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/service-worker/notiblast-sw.js +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
Official web push SDK for
|
|
6
|
-
app's users — they arrive even when your site is closed.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://app.notiblast.com/apple-touch-icon.png" alt="NotiBlast" width="72" height="72">
|
|
3
|
+
<h1>@notiblast/web</h1>
|
|
4
|
+
<p>
|
|
5
|
+
Official web push SDK for <a href="https://notiblast.com">NotiBlast</a>.<br>
|
|
6
|
+
Send notifications to your web app's users — they arrive even when your site is closed.
|
|
7
|
+
</p>
|
|
8
|
+
<p>
|
|
9
|
+
<img src="https://img.shields.io/badge/size-3%20kB-informational" alt="3 kB">
|
|
10
|
+
<img src="https://img.shields.io/badge/React%20%C2%B7%20Vue%20%C2%B7%20Angular%20%C2%B7%20Svelte-informational" alt="React · Vue · Angular · Svelte">
|
|
11
|
+
<img src="https://img.shields.io/badge/TypeScript-informational" alt="TypeScript">
|
|
12
|
+
<img src="https://img.shields.io/badge/license-MIT-informational" alt="MIT">
|
|
13
|
+
</p>
|
|
14
|
+
</div>
|
|
12
15
|
|
|
13
16
|
---
|
|
14
17
|
|
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ type ReleaseAction = 'logout' | 'unsubscribe' | 'permission_denied';
|
|
|
39
39
|
declare function isPromptOpen(): boolean;
|
|
40
40
|
declare function showPrompt(options?: PromptOptions): Promise<boolean>;
|
|
41
41
|
|
|
42
|
-
declare const SDK_VERSION = "0.3.
|
|
42
|
+
declare const SDK_VERSION = "0.3.2";
|
|
43
43
|
|
|
44
44
|
declare function init(next: NotiblastOptions): void;
|
|
45
45
|
declare function identify(externalUserId: string | null): Promise<string | null>;
|
package/dist/index.js
CHANGED
|
@@ -55,5 +55,5 @@ button {
|
|
|
55
55
|
.card { flex-wrap: wrap }
|
|
56
56
|
.actions { width: 100%; justify-content: flex-end }
|
|
57
57
|
}
|
|
58
|
-
`;function A(){return !!document.getElementById(T)}function W(e={}){if(typeof document>"u"||A())return Promise.resolve(false);let t={...C,...e};return new Promise(n=>{let o=document.createElement("div");o.id=T;let r=o.attachShadow({mode:"closed"}),a=document.createElement("style");a.textContent=j;let i=document.createElement("div");i.className="wrap";let s=document.createElement("div");if(s.className=`card ${t.theme}`,s.setAttribute("role","dialog"),s.setAttribute("aria-live","polite"),e.icon){let c=document.createElement("img");c.src=e.icon,c.alt="",s.append(c);}let S=document.createElement("p");S.textContent=t.message;let m=document.createElement("div");m.className="actions";let u=document.createElement("button");u.className="cancel",u.textContent=t.cancel;let l=document.createElement("button");l.className="accept",l.textContent=t.accept,m.append(u,l),s.append(S,m),i.append(s),r.append(a,i),document.body.append(o),requestAnimationFrame(()=>s.classList.add("in"));function g(c){document.removeEventListener("keydown",E),s.classList.remove("in"),setTimeout(()=>o.remove(),280),n(c);}function E(c){c.key==="Escape"&&g(false);}u.addEventListener("click",()=>g(false)),l.addEventListener("click",()=>g(true)),document.addEventListener("keydown",E),l.focus();})}function b(e){return `notiblast:${e}:token`}function w(e){try{return localStorage.getItem(b(e))}catch{return null}}function D(e,t){try{localStorage.setItem(b(e),t);}catch{return}}function y(e){try{localStorage.removeItem(b(e));}catch{return}}var x="0.3.
|
|
58
|
+
`;function A(){return !!document.getElementById(T)}function W(e={}){if(typeof document>"u"||A())return Promise.resolve(false);let t={...C,...e};return new Promise(n=>{let o=document.createElement("div");o.id=T;let r=o.attachShadow({mode:"closed"}),a=document.createElement("style");a.textContent=j;let i=document.createElement("div");i.className="wrap";let s=document.createElement("div");if(s.className=`card ${t.theme}`,s.setAttribute("role","dialog"),s.setAttribute("aria-live","polite"),e.icon){let c=document.createElement("img");c.src=e.icon,c.alt="",s.append(c);}let S=document.createElement("p");S.textContent=t.message;let m=document.createElement("div");m.className="actions";let u=document.createElement("button");u.className="cancel",u.textContent=t.cancel;let l=document.createElement("button");l.className="accept",l.textContent=t.accept,m.append(u,l),s.append(S,m),i.append(s),r.append(a,i),document.body.append(o),requestAnimationFrame(()=>s.classList.add("in"));function g(c){document.removeEventListener("keydown",E),s.classList.remove("in"),setTimeout(()=>o.remove(),280),n(c);}function E(c){c.key==="Escape"&&g(false);}u.addEventListener("click",()=>g(false)),l.addEventListener("click",()=>g(true)),document.addEventListener("keydown",E),l.focus();})}function b(e){return `notiblast:${e}:token`}function w(e){try{return localStorage.getItem(b(e))}catch{return null}}function D(e,t){try{localStorage.setItem(b(e),t);}catch{return}}function y(e){try{localStorage.removeItem(b(e));}catch{return}}var x="0.3.2";function H(e,t){return t?t===e?"ok":"stale":"unknown"}function L(e,t){return H(e,t)==="ok"?null:[`notiblast: your service worker is version ${t??"unknown"}, the package is ${e}.`,"Re-copy it: npx notiblast init"].join(" ")}var K="https://primaryapi.notiblast.com",Y="/notiblast-sw.js",d=null,p=null;function ge(e){if(!e.appId||!e.firebase||!e.vapidKey)throw new Error("notiblast: init() needs appId, firebase and vapidKey");d={apiUrl:K,...e};}function f(){if(!d)throw new Error("notiblast: call init() first");return d}function k(e){return e.apiUrl??K}async function h(e,t,n){await N(k(e),{appId:e.appId,token:t,action:n});}async function ve(e){let t=f();if(d={...t,externalUserId:e},!p)return null;try{return e===null?(await h(t,p,"logout"),null):await v(k(t),{appId:t.appId,token:p,externalUserId:e})}catch(n){return console.error(`notiblast: identify failed \u2014 ${I(n)}`),null}}async function be(){let e=f(),t=p??w(e.appId);t&&(await h(e,t,"unsubscribe"),y(e.appId),p=null);}async function M(){return typeof window>"u"||!("serviceWorker"in navigator)||!("Notification"in window)?false:isSupported()}function G(){return typeof window>"u"||!("Notification"in window)?"unsupported":Notification.permission}async function we(){let e=f();return await M()?G()!=="default"||await W(e.prompt)?U():{outcome:"dismissed",deviceId:null}:{outcome:"unsupported",deviceId:null}}async function U(){let e=f();if(!await M())return {outcome:"unsupported",deviceId:null};let t=await Q();if(t==="denied"&&await J(e),t!=="granted")return {outcome:t,deviceId:null};let n="service-worker";try{let o=await navigator.serviceWorker.register(e.serviceWorkerPath??Y,e.serviceWorkerScope?{scope:e.serviceWorkerScope}:void 0);await navigator.serviceWorker.ready;let r=L(x,await _(o.active??navigator.serviceWorker.controller));r&&console.warn(r),n="token";let a=getMessaging(initializeApp(e.firebase,`notiblast-${e.appId}`)),i=await getToken(a,{vapidKey:e.vapidKey,serviceWorkerRegistration:o});if(!i)return $("token","Firebase returned no token");p=i,n="register";let s=await v(k(e),{appId:e.appId,token:i,externalUserId:e.externalUserId});return D(e.appId,i),{outcome:"granted",deviceId:s}}catch(o){return $(n,I(o))}}async function J(e){let t=w(e.appId);if(t)try{await h(e,t,"permission_denied"),y(e.appId);}catch(n){console.error(`notiblast: could not report the revoked permission \u2014 ${I(n)}`);}}function I(e){return e instanceof Error?e.message:String(e)}function $(e,t){return console.error(`notiblast: failed at step "${e}" \u2014 ${t}`),{outcome:"error",deviceId:null,step:e,reason:t}}async function Q(){if(Notification.permission==="granted")return "granted";if(Notification.permission==="denied")return "denied";let e=await Notification.requestPermission();return e==="granted"?"granted":e==="denied"?"denied":"dismissed"}
|
|
59
59
|
export{x as SDK_VERSION,ve as identify,ge as init,A as isPromptOpen,M as isSupported,G as permission,we as promptAndSubscribe,W as showPrompt,U as subscribe,be as unsubscribe};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){'use strict';function c(n){return n?.url??null}function u(n,t){return n.find(i=>i.url===t)??null}function r(n){return typeof n=="object"&&n!==null?n:{}}function e(n){return typeof n=="string"&&n.length>0?n:void 0}function f(n){return n===true||n==="true"||n==="1"}function d(n){if(typeof n!="object"||n===null)return null;let t=n,i=r(t.notification),o=r(t.data),y=r(t.fcmOptions),s=e(i.title)??e(o.title);if(!s)return null;let a=e(i.tag)??e(o.tag),l=i.renotify??o.renotify;return {title:s,body:e(i.body)??e(o.body),icon:e(i.icon)??e(o.icon),image:e(i.image)??e(o.image_url),url:e(y.link)??e(i.click_action)??e(o.url),tag:a,renotify:a?l===void 0||f(l):false,requireInteraction:f(i.requireInteraction??o.require_interaction)}}function p(n){return {body:n.body??"",icon:n.icon,image:n.image,tag:n.tag,renotify:!!(n.tag&&n.renotify),requireInteraction:!!n.requireInteraction,data:n}}var g="0.3.
|
|
1
|
+
(function(){'use strict';function c(n){return n?.url??null}function u(n,t){return n.find(i=>i.url===t)??null}function r(n){return typeof n=="object"&&n!==null?n:{}}function e(n){return typeof n=="string"&&n.length>0?n:void 0}function f(n){return n===true||n==="true"||n==="1"}function d(n){if(typeof n!="object"||n===null)return null;let t=n,i=r(t.notification),o=r(t.data),y=r(t.fcmOptions),s=e(i.title)??e(o.title);if(!s)return null;let a=e(i.tag)??e(o.tag),l=i.renotify??o.renotify;return {title:s,body:e(i.body)??e(o.body),icon:e(i.icon)??e(o.icon),image:e(i.image)??e(o.image_url),url:e(y.link)??e(i.click_action)??e(o.url),tag:a,renotify:a?l===void 0||f(l):false,requireInteraction:f(i.requireInteraction??o.require_interaction)}}function p(n){return {body:n.body??"",icon:n.icon,image:n.image,tag:n.tag,renotify:!!(n.tag&&n.renotify),requireInteraction:!!n.requireInteraction,data:n}}var g="0.3.2";self.addEventListener("install",()=>self.skipWaiting());self.addEventListener("message",n=>{if(n.data!=="notiblast:version")return;let t={type:"notiblast:version",version:g},i=n.ports[0];if(i){i.postMessage(t);return}n.source?.postMessage(t);});self.addEventListener("activate",n=>{n.waitUntil(self.clients.claim());});self.addEventListener("push",n=>{if(!n.data)return;let t=null;try{t=d(n.data.json());}catch{return}t&&n.waitUntil(self.registration.showNotification(t.title,p(t)));});self.addEventListener("notificationclick",n=>{n.notification.close();let t=c(n.notification.data??null);t&&n.waitUntil((async()=>{let i=await self.clients.matchAll({type:"window",includeUncontrolled:true}),o=u(i,t);if(o){await o.focus();return}await self.clients.openWindow(t);})());});})();
|