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