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

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