@picked/client 0.0.1-dev.1773368658489 → 0.0.1-dev.1773719715758

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