@shopify/hydrogen 0.5.1 → 0.6.1

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 (186) hide show
  1. package/README.md +1 -1
  2. package/dist/esnext/components/CartLineImage/CartLineImage.client.d.ts +1 -1
  3. package/dist/esnext/components/CartLineImage/CartLineImage.client.js +1 -1
  4. package/dist/esnext/components/CartLineProvider/context.d.ts +1 -1
  5. package/dist/esnext/components/CartLineProvider/index.d.ts +1 -1
  6. package/dist/esnext/components/CartLineProvider/index.js +1 -1
  7. package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.js +3 -2
  8. package/dist/esnext/components/CartProvider/CartProvider.client.js +52 -23
  9. package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +1 -0
  10. package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +1 -0
  11. package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +1 -0
  12. package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +1 -0
  13. package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +1 -0
  14. package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +1 -0
  15. package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +1 -0
  16. package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +1 -0
  17. package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +1 -0
  18. package/dist/esnext/components/CartProvider/hooks.d.ts +0 -11
  19. package/dist/esnext/components/CartProvider/hooks.js +0 -54
  20. package/dist/esnext/components/CartProvider/index.d.ts +12 -1
  21. package/dist/esnext/components/CartProvider/index.js +12 -1
  22. package/dist/esnext/components/Image/Image.d.ts +2 -2
  23. package/dist/esnext/components/Image/Image.js +1 -1
  24. package/dist/esnext/components/Image/ImageFragment.d.ts +1 -1
  25. package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +1 -1
  26. package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +5 -2
  27. package/dist/esnext/components/LocalizationProvider/index.d.ts +2 -1
  28. package/dist/esnext/components/LocalizationProvider/index.js +2 -1
  29. package/dist/esnext/components/Model3D/Model3D.client.d.ts +1 -1
  30. package/dist/esnext/components/Model3D/Model3D.client.js +2 -2
  31. package/dist/esnext/components/Model3D/Model3DFragment.d.ts +1 -1
  32. package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +1 -1
  33. package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +1 -1
  34. package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +1 -1
  35. package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.js +1 -1
  36. package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.d.ts +1 -1
  37. package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.js +1 -1
  38. package/dist/esnext/components/Video/Video.d.ts +1 -1
  39. package/dist/esnext/components/Video/Video.js +1 -1
  40. package/dist/esnext/components/Video/VideoFragment.d.ts +1 -1
  41. package/dist/esnext/components/index.d.ts +2 -1
  42. package/dist/esnext/components/index.js +2 -1
  43. package/dist/esnext/entry-client.js +2 -1
  44. package/dist/esnext/entry-server.js +12 -5
  45. package/dist/esnext/foundation/Router/ServerStateRouter.client.js +1 -1
  46. package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +2 -1
  47. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.d.ts +1 -1
  48. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.js +1 -1
  49. package/dist/esnext/foundation/useServerState/use-server-state.d.ts +1 -1
  50. package/dist/esnext/foundation/useServerState/use-server-state.js +1 -1
  51. package/dist/esnext/framework/Hydration/react-utils.js +1 -1
  52. package/dist/esnext/framework/cache.js +4 -2
  53. package/dist/esnext/framework/config.d.ts +6 -0
  54. package/dist/esnext/framework/config.js +6 -0
  55. package/dist/esnext/framework/runtime.d.ts +2 -2
  56. package/dist/esnext/framework/runtime.js +4 -3
  57. package/dist/esnext/graphql/graphql-constants.d.ts +31 -30
  58. package/dist/esnext/graphql/graphql-constants.js +62 -60
  59. package/dist/esnext/graphql/types/types.d.ts +234 -56
  60. package/dist/esnext/graphql/types/types.js +22 -0
  61. package/dist/esnext/handle-event.js +64 -71
  62. package/dist/esnext/hooks/useAvailableCountries/index.d.ts +1 -0
  63. package/dist/esnext/hooks/useAvailableCountries/index.js +1 -0
  64. package/dist/esnext/hooks/useAvailableCountries/useAvailableCountries.d.ts +11 -0
  65. package/dist/esnext/{components/LocalizationProvider/hooks.js → hooks/useAvailableCountries/useAvailableCountries.js} +5 -5
  66. package/dist/esnext/hooks/useCart/index.d.ts +1 -0
  67. package/dist/esnext/hooks/useCart/index.js +1 -0
  68. package/dist/esnext/hooks/useCart/useCart.d.ts +4 -0
  69. package/dist/esnext/hooks/useCart/useCart.js +12 -0
  70. package/dist/esnext/hooks/useCartAttributesUpdateCallback/index.d.ts +1 -0
  71. package/dist/esnext/hooks/useCartAttributesUpdateCallback/index.js +1 -0
  72. package/dist/esnext/hooks/useCartAttributesUpdateCallback/useCartAttributesUpdateCallback.d.ts +4 -0
  73. package/dist/esnext/hooks/useCartAttributesUpdateCallback/useCartAttributesUpdateCallback.js +8 -0
  74. package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/index.d.ts +1 -0
  75. package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/index.js +1 -0
  76. package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/useCartBuyerIdentityUpdateCallback.d.ts +4 -0
  77. package/dist/esnext/hooks/useCartBuyerIdentityUpdateCallback/useCartBuyerIdentityUpdateCallback.js +8 -0
  78. package/dist/esnext/hooks/useCartCheckoutUrl/index.d.ts +1 -0
  79. package/dist/esnext/hooks/useCartCheckoutUrl/index.js +1 -0
  80. package/dist/esnext/hooks/useCartCheckoutUrl/useCartCheckoutUrl.d.ts +4 -0
  81. package/dist/esnext/hooks/useCartCheckoutUrl/useCartCheckoutUrl.js +8 -0
  82. package/dist/esnext/hooks/useCartCreateCallback/index.d.ts +1 -0
  83. package/dist/esnext/hooks/useCartCreateCallback/index.js +1 -0
  84. package/dist/esnext/hooks/useCartCreateCallback/useCartCreateCallback.d.ts +4 -0
  85. package/dist/esnext/hooks/useCartCreateCallback/useCartCreateCallback.js +8 -0
  86. package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/index.d.ts +1 -0
  87. package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/index.js +1 -0
  88. package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/useCartDiscountCodesUpdateCallback.d.ts +4 -0
  89. package/dist/esnext/hooks/useCartDiscountCodesUpdateCallback/useCartDiscountCodesUpdateCallback.js +8 -0
  90. package/dist/esnext/hooks/useCartLine/index.d.ts +1 -0
  91. package/dist/esnext/hooks/useCartLine/index.js +1 -0
  92. package/dist/esnext/{components/CartLineProvider/hooks.d.ts → hooks/useCartLine/useCartLine.d.ts} +7 -2
  93. package/dist/esnext/{components/CartLineProvider/hooks.js → hooks/useCartLine/useCartLine.js} +4 -1
  94. package/dist/esnext/hooks/useCartLinesAddCallback/index.d.ts +1 -0
  95. package/dist/esnext/hooks/useCartLinesAddCallback/index.js +1 -0
  96. package/dist/esnext/hooks/useCartLinesAddCallback/useCartLinesAddCallback.d.ts +5 -0
  97. package/dist/esnext/hooks/useCartLinesAddCallback/useCartLinesAddCallback.js +9 -0
  98. package/dist/esnext/hooks/useCartLinesRemoveCallback/index.d.ts +1 -0
  99. package/dist/esnext/hooks/useCartLinesRemoveCallback/index.js +1 -0
  100. package/dist/esnext/hooks/useCartLinesRemoveCallback/useCartLinesRemoveCallback.d.ts +4 -0
  101. package/dist/esnext/hooks/useCartLinesRemoveCallback/useCartLinesRemoveCallback.js +8 -0
  102. package/dist/esnext/hooks/useCartLinesTotalQuantity/index.d.ts +1 -0
  103. package/dist/esnext/hooks/useCartLinesTotalQuantity/index.js +1 -0
  104. package/dist/esnext/hooks/useCartLinesTotalQuantity/useCartLinesTotalQuantity.d.ts +4 -0
  105. package/dist/esnext/hooks/useCartLinesTotalQuantity/useCartLinesTotalQuantity.js +15 -0
  106. package/dist/esnext/hooks/useCartLinesUpdateCallback/index.d.ts +1 -0
  107. package/dist/esnext/hooks/useCartLinesUpdateCallback/index.js +1 -0
  108. package/dist/esnext/hooks/useCartLinesUpdateCallback/useCartLinesUpdateCallback.d.ts +4 -0
  109. package/dist/esnext/hooks/useCartLinesUpdateCallback/useCartLinesUpdateCallback.js +8 -0
  110. package/dist/esnext/hooks/useCartNoteUpdateCallback/index.d.ts +1 -0
  111. package/dist/esnext/hooks/useCartNoteUpdateCallback/index.js +1 -0
  112. package/dist/esnext/hooks/useCartNoteUpdateCallback/useCartNoteUpdateCallback.d.ts +4 -0
  113. package/dist/esnext/hooks/useCartNoteUpdateCallback/useCartNoteUpdateCallback.js +8 -0
  114. package/dist/esnext/hooks/useCountry/index.d.ts +1 -0
  115. package/dist/esnext/hooks/useCountry/index.js +1 -0
  116. package/dist/esnext/{components/LocalizationProvider/hooks.d.ts → hooks/useCountry/useCountry.d.ts} +4 -7
  117. package/dist/esnext/hooks/useCountry/useCountry.js +17 -0
  118. package/dist/esnext/hooks/useMoney/hooks.js +18 -4
  119. package/dist/esnext/hooks/useProductOptions/useProductOptions.d.ts +1 -1
  120. package/dist/esnext/hooks/useProductOptions/useProductOptions.js +1 -1
  121. package/dist/esnext/hooks/useQuery/hooks.d.ts +9 -7
  122. package/dist/esnext/hooks/useQuery/hooks.js +15 -5
  123. package/dist/esnext/hooks/useShopQuery/hooks.d.ts +1 -0
  124. package/dist/esnext/hooks/useShopQuery/hooks.js +4 -0
  125. package/dist/esnext/types.d.ts +1 -0
  126. package/dist/esnext/utilities/error.d.ts +1 -0
  127. package/dist/esnext/utilities/error.js +15 -0
  128. package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +12 -0
  129. package/dist/esnext/utilities/flattenConnection/flattenConnection.js +14 -0
  130. package/dist/esnext/utilities/flattenConnection/index.d.ts +1 -0
  131. package/dist/esnext/utilities/flattenConnection/index.js +1 -0
  132. package/dist/esnext/utilities/image_size.d.ts +1 -1
  133. package/dist/esnext/utilities/index.d.ts +3 -3
  134. package/dist/esnext/utilities/index.js +3 -3
  135. package/dist/esnext/utilities/{meaurement.d.ts → measurement.d.ts} +0 -0
  136. package/dist/esnext/utilities/{meaurement.js → measurement.js} +0 -0
  137. package/dist/esnext/utilities/{metafields → parseMetafieldValue}/index.d.ts +0 -0
  138. package/dist/esnext/utilities/{metafields → parseMetafieldValue}/index.js +0 -0
  139. package/dist/esnext/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.d.ts +1 -6
  140. package/dist/esnext/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.js +1 -6
  141. package/dist/esnext/version.d.ts +1 -1
  142. package/dist/esnext/version.js +1 -1
  143. package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +2 -1
  144. package/dist/node/foundation/ShopifyProvider/ShopifyProvider.d.ts +1 -1
  145. package/dist/node/foundation/ShopifyProvider/ShopifyProvider.js +1 -1
  146. package/dist/node/framework/Hydration/react-utils.js +1 -1
  147. package/dist/node/framework/cache.js +4 -2
  148. package/dist/node/framework/config.d.ts +6 -0
  149. package/dist/node/framework/config.js +11 -0
  150. package/dist/node/framework/runtime.d.ts +2 -2
  151. package/dist/node/framework/runtime.js +4 -3
  152. package/dist/node/graphql/types/types.d.ts +234 -56
  153. package/dist/node/graphql/types/types.js +23 -1
  154. package/dist/node/handle-event.js +64 -71
  155. package/dist/node/hooks/useQuery/hooks.d.ts +9 -7
  156. package/dist/node/hooks/useQuery/hooks.js +15 -5
  157. package/dist/node/types.d.ts +1 -0
  158. package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +12 -0
  159. package/dist/node/utilities/flattenConnection/flattenConnection.js +18 -0
  160. package/dist/node/utilities/flattenConnection/index.d.ts +1 -0
  161. package/dist/node/utilities/flattenConnection/index.js +5 -0
  162. package/dist/node/utilities/image_size.d.ts +1 -1
  163. package/dist/node/utilities/index.d.ts +3 -3
  164. package/dist/node/utilities/index.js +7 -7
  165. package/dist/node/utilities/{meaurement.d.ts → measurement.d.ts} +0 -0
  166. package/dist/node/utilities/{meaurement.js → measurement.js} +0 -0
  167. package/dist/node/utilities/{metafields → parseMetafieldValue}/index.d.ts +0 -0
  168. package/dist/node/utilities/{metafields → parseMetafieldValue}/index.js +0 -0
  169. package/dist/node/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.d.ts +1 -6
  170. package/dist/node/utilities/{metafields → parseMetafieldValue}/parseMetafieldValue.js +1 -6
  171. package/dist/node/version.d.ts +1 -1
  172. package/dist/node/version.js +1 -1
  173. package/dist/worker/framework/cache.js +4 -2
  174. package/dist/worker/framework/config.d.ts +6 -0
  175. package/dist/worker/framework/config.js +6 -0
  176. package/dist/worker/framework/runtime.d.ts +2 -2
  177. package/dist/worker/framework/runtime.js +4 -3
  178. package/dist/worker/graphql/types/types.d.ts +234 -56
  179. package/dist/worker/graphql/types/types.js +22 -0
  180. package/dist/worker/handle-event.js +64 -71
  181. package/dist/worker/types.d.ts +1 -0
  182. package/package.json +2 -2
  183. package/dist/esnext/utilities/connections.d.ts +0 -2
  184. package/dist/esnext/utilities/connections.js +0 -4
  185. package/dist/node/utilities/connections.d.ts +0 -2
  186. package/dist/node/utilities/connections.js +0 -8
@@ -1,5 +1,6 @@
1
1
  import { getCacheControlHeader } from './framework/cache';
2
2
  import { setContext, setCache } from './framework/runtime';
3
+ import { setConfig } from './framework/config';
3
4
  export default async function handleEvent(event, { request, entrypoint, indexTemplate, assetHandler, streamableResponse, dev, cache, context, }) {
4
5
  var _a, _b, _c;
5
6
  const url = new URL(request.url);
@@ -8,86 +9,78 @@ export default async function handleEvent(event, { request, entrypoint, indexTem
8
9
  */
9
10
  setCache(cache);
10
11
  setContext(context);
12
+ setConfig({ dev });
11
13
  const isReactHydrationRequest = url.pathname === '/react';
12
- try {
13
- const template = typeof indexTemplate === 'function'
14
- ? await indexTemplate(url.toString())
15
- : indexTemplate;
16
- /**
17
- * If this is a request for an asset, and an asset handler is present, call it.
18
- */
19
- if (/\.(png|jpe?g|gif|css|js|svg|ico|map)$/i.test(url.pathname) &&
20
- assetHandler) {
21
- return assetHandler(event, url);
22
- }
23
- const { render, hydrate, stream } = entrypoint.default || entrypoint;
24
- // @ts-ignore
25
- if (dev && !(render && hydrate && stream)) {
26
- throw new Error(`entry-server.jsx could not be loaded. This likely occurred because of a Vite compilation error.\n` +
27
- `Please check your server logs for more information.`);
28
- }
29
- const isStreamable = streamableResponse && isStreamableRequest(url);
30
- const context = {};
31
- /**
32
- * Stream back real-user responses, but for bots/etc,
33
- * use `render` instead. This is because we need to inject <head>
34
- * things for SEO reasons.
35
- */
36
- if (isStreamable) {
37
- if (isReactHydrationRequest) {
38
- hydrate(url, { context, request, response: streamableResponse, dev });
39
- }
40
- else {
41
- stream(url, {
42
- context,
43
- request,
44
- response: streamableResponse,
45
- template,
46
- dev,
47
- });
48
- }
49
- return;
50
- }
51
- const { body, bodyAttributes, htmlAttributes, componentResponse, ...head } = await render(url, { request, context, isReactHydrationRequest });
52
- const headers = componentResponse.headers;
53
- /**
54
- * TODO: Also add `Vary` headers for `accept-language` and any other keys
55
- * we want to shard our full-page cache for all Hydrogen storefronts.
56
- */
57
- headers.set(getCacheControlHeader({ dev }), componentResponse.cacheControlHeader);
58
- if (componentResponse.customBody) {
59
- return new Response(await componentResponse.customBody, {
60
- status: (_a = componentResponse.status) !== null && _a !== void 0 ? _a : 200,
61
- headers,
62
- });
63
- }
64
- let response;
14
+ const template = typeof indexTemplate === 'function'
15
+ ? await indexTemplate(url.toString())
16
+ : indexTemplate;
17
+ /**
18
+ * If this is a request for an asset, and an asset handler is present, call it.
19
+ */
20
+ if (/\.(png|jpe?g|gif|css|js|svg|ico|map)$/i.test(url.pathname) &&
21
+ assetHandler) {
22
+ return assetHandler(event, url);
23
+ }
24
+ const { render, hydrate, stream } = entrypoint.default || entrypoint;
25
+ // @ts-ignore
26
+ if (dev && !(render && hydrate && stream)) {
27
+ throw new Error(`entry-server.jsx could not be loaded. This likely occurred because of a Vite compilation error.\n` +
28
+ `Please check your server logs for more information.`);
29
+ }
30
+ const isStreamable = streamableResponse && isStreamableRequest(url);
31
+ /**
32
+ * Stream back real-user responses, but for bots/etc,
33
+ * use `render` instead. This is because we need to inject <head>
34
+ * things for SEO reasons.
35
+ */
36
+ if (isStreamable) {
65
37
  if (isReactHydrationRequest) {
66
- response = new Response(body, {
67
- status: (_b = componentResponse.status) !== null && _b !== void 0 ? _b : 200,
68
- headers,
69
- });
38
+ hydrate(url, { context: {}, request, response: streamableResponse, dev });
70
39
  }
71
40
  else {
72
- const html = template
73
- .replace(`<div id="root"></div>`, `<div id="root" data-server-rendered="true">${body}</div>`)
74
- .replace(/<head>(.*?)<\/head>/s, generateHeadTag(head))
75
- .replace('<body', bodyAttributes ? `<body ${bodyAttributes}` : '$&')
76
- .replace('<html', htmlAttributes ? `<html ${htmlAttributes}` : '$&');
77
- headers.append('content-type', 'text/html');
78
- response = new Response(html, {
79
- status: (_c = componentResponse.status) !== null && _c !== void 0 ? _c : 200,
80
- headers,
41
+ stream(url, {
42
+ context: {},
43
+ request,
44
+ response: streamableResponse,
45
+ template,
46
+ dev,
81
47
  });
82
48
  }
83
- return response;
49
+ return;
50
+ }
51
+ const { body, bodyAttributes, htmlAttributes, componentResponse, ...head } = await render(url, { request, context: {}, isReactHydrationRequest, dev });
52
+ const headers = componentResponse.headers;
53
+ /**
54
+ * TODO: Also add `Vary` headers for `accept-language` and any other keys
55
+ * we want to shard our full-page cache for all Hydrogen storefronts.
56
+ */
57
+ headers.set(getCacheControlHeader({ dev }), componentResponse.cacheControlHeader);
58
+ if (componentResponse.customBody) {
59
+ return new Response(await componentResponse.customBody, {
60
+ status: (_a = componentResponse.status) !== null && _a !== void 0 ? _a : 200,
61
+ headers,
62
+ });
63
+ }
64
+ let response;
65
+ if (isReactHydrationRequest) {
66
+ response = new Response(body, {
67
+ status: (_b = componentResponse.status) !== null && _b !== void 0 ? _b : 200,
68
+ headers,
69
+ });
84
70
  }
85
- catch (e) {
86
- console.log(e.stack);
87
- return new Response(e.message || e.toString(), {
88
- status: 500,
71
+ else {
72
+ const html = template
73
+ .replace(`<div id="root"></div>`, `<div id="root" data-server-rendered="true">${body}</div>`)
74
+ .replace(/<head>(.*?)<\/head>/s, generateHeadTag(head))
75
+ .replace('<body', bodyAttributes ? `<body ${bodyAttributes}` : '$&')
76
+ .replace('<html', htmlAttributes ? `<html ${htmlAttributes}` : '$&');
77
+ headers.append('content-type', 'text/html');
78
+ response = new Response(html, {
79
+ status: (_c = componentResponse.status) !== null && _c !== void 0 ? _c : 200,
80
+ headers,
89
81
  });
90
82
  }
83
+ return response;
91
84
  }
92
85
  function isStreamableRequest(url) {
93
86
  /**
@@ -0,0 +1 @@
1
+ export { useAvailableCountries } from './useAvailableCountries';
@@ -0,0 +1 @@
1
+ export { useAvailableCountries } from './useAvailableCountries';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The `useAvailableCountries` hook returns an array of available countries used for localization.
3
+ * It must be a descendent of a `LocalizationProvider` component.
4
+ */
5
+ export declare function useAvailableCountries(): ({
6
+ __typename?: "Country" | undefined;
7
+ } & Pick<import("../../graphql/types/types").Country, "name" | "isoCode"> & {
8
+ currency: {
9
+ __typename?: "Currency" | undefined;
10
+ } & Pick<import("../../graphql/types/types").Currency, "isoCode">;
11
+ })[];
@@ -1,5 +1,5 @@
1
1
  import { useContext } from 'react';
2
- import { LocalizationContext, } from './LocalizationContext.client';
2
+ import { LocalizationContext, } from '../../components/LocalizationProvider/LocalizationContext.client';
3
3
  function useLocalization() {
4
4
  const context = useContext(LocalizationContext);
5
5
  if (context == null) {
@@ -7,10 +7,10 @@ function useLocalization() {
7
7
  }
8
8
  return context;
9
9
  }
10
- export function useCountry() {
11
- const context = useLocalization();
12
- return [context.country, context.setCountry];
13
- }
10
+ /**
11
+ * The `useAvailableCountries` hook returns an array of available countries used for localization.
12
+ * It must be a descendent of a `LocalizationProvider` component.
13
+ */
14
14
  export function useAvailableCountries() {
15
15
  const context = useLocalization();
16
16
  return context.availableCountries;
@@ -0,0 +1 @@
1
+ export { useCart } from './useCart';
@@ -0,0 +1 @@
1
+ export { useCart } from './useCart';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCart` hook provides access to the cart object. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCart(): import("../..").CartWithActions;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { CartContext } from '../../components/CartProvider/context';
3
+ /**
4
+ * The `useCart` hook provides access to the cart object. It must be a descendent of a `CartProvider` component.
5
+ */
6
+ export function useCart() {
7
+ const context = React.useContext(CartContext);
8
+ if (!context) {
9
+ throw new Error('Expected a Cart Context, but no Cart Context was found');
10
+ }
11
+ return context;
12
+ }
@@ -0,0 +1 @@
1
+ export { useCartAttributesUpdateCallback } from './useCartAttributesUpdateCallback';
@@ -0,0 +1 @@
1
+ export { useCartAttributesUpdateCallback } from './useCartAttributesUpdateCallback';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartAttributesUpdateCallback` hook returns a callback that can be used to update the cart's attributes. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartAttributesUpdateCallback(): (attributes: import("../../graphql/types/types").AttributeInput[]) => void;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartAttributesUpdateCallback` hook returns a callback that can be used to update the cart's attributes. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartAttributesUpdateCallback() {
6
+ const { cartAttributesUpdate } = useCart();
7
+ return cartAttributesUpdate;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCartBuyerIdentityUpdateCallback } from './useCartBuyerIdentityUpdateCallback';
@@ -0,0 +1 @@
1
+ export { useCartBuyerIdentityUpdateCallback } from './useCartBuyerIdentityUpdateCallback';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartBuyerIdentityUpdateCallback` hook returns a callback that can be used to update the cart's buyer identity. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartBuyerIdentityUpdateCallback(): (buyerIdenity: import("../../graphql/types/types").CartBuyerIdentityInput) => void;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartBuyerIdentityUpdateCallback` hook returns a callback that can be used to update the cart's buyer identity. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartBuyerIdentityUpdateCallback() {
6
+ const { buyerIdentityUpdate } = useCart();
7
+ return buyerIdentityUpdate;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCartCheckoutUrl } from './useCartCheckoutUrl';
@@ -0,0 +1 @@
1
+ export { useCartCheckoutUrl } from './useCartCheckoutUrl';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartCheckoutUrl` hook returns a string of the checkout URL for the cart. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartCheckoutUrl(): string | undefined;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartCheckoutUrl` hook returns a string of the checkout URL for the cart. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartCheckoutUrl() {
6
+ const { checkoutUrl } = useCart();
7
+ return checkoutUrl;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCartCreateCallback } from './useCartCreateCallback';
@@ -0,0 +1 @@
1
+ export { useCartCreateCallback } from './useCartCreateCallback';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartCreateCallback` hook returns a callback that can be used to create a cart. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartCreateCallback(): (cart: import("../../graphql/types/types").CartInput) => void;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartCreateCallback` hook returns a callback that can be used to create a cart. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartCreateCallback() {
6
+ const { cartCreate } = useCart();
7
+ return cartCreate;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCartDiscountCodesUpdateCallback } from './useCartDiscountCodesUpdateCallback';
@@ -0,0 +1 @@
1
+ export { useCartDiscountCodesUpdateCallback } from './useCartDiscountCodesUpdateCallback';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartDiscountCodesUpdateCallback` hook returns a callback that can be used to update the cart's discount codes. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartDiscountCodesUpdateCallback(): (discountCodes: string[]) => void;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartDiscountCodesUpdateCallback` hook returns a callback that can be used to update the cart's discount codes. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartDiscountCodesUpdateCallback() {
6
+ const { discountCodesUpdate } = useCart();
7
+ return discountCodesUpdate;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCartLine } from './useCartLine';
@@ -0,0 +1 @@
1
+ export { useCartLine } from './useCartLine';
@@ -1,3 +1,6 @@
1
+ /**
2
+ * The `useCartLine` hook provides access to the cart line object. It must be a descendent of a `CartProvider` component.
3
+ */
1
4
  export declare function useCartLine(): {
2
5
  __typename?: "CartLine" | undefined;
3
6
  } & Pick<import("../../graphql/types/types").CartLine, "id" | "quantity"> & {
@@ -20,8 +23,10 @@ export declare function useCartLine(): {
20
23
  image?: import("../../graphql/types/types").Maybe<{
21
24
  __typename?: "Image" | undefined;
22
25
  } & {
23
- __typename?: "Image" | undefined;
24
- } & Pick<import("../../graphql/types/types").Image, "height" | "width" | "id" | "altText" | "originalSrc">> | undefined;
26
+ __typename?: "Image" | undefined; /**
27
+ * The `useCartLine` hook provides access to the cart line object. It must be a descendent of a `CartProvider` component.
28
+ */
29
+ } & Pick<import("../../graphql/types/types").Image, "height" | "width" | "url" | "id" | "altText">> | undefined;
25
30
  product: {
26
31
  __typename?: "Product" | undefined;
27
32
  } & Pick<import("../../graphql/types/types").Product, "title" | "handle">;
@@ -1,5 +1,8 @@
1
1
  import { useContext } from 'react';
2
- import { CartLineContext } from './context';
2
+ import { CartLineContext } from '../../components/CartLineProvider/context';
3
+ /**
4
+ * The `useCartLine` hook provides access to the cart line object. It must be a descendent of a `CartProvider` component.
5
+ */
3
6
  export function useCartLine() {
4
7
  const context = useContext(CartLineContext);
5
8
  if (context == null) {
@@ -0,0 +1 @@
1
+ export { useCartLinesAddCallback } from './useCartLinesAddCallback';
@@ -0,0 +1 @@
1
+ export { useCartLinesAddCallback } from './useCartLinesAddCallback';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The `useCartLinesAddCallback` hook returns a callback that can be used to add lines to a cart. If a cart doesn't
3
+ * already exist, then it will create the cart for you. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export declare function useCartLinesAddCallback(): (lines: import("../../graphql/types/types").CartLineInput[]) => void;
@@ -0,0 +1,9 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartLinesAddCallback` hook returns a callback that can be used to add lines to a cart. If a cart doesn't
4
+ * already exist, then it will create the cart for you. It must be a descendent of a `CartProvider` component.
5
+ */
6
+ export function useCartLinesAddCallback() {
7
+ const { linesAdd } = useCart();
8
+ return linesAdd;
9
+ }
@@ -0,0 +1 @@
1
+ export { useCartLinesRemoveCallback } from './useCartLinesRemoveCallback';
@@ -0,0 +1 @@
1
+ export { useCartLinesRemoveCallback } from './useCartLinesRemoveCallback';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartLinesRemoveCallback` hook returns a callback that can be used to remove lines from a cart. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartLinesRemoveCallback(): (lines: string[]) => void;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartLinesRemoveCallback` hook returns a callback that can be used to remove lines from a cart. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartLinesRemoveCallback() {
6
+ const { linesRemove } = useCart();
7
+ return linesRemove;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCartLinesTotalQuantity } from './useCartLinesTotalQuantity';
@@ -0,0 +1 @@
1
+ export { useCartLinesTotalQuantity } from './useCartLinesTotalQuantity';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartLinesTotalQuantity` hook returns the total amount of items in the cart. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartLinesTotalQuantity(): number;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { useCart } from '../useCart';
3
+ /**
4
+ * The `useCartLinesTotalQuantity` hook returns the total amount of items in the cart. It must be a descendent of a `CartProvider` component.
5
+ */
6
+ export function useCartLinesTotalQuantity() {
7
+ var _a;
8
+ const { lines } = useCart();
9
+ const itemCount = (_a = React.useMemo(() => {
10
+ return lines.reduce((accumulator, line) => {
11
+ return accumulator + line.quantity;
12
+ }, 0);
13
+ }, [lines])) !== null && _a !== void 0 ? _a : 0;
14
+ return itemCount;
15
+ }
@@ -0,0 +1 @@
1
+ export { useCartLinesUpdateCallback } from './useCartLinesUpdateCallback';
@@ -0,0 +1 @@
1
+ export { useCartLinesUpdateCallback } from './useCartLinesUpdateCallback';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartLinesUpdateCallback` hook returns a callback that can be used to update lines in a cart. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartLinesUpdateCallback(): (lines: import("../../graphql/types/types").CartLineUpdateInput[]) => void;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartLinesUpdateCallback` hook returns a callback that can be used to update lines in a cart. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartLinesUpdateCallback() {
6
+ const { linesUpdate } = useCart();
7
+ return linesUpdate;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCartNoteUpdateCallback } from './useCartNoteUpdateCallback';
@@ -0,0 +1 @@
1
+ export { useCartNoteUpdateCallback } from './useCartNoteUpdateCallback';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The `useCartNoteUpdateCallback` hook returns a callback that can be used to update the cart's note. It must be a descendent of a `CartProvider` component.
3
+ */
4
+ export declare function useCartNoteUpdateCallback(): (note: import("../../graphql/types/types").Maybe<string> | undefined) => void;
@@ -0,0 +1,8 @@
1
+ import { useCart } from '../useCart';
2
+ /**
3
+ * The `useCartNoteUpdateCallback` hook returns a callback that can be used to update the cart's note. It must be a descendent of a `CartProvider` component.
4
+ */
5
+ export function useCartNoteUpdateCallback() {
6
+ const { noteUpdate } = useCart();
7
+ return noteUpdate;
8
+ }
@@ -0,0 +1 @@
1
+ export { useCountry } from './useCountry';
@@ -0,0 +1 @@
1
+ export { useCountry } from './useCountry';
@@ -1,3 +1,7 @@
1
+ /**
2
+ * The `useCountry` hook returns a tuple of the current localization country and a function for updating it.
3
+ * It must be a descendent of a `LocalizationProvider` component.
4
+ */
1
5
  export declare function useCountry(): (({
2
6
  __typename?: "Country" | undefined;
3
7
  } & Pick<import("../../graphql/types/types").Country, "name" | "isoCode"> & {
@@ -11,10 +15,3 @@ export declare function useCountry(): (({
11
15
  __typename?: "Currency" | undefined;
12
16
  } & Pick<import("../../graphql/types/types").Currency, "isoCode">;
13
17
  }) => void) | undefined)[];
14
- export declare function useAvailableCountries(): ({
15
- __typename?: "Country" | undefined;
16
- } & Pick<import("../../graphql/types/types").Country, "name" | "isoCode"> & {
17
- currency: {
18
- __typename?: "Currency" | undefined;
19
- } & Pick<import("../../graphql/types/types").Currency, "isoCode">;
20
- })[];
@@ -0,0 +1,17 @@
1
+ import { useContext } from 'react';
2
+ import { LocalizationContext, } from '../../components/LocalizationProvider/LocalizationContext.client';
3
+ function useLocalization() {
4
+ const context = useContext(LocalizationContext);
5
+ if (context == null) {
6
+ throw new Error('No Localization Context available');
7
+ }
8
+ return context;
9
+ }
10
+ /**
11
+ * The `useCountry` hook returns a tuple of the current localization country and a function for updating it.
12
+ * It must be a descendent of a `LocalizationProvider` component.
13
+ */
14
+ export function useCountry() {
15
+ const context = useLocalization();
16
+ return [context.country, context.setCountry];
17
+ }
@@ -1,5 +1,19 @@
1
1
  import { useMemo } from 'react';
2
2
  import { useShop } from '../../foundation/useShop';
3
+ // TODO: Remove this when Oxygen supports Intl properly (oxygen-sws#527)
4
+ const NARROW_SYMBOL_MAP = {
5
+ USD: '$',
6
+ AUD: '$',
7
+ CAD: '$',
8
+ NZD: '$',
9
+ EUR: '€',
10
+ GBP: '£',
11
+ INR: '₹',
12
+ RUB: '₽',
13
+ CNY: '¥',
14
+ JPY: '¥',
15
+ BRL: 'R$',
16
+ };
3
17
  /**
4
18
  * The `useMoney` hook takes a [`MoneyV2` object](/api/storefront/reference/common-objects/moneyv2) and returns a
5
19
  * default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by
@@ -23,12 +37,12 @@ export function useMoney(money) {
23
37
  currencyDisplay: 'narrowSymbol',
24
38
  }).formatToParts(amount);
25
39
  const moneyValue = useMemo(() => {
26
- var _a, _b, _c;
40
+ var _a, _b, _c, _d, _e, _f, _g;
27
41
  return ({
28
42
  currencyCode: money.currencyCode,
29
- currencyName: (_a = nameParts.find((part) => part.type === 'currency')) === null || _a === void 0 ? void 0 : _a.value,
30
- currencySymbol: (_b = baseParts.find((part) => part.type === 'currency')) === null || _b === void 0 ? void 0 : _b.value,
31
- currencyNarrowSymbol: (_c = narrowParts.find((part) => part.type === 'currency')) === null || _c === void 0 ? void 0 : _c.value,
43
+ currencyName: (_b = (_a = nameParts.find((part) => part.type === 'currency')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : money.currencyCode,
44
+ currencySymbol: (_d = (_c = baseParts.find((part) => part.type === 'currency')) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : money.currencyCode,
45
+ currencyNarrowSymbol: (_g = (_f = (_e = narrowParts.find((part) => part.type === 'currency')) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : NARROW_SYMBOL_MAP[money.currencyCode]) !== null && _g !== void 0 ? _g : '',
32
46
  parts: baseParts,
33
47
  localizedString: value,
34
48
  amount: baseParts
@@ -1,7 +1,7 @@
1
1
  import { SellingPlanGroup, Variant, ProductOptionsHookValue } from './types';
2
2
  import { GraphQLConnection } from '../../types';
3
3
  /**
4
- * The `useProductOptions` hook returns an object that allows you to keep track of the
4
+ * The `useProductOptions` hook returns an object that enables you to keep track of the
5
5
  * selected variant and/or selling plan state, as well as callbacks for modifying the state.
6
6
  */
7
7
  export declare function useProductOptions({ variants: variantsConnection, sellingPlanGroups: sellingPlanGroupsConnection, initialVariantId, }: {
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import { flattenConnection } from '../../utilities';
3
3
  import { getOptions, getSelectedVariant } from './helpers';
4
4
  /**
5
- * The `useProductOptions` hook returns an object that allows you to keep track of the
5
+ * The `useProductOptions` hook returns an object that enables you to keep track of the
6
6
  * selected variant and/or selling plan state, as well as callbacks for modifying the state.
7
7
  */
8
8
  export function useProductOptions({ variants: variantsConnection, sellingPlanGroups: sellingPlanGroupsConnection, initialVariantId, }) {