@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
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const cache_1 = require("./framework/cache");
4
4
  const runtime_1 = require("./framework/runtime");
5
+ const config_1 = require("./framework/config");
5
6
  async function handleEvent(event, { request, entrypoint, indexTemplate, assetHandler, streamableResponse, dev, cache, context, }) {
6
7
  var _a, _b, _c;
7
8
  const url = new URL(request.url);
@@ -10,86 +11,78 @@ async function handleEvent(event, { request, entrypoint, indexTemplate, assetHan
10
11
  */
11
12
  runtime_1.setCache(cache);
12
13
  runtime_1.setContext(context);
14
+ config_1.setConfig({ dev });
13
15
  const isReactHydrationRequest = url.pathname === '/react';
14
- try {
15
- const template = typeof indexTemplate === 'function'
16
- ? await indexTemplate(url.toString())
17
- : indexTemplate;
18
- /**
19
- * If this is a request for an asset, and an asset handler is present, call it.
20
- */
21
- if (/\.(png|jpe?g|gif|css|js|svg|ico|map)$/i.test(url.pathname) &&
22
- assetHandler) {
23
- return assetHandler(event, url);
24
- }
25
- const { render, hydrate, stream } = entrypoint.default || entrypoint;
26
- // @ts-ignore
27
- if (dev && !(render && hydrate && stream)) {
28
- throw new Error(`entry-server.jsx could not be loaded. This likely occurred because of a Vite compilation error.\n` +
29
- `Please check your server logs for more information.`);
30
- }
31
- const isStreamable = streamableResponse && isStreamableRequest(url);
32
- const context = {};
33
- /**
34
- * Stream back real-user responses, but for bots/etc,
35
- * use `render` instead. This is because we need to inject <head>
36
- * things for SEO reasons.
37
- */
38
- if (isStreamable) {
39
- if (isReactHydrationRequest) {
40
- hydrate(url, { context, request, response: streamableResponse, dev });
41
- }
42
- else {
43
- stream(url, {
44
- context,
45
- request,
46
- response: streamableResponse,
47
- template,
48
- dev,
49
- });
50
- }
51
- return;
52
- }
53
- const { body, bodyAttributes, htmlAttributes, componentResponse, ...head } = await render(url, { request, context, isReactHydrationRequest });
54
- const headers = componentResponse.headers;
55
- /**
56
- * TODO: Also add `Vary` headers for `accept-language` and any other keys
57
- * we want to shard our full-page cache for all Hydrogen storefronts.
58
- */
59
- headers.set(cache_1.getCacheControlHeader({ dev }), componentResponse.cacheControlHeader);
60
- if (componentResponse.customBody) {
61
- return new Response(await componentResponse.customBody, {
62
- status: (_a = componentResponse.status) !== null && _a !== void 0 ? _a : 200,
63
- headers,
64
- });
65
- }
66
- let response;
16
+ const template = typeof indexTemplate === 'function'
17
+ ? await indexTemplate(url.toString())
18
+ : indexTemplate;
19
+ /**
20
+ * If this is a request for an asset, and an asset handler is present, call it.
21
+ */
22
+ if (/\.(png|jpe?g|gif|css|js|svg|ico|map)$/i.test(url.pathname) &&
23
+ assetHandler) {
24
+ return assetHandler(event, url);
25
+ }
26
+ const { render, hydrate, stream } = entrypoint.default || entrypoint;
27
+ // @ts-ignore
28
+ if (dev && !(render && hydrate && stream)) {
29
+ throw new Error(`entry-server.jsx could not be loaded. This likely occurred because of a Vite compilation error.\n` +
30
+ `Please check your server logs for more information.`);
31
+ }
32
+ const isStreamable = streamableResponse && isStreamableRequest(url);
33
+ /**
34
+ * Stream back real-user responses, but for bots/etc,
35
+ * use `render` instead. This is because we need to inject <head>
36
+ * things for SEO reasons.
37
+ */
38
+ if (isStreamable) {
67
39
  if (isReactHydrationRequest) {
68
- response = new Response(body, {
69
- status: (_b = componentResponse.status) !== null && _b !== void 0 ? _b : 200,
70
- headers,
71
- });
40
+ hydrate(url, { context: {}, request, response: streamableResponse, dev });
72
41
  }
73
42
  else {
74
- const html = template
75
- .replace(`<div id="root"></div>`, `<div id="root" data-server-rendered="true">${body}</div>`)
76
- .replace(/<head>(.*?)<\/head>/s, generateHeadTag(head))
77
- .replace('<body', bodyAttributes ? `<body ${bodyAttributes}` : '$&')
78
- .replace('<html', htmlAttributes ? `<html ${htmlAttributes}` : '$&');
79
- headers.append('content-type', 'text/html');
80
- response = new Response(html, {
81
- status: (_c = componentResponse.status) !== null && _c !== void 0 ? _c : 200,
82
- headers,
43
+ stream(url, {
44
+ context: {},
45
+ request,
46
+ response: streamableResponse,
47
+ template,
48
+ dev,
83
49
  });
84
50
  }
85
- return response;
51
+ return;
52
+ }
53
+ const { body, bodyAttributes, htmlAttributes, componentResponse, ...head } = await render(url, { request, context: {}, isReactHydrationRequest, dev });
54
+ const headers = componentResponse.headers;
55
+ /**
56
+ * TODO: Also add `Vary` headers for `accept-language` and any other keys
57
+ * we want to shard our full-page cache for all Hydrogen storefronts.
58
+ */
59
+ headers.set(cache_1.getCacheControlHeader({ dev }), componentResponse.cacheControlHeader);
60
+ if (componentResponse.customBody) {
61
+ return new Response(await componentResponse.customBody, {
62
+ status: (_a = componentResponse.status) !== null && _a !== void 0 ? _a : 200,
63
+ headers,
64
+ });
65
+ }
66
+ let response;
67
+ if (isReactHydrationRequest) {
68
+ response = new Response(body, {
69
+ status: (_b = componentResponse.status) !== null && _b !== void 0 ? _b : 200,
70
+ headers,
71
+ });
86
72
  }
87
- catch (e) {
88
- console.log(e.stack);
89
- return new Response(e.message || e.toString(), {
90
- status: 500,
73
+ else {
74
+ const html = template
75
+ .replace(`<div id="root"></div>`, `<div id="root" data-server-rendered="true">${body}</div>`)
76
+ .replace(/<head>(.*?)<\/head>/s, generateHeadTag(head))
77
+ .replace('<body', bodyAttributes ? `<body ${bodyAttributes}` : '$&')
78
+ .replace('<html', htmlAttributes ? `<html ${htmlAttributes}` : '$&');
79
+ headers.append('content-type', 'text/html');
80
+ response = new Response(html, {
81
+ status: (_c = componentResponse.status) !== null && _c !== void 0 ? _c : 200,
82
+ headers,
91
83
  });
92
84
  }
85
+ return response;
93
86
  }
94
87
  exports.default = handleEvent;
95
88
  function isStreamableRequest(url) {
@@ -1,13 +1,15 @@
1
1
  import type { UseQueryOptions, QueryKey, QueryFunction } from 'react-query';
2
2
  import { CacheOptions } from '../../types';
3
- interface HydrogenUseQueryOptions<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> {
3
+ export interface HydrogenUseQueryOptions<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> {
4
4
  cache: CacheOptions;
5
5
  }
6
6
  /**
7
- * useQuery is a wrapper around `useQuery` from `react-query` which supports Suspense calls on the server
8
- * and on the client.
9
- *
10
- * @see https://react-query.tanstack.com/reference/useQuery
7
+ * The `useQuery` hook is a wrapper around `useQuery` from `react-query`. It supports Suspense calls on the server and on the client.
11
8
  */
12
- export declare function useQuery<T>(key: QueryKey, queryFn: QueryFunction<T>, queryOptions?: HydrogenUseQueryOptions<T, Error, T, QueryKey>): import("react-query").UseQueryResult<T, Error>;
13
- export {};
9
+ export declare function useQuery<T>(
10
+ /** A string or array to uniquely identify the current query. */
11
+ key: QueryKey,
12
+ /** An asynchronous query function like `fetch` which returns data. */
13
+ queryFn: QueryFunction<T>,
14
+ /** Options including `cache` to manage the cache behavior of the sub-request. */
15
+ queryOptions?: HydrogenUseQueryOptions<T, Error, T, QueryKey>): import("react-query").UseQueryResult<T, Error>;
@@ -5,12 +5,15 @@ const react_query_1 = require("react-query");
5
5
  const cache_1 = require("../../framework/cache");
6
6
  const runtime_1 = require("../../framework/runtime");
7
7
  /**
8
- * useQuery is a wrapper around `useQuery` from `react-query` which supports Suspense calls on the server
9
- * and on the client.
10
- *
11
- * @see https://react-query.tanstack.com/reference/useQuery
8
+ * The `useQuery` hook is a wrapper around `useQuery` from `react-query`. It supports Suspense calls on the server and on the client.
12
9
  */
13
- function useQuery(key, queryFn, queryOptions) {
10
+ function useQuery(
11
+ /** A string or array to uniquely identify the current query. */
12
+ key,
13
+ /** An asynchronous query function like `fetch` which returns data. */
14
+ queryFn,
15
+ /** Options including `cache` to manage the cache behavior of the sub-request. */
16
+ queryOptions) {
14
17
  /**
15
18
  * Attempt to read the query from cache. If it doesn't exist or if it's stale, regenerate it.
16
19
  */
@@ -25,21 +28,28 @@ function useQuery(key, queryFn, queryOptions) {
25
28
  * Important: Do this async
26
29
  */
27
30
  if (cache_1.isStale(response)) {
31
+ console.log('[useQuery] cache stale; generating new response in background');
28
32
  const lockKey = `lock-${key}`;
29
33
  runtime_1.runDelayedFunction(async () => {
34
+ console.log(`[stale regen] fetching cache lock`);
30
35
  const lockExists = await cache_1.getItemFromCache(lockKey);
31
36
  if (lockExists)
32
37
  return;
38
+ console.log(`[stale regen] no cache lock`);
33
39
  await cache_1.setItemInCache(lockKey, true);
40
+ console.log(`[stale regen] set cache lock`);
34
41
  try {
35
42
  const output = await generateNewOutput();
43
+ console.log(`[stale regen] got new output`);
36
44
  await cache_1.setItemInCache(key, output, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.cache);
45
+ console.log(`[stale regen] set new output`);
37
46
  }
38
47
  catch (e) {
39
48
  console.error(`Error generating async response: ${e.message}`);
40
49
  }
41
50
  finally {
42
51
  await cache_1.deleteItemFromCache(lockKey);
52
+ console.log(`[stale regen] deleted lock`);
43
53
  }
44
54
  });
45
55
  }
@@ -7,6 +7,7 @@ export declare type Renderer = (url: URL, options: {
7
7
  request: ServerComponentRequest;
8
8
  context?: Record<string, any>;
9
9
  isReactHydrationRequest?: boolean;
10
+ dev?: boolean;
10
11
  }) => Promise<{
11
12
  body: string;
12
13
  componentResponse: ServerComponentResponse;
@@ -0,0 +1,12 @@
1
+ import { GraphQLConnection } from '../../types';
2
+ /**
3
+ * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](api/storefront/reference/products/product#connections)) into a flat array of nodes.
4
+ * ## Arguments
5
+ * | Description | Required |
6
+ * | ------------| --------- |
7
+ * | A connection object with the field `edges` whose value is an array of objects corresponding to `{node: Value}`. For example, any of the [Product connections](api/storefront/reference/products/product#connections) | Yes |
8
+ *
9
+ * ## Return type
10
+ * A flat array whose elements correspond to the `node` value in each element of the original `edges` array.
11
+ */
12
+ export declare function flattenConnection<T>(connection: GraphQLConnection<T>): T[];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenConnection = void 0;
4
+ /**
5
+ * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](api/storefront/reference/products/product#connections)) into a flat array of nodes.
6
+ * ## Arguments
7
+ * | Description | Required |
8
+ * | ------------| --------- |
9
+ * | A connection object with the field `edges` whose value is an array of objects corresponding to `{node: Value}`. For example, any of the [Product connections](api/storefront/reference/products/product#connections) | Yes |
10
+ *
11
+ * ## Return type
12
+ * A flat array whose elements correspond to the `node` value in each element of the original `edges` array.
13
+ */
14
+ function flattenConnection(connection) {
15
+ var _a;
16
+ return ((_a = connection.edges) !== null && _a !== void 0 ? _a : []).map((edge) => edge.node);
17
+ }
18
+ exports.flattenConnection = flattenConnection;
@@ -0,0 +1 @@
1
+ export { flattenConnection } from './flattenConnection';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenConnection = void 0;
4
+ var flattenConnection_1 = require("./flattenConnection");
5
+ Object.defineProperty(exports, "flattenConnection", { enumerable: true, get: function () { return flattenConnection_1.flattenConnection; } });
@@ -23,7 +23,7 @@ export interface ImageLoaderOptions {
23
23
  export declare function addImageSizeParametersToUrl(url: string, { width, height, crop, scale, format }: ImageSizeOptions): string;
24
24
  export declare function shopifyImageLoader({ src, options }: ImageLoaderOptions): string;
25
25
  export declare function useImageUrl(src?: string, options?: ImageSizeOptions): string | undefined;
26
- export declare function getShopifyImageDimensions(image: Pick<ImageType, 'altText' | 'originalSrc' | 'id' | 'width' | 'height'>, options?: ImageSizeOptions): {
26
+ export declare function getShopifyImageDimensions(image: Pick<ImageType, 'altText' | 'url' | 'id' | 'width' | 'height'>, options?: ImageSizeOptions): {
27
27
  width: import("../graphql/types/types").Maybe<number> | undefined;
28
28
  height: import("../graphql/types/types").Maybe<number> | undefined;
29
29
  };
@@ -2,9 +2,9 @@ export { addImageSizeParametersToUrl, ImageSizeOptions, ImageLoaderOptions, useI
2
2
  export { YouTube, Vimeo, addParametersToEmbeddedVideoUrl, useEmbeddedVideoUrl, } from './video_parameters';
3
3
  export { loadScript } from './script_loader';
4
4
  export { wrapPromise } from './suspense';
5
- export { flattenConnection } from './connections';
5
+ export { flattenConnection } from './flattenConnection';
6
6
  export { isClient } from './isClient';
7
7
  export { isServer } from './isServer';
8
- export { getMeasurementAsParts, getMeasurementAsString } from './meaurement';
9
- export { parseMetafieldValue } from './metafields';
8
+ export { getMeasurementAsParts, getMeasurementAsString } from './measurement';
9
+ export { parseMetafieldValue } from './parseMetafieldValue';
10
10
  export { fetchBuilder, graphqlRequestBody, decodeShopifyId } from './fetch';
@@ -13,17 +13,17 @@ var script_loader_1 = require("./script_loader");
13
13
  Object.defineProperty(exports, "loadScript", { enumerable: true, get: function () { return script_loader_1.loadScript; } });
14
14
  var suspense_1 = require("./suspense");
15
15
  Object.defineProperty(exports, "wrapPromise", { enumerable: true, get: function () { return suspense_1.wrapPromise; } });
16
- var connections_1 = require("./connections");
17
- Object.defineProperty(exports, "flattenConnection", { enumerable: true, get: function () { return connections_1.flattenConnection; } });
16
+ var flattenConnection_1 = require("./flattenConnection");
17
+ Object.defineProperty(exports, "flattenConnection", { enumerable: true, get: function () { return flattenConnection_1.flattenConnection; } });
18
18
  var isClient_1 = require("./isClient");
19
19
  Object.defineProperty(exports, "isClient", { enumerable: true, get: function () { return isClient_1.isClient; } });
20
20
  var isServer_1 = require("./isServer");
21
21
  Object.defineProperty(exports, "isServer", { enumerable: true, get: function () { return isServer_1.isServer; } });
22
- var meaurement_1 = require("./meaurement");
23
- Object.defineProperty(exports, "getMeasurementAsParts", { enumerable: true, get: function () { return meaurement_1.getMeasurementAsParts; } });
24
- Object.defineProperty(exports, "getMeasurementAsString", { enumerable: true, get: function () { return meaurement_1.getMeasurementAsString; } });
25
- var metafields_1 = require("./metafields");
26
- Object.defineProperty(exports, "parseMetafieldValue", { enumerable: true, get: function () { return metafields_1.parseMetafieldValue; } });
22
+ var measurement_1 = require("./measurement");
23
+ Object.defineProperty(exports, "getMeasurementAsParts", { enumerable: true, get: function () { return measurement_1.getMeasurementAsParts; } });
24
+ Object.defineProperty(exports, "getMeasurementAsString", { enumerable: true, get: function () { return measurement_1.getMeasurementAsString; } });
25
+ var parseMetafieldValue_1 = require("./parseMetafieldValue");
26
+ Object.defineProperty(exports, "parseMetafieldValue", { enumerable: true, get: function () { return parseMetafieldValue_1.parseMetafieldValue; } });
27
27
  var fetch_1 = require("./fetch");
28
28
  Object.defineProperty(exports, "fetchBuilder", { enumerable: true, get: function () { return fetch_1.fetchBuilder; } });
29
29
  Object.defineProperty(exports, "graphqlRequestBody", { enumerable: true, get: function () { return fetch_1.graphqlRequestBody; } });
@@ -8,7 +8,7 @@ import { Metafield } from '../../graphql/types/types';
8
8
  * | ------------------------------------------------------------------------- | -------- |
9
9
  * | A [Metafield object](/api/storefront/reference/common-objects/metafield). | Yes |
10
10
  *
11
- * ## Return Type
11
+ * ## Return type
12
12
  *
13
13
  * Depending on the `type` specified in the passed [Metafield](/api/storefront/reference/common-objects/metafield), the following type is returned:
14
14
  *
@@ -32,10 +32,5 @@ import { Metafield } from '../../graphql/types/types';
32
32
  * | `page_reference` | string |
33
33
  * | `variant_reference` | string |
34
34
  * | `url` | string |
35
- *
36
- *
37
- * ## Related hook
38
- *
39
- * - [`useParsedMetafields`](/beta/hydrogen/reference/hooks/metafield/useparsedmetafields)
40
35
  */
41
36
  export declare function parseMetafieldValue(metafield: Partial<Metafield>): any;
@@ -10,7 +10,7 @@ exports.parseMetafieldValue = void 0;
10
10
  * | ------------------------------------------------------------------------- | -------- |
11
11
  * | A [Metafield object](/api/storefront/reference/common-objects/metafield). | Yes |
12
12
  *
13
- * ## Return Type
13
+ * ## Return type
14
14
  *
15
15
  * Depending on the `type` specified in the passed [Metafield](/api/storefront/reference/common-objects/metafield), the following type is returned:
16
16
  *
@@ -34,11 +34,6 @@ exports.parseMetafieldValue = void 0;
34
34
  * | `page_reference` | string |
35
35
  * | `variant_reference` | string |
36
36
  * | `url` | string |
37
- *
38
- *
39
- * ## Related hook
40
- *
41
- * - [`useParsedMetafields`](/beta/hydrogen/reference/hooks/metafield/useparsedmetafields)
42
37
  */
43
38
  function parseMetafieldValue(metafield) {
44
39
  if (metafield.value == null) {
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "0.5.1";
1
+ export declare const LIB_VERSION = "0.6.1";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LIB_VERSION = void 0;
4
- exports.LIB_VERSION = '0.5.1';
4
+ exports.LIB_VERSION = '0.6.1';
@@ -41,8 +41,9 @@ function getKeyUrl(key) {
41
41
  */
42
42
  export async function getItemFromCache(key) {
43
43
  const cache = getCache();
44
- if (!cache)
44
+ if (!cache) {
45
45
  return;
46
+ }
46
47
  const url = getKeyUrl(hashKey(key));
47
48
  const request = new Request(url);
48
49
  const response = await cache.match(request);
@@ -55,8 +56,9 @@ export async function getItemFromCache(key) {
55
56
  */
56
57
  export async function setItemInCache(key, value, userCacheOptions) {
57
58
  const cache = getCache();
58
- if (!cache)
59
+ if (!cache) {
59
60
  return;
61
+ }
60
62
  const url = getKeyUrl(hashKey(key));
61
63
  const request = new Request(url);
62
64
  const cacheOptions = {
@@ -0,0 +1,6 @@
1
+ declare type HydrogenConfig = {
2
+ dev?: boolean;
3
+ };
4
+ export declare function setConfig(config: HydrogenConfig): void;
5
+ export declare function getConfig(): HydrogenConfig;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ export function setConfig(config) {
2
+ globalThis.__config = config;
3
+ }
4
+ export function getConfig() {
5
+ return globalThis.__config || {};
6
+ }
@@ -1,5 +1,5 @@
1
1
  export interface RuntimeContext {
2
- waitUntil: (fn: Function) => void;
2
+ waitUntil: (fn: Promise<any>) => void;
3
3
  }
4
4
  /**
5
5
  * Set a global runtime context for the current request.
@@ -10,4 +10,4 @@ export declare function setContext(ctx?: RuntimeContext): void;
10
10
  export declare function getContext(): RuntimeContext | undefined;
11
11
  export declare function setCache(cache?: Cache): void;
12
12
  export declare function getCache(): Cache | undefined;
13
- export declare function runDelayedFunction(fn: () => void): Promise<void>;
13
+ export declare function runDelayedFunction(fn: () => Promise<any>): void | Promise<any>;
@@ -15,12 +15,13 @@ export function setCache(cache) {
15
15
  export function getCache() {
16
16
  return globalThis.__cache;
17
17
  }
18
- export async function runDelayedFunction(fn) {
18
+ export function runDelayedFunction(fn) {
19
19
  const context = getContext();
20
20
  /**
21
21
  * Runtimes (Oxygen, Node.js) might not have this.
22
22
  */
23
- if (!(context === null || context === void 0 ? void 0 : context.waitUntil))
23
+ if (!(context === null || context === void 0 ? void 0 : context.waitUntil)) {
24
24
  return fn();
25
- return context.waitUntil(fn);
25
+ }
26
+ return context.waitUntil(fn());
26
27
  }