@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/loaders/catalog.ts
CHANGED
|
@@ -5,29 +5,29 @@
|
|
|
5
5
|
* Ported from deco-cx/apps vtex/loaders/legacy/*.ts and vtex/utils/client.ts
|
|
6
6
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { getVtexConfig, vtexFetch } from "../client";
|
|
9
9
|
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
// Product search (public)
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
13
|
|
|
14
14
|
export type LegacySort =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
| ""
|
|
16
|
+
| "OrderByTopSaleDESC"
|
|
17
|
+
| "OrderByReleaseDateDESC"
|
|
18
|
+
| "OrderByBestDiscountDESC"
|
|
19
|
+
| "OrderByPriceDESC"
|
|
20
|
+
| "OrderByPriceASC"
|
|
21
|
+
| "OrderByNameASC"
|
|
22
|
+
| "OrderByNameDESC"
|
|
23
|
+
| "OrderByScoreDESC";
|
|
24
24
|
|
|
25
25
|
export interface SearchProductsOpts {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
fq?: string | string[];
|
|
27
|
+
ft?: string;
|
|
28
|
+
sort?: LegacySort;
|
|
29
|
+
from?: number;
|
|
30
|
+
to?: number;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -35,18 +35,18 @@ export interface SearchProductsOpts {
|
|
|
35
35
|
* @see https://developers.vtex.com/docs/api-reference/search-api#get-/api/catalog_system/pub/products/search
|
|
36
36
|
*/
|
|
37
37
|
export async function searchProducts<T = any>(opts: SearchProductsOpts = {}): Promise<T[]> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
const params = new URLSearchParams();
|
|
39
|
+
const fqs = Array.isArray(opts.fq) ? opts.fq : opts.fq ? [opts.fq] : [];
|
|
40
|
+
for (const f of fqs) params.append("fq", f);
|
|
41
|
+
if (opts.ft) params.set("ft", opts.ft);
|
|
42
|
+
if (opts.sort) params.set("O", opts.sort);
|
|
43
|
+
if (opts.from != null) params.set("_from", String(opts.from));
|
|
44
|
+
if (opts.to != null) params.set("_to", String(opts.to));
|
|
45
|
+
|
|
46
|
+
const { salesChannel } = getVtexConfig();
|
|
47
|
+
if (salesChannel) params.set("sc", salesChannel);
|
|
48
|
+
|
|
49
|
+
return vtexFetch<T[]>(`/api/catalog_system/pub/products/search/?${params}`);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -54,16 +54,16 @@ export async function searchProducts<T = any>(opts: SearchProductsOpts = {}): Pr
|
|
|
54
54
|
* @see https://developers.vtex.com/docs/api-reference/search-api#get-/api/catalog_system/pub/products/search
|
|
55
55
|
*/
|
|
56
56
|
export async function getProductByIdOrSku<T = any>(opts: {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
productId?: string;
|
|
58
|
+
skuId?: string;
|
|
59
59
|
}): Promise<T | null> {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
let fq: string;
|
|
61
|
+
if (opts.productId) fq = `productId:${opts.productId}`;
|
|
62
|
+
else if (opts.skuId) fq = `skuId:${opts.skuId}`;
|
|
63
|
+
else throw new Error("Neither productId nor skuId provided.");
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const results = await searchProducts<T>({ fq });
|
|
66
|
+
return results[0] ?? null;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// ---------------------------------------------------------------------------
|
|
@@ -75,7 +75,7 @@ export async function getProductByIdOrSku<T = any>(opts: {
|
|
|
75
75
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/products/variations/-productId-
|
|
76
76
|
*/
|
|
77
77
|
export async function getProductVariations<T = any>(productId: string): Promise<T> {
|
|
78
|
-
|
|
78
|
+
return vtexFetch<T>(`/api/catalog_system/pub/products/variations/${productId}`);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// ---------------------------------------------------------------------------
|
|
@@ -87,7 +87,7 @@ export async function getProductVariations<T = any>(productId: string): Promise<
|
|
|
87
87
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pvt/products/-productId-/specification
|
|
88
88
|
*/
|
|
89
89
|
export async function getProductSpecification<T = any>(productId: string): Promise<T> {
|
|
90
|
-
|
|
90
|
+
return vtexFetch<T>(`/api/catalog_system/pvt/products/${productId}/Specification`);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// ---------------------------------------------------------------------------
|
|
@@ -95,25 +95,23 @@ export async function getProductSpecification<T = any>(productId: string): Promi
|
|
|
95
95
|
// ---------------------------------------------------------------------------
|
|
96
96
|
|
|
97
97
|
export type CrossSellingType =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
| "similars"
|
|
99
|
+
| "suggestions"
|
|
100
|
+
| "accessories"
|
|
101
|
+
| "whosawalsosaw"
|
|
102
|
+
| "whosawalsobought"
|
|
103
|
+
| "whoboughtalsobought"
|
|
104
|
+
| "showtogether";
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* Get cross-selling products.
|
|
108
108
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/products/crossselling/-type-/-productId-
|
|
109
109
|
*/
|
|
110
110
|
export async function getCrossSelling<T = any>(
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
type: CrossSellingType,
|
|
112
|
+
productId: string,
|
|
113
113
|
): Promise<T[]> {
|
|
114
|
-
|
|
115
|
-
`/api/catalog_system/pub/products/crossselling/${type}/${productId}`,
|
|
116
|
-
);
|
|
114
|
+
return vtexFetch<T[]>(`/api/catalog_system/pub/products/crossselling/${type}/${productId}`);
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
// ---------------------------------------------------------------------------
|
|
@@ -125,7 +123,7 @@ export async function getCrossSelling<T = any>(
|
|
|
125
123
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/category/tree/-categoryLevels-
|
|
126
124
|
*/
|
|
127
125
|
export async function getCategoryTree<T = any>(levels = 3): Promise<T[]> {
|
|
128
|
-
|
|
126
|
+
return vtexFetch<T[]>(`/api/catalog_system/pub/category/tree/${levels}`);
|
|
129
127
|
}
|
|
130
128
|
|
|
131
129
|
// ---------------------------------------------------------------------------
|
|
@@ -137,7 +135,7 @@ export async function getCategoryTree<T = any>(levels = 3): Promise<T[]> {
|
|
|
137
135
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/brand/list
|
|
138
136
|
*/
|
|
139
137
|
export async function getBrands<T = any>(): Promise<T[]> {
|
|
140
|
-
|
|
138
|
+
return vtexFetch<T[]>("/api/catalog_system/pub/brand/list");
|
|
141
139
|
}
|
|
142
140
|
|
|
143
141
|
// ---------------------------------------------------------------------------
|
|
@@ -149,7 +147,7 @@ export async function getBrands<T = any>(): Promise<T[]> {
|
|
|
149
147
|
* @see https://developers.vtex.com/docs/api-reference/catalog-api#get-/api/catalog_system/pub/portal/pagetype/-term-
|
|
150
148
|
*/
|
|
151
149
|
export async function getPageType<T = any>(term: string): Promise<T> {
|
|
152
|
-
|
|
150
|
+
return vtexFetch<T>(`/api/catalog_system/pub/portal/pagetype/${term}`);
|
|
153
151
|
}
|
|
154
152
|
|
|
155
153
|
// ---------------------------------------------------------------------------
|
|
@@ -161,5 +159,5 @@ export async function getPageType<T = any>(term: string): Promise<T> {
|
|
|
161
159
|
* @see https://developers.vtex.com/docs/api-reference/search-api#get-/api/catalog_system/pub/facets/search/-term-
|
|
162
160
|
*/
|
|
163
161
|
export async function getFacets<T = any>(term: string): Promise<T> {
|
|
164
|
-
|
|
162
|
+
return vtexFetch<T>(`/api/catalog_system/pub/facets/search/${term}`);
|
|
165
163
|
}
|
|
@@ -11,8 +11,8 @@ import { vtexFetch } from "../client";
|
|
|
11
11
|
import type { CollectionList } from "../utils/types";
|
|
12
12
|
|
|
13
13
|
export interface CollectionOption {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
value: string;
|
|
15
|
+
label: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -24,34 +24,32 @@ export interface CollectionOption {
|
|
|
24
24
|
*
|
|
25
25
|
* Note: uses the **pvt** (private) endpoint — requires appKey/appToken.
|
|
26
26
|
*/
|
|
27
|
-
export async function getCollections(
|
|
28
|
-
|
|
29
|
-
): Promise<CollectionOption[]> {
|
|
30
|
-
const params = new URLSearchParams();
|
|
27
|
+
export async function getCollections(term?: string): Promise<CollectionOption[]> {
|
|
28
|
+
const params = new URLSearchParams();
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
if (term) {
|
|
31
|
+
params.set("page", "1");
|
|
32
|
+
params.set("pageSize", "15");
|
|
33
|
+
const list = await vtexFetch<CollectionList>(
|
|
34
|
+
`/api/catalog_system/pvt/collection/search/${encodeURIComponent(term)}?${params}`,
|
|
35
|
+
);
|
|
36
|
+
return mapToOptions(list);
|
|
37
|
+
}
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
params.set("page", "1");
|
|
40
|
+
params.set("pageSize", "3000");
|
|
41
|
+
params.set("orderByAsc", "false");
|
|
42
|
+
const list = await vtexFetch<CollectionList>(
|
|
43
|
+
`/api/catalog_system/pvt/collection/search?${params}`,
|
|
44
|
+
);
|
|
45
|
+
return mapToOptions(list);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
function mapToOptions(list: CollectionList): CollectionOption[] {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
return (
|
|
50
|
+
list.items?.map((c) => ({
|
|
51
|
+
value: `${c.id}`,
|
|
52
|
+
label: `${c.id} - ${c.name}`,
|
|
53
|
+
})) ?? []
|
|
54
|
+
);
|
|
57
55
|
}
|