@picked/client 0.0.1-dev.1774224866171 → 0.0.1-dev.1774244905386

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