@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
|
@@ -18,22 +18,22 @@ import { vtexFetch } from "../client";
|
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
19
19
|
|
|
20
20
|
export interface ProductBalance {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
warehouseId: string;
|
|
22
|
+
warehouseName: string;
|
|
23
|
+
totalQuantity: number;
|
|
24
|
+
reservedQuantity: number;
|
|
25
|
+
hasUnlimitedQuantity: boolean;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface PickupPointsByLocationOpts {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
geoCoordinates?: number[];
|
|
30
|
+
postalCode?: string;
|
|
31
|
+
countryCode?: string;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export interface PickupPointsResponse<T = any> {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
paging: { page: number; pageSize: number; total: number; pages: number };
|
|
36
|
+
items: Array<{ distance: number; pickupPoint: T }>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// ---------------------------------------------------------------------------
|
|
@@ -45,7 +45,7 @@ export interface PickupPointsResponse<T = any> {
|
|
|
45
45
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/saleschannel/-salesChannelId-
|
|
46
46
|
*/
|
|
47
47
|
export async function getSalesChannelById<T = any>(id: string): Promise<T> {
|
|
48
|
-
|
|
48
|
+
return vtexFetch<T>(`/api/catalog_system/pub/saleschannel/${id}`);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
@@ -53,7 +53,7 @@ export async function getSalesChannelById<T = any>(id: string): Promise<T> {
|
|
|
53
53
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pvt/saleschannel/list
|
|
54
54
|
*/
|
|
55
55
|
export async function listSalesChannels<T = any>(): Promise<T[]> {
|
|
56
|
-
|
|
56
|
+
return vtexFetch<T[]>("/api/catalog_system/pvt/saleschannel/list");
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// ---------------------------------------------------------------------------
|
|
@@ -65,7 +65,7 @@ export async function listSalesChannels<T = any>(): Promise<T[]> {
|
|
|
65
65
|
* @see https://developers.vtex.com/docs/api-reference/logistics-api#get-/api/logistics/pvt/configuration/pickuppoints
|
|
66
66
|
*/
|
|
67
67
|
export async function listPickupPoints<T = any>(): Promise<T[]> {
|
|
68
|
-
|
|
68
|
+
return vtexFetch<T[]>("/api/logistics/pvt/configuration/pickuppoints");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -75,19 +75,17 @@ export async function listPickupPoints<T = any>(): Promise<T[]> {
|
|
|
75
75
|
* @see https://developers.vtex.com/docs/api-reference/checkout-api#get-/api/checkout/pub/pickup-points
|
|
76
76
|
*/
|
|
77
77
|
export async function listPickupPointsByLocation<T = any>(
|
|
78
|
-
|
|
78
|
+
opts: PickupPointsByLocationOpts,
|
|
79
79
|
): Promise<PickupPointsResponse<T>> {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
const params = new URLSearchParams();
|
|
81
|
+
if (opts.geoCoordinates) {
|
|
82
|
+
params.set("geoCoordinates", opts.geoCoordinates.join(","));
|
|
83
|
+
} else {
|
|
84
|
+
if (opts.postalCode) params.set("postalCode", opts.postalCode);
|
|
85
|
+
if (opts.countryCode) params.set("countryCode", opts.countryCode);
|
|
86
|
+
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
`/api/checkout/pub/pickup-points?${params}`,
|
|
90
|
-
);
|
|
88
|
+
return vtexFetch<PickupPointsResponse<T>>(`/api/checkout/pub/pickup-points?${params}`);
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
// ---------------------------------------------------------------------------
|
|
@@ -98,18 +96,16 @@ export async function listPickupPointsByLocation<T = any>(
|
|
|
98
96
|
* List inventory balances for a SKU across all warehouses.
|
|
99
97
|
* @see https://developers.vtex.com/docs/api-reference/logistics-api#get-/api/logistics/pvt/inventory/skus/-skuId-
|
|
100
98
|
*/
|
|
101
|
-
export async function listStockByStore(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
balance?: ProductBalance[];
|
|
108
|
-
}>(`/api/logistics/pvt/inventory/skus/${skuId}`);
|
|
99
|
+
export async function listStockByStore(skuId: number): Promise<ProductBalance[]> {
|
|
100
|
+
try {
|
|
101
|
+
const result = await vtexFetch<{
|
|
102
|
+
skuId?: string;
|
|
103
|
+
balance?: ProductBalance[];
|
|
104
|
+
}>(`/api/logistics/pvt/inventory/skus/${skuId}`);
|
|
109
105
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
return result.balance ?? [];
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error("[listStockByStore]", error);
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
115
111
|
}
|
package/vtex/loaders/navbar.ts
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/category/tree/-categoryLevels-
|
|
9
9
|
*/
|
|
10
|
+
|
|
11
|
+
import type { SiteNavigationElement } from "../../commerce/types/commerce";
|
|
10
12
|
import { vtexFetch } from "../client";
|
|
11
13
|
import { categoryTreeToNavbar } from "../utils/transform";
|
|
12
14
|
import type { Category } from "../utils/types";
|
|
13
|
-
import type { SiteNavigationElement } from "../../commerce/types/commerce";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Fetch the category tree and transform it into an array of
|
|
@@ -18,12 +19,8 @@ import type { SiteNavigationElement } from "../../commerce/types/commerce";
|
|
|
18
19
|
*
|
|
19
20
|
* @param levels - Depth of the category tree (default: 2)
|
|
20
21
|
*/
|
|
21
|
-
export async function getNavbar(
|
|
22
|
-
|
|
23
|
-
): Promise<SiteNavigationElement[]> {
|
|
24
|
-
const tree = await vtexFetch<Category[]>(
|
|
25
|
-
`/api/catalog_system/pub/category/tree/${levels}`,
|
|
26
|
-
);
|
|
22
|
+
export async function getNavbar(levels: number = 2): Promise<SiteNavigationElement[]> {
|
|
23
|
+
const tree = await vtexFetch<Category[]>(`/api/catalog_system/pub/category/tree/${levels}`);
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
return categoryTreeToNavbar(tree);
|
|
29
26
|
}
|
package/vtex/loaders/orders.ts
CHANGED
|
@@ -20,13 +20,10 @@ import { vtexFetch } from "../client";
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://developers.vtex.com/docs/api-reference/orders-api#get-/api/oms/user/orders/-orderId-
|
|
22
22
|
*/
|
|
23
|
-
export async function getOrderById<T = any>(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
return vtexFetch<T>(`/api/oms/user/orders/${orderId}`, {
|
|
28
|
-
headers: { cookie: authCookie },
|
|
29
|
-
});
|
|
23
|
+
export async function getOrderById<T = any>(orderId: string, authCookie: string): Promise<T> {
|
|
24
|
+
return vtexFetch<T>(`/api/oms/user/orders/${orderId}`, {
|
|
25
|
+
headers: { cookie: authCookie },
|
|
26
|
+
});
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
// ---------------------------------------------------------------------------
|
|
@@ -34,9 +31,9 @@ export async function getOrderById<T = any>(
|
|
|
34
31
|
// ---------------------------------------------------------------------------
|
|
35
32
|
|
|
36
33
|
export interface ListOrdersOpts {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
clientEmail: string;
|
|
35
|
+
page?: string;
|
|
36
|
+
perPage?: string;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
/**
|
|
@@ -45,20 +42,17 @@ export interface ListOrdersOpts {
|
|
|
45
42
|
*
|
|
46
43
|
* @see https://developers.vtex.com/docs/api-reference/orders-api#get-/api/oms/user/orders
|
|
47
44
|
*/
|
|
48
|
-
export async function listOrders<T = any>(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
page,
|
|
56
|
-
per_page: perPage,
|
|
57
|
-
});
|
|
45
|
+
export async function listOrders<T = any>(opts: ListOrdersOpts, authCookie: string): Promise<T> {
|
|
46
|
+
const { clientEmail, page = "0", perPage = "15" } = opts;
|
|
47
|
+
const params = new URLSearchParams({
|
|
48
|
+
clientEmail,
|
|
49
|
+
page,
|
|
50
|
+
per_page: perPage,
|
|
51
|
+
});
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
return vtexFetch<T>(`/api/oms/user/orders?${params}`, {
|
|
54
|
+
headers: { cookie: authCookie },
|
|
55
|
+
});
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
// ---------------------------------------------------------------------------
|
|
@@ -81,23 +75,18 @@ export async function listOrders<T = any>(
|
|
|
81
75
|
*
|
|
82
76
|
* @see https://developers.vtex.com/docs/api-reference/checkout-api#get-/api/checkout/pub/orders/order-group/-orderGroupId-
|
|
83
77
|
*/
|
|
84
|
-
export async function getOrderPlaced<T = any>(
|
|
85
|
-
|
|
86
|
-
authCookie: string,
|
|
87
|
-
): Promise<T[]> {
|
|
88
|
-
const isOrderGroup = !orderId.includes("-");
|
|
78
|
+
export async function getOrderPlaced<T = any>(orderId: string, authCookie: string): Promise<T[]> {
|
|
79
|
+
const isOrderGroup = !orderId.includes("-");
|
|
89
80
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
81
|
+
if (isOrderGroup) {
|
|
82
|
+
return vtexFetch<T[]>(`/api/checkout/pub/orders/order-group/${orderId}`, {
|
|
83
|
+
headers: { cookie: authCookie },
|
|
84
|
+
});
|
|
85
|
+
}
|
|
96
86
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
87
|
+
const order = await vtexFetch<T>(`/api/checkout/pub/orders/${orderId}`, {
|
|
88
|
+
headers: { cookie: authCookie },
|
|
89
|
+
});
|
|
101
90
|
|
|
102
|
-
|
|
91
|
+
return [order];
|
|
103
92
|
}
|
package/vtex/loaders/pageType.ts
CHANGED
|
@@ -6,20 +6,20 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/portal/pagetype/-path-
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { type PageType, vtexFetch } from "../client";
|
|
10
10
|
|
|
11
11
|
export type { PageType };
|
|
12
12
|
|
|
13
13
|
export type VtexPageKind =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
| "product"
|
|
15
|
+
| "category"
|
|
16
|
+
| "department"
|
|
17
|
+
| "subcategory"
|
|
18
|
+
| "brand"
|
|
19
|
+
| "collection"
|
|
20
|
+
| "search"
|
|
21
|
+
| "fulltext"
|
|
22
|
+
| "notfound";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Resolve a URL path to a VTEX page type.
|
|
@@ -28,35 +28,41 @@ export type VtexPageKind =
|
|
|
28
28
|
* @returns The page type with kind normalization, or null on error
|
|
29
29
|
*/
|
|
30
30
|
export async function resolvePageType(
|
|
31
|
-
|
|
31
|
+
urlPath: string,
|
|
32
32
|
): Promise<{ pageType: PageType; kind: VtexPageKind } | null> {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const cleanPath = urlPath.replace(/^\//, "").replace(/\/$/, "");
|
|
34
|
+
if (!cleanPath) return null;
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`/api/catalog_system/pub/portal/pagetype/${cleanPath}`,
|
|
39
|
-
);
|
|
36
|
+
try {
|
|
37
|
+
const pt = await vtexFetch<PageType>(`/api/catalog_system/pub/portal/pagetype/${cleanPath}`);
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const kind = normalizeKind(pt.pageType);
|
|
40
|
+
return { pageType: pt, kind };
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
function normalizeKind(pageType: PageType["pageType"]): VtexPageKind {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
switch (pageType) {
|
|
48
|
+
case "Product":
|
|
49
|
+
return "product";
|
|
50
|
+
case "Category":
|
|
51
|
+
return "category";
|
|
52
|
+
case "Department":
|
|
53
|
+
return "department";
|
|
54
|
+
case "SubCategory":
|
|
55
|
+
return "subcategory";
|
|
56
|
+
case "Brand":
|
|
57
|
+
return "brand";
|
|
58
|
+
case "Collection":
|
|
59
|
+
case "Cluster":
|
|
60
|
+
return "collection";
|
|
61
|
+
case "Search":
|
|
62
|
+
return "search";
|
|
63
|
+
case "FullText":
|
|
64
|
+
return "fulltext";
|
|
65
|
+
default:
|
|
66
|
+
return "notfound";
|
|
67
|
+
}
|
|
62
68
|
}
|
package/vtex/loaders/payment.ts
CHANGED
|
@@ -13,26 +13,26 @@ import { vtexIOGraphQL } from "../client";
|
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
14
|
|
|
15
15
|
export interface PaymentSystem {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
name: string;
|
|
17
|
+
groupName: string;
|
|
18
|
+
requiresDocument: boolean;
|
|
19
|
+
displayDocument: boolean;
|
|
20
|
+
validator: {
|
|
21
|
+
regex: string | null;
|
|
22
|
+
mask: string | null;
|
|
23
|
+
cardCodeMask: string | null;
|
|
24
|
+
cardCodeRegex: string | null;
|
|
25
|
+
};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface Payment {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
accountStatus: string | null;
|
|
30
|
+
cardNumber: string;
|
|
31
|
+
expirationDate: string;
|
|
32
|
+
id: string;
|
|
33
|
+
isExpired: boolean;
|
|
34
|
+
paymentSystem: string;
|
|
35
|
+
paymentSystemName: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// ---------------------------------------------------------------------------
|
|
@@ -58,17 +58,12 @@ const PAYMENT_SYSTEMS_QUERY = `query getPaymentSystems {
|
|
|
58
58
|
* List available payment systems for the authenticated user.
|
|
59
59
|
* Requires a valid VTEX auth cookie.
|
|
60
60
|
*/
|
|
61
|
-
export async function getPaymentSystems(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
paymentSystems: PaymentSystem[];
|
|
66
|
-
}>(
|
|
67
|
-
{ query: PAYMENT_SYSTEMS_QUERY },
|
|
68
|
-
{ cookie: authCookie },
|
|
69
|
-
);
|
|
61
|
+
export async function getPaymentSystems(authCookie: string): Promise<PaymentSystem[]> {
|
|
62
|
+
const { paymentSystems } = await vtexIOGraphQL<{
|
|
63
|
+
paymentSystems: PaymentSystem[];
|
|
64
|
+
}>({ query: PAYMENT_SYSTEMS_QUERY }, { cookie: authCookie });
|
|
70
65
|
|
|
71
|
-
|
|
66
|
+
return paymentSystems;
|
|
72
67
|
}
|
|
73
68
|
|
|
74
69
|
// ---------------------------------------------------------------------------
|
|
@@ -93,15 +88,10 @@ const USER_PAYMENTS_QUERY = `query getUserPayments {
|
|
|
93
88
|
* List saved payment methods for the authenticated user.
|
|
94
89
|
* Requires a valid VTEX auth cookie.
|
|
95
90
|
*/
|
|
96
|
-
export async function getUserPayments(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
profile: { payments: Payment[] } | null;
|
|
101
|
-
}>(
|
|
102
|
-
{ query: USER_PAYMENTS_QUERY },
|
|
103
|
-
{ cookie: authCookie },
|
|
104
|
-
);
|
|
91
|
+
export async function getUserPayments(authCookie: string): Promise<Payment[]> {
|
|
92
|
+
const data = await vtexIOGraphQL<{
|
|
93
|
+
profile: { payments: Payment[] } | null;
|
|
94
|
+
}>({ query: USER_PAYMENTS_QUERY }, { cookie: authCookie });
|
|
105
95
|
|
|
106
|
-
|
|
96
|
+
return data.profile?.payments ?? [];
|
|
107
97
|
}
|
package/vtex/loaders/profile.ts
CHANGED
|
@@ -31,26 +31,26 @@ const ADDRESS_FIELDS = `
|
|
|
31
31
|
`;
|
|
32
32
|
|
|
33
33
|
export interface Profile {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
id: string;
|
|
35
|
+
cacheId: string;
|
|
36
|
+
email: string;
|
|
37
|
+
firstName: string;
|
|
38
|
+
lastName: string;
|
|
39
|
+
document: string;
|
|
40
|
+
userId: string;
|
|
41
|
+
birthDate: string;
|
|
42
|
+
gender: string;
|
|
43
|
+
homePhone: string;
|
|
44
|
+
businessPhone: string;
|
|
45
|
+
addresses: Record<string, unknown>[];
|
|
46
|
+
isCorporate: boolean;
|
|
47
|
+
tradeName: string;
|
|
48
|
+
corporateName: string;
|
|
49
|
+
corporateDocument: string;
|
|
50
|
+
stateRegistration: string;
|
|
51
|
+
payments: Record<string, unknown>[];
|
|
52
|
+
customFields: Array<{ key: string; value: string }>;
|
|
53
|
+
passwordLastUpdate: string;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// ---------------------------------------------------------------------------
|
|
@@ -100,18 +100,18 @@ const PROFILE_QUERY = `query getUserProfile($customFields: String) {
|
|
|
100
100
|
* Requires a valid VTEX auth cookie.
|
|
101
101
|
*/
|
|
102
102
|
export async function getCurrentProfile(
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
authCookie: string,
|
|
104
|
+
customFields?: string[],
|
|
105
105
|
): Promise<Profile> {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
const { profile } = await vtexIOGraphQL<{ profile: Profile }>(
|
|
107
|
+
{
|
|
108
|
+
query: PROFILE_QUERY,
|
|
109
|
+
variables: { customFields: customFields?.join(",") },
|
|
110
|
+
},
|
|
111
|
+
{ cookie: authCookie },
|
|
112
|
+
);
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
return profile;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
// ---------------------------------------------------------------------------
|
|
@@ -125,14 +125,14 @@ export async function getCurrentProfile(
|
|
|
125
125
|
* @see https://developers.vtex.com/docs/api-reference/checkout-api#get-/api/checkout/pub/profiles
|
|
126
126
|
*/
|
|
127
127
|
export async function getProfileByEmail<T = any>(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
email: string,
|
|
129
|
+
authCookie: string,
|
|
130
|
+
ensureComplete?: boolean,
|
|
131
131
|
): Promise<T> {
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
const params = new URLSearchParams({ email });
|
|
133
|
+
if (ensureComplete) params.set("ensureComplete", "true");
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
return vtexFetch<T>(`/api/checkout/pub/profiles?${params}`, {
|
|
136
|
+
headers: { cookie: authCookie },
|
|
137
|
+
});
|
|
138
138
|
}
|
|
@@ -20,14 +20,11 @@ import type { Document } from "../utils/types";
|
|
|
20
20
|
* @param authCookie - Optional cookie string for authenticated requests
|
|
21
21
|
*/
|
|
22
22
|
export async function getPromotionById(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
promotionId: string,
|
|
24
|
+
authCookie?: string,
|
|
25
25
|
): Promise<Document[]> {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const headers: Record<string, string> = {};
|
|
27
|
+
if (authCookie) headers.cookie = authCookie;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
`/api/rnb/pvt/calculatorconfiguration/${promotionId}`,
|
|
31
|
-
{ headers },
|
|
32
|
-
);
|
|
29
|
+
return vtexFetch<Document[]>(`/api/rnb/pvt/calculatorconfiguration/${promotionId}`, { headers });
|
|
33
30
|
}
|