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