@picked/client 0.0.1-dev.1771981674305 → 0.0.1-dev.1772057362040

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