@picked/client 0.0.1-dev.1770181472896 → 0.0.1-dev.1770759602712

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