@picked/client 0.0.12-next.9 → 0.0.13

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 (27) 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 -754
  5. package/dist/esm/plugins/shopify/index.js +68 -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-Bs9t-zff.js → experience-instance-CeuHLrdL.js} +170 -166
  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/{utils.d.ts → global-obj.d.ts} +8 -1
  15. package/dist/types/plugins/shopify/global-obj.d.ts.map +1 -0
  16. package/dist/types/plugins/shopify/index.d.ts +2 -0
  17. package/dist/types/plugins/shopify/index.d.ts.map +1 -1
  18. package/dist/types/plugins/shopify/picked-config.d.ts +96 -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-D-l-VMTb.cjs +1 -0
  23. package/dist/user-session-Ht0ayuo5.js +632 -0
  24. package/package.json +1 -1
  25. package/dist/experience-instance-COUhADSj.cjs +0 -1
  26. package/dist/types/plugins/shopify/shopify.d.ts.map +0 -1
  27. package/dist/types/plugins/shopify/utils.d.ts.map +0 -1
@@ -0,0 +1,632 @@
1
+ import { createDomain as h, createApi as b, createEffect as j, attach as _, sample as x, combine as B, createEvent as O } from "effector";
2
+ import { createFactory as v, invoke as k } from "@withease/factories";
3
+ import { g as N, t as U, b as H, f as q, e as C, h as z } from "./experience-instance-CeuHLrdL.js";
4
+ import { l as E } from "./logger-C9a75KZn.js";
5
+ import { c as D, s as M, l as A } from "./storage-Cb_71y48.js";
6
+ import { g as G } from "./id-BW-g3y32.js";
7
+ import { i as K } from "./object-JwZ58NOH.js";
8
+ import { e as Y, k as J } from "./supports-DBMT17KZ.js";
9
+ const L = h("experience"), Q = v(
10
+ ({ client: t, experience: e }) => {
11
+ const i = L.store(e), g = b(i, {
12
+ merge(c, m) {
13
+ return {
14
+ ...c,
15
+ ...m.experience
16
+ };
17
+ }
18
+ }), p = i.map((c) => ({
19
+ name: c.name,
20
+ decisionLogic: c.decide,
21
+ targetSelectors: c.targets,
22
+ initializeOpenLogic: e.initializeOpen
23
+ })), d = t.components.listStore.map(
24
+ (c) => c.find((m) => m.name === `experience:${e.id}`) || c.find((m) => m.name === "experience"),
25
+ { skipVoid: !1 }
26
+ ), r = i.map((c) => ({
27
+ steps: c.steps,
28
+ nodes: c.nodes,
29
+ edges: c.edges,
30
+ conditionals: c.conditionals
31
+ })), n = e.actions ?? [];
32
+ return {
33
+ id: e.id,
34
+ configStore: p,
35
+ treeStore: r,
36
+ componentStore: d,
37
+ actions: n,
38
+ merge: g.merge
39
+ };
40
+ }
41
+ );
42
+ function W(t) {
43
+ return k(Q, t);
44
+ }
45
+ const X = v(({ client: t }) => {
46
+ const e = L.store({}), i = b(e, {
47
+ register(r, n) {
48
+ return {
49
+ ...r,
50
+ [n.id]: n
51
+ };
52
+ }
53
+ });
54
+ function g(r) {
55
+ const n = e.getState()[r.id];
56
+ if (n) {
57
+ n.merge({ experience: r, strategy: "override" });
58
+ return;
59
+ }
60
+ const c = W({ client: t, experience: r });
61
+ i.register(c);
62
+ }
63
+ const p = e.map((r) => Object.values(r));
64
+ function d(r) {
65
+ return e.map((n) => n[r], { skipVoid: !1 });
66
+ }
67
+ return {
68
+ register: g,
69
+ getById: d,
70
+ listStore: p
71
+ };
72
+ });
73
+ function Ae(t) {
74
+ return k(X, t);
75
+ }
76
+ const je = (t, e) => {
77
+ e.register(t);
78
+ }, Z = (t, e) => {
79
+ const { targetSelectors: i } = e.configStore.getState(), g = N(i, e.id);
80
+ g.forEach(
81
+ ({ elements: d }) => d.forEach((r) => U(r, e.id))
82
+ ), H(g, e.id).forEach((d) => {
83
+ t.experienceInstances.spawn(e, d);
84
+ });
85
+ }, Oe = async (t) => {
86
+ await Promise.all(
87
+ t.experiences.listStore.getState().map(async (e) => {
88
+ await ee(t, e) && Z(t, e);
89
+ })
90
+ );
91
+ }, ee = async (t, e) => {
92
+ const { decisionLogic: i, targetSelectors: g } = e.configStore.getState();
93
+ return N(g, e.id).length < 1 || g.length === 0 ? !1 : i && q(i) ? await C(t, i) === !0 : !0;
94
+ }, te = h("component"), re = v(
95
+ ({ client: t, component: e, name: i }) => {
96
+ const g = t.frameworks.getByName(e.frameworkName);
97
+ return {
98
+ name: i,
99
+ component: e,
100
+ frameworkStore: g
101
+ };
102
+ }
103
+ );
104
+ function ne(t) {
105
+ return k(re, t);
106
+ }
107
+ const se = v(({ client: t }) => {
108
+ const e = te.store({}), i = b(e, {
109
+ register(r, n) {
110
+ return {
111
+ ...r,
112
+ [n.name]: n
113
+ };
114
+ }
115
+ });
116
+ function g(r, n) {
117
+ e.getState()[r] && E(
118
+ "warn",
119
+ `Component '${r}' already registered. Registering again will override the previous registration.`
120
+ );
121
+ const m = ne({ client: t, name: r, component: n });
122
+ i.register(m);
123
+ }
124
+ const p = e.map((r) => Object.values(r));
125
+ function d(r) {
126
+ return e.map((n) => n[r], { skipVoid: !1 });
127
+ }
128
+ return {
129
+ register: g,
130
+ getByName: d,
131
+ listStore: p
132
+ };
133
+ });
134
+ function Me(t) {
135
+ return k(se, t);
136
+ }
137
+ const Pe = (t, e, i) => {
138
+ i.register(t, e);
139
+ }, oe = h("framework"), ie = v(({ client: t }) => {
140
+ const e = oe.store({}), i = b(e, {
141
+ register(r, n) {
142
+ return {
143
+ ...r,
144
+ [n.name]: n.framework
145
+ };
146
+ }
147
+ });
148
+ function g(r, n) {
149
+ e.getState()[r] && E(
150
+ "warn",
151
+ `Framework '${r}' already registered. Registering again will override the previous registration.`
152
+ ), i.register({ name: r, framework: n });
153
+ }
154
+ const p = e.map((r) => Object.values(r));
155
+ function d(r) {
156
+ return e.map((n) => n[r], { skipVoid: !1 });
157
+ }
158
+ return {
159
+ register: g,
160
+ getByName: d,
161
+ listStore: p
162
+ };
163
+ });
164
+ function Te(t) {
165
+ return k(ie, t);
166
+ }
167
+ const Ve = (t, e) => {
168
+ e.register(t.name, t);
169
+ }, ae = 6e3, P = D("last_ping", "global"), ce = (t) => `${t}/api/v1/ping`, Ne = async (t) => {
170
+ try {
171
+ const e = Date.now(), i = localStorage.getItem(P);
172
+ if (i && e - parseInt(i) < ae)
173
+ return !0;
174
+ const g = ce(t.apiUrl), p = {
175
+ projectId: t.projectId,
176
+ path: window.location.pathname
177
+ }, d = JSON.stringify(p), r = {
178
+ "Content-Type": "application/json"
179
+ }, n = document.getElementById("picked_script"), c = n == null ? void 0 : n.dataset.verceltoken;
180
+ c && (r["x-vercel-protection-bypass"] = c);
181
+ const S = (await fetch(g, {
182
+ method: "POST",
183
+ headers: r,
184
+ body: d
185
+ })).ok;
186
+ return S && localStorage.setItem(P, e.toString()), S;
187
+ } catch (e) {
188
+ return E("error", e), !1;
189
+ }
190
+ }, ue = h("predicate"), le = v(({ client: t }) => {
191
+ const e = ue.store({}), i = b(e, {
192
+ register(r, n) {
193
+ return {
194
+ ...r,
195
+ [n.name]: {
196
+ name: n.name,
197
+ predicate: n.predicate
198
+ }
199
+ };
200
+ }
201
+ });
202
+ function g(r, n) {
203
+ e.getState()[r] && E(
204
+ "warn",
205
+ `Predicate '${r}' already registered. Registering again will override the previous registration.`
206
+ ), i.register(Object.freeze({ name: r, predicate: n }));
207
+ }
208
+ const p = e.map((r) => Object.values(r));
209
+ function d(r) {
210
+ return e.map((n) => n[r], { skipVoid: !1 });
211
+ }
212
+ return {
213
+ register: g,
214
+ getByName: d,
215
+ listStore: p
216
+ };
217
+ });
218
+ function Ce(t) {
219
+ return k(le, t);
220
+ }
221
+ const Le = (t, e, i) => {
222
+ i.register(t, e);
223
+ }, T = h("feature"), ge = v(({ client: t }) => {
224
+ const e = T.store({}), i = T.store([]), g = b(e, {
225
+ register(a, o) {
226
+ return {
227
+ ...a,
228
+ [o.id]: o.feature
229
+ };
230
+ }
231
+ });
232
+ function p(a, o) {
233
+ e.getState()[a] && E(
234
+ "warn",
235
+ `Feature '${a}' already registered. Registering again will override the previous registration.`
236
+ );
237
+ const l = {
238
+ id: a,
239
+ feature: {
240
+ ...o,
241
+ id: a
242
+ }
243
+ };
244
+ g.register(
245
+ Object.freeze({
246
+ id: a,
247
+ feature: l
248
+ })
249
+ );
250
+ }
251
+ const d = j(
252
+ async ({
253
+ id: a,
254
+ key: o,
255
+ storage: s = "local"
256
+ }) => {
257
+ const l = D(`feature:${a}:${o}`, "global"), u = (s === "session" ? M : A).get(l).boolean();
258
+ return u === null ? null : { id: a, key: o, bucket: u };
259
+ }
260
+ ), r = j((a) => {
261
+ if (!a)
262
+ return null;
263
+ const o = D(`feature:${a.id}:${a.key}`, "global");
264
+ (a.storage === "session" ? M : A).set(o, a.bucket);
265
+ }), n = /* @__PURE__ */ new Map(), c = _({
266
+ source: { allFeaturesStore: e, resolvedFeaturesStore: i },
267
+ effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: o }, { id: s, decide: l, key: f }) => {
268
+ const u = o.find((R) => R.id === s);
269
+ if (u)
270
+ return u;
271
+ const y = a[s];
272
+ if (!y)
273
+ throw new Error(`Feature with id '${s}' not found`);
274
+ const w = n.get(`${s}:${f}`);
275
+ if (w !== void 0) {
276
+ const R = await w;
277
+ return { id: y.id, bucket: R, key: f, storage: y.feature.storage };
278
+ }
279
+ const $ = l();
280
+ n.set(`${s}:${f}`, $);
281
+ const F = await $;
282
+ return { id: y.id, bucket: F, key: f, storage: y.feature.storage };
283
+ }
284
+ });
285
+ x({
286
+ clock: g.register,
287
+ fn: (a) => {
288
+ const { id: o, feature: s } = a;
289
+ return { id: o, key: s.feature.key, storage: s.feature.storage };
290
+ },
291
+ target: d
292
+ }), x({
293
+ source: e,
294
+ clock: c.doneData,
295
+ fn: (a, o) => {
296
+ var y;
297
+ const { id: s, bucket: l, storage: f } = o, u = (y = a[s]) == null ? void 0 : y.feature.key;
298
+ return u ? { key: u, id: s, bucket: l, storage: f } : null;
299
+ },
300
+ target: r
301
+ });
302
+ const m = B({ allFeaturesStore: e, resolvedFeaturesStore: i }).map(
303
+ ({
304
+ allFeaturesStore: a,
305
+ resolvedFeaturesStore: o
306
+ }) => Object.values(a).map((s) => {
307
+ const l = o.find((f) => f.id === s.id);
308
+ return l ? {
309
+ id: s.id,
310
+ name: s.feature.name,
311
+ key: s.feature.key,
312
+ getBucket: () => ({ id: s.id, bucket: l.bucket }),
313
+ isResolved: !0
314
+ } : {
315
+ id: s.id,
316
+ name: s.feature.name,
317
+ key: s.feature.key,
318
+ getBucket: async () => await c(s.feature),
319
+ isResolved: !1
320
+ };
321
+ })
322
+ );
323
+ x({
324
+ clock: c.doneData,
325
+ source: { resolvedFeatures: i },
326
+ filter: ({ resolvedFeatures: a }, { id: o }) => !a.some((s) => s.id === o),
327
+ fn: (a, o) => o,
328
+ target: t.eventBus.prepend((a) => ({
329
+ type: "feature_decide",
330
+ feature: a
331
+ }))
332
+ }), x({
333
+ clock: [d.doneData, c.doneData],
334
+ source: i,
335
+ fn: (a, o) => !o || a.some((s) => s.id === o.id) ? a : [...a, o],
336
+ target: i
337
+ });
338
+ function S(a) {
339
+ return e.map((o) => o[a], { skipVoid: !1 });
340
+ }
341
+ return {
342
+ register: p,
343
+ getByName: S,
344
+ listStore: m
345
+ };
346
+ });
347
+ function _e(t) {
348
+ return k(ge, t);
349
+ }
350
+ const Ue = (t, e, i) => {
351
+ i.register(t, e);
352
+ }, I = h("history");
353
+ function V(t, e) {
354
+ return {
355
+ // eslint-disable-next-line sonarjs/pseudo-random
356
+ id: G(`history-entry-${Date.now()}-${Math.random()}}`),
357
+ node: e,
358
+ at: Date.now(),
359
+ experienceId: t
360
+ };
361
+ }
362
+ const de = v(() => {
363
+ const t = I.store({ entries: [] }), e = I.event(), i = I.event(), g = I.event(), p = I.event();
364
+ t.on(e, (r, n) => ({
365
+ entries: [...r.entries, V(n.experienceId, n.node)]
366
+ })), t.on(i, (r, n) => ({
367
+ entries: [
368
+ ...r.entries.slice(0, -1),
369
+ V(n.experienceId, n.node)
370
+ ]
371
+ })), t.on(p, (r, n) => n);
372
+ function d(r, n) {
373
+ const c = { lastStepIndex: -1, secondLastStepIndex: -1 };
374
+ for (let m = r.length - 1; m >= 0; m--) {
375
+ const S = r[m], a = S == null ? void 0 : S.node;
376
+ if (!(!a || !z(a)) && !(n && (S == null ? void 0 : S.experienceId) !== n))
377
+ if (c.lastStepIndex === -1)
378
+ c.lastStepIndex = m;
379
+ else {
380
+ c.secondLastStepIndex = m;
381
+ break;
382
+ }
383
+ }
384
+ return c;
385
+ }
386
+ return t.on(g, (r, n) => {
387
+ const { secondLastStepIndex: c } = d(r.entries, n.experienceId), m = c !== -1 ? r.entries.slice(0, c + 1) : r.entries;
388
+ return {
389
+ ...r,
390
+ entries: m
391
+ };
392
+ }), {
393
+ push: e,
394
+ replace: i,
395
+ back: g,
396
+ restore: p,
397
+ entriesStore: t.map((r) => r.entries)
398
+ };
399
+ });
400
+ function He() {
401
+ return k(de);
402
+ }
403
+ const pe = h("field"), fe = v(() => {
404
+ const t = pe.store({}), e = b(t, {
405
+ register(r, n) {
406
+ return {
407
+ ...r,
408
+ [n.field.id]: n.field
409
+ };
410
+ }
411
+ });
412
+ function i(r) {
413
+ e.register({ field: r });
414
+ }
415
+ const g = t.map((r) => Object.values(r));
416
+ function p(r) {
417
+ return t.map((n) => n[r] || null);
418
+ }
419
+ function d(r) {
420
+ return t.map((n) => Object.values(n).find((c) => c.name === r) || null);
421
+ }
422
+ return {
423
+ register: i,
424
+ getById: p,
425
+ listStore: g,
426
+ getByName: d
427
+ };
428
+ });
429
+ function qe() {
430
+ return k(fe);
431
+ }
432
+ const ze = (t, e) => {
433
+ e.register(t);
434
+ }, me = h("action"), ye = v(() => {
435
+ const t = me.store({}), e = b(t, {
436
+ register(d, r) {
437
+ return {
438
+ ...d,
439
+ [r.name]: {
440
+ name: r.name,
441
+ action: r.action
442
+ }
443
+ };
444
+ }
445
+ });
446
+ function i(d, r) {
447
+ e.register({ name: d, action: r });
448
+ }
449
+ const g = t.map((d) => Object.values(d));
450
+ function p(d) {
451
+ return t.map((r) => r[d], { skipVoid: !1 });
452
+ }
453
+ return {
454
+ register: i,
455
+ getByName: p,
456
+ listStore: g
457
+ };
458
+ });
459
+ function Ge() {
460
+ return k(ye);
461
+ }
462
+ const Ke = (t, e, i) => {
463
+ i.register(t, e);
464
+ }, Se = h("response"), ve = v(({ client: t }) => {
465
+ const e = Se.store({}), i = O(), g = O(), p = b(e, {
466
+ register(o, s) {
467
+ return {
468
+ ...o,
469
+ [s.fieldId]: s.response
470
+ };
471
+ },
472
+ registerBatch(o, s) {
473
+ return {
474
+ ...o,
475
+ ...s
476
+ };
477
+ },
478
+ clear(o, s) {
479
+ const { [s]: l, ...f } = o;
480
+ return f;
481
+ },
482
+ clearAll() {
483
+ return {};
484
+ }
485
+ });
486
+ function d(o, s) {
487
+ p.register({ fieldId: o, response: s });
488
+ }
489
+ async function r(o) {
490
+ const s = [];
491
+ return await Promise.allSettled(
492
+ Object.entries(o).map(async ([l, f]) => {
493
+ let u = f;
494
+ const y = t.fields.getById(l).getState();
495
+ if (!y) {
496
+ s.push({
497
+ fieldId: l,
498
+ userMessage: `Field '${l}' not found`,
499
+ systemMessage: `No field with ID '${l}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
500
+ value: u
501
+ });
502
+ return;
503
+ }
504
+ if (y.multiple && (typeof u == "string" || typeof u == "number" || typeof u == "boolean") && (u = [u]), y.validation && !K(y.validation)) {
505
+ const w = await C(t, y.validation, {
506
+ $input: u
507
+ });
508
+ if (typeof w == "string") {
509
+ s.push({
510
+ fieldId: l,
511
+ userMessage: w,
512
+ systemMessage: `Field validation resulted in an error: ${w}.`,
513
+ value: u
514
+ });
515
+ return;
516
+ }
517
+ if (w === !1) {
518
+ s.push({
519
+ fieldId: l,
520
+ userMessage: "This field is invalid",
521
+ systemMessage: "Field validation resulted in an unspecified error.",
522
+ value: u
523
+ });
524
+ return;
525
+ }
526
+ }
527
+ if (y.required && (typeof u > "u" || u === null || u === "" || Array.isArray(u) && !u.length)) {
528
+ s.push({
529
+ fieldId: l,
530
+ userMessage: "This field is required",
531
+ systemMessage: "Field is required.",
532
+ value: u
533
+ });
534
+ return;
535
+ }
536
+ if (!y.multiple && Array.isArray(u) && u.length > 1) {
537
+ s.push({
538
+ fieldId: l,
539
+ userMessage: "This field expects a single response",
540
+ systemMessage: "Field expects a single response.",
541
+ value: u
542
+ });
543
+ return;
544
+ }
545
+ if (y.options) {
546
+ const w = y.options.map((F) => F.value), $ = Array.isArray(u) ? u : [u];
547
+ Array.isArray(u) && ($.every((F) => w.includes(F)) || s.push({
548
+ fieldId: l,
549
+ userMessage: "This field expects a valid option",
550
+ systemMessage: `Field expects a valid option. Valid options are: ${w.join(", ")}`,
551
+ value: u
552
+ }));
553
+ }
554
+ })
555
+ ), { responsesToCommit: o, validationErrors: s };
556
+ }
557
+ async function n(o) {
558
+ const { responsesToCommit: s, validationErrors: l } = await r(o);
559
+ return l.length ? { errors: l } : (p.registerBatch(s), { errors: [] });
560
+ }
561
+ const c = e.map((o) => o), m = e.map((o) => Object.keys(o).map((l) => ({
562
+ fieldId: l,
563
+ value: o[l]
564
+ })));
565
+ function S(o) {
566
+ const s = t.fields.getById(o), l = e.map((f) => f[o] || null);
567
+ return B({ f: s, r: l }, ({ f, r: u }) => u || (f != null && f.defaultValue ? f.defaultValue : null));
568
+ }
569
+ function a(o) {
570
+ const s = t.fields.getByName(o);
571
+ return B({ f: s, s: e }, ({ f: l, s: f }) => {
572
+ const u = l && f[l.id] || null;
573
+ return u || (l != null && l.defaultValue ? l.defaultValue : null);
574
+ });
575
+ }
576
+ return x({
577
+ clock: i,
578
+ target: p.clearAll
579
+ }), x({
580
+ clock: g,
581
+ target: p.clear
582
+ }), {
583
+ register: d,
584
+ clearAll: i,
585
+ clear: g,
586
+ commit: n,
587
+ getResponsesToCommit: r,
588
+ listStore: m,
589
+ getAllStore: c,
590
+ getByFieldId: S,
591
+ getByFieldName: a
592
+ };
593
+ });
594
+ function Ye(t) {
595
+ return k(ve, t);
596
+ }
597
+ function ke() {
598
+ if (J())
599
+ return crypto.randomUUID();
600
+ const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), i = Math.random().toString(36).substring(2, 15), g = Math.random().toString(36).substring(2, 15);
601
+ return `${t}-${e}-${i}-${g}`;
602
+ }
603
+ const we = () => ({
604
+ id: ke()
605
+ }), he = D("session", "global"), be = () => {
606
+ if (!Y()) return null;
607
+ const t = A.get(he);
608
+ let e = t.isSet() ? t.json() : null;
609
+ return e || (e = we(), t.set(e)), e;
610
+ }, Je = () => be();
611
+ export {
612
+ Me as a,
613
+ Ae as b,
614
+ He as c,
615
+ Te as d,
616
+ Ce as e,
617
+ _e as f,
618
+ Ye as g,
619
+ qe as h,
620
+ Ge as i,
621
+ Je as j,
622
+ Pe as k,
623
+ Ue as l,
624
+ Le as m,
625
+ ze as n,
626
+ Ke as o,
627
+ Ne as p,
628
+ je as q,
629
+ Z as r,
630
+ Ve as s,
631
+ Oe as t
632
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/client",
3
- "version": "0.0.12-next.9",
3
+ "version": "0.0.13",
4
4
  "dependencies": {
5
5
  "@withease/factories": "^1.0.5"
6
6
  },
@@ -1 +0,0 @@
1
- "use strict";const s=require("effector"),G=require("@withease/factories"),H=require("./supports-YvpQZxbh.cjs"),N=require("./logger-BsmHUUw1.cjs"),mt=require("./object-BbFTsGh3.cjs");function ht(t){return typeof t=="number"&&!isNaN(t)}function R(t){return typeof t=="string"}function E(t){return Array.isArray(t)}function rt(t){return t instanceof Promise}function tt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length===1}function m(t){if(ht(t))return t;const e=parseFloat(`${t}`);return isNaN(e)?0:e}function T(t){return`${t}`}const St={"==":(t,e)=>t==e,"===":(t,e)=>t===e,"!=":(t,e)=>t!=e,"!==":(t,e)=>t!==e,">":(t,e)=>m(t)>m(e),">=":(t,e)=>m(t)>=m(e),"<":(t,e,r)=>{const n=m(t),a=m(e);if(r===void 0)return n<a;const c=m(r);return n<a&&a<c},"<=":(t,e,r)=>{const n=m(t),a=m(e);if(r===void 0)return n<=a;const c=m(r);return n<=a&&a<=c},"!!":async t=>await A(t),"!":async t=>!await A(t),"%":(t,e)=>m(t)%m(e),log:t=>(console.log(t),t),in:(t,e)=>e?R(e)?e.indexOf(T(t))!==-1:E(e)?e.includes(t):!1:!1,cat:(...t)=>t.map(T).join(""),substr:(t,e,r)=>{const n=T(t),a=m(e);if(r===void 0)return n.substr(a);const c=m(r);if(c<0){const o=n.substr(a);return o.substr(0,o.length+c)}return n.substr(a,c)},"+":(...t)=>t.reduce((e,r)=>m(e)+m(r),0),"*":(...t)=>t.reduce((e,r)=>m(e)*m(r),1),"-":(t,e)=>{const r=m(t);return e===void 0?-r:r-m(e)},"/":(t,e)=>m(t)/m(e),min:(...t)=>Math.min(...t.map(m)),max:(...t)=>Math.max(...t.map(m)),merge:(...t)=>t.reduce((e,r)=>E(r)?e.concat(r):e.concat([r]),[]),var(t,e){const r=arguments.length>1?e:null;if(t===""||t==="."||t===null||t===void 0)return this;if(typeof t=="number"&&Array.isArray(this))return t>=0&&t<this.length?this[t]:r;const n=T(t);if(n===""||n===".")return this;const a=n.split(".");let c=this;for(const o of a){if(c==null)return r;if(Array.isArray(c)){const u=parseInt(o,10);isNaN(u)?c=c[o]:c=c[u]}else c=c[o]}return c!==void 0?c:r},async missing(...t){const e=E(t[0])?t[0]:t,r=[];for(const n of e){const a=await g({var:n},this);(a===null||a==="")&&r.push(`${n}`)}return r},async missing_some(t,e){const r=await g({missing:e},this);if(!E(r)||!E(e))return[];const n=r.filter(R);return e.filter(R).length-n.length>=m(t)?[]:n},invoke(t){return typeof t!="function"?null:t()},regexp_matches(t,e){let r=t,n="";if(E(t)){const[c,o]=t;r=c,n=o}return!R(r)||!R(n)?!1:new RegExp(r,n).test(T(e))},throw(t){throw new Error(T(t))}};async function g(t,e){if(!t)return t;if(rt(t))return g(await t,e);if(E(t))return Promise.all(t.map(o=>g(o,e)));if(!tt(t))return t;const r=yt(t);let n=r?t[r]??[]:[];switch(E(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await A(await g(n[o],e)))return g(n[o+1],e);return n.length%2===1?g(n[n.length-1],e):null;case"and":{let o=null;for(const u of n)if(o=await g(u,e),!await A(o))return o;return o}case"or":{let o=null;for(const u of n)if(o=await g(u,e),await A(o))return o;return o}case"map":{const o=await g(n[0],e);return E(o)?await Promise.all(o.map(u=>g(n[1],u))):[]}case"filter":{const o=await g(n[0],e);return E(o)?(await Promise.all(o.map(async p=>{const y=await A(await g(n[1],p));return{item:p,shouldInclude:y}}))).filter(({shouldInclude:p})=>p).map(({item:p})=>p):[]}case"reduce":{const o=await g(n[0],e);if(!E(o))return n.length>2?await g(n[2],e):null;const u=n[1];let y=n.length>2?await g(n[2],e):null;for(const k of o)y=await g(u,{current:k,accumulator:y});return y}case"all":{const o=await g(n[0],e);if(!E(o)||o.length===0)return!1;for(const u of o)if(!await A(await g(n[1],u)))return!1;return!0}case"some":{const o=await g(n[0],e);if(!E(o))return!1;for(const u of o)if(await A(await g(n[1],u)))return!0;return!1}case"none":{const o=await g(n[0],e);if(!E(o))return!0;for(const u of o)if(await A(await g(n[1],u)))return!1;return!0}case"catch":try{return await g(n[0],e)}catch(o){return tt(o)?await g(o,e):n[1]?await g(n[1],o):o instanceof Error?o.message:o}}const a=await Promise.all(n.map(o=>g(o,e))),c=r?St[r]:void 0;if(!c)throw new Error(`Unrecognized operation ${r}`);return c.apply(e,a)}async function A(t){return rt(t)?A(await t):!(Array.isArray(t)&&t.length===0)&&!!t}function yt(t){return Object.keys(t)[0]}function ot(t){return!mt.isEmpty(t)}async function z(t,e,r){const n=t.getStateSnapshot(),a=t.predicates.listStore.getState().reduce((u,p)=>({...u,[p.name]:()=>p.predicate(n)}),{}),c=t.features.listStore.getState().reduce((u,p)=>({...u,[p.id]:async()=>{const{bucket:y}=await p.getBucket();return y}}),{}),o={...r,responses:t.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:a,features:c};return await g(e,o)}function wt(t){return!H.supportsWindow()||!H.supportsDocument()?[]:Array.from(window.document.querySelectorAll(t)).filter(e=>e instanceof HTMLElement)}function Et(t){if(!H.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return t.attachShadow({mode:"closed"})}function Nt(){return new Promise((t,e)=>{if(!H.supportsDocument()){e();return}document.readyState!=="loading"?t():document.addEventListener("readystatechange",()=>t(),{once:!0})})}function It(t,e){const r=new MutationObserver(n=>{document.contains(t)||(r.disconnect(),e())});r.observe(document.body,{childList:!0,subtree:!0})}const j="picked-root",q="picked-target",xt="picked-root";function kt(t,e){return[...t,{selector:`${xt}[experience-id="${e}"]`,placement:"replace"}].flatMap(n=>{const a=wt(n.selector).filter(c=>!At(c,e)&&!it(c,e));return{...n,elements:a}})}function vt(t,e){return t.flatMap(r=>r.elements.map(n=>Bt(n,r.placement,e)))}function bt(t,e){t.classList.add(q),t.classList.add(`${q}-${e}`)}function At(t,e){return e?t.classList.contains(`${q}-${e}`):t.classList.contains(`${q}`)}function it(t,e){return e?t.classList.contains(`${j}-${e}`):t.classList.contains(j)}function Ot(t){const e=document.createElement("div");return e.style.display="block",e.classList.add(j),e.classList.add(`${j}-${t}`),e}function Bt(t,e,r){let n;const a=Ot(r);if(t instanceof Document)n=t.body.appendChild(a);else{switch(e){case"replace":t.replaceWith(a);break;case"before":t.before(a);break;case"after":t.after(a);break;case"prepend":t.prepend(a);break;default:t.append(a);break}n=a}return n}function Ft(t){return t.type==="conditional"}function L(t){return t.type==="step"}function $t(t){return t.type==="experience"}function et(t){return t.type==="origin"}function nt(t){return t.type==="action"}const st=(t,e,r,n,a=new Set)=>a.has(r.id)?[]:(a.add(r.id),L(r)&&!n?[r]:e.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const u=t.find(p=>p.id===o.destinationNodeId);return u?st(t,e,u,!1,a):[]})),_t=(t,e,r)=>st(t,e,r,!0,new Set),at=(t,e,r,n,a=new Set)=>{if(a.has(r.id))return[-1,-1];a.add(r.id);const c=e.filter(p=>p.sourceNodeId===r.id);if(c.length===0)return[0,0];let o=1/0,u=-1/0;for(const p of c){const y=t.find(M=>M.id===p.destinationNodeId);if(!y)continue;const[k,B]=at(t,e,y,!1,new Set(a));k!==-1&&(o=Math.min(o,k+1),u=Math.max(u,B+1))}return o===1/0?[-1,-1]:[o,u]},Tt=(t,e,r)=>at(t,e,r,!0,new Set),ct=(t,e,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const a=e.filter(u=>u.destinationNodeId===r.id);if(a.length===0)return[-1,-1];let c=1/0,o=-1/0;for(const u of a){const p=t.find(B=>B.id===u.sourceNodeId);if(!p)continue;const[y,k]=ct(t,e,p,new Set(n));y!==-1&&(c=Math.min(c,y+1),o=Math.max(o,k+1))}return c===1/0?[-1,-1]:[c,o]},Lt=(t,e,r)=>ct(t,e,r,new Set),ut=t=>t.find(r=>r.type==="origin")||null,W=(t,e,r)=>{if(!t)return ut(e);const n=r.find(c=>c.sourceNodeId===t.id);if(!n)return null;const a=e.find(c=>c.id===n.destinationNodeId);return a||null};async function Mt(t,e,r,n){const a=t?"true":"false",c=n.find(o=>o.sourceNodeHandle===a&&o.sourceNodeId===e);return r.find(o=>o.id===(c==null?void 0:c.destinationNodeId))}const X=s.createDomain("experience-instance"),Dt=G.createFactory(({client:t,experience:e,target:r})=>{const n=s.createEvent(),a=s.createEvent(),c=s.createEvent(),o=s.createEvent(),u=s.createEvent(),p=s.createEvent(),y=e.componentStore,k=X.store("transitioning"),B=t.history.entriesStore.map(i=>i.filter(l=>l.experienceId===e.id)),M=B.map(i=>i.filter(l=>L(l.node))),I=B.map(i=>{var l;return((l=i[i.length-1])==null?void 0:l.node)||null}),f=s.combine(e.treeStore,I,({steps:i},l)=>i.find(d=>l&&L(l)&&d.id===l.stepId)||null),h=s.combine(e.treeStore,I,({nodes:i,edges:l},d)=>d?_t(i,l,d):[]),b=s.combine(e.treeStore,I,({nodes:i,edges:l},d)=>d?Lt(i,l,d):[-1,-1]),F=s.combine(e.treeStore,I,({nodes:i,edges:l},d)=>d?Tt(i,l,d):[-1,-1]),$=e.configStore.getState().initializeOpenLogic,O=X.store($===!0),P=s.createApi(O,{open:()=>!0,close:()=>!1,toggle:i=>!i,set:(i,l)=>l}),lt=s.createEffect(async()=>{t.history.back({experienceId:e.id})}),dt=s.attach({source:e.treeStore,effect:async(i,l)=>{const d=i.nodes.find(w=>L(w)&&w.stepId===l);d&&t.history.push({experienceId:e.id,node:d})}}),J=s.attach({source:I,effect:i=>{}}),K=s.attach({source:e.treeStore,effect:async({nodes:i})=>ut(i)}),U=s.attach({source:e.treeStore,effect:async({nodes:i,edges:l},d)=>W(d,i,l)}),V=s.attach({source:e.treeStore,effect:async({nodes:i,edges:l,conditionals:d},w)=>{if(!w)return;const _=d.find(v=>v.id===w.conditionalId);if(!_)return;const x=w.id,S=await z(t,_.condition);return Mt(!!S,x,i,l)}}),Q=s.attach({source:e.treeStore,effect:async({nodes:i,edges:l},d)=>{if(!d||!nt(d))return;const w=d.action;if(!w){N.logger("warn",`Action node ${d.id} has no action name`);return}const _=t.actions.getByName(w).getState();if(!_){N.logger("warn",`Action '${w}' not registered on client`);const x=l.find(S=>S.sourceNodeId===d.id&&S.sourceNodeHandle==="false");return x?i.find(S=>S.id===x.destinationNodeId):null}if(typeof _.action!="function"){N.logger("warn",`Action '${w}' is not a function`);const x=l.find(S=>S.sourceNodeId===d.id&&S.sourceNodeHandle==="false");return x?i.find(S=>S.id===x.destinationNodeId):null}try{N.logger("info",`Executing action: ${w}`),await _.action();const x=l.find(v=>v.sourceNodeId===d.id&&v.sourceNodeHandle==="true");if(!x)return N.logger("warn",`No 'true' edge found for action node ${d.id}`),null;const S=i.find(v=>v.id===x.destinationNodeId);return N.logger("info",`Action '${w}' succeeded, moving to node ${S==null?void 0:S.id}`),S||null}catch(x){N.logger("warn",`Action '${w}' failed:`,x);const S=l.find(C=>C.sourceNodeId===d.id&&C.sourceNodeHandle==="false");if(!S)return N.logger("warn",`No 'false' edge found for action node ${d.id}`),null;const v=i.find(C=>C.id===S.destinationNodeId);return N.logger("info",`Action '${w}' failed, moving to node ${v==null?void 0:v.id}`),v||null}}}),pt=s.createEffect(i=>{if(i)return t.launchExperienceById(i.experienceId)}),Y=s.attach({source:[I,e.treeStore],effect:async([i,{nodes:l,edges:d}])=>W(i,l,d)}),D=s.attach({source:[I,e.treeStore],effect:async([i,{nodes:l,edges:d}])=>W(i,l,d)}),gt=s.createEffect(i=>{t.history.push({experienceId:e.id,node:i})}),Z=s.attach({source:e.configStore,effect:async({initializeOpenLogic:i})=>ot(i)?!!await z(t,i):i??!1});return s.split({source:I,match:i=>i?Ft(i)?"condition":L(i)?"step":$t(i)?"launchExperience":et(i)?"origin":nt(i)?"action":"other":"none",cases:{none:K,origin:U,condition:V,step:J,launchExperience:pt,action:Q,__:s.createEvent()}}),s.sample({clock:[V.doneData,U.doneData,K.doneData,D.doneData,Y.doneData,Q.doneData],filter:Boolean,target:gt}),s.sample({clock:a,target:D}),s.sample({clock:a,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_submit",step:i,experience:e}))}),s.sample({clock:D.done,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_submit_success",step:i,experience:e}))}),s.sample({clock:D.fail,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_submit_error",step:i,experience:e}))}),s.sample({clock:c,target:lt}),s.sample({clock:o,target:dt}),s.sample({source:s.combine([V.pending,U.pending,K.pending,D.pending]),fn:i=>i.some(Boolean)?"transitioning":"ready",target:k}),s.sample({clock:J.doneData,source:f,filter:Boolean,target:t.eventBus.prepend(i=>({type:"step_enter",step:i,experience:e}))}),s.sample({clock:p,target:Z}),s.sample({source:Z.doneData,fn:i=>!!i,target:O}),s.sample({source:I,clock:n,filter:i=>i?et(i):!0,target:Y}),s.sample({source:O,filter:Boolean,target:t.eventBus.prepend(()=>({type:"experience_open",experience:e}))}),s.sample({source:O,filter:i=>!i,target:t.eventBus.prepend(()=>({type:"experience_close",experience:e}))}),s.sample({clock:u,target:[n,p]}),u(),{id:Math.random().toString(36).substring(7),experienceId:e.id,configStore:e.configStore,target:r,componentStore:y,stateStore:k,isOpenStore:O,open:P.open,close:P.close,toggleOpen:P.toggle,setOpen:P.set,treeStore:e.treeStore,currentNodeStore:I,currentStepStore:f,nextReachableStepNodesStore:h,stepsToOriginStore:b,stepsToLeafStore:F,goToNextStep:a,goToPreviousStep:c,goToStepById:o,stepsHistoryStore:M}});function ft(t){return G.invoke(Dt,t)}const Rt=G.createFactory(({client:t})=>{const e=X.store({}),r=s.createEvent(),n=s.createEvent(),a=s.createEvent(),c=s.createApi(e,{register(f,h){const b=[...f[h.experienceId]??[]];return b.push(h),{...f,[h.experienceId]:b}},unregister(f,h){var $;const b=h.experienceId,F=($=f[b])==null?void 0:$.filter(O=>O!==h);return{...f,[b]:F??[]}}}),o=s.createEffect(({experience:f,target:h})=>ft({client:t,experience:f,target:h})),u=s.createEffect(f=>{c.register(f)}),p=s.createEffect(f=>{f.target&&It(f.target,()=>{a(f)})}),y=s.createEffect(f=>{c.unregister(f)}),k=s.createEffect(f=>{const h=f.componentStore.getState();if(!h){N.logger("warn","No app component registered. Skipping init.");return}const b=h.frameworkStore.getState();if(!b){N.logger("error",`No framework registered for component '${h.name}'. Skipping rendering.`);return}const F=f.target;if(!F){N.logger("error",`No target element registered for experience '${f.experienceId}'. Skipping rendering.`);return}const $=Et(F);try{b.render($,h.component,t,f)}catch(O){N.logger("error",O)}});s.sample({clock:r,target:o}),s.sample({clock:a,target:y}),s.sample({clock:o.doneData,target:[u,p,n]}),s.sample({clock:o.doneData,target:t.eventBus.prepend(f=>({type:"experience_initialized",experienceInstance:f}))}),s.sample({clock:n,target:k});function B(f,h){r({experience:f,target:h})}const M=e.map(f=>Object.values(f).flat());function I(f){return e.map(h=>h[f]||[],{skipVoid:!1})}return{spawn:B,getByExperienceId:I,listStore:M}});function Pt(t){return G.invoke(Rt,t)}exports.createAppHosts=vt;exports.createExperienceInstance=ft;exports.createExperienceInstanceIndex=Pt;exports.domInteractive=Nt;exports.evaluateRuleLogic=z;exports.getTargetElements=kt;exports.isPickedRoot=it;exports.isRulesLogic=ot;exports.isStepNode=L;exports.tagTargetElement=bt;
@@ -1 +0,0 @@
1
- {"version":3,"file":"shopify.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/shopify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAoB9D,eAAO,MAAM,gBAAgB,GAC3B,cAAc,MAAM,EACpB,WAAW,aAAa,CAAC,UAAU,CAAC,KACnC,OAMF,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,cAAc,MAAM,EAAE,WAAW,aAAa,CAAC,UAAU,CAAC,uBAOxF,CAAA;AAED,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CACrC;AAED,eAAO,MAAM,iBAAiB;8BAEF,aAAa;sCACL,aAAa;sCAEb,aAAa;yCACV,aAAa;yCAEb,aAAa;4CACV,aAAa;mCAGtB,aAAa;sCACV,aAAa;sCAEb,aAAa;yCACV,aAAa;wCAEd,aAAa;2CACV,aAAa;sCAElB,aAAa;oCACf,aAAa;uCACV,aAAa;mCAGjB,aAAa;uCAET,aAAa;kCAElB,aAAa;CAC5C,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/utils.ts"],"names":[],"mappings":"AAAA,UAAU,YAAY;IACpB,CAAC,GAAG,EAAE,MAAM,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,YAAY,GACZ,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,CAAC,CAAA;CACvE;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,CAAC,EAAE;YACR,SAAS,CAAC,EAAE;gBACV,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;aACzD,CAAA;SACF,CAAA;KACF;CACF;AAED,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG;IACjE,OAAO,EAAE;QAAE,SAAS,EAAE;YAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;SAAE,CAAA;KAAE,CAAA;CACpF,CAEA"}