@suprsend/web-sdk 0.1.20 → 0.1.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "This is sdk used to integrate suprsend functionality in javascript applications",
5
5
  "main": "dist/cjs_bundle.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  var suprsend_config = {
2
- api_url: "https://collector-staging.suprsend.workers.dev",
2
+ api_url: "https://hub.suprsend.com",
3
3
  imgkit_root: "https://ik.imagekit.io/l0quatz6utm/",
4
4
  api_events_route: "event/",
5
5
  };
@@ -1 +1 @@
1
- var suprsend_config={api_url:"https://collector-staging.suprsend.workers.dev",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)}));
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
@@ -4,6 +4,7 @@ const config = {
4
4
  api_url: "https://hub.suprsend.com",
5
5
  sdk_version: package_data.version,
6
6
  batch_size: 20,
7
+ flush_interval: 3000,
7
8
  service_worker_file: "serviceworker.js",
8
9
  sw_delay: 5000, //in ms,
9
10
  };
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.schedule_flush();
30
+ utils.bulk_call_api();
31
31
  }
32
32
 
33
33
  static setEnvProperties() {
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 = 5000) {
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
  };