@decocms/apps 0.23.3 → 0.25.0

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/commerce/components/Image.tsx +129 -143
  3. package/commerce/components/JsonLd.tsx +192 -201
  4. package/commerce/components/Picture.tsx +65 -75
  5. package/commerce/sdk/analytics.ts +15 -15
  6. package/commerce/sdk/formatPrice.ts +13 -16
  7. package/commerce/sdk/url.ts +7 -7
  8. package/commerce/sdk/useOffer.ts +46 -57
  9. package/commerce/sdk/useVariantPossibilities.ts +25 -25
  10. package/commerce/types/commerce.ts +868 -875
  11. package/commerce/utils/canonical.ts +5 -8
  12. package/commerce/utils/constants.ts +5 -6
  13. package/commerce/utils/filters.ts +4 -4
  14. package/commerce/utils/productToAnalyticsItem.ts +52 -56
  15. package/commerce/utils/stateByZip.ts +42 -42
  16. package/package.json +24 -4
  17. package/shopify/actions/cart/addItems.ts +24 -25
  18. package/shopify/actions/cart/updateCoupons.ts +19 -20
  19. package/shopify/actions/cart/updateItems.ts +19 -20
  20. package/shopify/actions/user/signIn.ts +25 -30
  21. package/shopify/actions/user/signUp.ts +19 -24
  22. package/shopify/client.ts +24 -24
  23. package/shopify/index.ts +20 -18
  24. package/shopify/init.ts +18 -21
  25. package/shopify/loaders/ProductDetailsPage.ts +16 -20
  26. package/shopify/loaders/ProductList.ts +66 -69
  27. package/shopify/loaders/ProductListingPage.ts +150 -158
  28. package/shopify/loaders/RelatedProducts.ts +24 -27
  29. package/shopify/loaders/cart.ts +53 -52
  30. package/shopify/loaders/shop.ts +22 -27
  31. package/shopify/loaders/user.ts +27 -32
  32. package/shopify/utils/admin/admin.ts +33 -34
  33. package/shopify/utils/admin/queries.ts +2 -2
  34. package/shopify/utils/cart.ts +18 -14
  35. package/shopify/utils/cookies.ts +62 -65
  36. package/shopify/utils/enums.ts +424 -424
  37. package/shopify/utils/graphql.ts +44 -55
  38. package/shopify/utils/storefront/queries.ts +24 -29
  39. package/shopify/utils/storefront/storefront.graphql.gen.ts +55 -55
  40. package/shopify/utils/transform.ts +370 -376
  41. package/shopify/utils/types.ts +118 -118
  42. package/shopify/utils/user.ts +11 -11
  43. package/shopify/utils/utils.ts +135 -140
  44. package/vtex/actions/address.ts +86 -86
  45. package/vtex/actions/auth.ts +14 -27
  46. package/vtex/actions/checkout.ts +36 -49
  47. package/vtex/actions/masterData.ts +10 -27
  48. package/vtex/actions/misc.ts +101 -111
  49. package/vtex/actions/newsletter.ts +48 -52
  50. package/vtex/actions/orders.ts +13 -16
  51. package/vtex/actions/profile.ts +55 -55
  52. package/vtex/actions/session.ts +36 -35
  53. package/vtex/actions/trigger.ts +25 -25
  54. package/vtex/actions/wishlist.ts +51 -53
  55. package/vtex/client.ts +14 -42
  56. package/vtex/hooks/index.ts +4 -4
  57. package/vtex/hooks/useAutocomplete.ts +42 -48
  58. package/vtex/hooks/useCart.ts +153 -165
  59. package/vtex/hooks/useUser.ts +40 -40
  60. package/vtex/hooks/useWishlist.ts +70 -70
  61. package/vtex/inline-loaders/productDetailsPage.ts +1 -3
  62. package/vtex/inline-loaders/productList.ts +121 -127
  63. package/vtex/inline-loaders/productListShelf.ts +159 -0
  64. package/vtex/inline-loaders/productListingPage.ts +10 -34
  65. package/vtex/inline-loaders/relatedProducts.ts +1 -3
  66. package/vtex/inline-loaders/suggestions.ts +36 -39
  67. package/vtex/inline-loaders/workflowProducts.ts +45 -49
  68. package/vtex/invoke.ts +159 -194
  69. package/vtex/loaders/address.ts +49 -54
  70. package/vtex/loaders/brands.ts +19 -26
  71. package/vtex/loaders/cart.ts +24 -21
  72. package/vtex/loaders/catalog.ts +51 -53
  73. package/vtex/loaders/collections.ts +25 -27
  74. package/vtex/loaders/legacy.ts +487 -534
  75. package/vtex/loaders/logistics.ts +33 -37
  76. package/vtex/loaders/navbar.ts +5 -8
  77. package/vtex/loaders/orders.ts +28 -39
  78. package/vtex/loaders/pageType.ts +41 -35
  79. package/vtex/loaders/payment.ts +27 -37
  80. package/vtex/loaders/profile.ts +38 -38
  81. package/vtex/loaders/promotion.ts +5 -8
  82. package/vtex/loaders/search.ts +56 -59
  83. package/vtex/loaders/session.ts +22 -30
  84. package/vtex/loaders/user.ts +39 -41
  85. package/vtex/loaders/wishlist.ts +35 -35
  86. package/vtex/loaders/wishlistProducts.ts +3 -15
  87. package/vtex/loaders/workflow.ts +220 -227
  88. package/vtex/middleware.ts +116 -119
  89. package/vtex/types.ts +201 -201
  90. package/vtex/utils/batch.ts +13 -16
  91. package/vtex/utils/cookies.ts +76 -80
  92. package/vtex/utils/enrichment.ts +62 -42
  93. package/vtex/utils/fetchCache.ts +1 -4
  94. package/vtex/utils/index.ts +6 -6
  95. package/vtex/utils/intelligentSearch.ts +48 -57
  96. package/vtex/utils/legacy.ts +108 -124
  97. package/vtex/utils/pickAndOmit.ts +15 -20
  98. package/vtex/utils/proxy.ts +136 -146
  99. package/vtex/utils/resourceRange.ts +3 -3
  100. package/vtex/utils/segment.ts +100 -111
  101. package/vtex/utils/similars.ts +1 -2
  102. package/vtex/utils/sitemap.ts +91 -91
  103. package/vtex/utils/slugCache.ts +2 -6
  104. package/vtex/utils/slugify.ts +9 -9
  105. package/vtex/utils/transform.ts +1178 -1105
  106. package/vtex/utils/types.ts +1381 -1381
  107. package/vtex/utils/vtexId.ts +44 -47
  108. package/.github/workflows/release.yml +0 -34
  109. package/.releaserc.json +0 -28
  110. package/knip.json +0 -19
  111. package/tsconfig.json +0 -11
@@ -6,7 +6,7 @@
6
6
  * - vtex/actions/address/update.ts
7
7
  * @see https://developers.vtex.com/docs/guides/profile-system
8
8
  */
9
- import { vtexFetch, getVtexConfig } from "../client";
9
+ import { getVtexConfig, vtexFetch } from "../client";
10
10
  import { buildAuthCookieHeader } from "../utils/vtexId";
11
11
 
12
12
  // ---------------------------------------------------------------------------
@@ -14,50 +14,50 @@ import { buildAuthCookieHeader } from "../utils/vtexId";
14
14
  // ---------------------------------------------------------------------------
15
15
 
16
16
  export interface AddressInput {
17
- addressName: string;
18
- addressType?: string;
19
- city?: string;
20
- complement?: string;
21
- country?: string;
22
- geoCoordinates?: number[];
23
- neighborhood?: string;
24
- number?: string;
25
- postalCode?: string;
26
- receiverName?: string;
27
- reference?: string;
28
- state?: string;
29
- street?: string;
17
+ addressName: string;
18
+ addressType?: string;
19
+ city?: string;
20
+ complement?: string;
21
+ country?: string;
22
+ geoCoordinates?: number[];
23
+ neighborhood?: string;
24
+ number?: string;
25
+ postalCode?: string;
26
+ receiverName?: string;
27
+ reference?: string;
28
+ state?: string;
29
+ street?: string;
30
30
  }
31
31
 
32
32
  export interface SavedAddress {
33
- id: string;
34
- cacheId: string;
35
- addressId: string;
36
- userId?: string;
37
- addressName: string;
38
- addressType: string | null;
39
- city: string | null;
40
- complement: string | null;
41
- country: string | null;
42
- geoCoordinates: number[] | null;
43
- neighborhood: string | null;
44
- number: string | null;
45
- postalCode: string | null;
46
- receiverName: string | null;
47
- reference: string | null;
48
- state: string | null;
49
- street: string | null;
50
- name?: string;
33
+ id: string;
34
+ cacheId: string;
35
+ addressId: string;
36
+ userId?: string;
37
+ addressName: string;
38
+ addressType: string | null;
39
+ city: string | null;
40
+ complement: string | null;
41
+ country: string | null;
42
+ geoCoordinates: number[] | null;
43
+ neighborhood: string | null;
44
+ number: string | null;
45
+ postalCode: string | null;
46
+ receiverName: string | null;
47
+ reference: string | null;
48
+ state: string | null;
49
+ street: string | null;
50
+ name?: string;
51
51
  }
52
52
 
53
53
  export interface DeleteAddressResult {
54
- cacheId: string;
55
- addresses: SavedAddress[];
54
+ cacheId: string;
55
+ addresses: SavedAddress[];
56
56
  }
57
57
 
58
58
  export interface UpdateAddressResult {
59
- cacheId: string;
60
- addresses: SavedAddress;
59
+ cacheId: string;
60
+ addresses: SavedAddress;
61
61
  }
62
62
 
63
63
  // ---------------------------------------------------------------------------
@@ -65,28 +65,28 @@ export interface UpdateAddressResult {
65
65
  // ---------------------------------------------------------------------------
66
66
 
67
67
  interface GqlResponse<T> {
68
- data: T;
69
- errors?: Array<{ message: string }>;
68
+ data: T;
69
+ errors?: Array<{ message: string }>;
70
70
  }
71
71
 
72
72
  async function gql<T>(
73
- query: string,
74
- variables: Record<string, unknown>,
75
- authCookie: string,
73
+ query: string,
74
+ variables: Record<string, unknown>,
75
+ authCookie: string,
76
76
  ): Promise<T> {
77
- const { account } = getVtexConfig();
78
- const result = await vtexFetch<GqlResponse<T>>(
79
- `https://${account}.myvtex.com/_v/private/graphql/v1`,
80
- {
81
- method: "POST",
82
- body: JSON.stringify({ query, variables }),
83
- headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
84
- },
85
- );
86
- if (result.errors?.length) {
87
- throw new Error(`GraphQL error: ${result.errors[0].message}`);
88
- }
89
- return result.data;
77
+ const { account } = getVtexConfig();
78
+ const result = await vtexFetch<GqlResponse<T>>(
79
+ `https://${account}.myvtex.com/_v/private/graphql/v1`,
80
+ {
81
+ method: "POST",
82
+ body: JSON.stringify({ query, variables }),
83
+ headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
84
+ },
85
+ );
86
+ if (result.errors?.length) {
87
+ throw new Error(`GraphQL error: ${result.errors[0].message}`);
88
+ }
89
+ return result.data;
90
90
  }
91
91
 
92
92
  // ---------------------------------------------------------------------------
@@ -165,47 +165,47 @@ const UPDATE_ADDRESS = `mutation UpdateAddress($addressId: String!, $addressFiel
165
165
 
166
166
  /** Create a new user address. Requires the user's VtexIdclientAutCookie token. */
167
167
  export async function createAddress(
168
- input: AddressInput,
169
- authCookie: string,
168
+ input: AddressInput,
169
+ authCookie: string,
170
170
  ): Promise<SavedAddress> {
171
- const { saveAddress } = await gql<{ saveAddress: SavedAddress }>(
172
- SAVE_ADDRESS,
173
- { address: input },
174
- authCookie,
175
- );
176
- return saveAddress;
171
+ const { saveAddress } = await gql<{ saveAddress: SavedAddress }>(
172
+ SAVE_ADDRESS,
173
+ { address: input },
174
+ authCookie,
175
+ );
176
+ return saveAddress;
177
177
  }
178
178
 
179
179
  /** Delete an address by its ID. Returns remaining addresses. */
180
180
  export async function deleteAddress(
181
- addressId: string,
182
- authCookie: string,
181
+ addressId: string,
182
+ authCookie: string,
183
183
  ): Promise<DeleteAddressResult> {
184
- const { deleteAddress: result } = await gql<{ deleteAddress: DeleteAddressResult }>(
185
- DELETE_ADDRESS,
186
- { addressId },
187
- authCookie,
188
- );
189
- return result;
184
+ const { deleteAddress: result } = await gql<{ deleteAddress: DeleteAddressResult }>(
185
+ DELETE_ADDRESS,
186
+ { addressId },
187
+ authCookie,
188
+ );
189
+ return result;
190
190
  }
191
191
 
192
192
  /** Update an existing address. Returns the updated address. */
193
193
  export async function updateAddress(
194
- addressId: string,
195
- fields: Partial<AddressInput>,
196
- authCookie: string,
194
+ addressId: string,
195
+ fields: Partial<AddressInput>,
196
+ authCookie: string,
197
197
  ): Promise<UpdateAddressResult> {
198
- const { updateAddress: result } = await gql<{ updateAddress: UpdateAddressResult }>(
199
- UPDATE_ADDRESS,
200
- {
201
- addressId,
202
- addressFields: {
203
- ...fields,
204
- receiverName: fields.receiverName ?? null,
205
- complement: fields.complement ?? null,
206
- },
207
- },
208
- authCookie,
209
- );
210
- return result;
198
+ const { updateAddress: result } = await gql<{ updateAddress: UpdateAddressResult }>(
199
+ UPDATE_ADDRESS,
200
+ {
201
+ addressId,
202
+ addressFields: {
203
+ ...fields,
204
+ receiverName: fields.receiverName ?? null,
205
+ complement: fields.complement ?? null,
206
+ },
207
+ },
208
+ authCookie,
209
+ );
210
+ return result;
211
211
  }
@@ -6,10 +6,7 @@
6
6
  */
7
7
 
8
8
  import type { VtexFetchResult } from "../client";
9
- import {
10
- getVtexConfig,
11
- vtexFetchWithCookies,
12
- } from "../client";
9
+ import { getVtexConfig, vtexFetchWithCookies } from "../client";
13
10
  import { VTEX_AUTH_COOKIE } from "../utils/vtexId";
14
11
 
15
12
  // ---------------------------------------------------------------------------
@@ -77,9 +74,7 @@ const FORM_HEADERS = {
77
74
  * Extract login cookies from an AuthResponse.
78
75
  * Returns null if auth failed.
79
76
  */
80
- export function extractLoginCookies(
81
- response: AuthResponse,
82
- ): LoginCookies | null {
77
+ export function extractLoginCookies(response: AuthResponse): LoginCookies | null {
83
78
  if (response.authStatus !== "Success" || !response.authCookie) {
84
79
  return null;
85
80
  }
@@ -138,10 +133,7 @@ export async function classicSignIn(
138
133
  const startResult = await startAuthentication();
139
134
  token = startResult.data.authenticationToken ?? undefined;
140
135
  startCookies = startResult.setCookies;
141
- if (!token)
142
- throw new Error(
143
- "Failed to obtain authentication token from startAuthentication",
144
- );
136
+ if (!token) throw new Error("Failed to obtain authentication token from startAuthentication");
145
137
  }
146
138
 
147
139
  const body = new URLSearchParams({
@@ -172,10 +164,11 @@ export async function accessKeySignIn(
172
164
  authenticationToken,
173
165
  });
174
166
 
175
- return vtexFetchWithCookies<AuthResponse>(
176
- "/api/vtexid/pub/authentication/accesskey/validate",
177
- { method: "POST", body, headers: FORM_HEADERS },
178
- );
167
+ return vtexFetchWithCookies<AuthResponse>("/api/vtexid/pub/authentication/accesskey/validate", {
168
+ method: "POST",
169
+ body,
170
+ headers: FORM_HEADERS,
171
+ });
179
172
  }
180
173
 
181
174
  /**
@@ -201,14 +194,11 @@ export async function refreshToken(
201
194
  cookieHeader: string,
202
195
  fingerprint?: string,
203
196
  ): Promise<VtexFetchResult<RefreshTokenResponse>> {
204
- return vtexFetchWithCookies<RefreshTokenResponse>(
205
- "/api/vtexid/refreshtoken/webstore",
206
- {
207
- method: "POST",
208
- body: JSON.stringify({ fingerprint }),
209
- headers: { cookie: cookieHeader },
210
- },
211
- );
197
+ return vtexFetchWithCookies<RefreshTokenResponse>("/api/vtexid/refreshtoken/webstore", {
198
+ method: "POST",
199
+ body: JSON.stringify({ fingerprint }),
200
+ headers: { cookie: cookieHeader },
201
+ });
212
202
  }
213
203
 
214
204
  /**
@@ -260,10 +250,7 @@ export async function resetPassword(
260
250
  const startResult = await startAuthentication({ locale });
261
251
  token = startResult.data.authenticationToken ?? undefined;
262
252
  startCookies = startResult.setCookies;
263
- if (!token)
264
- throw new Error(
265
- "Failed to obtain authentication token from startAuthentication",
266
- );
253
+ if (!token) throw new Error("Failed to obtain authentication token from startAuthentication");
267
254
  }
268
255
 
269
256
  const params = new URLSearchParams({
@@ -60,7 +60,7 @@ export async function getOrCreateCart(
60
60
  ): Promise<VtexFetchResult<OrderForm>> {
61
61
  const sc = scParam();
62
62
  const headers: Record<string, string> = {};
63
- if (cookieHeader) headers["cookie"] = cookieHeader;
63
+ if (cookieHeader) headers.cookie = cookieHeader;
64
64
 
65
65
  if (orderFormId) {
66
66
  const result = await vtexFetchWithCookies<OrderForm>(
@@ -99,7 +99,7 @@ export async function addItemsToCart(
99
99
  const params = appendSc(new URLSearchParams());
100
100
  for (const d of allowedOutdatedData) params.append("allowedOutdatedData", d);
101
101
  const headers: Record<string, string> = {};
102
- if (cookieHeader) headers["cookie"] = cookieHeader;
102
+ if (cookieHeader) headers.cookie = cookieHeader;
103
103
  const result = await vtexFetchWithCookies<OrderForm>(
104
104
  `/api/checkout/pub/orderForm/${orderFormId}/items?${params}`,
105
105
  { method: "POST", body: JSON.stringify({ orderItems }), headers },
@@ -122,7 +122,7 @@ export async function updateCartItems(
122
122
  params.append("allowedOutdatedData", d);
123
123
  }
124
124
  const headers: Record<string, string> = {};
125
- if (opts?.cookieHeader) headers["cookie"] = opts.cookieHeader;
125
+ if (opts?.cookieHeader) headers.cookie = opts.cookieHeader;
126
126
  const result = await vtexFetchWithCookies<OrderForm>(
127
127
  `/api/checkout/pub/orderForm/${orderFormId}/items/update?${params}`,
128
128
  {
@@ -144,7 +144,7 @@ export async function removeAllItems(
144
144
  ): Promise<VtexFetchResult<OrderForm>> {
145
145
  const sc = scParam();
146
146
  const headers: Record<string, string> = {};
147
- if (cookieHeader) headers["cookie"] = cookieHeader;
147
+ if (cookieHeader) headers.cookie = cookieHeader;
148
148
  const result = await vtexFetchWithCookies<OrderForm>(
149
149
  `/api/checkout/pub/orderForm/${orderFormId}/items/removeAll${sc ? `?${sc}` : ""}`,
150
150
  { method: "POST", body: JSON.stringify({}), headers },
@@ -160,7 +160,7 @@ export async function addCouponToCart(
160
160
  ): Promise<VtexFetchResult<OrderForm>> {
161
161
  const sc = scParam();
162
162
  const headers: Record<string, string> = {};
163
- if (cookieHeader) headers["cookie"] = cookieHeader;
163
+ if (cookieHeader) headers.cookie = cookieHeader;
164
164
  const result = await vtexFetchWithCookies<OrderForm>(
165
165
  `/api/checkout/pub/orderForm/${orderFormId}/coupons${sc ? `?${sc}` : ""}`,
166
166
  { method: "POST", body: JSON.stringify({ text }), headers },
@@ -187,11 +187,9 @@ export async function simulateCart(
187
187
  cookieHeader?: string,
188
188
  ) {
189
189
  const config = getVtexConfig();
190
- const params = appendSc(
191
- new URLSearchParams({ RnbBehavior: String(RnbBehavior) }),
192
- );
190
+ const params = appendSc(new URLSearchParams({ RnbBehavior: String(RnbBehavior) }));
193
191
  const headers: Record<string, string> = {};
194
- if (cookieHeader) headers["cookie"] = cookieHeader;
192
+ if (cookieHeader) headers.cookie = cookieHeader;
195
193
  return vtexFetch<any>(`/api/checkout/pub/orderForms/simulation?${params}`, {
196
194
  method: "POST",
197
195
  body: JSON.stringify({
@@ -215,7 +213,7 @@ export async function addOffering(
215
213
  cookieHeader?: string,
216
214
  ): Promise<VtexFetchResult<OrderForm>> {
217
215
  const headers: Record<string, string> = {};
218
- if (cookieHeader) headers["cookie"] = cookieHeader;
216
+ if (cookieHeader) headers.cookie = cookieHeader;
219
217
  const result = await vtexFetchWithCookies<OrderForm>(
220
218
  `/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/offerings`,
221
219
  {
@@ -240,7 +238,7 @@ export async function removeOffering(
240
238
  cookieHeader?: string,
241
239
  ): Promise<VtexFetchResult<OrderForm>> {
242
240
  const headers: Record<string, string> = {};
243
- if (cookieHeader) headers["cookie"] = cookieHeader;
241
+ if (cookieHeader) headers.cookie = cookieHeader;
244
242
  const result = await vtexFetchWithCookies<OrderForm>(
245
243
  `/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/offerings/${offeringId}/remove`,
246
244
  {
@@ -266,7 +264,7 @@ export async function updateOrderFormAttachment(
266
264
  ): Promise<VtexFetchResult<OrderForm>> {
267
265
  if (!orderFormId) throw new Error("Order form ID is required");
268
266
  const headers: Record<string, string> = {};
269
- if (cookieHeader) headers["cookie"] = cookieHeader;
267
+ if (cookieHeader) headers.cookie = cookieHeader;
270
268
  const result = await vtexFetchWithCookies<OrderForm>(
271
269
  `/api/checkout/pub/orderForm/${orderFormId}/attachments/${attachment}`,
272
270
  {
@@ -292,7 +290,7 @@ export async function updateItemAttachment(
292
290
  ): Promise<VtexFetchResult<OrderForm>> {
293
291
  const sections = opts?.expectedOrderFormSections ?? DEFAULT_EXPECTED_SECTIONS;
294
292
  const headers: Record<string, string> = {};
295
- if (opts?.cookieHeader) headers["cookie"] = opts.cookieHeader;
293
+ if (opts?.cookieHeader) headers.cookie = opts.cookieHeader;
296
294
  const result = await vtexFetchWithCookies<OrderForm>(
297
295
  `/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/attachments/${attachment}`,
298
296
  {
@@ -322,7 +320,7 @@ export async function removeItemAttachment(
322
320
  ): Promise<VtexFetchResult<OrderForm>> {
323
321
  const sections = opts?.expectedOrderFormSections ?? DEFAULT_EXPECTED_SECTIONS;
324
322
  const headers: Record<string, string> = {};
325
- if (opts?.cookieHeader) headers["cookie"] = opts.cookieHeader;
323
+ if (opts?.cookieHeader) headers.cookie = opts.cookieHeader;
326
324
  const result = await vtexFetchWithCookies<OrderForm>(
327
325
  `/api/checkout/pub/orderForm/${orderFormId}/items/${itemIndex}/attachments/${attachment}`,
328
326
  {
@@ -366,7 +364,7 @@ export async function updateSelectableGifts(
366
364
  cookieHeader?: string,
367
365
  ): Promise<VtexFetchResult<OrderForm>> {
368
366
  const headers: Record<string, string> = {};
369
- if (cookieHeader) headers["cookie"] = cookieHeader;
367
+ if (cookieHeader) headers.cookie = cookieHeader;
370
368
  const result = await vtexFetchWithCookies<OrderForm>(
371
369
  `/api/checkout/pub/orderForm/${orderFormId}/selectable-gifts/${giftId}`,
372
370
  {
@@ -395,11 +393,10 @@ export async function getInstallments(
395
393
  const params = new URLSearchParams({ paymentSystem: String(paymentSystem) });
396
394
  appendSc(params);
397
395
  const headers: Record<string, string> = {};
398
- if (cookieHeader) headers["cookie"] = cookieHeader;
399
- return vtexFetch<any>(
400
- `/api/checkout/pub/orderForm/${orderFormId}/installments?${params}`,
401
- { headers },
402
- );
396
+ if (cookieHeader) headers.cookie = cookieHeader;
397
+ return vtexFetch<any>(`/api/checkout/pub/orderForm/${orderFormId}/installments?${params}`, {
398
+ headers,
399
+ });
403
400
  }
404
401
 
405
402
  // ---------------------------------------------------------------------------
@@ -411,11 +408,9 @@ export async function updateOrderFormProfile(
411
408
  fields: Record<string, unknown>,
412
409
  opts?: { ignoreProfileData?: boolean; cookieHeader?: string },
413
410
  ): Promise<VtexFetchResult<OrderForm>> {
414
- const body = opts?.ignoreProfileData
415
- ? { ...fields, ignoreProfileData: true }
416
- : fields;
411
+ const body = opts?.ignoreProfileData ? { ...fields, ignoreProfileData: true } : fields;
417
412
  const headers: Record<string, string> = {};
418
- if (opts?.cookieHeader) headers["cookie"] = opts.cookieHeader;
413
+ if (opts?.cookieHeader) headers.cookie = opts.cookieHeader;
419
414
  const result = await vtexFetchWithCookies<OrderForm>(
420
415
  `/api/checkout/pub/orderForm/${orderFormId}/profile`,
421
416
  { method: "PATCH", body: JSON.stringify(body), headers },
@@ -424,12 +419,8 @@ export async function updateOrderFormProfile(
424
419
  return result;
425
420
  }
426
421
 
427
- export async function changeToAnonymousUser(
428
- orderFormId: string,
429
- ): Promise<OrderForm> {
430
- return vtexFetch<OrderForm>(
431
- `/api/checkout/changeToAnonymousUser/${orderFormId}`,
432
- );
422
+ export async function changeToAnonymousUser(orderFormId: string): Promise<OrderForm> {
423
+ return vtexFetch<OrderForm>(`/api/checkout/changeToAnonymousUser/${orderFormId}`);
433
424
  }
434
425
 
435
426
  export async function clearOrderFormMessages(
@@ -437,11 +428,12 @@ export async function clearOrderFormMessages(
437
428
  cookieHeader?: string,
438
429
  ): Promise<OrderForm> {
439
430
  const headers: Record<string, string> = {};
440
- if (cookieHeader) headers["cookie"] = cookieHeader;
441
- return vtexFetch<OrderForm>(
442
- `/api/checkout/pub/orderForm/${orderFormId}/messages/clear`,
443
- { method: "POST", body: JSON.stringify({}), headers },
444
- );
431
+ if (cookieHeader) headers.cookie = cookieHeader;
432
+ return vtexFetch<OrderForm>(`/api/checkout/pub/orderForm/${orderFormId}/messages/clear`, {
433
+ method: "POST",
434
+ body: JSON.stringify({}),
435
+ headers,
436
+ });
445
437
  }
446
438
 
447
439
  // ---------------------------------------------------------------------------
@@ -465,9 +457,7 @@ export async function getSellersByRegion(
465
457
  const params = new URLSearchParams({ country: "BRA", postalCode });
466
458
  const sc = salesChannel ?? getVtexConfig().salesChannel;
467
459
  if (sc) params.set("sc", sc);
468
- const resp = await vtexFetch<RegionResult[]>(
469
- `/api/checkout/pub/regions/?${params}`,
470
- );
460
+ const resp = await vtexFetch<RegionResult[]>(`/api/checkout/pub/regions/?${params}`);
471
461
  return resp[0]?.sellers?.length > 0 ? resp[0] : null;
472
462
  }
473
463
 
@@ -479,17 +469,14 @@ export async function setShippingPostalCode(
479
469
  ): Promise<boolean> {
480
470
  try {
481
471
  const headers: Record<string, string> = {};
482
- if (cookieHeader) headers["cookie"] = cookieHeader;
483
- await vtexFetch<any>(
484
- `/api/checkout/pub/orderForm/${orderFormId}/attachments/shippingData`,
485
- {
486
- method: "POST",
487
- body: JSON.stringify({
488
- selectedAddresses: [{ postalCode, country }],
489
- }),
490
- headers,
491
- },
492
- );
472
+ if (cookieHeader) headers.cookie = cookieHeader;
473
+ await vtexFetch<any>(`/api/checkout/pub/orderForm/${orderFormId}/attachments/shippingData`, {
474
+ method: "POST",
475
+ body: JSON.stringify({
476
+ selectedAddresses: [{ postalCode, country }],
477
+ }),
478
+ headers,
479
+ });
493
480
  return true;
494
481
  } catch {
495
482
  return false;
@@ -20,16 +20,13 @@ export async function createDocument(
20
20
  entity: string,
21
21
  data: Record<string, any>,
22
22
  ): Promise<CreateDocumentResult> {
23
- return vtexFetch<CreateDocumentResult>(
24
- `/api/dataentities/${entity}/documents`,
25
- { method: "POST", body: JSON.stringify(removeEmptyFields(data)) },
26
- );
23
+ return vtexFetch<CreateDocumentResult>(`/api/dataentities/${entity}/documents`, {
24
+ method: "POST",
25
+ body: JSON.stringify(removeEmptyFields(data)),
26
+ });
27
27
  }
28
28
 
29
- export async function getDocument<T = unknown>(
30
- entity: string,
31
- documentId: string,
32
- ): Promise<T> {
29
+ export async function getDocument<T = unknown>(entity: string, documentId: string): Promise<T> {
33
30
  return vtexFetch<T>(`/api/dataentities/${entity}/documents/${documentId}`);
34
31
  }
35
32
 
@@ -59,9 +56,7 @@ export async function searchDocuments<T = MasterDataSearchResult>(
59
56
  entity: string,
60
57
  filter: string,
61
58
  ): Promise<T[]> {
62
- return vtexFetch<T[]>(
63
- `/api/dataentities/${entity}/search?_where=${encodeURIComponent(filter)}`,
64
- );
59
+ return vtexFetch<T[]>(`/api/dataentities/${entity}/search?_where=${encodeURIComponent(filter)}`);
65
60
  }
66
61
 
67
62
  /**
@@ -86,15 +81,7 @@ export interface SearchDocumentsOpts {
86
81
  export async function searchDocumentsFull<T = Record<string, unknown>>(
87
82
  opts: SearchDocumentsOpts,
88
83
  ): Promise<T[]> {
89
- const {
90
- acronym,
91
- fields,
92
- where,
93
- sort,
94
- skip = 0,
95
- take = 10,
96
- cookieHeader,
97
- } = opts;
84
+ const { acronym, fields, where, sort, skip = 0, take = 10, cookieHeader } = opts;
98
85
  const from = Math.max(skip, 0);
99
86
  const to = from + Math.min(100, take);
100
87
 
@@ -108,7 +95,7 @@ export async function searchDocumentsFull<T = Record<string, unknown>>(
108
95
  "content-type": "application/json",
109
96
  "REST-Range": `resources=${from}-${to}`,
110
97
  };
111
- if (cookieHeader) headers["cookie"] = cookieHeader;
98
+ if (cookieHeader) headers.cookie = cookieHeader;
112
99
 
113
100
  return vtexFetchResponse(`/api/dataentities/${acronym}/search?${params}`, {
114
101
  headers,
@@ -133,9 +120,7 @@ export interface UploadAttachmentOpts {
133
120
  * Upload a file attachment to a MasterData document.
134
121
  * Uses the VTEX MasterData attachment API with appKey/appToken auth.
135
122
  */
136
- export async function uploadAttachment(
137
- opts: UploadAttachmentOpts,
138
- ): Promise<{ ok: true }> {
123
+ export async function uploadAttachment(opts: UploadAttachmentOpts): Promise<{ ok: true }> {
139
124
  const { entity, documentId, field, fileName, fileBase64, contentType } = opts;
140
125
  const config = getVtexConfig();
141
126
  const url = `https://${config.account}.vtexcommercestable.${config.domain ?? "com.br"}/api/dataentities/${entity}/documents/${documentId}/${field}/attachments`;
@@ -161,9 +146,7 @@ export async function uploadAttachment(
161
146
  });
162
147
 
163
148
  if (!response.ok) {
164
- throw new Error(
165
- `VTEX attachment upload failed: ${response.status} ${response.statusText}`,
166
- );
149
+ throw new Error(`VTEX attachment upload failed: ${response.status} ${response.statusText}`);
167
150
  }
168
151
 
169
152
  return { ok: true };