/*! For license information please see native-push-sdk.js.LICENSE.txt */ !function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(e){for(var r=1;r=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),u=s.call(o,"finallyLoc");if(c&&u){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&s.call(n,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),L(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;L(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:_(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function s(e,t,r,n,i,s,o){try{var a=e[s](o),c=a.value}catch(e){return void r(e)}a.done?t(c):Promise.resolve(c).then(n,i)}function o(){this.partnerName=Insider.partner.name,this.localStorage="storageData",this.webPushStorageKey="ins-wp-storage",this.debug=!0,this.tokenCollectorUrl="https://carrier.useinsider.com/v2/web-push/token-collector",this.hitApiUrl="https://hit.api.useinsider.com/hit",this.swPath=Insider.webPushState.nativeOptInSDKCustomPath?Insider.webPushState.nativeOptInSDKCustomPath:"/insider-sw-sdk.js",this.VAPIDPublicKey=Insider.webPushState.VAPIDPublicKey,this.isVAPIDActive=!Insider.fns.isEmptyString(this.VAPIDPublicKey),this.wpLogUrl="https://wp-log.api.useinsider.com/v2/collect",this.STORAGE={PAYLOAD_COMPLETE:"ins-wp-payload-complete",TOKEN_CREATE_DATE:"ins-wp-token-create-date",MIGRATED_SDK:"ins-wp-migrated-sdk",TOKEN:"ins-wp-token",REQUEST_SENT:"ins-wp-request-sent",NATIVE_PERMISSION_IMPRESSION:"ins-wp-native-permission-impression",LOCAL_STORAGE:"localStorage",VARIATION_CANDIDATE:"ins-variationCandidate"},this.tableName="settings",this.hasServiceWorkerSupport="serviceWorker"in navigator,this.hasPush="PushManager"in window||"push"in navigator,this.hasNotification="Notification"in window,this.events={CORE:"nativeSdk:permission:",PROMPTED:"prompted",GRANTED:"granted",DENIED:"denied"},this.classes={optInNativeDialog:"insider-opt-in-native-dialog",optInOverlay:"insider-opt-in-overlay",optInOverlayMessage:"insider-opt-in-overlay-message",optInInstructionWrapper:"insider-opt-in-instruction-wrapper",optInInstruction:"insider-opt-in-instruction",optInInstructionClose:"insider-opt-in-instruction-close",optInInstructionImage:"insider-opt-in-instruction-image",optInInstructionMessage:"insider-opt-in-instruction-message"},this.lastSwRegistrationError="lastSwRegistrationError",this.campaignStorageNamePrefix="sp-camp-",this.METHODS={INSERT:"insert",UPDATE:"update"},this.PUSH_TYPES={WELCOME:10},this.LEAD_COLLECTION={ENDPOINT:"https://carrier.useinsider.com/v2/form/save-questionnaire/".concat(this.partnerName),REQUEST_HEADERS:{partner:this.partnerName,"Content-Type":"application/json"},REQUEST_DATA:{form_data:[],uid:Insider.getUserId(),source:window.location.href,platform:Insider.browser.getPlatform()}}}o.prototype.initialize=function(){var e=this;return this.debug=this.checkFromStorage("insider-push-debug",!0),this.initializeIndexedDB((function(t){t&&(Insider.indexedDB.save(e.tableName,{id:1,name:"partnerName",value:e.partnerName}),Insider.indexedDB.save(e.tableName,{id:2,name:"spUID",value:Insider.getUserId()}),Insider.indexedDB.save(e.tableName,{id:3,name:"lastReceivedWebPushes",value:[]}))})),this.debug&&(console.log("Initializing Native SDK"),console.log("Push Manager Support:",this.hasPush),console.log("Notification Support:",this.hasNotification)),this.hasPush&&this.hasNotification&&("Safari"!==Insider.browser.name&&this.saveImpressionLog(),this.grantPermission()),Insider.eventManager.dispatch(this.events.CORE+this.events.PROMPTED),!0},o.prototype.initializeIndexedDB=function(){var e,t=(e=i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Insider.indexedDB.connect("webPush",(function(e){t(e)})),e.abrupt("return",!0);case 2:case"end":return e.stop()}}),e)})),function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){s(o,n,i,a,c,"next",e)}function c(e){s(o,n,i,a,c,"throw",e)}a(void 0)}))});return function(e){return t.apply(this,arguments)}}(),o.prototype.saveImpressionLog=function(){return!this.checkFromStorage(this.STORAGE.NATIVE_PERMISSION_IMPRESSION,!0)&&(this.setStorage(this.STORAGE.NATIVE_PERMISSION_IMPRESSION,!0,360),new Insider.log("w",{t:"storeLog",type:"webPush",logType:"native-permission-impression",browser:Insider.browser.name,isMobile:Insider.browser.isMobile(),language:Insider.systemRules.call("getLang")}).setLogURL(this.wpLogUrl).send(),!0)},o.prototype.grantPermission=function(){return this.appendOverlay(),this.appendInstructionMessage(),"Safari"===Insider.browser.name&&"granted"===Notification.permission?(this.registerServiceWorker(),!0):(Notification.requestPermission().then(this.handlePermissionAction.bind(this)),!0)},o.prototype.appendOverlay=function(){if(!window.insiderOptInOverlayIsActive)return!1;var e=Insider.dom().create("div",{id:this.classes.optInNativeDialog});return e.append(Insider.dom().create("div",{className:this.classes.optInOverlay})),e.append(Insider.dom().create("div",{className:this.classes.optInOverlayMessage}).text(window.insiderOptInOverlayMessage)),Insider.dom("body").append(e),Insider.eventManager.on("click",".".concat(this.classes.optInOverlay),this.removeOverlayAndInstruction.bind(this)),!0},o.prototype.appendInstructionMessage=function(){return!!window.insiderOptInInstructionMessageIsActive&&(Insider.dom("body").append(this.getInstructionMessageElement()),Insider.eventManager.on("click",".".concat(this.classes.optInInstruction),this.removeOverlayAndInstruction.bind(this)),!0)},o.prototype.getInstructionMessageElement=function(){var e=Insider.dom().create("div",{id:this.classes.optInInstructionWrapper,className:this.classes.optInInstruction});return e.append(Insider.dom().create("div",{className:this.classes.optInInstructionClose})).append(Insider.dom().create("div",{className:this.classes.optInInstructionImage}).append(Insider.dom().create("img",{src:window.insiderOptInInstructionImage}))),e.append(Insider.dom().create("div",{className:this.classes.optInInstructionMessage}).text(window.insiderOptInInstructionMessage)),e},o.prototype.handlePermissionAction=function(e){return this.removeOverlayAndInstruction(),!window.isRequestPermission&&"default"!==e&&("Safari"===Insider.browser.name&&this.saveImpressionLog(),window.isRequestPermission=!0,"granted"!==e?(Insider.eventManager.dispatch(this.events.CORE+this.events.DENIED),!1):(Insider.eventManager.dispatch(this.events.CORE+this.events.GRANTED),this.registerServiceWorker(),!0))},o.prototype.removeOverlayAndInstruction=function(){return!(!window.insiderOptInOverlayIsActive&&!window.insiderOptInInstructionMessageIsActive||(window.insiderOptInOverlayIsActive&&Insider.dom("#".concat(this.classes.optInNativeDialog)).remove(),window.insiderOptInInstructionMessageIsActive&&Insider.dom("#".concat(this.classes.optInInstructionWrapper)).remove(),0))},o.prototype.registerServiceWorker=function(){var e=this;return navigator.serviceWorker.register(this.swPath).then(this.handleRegistrationEvent.bind(this)).catch((function(t){var r="REGISTRATION_ERROR | "+"Browser: ".concat(Insider.browser.getBrowserNameForWebPushToken()," | ")+"Partner: ".concat(e.partnerName," | ")+"Error: ".concat(t.message||t.stack);e.isEqualToLastError(r)||(e.setLastSwRegistrationError(r),e.sendLogToTokenCollector(r)),e.handleException(t)})),Insider.worker.pm({type:"unregisterCustomOptInServiceWorker"}),!0},o.prototype.handleException=function(e){var t=Number(Insider.webPushState.nativeOptInCookieSettings.permissionAbandonExpireDay);return"denied"===Notification.permission&&(t=Number(Insider.webPushState.nativeOptInCookieSettings.permissionBlockExpireDay)),this.setUserPermissionGranted({pushRequestSent:!0}),this.setStorage(this.STORAGE.REQUEST_SENT,!0,t),this.debug&&console.log(e),this.removeOverlayAndInstruction(),!0},o.prototype.handleRegistrationEvent=function(e){var t=this;return e.addEventListener("updatefound",(function(r){var n=r.target.installing;n.addEventListener("statechange",(function(){"activated"===n.state&&t.subscribe(e)}))})),this.instantSubscribe(e),!0},o.prototype.subscribe=function(e){var t={userVisibleOnly:!0};return this.isVAPIDActive&&(t.applicationServerKey=this.convertVapidKeyToInt8Array()),e.pushManager.subscribe(t).then(this.saveSubscription.bind(this)).catch((function(e){var t=this;console.log("Error occurred while subscribing existing registration: ",e),Insider.fns.has(e.message,"applicationServerKey")&&this.hasServiceWorkerSupport&&navigator.serviceWorker.getRegistration().then((function(e){Insider.fns.isUndefined(e)||e.unregister().then((function(){t.register()}))}))})),!0},o.prototype.saveSubscription=function(e){var t;t="subscriptionId"in e?e.subscriptionId:this.getSubscriptionId(e.endpoint);var r=Insider.fns.parse(Insider.fns.stringify(e)).keys||{},n=r.auth||"",i=r.p256dh||"";return this.setUserPermissionGranted({insdrSubsId:t,pushRequestSent:!0}),Insider.worker.pm({type:this.localStorage,message:{action:"read"},success:function(r){var s=Insider.fns.find(r,"key",this.webPushStorageKey,!0),o=Math.floor(Date.now()/1e3),a=this.getStorage("unificationUserDataHash")&&!this.getStorage("ins-wp-user-unification");if(this.migrationNeeded()||!Insider.fns.isEmptyArray(s)||a)a&&this.setStorage("ins-wp-user-unification","true",Insider.dateHelper.addHour()),this.saveSubscriptionId(t,n,i,this.METHODS.UPDATE),this.initializeIndexedDB((function(t){t&&(Insider.indexedDB.upsert("options",{key:"subscriptionId",value:e.endpoint}),Insider.indexedDB.upsert("options",{key:"subscriptionUpdateDate",value:o}))}));else{var c=this.getWelcomeTestPushId();this.saveSubscriptionId(t,n,i,this.METHODS.INSERT,c),this.initializeIndexedDB((function(t){t&&(Insider.indexedDB.upsert("options",{key:"subscriptionId",value:e.endpoint}),Insider.indexedDB.upsert("options",{key:"subscriptionCreateDate",value:o}),Insider.indexedDB.upsert("options",{key:"subscriptionUpdateDate",value:o}))}))}}.bind(this)}),!0},o.prototype.getWelcomeTestPushId=function(){var e=Insider.fns.objectValues(Insider.storage.get(this.STORAGE.VARIATION_CANDIDATE))[0];if(!e)return!1;var t=Insider.webPush.webPush.getPushById(e);return!(!t||t.otherSettings.pushType!==this.PUSH_TYPES.WELCOME)&&t.id},o.prototype.saveSubscriptionId=function(e,t,r,n){var i=this,s=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o={token:e,authToken:t,p256DH:r,isNativeOptIn:1,browser:Insider.browser.getBrowserNameForWebPushToken(),userId:Insider.getUserId(),pageUrl:window.location.href,language:Insider.systemRules.call("getLang"),partner:this.partnerName,method:n,swVersion:Insider.webPush.swVersion};return s&&(o.testCampaign=s),this.sendRequest({url:this.tokenCollectorUrl,data:o,headers:{partner:this.partnerName}},(function(){var t=Number(Insider.webPushState.nativeOptInCookieSettings.permissionAllowExpireDay);i.setStorage(i.STORAGE.REQUEST_SENT,!0,t),i.setStorage(i.STORAGE.PAYLOAD_COMPLETE,!0,t),i.setStorage(i.STORAGE.TOKEN,e,t),i.setStorage(i.STORAGE.MIGRATED_SDK,i.swPath,t),i.setStorage(i.STORAGE.TOKEN_CREATE_DATE,Date.now(),t),n===i.METHODS.INSERT&&i.sendOptinTemplatesLeadCollectionLogs()})),!0},o.prototype.sendOptinTemplatesLeadCollectionLogs=function(){var e=this,t=(Insider.webPush.webPush.optInTemplates||{}).campaigns;return!Insider.fns.isEmptyArray(t)&&(t.forEach((function(t){var n=t.id,i=Insider.storage.localStorage.get("".concat(e.campaignStorageNamePrefix).concat(n));Insider.fns.isObject(i)&&Insider.request.post({url:e.LEAD_COLLECTION.ENDPOINT,headers:e.LEAD_COLLECTION.REQUEST_HEADERS,parse:!0,data:Insider.fns.stringify(r(r({},e.LEAD_COLLECTION.REQUEST_DATA),{},{campaign_id:n}))})})),!0)},o.prototype.setUserPermissionGranted=function(e){return Insider.fns.pm({target:window.top,type:"setUserPermissionGranted",message:e}),!0},o.prototype.getSubscriptionId=function(e){return e.split("/").pop()},o.prototype.instantSubscribe=function(e){var t;return e.installing?t=e.installing:e.waiting?t=e.waiting:e.active&&(t=e.active),!(!t||"activated"!==t.state||(this.subscribe(e),0))},o.prototype.migrationNeeded=function(){var e=this.checkFromStorage(this.STORAGE.PAYLOAD_COMPLETE,!0),t=Insider.webPushState.nativeOptInSDKCustomPath&&!this.getStorage(this.STORAGE.MIGRATED_SDK)&&e,r=!e&&this.getStorage(this.STORAGE.TOKEN);return t||r},o.prototype.getStorage=function(e){return Insider.storage.get(e,this.STORAGE.LOCAL_STORAGE,!0)},o.prototype.setStorage=function(e,t,r){return Insider.storage.set({name:e,value:t,expires:r},this.STORAGE.LOCAL_STORAGE,!0),!0},o.prototype.checkFromStorage=function(e,t){return this.getStorage(e)===t},o.prototype.convertVapidKeyToInt8Array=function(){for(var e=this.VAPIDPublicKey,t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),r=window.atob(t),n=new Uint8Array(r.length),i=0;i