@picked/client 0.0.1-dev.1772083499814 → 0.0.1-dev.1772085077346

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