@customerio/cdp-analytics-browser 0.3.15 → 0.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd/740.js DELETED
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[740],{3740:function(e,t,n){n.d(t,{A:function(){return it}});var s=function(){function e(){this.callbacks={}}return e.prototype.on=function(e,t){var n=this.callbacks[e];n?n.push(t):this.callbacks[e]=[t]},e.prototype.off=function(e,t){var n=this.callbacks[e];if(n)if(t){var s=n.indexOf(t);-1!==s&&n.splice(s,1),0===n.length&&delete this.callbacks[e]}else delete this.callbacks[e]},e.prototype.dispatch=function(e,t){var n=this.callbacks[e];n&&n.forEach((function(e){return e(t)}))},e}();function i(e){it.config&&it.config.logging&&console.log("Gist: ".concat(e))}var a,o="gist.web.isPersistingSession";function r(e,t,n){void 0===n&&(n=null);var s=n;s||(s=new Date).setDate(s.getDate()+365);var i={value:t,expiry:s};d().setItem(e,JSON.stringify(i))}function c(e){return g(e)}function u(e){d().removeItem(e)}function l(){var e=sessionStorage.getItem(o);return null===e?(sessionStorage.setItem(o,"true"),!0):"true"===e}function d(){return l()?localStorage:sessionStorage}function g(e){if(!e)return null;try{var t=d().getItem(e);if(!t)return null;var n=JSON.parse(t);if(!n.expiry)return n.value;var s=new Date,a=new Date(n.expiry),o=e.startsWith("gist.web.message.broadcasts")&&!e.endsWith("shouldShow")&&!e.endsWith("numberOfTimesShown")||e.startsWith("gist.web.message.user")&&!e.endsWith("seen")&&!e.endsWith("state"),r=new Date(s.getTime()+366e4);return o&&a.getTime()>r.getTime()||s.getTime()>a.getTime()?(u(e),null):n.value}catch(t){i("Error checking key ".concat(e," for expiry: ").concat(t))}return null}var m=new Uint8Array(16);function p(){if(!a&&!(a="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return a(m)}var f=/^(?:[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;for(var h=function(e){return"string"==typeof e&&f.test(e)},v=[],w=0;w<256;++w)v.push((w+256).toString(16).substr(1));var y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(v[e[t+0]]+v[e[t+1]]+v[e[t+2]]+v[e[t+3]]+"-"+v[e[t+4]]+v[e[t+5]]+"-"+v[e[t+6]]+v[e[t+7]]+"-"+v[e[t+8]]+v[e[t+9]]+"-"+v[e[t+10]]+v[e[t+11]]+v[e[t+12]]+v[e[t+13]]+v[e[t+14]]+v[e[t+15]]).toLowerCase();if(!h(n))throw TypeError("Stringified UUID is invalid");return n};var b=function(e,t,n){var s=(e=e||{}).random||(e.rng||p)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=s[i];return t}return y(s)};const S="gist.web.userQueueUseSSE",I="gist.web.activeSSEConnection";let x,E=30;const $={RENDERER_HOST:"https://code.gist.build",ENGINE_API_ENDPOINT:{prod:"https://engine.api.gist.build",dev:"https://engine.api.dev.gist.build",local:"http://engine.api.local.gist.build:82"},GIST_QUEUE_API_ENDPOINT:{prod:"https://consumer.cloud.gist.build",dev:"https://consumer.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_QUEUE_REALTIME_API_ENDPOINT:{prod:"https://realtime.cloud.gist.build",dev:"https://realtime.cloud.dev.gist.build",local:"http://api.local.gist.build:3000"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/3.0",dev:"https://renderer.gist.build/3.0",local:"http://app.local.gist.build:8080/web"},getSdkId:function(){return x||(x=b()),x},useSSE:function(){return c(S)??!1},setUseSSEFlag:function(e){r(S,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection:function(){u(I)},setActiveSSEConnection:function(){r(I,$.getSdkId(),new Date((new Date).getTime()+$.getSSEHeartbeat()))},hasActiveSSEConnection:function(){return c(I)??!1},isSSEConnectionManagedBySDK:function(){return c(I)===$.getSdkId()},getSSEHeartbeat:function(){return 1e3*(E+5)},setSSEHeartbeat:function(e){e&&e>0&&(E=e)}};function k(){const e=$.GIST_QUEUE_API_ENDPOINT[it.config.env],t={"X-CIO-Site-Id":it.config.siteId,"X-CIO-Client-Platform":"web"},n=H();async function s(n,s={}){const i=e+n,a=new AbortController,o=setTimeout((()=>a.abort()),5e3);try{const e=await fetch(i,{method:s.method||"GET",headers:{...t,...s.headers||{}},body:s.method&&"GET"!==s.method.toUpperCase()?s.body:void 0,signal:a.signal});clearTimeout(o);const n=e.headers.get("content-type")?.includes("application/json"),r=n?await e.json():await e.text(),c=Object.fromEntries(e.headers.entries());if(e.status<200||e.status>=400)throw{response:{status:e.status,data:r,headers:c}};return{status:e.status,headers:c,data:r}}catch(e){throw clearTimeout(o),e.response||(e.response={status:0,data:e.message||"Unknown error"}),e}}return null!=n&&(t["X-Gist-Encoded-User-Token"]=n),s.post=(e,t={},n={})=>s(e,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...n.headers||{}}}),s}const C="gist.web.userLocale";var D=600,T=!1;const M="gist.web.userQueueNextPullCheck",q="gist.web.sessionId";async function R(){const e=U();var t;try{if(!T){T=!0;var n={"X-Gist-User-Anonymous":W(),"Content-Language":null!==c(C)?c(C):navigator.language};t=await k().post(`/api/v4/users?sessionId=${P()}`,{},{headers:n})}}catch(e){e.response?t=e.response:i(`Error getting user queue: ${e}`)}finally{T=!1}return e!==U()?(i("User token changed, clearing queue next pull check."),void u(M)):(function(e){if(e&&e.headers){var t=e.headers["x-gist-queue-polling-interval"];t&&t>0&&(D=t)}var n=new Date((new Date).getTime()+1e3*D);r(M,D,n)}(t),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();$.setUseSSEFlag(t)}(t),t)}function P(){var e=c(q);return e||(e=b()),r(q,e,new Date((new Date).getTime()+18e5)),e}const L="gist.web.userToken",N="gist.web.usingGuestUserToken",A="gist.web.guestUserToken";function W(){return null!==c(N)}function U(){return c(L)}function _(){if(null===U()){var e=c(A);null==e&&(e=b(),r(A,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),r(L,e),r(N,!0),i(`Using anonymous session with token: "${e}"`)}}async function O(){var e=U();return null===e?null:await async function(e){const t=(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t),s=Array.from(new Uint8Array(n));return s.map((e=>e.toString(16).padStart(2,"0"))).join("")}(e)}function H(){var e=U();return null===e?null:btoa(e)}async function z(e){try{return await k().post(`/api/v1/logs/queue/${e}`)}catch(e){return e.response}}function G(e){const t={isEmbedded:!1,elementId:"",hasRouteRule:!1,routeRule:"",position:"",hasPosition:!1,shouldScale:!1,campaignId:null,messageWidth:414,overlayColor:"#00000033",persistent:!1,exitClick:!1,hasCustomWidth:!1},n=e?.properties?.gist;return n?{isEmbedded:!!n.elementId,elementId:n.elementId||"",hasRouteRule:!!n.routeRuleWeb,routeRule:n.routeRuleWeb||"",position:n.position||"",hasPosition:!!n.position,shouldScale:!!n.scale,campaignId:n.campaignId??null,messageWidth:n.messageWidth>0?n.messageWidth:t.messageWidth,hasCustomWidth:n.messageWidth>0,overlayColor:n.overlayColor||t.overlayColor,persistent:!!n.persistent,exitClick:!!n.exitClick}:t}var V=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function j(e){if(document.getElementById(e))return;const t=document.createElement("div");if(t.id=e,"x-gist-top"===e)document.body.insertBefore(t,document.body.firstChild);else document.body.insertAdjacentElement("beforeend",t);i("Top & bottom elements injected into page")}const F=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function B(e){return it.currentMessages.find((t=>t.instanceId===e))}function J(e){return!!e&&it.currentMessages.some((t=>t.queueId===e))}function Q(e){return e?it.currentMessages.find((t=>t.elementId===e)):null}function X(e){it.currentMessages=it.currentMessages.filter((t=>t.instanceId!==e))}function K(e,t){X(e),it.currentMessages.push(t)}function Y(e){const t={topLeft:"x-gist-floating-top-left",topCenter:"x-gist-floating-top",topRight:"x-gist-floating-top-right",bottomLeft:"x-gist-floating-bottom-left",bottomCenter:"x-gist-floating-bottom",bottomRight:"x-gist-floating-bottom-right"};return e&&t[e]?t[e]:(i(`Invalid overlay position "${e}", defaulting to "topCenter"`),t.topCenter)}function Z(e,t){const n=(s=e).overlay?"modal":s.elementId&&V.includes(s.elementId)?"overlay":s.elementId?"inline":"modal";var s;const i=t.displayType;if(void 0===i)return!1;if(n!==i)return!0;const a=G(e);switch(i){case"modal":if((e.position||"center")!==(t.modalPosition||"center"))return!0;if(void 0!==t.dismissOutsideClick&&a.exitClick!==t.dismissOutsideClick)return!0;if(void 0!==t.overlayColor&&a.overlayColor!==t.overlayColor)return!0;break;case"overlay":{const n=Y(t.overlayPosition);if(e.elementId!==n)return!0;break}case"inline":if(e.elementId!==t.elementSelector)return!0}return void 0!==t.maxWidth&&a.messageWidth!==t.maxWidth}function ee(e,t){if(e.properties||(e.properties={}),e.properties.gist||(e.properties.gist={}),"modal"===t.displayType)e.overlay=!0,e.elementId=null,e.properties.gist.elementId=null,e.position=t.modalPosition||"center",e.properties.gist.position=t.modalPosition||"center";else if("overlay"===t.displayType){e.overlay=!1;const n=Y(t.overlayPosition);e.elementId=n,e.properties.gist.elementId=n,e.position=null,e.properties.gist.position=null}else"inline"===t.displayType&&(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.position=null,e.properties.gist.position=null);e.elementId&&F.includes(e.elementId)?delete e.properties.gist.messageWidth:void 0!==t.maxWidth&&t.maxWidth>0?e.properties.gist.messageWidth=t.maxWidth:delete e.properties.gist.messageWidth,void 0!==t.overlayColor?e.properties.gist.overlayColor=t.overlayColor:delete e.properties.gist.overlayColor,void 0!==t.dismissOutsideClick?e.properties.gist.exitClick=t.dismissOutsideClick:delete e.properties.gist.exitClick}function te(e,t,n,s,a=null){var o=me(e);if(o){var r=de(n.instanceId);o.classList.add(r);var c=G(n),u=c.messageWidth+"px";F.includes(e)&&!c.hasCustomWidth&&(u="100%"),V.includes(e)&&(o.style.width=u),se(e)||(o.style.height="0px"),o.innerHTML=function(e,t,n){return function(e,t,n){var s=800;return t.messageWidth>s&&(s=t.messageWidth),`\n <div id="gist-embed">\n <style>\n #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right {\n position: fixed;\n top: 0px;\n z-index: 1000000;\n }\n #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n position: fixed;\n bottom: 0px;\n z-index: 1000000;\n }\n #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom {\n left: 50%;\n transform: translate(-50%, 0%);\n }\n #x-gist-floating-top-right, #x-gist-floating-bottom-right {\n right: 0px;\n }\n #gist-embed {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container .gist-frame {\n height: 100%;\n width: 100%;\n border: none;\n }\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n transition: height 0.1s ease-in-out;\n }\n @media (max-width: ${s}px) {\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n width: 100% !important;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe id="${e}" class="gist-frame" src="${n}"></iframe>\n </div>\n </div>`}(de(t.instanceId),n,e)}(t,n,c),ae(r,s,a)}else i(`Message could not be embedded, elementId ${e} not found.`)}function ne(e){var t=me(e);if(t){t.classList.remove("gist-visible");Array.from(t.classList).filter((e=>e.startsWith("gist-"))).forEach((e=>t.classList.remove(e))),t.style.removeProperty("height"),t.style.removeProperty("width"),t.innerHTML=""}}function se(e){var t=me(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function ie(e,t,n,s=null){document.querySelectorAll("#gist-embed-message").forEach((function(e){e.parentNode.removeChild(e)})),document.body.insertAdjacentHTML("afterbegin",function(e,t){var n=G(t);return function(e,t,n){var s=600;return t.messageWidth>s&&(s=t.messageWidth),`\n <div id="gist-embed-message">\n <style>\n #gist-overlay.gist-background {\n position: fixed;\n z-index: 9999999998;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n background-color: ${t.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.gist-background.gist-visible {\n visibility: visible;\n }\n .gist-message {\n width: ${t.messageWidth}px;\n position: absolute;\n border: none;\n opacity: 0;\n transition: opacity 0.3s ease-in-out, height 0.1s ease-in-out;\n z-index: 9999999999;\n left: 50%;\n transform: translateX(-50%);\n }\n .gist-message.gist-visible {\n opacity: 1;\n pointer-events: auto;\n }\n .gist-message.gist-center {\n transform: translate(-50%, -50%);\n top: 50%;\n }\n .gist-message.gist-bottom {\n bottom: 0;\n }\n .gist-message.gist-top {\n top: 0;\n }\n @media (max-width: ${s}px) {\n .gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="gist-background">\n <iframe id="${e}" class="gist-message" src="${n}"></iframe>\n </div>\n </div>`}(de(t.instanceId),n,e)}(e,t)),ae(de(t.instanceId),n,s)}function ae(e,t,n=null){const s=document.getElementById(e);s&&(s.onload=function(){!function(e,t,n=null){const s=document.getElementById(e);if(s&&s.contentWindow){const e={options:t,capabilities:oe};n&&(t.stepId=n),s.contentWindow.postMessage(e,"*")}}(e,t,n)})}const oe=["MultiStepDisplayTypes"];function re(e){if(!e.displaySettings)return;const t=de(e.instanceId),n=document.getElementById(t);n&&n.contentWindow&&n.contentWindow.postMessage({action:"updateDisplaySettings",displaySettings:e.displaySettings},"*")}function ce(e){var t=G(e),n=document.querySelector("#gist-overlay");if(n){n.classList.add("gist-visible");var s=document.querySelector(".gist-message");e.position?s.classList.add("gist-"+e.position):s.classList.add("gist-center"),setTimeout(ge,100),t.exitClick&&setTimeout((()=>function(e){var t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",(function(){it.dismissMessage(e)}))}(e.instanceId)),1e3)}else le()}async function ue(){var e,t=document.querySelector(".gist-message");t&&(t.classList.remove("gist-visible"),await(e=300,new Promise((t=>setTimeout(t,e))))),le()}function le(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function de(e){return`gist-${e}`}function ge(){var e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function me(e){try{var t=document.querySelector(`#${e}`);return t||null}catch{return null}}const pe="gist.web.customAttributes";let fe=new Map;function he(){const e=Array.from(fe.entries()),t=new Date;t.setDate(t.getDate()+30),r(pe,e,t),i(`Saved ${fe.size} custom attributes to storage with TTL of 30 days`)}!function(){const e=c(pe);if(e)try{fe=new Map(e)}catch{fe=new Map}else fe=new Map}();async function ve(e){const t=await Se();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60);r(t,e.filter(ye),n)}async function we(e,t){return c(e).find((e=>e.queueId===t))}function ye(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}function be(e){if(!ye(e))return!1;const{broadcast:t}=e.properties.gist;return 0===t.frequency.delay&&0===t.frequency.count}async function Se(){const e=await O();return e?`gist.web.message.broadcasts.${e}`:null}function Ie(e,t){return`${e}.${t}.numberOfTimesShown`}function xe(e,t){return`${e}.${t}.shouldShow`}async function Ee(e){const t=await ke();if(!t)return;const n=e.filter((e=>!(e.properties&&e.properties.gist&&e.properties.gist.broadcast))),s=new Date;s.setMinutes(s.getMinutes()+60),r(t,n,s)}async function $e(){const e=await ke();if(!e)return[];const t=c(e)??[],n=await async function(){const e=await Ce();return e?c(e)??[]:[]}();return t.filter((e=>!n.includes(e.queueId)))}async function ke(){const e=await O();return e?`gist.web.message.user.${e}`:null}async function Ce(){const e=await O();return e?`gist.web.message.user.${e}.seen`:null}async function De(e){const t=await O();return t?`gist.web.message.user.${t}.message.${e}.loading`:null}async function Te(e){const t=await O();return t?`gist.web.message.user.${t}.message.${e}.state`:null}async function Me(e){const t=await Te(e);t&&(u(t),i(`Cleared message state for queueId: ${e}`))}async function qe(e){if(it.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;if(it.overlayInstanceId)return i(`Message ${it.overlayInstanceId} already showing.`),null;var t=G(e);e.instanceId=b(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),it.overlayInstanceId=e.instanceId,it.currentMessages.push(e);return We(e,null,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}function Re(e,t){if(it.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;if(Q(t))return i(`Message with elementId ${t} already has a message.`),null;e.instanceId=b(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!se(t),e.renderStartTime=(new Date).getTime(),it.currentMessages.push(e);return We(e,t,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}async function Pe(e){e?(it.messageDismissed(e),e.overlay?await Ae(!0,e):Ne(e)):i(`Message with instance id: ${e.instanceId} not found`)}async function Le(e){var t=G(e);e?t.persistent&&(i("Persistent message dismissed, logging view"),await He(e),await Ue(e),await Me(e.queueId)):i(`Message with instance id: ${e.instanceId} not found`)}function Ne(e){X(e.instanceId),ne(e.elementId)}async function Ae(e,t){e?await ue():le(),0==it.currentMessages.length&&(window.removeEventListener("message",Oe),window.removeEventListener("touchstart",_e)),X(t.instanceId),it.overlayInstanceId=null}function We(e,t=null,n=null){var s={endpoint:$.ENGINE_API_ENDPOINT[it.config.env],siteId:it.config.siteId,dataCenter:it.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(fe))},i=`${$.GIST_VIEW_ENDPOINT[it.config.env]}/index.html`;return window.addEventListener("message",Oe),window.addEventListener("touchstart",_e),t?(V.includes(t)&&j(t),te(t,i,e,s,n)):ie(i,e,s,n),e}async function Ue(e){i(`Message shown, logging view for: ${e.messageId}`);var t={};null!=e.queueId?(await He(e),t=await z(e.queueId)):t=await async function(e){try{return await k().post(`/api/v1/logs/message/${e}`)}catch(e){return e.response}}(e.messageId),200===t.status?i("Message view logged"):i(`Problem logging message: ${t.status}`)}function _e(){}async function Oe(e){if(e.data.gist&&e.origin===$.RENDERER_HOST){var t=e.data.gist.instanceId,n=B(t);if(!n)return;var s=G(n);switch(e.data.gist.method){case"routeLoaded":var a=.001*((new Date).getTime()-n.renderStartTime);i(`Engine render for message: ${n.messageId} timer elapsed in ${a.toFixed(3)} seconds`),async function(e){const t=await De(e);if(!t)return!1;u(t)}(n.queueId),n.currentRoute=e.data.gist.parameters.route,e.data.gist.parameters.fullDisplaySettings&&!n.displaySettings?n.displaySettings=e.data.gist.parameters.fullDisplaySettings:n.displaySettings&&(i("SDK already has display settings state, sending it to iframe"),re(n)),(n.firstLoad||n.isDisplayChange)&&(n.overlay?ce(n):(h=n.elementId,(v=me(h))&&v.classList.add("gist-visible")),n.firstLoad&&!n.isDisplayChange&&(it.messageShown(n),s.persistent?i("Persistent message shown, skipping logging view"):await Ue(n)),n.firstLoad=!1,n.isDisplayChange=!1),K(t,n);break;case"tap":var o=e.data.gist.parameters.action,l=e.data.gist.parameters.name;if(it.messageAction(n,o,l),e.data.gist.parameters.system&&!s.persistent){await Pe(n);break}try{var d=new URL(o);if(d&&"gist:"===d.protocol)switch(d.href.replace("gist://","").split("?")[0]){case"close":await Pe(n),await Le(n),await ze(n),await Ye();break;case"showMessage":var g=d.searchParams.get("messageId"),m=d.searchParams.get("properties");g&&(m&&(m=JSON.parse(atob(m))),await it.showMessage({messageId:g,properties:m}));break;case"loadPage":(d=d.href.substring(d.href.indexOf("?url=")+5))&&(d.startsWith("mailto:")||d.startsWith("https://")||d.startsWith("http://")||d.startsWith("/")?window.location.href=d:window.location.href=window.location+d)}}catch{}break;case"changeMessageStep":var p=e.data.gist.parameters.displaySettings,f=e.data.gist.parameters.messageStepName;(s.persistent||be(n))&&await async function(e,t,n){const s=await Te(e);if(!s)return;const a=c(s)||{},o={stepName:void 0!==t?t:a.stepName,displaySettings:void 0!==n?n:a.displaySettings},u=new Date;u.setDate(u.getDate()+30),r(s,o,u),i(`Saved message state for queueId: ${e}`)}(n.queueId,f,p),p&&Z(n,p)&&(i("Display settings changed, reloading message"),await async function(e){e.overlay?await ue():ne(e.elementId)}(n),ee(n,p),await async function(e,t){e.isDisplayChange=!0,e.renderStartTime=(new Date).getTime();var n=e.elementId||null;if(n){const t=Q(n);t&&t.instanceId!==e.instanceId&&(i(`Dismissing existing message at ${n} to make room for multi-step message`),await Pe(t))}if(e.overlay){it.overlayInstanceId=e.instanceId;var s=G(e);e.shouldScale=s.shouldScale,e.shouldResizeHeight=!0}else it.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!se(n);n&&V.includes(n)&&j(n);We(e,n,t)}(n,f));break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=(new Date).getTime(),K(t,n),i(`Route changed to: ${n.currentRoute}`);break;case"sizeChanged":i(`Size Changed Width: ${e.data.gist.parameters.width} - Height: ${e.data.gist.parameters.height}`),n.elementId&&!n.shouldResizeHeight||function(e,t){var n=me(e.elementId?e.elementId:de(e.instanceId));if(n){var s=n.style;if(t.height>0)if(t.height>window.innerHeight){var i=1-(t.height/window.innerHeight-1);e.shouldScale&&i>=.4?(s.height=`${t.height}px`,s.transform=`translateX(-50%) translateY(-50%) scale(${i})`):s.height=`${window.innerHeight}px`}else s.height=`${t.height}px`}}(n,e.data.gist.parameters);break;case"titleChanged":i(`Overlay title changed to: ${e.data.gist.parameters.title}`),function(e,t){var n=me(de(e));n&&(n.title=t)}(t,e.data.gist.parameters.title);break;case"eventDispatched":it.events.dispatch("eventDispatched",{name:e.data.gist.parameters.name,payload:e.data.gist.parameters.payload});break;case"error":case"routeError":it.messageError(n),it.overlayInstanceId?Ae(!1,n):Ne(n)}}var h,v}async function He(e){i(`Logging user message view locally for: ${e.queueId}`),ye(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await Se();if(!t)return;const n=await we(t,e);if(!n)return;const{broadcast:s}=n.properties.gist,a=Ie(t,e),o=xe(t,e);let u=c(a)||0;if(r(a,u+1),1===s.frequency.count)r(o,!1),i(`Marked broadcast ${e} as seen.`);else{let t=new Date;t.setSeconds(t.getSeconds()+s.frequency.delay),r(o,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${u+1} times, next show date is ${t}.`)}}(e.queueId):await async function(e){const t=await Ce();if(!t)return;const n=c(t)??[];n.push(e),r(t,n)}(e.queueId)}async function ze(e){ye(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await Se();if(!t)return;const n=await we(t,e);if(!n)return;const{broadcast:s}=n.properties.gist;if(!0===s.frequency.ignoreDismiss)return void i(`Broadcast ${e} is set to ignore dismiss.`);r(xe(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)}(e.queueId),await Me(e.queueId))}const Ge="messageInboxUpdated";async function Ve(e){const t=await Be();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),r(t,e,n),it.events.dispatch(Ge,e)}async function je(){const e=await Be();if(!e)return[];const t=c(e)??[],n=new Date;return t.filter((e=>{if(!e.expiry)return!0;return new Date(e.expiry)>n}))}async function Fe(e,t){const n=await Be();if(!n)return;const s=await async function(e,t){try{return await k()(`/api/v1/messages/${e}`,{method:"PATCH",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return e.response}}(e,{opened:t});if(!s||s.status<200||s.status>=300){const e=`Failed to mark inbox message opened: ${s?.status||"unknown error"}`;throw i(e),new Error(e)}const a=await je();let o=null;const c=a.map((n=>n.queueId===e?(n.opened=t,o=n,{...n}):n)),u=new Date;if(u.setMinutes(u.getMinutes()+60),r(n,c,u),o){const e=t?"opened":"unopened";it.events.dispatch("inboxMessageAction",{message:o,action:e})}it.events.dispatch(Ge,await je())}async function Be(){const e=await O();return e?`gist.web.inbox.messages.${e}`:null}var Je=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>Je(e,t)))),Qe=!1;let Xe=null;async function Ke(){Qe?await Ye():U()?(i("Queue watcher started"),Qe=!0,Je((()=>new Promise((()=>async function(){if($.hasActiveSSEConnection())return!$.isSSEConnectionManagedBySDK()&&Xe&&(i("Not the main instance, closing our SSE connection."),tt()),void await Ye();Xe&&(i("SSE connection not active, closing it."),tt());if($.useSSE()&&!W())return void await async function(){tt();const e=(t=H(),null===t?(i("No user token available for SSE endpoint."),null):$.GIST_QUEUE_REALTIME_API_ENDPOINT[it.config.env]+`/api/v3/sse?userToken=${t}&siteId=${it.config.siteId}&sessionId=${P()}`);var t;if(null===e)return i("SSE endpoint not available, falling back to polling."),void await et();i(`Starting SSE queue listener on ${e}`),Xe=new EventSource(e),$.setActiveSSEConnection(),Xe.addEventListener("connected",(async e=>{try{i("SSE connection received:"),$.setUseSSEFlag(!0);var t=JSON.parse(e.data);t.heartbeat&&($.setSSEHeartbeat(t.heartbeat),i(`SSE heartbeat set to ${t.heartbeat} seconds`)),$.setActiveSSEConnection()}catch(e){i(`Failed to parse SSE settings: ${e}`)}u(M),await et()})),Xe.addEventListener("messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE message received:"),await Ee(t),await ve(t),await Ye()}catch(e){i("Failed to parse SSE message"),tt()}})),Xe.addEventListener("inbox_messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE inbox messages received:"),await Ve(t)}catch(e){i("Failed to parse SSE inbox messages")}})),Xe.addEventListener("error",(async e=>{i("SSE error received:"),tt()})),Xe.addEventListener("heartbeat",(async e=>{i("SSE heartbeat received:"),$.setActiveSSEConnection(),$.setUseSSEFlag(!0)}))}();await et()}()))),1e3)):i("User token not setup, queue not started.")}async function Ye(){var e=await async function(){const e=await Se();return e?(c(e)??[]).filter((t=>{const{broadcast:n}=t.properties.gist,s=c(xe(e,t.queueId))??!0,i=c(Ie(e,t.queueId))||0,a=0===n.frequency.count;return s&&(a||i<n.frequency.count)})):[]}(),t=await $e(),n=e.concat(t);i(`Messages in local queue: ${n.length}`);var s=n.sort(((e,t)=>e.priority-t.priority));for(const e of s)await Ze(e)}async function Ze(e){var t=G(e);if(t.hasRouteRule){var n=it.currentRoute;null==n&&(n=new URL(window.location.href).pathname);var s=t.routeRule;if(i(`Verifying route ${n} against rule: ${s}`),!new RegExp(s).test(n))return i(`Route ${n} does not match rule.`),!1}if(t.hasPosition&&(e.position=t.position),t.persistent||be(e)){const n=await async function(e){const t=await Te(e);return t?c(t):null}(e.queueId);n&&(i(`Restoring saved state for queueId ${e.queueId}`),n.displaySettings&&(ee(e,n.displaySettings),t=G(e)),e.savedStepName=n.stepName)}if(t.persistent||be(e)||!await async function(e){const t=await De(e);return!!t&&null!==c(t)}(e.queueId)){var a=!1;return(a=t.isEmbedded?Re(e,t.elementId):await qe(e))&&async function(e){const t=await De(e);if(!t)return!1;r(t,!0,new Date(Date.now()+5e3))}(e.queueId),a}return i(`Not showing message with queueId ${e.queueId} because its already loading.`),!1}async function et(){if(U())if(it.isDocumentVisible)if(null===c(M)){var e=await R();if(e){if(200===e.status||204===e.status){i("200 response, updating local store.");var t=e.data?.inAppMessages||[],n=e.data?.inboxMessages||[];Ee(t),ve(t),Ve(n)}else 304===e.status&&i("304 response, using local store.");await Ye()}else i("No response object returned while checking message queue.")}else i("Next queue pull scheduled for later.");else i("Document not visible, skipping queue check.");else i("User token reset, skipping queue check.")}function tt(e=!1){e&&$.removeActiveSSEConnection(),(e||$.isSSEConnectionManagedBySDK())&&$.setUseSSEFlag(!1),Xe&&(i("Stopping SSE queue listener..."),Xe.close(),Xe=null)}const nt="cioPreviewId";function st(){const e=new URLSearchParams(window.location.search).get(nt);var t;return e&&(t=!1,sessionStorage.setItem(o,String(t)),it.setUserToken(e),i(`Preview mode enabled with user token: ${e}`)),!l()}var it=class{static events;static config;static initialized;static currentMessages;static overlayInstanceId;static currentRoute;static isDocumentVisible;static async setup(e){this.initialized?i("Gist SDK already initialized, skipping setup."):(this.initialized=!0,this.events=new s,this.config={useAnonymousSession:void 0!==e.useAnonymousSession&&e.useAnonymousSession,siteId:e.siteId,dataCenter:e.dataCenter,env:void 0===e.env?"prod":e.env,logging:void 0!==e.logging&&e.logging,experiments:void 0!==e.experiments&&e.experiments},this.currentMessages=[],this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,this.config.isPreviewSession=st(),function(){for(var e=d(),t=e.length-1;t>=0;t--)g(e.key(t))}(),i(`Setup complete on ${this.config.env} environment.`),this.config.isPreviewSession||!this.config.useAnonymousSession||new URLSearchParams(location.search).has("ajs_uid")||_(),await Ke(),document.addEventListener("visibilitychange",(async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Ye())}),!1))}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await Ye()}static async setUserToken(e,t){this.config.isPreviewSession||(!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),r(L,e,t),W()&&(u(M),u(N)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),tt(!0),await Ke())}static setUserLocale(e){var t;r(C,t=e),i(`Set user locate to "${t}"`)}static setCustomAttribute(e,t){return function(e,t){return e&&"string"==typeof e?(fe.set(e,t),he(),i(`Set custom attribute "${e}" to "${t}"`),!0):(i(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){fe.clear(),u(pe),i("Cleared all custom attributes")}static removeCustomAttribute(e){return function(e){if(!e||"string"!=typeof e)return i(`Invalid key for custom attribute: ${e}`),!1;const t=fe.has(e);return fe.delete(e),fe.size>0?he():u(pe),i(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(u(L),i("Cleared user token"),this.config.useAnonymousSession&&_(),tt(!0),await Ke())}static async dismissMessage(e){var t=B(e);await Pe(t),await Le(t),await ze(t),await Ye()}static async embedMessage(e,t){var n=Re(e,t);return n?n.instanceId:null}static async showMessage(e){var t=await qe(e);return t?t.instanceId:null}static updateMessageDisplaySettings(e,t){var n=B(e);return!!n&&(n.displaySettings=t,re(n),!0)}static messageShown(e){i(`Message shown: ${e.messageId}`),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(i(`Message dismissed: ${e.messageId}`),this.events.dispatch("messageDismissed",e))}static messageError(e){i(`Message error: ${e.messageId}`),this.events.dispatch("messageError",e)}static messageAction(e,t,n){i(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}static async getInboxUnopenedCount(){return(await je()).filter((e=>!e.opened)).length}static async getInboxMessages(){return await je()}static async updateInboxMessageOpenState(e,t){return await Fe(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await Be();if(!t)return;const n=await z(e);if(!n||n.status<200||n.status>=300){const e=`Failed to remove inbox message: ${n?.status||"unknown error"}`;throw i(e),new Error(e)}const s=(await je()).filter((t=>t.queueId!==e)),a=new Date;a.setMinutes(a.getMinutes()+60),r(t,s,a),it.events.dispatch(Ge,await je())}(e)}}}}]);
Binary file