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

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