@commercelayer/app-elements 6.0.0 → 6.0.1

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,124 +0,0 @@
1
- "use client";
2
- const c = /* @__PURE__ */ (() => {
3
- let t;
4
- return async (a = !0) => {
5
- if (a) {
6
- for (; t == null; )
7
- await new Promise((e) => setTimeout(e, 100));
8
- return t;
9
- }
10
- return t != null || (t = await fetch("https://core.commercelayer.io/api/public/resources").then(async (e) => await e.json()).then((e) => ({
11
- data: e.data.concat([
12
- {
13
- id: "inventory",
14
- type: "resources",
15
- attributes: {
16
- fields: {
17
- available: {
18
- type: "boolean",
19
- desc: "Indicates if the sku is available."
20
- },
21
- quantity: {
22
- type: "integer",
23
- desc: "The available stock quantity."
24
- }
25
- },
26
- relationships: {}
27
- }
28
- }
29
- ]).map((s) => s.id === "sku" ? (delete s.attributes.fields.inventory, {
30
- ...s,
31
- attributes: {
32
- ...s.attributes,
33
- relationships: {
34
- ...s.attributes.relationships,
35
- inventory: {
36
- type: "has_one",
37
- desc: "The associated inventory.",
38
- required: "required",
39
- creatable: !0,
40
- updatable: !0,
41
- filterable: !0,
42
- sortable: !0,
43
- parent_resource: "Api::SkuResource",
44
- class_name: "Inventory"
45
- }
46
- }
47
- }
48
- }) : s)
49
- })).then(
50
- ({ data: e }) => e.reduce((s, r, i, u) => ({
51
- ...s,
52
- [r.id]: {
53
- ...r,
54
- fields: Object.entries(r.attributes.fields).filter(([n]) => !n.startsWith("_")),
55
- relationships: Object.entries(r.attributes.relationships).filter(([n]) => !n.startsWith("_")).filter(
56
- ([, n]) => e.find(
57
- (o) => o.id === h(n.class_name)
58
- ) != null
59
- )
60
- }
61
- }), {})
62
- ).catch((e) => {
63
- throw e;
64
- })), t;
65
- };
66
- })();
67
- c(!1);
68
- async function f(t, a) {
69
- if (!new RegExp(`^(${t.join("|")})(.|$)`).test(a))
70
- return t.map((r) => ({
71
- value: r,
72
- type: "relationship"
73
- }));
74
- const e = await p(a);
75
- return [].concat(
76
- e.resource?.fields.map(([r]) => ({
77
- value: `${e.resourcePath}.${r}`,
78
- type: "field"
79
- })) ?? []
80
- ).concat(
81
- e.resource?.relationships.map(([r]) => ({
82
- value: `${e.resourcePath}.${r}`,
83
- type: "relationship"
84
- })) ?? []
85
- );
86
- }
87
- async function p(t, a) {
88
- const e = await c(), s = t.replace(/\.$/, "").split("."), r = s.shift();
89
- return a ??= e[r ?? ""], s.reduce(
90
- (i, u) => {
91
- const n = i.resource?.relationships.find(
92
- ([l]) => l === u
93
- )?.[1].class_name;
94
- if (n == null) {
95
- const l = i.resource?.fields.find(([d]) => d === u)?.[1];
96
- return {
97
- ...i,
98
- field: l != null ? {
99
- ...l,
100
- name: u
101
- } : void 0
102
- };
103
- }
104
- const o = e[h(n)];
105
- return o == null ? i : {
106
- path: i.path,
107
- resourcePath: `${i.resourcePath == null ? "" : `${i.resourcePath}.`}${u}`,
108
- resource: o
109
- };
110
- },
111
- {
112
- path: t,
113
- resourcePath: a != null ? r ?? "" : "",
114
- resource: a
115
- }
116
- );
117
- }
118
- function h(t) {
119
- return t.replace(/([A-Z])/g, "_$1").replace(/^_/, "").toLowerCase();
120
- }
121
- export {
122
- p as a,
123
- f
124
- };