@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
@@ -7,7 +7,7 @@
7
7
  * - vtex/actions/payment/deletePaymentToken.ts
8
8
  * @see https://developers.vtex.com/docs/api-reference
9
9
  */
10
- import { vtexFetch, getVtexConfig } from "../client";
10
+ import { getVtexConfig, vtexFetch } from "../client";
11
11
  import { buildAuthCookieHeader, VTEX_AUTH_COOKIE } from "../utils/vtexId";
12
12
 
13
13
  // ---------------------------------------------------------------------------
@@ -15,62 +15,62 @@ import { buildAuthCookieHeader, VTEX_AUTH_COOKIE } from "../utils/vtexId";
15
15
  // ---------------------------------------------------------------------------
16
16
 
17
17
  export interface NotifyMeProps {
18
- email: string;
19
- skuId: string;
20
- name?: string;
18
+ email: string;
19
+ skuId: string;
20
+ name?: string;
21
21
  }
22
22
 
23
23
  export interface ReviewData {
24
- productId: string;
25
- rating: number;
26
- title: string;
27
- text: string;
28
- reviewerName: string;
29
- approved: boolean;
24
+ productId: string;
25
+ rating: number;
26
+ title: string;
27
+ text: string;
28
+ reviewerName: string;
29
+ approved: boolean;
30
30
  }
31
31
 
32
32
  export type AnalyticsEvent =
33
- | {
34
- type: "session.ping";
35
- url: string;
36
- }
37
- | {
38
- type: "page.cart";
39
- products: { productId: string; quantity: number }[];
40
- }
41
- | {
42
- type: "page.empty_cart";
43
- products: Record<string, never>;
44
- }
45
- | {
46
- type: "page.confirmation";
47
- order: string;
48
- products: { productId: string; quantity: number; price: number }[];
49
- }
50
- | {
51
- type: "search.click";
52
- position: number;
53
- text: string;
54
- productId: string;
55
- url: string;
56
- }
57
- | {
58
- type: "search.query";
59
- url: string;
60
- text: string;
61
- misspelled: boolean;
62
- match: number;
63
- operator: string;
64
- locale: string;
65
- };
33
+ | {
34
+ type: "session.ping";
35
+ url: string;
36
+ }
37
+ | {
38
+ type: "page.cart";
39
+ products: { productId: string; quantity: number }[];
40
+ }
41
+ | {
42
+ type: "page.empty_cart";
43
+ products: Record<string, never>;
44
+ }
45
+ | {
46
+ type: "page.confirmation";
47
+ order: string;
48
+ products: { productId: string; quantity: number; price: number }[];
49
+ }
50
+ | {
51
+ type: "search.click";
52
+ position: number;
53
+ text: string;
54
+ productId: string;
55
+ url: string;
56
+ }
57
+ | {
58
+ type: "search.query";
59
+ url: string;
60
+ text: string;
61
+ misspelled: boolean;
62
+ match: number;
63
+ operator: string;
64
+ locale: string;
65
+ };
66
66
 
67
67
  export interface ISCookies {
68
- anonymous: string;
69
- session: string;
68
+ anonymous: string;
69
+ session: string;
70
70
  }
71
71
 
72
72
  export interface DeletePaymentTokenResult {
73
- deletePaymentToken: boolean;
73
+ deletePaymentToken: boolean;
74
74
  }
75
75
 
76
76
  // ---------------------------------------------------------------------------
@@ -78,28 +78,28 @@ export interface DeletePaymentTokenResult {
78
78
  // ---------------------------------------------------------------------------
79
79
 
80
80
  interface GqlResponse<T> {
81
- data: T;
82
- errors?: Array<{ message: string }>;
81
+ data: T;
82
+ errors?: Array<{ message: string }>;
83
83
  }
84
84
 
85
85
  async function gql<T>(
86
- query: string,
87
- variables: Record<string, unknown>,
88
- authCookie: string,
86
+ query: string,
87
+ variables: Record<string, unknown>,
88
+ authCookie: string,
89
89
  ): Promise<T> {
90
- const { account } = getVtexConfig();
91
- const result = await vtexFetch<GqlResponse<T>>(
92
- `https://${account}.myvtex.com/_v/private/graphql/v1`,
93
- {
94
- method: "POST",
95
- body: JSON.stringify({ query, variables }),
96
- headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
97
- },
98
- );
99
- if (result.errors?.length) {
100
- throw new Error(`GraphQL error: ${result.errors[0].message}`);
101
- }
102
- return result.data;
90
+ const { account } = getVtexConfig();
91
+ const result = await vtexFetch<GqlResponse<T>>(
92
+ `https://${account}.myvtex.com/_v/private/graphql/v1`,
93
+ {
94
+ method: "POST",
95
+ body: JSON.stringify({ query, variables }),
96
+ headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
97
+ },
98
+ );
99
+ if (result.errors?.length) {
100
+ throw new Error(`GraphQL error: ${result.errors[0].message}`);
101
+ }
102
+ return result.data;
103
103
  }
104
104
 
105
105
  // ---------------------------------------------------------------------------
@@ -119,18 +119,18 @@ const DELETE_PAYMENT_TOKEN = `mutation DeleteCreditCardToken($tokenId: ID!) {
119
119
  * Uses the legacy VTEX .aspx form endpoint (FormData, not JSON).
120
120
  */
121
121
  export async function notifyMe(props: NotifyMeProps): Promise<void> {
122
- const { account } = getVtexConfig();
123
- const { email, skuId, name = "" } = props;
124
-
125
- const form = new FormData();
126
- form.append("notifymeClientName", name);
127
- form.append("notifymeClientEmail", email);
128
- form.append("notifymeIdSku", skuId);
129
-
130
- await fetch(
131
- `https://${account}.vtexcommercestable.com.br/no-cache/AviseMe.aspx`,
132
- { method: "POST", body: form },
133
- );
122
+ const { account } = getVtexConfig();
123
+ const { email, skuId, name = "" } = props;
124
+
125
+ const form = new FormData();
126
+ form.append("notifymeClientName", name);
127
+ form.append("notifymeClientEmail", email);
128
+ form.append("notifymeIdSku", skuId);
129
+
130
+ await fetch(`https://${account}.vtexcommercestable.com.br/no-cache/AviseMe.aspx`, {
131
+ method: "POST",
132
+ body: form,
133
+ });
134
134
  }
135
135
 
136
136
  /**
@@ -142,21 +142,21 @@ export async function notifyMe(props: NotifyMeProps): Promise<void> {
142
142
  * @param userAgent - Forwarded user-agent string.
143
143
  */
144
144
  export async function sendEvent(
145
- event: AnalyticsEvent,
146
- isCookies: ISCookies,
147
- userAgent?: string,
145
+ event: AnalyticsEvent,
146
+ isCookies: ISCookies,
147
+ userAgent?: string,
148
148
  ): Promise<void> {
149
- const { account } = getVtexConfig();
150
-
151
- await fetch(`https://sp.vtex.com/event-api/v1/${account}/event`, {
152
- method: "POST",
153
- headers: { "Content-Type": "application/json" },
154
- body: JSON.stringify({
155
- ...event,
156
- ...isCookies,
157
- agent: userAgent || "deco-sites/apps",
158
- }),
159
- });
149
+ const { account } = getVtexConfig();
150
+
151
+ await fetch(`https://sp.vtex.com/event-api/v1/${account}/event`, {
152
+ method: "POST",
153
+ headers: { "Content-Type": "application/json" },
154
+ body: JSON.stringify({
155
+ ...event,
156
+ ...isCookies,
157
+ agent: userAgent || "deco-sites/apps",
158
+ }),
159
+ });
160
160
  }
161
161
 
162
162
  /**
@@ -164,20 +164,14 @@ export async function sendEvent(
164
164
  * Hits POST https://{account}.myvtex.com/reviews-and-ratings/api/review.
165
165
  * Auth is passed via the `VtexIdclientAutCookie` header (not a Cookie header).
166
166
  */
167
- export async function submitReview(
168
- data: ReviewData,
169
- authCookie: string,
170
- ): Promise<unknown> {
171
- const { account } = getVtexConfig();
172
-
173
- return vtexFetch<unknown>(
174
- `https://${account}.myvtex.com/reviews-and-ratings/api/review`,
175
- {
176
- method: "POST",
177
- body: JSON.stringify(data),
178
- headers: { [VTEX_AUTH_COOKIE]: authCookie },
179
- },
180
- );
167
+ export async function submitReview(data: ReviewData, authCookie: string): Promise<unknown> {
168
+ const { account } = getVtexConfig();
169
+
170
+ return vtexFetch<unknown>(`https://${account}.myvtex.com/reviews-and-ratings/api/review`, {
171
+ method: "POST",
172
+ body: JSON.stringify(data),
173
+ headers: { [VTEX_AUTH_COOKIE]: authCookie },
174
+ });
181
175
  }
182
176
 
183
177
  /**
@@ -185,12 +179,8 @@ export async function submitReview(
185
179
  * Uses the my-cards-graphql VTEX IO app.
186
180
  */
187
181
  export async function deletePaymentToken(
188
- tokenId: string,
189
- authCookie: string,
182
+ tokenId: string,
183
+ authCookie: string,
190
184
  ): Promise<DeletePaymentTokenResult> {
191
- return gql<DeletePaymentTokenResult>(
192
- DELETE_PAYMENT_TOKEN,
193
- { tokenId },
194
- authCookie,
195
- );
185
+ return gql<DeletePaymentTokenResult>(DELETE_PAYMENT_TOKEN, { tokenId }, authCookie);
196
186
  }
@@ -5,7 +5,7 @@
5
5
  * - vtex/actions/newsletter/updateNewsletterOptIn.ts
6
6
  * @see https://developers.vtex.com/docs/guides/newsletter
7
7
  */
8
- import { vtexFetch, getVtexConfig } from "../client";
8
+ import { getVtexConfig, vtexFetch } from "../client";
9
9
  import { buildAuthCookieHeader } from "../utils/vtexId";
10
10
 
11
11
  // ---------------------------------------------------------------------------
@@ -13,12 +13,12 @@ import { buildAuthCookieHeader } from "../utils/vtexId";
13
13
  // ---------------------------------------------------------------------------
14
14
 
15
15
  export interface SubscribeProps {
16
- email: string;
17
- name?: string;
18
- page?: string;
19
- part?: string;
20
- /** Intentionally preserving the original typo from the VTEX legacy form field. */
21
- campaing?: string;
16
+ email: string;
17
+ name?: string;
18
+ page?: string;
19
+ part?: string;
20
+ /** Intentionally preserving the original typo from the VTEX legacy form field. */
21
+ campaing?: string;
22
22
  }
23
23
 
24
24
  // ---------------------------------------------------------------------------
@@ -26,28 +26,28 @@ export interface SubscribeProps {
26
26
  // ---------------------------------------------------------------------------
27
27
 
28
28
  interface GqlResponse<T> {
29
- data: T;
30
- errors?: Array<{ message: string }>;
29
+ data: T;
30
+ errors?: Array<{ message: string }>;
31
31
  }
32
32
 
33
33
  async function gql<T>(
34
- query: string,
35
- variables: Record<string, unknown>,
36
- authCookie: string,
34
+ query: string,
35
+ variables: Record<string, unknown>,
36
+ authCookie: string,
37
37
  ): Promise<T> {
38
- const { account } = getVtexConfig();
39
- const result = await vtexFetch<GqlResponse<T>>(
40
- `https://${account}.myvtex.com/_v/private/graphql/v1`,
41
- {
42
- method: "POST",
43
- body: JSON.stringify({ query, variables }),
44
- headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
45
- },
46
- );
47
- if (result.errors?.length) {
48
- throw new Error(`GraphQL error: ${result.errors[0].message}`);
49
- }
50
- return result.data;
38
+ const { account } = getVtexConfig();
39
+ const result = await vtexFetch<GqlResponse<T>>(
40
+ `https://${account}.myvtex.com/_v/private/graphql/v1`,
41
+ {
42
+ method: "POST",
43
+ body: JSON.stringify({ query, variables }),
44
+ headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
45
+ },
46
+ );
47
+ if (result.errors?.length) {
48
+ throw new Error(`GraphQL error: ${result.errors[0].message}`);
49
+ }
50
+ return result.data;
51
51
  }
52
52
 
53
53
  // ---------------------------------------------------------------------------
@@ -67,26 +67,26 @@ const SUBSCRIBE_NEWSLETTER = `mutation SubscribeNewsletter($email: String!, $isN
67
67
  * Uses raw fetch because the body is FormData (not JSON).
68
68
  */
69
69
  export async function subscribe(props: SubscribeProps): Promise<void> {
70
- const { account } = getVtexConfig();
71
- const {
72
- email,
73
- name = "",
74
- part = "newsletter",
75
- page = "_",
76
- campaing = "newsletter:opt-in",
77
- } = props;
70
+ const { account } = getVtexConfig();
71
+ const {
72
+ email,
73
+ name = "",
74
+ part = "newsletter",
75
+ page = "_",
76
+ campaing = "newsletter:opt-in",
77
+ } = props;
78
78
 
79
- const form = new FormData();
80
- form.append("newsletterClientName", name);
81
- form.append("newsletterClientEmail", email);
82
- form.append("newsInternalPage", page);
83
- form.append("newsInternalPart", part);
84
- form.append("newsInternalCampaign", campaing);
79
+ const form = new FormData();
80
+ form.append("newsletterClientName", name);
81
+ form.append("newsletterClientEmail", email);
82
+ form.append("newsInternalPage", page);
83
+ form.append("newsInternalPart", part);
84
+ form.append("newsInternalCampaign", campaing);
85
85
 
86
- await fetch(
87
- `https://${account}.vtexcommercestable.com.br/no-cache/Newsletter.aspx`,
88
- { method: "POST", body: form },
89
- );
86
+ await fetch(`https://${account}.vtexcommercestable.com.br/no-cache/Newsletter.aspx`, {
87
+ method: "POST",
88
+ body: form,
89
+ });
90
90
  }
91
91
 
92
92
  /**
@@ -95,14 +95,10 @@ export async function subscribe(props: SubscribeProps): Promise<void> {
95
95
  * Here the caller must provide it explicitly.
96
96
  */
97
97
  export async function updateNewsletterOptIn(
98
- subscribed: boolean,
99
- email: string,
100
- authCookie: string,
98
+ subscribed: boolean,
99
+ email: string,
100
+ authCookie: string,
101
101
  ): Promise<{ subscribed: boolean }> {
102
- await gql<unknown>(
103
- SUBSCRIBE_NEWSLETTER,
104
- { email, isNewsletterOptIn: subscribed },
105
- authCookie,
106
- );
107
- return { subscribed };
102
+ await gql<unknown>(SUBSCRIBE_NEWSLETTER, { email, isNewsletterOptIn: subscribed }, authCookie);
103
+ return { subscribed };
108
104
  }
@@ -4,7 +4,7 @@
4
4
  * - vtex/actions/orders/cancel.ts
5
5
  * @see https://developers.vtex.com/docs/api-reference/orders-api
6
6
  */
7
- import { vtexFetch, getVtexConfig } from "../client";
7
+ import { getVtexConfig, vtexFetch } from "../client";
8
8
  import { buildAuthCookieHeader } from "../utils/vtexId";
9
9
 
10
10
  // ---------------------------------------------------------------------------
@@ -17,21 +17,18 @@ import { buildAuthCookieHeader } from "../utils/vtexId";
17
17
  * on vtexcommercestable.com.br.
18
18
  */
19
19
  export async function cancelOrder(
20
- orderId: string,
21
- reason: string,
22
- authCookie?: string,
20
+ orderId: string,
21
+ reason: string,
22
+ authCookie?: string,
23
23
  ): Promise<void> {
24
- const headers: Record<string, string> = {};
25
- if (authCookie) {
26
- headers.Cookie = buildAuthCookieHeader(authCookie, getVtexConfig().account);
27
- }
24
+ const headers: Record<string, string> = {};
25
+ if (authCookie) {
26
+ headers.Cookie = buildAuthCookieHeader(authCookie, getVtexConfig().account);
27
+ }
28
28
 
29
- await vtexFetch<unknown>(
30
- `/api/checkout/pub/orders/${orderId}/user-cancel-request`,
31
- {
32
- method: "POST",
33
- body: JSON.stringify({ reason }),
34
- headers,
35
- },
36
- );
29
+ await vtexFetch<unknown>(`/api/checkout/pub/orders/${orderId}/user-cancel-request`, {
30
+ method: "POST",
31
+ body: JSON.stringify({ reason }),
32
+ headers,
33
+ });
37
34
  }
@@ -4,7 +4,7 @@
4
4
  * - vtex/actions/profile/updateProfile.ts
5
5
  * @see https://developers.vtex.com/docs/guides/profile-system
6
6
  */
7
- import { vtexFetch, getVtexConfig } from "../client";
7
+ import { getVtexConfig, vtexFetch } from "../client";
8
8
  import { buildAuthCookieHeader } from "../utils/vtexId";
9
9
 
10
10
  // ---------------------------------------------------------------------------
@@ -12,36 +12,36 @@ import { buildAuthCookieHeader } from "../utils/vtexId";
12
12
  // ---------------------------------------------------------------------------
13
13
 
14
14
  export interface ProfileInput {
15
- firstName?: string;
16
- lastName?: string;
17
- birthDate?: string;
18
- gender?: string;
19
- homePhone?: string;
20
- businessPhone?: string;
21
- document?: string;
22
- email: string;
23
- tradeName?: string;
24
- corporateName?: string;
25
- corporateDocument?: string;
26
- stateRegistration?: string;
27
- isCorporate?: boolean;
15
+ firstName?: string;
16
+ lastName?: string;
17
+ birthDate?: string;
18
+ gender?: string;
19
+ homePhone?: string;
20
+ businessPhone?: string;
21
+ document?: string;
22
+ email: string;
23
+ tradeName?: string;
24
+ corporateName?: string;
25
+ corporateDocument?: string;
26
+ stateRegistration?: string;
27
+ isCorporate?: boolean;
28
28
  }
29
29
 
30
30
  export interface Profile {
31
- cacheId: string;
32
- firstName: string;
33
- lastName: string;
34
- birthDate: string;
35
- gender: string;
36
- homePhone: string;
37
- businessPhone: string;
38
- document: string;
39
- email: string;
40
- tradeName: string;
41
- corporateName: string;
42
- corporateDocument: string;
43
- stateRegistration: string;
44
- isCorporate: boolean;
31
+ cacheId: string;
32
+ firstName: string;
33
+ lastName: string;
34
+ birthDate: string;
35
+ gender: string;
36
+ homePhone: string;
37
+ businessPhone: string;
38
+ document: string;
39
+ email: string;
40
+ tradeName: string;
41
+ corporateName: string;
42
+ corporateDocument: string;
43
+ stateRegistration: string;
44
+ isCorporate: boolean;
45
45
  }
46
46
 
47
47
  // ---------------------------------------------------------------------------
@@ -49,28 +49,28 @@ export interface Profile {
49
49
  // ---------------------------------------------------------------------------
50
50
 
51
51
  interface GqlResponse<T> {
52
- data: T;
53
- errors?: Array<{ message: string }>;
52
+ data: T;
53
+ errors?: Array<{ message: string }>;
54
54
  }
55
55
 
56
56
  async function gql<T>(
57
- query: string,
58
- variables: Record<string, unknown>,
59
- authCookie: string,
57
+ query: string,
58
+ variables: Record<string, unknown>,
59
+ authCookie: string,
60
60
  ): Promise<T> {
61
- const { account } = getVtexConfig();
62
- const result = await vtexFetch<GqlResponse<T>>(
63
- `https://${account}.myvtex.com/_v/private/graphql/v1`,
64
- {
65
- method: "POST",
66
- body: JSON.stringify({ query, variables }),
67
- headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
68
- },
69
- );
70
- if (result.errors?.length) {
71
- throw new Error(`GraphQL error: ${result.errors[0].message}`);
72
- }
73
- return result.data;
61
+ const { account } = getVtexConfig();
62
+ const result = await vtexFetch<GqlResponse<T>>(
63
+ `https://${account}.myvtex.com/_v/private/graphql/v1`,
64
+ {
65
+ method: "POST",
66
+ body: JSON.stringify({ query, variables }),
67
+ headers: { Cookie: buildAuthCookieHeader(authCookie, account) },
68
+ },
69
+ );
70
+ if (result.errors?.length) {
71
+ throw new Error(`GraphQL error: ${result.errors[0].message}`);
72
+ }
73
+ return result.data;
74
74
  }
75
75
 
76
76
  // ---------------------------------------------------------------------------
@@ -106,14 +106,14 @@ const UPDATE_PROFILE = `mutation UpdateProfile($input: ProfileInput!) {
106
106
  * Here the caller must provide it explicitly.
107
107
  */
108
108
  export async function updateProfile(
109
- fields: Omit<ProfileInput, "email">,
110
- email: string,
111
- authCookie: string,
109
+ fields: Omit<ProfileInput, "email">,
110
+ email: string,
111
+ authCookie: string,
112
112
  ): Promise<Profile> {
113
- const { updateProfile: profile } = await gql<{ updateProfile: Profile }>(
114
- UPDATE_PROFILE,
115
- { input: { ...fields, email } },
116
- authCookie,
117
- );
118
- return profile;
113
+ const { updateProfile: profile } = await gql<{ updateProfile: Profile }>(
114
+ UPDATE_PROFILE,
115
+ { input: { ...fields, email } },
116
+ authCookie,
117
+ );
118
+ return profile;
119
119
  }