@soma-vertical-web/multi-lib 0.0.31 → 0.0.33

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