@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
@@ -0,0 +1,637 @@
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 k, invoke as v } 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 = k(
10
+ ({ client: t, experience: e }) => {
11
+ const i = L.store(e), g = b(i, {
12
+ merge(u, m) {
13
+ return {
14
+ ...u,
15
+ ...m.experience
16
+ };
17
+ }
18
+ }), p = i.map((u) => ({
19
+ name: u.name,
20
+ decisionLogic: u.decide,
21
+ targetSelectors: u.targets,
22
+ initializeOpenLogic: e.initializeOpen
23
+ })), d = t.components.listStore.map(
24
+ (u) => u.find((m) => m.name === `experience:${e.id}`) || u.find((m) => m.name === "experience"),
25
+ { skipVoid: !1 }
26
+ ), r = i.map((u) => ({
27
+ steps: u.steps,
28
+ nodes: u.nodes,
29
+ edges: u.edges,
30
+ conditionals: u.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 v(Q, t);
44
+ }
45
+ const X = k(({ 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 u = W({ client: t, experience: r });
61
+ i.register(u);
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 v(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 = k(
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 v(re, t);
106
+ }
107
+ const se = k(({ 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 v(se, t);
136
+ }
137
+ const Pe = (t, e, i) => {
138
+ i.register(t, e);
139
+ }, oe = h("framework"), ie = k(({ 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 v(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"), u = n == null ? void 0 : n.dataset.verceltoken;
180
+ u && (r["x-vercel-protection-bypass"] = u);
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 = k(({ 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 v(le, t);
220
+ }
221
+ const Le = (t, e, i) => {
222
+ i.register(t, e);
223
+ }, T = h("feature"), ge = k(({ 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 c = {
238
+ id: a,
239
+ feature: {
240
+ ...o,
241
+ id: a
242
+ }
243
+ };
244
+ g.register(
245
+ Object.freeze({
246
+ id: a,
247
+ feature: c
248
+ })
249
+ );
250
+ }
251
+ const d = j(
252
+ async ({
253
+ id: a,
254
+ key: o,
255
+ storage: s = "local"
256
+ }) => {
257
+ const c = D(`feature:${a}:${o}`, "global"), l = (s === "session" ? M : A).get(c).boolean();
258
+ return l === null ? null : { id: a, key: o, bucket: l, storage: s };
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(), u = _({
266
+ source: { allFeaturesStore: e, resolvedFeaturesStore: i },
267
+ effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: o }, { id: s, decide: c, key: f }) => {
268
+ const l = o.find((R) => R.id === s);
269
+ if (l)
270
+ return l;
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 $ = c();
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
+ source: e,
288
+ filter: (a, o) => {
289
+ const s = a[o.id];
290
+ return s ? s.feature.key !== o.feature.feature.key || s.feature.storage !== o.feature.feature.storage : !0;
291
+ },
292
+ fn: (a, o) => {
293
+ const { id: s, feature: c } = o;
294
+ return { id: s, key: c.feature.key, storage: c.feature.storage };
295
+ },
296
+ target: d
297
+ }), x({
298
+ source: e,
299
+ clock: u.doneData,
300
+ fn: (a, o) => {
301
+ var y;
302
+ const { id: s, bucket: c, storage: f } = o, l = (y = a[s]) == null ? void 0 : y.feature.key;
303
+ return l ? { key: l, id: s, bucket: c, storage: f } : null;
304
+ },
305
+ target: r
306
+ });
307
+ const m = B({ allFeaturesStore: e, resolvedFeaturesStore: i }).map(
308
+ ({
309
+ allFeaturesStore: a,
310
+ resolvedFeaturesStore: o
311
+ }) => Object.values(a).map((s) => {
312
+ const c = o.find((f) => f.id === s.id);
313
+ return c ? {
314
+ id: s.id,
315
+ name: s.feature.name,
316
+ key: s.feature.key,
317
+ getBucket: () => ({ id: s.id, bucket: c.bucket }),
318
+ isResolved: !0
319
+ } : {
320
+ id: s.id,
321
+ name: s.feature.name,
322
+ key: s.feature.key,
323
+ getBucket: async () => await u(s.feature),
324
+ isResolved: !1
325
+ };
326
+ })
327
+ );
328
+ x({
329
+ clock: u.doneData,
330
+ source: { resolvedFeatures: i },
331
+ filter: ({ resolvedFeatures: a }, { id: o }) => !a.some((s) => s.id === o),
332
+ fn: (a, o) => o,
333
+ target: t.eventBus.prepend((a) => ({
334
+ type: "feature_decide",
335
+ feature: a
336
+ }))
337
+ }), x({
338
+ clock: [d.doneData, u.doneData],
339
+ source: i,
340
+ fn: (a, o) => !o || a.some((s) => s.id === o.id) ? a : [...a, o],
341
+ target: i
342
+ });
343
+ function S(a) {
344
+ return e.map((o) => o[a], { skipVoid: !1 });
345
+ }
346
+ return {
347
+ register: p,
348
+ getByName: S,
349
+ listStore: m
350
+ };
351
+ });
352
+ function _e(t) {
353
+ return v(ge, t);
354
+ }
355
+ const Ue = (t, e, i) => {
356
+ i.register(t, e);
357
+ }, I = h("history");
358
+ function V(t, e) {
359
+ return {
360
+ // eslint-disable-next-line sonarjs/pseudo-random
361
+ id: G(`history-entry-${Date.now()}-${Math.random()}}`),
362
+ node: e,
363
+ at: Date.now(),
364
+ experienceId: t
365
+ };
366
+ }
367
+ const de = k(() => {
368
+ const t = I.store({ entries: [] }), e = I.event(), i = I.event(), g = I.event(), p = I.event();
369
+ t.on(e, (r, n) => ({
370
+ entries: [...r.entries, V(n.experienceId, n.node)]
371
+ })), t.on(i, (r, n) => ({
372
+ entries: [
373
+ ...r.entries.slice(0, -1),
374
+ V(n.experienceId, n.node)
375
+ ]
376
+ })), t.on(p, (r, n) => n);
377
+ function d(r, n) {
378
+ const u = { lastStepIndex: -1, secondLastStepIndex: -1 };
379
+ for (let m = r.length - 1; m >= 0; m--) {
380
+ const S = r[m], a = S == null ? void 0 : S.node;
381
+ if (!(!a || !z(a)) && !(n && (S == null ? void 0 : S.experienceId) !== n))
382
+ if (u.lastStepIndex === -1)
383
+ u.lastStepIndex = m;
384
+ else {
385
+ u.secondLastStepIndex = m;
386
+ break;
387
+ }
388
+ }
389
+ return u;
390
+ }
391
+ return t.on(g, (r, n) => {
392
+ const { secondLastStepIndex: u } = d(r.entries, n.experienceId), m = u !== -1 ? r.entries.slice(0, u + 1) : r.entries;
393
+ return {
394
+ ...r,
395
+ entries: m
396
+ };
397
+ }), {
398
+ push: e,
399
+ replace: i,
400
+ back: g,
401
+ restore: p,
402
+ entriesStore: t.map((r) => r.entries)
403
+ };
404
+ });
405
+ function He() {
406
+ return v(de);
407
+ }
408
+ const pe = h("field"), fe = k(() => {
409
+ const t = pe.store({}), e = b(t, {
410
+ register(r, n) {
411
+ return {
412
+ ...r,
413
+ [n.field.id]: n.field
414
+ };
415
+ }
416
+ });
417
+ function i(r) {
418
+ e.register({ field: r });
419
+ }
420
+ const g = t.map((r) => Object.values(r));
421
+ function p(r) {
422
+ return t.map((n) => n[r] || null);
423
+ }
424
+ function d(r) {
425
+ return t.map((n) => Object.values(n).find((u) => u.name === r) || null);
426
+ }
427
+ return {
428
+ register: i,
429
+ getById: p,
430
+ listStore: g,
431
+ getByName: d
432
+ };
433
+ });
434
+ function qe() {
435
+ return v(fe);
436
+ }
437
+ const ze = (t, e) => {
438
+ e.register(t);
439
+ }, me = h("action"), ye = k(() => {
440
+ const t = me.store({}), e = b(t, {
441
+ register(d, r) {
442
+ return {
443
+ ...d,
444
+ [r.name]: {
445
+ name: r.name,
446
+ action: r.action
447
+ }
448
+ };
449
+ }
450
+ });
451
+ function i(d, r) {
452
+ e.register({ name: d, action: r });
453
+ }
454
+ const g = t.map((d) => Object.values(d));
455
+ function p(d) {
456
+ return t.map((r) => r[d], { skipVoid: !1 });
457
+ }
458
+ return {
459
+ register: i,
460
+ getByName: p,
461
+ listStore: g
462
+ };
463
+ });
464
+ function Ge() {
465
+ return v(ye);
466
+ }
467
+ const Ke = (t, e, i) => {
468
+ i.register(t, e);
469
+ }, Se = h("response"), ke = k(({ client: t }) => {
470
+ const e = Se.store({}), i = O(), g = O(), p = b(e, {
471
+ register(o, s) {
472
+ return {
473
+ ...o,
474
+ [s.fieldId]: s.response
475
+ };
476
+ },
477
+ registerBatch(o, s) {
478
+ return {
479
+ ...o,
480
+ ...s
481
+ };
482
+ },
483
+ clear(o, s) {
484
+ const { [s]: c, ...f } = o;
485
+ return f;
486
+ },
487
+ clearAll() {
488
+ return {};
489
+ }
490
+ });
491
+ function d(o, s) {
492
+ p.register({ fieldId: o, response: s });
493
+ }
494
+ async function r(o) {
495
+ const s = [];
496
+ return await Promise.allSettled(
497
+ Object.entries(o).map(async ([c, f]) => {
498
+ let l = f;
499
+ const y = t.fields.getById(c).getState();
500
+ if (!y) {
501
+ s.push({
502
+ fieldId: c,
503
+ userMessage: `Field '${c}' not found`,
504
+ systemMessage: `No field with ID '${c}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
505
+ value: l
506
+ });
507
+ return;
508
+ }
509
+ if (y.multiple && (typeof l == "string" || typeof l == "number" || typeof l == "boolean") && (l = [l]), y.validation && !K(y.validation)) {
510
+ const w = await C(t, y.validation, {
511
+ $input: l
512
+ });
513
+ if (typeof w == "string") {
514
+ s.push({
515
+ fieldId: c,
516
+ userMessage: w,
517
+ systemMessage: `Field validation resulted in an error: ${w}.`,
518
+ value: l
519
+ });
520
+ return;
521
+ }
522
+ if (w === !1) {
523
+ s.push({
524
+ fieldId: c,
525
+ userMessage: "This field is invalid",
526
+ systemMessage: "Field validation resulted in an unspecified error.",
527
+ value: l
528
+ });
529
+ return;
530
+ }
531
+ }
532
+ if (y.required && (typeof l > "u" || l === null || l === "" || Array.isArray(l) && !l.length)) {
533
+ s.push({
534
+ fieldId: c,
535
+ userMessage: "This field is required",
536
+ systemMessage: "Field is required.",
537
+ value: l
538
+ });
539
+ return;
540
+ }
541
+ if (!y.multiple && Array.isArray(l) && l.length > 1) {
542
+ s.push({
543
+ fieldId: c,
544
+ userMessage: "This field expects a single response",
545
+ systemMessage: "Field expects a single response.",
546
+ value: l
547
+ });
548
+ return;
549
+ }
550
+ if (y.options) {
551
+ const w = y.options.map((F) => F.value), $ = Array.isArray(l) ? l : [l];
552
+ Array.isArray(l) && ($.every((F) => w.includes(F)) || s.push({
553
+ fieldId: c,
554
+ userMessage: "This field expects a valid option",
555
+ systemMessage: `Field expects a valid option. Valid options are: ${w.join(", ")}`,
556
+ value: l
557
+ }));
558
+ }
559
+ })
560
+ ), { responsesToCommit: o, validationErrors: s };
561
+ }
562
+ async function n(o) {
563
+ const { responsesToCommit: s, validationErrors: c } = await r(o);
564
+ return c.length ? { errors: c } : (p.registerBatch(s), { errors: [] });
565
+ }
566
+ const u = e.map((o) => o), m = e.map((o) => Object.keys(o).map((c) => ({
567
+ fieldId: c,
568
+ value: o[c]
569
+ })));
570
+ function S(o) {
571
+ const s = t.fields.getById(o), c = e.map((f) => f[o] || null);
572
+ return B({ f: s, r: c }, ({ f, r: l }) => l || (f != null && f.defaultValue ? f.defaultValue : null));
573
+ }
574
+ function a(o) {
575
+ const s = t.fields.getByName(o);
576
+ return B({ f: s, s: e }, ({ f: c, s: f }) => {
577
+ const l = c && f[c.id] || null;
578
+ return l || (c != null && c.defaultValue ? c.defaultValue : null);
579
+ });
580
+ }
581
+ return x({
582
+ clock: i,
583
+ target: p.clearAll
584
+ }), x({
585
+ clock: g,
586
+ target: p.clear
587
+ }), {
588
+ register: d,
589
+ clearAll: i,
590
+ clear: g,
591
+ commit: n,
592
+ getResponsesToCommit: r,
593
+ listStore: m,
594
+ getAllStore: u,
595
+ getByFieldId: S,
596
+ getByFieldName: a
597
+ };
598
+ });
599
+ function Ye(t) {
600
+ return v(ke, t);
601
+ }
602
+ function ve() {
603
+ if (J())
604
+ return crypto.randomUUID();
605
+ 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);
606
+ return `${t}-${e}-${i}-${g}`;
607
+ }
608
+ const we = () => ({
609
+ id: ve()
610
+ }), he = D("session", "global"), be = () => {
611
+ if (!Y()) return null;
612
+ const t = A.get(he);
613
+ let e = t.isSet() ? t.json() : null;
614
+ return e || (e = we(), t.set(e)), e;
615
+ }, Je = () => be();
616
+ export {
617
+ Me as a,
618
+ Ae as b,
619
+ He as c,
620
+ Te as d,
621
+ Ce as e,
622
+ _e as f,
623
+ Ye as g,
624
+ qe as h,
625
+ Ge as i,
626
+ Je as j,
627
+ Pe as k,
628
+ Ue as l,
629
+ Le as m,
630
+ ze as n,
631
+ Ke as o,
632
+ Ne as p,
633
+ je as q,
634
+ Z as r,
635
+ Ve as s,
636
+ Oe as t
637
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/client",
3
- "version": "0.0.1-dev.1763014928671",
3
+ "version": "0.0.1-dev.1763077817547",
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 B(t),"!":async t=>!await B(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 B(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 B(o))return o;return o}case"or":{let o=null;for(const u of n)if(o=await g(u,e),await B(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 B(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 B(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 B(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 B(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 B(t){return rt(t)?B(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=>Ot(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 Bt(t){const e=document.createElement("div");return e.style.display="block",e.classList.add(j),e.classList.add(`${j}-${t}`),e}function Ot(t,e,r){let n;const a=Bt(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,O]=at(t,e,y,!1,new Set(a));k!==-1&&(o=Math.min(o,k+1),u=Math.max(u,O+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(O=>O.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"),O=t.history.entriesStore.map(i=>i.filter(l=>l.experienceId===e.id)),M=O.map(i=>i.filter(l=>L(l.node))),I=O.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,A=X.store($===!0),P=s.createApi(A,{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:A}),s.sample({source:I,clock:n,filter:i=>i?et(i):!0,target:Y}),s.sample({source:A,filter:i=>!!i,target:n}),s.sample({source:A,filter:Boolean,target:t.eventBus.prepend(()=>({type:"experience_open",experience:e}))}),s.sample({source:A,filter:i=>!i,target:t.eventBus.prepend(()=>({type:"experience_close",experience:e}))}),s.sample({clock:u,target:[p]}),u(),{id:Math.random().toString(36).substring(7),experienceId:e.id,configStore:e.configStore,target:r,componentStore:y,stateStore:k,isOpenStore:A,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(A=>A!==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(A){N.logger("error",A)}});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 O(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:O,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,21 +0,0 @@
1
- interface EventPayload {
2
- [key: string]: string | number | boolean | null | undefined | EventPayload | Array<string | number | boolean | null | undefined | EventPayload>;
3
- }
4
- declare global {
5
- interface Window {
6
- Shopify?: {
7
- analytics?: {
8
- publish?: (event: string, payload: EventPayload) => void;
9
- };
10
- };
11
- }
12
- }
13
- export declare function supportsShopifyAnalytics(w: Window): w is Window & {
14
- Shopify: {
15
- analytics: {
16
- publish: (event: string, payload: EventPayload) => void;
17
- };
18
- };
19
- };
20
- export {};
21
- //# sourceMappingURL=utils.d.ts.map