@customerio/cdp-analytics-browser 0.3.10 → 0.3.12

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.10';
5
+ exports.version = '0.3.12';
6
6
  //# sourceMappingURL=version.js.map
@@ -6,11 +6,12 @@ var events_1 = require("./events");
6
6
  function createInboxMessage(analyticsInstance, gist, gistMessage) {
7
7
  var _this = this;
8
8
  return {
9
- sentAt: gistMessage.sentAt,
9
+ sentAt: new Date(gistMessage.sentAt),
10
+ expiresAt: gistMessage.expiry ? new Date(gistMessage.expiry) : undefined,
10
11
  messageId: gistMessage.queueId,
11
12
  opened: (gistMessage === null || gistMessage === void 0 ? void 0 : gistMessage.opened) === true,
12
13
  properties: gistMessage.properties,
13
- type: gistMessage.type || "",
14
+ type: gistMessage.type || '',
14
15
  topics: gistMessage.topics || [],
15
16
  trackClick: function (trackedResponse) {
16
17
  if (typeof gistMessage.deliveryId === 'undefined' || gistMessage.deliveryId === '') {
@@ -70,6 +71,9 @@ function getFilteredMessages(gist, topics, messages) {
70
71
  if (!allMessages || !Array.isArray(allMessages)) {
71
72
  return [2 /*return*/, []];
72
73
  }
74
+ allMessages = allMessages.slice().sort(function (a, b) {
75
+ return new Date(b.sentAt).getTime() - new Date(a.sentAt).getTime();
76
+ });
73
77
  if (topics.length === 0) {
74
78
  return [2 /*return*/, allMessages];
75
79
  }
@@ -1 +1 @@
1
- {"version":3,"file":"inbox_messages.js","sourceRoot":"","sources":["../../../../src/plugins/in-app-plugin/inbox_messages.ts"],"names":[],"mappings":";;;;AACA,mCAAyC;AAuFzC,SAAS,kBAAkB,CACzB,iBAA4B,EAC5B,IAAS,EACT,WAA6B;IAH/B,iBAgCC;IA3BC,OAAO;QACL,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,SAAS,EA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- export var version = '0.3.10';
2
+ export var version = '0.3.12';
3
3
  //# sourceMappingURL=version.js.map
@@ -3,11 +3,12 @@ import { JourneysEvents } from './events';
3
3
  function createInboxMessage(analyticsInstance, gist, gistMessage) {
4
4
  var _this = this;
5
5
  return {
6
- sentAt: gistMessage.sentAt,
6
+ sentAt: new Date(gistMessage.sentAt),
7
+ expiresAt: gistMessage.expiry ? new Date(gistMessage.expiry) : undefined,
7
8
  messageId: gistMessage.queueId,
8
9
  opened: (gistMessage === null || gistMessage === void 0 ? void 0 : gistMessage.opened) === true,
9
10
  properties: gistMessage.properties,
10
- type: gistMessage.type || "",
11
+ type: gistMessage.type || '',
11
12
  topics: gistMessage.topics || [],
12
13
  trackClick: function (trackedResponse) {
13
14
  if (typeof gistMessage.deliveryId === 'undefined' || gistMessage.deliveryId === '') {
@@ -67,6 +68,9 @@ function getFilteredMessages(gist, topics, messages) {
67
68
  if (!allMessages || !Array.isArray(allMessages)) {
68
69
  return [2 /*return*/, []];
69
70
  }
71
+ allMessages = allMessages.slice().sort(function (a, b) {
72
+ return new Date(b.sentAt).getTime() - new Date(a.sentAt).getTime();
73
+ });
70
74
  if (topics.length === 0) {
71
75
  return [2 /*return*/, allMessages];
72
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"inbox_messages.js","sourceRoot":"","sources":["../../../../src/plugins/in-app-plugin/inbox_messages.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAuFzC,SAAS,kBAAkB,CACzB,iBAA4B,EAC5B,IAAS,EACT,WAA6B;IAH/B,iBAgCC;IA3BC,OAAO;QACL,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,SAAS,EAAE,WAAW,CAAC,OAAO;QAC9B,MAAM,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,MAAK,IAAI;QACpC,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,IAAI,EAAE,WAAW,CAAC,IAAI,IAA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M,MAAK,IAAI,CAAA;4BACjC,CAAC,CAAC,CAAC,MAAM,EAAA;;;aACV;QACD,QAAQ,EAAE;;;;4BACS,qBAAM,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAA;;wBAAxD,QAAQ,GAAG,SAA6C;wBAC9D,sBAAO,QAAQ,CAAC,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,kBAAkB,CAAC,iBAAiB,EAAE,IAAI,EAAE,GAAG,CAAC,EAAhD,CAAgD,CAAC,EAAA;;;aAC/E;QACD,SAAS,EAAE,UAAC,QAA4C;YACtD,IAAM,OAAO,GAAG,UAAO,YAAgC;;;;;;4BAE1B,qBAAM,mBAAmB,CAChD,IAAI,EACJ,MAAM,EACN,YAAY,CACb,EAAA;;4BAJK,gBAAgB,GAAG,SAIxB;4BACK,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAAC,GAAG;gCAC7C,OAAA,kBAAkB,CAAC,iBAAiB,EAAE,IAAI,EAAE,GAAG,CAAC;4BAAhD,CAAgD,CACjD,CAAA;4BAED,QAAQ,CAAC,aAAa,CAAC,CAAA;;;;4BAEvB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,OAAK,CAAC,CAAA;;;;;iBAE1D,CAAA;YAED,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAA;YAE9C,8BAA8B;YAC9B,OAAO;gBACL,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAA;YACjD,CAAC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -76,7 +76,7 @@ export declare class AnalyticsBuffered implements PromiseLike<[Analytics, Contex
76
76
  deregister: (...args: string[]) => Promise<Context>;
77
77
  user: () => Promise<import("../user").User>;
78
78
  inbox(...topics: string[]): import('../../plugins/in-app-plugin').InboxAPI;
79
- readonly VERSION = "0.3.10";
79
+ readonly VERSION = "0.3.12";
80
80
  private _createMethod;
81
81
  /**
82
82
  * 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.10";
1
+ export declare const version = "0.3.12";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -20,7 +20,8 @@ export interface InboxMessage {
20
20
  readonly properties: {
21
21
  [key: string]: any;
22
22
  };
23
- readonly sentAt: string;
23
+ readonly sentAt: Date;
24
+ readonly expiresAt?: Date;
24
25
  readonly type: string;
25
26
  readonly topics: string[];
26
27
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"inbox_messages.d.ts","sourceRoot":"","sources":["../../../../src/plugins/in-app-plugin/inbox_messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAGhD,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,YAAY;IAE3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAG1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IAGxB,QAAQ,CAAC,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;IAG3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IAGvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAGrB,QAAQ,CAAC,MAAM,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js CHANGED
@@ -1 +1 @@
1
- (self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[852],{4587:function(e,t,n){"use strict";n.d(t,{A:function(){return nt}});class s{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}off(e,t){var n=this[e];if(n)if(t){var s=n.indexOf(t);-1!==s&&n.splice(s,1),0===n.length&&delete this[e]}else delete this[e]}dispatch(e,t){var n=this[e];n&&n.forEach((e=>e(t)))}}function i(e){nt.config&&nt.config.logging&&console.log(`Gist: ${e}`)}const a="gist.web.isPersistingSession";function o(e,t,n=null){var s=n;s||(s=new Date).setDate(s.getDate()+365);const i={value:t,expiry:s};l().setItem(e,JSON.stringify(i))}function r(e){return d(e)}function u(e){l().removeItem(e)}function c(){const e=sessionStorage.getItem(a);return null===e?(sessionStorage.setItem(a,"true"),!0):"true"===e}function l(){return c()?localStorage:sessionStorage}function d(e){if(!e)return null;try{const t=l().getItem(e);if(!t)return null;const n=JSON.parse(t);if(!n.expiry)return n.value;const 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")&&!e.endsWith("state"),o=new Date(s.getTime()+366e4);return a&&i.getTime()>o.getTime()||s.getTime()>i.getTime()?(u(e),null):n.value}catch(t){i(`Error checking key ${e} for expiry: ${t}`)}return null}var g,m=new Uint8Array(16);function f(){if(!g&&!(g="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 g(m)}var p=/^(?:[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&&p.test(e)},w=[],v=0;v<256;++v)w.push((v+256).toString(16).substr(1));var y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(w[e[t+0]]+w[e[t+1]]+w[e[t+2]]+w[e[t+3]]+"-"+w[e[t+4]]+w[e[t+5]]+"-"+w[e[t+6]]+w[e[t+7]]+"-"+w[e[t+8]]+w[e[t+9]]+"-"+w[e[t+10]]+w[e[t+11]]+w[e[t+12]]+w[e[t+13]]+w[e[t+14]]+w[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||f)();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,$=30;const 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://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 r(S)??!1},setUseSSEFlag:function(e){o(S,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection:function(){u(I)},setActiveSSEConnection:function(){o(I,E.getSdkId(),new Date((new Date).getTime()+E.getSSEHeartbeat()))},hasActiveSSEConnection:function(){return r(I)??!1},isSSEConnectionManagedBySDK:function(){return r(I)===E.getSdkId()},getSSEHeartbeat:function(){return 1e3*($+5)},setSSEHeartbeat:function(e){e&&e>0&&($=e)}};function C(){const e=E.GIST_QUEUE_API_ENDPOINT[nt.config.env],t={"X-CIO-Site-Id":nt.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(),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 k="gist.web.userLocale";var D=600,T=!1;const M="gist.web.userQueueNextPullCheck",q="gist.web.sessionId";async function R(){var e;try{if(!T){T=!0;var t={"X-Gist-User-Anonymous":W(),"Content-Language":null!==r(k)?r(k):navigator.language};e=await C().post(`/api/v4/users?sessionId=${L()}`,{},{headers:t})}}catch(t){t.response?e=t.response:i(`Error getting user queue: ${t}`)}finally{T=!1,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);o(M,D,n)}(e),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();E.setUseSSEFlag(t)}(e)}return e}function L(){var e=r(q);return e||(e=b()),o(q,e,new Date((new Date).getTime()+18e5)),e}const P="gist.web.userToken",A="gist.web.usingGuestUserToken",N="gist.web.guestUserToken";function W(){return null!==r(A)}function U(){return r(P)}function O(){if(null===U()){var e=r(N);null==e&&(e=b(),o(N,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),o(P,e),o(A,!0),i(`Using anonymous session with token: "${e}"`)}}async function _(){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 G(e){try{return await C().post(`/api/v1/logs/queue/${e}`)}catch(e){return e.response}}function V(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 z=["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 nt.currentMessages.find((t=>t.instanceId===e))}function J(e){return!!e&&nt.currentMessages.some((t=>t.queueId===e))}function Q(e){nt.currentMessages=nt.currentMessages.filter((t=>t.instanceId!==e))}function X(e,t){Q(e),nt.currentMessages.push(t)}function K(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 Y(e,t){const n=(s=e).overlay?"modal":s.elementId&&z.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=V(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=K(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 Z(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=K(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 ee(e,t,n,s,a=null){var o=de(e);if(o){var r=ce(n.instanceId);o.classList.add(r);var u=V(n),c=u.messageWidth+"px";F.includes(e)&&!u.hasCustomWidth&&(c="100%"),z.includes(e)&&(o.style.width=c),ne(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>`}(ce(t.instanceId),n,e)}(t,n,u),ie(r,s,a)}else i(`Message could not be embedded, elementId ${e} not found.`)}function te(e){var t=de(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 ne(e){var t=de(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function se(e,t,n,s=null){document.body.insertAdjacentHTML("afterbegin",function(e,t){var n=V(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>`}(ce(t.instanceId),n,e)}(e,t)),ie(ce(t.instanceId),n,s)}function ie(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:ae};n&&(t.stepId=n),s.contentWindow.postMessage(e,"*")}}(e,t,n)})}const ae=["MultiStepDisplayTypes"];function oe(e){var t=V(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(le,100),t.exitClick&&setTimeout((()=>function(e){var t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",(function(){nt.dismissMessage(e)}))}(e.instanceId)),1e3)}else ue()}async function re(){var e,t=document.querySelector(".gist-message");t&&(t.classList.remove("gist-visible"),await(e=300,new Promise((t=>setTimeout(t,e))))),ue()}function ue(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function ce(e){return`gist-${e}`}function le(){var e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function de(e){try{var t=document.querySelector(`#${e}`);return t||null}catch{return null}}const ge="gist.web.customAttributes";let me=new Map;function fe(){const e=Array.from(me.entries()),t=new Date;t.setDate(t.getDate()+30),o(ge,e,t),i(`Saved ${me.size} custom attributes to storage with TTL of 30 days`)}!function(){const e=r(ge);if(e)try{me=new Map(e)}catch{me=new Map}else me=new Map}();async function pe(e){const t=await ye();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60);o(t,e.filter(we),n)}async function he(e,t){return r(e).find((e=>e.queueId===t))}function we(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}function ve(e){if(!we(e))return!1;const{broadcast:t}=e.properties.gist;return 0===t.frequency.delay&&0===t.frequency.count}async function ye(){const e=await _();return e?`gist.web.message.broadcasts.${e}`:null}function be(e,t){return`${e}.${t}.numberOfTimesShown`}function Se(e,t){return`${e}.${t}.shouldShow`}async function Ie(e){const t=await $e();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),o(t,n,s)}async function xe(){const e=await $e();if(!e)return[];const t=r(e)??[],n=await async function(){const e=await Ee();return e?r(e)??[]:[]}();return t.filter((e=>!n.includes(e.queueId)))}async function $e(){const e=await _();return e?`gist.web.message.user.${e}`:null}async function Ee(){const e=await _();return e?`gist.web.message.user.${e}.seen`:null}async function Ce(e){const t=await _();return t?`gist.web.message.user.${t}.message.${e}.loading`:null}async function ke(e){const t=await _();return t?`gist.web.message.user.${t}.message.${e}.state`:null}async function De(e){const t=await ke(e);t&&(u(t),i(`Cleared message state for queueId: ${e}`))}async function Te(e){if(nt.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;if(nt.overlayInstanceId)return i(`Message ${nt.overlayInstanceId} already showing.`),null;var t=V(e);e.instanceId=b(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),nt.overlayInstanceId=e.instanceId,nt.currentMessages.push(e);return Ae(e,null,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}async function Me(e,t){if(nt.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;e.instanceId=b(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!ne(t),e.renderStartTime=(new Date).getTime(),nt.currentMessages.push(e);return Ae(e,t,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}async function qe(e){e?(nt.messageDismissed(e),e.overlay?await Pe(!0,e):Le(e)):i(`Message with instance id: ${e.instanceId} not found`)}async function Re(e){var t=V(e);e?t.persistent&&(i("Persistent message dismissed, logging view"),await Oe(e),await Ne(e),await De(e.queueId)):i(`Message with instance id: ${e.instanceId} not found`)}function Le(e){Q(e.instanceId),te(e.elementId)}async function Pe(e,t){e?await re():ue(),0==nt.currentMessages.length&&(window.removeEventListener("message",Ue),window.removeEventListener("touchstart",We)),Q(t.instanceId),nt.overlayInstanceId=null}function Ae(e,t=null,n=null){if(t&&function(e){var t=de(e);return!(!t||!t.classList.contains("gist-visible"))}(t))return i(`Message ${e.messageId} already showing in element ${t}.`),null;var s={endpoint:E.ENGINE_API_ENDPOINT[nt.config.env],siteId:nt.config.siteId,dataCenter:nt.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(me))},a=`${E.GIST_VIEW_ENDPOINT[nt.config.env]}/index.html`;return window.addEventListener("message",Ue),window.addEventListener("touchstart",We),t?(z.includes(t)&&j(t),ee(t,a,e,s,n)):se(a,e,s,n),e}async function Ne(e){i(`Message shown, logging view for: ${e.messageId}`);var t={};null!=e.queueId?(await Oe(e),t=await G(e.queueId)):t=await async function(e){try{return await C().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 We(){}async function Ue(e){if(e.data.gist&&e.origin===E.RENDERER_HOST){var t=e.data.gist.instanceId,n=B(t);if(!n)return;var s=V(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;u(t)}(n.queueId),n.currentRoute=e.data.gist.parameters.route,(n.firstLoad||n.isDisplayChange)&&(n.overlay?oe(n):(h=n.elementId,(w=de(h))&&w.classList.add("gist-visible")),n.firstLoad&&!n.isDisplayChange&&(nt.messageShown(n),s.persistent?i("Persistent message shown, skipping logging view"):await Ne(n)),n.firstLoad=!1,n.isDisplayChange=!1),X(t,n);break;case"tap":var c=e.data.gist.parameters.action,l=e.data.gist.parameters.name;if(nt.messageAction(n,c,l),e.data.gist.parameters.system&&!s.persistent){await qe(n);break}try{var d=new URL(c);if(d&&"gist:"===d.protocol)switch(d.href.replace("gist://","").split("?")[0]){case"close":await qe(n),await Re(n),await _e(n),await Xe();break;case"showMessage":var g=d.searchParams.get("messageId"),m=d.searchParams.get("properties");g&&(m&&(m=JSON.parse(atob(m))),await nt.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 f=e.data.gist.parameters.displaySettings,p=e.data.gist.parameters.messageStepName;(s.persistent||ve(n))&&await async function(e,t,n){const s=await ke(e);if(!s)return;const a=r(s)||{},u={stepName:void 0!==t?t:a.stepName,displaySettings:void 0!==n?n:a.displaySettings},c=new Date;c.setDate(c.getDate()+30),o(s,u,c),i(`Saved message state for queueId: ${e}`)}(n.queueId,p,f),f&&Y(n,f)&&(i("Display settings changed, reloading message"),await async function(e){e.overlay?await re():te(e.elementId)}(n),Z(n,f),await async function(e,t){e.isDisplayChange=!0,e.renderStartTime=(new Date).getTime();var n=e.elementId||null;if(n){const t=function(e){return e?nt.currentMessages.find((t=>t.elementId===e)):null}(n);t&&t.instanceId!==e.instanceId&&(i(`Dismissing existing message at ${n} to make room for multi-step message`),await qe(t))}if(e.overlay){nt.overlayInstanceId=e.instanceId;var s=V(e);e.shouldScale=s.shouldScale,e.shouldResizeHeight=!0}else nt.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!ne(n);n&&z.includes(n)&&j(n);Ae(e,n,t)}(n,p));break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=(new Date).getTime(),X(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=de(e.elementId?e.elementId:ce(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=de(ce(e));n&&(n.title=t)}(t,e.data.gist.parameters.title);break;case"eventDispatched":nt.events.dispatch("eventDispatched",{name:e.data.gist.parameters.name,payload:e.data.gist.parameters.payload});break;case"error":case"routeError":nt.messageError(n),nt.overlayInstanceId?Pe(!1,n):Le(n)}}var h,w}async function Oe(e){i(`Logging user message view locally for: ${e.queueId}`),we(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await ye();if(!t)return;const n=await he(t,e);if(!n)return;const{broadcast:s}=n.properties.gist,a=be(t,e),u=Se(t,e);let c=r(a)||0;if(o(a,c+1),1===s.frequency.count)o(u,!1),i(`Marked broadcast ${e} as seen.`);else{let t=new Date;t.setSeconds(t.getSeconds()+s.frequency.delay),o(u,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${c+1} times, next show date is ${t}.`)}}(e.queueId):await async function(e){const t=await Ee();if(!t)return;const n=r(t)??[];n.push(e),o(t,n)}(e.queueId)}async function _e(e){we(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await ye();if(!t)return;const n=await he(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.`);o(Se(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)}(e.queueId),await De(e.queueId))}const He="messageInboxUpdated";async function Ge(e){const t=await je();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),o(t,e,n),nt.events.dispatch(He,e)}async function Ve(){const e=await je();if(!e)return[];const t=r(e)??[],n=new Date;return t.filter((e=>{if(!e.expiry)return!0;return new Date(e.expiry)>n}))}async function ze(e,t){const n=await je();if(!n)return;const s=await async function(e,t){try{return await C()(`/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 Ve();let r=null;const u=a.map((n=>n.queueId===e?(n.opened=t,r=n,{...n}):n)),c=new Date;if(c.setMinutes(c.getMinutes()+60),o(n,u,c),r){const e=t?"opened":"unopened";nt.events.dispatch("inboxMessageAction",{message:r,action:e})}nt.events.dispatch(He,await Ve())}async function je(){const e=await _();return e?`gist.web.inbox.messages.${e}`:null}var Fe=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>Fe(e,t)))),Be=!1;let Je=null;async function Qe(){Be?await Xe():U()?(i("Queue watcher started"),Be=!0,Fe((()=>new Promise((()=>async function(){if(E.hasActiveSSEConnection())return!E.isSSEConnectionManagedBySDK()&&Je&&(i("Not the main instance, closing our SSE connection."),Ze()),void await Xe();Je&&(i("SSE connection not active, closing it."),Ze());if(E.useSSE()&&!W())return void await async function(){Ze();const e=(t=H(),null===t?(i("No user token available for SSE endpoint."),null):E.GIST_QUEUE_REALTIME_API_ENDPOINT[nt.config.env]+`/api/v3/sse?userToken=${t}&siteId=${nt.config.siteId}&sessionId=${L()}`);var t;if(null===e)return i("SSE endpoint not available, falling back to polling."),void await Ye();i(`Starting SSE queue listener on ${e}`),Je=new EventSource(e),E.setActiveSSEConnection(),Je.addEventListener("connected",(async e=>{try{i("SSE connection received:"),E.setUseSSEFlag(!0);var t=JSON.parse(e.data);t.heartbeat&&(E.setSSEHeartbeat(t.heartbeat),i(`SSE heartbeat set to ${t.heartbeat} seconds`)),E.setActiveSSEConnection()}catch(e){i(`Failed to parse SSE settings: ${e}`)}u(M),await Ye()})),Je.addEventListener("messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE message received:"),await Ie(t),await pe(t),await Xe()}catch(e){i("Failed to parse SSE message"),Ze()}})),Je.addEventListener("inbox_messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE inbox messages received:"),await Ge(t)}catch(e){i("Failed to parse SSE inbox messages")}})),Je.addEventListener("error",(async e=>{i("SSE error received:"),Ze()})),Je.addEventListener("heartbeat",(async e=>{i("SSE heartbeat received:"),E.setActiveSSEConnection(),E.setUseSSEFlag(!0)}))}();await Ye()}()))),1e3)):i("User token not setup, queue not started.")}async function Xe(){var e=await async function(){const e=await ye();return e?(r(e)??[]).filter((t=>{const{broadcast:n}=t.properties.gist,s=r(Se(e,t.queueId))??!0,i=r(be(e,t.queueId))||0,a=0===n.frequency.count;return s&&(a||i<n.frequency.count)})):[]}(),t=await xe(),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 Ke(e)}async function Ke(e){var t=V(e);if(t.hasRouteRule){var n=nt.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||ve(e)){const n=await async function(e){const t=await ke(e);return t?r(t):null}(e.queueId);n&&(i(`Restoring saved state for queueId ${e.queueId}`),n.displaySettings&&(Z(e,n.displaySettings),t=V(e)),e.savedStepName=n.stepName)}if(t.persistent||ve(e)||!await async function(e){const t=await Ce(e);return!!t&&null!==r(t)}(e.queueId)){var a=!1;return(a=t.isEmbedded?await Me(e,t.elementId):await Te(e))&&async function(e){const t=await Ce(e);if(!t)return!1;o(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 Ye(){if(U())if(nt.isDocumentVisible)if(null===r(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||[];Ie(t),pe(t),Ge(n)}else 304===e.status&&i("304 response, using local store.");await Xe()}else 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 Ze(e=!1){e&&E.removeActiveSSEConnection(),(e||E.isSSEConnectionManagedBySDK())&&E.setUseSSEFlag(!1),Je&&(i("Stopping SSE queue listener..."),Je.close(),Je=null)}const et="cioPreviewId";function tt(){const e=new URLSearchParams(window.location.search).get(et);var t;return e&&(t=!1,sessionStorage.setItem(a,t),nt.setUserToken(e),i(`Preview mode enabled with user token: ${e}`)),!c()}var nt=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=tt(),function(){const e=l();for(let t=e.length-1;t>=0;t--)d(e.key(t))}(),i(`Setup complete on ${this.config.env} environment.`),!this.config.isPreviewSession&&this.config.useAnonymousSession&&O(),await Qe(),document.addEventListener("visibilitychange",(async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Xe())}),!1)}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await Xe()}static async setUserToken(e,t){this.config.isPreviewSession||(!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),o(P,e,t),W()&&(u(M),u(A)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),Ze(!0),await Qe())}static setUserLocale(e){var t;o(k,t=e),i(`Set user locate to "${t}"`)}static setCustomAttribute(e,t){return function(e,t){return e&&"string"==typeof e?(me.set(e,t),fe(),i(`Set custom attribute "${e}" to "${t}"`),!0):(i(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){me.clear(),u(ge),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=me.has(e);return me.delete(e),me.size>0?fe():u(ge),i(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(u(P),i("Cleared user token"),this.config.useAnonymousSession&&O(),Ze(!0),await Qe())}static async dismissMessage(e){var t=B(e);await qe(t),await Re(t),await _e(t),await Xe()}static async embedMessage(e,t){var n=await Me(e,t);return n?n.instanceId:null}static async showMessage(e){var t=await Te(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})}static async getInboxUnopenedCount(){return(await Ve()).filter((e=>!e.opened)).length}static async getInboxMessages(){return await Ve()}static async updateInboxMessageOpenState(e,t){return await ze(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await je();if(!t)return;const n=await G(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 Ve()).filter((t=>t.queueId!==e)),a=new Date;a.setMinutes(a.getMinutes()+60),o(t,s,a),nt.events.dispatch(He,await Ve())}(e)}}},7852:function(e,t,n){const s=n(4587).A;e.exports=s}}]);
1
+ (self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[852],{4587:function(e,t,n){"use strict";n.d(t,{A:function(){return st}});class s{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}off(e,t){var n=this[e];if(n)if(t){var s=n.indexOf(t);-1!==s&&n.splice(s,1),0===n.length&&delete this[e]}else delete this[e]}dispatch(e,t){var n=this[e];n&&n.forEach((e=>e(t)))}}function i(e){st.config&&st.config.logging&&console.log(`Gist: ${e}`)}const a="gist.web.isPersistingSession";function o(e,t,n=null){var s=n;s||(s=new Date).setDate(s.getDate()+365);const i={value:t,expiry:s};l().setItem(e,JSON.stringify(i))}function r(e){return d(e)}function u(e){l().removeItem(e)}function c(){const e=sessionStorage.getItem(a);return null===e?(sessionStorage.setItem(a,"true"),!0):"true"===e}function l(){return c()?localStorage:sessionStorage}function d(e){if(!e)return null;try{const t=l().getItem(e);if(!t)return null;const n=JSON.parse(t);if(!n.expiry)return n.value;const 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")&&!e.endsWith("state"),o=new Date(s.getTime()+366e4);return a&&i.getTime()>o.getTime()||s.getTime()>i.getTime()?(u(e),null):n.value}catch(t){i(`Error checking key ${e} for expiry: ${t}`)}return null}var g,m=new Uint8Array(16);function f(){if(!g&&!(g="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 g(m)}var p=/^(?:[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&&p.test(e)},w=[],v=0;v<256;++v)w.push((v+256).toString(16).substr(1));var y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(w[e[t+0]]+w[e[t+1]]+w[e[t+2]]+w[e[t+3]]+"-"+w[e[t+4]]+w[e[t+5]]+"-"+w[e[t+6]]+w[e[t+7]]+"-"+w[e[t+8]]+w[e[t+9]]+"-"+w[e[t+10]]+w[e[t+11]]+w[e[t+12]]+w[e[t+13]]+w[e[t+14]]+w[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||f)();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,$=30;const 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://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 r(S)??!1},setUseSSEFlag:function(e){o(S,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection:function(){u(I)},setActiveSSEConnection:function(){o(I,E.getSdkId(),new Date((new Date).getTime()+E.getSSEHeartbeat()))},hasActiveSSEConnection:function(){return r(I)??!1},isSSEConnectionManagedBySDK:function(){return r(I)===E.getSdkId()},getSSEHeartbeat:function(){return 1e3*($+5)},setSSEHeartbeat:function(e){e&&e>0&&($=e)}};function C(){const e=E.GIST_QUEUE_API_ENDPOINT[st.config.env],t={"X-CIO-Site-Id":st.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(),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 k="gist.web.userLocale";var D=600,T=!1;const M="gist.web.userQueueNextPullCheck",q="gist.web.sessionId";async function R(){var e;try{if(!T){T=!0;var t={"X-Gist-User-Anonymous":W(),"Content-Language":null!==r(k)?r(k):navigator.language};e=await C().post(`/api/v4/users?sessionId=${P()}`,{},{headers:t})}}catch(t){t.response?e=t.response:i(`Error getting user queue: ${t}`)}finally{T=!1,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);o(M,D,n)}(e),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();E.setUseSSEFlag(t)}(e)}return e}function P(){var e=r(q);return e||(e=b()),o(q,e,new Date((new Date).getTime()+18e5)),e}const L="gist.web.userToken",A="gist.web.usingGuestUserToken",N="gist.web.guestUserToken";function W(){return null!==r(A)}function U(){return r(L)}function O(){if(null===U()){var e=r(N);null==e&&(e=b(),o(N,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),o(L,e),o(A,!0),i(`Using anonymous session with token: "${e}"`)}}async function _(){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 G(e){try{return await C().post(`/api/v1/logs/queue/${e}`)}catch(e){return e.response}}function V(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 z=["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 st.currentMessages.find((t=>t.instanceId===e))}function J(e){return!!e&&st.currentMessages.some((t=>t.queueId===e))}function Q(e){return e?st.currentMessages.find((t=>t.elementId===e)):null}function X(e){st.currentMessages=st.currentMessages.filter((t=>t.instanceId!==e))}function K(e,t){X(e),st.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&&z.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=V(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=ge(e);if(o){var r=le(n.instanceId);o.classList.add(r);var u=V(n),c=u.messageWidth+"px";F.includes(e)&&!u.hasCustomWidth&&(c="100%"),z.includes(e)&&(o.style.width=c),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>`}(le(t.instanceId),n,e)}(t,n,u),ae(r,s,a)}else i(`Message could not be embedded, elementId ${e} not found.`)}function ne(e){var t=ge(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=ge(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function ie(e,t,n,s=null){document.body.insertAdjacentHTML("afterbegin",function(e,t){var n=V(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>`}(le(t.instanceId),n,e)}(e,t)),ae(le(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){var t=V(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(de,100),t.exitClick&&setTimeout((()=>function(e){var t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",(function(){st.dismissMessage(e)}))}(e.instanceId)),1e3)}else ce()}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))))),ce()}function ce(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function le(e){return`gist-${e}`}function de(){var e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function ge(e){try{var t=document.querySelector(`#${e}`);return t||null}catch{return null}}const me="gist.web.customAttributes";let fe=new Map;function pe(){const e=Array.from(fe.entries()),t=new Date;t.setDate(t.getDate()+30),o(me,e,t),i(`Saved ${fe.size} custom attributes to storage with TTL of 30 days`)}!function(){const e=r(me);if(e)try{fe=new Map(e)}catch{fe=new Map}else fe=new Map}();async function he(e){const t=await be();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60);o(t,e.filter(ve),n)}async function we(e,t){return r(e).find((e=>e.queueId===t))}function ve(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}function ye(e){if(!ve(e))return!1;const{broadcast:t}=e.properties.gist;return 0===t.frequency.delay&&0===t.frequency.count}async function be(){const e=await _();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 xe(e){const t=await Ee();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),o(t,n,s)}async function $e(){const e=await Ee();if(!e)return[];const t=r(e)??[],n=await async function(){const e=await Ce();return e?r(e)??[]:[]}();return t.filter((e=>!n.includes(e.queueId)))}async function Ee(){const e=await _();return e?`gist.web.message.user.${e}`:null}async function Ce(){const e=await _();return e?`gist.web.message.user.${e}.seen`:null}async function ke(e){const t=await _();return t?`gist.web.message.user.${t}.message.${e}.loading`:null}async function De(e){const t=await _();return t?`gist.web.message.user.${t}.message.${e}.state`:null}async function Te(e){const t=await De(e);t&&(u(t),i(`Cleared message state for queueId: ${e}`))}async function Me(e){if(st.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;if(st.overlayInstanceId)return i(`Message ${st.overlayInstanceId} already showing.`),null;var t=V(e);e.instanceId=b(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),st.overlayInstanceId=e.instanceId,st.currentMessages.push(e);return Ne(e,null,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}function qe(e,t){if(st.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(),st.currentMessages.push(e);return Ne(e,t,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}async function Re(e){e?(st.messageDismissed(e),e.overlay?await Ae(!0,e):Le(e)):i(`Message with instance id: ${e.instanceId} not found`)}async function Pe(e){var t=V(e);e?t.persistent&&(i("Persistent message dismissed, logging view"),await _e(e),await We(e),await Te(e.queueId)):i(`Message with instance id: ${e.instanceId} not found`)}function Le(e){X(e.instanceId),ne(e.elementId)}async function Ae(e,t){e?await ue():ce(),0==st.currentMessages.length&&(window.removeEventListener("message",Oe),window.removeEventListener("touchstart",Ue)),X(t.instanceId),st.overlayInstanceId=null}function Ne(e,t=null,n=null){var s={endpoint:E.ENGINE_API_ENDPOINT[st.config.env],siteId:st.config.siteId,dataCenter:st.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(fe))},i=`${E.GIST_VIEW_ENDPOINT[st.config.env]}/index.html`;return window.addEventListener("message",Oe),window.addEventListener("touchstart",Ue),t?(z.includes(t)&&j(t),te(t,i,e,s,n)):ie(i,e,s,n),e}async function We(e){i(`Message shown, logging view for: ${e.messageId}`);var t={};null!=e.queueId?(await _e(e),t=await G(e.queueId)):t=await async function(e){try{return await C().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 Ue(){}async function Oe(e){if(e.data.gist&&e.origin===E.RENDERER_HOST){var t=e.data.gist.instanceId,n=B(t);if(!n)return;var s=V(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 ke(e);if(!t)return!1;u(t)}(n.queueId),n.currentRoute=e.data.gist.parameters.route,(n.firstLoad||n.isDisplayChange)&&(n.overlay?re(n):(h=n.elementId,(w=ge(h))&&w.classList.add("gist-visible")),n.firstLoad&&!n.isDisplayChange&&(st.messageShown(n),s.persistent?i("Persistent message shown, skipping logging view"):await We(n)),n.firstLoad=!1,n.isDisplayChange=!1),K(t,n);break;case"tap":var c=e.data.gist.parameters.action,l=e.data.gist.parameters.name;if(st.messageAction(n,c,l),e.data.gist.parameters.system&&!s.persistent){await Re(n);break}try{var d=new URL(c);if(d&&"gist:"===d.protocol)switch(d.href.replace("gist://","").split("?")[0]){case"close":await Re(n),await Pe(n),await He(n),await Ke();break;case"showMessage":var g=d.searchParams.get("messageId"),m=d.searchParams.get("properties");g&&(m&&(m=JSON.parse(atob(m))),await st.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 f=e.data.gist.parameters.displaySettings,p=e.data.gist.parameters.messageStepName;(s.persistent||ye(n))&&await async function(e,t,n){const s=await De(e);if(!s)return;const a=r(s)||{},u={stepName:void 0!==t?t:a.stepName,displaySettings:void 0!==n?n:a.displaySettings},c=new Date;c.setDate(c.getDate()+30),o(s,u,c),i(`Saved message state for queueId: ${e}`)}(n.queueId,p,f),f&&Z(n,f)&&(i("Display settings changed, reloading message"),await async function(e){e.overlay?await ue():ne(e.elementId)}(n),ee(n,f),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 Re(t))}if(e.overlay){st.overlayInstanceId=e.instanceId;var s=V(e);e.shouldScale=s.shouldScale,e.shouldResizeHeight=!0}else st.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!se(n);n&&z.includes(n)&&j(n);Ne(e,n,t)}(n,p));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=ge(e.elementId?e.elementId:le(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=ge(le(e));n&&(n.title=t)}(t,e.data.gist.parameters.title);break;case"eventDispatched":st.events.dispatch("eventDispatched",{name:e.data.gist.parameters.name,payload:e.data.gist.parameters.payload});break;case"error":case"routeError":st.messageError(n),st.overlayInstanceId?Ae(!1,n):Le(n)}}var h,w}async function _e(e){i(`Logging user message view locally for: ${e.queueId}`),ve(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await be();if(!t)return;const n=await we(t,e);if(!n)return;const{broadcast:s}=n.properties.gist,a=Se(t,e),u=Ie(t,e);let c=r(a)||0;if(o(a,c+1),1===s.frequency.count)o(u,!1),i(`Marked broadcast ${e} as seen.`);else{let t=new Date;t.setSeconds(t.getSeconds()+s.frequency.delay),o(u,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${c+1} times, next show date is ${t}.`)}}(e.queueId):await async function(e){const t=await Ce();if(!t)return;const n=r(t)??[];n.push(e),o(t,n)}(e.queueId)}async function He(e){ve(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await be();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.`);o(Ie(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)}(e.queueId),await Te(e.queueId))}const Ge="messageInboxUpdated";async function Ve(e){const t=await Fe();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),o(t,e,n),st.events.dispatch(Ge,e)}async function ze(){const e=await Fe();if(!e)return[];const t=r(e)??[],n=new Date;return t.filter((e=>{if(!e.expiry)return!0;return new Date(e.expiry)>n}))}async function je(e,t){const n=await Fe();if(!n)return;const s=await async function(e,t){try{return await C()(`/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 ze();let r=null;const u=a.map((n=>n.queueId===e?(n.opened=t,r=n,{...n}):n)),c=new Date;if(c.setMinutes(c.getMinutes()+60),o(n,u,c),r){const e=t?"opened":"unopened";st.events.dispatch("inboxMessageAction",{message:r,action:e})}st.events.dispatch(Ge,await ze())}async function Fe(){const e=await _();return e?`gist.web.inbox.messages.${e}`:null}var Be=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>Be(e,t)))),Je=!1;let Qe=null;async function Xe(){Je?await Ke():U()?(i("Queue watcher started"),Je=!0,Be((()=>new Promise((()=>async function(){if(E.hasActiveSSEConnection())return!E.isSSEConnectionManagedBySDK()&&Qe&&(i("Not the main instance, closing our SSE connection."),et()),void await Ke();Qe&&(i("SSE connection not active, closing it."),et());if(E.useSSE()&&!W())return void await async function(){et();const e=(t=H(),null===t?(i("No user token available for SSE endpoint."),null):E.GIST_QUEUE_REALTIME_API_ENDPOINT[st.config.env]+`/api/v3/sse?userToken=${t}&siteId=${st.config.siteId}&sessionId=${P()}`);var t;if(null===e)return i("SSE endpoint not available, falling back to polling."),void await Ze();i(`Starting SSE queue listener on ${e}`),Qe=new EventSource(e),E.setActiveSSEConnection(),Qe.addEventListener("connected",(async e=>{try{i("SSE connection received:"),E.setUseSSEFlag(!0);var t=JSON.parse(e.data);t.heartbeat&&(E.setSSEHeartbeat(t.heartbeat),i(`SSE heartbeat set to ${t.heartbeat} seconds`)),E.setActiveSSEConnection()}catch(e){i(`Failed to parse SSE settings: ${e}`)}u(M),await Ze()})),Qe.addEventListener("messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE message received:"),await xe(t),await he(t),await Ke()}catch(e){i("Failed to parse SSE message"),et()}})),Qe.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")}})),Qe.addEventListener("error",(async e=>{i("SSE error received:"),et()})),Qe.addEventListener("heartbeat",(async e=>{i("SSE heartbeat received:"),E.setActiveSSEConnection(),E.setUseSSEFlag(!0)}))}();await Ze()}()))),1e3)):i("User token not setup, queue not started.")}async function Ke(){var e=await async function(){const e=await be();return e?(r(e)??[]).filter((t=>{const{broadcast:n}=t.properties.gist,s=r(Ie(e,t.queueId))??!0,i=r(Se(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 Ye(e)}async function Ye(e){var t=V(e);if(t.hasRouteRule){var n=st.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||ye(e)){const n=await async function(e){const t=await De(e);return t?r(t):null}(e.queueId);n&&(i(`Restoring saved state for queueId ${e.queueId}`),n.displaySettings&&(ee(e,n.displaySettings),t=V(e)),e.savedStepName=n.stepName)}if(t.persistent||ye(e)||!await async function(e){const t=await ke(e);return!!t&&null!==r(t)}(e.queueId)){var a=!1;return(a=t.isEmbedded?qe(e,t.elementId):await Me(e))&&async function(e){const t=await ke(e);if(!t)return!1;o(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 Ze(){if(U())if(st.isDocumentVisible)if(null===r(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||[];xe(t),he(t),Ve(n)}else 304===e.status&&i("304 response, using local store.");await Ke()}else 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 et(e=!1){e&&E.removeActiveSSEConnection(),(e||E.isSSEConnectionManagedBySDK())&&E.setUseSSEFlag(!1),Qe&&(i("Stopping SSE queue listener..."),Qe.close(),Qe=null)}const tt="cioPreviewId";function nt(){const e=new URLSearchParams(window.location.search).get(tt);var t;return e&&(t=!1,sessionStorage.setItem(a,t),st.setUserToken(e),i(`Preview mode enabled with user token: ${e}`)),!c()}var st=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=nt(),function(){const e=l();for(let t=e.length-1;t>=0;t--)d(e.key(t))}(),i(`Setup complete on ${this.config.env} environment.`),!this.config.isPreviewSession&&this.config.useAnonymousSession&&O(),await Xe(),document.addEventListener("visibilitychange",(async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Ke())}),!1)}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await Ke()}static async setUserToken(e,t){this.config.isPreviewSession||(!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),o(L,e,t),W()&&(u(M),u(A)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),et(!0),await Xe())}static setUserLocale(e){var t;o(k,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),pe(),i(`Set custom attribute "${e}" to "${t}"`),!0):(i(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){fe.clear(),u(me),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?pe():u(me),i(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(u(L),i("Cleared user token"),this.config.useAnonymousSession&&O(),et(!0),await Xe())}static async dismissMessage(e){var t=B(e);await Re(t),await Pe(t),await He(t),await Ke()}static async embedMessage(e,t){var n=qe(e,t);return n?n.instanceId:null}static async showMessage(e){var t=await Me(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})}static async getInboxUnopenedCount(){return(await ze()).filter((e=>!e.opened)).length}static async getInboxMessages(){return await ze()}static async updateInboxMessageOpenState(e,t){return await je(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await Fe();if(!t)return;const n=await G(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 ze()).filter((t=>t.queueId!==e)),a=new Date;a.setMinutes(a.getMinutes()+60),o(t,s,a),st.events.dispatch(Ge,await ze())}(e)}}},7852:function(e,t,n){const s=n(4587).A;e.exports=s}}]);
Binary file
@@ -1 +1 @@
1
- "use strict";(self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[926],{599:function(e,n,t){t.d(n,{InAppPlugin:function(){return f}});var i,s=t(5478);!function(e){e.MessageOpened="in-app:message-opened",e.MessageDismissed="in-app:message-dismissed",e.MessageError="in-app:message-error",e.MessageAction="in-app:message-action"}(i||(i={}));var o,r=Object.values(i);!function(e){e.Metric="Report Delivery Event",e.Content="Report Content Event",e.Opened="opened",e.Clicked="clicked",e.ViewedContent="viewed_content",e.ClickedContent="clicked_content"}(o||(o={}));var a="in_app_content";function u(e,n){return new CustomEvent(e,{detail:n})}var d=t(7852),c=t.n(d);function l(e,n,t){var i=this;return{sentAt:t.sentAt,messageId:t.queueId,opened:!0===(null==t?void 0:t.opened),properties:t.properties,type:t.type||"",topics:t.topics||[],trackClick:function(n){void 0!==t.deliveryId&&""!==t.deliveryId&&e.track(o.Metric,{deliveryId:t.deliveryId,metric:o.Clicked,actionName:n})},markOpened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.updateInboxMessageOpenState(t.queueId,!0)];case 1:return e.sent(),[2]}}))}))},markUnopened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.updateInboxMessageOpenState(t.queueId,!1)];case 1:return e.sent(),[2]}}))}))},markDeleted:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.removeInboxMessage(t.queueId)];case 1:return e.sent(),[2]}}))}))}}}function v(e,n,t){return(0,s.sH)(this,void 0,Promise,(function(){var i;return(0,s.YH)(this,(function(s){switch(s.label){case 0:return(i=t)&&Array.isArray(i)?[3,2]:[4,e.getInboxMessages()];case 1:i=s.sent(),s.label=2;case 2:return i&&Array.isArray(i)?0===n.length?[2,i]:[2,i.filter((function(e){var t=e.topics;return!(!t||0===t.length)&&t.some((function(e){return n.includes(e)}))}))]:[2,[]]}}))}))}function p(e,n,t){var i=this;return{total:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,v(n,t,null)];case 1:return[2,e.sent().length]}}))}))},totalUnopened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,v(n,t,null)];case 1:return[2,e.sent().filter((function(e){return!0!==(null==e?void 0:e.opened)})).length]}}))}))},messages:function(){return(0,s.sH)(i,void 0,Promise,(function(){return(0,s.YH)(this,(function(i){switch(i.label){case 0:return[4,v(n,t,null)];case 1:return[2,i.sent().map((function(t){return l(e,n,t)}))]}}))}))},onUpdates:function(o){var r=function(r){return(0,s.sH)(i,void 0,void 0,(function(){var i,a,u;return(0,s.YH)(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,v(n,t,r)];case 1:return i=s.sent(),a=i.map((function(t){return l(e,n,t)})),o(a),[3,3];case 2:return u=s.sent(),console.error("Error processing inbox updates:",u),[3,3];case 3:return[2]}}))}))};return n.events.on("messageInboxUpdated",r),function(){n.events.off("messageInboxUpdated",r)}}}}function f(e){var n,t=this,d=!1,l=!1,v=new EventTarget;function f(){return(0,s.sH)(this,void 0,void 0,(function(){var e;return(0,s.YH)(this,(function(t){switch(t.label){case 0:return(e=n.user().anonymousId())?[4,c().setCustomAttribute("cio_anonymous_id",e)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))}function m(){d&&!l&&(n.on("reset",g),e.events&&(r.forEach((function(n){v.addEventListener(n,null==e?void 0:e.events)})),["messageDismissed","messageError"].forEach((function(e){c().events.on(e,(function(n){var t,s;v.dispatchEvent(u(function(e){switch(e){case"messageShown":return i.MessageOpened;case"messageDismissed":return i.MessageDismissed;case"messageError":return i.MessageError;case"messageAction":return i.MessageAction;default:return""}}(e),{messageId:n.messageId,deliveryId:null===(s=null===(t=n.properties)||void 0===t?void 0:t.gist)||void 0===s?void 0:s.campaignId}))}))}))),c().events.on("messageShown",(function(t){var s,r,d,l,p,f,m,g,I,h,b,y=null===(r=null===(s=null==t?void 0:t.properties)||void 0===s?void 0:s.gist)||void 0===r?void 0:r.campaignId;if(e.events&&v.dispatchEvent(u(i.MessageOpened,{messageId:null==t?void 0:t.messageId,deliveryId:y,message:{dismiss:function(){c().dismissMessage(null==t?void 0:t.instanceId)}}})),void 0===y||""===y){var k=null===(p=null===(l=null===(d=null==t?void 0:t.properties)||void 0===d?void 0:d.gist)||void 0===l?void 0:l.broadcast)||void 0===p?void 0:p.broadcastIdInt;if(k||(k=null===(g=null===(m=null===(f=null==t?void 0:t.properties)||void 0===f?void 0:f.gist)||void 0===m?void 0:m.broadcast)||void 0===g?void 0:g.broadcastId),k){var w=null===(b=null===(h=null===(I=null==t?void 0:t.properties)||void 0===I?void 0:I.gist)||void 0===h?void 0:h.broadcast)||void 0===b?void 0:b.templateId;n.track(o.Content,{actionType:o.ViewedContent,contentId:k,templateId:w,contentType:a})}}else n.track(o.Metric,{deliveryId:y,metric:o.Opened})})),c().events.on("inboxMessageAction",(function(e){var t,i,s,r;(null==e?void 0:e.message)&&""!==(null==e?void 0:e.action)&&(t=n,i=e.message,s=e.action,r=null==i?void 0:i.deliveryId,"opened"===s&&void 0!==r&&""!==r&&t.track(o.Metric,{deliveryId:i.deliveryId,metric:o.Opened}))})),c().events.on("messageAction",(function(t){var s,r,d,l,p,f,m,g,I,h,b,y,k,w,C,H=null===(d=null===(r=null===(s=null==t?void 0:t.message)||void 0===s?void 0:s.properties)||void 0===r?void 0:r.gist)||void 0===d?void 0:d.campaignId;if(e.events&&v.dispatchEvent(u(i.MessageAction,{messageId:t.message.messageId,deliveryId:H,action:t.action,name:t.name,actionName:t.name,actionValue:t.action,message:{dismiss:function(){c().dismissMessage(t.message.instanceId)}}})),"gist://close"!==t.action)if(void 0===H||""===H){var M=null===(m=null===(f=null===(p=null===(l=null==t?void 0:t.message)||void 0===l?void 0:l.properties)||void 0===p?void 0:p.gist)||void 0===f?void 0:f.broadcast)||void 0===m?void 0:m.broadcastIdInt;if(M||(M=null===(b=null===(h=null===(I=null===(g=null==t?void 0:t.message)||void 0===g?void 0:g.properties)||void 0===I?void 0:I.gist)||void 0===h?void 0:h.broadcast)||void 0===b?void 0:b.broadcastId),M){var A=null===(C=null===(w=null===(k=null===(y=null==t?void 0:t.message)||void 0===y?void 0:y.properties)||void 0===k?void 0:k.gist)||void 0===w?void 0:w.broadcast)||void 0===C?void 0:C.templateId;n.track(o.Content,{actionType:o.ClickedContent,contentId:M,templateId:A,contentType:a,actionName:t.name,actionValue:t.action})}}else n.track(o.Metric,{deliveryId:H,metric:o.Clicked,actionName:t.name,actionValue:t.action})})),c().events.on("eventDispatched",(function(e){var t,i,s;if("analytics:track"===e.name){var o=null===(t=e.payload)||void 0===t?void 0:t.event;if(void 0===o||""===o)return;n.track(o,null===(i=e.payload)||void 0===i?void 0:i.properties,null===(s=e.payload)||void 0===s?void 0:s.options)}})))}function g(e){return(0,s.sH)(this,void 0,Promise,(function(){return(0,s.YH)(this,(function(n){switch(n.label){case 0:return[4,c().clearUserToken()];case 1:return n.sent(),[4,c().clearCustomAttributes()];case 2:return n.sent(),[4,f()];case 3:return n.sent(),[2,e]}}))}))}function I(e){return(0,s.sH)(this,void 0,Promise,(function(){var t;return(0,s.YH)(this,(function(i){switch(i.label){case 0:return d?"string"==typeof(t=n.user().id())&&t.length>0?[4,c().setUserToken(t)]:[3,2]:[2,e];case 1:return i.sent(),[3,4];case 2:return[4,c().clearUserToken()];case 3:i.sent(),i.label=4;case 4:return[2,e]}}))}))}var h={name:"Customer.io In-App Plugin",type:"before",version:"0.0.1",isLoaded:function(){return l},load:function(i,o){return(0,s.sH)(t,void 0,void 0,(function(){return(0,s.YH)(this,(function(t){switch(t.label){case 0:return n=o,null==e.siteId||""===e.siteId?(s="siteId is required. Can't initialize.",console.error("[Customer.io In-App Plugin] ".concat(s)),[2,i]):[4,f()];case 1:return t.sent(),[4,c().setup({siteId:e.siteId,env:e._env?e._env:"prod",logging:e._logging,useAnonymousSession:e.anonymousInApp})];case 2:return t.sent(),d=!0,[4,I(i)];case 3:return t.sent(),m(),o.inbox=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(!l)throw new Error("Customer.io In-App Plugin is not loaded yet. Ensure the plugin is initialized before calling inbox().");return p(o,c(),e)},l=!0,[2,Promise.resolve()]}var s}))}))},identify:I,page:function(e){var n,t,i,s,o;if(!l)return e;var r=null!==(i=null===(t=null===(n=e.event)||void 0===n?void 0:n.properties)||void 0===t?void 0:t.name)&&void 0!==i?i:null===(o=null===(s=e.event)||void 0===s?void 0:s.properties)||void 0===o?void 0:o.url;return"string"==typeof r&&r.length>0&&c().setCurrentRoute(r),e},unload:function(){e.events&&r.forEach((function(n){v.removeEventListener(n,null==e?void 0:e.events)}))}};return h}}}]);
1
+ "use strict";(self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[926],{599:function(e,n,t){t.d(n,{InAppPlugin:function(){return f}});var i,s=t(5478);!function(e){e.MessageOpened="in-app:message-opened",e.MessageDismissed="in-app:message-dismissed",e.MessageError="in-app:message-error",e.MessageAction="in-app:message-action"}(i||(i={}));var o,r=Object.values(i);!function(e){e.Metric="Report Delivery Event",e.Content="Report Content Event",e.Opened="opened",e.Clicked="clicked",e.ViewedContent="viewed_content",e.ClickedContent="clicked_content"}(o||(o={}));var a="in_app_content";function u(e,n){return new CustomEvent(e,{detail:n})}var d=t(7852),c=t.n(d);function l(e,n,t){var i=this;return{sentAt:new Date(t.sentAt),expiresAt:t.expiry?new Date(t.expiry):void 0,messageId:t.queueId,opened:!0===(null==t?void 0:t.opened),properties:t.properties,type:t.type||"",topics:t.topics||[],trackClick:function(n){void 0!==t.deliveryId&&""!==t.deliveryId&&e.track(o.Metric,{deliveryId:t.deliveryId,metric:o.Clicked,actionName:n})},markOpened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.updateInboxMessageOpenState(t.queueId,!0)];case 1:return e.sent(),[2]}}))}))},markUnopened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.updateInboxMessageOpenState(t.queueId,!1)];case 1:return e.sent(),[2]}}))}))},markDeleted:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.removeInboxMessage(t.queueId)];case 1:return e.sent(),[2]}}))}))}}}function v(e,n,t){return(0,s.sH)(this,void 0,Promise,(function(){var i;return(0,s.YH)(this,(function(s){switch(s.label){case 0:return(i=t)&&Array.isArray(i)?[3,2]:[4,e.getInboxMessages()];case 1:i=s.sent(),s.label=2;case 2:return i&&Array.isArray(i)?(i=i.slice().sort((function(e,n){return new Date(n.sentAt).getTime()-new Date(e.sentAt).getTime()})),0===n.length?[2,i]:[2,i.filter((function(e){var t=e.topics;return!(!t||0===t.length)&&t.some((function(e){return n.includes(e)}))}))]):[2,[]]}}))}))}function p(e,n,t){var i=this;return{total:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,v(n,t,null)];case 1:return[2,e.sent().length]}}))}))},totalUnopened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,v(n,t,null)];case 1:return[2,e.sent().filter((function(e){return!0!==(null==e?void 0:e.opened)})).length]}}))}))},messages:function(){return(0,s.sH)(i,void 0,Promise,(function(){return(0,s.YH)(this,(function(i){switch(i.label){case 0:return[4,v(n,t,null)];case 1:return[2,i.sent().map((function(t){return l(e,n,t)}))]}}))}))},onUpdates:function(o){var r=function(r){return(0,s.sH)(i,void 0,void 0,(function(){var i,a,u;return(0,s.YH)(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,v(n,t,r)];case 1:return i=s.sent(),a=i.map((function(t){return l(e,n,t)})),o(a),[3,3];case 2:return u=s.sent(),console.error("Error processing inbox updates:",u),[3,3];case 3:return[2]}}))}))};return n.events.on("messageInboxUpdated",r),function(){n.events.off("messageInboxUpdated",r)}}}}function f(e){var n,t=this,d=!1,l=!1,v=new EventTarget;function f(){return(0,s.sH)(this,void 0,void 0,(function(){var e;return(0,s.YH)(this,(function(t){switch(t.label){case 0:return(e=n.user().anonymousId())?[4,c().setCustomAttribute("cio_anonymous_id",e)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))}function m(){d&&!l&&(n.on("reset",g),e.events&&(r.forEach((function(n){v.addEventListener(n,null==e?void 0:e.events)})),["messageDismissed","messageError"].forEach((function(e){c().events.on(e,(function(n){var t,s;v.dispatchEvent(u(function(e){switch(e){case"messageShown":return i.MessageOpened;case"messageDismissed":return i.MessageDismissed;case"messageError":return i.MessageError;case"messageAction":return i.MessageAction;default:return""}}(e),{messageId:n.messageId,deliveryId:null===(s=null===(t=n.properties)||void 0===t?void 0:t.gist)||void 0===s?void 0:s.campaignId}))}))}))),c().events.on("messageShown",(function(t){var s,r,d,l,p,f,m,g,I,h,b,y=null===(r=null===(s=null==t?void 0:t.properties)||void 0===s?void 0:s.gist)||void 0===r?void 0:r.campaignId;if(e.events&&v.dispatchEvent(u(i.MessageOpened,{messageId:null==t?void 0:t.messageId,deliveryId:y,message:{dismiss:function(){c().dismissMessage(null==t?void 0:t.instanceId)}}})),void 0===y||""===y){var w=null===(p=null===(l=null===(d=null==t?void 0:t.properties)||void 0===d?void 0:d.gist)||void 0===l?void 0:l.broadcast)||void 0===p?void 0:p.broadcastIdInt;if(w||(w=null===(g=null===(m=null===(f=null==t?void 0:t.properties)||void 0===f?void 0:f.gist)||void 0===m?void 0:m.broadcast)||void 0===g?void 0:g.broadcastId),w){var k=null===(b=null===(h=null===(I=null==t?void 0:t.properties)||void 0===I?void 0:I.gist)||void 0===h?void 0:h.broadcast)||void 0===b?void 0:b.templateId;n.track(o.Content,{actionType:o.ViewedContent,contentId:w,templateId:k,contentType:a})}}else n.track(o.Metric,{deliveryId:y,metric:o.Opened})})),c().events.on("inboxMessageAction",(function(e){var t,i,s,r;(null==e?void 0:e.message)&&""!==(null==e?void 0:e.action)&&(t=n,i=e.message,s=e.action,r=null==i?void 0:i.deliveryId,"opened"===s&&void 0!==r&&""!==r&&t.track(o.Metric,{deliveryId:i.deliveryId,metric:o.Opened}))})),c().events.on("messageAction",(function(t){var s,r,d,l,p,f,m,g,I,h,b,y,w,k,C,H=null===(d=null===(r=null===(s=null==t?void 0:t.message)||void 0===s?void 0:s.properties)||void 0===r?void 0:r.gist)||void 0===d?void 0:d.campaignId;if(e.events&&v.dispatchEvent(u(i.MessageAction,{messageId:t.message.messageId,deliveryId:H,action:t.action,name:t.name,actionName:t.name,actionValue:t.action,message:{dismiss:function(){c().dismissMessage(t.message.instanceId)}}})),"gist://close"!==t.action)if(void 0===H||""===H){var A=null===(m=null===(f=null===(p=null===(l=null==t?void 0:t.message)||void 0===l?void 0:l.properties)||void 0===p?void 0:p.gist)||void 0===f?void 0:f.broadcast)||void 0===m?void 0:m.broadcastIdInt;if(A||(A=null===(b=null===(h=null===(I=null===(g=null==t?void 0:t.message)||void 0===g?void 0:g.properties)||void 0===I?void 0:I.gist)||void 0===h?void 0:h.broadcast)||void 0===b?void 0:b.broadcastId),A){var M=null===(C=null===(k=null===(w=null===(y=null==t?void 0:t.message)||void 0===y?void 0:y.properties)||void 0===w?void 0:w.gist)||void 0===k?void 0:k.broadcast)||void 0===C?void 0:C.templateId;n.track(o.Content,{actionType:o.ClickedContent,contentId:A,templateId:M,contentType:a,actionName:t.name,actionValue:t.action})}}else n.track(o.Metric,{deliveryId:H,metric:o.Clicked,actionName:t.name,actionValue:t.action})})),c().events.on("eventDispatched",(function(e){var t,i,s;if("analytics:track"===e.name){var o=null===(t=e.payload)||void 0===t?void 0:t.event;if(void 0===o||""===o)return;n.track(o,null===(i=e.payload)||void 0===i?void 0:i.properties,null===(s=e.payload)||void 0===s?void 0:s.options)}})))}function g(e){return(0,s.sH)(this,void 0,Promise,(function(){return(0,s.YH)(this,(function(n){switch(n.label){case 0:return[4,c().clearUserToken()];case 1:return n.sent(),[4,c().clearCustomAttributes()];case 2:return n.sent(),[4,f()];case 3:return n.sent(),[2,e]}}))}))}function I(e){return(0,s.sH)(this,void 0,Promise,(function(){var t;return(0,s.YH)(this,(function(i){switch(i.label){case 0:return d?"string"==typeof(t=n.user().id())&&t.length>0?[4,c().setUserToken(t)]:[3,2]:[2,e];case 1:return i.sent(),[3,4];case 2:return[4,c().clearUserToken()];case 3:i.sent(),i.label=4;case 4:return[2,e]}}))}))}var h={name:"Customer.io In-App Plugin",type:"before",version:"0.0.1",isLoaded:function(){return l},load:function(i,o){return(0,s.sH)(t,void 0,void 0,(function(){return(0,s.YH)(this,(function(t){switch(t.label){case 0:return n=o,null==e.siteId||""===e.siteId?(s="siteId is required. Can't initialize.",console.error("[Customer.io In-App Plugin] ".concat(s)),[2,i]):[4,f()];case 1:return t.sent(),[4,c().setup({siteId:e.siteId,env:e._env?e._env:"prod",logging:e._logging,useAnonymousSession:e.anonymousInApp})];case 2:return t.sent(),d=!0,[4,I(i)];case 3:return t.sent(),m(),o.inbox=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(!l)throw new Error("Customer.io In-App Plugin is not loaded yet. Ensure the plugin is initialized before calling inbox().");return p(o,c(),e)},l=!0,[2,Promise.resolve()]}var s}))}))},identify:I,page:function(e){var n,t,i,s,o;if(!l)return e;var r=null!==(i=null===(t=null===(n=e.event)||void 0===n?void 0:n.properties)||void 0===t?void 0:t.name)&&void 0!==i?i:null===(o=null===(s=e.event)||void 0===s?void 0:s.properties)||void 0===o?void 0:o.url;return"string"==typeof r&&r.length>0&&c().setCurrentRoute(r),e},unload:function(){e.events&&r.forEach((function(n){v.removeEventListener(n,null==e?void 0:e.events)}))}};return h}}}]);
Binary file