@picked/client 0.0.1-dev.1763357104016 → 0.0.1-dev.1763359305886
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/shopify/index.js +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/plugins/shopify/index.js +1 -1
- package/dist/types/entities/response/response.d.ts.map +1 -1
- package/dist/{user-session-Ht0ayuo5.js → user-session-DINAj_Ci.js} +221 -217
- package/dist/user-session-nuW7qzmd.cjs +1 -0
- package/package.json +1 -1
- package/dist/user-session-D-l-VMTb.cjs +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var y=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var o=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../user-session-
|
|
1
|
+
"use strict";var m=Object.defineProperty;var y=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var o=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../user-session-nuW7qzmd.cjs"),d=require("../logger-BsmHUUw1.cjs"),l=require("../experience-instance-B2l_MG7I.cjs"),S=require("effector"),c=require("../supports-YvpQZxbh.cjs"),u=require("../storage-DuRlyFaY.cjs"),w=(i,e,t)=>{const s=e.name,n=e.setup(i);if(n){const a=t[s]??{};t[s]=Object.freeze({...a,...n})}};function v(i){const e=typeof window<"u",t={client:i,responses:i.responses.listStore.getState(),fields:i.fields.listStore.getState(),location:e?window.location:void 0,document:e?window.document:void 0,sessionStorage:e?window.sessionStorage:void 0,localStorage:e?window.localStorage:void 0};return Object.freeze(t)}const I=()=>S.createEvent(),P=()=>"0.0.1-dev.1763359305886";function k(){if(c.supportsDocument()){const i=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of i)if(e!=null&&e.dataset.api)return e.dataset.api}return"https://api.picked.app"}function x(){if(!c.supportsWindow())return{};const i=new URLSearchParams(window.location.search),e={},t=new Set;for(const[n]of i.entries())n.startsWith("picked-")&&t.add(n);for(const n of t){const a=n.replace("picked-","");e[a]=i.getAll(n)}const s=u.createStorageKey("s");if(t.size>0)u.sessionStore.set(s,e);else{const n=u.sessionStore.get(s);if(n)return n.json()||{}}return e}class h{constructor(e){o(this,"options");o(this,"isReady",!1);o(this,"project");o(this,"plugins",{});o(this,"eventBus",I());o(this,"organizationId");o(this,"projectId");o(this,"apiUrl");o(this,"session");o(this,"searchParams",x());o(this,"history",r.createHistory());o(this,"components",r.createComponentIndex({client:this}));o(this,"experienceInstances",l.createExperienceInstanceIndex({client:this}));o(this,"experiences",r.createExperienceIndex({client:this}));o(this,"frameworks",r.createFrameworkIndex({client:this}));o(this,"predicates",r.createPredicateIndex({client:this}));o(this,"features",r.createFeatureIndex({client:this}));o(this,"responses",r.createResponseIndex({client:this}));o(this,"fields",r.createFieldIndex());o(this,"actions",r.createActionIndex());d.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||k(),this.session=r.initialiseSession(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.eventBus({type:"initialized",version:P()}),d.logger("info","Picked client initialized.")}start(){r.ping(this),(async()=>{c.supportsDocument()&&(document.body&&r.initialiseExperiences(this),await l.domInteractive(),await r.initialiseExperiences(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session}))})()}registerFramework(e){r.setupFramework(e,this.frameworks)}registerComponent(e,t){r.setupComponent(e,t,this.components)}registerPlugin(e){w(this,e,this.plugins)}registerFeature(e,t){r.setupFeature(e,t,this.features)}registerPredicate(e,t){r.setupPredicate(e,t,this.predicates)}registerField(e){r.setupField(e,this.fields)}registerAction(e,t){r.setupAction(e,t,this.actions)}registerExperience(e){e.component&&r.setupComponent(`experience:${e.id}`,e.component,this.components),r.setupExperience(e,this.experiences)}getStateSnapshot(){return v(this)}async launchExperienceById(e){const t=this.experiences.getById(e).getState();if(!t){d.logger("warn",`Experience with id '${e}' not found.`);return}r.initialiseExperience(this,t)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(t=>{if(Array.isArray(t)){t.forEach(n=>{this.registerPlugin(n)});return}const s=typeof t=="function"?t():t;if(Array.isArray(s)){s.forEach(n=>this.registerPlugin(n));return}this.registerPlugin(s)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([t,s])=>{const n=typeof s=="function"?s():s;this.registerFeature(t,n)}),this.searchParams.feature&&this.searchParams.feature.forEach(t=>{try{const[s,n]=t.split(":");if(!s||!n)return;let a=n;a==="true"&&(a=!0),a==="false"&&(a=!1),this.registerFeature(s,{key:`${a}`,name:s,decide:()=>a,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([t,s])=>{if(typeof s!="function"){d.logger("warn",`Predicate "${t}" is not a function.`);return}this.registerPredicate(t,s)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([t,s])=>{if(typeof s!="function"){d.logger("warn",`Action "${t}" is not a function.`);return}this.registerAction(t,s)})}getPluginConfig(e){return this.plugins[e]??{}}}o(h,"logger",d.logger);function f(i){var e;return((e=i.options)==null?void 0:e.some(t=>"condition"in t))??!1}function E(i){return i.some(e=>e.condition||f(e))}async function C(i,e){return e.length===0||!E(e)?e:(await Promise.all(e.map(async s=>{if(!(s.condition?await l.evaluateRuleLogic(i,s.condition):!0))return null;if(!s.options||!f(s))return s;const g=(await Promise.all(s.options.map(async p=>p.condition?await l.evaluateRuleLogic(i,p.condition)?p:null:p))).filter(p=>p!==null);return g.length===s.options.length?s:g.length===0?null:{...s,options:g}}))).filter(s=>s!==null)}const R=i=>{const e=new h(i);return c.bindClient(e),e};exports.evaluateRuleLogic=l.evaluateRuleLogic;exports.isPickedRoot=l.isPickedRoot;exports.supportsCookies=c.supportsCookies;exports.supportsCryptoRandomUUID=c.supportsCryptoRandomUUID;exports.supportsDocument=c.supportsDocument;exports.supportsHistory=c.supportsHistory;exports.supportsIntersectionObserver=c.supportsIntersectionObserver;exports.supportsLocalStorage=c.supportsLocalStorage;exports.supportsLocation=c.supportsLocation;exports.supportsSessionStorage=c.supportsSessionStorage;exports.supportsShadowRoot=c.supportsShadowRoot;exports.supportsWebComponents=c.supportsWebComponents;exports.supportsWindow=c.supportsWindow;exports.createStorageKey=u.createStorageKey;exports.localStore=u.localStore;exports.sessionStore=u.sessionStore;exports.subscribe=u.subscribe;exports.Picked=h;exports.createClient=R;exports.getStepFields=C;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../../../supports-YvpQZxbh.cjs");require("../../../user-session-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../../../supports-YvpQZxbh.cjs");require("../../../user-session-nuW7qzmd.cjs");require("../../../experience-instance-B2l_MG7I.cjs");require("effector");function c(){if(!r.supportsWindow()||!window.pickedConfig)throw new Error("Picked config not found. Ensure the Picked Script is enabled on your Shopify storefront");return window.pickedConfig}function d(){if(r.supportsWindow())return c().customer}function s(){if(r.supportsWindow())return c().product}function u(){if(r.supportsWindow())return c().collection}function l(){if(r.supportsWindow())return c().experiments}function f(){var e;if(r.supportsWindow())return(e=c().storefront_api)==null?void 0:e.token}const t={homepage:/^\/$/,page:/(?:^|\/)pages\/[^/]+$/,blog:/(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,article:/^\/blogs\/[^/]+\/(?<article>[^/]+)\/?$/,cart:/(?:^|\/)cart\/[^/]+$/,checkout:/^\/checkout\/.+/,appProxy:/^\/(?:a|apps|community|tools)\/(?<proxyTarget>[^/]+)/,accountWildcard:/^\/account\/.+/,accountLogin:/^\/account\/login(?:\/|$)/,accountRegister:/^\/account\/register(?:\/|$)/},n=(e,o)=>o?!!e.exec(o.pathname):!1,a=(e,o)=>{if(o){const i=e.exec(o.pathname);if(i)return i[1]}},p=e=>{var o,i;switch(e){case"product":return((o=s())==null?void 0:o.handle)??!1;case"collection":return((i=u())==null?void 0:i.handle)??!1;default:return!1}},h={"is-page":({location:e})=>n(t.page,e),"get-page-handle":({location:e})=>a(t.page,e),"is-product-page":()=>!!p("product"),"get-product-handle":()=>p("product"),"is-collection-page":()=>!!p("collection"),"get-collection-handle":()=>p("collection"),"is-blog-page":({location:e})=>n(t.blog,e),"get-blog-handle":({location:e})=>a(t.blog,e),"is-article-page":({location:e})=>n(t.article,e),"get-article-handle":({location:e})=>a(t.article,e),"is-app-proxy-page":({location:e})=>n(t.appProxy,e),"get-app-proxy-handle":({location:e})=>a(t.appProxy,e),"is-account-page":({location:e})=>n(t.accountWildcard,e),"is-login-page":({location:e})=>n(t.accountLogin,e),"is-register-page":({location:e})=>n(t.accountRegister,e),"is-cart-page":({location:e})=>n(t.cart,e),"is-checkout-page":({location:e})=>n(t.checkout,e),"is-homepage":({location:e})=>n(t.homepage,e)};function g(){if(!r.supportsWindow()||!window.Shopify)throw new Error("Shopify global object not found. This plugin must be used on a Shopify storefront page.");return window.Shopify}function y(e){var o,i;return typeof((i=(o=g())==null?void 0:o.analytics)==null?void 0:i.publish)=="function"}const P=()=>({name:"shopify",setup:e=>{Object.entries(h).forEach(([o,i])=>{e.registerPredicate(`shopify-${o}`,i)}),r.supportsWindow()&&e.eventBus.watch(o=>{y()&&o.type==="session"&&window.Shopify.analytics.publish("picked:session",{id:o.id})})}});exports.getPickedConfig=c;exports.getPickedConfigCollection=u;exports.getPickedConfigCustomer=d;exports.getPickedConfigExperiments=l;exports.getPickedConfigProduct=s;exports.getPickedConfigStorefrontApiToken=f;exports.getShopify=g;exports.shopifyPlugin=P;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var y = Object.defineProperty;
|
|
2
2
|
var w = (i, e, t) => e in i ? y(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
3
|
var n = (i, e, t) => w(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { c as S, a as x, b as I, d as P, e as v, f as k, g as E, h as F, i as b, j as C, p as A, s as R, k as u, l as j, m as B, n as z, o as U, q as O, r as $, t as d } from "../user-session-
|
|
4
|
+
import { c as S, a as x, b as I, d as P, e as v, f as k, g as E, h as F, i as b, j as C, p as A, s as R, k as u, l as j, m as B, n as z, o as U, q as O, r as $, t as d } from "../user-session-DINAj_Ci.js";
|
|
5
5
|
import { l as c } from "../logger-C9a75KZn.js";
|
|
6
6
|
import { c as K, d as L, e as l } from "../experience-instance-CeuHLrdL.js";
|
|
7
7
|
import { i as pe } from "../experience-instance-CeuHLrdL.js";
|
|
@@ -29,7 +29,7 @@ function N(i) {
|
|
|
29
29
|
};
|
|
30
30
|
return Object.freeze(t);
|
|
31
31
|
}
|
|
32
|
-
const T = () => W(), V = () => "0.0.1-dev.
|
|
32
|
+
const T = () => W(), V = () => "0.0.1-dev.1763359305886";
|
|
33
33
|
function G() {
|
|
34
34
|
if (h()) {
|
|
35
35
|
const i = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../../src/entities/response/response.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../../src/entities/response/response.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAA;AAkB5E,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAInE,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAA;AAGjC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAA;CAC5B;AAED,QAAA,MAAM,0BAA0B,eAA8B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;wBA8BnD,KAAK,CAAC,IAAI,CAAC,YAAY,QAAQ,KAAG,IAAI;;;gCAwH5C,eAAe,KACjC,OAAO,CAAC;QAAE,MAAM,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC;8CApHpB,eAAe,KACjC,OAAO,CAAC;QAAE,iBAAiB,EAAE,eAAe,CAAC;QAAC,gBAAgB,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC;;;;;;;;4BA8IxD,KAAK,CAAC,IAAI,CAAC;gCAmBP,KAAK,CAAC,MAAM,CAAC;CAwChD,CAAA;AAEF,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC,CAAC,CAAC,EAC5F,MAAM,EAAE,CAAC,GACR,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAE/C;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAA;AAE7D,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;IAGpB,WAAW,EAAE,MAAM,CAAA;IAGnB,aAAa,EAAE,MAAM,CAAA;IAGrB,KAAK,EAAE,UAAU,CAAA;CAClB"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { createDomain as h, createApi as b, createEffect as j, attach as
|
|
2
|
-
import { createFactory as
|
|
3
|
-
import { g as
|
|
1
|
+
import { createDomain as h, createApi as b, createEffect as j, attach as U, sample as x, combine as B, createEvent as O } from "effector";
|
|
2
|
+
import { createFactory as k, invoke as v } from "@withease/factories";
|
|
3
|
+
import { g as C, t as H, b as q, f as z, e as L, h as G } from "./experience-instance-CeuHLrdL.js";
|
|
4
4
|
import { l as E } from "./logger-C9a75KZn.js";
|
|
5
|
-
import { c as
|
|
6
|
-
import { g as
|
|
7
|
-
import { i as
|
|
8
|
-
import { e as
|
|
9
|
-
const
|
|
10
|
-
({ client:
|
|
11
|
-
const i =
|
|
5
|
+
import { c as R, s as M, l as A } from "./storage-Cb_71y48.js";
|
|
6
|
+
import { g as K } from "./id-BW-g3y32.js";
|
|
7
|
+
import { i as Y } from "./object-JwZ58NOH.js";
|
|
8
|
+
import { e as J, k as Q } from "./supports-DBMT17KZ.js";
|
|
9
|
+
const _ = h("experience"), W = k(
|
|
10
|
+
({ client: e, experience: t }) => {
|
|
11
|
+
const i = _.store(t), g = b(i, {
|
|
12
12
|
merge(c, m) {
|
|
13
13
|
return {
|
|
14
14
|
...c,
|
|
@@ -19,18 +19,18 @@ const L = h("experience"), Q = v(
|
|
|
19
19
|
name: c.name,
|
|
20
20
|
decisionLogic: c.decide,
|
|
21
21
|
targetSelectors: c.targets,
|
|
22
|
-
initializeOpenLogic:
|
|
23
|
-
})), d =
|
|
24
|
-
(c) => c.find((m) => m.name === `experience:${
|
|
22
|
+
initializeOpenLogic: t.initializeOpen
|
|
23
|
+
})), d = e.components.listStore.map(
|
|
24
|
+
(c) => c.find((m) => m.name === `experience:${t.id}`) || c.find((m) => m.name === "experience"),
|
|
25
25
|
{ skipVoid: !1 }
|
|
26
26
|
), r = i.map((c) => ({
|
|
27
27
|
steps: c.steps,
|
|
28
28
|
nodes: c.nodes,
|
|
29
29
|
edges: c.edges,
|
|
30
30
|
conditionals: c.conditionals
|
|
31
|
-
})), n =
|
|
31
|
+
})), n = t.actions ?? [];
|
|
32
32
|
return {
|
|
33
|
-
id:
|
|
33
|
+
id: t.id,
|
|
34
34
|
configStore: p,
|
|
35
35
|
treeStore: r,
|
|
36
36
|
componentStore: d,
|
|
@@ -39,11 +39,11 @@ const L = h("experience"), Q = v(
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
);
|
|
42
|
-
function
|
|
43
|
-
return
|
|
42
|
+
function X(e) {
|
|
43
|
+
return v(W, e);
|
|
44
44
|
}
|
|
45
|
-
const
|
|
46
|
-
const
|
|
45
|
+
const Z = k(({ client: e }) => {
|
|
46
|
+
const t = _.store({}), i = b(t, {
|
|
47
47
|
register(r, n) {
|
|
48
48
|
return {
|
|
49
49
|
...r,
|
|
@@ -52,17 +52,17 @@ const X = v(({ client: t }) => {
|
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
function g(r) {
|
|
55
|
-
const n =
|
|
55
|
+
const n = t.getState()[r.id];
|
|
56
56
|
if (n) {
|
|
57
57
|
n.merge({ experience: r, strategy: "override" });
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
const c =
|
|
60
|
+
const c = X({ client: e, experience: r });
|
|
61
61
|
i.register(c);
|
|
62
62
|
}
|
|
63
|
-
const p =
|
|
63
|
+
const p = t.map((r) => Object.values(r));
|
|
64
64
|
function d(r) {
|
|
65
|
-
return
|
|
65
|
+
return t.map((n) => n[r], { skipVoid: !1 });
|
|
66
66
|
}
|
|
67
67
|
return {
|
|
68
68
|
register: g,
|
|
@@ -70,42 +70,42 @@ const X = v(({ client: t }) => {
|
|
|
70
70
|
listStore: p
|
|
71
71
|
};
|
|
72
72
|
});
|
|
73
|
-
function
|
|
74
|
-
return
|
|
73
|
+
function je(e) {
|
|
74
|
+
return v(Z, e);
|
|
75
75
|
}
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
const { targetSelectors: i } =
|
|
76
|
+
const Oe = (e, t) => {
|
|
77
|
+
t.register(e);
|
|
78
|
+
}, ee = (e, t) => {
|
|
79
|
+
const { targetSelectors: i } = t.configStore.getState(), g = C(i, t.id);
|
|
80
80
|
g.forEach(
|
|
81
|
-
({ elements: d }) => d.forEach((r) =>
|
|
82
|
-
),
|
|
83
|
-
|
|
81
|
+
({ elements: d }) => d.forEach((r) => H(r, t.id))
|
|
82
|
+
), q(g, t.id).forEach((d) => {
|
|
83
|
+
e.experienceInstances.spawn(t, d);
|
|
84
84
|
});
|
|
85
|
-
},
|
|
85
|
+
}, Me = async (e) => {
|
|
86
86
|
await Promise.all(
|
|
87
|
-
|
|
88
|
-
await
|
|
87
|
+
e.experiences.listStore.getState().map(async (t) => {
|
|
88
|
+
await te(e, t) && ee(e, t);
|
|
89
89
|
})
|
|
90
90
|
);
|
|
91
|
-
},
|
|
92
|
-
const { decisionLogic: i, targetSelectors: g } =
|
|
93
|
-
return
|
|
94
|
-
},
|
|
95
|
-
({ client:
|
|
96
|
-
const g =
|
|
91
|
+
}, te = async (e, t) => {
|
|
92
|
+
const { decisionLogic: i, targetSelectors: g } = t.configStore.getState();
|
|
93
|
+
return C(g, t.id).length < 1 || g.length === 0 ? !1 : i && z(i) ? await L(e, i) === !0 : !0;
|
|
94
|
+
}, re = h("component"), ne = k(
|
|
95
|
+
({ client: e, component: t, name: i }) => {
|
|
96
|
+
const g = e.frameworks.getByName(t.frameworkName);
|
|
97
97
|
return {
|
|
98
98
|
name: i,
|
|
99
|
-
component:
|
|
99
|
+
component: t,
|
|
100
100
|
frameworkStore: g
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
);
|
|
104
|
-
function
|
|
105
|
-
return
|
|
104
|
+
function se(e) {
|
|
105
|
+
return v(ne, e);
|
|
106
106
|
}
|
|
107
|
-
const
|
|
108
|
-
const
|
|
107
|
+
const oe = k(({ client: e }) => {
|
|
108
|
+
const t = re.store({}), i = b(t, {
|
|
109
109
|
register(r, n) {
|
|
110
110
|
return {
|
|
111
111
|
...r,
|
|
@@ -114,16 +114,16 @@ const se = v(({ client: t }) => {
|
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
116
|
function g(r, n) {
|
|
117
|
-
|
|
117
|
+
t.getState()[r] && E(
|
|
118
118
|
"warn",
|
|
119
119
|
`Component '${r}' already registered. Registering again will override the previous registration.`
|
|
120
120
|
);
|
|
121
|
-
const m =
|
|
121
|
+
const m = se({ client: e, name: r, component: n });
|
|
122
122
|
i.register(m);
|
|
123
123
|
}
|
|
124
|
-
const p =
|
|
124
|
+
const p = t.map((r) => Object.values(r));
|
|
125
125
|
function d(r) {
|
|
126
|
-
return
|
|
126
|
+
return t.map((n) => n[r], { skipVoid: !1 });
|
|
127
127
|
}
|
|
128
128
|
return {
|
|
129
129
|
register: g,
|
|
@@ -131,13 +131,13 @@ const se = v(({ client: t }) => {
|
|
|
131
131
|
listStore: p
|
|
132
132
|
};
|
|
133
133
|
});
|
|
134
|
-
function
|
|
135
|
-
return
|
|
134
|
+
function Pe(e) {
|
|
135
|
+
return v(oe, e);
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
i.register(
|
|
139
|
-
},
|
|
140
|
-
const
|
|
137
|
+
const Ve = (e, t, i) => {
|
|
138
|
+
i.register(e, t);
|
|
139
|
+
}, ie = h("framework"), ae = k(({ client: e }) => {
|
|
140
|
+
const t = ie.store({}), i = b(t, {
|
|
141
141
|
register(r, n) {
|
|
142
142
|
return {
|
|
143
143
|
...r,
|
|
@@ -146,14 +146,14 @@ const Pe = (t, e, i) => {
|
|
|
146
146
|
}
|
|
147
147
|
});
|
|
148
148
|
function g(r, n) {
|
|
149
|
-
|
|
149
|
+
t.getState()[r] && E(
|
|
150
150
|
"warn",
|
|
151
151
|
`Framework '${r}' already registered. Registering again will override the previous registration.`
|
|
152
152
|
), i.register({ name: r, framework: n });
|
|
153
153
|
}
|
|
154
|
-
const p =
|
|
154
|
+
const p = t.map((r) => Object.values(r));
|
|
155
155
|
function d(r) {
|
|
156
|
-
return
|
|
156
|
+
return t.map((n) => n[r], { skipVoid: !1 });
|
|
157
157
|
}
|
|
158
158
|
return {
|
|
159
159
|
register: g,
|
|
@@ -161,18 +161,18 @@ const Pe = (t, e, i) => {
|
|
|
161
161
|
listStore: p
|
|
162
162
|
};
|
|
163
163
|
});
|
|
164
|
-
function Te(
|
|
165
|
-
return
|
|
164
|
+
function Te(e) {
|
|
165
|
+
return v(ae, e);
|
|
166
166
|
}
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
},
|
|
167
|
+
const Ne = (e, t) => {
|
|
168
|
+
t.register(e.name, e);
|
|
169
|
+
}, ce = 6e3, P = R("last_ping", "global"), ue = (e) => `${e}/api/v1/ping`, Ce = async (e) => {
|
|
170
170
|
try {
|
|
171
|
-
const
|
|
172
|
-
if (i &&
|
|
171
|
+
const t = Date.now(), i = localStorage.getItem(P);
|
|
172
|
+
if (i && t - parseInt(i) < ce)
|
|
173
173
|
return !0;
|
|
174
|
-
const g =
|
|
175
|
-
projectId:
|
|
174
|
+
const g = ue(e.apiUrl), p = {
|
|
175
|
+
projectId: e.projectId,
|
|
176
176
|
path: window.location.pathname
|
|
177
177
|
}, d = JSON.stringify(p), r = {
|
|
178
178
|
"Content-Type": "application/json"
|
|
@@ -183,12 +183,12 @@ const Ve = (t, e) => {
|
|
|
183
183
|
headers: r,
|
|
184
184
|
body: d
|
|
185
185
|
})).ok;
|
|
186
|
-
return S && localStorage.setItem(P,
|
|
187
|
-
} catch (
|
|
188
|
-
return E("error",
|
|
186
|
+
return S && localStorage.setItem(P, t.toString()), S;
|
|
187
|
+
} catch (t) {
|
|
188
|
+
return E("error", t), !1;
|
|
189
189
|
}
|
|
190
|
-
},
|
|
191
|
-
const
|
|
190
|
+
}, le = h("predicate"), ge = k(({ client: e }) => {
|
|
191
|
+
const t = le.store({}), i = b(t, {
|
|
192
192
|
register(r, n) {
|
|
193
193
|
return {
|
|
194
194
|
...r,
|
|
@@ -200,14 +200,14 @@ const Ve = (t, e) => {
|
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
202
|
function g(r, n) {
|
|
203
|
-
|
|
203
|
+
t.getState()[r] && E(
|
|
204
204
|
"warn",
|
|
205
205
|
`Predicate '${r}' already registered. Registering again will override the previous registration.`
|
|
206
206
|
), i.register(Object.freeze({ name: r, predicate: n }));
|
|
207
207
|
}
|
|
208
|
-
const p =
|
|
208
|
+
const p = t.map((r) => Object.values(r));
|
|
209
209
|
function d(r) {
|
|
210
|
-
return
|
|
210
|
+
return t.map((n) => n[r], { skipVoid: !1 });
|
|
211
211
|
}
|
|
212
212
|
return {
|
|
213
213
|
register: g,
|
|
@@ -215,13 +215,13 @@ const Ve = (t, e) => {
|
|
|
215
215
|
listStore: p
|
|
216
216
|
};
|
|
217
217
|
});
|
|
218
|
-
function
|
|
219
|
-
return
|
|
218
|
+
function Le(e) {
|
|
219
|
+
return v(ge, e);
|
|
220
220
|
}
|
|
221
|
-
const
|
|
222
|
-
i.register(
|
|
223
|
-
},
|
|
224
|
-
const
|
|
221
|
+
const _e = (e, t, i) => {
|
|
222
|
+
i.register(e, t);
|
|
223
|
+
}, V = h("feature"), de = k(({ client: e }) => {
|
|
224
|
+
const t = V.store({}), i = V.store([]), g = b(t, {
|
|
225
225
|
register(a, o) {
|
|
226
226
|
return {
|
|
227
227
|
...a,
|
|
@@ -230,11 +230,11 @@ const Le = (t, e, i) => {
|
|
|
230
230
|
}
|
|
231
231
|
});
|
|
232
232
|
function p(a, o) {
|
|
233
|
-
|
|
233
|
+
t.getState()[a] && E(
|
|
234
234
|
"warn",
|
|
235
235
|
`Feature '${a}' already registered. Registering again will override the previous registration.`
|
|
236
236
|
);
|
|
237
|
-
const
|
|
237
|
+
const u = {
|
|
238
238
|
id: a,
|
|
239
239
|
feature: {
|
|
240
240
|
...o,
|
|
@@ -244,7 +244,7 @@ const Le = (t, e, i) => {
|
|
|
244
244
|
g.register(
|
|
245
245
|
Object.freeze({
|
|
246
246
|
id: a,
|
|
247
|
-
feature:
|
|
247
|
+
feature: u
|
|
248
248
|
})
|
|
249
249
|
);
|
|
250
250
|
}
|
|
@@ -254,29 +254,29 @@ const Le = (t, e, i) => {
|
|
|
254
254
|
key: o,
|
|
255
255
|
storage: s = "local"
|
|
256
256
|
}) => {
|
|
257
|
-
const
|
|
258
|
-
return
|
|
257
|
+
const u = R(`feature:${a}:${o}`, "global"), l = (s === "session" ? M : A).get(u).boolean();
|
|
258
|
+
return l === null ? null : { id: a, key: o, bucket: l };
|
|
259
259
|
}
|
|
260
260
|
), r = j((a) => {
|
|
261
261
|
if (!a)
|
|
262
262
|
return null;
|
|
263
|
-
const o =
|
|
263
|
+
const o = R(`feature:${a.id}:${a.key}`, "global");
|
|
264
264
|
(a.storage === "session" ? M : A).set(o, a.bucket);
|
|
265
|
-
}), n = /* @__PURE__ */ new Map(), c =
|
|
266
|
-
source: { allFeaturesStore:
|
|
267
|
-
effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: o }, { id: s, decide:
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
return
|
|
265
|
+
}), n = /* @__PURE__ */ new Map(), c = U({
|
|
266
|
+
source: { allFeaturesStore: t, resolvedFeaturesStore: i },
|
|
267
|
+
effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: o }, { id: s, decide: u, key: f }) => {
|
|
268
|
+
const l = o.find((D) => D.id === s);
|
|
269
|
+
if (l)
|
|
270
|
+
return l;
|
|
271
271
|
const y = a[s];
|
|
272
272
|
if (!y)
|
|
273
273
|
throw new Error(`Feature with id '${s}' not found`);
|
|
274
274
|
const w = n.get(`${s}:${f}`);
|
|
275
275
|
if (w !== void 0) {
|
|
276
|
-
const
|
|
277
|
-
return { id: y.id, bucket:
|
|
276
|
+
const D = await w;
|
|
277
|
+
return { id: y.id, bucket: D, key: f, storage: y.feature.storage };
|
|
278
278
|
}
|
|
279
|
-
const $ =
|
|
279
|
+
const $ = u();
|
|
280
280
|
n.set(`${s}:${f}`, $);
|
|
281
281
|
const F = await $;
|
|
282
282
|
return { id: y.id, bucket: F, key: f, storage: y.feature.storage };
|
|
@@ -290,26 +290,26 @@ const Le = (t, e, i) => {
|
|
|
290
290
|
},
|
|
291
291
|
target: d
|
|
292
292
|
}), x({
|
|
293
|
-
source:
|
|
293
|
+
source: t,
|
|
294
294
|
clock: c.doneData,
|
|
295
295
|
fn: (a, o) => {
|
|
296
296
|
var y;
|
|
297
|
-
const { id: s, bucket:
|
|
298
|
-
return
|
|
297
|
+
const { id: s, bucket: u, storage: f } = o, l = (y = a[s]) == null ? void 0 : y.feature.key;
|
|
298
|
+
return l ? { key: l, id: s, bucket: u, storage: f } : null;
|
|
299
299
|
},
|
|
300
300
|
target: r
|
|
301
301
|
});
|
|
302
|
-
const m = B({ allFeaturesStore:
|
|
302
|
+
const m = B({ allFeaturesStore: t, resolvedFeaturesStore: i }).map(
|
|
303
303
|
({
|
|
304
304
|
allFeaturesStore: a,
|
|
305
305
|
resolvedFeaturesStore: o
|
|
306
306
|
}) => Object.values(a).map((s) => {
|
|
307
|
-
const
|
|
308
|
-
return
|
|
307
|
+
const u = o.find((f) => f.id === s.id);
|
|
308
|
+
return u ? {
|
|
309
309
|
id: s.id,
|
|
310
310
|
name: s.feature.name,
|
|
311
311
|
key: s.feature.key,
|
|
312
|
-
getBucket: () => ({ id: s.id, bucket:
|
|
312
|
+
getBucket: () => ({ id: s.id, bucket: u.bucket }),
|
|
313
313
|
isResolved: !0
|
|
314
314
|
} : {
|
|
315
315
|
id: s.id,
|
|
@@ -325,7 +325,7 @@ const Le = (t, e, i) => {
|
|
|
325
325
|
source: { resolvedFeatures: i },
|
|
326
326
|
filter: ({ resolvedFeatures: a }, { id: o }) => !a.some((s) => s.id === o),
|
|
327
327
|
fn: (a, o) => o,
|
|
328
|
-
target:
|
|
328
|
+
target: e.eventBus.prepend((a) => ({
|
|
329
329
|
type: "feature_decide",
|
|
330
330
|
feature: a
|
|
331
331
|
}))
|
|
@@ -336,7 +336,7 @@ const Le = (t, e, i) => {
|
|
|
336
336
|
target: i
|
|
337
337
|
});
|
|
338
338
|
function S(a) {
|
|
339
|
-
return
|
|
339
|
+
return t.map((o) => o[a], { skipVoid: !1 });
|
|
340
340
|
}
|
|
341
341
|
return {
|
|
342
342
|
register: p,
|
|
@@ -344,36 +344,36 @@ const Le = (t, e, i) => {
|
|
|
344
344
|
listStore: m
|
|
345
345
|
};
|
|
346
346
|
});
|
|
347
|
-
function
|
|
348
|
-
return
|
|
347
|
+
function Ue(e) {
|
|
348
|
+
return v(de, e);
|
|
349
349
|
}
|
|
350
|
-
const
|
|
351
|
-
i.register(
|
|
350
|
+
const He = (e, t, i) => {
|
|
351
|
+
i.register(e, t);
|
|
352
352
|
}, I = h("history");
|
|
353
|
-
function
|
|
353
|
+
function T(e, t) {
|
|
354
354
|
return {
|
|
355
355
|
// eslint-disable-next-line sonarjs/pseudo-random
|
|
356
|
-
id:
|
|
357
|
-
node:
|
|
356
|
+
id: K(`history-entry-${Date.now()}-${Math.random()}}`),
|
|
357
|
+
node: t,
|
|
358
358
|
at: Date.now(),
|
|
359
|
-
experienceId:
|
|
359
|
+
experienceId: e
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
entries: [...r.entries,
|
|
366
|
-
})),
|
|
362
|
+
const pe = k(() => {
|
|
363
|
+
const e = I.store({ entries: [] }), t = I.event(), i = I.event(), g = I.event(), p = I.event();
|
|
364
|
+
e.on(t, (r, n) => ({
|
|
365
|
+
entries: [...r.entries, T(n.experienceId, n.node)]
|
|
366
|
+
})), e.on(i, (r, n) => ({
|
|
367
367
|
entries: [
|
|
368
368
|
...r.entries.slice(0, -1),
|
|
369
|
-
|
|
369
|
+
T(n.experienceId, n.node)
|
|
370
370
|
]
|
|
371
|
-
})),
|
|
371
|
+
})), e.on(p, (r, n) => n);
|
|
372
372
|
function d(r, n) {
|
|
373
373
|
const c = { lastStepIndex: -1, secondLastStepIndex: -1 };
|
|
374
374
|
for (let m = r.length - 1; m >= 0; m--) {
|
|
375
375
|
const S = r[m], a = S == null ? void 0 : S.node;
|
|
376
|
-
if (!(!a || !
|
|
376
|
+
if (!(!a || !G(a)) && !(n && (S == null ? void 0 : S.experienceId) !== n))
|
|
377
377
|
if (c.lastStepIndex === -1)
|
|
378
378
|
c.lastStepIndex = m;
|
|
379
379
|
else {
|
|
@@ -383,25 +383,25 @@ const de = v(() => {
|
|
|
383
383
|
}
|
|
384
384
|
return c;
|
|
385
385
|
}
|
|
386
|
-
return
|
|
386
|
+
return e.on(g, (r, n) => {
|
|
387
387
|
const { secondLastStepIndex: c } = d(r.entries, n.experienceId), m = c !== -1 ? r.entries.slice(0, c + 1) : r.entries;
|
|
388
388
|
return {
|
|
389
389
|
...r,
|
|
390
390
|
entries: m
|
|
391
391
|
};
|
|
392
392
|
}), {
|
|
393
|
-
push:
|
|
393
|
+
push: t,
|
|
394
394
|
replace: i,
|
|
395
395
|
back: g,
|
|
396
396
|
restore: p,
|
|
397
|
-
entriesStore:
|
|
397
|
+
entriesStore: e.map((r) => r.entries)
|
|
398
398
|
};
|
|
399
399
|
});
|
|
400
|
-
function
|
|
401
|
-
return
|
|
400
|
+
function qe() {
|
|
401
|
+
return v(pe);
|
|
402
402
|
}
|
|
403
|
-
const
|
|
404
|
-
const
|
|
403
|
+
const fe = h("field"), me = k(() => {
|
|
404
|
+
const e = fe.store({}), t = b(e, {
|
|
405
405
|
register(r, n) {
|
|
406
406
|
return {
|
|
407
407
|
...r,
|
|
@@ -410,14 +410,14 @@ const pe = h("field"), fe = v(() => {
|
|
|
410
410
|
}
|
|
411
411
|
});
|
|
412
412
|
function i(r) {
|
|
413
|
-
|
|
413
|
+
t.register({ field: r });
|
|
414
414
|
}
|
|
415
|
-
const g =
|
|
415
|
+
const g = e.map((r) => Object.values(r));
|
|
416
416
|
function p(r) {
|
|
417
|
-
return
|
|
417
|
+
return e.map((n) => n[r] || null);
|
|
418
418
|
}
|
|
419
419
|
function d(r) {
|
|
420
|
-
return
|
|
420
|
+
return e.map((n) => Object.values(n).find((c) => c.name === r) || null);
|
|
421
421
|
}
|
|
422
422
|
return {
|
|
423
423
|
register: i,
|
|
@@ -426,13 +426,13 @@ const pe = h("field"), fe = v(() => {
|
|
|
426
426
|
getByName: d
|
|
427
427
|
};
|
|
428
428
|
});
|
|
429
|
-
function
|
|
430
|
-
return
|
|
429
|
+
function ze() {
|
|
430
|
+
return v(me);
|
|
431
431
|
}
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
},
|
|
435
|
-
const
|
|
432
|
+
const Ge = (e, t) => {
|
|
433
|
+
t.register(e);
|
|
434
|
+
}, ye = h("action"), Se = k(() => {
|
|
435
|
+
const e = ye.store({}), t = b(e, {
|
|
436
436
|
register(d, r) {
|
|
437
437
|
return {
|
|
438
438
|
...d,
|
|
@@ -444,11 +444,11 @@ const ze = (t, e) => {
|
|
|
444
444
|
}
|
|
445
445
|
});
|
|
446
446
|
function i(d, r) {
|
|
447
|
-
|
|
447
|
+
t.register({ name: d, action: r });
|
|
448
448
|
}
|
|
449
|
-
const g =
|
|
449
|
+
const g = e.map((d) => Object.values(d));
|
|
450
450
|
function p(d) {
|
|
451
|
-
return
|
|
451
|
+
return e.map((r) => r[d], { skipVoid: !1 });
|
|
452
452
|
}
|
|
453
453
|
return {
|
|
454
454
|
register: i,
|
|
@@ -456,13 +456,17 @@ const ze = (t, e) => {
|
|
|
456
456
|
listStore: g
|
|
457
457
|
};
|
|
458
458
|
});
|
|
459
|
-
function
|
|
460
|
-
return
|
|
459
|
+
function Ke() {
|
|
460
|
+
return v(Se);
|
|
461
|
+
}
|
|
462
|
+
const Ye = (e, t, i) => {
|
|
463
|
+
i.register(e, t);
|
|
464
|
+
};
|
|
465
|
+
function N(e) {
|
|
466
|
+
return typeof e > "u" || e === null || e === "" || Array.isArray(e) && !e.length;
|
|
461
467
|
}
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
}, Se = h("response"), ve = v(({ client: t }) => {
|
|
465
|
-
const e = Se.store({}), i = O(), g = O(), p = b(e, {
|
|
468
|
+
const ke = h("response"), ve = k(({ client: e }) => {
|
|
469
|
+
const t = ke.store({}), i = O(), g = O(), p = b(t, {
|
|
466
470
|
register(o, s) {
|
|
467
471
|
return {
|
|
468
472
|
...o,
|
|
@@ -476,7 +480,7 @@ const Ke = (t, e, i) => {
|
|
|
476
480
|
};
|
|
477
481
|
},
|
|
478
482
|
clear(o, s) {
|
|
479
|
-
const { [s]:
|
|
483
|
+
const { [s]: u, ...f } = o;
|
|
480
484
|
return f;
|
|
481
485
|
},
|
|
482
486
|
clearAll() {
|
|
@@ -489,88 +493,88 @@ const Ke = (t, e, i) => {
|
|
|
489
493
|
async function r(o) {
|
|
490
494
|
const s = [];
|
|
491
495
|
return await Promise.allSettled(
|
|
492
|
-
Object.entries(o).map(async ([
|
|
493
|
-
let
|
|
494
|
-
const y =
|
|
496
|
+
Object.entries(o).map(async ([u, f]) => {
|
|
497
|
+
let l = f;
|
|
498
|
+
const y = e.fields.getById(u).getState();
|
|
495
499
|
if (!y) {
|
|
496
500
|
s.push({
|
|
497
|
-
fieldId:
|
|
498
|
-
userMessage: `Field '${
|
|
499
|
-
systemMessage: `No field with ID '${
|
|
500
|
-
value:
|
|
501
|
+
fieldId: u,
|
|
502
|
+
userMessage: `Field '${u}' not found`,
|
|
503
|
+
systemMessage: `No field with ID '${u}' exists. Available field IDs are: ${Object.keys(e.fields.listStore.getState()).join(",")}.`,
|
|
504
|
+
value: l
|
|
501
505
|
});
|
|
502
506
|
return;
|
|
503
507
|
}
|
|
504
|
-
if (y.multiple && (typeof
|
|
505
|
-
const w = await
|
|
506
|
-
$input:
|
|
508
|
+
if (y.multiple && (typeof l == "string" || typeof l == "number" || typeof l == "boolean") && (l = [l]), y.validation && !Y(y.validation) && !N(l)) {
|
|
509
|
+
const w = await L(e, y.validation, {
|
|
510
|
+
$input: l
|
|
507
511
|
});
|
|
508
512
|
if (typeof w == "string") {
|
|
509
513
|
s.push({
|
|
510
|
-
fieldId:
|
|
514
|
+
fieldId: u,
|
|
511
515
|
userMessage: w,
|
|
512
516
|
systemMessage: `Field validation resulted in an error: ${w}.`,
|
|
513
|
-
value:
|
|
517
|
+
value: l
|
|
514
518
|
});
|
|
515
519
|
return;
|
|
516
520
|
}
|
|
517
521
|
if (w === !1) {
|
|
518
522
|
s.push({
|
|
519
|
-
fieldId:
|
|
523
|
+
fieldId: u,
|
|
520
524
|
userMessage: "This field is invalid",
|
|
521
525
|
systemMessage: "Field validation resulted in an unspecified error.",
|
|
522
|
-
value:
|
|
526
|
+
value: l
|
|
523
527
|
});
|
|
524
528
|
return;
|
|
525
529
|
}
|
|
526
530
|
}
|
|
527
|
-
if (y.required && (
|
|
531
|
+
if (y.required && N(l)) {
|
|
528
532
|
s.push({
|
|
529
|
-
fieldId:
|
|
533
|
+
fieldId: u,
|
|
530
534
|
userMessage: "This field is required",
|
|
531
535
|
systemMessage: "Field is required.",
|
|
532
|
-
value:
|
|
536
|
+
value: l
|
|
533
537
|
});
|
|
534
538
|
return;
|
|
535
539
|
}
|
|
536
|
-
if (!y.multiple && Array.isArray(
|
|
540
|
+
if (!y.multiple && Array.isArray(l) && l.length > 1) {
|
|
537
541
|
s.push({
|
|
538
|
-
fieldId:
|
|
542
|
+
fieldId: u,
|
|
539
543
|
userMessage: "This field expects a single response",
|
|
540
544
|
systemMessage: "Field expects a single response.",
|
|
541
|
-
value:
|
|
545
|
+
value: l
|
|
542
546
|
});
|
|
543
547
|
return;
|
|
544
548
|
}
|
|
545
549
|
if (y.options) {
|
|
546
|
-
const w = y.options.map((F) => F.value), $ = Array.isArray(
|
|
547
|
-
Array.isArray(
|
|
548
|
-
fieldId:
|
|
550
|
+
const w = y.options.map((F) => F.value), $ = Array.isArray(l) ? l : [l];
|
|
551
|
+
Array.isArray(l) && ($.every((F) => w.includes(F)) || s.push({
|
|
552
|
+
fieldId: u,
|
|
549
553
|
userMessage: "This field expects a valid option",
|
|
550
554
|
systemMessage: `Field expects a valid option. Valid options are: ${w.join(", ")}`,
|
|
551
|
-
value:
|
|
555
|
+
value: l
|
|
552
556
|
}));
|
|
553
557
|
}
|
|
554
558
|
})
|
|
555
559
|
), { responsesToCommit: o, validationErrors: s };
|
|
556
560
|
}
|
|
557
561
|
async function n(o) {
|
|
558
|
-
const { responsesToCommit: s, validationErrors:
|
|
559
|
-
return
|
|
562
|
+
const { responsesToCommit: s, validationErrors: u } = await r(o);
|
|
563
|
+
return u.length ? { errors: u } : (p.registerBatch(s), { errors: [] });
|
|
560
564
|
}
|
|
561
|
-
const c =
|
|
562
|
-
fieldId:
|
|
563
|
-
value: o[
|
|
565
|
+
const c = t.map((o) => o), m = t.map((o) => Object.keys(o).map((u) => ({
|
|
566
|
+
fieldId: u,
|
|
567
|
+
value: o[u]
|
|
564
568
|
})));
|
|
565
569
|
function S(o) {
|
|
566
|
-
const s =
|
|
567
|
-
return B({ f: s, r:
|
|
570
|
+
const s = e.fields.getById(o), u = t.map((f) => f[o] || null);
|
|
571
|
+
return B({ f: s, r: u }, ({ f, r: l }) => l || (f != null && f.defaultValue ? f.defaultValue : null));
|
|
568
572
|
}
|
|
569
573
|
function a(o) {
|
|
570
|
-
const s =
|
|
571
|
-
return B({ f: s, s:
|
|
572
|
-
const
|
|
573
|
-
return
|
|
574
|
+
const s = e.fields.getByName(o);
|
|
575
|
+
return B({ f: s, s: t }, ({ f: u, s: f }) => {
|
|
576
|
+
const l = u && f[u.id] || null;
|
|
577
|
+
return l || (u != null && u.defaultValue ? u.defaultValue : null);
|
|
574
578
|
});
|
|
575
579
|
}
|
|
576
580
|
return x({
|
|
@@ -591,42 +595,42 @@ const Ke = (t, e, i) => {
|
|
|
591
595
|
getByFieldName: a
|
|
592
596
|
};
|
|
593
597
|
});
|
|
594
|
-
function
|
|
595
|
-
return
|
|
598
|
+
function Je(e) {
|
|
599
|
+
return v(ve, e);
|
|
596
600
|
}
|
|
597
|
-
function
|
|
598
|
-
if (
|
|
601
|
+
function we() {
|
|
602
|
+
if (Q())
|
|
599
603
|
return crypto.randomUUID();
|
|
600
|
-
const
|
|
601
|
-
return `${
|
|
604
|
+
const e = Date.now().toString(36), t = Math.random().toString(36).substring(2, 15), i = Math.random().toString(36).substring(2, 15), g = Math.random().toString(36).substring(2, 15);
|
|
605
|
+
return `${e}-${t}-${i}-${g}`;
|
|
602
606
|
}
|
|
603
|
-
const
|
|
604
|
-
id:
|
|
605
|
-
}),
|
|
606
|
-
if (!
|
|
607
|
-
const
|
|
608
|
-
let
|
|
609
|
-
return
|
|
610
|
-
},
|
|
607
|
+
const he = () => ({
|
|
608
|
+
id: we()
|
|
609
|
+
}), be = R("session", "global"), xe = () => {
|
|
610
|
+
if (!J()) return null;
|
|
611
|
+
const e = A.get(be);
|
|
612
|
+
let t = e.isSet() ? e.json() : null;
|
|
613
|
+
return t || (t = he(), e.set(t)), t;
|
|
614
|
+
}, Qe = () => xe();
|
|
611
615
|
export {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
616
|
+
Pe as a,
|
|
617
|
+
je as b,
|
|
618
|
+
qe as c,
|
|
615
619
|
Te as d,
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
620
|
+
Le as e,
|
|
621
|
+
Ue as f,
|
|
622
|
+
Je as g,
|
|
623
|
+
ze as h,
|
|
624
|
+
Ke as i,
|
|
625
|
+
Qe as j,
|
|
626
|
+
Ve as k,
|
|
627
|
+
He as l,
|
|
628
|
+
_e as m,
|
|
629
|
+
Ge as n,
|
|
630
|
+
Ye as o,
|
|
631
|
+
Ce as p,
|
|
632
|
+
Oe as q,
|
|
633
|
+
ee as r,
|
|
634
|
+
Ne as s,
|
|
635
|
+
Me as t
|
|
632
636
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const p=require("effector"),y=require("@withease/factories"),w=require("./experience-instance-B2l_MG7I.cjs"),b=require("./logger-BsmHUUw1.cjs"),x=require("./storage-DuRlyFaY.cjs"),M=require("./id-BKIWbSTy.cjs"),T=require("./object-BbFTsGh3.cjs"),j=require("./supports-YvpQZxbh.cjs"),O=p.createDomain("experience"),V=y.createFactory(({client:e,experience:t})=>{const i=O.store(t),g=p.createApi(i,{merge(c,S){return{...c,...S.experience}}}),m=i.map(c=>({name:c.name,decisionLogic:c.decide,targetSelectors:c.targets,initializeOpenLogic:t.initializeOpen})),d=e.components.listStore.map(c=>c.find(S=>S.name===`experience:${t.id}`)||c.find(S=>S.name==="experience"),{skipVoid:!1}),r=i.map(c=>({steps:c.steps,nodes:c.nodes,edges:c.edges,conditionals:c.conditionals})),n=t.actions??[];return{id:t.id,configStore:m,treeStore:r,componentStore:d,actions:n,merge:g.merge}});function N(e){return y.invoke(V,e)}const C=y.createFactory(({client:e})=>{const t=O.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.id]:n}}});function g(r){const n=t.getState()[r.id];if(n){n.merge({experience:r,strategy:"override"});return}const c=N({client:e,experience:r});i.register(c)}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getById:d,listStore:m}});function L(e){return y.invoke(C,e)}const q=(e,t)=>{t.register(e)},P=(e,t)=>{const{targetSelectors:i}=t.configStore.getState(),g=w.getTargetElements(i,t.id);g.forEach(({elements:d})=>d.forEach(r=>w.tagTargetElement(r,t.id))),w.createAppHosts(g,t.id).forEach(d=>{e.experienceInstances.spawn(t,d)})},_=async e=>{await Promise.all(e.experiences.listStore.getState().map(async t=>{await U(e,t)&&P(e,t)}))},U=async(e,t)=>{const{decisionLogic:i,targetSelectors:g}=t.configStore.getState();return w.getTargetElements(g,t.id).length<1||g.length===0?!1:i&&w.isRulesLogic(i)?await w.evaluateRuleLogic(e,i)===!0:!0},H=p.createDomain("component"),K=y.createFactory(({client:e,component:t,name:i})=>{const g=e.frameworks.getByName(t.frameworkName);return{name:i,component:t,frameworkStore:g}});function z(e){return y.invoke(K,e)}const G=y.createFactory(({client:e})=>{const t=H.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.name]:n}}});function g(r,n){t.getState()[r]&&b.logger("warn",`Component '${r}' already registered. Registering again will override the previous registration.`);const S=z({client:e,name:r,component:n});i.register(S)}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function Y(e){return y.invoke(G,e)}const J=(e,t,i)=>{i.register(e,t)},Q=p.createDomain("framework"),W=y.createFactory(({client:e})=>{const t=Q.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.name]:n.framework}}});function g(r,n){t.getState()[r]&&b.logger("warn",`Framework '${r}' already registered. Registering again will override the previous registration.`),i.register({name:r,framework:n})}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function X(e){return y.invoke(W,e)}const Z=(e,t)=>{t.register(e.name,e)},ee=6e3,D=x.createStorageKey("last_ping","global"),te=e=>`${e}/api/v1/ping`,re=async e=>{try{const t=Date.now(),i=localStorage.getItem(D);if(i&&t-parseInt(i)<ee)return!0;const g=te(e.apiUrl),m={projectId:e.projectId,path:window.location.pathname},d=JSON.stringify(m),r={"Content-Type":"application/json"},n=document.getElementById("picked_script"),c=n==null?void 0:n.dataset.verceltoken;c&&(r["x-vercel-protection-bypass"]=c);const v=(await fetch(g,{method:"POST",headers:r,body:d})).ok;return v&&localStorage.setItem(D,t.toString()),v}catch(t){return b.logger("error",t),!1}},ne=p.createDomain("predicate"),se=y.createFactory(({client:e})=>{const t=ne.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.name]:{name:n.name,predicate:n.predicate}}}});function g(r,n){t.getState()[r]&&b.logger("warn",`Predicate '${r}' already registered. Registering again will override the previous registration.`),i.register(Object.freeze({name:r,predicate:n}))}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function oe(e){return y.invoke(se,e)}const ie=(e,t,i)=>{i.register(e,t)},$=p.createDomain("feature"),ae=y.createFactory(({client:e})=>{const t=$.store({}),i=$.store([]),g=p.createApi(t,{register(a,o){return{...a,[o.id]:o.feature}}});function m(a,o){t.getState()[a]&&b.logger("warn",`Feature '${a}' already registered. Registering again will override the previous registration.`);const u={id:a,feature:{...o,id:a}};g.register(Object.freeze({id:a,feature:u}))}const d=p.createEffect(async({id:a,key:o,storage:s="local"})=>{const u=x.createStorageKey(`feature:${a}:${o}`,"global"),l=(s==="session"?x.sessionStore:x.localStore).get(u).boolean();return l===null?null:{id:a,key:o,bucket:l}}),r=p.createEffect(a=>{if(!a)return null;const o=x.createStorageKey(`feature:${a.id}:${a.key}`,"global");(a.storage==="session"?x.sessionStore:x.localStore).set(o,a.bucket)}),n=new Map,c=p.attach({source:{allFeaturesStore:t,resolvedFeaturesStore:i},effect:async({allFeaturesStore:a,resolvedFeaturesStore:o},{id:s,decide:u,key:f})=>{const l=o.find(A=>A.id===s);if(l)return l;const k=a[s];if(!k)throw new Error(`Feature with id '${s}' not found`);const F=n.get(`${s}:${f}`);if(F!==void 0){const A=await F;return{id:k.id,bucket:A,key:f,storage:k.feature.storage}}const E=u();n.set(`${s}:${f}`,E);const I=await E;return{id:k.id,bucket:I,key:f,storage:k.feature.storage}}});p.sample({clock:g.register,fn:a=>{const{id:o,feature:s}=a;return{id:o,key:s.feature.key,storage:s.feature.storage}},target:d}),p.sample({source:t,clock:c.doneData,fn:(a,o)=>{var k;const{id:s,bucket:u,storage:f}=o,l=(k=a[s])==null?void 0:k.feature.key;return l?{key:l,id:s,bucket:u,storage:f}:null},target:r});const S=p.combine({allFeaturesStore:t,resolvedFeaturesStore:i}).map(({allFeaturesStore:a,resolvedFeaturesStore:o})=>Object.values(a).map(s=>{const u=o.find(f=>f.id===s.id);return u?{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:()=>({id:s.id,bucket:u.bucket}),isResolved:!0}:{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:async()=>await c(s.feature),isResolved:!1}}));p.sample({clock:c.doneData,source:{resolvedFeatures:i},filter:({resolvedFeatures:a},{id:o})=>!a.some(s=>s.id===o),fn:(a,o)=>o,target:e.eventBus.prepend(a=>({type:"feature_decide",feature:a}))}),p.sample({clock:[d.doneData,c.doneData],source:i,fn:(a,o)=>!o||a.some(s=>s.id===o.id)?a:[...a,o],target:i});function v(a){return t.map(o=>o[a],{skipVoid:!1})}return{register:m,getByName:v,listStore:S}});function ce(e){return y.invoke(ae,e)}const ue=(e,t,i)=>{i.register(e,t)},h=p.createDomain("history");function R(e,t){return{id:M.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:t,at:Date.now(),experienceId:e}}const le=y.createFactory(()=>{const e=h.store({entries:[]}),t=h.event(),i=h.event(),g=h.event(),m=h.event();e.on(t,(r,n)=>({entries:[...r.entries,R(n.experienceId,n.node)]})),e.on(i,(r,n)=>({entries:[...r.entries.slice(0,-1),R(n.experienceId,n.node)]})),e.on(m,(r,n)=>n);function d(r,n){const c={lastStepIndex:-1,secondLastStepIndex:-1};for(let S=r.length-1;S>=0;S--){const v=r[S],a=v==null?void 0:v.node;if(!(!a||!w.isStepNode(a))&&!(n&&(v==null?void 0:v.experienceId)!==n))if(c.lastStepIndex===-1)c.lastStepIndex=S;else{c.secondLastStepIndex=S;break}}return c}return e.on(g,(r,n)=>{const{secondLastStepIndex:c}=d(r.entries,n.experienceId),S=c!==-1?r.entries.slice(0,c+1):r.entries;return{...r,entries:S}}),{push:t,replace:i,back:g,restore:m,entriesStore:e.map(r=>r.entries)}});function ge(){return y.invoke(le)}const de=p.createDomain("field"),pe=y.createFactory(()=>{const e=de.store({}),t=p.createApi(e,{register(r,n){return{...r,[n.field.id]:n.field}}});function i(r){t.register({field:r})}const g=e.map(r=>Object.values(r));function m(r){return e.map(n=>n[r]||null)}function d(r){return e.map(n=>Object.values(n).find(c=>c.name===r)||null)}return{register:i,getById:m,listStore:g,getByName:d}});function me(){return y.invoke(pe)}const fe=(e,t)=>{t.register(e)},ye=p.createDomain("action"),Se=y.createFactory(()=>{const e=ye.store({}),t=p.createApi(e,{register(d,r){return{...d,[r.name]:{name:r.name,action:r.action}}}});function i(d,r){t.register({name:d,action:r})}const g=e.map(d=>Object.values(d));function m(d){return e.map(r=>r[d],{skipVoid:!1})}return{register:i,getByName:m,listStore:g}});function ke(){return y.invoke(Se)}const ve=(e,t,i)=>{i.register(e,t)};function B(e){return typeof e>"u"||e===null||e===""||Array.isArray(e)&&!e.length}const Fe=p.createDomain("response"),xe=y.createFactory(({client:e})=>{const t=Fe.store({}),i=p.createEvent(),g=p.createEvent(),m=p.createApi(t,{register(o,s){return{...o,[s.fieldId]:s.response}},registerBatch(o,s){return{...o,...s}},clear(o,s){const{[s]:u,...f}=o;return f},clearAll(){return{}}});function d(o,s){m.register({fieldId:o,response:s})}async function r(o){const s=[];return await Promise.allSettled(Object.entries(o).map(async([u,f])=>{let l=f;const k=e.fields.getById(u).getState();if(!k){s.push({fieldId:u,userMessage:`Field '${u}' not found`,systemMessage:`No field with ID '${u}' exists. Available field IDs are: ${Object.keys(e.fields.listStore.getState()).join(",")}.`,value:l});return}if(k.multiple&&(typeof l=="string"||typeof l=="number"||typeof l=="boolean")&&(l=[l]),k.validation&&!T.isEmpty(k.validation)&&!B(l)){const F=await w.evaluateRuleLogic(e,k.validation,{$input:l});if(typeof F=="string"){s.push({fieldId:u,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:l});return}if(F===!1){s.push({fieldId:u,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:l});return}}if(k.required&&B(l)){s.push({fieldId:u,userMessage:"This field is required",systemMessage:"Field is required.",value:l});return}if(!k.multiple&&Array.isArray(l)&&l.length>1){s.push({fieldId:u,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:l});return}if(k.options){const F=k.options.map(I=>I.value),E=Array.isArray(l)?l:[l];Array.isArray(l)&&(E.every(I=>F.includes(I))||s.push({fieldId:u,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.join(", ")}`,value:l}))}})),{responsesToCommit:o,validationErrors:s}}async function n(o){const{responsesToCommit:s,validationErrors:u}=await r(o);return u.length?{errors:u}:(m.registerBatch(s),{errors:[]})}const c=t.map(o=>o),S=t.map(o=>Object.keys(o).map(u=>({fieldId:u,value:o[u]})));function v(o){const s=e.fields.getById(o),u=t.map(f=>f[o]||null);return p.combine({f:s,r:u},({f,r:l})=>l||(f!=null&&f.defaultValue?f.defaultValue:null))}function a(o){const s=e.fields.getByName(o);return p.combine({f:s,s:t},({f:u,s:f})=>{const l=u&&f[u.id]||null;return l||(u!=null&&u.defaultValue?u.defaultValue:null)})}return p.sample({clock:i,target:m.clearAll}),p.sample({clock:g,target:m.clear}),{register:d,clearAll:i,clear:g,commit:n,getResponsesToCommit:r,listStore:S,getAllStore:c,getByFieldId:v,getByFieldName:a}});function we(e){return y.invoke(xe,e)}function Ie(){if(j.supportsCryptoRandomUUID())return crypto.randomUUID();const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,15),i=Math.random().toString(36).substring(2,15),g=Math.random().toString(36).substring(2,15);return`${e}-${t}-${i}-${g}`}const he=()=>({id:Ie()}),be=x.createStorageKey("session","global"),Ee=()=>{if(!j.supportsLocalStorage())return null;const e=x.localStore.get(be);let t=e.isSet()?e.json():null;return t||(t=he(),e.set(t)),t},Ae=()=>Ee();exports.createActionIndex=ke;exports.createComponentIndex=Y;exports.createExperienceIndex=L;exports.createFeatureIndex=ce;exports.createFieldIndex=me;exports.createFrameworkIndex=X;exports.createHistory=ge;exports.createPredicateIndex=oe;exports.createResponseIndex=we;exports.initialiseExperience=P;exports.initialiseExperiences=_;exports.initialiseSession=Ae;exports.ping=re;exports.setupAction=ve;exports.setupComponent=J;exports.setupExperience=q;exports.setupFeature=ue;exports.setupField=fe;exports.setupFramework=Z;exports.setupPredicate=ie;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const p=require("effector"),y=require("@withease/factories"),w=require("./experience-instance-B2l_MG7I.cjs"),b=require("./logger-BsmHUUw1.cjs"),x=require("./storage-DuRlyFaY.cjs"),P=require("./id-BKIWbSTy.cjs"),M=require("./object-BbFTsGh3.cjs"),B=require("./supports-YvpQZxbh.cjs"),j=p.createDomain("experience"),T=y.createFactory(({client:t,experience:e})=>{const i=j.store(e),g=p.createApi(i,{merge(c,S){return{...c,...S.experience}}}),m=i.map(c=>({name:c.name,decisionLogic:c.decide,targetSelectors:c.targets,initializeOpenLogic:e.initializeOpen})),d=t.components.listStore.map(c=>c.find(S=>S.name===`experience:${e.id}`)||c.find(S=>S.name==="experience"),{skipVoid:!1}),r=i.map(c=>({steps:c.steps,nodes:c.nodes,edges:c.edges,conditionals:c.conditionals})),n=e.actions??[];return{id:e.id,configStore:m,treeStore:r,componentStore:d,actions:n,merge:g.merge}});function V(t){return y.invoke(T,t)}const N=y.createFactory(({client:t})=>{const e=j.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.id]:n}}});function g(r){const n=e.getState()[r.id];if(n){n.merge({experience:r,strategy:"override"});return}const c=V({client:t,experience:r});i.register(c)}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getById:d,listStore:m}});function C(t){return y.invoke(N,t)}const L=(t,e)=>{e.register(t)},O=(t,e)=>{const{targetSelectors:i}=e.configStore.getState(),g=w.getTargetElements(i,e.id);g.forEach(({elements:d})=>d.forEach(r=>w.tagTargetElement(r,e.id))),w.createAppHosts(g,e.id).forEach(d=>{t.experienceInstances.spawn(e,d)})},q=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await _(t,e)&&O(t,e)}))},_=async(t,e)=>{const{decisionLogic:i,targetSelectors:g}=e.configStore.getState();return w.getTargetElements(g,e.id).length<1||g.length===0?!1:i&&w.isRulesLogic(i)?await w.evaluateRuleLogic(t,i)===!0:!0},U=p.createDomain("component"),H=y.createFactory(({client:t,component:e,name:i})=>{const g=t.frameworks.getByName(e.frameworkName);return{name:i,component:e,frameworkStore:g}});function K(t){return y.invoke(H,t)}const z=y.createFactory(({client:t})=>{const e=U.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:n}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Component '${r}' already registered. Registering again will override the previous registration.`);const S=K({client:t,name:r,component:n});i.register(S)}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function G(t){return y.invoke(z,t)}const Y=(t,e,i)=>{i.register(t,e)},J=p.createDomain("framework"),Q=y.createFactory(({client:t})=>{const e=J.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:n.framework}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Framework '${r}' already registered. Registering again will override the previous registration.`),i.register({name:r,framework:n})}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function W(t){return y.invoke(Q,t)}const X=(t,e)=>{e.register(t.name,t)},Z=6e3,D=x.createStorageKey("last_ping","global"),ee=t=>`${t}/api/v1/ping`,te=async t=>{try{const e=Date.now(),i=localStorage.getItem(D);if(i&&e-parseInt(i)<Z)return!0;const g=ee(t.apiUrl),m={projectId:t.projectId,path:window.location.pathname},d=JSON.stringify(m),r={"Content-Type":"application/json"},n=document.getElementById("picked_script"),c=n==null?void 0:n.dataset.verceltoken;c&&(r["x-vercel-protection-bypass"]=c);const k=(await fetch(g,{method:"POST",headers:r,body:d})).ok;return k&&localStorage.setItem(D,e.toString()),k}catch(e){return b.logger("error",e),!1}},re=p.createDomain("predicate"),ne=y.createFactory(({client:t})=>{const e=re.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:{name:n.name,predicate:n.predicate}}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Predicate '${r}' already registered. Registering again will override the previous registration.`),i.register(Object.freeze({name:r,predicate:n}))}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function se(t){return y.invoke(ne,t)}const oe=(t,e,i)=>{i.register(t,e)},$=p.createDomain("feature"),ie=y.createFactory(({client:t})=>{const e=$.store({}),i=$.store([]),g=p.createApi(e,{register(a,o){return{...a,[o.id]:o.feature}}});function m(a,o){e.getState()[a]&&b.logger("warn",`Feature '${a}' already registered. Registering again will override the previous registration.`);const l={id:a,feature:{...o,id:a}};g.register(Object.freeze({id:a,feature:l}))}const d=p.createEffect(async({id:a,key:o,storage:s="local"})=>{const l=x.createStorageKey(`feature:${a}:${o}`,"global"),u=(s==="session"?x.sessionStore:x.localStore).get(l).boolean();return u===null?null:{id:a,key:o,bucket:u}}),r=p.createEffect(a=>{if(!a)return null;const o=x.createStorageKey(`feature:${a.id}:${a.key}`,"global");(a.storage==="session"?x.sessionStore:x.localStore).set(o,a.bucket)}),n=new Map,c=p.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:i},effect:async({allFeaturesStore:a,resolvedFeaturesStore:o},{id:s,decide:l,key:f})=>{const u=o.find(A=>A.id===s);if(u)return u;const v=a[s];if(!v)throw new Error(`Feature with id '${s}' not found`);const F=n.get(`${s}:${f}`);if(F!==void 0){const A=await F;return{id:v.id,bucket:A,key:f,storage:v.feature.storage}}const E=l();n.set(`${s}:${f}`,E);const I=await E;return{id:v.id,bucket:I,key:f,storage:v.feature.storage}}});p.sample({clock:g.register,fn:a=>{const{id:o,feature:s}=a;return{id:o,key:s.feature.key,storage:s.feature.storage}},target:d}),p.sample({source:e,clock:c.doneData,fn:(a,o)=>{var v;const{id:s,bucket:l,storage:f}=o,u=(v=a[s])==null?void 0:v.feature.key;return u?{key:u,id:s,bucket:l,storage:f}:null},target:r});const S=p.combine({allFeaturesStore:e,resolvedFeaturesStore:i}).map(({allFeaturesStore:a,resolvedFeaturesStore:o})=>Object.values(a).map(s=>{const l=o.find(f=>f.id===s.id);return l?{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:()=>({id:s.id,bucket:l.bucket}),isResolved:!0}:{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:async()=>await c(s.feature),isResolved:!1}}));p.sample({clock:c.doneData,source:{resolvedFeatures:i},filter:({resolvedFeatures:a},{id:o})=>!a.some(s=>s.id===o),fn:(a,o)=>o,target:t.eventBus.prepend(a=>({type:"feature_decide",feature:a}))}),p.sample({clock:[d.doneData,c.doneData],source:i,fn:(a,o)=>!o||a.some(s=>s.id===o.id)?a:[...a,o],target:i});function k(a){return e.map(o=>o[a],{skipVoid:!1})}return{register:m,getByName:k,listStore:S}});function ae(t){return y.invoke(ie,t)}const ce=(t,e,i)=>{i.register(t,e)},h=p.createDomain("history");function R(t,e){return{id:P.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ue=y.createFactory(()=>{const t=h.store({entries:[]}),e=h.event(),i=h.event(),g=h.event(),m=h.event();t.on(e,(r,n)=>({entries:[...r.entries,R(n.experienceId,n.node)]})),t.on(i,(r,n)=>({entries:[...r.entries.slice(0,-1),R(n.experienceId,n.node)]})),t.on(m,(r,n)=>n);function d(r,n){const c={lastStepIndex:-1,secondLastStepIndex:-1};for(let S=r.length-1;S>=0;S--){const k=r[S],a=k==null?void 0:k.node;if(!(!a||!w.isStepNode(a))&&!(n&&(k==null?void 0:k.experienceId)!==n))if(c.lastStepIndex===-1)c.lastStepIndex=S;else{c.secondLastStepIndex=S;break}}return c}return t.on(g,(r,n)=>{const{secondLastStepIndex:c}=d(r.entries,n.experienceId),S=c!==-1?r.entries.slice(0,c+1):r.entries;return{...r,entries:S}}),{push:e,replace:i,back:g,restore:m,entriesStore:t.map(r=>r.entries)}});function le(){return y.invoke(ue)}const ge=p.createDomain("field"),de=y.createFactory(()=>{const t=ge.store({}),e=p.createApi(t,{register(r,n){return{...r,[n.field.id]:n.field}}});function i(r){e.register({field:r})}const g=t.map(r=>Object.values(r));function m(r){return t.map(n=>n[r]||null)}function d(r){return t.map(n=>Object.values(n).find(c=>c.name===r)||null)}return{register:i,getById:m,listStore:g,getByName:d}});function pe(){return y.invoke(de)}const me=(t,e)=>{e.register(t)},fe=p.createDomain("action"),ye=y.createFactory(()=>{const t=fe.store({}),e=p.createApi(t,{register(d,r){return{...d,[r.name]:{name:r.name,action:r.action}}}});function i(d,r){e.register({name:d,action:r})}const g=t.map(d=>Object.values(d));function m(d){return t.map(r=>r[d],{skipVoid:!1})}return{register:i,getByName:m,listStore:g}});function Se(){return y.invoke(ye)}const ve=(t,e,i)=>{i.register(t,e)},ke=p.createDomain("response"),Fe=y.createFactory(({client:t})=>{const e=ke.store({}),i=p.createEvent(),g=p.createEvent(),m=p.createApi(e,{register(o,s){return{...o,[s.fieldId]:s.response}},registerBatch(o,s){return{...o,...s}},clear(o,s){const{[s]:l,...f}=o;return f},clearAll(){return{}}});function d(o,s){m.register({fieldId:o,response:s})}async function r(o){const s=[];return await Promise.allSettled(Object.entries(o).map(async([l,f])=>{let u=f;const v=t.fields.getById(l).getState();if(!v){s.push({fieldId:l,userMessage:`Field '${l}' not found`,systemMessage:`No field with ID '${l}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:u});return}if(v.multiple&&(typeof u=="string"||typeof u=="number"||typeof u=="boolean")&&(u=[u]),v.validation&&!M.isEmpty(v.validation)){const F=await w.evaluateRuleLogic(t,v.validation,{$input:u});if(typeof F=="string"){s.push({fieldId:l,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:u});return}if(F===!1){s.push({fieldId:l,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:u});return}}if(v.required&&(typeof u>"u"||u===null||u===""||Array.isArray(u)&&!u.length)){s.push({fieldId:l,userMessage:"This field is required",systemMessage:"Field is required.",value:u});return}if(!v.multiple&&Array.isArray(u)&&u.length>1){s.push({fieldId:l,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:u});return}if(v.options){const F=v.options.map(I=>I.value),E=Array.isArray(u)?u:[u];Array.isArray(u)&&(E.every(I=>F.includes(I))||s.push({fieldId:l,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.join(", ")}`,value:u}))}})),{responsesToCommit:o,validationErrors:s}}async function n(o){const{responsesToCommit:s,validationErrors:l}=await r(o);return l.length?{errors:l}:(m.registerBatch(s),{errors:[]})}const c=e.map(o=>o),S=e.map(o=>Object.keys(o).map(l=>({fieldId:l,value:o[l]})));function k(o){const s=t.fields.getById(o),l=e.map(f=>f[o]||null);return p.combine({f:s,r:l},({f,r:u})=>u||(f!=null&&f.defaultValue?f.defaultValue:null))}function a(o){const s=t.fields.getByName(o);return p.combine({f:s,s:e},({f:l,s:f})=>{const u=l&&f[l.id]||null;return u||(l!=null&&l.defaultValue?l.defaultValue:null)})}return p.sample({clock:i,target:m.clearAll}),p.sample({clock:g,target:m.clear}),{register:d,clearAll:i,clear:g,commit:n,getResponsesToCommit:r,listStore:S,getAllStore:c,getByFieldId:k,getByFieldName:a}});function xe(t){return y.invoke(Fe,t)}function we(){if(B.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),i=Math.random().toString(36).substring(2,15),g=Math.random().toString(36).substring(2,15);return`${t}-${e}-${i}-${g}`}const Ie=()=>({id:we()}),he=x.createStorageKey("session","global"),be=()=>{if(!B.supportsLocalStorage())return null;const t=x.localStore.get(he);let e=t.isSet()?t.json():null;return e||(e=Ie(),t.set(e)),e},Ee=()=>be();exports.createActionIndex=Se;exports.createComponentIndex=G;exports.createExperienceIndex=C;exports.createFeatureIndex=ae;exports.createFieldIndex=pe;exports.createFrameworkIndex=W;exports.createHistory=le;exports.createPredicateIndex=se;exports.createResponseIndex=xe;exports.initialiseExperience=O;exports.initialiseExperiences=q;exports.initialiseSession=Ee;exports.ping=te;exports.setupAction=ve;exports.setupComponent=Y;exports.setupExperience=L;exports.setupFeature=ce;exports.setupField=me;exports.setupFramework=X;exports.setupPredicate=oe;
|