@decocms/apps 0.23.3 → 0.25.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 +24 -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/productListShelf.ts +159 -0
- 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 +1178 -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
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
const formatters = new Map<string, Intl.NumberFormat>();
|
|
2
2
|
|
|
3
3
|
const formatter = (currency: string, locale: string) => {
|
|
4
|
-
|
|
4
|
+
const key = `${currency}::${locale}`;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
if (!formatters.has(key)) {
|
|
7
|
+
formatters.set(
|
|
8
|
+
key,
|
|
9
|
+
new Intl.NumberFormat(locale, {
|
|
10
|
+
style: "currency",
|
|
11
|
+
currency,
|
|
12
|
+
}),
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
return formatters.get(key)!;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const formatPrice = (
|
|
20
|
-
|
|
21
|
-
currency = "BRL",
|
|
22
|
-
locale = "pt-BR",
|
|
23
|
-
) => price ? formatter(currency, locale).format(price) : null;
|
|
19
|
+
export const formatPrice = (price: number | undefined, currency = "BRL", locale = "pt-BR") =>
|
|
20
|
+
price !== undefined ? formatter(currency, locale).format(price) : null;
|
package/commerce/sdk/url.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export const relative = (link?: string | undefined) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
if (!link) return undefined;
|
|
3
|
+
try {
|
|
4
|
+
const linkUrl = new URL(link, "https://localhost");
|
|
5
|
+
return `${linkUrl.pathname}${linkUrl.search}`;
|
|
6
|
+
} catch {
|
|
7
|
+
return link;
|
|
8
|
+
}
|
|
9
9
|
};
|
package/commerce/sdk/useOffer.ts
CHANGED
|
@@ -1,75 +1,64 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AggregateOffer,
|
|
3
|
-
UnitPriceSpecification,
|
|
4
|
-
} from "../types/commerce";
|
|
1
|
+
import type { AggregateOffer, UnitPriceSpecification } from "../types/commerce";
|
|
5
2
|
|
|
6
|
-
const bestInstallment = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (curr.priceComponentType !== "https://schema.org/Installment") {
|
|
11
|
-
return acc;
|
|
12
|
-
}
|
|
3
|
+
const bestInstallment = (acc: UnitPriceSpecification | null, curr: UnitPriceSpecification) => {
|
|
4
|
+
if (curr.priceComponentType !== "https://schema.org/Installment") {
|
|
5
|
+
return acc;
|
|
6
|
+
}
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
if (!acc) {
|
|
9
|
+
return curr;
|
|
10
|
+
}
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
if (acc.price > curr.price) {
|
|
13
|
+
return curr;
|
|
14
|
+
}
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
if (acc.price < curr.price) {
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
) {
|
|
30
|
-
return curr;
|
|
31
|
-
}
|
|
20
|
+
if (acc.billingDuration && curr.billingDuration && acc.billingDuration < curr.billingDuration) {
|
|
21
|
+
return curr;
|
|
22
|
+
}
|
|
32
23
|
|
|
33
|
-
|
|
24
|
+
return acc;
|
|
34
25
|
};
|
|
35
26
|
|
|
36
27
|
const installmentToString = (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
installment: UnitPriceSpecification,
|
|
29
|
+
locale = "pt-BR",
|
|
30
|
+
currency = "BRL",
|
|
40
31
|
) => {
|
|
41
|
-
|
|
32
|
+
const { billingDuration, billingIncrement } = installment;
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
if (!billingDuration || !billingIncrement) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
const formatted = new Intl.NumberFormat(locale, {
|
|
39
|
+
style: "currency",
|
|
40
|
+
currency,
|
|
41
|
+
}).format(billingIncrement);
|
|
51
42
|
|
|
52
|
-
|
|
43
|
+
return `${billingDuration}x ${formatted}`;
|
|
53
44
|
};
|
|
54
45
|
|
|
55
46
|
export const useOffer = (aggregateOffer?: AggregateOffer) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
const offer = aggregateOffer?.offers?.[0];
|
|
48
|
+
const listPrice = offer?.priceSpecification?.find(
|
|
49
|
+
(spec) => spec.priceType === "https://schema.org/ListPrice",
|
|
50
|
+
);
|
|
51
|
+
const installment = offer?.priceSpecification?.reduce(bestInstallment, null);
|
|
52
|
+
const seller = offer?.seller;
|
|
53
|
+
const price = offer?.price;
|
|
54
|
+
const availability = offer?.availability;
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
installment,
|
|
74
|
-
};
|
|
56
|
+
return {
|
|
57
|
+
price,
|
|
58
|
+
listPrice: listPrice?.price,
|
|
59
|
+
availability,
|
|
60
|
+
seller,
|
|
61
|
+
installments: installment && price ? installmentToString(installment) : null,
|
|
62
|
+
installment,
|
|
63
|
+
};
|
|
75
64
|
};
|
|
@@ -7,37 +7,37 @@ const hash = ({ name, value }: PropertyValue) => `${name}::${value}`;
|
|
|
7
7
|
const omit = new Set(["category", "cluster", "RefId", "descriptionHtml"]);
|
|
8
8
|
|
|
9
9
|
export const useVariantPossibilities = (
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
variants: ProductLeaf[],
|
|
11
|
+
selected: ProductLeaf,
|
|
12
12
|
): Possibilities => {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const possibilities: Possibilities = {};
|
|
14
|
+
const selectedSpecs = new Set(selected.additionalProperty?.map(hash));
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
for (const variant of variants) {
|
|
17
|
+
const { url, additionalProperty = [], productID } = variant;
|
|
18
|
+
const isSelected = productID === selected.productID;
|
|
19
|
+
const specs = additionalProperty.filter(({ name }) => !omit.has(name!));
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
for (let it = 0; it < specs.length; it++) {
|
|
22
|
+
const name = specs[it].name!;
|
|
23
|
+
const value = specs[it].value!;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
if (omit.has(name)) continue;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
if (!possibilities[name]) {
|
|
28
|
+
possibilities[name] = {};
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const isSelectable =
|
|
32
|
+
it === 0 || specs.every((s) => s.name === name || selectedSpecs.has(hash(s)));
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
possibilities[name][value] = isSelected
|
|
35
|
+
? url
|
|
36
|
+
: isSelectable
|
|
37
|
+
? possibilities[name][value] || url
|
|
38
|
+
: possibilities[name][value];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
return possibilities;
|
|
43
43
|
};
|