@soma-vertical-web/multi-lib 0.0.48 → 0.0.50

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.
@@ -0,0 +1,221 @@
1
+ import { jsxs as y, Fragment as I, jsx as i } from "react/jsx-runtime";
2
+ import { Utils as S } from "@soma-vertical-web/core-components";
3
+ const h = "fuzzy", b = "operator", w = (e) => ({
4
+ isDepartment: e != null && e.length ? e[0].key === "category-1" : !1
5
+ }), M = (e, t) => {
6
+ const s = decodeURIComponent(t ?? "").slice(1).split("/");
7
+ return e.map((o) => {
8
+ if (o.key === "category-2" && o.__typename === "FacetBoolean") {
9
+ const r = o.values;
10
+ return {
11
+ ...o,
12
+ values: r.filter(
13
+ (a) => !s.find(
14
+ (n) => n.toLowerCase() === a.value || n.toLowerCase() === a.name.toLowerCase()
15
+ )
16
+ )
17
+ };
18
+ }
19
+ return o;
20
+ });
21
+ }, _ = (e, t) => t ? e === "category-1" : !1, O = (e) => e.key === "operator" && (e.value === "and" || e.value === "or"), R = (e) => e.type === "TEXT", j = (e) => e.key === "fuzzy" && (e.value === "0" || e.value === "1" || e.value === "auto"), z = (e) => {
22
+ const { key: t, name: s, values: o } = e;
23
+ return {
24
+ __typename: "FacetBoolean",
25
+ key: t,
26
+ label: s,
27
+ values: o.slice().sort((r, a) => r.name.localeCompare(a.name))
28
+ };
29
+ }, F = ({ key: e, values: t }) => ({
30
+ __typename: "FacetRange",
31
+ key: e,
32
+ values: t
33
+ }), L = (e, t, s) => {
34
+ if (!(e instanceof Object) || !("facets" in e))
35
+ return [];
36
+ const { facets: o = [] } = e, r = t != null && t.length ? t[0].key === "category-1" : !1;
37
+ return o.filter(
38
+ (n) => !s || !_(n.key, r)
39
+ ).map(
40
+ (n) => R(n) ? z(n) : F(n)
41
+ );
42
+ }, N = (e, t) => {
43
+ const s = e.find(({ key: r }) => r === h) ?? null, o = e.find(({ key: r }) => r === b) ?? null;
44
+ s && j(s) && t.append(h, s.value), o && O(o) && t.append(b, o.value);
45
+ }, C = (e) => e.map((t) => {
46
+ const [s, o] = t.split("/");
47
+ return { key: s, value: o };
48
+ }), Y = (e, t) => {
49
+ const s = decodeURIComponent(t ?? "").slice(1).split("/"), o = e.filter(({ value: a }) => !s.includes(decodeURIComponent(a))).map((a) => ({
50
+ ...a,
51
+ value: decodeURIComponent(a.value)
52
+ })), { isDepartment: r } = w(o);
53
+ return o == null ? void 0 : o.filter((a) => !_(a.key, r));
54
+ }, A = ({ pathname: e, searchParams: t }, s) => {
55
+ const o = t.get("sort") ?? "", r = t.get("query") ?? null, a = parseInt(t.get("page") ?? "1", 10);
56
+ return {
57
+ sort: o,
58
+ facets: C(s),
59
+ term: r,
60
+ base: r ? "" : e,
61
+ page: a
62
+ };
63
+ }, J = (e) => {
64
+ const t = new URLSearchParams();
65
+ return Object.entries(e).forEach(([s, o]) => {
66
+ Array.isArray(o) ? o.forEach((r) => t.append(s, r)) : o !== void 0 && t.append(s, o);
67
+ }), t;
68
+ }, v = {
69
+ "responsive-mobile-flex": "_responsive-mobile-flex_t5bry_2",
70
+ "responsive-desktop-flex": "_responsive-desktop-flex_t5bry_13",
71
+ "responsive-mobile-block": "_responsive-mobile-block_t5bry_24",
72
+ "responsive-desktop-block": "_responsive-desktop-block_t5bry_35"
73
+ }, $ = {}, K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
74
+ __proto__: null,
75
+ default: $
76
+ }, Symbol.toStringTag, { value: "Module" })), V = ({
77
+ children: e,
78
+ data: t,
79
+ SectionZone: s,
80
+ className: o
81
+ }) => {
82
+ var f, u;
83
+ const r = ((f = t == null ? void 0 : t.filter((l) => {
84
+ var c, g;
85
+ return ((g = (c = l.config) == null ? void 0 : c.responsive) == null ? void 0 : g.deviceType) === "mobile";
86
+ })[0]) == null ? void 0 : f.sections) || [], a = ((u = t == null ? void 0 : t.filter((l) => {
87
+ var c, g;
88
+ return ((g = (c = l.config) == null ? void 0 : c.responsive) == null ? void 0 : g.deviceType) === "desktop";
89
+ })[0]) == null ? void 0 : u.sections) || [], n = r.slice(0, 1), p = r.slice(1, r.length), d = a.slice(0, 1), m = a.slice(1, a.length);
90
+ return /* @__PURE__ */ y(I, { children: [
91
+ /* @__PURE__ */ y("div", { className: o, children: [
92
+ /* @__PURE__ */ i("div", { className: v["responsive-mobile-flex"], children: /* @__PURE__ */ i(s, { data: n ?? [] }) }),
93
+ /* @__PURE__ */ i("div", { className: v["responsive-desktop-flex"], children: /* @__PURE__ */ i(s, { data: d ?? [] }) })
94
+ ] }),
95
+ e,
96
+ /* @__PURE__ */ i("div", { className: v["responsive-mobile-flex"], children: /* @__PURE__ */ i(s, { data: p ?? [] }) }),
97
+ /* @__PURE__ */ i("div", { className: v["responsive-desktop-flex"], children: /* @__PURE__ */ i(s, { data: m ?? [] }) }),
98
+ /* @__PURE__ */ i(S.Divider, {})
99
+ ] });
100
+ };
101
+ async function x({ contentType: e, storeId: t, CMS_PROJECT_NAME: s, NextCookies: o }) {
102
+ const r = await k({
103
+ contentType: e,
104
+ storeId: t,
105
+ CMS_PROJECT_NAME: s,
106
+ NextCookies: o
107
+ });
108
+ if (r.status === 200) {
109
+ const a = {
110
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
111
+ contentType: e,
112
+ data: r.data
113
+ };
114
+ console.log("Resultado da chamada:", r);
115
+ const n = `backup-${e}-${Date.now()}.json`;
116
+ return await $.writeFile(
117
+ `./backups/${n}`,
118
+ JSON.stringify(a, null, 2),
119
+ "utf-8"
120
+ ), { success: !0, fileName: n };
121
+ }
122
+ return { success: !1, error: r.error || "No data to backup" };
123
+ }
124
+ async function B(e) {
125
+ return x(e);
126
+ }
127
+ async function T({
128
+ contentType: e,
129
+ documentId: t,
130
+ versionId: s,
131
+ storeId: o,
132
+ CMS_PROJECT_NAME: r
133
+ }) {
134
+ const a = t && t.length ? `/${t}` : "", n = s && s.length ? `?versionId=${s}` : "";
135
+ return fetch(
136
+ `https://${o}.myvtex.com/_v/cms/api/${r}/${e}${a}${n}`,
137
+ { cache: "no-cache" }
138
+ );
139
+ }
140
+ async function U({
141
+ contentType: e,
142
+ documents: t,
143
+ NextCookies: s,
144
+ previewId: o,
145
+ CMS_PROJECT_NAME: r,
146
+ storeId: a
147
+ }) {
148
+ var p;
149
+ const n = JSON.parse(
150
+ o ?? ((p = s == null ? void 0 : s().get("cms_preview_data")) == null ? void 0 : p.value) ?? "{}"
151
+ );
152
+ if (n && (n == null ? void 0 : n.contentType) === e) {
153
+ const d = n.documentId && n.documentId.length ? `/${n.documentId}` : "", m = n != null && n.versionId && (n != null && n.versionId.length) ? `?versionId=${n == null ? void 0 : n.versionId}` : "", u = await (await fetch(
154
+ `https://${a}.myvtex.com/_v/cms/api/${r}/${e}${d}${m}`,
155
+ { cache: "no-store" }
156
+ )).json(), l = t.filter(
157
+ (c) => u.id !== c.documentId
158
+ );
159
+ return l.unshift(u), l;
160
+ }
161
+ return t;
162
+ }
163
+ async function k({
164
+ contentType: e,
165
+ NextCookies: t,
166
+ CMS_PROJECT_NAME: s,
167
+ storeId: o,
168
+ previewId: r
169
+ }) {
170
+ var f, u;
171
+ const a = JSON.parse(
172
+ r ?? ((f = t == null ? void 0 : t().get("cms_preview_data")) == null ? void 0 : f.value) ?? "{}"
173
+ ), n = [];
174
+ let p = 1, d = 0, m = !0;
175
+ try {
176
+ do {
177
+ const c = await (await fetch(
178
+ `https://${o}.myvtex.com/_v/cms/api/${s}/${e}?page=${p}`
179
+ )).json();
180
+ p === 1 && (d = c.totalItems), (u = c == null ? void 0 : c.data) != null && u.length && n.push(...c.data), m = c.hasNextPage, p++;
181
+ } while (m && n.length < d);
182
+ if (a.previewMode && n.length) {
183
+ const l = await U({
184
+ contentType: e,
185
+ documents: n,
186
+ NextCookies: t,
187
+ CMS_PROJECT_NAME: s,
188
+ storeId: o
189
+ });
190
+ return {
191
+ status: l.length > 0 ? 200 : 404,
192
+ data: l ?? []
193
+ };
194
+ }
195
+ return {
196
+ status: n.length ? 200 : 404,
197
+ data: n
198
+ };
199
+ } catch (l) {
200
+ return { status: "error", data: [], error: l };
201
+ }
202
+ }
203
+ const q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
204
+ __proto__: null,
205
+ cmsBackup: B,
206
+ getCMSContentType: T,
207
+ getContentType: k
208
+ }, Symbol.toStringTag, { value: "Module" }));
209
+ export {
210
+ V as S,
211
+ K as _,
212
+ N as a,
213
+ M as b,
214
+ J as c,
215
+ Y as d,
216
+ q as e,
217
+ L as f,
218
+ k as g,
219
+ A as p,
220
+ v as r
221
+ };