@customerio/cdp-analytics-browser 0.3.14 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/generated/version.js +1 -1
- package/dist/cjs/plugins/in-app-plugin/index.js +6 -4
- package/dist/cjs/plugins/in-app-plugin/index.js.map +1 -1
- package/dist/pkg/generated/version.js +1 -1
- package/dist/pkg/plugins/in-app-plugin/index.js +6 -4
- package/dist/pkg/plugins/in-app-plugin/index.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/umd/573.js +1 -0
- package/dist/umd/573.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/index.ts +8 -4
- package/dist/umd/852.js +0 -1
- package/dist/umd/852.js.gz +0 -0
|
@@ -73,7 +73,7 @@ export function InAppPlugin(settings: InAppPluginSettings): Plugin {
|
|
|
73
73
|
deliveryId: deliveryId,
|
|
74
74
|
message: {
|
|
75
75
|
dismiss: function () {
|
|
76
|
-
Gist.dismissMessage(message?.instanceId)
|
|
76
|
+
void Gist.dismissMessage(message?.instanceId)
|
|
77
77
|
},
|
|
78
78
|
},
|
|
79
79
|
})
|
|
@@ -121,7 +121,7 @@ export function InAppPlugin(settings: InAppPluginSettings): Plugin {
|
|
|
121
121
|
actionValue: params.action,
|
|
122
122
|
message: {
|
|
123
123
|
dismiss: function () {
|
|
124
|
-
Gist.dismissMessage(params.message.instanceId)
|
|
124
|
+
void Gist.dismissMessage(params.message.instanceId)
|
|
125
125
|
},
|
|
126
126
|
},
|
|
127
127
|
})
|
|
@@ -179,7 +179,7 @@ export function InAppPlugin(settings: InAppPluginSettings): Plugin {
|
|
|
179
179
|
const page: string =
|
|
180
180
|
ctx.event?.properties?.name ?? ctx.event?.properties?.url
|
|
181
181
|
if (typeof page === 'string' && page.length > 0) {
|
|
182
|
-
Gist.setCurrentRoute(page)
|
|
182
|
+
void Gist.setCurrentRoute(page)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
return ctx
|
|
@@ -265,7 +265,11 @@ function _handleInboxMessageAction(
|
|
|
265
265
|
action: string
|
|
266
266
|
) {
|
|
267
267
|
const deliveryId = message?.deliveryId
|
|
268
|
-
if (
|
|
268
|
+
if (
|
|
269
|
+
action === 'opened' &&
|
|
270
|
+
typeof deliveryId !== 'undefined' &&
|
|
271
|
+
deliveryId !== ''
|
|
272
|
+
) {
|
|
269
273
|
void analyticsInstance.track(JourneysEvents.Metric, {
|
|
270
274
|
deliveryId: message.deliveryId,
|
|
271
275
|
metric: JourneysEvents.Opened,
|
package/dist/umd/852.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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=[],y=0;y<256;++y)w.push((y+256).toString(16).substr(1));var v=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 v(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 z(e){try{return await C().post(`/api/v1/logs/queue/${e}`)}catch(e){return e.response}}function G(e){const t={isEmbedded:!1,elementId:"",hasRouteRule:!1,routeRule:"",position:"",hasPosition:!1,shouldScale:!1,campaignId:null,messageWidth:414,overlayColor:"#00000033",persistent:!1,exitClick:!1,hasCustomWidth:!1},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 V=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function j(e){if(document.getElementById(e))return;const t=document.createElement("div");if(t.id=e,"x-gist-top"===e)document.body.insertBefore(t,document.body.firstChild);else document.body.insertAdjacentElement("beforeend",t);i("Top & bottom elements injected into page")}const F=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function B(e){return it.currentMessages.find((t=>t.instanceId===e))}function J(e){return!!e&&it.currentMessages.some((t=>t.queueId===e))}function Q(e){return e?it.currentMessages.find((t=>t.elementId===e)):null}function X(e){it.currentMessages=it.currentMessages.filter((t=>t.instanceId!==e))}function K(e,t){X(e),it.currentMessages.push(t)}function Y(e){const t={topLeft:"x-gist-floating-top-left",topCenter:"x-gist-floating-top",topRight:"x-gist-floating-top-right",bottomLeft:"x-gist-floating-bottom-left",bottomCenter:"x-gist-floating-bottom",bottomRight:"x-gist-floating-bottom-right"};return e&&t[e]?t[e]:(i(`Invalid overlay position "${e}", defaulting to "topCenter"`),t.topCenter)}function Z(e,t){const s=(n=e).overlay?"modal":n.elementId&&V.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=G(e);switch(i){case"modal":if((e.position||"center")!==(t.modalPosition||"center"))return!0;if(void 0!==t.dismissOutsideClick&&a.exitClick!==t.dismissOutsideClick)return!0;if(void 0!==t.overlayColor&&a.overlayColor!==t.overlayColor)return!0;break;case"overlay":{const 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=G(s),c=u.messageWidth+"px";F.includes(e)&&!u.hasCustomWidth&&(c="100%"),V.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.querySelectorAll("#gist-embed-message").forEach((function(e){e.parentNode.removeChild(e)})),document.body.insertAdjacentHTML("afterbegin",function(e,t){var s=G(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=G(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(ve),s)}async function ye(e,t){return r(e).find((e=>e.queueId===t))}function ve(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}function be(e){if(!ve(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=G(e);e.instanceId=b(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),it.overlayInstanceId=e.instanceId,it.currentMessages.push(e);return We(e,null,e.savedStepName||null)}return i("Document hidden, not showing message now."),null}function Re(e,t){if(it.isDocumentVisible){if(J(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;if(Q(t))return i(`Message with elementId ${t} already has a message.`),null;e.instanceId=b(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!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=G(e);e?t.persistent&&(i("Persistent message dismissed, logging view"),await He(e),await Ue(e),await Me(e.queueId)):i(`Message with instance id: ${e.instanceId} not found`)}function 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?(V.includes(t)&&j(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 z(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=G(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 ze(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=G(e);e.shouldScale=n.shouldScale,e.shouldResizeHeight=!0}else it.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!ne(s);s&&V.includes(s)&&j(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}`),ve(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await Se();if(!t)return;const s=await ye(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 ze(e){ve(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 ye(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 Ge="messageInboxUpdated";async function Ve(e){const t=await Be();if(!t)return;const s=new Date;s.setMinutes(s.getMinutes()+60),o(t,e,s),it.events.dispatch(Ge,e)}async function je(){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 je();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(Ge,await je())}async function Be(){const e=await O();return e?`gist.web.inbox.messages.${e}`:null}var Je=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>Je(e,t)))),Qe=!1;let Xe=null;async function Ke(){Qe?await Ye():U()?(i("Queue watcher started"),Qe=!0,Je((()=>new Promise((()=>async function(){if(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 Ve(t)}catch(e){i("Failed to parse SSE inbox messages")}})),Xe.addEventListener("error",(async e=>{i("SSE error received:"),tt()})),Xe.addEventListener("heartbeat",(async e=>{i("SSE heartbeat received:"),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=G(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=G(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),Ve(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.initialized?i("Gist SDK already initialized, skipping setup."):(this.initialized=!0,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 ze(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 je()).filter((e=>!e.opened)).length}static async getInboxMessages(){return await je()}static async updateInboxMessageOpenState(e,t){return await Fe(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await Be();if(!t)return;const s=await z(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 je()).filter((t=>t.queueId!==e)),a=new Date;a.setMinutes(a.getMinutes()+60),o(t,n,a),it.events.dispatch(Ge,await je())}(e)}}},7852:function(e,t,s){const n=s(4587).A;e.exports=n}}]);
|
package/dist/umd/852.js.gz
DELETED
|
Binary file
|