@picked/client 0.0.1-dev.1773729274420 → 0.0.1-dev.1773807602703

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