@soma-vertical-web/multi-lib 0.0.32 → 0.0.34

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 (53) hide show
  1. package/__vite-browser-external-CpdIDx9o.mjs +79 -0
  2. package/__vite-browser-external-DDWPeg5L.js +1 -0
  3. package/constants.d.ts +32 -0
  4. package/contexts/contexts/search/Facets.d.ts +5 -0
  5. package/contexts/contexts/search/Products.d.ts +5 -0
  6. package/contexts/contexts/search/Root.d.ts +5 -0
  7. package/contexts/contexts/search/Search.d.ts +5 -0
  8. package/contexts/contexts/search/SuggestedTerms.d.ts +5 -0
  9. package/contexts/contexts/search/TopSearches.d.ts +6 -0
  10. package/contexts/index.d.ts +24 -0
  11. package/data/api/fetchVtex.d.ts +2 -1
  12. package/data/api/search/autoCompleteSuggestions/index.d.ts +11 -0
  13. package/data/api/search/crosseling/index.d.ts +91 -0
  14. package/data/api/search/facets/index.d.ts +4 -0
  15. package/data/api/search/index.d.ts +6 -0
  16. package/data/api/search/product/index.d.ts +3 -0
  17. package/data/api/search/searchFetch.d.ts +3 -0
  18. package/data/api/search/suggestedTerms/index.d.ts +12 -0
  19. package/data/api/search/topSearch/index.d.ts +3 -0
  20. package/data/helpers/search/facets.d.ts +48 -0
  21. package/data/helpers/search/index.d.ts +12 -0
  22. package/data/helpers/search/product/index.d.ts +279 -0
  23. package/data/helpers/search/product/utils/canonical.d.ts +1 -0
  24. package/data/helpers/search/product/utils/enhanceSku.d.ts +9 -0
  25. package/data/helpers/search/product/utils/images.d.ts +7 -0
  26. package/data/helpers/search/product/utils/index.d.ts +8 -0
  27. package/data/helpers/search/product/utils/productStock.d.ts +7 -0
  28. package/data/helpers/search/product/utils/propertyValue.d.ts +20 -0
  29. package/data/helpers/search/product/utils/sanitizeHtml.d.ts +18 -0
  30. package/data/helpers/search/product/utils/sku.d.ts +5 -0
  31. package/data/helpers/search/product/utils/slugify.d.ts +1 -0
  32. package/data/helpers/search/root.d.ts +11 -0
  33. package/data/helpers/search/search.d.ts +7 -0
  34. package/index.js +19 -19
  35. package/index.mjs +4336 -3979
  36. package/index2.js +1 -1
  37. package/index2.mjs +891 -400
  38. package/package.json +1 -1
  39. package/server.d.ts +13 -0
  40. package/types/constants.d.ts +9 -15
  41. package/types/contexts/contexts/plp.d.ts +13 -0
  42. package/types/contexts/contexts/search.d.ts +10 -4
  43. package/types/data/api/index.d.ts +5 -2
  44. package/types/data/api/search/facets/index.d.ts +13 -13
  45. package/types/data/api/search/index.d.ts +25 -12
  46. package/types/data/api/search/product/index.d.ts +1 -8
  47. package/types/data/events/index.d.ts +0 -4
  48. package/types/data/helpers/index.d.ts +9 -1
  49. package/types/global/product/index.d.ts +5 -4
  50. package/types/layout/team-components/AddToCart/index.d.ts +2 -2
  51. package/types/layout/team-components/Sort/index.d.ts +2 -3
  52. package/types/data/api/search/autoCompleteSuggestions/index.d.ts +0 -7
  53. package/types/data/api/search/suggestedTerms/index.d.ts +0 -7
package/index2.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import * as r from "yup";
2
- import { f as $ } from "./__vite-browser-external-BYRIRx8p.mjs";
3
- const l = async (t, e = {}) => {
4
- const { method: o = "GET", body: n, headers: s = {}, priority: a = "auto" } = e;
5
- return fetch(t, {
1
+ import * as n from "yup";
2
+ import { f as Z, a as ee, b as te, d as re, e as oe, c as ne, p as ae } from "./__vite-browser-external-CpdIDx9o.mjs";
3
+ import se from "sanitize-html";
4
+ const u = async (e, t = {}) => {
5
+ const { method: o = "GET", body: r, headers: s = {}, priority: a = "auto", cache: i = "default" } = t;
6
+ return fetch(e, {
6
7
  method: o,
7
8
  headers: {
8
9
  ...s,
@@ -10,49 +11,69 @@ const l = async (t, e = {}) => {
10
11
  "Content-Type": "application/json"
11
12
  },
12
13
  priority: a,
13
- ...n ? { body: JSON.stringify(n) } : {}
14
+ cache: i,
15
+ ...r ? { body: JSON.stringify(r) } : {}
14
16
  // not body in get
15
- }).then((i) => i.json()).catch((i) => {
16
- console.error("[ERROR FETCH VTEX]", i);
17
+ }).then((c) => c.json()).catch((c) => {
18
+ console.error("[ERROR FETCH VTEX]", c);
17
19
  });
18
- }, R = r.object({
19
- country: r.string().length(3, "Country code must be 3 characters long").required("Country is required"),
20
- postalCode: r.string().nullable()
20
+ }, O = /* @__PURE__ */ new Map();
21
+ async function ie(e, t = {}) {
22
+ var o;
23
+ try {
24
+ const { abort: r = !1 } = t, s = new AbortController();
25
+ r && (O.has(e) && ((o = O.get(e)) == null || o.abort(), O.delete(e)), O.set(e, s));
26
+ const a = u(e, {
27
+ ...t,
28
+ ...r ? { signal: s.signal } : {}
29
+ });
30
+ return r && O.delete(e), a;
31
+ } catch (r) {
32
+ if (r.name === "AbortError") {
33
+ console.log(`[REQUEST CANCELLED]: ${e}`);
34
+ return;
35
+ }
36
+ throw console.error(`[ERROR API]: ${r.message}`), r;
37
+ }
38
+ }
39
+ const ce = n.object({
40
+ country: n.string().length(3, "Country code must be 3 characters long").required("Country is required"),
41
+ postalCode: n.string().nullable()
21
42
  });
22
- async function O({ apiUrl: t, body: e, fetchOptions: o }) {
23
- if (!e) {
43
+ async function le({ apiUrl: e, body: t, fetchOptions: o }) {
44
+ if (!t) {
24
45
  console.error("[ERROR FETCHING] Body is required");
25
46
  return;
26
47
  }
27
- await R.validate(e);
28
- const { country: n, postalCode: s } = e;
29
- return await l(
30
- `${t}/api/checkout/pub/postal-code/${n}/${s}`,
48
+ await ce.validate(t);
49
+ const { country: r, postalCode: s } = t;
50
+ return await u(
51
+ `${e}/api/checkout/pub/postal-code/${r}/${s}`,
31
52
  {
32
53
  method: "POST",
33
- body: e,
54
+ body: t,
34
55
  ...o
35
56
  }
36
57
  );
37
58
  }
38
- const y = r.object({
39
- orderFormId: r.string().nullable(),
40
- sellerCode: r.string().nullable(),
41
- sellerName: r.string().nullable()
59
+ const ue = n.object({
60
+ orderFormId: n.string().nullable(),
61
+ sellerCode: n.string().nullable(),
62
+ sellerName: n.string().nullable()
42
63
  });
43
- async function b({
44
- apiUrl: t,
45
- body: e,
64
+ async function B({
65
+ apiUrl: e,
66
+ body: t,
46
67
  fetchOptions: o
47
68
  }) {
48
- if (!e) {
69
+ if (!t) {
49
70
  console.error("[ERROR FETCHING] Body is required");
50
71
  return;
51
72
  }
52
- await y.validate(e);
53
- const { orderFormId: n, sellerCode: s, sellerName: a } = e, i = s ? `${s.trim()} - ${a}` : null;
54
- return l(
55
- `${t}/api/checkout/pub/orderForm/${n}/attachments/openTextField`,
73
+ await ue.validate(t);
74
+ const { orderFormId: r, sellerCode: s, sellerName: a } = t, i = s ? `${s.trim()} - ${a}` : null;
75
+ return u(
76
+ `${e}/api/checkout/pub/orderForm/${r}/attachments/openTextField`,
56
77
  {
57
78
  method: "POST",
58
79
  body: {
@@ -62,23 +83,23 @@ async function b({
62
83
  }
63
84
  );
64
85
  }
65
- const q = r.object({
66
- orderFormId: r.string().nullable(),
67
- sellerCode: r.string().nullable(),
68
- marketingData: r.object()
86
+ const de = n.object({
87
+ orderFormId: n.string().nullable(),
88
+ sellerCode: n.string().nullable(),
89
+ marketingData: n.object()
69
90
  });
70
- async function F({ apiUrl: t, body: e, fetchOptions: o }) {
71
- if (!e) {
91
+ async function U({ apiUrl: e, body: t, fetchOptions: o }) {
92
+ if (!t) {
72
93
  console.error("[ERROR FETCHING] Body is required");
73
94
  return;
74
95
  }
75
- await q.validate(e);
76
- const { orderFormId: n, sellerCode: s, marketingData: a } = e, i = s ? {
96
+ await de.validate(t);
97
+ const { orderFormId: r, sellerCode: s, marketingData: a } = t, i = s ? {
77
98
  utmCampaign: s ? s.toUpperCase() : "",
78
99
  utmiCampaign: s ? "codigodavendedora" : "semcodigo"
79
100
  } : {};
80
- return l(
81
- `${t}/api/checkout/pub/orderForm/${n}/attachments/marketingData`,
101
+ return u(
102
+ `${e}/api/checkout/pub/orderForm/${r}/attachments/marketingData`,
82
103
  {
83
104
  method: "POST",
84
105
  body: {
@@ -89,104 +110,104 @@ async function F({ apiUrl: t, body: e, fetchOptions: o }) {
89
110
  }
90
111
  );
91
112
  }
92
- const T = r.object({
93
- orderFormId: r.string().nullable(),
94
- sellerCode: r.string().nullable(),
95
- sellerName: r.string().nullable()
113
+ const me = n.object({
114
+ orderFormId: n.string().nullable(),
115
+ sellerCode: n.string().nullable(),
116
+ sellerName: n.string().nullable()
96
117
  });
97
- async function S({ apiUrl: t, body: e, fetchOptions: o }) {
98
- if (!e) {
118
+ async function pe({ apiUrl: e, body: t, fetchOptions: o }) {
119
+ if (!t) {
99
120
  console.error("[ERROR FETCHING] Body is required");
100
121
  return;
101
122
  }
102
- await T.validate(e);
103
- const n = await b({ apiUrl: t, body: e, fetchOptions: o });
104
- return F({
105
- apiUrl: t,
123
+ await me.validate(t);
124
+ const r = await B({ apiUrl: e, body: t, fetchOptions: o });
125
+ return U({
126
+ apiUrl: e,
106
127
  body: {
107
- ...e,
108
- marketingData: n == null ? void 0 : n.marketingData
128
+ ...t,
129
+ marketingData: r == null ? void 0 : r.marketingData
109
130
  },
110
131
  fetchOptions: o
111
132
  });
112
133
  }
113
- const v = r.object({
114
- orderFormId: r.string().nullable(),
115
- coupon: r.string().nullable()
134
+ const ge = n.object({
135
+ orderFormId: n.string().nullable(),
136
+ coupon: n.string().nullable()
116
137
  });
117
- async function E({
118
- apiUrl: t,
119
- body: e,
138
+ async function fe({
139
+ apiUrl: e,
140
+ body: t,
120
141
  fetchOptions: o
121
142
  }) {
122
- if (!e) {
143
+ if (!t) {
123
144
  console.error("[ERROR FETCHING] Body is required");
124
145
  return;
125
146
  }
126
- await v.validate(e);
127
- const { coupon: n = "", orderFormId: s } = e;
128
- return l(
129
- `${t}/api/checkout/pub/orderForm/${s}/coupons`,
147
+ await ge.validate(t);
148
+ const { coupon: r = "", orderFormId: s } = t;
149
+ return u(
150
+ `${e}/api/checkout/pub/orderForm/${s}/coupons`,
130
151
  {
131
152
  method: "POST",
132
- body: { text: n },
153
+ body: { text: r },
133
154
  ...o
134
155
  }
135
156
  );
136
157
  }
137
- const j = r.object({
138
- appId: r.string().required("App ID is required"),
139
- orderFormId: r.string().nullable(),
140
- key: r.array().of(r.string())
158
+ const he = n.object({
159
+ appId: n.string().required("App ID is required"),
160
+ orderFormId: n.string().nullable(),
161
+ key: n.array().of(n.string())
141
162
  });
142
- async function w({
143
- apiUrl: t,
144
- body: e,
163
+ async function Ie({
164
+ apiUrl: e,
165
+ body: t,
145
166
  fetchOptions: o
146
167
  }) {
147
- if (!e) {
168
+ if (!t) {
148
169
  console.error("[ERROR FETCHING] Body is required");
149
170
  return;
150
171
  }
151
- await j.validate(e);
152
- const { appId: n = "faststore", orderFormId: s, key: a } = e;
153
- return l(
154
- `${t}/api/checkout/pub/orderForm/${s}/customData/${n}/${a}`,
172
+ await he.validate(t);
173
+ const { appId: r = "faststore", orderFormId: s, key: a } = t;
174
+ return u(
175
+ `${e}/api/checkout/pub/orderForm/${s}/customData/${r}/${a}`,
155
176
  {
156
177
  method: "PUT",
157
178
  ...o
158
179
  }
159
180
  );
160
181
  }
161
- const k = r.object().shape({
162
- name: r.string().required("Attachment name is required"),
163
- content: r.object().nullable()
182
+ const be = n.object().shape({
183
+ name: n.string().required("Attachment name is required"),
184
+ content: n.object().nullable()
164
185
  });
165
- var f;
166
- const A = r.object().shape({
167
- attachments: (f = r.array().of(k)) == null ? void 0 : f.nullable(),
168
- id: r.string().required("ID of SKU is required"),
169
- index: r.number().integer().nullable(),
170
- quantity: r.number().integer().nullable(),
171
- seller: r.string().required("Seller is required"),
172
- price: r.number().integer()
173
- }), N = r.object({
174
- orderFormId: r.string().required("OrderFormId is required"),
175
- orderItems: r.array().of(A)
186
+ var H;
187
+ const Ce = n.object().shape({
188
+ attachments: (H = n.array().of(be)) == null ? void 0 : H.nullable(),
189
+ id: n.string().required("ID of SKU is required"),
190
+ index: n.number().integer().nullable(),
191
+ quantity: n.number().integer().nullable(),
192
+ seller: n.string().required("Seller is required"),
193
+ price: n.number().integer()
194
+ }), Re = n.object({
195
+ orderFormId: n.string().required("OrderFormId is required"),
196
+ orderItems: n.array().of(Ce)
176
197
  });
177
- async function D({
178
- apiUrl: t,
179
- body: e,
198
+ async function ye({
199
+ apiUrl: e,
200
+ body: t,
180
201
  fetchOptions: o
181
202
  }) {
182
- if (!e) {
203
+ if (!t) {
183
204
  console.error("[ERROR FETCHING] Body is required");
184
205
  return;
185
206
  }
186
- await N.validate(e);
187
- const { orderFormId: n, orderItems: s } = e;
188
- return l(
189
- `${t}/api/checkout/pub/orderForm/${n}/items`,
207
+ await Re.validate(t);
208
+ const { orderFormId: r, orderItems: s } = t;
209
+ return u(
210
+ `${e}/api/checkout/pub/orderForm/${r}/items`,
190
211
  {
191
212
  method: "POST",
192
213
  body: { orderItems: s },
@@ -194,57 +215,57 @@ async function D({
194
215
  }
195
216
  );
196
217
  }
197
- const G = r.object({
198
- orderFormId: r.string().nullable()
218
+ const Fe = n.object({
219
+ orderFormId: n.string().nullable()
199
220
  });
200
- async function P({
201
- apiUrl: t,
202
- body: e,
221
+ async function Oe({
222
+ apiUrl: e,
223
+ body: t,
203
224
  fetchOptions: o
204
225
  }) {
205
- if (!e) {
226
+ if (!t) {
206
227
  console.error("[ERROR FETCHING] Body is required");
207
228
  return;
208
229
  }
209
- await G.validate(e);
210
- const { orderFormId: n } = e;
211
- return l(
212
- `${t}/api/checkout/pub/orderForm/${n}/items/removeAll`,
230
+ await Fe.validate(t);
231
+ const { orderFormId: r } = t;
232
+ return u(
233
+ `${e}/api/checkout/pub/orderForm/${r}/items/removeAll`,
213
234
  {
214
235
  method: "POST",
215
236
  ...o
216
237
  }
217
238
  );
218
239
  }
219
- const _ = r.object().shape({
220
- name: r.string().required("Attachment name is required"),
221
- content: r.object().nullable()
240
+ const $e = n.object().shape({
241
+ name: n.string().required("Attachment name is required"),
242
+ content: n.object().nullable()
222
243
  });
223
- var I;
224
- const B = r.object().shape({
225
- attachments: (I = r.array().of(_)) == null ? void 0 : I.nullable(),
226
- id: r.string().required("ID of SKU is required"),
227
- index: r.number().integer().nullable(),
228
- quantity: r.number().integer().nullable(),
229
- seller: r.string().required("Seller is required"),
230
- price: r.number().integer()
231
- }), H = r.object({
232
- orderFormId: r.string().nullable(),
233
- orderItems: r.array().of(B)
244
+ var G;
245
+ const ve = n.object().shape({
246
+ attachments: (G = n.array().of($e)) == null ? void 0 : G.nullable(),
247
+ id: n.string().required("ID of SKU is required"),
248
+ index: n.number().integer().nullable(),
249
+ quantity: n.number().integer().nullable(),
250
+ seller: n.string().required("Seller is required"),
251
+ price: n.number().integer()
252
+ }), Se = n.object({
253
+ orderFormId: n.string().nullable(),
254
+ orderItems: n.array().of(ve)
234
255
  });
235
- async function M({
236
- apiUrl: t,
237
- body: e,
256
+ async function Ee({
257
+ apiUrl: e,
258
+ body: t,
238
259
  fetchOptions: o
239
260
  }) {
240
- if (!e) {
261
+ if (!t) {
241
262
  console.error("[ERROR FETCHING] Body is required");
242
263
  return;
243
264
  }
244
- await H.validate(e);
245
- const { orderFormId: n, orderItems: s } = e;
246
- return l(
247
- `${t}/api/checkout/pub/orderForm/${n}/items/update`,
265
+ await Se.validate(t);
266
+ const { orderFormId: r, orderItems: s } = t;
267
+ return u(
268
+ `${e}/api/checkout/pub/orderForm/${r}/items/update`,
248
269
  {
249
270
  method: "POST",
250
271
  body: { orderItems: s },
@@ -252,90 +273,90 @@ async function M({
252
273
  }
253
274
  );
254
275
  }
255
- const U = r.object({
256
- orderFormId: r.string().nullable()
276
+ const qe = n.object({
277
+ orderFormId: n.string().nullable()
257
278
  });
258
- async function x({
259
- apiUrl: t,
260
- body: e,
279
+ async function Te({
280
+ apiUrl: e,
281
+ body: t,
261
282
  fetchOptions: o
262
283
  }) {
263
- if (!e) {
284
+ if (!t) {
264
285
  console.error("[ERROR FETCHING] Body is required");
265
286
  return;
266
287
  }
267
- await U.validate(e);
268
- const { orderFormId: n } = e;
269
- return l(
270
- `${t}/api/checkout/pub/orderForm/${n}/messages/clear`,
288
+ await qe.validate(t);
289
+ const { orderFormId: r } = t;
290
+ return u(
291
+ `${e}/api/checkout/pub/orderForm/${r}/messages/clear`,
271
292
  {
272
293
  method: "POST",
273
294
  ...o
274
295
  }
275
296
  );
276
297
  }
277
- const z = r.object({
278
- id: r.string().nullable(),
298
+ const Ae = n.object({
299
+ id: n.string().nullable(),
279
300
  // id offering
280
- itemIndex: r.number().nullable(),
281
- orderFormId: r.string().nullable(),
282
- remove: r.boolean().nullable()
301
+ itemIndex: n.number().nullable(),
302
+ orderFormId: n.string().nullable(),
303
+ remove: n.boolean().nullable()
283
304
  });
284
- async function L({ apiUrl: t, body: e, fetchOptions: o }) {
285
- if (!e) {
305
+ async function Pe({ apiUrl: e, body: t, fetchOptions: o }) {
306
+ if (!t) {
286
307
  console.error("[ERROR FETCHING] Body is required");
287
308
  return;
288
309
  }
289
- await z.validate(e);
290
- const { itemIndex: n, orderFormId: s, id: a, remove: i } = e, d = i ? `/${a}/remove` : "", m = `${t}/api/checkout/pub/orderForm/${s}/items/${n}/offerings${d}`;
291
- return l(m, {
310
+ await Ae.validate(t);
311
+ const { itemIndex: r, orderFormId: s, id: a, remove: i } = t, c = i ? `/${a}/remove` : "", l = `${e}/api/checkout/pub/orderForm/${s}/items/${r}/offerings${c}`;
312
+ return u(l, {
292
313
  method: "POST",
293
314
  body: { id: a },
294
315
  ...o
295
316
  });
296
317
  }
297
- const V = r.object({
298
- orderFormId: r.string().nullable()
318
+ const Ne = n.object({
319
+ orderFormId: n.string().nullable()
299
320
  });
300
- async function J({
301
- apiUrl: t,
302
- body: e,
321
+ async function je({
322
+ apiUrl: e,
323
+ body: t,
303
324
  fetchOptions: o,
304
- extraData: n
325
+ extraData: r
305
326
  }) {
306
327
  var i;
307
- if (!e) {
328
+ if (!t) {
308
329
  console.error("[ERROR FETCHING] Body is required");
309
330
  return;
310
331
  }
311
- await V.validate(e);
332
+ await Ne.validate(t);
312
333
  const s = new URLSearchParams({
313
334
  refreshOutdatedData: "true"
314
- }), a = e.orderFormId && ((i = n.orderFormPurchaseId) == null ? void 0 : i.value) !== e.orderFormId ? `${t}/api/checkout/pub/orderForm/${e.orderFormId}?${String(s)}` : `${t}/api/checkout/pub/orderForm`;
315
- return l(a, { method: "GET", ...o });
316
- }
317
- const K = r.object({
318
- orderFormId: r.string().nullable(),
319
- email: r.string().email().required(),
320
- firstName: r.string().required(),
321
- lastName: r.string().required(),
322
- documentType: r.string().required(),
323
- document: r.string().required(),
324
- phone: r.string().matches(/^\+\d{1,3}\d{10,11}$/)
335
+ }), a = t.orderFormId && ((i = r.orderFormPurchaseId) == null ? void 0 : i.value) !== t.orderFormId ? `${e}/api/checkout/pub/orderForm/${t.orderFormId}?${String(s)}` : `${e}/api/checkout/pub/orderForm`;
336
+ return u(a, { method: "GET", ...o });
337
+ }
338
+ const ke = n.object({
339
+ orderFormId: n.string().nullable(),
340
+ email: n.string().email().required(),
341
+ firstName: n.string().required(),
342
+ lastName: n.string().required(),
343
+ documentType: n.string().required(),
344
+ document: n.string().required(),
345
+ phone: n.string().matches(/^\+\d{1,3}\d{10,11}$/)
325
346
  });
326
- async function Y({
327
- apiUrl: t,
328
- body: e,
347
+ async function we({
348
+ apiUrl: e,
349
+ body: t,
329
350
  fetchOptions: o
330
351
  }) {
331
- if (!e) {
352
+ if (!t) {
332
353
  console.error("[ERROR FETCHING] Body is required");
333
354
  return;
334
355
  }
335
- await K.validate(e);
336
- const { orderFormId: n, ...s } = e;
337
- return l(
338
- `${t}/api/checkout/pub/orderForm/${n}/attachments/clientProfileData`,
356
+ await ke.validate(t);
357
+ const { orderFormId: r, ...s } = t;
358
+ return u(
359
+ `${e}/api/checkout/pub/orderForm/${r}/attachments/clientProfileData`,
339
360
  {
340
361
  method: "POST",
341
362
  body: { ...s },
@@ -343,22 +364,22 @@ async function Y({
343
364
  }
344
365
  );
345
366
  }
346
- const Q = r.object({
347
- sellerCode: r.string().nullable()
367
+ const De = n.object({
368
+ sellerCode: n.string().nullable()
348
369
  });
349
- async function X({
350
- apiUrl: t,
351
- body: e,
370
+ async function _e({
371
+ apiUrl: e,
372
+ body: t,
352
373
  fetchOptions: o
353
374
  }) {
354
- if (!e) {
375
+ if (!t) {
355
376
  console.error("[ERROR FETCHING] Body is required");
356
377
  return;
357
378
  }
358
- await Q.validate(e);
359
- const { sellerCode: n = "" } = e;
360
- return l(
361
- `${t}/api/dataentities/VD/search?_fields=id,cod,name,ativo&cod=${n}`,
379
+ await De.validate(t);
380
+ const { sellerCode: r = "" } = t;
381
+ return u(
382
+ `${e}/api/dataentities/VD/search?_fields=id,cod,name,ativo&cod=${r}`,
362
383
  {
363
384
  method: "GET",
364
385
  headers: {
@@ -368,33 +389,33 @@ async function X({
368
389
  }
369
390
  );
370
391
  }
371
- const W = r.object().shape({
372
- country: r.string().length(3, "Country code must be 3 characters long").required("Country is required"),
373
- orderFormId: r.string().nullable(),
374
- postalCode: r.string().nullable()
392
+ const He = n.object().shape({
393
+ country: n.string().length(3, "Country code must be 3 characters long").required("Country is required"),
394
+ orderFormId: n.string().nullable(),
395
+ postalCode: n.string().nullable()
375
396
  });
376
- async function Z({
377
- apiUrl: t,
378
- body: e,
397
+ async function Ge({
398
+ apiUrl: e,
399
+ body: t,
379
400
  fetchOptions: o
380
401
  }) {
381
- if (!e) {
402
+ if (!t) {
382
403
  console.error("[ERROR FETCHING] Body is required");
383
404
  return;
384
405
  }
385
- await W.validate(e);
386
- const { country: n, orderFormId: s, postalCode: a } = e, i = a ? {
406
+ await He.validate(t);
407
+ const { country: r, orderFormId: s, postalCode: a } = t, i = a ? {
387
408
  address: {
388
409
  addressType: "residential",
389
410
  postalCode: a,
390
- country: n
411
+ country: r
391
412
  }
392
413
  } : {
393
414
  logisticsInfo: [],
394
415
  clearAddressIfPostalCodeNotFound: !0
395
416
  };
396
- return l(
397
- `${t}/api/checkout/pub/orderForm/${s}/attachments/shippingData`,
417
+ return u(
418
+ `${e}/api/checkout/pub/orderForm/${s}/attachments/shippingData`,
398
419
  {
399
420
  method: "POST",
400
421
  body: i,
@@ -402,43 +423,43 @@ async function Z({
402
423
  }
403
424
  );
404
425
  }
405
- const ee = r.object().shape({
406
- orderFormId: r.string().nullable(),
407
- options: r.array().of(
408
- r.object().shape({
409
- itemIndex: r.number(),
410
- selectedDeliveryChannel: r.string(),
411
- selectedSla: r.string()
426
+ const Be = n.object().shape({
427
+ orderFormId: n.string().nullable(),
428
+ options: n.array().of(
429
+ n.object().shape({
430
+ itemIndex: n.number(),
431
+ selectedDeliveryChannel: n.string(),
432
+ selectedSla: n.string()
412
433
  })
413
434
  ),
414
- selectedAddresses: r.array().of(
415
- r.object().shape({
416
- addressId: r.string().required(),
417
- addressType: r.string().required(),
418
- city: r.string().nullable(),
419
- complement: r.string().nullable(),
420
- country: r.string().required().length(3),
421
- geoCoordinates: r.array().of(r.number()).required().min(0),
422
- isDisposable: r.boolean().required(),
423
- neighborhood: r.string().nullable(),
424
- number: r.string().nullable(),
425
- postalCode: r.string().required(),
426
- receiverName: r.string().nullable(),
427
- reference: r.string().nullable(),
428
- state: r.string().nullable(),
429
- street: r.string().nullable()
435
+ selectedAddresses: n.array().of(
436
+ n.object().shape({
437
+ addressId: n.string().required(),
438
+ addressType: n.string().required(),
439
+ city: n.string().nullable(),
440
+ complement: n.string().nullable(),
441
+ country: n.string().required().length(3),
442
+ geoCoordinates: n.array().of(n.number()).required().min(0),
443
+ isDisposable: n.boolean().required(),
444
+ neighborhood: n.string().nullable(),
445
+ number: n.string().nullable(),
446
+ postalCode: n.string().required(),
447
+ receiverName: n.string().nullable(),
448
+ reference: n.string().nullable(),
449
+ state: n.string().nullable(),
450
+ street: n.string().nullable()
430
451
  })
431
452
  )
432
453
  });
433
- async function re({ apiUrl: t, body: e, fetchOptions: o }) {
434
- if (!e) {
454
+ async function Ue({ apiUrl: e, body: t, fetchOptions: o }) {
455
+ if (!t) {
435
456
  console.error("[ERROR FETCHING] Body is required");
436
457
  return;
437
458
  }
438
- await ee.validate(e);
439
- const { orderFormId: n, options: s, selectedAddresses: a } = e;
440
- return l(
441
- `${t}/api/checkout/pub/orderForm/${n}/attachments/shippingData`,
459
+ await Be.validate(t);
460
+ const { orderFormId: r, options: s, selectedAddresses: a } = t;
461
+ return u(
462
+ `${e}/api/checkout/pub/orderForm/${r}/attachments/shippingData`,
442
463
  {
443
464
  method: "POST",
444
465
  body: {
@@ -450,215 +471,215 @@ async function re({ apiUrl: t, body: e, fetchOptions: o }) {
450
471
  }
451
472
  );
452
473
  }
453
- const te = r.object({
454
- country: r.string().length(3, "Country code must be 3 characters long").required("Country is required"),
455
- postalCode: r.string().nullable(),
456
- geoCoordinates: r.object().shape({
457
- longitude: r.number().required(),
458
- latitude: r.number().required()
474
+ const Ve = n.object({
475
+ country: n.string().length(3, "Country code must be 3 characters long").required("Country is required"),
476
+ postalCode: n.string().nullable(),
477
+ geoCoordinates: n.object().shape({
478
+ longitude: n.number().required(),
479
+ latitude: n.number().required()
459
480
  })
460
481
  });
461
- async function oe({ apiUrl: t, body: e, fetchOptions: o }) {
462
- if (!e) {
482
+ async function Le({ apiUrl: e, body: t, fetchOptions: o }) {
483
+ if (!t) {
463
484
  console.error("[ERROR FETCHING] Body is required");
464
485
  return;
465
486
  }
466
- await te.validate(e);
467
- const { country: n = "", geoCoordinates: s, postalCode: a = "" } = e, i = new URLSearchParams({ country: String(n) });
487
+ await Ve.validate(t);
488
+ const { country: r = "", geoCoordinates: s, postalCode: a = "" } = t, i = new URLSearchParams({ country: String(r) });
468
489
  return a ? i.append("postalCode", a) : i.append(
469
490
  "geoCoordinates",
470
491
  `${s == null ? void 0 : s.longitude};${s == null ? void 0 : s.latitude}`
471
- ), await l(
472
- `${t}/api/checkout/pub/regions/?${i.toString()}`,
492
+ ), await u(
493
+ `${e}/api/checkout/pub/regions/?${i.toString()}`,
473
494
  {
474
495
  method: "GET",
475
496
  ...o
476
497
  }
477
498
  );
478
499
  }
479
- const ne = r.object({
480
- id: r.string().required("ID of SKU is required"),
481
- quantity: r.number().integer().required("Quantity of item is required"),
482
- seller: r.string()
483
- }), ae = r.object({
484
- items: r.array().of(ne),
485
- country: r.string().length(3, "Country code must be 3 characters long").required("Country is required"),
486
- postalCode: r.string().nullable(),
487
- geoCoordinates: r.array().nullable().of(r.number()).length(2)
500
+ const Me = n.object({
501
+ id: n.string().required("ID of SKU is required"),
502
+ quantity: n.number().integer().required("Quantity of item is required"),
503
+ seller: n.string()
504
+ }), xe = n.object({
505
+ items: n.array().of(Me),
506
+ country: n.string().length(3, "Country code must be 3 characters long").required("Country is required"),
507
+ postalCode: n.string().nullable(),
508
+ geoCoordinates: n.array().nullable().of(n.number()).length(2)
488
509
  });
489
- async function se({ apiUrl: t, body: e, fetchOptions: o }) {
490
- if (!e) {
510
+ async function ze({ apiUrl: e, body: t, fetchOptions: o }) {
511
+ if (!t) {
491
512
  console.error("[ERROR FETCHING] Body is required");
492
513
  return;
493
514
  }
494
- return await ae.validate(e), l(
495
- `${t}/api/checkout/pub/orderForms/simulation`,
515
+ return await xe.validate(t), u(
516
+ `${e}/api/checkout/pub/orderForms/simulation`,
496
517
  {
497
518
  method: "POST",
498
- body: e,
519
+ body: t,
499
520
  ...o
500
521
  }
501
522
  );
502
523
  }
503
- const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
524
+ const Qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
504
525
  __proto__: null,
505
- getMasterDataSellerCode: X,
506
- getOrderForm: J,
507
- postOrderFormAddCoupon: E,
508
- postOrderFormAttachClientProfileData: Y,
509
- postOrderFormAttachOrderFormData: S,
510
- postOrderFormAttachShippingData: Z,
511
- postOrderFormAttachmentsMarketingData: F,
512
- postOrderFormAttachmentsOpenTextField: b,
513
- postOrderFormClearMessages: x,
514
- postOrderFormFreightSimulation: se,
515
- postOrderFormItems: D,
516
- postOrderFormRegion: oe,
517
- postOrderFormRemoveAllItems: P,
518
- postOrderFormUpdateItems: M,
519
- postOrderFormUpdateShippingData: re,
520
- postOrderformAddress: O,
521
- putOrderFormCustomData: w,
522
- updateOrderFormOffering: L
523
- }, Symbol.toStringTag, { value: "Module" })), le = r.object({
524
- skuId: r.string()
526
+ getMasterDataSellerCode: _e,
527
+ getOrderForm: je,
528
+ postOrderFormAddCoupon: fe,
529
+ postOrderFormAttachClientProfileData: we,
530
+ postOrderFormAttachOrderFormData: pe,
531
+ postOrderFormAttachShippingData: Ge,
532
+ postOrderFormAttachmentsMarketingData: U,
533
+ postOrderFormAttachmentsOpenTextField: B,
534
+ postOrderFormClearMessages: Te,
535
+ postOrderFormFreightSimulation: ze,
536
+ postOrderFormItems: ye,
537
+ postOrderFormRegion: Le,
538
+ postOrderFormRemoveAllItems: Oe,
539
+ postOrderFormUpdateItems: Ee,
540
+ postOrderFormUpdateShippingData: Ue,
541
+ postOrderformAddress: le,
542
+ putOrderFormCustomData: Ie,
543
+ updateOrderFormOffering: Pe
544
+ }, Symbol.toStringTag, { value: "Module" })), Je = n.object({
545
+ skuId: n.string()
525
546
  });
526
- async function de({ apiUrl: t, body: e, fetchOptions: o }) {
527
- if (!e) {
547
+ async function Ke({ apiUrl: e, body: t, fetchOptions: o }) {
548
+ if (!t) {
528
549
  console.error("[ERROR FETCHING] Body is required");
529
550
  return;
530
551
  }
531
- await le.validate(e);
532
- const { skuId: n } = e;
533
- return l(
534
- `${t}/api/catalog/pvt/stockkeepingunitkit?parentSkuId=${n}`,
552
+ await Je.validate(t);
553
+ const { skuId: r } = t;
554
+ return u(
555
+ `${e}/api/catalog/pvt/stockkeepingunitkit?parentSkuId=${r}`,
535
556
  {
536
557
  ...o
537
558
  }
538
559
  );
539
560
  }
540
- const ce = r.object({
541
- ids: r.array().of(r.string().required("ID are required")).required("IDs are required")
561
+ const Ye = n.object({
562
+ ids: n.array().of(n.string().required("ID are required")).required("IDs are required")
542
563
  });
543
- async function ue({ apiUrl: t, body: e, fetchOptions: o }) {
544
- if (!e) {
564
+ async function We({ apiUrl: e, body: t, fetchOptions: o }) {
565
+ if (!t) {
545
566
  console.error("[ERROR FETCHING] Body is required");
546
567
  return;
547
568
  }
548
- await ce.validate(e);
549
- const { ids: n } = e;
550
- return l(
551
- `${t}/api/catalog_system/pub/products/search?fq=${n.map((s) => `productId:${s}`).join("&fq=")}`,
569
+ await Ye.validate(t);
570
+ const { ids: r } = t;
571
+ return u(
572
+ `${e}/api/catalog_system/pub/products/search?fq=${r.map((s) => `productId:${s}`).join("&fq=")}`,
552
573
  {
553
574
  ...o
554
575
  }
555
576
  );
556
577
  }
557
- const me = r.object({
558
- productId: r.number().required("Product ID is required")
578
+ const Xe = n.object({
579
+ productId: n.number().required("Product ID is required")
559
580
  });
560
- async function pe({ apiUrl: t, body: e, fetchOptions: o }) {
561
- if (!e) {
581
+ async function Ze({ apiUrl: e, body: t, fetchOptions: o }) {
582
+ if (!t) {
562
583
  console.error("[ERROR FETCHING] Body is required");
563
584
  return;
564
585
  }
565
- await me.validate(e);
566
- const { productId: n } = e;
567
- return l(
568
- `${t}/api/catalog_system/pub/products/crossselling/similars/${n.toString()}`,
586
+ await Xe.validate(t);
587
+ const { productId: r } = t;
588
+ return u(
589
+ `${e}/api/catalog_system/pub/products/crossselling/similars/${r.toString()}`,
569
590
  {
570
591
  ...o
571
592
  }
572
593
  );
573
594
  }
574
- const ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
595
+ const et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
575
596
  __proto__: null,
576
- getCatalogKitProducts: de,
577
- getCatalogProducts: ue,
578
- getCatalogSimilars: pe
579
- }, Symbol.toStringTag, { value: "Module" })), he = (t = "") => t.charAt(0).toUpperCase() + t.slice(1), h = (t, e = " ") => !t || typeof t == "string" && t.length === 0 ? t : (Array.isArray(t) ? t : t.split("-")).map(he).join(e), fe = ({ canonical: t, seo: e, slug: o }) => {
580
- const n = Array.isArray(o) ? o.join(", ") : o;
597
+ getCatalogKitProducts: Ke,
598
+ getCatalogProducts: We,
599
+ getCatalogSimilars: Ze
600
+ }, Symbol.toStringTag, { value: "Module" })), tt = (e = "") => e.charAt(0).toUpperCase() + e.slice(1), w = (e, t = " ") => !e || typeof e == "string" && e.length === 0 ? e : (Array.isArray(e) ? e : e.split("-")).map(tt).join(t), rt = ({ canonical: e, seo: t, slug: o }) => {
601
+ const r = Array.isArray(o) ? o.join(", ") : o;
581
602
  return {
582
603
  id: 0,
583
- Title: `${Array.isArray(o) ? o.map((a) => h(a)).join(",") : h(o)} - ${e.title}`,
584
- MetaTagDescription: e.description,
585
- name: n,
604
+ Title: `${Array.isArray(o) ? o.map((a) => w(a)).join(",") : w(o)} - ${t.title}`,
605
+ MetaTagDescription: t.description,
606
+ name: r,
586
607
  hasChildren: !1,
587
- url: t,
608
+ url: e,
588
609
  children: []
589
610
  };
590
- }, Ie = ({ canonical: t, category: e, previousImages: o, seo: n }) => ({
591
- category: String(e == null ? void 0 : e.id),
592
- title: (e == null ? void 0 : e.Title) ?? n.title,
593
- description: (e == null ? void 0 : e.MetaTagDescription) ?? n.description,
594
- alternates: { canonical: t },
611
+ }, ot = ({ canonical: e, category: t, previousImages: o, seo: r }) => ({
612
+ category: String(t == null ? void 0 : t.id),
613
+ title: (t == null ? void 0 : t.Title) ?? r.title,
614
+ description: (t == null ? void 0 : t.MetaTagDescription) ?? r.description,
615
+ alternates: { canonical: e },
595
616
  openGraph: {
596
617
  type: "website",
597
- title: (e == null ? void 0 : e.Title) ?? n.title,
598
- description: (e == null ? void 0 : e.MetaTagDescription) ?? n.description,
618
+ title: (t == null ? void 0 : t.Title) ?? r.title,
619
+ description: (t == null ? void 0 : t.MetaTagDescription) ?? r.description,
599
620
  images: Array.isArray(o) ? [...o] : []
600
621
  }
601
- }), be = ({ items: t, parent: e, apiUrl: o, find: n }) => {
602
- const s = t.find(
603
- (i) => i.url.replace(o, "") === decodeURIComponent(e.toLowerCase())
622
+ }), nt = ({ items: e, parent: t, apiUrl: o, find: r }) => {
623
+ const s = e.find(
624
+ (i) => i.url.replace(o, "") === decodeURIComponent(t.toLowerCase())
604
625
  );
605
626
  return (s == null ? void 0 : s.children.find(
606
- (i) => i.name.toLowerCase() === decodeURIComponent(String(n))
627
+ (i) => i.name.toLowerCase() === decodeURIComponent(String(r))
607
628
  )) ?? s;
608
- }, Fe = (t) => {
609
- t instanceof Error ? (console.error(`[ERROR CATEGORY INFO]: ${t.message}`), console.error(t.stack)) : console.error("[ERROR CATEGORY INFO]: Unknown error", t);
610
- }, Ce = /* @__PURE__ */ new Set([
629
+ }, at = (e) => {
630
+ e instanceof Error ? (console.error(`[ERROR CATEGORY INFO]: ${e.message}`), console.error(e.stack)) : console.error("[ERROR CATEGORY INFO]: Unknown error", e);
631
+ }, st = /* @__PURE__ */ new Set([
611
632
  "brand",
612
633
  "category",
613
634
  "department",
614
635
  "subcategory",
615
636
  "collection",
616
637
  "cluster"
617
- ]), $e = (t) => typeof (t == null ? void 0 : t.pageType) == "string" && Ce.has(t == null ? void 0 : t.pageType.toLowerCase()), Re = (t) => ({
618
- collection: t.Coleção,
619
- categoryId: t.categoryId,
620
- current_collection: t["Coleção Atual"],
621
- items: t.items
622
- }), Oe = (t, e) => t.reduce((o, n) => {
623
- if (n.items.filter(
624
- (i) => i.sellers.find((d) => d.commertialOffer.IsAvailable)
625
- ).length === 0 || (o == null ? void 0 : o.find((i) => (i == null ? void 0 : i.productId) === (n == null ? void 0 : n.productId))) !== void 0)
638
+ ]), it = (e) => typeof (e == null ? void 0 : e.pageType) == "string" && st.has(e == null ? void 0 : e.pageType.toLowerCase()), ct = (e) => ({
639
+ collection: e.Coleção,
640
+ categoryId: e.categoryId,
641
+ current_collection: e["Coleção Atual"],
642
+ items: e.items
643
+ }), lt = (e, t) => e.reduce((o, r) => {
644
+ if (r.items.filter(
645
+ (i) => i.sellers.find((c) => c.commertialOffer.IsAvailable)
646
+ ).length === 0 || (o == null ? void 0 : o.find((i) => (i == null ? void 0 : i.productId) === (r == null ? void 0 : r.productId))) !== void 0)
626
647
  return o;
627
- const a = n.items[0].images.find(
628
- (i) => e.includes(i.imageLabel)
648
+ const a = r.items[0].images.find(
649
+ (i) => t.includes(i.imageLabel)
629
650
  );
630
651
  return o.push({
631
- slug: `/${n.linkText}/p`,
632
- productId: n == null ? void 0 : n.productId,
652
+ slug: `/${r.linkText}/p`,
653
+ productId: r == null ? void 0 : r.productId,
633
654
  textureImage: (a == null ? void 0 : a.imageUrl) ?? "",
634
655
  textureAlt: (a == null ? void 0 : a.imageText) ?? ""
635
656
  }), o;
636
- }, []), ye = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
657
+ }, []), ut = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
637
658
  __proto__: null,
638
- createEmptySeoCategory: fe,
639
- createSeoCategory: Ie,
640
- findCategory: be,
641
- formattedSimilars: Oe,
642
- isCollectionPageType: $e,
643
- notFindCategoryError: Fe,
644
- responseAdapter: Re
659
+ createEmptySeoCategory: rt,
660
+ createSeoCategory: ot,
661
+ findCategory: nt,
662
+ formattedSimilars: lt,
663
+ isCollectionPageType: it,
664
+ notFindCategoryError: at,
665
+ responseAdapter: ct
645
666
  }, Symbol.toStringTag, { value: "Module" }));
646
- async function qe({ contentType: t, storeId: e, CMS_PROJECT_NAME: o, NextCookies: n }) {
647
- const s = await C({
648
- contentType: t,
649
- storeId: e,
667
+ async function dt({ contentType: e, storeId: t, CMS_PROJECT_NAME: o, NextCookies: r }) {
668
+ const s = await V({
669
+ contentType: e,
670
+ storeId: t,
650
671
  CMS_PROJECT_NAME: o,
651
- NextCookies: n
672
+ NextCookies: r
652
673
  });
653
674
  if (s.status === 200) {
654
675
  const a = {
655
676
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
656
- contentType: t,
677
+ contentType: e,
657
678
  data: s.data
658
679
  };
659
680
  console.log("Resultado da chamada:", s);
660
- const i = `backup-${t}-${Date.now()}.json`;
661
- return await $.writeFile(
681
+ const i = `backup-${e}-${Date.now()}.json`;
682
+ return await Z.writeFile(
662
683
  `./backups/${i}`,
663
684
  JSON.stringify(a, null, 2),
664
685
  "utf-8"
@@ -666,96 +687,566 @@ async function qe({ contentType: t, storeId: e, CMS_PROJECT_NAME: o, NextCookies
666
687
  }
667
688
  return { success: !1, error: s.error || "No data to backup" };
668
689
  }
669
- async function Te(t) {
670
- return qe(t);
690
+ async function mt(e) {
691
+ return dt(e);
671
692
  }
672
- async function Se({
673
- contentType: t,
674
- documentId: e,
693
+ async function pt({
694
+ contentType: e,
695
+ documentId: t,
675
696
  versionId: o,
676
- storeId: n,
697
+ storeId: r,
677
698
  CMS_PROJECT_NAME: s
678
699
  }) {
679
- const a = e && e.length ? `/${e}` : "", i = o && o.length ? `?versionId=${o}` : "";
700
+ const a = t && t.length ? `/${t}` : "", i = o && o.length ? `?versionId=${o}` : "";
680
701
  return fetch(
681
- `https://${n}.myvtex.com/_v/cms/api/${s}/${t}${a}${i}`,
702
+ `https://${r}.myvtex.com/_v/cms/api/${s}/${e}${a}${i}`,
682
703
  { cache: "no-cache" }
683
704
  );
684
705
  }
685
- async function ve({
686
- contentType: t,
687
- documents: e,
706
+ async function gt({
707
+ contentType: e,
708
+ documents: t,
688
709
  NextCookies: o,
689
- CMS_PROJECT_NAME: n,
710
+ CMS_PROJECT_NAME: r,
690
711
  storeId: s
691
712
  }) {
692
713
  var i;
693
714
  const a = JSON.parse(
694
715
  ((i = o().get("cms_preview_data")) == null ? void 0 : i.value) ?? "{}"
695
716
  );
696
- if (a && (a == null ? void 0 : a.contentType) === t) {
697
- const d = a.documentId && a.documentId.length ? `/${a.documentId}` : "", m = a != null && a.versionId && (a != null && a.versionId.length) ? `?versionId=${a == null ? void 0 : a.versionId}` : "", p = await (await fetch(
698
- `https://${s}.myvtex.com/_v/cms/api/${n}/${t}${d}${m}`,
717
+ if (a && (a == null ? void 0 : a.contentType) === e) {
718
+ const c = a.documentId && a.documentId.length ? `/${a.documentId}` : "", l = a != null && a.versionId && (a != null && a.versionId.length) ? `?versionId=${a == null ? void 0 : a.versionId}` : "", p = await (await fetch(
719
+ `https://${s}.myvtex.com/_v/cms/api/${r}/${e}${c}${l}`,
699
720
  { cache: "no-store" }
700
- )).json(), c = e.filter(
701
- (u) => p.id !== u.documentId
721
+ )).json(), d = t.filter(
722
+ (m) => p.id !== m.documentId
702
723
  );
703
- return c.unshift(p), c;
724
+ return d.unshift(p), d;
704
725
  }
705
- return e;
726
+ return t;
706
727
  }
707
- async function C({
708
- contentType: t,
709
- NextCookies: e,
728
+ async function V({
729
+ contentType: e,
730
+ NextCookies: t,
710
731
  CMS_PROJECT_NAME: o,
711
- storeId: n
732
+ storeId: r
712
733
  }) {
713
734
  var g, p;
714
735
  const s = JSON.parse(
715
- ((g = e().get("cms_preview_data")) == null ? void 0 : g.value) ?? "{}"
736
+ ((g = t().get("cms_preview_data")) == null ? void 0 : g.value) ?? "{}"
716
737
  ), a = [];
717
- let i = 1, d = 0, m = !0;
738
+ let i = 1, c = 0, l = !0;
718
739
  try {
719
740
  do {
720
- const u = await (await fetch(
721
- `https://${n}.myvtex.com/_v/cms/api/${o}/${t}?page=${i}`
741
+ const m = await (await fetch(
742
+ `https://${r}.myvtex.com/_v/cms/api/${o}/${e}?page=${i}`
722
743
  )).json();
723
- i === 1 && (d = u.totalItems), (p = u == null ? void 0 : u.data) != null && p.length && a.push(...u.data), m = u.hasNextPage, i++;
724
- } while (m && a.length < d);
744
+ i === 1 && (c = m.totalItems), (p = m == null ? void 0 : m.data) != null && p.length && a.push(...m.data), l = m.hasNextPage, i++;
745
+ } while (l && a.length < c);
725
746
  if (s.previewMode && a.length) {
726
- const c = await ve({
727
- contentType: t,
747
+ const d = await gt({
748
+ contentType: e,
728
749
  documents: a,
729
- NextCookies: e,
750
+ NextCookies: t,
730
751
  CMS_PROJECT_NAME: o,
731
- storeId: n
752
+ storeId: r
732
753
  });
733
754
  return {
734
- status: c.length > 0 ? 200 : 404,
735
- data: c ?? []
755
+ status: d.length > 0 ? 200 : 404,
756
+ data: d ?? []
736
757
  };
737
758
  }
738
759
  return {
739
760
  status: a.length ? 200 : 404,
740
761
  data: a
741
762
  };
742
- } catch (c) {
743
- return { status: "error", data: [], error: c };
763
+ } catch (d) {
764
+ return { status: "error", data: [], error: d };
765
+ }
766
+ }
767
+ const ft = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
768
+ __proto__: null,
769
+ cmsBackup: mt,
770
+ getCMSContentType: pt,
771
+ getContentType: V
772
+ }, Symbol.toStringTag, { value: "Module" })), ht = n.object({
773
+ query: n.string()
774
+ });
775
+ async function It({ apiUrl: e, body: t, fetchOptions: o }) {
776
+ if (!t) {
777
+ console.error("[ERROR FETCHING] Body is required");
778
+ return;
744
779
  }
780
+ await ht.validate(t);
781
+ const { query: r = "" } = t, s = new URLSearchParams({ query: r });
782
+ return u(
783
+ `${e}/api/io/_v/api/intelligent-search/autocomplete_suggestions?${s.toString()}`,
784
+ {
785
+ ...o
786
+ }
787
+ );
788
+ }
789
+ const bt = (e, t) => se(e, t), Ct = (e) => ({
790
+ ...e,
791
+ description: e.description ? bt(e.description) : e.description
792
+ }), Rt = ({
793
+ offer: e,
794
+ seller: t,
795
+ product: o
796
+ }) => ({
797
+ ...e,
798
+ product: o,
799
+ seller: t
800
+ }), L = (e, t) => ({
801
+ ...e,
802
+ isVariantOf: Ct(t)
803
+ }), yt = (e) => e ? "https://schema.org/InStock" : "https://schema.org/OutOfStock", S = (e) => e.AvailableQuantity > 0, D = (e) => e.spotPrice ?? 0, Ft = (e) => e.Price ?? 0, M = (e, t) => S(e) && !S(t) ? -1 : !S(e) && S(t) ? 1 : D(e) - D(t), Ot = (e, t) => {
804
+ let o = 0;
805
+ for (let r = 1; r < e.length; r++)
806
+ t(e[o], e[r]) > 0 && (o = r);
807
+ return e[o];
808
+ }, x = (e) => {
809
+ const t = e.flatMap(
810
+ (r) => r.sellers.map((s) => ({
811
+ offer: s.commertialOffer,
812
+ sku: r
813
+ }))
814
+ ), o = Ot(
815
+ t,
816
+ ({ offer: r }, { offer: s }) => M(r, s)
817
+ );
818
+ return o ? o.sku : e[0];
819
+ }, z = (e) => e.map(
820
+ ({ imageUrl: t, imageText: o, imageLabel: r }) => ({
821
+ alternateName: o ?? "",
822
+ url: t.replace("vteximg.com.br", "vtexassets.com"),
823
+ keywords: r
824
+ })
825
+ ), E = {
826
+ attachment: "ATTACHMENT",
827
+ specification: "SPECIFICATION",
828
+ attribute: "ATTRIBUTE"
829
+ }, $t = (e) => ({
830
+ name: e.name,
831
+ value: e.content,
832
+ valueReference: E.attachment
833
+ }), vt = (e) => ({
834
+ propertyID: e.id,
835
+ name: e.name,
836
+ value: e.value,
837
+ valueReference: {
838
+ valueReference: E.attribute,
839
+ visible: e.visible
840
+ }
841
+ }), q = (e, t, o) => {
842
+ const r = e.flatMap(({ name: i, values: c }) => c ? c.map((l) => ({
843
+ name: i,
844
+ value: l,
845
+ valueReference: E.specification
846
+ })) : {
847
+ name: i,
848
+ value: "",
849
+ valueReference: E.specification
850
+ }), s = Array.isArray(o) ? o.map($t) : [], a = t ? t.map(vt) : [];
851
+ return [
852
+ ...r,
853
+ ...s,
854
+ ...a
855
+ ];
856
+ }, _ = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđ߯a", St = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa", Et = (e) => {
857
+ let t = e.slice(0);
858
+ for (let o = 0; o < _.length; o++)
859
+ t = t.replace(
860
+ new RegExp(_.charAt(o), "g"),
861
+ St.charAt(o)
862
+ );
863
+ return t;
864
+ }, qt = (e) => e.replace(/[·/_,:]/, "-"), Q = (e) => {
865
+ const o = e.replace(/,/g, "").replace(/[*+~.()'"!:@&\[\]`/ %$#?{}|><=_^]/g, "-");
866
+ return qt(Et(o)).toLowerCase();
867
+ }, J = (e) => `/${e}/p`, K = (e) => {
868
+ const t = Math.max(
869
+ ...e.map((r) => r.NumberOfInstallments)
870
+ ), o = e.find(
871
+ (r) => r.NumberOfInstallments === t
872
+ );
873
+ return {
874
+ count: (o == null ? void 0 : o.NumberOfInstallments) ?? 0,
875
+ value: (o == null ? void 0 : o.Value) ?? 0
876
+ };
877
+ }, Y = (e, t) => {
878
+ const o = {
879
+ price: 0,
880
+ listPrice: 0,
881
+ sellerDefault: !1
882
+ }, s = e.map(
883
+ (a) => Rt({
884
+ offer: a.commertialOffer,
885
+ seller: a,
886
+ product: t
887
+ })
888
+ ).sort(M).map((a) => (a.seller.sellerId === "1" && a.AvailableQuantity > 0 && (o.price = a.Price, o.listPrice = a.ListPrice, o.sellerDefault = !0), {
889
+ availability: a.AvailableQuantity > 0,
890
+ listPrice: a.ListPrice,
891
+ price: Ft(a),
892
+ priceValidUntil: a.PriceValidUntil,
893
+ priceCurrency: "BRL",
894
+ installments: a.Installments,
895
+ lowPrice: a.spotPrice,
896
+ quantity: a.AvailableQuantity,
897
+ seller: {
898
+ identifier: a.seller.sellerId
899
+ }
900
+ }));
901
+ return {
902
+ lowPrice: o.sellerDefault ? o.price : s[0].price,
903
+ highPrice: o.sellerDefault ? o.listPrice : s[0].listPrice,
904
+ offers: s
905
+ };
906
+ }, W = (e) => {
907
+ const { attributes: t, itemId: o, name: r, sellers: s, variations: a } = e;
908
+ return {
909
+ additionalProperty: q(a, t, []),
910
+ name: r,
911
+ offers: {
912
+ offers: s.map(({ sellerId: i, commertialOffer: c }) => ({
913
+ availability: yt(c.AvailableQuantity > 0),
914
+ listPrice: c.ListPrice,
915
+ price: c.Price,
916
+ quantity: c.AvailableQuantity,
917
+ seller: {
918
+ identifier: i
919
+ }
920
+ }))
921
+ },
922
+ sku: o
923
+ // slug: getSlug('', itemId), // getSlug('', itemId) que tipo de slug é esse?
924
+ };
925
+ }, Tt = (e) => {
926
+ var y;
927
+ const {
928
+ attributes: t,
929
+ referenceId: o,
930
+ isVariantOf: r,
931
+ images: s,
932
+ itemId: a,
933
+ name: i,
934
+ sellers: c,
935
+ videos: l,
936
+ variations: g
937
+ } = e, {
938
+ brand: p,
939
+ categories: d,
940
+ categoriesIds: m,
941
+ description: b,
942
+ linkText: f,
943
+ productClusters: T,
944
+ clusterHighlights: $,
945
+ productName: v,
946
+ properties: A,
947
+ productId: P
948
+ } = r, N = d.slice().reverse(), C = Y(c, e.isVariantOf), j = K(C.offers[0].installments);
949
+ return {
950
+ sku: a,
951
+ gtin: ((y = o[0]) == null ? void 0 : y.Value) ?? "",
952
+ name: v ?? i,
953
+ description: b,
954
+ releaseDate: r.releaseDate ?? "",
955
+ slug: f,
956
+ video: l[0],
957
+ categories: d,
958
+ categoriesIds: m,
959
+ id: P,
960
+ brand: { name: p, brandName: p },
961
+ seo: {
962
+ description: b,
963
+ title: v,
964
+ canonical: J(f)
965
+ },
966
+ cluster: {
967
+ generals: T,
968
+ highlights: $
969
+ },
970
+ properties: A,
971
+ availability: { status: C.offers[0].availability },
972
+ breadcrumbList: {
973
+ itemListElement: [
974
+ ...N.map((h, F) => {
975
+ const I = h.split("/"), R = I[I.length - 2], k = I.map(Q).join("/");
976
+ return {
977
+ name: R,
978
+ item: k,
979
+ position: F + 1
980
+ };
981
+ }),
982
+ {
983
+ name: r.productName,
984
+ item: f,
985
+ position: d.length + 1
986
+ }
987
+ ],
988
+ numberOfItems: d.length
989
+ },
990
+ image: z(s),
991
+ offers: C,
992
+ additionalProperty: q(g, t, []),
993
+ isVariantOf: {
994
+ productGroupID: r.productId,
995
+ hasVariant: r.items.map((h) => W(h))
996
+ },
997
+ installments: j
998
+ };
999
+ }, At = (e) => {
1000
+ var y;
1001
+ const {
1002
+ attributes: t,
1003
+ referenceId: o,
1004
+ isVariantOf: r,
1005
+ images: s,
1006
+ itemId: a,
1007
+ name: i,
1008
+ sellers: c,
1009
+ Videos: l,
1010
+ variations: g
1011
+ } = e, {
1012
+ brand: p,
1013
+ categories: d,
1014
+ categoriesIds: m,
1015
+ description: b,
1016
+ linkText: f,
1017
+ productClusters: T,
1018
+ productName: $,
1019
+ Coleção: v,
1020
+ "ID Coleção": A,
1021
+ productId: P
1022
+ } = r, N = d.slice().reverse(), C = Y(c, e.isVariantOf), j = K(C.offers[0].installments);
1023
+ return {
1024
+ sku: a,
1025
+ gtin: ((y = o[0]) == null ? void 0 : y.Value) ?? "",
1026
+ name: $ ?? i,
1027
+ description: b,
1028
+ releaseDate: r.releaseDate ?? "",
1029
+ slug: f,
1030
+ video: l[0],
1031
+ categories: d,
1032
+ categoriesIds: m,
1033
+ collection: v,
1034
+ collectionId: A,
1035
+ id: P,
1036
+ brand: { name: p, brandName: p },
1037
+ seo: {
1038
+ description: b,
1039
+ title: $,
1040
+ canonical: J(f)
1041
+ },
1042
+ cluster: {
1043
+ generals: T,
1044
+ highlights: []
1045
+ // TODO: add highlights
1046
+ },
1047
+ availability: { status: C.offers[0].availability },
1048
+ breadcrumbList: {
1049
+ itemListElement: [
1050
+ ...N.map((h, F) => {
1051
+ const I = h.split("/"), R = I[I.length - 2], k = I.map(Q).join("/");
1052
+ return {
1053
+ name: R,
1054
+ item: k,
1055
+ position: F + 1
1056
+ };
1057
+ }),
1058
+ {
1059
+ name: r.productName,
1060
+ item: f,
1061
+ position: d.length + 1
1062
+ }
1063
+ ],
1064
+ numberOfItems: d.length
1065
+ },
1066
+ image: z(s),
1067
+ offers: C,
1068
+ additionalProperty: q(g, t, []),
1069
+ isVariantOf: {
1070
+ productGroupID: r.productId,
1071
+ hasVariant: r.items.map((h) => {
1072
+ const { variations: F } = h, I = F.map((R) => ({
1073
+ name: R,
1074
+ values: h[R]
1075
+ }));
1076
+ return {
1077
+ ...W(h),
1078
+ additionalProperty: q(
1079
+ I,
1080
+ t,
1081
+ []
1082
+ )
1083
+ };
1084
+ })
1085
+ },
1086
+ installments: j
1087
+ };
1088
+ }, Pt = n.array().of(n.object({
1089
+ key: n.string().required(),
1090
+ value: n.string().required()
1091
+ })).required("Facets are required");
1092
+ async function Nt({ apiUrl: e, body: t, fetchOptions: o }) {
1093
+ if (!t) {
1094
+ console.error("[ERROR FETCHING] Body is required");
1095
+ return;
1096
+ }
1097
+ await Pt.validate(t);
1098
+ const r = new URLSearchParams({}), s = t.map(({ key: i, value: c }) => `${i}/${c}`).join("/");
1099
+ ee(t, r);
1100
+ const a = `${e}/api/catalog_system/pub/products/crossselling/${s}`;
1101
+ return u(a, {
1102
+ cache: "no-store",
1103
+ ...o
1104
+ }).then((i) => i.map((l) => {
1105
+ const g = x(l.items);
1106
+ return g && L(g, l);
1107
+ }).filter((l) => !!l).map((l) => ({
1108
+ node: At(l)
1109
+ })));
1110
+ }
1111
+ const X = ({
1112
+ apiUrl: e,
1113
+ body: t,
1114
+ fetchOptions: o,
1115
+ extraData: r
1116
+ }) => {
1117
+ if (!t) {
1118
+ console.error("[ERROR FETCHING] Body is required");
1119
+ return;
1120
+ }
1121
+ const {
1122
+ query: s = "",
1123
+ page: a = 1,
1124
+ count: i,
1125
+ sort: c = "",
1126
+ facets: l = [],
1127
+ type: g,
1128
+ hideUnavailableItems: p = !0,
1129
+ locale: d = ""
1130
+ } = t, m = new URLSearchParams({
1131
+ page: a.toString(),
1132
+ count: (i == null ? void 0 : i.toString()) ?? (r == null ? void 0 : r.ITEMS_PER_PAGE) ?? 24,
1133
+ query: s,
1134
+ sort: c,
1135
+ locale: d
1136
+ });
1137
+ p !== void 0 && m.append("hideUnavailableItems", p.toString());
1138
+ const b = l.map((f) => `${f.key}/${f.value}`).join("/") ?? "";
1139
+ return ie(
1140
+ `${e}/api/io/_v/api/intelligent-search/${g}/${b}?${m.toString()}`,
1141
+ {
1142
+ headers: {
1143
+ Accept: "application/json",
1144
+ "content-type": "application/json"
1145
+ },
1146
+ ...o
1147
+ }
1148
+ );
1149
+ };
1150
+ async function jt({ body: e, extraData: t, ...o }) {
1151
+ if (!e) {
1152
+ console.error("[ERROR FETCHING] Body is required");
1153
+ return;
1154
+ }
1155
+ const r = await X({
1156
+ body: {
1157
+ ...e,
1158
+ type: "product_search"
1159
+ },
1160
+ extraData: t,
1161
+ ...o
1162
+ }), s = (r == null ? void 0 : r.products.map((c) => {
1163
+ const l = x(c.items);
1164
+ return l && L(l, c);
1165
+ }).filter((c) => !!c)) ?? [], {
1166
+ pagination: a,
1167
+ recordsFiltered: i
1168
+ } = r;
1169
+ return {
1170
+ data: {
1171
+ pagination: {
1172
+ nextPage: a.after.length > 0,
1173
+ previousPage: a.before.length > 0,
1174
+ startCursor: "0",
1175
+ endCursor: i.toString(),
1176
+ count: i,
1177
+ total: a.count
1178
+ },
1179
+ products: s.map((c, l) => ({
1180
+ node: Tt(c),
1181
+ cursor: l.toString()
1182
+ }))
1183
+ }
1184
+ };
1185
+ }
1186
+ async function kt({ body: e, extraData: t, ...o }) {
1187
+ if (!e) {
1188
+ console.error("[ERROR FETCHING] Body is required");
1189
+ return;
1190
+ }
1191
+ const r = await X({
1192
+ body: {
1193
+ ...e,
1194
+ type: "facets"
1195
+ },
1196
+ extraData: t,
1197
+ ...o
1198
+ });
1199
+ return !r || !r.facets ? (console.error("[ERROR FETCHING] No facets found"), { data: { facets: [] } }) : {
1200
+ data: {
1201
+ ...r,
1202
+ facets: te(r, e == null ? void 0 : e.selectedFacets, (e == null ? void 0 : e.query) ?? "")
1203
+ }
1204
+ };
1205
+ }
1206
+ const wt = n.object({
1207
+ query: n.string().optional(),
1208
+ locale: n.string().optional()
1209
+ });
1210
+ async function Dt({ apiUrl: e, body: t, fetchOptions: o }) {
1211
+ if (!t) {
1212
+ console.error("[ERROR FETCHING] Body is required");
1213
+ return;
1214
+ }
1215
+ await wt.validate(t);
1216
+ const { query: r = "", locale: s = "default_locale" } = t, a = new URLSearchParams({ query: r, locale: s });
1217
+ return u(
1218
+ `${e}/api/io/_v/api/intelligent-search/search_suggestions?${a.toString()}`,
1219
+ {
1220
+ ...o
1221
+ }
1222
+ );
1223
+ }
1224
+ async function _t({ apiUrl: e }) {
1225
+ return u(`${e}/api/io/_v/api/intelligent-search/top_searches`);
745
1226
  }
746
- const Ee = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1227
+ const Ht = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
747
1228
  __proto__: null,
748
- cmsBackup: Te,
749
- getCMSContentType: Se,
750
- getContentType: C
751
- }, Symbol.toStringTag, { value: "Module" })), we = {
752
- checkout: ie,
753
- catalog: ge,
754
- cms: Ee
755
- }, ke = {
756
- catalog: ye
1229
+ getSearchAutoCompleteSuggestions: It,
1230
+ getSearchCrossellingProducts: Nt,
1231
+ getSearchFacets: kt,
1232
+ getSearchProducts: jt,
1233
+ getSearchSuggestedTerms: Dt,
1234
+ getSearchTopSearchs: _t
1235
+ }, Symbol.toStringTag, { value: "Module" })), Gt = {
1236
+ parseSearchState: ae,
1237
+ convertSearchParams: ne,
1238
+ filterNonRootFacets: oe,
1239
+ filterNonCategorySelected: re
1240
+ }, Vt = {
1241
+ checkout: Qe,
1242
+ catalog: et,
1243
+ cms: ft,
1244
+ search: Ht
1245
+ }, Lt = {
1246
+ catalog: ut,
1247
+ search: Gt
757
1248
  };
758
1249
  export {
759
- we as serverAPIs,
760
- ke as serverHelpers
1250
+ Vt as serverAPIs,
1251
+ Lt as serverHelpers
761
1252
  };