@shopify/hydrogen 0.11.0-experimental.1 → 0.11.1-experimental.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.
- package/CHANGELOG.md +504 -0
- package/dist/esnext/client.d.ts +1 -1
- package/dist/esnext/client.js +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +11 -2
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.js +1 -1
- package/dist/esnext/components/CartLineImage/CartLineImage.client.js +2 -2
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.d.ts +1 -1
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +1 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +2 -2
- package/dist/esnext/components/CartProvider/CartProvider.client.js +1 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +1 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.js +2 -2
- package/dist/esnext/components/Image/Image.d.ts +1 -1
- package/dist/esnext/components/Image/Image.js +9 -9
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +13 -4
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +5 -3
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +8 -6
- package/dist/esnext/components/MediaFile/MediaFile.js +6 -6
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.js +16 -16
- package/dist/esnext/components/ModelViewer/ModelViewer.client.d.ts +1 -1
- package/dist/esnext/components/ModelViewer/ModelViewer.client.js +1 -1
- package/dist/esnext/components/Money/Money.client.d.ts +1 -1
- package/dist/esnext/components/Money/Money.client.js +2 -2
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +3 -1
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +21 -4
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +5 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +30 -9
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.d.ts +8 -0
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.js +12 -0
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +8 -7
- package/dist/esnext/components/ProductProvider/ProductProvider.client.js +9 -35
- package/dist/esnext/components/ProductProvider/context.d.ts +10 -6
- package/dist/esnext/components/ProductProvider/context.js +1 -0
- package/dist/esnext/components/Seo/DefaultPageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/DescriptionSeo.client.js +2 -2
- package/dist/esnext/components/Seo/HomePageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/ImageSeo.client.js +2 -2
- package/dist/esnext/components/Seo/ProductSeo.client.js +5 -3
- package/dist/esnext/components/Seo/TitleSeo.client.js +2 -2
- package/dist/esnext/components/Seo/TwitterSeo.client.js +2 -2
- package/dist/esnext/components/Seo/types.d.ts +1 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +2 -2
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +3 -3
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/Video/Video.js +3 -3
- package/dist/esnext/components/index.d.ts +0 -8
- package/dist/esnext/components/index.js +0 -8
- package/dist/esnext/entry-client.js +1 -1
- package/dist/esnext/entry-server.d.ts +18 -2
- package/dist/esnext/entry-server.js +347 -329
- package/dist/esnext/foundation/Head/Head.client.d.ts +5 -0
- package/dist/esnext/foundation/Head/Head.client.js +10 -0
- package/dist/esnext/foundation/Head/index.d.ts +1 -0
- package/dist/esnext/foundation/Head/index.js +1 -0
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +2 -1
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +43 -4
- package/dist/esnext/foundation/useQuery/hooks.d.ts +11 -3
- package/dist/esnext/foundation/useQuery/hooks.js +21 -5
- package/dist/esnext/framework/CachingStrategy/index.d.ts +10 -0
- package/dist/esnext/framework/CachingStrategy/index.js +96 -0
- package/dist/esnext/framework/Hydration/Html.js +5 -12
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +20 -2
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.js +51 -2
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +2 -2
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +2 -11
- package/dist/esnext/framework/cache/in-memory.js +6 -5
- package/dist/esnext/framework/cache.d.ts +3 -3
- package/dist/esnext/framework/cache.js +4 -18
- package/dist/esnext/framework/middleware.d.ts +7 -7
- package/dist/esnext/framework/middleware.js +15 -43
- package/dist/esnext/framework/plugin.js +14 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.js +38 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +9 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.js +37 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +2 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +3 -1
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +70 -0
- package/dist/esnext/hooks/useProduct/useProduct.d.ts +150 -1
- package/dist/esnext/hooks/useProduct/useProduct.js +36 -3
- package/dist/esnext/hooks/useProductOptions/types.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/useProductOptions.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/useProductOptions.js +6 -6
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +11 -4
- package/dist/esnext/hooks/useShopQuery/hooks.js +6 -3
- package/dist/esnext/index.d.ts +2 -1
- package/dist/esnext/index.js +2 -1
- package/dist/esnext/platforms/node.d.ts +10 -0
- package/dist/esnext/platforms/node.js +38 -0
- package/dist/esnext/platforms/worker-event.d.ts +9 -0
- package/dist/esnext/platforms/worker-event.js +24 -0
- package/dist/esnext/streaming.server.d.ts +17 -7
- package/dist/esnext/streaming.server.js +44 -0
- package/dist/esnext/types.d.ts +25 -25
- package/dist/esnext/utilities/apiRoutes.d.ts +1 -2
- package/dist/esnext/utilities/apiRoutes.js +4 -3
- package/dist/esnext/utilities/bot-ua.d.ts +4 -0
- package/dist/esnext/utilities/bot-ua.js +54 -0
- package/dist/esnext/utilities/fetch.js +1 -26
- package/dist/esnext/utilities/log/index.d.ts +4 -1
- package/dist/esnext/utilities/log/index.js +4 -1
- package/dist/esnext/utilities/log/log-cache-api-status.d.ts +1 -0
- package/dist/esnext/utilities/log/log-cache-api-status.js +9 -0
- package/dist/esnext/utilities/log/log-cache-header.d.ts +10 -0
- package/dist/esnext/utilities/log/log-cache-header.js +30 -0
- package/dist/esnext/utilities/log/log-query-timeline.d.ts +12 -0
- package/dist/esnext/utilities/log/log-query-timeline.js +83 -0
- package/dist/esnext/utilities/log/log.d.ts +11 -8
- package/dist/esnext/utilities/log/log.js +24 -35
- package/dist/esnext/utilities/log/utils.d.ts +3 -0
- package/dist/esnext/utilities/log/utils.js +13 -0
- package/dist/esnext/utilities/template.d.ts +9 -0
- package/dist/esnext/utilities/template.js +23 -0
- package/dist/{worker/foundation/ShopifyProvider/types.js → esnext/utilities/web-api-polyfill.d.ts} +0 -0
- package/dist/esnext/utilities/web-api-polyfill.js +19 -0
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/entry-server.d.ts +22 -0
- package/dist/node/entry-server.js +581 -0
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +23 -0
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +132 -0
- package/dist/node/foundation/ServerRequestProvider/index.d.ts +1 -0
- package/dist/node/foundation/ServerRequestProvider/index.js +13 -0
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +25 -0
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.client.js +68 -0
- package/dist/node/foundation/ServerStateProvider/index.d.ts +2 -0
- package/dist/node/foundation/ServerStateProvider/index.js +6 -0
- package/dist/node/framework/CachingStrategy/index.d.ts +10 -0
- package/dist/node/framework/CachingStrategy/index.js +108 -0
- package/dist/node/framework/Hydration/Html.js +5 -12
- package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +20 -2
- package/dist/node/framework/Hydration/ServerComponentRequest.server.js +50 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +2 -2
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +2 -11
- package/dist/node/framework/cache/in-memory.js +6 -5
- package/dist/node/framework/cache.d.ts +3 -3
- package/dist/node/framework/cache.js +6 -20
- package/dist/node/framework/middleware.d.ts +7 -7
- package/dist/node/framework/middleware.js +14 -46
- package/dist/node/framework/plugin.js +33 -3
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.js +43 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +9 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.js +39 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +2 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +4 -1
- package/dist/node/framework/plugins/vite-plugin-platform-entry.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-platform-entry.js +75 -0
- package/dist/node/streaming.server.d.ts +21 -0
- package/dist/node/streaming.server.js +59 -0
- package/dist/node/types.d.ts +25 -25
- package/dist/node/utilities/apiRoutes.d.ts +1 -2
- package/dist/node/utilities/apiRoutes.js +4 -3
- package/dist/node/utilities/bot-ua.d.ts +4 -0
- package/dist/node/utilities/bot-ua.js +58 -0
- package/dist/node/utilities/defer.d.ts +6 -0
- package/dist/node/utilities/defer.js +18 -0
- package/dist/node/utilities/error.d.ts +1 -0
- package/dist/node/utilities/error.js +10 -0
- package/dist/node/utilities/log/index.d.ts +4 -0
- package/dist/node/utilities/log/index.js +18 -0
- package/dist/node/utilities/log/log-cache-api-status.d.ts +1 -0
- package/dist/node/utilities/log/log-cache-api-status.js +13 -0
- package/dist/node/utilities/log/log-cache-header.d.ts +10 -0
- package/dist/node/utilities/log/log-cache-header.js +35 -0
- package/dist/node/utilities/log/log-query-timeline.d.ts +12 -0
- package/dist/node/utilities/log/log-query-timeline.js +88 -0
- package/dist/node/utilities/log/log.d.ts +11 -8
- package/dist/node/utilities/log/log.js +27 -37
- package/dist/node/utilities/log/utils.d.ts +3 -0
- package/dist/node/utilities/log/utils.js +18 -0
- package/dist/node/utilities/template.d.ts +9 -0
- package/dist/node/utilities/template.js +27 -0
- package/dist/{worker/types.js → node/utilities/web-api-polyfill.d.ts} +0 -0
- package/dist/node/utilities/web-api-polyfill.js +43 -0
- package/package.json +20 -10
- package/web-polyfills.js +1 -0
- package/LICENSE.md +0 -7
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.d.ts +0 -22
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.js +0 -13
- package/dist/esnext/components/CartLineAttributes/index.d.ts +0 -1
- package/dist/esnext/components/CartLineAttributes/index.js +0 -1
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.d.ts +0 -21
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.js +0 -13
- package/dist/esnext/components/CartLineSelectedOptions/index.d.ts +0 -1
- package/dist/esnext/components/CartLineSelectedOptions/index.js +0 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.d.ts +0 -11
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +0 -17
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.d.ts +0 -9
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.js +0 -17
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.d.ts +0 -10
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.js +0 -16
- package/dist/esnext/components/SelectedVariantImage/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantImage/index.js +0 -1
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.d.ts +0 -15
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.js +0 -24
- package/dist/esnext/components/SelectedVariantMetafield/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantMetafield/index.js +0 -1
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.d.ts +0 -12
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.js +0 -22
- package/dist/esnext/components/SelectedVariantPrice/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantPrice/index.js +0 -1
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.d.ts +0 -8
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.js +0 -18
- package/dist/esnext/components/SelectedVariantShopPayButton/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantShopPayButton/index.js +0 -1
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.d.ts +0 -7
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.js +0 -16
- package/dist/esnext/components/SelectedVariantUnitPrice/index.d.ts +0 -1
- package/dist/esnext/components/SelectedVariantUnitPrice/index.js +0 -1
- package/dist/esnext/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/esnext/foundation/Helmet/Helmet.client.js +0 -10
- package/dist/esnext/foundation/Helmet/index.d.ts +0 -1
- package/dist/esnext/foundation/Helmet/index.js +0 -1
- package/dist/esnext/handle-event.d.ts +0 -23
- package/dist/esnext/handle-event.js +0 -132
- package/dist/esnext/handle-worker-event.d.ts +0 -11
- package/dist/esnext/handle-worker-event.js +0 -14
- package/dist/node/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/node/foundation/Helmet/Helmet.client.js +0 -17
- package/dist/node/foundation/Helmet/index.d.ts +0 -1
- package/dist/node/foundation/Helmet/index.js +0 -5
- package/dist/node/foundation/ssr-interop.d.ts +0 -29
- package/dist/node/foundation/ssr-interop.js +0 -39
- package/dist/node/handle-event.d.ts +0 -23
- package/dist/node/handle-event.js +0 -135
- package/dist/worker/constants.d.ts +0 -1
- package/dist/worker/constants.js +0 -1
- package/dist/worker/foundation/Helmet/Helmet.client.d.ts +0 -10
- package/dist/worker/foundation/Helmet/Helmet.client.js +0 -10
- package/dist/worker/foundation/Helmet/index.d.ts +0 -1
- package/dist/worker/foundation/Helmet/index.js +0 -1
- package/dist/worker/foundation/ShopifyProvider/types.d.ts +0 -15
- package/dist/worker/foundation/ssr-interop.d.ts +0 -29
- package/dist/worker/foundation/ssr-interop.js +0 -35
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.d.ts +0 -23
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.js +0 -57
- package/dist/worker/framework/config.d.ts +0 -6
- package/dist/worker/framework/config.js +0 -6
- package/dist/worker/framework/runtime.d.ts +0 -13
- package/dist/worker/framework/runtime.js +0 -27
- package/dist/worker/graphql/types/types.d.ts +0 -5761
- package/dist/worker/graphql/types/types.js +0 -1436
- package/dist/worker/handle-event.d.ts +0 -23
- package/dist/worker/handle-event.js +0 -132
- package/dist/worker/handle-worker-event.d.ts +0 -11
- package/dist/worker/handle-worker-event.js +0 -14
- package/dist/worker/types.d.ts +0 -96
- package/dist/worker/utilities/apiRoutes.d.ts +0 -21
- package/dist/worker/utilities/apiRoutes.js +0 -87
- package/dist/worker/utilities/log/log.d.ts +0 -18
- package/dist/worker/utilities/log/log.js +0 -77
- package/dist/worker/utilities/matchPath.d.ts +0 -10
- package/dist/worker/utilities/matchPath.js +0 -54
- package/dist/worker/utilities/timing.d.ts +0 -7
- package/dist/worker/utilities/timing.js +0 -14
- package/worker.js +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { graphiqlHtml } from './graphiql';
|
|
2
|
-
import handleEvent from '../handle-event';
|
|
3
2
|
export function graphiqlMiddleware({ shopifyConfig, dev, }) {
|
|
4
3
|
return async function (request, response, next) {
|
|
5
4
|
const graphiqlRequest = dev && isGraphiqlRequest(request);
|
|
@@ -14,51 +13,24 @@ export function graphiqlMiddleware({ shopifyConfig, dev, }) {
|
|
|
14
13
|
* Vite dev server plugin as well as production Node.js implementation.
|
|
15
14
|
*/
|
|
16
15
|
export function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypoint, devServer, }) {
|
|
16
|
+
/**
|
|
17
|
+
* We're running in the Node.js runtime without access to `fetch`,
|
|
18
|
+
* which is needed for proxy requests and server-side API requests.
|
|
19
|
+
*/
|
|
20
|
+
const webPolyfills = !globalThis.fetch || !globalThis.ReadableStream
|
|
21
|
+
? import('../utilities/web-api-polyfill')
|
|
22
|
+
: undefined;
|
|
17
23
|
return async function (request, response, next) {
|
|
18
|
-
|
|
24
|
+
var _a, _b, _c;
|
|
19
25
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!globalThis.fetch) {
|
|
25
|
-
const fetch = await import('node-fetch');
|
|
26
|
-
const { default: AbortController } = await import('abort-controller');
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
globalThis.fetch = fetch;
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
globalThis.Request = fetch.Request;
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
globalThis.Response = fetch.Response;
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
globalThis.Headers = fetch.Headers;
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
globalThis.AbortController = AbortController;
|
|
37
|
-
}
|
|
38
|
-
if (!globalThis.ReadableStream) {
|
|
39
|
-
const { ReadableStream, WritableStream, TransformStream } = await import('web-streams-polyfill/ponyfill');
|
|
40
|
-
Object.assign(globalThis, {
|
|
41
|
-
ReadableStream,
|
|
42
|
-
WritableStream,
|
|
43
|
-
TransformStream,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Dynamically import ServerComponentResponse after the `fetch`
|
|
48
|
-
* polyfill has loaded above.
|
|
49
|
-
*/
|
|
50
|
-
const { ServerComponentRequest } = await import('./Hydration/ServerComponentRequest.server');
|
|
51
|
-
const eventResponse = await handleEvent(
|
|
52
|
-
/**
|
|
53
|
-
* Mimic a `FetchEvent`
|
|
54
|
-
*/
|
|
55
|
-
{}, {
|
|
56
|
-
request: new ServerComponentRequest(request),
|
|
57
|
-
entrypoint: await getServerEntrypoint(),
|
|
58
|
-
indexTemplate,
|
|
59
|
-
streamableResponse: response,
|
|
26
|
+
await webPolyfills;
|
|
27
|
+
const entrypoint = await getServerEntrypoint();
|
|
28
|
+
const handleRequest = (_a = entrypoint.default) !== null && _a !== void 0 ? _a : entrypoint;
|
|
29
|
+
const eventResponse = await handleRequest(request, {
|
|
60
30
|
dev,
|
|
61
31
|
cache,
|
|
32
|
+
indexTemplate,
|
|
33
|
+
streamableResponse: response,
|
|
62
34
|
});
|
|
63
35
|
/**
|
|
64
36
|
* If a `Response` was returned, that means it was not streamed.
|
|
@@ -88,7 +60,7 @@ export function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypo
|
|
|
88
60
|
*/
|
|
89
61
|
try {
|
|
90
62
|
const template = typeof indexTemplate === 'function'
|
|
91
|
-
? await indexTemplate(
|
|
63
|
+
? await indexTemplate((_c = (_b = request.originalUrl) !== null && _b !== void 0 ? _b : request.url) !== null && _c !== void 0 ? _c : '')
|
|
92
64
|
: indexTemplate;
|
|
93
65
|
const html = template.replace(`<div id="root"></div>`, `<div id="root"><pre><code>${e.stack}</code></pre></div>`);
|
|
94
66
|
response.write(html);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import hydrogenConfig from './plugins/vite-plugin-hydrogen-config';
|
|
2
|
-
import hydrogenMiddleware from './plugins/vite-plugin-hydrogen-middleware';
|
|
2
|
+
import hydrogenMiddleware, { HYDROGEN_DEFAULT_SERVER_ENTRY, } from './plugins/vite-plugin-hydrogen-middleware';
|
|
3
|
+
import hydrogenClientMiddleware from './plugins/vite-plugin-hydrogen-client-middleware';
|
|
4
|
+
import platformEntry from './plugins/vite-plugin-platform-entry';
|
|
3
5
|
// @ts-ignore
|
|
4
6
|
import rsc from '@shopify/hydrogen/vendor/react-server-dom-vite/plugin';
|
|
5
7
|
import ssrInterop from './plugins/vite-plugin-ssr-interop';
|
|
6
8
|
import purgeQueryCache from './plugins/vite-plugin-purge-query-cache';
|
|
9
|
+
import hydrationAutoImport from './plugins/vite-plugin-hydration-auto-import';
|
|
7
10
|
import inspect from 'vite-plugin-inspect';
|
|
8
11
|
import react from '@vitejs/plugin-react';
|
|
9
12
|
import path from 'path';
|
|
@@ -11,17 +14,25 @@ export default (shopifyConfig, pluginOptions = {}) => {
|
|
|
11
14
|
return [
|
|
12
15
|
process.env.VITE_INSPECT && inspect(),
|
|
13
16
|
hydrogenConfig(),
|
|
17
|
+
hydrogenClientMiddleware(),
|
|
14
18
|
hydrogenMiddleware(shopifyConfig, pluginOptions),
|
|
15
19
|
react(),
|
|
20
|
+
hydrationAutoImport(),
|
|
16
21
|
ssrInterop(),
|
|
17
22
|
rsc({
|
|
18
23
|
clientComponentPaths: [
|
|
19
24
|
path.join(path.dirname(require.resolve('@shopify/hydrogen/package.json'))),
|
|
20
25
|
],
|
|
21
|
-
isServerComponentImporterAllowed(importer) {
|
|
22
|
-
|
|
26
|
+
isServerComponentImporterAllowed(importer, source) {
|
|
27
|
+
// Always allow the entry server (e.g. App.server.jsx) to be imported
|
|
28
|
+
// in other files such as worker.js or server.js.
|
|
29
|
+
const entryServer = process.env.HYDROGEN_SERVER_ENTRY || HYDROGEN_DEFAULT_SERVER_ENTRY;
|
|
30
|
+
return (source.includes(entryServer) ||
|
|
31
|
+
// TODO update this after handleEvent is replaced with handleRequest
|
|
32
|
+
/(handle-worker-event|index|entry-server)\.js/.test(importer));
|
|
23
33
|
},
|
|
24
34
|
}),
|
|
35
|
+
platformEntry(),
|
|
25
36
|
pluginOptions.purgeQueryCacheOnBuild && purgeQueryCache(),
|
|
26
37
|
];
|
|
27
38
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { normalizePath } from 'vite';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import MagicString from 'magic-string';
|
|
4
|
+
const HYDROGEN_ENTRY_FILE = 'hydrogen-entry-client.jsx';
|
|
5
|
+
export default () => {
|
|
6
|
+
let config;
|
|
7
|
+
return {
|
|
8
|
+
name: 'vite-plugin-hydration-auto-import',
|
|
9
|
+
enforce: 'pre',
|
|
10
|
+
configResolved(_config) {
|
|
11
|
+
config = _config;
|
|
12
|
+
},
|
|
13
|
+
resolveId(id, importer) {
|
|
14
|
+
if ((/^\/?@shopify\/hydrogen\/entry-client$/.test(id) ||
|
|
15
|
+
id.endsWith(path.sep + HYDROGEN_ENTRY_FILE)) &&
|
|
16
|
+
normalizePath(importer || '').endsWith('/index.html')) {
|
|
17
|
+
// Make this virtual import look like a local project file
|
|
18
|
+
// to enable React Refresh normally.
|
|
19
|
+
return path.join(config.root, HYDROGEN_ENTRY_FILE + '?virtual');
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
},
|
|
23
|
+
load(id) {
|
|
24
|
+
if (id.includes(HYDROGEN_ENTRY_FILE + '?virtual')) {
|
|
25
|
+
const code = new MagicString(`import renderHydrogen from '@shopify/hydrogen/entry-client';\n` +
|
|
26
|
+
`export default renderHydrogen((props) => props.children);`);
|
|
27
|
+
return {
|
|
28
|
+
code: code.toString(),
|
|
29
|
+
map: code.generateMap({
|
|
30
|
+
file: HYDROGEN_ENTRY_FILE,
|
|
31
|
+
source: HYDROGEN_ENTRY_FILE,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Plugin } from 'vite';
|
|
2
|
+
declare const _default: () => Plugin;
|
|
3
|
+
/**
|
|
4
|
+
* This dev server middleware prevents Vite from applying immutable cache control headers to client
|
|
5
|
+
* components. These client components are part of the user's local source, but since they are
|
|
6
|
+
* referenced via import globs in the `react-dom-server-vite` NPM package, Vite assumes they
|
|
7
|
+
* are 3P deps that can be cached. This middleware responds to the requests early with `no-cache`.
|
|
8
|
+
*/
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { send } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* This dev server middleware prevents Vite from applying immutable cache control headers to client
|
|
4
|
+
* components. These client components are part of the user's local source, but since they are
|
|
5
|
+
* referenced via import globs in the `react-dom-server-vite` NPM package, Vite assumes they
|
|
6
|
+
* are 3P deps that can be cached. This middleware responds to the requests early with `no-cache`.
|
|
7
|
+
*/
|
|
8
|
+
export default () => {
|
|
9
|
+
return {
|
|
10
|
+
name: 'vite-plugin-hydrogen-client-middleware',
|
|
11
|
+
enforce: 'pre',
|
|
12
|
+
configureServer(server) {
|
|
13
|
+
server.middlewares.use(async (req, res, next) => {
|
|
14
|
+
const url = req.url;
|
|
15
|
+
try {
|
|
16
|
+
if (url.includes('.client.js') &&
|
|
17
|
+
url.includes('?v=') &&
|
|
18
|
+
!url.includes('node_modules')) {
|
|
19
|
+
const result = await server.transformRequest(url, { html: false });
|
|
20
|
+
if (result) {
|
|
21
|
+
return send(req, res, result.code, 'js', {
|
|
22
|
+
etag: result.etag,
|
|
23
|
+
cacheControl: 'no-cache',
|
|
24
|
+
headers: server.config.server.headers,
|
|
25
|
+
map: result.map,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
next(e);
|
|
32
|
+
}
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import type { HydrogenVitePluginOptions, ShopifyConfig } from '../../types';
|
|
3
|
+
export declare const HYDROGEN_DEFAULT_SERVER_ENTRY = "/src/App.server";
|
|
3
4
|
declare const _default: (shopifyConfig: ShopifyConfig, pluginOptions: HydrogenVitePluginOptions) => Plugin;
|
|
4
5
|
export default _default;
|
|
5
6
|
declare global {
|
|
6
7
|
var Oxygen: {
|
|
7
|
-
env:
|
|
8
|
+
env: any;
|
|
8
9
|
[key: string]: any;
|
|
9
10
|
};
|
|
10
11
|
}
|
|
@@ -4,6 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import { promises as fs } from 'fs';
|
|
5
5
|
import { hydrogenMiddleware, graphiqlMiddleware } from '../middleware';
|
|
6
6
|
import { InMemoryCache } from '../cache/in-memory';
|
|
7
|
+
export const HYDROGEN_DEFAULT_SERVER_ENTRY = '/src/App.server';
|
|
7
8
|
export default (shopifyConfig, pluginOptions) => {
|
|
8
9
|
return {
|
|
9
10
|
name: 'vite-plugin-hydrogen-middleware',
|
|
@@ -31,7 +32,8 @@ export default (shopifyConfig, pluginOptions) => {
|
|
|
31
32
|
dev: true,
|
|
32
33
|
shopifyConfig,
|
|
33
34
|
indexTemplate: getIndexTemplate,
|
|
34
|
-
getServerEntrypoint:
|
|
35
|
+
getServerEntrypoint: () => server.ssrLoadModule(process.env.HYDROGEN_SERVER_ENTRY ||
|
|
36
|
+
HYDROGEN_DEFAULT_SERVER_ENTRY),
|
|
35
37
|
devServer: server,
|
|
36
38
|
cache: (pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.devCache)
|
|
37
39
|
? new InMemoryCache()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { normalizePath } from 'vite';
|
|
2
|
+
import { HYDROGEN_DEFAULT_SERVER_ENTRY } from './vite-plugin-hydrogen-middleware';
|
|
3
|
+
import MagicString from 'magic-string';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
const SSR_BUNDLE_NAME = 'index.js';
|
|
7
|
+
export default () => {
|
|
8
|
+
let config;
|
|
9
|
+
let isESM;
|
|
10
|
+
return {
|
|
11
|
+
name: 'vite-plugin-platform-entry',
|
|
12
|
+
enforce: 'pre',
|
|
13
|
+
configResolved(_config) {
|
|
14
|
+
config = _config;
|
|
15
|
+
if (config.build.ssr) {
|
|
16
|
+
const { output = {} } = config.build.rollupOptions || {};
|
|
17
|
+
const { format = '' } = (Array.isArray(output) ? output[0] : output) || {};
|
|
18
|
+
isESM = Boolean(process.env.WORKER) || ['es', 'esm'].includes(format);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
resolveId(source, importer) {
|
|
22
|
+
if (normalizePath(source).includes('@shopify/hydrogen/platforms/')) {
|
|
23
|
+
const hydrogenPath = path.dirname(require.resolve('@shopify/hydrogen/package.json'));
|
|
24
|
+
const platformEntryName = source.split(path.sep).pop() || '';
|
|
25
|
+
const platformEntryPath = path.resolve(hydrogenPath, 'dist', 'esnext', 'platforms', platformEntryName);
|
|
26
|
+
return this.resolve(platformEntryPath, importer, {
|
|
27
|
+
skipSelf: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
},
|
|
32
|
+
transform(code, id) {
|
|
33
|
+
if (normalizePath(id).includes('@shopify/hydrogen/dist/esnext/platforms/')) {
|
|
34
|
+
code = code
|
|
35
|
+
.replace('__SERVER_ENTRY__', process.env.HYDROGEN_SERVER_ENTRY || HYDROGEN_DEFAULT_SERVER_ENTRY)
|
|
36
|
+
.replace('__INDEX_TEMPLATE__', normalizePath(path.resolve(config.root, config.build.outDir, '..', 'client', 'index.html')));
|
|
37
|
+
const ms = new MagicString(code);
|
|
38
|
+
return {
|
|
39
|
+
code: ms.toString(),
|
|
40
|
+
map: ms.generateMap({ file: id, source: id }),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
generateBundle(options, bundle) {
|
|
45
|
+
if (config.build.ssr) {
|
|
46
|
+
const [[key, value]] = Object.entries(bundle);
|
|
47
|
+
delete bundle[key];
|
|
48
|
+
value.fileName = SSR_BUNDLE_NAME;
|
|
49
|
+
bundle[SSR_BUNDLE_NAME] = value;
|
|
50
|
+
// This ensures the file has a proper
|
|
51
|
+
// default export instead of exporting an
|
|
52
|
+
// object containing a 'default' property.
|
|
53
|
+
if (value.type === 'chunk' && !isESM) {
|
|
54
|
+
value.code = value.code.replace(/((^|;)[\s]*)exports\[['"]default['"]\]\s*=/m, '$1module.exports =');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
writeBundle(options) {
|
|
59
|
+
if (config.build.ssr && options.dir) {
|
|
60
|
+
const mainFile = `./${SSR_BUNDLE_NAME}`;
|
|
61
|
+
const packageJson = {
|
|
62
|
+
type: isESM ? 'module' : 'commonjs',
|
|
63
|
+
main: mainFile,
|
|
64
|
+
exports: { '.': mainFile, mainFile },
|
|
65
|
+
};
|
|
66
|
+
fs.writeFileSync(path.join(options.dir, 'package.json'), JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -2,4 +2,153 @@
|
|
|
2
2
|
* The `useProduct` hook returns the product object of the nearest `ProductProvider`. It must be a descendent of
|
|
3
3
|
* a `ProductProvider` component.
|
|
4
4
|
*/
|
|
5
|
-
export declare function useProduct():
|
|
5
|
+
export declare function useProduct(): {
|
|
6
|
+
id?: string | undefined;
|
|
7
|
+
title?: string | undefined;
|
|
8
|
+
handle?: any;
|
|
9
|
+
compareAtPriceRange?: Partial<{
|
|
10
|
+
__typename?: "ProductPriceRange" | undefined;
|
|
11
|
+
} & {
|
|
12
|
+
maxVariantPrice: {
|
|
13
|
+
__typename?: "MoneyV2" | undefined;
|
|
14
|
+
} & {
|
|
15
|
+
__typename?: "MoneyV2" | undefined;
|
|
16
|
+
} & Pick<import("../../graphql/types/types").MoneyV2, "currencyCode" | "amount">;
|
|
17
|
+
minVariantPrice: {
|
|
18
|
+
__typename?: "MoneyV2" | undefined;
|
|
19
|
+
} & {
|
|
20
|
+
__typename?: "MoneyV2" | undefined;
|
|
21
|
+
} & Pick<import("../../graphql/types/types").MoneyV2, "currencyCode" | "amount">;
|
|
22
|
+
}> | undefined;
|
|
23
|
+
descriptionHtml?: any;
|
|
24
|
+
priceRange?: Partial<{
|
|
25
|
+
__typename?: "ProductPriceRange" | undefined;
|
|
26
|
+
} & {
|
|
27
|
+
maxVariantPrice: {
|
|
28
|
+
__typename?: "MoneyV2" | undefined;
|
|
29
|
+
} & {
|
|
30
|
+
__typename?: "MoneyV2" | undefined;
|
|
31
|
+
} & Pick<import("../../graphql/types/types").MoneyV2, "currencyCode" | "amount">;
|
|
32
|
+
minVariantPrice: {
|
|
33
|
+
__typename?: "MoneyV2" | undefined;
|
|
34
|
+
} & {
|
|
35
|
+
__typename?: "MoneyV2" | undefined;
|
|
36
|
+
} & Pick<import("../../graphql/types/types").MoneyV2, "currencyCode" | "amount">;
|
|
37
|
+
}> | undefined;
|
|
38
|
+
media?: (({
|
|
39
|
+
__typename?: "ExternalVideo" | undefined;
|
|
40
|
+
} & {
|
|
41
|
+
__typename?: "ExternalVideo" | undefined;
|
|
42
|
+
} & Pick<import("../../graphql/types/types").ExternalVideo, "mediaContentType"> & {
|
|
43
|
+
__typename?: "ExternalVideo" | undefined;
|
|
44
|
+
} & Pick<import("../../graphql/types/types").ExternalVideo, "id" | "host" | "embeddedUrl">) | ({
|
|
45
|
+
__typename?: "MediaImage" | undefined;
|
|
46
|
+
} & {
|
|
47
|
+
__typename?: "MediaImage" | undefined;
|
|
48
|
+
} & Pick<import("../../graphql/types/types").MediaImage, "mediaContentType"> & {
|
|
49
|
+
image?: import("../../graphql/types/types").Maybe<{
|
|
50
|
+
__typename?: "Image" | undefined;
|
|
51
|
+
} & {
|
|
52
|
+
__typename?: "Image" | undefined;
|
|
53
|
+
} & Pick<import("../../graphql/types/types").Image, "id" | "height" | "width" | "url" | "altText">> | undefined;
|
|
54
|
+
}) | ({
|
|
55
|
+
__typename?: "Model3d" | undefined;
|
|
56
|
+
} & {
|
|
57
|
+
__typename?: "Model3d" | undefined;
|
|
58
|
+
} & Pick<import("../../graphql/types/types").Model3d, "mediaContentType"> & {
|
|
59
|
+
__typename?: "Model3d" | undefined;
|
|
60
|
+
} & Pick<import("../../graphql/types/types").Model3d, "id" | "alt" | "mediaContentType"> & {
|
|
61
|
+
previewImage?: import("../../graphql/types/types").Maybe<{
|
|
62
|
+
__typename?: "Image" | undefined;
|
|
63
|
+
} & Pick<import("../../graphql/types/types").Image, "url">> | undefined;
|
|
64
|
+
sources: ({
|
|
65
|
+
__typename?: "Model3dSource" | undefined;
|
|
66
|
+
} & Pick<import("../../graphql/types/types").Model3dSource, "url">)[];
|
|
67
|
+
}) | ({
|
|
68
|
+
__typename?: "Video" | undefined;
|
|
69
|
+
} & {
|
|
70
|
+
__typename?: "Video" | undefined;
|
|
71
|
+
} & Pick<import("../../graphql/types/types").Video, "mediaContentType"> & {
|
|
72
|
+
__typename?: "Video" | undefined;
|
|
73
|
+
} & Pick<import("../../graphql/types/types").Video, "id"> & {
|
|
74
|
+
previewImage?: import("../../graphql/types/types").Maybe<{
|
|
75
|
+
__typename?: "Image" | undefined;
|
|
76
|
+
} & Pick<import("../../graphql/types/types").Image, "url">> | undefined;
|
|
77
|
+
sources: ({
|
|
78
|
+
__typename?: "VideoSource" | undefined;
|
|
79
|
+
} & Pick<import("../../graphql/types/types").VideoSource, "url" | "mimeType">)[];
|
|
80
|
+
}))[] | undefined;
|
|
81
|
+
mediaConnection?: ({
|
|
82
|
+
__typename?: "MediaConnection" | undefined;
|
|
83
|
+
} & {
|
|
84
|
+
edges: ({
|
|
85
|
+
__typename?: "MediaEdge" | undefined;
|
|
86
|
+
} & {
|
|
87
|
+
node: ({
|
|
88
|
+
__typename?: "ExternalVideo" | undefined;
|
|
89
|
+
} & {
|
|
90
|
+
__typename?: "ExternalVideo" | undefined;
|
|
91
|
+
} & Pick<import("../../graphql/types/types").ExternalVideo, "mediaContentType"> & {
|
|
92
|
+
__typename?: "ExternalVideo" | undefined;
|
|
93
|
+
} & Pick<import("../../graphql/types/types").ExternalVideo, "id" | "host" | "embeddedUrl">) | ({
|
|
94
|
+
__typename?: "MediaImage" | undefined;
|
|
95
|
+
} & {
|
|
96
|
+
__typename?: "MediaImage" | undefined;
|
|
97
|
+
} & Pick<import("../../graphql/types/types").MediaImage, "mediaContentType"> & {
|
|
98
|
+
image?: import("../../graphql/types/types").Maybe<{
|
|
99
|
+
__typename?: "Image" | undefined;
|
|
100
|
+
} & {
|
|
101
|
+
__typename?: "Image" | undefined;
|
|
102
|
+
} & Pick<import("../../graphql/types/types").Image, "id" | "height" | "width" | "url" | "altText">> | undefined;
|
|
103
|
+
}) | ({
|
|
104
|
+
__typename?: "Model3d" | undefined;
|
|
105
|
+
} & {
|
|
106
|
+
__typename?: "Model3d" | undefined;
|
|
107
|
+
} & Pick<import("../../graphql/types/types").Model3d, "mediaContentType"> & {
|
|
108
|
+
__typename?: "Model3d" | undefined;
|
|
109
|
+
} & Pick<import("../../graphql/types/types").Model3d, "id" | "alt" | "mediaContentType"> & {
|
|
110
|
+
previewImage?: import("../../graphql/types/types").Maybe<{
|
|
111
|
+
__typename?: "Image" | undefined;
|
|
112
|
+
} & Pick<import("../../graphql/types/types").Image, "url">> | undefined;
|
|
113
|
+
sources: ({
|
|
114
|
+
__typename?: "Model3dSource" | undefined;
|
|
115
|
+
} & Pick<import("../../graphql/types/types").Model3dSource, "url">)[];
|
|
116
|
+
}) | ({
|
|
117
|
+
__typename?: "Video" | undefined;
|
|
118
|
+
} & {
|
|
119
|
+
__typename?: "Video" | undefined;
|
|
120
|
+
} & Pick<import("../../graphql/types/types").Video, "mediaContentType"> & {
|
|
121
|
+
__typename?: "Video" | undefined;
|
|
122
|
+
} & Pick<import("../../graphql/types/types").Video, "id"> & {
|
|
123
|
+
previewImage?: import("../../graphql/types/types").Maybe<{
|
|
124
|
+
__typename?: "Image" | undefined;
|
|
125
|
+
} & Pick<import("../../graphql/types/types").Image, "url">> | undefined;
|
|
126
|
+
sources: ({
|
|
127
|
+
__typename?: "VideoSource" | undefined;
|
|
128
|
+
} & Pick<import("../../graphql/types/types").VideoSource, "url" | "mimeType">)[];
|
|
129
|
+
});
|
|
130
|
+
})[];
|
|
131
|
+
}) | undefined;
|
|
132
|
+
metafields?: import("../../types").ParsedMetafield[] | undefined;
|
|
133
|
+
metafieldsConnection?: import("../../types").GraphQLConnection<import("../../types").RawMetafield> | undefined;
|
|
134
|
+
images?: Partial<import("../../graphql/types/types").Image>[] | undefined;
|
|
135
|
+
imagesConnection?: import("../../types").GraphQLConnection<import("../../components/Image/ImageFragment").ImageFragmentFragment> | undefined;
|
|
136
|
+
collections?: Partial<import("../../graphql/types/types").Collection>[] | undefined;
|
|
137
|
+
collectionsConnection?: import("../../types").GraphQLConnection<Partial<import("../../graphql/types/types").Collection>> | undefined;
|
|
138
|
+
variants?: import("../useProductOptions").Variant[] | Partial<import("../useProductOptions").Variant>[] | undefined;
|
|
139
|
+
variantsConnection?: import("../../types").GraphQLConnection<import("../useProductOptions").Variant> | undefined;
|
|
140
|
+
options?: import("../useProductOptions").OptionWithValues[] | undefined;
|
|
141
|
+
selectedVariant?: import("../useProductOptions").Variant | null | undefined;
|
|
142
|
+
setSelectedVariant?: import("../useProductOptions").SelectVariantCallback | undefined;
|
|
143
|
+
selectedOptions?: import("../useProductOptions").SelectedOptions | undefined;
|
|
144
|
+
setSelectedOption?: import("../useProductOptions").SelectOptionCallback | undefined;
|
|
145
|
+
setSelectedOptions?: import("../useProductOptions").SelectOptionsCallback | undefined;
|
|
146
|
+
isOptionInStock?: import("../useProductOptions").OptionsInStockCallback | undefined;
|
|
147
|
+
setSelectedSellingPlan?: import("../useProductOptions").SelectedSellingPlanCallback | undefined;
|
|
148
|
+
selectedSellingPlan?: import("../useProductOptions").SellingPlan | undefined;
|
|
149
|
+
selectedSellingPlanAllocation?: import("../useProductOptions").SellingPlanAllocation | undefined;
|
|
150
|
+
sellingPlanGroups?: (Omit<import("../useProductOptions").SellingPlanGroup, "sellingPlans"> & {
|
|
151
|
+
sellingPlans: import("../useProductOptions").SellingPlan[];
|
|
152
|
+
})[] | undefined;
|
|
153
|
+
sellingPlanGroupsConnection?: import("../../types").GraphQLConnection<import("../useProductOptions").SellingPlanGroup> | undefined;
|
|
154
|
+
};
|
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import { ProductContext } from '../../components/ProductProvider/context';
|
|
2
|
+
import { ProductContext, ProductOptionsContext, } from '../../components/ProductProvider/context';
|
|
3
3
|
/**
|
|
4
4
|
* The `useProduct` hook returns the product object of the nearest `ProductProvider`. It must be a descendent of
|
|
5
5
|
* a `ProductProvider` component.
|
|
6
6
|
*/
|
|
7
7
|
export function useProduct() {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var _a;
|
|
9
|
+
const data = useContext(ProductContext);
|
|
10
|
+
let state;
|
|
11
|
+
try {
|
|
12
|
+
state = (_a = useContext(ProductOptionsContext)) !== null && _a !== void 0 ? _a : { ...stateFallback };
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// for server components which can't use state
|
|
16
|
+
state = { ...stateFallback };
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
...data,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const stateFallback = {
|
|
24
|
+
variants: undefined,
|
|
25
|
+
variantsConnection: undefined,
|
|
26
|
+
options: undefined,
|
|
27
|
+
selectedVariant: undefined,
|
|
28
|
+
setSelectedVariant: NotAvailable('setSelectedVariant'),
|
|
29
|
+
selectedOptions: undefined,
|
|
30
|
+
setSelectedOption: NotAvailable('setSelectedOption'),
|
|
31
|
+
setSelectedOptions: NotAvailable('setSelectedOptions'),
|
|
32
|
+
isOptionInStock: undefined,
|
|
33
|
+
setSelectedSellingPlan: NotAvailable('setSelectedSellingPlan'),
|
|
34
|
+
selectedSellingPlan: undefined,
|
|
35
|
+
selectedSellingPlanAllocation: undefined,
|
|
36
|
+
sellingPlanGroups: undefined,
|
|
37
|
+
sellingPlanGroupsConnection: undefined,
|
|
38
|
+
};
|
|
39
|
+
function NotAvailable(propName) {
|
|
40
|
+
return () => {
|
|
41
|
+
throw new Error(`The '${propName}' function is not available in server components`);
|
|
42
|
+
};
|
|
10
43
|
}
|
|
@@ -38,7 +38,7 @@ export interface ProductOptionsHookValue {
|
|
|
38
38
|
/** An array of the product's options and values. */
|
|
39
39
|
options: OptionWithValues[];
|
|
40
40
|
/** The selected variant. */
|
|
41
|
-
selectedVariant?: Variant;
|
|
41
|
+
selectedVariant?: Variant | null;
|
|
42
42
|
/** A callback to set the selected variant to the variant passed as an argument. */
|
|
43
43
|
setSelectedVariant: SelectVariantCallback;
|
|
44
44
|
selectedOptions: SelectedOptions;
|
|
@@ -10,5 +10,5 @@ export declare function useProductOptions({ variants: variantsConnection, sellin
|
|
|
10
10
|
/** The product's `SellingPlanGroups`. */
|
|
11
11
|
sellingPlanGroups?: GraphQLConnection<SellingPlanGroup>;
|
|
12
12
|
/** The initially selected variant. */
|
|
13
|
-
initialVariantId?: Variant['id'];
|
|
13
|
+
initialVariantId?: Variant['id'] | null;
|
|
14
14
|
}): ProductOptionsHookValue;
|
|
@@ -14,9 +14,9 @@ export function useProductOptions({ variants: variantsConnection, sellingPlanGro
|
|
|
14
14
|
* Track the selectedVariant within the hook. If `initialVariantId`
|
|
15
15
|
* is passed, use that as an initial value.
|
|
16
16
|
*/
|
|
17
|
-
const [selectedVariant, setSelectedVariant] = useState(initialVariantId
|
|
18
|
-
?
|
|
19
|
-
:
|
|
17
|
+
const [selectedVariant, setSelectedVariant] = useState(initialVariantId == null
|
|
18
|
+
? initialVariantId
|
|
19
|
+
: variants.find((variant) => variant.id === initialVariantId));
|
|
20
20
|
/**
|
|
21
21
|
* Track the selectedOptions within the hook. If a `initialVariantId`
|
|
22
22
|
* is passed, use that to select initial options.
|
|
@@ -34,9 +34,9 @@ export function useProductOptions({ variants: variantsConnection, sellingPlanGro
|
|
|
34
34
|
* values.
|
|
35
35
|
*/
|
|
36
36
|
useEffect(() => {
|
|
37
|
-
const selectedVariant = initialVariantId
|
|
38
|
-
?
|
|
39
|
-
:
|
|
37
|
+
const selectedVariant = initialVariantId == null
|
|
38
|
+
? initialVariantId
|
|
39
|
+
: variants.find((variant) => variant.id === initialVariantId);
|
|
40
40
|
setSelectedVariant(selectedVariant);
|
|
41
41
|
const selectedOptions = (selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.selectedOptions)
|
|
42
42
|
? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ASTNode } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CachingStrategy, PreloadOptions } from '../../types';
|
|
3
3
|
export interface UseShopQueryResponse<T> {
|
|
4
4
|
/** The data returned by the query. */
|
|
5
5
|
data: T;
|
|
@@ -8,15 +8,22 @@ export interface UseShopQueryResponse<T> {
|
|
|
8
8
|
/**
|
|
9
9
|
* The `useShopQuery` hook allows you to make server-only GraphQL queries to the Storefront API. It must be a descendent of a `ShopifyProvider` component.
|
|
10
10
|
*/
|
|
11
|
-
export declare function useShopQuery<T>({ query, variables, cache, locale, }: {
|
|
11
|
+
export declare function useShopQuery<T>({ query, variables, cache, locale, preload, }: {
|
|
12
12
|
/** A string of the GraphQL query.
|
|
13
13
|
* If no query is provided, useShopQuery will make no calls to the Storefront API.
|
|
14
14
|
*/
|
|
15
15
|
query?: ASTNode | string;
|
|
16
16
|
/** An object of the variables for the GraphQL query. */
|
|
17
17
|
variables?: Record<string, any>;
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/** The [caching strategy](/custom-storefronts/hydrogen/framework/cache#caching-strategies) to
|
|
19
|
+
* help you determine which cache control header to set.
|
|
20
|
+
*/
|
|
21
|
+
cache?: CachingStrategy;
|
|
20
22
|
/** A string corresponding to a valid locale identifier like `en-us` used to make the request. */
|
|
21
23
|
locale?: string;
|
|
24
|
+
/** Whether to[preload the query](/custom-storefronts/hydrogen/framework/preloaded-queries).
|
|
25
|
+
* Defaults to `false`. Specify `true` to preload the query for the URL or `'*'`
|
|
26
|
+
* to preload the query for all requests.
|
|
27
|
+
*/
|
|
28
|
+
preload?: PreloadOptions;
|
|
22
29
|
}): UseShopQueryResponse<T>;
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { useShop } from '../../foundation/useShop';
|
|
2
|
-
import {
|
|
2
|
+
import { getLoggerWithContext } from '../../utilities/log';
|
|
3
3
|
import { useQuery } from '../../foundation/useQuery';
|
|
4
4
|
import { fetchBuilder, graphqlRequestBody } from '../../utilities';
|
|
5
5
|
import { getConfig } from '../../framework/config';
|
|
6
|
+
import { useServerRequest } from '../../foundation/ServerRequestProvider';
|
|
6
7
|
/**
|
|
7
8
|
* The `useShopQuery` hook allows you to make server-only GraphQL queries to the Storefront API. It must be a descendent of a `ShopifyProvider` component.
|
|
8
9
|
*/
|
|
9
|
-
export function useShopQuery({ query, variables = {}, cache
|
|
10
|
+
export function useShopQuery({ query, variables = {}, cache, locale = '', preload = false, }) {
|
|
10
11
|
if (!import.meta.env.SSR) {
|
|
11
12
|
throw new Error('Shopify Storefront API requests should only be made from the server.');
|
|
12
13
|
}
|
|
14
|
+
const serverRequest = useServerRequest();
|
|
15
|
+
const log = getLoggerWithContext(serverRequest);
|
|
13
16
|
const body = query ? graphqlRequestBody(query, variables) : '';
|
|
14
17
|
const { request, key } = createShopRequest(body, locale);
|
|
15
18
|
const { data, error: fetchError } = useQuery(key, query
|
|
16
19
|
? fetchBuilder(request)
|
|
17
20
|
: // If no query, avoid calling SFAPI & return nothing
|
|
18
|
-
async () => ({ data: undefined, errors: undefined }), { cache });
|
|
21
|
+
async () => ({ data: undefined, errors: undefined }), { cache, preload });
|
|
19
22
|
/**
|
|
20
23
|
* The fetch request itself failed, so we handle that differently than a GraphQL error
|
|
21
24
|
*/
|
package/dist/esnext/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export * from './foundation/';
|
|
|
2
2
|
export * from './components/';
|
|
3
3
|
export * from './hooks/';
|
|
4
4
|
export { flattenConnection, fetchBuilder, graphqlRequestBody, decodeShopifyId, isClient, getTime, } from './utilities';
|
|
5
|
-
export { log, setLogger, Logger } from './utilities/log';
|
|
5
|
+
export { log, setLogger, setLoggerOptions, Logger } from './utilities/log';
|
|
6
6
|
export { LocalizationProvider } from './components/LocalizationProvider/LocalizationProvider.server';
|
|
7
7
|
export * from './hooks/useShopQuery';
|
|
8
8
|
export { CartQuery } from './graphql/graphql-constants';
|
|
9
|
+
export { generateCacheControlHeader, NoStore, CacheSeconds, CacheMinutes, CacheHours, CacheDays, CacheWeeks, CacheMonths, CacheCustom, } from './framework/CachingStrategy';
|