@picked/client 0.0.1-dev.1773365725739 → 0.0.1-dev.1773371977114

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