@shopify/hydrogen 0.23.0 → 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 (74) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +5 -8
  3. package/dist/esnext/components/CartLineProvider/context.d.ts +12 -2
  4. package/dist/esnext/components/CartProvider/CartProvider.client.js +2 -5
  5. package/dist/esnext/components/CartProvider/cart-queries.d.ts +1 -1
  6. package/dist/esnext/components/CartProvider/cart-queries.js +11 -0
  7. package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +11 -1
  8. package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +11 -1
  9. package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +11 -1
  10. package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +11 -1
  11. package/dist/esnext/components/CartProvider/graphql/CartFragment.d.ts +11 -1
  12. package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +11 -1
  13. package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +11 -1
  14. package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +11 -1
  15. package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +11 -1
  16. package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +11 -1
  17. package/dist/esnext/components/CartProvider/hooks.client.js +3 -5
  18. package/dist/esnext/components/CartProvider/types.d.ts +2 -0
  19. package/dist/esnext/components/ProductOptionsProvider/ProductOptionsProvider.client.js +6 -5
  20. package/dist/esnext/entry-server.js +2 -2
  21. package/dist/esnext/foundation/Analytics/ClientAnalytics.js +4 -4
  22. package/dist/esnext/foundation/Cache/strategies/index.d.ts +1 -0
  23. package/dist/esnext/foundation/Cache/strategies/index.js +1 -1
  24. package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +1 -0
  25. package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.js +2 -1
  26. package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +1 -2
  27. package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +16 -19
  28. package/dist/esnext/foundation/useQuery/hooks.d.ts +1 -0
  29. package/dist/esnext/foundation/useQuery/hooks.js +16 -2
  30. package/dist/esnext/foundation/useRequestContext/index.d.ts +15 -0
  31. package/dist/esnext/foundation/useRequestContext/index.js +23 -0
  32. package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +12 -2
  33. package/dist/esnext/hooks/useProductOptions/types.d.ts +1 -1
  34. package/dist/esnext/index.d.ts +3 -0
  35. package/dist/esnext/index.js +1 -0
  36. package/dist/esnext/storefront-api-types.d.ts +10 -339
  37. package/dist/esnext/version.d.ts +1 -1
  38. package/dist/esnext/version.js +1 -1
  39. package/dist/node/components/CartLinePrice/CartLinePrice.client.js +5 -8
  40. package/dist/node/components/CartLineProvider/context.d.ts +12 -2
  41. package/dist/node/components/CartProvider/CartProvider.client.js +2 -5
  42. package/dist/node/components/CartProvider/cart-queries.d.ts +1 -1
  43. package/dist/node/components/CartProvider/cart-queries.js +11 -0
  44. package/dist/node/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +11 -1
  45. package/dist/node/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +11 -1
  46. package/dist/node/components/CartProvider/graphql/CartCreateMutation.d.ts +11 -1
  47. package/dist/node/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +11 -1
  48. package/dist/node/components/CartProvider/graphql/CartFragment.d.ts +11 -1
  49. package/dist/node/components/CartProvider/graphql/CartLineAddMutation.d.ts +11 -1
  50. package/dist/node/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +11 -1
  51. package/dist/node/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +11 -1
  52. package/dist/node/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +11 -1
  53. package/dist/node/components/CartProvider/graphql/CartQuery.d.ts +11 -1
  54. package/dist/node/components/CartProvider/hooks.client.js +2 -4
  55. package/dist/node/components/CartProvider/types.d.ts +2 -0
  56. package/dist/node/components/ProductOptionsProvider/ProductOptionsProvider.client.js +6 -5
  57. package/dist/node/entry-server.js +2 -2
  58. package/dist/node/foundation/Analytics/ClientAnalytics.js +4 -4
  59. package/dist/node/foundation/Cache/strategies/index.d.ts +1 -0
  60. package/dist/node/foundation/Cache/strategies/index.js +3 -3
  61. package/dist/node/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +1 -0
  62. package/dist/node/foundation/HydrogenRequest/HydrogenRequest.server.js +2 -1
  63. package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +1 -2
  64. package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +16 -19
  65. package/dist/node/foundation/useQuery/hooks.d.ts +1 -0
  66. package/dist/node/foundation/useQuery/hooks.js +17 -2
  67. package/dist/node/hooks/useCartLine/useCartLine.d.ts +12 -2
  68. package/dist/node/hooks/useProductOptions/types.d.ts +1 -1
  69. package/dist/node/storefront-api-types.d.ts +10 -339
  70. package/dist/node/version.d.ts +1 -1
  71. package/dist/node/version.js +1 -1
  72. package/package.json +1 -1
  73. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +36 -6
  74. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +36 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1489](https://github.com/Shopify/hydrogen/pull/1489) [`e2ee2d45`](https://github.com/Shopify/hydrogen/commit/e2ee2d4575613ae34727de9c1a6280904bb2e3ff) Thanks [@blittle](https://github.com/blittle)! - In an effort to be performant by default, the [preloaded queries](https://shopify.dev/custom-storefronts/hydrogen/framework/preloaded-queries) are turned on by default when caching is also enabled. By default, each query has caching enabled too, so `preload` will on universally by default.
8
+
9
+ * [#1237](https://github.com/Shopify/hydrogen/pull/1237) [`356e75f3`](https://github.com/Shopify/hydrogen/commit/356e75f351c04ff393e996c34632005331ec0872) Thanks [@frehner](https://github.com/frehner)! - Updated Cart queries in two ways, one of which requires you to be using Storefront API `2022-07`:
10
+
11
+ 1. [`CartLine`](https://shopify.dev/api/storefront/2022-04/objects/CartLine#fields) now uses [`CartLineEstimatedCost`'s `totalAmount`](https://shopify.dev/api/storefront/2022-04/objects/CartLineEstimatedCost) field for calculating the Line's total, instead of doing it manually.
12
+ 2. Cart now uses [`totalQuantity`](https://shopify.dev/api/storefront/2022-07/objects/Cart#field-cart-totalquantity) for calculating how many items are in the cart, instead of doing this manually. **Note that this feature is only available in Storefront API `2022-07` and newer.**
13
+
14
+ ### Patch Changes
15
+
16
+ - [#1473](https://github.com/Shopify/hydrogen/pull/1473) [`a7f3b4bf`](https://github.com/Shopify/hydrogen/commit/a7f3b4bfe0d66fb0440dff3d641a181372de313a) Thanks [@frandiox](https://github.com/frandiox)! - Reduce CPU consumption when rendering React Server Components.
17
+
18
+ * [#1453](https://github.com/Shopify/hydrogen/pull/1453) [`84b9e6d3`](https://github.com/Shopify/hydrogen/commit/84b9e6d3516a74f94fab691d6ff7605623351f1e) Thanks [@jplhomer](https://github.com/jplhomer)! - Update `setSelectedVariant` types to allow `null` to be passed.
19
+
20
+ - [#1484](https://github.com/Shopify/hydrogen/pull/1484) [`990bfd8b`](https://github.com/Shopify/hydrogen/commit/990bfd8b928425f2685901c1a02b686354d18d4d) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Fix ClientAnalytics losing subscriber object when passed as a param
21
+
22
+ * [#1509](https://github.com/Shopify/hydrogen/pull/1509) [`05081b01`](https://github.com/Shopify/hydrogen/commit/05081b01283c023e9c751c04ed496003daf47091) Thanks [@jplhomer](https://github.com/jplhomer)! - Fix `<BuyNowButton>` so it can be rendered without being nested in a `<CartProvider>`
23
+
24
+ - [#1469](https://github.com/Shopify/hydrogen/pull/1469) [`07d45290`](https://github.com/Shopify/hydrogen/commit/07d452905492bfa1bd58c681b8d56407fdc4716b) Thanks [@frandiox](https://github.com/frandiox)! - Fix path resolution when using aliases in server components.
25
+
26
+ * [#1471](https://github.com/Shopify/hydrogen/pull/1471) [`5b4e08df`](https://github.com/Shopify/hydrogen/commit/5b4e08df97dd2343452b0d1f7ff59ac5bbf98d32) Thanks [@frandiox](https://github.com/frandiox)! - Added an experimental hook `useRequestContext` that provides server-only context for third party integrations.
27
+
28
+ - [#1486](https://github.com/Shopify/hydrogen/pull/1486) [`a31e007d`](https://github.com/Shopify/hydrogen/commit/a31e007dbc2a1a6ce12e39ffc3f63f45e90abfa7) Thanks [@frehner](https://github.com/frehner)! - Fix `<ProductOptionsProvider/>`'s `setSelectedOptions()` function to update the `selectedVariant` as well
29
+
3
30
  ## 0.23.0
4
31
 
5
32
  ### Minor Changes
@@ -8,14 +8,11 @@ import { Money } from '../Money';
8
8
  export function CartLinePrice(props) {
9
9
  const cartLine = useCartLine();
10
10
  const { priceType = 'regular', ...passthroughProps } = props;
11
- const price = priceType === 'regular'
12
- ? cartLine.merchandise.priceV2
13
- : cartLine.merchandise.compareAtPriceV2;
14
- if (price == null) {
11
+ const moneyV2 = priceType === 'regular'
12
+ ? cartLine.estimatedCost.totalAmount
13
+ : cartLine.estimatedCost.compareAtAmount;
14
+ if (moneyV2 == null) {
15
15
  return null;
16
16
  }
17
- return (React.createElement(Money, { ...passthroughProps, data: {
18
- amount: `${parseFloat(price.amount) * cartLine.quantity}`,
19
- currencyCode: price.currencyCode,
20
- } }));
17
+ return React.createElement(Money, { ...passthroughProps, data: moneyV2 });
21
18
  }
@@ -4,15 +4,25 @@ export declare const CartLineContext: import("react").Context<({
4
4
  attributes: ({
5
5
  __typename?: "Attribute" | undefined;
6
6
  } & Pick<import("../../storefront-api-types").Attribute, "key" | "value">)[];
7
+ estimatedCost: {
8
+ __typename?: "CartLineEstimatedCost" | undefined;
9
+ } & {
10
+ totalAmount: {
11
+ __typename?: "MoneyV2" | undefined;
12
+ } & Pick<import("../../storefront-api-types").MoneyV2, "amount" | "currencyCode">;
13
+ compareAtAmount?: import("../../storefront-api-types").Maybe<{
14
+ __typename?: "MoneyV2" | undefined;
15
+ } & Pick<import("../../storefront-api-types").MoneyV2, "amount" | "currencyCode">> | undefined;
16
+ };
7
17
  merchandise: {
8
18
  __typename?: "ProductVariant" | undefined;
9
19
  } & Pick<import("../../storefront-api-types").ProductVariant, "id" | "title" | "availableForSale" | "requiresShipping"> & {
10
20
  compareAtPriceV2?: import("../../storefront-api-types").Maybe<{
11
21
  __typename?: "MoneyV2" | undefined;
12
- } & Pick<import("../../storefront-api-types").MoneyV2, "currencyCode" | "amount">> | undefined;
22
+ } & Pick<import("../../storefront-api-types").MoneyV2, "amount" | "currencyCode">> | undefined;
13
23
  priceV2: {
14
24
  __typename?: "MoneyV2" | undefined;
15
- } & Pick<import("../../storefront-api-types").MoneyV2, "currencyCode" | "amount">;
25
+ } & Pick<import("../../storefront-api-types").MoneyV2, "amount" | "currencyCode">;
16
26
  image?: import("../../storefront-api-types").Maybe<{
17
27
  __typename?: "Image" | undefined;
18
28
  } & Pick<import("../../storefront-api-types").Image, "id" | "height" | "width" | "url" | "altText">> | undefined;
@@ -453,6 +453,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
453
453
  // eslint-disable-next-line react-hooks/exhaustive-deps
454
454
  }, [countryCode, customerAccessToken]);
455
455
  const cartContextValue = useMemo(() => {
456
+ var _a, _b;
456
457
  return {
457
458
  ...('cart' in state
458
459
  ? state.cart
@@ -463,11 +464,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
463
464
  }),
464
465
  status: state.status,
465
466
  error: 'error' in state ? state.error : undefined,
466
- totalQuantity: 'cart' in state
467
- ? state.cart.lines.reduce((previous, current) => {
468
- return previous + current.quantity;
469
- }, 0)
470
- : 0,
467
+ totalQuantity: 'cart' in state ? (_b = (_a = state === null || state === void 0 ? void 0 : state.cart) === null || _a === void 0 ? void 0 : _a.totalQuantity) !== null && _b !== void 0 ? _b : 0 : 0,
471
468
  cartCreate,
472
469
  linesAdd(lines) {
473
470
  if ('cart' in state && state.cart.id) {
@@ -7,4 +7,4 @@ export declare const CartBuyerIdentityUpdate: (cartFragment: string) => string;
7
7
  export declare const CartAttributesUpdate: (cartFragment: string) => string;
8
8
  export declare const CartDiscountCodesUpdate: (cartFragment: string) => string;
9
9
  export declare const CartQuery: (cartFragment: string) => string;
10
- export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n estimatedCost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
10
+ export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n estimatedCost {\n totalAmount {\n amount\n currencyCode\n }\n compareAtAmount {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n estimatedCost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
@@ -104,6 +104,7 @@ export const defaultCartFragment = `
104
104
  fragment CartFragment on Cart {
105
105
  id
106
106
  checkoutUrl
107
+ totalQuantity
107
108
  buyerIdentity {
108
109
  countryCode
109
110
  customer {
@@ -125,6 +126,16 @@ fragment CartFragment on Cart {
125
126
  key
126
127
  value
127
128
  }
129
+ estimatedCost {
130
+ totalAmount {
131
+ amount
132
+ currencyCode
133
+ }
134
+ compareAtAmount {
135
+ amount
136
+ currencyCode
137
+ }
138
+ }
128
139
  merchandise {
129
140
  ... on ProductVariant {
130
141
  id
@@ -17,7 +17,7 @@ export declare type CartAttributesUpdateMutation = {
17
17
  } & {
18
18
  cart?: Types.Maybe<{
19
19
  __typename?: 'Cart';
20
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
20
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
21
21
  buyerIdentity: {
22
22
  __typename?: 'CartBuyerIdentity';
23
23
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -37,6 +37,16 @@ export declare type CartAttributesUpdateMutation = {
37
37
  attributes: Array<{
38
38
  __typename?: 'Attribute';
39
39
  } & Pick<Types.Attribute, 'key' | 'value'>>;
40
+ estimatedCost: {
41
+ __typename?: 'CartLineEstimatedCost';
42
+ } & {
43
+ totalAmount: {
44
+ __typename?: 'MoneyV2';
45
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
46
+ compareAtAmount?: Types.Maybe<{
47
+ __typename?: 'MoneyV2';
48
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
49
+ };
40
50
  merchandise: {
41
51
  __typename?: 'ProductVariant';
42
52
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -17,7 +17,7 @@ export declare type CartBuyerIdentityUpdateMutation = {
17
17
  } & {
18
18
  cart?: Types.Maybe<{
19
19
  __typename?: 'Cart';
20
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
20
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
21
21
  buyerIdentity: {
22
22
  __typename?: 'CartBuyerIdentity';
23
23
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -37,6 +37,16 @@ export declare type CartBuyerIdentityUpdateMutation = {
37
37
  attributes: Array<{
38
38
  __typename?: 'Attribute';
39
39
  } & Pick<Types.Attribute, 'key' | 'value'>>;
40
+ estimatedCost: {
41
+ __typename?: 'CartLineEstimatedCost';
42
+ } & {
43
+ totalAmount: {
44
+ __typename?: 'MoneyV2';
45
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
46
+ compareAtAmount?: Types.Maybe<{
47
+ __typename?: 'MoneyV2';
48
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
49
+ };
40
50
  merchandise: {
41
51
  __typename?: 'ProductVariant';
42
52
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -16,7 +16,7 @@ export declare type CartCreateMutation = {
16
16
  } & {
17
17
  cart?: Types.Maybe<{
18
18
  __typename?: 'Cart';
19
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
19
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
20
20
  buyerIdentity: {
21
21
  __typename?: 'CartBuyerIdentity';
22
22
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -36,6 +36,16 @@ export declare type CartCreateMutation = {
36
36
  attributes: Array<{
37
37
  __typename?: 'Attribute';
38
38
  } & Pick<Types.Attribute, 'key' | 'value'>>;
39
+ estimatedCost: {
40
+ __typename?: 'CartLineEstimatedCost';
41
+ } & {
42
+ totalAmount: {
43
+ __typename?: 'MoneyV2';
44
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
45
+ compareAtAmount?: Types.Maybe<{
46
+ __typename?: 'MoneyV2';
47
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
48
+ };
39
49
  merchandise: {
40
50
  __typename?: 'ProductVariant';
41
51
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -17,7 +17,7 @@ export declare type CartDiscountCodesUpdateMutation = {
17
17
  } & {
18
18
  cart?: Types.Maybe<{
19
19
  __typename?: 'Cart';
20
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
20
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
21
21
  buyerIdentity: {
22
22
  __typename?: 'CartBuyerIdentity';
23
23
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -37,6 +37,16 @@ export declare type CartDiscountCodesUpdateMutation = {
37
37
  attributes: Array<{
38
38
  __typename?: 'Attribute';
39
39
  } & Pick<Types.Attribute, 'key' | 'value'>>;
40
+ estimatedCost: {
41
+ __typename?: 'CartLineEstimatedCost';
42
+ } & {
43
+ totalAmount: {
44
+ __typename?: 'MoneyV2';
45
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
46
+ compareAtAmount?: Types.Maybe<{
47
+ __typename?: 'MoneyV2';
48
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
49
+ };
40
50
  merchandise: {
41
51
  __typename?: 'ProductVariant';
42
52
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -5,7 +5,7 @@
5
5
  import * as Types from '../../../storefront-api-types';
6
6
  export declare type CartFragmentFragment = {
7
7
  __typename?: 'Cart';
8
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
8
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
9
9
  buyerIdentity: {
10
10
  __typename?: 'CartBuyerIdentity';
11
11
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -25,6 +25,16 @@ export declare type CartFragmentFragment = {
25
25
  attributes: Array<{
26
26
  __typename?: 'Attribute';
27
27
  } & Pick<Types.Attribute, 'key' | 'value'>>;
28
+ estimatedCost: {
29
+ __typename?: 'CartLineEstimatedCost';
30
+ } & {
31
+ totalAmount: {
32
+ __typename?: 'MoneyV2';
33
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
34
+ compareAtAmount?: Types.Maybe<{
35
+ __typename?: 'MoneyV2';
36
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
37
+ };
28
38
  merchandise: {
29
39
  __typename?: 'ProductVariant';
30
40
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -17,7 +17,7 @@ export declare type CartLineAddMutation = {
17
17
  } & {
18
18
  cart?: Types.Maybe<{
19
19
  __typename?: 'Cart';
20
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
20
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
21
21
  buyerIdentity: {
22
22
  __typename?: 'CartBuyerIdentity';
23
23
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -37,6 +37,16 @@ export declare type CartLineAddMutation = {
37
37
  attributes: Array<{
38
38
  __typename?: 'Attribute';
39
39
  } & Pick<Types.Attribute, 'key' | 'value'>>;
40
+ estimatedCost: {
41
+ __typename?: 'CartLineEstimatedCost';
42
+ } & {
43
+ totalAmount: {
44
+ __typename?: 'MoneyV2';
45
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
46
+ compareAtAmount?: Types.Maybe<{
47
+ __typename?: 'MoneyV2';
48
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
49
+ };
40
50
  merchandise: {
41
51
  __typename?: 'ProductVariant';
42
52
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -17,7 +17,7 @@ export declare type CartLineRemoveMutation = {
17
17
  } & {
18
18
  cart?: Types.Maybe<{
19
19
  __typename?: 'Cart';
20
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
20
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
21
21
  buyerIdentity: {
22
22
  __typename?: 'CartBuyerIdentity';
23
23
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -37,6 +37,16 @@ export declare type CartLineRemoveMutation = {
37
37
  attributes: Array<{
38
38
  __typename?: 'Attribute';
39
39
  } & Pick<Types.Attribute, 'key' | 'value'>>;
40
+ estimatedCost: {
41
+ __typename?: 'CartLineEstimatedCost';
42
+ } & {
43
+ totalAmount: {
44
+ __typename?: 'MoneyV2';
45
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
46
+ compareAtAmount?: Types.Maybe<{
47
+ __typename?: 'MoneyV2';
48
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
49
+ };
40
50
  merchandise: {
41
51
  __typename?: 'ProductVariant';
42
52
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -17,7 +17,7 @@ export declare type CartLineUpdateMutation = {
17
17
  } & {
18
18
  cart?: Types.Maybe<{
19
19
  __typename?: 'Cart';
20
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
20
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
21
21
  buyerIdentity: {
22
22
  __typename?: 'CartBuyerIdentity';
23
23
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -37,6 +37,16 @@ export declare type CartLineUpdateMutation = {
37
37
  attributes: Array<{
38
38
  __typename?: 'Attribute';
39
39
  } & Pick<Types.Attribute, 'key' | 'value'>>;
40
+ estimatedCost: {
41
+ __typename?: 'CartLineEstimatedCost';
42
+ } & {
43
+ totalAmount: {
44
+ __typename?: 'MoneyV2';
45
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
46
+ compareAtAmount?: Types.Maybe<{
47
+ __typename?: 'MoneyV2';
48
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
49
+ };
40
50
  merchandise: {
41
51
  __typename?: 'ProductVariant';
42
52
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -17,7 +17,7 @@ export declare type CartNoteUpdateMutation = {
17
17
  } & {
18
18
  cart?: Types.Maybe<{
19
19
  __typename?: 'Cart';
20
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
20
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
21
21
  buyerIdentity: {
22
22
  __typename?: 'CartBuyerIdentity';
23
23
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -37,6 +37,16 @@ export declare type CartNoteUpdateMutation = {
37
37
  attributes: Array<{
38
38
  __typename?: 'Attribute';
39
39
  } & Pick<Types.Attribute, 'key' | 'value'>>;
40
+ estimatedCost: {
41
+ __typename?: 'CartLineEstimatedCost';
42
+ } & {
43
+ totalAmount: {
44
+ __typename?: 'MoneyV2';
45
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
46
+ compareAtAmount?: Types.Maybe<{
47
+ __typename?: 'MoneyV2';
48
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
49
+ };
40
50
  merchandise: {
41
51
  __typename?: 'ProductVariant';
42
52
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -13,7 +13,7 @@ export declare type CartQueryQuery = {
13
13
  } & {
14
14
  cart?: Types.Maybe<{
15
15
  __typename?: 'Cart';
16
- } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'note'> & {
16
+ } & Pick<Types.Cart, 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'> & {
17
17
  buyerIdentity: {
18
18
  __typename?: 'CartBuyerIdentity';
19
19
  } & Pick<Types.CartBuyerIdentity, 'countryCode' | 'email' | 'phone'> & {
@@ -33,6 +33,16 @@ export declare type CartQueryQuery = {
33
33
  attributes: Array<{
34
34
  __typename?: 'Attribute';
35
35
  } & Pick<Types.Attribute, 'key' | 'value'>>;
36
+ estimatedCost: {
37
+ __typename?: 'CartLineEstimatedCost';
38
+ } & {
39
+ totalAmount: {
40
+ __typename?: 'MoneyV2';
41
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
42
+ compareAtAmount?: Types.Maybe<{
43
+ __typename?: 'MoneyV2';
44
+ } & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
45
+ };
36
46
  merchandise: {
37
47
  __typename?: 'ProductVariant';
38
48
  } & Pick<Types.ProductVariant, 'id' | 'availableForSale' | 'requiresShipping' | 'title'> & {
@@ -1,8 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
  import { useShop } from '../../foundation';
3
3
  import { flattenConnection } from '../../utilities';
4
- import { CartCreate } from './cart-queries';
5
- import { useCart } from '../../hooks/useCart';
4
+ import { CartCreate, defaultCartFragment } from './cart-queries';
6
5
  export function useCartFetch() {
7
6
  const { storeDomain, storefrontApiVersion, storefrontToken } = useShop();
8
7
  return React.useCallback(({ query, variables, }) => {
@@ -29,7 +28,6 @@ export function useCartFetch() {
29
28
  }, [storeDomain, storefrontApiVersion, storefrontToken]);
30
29
  }
31
30
  export function useInstantCheckout() {
32
- const { cartFragment } = useCart();
33
31
  const [cart, updateCart] = useState();
34
32
  const [checkoutUrl, updateCheckoutUrl] = useState();
35
33
  const [error, updateError] = useState();
@@ -37,7 +35,7 @@ export function useInstantCheckout() {
37
35
  const createInstantCheckout = React.useCallback(async (cartInput) => {
38
36
  var _a, _b;
39
37
  const { data, error } = await fetch({
40
- query: CartCreate(cartFragment),
38
+ query: CartCreate(defaultCartFragment),
41
39
  variables: {
42
40
  input: cartInput,
43
41
  },
@@ -57,6 +55,6 @@ export function useInstantCheckout() {
57
55
  });
58
56
  updateCheckoutUrl(dataCart.checkoutUrl);
59
57
  }
60
- }, [cartFragment, fetch]);
58
+ }, [fetch]);
61
59
  return { cart, checkoutUrl, error, createInstantCheckout };
62
60
  }
@@ -18,6 +18,8 @@ export interface Cart {
18
18
  discountCodes?: CartFragmentFragment['discountCodes'];
19
19
  /** The estimate cost for the cart, including the subtotal, total, taxes, and duties. */
20
20
  estimatedCost?: CartFragmentFragment['estimatedCost'];
21
+ /** The total number of items in the cart, across all lines. If there are no lines, then the value is 0. */
22
+ totalQuantity: number;
21
23
  }
22
24
  export interface CartWithActions extends Cart {
23
25
  /** The status of the cart. This returns 'uninitialized' when the cart is not yet created, `creating` when the cart is being created, `fetching` when an existing cart is being fetched, `updating` when the cart is updating, and `idle` when the cart isn't being created or updated. */
@@ -34,11 +34,12 @@ export function ProductOptionsProvider({ children, data: product, initialVariant
34
34
  * Allow the developer to select an option.
35
35
  */
36
36
  const setSelectedOption = useCallback((name, value) => {
37
- setSelectedOptions((selectedOptions) => ({
38
- ...selectedOptions,
39
- [name]: value,
40
- }));
41
- }, [setSelectedOptions]);
37
+ setSelectedOptions((selectedOptions) => {
38
+ const opts = { ...selectedOptions, [name]: value };
39
+ setSelectedVariant(getSelectedVariant(variants, opts));
40
+ return opts;
41
+ });
42
+ }, [setSelectedOptions, variants]);
42
43
  const isOptionInStock = useCallback((option, value) => {
43
44
  var _a;
44
45
  const proposedVariant = getSelectedVariant(variants, {
@@ -133,7 +133,7 @@ async function runSSR({ rsc, state, request, response, nodeResponse, template, n
133
133
  const RscConsumer = () => rscResponse.readRoot();
134
134
  const { noScriptTemplate, bootstrapScripts, bootstrapModules } = stripScriptsFromTemplate(template);
135
135
  const AppSSR = (React.createElement(Html, { template: response.canStream() ? noScriptTemplate : template, hydrogenConfig: request.ctx.hydrogenConfig },
136
- React.createElement(ServerRequestProvider, { request: request, isRSC: false },
136
+ React.createElement(ServerRequestProvider, { request: request },
137
137
  React.createElement(ServerPropsProvider, { initialServerProps: state, setServerPropsForRsc: () => { } },
138
138
  React.createElement(PreloadQueries, { request: request },
139
139
  React.createElement(Suspense, { fallback: null },
@@ -344,7 +344,7 @@ async function runSSR({ rsc, state, request, response, nodeResponse, template, n
344
344
  function runRSC({ App, state, log, request, response }) {
345
345
  const serverProps = { ...state, request, response, log };
346
346
  request.ctx.router.serverProps = serverProps;
347
- const AppRSC = (React.createElement(ServerRequestProvider, { request: request, isRSC: true },
347
+ const AppRSC = (React.createElement(ServerRequestProvider, { request: request },
348
348
  React.createElement(PreloadQueries, { request: request },
349
349
  React.createElement(App, { ...serverProps }),
350
350
  React.createElement(Suspense, { fallback: null },
@@ -33,7 +33,6 @@ function publish(eventname, guardDup = false, payload = {}) {
33
33
  if (isInvokedFromServer())
34
34
  return;
35
35
  const namedspacedEventname = getNamedspacedEventname(eventname);
36
- const subs = subscribers[namedspacedEventname];
37
36
  // De-dup events due to re-renders
38
37
  if (guardDup) {
39
38
  const eventGuardTimeout = guardDupEvents[namedspacedEventname];
@@ -41,15 +40,16 @@ function publish(eventname, guardDup = false, payload = {}) {
41
40
  clearTimeout(eventGuardTimeout);
42
41
  }
43
42
  const namespacedTimeout = setTimeout(() => {
44
- publishEvent(namedspacedEventname, subs, mergeDeep(pageAnalyticsData, payload));
43
+ publishEvent(namedspacedEventname, mergeDeep(pageAnalyticsData, payload));
45
44
  }, 100);
46
45
  guardDupEvents[namedspacedEventname] = namespacedTimeout;
47
46
  }
48
47
  else {
49
- publishEvent(namedspacedEventname, subs, mergeDeep(pageAnalyticsData, payload));
48
+ publishEvent(namedspacedEventname, mergeDeep(pageAnalyticsData, payload));
50
49
  }
51
50
  }
52
- function publishEvent(eventname, subs, payload) {
51
+ function publishEvent(eventname, payload) {
52
+ const subs = subscribers[eventname];
53
53
  if (!isFirstPageViewSent && eventname === eventNames.PAGE_VIEW) {
54
54
  isFirstPageViewSent = true;
55
55
  }
@@ -1,4 +1,5 @@
1
1
  import type { CachingStrategy, AllCacheOptions, NoStoreStrategy } from '../../../types';
2
+ export declare const NO_STORE = "no-store";
2
3
  export declare function generateCacheControlHeader(cacheOptions: CachingStrategy): string;
3
4
  export declare function NoStore(): NoStoreStrategy;
4
5
  export declare function CacheSeconds(overrideOptions?: CachingStrategy): AllCacheOptions;
@@ -1,6 +1,6 @@
1
1
  const PUBLIC = 'public';
2
2
  const PRIVATE = 'private';
3
- const NO_STORE = 'no-store';
3
+ export const NO_STORE = 'no-store';
4
4
  const optionMapping = {
5
5
  maxAge: 'max-age',
6
6
  staleWhileRevalidate: 'stale-while-revalidate',
@@ -44,6 +44,7 @@ export declare class HydrogenRequest extends Request {
44
44
  buyerIpHeader?: string;
45
45
  session?: SessionSyncApi;
46
46
  runtime?: RuntimeContext;
47
+ scopes: Map<string, Record<string, any>>;
47
48
  [key: string]: any;
48
49
  };
49
50
  constructor(input: any);
@@ -48,6 +48,7 @@ export class HydrogenRequest extends Request {
48
48
  normalizedRscUrl: this.normalizedUrl,
49
49
  },
50
50
  preloadQueries: new Map(),
51
+ scopes: new Map(),
51
52
  };
52
53
  this.cookies = this.parseCookies();
53
54
  }
@@ -67,7 +68,7 @@ export class HydrogenRequest extends Request {
67
68
  if (typeof query.preload === 'string' && query.preload === PRELOAD_ALL) {
68
69
  saveToPreloadAllPreload(query);
69
70
  }
70
- else if (query.preload) {
71
+ else {
71
72
  this.ctx.preloadQueries.set(hashKey(query.key), query);
72
73
  }
73
74
  }
@@ -1,11 +1,10 @@
1
1
  import type { PreloadQueriesByURL, HydrogenRequest } from '../HydrogenRequest/HydrogenRequest.server';
2
2
  import type { QueryKey } from '../../types';
3
3
  declare type ServerRequestProviderProps = {
4
- isRSC: boolean;
5
4
  request: HydrogenRequest;
6
5
  children: JSX.Element;
7
6
  };
8
- export declare function ServerRequestProvider({ isRSC, request, children, }: ServerRequestProviderProps): JSX.Element;
7
+ export declare function ServerRequestProvider({ request, children, }: ServerRequestProviderProps): JSX.Element;
9
8
  export declare function useServerRequest(): HydrogenRequest;
10
9
  declare type RequestCacheResult<T> = {
11
10
  data: T;