@suprsend/web-sdk 0.1.18 → 0.1.22
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cdn_bundle.js +1 -1
- package/dist/cjs_bundle.js +1 -1
- package/package.json +1 -1
- package/serviceworker/serviceworker.js +1 -1
- package/serviceworker/serviceworker.min.js +1 -0
- package/src/config.js +1 -0
- package/src/index.js +2 -1
- package/src/user.js +1 -0
- package/src/utils.js +2 -1
- package/. npmignore +0 -1
- package/.vscode/settings.json +0 -3
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var suprsend_config={api_url:"https://hub.suprsend.com",imgkit_root:"https://ik.imagekit.io/l0quatz6utm/",api_events_route:"event/"},valid_notification_params=["title","body","icon","image","badge","vibrate","sound","dir","tag","data","requireInteraction","renotify","silent","timestamp","actions"];const url_fields=["image","icon","badge"];function safe_get(i,t){let n;try{n=i()}catch(i){n=t}return n}function validate_notification(i){let t={};for(var n in i)valid_notification_params.includes(n)&&(url_fields.includes(n)?t[n]=`${suprsend_config.imgkit_root}${i[n]}`:t[n]=i[n]);return t.actions instanceof Array||delete t.actions,t}function track_data(i,t="post"){return fetch(`${suprsend_config.api_url}/${suprsend_config.api_events_route}`,{method:t,body:JSON.stringify(i),headers:{"Content-Type":"application/json"}})}self.addEventListener("push",(function(i){const t=validate_notification(i.data.json());console.log("Received notification",t),track_data({event:"$notification_delivered",properties:{id:safe_get((()=>t.data.notification_id))}}),i.waitUntil(self.registration.showNotification(t.title||"",t))})),self.addEventListener("notificationclose",(function(i){var t=i.notification;console.log("Closed notification",t),track_data({event:"$notification_dismiss",properties:{id:safe_get((()=>t.data.notification_id))}})})),self.addEventListener("notificationclick",(function(i){i.notification.close();var t=i.notification;console.log("Clicked notification",t),track_data({event:"$notification_clicked",properties:{id:safe_get((()=>t.data.notification_id)),label_id:i.action}});var n=safe_get((()=>t.data.launch_urls)),e="/";n?i.action&&n[i.action]?e=n[i.action]:n.default&&(e=n.default):e="/",clients.openWindow(e)}));
|
package/src/config.js
CHANGED
package/src/index.js
CHANGED
|
@@ -27,7 +27,7 @@ class SuprSend {
|
|
|
27
27
|
this.sw = new ServiceWorker(suprSendInstance);
|
|
28
28
|
this.sw.update_subscription();
|
|
29
29
|
SuprSend.setEnvProperties();
|
|
30
|
-
utils.
|
|
30
|
+
utils.bulk_call_api();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
static setEnvProperties() {
|
|
@@ -101,6 +101,7 @@ class SuprSend {
|
|
|
101
101
|
utils.set_cookie(constants.distinct_id, unique_id);
|
|
102
102
|
suprSendInstance.distinct_id = unique_id;
|
|
103
103
|
suprSendInstance._user_identified = true;
|
|
104
|
+
this.sw.update_subscription();
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
package/src/user.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -174,7 +174,7 @@ function bulk_call_api() {
|
|
|
174
174
|
/*
|
|
175
175
|
schedule the flush in some time future
|
|
176
176
|
*/
|
|
177
|
-
function schedule_flush(delay =
|
|
177
|
+
function schedule_flush(delay = config.flush_interval) {
|
|
178
178
|
setTimeout(() => {
|
|
179
179
|
bulk_call_api();
|
|
180
180
|
}, delay);
|
|
@@ -271,4 +271,5 @@ export default {
|
|
|
271
271
|
batch_or_call,
|
|
272
272
|
has_special_char,
|
|
273
273
|
is_empty,
|
|
274
|
+
bulk_call_api,
|
|
274
275
|
};
|
package/. npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/node_modules
|
package/.vscode/settings.json
DELETED