@decocms/apps 0.23.3 → 0.24.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 (110) 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 +23 -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/productListingPage.ts +10 -34
  64. package/vtex/inline-loaders/relatedProducts.ts +1 -3
  65. package/vtex/inline-loaders/suggestions.ts +36 -39
  66. package/vtex/inline-loaders/workflowProducts.ts +45 -49
  67. package/vtex/invoke.ts +159 -194
  68. package/vtex/loaders/address.ts +49 -54
  69. package/vtex/loaders/brands.ts +19 -26
  70. package/vtex/loaders/cart.ts +24 -21
  71. package/vtex/loaders/catalog.ts +51 -53
  72. package/vtex/loaders/collections.ts +25 -27
  73. package/vtex/loaders/legacy.ts +487 -534
  74. package/vtex/loaders/logistics.ts +33 -37
  75. package/vtex/loaders/navbar.ts +5 -8
  76. package/vtex/loaders/orders.ts +28 -39
  77. package/vtex/loaders/pageType.ts +41 -35
  78. package/vtex/loaders/payment.ts +27 -37
  79. package/vtex/loaders/profile.ts +38 -38
  80. package/vtex/loaders/promotion.ts +5 -8
  81. package/vtex/loaders/search.ts +56 -59
  82. package/vtex/loaders/session.ts +22 -30
  83. package/vtex/loaders/user.ts +39 -41
  84. package/vtex/loaders/wishlist.ts +35 -35
  85. package/vtex/loaders/wishlistProducts.ts +3 -15
  86. package/vtex/loaders/workflow.ts +220 -227
  87. package/vtex/middleware.ts +116 -119
  88. package/vtex/types.ts +201 -201
  89. package/vtex/utils/batch.ts +13 -16
  90. package/vtex/utils/cookies.ts +76 -80
  91. package/vtex/utils/enrichment.ts +62 -42
  92. package/vtex/utils/fetchCache.ts +1 -4
  93. package/vtex/utils/index.ts +6 -6
  94. package/vtex/utils/intelligentSearch.ts +48 -57
  95. package/vtex/utils/legacy.ts +108 -124
  96. package/vtex/utils/pickAndOmit.ts +15 -20
  97. package/vtex/utils/proxy.ts +136 -146
  98. package/vtex/utils/resourceRange.ts +3 -3
  99. package/vtex/utils/segment.ts +100 -111
  100. package/vtex/utils/similars.ts +1 -2
  101. package/vtex/utils/sitemap.ts +91 -91
  102. package/vtex/utils/slugCache.ts +2 -6
  103. package/vtex/utils/slugify.ts +9 -9
  104. package/vtex/utils/transform.ts +1012 -1105
  105. package/vtex/utils/types.ts +1381 -1381
  106. package/vtex/utils/vtexId.ts +44 -47
  107. package/.github/workflows/release.yml +0 -34
  108. package/.releaserc.json +0 -28
  109. package/knip.json +0 -19
  110. package/tsconfig.json +0 -11
package/vtex/invoke.ts CHANGED
@@ -22,210 +22,175 @@
22
22
  * ```
23
23
  */
24
24
  import { createInvokeFn } from "@decocms/start/sdk/createInvoke";
25
+ import type { RegionResult } from "./actions/checkout";
25
26
  import {
26
- getOrCreateCart,
27
- addItemsToCart,
28
- updateCartItems,
29
- addCouponToCart,
30
- simulateCart,
31
- getSellersByRegion,
32
- setShippingPostalCode,
33
- updateOrderFormAttachment,
34
- type SimulationItem,
27
+ addCouponToCart,
28
+ addItemsToCart,
29
+ getOrCreateCart,
30
+ getSellersByRegion,
31
+ type SimulationItem,
32
+ setShippingPostalCode,
33
+ simulateCart,
34
+ updateCartItems,
35
+ updateOrderFormAttachment,
35
36
  } from "./actions/checkout";
36
37
  import {
37
- createDocument,
38
- getDocument,
39
- patchDocument,
40
- searchDocuments,
41
- uploadAttachment,
42
- type UploadAttachmentOpts,
43
- type CreateDocumentResult,
38
+ type CreateDocumentResult,
39
+ createDocument,
40
+ getDocument,
41
+ patchDocument,
42
+ searchDocuments,
43
+ type UploadAttachmentOpts,
44
+ uploadAttachment,
44
45
  } from "./actions/masterData";
46
+ import { type NotifyMeProps, notifyMe } from "./actions/misc";
47
+ import { type SubscribeProps, subscribe } from "./actions/newsletter";
45
48
  import { createSession, editSession, type SessionData } from "./actions/session";
46
- import { subscribe, type SubscribeProps } from "./actions/newsletter";
47
- import { notifyMe, type NotifyMeProps } from "./actions/misc";
48
49
  import type { OrderForm } from "./types";
49
- import type { RegionResult } from "./actions/checkout";
50
50
 
51
51
  // ---------------------------------------------------------------------------
52
52
  // invoke.vtex.actions — typed server functions callable from client
53
53
  // ---------------------------------------------------------------------------
54
54
 
55
55
  export const invoke = {
56
- vtex: {
57
- actions: {
58
- // -- Cart (unwrap VtexFetchResult -> OrderForm) -----------------------
59
-
60
- getOrCreateCart: createInvokeFn(
61
- (input: { orderFormId?: string }) =>
62
- getOrCreateCart(input.orderFormId),
63
- { unwrap: true },
64
- ) as unknown as (ctx: { data: { orderFormId?: string } }) => Promise<OrderForm>,
65
-
66
- addItemsToCart: createInvokeFn(
67
- (input: {
68
- orderFormId: string;
69
- orderItems: Array<{
70
- id: string;
71
- seller: string;
72
- quantity: number;
73
- }>;
74
- }) => addItemsToCart(input.orderFormId, input.orderItems),
75
- { unwrap: true },
76
- ) as unknown as (ctx: {
77
- data: {
78
- orderFormId: string;
79
- orderItems: Array<{
80
- id: string;
81
- seller: string;
82
- quantity: number;
83
- }>;
84
- };
85
- }) => Promise<OrderForm>,
86
-
87
- updateCartItems: createInvokeFn(
88
- (input: {
89
- orderFormId: string;
90
- orderItems: Array<{ index: number; quantity: number }>;
91
- }) => updateCartItems(input.orderFormId, input.orderItems),
92
- { unwrap: true },
93
- ) as unknown as (ctx: {
94
- data: {
95
- orderFormId: string;
96
- orderItems: Array<{ index: number; quantity: number }>;
97
- };
98
- }) => Promise<OrderForm>,
99
-
100
- addCouponToCart: createInvokeFn(
101
- (input: { orderFormId: string; text: string }) =>
102
- addCouponToCart(input.orderFormId, input.text),
103
- { unwrap: true },
104
- ) as unknown as (ctx: {
105
- data: { orderFormId: string; text: string };
106
- }) => Promise<OrderForm>,
107
-
108
- simulateCart: createInvokeFn(
109
- (input: {
110
- items: SimulationItem[];
111
- postalCode: string;
112
- country?: string;
113
- }) => simulateCart(input.items, input.postalCode, input.country),
114
- ),
115
-
116
- // -- Shipping / Region ------------------------------------------------
117
-
118
- getSellersByRegion: createInvokeFn(
119
- (input: { postalCode: string; salesChannel?: string }) =>
120
- getSellersByRegion(input.postalCode, input.salesChannel),
121
- ) as (ctx: {
122
- data: { postalCode: string; salesChannel?: string };
123
- }) => Promise<RegionResult | null>,
124
-
125
- setShippingPostalCode: createInvokeFn(
126
- (input: {
127
- orderFormId: string;
128
- postalCode: string;
129
- country?: string;
130
- }) =>
131
- setShippingPostalCode(
132
- input.orderFormId,
133
- input.postalCode,
134
- input.country,
135
- ),
136
- ) as (ctx: {
137
- data: {
138
- orderFormId: string;
139
- postalCode: string;
140
- country?: string;
141
- };
142
- }) => Promise<boolean>,
143
-
144
- updateOrderFormAttachment: createInvokeFn(
145
- (input: {
146
- orderFormId: string;
147
- attachment: string;
148
- body: Record<string, unknown>;
149
- }) =>
150
- updateOrderFormAttachment(
151
- input.orderFormId,
152
- input.attachment,
153
- input.body,
154
- ),
155
- { unwrap: true },
156
- ) as unknown as (ctx: {
157
- data: {
158
- orderFormId: string;
159
- attachment: string;
160
- body: Record<string, unknown>;
161
- };
162
- }) => Promise<OrderForm>,
163
-
164
- // -- Session ----------------------------------------------------------
165
-
166
- createSession: createInvokeFn(
167
- (input: Record<string, any>) => createSession(input),
168
- { unwrap: true },
169
- ),
170
-
171
- editSession: createInvokeFn(
172
- (input: { public: Record<string, { value: string }> }) =>
173
- editSession(input.public),
174
- { unwrap: true },
175
- ) as unknown as (ctx: {
176
- data: { public: Record<string, { value: string }> };
177
- }) => Promise<SessionData>,
178
-
179
- // -- MasterData -------------------------------------------------------
180
-
181
- createDocument: createInvokeFn(
182
- (input: { entity: string; data: Record<string, any> }) =>
183
- createDocument(input.entity, input.data),
184
- ) as (ctx: {
185
- data: { entity: string; data: Record<string, any> };
186
- }) => Promise<CreateDocumentResult>,
187
-
188
- getDocument: createInvokeFn(
189
- (input: { entity: string; documentId: string }) =>
190
- getDocument(input.entity, input.documentId),
191
- ),
192
-
193
- patchDocument: createInvokeFn(
194
- (input: {
195
- entity: string;
196
- documentId: string;
197
- data: Record<string, any>;
198
- }) => patchDocument(input.entity, input.documentId, input.data),
199
- ) as (ctx: {
200
- data: {
201
- entity: string;
202
- documentId: string;
203
- data: Record<string, any>;
204
- };
205
- }) => Promise<void>,
206
-
207
- searchDocuments: createInvokeFn(
208
- (input: { entity: string; filter: string }) =>
209
- searchDocuments(input.entity, input.filter),
210
- ),
211
-
212
- uploadAttachment: createInvokeFn(
213
- (input: UploadAttachmentOpts) => uploadAttachment(input),
214
- ) as (ctx: {
215
- data: UploadAttachmentOpts;
216
- }) => Promise<{ ok: true }>,
217
-
218
- // -- Newsletter -------------------------------------------------------
219
-
220
- subscribe: createInvokeFn(
221
- (input: SubscribeProps) => subscribe(input),
222
- ) as (ctx: { data: SubscribeProps }) => Promise<void>,
223
-
224
- // -- Misc -------------------------------------------------------------
225
-
226
- notifyMe: createInvokeFn(
227
- (input: NotifyMeProps) => notifyMe(input),
228
- ) as (ctx: { data: NotifyMeProps }) => Promise<void>,
229
- },
230
- },
56
+ vtex: {
57
+ actions: {
58
+ // -- Cart (unwrap VtexFetchResult -> OrderForm) -----------------------
59
+
60
+ getOrCreateCart: createInvokeFn(
61
+ (input: { orderFormId?: string }) => getOrCreateCart(input.orderFormId),
62
+ { unwrap: true },
63
+ ) as unknown as (ctx: { data: { orderFormId?: string } }) => Promise<OrderForm>,
64
+
65
+ addItemsToCart: createInvokeFn(
66
+ (input: {
67
+ orderFormId: string;
68
+ orderItems: Array<{
69
+ id: string;
70
+ seller: string;
71
+ quantity: number;
72
+ }>;
73
+ }) => addItemsToCart(input.orderFormId, input.orderItems),
74
+ { unwrap: true },
75
+ ) as unknown as (ctx: {
76
+ data: {
77
+ orderFormId: string;
78
+ orderItems: Array<{
79
+ id: string;
80
+ seller: string;
81
+ quantity: number;
82
+ }>;
83
+ };
84
+ }) => Promise<OrderForm>,
85
+
86
+ updateCartItems: createInvokeFn(
87
+ (input: { orderFormId: string; orderItems: Array<{ index: number; quantity: number }> }) =>
88
+ updateCartItems(input.orderFormId, input.orderItems),
89
+ { unwrap: true },
90
+ ) as unknown as (ctx: {
91
+ data: {
92
+ orderFormId: string;
93
+ orderItems: Array<{ index: number; quantity: number }>;
94
+ };
95
+ }) => Promise<OrderForm>,
96
+
97
+ addCouponToCart: createInvokeFn(
98
+ (input: { orderFormId: string; text: string }) =>
99
+ addCouponToCart(input.orderFormId, input.text),
100
+ { unwrap: true },
101
+ ) as unknown as (ctx: { data: { orderFormId: string; text: string } }) => Promise<OrderForm>,
102
+
103
+ simulateCart: createInvokeFn(
104
+ (input: { items: SimulationItem[]; postalCode: string; country?: string }) =>
105
+ simulateCart(input.items, input.postalCode, input.country),
106
+ ),
107
+
108
+ // -- Shipping / Region ------------------------------------------------
109
+
110
+ getSellersByRegion: createInvokeFn((input: { postalCode: string; salesChannel?: string }) =>
111
+ getSellersByRegion(input.postalCode, input.salesChannel),
112
+ ) as (ctx: {
113
+ data: { postalCode: string; salesChannel?: string };
114
+ }) => Promise<RegionResult | null>,
115
+
116
+ setShippingPostalCode: createInvokeFn(
117
+ (input: { orderFormId: string; postalCode: string; country?: string }) =>
118
+ setShippingPostalCode(input.orderFormId, input.postalCode, input.country),
119
+ ) as (ctx: {
120
+ data: {
121
+ orderFormId: string;
122
+ postalCode: string;
123
+ country?: string;
124
+ };
125
+ }) => Promise<boolean>,
126
+
127
+ updateOrderFormAttachment: createInvokeFn(
128
+ (input: { orderFormId: string; attachment: string; body: Record<string, unknown> }) =>
129
+ updateOrderFormAttachment(input.orderFormId, input.attachment, input.body),
130
+ { unwrap: true },
131
+ ) as unknown as (ctx: {
132
+ data: {
133
+ orderFormId: string;
134
+ attachment: string;
135
+ body: Record<string, unknown>;
136
+ };
137
+ }) => Promise<OrderForm>,
138
+
139
+ // -- Session ----------------------------------------------------------
140
+
141
+ createSession: createInvokeFn((input: Record<string, any>) => createSession(input), {
142
+ unwrap: true,
143
+ }),
144
+
145
+ editSession: createInvokeFn(
146
+ (input: { public: Record<string, { value: string }> }) => editSession(input.public),
147
+ { unwrap: true },
148
+ ) as unknown as (ctx: {
149
+ data: { public: Record<string, { value: string }> };
150
+ }) => Promise<SessionData>,
151
+
152
+ // -- MasterData -------------------------------------------------------
153
+
154
+ createDocument: createInvokeFn((input: { entity: string; data: Record<string, any> }) =>
155
+ createDocument(input.entity, input.data),
156
+ ) as (ctx: {
157
+ data: { entity: string; data: Record<string, any> };
158
+ }) => Promise<CreateDocumentResult>,
159
+
160
+ getDocument: createInvokeFn((input: { entity: string; documentId: string }) =>
161
+ getDocument(input.entity, input.documentId),
162
+ ),
163
+
164
+ patchDocument: createInvokeFn(
165
+ (input: { entity: string; documentId: string; data: Record<string, any> }) =>
166
+ patchDocument(input.entity, input.documentId, input.data),
167
+ ) as (ctx: {
168
+ data: {
169
+ entity: string;
170
+ documentId: string;
171
+ data: Record<string, any>;
172
+ };
173
+ }) => Promise<void>,
174
+
175
+ searchDocuments: createInvokeFn((input: { entity: string; filter: string }) =>
176
+ searchDocuments(input.entity, input.filter),
177
+ ),
178
+
179
+ uploadAttachment: createInvokeFn((input: UploadAttachmentOpts) =>
180
+ uploadAttachment(input),
181
+ ) as (ctx: { data: UploadAttachmentOpts }) => Promise<{ ok: true }>,
182
+
183
+ // -- Newsletter -------------------------------------------------------
184
+
185
+ subscribe: createInvokeFn((input: SubscribeProps) => subscribe(input)) as (ctx: {
186
+ data: SubscribeProps;
187
+ }) => Promise<void>,
188
+
189
+ // -- Misc -------------------------------------------------------------
190
+
191
+ notifyMe: createInvokeFn((input: NotifyMeProps) => notifyMe(input)) as (ctx: {
192
+ data: NotifyMeProps;
193
+ }) => Promise<void>,
194
+ },
195
+ },
231
196
  } as const;
@@ -15,34 +15,34 @@ import { vtexFetch, vtexIOGraphQL } from "../client";
15
15
  // ---------------------------------------------------------------------------
16
16
 
17
17
  export interface PostalAddress {
18
- "@type": "PostalAddress";
19
- postalCode?: string;
20
- addressLocality?: string;
21
- addressRegion?: string;
22
- addressCountry?: string;
23
- streetAddress?: string;
24
- identifier?: string;
25
- areaServed?: string;
26
- description?: string;
27
- disambiguatingDescription?: string;
28
- latitude?: number;
29
- longitude?: number;
18
+ "@type": "PostalAddress";
19
+ postalCode?: string;
20
+ addressLocality?: string;
21
+ addressRegion?: string;
22
+ addressCountry?: string;
23
+ streetAddress?: string;
24
+ identifier?: string;
25
+ areaServed?: string;
26
+ description?: string;
27
+ disambiguatingDescription?: string;
28
+ latitude?: number;
29
+ longitude?: number;
30
30
  }
31
31
 
32
32
  export interface VtexAddress {
33
- addressId: string;
34
- addressType: string;
35
- addressName: string;
36
- city: string;
37
- complement: string;
38
- country: string;
39
- neighborhood: string;
40
- number: string;
41
- postalCode: string;
42
- geoCoordinates: number[];
43
- receiverName: string;
44
- state: string;
45
- street: string;
33
+ addressId: string;
34
+ addressType: string;
35
+ addressName: string;
36
+ city: string;
37
+ complement: string;
38
+ country: string;
39
+ neighborhood: string;
40
+ number: string;
41
+ postalCode: string;
42
+ geoCoordinates: number[];
43
+ receiverName: string;
44
+ state: string;
45
+ street: string;
46
46
  }
47
47
 
48
48
  // ---------------------------------------------------------------------------
@@ -54,27 +54,27 @@ export interface VtexAddress {
54
54
  * @see https://developers.vtex.com/docs/api-reference/checkout-api#get-/api/checkout/pub/postal-code/-countryCode-/-postalCode-
55
55
  */
56
56
  export async function getAddressByPostalCode(
57
- countryCode: string,
58
- postalCode: string,
57
+ countryCode: string,
58
+ postalCode: string,
59
59
  ): Promise<PostalAddress> {
60
- const data = await vtexFetch<Record<string, any>>(
61
- `/api/checkout/pub/postal-code/${countryCode}/${postalCode}`,
62
- );
60
+ const data = await vtexFetch<Record<string, any>>(
61
+ `/api/checkout/pub/postal-code/${countryCode}/${postalCode}`,
62
+ );
63
63
 
64
- return {
65
- "@type": "PostalAddress",
66
- postalCode: data.postalCode,
67
- addressLocality: data.city,
68
- addressRegion: data.state,
69
- addressCountry: data.country,
70
- streetAddress: data.street || undefined,
71
- identifier: data.number || undefined,
72
- areaServed: data.neighborhood || undefined,
73
- description: data.complement || undefined,
74
- disambiguatingDescription: data.reference || undefined,
75
- latitude: data.geoCoordinates?.[0] || undefined,
76
- longitude: data.geoCoordinates?.[1] || undefined,
77
- };
64
+ return {
65
+ "@type": "PostalAddress",
66
+ postalCode: data.postalCode,
67
+ addressLocality: data.city,
68
+ addressRegion: data.state,
69
+ addressCountry: data.country,
70
+ streetAddress: data.street || undefined,
71
+ identifier: data.number || undefined,
72
+ areaServed: data.neighborhood || undefined,
73
+ description: data.complement || undefined,
74
+ disambiguatingDescription: data.reference || undefined,
75
+ latitude: data.geoCoordinates?.[0] ?? undefined,
76
+ longitude: data.geoCoordinates?.[1] ?? undefined,
77
+ };
78
78
  }
79
79
 
80
80
  // ---------------------------------------------------------------------------
@@ -106,15 +106,10 @@ const USER_ADDRESSES_QUERY = `query Addresses @context(scope: "private") {
106
106
  * Fetch addresses for the currently authenticated user.
107
107
  * Requires a valid VTEX auth cookie.
108
108
  */
109
- export async function getUserAddresses(
110
- authCookie: string,
111
- ): Promise<VtexAddress[]> {
112
- const { profile } = await vtexIOGraphQL<{
113
- profile: { addresses: VtexAddress[] };
114
- }>(
115
- { query: USER_ADDRESSES_QUERY },
116
- { cookie: authCookie },
117
- );
109
+ export async function getUserAddresses(authCookie: string): Promise<VtexAddress[]> {
110
+ const { profile } = await vtexIOGraphQL<{
111
+ profile: { addresses: VtexAddress[] };
112
+ }>({ query: USER_ADDRESSES_QUERY }, { cookie: authCookie });
118
113
 
119
- return profile?.addresses ?? [];
114
+ return profile?.addresses ?? [];
120
115
  }
@@ -4,48 +4,41 @@
4
4
  *
5
5
  * @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/brand/list
6
6
  */
7
- import { vtexFetch, getVtexConfig } from "../client";
8
- import { toBrand } from "../utils/transform";
7
+
9
8
  import type { Brand } from "../../commerce/types/commerce";
9
+ import { getVtexConfig, vtexFetch } from "../client";
10
+ import { toBrand } from "../utils/transform";
10
11
  import type { Brand as BrandVTEX } from "../utils/types";
11
12
 
12
13
  export interface ListBrandsOpts {
13
- /** When true, only returns active brands. @default false */
14
- filterInactive?: boolean;
14
+ /** When true, only returns active brands. @default false */
15
+ filterInactive?: boolean;
15
16
  }
16
17
 
17
18
  /**
18
19
  * List brands from the VTEX catalog, transformed to schema.org Brand format.
19
20
  */
20
- export async function listBrands(
21
- opts?: ListBrandsOpts,
22
- ): Promise<Brand[]> {
23
- const config = getVtexConfig();
24
- const baseUrl = `https://${config.account}.vteximg.com.br/arquivos/ids`;
21
+ export async function listBrands(opts?: ListBrandsOpts): Promise<Brand[]> {
22
+ const config = getVtexConfig();
23
+ const baseUrl = `https://${config.account}.vteximg.com.br/arquivos/ids`;
25
24
 
26
- const brands = await vtexFetch<BrandVTEX[]>(
27
- "/api/catalog_system/pub/brand/list",
28
- );
25
+ const brands = await vtexFetch<BrandVTEX[]>("/api/catalog_system/pub/brand/list");
29
26
 
30
- const filtered = opts?.filterInactive
31
- ? brands.filter((b) => b.isActive)
32
- : brands;
27
+ const filtered = opts?.filterInactive ? brands.filter((b) => b.isActive) : brands;
33
28
 
34
- return filtered.map((b) => toBrand(b, baseUrl));
29
+ return filtered.map((b) => toBrand(b, baseUrl));
35
30
  }
36
31
 
37
32
  /**
38
33
  * Get a single brand by ID, as schema.org Brand.
39
34
  */
40
35
  export async function getBrandById(brandId: number): Promise<Brand | null> {
41
- try {
42
- const config = getVtexConfig();
43
- const baseUrl = `https://${config.account}.vteximg.com.br/arquivos/ids`;
44
- const brand = await vtexFetch<BrandVTEX>(
45
- `/api/catalog_system/pub/brand/${brandId}`,
46
- );
47
- return toBrand(brand, baseUrl);
48
- } catch {
49
- return null;
50
- }
36
+ try {
37
+ const config = getVtexConfig();
38
+ const baseUrl = `https://${config.account}.vteximg.com.br/arquivos/ids`;
39
+ const brand = await vtexFetch<BrandVTEX>(`/api/catalog_system/pub/brand/${brandId}`);
40
+ return toBrand(brand, baseUrl);
41
+ } catch {
42
+ return null;
43
+ }
51
44
  }
@@ -7,10 +7,11 @@
7
7
  *
8
8
  * @see https://developers.vtex.com/docs/api-reference/checkout-api#get-/api/checkout/pub/orderForm
9
9
  */
10
- import { vtexFetch, getVtexConfig } from "../client";
11
- import type { OrderForm } from "../utils/types";
12
- import { forceHttpsOnAssets } from "../utils/transform";
10
+
13
11
  import { DEFAULT_EXPECTED_SECTIONS } from "../actions/checkout";
12
+ import { getVtexConfig, vtexFetch } from "../client";
13
+ import { forceHttpsOnAssets } from "../utils/transform";
14
+ import type { OrderForm } from "../utils/types";
14
15
 
15
16
  /**
16
17
  * Fetch the current cart (OrderForm).
@@ -23,27 +24,29 @@ import { DEFAULT_EXPECTED_SECTIONS } from "../actions/checkout";
23
24
  * @param authCookie - Optional cookie string for authenticated requests
24
25
  */
25
26
  export async function getCart(
26
- orderFormId?: string,
27
- opts?: { salesChannel?: string; authCookie?: string },
27
+ orderFormId?: string,
28
+ opts?: { salesChannel?: string; authCookie?: string },
28
29
  ): Promise<OrderForm> {
29
- const { salesChannel } = getVtexConfig();
30
- const sc = opts?.salesChannel ?? salesChannel;
31
- const headers: Record<string, string> = {};
32
- if (opts?.authCookie) headers.cookie = opts.authCookie;
30
+ const { salesChannel } = getVtexConfig();
31
+ const sc = opts?.salesChannel ?? salesChannel;
32
+ const headers: Record<string, string> = {};
33
+ if (opts?.authCookie) headers.cookie = opts.authCookie;
33
34
 
34
- const scParam = sc ? `?sc=${sc}` : "";
35
+ const scParam = sc ? `?sc=${sc}` : "";
35
36
 
36
- const body = JSON.stringify({ expectedOrderFormSections: DEFAULT_EXPECTED_SECTIONS });
37
+ const body = JSON.stringify({ expectedOrderFormSections: DEFAULT_EXPECTED_SECTIONS });
37
38
 
38
- const cart = orderFormId
39
- ? await vtexFetch<OrderForm>(
40
- `/api/checkout/pub/orderForm/${orderFormId}${scParam}`,
41
- { method: "POST", headers, body },
42
- )
43
- : await vtexFetch<OrderForm>(
44
- `/api/checkout/pub/orderForm${scParam}`,
45
- { method: "POST", headers, body },
46
- );
39
+ const cart = orderFormId
40
+ ? await vtexFetch<OrderForm>(`/api/checkout/pub/orderForm/${orderFormId}${scParam}`, {
41
+ method: "POST",
42
+ headers,
43
+ body,
44
+ })
45
+ : await vtexFetch<OrderForm>(`/api/checkout/pub/orderForm${scParam}`, {
46
+ method: "POST",
47
+ headers,
48
+ body,
49
+ });
47
50
 
48
- return forceHttpsOnAssets(cart);
51
+ return forceHttpsOnAssets(cart);
49
52
  }