@picked/client 0.0.12-next.14 → 0.0.12-next.2

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