@contentful/optimization-web 0.1.0-alpha
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/LICENSE +21 -0
- package/README.md +491 -0
- package/dist/AutoEntryViewTracking.d.ts +88 -0
- package/dist/AutoEntryViewTracking.d.ts.map +1 -0
- package/dist/Optimization.d.ts +146 -0
- package/dist/Optimization.d.ts.map +1 -0
- package/dist/analyzer.html +4 -0
- package/dist/builders/EventBuilder.d.ts +42 -0
- package/dist/builders/EventBuilder.d.ts.map +1 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/contentful-optimization-web.umd.cjs +2 -0
- package/dist/contentful-optimization-web.umd.cjs.map +1 -0
- package/dist/global-constants.d.ts +37 -0
- package/dist/global-constants.d.ts.map +1 -0
- package/dist/handlers/beaconHandler.d.ts +24 -0
- package/dist/handlers/beaconHandler.d.ts.map +1 -0
- package/dist/handlers/createOnlineChangeListener.d.ts +34 -0
- package/dist/handlers/createOnlineChangeListener.d.ts.map +1 -0
- package/dist/handlers/createVisibilityChangeListener.d.ts +40 -0
- package/dist/handlers/createVisibilityChangeListener.d.ts.map +1 -0
- package/dist/handlers/index.d.ts +4 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6244 -0
- package/dist/index.js.map +1 -0
- package/dist/observers/ElementExistenceObserver.d.ts +195 -0
- package/dist/observers/ElementExistenceObserver.d.ts.map +1 -0
- package/dist/observers/ElementView.d.ts +178 -0
- package/dist/observers/ElementView.d.ts.map +1 -0
- package/dist/observers/ElementViewObserver.d.ts +164 -0
- package/dist/observers/ElementViewObserver.d.ts.map +1 -0
- package/dist/observers/index.d.ts +6 -0
- package/dist/observers/index.d.ts.map +1 -0
- package/dist/storage/LocalStore.d.ts +111 -0
- package/dist/storage/LocalStore.d.ts.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/test/helpers.d.ts +41 -0
- package/dist/test/helpers.d.ts.map +1 -0
- package/dist/visualizer.html +4687 -0
- package/package.json +28 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const OPTIMIZATION_WEB_SDK_VERSION: string;
|
|
2
|
+
/**
|
|
3
|
+
* Name of the cookie used by the Optimization Core to persist an anonymous ID.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
* @remarks
|
|
7
|
+
* Re-exported here to provide a stable Web SDK import path. The value itself
|
|
8
|
+
* is defined and maintained in `@contentful/optimization-core`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { ANONYMOUS_ID_COOKIE } from '@contentful/optimization-web/global-constants'
|
|
13
|
+
*
|
|
14
|
+
* const anonId = Cookies.get(ANONYMOUS_ID_COOKIE)
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export { ANONYMOUS_ID_COOKIE } from '@contentful/optimization-core';
|
|
18
|
+
/**
|
|
19
|
+
* Flag indicating whether the current environment can safely add DOM
|
|
20
|
+
* event listeners.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
* @remarks
|
|
24
|
+
* Many Web SDK utilities short-circuit to no-ops when this flag is `false`
|
|
25
|
+
* (e.g., during server-side rendering).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { CAN_ADD_LISTENERS } from '@contentful/optimization-web/global-constants'
|
|
30
|
+
*
|
|
31
|
+
* if (CAN_ADD_LISTENERS) {
|
|
32
|
+
* window.addEventListener('resize', onResize)
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const CAN_ADD_LISTENERS: boolean;
|
|
37
|
+
//# sourceMappingURL=global-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-constants.d.ts","sourceRoot":"","sources":["../src/global-constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B,QAC0C,CAAA;AAEnF;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAEnE;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iBAAiB,SAGmB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BatchInsightsEventArray } from '@contentful/optimization-core';
|
|
2
|
+
/**
|
|
3
|
+
* Send a batch of analytics events using `navigator.sendBeacon`.
|
|
4
|
+
*
|
|
5
|
+
* @param url - The endpoint URL to which the beacon request should be sent.
|
|
6
|
+
* @param events - The batch of events to serialize and send.
|
|
7
|
+
* @returns `true` if the user agent successfully queued the data for transfer,
|
|
8
|
+
* otherwise `false`.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @remarks
|
|
12
|
+
* This is intended for fire-and-forget flushing of analytics events during
|
|
13
|
+
* lifecycle transitions (e.g., page unload or visibility change).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const ok = beaconHandler('/analytics/batch', batchEvents)
|
|
18
|
+
* if (!ok) {
|
|
19
|
+
* // Optionally fall back to XHR/fetch
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function beaconHandler(url: string | URL, events: BatchInsightsEventArray): boolean;
|
|
24
|
+
//# sourceMappingURL=beaconHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beaconHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/beaconHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAE5E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAMzF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback invoked when the browser's connectivity state changes.
|
|
3
|
+
*
|
|
4
|
+
* The callback receives `true` when the browser is online and `false` when it is offline.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
type Callback = (isOnline: boolean) => Promise<void> | void;
|
|
9
|
+
/**
|
|
10
|
+
* Create an online/offline listener that invokes a callback whenever the browser transitions
|
|
11
|
+
* between connectivity states, and returns a cleanup function to remove all listeners.
|
|
12
|
+
*
|
|
13
|
+
* @param callback - Function invoked when the browser goes online (`true`) or offline (`false`).
|
|
14
|
+
* May return a promise.
|
|
15
|
+
* @returns A function that removes the registered event listeners when called.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
* @remarks
|
|
19
|
+
* - If the environment cannot add listeners (e.g., SSR), a no-op cleanup function is returned.
|
|
20
|
+
* - If `navigator.onLine` is available, the callback is invoked immediately with the initial state.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const cleanup = createOnlineChangeListener(async (isOnline) => {
|
|
25
|
+
* if (isOnline) await sdk.analytics.flush()
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Later:
|
|
29
|
+
* cleanup()
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function createOnlineChangeListener(callback: Callback): () => void;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=createOnlineChangeListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOnlineChangeListener.d.ts","sourceRoot":"","sources":["../../src/handlers/createOnlineChangeListener.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,KAAK,QAAQ,GAAG,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAkCzE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event type for browser page-hide / visibility-change events.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
type HideEvent = Event | PageTransitionEvent;
|
|
7
|
+
/**
|
|
8
|
+
* Callback type invoked when the page is being hidden.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
type Callback = (event: HideEvent) => Promise<void> | void;
|
|
13
|
+
/**
|
|
14
|
+
* Create a visibility-change listener that invokes a callback when the page
|
|
15
|
+
* is hidden, and returns a cleanup function to remove all listeners.
|
|
16
|
+
*
|
|
17
|
+
* @param callback - Function invoked once when the page is being hidden, or
|
|
18
|
+
* when a pagehide event occurs. May return a promise.
|
|
19
|
+
* @returns A function that removes all registered event listeners when called.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @remarks
|
|
23
|
+
* The callback is guaranteed to be invoked at most once per hide cycle until
|
|
24
|
+
* the next visibility or page show event resets the internal state. If the
|
|
25
|
+
* environment does not permit adding listeners (e.g., server-side rendering),
|
|
26
|
+
* a no-op cleanup function is returned.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const cleanup = createVisibilityChangeListener(async () => {
|
|
31
|
+
* await flushPendingEvents()
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* // Later, when teardown is needed:
|
|
35
|
+
* cleanup()
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function createVisibilityChangeListener(callback: Callback): () => void;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=createVisibilityChangeListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVisibilityChangeListener.d.ts","sourceRoot":"","sources":["../../src/handlers/createVisibilityChangeListener.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,KAAK,SAAS,GAAG,KAAK,GAAG,mBAAmB,CAAA;AAE5C;;;;GAIG;AACH,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAoD7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,kCAAkC,CAAA"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var ji=Symbol.for("preact-signals");function _t(){if(Y>1)Y--;else{for(var t,e=!1;Ne!==void 0;){var n=Ne;for(Ne=void 0,Dt++;n!==void 0;){var r=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&qn(n))try{n.c()}catch(i){e||(t=i,e=!0)}n=r}}if(Dt=0,Y--,e)throw t}}function be(t){if(Y>0)return t();Y++;try{return t()}finally{_t()}}var v=void 0;function Zn(t){var e=v;v=void 0;try{return t()}finally{v=e}}var Ne=void 0,Y=0,Dt=0,ft=0;function Fn(t){if(v!==void 0){var e=t.n;if(e===void 0||e.t!==v)return e={i:0,S:t,p:v.s,n:void 0,t:v,e:void 0,x:void 0,r:e},v.s!==void 0&&(v.s.n=e),v.s=e,t.n=e,32&v.f&&t.S(e),e;if(e.i===-1)return e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=v.s,e.n=void 0,v.s.n=e,v.s=e),e}}function $(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.W=e?.watched,this.Z=e?.unwatched,this.name=e?.name}$.prototype.brand=ji;$.prototype.h=function(){return!0};$.prototype.S=function(t){var e=this,n=this.t;n!==t&&t.e===void 0&&(t.x=n,this.t=t,n!==void 0?n.e=t:Zn(function(){var r;(r=e.W)==null||r.call(e)}))};$.prototype.U=function(t){var e=this;if(this.t!==void 0){var n=t.e,r=t.x;n!==void 0&&(n.x=r,t.e=void 0),r!==void 0&&(r.e=n,t.x=void 0),t===this.t&&(this.t=r,r===void 0&&Zn(function(){var i;(i=e.Z)==null||i.call(e)}))}};$.prototype.subscribe=function(t){var e=this;return V(function(){var n=e.value,r=v;v=void 0;try{t(n)}finally{v=r}},{name:"sub"})};$.prototype.valueOf=function(){return this.value};$.prototype.toString=function(){return this.value+""};$.prototype.toJSON=function(){return this.value};$.prototype.peek=function(){var t=v;v=void 0;try{return this.value}finally{v=t}};Object.defineProperty($.prototype,"value",{get:function(){var t=Fn(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(Dt>100)throw new Error("Cycle detected");this.v=t,this.i++,ft++,Y++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{_t()}}}});function Ee(t,e){return new $(t,e)}function qn(t){for(var e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function Hn(t){for(var e=t.s;e!==void 0;e=e.n){var n=e.S.n;if(n!==void 0&&(e.r=n),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function Kn(t){for(var e=t.s,n=void 0;e!==void 0;){var r=e.p;e.i===-1?(e.S.U(e),r!==void 0&&(r.n=e.n),e.n!==void 0&&(e.n.p=r)):n=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=r}t.s=n}function de(t,e){$.call(this,void 0),this.x=t,this.s=void 0,this.g=ft-1,this.f=4,this.W=e?.watched,this.Z=e?.unwatched,this.name=e?.name}de.prototype=new $;de.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ft))return!0;if(this.g=ft,this.f|=1,this.i>0&&!qn(this))return this.f&=-2,!0;var t=v;try{Hn(this),v=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return v=t,Kn(this),this.f&=-2,!0};de.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var e=this.s;e!==void 0;e=e.n)e.S.S(e)}$.prototype.S.call(this,t)};de.prototype.U=function(t){if(this.t!==void 0&&($.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var e=this.s;e!==void 0;e=e.n)e.S.U(e)}};de.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}};Object.defineProperty(de.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=Fn(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function Ui(t,e){return new de(t,e)}function Wn(t){var e=t.u;if(t.u=void 0,typeof e=="function"){Y++;var n=v;v=void 0;try{e()}catch(r){throw t.f&=-2,t.f|=8,Yt(t),r}finally{v=n,_t()}}}function Yt(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,Wn(t)}function Di(t){if(v!==this)throw new Error("Out-of-order effect");Kn(this),v=t,this.f&=-2,8&this.f&&Yt(this),_t()}function Se(t,e){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=e?.name}Se.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var e=this.x();typeof e=="function"&&(this.u=e)}finally{t()}};Se.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Wn(this),Hn(this),Y++;var t=v;return v=this,Di.bind(this,t)};Se.prototype.N=function(){2&this.f||(this.f|=2,this.o=Ne,Ne=this)};Se.prototype.d=function(){this.f|=8,1&this.f||Yt(this)};Se.prototype.dispose=function(){this.d()};function V(t,e){var n=new Se(t,e);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}const pt={resolve(t){return t?t.reduce((e,{key:n,value:r})=>{const i=typeof r=="object"&&r!==null&&"value"in r&&typeof r.value=="object"?r.value:r;return e[n]=i,e},{}):{}}};function p(t,e,n){function r(a,c){var u;Object.defineProperty(a,"_zod",{value:a._zod??{},enumerable:!1}),(u=a._zod).traits??(u.traits=new Set),a._zod.traits.add(t),e(a,c);for(const d in s.prototype)d in a||Object.defineProperty(a,d,{value:s.prototype[d].bind(a)});a._zod.constr=s,a._zod.def=c}const i=n?.Parent??Object;class o extends i{}Object.defineProperty(o,"name",{value:t});function s(a){var c;const u=n?.Parent?new o:this;r(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const d of u._zod.deferred)d();return u}return Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(t)}),Object.defineProperty(s,"name",{value:t}),s}class _e extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Zi extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Fi={};function ze(t){return Fi}function qi(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,i])=>e.indexOf(+r)===-1).map(([r,i])=>i)}function Hi(t,e){return typeof e=="bigint"?e.toString():e}function Gn(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function Jn(t){return t==null}function en(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}const bn=Symbol("evaluating");function E(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==bn)return r===void 0&&(r=bn,r=n()),r},set(i){Object.defineProperty(t,e,{value:i})},configurable:!0})}function tn(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Qn(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}const Xn="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function ht(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function nn(t){if(ht(t)===!1)return!1;const e=t.constructor;if(e===void 0)return!0;const n=e.prototype;return!(ht(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Ki(t){return nn(t)?{...t}:t}const Wi=new Set(["string","number","symbol"]);function Zt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rn(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n?.parent)&&(r._zod.parent=t),r}function R(t){return{}}function Gi(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}function Ji(t,e){if(!nn(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const i=Qn(t._zod.def,{get shape(){const o={...t._zod.def.shape,...e};return tn(this,"shape",o),o},checks:[]});return rn(t,i)}function Qi(t,e,n){const r=Qn(e._zod.def,{get shape(){const i=e._zod.def.shape,o={...i};for(const s in i)o[s]=t?new t({type:"optional",innerType:i[s]}):i[s];return tn(this,"shape",o),o},checks:[]});return rn(e,r)}function Oe(t,e=0){if(t.aborted===!0)return!0;for(let n=e;n<t.issues.length;n++)if(t.issues[n]?.continue!==!0)return!0;return!1}function ve(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function Xe(t){return typeof t=="string"?t:t?.message}function Te(t,e,n){const r={...t,path:t.path??[]};if(!t.message){const i=Xe(t.inst?._zod.def?.error?.(t))??Xe(e?.error?.(t))??Xe(n.customError?.(t))??Xe(n.localeError?.(t))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,e?.reportInput||delete r.input,r}function Yn(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Xi(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const er=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,Hi,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Yi=p("$ZodError",er),wt=p("$ZodError",er,{Parent:Error}),eo=t=>(e,n,r,i)=>{const o=r?Object.assign(r,{async:!1}):{async:!1},s=e._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new _e;if(s.issues.length){const a=new(i?.Err??t)(s.issues.map(c=>Te(c,o,ze())));throw Xn(a,i?.callee),a}return s.value},to=eo(wt),no=t=>async(e,n,r,i)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=e._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){const a=new(i?.Err??t)(s.issues.map(c=>Te(c,o,ze())));throw Xn(a,i?.callee),a}return s.value},ro=no(wt),io=t=>(e,n,r)=>{const i=r?{...r,async:!1}:{async:!1},o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new _e;return o.issues.length?{success:!1,error:new(t??Yi)(o.issues.map(s=>Te(s,i,ze())))}:{success:!0,data:o.value}},tr=io(wt),oo=t=>async(e,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=e._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new t(o.issues.map(s=>Te(s,i,ze())))}:{success:!0,data:o.value}},nr=oo(wt),so="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function ao(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function co(t){const e=ao({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${e}(?:${n.join("|")})`;return new RegExp(`^${so}T(?:${r})$`)}const uo=t=>{const e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},lo=/^-?\d+(?:\.\d+)?/i,fo=/true|false/i,po=/null/i,Et=p("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),ho=p("$ZodCheckMinLength",(t,e)=>{var n;Et.init(t,e),(n=t._zod.def).when??(n.when=r=>{const i=r.value;return!Jn(i)&&i.length!==void 0}),t._zod.onattach.push(r=>{const i=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>i&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const i=r.value;if(i.length>=e.minimum)return;const s=Yn(i);r.issues.push({origin:s,code:"too_small",minimum:e.minimum,inclusive:!0,input:i,inst:t,continue:!e.abort})}}),go=p("$ZodCheckLengthEquals",(t,e)=>{var n;Et.init(t,e),(n=t._zod.def).when??(n.when=r=>{const i=r.value;return!Jn(i)&&i.length!==void 0}),t._zod.onattach.push(r=>{const i=r._zod.bag;i.minimum=e.length,i.maximum=e.length,i.length=e.length}),t._zod.check=r=>{const i=r.value,o=i.length;if(o===e.length)return;const s=Yn(i),a=o>e.length;r.issues.push({origin:s,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),vo=p("$ZodCheckStringFormat",(t,e)=>{var n,r;Et.init(t,e),t._zod.onattach.push(i=>{const o=i._zod.bag;o.format=e.format,e.pattern&&(o.patterns??(o.patterns=new Set),o.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=i=>{e.pattern.lastIndex=0,!e.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:e.format,input:i.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),yo={major:4,minor:1,patch:5},z=p("$ZodType",(t,e)=>{var n;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=yo;const r=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&r.unshift(t);for(const i of r)for(const o of i._zod.onattach)o(t);if(r.length===0)(n=t._zod).deferred??(n.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const i=(s,a,c)=>{let u=Oe(s),d;for(const m of a){if(m._zod.def.when){if(!m._zod.def.when(s))continue}else if(u)continue;const _=s.issues.length,S=m._zod.check(s);if(S instanceof Promise&&c?.async===!1)throw new _e;if(d||S instanceof Promise)d=(d??Promise.resolve()).then(async()=>{await S,s.issues.length!==_&&(u||(u=Oe(s,_)))});else{if(s.issues.length===_)continue;u||(u=Oe(s,_))}}return d?d.then(()=>s):s},o=(s,a,c)=>{if(Oe(s))return s.aborted=!0,s;const u=i(a,r,c);if(u instanceof Promise){if(c.async===!1)throw new _e;return u.then(d=>t._zod.parse(d,c))}return t._zod.parse(u,c)};t._zod.run=(s,a)=>{if(a.skipChecks)return t._zod.parse(s,a);if(a.direction==="backward"){const u=t._zod.parse({value:s.value,issues:[]},{...a,skipChecks:!0});return u instanceof Promise?u.then(d=>o(d,s,a)):o(u,s,a)}const c=t._zod.parse(s,a);if(c instanceof Promise){if(a.async===!1)throw new _e;return c.then(u=>i(u,r,a))}return i(c,r,a)}}t["~standard"]={validate:i=>{try{const o=tr(t,i);return o.success?{value:o.data}:{issues:o.error?.issues}}catch{return nr(t,i).then(s=>s.success?{value:s.data}:{issues:s.error?.issues})}},vendor:"zod",version:1}}),rr=p("$ZodString",(t,e)=>{z.init(t,e),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??uo(t._zod.bag),t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:t}),n}}),ir=p("$ZodStringFormat",(t,e)=>{vo.init(t,e),rr.init(t,e)}),mo=p("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=co(e)),ir.init(t,e)}),bo=p("$ZodNumber",(t,e)=>{z.init(t,e),t._zod.pattern=t._zod.bag.pattern??lo,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=Number(n.value)}catch{}const i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;const o=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:t,...o?{received:o}:{}}),n}}),_o=p("$ZodBoolean",(t,e)=>{z.init(t,e),t._zod.pattern=fo,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=!!n.value}catch{}const i=n.value;return typeof i=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:t}),n}}),wo=p("$ZodNull",(t,e)=>{z.init(t,e),t._zod.pattern=po,t._zod.values=new Set([null]),t._zod.parse=(n,r)=>{const i=n.value;return i===null||n.issues.push({expected:"null",code:"invalid_type",input:i,inst:t}),n}}),Eo=p("$ZodAny",(t,e)=>{z.init(t,e),t._zod.parse=n=>n}),So=p("$ZodUnknown",(t,e)=>{z.init(t,e),t._zod.parse=n=>n});function _n(t,e,n){t.issues.length&&e.issues.push(...ve(n,t.issues)),e.value[n]=t.value}const zo=p("$ZodArray",(t,e)=>{z.init(t,e),t._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:t}),n;n.value=Array(i.length);const o=[];for(let s=0;s<i.length;s++){const a=i[s],c=e.element._zod.run({value:a,issues:[]},r);c instanceof Promise?o.push(c.then(u=>_n(u,n,s))):_n(c,n,s)}return o.length?Promise.all(o).then(()=>n):n}});function gt(t,e,n,r){t.issues.length&&e.issues.push(...ve(n,t.issues)),t.value===void 0?n in r&&(e.value[n]=void 0):e.value[n]=t.value}function To(t){const e=Object.keys(t.shape);for(const r of e)if(!t.shape[r]._zod.traits.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=Gi(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}}function Ao(t,e,n,r,i,o){const s=[],a=i.keySet,c=i.catchall._zod,u=c.def.type;for(const d of Object.keys(e)){if(a.has(d))continue;if(u==="never"){s.push(d);continue}const m=c.run({value:e[d],issues:[]},r);m instanceof Promise?t.push(m.then(_=>gt(_,n,d,e))):gt(m,n,d,e)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:e,inst:o}),t.length?Promise.all(t).then(()=>n):n}const Po=p("$ZodObject",(t,e)=>{z.init(t,e);const n=Gn(()=>To(e));E(t._zod,"propValues",()=>{const s=e.shape,a={};for(const c in s){const u=s[c]._zod;if(u.values){a[c]??(a[c]=new Set);for(const d of u.values)a[c].add(d)}}return a});const r=ht,i=e.catchall;let o;t._zod.parse=(s,a)=>{o??(o=n.value);const c=s.value;if(!r(c))return s.issues.push({expected:"object",code:"invalid_type",input:c,inst:t}),s;s.value={};const u=[],d=o.shape;for(const m of o.keys){const S=d[m]._zod.run({value:c[m],issues:[]},a);S instanceof Promise?u.push(S.then(b=>gt(b,s,m,c))):gt(S,s,m,c)}return i?Ao(u,c,s,a,n.value,t):u.length?Promise.all(u).then(()=>s):s}});function wn(t,e,n,r){for(const o of t)if(o.issues.length===0)return e.value=o.value,e;const i=t.filter(o=>!Oe(o));return i.length===1?(e.value=i[0].value,i[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:n,errors:t.map(o=>o.issues.map(s=>Te(s,r,ze())))}),e)}const or=p("$ZodUnion",(t,e)=>{z.init(t,e),E(t._zod,"optin",()=>e.options.some(i=>i._zod.optin==="optional")?"optional":void 0),E(t._zod,"optout",()=>e.options.some(i=>i._zod.optout==="optional")?"optional":void 0),E(t._zod,"values",()=>{if(e.options.every(i=>i._zod.values))return new Set(e.options.flatMap(i=>Array.from(i._zod.values)))}),E(t._zod,"pattern",()=>{if(e.options.every(i=>i._zod.pattern)){const i=e.options.map(o=>o._zod.pattern);return new RegExp(`^(${i.map(o=>en(o.source)).join("|")})$`)}});const n=e.options.length===1,r=e.options[0]._zod.run;t._zod.parse=(i,o)=>{if(n)return r(i,o);let s=!1;const a=[];for(const c of e.options){const u=c._zod.run({value:i.value,issues:[]},o);if(u instanceof Promise)a.push(u),s=!0;else{if(u.issues.length===0)return u;a.push(u)}}return s?Promise.all(a).then(c=>wn(c,i,t,o)):wn(a,i,t,o)}}),ko=p("$ZodDiscriminatedUnion",(t,e)=>{or.init(t,e);const n=t._zod.parse;E(t._zod,"propValues",()=>{const i={};for(const o of e.options){const s=o._zod.propValues;if(!s||Object.keys(s).length===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(o)}"`);for(const[a,c]of Object.entries(s)){i[a]||(i[a]=new Set);for(const u of c)i[a].add(u)}}return i});const r=Gn(()=>{const i=e.options,o=new Map;for(const s of i){const a=s._zod.propValues?.[e.discriminator];if(!a||a.size===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(s)}"`);for(const c of a){if(o.has(c))throw new Error(`Duplicate discriminator value "${String(c)}"`);o.set(c,s)}}return o});t._zod.parse=(i,o)=>{const s=i.value;if(!ht(s))return i.issues.push({code:"invalid_type",expected:"object",input:s,inst:t}),i;const a=r.value.get(s?.[e.discriminator]);return a?a._zod.run(i,o):e.unionFallback?n(i,o):(i.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:e.discriminator,input:s,path:[e.discriminator],inst:t}),i)}}),Co=p("$ZodRecord",(t,e)=>{z.init(t,e),t._zod.parse=(n,r)=>{const i=n.value;if(!nn(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:t}),n;const o=[];if(e.keyType._zod.values){const s=e.keyType._zod.values;n.value={};for(const c of s)if(typeof c=="string"||typeof c=="number"||typeof c=="symbol"){const u=e.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?o.push(u.then(d=>{d.issues.length&&n.issues.push(...ve(c,d.issues)),n.value[c]=d.value})):(u.issues.length&&n.issues.push(...ve(c,u.issues)),n.value[c]=u.value)}let a;for(const c in i)s.has(c)||(a=a??[],a.push(c));a&&a.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:t,keys:a})}else{n.value={};for(const s of Reflect.ownKeys(i)){if(s==="__proto__")continue;const a=e.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(a.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map(u=>Te(u,r,ze())),input:s,path:[s],inst:t}),n.value[a.value]=a.value;continue}const c=e.valueType._zod.run({value:i[s],issues:[]},r);c instanceof Promise?o.push(c.then(u=>{u.issues.length&&n.issues.push(...ve(s,u.issues)),n.value[a.value]=u.value})):(c.issues.length&&n.issues.push(...ve(s,c.issues)),n.value[a.value]=c.value)}}return o.length?Promise.all(o).then(()=>n):n}}),Io=p("$ZodEnum",(t,e)=>{z.init(t,e);const n=qi(e.entries),r=new Set(n);t._zod.values=r,t._zod.pattern=new RegExp(`^(${n.filter(i=>Wi.has(typeof i)).map(i=>typeof i=="string"?Zt(i):i.toString()).join("|")})$`),t._zod.parse=(i,o)=>{const s=i.value;return r.has(s)||i.issues.push({code:"invalid_value",values:n,input:s,inst:t}),i}}),$o=p("$ZodLiteral",(t,e)=>{if(z.init(t,e),e.values.length===0)throw new Error("Cannot create literal schema with no valid values");t._zod.values=new Set(e.values),t._zod.pattern=new RegExp(`^(${e.values.map(n=>typeof n=="string"?Zt(n):n?Zt(n.toString()):String(n)).join("|")})$`),t._zod.parse=(n,r)=>{const i=n.value;return t._zod.values.has(i)||n.issues.push({code:"invalid_value",values:e.values,input:i,inst:t}),n}}),Ro=p("$ZodTransform",(t,e)=>{z.init(t,e),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Zi(t.constructor.name);const i=e.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(s=>(n.value=s,n));if(i instanceof Promise)throw new _e;return n.value=i,n}});function En(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Oo=p("$ZodOptional",(t,e)=>{z.init(t,e),t._zod.optin="optional",t._zod.optout="optional",E(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),E(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${en(n.source)})?$`):void 0}),t._zod.parse=(n,r)=>{if(e.innerType._zod.optin==="optional"){const i=e.innerType._zod.run(n,r);return i instanceof Promise?i.then(o=>En(o,n.value)):En(i,n.value)}return n.value===void 0?n:e.innerType._zod.run(n,r)}}),Mo=p("$ZodNullable",(t,e)=>{z.init(t,e),E(t._zod,"optin",()=>e.innerType._zod.optin),E(t._zod,"optout",()=>e.innerType._zod.optout),E(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${en(n.source)}|null)$`):void 0}),E(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(n,r)=>n.value===null?n:e.innerType._zod.run(n,r)}),xo=p("$ZodPrefault",(t,e)=>{z.init(t,e),t._zod.optin="optional",E(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=e.defaultValue),e.innerType._zod.run(n,r))}),Vo=p("$ZodPipe",(t,e)=>{z.init(t,e),E(t._zod,"values",()=>e.in._zod.values),E(t._zod,"optin",()=>e.in._zod.optin),E(t._zod,"optout",()=>e.out._zod.optout),E(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(n,r)=>{if(r.direction==="backward"){const o=e.out._zod.run(n,r);return o instanceof Promise?o.then(s=>Ye(s,e.in,r)):Ye(o,e.in,r)}const i=e.in._zod.run(n,r);return i instanceof Promise?i.then(o=>Ye(o,e.out,r)):Ye(i,e.out,r)}});function Ye(t,e,n){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},n)}const No=p("$ZodLazy",(t,e)=>{z.init(t,e),E(t._zod,"innerType",()=>e.getter()),E(t._zod,"pattern",()=>t._zod.innerType._zod.pattern),E(t._zod,"propValues",()=>t._zod.innerType._zod.propValues),E(t._zod,"optin",()=>t._zod.innerType._zod.optin??void 0),E(t._zod,"optout",()=>t._zod.innerType._zod.optout??void 0),t._zod.parse=(n,r)=>t._zod.innerType._zod.run(n,r)}),Lo=p("$ZodCustom",(t,e)=>{Et.init(t,e),z.init(t,e),t._zod.parse=(n,r)=>n,t._zod.check=n=>{const r=n.value,i=e.fn(r);if(i instanceof Promise)return i.then(o=>Sn(o,n,r,t));Sn(i,n,r,t)}});function Sn(t,e,n,r){if(!t){const i={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(i.params=r._zod.def.params),e.issues.push(Xi(i))}}function Bo(t,e){return new t({type:"string",...R()})}function jo(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...R()})}function Uo(t,e){return new t({type:"number",checks:[],...R()})}function Do(t,e){return new t({type:"boolean",...R()})}function Zo(t,e){return new t({type:"null",...R()})}function Fo(t){return new t({type:"any"})}function qo(t){return new t({type:"unknown"})}function Ho(t,e){return new ho({check:"min_length",...R(),minimum:t})}function Ko(t,e){return new go({check:"length_equals",...R(),length:t})}function Wo(t,e,n){const r=R();return r.abort??(r.abort=!0),new t({type:"custom",check:"custom",fn:e,...r})}const T=p("ZodMiniType",(t,e)=>{if(!t._zod)throw new Error("Uninitialized schema in ZodMiniType.");z.init(t,e),t.def=e,t.type=e.type,t.parse=(n,r)=>to(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>tr(t,n,r),t.parseAsync=async(n,r)=>ro(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>nr(t,n,r),t.check=(...n)=>t.clone({...e,checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),t.clone=(n,r)=>rn(t,n,r),t.brand=()=>t,t.register=(n,r)=>(n.add(t,r),t)}),sr=p("ZodMiniString",(t,e)=>{rr.init(t,e),T.init(t,e)});function l(t){return Bo(sr)}const Go=p("ZodMiniStringFormat",(t,e)=>{ir.init(t,e),sr.init(t,e)}),Jo=p("ZodMiniNumber",(t,e)=>{bo.init(t,e),T.init(t,e)});function k(t){return Uo(Jo)}const Qo=p("ZodMiniBoolean",(t,e)=>{_o.init(t,e),T.init(t,e)});function q(t){return Do(Qo)}const Xo=p("ZodMiniNull",(t,e)=>{wo.init(t,e),T.init(t,e)});function on(t){return Zo(Xo)}const Yo=p("ZodMiniAny",(t,e)=>{Eo.init(t,e),T.init(t,e)});function zn(){return Fo(Yo)}const es=p("ZodMiniUnknown",(t,e)=>{So.init(t,e),T.init(t,e)});function ts(){return qo(es)}const ns=p("ZodMiniArray",(t,e)=>{zo.init(t,e),T.init(t,e)});function C(t,e){return new ns({type:"array",element:t,...R()})}const rs=p("ZodMiniObject",(t,e)=>{Po.init(t,e),T.init(t,e),E(t,"shape",()=>e.shape)});function h(t,e){const n={type:"object",get shape(){return tn(this,"shape",{...t}),this.shape},...R()};return new rs(n)}function g(t,e){return Ji(t,e)}function is(t,e){return Qi(cr,t)}function Ze(t,e){return t.clone({...t._zod.def,catchall:e})}const os=p("ZodMiniUnion",(t,e)=>{or.init(t,e),T.init(t,e)});function ee(t,e){return new os({type:"union",options:t,...R()})}const ss=p("ZodMiniDiscriminatedUnion",(t,e)=>{ko.init(t,e),T.init(t,e)});function Fe(t,e,n){return new ss({type:"union",options:e,discriminator:t,...R()})}const as=p("ZodMiniRecord",(t,e)=>{Co.init(t,e),T.init(t,e)});function fe(t,e,n){return new as({type:"record",keyType:t,valueType:e,...R()})}const cs=p("ZodMiniEnum",(t,e)=>{Io.init(t,e),T.init(t,e),t.options=Object.values(e.entries)});function ar(t,e){const n=Array.isArray(t)?Object.fromEntries(t.map(r=>[r,r])):t;return new cs({type:"enum",entries:n,...R()})}const us=p("ZodMiniLiteral",(t,e)=>{$o.init(t,e),T.init(t,e)});function y(t,e){return new us({type:"literal",values:Array.isArray(t)?t:[t],...R()})}const ls=p("ZodMiniTransform",(t,e)=>{Ro.init(t,e),T.init(t,e)});function ds(t){return new ls({type:"transform",transform:t})}const cr=p("ZodMiniOptional",(t,e)=>{Oo.init(t,e),T.init(t,e)});function f(t){return new cr({type:"optional",innerType:t})}const fs=p("ZodMiniNullable",(t,e)=>{Mo.init(t,e),T.init(t,e)});function rt(t){return new fs({type:"nullable",innerType:t})}const ps=p("ZodMiniPrefault",(t,e)=>{xo.init(t,e),T.init(t,e)});function K(t,e){return new ps({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():Ki(e)}})}const hs=p("ZodMiniPipe",(t,e)=>{Vo.init(t,e),T.init(t,e)});function gs(t,e){return new hs({type:"pipe",in:t,out:e})}const vs=p("ZodMiniLazy",(t,e)=>{No.init(t,e),T.init(t,e)});function ys(t){return new vs({type:"lazy",getter:t})}const ms=p("ZodMiniCustom",(t,e)=>{Lo.init(t,e),T.init(t,e)});function bs(t,e){return Wo(ms,()=>!0)}function G(){const t=ys(()=>ee([l(),k(),q(),on(),C(t),fe(l(),t)]));return t}const _s=p("$ZodISODateTime",(t,e)=>{mo.init(t,e),Go.init(t,e)});function $t(t){return jo(_s)}const qe=Ze(h({}),G()),ur=h({sys:h({type:y("Link"),linkType:l(),id:l()})}),lr=h({sys:h({type:y("Link"),linkType:y("ContentType"),id:l()})}),dr=h({sys:h({type:y("Link"),linkType:y("Environment"),id:l()})}),fr=h({sys:h({type:y("Link"),linkType:y("Space"),id:l()})}),pr=h({sys:h({type:y("Link"),linkType:y("Tag"),id:l()})}),sn=h({type:y("Entry"),contentType:lr,publishedVersion:k(),id:l(),createdAt:zn(),updatedAt:zn(),locale:f(l()),revision:k(),space:fr,environment:dr}),Ae=h({fields:qe,metadata:Ze(h({tags:C(pr)}),G()),sys:sn});function hr(t){return Ae.safeParse(t).success}const gr=g(qe,{nt_audience_id:l(),nt_name:f(l()),nt_description:f(l())}),vr=g(Ae,{fields:gr}),yr=g(Ae,{fields:h({nt_name:l(),nt_fallback:f(l()),nt_mergetag_id:l()}),sys:g(sn,{contentType:h({sys:h({type:y("Link"),linkType:y("ContentType"),id:y("nt_mergetag")})})})}),vt=h({id:l(),hidden:K(q(),!1)});function mr(t){return vt.safeParse(t).success}const br=h({type:f(y("EntryReplacement")),baseline:vt,variants:C(vt)});function _r(t){return t.type==="EntryReplacement"||t.type===void 0}const Ft=h({value:ee([l(),q(),on(),k(),fe(l(),G())])}),wr=ar(["Boolean","Number","Object","String"]),Er=h({type:y("InlineVariable"),key:l(),valueType:wr,baseline:Ft,variants:C(Ft)});function ws(t){return t.type==="InlineVariable"}const Sr=Fe("type",[br,Er]),zr=C(Sr),Tr=h({distribution:f(K(C(k()),[.5,.5])),traffic:f(K(k(),0)),components:f(K(zr,[{type:"EntryReplacement",baseline:{id:""},variants:[{id:""}]}])),sticky:f(K(q(),!1))}),Ar=ee([y("nt_experiment"),y("nt_personalization")]),Pr=g(qe,{nt_name:l(),nt_description:f(rt(l())),nt_type:Ar,nt_config:gs(f(K(rt(Tr),null)),ds(t=>t??{traffic:0,distribution:[.5,.5],components:[],sticky:!1})),nt_audience:f(rt(vr)),nt_variants:f(K(C(bs()),[])),nt_experience_id:l()}),an=g(Ae,{fields:Pr});function Me(t){return an.safeParse(t).success}const kr=C(ee([ur,an])),Cr=g(Ae,{fields:g(qe,{nt_experiences:kr})});function it(t){return Cr.safeParse(t).success}const Ir=f(h({name:l(),version:l()})),cn=h({name:f(l()),source:f(l()),medium:f(l()),term:f(l()),content:f(l())}),$r=ee([y("mobile"),y("server"),y("web")]),Rr=fe(l(),l()),Es=2,Ss=h({latitude:k(),longitude:k()}),St=h({coordinates:f(Ss),city:f(l()),postalCode:f(l()),region:f(l()),regionCode:f(l()),country:f(l()),countryCode:f(l().check(Ko(Es))),continent:f(l()),timezone:f(l())}),Or=h({name:l(),version:l()}),pe=Ze(h({path:l(),query:Rr,referrer:l(),search:l(),title:f(l()),url:l()}),G()),He=fe(l(),G()),zt=Ze(h({name:l()}),G()),Tt=fe(l(),G()),Mr=h({id:l(),isReturningVisitor:q(),landingPage:pe,count:k(),activeSessionLength:k(),averageSessionLength:k()}),Ke=h({id:l(),stableId:l(),random:k(),audiences:C(l()),traits:Tt,location:St,session:Mr}),xr=Ze(h({id:l()}),G()),Vr=h({data:h(),message:l(),error:rt(q())}),Nr=h({profiles:f(C(Ke))}),Lr=g(Vr,{data:Nr}),Br=["Variable"],jr=h({key:l(),type:ee([ar(Br),l()]),meta:h({experienceId:l(),variantIndex:k()})}),Ur=ee([l(),q(),on(),k(),fe(l(),G())]),zs=g(jr,{type:l(),value:ts()}),Dr=g(jr,{type:y("Variable"),value:Ur}),Zr=Fe("type",[Dr]),un=C(Zr),At=h({app:Ir,campaign:cn,gdpr:h({isConsentGiven:q()}),library:Or,locale:l(),location:f(St),userAgent:f(l())}),te=h({channel:$r,context:g(At,{page:f(pe),screen:f(zt)}),messageId:l(),originalTimestamp:$t(),sentAt:$t(),timestamp:$t(),userId:f(l())}),ln=g(te,{type:y("alias")}),le=g(te,{type:y("component"),componentType:ee([y("Entry"),y("Variable")]),componentId:l(),experienceId:f(l()),variantIndex:k()}),dn=g(te,{type:y("group")}),Pt=g(te,{type:y("identify"),traits:Tt}),fn=g(At,{page:pe}),kt=g(te,{type:y("page"),name:f(l()),properties:pe,context:fn}),pn=g(At,{screen:zt}),Ct=g(te,{type:y("screen"),name:l(),properties:f(He),context:pn}),It=g(te,{type:y("track"),event:l(),properties:He}),oe={anonymousId:l()},Fr=Fe("type",[g(ln,oe),g(le,oe),g(dn,oe),g(Pt,oe),g(kt,oe),g(Ct,oe),g(It,oe)]),Ts=C(Fr),hn=Fe("type",[ln,le,dn,Pt,kt,Ct,It]),Le=C(hn),qr=h({features:f(C(l()))}),As=h({events:Le.check(Ho(1)),options:f(qr)}),Hr=h({experienceId:l(),variantIndex:k(),variants:fe(l(),l()),sticky:f(K(q(),!1))}),gn=C(Hr),Kr=h({profile:Ke,experiences:gn,changes:un}),ot=g(Vr,{data:Kr}),vn=Fe("type",[le]),Wr=C(vn),Gr=h({profile:xr,events:Wr}),yn=C(Gr);var qt=[],Ps=t=>new RegExp(t.replace(/\*/g,".*")+"$"),ks=t=>{qt=t.split(/[\s,]+/).map(Ps)},he=(t,e,n,...r)=>{for(let i=qt.length;i--;)if(qt[i].test(t))return e({name:t,level:n,messages:r})},Cs=t=>{let e="";const n=console[t.level==="fatal"?"error":t.level];t.name&&(e+=`[${t.name}] `),typeof t.messages[0]=="object"?n(e,...t.messages):n(e+t.messages.shift(),...t.messages)},Jr=(t,e)=>({fatal:he.bind(0,t,e=e||Cs,"fatal"),error:he.bind(0,t,e,"error"),warn:he.bind(0,t,e,"warn"),debug:he.bind(0,t,e,"debug"),info:he.bind(0,t,e,"info"),log:he.bind(0,t,e,"log")}),Pe=Jr("");Pe.fatal;Pe.error;Pe.warn;Pe.debug;Pe.info;Pe.log;class Qr{name="@contentful/optimization";PREFIX_PARTS=["Ctfl","O10n"];DELIMITER=":";diary;sinks=[];constructor(){this.diary=Jr(this.name,this.onLogEvent.bind(this)),ks(this.name)}assembleLocationPrefix(e){return`[${[...this.PREFIX_PARTS,e].join(this.DELIMITER)}]`}addSink(e){this.sinks=[...this.sinks.filter(n=>n.name!==e.name),e]}removeSink(e){this.sinks=this.sinks.filter(n=>n.name!==e)}removeSinks(){this.sinks=[]}debug(e,n,...r){this.diary.debug(`${this.assembleLocationPrefix(e)} ${n}`,...r)}info(e,n,...r){this.diary.info(`${this.assembleLocationPrefix(e)} ${n}`,...r)}log(e,n,...r){this.diary.log(`${this.assembleLocationPrefix(e)} ${n}`,...r)}warn(e,n,...r){this.diary.warn(`${this.assembleLocationPrefix(e)} ${n}`,...r)}error(e,n,...r){this.diary.error(`${this.assembleLocationPrefix(e)} ${n}`,...r)}fatal(e,n,...r){this.diary.fatal(`${this.assembleLocationPrefix(e)} ${n}`,...r)}onLogEvent(e){this.sinks.forEach(n=>{n.ingest(e)})}}const Q=new Qr;function P(t){return{debug:(e,...n)=>{Q.debug(t,e,...n)},info:(e,...n)=>{Q.info(t,e,...n)},log:(e,...n)=>{Q.log(t,e,...n)},warn:(e,...n)=>{Q.warn(t,e,...n)},error:(e,...n)=>{Q.error(t,e,...n)},fatal:(e,...n)=>{Q.fatal(t,e,...n)}}}class Xr{}var ge={fatal:60,error:50,warn:40,info:30,debug:20,log:10},Is=(t,e)=>e in ge&&t in ge?ge[e]===ge[t]?0:ge[e]<ge[t]?1:-1:0;const $s={debug:(...t)=>{console.debug(...t)},info:(...t)=>{console.info(...t)},log:(...t)=>{console.log(...t)},warn:(...t)=>{console.warn(...t)},error:(...t)=>{console.error(...t)},fatal:(...t)=>{console.error(...t)}},Rs=0;class Yr extends Xr{name="ConsoleLogSink";verbosity;constructor(e){super(),this.verbosity=e??"error"}ingest(e){Is(this.verbosity,e.level)>Rs||$s[e.level](...e.messages)}}function Os(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Rt={},Ot,Tn;function Ms(){if(Tn)return Ot;Tn=1;function t(e,n){typeof n=="boolean"&&(n={forever:n}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=n||{},this._maxRetryTime=n&&n.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}return Ot=t,t.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},t.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},t.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var n=new Date().getTime();if(e&&n-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var r=this._timeouts.shift();if(r===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),r=this._cachedTimeouts.slice(-1);else return!1;var i=this;return this._timer=setTimeout(function(){i._attempts++,i._operationTimeoutCb&&(i._timeout=setTimeout(function(){i._operationTimeoutCb(i._attempts)},i._operationTimeout),i._options.unref&&i._timeout.unref()),i._fn(i._attempts)},r),this._options.unref&&this._timer.unref(),!0},t.prototype.attempt=function(e,n){this._fn=e,n&&(n.timeout&&(this._operationTimeout=n.timeout),n.cb&&(this._operationTimeoutCb=n.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){r._operationTimeoutCb()},r._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)},t.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},t.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},t.prototype.start=t.prototype.try,t.prototype.errors=function(){return this._errors},t.prototype.attempts=function(){return this._attempts},t.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},n=null,r=0,i=0;i<this._errors.length;i++){var o=this._errors[i],s=o.message,a=(e[s]||0)+1;e[s]=a,a>=r&&(n=o,r=a)}return n},Ot}var An;function xs(){return An||(An=1,function(t){var e=Ms();t.operation=function(n){var r=t.timeouts(n);return new e(r,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},t.timeouts=function(n){if(n instanceof Array)return[].concat(n);var r={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var i in n)r[i]=n[i];if(r.minTimeout>r.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var o=[],s=0;s<r.retries;s++)o.push(this.createTimeout(s,r));return n&&n.forever&&!o.length&&o.push(this.createTimeout(s,r)),o.sort(function(a,c){return a-c}),o},t.createTimeout=function(n,r){var i=r.randomize?Math.random()+1:1,o=Math.round(i*Math.max(r.minTimeout,1)*Math.pow(r.factor,n));return o=Math.min(o,r.maxTimeout),o},t.wrap=function(n,r,i){if(r instanceof Array&&(i=r,r=null),!i){i=[];for(var o in n)typeof n[o]=="function"&&i.push(o)}for(var s=0;s<i.length;s++){var a=i[s],c=n[a];n[a]=(function(d){var m=t.operation(r),_=Array.prototype.slice.call(arguments,1),S=_.pop();_.push(function(b){m.retry(b)||(b&&(arguments[0]=m.mainError()),S.apply(this,arguments))}),m.attempt(function(){d.apply(n,_)})}).bind(n,c),n[a].options=r}}}(Rt)),Rt}var Mt,Pn;function Vs(){return Pn||(Pn=1,Mt=xs()),Mt}var Ns=Vs();const Ls=Os(Ns),Bs=Object.prototype.toString,js=t=>Bs.call(t)==="[object Error]",Us=new Set(["network error","Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Load failed","Network request failed","fetch failed","terminated"]);function Ds(t){return t&&js(t)&&t.name==="TypeError"&&typeof t.message=="string"?t.message==="Load failed"?t.stack===void 0:Us.has(t.message):!1}class Zs extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}}const kn=(t,e,n)=>{const r=n.retries-(e-1);return t.attemptNumber=e,t.retriesLeft=r,t};async function Fs(t,e){return new Promise((n,r)=>{e={...e},e.onFailedAttempt??=()=>{},e.shouldRetry??=()=>!0,e.retries??=10;const i=Ls.operation(e),o=()=>{i.stop(),r(e.signal?.reason)};e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",o,{once:!0});const s=()=>{e.signal?.removeEventListener("abort",o),i.stop()};i.attempt(async a=>{try{const c=await t(a);s(),n(c)}catch(c){try{if(!(c instanceof Error))throw new TypeError(`Non-error was thrown: "${c}". You should only throw errors.`);if(c instanceof Zs)throw c.originalError;if(c instanceof TypeError&&!Ds(c))throw c;if(kn(c,a,e),await e.shouldRetry(c)||(i.stop(),r(c)),await e.onFailedAttempt(c),!i.retry(c))throw i.mainError()}catch(u){kn(u,a,e),s(),r(u)}}})})}const xt=P("ApiClient:Retry"),qs=0,Hs=1,Vt=503,Ks=500;class yt extends Error{status;constructor(e,n=Ks){super(e),Object.setPrototypeOf(this,yt.prototype),this.status=n}}function Ws({apiName:t="Optimization",controller:e,fetchMethod:n=fetch,init:r,url:i}){return async()=>{try{const o=await n(i,r);if(o.status===Vt)throw new yt(`${t} API request to "${i.toString()}" failed with status: "[${o.status}] ${o.statusText}".`,Vt);if(!o.ok){const s=new Error(`Request to "${i.toString()}" failed with status: [${o.status}] ${o.statusText} - traceparent: ${o.headers.get("traceparent")}`);xt.error("Request failed with non-OK status:",s),e.abort();return}return xt.debug(`Response from "${i.toString()}":`,o),o}catch(o){if(o instanceof yt&&o.status===Vt)throw o;xt.error(`Request to "${i.toString()}" failed:`,o),e.abort()}}}function Gs({apiName:t="Optimization",fetchMethod:e=fetch,intervalTimeout:n=qs,onFailedAttempt:r,retries:i=Hs}={}){return async(o,s)=>{const a=new AbortController;let c;try{c=await Fs(Ws({apiName:t,controller:a,fetchMethod:e,init:s,url:o}),{minTimeout:n,onFailedAttempt:u=>r?.({...u,apiName:t}),retries:i,signal:a.signal})}catch(u){if(!(u instanceof Error)||u.name!=="AbortError")throw u}if(!c)throw new Error(`${t} API request to "${o.toString()}" may not be retried.`);return c}}const Js=P("ApiClient:Timeout"),Qs=3e3;function Xs({apiName:t="Optimization",fetchMethod:e=fetch,onRequestTimeout:n,requestTimeout:r=Qs}={}){return async(i,o)=>{const s=new AbortController,a=setTimeout(()=>{typeof n=="function"?n({apiName:t}):Js.error(`Request to "${i.toString()}" timed out`,new Error("Request timeout")),s.abort()},r),c=await e(i,{...o,signal:s.signal});return clearTimeout(a),c}}const Cn=P("ApiClient:Fetch");function Ys(t){try{const e=Xs(t);return Gs({...t,fetchMethod:e})}catch(e){throw e instanceof Error&&(e.name==="AbortError"?Cn.warn("Request aborted due to network issues. This request may not be retried."):Cn.error("Request failed:",e)),e}}const ea={create:Ys},In=P("ApiClient"),ta="main";class ei{name;clientId;environment;fetch;constructor(e,{fetchOptions:n,clientId:r,environment:i}){this.clientId=r,this.environment=i??ta,this.name=e,this.fetch=ea.create({...n??{},apiName:e})}logRequestError(e,{requestName:n}){e instanceof Error&&(e.name==="AbortError"?In.warn(`[${this.name}] "${n}" request aborted due to network issues. This request may not be retried.`):In.error(`[${this.name}] "${n}" request failed:`,e))}}const B=P("ApiClient:Experience"),ti="https://experience.ninetailed.co/";class na extends ei{baseUrl;enabledFeatures;ip;locale;plainText;preflight;constructor(e){super("Experience",e);const{baseUrl:n,enabledFeatures:r,ip:i,locale:o,plainText:s,preflight:a}=e;this.baseUrl=n||ti,this.enabledFeatures=r,this.ip=i,this.locale=o,this.plainText=s,this.preflight=a}async getProfile(e,n={}){if(!e)throw new Error("Valid profile ID required.");const r="Get Profile";B.info(`Sending "${r}" request`);try{const i=await this.fetch(this.constructUrl(`v2/organizations/${this.clientId}/environments/${this.environment}/profiles/${e}`,n),{method:"GET"}),{data:{changes:o,experiences:s,profile:a}}=ot.parse(await i.json()),c={changes:o,personalizations:s,profile:a};return B.debug(`"${r}" request successfully completed`),c}catch(i){throw this.logRequestError(i,{requestName:r}),i}}async makeProfileMutationRequest({url:e,body:n,options:r}){return await this.fetch(this.constructUrl(e,r),{method:"POST",headers:this.constructHeaders(r),body:JSON.stringify(n),keepalive:!0})}async createProfile({events:e},n={}){const r="Create Profile";B.info(`Sending "${r}" request`);const i={events:Le.parse(e),options:this.constructBodyOptions(n)};B.debug(`"${r}" request body:`,i);try{const o=await this.makeProfileMutationRequest({url:`v2/organizations/${this.clientId}/environments/${this.environment}/profiles`,body:i,options:n}),{data:{changes:s,experiences:a,profile:c}}=ot.parse(await o.json()),u={changes:s,personalizations:a,profile:c};return B.debug(`"${r}" request successfully completed`),u}catch(o){throw this.logRequestError(o,{requestName:r}),o}}async updateProfile({profileId:e,events:n},r={}){if(!e)throw new Error("Valid profile ID required.");const i="Update Profile";B.info(`Sending "${i}" request`);const o={events:Le.parse(n),options:this.constructBodyOptions(r)};B.debug(`"${i}" request body:`,o);try{const s=await this.makeProfileMutationRequest({url:`v2/organizations/${this.clientId}/environments/${this.environment}/profiles/${e}`,body:o,options:r}),{data:{changes:a,experiences:c,profile:u}}=ot.parse(await s.json()),d={changes:a,personalizations:c,profile:u};return B.debug(`"${i}" request successfully completed`),d}catch(s){throw this.logRequestError(s,{requestName:i}),s}}async upsertProfile({profileId:e,events:n},r){return e?await this.updateProfile({profileId:e,events:n},r):await this.createProfile({events:n},r)}async upsertManyProfiles({events:e},n={}){const r="Upsert Many Profiles";B.info(`Sending "${r}" request`);const i={events:Le.parse(e),options:this.constructBodyOptions(n)};B.debug(`"${r}" request body:`,i);try{const o=await this.makeProfileMutationRequest({url:`v2/organizations/${this.clientId}/environments/${this.environment}/events`,body:i,options:{plainText:!1,...n}}),{data:{profiles:s}}=Lr.parse(await o.json());return B.debug(`"${r}" request successfully completed`),s}catch(o){throw this.logRequestError(o,{requestName:r}),o}}constructUrl(e,n){const r=new URL(e,this.baseUrl),i=n.locale??this.locale,o=n.preflight??this.preflight;return i&&r.searchParams.set("locale",i),o&&r.searchParams.set("type","preflight"),r.toString()}constructHeaders({ip:e=this.ip,plainText:n=this.plainText}){const r=new Map;return e&&r.set("X-Force-IP",e),n??this.plainText??!0?r.set("Content-Type","text/plain"):r.set("Content-Type","application/json"),Object.fromEntries(r)}constructBodyOptions=({enabledFeatures:e=this.enabledFeatures})=>{const n={};return e&&Array.isArray(e)&&e.length>0?n.features=e:n.features=["ip-enrichment","location"],n}}const ke=P("ApiClient:Insights"),ni="https://ingest.insights.ninetailed.co/";class ra extends ei{baseUrl;beaconHandler;constructor(e){super("Insights",e);const{baseUrl:n,beaconHandler:r}=e;this.baseUrl=n??ni,this.beaconHandler=r}async sendBatchEvents(e,n={}){const{beaconHandler:r=this.beaconHandler}=n,i=new URL(`v1/organizations/${this.clientId}/environments/${this.environment}/events`,this.baseUrl),o=yn.parse(e);if(typeof r=="function"){if(ke.debug("Queueing events via beaconHandler"),r(i,o))return!0;ke.warn("beaconHandler failed to queue events; events will be emitted immediately via fetch")}const s="Event Batches";ke.info(`Sending "${s}" request`),ke.debug(`"${s}" request body:`,o);try{return await this.fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o),keepalive:!0}),ke.debug(`"${s}" request successfully completed`),!0}catch(a){return this.logRequestError(a,{requestName:s}),!1}}}class ri{config;experience;insights;constructor(e){const{personalization:n,analytics:r,...i}=e;this.config=i,this.experience=new na({...i,...n}),this.insights=new ra({...i,...r})}}function ia(){}function $n(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function Rn(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const oa="[object RegExp]",sa="[object String]",aa="[object Number]",ca="[object Boolean]",On="[object Arguments]",ua="[object Symbol]",la="[object Date]",da="[object Map]",fa="[object Set]",pa="[object Array]",ha="[object Function]",ga="[object ArrayBuffer]",Nt="[object Object]",va="[object Error]",ya="[object DataView]",ma="[object Uint8Array]",ba="[object Uint8ClampedArray]",_a="[object Uint16Array]",wa="[object Uint32Array]",Ea="[object BigUint64Array]",Sa="[object Int8Array]",za="[object Int16Array]",Ta="[object Int32Array]",Aa="[object BigInt64Array]",Pa="[object Float32Array]",ka="[object Float64Array]";function mt(t){if(!t||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e===null||e===Object.prototype||Object.getPrototypeOf(e)===null?Object.prototype.toString.call(t)==="[object Object]":!1}function bt(t){return t==="__proto__"}function ye(t,e){const n=Object.keys(e);for(let r=0;r<n.length;r++){const i=n[r];if(bt(i))continue;const o=e[i],s=t[i];Array.isArray(o)?Array.isArray(s)?t[i]=ye(s,o):t[i]=ye([],o):mt(o)?mt(s)?t[i]=ye(s,o):t[i]=ye({},o):(s===void 0||o!==void 0)&&(t[i]=o)}return t}function Ca(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function Ia(t,e,n){return xe(t,e,void 0,void 0,void 0,void 0,n)}function xe(t,e,n,r,i,o,s){const a=s(t,e,n,r,i,o);if(a!==void 0)return a;if(typeof t==typeof e)switch(typeof t){case"bigint":case"string":case"boolean":case"symbol":case"undefined":return t===e;case"number":return t===e||Object.is(t,e);case"function":return t===e;case"object":return Be(t,e,o,s)}return Be(t,e,o,s)}function Be(t,e,n,r){if(Object.is(t,e))return!0;let i=Rn(t),o=Rn(e);if(i===On&&(i=Nt),o===On&&(o=Nt),i!==o)return!1;switch(i){case sa:return t.toString()===e.toString();case aa:{const c=t.valueOf(),u=e.valueOf();return Ca(c,u)}case ca:case la:case ua:return Object.is(t.valueOf(),e.valueOf());case oa:return t.source===e.source&&t.flags===e.flags;case ha:return t===e}n=n??new Map;const s=n.get(t),a=n.get(e);if(s!=null&&a!=null)return s===e;n.set(t,e),n.set(e,t);try{switch(i){case da:{if(t.size!==e.size)return!1;for(const[c,u]of t.entries())if(!e.has(c)||!xe(u,e.get(c),c,t,e,n,r))return!1;return!0}case fa:{if(t.size!==e.size)return!1;const c=Array.from(t.values()),u=Array.from(e.values());for(let d=0;d<c.length;d++){const m=c[d],_=u.findIndex(S=>xe(m,S,void 0,t,e,n,r));if(_===-1)return!1;u.splice(_,1)}return!0}case pa:case ma:case ba:case _a:case wa:case Ea:case Sa:case za:case Ta:case Aa:case Pa:case ka:{if(typeof Buffer<"u"&&Buffer.isBuffer(t)!==Buffer.isBuffer(e)||t.length!==e.length)return!1;for(let c=0;c<t.length;c++)if(!xe(t[c],e[c],c,t,e,n,r))return!1;return!0}case ga:return t.byteLength!==e.byteLength?!1:Be(new Uint8Array(t),new Uint8Array(e),n,r);case ya:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:Be(new Uint8Array(t),new Uint8Array(e),n,r);case va:return t.name===e.name&&t.message===e.message;case Nt:{if(!(Be(t.constructor,e.constructor,n,r)||mt(t)&&mt(e)))return!1;const u=[...Object.keys(t),...$n(t)],d=[...Object.keys(e),...$n(e)];if(u.length!==d.length)return!1;for(let m=0;m<u.length;m++){const _=u[m],S=t[_];if(!Object.hasOwn(e,_))return!1;const b=e[_];if(!xe(S,b,_,t,e,n,r))return!1}return!0}default:return!1}}finally{n.delete(t),n.delete(e)}}function Lt(t,e){return Ia(t,e,ia)}const We=h({campaign:f(cn),locale:f(l()),location:f(St),page:f(pe),screen:f(zt),userAgent:f(l())}),$a=g(We,{componentId:l(),experienceId:f(l()),variantIndex:f(k()),sticky:f(q())}),Ra=g(We,{traits:f(Tt),userId:l()}),Oa=g(We,{properties:f(is(pe))}),Ma=g(We,{name:l(),properties:He}),xa=g(We,{event:l(),properties:f(K(He,{}))}),Ht={path:"",query:{},referrer:"",search:"",title:"",url:""};class ii{app;channel;library;getLocale;getPageProperties;getUserAgent;constructor(e){const{app:n,channel:r,library:i,getLocale:o,getPageProperties:s,getUserAgent:a}=e;this.app=n,this.channel=r,this.library=i,this.getLocale=o??(()=>"en-US"),this.getPageProperties=s??(()=>Ht),this.getUserAgent=a??(()=>{})}buildUniversalEventProperties({campaign:e={},locale:n,location:r,page:i,screen:o,userAgent:s}){const a=new Date().toISOString();return{channel:this.channel,context:{app:this.app,campaign:e,gdpr:{isConsentGiven:!0},library:this.library,locale:n??this.getLocale()??"en-US",location:r,page:i??this.getPageProperties(),screen:o,userAgent:s??this.getUserAgent()},messageId:crypto.randomUUID(),originalTimestamp:a,sentAt:a,timestamp:a}}buildComponentView(e){const{componentId:n,experienceId:r,variantIndex:i,...o}=$a.parse(e);return{...this.buildUniversalEventProperties(o),type:"component",componentType:"Entry",componentId:n,experienceId:r,variantIndex:i??0}}buildFlagView(e){return{...this.buildComponentView(e),componentType:"Variable"}}buildIdentify(e){const{traits:n={},userId:r,...i}=Ra.parse(e);return{...this.buildUniversalEventProperties(i),type:"identify",traits:n,userId:r}}buildPageView(e={}){const{properties:n={},...r}=Oa.parse(e),i=this.getPageProperties(),o=ye({...i,title:i.title??Ht.title},n),{context:{screen:s,...a},...c}=this.buildUniversalEventProperties(r),u=fn.parse(a);return{...c,context:u,type:"page",properties:o}}buildScreenView(e){const{name:n,properties:r,...i}=Ma.parse(e),{context:{page:o,...s},...a}=this.buildUniversalEventProperties(i),c=pn.parse(s);return{...a,context:c,type:"screen",name:n,properties:r}}buildTrack(e){const{event:n,properties:r={},...i}=xa.parse(e);return{...this.buildUniversalEventProperties(i),type:"track",event:n,properties:r}}}function Va(t){switch(typeof t){case"number":case"symbol":return!1;case"string":return t.includes(".")||t.includes("[")||t.includes("]")}}function Na(t){return typeof t=="string"||typeof t=="symbol"?t:Object.is(t?.valueOf?.(),-0)?"-0":String(t)}function La(t){const e=[],n=t.length;if(n===0)return e;let r=0,i="",o="",s=!1;for(t.charCodeAt(0)===46&&(e.push(""),r++);r<n;){const a=t[r];o?a==="\\"&&r+1<n?(r++,i+=t[r]):a===o?o="":i+=a:s?a==='"'||a==="'"?o=a:a==="]"?(s=!1,e.push(i),i=""):i+=a:a==="["?(s=!0,i&&(e.push(i),i="")):a==="."?i&&(e.push(i),i=""):i+=a,r++}return i&&e.push(i),e}function Kt(t,e,n){if(t==null)return n;switch(typeof e){case"string":{if(bt(e))return n;const r=t[e];return r===void 0?Va(e)?Kt(t,La(e),n):n:r}case"number":case"symbol":{typeof e=="number"&&(e=Na(e));const r=t[e];return r===void 0?n:r}default:{if(Array.isArray(e))return Ba(t,e,n);if(Object.is(e?.valueOf(),-0)?e="-0":e=String(e),bt(e))return n;const r=t[e];return r===void 0?n:r}}}function Ba(t,e,n){if(e.length===0)return n;let r=t;for(let i=0;i<e.length;i++){if(r==null||bt(e[i]))return n;r=r[e[i]]}return r===void 0?n:r}const Mn=P("Personalization"),xn="Could not resolve Merge Tag value:",we={isMergeTagEntry(t){return yr.safeParse(t).success},normalizeSelectors(t){return t.split("_").map((e,n,r)=>{const i=r.slice(0,n).join("."),o=r.slice(n).join("_");return[i,o].filter(s=>s!=="").join(".")})},getValueFromProfile(t,e){const r=we.normalizeSelectors(t).find(o=>Kt(e,o));if(!r)return;const i=Kt(e,r);if(!(!i||typeof i!="string"&&typeof i!="number"&&typeof i!="boolean"))return`${i}`},resolve(t,e){if(!we.isMergeTagEntry(t)){Mn.warn(`${xn} supplied entry is not a Merge Tag entry`);return}const{fields:{nt_fallback:n}}=t;return Ke.safeParse(e).success?we.getValueFromProfile(t.fields.nt_mergetag_id,e)??n:(Mn.warn(`${xn} no valid profile`),n)}},J=P("Personalization"),Ce="Could not resolve personalized entry variant:",ue={getPersonalizationEntry({personalizedEntry:t,selectedPersonalizations:e},n=!1){return!n&&(!e.length||!it(t))?void 0:t.fields.nt_experiences.filter(i=>Me(i)).find(i=>e.some(({experienceId:o})=>o===i.fields.nt_experience_id))},getSelectedPersonalization({personalizationEntry:t,selectedPersonalizations:e},n=!1){return!n&&(!e.length||!Me(t))?void 0:e.find(({experienceId:i})=>i===t.fields.nt_experience_id)},getSelectedVariant({personalizedEntry:t,personalizationEntry:e,selectedVariantIndex:n},r=!1){if(!r&&(!it(t)||!Me(e)))return;const i=e.fields.nt_config?.components?.filter(o=>_r(o)&&!o.baseline.hidden).find(o=>o.baseline.id===t.sys.id)?.variants;if(i?.length)return i.at(n-1)},getSelectedVariantEntry({personalizationEntry:t,selectedVariant:e},n=!1){if(!n&&(!Me(t)||!mr(e)))return;const r=t.fields.nt_variants?.find(i=>i.sys.id===e.id);return hr(r)?r:void 0},resolve(t,e){if(J.debug(`Resolving personalized entry for baseline entry ${t.sys.id}`),!e?.length)return J.warn(`${Ce} no selectedPersonalizations exist for the current profile`),{entry:t};if(!it(t))return J.warn(`${Ce} entry ${t.sys.id} is not personalized`),{entry:t};const n=ue.getPersonalizationEntry({personalizedEntry:t,selectedPersonalizations:e},!0);if(!n)return J.warn(`${Ce} could not find a personalization entry for ${t.sys.id}`),{entry:t};const r=ue.getSelectedPersonalization({personalizationEntry:n,selectedPersonalizations:e},!0),i=r?.variantIndex??0;if(i===0)return J.debug(`Resolved personalization entry for entry ${t.sys.id} is baseline`),{entry:t};const o=ue.getSelectedVariant({personalizedEntry:t,personalizationEntry:n,selectedVariantIndex:i},!0);if(!o)return J.warn(`${Ce} could not find a valid replacement variant entry for ${t.sys.id}`),{entry:t};const s=ue.getSelectedVariantEntry({personalizationEntry:n,selectedVariant:o},!0);if(s)J.debug(`Entry ${t.sys.id} has been resolved to variant entry ${s.sys.id}`);else return J.warn(`${Ce} could not find a valid replacement variant entry for ${t.sys.id}`),{entry:t};return{entry:s,personalization:r}}},X=Ee(),Z=Ee(),W=Ee(),mn=Ui(()=>pt.resolve(X.value??[])),Ue=Ee(!0),F=Ee(),A=Ee();function D(t){return{subscribe(e){return{unsubscribe:V(()=>{e(t.value)})}}}}const me={changes:X,consent:Z,event:W,flags:mn,online:Ue,personalizations:F,profile:A},et=t=>typeof t=="function",ja=t=>typeof t=="string"?t:typeof t=="symbol"?t.description??String(t):String(t),Ua=t=>typeof t=="string"||typeof t=="symbol",Da=t=>Object.prototype.toString.call(t)==="[object AsyncFunction]";function U(t,e){return function(n,r){const i=ja(r.name);r.addInitializer(function(){const s=Reflect.get(this,r.name);if(!et(s))return;const a=s,c=Da(a),u=b=>{const{[t]:L}=b;if(!et(L))throw new TypeError(`@guardedBy expects predicate "${String(t)}" to be a synchronous function.`);return L},d=(b,L)=>{const M=!!u(b).call(b,i,L);return e?.invert===!0?!M:M},m=(b,L)=>{const{onBlocked:I}=e??{};if(I!==void 0){if(et(I)){I.call(b,i,L);return}if(Ua(I)){const{[I]:M}=b;et(M)&&M.call(b,i,L)}}},_=()=>c?Promise.resolve(void 0):void 0,S=function(...b){return d(this,b)?a.call(this,...b):(m(this,b),_())};Reflect.set(this,r.name,S)})}}class oi{#e;constructor(e){const n=new Map;e&&Object.entries(e).map(([r,i])=>n.set(r.length?r:void 0,new Set(i))),this.#e=n}isPresent(e,n){return this.#e.get(e)?.has(n)??!1}addValue(e,n){const r=this.#e.get(e);r?r.add(n):this.#e.set(e,new Set([n]))}removeValue(e,n){this.#e.get(e)?.delete(n)}reset(e){e!==void 0?this.#e.get(e)?.clear():this.#e.clear()}}const Za=["page","identify"];class si{allowedEventTypes;builder;api;duplicationDetector;interceptors;constructor(e){const{api:n,builder:r,config:i,interceptors:o}=e;this.allowedEventTypes=i?.allowedEventTypes??Za,this.api=n,this.builder=r,this.duplicationDetector=new oi(i?.preventedComponentEvents),this.interceptors=o}}class ai extends si{}var Fa=Object.create,ci=Object.defineProperty,qa=Object.getOwnPropertyDescriptor,ui=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),li=t=>{throw TypeError(t)},di=(t,e,n)=>e in t?ci(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ha=t=>[,,,Fa(t?.[ui("metadata")]??null)],fi=["class","method","getter","setter","accessor","field","value","get","set"],pi=t=>t!==void 0&&typeof t!="function"?li("Function expected"):t,Ka=(t,e,n,r,i)=>({kind:fi[t],name:e,metadata:r,addInitializer:o=>n._?li("Already initialized"):i.push(pi(o||null))}),Wa=(t,e)=>di(e,ui("metadata"),t[3]),Ga=(t,e,n,r)=>{for(var i=0,o=t[e>>1],s=o&&o.length;i<s;i++)o[i].call(n);return r},hi=(t,e,n,r,i,o)=>{for(var s,a,c,u,d=e&7,m=!1,_=!1,S=2,b=fi[d+5],L=t[S]||(t[S]=[]),I=(i=i.prototype,qa(i,n)),M=r.length-1;M>=0;M--)c=Ka(d,n,a={},t[3],L),c.static=m,c.private=_,u=c.access={has:ie=>n in ie},u.get=ie=>ie[n],s=(0,r[M])(I[b],c),a._=1,pi(s)&&(I[b]=s);return I&&ci(i,n,I),i},Vn=(t,e,n)=>di(t,typeof e!="symbol"?e+"":e,n),gi,vi,Wt,Ge;const H=P("Analytics"),Ja=25;class Je extends(Wt=ai,vi=[U("isNotDuplicated",{onBlocked:"onBlockedByDuplication"}),U("hasConsent",{onBlocked:"onBlockedByConsent"})],gi=[U("isNotDuplicated",{onBlocked:"onBlockedByDuplication"}),U("hasConsent",{onBlocked:"onBlockedByConsent"})],Wt){constructor(e){const{api:n,builder:r,config:i,interceptors:o}=e;super({api:n,builder:r,config:i,interceptors:o}),Ga(Ge,5,this),Vn(this,"queue",new Map),Vn(this,"states",{eventStream:D(W),profile:D(A)});const{defaults:s}=i??{};if(s?.profile!==void 0){const{profile:a}=s;A.value=a}V(()=>{const a=A.value?.id;H.info(`Analytics ${Z.value?"will":"will not"} be collected due to consent (${Z.value})`),H.debug(`Profile ${a&&`with ID ${a}`} has been ${a?"set":"cleared"}`)}),V(()=>{Ue.value&&this.flush()})}reset(){be(()=>{W.value=void 0,A.value=void 0})}hasConsent(e){return!!Z.value||(this.allowedEventTypes??[]).includes(e==="trackComponentView"||e==="trackFlagView"?"component":e)}onBlockedByConsent(e,n){H.warn(`Event "${e}" was blocked due to lack of consent; payload: ${JSON.stringify(n)}`)}isNotDuplicated(e,n){const[{componentId:r},i]=n,o=this.duplicationDetector.isPresent(i,r);return o||this.duplicationDetector.addValue(i,r),!o}onBlockedByDuplication(e,n){const r=e==="trackFlagView"?"flag":"component";H.debug(`Duplicate "${r} view" event detected, skipping; payload: ${JSON.stringify(n)}`)}async trackComponentView(e,n=""){H.info(`Processing "component view" event for ${e.componentId}`),await this.enqueueEvent(this.builder.buildComponentView(e))}async trackFlagView(e,n=""){H.debug(`Processing "flag view" event for ${e.componentId}`),await this.enqueueEvent(this.builder.buildFlagView(e))}async enqueueEvent(e){const{value:n}=A;if(!n){H.warn("Attempting to emit an event without an Optimization profile");return}const r=await this.interceptors.event.run(e),i=vn.parse(r);H.debug(`Queueing ${i.type} event for profile ${n.id}`,i);const o=this.queue.get(n);W.value=i,o?o.push(i):this.queue.set(n,[i]),await this.flushMaxEvents()}async flushMaxEvents(){this.queue.values().toArray().flat().length>=Ja&&await this.flush()}async flush(){H.debug("Flushing event queue");const e=[];if(this.queue.forEach((r,i)=>e.push({profile:i,events:r})),!e.length)return;await this.api.insights.sendBatchEvents(e)&&this.queue.clear()}}Ge=Ha(Wt);hi(Ge,1,"trackComponentView",vi,Je);hi(Ge,1,"trackFlagView",gi,Je);Wa(Ge,Je);const Nn=P("Analytics");class yi extends ai{async trackComponentView(e){Nn.info('Processing "component view" event');const{profile:n,...r}=e,i=this.builder.buildComponentView(r),o=await this.interceptors.event.run(i),s=le.parse(o);await this.sendBatchEvent(s,n)}async trackFlagView(e){Nn.debug('Processing "flag view" event');const{profile:n,...r}=e,i=this.builder.buildFlagView(r),o=await this.interceptors.event.run(i),s=le.parse(o);await this.sendBatchEvent(s,n)}async sendBatchEvent(e,n){const r=yn.parse([{profile:n,events:[e]}]);await this.api.insights.sendBatchEvents(r)}}const mi="0.1.0-alpha",Ve="ctfl-opt-aid";class Gt{interceptors=new Map;nextId=0;add(e){const{nextId:n}=this;return this.nextId+=1,this.interceptors.set(n,e),n}remove(e){return this.interceptors.delete(e)}clear(){this.interceptors.clear()}count(){return this.interceptors.size}async run(e){const n=Array.from(this.interceptors.values());let r=e;for(const i of n)r=await i(r);return r}}class bi{api;eventBuilder;config;interceptors={event:new Gt,state:new Gt};constructor(e){this.config=e;const{analytics:n,personalization:r,eventBuilder:i,logLevel:o,environment:s,clientId:a}=e;Q.addSink(new Yr(o));const c={...n,...r,clientId:a,environment:s};this.api=new ri(c),this.eventBuilder=new ii(i??{channel:"server",library:{name:"Optimization Core",version:mi}})}getCustomFlag(e,n){return this.personalization.getCustomFlag(e,n)}personalizeEntry(e,n){return this.personalization.personalizeEntry(e,n)}getMergeTagValue(e,n){return this.personalization.getMergeTagValue(e,n)}async identify(e){return await this.personalization.identify(e)}async page(e){return await this.personalization.page(e)}async screen(e){return await this.personalization.screen(e)}async track(e){return await this.personalization.track(e)}async trackComponentView(e,n){if(e.sticky)return await this.personalization.trackComponentView(e,n);await this.analytics.trackComponentView(e,n)}async trackFlagView(e,n){await this.analytics.trackFlagView(e,n)}}class _i extends si{flagsResolver=pt;mergeTagValueResolver=we;personalizedEntryResolver=ue;getCustomFlag(e,n){return pt.resolve(n)[e]}personalizeEntry(e,n){return ue.resolve(e,n)}getMergeTagValue(e,n){return we.resolve(e,n)}}var Qa=Object.create,wi=Object.defineProperty,Xa=Object.getOwnPropertyDescriptor,Ei=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Si=t=>{throw TypeError(t)},zi=(t,e,n)=>e in t?wi(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ya=t=>[,,,Qa(t?.[Ei("metadata")]??null)],Ti=["class","method","getter","setter","accessor","field","value","get","set"],Ai=t=>t!==void 0&&typeof t!="function"?Si("Function expected"):t,ec=(t,e,n,r,i)=>({kind:Ti[t],name:e,metadata:r,addInitializer:o=>n._?Si("Already initialized"):i.push(Ai(o||null))}),tc=(t,e)=>zi(e,Ei("metadata"),t[3]),nc=(t,e,n,r)=>{for(var i=0,o=t[e>>1],s=o&&o.length;i<s;i++)o[i].call(n);return r},Qe=(t,e,n,r,i,o)=>{for(var s,a,c,u,d=e&7,m=!1,_=!1,S=2,b=Ti[d+5],L=t[S]||(t[S]=[]),I=(i=i.prototype,Xa(i,n)),M=r.length-1;M>=0;M--)c=ec(d,n,a={},t[3],L),c.static=m,c.private=_,u=c.access={has:ie=>n in ie},u.get=ie=>ie[n],s=(0,r[M])(I[b],c),a._=1,Ai(s)&&(I[b]=s);return I&&wi(i,n,I),i},Bt=(t,e,n)=>zi(t,typeof e!="symbol"?e+"":e,n),Pi,ki,Ci,Ii,$i,Jt,ne;const x=P("Personalization");class re extends(Jt=_i,$i=[U("hasConsent",{onBlocked:"onBlockedByConsent"})],Ii=[U("hasConsent",{onBlocked:"onBlockedByConsent"})],Ci=[U("hasConsent",{onBlocked:"onBlockedByConsent"})],ki=[U("hasConsent",{onBlocked:"onBlockedByConsent"})],Pi=[U("isNotDuplicated",{onBlocked:"onBlockedByDuplication"}),U("hasConsent",{onBlocked:"onBlockedByConsent"})],Jt){constructor(e){const{api:n,builder:r,config:i,interceptors:o}=e;super({api:n,builder:r,config:i,interceptors:o}),nc(ne,5,this),Bt(this,"offlineQueue",new Set),Bt(this,"states",{eventStream:D(W),flags:D(mn),profile:D(A),personalizations:D(F)}),Bt(this,"getAnonymousId");const{defaults:s,getAnonymousId:a}=i??{};if(s){const{changes:c,personalizations:u,profile:d}=s;be(()=>{X.value=c,F.value=u,A.value=d})}if(s?.consent!==void 0){const{consent:c}=s;Z.value=c}this.getAnonymousId=a??(()=>{}),V(()=>{x.debug(`Profile ${A.value&&`with ID ${A.value.id}`} has been ${A.value?"set":"cleared"}`)}),V(()=>{x.debug(`Variants have been ${F.value?.length?"populated":"cleared"}`)}),V(()=>{x.info(`Personalization ${Z.value?"will":"will not"} take effect due to consent (${Z.value})`)}),V(()=>{Ue.value&&this.flush()})}reset(){be(()=>{X.value=void 0,W.value=void 0,A.value=void 0,F.value=void 0})}getCustomFlag(e,n=X.value){return super.getCustomFlag(e,n)}personalizeEntry(e,n=F.value){return super.personalizeEntry(e,n)}getMergeTagValue(e,n=A.value){return super.getMergeTagValue(e,n)}hasConsent(e){return!!Z.value||(this.allowedEventTypes??[]).includes(e==="trackComponentView"||e==="trackFlagView"?"component":e)}onBlockedByConsent(e,n){x.warn(`Event "${e}" was blocked due to lack of consent; payload: ${JSON.stringify(n)}`)}isNotDuplicated(e,n){const[{componentId:r},i]=n,o=this.duplicationDetector.isPresent(i,r);return o||this.duplicationDetector.addValue(i,r),!o}onBlockedByDuplication(e,n){x.debug(`Duplicate "component view" event detected, skipping; payload: ${JSON.stringify(n)}`)}async identify(e){x.info('Sending "identify" event');const n=this.builder.buildIdentify(e);return await this.sendOrEnqueueEvent(n)}async page(e){x.info('Sending "page" event');const n=this.builder.buildPageView(e);return await this.sendOrEnqueueEvent(n)}async screen(e){x.info(`Sending "screen" event for "${e.name}"`);const n=this.builder.buildScreenView(e);return await this.sendOrEnqueueEvent(n)}async track(e){x.info(`Sending "track" event "${e.event}"`);const n=this.builder.buildTrack(e);return await this.sendOrEnqueueEvent(n)}async trackComponentView(e,n=""){x.info(`Sending "track personalization" event for ${e.componentId}`);const r=this.builder.buildComponentView(e);return await this.sendOrEnqueueEvent(r)}async sendOrEnqueueEvent(e){const n=await this.interceptors.event.run(e),r=hn.parse(n);if(W.value=r,Ue.value)return await this.upsertProfile([r]);x.debug(`Queueing ${r.type} event`,r),this.offlineQueue.add(r)}async flush(){this.offlineQueue.size!==0&&(x.debug("Flushing offline event queue"),await this.upsertProfile(Array.from(this.offlineQueue)),this.offlineQueue.clear())}async upsertProfile(e){const n=this.getAnonymousId();n&&x.debug(`Anonymous ID found: ${n}`);const r=await this.api.experience.upsertProfile({profileId:n??A.value?.id,events:e});return await this.updateOutputSignals(r),r}async updateOutputSignals(e){const n=await this.interceptors.state.run(e),{changes:r,personalizations:i,profile:o}=n;be(()=>{Lt(X.value,r)||(X.value=r),Lt(A.value,o)||(A.value=o),Lt(F.value,i)||(F.value=i)})}}ne=Ya(Jt);Qe(ne,1,"identify",$i,re);Qe(ne,1,"page",Ii,re);Qe(ne,1,"screen",Ci,re);Qe(ne,1,"track",ki,re);Qe(ne,1,"trackComponentView",Pi,re);tc(ne,re);const Ie=P("Personalization");class Ri extends _i{async identify(e){Ie.info('Sending "identify" event');const{profile:n,...r}=e,i=Pt.parse(this.builder.buildIdentify(r));return await this.upsertProfile(i,n)}async page(e){Ie.info('Sending "page" event');const{profile:n,...r}=e,i=kt.parse(this.builder.buildPageView(r));return await this.upsertProfile(i,n)}async screen(e){Ie.info(`Sending "screen" event for "${e.name}"`);const{profile:n,...r}=e,i=Ct.parse(this.builder.buildScreenView(r));return await this.upsertProfile(i,n)}async track(e){Ie.info(`Sending "track" event "${e.event}"`);const{profile:n,...r}=e,i=It.parse(this.builder.buildTrack(r));return await this.upsertProfile(i,n)}async trackComponentView(e){Ie.info('Sending "track personalization" event');const{profile:n,...r}=e,i=le.parse(this.builder.buildComponentView(r));return await this.upsertProfile(i,n)}async upsertProfile(e,n){const r=await this.interceptors.event.run(e);return await this.api.experience.upsertProfile({profileId:n?.id,events:[r]})}}class Oi extends bi{analytics;personalization;constructor(e){super(e);const{allowedEventTypes:n,defaults:r,getAnonymousId:i,preventedComponentEvents:o}=e;if(r?.consent!==void 0){const{consent:s}=r;Z.value=s}this.analytics=new Je({api:this.api,builder:this.eventBuilder,config:{allowedEventTypes:n,preventedComponentEvents:o,defaults:{consent:r?.consent,profile:r?.profile}},interceptors:this.interceptors}),this.personalization=new re({api:this.api,builder:this.eventBuilder,config:{allowedEventTypes:n,getAnonymousId:i,preventedComponentEvents:o,defaults:{consent:r?.consent,changes:r?.changes,profile:r?.profile,personalizations:r?.personalizations}},interceptors:this.interceptors})}get states(){return{consent:D(Z),eventStream:D(W),flags:D(mn),personalizations:D(F),profile:D(A)}}reset(){be(()=>{W.value=void 0,X.value=void 0,A.value=void 0,F.value=void 0})}async flush(){await this.analytics.flush(),await this.personalization.flush()}consent(e){Z.value=e}online(e){Ue.value=e}registerPreviewPanel(e){e.signals=me}}class rc extends bi{analytics;personalization;constructor(e){super(e),this.analytics=new yi({api:this.api,builder:this.eventBuilder,interceptors:this.interceptors}),this.personalization=new Ri({api:this.api,builder:this.eventBuilder,interceptors:this.interceptors})}}/*! js-cookie v3.0.5 | MIT */function tt(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}var ic={read:function(t){return t[0]==='"'&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function Qt(t,e){function n(i,o,s){if(!(typeof document>"u")){s=tt({},e,s),typeof s.expires=="number"&&(s.expires=new Date(Date.now()+s.expires*864e5)),s.expires&&(s.expires=s.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in s)s[c]&&(a+="; "+c,s[c]!==!0&&(a+="="+s[c].split(";")[0]));return document.cookie=i+"="+t.write(o,i)+a}}function r(i){if(!(typeof document>"u"||arguments.length&&!i)){for(var o=document.cookie?document.cookie.split("; "):[],s={},a=0;a<o.length;a++){var c=o[a].split("="),u=c.slice(1).join("=");try{var d=decodeURIComponent(c[0]);if(s[d]=t.read(u,d),i===d)break}catch{}}return i?s[i]:s}}return Object.create({set:n,get:r,remove:function(i,o){n(i,"",tt({},o,{expires:-1}))},withAttributes:function(i){return Qt(this.converter,tt({},this.attributes,i))},withConverter:function(i){return Qt(tt({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var nt=Qt(ic,{path:"/"});const Xt=P("Web:AutoTracking");function De(t){if(!(typeof HTMLElement<"u"&&typeof SVGElement<"u")||!t||t.nodeType!==1||!("dataset"in t)||!t.dataset||typeof t.dataset!="object"||!("ctflEntryId"in t.dataset))return!1;const{dataset:{ctflEntryId:n}}=t;return typeof n=="string"&&n.trim().length>0}function Ln(t){return!t||typeof t!="object"?!1:"entryId"in t&&typeof t.entryId=="string"&&!!t.entryId.trim().length}function oc(t){return(t?.trim().toLowerCase()??"")==="true"}function sc(t){if(t===void 0||!/^\d+$/.test(t))return;const e=Number(t);return Number.isSafeInteger(e)?e:void 0}const ac=t=>async(e,n)=>{if(!Ln(n.data)&&!De(e))return;let r,i,o,s,a;if(Ln(n.data))({data:{duplicationScope:r,entryId:i,personalizationId:o,sticky:s,variantIndex:a}}=n);else if(De(e)){({dataset:{ctflDuplicationScope:r,ctflEntryId:i,ctflPersonalizationId:o}}=e);const{dataset:{ctflSticky:c,ctflVariantIndex:u}}=e;s=oc(c),a=sc(u)}if(!i){Xt.warn("No entry data found in entry view observer callback; please add data attributes or observe with data info");return}await t.trackComponentView({componentId:i,experienceId:o,sticky:s,variantIndex:a},r)};function Bn(t){if(De(t))return t;const e=t.querySelector("[data-ctfl-entry-id]")??void 0;return De(e)?e:void 0}const cc=(t,e=!1)=>({onRemoved:n=>{n.forEach(r=>{const i=Bn(r);!i||!t.getStats(i)||(Xt.info("Auto-unobserving element (remove):",i),t.unobserve(i))})},onAdded:e?n=>{n.forEach(r=>{const i=Bn(r);i&&(Xt.info("Auto-observing element (add):",i),t.observe(i))})}:void 0}),uc=P("Web:EventBuilder");function lc(t){return new URL(t).searchParams.entries().reduce((e,[n,r])=>(e[n]=r,e),{})}function Mi(){const{languages:t,language:e}=navigator;return t[0]??e}function xi(){try{const t=new URL(window.location.href),{referrer:e,title:n}=document;return{hash:window.location.hash,height:window.innerHeight,path:t.pathname,query:lc(t),referrer:e,search:t.search,title:n,url:t.toString(),width:window.innerWidth}}catch(t){return t instanceof Error&&uc.error("Failed to get page properties:",t),{path:"",query:{},referrer:"",search:"",title:"",url:""}}}function Vi(){return navigator.userAgent}const Ni="0.1.0-alpha",O=typeof window<"u"&&typeof document<"u"&&typeof document.addEventListener=="function";function Li(t,e){const n=new Blob([JSON.stringify(e)],{type:"text/plain"});return window.navigator.sendBeacon(t,n)}const dc=P("Web:Network");function fc(t){if(!O)return()=>{};const e=i=>{(async()=>{try{await t(i)}catch(o){dc.error("Error in online state callback:",o)}})()},n=()=>{e(!0)},r=()=>{e(!1)};return window.addEventListener("online",n),window.addEventListener("offline",r),e(typeof navigator.onLine=="boolean"?navigator.onLine:!0),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",r)}}const pc=P("Web:Visibility");function hc(t){if(!O)return()=>{};let e=!1;const n=a=>{e||(e=!0,(async()=>{try{await t(a)}catch(c){pc.error("Error handling page visibility change:",c)}})())},r=()=>{e=!1},i=a=>{document.visibilityState==="hidden"?n(a):r()},o=a=>{n(a)},s=()=>{r()};return document.addEventListener("visibilitychange",i),window.addEventListener("pagehide",o),window.addEventListener("pageshow",s),()=>{document.removeEventListener("visibilitychange",i),window.removeEventListener("pagehide",o),window.removeEventListener("pageshow",s)}}const $e=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),Re=()=>O?document.visibilityState==="visible":!0,ce={DWELL_MS:1e3,RATIO:.1,MAX_RETRIES:2,BACKOFF_MS:300,MULTIPLIER:2,JITTER_DIVISOR:2,SWEEP_INTERVAL_MS:3e4},gc=t=>t+Math.floor(Math.random()*Math.max(1,Math.floor(t/ce.JITTER_DIVISOR))),N={n:(t,e)=>typeof t=="number"?t:e,clamp01:(t,e)=>Math.min(1,Math.max(0,N.n(t,e))),nonNeg:(t,e)=>Math.max(0,N.n(t,e)),atLeast1:(t,e)=>Math.max(1,N.n(t,e))},se=t=>{t.fireTimer!==null&&(clearTimeout(t.fireTimer),t.fireTimer=null)},ae=t=>{t.retryTimer!==null&&(clearTimeout(t.retryTimer),t.retryTimer=null),t.retryScheduledAt=null},jt=t=>{if(t.ref&&typeof t.ref.deref=="function"){const e=t.ref.deref();if(e)return e}return t.strongRef??null},jn=100,Un=250,vc=16,yc=1,mc=O&&typeof MutationObserver<"u",Dn=O&&typeof window.requestIdleCallback=="function",bc=O&&typeof window.cancelIdleCallback=="function";class j{observer;root;idleTimeoutMs;maxChunk;onChange;onAdded;onRemoved;onError;pendingRecords=[];scheduled=!1;idleHandle=null;disconnected=!1;constructor(e={}){const{root:n,idleTimeoutMs:r=jn,maxChunk:i=Un,onChange:o,onAdded:s,onRemoved:a,onError:c}=e;this.root=j.isNode(n)?n:O?document:null,this.idleTimeoutMs=j.sanitizeInt(r,jn,vc),this.maxChunk=j.sanitizeInt(i,Un,yc),this.onChange=o,this.onAdded=s,this.onRemoved=a,this.onError=c,mc&&this.root&&(this.observer=new MutationObserver(u=>{for(const d of u)(d.addedNodes.length>0||d.removedNodes.length>0)&&this.pendingRecords.push(d);this.pendingRecords.length>0&&this.scheduleProcess()}),this.observer.observe(this.root,{childList:!0,subtree:!0}))}isActive(){return!!this.observer&&!this.disconnected}disconnect(){this.disconnected||(this.disconnected=!0,this.observer?.disconnect(),this.pendingRecords=[],this.idleHandle!==null&&(j.cancelIdle(this.idleHandle),this.idleHandle=null),this.scheduled=!1)}flush(){this.isActive()&&(this.idleHandle!==null&&(j.cancelIdle(this.idleHandle),this.idleHandle=null),!(!this.scheduled&&this.pendingRecords.length===0)&&(this.scheduled=!1,this.processNow()))}scheduleProcess(){if(!this.isActive()||this.scheduled)return;this.scheduled=!0;const e=()=>{this.idleHandle=null,this.scheduled=!1,this.processNow()};this.idleHandle=Dn?window.requestIdleCallback(e,{timeout:this.idleTimeoutMs}):window.setTimeout(e,this.idleTimeoutMs)}processNow(){if(!this.isActive()||this.pendingRecords.length===0)return;const e=this.drainPending(),{addedNodes:n,removedNodes:r}=j.coalesce(e),{added:i,removed:o}=j.toElementSets(n,r);i.size===0&&o.size===0||(this.deliverAggregate(i,o,e),this.deliverPerKind(o,i))}static isNode(e){return O&&typeof Node<"u"&&e instanceof Node}static sanitizeInt(e,n,r){if(typeof e!="number"||!Number.isFinite(e))return n;const i=Math.trunc(e);return i>=r?i:r}static coalesce(e){const n=new Set,r=new Set;for(const i of e){for(const o of i.addedNodes)r.delete(o)||n.add(o);for(const o of i.removedNodes)n.delete(o)||r.add(o)}return{addedNodes:n,removedNodes:r}}static toElementSets(e,n){const r=j.flattenElements(e,!0),i=j.flattenElements(n,!1);return{added:r,removed:i}}static flattenElements(e,n){const r=new Set;for(const i of e){if(i instanceof Element){(!n||i.isConnected)&&r.add(i),i.querySelectorAll("*").forEach(o=>{(!n||o.isConnected)&&r.add(o)});continue}i instanceof DocumentFragment&&i.querySelectorAll("*").forEach(o=>{(!n||o.isConnected)&&r.add(o)})}return r}static cancelIdle(e){bc?window.cancelIdleCallback(e):O&&window.clearTimeout(e)}drainPending(){const{pendingRecords:e}=this;return this.pendingRecords=[],e}deliverAggregate(e,n,r){if(!this.onChange)return;const i={added:e,removed:n,records:r};this.safeCall(()=>this.onChange?.(i))}deliverPerKind(e,n){const r=e.size>0?[...e]:[],i=n.size>0?[...n]:[];this.onRemoved&&r.length>0&&this.dispatchChunked(r,this.onRemoved),this.onAdded&&i.length>0&&this.dispatchChunked(i,this.onAdded)}dispatchChunked(e,n){if(!this.isActive()||e.length===0)return;if(e.length<=this.maxChunk){this.safeCall(()=>n(e));return}let r=0;const i=()=>{if(!this.isActive())return;const o=Math.min(e.length,r+this.maxChunk),s=e.slice(r,o);r=o,this.safeCall(()=>n(s)),r<e.length&&(Dn?window.requestIdleCallback(i,{timeout:this.idleTimeoutMs}):O&&window.setTimeout(i,this.idleTimeoutMs))};i()}safeCall(e){try{const n=e();Promise.resolve(n).catch(r=>{this.onError?.(r)})}catch(n){this.onError?.(n)}}}class je{callback;opts;io;states=new WeakMap;activeStates=new Set;boundVisibilityHandler=null;sweepInterval=null;constructor(e,n){this.callback=e,this.opts=je.initOptions(n),this.io=new IntersectionObserver(r=>{this.onIntersect(r)},{root:this.opts.root??null,rootMargin:this.opts.rootMargin,threshold:this.opts.minVisibleRatio===0?[0]:[0,this.opts.minVisibleRatio]}),O&&(this.boundVisibilityHandler=()=>{this.onPageVisibilityChange()},document.addEventListener("visibilitychange",this.boundVisibilityHandler))}observe(e,n){let r=this.states.get(e);r||(r=this.createState(e,n),this.states.set(e,r),this.activeStates.add(r),this.ensureSweeper()),this.io.observe(e)}unobserve(e){this.io.unobserve(e);const n=this.states.get(e);n&&(se(n),ae(n),n.done=!0,this.activeStates.delete(n),n.strongRef===e&&(n.strongRef=null),this.states.delete(e),this.maybeStopSweeper())}disconnect(){this.io.disconnect();for(const e of this.activeStates)se(e),ae(e),e.done=!0,e.strongRef=null;this.activeStates.clear(),O&&this.boundVisibilityHandler&&(document.removeEventListener("visibilitychange",this.boundVisibilityHandler),this.boundVisibilityHandler=null),this.stopSweeper()}getStats(e){const n=this.states.get(e);return n?{accumulatedMs:n.accumulatedMs,visibleSince:n.visibleSince,attempts:n.attempts,done:n.done,inFlight:n.inFlight,pendingRetry:n.pendingRetry,lastKnownVisible:n.lastKnownVisible}:null}static initOptions(e){return{dwellTimeMs:N.nonNeg(e?.dwellTimeMs,ce.DWELL_MS),minVisibleRatio:N.clamp01(e?.minVisibleRatio,ce.RATIO),root:e?.root??null,rootMargin:e?.rootMargin??"0px",maxRetries:N.nonNeg(e?.maxRetries,ce.MAX_RETRIES),retryBackoffMs:N.nonNeg(e?.retryBackoffMs,ce.BACKOFF_MS),backoffMultiplier:N.atLeast1(e?.backoffMultiplier,ce.MULTIPLIER)}}createState(e,n){const r={dwellTimeMs:N.nonNeg(n?.dwellTimeMs,this.opts.dwellTimeMs),maxRetries:N.nonNeg(n?.maxRetries,this.opts.maxRetries),retryBackoffMs:N.nonNeg(n?.retryBackoffMs,this.opts.retryBackoffMs),backoffMultiplier:N.atLeast1(n?.backoffMultiplier,this.opts.backoffMultiplier)},i=typeof WeakRef=="function";return{ref:i?new WeakRef(e):null,strongRef:i?null:e,opts:r,data:n?.data,accumulatedMs:0,visibleSince:null,fireTimer:null,retryTimer:null,retryScheduledAt:null,retryDelayMs:null,pendingRetry:!1,attempts:0,done:!1,inFlight:!1,lastKnownVisible:!1}}onPageVisibilityChange(){const e=$e(),n=!Re();for(const r of this.activeStates)n?je.onHidden(r,e):this.onResume(r,e);this.sweepOrphans()}static onHidden(e,n){if(!e.done&&(e.visibleSince!==null&&(e.accumulatedMs+=n-e.visibleSince,e.visibleSince=null),se(e),e.retryTimer!==null)){const r=e.retryScheduledAt?n-e.retryScheduledAt:0,i=e.retryDelayMs!==null?Math.max(0,e.retryDelayMs-r):null;ae(e),i!==null&&(e.pendingRetry=!0,e.retryDelayMs=i,e.retryScheduledAt=null)}}onResume(e,n){e.done||(e.lastKnownVisible&&e.visibleSince===null&&(e.visibleSince=n,this.scheduleFireIfDue(e,n)),e.pendingRetry&&!e.inFlight&&e.lastKnownVisible&&e.retryDelayMs!==null&&this.scheduleRetry(e,e.retryDelayMs))}onIntersect(e){const n=$e();for(const r of e){const i=this.states.get(r.target);if(!i||i.done)continue;r.isIntersecting&&r.intersectionRatio>=this.opts.minVisibleRatio&&Re()?this.onVisible(i,n):je.onNotVisible(i,n)}this.sweepOrphans()}onVisible(e,n){if(e.lastKnownVisible=!0,e.visibleSince===null){e.visibleSince=n,e.attempts=0,e.pendingRetry&&!e.inFlight&&e.retryDelayMs!==null?this.scheduleRetry(e,e.retryDelayMs):this.scheduleFireIfDue(e,n);return}!e.pendingRetry&&e.fireTimer===null&&!e.inFlight&&this.scheduleFireIfDue(e,n)}static onNotVisible(e,n){e.lastKnownVisible=!1,e.visibleSince!==null&&(e.accumulatedMs+=n-e.visibleSince,e.visibleSince=null),se(e),(e.pendingRetry||e.retryTimer!==null)&&(ae(e),e.pendingRetry=!1,e.attempts=0)}scheduleFireIfDue(e,n){if(e.done||e.inFlight||e.fireTimer!==null||e.pendingRetry)return;const r=e.accumulatedMs+(e.visibleSince!==null?n-e.visibleSince:0),i=e.opts.dwellTimeMs-r;if(i<=0){this.trigger(e);return}e.fireTimer=setTimeout(()=>{!e.done&&e.lastKnownVisible&&Re()?this.trigger(e):se(e)},Math.ceil(i))}scheduleRetry(e,n){e.pendingRetry=!0,e.retryDelayMs=Math.max(0,Math.ceil(n)),!(!Re()||!e.lastKnownVisible||e.done||e.inFlight)&&(e.retryScheduledAt=$e(),e.retryTimer=setTimeout(()=>{e.retryTimer=null,e.retryScheduledAt=null,this.attemptCallback(e)},e.retryDelayMs))}trigger(e){if(e.done||e.inFlight)return;const n=$e(),r=e.accumulatedMs+(e.visibleSince!==null?n-e.visibleSince:0);ae(e),e.pendingRetry=!1,se(e),this.attemptCallback(e,r)}async attemptCallback(e,n){if(e.done||e.inFlight)return;const r=jt(e);if(!r){this.finalizeDroppedState(e);return}const i=e.attempts+1;e.attempts=i,e.inFlight=!0;const o=n??e.accumulatedMs+(e.visibleSince!==null?$e()-e.visibleSince:0);try{await this.callback(r,{totalVisibleMs:o,attempts:i,data:e.data}),this.onAttemptSuccess(e,r)}catch{this.onAttemptFailure(e)}}onAttemptSuccess(e,n){e.inFlight=!1,e.done=!0,this.safeAutoUnobserve(n,e)}onAttemptFailure(e){if(e.inFlight=!1,e.attempts>e.opts.maxRetries){this.onRetriesExceeded(e);return}const n=e.opts.retryBackoffMs*Math.pow(e.opts.backoffMultiplier,e.attempts-1),r=gc(n);if(!e.lastKnownVisible||!Re()){e.pendingRetry=!0,e.retryDelayMs=Math.ceil(r),e.retryScheduledAt=null;return}this.scheduleRetry(e,r)}onRetriesExceeded(e){ae(e),e.pendingRetry=!1,e.done=!0;const n=jt(e);n?this.safeAutoUnobserve(n,e):this.finalizeDroppedState(e)}finalizeDroppedState(e){se(e),ae(e),e.done=!0,this.activeStates.delete(e),e.strongRef&&(this.states.delete(e.strongRef),e.strongRef=null),this.maybeStopSweeper()}safeAutoUnobserve(e,n){try{this.unobserve(e)}catch{this.activeStates.delete(n),n.strongRef===e&&(this.states.delete(e),n.strongRef=null),n.done=!0,this.maybeStopSweeper()}}ensureSweeper(){this.sweepInterval===null&&(this.sweepInterval=setInterval(()=>{this.sweepOrphans()},ce.SWEEP_INTERVAL_MS))}stopSweeper(){this.sweepInterval!==null&&(clearInterval(this.sweepInterval),this.sweepInterval=null)}maybeStopSweeper(){this.activeStates.size===0&&this.stopSweeper()}sweepOrphans(){if(O){for(const e of Array.from(this.activeStates)){const n=jt(e);if(!n){this.finalizeDroppedState(e);continue}(typeof n.isConnected=="boolean"?n.isConnected:document.contains(n))||this.safeAutoUnobserve(n,e)}this.maybeStopSweeper()}}}const st="__ctfl_opt_anonymous_id__",at="__ctfl_opt_consent__",ct="__ctfl_opt_changes__",ut="__ctfl_opt_debug__",lt="__ctfl_opt_profile__",dt="__ctfl_opt_personalizations__",w={reset(t={resetConsent:!1,resetDebug:!1}){t.resetConsent&&localStorage.removeItem(at),t.resetDebug&&localStorage.removeItem(ut),localStorage.removeItem(st),localStorage.removeItem(ct),localStorage.removeItem(lt),localStorage.removeItem(dt)},get anonymousId(){return localStorage.getItem(st)??void 0},set anonymousId(t){w.setCache(st,t)},get consent(){switch(localStorage.getItem(at)){case"accepted":return!0;case"denied":return!1}},set consent(t){const e=t?"accepted":"denied";w.setCache(at,t===void 0?void 0:e)},get debug(){const t=localStorage.getItem(ut);return t?t==="true":void 0},set debug(t){w.setCache(ut,t)},get changes(){return w.getCache(ct,un)},set changes(t){w.setCache(ct,t)},get profile(){return w.getCache(lt,Ke)},set profile(t){w.setCache(lt,t)},get personalizations(){return w.getCache(dt,gn)},set personalizations(t){w.setCache(dt,t)},getCache(t,e){const n=localStorage.getItem(t);if(!n)return;const r=e.safeParse(JSON.parse(n));if(r.success)return r.data},setCache(t,e){e===void 0?localStorage.removeItem(t):localStorage.setItem(t,typeof e=="string"?e:JSON.stringify(e))}},Ut=P("Web:SDK"),_c=365;function wc({app:t,defaults:e,logLevel:n,...r}){const{consent:i=w.consent,profile:o=w.profile,changes:s=w.changes,personalizations:a=w.personalizations}=e??{};return ye({analytics:{beaconHandler:Li},defaults:{consent:i,changes:s,profile:o,personalizations:a},eventBuilder:{app:t,channel:"web",library:{name:"Optimization Web API",version:Ni},getLocale:Mi,getPageProperties:xi,getUserAgent:Vi},getAnonymousId:()=>w.anonymousId,logLevel:w.debug?"debug":n},r)}class Bi extends Oi{elementViewObserver=void 0;elementExistenceObserver=void 0;autoTrackEntryViews=!1;cookieAttributes=void 0;constructor(e){if(typeof window<"u"&&window.optimization)throw new Error("Optimization is already initialized");const{autoTrackEntryViews:n,...r}=e,i=wc(r);super(i);const o=nt.get(Ve);this.cookieAttributes={domain:i.cookie?.domain,expires:i.cookie?.expires??_c},this.autoTrackEntryViews=!0,fc(s=>{this.online(s)}),hc(async()=>{await this.flush()}),V(()=>{const{changes:{value:s}}=me;w.changes=s}),V(()=>{const{consent:{value:s}}=me;this.autoTrackEntryViews&&(s?this.startAutoTrackingEntryViews():this.stopAutoTrackingEntryViews()),w.consent=s}),V(()=>{const{profile:{value:s}}=me;w.profile=s,this.setAnonymousId(s?.id)}),V(()=>{const{personalizations:{value:s}}=me;w.personalizations=s}),o&&o!==w.anonymousId&&(this.reset(),this.setAnonymousId(o)),typeof window<"u"&&(window.optimization??=this)}setAnonymousId(e){if(!e){nt.remove(Ve),w.anonymousId=void 0;return}nt.set(Ve,e,this.cookieAttributes),w.anonymousId=e}startAutoTrackingEntryViews(e){this.autoTrackEntryViews=!0,this.elementViewObserver=new je(ac(this)),this.elementExistenceObserver=new j(cc(this.elementViewObserver,!0)),document.querySelectorAll("[data-ctfl-entry-id]").forEach(r=>{De(r)&&(Ut.info("Auto-observing element (init):",r),this.elementViewObserver?.observe(r,{...e}))})}stopAutoTrackingEntryViews(){this.elementExistenceObserver?.disconnect(),this.elementViewObserver?.disconnect()}trackEntryViewForElement(e,n){Ut.info("Manually observing element:",e),this.elementViewObserver?.observe(e,n)}untrackEntryViewForElement(e){Ut.info("Manually unobserving element:",e),this.elementViewObserver?.unobserve(e)}reset(){this.stopAutoTrackingEntryViews(),nt.remove(Ve),w.reset(),super.reset()}}typeof window<"u"&&(window.Optimization??=Bi);exports.ANONYMOUS_ID=st;exports.ANONYMOUS_ID_COOKIE=Ve;exports.AliasEvent=ln;exports.AnalyticsStateful=Je;exports.AnalyticsStateless=yi;exports.ApiClient=ri;exports.App=Ir;exports.AudienceEntry=vr;exports.AudienceEntryFields=gr;exports.BatchExperienceData=Nr;exports.BatchExperienceEvent=Fr;exports.BatchExperienceEventArray=Ts;exports.BatchExperienceResponse=Lr;exports.BatchInsightsEvent=Gr;exports.BatchInsightsEventArray=yn;exports.CAN_ADD_LISTENERS=O;exports.CHANGES_CACHE=ct;exports.CONSENT=at;exports.Campaign=cn;exports.Change=Zr;exports.ChangeArray=un;exports.ChangeType=Br;exports.Channel=$r;exports.ComponentViewEvent=le;exports.ConsoleLogSink=Yr;exports.ContentTypeLink=lr;exports.CoreStateful=Oi;exports.CoreStateless=rc;exports.CtflEntry=Ae;exports.DEBUG_FLAG=ut;exports.DEFAULT_PAGE_PROPERTIES=Ht;exports.Dictionary=Rr;exports.EXPERIENCE_BASE_URL=ti;exports.EntryFields=qe;exports.EntryReplacementComponent=br;exports.EntryReplacementVariant=vt;exports.EntrySys=sn;exports.EnvironmentLink=dr;exports.EventBuilder=ii;exports.ExperienceData=Kr;exports.ExperienceEvent=hn;exports.ExperienceEventArray=Le;exports.ExperienceRequestData=As;exports.ExperienceRequestOptions=qr;exports.ExperienceResponse=ot;exports.FlagsResolver=pt;exports.GeoLocation=St;exports.GroupEvent=dn;exports.INSIGHTS_BASE_URL=ni;exports.IdentifyEvent=Pt;exports.InlineVariableComponent=Er;exports.InlineVariableComponentValueType=wr;exports.InlineVariableVariant=Ft;exports.InsightsEvent=vn;exports.InsightsEventArray=Wr;exports.InterceptorManager=Gt;exports.Library=Or;exports.Link=ur;exports.LogSink=Xr;exports.Logger=Qr;exports.MergeTagEntry=yr;exports.MergeTagValueResolver=we;exports.OPTIMIZATION_CORE_SDK_VERSION=mi;exports.OPTIMIZATION_WEB_SDK_VERSION=Ni;exports.Optimization=Bi;exports.PERSONALIZATIONS_CACHE=dt;exports.PROFILE_CACHE=lt;exports.Page=pe;exports.PageEventContext=fn;exports.PageViewEvent=kt;exports.PartialProfile=xr;exports.PersonalizationComponent=Sr;exports.PersonalizationComponentArray=zr;exports.PersonalizationConfig=Tr;exports.PersonalizationEntry=an;exports.PersonalizationEntryArray=kr;exports.PersonalizationFields=Pr;exports.PersonalizationStateful=re;exports.PersonalizationStateless=Ri;exports.PersonalizationType=Ar;exports.PersonalizedEntry=Cr;exports.PersonalizedEntryResolver=ue;exports.Profile=Ke;exports.Properties=He;exports.Screen=zt;exports.ScreenEventContext=pn;exports.ScreenViewEvent=Ct;exports.SelectedPersonalization=Hr;exports.SelectedPersonalizationArray=gn;exports.SessionStatistics=Mr;exports.SpaceLink=fr;exports.TagLink=pr;exports.TrackEvent=It;exports.Traits=Tt;exports.UniversalEventContext=At;exports.UniversalEventProperties=te;exports.UnknownChange=zs;exports.ValuePresence=oi;exports.VariableChange=Dr;exports.VariableChangeValue=Ur;exports.batch=be;exports.beaconHandler=Li;exports.createScopedLogger=P;exports.effect=V;exports.getLocale=Mi;exports.getPageProperties=xi;exports.getUserAgent=Vi;exports.guardedBy=U;exports.isEntry=hr;exports.isEntryReplacementComponent=_r;exports.isEntryReplacementVariant=mr;exports.isInlineVariableComponent=ws;exports.isPersonalizationEntry=Me;exports.isPersonalizedEntry=it;exports.logger=Q;exports.signals=me;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|