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

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