@picked/client 0.0.11-next.1 → 0.0.12-next.1

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