@picked/client 0.0.46 → 0.0.47-next.2

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