@picked/client 0.0.11 → 0.0.12-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/plugins/create-experience/index.js +1 -1
  3. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  4. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  5. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  6. package/dist/cjs/server/index.js +1 -1
  7. package/dist/esm/index.js +535 -481
  8. package/dist/esm/plugins/create-experience/index.js +229 -178
  9. package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
  10. package/dist/esm/plugins/history-browser-storage/index.js +1 -1
  11. package/dist/esm/plugins/responses-browser-storage/index.js +1 -1
  12. package/dist/esm/server/index.js +1 -1
  13. package/dist/experience-instance-CF6m7G83.cjs +1 -0
  14. package/dist/experience-instance-CKru5var.js +781 -0
  15. package/dist/storage-Cb_71y48.js +94 -0
  16. package/dist/storage-DuRlyFaY.cjs +1 -0
  17. package/dist/types/client.d.ts +26 -0
  18. package/dist/types/client.d.ts.map +1 -1
  19. package/dist/types/entities/action/action.d.ts +15 -0
  20. package/dist/types/entities/action/action.d.ts.map +1 -0
  21. package/dist/types/entities/experience/experience.d.ts +19 -6
  22. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  23. package/dist/types/entities/experience-instance/experience-instance.d.ts +3 -3
  24. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  25. package/dist/types/entities/feature/feature.d.ts +5 -2
  26. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  27. package/dist/types/picked.d.ts +14 -4
  28. package/dist/types/picked.d.ts.map +1 -1
  29. package/dist/types/plugins/create-experience/create-experience.d.ts +23 -5
  30. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  31. package/dist/types/utils/events.d.ts +10 -4
  32. package/dist/types/utils/events.d.ts.map +1 -1
  33. package/dist/types/utils/nodes.d.ts +2 -1
  34. package/dist/types/utils/nodes.d.ts.map +1 -1
  35. package/dist/types/utils/storage.d.ts.map +1 -1
  36. package/package.json +6 -6
  37. package/dist/experience-instance-DXWLnF-R.cjs +0 -1
  38. package/dist/experience-instance-XlIuqLrL.js +0 -716
  39. package/dist/storage-BxBBl9Bw.js +0 -93
  40. package/dist/storage-LI3UdcCr.cjs +0 -1
package/dist/esm/index.js CHANGED
@@ -1,206 +1,207 @@
1
- var G = Object.defineProperty;
2
- var W = (t, e, s) => e in t ? G(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
- var h = (t, e, s) => W(t, typeof e != "symbol" ? e + "" : e, s);
4
- import { createDomain as I, createApi as x, createEffect as O, attach as Y, sample as P, combine as A, createEvent as C } from "effector";
5
- import { createFactory as k, invoke as b } from "@withease/factories";
6
- import { g as U, t as J, c as Q, e as R, i as X, a as Z, b as ee, d as te } from "../experience-instance-XlIuqLrL.js";
7
- import { f as gt } from "../experience-instance-XlIuqLrL.js";
1
+ var W = Object.defineProperty;
2
+ var Y = (t, e, r) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var m = (t, e, r) => Y(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { createDomain as I, createApi as x, createEffect as M, attach as J, sample as F, combine as O, createEvent as C } from "effector";
5
+ import { createFactory as w, invoke as k } from "@withease/factories";
6
+ import { g as U, t as Q, c as X, i as Z, e as A, a as ee, b as te, d as re } from "../experience-instance-CKru5var.js";
7
+ import { f as St } from "../experience-instance-CKru5var.js";
8
8
  import { l as v } from "../logger-C9a75KZn.js";
9
- import { c as $, s as B, l as D } from "../storage-BxBBl9Bw.js";
10
- import { a as mt } from "../storage-BxBBl9Bw.js";
11
- import { g as re } from "../id-BW-g3y32.js";
12
- import { i as se } from "../object-JwZ58NOH.js";
13
- import { s as z, a as ne, b as oe, c as ie, d as ae } from "../supports-BjhuLJ8z.js";
14
- import { h as yt, f as St, j as wt, e as vt, g as kt, i as bt, k as It } from "../supports-BjhuLJ8z.js";
15
- const _ = I("experience"), ce = k(
9
+ import { c as B, s as $, l as D } from "../storage-Cb_71y48.js";
10
+ import { a as wt } from "../storage-Cb_71y48.js";
11
+ import { g as se } from "../id-BW-g3y32.js";
12
+ import { i as ne } from "../object-JwZ58NOH.js";
13
+ import { s as _, a as oe, b as ie, c as ae, d as ce } from "../supports-BjhuLJ8z.js";
14
+ import { h as bt, f as It, j as xt, e as Ft, g as Et, i as Pt, k as Bt } from "../supports-BjhuLJ8z.js";
15
+ const H = I("experience"), ue = w(
16
16
  ({ client: t, experience: e }) => {
17
- const s = _.store(e), o = x(s, {
18
- merge(n, d) {
17
+ const r = H.store(e), n = x(r, {
18
+ merge(l, h) {
19
19
  return {
20
- ...n,
21
- ...d.experience
20
+ ...l,
21
+ ...h.experience
22
22
  };
23
23
  }
24
- }), i = s.map((n) => ({
25
- type: n.type,
26
- name: n.name,
27
- decisionLogic: n.decide,
28
- targetSelectors: n.targets
29
- })), l = t.components.listStore.map(
30
- (n) => n.find((d) => d.name === `experience:${e.id}`) || n.find((d) => d.name === "experience"),
24
+ }), c = r.map((l) => ({
25
+ name: l.name,
26
+ decisionLogic: l.decide,
27
+ targetSelectors: l.targets,
28
+ initializeOpenLogic: e.initializeOpen
29
+ })), u = t.components.listStore.map(
30
+ (l) => l.find((h) => h.name === `experience:${e.id}`) || l.find((h) => h.name === "experience"),
31
31
  { skipVoid: !1 }
32
- ), r = s.map((n) => ({
33
- steps: n.steps,
34
- nodes: n.nodes,
35
- edges: n.edges,
36
- conditionals: n.conditionals
37
- }));
32
+ ), s = r.map((l) => ({
33
+ steps: l.steps,
34
+ nodes: l.nodes,
35
+ edges: l.edges,
36
+ conditionals: l.conditionals
37
+ })), o = e.actions ?? [];
38
38
  return {
39
39
  id: e.id,
40
- configStore: i,
41
- treeStore: r,
42
- componentStore: l,
43
- merge: o.merge
40
+ configStore: c,
41
+ treeStore: s,
42
+ componentStore: u,
43
+ actions: o,
44
+ merge: n.merge
44
45
  };
45
46
  }
46
47
  );
47
- function ue(t) {
48
- return b(ce, t);
48
+ function le(t) {
49
+ return k(ue, t);
49
50
  }
50
- const le = k(({ client: t }) => {
51
- const e = _.store({}), s = x(e, {
52
- register(r, n) {
51
+ const de = w(({ client: t }) => {
52
+ const e = H.store({}), r = x(e, {
53
+ register(s, o) {
53
54
  return {
54
- ...r,
55
- [n.id]: n
55
+ ...s,
56
+ [o.id]: o
56
57
  };
57
58
  }
58
59
  });
59
- function o(r) {
60
- const n = e.getState()[r.id];
61
- if (n) {
62
- n.merge({ experience: r, strategy: "override" });
60
+ function n(s) {
61
+ const o = e.getState()[s.id];
62
+ if (o) {
63
+ o.merge({ experience: s, strategy: "override" });
63
64
  return;
64
65
  }
65
- const d = ue({ client: t, experience: r });
66
- s.register(d);
66
+ const l = le({ client: t, experience: s });
67
+ r.register(l);
67
68
  }
68
- const i = e.map((r) => Object.values(r));
69
- function l(r) {
70
- return e.map((n) => n[r], { skipVoid: !1 });
69
+ const c = e.map((s) => Object.values(s));
70
+ function u(s) {
71
+ return e.map((o) => o[s], { skipVoid: !1 });
71
72
  }
72
73
  return {
73
- register: o,
74
- getById: l,
75
- listStore: i
74
+ register: n,
75
+ getById: u,
76
+ listStore: c
76
77
  };
77
78
  });
78
- function de(t) {
79
- return b(le, t);
79
+ function pe(t) {
80
+ return k(de, t);
80
81
  }
81
- const pe = (t, e) => {
82
+ const ge = (t, e) => {
82
83
  e.register(t);
83
- }, H = (t, e) => {
84
- const { targetSelectors: s } = e.configStore.getState(), o = U(s, e.id);
85
- o.forEach(
86
- ({ elements: l }) => l.forEach((r) => J(r, e.id))
87
- ), Q(o, e.id).forEach((l) => {
88
- t.experienceInstances.spawn(e, l);
84
+ }, K = (t, e) => {
85
+ const { targetSelectors: r } = e.configStore.getState(), n = U(r, e.id);
86
+ n.forEach(
87
+ ({ elements: u }) => u.forEach((s) => Q(s, e.id))
88
+ ), X(n, e.id).forEach((u) => {
89
+ t.experienceInstances.spawn(e, u);
89
90
  });
90
- }, M = async (t) => {
91
+ }, T = async (t) => {
91
92
  await Promise.all(
92
93
  t.experiences.listStore.getState().map(async (e) => {
93
- await ge(t, e) && H(t, e);
94
+ await fe(t, e) && K(t, e);
94
95
  })
95
96
  );
96
- }, ge = async (t, e) => {
97
- const { type: s, decisionLogic: o, targetSelectors: i } = e.configStore.getState();
98
- return U(i, e.id).length < 1 ? !1 : s === "funnel" ? o ? await R(t, o) === !0 : !1 : i.length === 0 ? !1 : X(o) ? await R(t, o) === !0 : !0;
99
- }, fe = (t, e, s) => {
100
- const o = e.name, i = e.setup(t);
101
- if (i) {
102
- const l = s[o] ?? {};
103
- s[o] = Object.freeze({ ...l, ...i });
104
- }
105
- }, me = I("component"), he = k(
106
- ({ client: t, component: e, name: s }) => {
107
- const o = t.frameworks.getByName(e.frameworkName);
97
+ }, fe = async (t, e) => {
98
+ const { decisionLogic: r, targetSelectors: n } = e.configStore.getState();
99
+ return U(n, e.id).length < 1 || n.length === 0 ? !1 : r && Z(r) ? await A(t, r) === !0 : !0;
100
+ }, me = (t, e, r) => {
101
+ const n = e.name, c = e.setup(t);
102
+ if (c) {
103
+ const u = r[n] ?? {};
104
+ r[n] = Object.freeze({ ...u, ...c });
105
+ }
106
+ }, he = I("component"), ye = w(
107
+ ({ client: t, component: e, name: r }) => {
108
+ const n = t.frameworks.getByName(e.frameworkName);
108
109
  return {
109
- name: s,
110
+ name: r,
110
111
  component: e,
111
- frameworkStore: o
112
+ frameworkStore: n
112
113
  };
113
114
  }
114
115
  );
115
- function ye(t) {
116
- return b(he, t);
116
+ function Se(t) {
117
+ return k(ye, t);
117
118
  }
118
- const Se = k(({ client: t }) => {
119
- const e = me.store({}), s = x(e, {
120
- register(r, n) {
119
+ const ve = w(({ client: t }) => {
120
+ const e = he.store({}), r = x(e, {
121
+ register(s, o) {
121
122
  return {
122
- ...r,
123
- [n.name]: n
123
+ ...s,
124
+ [o.name]: o
124
125
  };
125
126
  }
126
127
  });
127
- function o(r, n) {
128
- e.getState()[r] && v(
128
+ function n(s, o) {
129
+ e.getState()[s] && v(
129
130
  "warn",
130
- `Component '${r}' already registered. Registering again will override the previous registration.`
131
+ `Component '${s}' already registered. Registering again will override the previous registration.`
131
132
  );
132
- const y = ye({ client: t, name: r, component: n });
133
- s.register(y);
133
+ const h = Se({ client: t, name: s, component: o });
134
+ r.register(h);
134
135
  }
135
- const i = e.map((r) => Object.values(r));
136
- function l(r) {
137
- return e.map((n) => n[r], { skipVoid: !1 });
136
+ const c = e.map((s) => Object.values(s));
137
+ function u(s) {
138
+ return e.map((o) => o[s], { skipVoid: !1 });
138
139
  }
139
140
  return {
140
- register: o,
141
- getByName: l,
142
- listStore: i
141
+ register: n,
142
+ getByName: u,
143
+ listStore: c
143
144
  };
144
145
  });
145
146
  function we(t) {
146
- return b(Se, t);
147
+ return k(ve, t);
147
148
  }
148
- const T = (t, e, s) => {
149
- s.register(t, e);
150
- }, ve = I("framework"), ke = k(({ client: t }) => {
151
- const e = ve.store({}), s = x(e, {
152
- register(r, n) {
149
+ const V = (t, e, r) => {
150
+ r.register(t, e);
151
+ }, ke = I("framework"), be = w(({ client: t }) => {
152
+ const e = ke.store({}), r = x(e, {
153
+ register(s, o) {
153
154
  return {
154
- ...r,
155
- [n.name]: n.framework
155
+ ...s,
156
+ [o.name]: o.framework
156
157
  };
157
158
  }
158
159
  });
159
- function o(r, n) {
160
- e.getState()[r] && v(
160
+ function n(s, o) {
161
+ e.getState()[s] && v(
161
162
  "warn",
162
- `Framework '${r}' already registered. Registering again will override the previous registration.`
163
- ), s.register({ name: r, framework: n });
163
+ `Framework '${s}' already registered. Registering again will override the previous registration.`
164
+ ), r.register({ name: s, framework: o });
164
165
  }
165
- const i = e.map((r) => Object.values(r));
166
- function l(r) {
167
- return e.map((n) => n[r], { skipVoid: !1 });
166
+ const c = e.map((s) => Object.values(s));
167
+ function u(s) {
168
+ return e.map((o) => o[s], { skipVoid: !1 });
168
169
  }
169
170
  return {
170
- register: o,
171
- getByName: l,
172
- listStore: i
171
+ register: n,
172
+ getByName: u,
173
+ listStore: c
173
174
  };
174
175
  });
175
- function be(t) {
176
- return b(ke, t);
176
+ function Ie(t) {
177
+ return k(be, t);
177
178
  }
178
- const Ie = (t, e) => {
179
+ const xe = (t, e) => {
179
180
  e.register(t.name, t);
180
- }, xe = 6e3, V = $("last_ping", "global"), Fe = (t) => `${t}/api/v1/ping`, Ee = async (t) => {
181
+ }, Fe = 6e3, N = B("last_ping", "global"), Ee = (t) => `${t}/api/v1/ping`, Pe = async (t) => {
181
182
  try {
182
- const e = Date.now(), s = localStorage.getItem(V);
183
- if (s && e - parseInt(s) < xe)
183
+ const e = Date.now(), r = localStorage.getItem(N);
184
+ if (r && e - parseInt(r) < Fe)
184
185
  return !0;
185
- const o = Fe(t.apiUrl), i = {
186
+ const n = Ee(t.apiUrl), c = {
186
187
  projectId: t.projectId,
187
188
  path: window.location.pathname
188
- }, l = JSON.stringify(i), r = {
189
+ }, u = JSON.stringify(c), s = {
189
190
  "Content-Type": "application/json"
190
- }, n = document.getElementById("picked_script"), d = n == null ? void 0 : n.dataset.verceltoken;
191
- d && (r["x-vercel-protection-bypass"] = d);
192
- const c = (await fetch(o, {
191
+ }, o = document.getElementById("picked_script"), l = o == null ? void 0 : o.dataset.verceltoken;
192
+ l && (s["x-vercel-protection-bypass"] = l);
193
+ const S = (await fetch(n, {
193
194
  method: "POST",
194
- headers: r,
195
- body: l
195
+ headers: s,
196
+ body: u
196
197
  })).ok;
197
- return c && localStorage.setItem(V, e.toString()), c;
198
+ return S && localStorage.setItem(N, e.toString()), S;
198
199
  } catch (e) {
199
200
  return v("error", e), !1;
200
201
  }
201
202
  };
202
- function Pe(t) {
203
- const e = typeof window < "u", s = {
203
+ function Be(t) {
204
+ const e = typeof window < "u", r = {
204
205
  client: t,
205
206
  responses: t.responses.listStore.getState(),
206
207
  fields: t.fields.listStore.getState(),
@@ -209,379 +210,418 @@ function Pe(t) {
209
210
  sessionStorage: e ? window.sessionStorage : void 0,
210
211
  localStorage: e ? window.localStorage : void 0
211
212
  };
212
- return Object.freeze(s);
213
+ return Object.freeze(r);
213
214
  }
214
- const Re = I("predicate"), $e = k(({ client: t }) => {
215
- const e = Re.store({}), s = x(e, {
216
- register(r, n) {
215
+ const Re = I("predicate"), Ae = w(({ client: t }) => {
216
+ const e = Re.store({}), r = x(e, {
217
+ register(s, o) {
217
218
  return {
218
- ...r,
219
- [n.name]: {
220
- name: n.name,
221
- predicate: n.predicate
219
+ ...s,
220
+ [o.name]: {
221
+ name: o.name,
222
+ predicate: o.predicate
222
223
  }
223
224
  };
224
225
  }
225
226
  });
226
- function o(r, n) {
227
- e.getState()[r] && v(
227
+ function n(s, o) {
228
+ e.getState()[s] && v(
228
229
  "warn",
229
- `Predicate '${r}' already registered. Registering again will override the previous registration.`
230
- ), s.register(Object.freeze({ name: r, predicate: n }));
230
+ `Predicate '${s}' already registered. Registering again will override the previous registration.`
231
+ ), r.register(Object.freeze({ name: s, predicate: o }));
231
232
  }
232
- const i = e.map((r) => Object.values(r));
233
- function l(r) {
234
- return e.map((n) => n[r], { skipVoid: !1 });
233
+ const c = e.map((s) => Object.values(s));
234
+ function u(s) {
235
+ return e.map((o) => o[s], { skipVoid: !1 });
235
236
  }
236
237
  return {
237
- register: o,
238
- getByName: l,
239
- listStore: i
238
+ register: n,
239
+ getByName: u,
240
+ listStore: c
240
241
  };
241
242
  });
242
- function Be(t) {
243
- return b($e, t);
243
+ function $e(t) {
244
+ return k(Ae, t);
244
245
  }
245
- const je = (t, e, s) => {
246
- s.register(t, e);
247
- }, N = I("feature"), Ae = k(() => {
248
- const t = N.store({}), e = N.store([]), s = x(t, {
249
- register(c, f) {
246
+ const je = (t, e, r) => {
247
+ r.register(t, e);
248
+ }, z = I("feature"), Oe = w(({ client: t }) => {
249
+ const e = z.store({}), r = z.store([]), n = x(e, {
250
+ register(d, a) {
250
251
  return {
251
- ...c,
252
- [f.id]: f.feature
252
+ ...d,
253
+ [a.id]: a.feature
253
254
  };
254
255
  }
255
256
  });
256
- function o(c, f) {
257
- t.getState()[c] && v(
257
+ function c(d, a) {
258
+ e.getState()[d] && v(
258
259
  "warn",
259
- `Feature '${c}' already registered. Registering again will override the previous registration.`
260
+ `Feature '${d}' already registered. Registering again will override the previous registration.`
260
261
  );
261
- const p = {
262
- id: c,
262
+ const g = {
263
+ id: d,
263
264
  feature: {
264
- ...f,
265
- id: c
265
+ ...a,
266
+ id: d
266
267
  }
267
268
  };
268
- s.register(
269
+ n.register(
269
270
  Object.freeze({
270
- id: c,
271
- feature: p
271
+ id: d,
272
+ feature: g
272
273
  })
273
274
  );
274
275
  }
275
- const i = O(
276
+ const u = M(
276
277
  async ({
277
- id: c,
278
- key: f,
279
- storage: a = "local"
278
+ id: d,
279
+ key: a,
280
+ storage: i = "local"
280
281
  }) => {
281
- const p = $(`feature:${c}:${f}`, "global"), m = (a === "session" ? B : D).get(p).boolean();
282
- if (m !== null)
283
- return { id: c, bucket: m };
282
+ const g = B(`feature:${d}:${a}`, "global"), p = (i === "session" ? $ : D).get(g).boolean();
283
+ return p === null ? null : { id: d, key: a, bucket: p };
284
284
  }
285
- ), l = O((c) => {
286
- if (!c)
285
+ ), s = M((d) => {
286
+ if (!d)
287
287
  return null;
288
- const f = $(`feature:${c.id}:${c.key}`, "global");
289
- (c.storage === "session" ? B : D).set(f, c.bucket);
290
- }), r = /* @__PURE__ */ new Map(), n = Y({
291
- source: { allFeaturesStore: t, resolvedFeaturesStore: e },
292
- effect: async ({ allFeaturesStore: c, resolvedFeaturesStore: f }, { id: a, decide: p, key: g }) => {
293
- const m = f.find((F) => F.id === a);
294
- if (m)
295
- return m;
296
- const u = c[a];
297
- if (!u)
298
- throw new Error(`Feature with id '${a}' not found`);
299
- const S = r.get(`${a}:${g}`);
300
- if (S !== void 0) {
301
- const F = await S;
302
- return { id: u.id, bucket: F, storage: u.feature.storage };
288
+ const a = B(`feature:${d.id}:${d.key}`, "global");
289
+ (d.storage === "session" ? $ : D).set(a, d.bucket);
290
+ }), o = /* @__PURE__ */ new Map(), l = J({
291
+ source: { allFeaturesStore: e, resolvedFeaturesStore: r },
292
+ effect: async ({ allFeaturesStore: d, resolvedFeaturesStore: a }, { id: i, decide: g, key: f }) => {
293
+ const p = a.find((j) => j.id === i);
294
+ if (p)
295
+ return p;
296
+ const y = d[i];
297
+ if (!y)
298
+ throw new Error(`Feature with id '${i}' not found`);
299
+ const b = o.get(`${i}:${f}`);
300
+ if (b !== void 0) {
301
+ const j = await b;
302
+ return { id: y.id, bucket: j, key: f, storage: y.feature.storage };
303
303
  }
304
- const w = p();
305
- r.set(`${a}:${g}`, w);
306
- const j = await w;
307
- return { id: u.id, bucket: j, storage: u.feature.storage };
304
+ const R = g();
305
+ o.set(`${i}:${f}`, R);
306
+ const E = await R;
307
+ return { id: y.id, bucket: E, key: f, storage: y.feature.storage };
308
308
  }
309
309
  });
310
- P({
311
- clock: s.register,
312
- fn: (c) => {
313
- const { id: f, feature: a } = c;
314
- return { id: f, key: a.feature.key, storage: a.feature.storage };
310
+ F({
311
+ clock: n.register,
312
+ fn: (d) => {
313
+ const { id: a, feature: i } = d;
314
+ return { id: a, key: i.feature.key, storage: i.feature.storage };
315
315
  },
316
- target: i
317
- }), P({
316
+ target: u
317
+ }), F({
318
318
  source: e,
319
- clock: [i.doneData, n.doneData],
320
- fn: (c, f) => !f || c.some((a) => a.id === f.id) ? c : [...c, f],
321
- target: e
322
- }), P({
323
- source: t,
324
- clock: n.doneData,
325
- fn: (c, f) => {
326
- var u;
327
- const { id: a, bucket: p, storage: g } = f, m = (u = c[a]) == null ? void 0 : u.feature.key;
328
- return m ? { key: m, id: a, bucket: p, storage: g } : null;
319
+ clock: l.doneData,
320
+ fn: (d, a) => {
321
+ var y;
322
+ const { id: i, bucket: g, storage: f } = a, p = (y = d[i]) == null ? void 0 : y.feature.key;
323
+ return p ? { key: p, id: i, bucket: g, storage: f } : null;
329
324
  },
330
- target: l
325
+ target: s
331
326
  });
332
- const d = A({ allFeaturesStore: t, resolvedFeaturesStore: e }).map(
327
+ const h = O({ allFeaturesStore: e, resolvedFeaturesStore: r }).map(
333
328
  ({
334
- allFeaturesStore: c,
335
- resolvedFeaturesStore: f
336
- }) => Object.values(c).map((a) => {
337
- const p = f.find((g) => g.id === a.id);
338
- return p ? {
339
- id: a.id,
340
- name: a.feature.name,
341
- key: a.feature.key,
342
- getBucket: () => ({ id: a.id, bucket: p.bucket }),
329
+ allFeaturesStore: d,
330
+ resolvedFeaturesStore: a
331
+ }) => Object.values(d).map((i) => {
332
+ const g = a.find((f) => f.id === i.id);
333
+ return g ? {
334
+ id: i.id,
335
+ name: i.feature.name,
336
+ key: i.feature.key,
337
+ getBucket: () => ({ id: i.id, bucket: g.bucket }),
343
338
  isResolved: !0
344
339
  } : {
345
- id: a.id,
346
- name: a.feature.name,
347
- key: a.feature.key,
348
- getBucket: async () => await n(a.feature),
340
+ id: i.id,
341
+ name: i.feature.name,
342
+ key: i.feature.key,
343
+ getBucket: async () => await l(i.feature),
349
344
  isResolved: !1
350
345
  };
351
346
  })
352
347
  );
353
- function y(c) {
354
- return t.map((f) => f[c], { skipVoid: !1 });
348
+ F({
349
+ clock: l.doneData,
350
+ source: { resolvedFeatures: r },
351
+ filter: ({ resolvedFeatures: d }, { id: a }) => !d.some((i) => i.id === a),
352
+ fn: (d, a) => a,
353
+ target: t.eventBus.prepend((d) => ({
354
+ type: "feature_decide",
355
+ feature: d
356
+ }))
357
+ }), F({
358
+ clock: [u.doneData, l.doneData],
359
+ source: r,
360
+ fn: (d, a) => !a || d.some((i) => i.id === a.id) ? d : [...d, a],
361
+ target: r
362
+ });
363
+ function S(d) {
364
+ return e.map((a) => a[d], { skipVoid: !1 });
355
365
  }
356
366
  return {
357
- register: o,
358
- getByName: y,
359
- listStore: d
367
+ register: c,
368
+ getByName: S,
369
+ listStore: h
360
370
  };
361
371
  });
362
- function Ce() {
363
- return b(Ae);
372
+ function Ce(t) {
373
+ return k(Oe, t);
364
374
  }
365
- const De = (t, e, s) => {
366
- s.register(t, e);
367
- }, E = I("history");
375
+ const De = (t, e, r) => {
376
+ r.register(t, e);
377
+ }, P = I("history");
368
378
  function L(t, e) {
369
379
  return {
370
380
  // eslint-disable-next-line sonarjs/pseudo-random
371
- id: re(`history-entry-${Date.now()}-${Math.random()}}`),
381
+ id: se(`history-entry-${Date.now()}-${Math.random()}}`),
372
382
  node: e,
373
383
  at: Date.now(),
374
384
  experienceId: t
375
385
  };
376
386
  }
377
- const Oe = k(() => {
378
- const t = E.store({ entries: [] }), e = E.event(), s = E.event(), o = E.event(), i = E.event();
379
- t.on(e, (r, n) => ({
380
- entries: [...r.entries, L(n.experienceId, n.node)]
381
- })), t.on(s, (r, n) => ({
387
+ const Me = w(() => {
388
+ const t = P.store({ entries: [] }), e = P.event(), r = P.event(), n = P.event(), c = P.event();
389
+ t.on(e, (s, o) => ({
390
+ entries: [...s.entries, L(o.experienceId, o.node)]
391
+ })), t.on(r, (s, o) => ({
382
392
  entries: [
383
- ...r.entries.slice(0, -1),
384
- L(n.experienceId, n.node)
393
+ ...s.entries.slice(0, -1),
394
+ L(o.experienceId, o.node)
385
395
  ]
386
- })), t.on(i, (r, n) => n);
387
- function l(r, n) {
388
- const d = { lastStepIndex: -1, secondLastStepIndex: -1 };
389
- for (let y = r.length - 1; y >= 0; y--) {
390
- const c = r[y], f = c == null ? void 0 : c.node;
391
- if (!(!f || !Z(f)) && !(n && (c == null ? void 0 : c.experienceId) !== n))
392
- if (d.lastStepIndex === -1)
393
- d.lastStepIndex = y;
396
+ })), t.on(c, (s, o) => o);
397
+ function u(s, o) {
398
+ const l = { lastStepIndex: -1, secondLastStepIndex: -1 };
399
+ for (let h = s.length - 1; h >= 0; h--) {
400
+ const S = s[h], d = S == null ? void 0 : S.node;
401
+ if (!(!d || !ee(d)) && !(o && (S == null ? void 0 : S.experienceId) !== o))
402
+ if (l.lastStepIndex === -1)
403
+ l.lastStepIndex = h;
394
404
  else {
395
- d.secondLastStepIndex = y;
405
+ l.secondLastStepIndex = h;
396
406
  break;
397
407
  }
398
408
  }
399
- return d;
409
+ return l;
400
410
  }
401
- return t.on(o, (r, n) => {
402
- const { secondLastStepIndex: d } = l(r.entries, n.experienceId), y = d !== -1 ? r.entries.slice(0, d + 1) : r.entries;
411
+ return t.on(n, (s, o) => {
412
+ const { secondLastStepIndex: l } = u(s.entries, o.experienceId), h = l !== -1 ? s.entries.slice(0, l + 1) : s.entries;
403
413
  return {
404
- ...r,
405
- entries: y
414
+ ...s,
415
+ entries: h
406
416
  };
407
417
  }), {
408
418
  push: e,
409
- replace: s,
410
- back: o,
411
- restore: i,
412
- entriesStore: t.map((r) => r.entries)
419
+ replace: r,
420
+ back: n,
421
+ restore: c,
422
+ entriesStore: t.map((s) => s.entries)
413
423
  };
414
424
  });
415
- function Me() {
416
- return b(Oe);
425
+ function Te() {
426
+ return k(Me);
417
427
  }
418
- const Te = () => C(), Ve = I("field"), Ne = k(() => {
419
- const t = Ve.store({}), e = x(t, {
420
- register(r, n) {
428
+ const Ve = () => C(), Ne = I("field"), ze = w(() => {
429
+ const t = Ne.store({}), e = x(t, {
430
+ register(s, o) {
421
431
  return {
422
- ...r,
423
- [n.field.id]: n.field
432
+ ...s,
433
+ [o.field.id]: o.field
424
434
  };
425
435
  }
426
436
  });
427
- function s(r) {
428
- e.register({ field: r });
437
+ function r(s) {
438
+ e.register({ field: s });
429
439
  }
430
- const o = t.map((r) => Object.values(r));
431
- function i(r) {
432
- return t.map((n) => n[r] || null);
440
+ const n = t.map((s) => Object.values(s));
441
+ function c(s) {
442
+ return t.map((o) => o[s] || null);
433
443
  }
434
- function l(r) {
435
- return t.map((n) => Object.values(n).find((d) => d.name === r) || null);
444
+ function u(s) {
445
+ return t.map((o) => Object.values(o).find((l) => l.name === s) || null);
436
446
  }
437
447
  return {
438
- register: s,
439
- getById: i,
440
- listStore: o,
441
- getByName: l
448
+ register: r,
449
+ getById: c,
450
+ listStore: n,
451
+ getByName: u
442
452
  };
443
453
  });
444
454
  function Le() {
445
- return b(Ne);
455
+ return k(ze);
446
456
  }
447
457
  const Ue = (t, e) => {
448
458
  e.register(t);
449
- }, ze = I("response"), _e = k(({ client: t }) => {
450
- const e = ze.store({}), s = C(), o = C(), i = x(e, {
451
- register(a, p) {
459
+ }, _e = I("action"), He = w(() => {
460
+ const t = _e.store({}), e = x(t, {
461
+ register(u, s) {
462
+ return {
463
+ ...u,
464
+ [s.name]: {
465
+ name: s.name,
466
+ action: s.action
467
+ }
468
+ };
469
+ }
470
+ });
471
+ function r(u, s) {
472
+ e.register({ name: u, action: s });
473
+ }
474
+ const n = t.map((u) => Object.values(u));
475
+ function c(u) {
476
+ return t.map((s) => s[u], { skipVoid: !1 });
477
+ }
478
+ return {
479
+ register: r,
480
+ getByName: c,
481
+ listStore: n
482
+ };
483
+ });
484
+ function Ke() {
485
+ return k(He);
486
+ }
487
+ const qe = (t, e, r) => {
488
+ r.register(t, e);
489
+ }, Ge = I("response"), We = w(({ client: t }) => {
490
+ const e = Ge.store({}), r = C(), n = C(), c = x(e, {
491
+ register(a, i) {
452
492
  return {
453
493
  ...a,
454
- [p.fieldId]: p.response
494
+ [i.fieldId]: i.response
455
495
  };
456
496
  },
457
- registerBatch(a, p) {
497
+ registerBatch(a, i) {
458
498
  return {
459
499
  ...a,
460
- ...p
500
+ ...i
461
501
  };
462
502
  },
463
- clear(a, p) {
464
- const { [p]: g, ...m } = a;
465
- return m;
503
+ clear(a, i) {
504
+ const { [i]: g, ...f } = a;
505
+ return f;
466
506
  },
467
507
  clearAll() {
468
508
  return {};
469
509
  }
470
510
  });
471
- function l(a, p) {
472
- i.register({ fieldId: a, response: p });
511
+ function u(a, i) {
512
+ c.register({ fieldId: a, response: i });
473
513
  }
474
- async function r(a) {
475
- const p = [];
514
+ async function s(a) {
515
+ const i = [];
476
516
  return await Promise.allSettled(
477
- Object.entries(a).map(async ([g, m]) => {
478
- let u = m;
479
- const S = t.fields.getById(g).getState();
480
- if (!S) {
481
- p.push({
517
+ Object.entries(a).map(async ([g, f]) => {
518
+ let p = f;
519
+ const y = t.fields.getById(g).getState();
520
+ if (!y) {
521
+ i.push({
482
522
  fieldId: g,
483
523
  userMessage: `Field '${g}' not found`,
484
524
  systemMessage: `No field with ID '${g}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
485
- value: u
525
+ value: p
486
526
  });
487
527
  return;
488
528
  }
489
- if (S.multiple && (typeof u == "string" || typeof u == "number" || typeof u == "boolean") && (u = [u]), S.validation && !se(S.validation)) {
490
- const w = await R(t, S.validation, {
491
- $input: u
529
+ if (y.multiple && (typeof p == "string" || typeof p == "number" || typeof p == "boolean") && (p = [p]), y.validation && !ne(y.validation)) {
530
+ const b = await A(t, y.validation, {
531
+ $input: p
492
532
  });
493
- if (typeof w == "string") {
494
- p.push({
533
+ if (typeof b == "string") {
534
+ i.push({
495
535
  fieldId: g,
496
- userMessage: w,
497
- systemMessage: `Field validation resulted in an error: ${w}.`,
498
- value: u
536
+ userMessage: b,
537
+ systemMessage: `Field validation resulted in an error: ${b}.`,
538
+ value: p
499
539
  });
500
540
  return;
501
541
  }
502
- if (w === !1) {
503
- p.push({
542
+ if (b === !1) {
543
+ i.push({
504
544
  fieldId: g,
505
545
  userMessage: "This field is invalid",
506
546
  systemMessage: "Field validation resulted in an unspecified error.",
507
- value: u
547
+ value: p
508
548
  });
509
549
  return;
510
550
  }
511
551
  }
512
- if (S.required && (typeof u > "u" || u === null || u === "" || Array.isArray(u) && !u.length)) {
513
- p.push({
552
+ if (y.required && (typeof p > "u" || p === null || p === "" || Array.isArray(p) && !p.length)) {
553
+ i.push({
514
554
  fieldId: g,
515
555
  userMessage: "This field is required",
516
556
  systemMessage: "Field is required.",
517
- value: u
557
+ value: p
518
558
  });
519
559
  return;
520
560
  }
521
- if (!S.multiple && Array.isArray(u) && u.length > 1) {
522
- p.push({
561
+ if (!y.multiple && Array.isArray(p) && p.length > 1) {
562
+ i.push({
523
563
  fieldId: g,
524
564
  userMessage: "This field expects a single response",
525
565
  systemMessage: "Field expects a single response.",
526
- value: u
566
+ value: p
527
567
  });
528
568
  return;
529
569
  }
530
- if (S.options) {
531
- const w = S.options.map((F) => F.value), j = Array.isArray(u) ? u : [u];
532
- Array.isArray(u) && (j.every((F) => w.includes(F)) || p.push({
570
+ if (y.options) {
571
+ const b = y.options.map((E) => E.value), R = Array.isArray(p) ? p : [p];
572
+ Array.isArray(p) && (R.every((E) => b.includes(E)) || i.push({
533
573
  fieldId: g,
534
574
  userMessage: "This field expects a valid option",
535
- systemMessage: `Field expects a valid option. Valid options are: ${w.join(", ")}`,
536
- value: u
575
+ systemMessage: `Field expects a valid option. Valid options are: ${b.join(", ")}`,
576
+ value: p
537
577
  }));
538
578
  }
539
579
  })
540
- ), { responsesToCommit: a, validationErrors: p };
580
+ ), { responsesToCommit: a, validationErrors: i };
541
581
  }
542
- async function n(a) {
543
- const { responsesToCommit: p, validationErrors: g } = await r(a);
544
- return g.length ? { errors: g } : (i.registerBatch(p), { errors: [] });
582
+ async function o(a) {
583
+ const { responsesToCommit: i, validationErrors: g } = await s(a);
584
+ return g.length ? { errors: g } : (c.registerBatch(i), { errors: [] });
545
585
  }
546
- const d = e.map((a) => a), y = e.map((a) => Object.keys(a).map((g) => ({
586
+ const l = e.map((a) => a), h = e.map((a) => Object.keys(a).map((g) => ({
547
587
  fieldId: g,
548
588
  value: a[g]
549
589
  })));
550
- function c(a) {
551
- const p = t.fields.getById(a), g = e.map((m) => m[a] || null);
552
- return A({ f: p, r: g }, ({ f: m, r: u }) => u || (m != null && m.defaultValue ? m.defaultValue : null));
553
- }
554
- function f(a) {
555
- const p = t.fields.getByName(a);
556
- return A({ f: p, s: e }, ({ f: g, s: m }) => {
557
- const u = g && m[g.id] || null;
558
- return u || (g != null && g.defaultValue ? g.defaultValue : null);
590
+ function S(a) {
591
+ const i = t.fields.getById(a), g = e.map((f) => f[a] || null);
592
+ return O({ f: i, r: g }, ({ f, r: p }) => p || (f != null && f.defaultValue ? f.defaultValue : null));
593
+ }
594
+ function d(a) {
595
+ const i = t.fields.getByName(a);
596
+ return O({ f: i, s: e }, ({ f: g, s: f }) => {
597
+ const p = g && f[g.id] || null;
598
+ return p || (g != null && g.defaultValue ? g.defaultValue : null);
559
599
  });
560
600
  }
561
- return P({
562
- clock: s,
563
- target: i.clearAll
564
- }), P({
565
- clock: o,
566
- target: i.clear
601
+ return F({
602
+ clock: r,
603
+ target: c.clearAll
604
+ }), F({
605
+ clock: n,
606
+ target: c.clear
567
607
  }), {
568
- register: l,
569
- clearAll: s,
570
- clear: o,
571
- commit: n,
572
- getResponsesToCommit: r,
573
- listStore: y,
574
- getAllStore: d,
575
- getByFieldId: c,
576
- getByFieldName: f
608
+ register: u,
609
+ clearAll: r,
610
+ clear: n,
611
+ commit: o,
612
+ getResponsesToCommit: s,
613
+ listStore: h,
614
+ getAllStore: l,
615
+ getByFieldId: S,
616
+ getByFieldName: d
577
617
  };
578
618
  });
579
- function He(t) {
580
- return b(_e, t);
619
+ function Ye(t) {
620
+ return k(We, t);
581
621
  }
582
- const Ke = () => "0.0.11";
583
- function qe() {
584
- if (z()) {
622
+ const Je = () => "0.0.12-next.10";
623
+ function Qe() {
624
+ if (_()) {
585
625
  const t = [
586
626
  document.currentScript,
587
627
  document.getElementById("picked_script"),
@@ -595,99 +635,103 @@ function qe() {
595
635
  }
596
636
  return "https://api.picked.app";
597
637
  }
598
- function Ge() {
599
- if (!ne())
638
+ function Xe() {
639
+ if (!oe())
600
640
  return {};
601
- const t = new URLSearchParams(window.location.search), e = {}, s = /* @__PURE__ */ new Set();
602
- for (const [i] of t.entries())
603
- i.startsWith("picked-") && s.add(i);
604
- for (const i of s) {
605
- const l = i.replace("picked-", "");
606
- e[l] = t.getAll(i);
607
- }
608
- const o = $("s");
609
- if (s.size > 0)
610
- B.set(o, e);
641
+ const t = new URLSearchParams(window.location.search), e = {}, r = /* @__PURE__ */ new Set();
642
+ for (const [c] of t.entries())
643
+ c.startsWith("picked-") && r.add(c);
644
+ for (const c of r) {
645
+ const u = c.replace("picked-", "");
646
+ e[u] = t.getAll(c);
647
+ }
648
+ const n = B("s");
649
+ if (r.size > 0)
650
+ $.set(n, e);
611
651
  else {
612
- const i = B.get(o);
613
- if (i)
614
- return i.json() || {};
652
+ const c = $.get(n);
653
+ if (c)
654
+ return c.json() || {};
615
655
  }
616
656
  return e;
617
657
  }
618
- function We() {
619
- if (ie())
658
+ function Ze() {
659
+ if (ae())
620
660
  return crypto.randomUUID();
621
- const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), s = Math.random().toString(36).substring(2, 15), o = Math.random().toString(36).substring(2, 15);
622
- return `${t}-${e}-${s}-${o}`;
661
+ const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), r = Math.random().toString(36).substring(2, 15), n = Math.random().toString(36).substring(2, 15);
662
+ return `${t}-${e}-${r}-${n}`;
623
663
  }
624
- const Ye = () => ({
625
- id: We()
626
- }), Je = $("session", "global"), Qe = () => {
627
- if (!oe()) return null;
628
- const t = D.get(Je);
664
+ const et = () => ({
665
+ id: Ze()
666
+ }), tt = B("session", "global"), rt = () => {
667
+ if (!ie()) return null;
668
+ const t = D.get(tt);
629
669
  let e = t.isSet() ? t.json() : null;
630
- return e || (e = Ye(), t.set(e)), e;
631
- }, Xe = () => Qe();
632
- class K {
670
+ return e || (e = et(), t.set(e)), e;
671
+ }, st = () => rt();
672
+ class q {
633
673
  constructor(e) {
634
- h(this, "options");
635
- h(this, "isReady", !1);
636
- h(this, "project");
637
- h(this, "plugins", {});
638
- h(this, "eventBus", Te());
639
- h(this, "organizationId");
640
- h(this, "projectId");
641
- h(this, "apiUrl");
642
- h(this, "session");
643
- h(this, "searchParams", Ge());
644
- h(this, "history", Me());
645
- h(this, "components", we({ client: this }));
646
- h(this, "experienceInstances", ee({ client: this }));
647
- h(this, "experiences", de({ client: this }));
648
- h(this, "frameworks", be({ client: this }));
649
- h(this, "predicates", Be({ client: this }));
650
- h(this, "features", Ce());
651
- h(this, "responses", He({ client: this }));
652
- h(this, "fields", Le());
653
- v("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || qe(), this.session = Xe(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.eventBus({ type: "initialized", version: Ke() }), v("info", "Picked client initialized.");
674
+ m(this, "options");
675
+ m(this, "isReady", !1);
676
+ m(this, "project");
677
+ m(this, "plugins", {});
678
+ m(this, "eventBus", Ve());
679
+ m(this, "organizationId");
680
+ m(this, "projectId");
681
+ m(this, "apiUrl");
682
+ m(this, "session");
683
+ m(this, "searchParams", Xe());
684
+ m(this, "history", Te());
685
+ m(this, "components", we({ client: this }));
686
+ m(this, "experienceInstances", te({ client: this }));
687
+ m(this, "experiences", pe({ client: this }));
688
+ m(this, "frameworks", Ie({ client: this }));
689
+ m(this, "predicates", $e({ client: this }));
690
+ m(this, "features", Ce({ client: this }));
691
+ m(this, "responses", Ye({ client: this }));
692
+ m(this, "fields", Le());
693
+ m(this, "actions", Ke());
694
+ v("info", "Picked client initializing."), this.organizationId = e.organizationId, this.projectId = e.projectId, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || Qe(), this.session = st(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.eventBus({ type: "initialized", version: Je() }), v("info", "Picked client initialized.");
654
695
  }
655
696
  start() {
656
- Ee(this), (async () => {
657
- z() && (document.body && M(this), await te(), await M(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session }));
697
+ Pe(this), (async () => {
698
+ _() && (document.body && T(this), await re(), await T(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session }));
658
699
  })();
659
700
  }
660
701
  registerFramework(e) {
661
- Ie(e, this.frameworks);
702
+ xe(e, this.frameworks);
662
703
  }
663
- registerComponent(e, s) {
664
- T(e, s, this.components);
704
+ registerComponent(e, r) {
705
+ V(e, r, this.components);
665
706
  }
666
707
  registerPlugin(e) {
667
- fe(this, e, this.plugins);
708
+ me(this, e, this.plugins);
668
709
  }
669
- registerFeature(e, s) {
670
- De(e, s, this.features);
710
+ registerFeature(e, r) {
711
+ De(e, r, this.features);
671
712
  }
672
- registerPredicate(e, s) {
673
- je(e, s, this.predicates);
713
+ registerPredicate(e, r) {
714
+ je(e, r, this.predicates);
674
715
  }
675
716
  registerField(e) {
676
717
  Ue(e, this.fields);
677
718
  }
719
+ registerAction(e, r) {
720
+ qe(e, r, this.actions);
721
+ }
678
722
  registerExperience(e) {
679
- e.component && T(`experience:${e.id}`, e.component, this.components), pe(e, this.experiences);
723
+ e.component && V(`experience:${e.id}`, e.component, this.components), ge(e, this.experiences);
680
724
  }
681
725
  getStateSnapshot() {
682
- return Pe(this);
726
+ return Be(this);
683
727
  }
684
728
  async launchExperienceById(e) {
685
- const s = this.experiences.getById(e).getState();
686
- if (!s) {
729
+ const r = this.experiences.getById(e).getState();
730
+ if (!r) {
687
731
  v("warn", `Experience with id '${e}' not found.`);
688
732
  return;
689
733
  }
690
- H(this, s);
734
+ K(this, r);
691
735
  }
692
736
  // private async fetchProject() {
693
737
  // if (this.project) {
@@ -700,38 +744,38 @@ class K {
700
744
  // }
701
745
  setupPlugins() {
702
746
  var e;
703
- (e = this.options.plugins) == null || e.forEach((s) => {
704
- if (Array.isArray(s)) {
705
- s.forEach((i) => {
706
- this.registerPlugin(i);
747
+ (e = this.options.plugins) == null || e.forEach((r) => {
748
+ if (Array.isArray(r)) {
749
+ r.forEach((c) => {
750
+ this.registerPlugin(c);
707
751
  });
708
752
  return;
709
753
  }
710
- const o = typeof s == "function" ? s() : s;
711
- if (Array.isArray(o)) {
712
- o.forEach((i) => this.registerPlugin(i));
754
+ const n = typeof r == "function" ? r() : r;
755
+ if (Array.isArray(n)) {
756
+ n.forEach((c) => this.registerPlugin(c));
713
757
  return;
714
758
  }
715
- this.registerPlugin(o);
759
+ this.registerPlugin(n);
716
760
  });
717
761
  }
718
762
  setupFeatures() {
719
763
  const e = this.options.features;
720
- e && (Object.entries(e).forEach(([s, o]) => {
721
- const i = typeof o == "function" ? o() : o;
722
- this.registerFeature(s, i);
723
- }), this.searchParams.feature && this.searchParams.feature.forEach((s) => {
764
+ e && (Object.entries(e).forEach(([r, n]) => {
765
+ const c = typeof n == "function" ? n() : n;
766
+ this.registerFeature(r, c);
767
+ }), this.searchParams.feature && this.searchParams.feature.forEach((r) => {
724
768
  try {
725
- const [o, i] = s.split(":");
726
- if (!o || !i)
769
+ const [n, c] = r.split(":");
770
+ if (!n || !c)
727
771
  return;
728
- let l = i;
729
- l === "true" && (l = !0), l === "false" && (l = !1), this.registerFeature(o, {
730
- key: `${l}`,
772
+ let u = c;
773
+ u === "true" && (u = !0), u === "false" && (u = !1), this.registerFeature(n, {
774
+ key: `${u}`,
731
775
  // use the assigned bucket value as the key
732
- name: o,
776
+ name: n,
733
777
  // eslint-disable-next-line sonarjs/function-return-type
734
- decide: () => l,
778
+ decide: () => u,
735
779
  storage: "session"
736
780
  });
737
781
  } catch {
@@ -740,63 +784,73 @@ class K {
740
784
  }
741
785
  setupPredicates() {
742
786
  const e = this.options.predicates;
743
- e && Object.entries(e).forEach(([s, o]) => {
744
- if (typeof o != "function") {
745
- v("warn", `Predicate "${s}" is not a function.`);
787
+ e && Object.entries(e).forEach(([r, n]) => {
788
+ if (typeof n != "function") {
789
+ v("warn", `Predicate "${r}" is not a function.`);
790
+ return;
791
+ }
792
+ this.registerPredicate(r, n);
793
+ });
794
+ }
795
+ setupActions() {
796
+ const e = this.options.actions;
797
+ e && Object.entries(e).forEach(([r, n]) => {
798
+ if (typeof n != "function") {
799
+ v("warn", `Action "${r}" is not a function.`);
746
800
  return;
747
801
  }
748
- this.registerPredicate(s, o);
802
+ this.registerAction(r, n);
749
803
  });
750
804
  }
751
805
  getPluginConfig(e) {
752
806
  return this.plugins[e] ?? {};
753
807
  }
754
808
  }
755
- h(K, "logger", v);
756
- function q(t) {
809
+ m(q, "logger", v);
810
+ function G(t) {
757
811
  var e;
758
- return ((e = t.options) == null ? void 0 : e.some((s) => "condition" in s)) ?? !1;
812
+ return ((e = t.options) == null ? void 0 : e.some((r) => "condition" in r)) ?? !1;
759
813
  }
760
- function Ze(t) {
761
- return t.some((e) => e.condition || q(e));
814
+ function nt(t) {
815
+ return t.some((e) => e.condition || G(e));
762
816
  }
763
- async function ut(t, e) {
764
- return e.length === 0 || !Ze(e) ? e : (await Promise.all(
765
- e.map(async (o) => {
766
- if (!(o.condition ? await R(t, o.condition) : !0))
817
+ async function ft(t, e) {
818
+ return e.length === 0 || !nt(e) ? e : (await Promise.all(
819
+ e.map(async (n) => {
820
+ if (!(n.condition ? await A(t, n.condition) : !0))
767
821
  return null;
768
- if (!o.options || !q(o))
769
- return o;
770
- const r = (await Promise.all(
771
- o.options.map(async (d) => d.condition ? await R(t, d.condition) ? d : null : d)
772
- )).filter((d) => d !== null);
773
- return r.length === o.options.length ? o : r.length === 0 ? null : { ...o, options: r };
822
+ if (!n.options || !G(n))
823
+ return n;
824
+ const s = (await Promise.all(
825
+ n.options.map(async (l) => l.condition ? await A(t, l.condition) ? l : null : l)
826
+ )).filter((l) => l !== null);
827
+ return s.length === n.options.length ? n : s.length === 0 ? null : { ...n, options: s };
774
828
  })
775
- )).filter((o) => o !== null);
829
+ )).filter((n) => n !== null);
776
830
  }
777
- const lt = (t) => {
778
- const e = new K(t);
779
- return ae(e), e;
831
+ const mt = (t) => {
832
+ const e = new q(t);
833
+ return ce(e), e;
780
834
  };
781
835
  export {
782
- K as Picked,
783
- lt as createClient,
784
- $ as createStorageKey,
785
- R as evaluateRuleLogic,
786
- ut as getStepFields,
787
- gt as isPickedRoot,
836
+ q as Picked,
837
+ mt as createClient,
838
+ B as createStorageKey,
839
+ A as evaluateRuleLogic,
840
+ ft as getStepFields,
841
+ St as isPickedRoot,
788
842
  D as localStore,
789
- B as sessionStore,
790
- mt as subscribe,
791
- yt as supportsCookies,
792
- ie as supportsCryptoRandomUUID,
793
- z as supportsDocument,
794
- St as supportsHistory,
795
- wt as supportsIntersectionObserver,
796
- oe as supportsLocalStorage,
797
- vt as supportsLocation,
798
- kt as supportsSessionStorage,
799
- bt as supportsShadowRoot,
800
- It as supportsWebComponents,
801
- ne as supportsWindow
843
+ $ as sessionStore,
844
+ wt as subscribe,
845
+ bt as supportsCookies,
846
+ ae as supportsCryptoRandomUUID,
847
+ _ as supportsDocument,
848
+ It as supportsHistory,
849
+ xt as supportsIntersectionObserver,
850
+ ie as supportsLocalStorage,
851
+ Ft as supportsLocation,
852
+ Et as supportsSessionStorage,
853
+ Pt as supportsShadowRoot,
854
+ Bt as supportsWebComponents,
855
+ oe as supportsWindow
802
856
  };