@decocms/apps 0.23.2 → 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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 deco.cx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -24,11 +24,11 @@ let imageCdnDomain = "decoims.com";
|
|
|
24
24
|
* - `deco-assets.decoazn.com` (Azion IMS, legacy)
|
|
25
25
|
*/
|
|
26
26
|
export function registerImageCdnDomain(domain: string) {
|
|
27
|
-
|
|
27
|
+
imageCdnDomain = domain.replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function getImageCdnDomain(): string {
|
|
31
|
-
|
|
31
|
+
return imageCdnDomain;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// -------------------------------------------------------------------------
|
|
@@ -40,10 +40,10 @@ export type FitOptions = "contain" | "cover" | "fill";
|
|
|
40
40
|
export const FACTORS = [1, 2];
|
|
41
41
|
|
|
42
42
|
interface OptimizationOptions {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
originalSrc: string;
|
|
44
|
+
width: number;
|
|
45
|
+
height?: number;
|
|
46
|
+
fit: FitOptions;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// -------------------------------------------------------------------------
|
|
@@ -52,27 +52,21 @@ interface OptimizationOptions {
|
|
|
52
52
|
// -------------------------------------------------------------------------
|
|
53
53
|
|
|
54
54
|
function optimizeVTEX(originalSrc: string, width: number, height?: number): string {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
ids,
|
|
63
|
-
`${trueId}-${width}-${height ?? width}`,
|
|
64
|
-
...rest,
|
|
65
|
-
].join("/");
|
|
66
|
-
|
|
67
|
-
return src.href;
|
|
55
|
+
const src = new URL(originalSrc);
|
|
56
|
+
const [slash, arquivos, ids, rawId, ...rest] = src.pathname.split("/");
|
|
57
|
+
const [trueId] = rawId.split("-");
|
|
58
|
+
|
|
59
|
+
src.pathname = [slash, arquivos, ids, `${trueId}-${width}-${height ?? width}`, ...rest].join("/");
|
|
60
|
+
|
|
61
|
+
return src.href;
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
function optimizeShopify(originalSrc: string, width: number, height?: number): string {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
const url = new URL(originalSrc);
|
|
66
|
+
url.searchParams.set("width", `${width}`);
|
|
67
|
+
if (height) url.searchParams.set("height", `${height}`);
|
|
68
|
+
url.searchParams.set("crop", "center");
|
|
69
|
+
return url.href;
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
// -------------------------------------------------------------------------
|
|
@@ -92,149 +86,141 @@ function optimizeShopify(originalSrc: string, width: number, height?: number): s
|
|
|
92
86
|
* Data URIs are returned as-is.
|
|
93
87
|
*/
|
|
94
88
|
export function getOptimizedMediaUrl(opts: OptimizationOptions): string {
|
|
95
|
-
|
|
89
|
+
const { originalSrc, width, height, fit } = opts;
|
|
96
90
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
if (originalSrc.startsWith("data:")) {
|
|
92
|
+
return originalSrc;
|
|
93
|
+
}
|
|
100
94
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return optimizeVTEX(originalSrc, width, height);
|
|
105
|
-
}
|
|
95
|
+
if (/(vteximg\.com\.br|vtexassets\.com|myvtex\.com)\/arquivos\/ids\/\d+/.test(originalSrc)) {
|
|
96
|
+
return optimizeVTEX(originalSrc, width, height);
|
|
97
|
+
}
|
|
106
98
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
99
|
+
if (originalSrc.startsWith("https://cdn.shopify.com")) {
|
|
100
|
+
return optimizeShopify(originalSrc, width, height);
|
|
101
|
+
}
|
|
110
102
|
|
|
111
|
-
|
|
112
|
-
.replace(DECO_CACHE_URL, "")
|
|
113
|
-
.replace(S3_URL, "")
|
|
114
|
-
.split("?")[0];
|
|
103
|
+
const imageSource = originalSrc.replace(DECO_CACHE_URL, "").replace(S3_URL, "").split("?")[0];
|
|
115
104
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
105
|
+
const params = new URLSearchParams();
|
|
106
|
+
params.set("fit", fit);
|
|
107
|
+
params.set("width", `${width}`);
|
|
108
|
+
if (height) params.set("height", `${height}`);
|
|
120
109
|
|
|
121
|
-
|
|
110
|
+
return `https://${imageCdnDomain}/image?${params}&src=${imageSource}`;
|
|
122
111
|
}
|
|
123
112
|
|
|
124
113
|
/**
|
|
125
114
|
* Generates a srcset string with responsive multipliers.
|
|
126
115
|
*/
|
|
127
116
|
export function getSrcSet(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
originalSrc: string,
|
|
118
|
+
width: number,
|
|
119
|
+
height?: number,
|
|
120
|
+
fit?: FitOptions,
|
|
121
|
+
factors: number[] = FACTORS,
|
|
133
122
|
): string | undefined {
|
|
134
|
-
|
|
123
|
+
const entries: string[] = [];
|
|
135
124
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
125
|
+
for (const factor of factors) {
|
|
126
|
+
const w = Math.trunc(factor * width);
|
|
127
|
+
const h = height ? Math.trunc(factor * height) : undefined;
|
|
139
128
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
129
|
+
const src = getOptimizedMediaUrl({
|
|
130
|
+
originalSrc,
|
|
131
|
+
width: w,
|
|
132
|
+
height: h,
|
|
133
|
+
fit: fit ?? "cover",
|
|
134
|
+
});
|
|
146
135
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
136
|
+
if (src) {
|
|
137
|
+
entries.push(`${src} ${w}w`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
151
140
|
|
|
152
|
-
|
|
141
|
+
return entries.length > 0 ? entries.join(", ") : undefined;
|
|
153
142
|
}
|
|
154
143
|
|
|
155
144
|
// -------------------------------------------------------------------------
|
|
156
145
|
// Image component
|
|
157
146
|
// -------------------------------------------------------------------------
|
|
158
147
|
|
|
159
|
-
export interface ImageProps
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
148
|
+
export interface ImageProps
|
|
149
|
+
extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "width" | "height"> {
|
|
150
|
+
src: string;
|
|
151
|
+
/** @description Improves Web Vitals (CLS/LCP) */
|
|
152
|
+
width: number;
|
|
153
|
+
/** @description Improves Web Vitals (CLS/LCP) */
|
|
154
|
+
height?: number;
|
|
155
|
+
/** @description Object-fit */
|
|
156
|
+
fit?: FitOptions;
|
|
157
|
+
/**
|
|
158
|
+
* @description Web Vitals (LCP). Injects a `<link rel="preload">` tag
|
|
159
|
+
* alongside the `<img>`, sets `fetchPriority="high"` and `loading="eager"`.
|
|
160
|
+
* Use once per page for the LCP image.
|
|
161
|
+
*/
|
|
162
|
+
preload?: boolean;
|
|
163
|
+
/** @description Media query for responsive preloading (e.g. "(min-width: 768px)") */
|
|
164
|
+
media?: string;
|
|
175
165
|
}
|
|
176
166
|
|
|
177
|
-
export const Image = forwardRef<HTMLImageElement, ImageProps>(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
</>
|
|
236
|
-
);
|
|
237
|
-
},
|
|
238
|
-
);
|
|
167
|
+
export const Image = forwardRef<HTMLImageElement, ImageProps>(function Image(
|
|
168
|
+
{
|
|
169
|
+
src,
|
|
170
|
+
width,
|
|
171
|
+
height,
|
|
172
|
+
fit = "cover",
|
|
173
|
+
preload,
|
|
174
|
+
media,
|
|
175
|
+
loading,
|
|
176
|
+
decoding,
|
|
177
|
+
srcSet: srcSetProp,
|
|
178
|
+
sizes,
|
|
179
|
+
fetchPriority,
|
|
180
|
+
...rest
|
|
181
|
+
},
|
|
182
|
+
ref,
|
|
183
|
+
) {
|
|
184
|
+
if (!height && typeof process !== "undefined") {
|
|
185
|
+
console.warn(`Missing height. This image will NOT be optimized: ${src}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const optimizedSrc = getOptimizedMediaUrl({
|
|
189
|
+
originalSrc: src,
|
|
190
|
+
width,
|
|
191
|
+
height,
|
|
192
|
+
fit,
|
|
193
|
+
});
|
|
194
|
+
const srcSet = srcSetProp ?? getSrcSet(src, width, height, fit);
|
|
195
|
+
const resolvedSizes = srcSet ? (sizes ?? "(max-width: 768px) 100vw, 50vw") : undefined;
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<>
|
|
199
|
+
{preload && (
|
|
200
|
+
<link
|
|
201
|
+
as="image"
|
|
202
|
+
rel="preload"
|
|
203
|
+
href={optimizedSrc}
|
|
204
|
+
imageSrcSet={srcSet}
|
|
205
|
+
imageSizes={resolvedSizes}
|
|
206
|
+
fetchPriority={fetchPriority ?? "high"}
|
|
207
|
+
media={media}
|
|
208
|
+
/>
|
|
209
|
+
)}
|
|
210
|
+
<img
|
|
211
|
+
{...rest}
|
|
212
|
+
src={optimizedSrc}
|
|
213
|
+
srcSet={srcSet}
|
|
214
|
+
sizes={resolvedSizes}
|
|
215
|
+
width={width}
|
|
216
|
+
height={height}
|
|
217
|
+
loading={loading ?? (preload ? "eager" : "lazy")}
|
|
218
|
+
decoding={decoding ?? "async"}
|
|
219
|
+
fetchPriority={preload ? "high" : fetchPriority}
|
|
220
|
+
ref={ref}
|
|
221
|
+
/>
|
|
222
|
+
</>
|
|
223
|
+
);
|
|
224
|
+
});
|
|
239
225
|
|
|
240
226
|
export default Image;
|