@customerio/cdp-analytics-browser 0.3.4 → 0.3.5

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.
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // This file is generated.
5
- exports.version = '0.3.4';
5
+ exports.version = '0.3.5';
6
6
  //# sourceMappingURL=version.js.map
@@ -1,3 +1,3 @@
1
1
  // This file is generated.
2
- export var version = '0.3.4';
2
+ export var version = '0.3.5';
3
3
  //# sourceMappingURL=version.js.map
@@ -75,7 +75,7 @@ export declare class AnalyticsBuffered implements PromiseLike<[Analytics, Contex
75
75
  register: (...args: import("../plugin").Plugin[]) => Promise<Context>;
76
76
  deregister: (...args: string[]) => Promise<Context>;
77
77
  user: () => Promise<import("../user").User>;
78
- readonly VERSION = "0.3.4";
78
+ readonly VERSION = "0.3.5";
79
79
  private _createMethod;
80
80
  /**
81
81
  * These are for methods that where determining when the method gets "flushed" is not important.
@@ -1,2 +1,2 @@
1
- export declare const version = "0.3.4";
1
+ export declare const version = "0.3.5";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/umd/646.js CHANGED
@@ -1 +1 @@
1
- (self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[646],{5446:function(e,t,n){"use strict";n.d(t,{Z:function(){return Ae}});class s{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}dispatch(e,t){var n=this[e];n&&n.forEach((e=>e(t)))}}function i(e){Ae.config.logging&&console.log(`Gist: ${e}`)}var a,o=new Uint8Array(16);function r(){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(o)}var u=/^(?:[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 c=function(e){return"string"==typeof e&&u.test(e)},d=[],g=0;g<256;++g)d.push((g+256).toString(16).substr(1));var l=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(d[e[t+0]]+d[e[t+1]]+d[e[t+2]]+d[e[t+3]]+"-"+d[e[t+4]]+d[e[t+5]]+"-"+d[e[t+6]]+d[e[t+7]]+"-"+d[e[t+8]]+d[e[t+9]]+"-"+d[e[t+10]]+d[e[t+11]]+d[e[t+12]]+d[e[t+13]]+d[e[t+14]]+d[e[t+15]]).toLowerCase();if(!c(n))throw TypeError("Stringified UUID is invalid");return n};var m=function(e,t,n){var s=(e=e||{}).random||(e.rng||r)();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 l(s)};const f="gist.web.isPersistingSession";function h(e,t,n=null){var s=n;s||(s=new Date).setDate(s.getDate()+365);const i={value:t,expiry:s};y().setItem(e,JSON.stringify(i))}function p(e){const t=y().getItem(e);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>new Date(n.expiry).getTime()?(w(e),null):n.value}function w(e){y().removeItem(e)}function v(){const e=sessionStorage.getItem(f);return null===e?(sessionStorage.setItem(f,"true"),!0):"true"===e}function y(){return v()?localStorage:sessionStorage}const b="gist.web.userQueueVersion",I="gist.web.userQueueUseSSE",S="gist.web.activeSSEConnection",E={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://gist-queue-consumer-api.cloud.gist.build",dev:"https://gist-queue-consumer-api.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_QUEUE_V3_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"},getQueueAPIVersion:function(){return p(b)??"2"},setQueueAPIVersion:function(e){h(b,e,new Date((new Date).getTime()+18e5)),i(`Set user queue version to "${e}"`)},useSSE:function(){return p(I)??!1},setUseSSEFlag:function(e){h(I,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},setActiveSSEConnection:function(){h(S,!0,new Date((new Date).getTime()+31e3))},hasActiveSSEConnection:function(){return p(S)??!1}};function $(){const e="3"===E.getQueueAPIVersion()?E.GIST_QUEUE_V3_API_ENDPOINT[Ae.config.env]:E.GIST_QUEUE_API_ENDPOINT[Ae.config.env],t={"X-CIO-Site-Id":Ae.config.siteId,"X-CIO-Client-Platform":"web"},n=W();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(),u=Object.fromEntries(e.headers.entries());if(e.status<200||e.status>=400)throw{response:{status:e.status,data:r,headers:u}};return{status:e.status,headers:u,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 x="gist.web.userLocale";var T=600,D=!1;const k="gist.web.userQueueNextPullCheck",C="gist.web.sessionId";async function P(){var e;try{if(!D){D=!0;var t={"X-Gist-User-Anonymous":U(),"Content-Language":null!==p(x)?p(x):navigator.language};if("3"===E.getQueueAPIVersion())e=await $().post(`/api/v3/users?sessionId=${q()}`,{},{headers:t});else{var n=(new Date).getTime();e=await $().post(`/api/v2/users?timestamp=${n}`,{},{headers:t})}}}catch(t){t.response?e=t.response:i(`Error getting user queue: ${t}`)}finally{D=!1,function(e){if(e&&e.headers){var t=e.headers["x-gist-queue-polling-interval"];t&&t>0&&(T=t)}var n=new Date((new Date).getTime()+1e3*T);h(k,T,n)}(e),function(e){if(e&&e.headers){var t=e.headers["x-cio-queue-version"];t&&E.setQueueAPIVersion(t)}}(e),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();E.setUseSSEFlag(t)}(e)}return e}function q(){var e=p(C);return e||(e=m()),h(C,e,new Date((new Date).getTime()+18e5)),e}const R="gist.web.userToken",_="gist.web.usingGuestUserToken",L="gist.web.guestUserToken";function U(){return null!==p(_)}function A(){return p(R)}function M(){if(null===A()){var e=p(L);null==e&&(e=m(),h(L,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),h(R,e),h(_,!0),i(`Using anonymous session with token: "${e}"`)}}async function N(){var e=A();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 W(){var e=A();return null===e?null:btoa(e)}function O(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"];const G=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function Q(e,t,n,s){var a=Y(e);if(a){var o=B(n.instanceId);a.classList.add(o);var r=O(n),u=r.messageWidth+"px";G.includes(e)&&!r.hasCustomWidth&&(u="100%"),V.includes(e)&&(a.style.width=u),H(e)||(a.style.height="0px"),a.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>`}(B(t.instanceId),n,e)}(t,n,r),z(o,s)}else i(`Message could not be embedded, elementId ${e} not found.`)}function H(e){var t=Y(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function j(e,t,n){document.body.insertAdjacentHTML("afterbegin",function(e,t){var n=O(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>`}(B(t.instanceId),n,e)}(e,t)),z(B(t.instanceId),n)}function z(e,t){const n=document.getElementById(e);n&&(n.onload=function(){!function(e,t){const n=document.getElementById(e);n&&n.contentWindow&&n.contentWindow.postMessage({options:t},"*")}(e,t)})}function F(e){var t=O(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(Z,100),t.exitClick&&setTimeout((()=>function(e){var t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",(function(){Ae.dismissMessage(e)}))}(e.instanceId)),1e3)}else J()}async function X(){var e,t=document.querySelector(".gist-message");t&&(t.classList.remove("gist-visible"),await(e=300,new Promise((t=>setTimeout(t,e))))),J()}function J(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function B(e){return`gist-${e}`}function Z(){var e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function Y(e){try{var t=document.querySelector(`#${e}`);return t||null}catch{return null}}async function K(e){const t=await ne();if(!t)return;const n=new Date;n.setDate(n.getDate()+30);h(t,e.filter(te),n)}async function ee(e,t){return p(e).find((e=>e.queueId===t))}function te(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}async function ne(){const e=await N();return e?`gist.web.message.broadcasts.${e}`:null}function se(e,t){return`${e}.${t}.numberOfTimesShown`}function ie(e,t){return`${e}.${t}.shouldShow`}async function ae(e){const t=await re();if(!t)return;h(t,e.filter((e=>!(e.properties&&e.properties.gist&&e.properties.gist.broadcast))),new Date(Date.now()+36e5))}async function oe(){const e=await re();if(!e)return[];const t=p(e)??[],n=await async function(){const e=await ue();return e?p(e)??[]:[]}();return t.filter((e=>!n.includes(e.queueId)))}async function re(){const e=await N();return e?`gist.web.message.user.${e}`:null}async function ue(){const e=await N();return e?`gist.web.message.user.${e}.seen`:null}async function ce(e){const t=await N();return t?`gist.web.message.user.${t}.message.${e}.loading`:null}async function de(e){if(Ae.isDocumentVisible){if(Ae.overlayInstanceId)return i(`Message ${Ae.overlayInstanceId} already showing.`),null;var t=O(e);return e.instanceId=m(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),Ae.overlayInstanceId=e.instanceId,Ae.currentMessages.push(e),pe(e)}return i("Document hidden, not showing message now."),null}async function ge(e,t){return Ae.isDocumentVisible?(e.instanceId=m(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!H(t),e.renderStartTime=(new Date).getTime(),Ae.currentMessages.push(e),pe(e,t)):(i("Document hidden, not showing message now."),null)}async function le(e){e?(Ae.messageDismissed(e),e.overlay?await he(!0,e):fe(e)):i(`Message with instance id: ${e.instanceId} not found`)}async function me(e){var t=O(e);e?t.persistent&&(i("Persistent message dismissed, logging view"),await Ee(e),await we(e)):i(`Message with instance id: ${e.instanceId} not found`)}function fe(e){var t,n;ye(e.instanceId),t=e.elementId,(n=Y(t))&&(n.classList.remove("gist-visible"),n.style.removeProperty("height"),n.innerHTML="")}async function he(e,t){e?await X():J(),0==Ae.currentMessages.length&&(window.removeEventListener("message",Se),window.removeEventListener("touchstart",Ie)),ye(t.instanceId),Ae.overlayInstanceId=null}function pe(e,t=null){if(t&&function(e){var t=Y(e);return!(!t||!t.classList.contains("gist-visible"))}(t))return i(`Message ${e.messageId} already showing in element ${t}.`),null;var n={endpoint:E.ENGINE_API_ENDPOINT[Ae.config.env],siteId:Ae.config.siteId,dataCenter:Ae.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties},s=`${E.GIST_VIEW_ENDPOINT[Ae.config.env]}/index.html`;return window.addEventListener("message",Se),window.addEventListener("touchstart",Ie),t?(V.includes(t)&&function(e){const t=document.createElement("div");t.id=e,"x-gist-top"===e?document.body.insertBefore(t,document.body.firstChild):document.body.insertAdjacentElement("beforeend",t);i("Top & bottom elements injected into page")}(t),Q(t,s,e,n)):j(s,e,n),e}async function we(e){i(`Message shown, logging view for: ${e.messageId}`);var t={};null!=e.queueId?(await Ee(e),t=await async function(e){try{return await $().post(`/api/v1/logs/queue/${e}`)}catch(e){return e.response}}(e.queueId)):t=await async function(e){try{return await $().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 ve(e){return Ae.currentMessages.find((t=>t.instanceId===e))}function ye(e){Ae.currentMessages=Ae.currentMessages.filter((t=>t.instanceId!==e))}function be(e,t){ye(e),Ae.currentMessages.push(t)}function Ie(){}async function Se(e){if(e.data.gist&&e.origin===E.RENDERER_HOST){var t=e.data.gist.instanceId,n=ve(t);if(!n)return;var s=O(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 ce(e);if(!t)return!1;w(t)}(n.queueId),n.currentRoute=e.data.gist.parameters.route,n.firstLoad&&(n.overlay?F(n):(g=n.elementId,(l=Y(g))&&l.classList.add("gist-visible")),Ae.messageShown(n),s.persistent?i("Persistent message shown, skipping logging view"):await we(n),n.firstLoad=!1),be(t,n);break;case"tap":var o=e.data.gist.parameters.action,r=e.data.gist.parameters.name;if(Ae.messageAction(n,o,r),e.data.gist.parameters.system&&!s.persistent){await le(n);break}try{var u=new URL(o);if(u&&"gist:"===u.protocol)switch(u.href.replace("gist://","").split("?")[0]){case"close":await le(n),await me(n),await $e(n),await Ce();break;case"showMessage":var c=u.searchParams.get("messageId"),d=u.searchParams.get("properties");c&&(d&&(d=JSON.parse(atob(d))),await Ae.showMessage({messageId:c,properties:d}));break;case"loadPage":(u=u.href.substring(u.href.indexOf("?url=")+5))&&(u.startsWith("mailto:")||u.startsWith("https://")||u.startsWith("http://")||u.startsWith("/")?window.location.href=u:window.location.href=window.location+u)}}catch{}break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=(new Date).getTime(),be(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=Y(e.elementId?e.elementId:B(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=Y(B(e));n&&(n.title=t)}(t,e.data.gist.parameters.title);break;case"eventDispatched":Ae.events.dispatch("eventDispatched",{name:e.data.gist.parameters.name,payload:e.data.gist.parameters.payload});break;case"error":case"routeError":Ae.messageError(n),Ae.overlayInstanceId?he(!1,n):fe(n)}}var g,l}async function Ee(e){i(`Logging user message view locally for: ${e.queueId}`),te(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await ne();if(!t)return;const n=await ee(t,e);if(!n)return;const{broadcast:s}=n.properties.gist,a=se(t,e),o=ie(t,e);let r=p(a)||0;if(h(a,r+1),1===s.frequency.count)h(o,!1),i(`Marked broadcast ${e} as seen.`);else{let t=new Date;t.setSeconds(t.getSeconds()+s.frequency.delay),h(o,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${r+1} times, next show date is ${t}.`)}}(e.queueId):await async function(e){const t=await ue();if(!t)return;const n=p(t)??[];n.push(e),h(t,n)}(e.queueId)}async function $e(e){te(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await ne();if(!t)return;const n=await ee(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.`);h(ie(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)}(e.queueId))}var xe=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>xe(e,t)))),Te=!1;let De=null;async function ke(){Te?await Ce():A()?(i("Queue watcher started"),Te=!0,xe((()=>new Promise((()=>async function(){if(E.hasActiveSSEConnection())return void await Ce();if(E.useSSE()&&!U())return void await Re();await qe()}()))),1e3)):i("User token not setup, queue not started.")}async function Ce(){var e=await async function(){const e=await ne();return e?(p(e)??[]).filter((t=>{const{broadcast:n}=t.properties.gist,s=p(ie(e,t.queueId))??!0,i=p(se(e,t.queueId))||0,a=0===n.frequency.count;return s&&(a||i<n.frequency.count)})):[]}(),t=await oe(),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 Pe(e)}async function Pe(e){var t=O(e);if(t.hasRouteRule){var n=Ae.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||function(e){if(!te(e))return!1;const{broadcast:t}=e.properties.gist;return 0===t.frequency.delay&&0===t.frequency.count}(e)||!await async function(e){const t=await ce(e);return!!t&&null!==p(t)}(e.queueId)){var a=!1;return(a=t.isEmbedded?await ge(e,t.elementId):await de(e))&&async function(e){const t=await ce(e);if(!t)return!1;h(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 qe(){if(A())if(Ae.isDocumentVisible)if(null===p(k)){var e=await P(),t=[];e?(200===e.status||204===e.status?(i("200 response, updating local store."),ae(t=e.data),K(t)):304===e.status&&i("304 response, using local store."),await Ce()):i("There was an error 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.")}async function Re(){const e=null===(t=W())?(i("No user token available for SSE endpoint."),null):E.GIST_QUEUE_REALTIME_API_ENDPOINT[Ae.config.env]+`/api/v3/sse?userToken=${t}&siteId=${Ae.config.siteId}&sessionId=${q()}`;var t;if(null===e)return i("SSE endpoint not available, falling back to polling."),void await qe();i(`Starting SSE queue listener on ${e}`),De=new EventSource(e),E.setActiveSSEConnection(),De.addEventListener("connected",(async e=>{i("SSE connection received:"),E.setActiveSSEConnection(),E.setUseSSEFlag(!0),w(k),await qe()})),De.addEventListener("messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE message received:"),await ae(t),await K(t),await Ce()}catch(e){i("Failed to parse SSE message"),_e()}})),De.addEventListener("error",(async e=>{i("SSE error received:"),_e()})),De.addEventListener("heartbeat",(async e=>{i("SSE heartbeat received:"),E.setActiveSSEConnection(),E.setUseSSEFlag(!0)}))}function _e(){De&&(i("Stopping SSE queue listener..."),De.close(),De=null,E.setUseSSEFlag(!1))}const Le="cioPreviewId";function Ue(){const e=new URLSearchParams(window.location.search).get(Le);var t;return e&&(t=!1,sessionStorage.setItem(f,t),Ae.setUserToken(e),i(`Preview mode enabled with user token: ${e}`)),!v()}var Ae=class{static async setup(e){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=Ue(),i(`Setup complete on ${this.config.env} environment.`),!this.config.isPreviewSession&&this.config.useAnonymousSession&&M(),await ke(),document.addEventListener("visibilitychange",(async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Ce())}),!1)}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await Ce()}static async setUserToken(e,t){if(this.config.isPreviewSession)return;const n=E.hasActiveSSEConnection();_e(),function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),h(R,e,t),U()&&(w(k),w(_)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),n&&(E.setUseSSEFlag(!0),await Re()),await ke()}static setUserLocale(e){var t;h(x,t=e),i(`Set user locate to "${t}"`)}static async clearUserToken(){this.config.isPreviewSession||(w(R),i("Cleared user token"),this.config.useAnonymousSession&&M(),_e(),await ke())}static async dismissMessage(e){var t=ve(e);await le(t),await me(t),await $e(t),await Ce()}static async embedMessage(e,t){var n=await ge(e,t);return n?n.instanceId:null}static async showMessage(e){var t=await de(e);return t?t.instanceId:null}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})}}},6646:function(e,t,n){const s=n(5446).Z;e.exports=s}}]);
1
+ (self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[646],{5446:function(e,t,n){"use strict";n.d(t,{Z:function(){return Ne}});class s{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}dispatch(e,t){var n=this[e];n&&n.forEach((e=>e(t)))}}function i(e){Ne.config.logging&&console.log(`Gist: ${e}`)}var a,o=new Uint8Array(16);function r(){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(o)}var u=/^(?:[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 c=function(e){return"string"==typeof e&&u.test(e)},d=[],g=0;g<256;++g)d.push((g+256).toString(16).substr(1));var l=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(d[e[t+0]]+d[e[t+1]]+d[e[t+2]]+d[e[t+3]]+"-"+d[e[t+4]]+d[e[t+5]]+"-"+d[e[t+6]]+d[e[t+7]]+"-"+d[e[t+8]]+d[e[t+9]]+"-"+d[e[t+10]]+d[e[t+11]]+d[e[t+12]]+d[e[t+13]]+d[e[t+14]]+d[e[t+15]]).toLowerCase();if(!c(n))throw TypeError("Stringified UUID is invalid");return n};var m=function(e,t,n){var s=(e=e||{}).random||(e.rng||r)();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 l(s)};const f="gist.web.isPersistingSession";function h(e,t,n=null){var s=n;s||(s=new Date).setDate(s.getDate()+365);const i={value:t,expiry:s};y().setItem(e,JSON.stringify(i))}function p(e){const t=y().getItem(e);if(!t)return null;const n=JSON.parse(t),s=new Date,i=new Date(n.expiry),a=e.startsWith("gist.web.message.broadcasts")&&!e.endsWith("shouldShow")&&!e.endsWith("numberOfTimesShown")||e.startsWith("gist.web.message.user")&&!e.endsWith("seen"),o=new Date(s.getTime()+366e4);return a&&i.getTime()>o.getTime()||s.getTime()>i.getTime()?(w(e),null):n.value}function w(e){y().removeItem(e)}function v(){const e=sessionStorage.getItem(f);return null===e?(sessionStorage.setItem(f,"true"),!0):"true"===e}function y(){return v()?localStorage:sessionStorage}const b="gist.web.userQueueVersion",S="gist.web.userQueueUseSSE",I="gist.web.activeSSEConnection";let E,$=30;const x={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://gist-queue-consumer-api.cloud.gist.build",dev:"https://gist-queue-consumer-api.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_QUEUE_V3_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 E||(E=m()),E},getQueueAPIVersion:function(){return p(b)??"2"},setQueueAPIVersion:function(e){h(b,e,new Date((new Date).getTime()+18e5)),i(`Set user queue version to "${e}"`)},useSSE:function(){return p(S)??!1},setUseSSEFlag:function(e){h(S,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection:function(){w(I)},setActiveSSEConnection:function(){h(I,x.getSdkId(),new Date((new Date).getTime()+x.getSSEHeartbeat()))},hasActiveSSEConnection:function(){return p(I)??!1},isSSEConnectionManagedBySDK:function(){return p(I)===x.getSdkId()},getSSEHeartbeat:function(){return 1e3*($+5)},setSSEHeartbeat:function(e){e&&e>0&&($=e)}};function T(){const e="3"===x.getQueueAPIVersion()?x.GIST_QUEUE_V3_API_ENDPOINT[Ne.config.env]:x.GIST_QUEUE_API_ENDPOINT[Ne.config.env],t={"X-CIO-Site-Id":Ne.config.siteId,"X-CIO-Client-Platform":"web"},n=V();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(),u=Object.fromEntries(e.headers.entries());if(e.status<200||e.status>=400)throw{response:{status:e.status,data:r,headers:u}};return{status:e.status,headers:u,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 D="gist.web.userLocale";var k=600,C=!1;const P="gist.web.userQueueNextPullCheck",q="gist.web.sessionId";async function M(){var e;try{if(!C){C=!0;var t={"X-Gist-User-Anonymous":N(),"Content-Language":null!==p(D)?p(D):navigator.language};if("3"===x.getQueueAPIVersion())e=await T().post(`/api/v3/users?sessionId=${R()}`,{},{headers:t});else{var n=(new Date).getTime();e=await T().post(`/api/v2/users?timestamp=${n}`,{},{headers:t})}}}catch(t){t.response?e=t.response:i(`Error getting user queue: ${t}`)}finally{C=!1,function(e){if(e&&e.headers){var t=e.headers["x-gist-queue-polling-interval"];t&&t>0&&(k=t)}var n=new Date((new Date).getTime()+1e3*k);h(P,k,n)}(e),function(e){if(e&&e.headers){var t=e.headers["x-cio-queue-version"];t&&x.setQueueAPIVersion(t)}}(e),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();x.setUseSSEFlag(t)}(e)}return e}function R(){var e=p(q);return e||(e=m()),h(q,e,new Date((new Date).getTime()+18e5)),e}const _="gist.web.userToken",A="gist.web.usingGuestUserToken",L="gist.web.guestUserToken";function N(){return null!==p(A)}function U(){return p(_)}function W(){if(null===U()){var e=p(L);null==e&&(e=m(),h(L,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),h(_,e),h(A,!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 V(){var e=U();return null===e?null:btoa(e)}function H(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 G=["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"];const Q=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function j(e,t,n,s){var a=ee(e);if(a){var o=Z(n.instanceId);a.classList.add(o);var r=H(n),u=r.messageWidth+"px";Q.includes(e)&&!r.hasCustomWidth&&(u="100%"),G.includes(e)&&(a.style.width=u),z(e)||(a.style.height="0px"),a.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>`}(Z(t.instanceId),n,e)}(t,n,r),B(o,s)}else i(`Message could not be embedded, elementId ${e} not found.`)}function z(e){var t=ee(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function F(e,t,n){document.body.insertAdjacentHTML("afterbegin",function(e,t){var n=H(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>`}(Z(t.instanceId),n,e)}(e,t)),B(Z(t.instanceId),n)}function B(e,t){const n=document.getElementById(e);n&&(n.onload=function(){!function(e,t){const n=document.getElementById(e);n&&n.contentWindow&&n.contentWindow.postMessage({options:t},"*")}(e,t)})}function J(e){var t=H(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(Y,100),t.exitClick&&setTimeout((()=>function(e){var t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",(function(){Ne.dismissMessage(e)}))}(e.instanceId)),1e3)}else K()}async function X(){var e,t=document.querySelector(".gist-message");t&&(t.classList.remove("gist-visible"),await(e=300,new Promise((t=>setTimeout(t,e))))),K()}function K(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function Z(e){return`gist-${e}`}function Y(){var e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function ee(e){try{var t=document.querySelector(`#${e}`);return t||null}catch{return null}}async function te(e){const t=await ie();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60);h(t,e.filter(se),n)}async function ne(e,t){return p(e).find((e=>e.queueId===t))}function se(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}async function ie(){const e=await O();return e?`gist.web.message.broadcasts.${e}`:null}function ae(e,t){return`${e}.${t}.numberOfTimesShown`}function oe(e,t){return`${e}.${t}.shouldShow`}async function re(e){const t=await ce();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),h(t,n,s)}async function ue(){const e=await ce();if(!e)return[];const t=p(e)??[],n=await async function(){const e=await de();return e?p(e)??[]:[]}();return t.filter((e=>!n.includes(e.queueId)))}async function ce(){const e=await O();return e?`gist.web.message.user.${e}`:null}async function de(){const e=await O();return e?`gist.web.message.user.${e}.seen`:null}async function ge(e){const t=await O();return t?`gist.web.message.user.${t}.message.${e}.loading`:null}async function le(e){if(Ne.isDocumentVisible){if(Ne.overlayInstanceId)return i(`Message ${Ne.overlayInstanceId} already showing.`),null;var t=H(e);return e.instanceId=m(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),Ne.overlayInstanceId=e.instanceId,Ne.currentMessages.push(e),ve(e)}return i("Document hidden, not showing message now."),null}async function me(e,t){return Ne.isDocumentVisible?(e.instanceId=m(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!z(t),e.renderStartTime=(new Date).getTime(),Ne.currentMessages.push(e),ve(e,t)):(i("Document hidden, not showing message now."),null)}async function fe(e){e?(Ne.messageDismissed(e),e.overlay?await we(!0,e):pe(e)):i(`Message with instance id: ${e.instanceId} not found`)}async function he(e){var t=H(e);e?t.persistent&&(i("Persistent message dismissed, logging view"),await xe(e),await ye(e)):i(`Message with instance id: ${e.instanceId} not found`)}function pe(e){var t,n;Se(e.instanceId),t=e.elementId,(n=ee(t))&&(n.classList.remove("gist-visible"),n.style.removeProperty("height"),n.innerHTML="")}async function we(e,t){e?await X():K(),0==Ne.currentMessages.length&&(window.removeEventListener("message",$e),window.removeEventListener("touchstart",Ee)),Se(t.instanceId),Ne.overlayInstanceId=null}function ve(e,t=null){if(t&&function(e){var t=ee(e);return!(!t||!t.classList.contains("gist-visible"))}(t))return i(`Message ${e.messageId} already showing in element ${t}.`),null;var n={endpoint:x.ENGINE_API_ENDPOINT[Ne.config.env],siteId:Ne.config.siteId,dataCenter:Ne.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties},s=`${x.GIST_VIEW_ENDPOINT[Ne.config.env]}/index.html`;return window.addEventListener("message",$e),window.addEventListener("touchstart",Ee),t?(G.includes(t)&&function(e){const t=document.createElement("div");t.id=e,"x-gist-top"===e?document.body.insertBefore(t,document.body.firstChild):document.body.insertAdjacentElement("beforeend",t);i("Top & bottom elements injected into page")}(t),j(t,s,e,n)):F(s,e,n),e}async function ye(e){i(`Message shown, logging view for: ${e.messageId}`);var t={};null!=e.queueId?(await xe(e),t=await async function(e){try{return await T().post(`/api/v1/logs/queue/${e}`)}catch(e){return e.response}}(e.queueId)):t=await async function(e){try{return await T().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 be(e){return Ne.currentMessages.find((t=>t.instanceId===e))}function Se(e){Ne.currentMessages=Ne.currentMessages.filter((t=>t.instanceId!==e))}function Ie(e,t){Se(e),Ne.currentMessages.push(t)}function Ee(){}async function $e(e){if(e.data.gist&&e.origin===x.RENDERER_HOST){var t=e.data.gist.instanceId,n=be(t);if(!n)return;var s=H(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 ge(e);if(!t)return!1;w(t)}(n.queueId),n.currentRoute=e.data.gist.parameters.route,n.firstLoad&&(n.overlay?J(n):(g=n.elementId,(l=ee(g))&&l.classList.add("gist-visible")),Ne.messageShown(n),s.persistent?i("Persistent message shown, skipping logging view"):await ye(n),n.firstLoad=!1),Ie(t,n);break;case"tap":var o=e.data.gist.parameters.action,r=e.data.gist.parameters.name;if(Ne.messageAction(n,o,r),e.data.gist.parameters.system&&!s.persistent){await fe(n);break}try{var u=new URL(o);if(u&&"gist:"===u.protocol)switch(u.href.replace("gist://","").split("?")[0]){case"close":await fe(n),await he(n),await Te(n),await qe();break;case"showMessage":var c=u.searchParams.get("messageId"),d=u.searchParams.get("properties");c&&(d&&(d=JSON.parse(atob(d))),await Ne.showMessage({messageId:c,properties:d}));break;case"loadPage":(u=u.href.substring(u.href.indexOf("?url=")+5))&&(u.startsWith("mailto:")||u.startsWith("https://")||u.startsWith("http://")||u.startsWith("/")?window.location.href=u:window.location.href=window.location+u)}}catch{}break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=(new Date).getTime(),Ie(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=ee(e.elementId?e.elementId:Z(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=ee(Z(e));n&&(n.title=t)}(t,e.data.gist.parameters.title);break;case"eventDispatched":Ne.events.dispatch("eventDispatched",{name:e.data.gist.parameters.name,payload:e.data.gist.parameters.payload});break;case"error":case"routeError":Ne.messageError(n),Ne.overlayInstanceId?we(!1,n):pe(n)}}var g,l}async function xe(e){i(`Logging user message view locally for: ${e.queueId}`),se(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await ie();if(!t)return;const n=await ne(t,e);if(!n)return;const{broadcast:s}=n.properties.gist,a=ae(t,e),o=oe(t,e);let r=p(a)||0;if(h(a,r+1),1===s.frequency.count)h(o,!1),i(`Marked broadcast ${e} as seen.`);else{let t=new Date;t.setSeconds(t.getSeconds()+s.frequency.delay),h(o,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${r+1} times, next show date is ${t}.`)}}(e.queueId):await async function(e){const t=await de();if(!t)return;const n=p(t)??[];n.push(e),h(t,n)}(e.queueId)}async function Te(e){se(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await ie();if(!t)return;const n=await ne(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.`);h(oe(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)}(e.queueId))}var De=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>De(e,t)))),ke=!1;let Ce=null;async function Pe(){ke?await qe():U()?(i("Queue watcher started"),ke=!0,De((()=>new Promise((()=>async function(){if(x.hasActiveSSEConnection())return!x.isSSEConnectionManagedBySDK()&&Ce&&(i("Not the main instance, closing our SSE connection."),_e()),void await qe();Ce&&(i("SSE connection not active, closing it."),_e());if(x.useSSE()&&!N())return void await async function(){_e();const e=(t=V(),null===t?(i("No user token available for SSE endpoint."),null):x.GIST_QUEUE_REALTIME_API_ENDPOINT[Ne.config.env]+`/api/v3/sse?userToken=${t}&siteId=${Ne.config.siteId}&sessionId=${R()}`);var t;if(null===e)return i("SSE endpoint not available, falling back to polling."),void await Re();i(`Starting SSE queue listener on ${e}`),Ce=new EventSource(e),x.setActiveSSEConnection(),Ce.addEventListener("connected",(async e=>{try{i("SSE connection received:"),x.setUseSSEFlag(!0);var t=JSON.parse(e.data);t.heartbeat&&(x.setSSEHeartbeat(t.heartbeat),i(`SSE heartbeat set to ${t.heartbeat} seconds`)),x.setActiveSSEConnection()}catch(e){i(`Failed to parse SSE settings: ${e}`)}w(P),await Re()})),Ce.addEventListener("messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE message received:"),await re(t),await te(t),await qe()}catch(e){i("Failed to parse SSE message"),_e()}})),Ce.addEventListener("error",(async e=>{i("SSE error received:"),_e()})),Ce.addEventListener("heartbeat",(async e=>{i("SSE heartbeat received:"),x.setActiveSSEConnection(),x.setUseSSEFlag(!0)}))}();await Re()}()))),1e3)):i("User token not setup, queue not started.")}async function qe(){var e=await async function(){const e=await ie();return e?(p(e)??[]).filter((t=>{const{broadcast:n}=t.properties.gist,s=p(oe(e,t.queueId))??!0,i=p(ae(e,t.queueId))||0,a=0===n.frequency.count;return s&&(a||i<n.frequency.count)})):[]}(),t=await ue(),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 Me(e)}async function Me(e){var t=H(e);if(t.hasRouteRule){var n=Ne.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||function(e){if(!se(e))return!1;const{broadcast:t}=e.properties.gist;return 0===t.frequency.delay&&0===t.frequency.count}(e)||!await async function(e){const t=await ge(e);return!!t&&null!==p(t)}(e.queueId)){var a=!1;return(a=t.isEmbedded?await me(e,t.elementId):await le(e))&&async function(e){const t=await ge(e);if(!t)return!1;h(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 Re(){if(U())if(Ne.isDocumentVisible)if(null===p(P)){var e=await M(),t=[];e?(200===e.status||204===e.status?(i("200 response, updating local store."),re(t=e.data),te(t)):304===e.status&&i("304 response, using local store."),await qe()):i("There was an error 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 _e(e=!1){e&&x.removeActiveSSEConnection(),(e||x.isSSEConnectionManagedBySDK())&&x.setUseSSEFlag(!1),Ce&&(i("Stopping SSE queue listener..."),Ce.close(),Ce=null)}const Ae="cioPreviewId";function Le(){const e=new URLSearchParams(window.location.search).get(Ae);var t;return e&&(t=!1,sessionStorage.setItem(f,t),Ne.setUserToken(e),i(`Preview mode enabled with user token: ${e}`)),!v()}var Ne=class{static async setup(e){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=Le(),i(`Setup complete on ${this.config.env} environment.`),!this.config.isPreviewSession&&this.config.useAnonymousSession&&W(),await Pe(),document.addEventListener("visibilitychange",(async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await qe())}),!1)}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await qe()}static async setUserToken(e,t){this.config.isPreviewSession||(!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),h(_,e,t),N()&&(w(P),w(A)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),_e(!0),await Pe())}static setUserLocale(e){var t;h(D,t=e),i(`Set user locate to "${t}"`)}static async clearUserToken(){this.config.isPreviewSession||(w(_),i("Cleared user token"),this.config.useAnonymousSession&&W(),_e(!0),await Pe())}static async dismissMessage(e){var t=be(e);await fe(t),await he(t),await Te(t),await qe()}static async embedMessage(e,t){var n=await me(e,t);return n?n.instanceId:null}static async showMessage(e){var t=await le(e);return t?t.instanceId:null}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})}}},6646:function(e,t,n){const s=n(5446).Z;e.exports=s}}]);
Binary file