@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.
- package/LICENSE +21 -0
- package/commerce/components/Image.tsx +129 -143
- package/commerce/components/JsonLd.tsx +192 -201
- package/commerce/components/Picture.tsx +65 -75
- package/commerce/sdk/analytics.ts +15 -15
- package/commerce/sdk/formatPrice.ts +13 -16
- package/commerce/sdk/url.ts +7 -7
- package/commerce/sdk/useOffer.ts +46 -57
- package/commerce/sdk/useVariantPossibilities.ts +25 -25
- package/commerce/types/commerce.ts +868 -875
- package/commerce/utils/canonical.ts +5 -8
- package/commerce/utils/constants.ts +5 -6
- package/commerce/utils/filters.ts +4 -4
- package/commerce/utils/productToAnalyticsItem.ts +52 -56
- package/commerce/utils/stateByZip.ts +42 -42
- package/package.json +23 -4
- package/shopify/actions/cart/addItems.ts +24 -25
- package/shopify/actions/cart/updateCoupons.ts +19 -20
- package/shopify/actions/cart/updateItems.ts +19 -20
- package/shopify/actions/user/signIn.ts +25 -30
- package/shopify/actions/user/signUp.ts +19 -24
- package/shopify/client.ts +24 -24
- package/shopify/index.ts +20 -18
- package/shopify/init.ts +18 -21
- package/shopify/loaders/ProductDetailsPage.ts +16 -20
- package/shopify/loaders/ProductList.ts +66 -69
- package/shopify/loaders/ProductListingPage.ts +150 -158
- package/shopify/loaders/RelatedProducts.ts +24 -27
- package/shopify/loaders/cart.ts +53 -52
- package/shopify/loaders/shop.ts +22 -27
- package/shopify/loaders/user.ts +27 -32
- package/shopify/utils/admin/admin.ts +33 -34
- package/shopify/utils/admin/queries.ts +2 -2
- package/shopify/utils/cart.ts +18 -14
- package/shopify/utils/cookies.ts +62 -65
- package/shopify/utils/enums.ts +424 -424
- package/shopify/utils/graphql.ts +44 -55
- package/shopify/utils/storefront/queries.ts +24 -29
- package/shopify/utils/storefront/storefront.graphql.gen.ts +55 -55
- package/shopify/utils/transform.ts +370 -376
- package/shopify/utils/types.ts +118 -118
- package/shopify/utils/user.ts +11 -11
- package/shopify/utils/utils.ts +135 -140
- package/vtex/actions/address.ts +86 -86
- package/vtex/actions/auth.ts +14 -27
- package/vtex/actions/checkout.ts +36 -49
- package/vtex/actions/masterData.ts +10 -27
- package/vtex/actions/misc.ts +101 -111
- package/vtex/actions/newsletter.ts +48 -52
- package/vtex/actions/orders.ts +13 -16
- package/vtex/actions/profile.ts +55 -55
- package/vtex/actions/session.ts +36 -35
- package/vtex/actions/trigger.ts +25 -25
- package/vtex/actions/wishlist.ts +51 -53
- package/vtex/client.ts +14 -42
- package/vtex/hooks/index.ts +4 -4
- package/vtex/hooks/useAutocomplete.ts +42 -48
- package/vtex/hooks/useCart.ts +153 -165
- package/vtex/hooks/useUser.ts +40 -40
- package/vtex/hooks/useWishlist.ts +70 -70
- package/vtex/inline-loaders/productDetailsPage.ts +1 -3
- package/vtex/inline-loaders/productList.ts +121 -127
- package/vtex/inline-loaders/productListingPage.ts +10 -34
- package/vtex/inline-loaders/relatedProducts.ts +1 -3
- package/vtex/inline-loaders/suggestions.ts +36 -39
- package/vtex/inline-loaders/workflowProducts.ts +45 -49
- package/vtex/invoke.ts +159 -194
- package/vtex/loaders/address.ts +49 -54
- package/vtex/loaders/brands.ts +19 -26
- package/vtex/loaders/cart.ts +24 -21
- package/vtex/loaders/catalog.ts +51 -53
- package/vtex/loaders/collections.ts +25 -27
- package/vtex/loaders/legacy.ts +487 -534
- package/vtex/loaders/logistics.ts +33 -37
- package/vtex/loaders/navbar.ts +5 -8
- package/vtex/loaders/orders.ts +28 -39
- package/vtex/loaders/pageType.ts +41 -35
- package/vtex/loaders/payment.ts +27 -37
- package/vtex/loaders/profile.ts +38 -38
- package/vtex/loaders/promotion.ts +5 -8
- package/vtex/loaders/search.ts +56 -59
- package/vtex/loaders/session.ts +22 -30
- package/vtex/loaders/user.ts +39 -41
- package/vtex/loaders/wishlist.ts +35 -35
- package/vtex/loaders/wishlistProducts.ts +3 -15
- package/vtex/loaders/workflow.ts +220 -227
- package/vtex/middleware.ts +116 -119
- package/vtex/types.ts +201 -201
- package/vtex/utils/batch.ts +13 -16
- package/vtex/utils/cookies.ts +76 -80
- package/vtex/utils/enrichment.ts +62 -42
- package/vtex/utils/fetchCache.ts +1 -4
- package/vtex/utils/index.ts +6 -6
- package/vtex/utils/intelligentSearch.ts +48 -57
- package/vtex/utils/legacy.ts +108 -124
- package/vtex/utils/pickAndOmit.ts +15 -20
- package/vtex/utils/proxy.ts +136 -146
- package/vtex/utils/resourceRange.ts +3 -3
- package/vtex/utils/segment.ts +100 -111
- package/vtex/utils/similars.ts +1 -2
- package/vtex/utils/sitemap.ts +91 -91
- package/vtex/utils/slugCache.ts +2 -6
- package/vtex/utils/slugify.ts +9 -9
- package/vtex/utils/transform.ts +1012 -1105
- package/vtex/utils/types.ts +1381 -1381
- package/vtex/utils/vtexId.ts +44 -47
- package/.github/workflows/release.yml +0 -34
- package/.releaserc.json +0 -28
- package/knip.json +0 -19
- package/tsconfig.json +0 -11
package/vtex/actions/misc.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
email: string;
|
|
19
|
+
skuId: string;
|
|
20
|
+
name?: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface ReviewData {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
69
|
-
|
|
68
|
+
anonymous: string;
|
|
69
|
+
session: string;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export interface DeletePaymentTokenResult {
|
|
73
|
-
|
|
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
|
-
|
|
82
|
-
|
|
81
|
+
data: T;
|
|
82
|
+
errors?: Array<{ message: string }>;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
async function gql<T>(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
query: string,
|
|
87
|
+
variables: Record<string, unknown>,
|
|
88
|
+
authCookie: string,
|
|
89
89
|
): Promise<T> {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
event: AnalyticsEvent,
|
|
146
|
+
isCookies: ISCookies,
|
|
147
|
+
userAgent?: string,
|
|
148
148
|
): Promise<void> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
189
|
-
|
|
182
|
+
tokenId: string,
|
|
183
|
+
authCookie: string,
|
|
190
184
|
): Promise<DeletePaymentTokenResult> {
|
|
191
|
-
|
|
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 {
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
30
|
-
|
|
29
|
+
data: T;
|
|
30
|
+
errors?: Array<{ message: string }>;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async function gql<T>(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
query: string,
|
|
35
|
+
variables: Record<string, unknown>,
|
|
36
|
+
authCookie: string,
|
|
37
37
|
): Promise<T> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
subscribed: boolean,
|
|
99
|
+
email: string,
|
|
100
|
+
authCookie: string,
|
|
101
101
|
): Promise<{ subscribed: boolean }> {
|
|
102
|
-
|
|
103
|
-
|
|
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
|
}
|
package/vtex/actions/orders.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
orderId: string,
|
|
21
|
+
reason: string,
|
|
22
|
+
authCookie?: string,
|
|
23
23
|
): Promise<void> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const headers: Record<string, string> = {};
|
|
25
|
+
if (authCookie) {
|
|
26
|
+
headers.Cookie = buildAuthCookieHeader(authCookie, getVtexConfig().account);
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
}
|
package/vtex/actions/profile.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
53
|
-
|
|
52
|
+
data: T;
|
|
53
|
+
errors?: Array<{ message: string }>;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
async function gql<T>(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
query: string,
|
|
58
|
+
variables: Record<string, unknown>,
|
|
59
|
+
authCookie: string,
|
|
60
60
|
): Promise<T> {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
fields: Omit<ProfileInput, "email">,
|
|
110
|
+
email: string,
|
|
111
|
+
authCookie: string,
|
|
112
112
|
): Promise<Profile> {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
const { updateProfile: profile } = await gql<{ updateProfile: Profile }>(
|
|
114
|
+
UPDATE_PROFILE,
|
|
115
|
+
{ input: { ...fields, email } },
|
|
116
|
+
authCookie,
|
|
117
|
+
);
|
|
118
|
+
return profile;
|
|
119
119
|
}
|