(()=>{"use strict";var e={552:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrowserVersionParser=void 0;class i{static parseBrowserVersion(e){const t=i.getVersionOffset(e.userAgent);if(-1===t)return e.appVersion;const s=e.userAgent.substring(t);return i.trimVersion(s)}static getVersionOffset(e){const t=["SamsungBrowser","OPR","Edge","Edg","Chrome","Safari","Firefox"];for(let s=0;s=0?i+e.length+1:-1}static trimVersion(e){const t=/^(([0-9]|\.)*)[ );]/;return t.test(e)?t.exec(e)[1]:e}}t.BrowserVersionParser=i},838:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DEVICE_REGISTRATION_STATUS_UNREGISTERED=t.DEVICE_REGISTRATION_STATUS_REGISTERED=t.KEY_DEVICE_REGISTRATION_STATUS=t.EVENT_ON_HIDE_NOTIFICATION_PERMISSION_DIALOG=t.EVENT_ON_SHOW_NOTIFICATION_PERMISSION_DIALOG=t.EVENT_ON_UPDATE_INBOX_MESSAGES=t.EVENT_ON_PUT_NEW_MESSAGE_TO_INBOX_STORE=t.EVENT_ON_PUSH_DELIVERY=t.EVENT_ON_SW_INIT_ERROR=t.EVENT_ON_PERMISSION_GRANTED=t.EVENT_ON_PERMISSION_DENIED=t.EVENT_ON_PERMISSION_PROMPT=t.EVENT_ON_UNSUBSCRIBE=t.EVENT_ON_SUBSCRIBE=t.EVENT_ON_READY=t.PERMISSION_PROMPT=t.PERMISSION_GRANTED=t.PERMISSION_DENIED=t.indexedDbVersion=t.indexedDbName=t.meCustomEvent=t.meOpen=t.meLogout=t.meLogin=t.lsKeyLastContactFieldId=t.lsKeyLastLoginToken=t.lsKeyLastLoginTime=t.dbKeyLastUsedAt=t.dbKeyLoggingEnabled=t.dbKeyTimezone=t.dbKeyLanguage=t.dbKeyOsVersion=t.dbKeyDeviceModel=t.dbKeyApplicationVersion=t.dbKeyPlatform=t.dbKeyContactFieldValue=t.dbKeyContactFieldId=t.dbKeyPushToken=t.dbKeyServiceWorkerVersion=t.dbKeySdkVersion=t.dbKeyRefreshToken=t.dbKeyContactToken=t.dbKeyXClientState=t.dbKeyBrowserIds=t.dbKeyBrowserId=t.dbKeyInitParams=t.dbKeyLastPermissionStatus=t.dbKeyPushPackageServiceUrl=t.dbKeyWebsitePushId=t.dbKeyApplicationServerPublicKey=t.dbKeyServiceWorkerScope=t.dbKeyServiceWorkerUrl=t.dbKeyMeDeviceEventServiceApiBaseUrl=t.dbKeyMeClientServiceApiBaseUrl=t.dbKeyApplicationCode=t.dbKeyDefaultNotificationIcon=t.dbKeyDefaultNotificationTitle=t.applicationPassword=t.pushActionsProperty=t.pushImageProperty=t.pushIconProperty=t.pushLinkProperty=t.pushTitleProperty=t.loginOverloadProtectionTime=t.defaultApplicationVersion=t.defaultSafariPushPackageServiceUrl=t.defaultDeviceEventServiceApiBaseUrl=t.defaultClientServiceApiBaseUrl=void 0,t.defaultClientServiceApiBaseUrl="https://me-client.eservice.emarsys.net/v3",t.defaultDeviceEventServiceApiBaseUrl="https://mobile-events.eservice.emarsys.net/v3",t.defaultSafariPushPackageServiceUrl="https://me-client.eservice.emarsys.net",t.defaultApplicationVersion="0.0.0",t.loginOverloadProtectionTime=36e5,t.pushTitleProperty="title",t.pushLinkProperty="link",t.pushIconProperty="icon",t.pushImageProperty="image",t.pushActionsProperty="actions",t.applicationPassword="not-used",t.dbKeyDefaultNotificationTitle="pushDefaultNotificationTitle",t.dbKeyDefaultNotificationIcon="pushDefaultNotificationIcon",t.dbKeyApplicationCode="emarsysApplicationCode",t.dbKeyMeClientServiceApiBaseUrl="meClientServiceApiBaseUrl",t.dbKeyMeDeviceEventServiceApiBaseUrl="meDeviceEventServiceApiBaseUrl",t.dbKeyServiceWorkerUrl="serviceWorkerUrl",t.dbKeyServiceWorkerScope="serviceWorkerScope",t.dbKeyApplicationServerPublicKey="applicationServerPublicKey",t.dbKeyWebsitePushId="websitePushId",t.dbKeyPushPackageServiceUrl="pushPackageServiceUrl",t.dbKeyLastPermissionStatus="lastPermissionStatus",t.dbKeyInitParams="initParams",t.dbKeyBrowserId="browserId",t.dbKeyBrowserIds="browserIds",t.dbKeyXClientState="xClientState",t.dbKeyContactToken="contactToken",t.dbKeyRefreshToken="refreshToken",t.dbKeySdkVersion="sdkVersion",t.dbKeyServiceWorkerVersion="serviceWorkerVersion",t.dbKeyPushToken="pushToken",t.dbKeyContactFieldId="contactFieldId",t.dbKeyContactFieldValue="contactFieldValue",t.dbKeyPlatform="platform",t.dbKeyApplicationVersion="applicationVersion",t.dbKeyDeviceModel="deviceModel",t.dbKeyOsVersion="osVersion",t.dbKeyLanguage="language",t.dbKeyTimezone="timezone",t.dbKeyLoggingEnabled="loggingEnabled",t.dbKeyLastUsedAt="lastUsedAt",t.lsKeyLastLoginTime="emarsysWebpushLastLoginTime",t.lsKeyLastLoginToken="emarsysWebpushLastLoginToken",t.lsKeyLastContactFieldId="emarsysWebpushLastContactFieldId",t.meLogin="/users/login",t.meLogout="/users/logout",t.meOpen="/events/message_open",t.meCustomEvent="/events/",t.indexedDbName="EMARSYS_WEBPUSH_STORE",t.indexedDbVersion=1,t.PERMISSION_DENIED="denied",t.PERMISSION_GRANTED="granted",t.PERMISSION_PROMPT="default",t.EVENT_ON_READY="onReady",t.EVENT_ON_SUBSCRIBE="onSubscribe",t.EVENT_ON_UNSUBSCRIBE="onUnsubscribe",t.EVENT_ON_PERMISSION_PROMPT="onPermissionPrompt",t.EVENT_ON_PERMISSION_DENIED="onPermissionDenied",t.EVENT_ON_PERMISSION_GRANTED="onPermissionGranted",t.EVENT_ON_SW_INIT_ERROR="onSWInitError",t.EVENT_ON_PUSH_DELIVERY="onPushDelivery",t.EVENT_ON_PUT_NEW_MESSAGE_TO_INBOX_STORE="onPutNewMessageToInboxStore",t.EVENT_ON_UPDATE_INBOX_MESSAGES="onUpdateInboxMessages",t.EVENT_ON_SHOW_NOTIFICATION_PERMISSION_DIALOG="onShowNotificationPermissionDialog",t.EVENT_ON_HIDE_NOTIFICATION_PERMISSION_DIALOG="onHideNotificationPermissionDialog",t.KEY_DEVICE_REGISTRATION_STATUS="registrationStatus",t.DEVICE_REGISTRATION_STATUS_REGISTERED="registered",t.DEVICE_REGISTRATION_STATUS_UNREGISTERED="unregistered"},148:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this._events={}}emit(e,t){const i=this._events[e]&&this._events[e].slice();if(i&&i.length)for(let e=0;e{if(!i)return i=!0,this.removeListener(e,s),t(n)};return this.on(e,s)}removeListener(e,t){const i=this._events[e];if(i){const s=i.indexOf(t);s>-1&&i.splice(s,1),i.length<1&&delete this._events[e]}}totalListenerCount(){let e=0;return Object.keys(this._events).forEach((t=>{e+=this._events[t].length})),e}listenerCountFor(e){const t=this._events[e];return t?t.length:0}}},818:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IndexDb=void 0;const s=i(838),n="not_found";class r{constructor(){this.name="keyValue"}async setDBValue(e,t){return this.openIndexDB().then((i=>new Promise(((s,n)=>{const r=i.transaction([this.name],"readwrite").objectStore(this.name).put({key:e,value:t});r.onsuccess=()=>(this.indexedDBInstance=void 0,i.close(),s(e)),r.onerror=e=>(this.indexedDBInstance=void 0,i.close(),n(e))}))))}async deleteDBKey(e){return this.openIndexDB().then((t=>new Promise(((i,s)=>{const n=t.transaction([this.name],"readwrite").objectStore(this.name).delete(e);n.onsuccess=()=>(this.indexedDBInstance=void 0,t.close(),i(!0)),n.onerror=e=>(this.indexedDBInstance=void 0,t.close(),s(e))}))))}async getDBValue(e){const t=await this.openIndexDB();return new Promise(((i,s)=>{const r=t.transaction(this.name).objectStore(this.name).get(e);r.onsuccess=()=>{const{result:e}=r;return e?(this.indexedDBInstance=void 0,t.close(),i(e.value)):(this.indexedDBInstance=void 0,t.close(),s(new Error(n)))},r.onerror=e=>(this.indexedDBInstance=void 0,t.close(),s(e))}))}async getDBValueOrDefault(e,t=void 0){try{return await this.getDBValue(e)}catch(e){if(e.message===n)return t;throw e}}async openIndexDB(){return new Promise(((e,t)=>{if(this.indexedDBInstance)return e(this.indexedDBInstance);const i=indexedDB.open(s.indexedDbName,s.indexedDbVersion);i.onsuccess=t=>(this.indexedDBInstance=t.target.result,e(this.indexedDBInstance)),i.onerror=e=>t(e),i.onupgradeneeded=e=>{e.target.result.createObjectStore("keyValue",{keyPath:"key"})}}))}static create(){return new r}}t.IndexDb=r},198:function(e,t,i){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.decode=void 0;const n=i(50),r=s(i(142));t.decode=function(e,t){const i=!0===(null!=t?t:{}).header?0:1;try{return JSON.parse(n.urlB64ToString(e.split(".")[i]))}catch(e){return r.default.Logger.error("Error decoding token",e),null}}},304:function(e,t,i){var s=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[i]}})}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.hasOwnProperty.call(e,i)&&s(t,e,i);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.removeRegistrationStatus=t.setRegistrationStatus=t.getRegistrationStatus=void 0;const a=r(i(838));t.getRegistrationStatus=function(){const e=localStorage.getItem(a.KEY_DEVICE_REGISTRATION_STATUS);return e||void 0},t.setRegistrationStatus=function(e){localStorage.setItem(a.KEY_DEVICE_REGISTRATION_STATUS,e)},t.removeRegistrationStatus=function(){localStorage.removeItem(a.KEY_DEVICE_REGISTRATION_STATUS)}},142:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});const i="[WebEmarsysSDK]",s=()=>{},n=(e,t)=>(...i)=>{console[t](e,...i)};const r={trace:s,debug:s,info:s,warn:s,error:s,log:s},a={NoopLogFn:s,enableLogger:function(e,t=i){const a=["trace","debug","info","warn","error","log"];if(e)for(const e of a)r[e]=n(t,e);else for(const e of a)r[e]=s},SdkContext:i,SwContext:"[WebEmarsysSW]",Logger:r};t.default=a},47:function(e,t,i){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.MEClientService=void 0;const n=s(i(142)),r=i(252),{Logger:a}=n.default;class o{constructor(e,t,i){this.storage=i,this.storageWithLog=new r.StorageWithLog(i),this.baseUrl=`${e}/domains`,this.meClientServiceRequest=t}async storeClientDetails(){const e=await this.storageWithLog.getClientId();if(!e)return!1;const t=await this.apiEndpoint("client"),i=await this.storage.getClientState(),s=await this.getClientDetails(),n=await this.meClientServiceRequest.post(t,s,{clientId:e,clientState:i});if(204===n.status)return await this.saveClientState(n),!0;{const e=await n.json();return a.error("Error storing client info",n.status,JSON.stringify(e)),!1}}async linkClientToContact(e){const t=await this.storageWithLog.getClientId(),i=await this.storageWithLog.getClientState({level:"info"});if(!t||!i)return!1;const{anonymous:s,body:n}=this.toContactRequestBodyData(e),r=`${await this.apiEndpoint("client/contact")}${s?"?anonymous=true":""}`,o=await this.meClientServiceRequest.post(r,n,{clientId:t,clientState:i});if(200===o.status){await this.saveClientState(o);const e=await o.json();return e.contactToken&&e.refreshToken?(await Promise.all([this.storage.setContactToken(e.contactToken),this.storage.setRefreshToken(e.refreshToken)]),!0):(a.error("At least one of the expected response parts missing!"),!1)}{const e=await o.json();return a.error("Error linking contact to client",o.status,JSON.stringify(e)),!1}}async generateAccessToken(){const e=await this.storageWithLog.getClientId(),t=await this.storageWithLog.getRefreshToken(),i=await this.storageWithLog.getClientState();if(!e||!t||!i)return!1;const s=await this.apiEndpoint("client/contact-token"),n={refreshToken:t},r=await this.meClientServiceRequest.post(s,n,{clientId:e,clientState:i});if(200===r.status){const e=await r.json();return e.contactToken?(await this.storage.setContactToken(e.contactToken),!0):(a.error("ContactToken is not part of response body!"),!1)}{const e=await r.json();return a.log("Error refreshing the contact token",r.status,JSON.stringify(e)),!1}}async registerPushToken(e){const t=await this.storageWithLog.getClientId(),i=await this.storageWithLog.getClientState(),s=await this.storageWithLog.getContactToken({message:"Unable to register subscription as contactToken is missing!"});if(!t||!i||!s)return!1;const n=await this.apiEndpoint("client/push-token"),r={pushToken:e},o=await this.meClientServiceRequest.put(n,r,{clientId:t,clientState:i,contactToken:s});if(204===o.status)return await this.saveClientState(o),!0;{const e=await o.json();return a.error("Error registering the subscription",o.status,JSON.stringify(e)),!1}}async removePushToken(){a.info("Remove push token");const e=await this.storageWithLog.getClientId(),t=await this.storageWithLog.getClientState({level:"info"}),i=await this.storageWithLog.getContactToken({level:"info"});if(!e||!t||!i)return!1;const s=await this.apiEndpoint("client/push-token"),n=await this.meClientServiceRequest.delete(s,{},{clientId:e,clientState:t,contactToken:i});if(204===n.status)return await this.saveClientState(n),!0;{const e=await n.json();return a.error("Error removing a subscription",n.status,JSON.stringify(e)),!0}}async apiEndpoint(e){const t=await this.storage.getAppCode();return`${this.baseUrl}/${t}/${e}`}async saveClientState(e){const t=e.headers.get("x-client-state");t?await this.storage.setClientState(t):a.error("Error: X-Client-State not found in response header!")}async getClientDetails(){const e=await this.storage.getPlatform();if(e){return{platform:e,applicationVersion:await this.storage.getApplicationVersion(),deviceModel:await this.storage.getDeviceModel(),osVersion:await this.storage.getOsVersion(),sdkVersion:await this.storage.getSdkVersion(),language:await this.storage.getLanguage(),timezone:await this.storage.getTimezone()}}throw new Error("platform not found in storage!")}toContactRequestBodyData(e){return e?"openIdToken"in e?{body:{contactFieldId:e.fieldId,openIdToken:e.openIdToken},anonymous:!1}:{body:{contactFieldId:e.fieldId,contactFieldValue:e.fieldValue,contactFieldEncrypted:e.encrypted},anonymous:!1}:{body:{},anonymous:!0}}static create(e,t,i){return new o(e,t,i)}}t.MEClientService=o},847:function(e,t,i){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.MEDeviceEventService=void 0;const n=s(i(142)),r=i(252),{Logger:a}=n.default,o=[200,204];class c{constructor(e,t,i){this.storage=i,this.storageWithLog=new r.StorageWithLog(i),this.baseUrl=`${e}/apps`,this.desRequest=t}async postEvents(e){const t=await this.storageWithLog.getClientId(),i=await this.storageWithLog.getContactToken(),s=await this.storageWithLog.getClientState();if(!t||!i||!s)return{success:!1};const n=await this.apiEndpoint("client/events"),r=await this.desRequest.post(n,e,{clientId:t,clientState:s,contactToken:i});if(o.includes(r.status))return{success:!0,statusCode:r.status};{const e=await r.json();return a.warn("Error posting events to device event service",r.status,JSON.stringify(e)),{success:!1,statusCode:r.status}}}async apiEndpoint(e){const t=await this.storage.getAppCode();return`${this.baseUrl}/${t}/${e}`}static create(e,t,i){return new c(e,t,i)}}t.MEDeviceEventService=c},244:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MEV3ApiRequest=void 0;const i={"Content-Type":"application/json"};class s{constructor(){this.requestOrder=0}async post(e,t,i){const s=this.createPostRequestInit(t,i);return fetch(e,s)}async put(e,t,i){const s=this.createPutRequestInit(t,i);return fetch(e,s)}async delete(e,t,i){const s=this.createDeleteRequestInit(t,i);return fetch(e,s)}createPostRequestInit(e,t){return this.createRequestInit("POST",e,t)}createPutRequestInit(e,t){return this.createRequestInit("PUT",e,t)}createDeleteRequestInit(e,t){return this.createRequestInit("DELETE",e,t)}createRequestInit(e,t,i){return{method:e,headers:this.buildHeaders(i),mode:"cors",cache:"default",body:JSON.stringify(t)}}buildHeaders(e){const t=new Headers;return Object.keys(i).forEach((e=>{t.append(e,i[e])})),t.append("x-client-id",e.clientId),e.clientState&&t.append("x-client-state",e.clientState),e.contactToken&&t.append("x-contact-token",e.contactToken),t.append("x-request-order",`${this.requestOrder}`),this.requestOrder+=1,t}static create(){return new s}}t.MEV3ApiRequest=s},18:function(e,t,i){var s=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[i]}})}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.hasOwnProperty.call(e,i)&&s(t,e,i);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.MEWebPushDb=void 0;const a=r(i(838));class o{constructor(e){this.indexDb=e}async getDefaultNotificationTitle(e){return this.indexDb.getDBValueOrDefault(a.dbKeyDefaultNotificationTitle,e)}async getDefaultNotificationIcon(e){return this.indexDb.getDBValueOrDefault(a.dbKeyDefaultNotificationIcon,e)}async getClientIdForAppCode(e){if(void 0!==e){return(await this.getBrowserIdsFromDb())[e.toUpperCase()]}}async getClientIds(){return this.getBrowserIdsFromDb()}async getBrowserIdsFromDb(){const e=await this.indexDb.getDBValueOrDefault(a.dbKeyBrowserIds);let t={};if(void 0!==e)try{t=JSON.parse(e)}catch(e){}return t=await this.addLegacyBrowserId(t),t}async addLegacyBrowserId(e){const t=await this.indexDb.getDBValueOrDefault(a.dbKeyBrowserId);if(void 0!==t){e[t.split("_")[0].toUpperCase()]=t,await this.indexDb.setDBValue(a.dbKeyBrowserIds,JSON.stringify(e)),await this.indexDb.setDBValue(a.dbKeyBrowserId,void 0)}return e}async getInitParams(){const e=await this.indexDb.getDBValueOrDefault(a.dbKeyInitParams);return e?JSON.parse(e):void 0}async getMeClientServiceApiBaseUrl(){return this.indexDb.getDBValue(a.dbKeyMeClientServiceApiBaseUrl)}async getMeDeviceEventServiceApiBaseUrl(){return this.indexDb.getDBValue(a.dbKeyMeDeviceEventServiceApiBaseUrl)}async getClientId(){const e=await this.getAppCode();return this.getClientIdForAppCode(e)}async getClientState(){return this.indexDb.getDBValueOrDefault(a.dbKeyXClientState)}async getRefreshToken(){return this.indexDb.getDBValueOrDefault(a.dbKeyRefreshToken)}async getContactToken(){return this.indexDb.getDBValueOrDefault(a.dbKeyContactToken)}async getAppCode(){return this.appCode||(this.appCode=await this.indexDb.getDBValueOrDefault(a.dbKeyApplicationCode)),this.appCode}async getWebsitePushId(){return this.indexDb.getDBValueOrDefault(a.dbKeyWebsitePushId)}async getLastPermissionStatus(){return this.indexDb.getDBValueOrDefault(a.dbKeyLastPermissionStatus).then((e=>e))}async getApplicationServerPublicKey(){return this.indexDb.getDBValueOrDefault(a.dbKeyApplicationServerPublicKey)}async getServiceWorkerUrl(){return this.indexDb.getDBValueOrDefault(a.dbKeyServiceWorkerUrl)}async getServiceWorkerScope(){return this.indexDb.getDBValueOrDefault(a.dbKeyServiceWorkerScope)}async getSdkVersion(){return this.indexDb.getDBValueOrDefault(a.dbKeySdkVersion)}async getServiceWorkerVersion(){return this.indexDb.getDBValueOrDefault(a.dbKeyServiceWorkerVersion)}async getPushToken(){return this.indexDb.getDBValueOrDefault(a.dbKeyPushToken)}async getContactFieldId(){const e=await this.indexDb.getDBValueOrDefault(a.dbKeyContactFieldId);return e?Number(e):void 0}async getContactFieldValue(){return this.indexDb.getDBValueOrDefault(a.dbKeyContactFieldValue)}async getPushPackageServiceUrl(){return this.indexDb.getDBValueOrDefault(a.dbKeyPushPackageServiceUrl)}async getPlatform(){return this.indexDb.getDBValueOrDefault(a.dbKeyPlatform)}async getApplicationVersion(){return this.indexDb.getDBValueOrDefault(a.dbKeyApplicationVersion)}async getDeviceModel(){return this.indexDb.getDBValueOrDefault(a.dbKeyDeviceModel)}async getOsVersion(){return this.indexDb.getDBValueOrDefault(a.dbKeyOsVersion)}async getLanguage(){return this.indexDb.getDBValueOrDefault(a.dbKeyLanguage)}async getTimezone(){return this.indexDb.getDBValueOrDefault(a.dbKeyTimezone)}async getLoggingEnabled(){const e=await this.indexDb.getDBValueOrDefault(a.dbKeyLoggingEnabled);return"true"===(null==e?void 0:e.toLowerCase())}async setTimezone(e){await this.indexDb.setDBValue(a.dbKeyTimezone,e)}async setLanguage(e){await this.indexDb.setDBValue(a.dbKeyLanguage,e)}async setOsVersion(e){await this.indexDb.setDBValue(a.dbKeyOsVersion,e)}async setDeviceModel(e){await this.indexDb.setDBValue(a.dbKeyDeviceModel,e)}async setApplicationVersion(e){await this.indexDb.setDBValue(a.dbKeyApplicationVersion,e)}async setPlatform(e){await this.indexDb.setDBValue(a.dbKeyPlatform,e)}async setPushPackageServiceUrl(e){await this.indexDb.setDBValue(a.dbKeyPushPackageServiceUrl,e)}async setContactFieldValue(e){await this.indexDb.setDBValue(a.dbKeyContactFieldValue,e)}async setContactFieldId(e){await this.indexDb.setDBValue(a.dbKeyContactFieldId,"number"==typeof e?e.toString():void 0)}async setMeClientServiceApiBaseUrl(e){await this.indexDb.setDBValue(a.dbKeyMeClientServiceApiBaseUrl,e)}async setMeDeviceEventServiceApiBaseUrl(e){await this.indexDb.setDBValue(a.dbKeyMeDeviceEventServiceApiBaseUrl,e)}async setPushToken(e){await this.indexDb.setDBValue(a.dbKeyPushToken,e)}async setServiceWorkerVersion(e){await this.indexDb.setDBValue(a.dbKeyServiceWorkerVersion,e)}async setSdkVersion(e){await this.indexDb.setDBValue(a.dbKeySdkVersion,e)}async setLastPermissionStatus(e){await this.indexDb.setDBValue(a.dbKeyLastPermissionStatus,e)}async setAppCode(e){await this.indexDb.setDBValue(a.dbKeyApplicationCode,e),this.appCode=e}async setClientState(e){await this.indexDb.setDBValue(a.dbKeyXClientState,e)}async setContactToken(e){await this.indexDb.setDBValue(a.dbKeyContactToken,e)}async setRefreshToken(e){await this.indexDb.setDBValue(a.dbKeyRefreshToken,e)}async setClientId(e){await this.indexDb.setDBValue(a.dbKeyBrowserId,e)}async setClientIdForAppCode(e,t){const i=await this.getBrowserIdsFromDb();void 0!==e?i[t.toUpperCase()]=e:delete i[t.toUpperCase()],await this.indexDb.setDBValue(a.dbKeyBrowserIds,JSON.stringify(i))}async setClientIds(e){await this.indexDb.setDBValue(a.dbKeyBrowserIds,JSON.stringify(e))}async setDefaultNotificationIcon(e){await this.indexDb.setDBValue(a.dbKeyDefaultNotificationIcon,e)}async setDefaultNotificationTitle(e){await this.indexDb.setDBValue(a.dbKeyDefaultNotificationTitle,e)}async setServiceWorkerUrl(e){await this.indexDb.setDBValue(a.dbKeyServiceWorkerUrl,e)}async setServiceWorkerScope(e){await this.indexDb.setDBValue(a.dbKeyServiceWorkerScope,e)}async setApplicationServerPublicKey(e){await this.indexDb.setDBValue(a.dbKeyApplicationServerPublicKey,e)}async setInitParams(e){await this.indexDb.setDBValue(a.dbKeyInitParams,JSON.stringify(e))}async setWebsitePushId(e){await this.indexDb.setDBValue(a.dbKeyWebsitePushId,e)}async setLoggingEnabled(e){await this.indexDb.setDBValue(a.dbKeyLoggingEnabled,`${e}`)}async setLastUsedAt(){const e=(new Date).toISOString();await this.indexDb.setDBValue(a.dbKeyLastUsedAt,e)}async deleteLastUsedAt(){await this.indexDb.deleteDBKey(a.dbKeyLastUsedAt)}async clearAll(){await Promise.all([this.setAppCode(void 0),this.setClientState(void 0),this.setContactToken(void 0),this.setRefreshToken(void 0),this.setDefaultNotificationIcon(void 0),this.setDefaultNotificationTitle(void 0),this.setServiceWorkerUrl(void 0),this.setServiceWorkerScope(void 0),this.setApplicationServerPublicKey(void 0),this.setSdkVersion(void 0),this.setServiceWorkerVersion(void 0),this.setInitParams(void 0),this.setWebsitePushId(void 0),this.setPushPackageServiceUrl(void 0),this.setLastPermissionStatus(void 0),this.setPushToken(void 0),this.setContactFieldId(void 0),this.setContactFieldValue(void 0),this.setPlatform(void 0),this.setApplicationVersion(void 0),this.setDeviceModel(void 0),this.setTimezone(void 0),this.setLanguage(void 0),this.setOsVersion(void 0),this.setMeClientServiceApiBaseUrl(void 0),this.setMeDeviceEventServiceApiBaseUrl(void 0),this.deleteLastUsedAt()]),this.appCode=void 0}static create(e){return new o(e)}}t.MEWebPushDb=o},843:function(e,t,i){var s=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[i]}})}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.hasOwnProperty.call(e,i)&&s(t,e,i);return n(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(i(838)),c=a(i(142)),u=i(47),l=i(847),d=i(282),h=i(151),g=i(18),f=i(818),b=i(244),p=i(642),v=i(831),S=a(i(148)),y=r(i(304)),D=r(i(198)),P=r(i(50)),E=i(252),{Logger:I,enableLogger:m}=c.default;class _{constructor(e,t){this.ready=!1,this.navigator=t,this.window=e,this.navigatorInfo=h.NavigatorInfo.create(t),this.pushNotificationSupportInfo=d.PushNotificationSupportInfo.create(this.navigatorInfo,e),this.meWebPushDb=g.MEWebPushDb.create(f.IndexDb.create()),this.storageWithLog=new E.StorageWithLog(this.meWebPushDb),this.eventEmitter=new S.default,this.permissionPromises={},this.pushNotificationSupportInfo.canUsePromises()&&(this.permissionPromises={[o.EVENT_ON_PERMISSION_DENIED]:new Promise((e=>this.eventEmitter.once(o.EVENT_ON_PERMISSION_DENIED,e))),[o.EVENT_ON_PERMISSION_PROMPT]:new Promise((e=>this.eventEmitter.once(o.EVENT_ON_PERMISSION_PROMPT,e))),[o.EVENT_ON_PERMISSION_GRANTED]:new Promise((e=>this.eventEmitter.once(o.EVENT_ON_PERMISSION_GRANTED,e)))})}push(e){if("function"!=typeof e){if(!Array.isArray(e))throw new Error("Invalid command!");switch(e[0]){case"init":this.init(e[1]).then((()=>I.debug("Initialized"))).catch((e=>I.error(e,"Init failed!")));break;case o.EVENT_ON_READY:this.registerOrHandleOnReadyCallback(e[1]);break;case o.EVENT_ON_SUBSCRIBE:case o.EVENT_ON_UNSUBSCRIBE:case o.EVENT_ON_SW_INIT_ERROR:this.registerEventCallback(e[0],e[1]);break;case o.EVENT_ON_PERMISSION_DENIED:case o.EVENT_ON_PERMISSION_PROMPT:case o.EVENT_ON_PERMISSION_GRANTED:this.registerChangePermissionCallback(e[0],e[1]);break;default:I.warn(`WARN: Command "${JSON.stringify(e)}" not yet implemented!`)}}else this.registerOrHandleOnReadyCallback(e)}async customEvent(e,t){try{const i={dnd:!0,events:[{type:"custom",name:e,timestamp:(new Date).toISOString(),attributes:{...t,"me:origin":"webpush"}}],clicks:[],viewedMessages:[]};let s=await this.meDeviceEventService.postEvents(i);return s.success||401!==s.statusCode||(I.log("Contact token seems outdated, try to refresh and send again..."),s=await this.retrySendAfterContactTokenRefresh(i)),I.debug("Sent custom event",e,JSON.stringify(t),JSON.stringify(s)),s.success}catch(e){return I.error("Error sending custom event",e.message,e),!1}}async subscribe(){const e=this.getPushService();let t;if(e.isPermissionDefault()){this.eventEmitter.emit(o.EVENT_ON_PERMISSION_PROMPT);const i=setInterval((()=>{e.isPermissionDefault()||(clearInterval(i),t||this.subscribe())}),1e3);t=await e.askPermission().catch((e=>(I.error("Safari ask permission error",e),o.PERMISSION_DENIED))),clearInterval(i)}else t=e.getPermission();const i=await this.isFullyRegistered(!1);if(t===o.PERMISSION_GRANTED){const t=await this.getLoggedInContact();return I.debug("User granted permission for push notifications"),this.eventEmitter.emit(o.EVENT_ON_PERMISSION_GRANTED),i?I.debug("Triggering subscribe for token update"):(I.debug("Triggering push service unsubscribe"),await e.unsubscribe(),I.debug("Triggering push service subscribe")),await e.subscribe(t),await this.meWebPushDb.setLastUsedAt(),void this.eventEmitter.emit(o.EVENT_ON_SUBSCRIBE)}t===o.PERMISSION_DENIED&&(I.log("User has declined push permission"),i&&await e.unsubscribe(),this.eventEmitter.emit(o.EVENT_ON_PERMISSION_DENIED))}async unsubscribe(){try{I.debug("Unsubscribing..."),await this.getPushService().unsubscribe(),y.setRegistrationStatus(o.DEVICE_REGISTRATION_STATUS_UNREGISTERED),this.eventEmitter.emit(o.EVENT_ON_UNSUBSCRIBE)}catch(e){I.error(e,"Error occurred during unsubscribe")}}async getParams(){const e=await this.meWebPushDb.getAppCode(),t=await this.meWebPushDb.getClientIdForAppCode(e),i=await this.meWebPushDb.getInitParams();return{applicationCode:e,clientId:t,pushToken:await this.meWebPushDb.getPushToken(),serviceWorkerScope:await this.meWebPushDb.getServiceWorkerScope(),serviceWorkerVersion:await this.meWebPushDb.getServiceWorkerVersion(),sdkVersion:await this.meWebPushDb.getSdkVersion(),meClientServiceApiBaseUrl:await this.meWebPushDb.getMeClientServiceApiBaseUrl(),meDeviceEventServiceApiBaseUrl:await this.meWebPushDb.getMeDeviceEventServiceApiBaseUrl(),clientState:await this.meWebPushDb.getClientState(),contactToken:await this.meWebPushDb.getContactToken(),refreshToken:await this.meWebPushDb.getRefreshToken(),...i}}async getLoggedInContact(){const e=await this.storageWithLog.getClientState({level:"info"});if(!e)return;const t=D.decode(e);if(!t)return void I.error("Decoding failed",JSON.stringify(e));const i=t.contactField;return void 0!==i?null===i||0===Object.keys(i).length?{}:void 0!==i.contactFieldId&&i.contactFieldValue?{fieldId:i.contactFieldId,fieldValue:i.contactFieldValue,encrypted:"boolean"==typeof i.contactFieldEncryped&&i.contactFieldEncryped}:void I.error("contactField information incomplete",JSON.stringify(i)):void 0}async isLoggedIn(){const e=await this.getLoggedInContact();return!(P.isEmptyObject(e)||void 0===e)}async setOpenIdAuthenticatedContact(e){return this.assertOpenIdContactInfo(e),this.meClientService.linkClientToContact(e)}async login(e){this.assertContactInfo(e);const t=void 0!==e?{...e,encrypted:!1}:e;return this.meClientService.linkClientToContact(t)}async logout(){return this.meClientService.linkClientToContact()}async removeAllDeviceData(){await this.cleanupClientOnBackend(this.meClientService),await this.meWebPushDb.clearAll()}async isSubscribed(){return this.isFullyRegistered()}async registerClient(e){this.assertContactInfo(e);const t=e?{...e,encrypted:!1}:void 0;return await this.meClientService.storeClientDetails()&&await this.meClientService.linkClientToContact(t)}async getClientId(){const e=await this.meWebPushDb.getAppCode();if(void 0===e)return void I.log("No APP code found in environment");const t=await this.meWebPushDb.getClientIdForAppCode(e);return void 0===t&&I.log(`No client ID for APP code "${e}" found`),t}assertContactInfo(e){if(e&&(void 0===e.fieldId||!e.fieldValue))throw new Error(`Incomplete contact info: ${JSON.stringify(e)}`)}assertOpenIdContactInfo(e){if(void 0===e.fieldId||!e.openIdToken)throw new Error(`Incomplete contact info: ${JSON.stringify(e)}`)}async init(e){if(!this.pushNotificationSupportInfo.pushNotificationsSupported())return Promise.reject(new Error("Web push not supported"));this.enableLogging(e.enableLogging),await this.setupMeClientService(e.clientServiceApiBaseUrl),await this.setupMeDeviceEventService(e.deviceEventServiceApiBaseUrl);const t=await this.checkApplicationCode(this.meClientService,e.applicationCode);await this.checkClientId(t),await this.persistPlatformInfo(e),await this.persistConfig(e),await this.initPushNotifications(e),this.eventEmitter.emit(o.EVENT_ON_READY),this.ready=!0}enableLogging(e){m(!0===e)}async setupMeClientService(e){const t=null!=e?e:o.defaultClientServiceApiBaseUrl;this.meClientService=u.MEClientService.create(t,b.MEV3ApiRequest.create(),this.meWebPushDb),await this.meWebPushDb.setMeClientServiceApiBaseUrl(t)}async setupMeDeviceEventService(e){const t=null!=e?e:o.defaultDeviceEventServiceApiBaseUrl;this.meDeviceEventService=l.MEDeviceEventService.create(t,b.MEV3ApiRequest.create(),this.meWebPushDb),await this.meWebPushDb.setMeDeviceEventServiceApiBaseUrl(t)}async checkApplicationCode(e,t){const i=await this.meWebPushDb.getAppCode();if(!t)return Promise.reject(new Error("Can't find application code!"));return(!i||i&&i!==t)&&(await this.cleanupClientOnBackend(e),await this.meWebPushDb.clearAll(),await this.meWebPushDb.setAppCode(t)),t}async checkClientId(e){const t=await this.meWebPushDb.getClientIdForAppCode(e);if(t)I.log("ClientId exists:",t);else{I.log("No ClientId stored. Creating one...");const t=e+"_"+v.v4();await this.meWebPushDb.setClientIdForAppCode(t,e)}}async persistPlatformInfo(e){var t;const i=this.navigatorInfo.getAll();await Promise.all([this.meWebPushDb.setPlatform(i.browser),this.meWebPushDb.setApplicationVersion(null!==(t=e.applicationVersion)&&void 0!==t?t:o.defaultApplicationVersion),this.meWebPushDb.setDeviceModel(i.userAgent),this.meWebPushDb.setOsVersion(i.browserVersion),this.meWebPushDb.setLanguage(i.language),this.meWebPushDb.setTimezone(i.timezone),this.meWebPushDb.setSdkVersion("4.6.0")])}async persistConfig(e){var t,i;const s=e.serviceWorker?e.serviceWorker.url:void 0,n=P.determineServiceWorkerScope(e.serviceWorker),r=e.serviceWorker?e.serviceWorker.applicationServerPublicKey:void 0;await Promise.all([this.meWebPushDb.setServiceWorkerUrl(s),this.meWebPushDb.setServiceWorkerScope(n),this.meWebPushDb.setApplicationServerPublicKey(r),this.meWebPushDb.setDefaultNotificationIcon(e.defaultNotificationIcon),this.meWebPushDb.setDefaultNotificationTitle(e.defaultNotificationTitle),this.meWebPushDb.setWebsitePushId(e.safariWebsitePushID),this.meWebPushDb.setPushPackageServiceUrl(e.safariPushPackageServiceUrl),this.meWebPushDb.setLoggingEnabled(Boolean(e.enableLogging).valueOf()),this.meWebPushDb.setMeClientServiceApiBaseUrl(null!==(t=e.clientServiceApiBaseUrl)&&void 0!==t?t:o.defaultClientServiceApiBaseUrl),this.meWebPushDb.setMeDeviceEventServiceApiBaseUrl(null!==(i=e.deviceEventServiceApiBaseUrl)&&void 0!==i?i:o.defaultDeviceEventServiceApiBaseUrl),this.meWebPushDb.setLastUsedAt()])}async initPushNotifications(e){const t=Boolean(e.enableMacSafariVapid).valueOf(),i={...e,enableLogging:Boolean(e.enableLogging).valueOf(),enableMacSafariVapid:t};await this.meWebPushDb.setInitParams(i),await this.setupPushService(t);try{await this.initialPushServiceProcessing(i)}catch(e){I.error(e,"Internal error")}}async setupPushService(e){if(!this.meClientService)throw new Error("Me client service connection is not set up!");if(!this.pushNotificationSupportInfo.canUseSafariPush()||e&&this.pushNotificationSupportInfo.canUseServiceWorkers()){if(this.pushNotificationSupportInfo.canUseServiceWorkers()){const e=new p.VapidPushService(this.meWebPushDb,this.meClientService);await e.updateServiceWorker(),this.pushService=e}}else{const e=await this.buildApnsApiRegistrationConfig();this.pushService=new p.SafariPushService(this.meWebPushDb,e,this.meClientService)}}async initialPushServiceProcessing(e){const t=this.getPushService(),i=t.getPermission();i===o.PERMISSION_GRANTED&&await this.meWebPushDb.setLastPermissionStatus(i);await t.isResubscribeNeeded()&&(I.log("Re-subscribe is needed."),await this.unsubscribe());const s=await this.isFullyRegistered(!1);switch(i){case o.PERMISSION_PROMPT:s&&(I.debug("Unsubscribing in PROMPT state"),this.eventEmitter.emit(o.EVENT_ON_PERMISSION_PROMPT),await this.unsubscribe());break;case o.PERMISSION_DENIED:s&&await this.unsubscribe(),this.eventEmitter.emit(o.EVENT_ON_PERMISSION_DENIED);break;case o.PERMISSION_GRANTED:_.isUnregistered()||await this.subscribe(),this.eventEmitter.emit(o.EVENT_ON_PERMISSION_GRANTED)}}async cleanupClientOnBackend(e){I.debug("Cleanup of client information on backend side");const{exists:t,pushTokenExists:i,identified:s}=await P.checkDevice(this.meWebPushDb);if(t){if(i){const t=await e.removePushToken();I.log("Removed registered push token:",t)}if(s){const t=await e.linkClientToContact();I.log("Assigned anonymous contact:",t)}}else I.debug("The browser is not registered at all.")}getPushService(){if(this.pushService)return this.pushService;throw new Error("Push service is not set up!")}async buildApnsApiRegistrationConfig(){const e=await this.meWebPushDb.getWebsitePushId(),t=await this.meWebPushDb.getAppCode(),i=await this.meWebPushDb.getClientIdForAppCode(t);if(e&&t&&i){const s=await this.meWebPushDb.getPushPackageServiceUrl();return{clientId:i,applicationCode:t,safariWebsitePushID:e,safariPushPackageServiceUrl:null!=s?s:o.defaultSafariPushPackageServiceUrl}}throw new Error("safariWebsitePushID must be specified for Safari support!")}onReadyHandler(e){this.ready?e(void 0):this.eventEmitter.on(o.EVENT_ON_READY,(t=>e(void 0,t)))}registerOrHandleOnReadyCallback(e){this.onReadyHandler(e)}registerEventCallback(e,t){this.eventEmitter.on(e,(e=>t(void 0,e)))}registerChangePermissionCallback(e,t){const i=this.permissionPromises[e];if(!i)return;const s=this.registerEventCallback.bind(this);i.then((()=>(s(e,t),t(void 0)))).catch((e=>I.error(e,"Error while handling permission change callback.")))}async isFullyRegistered(e=!0){const t=y.getRegistrationStatus();return I.debug("Local status is",t),void 0!==t&&e?Promise.resolve(t===o.DEVICE_REGISTRATION_STATUS_REGISTERED):this.updateRegistrationStatus()}static isUnregistered(){return y.getRegistrationStatus()===o.DEVICE_REGISTRATION_STATUS_UNREGISTERED}async updateRegistrationStatus(){I.debug("Checking device...");const e=await this.pushService.isRegistered();I.debug("Device exists & has token",e);const t=e?o.DEVICE_REGISTRATION_STATUS_REGISTERED:o.DEVICE_REGISTRATION_STATUS_UNREGISTERED;return y.setRegistrationStatus(t),t===o.DEVICE_REGISTRATION_STATUS_REGISTERED}async retrySendAfterContactTokenRefresh(e){return await this.meClientService.generateAccessToken()?this.meDeviceEventService.postEvents(e):(I.error("Refresh of access token failed!"),{success:!1})}static create(e,t){return new _(e,t)}}t.default=_},151:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.NavigatorInfo=void 0;const s=i(552),n=[["edge",/Edge\/([0-9._]+)/],["edge",/EdgiOS\/([0-9._]+)/],["edge",/EdgA?\/([0-9.]+)/],["samsung",/SamsungBrowser\/([0-9.]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9.]+)(?:\s|$)/],["opera",/Opera Mini.*Version\/([0-9.]+)/],["opera",/Opera\/([0-9.]+)(?:\s|$)/],["opera",/OPR\/([0-9.]+)(:?\s|$)/],["safari",/Version\/([0-9._]+).*Safari/]],r={samsung:"chrome",opera:"chrome"};class a{constructor(e){this.navigator=e}getAll(){return{userAgent:this.getUserAgent(),browser:this.getBrowserName(),browserVersion:this.getVersion(),timezone:this.getTimezone(),language:this.getLanguage()}}hasServiceWorker(){return"serviceWorker"in this.navigator}getUserAgent(){return this.navigator.userAgent}getBrowserName(){let e="chrome";const t=this.navigator.userAgent;for(const i of n){const[s,n]=i;if(n.exec(t)){e=s;break}}return this.getMappedBrowserName(e)}getMappedBrowserName(e){const t=r[e];return t||e}getVersion(){return s.BrowserVersionParser.parseBrowserVersion(this.navigator)}getTimezone(){const e=(new Date).getTimezoneOffset();return(e<0?"+":"-")+this.pad(Math.abs(e/60),2)+this.pad(Math.abs(e%60),2)}getLanguage(){return this.navigator.language}pad(e,t){let i=e.toString();for(;i.length{Object.defineProperty(t,"__esModule",{value:!0}),t.PushNotificationSupportInfo=void 0;class i{constructor(e,t){this.navigatorInfo=e,this.window=t}pushNotificationsSupported(){return this.canUseSafariPush()||this.canUseServiceWorkers()}canUseServiceWorkers(){return this.navigatorInfo.hasServiceWorker()&&"PushManager"in this.window}canUseSafariPush(){return"safari"in this.window&&"pushNotification"in this.window.safari}canUsePromises(){return"Promise"in this.window}static create(e,t){return new i(e,t)}}t.PushNotificationSupportInfo=i},642:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});var s=i(911);Object.defineProperty(t,"VapidPushService",{enumerable:!0,get:function(){return s.VapidPushService}});var n=i(819);Object.defineProperty(t,"SafariPushService",{enumerable:!0,get:function(){return n.SafariPushService}})},819:function(e,t,i){var s=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[i]}})}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.hasOwnProperty.call(e,i)&&s(t,e,i);return n(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SafariPushService=void 0;const o=r(i(838)),c=a(i(142)),u=r(i(304)),l=r(i(50));t.SafariPushService=class{constructor(e,t,i){this.webPushDb=e,this.config=t,this.meClientService=i}getPermission(){const{permission:e}=this.getPermissionInfo();return e}isPermissionGranted(){return this.getPermission()===o.PERMISSION_GRANTED}isPermissionDefault(){return this.getPermission()===o.PERMISSION_PROMPT}async askPermission(){const e={application:this.config.applicationCode,clientId:this.config.clientId};return new Promise((t=>{safari.pushNotification.requestPermission(this.config.safariPushPackageServiceUrl,this.config.safariWebsitePushID,e,(e=>t(e.permission)))}))}async getPushToken(){return this.webPushDb.getPushToken()}async subscribe(e){if(!this.isPermissionGranted())return void c.default.Logger.error("Permission must be granted before subscribing!");const{deviceToken:t}=this.getPermissionInfo();if(t){c.default.Logger.debug("Got device token:",t);await this.getPushToken()!==t&&(c.default.Logger.debug("Registering device, linking and registering push token"),await this.meClientService.storeClientDetails()&&await this.meClientService.linkClientToContact(l.toContactInfo(e))&&await this.meClientService.registerPushToken(t)&&(await this.webPushDb.setPushToken(t),u.setRegistrationStatus(o.DEVICE_REGISTRATION_STATUS_REGISTERED)))}else await this.webPushDb.setPushToken(t),u.setRegistrationStatus(o.DEVICE_REGISTRATION_STATUS_UNREGISTERED)}async unsubscribe(){await this.meClientService.removePushToken(),await this.webPushDb.setPushToken(void 0),u.setRegistrationStatus(o.DEVICE_REGISTRATION_STATUS_UNREGISTERED)}async isRegistered(){return l.isDeviceRegistered(this.webPushDb)}async isResubscribeNeeded(){const e=await this.webPushDb.getWebsitePushId(),t=void 0!==e,i=t&&this.config.safariWebsitePushID!==e;await this.webPushDb.setWebsitePushId(this.config.safariWebsitePushID);const s=await this.webPushDb.getLastPermissionStatus(),n=this.getPermission();return s!==n?(await this.webPushDb.setLastPermissionStatus(n),!0):i||!t}getPermissionInfo(){return safari.pushNotification.permission(this.config.safariWebsitePushID)}}},911:function(e,t,i){var s=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[i]}})}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.hasOwnProperty.call(e,i)&&s(t,e,i);return n(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.VapidPushService=void 0;const o=i(831),c=r(i(838)),u=a(i(142)),l=r(i(304)),d=r(i(50));t.VapidPushService=class{constructor(e,t){this.webPushDb=e,this.meClientService=t}getPermission(){return Notification.permission}isPermissionGranted(){return this.getPermission()===c.PERMISSION_GRANTED}isPermissionDefault(){return this.getPermission()===c.PERMISSION_PROMPT}async askPermission(){return Notification.requestPermission()}async getPushToken(){return this.webPushDb.getPushToken()}async subscribe(e){if(!this.isPermissionGranted())return void u.default.Logger.error("Permission must be granted before subscription!");const t=await this.getPushSubscription();if(null!==t){const i=JSON.stringify(t);u.default.Logger.debug("Got valid subscription:",i);await this.getPushToken()!==i&&(u.default.Logger.debug("Registering device, linking and registering push token"),await this.meClientService.storeClientDetails()&&await this.meClientService.linkClientToContact(d.toContactInfo(e))&&await this.meClientService.registerPushToken(i)&&(await this.webPushDb.setPushToken(i),l.setRegistrationStatus(c.DEVICE_REGISTRATION_STATUS_REGISTERED)))}else u.default.Logger.warn("Issue fetching the actual push token (subscription).")}async unsubscribe(){u.default.Logger.log("VAPID: unsubscribe");const e=await this.getServiceWorkerRegistration();u.default.Logger.log("VAPID: registration",e);const t=await e.pushManager.getSubscription();u.default.Logger.log("VAPID: subscription",t),await this.meClientService.removePushToken(),await this.webPushDb.setPushToken(void 0),t&&(await t.unsubscribe(),l.setRegistrationStatus(c.DEVICE_REGISTRATION_STATUS_UNREGISTERED))}async isRegistered(){return d.isDeviceRegistered(this.webPushDb)}async isResubscribeNeeded(){const e=await this.webPushDb.getLastPermissionStatus(),t=this.getPermission();return e!==t&&await this.webPushDb.setLastPermissionStatus(t),e!==t}async updateServiceWorker(){return this.registerServiceWorker()}async getServiceWorkerRegistration(){if(!this.registration){if(u.default.Logger.debug("No service worker found. Registering service worker..."),this.registration=await this.registerServiceWorker(),!this.registration)throw new Error("Internal Error: Can't register service worker!");u.default.Logger.log("Service worker is registered"),await this.registration.update()}return this.registration}async registerServiceWorker(){const e=await this.webPushDb.getServiceWorkerUrl(),t=await this.webPushDb.getServiceWorkerScope(),i=await this.webPushDb.getSdkVersion()!==await this.webPushDb.getServiceWorkerVersion()?`?cache_clean=${o.v4()}`:"",s=t?{scope:t}:void 0;return navigator.serviceWorker.register(`/${e}${i}`,s)}async getPushSubscription(e=!1){const t=await this.getServiceWorkerRegistration(),i=await this.getApplicationServerKey(),s=await t.pushManager.getSubscription(),n=null!==s?s:await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:i});return n.endpoint.length>0?n:e?(u.default.Logger.warn("Retry to get subscription without empty endpoint failed. Giving up."),null):this.handleSubscriptionWithEmptyEndpoint(n)}async handleSubscriptionWithEmptyEndpoint(e){u.default.Logger.warn("Got subscription with empty endpoint",e);return await e.unsubscribe()?(u.default.Logger.debug("Retrying to get a subscription without an empty endpoint"),this.getPushSubscription(!0)):(u.default.Logger.warn("Unable to unsubscribe from subscription with empty endpoint"),null)}async getApplicationServerKey(){return this.webPushDb.getApplicationServerPublicKey()}}},252:function(e,t,i){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.StorageWithLog=void 0;const n=s(i(142)),{Logger:r}=n.default;t.StorageWithLog=class{constructor(e){this.storage=e}log(e,t,i){const{level:s="error",message:n=t}=null!=i?i:{};return e||r[s](n),e}async getClientId(e){const t=await this.storage.getClientId();return this.log(t,"Error: No client ID set for the browser!",e)}async getContactToken(e){const t=await this.storage.getContactToken();return this.log(t,"Error: No contact token set!",e)}async getClientState(e){const t=await this.storage.getClientState();return this.log(t,"Error: No client state set!",e)}async getRefreshToken(e){const t=await this.storage.getRefreshToken();return this.log(t,"Unable to refresh contact token a refresh-token is missing!",e)}}},50:function(e,t,i){var s=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[i]}})}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.hasOwnProperty.call(e,i)&&s(t,e,i);return n(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.determineServiceWorkerScope=t.isEmptyObject=t.toContactInfo=t.isValidPayload=t.payloadMessageDataProperties=t.checkDevice=t.isDeviceRegistered=t.urlB64ToString=t.urlB64ToUint8Array=t.getGlobal=t.getVersion=void 0;const a=r(i(198));function o(e){const t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/");return atob(t)}async function c(e){if(!await e.getClientId())return{exists:!1};const t=await e.getClientState();if(!t)return{exists:!1};const i=a.decode(t);if(!i)return{exists:!1};return{exists:!0,pushTokenExists:null!==(i.pushToken||null),identified:null!==(i.contactField||null)}}t.getVersion=function(){return"4.6.0"},t.getGlobal=function(){return Function("return this")()},t.urlB64ToUint8Array=function(e){const t=o(e),i=new Uint8Array(t.length);for(let e=0;e!!i[e]&&typeof i[e]===t.payloadMessageDataProperties[e])).reduce(((e,t)=>e&&t),!0)},t.toContactInfo=function(e){if(void 0!==e&&3===Object.keys(e).length)return e},t.isEmptyObject=e=>{if(null===e)return!0;if(void 0===e)return!0;for(const t in e)return!1;return!0},t.determineServiceWorkerScope=function(e){return e?e.scope:void 0}},395:function(e,t,i){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(843)),r=i(50);function a(){const e=r.getGlobal();let t,{WebEmarsysSdk:i}=e;i&&(t=i),i=n.default.create(window,navigator),Array.isArray(t)&&t.forEach((e=>i.push(e))),e.WebEmarsysSdk=i}"complete"===document.readyState?a():window.addEventListener("load",a)},831:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"NIL",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(t,"parse",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(t,"v1",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(t,"v3",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(t,"v4",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(t,"v5",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(t,"validate",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(t,"version",{enumerable:!0,get:function(){return c.default}});var s=h(i(518)),n=h(i(948)),r=h(i(73)),a=h(i(805)),o=h(i(808)),c=h(i(775)),u=h(i(37)),l=h(i(910)),d=h(i(792));function h(e){return e&&e.__esModule?e:{default:e}}},311:(e,t)=>{function i(e){return 14+(e+64>>>9<<4)+1}function s(e,t){const i=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(i>>16)<<16|65535&i}function n(e,t,i,n,r,a){return s((o=s(s(t,e),s(n,a)))<<(c=r)|o>>>32-c,i);var o,c}function r(e,t,i,s,r,a,o){return n(t&i|~t&s,e,t,r,a,o)}function a(e,t,i,s,r,a,o){return n(t&s|i&~s,e,t,r,a,o)}function o(e,t,i,s,r,a,o){return n(t^i^s,e,t,r,a,o)}function c(e,t,i,s,r,a,o){return n(i^(t|~s),e,t,r,a,o)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var u=function(e){if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(let i=0;i>5]>>>n%32&255,r=parseInt(s.charAt(i>>>4&15)+s.charAt(15&i),16);t.push(r)}return t}(function(e,t){e[t>>5]|=128<>5]|=(255&e[i/8])<{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};t.default=i},808:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default="00000000-0000-0000-0000-000000000000"},792:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s,n=(s=i(37))&&s.__esModule?s:{default:s};var r=function(e){if(!(0,n.default)(e))throw TypeError("Invalid UUID");let t;const i=new Uint8Array(16);return i[0]=(t=parseInt(e.slice(0,8),16))>>>24,i[1]=t>>>16&255,i[2]=t>>>8&255,i[3]=255&t,i[4]=(t=parseInt(e.slice(9,13),16))>>>8,i[5]=255&t,i[6]=(t=parseInt(e.slice(14,18),16))>>>8,i[7]=255&t,i[8]=(t=parseInt(e.slice(19,23),16))>>>8,i[9]=255&t,i[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,i[11]=t/4294967296&255,i[12]=t>>>24&255,i[13]=t>>>16&255,i[14]=t>>>8&255,i[15]=255&t,i};t.default=r},656:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i},858:(e,t)=>{let i;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){if(!i&&(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!i))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(s)};const s=new Uint8Array(16)},42:(e,t)=>{function i(e,t,i,s){switch(e){case 0:return t&i^~t&s;case 1:case 3:return t^i^s;case 2:return t&i^t&s^i&s}}function s(e,t){return e<>>32-t}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let i=0;i>>0;d=l,l=u,u=s(c,30)>>>0,c=a,a=o}n[0]=n[0]+a>>>0,n[1]=n[1]+c>>>0,n[2]=n[2]+u>>>0,n[3]=n[3]+l>>>0,n[4]=n[4]+d>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]};t.default=n},910:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.unsafeStringify=a;var s,n=(s=i(37))&&s.__esModule?s:{default:s};const r=[];for(let e=0;e<256;++e)r.push((e+256).toString(16).slice(1));function a(e,t=0){return r[e[t+0]]+r[e[t+1]]+r[e[t+2]]+r[e[t+3]]+"-"+r[e[t+4]]+r[e[t+5]]+"-"+r[e[t+6]]+r[e[t+7]]+"-"+r[e[t+8]]+r[e[t+9]]+"-"+r[e[t+10]]+r[e[t+11]]+r[e[t+12]]+r[e[t+13]]+r[e[t+14]]+r[e[t+15]]}var o=function(e,t=0){const i=a(e,t);if(!(0,n.default)(i))throw TypeError("Stringified UUID is invalid");return i};t.default=o},518:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s,n=(s=i(858))&&s.__esModule?s:{default:s},r=i(910);let a,o,c=0,u=0;var l=function(e,t,i){let s=t&&i||0;const l=t||new Array(16);let d=(e=e||{}).node||a,h=void 0!==e.clockseq?e.clockseq:o;if(null==d||null==h){const t=e.random||(e.rng||n.default)();null==d&&(d=a=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==h&&(h=o=16383&(t[6]<<8|t[7]))}let g=void 0!==e.msecs?e.msecs:Date.now(),f=void 0!==e.nsecs?e.nsecs:u+1;const b=g-c+(f-u)/1e4;if(b<0&&void 0===e.clockseq&&(h=h+1&16383),(b<0||g>c)&&void 0===e.nsecs&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");c=g,u=f,o=h,g+=122192928e5;const p=(1e4*(268435455&g)+f)%4294967296;l[s++]=p>>>24&255,l[s++]=p>>>16&255,l[s++]=p>>>8&255,l[s++]=255&p;const v=g/4294967296*1e4&268435455;l[s++]=v>>>8&255,l[s++]=255&v,l[s++]=v>>>24&15|16,l[s++]=v>>>16&255,l[s++]=h>>>8|128,l[s++]=255&h;for(let e=0;e<6;++e)l[s+e]=d[e];return t||(0,r.unsafeStringify)(l)};t.default=l},948:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=r(i(25)),n=r(i(311));function r(e){return e&&e.__esModule?e:{default:e}}var a=(0,s.default)("v3",48,n.default);t.default=a},25:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.URL=t.DNS=void 0,t.default=function(e,t,i){function s(e,s,a,o){var c;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let i=0;i{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=a(i(140)),n=a(i(858)),r=i(910);function a(e){return e&&e.__esModule?e:{default:e}}var o=function(e,t,i){if(s.default.randomUUID&&!t&&!e)return s.default.randomUUID();const a=(e=e||{}).random||(e.rng||n.default)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t){i=i||0;for(let e=0;e<16;++e)t[i+e]=a[e];return t}return(0,r.unsafeStringify)(a)};t.default=o},805:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=r(i(25)),n=r(i(42));function r(e){return e&&e.__esModule?e:{default:e}}var a=(0,s.default)("v5",80,n.default);t.default=a},37:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s,n=(s=i(656))&&s.__esModule?s:{default:s};var r=function(e){return"string"==typeof e&&n.default.test(e)};t.default=r},775:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s,n=(s=i(37))&&s.__esModule?s:{default:s};var r=function(e){if(!(0,n.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)};t.default=r}},t={};(function i(s){var n=t[s];if(void 0!==n)return n.exports;var r=t[s]={exports:{}};return e[s].call(r.exports,r,r.exports,i),r.exports})(395)})(); //# sourceMappingURL=web-emarsys-sdk.js.map