@picked/client 0.0.50 → 0.0.51-next.10

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 (130) hide show
  1. package/dist/api-CHy9HcU7.cjs +1 -0
  2. package/dist/{api-DWBcrf98.js → api-mlYS-lDj.js} +1 -1
  3. package/dist/cjs/form/index.js +1 -0
  4. package/dist/cjs/index.js +2 -2
  5. package/dist/cjs/plugins/create-experience/index.js +1 -1
  6. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  7. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  9. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  10. package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
  11. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  12. package/dist/cjs/server/index.js +1 -1
  13. package/dist/esm/form/index.js +472 -0
  14. package/dist/esm/index.js +473 -383
  15. package/dist/esm/plugins/create-experience/index.js +198 -165
  16. package/dist/esm/plugins/dynamic-experiences/index.js +52 -30
  17. package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
  18. package/dist/esm/plugins/history-browser-storage/index.js +1 -1
  19. package/dist/esm/plugins/responses-browser-storage/index.js +7 -9
  20. package/dist/esm/plugins/responses-indexeddb/index.js +11 -11
  21. package/dist/esm/plugins/single-page-app/index.js +4 -4
  22. package/dist/esm/server/index.js +1 -1
  23. package/dist/experience-instance-DOcd8XI1.cjs +1 -0
  24. package/dist/experience-instance-NHU1moID.js +486 -0
  25. package/dist/{object-Clj5zVr1.js → object-C82v79xc.js} +2 -1
  26. package/dist/object-CUJOjanb.cjs +1 -0
  27. package/dist/rules-logic-CnVktz2l.js +240 -0
  28. package/dist/rules-logic-nMHNVLn7.cjs +1 -0
  29. package/dist/{storage-DyxpJ0pg.js → storage-6Xk0uAxB.js} +3 -1
  30. package/dist/storage-B6lQtc4-.cjs +1 -0
  31. package/dist/types/client.d.ts +47 -43
  32. package/dist/types/client.d.ts.map +1 -1
  33. package/dist/types/entities/action/action.d.ts +37 -5
  34. package/dist/types/entities/action/action.d.ts.map +1 -1
  35. package/dist/types/entities/condition/condition.d.ts +20 -0
  36. package/dist/types/entities/condition/condition.d.ts.map +1 -0
  37. package/dist/types/entities/experience/experience.d.ts +67 -51
  38. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  39. package/dist/types/entities/experience-instance/experience-instance.d.ts +22 -2
  40. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  41. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  42. package/dist/types/entities/field/field.d.ts +24 -10
  43. package/dist/types/entities/field/field.d.ts.map +1 -1
  44. package/dist/types/entities/history/history.d.ts.map +1 -1
  45. package/dist/types/entities/response/response-validation.d.ts +74 -0
  46. package/dist/types/entities/response/response-validation.d.ts.map +1 -0
  47. package/dist/types/entities/response/response.d.ts +24 -20
  48. package/dist/types/entities/response/response.d.ts.map +1 -1
  49. package/dist/types/entities/step/step.d.ts +42 -0
  50. package/dist/types/entities/step/step.d.ts.map +1 -0
  51. package/dist/types/exports.d.ts +0 -1
  52. package/dist/types/exports.d.ts.map +1 -1
  53. package/dist/types/form/build-responses.d.ts +17 -0
  54. package/dist/types/form/build-responses.d.ts.map +1 -0
  55. package/dist/types/form/create-field-evaluator.d.ts +27 -0
  56. package/dist/types/form/create-field-evaluator.d.ts.map +1 -0
  57. package/dist/types/form/create-field-validation.d.ts +59 -0
  58. package/dist/types/form/create-field-validation.d.ts.map +1 -0
  59. package/dist/types/form/create-form.d.ts +97 -0
  60. package/dist/types/form/create-form.d.ts.map +1 -0
  61. package/dist/types/form/create-submit-pipeline.d.ts +70 -0
  62. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -0
  63. package/dist/types/form/get-step-fields.d.ts +18 -0
  64. package/dist/types/form/get-step-fields.d.ts.map +1 -0
  65. package/dist/types/form/index.d.ts +10 -0
  66. package/dist/types/form/index.d.ts.map +1 -0
  67. package/dist/types/index.d.ts +3 -1
  68. package/dist/types/index.d.ts.map +1 -1
  69. package/dist/types/logic-engine.d.ts +12 -10
  70. package/dist/types/logic-engine.d.ts.map +1 -1
  71. package/dist/types/picked.d.ts +99 -33
  72. package/dist/types/picked.d.ts.map +1 -1
  73. package/dist/types/plugins/create-experience/create-experience.d.ts +53 -31
  74. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  75. package/dist/types/plugins/create-experience/index.d.ts +2 -2
  76. package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
  77. package/dist/types/plugins/create-experience/plugin.d.ts.map +1 -1
  78. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +21 -4
  79. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  80. package/dist/types/plugins/dynamic-experiences/types.d.ts +45 -0
  81. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  82. package/dist/types/plugins/experience-browser-storage/plugin.d.ts +2 -1
  83. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  84. package/dist/types/plugins/history-browser-storage/plugin.d.ts +1 -0
  85. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  86. package/dist/types/plugins/responses-browser-storage/plugin.d.ts +2 -1
  87. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
  88. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
  89. package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
  90. package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
  91. package/dist/types/utils/dom.d.ts +0 -3
  92. package/dist/types/utils/dom.d.ts.map +1 -1
  93. package/dist/types/utils/events.d.ts +2 -2
  94. package/dist/types/utils/events.d.ts.map +1 -1
  95. package/dist/types/utils/global-obj.d.ts +0 -1
  96. package/dist/types/utils/global-obj.d.ts.map +1 -1
  97. package/dist/types/utils/indexed-db.d.ts +2 -1
  98. package/dist/types/utils/indexed-db.d.ts.map +1 -1
  99. package/dist/types/utils/logger.d.ts.map +1 -1
  100. package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts +16 -0
  101. package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts.map +1 -0
  102. package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
  103. package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
  104. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
  105. package/dist/types/utils/nodes.d.ts +2 -2
  106. package/dist/types/utils/nodes.d.ts.map +1 -1
  107. package/dist/types/utils/object.d.ts +0 -8
  108. package/dist/types/utils/object.d.ts.map +1 -1
  109. package/dist/types/utils/picked-config.d.ts +1 -1
  110. package/dist/types/utils/picked-config.d.ts.map +1 -1
  111. package/dist/types/utils/rules-logic.d.ts +31 -0
  112. package/dist/types/utils/rules-logic.d.ts.map +1 -1
  113. package/dist/types/utils/search-params.d.ts.map +1 -1
  114. package/dist/types/utils/state-snaphot.d.ts +11 -1
  115. package/dist/types/utils/state-snaphot.d.ts.map +1 -1
  116. package/dist/types/utils/storage.d.ts.map +1 -1
  117. package/package.json +43 -7
  118. package/dist/api-BwTaomem.cjs +0 -1
  119. package/dist/experience-instance-BRpI9I4s.js +0 -710
  120. package/dist/experience-instance-BUTnwbSJ.cjs +0 -1
  121. package/dist/object-BReQiaSS.cjs +0 -1
  122. package/dist/storage-BFjb8azI.cjs +0 -1
  123. package/dist/types/entities/project/project.d.ts +0 -9
  124. package/dist/types/entities/project/project.d.ts.map +0 -1
  125. package/dist/types/utils/get-step-fields.d.ts +0 -4
  126. package/dist/types/utils/get-step-fields.d.ts.map +0 -1
  127. package/dist/types/utils/node-tree/get-next-node-from-conditional.d.ts +0 -3
  128. package/dist/types/utils/node-tree/get-next-node-from-conditional.d.ts.map +0 -1
  129. /package/dist/{id-CIbS4P60.cjs → id-Bv44ilEo.cjs} +0 -0
  130. /package/dist/{id-BniPxOdF.js → id-CRqy981z.js} +0 -0
package/dist/esm/index.js CHANGED
@@ -1,15 +1,16 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, u as c } from "../experience-instance-BRpI9I4s.js";
2
- import { t as l } from "../object-Clj5zVr1.js";
3
- import { t as u } from "../logger-6z_gb4rA.js";
4
- import { a as d, c as f, d as p, i as ee, l as m, n as h, o as g, p as te, r as _, s as ne, t as re, u as ie } from "../supports-0XIfd4-R.js";
5
- import { i as ae, n as v, r as y, t as b } from "../storage-DyxpJ0pg.js";
6
- import { n as x, r as oe } from "../api-DWBcrf98.js";
7
- import { t as se } from "../id-BniPxOdF.js";
8
- import { attach as S, combine as C, createApi as w, createDomain as T, createEffect as E, createEvent as D, createStore as O, sample as k } from "effector";
9
- import { createFactory as A, invoke as j } from "@withease/factories";
1
+ import { n as e, t } from "../rules-logic-CnVktz2l.js";
2
+ import { t as n } from "../object-C82v79xc.js";
3
+ import { t as r } from "../logger-6z_gb4rA.js";
4
+ import { a as i, c as a, d as o, i as s, l as c, n as l, o as u, p as d, r as f, s as p, t as m, u as h } from "../supports-0XIfd4-R.js";
5
+ import { a as g, c as _, i as v, l as ee, n as te, o as ne, r as re, s as y } from "../experience-instance-NHU1moID.js";
6
+ import { i as ie, n as b, r as x, t as S } from "../storage-6Xk0uAxB.js";
7
+ import { n as ae, r as oe } from "../api-mlYS-lDj.js";
8
+ import { t as se } from "../id-CRqy981z.js";
9
+ import { attach as C, combine as w, createApi as T, createDomain as E, createEffect as D, createEvent as O, createStore as k, sample as A } from "effector";
10
+ import { createFactory as j, invoke as M } from "@withease/factories";
10
11
  //#region src/entities/experience/experience.ts
11
- var M = T("experience"), ce = A(({ client: e, experience: t }) => {
12
- let n = M.store(t), r = w(n, { merge(e, t) {
12
+ var N = E("experience"), ce = j(({ client: e, experience: t }) => {
13
+ let n = N.store(t), r = T(n, { merge(e, t) {
13
14
  return {
14
15
  ...e,
15
16
  ...t.experience
@@ -18,28 +19,32 @@ var M = T("experience"), ce = A(({ client: e, experience: t }) => {
18
19
  name: e.name,
19
20
  decisionLogic: e.condition,
20
21
  targetSelectors: e.targets,
21
- initializeOpenLogic: t.initializeOpen
22
- })), a = e.components.listStore.map((e) => (t.componentName ? e.find((e) => e.name === t.componentName) : void 0) || e.find((e) => e.name === `experience:${t.id}`) || e.find((e) => e.name === "experience"), { skipVoid: !1 }), o = n.map((e) => ({
23
- steps: e.steps,
24
- nodes: e.nodes,
25
- edges: e.edges,
26
- conditionals: e.conditionals
27
- })), s = n.map((e) => e.fields), c = t.actions ?? [];
22
+ initializeOpenLogic: e.initializeOpen
23
+ })), a = w(n, e.components.listStore, (e, t) => (e.componentName ? t.find((t) => t.name === e.componentName) : void 0) || t.find((t) => t.name === `experience:${e.id}`) || t.find((e) => e.name === "experience"), { skipVoid: !1 }), o = w(n, e.steps.indexStore, e.conditions.indexStore, (e, t, n) => {
24
+ let r = e.nodes.filter(v).map((e) => t[e.stepId]).filter((e) => e !== void 0), i = e.nodes.filter(re).map((e) => n[e.conditionId]).filter((e) => e !== void 0);
25
+ return {
26
+ steps: r,
27
+ nodes: e.nodes,
28
+ edges: e.edges,
29
+ conditions: i
30
+ };
31
+ }), s = t.actions ?? [];
28
32
  return {
29
33
  id: t.id,
34
+ key: t.key,
35
+ name: t.name,
30
36
  configStore: i,
31
37
  treeStore: o,
32
- fieldsStore: s,
33
38
  componentStore: a,
34
- actions: c,
39
+ actions: s,
35
40
  merge: r.merge
36
41
  };
37
42
  });
38
43
  function le(e) {
39
- return j(ce, e);
44
+ return M(ce, e);
40
45
  }
41
- var ue = A(({ client: e }) => {
42
- let t = M.store({}), n = w(t, { register(e, t) {
46
+ var ue = j(({ client: e }) => {
47
+ let t = N.store({}), n = T(t, { register(e, t) {
43
48
  return {
44
49
  ...e,
45
50
  [t.id]: t
@@ -64,35 +69,49 @@ var ue = A(({ client: e }) => {
64
69
  function a(e) {
65
70
  return t.map((t) => t[e], { skipVoid: !1 });
66
71
  }
67
- let o = S({
72
+ function o(e) {
73
+ return t.map((t) => Object.values(t).find((t) => t.key === e) ?? t[e], { skipVoid: !1 });
74
+ }
75
+ let s = C({
68
76
  source: t,
69
- effect: async (t, { id: n, options: r }) => {
70
- let i = t[n];
71
- if (!i) {
72
- `${n}`;
77
+ effect: async (t, n) => {
78
+ let r = "key" in n ? Object.values(t).find((e) => e.key === n.key) : t[n.id];
79
+ if (!r) {
80
+ "key" in n ? `${n.key}` : `${n.id}`;
73
81
  return;
74
82
  }
75
- if (r?.bypassCondition) {
76
- N(e, i, r);
83
+ let { options: i } = n;
84
+ if (i?.bypassCondition) {
85
+ P(e, r, i);
77
86
  return;
78
87
  }
79
- await F(e, i) && N(e, i, r);
88
+ await I(e, r) && P(e, r, i);
80
89
  }
81
90
  });
82
91
  return {
83
92
  register: r,
84
93
  get: a,
85
94
  getById: a,
86
- launch: o,
87
- open: S({
88
- source: e.experienceInstances.listStore,
89
- effect: (e, { id: t, options: n }) => {
90
- let r = e.filter((e) => e.experienceId === t);
91
- if (r.length > 0) for (let e of r) e.open();
92
- else o({
93
- id: t,
95
+ getByKey: o,
96
+ launch: s,
97
+ open: C({
98
+ source: {
99
+ experiences: t,
100
+ instances: e.experienceInstances.listStore
101
+ },
102
+ effect: ({ experiences: e, instances: t }, n) => {
103
+ let r = "key" in n ? Object.values(e).find((e) => e.key === n.key) : e[n.id], i = t.filter((e) => r && e.experienceId === r.id);
104
+ if (i.length > 0) for (let e of i) e.open();
105
+ else s("key" in n ? {
106
+ key: n.key,
94
107
  options: {
95
- ...n,
108
+ ...n.options,
109
+ initialiseOpen: !0
110
+ }
111
+ } : {
112
+ id: n.id,
113
+ options: {
114
+ ...n.options,
96
115
  initialiseOpen: !0
97
116
  }
98
117
  });
@@ -102,24 +121,22 @@ var ue = A(({ client: e }) => {
102
121
  };
103
122
  });
104
123
  function de(e) {
105
- return j(ue, e);
124
+ return M(ue, e);
106
125
  }
107
- var fe = (e, t) => {
108
- t.register(e);
109
- }, N = (e, r, i) => {
110
- let { targetSelectors: o } = r.configStore.getState(), s = a(o, r.id);
111
- s.forEach(({ elements: e }) => e.forEach((e) => t(e, r.id))), n(s, r.id).forEach((t) => {
112
- i ? e.experienceInstances.spawn(r, t, i) : e.experienceInstances.spawn(r, t);
126
+ var P = (e, t, n) => {
127
+ let { targetSelectors: r } = t.configStore.getState(), i = y(r, t.id);
128
+ i.forEach(({ elements: e }) => e.forEach((e) => ee(e, t.id))), g(i, t.id).forEach((r) => {
129
+ n ? e.experienceInstances.spawn(t, r, n) : e.experienceInstances.spawn(t, r);
113
130
  });
114
- }, P = async (e) => {
131
+ }, F = async (e) => {
115
132
  await Promise.all(e.experiences.listStore.getState().map(async (t) => {
116
- await F(e, t) && N(e, t);
133
+ await I(e, t) && P(e, t);
117
134
  }));
118
- }, F = async (e, t) => {
119
- if (!e.preconditionPassed || !e.session?.isUser) return !1;
120
- let { decisionLogic: n, targetSelectors: i } = t.configStore.getState();
121
- return a(i, t.id).length < 1 || i.length === 0 ? !1 : n === void 0 ? !0 : c(n) ? await r(e, n) === !0 : !0;
122
- }, I = (e, t, n) => {
135
+ }, I = async (n, r) => {
136
+ if (!n.preconditionPassed || !n.session?.isUser) return !1;
137
+ let { decisionLogic: i, targetSelectors: a } = r.configStore.getState();
138
+ return y(a, r.id).length < 1 || a.length === 0 ? !1 : i === void 0 ? !0 : e(i) ? await t(n, i) === !0 : !0;
139
+ }, fe = (e, t, n) => {
123
140
  let r = t.name, i = t.setup(e);
124
141
  if (i) {
125
142
  let e = n[r] ?? {};
@@ -128,16 +145,16 @@ var fe = (e, t) => {
128
145
  ...i
129
146
  });
130
147
  }
131
- }, L = T("component"), R = A(({ client: e, component: t, name: n }) => ({
148
+ }, L = E("component"), R = j(({ client: e, component: t, name: n }) => ({
132
149
  name: n,
133
150
  component: t,
134
151
  frameworkStore: e.frameworks.getByName(t.frameworkName)
135
152
  }));
136
153
  function z(e) {
137
- return j(R, e);
154
+ return M(R, e);
138
155
  }
139
- var B = A(({ client: e }) => {
140
- let t = L.store({}), n = w(t, { register(e, t) {
156
+ var B = j(({ client: e }) => {
157
+ let t = L.store({}), n = T(t, { register(e, t) {
141
158
  return {
142
159
  ...e,
143
160
  [t.name]: t
@@ -163,12 +180,12 @@ var B = A(({ client: e }) => {
163
180
  };
164
181
  });
165
182
  function V(e) {
166
- return j(B, e);
183
+ return M(B, e);
167
184
  }
168
185
  var H = (e, t, n) => {
169
186
  n.register(e, t);
170
- }, pe = T("framework"), me = A(({ client: e }) => {
171
- let t = pe.store({}), n = w(t, { register(e, t) {
187
+ }, pe = E("framework"), me = j(({ client: e }) => {
188
+ let t = pe.store({}), n = T(t, { register(e, t) {
172
189
  return {
173
190
  ...e,
174
191
  [t.name]: t.framework
@@ -191,20 +208,20 @@ var H = (e, t, n) => {
191
208
  };
192
209
  });
193
210
  function he(e) {
194
- return j(me, e);
211
+ return M(me, e);
195
212
  }
196
213
  var ge = (e, t) => {
197
214
  t.register(e.name, e);
198
- }, _e = 6e3, ve = b("last_ping", "global"), ye = async (e) => {
215
+ }, _e = 6e3, ve = S("last_ping", "global"), ye = async (e) => {
199
216
  try {
200
- let t = Date.now(), n = v.get(ve), r = 0;
217
+ let t = Date.now(), n = b.get(ve), r = 0;
201
218
  if (n.isSet() && (r = n.json() ?? 0), r && t - r < _e) return !0;
202
219
  let i = {
203
220
  projectId: e.projectId,
204
221
  path: window.location.pathname
205
222
  }, a = {}, o = document.getElementById("picked_script")?.dataset.verceltoken;
206
223
  o && (a["x-vercel-protection-bypass"] = o);
207
- let s = (await x(e.apiUrl, "ping", i, a)).ok;
224
+ let s = (await ae(e.apiUrl, "ping", i, a)).ok;
208
225
  return s && n.set(t), s;
209
226
  } catch {
210
227
  return !1;
@@ -226,8 +243,8 @@ function U(e) {
226
243
  }
227
244
  //#endregion
228
245
  //#region src/entities/predicate/predicate.ts
229
- var be = T("predicate"), xe = A(({ client: e }) => {
230
- let t = be.store({}), n = w(t, { register(e, t) {
246
+ var be = E("predicate"), xe = j(({ client: e }) => {
247
+ let t = be.store({}), n = T(t, { register(e, t) {
231
248
  return {
232
249
  ...e,
233
250
  [t.name]: {
@@ -247,7 +264,7 @@ var be = T("predicate"), xe = A(({ client: e }) => {
247
264
  return t.map((t) => t[e]?.predicate, { skipVoid: !1 });
248
265
  }
249
266
  function o(t) {
250
- let n = O(() => void 0, { skipVoid: !1 }), r = E(async () => {
267
+ let n = k(() => void 0, { skipVoid: !1 }), r = D(async () => {
251
268
  let n = a(t).getState();
252
269
  if (!n) return;
253
270
  let r = U(e);
@@ -256,13 +273,13 @@ var be = T("predicate"), xe = A(({ client: e }) => {
256
273
  args: e
257
274
  });
258
275
  });
259
- return k({
276
+ return A({
260
277
  source: {
261
278
  responses: e.responses.listStore,
262
279
  fields: e.fields.listStore
263
280
  },
264
281
  target: r
265
- }), k({
282
+ }), A({
266
283
  clock: r.doneData,
267
284
  filter: (e) => e !== void 0,
268
285
  target: n
@@ -276,12 +293,12 @@ var be = T("predicate"), xe = A(({ client: e }) => {
276
293
  };
277
294
  });
278
295
  function Se(e) {
279
- return j(xe, e);
296
+ return M(xe, e);
280
297
  }
281
298
  var Ce = (e, t, n) => {
282
299
  n.register(e, t);
283
- }, W = T("feature"), we = A(({ client: e }) => {
284
- let t = W.store({}), n = W.store([]), r = w(t, { register(e, t) {
300
+ }, W = E("feature"), we = j(({ client: e }) => {
301
+ let t = W.store({}), n = W.store([]), r = T(t, { register(e, t) {
285
302
  return {
286
303
  ...e,
287
304
  [t.id]: t.feature
@@ -301,19 +318,19 @@ var Ce = (e, t, n) => {
301
318
  feature: i
302
319
  }));
303
320
  }
304
- let a = E(async ({ id: e, key: t, storage: n = "local" }) => {
305
- let r = b(`feature:${e}:${t}`, "global"), i = (n === "session" ? y : v).get(r).boolean();
321
+ let a = D(async ({ id: e, key: t, storage: n = "local" }) => {
322
+ let r = S(`feature:${e}:${t}`, "global"), i = (n === "session" ? x : b).get(r).boolean();
306
323
  return i === null ? null : {
307
324
  id: e,
308
325
  key: t,
309
326
  bucket: i,
310
327
  storage: n
311
328
  };
312
- }), o = E((e) => {
329
+ }), o = D((e) => {
313
330
  if (!e) return null;
314
- let t = b(`feature:${e.id}:${e.key}`, "global");
315
- (e.storage === "session" ? y : v).set(t, e.bucket);
316
- }), s = /* @__PURE__ */ new Map(), c = S({
331
+ let t = S(`feature:${e.id}:${e.key}`, "global");
332
+ (e.storage === "session" ? x : b).set(t, e.bucket);
333
+ }), s = /* @__PURE__ */ new Map(), c = C({
317
334
  source: {
318
335
  allFeaturesStore: t,
319
336
  resolvedFeaturesStore: n
@@ -344,7 +361,7 @@ var Ce = (e, t, n) => {
344
361
  };
345
362
  }
346
363
  });
347
- k({
364
+ A({
348
365
  clock: r.register,
349
366
  fn: (e) => {
350
367
  let { id: t, feature: n } = e;
@@ -355,7 +372,7 @@ var Ce = (e, t, n) => {
355
372
  };
356
373
  },
357
374
  target: a
358
- }), k({
375
+ }), A({
359
376
  source: t,
360
377
  clock: c.doneData,
361
378
  fn: (e, t) => {
@@ -369,7 +386,7 @@ var Ce = (e, t, n) => {
369
386
  },
370
387
  target: o
371
388
  });
372
- let l = C({
389
+ let l = w({
373
390
  allFeaturesStore: t,
374
391
  resolvedFeaturesStore: n
375
392
  }).map(({ allFeaturesStore: e, resolvedFeaturesStore: t }) => Object.values(e).map((e) => {
@@ -391,7 +408,7 @@ var Ce = (e, t, n) => {
391
408
  isResolved: !1
392
409
  };
393
410
  }));
394
- k({
411
+ A({
395
412
  clock: c.doneData,
396
413
  source: { resolvedFeatures: n },
397
414
  filter: ({ resolvedFeatures: e }, { id: t, key: n }) => !e.some((e) => e.id === t && e.key === n),
@@ -400,7 +417,7 @@ var Ce = (e, t, n) => {
400
417
  type: "feature_decide",
401
418
  feature: e
402
419
  }))
403
- }), k({
420
+ }), A({
404
421
  clock: [a.doneData, c.doneData],
405
422
  source: n,
406
423
  fn: (e, t) => !t || e.some((e) => e.id === t.id && e.key === t.key) ? e : [...e, t],
@@ -413,15 +430,15 @@ var Ce = (e, t, n) => {
413
430
  return t.map((t) => t[e], { skipVoid: !1 });
414
431
  }
415
432
  function f(e) {
416
- let t = O(async () => void 0, { skipVoid: !1 }), r = E(async () => {
433
+ let t = k(async () => void 0, { skipVoid: !1 }), r = D(async () => {
417
434
  let t = u(e).getState();
418
435
  if (t) return async () => (await t.getBucket()).bucket;
419
436
  });
420
- return k({
437
+ return A({
421
438
  source: n,
422
439
  filter: (t) => t.some((t) => t.id === e),
423
440
  target: r
424
- }), k({
441
+ }), A({
425
442
  clock: r.doneData,
426
443
  filter: (e) => e !== void 0,
427
444
  target: t
@@ -436,11 +453,11 @@ var Ce = (e, t, n) => {
436
453
  };
437
454
  });
438
455
  function Te(e) {
439
- return j(we, e);
456
+ return M(we, e);
440
457
  }
441
458
  var Ee = (e, t, n) => {
442
459
  n.register(e, t);
443
- }, G = T("history");
460
+ }, G = E("history");
444
461
  function K(e, t) {
445
462
  return {
446
463
  id: se(`history-entry-${Date.now()}-${Math.random()}}`),
@@ -449,7 +466,7 @@ function K(e, t) {
449
466
  experienceId: e
450
467
  };
451
468
  }
452
- var De = A(() => {
469
+ var De = j(() => {
453
470
  let e = G.store({ entries: [] }), t = G.event(), n = G.event(), r = G.event(), i = G.event();
454
471
  e.on(t, (e, t) => ({ entries: [...e.entries, K(t.experienceId, t.node)] })), e.on(n, (e, t) => ({ entries: [...e.entries.slice(0, -1), K(t.experienceId, t.node)] })), e.on(i, (e, t) => t);
455
472
  function a(e, t) {
@@ -459,7 +476,7 @@ var De = A(() => {
459
476
  };
460
477
  for (let r = e.length - 1; r >= 0; r--) {
461
478
  let i = e[r], a = i?.node;
462
- if (!(!a || !o(a)) && !(t && i?.experienceId !== t)) if (n.lastStepIndex === -1) n.lastStepIndex = r;
479
+ if (!(!a || !v(a)) && !(t && i.experienceId !== t)) if (n.lastStepIndex === -1) n.lastStepIndex = r;
463
480
  else {
464
481
  n.secondLastStepIndex = r;
465
482
  break;
@@ -482,13 +499,13 @@ var De = A(() => {
482
499
  };
483
500
  });
484
501
  function Oe() {
485
- return j(De);
502
+ return M(De);
486
503
  }
487
504
  //#endregion
488
505
  //#region src/utils/events.ts
489
506
  var ke = 0, Ae = (e) => {
490
- let t = O([]);
491
- return k({
507
+ let t = k([]);
508
+ return A({
492
509
  clock: e,
493
510
  source: t,
494
511
  fn: (e, t) => [...e, {
@@ -498,44 +515,91 @@ var ke = 0, Ae = (e) => {
498
515
  }],
499
516
  target: t
500
517
  }), t;
501
- }, je = T("field"), Me = A(() => {
502
- let e = je.store({}), t = w(e, { register(e, t) {
503
- return {
504
- ...e,
505
- [t.field.id]: t.field
506
- };
507
- } });
518
+ }, je = E("field"), Me = j(() => {
519
+ let e = je.store({}), t = T(e, {
520
+ register(e, t) {
521
+ return {
522
+ ...e,
523
+ [t.field.id]: t.field
524
+ };
525
+ },
526
+ updateByKey(e, t) {
527
+ let n = Object.values(e).find((e) => e.key === t.fieldKey);
528
+ return n ? {
529
+ ...e,
530
+ [n.id]: Object.assign({}, n, t.updates)
531
+ } : e;
532
+ }
533
+ });
508
534
  function n(e) {
509
535
  t.register({ field: e });
510
536
  }
511
- function r(e, n) {
512
- let r = a(e).getState();
513
- if (!r) return;
514
- let i = Object.assign({}, r, { ...n });
515
- t.register({ field: { ...i } });
537
+ function r(n, r) {
538
+ let i = e.getState(), a = Object.values(i).find((e) => e.key === n)?.key;
539
+ a && t.updateByKey({
540
+ fieldKey: a,
541
+ updates: r
542
+ });
516
543
  }
517
544
  let i = e.map((e) => Object.values(e));
518
545
  function a(t) {
519
- return e.map((e) => e[t] || null);
546
+ return e.map((e) => e[t] ?? null, { skipVoid: !1 });
520
547
  }
521
548
  function o(t) {
522
- return e.map((e) => Object.values(e).find((e) => e.name === t) || null);
549
+ return e.map((e) => Object.values(e).find((e) => e.key === t) ?? null, { skipVoid: !1 });
550
+ }
551
+ function s(t) {
552
+ return e.map((e) => Object.values(e).find((e) => e.name === t) ?? null, { skipVoid: !1 });
523
553
  }
524
554
  return {
525
555
  register: n,
526
556
  update: r,
527
557
  getById: a,
558
+ getByKey: o,
528
559
  listStore: i,
529
- getByName: o
560
+ getByName: s
530
561
  };
531
562
  });
532
563
  function Ne() {
533
- return j(Me);
564
+ return M(Me);
534
565
  }
535
- var Pe = (e, t) => {
566
+ //#endregion
567
+ //#region src/entities/step/step.ts
568
+ var Pe = E("step"), Fe = j(() => {
569
+ let e = Pe.store({}), t = T(e, { register(e, t) {
570
+ return {
571
+ ...e,
572
+ [t.step.id]: t.step
573
+ };
574
+ } });
575
+ function n(e) {
576
+ t.register({ step: e });
577
+ }
578
+ let r = e.map((e) => Object.values(e));
579
+ function i(t) {
580
+ return e.map((e) => e[t] ?? null, { skipVoid: !1 });
581
+ }
582
+ function a(t) {
583
+ return e.map((e) => Object.values(e).find((e) => e.key === t) ?? null, { skipVoid: !1 });
584
+ }
585
+ return {
586
+ register: n,
587
+ getById: i,
588
+ getByKey: a,
589
+ listStore: r,
590
+ indexStore: e
591
+ };
592
+ });
593
+ function Ie() {
594
+ return M(Fe);
595
+ }
596
+ function Le(e, t) {
536
597
  t.register(e);
537
- }, Fe = T("action"), Ie = A(() => {
538
- let e = Fe.store({}), t = w(e, { register(e, t) {
598
+ }
599
+ //#endregion
600
+ //#region src/entities/action/action.ts
601
+ var Re = E("action"), ze = j(({ client: e }) => {
602
+ let t = Re.store({}), n = T(t, { register(e, t) {
539
603
  return {
540
604
  ...e,
541
605
  [t.name]: {
@@ -544,56 +608,121 @@ var Pe = (e, t) => {
544
608
  }
545
609
  };
546
610
  } });
547
- function n(e, n) {
548
- t.register({
611
+ function r(e, r) {
612
+ t.getState()[e] && `${e}`, n.register(Object.freeze({
549
613
  name: e,
550
- action: n
551
- });
614
+ action: r
615
+ }));
552
616
  }
553
- let r = e.map((e) => Object.values(e));
554
- function i(t) {
555
- return e.map((e) => e[t], { skipVoid: !1 });
617
+ let i = t.map((e) => Object.values(e));
618
+ function a(e) {
619
+ return t.map((t) => t[e]?.action, { skipVoid: !1 });
556
620
  }
557
- function a(t) {
558
- return e.map((e) => {
559
- let n = e[t];
560
- return n ? n.action : void 0;
561
- }, { skipVoid: !1 });
621
+ function o(t) {
622
+ let n = k(() => void 0, { skipVoid: !1 }), r = D(async () => {
623
+ let n = a(t).getState();
624
+ if (!n) return;
625
+ let r = U(e);
626
+ return (...e) => n({
627
+ ...r,
628
+ args: e
629
+ });
630
+ });
631
+ return A({
632
+ source: {
633
+ responses: e.responses.listStore,
634
+ fields: e.fields.listStore
635
+ },
636
+ target: r
637
+ }), A({
638
+ clock: r.doneData,
639
+ filter: (e) => e !== void 0,
640
+ target: n
641
+ }), r(), n;
562
642
  }
563
643
  return {
564
- register: n,
565
- getByName: i,
566
- listStore: r,
567
- getEvokableAction: a
644
+ register: r,
645
+ getByName: a,
646
+ listStore: i,
647
+ getEvokableAction: o
568
648
  };
569
649
  });
570
- function Le() {
571
- return j(Ie);
650
+ function Be(e) {
651
+ return M(ze, e);
572
652
  }
573
- var Re = (e, t, n) => {
653
+ var Ve = (e, t, n) => {
574
654
  n.register(e, t);
575
655
  };
576
656
  //#endregion
577
- //#region src/entities/response/response.ts
578
- function q(e) {
657
+ //#region src/entities/response/response-validation.ts
658
+ function q(e, t, n, r) {
659
+ return {
660
+ fieldKey: e.key,
661
+ userMessage: n,
662
+ systemMessage: r,
663
+ value: t
664
+ };
665
+ }
666
+ function J(e) {
579
667
  return e == null || e === "" || Array.isArray(e) && !e.length;
580
668
  }
581
- function ze(e) {
669
+ function He(e) {
582
670
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
583
671
  }
584
- function J(e) {
672
+ function Y(e) {
585
673
  try {
586
674
  return JSON.stringify(e), !0;
587
675
  } catch {
588
676
  return !1;
589
677
  }
590
678
  }
591
- var Be = T("response"), Ve = A(({ client: e }) => {
592
- let t = Be.store({}), n = D(), i = D(), a = w(t, {
679
+ function Ue(e, t) {
680
+ return t.find((t) => t.key === e) ?? null;
681
+ }
682
+ function We(e, t) {
683
+ return e.multiple && (typeof t == "string" || typeof t == "number" || typeof t == "boolean") ? [t] : t;
684
+ }
685
+ function Ge(e, t) {
686
+ if (e.type !== "object" || J(t)) return null;
687
+ if (e.multiple) {
688
+ if (!Array.isArray(t)) return q(e, t, "This field expects multiple values", "Field expects an array of objects.");
689
+ for (let n of t) {
690
+ if (typeof n != "object" || !n) return q(e, t, "This field expects object values", "Field expects an array of objects, but received non-object value.");
691
+ if (!Y(n)) return q(e, t, "This field contains non-serializable data", "Field value contains non-JSON-serializable data (functions, circular references, etc.).");
692
+ }
693
+ return null;
694
+ }
695
+ return Array.isArray(t) ? q(e, t, "This field expects a single value", "Field expects a single object, not an array.") : typeof t != "object" || !t ? q(e, t, "This field expects an object value", "Field expects an object value.") : Y(t) ? null : q(e, t, "This field contains non-serializable data", "Field value contains non-JSON-serializable data (functions, circular references, etc.).");
696
+ }
697
+ function Ke(e, t) {
698
+ if (!Array.isArray(e.options) || e.options.length === 0) return null;
699
+ let n = Array.isArray(t) ? t : [t];
700
+ if (e.type === "object") {
701
+ let r = e.options.map((e) => JSON.stringify(e.value));
702
+ return n.every((e) => r.includes(JSON.stringify(e))) ? null : q(e, t, "This field expects a valid option", "Field expects a valid option from the defined choices.");
703
+ }
704
+ let r = e.options.map((e) => e.value);
705
+ return n.every((e) => !He(e) || e === null ? !1 : r.includes(e)) ? null : q(e, t, "This field expects a valid option", `Field expects a valid option. Valid options are: ${r.join(", ")}`);
706
+ }
707
+ async function qe(e, t, r, i) {
708
+ if (t.validation && !n(t.validation) && !J(r)) {
709
+ let n = i ? {
710
+ $input: r,
711
+ responses: i
712
+ } : { $input: r }, a = await e(t.validation, n);
713
+ if (typeof a == "string") return q(t, r, a, `Field validation resulted in an error: ${a}.`);
714
+ if (a === !1) return q(t, r, "This field is invalid", "Field validation resulted in an unspecified error.");
715
+ }
716
+ return t.required && J(r) ? q(t, r, "This field is required", "Field is required.") : !t.multiple && Array.isArray(r) && r.length > 1 ? q(t, r, "This field expects a single response", "Field expects a single response.") : null;
717
+ }
718
+ //#endregion
719
+ //#region src/entities/response/response.ts
720
+ var Je = E("response"), Ye = j(({ client: e }) => {
721
+ let n = Je.store({}), r = O(), i = O(), a = T(n, {
593
722
  register(e, t) {
594
723
  return {
595
724
  ...e,
596
- [t.fieldId]: t.response
725
+ [t.fieldKey]: t.response
597
726
  };
598
727
  },
599
728
  registerBatch(e, t) {
@@ -603,8 +732,7 @@ var Be = T("response"), Ve = A(({ client: e }) => {
603
732
  };
604
733
  },
605
734
  clear(e, t) {
606
- let { [t]: n, ...r } = e;
607
- return r;
735
+ return Object.fromEntries(Object.entries(e).filter(([e]) => e !== t));
608
736
  },
609
737
  clearAll() {
610
738
  return {};
@@ -614,192 +742,157 @@ var Be = T("response"), Ve = A(({ client: e }) => {
614
742
  if (typeof e == "string") {
615
743
  if (t === void 0) throw Error("Response is required when registering a single field");
616
744
  a.register({
617
- fieldId: e,
745
+ fieldKey: e,
618
746
  response: t
619
747
  });
620
748
  } else a.registerBatch(e);
621
749
  }
622
- async function s(t) {
623
- let n = [];
624
- return await Promise.allSettled(Object.entries(t).map(async ([t, i]) => {
625
- let a = i, o = e.fields.getById(t).getState();
626
- if (!o) {
627
- n.push({
628
- fieldId: t,
629
- userMessage: `Field '${t}' not found`,
630
- systemMessage: `No field with ID '${t}' exists. Available field IDs are: ${Object.keys(e.fields.listStore.getState()).join(",")}.`,
631
- value: a
632
- });
633
- return;
634
- }
635
- if (o.multiple && (typeof a == "string" || typeof a == "number" || typeof a == "boolean") && (a = [a]), o.validation && !l(o.validation) && !q(a)) {
636
- let i = await r(e, o.validation, { $input: a });
637
- if (typeof i == "string") {
638
- n.push({
639
- fieldId: t,
640
- userMessage: i,
641
- systemMessage: `Field validation resulted in an error: ${i}.`,
642
- value: a
643
- });
644
- return;
645
- }
646
- if (i === !1) {
647
- n.push({
648
- fieldId: t,
649
- userMessage: "This field is invalid",
650
- systemMessage: "Field validation resulted in an unspecified error.",
651
- value: a
652
- });
653
- return;
654
- }
655
- }
656
- if (o.required && q(a)) {
657
- n.push({
658
- fieldId: t,
659
- userMessage: "This field is required",
660
- systemMessage: "Field is required.",
661
- value: a
662
- });
663
- return;
664
- }
665
- if (!o.multiple && Array.isArray(a) && a.length > 1) {
666
- n.push({
667
- fieldId: t,
668
- userMessage: "This field expects a single response",
669
- systemMessage: "Field expects a single response.",
670
- value: a
671
- });
672
- return;
673
- }
674
- if (o.type === "object" && !q(a)) if (o.multiple) {
675
- if (!Array.isArray(a)) {
676
- n.push({
677
- fieldId: t,
678
- userMessage: "This field expects multiple values",
679
- systemMessage: "Field expects an array of objects.",
680
- value: a
750
+ let s = (n, r) => t(e, n, r), c = C({
751
+ source: {
752
+ allFields: e.fields.listStore,
753
+ existingResponses: n
754
+ },
755
+ effect: async ({ allFields: e, existingResponses: t }, n) => {
756
+ let r = [], i = {}, a = {
757
+ ...t,
758
+ ...n
759
+ }, o = Object.entries(n), c = await Promise.allSettled(o.map(async ([t, n]) => {
760
+ let o = Ue(t, e);
761
+ if (!o) {
762
+ r.push({
763
+ fieldKey: t,
764
+ userMessage: `Field '${t}' not found`,
765
+ systemMessage: `No field with key '${t}' exists. Available field keys are: ${e.map((e) => e.key).join(",")}.`,
766
+ value: n
681
767
  });
682
768
  return;
683
769
  }
684
- for (let e of a) {
685
- if (typeof e != "object" || !e) {
686
- n.push({
687
- fieldId: t,
688
- userMessage: "This field expects object values",
689
- systemMessage: "Field expects an array of objects, but received non-object value.",
690
- value: a
691
- });
692
- return;
693
- }
694
- if (!J(e)) {
695
- n.push({
696
- fieldId: t,
697
- userMessage: "This field contains non-serializable data",
698
- systemMessage: "Field value contains non-JSON-serializable data (functions, circular references, etc.).",
699
- value: a
700
- });
701
- return;
702
- }
703
- }
704
- } else {
705
- if (Array.isArray(a)) {
706
- n.push({
707
- fieldId: t,
708
- userMessage: "This field expects a single value",
709
- systemMessage: "Field expects a single object, not an array.",
710
- value: a
711
- });
770
+ let c = We(o, n), l = await qe(s, o, c, a);
771
+ if (l) {
772
+ r.push(l);
712
773
  return;
713
774
  }
714
- if (typeof a != "object" || !a) {
715
- n.push({
716
- fieldId: t,
717
- userMessage: "This field expects an object value",
718
- systemMessage: "Field expects an object value.",
719
- value: a
720
- });
775
+ let u = Ge(o, c);
776
+ if (u) {
777
+ r.push(u);
721
778
  return;
722
779
  }
723
- if (!J(a)) {
724
- n.push({
725
- fieldId: t,
726
- userMessage: "This field contains non-serializable data",
727
- systemMessage: "Field value contains non-JSON-serializable data (functions, circular references, etc.).",
728
- value: a
729
- });
780
+ let d = Ke(o, c);
781
+ if (d) {
782
+ r.push(d);
730
783
  return;
731
784
  }
785
+ i[o.key] = n;
786
+ }));
787
+ for (let [e, t] of c.entries()) {
788
+ if (t.status !== "rejected") continue;
789
+ let n = o[e];
790
+ if (!n) continue;
791
+ let [i, a] = n, s = t.reason instanceof Error ? t.reason.message : String(t.reason);
792
+ r.push({
793
+ fieldKey: i,
794
+ userMessage: "An unexpected error occurred validating this field",
795
+ systemMessage: `Validation threw for field '${i}': ${s}`,
796
+ value: a
797
+ });
732
798
  }
733
- if (Array.isArray(o.options) && o.options.length > 0) {
734
- let e = Array.isArray(a) ? a : [a];
735
- if (o.type === "object") {
736
- let r = o.options.map((e) => JSON.stringify(e.value));
737
- e.every((e) => r.includes(JSON.stringify(e))) || n.push({
738
- fieldId: t,
739
- userMessage: "This field expects a valid option",
740
- systemMessage: "Field expects a valid option from the defined choices.",
741
- value: a
742
- });
743
- } else {
744
- let r = o.options.map((e) => e.value);
745
- e.every((e) => !ze(e) || e === null ? !1 : r.includes(e)) || n.push({
746
- fieldId: t,
747
- userMessage: "This field expects a valid option",
748
- systemMessage: `Field expects a valid option. Valid options are: ${r.join(", ")}`,
749
- value: a
750
- });
751
- }
752
- }
753
- })), {
754
- responsesToCommit: t,
755
- validationErrors: n
756
- };
799
+ return {
800
+ responsesToCommit: i,
801
+ validationErrors: r
802
+ };
803
+ }
804
+ });
805
+ async function l(e) {
806
+ return c(e);
757
807
  }
758
- async function c(e) {
759
- let { responsesToCommit: t, validationErrors: n } = await s(e);
760
- return n.length ? { errors: n } : (a.registerBatch(t), { errors: [] });
808
+ let u = C({
809
+ source: n,
810
+ effect: async (e, t) => {
811
+ let { responsesToCommit: n, validationErrors: r } = await c(t);
812
+ return r.length ? { errors: r } : (a.registerBatch(n), { errors: [] });
813
+ }
814
+ });
815
+ async function d(e) {
816
+ return u(e);
761
817
  }
762
- let u = t.map((e) => e), d = t.map((e) => Object.keys(e).map((t) => ({
763
- fieldId: t,
764
- value: e[t]
818
+ let f = n.map((e) => e), p = n.map((e) => Object.entries(e).map(([e, t]) => ({
819
+ fieldKey: e,
820
+ value: t
765
821
  })));
766
- function f(n) {
767
- return C({
768
- f: e.fields.getById(n),
769
- r: t.map((e) => e[n] || null)
770
- }, ({ f: e, r: t }) => t || (e?.defaultValue ? e.defaultValue : null));
822
+ function m(e) {
823
+ return w({
824
+ f: e,
825
+ s: n
826
+ }, ({ f: e, s: t }) => {
827
+ let n = e ? t[e.key] ?? null : null;
828
+ return n === null ? e?.defaultValue !== void 0 && e.defaultValue !== null ? e.defaultValue : null : n;
829
+ });
830
+ }
831
+ function h(t) {
832
+ return m(e.fields.getById(t));
771
833
  }
772
- function p(n) {
773
- return C({
774
- f: e.fields.getByName(n),
775
- s: t
776
- }, ({ f: e, s: t }) => e && t[e.id] || (e?.defaultValue ? e.defaultValue : null));
834
+ function g(t) {
835
+ return m(e.fields.getByKey(t));
777
836
  }
778
- return k({
779
- clock: n,
837
+ function _(t) {
838
+ return m(e.fields.getByName(t));
839
+ }
840
+ return A({
841
+ clock: r,
780
842
  target: a.clearAll
781
- }), k({
843
+ }), A({
782
844
  clock: i,
783
845
  target: a.clear
784
846
  }), {
785
847
  register: o,
786
- clearAll: n,
848
+ clearAll: r,
787
849
  clear: i,
788
- commit: c,
789
- getResponsesToCommit: s,
790
- listStore: d,
791
- getAllStore: u,
792
- getByFieldId: f,
793
- getByFieldName: p
850
+ commit: d,
851
+ getResponsesToCommit: l,
852
+ listStore: p,
853
+ getAllStore: f,
854
+ getByFieldId: h,
855
+ getByFieldKey: g,
856
+ getByFieldName: _
794
857
  };
795
858
  });
796
- function He(e) {
797
- return j(Ve, e);
859
+ function Xe(e) {
860
+ return M(Ye, e);
861
+ }
862
+ //#endregion
863
+ //#region src/entities/condition/condition.ts
864
+ var Ze = E("condition"), Qe = j(() => {
865
+ let e = Ze.store({}), t = T(e, { register(e, t) {
866
+ return {
867
+ ...e,
868
+ [t.condition.id]: t.condition
869
+ };
870
+ } });
871
+ function n(e) {
872
+ t.register({ condition: e });
873
+ }
874
+ let r = e.map((e) => Object.values(e));
875
+ function i(t) {
876
+ return e.map((e) => e[t] ?? null, { skipVoid: !1 });
877
+ }
878
+ function a(t) {
879
+ return e.map((e) => Object.values(e).find((e) => e.key === t) ?? null, { skipVoid: !1 });
880
+ }
881
+ return {
882
+ register: n,
883
+ getById: i,
884
+ getByKey: a,
885
+ listStore: r,
886
+ indexStore: e
887
+ };
888
+ });
889
+ function $e() {
890
+ return M(Qe);
798
891
  }
799
892
  //#endregion
800
893
  //#region src/utils/api-url.ts
801
- function Ue() {
802
- if (_()) {
894
+ function et() {
895
+ if (f()) {
803
896
  let e = [
804
897
  document.currentScript,
805
898
  document.getElementById("picked_script"),
@@ -813,36 +906,36 @@ function Ue() {
813
906
  }
814
907
  //#endregion
815
908
  //#region src/utils/search-params.ts
816
- function We() {
817
- if (!p()) return {};
909
+ function tt() {
910
+ if (!o()) return {};
818
911
  let e = new URLSearchParams(window.location.search), t = {}, n = /* @__PURE__ */ new Set();
819
912
  for (let [t] of e.entries()) t.startsWith("picked-") && n.add(t);
820
913
  for (let r of n) {
821
914
  let n = r.replace("picked-", "");
822
915
  t[n] = e.getAll(r);
823
916
  }
824
- let r = b("s");
825
- if (n.size > 0) y.set(r, t);
917
+ let r = S("s");
918
+ if (n.size > 0) x.set(r, t);
826
919
  else {
827
- let e = y.get(r);
920
+ let e = x.get(r);
828
921
  if (e) return e.json() || {};
829
922
  }
830
923
  return t;
831
924
  }
832
925
  //#endregion
833
926
  //#region src/utils/user-session.ts
834
- function Ge() {
835
- return h() ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).substring(2, 15)}-${Math.random().toString(36).substring(2, 15)}-${Math.random().toString(36).substring(2, 15)}`;
927
+ function nt() {
928
+ return l() ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).substring(2, 15)}-${Math.random().toString(36).substring(2, 15)}-${Math.random().toString(36).substring(2, 15)}`;
836
929
  }
837
- var Ke = b("session", "global"), qe = () => {
838
- let e = v.get(Ke), t;
930
+ var rt = S("session", "global"), it = () => {
931
+ let e = b.get(rt), t;
839
932
  e.isSet() && (t = e.json());
840
933
  let n = (t) => e.set({
841
934
  id: t.id,
842
935
  isUser: t.isUser,
843
936
  identifiers: t.identifiers
844
937
  }), r = {
845
- id: t?.id ?? Ge(),
938
+ id: t?.id ?? nt(),
846
939
  isUser: t?.isUser ?? void 0,
847
940
  identifiers: t?.identifiers ?? void 0,
848
941
  setIsUser(e) {
@@ -859,22 +952,22 @@ var Ke = b("session", "global"), qe = () => {
859
952
  }
860
953
  };
861
954
  return n(r), r;
862
- }, Je = () => g() ? qe() : null;
955
+ }, X = () => u() ? it() : null;
863
956
  //#endregion
864
957
  //#region src/utils/picked-config.ts
865
- function Y() {
866
- if (p()) return globalThis.window.pickedConfig;
958
+ function Z() {
959
+ if (o()) return globalThis.window.pickedConfig;
867
960
  }
868
- function Ye() {
869
- if (!p()) return;
870
- let e = Y(), t = e?.organizationId, n = e?.projectId;
961
+ function at() {
962
+ if (!o()) return;
963
+ let e = Z(), t = e?.organizationId, n = e?.projectId;
871
964
  return t && n ? {
872
965
  organizationId: t,
873
966
  projectId: n
874
967
  } : void 0;
875
968
  }
876
- function Xe() {
877
- if (!_()) return;
969
+ function ot() {
970
+ if (!f()) return;
878
971
  let e = document.getElementById("picked_script") || document.querySelector("script#picked") || document.getElementById("cvly");
879
972
  if (!e) return;
880
973
  let t = e.dataset.organizationid || e.getAttribute("organization-id"), n = e.dataset.projectid || e.getAttribute("project-id");
@@ -883,27 +976,27 @@ function Xe() {
883
976
  projectId: n
884
977
  } : void 0;
885
978
  }
886
- function Ze(e) {
979
+ function st(e) {
887
980
  let { organizationId: t, projectId: n } = e;
888
981
  if (t && n) return {
889
982
  organizationId: t,
890
983
  projectId: n
891
984
  };
892
- let r = Ye();
985
+ let r = at();
893
986
  if (r) return r;
894
- let i = Xe();
987
+ let i = ot();
895
988
  if (i) return i;
896
989
  throw Error("organizationId and projectId are required. You can provide them via one of:\n (1) createClient({ organizationId, projectId }) options;\n (2) window.pickedConfig = { organizationId, projectId };\n (3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.");
897
990
  }
898
991
  //#endregion
899
992
  //#region src/utils/render-string.ts
900
- function X(e) {
993
+ function Q(e) {
901
994
  return e == null || e === "" || Number.isNaN(e);
902
995
  }
903
- var Qe = {
904
- default: (e, t) => X(e) ? String(t ?? "") : String(e),
905
- append: (e, t) => t && !X(e) ? `${e} ${t}` : e,
906
- prepend: (e, t) => t && !X(e) ? `${t} ${e}` : e,
996
+ var ct = {
997
+ default: (e, t) => Q(e) ? String(t ?? "") : String(e),
998
+ append: (e, t) => t && !Q(e) ? `${e} ${t}` : e,
999
+ prepend: (e, t) => t && !Q(e) ? `${t} ${e}` : e,
907
1000
  upper: (e) => typeof e == "string" ? e.toUpperCase() : e,
908
1001
  lower: (e) => typeof e == "string" ? e.toLowerCase() : e,
909
1002
  capitalize: (e) => typeof e == "string" ? e.charAt(0).toUpperCase() + e.slice(1) : e,
@@ -921,24 +1014,24 @@ var Qe = {
921
1014
  return e instanceof Set ? t.format(Array.from(e).map(String)) : e;
922
1015
  }
923
1016
  };
924
- function $e(e) {
1017
+ function lt(e) {
925
1018
  return typeof e == "object" && !!e;
926
1019
  }
927
- function et(e, t) {
1020
+ function ut(e, t) {
928
1021
  let n = t;
929
- for (let t of e.split(".")) if ($e(n) && t in n) n = n[t];
1022
+ for (let t of e.split(".")) if (lt(n) && t in n) n = n[t];
930
1023
  else return;
931
1024
  return typeof n == "function" ? n() : n;
932
1025
  }
933
- function tt(e, t) {
934
- let n = e.split("|").map((e) => e.trim()), r = et(n.shift() ?? "", t);
1026
+ function dt(e, t) {
1027
+ let n = e.split("|").map((e) => e.trim()), r = ut(n.shift() ?? "", t);
935
1028
  for (let e of n) {
936
- let [t, ...n] = e.split(":"), i = t?.trim() ?? "", a = n.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), o = Qe[i];
1029
+ let [t, ...n] = e.split(":"), i = t?.trim() ?? "", a = n.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), o = ct[i];
937
1030
  o && (r = o(r, a));
938
1031
  }
939
- return X(r) ? "" : typeof r == "object" ? JSON.stringify(r) : String(r);
1032
+ return Q(r) ? "" : typeof r == "object" ? JSON.stringify(r) : String(r);
940
1033
  }
941
- function Z(e, t) {
1034
+ function ft(e, t) {
942
1035
  let n = "", r = 0;
943
1036
  for (; r < e.length;) if (e[r] === "{" && e[r + 1] === "{") {
944
1037
  r += 2;
@@ -950,20 +1043,19 @@ function Z(e, t) {
950
1043
  }
951
1044
  i += e[r++];
952
1045
  }
953
- n += tt(i.trim(), t);
1046
+ n += dt(i.trim(), t);
954
1047
  } else n += e[r++];
955
1048
  return n;
956
1049
  }
957
1050
  //#endregion
958
1051
  //#region src/picked.ts
959
- var Q = class {
960
- static logger = u;
1052
+ var $ = class {
1053
+ static logger = r;
961
1054
  options;
962
1055
  isReady = !1;
963
- project;
964
1056
  plugins = {};
965
1057
  pluginStartHooks = [];
966
- eventBus = D();
1058
+ eventBus = O();
967
1059
  events;
968
1060
  organizationId;
969
1061
  projectId;
@@ -974,42 +1066,44 @@ var Q = class {
974
1066
  precondition;
975
1067
  condition;
976
1068
  preconditionPassed;
977
- searchParams = We();
1069
+ searchParams = tt();
978
1070
  history = Oe();
979
1071
  components = V({ client: this });
980
- experienceInstances = i({ client: this });
1072
+ experienceInstances = te({ client: this });
981
1073
  experiences = de({ client: this });
982
1074
  frameworks = he({ client: this });
983
1075
  predicates = Se({ client: this });
984
1076
  features = Te({ client: this });
985
- responses = He({ client: this });
1077
+ conditions = $e();
986
1078
  fields = Ne();
987
- actions = Le();
1079
+ responses = Xe({ client: this });
1080
+ steps = Ie();
1081
+ actions = Be({ client: this });
988
1082
  constructor(e) {
989
1083
  this.events = Ae(this.eventBus);
990
- let { organizationId: t, projectId: n } = Ze(e);
991
- this.organizationId = t, this.projectId = n, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Ue(), this.dashboardUrl = e.dashboardUrl ?? "https://dashboard.picked.app", this.documentationSiteUrl = e.documentationSiteUrl ?? "https://docs.picked.app", this.session = Je(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.setupComponents(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({
1084
+ let { organizationId: t, projectId: n } = st(e);
1085
+ this.organizationId = t, this.projectId = n, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || et(), this.dashboardUrl = e.dashboardUrl ?? "https://dashboard.picked.app", this.documentationSiteUrl = e.documentationSiteUrl ?? "https://docs.picked.app", this.session = X(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.setupComponents(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({
992
1086
  type: "load",
993
1087
  version: oe()
994
1088
  });
995
1089
  }
996
1090
  start = () => {
997
1091
  ye(this), (async () => {
998
- if (!_()) return;
1092
+ if (!f()) return;
999
1093
  await this.runPluginStartHooks();
1000
- let t = await this.evaluateGate(this.precondition);
1001
- this.preconditionPassed = t;
1002
- let n;
1003
- t && (n = await this.evaluateGate(this.condition));
1004
- let r = t && n === !0;
1005
- if (typeof n == "boolean" && this.session) {
1006
- let e = n;
1094
+ let e = await this.evaluateGate(this.precondition);
1095
+ this.preconditionPassed = e;
1096
+ let t;
1097
+ e && (t = await this.evaluateGate(this.condition));
1098
+ let n = e && t === !0;
1099
+ if (typeof t == "boolean" && this.session) {
1100
+ let e = t;
1007
1101
  this.session.setIsUser(e), this.eventBus({
1008
1102
  type: "user_decide",
1009
1103
  value: e
1010
1104
  });
1011
1105
  }
1012
- if (this.eventBus({ type: "initialize" }), r && P(this), await e(), r && P(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session) {
1106
+ if (this.eventBus({ type: "initialize" }), n && F(this), await ne(), n && F(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session) {
1013
1107
  let { id: e, isUser: t, identifiers: n } = this.session;
1014
1108
  this.eventBus({
1015
1109
  type: "session",
@@ -1027,7 +1121,7 @@ var Q = class {
1027
1121
  H(e, t, this.components);
1028
1122
  };
1029
1123
  registerPlugin = (e) => {
1030
- I(this, e, this.plugins);
1124
+ fe(this, e, this.plugins);
1031
1125
  let t = this.plugins[e.name];
1032
1126
  t?.onStart && this.pluginStartHooks.push(t.onStart);
1033
1127
  };
@@ -1037,14 +1131,20 @@ var Q = class {
1037
1131
  registerPredicate = (e, t) => {
1038
1132
  Ce(e, t, this.predicates);
1039
1133
  };
1134
+ registerCondition = (e) => {
1135
+ this.conditions.register(e);
1136
+ };
1040
1137
  registerField = (e) => {
1041
- Pe(e, this.fields);
1138
+ this.fields.register(e);
1139
+ };
1140
+ registerStep = (e) => {
1141
+ Le(e, this.steps);
1042
1142
  };
1043
1143
  registerAction = (e, t) => {
1044
- Re(e, t, this.actions);
1144
+ Ve(e, t, this.actions);
1045
1145
  };
1046
1146
  registerExperience = (e) => {
1047
- e.component && H(`experience:${e.id}`, e.component, this.components), fe(e, this.experiences);
1147
+ e.component && H(`experience:${e.id}`, e.component, this.components), this.experiences.register(e);
1048
1148
  };
1049
1149
  getStateSnapshot = () => U(this);
1050
1150
  launchExperienceById = async (e, t) => {
@@ -1053,14 +1153,23 @@ var Q = class {
1053
1153
  options: t
1054
1154
  });
1055
1155
  };
1156
+ launchExperienceByKey = async (e, t) => {
1157
+ this.experiences.launch({
1158
+ key: e,
1159
+ options: t
1160
+ });
1161
+ };
1056
1162
  openExperienceById = async (e) => {
1057
1163
  this.experiences.open({ id: e });
1058
1164
  };
1165
+ openExperienceByKey = async (e) => {
1166
+ this.experiences.open({ key: e });
1167
+ };
1059
1168
  async runPluginStartHooks() {
1060
1169
  for (let e of this.pluginStartHooks) await e();
1061
1170
  }
1062
1171
  async evaluateGate(e) {
1063
- return e === void 0 ? !0 : typeof e == "boolean" ? e : await r(this, e) === !0;
1172
+ return e === void 0 ? !0 : typeof e == "boolean" ? e : await t(this, e) === !0;
1064
1173
  }
1065
1174
  setupPlugins() {
1066
1175
  this.options.plugins?.forEach((e) => {
@@ -1125,48 +1234,29 @@ var Q = class {
1125
1234
  }
1126
1235
  getPluginConfig = (e) => this.plugins[e] ?? {};
1127
1236
  renderString = (e, t) => {
1128
- let n = this.responses.listStore.getState().reduce((e, t) => (e[t.fieldId] = t.value, e), {});
1129
- return Z(e, {
1237
+ let n = this.responses.listStore.getState().reduce((e, t) => (e[t.fieldKey] = t.value, e), {});
1238
+ return ft(e, {
1130
1239
  ...t,
1131
1240
  responses: n
1132
1241
  });
1133
1242
  };
1134
1243
  };
1135
1244
  //#endregion
1136
- //#region src/utils/get-step-fields.ts
1137
- function $(e) {
1138
- return e.options?.some((e) => "condition" in e) ?? !1;
1139
- }
1140
- function nt(e) {
1141
- return e.some((e) => e.condition || $(e));
1142
- }
1143
- async function rt(e, t) {
1144
- return t.length === 0 || !nt(t) ? t : (await Promise.all(t.map(async (t) => {
1145
- if (!(!t.condition || await r(e, t.condition))) return null;
1146
- if (!t.options || !$(t)) return t;
1147
- let n = (await Promise.all(t.options.map(async (t) => t.condition ? await r(e, t.condition) ? t : null : t))).filter((e) => e !== null);
1148
- return n.length === t.options.length ? t : n.length === 0 ? null : {
1149
- ...t,
1150
- options: n
1151
- };
1152
- }))).filter((e) => e !== null);
1153
- }
1154
- //#endregion
1155
1245
  //#region src/entities/component/lazyComponent.ts
1156
- function it(e) {
1246
+ function pt(e) {
1157
1247
  return {
1158
1248
  $$type: "lazy-component",
1159
1249
  load: e
1160
1250
  };
1161
1251
  }
1162
- function at(e) {
1252
+ function mt(e) {
1163
1253
  return typeof e == "object" && !!e && "$$type" in e && e.$$type === "lazy-component";
1164
1254
  }
1165
1255
  //#endregion
1166
1256
  //#region src/exports.ts
1167
- var ot = (e) => {
1168
- let t = new Q(e);
1169
- return te(t), t;
1257
+ var ht = (e) => {
1258
+ let t = new $(e);
1259
+ return d(t), t;
1170
1260
  };
1171
1261
  //#endregion
1172
- export { Q as Picked, ot as createClient, b as createStorageKey, r as evaluateRuleLogic, Y as getPickedConfig, rt as getStepFields, at as isLazyLoader, s as isPickedRoot, it as lazyComponent, v as localStore, y as sessionStore, ae as subscribe, re as supportsCookies, h as supportsCryptoRandomUUID, _ as supportsDocument, ee as supportsHistory, d as supportsIntersectionObserver, g as supportsLocalStorage, ne as supportsLocation, f as supportsSessionStorage, m as supportsShadowRoot, ie as supportsWebComponents, p as supportsWindow };
1262
+ export { $ as Picked, ht as createClient, S as createStorageKey, t as evaluateRuleLogic, Z as getPickedConfig, mt as isLazyLoader, _ as isPickedRoot, pt as lazyComponent, b as localStore, x as sessionStore, ie as subscribe, m as supportsCookies, l as supportsCryptoRandomUUID, f as supportsDocument, s as supportsHistory, i as supportsIntersectionObserver, u as supportsLocalStorage, p as supportsLocation, a as supportsSessionStorage, c as supportsShadowRoot, h as supportsWebComponents, o as supportsWindow };