web-push-notifications 3.39.8 → 3.40.1
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/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/service-worker.js +1 -1
- package/lib/service-worker.js.map +1 -1
- package/package.json +1 -3
package/lib/service-worker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,(()=>(()=>{"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var s in e=arguments[n])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},n.apply(this,arguments)};function r(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(n[r[s]]=t[r[s]])}return n}function s(t,e,n,r){return new(n||(n=Promise))((function(s,i){function o(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}u((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,s,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(s=2&a[0]?r.return:a[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,a[1])).done)return s;switch(r=0,s&&(a=[2&a[0],s.value]),a[0]){case 0:case 1:s=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(6===a[0]&&i.label<s[1]){i.label=s[1],s=a;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(a);break}s[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],r=0}finally{n=s=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}Object.create;function o(t,e,n){if(n||2===arguments.length)for(var r,s=0,i=e.length;s<i;s++)!r&&s in e||(r||(r=Array.prototype.slice.call(e,0,s)),r[s]=e[s]);return t.concat(r||Array.prototype.slice.call(e))}Object.create;"function"==typeof SuppressedError&&SuppressedError;var a="deviceRegistrationStatus",u="registered",c="unregistered";const h={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let p;const d=new Uint8Array(16);const l=[];for(let t=0;t<256;++t)l.push((t+256).toString(16).slice(1));function f(t,e=0){return(l[t[e+0]]+l[t[e+1]]+l[t[e+2]]+l[t[e+3]]+"-"+l[t[e+4]]+l[t[e+5]]+"-"+l[t[e+6]]+l[t[e+7]]+"-"+l[t[e+8]]+l[t[e+9]]+"-"+l[t[e+10]]+l[t[e+11]]+l[t[e+12]]+l[t[e+13]]+l[t[e+14]]+l[t[e+15]]).toLowerCase()}const v=function(t,e,n){if(h.randomUUID&&!e&&!t)return h.randomUUID();const r=(t=t||{}).random??t.rng?.()??function(){if(!p){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");p=crypto.getRandomValues.bind(crypto)}return p(d)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,e){if((n=n||0)<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[n+t]=r[t];return e}return f(r)};var g,m=function(){var t=this;this.addEventHandler=function(e,n){var r=t.savedEventHandlersMap[e];r||(r=[]),r.push(n),t.savedEventHandlersMap[e]=r},this.removeEventHandler=function(e,n){var r=t.savedEventHandlersMap[e];r&&(t.savedEventHandlersMap[e]=r.filter((function(t){return t!==n})))},this.dispatchEvent=function(e,r){var s=r.eventId||v(),i=t.savedEventHandlersMap[e];return i?(i.forEach((function(t){"function"==typeof t&&setTimeout((function(){t(n(n({},r),{eventId:s}))}),0)})),s):s},this.savedEventHandlersMap={}};function y(){return globalThis}function b(t,e){if("string"==typeof t)try{return JSON.parse(t)}catch(t){console.log(t)}return void 0===t&&void 0!==e?e:t}var w="silent",S="fatal",E="error",M="warn",x="info",P="debug",D=((g={})[w]=0,g[S]=10,g[E]=20,g[M]=30,g[x]=40,g[P]=50,g),C=function(){function t(t){this.relations=D,this.level=t&&void 0!==t.level?t.level:E,this.applicationType=t&&void 0!==t.applicationType?t.applicationType:"sdk",this.subscribers=t&&void 0!==t.subscribers?t.subscribers:[]}return t.prototype.updateLogLevel=function(t){this.level=t},t.prototype.updateApplicationType=function(t){this.applicationType=t},t.prototype.updateApplicationCode=function(t){this.applicationCode=t},t.prototype.updateDomain=function(t){this.domain=t},t.prototype.updateDeviceInfo=function(t){this.deviceInfo=t},t.prototype.subscribe=function(t,e){this.subscribers.push({handler:e,level:t})},t.prototype.log=function(t){return s(this,void 0,void 0,(function(){var e,s,o,a,u,c,h=this;return i(this,(function(i){switch(i.label){case 0:return e=[],s=t.options,o=r(t,["options"]),a=o,s&&(s.handler,u=r(s,["handler"]),a=n(n({},o),u)),c=this.getMessage(a),this.subscribers.forEach((function(n){n.level===t.type&&h.relations[n.level]<=h.relations[h.level]&&e.push(n.handler.call(null,c))})),s&&s.handler&&this.level!==w&&s.handler.call(null,c),[4,Promise.all(e)];case 1:return i.sent(),[2]}}))}))},t.prototype.debug=function(t,e){return s(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.log({type:P,text:t,options:e})]}))}))},t.prototype.info=function(t,e){return s(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.log({type:x,text:t,options:e})]}))}))},t.prototype.warn=function(t,e,n){return s(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.log({type:M,text:t,code:e,options:n})]}))}))},t.prototype.error=function(t,e,n){return s(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.log({type:E,text:t,code:e,options:n})]}))}))},t.prototype.fatal=function(t,e,n){return s(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.log({type:S,text:t,code:e,options:n})]}))}))},t.prototype.errorAndThrow=function(t,e,n){return s(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.logAndThrow({type:E,text:t,code:e,options:n})]}))}))},t.prototype.errorAndReject=function(t,e,n,r){return s(this,void 0,void 0,(function(){return i(this,(function(s){return[2,this.logAndReject(t,{type:E,text:e,code:n,options:r})]}))}))},t.prototype.fatalAndThrow=function(t,e,n){return s(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.logAndThrow({type:S,text:t,code:e,options:n})]}))}))},t.prototype.fatalAndReject=function(t,e,n,r){return s(this,void 0,void 0,(function(){return i(this,(function(s){return[2,this.logAndReject(t,{type:S,text:e,code:n,options:r})]}))}))},t.prototype.logAndThrow=function(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.log(t)];case 1:throw n.sent(),e=new Error(t.text),t.code&&(e.code=t.code),e}}))}))},t.prototype.logAndReject=function(t,e){return s(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.log(e)];case 1:return r.sent(),n=new Error(e.text),e.code&&(n.code=e.code),t(n),[2]}}))}))},t.prototype.getMessage=function(t){return n({applicationCode:this.applicationCode,domain:this.domain,applicationType:this.applicationType,deviceInfo:this.deviceInfo},t)},t}();function T(t){var e=t.code,n=t.text,r=t.type,s=function(t){switch(t){case"fatal":case"error":return console.error;case"warn":case"info":case"debug":return console.log}}(r);console.groupCollapsed(r),s(e?"".concat(e,": ").concat(n):n),console.groupEnd()}var I=new C({level:"error",subscribers:[{level:"fatal",handler:T},{level:"error",handler:T}]});function k(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(n){return e=A(t),[2,I.fatal(e.text,e.code,e.options)]}))}))}function A(t){var e=t.message,s=t.code,i=t.error,o=r(t,["message","code","error"]),a=function(t){var e=new Error("unknown error");"string"!=typeof t&&"number"!=typeof t&&"boolean"!=typeof t||(e.message=t.toString());t instanceof Error&&(e=t);return e}(i);return{text:e,code:s,options:n(n({},o),{errorText:a.message,errorStack:a.stack})}}var O="keyValue",R="messages",_="log",N="inboxMessages";function U(t,e){return function(n){n.objectStoreNames.contains(t)||e(n)}}const q=[U(N,(function(t){var e="status",n=t.createObjectStore(N,{keyPath:"inbox_id",autoIncrement:!1});n.createIndex(e,e,{unique:!1,multiEntry:!0}),n.createIndex("rt","rt",{unique:!1,multiEntry:!0})}))];const W=[U(O,(function(t){t.createObjectStore(O,{keyPath:"key"})})),U(_,(function(t){var e=t.createObjectStore(_,{keyPath:"id",autoIncrement:!0});e.createIndex("environment","environment",{unique:!1}),e.createIndex("date","date",{unique:!1}),e.createIndex("type","type",{unique:!1})})),U(R,(function(t){t.createObjectStore(R,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}))];const L=function(){function t(t){void 0===t&&(t=new Date),this._date=t}return Object.defineProperty(t.prototype,"date",{get:function(){return this._date},set:function(t){this._date=t},enumerable:!1,configurable:!0}),t.prototype.getUtcTimestamp=function(){return Math.floor((this.date.getTime()+60*this.date.getTimezoneOffset()*1e3)/1e3)},t.prototype.getTimestamp=function(){return Math.round(this.date.getTime()/1e3)},t.prototype.setLocal=function(){var t=this._date.getTime()-60*this.date.getTimezoneOffset()*1e3;this._date=new Date(t)},t.prototype.addDays=function(t){var e=this._date.getTime()+24*t*60*60*1e3;this._date=new Date(e)},t.prototype.getInboxFakeOrder=function(){return(100*this._date.getTime()+9e9).toString()},t}();const j=function(){function t(t){void 0===t&&(t=new L),this.migrations={initial:W,"2018/11/26":q},this.dateModule=t}return Object.defineProperty(t.prototype,"initial",{get:function(){return this.migrations.initial},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dateSorted",{get:function(){var t=this;return Object.keys(this.migrations).filter((function(t){return"initial"!==t})).sort((function(t,e){var n=new L(new Date(t)),r=new L(new Date(e));return n.getTimestamp()-r.getTimestamp()})).map((function(e){return t.migrations[e]}))},enumerable:!1,configurable:!0}),t}();const V=function(){function t(t,e){void 0===e&&(e=new j),this.db=t,this.migrationsBuilder=e}return t.prototype.applyMigrations=function(){var t=this;this.applyMigrationsPack(this.migrationsBuilder.initial),this.migrationsBuilder.dateSorted.forEach((function(e){t.applyMigrationsPack(e)}))},t.prototype.applyMigrationsPack=function(t){var e=this;t.forEach((function(t){t(e.db)}))},t}();function B(t,e){console.info("onversionchange",e),t.close()}var H;function F(t){return(H||(H=new Promise((function(t,e){var n=indexedDB.open("PUSHWOOSH_SDK_STORE",7);n.onsuccess=function(n){var r=n.target.result;r.onversionchange=B.bind(null,r,e),t(r)},n.onerror=function(){return e(n.error)},n.onupgradeneeded=function(t){var n=t.target.result;n.onversionchange=B.bind(null,n,e),new V(n).applyMigrations()}}))),H).then((function(e){return new Promise((function(n,r){return t(e,n,r)}))}))}var K,z=function(){function t(){}return t.prototype._add=function(t){var e=this;return F((function(n,r,s){var i=n.transaction([e.name],"readwrite").objectStore(e.name).add(t);i.onsuccess=function(){r(t)},i.onerror=function(){s(i.error)}})).then((function(t){return e.getAll().then((function(n){if(Array.isArray(n)){var r=n.map((function(t){return t.id})).sort((function(t,e){return t==e?0:t<e?1:-1}));if(r.length>e.maxItems)return Promise.all(r.slice(e.maxItems).map((function(t){return e.delete(t)}))).then((function(){return t}))}return t}))}))},t.prototype.delete=function(t){var e=this;return F((function(n,r,s){var i=n.transaction([e.name],"readwrite").objectStore(e.name).delete(t);i.onsuccess=function(){r(i.result)},i.onerror=function(){s(i.error)}}))},t.prototype.getAll=function(){var t=this;return F((function(e,n,r){var s=[],i=e.transaction(t.name).objectStore(t.name).openCursor();i.onsuccess=function(t){var e=t.target.result;e?(e.value&&s.push(e.value),e.continue()):n(s)},i.onerror=function(){r(i.error)}}))},t}(),J=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=_,e.maxItems=100,e.environment="undefined"!=typeof self&&self.registration?"worker":"browser",e}return e(n,t),n.prototype.add=function(t,e,n){var r={type:t,environment:this.environment,message:"".concat(e),date:new Date};return e instanceof Error&&(r.stack=e.stack),n&&(r.additional=n),this._add(r)},n}(z),G=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=R,e.maxItems=25,e}return e(r,t),r.prototype.add=function(t){return this._add(n(n({},t),{date:new Date}))},r}(z),Y=(K=O,{get:function(t,e){return F((function(n,r,s){var i,o=n.transaction(K).objectStore(K).get(t),a=!1,u=!1,c=function(){if(clearTimeout(i),a){var t=o.result;r(t&&t.value||e)}else u?s(o.error):i=setTimeout(c,0)};o.onsuccess=function(){return a=!0},o.onerror=function(){return u=!0},c()}))},getAll:function(){return F((function(t,e,n){var r,s={},i=t.transaction(K).objectStore(K).openCursor(),o=!1,a=!1,u=function(){clearTimeout(r),o?e(s):a?n(i.error):r=setTimeout(u,0)};i.onsuccess=function(t){var e=t.target.result;e?(s[e.key]=e.value.value,e.continue()):o=!0},i.onerror=function(){return a=!0},u()}))},extend:function(t,e){return s(this,void 0,void 0,(function(){var s,o;return i(this,(function(i){switch(i.label){case 0:return[4,this.get(t)];case 1:return s=i.sent(),o=r(e,[]),[4,this.set(t,n(n({},s),o))];case 2:return i.sent(),[2]}}))}))},set:function(t,e){return F((function(n,r,s){var i,o=n.transaction([K],"readwrite").objectStore(K).put({key:t,value:e}),a=!1,u=!1,c=function(){clearTimeout(i),a?r(t):u?s(o.error):i=setTimeout(c,0)};o.onsuccess=function(){return a=!0},o.onerror=function(){return u=!0},c()}))}}),$=new J,Q=new G,X={error:1,info:2,debug:3},Z=3;!function(){for(var t,e=function(){},n=["assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"],r=n.length,s=y(),i=s.console=s.console||{};r--;)i[t=n[r]]||(i[t]=e)}();var tt={setLevel:function(t){X[t]||(t="error"),Z=X[t]},write:function(t,e,n){return"error"===t?this.error(e):this.info(e),$.add(t,e,n)}};Object.keys(X).forEach((function(t){var e=X[t];tt[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];e<=Z&&(console.groupCollapsed(t),console.info.apply(console,o([""],n,!1)),console.trace("trace"),console.groupEnd())}}));var et=function(){function t(t,e,n,r){void 0===r&&(r=new L),this.data=t,this.api=e,this.inboxModel=n,this.dateModule=r,this.publicMessageBuilder=this.publicMessageBuilder.bind(this)}return t.prototype.messageTypeFactory=function(t,e){var n=0;return 2===t?n=1:"l"in e&&null!=e.l&&(n=e.l.startsWith("http")?2:3),n},t.prototype.updateMessagesStatusWithCodes=function(t,e,n){return s(this,void 0,void 0,(function(){var r,o,a=this;return i(this,(function(u){switch(u.label){case 0:return r=[],o=[],e.forEach((function(e){return s(a,void 0,void 0,(function(){return i(this,(function(s){return-1===t.indexOf(e.inbox_id)||(e.status=n,r.push(e),o.push(this.api.inboxStatus(e.order,e.status))),[2]}))}))})),[4,this.inboxModel.putBulkMessages(r)];case 1:return u.sent(),[4,Promise.all(o)];case 2:return u.sent(),[2]}}))}))},t.prototype.publicMessageBuilder=function(t){return s(this,arguments,void 0,(function(t){var e,n,r,s,o,a=t.action_type,u=t.action_params,c=t.image,h=t.title,p=t.send_date,d=t.inbox_id,l=t.text,f=t.status;return i(this,(function(t){switch(t.label){case 0:return(n=c)?[3,2]:[4,this.data.getDefaultNotificationImage()];case 1:n=t.sent(),t.label=2;case 2:return e=n,(s=h)?[3,4]:[4,this.data.getDefaultNotificationTitle()];case 3:s=t.sent(),t.label=4;case 4:return r=s,o=JSON.parse(u),this.dateModule.date=new Date(1e3*parseInt(p)),this.dateModule.setLocal(),[2,{title:r,imageUrl:e,code:d,message:l,sendDate:this.dateModule.date.toISOString(),type:this.messageTypeFactory(a,o),link:(null==o?void 0:o.l)||"/",isRead:2===f||3===f,isActionPerformed:3===f}]}}))}))},t.prototype.messagesWithNoActionPerformedCount=function(){return this.inboxModel.getDeliveredReadMessagesCount()},t.prototype.unreadMessagesCount=function(){return this.inboxModel.getDeliveredMessagesCount()},t.prototype.messagesCount=function(){return this.inboxModel.messagesCount()},t.prototype.loadMessages=function(){return s(this,void 0,void 0,(function(){var t,e,n;return i(this,(function(r){switch(r.label){case 0:return[4,this.inboxModel.getReadOpenMessages()];case 1:return t=r.sent(),[4,this.inboxModel.getDeliveredMessages()];case 2:return e=r.sent(),n=o(o([],t,!0),e,!0).sort((function(t,e){return parseInt(e.send_date,10)-parseInt(t.send_date,10)})).sort((function(t,e){return parseInt(e.order||"0",10)-parseInt(t.order||"0",10)})).map(this.publicMessageBuilder),[2,Promise.all(n)]}}))}))},t.prototype.readMessagesWithCodes=function(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.inboxModel.getDeliveredMessages()];case 1:return e=n.sent(),[4,this.updateMessagesStatusWithCodes(t,e,2)];case 2:return n.sent(),[2]}}))}))},t.prototype.performActionForMessageWithCode=function(t){return s(this,void 0,void 0,(function(){var e,n,r;return i(this,(function(s){switch(s.label){case 0:return[4,this.inboxModel.getMessage(t)];case 1:return e=s.sent(),n=JSON.parse(e.action_params),2===(r=this.messageTypeFactory(e.action_type,n))&&null!=n.l?document.location.href=n.l:3===r&&null!=n.l&&window.history.go(n.l),e.status=3,[4,this.inboxModel.putMessage(e)];case 2:return s.sent(),[4,this.api.inboxStatus(e.order,e.status)];case 3:return s.sent(),[2]}}))}))},t.prototype.deleteMessagesWithCodes=function(t){return s(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return[4,this.inboxModel.getReadOpenMessages()];case 1:return e=r.sent(),[4,this.inboxModel.getDeliveredMessages()];case 2:return n=r.sent(),[4,this.updateMessagesStatusWithCodes(t,o(o([],e,!0),n,!0),4)];case 3:return r.sent(),[2]}}))}))},t.prototype.syncMessages=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.inboxModel.updateMessages()];case 1:return t.sent(),[2]}}))}))},t}();const nt=et;var rt=function(){function t(t,e){this.name=e,this.store=t.transaction(this.name,"readwrite").objectStore(this.name)}return Object.defineProperty(t.prototype,"index",{set:function(t){this.store.indexNames.contains(t)?this._index=this.store.index(t):console.warn('Index "'.concat(t,'" in '))},enumerable:!1,configurable:!0}),t.prototype.writeRequestPromise=function(t,e){return new Promise((function(n,r){t.onsuccess=function(){n(e)},t.onerror=function(){r(t.error)}}))},t.prototype.readRequestPromise=function(t,e){return new Promise((function(n,r){t.onsuccess=function(t){var r=t.target;n(r.result||e)},t.onerror=function(){r(t.error)}}))},t.prototype.put=function(t,e){var n=this.store.put(t,e);return this.writeRequestPromise(n,e)},t.prototype.add=function(t,e){return this.put(t,e)},t.prototype.delete=function(t){var e=this.store.delete(t);return this.writeRequestPromise(e)},t.prototype.get=function(t,e){var n=this.store.get(t);return this.readRequestPromise(n,e)},t.prototype.getAll=function(){var t=this.store.openCursor(),e=[];return new Promise((function(n,r){t.onsuccess=function(t){var r=t.target.result;r?(e.push(r.value),r.continue()):n(e)},t.onerror=function(){r(t.error)}}))},t.prototype.count=function(t){var e=this.store.count(t);return this.readRequestPromise(e,0)},t.prototype.countByIndex=function(t){var e=this._index.count(t);return this.readRequestPromise(e,0)},t}();const st=rt;var it=function(){function t(){}return t.prototype.dbVersionChangeHandler=function(t,e){console.info("onversionchange",e),t.close()},t.prototype.dbRequestSuccessHandler=function(t,e){var n=this,r=e.target.result;r.onversionchange=function(t){n.dbVersionChangeHandler(r,t)},t(r)},t.prototype.dbRequestUpgradeNeededHandler=function(t){var e=this,n=t.target.result;n.onversionchange=function(t){e.dbVersionChangeHandler(n,t)},new V(n).applyMigrations()},t.prototype.getDB=function(){var t=this;return new Promise((function(e,n){var r=indexedDB.open("PUSHWOOSH_SDK_STORE",7);r.onsuccess=function(n){t.dbRequestSuccessHandler(e,n)},r.onupgradeneeded=function(e){t.dbRequestUpgradeNeededHandler(e)},r.onerror=function(){return n(r.error)}}))},t.prototype.put=function(t,e,n){return s(this,void 0,void 0,(function(){var r,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getDB()];case 1:return r=i.sent(),[4,new st(r,t).put(e,n)];case 2:return s=i.sent(),r.close(),[2,s]}}))}))},t.prototype.delete=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return i(this,(function(s){switch(s.label){case 0:return[4,this.getDB()];case 1:return n=s.sent(),[4,new st(n,t).delete(e)];case 2:return r=s.sent(),n.close(),[2,r]}}))}))},t.prototype.get=function(t,e,n){return s(this,void 0,void 0,(function(){var r,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getDB()];case 1:return r=i.sent(),[4,new st(r,t).get(e,n)];case 2:return s=i.sent(),r.close(),[2,s]}}))}))},t.prototype.getAll=function(t){return s(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getDB()];case 1:return e=r.sent(),[4,new st(e,t).getAll()];case 2:return n=r.sent(),e.close(),[2,n||[]]}}))}))},t.prototype.count=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return i(this,(function(s){switch(s.label){case 0:return[4,this.getDB()];case 1:return n=s.sent(),[4,new st(n,t).count(e)];case 2:return r=s.sent(),n.close(),[2,r]}}))}))},t.prototype.countByIndex=function(t,e,n){return s(this,void 0,void 0,(function(){var r,s,o;return i(this,(function(i){switch(i.label){case 0:return[4,this.getDB()];case 1:return r=i.sent(),(s=new st(r,t)).index=e,[4,s.countByIndex(n)];case 2:return o=i.sent(),r.close(),[2,o]}}))}))},t}();const ot=it;var at=function(){function t(t,e,n,r,s){void 0===r&&(r=new ot),void 0===s&&(s=new L),this.eventBus=t,this.data=e,this.api=n,this.storage=r,this.storeName="inboxMessages",this.dateModule=s}return t.prototype.getInboxMessages=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return[4,this.api.getInboxMessages()];case 1:return t=e.sent(),[4,this.storeGetInboxMessagesRequestParams(t.next,t.new_inbox)];case 2:return e.sent(),[2,t]}}))}))},t.prototype.storeGetInboxMessagesRequestParams=function(t,e){return s(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return this.dateModule.date=new Date,[4,this.data.setInboxLastRequestTime(this.dateModule.getUtcTimestamp())];case 1:return n.sent(),[4,this.data.setInboxLastRequestCode(t)];case 2:return n.sent(),[4,this.data.setInboxNewMessagesCount(e)];case 3:return n.sent(),[2]}}))}))},t.prototype.putServerMessages=function(t){return s(this,void 0,void 0,(function(){var e,n=this;return i(this,(function(r){return e=t.map((function(t){return s(n,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this.storage.get(this.storeName,t.inbox_id,{})];case 1:return"status"in(e=n.sent())&&(t.status=e.status),[2,this.putMessage(t)]}}))}))})),[2,Promise.all(e)]}))}))},t.prototype.putMessage=function(t){return this.storage.put(this.storeName,t)},t.prototype.putBulkMessages=function(t){var e=this,n=t.map((function(t){return e.putMessage(t)}));return Promise.all(n)},t.prototype.deleteMessages=function(t){var e=this,n=t.map((function(t){return e.storage.delete(e.storeName,t)}));return Promise.all(n)},t.prototype.deleteExpiredMessages=function(){return s(this,void 0,void 0,(function(){var t,e,n;return i(this,(function(r){switch(r.label){case 0:return this.dateModule.date=new Date,t=this.dateModule.getTimestamp().toString(),[4,this.storage.getAll(this.storeName)];case 1:return e=r.sent(),n=e.filter((function(e){return e.rt<t})).map((function(t){return t.inbox_id})),[2,this.deleteMessages(n)]}}))}))},t.prototype.getMessage=function(t){return this.storage.get(this.storeName,t)},t.prototype.getReadOpenMessages=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.storage.getAll(this.storeName)];case 1:return[2,t.sent().filter((function(t){return 2===t.status||3===t.status}))]}}))}))},t.prototype.getDeliveredMessages=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.storage.getAll(this.storeName)];case 1:return[2,t.sent().filter((function(t){return 1===t.status}))]}}))}))},t.prototype.messagesCount=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.storage.count(this.storeName)]}))}))},t.prototype.getDeliveredMessagesCount=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.storage.countByIndex(this.storeName,"status",1)]}))}))},t.prototype.getReadMessagesCount=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.storage.countByIndex(this.storeName,"status",2)]}))}))},t.prototype.getDeliveredReadMessagesCount=function(){return s(this,void 0,void 0,(function(){var t,e,n,r;return i(this,(function(s){return e=(t=[2,3])[0],n=t[1],r=IDBKeyRange.bound(e,n),[2,this.storage.countByIndex(this.storeName,"status",r)]}))}))},t.prototype.updateMessages=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return[4,this.getInboxMessages()];case 1:return t=e.sent(),[4,this.deleteExpiredMessages()];case 2:return e.sent(),t.deleted?[4,this.deleteMessages(t.deleted)]:[3,4];case 3:e.sent(),e.label=4;case 4:return[4,this.putServerMessages(t.messages)];case 5:return e.sent(),this.eventBus.dispatchEvent("update-inbox-messages",{messages:new nt(this.data,this.api,this)}),[2]}}))}))},t}();const ut=at;var ct={"&":"&","<":"<",">":">",""":'"',"'":"'"},ht=/&(?:amp|lt|gt|quot|#39);/g,pt=RegExp(ht.source);var dt=function(){function t(t){void 0===t&&(t=Y),this.store=t}return t.prototype.clearAll=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.set("params.applicationCode",void 0)];case 1:return t.sent(),[4,this.store.set("params.hwid",void 0)];case 2:return t.sent(),[4,this.store.set("params.deviceType",void 0)];case 3:return t.sent(),[4,this.store.set("params.deviceModel",void 0)];case 4:return t.sent(),[4,this.store.set("params.language",void 0)];case 5:return t.sent(),[4,this.store.set("params.apiEntrypoint",void 0)];case 6:return t.sent(),[4,this.store.set("params.tokens",void 0)];case 7:return t.sent(),[4,this.store.set("params.applicationServerKey",void 0)];case 8:return t.sent(),[4,this.store.set("params.senderId",void 0)];case 9:return t.sent(),[4,this.store.set("params.webSitePushId",void 0)];case 10:return t.sent(),[4,this.store.set("params.defaultNotificationImage",void 0)];case 11:return t.sent(),[4,this.store.set("params.defaultNotificationTitle",void 0)];case 12:return t.sent(),[4,this.store.set("params.userId",void 0)];case 13:return t.sent(),[4,this.store.set("params.email",void 0)];case 14:return t.sent(),[4,this.store.set("params.userIdWasChanged",void 0)];case 15:return t.sent(),[4,this.store.set("params.isLastPermissionStatus",void 0)];case 16:return t.sent(),[4,this.store.set("params.isManualUnsubscribed",void 0)];case 17:return t.sent(),[4,this.store.set("params.isCommunicationDisabled",void 0)];case 18:return t.sent(),[4,this.store.set("params.isDropAllData",void 0)];case 19:return t.sent(),[4,this.store.set("params.sdkVersion",void 0)];case 20:return t.sent(),[4,this.store.set("params.serviceWorkerVersion",void 0)];case 21:return t.sent(),[4,this.store.set("params.serviceWorkerUrl",void 0)];case 22:return t.sent(),[4,this.store.set("params.serviceWorkerScope",void 0)];case 23:return t.sent(),[4,this.store.set("params.lastOpenMessage",void 0)];case 24:return t.sent(),[4,this.store.set("params.lastOpenApplicationTime",void 0)];case 25:return t.sent(),[4,this.store.set("params.features",void 0)];case 26:return t.sent(),[4,this.store.set("params.init",void 0)];case 27:return t.sent(),[4,this.store.set("API_PARAMS",void 0)];case 28:return t.sent(),[4,this.store.set("SENDER_ID",void 0)];case 29:return t.sent(),[4,this.store.set("COMMUNICATION_ENABLED",void 0)];case 30:return t.sent(),[4,this.store.set("DEVICE_DATA_REMOVED",void 0)];case 31:return t.sent(),[4,this.store.set("LAST_OPEN_MESSAGE",void 0)];case 32:return t.sent(),[4,this.store.set("DELAYED_EVENT",void 0)];case 33:return t.sent(),[2]}}))}))},t.prototype.setApplicationCode=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.applicationCode",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getApplicationCode=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.applicationCode")];case 1:return[2,t.sent()]}}))}))},t.prototype.setApiToken=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.apiToken",t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getApiToken=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.apiToken")];case 1:return[2,t.sent()]}}))}))},t.prototype.setHwid=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.hwid",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getHwid=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.hwid")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDeviceType=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.deviceType",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDeviceType=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.deviceType")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDeviceModel=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.deviceModel",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDeviceModel=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.deviceModel")];case 1:return[2,t.sent()]}}))}))},t.prototype.setLanguage=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.language",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getLanguage=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.language","en")];case 1:return[2,t.sent()]}}))}))},t.prototype.setApiEntrypoint=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.apiEntrypoint",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getApiEntrypoint=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.apiEntrypoint","https://cp.pushwoosh.com/json/1.3/")];case 1:return[2,t.sent()]}}))}))},t.prototype.setTokens=function(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(r){switch(r.label){case 0:return[4,this.getHwid()];case 1:return e=r.sent(),[4,this.store.set("API_PARAMS",n({hwid:e},t))];case 2:return r.sent(),[4,this.store.set("params.tokens",t)];case 3:return r.sent(),[2]}}))}))},t.prototype.getTokens=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.store.get("API_PARAMS")];case 1:return t=n.sent(),[4,this.store.get("params.tokens")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setApplicationServerKey=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.applicationServerKey",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getApplicationServerKey=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.applicationServerKey")];case 1:return[2,t.sent()]}}))}))},t.prototype.setIsVapidChanged=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.isVapidChanged",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getIsVapidChanged=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.isVapidChanged",!1)];case 1:return[2,t.sent()]}}))}))},t.prototype.setWebSitePushId=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.webSitePushId",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getWebSitePushId=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.webSitePushId")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDefaultNotificationImage=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.defaultNotificationImage",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDefaultNotificationImage=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.defaultNotificationImage","https://cp.pushwoosh.com/img/logo-medium.png")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDefaultNotificationTitle=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.defaultNotificationTitle",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDefaultNotificationTitle=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.defaultNotificationTitle","Pushwoosh notification")];case 1:return[2,t.sent()]}}))}))},t.prototype.setUserId=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return t?[3,2]:[4,this.store.set("params.userId",void 0)];case 1:case 3:return e.sent(),[2];case 2:return[4,this.store.set("params.userId",t.toString())]}}))}))},t.prototype.getUserId=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.userId")];case 1:return[2,t.sent()]}}))}))},t.prototype.setStatusUserIdWasChanged=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.userIdWasChanged",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getStatusUserIdWasChanged=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.userIdWasChanged",!1)];case 1:return[2,t.sent()]}}))}))},t.prototype.setEmail=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return t?[3,2]:[4,this.store.set("params.email",void 0)];case 1:case 3:return e.sent(),[2];case 2:return[4,this.store.set("params.email",t.toString())]}}))}))},t.prototype.getEmail=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.email")];case 1:return[2,t.sent()]}}))}))},t.prototype.setStatusEmailWasChanged=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.emailWasChanged",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getStatusEmailWasChanged=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.emailWasChanged",!1)];case 1:return[2,t.sent()]}}))}))},t.prototype.setLastPermissionStatus=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.isLastPermissionStatus",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getLastPermissionStatus=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.isLastPermissionStatus")];case 1:return[2,t.sent()]}}))}))},t.prototype.setStatusManualUnsubscribed=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("MANUAL_UNSUBSCRIBE",t)];case 1:return e.sent(),[4,this.store.set("params.isManualUnsubscribed",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getStatusManualUnsubscribed=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.store.get("MANUAL_UNSUBSCRIBE",!1)];case 1:return t=n.sent(),[4,this.store.get("params.isManualUnsubscribed",!1)];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setStatusCommunicationDisabled=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("COMMUNICATION_ENABLED",t?0:1)];case 1:return e.sent(),[4,this.store.set("params.isCommunicationDisabled",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getStatusCommunicationDisabled=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.store.get("COMMUNICATION_ENABLED")];case 1:return t=n.sent(),[4,this.store.get("params.isCommunicationDisabled",!1)];case 2:return[2,void 0!==(e=n.sent())?e:0==t]}}))}))},t.prototype.setStatusDropAllData=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("DEVICE_DATA_REMOVED",t)];case 1:return e.sent(),[4,this.store.set("params.isDropAllData",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getStatusDropAllData=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.store.get("DEVICE_DATA_REMOVED",!1)];case 1:return t=n.sent(),[4,this.store.get("params.isDropAllData",!1)];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setSdkVersion=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.sdkVersion",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getSdkVersion=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.sdkVersion")];case 1:return[2,t.sent()]}}))}))},t.prototype.setServiceWorkerVersion=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("WORKER_VERSION",t)];case 1:return e.sent(),[4,this.store.set("params.serviceWorkerVersion",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getServiceWorkerVersion=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.store.get("WORKER_VERSION")];case 1:return t=n.sent(),[4,this.store.get("params.serviceWorkerVersion")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setServiceWorkerUrl=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return t?[4,this.store.set("params.serviceWorkerUrl",t)]:[2];case 1:return e.sent(),[2]}}))}))},t.prototype.getServiceWorkerUrl=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.serviceWorkerUrl","/pushwoosh-service-worker.js")];case 1:return[2,t.sent()]}}))}))},t.prototype.setServiceWorkerScope=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return t?[4,this.store.set("params.serviceWorkerScope",t)]:[2];case 1:return e.sent(),[2]}}))}))},t.prototype.getServiceWorkerScope=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.serviceWorkerScope")];case 1:return[2,t.sent()]}}))}))},t.prototype.setLastOpenMessage=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("LAST_OPEN_MESSAGE",t)];case 1:return e.sent(),[4,this.store.set("params.lastOpenMessage",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getLastOpenMessage=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.store.get("LAST_OPEN_MESSAGE")];case 1:return t=n.sent(),[4,this.store.get("params.lastOpenMessage")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setLastOpenApplicationTime=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.lastOpenApplicationTime",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getLastOpenApplicationTime=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.lastOpenApplicationTime")];case 1:return[2,t.sent()]}}))}))},t.prototype.setFeatures=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.features",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getFeatures=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.features")];case 1:return[2,t.sent()]}}))}))},t.prototype.setInitParams=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.init",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInitParams=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.init")];case 1:return[2,t.sent()]}}))}))},t.prototype.setInboxLastRequestCode=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.inbox.lastRequestCode",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInboxLastRequestCode=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.inbox.lastRequestCode","")];case 1:return[2,t.sent()]}}))}))},t.prototype.setInboxLastRequestTime=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.inbox.lastRequestTime",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInboxLastRequestTime=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.store.get("params.inbox.lastRequestTime",0)]}))}))},t.prototype.setInboxNewMessagesCount=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.inbox.newMessagesCount",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInboxNewMessagesCount=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.store.get("params.inbox.newMessagesCount",0)]}))}))},t.prototype.setDelayedEvent=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("DELAYED_EVENT",t)];case 1:return e.sent(),[4,this.store.set("params.delayedEvent",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getDelayedEvent=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.store.get("DELAYED_EVENT")];case 1:return t=n.sent(),[4,this.store.get("params.delayedEvent")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setPromptDisplayCount=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.promptDisplayCount",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getPromptDisplayCount=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.store.get("params.promptDisplayCount",0)]}))}))},t.prototype.setPromptLastSeenTime=function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.promptLastSeenTime",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getPromptLastSeenTime=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.store.get("params.promptLastSeenTime",0)]}))}))},t}(),lt=function(){function t(t,e,n){if(void 0===e&&(e=new dt),void 0===n&&(n=new L),"data"in t){var r=t;this.payload=r.data}else this.payload=t;this.data=e,this.code="notificationCode-".concat(Date.now(),"-").concat(Math.random().toString(16).slice(2,10)),this.dateModule=n}return t.prototype.getIcon=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return(t=this.payload.i)?[3,2]:[4,this.data.getDefaultNotificationImage()];case 1:t=e.sent(),e.label=2;case 2:return[2,t]}}))}))},t.prototype.getTitle=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return(t=this.payload.header)?[3,2]:[4,this.data.getDefaultNotificationTitle()];case 1:t=e.sent(),e.label=2;case 2:return[2,t]}}))}))},Object.defineProperty(t.prototype,"silent",{get:function(){return Boolean(this.payload.silent)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"body",{get:function(){return this.payload.body},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"messageHash",{get:function(){return this.payload.p||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"metaData",{get:function(){return this.payload.md?b(this.payload.md):{}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"image",{get:function(){return this.payload.image||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"buttons",{get:function(){return this.payload.buttons?b(this.payload.buttons):[]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"customData",{get:function(){return this.payload.u?b(this.payload.u):{}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"campaignCode",{get:function(){return this.payload.pwcid||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"link",{get:function(){return this.payload.l?(t=this.payload.l)&&pt.test(t)?t.replace(ht,(function(t){return ct[t]})):t:"/";var t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"inboxId",{get:function(){return this.payload.pw_inbox||""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"inboxParams",{get:function(){return this.payload.inbox_params?b(this.payload.inbox_params):{}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"inboxRemovalTime",{get:function(){return this.inboxParams&&this.inboxParams.rt?this.inboxParams.rt:(this.dateModule.date=new Date,this.dateModule.addDays(1),this.dateModule.getUtcTimestamp().toString())},enumerable:!1,configurable:!0}),t.prototype.getInboxImage=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return this.inboxParams&&this.inboxParams.image?[2,this.inboxParams.image]:[2,""]}))}))},Object.defineProperty(t.prototype,"rootParams",{get:function(){var t=this.payload;t.body,t.p,t.header,t.i,t.u,t.l,t.pwcid,t.image,t.buttons,t.pw_inbox,t.inbox_params;return r(t,["body","p","header","i","u","l","pwcid","image","buttons","pw_inbox","inbox_params"])},enumerable:!1,configurable:!0}),t.prototype.getNotificationOptionsPayload=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(r){switch(r.label){case 0:return[4,this.getTitle()];case 1:return t=r.sent(),[4,this.getIcon()];case 2:return e=r.sent(),[2,n(n({},this.rootParams),{body:this.body,title:t,icon:e,image:this.image,buttons:this.buttons,customData:this.customData,metaData:this.metaData,campaignCode:this.campaignCode,openUrl:this.link,messageHash:this.messageHash})]}}))}))},t.prototype.getShowNotificationOptions=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(r){switch(r.label){case 0:return[4,this.getIcon()];case 1:return t=r.sent(),e=this.buttons.map((function(t,e){return t.action="action-".concat(e),t})),[2,n(n({renotify:!0},this.rootParams),{body:this.body,icon:t,tag:JSON.stringify({url:this.link,messageHash:this.messageHash,customData:this.customData,metaData:this.metaData}),data:{code:this.code,buttons:e,image:this.image,campaignCode:this.campaignCode,inboxId:this.inboxId},silent:this.silent,actions:e,image:this.image,buttons:e})]}}))}))},t.prototype.getInboxMessage=function(){return s(this,void 0,void 0,(function(){var t,e,n;return i(this,(function(r){switch(r.label){case 0:return this.dateModule.date=new Date,t=this.dateModule.getTimestamp().toString(),e=this.payload.header||"",[4,this.getInboxImage()];case 1:return n=r.sent(),[2,{title:e,image:n,status:1,order:this.dateModule.getInboxFakeOrder(),inbox_id:this.inboxId,send_date:t,rt:this.inboxRemovalTime,text:this.body,action_type:1,action_params:JSON.stringify({l:this.link})}]}}))}))},t}();const ft=lt;var vt=function(){function t(t,e){void 0===t&&(t=new dt),void 0===e&&(e=tt),this.data=t,this.logger=e}return t.prototype.checkDevice=function(t){return this.createRequest("checkDevice",t)},t.prototype.getConfig=function(t){return this.createRequest("getConfig",t,"",!0)},t.prototype.applicationOpen=function(t){return this.createRequest("applicationOpen",t)},t.prototype.registerDevice=function(t){return this.createRequest("registerDevice",t)},t.prototype.unregisterDevice=function(t){return this.createRequest("unregisterDevice",t)},t.prototype.deleteDevice=function(t){return this.createRequest("deleteDevice",t)},t.prototype.messageDeliveryEvent=function(t){return this.createRequest("messageDeliveryEvent",t)},t.prototype.pushStat=function(t){return this.createRequest("pushStat",t)},t.prototype.setTags=function(t){return this.createRequest("setTags",t)},t.prototype.getTags=function(t){return this.createRequest("getTags",t)},t.prototype.registerUser=function(t){return this.createRequest("registerUser",t)},t.prototype.registerEmail=function(t){return this.createRequest("registerEmail",t)},t.prototype.registerEmailUser=function(t){return this.createRequest("registerEmailUser",t)},t.prototype.setEmailTags=function(t){return this.createRequest("setEmailTags",t)},t.prototype.postEvent=function(t){return this.createRequest("postEvent",t)},t.prototype.getInboxMessages=function(t){return this.createRequest("getInboxMessages",t)},t.prototype.inboxStatus=function(t){return this.createRequest("inboxStatus",t)},t.prototype.pageVisit=function(t,e){return this.createRequest("pageVisit",t,e)},t.prototype.setPurchase=function(t){return this.createRequest("setPurchase",t)},t.prototype.createRequest=function(t,e,r,o){return s(this,void 0,void 0,(function(){var s,a,u,c,h,p,d;return i(this,(function(i){switch(i.label){case 0:return[4,this.data.getApiEntrypoint()];case 1:return s=i.sent(),o?(u="",[3,4]):[3,2];case 2:return[4,this.data.getApiToken()];case 3:u=i.sent(),i.label=4;case 4:return c=r||s+t,h=(a=u)?{headers:{Authorization:"Token ".concat(a),"Content-Type":"text/plain;charset=UTF-8",Origin:globalThis.location.origin},credentials:"include"}:{},[4,fetch(c,n({method:"POST",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:JSON.stringify({request:e})},h))];case 5:return p=i.sent(),[4,this.checkResponse(p)];case 6:return(d=i.sent()).base_url?[4,this.data.setApiEntrypoint(d.base_url)]:[3,8];case 7:i.sent(),i.label=8;case 8:return[4,this.logger.write("apirequest","".concat(t," call with arguments: ").concat(JSON.stringify(e)," to Pushwoosh has been successful. Result: ").concat(JSON.stringify(d.response)))];case 9:return i.sent(),[2,d.response]}}))}))},t.prototype.checkResponse=function(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:if(200!==t.status)throw new Error("Error code: ".concat(t.status,". Error text: ").concat(t.statusText));return[4,t.json()];case 1:if(200!==(e=n.sent()).status_code)throw new Error("Error code: ".concat(e.status_code,". Error text: ").concat(e.status_message));return[2,e]}}))}))},t}(),gt=function(){function t(t,e,n){void 0===e&&(e=new dt),void 0===n&&(n=new vt),this.eventBus=t,this.data=e,this.apiClient=n}return t.prototype.checkDevice=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return t=e.sent(),[4,this.apiClient.checkDevice(t)];case 2:return[2,e.sent()]}}))}))},t.prototype.checkDeviceSubscribeForPushNotifications=function(){return s(this,arguments,void 0,(function(t){var e,n,r,s;return void 0===t&&(t=!0),i(this,(function(i){switch(i.label){case 0:return void 0!==(e=localStorage.getItem(a))&&t?[3,2]:[4,this.checkDevice()];case 1:n=i.sent(),r=n.exist,s=n.push_token_exist,localStorage.setItem(a,r&&s?u:c),e=localStorage.getItem(a),i.label=2;case 2:return[2,e===u]}}))}))},t.prototype.getConfig=function(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(r){switch(r.label){case 0:return[4,this.getRequestParams()];case 1:return e=r.sent(),[2,this.apiClient.getConfig(n(n({},e),{features:t}))]}}))}))},t.prototype.applicationOpen=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return t=e.sent(),[4,this.data.setLastOpenApplicationTime(Date.now())];case 2:return e.sent(),[2,this.apiClient.applicationOpen(t)]}}))}))},t.prototype.registerDevice=function(){return s(this,void 0,void 0,(function(){var t,e,r;return i(this,(function(s){switch(s.label){case 0:return[4,this.data.getStatusCommunicationDisabled()];case 1:if(s.sent())throw new Error("Can't register device: Communication is disabled!");return[4,this.getRequestParams()];case 2:return t=s.sent(),[4,this.data.getTokens()];case 3:if(!(e=s.sent()).pushToken)throw new Error("Can't register device: pushToken is not exist!");return[4,this.apiClient.registerDevice(n(n({},t),{push_token:e.pushToken,auth_token:e.authToken,public_key:e.publicKey}))];case 4:return r=s.sent(),[4,this.data.setStatusManualUnsubscribed(!1)];case 5:return s.sent(),localStorage.setItem(a,u),this.eventBus.dispatchEvent("register",{}),[2,r]}}))}))},t.prototype.unregisterDevice=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.getRequestParams()];case 1:return t=n.sent(),e=this.apiClient.unregisterDevice(t),localStorage.setItem(a,c),this.eventBus.dispatchEvent("unsubscribe",{}),[2,e]}}))}))},t.prototype.deleteDevice=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.getRequestParams()];case 1:return t=n.sent(),e=this.apiClient.deleteDevice(t),[4,this.data.setStatusManualUnsubscribed(!0)];case 2:return n.sent(),localStorage.setItem(a,c),this.eventBus.dispatchEvent("unsubscribe",{}),[2,e]}}))}))},t.prototype.messageDeliveryEvent=function(t,e){return s(this,arguments,void 0,(function(t,e,r){var s;return void 0===r&&(r={}),i(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return s=e.sent(),[4,this.apiClient.messageDeliveryEvent(n(n({},s),{hash:t,metaData:r}))];case 2:return[2,e.sent()]}}))}))},t.prototype.pushStat=function(t,e){return s(this,arguments,void 0,(function(t,e,r){var s;return void 0===r&&(r={}),i(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return s=e.sent(),[4,this.apiClient.pushStat(n(n({},s),{hash:t,metaData:r}))];case 2:return[2,e.sent()]}}))}))},t.prototype.setTags=function(t){return s(this,void 0,void 0,(function(){var e,s,o,a,u;return i(this,(function(i){switch(i.label){case 0:return[4,this.getRequestParams()];case 1:return e=i.sent(),s=e.hwid,o=e.device_type,a=r(e,["hwid","device_type"]),[4,this.data.getEmail()];case 2:return(u=i.sent())?[4,this.apiClient.setEmailTags(n(n({},a),{email:u,tags:t}))]:[3,4];case 3:i.sent(),i.label=4;case 4:return[2,this.apiClient.setTags(n(n({},a),{hwid:s,device_type:o,tags:t}))]}}))}))},t.prototype.getTags=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return t=e.sent(),[2,this.apiClient.getTags(t)]}}))}))},t.prototype.registerUser=function(t){return s(this,void 0,void 0,(function(){var e,s,o,a,u,c,h;return i(this,(function(i){switch(i.label){case 0:return[4,this.getRequestParams()];case 1:return e=i.sent(),s=e.hwid,e.device_type,o=r(e,["hwid","device_type"]),[4,this.data.getDeviceType()];case 2:return a=i.sent(),u="".concat(t),[4,this.data.getEmail()];case 3:return c=i.sent(),[4,this.apiClient.registerUser(n(n({},o),{hwid:s,userId:u,ts_offset:60*-(new Date).getTimezoneOffset(),device_type:a}))];case 4:return h=i.sent(),c?[4,this.apiClient.registerEmailUser(n(n({},o),{email:c,userId:u,ts_offset:60*-(new Date).getTimezoneOffset()}))]:[3,6];case 5:i.sent(),i.label=6;case 6:return[4,this.data.setUserId("".concat(t))];case 7:return i.sent(),[4,this.data.setStatusUserIdWasChanged(!0)];case 8:return i.sent(),[2,h]}}))}))},t.prototype.registerEmail=function(t){return s(this,void 0,void 0,(function(){var e,s,o;return i(this,(function(i){switch(i.label){case 0:return[4,this.getRequestParams()];case 1:return e=i.sent(),e.hwid,e.device_type,s=r(e,["hwid","device_type"]),[4,this.apiClient.registerEmail(n(n({},s),{email:t,ts_offset:60*-(new Date).getTimezoneOffset()}))];case 2:return o=i.sent(),[4,this.data.setEmail("".concat(t))];case 3:return i.sent(),[4,this.data.setStatusEmailWasChanged(!0)];case 4:return i.sent(),[2,o]}}))}))},t.prototype.postEvent=function(t,e){return s(this,void 0,void 0,(function(){var r,s,o,a,u,c,h;return i(this,(function(i){switch(i.label){case 0:return[4,this.getRequestParams()];case 1:return r=i.sent(),s=new Date,o=s.getTime(),a=Math.floor(o/1e3),u=a-s.getTimezoneOffset()/60*3600,[4,this.data.getLastOpenMessage()];case 2:if((c=i.sent())&&c.expiry>Date.now()){if(e.msgHash)return[2,Promise.reject("attribute msgHash already defined")];e=n(n({},e),{msgHash:c.messageHash})}return[4,this.data.setLastOpenMessage(void 0)];case 3:return i.sent(),[4,this.apiClient.postEvent(n(n({},r),{event:t,timestampUTC:a,timestampCurrent:u,attributes:e}))];case 4:return(h=i.sent())&&h.code&&this.eventBus.dispatchEvent("receive-in-app-code",{code:h.code}),[2,h]}}))}))},t.prototype.getInboxMessages=function(){return s(this,arguments,void 0,(function(t){var e,r,s;return void 0===t&&(t=0),i(this,(function(i){switch(i.label){case 0:return[4,this.getRequestParams()];case 1:return e=i.sent(),[4,this.data.getInboxLastRequestCode()];case 2:return r=i.sent(),[4,this.data.getInboxLastRequestTime()];case 3:return s=i.sent(),[2,this.apiClient.getInboxMessages(n(n({},e),{count:t,last_code:r,last_request_time:s}))]}}))}))},t.prototype.inboxStatus=function(t,e){return s(this,void 0,void 0,(function(){var r;return i(this,(function(s){switch(s.label){case 0:return[4,this.getRequestParams()];case 1:return r=s.sent(),[2,this.apiClient.inboxStatus(n(n({},r),{inbox_code:t,status:e,time:(new Date).getTime()}))]}}))}))},t.prototype.triggerEvent=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){throw new Error("Method has been deprecated, because we don't aggregate this statistics.")}))}))},t.prototype.pageVisit=function(t){return s(this,void 0,void 0,(function(){var e,r,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getRequestParams()];case 1:return e=i.sent(),[4,this.data.getFeatures()];case 2:return r=i.sent(),(s=r&&r.page_visit&&r.page_visit.entrypoint)?[2,this.apiClient.pageVisit(n(n({},e),t),s)]:[2]}}))}))},t.prototype.setPurchase=function(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(r){switch(r.label){case 0:return[4,this.getRequestParams()];case 1:return e=r.sent(),[2,this.apiClient.setPurchase(n(n({},e),t))]}}))}))},t.prototype.getParams=function(){return s(this,void 0,void 0,(function(){var t,e,r,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.data.getApplicationCode()];case 1:return t=i.sent(),[4,this.data.getHwid()];case 2:return e=i.sent(),[4,this.data.getTokens()];case 3:return r=i.sent(),[4,this.data.getInitParams()];case 4:return s=i.sent(),[2,n(n({applicationCode:t,hwid:e},r),s)]}}))}))},Object.defineProperty(t.prototype,"params",{get:function(){throw new Error('Property "Pushwoosh.api.params" have been deprecated. Use the async method "Pushwoosh.api.getParams()"')},enumerable:!1,configurable:!0}),t.prototype.getRequestParams=function(){return s(this,void 0,void 0,(function(){var t,e,n,r,s,o,a,u;return i(this,(function(i){switch(i.label){case 0:return[4,this.data.getApplicationCode()];case 1:return t=i.sent(),[4,this.data.getHwid()];case 2:return e=i.sent(),[4,this.data.getUserId()];case 3:return n=i.sent(),[4,this.data.getDeviceType()];case 4:return r=i.sent(),[4,this.data.getDeviceModel()];case 5:return s=i.sent(),[4,this.data.getLanguage()];case 6:return o=i.sent(),[4,this.data.getSdkVersion()];case 7:return a=i.sent(),u=60*-(new Date).getTimezoneOffset(),[2,{application:t,hwid:e,userId:n||e,device_type:r,device_model:s,timezone:u,language:o,v:a}]}}))}))},t}(),mt=function(){function t(t,e,n){this.api=t,this.data=e,this.config=n}return t.prototype.getPermission=function(){return Notification.permission},t.prototype.checkIsPermissionGranted=function(){return"granted"===this.getPermission()},t.prototype.checkIsPermissionDefault=function(){return"default"===this.getPermission()},t.prototype.checkIsManualUnsubscribed=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.data.getStatusManualUnsubscribed()]}))}))},t.prototype.askPermission=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,Notification.requestPermission()];case 1:return t.sent(),[2]}}))}))},t.prototype.getTokens=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.data.getTokens()]}))}))},t.prototype.subscribe=function(t){return s(this,void 0,void 0,(function(){var e,n,r,s,o,a,u;return i(this,(function(i){switch(i.label){case 0:return(n=t)?[3,2]:[4,this.trySubscribe()];case 1:n=i.sent(),i.label=2;case 2:if(e=n,!this.checkIsPermissionGranted())return tt.error("You must have permission granted before subscribe!"),[2];if(r=this.getPushToken(e),s=e.getKey("p256dh"),o=e.getKey("auth"),!s||!o)throw new Error("Can't get subscription keys!");return a=btoa(String.fromCharCode.apply(String,new Uint8Array(s))),u=btoa(String.fromCharCode.apply(String,new Uint8Array(o))),[4,this.data.setTokens({publicKey:a,pushToken:r,authToken:u,endpoint:e.endpoint})];case 3:return i.sent(),[4,this.api.registerDevice()];case 4:return i.sent(),[2]}}))}))},t.prototype.unsubscribe=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return[4,this.getServiceWorkerRegistration()];case 1:return[4,e.sent().pushManager.getSubscription()];case 2:return t=e.sent(),[4,this.data.setTokens({})];case 3:return e.sent(),[4,this.data.setStatusManualUnsubscribed(!0)];case 4:return e.sent(),[4,this.api.unregisterDevice()];case 5:return e.sent(),t?[4,t.unsubscribe()]:[2];case 6:return e.sent(),[2]}}))}))},t.prototype.checkIsRegister=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.api.checkDeviceSubscribeForPushNotifications()]}))}))},t.prototype.checkIsNeedResubscribe=function(){return s(this,void 0,void 0,(function(){var t,e,n,r,s,o,a,u;return i(this,(function(i){switch(i.label){case 0:return[4,this.data.getLastPermissionStatus()];case 1:return t=i.sent(),e=this.getPermission(),t===e?[3,3]:[4,this.data.setLastPermissionStatus(e)];case 2:return i.sent(),[2,!0];case 3:return[4,this.getCredentials()];case 4:return n=i.sent(),r=this.getPushToken(n),[4,this.data.getTokens()];case 5:return s=i.sent(),o=s&&s.pushToken||"",a=r===o,[4,this.data.getIsVapidChanged()];case 6:return u=i.sent(),[2,!a||u]}}))}))},t.prototype.getServiceWorkerRegistration=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return this.registration?[3,5]:[4,this.registerServiceWorker()];case 1:return n.sent(),[4,this.data.getServiceWorkerUrl()];case 2:return t=n.sent(),e=this,[4,navigator.serviceWorker.getRegistration(t)];case 3:return e.registration=n.sent(),[4,this.registration.update()];case 4:n.sent(),n.label=5;case 5:if(!this.registration)throw new Error("Internal Error: Can't register service worker!");return[2,this.registration]}}))}))},t.prototype.registerServiceWorker=function(){return s(this,void 0,void 0,(function(){var t,e,n,r,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.data.getServiceWorkerUrl()];case 1:return t=i.sent(),[4,this.data.getServiceWorkerScope()];case 2:return e=i.sent(),[4,this.data.getSdkVersion()];case 3:return n=i.sent(),[4,this.data.getServiceWorkerVersion()];case 4:return r=i.sent(),s="",n!==r&&(s="?cache_clean=".concat(v())),[4,navigator.serviceWorker.register("".concat(t).concat(s),{scope:e})];case 5:return i.sent(),[2]}}))}))},t.prototype.trySubscribe=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,4]),[4,this.subscribePushManager()];case 1:return[2,e.sent()];case 2:return t=e.sent(),console.error(t),[4,this.unsubscribe()];case 3:return e.sent(),[2,this.subscribePushManager()];case 4:return[2]}}))}))},t.prototype.subscribePushManager=function(){return s(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return[4,this.getServiceWorkerRegistration()];case 1:return t=n.sent(),[4,this.getApplicationServerKey()];case 2:return e=n.sent(),[2,t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:e?this.urlBase64ToUint8Array(e):null})]}}))}))},t.prototype.getCredentials=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.getServiceWorkerRegistration()];case 1:return[4,t.sent().pushManager.getSubscription()];case 2:return[2,t.sent()]}}))}))},t.prototype.getPushToken=function(t){return t?t.endpoint:""},t.prototype.getApplicationServerKey=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.data.getDeviceType()];case 1:return 11!==t.sent()?[2]:[4,this.data.getApplicationServerKey()];case 2:return[2,t.sent()]}}))}))},t.prototype.urlBase64ToUint8Array=function(t){for(var e=(t+"=".repeat((4-t.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),n=atob(e),r=new Uint8Array(n.length),s=0;s<n.length;++s)r[s]=n.charCodeAt(s);return r},t}(),yt=function(){function t(t,e,n){this._listeners={},this.eventBus=t,this.data=e,this.api=n}return t.prototype.push=function(t){Array.isArray(t)&&"onPush"===t[0]&&"function"==typeof t[1]&&(this._listeners[t[0]]||(this._listeners[t[0]]=[]),this._listeners[t[0]].push(t[1]))},t.prototype.getListeners=function(t){return this._listeners[t]||[]},t.prototype.initApi=function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){return[2,Promise.resolve()]}))}))},t}();const bt=yt;var wt=function(){function t(t,e,n){this._canceled=!1,this.showNotificationOptions=t,this.body=e,this.title=n}return t.prototype.show=function(){return s(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return this._canceled?[2]:(t=this.showNotificationOptions).silent?[3,2]:[4,self.registration.showNotification(this.title,t)];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))},t.prototype.cancel=function(){this._canceled=!0},t}();const St=wt;var Et=new m,Mt=new dt,xt=new gt(Et,Mt),Pt=self.Pushwoosh=new bt(Et,Mt,xt),Dt=[];function Ct(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,self.clients.matchAll()];case 1:return e.sent().forEach((function(e){return e.postMessage(t)})),[2]}}))}))}function Tt(t){return s(this,void 0,void 0,(function(){var e,n,r,s,o,a;return i(this,(function(i){return e=t.notification,r=(n=void 0===e?{}:e).data,s=b(n.tag,{}),o="",t.action&&Array.isArray(r.buttons)?(a=r.buttons.find((function(e){return e.action===t.action}))||{},o=a.url):o=s.url,[2,{title:n.title,body:n.body,icon:n.icon,buttons:r.buttons,image:r.image,code:r.code,campaignCode:r.campaignCode,inboxId:r.inboxId,messageHash:s.messageHash,customData:s.customData,metaData:s.metaData,openUrl:s.url,tag:n.tag,url:o}]}))}))}function It(t){return s(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return[4,Pt.data.getApplicationCode()];case 1:return e=r.sent(),[4,Pt.data.getServiceWorkerVersion()];case 2:return n=r.sent(),[4,k({message:"Error in onInstallEventHandler",code:"FATAL-SW-001",error:t,applicationCode:e,workerVersion:n})];case 3:return r.sent(),[2]}}))}))}function kt(t){return s(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return[4,Pt.data.getApplicationCode()];case 1:return e=r.sent(),[4,Pt.data.getServiceWorkerVersion()];case 2:return n=r.sent(),[4,k({message:"Error in onActivateEventHandler",code:"FATAL-SW-002",error:t,applicationCode:e,workerVersion:n})];case 3:return r.sent(),[2]}}))}))}function At(t){return s(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return[4,Pt.data.getApplicationCode()];case 1:return e=r.sent(),[4,Pt.data.getServiceWorkerVersion()];case 2:return n=r.sent(),[4,k({message:"Error in onNotificationClickEventHandler",code:"FATAL-SW-004",error:t,applicationCode:e,workerVersion:n})];case 3:return r.sent(),[2]}}))}))}function Ot(t){return s(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return[4,Pt.data.getApplicationCode()];case 1:return e=r.sent(),[4,Pt.data.getServiceWorkerVersion()];case 2:return n=r.sent(),[4,k({message:"Error in onNotificationCloseEventHandler",code:"FATAL-SW-005",error:t,applicationCode:e,workerVersion:n})];case 3:return r.sent(),[2]}}))}))}function Rt(t){return s(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return[4,Pt.data.getApplicationCode()];case 1:return e=r.sent(),[4,Pt.data.getServiceWorkerVersion()];case 2:return n=r.sent(),[4,k({message:"Error in onPushSubscriptionChange",code:"FATAL-SW-006",error:t,applicationCode:e,workerVersion:n})];case 3:return r.sent(),[2]}}))}))}return self.addEventListener("install",(function(t){return t.waitUntil(function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,Promise.all([Pt.data.setServiceWorkerVersion("3.39.8"),tt.write("info","install")])];case 1:return t.sent(),[4,self.skipWaiting()];case 2:return t.sent(),[2]}}))}))}().catch(It))})),self.addEventListener("activate",(function(t){t.waitUntil(function(){return s(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,Promise.all([tt.write("info","activate")])];case 1:return t.sent(),[4,self.clients.claim()];case 2:return t.sent(),[2]}}))}))}().catch(kt))})),self.addEventListener("push",(function(t){t.waitUntil(function(t){return s(this,void 0,void 0,(function(){var e,n,r,s,o,a,u,c,h,p,d,l,f;return i(this,(function(i){switch(i.label){case 0:return[4,self.clients.claim()];case 1:return i.sent(),[4,t.data.json()];case 2:return e=i.sent(),[4,(n=new ft(e)).getNotificationOptionsPayload()];case 3:return r=i.sent(),[4,n.getShowNotificationOptions()];case 4:return s=i.sent(),o=n.messageHash,[4,tt.write("info",JSON.stringify(r),"onPush")];case 5:return i.sent(),u=St.bind,c=[void 0,s,n.body],[4,n.getTitle()];case 6:return a=new(u.apply(St,c.concat([i.sent()]))),[4,Pt.getListeners("onPush").reduce((function(t,e){return t.then((function(){return e(a)}))}),Promise.resolve())];case 7:return i.sent(),h=[a.show(),Q.add({payload:e,parsedPayload:r,showOptions:s}),Ct({type:"onPushDelivery",payload:r})],o&&h.push(Pt.initApi().then((function(){return Pt.api.messageDeliveryEvent(o,!0,r.metaData)}))),""===n.inboxId?[3,10]:(p=new ut(Pt.eventBus,Pt.data,Pt.api),d=new nt(Pt.data,Pt.api,p),[4,n.getInboxMessage()]);case 8:return l=i.sent(),[4,d.publicMessageBuilder(l)];case 9:f=i.sent(),h.push(p.putMessage(l),Ct({type:"onPutNewMessageToInboxStore",payload:f})),i.label=10;case 10:return[4,Promise.all(h)];case 11:return i.sent(),[2]}}))}))}(t).catch((function(e){return function(t,e){return s(this,void 0,void 0,(function(){var n,r;return i(this,(function(s){switch(s.label){case 0:return[4,Pt.data.getApplicationCode()];case 1:return n=s.sent(),[4,Pt.data.getServiceWorkerVersion()];case 2:return r=s.sent(),[4,k({message:"Error in onPushEventHandler",code:"FATAL-SW-003",error:t,applicationCode:n,workerVersion:r})];case 3:return s.sent(),t instanceof Error||(t=new Error(t)),[2,Q.add({error:"".concat(t),stack:t.stack,payload:e.data&&e.data.text()})]}}))}))}(e,t)})))})),self.addEventListener("notificationclick",(function(t){t.waitUntil(function(t){return s(this,void 0,void 0,(function(){var e,n,r,o,a,u,c,h,p;return i(this,(function(d){switch(d.label){case 0:return[4,self.clients.claim()];case 1:return d.sent(),[4,Tt(t)];case 2:return e=d.sent(),n=e.messageHash,r=e.metaData,o=e.url,a=e.code,u=e.inboxId,a&&Dt.push(a),""===u?[3,5]:[4,(c=new ut(Pt.eventBus,Pt.data,Pt.api)).getMessage(u)];case 3:return(h=d.sent()).status=3,[4,c.putMessage(h)];case 4:d.sent(),d.label=5;case 5:return t.notification.close(),p={type:"onNotificationClick",payload:e},o&&t.waitUntil(self.clients.matchAll({type:"window"}).then((function(t){return function(t,e){return s(this,void 0,void 0,(function(){var n,r,s,o;return i(this,(function(i){switch(i.label){case 0:return n=new URL(e,self.location.origin),r=n.hostname,s=n.pathname,o=t.find((function(t){var e=new URL(t.url),n=e.hostname,i=e.pathname;return n===r&&i===s})),o?[4,o.focus()]:[3,2];case 1:return i.sent(),[2,!1];case 2:return[4,self.clients.openWindow(e).then((function(t){t&&t.focus()}))];case 3:return i.sent(),[2,!0]}}))}))}(t,o)})).then((function(t){t&&Pt.data.setDelayedEvent(p)}))),[2,Promise.all([Pt.initApi().then((function(){return Pt.api.pushStat(n,!0,r)})),Pt.data.setLastOpenMessage({url:o,messageHash:n,expiry:Date.now()+864e5}),Ct(p)])]}}))}))}(t).catch(At))})),self.addEventListener("notificationclose",(function(t){t.waitUntil(function(t){return s(this,void 0,void 0,(function(){var e,n,r;return i(this,(function(s){switch(s.label){case 0:return[4,self.clients.claim()];case 1:return s.sent(),[4,Tt(t)];case 2:return e=s.sent(),n=e.code,t.notification.close(),n?(r=Dt.indexOf(n))>=0?(Dt.splice(r,1),[2]):[2,Ct({type:"onNotificationClose",payload:e})]:[2]}}))}))}(t).catch(Ot))})),self.addEventListener("pushsubscriptionchange",(function(t){return s(this,void 0,void 0,(function(){return i(this,(function(e){return t.waitUntil(function(t){return s(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return(e=t.newSubscription)?[3,2]:[4,self.registration.pushManager.getSubscription()];case 1:if(!(e=n.sent()))return[2];n.label=2;case 2:return[4,new mt(xt,Mt,{}).subscribe(e)];case 3:return n.sent(),[2]}}))}))}(t).catch(Rt)),[2]}))}))})),{}})()));
|
|
1
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var a in s)("object"==typeof exports?exports:t)[a]=s[a]}}(this,(()=>(()=>{"use strict";const t="deviceRegistrationStatus",e="registered",s="unregistered";function a(t,e){if("string"==typeof t)try{return JSON.parse(t)}catch(t){console.log(t)}return void 0===t&&void 0!==e?e:t}function i(){return crypto.randomUUID?.()||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))}const r=t=>"function"==typeof t;const n="silent",o="fatal",c="error",u="warn",h="info",d="debug",l={[n]:0,[o]:10,[c]:20,[u]:30,[h]:40,[d]:50};function g(t){const{code:e,text:s,type:a}=t,i=function(t){switch(t){case"fatal":case"error":return console.error;case"warn":case"info":case"debug":return console.log}}(a);console.groupCollapsed(a),i(e?`${e}: ${s}`:s),console.groupEnd()}const p=new class{constructor(t){this.relations=l,this.level=t&&void 0!==t.level?t.level:c,this.applicationType=t&&void 0!==t.applicationType?t.applicationType:"sdk",this.subscribers=t&&void 0!==t.subscribers?t.subscribers:[]}updateLogLevel(t){this.level=t}updateApplicationType(t){this.applicationType=t}updateApplicationCode(t){this.applicationCode=t}updateDomain(t){this.domain=t}updateDeviceInfo(t){this.deviceInfo=t}subscribe(t,e){this.subscribers.push({handler:e,level:t})}async log(t){const e=[],{options:s,...a}=t;let i=a;if(s){const{handler:t,...e}=s;i={...a,...e}}const r=this.getMessage(i);this.subscribers.forEach((s=>{s.level===t.type&&this.relations[s.level]<=this.relations[this.level]&&e.push(s.handler.call(null,r))})),s&&s.handler&&this.level!==n&&s.handler.call(null,r),await Promise.all(e)}async debug(t,e){return this.log({type:d,text:t,options:e})}async info(t,e){return this.log({type:h,text:t,options:e})}async warn(t,e,s){return this.log({type:u,text:t,code:e,options:s})}async error(t,e,s){return this.log({type:c,text:t,code:e,options:s})}async fatal(t,e,s){return this.log({type:o,text:t,code:e,options:s})}async errorAndThrow(t,e,s){return this.logAndThrow({type:c,text:t,code:e,options:s})}async errorAndReject(t,e,s,a){return this.logAndReject(t,{type:c,text:e,code:s,options:a})}async fatalAndThrow(t,e,s){return this.logAndThrow({type:o,text:t,code:e,options:s})}async fatalAndReject(t,e,s,a){return this.logAndReject(t,{type:o,text:e,code:s,options:a})}async logAndThrow(t){await this.log(t);const e=new Error(t.text);throw t.code&&(e.code=t.code),e}async logAndReject(t,e){await this.log(e);const s=new Error(e.text);e.code&&(s.code=e.code),t(s)}getMessage(t){return{applicationCode:this.applicationCode,domain:this.domain,applicationType:this.applicationType,deviceInfo:this.deviceInfo,...t}}}({level:"error",subscribers:[{level:"fatal",handler:g},{level:"error",handler:g}]});async function m(t){const e=w(t);return p.fatal(e.text,e.code,e.options)}function w(t){const{message:e,code:s,error:a,...i}=t,r=function(t){let e=new Error("unknown error");"string"!=typeof t&&"number"!=typeof t&&"boolean"!=typeof t||(e.message=t.toString());t instanceof Error&&(e=t);return e}(a);return{text:e,code:s,options:{...i,errorText:r.message,errorStack:r.stack}}}const y="keyValue",b="messages",f="log",v="inboxMessages";function x(t,e){return function(s){s.objectStoreNames.contains(t)||e(s)}}const S=[x(v,(function(t){const e="status",s=t.createObjectStore(v,{keyPath:"inbox_id",autoIncrement:!1});s.createIndex(e,e,{unique:!1,multiEntry:!0}),s.createIndex("rt","rt",{unique:!1,multiEntry:!0})}))];const M=[x(y,(function(t){t.createObjectStore(y,{keyPath:"key"})})),x(f,(function(t){const e=t.createObjectStore(f,{keyPath:"id",autoIncrement:!0});e.createIndex("environment","environment",{unique:!1}),e.createIndex("date","date",{unique:!1}),e.createIndex("type","type",{unique:!1})})),x(b,(function(t){t.createObjectStore(b,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}))];class C{constructor(t=new Date){this._date=t}set date(t){this._date=t}get date(){return this._date}getUtcTimestamp(){return Math.floor((this.date.getTime()+60*this.date.getTimezoneOffset()*1e3)/1e3)}getTimestamp(){return Math.round(this.date.getTime()/1e3)}setLocal(){const t=this._date.getTime()-60*this.date.getTimezoneOffset()*1e3;this._date=new Date(t)}addDays(t){const e=this._date.getTime()+24*t*60*60*1e3;this._date=new Date(e)}getInboxFakeOrder(){return(100*this._date.getTime()+9e9).toString()}}class T{constructor(t=new C){this.migrations={initial:M,"2018/11/26":S},this.dateModule=t}get initial(){return this.migrations.initial}get dateSorted(){return Object.keys(this.migrations).filter((t=>"initial"!==t)).sort(((t,e)=>{const s=new C(new Date(t)),a=new C(new Date(e));return s.getTimestamp()-a.getTimestamp()})).map((t=>this.migrations[t]))}}class k{constructor(t,e=new T){this.db=t,this.migrationsBuilder=e}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.initial),this.migrationsBuilder.dateSorted.forEach((t=>{this.applyMigrationsPack(t)}))}applyMigrationsPack(t){t.forEach((t=>{t(this.db)}))}}function D(t,e){console.info("onversionchange",e),t.close()}let P;function I(t){return(P||(P=new Promise(((t,e)=>{const s=indexedDB.open("PUSHWOOSH_SDK_STORE",7);s.onsuccess=s=>{const a=s.target.result;a.onversionchange=D.bind(null,a,e),t(a)},s.onerror=()=>e(s.error),s.onupgradeneeded=t=>{const s=t.target.result;s.onversionchange=D.bind(null,s,e),new k(s).applyMigrations()}}))),P).then((e=>new Promise(((s,a)=>t(e,s,a)))))}class E{_add(t){return I(((e,s,a)=>{const i=e.transaction([this.name],"readwrite").objectStore(this.name).add(t);i.onsuccess=()=>{s(t)},i.onerror=()=>{a(i.error)}})).then((t=>this.getAll().then((e=>{if(Array.isArray(e)){const s=e.map((t=>t.id)).sort(((t,e)=>t==e?0:t<e?1:-1));if(s.length>this.maxItems)return Promise.all(s.slice(this.maxItems).map((t=>this.delete(t)))).then((()=>t))}return t}))))}delete(t){return I(((e,s,a)=>{const i=e.transaction([this.name],"readwrite").objectStore(this.name).delete(t);i.onsuccess=()=>{s(i.result)},i.onerror=()=>{a(i.error)}}))}getAll(){return I(((t,e,s)=>{const a=[],i=t.transaction(this.name).objectStore(this.name).openCursor();i.onsuccess=t=>{const s=t.target.result;s?(s.value&&a.push(s.value),s.continue()):e(a)},i.onerror=()=>{s(i.error)}}))}}const R=(A=y,{get:(t,e)=>I(((s,a,i)=>{const r=s.transaction(A).objectStore(A).get(t);let n,o=!1,c=!1;const u=()=>{clearTimeout(n),o?a(r.result?.value||e):c?i(r.error):n=setTimeout(u,0)};r.onsuccess=()=>o=!0,r.onerror=()=>c=!0,u()})),getAll:()=>I(((t,e,s)=>{const a={},i=t.transaction(A).objectStore(A).openCursor();let r,n=!1,o=!1;const c=()=>{clearTimeout(r),n?e(a):o?s(i.error):r=setTimeout(c,0)};i.onsuccess=t=>{const e=t.target.result;e?(a[e.key]=e.value.value,e.continue()):n=!0},i.onerror=()=>o=!0,c()})),async extend(t,e){const s=await this.get(t),{...a}=e;await this.set(t,{...s,...a})},set:(t,e)=>I(((s,a,i)=>{const r=s.transaction([A],"readwrite").objectStore(A).put({key:t,value:e});let n,o=!1,c=!1;const u=()=>{clearTimeout(n),o?a(t):c?i(r.error):n=setTimeout(u,0)};r.onsuccess=()=>o=!0,r.onerror=()=>c=!0,u()}))});var A;const q=new class extends E{constructor(){super(...arguments),this.name=f,this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(t,e,s){const a={type:t,environment:this.environment,message:`${e}`,date:new Date};return e instanceof Error&&(a.stack=e.stack),s&&(a.additional=s),this._add(a)}},_=new class extends E{constructor(){super(...arguments),this.name=b,this.maxItems=25}add(t){return this._add({...t,date:new Date})}},W={error:1,info:2,debug:3};let O=3;!function(){const t=["assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"],e=globalThis,s=e.console=e.console||{};for(const e of t)s[e]||(s[e]=()=>{})}();const U={setLevel(t){W[t]||(t="error"),O=W[t]},write(t,e,s){return"error"===t?this.error(e):this.info(e),q.add(t,e,s)}};Object.keys(W).forEach((t=>{const e=W[t];U[t]=(...s)=>{e<=O&&(console.groupCollapsed(t),console.info("",...s),console.trace("trace"),console.groupEnd())}}));class N{constructor(t,e,s,a=new C){this.data=t,this.api=e,this.inboxModel=s,this.dateModule=a,this.publicMessageBuilder=this.publicMessageBuilder.bind(this)}messageTypeFactory(t,e){let s=0;return 2===t?s=1:"l"in e&&null!=e.l&&(s=e.l.startsWith("http")?2:3),s}async updateMessagesStatusWithCodes(t,e,s){const a=[],i=[];e.forEach((async e=>{-1!==t.indexOf(e.inbox_id)&&(e.status=s,a.push(e),i.push(this.api.inboxStatus(e.order,e.status)))})),await this.inboxModel.putBulkMessages(a),await Promise.all(i)}async publicMessageBuilder({action_type:t,action_params:e,image:s,title:a,send_date:i,inbox_id:r,text:n,status:o}){const c=s||await this.data.getDefaultNotificationImage(),u=a||await this.data.getDefaultNotificationTitle(),h=JSON.parse(e);return this.dateModule.date=new Date(1e3*parseInt(i)),this.dateModule.setLocal(),{title:u,imageUrl:c,code:r,message:n,sendDate:this.dateModule.date.toISOString(),type:this.messageTypeFactory(t,h),link:h?.l||"/",isRead:2===o||3===o,isActionPerformed:3===o}}messagesWithNoActionPerformedCount(){return this.inboxModel.getDeliveredReadMessagesCount()}unreadMessagesCount(){return this.inboxModel.getDeliveredMessagesCount()}messagesCount(){return this.inboxModel.messagesCount()}async loadMessages(){const t=[...await this.inboxModel.getReadOpenMessages(),...await this.inboxModel.getDeliveredMessages()].sort(((t,e)=>parseInt(e.send_date,10)-parseInt(t.send_date,10))).sort(((t,e)=>parseInt(e.order||"0",10)-parseInt(t.order||"0",10))).map(this.publicMessageBuilder);return Promise.all(t)}async readMessagesWithCodes(t){const e=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(t,e,2)}async performActionForMessageWithCode(t){const e=await this.inboxModel.getMessage(t),s=JSON.parse(e.action_params),a=this.messageTypeFactory(e.action_type,s);2===a&&null!=s.l?document.location.href=s.l:3===a&&null!=s.l&&window.history.go(s.l),e.status=3,await this.inboxModel.putMessage(e),await this.api.inboxStatus(e.order,e.status)}async deleteMessagesWithCodes(t){const e=await this.inboxModel.getReadOpenMessages(),s=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(t,[...e,...s],4)}async syncMessages(){await this.inboxModel.updateMessages()}}class L{constructor(t,e){this.name=e,this.store=t.transaction(this.name,"readwrite").objectStore(this.name)}set index(t){this.store.indexNames.contains(t)?this._index=this.store.index(t):console.warn(`Index "${t}" in `)}writeRequestPromise(t,e){return new Promise(((s,a)=>{t.onsuccess=()=>{s(e)},t.onerror=()=>{a(t.error)}}))}readRequestPromise(t,e){return new Promise(((s,a)=>{t.onsuccess=t=>{const a=t.target;s(a.result||e)},t.onerror=()=>{a(t.error)}}))}put(t,e){const s=this.store.put(t,e);return this.writeRequestPromise(s,e)}add(t,e){return this.put(t,e)}delete(t){const e=this.store.delete(t);return this.writeRequestPromise(e)}get(t,e){const s=this.store.get(t);return this.readRequestPromise(s,e)}getAll(){const t=this.store.openCursor(),e=[];return new Promise(((s,a)=>{t.onsuccess=t=>{const a=t.target.result;a?(e.push(a.value),a.continue()):s(e)},t.onerror=()=>{a(t.error)}}))}count(t){const e=this.store.count(t);return this.readRequestPromise(e,0)}countByIndex(t){const e=this._index.count(t);return this.readRequestPromise(e,0)}}class V{dbVersionChangeHandler(t,e){console.info("onversionchange",e),t.close()}dbRequestSuccessHandler(t,e){const s=e.target.result;s.onversionchange=t=>{this.dbVersionChangeHandler(s,t)},t(s)}dbRequestUpgradeNeededHandler(t){const e=t.target.result;e.onversionchange=t=>{this.dbVersionChangeHandler(e,t)};new k(e).applyMigrations()}getDB(){return new Promise(((t,e)=>{const s=indexedDB.open("PUSHWOOSH_SDK_STORE",7);s.onsuccess=e=>{this.dbRequestSuccessHandler(t,e)},s.onupgradeneeded=t=>{this.dbRequestUpgradeNeededHandler(t)},s.onerror=()=>e(s.error)}))}async put(t,e,s){const a=await this.getDB(),i=new L(a,t),r=await i.put(e,s);return a.close(),r}async delete(t,e){const s=await this.getDB(),a=new L(s,t),i=await a.delete(e);return s.close(),i}async get(t,e,s){const a=await this.getDB(),i=new L(a,t),r=await i.get(e,s);return a.close(),r}async getAll(t){const e=await this.getDB(),s=new L(e,t),a=await s.getAll();return e.close(),a||[]}async count(t,e){const s=await this.getDB(),a=new L(s,t),i=await a.count(e);return s.close(),i}async countByIndex(t,e,s){const a=await this.getDB(),i=new L(a,t);i.index=e;const r=await i.countByIndex(s);return a.close(),r}}class B{constructor(t,e,s,a=new V,i=new C){this.eventBus=t,this.data=e,this.api=s,this.storage=a,this.storeName="inboxMessages",this.dateModule=i}async getInboxMessages(){const t=await this.api.getInboxMessages();return await this.storeGetInboxMessagesRequestParams(t.next,t.new_inbox),t}async storeGetInboxMessagesRequestParams(t,e){this.dateModule.date=new Date,await this.data.setInboxLastRequestTime(this.dateModule.getUtcTimestamp()),await this.data.setInboxLastRequestCode(t),await this.data.setInboxNewMessagesCount(e)}async putServerMessages(t){const e=t.map((async t=>{const e=await this.storage.get(this.storeName,t.inbox_id,{});return"status"in e&&(t.status=e.status),this.putMessage(t)}));return Promise.all(e)}putMessage(t){return this.storage.put(this.storeName,t)}putBulkMessages(t){const e=t.map((t=>this.putMessage(t)));return Promise.all(e)}deleteMessages(t){const e=t.map((t=>this.storage.delete(this.storeName,t)));return Promise.all(e)}async deleteExpiredMessages(){this.dateModule.date=new Date;const t=this.dateModule.getTimestamp().toString(),e=(await this.storage.getAll(this.storeName)).filter((e=>e.rt<t)).map((t=>t.inbox_id));return this.deleteMessages(e)}getMessage(t){return this.storage.get(this.storeName,t)}async getReadOpenMessages(){return(await this.storage.getAll(this.storeName)).filter((t=>2===t.status||3===t.status))}async getDeliveredMessages(){return(await this.storage.getAll(this.storeName)).filter((t=>1===t.status))}async messagesCount(){return this.storage.count(this.storeName)}async getDeliveredMessagesCount(){return this.storage.countByIndex(this.storeName,"status",1)}async getReadMessagesCount(){return this.storage.countByIndex(this.storeName,"status",2)}async getDeliveredReadMessagesCount(){const[t,e]=[2,3],s=IDBKeyRange.bound(t,e);return this.storage.countByIndex(this.storeName,"status",s)}async updateMessages(){const t=await this.getInboxMessages();await this.deleteExpiredMessages(),t.deleted&&await this.deleteMessages(t.deleted),await this.putServerMessages(t.messages),this.eventBus.dispatchEvent("update-inbox-messages",{messages:new N(this.data,this.api,this)})}}const H={"&":"&","<":"<",">":">",""":'"',"'":"'"},j=/&(?:amp|lt|gt|quot|#39);/g,$=RegExp(j.source);class F{constructor(t=R){this.store=t}async clearAll(){await this.store.set("params.applicationCode",void 0),await this.store.set("params.hwid",void 0),await this.store.set("params.deviceType",void 0),await this.store.set("params.deviceModel",void 0),await this.store.set("params.language",void 0),await this.store.set("params.apiEntrypoint",void 0),await this.store.set("params.tokens",void 0),await this.store.set("params.applicationServerKey",void 0),await this.store.set("params.senderId",void 0),await this.store.set("params.webSitePushId",void 0),await this.store.set("params.defaultNotificationImage",void 0),await this.store.set("params.defaultNotificationTitle",void 0),await this.store.set("params.userId",void 0),await this.store.set("params.email",void 0),await this.store.set("params.userIdWasChanged",void 0),await this.store.set("params.isLastPermissionStatus",void 0),await this.store.set("params.isManualUnsubscribed",void 0),await this.store.set("params.isCommunicationDisabled",void 0),await this.store.set("params.isDropAllData",void 0),await this.store.set("params.sdkVersion",void 0),await this.store.set("params.serviceWorkerVersion",void 0),await this.store.set("params.serviceWorkerUrl",void 0),await this.store.set("params.serviceWorkerScope",void 0),await this.store.set("params.lastOpenMessage",void 0),await this.store.set("params.lastOpenApplicationTime",void 0),await this.store.set("params.features",void 0),await this.store.set("params.init",void 0)}async setApplicationCode(t){await this.store.set("params.applicationCode",t)}async getApplicationCode(){return await this.store.get("params.applicationCode")}async setApiToken(t){return await this.store.set("params.apiToken",t)}async getApiToken(){return await this.store.get("params.apiToken")}async setHwid(t){await this.store.set("params.hwid",t)}async getHwid(){return await this.store.get("params.hwid")}async setDeviceType(t){await this.store.set("params.deviceType",t)}async getDeviceType(){return await this.store.get("params.deviceType")}async setDeviceModel(t){await this.store.set("params.deviceModel",t)}async getDeviceModel(){return await this.store.get("params.deviceModel")}async setLanguage(t){await this.store.set("params.language",t)}async getLanguage(){return await this.store.get("params.language","en")}async setApiEntrypoint(t){await this.store.set("params.apiEntrypoint",t)}async getApiEntrypoint(){return await this.store.get("params.apiEntrypoint","https://cp.pushwoosh.com/json/1.3/")}async setTokens(t){await this.store.set("params.tokens",t)}getTokens(){return this.store.get("params.tokens")}async setApplicationServerKey(t){await this.store.set("params.applicationServerKey",t)}async getApplicationServerKey(){return await this.store.get("params.applicationServerKey")}async setIsVapidChanged(t){await this.store.set("params.isVapidChanged",t)}async getIsVapidChanged(){return await this.store.get("params.isVapidChanged",!1)}async setWebSitePushId(t){await this.store.set("params.webSitePushId",t)}async getWebSitePushId(){return await this.store.get("params.webSitePushId")}async setDefaultNotificationImage(t){await this.store.set("params.defaultNotificationImage",t)}async getDefaultNotificationImage(){return await this.store.get("params.defaultNotificationImage","https://cp.pushwoosh.com/img/logo-medium.png")}async setDefaultNotificationTitle(t){await this.store.set("params.defaultNotificationTitle",t)}async getDefaultNotificationTitle(){return await this.store.get("params.defaultNotificationTitle","Pushwoosh notification")}async setUserId(t){t?await this.store.set("params.userId",t.toString()):await this.store.set("params.userId",void 0)}async getUserId(){return await this.store.get("params.userId")}async setStatusUserIdWasChanged(t){await this.store.set("params.userIdWasChanged",t)}async getStatusUserIdWasChanged(){return await this.store.get("params.userIdWasChanged",!1)}async setEmail(t){t?await this.store.set("params.email",t.toString()):await this.store.set("params.email",void 0)}async getEmail(){return await this.store.get("params.email")}async setStatusEmailWasChanged(t){await this.store.set("params.emailWasChanged",t)}async getStatusEmailWasChanged(){return await this.store.get("params.emailWasChanged",!1)}async setLastPermissionStatus(t){await this.store.set("params.isLastPermissionStatus",t)}async getLastPermissionStatus(){return await this.store.get("params.isLastPermissionStatus")}async setStatusManualUnsubscribed(t){await this.store.set("params.isManualUnsubscribed",t)}getStatusManualUnsubscribed(){return this.store.get("params.isManualUnsubscribed",!1)}async setStatusCommunicationDisabled(t){await this.store.set("params.isCommunicationDisabled",t)}getStatusCommunicationDisabled(){return this.store.get("params.isCommunicationDisabled",!1)}async setStatusDropAllData(t){await this.store.set("params.isDropAllData",t)}getStatusDropAllData(){return this.store.get("params.isDropAllData",!1)}async setSdkVersion(t){await this.store.set("params.sdkVersion",t)}async getSdkVersion(){return await this.store.get("params.sdkVersion")}async setServiceWorkerVersion(t){await this.store.set("params.serviceWorkerVersion",t)}getServiceWorkerVersion(){return this.store.get("params.serviceWorkerVersion")}async setServiceWorkerUrl(t){t&&await this.store.set("params.serviceWorkerUrl",t)}async getServiceWorkerUrl(){return await this.store.get("params.serviceWorkerUrl","/pushwoosh-service-worker.js")}async setServiceWorkerScope(t){t&&await this.store.set("params.serviceWorkerScope",t)}async getServiceWorkerScope(){return await this.store.get("params.serviceWorkerScope")}async setLastOpenMessage(t){await this.store.set("params.lastOpenMessage",t)}getLastOpenMessage(){return this.store.get("params.lastOpenMessage")}async setLastOpenApplicationTime(t){await this.store.set("params.lastOpenApplicationTime",t)}async getLastOpenApplicationTime(){return await this.store.get("params.lastOpenApplicationTime")}async setFeatures(t){await this.store.set("params.features",t)}async getFeatures(){return await this.store.get("params.features")}async setInitParams(t){await this.store.set("params.init",t)}async getInitParams(){return await this.store.get("params.init")}async setInboxLastRequestCode(t){await this.store.set("params.inbox.lastRequestCode",t)}async getInboxLastRequestCode(){return await this.store.get("params.inbox.lastRequestCode","")}async setInboxLastRequestTime(t){await this.store.set("params.inbox.lastRequestTime",t)}async getInboxLastRequestTime(){return this.store.get("params.inbox.lastRequestTime",0)}async setInboxNewMessagesCount(t){await this.store.set("params.inbox.newMessagesCount",t)}async getInboxNewMessagesCount(){return this.store.get("params.inbox.newMessagesCount",0)}async setDelayedEvent(t){await this.store.set("params.delayedEvent",t)}getDelayedEvent(){return this.store.get("params.delayedEvent")}async setPromptDisplayCount(t){await this.store.set("params.promptDisplayCount",t)}async getPromptDisplayCount(){return this.store.get("params.promptDisplayCount",0)}async setPromptLastSeenTime(t){await this.store.set("params.promptLastSeenTime",t)}async getPromptLastSeenTime(){return this.store.get("params.promptLastSeenTime",0)}}class K{constructor(t,e=new F,s=new C){if("data"in t){const e=t;this.payload=e.data}else this.payload=t;this.data=e,this.code=`notificationCode-${Date.now()}-${Math.random().toString(16).slice(2,10)}`,this.dateModule=s}async getIcon(){return this.payload.i||await this.data.getDefaultNotificationImage()}async getTitle(){return this.payload.header||await this.data.getDefaultNotificationTitle()}get silent(){return Boolean(this.payload.silent)}get body(){return this.payload.body}get messageHash(){return this.payload.p||""}get metaData(){return this.payload.md?a(this.payload.md):{}}get image(){return this.payload.image||""}get buttons(){return this.payload.buttons?a(this.payload.buttons):[]}get customData(){return this.payload.u?a(this.payload.u):{}}get campaignCode(){return this.payload.pwcid||""}get link(){return this.payload.l?(t=this.payload.l)&&$.test(t)?t.replace(j,(t=>H[t])):t:"/";var t}get inboxId(){return this.payload.pw_inbox||""}get inboxParams(){return this.payload.inbox_params?a(this.payload.inbox_params):{}}get inboxRemovalTime(){return this.inboxParams&&this.inboxParams.rt?this.inboxParams.rt:(this.dateModule.date=new Date,this.dateModule.addDays(1),this.dateModule.getUtcTimestamp().toString())}async getInboxImage(){return this.inboxParams&&this.inboxParams.image?this.inboxParams.image:""}get rootParams(){const{body:t,p:e,header:s,i:a,u:i,l:r,pwcid:n,image:o,buttons:c,pw_inbox:u,inbox_params:h,...d}=this.payload;return d}async getNotificationOptionsPayload(){const t=await this.getTitle(),e=await this.getIcon();return{...this.rootParams,body:this.body,title:t,icon:e,image:this.image,buttons:this.buttons,customData:this.customData,metaData:this.metaData,campaignCode:this.campaignCode,openUrl:this.link,messageHash:this.messageHash}}async getShowNotificationOptions(){const t=await this.getIcon(),e=this.buttons.map(((t,e)=>(t.action=`action-${e}`,t)));return{renotify:!0,...this.rootParams,body:this.body,icon:t,tag:JSON.stringify({url:this.link,messageHash:this.messageHash,customData:this.customData,metaData:this.metaData}),data:{code:this.code,buttons:e,image:this.image,campaignCode:this.campaignCode,inboxId:this.inboxId},silent:this.silent,actions:e,image:this.image,buttons:e}}async getInboxMessage(){this.dateModule.date=new Date;const t=this.dateModule.getTimestamp().toString();return{title:this.payload.header||"",image:await this.getInboxImage(),status:1,order:this.dateModule.getInboxFakeOrder(),inbox_id:this.inboxId,send_date:t,rt:this.inboxRemovalTime,text:this.body,action_type:1,action_params:JSON.stringify({l:this.link})}}}class z{constructor(t=new F,e=U){this.data=t,this.logger=e}checkDevice(t){return this.createRequest("checkDevice",t)}getConfig(t){return this.createRequest("getConfig",t,"",!0)}applicationOpen(t){return this.createRequest("applicationOpen",t)}registerDevice(t){return this.createRequest("registerDevice",t)}unregisterDevice(t){return this.createRequest("unregisterDevice",t)}deleteDevice(t){return this.createRequest("deleteDevice",t)}messageDeliveryEvent(t){return this.createRequest("messageDeliveryEvent",t)}pushStat(t){return this.createRequest("pushStat",t)}setTags(t){return this.createRequest("setTags",t)}getTags(t){return this.createRequest("getTags",t)}registerUser(t){return this.createRequest("registerUser",t)}registerEmail(t){return this.createRequest("registerEmail",t)}registerEmailUser(t){return this.createRequest("registerEmailUser",t)}setEmailTags(t){return this.createRequest("setEmailTags",t)}postEvent(t){return this.createRequest("postEvent",t)}getInboxMessages(t){return this.createRequest("getInboxMessages",t)}inboxStatus(t){return this.createRequest("inboxStatus",t)}pageVisit(t,e){return this.createRequest("pageVisit",t,e)}setPurchase(t){return this.createRequest("setPurchase",t)}async createRequest(t,e,s,a){const i=await this.data.getApiEntrypoint(),r=a?"":await this.data.getApiToken(),n=s||i+t,o=r?{headers:{Authorization:`Token ${r}`,"Content-Type":"text/plain;charset=UTF-8",Origin:globalThis.location.origin},credentials:"include"}:{},c=await fetch(n,{method:"POST",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:JSON.stringify({request:e}),...o}),u=await this.checkResponse(c);return u.base_url&&await this.data.setApiEntrypoint(u.base_url),await this.logger.write("apirequest",`${t} call with arguments: ${JSON.stringify(e)} to Pushwoosh has been successful. Result: ${JSON.stringify(u.response)}`),u.response}async checkResponse(t){if(200!==t.status)throw new Error(`Error code: ${t.status}. Error text: ${t.statusText}`);const e=await t.json();if(200!==e.status_code)throw new Error(`Error code: ${e.status_code}. Error text: ${e.status_message}`);return e}}class J{constructor(t,e,s){this.api=t,this.data=e,this.config=s}getPermission(){return Notification.permission}checkIsPermissionGranted(){return"granted"===this.getPermission()}checkIsPermissionDefault(){return"default"===this.getPermission()}async checkIsManualUnsubscribed(){return this.data.getStatusManualUnsubscribed()}async askPermission(){await Notification.requestPermission()}async getTokens(){return this.data.getTokens()}async subscribe(t){const e=t||await this.trySubscribe();if(!this.checkIsPermissionGranted())return void U.error("You must have permission granted before subscribe!");const s=this.getPushToken(e),a=e.getKey("p256dh"),i=e.getKey("auth");if(!a||!i)throw new Error("Can't get subscription keys!");const r=btoa(String.fromCharCode.apply(String,new Uint8Array(a))),n=btoa(String.fromCharCode.apply(String,new Uint8Array(i)));await this.data.setTokens({publicKey:r,pushToken:s,authToken:n,endpoint:e.endpoint}),await this.api.registerDevice()}async unsubscribe(){const t=await this.getServiceWorkerRegistration(),e=await t.pushManager.getSubscription();await this.data.setTokens({}),await this.data.setStatusManualUnsubscribed(!0),await this.api.unregisterDevice(),e&&await e.unsubscribe()}async checkIsRegister(){return this.api.checkDeviceSubscribeForPushNotifications()}async checkIsNeedResubscribe(){const t=await this.data.getLastPermissionStatus(),e=this.getPermission();if(t!==e)return await this.data.setLastPermissionStatus(e),!0;const s=await this.getCredentials(),a=this.getPushToken(s),i=await this.data.getTokens(),r=a===(i&&i.pushToken||""),n=await this.data.getIsVapidChanged();return!r||n}async getServiceWorkerRegistration(){if(!this.registration){await this.registerServiceWorker();const t=await this.data.getServiceWorkerUrl();this.registration=await navigator.serviceWorker.getRegistration(t),await this.registration.update()}if(!this.registration)throw new Error("Internal Error: Can't register service worker!");return this.registration}async registerServiceWorker(){const t=await this.data.getServiceWorkerUrl(),e=await this.data.getServiceWorkerScope();let s="";await this.data.getSdkVersion()!==await this.data.getServiceWorkerVersion()&&(s=`?cache_clean=${i()}`),await navigator.serviceWorker.register(`${t}${s}`,{scope:e})}async trySubscribe(){try{return await this.subscribePushManager()}catch(t){return console.error(t),await this.unsubscribe(),this.subscribePushManager()}}async subscribePushManager(){const t=await this.getServiceWorkerRegistration(),e=await this.getApplicationServerKey();return t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:e?this.urlBase64ToUint8Array(e):null})}async getCredentials(){const t=await this.getServiceWorkerRegistration();return await t.pushManager.getSubscription()}getPushToken(t){return t?t.endpoint:""}async getApplicationServerKey(){if(11===await this.data.getDeviceType())return await this.data.getApplicationServerKey()}urlBase64ToUint8Array(t){const e=(t+"=".repeat((4-t.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),s=atob(e),a=new Uint8Array(s.length);for(let t=0;t<s.length;++t)a[t]=s.charCodeAt(t);return a}}class G{constructor(t,e,s){this._canceled=!1,this.showNotificationOptions=t,this.body=e,this.title=s}async show(){if(this._canceled)return;const t=this.showNotificationOptions;t.silent||await self.registration.showNotification(this.title,t)}cancel(){this._canceled=!0}}const Y=new class{constructor(){this.addEventHandler=(t,e)=>{let s=this.handlers[t];s||(s=[]),s.push(e),this.handlers[t]=s},this.removeEventHandler=(t,e)=>{const s=this.handlers[t];s&&(this.handlers[t]=s.filter((t=>t!==e)))},this.dispatchEvent=(t,e)=>{const s=e.eventId||i(),a=this.handlers[t];return a?(a.forEach((t=>{r(t)&&setTimeout((()=>{t({...e,eventId:s})}),0)})),s):s},this.handlers={}}},Q=new F,X=new class{constructor(t,e=new F,s=new z){this.eventBus=t,this.data=e,this.apiClient=s}async checkDevice(){const t=await this.getRequestParams();return await this.apiClient.checkDevice(t)}async checkDeviceSubscribeForPushNotifications(a=!0){let i=localStorage.getItem(t);if(void 0===i||!a){const{exist:a,push_token_exist:r}=await this.checkDevice();localStorage.setItem(t,a&&r?e:s),i=localStorage.getItem(t)}return i===e}async getConfig(t){const e=await this.getRequestParams();return this.apiClient.getConfig({...e,features:t})}async applicationOpen(){const t=await this.getRequestParams();return await this.data.setLastOpenApplicationTime(Date.now()),this.apiClient.applicationOpen(t)}async registerDevice(){if(await this.data.getStatusCommunicationDisabled())throw new Error("Can't register device: Communication is disabled!");const s=await this.getRequestParams(),a=await this.data.getTokens();if(!a.pushToken)throw new Error("Can't register device: pushToken is not exist!");const i=await this.apiClient.registerDevice({...s,push_token:a.pushToken,auth_token:a.authToken,public_key:a.publicKey});return await this.data.setStatusManualUnsubscribed(!1),localStorage.setItem(t,e),this.eventBus.dispatchEvent("register",{}),i}async unregisterDevice(){const e=await this.getRequestParams(),a=this.apiClient.unregisterDevice(e);return localStorage.setItem(t,s),this.eventBus.dispatchEvent("unsubscribe",{}),a}async deleteDevice(){const e=await this.getRequestParams(),a=this.apiClient.deleteDevice(e);return await this.data.setStatusManualUnsubscribed(!0),localStorage.setItem(t,s),this.eventBus.dispatchEvent("unsubscribe",{}),a}async messageDeliveryEvent(t,e,s={}){const a=await this.getRequestParams();return await this.apiClient.messageDeliveryEvent({...a,hash:t,metaData:s})}async pushStat(t,e,s={}){const a=await this.getRequestParams();return await this.apiClient.pushStat({...a,hash:t,metaData:s})}async setTags(t){const{hwid:e,device_type:s,...a}=await this.getRequestParams(),i=await this.data.getEmail();return i&&await this.apiClient.setEmailTags({...a,email:i,tags:t}),this.apiClient.setTags({...a,hwid:e,device_type:s,tags:t})}async getTags(){const t=await this.getRequestParams();return this.apiClient.getTags(t)}async registerUser(t){const{hwid:e,device_type:s,...a}=await this.getRequestParams(),i=await this.data.getDeviceType(),r=`${t}`,n=await this.data.getEmail(),o=await this.apiClient.registerUser({...a,hwid:e,userId:r,ts_offset:60*-(new Date).getTimezoneOffset(),device_type:i});return n&&await this.apiClient.registerEmailUser({...a,email:n,userId:r,ts_offset:60*-(new Date).getTimezoneOffset()}),await this.data.setUserId(`${t}`),await this.data.setStatusUserIdWasChanged(!0),o}async registerEmail(t){const{hwid:e,device_type:s,...a}=await this.getRequestParams(),i=await this.apiClient.registerEmail({...a,email:t,ts_offset:60*-(new Date).getTimezoneOffset()});return await this.data.setEmail(`${t}`),await this.data.setStatusEmailWasChanged(!0),i}async postEvent(t,e){const s=await this.getRequestParams(),a=new Date,i=a.getTime(),r=Math.floor(i/1e3),n=r-a.getTimezoneOffset()/60*3600,o=await this.data.getLastOpenMessage();if(o&&o.expiry>Date.now()){if(e.msgHash)return Promise.reject("attribute msgHash already defined");e={...e,msgHash:o.messageHash}}await this.data.setLastOpenMessage(void 0);const c=await this.apiClient.postEvent({...s,event:t,timestampUTC:r,timestampCurrent:n,attributes:e});return c&&c.code&&this.eventBus.dispatchEvent("receive-in-app-code",{code:c.code}),c}async getInboxMessages(t=0){const e=await this.getRequestParams(),s=await this.data.getInboxLastRequestCode(),a=await this.data.getInboxLastRequestTime();return this.apiClient.getInboxMessages({...e,count:t,last_code:s,last_request_time:a})}async inboxStatus(t,e){const s=await this.getRequestParams();return this.apiClient.inboxStatus({...s,inbox_code:t,status:e,time:(new Date).getTime()})}async triggerEvent(){throw new Error("Method has been deprecated, because we don't aggregate this statistics.")}async pageVisit(t){const e=await this.getRequestParams(),s=await this.data.getFeatures(),a=s&&s.page_visit&&s.page_visit.entrypoint;if(a)return this.apiClient.pageVisit({...e,...t},a)}async setPurchase(t){const e=await this.getRequestParams();return this.apiClient.setPurchase({...e,...t})}async getParams(){return{applicationCode:await this.data.getApplicationCode(),hwid:await this.data.getHwid(),...await this.data.getTokens(),...await this.data.getInitParams()}}get params(){throw new Error('Property "Pushwoosh.api.params" have been deprecated. Use the async method "Pushwoosh.api.getParams()"')}async getRequestParams(){const t=await this.data.getApplicationCode(),e=await this.data.getHwid(),s=await this.data.getUserId(),a=await this.data.getDeviceType(),i=await this.data.getDeviceModel(),r=await this.data.getLanguage(),n=await this.data.getSdkVersion();return{application:t,hwid:e,userId:s||e,device_type:a,device_model:i,timezone:60*-(new Date).getTimezoneOffset(),language:r,v:n}}}(Y,Q),Z=self.Pushwoosh=new class{constructor(t,e,s){this._listeners={},this.eventBus=t,this.data=e,this.api=s}push(t){Array.isArray(t)&&"onPush"===t[0]&&r(t[1])&&(this._listeners[t[0]]||(this._listeners[t[0]]=[]),this._listeners[t[0]].push(t[1]))}getListeners(t){return this._listeners[t]||[]}async initApi(){return Promise.resolve()}}(Y,Q,X),tt=[];async function et(t){(await self.clients.matchAll()).forEach((e=>e.postMessage(t)))}async function st(t){const{notification:e={}}=t,{data:s}=e,i=a(e.tag,{});let r="";if(t.action&&Array.isArray(s.buttons)){r=(s.buttons.find((e=>e.action===t.action))||{}).url}else r=i.url;return{title:e.title,body:e.body,icon:e.icon,buttons:s.buttons,image:s.image,code:s.code,campaignCode:s.campaignCode,inboxId:s.inboxId,messageHash:i.messageHash,customData:i.customData,metaData:i.metaData,openUrl:i.url,tag:e.tag,url:r}}async function at(t){const e=await Z.data.getApplicationCode(),s=await Z.data.getServiceWorkerVersion();await m({message:"Error in onInstallEventHandler",code:"FATAL-SW-001",error:t,applicationCode:e,workerVersion:s})}async function it(t){const e=await Z.data.getApplicationCode(),s=await Z.data.getServiceWorkerVersion();await m({message:"Error in onActivateEventHandler",code:"FATAL-SW-002",error:t,applicationCode:e,workerVersion:s})}async function rt(t){const e=await Z.data.getApplicationCode(),s=await Z.data.getServiceWorkerVersion();await m({message:"Error in onNotificationClickEventHandler",code:"FATAL-SW-004",error:t,applicationCode:e,workerVersion:s})}async function nt(t){const e=await Z.data.getApplicationCode(),s=await Z.data.getServiceWorkerVersion();await m({message:"Error in onNotificationCloseEventHandler",code:"FATAL-SW-005",error:t,applicationCode:e,workerVersion:s})}async function ot(t){const e=await Z.data.getApplicationCode(),s=await Z.data.getServiceWorkerVersion();await m({message:"Error in onPushSubscriptionChange",code:"FATAL-SW-006",error:t,applicationCode:e,workerVersion:s})}return self.addEventListener("install",(function(t){return t.waitUntil(async function(){await Promise.all([Z.data.setServiceWorkerVersion("3.40.1"),U.write("info","install")]),await self.skipWaiting()}().catch(at))})),self.addEventListener("activate",(function(t){t.waitUntil(async function(){await Promise.all([U.write("info","activate")]),await self.clients.claim()}().catch(it))})),self.addEventListener("push",(function(t){t.waitUntil(async function(t){await self.clients.claim();const e=await t.data.json(),s=new K(e),a=await s.getNotificationOptionsPayload(),i=await s.getShowNotificationOptions(),r=s.messageHash;await U.write("info",JSON.stringify(a),"onPush");const n=new G(i,s.body,await s.getTitle()),o=Z.getListeners("onPush");await o.reduce(((t,e)=>t.then((()=>e(n)))),Promise.resolve());const c=[n.show(),_.add({payload:e,parsedPayload:a,showOptions:i}),et({type:"onPushDelivery",payload:a})];if(r&&c.push(Z.initApi().then((()=>Z.api.messageDeliveryEvent(r,!0,a.metaData)))),""!==s.inboxId){const t=new B(Z.eventBus,Z.data,Z.api),e=new N(Z.data,Z.api,t),a=await s.getInboxMessage(),i=await e.publicMessageBuilder(a);c.push(t.putMessage(a),et({type:"onPutNewMessageToInboxStore",payload:i}))}await Promise.all(c)}(t).catch((e=>async function(t,e){const s=await Z.data.getApplicationCode(),a=await Z.data.getServiceWorkerVersion();await m({message:"Error in onPushEventHandler",code:"FATAL-SW-003",error:t,applicationCode:s,workerVersion:a}),t instanceof Error||(t=new Error(t));return _.add({error:`${t}`,stack:t.stack,payload:e.data&&e.data.text()})}(e,t))))})),self.addEventListener("notificationclick",(function(t){t.waitUntil(async function(t){await self.clients.claim();const e=await st(t),{messageHash:s,metaData:a,url:i,code:r,inboxId:n}=e;if(r&&tt.push(r),""!==n){const t=new B(Z.eventBus,Z.data,Z.api),e=await t.getMessage(n);e.status=3,await t.putMessage(e)}t.notification.close();const o={type:"onNotificationClick",payload:e};return i&&t.waitUntil(self.clients.matchAll({type:"window"}).then((t=>async function(t,e){const{hostname:s,pathname:a}=new URL(e,self.location.origin),i=t.find((t=>{const{hostname:e,pathname:i}=new URL(t.url);return e===s&&i===a}));return i?(await i.focus(),!1):(await self.clients.openWindow(e).then((t=>{t&&t.focus()})),!0)}(t,i))).then((t=>{t&&Z.data.setDelayedEvent(o)}))),Promise.all([Z.initApi().then((()=>Z.api.pushStat(s,!0,a))),Z.data.setLastOpenMessage({url:i,messageHash:s,expiry:Date.now()+864e5}),et(o)])}(t).catch(rt))})),self.addEventListener("notificationclose",(function(t){t.waitUntil(async function(t){await self.clients.claim();const e=await st(t),{code:s}=e;if(t.notification.close(),!s)return;const a=tt.indexOf(s);if(!(a>=0))return et({type:"onNotificationClose",payload:e});tt.splice(a,1)}(t).catch(nt))})),self.addEventListener("pushsubscriptionchange",(async function(t){t.waitUntil(async function(t){let e=t.newSubscription;if(!e&&(e=await self.registration.pushManager.getSubscription(),!e))return;const s=new J(X,Q,{});await s.subscribe(e)}(t).catch(ot))})),{}})()));
|
|
2
2
|
//# sourceMappingURL=service-worker.js.map
|