@picked/client 0.0.12-next.13 → 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.
@@ -1,5 +1,23 @@
1
- import { a as l } from "../../../supports-BjhuLJ8z.js";
2
- const o = {
1
+ import { a as n } from "../../../supports-DBMT17KZ.js";
2
+ import "../../../user-session-Ht0ayuo5.js";
3
+ import "../../../experience-instance-CeuHLrdL.js";
4
+ import "effector";
5
+ function p() {
6
+ var e;
7
+ if (n())
8
+ return (e = window.pickedConfig) == null ? void 0 : e.product;
9
+ }
10
+ function s() {
11
+ var e;
12
+ if (n())
13
+ return (e = window.pickedConfig) == null ? void 0 : e.collection;
14
+ }
15
+ function m() {
16
+ var e, o;
17
+ if (n())
18
+ return (o = (e = window.pickedConfig) == null ? void 0 : e.storefront_api) == null ? void 0 : o.token;
19
+ }
20
+ const t = {
3
21
  homepage: /^\/$/,
4
22
  page: /(?:^|\/)pages\/[^/]+$/,
5
23
  blog: /(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,
@@ -10,68 +28,74 @@ const o = {
10
28
  accountWildcard: /^\/account\/.+/,
11
29
  accountLogin: /^\/account\/login(?:\/|$)/,
12
30
  accountRegister: /^\/account\/register(?:\/|$)/
13
- }, c = (e, a) => a ? !!e.exec(a.pathname) : !1, i = (e, a) => {
14
- if (a) {
15
- const t = e.exec(a.pathname);
16
- if (t)
17
- return t[1];
31
+ }, a = (e, o) => o ? !!e.exec(o.pathname) : !1, c = (e, o) => {
32
+ if (o) {
33
+ const i = e.exec(o.pathname);
34
+ if (i)
35
+ return i[1];
18
36
  }
19
- }, n = (e) => {
20
- var a, t, p, s;
37
+ }, r = (e) => {
38
+ var o, i;
21
39
  switch (e) {
22
40
  case "product":
23
- return ((t = (a = globalThis.window.pickedConfig) == null ? void 0 : a.product) == null ? void 0 : t.handle) ?? !1;
41
+ return ((o = p()) == null ? void 0 : o.handle) ?? !1;
24
42
  case "collection":
25
- return ((s = (p = globalThis.window.pickedConfig) == null ? void 0 : p.collection) == null ? void 0 : s.handle) ?? !1;
43
+ return ((i = s()) == null ? void 0 : i.handle) ?? !1;
26
44
  default:
27
45
  return !1;
28
46
  }
29
- }, r = {
47
+ }, l = {
30
48
  // Pages
31
- "is-page": ({ location: e }) => c(o.page, e),
32
- "get-page-handle": ({ location: e }) => i(o.page, e),
49
+ "is-page": ({ location: e }) => a(t.page, e),
50
+ "get-page-handle": ({ location: e }) => c(t.page, e),
33
51
  // Products
34
- "is-product-page": () => !!n("product"),
35
- "get-product-handle": () => n("product"),
52
+ "is-product-page": () => !!r("product"),
53
+ "get-product-handle": () => r("product"),
36
54
  // Collections
37
- "is-collection-page": () => !!n("collection"),
38
- "get-collection-handle": () => n("collection"),
55
+ "is-collection-page": () => !!r("collection"),
56
+ "get-collection-handle": () => r("collection"),
39
57
  // Blogs
40
- "is-blog-page": ({ location: e }) => c(o.blog, e),
41
- "get-blog-handle": ({ location: e }) => i(o.blog, e),
58
+ "is-blog-page": ({ location: e }) => a(t.blog, e),
59
+ "get-blog-handle": ({ location: e }) => c(t.blog, e),
42
60
  // Blog Articles
43
- "is-article-page": ({ location: e }) => c(o.article, e),
44
- "get-article-handle": ({ location: e }) => i(o.article, e),
61
+ "is-article-page": ({ location: e }) => a(t.article, e),
62
+ "get-article-handle": ({ location: e }) => c(t.article, e),
45
63
  // Apps
46
- "is-app-proxy-page": ({ location: e }) => c(o.appProxy, e),
47
- "get-app-proxy-handle": ({ location: e }) => i(o.appProxy, e),
64
+ "is-app-proxy-page": ({ location: e }) => a(t.appProxy, e),
65
+ "get-app-proxy-handle": ({ location: e }) => c(t.appProxy, e),
48
66
  // Account
49
- "is-account-page": ({ location: e }) => c(o.accountWildcard, e),
50
- "is-login-page": ({ location: e }) => c(o.accountLogin, e),
51
- "is-register-page": ({ location: e }) => c(o.accountRegister, e),
67
+ "is-account-page": ({ location: e }) => a(t.accountWildcard, e),
68
+ "is-login-page": ({ location: e }) => a(t.accountLogin, e),
69
+ "is-register-page": ({ location: e }) => a(t.accountRegister, e),
52
70
  // Cart
53
- "is-cart-page": ({ location: e }) => c(o.cart, e),
71
+ "is-cart-page": ({ location: e }) => a(t.cart, e),
54
72
  // Checkout
55
- "is-checkout-page": ({ location: e }) => c(o.checkout, e),
73
+ "is-checkout-page": ({ location: e }) => a(t.checkout, e),
56
74
  // Homepage
57
- "is-homepage": ({ location: e }) => c(o.homepage, e)
75
+ "is-homepage": ({ location: e }) => a(t.homepage, e)
58
76
  };
59
- function g(e) {
60
- var a, t;
61
- return typeof ((t = (a = e.Shopify) == null ? void 0 : a.analytics) == null ? void 0 : t.publish) == "function";
77
+ function g() {
78
+ if (n())
79
+ return window.Shopify;
80
+ }
81
+ function u(e) {
82
+ var o, i;
83
+ return typeof ((i = (o = g()) == null ? void 0 : o.analytics) == null ? void 0 : i.publish) == "function";
62
84
  }
63
- const d = () => ({
85
+ const w = () => ({
64
86
  name: "shopify",
65
87
  setup: (e) => {
66
- Object.entries(r).forEach(([a, t]) => {
67
- e.registerPredicate(`shopify-${a}`, t);
68
- }), l() && e.eventBus.watch((a) => {
69
- g(window) && a.type === "session" && window.Shopify.analytics.publish("picked:session", {
70
- id: a.id
88
+ Object.entries(l).forEach(([o, i]) => {
89
+ e.registerPredicate(`shopify-${o}`, i);
90
+ }), n() && e.eventBus.watch((o) => {
91
+ u() && o.type === "session" && window.Shopify.analytics.publish("picked:session", {
92
+ id: o.id
71
93
  });
72
94
  });
73
95
  }
74
96
  });
75
97
  export {
76
- d as shopifyPlugin
98
+ m as getPickedConfigStorefrontApiToken,
99
+ g as getShopify,
100
+ w as shopifyPlugin
77
101
  };
@@ -1,8 +1,8 @@
1
- import { a as f, G as c, f as m } from "../../../supports-BjhuLJ8z.js";
1
+ import { a as f, G as c, d as m } from "../../../supports-DBMT17KZ.js";
2
2
  import { p as a } from "../../../object-JwZ58NOH.js";
3
3
  const o = c;
4
4
  let s;
5
- const d = (r) => ({
5
+ const y = (r) => ({
6
6
  name: "single-page-app",
7
7
  setup: (n) => {
8
8
  r.instrumentHistory && f() && h(() => {
@@ -33,5 +33,5 @@ function h(r) {
33
33
  a(o.history, "pushState", n), a(o.history, "replaceState", n);
34
34
  }
35
35
  export {
36
- d as singlePageAppPlugin
36
+ y as singlePageAppPlugin
37
37
  };
@@ -1,4 +1,4 @@
1
- import { a as s, k as i } from "../../../supports-BjhuLJ8z.js";
1
+ import { a as s, j as i } from "../../../supports-DBMT17KZ.js";
2
2
  const p = () => ({
3
3
  name: "web-components",
4
4
  setup: (e) => {
@@ -1,4 +1,4 @@
1
- import { a as i } from "../../../supports-BjhuLJ8z.js";
1
+ import { a as i } from "../../../supports-DBMT17KZ.js";
2
2
  const t = () => ({
3
3
  name: "window",
4
4
  setup: (o) => {
@@ -1,5 +1,5 @@
1
- import { createEvent as i, createStore as v, createEffect as C, sample as n, attach as S } from "effector";
2
- import { h as F } from "../../experience-instance-QtGs0N3g.js";
1
+ import { createEvent as i, createStore as C, createEffect as S, sample as n, attach as h } from "effector";
2
+ import { a as F } from "../../experience-instance-CeuHLrdL.js";
3
3
  function R() {
4
4
  let c, p;
5
5
  return {
@@ -11,19 +11,19 @@ function R() {
11
11
  };
12
12
  }
13
13
  function w(c, p) {
14
- const { promise: g, resolve: t } = R(), o = i(), s = i(), l = i(), m = i(), d = i(), I = c.experiences.listStore.map((e) => e.map((r) => F({ client: c, experience: r }))), x = v({
14
+ const { promise: g, resolve: t } = R(), o = i(), s = i(), l = i(), m = i(), d = i(), I = c.experiences.listStore.map((e) => e.map((r) => F({ client: c, experience: r }))), x = C({
15
15
  currentExperienceIndex: 0,
16
16
  renderedExperiences: [],
17
17
  isComplete: !1
18
- }), f = C(
18
+ }), f = S(
19
19
  async ({
20
20
  experience: e,
21
21
  availableRenderers: r,
22
- startRendererIndex: h = 0
22
+ startRendererIndex: v = 0
23
23
  }) => {
24
24
  if (!e)
25
25
  return null;
26
- for (let a = h; a < r.length; a++) {
26
+ for (let a = v; a < r.length; a++) {
27
27
  const u = r[a], E = e.componentStore.getState();
28
28
  if (E && (u != null && u.isValidComponent(E.component)))
29
29
  return { rendered: await u.render(E.component, c, e), rendererIndex: a };
@@ -75,7 +75,7 @@ function w(c, p) {
75
75
  filter: ({ experiences: e, state: r }) => r.currentExperienceIndex >= e.length,
76
76
  target: m
77
77
  });
78
- const k = S({
78
+ const k = h({
79
79
  source: x,
80
80
  effect: (e) => {
81
81
  e.isComplete && t(e.renderedExperiences);
@@ -1,6 +1,6 @@
1
1
  import { createDomain as ht, createEvent as B, combine as C, createApi as ot, createEffect as M, attach as F, split as yt, sample as m } from "effector";
2
2
  import { createFactory as it, invoke as st } from "@withease/factories";
3
- import { i as wt, s as at, a as Nt } from "./supports-BjhuLJ8z.js";
3
+ import { h as wt, s as at, a as Nt } from "./supports-DBMT17KZ.js";
4
4
  import { l as I } from "./logger-C9a75KZn.js";
5
5
  import { i as It } from "./object-JwZ58NOH.js";
6
6
  function xt(t) {
@@ -768,14 +768,14 @@ function Yt(t) {
768
768
  return st(Gt, t);
769
769
  }
770
770
  export {
771
- j as a,
772
- Yt as b,
773
- Jt as c,
771
+ jt as a,
772
+ Jt as b,
773
+ Yt as c,
774
774
  Xt as d,
775
775
  et as e,
776
- Ot as f,
776
+ At as f,
777
777
  zt as g,
778
- jt as h,
779
- At as i,
778
+ j as h,
779
+ Ot as i,
780
780
  Qt as t
781
781
  };
@@ -81,15 +81,15 @@ function h() {
81
81
  export {
82
82
  t as G,
83
83
  l as a,
84
- a as b,
85
- h as c,
86
- r as d,
87
- e,
88
- s as f,
89
- c as g,
90
- u as h,
91
- i,
92
- f as j,
93
- y as k,
84
+ r as b,
85
+ e as c,
86
+ s as d,
87
+ a as e,
88
+ c as f,
89
+ u as g,
90
+ i as h,
91
+ f as i,
92
+ y as j,
93
+ h as k,
94
94
  p as s
95
95
  };
@@ -0,0 +1,28 @@
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
+ shop: string;
11
+ };
12
+ }
13
+ }
14
+ export declare function getShopify(): {
15
+ analytics?: {
16
+ publish?: (event: string, payload: EventPayload) => void;
17
+ };
18
+ shop: string;
19
+ } | undefined;
20
+ export declare function supportsShopifyAnalytics(w: Window): w is Window & {
21
+ Shopify: {
22
+ analytics: {
23
+ publish: (event: string, payload: EventPayload) => void;
24
+ };
25
+ };
26
+ };
27
+ export {};
28
+ //# sourceMappingURL=global-obj.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-obj.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/global-obj.ts"],"names":[],"mappings":"AAEA,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;YACD,IAAI,EAAE,MAAM,CAAA;SACb,CAAA;KACF;CACF;AAED,wBAAgB,UAAU;gBARR;QACV,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;KACzD;UACK,MAAM;cASjB;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"}
@@ -1,2 +1,4 @@
1
1
  export { shopifyPlugin } from './plugin';
2
+ export { getPickedConfigStorefrontApiToken } from './picked-config';
3
+ export { getShopify } from './global-obj';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAGxC,OAAO,EAAE,iCAAiC,EAAE,MAAM,iBAAiB,CAAA;AAGnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA"}
@@ -1,7 +1,4 @@
1
1
  import { CreateClientOptions } from '../../index';
2
- interface EventPayload {
3
- [key: string]: string | number | boolean | null | undefined | EventPayload | Array<string | number | boolean | null | undefined | EventPayload>;
4
- }
5
2
  export interface PickedConfigExperiment {
6
3
  enabled: boolean;
7
4
  id: string;
@@ -54,24 +51,46 @@ export interface ShopifyPickedConfig {
54
51
  customer?: PickedConfigCustomer;
55
52
  product?: PickedConfigProduct;
56
53
  collection?: PickedConfigCollection;
57
- experiments: PickedConfigExperiment[];
54
+ experiments?: PickedConfigExperiment[];
55
+ storefront_api?: {
56
+ token?: string;
57
+ };
58
58
  }
59
59
  declare global {
60
60
  interface Window {
61
- Shopify?: {
62
- analytics?: {
63
- publish?: (event: string, payload: EventPayload) => void;
64
- };
65
- };
66
61
  pickedConfig?: Readonly<Partial<CreateClientOptions> & ShopifyPickedConfig>;
67
62
  }
68
63
  }
69
- export declare function supportsShopifyAnalytics(w: Window): w is Window & {
70
- Shopify: {
71
- analytics: {
72
- publish: (event: string, payload: EventPayload) => void;
73
- };
74
- };
75
- };
76
- export {};
77
- //# sourceMappingURL=utils.d.ts.map
64
+ export declare function getPickedConfigCustomer(): Partial<{
65
+ accepts_marketing: boolean;
66
+ email: string;
67
+ first_name: string | null;
68
+ has_account: boolean;
69
+ id: number;
70
+ last_name: string | null;
71
+ orders_count: number;
72
+ phone: string | null;
73
+ tax_exempt: boolean;
74
+ }> | undefined;
75
+ export declare function getPickedConfigProduct(): Partial<{
76
+ available: boolean;
77
+ collections: PickedConfigProductCollection[];
78
+ title: string;
79
+ id: number;
80
+ handle: string;
81
+ featured_image: string;
82
+ vendor: string;
83
+ url: string;
84
+ price: number;
85
+ tags: string[];
86
+ variants: PickedConfigProductVariant[];
87
+ metafields: Record<string, unknown>;
88
+ }> | undefined;
89
+ export declare function getPickedConfigCollection(): Partial<{
90
+ title: string;
91
+ id: number;
92
+ handle: string;
93
+ }> | undefined;
94
+ export declare function getPickedConfigExperiments(): PickedConfigExperiment[] | undefined;
95
+ export declare function getPickedConfigStorefrontApiToken(): string | undefined;
96
+ //# sourceMappingURL=picked-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"picked-config.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/picked-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAGtD,MAAM,WAAW,sBAAsB;IAErC,OAAO,EAAE,OAAO,CAAA;IAGhB,EAAE,EAAE,MAAM,CAAA;IAGV,IAAI,EAAE,MAAM,CAAA;IAGZ,OAAO,EAAE,MAAM,CAAA;IAGf,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;CACf,CAAC,CAAA;AAEF,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC;IAC/C,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,kBAAkB,EAAE,MAAM,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC,CAAA;AAEF,MAAM,MAAM,6BAA6B,GAAG,OAAO,CAAC;IAClD,EAAE,EAAE,MAAM,CAAA;CACX,CAAC,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC;IACxC,SAAS,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,6BAA6B,EAAE,CAAA;IAC5C,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,QAAQ,EAAE,0BAA0B,EAAE,CAAA;IACtC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;IACzC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,oBAAoB,CAAA;IAC/B,OAAO,CAAC,EAAE,mBAAmB,CAAA;IAC7B,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC,WAAW,CAAC,EAAE,sBAAsB,EAAE,CAAA;IACtC,cAAc,CAAC,EAAE;QACf,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC,CAAA;KAC5E;CACF;AAED,wBAAgB,uBAAuB;uBA3BlB,OAAO;WACnB,MAAM;gBACD,MAAM,GAAG,IAAI;iBACZ,OAAO;QAChB,MAAM;eACC,MAAM,GAAG,IAAI;kBACV,MAAM;WACb,MAAM,GAAG,IAAI;gBACR,OAAO;eAyBpB;AAED,wBAAgB,sBAAsB;eAlDzB,OAAO;iBACL,6BAA6B,EAAE;WACrC,MAAM;QACT,MAAM;YACF,MAAM;oBACE,MAAM;YACd,MAAM;SACT,MAAM;WACJ,MAAM;UACP,MAAM,EAAE;cACJ,0BAA0B,EAAE;gBAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;eA6CpC;AAED,wBAAgB,yBAAyB;WA7EhC,MAAM;QACT,MAAM;YACF,MAAM;eAiFf;AAED,wBAAgB,0BAA0B,yCAMzC;AAED,wBAAgB,iCAAiC,uBAMhD"}
@@ -39,4 +39,4 @@ export declare const shopifyPredicates: {
39
39
  'is-homepage': ({ location }: PredicateArgs) => boolean;
40
40
  };
41
41
  export {};
42
- //# sourceMappingURL=shopify.d.ts.map
42
+ //# sourceMappingURL=predicates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/predicates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAmB9D,eAAO,MAAM,gBAAgB,GAC3B,cAAc,MAAM,EACpB,WAAW,aAAa,CAAC,UAAU,CAAC,KACnC,OAMF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,MAAM,EACpB,WAAW,aAAa,CAAC,UAAU,CAAC,uBAQrC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,SAAS,GAAG,YAAY,mBASlE,CAAA;AAED,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CACrC;AAED,eAAO,MAAM,iBAAiB;8BAEF,aAAa;sCACL,aAAa;;;;;mCAQhB,aAAa;sCACV,aAAa;sCAEb,aAAa;yCACV,aAAa;wCAGd,aAAa;2CACV,aAAa;sCAGlB,aAAa;oCAEf,aAAa;uCACV,aAAa;mCAGjB,aAAa;uCAET,aAAa;kCAElB,aAAa;CAC5C,CAAA"}
@@ -0,0 +1 @@
1
+ "use strict";const p=require("effector"),y=require("@withease/factories"),w=require("./experience-instance-B2l_MG7I.cjs"),b=require("./logger-BsmHUUw1.cjs"),x=require("./storage-DuRlyFaY.cjs"),P=require("./id-BKIWbSTy.cjs"),M=require("./object-BbFTsGh3.cjs"),B=require("./supports-YvpQZxbh.cjs"),j=p.createDomain("experience"),T=y.createFactory(({client:t,experience:e})=>{const i=j.store(e),g=p.createApi(i,{merge(c,S){return{...c,...S.experience}}}),m=i.map(c=>({name:c.name,decisionLogic:c.decide,targetSelectors:c.targets,initializeOpenLogic:e.initializeOpen})),d=t.components.listStore.map(c=>c.find(S=>S.name===`experience:${e.id}`)||c.find(S=>S.name==="experience"),{skipVoid:!1}),r=i.map(c=>({steps:c.steps,nodes:c.nodes,edges:c.edges,conditionals:c.conditionals})),n=e.actions??[];return{id:e.id,configStore:m,treeStore:r,componentStore:d,actions:n,merge:g.merge}});function V(t){return y.invoke(T,t)}const N=y.createFactory(({client:t})=>{const e=j.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.id]:n}}});function g(r){const n=e.getState()[r.id];if(n){n.merge({experience:r,strategy:"override"});return}const c=V({client:t,experience:r});i.register(c)}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getById:d,listStore:m}});function C(t){return y.invoke(N,t)}const L=(t,e)=>{e.register(t)},O=(t,e)=>{const{targetSelectors:i}=e.configStore.getState(),g=w.getTargetElements(i,e.id);g.forEach(({elements:d})=>d.forEach(r=>w.tagTargetElement(r,e.id))),w.createAppHosts(g,e.id).forEach(d=>{t.experienceInstances.spawn(e,d)})},q=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await _(t,e)&&O(t,e)}))},_=async(t,e)=>{const{decisionLogic:i,targetSelectors:g}=e.configStore.getState();return w.getTargetElements(g,e.id).length<1||g.length===0?!1:i&&w.isRulesLogic(i)?await w.evaluateRuleLogic(t,i)===!0:!0},U=p.createDomain("component"),H=y.createFactory(({client:t,component:e,name:i})=>{const g=t.frameworks.getByName(e.frameworkName);return{name:i,component:e,frameworkStore:g}});function K(t){return y.invoke(H,t)}const z=y.createFactory(({client:t})=>{const e=U.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:n}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Component '${r}' already registered. Registering again will override the previous registration.`);const S=K({client:t,name:r,component:n});i.register(S)}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function G(t){return y.invoke(z,t)}const Y=(t,e,i)=>{i.register(t,e)},J=p.createDomain("framework"),Q=y.createFactory(({client:t})=>{const e=J.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:n.framework}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Framework '${r}' already registered. Registering again will override the previous registration.`),i.register({name:r,framework:n})}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function W(t){return y.invoke(Q,t)}const X=(t,e)=>{e.register(t.name,t)},Z=6e3,D=x.createStorageKey("last_ping","global"),ee=t=>`${t}/api/v1/ping`,te=async t=>{try{const e=Date.now(),i=localStorage.getItem(D);if(i&&e-parseInt(i)<Z)return!0;const g=ee(t.apiUrl),m={projectId:t.projectId,path:window.location.pathname},d=JSON.stringify(m),r={"Content-Type":"application/json"},n=document.getElementById("picked_script"),c=n==null?void 0:n.dataset.verceltoken;c&&(r["x-vercel-protection-bypass"]=c);const k=(await fetch(g,{method:"POST",headers:r,body:d})).ok;return k&&localStorage.setItem(D,e.toString()),k}catch(e){return b.logger("error",e),!1}},re=p.createDomain("predicate"),ne=y.createFactory(({client:t})=>{const e=re.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:{name:n.name,predicate:n.predicate}}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Predicate '${r}' already registered. Registering again will override the previous registration.`),i.register(Object.freeze({name:r,predicate:n}))}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function se(t){return y.invoke(ne,t)}const oe=(t,e,i)=>{i.register(t,e)},$=p.createDomain("feature"),ie=y.createFactory(({client:t})=>{const e=$.store({}),i=$.store([]),g=p.createApi(e,{register(a,o){return{...a,[o.id]:o.feature}}});function m(a,o){e.getState()[a]&&b.logger("warn",`Feature '${a}' already registered. Registering again will override the previous registration.`);const l={id:a,feature:{...o,id:a}};g.register(Object.freeze({id:a,feature:l}))}const d=p.createEffect(async({id:a,key:o,storage:s="local"})=>{const l=x.createStorageKey(`feature:${a}:${o}`,"global"),u=(s==="session"?x.sessionStore:x.localStore).get(l).boolean();return u===null?null:{id:a,key:o,bucket:u}}),r=p.createEffect(a=>{if(!a)return null;const o=x.createStorageKey(`feature:${a.id}:${a.key}`,"global");(a.storage==="session"?x.sessionStore:x.localStore).set(o,a.bucket)}),n=new Map,c=p.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:i},effect:async({allFeaturesStore:a,resolvedFeaturesStore:o},{id:s,decide:l,key:f})=>{const u=o.find(A=>A.id===s);if(u)return u;const v=a[s];if(!v)throw new Error(`Feature with id '${s}' not found`);const F=n.get(`${s}:${f}`);if(F!==void 0){const A=await F;return{id:v.id,bucket:A,key:f,storage:v.feature.storage}}const E=l();n.set(`${s}:${f}`,E);const I=await E;return{id:v.id,bucket:I,key:f,storage:v.feature.storage}}});p.sample({clock:g.register,fn:a=>{const{id:o,feature:s}=a;return{id:o,key:s.feature.key,storage:s.feature.storage}},target:d}),p.sample({source:e,clock:c.doneData,fn:(a,o)=>{var v;const{id:s,bucket:l,storage:f}=o,u=(v=a[s])==null?void 0:v.feature.key;return u?{key:u,id:s,bucket:l,storage:f}:null},target:r});const S=p.combine({allFeaturesStore:e,resolvedFeaturesStore:i}).map(({allFeaturesStore:a,resolvedFeaturesStore:o})=>Object.values(a).map(s=>{const l=o.find(f=>f.id===s.id);return l?{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:()=>({id:s.id,bucket:l.bucket}),isResolved:!0}:{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:async()=>await c(s.feature),isResolved:!1}}));p.sample({clock:c.doneData,source:{resolvedFeatures:i},filter:({resolvedFeatures:a},{id:o})=>!a.some(s=>s.id===o),fn:(a,o)=>o,target:t.eventBus.prepend(a=>({type:"feature_decide",feature:a}))}),p.sample({clock:[d.doneData,c.doneData],source:i,fn:(a,o)=>!o||a.some(s=>s.id===o.id)?a:[...a,o],target:i});function k(a){return e.map(o=>o[a],{skipVoid:!1})}return{register:m,getByName:k,listStore:S}});function ae(t){return y.invoke(ie,t)}const ce=(t,e,i)=>{i.register(t,e)},h=p.createDomain("history");function R(t,e){return{id:P.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ue=y.createFactory(()=>{const t=h.store({entries:[]}),e=h.event(),i=h.event(),g=h.event(),m=h.event();t.on(e,(r,n)=>({entries:[...r.entries,R(n.experienceId,n.node)]})),t.on(i,(r,n)=>({entries:[...r.entries.slice(0,-1),R(n.experienceId,n.node)]})),t.on(m,(r,n)=>n);function d(r,n){const c={lastStepIndex:-1,secondLastStepIndex:-1};for(let S=r.length-1;S>=0;S--){const k=r[S],a=k==null?void 0:k.node;if(!(!a||!w.isStepNode(a))&&!(n&&(k==null?void 0:k.experienceId)!==n))if(c.lastStepIndex===-1)c.lastStepIndex=S;else{c.secondLastStepIndex=S;break}}return c}return t.on(g,(r,n)=>{const{secondLastStepIndex:c}=d(r.entries,n.experienceId),S=c!==-1?r.entries.slice(0,c+1):r.entries;return{...r,entries:S}}),{push:e,replace:i,back:g,restore:m,entriesStore:t.map(r=>r.entries)}});function le(){return y.invoke(ue)}const ge=p.createDomain("field"),de=y.createFactory(()=>{const t=ge.store({}),e=p.createApi(t,{register(r,n){return{...r,[n.field.id]:n.field}}});function i(r){e.register({field:r})}const g=t.map(r=>Object.values(r));function m(r){return t.map(n=>n[r]||null)}function d(r){return t.map(n=>Object.values(n).find(c=>c.name===r)||null)}return{register:i,getById:m,listStore:g,getByName:d}});function pe(){return y.invoke(de)}const me=(t,e)=>{e.register(t)},fe=p.createDomain("action"),ye=y.createFactory(()=>{const t=fe.store({}),e=p.createApi(t,{register(d,r){return{...d,[r.name]:{name:r.name,action:r.action}}}});function i(d,r){e.register({name:d,action:r})}const g=t.map(d=>Object.values(d));function m(d){return t.map(r=>r[d],{skipVoid:!1})}return{register:i,getByName:m,listStore:g}});function Se(){return y.invoke(ye)}const ve=(t,e,i)=>{i.register(t,e)},ke=p.createDomain("response"),Fe=y.createFactory(({client:t})=>{const e=ke.store({}),i=p.createEvent(),g=p.createEvent(),m=p.createApi(e,{register(o,s){return{...o,[s.fieldId]:s.response}},registerBatch(o,s){return{...o,...s}},clear(o,s){const{[s]:l,...f}=o;return f},clearAll(){return{}}});function d(o,s){m.register({fieldId:o,response:s})}async function r(o){const s=[];return await Promise.allSettled(Object.entries(o).map(async([l,f])=>{let u=f;const v=t.fields.getById(l).getState();if(!v){s.push({fieldId:l,userMessage:`Field '${l}' not found`,systemMessage:`No field with ID '${l}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:u});return}if(v.multiple&&(typeof u=="string"||typeof u=="number"||typeof u=="boolean")&&(u=[u]),v.validation&&!M.isEmpty(v.validation)){const F=await w.evaluateRuleLogic(t,v.validation,{$input:u});if(typeof F=="string"){s.push({fieldId:l,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:u});return}if(F===!1){s.push({fieldId:l,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:u});return}}if(v.required&&(typeof u>"u"||u===null||u===""||Array.isArray(u)&&!u.length)){s.push({fieldId:l,userMessage:"This field is required",systemMessage:"Field is required.",value:u});return}if(!v.multiple&&Array.isArray(u)&&u.length>1){s.push({fieldId:l,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:u});return}if(v.options){const F=v.options.map(I=>I.value),E=Array.isArray(u)?u:[u];Array.isArray(u)&&(E.every(I=>F.includes(I))||s.push({fieldId:l,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.join(", ")}`,value:u}))}})),{responsesToCommit:o,validationErrors:s}}async function n(o){const{responsesToCommit:s,validationErrors:l}=await r(o);return l.length?{errors:l}:(m.registerBatch(s),{errors:[]})}const c=e.map(o=>o),S=e.map(o=>Object.keys(o).map(l=>({fieldId:l,value:o[l]})));function k(o){const s=t.fields.getById(o),l=e.map(f=>f[o]||null);return p.combine({f:s,r:l},({f,r:u})=>u||(f!=null&&f.defaultValue?f.defaultValue:null))}function a(o){const s=t.fields.getByName(o);return p.combine({f:s,s:e},({f:l,s:f})=>{const u=l&&f[l.id]||null;return u||(l!=null&&l.defaultValue?l.defaultValue:null)})}return p.sample({clock:i,target:m.clearAll}),p.sample({clock:g,target:m.clear}),{register:d,clearAll:i,clear:g,commit:n,getResponsesToCommit:r,listStore:S,getAllStore:c,getByFieldId:k,getByFieldName:a}});function xe(t){return y.invoke(Fe,t)}function we(){if(B.supportsCryptoRandomUUID())return crypto.randomUUID();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);return`${t}-${e}-${i}-${g}`}const Ie=()=>({id:we()}),he=x.createStorageKey("session","global"),be=()=>{if(!B.supportsLocalStorage())return null;const t=x.localStore.get(he);let e=t.isSet()?t.json():null;return e||(e=Ie(),t.set(e)),e},Ee=()=>be();exports.createActionIndex=Se;exports.createComponentIndex=G;exports.createExperienceIndex=C;exports.createFeatureIndex=ae;exports.createFieldIndex=pe;exports.createFrameworkIndex=W;exports.createHistory=le;exports.createPredicateIndex=se;exports.createResponseIndex=xe;exports.initialiseExperience=O;exports.initialiseExperiences=q;exports.initialiseSession=Ee;exports.ping=te;exports.setupAction=ve;exports.setupComponent=Y;exports.setupExperience=L;exports.setupFeature=ce;exports.setupField=me;exports.setupFramework=X;exports.setupPredicate=oe;