@picked/client 0.0.1-dev.1773724362573 → 0.0.1-dev.1773804563218

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