@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
@@ -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 { vtexFetch, getVtexConfig } from "../client";
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
- | "OrderByTopSaleDESC"
17
- | "OrderByReleaseDateDESC"
18
- | "OrderByBestDiscountDESC"
19
- | "OrderByPriceDESC"
20
- | "OrderByPriceASC"
21
- | "OrderByNameASC"
22
- | "OrderByNameDESC"
23
- | "OrderByScoreDESC";
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
- fq?: string | string[];
27
- ft?: string;
28
- sort?: LegacySort;
29
- from?: number;
30
- to?: number;
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
- 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}`);
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
- productId?: string;
58
- skuId?: string;
57
+ productId?: string;
58
+ skuId?: string;
59
59
  }): Promise<T | null> {
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.");
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
- const results = await searchProducts<T>({ fq });
66
- return results[0] ?? null;
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
- return vtexFetch<T>(`/api/catalog_system/pub/products/variations/${productId}`);
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
- return vtexFetch<T>(`/api/catalog_system/pvt/products/${productId}/Specification`);
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
- | "similars"
99
- | "suggestions"
100
- | "accessories"
101
- | "whosawalsosaw"
102
- | "whosawalsobought"
103
- | "whoboughtalsobought"
104
- | "showtogether";
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
- type: CrossSellingType,
112
- productId: string,
111
+ type: CrossSellingType,
112
+ productId: string,
113
113
  ): Promise<T[]> {
114
- return vtexFetch<T[]>(
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
- return vtexFetch<T[]>(`/api/catalog_system/pub/category/tree/${levels}`);
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
- return vtexFetch<T[]>("/api/catalog_system/pub/brand/list");
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
- return vtexFetch<T>(`/api/catalog_system/pub/portal/pagetype/${term}`);
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
- return vtexFetch<T>(`/api/catalog_system/pub/facets/search/${term}`);
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
- value: string;
15
- label: string;
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
- term?: string,
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
- if (term) {
33
- params.set("page", "1");
34
- params.set("pageSize", "15");
35
- const list = await vtexFetch<CollectionList>(
36
- `/api/catalog_system/pvt/collection/search/${encodeURIComponent(term)}?${params}`,
37
- );
38
- return mapToOptions(list);
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
- params.set("page", "1");
42
- params.set("pageSize", "3000");
43
- params.set("orderByAsc", "false");
44
- const list = await vtexFetch<CollectionList>(
45
- `/api/catalog_system/pvt/collection/search?${params}`,
46
- );
47
- return mapToOptions(list);
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
- return (
52
- list.items?.map((c) => ({
53
- value: `${c.id}`,
54
- label: `${c.id} - ${c.name}`,
55
- })) ?? []
56
- );
49
+ return (
50
+ list.items?.map((c) => ({
51
+ value: `${c.id}`,
52
+ label: `${c.id} - ${c.name}`,
53
+ })) ?? []
54
+ );
57
55
  }