@shopify/hydrogen 0.1.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/README.md +29 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/dist/esnext/client.d.ts +7 -0
- package/dist/esnext/client.js +7 -0
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +15 -0
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +44 -0
- package/dist/esnext/components/AddToCartButton/index.d.ts +1 -0
- package/dist/esnext/components/AddToCartButton/index.js +1 -0
- package/dist/esnext/components/BuyNowButton/BuyNowButton.d.ts +12 -0
- package/dist/esnext/components/BuyNowButton/BuyNowButton.js +29 -0
- package/dist/esnext/components/BuyNowButton/index.d.ts +1 -0
- package/dist/esnext/components/BuyNowButton/index.js +1 -0
- package/dist/esnext/components/CartCheckoutButton/CartCheckoutButton.client.d.ts +7 -0
- package/dist/esnext/components/CartCheckoutButton/CartCheckoutButton.client.js +14 -0
- package/dist/esnext/components/CartCheckoutButton/index.d.ts +1 -0
- package/dist/esnext/components/CartCheckoutButton/index.js +1 -0
- package/dist/esnext/components/CartContainer/CartContainer.client.d.ts +9 -0
- package/dist/esnext/components/CartContainer/CartContainer.client.js +24 -0
- package/dist/esnext/components/CartContainer/index.d.ts +1 -0
- package/dist/esnext/components/CartContainer/index.js +1 -0
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.d.ts +10 -0
- package/dist/esnext/components/CartLineAttributes/CartLineAttributes.client.js +9 -0
- package/dist/esnext/components/CartLineAttributes/index.d.ts +1 -0
- package/dist/esnext/components/CartLineAttributes/index.js +1 -0
- package/dist/esnext/components/CartLineImage/CartLineImage.client.d.ts +6 -0
- package/dist/esnext/components/CartLineImage/CartLineImage.client.js +8 -0
- package/dist/esnext/components/CartLineImage/index.d.ts +1 -0
- package/dist/esnext/components/CartLineImage/index.js +1 -0
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.d.ts +6 -0
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +17 -0
- package/dist/esnext/components/CartLinePrice/index.d.ts +1 -0
- package/dist/esnext/components/CartLinePrice/index.js +1 -0
- package/dist/esnext/components/CartLineProductTitle/CartLineProductTitle.client.d.ts +3 -0
- package/dist/esnext/components/CartLineProductTitle/CartLineProductTitle.client.js +8 -0
- package/dist/esnext/components/CartLineProductTitle/index.d.ts +1 -0
- package/dist/esnext/components/CartLineProductTitle/index.js +1 -0
- package/dist/esnext/components/CartLineProvider/CartLineProvider.client.d.ts +6 -0
- package/dist/esnext/components/CartLineProvider/CartLineProvider.client.js +5 -0
- package/dist/esnext/components/CartLineProvider/context.d.ts +26 -0
- package/dist/esnext/components/CartLineProvider/context.js +2 -0
- package/dist/esnext/components/CartLineProvider/hooks.d.ts +26 -0
- package/dist/esnext/components/CartLineProvider/hooks.js +9 -0
- package/dist/esnext/components/CartLineProvider/index.d.ts +2 -0
- package/dist/esnext/components/CartLineProvider/index.js +2 -0
- package/dist/esnext/components/CartLineQuantity/CartLineQuantity.client.d.ts +3 -0
- package/dist/esnext/components/CartLineQuantity/CartLineQuantity.client.js +8 -0
- package/dist/esnext/components/CartLineQuantity/index.d.ts +1 -0
- package/dist/esnext/components/CartLineQuantity/index.js +1 -0
- package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.d.ts +8 -0
- package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.js +17 -0
- package/dist/esnext/components/CartLineQuantityAdjustButton/index.d.ts +1 -0
- package/dist/esnext/components/CartLineQuantityAdjustButton/index.js +1 -0
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.d.ts +10 -0
- package/dist/esnext/components/CartLineSelectedOptions/CartLineSelectedOptions.client.js +9 -0
- package/dist/esnext/components/CartLineSelectedOptions/index.d.ts +1 -0
- package/dist/esnext/components/CartLineSelectedOptions/index.js +1 -0
- package/dist/esnext/components/CartLines/CartLines.d.ts +7 -0
- package/dist/esnext/components/CartLines/CartLines.js +15 -0
- package/dist/esnext/components/CartLines/index.d.ts +1 -0
- package/dist/esnext/components/CartLines/index.js +1 -0
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +7 -0
- package/dist/esnext/components/CartProvider/CartProvider.client.js +422 -0
- package/dist/esnext/components/CartProvider/CartServerProvider.server.d.ts +11 -0
- package/dist/esnext/components/CartProvider/CartServerProvider.server.js +20 -0
- package/dist/esnext/components/CartProvider/constants.d.ts +2 -0
- package/dist/esnext/components/CartProvider/constants.js +2 -0
- package/dist/esnext/components/CartProvider/context.d.ts +2 -0
- package/dist/esnext/components/CartProvider/context.js +2 -0
- package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +18 -0
- package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +18 -0
- package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +17 -0
- package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +18 -0
- package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartFragment.d.ts +68 -0
- package/dist/esnext/components/CartProvider/graphql/CartFragment.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +18 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +18 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +18 -0
- package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +18 -0
- package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.js +1 -0
- package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +13 -0
- package/dist/esnext/components/CartProvider/graphql/CartQuery.js +1 -0
- package/dist/esnext/components/CartProvider/hooks.d.ts +18 -0
- package/dist/esnext/components/CartProvider/hooks.js +79 -0
- package/dist/esnext/components/CartProvider/index.d.ts +4 -0
- package/dist/esnext/components/CartProvider/index.js +4 -0
- package/dist/esnext/components/CartProvider/types.d.ts +105 -0
- package/dist/esnext/components/CartProvider/types.js +1 -0
- package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.d.ts +2 -0
- package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.js +10 -0
- package/dist/esnext/components/CartShopPayButton/index.d.ts +1 -0
- package/dist/esnext/components/CartShopPayButton/index.js +1 -0
- package/dist/esnext/components/CartToggle/CartToggle.client.d.ts +8 -0
- package/dist/esnext/components/CartToggle/CartToggle.client.js +11 -0
- package/dist/esnext/components/CartToggle/index.d.ts +1 -0
- package/dist/esnext/components/CartToggle/index.js +1 -0
- package/dist/esnext/components/CartTotal/CartTotal.client.d.ts +3 -0
- package/dist/esnext/components/CartTotal/CartTotal.client.js +8 -0
- package/dist/esnext/components/CartTotal/index.d.ts +1 -0
- package/dist/esnext/components/CartTotal/index.js +1 -0
- package/dist/esnext/components/CartUIProvider/CartUIProvider.client.d.ts +5 -0
- package/dist/esnext/components/CartUIProvider/CartUIProvider.client.js +26 -0
- package/dist/esnext/components/CartUIProvider/context.d.ts +9 -0
- package/dist/esnext/components/CartUIProvider/context.js +2 -0
- package/dist/esnext/components/CartUIProvider/hooks.d.ts +1 -0
- package/dist/esnext/components/CartUIProvider/hooks.js +9 -0
- package/dist/esnext/components/CartUIProvider/index.d.ts +2 -0
- package/dist/esnext/components/CartUIProvider/index.js +2 -0
- package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +14 -0
- package/dist/esnext/components/ExternalVideo/ExternalVideo.js +9 -0
- package/dist/esnext/components/ExternalVideo/ExternalVideoFragment.d.ts +4 -0
- package/dist/esnext/components/ExternalVideo/ExternalVideoFragment.js +1 -0
- package/dist/esnext/components/ExternalVideo/index.d.ts +1 -0
- package/dist/esnext/components/ExternalVideo/index.js +1 -0
- package/dist/esnext/components/Image/Image.d.ts +14 -0
- package/dist/esnext/components/Image/Image.js +10 -0
- package/dist/esnext/components/Image/ImageFragment.d.ts +4 -0
- package/dist/esnext/components/Image/ImageFragment.js +1 -0
- package/dist/esnext/components/Image/index.d.ts +1 -0
- package/dist/esnext/components/Image/index.js +1 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.d.ts +6 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +14 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationContext.client.d.ts +8 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationContext.client.js +2 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +4 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +8 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationQuery.d.ts +18 -0
- package/dist/esnext/components/LocalizationProvider/LocalizationQuery.js +1 -0
- package/dist/esnext/components/LocalizationProvider/hooks.d.ts +8 -0
- package/dist/esnext/components/LocalizationProvider/hooks.js +17 -0
- package/dist/esnext/components/LocalizationProvider/index.d.ts +2 -0
- package/dist/esnext/components/LocalizationProvider/index.js +2 -0
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +19 -0
- package/dist/esnext/components/MediaFile/MediaFile.js +22 -0
- package/dist/esnext/components/MediaFile/MediaFileFragment.d.ts +22 -0
- package/dist/esnext/components/MediaFile/MediaFileFragment.js +1 -0
- package/dist/esnext/components/MediaFile/index.d.ts +1 -0
- package/dist/esnext/components/MediaFile/index.js +1 -0
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +8 -0
- package/dist/esnext/components/Metafield/Metafield.client.js +50 -0
- package/dist/esnext/components/Metafield/MetafieldFragment.d.ts +4 -0
- package/dist/esnext/components/Metafield/MetafieldFragment.js +1 -0
- package/dist/esnext/components/Metafield/components/StarRating/StarRating.d.ts +12 -0
- package/dist/esnext/components/Metafield/components/StarRating/StarRating.js +48 -0
- package/dist/esnext/components/Metafield/components/StarRating/index.d.ts +1 -0
- package/dist/esnext/components/Metafield/components/StarRating/index.js +1 -0
- package/dist/esnext/components/Metafield/components/index.d.ts +1 -0
- package/dist/esnext/components/Metafield/components/index.js +1 -0
- package/dist/esnext/components/Metafield/index.d.ts +3 -0
- package/dist/esnext/components/Metafield/index.js +1 -0
- package/dist/esnext/components/Metafield/types.d.ts +4 -0
- package/dist/esnext/components/Metafield/types.js +1 -0
- package/dist/esnext/components/Model3D/Model3D.client.d.ts +25 -0
- package/dist/esnext/components/Model3D/Model3D.client.js +30 -0
- package/dist/esnext/components/Model3D/Model3DFragment.d.ts +11 -0
- package/dist/esnext/components/Model3D/Model3DFragment.js +1 -0
- package/dist/esnext/components/Model3D/index.d.ts +1 -0
- package/dist/esnext/components/Model3D/index.js +1 -0
- package/dist/esnext/components/Money/Money.client.d.ts +7 -0
- package/dist/esnext/components/Money/Money.client.js +10 -0
- package/dist/esnext/components/Money/index.d.ts +1 -0
- package/dist/esnext/components/Money/index.js +1 -0
- package/dist/esnext/components/ProductDescription/ProductDescription.client.d.ts +3 -0
- package/dist/esnext/components/ProductDescription/ProductDescription.client.js +10 -0
- package/dist/esnext/components/ProductDescription/index.d.ts +1 -0
- package/dist/esnext/components/ProductDescription/index.js +1 -0
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +7 -0
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +16 -0
- package/dist/esnext/components/ProductMetafield/index.d.ts +1 -0
- package/dist/esnext/components/ProductMetafield/index.js +1 -0
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +7 -0
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +32 -0
- package/dist/esnext/components/ProductPrice/index.d.ts +1 -0
- package/dist/esnext/components/ProductPrice/index.js +1 -0
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +7 -0
- package/dist/esnext/components/ProductProvider/ProductProvider.client.js +35 -0
- package/dist/esnext/components/ProductProvider/ProductProviderFragment.d.ts +96 -0
- package/dist/esnext/components/ProductProvider/ProductProviderFragment.js +1 -0
- package/dist/esnext/components/ProductProvider/context.d.ts +13 -0
- package/dist/esnext/components/ProductProvider/context.js +2 -0
- package/dist/esnext/components/ProductProvider/hooks.d.ts +1 -0
- package/dist/esnext/components/ProductProvider/hooks.js +6 -0
- package/dist/esnext/components/ProductProvider/index.d.ts +2 -0
- package/dist/esnext/components/ProductProvider/index.js +2 -0
- package/dist/esnext/components/ProductProvider/types.d.ts +5 -0
- package/dist/esnext/components/ProductProvider/types.js +1 -0
- package/dist/esnext/components/ProductTitle/ProductTitle.client.d.ts +3 -0
- package/dist/esnext/components/ProductTitle/ProductTitle.client.js +11 -0
- package/dist/esnext/components/ProductTitle/index.d.ts +1 -0
- package/dist/esnext/components/ProductTitle/index.js +1 -0
- package/dist/esnext/components/RawHtml/RawHtml.d.ts +7 -0
- package/dist/esnext/components/RawHtml/RawHtml.js +13 -0
- package/dist/esnext/components/RawHtml/index.d.ts +1 -0
- package/dist/esnext/components/RawHtml/index.js +1 -0
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.d.ts +6 -0
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +12 -0
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.d.ts +1 -0
- package/dist/esnext/components/SelectedVariantAddToCartButton/index.js +1 -0
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.d.ts +4 -0
- package/dist/esnext/components/SelectedVariantBuyNowButton/SelectedVariantBuyNowButton.js +12 -0
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.d.ts +1 -0
- package/dist/esnext/components/SelectedVariantBuyNowButton/index.js +1 -0
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.d.ts +6 -0
- package/dist/esnext/components/SelectedVariantImage/SelectedVariantImage.client.js +12 -0
- package/dist/esnext/components/SelectedVariantImage/index.d.ts +1 -0
- package/dist/esnext/components/SelectedVariantImage/index.js +1 -0
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.d.ts +7 -0
- package/dist/esnext/components/SelectedVariantMetafield/SelectedVariantMetafield.client.js +15 -0
- package/dist/esnext/components/SelectedVariantMetafield/index.d.ts +1 -0
- package/dist/esnext/components/SelectedVariantMetafield/index.js +1 -0
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.d.ts +6 -0
- package/dist/esnext/components/SelectedVariantPrice/SelectedVariantPrice.client.js +18 -0
- package/dist/esnext/components/SelectedVariantPrice/index.d.ts +1 -0
- package/dist/esnext/components/SelectedVariantPrice/index.js +1 -0
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.d.ts +2 -0
- package/dist/esnext/components/SelectedVariantShopPayButton/SelectedVariantShopPayButton.client.js +12 -0
- package/dist/esnext/components/SelectedVariantShopPayButton/index.d.ts +1 -0
- package/dist/esnext/components/SelectedVariantShopPayButton/index.js +1 -0
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.d.ts +3 -0
- package/dist/esnext/components/SelectedVariantUnitPrice/SelectedVariantUnitPrice.client.js +12 -0
- package/dist/esnext/components/SelectedVariantUnitPrice/index.d.ts +1 -0
- package/dist/esnext/components/SelectedVariantUnitPrice/index.js +1 -0
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.d.ts +15 -0
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.js +32 -0
- package/dist/esnext/components/ShopPayButton/index.d.ts +1 -0
- package/dist/esnext/components/ShopPayButton/index.js +1 -0
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +8 -0
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +16 -0
- package/dist/esnext/components/UnitPrice/index.d.ts +1 -0
- package/dist/esnext/components/UnitPrice/index.js +1 -0
- package/dist/esnext/components/Video/Video.d.ts +13 -0
- package/dist/esnext/components/Video/Video.js +8 -0
- package/dist/esnext/components/Video/VideoFragment.d.ts +11 -0
- package/dist/esnext/components/Video/VideoFragment.js +1 -0
- package/dist/esnext/components/Video/index.d.ts +1 -0
- package/dist/esnext/components/Video/index.js +1 -0
- package/dist/esnext/components/index.d.ts +41 -0
- package/dist/esnext/components/index.js +87 -0
- package/dist/esnext/components/types.d.ts +73 -0
- package/dist/esnext/components/types.js +10 -0
- package/dist/esnext/entry-client.d.ts +3 -0
- package/dist/esnext/entry-client.js +36 -0
- package/dist/esnext/entry-server.d.ts +3 -0
- package/dist/esnext/entry-server.js +286 -0
- package/dist/esnext/foundation/ClientMarker/ClientMarker.d.ts +10 -0
- package/dist/esnext/foundation/ClientMarker/ClientMarker.js +25 -0
- package/dist/esnext/foundation/ClientMarker/index.d.ts +1 -0
- package/dist/esnext/foundation/ClientMarker/index.js +1 -0
- package/dist/esnext/foundation/Hydration/Cache.client.d.ts +9 -0
- package/dist/esnext/foundation/Hydration/Cache.client.js +131 -0
- package/dist/esnext/foundation/Hydration/ClientComponents.server.d.ts +13 -0
- package/dist/esnext/foundation/Hydration/ClientComponents.server.js +18 -0
- package/dist/esnext/foundation/Hydration/Html.d.ts +5 -0
- package/dist/esnext/foundation/Hydration/Html.js +9 -0
- package/dist/esnext/foundation/Hydration/HydrationContext.server.d.ts +1 -0
- package/dist/esnext/foundation/Hydration/HydrationContext.server.js +2 -0
- package/dist/esnext/foundation/Hydration/ServerComponentRequest.server.d.ts +13 -0
- package/dist/esnext/foundation/Hydration/ServerComponentRequest.server.js +39 -0
- package/dist/esnext/foundation/Hydration/ServerComponentResponse.server.d.ts +18 -0
- package/dist/esnext/foundation/Hydration/ServerComponentResponse.server.js +35 -0
- package/dist/esnext/foundation/Hydration/react-utils.d.ts +5 -0
- package/dist/esnext/foundation/Hydration/react-utils.js +55 -0
- package/dist/esnext/foundation/Hydration/wire.server.d.ts +4 -0
- package/dist/esnext/foundation/Hydration/wire.server.js +75 -0
- package/dist/esnext/foundation/Hydration/writer.server.d.ts +14 -0
- package/dist/esnext/foundation/Hydration/writer.server.js +29 -0
- package/dist/esnext/foundation/Router/DefaultRoutes.d.ts +20 -0
- package/dist/esnext/foundation/Router/DefaultRoutes.js +54 -0
- package/dist/esnext/foundation/Router/ServerStateRouter.client.d.ts +6 -0
- package/dist/esnext/foundation/Router/ServerStateRouter.client.js +27 -0
- package/dist/esnext/foundation/Router/index.d.ts +1 -0
- package/dist/esnext/foundation/Router/index.js +1 -0
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +11 -0
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.js +48 -0
- package/dist/esnext/foundation/ServerStateProvider/index.d.ts +1 -0
- package/dist/esnext/foundation/ServerStateProvider/index.js +1 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyContext.d.ts +1 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyContext.js +2 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.d.ts +3 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.js +11 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.d.ts +8 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.js +7 -0
- package/dist/esnext/foundation/ShopifyProvider/hooks.d.ts +2 -0
- package/dist/esnext/foundation/ShopifyProvider/hooks.js +9 -0
- package/dist/esnext/foundation/ShopifyProvider/index.d.ts +2 -0
- package/dist/esnext/foundation/ShopifyProvider/index.js +2 -0
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +12 -0
- package/dist/esnext/foundation/ShopifyProvider/types.js +1 -0
- package/dist/esnext/foundation/index.d.ts +4 -0
- package/dist/esnext/foundation/index.js +4 -0
- package/dist/esnext/framework/graphiql.d.ts +1 -0
- package/dist/esnext/framework/graphiql.js +39 -0
- package/dist/esnext/framework/middleware.d.ts +17 -0
- package/dist/esnext/framework/middleware.js +116 -0
- package/dist/esnext/framework/plugin.d.ts +3 -0
- package/dist/esnext/framework/plugin.js +14 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +43 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +4 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +28 -0
- package/dist/esnext/framework/plugins/vite-plugin-react-server-components-shim.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-react-server-components-shim.js +123 -0
- package/dist/esnext/framework/server-components.d.ts +12 -0
- package/dist/esnext/framework/server-components.js +72 -0
- package/dist/esnext/graphql/graphql-constants.d.ts +1295 -0
- package/dist/esnext/graphql/graphql-constants.js +2482 -0
- package/dist/esnext/graphql/types/types.d.ts +5583 -0
- package/dist/esnext/graphql/types/types.js +1414 -0
- package/dist/esnext/handle-event.d.ts +20 -0
- package/dist/esnext/handle-event.js +140 -0
- package/dist/esnext/handle-worker-event.d.ts +11 -0
- package/dist/esnext/handle-worker-event.js +14 -0
- package/dist/esnext/hooks/index.d.ts +5 -0
- package/dist/esnext/hooks/index.js +5 -0
- package/dist/esnext/hooks/useMeasurement/hooks.d.ts +9 -0
- package/dist/esnext/hooks/useMeasurement/hooks.js +13 -0
- package/dist/esnext/hooks/useMeasurement/index.d.ts +1 -0
- package/dist/esnext/hooks/useMeasurement/index.js +1 -0
- package/dist/esnext/hooks/useMoney/hooks.d.ts +11 -0
- package/dist/esnext/hooks/useMoney/hooks.js +33 -0
- package/dist/esnext/hooks/useMoney/index.d.ts +1 -0
- package/dist/esnext/hooks/useMoney/index.js +1 -0
- package/dist/esnext/hooks/useParsedMetafields/hooks.d.ts +3 -0
- package/dist/esnext/hooks/useParsedMetafields/hooks.js +15 -0
- package/dist/esnext/hooks/useParsedMetafields/index.d.ts +1 -0
- package/dist/esnext/hooks/useParsedMetafields/index.js +1 -0
- package/dist/esnext/hooks/useProductOptions/helpers.d.ts +4 -0
- package/dist/esnext/hooks/useProductOptions/helpers.js +33 -0
- package/dist/esnext/hooks/useProductOptions/index.d.ts +2 -0
- package/dist/esnext/hooks/useProductOptions/index.js +2 -0
- package/dist/esnext/hooks/useProductOptions/types.d.ts +50 -0
- package/dist/esnext/hooks/useProductOptions/types.js +1 -0
- package/dist/esnext/hooks/useProductOptions/useProductOptions.d.ts +23 -0
- package/dist/esnext/hooks/useProductOptions/useProductOptions.js +84 -0
- package/dist/esnext/hooks/useQuery/QueryProvider.d.ts +6 -0
- package/dist/esnext/hooks/useQuery/QueryProvider.js +13 -0
- package/dist/esnext/hooks/useQuery/hooks.d.ts +12 -0
- package/dist/esnext/hooks/useQuery/hooks.js +28 -0
- package/dist/esnext/hooks/useQuery/index.d.ts +2 -0
- package/dist/esnext/hooks/useQuery/index.js +2 -0
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +9 -0
- package/dist/esnext/hooks/useShopQuery/hooks.js +34 -0
- package/dist/esnext/hooks/useShopQuery/index.d.ts +1 -0
- package/dist/esnext/hooks/useShopQuery/index.js +1 -0
- package/dist/esnext/index.d.ts +9 -0
- package/dist/esnext/index.js +11 -0
- package/dist/esnext/types.d.ts +62 -0
- package/dist/esnext/types.js +1 -0
- package/dist/esnext/utilities/connections.d.ts +2 -0
- package/dist/esnext/utilities/connections.js +4 -0
- package/dist/esnext/utilities/environment.d.ts +2 -0
- package/dist/esnext/utilities/environment.js +2 -0
- package/dist/esnext/utilities/image_size.d.ts +17 -0
- package/dist/esnext/utilities/image_size.js +45 -0
- package/dist/esnext/utilities/index.d.ts +8 -0
- package/dist/esnext/utilities/index.js +8 -0
- package/dist/esnext/utilities/meaurement.d.ts +3 -0
- package/dist/esnext/utilities/meaurement.js +98 -0
- package/dist/esnext/utilities/metafields.d.ts +2 -0
- package/dist/esnext/utilities/metafields.js +32 -0
- package/dist/esnext/utilities/script_loader.d.ts +3 -0
- package/dist/esnext/utilities/script_loader.js +23 -0
- package/dist/esnext/utilities/suspense.d.ts +7 -0
- package/dist/esnext/utilities/suspense.js +32 -0
- package/dist/esnext/utilities/video_parameters.d.ts +47 -0
- package/dist/esnext/utilities/video_parameters.js +22 -0
- package/dist/esnext/version.d.ts +1 -0
- package/dist/esnext/version.js +1 -0
- package/dist/node/foundation/ClientMarker/ClientMarker.d.ts +10 -0
- package/dist/node/foundation/ClientMarker/ClientMarker.js +48 -0
- package/dist/node/foundation/ClientMarker/index.d.ts +1 -0
- package/dist/node/foundation/ClientMarker/index.js +13 -0
- package/dist/node/foundation/Hydration/HydrationContext.server.d.ts +1 -0
- package/dist/node/foundation/Hydration/HydrationContext.server.js +5 -0
- package/dist/node/foundation/Hydration/ServerComponentRequest.server.d.ts +13 -0
- package/dist/node/foundation/Hydration/ServerComponentRequest.server.js +43 -0
- package/dist/node/foundation/Hydration/ServerComponentResponse.server.d.ts +18 -0
- package/dist/node/foundation/Hydration/ServerComponentResponse.server.js +39 -0
- package/dist/node/foundation/Hydration/react-utils.d.ts +5 -0
- package/dist/node/foundation/Hydration/react-utils.js +63 -0
- package/dist/node/foundation/Router/DefaultRoutes.d.ts +20 -0
- package/dist/node/foundation/Router/DefaultRoutes.js +78 -0
- package/dist/node/foundation/Router/index.d.ts +1 -0
- package/dist/node/foundation/Router/index.js +5 -0
- package/dist/node/foundation/ShopifyProvider/ShopifyContext.d.ts +1 -0
- package/dist/node/foundation/ShopifyProvider/ShopifyContext.js +5 -0
- package/dist/node/foundation/ShopifyProvider/ShopifyProvider.d.ts +3 -0
- package/dist/node/foundation/ShopifyProvider/ShopifyProvider.js +34 -0
- package/dist/node/foundation/ShopifyProvider/ShopifyServerProvider.server.d.ts +8 -0
- package/dist/node/foundation/ShopifyProvider/ShopifyServerProvider.server.js +14 -0
- package/dist/node/foundation/ShopifyProvider/hooks.d.ts +2 -0
- package/dist/node/foundation/ShopifyProvider/hooks.js +13 -0
- package/dist/node/foundation/ShopifyProvider/index.d.ts +2 -0
- package/dist/node/foundation/ShopifyProvider/index.js +8 -0
- package/dist/node/foundation/ShopifyProvider/types.d.ts +12 -0
- package/dist/node/foundation/ShopifyProvider/types.js +2 -0
- package/dist/node/foundation/index.d.ts +4 -0
- package/dist/node/foundation/index.js +13 -0
- package/dist/node/framework/graphiql.d.ts +1 -0
- package/dist/node/framework/graphiql.js +43 -0
- package/dist/node/framework/middleware.d.ts +17 -0
- package/dist/node/framework/middleware.js +141 -0
- package/dist/node/framework/plugin.d.ts +3 -0
- package/dist/node/framework/plugin.js +19 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +45 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +4 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +33 -0
- package/dist/node/framework/plugins/vite-plugin-react-server-components-shim.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-react-server-components-shim.js +128 -0
- package/dist/node/framework/server-components.d.ts +12 -0
- package/dist/node/framework/server-components.js +77 -0
- package/dist/node/graphql/types/types.d.ts +5583 -0
- package/dist/node/graphql/types/types.js +1417 -0
- package/dist/node/handle-event.d.ts +20 -0
- package/dist/node/handle-event.js +143 -0
- package/dist/node/hooks/useQuery/QueryProvider.d.ts +6 -0
- package/dist/node/hooks/useQuery/QueryProvider.js +20 -0
- package/dist/node/hooks/useQuery/hooks.d.ts +12 -0
- package/dist/node/hooks/useQuery/hooks.js +32 -0
- package/dist/node/hooks/useQuery/index.d.ts +2 -0
- package/dist/node/hooks/useQuery/index.js +14 -0
- package/dist/node/types.d.ts +62 -0
- package/dist/node/types.js +2 -0
- package/dist/worker/foundation/Hydration/ServerComponentRequest.server.d.ts +13 -0
- package/dist/worker/foundation/Hydration/ServerComponentRequest.server.js +39 -0
- package/dist/worker/foundation/Hydration/ServerComponentResponse.server.d.ts +18 -0
- package/dist/worker/foundation/Hydration/ServerComponentResponse.server.js +35 -0
- package/dist/worker/graphql/types/types.d.ts +5583 -0
- package/dist/worker/graphql/types/types.js +1414 -0
- package/dist/worker/handle-event.d.ts +20 -0
- package/dist/worker/handle-event.js +140 -0
- package/dist/worker/handle-worker-event.d.ts +11 -0
- package/dist/worker/handle-worker-event.js +14 -0
- package/dist/worker/types.d.ts +62 -0
- package/dist/worker/types.js +1 -0
- package/entry-client.d.ts +1 -0
- package/entry-client.js +1 -0
- package/entry-server.d.ts +1 -0
- package/entry-server.js +1 -0
- package/marker.js +1 -0
- package/middleware.d.ts +1 -0
- package/middleware.js +1 -0
- package/package.json +98 -0
- package/plugin.d.ts +1 -0
- package/plugin.js +1 -0
- package/worker.js +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ServerResponse } from 'http';
|
|
3
|
+
import { ServerComponentRequest } from './foundation/Hydration/ServerComponentRequest.server';
|
|
4
|
+
interface HydrogenFetchEvent {
|
|
5
|
+
/**
|
|
6
|
+
* Hydrogen only cares about a single property, since we pass `request` as a separate option.
|
|
7
|
+
*/
|
|
8
|
+
waitUntil?: (callback: Promise<void>) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface HandleEventOptions {
|
|
11
|
+
request: ServerComponentRequest;
|
|
12
|
+
entrypoint: any;
|
|
13
|
+
indexTemplate: string | ((url: string) => Promise<string>);
|
|
14
|
+
assetHandler?: (event: HydrogenFetchEvent, url: URL) => Promise<Response>;
|
|
15
|
+
cache?: Cache;
|
|
16
|
+
streamableResponse: ServerResponse;
|
|
17
|
+
dev?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export default function handleEvent(event: HydrogenFetchEvent, { request, entrypoint, indexTemplate, assetHandler, cache, streamableResponse, dev, }: HandleEventOptions): Promise<Response | undefined>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const EXPIRES_HEADER = 'Expires';
|
|
2
|
+
const CACHE_TTL_IN_SECONDS = 60;
|
|
3
|
+
export default async function handleEvent(event, { request, entrypoint, indexTemplate, assetHandler, cache, streamableResponse, dev, }) {
|
|
4
|
+
var _a, _b, _c;
|
|
5
|
+
if (cache) {
|
|
6
|
+
const response = await cache.match(request);
|
|
7
|
+
if (response && responseIsValid(response)) {
|
|
8
|
+
return response;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const url = new URL(request.url);
|
|
12
|
+
const isReactHydrationRequest = url.pathname === '/react';
|
|
13
|
+
try {
|
|
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
|
+
const context = {};
|
|
32
|
+
/**
|
|
33
|
+
* Stream back real-user responses, but for bots/etc,
|
|
34
|
+
* use `render` instead. This is because we need to inject <head>
|
|
35
|
+
* things for SEO reasons.
|
|
36
|
+
*/
|
|
37
|
+
if (isStreamable) {
|
|
38
|
+
if (isReactHydrationRequest) {
|
|
39
|
+
hydrate(url, { context, request, response: streamableResponse });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
stream(url, { context, request, response: streamableResponse, template });
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const { body, bodyAttributes, htmlAttributes, componentResponse, ...head } = await render(url, { request, context, isReactHydrationRequest });
|
|
47
|
+
const headers = componentResponse.headers;
|
|
48
|
+
/**
|
|
49
|
+
* TODO: Set as part of cache-control headers when Oxygen support lands.
|
|
50
|
+
*/
|
|
51
|
+
headers.set(EXPIRES_HEADER, new Date(Date.now() + CACHE_TTL_IN_SECONDS * 1000).toUTCString());
|
|
52
|
+
if (componentResponse.customBody) {
|
|
53
|
+
return new Response(await componentResponse.customBody, {
|
|
54
|
+
status: (_a = componentResponse.status) !== null && _a !== void 0 ? _a : 200,
|
|
55
|
+
headers,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
let response;
|
|
59
|
+
if (isReactHydrationRequest) {
|
|
60
|
+
response = new Response(body, {
|
|
61
|
+
status: (_b = componentResponse.status) !== null && _b !== void 0 ? _b : 200,
|
|
62
|
+
headers,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const html = template
|
|
67
|
+
.replace(`<div id="root"></div>`, `<div id="root" data-server-rendered="true">${body}</div>`)
|
|
68
|
+
.replace(/<head>(.*?)<\/head>/s, generateHeadTag(head))
|
|
69
|
+
.replace('<body', bodyAttributes ? `<body ${bodyAttributes}` : '$&')
|
|
70
|
+
.replace('<html', htmlAttributes ? `<html ${htmlAttributes}` : '$&');
|
|
71
|
+
headers.append('content-type', 'text/html');
|
|
72
|
+
response = new Response(html, {
|
|
73
|
+
status: (_c = componentResponse.status) !== null && _c !== void 0 ? _c : 200,
|
|
74
|
+
headers,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (cache) {
|
|
78
|
+
/**
|
|
79
|
+
* Put response into cache. If the Worker runtime requires `event.waitUntil` to keep the request
|
|
80
|
+
* alive while the cache operation completes, use it. Otherwise, assume queued microtasks will finish.
|
|
81
|
+
*/
|
|
82
|
+
if (typeof event.waitUntil === 'function') {
|
|
83
|
+
event.waitUntil(cache.put(request, response.clone()));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
cache.put(request, response.clone());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return response;
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
console.log(e.stack);
|
|
93
|
+
return new Response(e.message || e.toString(), {
|
|
94
|
+
status: 500,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Determine whether a current response is valid.
|
|
100
|
+
* This is necessary because the Oxygen Cache API does not yet
|
|
101
|
+
* support automatic expiration via cache-control headers.
|
|
102
|
+
* Eventually, a method like this may not be necessary.
|
|
103
|
+
*/
|
|
104
|
+
function responseIsValid(response) {
|
|
105
|
+
const expiration = response.headers.get(EXPIRES_HEADER);
|
|
106
|
+
if (!expiration)
|
|
107
|
+
return false;
|
|
108
|
+
return new Date(expiration) > new Date();
|
|
109
|
+
}
|
|
110
|
+
function isStreamableRequest(url) {
|
|
111
|
+
/**
|
|
112
|
+
* TODO: Add UA detection.
|
|
113
|
+
*/
|
|
114
|
+
const isBot = url.searchParams.has('_bot');
|
|
115
|
+
return !isBot;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generate the contents of the `head` tag, and update the existing `<title>` tag
|
|
119
|
+
* if one exists, and if a title is passed.
|
|
120
|
+
*/
|
|
121
|
+
function generateHeadTag(head) {
|
|
122
|
+
const headProps = ['base', 'meta', 'style', 'noscript', 'script', 'link'];
|
|
123
|
+
const { title, ...rest } = head;
|
|
124
|
+
const otherHeadProps = headProps
|
|
125
|
+
.map((prop) => rest[prop])
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join('\n');
|
|
128
|
+
return (_outerHtml, innerHtml) => {
|
|
129
|
+
let headHtml = otherHeadProps + innerHtml;
|
|
130
|
+
if (title) {
|
|
131
|
+
if (headHtml.includes('<title>')) {
|
|
132
|
+
headHtml = headHtml.replace(/(<title>(?:.|\n)*?<\/title>)/, title);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
headHtml += title;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return `<head>${headHtml}</head>`;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HandleEventOptions } from './handle-event';
|
|
2
|
+
interface FetchEvent {
|
|
3
|
+
request: Request;
|
|
4
|
+
waitUntil?: (callback: Promise<void>) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This is a wrapper around `handleEvent` that upgrades Request to ServerComponentRequest,
|
|
8
|
+
* so the rest of the application downstream has access to things like `request.cookies`, etc.
|
|
9
|
+
*/
|
|
10
|
+
export default function handleWorkerEvent(event: FetchEvent, options: HandleEventOptions): Promise<Response | undefined>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ServerComponentRequest } from './foundation/Hydration/ServerComponentRequest.server';
|
|
2
|
+
import handleEvent from './handle-event';
|
|
3
|
+
/**
|
|
4
|
+
* This is a wrapper around `handleEvent` that upgrades Request to ServerComponentRequest,
|
|
5
|
+
* so the rest of the application downstream has access to things like `request.cookies`, etc.
|
|
6
|
+
*/
|
|
7
|
+
export default async function handleWorkerEvent(event, options) {
|
|
8
|
+
const request = new ServerComponentRequest(event.request);
|
|
9
|
+
/**
|
|
10
|
+
* Note: We need to pass `request` as a separate option since Cloudflare (and other Worker
|
|
11
|
+
* runtimes, presumably) does not like when `event` is mutated.
|
|
12
|
+
*/
|
|
13
|
+
return handleEvent(event, { ...options, request });
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Measurement } from '../../types';
|
|
2
|
+
export interface UseMeasurementValue {
|
|
3
|
+
localizedString: string;
|
|
4
|
+
amount?: string;
|
|
5
|
+
unitName?: string;
|
|
6
|
+
parts: Intl.NumberFormatPart[];
|
|
7
|
+
original: Measurement;
|
|
8
|
+
}
|
|
9
|
+
export declare function useMeasurement(measurement: Measurement, options?: Omit<Intl.NumberFormatOptions, 'unit'>): UseMeasurementValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useShop } from '../../foundation';
|
|
3
|
+
import { getMeasurementAsParts, getMeasurementAsString } from '../../utilities';
|
|
4
|
+
export function useMeasurement(measurement, options = {}) {
|
|
5
|
+
const { locale } = useShop();
|
|
6
|
+
return useMemo(() => {
|
|
7
|
+
return {
|
|
8
|
+
localizedString: getMeasurementAsString(measurement, locale, options),
|
|
9
|
+
parts: getMeasurementAsParts(measurement, locale, options),
|
|
10
|
+
original: measurement,
|
|
11
|
+
};
|
|
12
|
+
}, [locale, measurement, options]);
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMeasurement } from './hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMeasurement } from './hooks';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CurrencyCode, MoneyV2 } from '../../graphql/types/types';
|
|
2
|
+
export declare type UseMoneyValue = {
|
|
3
|
+
currencyCode: CurrencyCode;
|
|
4
|
+
currencyName?: string;
|
|
5
|
+
currencySymbol?: string;
|
|
6
|
+
currencyNarrowSymbol?: string;
|
|
7
|
+
amount: string;
|
|
8
|
+
parts: Intl.NumberFormatPart[];
|
|
9
|
+
localizedString: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function useMoney(money: MoneyV2): UseMoneyValue;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useShop } from '../../foundation/ShopifyProvider';
|
|
3
|
+
export function useMoney(money) {
|
|
4
|
+
const { locale } = useShop();
|
|
5
|
+
const options = useMemo(() => ({
|
|
6
|
+
style: 'currency',
|
|
7
|
+
currency: money.currencyCode,
|
|
8
|
+
}), [money.currencyCode]);
|
|
9
|
+
const amount = parseFloat(money.amount);
|
|
10
|
+
const value = useMemo(() => new Intl.NumberFormat(locale, options).format(amount), [amount, locale, options]);
|
|
11
|
+
const baseParts = new Intl.NumberFormat(locale, options).formatToParts(amount);
|
|
12
|
+
const nameParts = new Intl.NumberFormat(locale, {
|
|
13
|
+
...options,
|
|
14
|
+
currencyDisplay: 'name',
|
|
15
|
+
}).formatToParts(amount);
|
|
16
|
+
const narrowParts = new Intl.NumberFormat(locale, {
|
|
17
|
+
...options,
|
|
18
|
+
currencyDisplay: 'narrowSymbol',
|
|
19
|
+
}).formatToParts(amount);
|
|
20
|
+
const parts = useMemo(() => {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
return ({
|
|
23
|
+
currencyCode: money.currencyCode,
|
|
24
|
+
currencyName: (_a = nameParts.find((part) => part.type === 'currency')) === null || _a === void 0 ? void 0 : _a.value,
|
|
25
|
+
currencySymbol: (_b = baseParts.find((part) => part.type === 'currency')) === null || _b === void 0 ? void 0 : _b.value,
|
|
26
|
+
currencyNarrowSymbol: (_c = narrowParts.find((part) => part.type === 'currency')) === null || _c === void 0 ? void 0 : _c.value,
|
|
27
|
+
amount: money.amount,
|
|
28
|
+
parts: baseParts.filter((part) => part.type !== 'currency'),
|
|
29
|
+
localizedString: value,
|
|
30
|
+
});
|
|
31
|
+
}, [baseParts, money.amount, money.currencyCode, nameParts, narrowParts, value]);
|
|
32
|
+
return parts;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMoney } from './hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMoney } from './hooks';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { flattenConnection, parseMetafieldValue } from '../../utilities';
|
|
3
|
+
export function useParsedMetafields(metafields) {
|
|
4
|
+
return useMemo(() => {
|
|
5
|
+
if (metafields == null) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
return flattenConnection(metafields).map((metafield) => {
|
|
9
|
+
return {
|
|
10
|
+
...metafield,
|
|
11
|
+
value: parseMetafieldValue(metafield),
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
}, [metafields]);
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useParsedMetafields } from './hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useParsedMetafields } from './hooks';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Variant, SelectedOptions, OptionWithValues } from './types';
|
|
2
|
+
export declare function getAllOptionValues(variants: Variant[], option: string): string[];
|
|
3
|
+
export declare function getSelectedVariant(variants: Variant[], choices: SelectedOptions): Variant | undefined;
|
|
4
|
+
export declare function getOptions(variants: Variant[]): OptionWithValues[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function getAllOptionValues(variants, option) {
|
|
2
|
+
return Array.from(new Set(variants.map((variant) => variant.selectedOptions.find((selection) => selection.name == option)
|
|
3
|
+
.value)));
|
|
4
|
+
}
|
|
5
|
+
export function getSelectedVariant(variants, choices) {
|
|
6
|
+
/**
|
|
7
|
+
* Ensure the user has selected all the required options, not just some.
|
|
8
|
+
*/
|
|
9
|
+
if (!variants.length ||
|
|
10
|
+
variants[0].selectedOptions.length !== Object.keys(choices).length) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return variants.find((variant) => {
|
|
14
|
+
return Object.entries(choices).every(([name, value]) => {
|
|
15
|
+
return variant.selectedOptions.some((option) => option.name === name && option.value === value);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function getOptions(variants) {
|
|
20
|
+
const map = variants.reduce((memo, variant) => {
|
|
21
|
+
variant.selectedOptions.forEach(({ name, value }) => {
|
|
22
|
+
memo[name] = memo[name] || new Set();
|
|
23
|
+
memo[name].add(value);
|
|
24
|
+
});
|
|
25
|
+
return memo;
|
|
26
|
+
}, {});
|
|
27
|
+
return Object.keys(map).map((option) => {
|
|
28
|
+
return {
|
|
29
|
+
name: option,
|
|
30
|
+
values: Array.from(map[option]),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ProductProviderFragmentFragment } from '../../components/ProductProvider/ProductProviderFragment';
|
|
2
|
+
import { CurrencyCode, SellingPlanAllocationConnection, SellingPlanConnection, SellingPlan, UnitPriceMeasurement } from '../../graphql/types/types';
|
|
3
|
+
import { GraphQLConnection } from '../../types';
|
|
4
|
+
export declare type VariantsConnection = GraphQLConnection<Variant>;
|
|
5
|
+
interface OptionSet {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
export interface Variant {
|
|
10
|
+
availableForSale: boolean;
|
|
11
|
+
compareAtPriceV2?: Money;
|
|
12
|
+
id: string;
|
|
13
|
+
image?: {
|
|
14
|
+
originalSrc: string;
|
|
15
|
+
altText: string;
|
|
16
|
+
};
|
|
17
|
+
unitPrice: Money;
|
|
18
|
+
unitPriceMeasurement: UnitPriceMeasurement;
|
|
19
|
+
priceV2: Money;
|
|
20
|
+
selectedOptions: OptionSet[];
|
|
21
|
+
sellingPlanAllocations?: SellingPlanAllocationConnection;
|
|
22
|
+
title: string;
|
|
23
|
+
metafields: ProductProviderFragmentFragment['variants']['edges'][0]['node']['metafields'];
|
|
24
|
+
}
|
|
25
|
+
export declare type SelectedOptions = Record<string, string>;
|
|
26
|
+
export declare type SelectVariantCallback = (variant: Variant) => void;
|
|
27
|
+
export declare type SelectOption = (name: string, value: string) => void;
|
|
28
|
+
export declare type SelectOptionCallback = (name: string, value: string) => void;
|
|
29
|
+
export interface OptionWithValues {
|
|
30
|
+
name: string;
|
|
31
|
+
values: string[];
|
|
32
|
+
}
|
|
33
|
+
export declare type SellingPlanGroupsConnection = GraphQLConnection<SellingPlanGroup>;
|
|
34
|
+
export interface SellingPlanGroup {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
options: {
|
|
38
|
+
name: string;
|
|
39
|
+
values: string[];
|
|
40
|
+
}[];
|
|
41
|
+
sellingPlans: SellingPlanConnection;
|
|
42
|
+
}
|
|
43
|
+
export interface FlattenedSellingPlanGroup extends Omit<SellingPlanGroup, 'sellingPlans'> {
|
|
44
|
+
sellingPlans: SellingPlan[];
|
|
45
|
+
}
|
|
46
|
+
interface Money {
|
|
47
|
+
amount: string;
|
|
48
|
+
currencyCode: CurrencyCode;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FlattenedSellingPlanGroup, SellingPlanGroupsConnection, OptionWithValues, SelectedOptions, Variant, VariantsConnection } from './types';
|
|
2
|
+
import { SellingPlan, SellingPlanAllocation } from '../../graphql/types/types';
|
|
3
|
+
export interface ProductOptionsHookValue {
|
|
4
|
+
variants: Variant[];
|
|
5
|
+
options: OptionWithValues[];
|
|
6
|
+
selectedVariant?: Variant;
|
|
7
|
+
setSelectedVariant: (variant: Variant) => void;
|
|
8
|
+
selectedOptions: SelectedOptions;
|
|
9
|
+
setSelectedOption: (name: string, value: string) => void;
|
|
10
|
+
setSelectedOptions: (options: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
isOptionInStock: (name: string, value: string) => boolean;
|
|
14
|
+
setSelectedSellingPlan: (sellingPlan: SellingPlan) => void;
|
|
15
|
+
selectedSellingPlan?: SellingPlan;
|
|
16
|
+
selectedSellingPlanAllocation?: SellingPlanAllocation;
|
|
17
|
+
sellingPlanGroups: FlattenedSellingPlanGroup[];
|
|
18
|
+
}
|
|
19
|
+
export declare function useProductOptions({ variants: variantsConnection, sellingPlanGroups: sellingPlanGroupsConnection, initialVariantId, }: {
|
|
20
|
+
variants?: VariantsConnection;
|
|
21
|
+
sellingPlanGroups?: SellingPlanGroupsConnection;
|
|
22
|
+
initialVariantId?: string;
|
|
23
|
+
}): ProductOptionsHookValue;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { flattenConnection } from '../../utilities';
|
|
3
|
+
import { getOptions, getSelectedVariant } from './helpers';
|
|
4
|
+
export function useProductOptions({ variants: variantsConnection, sellingPlanGroups: sellingPlanGroupsConnection, initialVariantId, }) {
|
|
5
|
+
const variants = useMemo(() => (variantsConnection ? flattenConnection(variantsConnection) : []), [variantsConnection]);
|
|
6
|
+
const options = useMemo(() => getOptions(variants), [variants]);
|
|
7
|
+
/**
|
|
8
|
+
* Track the state of the selectedVariant within the hook. If a `selectedVariantId`
|
|
9
|
+
* is passed, use that as an initial value.
|
|
10
|
+
*/
|
|
11
|
+
const [selectedVariant, setSelectedVariant] = useState(initialVariantId
|
|
12
|
+
? variants.find((variant) => variant.id === initialVariantId)
|
|
13
|
+
: undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Track the state of selectedOptions within the hook. If a `selectedVariantId`
|
|
16
|
+
* is passed, use that to select initial options.
|
|
17
|
+
*/
|
|
18
|
+
const [selectedOptions, setSelectedOptions] = useState(selectedVariant
|
|
19
|
+
? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
|
|
20
|
+
memo[optionSet.name] = optionSet.value;
|
|
21
|
+
return memo;
|
|
22
|
+
}, {})
|
|
23
|
+
: {});
|
|
24
|
+
/**
|
|
25
|
+
* Allow the developer to select an option.
|
|
26
|
+
*/
|
|
27
|
+
function setSelectedOption(name, value) {
|
|
28
|
+
const newSelectedOptions = {
|
|
29
|
+
...selectedOptions,
|
|
30
|
+
[name]: value,
|
|
31
|
+
};
|
|
32
|
+
setSelectedOptions(newSelectedOptions);
|
|
33
|
+
}
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
/**
|
|
36
|
+
* When selected options change, select the correct variant.
|
|
37
|
+
*/
|
|
38
|
+
const variant = getSelectedVariant(variants, selectedOptions);
|
|
39
|
+
if (variant) {
|
|
40
|
+
setSelectedVariant(variant);
|
|
41
|
+
}
|
|
42
|
+
}, [variants, selectedOptions]);
|
|
43
|
+
const isOptionInStock = useCallback((option, value) => {
|
|
44
|
+
const proposedVariant = getSelectedVariant(variants, {
|
|
45
|
+
...selectedOptions,
|
|
46
|
+
...{ [option]: value },
|
|
47
|
+
});
|
|
48
|
+
return proposedVariant ? proposedVariant.availableForSale : true;
|
|
49
|
+
}, [selectedOptions, variants]);
|
|
50
|
+
const sellingPlanGroups = useMemo(() => sellingPlanGroupsConnection
|
|
51
|
+
? flattenConnection(sellingPlanGroupsConnection).map((sellingPlanGroup) => ({
|
|
52
|
+
...sellingPlanGroup,
|
|
53
|
+
sellingPlans: flattenConnection(sellingPlanGroup.sellingPlans),
|
|
54
|
+
}))
|
|
55
|
+
: [], [sellingPlanGroupsConnection]);
|
|
56
|
+
/**
|
|
57
|
+
* Track the state of the selectedSellingPlan within the hook. If a `initialSellingPlanId`
|
|
58
|
+
* is passed, use that as an initial value. Look it up from the `selectedVariant`, since
|
|
59
|
+
* that is also a requirement.
|
|
60
|
+
*/
|
|
61
|
+
const [selectedSellingPlan, setSelectedSellingPlan] = useState(undefined);
|
|
62
|
+
const selectedSellingPlanAllocation = useMemo(() => {
|
|
63
|
+
if (selectedVariant && selectedSellingPlan) {
|
|
64
|
+
if (!selectedVariant.sellingPlanAllocations) {
|
|
65
|
+
throw new Error(`You must include sellingPlanAllocations in your variants in order to calculate selectedSellingPlanAllocation`);
|
|
66
|
+
}
|
|
67
|
+
return flattenConnection(selectedVariant.sellingPlanAllocations).find((allocation) => allocation.sellingPlan.id === selectedSellingPlan.id);
|
|
68
|
+
}
|
|
69
|
+
}, [selectedVariant, selectedSellingPlan]);
|
|
70
|
+
return {
|
|
71
|
+
variants,
|
|
72
|
+
options,
|
|
73
|
+
selectedVariant,
|
|
74
|
+
setSelectedVariant,
|
|
75
|
+
selectedOptions,
|
|
76
|
+
setSelectedOption,
|
|
77
|
+
setSelectedOptions,
|
|
78
|
+
isOptionInStock,
|
|
79
|
+
selectedSellingPlan,
|
|
80
|
+
selectedSellingPlanAllocation,
|
|
81
|
+
setSelectedSellingPlan,
|
|
82
|
+
sellingPlanGroups,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { ReactQueryHydrationContext } from '../../foundation/ShopifyProvider/types';
|
|
3
|
+
export declare function QueryProvider({ children, hydrationContext, }: {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
hydrationContext?: ReactQueryHydrationContext;
|
|
6
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { QueryClientProvider, QueryClient } from 'react-query';
|
|
3
|
+
import { Hydrate } from 'react-query/hydration';
|
|
4
|
+
export function QueryProvider({ children, hydrationContext, }) {
|
|
5
|
+
const queryClient = new QueryClient({
|
|
6
|
+
defaultOptions: { queries: { suspense: true } },
|
|
7
|
+
});
|
|
8
|
+
if (hydrationContext) {
|
|
9
|
+
hydrationContext.queryClient = queryClient;
|
|
10
|
+
}
|
|
11
|
+
return (React.createElement(QueryClientProvider, { client: queryClient },
|
|
12
|
+
React.createElement(Hydrate, { state: hydrationContext === null || hydrationContext === void 0 ? void 0 : hydrationContext.dehydratedState }, children)));
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UseQueryOptions, QueryKey } from 'react-query';
|
|
2
|
+
/**
|
|
3
|
+
* useQuery is a wrapper around `fetch` which supports Suspense calls on the server
|
|
4
|
+
* and on the client. It is backed by `react-query`, and it accepts options to that package's
|
|
5
|
+
* `useQuery` hook.
|
|
6
|
+
*
|
|
7
|
+
* If the `init` object contains `accept` or `content-type` headers indicating JSON,
|
|
8
|
+
* the response will be converted to JSON. Otherwise, it will be read as text.
|
|
9
|
+
*
|
|
10
|
+
* @see https://react-query.tanstack.com/reference/useQuery
|
|
11
|
+
*/
|
|
12
|
+
export declare function useQuery<T>(url: string, init?: RequestInit, queryOptions?: UseQueryOptions<T, Error, T, QueryKey>): import("react-query").UseQueryResult<T, Error>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useQuery as useReactQuery, } from 'react-query';
|
|
2
|
+
/**
|
|
3
|
+
* useQuery is a wrapper around `fetch` which supports Suspense calls on the server
|
|
4
|
+
* and on the client. It is backed by `react-query`, and it accepts options to that package's
|
|
5
|
+
* `useQuery` hook.
|
|
6
|
+
*
|
|
7
|
+
* If the `init` object contains `accept` or `content-type` headers indicating JSON,
|
|
8
|
+
* the response will be converted to JSON. Otherwise, it will be read as text.
|
|
9
|
+
*
|
|
10
|
+
* @see https://react-query.tanstack.com/reference/useQuery
|
|
11
|
+
*/
|
|
12
|
+
export function useQuery(url, init, queryOptions) {
|
|
13
|
+
return useReactQuery(
|
|
14
|
+
/**
|
|
15
|
+
* TODO: Add better key generation, taking into account headers, etc.
|
|
16
|
+
*/
|
|
17
|
+
[url, init === null || init === void 0 ? void 0 : init.body], async () => {
|
|
18
|
+
const response = await fetch(url, init);
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(`[useQuery] error: ${response.status} ${response.statusText}`);
|
|
21
|
+
}
|
|
22
|
+
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
23
|
+
const isJsonRequest = headers.get('accept') === 'application/json' ||
|
|
24
|
+
headers.get('content-type') === 'application/json';
|
|
25
|
+
const method = isJsonRequest ? 'json' : 'text';
|
|
26
|
+
return response[method]();
|
|
27
|
+
}, queryOptions);
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ASTNode } from 'graphql';
|
|
2
|
+
export interface UseShopQueryResponse<T> {
|
|
3
|
+
data: T;
|
|
4
|
+
errors: any;
|
|
5
|
+
}
|
|
6
|
+
export declare function useShopQuery<T>({ query, variables, }: {
|
|
7
|
+
query: ASTNode | string;
|
|
8
|
+
variables?: Record<string, any>;
|
|
9
|
+
}): UseShopQueryResponse<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useShop } from '../../foundation/ShopifyProvider/hooks';
|
|
2
|
+
import { print } from 'graphql';
|
|
3
|
+
import { useQuery } from '../useQuery';
|
|
4
|
+
import { isClient } from '../../utilities';
|
|
5
|
+
import { LIB_VERSION } from '../../version';
|
|
6
|
+
export function useShopQuery({ query, variables = {}, }) {
|
|
7
|
+
if (isClient()) {
|
|
8
|
+
throw new Error('Shopify Storefront API requests should only be made from the server.');
|
|
9
|
+
}
|
|
10
|
+
const { storeDomain, storefrontToken, graphqlApiVersion } = useShop();
|
|
11
|
+
const { data } = useQuery(`https://${storeDomain}/api/${graphqlApiVersion}/graphql.json`, {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
headers: {
|
|
14
|
+
'content-type': 'application/json',
|
|
15
|
+
'user-agent': `Hydrogen ${LIB_VERSION}`,
|
|
16
|
+
'X-Shopify-Storefront-Access-Token': storefrontToken,
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({
|
|
19
|
+
query: typeof query === 'string' ? query : print(query),
|
|
20
|
+
variables,
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* GraphQL errors get printed to the console but ultimately
|
|
25
|
+
* get returned to the consumer.
|
|
26
|
+
*/
|
|
27
|
+
if (data === null || data === void 0 ? void 0 : data.errors) {
|
|
28
|
+
for (const error of data.errors) {
|
|
29
|
+
console.error('GraphQL Error', error);
|
|
30
|
+
}
|
|
31
|
+
console.error(`GraphQL errors: ${data.errors.length}`);
|
|
32
|
+
}
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks';
|