@suprsend/web-sdk 0.1.7 → 0.1.11

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.
@@ -1 +1 @@
1
- !function(){"use strict";var e={147:function(e){e.exports=JSON.parse('{"name":"@suprsend/web-sdk","version":"0.1.6","description":"This is sdk used to integrate suprsend functionality in javascript applications","main":"dist/cjs_bundle.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","build":"rm -rf dist && webpack --env module_type=commonjs --env filename=cjs_bundle.js && webpack --env module_type=window --env filename=cdn_bundle.js","publish_sdk":"npm run build && npm publish"},"keywords":["suprsend","suprsend-browser","suprsend-browser-sdk"],"author":"Sivaram Katta","license":"ISC","repository":{"type":"git","url":"https://github.com/suprsend/suprsend-browser.git"},"publishConfig":{"access":"public"},"devDependencies":{"@babel/core":"^7.15.0","@babel/preset-env":"^7.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"}}')}},r={};function t(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}t.d=function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};!function(){t.r(n),t.d(n,{default:function(){return J},init_at:function(){return V}});var e="_suprsend_dist_id",r="_bulk_api_call",i="event/",o="_suprsend_super_props",a="_suprsend_device_id",s={Edge:["Edge"],"Opera Mini":["Opera Mini"],"Opera Mobile":["Opera Mobi"],Opera:["Opera"],"Internet Explorer":["Trident","MSIE"],Chrome:["Chrome"],Firefox:["Firefox"],Safari:["Safari"],Mozilla:["Mozilla"]},c={Edge:/Edge\/([0-9]+(\.[0-9]+)?)/,"Opera Mini":/Opera Mini\/([0-9]+(\.[0-9]+)?)/,"Opera Mobile":/Version\/([0-9]+(\.[0-9]+)?)/,Opera:/Version\/([0-9]+(\.[0-9]+)?)/,"Internet Explorer":"rv:",Chrome:/Chrome\/([0-9]+(\.[0-9]+)?)/,Firefox:/rv:([0-9]+(\.[0-9]+)?)/,Safari:/Version\/([0-9]+(\.[0-9]+)?)/,Mozilla:/rv:([0-9]+(\.[0-9]+)?)/},u={"Chrome OS":"CrOS","Mac OS":"Macintosh",Windows:"Windows",iOS:"like Mac",Android:"Android",Linux:"Linux"};const l={api_url:"https://collector.suprsend.workers.dev",sdk_version:t(147).version,batch_size:20,service_worker_file:"suprsend_service_worker.js",sw_delay:5e3};function f(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return p(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?p(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(s)throw o}}}}function p(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(){var e=!0;try{window.localStorage}catch(r){e=!1}return e}function v(e){if(d())return localStorage.getItem(e)}function _(e,r){d()&&localStorage.setItem(e,r)}function b(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=v(e);return t?JSON.parse(t):r}function h(){var e=navigator.userAgent;for(var r in s){var t,n=f(s[r]);try{for(n.s();!(t=n.n()).done;){var i=t.value;if(e.indexOf(i)>=0)return r}}catch(e){n.e(e)}finally{n.f()}}}function g(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"post";return fetch("".concat(l.api_url,"/").concat(e),{method:t,body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})}function y(){var e=b(r,[]);if(e.length){var t=e.slice(0,l.batch_size);g(i,t).then((function(e){if(!e.ok)throw new Error("Error in Fetch");var t=b(r,[]);t.splice(0,l.batch_size),_(r,JSON.stringify(t)),y()})).catch((function(){m(12e4)}))}else m()}function m(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;setTimeout((function(){y()}),e)}const w={uuid:function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==r?t:3&t|8).toString(16)}))},epoch_milliseconds:function(){return Math.round(Date.now())},cookie_enabled:function(){return navigator.cookieEnabled},set_cookie:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:365,n="";if(t){var i=new Date;i.setTime(i.getTime()+24*t*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=e+"="+(r||"")+n+"; path=/"},get_cookie:function(e){for(var r=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var i=t[n];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(r))return i.substring(r.length,i.length)}return null},remove_cookie:function(e){document.cookie=e+"=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"},local_storage_enabled:d,get_local_storage_item:v,set_local_storage_item:_,remove_local_storage_item:function(e){d()&&localStorage.removeItem(e)},get_parsed_local_store_data:b,browser:h,browser_version:function(){var e=navigator.userAgent,r=h(),t=c[r];if(t){var n=e.match(t);if(n&&n.length>1)return n[1]}},os:function(){var e=navigator.userAgent;for(var r in u)if(e.indexOf(u[r])>=0)return r},schedule_flush:m,format_props:function(e,r){var t;if(e instanceof Object){t={};for(var n=Object.keys(e),i=0;i<n.length;i++){var o=n[i];void 0!==e[o]&&(t[String(o)]=e[o])}}else null!=r&&(t=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}({},String(e),r));return t},urlB64ToUint8Array:function(e){for(var r=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),t=atob(r),n=new Uint8Array(t.length),i=0;i<t.length;++i)n[i]=t.charCodeAt(i);return n},batch_or_call:function(e){if(d()){var t=b(r,[]);null==t||t.push(e),_(r,JSON.stringify(t))}else g(i,e)}};function O(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function k(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function x(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}const j=function(){function e(r,t){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.env=r,this.instance=t}var r,t;return r=e,(t=[{key:"_call_indetity",value:function(e){w.batch_or_call(function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?O(Object(t),!0).forEach((function(r){k(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):O(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}({env:this.env,distinct_id:this.instance.distinct_id},e))}},{key:"set",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set:t})}},{key:"set_once",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set_once:t})}},{key:"increment",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,t=w.format_props(e,r);if(t){for(var n=Object.keys(t),i=0;i<n.length;i++){var o=n[i],a=Number(t[o]);a||delete t[o]}this._call_indetity({$add:t})}}},{key:"append",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$append:t})}},{key:"remove",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$remove:t})}},{key:"unset",value:function(e){var r;if("string"==typeof e)r=[String(e)];else{if(!(e instanceof Array))return;r=e.map((function(e){return String(e)}))}this._call_indetity({$unset:r})}},{key:"add_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$email",e)}},{key:"remove_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.remove("$email",e)}},{key:"add_sms",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$sms",e)}},{key:"add_whatsapp",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$whatsapp",e)}},{key:"add_webpush",value:function(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append({$webpush:JSON.stringify(t),$device_id:null===(e=this.instance)||void 0===e||null===(r=e.env_properties)||void 0===r?void 0:r.$device_id})}}])&&x(r.prototype,t),e}();function P(e,r,t,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void t(e)}s.done?r(c):Promise.resolve(c).then(n,i)}function S(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){P(o,n,i,a,s,"next",e)}function s(e){P(o,n,i,a,s,"throw",e)}a(void 0)}))}}function E(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function A(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var M;const $=function(){function e(r,t){var n=this;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),A(this,"_check_push_support",(function(){return!(!("serviceWorker"in navigator)||!("PushManager"in window))})),A(this,"_ask_notification_permission",S(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Notification.requestPermission();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})))),A(this,"_register_sw",(function(){return navigator.serviceWorker.register("/".concat(l.service_worker_file)).then((function(e){console.log("Service worker successfully registered."),n._subscribe_push(e)})).catch((function(e){console.error("Unable to register service worker.",e)}))})),A(this,"_get_subscription",(function(){return navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription()})).then(function(){var e=S(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}return e.abrupt("return");case 2:return e.abrupt("return",r);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}())})),A(this,"_subscribe_push",function(){var e=S(regeneratorRuntime.mark((function e(r){var t,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("calling subscribe 1.3"),e.next=3,n._ask_notification_permission();case 3:if("granted"!==e.sent){e.next=18;break}return e.next=7,n._get_subscription();case 7:if(e.sent){e.next=17;break}return console.log("API_CALL: get public vapid from server"),t=w.urlB64ToUint8Array("BADMgGsRZWdjJPH34F0v9OTQfrxHArhk_sVawIACOFHTcaPF_Cfpq1uBX6lOwHByQDjt8f05h3ESK3dldpG3Q9Q"),e.next=13,r.pushManager.subscribe({applicationServerKey:t,userVisibleOnly:!0});case 13:i=e.sent,n.user.add_webpush(i),e.next=18;break;case 17:console.log("Push already subscribed");case 18:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),A(this,"register_push",(function(){n._check_push_support()?(console.log("calling subscribe 1"),n._subscribe_with_delay()):console.log("OOPS, Web Push isn't supported")})),A(this,"is_subscribed",S(regeneratorRuntime.mark((function e(){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n._get_subscription();case 2:return r=e.sent,e.abrupt("return",!!r);case 4:case"end":return e.stop()}}),e)})))),this.env=r,this.instance=t,this.user=new j(r,t)}var r,t;return r=e,(t=[{key:"_subscribe_with_delay",value:function(){var e=this,r=new Date-V;r>=l.sw_delay?(console.log("calling subscribe 1.1"),this._subscribe_push()):(console.log("calling subscribe 1.2"),clearTimeout(M),M=setTimeout((function(){e._subscribe_push()}),l.sw_delay-r))}},{key:"update_subscription",value:function(){var e,r,t=this;null===(e=navigator)||void 0===e||null===(r=e.serviceWorker)||void 0===r||r.ready.then((function(e){return e.pushManager.getSubscription()})).then((function(e){e&&(t.user.add_webpush(e),console.log("API_CALL: save subscription",e))}))}}])&&E(r.prototype,t),e}();function T(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function I(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?T(Object(t),!0).forEach((function(r){N(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):T(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function C(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function N(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var D,V,K=function(){function r(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r)}var t,n,i;return t=r,i=[{key:"setEnvProperties",value:function(){var e=w.get_local_storage_item(a);e||(e=w.uuid(),w.set_local_storage_item(a,e)),D.env_properties={$os:w.os(),$browser:w.browser(),$browser_version:w.browser_version(),$sdk_type:"Browser",$device_id:e,$sdk_version:l.sdk_version}}}],(n=[{key:"initialize",value:function(t){V=new Date;var n=w.get_cookie(e);D||(r.ENV_API_KEY=t,D={}),n||(n=w.uuid(),w.set_cookie(e,n)),D.distinct_id=n,this.user=new j(r.ENV_API_KEY,D),this.sw=new $(r.ENV_API_KEY,D),this.sw.update_subscription(),r.setEnvProperties(),w.schedule_flush()}},{key:"set_super_properties",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=w.get_parsed_local_store_data(o),t=I(I({},r),e);w.set_local_storage_item(o,JSON.stringify(t)),D.env_properties=I(I({},D.env_properties),t)}},{key:"identify",value:function(t){D._user_identified||(w.batch_or_call({env:r.ENV_API_KEY,event:"$identify",properties:{$identified_id:t,$anon_id:D.distinct_id}}),w.set_cookie(e,t),D.distinct_id=t,D._user_identified=!0)}},{key:"track",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=e){var n=w.get_parsed_local_store_data(o),i=w.format_props(I(I(I(I({},t),D.env_properties),n),{},{$current_url:window.location.href}));w.batch_or_call({event:String(e),distinct_id:D.distinct_id,env:r.ENV_API_KEY,properties:i,$insert_id:w.uuid(),$time:w.epoch_milliseconds()})}}},{key:"reset",value:function(){var t=w.uuid();w.set_cookie(e,t),D={distinct_id:t,_user_identified:!1},w.remove_local_storage_item(o),this.user=new j(r.ENV_API_KEY,D),this.sw=new $(r.ENV_API_KEY,D),r.setEnvProperties()}}])&&C(t.prototype,n),i&&C(t,i),r}();N(K,"ENV_API_KEY",void 0);const J=new K}(),window.suprsend=n}();
1
+ !function(){"use strict";var e={147:function(e){e.exports=JSON.parse('{"name":"@suprsend/web-sdk","version":"0.1.11","description":"This is sdk used to integrate suprsend functionality in javascript applications","main":"dist/cjs_bundle.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","build":"rm -rf dist && webpack --env module_type=commonjs --env filename=cjs_bundle.js && webpack --env module_type=window --env filename=cdn_bundle.js","publish_sdk":"npm run build && npm publish"},"keywords":["suprsend","suprsend-browser","suprsend-browser-sdk"],"author":"Sivaram Katta","license":"ISC","repository":{"type":"git","url":"https://github.com/suprsend/suprsend-browser.git"},"publishConfig":{"access":"public"},"devDependencies":{"@babel/core":"^7.15.0","@babel/preset-env":"^7.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"}}')}},r={};function t(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}t.d=function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};!function(){t.r(n),t.d(n,{default:function(){return Y},init_at:function(){return K}});var e="_suprsend_dist_id",r="_bulk_api_call",i="event/",o="_suprsend_super_props",a="_suprsend_device_id",s={Edge:["Edge"],"Opera Mini":["Opera Mini"],"Opera Mobile":["Opera Mobi"],Opera:["Opera"],"Internet Explorer":["Trident","MSIE"],Chrome:["Chrome"],Firefox:["Firefox"],Safari:["Safari"],Mozilla:["Mozilla"]},u={Edge:/Edge\/([0-9]+(\.[0-9]+)?)/,"Opera Mini":/Opera Mini\/([0-9]+(\.[0-9]+)?)/,"Opera Mobile":/Version\/([0-9]+(\.[0-9]+)?)/,Opera:/Version\/([0-9]+(\.[0-9]+)?)/,"Internet Explorer":"rv:",Chrome:/Chrome\/([0-9]+(\.[0-9]+)?)/,Firefox:/rv:([0-9]+(\.[0-9]+)?)/,Safari:/Version\/([0-9]+(\.[0-9]+)?)/,Mozilla:/rv:([0-9]+(\.[0-9]+)?)/},c={"Chrome OS":"CrOS","Mac OS":"Macintosh",Windows:"Windows",iOS:"like Mac",Android:"Android",Linux:"Linux"};const l={api_url:"https://collector.suprsend.workers.dev",sdk_version:t(147).version,batch_size:20,service_worker_file:"suprsend_service_worker.js",sw_delay:5e3};function f(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return p(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?p(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(s)throw o}}}}function p(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(){var e=!0;try{window.localStorage}catch(r){e=!1}return e}function v(e){if(d())return localStorage.getItem(e)}function _(e,r){d()&&localStorage.setItem(e,r)}function h(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=v(e);return t?JSON.parse(t):r}function b(){var e=navigator.userAgent;for(var r in s){var t,n=f(s[r]);try{for(n.s();!(t=n.n()).done;){var i=t.value;if(e.indexOf(i)>=0)return r}}catch(e){n.e(e)}finally{n.f()}}}function g(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"post";return fetch("".concat(l.api_url,"/").concat(e),{method:t,body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})}function y(){var e=h(r,[]);if(e.length){var t=e.slice(0,l.batch_size);g(i,t).then((function(e){if(!e.ok)throw new Error("Error in Fetch");var t=h(r,[]);t.splice(0,l.batch_size),_(r,JSON.stringify(t)),y()})).catch((function(){m(12e4)}))}else m()}function m(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;setTimeout((function(){y()}),e)}const w={uuid:function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==r?t:3&t|8).toString(16)}))},epoch_milliseconds:function(){return Math.round(Date.now())},cookie_enabled:function(){return navigator.cookieEnabled},set_cookie:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:365,n="";if(t){var i=new Date;i.setTime(i.getTime()+24*t*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=e+"="+(r||"")+n+"; path=/"},get_cookie:function(e){for(var r=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var i=t[n];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(r))return i.substring(r.length,i.length)}return null},remove_cookie:function(e){document.cookie=e+"=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"},local_storage_enabled:d,get_local_storage_item:v,set_local_storage_item:_,remove_local_storage_item:function(e){d()&&localStorage.removeItem(e)},get_parsed_local_store_data:h,browser:b,browser_version:function(){var e=navigator.userAgent,r=b(),t=u[r];if(t){var n=e.match(t);if(n&&n.length>1)return n[1]}},os:function(){var e=navigator.userAgent;for(var r in c)if(e.indexOf(c[r])>=0)return r},schedule_flush:m,format_props:function(e,r){var t;if(e instanceof Object){t={};for(var n=Object.keys(e),i=0;i<n.length;i++){var o=n[i];void 0!==e[o]&&(t[String(o)]=e[o])}}else null!=r&&(t=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}({},String(e),r));return t},urlB64ToUint8Array:function(e){for(var r=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),t=atob(r),n=new Uint8Array(t.length),i=0;i<t.length;++i)n[i]=t.charCodeAt(i);return n},batch_or_call:function(e){if(d()){var t=h(r,[]);null==t||t.push(e),_(r,JSON.stringify(t))}else g(i,e)}};function k(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function O(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function x(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}const P=function(){function e(r,t){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.env=r,this.instance=t}var r,t;return r=e,(t=[{key:"_call_indetity",value:function(e){w.batch_or_call(function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?k(Object(t),!0).forEach((function(r){O(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):k(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}({env:this.env,distinct_id:this.instance.distinct_id},e))}},{key:"set",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set:t})}},{key:"set_once",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set_once:t})}},{key:"increment",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,t=w.format_props(e,r);if(t){for(var n=Object.keys(t),i=0;i<n.length;i++){var o=n[i],a=Number(t[o]);a||delete t[o]}this._call_indetity({$add:t})}}},{key:"append",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$append:t})}},{key:"remove",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$remove:t})}},{key:"unset",value:function(e){var r;if("string"==typeof e)r=[String(e)];else{if(!(e instanceof Array))return;r=e.map((function(e){return String(e)}))}this._call_indetity({$unset:r})}},{key:"add_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$email",e)}},{key:"remove_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.remove("$email",e)}},{key:"add_sms",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$sms",e)}},{key:"add_whatsapp",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$whatsapp",e)}},{key:"add_webpush",value:function(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append({$webpush:t,$device_id:null===(e=this.instance)||void 0===e||null===(r=e.env_properties)||void 0===r?void 0:r.$device_id})}}])&&x(r.prototype,t),e}();function S(e,r,t,n,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void t(e)}s.done?r(u):Promise.resolve(u).then(n,i)}function j(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){S(o,n,i,a,s,"next",e)}function s(e){S(o,n,i,a,s,"throw",e)}a(void 0)}))}}function E(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function A(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var $;const M=function(){function e(r,t,n){var i=this;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),A(this,"_check_push_support",(function(){return!(!("serviceWorker"in navigator)||!("PushManager"in window))})),A(this,"_ask_notification_permission",j(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Notification.requestPermission();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})))),A(this,"_register_sw",(function(){return navigator.serviceWorker.register("/".concat(l.service_worker_file)).then((function(e){console.log("Service worker successfully registered."),i._subscribe_push(e)})).catch((function(e){console.error("Unable to register service worker.",e)}))})),A(this,"_get_subscription",(function(){return navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription()})).then(function(){var e=j(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}return e.abrupt("return");case 2:return e.abrupt("return",r);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}())})),A(this,"_subscribe_push",function(){var e=j(regeneratorRuntime.mark((function e(r){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i._ask_notification_permission();case 2:if("granted"!==e.sent){e.next=20;break}return e.next=6,i._get_subscription();case 6:if(e.sent){e.next=19;break}if(console.log("API_CALL: get public vapid from server"),i.vapid_key){e.next=12;break}return console.log("Provide vapid key while calling init"),e.abrupt("return");case 12:return t=w.urlB64ToUint8Array(i.vapid_key),e.next=15,r.pushManager.subscribe({applicationServerKey:t,userVisibleOnly:!0});case 15:n=e.sent,i.user.add_webpush(n),e.next=20;break;case 19:console.log("Push already subscribed");case 20:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),A(this,"register_push",(function(){i._check_push_support()?i._subscribe_with_delay():console.log("OOPS, Web Push isn't supported")})),A(this,"is_subscribed",j(regeneratorRuntime.mark((function e(){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i._get_subscription();case 2:return r=e.sent,e.abrupt("return",!!r);case 4:case"end":return e.stop()}}),e)})))),this.env=r,this.instance=t,this.user=new P(r,t),this.vapid_key=null==n?void 0:n.vapid_key}var r,t;return r=e,(t=[{key:"_subscribe_with_delay",value:function(){var e=this,r=new Date-K;r>=l.sw_delay?this._register_sw():(clearTimeout($),$=setTimeout((function(){e._register_sw()}),l.sw_delay-r))}},{key:"update_subscription",value:function(){var e,r,t=this;null===(e=navigator)||void 0===e||null===(r=e.serviceWorker)||void 0===r||r.ready.then((function(e){return e.pushManager.getSubscription()})).then((function(e){e&&(t.user.add_webpush(e),console.log("API_CALL: save subscription",e))}))}}])&&E(r.prototype,t),e}();function I(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function T(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?I(Object(t),!0).forEach((function(r){C(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):I(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function N(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function C(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var D,K,V=function(){function r(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r)}var t,n,i;return t=r,i=[{key:"setEnvProperties",value:function(){var e=w.get_local_storage_item(a);e||(e=w.uuid(),w.set_local_storage_item(a,e)),D.env_properties={$os:w.os(),$browser:w.browser(),$browser_version:w.browser_version(),$sdk_type:"Browser",$device_id:e,$sdk_version:l.sdk_version}}}],(n=[{key:"init",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};K=new Date;var i=w.get_cookie(e);D||(r.ENV_API_KEY=t,r.OPTIONAL_KEYS=n,D={}),i||(i=w.uuid(),w.set_cookie(e,i)),D.distinct_id=i,this.user=new P(r.ENV_API_KEY,D),this.sw=new M(r.ENV_API_KEY,D,r.OPTIONAL_KEYS),this.sw.update_subscription(),r.setEnvProperties(),w.schedule_flush()}},{key:"set_super_properties",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=w.get_parsed_local_store_data(o),t=T(T({},r),e);w.set_local_storage_item(o,JSON.stringify(t)),D.env_properties=T(T({},D.env_properties),t)}},{key:"identify",value:function(t){D._user_identified||(w.batch_or_call({env:r.ENV_API_KEY,event:"$identify",properties:{$identified_id:t,$anon_id:D.distinct_id}}),w.set_cookie(e,t),D.distinct_id=t,D._user_identified=!0)}},{key:"track",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=e){var n=w.get_parsed_local_store_data(o),i=w.format_props(T(T(T(T({},t),D.env_properties),n),{},{$current_url:window.location.href}));w.batch_or_call({event:String(e),distinct_id:D.distinct_id,env:r.ENV_API_KEY,properties:i,$insert_id:w.uuid(),$time:w.epoch_milliseconds()})}}},{key:"reset",value:function(){var t=w.uuid();w.set_cookie(e,t),D={distinct_id:t,_user_identified:!1},w.remove_local_storage_item(o),this.user=new P(r.ENV_API_KEY,D),this.sw=new M(r.ENV_API_KEY,D),r.setEnvProperties()}}])&&N(t.prototype,n),i&&N(t,i),r}();C(V,"ENV_API_KEY",void 0),C(V,"OPTIONAL_KEYS",void 0);const Y=new V}(),window.suprsend=n}();
@@ -1 +1 @@
1
- !function(){"use strict";var e={147:function(e){e.exports=JSON.parse('{"name":"@suprsend/web-sdk","version":"0.1.6","description":"This is sdk used to integrate suprsend functionality in javascript applications","main":"dist/cjs_bundle.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","build":"rm -rf dist && webpack --env module_type=commonjs --env filename=cjs_bundle.js && webpack --env module_type=window --env filename=cdn_bundle.js","publish_sdk":"npm run build && npm publish"},"keywords":["suprsend","suprsend-browser","suprsend-browser-sdk"],"author":"Sivaram Katta","license":"ISC","repository":{"type":"git","url":"https://github.com/suprsend/suprsend-browser.git"},"publishConfig":{"access":"public"},"devDependencies":{"@babel/core":"^7.15.0","@babel/preset-env":"^7.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"}}')}},r={};function t(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}t.d=function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};!function(){t.r(n),t.d(n,{default:function(){return J},init_at:function(){return V}});var e="_suprsend_dist_id",r="_bulk_api_call",i="event/",o="_suprsend_super_props",a="_suprsend_device_id",s={Edge:["Edge"],"Opera Mini":["Opera Mini"],"Opera Mobile":["Opera Mobi"],Opera:["Opera"],"Internet Explorer":["Trident","MSIE"],Chrome:["Chrome"],Firefox:["Firefox"],Safari:["Safari"],Mozilla:["Mozilla"]},c={Edge:/Edge\/([0-9]+(\.[0-9]+)?)/,"Opera Mini":/Opera Mini\/([0-9]+(\.[0-9]+)?)/,"Opera Mobile":/Version\/([0-9]+(\.[0-9]+)?)/,Opera:/Version\/([0-9]+(\.[0-9]+)?)/,"Internet Explorer":"rv:",Chrome:/Chrome\/([0-9]+(\.[0-9]+)?)/,Firefox:/rv:([0-9]+(\.[0-9]+)?)/,Safari:/Version\/([0-9]+(\.[0-9]+)?)/,Mozilla:/rv:([0-9]+(\.[0-9]+)?)/},u={"Chrome OS":"CrOS","Mac OS":"Macintosh",Windows:"Windows",iOS:"like Mac",Android:"Android",Linux:"Linux"};const l={api_url:"https://collector.suprsend.workers.dev",sdk_version:t(147).version,batch_size:20,service_worker_file:"suprsend_service_worker.js",sw_delay:5e3};function f(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return p(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?p(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(s)throw o}}}}function p(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(){var e=!0;try{window.localStorage}catch(r){e=!1}return e}function v(e){if(d())return localStorage.getItem(e)}function _(e,r){d()&&localStorage.setItem(e,r)}function b(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=v(e);return t?JSON.parse(t):r}function h(){var e=navigator.userAgent;for(var r in s){var t,n=f(s[r]);try{for(n.s();!(t=n.n()).done;){var i=t.value;if(e.indexOf(i)>=0)return r}}catch(e){n.e(e)}finally{n.f()}}}function g(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"post";return fetch("".concat(l.api_url,"/").concat(e),{method:t,body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})}function y(){var e=b(r,[]);if(e.length){var t=e.slice(0,l.batch_size);g(i,t).then((function(e){if(!e.ok)throw new Error("Error in Fetch");var t=b(r,[]);t.splice(0,l.batch_size),_(r,JSON.stringify(t)),y()})).catch((function(){m(12e4)}))}else m()}function m(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;setTimeout((function(){y()}),e)}const w={uuid:function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==r?t:3&t|8).toString(16)}))},epoch_milliseconds:function(){return Math.round(Date.now())},cookie_enabled:function(){return navigator.cookieEnabled},set_cookie:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:365,n="";if(t){var i=new Date;i.setTime(i.getTime()+24*t*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=e+"="+(r||"")+n+"; path=/"},get_cookie:function(e){for(var r=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var i=t[n];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(r))return i.substring(r.length,i.length)}return null},remove_cookie:function(e){document.cookie=e+"=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"},local_storage_enabled:d,get_local_storage_item:v,set_local_storage_item:_,remove_local_storage_item:function(e){d()&&localStorage.removeItem(e)},get_parsed_local_store_data:b,browser:h,browser_version:function(){var e=navigator.userAgent,r=h(),t=c[r];if(t){var n=e.match(t);if(n&&n.length>1)return n[1]}},os:function(){var e=navigator.userAgent;for(var r in u)if(e.indexOf(u[r])>=0)return r},schedule_flush:m,format_props:function(e,r){var t;if(e instanceof Object){t={};for(var n=Object.keys(e),i=0;i<n.length;i++){var o=n[i];void 0!==e[o]&&(t[String(o)]=e[o])}}else null!=r&&(t=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}({},String(e),r));return t},urlB64ToUint8Array:function(e){for(var r=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),t=atob(r),n=new Uint8Array(t.length),i=0;i<t.length;++i)n[i]=t.charCodeAt(i);return n},batch_or_call:function(e){if(d()){var t=b(r,[]);null==t||t.push(e),_(r,JSON.stringify(t))}else g(i,e)}};function O(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function k(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function x(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}const j=function(){function e(r,t){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.env=r,this.instance=t}var r,t;return r=e,(t=[{key:"_call_indetity",value:function(e){w.batch_or_call(function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?O(Object(t),!0).forEach((function(r){k(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):O(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}({env:this.env,distinct_id:this.instance.distinct_id},e))}},{key:"set",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set:t})}},{key:"set_once",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set_once:t})}},{key:"increment",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,t=w.format_props(e,r);if(t){for(var n=Object.keys(t),i=0;i<n.length;i++){var o=n[i],a=Number(t[o]);a||delete t[o]}this._call_indetity({$add:t})}}},{key:"append",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$append:t})}},{key:"remove",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$remove:t})}},{key:"unset",value:function(e){var r;if("string"==typeof e)r=[String(e)];else{if(!(e instanceof Array))return;r=e.map((function(e){return String(e)}))}this._call_indetity({$unset:r})}},{key:"add_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$email",e)}},{key:"remove_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.remove("$email",e)}},{key:"add_sms",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$sms",e)}},{key:"add_whatsapp",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$whatsapp",e)}},{key:"add_webpush",value:function(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append({$webpush:JSON.stringify(t),$device_id:null===(e=this.instance)||void 0===e||null===(r=e.env_properties)||void 0===r?void 0:r.$device_id})}}])&&x(r.prototype,t),e}();function P(e,r,t,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void t(e)}s.done?r(c):Promise.resolve(c).then(n,i)}function S(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){P(o,n,i,a,s,"next",e)}function s(e){P(o,n,i,a,s,"throw",e)}a(void 0)}))}}function E(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function A(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var M;const $=function(){function e(r,t){var n=this;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),A(this,"_check_push_support",(function(){return!(!("serviceWorker"in navigator)||!("PushManager"in window))})),A(this,"_ask_notification_permission",S(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Notification.requestPermission();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})))),A(this,"_register_sw",(function(){return navigator.serviceWorker.register("/".concat(l.service_worker_file)).then((function(e){console.log("Service worker successfully registered."),n._subscribe_push(e)})).catch((function(e){console.error("Unable to register service worker.",e)}))})),A(this,"_get_subscription",(function(){return navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription()})).then(function(){var e=S(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}return e.abrupt("return");case 2:return e.abrupt("return",r);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}())})),A(this,"_subscribe_push",function(){var e=S(regeneratorRuntime.mark((function e(r){var t,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("calling subscribe 1.3"),e.next=3,n._ask_notification_permission();case 3:if("granted"!==e.sent){e.next=18;break}return e.next=7,n._get_subscription();case 7:if(e.sent){e.next=17;break}return console.log("API_CALL: get public vapid from server"),t=w.urlB64ToUint8Array("BADMgGsRZWdjJPH34F0v9OTQfrxHArhk_sVawIACOFHTcaPF_Cfpq1uBX6lOwHByQDjt8f05h3ESK3dldpG3Q9Q"),e.next=13,r.pushManager.subscribe({applicationServerKey:t,userVisibleOnly:!0});case 13:i=e.sent,n.user.add_webpush(i),e.next=18;break;case 17:console.log("Push already subscribed");case 18:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),A(this,"register_push",(function(){n._check_push_support()?(console.log("calling subscribe 1"),n._subscribe_with_delay()):console.log("OOPS, Web Push isn't supported")})),A(this,"is_subscribed",S(regeneratorRuntime.mark((function e(){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n._get_subscription();case 2:return r=e.sent,e.abrupt("return",!!r);case 4:case"end":return e.stop()}}),e)})))),this.env=r,this.instance=t,this.user=new j(r,t)}var r,t;return r=e,(t=[{key:"_subscribe_with_delay",value:function(){var e=this,r=new Date-V;r>=l.sw_delay?(console.log("calling subscribe 1.1"),this._subscribe_push()):(console.log("calling subscribe 1.2"),clearTimeout(M),M=setTimeout((function(){e._subscribe_push()}),l.sw_delay-r))}},{key:"update_subscription",value:function(){var e,r,t=this;null===(e=navigator)||void 0===e||null===(r=e.serviceWorker)||void 0===r||r.ready.then((function(e){return e.pushManager.getSubscription()})).then((function(e){e&&(t.user.add_webpush(e),console.log("API_CALL: save subscription",e))}))}}])&&E(r.prototype,t),e}();function T(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function I(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?T(Object(t),!0).forEach((function(r){N(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):T(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function C(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function N(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var D,V,K=function(){function r(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r)}var t,n,i;return t=r,i=[{key:"setEnvProperties",value:function(){var e=w.get_local_storage_item(a);e||(e=w.uuid(),w.set_local_storage_item(a,e)),D.env_properties={$os:w.os(),$browser:w.browser(),$browser_version:w.browser_version(),$sdk_type:"Browser",$device_id:e,$sdk_version:l.sdk_version}}}],(n=[{key:"initialize",value:function(t){V=new Date;var n=w.get_cookie(e);D||(r.ENV_API_KEY=t,D={}),n||(n=w.uuid(),w.set_cookie(e,n)),D.distinct_id=n,this.user=new j(r.ENV_API_KEY,D),this.sw=new $(r.ENV_API_KEY,D),this.sw.update_subscription(),r.setEnvProperties(),w.schedule_flush()}},{key:"set_super_properties",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=w.get_parsed_local_store_data(o),t=I(I({},r),e);w.set_local_storage_item(o,JSON.stringify(t)),D.env_properties=I(I({},D.env_properties),t)}},{key:"identify",value:function(t){D._user_identified||(w.batch_or_call({env:r.ENV_API_KEY,event:"$identify",properties:{$identified_id:t,$anon_id:D.distinct_id}}),w.set_cookie(e,t),D.distinct_id=t,D._user_identified=!0)}},{key:"track",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=e){var n=w.get_parsed_local_store_data(o),i=w.format_props(I(I(I(I({},t),D.env_properties),n),{},{$current_url:window.location.href}));w.batch_or_call({event:String(e),distinct_id:D.distinct_id,env:r.ENV_API_KEY,properties:i,$insert_id:w.uuid(),$time:w.epoch_milliseconds()})}}},{key:"reset",value:function(){var t=w.uuid();w.set_cookie(e,t),D={distinct_id:t,_user_identified:!1},w.remove_local_storage_item(o),this.user=new j(r.ENV_API_KEY,D),this.sw=new $(r.ENV_API_KEY,D),r.setEnvProperties()}}])&&C(t.prototype,n),i&&C(t,i),r}();N(K,"ENV_API_KEY",void 0);const J=new K}();var i=exports;for(var o in n)i[o]=n[o];n.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})}();
1
+ !function(){"use strict";var e={147:function(e){e.exports=JSON.parse('{"name":"@suprsend/web-sdk","version":"0.1.11","description":"This is sdk used to integrate suprsend functionality in javascript applications","main":"dist/cjs_bundle.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","build":"rm -rf dist && webpack --env module_type=commonjs --env filename=cjs_bundle.js && webpack --env module_type=window --env filename=cdn_bundle.js","publish_sdk":"npm run build && npm publish"},"keywords":["suprsend","suprsend-browser","suprsend-browser-sdk"],"author":"Sivaram Katta","license":"ISC","repository":{"type":"git","url":"https://github.com/suprsend/suprsend-browser.git"},"publishConfig":{"access":"public"},"devDependencies":{"@babel/core":"^7.15.0","@babel/preset-env":"^7.15.0","babel-loader":"^8.2.2","webpack":"^5.51.1","webpack-cli":"^4.8.0"}}')}},r={};function t(n){var i=r[n];if(void 0!==i)return i.exports;var o=r[n]={exports:{}};return e[n](o,o.exports,t),o.exports}t.d=function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};!function(){t.r(n),t.d(n,{default:function(){return Y},init_at:function(){return K}});var e="_suprsend_dist_id",r="_bulk_api_call",i="event/",o="_suprsend_super_props",a="_suprsend_device_id",s={Edge:["Edge"],"Opera Mini":["Opera Mini"],"Opera Mobile":["Opera Mobi"],Opera:["Opera"],"Internet Explorer":["Trident","MSIE"],Chrome:["Chrome"],Firefox:["Firefox"],Safari:["Safari"],Mozilla:["Mozilla"]},u={Edge:/Edge\/([0-9]+(\.[0-9]+)?)/,"Opera Mini":/Opera Mini\/([0-9]+(\.[0-9]+)?)/,"Opera Mobile":/Version\/([0-9]+(\.[0-9]+)?)/,Opera:/Version\/([0-9]+(\.[0-9]+)?)/,"Internet Explorer":"rv:",Chrome:/Chrome\/([0-9]+(\.[0-9]+)?)/,Firefox:/rv:([0-9]+(\.[0-9]+)?)/,Safari:/Version\/([0-9]+(\.[0-9]+)?)/,Mozilla:/rv:([0-9]+(\.[0-9]+)?)/},c={"Chrome OS":"CrOS","Mac OS":"Macintosh",Windows:"Windows",iOS:"like Mac",Android:"Android",Linux:"Linux"};const l={api_url:"https://collector.suprsend.workers.dev",sdk_version:t(147).version,batch_size:20,service_worker_file:"suprsend_service_worker.js",sw_delay:5e3};function f(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return p(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?p(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(s)throw o}}}}function p(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(){var e=!0;try{window.localStorage}catch(r){e=!1}return e}function v(e){if(d())return localStorage.getItem(e)}function _(e,r){d()&&localStorage.setItem(e,r)}function h(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=v(e);return t?JSON.parse(t):r}function b(){var e=navigator.userAgent;for(var r in s){var t,n=f(s[r]);try{for(n.s();!(t=n.n()).done;){var i=t.value;if(e.indexOf(i)>=0)return r}}catch(e){n.e(e)}finally{n.f()}}}function g(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"post";return fetch("".concat(l.api_url,"/").concat(e),{method:t,body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})}function y(){var e=h(r,[]);if(e.length){var t=e.slice(0,l.batch_size);g(i,t).then((function(e){if(!e.ok)throw new Error("Error in Fetch");var t=h(r,[]);t.splice(0,l.batch_size),_(r,JSON.stringify(t)),y()})).catch((function(){m(12e4)}))}else m()}function m(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;setTimeout((function(){y()}),e)}const w={uuid:function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==r?t:3&t|8).toString(16)}))},epoch_milliseconds:function(){return Math.round(Date.now())},cookie_enabled:function(){return navigator.cookieEnabled},set_cookie:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:365,n="";if(t){var i=new Date;i.setTime(i.getTime()+24*t*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=e+"="+(r||"")+n+"; path=/"},get_cookie:function(e){for(var r=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(var i=t[n];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(r))return i.substring(r.length,i.length)}return null},remove_cookie:function(e){document.cookie=e+"=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"},local_storage_enabled:d,get_local_storage_item:v,set_local_storage_item:_,remove_local_storage_item:function(e){d()&&localStorage.removeItem(e)},get_parsed_local_store_data:h,browser:b,browser_version:function(){var e=navigator.userAgent,r=b(),t=u[r];if(t){var n=e.match(t);if(n&&n.length>1)return n[1]}},os:function(){var e=navigator.userAgent;for(var r in c)if(e.indexOf(c[r])>=0)return r},schedule_flush:m,format_props:function(e,r){var t;if(e instanceof Object){t={};for(var n=Object.keys(e),i=0;i<n.length;i++){var o=n[i];void 0!==e[o]&&(t[String(o)]=e[o])}}else null!=r&&(t=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}({},String(e),r));return t},urlB64ToUint8Array:function(e){for(var r=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),t=atob(r),n=new Uint8Array(t.length),i=0;i<t.length;++i)n[i]=t.charCodeAt(i);return n},batch_or_call:function(e){if(d()){var t=h(r,[]);null==t||t.push(e),_(r,JSON.stringify(t))}else g(i,e)}};function k(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function O(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function x(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}const P=function(){function e(r,t){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.env=r,this.instance=t}var r,t;return r=e,(t=[{key:"_call_indetity",value:function(e){w.batch_or_call(function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?k(Object(t),!0).forEach((function(r){O(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):k(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}({env:this.env,distinct_id:this.instance.distinct_id},e))}},{key:"set",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set:t})}},{key:"set_once",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$set_once:t})}},{key:"increment",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,t=w.format_props(e,r);if(t){for(var n=Object.keys(t),i=0;i<n.length;i++){var o=n[i],a=Number(t[o]);a||delete t[o]}this._call_indetity({$add:t})}}},{key:"append",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$append:t})}},{key:"remove",value:function(e,r){var t=w.format_props(e,r);t&&this._call_indetity({$remove:t})}},{key:"unset",value:function(e){var r;if("string"==typeof e)r=[String(e)];else{if(!(e instanceof Array))return;r=e.map((function(e){return String(e)}))}this._call_indetity({$unset:r})}},{key:"add_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$email",e)}},{key:"remove_email",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.remove("$email",e)}},{key:"add_sms",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$sms",e)}},{key:"add_whatsapp",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append("$whatsapp",e)}},{key:"add_webpush",value:function(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";this.append({$webpush:t,$device_id:null===(e=this.instance)||void 0===e||null===(r=e.env_properties)||void 0===r?void 0:r.$device_id})}}])&&x(r.prototype,t),e}();function j(e,r,t,n,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void t(e)}s.done?r(u):Promise.resolve(u).then(n,i)}function S(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){j(o,n,i,a,s,"next",e)}function s(e){j(o,n,i,a,s,"throw",e)}a(void 0)}))}}function E(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function A(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var M;const $=function(){function e(r,t,n){var i=this;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),A(this,"_check_push_support",(function(){return!(!("serviceWorker"in navigator)||!("PushManager"in window))})),A(this,"_ask_notification_permission",S(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Notification.requestPermission();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})))),A(this,"_register_sw",(function(){return navigator.serviceWorker.register("/".concat(l.service_worker_file)).then((function(e){console.log("Service worker successfully registered."),i._subscribe_push(e)})).catch((function(e){console.error("Unable to register service worker.",e)}))})),A(this,"_get_subscription",(function(){return navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription()})).then(function(){var e=S(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}return e.abrupt("return");case 2:return e.abrupt("return",r);case 3:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}())})),A(this,"_subscribe_push",function(){var e=S(regeneratorRuntime.mark((function e(r){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i._ask_notification_permission();case 2:if("granted"!==e.sent){e.next=20;break}return e.next=6,i._get_subscription();case 6:if(e.sent){e.next=19;break}if(console.log("API_CALL: get public vapid from server"),i.vapid_key){e.next=12;break}return console.log("Provide vapid key while calling init"),e.abrupt("return");case 12:return t=w.urlB64ToUint8Array(i.vapid_key),e.next=15,r.pushManager.subscribe({applicationServerKey:t,userVisibleOnly:!0});case 15:n=e.sent,i.user.add_webpush(n),e.next=20;break;case 19:console.log("Push already subscribed");case 20:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),A(this,"register_push",(function(){i._check_push_support()?i._subscribe_with_delay():console.log("OOPS, Web Push isn't supported")})),A(this,"is_subscribed",S(regeneratorRuntime.mark((function e(){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i._get_subscription();case 2:return r=e.sent,e.abrupt("return",!!r);case 4:case"end":return e.stop()}}),e)})))),this.env=r,this.instance=t,this.user=new P(r,t),this.vapid_key=null==n?void 0:n.vapid_key}var r,t;return r=e,(t=[{key:"_subscribe_with_delay",value:function(){var e=this,r=new Date-K;r>=l.sw_delay?this._register_sw():(clearTimeout(M),M=setTimeout((function(){e._register_sw()}),l.sw_delay-r))}},{key:"update_subscription",value:function(){var e,r,t=this;null===(e=navigator)||void 0===e||null===(r=e.serviceWorker)||void 0===r||r.ready.then((function(e){return e.pushManager.getSubscription()})).then((function(e){e&&(t.user.add_webpush(e),console.log("API_CALL: save subscription",e))}))}}])&&E(r.prototype,t),e}();function I(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function T(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?I(Object(t),!0).forEach((function(r){C(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):I(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function N(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function C(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var D,K,V=function(){function r(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r)}var t,n,i;return t=r,i=[{key:"setEnvProperties",value:function(){var e=w.get_local_storage_item(a);e||(e=w.uuid(),w.set_local_storage_item(a,e)),D.env_properties={$os:w.os(),$browser:w.browser(),$browser_version:w.browser_version(),$sdk_type:"Browser",$device_id:e,$sdk_version:l.sdk_version}}}],(n=[{key:"init",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};K=new Date;var i=w.get_cookie(e);D||(r.ENV_API_KEY=t,r.OPTIONAL_KEYS=n,D={}),i||(i=w.uuid(),w.set_cookie(e,i)),D.distinct_id=i,this.user=new P(r.ENV_API_KEY,D),this.sw=new $(r.ENV_API_KEY,D,r.OPTIONAL_KEYS),this.sw.update_subscription(),r.setEnvProperties(),w.schedule_flush()}},{key:"set_super_properties",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=w.get_parsed_local_store_data(o),t=T(T({},r),e);w.set_local_storage_item(o,JSON.stringify(t)),D.env_properties=T(T({},D.env_properties),t)}},{key:"identify",value:function(t){D._user_identified||(w.batch_or_call({env:r.ENV_API_KEY,event:"$identify",properties:{$identified_id:t,$anon_id:D.distinct_id}}),w.set_cookie(e,t),D.distinct_id=t,D._user_identified=!0)}},{key:"track",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=e){var n=w.get_parsed_local_store_data(o),i=w.format_props(T(T(T(T({},t),D.env_properties),n),{},{$current_url:window.location.href}));w.batch_or_call({event:String(e),distinct_id:D.distinct_id,env:r.ENV_API_KEY,properties:i,$insert_id:w.uuid(),$time:w.epoch_milliseconds()})}}},{key:"reset",value:function(){var t=w.uuid();w.set_cookie(e,t),D={distinct_id:t,_user_identified:!1},w.remove_local_storage_item(o),this.user=new P(r.ENV_API_KEY,D),this.sw=new $(r.ENV_API_KEY,D),r.setEnvProperties()}}])&&N(t.prototype,n),i&&N(t,i),r}();C(V,"ENV_API_KEY",void 0),C(V,"OPTIONAL_KEYS",void 0);const Y=new V}();var i=exports;for(var o in n)i[o]=n[o];n.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.11",
4
4
  "description": "This is sdk used to integrate suprsend functionality in javascript applications",
5
5
  "main": "dist/cjs_bundle.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -9,6 +9,7 @@ export var init_at;
9
9
 
10
10
  class SuprSend {
11
11
  static ENV_API_KEY;
12
+ static OPTIONAL_KEYS;
12
13
 
13
14
  static setEnvProperties() {
14
15
  let device_id = utils.get_local_storage_item(constants.device_id_key);
@@ -26,11 +27,12 @@ class SuprSend {
26
27
  };
27
28
  }
28
29
 
29
- initialize(ENV_API_KEY) {
30
+ init(ENV_API_KEY, options = {}) {
30
31
  init_at = new Date();
31
32
  var distinct_id = utils.get_cookie(constants.distinct_id);
32
33
  if (!suprSendInstance) {
33
34
  SuprSend.ENV_API_KEY = ENV_API_KEY;
35
+ SuprSend.OPTIONAL_KEYS = options;
34
36
  suprSendInstance = {};
35
37
  }
36
38
  if (!distinct_id) {
@@ -39,7 +41,11 @@ class SuprSend {
39
41
  }
40
42
  suprSendInstance.distinct_id = distinct_id;
41
43
  this.user = new User(SuprSend.ENV_API_KEY, suprSendInstance);
42
- this.sw = new ServiceWorker(SuprSend.ENV_API_KEY, suprSendInstance);
44
+ this.sw = new ServiceWorker(
45
+ SuprSend.ENV_API_KEY,
46
+ suprSendInstance,
47
+ SuprSend.OPTIONAL_KEYS
48
+ );
43
49
  this.sw.update_subscription();
44
50
  SuprSend.setEnvProperties();
45
51
  utils.schedule_flush();
@@ -5,10 +5,11 @@ import { init_at } from "./index";
5
5
 
6
6
  var notification_timer;
7
7
  class ServiceWorker {
8
- constructor(env_key, instance) {
8
+ constructor(env_key, instance, optional_keys) {
9
9
  this.env = env_key;
10
10
  this.instance = instance;
11
11
  this.user = new User(env_key, instance);
12
+ this.vapid_key = optional_keys?.vapid_key;
12
13
  }
13
14
 
14
15
  _check_push_support = () => {
@@ -49,11 +50,11 @@ class ServiceWorker {
49
50
  const delay = now - init_at;
50
51
  const has_delay = delay >= config.sw_delay;
51
52
  if (has_delay) {
52
- this._subscribe_push();
53
+ this._register_sw();
53
54
  } else {
54
55
  clearTimeout(notification_timer);
55
56
  notification_timer = setTimeout(() => {
56
- this._subscribe_push();
57
+ this._register_sw();
57
58
  }, config.sw_delay - delay);
58
59
  }
59
60
  }
@@ -67,9 +68,11 @@ class ServiceWorker {
67
68
  const subscription = await this._get_subscription();
68
69
  if (!subscription) {
69
70
  console.log("API_CALL: get public vapid from server");
70
- const applicationServerKey = utils.urlB64ToUint8Array(
71
- "BADMgGsRZWdjJPH34F0v9OTQfrxHArhk_sVawIACOFHTcaPF_Cfpq1uBX6lOwHByQDjt8f05h3ESK3dldpG3Q9Q"
72
- );
71
+ if (!this.vapid_key) {
72
+ console.log("Provide vapid key while calling init");
73
+ return;
74
+ }
75
+ const applicationServerKey = utils.urlB64ToUint8Array(this.vapid_key);
73
76
  const subscription = await reg.pushManager.subscribe({
74
77
  applicationServerKey,
75
78
  userVisibleOnly: true,
package/src/user.js CHANGED
@@ -87,7 +87,7 @@ class User {
87
87
 
88
88
  add_webpush(push = "") {
89
89
  this.append({
90
- $webpush: JSON.stringify(push),
90
+ $webpush: push,
91
91
  $device_id: this.instance?.env_properties?.$device_id,
92
92
  });
93
93
  }