@customerio/cdp-analytics-browser 0.3.11 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/generated/version.js +1 -1
- package/dist/cjs/plugins/in-app-plugin/inbox_messages.js +6 -2
- package/dist/cjs/plugins/in-app-plugin/inbox_messages.js.map +1 -1
- package/dist/pkg/generated/version.js +1 -1
- package/dist/pkg/plugins/in-app-plugin/inbox_messages.js +6 -2
- package/dist/pkg/plugins/in-app-plugin/inbox_messages.js.map +1 -1
- package/dist/types/core/buffer/index.d.ts +1 -1
- package/dist/types/generated/version.d.ts +1 -1
- package/dist/types/plugins/in-app-plugin/inbox_messages.d.ts +2 -1
- package/dist/types/plugins/in-app-plugin/inbox_messages.d.ts.map +1 -1
- package/dist/umd/852.js +1 -1
- package/dist/umd/852.js.gz +0 -0
- package/dist/umd/inAppPlugin.js +1 -1
- package/dist/umd/inAppPlugin.js.gz +0 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/standalone.js +1 -1
- package/dist/umd/standalone.js.gz +0 -0
- package/package.json +3 -3
- package/src/generated/version.ts +1 -1
- package/src/plugins/in-app-plugin/inbox_messages.ts +11 -3
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"inbox_messages.js","sourceRoot":"","sources":["../../../../src/plugins/in-app-plugin/inbox_messages.ts"],"names":[],"mappings":";;;;AACA,mCAAyC;AA0FzC,SAAS,kBAAkB,CACzB,iBAA4B,EAC5B,IAAS,EACT,WAA6B;IAH/B,iBAiCC;IA5BC,OAAO;QACL,MAAM,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACpC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;QACxE,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,IAAI,EAAE;QAC5B,MAAM,EAAE,WAAW,CAAC,MAAM,IAAI,EAAE;QAChC,UAAU,EAAE,UAAC,eAAwB;YACnC,IAAG,OAAO,W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G,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;AA1CD,wCA0CC"}
|
|
@@ -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;
|
|
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;AA0FzC,SAAS,kBAAkB,CACzB,iBAA4B,EAC5B,IAAS,EACT,WAA6B;IAH/B,iBAiCC;IA5BC,OAAO;QACL,MAAM,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACpC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;QACxE,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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C,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.
|
|
79
|
+
readonly VERSION = "0.3.13";
|
|
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.
|
|
1
|
+
export declare const version = "0.3.13";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -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,
|
|
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,W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OAAO,CAAC,YAAY,EAAE,CAAC,CAAA;IAEnC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;CACpE;AAoED,wBAAgB,cAAc,CAAC,iBAAiB,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CA0ClG"}
|
package/dist/umd/852.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 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}}]);
|
|
1
|
+
(self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[852],{4587:function(e,t,s){"use strict";s.d(t,{A:function(){return it}});class n{on(e,t){var s=this[e];s?s.push(t):this[e]=[t]}off(e,t){var s=this[e];if(s)if(t){var n=s.indexOf(t);-1!==n&&s.splice(n,1),0===s.length&&delete this[e]}else delete this[e]}dispatch(e,t){var s=this[e];s&&s.forEach((e=>e(t)))}}function i(e){it.config&&it.config.logging&&console.log(`Gist: ${e}`)}const a="gist.web.isPersistingSession";function o(e,t,s=null){var n=s;n||(n=new Date).setDate(n.getDate()+365);const i={value:t,expiry:n};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 s=JSON.parse(t);if(!s.expiry)return s.value;const n=new Date,i=new Date(s.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(n.getTime()+366e4);return a&&i.getTime()>o.getTime()||n.getTime()>i.getTime()?(u(e),null):s.value}catch(t){i(`Error checking key ${e} for expiry: ${t}`)}return null}var g,m=new Uint8Array(16);function p(){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 f=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var h=function(e){return"string"==typeof e&&f.test(e)},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,s=(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(s))throw TypeError("Stringified UUID is invalid");return s};var b=function(e,t,s){var n=(e=e||{}).random||(e.rng||p)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){s=s||0;for(var i=0;i<16;++i)t[s+i]=n[i];return t}return y(n)};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[it.config.env],t={"X-CIO-Site-Id":it.config.siteId,"X-CIO-Client-Platform":"web"},s=H();async function n(s,n={}){const i=e+s,a=new AbortController,o=setTimeout((()=>a.abort()),5e3);try{const e=await fetch(i,{method:n.method||"GET",headers:{...t,...n.headers||{}},body:n.method&&"GET"!==n.method.toUpperCase()?n.body:void 0,signal:a.signal});clearTimeout(o);const s=e.headers.get("content-type")?.includes("application/json"),r=s?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!=s&&(t["X-Gist-Encoded-User-Token"]=s),n.post=(e,t={},s={})=>n(e,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...s.headers||{}}}),n}const D="gist.web.userLocale";var k=600,T=!1;const M="gist.web.userQueueNextPullCheck",q="gist.web.sessionId";async function R(){const e=U();var t;try{if(!T){T=!0;var s={"X-Gist-User-Anonymous":W(),"Content-Language":null!==r(D)?r(D):navigator.language};t=await C().post(`/api/v4/users?sessionId=${P()}`,{},{headers:s})}}catch(e){e.response?t=e.response:i(`Error getting user queue: ${e}`)}finally{T=!1}return e!==U()?(i("User token changed, clearing queue next pull check."),void u(M)):(function(e){if(e&&e.headers){var t=e.headers["x-gist-queue-polling-interval"];t&&t>0&&(k=t)}var s=new Date((new Date).getTime()+1e3*k);o(M,k,s)}(t),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();E.setUseSSEFlag(t)}(t),t)}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 _(){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 O(){var e=U();return null===e?null:await async function(e){const t=(new TextEncoder).encode(e),s=await crypto.subtle.digest("SHA-256",t),n=Array.from(new Uint8Array(s));return n.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},s=e?.properties?.gist;return s?{isEmbedded:!!s.elementId,elementId:s.elementId||"",hasRouteRule:!!s.routeRuleWeb,routeRule:s.routeRuleWeb||"",position:s.position||"",hasPosition:!!s.position,shouldScale:!!s.scale,campaignId:s.campaignId??null,messageWidth:s.messageWidth>0?s.messageWidth:t.messageWidth,hasCustomWidth:s.messageWidth>0,overlayColor:s.overlayColor||t.overlayColor,persistent:!!s.persistent,exitClick:!!s.exitClick}:t}var j=["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 z(e){if(document.getElementById(e))return;const t=document.createElement("div");if(t.id=e,"x-gist-top"===e)document.body.insertBefore(t,document.body.firstChild);else document.body.insertAdjacentElement("beforeend",t);i("Top & bottom elements injected into page")}const F=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function B(e){return it.currentMessages.find((t=>t.instanceId===e))}function J(e){return!!e&&it.currentMessages.some((t=>t.queueId===e))}function Q(e){return e?it.currentMessages.find((t=>t.elementId===e)):null}function X(e){it.currentMessages=it.currentMessages.filter((t=>t.instanceId!==e))}function K(e,t){X(e),it.currentMessages.push(t)}function Y(e){const t={topLeft:"x-gist-floating-top-left",topCenter:"x-gist-floating-top",topRight:"x-gist-floating-top-right",bottomLeft:"x-gist-floating-bottom-left",bottomCenter:"x-gist-floating-bottom",bottomRight:"x-gist-floating-bottom-right"};return e&&t[e]?t[e]:(i(`Invalid overlay position "${e}", defaulting to "topCenter"`),t.topCenter)}function Z(e,t){const s=(n=e).overlay?"modal":n.elementId&&j.includes(n.elementId)?"overlay":n.elementId?"inline":"modal";var n;const i=t.displayType;if(void 0===i)return!1;if(s!==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 s=Y(t.overlayPosition);if(e.elementId!==s)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 s=Y(t.overlayPosition);e.elementId=s,e.properties.gist.elementId=s,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,s,n,a=null){var o=me(e);if(o){var r=de(s.instanceId);o.classList.add(r);var u=V(s),c=u.messageWidth+"px";F.includes(e)&&!u.hasCustomWidth&&(c="100%"),j.includes(e)&&(o.style.width=c),ne(e)||(o.style.height="0px"),o.innerHTML=function(e,t,s){return function(e,t,s){var n=800;return t.messageWidth>n&&(n=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: ${n}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="${s}"></iframe>\n </div>\n </div>`}(de(t.instanceId),s,e)}(t,s,u),ae(r,n,a)}else i(`Message could not be embedded, elementId ${e} not found.`)}function se(e){var t=me(e);if(t){t.classList.remove("gist-visible");Array.from(t.classList).filter((e=>e.startsWith("gist-"))).forEach((e=>t.classList.remove(e))),t.style.removeProperty("height"),t.style.removeProperty("width"),t.innerHTML=""}}function ne(e){var t=me(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function ie(e,t,s,n=null){document.body.insertAdjacentHTML("afterbegin",function(e,t){var s=V(t);return function(e,t,s){var n=600;return t.messageWidth>n&&(n=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: ${n}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="${s}"></iframe>\n </div>\n </div>`}(de(t.instanceId),s,e)}(e,t)),ae(de(t.instanceId),s,n)}function ae(e,t,s=null){const n=document.getElementById(e);n&&(n.onload=function(){!function(e,t,s=null){const n=document.getElementById(e);if(n&&n.contentWindow){const e={options:t,capabilities:oe};s&&(t.stepId=s),n.contentWindow.postMessage(e,"*")}}(e,t,s)})}const oe=["MultiStepDisplayTypes"];function re(e){if(!e.displaySettings)return;const t=de(e.instanceId),s=document.getElementById(t);s&&s.contentWindow&&s.contentWindow.postMessage({action:"updateDisplaySettings",displaySettings:e.displaySettings},"*")}function ue(e){var t=V(e),s=document.querySelector("#gist-overlay");if(s){s.classList.add("gist-visible");var n=document.querySelector(".gist-message");e.position?n.classList.add("gist-"+e.position):n.classList.add("gist-center"),setTimeout(ge,100),t.exitClick&&setTimeout((()=>function(e){var t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",(function(){it.dismissMessage(e)}))}(e.instanceId)),1e3)}else le()}async function ce(){var e,t=document.querySelector(".gist-message");t&&(t.classList.remove("gist-visible"),await(e=300,new Promise((t=>setTimeout(t,e))))),le()}function le(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function de(e){return`gist-${e}`}function ge(){var e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function me(e){try{var t=document.querySelector(`#${e}`);return t||null}catch{return null}}const pe="gist.web.customAttributes";let fe=new Map;function he(){const e=Array.from(fe.entries()),t=new Date;t.setDate(t.getDate()+30),o(pe,e,t),i(`Saved ${fe.size} custom attributes to storage with TTL of 30 days`)}!function(){const e=r(pe);if(e)try{fe=new Map(e)}catch{fe=new Map}else fe=new Map}();async function we(e){const t=await Se();if(!t)return;const s=new Date;s.setMinutes(s.getMinutes()+60);o(t,e.filter(ye),s)}async function ve(e,t){return r(e).find((e=>e.queueId===t))}function ye(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}function be(e){if(!ye(e))return!1;const{broadcast:t}=e.properties.gist;return 0===t.frequency.delay&&0===t.frequency.count}async function Se(){const e=await O();return e?`gist.web.message.broadcasts.${e}`:null}function Ie(e,t){return`${e}.${t}.numberOfTimesShown`}function xe(e,t){return`${e}.${t}.shouldShow`}async function $e(e){const t=await Ce();if(!t)return;const s=e.filter((e=>!(e.properties&&e.properties.gist&&e.properties.gist.broadcast))),n=new Date;n.setMinutes(n.getMinutes()+60),o(t,s,n)}async function Ee(){const e=await Ce();if(!e)return[];const t=r(e)??[],s=await async function(){const e=await De();return e?r(e)??[]:[]}();return t.filter((e=>!s.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 ke(e){const t=await O();return t?`gist.web.message.user.${t}.message.${e}.loading`:null}async function Te(e){const t=await O();return t?`gist.web.message.user.${t}.message.${e}.state`:null}async function Me(e){const t=await Te(e);t&&(u(t),i(`Cleared message state for queueId: ${e}`))}async function qe(e){if(it.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;if(it.overlayInstanceId)return i(`Message ${it.overlayInstanceId} already showing.`),null;var t=V(e);e.instanceId=b(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),it.overlayInstanceId=e.instanceId,it.currentMessages.push(e);return We(e,null,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}function Re(e,t){if(it.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;if(Q(t))return i(`Message with elementId ${t} already has a message.`),null;e.instanceId=b(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!ne(t),e.renderStartTime=(new Date).getTime(),it.currentMessages.push(e);return We(e,t,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}async function Pe(e){e?(it.messageDismissed(e),e.overlay?await Ne(!0,e):Ae(e)):i(`Message with instance id: ${e.instanceId} not found`)}async function Le(e){var t=V(e);e?t.persistent&&(i("Persistent message dismissed, logging view"),await He(e),await Ue(e),await Me(e.queueId)):i(`Message with instance id: ${e.instanceId} not found`)}function Ae(e){X(e.instanceId),se(e.elementId)}async function Ne(e,t){e?await ce():le(),0==it.currentMessages.length&&(window.removeEventListener("message",Oe),window.removeEventListener("touchstart",_e)),X(t.instanceId),it.overlayInstanceId=null}function We(e,t=null,s=null){var n={endpoint:E.ENGINE_API_ENDPOINT[it.config.env],siteId:it.config.siteId,dataCenter:it.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(fe))},i=`${E.GIST_VIEW_ENDPOINT[it.config.env]}/index.html`;return window.addEventListener("message",Oe),window.addEventListener("touchstart",_e),t?(j.includes(t)&&z(t),te(t,i,e,n,s)):ie(i,e,n,s),e}async function Ue(e){i(`Message shown, logging view for: ${e.messageId}`);var t={};null!=e.queueId?(await He(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 _e(){}async function Oe(e){if(e.data.gist&&e.origin===E.RENDERER_HOST){var t=e.data.gist.instanceId,s=B(t);if(!s)return;var n=V(s);switch(e.data.gist.method){case"routeLoaded":var a=.001*((new Date).getTime()-s.renderStartTime);i(`Engine render for message: ${s.messageId} timer elapsed in ${a.toFixed(3)} seconds`),async function(e){const t=await ke(e);if(!t)return!1;u(t)}(s.queueId),s.currentRoute=e.data.gist.parameters.route,e.data.gist.parameters.fullDisplaySettings&&!s.displaySettings?s.displaySettings=e.data.gist.parameters.fullDisplaySettings:s.displaySettings&&(i("SDK already has display settings state, sending it to iframe"),re(s)),(s.firstLoad||s.isDisplayChange)&&(s.overlay?ue(s):(h=s.elementId,(w=me(h))&&w.classList.add("gist-visible")),s.firstLoad&&!s.isDisplayChange&&(it.messageShown(s),n.persistent?i("Persistent message shown, skipping logging view"):await Ue(s)),s.firstLoad=!1,s.isDisplayChange=!1),K(t,s);break;case"tap":var c=e.data.gist.parameters.action,l=e.data.gist.parameters.name;if(it.messageAction(s,c,l),e.data.gist.parameters.system&&!n.persistent){await Pe(s);break}try{var d=new URL(c);if(d&&"gist:"===d.protocol)switch(d.href.replace("gist://","").split("?")[0]){case"close":await Pe(s),await Le(s),await Ge(s),await Ye();break;case"showMessage":var g=d.searchParams.get("messageId"),m=d.searchParams.get("properties");g&&(m&&(m=JSON.parse(atob(m))),await it.showMessage({messageId:g,properties:m}));break;case"loadPage":(d=d.href.substring(d.href.indexOf("?url=")+5))&&(d.startsWith("mailto:")||d.startsWith("https://")||d.startsWith("http://")||d.startsWith("/")?window.location.href=d:window.location.href=window.location+d)}}catch{}break;case"changeMessageStep":var p=e.data.gist.parameters.displaySettings,f=e.data.gist.parameters.messageStepName;(n.persistent||be(s))&&await async function(e,t,s){const n=await Te(e);if(!n)return;const a=r(n)||{},u={stepName:void 0!==t?t:a.stepName,displaySettings:void 0!==s?s:a.displaySettings},c=new Date;c.setDate(c.getDate()+30),o(n,u,c),i(`Saved message state for queueId: ${e}`)}(s.queueId,f,p),p&&Z(s,p)&&(i("Display settings changed, reloading message"),await async function(e){e.overlay?await ce():se(e.elementId)}(s),ee(s,p),await async function(e,t){e.isDisplayChange=!0,e.renderStartTime=(new Date).getTime();var s=e.elementId||null;if(s){const t=Q(s);t&&t.instanceId!==e.instanceId&&(i(`Dismissing existing message at ${s} to make room for multi-step message`),await Pe(t))}if(e.overlay){it.overlayInstanceId=e.instanceId;var n=V(e);e.shouldScale=n.shouldScale,e.shouldResizeHeight=!0}else it.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!ne(s);s&&j.includes(s)&&z(s);We(e,s,t)}(s,f));break;case"routeChanged":s.currentRoute=e.data.gist.parameters.route,s.renderStartTime=(new Date).getTime(),K(t,s),i(`Route changed to: ${s.currentRoute}`);break;case"sizeChanged":i(`Size Changed Width: ${e.data.gist.parameters.width} - Height: ${e.data.gist.parameters.height}`),s.elementId&&!s.shouldResizeHeight||function(e,t){var s=me(e.elementId?e.elementId:de(e.instanceId));if(s){var n=s.style;if(t.height>0)if(t.height>window.innerHeight){var i=1-(t.height/window.innerHeight-1);e.shouldScale&&i>=.4?(n.height=`${t.height}px`,n.transform=`translateX(-50%) translateY(-50%) scale(${i})`):n.height=`${window.innerHeight}px`}else n.height=`${t.height}px`}}(s,e.data.gist.parameters);break;case"titleChanged":i(`Overlay title changed to: ${e.data.gist.parameters.title}`),function(e,t){var s=me(de(e));s&&(s.title=t)}(t,e.data.gist.parameters.title);break;case"eventDispatched":it.events.dispatch("eventDispatched",{name:e.data.gist.parameters.name,payload:e.data.gist.parameters.payload});break;case"error":case"routeError":it.messageError(s),it.overlayInstanceId?Ne(!1,s):Ae(s)}}var h,w}async function He(e){i(`Logging user message view locally for: ${e.queueId}`),ye(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await Se();if(!t)return;const s=await ve(t,e);if(!s)return;const{broadcast:n}=s.properties.gist,a=Ie(t,e),u=xe(t,e);let c=r(a)||0;if(o(a,c+1),1===n.frequency.count)o(u,!1),i(`Marked broadcast ${e} as seen.`);else{let t=new Date;t.setSeconds(t.getSeconds()+n.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 De();if(!t)return;const s=r(t)??[];s.push(e),o(t,s)}(e.queueId)}async function Ge(e){ye(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await Se();if(!t)return;const s=await ve(t,e);if(!s)return;const{broadcast:n}=s.properties.gist;if(!0===n.frequency.ignoreDismiss)return void i(`Broadcast ${e} is set to ignore dismiss.`);o(xe(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)}(e.queueId),await Me(e.queueId))}const Ve="messageInboxUpdated";async function je(e){const t=await Be();if(!t)return;const s=new Date;s.setMinutes(s.getMinutes()+60),o(t,e,s),it.events.dispatch(Ve,e)}async function ze(){const e=await Be();if(!e)return[];const t=r(e)??[],s=new Date;return t.filter((e=>{if(!e.expiry)return!0;return new Date(e.expiry)>s}))}async function Fe(e,t){const s=await Be();if(!s)return;const n=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(!n||n.status<200||n.status>=300){const e=`Failed to mark inbox message opened: ${n?.status||"unknown error"}`;throw i(e),new Error(e)}const a=await ze();let r=null;const u=a.map((s=>s.queueId===e?(s.opened=t,r=s,{...s}):s)),c=new Date;if(c.setMinutes(c.getMinutes()+60),o(s,u,c),r){const e=t?"opened":"unopened";it.events.dispatch("inboxMessageAction",{message:r,action:e})}it.events.dispatch(Ve,await ze())}async function Be(){const e=await O();return e?`gist.web.inbox.messages.${e}`:null}var Je=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>Je(e,t)))),Qe=!1;let Xe=null;async function Ke(){Qe?await Ye():U()?(i("Queue watcher started"),Qe=!0,Je((()=>new Promise((()=>async function(){if(E.hasActiveSSEConnection())return!E.isSSEConnectionManagedBySDK()&&Xe&&(i("Not the main instance, closing our SSE connection."),tt()),void await Ye();Xe&&(i("SSE connection not active, closing it."),tt());if(E.useSSE()&&!W())return void await async function(){tt();const e=(t=H(),null===t?(i("No user token available for SSE endpoint."),null):E.GIST_QUEUE_REALTIME_API_ENDPOINT[it.config.env]+`/api/v3/sse?userToken=${t}&siteId=${it.config.siteId}&sessionId=${P()}`);var t;if(null===e)return i("SSE endpoint not available, falling back to polling."),void await et();i(`Starting SSE queue listener on ${e}`),Xe=new EventSource(e),E.setActiveSSEConnection(),Xe.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 et()})),Xe.addEventListener("messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE message received:"),await $e(t),await we(t),await Ye()}catch(e){i("Failed to parse SSE message"),tt()}})),Xe.addEventListener("inbox_messages",(async e=>{try{var t=JSON.parse(e.data);i("SSE inbox messages received:"),await je(t)}catch(e){i("Failed to parse SSE inbox messages")}})),Xe.addEventListener("error",(async e=>{i("SSE error received:"),tt()})),Xe.addEventListener("heartbeat",(async e=>{i("SSE heartbeat received:"),E.setActiveSSEConnection(),E.setUseSSEFlag(!0)}))}();await et()}()))),1e3)):i("User token not setup, queue not started.")}async function Ye(){var e=await async function(){const e=await Se();return e?(r(e)??[]).filter((t=>{const{broadcast:s}=t.properties.gist,n=r(xe(e,t.queueId))??!0,i=r(Ie(e,t.queueId))||0,a=0===s.frequency.count;return n&&(a||i<s.frequency.count)})):[]}(),t=await Ee(),s=e.concat(t);i(`Messages in local queue: ${s.length}`);var n=s.sort(((e,t)=>e.priority-t.priority));for(const e of n)await Ze(e)}async function Ze(e){var t=V(e);if(t.hasRouteRule){var s=it.currentRoute;null==s&&(s=new URL(window.location.href).pathname);var n=t.routeRule;if(i(`Verifying route ${s} against rule: ${n}`),!new RegExp(n).test(s))return i(`Route ${s} does not match rule.`),!1}if(t.hasPosition&&(e.position=t.position),t.persistent||be(e)){const s=await async function(e){const t=await Te(e);return t?r(t):null}(e.queueId);s&&(i(`Restoring saved state for queueId ${e.queueId}`),s.displaySettings&&(ee(e,s.displaySettings),t=V(e)),e.savedStepName=s.stepName)}if(t.persistent||be(e)||!await async function(e){const t=await ke(e);return!!t&&null!==r(t)}(e.queueId)){var a=!1;return(a=t.isEmbedded?Re(e,t.elementId):await qe(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 et(){if(U())if(it.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||[],s=e.data?.inboxMessages||[];$e(t),we(t),je(s)}else 304===e.status&&i("304 response, using local store.");await Ye()}else i("No response object returned while checking message queue.")}else i("Next queue pull scheduled for later.");else i("Document not visible, skipping queue check.");else i("User token reset, skipping queue check.")}function tt(e=!1){e&&E.removeActiveSSEConnection(),(e||E.isSSEConnectionManagedBySDK())&&E.setUseSSEFlag(!1),Xe&&(i("Stopping SSE queue listener..."),Xe.close(),Xe=null)}const st="cioPreviewId";function nt(){const e=new URLSearchParams(window.location.search).get(st);var t;return e&&(t=!1,sessionStorage.setItem(a,t),it.setUserToken(e),i(`Preview mode enabled with user token: ${e}`)),!c()}var it=class{static async setup(e){this.events=new n,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||new URLSearchParams(location.search).has("ajs_uid")||_(),await Ke(),document.addEventListener("visibilitychange",(async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Ye())}),!1)}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await Ye()}static async setUserToken(e,t){this.config.isPreviewSession||(!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),o(L,e,t),W()&&(u(M),u(A)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),tt(!0),await Ke())}static setUserLocale(e){var t;o(D,t=e),i(`Set user locate to "${t}"`)}static setCustomAttribute(e,t){return function(e,t){return e&&"string"==typeof e?(fe.set(e,t),he(),i(`Set custom attribute "${e}" to "${t}"`),!0):(i(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){fe.clear(),u(pe),i("Cleared all custom attributes")}static removeCustomAttribute(e){return function(e){if(!e||"string"!=typeof e)return i(`Invalid key for custom attribute: ${e}`),!1;const t=fe.has(e);return fe.delete(e),fe.size>0?he():u(pe),i(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(u(L),i("Cleared user token"),this.config.useAnonymousSession&&_(),tt(!0),await Ke())}static async dismissMessage(e){var t=B(e);await Pe(t),await Le(t),await Ge(t),await Ye()}static async embedMessage(e,t){var s=Re(e,t);return s?s.instanceId:null}static async showMessage(e){var t=await qe(e);return t?t.instanceId:null}static updateMessageDisplaySettings(e,t){var s=B(e);return!!s&&(s.displaySettings=t,re(s),!0)}static messageShown(e){i(`Message shown: ${e.messageId}`),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(i(`Message dismissed: ${e.messageId}`),this.events.dispatch("messageDismissed",e))}static messageError(e){i(`Message error: ${e.messageId}`),this.events.dispatch("messageError",e)}static messageAction(e,t,s){i(`Message action: ${e.currentRoute}, ${t} with name ${s} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:s})}static async getInboxUnopenedCount(){return(await ze()).filter((e=>!e.opened)).length}static async getInboxMessages(){return await ze()}static async updateInboxMessageOpenState(e,t){return await Fe(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await Be();if(!t)return;const s=await G(e);if(!s||s.status<200||s.status>=300){const e=`Failed to remove inbox message: ${s?.status||"unknown error"}`;throw i(e),new Error(e)}const n=(await ze()).filter((t=>t.queueId!==e)),a=new Date;a.setMinutes(a.getMinutes()+60),o(t,n,a),it.events.dispatch(Ve,await ze())}(e)}}},7852:function(e,t,s){const n=s(4587).A;e.exports=n}}]);
|
package/dist/umd/852.js.gz
CHANGED
|
Binary file
|
package/dist/umd/inAppPlugin.js
CHANGED
|
@@ -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
|
|
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
|