@picked/client 0.0.1-dev.1772412203098 → 0.0.1-dev.1773363643396

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.
Files changed (98) hide show
  1. package/dist/api-C7ddxkUx.cjs +1 -0
  2. package/dist/api-CQ_YBH_c.js +32 -0
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/plugins/create-experience/index.js +1 -1
  5. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  6. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  7. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  9. package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
  10. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  11. package/dist/cjs/server/index.js +1 -1
  12. package/dist/esm/index.js +602 -687
  13. package/dist/esm/plugins/create-experience/index.js +237 -213
  14. package/dist/esm/plugins/dynamic-experiences/index.js +65 -43
  15. package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
  16. package/dist/esm/plugins/history-browser-storage/index.js +1 -1
  17. package/dist/esm/plugins/responses-browser-storage/index.js +18 -17
  18. package/dist/esm/plugins/responses-indexeddb/index.js +46 -51
  19. package/dist/esm/plugins/single-page-app/index.js +24 -24
  20. package/dist/esm/server/index.js +1 -1
  21. package/dist/experience-instance-BsXG5XJ4.cjs +1 -0
  22. package/dist/{experience-instance-DTyL1fNb.js → experience-instance-fvSEb72i.js} +199 -205
  23. package/dist/object-BbFTsGh3.cjs +1 -0
  24. package/dist/{object-CJssU1Pm.js → object-JwZ58NOH.js} +1 -1
  25. package/dist/storage-Be5xWNPC.cjs +1 -0
  26. package/dist/{storage-B2d81EOI.js → storage-Co_LbKr_.js} +30 -35
  27. package/dist/to-kebab-case-BPnCZjhB.js +6 -0
  28. package/dist/to-kebab-case-BsOQ8CON.cjs +1 -0
  29. package/dist/types/client.d.ts +13 -0
  30. package/dist/types/client.d.ts.map +1 -1
  31. package/dist/types/entities/action/action.d.ts +2 -5
  32. package/dist/types/entities/action/action.d.ts.map +1 -1
  33. package/dist/types/entities/experience/experience.d.ts +31 -17
  34. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  35. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  36. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  37. package/dist/types/entities/field/field.d.ts +21 -52
  38. package/dist/types/entities/field/field.d.ts.map +1 -1
  39. package/dist/types/entities/history/history.d.ts.map +1 -1
  40. package/dist/types/entities/project/project.d.ts.map +1 -1
  41. package/dist/types/entities/response/response.d.ts +6 -6
  42. package/dist/types/entities/response/response.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +0 -1
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/logic-engine.d.ts +8 -2
  46. package/dist/types/logic-engine.d.ts.map +1 -1
  47. package/dist/types/picked.d.ts +17 -23
  48. package/dist/types/picked.d.ts.map +1 -1
  49. package/dist/types/plugins/create-experience/create-experience.d.ts +28 -33
  50. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  51. package/dist/types/plugins/dynamic-experiences/index.d.ts +1 -0
  52. package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
  53. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +2 -2
  54. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  55. package/dist/types/plugins/dynamic-experiences/types.d.ts +7 -1
  56. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  57. package/dist/types/plugins/experience-browser-storage/plugin.d.ts +1 -2
  58. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  59. package/dist/types/plugins/history-browser-storage/plugin.d.ts +1 -2
  60. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  61. package/dist/types/plugins/responses-browser-storage/plugin.d.ts +1 -2
  62. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
  63. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
  64. package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
  65. package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
  66. package/dist/types/utils/api.d.ts +1 -1
  67. package/dist/types/utils/api.d.ts.map +1 -1
  68. package/dist/types/utils/client-headers.d.ts +2 -0
  69. package/dist/types/utils/client-headers.d.ts.map +1 -0
  70. package/dist/types/utils/dom.d.ts +3 -0
  71. package/dist/types/utils/dom.d.ts.map +1 -1
  72. package/dist/types/utils/events.d.ts +1 -1
  73. package/dist/types/utils/events.d.ts.map +1 -1
  74. package/dist/types/utils/get-step-fields.d.ts +1 -2
  75. package/dist/types/utils/get-step-fields.d.ts.map +1 -1
  76. package/dist/types/utils/global-obj.d.ts +1 -0
  77. package/dist/types/utils/global-obj.d.ts.map +1 -1
  78. package/dist/types/utils/indexed-db.d.ts +1 -2
  79. package/dist/types/utils/indexed-db.d.ts.map +1 -1
  80. package/dist/types/utils/logger.d.ts.map +1 -1
  81. package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
  82. package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
  83. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
  84. package/dist/types/utils/object.d.ts +8 -0
  85. package/dist/types/utils/object.d.ts.map +1 -1
  86. package/dist/types/utils/picked-config.d.ts +1 -1
  87. package/dist/types/utils/picked-config.d.ts.map +1 -1
  88. package/dist/types/utils/rules-logic.d.ts.map +1 -1
  89. package/dist/types/utils/search-params.d.ts.map +1 -1
  90. package/dist/types/utils/storage.d.ts.map +1 -1
  91. package/dist/types/utils/to-kebab-case.d.ts +9 -0
  92. package/dist/types/utils/to-kebab-case.d.ts.map +1 -0
  93. package/package.json +59 -8
  94. package/dist/api-CbXfbi_s.js +0 -19
  95. package/dist/api-DzSCgBQ2.cjs +0 -1
  96. package/dist/experience-instance-BX0aqKsC.cjs +0 -1
  97. package/dist/object-mwaxtjLG.cjs +0 -1
  98. package/dist/storage-58NoTSsc.cjs +0 -1
package/dist/esm/index.js CHANGED
@@ -1,145 +1,145 @@
1
- import { createDomain as F, createApi as j, attach as T, createStore as _, createEffect as C, sample as w, combine as A, createEvent as $ } from "effector";
2
- import { createFactory as I, invoke as x } from "@withease/factories";
3
- import { g as Q, t as ne, c as se, i as ie, e as E, a as oe, b as ae, d as ce } from "../experience-instance-DTyL1fNb.js";
4
- import { f as Mt } from "../experience-instance-DTyL1fNb.js";
5
- import { l as b } from "../logger-C9a75KZn.js";
6
- import { c as R, l as O, s as D } from "../storage-B2d81EOI.js";
7
- import { a as Dt } from "../storage-B2d81EOI.js";
8
- import { p as ue } from "../api-CbXfbi_s.js";
9
- import { g as le } from "../id-BW-g3y32.js";
10
- import { i as de } from "../object-CJssU1Pm.js";
11
- import { s as H, a as G, b as pe, c as fe, d as ge } from "../supports-8YT4QKI7.js";
12
- import { e as Vt, f as Nt, g as Tt, h as Lt, i as _t, j as Ht, k as Gt } from "../supports-8YT4QKI7.js";
13
- const X = F("experience"), me = I(
1
+ import { createDomain as x, createApi as j, attach as U, createStore as T, createEffect as R, sample as k, combine as D, createEvent as V } from "effector";
2
+ import { createFactory as b, invoke as I } from "@withease/factories";
3
+ import { g as W, t as te, c as re, i as se, e as P, a as ne, b as ie, d as oe } from "../experience-instance-fvSEb72i.js";
4
+ import { f as Ot } from "../experience-instance-fvSEb72i.js";
5
+ import { l as w } from "../logger-C9a75KZn.js";
6
+ import { c as A, l as C, s as O } from "../storage-Co_LbKr_.js";
7
+ import { a as Ut } from "../storage-Co_LbKr_.js";
8
+ import { p as ae, g as ce } from "../api-CQ_YBH_c.js";
9
+ import { g as ue } from "../id-BW-g3y32.js";
10
+ import { i as de } from "../object-JwZ58NOH.js";
11
+ import { t as le } from "../to-kebab-case-BPnCZjhB.js";
12
+ import { s as L, a as _, b as pe, c as fe, d as ge } from "../supports-8YT4QKI7.js";
13
+ import { e as Vt, f as Nt, g as Tt, h as Lt, i as _t, j as Ht, k as Kt } from "../supports-8YT4QKI7.js";
14
+ const Y = x("experience"), me = b(
14
15
  ({ client: t, experience: e }) => {
15
- const r = X.store(e), s = j(r, {
16
- merge(l, m) {
16
+ const r = Y.store(e), s = j(r, {
17
+ merge(u, g) {
17
18
  return {
18
- ...l,
19
- ...m.experience
19
+ ...u,
20
+ ...g.experience
20
21
  };
21
22
  }
22
- }), i = r.map((l) => ({
23
- name: l.name,
24
- // eslint-disable-next-line sonarjs/deprecation -- backwards compatibility: `decide` is deprecated but still supported
25
- decisionLogic: l.condition ?? l.decide,
26
- targetSelectors: l.targets,
23
+ }), n = r.map((u) => ({
24
+ name: u.name,
25
+ decisionLogic: u.condition,
26
+ targetSelectors: u.targets,
27
27
  initializeOpenLogic: e.initializeOpen
28
- })), d = t.components.listStore.map(
29
- (l) => l.find((m) => m.name === `experience:${e.id}`) || l.find((m) => m.name === "experience"),
28
+ })), p = t.components.listStore.map(
29
+ (u) => (e.componentName ? u.find((g) => g.name === e.componentName) : void 0) || u.find((g) => g.name === `experience:${e.id}`) || u.find((g) => g.name === "experience"),
30
30
  { skipVoid: !1 }
31
- ), p = r.map((l) => ({
32
- steps: l.steps,
33
- nodes: l.nodes,
34
- edges: l.edges,
35
- conditionals: l.conditionals
36
- })), u = r.map((l) => l.fields), g = e.actions ?? [];
31
+ ), o = r.map((u) => ({
32
+ steps: u.steps,
33
+ nodes: u.nodes,
34
+ edges: u.edges,
35
+ conditionals: u.conditionals
36
+ })), c = r.map((u) => u.fields), a = e.actions ?? [];
37
37
  return {
38
38
  id: e.id,
39
- configStore: i,
40
- treeStore: p,
41
- fieldsStore: u,
42
- componentStore: d,
43
- actions: g,
39
+ configStore: n,
40
+ treeStore: o,
41
+ fieldsStore: c,
42
+ componentStore: p,
43
+ actions: a,
44
44
  merge: s.merge
45
45
  };
46
46
  }
47
47
  );
48
- function ye(t) {
49
- return x(me, t);
48
+ function he(t) {
49
+ return I(me, t);
50
50
  }
51
- const he = I(({ client: t }) => {
52
- const e = X.store({}), r = j(e, {
53
- register(l, m) {
51
+ const ye = b(({ client: t }) => {
52
+ const e = Y.store({}), r = j(e, {
53
+ register(a, u) {
54
54
  return {
55
- ...l,
56
- [m.id]: m
55
+ ...a,
56
+ [u.id]: u
57
57
  };
58
58
  }
59
59
  });
60
- function s(l) {
61
- const m = e.getState()[l.id];
62
- if (m) {
63
- m.merge({ experience: l, strategy: "override" });
60
+ function s(a) {
61
+ const u = e.getState()[a.id];
62
+ if (u) {
63
+ u.merge({ experience: a, strategy: "override" });
64
64
  return;
65
65
  }
66
- const h = ye({ client: t, experience: l });
67
- r.register(h);
66
+ const g = he({ client: t, experience: a });
67
+ r.register(g);
68
68
  }
69
- const i = e.map((l) => Object.values(l));
70
- function d(l) {
71
- return e.map((m) => m[l], { skipVoid: !1 });
69
+ const n = e.map((a) => Object.values(a));
70
+ function p(a) {
71
+ return e.map((u) => u[a], { skipVoid: !1 });
72
72
  }
73
- const p = d, u = T({
73
+ const o = U({
74
74
  source: e,
75
- effect: async (l, { id: m, options: h }) => {
76
- const y = l[m];
77
- if (!y) {
78
- b("warn", `Experience with id '${m}' not found.`);
75
+ effect: async (a, { id: u, options: g }) => {
76
+ const S = a[u];
77
+ if (!S) {
78
+ w("warn", `Experience with id '${u}' not found.`);
79
79
  return;
80
80
  }
81
- if (h?.bypassCondition) {
82
- L(t, y, h);
81
+ if (g?.bypassCondition) {
82
+ N(t, S, g);
83
83
  return;
84
84
  }
85
- await Z(t, y) && L(t, y, h);
85
+ await Q(t, S) && N(t, S, g);
86
86
  }
87
- }), g = T({
87
+ }), c = U({
88
88
  source: t.experienceInstances.listStore,
89
- effect: (l, { id: m, options: h }) => {
90
- const y = l.filter((c) => c.experienceId === m);
91
- if (y.length > 0)
92
- for (const c of y)
93
- c.open();
89
+ effect: (a, { id: u, options: g }) => {
90
+ const S = a.filter((m) => m.experienceId === u);
91
+ if (S.length > 0)
92
+ for (const m of S)
93
+ m.open();
94
94
  else
95
- u({ id: m, options: { ...h, initialiseOpen: !0 } });
95
+ o({ id: u, options: { ...g, initialiseOpen: !0 } });
96
96
  }
97
97
  });
98
98
  return {
99
99
  /** Registers an experience in the index. If an experience with the same ID already exists, it is merged. */
100
100
  register: s,
101
101
  /** Returns a derived store for an experience by its ID. The store value is `undefined` when no match exists. */
102
- get: d,
102
+ get: p,
103
103
  /** @deprecated Use `experiences.get(id)` instead. */
104
104
  getById: p,
105
105
  /** Effector effect that launches an experience by ID, creating instances for each DOM target. */
106
- launch: u,
106
+ launch: o,
107
107
  /** Effector effect that opens an experience's existing instances, or launches it with `initialiseOpen` if none exist. */
108
- open: g,
108
+ open: c,
109
109
  /** Derived store containing all registered experiences as an array. */
110
- listStore: i
110
+ listStore: n
111
111
  };
112
112
  });
113
- function ve(t) {
114
- return x(he, t);
113
+ function Se(t) {
114
+ return I(ye, t);
115
115
  }
116
- const Se = (t, e) => {
116
+ const ve = (t, e) => {
117
117
  e.register(t);
118
- }, L = (t, e, r) => {
119
- const { targetSelectors: s } = e.configStore.getState(), i = Q(s, e.id);
120
- i.forEach(
121
- ({ elements: p }) => p.forEach((u) => ne(u, e.id))
122
- ), se(i, e.id).forEach((p) => {
123
- r ? t.experienceInstances.spawn(e, p, r) : t.experienceInstances.spawn(e, p);
118
+ }, N = (t, e, r) => {
119
+ const { targetSelectors: s } = e.configStore.getState(), n = W(s, e.id);
120
+ n.forEach(
121
+ ({ elements: o }) => o.forEach((c) => te(c, e.id))
122
+ ), re(n, e.id).forEach((o) => {
123
+ r ? t.experienceInstances.spawn(e, o, r) : t.experienceInstances.spawn(e, o);
124
124
  });
125
- }, J = async (t) => {
125
+ }, H = async (t) => {
126
126
  await Promise.all(
127
127
  t.experiences.listStore.getState().map(async (e) => {
128
- await Z(t, e) && L(t, e);
128
+ await Q(t, e) && N(t, e);
129
129
  })
130
130
  );
131
- }, Z = async (t, e) => {
132
- if (!t.session?.isUser)
131
+ }, Q = async (t, e) => {
132
+ if (!t.preconditionPassed || !t.session?.isUser)
133
133
  return !1;
134
134
  const { decisionLogic: r, targetSelectors: s } = e.configStore.getState();
135
- return Q(s, e.id).length < 1 || s.length === 0 ? !1 : r === void 0 ? !0 : ie(r) ? await E(t, r) === !0 : !0;
135
+ return W(s, e.id).length < 1 || s.length === 0 ? !1 : r === void 0 ? !0 : se(r) ? await P(t, r) === !0 : !0;
136
136
  }, ke = (t, e, r) => {
137
- const s = e.name, i = e.setup(t);
138
- if (i) {
139
- const d = r[s] ?? {};
140
- r[s] = Object.freeze({ ...d, ...i });
137
+ const s = e.name, n = e.setup(t);
138
+ if (n) {
139
+ const p = r[s] ?? {};
140
+ r[s] = Object.freeze({ ...p, ...n });
141
141
  }
142
- }, we = F("component"), be = I(
142
+ }, we = x("component"), be = b(
143
143
  ({ client: t, component: e, name: r }) => {
144
144
  const s = t.frameworks.getByName(e.frameworkName);
145
145
  return {
@@ -150,88 +150,88 @@ const Se = (t, e) => {
150
150
  }
151
151
  );
152
152
  function Ie(t) {
153
- return x(be, t);
153
+ return I(be, t);
154
154
  }
155
- const xe = I(({ client: t }) => {
155
+ const Fe = b(({ client: t }) => {
156
156
  const e = we.store({}), r = j(e, {
157
- register(p, u) {
157
+ register(o, c) {
158
158
  return {
159
- ...p,
160
- [u.name]: u
159
+ ...o,
160
+ [c.name]: c
161
161
  };
162
162
  }
163
163
  });
164
- function s(p, u) {
165
- e.getState()[p] && b(
164
+ function s(o, c) {
165
+ e.getState()[o] && w(
166
166
  "warn",
167
- `Component '${p}' already registered. Registering again will override the previous registration.`
167
+ `Component '${o}' already registered. Registering again will override the previous registration.`
168
168
  );
169
- const l = Ie({ client: t, name: p, component: u });
170
- r.register(l);
169
+ const u = Ie({ client: t, name: o, component: c });
170
+ r.register(u);
171
171
  }
172
- const i = e.map((p) => Object.values(p));
173
- function d(p) {
174
- return e.map((u) => u[p], { skipVoid: !1 });
172
+ const n = e.map((o) => Object.values(o));
173
+ function p(o) {
174
+ return e.map((c) => c[o], { skipVoid: !1 });
175
175
  }
176
176
  return {
177
177
  register: s,
178
- getByName: d,
179
- listStore: i
178
+ getByName: p,
179
+ listStore: n
180
180
  };
181
181
  });
182
- function Fe(t) {
183
- return x(xe, t);
182
+ function xe(t) {
183
+ return I(Fe, t);
184
184
  }
185
- const q = (t, e, r) => {
185
+ const K = (t, e, r) => {
186
186
  r.register(t, e);
187
- }, je = F("framework"), Ae = I(({ client: t }) => {
187
+ }, je = x("framework"), Ee = b(({ client: t }) => {
188
188
  const e = je.store({}), r = j(e, {
189
- register(p, u) {
189
+ register(o, c) {
190
190
  return {
191
- ...p,
192
- [u.name]: u.framework
191
+ ...o,
192
+ [c.name]: c.framework
193
193
  };
194
194
  }
195
195
  });
196
- function s(p, u) {
197
- e.getState()[p] && b(
196
+ function s(o, c) {
197
+ e.getState()[o] && w(
198
198
  "warn",
199
- `Framework '${p}' already registered. Registering again will override the previous registration.`
200
- ), r.register({ name: p, framework: u });
199
+ `Framework '${o}' already registered. Registering again will override the previous registration.`
200
+ ), r.register({ name: o, framework: c });
201
201
  }
202
- const i = e.map((p) => Object.values(p));
203
- function d(p) {
204
- return e.map((u) => u[p], { skipVoid: !1 });
202
+ const n = e.map((o) => Object.values(o));
203
+ function p(o) {
204
+ return e.map((c) => c[o], { skipVoid: !1 });
205
205
  }
206
206
  return {
207
207
  register: s,
208
- getByName: d,
209
- listStore: i
208
+ getByName: p,
209
+ listStore: n
210
210
  };
211
211
  });
212
- function Ee(t) {
213
- return x(Ae, t);
212
+ function Pe(t) {
213
+ return I(Ee, t);
214
214
  }
215
- const Pe = (t, e) => {
215
+ const Ae = (t, e) => {
216
216
  e.register(t.name, t);
217
- }, $e = 6e3, Re = R("last_ping", "global"), Be = async (t) => {
217
+ }, $e = 6e3, Be = A("last_ping", "global"), Re = async (t) => {
218
218
  try {
219
- const e = Date.now(), r = O.get(Re);
219
+ const e = Date.now(), r = C.get(Be);
220
220
  let s = 0;
221
221
  if (r.isSet() && (s = r.json() ?? 0), s && e - s < $e)
222
222
  return !0;
223
- const i = {
223
+ const n = {
224
224
  projectId: t.projectId,
225
225
  path: window.location.pathname
226
- }, d = {}, u = document.getElementById("picked_script")?.dataset.verceltoken;
227
- u && (d["x-vercel-protection-bypass"] = u);
228
- const l = (await ue(t.apiUrl, "ping", i, d)).ok;
229
- return l && r.set(e), l;
226
+ }, p = {}, c = document.getElementById("picked_script")?.dataset.verceltoken;
227
+ c && (p["x-vercel-protection-bypass"] = c);
228
+ const u = (await ae(t.apiUrl, "ping", n, p)).ok;
229
+ return u && r.set(e), u;
230
230
  } catch (e) {
231
- return b("error", e), !1;
231
+ return w("error", e), !1;
232
232
  }
233
233
  };
234
- function ee(t) {
234
+ function X(t) {
235
235
  const e = typeof window < "u", r = {
236
236
  client: t,
237
237
  responses: t.responses.listStore.getState(),
@@ -243,277 +243,276 @@ function ee(t) {
243
243
  };
244
244
  return Object.freeze(r);
245
245
  }
246
- const ze = F("predicate"), Ce = I(({ client: t }) => {
246
+ const ze = x("predicate"), Ce = b(({ client: t }) => {
247
247
  const e = ze.store({}), r = j(e, {
248
- register(u, g) {
248
+ register(c, a) {
249
249
  return {
250
- ...u,
251
- [g.name]: {
252
- name: g.name,
253
- predicate: g.predicate
250
+ ...c,
251
+ [a.name]: {
252
+ name: a.name,
253
+ predicate: a.predicate
254
254
  }
255
255
  };
256
256
  }
257
257
  });
258
- function s(u, g) {
259
- e.getState()[u] && b(
258
+ function s(c, a) {
259
+ e.getState()[c] && w(
260
260
  "warn",
261
- `Predicate '${u}' already registered. Registering again will override the previous registration.`
262
- ), r.register(Object.freeze({ name: u, predicate: g }));
261
+ `Predicate '${c}' already registered. Registering again will override the previous registration.`
262
+ ), r.register(Object.freeze({ name: c, predicate: a }));
263
263
  }
264
- const i = e.map((u) => Object.values(u));
265
- function d(u) {
266
- return e.map((g) => g[u]?.predicate, { skipVoid: !1 });
264
+ const n = e.map((c) => Object.values(c));
265
+ function p(c) {
266
+ return e.map((a) => a[c]?.predicate, { skipVoid: !1 });
267
267
  }
268
- function p(u) {
269
- const g = _(() => {
268
+ function o(c) {
269
+ const a = T(() => {
270
270
  }, {
271
271
  skipVoid: !1
272
- }), l = C(async () => {
273
- const m = d(u).getState();
274
- if (!m)
272
+ }), u = R(async () => {
273
+ const g = p(c).getState();
274
+ if (!g)
275
275
  return;
276
- const h = ee(t);
277
- return (...y) => m({ ...h, args: y });
276
+ const S = X(t);
277
+ return (...m) => g({ ...S, args: m });
278
278
  });
279
- return w({
279
+ return k({
280
280
  source: { responses: t.responses.listStore, fields: t.fields.listStore },
281
- target: l
282
- }), w({
283
- clock: l.doneData,
284
- filter: (m) => m !== void 0,
285
- target: g
286
- }), l(), g;
281
+ target: u
282
+ }), k({
283
+ clock: u.doneData,
284
+ filter: (g) => g !== void 0,
285
+ target: a
286
+ }), u(), a;
287
287
  }
288
288
  return {
289
289
  register: s,
290
- getByName: d,
291
- listStore: i,
292
- getEvokablePredicate: p
290
+ getByName: p,
291
+ listStore: n,
292
+ getEvokablePredicate: o
293
293
  };
294
294
  });
295
- function Me(t) {
296
- return x(Ce, t);
295
+ function Oe(t) {
296
+ return I(Ce, t);
297
297
  }
298
- const Oe = (t, e, r) => {
298
+ const Me = (t, e, r) => {
299
299
  r.register(t, e);
300
- }, K = F("feature"), De = I(({ client: t }) => {
301
- const e = K.store({}), r = K.store([]), s = j(e, {
302
- register(c, n) {
300
+ }, G = x("feature"), Ue = b(({ client: t }) => {
301
+ const e = G.store({}), r = G.store([]), s = j(e, {
302
+ register(i, d) {
303
303
  return {
304
- ...c,
305
- [n.id]: n.feature
304
+ ...i,
305
+ [d.id]: d.feature
306
306
  };
307
307
  }
308
308
  });
309
- function i(c, n) {
310
- e.getState()[c] && b(
309
+ function n(i, d) {
310
+ e.getState()[i] && w(
311
311
  "warn",
312
- `Feature '${c}' already registered. Registering again will override the previous registration.`
312
+ `Feature '${i}' already registered. Registering again will override the previous registration.`
313
313
  );
314
- const a = {
315
- id: c,
314
+ const l = {
315
+ id: i,
316
316
  feature: {
317
- ...n,
318
- id: c
317
+ ...d,
318
+ id: i
319
319
  }
320
320
  };
321
321
  s.register(
322
322
  Object.freeze({
323
- id: c,
324
- feature: a
323
+ id: i,
324
+ feature: l
325
325
  })
326
326
  );
327
327
  }
328
- const d = C(
328
+ const p = R(
329
329
  async ({
330
- id: c,
331
- key: n,
332
- storage: o = "local"
330
+ id: i,
331
+ key: d,
332
+ storage: f = "local"
333
333
  }) => {
334
- const a = R(`feature:${c}:${n}`, "global"), v = (o === "session" ? D : O).get(a).boolean();
335
- return v === null ? null : { id: c, key: n, bucket: v, storage: o };
334
+ const l = A(`feature:${i}:${d}`, "global"), y = (f === "session" ? O : C).get(l).boolean();
335
+ return y === null ? null : { id: i, key: d, bucket: y, storage: f };
336
336
  }
337
- ), p = C((c) => {
338
- if (!c)
337
+ ), o = R((i) => {
338
+ if (!i)
339
339
  return null;
340
- const n = R(`feature:${c.id}:${c.key}`, "global");
341
- (c.storage === "session" ? D : O).set(n, c.bucket);
342
- }), u = /* @__PURE__ */ new Map(), g = T({
340
+ const d = A(`feature:${i.id}:${i.key}`, "global");
341
+ (i.storage === "session" ? O : C).set(d, i.bucket);
342
+ }), c = /* @__PURE__ */ new Map(), a = U({
343
343
  source: { allFeaturesStore: e, resolvedFeaturesStore: r },
344
- effect: async ({ allFeaturesStore: c, resolvedFeaturesStore: n }, { id: o, decide: a, key: f }) => {
345
- const v = n.find(
346
- (z) => z.id === o && z.key === f
344
+ effect: async ({ allFeaturesStore: i, resolvedFeaturesStore: d }, { id: f, decide: l, key: h }) => {
345
+ const y = d.find(
346
+ (B) => B.id === f && B.key === h
347
347
  );
348
- if (v)
349
- return v;
350
- const S = c[o];
351
- if (!S)
352
- throw new Error(`Feature with id '${o}' not found`);
353
- const B = u.get(`${o}:${f}`);
354
- if (B !== void 0) {
355
- const z = await B;
356
- return { id: S.id, bucket: z, key: f, storage: S.feature.storage };
348
+ if (y)
349
+ return y;
350
+ const F = i[f];
351
+ if (!F)
352
+ throw new Error(`Feature with id '${f}' not found`);
353
+ const $ = c.get(`${f}:${h}`);
354
+ if ($ !== void 0) {
355
+ const B = await $;
356
+ return { id: F.id, bucket: B, key: h, storage: F.feature.storage };
357
357
  }
358
- const k = a();
359
- u.set(`${o}:${f}`, k);
360
- const re = await k;
361
- return { id: S.id, bucket: re, key: f, storage: S.feature.storage };
358
+ const v = l();
359
+ c.set(`${f}:${h}`, v);
360
+ const ee = await v;
361
+ return { id: F.id, bucket: ee, key: h, storage: F.feature.storage };
362
362
  }
363
363
  });
364
- w({
364
+ k({
365
365
  clock: s.register,
366
- fn: (c) => {
367
- const { id: n, feature: o } = c;
368
- return { id: n, key: o.feature.key, storage: o.feature.storage };
366
+ fn: (i) => {
367
+ const { id: d, feature: f } = i;
368
+ return { id: d, key: f.feature.key, storage: f.feature.storage };
369
369
  },
370
- target: d
371
- }), w({
370
+ target: p
371
+ }), k({
372
372
  source: e,
373
- clock: g.doneData,
374
- fn: (c, n) => {
375
- const { id: o, bucket: a, storage: f } = n, v = c[o]?.feature.key;
376
- return v ? { key: v, id: o, bucket: a, storage: f } : null;
373
+ clock: a.doneData,
374
+ fn: (i, d) => {
375
+ const { id: f, bucket: l, storage: h } = d, y = i[f]?.feature.key;
376
+ return y ? { key: y, id: f, bucket: l, storage: h } : null;
377
377
  },
378
- target: p
378
+ target: o
379
379
  });
380
- const l = A({ allFeaturesStore: e, resolvedFeaturesStore: r }).map(
380
+ const u = D({ allFeaturesStore: e, resolvedFeaturesStore: r }).map(
381
381
  ({
382
- allFeaturesStore: c,
383
- resolvedFeaturesStore: n
384
- }) => Object.values(c).map((o) => {
385
- const a = n.find(
386
- (f) => f.id === o.id && f.key === o.feature.key
382
+ allFeaturesStore: i,
383
+ resolvedFeaturesStore: d
384
+ }) => Object.values(i).map((f) => {
385
+ const l = d.find(
386
+ (h) => h.id === f.id && h.key === f.feature.key
387
387
  );
388
- return a ? {
389
- id: o.id,
390
- name: o.feature.name,
391
- key: o.feature.key,
392
- getBucket: () => ({ id: o.id, bucket: a.bucket }),
388
+ return l ? {
389
+ id: f.id,
390
+ name: f.feature.name,
391
+ key: f.feature.key,
392
+ getBucket: () => ({ id: f.id, bucket: l.bucket }),
393
393
  isResolved: !0
394
394
  } : {
395
- id: o.id,
396
- name: o.feature.name,
397
- key: o.feature.key,
398
- getBucket: async () => await g(o.feature),
395
+ id: f.id,
396
+ name: f.feature.name,
397
+ key: f.feature.key,
398
+ getBucket: async () => await a(f.feature),
399
399
  isResolved: !1
400
400
  };
401
401
  })
402
402
  );
403
- w({
404
- clock: g.doneData,
403
+ k({
404
+ clock: a.doneData,
405
405
  source: { resolvedFeatures: r },
406
- filter: ({ resolvedFeatures: c }, { id: n, key: o }) => !c.some(
407
- (f) => f.id === n && f.key === o
406
+ filter: ({ resolvedFeatures: i }, { id: d, key: f }) => !i.some(
407
+ (h) => h.id === d && h.key === f
408
408
  ),
409
- fn: (c, n) => n,
410
- target: t.eventBus.prepend((c) => ({
409
+ fn: (i, d) => d,
410
+ target: t.eventBus.prepend((i) => ({
411
411
  type: "feature_decide",
412
- feature: c
412
+ feature: i
413
413
  }))
414
- }), w({
415
- clock: [d.doneData, g.doneData],
414
+ }), k({
415
+ clock: [p.doneData, a.doneData],
416
416
  source: r,
417
- fn: (c, n) => !n || c.some(
418
- (a) => a.id === n.id && a.key === n.key
419
- ) ? c : [...c, n],
417
+ fn: (i, d) => !d || i.some(
418
+ (l) => l.id === d.id && l.key === d.key
419
+ ) ? i : [...i, d],
420
420
  target: r
421
421
  });
422
- function m(c) {
423
- return l.map((n) => n.find((o) => o.id === c));
422
+ function g(i) {
423
+ return u.map((d) => d.find((f) => f.id === i));
424
424
  }
425
- function h(c) {
426
- return e.map((n) => n[c], { skipVoid: !1 });
425
+ function S(i) {
426
+ return e.map((d) => d[i], { skipVoid: !1 });
427
427
  }
428
- function y(c) {
429
- const n = _(
428
+ function m(i) {
429
+ const d = T(
430
430
  async () => {
431
431
  },
432
432
  { skipVoid: !1 }
433
- ), o = C(async () => {
434
- const a = m(c).getState();
435
- if (a)
436
- return async () => (await a.getBucket()).bucket;
433
+ ), f = R(async () => {
434
+ const l = g(i).getState();
435
+ if (l)
436
+ return async () => (await l.getBucket()).bucket;
437
437
  });
438
- return w({
438
+ return k({
439
439
  source: r,
440
- filter: (a) => a.some((f) => f.id === c),
441
- target: o
442
- }), w({
443
- clock: o.doneData,
444
- filter: (a) => a !== void 0,
445
- target: n
446
- }), o(), n;
440
+ filter: (l) => l.some((h) => h.id === i),
441
+ target: f
442
+ }), k({
443
+ clock: f.doneData,
444
+ filter: (l) => l !== void 0,
445
+ target: d
446
+ }), f(), d;
447
447
  }
448
448
  return {
449
- register: i,
450
- getById: m,
451
- // eslint-disable-next-line sonarjs/deprecation -- kept for backwards compatibility; use getById instead
452
- getByName: h,
453
- listStore: l,
454
- getEvokableFeature: y
449
+ register: n,
450
+ getById: g,
451
+ getByName: S,
452
+ listStore: u,
453
+ getEvokableFeature: m
455
454
  };
456
455
  });
457
- function Ue(t) {
458
- return x(De, t);
456
+ function De(t) {
457
+ return I(Ue, t);
459
458
  }
460
459
  const Ve = (t, e, r) => {
461
460
  r.register(t, e);
462
- }, P = F("history");
463
- function W(t, e) {
461
+ }, E = x("history");
462
+ function J(t, e) {
464
463
  return {
465
464
  // eslint-disable-next-line sonarjs/pseudo-random
466
- id: le(`history-entry-${Date.now()}-${Math.random()}}`),
465
+ id: ue(`history-entry-${Date.now()}-${Math.random()}}`),
467
466
  node: e,
468
467
  at: Date.now(),
469
468
  experienceId: t
470
469
  };
471
470
  }
472
- const Ne = I(() => {
473
- const t = P.store({ entries: [] }), e = P.event(), r = P.event(), s = P.event(), i = P.event();
474
- t.on(e, (p, u) => ({
475
- entries: [...p.entries, W(u.experienceId, u.node)]
476
- })), t.on(r, (p, u) => ({
471
+ const Ne = b(() => {
472
+ const t = E.store({ entries: [] }), e = E.event(), r = E.event(), s = E.event(), n = E.event();
473
+ t.on(e, (o, c) => ({
474
+ entries: [...o.entries, J(c.experienceId, c.node)]
475
+ })), t.on(r, (o, c) => ({
477
476
  entries: [
478
- ...p.entries.slice(0, -1),
479
- W(u.experienceId, u.node)
477
+ ...o.entries.slice(0, -1),
478
+ J(c.experienceId, c.node)
480
479
  ]
481
- })), t.on(i, (p, u) => u);
482
- function d(p, u) {
483
- const g = { lastStepIndex: -1, secondLastStepIndex: -1 };
484
- for (let l = p.length - 1; l >= 0; l--) {
485
- const m = p[l], h = m?.node;
486
- if (!(!h || !oe(h)) && !(u && m.experienceId !== u))
487
- if (g.lastStepIndex === -1)
488
- g.lastStepIndex = l;
480
+ })), t.on(n, (o, c) => c);
481
+ function p(o, c) {
482
+ const a = { lastStepIndex: -1, secondLastStepIndex: -1 };
483
+ for (let u = o.length - 1; u >= 0; u--) {
484
+ const g = o[u], S = g?.node;
485
+ if (!(!S || !ne(S)) && !(c && g?.experienceId !== c))
486
+ if (a.lastStepIndex === -1)
487
+ a.lastStepIndex = u;
489
488
  else {
490
- g.secondLastStepIndex = l;
489
+ a.secondLastStepIndex = u;
491
490
  break;
492
491
  }
493
492
  }
494
- return g;
493
+ return a;
495
494
  }
496
- return t.on(s, (p, u) => {
497
- const { secondLastStepIndex: g } = d(p.entries, u.experienceId), l = g !== -1 ? p.entries.slice(0, g + 1) : p.entries;
495
+ return t.on(s, (o, c) => {
496
+ const { secondLastStepIndex: a } = p(o.entries, c.experienceId), u = a !== -1 ? o.entries.slice(0, a + 1) : o.entries;
498
497
  return {
499
- ...p,
500
- entries: l
498
+ ...o,
499
+ entries: u
501
500
  };
502
501
  }), {
503
502
  push: e,
504
503
  replace: r,
505
504
  back: s,
506
- restore: i,
507
- entriesStore: t.map((p) => p.entries)
505
+ restore: n,
506
+ entriesStore: t.map((o) => o.entries)
508
507
  };
509
508
  });
510
509
  function Te() {
511
- return x(Ne);
510
+ return I(Ne);
512
511
  }
513
512
  let Le = 0;
514
513
  const _e = (t) => {
515
- const e = _([]);
516
- return w({
514
+ const e = T([]);
515
+ return k({
517
516
  clock: t,
518
517
  source: e,
519
518
  fn: (r, s) => [
@@ -526,409 +525,317 @@ const _e = (t) => {
526
525
  ],
527
526
  target: e
528
527
  }), e;
529
- }, U = F("field");
530
- function He(t) {
531
- return Array.isArray(t) && t.every(
532
- (e) => typeof e == "object" && e !== null && "id" in e && "label" in e && "value" in e
533
- );
534
- }
535
- function V(t, e) {
536
- const r = e ?? {
537
- status: "idle",
538
- options: Array.isArray(t.options) ? t.options : null
539
- };
540
- return {
541
- ...t,
542
- ...r,
543
- options: r.options ?? (Array.isArray(t.options) ? t.options : null)
544
- };
545
- }
546
- const Ge = I(({ client: t }) => {
547
- const e = U.store({}), r = j(e, {
548
- register(n, o) {
528
+ }, He = x("field"), Ke = b(() => {
529
+ const t = He.store({}), e = j(t, {
530
+ register(a, u) {
549
531
  return {
550
- ...n,
551
- [o.field.id]: o.field
532
+ ...a,
533
+ [u.resolvedKey]: { ...u.field, key: u.resolvedKey }
552
534
  };
553
535
  }
554
536
  });
555
- function s(n) {
556
- r.register({ field: n });
537
+ function r(a) {
538
+ e.register({ field: a, resolvedKey: a.key });
557
539
  }
558
- function i(n, o) {
559
- const a = e.getState()[n];
560
- if (!a)
540
+ function s(a, u) {
541
+ const g = p(a).getState();
542
+ if (!g)
561
543
  return;
562
- const f = Object.assign({}, a, {
563
- ...o
544
+ const S = Object.assign({}, g, {
545
+ ...u
564
546
  });
565
- r.register({ field: { ...f } });
547
+ e.register({ field: { ...S }, resolvedKey: a });
566
548
  }
567
- const d = U.store({}), p = A(
568
- e,
569
- d,
570
- (n, o) => Object.values(n).map((a) => V(a, o[a.id]))
571
- );
572
- function u(n) {
573
- return A(e, d, (o, a) => {
574
- const f = o[n];
575
- return f ? V(f, a[n]) : null;
576
- });
549
+ const n = t.map((a) => Object.values(a));
550
+ function p(a) {
551
+ return t.map((u) => u[a] || null);
577
552
  }
578
- function g(n) {
579
- return A(e, d, (o, a) => {
580
- const f = Object.values(o).find((v) => v.name === n);
581
- return f ? V(f, a[f.id]) : null;
582
- });
553
+ function o(a) {
554
+ return t.map((u) => Object.values(u).find((g) => g.id === a) || null);
583
555
  }
584
- const l = U.effect(
585
- async ({
586
- fieldId: n,
587
- fieldOptions: o,
588
- context: a
589
- }) => {
590
- if (t && !Array.isArray(o) && o !== null) {
591
- const f = await E(t, o, a);
592
- return He(f) ? { fieldId: n, options: f } : { fieldId: n, options: null };
593
- }
594
- return { fieldId: n, options: Array.isArray(o) ? o : null };
595
- }
596
- );
597
- d.on(l, (n, { fieldId: o }) => {
598
- const a = n[o];
599
- return {
600
- ...n,
601
- [o]: {
602
- status: "loading",
603
- // Preserve stale options during re-fetch so the UI doesn't flash blank
604
- options: a?.status === "resolved" ? a.options : null
605
- }
606
- };
607
- }), d.on(l.doneData, (n, { fieldId: o, options: a }) => ({
608
- ...n,
609
- [o]: { status: "resolved", options: a }
610
- })), d.on(l.fail, (n, { params: { fieldId: o } }) => ({
611
- ...n,
612
- [o]: { status: "error", options: null, error: "Failed to resolve field options" }
613
- }));
614
- const m = $();
615
- d.on(m, (n, o) => ({
616
- ...n,
617
- [o]: { status: "waiting", options: null }
618
- }));
619
- const h = $();
620
- t && w({
621
- clock: h,
622
- source: {
623
- states: d,
624
- fields: e
625
- },
626
- filter: ({ states: n }, { fieldId: o, force: a }) => {
627
- if (a) return !0;
628
- const f = n[o];
629
- return !f || f.status === "idle";
630
- },
631
- fn: ({ fields: n }, { fieldId: o, context: a }) => {
632
- const f = n[o] ?? null;
633
- return {
634
- fieldId: o,
635
- fieldOptions: f?.options ?? null,
636
- context: a
637
- };
638
- },
639
- target: l
640
- });
641
- function y(n, o) {
642
- h({ fieldId: n, force: o?.force, context: o?.context });
643
- }
644
- function c(n, o) {
645
- for (const a of n)
646
- h({ fieldId: a, force: o?.force, context: o?.context });
556
+ function c(a) {
557
+ return t.map((u) => Object.values(u).find((g) => g.name === a) || null);
647
558
  }
648
559
  return {
649
- register: s,
650
- update: i,
651
- getById: u,
652
- listStore: p,
653
- getByName: g,
654
- resolve: y,
655
- resolveAll: c,
656
- setWaiting: m
560
+ register: r,
561
+ update: s,
562
+ getByKey: p,
563
+ getById: o,
564
+ listStore: n,
565
+ getByName: c
657
566
  };
658
567
  });
659
- function Je(t) {
660
- return x(Ge, t ?? {});
568
+ function Ge() {
569
+ return I(Ke);
661
570
  }
662
- const qe = (t, e) => {
571
+ const Je = (t, e) => {
663
572
  e.register(t);
664
- }, Ke = F("action"), We = I(({ client: t }) => {
665
- const e = Ke.store({}), r = j(e, {
666
- register(u, g) {
573
+ }, qe = x("action"), We = b(() => {
574
+ const t = qe.store({}), e = j(t, {
575
+ register(o, c) {
667
576
  return {
668
- ...u,
669
- [g.name]: {
670
- name: g.name,
671
- action: g.action
577
+ ...o,
578
+ [c.name]: {
579
+ name: c.name,
580
+ action: c.action
672
581
  }
673
582
  };
674
583
  }
675
584
  });
676
- function s(u, g) {
677
- r.register({ name: u, action: g });
585
+ function r(o, c) {
586
+ e.register({ name: o, action: c });
678
587
  }
679
- const i = e.map((u) => Object.values(u));
680
- function d(u) {
681
- return e.map((g) => g[u], { skipVoid: !1 });
588
+ const s = t.map((o) => Object.values(o));
589
+ function n(o) {
590
+ return t.map((c) => c[o], { skipVoid: !1 });
682
591
  }
683
- function p(u) {
684
- return e.map(
685
- (g) => {
686
- const l = g[u];
687
- return l ? l.action : void 0;
592
+ function p(o) {
593
+ return t.map(
594
+ (c) => {
595
+ const a = c[o];
596
+ return a ? a.action : void 0;
688
597
  },
689
598
  { skipVoid: !1 }
690
599
  );
691
600
  }
692
601
  return {
693
- register: s,
694
- getByName: d,
695
- listStore: i,
602
+ register: r,
603
+ getByName: n,
604
+ listStore: s,
696
605
  getEvokableAction: p
697
606
  };
698
607
  });
699
- function Ye(t) {
700
- return x(We, t);
608
+ function Ye() {
609
+ return I(We);
701
610
  }
702
611
  const Qe = (t, e, r) => {
703
612
  r.register(t, e);
704
613
  };
705
- function N(t) {
614
+ function M(t) {
706
615
  return typeof t > "u" || t === null || t === "" || Array.isArray(t) && !t.length;
707
616
  }
708
617
  function Xe(t) {
709
618
  return typeof t == "string" || typeof t == "number" || typeof t == "boolean" || t === null;
710
619
  }
711
- function Y(t) {
620
+ function q(t) {
712
621
  try {
713
622
  return JSON.stringify(t), !0;
714
623
  } catch {
715
624
  return !1;
716
625
  }
717
626
  }
718
- const Ze = F("response"), et = I(({ client: t }) => {
719
- const e = Ze.store({}), r = $(), s = $(), i = j(e, {
720
- register(y, c) {
627
+ const Ze = x("response"), et = b(({ client: t }) => {
628
+ const e = Ze.store({}), r = V(), s = V(), n = j(e, {
629
+ register(m, i) {
721
630
  return {
722
- ...y,
723
- [c.fieldId]: c.response
631
+ ...m,
632
+ [i.fieldId]: i.response
724
633
  };
725
634
  },
726
- registerBatch(y, c) {
635
+ registerBatch(m, i) {
727
636
  return {
728
- ...y,
729
- ...c
637
+ ...m,
638
+ ...i
730
639
  };
731
640
  },
732
- clear(y, c) {
733
- const { [c]: n, ...o } = y;
734
- return o;
641
+ clear(m, i) {
642
+ const { [i]: d, ...f } = m;
643
+ return f;
735
644
  },
736
645
  clearAll() {
737
646
  return {};
738
647
  }
739
648
  });
740
- function d(y, c) {
741
- if (typeof y == "string") {
742
- if (c === void 0)
649
+ function p(m, i) {
650
+ if (typeof m == "string") {
651
+ if (i === void 0)
743
652
  throw new Error("Response is required when registering a single field");
744
- i.register({ fieldId: y, response: c });
653
+ n.register({ fieldId: m, response: i });
745
654
  } else
746
- i.registerBatch(y);
655
+ n.registerBatch(m);
747
656
  }
748
- async function p(y) {
749
- const c = [];
657
+ async function o(m) {
658
+ const i = [];
750
659
  return await Promise.allSettled(
751
- // eslint-disable-next-line sonarjs/cognitive-complexity -- comprehensive validation logic; refactoring would harm readability
752
- Object.entries(y).map(async ([n, o]) => {
753
- let a = o;
754
- const f = t.fields.getById(n).getState();
755
- if (!f) {
756
- c.push({
757
- fieldId: n,
758
- userMessage: `Field '${n}' not found`,
759
- systemMessage: `No field with ID '${n}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
760
- value: a
660
+ // eslint-disable-next-line sonarjs/cognitive-complexity -- validation covers all field types, options, and JSON-serializability; splitting would obscure intent
661
+ Object.entries(m).map(async ([d, f]) => {
662
+ let l = f;
663
+ const h = t.fields.getByKey(d).getState();
664
+ if (!h) {
665
+ i.push({
666
+ fieldId: d,
667
+ userMessage: `Field '${d}' not found`,
668
+ systemMessage: `No field with ID '${d}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
669
+ value: l
761
670
  });
762
671
  return;
763
672
  }
764
- if (f.multiple && (typeof a == "string" || typeof a == "number" || typeof a == "boolean") && (a = [a]), f.validation && !de(f.validation) && !N(a)) {
765
- const v = { ...e.getState(), ...y }, S = await E(t, f.validation, {
766
- $input: a,
767
- responses: v
673
+ if (h.multiple && (typeof l == "string" || typeof l == "number" || typeof l == "boolean") && (l = [l]), h.validation && !de(h.validation) && !M(l)) {
674
+ const y = await P(t, h.validation, {
675
+ $input: l
768
676
  });
769
- if (typeof S == "string") {
770
- c.push({
771
- fieldId: n,
772
- userMessage: S,
773
- systemMessage: `Field validation resulted in an error: ${S}.`,
774
- value: a
677
+ if (typeof y == "string") {
678
+ i.push({
679
+ fieldId: d,
680
+ userMessage: y,
681
+ systemMessage: `Field validation resulted in an error: ${y}.`,
682
+ value: l
775
683
  });
776
684
  return;
777
685
  }
778
- if (S === !1) {
779
- c.push({
780
- fieldId: n,
686
+ if (y === !1) {
687
+ i.push({
688
+ fieldId: d,
781
689
  userMessage: "This field is invalid",
782
690
  systemMessage: "Field validation resulted in an unspecified error.",
783
- value: a
691
+ value: l
784
692
  });
785
693
  return;
786
694
  }
787
695
  }
788
- if (f.required && N(a)) {
789
- c.push({
790
- fieldId: n,
696
+ if (h.required && M(l)) {
697
+ i.push({
698
+ fieldId: d,
791
699
  userMessage: "This field is required",
792
700
  systemMessage: "Field is required.",
793
- value: a
701
+ value: l
794
702
  });
795
703
  return;
796
704
  }
797
- if (!f.multiple && Array.isArray(a) && a.length > 1) {
798
- c.push({
799
- fieldId: n,
705
+ if (!h.multiple && Array.isArray(l) && l.length > 1) {
706
+ i.push({
707
+ fieldId: d,
800
708
  userMessage: "This field expects a single response",
801
709
  systemMessage: "Field expects a single response.",
802
- value: a
710
+ value: l
803
711
  });
804
712
  return;
805
713
  }
806
- if (f.type === "object" && !N(a))
807
- if (f.multiple) {
808
- if (!Array.isArray(a)) {
809
- c.push({
810
- fieldId: n,
714
+ if (h.type === "object" && !M(l))
715
+ if (h.multiple) {
716
+ if (!Array.isArray(l)) {
717
+ i.push({
718
+ fieldId: d,
811
719
  userMessage: "This field expects multiple values",
812
720
  systemMessage: "Field expects an array of objects.",
813
- value: a
721
+ value: l
814
722
  });
815
723
  return;
816
724
  }
817
- for (const v of a) {
818
- if (typeof v != "object" || v === null) {
819
- c.push({
820
- fieldId: n,
725
+ for (const y of l) {
726
+ if (typeof y != "object" || y === null) {
727
+ i.push({
728
+ fieldId: d,
821
729
  userMessage: "This field expects object values",
822
730
  systemMessage: "Field expects an array of objects, but received non-object value.",
823
- value: a
731
+ value: l
824
732
  });
825
733
  return;
826
734
  }
827
- if (!Y(v)) {
828
- c.push({
829
- fieldId: n,
735
+ if (!q(y)) {
736
+ i.push({
737
+ fieldId: d,
830
738
  userMessage: "This field contains non-serializable data",
831
739
  systemMessage: "Field value contains non-JSON-serializable data (functions, circular references, etc.).",
832
- value: a
740
+ value: l
833
741
  });
834
742
  return;
835
743
  }
836
744
  }
837
745
  } else {
838
- if (Array.isArray(a)) {
839
- c.push({
840
- fieldId: n,
746
+ if (Array.isArray(l)) {
747
+ i.push({
748
+ fieldId: d,
841
749
  userMessage: "This field expects a single value",
842
750
  systemMessage: "Field expects a single object, not an array.",
843
- value: a
751
+ value: l
844
752
  });
845
753
  return;
846
754
  }
847
- if (typeof a != "object" || a === null) {
848
- c.push({
849
- fieldId: n,
755
+ if (typeof l != "object" || l === null) {
756
+ i.push({
757
+ fieldId: d,
850
758
  userMessage: "This field expects an object value",
851
759
  systemMessage: "Field expects an object value.",
852
- value: a
760
+ value: l
853
761
  });
854
762
  return;
855
763
  }
856
- if (!Y(a)) {
857
- c.push({
858
- fieldId: n,
764
+ if (!q(l)) {
765
+ i.push({
766
+ fieldId: d,
859
767
  userMessage: "This field contains non-serializable data",
860
768
  systemMessage: "Field value contains non-JSON-serializable data (functions, circular references, etc.).",
861
- value: a
769
+ value: l
862
770
  });
863
771
  return;
864
772
  }
865
773
  }
866
- if (Array.isArray(f.options) && f.options.length > 0) {
867
- const v = Array.isArray(a) ? a : [a];
868
- if (f.type === "object") {
869
- const S = f.options.map((k) => JSON.stringify(k.value));
870
- v.every((k) => S.includes(JSON.stringify(k))) || c.push({
871
- fieldId: n,
774
+ if (Array.isArray(h.options) && h.options.length > 0) {
775
+ const y = Array.isArray(l) ? l : [l];
776
+ if (h.type === "object") {
777
+ const F = h.options.map((v) => JSON.stringify(v.value));
778
+ y.every((v) => F.includes(JSON.stringify(v))) || i.push({
779
+ fieldId: d,
872
780
  userMessage: "This field expects a valid option",
873
781
  systemMessage: "Field expects a valid option from the defined choices.",
874
- value: a
782
+ value: l
875
783
  });
876
784
  } else {
877
- const S = f.options.map((k) => k.value);
878
- v.every((k) => !Xe(k) || k === null ? !1 : S.includes(k)) || c.push({
879
- fieldId: n,
785
+ const F = h.options.map((v) => v.value);
786
+ y.every((v) => !Xe(v) || v === null ? !1 : F.includes(v)) || i.push({
787
+ fieldId: d,
880
788
  userMessage: "This field expects a valid option",
881
- systemMessage: `Field expects a valid option. Valid options are: ${S.join(", ")}`,
882
- value: a
789
+ systemMessage: `Field expects a valid option. Valid options are: ${F.join(", ")}`,
790
+ value: l
883
791
  });
884
792
  }
885
793
  }
886
794
  })
887
- ), { responsesToCommit: y, validationErrors: c };
795
+ ), { responsesToCommit: m, validationErrors: i };
888
796
  }
889
- async function u(y) {
890
- const { responsesToCommit: c, validationErrors: n } = await p(y);
891
- return n.length ? { errors: n } : (i.registerBatch(c), { errors: [] });
797
+ async function c(m) {
798
+ const { responsesToCommit: i, validationErrors: d } = await o(m);
799
+ return d.length ? { errors: d } : (n.registerBatch(i), { errors: [] });
892
800
  }
893
- const g = e.map((y) => y), l = e.map((y) => Object.keys(y).map((n) => ({
894
- fieldId: n,
895
- value: y[n]
801
+ const a = e.map((m) => m), u = e.map((m) => Object.keys(m).map((d) => ({
802
+ fieldId: d,
803
+ value: m[d]
896
804
  })));
897
- function m(y) {
898
- const c = t.fields.getById(y), n = e.map((o) => o[y] || null);
899
- return A({ f: c, r: n }, ({ f: o, r: a }) => a || (o?.defaultValue ? o.defaultValue : null));
805
+ function g(m) {
806
+ const i = t.fields.getByKey(m), d = e.map((f) => f[m] || null);
807
+ return D({ f: i, r: d }, ({ f, r: l }) => l || (f?.defaultValue ? f.defaultValue : null));
900
808
  }
901
- function h(y) {
902
- const c = t.fields.getByName(y);
903
- return A({ f: c, s: e }, ({ f: n, s: o }) => {
904
- const a = n && o[n.id] || null;
905
- return a || (n?.defaultValue ? n.defaultValue : null);
809
+ function S(m) {
810
+ const i = t.fields.getByName(m);
811
+ return D({ f: i, s: e }, ({ f: d, s: f }) => {
812
+ const l = d && f[d.key ?? le(d.name)] || null;
813
+ return l || (d?.defaultValue ? d.defaultValue : null);
906
814
  });
907
815
  }
908
- return w({
816
+ return k({
909
817
  clock: r,
910
- target: i.clearAll
911
- }), w({
818
+ target: n.clearAll
819
+ }), k({
912
820
  clock: s,
913
- target: i.clear
821
+ target: n.clear
914
822
  }), {
915
- register: d,
823
+ register: p,
916
824
  clearAll: r,
917
825
  clear: s,
918
- commit: u,
919
- getResponsesToCommit: p,
920
- listStore: l,
921
- getAllStore: g,
922
- getByFieldId: m,
923
- getByFieldName: h
826
+ commit: c,
827
+ getResponsesToCommit: o,
828
+ listStore: u,
829
+ getAllStore: a,
830
+ getByFieldId: g,
831
+ getByFieldName: S
924
832
  };
925
833
  });
926
834
  function tt(t) {
927
- return x(et, t);
835
+ return I(et, t);
928
836
  }
929
- const rt = () => "0.0.1-dev.1772412203098";
930
- function nt() {
931
- if (H()) {
837
+ function rt() {
838
+ if (L()) {
932
839
  const t = [
933
840
  document.currentScript,
934
841
  document.getElementById("picked_script"),
@@ -943,69 +850,69 @@ function nt() {
943
850
  return "https://api.picked.app";
944
851
  }
945
852
  function st() {
946
- if (!G())
853
+ if (!_())
947
854
  return {};
948
855
  const t = new URLSearchParams(window.location.search), e = {}, r = /* @__PURE__ */ new Set();
949
- for (const [i] of t.entries())
950
- i.startsWith("picked-") && r.add(i);
951
- for (const i of r) {
952
- const d = i.replace("picked-", "");
953
- e[d] = t.getAll(i);
856
+ for (const [n] of t.entries())
857
+ n.startsWith("picked-") && r.add(n);
858
+ for (const n of r) {
859
+ const p = n.replace("picked-", "");
860
+ e[p] = t.getAll(n);
954
861
  }
955
- const s = R("s");
862
+ const s = A("s");
956
863
  if (r.size > 0)
957
- D.set(s, e);
864
+ O.set(s, e);
958
865
  else {
959
- const i = D.get(s);
960
- if (i)
961
- return i.json() || {};
866
+ const n = O.get(s);
867
+ if (n)
868
+ return n.json() || {};
962
869
  }
963
870
  return e;
964
871
  }
965
- function it() {
872
+ function nt() {
966
873
  if (fe())
967
874
  return crypto.randomUUID();
968
875
  const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), r = Math.random().toString(36).substring(2, 15), s = Math.random().toString(36).substring(2, 15);
969
876
  return `${t}-${e}-${r}-${s}`;
970
877
  }
971
- const ot = R("session", "global"), at = () => {
972
- const t = O.get(ot);
878
+ const it = A("session", "global"), ot = () => {
879
+ const t = C.get(it);
973
880
  let e;
974
881
  t.isSet() && (e = t.json());
975
- const r = (i) => t.set({
976
- id: i.id,
977
- isUser: i.isUser,
978
- identifiers: i.identifiers
882
+ const r = (n) => t.set({
883
+ id: n.id,
884
+ isUser: n.isUser,
885
+ identifiers: n.identifiers
979
886
  }), s = {
980
- id: e?.id ?? it(),
887
+ id: e?.id ?? nt(),
981
888
  isUser: e?.isUser ?? void 0,
982
889
  identifiers: e?.identifiers ?? void 0,
983
- setIsUser(i) {
984
- this.isUser = i, r(this);
890
+ setIsUser(n) {
891
+ this.isUser = n, r(this);
985
892
  },
986
- setIdentifier(i, d) {
987
- this.identifiers = { ...this.identifiers, [i]: d }, r(this);
893
+ setIdentifier(n, p) {
894
+ this.identifiers = { ...this.identifiers, [n]: p }, r(this);
988
895
  },
989
- removeIdentifier(i) {
896
+ removeIdentifier(n) {
990
897
  this.identifiers && (this.identifiers = Object.fromEntries(
991
- Object.entries(this.identifiers).filter(([d]) => d !== i)
898
+ Object.entries(this.identifiers).filter(([p]) => p !== n)
992
899
  ), this.identifiers = Object.keys(this.identifiers).length ? this.identifiers : void 0, r(this));
993
900
  }
994
901
  };
995
902
  return r(s), s;
996
- }, ct = () => pe() ? at() : null;
997
- function ut() {
998
- if (G())
903
+ }, at = () => pe() ? ot() : null;
904
+ function ct() {
905
+ if (_())
999
906
  return globalThis.window.pickedConfig;
1000
907
  }
1001
- function lt() {
1002
- if (!G())
908
+ function ut() {
909
+ if (!_())
1003
910
  return;
1004
- const t = ut(), e = t?.organizationId, r = t?.projectId;
911
+ const t = ct(), e = t?.organizationId, r = t?.projectId;
1005
912
  return e && r ? { organizationId: e, projectId: r } : void 0;
1006
913
  }
1007
914
  function dt() {
1008
- if (!H())
915
+ if (!L())
1009
916
  return;
1010
917
  const t = document.getElementById("picked_script") || document.querySelector("script#picked") || // legacy support for 'cvly' script tag
1011
918
  document.getElementById("cvly");
@@ -1014,16 +921,16 @@ function dt() {
1014
921
  const e = t.dataset.organizationid || t.getAttribute("organization-id"), r = t.dataset.projectid || t.getAttribute("project-id");
1015
922
  return e && r ? { organizationId: e, projectId: r } : void 0;
1016
923
  }
1017
- function pt(t) {
924
+ function lt(t) {
1018
925
  const { organizationId: e, projectId: r } = t;
1019
926
  if (e && r)
1020
927
  return { organizationId: e, projectId: r };
1021
- const s = lt();
928
+ const s = ut();
1022
929
  if (s)
1023
930
  return s;
1024
- const i = dt();
1025
- if (i)
1026
- return i;
931
+ const n = dt();
932
+ if (n)
933
+ return n;
1027
934
  throw new Error(
1028
935
  `organizationId and projectId are required. You can provide them via one of:
1029
936
  (1) createClient({ organizationId, projectId }) options;
@@ -1031,13 +938,13 @@ function pt(t) {
1031
938
  (3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`
1032
939
  );
1033
940
  }
1034
- function M(t) {
941
+ function z(t) {
1035
942
  return t == null || t === "" || Number.isNaN(t);
1036
943
  }
1037
- const ft = {
1038
- default: (t, e) => M(t) ? String(e ?? "") : String(t),
1039
- append: (t, e) => e && !M(t) ? `${t} ${e}` : t,
1040
- prepend: (t, e) => e && !M(t) ? `${e} ${t}` : t,
944
+ const pt = {
945
+ default: (t, e) => z(t) ? String(e ?? "") : String(t),
946
+ append: (t, e) => e && !z(t) ? `${t} ${e}` : t,
947
+ prepend: (t, e) => e && !z(t) ? `${e} ${t}` : t,
1041
948
  upper: (t) => typeof t == "string" ? t.toUpperCase() : t,
1042
949
  lower: (t) => typeof t == "string" ? t.toLowerCase() : t,
1043
950
  capitalize: (t) => typeof t == "string" ? t.charAt(0).toUpperCase() + t.slice(1) : t,
@@ -1048,59 +955,59 @@ const ft = {
1048
955
  if (Array.isArray(t))
1049
956
  return e.format(t.map(String));
1050
957
  if (t instanceof Map) {
1051
- const r = Array.from(t.entries()).map(([s, i]) => `${s}: ${i}`);
958
+ const r = Array.from(t.entries()).map(([s, n]) => `${s}: ${n}`);
1052
959
  return e.format(r);
1053
960
  }
1054
961
  return t instanceof Set ? e.format(Array.from(t).map(String)) : t;
1055
962
  }
1056
963
  };
1057
- function gt(t) {
964
+ function ft(t) {
1058
965
  return typeof t == "object" && t !== null;
1059
966
  }
1060
- function mt(t, e) {
967
+ function gt(t, e) {
1061
968
  let r = e;
1062
969
  for (const s of t.split("."))
1063
- if (gt(r) && s in r)
970
+ if (ft(r) && s in r)
1064
971
  r = r[s];
1065
972
  else
1066
973
  return;
1067
974
  return typeof r == "function" ? r() : r;
1068
975
  }
1069
- function yt(t, e) {
1070
- const r = t.split("|").map((d) => d.trim()), s = r.shift() ?? "";
1071
- let i = mt(s, e);
1072
- for (const d of r) {
1073
- const [p, ...u] = d.split(":"), g = p?.trim() ?? "", l = u.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), m = ft[g];
1074
- m && (i = m(i, l));
976
+ function mt(t, e) {
977
+ const r = t.split("|").map((p) => p.trim()), s = r.shift() ?? "";
978
+ let n = gt(s, e);
979
+ for (const p of r) {
980
+ const [o, ...c] = p.split(":"), a = o?.trim() ?? "", u = c.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), g = pt[a];
981
+ g && (n = g(n, u));
1075
982
  }
1076
- return M(i) ? "" : typeof i == "object" ? JSON.stringify(i) : String(i);
983
+ return z(n) ? "" : typeof n == "object" ? JSON.stringify(n) : String(n);
1077
984
  }
1078
985
  function ht(t, e) {
1079
986
  let r = "", s = 0;
1080
987
  for (; s < t.length; )
1081
988
  if (t[s] === "{" && t[s + 1] === "{") {
1082
989
  s += 2;
1083
- let i = "";
990
+ let n = "";
1084
991
  for (; s < t.length; ) {
1085
992
  if (t[s] === "}" && t[s + 1] === "}") {
1086
993
  s += 2;
1087
994
  break;
1088
995
  }
1089
- i += t[s++];
996
+ n += t[s++];
1090
997
  }
1091
- r += yt(i.trim(), e);
998
+ r += mt(n.trim(), e);
1092
999
  } else
1093
1000
  r += t[s++];
1094
1001
  return r;
1095
1002
  }
1096
- class vt {
1097
- static logger = b;
1003
+ class yt {
1004
+ static logger = w;
1098
1005
  options;
1099
1006
  isReady = !1;
1100
1007
  project;
1101
1008
  plugins = {};
1102
1009
  pluginStartHooks = [];
1103
- eventBus = $();
1010
+ eventBus = V();
1104
1011
  events;
1105
1012
  organizationId;
1106
1013
  projectId;
@@ -1110,46 +1017,48 @@ class vt {
1110
1017
  session;
1111
1018
  precondition;
1112
1019
  condition;
1020
+ preconditionPassed;
1113
1021
  searchParams = st();
1114
1022
  history = Te();
1115
- components = Fe({ client: this });
1116
- experienceInstances = ae({ client: this });
1117
- experiences = ve({ client: this });
1118
- frameworks = Ee({ client: this });
1119
- predicates = Me({ client: this });
1120
- features = Ue({ client: this });
1023
+ components = xe({ client: this });
1024
+ experienceInstances = ie({ client: this });
1025
+ experiences = Se({ client: this });
1026
+ frameworks = Pe({ client: this });
1027
+ predicates = Oe({ client: this });
1028
+ features = De({ client: this });
1121
1029
  responses = tt({ client: this });
1122
- fields = Je({ client: this });
1123
- actions = Ye({ client: this });
1030
+ fields = Ge();
1031
+ actions = Ye();
1124
1032
  constructor(e) {
1125
- b("info", "Picked client initializing."), this.events = _e(this.eventBus);
1126
- const { organizationId: r, projectId: s } = pt(e);
1127
- this.organizationId = r, this.projectId = s, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || nt(), this.dashboardUrl = e.dashboardUrl ?? "https://dashboard.picked.app", this.documentationSiteUrl = e.documentationSiteUrl ?? "https://docs.picked.app", this.session = ct(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: rt() }), b("info", "Picked client initialized.");
1033
+ w("info", "Picked client initializing."), this.events = _e(this.eventBus);
1034
+ const { organizationId: r, projectId: s } = lt(e);
1035
+ this.organizationId = r, this.projectId = s, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || rt(), this.dashboardUrl = e.dashboardUrl ?? "https://dashboard.picked.app", this.documentationSiteUrl = e.documentationSiteUrl ?? "https://docs.picked.app", this.session = at(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.setupComponents(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: ce() }), w("info", "Picked client initialized.");
1128
1036
  }
1129
1037
  start = () => {
1130
- Be(this), (async () => {
1131
- if (!H())
1038
+ Re(this), (async () => {
1039
+ if (!L())
1132
1040
  return;
1133
1041
  await this.runPluginStartHooks();
1134
1042
  const r = await this.evaluateGate(this.precondition);
1043
+ this.preconditionPassed = r;
1135
1044
  let s;
1136
1045
  r && (s = await this.evaluateGate(this.condition));
1137
- const i = r && s === !0;
1046
+ const n = r && s === !0;
1138
1047
  if (typeof s == "boolean" && this.session) {
1139
- const d = s;
1140
- this.session.setIsUser(d), this.eventBus({ type: "user_decide", value: d });
1048
+ const p = s;
1049
+ this.session.setIsUser(p), this.eventBus({ type: "user_decide", value: p });
1141
1050
  }
1142
- if (this.eventBus({ type: "initialize" }), i && J(this), await ce(), i && J(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session) {
1143
- const { id: d, isUser: p, identifiers: u } = this.session;
1144
- this.eventBus({ type: "session", id: d, isUser: p, identifiers: u });
1051
+ if (this.eventBus({ type: "initialize" }), n && H(this), await oe(), n && H(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session) {
1052
+ const { id: p, isUser: o, identifiers: c } = this.session;
1053
+ this.eventBus({ type: "session", id: p, isUser: o, identifiers: c });
1145
1054
  }
1146
1055
  })();
1147
1056
  };
1148
1057
  registerFramework = (e) => {
1149
- Pe(e, this.frameworks);
1058
+ Ae(e, this.frameworks);
1150
1059
  };
1151
1060
  registerComponent = (e, r) => {
1152
- q(e, r, this.components);
1061
+ K(e, r, this.components);
1153
1062
  };
1154
1063
  registerPlugin = (e) => {
1155
1064
  ke(this, e, this.plugins);
@@ -1160,18 +1069,18 @@ class vt {
1160
1069
  Ve(e, r, this.features);
1161
1070
  };
1162
1071
  registerPredicate = (e, r) => {
1163
- Oe(e, r, this.predicates);
1072
+ Me(e, r, this.predicates);
1164
1073
  };
1165
1074
  registerField = (e) => {
1166
- qe(e, this.fields);
1075
+ Je(e, this.fields);
1167
1076
  };
1168
1077
  registerAction = (e, r) => {
1169
1078
  Qe(e, r, this.actions);
1170
1079
  };
1171
1080
  registerExperience = (e) => {
1172
- e.component && q(`experience:${e.id}`, e.component, this.components), Se(e, this.experiences);
1081
+ e.component && K(`experience:${e.id}`, e.component, this.components), ve(e, this.experiences);
1173
1082
  };
1174
- getStateSnapshot = () => ee(this);
1083
+ getStateSnapshot = () => X(this);
1175
1084
  /** @deprecated Use `client.experiences.launch({ id: experienceId })` instead. */
1176
1085
  launchExperienceById = async (e, r) => {
1177
1086
  this.experiences.launch({ id: e, options: r });
@@ -1185,7 +1094,7 @@ class vt {
1185
1094
  await e();
1186
1095
  }
1187
1096
  async evaluateGate(e) {
1188
- return e === void 0 ? !0 : typeof e == "boolean" ? e : await E(this, e) === !0;
1097
+ return e === void 0 ? !0 : typeof e == "boolean" ? e : await P(this, e) === !0;
1189
1098
  }
1190
1099
  setupPlugins() {
1191
1100
  this.options.plugins?.forEach((e) => {
@@ -1206,20 +1115,20 @@ class vt {
1206
1115
  setupFeatures() {
1207
1116
  const e = this.options.features;
1208
1117
  e && (Object.entries(e).forEach(([r, s]) => {
1209
- const i = typeof s == "function" ? s() : s;
1210
- this.registerFeature(r, i);
1118
+ const n = typeof s == "function" ? s() : s;
1119
+ this.registerFeature(r, n);
1211
1120
  }), this.searchParams.feature && this.searchParams.feature.forEach((r) => {
1212
1121
  try {
1213
- const [s, i] = r.split(":");
1214
- if (!s || !i)
1122
+ const [s, n] = r.split(":");
1123
+ if (!s || !n)
1215
1124
  return;
1216
- let d = i;
1217
- d === "true" && (d = !0), d === "false" && (d = !1), this.registerFeature(s, {
1218
- key: `${d}`,
1125
+ let p = n;
1126
+ p === "true" && (p = !0), p === "false" && (p = !1), this.registerFeature(s, {
1127
+ key: `${p}`,
1219
1128
  // use the assigned bucket value as the key
1220
1129
  name: s,
1221
1130
  // eslint-disable-next-line sonarjs/function-return-type
1222
- decide: () => d,
1131
+ decide: () => p,
1223
1132
  storage: "session"
1224
1133
  });
1225
1134
  } catch {
@@ -1230,7 +1139,7 @@ class vt {
1230
1139
  const e = this.options.predicates;
1231
1140
  e && Object.entries(e).forEach(([r, s]) => {
1232
1141
  if (typeof s != "function") {
1233
- b("warn", `Predicate "${r}" is not a function.`);
1142
+ w("warn", `Predicate "${r}" is not a function.`);
1234
1143
  return;
1235
1144
  }
1236
1145
  this.registerPredicate(r, s);
@@ -1240,12 +1149,18 @@ class vt {
1240
1149
  const e = this.options.actions;
1241
1150
  e && Object.entries(e).forEach(([r, s]) => {
1242
1151
  if (typeof s != "function") {
1243
- b("warn", `Action "${r}" is not a function.`);
1152
+ w("warn", `Action "${r}" is not a function.`);
1244
1153
  return;
1245
1154
  }
1246
1155
  this.registerAction(r, s);
1247
1156
  });
1248
1157
  }
1158
+ setupComponents() {
1159
+ const e = this.options.components;
1160
+ e && Object.entries(e).forEach(([r, s]) => {
1161
+ this.registerComponent(r, s);
1162
+ });
1163
+ }
1249
1164
  getPluginConfig = (e) => this.plugins[e] ?? {};
1250
1165
  /**
1251
1166
  * Interpolates a template string using values from the client's response store and/or a provided context.
@@ -1290,32 +1205,32 @@ class vt {
1290
1205
  * // => "Fruits: apple, banana, and cherry"
1291
1206
  */
1292
1207
  renderString = (e, r) => {
1293
- const s = this.responses.listStore.getState().reduce((i, d) => (i[d.fieldId] = d.value, i), {});
1208
+ const s = this.responses.listStore.getState().reduce((n, p) => (n[p.fieldId] = p.value, n), {});
1294
1209
  return ht(e, {
1295
1210
  ...r,
1296
1211
  responses: s
1297
1212
  });
1298
1213
  };
1299
1214
  }
1300
- function te(t) {
1301
- return Array.isArray(t.options) && t.options.some((e) => "condition" in e);
1215
+ function Z(t) {
1216
+ return t.options?.some((e) => "condition" in e) ?? !1;
1302
1217
  }
1303
1218
  function St(t) {
1304
- return t.some((e) => e.condition || te(e));
1219
+ return t.some((e) => e.condition || Z(e));
1305
1220
  }
1306
- async function Pt(t, e, r) {
1221
+ async function At(t, e) {
1307
1222
  return e.length === 0 || !St(e) ? e : (await Promise.all(
1308
- e.map(async (i) => {
1309
- if (!(i.condition ? await E(t, i.condition, r) : !0))
1223
+ e.map(async (s) => {
1224
+ if (!(s.condition ? await P(t, s.condition) : !0))
1310
1225
  return null;
1311
- if (!Array.isArray(i.options) || !te(i))
1312
- return i;
1313
- const u = (await Promise.all(
1314
- i.options.map(async (l) => l.condition ? await E(t, l.condition, r) ? l : null : l)
1315
- )).filter((l) => l !== null);
1316
- return u.length === i.options.length ? i : u.length === 0 ? null : { ...i, options: u };
1226
+ if (!s.options || !Z(s))
1227
+ return s;
1228
+ const o = (await Promise.all(
1229
+ s.options.map(async (a) => a.condition ? await P(t, a.condition) ? a : null : a)
1230
+ )).filter((a) => a !== null);
1231
+ return o.length === s.options.length ? s : o.length === 0 ? null : { ...s, options: o };
1317
1232
  })
1318
- )).filter((i) => i !== null);
1233
+ )).filter((s) => s !== null);
1319
1234
  }
1320
1235
  function $t(t) {
1321
1236
  return {
@@ -1323,35 +1238,35 @@ function $t(t) {
1323
1238
  load: t
1324
1239
  };
1325
1240
  }
1326
- function Rt(t) {
1241
+ function Bt(t) {
1327
1242
  return typeof t == "object" && t !== null && "$$type" in t && t.$$type === "lazy-component";
1328
1243
  }
1329
- const Bt = (t) => {
1330
- const e = new vt(t);
1244
+ const Rt = (t) => {
1245
+ const e = new yt(t);
1331
1246
  return ge(e), e;
1332
1247
  };
1333
1248
  export {
1334
- vt as Picked,
1335
- Bt as createClient,
1336
- R as createStorageKey,
1337
- E as evaluateRuleLogic,
1338
- ut as getPickedConfig,
1339
- Pt as getStepFields,
1340
- Rt as isLazyLoader,
1341
- Mt as isPickedRoot,
1249
+ yt as Picked,
1250
+ Rt as createClient,
1251
+ A as createStorageKey,
1252
+ P as evaluateRuleLogic,
1253
+ ct as getPickedConfig,
1254
+ At as getStepFields,
1255
+ Bt as isLazyLoader,
1256
+ Ot as isPickedRoot,
1342
1257
  $t as lazyComponent,
1343
- O as localStore,
1344
- D as sessionStore,
1345
- Dt as subscribe,
1258
+ C as localStore,
1259
+ O as sessionStore,
1260
+ Ut as subscribe,
1346
1261
  Vt as supportsCookies,
1347
1262
  fe as supportsCryptoRandomUUID,
1348
- H as supportsDocument,
1263
+ L as supportsDocument,
1349
1264
  Nt as supportsHistory,
1350
1265
  Tt as supportsIntersectionObserver,
1351
1266
  pe as supportsLocalStorage,
1352
1267
  Lt as supportsLocation,
1353
1268
  _t as supportsSessionStorage,
1354
1269
  Ht as supportsShadowRoot,
1355
- Gt as supportsWebComponents,
1356
- G as supportsWindow
1270
+ Kt as supportsWebComponents,
1271
+ _ as supportsWindow
1357
1272
  };