@picked/client 0.0.35 → 0.0.36-next.1

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