diff --git a/CHANGELOG.md b/CHANGELOG.md index 90483ca..6c178c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## [1.7.4] - 3 May, 2024 +- Cross-site scripting (XSS) bugfix. + ## [1.7.3] - 3 Apr, 2024 - Fixes a issue in release pipeline of Service worker. diff --git a/clevertap.js b/clevertap.js index 6619e50..55e7efa 100644 --- a/clevertap.js +++ b/clevertap.js @@ -6658,7 +6658,7 @@ var proto = document.location.protocol; proto = proto.replace(':', ''); dataObject.af = _objectSpread2({ - lib: 'web-sdk-v1.7.3', + lib: 'web-sdk-v1.7.4', protocol: proto }, $ct.flutterVersion); // app fields diff --git a/clevertap.min.js b/clevertap.min.js index ee472b1..9d761fb 100644 --- a/clevertap.min.js +++ b/clevertap.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).clevertap=t()}(this,(function(){"use strict";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})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var i=0;ie.length)&&(t=e.length);for(var i=0,n=new Array(t);i=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,s=!1;return{s:function(){i=e[Symbol.iterator]()},n:function(){var e=i.next();return a=e.done,e},e:function(e){s=!0,r=e},f:function(){try{a||null==i.return||i.return()}finally{if(s)throw r}}}}var w=0;function k(e){return"__private_"+w+++"_"+e}function C(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var x,P="clevertap-prod.com",S="https:",O=k("accountId"),I=k("region"),_=k("targetDomain"),E=k("dcSdkversion"),A=k("token"),M=function(){function e(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=i.id,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:P,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";t(this,e),Object.defineProperty(this,O,{writable:!0,value:void 0}),Object.defineProperty(this,I,{writable:!0,value:""}),Object.defineProperty(this,_,{writable:!0,value:P}),Object.defineProperty(this,E,{writable:!0,value:""}),Object.defineProperty(this,A,{writable:!0,value:""}),this.id=n,o&&(this.region=o),r&&(this.targetDomain=r),a&&(this.token=a)}return n(e,[{key:"id",get:function(){return C(this,O)[O]},set:function(e){C(this,O)[O]=e}},{key:"region",get:function(){return C(this,I)[I]},set:function(e){C(this,I)[I]=e}},{key:"dcSDKVersion",get:function(){return C(this,E)[E]},set:function(e){C(this,E)[E]=e}},{key:"targetDomain",get:function(){return C(this,_)[_]},set:function(e){C(this,_)[_]=e}},{key:"token",get:function(){return C(this,A)[A]},set:function(e){C(this,A)[A]=e}},{key:"finalTargetDomain",get:function(){return this.region?"".concat(this.region,".").concat(this.targetDomain):this.targetDomain===P?"".concat("eu1",".").concat(this.targetDomain):this.targetDomain}},{key:"dataPostPEURL",get:function(){return"".concat(S,"//").concat(this.finalTargetDomain,"/defineVars")}},{key:"dataPostURL",get:function(){return"".concat(S,"//").concat(this.finalTargetDomain,"/a?t=96")}},{key:"recorderURL",get:function(){return"".concat(S,"//").concat(this.finalTargetDomain,"/r?r=1")}},{key:"emailURL",get:function(){return"".concat(S,"//").concat(this.finalTargetDomain,"/e?r=1")}}]),e}(),L=new RegExp("^\\s+|\\.|:|\\$|'|\"|\\\\|\\s+$","g"),T=new RegExp("^\\s+|'|\"|\\\\|\\s+$","g"),R=new RegExp("'","g"),j="clear",D="Charged ID",B="WZRK_CHARGED_ID",N="WZRK_G",z="WZRK_K",U="WZRK_CAMP",F="WZRK_CAMP_G",q="WZRK_EV",V="WZRK_META",W="WZRK_PR",K="WZRK_ARP",H="WZRK_L",G="global",J="optOut",Z="useIP",$="WZRK_X",Y="push",Q=31536e3,X="2",ee="wzrk_",te="wzrk_id",ie="Notification Viewed",ne="Notification Clicked",oe="WZRK_FPU",re="WZRK_PSD",ae="$incr",se="$decr",le="$set",ce="$add",de="$remove",ue="$delete",pe="WZRK_INBOX_CONFIG",he="WZRK_INBOX",ve=1e3,ge="wzrk_fetch",fe="wiz-iframe",be="wiz-iframe-intent",ye="Event",me="Profile",we=["Stayed","UTM Visited","App Launched","Notification Sent",ie,ne],ke=function(e){return"string"==typeof e||e instanceof String},Ce=function(e){return"[object Object]"===Object.prototype.toString.call(e)},xe=function(t){return"object"===e(t)&&t instanceof Date},Pe=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},Se=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},Oe=function(e){return/^-?[\d.]+(?:e-?\d+)?$/.test(e)&&"number"==typeof e},Ie=function(e){return null!=e&&"undefined"!==e},_e=function t(i,n){var o;if("object"!==e(i))return ke(i)?(o=Ee(i,T)).length>1024&&(o=o.substring(0,1024),n.reportError(521,o+"... length exceeded 1024 chars. Trimmed.")):o=i,o;for(var r in i)if(i.hasOwnProperty(r)){var a=t(i[r],n),s=void 0;(s=Ee(r,L)).length>1024&&(s=s.substring(0,1024),n.reportError(520,s+"... length exceeded 1024 chars. Trimmed.")),delete i[r],i[s]=a}return i},Ee=function(e,t){return e.replace(t,"")},Ae=function(){var e=new Date;return e.getFullYear()+""+e.getMonth()+e.getDay()},Me=function(){return Math.floor((new Date).getTime()/1e3)},Le=function(e){return"$D_"+Math.round(e.getTime()/1e3)},Te=function(e){if(Re(e))return"$D_"+e},Re=function(e){var t=/^(\d{4})(\d{2})(\d{2})$/.exec(e);if(null==t)return!1;var i=t[3],n=t[2]-1,o=t[1],r=new Date(o,n,i);return r.getDate()==i&&r.getMonth()==n&&r.getFullYear()==o},je=function(){function e(){t(this,e)}return n(e,null,[{key:"save",value:function(e,t){return!(!e||!t)&&(this._isLocalStorageSupported()?(localStorage.setItem(e,"string"==typeof t?t:JSON.stringify(t)),!0):void 0)}},{key:"read",value:function(e){if(!e)return!1;var t=null;if(this._isLocalStorageSupported()&&(t=localStorage.getItem(e)),null!=t)try{t=JSON.parse(t)}catch(e){}return t}},{key:"remove",value:function(e){return!!e&&(this._isLocalStorageSupported()?(localStorage.removeItem(e),!0):void 0)}},{key:"removeCookie",value:function(e,t){var i=e+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;";t&&(i=i+" domain="+t+"; path=/"),document.cookie=i}},{key:"createCookie",value:function(e,t,i,n){var o="",r="";if(i){var a=new Date;a.setTime(a.getTime()+1e3*i),o="; expires="+a.toGMTString()}n&&(r="; domain="+n),t=encodeURIComponent(t),document.cookie=e+"="+t+o+r+"; path=/"}},{key:"readCookie",value:function(e){for(var t=e+"=",i=document.cookie.split(";"),n=0;n=0;s--){if(a=0===s?r[s]+a:"."+r[s]+a,this.readCookie(e)){var l="test_"+e+s;if(this.createCookie(l,t,10,a),!this.readCookie(l))continue;this.removeCookie(l,a)}if(this.createCookie(e,t,i,a),this.readCookie(e)==t){o=a,De.broadDomain=o;break}}else this.createCookie(e,t,i,o)}else this.createCookie(e,t,i,n)}},{key:"getMetaProp",value:function(e){var t=this.readFromLSorCookie(V);if(null!=t)return t[e]}},{key:"setMetaProp",value:function(e,t){if(this._isLocalStorageSupported()){var i=this.readFromLSorCookie(V);null==i&&(i={}),void 0===t?delete i[e]:i[e]=t,this.saveToLSorCookie(V,i)}}},{key:"getAndClearMetaProp",value:function(e){var t=this.getMetaProp(e);return this.setMetaProp(e,void 0),t}},{key:"setInstantDeleteFlagInK",value:function(){var e=this.readFromLSorCookie(z);null==e&&(e={}),e.flag=!0,this.saveToLSorCookie(z,e)}},{key:"backupEvent",value:function(e,t,i){var n=this.readFromLSorCookie(H);void 0===n&&(n={}),n[t]={q:e},this.saveToLSorCookie(H,n),i.debug("stored in ".concat(H," reqNo : ").concat(t," -> ").concat(e))}},{key:"removeBackup",value:function(e,t){var i=this.readFromLSorCookie(H);null!=i&&void 0!==i[e]&&(t.debug("del event: ".concat(e," data-> ").concat(i[e].q)),delete i[e],this.saveToLSorCookie(H,i))}}]),e}(),De={globalCache:{gcookie:null,REQ_N:0,RESP_N:0},LRU_CACHE:null,globalProfileMap:void 0,globalEventsMap:void 0,blockRequest:!1,isOptInRequest:!1,broadDomain:null,webPushEnabled:null,campaignDivMap:{},currentSessionId:null,wiz_counter:0,notifApi:{notifEnabledFromApi:!1},unsubGroups:[],updatedCategoryLong:null,inbox:null,isPrivacyArrPushed:!1,privacyArray:[],offline:!1,location:null,dismissSpamControl:!1,globalUnsubscribe:!0,flutterVersion:null,variableStore:{}},Be=k("keyOrder"),Ne=k("deleteFromObject"),ze=function(){function e(i){t(this,e),Object.defineProperty(this,Ne,{value:Ue}),Object.defineProperty(this,Be,{writable:!0,value:void 0}),this.max=i;var n=je.readFromLSorCookie($);if(n){var o={};for(var r in C(this,Be)[Be]=[],n=n.cache)n.hasOwnProperty(r)&&(o[n[r][0]]=n[r][1],C(this,Be)[Be].push(n[r][0]));this.cache=o}else this.cache={},C(this,Be)[Be]=[]}return n(e,[{key:"get",value:function(e){var t=this.cache[e];return t&&(this.cache=C(this,Ne)[Ne](e,this.cache),this.cache[e]=t,C(this,Be)[Be].push(e)),this.saveCacheToLS(this.cache),t}},{key:"set",value:function(e,t){var i=this.cache[e],n=C(this,Be)[Be];null!=i?this.cache=C(this,Ne)[Ne](e,this.cache):n.length===this.max&&(this.cache=C(this,Ne)[Ne](n[0],this.cache)),this.cache[e]=t,C(this,Be)[Be][C(this,Be)[Be]-1]!==e&&C(this,Be)[Be].push(e),this.saveCacheToLS(this.cache)}},{key:"saveCacheToLS",value:function(e){var t=[],i=C(this,Be)[Be];for(var n in i)if(i.hasOwnProperty(n)){var o=[];o.push(i[n]),o.push(e[i[n]]),t.push(o)}je.saveToLSorCookie($,{cache:t})}},{key:"getKey",value:function(e){if(null===e)return null;var t=C(this,Be)[Be];for(var i in t)if(t.hasOwnProperty(i)&&this.cache[t[i]]===e)return t[i];return null}},{key:"getSecondLastKey",value:function(){var e=C(this,Be)[Be];return null!=e&&e.length>1?e[e.length-2]:-1}},{key:"getLastKey",value:function(){var e=C(this,Be)[Be].length;if(e)return C(this,Be)[Be][e-1]}}]),e}(),Ue=function(e,t){var i,n=JSON.parse(JSON.stringify(C(this,Be)[Be])),o={};for(var r in n)n.hasOwnProperty(r)&&(n[r]!==e?o[n[r]]=t[n[r]]:i=r);return n.splice(i,1),C(this,Be)[Be]=JSON.parse(JSON.stringify(n)),o},Fe=k("logger"),qe=k("request"),Ve=k("device"),We=k("session"),Ke=function(){function e(i){var n=i.logger,o=i.request,r=i.device,a=i.session;t(this,e),Object.defineProperty(this,Fe,{writable:!0,value:void 0}),Object.defineProperty(this,qe,{writable:!0,value:void 0}),Object.defineProperty(this,Ve,{writable:!0,value:void 0}),Object.defineProperty(this,We,{writable:!0,value:void 0}),C(this,Fe)[Fe]=n,C(this,qe)[qe]=o,C(this,Ve)[Ve]=r,C(this,We)[We]=a}return n(e,[{key:"s",value:function(e,t,i,n,o){var r=!1,a=!1;if(window.isOULInProgress&&(i||"undefined"!==n&&n===window.oulReqN)&&(window.isOULInProgress=!1,r=!0),void 0===n&&(n=0),je.removeBackup(n,C(this,Fe)[Fe]),!(n>De.globalCache.REQ_N)){if(Ie(C(this,Ve)[Ve].gcookie)||e&&(a=!0),!Ie(C(this,Ve)[Ve].gcookie)||i||"boolean"==typeof o){var s=C(this,We)[We].getSessionCookieObject();if(window.isOULInProgress||s.s&&t50&&t.reportError(522,"Charged Items exceed 50 limit. Actual count: "+e[i].length),e[i])if(e[i].hasOwnProperty(n)&&(!Ce(e[i][n])||!at(e[i][n])))return!1}else{if(Ce(e[i])||Array.isArray(e[i]))return!1;xe(e[i])&&(e[i]=Le(e[i]))}if(ke(e[D])||Oe(e[D])){var o=e[D]+"";if(void 0===x&&(x=je.readFromLSorCookie(B)),void 0!==x&&x.trim()===o.trim())return t.error("Duplicate charged Id - Dropped"+e),!1;x=o,je.saveToLSorCookie(B,o)}return!0}return!1},lt=k("logger"),ct=k("oldValues"),dt=k("request"),ut=k("isPersonalisationActive"),pt=k("processEventArray"),ht=function(e){s(o,e);var i=g(o);function o(e,n){var r,a=e.logger,s=e.request,l=e.isPersonalisationActive;return t(this,o),r=i.call(this),Object.defineProperty(h(r),pt,{value:vt}),Object.defineProperty(h(r),lt,{writable:!0,value:void 0}),Object.defineProperty(h(r),ct,{writable:!0,value:void 0}),Object.defineProperty(h(r),dt,{writable:!0,value:void 0}),Object.defineProperty(h(r),ut,{writable:!0,value:void 0}),C(h(r),lt)[lt]=a,C(h(r),ct)[ct]=n,C(h(r),dt)[dt]=s,C(h(r),ut)[ut]=l,r}return n(o,[{key:"push",value:function(){for(var e=arguments.length,t=new Array(e),i=0;i0;){var t=e.shift();if(ke(t))if(t.length>1024&&(t=t.substring(0,1024),C(this,lt)[lt].reportError(510,t+"... length exceeded 1024 chars. Trimmed.")),we.includes(t))C(this,lt)[lt].reportError(513,t+" is a restricted system event. It cannot be used as an event name.");else{var i={type:"event"};if(i.evtName=Ee(t,L),0!==e.length){var n=e.shift();if(Ce(n)){if("Charged"===t){if(!st(n,C(this,lt)[lt])){C(this,lt)[lt].reportError(511,"Charged event structure invalid. Not sent.");continue}}else if(!at(n)){C(this,lt)[lt].reportError(512,t+" event structure invalid. Not sent.");continue}i.evtData=n}else e.unshift(n)}C(this,dt)[dt].processEvent(i)}else C(this,lt)[lt].error(Ye)}},gt=function(e){var t={},i=e.indexOf("?");if(i>1){var n,o=e.substring(i+1),r=/\+/g,a=/([^&=]+)=?([^&]*)/g,s=function(e){var t=e.replace(r," ");try{t=decodeURIComponent(t)}catch(e){}return t};for(n=a.exec(o);n;)t[s(n[1])]=s(n[2]),n=a.exec(o)}return t},ft=function(e,t,i){return e+"&"+t+"="+encodeURIComponent(i)},bt=function(){return window.location.hostname},yt=function(e,t){return t&&"function"==typeof t.debug&&t.debug("dobj:"+e),wt(e)},mt=function(){var e="",t=0;for(t=0;t<=25;t++)e+=String.fromCharCode(t+65);for(t=0;t<=25;t++)e+=String.fromCharCode(t+97);for(t=0;t<10;t++)e+=t;return e+"+/="}(),wt=function(e){if(null==e)return"";var t,i,n,o,r,a,s,l="",c=0;for(e=function(e){if(null==e)return"";var t,i,n,o={},r={},a="",s="",l="",c=2,d=3,u=2,p="",h=0,v=0,g=String.fromCharCode;for(n=0;n>=1}else{for(i=1,t=0;t>=1}0==--c&&(c=Math.pow(2,u),u++),delete r[l]}else for(i=o[l],t=0;t>=1;0==--c&&(c=Math.pow(2,u),u++),o[s]=d++,l=String(a)}if(""!==l){if(Object.prototype.hasOwnProperty.call(r,l)){if(l.charCodeAt(0)<256){for(t=0;t>=1}else{for(i=1,t=0;t>=1}0==--c&&(c=Math.pow(2,u),u++),delete r[l]}else for(i=o[l],t=0;t>=1;0==--c&&(c=Math.pow(2,u),u++)}for(i=2,t=0;t>=1;for(;;){if(h<<=1,15==v){p+=g(h);break}v++}return p}(e);c<2*e.length;)c%2==0?(t=e.charCodeAt(c/2)>>8,i=255&e.charCodeAt(c/2),n=c/2+1>8:NaN):(t=255&e.charCodeAt((c-1)/2),(c+1)/2>8,n=255&e.charCodeAt((c+1)/2)):i=n=NaN),c+=3,o=t>>2,r=(3&t)<<4|i>>4,a=(15&i)<<2|n>>6,s=63&n,isNaN(i)?a=s=64:isNaN(n)&&(s=64),l=l+mt.charAt(o)+mt.charAt(r)+mt.charAt(a)+mt.charAt(s);return l},kt=k("fireRequest"),Ct=k("dropRequestDueToOptOut"),xt=k("addUseIPToRequest"),Pt=k("addARPToRequest"),St=function(){function e(){t(this,e),this.networkRetryCount=0,this.minDelayFrequency=0}return n(e,[{key:"getDelayFrequency",value:function(){if(this.logger.debug("Network retry #"+this.networkRetryCount),this.networkRetryCount<10)return this.logger.debug(this.account.id,"Failure count is "+this.networkRetryCount+". Setting delay frequency to 1s"),this.minDelayFrequency=ve,this.minDelayFrequency;if(null==this.account.region)return this.logger.debug(this.account.id,"Setting delay frequency to 1s"),ve;var e=1e3*(Math.floor(10*Math.random())+1);return this.minDelayFrequency+=e,this.minDelayFrequency<6e5?(this.logger.debug(this.account.id,"Setting delay frequency to "+this.minDelayFrequency),this.minDelayFrequency):(this.minDelayFrequency=ve,this.logger.debug(this.account.id,"Setting delay frequency to "+this.minDelayFrequency),this.minDelayFrequency)}}],[{key:"fireRequest",value:function(e,t,i,n){C(this,kt)[kt](e,1,t,i,n)}}]),e}();St.logger=void 0,St.device=void 0,St.account=void 0,Object.defineProperty(St,kt,{value:function(e,t,i,n,o){var r,a,s=this;if(C(this,Ct)[Ct]())this.logger.debug("req dropped due to optout cookie: "+this.device.gcookie);else{if(Ie(this.device.gcookie)||(De.blockRequest=!0),o&&o===ge)!Ie(this.device.gcookie)&&De.globalCache.RESP_N url: "+e)}}}),Object.defineProperty(St,Ct,{value:function(){return!De.isOptInRequest&&Ie(this.device.gcookie)&&ke(this.device.gcookie)?":OO"===this.device.gcookie.slice(-3):(De.isOptInRequest=!1,!1)}}),Object.defineProperty(St,xt,{value:function(e){var t=je.getMetaProp(Z);return"boolean"!=typeof t&&(t=!1),ft(e,Z,t?"true":"false")}}),Object.defineProperty(St,Pt,{value:function(e,t){if(!0===t){var i={skipResARP:!0};return ft(e,"arp",yt(JSON.stringify(i),this.logger))}return je._isLocalStorageSupported()&&void 0!==localStorage.getItem(K)&&null!==localStorage.getItem(K)?ft(e,"arp",yt(JSON.stringify(je.readFromLSorCookie(K)),this.logger)):e}});var Ot=function(){var e={};if(je._isLocalStorageSupported()){var t=je.read(U);null!=t?(t=JSON.parse(decodeURIComponent(t).replace(R,'"'))).hasOwnProperty("global")?e.wp=t:e=t:e={}}return e},It=function(e){if(je._isLocalStorageSupported()){var t=a(a({},Ot()),e),i=JSON.stringify(t);je.save(U,encodeURIComponent(i)),_t()}},_t=function(){if(je._isLocalStorageSupported()){var e=je.read(N);if(Ie(e))try{e=JSON.parse(decodeURIComponent(je.read(N)));var t=je.read(F)?JSON.parse(decodeURIComponent(je.read(F))):{};if(e&&je._isLocalStorageSupported()){var i={},n=Ot();Object.keys(n).forEach((function(r){var s=e in t&&Object.keys(t[e]).length&&t[e][r]?t[e][r]:{},l=n[r].global,c=Ae(),d=n[r][c];if(void 0!==l){var u=Object.keys(l);for(var p in u){var h=[];if(u.hasOwnProperty(p)){var v=0,g=0,f=u[p];if("tc"===f)continue;void 0!==d&&void 0!==d[f]&&(v=d[f]),void 0!==l&&void 0!==l[f]&&(g=l[f]),h=[f,v,g],s[f]=h}}}i=a(a({},i),{},o({},r,s))})),t[e]=i,je.save(F,encodeURIComponent(JSON.stringify(t)))}}catch(e){console.error("Invalid clevertap Id "+e)}}},Et=function(){var e=JSON.parse(decodeURIComponent(je.read(N))),t={};if(je._isLocalStorageSupported()){t=Ot();var i=je.read(F),n=i?decodeURIComponent(i):null,o=n?JSON.parse(n):null,r=e&&null!=i&&o&&o[e]&&o[e].wp?Object.values(o[e].wp):[],a=e&&null!=i&&o&&o[e]&&o[e].wi?Object.values(o[e].wi):[],s=Ae(),l=0,c=0;return t.wp&&t.wp[s]&&"undefined"!==t.wp[s].tc&&(l=t.wp[s].tc),t.wi&&t.wi[s]&&"undefined"!==t.wi[s].tc&&(c=t.wi[s].tc),{wmp:l,wimp:c,tlc:r,witlc:a}}},At=function(e,t){var i=t.logger,n=!1;if(Ce(e))for(var o in e)if(e.hasOwnProperty(o)){n=!0;var r=e[o];if(null==r){delete e[o];continue}"Gender"!==o||r.match(/^M$|^F$/)||(n=!1,i.error(Qe)),"Employed"!==o||r.match(/^Y$|^N$/)||(n=!1,i.error(Xe)),"Married"!==o||r.match(/^Y$|^N$/)||(n=!1,i.error(et)),"Education"!==o||r.match(/^School$|^College$|^Graduate$/)||(n=!1,i.error(tt)),"Age"===o&&null!=r&&(Se(r)?e.Age=+r:(n=!1,i.error(it))),"DOB"===o?(/^\$D_/.test(r)&&11===(r+"").length||xe(r)||(n=!1,i.error(nt)),xe(r)&&(e[o]=Le(r))):xe(r)&&(e[o]=Le(r)),"Phone"!==o||Pe(r)||(r.length>8&&"+"===r.charAt(0)?(r=r.substring(1,r.length),Se(r)?e.Phone=+r:(n=!1,i.error(rt+". Removed."))):(n=!1,i.error(rt+". Removed."))),n||delete e[o]}return n},Mt=function(e){var t={};t.Name=e.name,null!=e.id&&(t.FBID=e.id+""),"male"===e.gender?t.Gender="M":"female"===e.gender?t.Gender="F":t.Gender="O";null!=e.relationship_status&&(t.Married="N","Married"===e.relationship_status&&(t.Married="Y"));var i=function(e){if(null!=e){for(var t="",i="",n=0;n0?"Y":"N",null!=e.email&&(t.Email=e.email),null!=e.birthday){var o=e.birthday.split("/");t.DOB=Te(o[2]+o[0]+o[1])}return t},Lt=function(e,t){var i=t.logger,n={};if(null!=e.displayName&&(n.Name=e.displayName),null!=e.id&&(n.GPID=e.id+""),null!=e.gender&&("male"===e.gender?n.Gender="M":"female"===e.gender?n.Gender="F":"other"===e.gender&&(n.Gender="O")),null!=e.image&&!1===e.image.isDefault&&(n.Photo=e.image.url.split("?sz")[0]),null!=e.emails)for(var o=0;o0)for(var t in e)if(e.hasOwnProperty(t)){var i=e[t],n={},o=void 0;if(null!=i.Site){if(o=i.Site,Pe(o)||!At(o,{logger:C(this,Bt)[Bt]}))return}else if(null!=i.Facebook){var r=i.Facebook;Pe(r)||r.error||(o=Mt(r))}else if(null!=i["Google Plus"]){var a=i["Google Plus"];Pe(a)||a.error||(o=Lt(a,{logger:C(this,Bt)[Bt]}))}if(null!=o&&!Pe(o)){n.type="profile",null==o.tz&&(o.tz=(new Date).toString().match(/([A-Z]+[\+-][0-9]+)/)[1]),n.profile=o,Tt(o,!0),n=C(this,Nt)[Nt].addSystemDataToObject(n,void 0),C(this,Nt)[Nt].addFlags(n);var s=yt(JSON.stringify(n),C(this,Bt)[Bt]),l=C(this,zt)[zt].dataPostURL;l=ft(l,"type",Y),l=ft(l,"d",s),C(this,Nt)[Nt].saveAndFireRequest(l,De.blockRequest)}}},Kt=k("request"),Ht=k("logger"),Gt=k("account"),Jt=k("session"),Zt=k("oldValues"),$t=k("device"),Yt=k("processOUL"),Qt=k("handleCookieFromCache"),Xt=k("deleteUser"),ei=k("processLoginArray"),ti=function(e){s(o,e);var i=g(o);function o(e,n){var r,a=e.request,s=e.account,l=e.session,c=e.logger,d=e.device;return t(this,o),r=i.call(this),Object.defineProperty(h(r),ei,{value:ri}),Object.defineProperty(h(r),Xt,{value:oi}),Object.defineProperty(h(r),Qt,{value:ni}),Object.defineProperty(h(r),Yt,{value:ii}),Object.defineProperty(h(r),Kt,{writable:!0,value:void 0}),Object.defineProperty(h(r),Ht,{writable:!0,value:void 0}),Object.defineProperty(h(r),Gt,{writable:!0,value:void 0}),Object.defineProperty(h(r),Jt,{writable:!0,value:void 0}),Object.defineProperty(h(r),Zt,{writable:!0,value:void 0}),Object.defineProperty(h(r),$t,{writable:!0,value:void 0}),C(h(r),Kt)[Kt]=a,C(h(r),Gt)[Gt]=s,C(h(r),Jt)[Jt]=l,C(h(r),Ht)[Ht]=c,C(h(r),Zt)[Zt]=n,C(h(r),$t)[$t]=d,r}return n(o,[{key:"clear",value:function(){C(this,Ht)[Ht].debug("clear called. Reset flag has been set."),C(this,Xt)[Xt](),je.setMetaProp(j,!0)}},{key:"push",value:function(){for(var e=arguments.length,t=new Array(e),i=0;i0)for(var o in e)if(e.hasOwnProperty(o)){var r=e[o],a={},s=void 0;if(null!=r.Site){if(s=r.Site,Pe(s)||!At(s,{logger:C(this,Ht)[Ht]}))return}else if(null!=r.Facebook){var l=r.Facebook;Pe(l)||l.error||(s=Mt(l))}else if(null!=r["Google Plus"]){var c=r["Google Plus"];Pe(c)&&!c.error&&(s=Lt(c,{logger:C(this,Ht)[Ht]}))}if(null!=s&&!Pe(s)){a.type="profile",null==s.tz&&(s.tz=(new Date).toString().match(/([A-Z]+[\+-][0-9]+)/)[1]),a.profile=s;var d=[];je._isLocalStorageSupported()&&(s.Identity&&d.push(s.Identity),s.Email&&d.push(s.Email),s.GPID&&d.push("GP:"+s.GPID),s.FBID&&d.push("FB:"+s.FBID),d.length>0&&n(d)),Tt(s,!0),a=C(this,Kt)[Kt].addSystemDataToObject(a,void 0),C(this,Kt)[Kt].addFlags(a),i&&(a.isOUL=!0);var u=yt(JSON.stringify(a),C(this,Ht)[Ht]),p=C(this,Gt)[Gt].dataPostURL;p=ft(p,"type",Y),p=ft(p,"d",u),C(this,Kt)[Kt].saveAndFireRequest(p,De.blockRequest,i)}}},ni=function(){De.blockRequest=!1,console.debug("Block request is false"),je._isLocalStorageSupported()&&(delete localStorage.WZRK_PR,delete localStorage.WZRK_EV,delete localStorage.WZRK_META,delete localStorage.WZRK_ARP,delete localStorage.WZRK_CAMP,delete localStorage.WZRK_CHARGED_ID),je.removeCookie(U,bt()),je.removeCookie(C(this,Jt)[Jt].cookieName,De.broadDomain),je.removeCookie(K,De.broadDomain),C(this,Jt)[Jt].setSessionCookieObject("")},oi=function(){De.blockRequest=!0,C(this,Ht)[Ht].debug("Block request is true"),De.globalCache={gcookie:null,REQ_N:0,RESP_N:0},je._isLocalStorageSupported()&&(delete localStorage.WZRK_G,delete localStorage.WZRK_K,delete localStorage.WZRK_PR,delete localStorage.WZRK_EV,delete localStorage.WZRK_META,delete localStorage.WZRK_ARP,delete localStorage.WZRK_CAMP,delete localStorage.WZRK_CHARGED_ID),je.removeCookie(N,De.broadDomain),je.removeCookie(U,bt()),je.removeCookie(z,bt()),je.removeCookie(C(this,Jt)[Jt].cookieName,De.broadDomain),je.removeCookie(K,De.broadDomain),C(this,$t)[$t].gcookie=null,C(this,Jt)[Jt].setSessionCookieObject("")},ri=function(e){if(Array.isArray(e)&&e.length>0){var t=e.pop();if(null!=t&&Ce(t)&&(null!=t.Site&&Object.keys(t.Site).length>0||null!=t.Facebook&&Object.keys(t.Facebook).length>0||null!=t["Google Plus"]&&Object.keys(t["Google Plus"]).length>0)){je.setInstantDeleteFlagInK();try{C(this,Yt)[Yt]([t])}catch(e){C(this,Ht)[Ht].debug(e)}}else C(this,Ht)[Ht].error("Profile object is in incorrect format")}},ai=function(e){s(o,e);var i=g(o);function o(){var e;return t(this,o),(e=i.call(this))._details=null,e.shadow=null,e.shadow=e.attachShadow({mode:"open"}),e}return n(o,[{key:"renderBanner",value:function(){var e=this;this.shadow.innerHTML=this.getBannerContent(),!1!==this.trackClick&&this.addEventListener("click",(function(){var t=e.details.onClick;t&&(e.details.window?window.open(t,"_blank"):window.parent.location.href=t),window.clevertap.renderNotificationClicked({msgId:e.msgId,pivotId:e.pivotId})})),window.clevertap.renderNotificationViewed({msgId:this.msgId,pivotId:this.pivotId})}},{key:"getBannerContent",value:function(){return'\n \n \n ")}},{key:"details",get:function(){return this._details||""},set:function(e){null===this._details&&(this._details=e,this.renderBanner())}}]),o}(p(HTMLElement)),si=function(e){s(o,e);var i=g(o);function o(){var e;return t(this,o),(e=i.call(this))._target=null,e._carousel=null,e.shadow=null,e.slides=0,e.previouslySelectedItem=-1,e.selectedItem=1,e.autoSlide=null,e.stopAutoSlideTimeout=null,e.shadow=e.attachShadow({mode:"open"}),void 0===customElements.get("ct-web-personalisation-banner")&&customElements.define("ct-web-personalisation-banner",ai),e}return n(o,[{key:"renderCarousel",value:function(){this.slides=this.details.length,this.shadow.innerHTML=this.getStyles();var e=this.getCarouselContent();this.display.showNavBtns&&e.insertAdjacentHTML("beforeend",this.display.navBtnsHtml),this.display.showNavArrows&&(e.insertAdjacentHTML("beforeend",this.display.leftNavArrowHtml),e.insertAdjacentHTML("beforeend",this.display.rightNavArrowHtml)),this._carousel=e,this.shadow.appendChild(e),this.setupClick(),this.updateSelectedItem(),this.startAutoSlide(),this.setupOnHover(),window.clevertap.renderNotificationViewed({msgId:this.target.wzrk_id,pivotId:this.target.wzrk_pivot})}},{key:"setupClick",value:function(){var e=this;this._carousel.addEventListener("click",(function(t){var i=t.target.id;if(i.startsWith("carousel__button")){var n=+i.split("-")[1];n!==e.selectedItem&&(e.previouslySelectedItem=e.selectedItem,e.selectedItem=n,e.updateSelectedItem(),e.startAutoSlide())}else if(i.startsWith("carousel__arrow"))i.endsWith("right")?e.goToNext():e.goToPrev(),e.startAutoSlide();else if(i.indexOf("-")>-1){var o=+i.split("-")[1],r=o-1;window.parent.clevertap&&window.clevertap.renderNotificationClicked({msgId:e.target.wzrk_id,pivotId:e.target.wzrk_pivot,wzrk_slideNo:o});var a=e.details[r].onClick;""!==a&&(e.details[r].window?window.open(a,"_blank"):window.location.href=a)}}))}},{key:"setupOnHover",value:function(){var e=this;this._carousel.addEventListener("mouseenter",(function(t){e.stopAutoSlideTimeout=setTimeout((function(){e.autoSlide=clearInterval(e.autoSlide)}),500)})),this._carousel.addEventListener("mouseleave",(function(t){clearTimeout(e.stopAutoSlideTimeout),void 0===e.autoSlide&&e.startAutoSlide()}))}},{key:"getCarouselContent",value:function(){var e=document.createElement("div");return e.setAttribute("class","carousel"),this.details.forEach((function(t,i){var n=document.createElement("ct-web-personalisation-banner");n.classList.add("carousel__item"),n.trackClick=!1,n.setAttribute("id","carousel__item-".concat(i+1)),n.details=t,e.appendChild(n)})),e}},{key:"getStyles",value:function(){var e,t;return"\n \n ")}},{key:"updateSelectedItem",value:function(){if(-1!==this.previouslySelectedItem){var e=this.shadow.getElementById("carousel__item-".concat(this.previouslySelectedItem)),t=this.shadow.getElementById("carousel__button-".concat(this.previouslySelectedItem));e.classList.remove("carousel__item--selected"),t&&t.classList.remove("carousel__button--selected")}var i=this.shadow.getElementById("carousel__item-".concat(this.selectedItem)),n=this.shadow.getElementById("carousel__button-".concat(this.selectedItem));i.classList.add("carousel__item--selected"),n&&n.classList.add("carousel__button--selected")}},{key:"startAutoSlide",value:function(){var e=this;clearInterval(this.autoSlide),this.autoSlide=setInterval((function(){e.goToNext()}),this.display.sliderTime?1e3*this.display.sliderTime:3e3)}},{key:"goToNext",value:function(){this.goTo(this.selectedItem,(this.selectedItem+1)%this.slides)}},{key:"goToPrev",value:function(){this.goTo(this.selectedItem,this.selectedItem-1)}},{key:"goTo",value:function(e,t){this.previouslySelectedItem=e,this.selectedItem=t,0===t&&(this.selectedItem=this.slides),this.updateSelectedItem()}},{key:"target",get:function(){return this._target||""},set:function(e){null===this._target&&(this._target=e,this.renderCarousel())}},{key:"details",get:function(){return this.target.display.details}},{key:"display",get:function(){return this.target.display}}]),o}(p(HTMLElement)),li=function(e){s(o,e);var i=g(o);function o(){var e;return t(this,o),(e=i.call(this))._target=null,e._session=null,e.shadow=null,e.popup=null,e.container=null,e.resizeObserver=null,e.shadow=e.attachShadow({mode:"open"}),e}return n(o,[{key:"renderImageOnlyPopup",value:function(){var e=this,t=this.target.wzrk_id.split("_")[0],i=this.session.sessionId;this.shadow.innerHTML=this.getImageOnlyPopupContent(),this.popup=this.shadowRoot.getElementById("imageOnlyPopup"),this.container=this.shadowRoot.getElementById("container"),this.closeIcon=this.shadowRoot.getElementById("close"),this.popup.addEventListener("load",this.updateImageAndContainerWidth()),this.resizeObserver=new ResizeObserver((function(){return e.handleResize(e.popup,e.container)})),this.resizeObserver.observe(this.popup),this.closeIcon.addEventListener("click",(function(){if(e.resizeObserver.unobserve(e.popup),document.getElementById("wzrkImageOnlyDiv").style.display="none",e.remove(),null!=t&&"-1"!==t&&je._isLocalStorageSupported()){var n=Ot(),o=n.wp[i];null==o&&(o={},n[i]=o),o[t]="dnd",It(n)}})),window.clevertap.renderNotificationViewed({msgId:this.msgId,pivotId:this.pivotId}),this.onClickUrl&&this.popup.addEventListener("click",(function(){e.target.display.window?window.open(e.onClickUrl,"_blank"):window.parent.location.href=e.onClickUrl,window.clevertap.renderNotificationClicked({msgId:e.msgId,pivotId:e.pivotId})}))}},{key:"handleResize",value:function(e,t){var i=this.getRenderedImageWidth(e);t.style.setProperty("width","".concat(i,"px"))}},{key:"getImageOnlyPopupContent",value:function(){return"\n ".concat(this.target.msgContent.css,"\n ").concat(this.target.msgContent.html,"\n ")}},{key:"updateImageAndContainerWidth",value:function(){var e=this;return function(){var t=e.getRenderedImageWidth(e.popup);e.popup.style.setProperty("width","".concat(t,"px")),e.container.style.setProperty("width","".concat(t,"px")),e.container.style.setProperty("height","auto"),e.container.style.setProperty("position","fixed"),e.popup.style.setProperty("visibility","visible"),e.closeIcon.style.setProperty("visibility","visible"),document.getElementById("wzrkImageOnlyDiv").style.visibility="visible"}}},{key:"getRenderedImageWidth",value:function(e){var t=e.naturalWidth/e.naturalHeight;return e.height*t}},{key:"target",get:function(){return this._target||""},set:function(e){null===this._target&&(this._target=e,this.renderImageOnlyPopup())}},{key:"session",get:function(){return this._session||""},set:function(e){this._session=e}},{key:"msgId",get:function(){return this.target.wzrk_id}},{key:"pivotId",get:function(){return this.target.wzrk_pivot}},{key:"onClickUrl",get:function(){return this.target.display.onClickUrl}}]),o}(p(HTMLElement)),ci=function(e){s(o,e);var i=g(o);function o(e,n){var r;return t(this,o),(r=i.call(this)).wrapper=null,r.snackBar=null,r.shadow=r.attachShadow({mode:"open"}),r.config=e,r.message=n,r.renderMessage(n),r}return n(o,[{key:"createEl",value:function(e,t,i){var n=document.createElement(e);return n.setAttribute("id",t),n.setAttribute("part",i||t),n}},{key:"renderMessage",value:function(e){switch(this.wrapper=this.createEl("div","messageWrapper"),e.templateType){case"text-only":case"text-with-icon":case"text-with-icon-and-image":var t=this.prepareBasicMessage(e.msg[0]);this.wrapper.appendChild(t)}var i=this.createEl("div","timeStamp");if(i.innerHTML="".concat(mi(e.id.split("_")[1]),""),!e.viewed){var n=this.createEl("span","unreadMarker");i.appendChild(n)}this.wrapper.appendChild(i),this.shadow.appendChild(this.wrapper)}},{key:"prepareBasicMessage",value:function(e){var t=this.createEl("div","message");if(e.imageUrl){var i=this.addImage(e.imageUrl,"mainImg");t.appendChild(i)}var n=this.createEl("div","iconTitleDescWrapper");if(e.iconUrl){var o=this.addImage(e.iconUrl,"iconImg");n.appendChild(o)}var r=this.createEl("div","titleDescWrapper");if(e.title){var a=this.createEl("div","title");a.innerText=e.title,r.appendChild(a)}if(e.description){var s=this.createEl("div","description");s.innerText=e.description,r.appendChild(s)}if((e.title||e.description)&&n.appendChild(r),(e.iconUrl||e.title||e.description)&&t.appendChild(n),e.buttons&&e.buttons.length){var l=this.addButtons(e.buttons);t.appendChild(l)}return t}},{key:"addButtons",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=this.createEl("div","buttonsContainer"),n=!1;return t.forEach((function(t,o){var r=e.createEl("button","button-".concat(o),"button");r.innerText=t.text,o>0&&(r.style.cssText+="margin-left: 2px;"),"copy"===t.action&&(n=!0),i.appendChild(r)})),n&&this.addSnackbar(i),i}},{key:"addSnackbar",value:function(e){this.snackBar=this.createEl("div","snackbar-".concat(this.campaignId),"snackbar"),this.snackBar.innerHTML=Ci;var t=this.createEl("span","snackbar-msg-".concat(this.campaignId),"snackbar-msg");t.innerText="Copied to clipboard",this.snackBar.appendChild(t),e.appendChild(this.snackBar)}},{key:"addImage",value:function(e,t){var i=this.createEl("div","".concat(t,"Container")),n=this.createEl("img",t);return n.setAttribute("src",e),n.setAttribute("loading","lazy"),i.appendChild(n),i}},{key:"raiseClickedEvent",value:function(e,t){switch(this.message.templateType){case"text-only":case"text-with-icon":case"text-with-icon-and-image":this.raiseClickedForBasicTemplates(e,t)}}},{key:"raiseClickedForBasicTemplates",value:function(e,t){var i=this,n=this.message.msg[0],o={msgId:this.campaignId,pivotId:this.pivotId};if("BUTTON"===e.tagName){var r=e.id.split("-")[1],a=n.buttons[r];o.kv={wzrk_c2a:a.text},"url"===a.action?a.openUrlInNewTab?window.open(a.url,"_blank"):window.location=a.url:"copy"===a.action&&(window.focus(),navigator.clipboard.writeText(a.clipboardText),this.snackBar.style.setProperty("display","flex","important"),setTimeout((function(){i.snackBar.style.setProperty("display","none","important")}),2e3))}else"CT-INBOX-MESSAGE"===e.tagName&&n.onClickUrl&&(n.openUrlInNewTab?window.open(n.onClickUrl,"_blank"):window.location=n.onClickUrl);t?console.log("Notifiction clicked event will be raised at run time with payload ::",o):window.clevertap.renderNotificationClicked(o)}},{key:"pivotId",get:function(){return this.message.wzrk_pivot}},{key:"campaignId",get:function(){return this.message.wzrk_id}}]),o}(p(HTMLElement)),di=function(e){s(o,e);var i=g(o);function o(e){var n;return t(this,o),(n=i.call(this)).isInboxOpen=!1,n.isInboxFromFlutter=!1,n.selectedCategory=null,n.unviewedMessages={},n.unviewedCounter=0,n.isPreview=!1,n.inboxConfigForPreview={},n.inboxSelector=null,n.inbox=null,n.emptyInboxMsg=null,n.inboxCard=null,n.unviewedBadge=null,n.observer=null,n.selectedCategoryRef=null,n.addClickListenerOnDocument=function(e){if(e.composedPath().includes(n.inbox)){var t=e.path||e.composedPath&&e.composedPath();if(t.length){var i=t[0].id;if("closeInbox"===i)n.toggleInbox();else if(i.startsWith("category-"))n.prevCategoryRef=n.selectedCategoryRef,n.selectedCategoryRef=t[0],n.updateActiveCategory(t[0].innerText);else{var o=t.filter((function(e){var t;return(null===(t=e.id)||void 0===t?void 0:t.startsWith("button-"))||"CT-INBOX-MESSAGE"===e.tagName}));o.length&&o[o.length-1].raiseClickedEvent(o[0],n.isPreview)}}}else(n.inboxSelector.contains(e.target)||n.isInboxOpen)&&(n.isInboxFromFlutter?n.isInboxFromFlutter=!1:n.toggleInbox(e))},n.setBadgeStyle=function(e){null!==n.unviewedBadge&&(n.unviewedBadge.innerText=e>9?"9+":e,n.unviewedBadge.style.display=e>0?"flex":"none")},n.logger=e,n.shadow=n.attachShadow({mode:"open"}),n}return n(o,[{key:"connectedCallback",value:function(){this.init()}},{key:"init",value:function(){this.config=this.isPreview?this.inboxConfigForPreview:je.readFromLSorCookie(pe)||{},0!==Object.keys(this.config).length&&(this.inboxSelector=document.getElementById(this.config.inboxSelector),null!==this.inboxSelector&&(this.config.styles.notificationsBadge?this.addUnviewedBadge():this.unviewedBadge&&this.unviewedBadge.remove(),this.createinbox(),document.removeEventListener("click",this.addClickListenerOnDocument),document.addEventListener("click",this.addClickListenerOnDocument),this.config.categories.length&&this.updateActiveCategory(this.selectedCategoryRef.innerText),this.shadow.innerHTML=this.getInboxStyles(),this.shadow.appendChild(this.inbox)))}},{key:"addMsgsToInboxFromLS",value:function(){var e=this,t=this.deleteExpiredAndGetUnexpiredMsgs(!1),i=t?Object.keys(t):[];0!==i.length&&(i.forEach((function(i){t[i].viewed||(e.unviewedMessages[i]=t[i],e.unviewedCounter++)})),this.buildUIForMessages(t),this.updateUnviewedBadgeCounter())}},{key:"deleteExpiredAndGetUnexpiredMsgs",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=vi(),i=Math.floor(Date.now()/1e3);for(var n in t)if(t[n].wzrk_ttl&&t[n].wzrk_ttl>0&&t[n].wzrk_ttl0&&(t=Object.values(t).sort((function(e,t){return t.date-e.date})).reduce((function(e,t){return e[t.id]=t,e}),{})),gi(t),t}},{key:"updateInboxMessages",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=this.deleteExpiredAndGetUnexpiredMsgs(),n=Date.now(),o={};t.forEach((function(t,r){var a="".concat(t.wzrk_id.split("_")[0],"_").concat(Date.now());t.id=a,t.date=n-r,t.viewed=0,i[a]=t,o[a]=t,e.unviewedMessages[a]=t,e.unviewedCounter++})),gi(i),this.buildUIForMessages(o),this.updateUnviewedBadgeCounter()}},{key:"createEl",value:function(e,t,i){var n=document.createElement(e);return n.setAttribute("id",t),n.setAttribute("part",i||t),n}},{key:"addUnviewedBadge",value:function(){var e=this;this.unviewedBadge||(this.unviewedBadge=this.createEl("div","unviewedBadge"),this.unviewedBadge.style.cssText="display: none; position: absolute; height: 16px; width: 26px; border-radius: 8px; background-color: ".concat(this.config.styles.notificationsBadge.backgroundColor,"; font-size: 12px; color: ").concat(this.config.styles.notificationsBadge.textColor,"; font-weight: bold; align-items: center; justify-content: center;"),document.body.appendChild(this.unviewedBadge)),this.updateUnviewedBadgePosition(),window.addEventListener("resize",(function(){e.updateUnviewedBadgePosition()}))}},{key:"updateUnviewedBadgePosition",value:function(){var e=this.inboxSelector.getBoundingClientRect(),t=e.top,i=e.right;this.unviewedBadge.style.top="".concat(t-8,"px"),this.unviewedBadge.style.left="".concat(i-8,"px")}},{key:"createinbox",value:function(){var e=this;this.inbox=this.createEl("div","inbox");var t=this.createEl("div","header"),i=this.createEl("div","headerTitle");i.innerText=this.config.title;var n=this.createEl("div","closeInbox");if(n.innerHTML="×",t.appendChild(i),t.appendChild(n),this.inbox.appendChild(t),this.config.categories.length){var o=this.createCategories();this.inbox.appendChild(o)}this.inboxCard=this.createEl("div","inboxCard"),this.inbox.appendChild(this.inboxCard),this.emptyInboxMsg=this.createEl("div","emptyInboxMsg"),this.emptyInboxMsg.innerText="All messages will be displayed here.",this.inboxCard.appendChild(this.emptyInboxMsg);var r={root:this.inboxCard,rootMargin:"0px",threshold:.5};this.observer=new IntersectionObserver((function(t,i){e.handleMessageViewed(t)}),r),this.addMsgsToInboxFromLS()}},{key:"createCategories",value:function(){var e=this,t=this.createEl("div","categoriesContainer"),i=this.createEl("div","leftArrow");i.innerHTML=ki,i.children[0].style="transform: rotate(180deg)",i.addEventListener("click",(function(){e.shadowRoot.getElementById("categoriesWrapper").scrollBy(-70,0)})),t.appendChild(i);var n=this.createEl("div","categoriesWrapper");["All"].concat(f(this.config.categories)).forEach((function(t,i){var o=e.createEl("div","category-".concat(i),"category");o.innerText=t,0===i&&(e.selectedCategoryRef=o),n.appendChild(o)})),t.appendChild(n);var o=this.createEl("div","rightArrow");o.innerHTML=ki,o.addEventListener("click",(function(){e.shadowRoot.getElementById("categoriesWrapper").scrollBy(70,0)})),t.appendChild(o);var r={root:t,threshold:.9},a=n.children[0],s=n.children[this.config.categories.length];return new IntersectionObserver((function(t){e.categoryObserverCb(i,t[0].intersectionRatio>=.9)}),r).observe(a),new IntersectionObserver((function(t){e.categoryObserverCb(o,t[0].intersectionRatio>=.9)}),r).observe(s),t}},{key:"categoryObserverCb",value:function(e,t){e&&(e.style.display=t?"none":"flex")}},{key:"updateActiveCategory",value:function(e){var t=this;this.selectedCategory=e,this.inboxCard.scrollTop=0;var i=0;this.prevCategoryRef&&this.prevCategoryRef.setAttribute("selected","false"),this.selectedCategoryRef.setAttribute("selected","true"),this.inboxCard.childNodes.forEach((function(e){"emptyInboxMsg"!==e.getAttribute("id")&&(e.style.display="All"===t.selectedCategory||e.getAttribute("category")===t.selectedCategory?"block":"none","block"===e.style.display&&i++)})),0===i?(this.emptyInboxMsg.innerText="".concat(e," messages will be displayed here."),this.emptyInboxMsg.style.display="block"):this.emptyInboxMsg.style.display="none"}},{key:"buildUIForMessages",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!this.isPreview&&this.updateTSForRenderedMsgs(),this.inboxCard.scrollTop=0;var i,n=null!==(e=this.config.maxMsgsInInbox)&&void 0!==e?e:15,o=this.inboxCard.firstChild,r=Object.values(t).sort((function(e,t){return t.date-e.date})).map((function(e){return e.id})),a=m(r);try{for(a.s();!(i=a.n()).done;){var s=i.value,l=new ci(this.config,t[s]);l.setAttribute("id",t[s].id),l.setAttribute("pivot",t[s].wzrk_pivot),l.setAttribute("part","ct-inbox-message"),this.config.categories.length>0?(l.setAttribute("category",t[s].tags[0]||""),l.style.display="All"===this.selectedCategory||t[s].category===this.selectedCategory?"block":"none"):l.style.display="block",this.inboxCard.insertBefore(l,o),this.observer.observe(l)}}catch(e){a.e(e)}finally{a.f()}for(var c=this.inboxCard.querySelectorAll("ct-inbox-message").length;c>n;){var d=this.inboxCard.querySelectorAll("ct-inbox-message");d.length>0&&d[d.length-1].remove(),c--}var u=this.inboxCard.querySelectorAll('ct-inbox-message[style*="display: block"]').length;this.emptyInboxMsg.style.display=u?"none":"block"}},{key:"handleMessageViewed",value:function(e){var t=this,i=!this.isPreview;this.isInboxOpen&&e.forEach((function(e){e.isIntersecting&&t.unviewedMessages.hasOwnProperty(e.target.id)&&0===e.target.message.viewed&&(e.target.message.viewed=1,i?(window.clevertap.renderNotificationViewed({msgId:e.target.campaignId,pivotId:e.target.pivotId}),t.updateMessageInLS(e.target.id,a(a({},e.target.message),{},{viewed:1})),setTimeout((function(){e.target.shadowRoot.getElementById("unreadMarker").style.display="none"}),1e3)):console.log("Notifiction viewed event will be raised at run time with payload ::",{msgId:e.target.campaignId,pivotId:e.target.pivotId}),t.unviewedCounter--,t.updateUnviewedBadgeCounter(),delete t.unviewedMessages[e.target.id])}))}},{key:"updateMessageInLS",value:function(e,t){if(!this.isPreview){var i=vi();i[e]=t,gi(i)}}},{key:"toggleInbox",value:function(e){this.isInboxOpen=!this.isInboxOpen,this.isInboxFromFlutter=!!(null==e?void 0:e.rect),this.isInboxOpen?(this.inboxCard.scrollTop=0,!this.isPreview&&this.deleteExpiredAndGetUnexpiredMsgs(),this.inbox.style.display="block",this.inbox.style.zIndex="2147483647",this.config.categories.length&&(this.selectedCategoryRef.setAttribute("selected","false"),this.selectedCategoryRef=this.shadowRoot.getElementById("category-0"),this.updateActiveCategory(this.selectedCategoryRef.innerText),this.shadowRoot.getElementById("categoriesWrapper").scrollLeft-=this.shadowRoot.getElementById("categoriesWrapper").scrollWidth),this.setInboxPosition(e)):this.inbox.style.display="none"}},{key:"setInboxPosition",value:function(e){var t=window.outerWidth,i=getComputedStyle(De.inbox),n=i.getPropertyValue("--inbox-top"),o=i.getPropertyValue("--inbox-bottom"),r=i.getPropertyValue("--inbox-left"),a=i.getPropertyValue("--inbox-right");if(t>481&&!(n||o||r||a)){var s=yi(e,this.inbox.clientHeight,this.inbox.clientWidth),l=s.xPos,c=s.yPos;this.inbox.style.top=c+"px",this.inbox.style.left=l+"px"}}},{key:"updateUnviewedBadgeCounter",value:function(){if(this.isPreview)this.setBadgeStyle(this.unviewedCounter);else{var e=0;this.inboxCard.querySelectorAll("ct-inbox-message").forEach((function(t){var i=vi();i[t.id]&&0===i[t.id].viewed&&e++})),this.setBadgeStyle(e)}}},{key:"updateTSForRenderedMsgs",value:function(){this.inboxCard.querySelectorAll("ct-inbox-message").forEach((function(e){var t=e.id.split("_")[1];e.shadow.getElementById("timeStamp").firstChild.innerText=mi(t)}))}},{key:"getInboxStyles",value:function(){var e=this.config.categories.length?64:16,t={panelBackgroundColor:this.config.styles.panelBackgroundColor,panelBorderColor:this.config.styles.panelBorderColor,headerBackgroundColor:this.config.styles.header.backgroundColor,headerTitleColor:this.config.styles.header.titleColor,closeIconColor:this.config.styles.closeIconColor,categoriesTabColor:this.config.styles.categories.tabColor,categoriesTitleColor:this.config.styles.categories.titleColor,selectedCategoryTabColor:this.config.styles.categories.selectedTab.tabColor,selectedCategoryTitleColor:this.config.styles.categories.selectedTab.titleColor,headerCategoryHeight:36+e};this.config.styles.categories.borderColor&&(t.categoriesBorderColor=this.config.styles.categories.borderColor),this.config.styles.categories.selectedTab.borderColor&&(t.selectedCategoryBorderColor=this.config.styles.categories.selectedTab.borderColor);var i,n,o,r,a,s,l,c,d,u,p,h,v,g,f,b,y,m,w,k,C,x=(n=(i=t).panelBackgroundColor,o=i.panelBorderColor,r=i.headerBackgroundColor,a=i.headerTitleColor,s=i.closeIconColor,l=i.categoriesTabColor,c=i.categoriesTitleColor,d=i.categoriesBorderColor,u=i.selectedCategoryTabColor,p=i.selectedCategoryTitleColor,h=i.selectedCategoryBorderColor,v=i.headerCategoryHeight,'\n \n ")),P=this.config.styles.cards;return x+(g={backgroundColor:P.backgroundColor,borderColor:P.borderColor,titleColor:P.titleColor,descriptionColor:P.descriptionColor,buttonColor:P.buttonColor,buttonTextColor:P.buttonTextColor,unreadMarkerColor:P.unreadMarkerColor},f=g.backgroundColor,b=g.borderColor,y=g.titleColor,m=g.descriptionColor,w=g.buttonColor,k=g.buttonTextColor,C=g.unreadMarkerColor,'\n \n "))}},{key:"incomingMessages",get:function(){return[]},set:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];e.length>0&&this.inbox&&this.updateInboxMessages(e)}},{key:"incomingMessagesForPreview",get:function(){return[]},set:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i={};t.length>0&&this.inbox&&(this.isPreview=!0,this.unviewedCounter=0,t.forEach((function(t){var n="".concat(t.wzrk_id.split("_")[0],"_").concat(Date.now());t.id=n,i[n]=t,e.unviewedMessages[n]=t,e.unviewedCounter++})),this.buildUIForMessages(i),this.updateUnviewedBadgeCounter())}}]),o}(p(HTMLElement)),ui=function(e){e.inbox_preview?De.inbox.incomingMessagesForPreview=e.inbox_notifs:De.inbox.incomingMessages=e},pi=function(e){bi(),De.inbox=new di({logger:e}),document.body.appendChild(De.inbox)},hi=function(e){var t=je.readFromLSorCookie(he)||{};if(Object.keys(t).length>0&&Object.keys(t)[0].includes("_")){var i={};return i[e]=t,je.saveToLSorCookie(he,i),i}return t},vi=function(){var e=JSON.parse(decodeURIComponent(je.read(N)));if(!Ie(e))return{};var t=hi(e);return t.hasOwnProperty(e)?t[e]:{}},gi=function(e){var t=JSON.parse(decodeURIComponent(je.read(N)));if(Ie(t)){var i=a(a({},hi(t)),{},o({},t,e));je.saveToLSorCookie(he,i)}},fi=function(e){return new Promise((function(t,i){if("complete"===document.readyState)pi(e),t();else{var n=je.readFromLSorCookie(pe)||{},o=function(){null===De.inbox&&pi(e),t()};window.addEventListener("load",(function(){if(document.getElementById(n.inboxSelector))o();else{var i=0;if(i<20)var r=setInterval((function(){document.getElementById(n.inboxSelector)?(o(),clearInterval(r),t()):i>=20&&(clearInterval(r),e.debug("Failed to add inbox")),i++}),500)}}))}}))},bi=function(){void 0===customElements.get("ct-web-inbox")&&(customElements.define("ct-web-inbox",di),customElements.define("ct-inbox-message",ci))},yi=function(e,t,i){var n,o,r=document.scrollingElement.scrollLeft,a=document.scrollingElement.scrollTop,s=window.innerWidth+r,l=window.innerHeight+a,c=e.rect||e.target.getBoundingClientRect(),d=c.x+r,u=c.y+a,p=c.left+r,h=c.right+r,v=c.top+a,g=c.bottom,f=c.height,b=c.width,y=!1,m=16;if(g+t<=l){var w=l-(g+t);o=w>=m?g+m:g+w}else if(v-t>=a){var k=v-t;o=k>=m?v-t-m:v-t-k}else y=!0,(o=u+f/2-t/2)l&&(o=l-t);if(y){var C=h+i;if(C<=s){n=h+(C+m<=s?m:s-C)}else{var x=p-i;n=x-(x-m>=r?m:x-r)}}else(n=d+b/2-i/2)s&&(n=h-i>=r?h-i:s-i);return{xPos:n,yPos:o}},mi=function(e){var t=Date.now(),i=Math.floor((t-e)/6e4);return i<5?"Just now":i<60?"".concat(i," minute").concat(i>1?"s":""," ago"):(i=Math.floor(i/60))<24?"".concat(i," hour").concat(i>1?"s":""," ago"):(i=Math.floor(i/24),"".concat(i," day").concat(i>1?"s":""," ago"))},wi=function(){return Object.keys(je.readFromLSorCookie(pe)||{}).length>0},ki='\n\n\n',Ci='\n\n\n',xi=function(e){var t=e.indexOf("