@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.
Files changed (111) 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 +24 -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/productListShelf.ts +159 -0
  64. package/vtex/inline-loaders/productListingPage.ts +10 -34
  65. package/vtex/inline-loaders/relatedProducts.ts +1 -3
  66. package/vtex/inline-loaders/suggestions.ts +36 -39
  67. package/vtex/inline-loaders/workflowProducts.ts +45 -49
  68. package/vtex/invoke.ts +159 -194
  69. package/vtex/loaders/address.ts +49 -54
  70. package/vtex/loaders/brands.ts +19 -26
  71. package/vtex/loaders/cart.ts +24 -21
  72. package/vtex/loaders/catalog.ts +51 -53
  73. package/vtex/loaders/collections.ts +25 -27
  74. package/vtex/loaders/legacy.ts +487 -534
  75. package/vtex/loaders/logistics.ts +33 -37
  76. package/vtex/loaders/navbar.ts +5 -8
  77. package/vtex/loaders/orders.ts +28 -39
  78. package/vtex/loaders/pageType.ts +41 -35
  79. package/vtex/loaders/payment.ts +27 -37
  80. package/vtex/loaders/profile.ts +38 -38
  81. package/vtex/loaders/promotion.ts +5 -8
  82. package/vtex/loaders/search.ts +56 -59
  83. package/vtex/loaders/session.ts +22 -30
  84. package/vtex/loaders/user.ts +39 -41
  85. package/vtex/loaders/wishlist.ts +35 -35
  86. package/vtex/loaders/wishlistProducts.ts +3 -15
  87. package/vtex/loaders/workflow.ts +220 -227
  88. package/vtex/middleware.ts +116 -119
  89. package/vtex/types.ts +201 -201
  90. package/vtex/utils/batch.ts +13 -16
  91. package/vtex/utils/cookies.ts +76 -80
  92. package/vtex/utils/enrichment.ts +62 -42
  93. package/vtex/utils/fetchCache.ts +1 -4
  94. package/vtex/utils/index.ts +6 -6
  95. package/vtex/utils/intelligentSearch.ts +48 -57
  96. package/vtex/utils/legacy.ts +108 -124
  97. package/vtex/utils/pickAndOmit.ts +15 -20
  98. package/vtex/utils/proxy.ts +136 -146
  99. package/vtex/utils/resourceRange.ts +3 -3
  100. package/vtex/utils/segment.ts +100 -111
  101. package/vtex/utils/similars.ts +1 -2
  102. package/vtex/utils/sitemap.ts +91 -91
  103. package/vtex/utils/slugCache.ts +2 -6
  104. package/vtex/utils/slugify.ts +9 -9
  105. package/vtex/utils/transform.ts +1178 -1105
  106. package/vtex/utils/types.ts +1381 -1381
  107. package/vtex/utils/vtexId.ts +44 -47
  108. package/.github/workflows/release.yml +0 -34
  109. package/.releaserc.json +0 -28
  110. package/knip.json +0 -19
  111. package/tsconfig.json +0 -11
@@ -1,57 +1,56 @@
1
-
2
1
  // deno-fmt-ignore-file
3
2
  // deno-lint-ignore-file no-explicit-any ban-types ban-unused-ignore
4
3
 
5
4
  export type Maybe<T> = T | null;
6
5
 
7
6
  export type Scalars = {
8
- ID: { input: string; output: string };
9
- String: { input: string; output: string };
10
- Boolean: { input: boolean; output: boolean };
11
- Int: { input: number; output: number };
12
- Float: { input: number; output: number };
13
- ARN: { input: any; output: any };
14
- Date: { input: any; output: any };
15
- DateTime: { input: any; output: any };
16
- Decimal: { input: any; output: any };
17
- FormattedString: { input: any; output: any };
18
- HTML: { input: any; output: any };
19
- JSON: { input: any; output: any };
20
- Money: { input: any; output: any };
21
- StorefrontID: { input: any; output: any };
22
- URL: { input: any; output: any };
23
- UnsignedInt64: { input: any; output: any };
24
- UtcOffset: { input: any; output: any };
7
+ ID: { input: string; output: string };
8
+ String: { input: string; output: string };
9
+ Boolean: { input: boolean; output: boolean };
10
+ Int: { input: number; output: number };
11
+ Float: { input: number; output: number };
12
+ ARN: { input: any; output: any };
13
+ Date: { input: any; output: any };
14
+ DateTime: { input: any; output: any };
15
+ Decimal: { input: any; output: any };
16
+ FormattedString: { input: any; output: any };
17
+ HTML: { input: any; output: any };
18
+ JSON: { input: any; output: any };
19
+ Money: { input: any; output: any };
20
+ StorefrontID: { input: any; output: any };
21
+ URL: { input: any; output: any };
22
+ UnsignedInt64: { input: any; output: any };
23
+ UtcOffset: { input: any; output: any };
25
24
  };
26
25
 
27
26
  /** Return type for `draftOrderCalculate` mutation. */
28
27
  export type DraftOrderCalculatePayload = {
29
- /** The calculated properties for a draft order. */
30
- calculatedDraftOrder?: Maybe<CalculatedDraftOrder>;
28
+ /** The calculated properties for a draft order. */
29
+ calculatedDraftOrder?: Maybe<CalculatedDraftOrder>;
31
30
  };
32
31
 
33
32
  export interface CalculatedDraftOrder {
34
- /** The available shipping rates for the draft order. Requires a customer with a valid shipping address and at least one line item. */
35
- availableShippingRates: Array<ShippingRate>;
33
+ /** The available shipping rates for the draft order. Requires a customer with a valid shipping address and at least one line item. */
34
+ availableShippingRates: Array<ShippingRate>;
36
35
  }
37
36
 
38
37
  export type ShippingRate = {
39
- /** Human-readable unique identifier for this shipping rate. */
40
- handle: Scalars["String"]["output"];
41
- /** The cost associated with the shipping rate. */
42
- price: MoneyV2;
43
- /** The name of the shipping rate. */
44
- title: Scalars["String"]["output"];
38
+ /** Human-readable unique identifier for this shipping rate. */
39
+ handle: Scalars["String"]["output"];
40
+ /** The cost associated with the shipping rate. */
41
+ price: MoneyV2;
42
+ /** The name of the shipping rate. */
43
+ title: Scalars["String"]["output"];
45
44
  };
46
45
 
47
46
  export type MoneyV2 = {
48
- /** Decimal money amount. */
49
- amount: Scalars["Decimal"]["output"];
50
- /** Currency of the money. */
51
- currencyCode: CurrencyCode;
47
+ /** Decimal money amount. */
48
+ amount: Scalars["Decimal"]["output"];
49
+ /** Currency of the money. */
50
+ currencyCode: CurrencyCode;
52
51
  };
53
52
 
54
53
  export enum CurrencyCode {
55
- CAD = "CAD",
56
- Usd = "USD",
54
+ CAD = "CAD",
55
+ Usd = "USD",
57
56
  }
@@ -4,11 +4,11 @@ import { gql } from "../graphql";
4
4
  // because it does not accept generating an empty schema
5
5
  // TODO: Remove this once you add any other query
6
6
  export const Noop = {
7
- query: gql`query Noop { app(id: "") { description } }`,
7
+ query: gql`query Noop { app(id: "") { description } }`,
8
8
  };
9
9
 
10
10
  export const draftOrderCalculate = {
11
- query: gql` mutation draftOrderCalculate($input: DraftOrderInput!) {
11
+ query: gql` mutation draftOrderCalculate($input: DraftOrderInput!) {
12
12
  calculatedDraftOrder: draftOrderCalculate(input: $input) {
13
13
  calculatedDraftOrder {
14
14
  availableShippingRates {
@@ -6,23 +6,27 @@ const SHOPIFY_PREFIX = "gid://shopify/Cart/";
6
6
  const ONE_WEEK_MS = 7 * 24 * 3600 * 1_000;
7
7
 
8
8
  export const getCartCookie = (headers: Headers): string | null => {
9
- const cookies = getCookies(headers);
9
+ const cookies = getCookies(headers);
10
10
 
11
- if (!cookies[CART_COOKIE]) {
12
- return null;
13
- }
11
+ if (!cookies[CART_COOKIE]) {
12
+ return null;
13
+ }
14
14
 
15
- return decodeURIComponent(`${SHOPIFY_PREFIX}${cookies[CART_COOKIE]}`);
15
+ try {
16
+ return decodeURIComponent(`${SHOPIFY_PREFIX}${cookies[CART_COOKIE]}`);
17
+ } catch {
18
+ return null;
19
+ }
16
20
  };
17
21
 
18
22
  export const setCartCookie = (headers: Headers, cartId: string) => {
19
- setCookie(headers, {
20
- name: CART_COOKIE,
21
- value: cartId.replace(SHOPIFY_PREFIX, ""),
22
- path: "/",
23
- expires: new Date(Date.now() + ONE_WEEK_MS),
24
- httpOnly: true,
25
- secure: true,
26
- sameSite: "Lax",
27
- });
23
+ setCookie(headers, {
24
+ name: CART_COOKIE,
25
+ value: cartId.replace(SHOPIFY_PREFIX, ""),
26
+ path: "/",
27
+ expires: new Date(Date.now() + ONE_WEEK_MS),
28
+ httpOnly: true,
29
+ secure: true,
30
+ sameSite: "Lax",
31
+ });
28
32
  };
@@ -4,82 +4,79 @@
4
4
  */
5
5
 
6
6
  export function getCookies(headers: Headers): Record<string, string> {
7
- const cookieHeader = headers.get("cookie") || "";
8
- const cookies: Record<string, string> = {};
9
- for (const pair of cookieHeader.split(";")) {
10
- const [key, ...rest] = pair.trim().split("=");
11
- if (key) {
12
- cookies[key.trim()] = decodeURIComponent(rest.join("=").trim());
13
- }
14
- }
15
- return cookies;
7
+ const cookieHeader = headers.get("cookie") || "";
8
+ const cookies: Record<string, string> = {};
9
+ for (const pair of cookieHeader.split(";")) {
10
+ const [key, ...rest] = pair.trim().split("=");
11
+ if (key) {
12
+ cookies[key.trim()] = decodeURIComponent(rest.join("=").trim());
13
+ }
14
+ }
15
+ return cookies;
16
16
  }
17
17
 
18
18
  export function setCookie(
19
- headers: Headers,
20
- options: {
21
- name: string;
22
- value: string;
23
- path?: string;
24
- expires?: Date;
25
- maxAge?: number;
26
- httpOnly?: boolean;
27
- secure?: boolean;
28
- sameSite?: "Strict" | "Lax" | "None";
29
- }
19
+ headers: Headers,
20
+ options: {
21
+ name: string;
22
+ value: string;
23
+ path?: string;
24
+ expires?: Date;
25
+ maxAge?: number;
26
+ httpOnly?: boolean;
27
+ secure?: boolean;
28
+ sameSite?: "Strict" | "Lax" | "None";
29
+ },
30
30
  ) {
31
- const parts = [`${options.name}=${encodeURIComponent(options.value)}`];
32
- if (options.path) parts.push(`Path=${options.path}`);
33
- if (options.expires) parts.push(`Expires=${options.expires.toUTCString()}`);
34
- if (options.maxAge !== undefined) parts.push(`Max-Age=${options.maxAge}`);
35
- if (options.httpOnly) parts.push("HttpOnly");
36
- if (options.secure) parts.push("Secure");
37
- if (options.sameSite) parts.push(`SameSite=${options.sameSite}`);
31
+ const parts = [`${options.name}=${encodeURIComponent(options.value)}`];
32
+ if (options.path) parts.push(`Path=${options.path}`);
33
+ if (options.expires) parts.push(`Expires=${options.expires.toUTCString()}`);
34
+ if (options.maxAge !== undefined) parts.push(`Max-Age=${options.maxAge}`);
35
+ if (options.httpOnly) parts.push("HttpOnly");
36
+ if (options.secure) parts.push("Secure");
37
+ if (options.sameSite) parts.push(`SameSite=${options.sameSite}`);
38
38
 
39
- headers.append("Set-Cookie", parts.join("; "));
39
+ headers.append("Set-Cookie", parts.join("; "));
40
40
  }
41
41
 
42
42
  export interface Cookie {
43
- name: string;
44
- value: string;
45
- path?: string;
46
- expires?: Date;
47
- maxAge?: number;
48
- httpOnly?: boolean;
49
- secure?: boolean;
50
- sameSite?: "Strict" | "Lax" | "None";
43
+ name: string;
44
+ value: string;
45
+ path?: string;
46
+ expires?: Date;
47
+ maxAge?: number;
48
+ httpOnly?: boolean;
49
+ secure?: boolean;
50
+ sameSite?: "Strict" | "Lax" | "None";
51
51
  }
52
52
 
53
53
  export function getSetCookies(headers: Headers): Cookie[] {
54
- const cookies: Cookie[] = [];
55
- const setCookieHeaders = headers.getSetCookie?.() ?? [];
56
- for (const header of setCookieHeaders) {
57
- const parts = header.split(";").map((p) => p.trim());
58
- const [nameValue, ...attrs] = parts;
59
- const [name, ...rest] = nameValue.split("=");
60
- const value = rest.join("=");
61
- const cookie: Cookie = { name: name.trim(), value };
62
- for (const attr of attrs) {
63
- const [k, v] = attr.split("=");
64
- const key = k.trim().toLowerCase();
65
- if (key === "path") cookie.path = v?.trim();
66
- if (key === "httponly") cookie.httpOnly = true;
67
- if (key === "secure") cookie.secure = true;
68
- if (key === "samesite") cookie.sameSite = v?.trim() as any;
69
- if (key === "max-age") cookie.maxAge = Number(v?.trim());
70
- }
71
- cookies.push(cookie);
72
- }
73
- return cookies;
54
+ const cookies: Cookie[] = [];
55
+ const setCookieHeaders = headers.getSetCookie?.() ?? [];
56
+ for (const header of setCookieHeaders) {
57
+ const parts = header.split(";").map((p) => p.trim());
58
+ const [nameValue, ...attrs] = parts;
59
+ const [name, ...rest] = nameValue.split("=");
60
+ const value = rest.join("=");
61
+ const cookie: Cookie = { name: name.trim(), value };
62
+ for (const attr of attrs) {
63
+ const [k, v] = attr.split("=");
64
+ const key = k.trim().toLowerCase();
65
+ if (key === "path") cookie.path = v?.trim();
66
+ if (key === "httponly") cookie.httpOnly = true;
67
+ if (key === "secure") cookie.secure = true;
68
+ if (key === "samesite") cookie.sameSite = v?.trim() as any;
69
+ if (key === "max-age") cookie.maxAge = Number(v?.trim());
70
+ }
71
+ cookies.push(cookie);
72
+ }
73
+ return cookies;
74
74
  }
75
75
 
76
- export function debounce<T extends (...args: any[]) => void>(
77
- fn: T,
78
- delay: number
79
- ): T {
80
- let timer: ReturnType<typeof setTimeout>;
81
- return ((...args: any[]) => {
82
- clearTimeout(timer);
83
- timer = setTimeout(() => fn(...args), delay);
84
- }) as T;
76
+ export function debounce<T extends (...args: any[]) => void>(fn: T, delay: number): T {
77
+ let timer: ReturnType<typeof setTimeout>;
78
+ return ((...args: any[]) => {
79
+ clearTimeout(timer);
80
+ timer = setTimeout(() => fn(...args), delay);
81
+ }) as T;
85
82
  }