@commercelayer/app-elements 6.11.0 → 6.11.2

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,14 +1,15 @@
1
1
  "use client";
2
- import { t as W, b as Oe, d as Re, e as Ve, j as t, i as R, g as U, I as j, D as S, f as L, h as Ae, u as Me, k as Ee, l as Ie, n as Y, o as ae, p as x, q as k, T as C, r as $, s as _, v as y, w as re, x as E, y as z, B as O, z as oe, A as qe, C as ie, S as X, H as De, E as ue, F as Le, G as Fe, J as H, K as ze, L as Ge, M as Ue } from "./main-CIxAHy9U.js";
3
- import K, { useReducer as Je, useCallback as A, useMemo as ce, createContext as Be, useContext as We, useState as v, useEffect as T, useRef as de } from "react";
2
+ import { t as B, X as Oe, Y as Re, Z as Ve, j as t, _ as R, $ as U, a0 as j, a1 as S, E as L, a2 as Ae, a3 as Me, a4 as Ee, a5 as Y, a6 as ae, a7 as x, T as k, a8 as C, a9 as $, aa as _, ab as y, ac as re, ad as E, ae as z, af as O, ag as X, ah as Ie, u as oe, ai as qe, aj as De, ak as H, I as Le, al as Fe } from "./main-Q1klqbeV.js";
3
+ import K, { useReducer as ze, useCallback as A, useMemo as ie, createContext as Ge, useContext as Ue, useState as v, useEffect as T, useRef as ue } from "react";
4
4
  import "react-hook-form";
5
+ import { b as Je, e as ce, a as We, c as de, f as Be } from "./fetchCoreResourcesSuggestions-CAoQMAh8.js";
5
6
  import "wouter";
6
- import { p as Q } from "./parseISO-C3M0cm1w.js";
7
+ import { p as Q } from "./parseISO-BSNCna2j.js";
7
8
  function Z(e, s) {
8
9
  const n = e.match(
9
10
  /(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{0,7}))?(?:Z|(.)(\d{2}):?(\d{2})?)?/
10
11
  );
11
- return n ? W(
12
+ return n ? B(
12
13
  Date.UTC(
13
14
  +n[1],
14
15
  +n[2] - 1,
@@ -19,7 +20,7 @@ function Z(e, s) {
19
20
  +((n[7] || "0") + "00").substring(0, 3)
20
21
  ),
21
22
  s?.in
22
- ) : W(NaN, s?.in);
23
+ ) : B(NaN, s?.in);
23
24
  }
24
25
  var Ye = 1, Xe = 4;
25
26
  function P(e) {
@@ -31,7 +32,7 @@ function q(e, s, n) {
31
32
  function D(e, s) {
32
33
  return e == null ? !0 : Ve(e, s);
33
34
  }
34
- const pe = Be(
35
+ const pe = Ge(
35
36
  void 0
36
37
  );
37
38
  function He(e, s) {
@@ -97,7 +98,7 @@ function Ke({
97
98
  children: e,
98
99
  initialValue: s
99
100
  }) {
100
- const [n, l] = Je(He, {
101
+ const [n, l] = ze(He, {
101
102
  value: s.value,
102
103
  renderOptions: {},
103
104
  selectedRuleIndex: 0
@@ -114,7 +115,7 @@ function Ke({
114
115
  l({ type: "SET_VALUE", value: c });
115
116
  }, []), i = A((c, d) => {
116
117
  l({ type: "SET_RENDER_OPTION", path: c, value: d });
117
- }, []), u = ce(
118
+ }, []), u = ie(
118
119
  () => ({
119
120
  state: n,
120
121
  setPath: r,
@@ -137,7 +138,7 @@ function Ke({
137
138
  return /* @__PURE__ */ t.jsx(pe.Provider, { value: u, children: e });
138
139
  }
139
140
  function f() {
140
- const e = We(pe);
141
+ const e = Ue(pe);
141
142
  if (e === void 0)
142
143
  throw new Error("useRuleEngine must be used within a RuleEngineProvider");
143
144
  return e;
@@ -508,7 +509,7 @@ function Ze(e) {
508
509
  function J(e) {
509
510
  const [s, n] = v(void 0);
510
511
  return T(() => {
511
- e?.field != null && Ae(e.field).then((l) => {
512
+ e?.field != null && Je(e.field).then((l) => {
512
513
  const r = fe.find(
513
514
  (o) => o.matcher === e.matcher
514
515
  );
@@ -523,8 +524,8 @@ function J(e) {
523
524
  }, [e?.field, e?.matcher]), { infos: s };
524
525
  }
525
526
  function be(e) {
526
- return e == null || e.length === 0 ? [] : Me(
527
- Ee(
527
+ return e == null || e.length === 0 ? [] : Ae(
528
+ Me(
528
529
  e.flatMap((s) => [
529
530
  s?.group,
530
531
  ...be(s?.nested?.conditions)
@@ -548,7 +549,7 @@ const ve = ({
548
549
  onSelect: r,
549
550
  isMulti: o = !1
550
551
  }) => {
551
- const { sdkClient: a } = Ie(), { data: i } = Y(s, "list", [G({ value: "" })]), { data: u, isLoading: c } = Y(
552
+ const { sdkClient: a } = Ee(), { data: i } = Y(s, "list", [G({ value: "" })]), { data: u, isLoading: c } = Y(
552
553
  s,
553
554
  "list",
554
555
  [
@@ -1696,7 +1697,7 @@ function $t({
1696
1697
  case "free_gift":
1697
1698
  return null;
1698
1699
  default:
1699
- return oe();
1700
+ return ce();
1700
1701
  }
1701
1702
  }
1702
1703
  function Nt({
@@ -1874,7 +1875,7 @@ function Ct({
1874
1875
  value: e,
1875
1876
  name: s
1876
1877
  }) {
1877
- const { setPath: n, schemaType: l } = f(), { t: r } = re(), o = de(null), a = l === "order-rules" ? "order" : l === "price-rules" ? "price" : void 0, i = ae(
1878
+ const { setPath: n, schemaType: l } = f(), { t: r } = re(), o = ue(null), a = l === "order-rules" ? "order" : l === "price-rules" ? "price" : void 0, i = ae(
1878
1879
  Tt.filter(
1879
1880
  (u) => a != null && u.startsWith(a)
1880
1881
  ).map((u) => ({
@@ -1903,7 +1904,7 @@ function Ct({
1903
1904
  return [];
1904
1905
  const c = i.filter(
1905
1906
  (p) => p.label.includes(u)
1906
- ), d = (await qe([a], u)).filter((p) => p.value.startsWith(u)).map((p) => {
1907
+ ), d = (await We([a], u)).filter((p) => p.value.startsWith(u)).map((p) => {
1907
1908
  const g = p.type === "relationship" || p.value.endsWith(".metadata") ? `${p.value}.` : p.value;
1908
1909
  return {
1909
1910
  value: g,
@@ -1990,7 +1991,7 @@ function St({
1990
1991
  } : void 0,
1991
1992
  initialValues: u,
1992
1993
  onSelect: (c) => {
1993
- _(c) && (n(`${s}.matcher`, c.value), ie.includes(
1994
+ _(c) && (n(`${s}.matcher`, c.value), de.includes(
1994
1995
  c.value
1995
1996
  ) && n(`${s}.value`, null));
1996
1997
  }
@@ -2036,7 +2037,7 @@ function te({
2036
2037
  }) {
2037
2038
  const { setPath: r } = f(), o = Object.keys(
2038
2039
  M
2039
- )[0], a = ce(() => typeof e == "object" && e !== null && !Array.isArray(e) ? e : {
2040
+ )[0], a = ie(() => typeof e == "object" && e !== null && !Array.isArray(e) ? e : {
2040
2041
  [o]: []
2041
2042
  }, [e]);
2042
2043
  T(() => {
@@ -2086,7 +2087,7 @@ function te({
2086
2087
  ] }) })
2087
2088
  }
2088
2089
  ),
2089
- /* @__PURE__ */ t.jsx(X, { top: "6", bottom: "2", children: /* @__PURE__ */ t.jsx(De, { variant: "dashed" }) })
2090
+ /* @__PURE__ */ t.jsx(X, { top: "6", bottom: "2", children: /* @__PURE__ */ t.jsx(Ie, { variant: "dashed" }) })
2090
2091
  ] })
2091
2092
  ] }, i.join("-"));
2092
2093
  }
@@ -2273,7 +2274,7 @@ function Vt({
2273
2274
  componentType: l,
2274
2275
  matcher: e?.matcher,
2275
2276
  field: e?.field
2276
- }), d = e == null || ie.includes(
2277
+ }), d = e == null || de.includes(
2277
2278
  e.matcher
2278
2279
  );
2279
2280
  return T(
@@ -2321,12 +2322,12 @@ function ne({
2321
2322
  componentType: n,
2322
2323
  pathKey: l
2323
2324
  }) {
2324
- const { setPath: r } = f(), { user: o } = ue(), { infos: a } = J(e), i = Te(e) ? e.value : void 0;
2325
+ const { setPath: r } = f(), { user: o } = oe(), { infos: a } = J(e), i = Te(e) ? e.value : void 0;
2325
2326
  switch (n) {
2326
2327
  case "date": {
2327
2328
  const u = Q(typeof i == "string" ? i : "");
2328
2329
  return /* @__PURE__ */ t.jsx(
2329
- Fe,
2330
+ De,
2330
2331
  {
2331
2332
  value: L(u) ? u : void 0,
2332
2333
  showTimeSelect: !0,
@@ -2344,7 +2345,7 @@ function ne({
2344
2345
  return L(d) ? d : null;
2345
2346
  }) : [null, null];
2346
2347
  return /* @__PURE__ */ t.jsx(
2347
- Le,
2348
+ qe,
2348
2349
  {
2349
2350
  value: u,
2350
2351
  showTimeSelect: !0,
@@ -2461,7 +2462,7 @@ function ne({
2461
2462
  }
2462
2463
  );
2463
2464
  default:
2464
- return oe();
2465
+ return ce();
2465
2466
  }
2466
2467
  }
2467
2468
  function Te(e) {
@@ -2804,10 +2805,10 @@ const se = {
2804
2805
  return !1;
2805
2806
  }
2806
2807
  };
2807
- function Yt(e) {
2808
+ function Xt(e) {
2808
2809
  const {
2809
2810
  settings: { domain: s }
2810
- } = ue(), [n, l] = v({
2811
+ } = oe(), [n, l] = v({
2811
2812
  actions: {},
2812
2813
  conditions: []
2813
2814
  }), [r, o] = v(
@@ -2820,7 +2821,7 @@ function Yt(e) {
2820
2821
  [e.value]
2821
2822
  ), T(
2822
2823
  function() {
2823
- ze(e.schemaType, s).then((i) => {
2824
+ Be(e.schemaType, s).then((i) => {
2824
2825
  const u = tt(
2825
2826
  i,
2826
2827
  e.schemaType
@@ -2849,7 +2850,7 @@ function Lt(e) {
2849
2850
  setPath: o
2850
2851
  } = f(), [a, i] = v(!1), [u, c] = v(
2851
2852
  e.defaultCodeEditorVisible ?? !1
2852
- ), d = s.rules?.[n], m = de(null), [h, p] = v(0);
2853
+ ), d = s.rules?.[n], m = ue(null), [h, p] = v(0);
2853
2854
  T(
2854
2855
  function() {
2855
2856
  !a && !R(F(m.current?.getValue()), s) && (m.current?.setValue(JSON.stringify(s, null, 2)), e.onChange?.(s));
@@ -2864,7 +2865,7 @@ function Lt(e) {
2864
2865
  [s, a]
2865
2866
  );
2866
2867
  return /* @__PURE__ */ t.jsx(
2867
- Ge,
2868
+ Le,
2868
2869
  {
2869
2870
  hint: e.hint,
2870
2871
  feedback: e.feedback,
@@ -2907,12 +2908,12 @@ function Lt(e) {
2907
2908
  $,
2908
2909
  {
2909
2910
  onClick: () => {
2910
- const B = s.rules?.length ?? 0;
2911
- o(`rules.${B}`, {
2911
+ const W = s.rules?.length ?? 0;
2912
+ o(`rules.${W}`, {
2912
2913
  ...w,
2913
2914
  id: void 0,
2914
2915
  name: `${w.name} (copy)`
2915
- }), l(B);
2916
+ }), l(W);
2916
2917
  },
2917
2918
  label: "Duplicate"
2918
2919
  }
@@ -3034,7 +3035,7 @@ function Lt(e) {
3034
3035
  h
3035
3036
  ),
3036
3037
  u && /* @__PURE__ */ t.jsx("div", { className: "shrink-0 basis-2/5", children: /* @__PURE__ */ t.jsx(
3037
- Ue,
3038
+ Fe,
3038
3039
  {
3039
3040
  ref: m,
3040
3041
  name: e.id ?? e.name,
@@ -3082,5 +3083,5 @@ function zt({
3082
3083
  return /* @__PURE__ */ t.jsx("div", { className: "h-full w-full bg-gray-50 p-8 bg-[radial-gradient(#d6d6d6_1px,transparent_1px)] bg-size-[16px_16px] overflow-auto", children: /* @__PURE__ */ t.jsx("div", { className: "max-w-[900px] mx-auto", children: e }) });
3083
3084
  }
3084
3085
  export {
3085
- Yt as RuleEngine
3086
+ Xt as RuleEngine
3086
3087
  };
@@ -0,0 +1,153 @@
1
+ "use client";
2
+ import { am as f } from "./main-Q1klqbeV.js";
3
+ const y = f([
4
+ "blank",
5
+ "present",
6
+ "null",
7
+ "not_null"
8
+ ]);
9
+ async function v(t, r) {
10
+ switch (r === "localhost" && (r = "commercelayer.co"), t) {
11
+ case "none":
12
+ break;
13
+ case "organization-config":
14
+ return (await fetch(
15
+ `https://provisioning.${r}/api/public/schemas/organization_config`
16
+ )).json();
17
+ case "order-rules":
18
+ return (await fetch(`https://core.${r}/api/public/schemas/order_rules`)).json();
19
+ case "price-rules":
20
+ return (await fetch(`https://core.${r}/api/public/schemas/price_rules`)).json();
21
+ }
22
+ }
23
+ function _(t) {
24
+ return null;
25
+ }
26
+ const c = /* @__PURE__ */ (() => {
27
+ let t;
28
+ return async (r = !0) => {
29
+ if (r) {
30
+ for (; t == null; )
31
+ await new Promise((e) => setTimeout(e, 100));
32
+ return t;
33
+ }
34
+ return t != null || (t = await fetch("https://core.commercelayer.io/api/public/resources").then(async (e) => await e.json()).then((e) => ({
35
+ data: e.data.concat([
36
+ {
37
+ id: "inventory",
38
+ type: "resources",
39
+ attributes: {
40
+ fields: {
41
+ available: {
42
+ name: "available",
43
+ type: "boolean",
44
+ desc: "Indicates if the sku is available."
45
+ },
46
+ quantity: {
47
+ name: "quantity",
48
+ type: "integer",
49
+ desc: "The available stock quantity."
50
+ }
51
+ },
52
+ relationships: {}
53
+ }
54
+ }
55
+ ]).map((a) => a.id === "sku" ? (delete a.attributes.fields.inventory, {
56
+ ...a,
57
+ attributes: {
58
+ ...a.attributes,
59
+ relationships: {
60
+ ...a.attributes.relationships,
61
+ inventory: {
62
+ type: "has_one",
63
+ desc: "The associated inventory.",
64
+ required: "required",
65
+ creatable: !0,
66
+ updatable: !0,
67
+ filterable: !0,
68
+ sortable: !0,
69
+ parent_resource: "Api::SkuResource",
70
+ class_name: "Inventory"
71
+ }
72
+ }
73
+ }
74
+ }) : a)
75
+ })).then(
76
+ ({ data: e }) => e.reduce((a, s, n, o) => ({
77
+ ...a,
78
+ [s.id]: {
79
+ ...s,
80
+ fields: Object.entries(s.attributes.fields).filter(([i]) => !i.startsWith("_")),
81
+ relationships: Object.entries(s.attributes.relationships).filter(([i]) => !i.startsWith("_")).filter(
82
+ ([, i]) => e.find(
83
+ (u) => u.id === h(i.class_name)
84
+ ) != null
85
+ )
86
+ }
87
+ }), {})
88
+ ).catch((e) => {
89
+ throw e;
90
+ })), t;
91
+ };
92
+ })();
93
+ c(!1);
94
+ async function m(t, r) {
95
+ if (!new RegExp(`^(${t.join("|")})(.|$)`).test(r))
96
+ return t.map((s) => ({
97
+ value: s,
98
+ type: "relationship"
99
+ }));
100
+ const e = await d(r);
101
+ return [].concat(
102
+ e.resource?.fields.map(([s]) => ({
103
+ value: `${e.resourcePath}.${s}`,
104
+ type: "field"
105
+ })) ?? []
106
+ ).concat(
107
+ e.resource?.relationships.map(([s]) => ({
108
+ value: `${e.resourcePath}.${s}`,
109
+ type: "relationship"
110
+ })) ?? []
111
+ );
112
+ }
113
+ async function d(t, r) {
114
+ const e = await c(), a = t.replace(/\.$/, "").split("."), s = a.shift();
115
+ return r ??= e[s ?? ""], a.reduce(
116
+ (n, o) => {
117
+ const i = n.resource?.relationships.find(
118
+ ([l]) => l === o
119
+ )?.[1].class_name;
120
+ if (i == null) {
121
+ const l = n.resource?.fields.find(([p]) => p === o)?.[1];
122
+ return {
123
+ ...n,
124
+ field: l != null ? {
125
+ ...l,
126
+ name: o
127
+ } : void 0
128
+ };
129
+ }
130
+ const u = e[h(i)];
131
+ return u == null ? n : {
132
+ path: n.path,
133
+ resourcePath: `${n.resourcePath == null ? "" : `${n.resourcePath}.`}${o}`,
134
+ resource: u
135
+ };
136
+ },
137
+ {
138
+ path: t,
139
+ resourcePath: r != null ? s ?? "" : "",
140
+ resource: r
141
+ }
142
+ );
143
+ }
144
+ function h(t) {
145
+ return t.replace(/([A-Z])/g, "_$1").replace(/^_/, "").toLowerCase();
146
+ }
147
+ export {
148
+ m as a,
149
+ d as b,
150
+ y as c,
151
+ _ as e,
152
+ v as f
153
+ };