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

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