@picked/client 0.0.1-dev.1763014928671 → 0.0.1-dev.1763077817547

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