@suprsend/web-sdk 0.1.10 → 0.1.14
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/dist/cdn_bundle.js +1 -1
- package/dist/cjs_bundle.js +1 -1
- package/package.json +1 -1
- package/src/config.js +2 -2
- package/src/encryption.js +266 -0
- package/src/index.js +26 -9
- package/src/service_worker.js +7 -8
- package/src/user.js +3 -3
- package/src/utils.js +14 -7
package/dist/cdn_bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";var e={147:function(e){e.exports=JSON.parse('{"name":"@suprsend/web-sdk","version":"0.1.10","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 R},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"]},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 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: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),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){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 e.next=2,n._ask_notification_permission();case 2:if("granted"!==e.sent){e.next=17;break}return e.next=6,n._get_subscription();case 6:if(e.sent){e.next=16;break}return console.log("API_CALL: get public vapid from server"),t=w.urlB64ToUint8Array("BADMgGsRZWdjJPH34F0v9OTQfrxHArhk_sVawIACOFHTcaPF_Cfpq1uBX6lOwHByQDjt8f05h3ESK3dldpG3Q9Q"),e.next=12,r.pushManager.subscribe({applicationServerKey:t,userVisibleOnly:!0});case 12:i=e.sent,n.user.add_webpush(i),e.next=17;break;case 16:console.log("Push already subscribed");case 17:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),A(this,"register_push",(function(){n._check_push_support()?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?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 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){D(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 D(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var N,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)),N.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);N||(r.ENV_API_KEY=t,N={}),n||(n=w.uuid(),w.set_cookie(e,n)),N.distinct_id=n,this.user=new j(r.ENV_API_KEY,N),this.sw=new $(r.ENV_API_KEY,N),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)),N.env_properties=I(I({},N.env_properties),t)}},{key:"identify",value:function(t){N._user_identified||(w.batch_or_call({env:r.ENV_API_KEY,event:"$identify",properties:{$identified_id:t,$anon_id:N.distinct_id}}),w.set_cookie(e,t),N.distinct_id=t,N._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),N.env_properties),n),{},{$current_url:window.location.href}));w.batch_or_call({event:String(e),distinct_id:N.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),N={distinct_id:t,_user_identified:!1},w.remove_local_storage_item(o),this.user=new j(r.ENV_API_KEY,N),this.sw=new $(r.ENV_API_KEY,N),r.setEnvProperties()}}])&&C(t.prototype,n),i&&C(t,i),r}();D(K,"ENV_API_KEY",void 0);const R=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.14","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 q},init_at:function(){return G}});var e="_suprsend_dist_id",r="_bulk_api_call",i="event/",o="_suprsend_super_props",a="_suprsend_device_id",u={Edge:["Edge"],"Opera Mini":["Opera Mini"],"Opera Mobile":["Opera Mobi"],Opera:["Opera"],"Internet Explorer":["Trident","MSIE"],Chrome:["Chrome"],Firefox:["Firefox"],Safari:["Safari"],Mozilla:["Mozilla"]},s={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://hub.suprsend.com",sdk_version:t(147).version,batch_size:20,service_worker_file:"suprsend_service_worker.js",sw_delay:5e3};function f(e,r,t,n,i,o,a){try{var u=e[o](a),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,i)}function p(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){f(o,n,i,a,u,"next",e)}function u(e){f(o,n,i,a,u,"throw",e)}a(void 0)}))}}function d(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return v(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)?v(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(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}var h=function(e){function r(e,r){return e<<r|e>>>32-r}function t(e,r){var t,n,i,o,a;return i=2147483648&e,o=2147483648&r,a=(1073741823&e)+(1073741823&r),(t=1073741824&e)&(n=1073741824&r)?2147483648^a^i^o:t|n?1073741824&a?3221225472^a^i^o:1073741824^a^i^o:a^i^o}function n(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return e&r|~e&t}(n,i,o),a),s)),t(r(e,u),n)}function i(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return e&t|r&~t}(n,i,o),a),s)),t(r(e,u),n)}function o(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return e^r^t}(n,i,o),a),s)),t(r(e,u),n)}function a(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return r^(e|~t)}(n,i,o),a),s)),t(r(e,u),n)}function u(e){var r,t="",n="";for(r=0;r<=3;r++)t+=(n="0"+(e>>>8*r&255).toString(16)).substr(n.length-2,2);return t}var s,c,l,f,p,d,v,h,_,g=Array();for(g=function(e){for(var r,t=e.length,n=t+8,i=16*((n-n%64)/64+1),o=Array(i-1),a=0,u=0;u<t;)a=u%4*8,o[r=(u-u%4)/4]=o[r]|e.charCodeAt(u)<<a,u++;return a=u%4*8,o[r=(u-u%4)/4]=o[r]|128<<a,o[i-2]=t<<3,o[i-1]=t>>>29,o}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var r="",t=0;t<e.length;t++){var n=e.charCodeAt(t);n<128?r+=String.fromCharCode(n):n>127&&n<2048?(r+=String.fromCharCode(n>>6|192),r+=String.fromCharCode(63&n|128)):(r+=String.fromCharCode(n>>12|224),r+=String.fromCharCode(n>>6&63|128),r+=String.fromCharCode(63&n|128))}return r}(e)),d=1732584193,v=4023233417,h=2562383102,_=271733878,s=0;s<g.length;s+=16)c=d,l=v,f=h,p=_,d=n(d,v,h,_,g[s+0],7,3614090360),_=n(_,d,v,h,g[s+1],12,3905402710),h=n(h,_,d,v,g[s+2],17,606105819),v=n(v,h,_,d,g[s+3],22,3250441966),d=n(d,v,h,_,g[s+4],7,4118548399),_=n(_,d,v,h,g[s+5],12,1200080426),h=n(h,_,d,v,g[s+6],17,2821735955),v=n(v,h,_,d,g[s+7],22,4249261313),d=n(d,v,h,_,g[s+8],7,1770035416),_=n(_,d,v,h,g[s+9],12,2336552879),h=n(h,_,d,v,g[s+10],17,4294925233),v=n(v,h,_,d,g[s+11],22,2304563134),d=n(d,v,h,_,g[s+12],7,1804603682),_=n(_,d,v,h,g[s+13],12,4254626195),h=n(h,_,d,v,g[s+14],17,2792965006),d=i(d,v=n(v,h,_,d,g[s+15],22,1236535329),h,_,g[s+1],5,4129170786),_=i(_,d,v,h,g[s+6],9,3225465664),h=i(h,_,d,v,g[s+11],14,643717713),v=i(v,h,_,d,g[s+0],20,3921069994),d=i(d,v,h,_,g[s+5],5,3593408605),_=i(_,d,v,h,g[s+10],9,38016083),h=i(h,_,d,v,g[s+15],14,3634488961),v=i(v,h,_,d,g[s+4],20,3889429448),d=i(d,v,h,_,g[s+9],5,568446438),_=i(_,d,v,h,g[s+14],9,3275163606),h=i(h,_,d,v,g[s+3],14,4107603335),v=i(v,h,_,d,g[s+8],20,1163531501),d=i(d,v,h,_,g[s+13],5,2850285829),_=i(_,d,v,h,g[s+2],9,4243563512),h=i(h,_,d,v,g[s+7],14,1735328473),d=o(d,v=i(v,h,_,d,g[s+12],20,2368359562),h,_,g[s+5],4,4294588738),_=o(_,d,v,h,g[s+8],11,2272392833),h=o(h,_,d,v,g[s+11],16,1839030562),v=o(v,h,_,d,g[s+14],23,4259657740),d=o(d,v,h,_,g[s+1],4,2763975236),_=o(_,d,v,h,g[s+4],11,1272893353),h=o(h,_,d,v,g[s+7],16,4139469664),v=o(v,h,_,d,g[s+10],23,3200236656),d=o(d,v,h,_,g[s+13],4,681279174),_=o(_,d,v,h,g[s+0],11,3936430074),h=o(h,_,d,v,g[s+3],16,3572445317),v=o(v,h,_,d,g[s+6],23,76029189),d=o(d,v,h,_,g[s+9],4,3654602809),_=o(_,d,v,h,g[s+12],11,3873151461),h=o(h,_,d,v,g[s+15],16,530742520),d=a(d,v=o(v,h,_,d,g[s+2],23,3299628645),h,_,g[s+0],6,4096336452),_=a(_,d,v,h,g[s+7],10,1126891415),h=a(h,_,d,v,g[s+14],15,2878612391),v=a(v,h,_,d,g[s+5],21,4237533241),d=a(d,v,h,_,g[s+12],6,1700485571),_=a(_,d,v,h,g[s+3],10,2399980690),h=a(h,_,d,v,g[s+10],15,4293915773),v=a(v,h,_,d,g[s+1],21,2240044497),d=a(d,v,h,_,g[s+8],6,1873313359),_=a(_,d,v,h,g[s+15],10,4264355552),h=a(h,_,d,v,g[s+6],15,2734768916),v=a(v,h,_,d,g[s+13],21,1309151649),d=a(d,v,h,_,g[s+4],6,4149444226),_=a(_,d,v,h,g[s+11],10,3174756917),h=a(h,_,d,v,g[s+2],15,718787259),v=a(v,h,_,d,g[s+9],21,3951481745),d=t(d,c),v=t(v,l),h=t(h,f),_=t(_,p);return(u(d)+u(v)+u(h)+u(_)).toLowerCase()},_=function(e){return new Uint8Array(d(unescape(encodeURIComponent(e))).map((function(e){return e.charCodeAt(0)})))};function g(e,r,t){return y.apply(this,arguments)}function y(){return(y=p(regeneratorRuntime.mark((function e(r,t,n){var o,a,u,s,c,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(window.crypto){e.next=2;break}return e.abrupt("return");case 2:return o=l.signing_key,a="".concat(n,"\n").concat(h(r),"\napplication/json\n").concat(t,"\n/").concat(i),u=_(o),s=_(a),e.next=8,crypto.subtle.importKey("raw",u,{name:"HMAC",hash:"SHA-256"},!0,["sign"]);case 8:return c=e.sent,e.next=11,crypto.subtle.sign("HMAC",c,s);case 11:return f=e.sent,d(new Uint8Array(f)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),e.abrupt("return",window.btoa(String.fromCharCode.apply(String,d(new Uint8Array(f)))));case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function b(e,r,t,n,i,o,a){try{var u=e[o](a),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,i)}function m(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){b(o,n,i,a,u,"next",e)}function u(e){b(o,n,i,a,u,"throw",e)}a(void 0)}))}}function w(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 k(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)?k(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,u=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){u=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(u)throw o}}}}function k(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 O(){var e=!0;try{window.localStorage}catch(r){e=!1}return e}function x(e){if(O())return localStorage.getItem(e)}function S(e,r){O()&&localStorage.setItem(e,r)}function j(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=x(e);return t?JSON.parse(t):r}function C(){var e=navigator.userAgent;for(var r in u){var t,n=w(u[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 P(e,r){return A.apply(this,arguments)}function A(){return(A=m(regeneratorRuntime.mark((function e(r,t){var n,i,o,a,u,s,c,f=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=f.length>2&&void 0!==f[2]?f[2]:"POST",a=(new Date).toGMTString(),u=JSON.stringify(t),e.next=5,g(u,a,"POST");case 5:return s=e.sent,c=s?"".concat(null===(n=t[0])||void 0===n?void 0:n.env,":").concat(s):null===(i=t[0])||void 0===i?void 0:i.env,e.abrupt("return",fetch("".concat(l.api_url,"/").concat(r),{method:o,body:u,headers:{"Content-Type":"application/json",Authorization:c,"x-amz-date":a}}));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function M(){var e=j(r,[]);if(e.length){var t=e.slice(0,l.batch_size);P(i,t).then((function(e){if(!e.ok)throw new Error("Error in Fetch");var t=j(r,[]);t.splice(0,l.batch_size),S(r,JSON.stringify(t)),M()})).catch((function(){$(12e4)}))}else $()}function $(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;setTimeout((function(){M()}),e)}const E={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:O,get_local_storage_item:x,set_local_storage_item:S,remove_local_storage_item:function(e){O()&&localStorage.removeItem(e)},get_parsed_local_store_data:j,browser:C,browser_version:function(){var e=navigator.userAgent,r=C(),t=s[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:$,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=window.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(O()){var t=j(r,[]);null==t||t.push(e),S(r,JSON.stringify(t))}else P(i,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 D(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function I(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 R=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.instance=r}var r,t;return r=e,(t=[{key:"_call_indetity",value:function(e){E.batch_or_call(function(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){D(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}({env:l.env_key,distinct_id:this.instance.distinct_id},e))}},{key:"set",value:function(e,r){var t=E.format_props(e,r);t&&this._call_indetity({$set:t})}},{key:"set_once",value:function(e,r){var t=E.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=E.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=E.format_props(e,r);t&&this._call_indetity({$append:t})}},{key:"remove",value:function(e,r){var t=E.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})}}])&&I(r.prototype,t),e}();function U(e,r,t,n,i,o,a){try{var u=e[o](a),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,i)}function z(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){U(o,n,i,a,u,"next",e)}function u(e){U(o,n,i,a,u,"throw",e)}a(void 0)}))}}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 J(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var W;const F=function(){function e(r){var t=this;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),J(this,"_check_push_support",(function(){return!(!("serviceWorker"in navigator)||!("PushManager"in window))})),J(this,"_ask_notification_permission",z(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)})))),J(this,"_register_sw",(function(){return navigator.serviceWorker.register("/".concat(l.service_worker_file)).then((function(e){console.log("Service worker successfully registered."),t._subscribe_push(e)})).catch((function(e){console.error("Unable to register service worker.",e)}))})),J(this,"_get_subscription",(function(){return navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription()})).then(function(){var e=z(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)}}())})),J(this,"_subscribe_push",function(){var e=z(regeneratorRuntime.mark((function e(r){var n,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._ask_notification_permission();case 2:if("granted"!==e.sent){e.next=19;break}return e.next=6,t._get_subscription();case 6:if(e.sent){e.next=18;break}if(l.vapid_key){e.next=11;break}return console.log("Provide vapid key while calling init"),e.abrupt("return");case 11:return n=E.urlB64ToUint8Array(l.vapid_key),e.next=14,r.pushManager.subscribe({applicationServerKey:n,userVisibleOnly:!0});case 14:i=e.sent,t.user.add_webpush(i),e.next=19;break;case 18:console.log("Push already subscribed");case 19:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),J(this,"register_push",(function(){t._check_push_support()?t._subscribe_with_delay():console.log("OOPS, Web Push isn't supported")})),J(this,"is_subscribed",z(regeneratorRuntime.mark((function e(){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._get_subscription();case 2:return r=e.sent,e.abrupt("return",!!r);case 4:case"end":return e.stop()}}),e)})))),this.instance=r,this.user=new R(r)}var r,t;return r=e,(t=[{key:"_subscribe_with_delay",value:function(){var e=this,r=new Date-G;r>=l.sw_delay?this._register_sw():(clearTimeout(W),W=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)}))}}])&&N(r.prototype,t),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 V(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){B(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}function B(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function H(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)}}var L,G;const q=new(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=E.get_local_storage_item(a);e||(e=E.uuid(),E.set_local_storage_item(a,e)),L.env_properties={$os:E.os(),$browser:E.browser(),$browser_version:E.browser_version(),$sdk_type:"Browser",$device_id:e,$sdk_version:l.sdk_version}}}],(n=[{key:"setCustomConfigProperty",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(r)l[e]=r;else if(t)throw Error("Mandatory Key Missing:",e)}},{key:"setCustomConfig",value:function(e){this.setCustomConfigProperty("env_key",e.env,!0),this.setCustomConfigProperty("signing_key",e.signing_key,!0),this.setCustomConfigProperty("api_url",null==e?void 0:e.api_url),this.setCustomConfigProperty("vapid_key",null==e?void 0:e.vapid_key)}},{key:"init",value:function(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.env=t,i.signing_key=n,G=new Date;var o=E.get_cookie(e);L||(L={},this.setCustomConfig(i)),o||(o=E.uuid(),E.set_cookie(e,o)),L.distinct_id=o,this.user=new R(L),this.sw=new F(L),this.sw.update_subscription(),r.setEnvProperties(),E.schedule_flush()}},{key:"set_super_properties",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=E.get_parsed_local_store_data(o),t=V(V({},r),e);E.set_local_storage_item(o,JSON.stringify(t)),L.env_properties=V(V({},L.env_properties),t)}},{key:"identify",value:function(r){L._user_identified||(E.batch_or_call({env:l.env_key,event:"$identify",properties:{$identified_id:r,$anon_id:L.distinct_id}}),E.set_cookie(e,r),L.distinct_id=r,L._user_identified=!0)}},{key:"track",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=e){var t=E.get_parsed_local_store_data(o),n=E.format_props(V(V(V(V({},r),L.env_properties),t),{},{$current_url:window.location.href}));E.batch_or_call({event:String(e),distinct_id:L.distinct_id,env:l.env_key,properties:n,$insert_id:E.uuid(),$time:E.epoch_milliseconds()})}}},{key:"reset",value:function(){var t=E.uuid();E.set_cookie(e,t),L={distinct_id:t,_user_identified:!1},E.remove_local_storage_item(o),this.user=new R(L),this.sw=new F(L),r.setEnvProperties()}}])&&H(t.prototype,n),i&&H(t,i),r}())}(),window.suprsend=n}();
|
package/dist/cjs_bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";var e={147:function(e){e.exports=JSON.parse('{"name":"@suprsend/web-sdk","version":"0.1.10","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 R},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"]},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 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: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),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){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 e.next=2,n._ask_notification_permission();case 2:if("granted"!==e.sent){e.next=17;break}return e.next=6,n._get_subscription();case 6:if(e.sent){e.next=16;break}return console.log("API_CALL: get public vapid from server"),t=w.urlB64ToUint8Array("BADMgGsRZWdjJPH34F0v9OTQfrxHArhk_sVawIACOFHTcaPF_Cfpq1uBX6lOwHByQDjt8f05h3ESK3dldpG3Q9Q"),e.next=12,r.pushManager.subscribe({applicationServerKey:t,userVisibleOnly:!0});case 12:i=e.sent,n.user.add_webpush(i),e.next=17;break;case 16:console.log("Push already subscribed");case 17:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),A(this,"register_push",(function(){n._check_push_support()?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?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 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){D(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 D(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var N,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)),N.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);N||(r.ENV_API_KEY=t,N={}),n||(n=w.uuid(),w.set_cookie(e,n)),N.distinct_id=n,this.user=new j(r.ENV_API_KEY,N),this.sw=new $(r.ENV_API_KEY,N),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)),N.env_properties=I(I({},N.env_properties),t)}},{key:"identify",value:function(t){N._user_identified||(w.batch_or_call({env:r.ENV_API_KEY,event:"$identify",properties:{$identified_id:t,$anon_id:N.distinct_id}}),w.set_cookie(e,t),N.distinct_id=t,N._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),N.env_properties),n),{},{$current_url:window.location.href}));w.batch_or_call({event:String(e),distinct_id:N.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),N={distinct_id:t,_user_identified:!1},w.remove_local_storage_item(o),this.user=new j(r.ENV_API_KEY,N),this.sw=new $(r.ENV_API_KEY,N),r.setEnvProperties()}}])&&C(t.prototype,n),i&&C(t,i),r}();D(K,"ENV_API_KEY",void 0);const R=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.14","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 q},init_at:function(){return G}});var e="_suprsend_dist_id",r="_bulk_api_call",i="event/",o="_suprsend_super_props",a="_suprsend_device_id",u={Edge:["Edge"],"Opera Mini":["Opera Mini"],"Opera Mobile":["Opera Mobi"],Opera:["Opera"],"Internet Explorer":["Trident","MSIE"],Chrome:["Chrome"],Firefox:["Firefox"],Safari:["Safari"],Mozilla:["Mozilla"]},s={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://hub.suprsend.com",sdk_version:t(147).version,batch_size:20,service_worker_file:"suprsend_service_worker.js",sw_delay:5e3};function f(e,r,t,n,i,o,a){try{var u=e[o](a),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,i)}function p(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){f(o,n,i,a,u,"next",e)}function u(e){f(o,n,i,a,u,"throw",e)}a(void 0)}))}}function d(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return v(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)?v(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(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}var h=function(e){function r(e,r){return e<<r|e>>>32-r}function t(e,r){var t,n,i,o,a;return i=2147483648&e,o=2147483648&r,a=(1073741823&e)+(1073741823&r),(t=1073741824&e)&(n=1073741824&r)?2147483648^a^i^o:t|n?1073741824&a?3221225472^a^i^o:1073741824^a^i^o:a^i^o}function n(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return e&r|~e&t}(n,i,o),a),s)),t(r(e,u),n)}function i(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return e&t|r&~t}(n,i,o),a),s)),t(r(e,u),n)}function o(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return e^r^t}(n,i,o),a),s)),t(r(e,u),n)}function a(e,n,i,o,a,u,s){return e=t(e,t(t(function(e,r,t){return r^(e|~t)}(n,i,o),a),s)),t(r(e,u),n)}function u(e){var r,t="",n="";for(r=0;r<=3;r++)t+=(n="0"+(e>>>8*r&255).toString(16)).substr(n.length-2,2);return t}var s,c,l,f,p,d,v,h,_,g=Array();for(g=function(e){for(var r,t=e.length,n=t+8,i=16*((n-n%64)/64+1),o=Array(i-1),a=0,u=0;u<t;)a=u%4*8,o[r=(u-u%4)/4]=o[r]|e.charCodeAt(u)<<a,u++;return a=u%4*8,o[r=(u-u%4)/4]=o[r]|128<<a,o[i-2]=t<<3,o[i-1]=t>>>29,o}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var r="",t=0;t<e.length;t++){var n=e.charCodeAt(t);n<128?r+=String.fromCharCode(n):n>127&&n<2048?(r+=String.fromCharCode(n>>6|192),r+=String.fromCharCode(63&n|128)):(r+=String.fromCharCode(n>>12|224),r+=String.fromCharCode(n>>6&63|128),r+=String.fromCharCode(63&n|128))}return r}(e)),d=1732584193,v=4023233417,h=2562383102,_=271733878,s=0;s<g.length;s+=16)c=d,l=v,f=h,p=_,d=n(d,v,h,_,g[s+0],7,3614090360),_=n(_,d,v,h,g[s+1],12,3905402710),h=n(h,_,d,v,g[s+2],17,606105819),v=n(v,h,_,d,g[s+3],22,3250441966),d=n(d,v,h,_,g[s+4],7,4118548399),_=n(_,d,v,h,g[s+5],12,1200080426),h=n(h,_,d,v,g[s+6],17,2821735955),v=n(v,h,_,d,g[s+7],22,4249261313),d=n(d,v,h,_,g[s+8],7,1770035416),_=n(_,d,v,h,g[s+9],12,2336552879),h=n(h,_,d,v,g[s+10],17,4294925233),v=n(v,h,_,d,g[s+11],22,2304563134),d=n(d,v,h,_,g[s+12],7,1804603682),_=n(_,d,v,h,g[s+13],12,4254626195),h=n(h,_,d,v,g[s+14],17,2792965006),d=i(d,v=n(v,h,_,d,g[s+15],22,1236535329),h,_,g[s+1],5,4129170786),_=i(_,d,v,h,g[s+6],9,3225465664),h=i(h,_,d,v,g[s+11],14,643717713),v=i(v,h,_,d,g[s+0],20,3921069994),d=i(d,v,h,_,g[s+5],5,3593408605),_=i(_,d,v,h,g[s+10],9,38016083),h=i(h,_,d,v,g[s+15],14,3634488961),v=i(v,h,_,d,g[s+4],20,3889429448),d=i(d,v,h,_,g[s+9],5,568446438),_=i(_,d,v,h,g[s+14],9,3275163606),h=i(h,_,d,v,g[s+3],14,4107603335),v=i(v,h,_,d,g[s+8],20,1163531501),d=i(d,v,h,_,g[s+13],5,2850285829),_=i(_,d,v,h,g[s+2],9,4243563512),h=i(h,_,d,v,g[s+7],14,1735328473),d=o(d,v=i(v,h,_,d,g[s+12],20,2368359562),h,_,g[s+5],4,4294588738),_=o(_,d,v,h,g[s+8],11,2272392833),h=o(h,_,d,v,g[s+11],16,1839030562),v=o(v,h,_,d,g[s+14],23,4259657740),d=o(d,v,h,_,g[s+1],4,2763975236),_=o(_,d,v,h,g[s+4],11,1272893353),h=o(h,_,d,v,g[s+7],16,4139469664),v=o(v,h,_,d,g[s+10],23,3200236656),d=o(d,v,h,_,g[s+13],4,681279174),_=o(_,d,v,h,g[s+0],11,3936430074),h=o(h,_,d,v,g[s+3],16,3572445317),v=o(v,h,_,d,g[s+6],23,76029189),d=o(d,v,h,_,g[s+9],4,3654602809),_=o(_,d,v,h,g[s+12],11,3873151461),h=o(h,_,d,v,g[s+15],16,530742520),d=a(d,v=o(v,h,_,d,g[s+2],23,3299628645),h,_,g[s+0],6,4096336452),_=a(_,d,v,h,g[s+7],10,1126891415),h=a(h,_,d,v,g[s+14],15,2878612391),v=a(v,h,_,d,g[s+5],21,4237533241),d=a(d,v,h,_,g[s+12],6,1700485571),_=a(_,d,v,h,g[s+3],10,2399980690),h=a(h,_,d,v,g[s+10],15,4293915773),v=a(v,h,_,d,g[s+1],21,2240044497),d=a(d,v,h,_,g[s+8],6,1873313359),_=a(_,d,v,h,g[s+15],10,4264355552),h=a(h,_,d,v,g[s+6],15,2734768916),v=a(v,h,_,d,g[s+13],21,1309151649),d=a(d,v,h,_,g[s+4],6,4149444226),_=a(_,d,v,h,g[s+11],10,3174756917),h=a(h,_,d,v,g[s+2],15,718787259),v=a(v,h,_,d,g[s+9],21,3951481745),d=t(d,c),v=t(v,l),h=t(h,f),_=t(_,p);return(u(d)+u(v)+u(h)+u(_)).toLowerCase()},_=function(e){return new Uint8Array(d(unescape(encodeURIComponent(e))).map((function(e){return e.charCodeAt(0)})))};function g(e,r,t){return y.apply(this,arguments)}function y(){return(y=p(regeneratorRuntime.mark((function e(r,t,n){var o,a,u,s,c,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(window.crypto){e.next=2;break}return e.abrupt("return");case 2:return o=l.signing_key,a="".concat(n,"\n").concat(h(r),"\napplication/json\n").concat(t,"\n/").concat(i),u=_(o),s=_(a),e.next=8,crypto.subtle.importKey("raw",u,{name:"HMAC",hash:"SHA-256"},!0,["sign"]);case 8:return c=e.sent,e.next=11,crypto.subtle.sign("HMAC",c,s);case 11:return f=e.sent,d(new Uint8Array(f)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),e.abrupt("return",window.btoa(String.fromCharCode.apply(String,d(new Uint8Array(f)))));case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function b(e,r,t,n,i,o,a){try{var u=e[o](a),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,i)}function m(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){b(o,n,i,a,u,"next",e)}function u(e){b(o,n,i,a,u,"throw",e)}a(void 0)}))}}function w(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 k(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)?k(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,u=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){u=!0,o=e},f:function(){try{a||null==t.return||t.return()}finally{if(u)throw o}}}}function k(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 O(){var e=!0;try{window.localStorage}catch(r){e=!1}return e}function x(e){if(O())return localStorage.getItem(e)}function S(e,r){O()&&localStorage.setItem(e,r)}function j(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=x(e);return t?JSON.parse(t):r}function C(){var e=navigator.userAgent;for(var r in u){var t,n=w(u[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 P(e,r){return A.apply(this,arguments)}function A(){return(A=m(regeneratorRuntime.mark((function e(r,t){var n,i,o,a,u,s,c,f=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=f.length>2&&void 0!==f[2]?f[2]:"POST",a=(new Date).toGMTString(),u=JSON.stringify(t),e.next=5,g(u,a,"POST");case 5:return s=e.sent,c=s?"".concat(null===(n=t[0])||void 0===n?void 0:n.env,":").concat(s):null===(i=t[0])||void 0===i?void 0:i.env,e.abrupt("return",fetch("".concat(l.api_url,"/").concat(r),{method:o,body:u,headers:{"Content-Type":"application/json",Authorization:c,"x-amz-date":a}}));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function M(){var e=j(r,[]);if(e.length){var t=e.slice(0,l.batch_size);P(i,t).then((function(e){if(!e.ok)throw new Error("Error in Fetch");var t=j(r,[]);t.splice(0,l.batch_size),S(r,JSON.stringify(t)),M()})).catch((function(){$(12e4)}))}else $()}function $(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;setTimeout((function(){M()}),e)}const E={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:O,get_local_storage_item:x,set_local_storage_item:S,remove_local_storage_item:function(e){O()&&localStorage.removeItem(e)},get_parsed_local_store_data:j,browser:C,browser_version:function(){var e=navigator.userAgent,r=C(),t=s[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:$,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=window.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(O()){var t=j(r,[]);null==t||t.push(e),S(r,JSON.stringify(t))}else P(i,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 D(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function I(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 R=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.instance=r}var r,t;return r=e,(t=[{key:"_call_indetity",value:function(e){E.batch_or_call(function(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){D(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}({env:l.env_key,distinct_id:this.instance.distinct_id},e))}},{key:"set",value:function(e,r){var t=E.format_props(e,r);t&&this._call_indetity({$set:t})}},{key:"set_once",value:function(e,r){var t=E.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=E.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=E.format_props(e,r);t&&this._call_indetity({$append:t})}},{key:"remove",value:function(e,r){var t=E.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})}}])&&I(r.prototype,t),e}();function U(e,r,t,n,i,o,a){try{var u=e[o](a),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,i)}function z(e){return function(){var r=this,t=arguments;return new Promise((function(n,i){var o=e.apply(r,t);function a(e){U(o,n,i,a,u,"next",e)}function u(e){U(o,n,i,a,u,"throw",e)}a(void 0)}))}}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 J(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var W;const F=function(){function e(r){var t=this;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),J(this,"_check_push_support",(function(){return!(!("serviceWorker"in navigator)||!("PushManager"in window))})),J(this,"_ask_notification_permission",z(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)})))),J(this,"_register_sw",(function(){return navigator.serviceWorker.register("/".concat(l.service_worker_file)).then((function(e){console.log("Service worker successfully registered."),t._subscribe_push(e)})).catch((function(e){console.error("Unable to register service worker.",e)}))})),J(this,"_get_subscription",(function(){return navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription()})).then(function(){var e=z(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)}}())})),J(this,"_subscribe_push",function(){var e=z(regeneratorRuntime.mark((function e(r){var n,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._ask_notification_permission();case 2:if("granted"!==e.sent){e.next=19;break}return e.next=6,t._get_subscription();case 6:if(e.sent){e.next=18;break}if(l.vapid_key){e.next=11;break}return console.log("Provide vapid key while calling init"),e.abrupt("return");case 11:return n=E.urlB64ToUint8Array(l.vapid_key),e.next=14,r.pushManager.subscribe({applicationServerKey:n,userVisibleOnly:!0});case 14:i=e.sent,t.user.add_webpush(i),e.next=19;break;case 18:console.log("Push already subscribed");case 19:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),J(this,"register_push",(function(){t._check_push_support()?t._subscribe_with_delay():console.log("OOPS, Web Push isn't supported")})),J(this,"is_subscribed",z(regeneratorRuntime.mark((function e(){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._get_subscription();case 2:return r=e.sent,e.abrupt("return",!!r);case 4:case"end":return e.stop()}}),e)})))),this.instance=r,this.user=new R(r)}var r,t;return r=e,(t=[{key:"_subscribe_with_delay",value:function(){var e=this,r=new Date-G;r>=l.sw_delay?this._register_sw():(clearTimeout(W),W=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)}))}}])&&N(r.prototype,t),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 V(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){B(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}function B(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function H(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)}}var L,G;const q=new(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=E.get_local_storage_item(a);e||(e=E.uuid(),E.set_local_storage_item(a,e)),L.env_properties={$os:E.os(),$browser:E.browser(),$browser_version:E.browser_version(),$sdk_type:"Browser",$device_id:e,$sdk_version:l.sdk_version}}}],(n=[{key:"setCustomConfigProperty",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(r)l[e]=r;else if(t)throw Error("Mandatory Key Missing:",e)}},{key:"setCustomConfig",value:function(e){this.setCustomConfigProperty("env_key",e.env,!0),this.setCustomConfigProperty("signing_key",e.signing_key,!0),this.setCustomConfigProperty("api_url",null==e?void 0:e.api_url),this.setCustomConfigProperty("vapid_key",null==e?void 0:e.vapid_key)}},{key:"init",value:function(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.env=t,i.signing_key=n,G=new Date;var o=E.get_cookie(e);L||(L={},this.setCustomConfig(i)),o||(o=E.uuid(),E.set_cookie(e,o)),L.distinct_id=o,this.user=new R(L),this.sw=new F(L),this.sw.update_subscription(),r.setEnvProperties(),E.schedule_flush()}},{key:"set_super_properties",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=E.get_parsed_local_store_data(o),t=V(V({},r),e);E.set_local_storage_item(o,JSON.stringify(t)),L.env_properties=V(V({},L.env_properties),t)}},{key:"identify",value:function(r){L._user_identified||(E.batch_or_call({env:l.env_key,event:"$identify",properties:{$identified_id:r,$anon_id:L.distinct_id}}),E.set_cookie(e,r),L.distinct_id=r,L._user_identified=!0)}},{key:"track",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null!=e){var t=E.get_parsed_local_store_data(o),n=E.format_props(V(V(V(V({},r),L.env_properties),t),{},{$current_url:window.location.href}));E.batch_or_call({event:String(e),distinct_id:L.distinct_id,env:l.env_key,properties:n,$insert_id:E.uuid(),$time:E.epoch_milliseconds()})}}},{key:"reset",value:function(){var t=E.uuid();E.set_cookie(e,t),L={distinct_id:t,_user_identified:!1},E.remove_local_storage_item(o),this.user=new R(L),this.sw=new F(L),r.setEnvProperties()}}])&&H(t.prototype,n),i&&H(t,i),r}())}();var i=exports;for(var o in n)i[o]=n[o];n.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})}();
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -2,11 +2,11 @@ const package_data = require("../package.json");
|
|
|
2
2
|
|
|
3
3
|
// suprsend sdk related config
|
|
4
4
|
const config = {
|
|
5
|
-
api_url: "https://
|
|
5
|
+
api_url: "https://hub.suprsend.com",
|
|
6
6
|
sdk_version: package_data.version,
|
|
7
7
|
batch_size: 20,
|
|
8
8
|
service_worker_file: "suprsend_service_worker.js",
|
|
9
|
-
sw_delay: 5000, //in ms
|
|
9
|
+
sw_delay: 5000, //in ms,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export default config;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import config from "./config";
|
|
2
|
+
import { constants } from "./constants";
|
|
3
|
+
|
|
4
|
+
var MD5 = function (string) {
|
|
5
|
+
function RotateLeft(lValue, iShiftBits) {
|
|
6
|
+
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function AddUnsigned(lX, lY) {
|
|
10
|
+
var lX4, lY4, lX8, lY8, lResult;
|
|
11
|
+
lX8 = lX & 0x80000000;
|
|
12
|
+
lY8 = lY & 0x80000000;
|
|
13
|
+
lX4 = lX & 0x40000000;
|
|
14
|
+
lY4 = lY & 0x40000000;
|
|
15
|
+
lResult = (lX & 0x3fffffff) + (lY & 0x3fffffff);
|
|
16
|
+
if (lX4 & lY4) {
|
|
17
|
+
return lResult ^ 0x80000000 ^ lX8 ^ lY8;
|
|
18
|
+
}
|
|
19
|
+
if (lX4 | lY4) {
|
|
20
|
+
if (lResult & 0x40000000) {
|
|
21
|
+
return lResult ^ 0xc0000000 ^ lX8 ^ lY8;
|
|
22
|
+
} else {
|
|
23
|
+
return lResult ^ 0x40000000 ^ lX8 ^ lY8;
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
return lResult ^ lX8 ^ lY8;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function F(x, y, z) {
|
|
31
|
+
return (x & y) | (~x & z);
|
|
32
|
+
}
|
|
33
|
+
function G(x, y, z) {
|
|
34
|
+
return (x & z) | (y & ~z);
|
|
35
|
+
}
|
|
36
|
+
function H(x, y, z) {
|
|
37
|
+
return x ^ y ^ z;
|
|
38
|
+
}
|
|
39
|
+
function I(x, y, z) {
|
|
40
|
+
return y ^ (x | ~z);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function FF(a, b, c, d, x, s, ac) {
|
|
44
|
+
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
|
|
45
|
+
return AddUnsigned(RotateLeft(a, s), b);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function GG(a, b, c, d, x, s, ac) {
|
|
49
|
+
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
|
|
50
|
+
return AddUnsigned(RotateLeft(a, s), b);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function HH(a, b, c, d, x, s, ac) {
|
|
54
|
+
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
|
|
55
|
+
return AddUnsigned(RotateLeft(a, s), b);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function II(a, b, c, d, x, s, ac) {
|
|
59
|
+
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
|
|
60
|
+
return AddUnsigned(RotateLeft(a, s), b);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ConvertToWordArray(string) {
|
|
64
|
+
var lWordCount;
|
|
65
|
+
var lMessageLength = string.length;
|
|
66
|
+
var lNumberOfWords_temp1 = lMessageLength + 8;
|
|
67
|
+
var lNumberOfWords_temp2 =
|
|
68
|
+
(lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
|
|
69
|
+
var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
|
|
70
|
+
var lWordArray = Array(lNumberOfWords - 1);
|
|
71
|
+
var lBytePosition = 0;
|
|
72
|
+
var lByteCount = 0;
|
|
73
|
+
while (lByteCount < lMessageLength) {
|
|
74
|
+
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
|
75
|
+
lBytePosition = (lByteCount % 4) * 8;
|
|
76
|
+
lWordArray[lWordCount] =
|
|
77
|
+
lWordArray[lWordCount] |
|
|
78
|
+
(string.charCodeAt(lByteCount) << lBytePosition);
|
|
79
|
+
lByteCount++;
|
|
80
|
+
}
|
|
81
|
+
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
|
82
|
+
lBytePosition = (lByteCount % 4) * 8;
|
|
83
|
+
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
|
|
84
|
+
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
|
|
85
|
+
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
|
|
86
|
+
return lWordArray;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function WordToHex(lValue) {
|
|
90
|
+
var WordToHexValue = "",
|
|
91
|
+
WordToHexValue_temp = "",
|
|
92
|
+
lByte,
|
|
93
|
+
lCount;
|
|
94
|
+
for (lCount = 0; lCount <= 3; lCount++) {
|
|
95
|
+
lByte = (lValue >>> (lCount * 8)) & 255;
|
|
96
|
+
WordToHexValue_temp = "0" + lByte.toString(16);
|
|
97
|
+
WordToHexValue =
|
|
98
|
+
WordToHexValue +
|
|
99
|
+
WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
|
|
100
|
+
}
|
|
101
|
+
return WordToHexValue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function Utf8Encode(string) {
|
|
105
|
+
string = string.replace(/\r\n/g, "\n");
|
|
106
|
+
var utftext = "";
|
|
107
|
+
|
|
108
|
+
for (var n = 0; n < string.length; n++) {
|
|
109
|
+
var c = string.charCodeAt(n);
|
|
110
|
+
|
|
111
|
+
if (c < 128) {
|
|
112
|
+
utftext += String.fromCharCode(c);
|
|
113
|
+
} else if (c > 127 && c < 2048) {
|
|
114
|
+
utftext += String.fromCharCode((c >> 6) | 192);
|
|
115
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
|
116
|
+
} else {
|
|
117
|
+
utftext += String.fromCharCode((c >> 12) | 224);
|
|
118
|
+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
119
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return utftext;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
var x = Array();
|
|
127
|
+
var k, AA, BB, CC, DD, a, b, c, d;
|
|
128
|
+
var S11 = 7,
|
|
129
|
+
S12 = 12,
|
|
130
|
+
S13 = 17,
|
|
131
|
+
S14 = 22;
|
|
132
|
+
var S21 = 5,
|
|
133
|
+
S22 = 9,
|
|
134
|
+
S23 = 14,
|
|
135
|
+
S24 = 20;
|
|
136
|
+
var S31 = 4,
|
|
137
|
+
S32 = 11,
|
|
138
|
+
S33 = 16,
|
|
139
|
+
S34 = 23;
|
|
140
|
+
var S41 = 6,
|
|
141
|
+
S42 = 10,
|
|
142
|
+
S43 = 15,
|
|
143
|
+
S44 = 21;
|
|
144
|
+
|
|
145
|
+
string = Utf8Encode(string);
|
|
146
|
+
|
|
147
|
+
x = ConvertToWordArray(string);
|
|
148
|
+
|
|
149
|
+
a = 0x67452301;
|
|
150
|
+
b = 0xefcdab89;
|
|
151
|
+
c = 0x98badcfe;
|
|
152
|
+
d = 0x10325476;
|
|
153
|
+
|
|
154
|
+
for (k = 0; k < x.length; k += 16) {
|
|
155
|
+
AA = a;
|
|
156
|
+
BB = b;
|
|
157
|
+
CC = c;
|
|
158
|
+
DD = d;
|
|
159
|
+
a = FF(a, b, c, d, x[k + 0], S11, 0xd76aa478);
|
|
160
|
+
d = FF(d, a, b, c, x[k + 1], S12, 0xe8c7b756);
|
|
161
|
+
c = FF(c, d, a, b, x[k + 2], S13, 0x242070db);
|
|
162
|
+
b = FF(b, c, d, a, x[k + 3], S14, 0xc1bdceee);
|
|
163
|
+
a = FF(a, b, c, d, x[k + 4], S11, 0xf57c0faf);
|
|
164
|
+
d = FF(d, a, b, c, x[k + 5], S12, 0x4787c62a);
|
|
165
|
+
c = FF(c, d, a, b, x[k + 6], S13, 0xa8304613);
|
|
166
|
+
b = FF(b, c, d, a, x[k + 7], S14, 0xfd469501);
|
|
167
|
+
a = FF(a, b, c, d, x[k + 8], S11, 0x698098d8);
|
|
168
|
+
d = FF(d, a, b, c, x[k + 9], S12, 0x8b44f7af);
|
|
169
|
+
c = FF(c, d, a, b, x[k + 10], S13, 0xffff5bb1);
|
|
170
|
+
b = FF(b, c, d, a, x[k + 11], S14, 0x895cd7be);
|
|
171
|
+
a = FF(a, b, c, d, x[k + 12], S11, 0x6b901122);
|
|
172
|
+
d = FF(d, a, b, c, x[k + 13], S12, 0xfd987193);
|
|
173
|
+
c = FF(c, d, a, b, x[k + 14], S13, 0xa679438e);
|
|
174
|
+
b = FF(b, c, d, a, x[k + 15], S14, 0x49b40821);
|
|
175
|
+
a = GG(a, b, c, d, x[k + 1], S21, 0xf61e2562);
|
|
176
|
+
d = GG(d, a, b, c, x[k + 6], S22, 0xc040b340);
|
|
177
|
+
c = GG(c, d, a, b, x[k + 11], S23, 0x265e5a51);
|
|
178
|
+
b = GG(b, c, d, a, x[k + 0], S24, 0xe9b6c7aa);
|
|
179
|
+
a = GG(a, b, c, d, x[k + 5], S21, 0xd62f105d);
|
|
180
|
+
d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
|
|
181
|
+
c = GG(c, d, a, b, x[k + 15], S23, 0xd8a1e681);
|
|
182
|
+
b = GG(b, c, d, a, x[k + 4], S24, 0xe7d3fbc8);
|
|
183
|
+
a = GG(a, b, c, d, x[k + 9], S21, 0x21e1cde6);
|
|
184
|
+
d = GG(d, a, b, c, x[k + 14], S22, 0xc33707d6);
|
|
185
|
+
c = GG(c, d, a, b, x[k + 3], S23, 0xf4d50d87);
|
|
186
|
+
b = GG(b, c, d, a, x[k + 8], S24, 0x455a14ed);
|
|
187
|
+
a = GG(a, b, c, d, x[k + 13], S21, 0xa9e3e905);
|
|
188
|
+
d = GG(d, a, b, c, x[k + 2], S22, 0xfcefa3f8);
|
|
189
|
+
c = GG(c, d, a, b, x[k + 7], S23, 0x676f02d9);
|
|
190
|
+
b = GG(b, c, d, a, x[k + 12], S24, 0x8d2a4c8a);
|
|
191
|
+
a = HH(a, b, c, d, x[k + 5], S31, 0xfffa3942);
|
|
192
|
+
d = HH(d, a, b, c, x[k + 8], S32, 0x8771f681);
|
|
193
|
+
c = HH(c, d, a, b, x[k + 11], S33, 0x6d9d6122);
|
|
194
|
+
b = HH(b, c, d, a, x[k + 14], S34, 0xfde5380c);
|
|
195
|
+
a = HH(a, b, c, d, x[k + 1], S31, 0xa4beea44);
|
|
196
|
+
d = HH(d, a, b, c, x[k + 4], S32, 0x4bdecfa9);
|
|
197
|
+
c = HH(c, d, a, b, x[k + 7], S33, 0xf6bb4b60);
|
|
198
|
+
b = HH(b, c, d, a, x[k + 10], S34, 0xbebfbc70);
|
|
199
|
+
a = HH(a, b, c, d, x[k + 13], S31, 0x289b7ec6);
|
|
200
|
+
d = HH(d, a, b, c, x[k + 0], S32, 0xeaa127fa);
|
|
201
|
+
c = HH(c, d, a, b, x[k + 3], S33, 0xd4ef3085);
|
|
202
|
+
b = HH(b, c, d, a, x[k + 6], S34, 0x4881d05);
|
|
203
|
+
a = HH(a, b, c, d, x[k + 9], S31, 0xd9d4d039);
|
|
204
|
+
d = HH(d, a, b, c, x[k + 12], S32, 0xe6db99e5);
|
|
205
|
+
c = HH(c, d, a, b, x[k + 15], S33, 0x1fa27cf8);
|
|
206
|
+
b = HH(b, c, d, a, x[k + 2], S34, 0xc4ac5665);
|
|
207
|
+
a = II(a, b, c, d, x[k + 0], S41, 0xf4292244);
|
|
208
|
+
d = II(d, a, b, c, x[k + 7], S42, 0x432aff97);
|
|
209
|
+
c = II(c, d, a, b, x[k + 14], S43, 0xab9423a7);
|
|
210
|
+
b = II(b, c, d, a, x[k + 5], S44, 0xfc93a039);
|
|
211
|
+
a = II(a, b, c, d, x[k + 12], S41, 0x655b59c3);
|
|
212
|
+
d = II(d, a, b, c, x[k + 3], S42, 0x8f0ccc92);
|
|
213
|
+
c = II(c, d, a, b, x[k + 10], S43, 0xffeff47d);
|
|
214
|
+
b = II(b, c, d, a, x[k + 1], S44, 0x85845dd1);
|
|
215
|
+
a = II(a, b, c, d, x[k + 8], S41, 0x6fa87e4f);
|
|
216
|
+
d = II(d, a, b, c, x[k + 15], S42, 0xfe2ce6e0);
|
|
217
|
+
c = II(c, d, a, b, x[k + 6], S43, 0xa3014314);
|
|
218
|
+
b = II(b, c, d, a, x[k + 13], S44, 0x4e0811a1);
|
|
219
|
+
a = II(a, b, c, d, x[k + 4], S41, 0xf7537e82);
|
|
220
|
+
d = II(d, a, b, c, x[k + 11], S42, 0xbd3af235);
|
|
221
|
+
c = II(c, d, a, b, x[k + 2], S43, 0x2ad7d2bb);
|
|
222
|
+
b = II(b, c, d, a, x[k + 9], S44, 0xeb86d391);
|
|
223
|
+
a = AddUnsigned(a, AA);
|
|
224
|
+
b = AddUnsigned(b, BB);
|
|
225
|
+
c = AddUnsigned(c, CC);
|
|
226
|
+
d = AddUnsigned(d, DD);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
|
|
230
|
+
|
|
231
|
+
return temp.toLowerCase();
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const getUtf8Bytes = (str) =>
|
|
235
|
+
new Uint8Array(
|
|
236
|
+
[...unescape(encodeURIComponent(str))].map((c) => c.charCodeAt(0))
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
export default async function create_signature(str, date, method) {
|
|
240
|
+
if (!window.crypto) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const key = config.signing_key;
|
|
244
|
+
const message = `${method}\n${MD5(str)}\napplication/json\n${date}\n/${
|
|
245
|
+
constants.api_events_route
|
|
246
|
+
}`;
|
|
247
|
+
|
|
248
|
+
const keyBytes = getUtf8Bytes(key);
|
|
249
|
+
const messageBytes = getUtf8Bytes(message);
|
|
250
|
+
|
|
251
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
252
|
+
"raw",
|
|
253
|
+
keyBytes,
|
|
254
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
255
|
+
true,
|
|
256
|
+
["sign"]
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const sig = await crypto.subtle.sign("HMAC", cryptoKey, messageBytes);
|
|
260
|
+
|
|
261
|
+
// to lowercase hexits
|
|
262
|
+
[...new Uint8Array(sig)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
263
|
+
|
|
264
|
+
// to base64
|
|
265
|
+
return window.btoa(String.fromCharCode(...new Uint8Array(sig)));
|
|
266
|
+
}
|
package/src/index.js
CHANGED
|
@@ -8,7 +8,22 @@ var suprSendInstance;
|
|
|
8
8
|
export var init_at;
|
|
9
9
|
|
|
10
10
|
class SuprSend {
|
|
11
|
-
|
|
11
|
+
setCustomConfigProperty(key, value = "", mandatory = false) {
|
|
12
|
+
if (value) {
|
|
13
|
+
config[key] = value;
|
|
14
|
+
} else {
|
|
15
|
+
if (mandatory) {
|
|
16
|
+
throw Error("Mandatory Key Missing:", key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setCustomConfig(config_keys) {
|
|
22
|
+
this.setCustomConfigProperty("env_key", config_keys.env, true);
|
|
23
|
+
this.setCustomConfigProperty("signing_key", config_keys.signing_key, true);
|
|
24
|
+
this.setCustomConfigProperty("api_url", config_keys?.api_url);
|
|
25
|
+
this.setCustomConfigProperty("vapid_key", config_keys?.vapid_key);
|
|
26
|
+
}
|
|
12
27
|
|
|
13
28
|
static setEnvProperties() {
|
|
14
29
|
let device_id = utils.get_local_storage_item(constants.device_id_key);
|
|
@@ -26,20 +41,22 @@ class SuprSend {
|
|
|
26
41
|
};
|
|
27
42
|
}
|
|
28
43
|
|
|
29
|
-
|
|
44
|
+
init(ENV_API_KEY, SIGNING_KEY, config_keys = {}) {
|
|
45
|
+
config_keys.env = ENV_API_KEY;
|
|
46
|
+
config_keys.signing_key = SIGNING_KEY;
|
|
30
47
|
init_at = new Date();
|
|
31
48
|
var distinct_id = utils.get_cookie(constants.distinct_id);
|
|
32
49
|
if (!suprSendInstance) {
|
|
33
|
-
SuprSend.ENV_API_KEY = ENV_API_KEY;
|
|
34
50
|
suprSendInstance = {};
|
|
51
|
+
this.setCustomConfig(config_keys);
|
|
35
52
|
}
|
|
36
53
|
if (!distinct_id) {
|
|
37
54
|
distinct_id = utils.uuid();
|
|
38
55
|
utils.set_cookie(constants.distinct_id, distinct_id);
|
|
39
56
|
}
|
|
40
57
|
suprSendInstance.distinct_id = distinct_id;
|
|
41
|
-
this.user = new User(
|
|
42
|
-
this.sw = new ServiceWorker(
|
|
58
|
+
this.user = new User(suprSendInstance);
|
|
59
|
+
this.sw = new ServiceWorker(suprSendInstance);
|
|
43
60
|
this.sw.update_subscription();
|
|
44
61
|
SuprSend.setEnvProperties();
|
|
45
62
|
utils.schedule_flush();
|
|
@@ -63,7 +80,7 @@ class SuprSend {
|
|
|
63
80
|
identify(unique_id) {
|
|
64
81
|
if (!suprSendInstance._user_identified) {
|
|
65
82
|
utils.batch_or_call({
|
|
66
|
-
env:
|
|
83
|
+
env: config.env_key,
|
|
67
84
|
event: "$identify",
|
|
68
85
|
properties: {
|
|
69
86
|
$identified_id: unique_id,
|
|
@@ -90,7 +107,7 @@ class SuprSend {
|
|
|
90
107
|
utils.batch_or_call({
|
|
91
108
|
event: String(event),
|
|
92
109
|
distinct_id: suprSendInstance.distinct_id,
|
|
93
|
-
env:
|
|
110
|
+
env: config.env_key,
|
|
94
111
|
properties: formatted_data,
|
|
95
112
|
$insert_id: utils.uuid(),
|
|
96
113
|
$time: utils.epoch_milliseconds(),
|
|
@@ -106,8 +123,8 @@ class SuprSend {
|
|
|
106
123
|
_user_identified: false,
|
|
107
124
|
};
|
|
108
125
|
utils.remove_local_storage_item(constants.super_properties_key);
|
|
109
|
-
this.user = new User(
|
|
110
|
-
this.sw = new ServiceWorker(
|
|
126
|
+
this.user = new User(suprSendInstance);
|
|
127
|
+
this.sw = new ServiceWorker(suprSendInstance);
|
|
111
128
|
SuprSend.setEnvProperties();
|
|
112
129
|
}
|
|
113
130
|
}
|
package/src/service_worker.js
CHANGED
|
@@ -5,10 +5,9 @@ import { init_at } from "./index";
|
|
|
5
5
|
|
|
6
6
|
var notification_timer;
|
|
7
7
|
class ServiceWorker {
|
|
8
|
-
constructor(
|
|
9
|
-
this.env = env_key;
|
|
8
|
+
constructor(instance) {
|
|
10
9
|
this.instance = instance;
|
|
11
|
-
this.user = new User(
|
|
10
|
+
this.user = new User(instance);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
_check_push_support = () => {
|
|
@@ -66,10 +65,11 @@ class ServiceWorker {
|
|
|
66
65
|
if (permission === "granted") {
|
|
67
66
|
const subscription = await this._get_subscription();
|
|
68
67
|
if (!subscription) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
if (!config.vapid_key) {
|
|
69
|
+
console.log("Provide vapid key while calling init");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const applicationServerKey = utils.urlB64ToUint8Array(config.vapid_key);
|
|
73
73
|
const subscription = await reg.pushManager.subscribe({
|
|
74
74
|
applicationServerKey,
|
|
75
75
|
userVisibleOnly: true,
|
|
@@ -91,7 +91,6 @@ class ServiceWorker {
|
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
this.user.add_webpush(subscription);
|
|
94
|
-
console.log("API_CALL: save subscription", subscription);
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
96
|
|
package/src/user.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import utils from "./utils";
|
|
2
|
+
import config from "./config";
|
|
2
3
|
|
|
3
4
|
class User {
|
|
4
|
-
constructor(
|
|
5
|
-
this.env = env_key;
|
|
5
|
+
constructor(instance) {
|
|
6
6
|
this.instance = instance;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
_call_indetity(properties) {
|
|
10
10
|
utils.batch_or_call({
|
|
11
|
-
env:
|
|
11
|
+
env: config.env_key,
|
|
12
12
|
distinct_id: this.instance.distinct_id,
|
|
13
13
|
...properties,
|
|
14
14
|
});
|
package/src/utils.js
CHANGED
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
constants,
|
|
6
6
|
} from "./constants";
|
|
7
7
|
import config from "./config";
|
|
8
|
-
|
|
9
|
-
let timerID;
|
|
8
|
+
import create_signature from "./encryption";
|
|
10
9
|
|
|
11
10
|
function uuid() {
|
|
12
11
|
var dt = new Date().getTime();
|
|
@@ -120,11 +119,19 @@ function os() {
|
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
function api(route, body, method = "
|
|
122
|
+
async function api(route, body, method = "POST") {
|
|
123
|
+
const requested_date = new Date().toGMTString();
|
|
124
|
+
const req_body = JSON.stringify(body);
|
|
125
|
+
const sign = await create_signature(req_body, requested_date, "POST");
|
|
126
|
+
const authorization = sign ? `${body[0]?.env}:${sign}` : body[0]?.env;
|
|
124
127
|
return fetch(`${config.api_url}/${route}`, {
|
|
125
128
|
method: method,
|
|
126
|
-
body:
|
|
127
|
-
headers: {
|
|
129
|
+
body: req_body,
|
|
130
|
+
headers: {
|
|
131
|
+
"Content-Type": "application/json",
|
|
132
|
+
Authorization: authorization,
|
|
133
|
+
"x-amz-date": requested_date,
|
|
134
|
+
},
|
|
128
135
|
});
|
|
129
136
|
}
|
|
130
137
|
|
|
@@ -163,7 +170,7 @@ function bulk_call_api() {
|
|
|
163
170
|
schedule the flush in some time future
|
|
164
171
|
*/
|
|
165
172
|
function schedule_flush(delay = 5000) {
|
|
166
|
-
|
|
173
|
+
setTimeout(() => {
|
|
167
174
|
bulk_call_api();
|
|
168
175
|
}, delay);
|
|
169
176
|
}
|
|
@@ -210,7 +217,7 @@ function urlB64ToUint8Array(base64String) {
|
|
|
210
217
|
const base64 = (base64String + padding)
|
|
211
218
|
.replace(/\-/g, "+")
|
|
212
219
|
.replace(/_/g, "/");
|
|
213
|
-
const rawData = atob(base64);
|
|
220
|
+
const rawData = window.atob(base64);
|
|
214
221
|
const outputArray = new Uint8Array(rawData.length);
|
|
215
222
|
for (let i = 0; i < rawData.length; ++i) {
|
|
216
223
|
outputArray[i] = rawData.charCodeAt(i);
|