@picked/client 0.0.1-dev.1772493269328 → 0.0.1-dev.1773364848747

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