@picked/client 0.0.1-dev.1770849584797 → 0.0.1-dev.1771902850952

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