@shopify/hydrogen-react 2026.4.1 → 2026.4.2
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/dist/browser-dev/AddToCartButton.mjs +60 -71
- package/dist/browser-dev/AddToCartButton.mjs.map +1 -1
- package/dist/browser-dev/BaseButton.mjs +20 -26
- package/dist/browser-dev/BaseButton.mjs.map +1 -1
- package/dist/browser-dev/BuyNowButton.mjs +40 -45
- package/dist/browser-dev/BuyNowButton.mjs.map +1 -1
- package/dist/browser-dev/CartCheckoutButton.mjs +28 -23
- package/dist/browser-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-dev/CartCost.mjs +26 -22
- package/dist/browser-dev/CartCost.mjs.map +1 -1
- package/dist/browser-dev/CartLineProvider.mjs +23 -18
- package/dist/browser-dev/CartLineProvider.mjs.map +1 -1
- package/dist/browser-dev/CartLineQuantity.mjs +18 -9
- package/dist/browser-dev/CartLineQuantity.mjs.map +1 -1
- package/dist/browser-dev/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/browser-dev/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/browser-dev/CartProvider.mjs +315 -385
- package/dist/browser-dev/CartProvider.mjs.map +1 -1
- package/dist/browser-dev/ExternalVideo.mjs +35 -47
- package/dist/browser-dev/ExternalVideo.mjs.map +1 -1
- package/dist/browser-dev/Image.mjs +335 -340
- package/dist/browser-dev/Image.mjs.map +1 -1
- package/dist/browser-dev/MediaFile.mjs +39 -61
- package/dist/browser-dev/MediaFile.mjs.map +1 -1
- package/dist/browser-dev/ModelViewer.mjs +115 -139
- package/dist/browser-dev/ModelViewer.mjs.map +1 -1
- package/dist/browser-dev/Money.mjs +53 -39
- package/dist/browser-dev/Money.mjs.map +1 -1
- package/dist/browser-dev/ProductPrice.mjs +44 -61
- package/dist/browser-dev/ProductPrice.mjs.map +1 -1
- package/dist/browser-dev/ProductProvider.mjs +147 -179
- package/dist/browser-dev/ProductProvider.mjs.map +1 -1
- package/dist/browser-dev/RichText.components.mjs +36 -46
- package/dist/browser-dev/RichText.components.mjs.map +1 -1
- package/dist/browser-dev/RichText.mjs +111 -154
- package/dist/browser-dev/RichText.mjs.map +1 -1
- package/dist/browser-dev/ShopPayButton.mjs +53 -81
- package/dist/browser-dev/ShopPayButton.mjs.map +1 -1
- package/dist/browser-dev/ShopifyProvider.mjs +71 -84
- package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-dev/Video.mjs +35 -52
- package/dist/browser-dev/Video.mjs.map +1 -1
- package/dist/browser-dev/analytics-constants.mjs +41 -43
- package/dist/browser-dev/analytics-constants.mjs.map +1 -1
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/browser-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/browser-dev/analytics-utils.mjs +78 -56
- package/dist/browser-dev/analytics-utils.mjs.map +1 -1
- package/dist/browser-dev/analytics.mjs +112 -155
- package/dist/browser-dev/analytics.mjs.map +1 -1
- package/dist/browser-dev/cart-constants.mjs +11 -15
- package/dist/browser-dev/cart-constants.mjs.map +1 -1
- package/dist/browser-dev/cart-hooks.mjs +42 -57
- package/dist/browser-dev/cart-hooks.mjs.map +1 -1
- package/dist/browser-dev/cart-queries.mjs +28 -66
- package/dist/browser-dev/cart-queries.mjs.map +1 -1
- package/dist/browser-dev/codegen.helpers.mjs +31 -20
- package/dist/browser-dev/codegen.helpers.mjs.map +1 -1
- package/dist/browser-dev/cookies-utils.mjs +44 -42
- package/dist/browser-dev/cookies-utils.mjs.map +1 -1
- package/dist/browser-dev/flatten-connection.mjs +23 -29
- package/dist/browser-dev/flatten-connection.mjs.map +1 -1
- package/dist/browser-dev/getProductOptions.mjs +248 -226
- package/dist/browser-dev/getProductOptions.mjs.map +1 -1
- package/dist/browser-dev/index.mjs +15 -70
- package/dist/browser-dev/load-script.mjs +38 -49
- package/dist/browser-dev/load-script.mjs.map +1 -1
- package/dist/browser-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/browser-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/browser-dev/optionValueDecoder.mjs +104 -86
- package/dist/browser-dev/optionValueDecoder.mjs.map +1 -1
- package/dist/browser-dev/packages/hydrogen-react/package.mjs +6 -0
- package/dist/browser-dev/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/browser-dev/parse-metafield.mjs +122 -134
- package/dist/browser-dev/parse-metafield.mjs.map +1 -1
- package/dist/browser-dev/storefront-api-constants.mjs +6 -5
- package/dist/browser-dev/storefront-api-constants.mjs.map +1 -1
- package/dist/browser-dev/storefront-client.mjs +62 -102
- package/dist/browser-dev/storefront-client.mjs.map +1 -1
- package/dist/browser-dev/tracking-utils.mjs +68 -88
- package/dist/browser-dev/tracking-utils.mjs.map +1 -1
- package/dist/browser-dev/useCartAPIStateMachine.mjs +188 -346
- package/dist/browser-dev/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/browser-dev/useCartActions.mjs +197 -172
- package/dist/browser-dev/useCartActions.mjs.map +1 -1
- package/dist/browser-dev/useMachine.mjs +50 -62
- package/dist/browser-dev/useMachine.mjs.map +1 -1
- package/dist/browser-dev/useMoney.mjs +176 -154
- package/dist/browser-dev/useMoney.mjs.map +1 -1
- package/dist/browser-dev/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/browser-dev/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/browser-dev/useShopifyCookies.mjs +123 -138
- package/dist/browser-dev/useShopifyCookies.mjs.map +1 -1
- package/dist/browser-prod/AddToCartButton.mjs +60 -71
- package/dist/browser-prod/AddToCartButton.mjs.map +1 -1
- package/dist/browser-prod/BaseButton.mjs +20 -26
- package/dist/browser-prod/BaseButton.mjs.map +1 -1
- package/dist/browser-prod/BuyNowButton.mjs +40 -45
- package/dist/browser-prod/BuyNowButton.mjs.map +1 -1
- package/dist/browser-prod/CartCheckoutButton.mjs +28 -23
- package/dist/browser-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/browser-prod/CartCost.mjs +26 -22
- package/dist/browser-prod/CartCost.mjs.map +1 -1
- package/dist/browser-prod/CartLineProvider.mjs +23 -18
- package/dist/browser-prod/CartLineProvider.mjs.map +1 -1
- package/dist/browser-prod/CartLineQuantity.mjs +18 -9
- package/dist/browser-prod/CartLineQuantity.mjs.map +1 -1
- package/dist/browser-prod/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/browser-prod/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/browser-prod/CartProvider.mjs +315 -385
- package/dist/browser-prod/CartProvider.mjs.map +1 -1
- package/dist/browser-prod/ExternalVideo.mjs +35 -47
- package/dist/browser-prod/ExternalVideo.mjs.map +1 -1
- package/dist/browser-prod/Image.mjs +326 -325
- package/dist/browser-prod/Image.mjs.map +1 -1
- package/dist/browser-prod/MediaFile.mjs +44 -63
- package/dist/browser-prod/MediaFile.mjs.map +1 -1
- package/dist/browser-prod/ModelViewer.mjs +117 -135
- package/dist/browser-prod/ModelViewer.mjs.map +1 -1
- package/dist/browser-prod/Money.mjs +53 -39
- package/dist/browser-prod/Money.mjs.map +1 -1
- package/dist/browser-prod/ProductPrice.mjs +44 -61
- package/dist/browser-prod/ProductPrice.mjs.map +1 -1
- package/dist/browser-prod/ProductProvider.mjs +147 -179
- package/dist/browser-prod/ProductProvider.mjs.map +1 -1
- package/dist/browser-prod/RichText.components.mjs +36 -46
- package/dist/browser-prod/RichText.components.mjs.map +1 -1
- package/dist/browser-prod/RichText.mjs +111 -154
- package/dist/browser-prod/RichText.mjs.map +1 -1
- package/dist/browser-prod/ShopPayButton.mjs +53 -81
- package/dist/browser-prod/ShopPayButton.mjs.map +1 -1
- package/dist/browser-prod/ShopifyProvider.mjs +71 -84
- package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-prod/Video.mjs +35 -52
- package/dist/browser-prod/Video.mjs.map +1 -1
- package/dist/browser-prod/analytics-constants.mjs +41 -43
- package/dist/browser-prod/analytics-constants.mjs.map +1 -1
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/browser-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/browser-prod/analytics-utils.mjs +78 -56
- package/dist/browser-prod/analytics-utils.mjs.map +1 -1
- package/dist/browser-prod/analytics.mjs +111 -153
- package/dist/browser-prod/analytics.mjs.map +1 -1
- package/dist/browser-prod/cart-constants.mjs +11 -15
- package/dist/browser-prod/cart-constants.mjs.map +1 -1
- package/dist/browser-prod/cart-hooks.mjs +42 -57
- package/dist/browser-prod/cart-hooks.mjs.map +1 -1
- package/dist/browser-prod/cart-queries.mjs +28 -66
- package/dist/browser-prod/cart-queries.mjs.map +1 -1
- package/dist/browser-prod/codegen.helpers.mjs +31 -20
- package/dist/browser-prod/codegen.helpers.mjs.map +1 -1
- package/dist/browser-prod/cookies-utils.mjs +44 -42
- package/dist/browser-prod/cookies-utils.mjs.map +1 -1
- package/dist/browser-prod/flatten-connection.mjs +23 -25
- package/dist/browser-prod/flatten-connection.mjs.map +1 -1
- package/dist/browser-prod/getProductOptions.mjs +248 -226
- package/dist/browser-prod/getProductOptions.mjs.map +1 -1
- package/dist/browser-prod/index.mjs +15 -70
- package/dist/browser-prod/load-script.mjs +38 -49
- package/dist/browser-prod/load-script.mjs.map +1 -1
- package/dist/browser-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/browser-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/browser-prod/optionValueDecoder.mjs +104 -86
- package/dist/browser-prod/optionValueDecoder.mjs.map +1 -1
- package/dist/browser-prod/packages/hydrogen-react/package.mjs +6 -0
- package/dist/browser-prod/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/browser-prod/parse-metafield.mjs +134 -146
- package/dist/browser-prod/parse-metafield.mjs.map +1 -1
- package/dist/browser-prod/storefront-api-constants.mjs +6 -5
- package/dist/browser-prod/storefront-api-constants.mjs.map +1 -1
- package/dist/browser-prod/storefront-client.mjs +56 -84
- package/dist/browser-prod/storefront-client.mjs.map +1 -1
- package/dist/browser-prod/tracking-utils.mjs +68 -88
- package/dist/browser-prod/tracking-utils.mjs.map +1 -1
- package/dist/browser-prod/useCartAPIStateMachine.mjs +188 -346
- package/dist/browser-prod/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/browser-prod/useCartActions.mjs +197 -172
- package/dist/browser-prod/useCartActions.mjs.map +1 -1
- package/dist/browser-prod/useMachine.mjs +50 -62
- package/dist/browser-prod/useMachine.mjs.map +1 -1
- package/dist/browser-prod/useMoney.mjs +176 -154
- package/dist/browser-prod/useMoney.mjs.map +1 -1
- package/dist/browser-prod/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/browser-prod/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/browser-prod/useShopifyCookies.mjs +123 -138
- package/dist/browser-prod/useShopifyCookies.mjs.map +1 -1
- package/dist/node-dev/AddToCartButton.js +64 -73
- package/dist/node-dev/AddToCartButton.js.map +1 -1
- package/dist/node-dev/AddToCartButton.mjs +60 -71
- package/dist/node-dev/AddToCartButton.mjs.map +1 -1
- package/dist/node-dev/BaseButton.js +21 -26
- package/dist/node-dev/BaseButton.js.map +1 -1
- package/dist/node-dev/BaseButton.mjs +20 -26
- package/dist/node-dev/BaseButton.mjs.map +1 -1
- package/dist/node-dev/BuyNowButton.js +42 -46
- package/dist/node-dev/BuyNowButton.js.map +1 -1
- package/dist/node-dev/BuyNowButton.mjs +40 -45
- package/dist/node-dev/BuyNowButton.mjs.map +1 -1
- package/dist/node-dev/CartCheckoutButton.js +30 -24
- package/dist/node-dev/CartCheckoutButton.js.map +1 -1
- package/dist/node-dev/CartCheckoutButton.mjs +28 -23
- package/dist/node-dev/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-dev/CartCost.js +27 -22
- package/dist/node-dev/CartCost.js.map +1 -1
- package/dist/node-dev/CartCost.mjs +26 -22
- package/dist/node-dev/CartCost.mjs.map +1 -1
- package/dist/node-dev/CartLineProvider.js +24 -17
- package/dist/node-dev/CartLineProvider.js.map +1 -1
- package/dist/node-dev/CartLineProvider.mjs +23 -18
- package/dist/node-dev/CartLineProvider.mjs.map +1 -1
- package/dist/node-dev/CartLineQuantity.js +19 -9
- package/dist/node-dev/CartLineQuantity.js.map +1 -1
- package/dist/node-dev/CartLineQuantity.mjs +18 -9
- package/dist/node-dev/CartLineQuantity.mjs.map +1 -1
- package/dist/node-dev/CartLineQuantityAdjustButton.js +50 -46
- package/dist/node-dev/CartLineQuantityAdjustButton.js.map +1 -1
- package/dist/node-dev/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/node-dev/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/node-dev/CartProvider.js +317 -385
- package/dist/node-dev/CartProvider.js.map +1 -1
- package/dist/node-dev/CartProvider.mjs +315 -385
- package/dist/node-dev/CartProvider.mjs.map +1 -1
- package/dist/node-dev/ExternalVideo.js +36 -47
- package/dist/node-dev/ExternalVideo.js.map +1 -1
- package/dist/node-dev/ExternalVideo.mjs +35 -47
- package/dist/node-dev/ExternalVideo.mjs.map +1 -1
- package/dist/node-dev/Image.js +337 -355
- package/dist/node-dev/Image.js.map +1 -1
- package/dist/node-dev/Image.mjs +335 -340
- package/dist/node-dev/Image.mjs.map +1 -1
- package/dist/node-dev/MediaFile.js +42 -63
- package/dist/node-dev/MediaFile.js.map +1 -1
- package/dist/node-dev/MediaFile.mjs +39 -61
- package/dist/node-dev/MediaFile.mjs.map +1 -1
- package/dist/node-dev/ModelViewer.js +116 -139
- package/dist/node-dev/ModelViewer.js.map +1 -1
- package/dist/node-dev/ModelViewer.mjs +115 -139
- package/dist/node-dev/ModelViewer.mjs.map +1 -1
- package/dist/node-dev/Money.js +54 -39
- package/dist/node-dev/Money.js.map +1 -1
- package/dist/node-dev/Money.mjs +53 -39
- package/dist/node-dev/Money.mjs.map +1 -1
- package/dist/node-dev/ProductPrice.js +45 -61
- package/dist/node-dev/ProductPrice.js.map +1 -1
- package/dist/node-dev/ProductPrice.mjs +44 -61
- package/dist/node-dev/ProductPrice.mjs.map +1 -1
- package/dist/node-dev/ProductProvider.js +148 -178
- package/dist/node-dev/ProductProvider.js.map +1 -1
- package/dist/node-dev/ProductProvider.mjs +147 -179
- package/dist/node-dev/ProductProvider.mjs.map +1 -1
- package/dist/node-dev/RichText.components.js +37 -46
- package/dist/node-dev/RichText.components.js.map +1 -1
- package/dist/node-dev/RichText.components.mjs +36 -46
- package/dist/node-dev/RichText.components.mjs.map +1 -1
- package/dist/node-dev/RichText.js +112 -154
- package/dist/node-dev/RichText.js.map +1 -1
- package/dist/node-dev/RichText.mjs +111 -154
- package/dist/node-dev/RichText.mjs.map +1 -1
- package/dist/node-dev/ShopPayButton.js +54 -81
- package/dist/node-dev/ShopPayButton.js.map +1 -1
- package/dist/node-dev/ShopPayButton.mjs +53 -81
- package/dist/node-dev/ShopPayButton.mjs.map +1 -1
- package/dist/node-dev/ShopifyProvider.js +73 -83
- package/dist/node-dev/ShopifyProvider.js.map +1 -1
- package/dist/node-dev/ShopifyProvider.mjs +71 -84
- package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/node-dev/Video.js +36 -52
- package/dist/node-dev/Video.js.map +1 -1
- package/dist/node-dev/Video.mjs +35 -52
- package/dist/node-dev/Video.mjs.map +1 -1
- package/dist/node-dev/_virtual/_rolldown/runtime.js +23 -0
- package/dist/node-dev/analytics-constants.js +40 -39
- package/dist/node-dev/analytics-constants.js.map +1 -1
- package/dist/node-dev/analytics-constants.mjs +41 -43
- package/dist/node-dev/analytics-constants.mjs.map +1 -1
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js +128 -210
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js.map +1 -1
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js +40 -51
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.js.map +1 -1
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/node-dev/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/node-dev/analytics-utils.js +77 -52
- package/dist/node-dev/analytics-utils.js.map +1 -1
- package/dist/node-dev/analytics-utils.mjs +78 -56
- package/dist/node-dev/analytics-utils.mjs.map +1 -1
- package/dist/node-dev/analytics.js +114 -156
- package/dist/node-dev/analytics.js.map +1 -1
- package/dist/node-dev/analytics.mjs +112 -155
- package/dist/node-dev/analytics.mjs.map +1 -1
- package/dist/node-dev/cart-constants.js +10 -9
- package/dist/node-dev/cart-constants.js.map +1 -1
- package/dist/node-dev/cart-constants.mjs +11 -15
- package/dist/node-dev/cart-constants.mjs.map +1 -1
- package/dist/node-dev/cart-hooks.js +43 -57
- package/dist/node-dev/cart-hooks.js.map +1 -1
- package/dist/node-dev/cart-hooks.mjs +42 -57
- package/dist/node-dev/cart-hooks.mjs.map +1 -1
- package/dist/node-dev/cart-queries.js +27 -56
- package/dist/node-dev/cart-queries.js.map +1 -1
- package/dist/node-dev/cart-queries.mjs +28 -66
- package/dist/node-dev/cart-queries.mjs.map +1 -1
- package/dist/node-dev/codegen.helpers.js +30 -18
- package/dist/node-dev/codegen.helpers.js.map +1 -1
- package/dist/node-dev/codegen.helpers.mjs +31 -20
- package/dist/node-dev/codegen.helpers.mjs.map +1 -1
- package/dist/node-dev/cookies-utils.js +45 -42
- package/dist/node-dev/cookies-utils.js.map +1 -1
- package/dist/node-dev/cookies-utils.mjs +44 -42
- package/dist/node-dev/cookies-utils.mjs.map +1 -1
- package/dist/node-dev/flatten-connection.js +22 -28
- package/dist/node-dev/flatten-connection.js.map +1 -1
- package/dist/node-dev/flatten-connection.mjs +23 -29
- package/dist/node-dev/flatten-connection.mjs.map +1 -1
- package/dist/node-dev/getProductOptions.js +248 -224
- package/dist/node-dev/getProductOptions.js.map +1 -1
- package/dist/node-dev/getProductOptions.mjs +248 -226
- package/dist/node-dev/getProductOptions.mjs.map +1 -1
- package/dist/node-dev/index.js +88 -90
- package/dist/node-dev/index.mjs +15 -70
- package/dist/node-dev/load-script.js +38 -48
- package/dist/node-dev/load-script.js.map +1 -1
- package/dist/node-dev/load-script.mjs +38 -49
- package/dist/node-dev/load-script.mjs.map +1 -1
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js +185 -124
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js.map +1 -1
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/node-dev/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/node-dev/optionValueDecoder.js +103 -84
- package/dist/node-dev/optionValueDecoder.js.map +1 -1
- package/dist/node-dev/optionValueDecoder.mjs +104 -86
- package/dist/node-dev/optionValueDecoder.mjs.map +1 -1
- package/dist/node-dev/packages/hydrogen-react/package.js +6 -0
- package/dist/node-dev/packages/hydrogen-react/package.js.map +1 -0
- package/dist/node-dev/packages/hydrogen-react/package.mjs +6 -0
- package/dist/node-dev/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/node-dev/parse-metafield.js +122 -134
- package/dist/node-dev/parse-metafield.js.map +1 -1
- package/dist/node-dev/parse-metafield.mjs +122 -134
- package/dist/node-dev/parse-metafield.mjs.map +1 -1
- package/dist/node-dev/storefront-api-constants.js +5 -4
- package/dist/node-dev/storefront-api-constants.js.map +1 -1
- package/dist/node-dev/storefront-api-constants.mjs +6 -5
- package/dist/node-dev/storefront-api-constants.mjs.map +1 -1
- package/dist/node-dev/storefront-client.js +62 -101
- package/dist/node-dev/storefront-client.js.map +1 -1
- package/dist/node-dev/storefront-client.mjs +62 -102
- package/dist/node-dev/storefront-client.mjs.map +1 -1
- package/dist/node-dev/tracking-utils.js +67 -85
- package/dist/node-dev/tracking-utils.js.map +1 -1
- package/dist/node-dev/tracking-utils.mjs +68 -88
- package/dist/node-dev/tracking-utils.mjs.map +1 -1
- package/dist/node-dev/useCartAPIStateMachine.js +192 -349
- package/dist/node-dev/useCartAPIStateMachine.js.map +1 -1
- package/dist/node-dev/useCartAPIStateMachine.mjs +188 -346
- package/dist/node-dev/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/node-dev/useCartActions.js +198 -172
- package/dist/node-dev/useCartActions.js.map +1 -1
- package/dist/node-dev/useCartActions.mjs +197 -172
- package/dist/node-dev/useCartActions.mjs.map +1 -1
- package/dist/node-dev/useMachine.js +50 -61
- package/dist/node-dev/useMachine.js.map +1 -1
- package/dist/node-dev/useMachine.mjs +50 -62
- package/dist/node-dev/useMachine.mjs.map +1 -1
- package/dist/node-dev/useMoney.js +177 -154
- package/dist/node-dev/useMoney.js.map +1 -1
- package/dist/node-dev/useMoney.mjs +176 -154
- package/dist/node-dev/useMoney.mjs.map +1 -1
- package/dist/node-dev/useSelectedOptionInUrlParam.js +18 -27
- package/dist/node-dev/useSelectedOptionInUrlParam.js.map +1 -1
- package/dist/node-dev/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/node-dev/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/node-dev/useShopifyCookies.js +124 -138
- package/dist/node-dev/useShopifyCookies.js.map +1 -1
- package/dist/node-dev/useShopifyCookies.mjs +123 -138
- package/dist/node-dev/useShopifyCookies.mjs.map +1 -1
- package/dist/node-prod/AddToCartButton.js +64 -73
- package/dist/node-prod/AddToCartButton.js.map +1 -1
- package/dist/node-prod/AddToCartButton.mjs +60 -71
- package/dist/node-prod/AddToCartButton.mjs.map +1 -1
- package/dist/node-prod/BaseButton.js +21 -26
- package/dist/node-prod/BaseButton.js.map +1 -1
- package/dist/node-prod/BaseButton.mjs +20 -26
- package/dist/node-prod/BaseButton.mjs.map +1 -1
- package/dist/node-prod/BuyNowButton.js +42 -46
- package/dist/node-prod/BuyNowButton.js.map +1 -1
- package/dist/node-prod/BuyNowButton.mjs +40 -45
- package/dist/node-prod/BuyNowButton.mjs.map +1 -1
- package/dist/node-prod/CartCheckoutButton.js +30 -24
- package/dist/node-prod/CartCheckoutButton.js.map +1 -1
- package/dist/node-prod/CartCheckoutButton.mjs +28 -23
- package/dist/node-prod/CartCheckoutButton.mjs.map +1 -1
- package/dist/node-prod/CartCost.js +27 -22
- package/dist/node-prod/CartCost.js.map +1 -1
- package/dist/node-prod/CartCost.mjs +26 -22
- package/dist/node-prod/CartCost.mjs.map +1 -1
- package/dist/node-prod/CartLineProvider.js +24 -17
- package/dist/node-prod/CartLineProvider.js.map +1 -1
- package/dist/node-prod/CartLineProvider.mjs +23 -18
- package/dist/node-prod/CartLineProvider.mjs.map +1 -1
- package/dist/node-prod/CartLineQuantity.js +19 -9
- package/dist/node-prod/CartLineQuantity.js.map +1 -1
- package/dist/node-prod/CartLineQuantity.mjs +18 -9
- package/dist/node-prod/CartLineQuantity.mjs.map +1 -1
- package/dist/node-prod/CartLineQuantityAdjustButton.js +50 -46
- package/dist/node-prod/CartLineQuantityAdjustButton.js.map +1 -1
- package/dist/node-prod/CartLineQuantityAdjustButton.mjs +48 -45
- package/dist/node-prod/CartLineQuantityAdjustButton.mjs.map +1 -1
- package/dist/node-prod/CartProvider.js +317 -385
- package/dist/node-prod/CartProvider.js.map +1 -1
- package/dist/node-prod/CartProvider.mjs +315 -385
- package/dist/node-prod/CartProvider.mjs.map +1 -1
- package/dist/node-prod/ExternalVideo.js +36 -47
- package/dist/node-prod/ExternalVideo.js.map +1 -1
- package/dist/node-prod/ExternalVideo.mjs +35 -47
- package/dist/node-prod/ExternalVideo.mjs.map +1 -1
- package/dist/node-prod/Image.js +328 -340
- package/dist/node-prod/Image.js.map +1 -1
- package/dist/node-prod/Image.mjs +326 -325
- package/dist/node-prod/Image.mjs.map +1 -1
- package/dist/node-prod/MediaFile.js +47 -65
- package/dist/node-prod/MediaFile.js.map +1 -1
- package/dist/node-prod/MediaFile.mjs +44 -63
- package/dist/node-prod/MediaFile.mjs.map +1 -1
- package/dist/node-prod/ModelViewer.js +118 -135
- package/dist/node-prod/ModelViewer.js.map +1 -1
- package/dist/node-prod/ModelViewer.mjs +117 -135
- package/dist/node-prod/ModelViewer.mjs.map +1 -1
- package/dist/node-prod/Money.js +54 -39
- package/dist/node-prod/Money.js.map +1 -1
- package/dist/node-prod/Money.mjs +53 -39
- package/dist/node-prod/Money.mjs.map +1 -1
- package/dist/node-prod/ProductPrice.js +45 -61
- package/dist/node-prod/ProductPrice.js.map +1 -1
- package/dist/node-prod/ProductPrice.mjs +44 -61
- package/dist/node-prod/ProductPrice.mjs.map +1 -1
- package/dist/node-prod/ProductProvider.js +148 -178
- package/dist/node-prod/ProductProvider.js.map +1 -1
- package/dist/node-prod/ProductProvider.mjs +147 -179
- package/dist/node-prod/ProductProvider.mjs.map +1 -1
- package/dist/node-prod/RichText.components.js +37 -46
- package/dist/node-prod/RichText.components.js.map +1 -1
- package/dist/node-prod/RichText.components.mjs +36 -46
- package/dist/node-prod/RichText.components.mjs.map +1 -1
- package/dist/node-prod/RichText.js +112 -154
- package/dist/node-prod/RichText.js.map +1 -1
- package/dist/node-prod/RichText.mjs +111 -154
- package/dist/node-prod/RichText.mjs.map +1 -1
- package/dist/node-prod/ShopPayButton.js +54 -81
- package/dist/node-prod/ShopPayButton.js.map +1 -1
- package/dist/node-prod/ShopPayButton.mjs +53 -81
- package/dist/node-prod/ShopPayButton.mjs.map +1 -1
- package/dist/node-prod/ShopifyProvider.js +73 -83
- package/dist/node-prod/ShopifyProvider.js.map +1 -1
- package/dist/node-prod/ShopifyProvider.mjs +71 -84
- package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/node-prod/Video.js +36 -52
- package/dist/node-prod/Video.js.map +1 -1
- package/dist/node-prod/Video.mjs +35 -52
- package/dist/node-prod/Video.mjs.map +1 -1
- package/dist/node-prod/_virtual/_rolldown/runtime.js +23 -0
- package/dist/node-prod/analytics-constants.js +40 -39
- package/dist/node-prod/analytics-constants.js.map +1 -1
- package/dist/node-prod/analytics-constants.mjs +41 -43
- package/dist/node-prod/analytics-constants.mjs.map +1 -1
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js +128 -210
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js.map +1 -1
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs +127 -214
- package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js +40 -51
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.js.map +1 -1
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs +39 -50
- package/dist/node-prod/analytics-schema-trekkie-storefront-page-view.mjs.map +1 -1
- package/dist/node-prod/analytics-utils.js +77 -52
- package/dist/node-prod/analytics-utils.js.map +1 -1
- package/dist/node-prod/analytics-utils.mjs +78 -56
- package/dist/node-prod/analytics-utils.mjs.map +1 -1
- package/dist/node-prod/analytics.js +113 -154
- package/dist/node-prod/analytics.js.map +1 -1
- package/dist/node-prod/analytics.mjs +111 -153
- package/dist/node-prod/analytics.mjs.map +1 -1
- package/dist/node-prod/cart-constants.js +10 -9
- package/dist/node-prod/cart-constants.js.map +1 -1
- package/dist/node-prod/cart-constants.mjs +11 -15
- package/dist/node-prod/cart-constants.mjs.map +1 -1
- package/dist/node-prod/cart-hooks.js +43 -57
- package/dist/node-prod/cart-hooks.js.map +1 -1
- package/dist/node-prod/cart-hooks.mjs +42 -57
- package/dist/node-prod/cart-hooks.mjs.map +1 -1
- package/dist/node-prod/cart-queries.js +27 -56
- package/dist/node-prod/cart-queries.js.map +1 -1
- package/dist/node-prod/cart-queries.mjs +28 -66
- package/dist/node-prod/cart-queries.mjs.map +1 -1
- package/dist/node-prod/codegen.helpers.js +30 -18
- package/dist/node-prod/codegen.helpers.js.map +1 -1
- package/dist/node-prod/codegen.helpers.mjs +31 -20
- package/dist/node-prod/codegen.helpers.mjs.map +1 -1
- package/dist/node-prod/cookies-utils.js +45 -42
- package/dist/node-prod/cookies-utils.js.map +1 -1
- package/dist/node-prod/cookies-utils.mjs +44 -42
- package/dist/node-prod/cookies-utils.mjs.map +1 -1
- package/dist/node-prod/flatten-connection.js +22 -24
- package/dist/node-prod/flatten-connection.js.map +1 -1
- package/dist/node-prod/flatten-connection.mjs +23 -25
- package/dist/node-prod/flatten-connection.mjs.map +1 -1
- package/dist/node-prod/getProductOptions.js +248 -224
- package/dist/node-prod/getProductOptions.js.map +1 -1
- package/dist/node-prod/getProductOptions.mjs +248 -226
- package/dist/node-prod/getProductOptions.mjs.map +1 -1
- package/dist/node-prod/index.js +88 -90
- package/dist/node-prod/index.mjs +15 -70
- package/dist/node-prod/load-script.js +38 -48
- package/dist/node-prod/load-script.js.map +1 -1
- package/dist/node-prod/load-script.mjs +38 -49
- package/dist/node-prod/load-script.mjs.map +1 -1
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js +185 -124
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.js.map +1 -1
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs +175 -123
- package/dist/node-prod/node_modules/.pnpm/@xstate_fsm@2.0.0/node_modules/@xstate/fsm/es/index.mjs.map +1 -1
- package/dist/node-prod/optionValueDecoder.js +103 -84
- package/dist/node-prod/optionValueDecoder.js.map +1 -1
- package/dist/node-prod/optionValueDecoder.mjs +104 -86
- package/dist/node-prod/optionValueDecoder.mjs.map +1 -1
- package/dist/node-prod/packages/hydrogen-react/package.js +6 -0
- package/dist/node-prod/packages/hydrogen-react/package.js.map +1 -0
- package/dist/node-prod/packages/hydrogen-react/package.mjs +6 -0
- package/dist/node-prod/packages/hydrogen-react/package.mjs.map +1 -0
- package/dist/node-prod/parse-metafield.js +134 -146
- package/dist/node-prod/parse-metafield.js.map +1 -1
- package/dist/node-prod/parse-metafield.mjs +134 -146
- package/dist/node-prod/parse-metafield.mjs.map +1 -1
- package/dist/node-prod/storefront-api-constants.js +5 -4
- package/dist/node-prod/storefront-api-constants.js.map +1 -1
- package/dist/node-prod/storefront-api-constants.mjs +6 -5
- package/dist/node-prod/storefront-api-constants.mjs.map +1 -1
- package/dist/node-prod/storefront-client.js +56 -83
- package/dist/node-prod/storefront-client.js.map +1 -1
- package/dist/node-prod/storefront-client.mjs +56 -84
- package/dist/node-prod/storefront-client.mjs.map +1 -1
- package/dist/node-prod/tracking-utils.js +67 -85
- package/dist/node-prod/tracking-utils.js.map +1 -1
- package/dist/node-prod/tracking-utils.mjs +68 -88
- package/dist/node-prod/tracking-utils.mjs.map +1 -1
- package/dist/node-prod/useCartAPIStateMachine.js +192 -349
- package/dist/node-prod/useCartAPIStateMachine.js.map +1 -1
- package/dist/node-prod/useCartAPIStateMachine.mjs +188 -346
- package/dist/node-prod/useCartAPIStateMachine.mjs.map +1 -1
- package/dist/node-prod/useCartActions.js +198 -172
- package/dist/node-prod/useCartActions.js.map +1 -1
- package/dist/node-prod/useCartActions.mjs +197 -172
- package/dist/node-prod/useCartActions.mjs.map +1 -1
- package/dist/node-prod/useMachine.js +50 -61
- package/dist/node-prod/useMachine.js.map +1 -1
- package/dist/node-prod/useMachine.mjs +50 -62
- package/dist/node-prod/useMachine.mjs.map +1 -1
- package/dist/node-prod/useMoney.js +177 -154
- package/dist/node-prod/useMoney.js.map +1 -1
- package/dist/node-prod/useMoney.mjs +176 -154
- package/dist/node-prod/useMoney.mjs.map +1 -1
- package/dist/node-prod/useSelectedOptionInUrlParam.js +18 -27
- package/dist/node-prod/useSelectedOptionInUrlParam.js.map +1 -1
- package/dist/node-prod/useSelectedOptionInUrlParam.mjs +17 -27
- package/dist/node-prod/useSelectedOptionInUrlParam.mjs.map +1 -1
- package/dist/node-prod/useShopifyCookies.js +124 -138
- package/dist/node-prod/useShopifyCookies.js.map +1 -1
- package/dist/node-prod/useShopifyCookies.mjs +123 -138
- package/dist/node-prod/useShopifyCookies.mjs.map +1 -1
- package/dist/umd/hydrogen-react.dev.js +3930 -4418
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +35 -49
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +5 -5
- package/dist/browser-dev/index.mjs.map +0 -1
- package/dist/browser-dev/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/browser-dev/packages/hydrogen-react/package.json.mjs.map +0 -1
- package/dist/browser-prod/index.mjs.map +0 -1
- package/dist/browser-prod/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/browser-prod/packages/hydrogen-react/package.json.mjs.map +0 -1
- package/dist/node-dev/index.js.map +0 -1
- package/dist/node-dev/index.mjs.map +0 -1
- package/dist/node-dev/packages/hydrogen-react/package.json.js +0 -5
- package/dist/node-dev/packages/hydrogen-react/package.json.js.map +0 -1
- package/dist/node-dev/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/node-dev/packages/hydrogen-react/package.json.mjs.map +0 -1
- package/dist/node-prod/index.js.map +0 -1
- package/dist/node-prod/index.mjs.map +0 -1
- package/dist/node-prod/packages/hydrogen-react/package.json.js +0 -5
- package/dist/node-prod/packages/hydrogen-react/package.json.js.map +0 -1
- package/dist/node-prod/packages/hydrogen-react/package.json.mjs +0 -5
- package/dist/node-prod/packages/hydrogen-react/package.json.mjs.map +0 -1
|
@@ -1,92 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region src/optionValueDecoder.ts
|
|
2
|
+
var OPTION_VALUE_SEPARATOR = ",";
|
|
3
|
+
var V1_CONTROL_CHARS = {
|
|
4
|
+
OPTION: ":",
|
|
5
|
+
END_OF_PREFIX: ",",
|
|
6
|
+
SEQUENCE_GAP: " ",
|
|
7
|
+
RANGE: "-"
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
9
|
+
/**
|
|
10
|
+
* Determine whether an option value combination is present in an encoded option value string. Function is memoized by encodedVariantField.
|
|
11
|
+
*
|
|
12
|
+
* @param targetOptionValueCombination - Indices of option values to look up in the encoded option value string. A partial set of indices may be passed to determine whether a node or any children is present. For example, if a product has 3 options, passing [0] will return true if any option value combination for the first option's option value is present in the encoded string.
|
|
13
|
+
* @param encodedVariantField - Encoded option value string from the Storefront API, e.g. [product.encodedVariantExistence](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantexistence) or [product.encodedVariantAvailability](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantavailability)
|
|
14
|
+
* @returns - True if a full or partial targetOptionValueIndices is present in the encoded option value string, false otherwise.
|
|
15
|
+
* @publicDocs
|
|
16
|
+
*/
|
|
17
|
+
var isOptionValueCombinationInEncodedVariant = (() => {
|
|
18
|
+
const decodedOptionValues = /* @__PURE__ */ new Map();
|
|
19
|
+
return function(targetOptionValueCombination, encodedVariantField) {
|
|
20
|
+
if (targetOptionValueCombination.length === 0) return false;
|
|
21
|
+
if (!decodedOptionValues.has(encodedVariantField)) {
|
|
22
|
+
const decodedOptionValuesSet = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const optionValue of decodeEncodedVariant(encodedVariantField)) {
|
|
24
|
+
decodedOptionValuesSet.add(optionValue.join(OPTION_VALUE_SEPARATOR));
|
|
25
|
+
for (let i = 0; i < optionValue.length; i++) decodedOptionValuesSet.add(optionValue.slice(0, i + 1).join(OPTION_VALUE_SEPARATOR));
|
|
26
|
+
}
|
|
27
|
+
decodedOptionValues.set(encodedVariantField, decodedOptionValuesSet);
|
|
28
|
+
}
|
|
29
|
+
return Boolean(decodedOptionValues.get(encodedVariantField)?.has(targetOptionValueCombination.join(OPTION_VALUE_SEPARATOR)));
|
|
30
|
+
};
|
|
31
31
|
})();
|
|
32
|
+
/**
|
|
33
|
+
* For an encoded option value string, decode into option value combinations. Entries represent a valid combination formatted as an array of option value positions.
|
|
34
|
+
* @param encodedVariantField - Encoded option value string from the Storefront API, e.g. [product.encodedVariantExistence](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantexistence) or [product.encodedVariantAvailability](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantavailability)
|
|
35
|
+
* @returns Decoded option value combinations
|
|
36
|
+
* @publicDocs
|
|
37
|
+
*/
|
|
32
38
|
function decodeEncodedVariant(encodedVariantField) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
throw new Error("Unsupported option value encoding");
|
|
39
|
+
if (!encodedVariantField) return [];
|
|
40
|
+
if (encodedVariantField.startsWith("v1_")) return v1Decoder(stripVersion(encodedVariantField));
|
|
41
|
+
throw new Error("Unsupported option value encoding");
|
|
38
42
|
}
|
|
39
|
-
|
|
43
|
+
var stripVersion = (encodedVariantField) => encodedVariantField.replace(/^v1_/, "");
|
|
44
|
+
/**
|
|
45
|
+
* We encode an array of arrays representing variants, expressed in terms of options and option values, as a trie.
|
|
46
|
+
*
|
|
47
|
+
* This encoding strategy allows extremely large numbers of variants to be expressed in an extremely compact data structure.
|
|
48
|
+
*
|
|
49
|
+
* Integers represent option and values, so [0,0,0] represents option_value at array index 0 for the options at array indexes 0, 1 and 2
|
|
50
|
+
*
|
|
51
|
+
* `:`, `,`, ` ` and `-` are control characters.
|
|
52
|
+
* `:` indicates a new option
|
|
53
|
+
* `,` indicates the end of a repeated prefix, mulitple consecutive commas indicate the end of multiple repeated prefixes.
|
|
54
|
+
* ` ` indicates a gap in the sequence of option values
|
|
55
|
+
* `-` indicates a continuous range of option values
|
|
56
|
+
*
|
|
57
|
+
* Encoding process:
|
|
58
|
+
*
|
|
59
|
+
* example input array: [[0,0,0], [0,1,0], [0,1,1], [1,0,0], [1,0,1], [1,1,1], [2,0,1], [2,1,0]]
|
|
60
|
+
*
|
|
61
|
+
* step 1: encode as string: "0:0:0,0:1:0,0:1:1,1:0:0,1:0:1,1:1:1,2:0:1,2:1:0,"
|
|
62
|
+
* step 2: combine nodes that share a prefix: "0:0:0,0:1:0 1,1:0:0 1,1:1:1,2:0:1,2:1:0,"
|
|
63
|
+
* step 3: encode data as a trie so no prefixes need to be repeated: "0:0:0,1:0 1,,1:0:0 1,1:1,,2:0:1,1:0,,"
|
|
64
|
+
* step 4: since the options are sorted, use a dash to express ranges: "0:0:0,1:0-1,,1:0:0-1,1:1,,2:0:1,1:0,,"
|
|
65
|
+
*/
|
|
40
66
|
function v1Decoder(encodedVariantField) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
options.push([...currentOptionValue]);
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
options.push([finalValueIndex]);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return options;
|
|
67
|
+
const tokenizer = /[ :,-]/g;
|
|
68
|
+
let index = 0;
|
|
69
|
+
let token;
|
|
70
|
+
const options = [];
|
|
71
|
+
const currentOptionValue = [];
|
|
72
|
+
let depth = 0;
|
|
73
|
+
let rangeStart = null;
|
|
74
|
+
while (token = tokenizer.exec(encodedVariantField)) {
|
|
75
|
+
const operation = token[0];
|
|
76
|
+
const optionValueIndex = Number.parseInt(encodedVariantField.slice(index, token.index)) || 0;
|
|
77
|
+
if (rangeStart !== null) {
|
|
78
|
+
for (; rangeStart < optionValueIndex; rangeStart++) {
|
|
79
|
+
currentOptionValue[depth] = rangeStart;
|
|
80
|
+
options.push([...currentOptionValue]);
|
|
81
|
+
}
|
|
82
|
+
rangeStart = null;
|
|
83
|
+
}
|
|
84
|
+
currentOptionValue[depth] = optionValueIndex;
|
|
85
|
+
if (operation === V1_CONTROL_CHARS.RANGE) rangeStart = optionValueIndex;
|
|
86
|
+
else if (operation === V1_CONTROL_CHARS.OPTION) depth++;
|
|
87
|
+
else {
|
|
88
|
+
if (operation === V1_CONTROL_CHARS.SEQUENCE_GAP || operation === V1_CONTROL_CHARS.END_OF_PREFIX && encodedVariantField[token.index - 1] !== V1_CONTROL_CHARS.END_OF_PREFIX) options.push([...currentOptionValue]);
|
|
89
|
+
if (operation === V1_CONTROL_CHARS.END_OF_PREFIX) {
|
|
90
|
+
currentOptionValue.pop();
|
|
91
|
+
depth--;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
index = tokenizer.lastIndex;
|
|
95
|
+
}
|
|
96
|
+
const encodingEndsWithIndex = encodedVariantField.match(/\d+$/g);
|
|
97
|
+
if (encodingEndsWithIndex) {
|
|
98
|
+
const finalValueIndex = parseInt(encodingEndsWithIndex[0]);
|
|
99
|
+
if (rangeStart != null) for (; rangeStart <= finalValueIndex; rangeStart++) {
|
|
100
|
+
currentOptionValue[depth] = rangeStart;
|
|
101
|
+
options.push([...currentOptionValue]);
|
|
102
|
+
}
|
|
103
|
+
else options.push([finalValueIndex]);
|
|
104
|
+
}
|
|
105
|
+
return options;
|
|
87
106
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//# sourceMappingURL=optionValueDecoder.mjs.map
|
|
107
|
+
//#endregion
|
|
108
|
+
export { decodeEncodedVariant, isOptionValueCombinationInEncodedVariant };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=optionValueDecoder.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optionValueDecoder.mjs","sources":["../../src/optionValueDecoder.ts"],"sourcesContent":["/**\n * This file provides utility functions for determining whether or not an option value combination is present in an encoded option value string.\n *\n * In V1 of the encoding strategy, option value arrays are encoded as a trie with the following rules:\n * - `:` `,` ` ` and `-` are control characters.\n * - `:` indicates a new option. ex: 0:1 indicates value 0 for the option in position 1, value 1 for the option in position 2.\n * - `,` indicates the end of a repeated prefix, mulitple consecutive commas indicate the end of multiple repeated prefixes.\n * - ` ` indicates a gap in the sequence of option values. ex: `0 4` indicates option values in position 0 and 4 are present.\n * - `-` indicates a continuous range of option values. ex: `0 1-3 4`. Ranges are only present encoded in the final option value position, so for example the trie for the set [[0,0,0],[0,0,1], ..., [0,2,2]] will be structured as `0:0:0-2,1:0-2,2:0-2`, not `0:0-2:0-2`.\n */\n\nimport {Product} from './storefront-api-types.js';\n\nconst OPTION_VALUE_SEPARATOR = ',';\n\nconst V1_CONTROL_CHARS = {\n OPTION: ':',\n END_OF_PREFIX: ',',\n SEQUENCE_GAP: ' ',\n RANGE: '-',\n};\n\n/** @publicDocs */\nexport type IsOptionValueCombinationInEncodedVariant = (\n targetOptionValueCombination: number[],\n encodedVariantField: string,\n) => boolean;\n\n/**\n * Determine whether an option value combination is present in an encoded option value string. Function is memoized by encodedVariantField.\n *\n * @param targetOptionValueCombination - Indices of option values to look up in the encoded option value string. A partial set of indices may be passed to determine whether a node or any children is present. For example, if a product has 3 options, passing [0] will return true if any option value combination for the first option's option value is present in the encoded string.\n * @param encodedVariantField - Encoded option value string from the Storefront API, e.g. [product.encodedVariantExistence](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantexistence) or [product.encodedVariantAvailability](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantavailability)\n * @returns - True if a full or partial targetOptionValueIndices is present in the encoded option value string, false otherwise.\n * @publicDocs\n */\nexport const isOptionValueCombinationInEncodedVariant: IsOptionValueCombinationInEncodedVariant =\n ((): IsOptionValueCombinationInEncodedVariant => {\n const decodedOptionValues = new Map<string, Set<string>>();\n\n return function (\n targetOptionValueCombination: number[],\n encodedVariantField: string,\n ): boolean {\n if (targetOptionValueCombination.length === 0) {\n return false;\n }\n\n if (!decodedOptionValues.has(encodedVariantField)) {\n const decodedOptionValuesSet = new Set<string>();\n\n for (const optionValue of decodeEncodedVariant(encodedVariantField)) {\n // add the complete option value to the decoded option values set\n decodedOptionValuesSet.add(optionValue.join(OPTION_VALUE_SEPARATOR));\n\n // add all composite parts of the option value to the decoded option values set. e.g. if the option value is [0,1,2], add \"0\", \"0,1\", \"0,1,2\"\n for (let i = 0; i < optionValue.length; i++) {\n decodedOptionValuesSet.add(\n optionValue.slice(0, i + 1).join(OPTION_VALUE_SEPARATOR),\n );\n }\n }\n\n decodedOptionValues.set(encodedVariantField, decodedOptionValuesSet);\n }\n\n return Boolean(\n decodedOptionValues\n .get(encodedVariantField)\n ?.has(targetOptionValueCombination.join(OPTION_VALUE_SEPARATOR)),\n );\n };\n })();\n\ntype EncodedVariantField =\n | Product['encodedVariantAvailability']\n // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents\n | Product['encodedVariantExistence'];\ntype DecodedOptionValues = number[][];\n\n/**\n * For an encoded option value string, decode into option value combinations. Entries represent a valid combination formatted as an array of option value positions.\n * @param encodedVariantField - Encoded option value string from the Storefront API, e.g. [product.encodedVariantExistence](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantexistence) or [product.encodedVariantAvailability](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantavailability)\n * @returns Decoded option value combinations\n * @publicDocs\n */\nexport function decodeEncodedVariant(\n encodedVariantField: EncodedVariantField,\n): DecodedOptionValues {\n if (!encodedVariantField) return [];\n\n if (encodedVariantField.startsWith('v1_')) {\n return v1Decoder(stripVersion(encodedVariantField));\n }\n\n throw new Error('Unsupported option value encoding');\n}\n\nconst stripVersion: (encodedVariantField: string) => string = (\n encodedVariantField: string,\n) => encodedVariantField.replace(/^v1_/, '');\n\n/**\n * We encode an array of arrays representing variants, expressed in terms of options and option values, as a trie.\n *\n * This encoding strategy allows extremely large numbers of variants to be expressed in an extremely compact data structure.\n *\n * Integers represent option and values, so [0,0,0] represents option_value at array index 0 for the options at array indexes 0, 1 and 2\n *\n * `:`, `,`, ` ` and `-` are control characters.\n * `:` indicates a new option\n * `,` indicates the end of a repeated prefix, mulitple consecutive commas indicate the end of multiple repeated prefixes.\n * ` ` indicates a gap in the sequence of option values\n * `-` indicates a continuous range of option values\n *\n * Encoding process:\n *\n * example input array: [[0,0,0], [0,1,0], [0,1,1], [1,0,0], [1,0,1], [1,1,1], [2,0,1], [2,1,0]]\n *\n * step 1: encode as string: \"0:0:0,0:1:0,0:1:1,1:0:0,1:0:1,1:1:1,2:0:1,2:1:0,\"\n * step 2: combine nodes that share a prefix: \"0:0:0,0:1:0 1,1:0:0 1,1:1:1,2:0:1,2:1:0,\"\n * step 3: encode data as a trie so no prefixes need to be repeated: \"0:0:0,1:0 1,,1:0:0 1,1:1,,2:0:1,1:0,,\"\n * step 4: since the options are sorted, use a dash to express ranges: \"0:0:0,1:0-1,,1:0:0-1,1:1,,2:0:1,1:0,,\"\n */\nfunction v1Decoder(encodedVariantField: string): number[][] {\n const tokenizer = /[ :,-]/g;\n let index = 0;\n let token: RegExpExecArray | null;\n const options: number[][] = [];\n const currentOptionValue: number[] = [];\n let depth = 0;\n let rangeStart: number | null = null;\n\n // iterate over control characters\n while ((token = tokenizer.exec(encodedVariantField))) {\n const operation = token[0];\n const optionValueIndex =\n Number.parseInt(encodedVariantField.slice(index, token.index)) || 0;\n\n if (rangeStart !== null) {\n // If a range has been started, iterate over the range and add each option value to the list of options\n // - `rangeStart` is set if the last control char was a dash, e.g. `0` for 0-2. It represents the numeric option value position for the start of the range.\n // - `optionValueIndex` is the numeric option value position for the end of the range\n for (; rangeStart < optionValueIndex; rangeStart++) {\n currentOptionValue[depth] = rangeStart;\n options.push([...currentOptionValue]);\n }\n // indicates the range has been processed\n rangeStart = null;\n }\n\n currentOptionValue[depth] = optionValueIndex;\n\n if (operation === V1_CONTROL_CHARS.RANGE) {\n // dash operation indicates we are in a range. e.g. 0-2 means option values 0, 1, 2\n rangeStart = optionValueIndex;\n } else if (operation === V1_CONTROL_CHARS.OPTION) {\n // colon operation indicates that we are moving down to the next layer of option values. e.g. 0:0:0-2 means we traverse down from option1 to option3 and represents [[0,0,0], [0,0,1], [0,0,2]]\n depth++;\n } else {\n if (\n operation === V1_CONTROL_CHARS.SEQUENCE_GAP ||\n (operation === V1_CONTROL_CHARS.END_OF_PREFIX &&\n encodedVariantField[token.index - 1] !==\n V1_CONTROL_CHARS.END_OF_PREFIX)\n ) {\n // add the current option value to the list of options if we hit a gap in our sequence or we are at the end of our depth and need to move back up\n options.push([...currentOptionValue]);\n }\n if (operation === V1_CONTROL_CHARS.END_OF_PREFIX) {\n // go up an option level, trash the last item in currentOptionValue\n currentOptionValue.pop();\n depth--;\n }\n }\n index = tokenizer.lastIndex;\n }\n\n // The while loop only iterates control characters, meaning if an encoded string ends with an index it will not be processed.\n const encodingEndsWithIndex = encodedVariantField.match(/\\d+$/g);\n if (encodingEndsWithIndex) {\n const finalValueIndex = parseInt(encodingEndsWithIndex[0]);\n if (rangeStart != null) {\n // process final range\n for (; rangeStart <= finalValueIndex; rangeStart++) {\n currentOptionValue[depth] = rangeStart;\n options.push([...currentOptionValue]);\n }\n } else {\n // process final index\n options.push([finalValueIndex]);\n }\n }\n\n return options;\n}\n"],"names":[],"mappings":"AAaA,MAAM,yBAAyB;AAE/B,MAAM,mBAAmB;AAAA,EACvB,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,cAAc;AAAA,EACd,OAAO;AACT;AAgBO,MAAM,2CACV,uBAAgD;AAC/C,QAAM,0CAA0B,IAAA;AAEhC,SAAO,SACL,8BACA,qBACS;AA9Bf;AA+BM,QAAI,6BAA6B,WAAW,GAAG;AAC7C,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,oBAAoB,IAAI,mBAAmB,GAAG;AACjD,YAAM,6CAA6B,IAAA;AAEnC,iBAAW,eAAe,qBAAqB,mBAAmB,GAAG;AAEnE,+BAAuB,IAAI,YAAY,KAAK,sBAAsB,CAAC;AAGnE,iBAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;AAC3C,iCAAuB;AAAA,YACrB,YAAY,MAAM,GAAG,IAAI,CAAC,EAAE,KAAK,sBAAsB;AAAA,UAAA;AAAA,QAE3D;AAAA,MACF;AAEA,0BAAoB,IAAI,qBAAqB,sBAAsB;AAAA,IACrE;AAEA,WAAO;AAAA,OACL,yBACG,IAAI,mBAAmB,MAD1B,mBAEI,IAAI,6BAA6B,KAAK,sBAAsB;AAAA,IAAC;AAAA,EAErE;AACF,GAAA;AAcK,SAAS,qBACd,qBACqB;AACrB,MAAI,CAAC,oBAAqB,QAAO,CAAA;AAEjC,MAAI,oBAAoB,WAAW,KAAK,GAAG;AACzC,WAAO,UAAU,aAAa,mBAAmB,CAAC;AAAA,EACpD;AAEA,QAAM,IAAI,MAAM,mCAAmC;AACrD;AAEA,MAAM,eAAwD,CAC5D,wBACG,oBAAoB,QAAQ,QAAQ,EAAE;AAwB3C,SAAS,UAAU,qBAAyC;AAC1D,QAAM,YAAY;AAClB,MAAI,QAAQ;AACZ,MAAI;AACJ,QAAM,UAAsB,CAAA;AAC5B,QAAM,qBAA+B,CAAA;AACrC,MAAI,QAAQ;AACZ,MAAI,aAA4B;AAGhC,SAAQ,QAAQ,UAAU,KAAK,mBAAmB,GAAI;AACpD,UAAM,YAAY,MAAM,CAAC;AACzB,UAAM,mBACJ,OAAO,SAAS,oBAAoB,MAAM,OAAO,MAAM,KAAK,CAAC,KAAK;AAEpE,QAAI,eAAe,MAAM;AAIvB,aAAO,aAAa,kBAAkB,cAAc;AAClD,2BAAmB,KAAK,IAAI;AAC5B,gBAAQ,KAAK,CAAC,GAAG,kBAAkB,CAAC;AAAA,MACtC;AAEA,mBAAa;AAAA,IACf;AAEA,uBAAmB,KAAK,IAAI;AAE5B,QAAI,cAAc,iBAAiB,OAAO;AAExC,mBAAa;AAAA,IACf,WAAW,cAAc,iBAAiB,QAAQ;AAEhD;AAAA,IACF,OAAO;AACL,UACE,cAAc,iBAAiB,gBAC9B,cAAc,iBAAiB,iBAC9B,oBAAoB,MAAM,QAAQ,CAAC,MACjC,iBAAiB,eACrB;AAEA,gBAAQ,KAAK,CAAC,GAAG,kBAAkB,CAAC;AAAA,MACtC;AACA,UAAI,cAAc,iBAAiB,eAAe;AAEhD,2BAAmB,IAAA;AACnB;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU;AAAA,EACpB;AAGA,QAAM,wBAAwB,oBAAoB,MAAM,OAAO;AAC/D,MAAI,uBAAuB;AACzB,UAAM,kBAAkB,SAAS,sBAAsB,CAAC,CAAC;AACzD,QAAI,cAAc,MAAM;AAEtB,aAAO,cAAc,iBAAiB,cAAc;AAClD,2BAAmB,KAAK,IAAI;AAC5B,gBAAQ,KAAK,CAAC,GAAG,kBAAkB,CAAC;AAAA,MACtC;AAAA,IACF,OAAO;AAEL,cAAQ,KAAK,CAAC,eAAe,CAAC;AAAA,IAChC;AAAA,EACF;AAEA,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"optionValueDecoder.mjs","names":[],"sources":["../../src/optionValueDecoder.ts"],"sourcesContent":["/**\n * This file provides utility functions for determining whether or not an option value combination is present in an encoded option value string.\n *\n * In V1 of the encoding strategy, option value arrays are encoded as a trie with the following rules:\n * - `:` `,` ` ` and `-` are control characters.\n * - `:` indicates a new option. ex: 0:1 indicates value 0 for the option in position 1, value 1 for the option in position 2.\n * - `,` indicates the end of a repeated prefix, mulitple consecutive commas indicate the end of multiple repeated prefixes.\n * - ` ` indicates a gap in the sequence of option values. ex: `0 4` indicates option values in position 0 and 4 are present.\n * - `-` indicates a continuous range of option values. ex: `0 1-3 4`. Ranges are only present encoded in the final option value position, so for example the trie for the set [[0,0,0],[0,0,1], ..., [0,2,2]] will be structured as `0:0:0-2,1:0-2,2:0-2`, not `0:0-2:0-2`.\n */\n\nimport {Product} from './storefront-api-types.js';\n\nconst OPTION_VALUE_SEPARATOR = ',';\n\nconst V1_CONTROL_CHARS = {\n OPTION: ':',\n END_OF_PREFIX: ',',\n SEQUENCE_GAP: ' ',\n RANGE: '-',\n};\n\n/** @publicDocs */\nexport type IsOptionValueCombinationInEncodedVariant = (\n targetOptionValueCombination: number[],\n encodedVariantField: string,\n) => boolean;\n\n/**\n * Determine whether an option value combination is present in an encoded option value string. Function is memoized by encodedVariantField.\n *\n * @param targetOptionValueCombination - Indices of option values to look up in the encoded option value string. A partial set of indices may be passed to determine whether a node or any children is present. For example, if a product has 3 options, passing [0] will return true if any option value combination for the first option's option value is present in the encoded string.\n * @param encodedVariantField - Encoded option value string from the Storefront API, e.g. [product.encodedVariantExistence](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantexistence) or [product.encodedVariantAvailability](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantavailability)\n * @returns - True if a full or partial targetOptionValueIndices is present in the encoded option value string, false otherwise.\n * @publicDocs\n */\nexport const isOptionValueCombinationInEncodedVariant: IsOptionValueCombinationInEncodedVariant =\n ((): IsOptionValueCombinationInEncodedVariant => {\n const decodedOptionValues = new Map<string, Set<string>>();\n\n return function (\n targetOptionValueCombination: number[],\n encodedVariantField: string,\n ): boolean {\n if (targetOptionValueCombination.length === 0) {\n return false;\n }\n\n if (!decodedOptionValues.has(encodedVariantField)) {\n const decodedOptionValuesSet = new Set<string>();\n\n for (const optionValue of decodeEncodedVariant(encodedVariantField)) {\n // add the complete option value to the decoded option values set\n decodedOptionValuesSet.add(optionValue.join(OPTION_VALUE_SEPARATOR));\n\n // add all composite parts of the option value to the decoded option values set. e.g. if the option value is [0,1,2], add \"0\", \"0,1\", \"0,1,2\"\n for (let i = 0; i < optionValue.length; i++) {\n decodedOptionValuesSet.add(\n optionValue.slice(0, i + 1).join(OPTION_VALUE_SEPARATOR),\n );\n }\n }\n\n decodedOptionValues.set(encodedVariantField, decodedOptionValuesSet);\n }\n\n return Boolean(\n decodedOptionValues\n .get(encodedVariantField)\n ?.has(targetOptionValueCombination.join(OPTION_VALUE_SEPARATOR)),\n );\n };\n })();\n\ntype EncodedVariantField =\n | Product['encodedVariantAvailability']\n // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents\n | Product['encodedVariantExistence'];\ntype DecodedOptionValues = number[][];\n\n/**\n * For an encoded option value string, decode into option value combinations. Entries represent a valid combination formatted as an array of option value positions.\n * @param encodedVariantField - Encoded option value string from the Storefront API, e.g. [product.encodedVariantExistence](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantexistence) or [product.encodedVariantAvailability](/docs/api/storefront/2026-04/objects/Product#field-encodedvariantavailability)\n * @returns Decoded option value combinations\n * @publicDocs\n */\nexport function decodeEncodedVariant(\n encodedVariantField: EncodedVariantField,\n): DecodedOptionValues {\n if (!encodedVariantField) return [];\n\n if (encodedVariantField.startsWith('v1_')) {\n return v1Decoder(stripVersion(encodedVariantField));\n }\n\n throw new Error('Unsupported option value encoding');\n}\n\nconst stripVersion: (encodedVariantField: string) => string = (\n encodedVariantField: string,\n) => encodedVariantField.replace(/^v1_/, '');\n\n/**\n * We encode an array of arrays representing variants, expressed in terms of options and option values, as a trie.\n *\n * This encoding strategy allows extremely large numbers of variants to be expressed in an extremely compact data structure.\n *\n * Integers represent option and values, so [0,0,0] represents option_value at array index 0 for the options at array indexes 0, 1 and 2\n *\n * `:`, `,`, ` ` and `-` are control characters.\n * `:` indicates a new option\n * `,` indicates the end of a repeated prefix, mulitple consecutive commas indicate the end of multiple repeated prefixes.\n * ` ` indicates a gap in the sequence of option values\n * `-` indicates a continuous range of option values\n *\n * Encoding process:\n *\n * example input array: [[0,0,0], [0,1,0], [0,1,1], [1,0,0], [1,0,1], [1,1,1], [2,0,1], [2,1,0]]\n *\n * step 1: encode as string: \"0:0:0,0:1:0,0:1:1,1:0:0,1:0:1,1:1:1,2:0:1,2:1:0,\"\n * step 2: combine nodes that share a prefix: \"0:0:0,0:1:0 1,1:0:0 1,1:1:1,2:0:1,2:1:0,\"\n * step 3: encode data as a trie so no prefixes need to be repeated: \"0:0:0,1:0 1,,1:0:0 1,1:1,,2:0:1,1:0,,\"\n * step 4: since the options are sorted, use a dash to express ranges: \"0:0:0,1:0-1,,1:0:0-1,1:1,,2:0:1,1:0,,\"\n */\nfunction v1Decoder(encodedVariantField: string): number[][] {\n const tokenizer = /[ :,-]/g;\n let index = 0;\n let token: RegExpExecArray | null;\n const options: number[][] = [];\n const currentOptionValue: number[] = [];\n let depth = 0;\n let rangeStart: number | null = null;\n\n // iterate over control characters\n while ((token = tokenizer.exec(encodedVariantField))) {\n const operation = token[0];\n const optionValueIndex =\n Number.parseInt(encodedVariantField.slice(index, token.index)) || 0;\n\n if (rangeStart !== null) {\n // If a range has been started, iterate over the range and add each option value to the list of options\n // - `rangeStart` is set if the last control char was a dash, e.g. `0` for 0-2. It represents the numeric option value position for the start of the range.\n // - `optionValueIndex` is the numeric option value position for the end of the range\n for (; rangeStart < optionValueIndex; rangeStart++) {\n currentOptionValue[depth] = rangeStart;\n options.push([...currentOptionValue]);\n }\n // indicates the range has been processed\n rangeStart = null;\n }\n\n currentOptionValue[depth] = optionValueIndex;\n\n if (operation === V1_CONTROL_CHARS.RANGE) {\n // dash operation indicates we are in a range. e.g. 0-2 means option values 0, 1, 2\n rangeStart = optionValueIndex;\n } else if (operation === V1_CONTROL_CHARS.OPTION) {\n // colon operation indicates that we are moving down to the next layer of option values. e.g. 0:0:0-2 means we traverse down from option1 to option3 and represents [[0,0,0], [0,0,1], [0,0,2]]\n depth++;\n } else {\n if (\n operation === V1_CONTROL_CHARS.SEQUENCE_GAP ||\n (operation === V1_CONTROL_CHARS.END_OF_PREFIX &&\n encodedVariantField[token.index - 1] !==\n V1_CONTROL_CHARS.END_OF_PREFIX)\n ) {\n // add the current option value to the list of options if we hit a gap in our sequence or we are at the end of our depth and need to move back up\n options.push([...currentOptionValue]);\n }\n if (operation === V1_CONTROL_CHARS.END_OF_PREFIX) {\n // go up an option level, trash the last item in currentOptionValue\n currentOptionValue.pop();\n depth--;\n }\n }\n index = tokenizer.lastIndex;\n }\n\n // The while loop only iterates control characters, meaning if an encoded string ends with an index it will not be processed.\n const encodingEndsWithIndex = encodedVariantField.match(/\\d+$/g);\n if (encodingEndsWithIndex) {\n const finalValueIndex = parseInt(encodingEndsWithIndex[0]);\n if (rangeStart != null) {\n // process final range\n for (; rangeStart <= finalValueIndex; rangeStart++) {\n currentOptionValue[depth] = rangeStart;\n options.push([...currentOptionValue]);\n }\n } else {\n // process final index\n options.push([finalValueIndex]);\n }\n }\n\n return options;\n}\n"],"mappings":";AAaA,IAAM,yBAAyB;AAE/B,IAAM,mBAAmB;CACvB,QAAQ;CACR,eAAe;CACf,cAAc;CACd,OAAO;CACR;;;;;;;;;AAgBD,IAAa,kDACsC;CAC/C,MAAM,sCAAsB,IAAI,KAA0B;AAE1D,QAAO,SACL,8BACA,qBACS;AACT,MAAI,6BAA6B,WAAW,EAC1C,QAAO;AAGT,MAAI,CAAC,oBAAoB,IAAI,oBAAoB,EAAE;GACjD,MAAM,yCAAyB,IAAI,KAAa;AAEhD,QAAK,MAAM,eAAe,qBAAqB,oBAAoB,EAAE;AAEnE,2BAAuB,IAAI,YAAY,KAAK,uBAAuB,CAAC;AAGpE,SAAK,IAAI,IAAI,GAAG,IAAI,YAAY,QAAQ,IACtC,wBAAuB,IACrB,YAAY,MAAM,GAAG,IAAI,EAAE,CAAC,KAAK,uBAAuB,CACzD;;AAIL,uBAAoB,IAAI,qBAAqB,uBAAuB;;AAGtE,SAAO,QACL,oBACG,IAAI,oBAAoB,EACvB,IAAI,6BAA6B,KAAK,uBAAuB,CAAC,CACnE;;IAED;;;;;;;AAcN,SAAgB,qBACd,qBACqB;AACrB,KAAI,CAAC,oBAAqB,QAAO,EAAE;AAEnC,KAAI,oBAAoB,WAAW,MAAM,CACvC,QAAO,UAAU,aAAa,oBAAoB,CAAC;AAGrD,OAAM,IAAI,MAAM,oCAAoC;;AAGtD,IAAM,gBACJ,wBACG,oBAAoB,QAAQ,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;AAwB5C,SAAS,UAAU,qBAAyC;CAC1D,MAAM,YAAY;CAClB,IAAI,QAAQ;CACZ,IAAI;CACJ,MAAM,UAAsB,EAAE;CAC9B,MAAM,qBAA+B,EAAE;CACvC,IAAI,QAAQ;CACZ,IAAI,aAA4B;AAGhC,QAAQ,QAAQ,UAAU,KAAK,oBAAoB,EAAG;EACpD,MAAM,YAAY,MAAM;EACxB,MAAM,mBACJ,OAAO,SAAS,oBAAoB,MAAM,OAAO,MAAM,MAAM,CAAC,IAAI;AAEpE,MAAI,eAAe,MAAM;AAIvB,UAAO,aAAa,kBAAkB,cAAc;AAClD,uBAAmB,SAAS;AAC5B,YAAQ,KAAK,CAAC,GAAG,mBAAmB,CAAC;;AAGvC,gBAAa;;AAGf,qBAAmB,SAAS;AAE5B,MAAI,cAAc,iBAAiB,MAEjC,cAAa;WACJ,cAAc,iBAAiB,OAExC;OACK;AACL,OACE,cAAc,iBAAiB,gBAC9B,cAAc,iBAAiB,iBAC9B,oBAAoB,MAAM,QAAQ,OAChC,iBAAiB,cAGrB,SAAQ,KAAK,CAAC,GAAG,mBAAmB,CAAC;AAEvC,OAAI,cAAc,iBAAiB,eAAe;AAEhD,uBAAmB,KAAK;AACxB;;;AAGJ,UAAQ,UAAU;;CAIpB,MAAM,wBAAwB,oBAAoB,MAAM,QAAQ;AAChE,KAAI,uBAAuB;EACzB,MAAM,kBAAkB,SAAS,sBAAsB,GAAG;AAC1D,MAAI,cAAc,KAEhB,QAAO,cAAc,iBAAiB,cAAc;AAClD,sBAAmB,SAAS;AAC5B,WAAQ,KAAK,CAAC,GAAG,mBAAmB,CAAC;;MAIvC,SAAQ,KAAK,CAAC,gBAAgB,CAAC;;AAInC,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.mjs","names":[],"sources":["../../../../package.json"],"sourcesContent":["{\n \"name\": \"@shopify/hydrogen-react\",\n \"version\": \"2026.4.2\",\n \"description\": \"React components, hooks, and utilities for creating custom Shopify storefronts\",\n \"homepage\": \"https://github.com/Shopify/hydrogen/tree/main/packages/hydrogen-react\",\n \"license\": \"MIT\",\n \"publishConfig\": {\n \"access\": \"public\",\n \"@shopify:registry\": \"https://registry.npmjs.org\"\n },\n \"files\": [\n \"dist\",\n \"storefront.schema.json\",\n \"customer-account.schema.json\"\n ],\n \"type\": \"commonjs\",\n \"exports\": {\n \".\": {\n \"node\": {\n \"require\": {\n \"types\": \"./dist/types/index.d.cts\",\n \"development\": \"./dist/node-dev/index.js\",\n \"default\": \"./dist/node-prod/index.js\"\n },\n \"import\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"development\": \"./dist/node-dev/index.mjs\",\n \"default\": \"./dist/node-prod/index.mjs\"\n },\n \"default\": \"./dist/node-prod/index.js\"\n },\n \"module\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"development\": \"./dist/browser-dev/index.mjs\",\n \"default\": \"./dist/browser-prod/index.mjs\"\n },\n \"import\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"development\": \"./dist/browser-dev/index.mjs\",\n \"default\": \"./dist/browser-prod/index.mjs\"\n },\n \"require\": {\n \"types\": \"./dist/types/index.d.cts\",\n \"development\": \"./dist/node-dev/index.js\",\n \"default\": \"./dist/node-prod/index.js\"\n },\n \"default\": \"./dist/browser-prod/index.mjs\"\n },\n \"./storefront-api-types\": \"./dist/types/storefront-api-types.d.ts\",\n \"./storefront.schema.json\": \"./storefront.schema.json\",\n \"./customer-account.schema.json\": \"./customer-account.schema.json\",\n \"./customer-account-api-types\": \"./dist/types/customer-account-api-types.d.ts\",\n \"./package.json\": \"./package.json\",\n \"./*\": {\n \"node\": {\n \"require\": {\n \"types\": \"./dist/types/*.d.cts\",\n \"development\": \"./dist/node-dev/*.js\",\n \"default\": \"./dist/node-prod/*.js\"\n },\n \"import\": {\n \"types\": \"./dist/types/*.d.ts\",\n \"development\": \"./dist/node-dev/*.mjs\",\n \"default\": \"./dist/node-prod/*.mjs\"\n },\n \"default\": \"./dist/node-prod/*.js\"\n },\n \"module\": {\n \"types\": \"./dist/types/*.d.ts\",\n \"development\": \"./dist/browser-dev/*.mjs\",\n \"default\": \"./dist/browser-prod/*.mjs\"\n },\n \"import\": {\n \"types\": \"./dist/types/*.d.ts\",\n \"development\": \"./dist/browser-dev/*.mjs\",\n \"default\": \"./dist/browser-prod/*.mjs\"\n },\n \"require\": {\n \"types\": \"./dist/types/*.d.cts\",\n \"development\": \"./dist/node-dev/*.js\",\n \"default\": \"./dist/node-prod/*.js\"\n },\n \"default\": \"./dist/browser-prod/*.mjs\"\n }\n },\n \"typesVersions\": {\n \"*\": {\n \"storefront-api-types\": [\n \"./dist/types/storefront-api-types.d.ts\"\n ]\n }\n },\n \"main\": \"./dist/node-prod/index.js\",\n \"module\": \"./dist/node-prod/index.mjs\",\n \"browser\": \"./dist/browser-prod/index.mjs\",\n \"types\": \"./dist/types/index.d.ts\",\n \"unpkg\": \"./dist/umd/hydrogen-react.prod.js\",\n \"jsdelivr\": \"./dist/umd/hydrogen-react.prod.js\",\n \"sideEffects\": false,\n \"scripts\": {\n \"build-docs\": \"sh ./docs/build-docs.sh && pnpm run format\",\n \"clean-dist\": \"rimraf ./dist\",\n \"dev\": \"run-s dev:demo\",\n \"dev:story\": \"ladle serve\",\n \"dev:demo\": \"run-p dev:demo:* copy-api-types\",\n \"dev:demo:browser-dev\": \"vite build --watch --emptyOutDir false --clearScreen false --mode devbuild\",\n \"dev:demo:ts\": \"tsc --watch --emitDeclarationOnly\",\n \"build\": \"npm-run-all --sequential clean-dist --parallel build:vite:* build:tsc:es --parallel build:tsc:cjs copy-api-types\",\n \"build:vite:browser-dev\": \"vite build --mode devbuild\",\n \"build:vite:browser-prod\": \"vite build\",\n \"build:vite:node-dev\": \"vite build --mode devbuild --ssr\",\n \"build:vite:node-prod\": \"vite build --ssr\",\n \"build:vite:umddev\": \"vite build --mode umdbuilddev\",\n \"build:vite:umdprod\": \"vite build --mode umdbuild\",\n \"build:tsc:cjs\": \"cpy ./dist/types/index.d.ts ./dist/types/ --rename=index.d.cts --flat\",\n \"build:tsc:es\": \"tsc --emitDeclarationOnly --project tsconfig.typeoutput.json\",\n \"copy-api-types\": \"cpy ./src/storefront-api-types.d.ts ./src/customer-account-api-types.d.ts ./dist/types/ --flat\",\n \"format\": \"prettier --write \\\"{src,docs}/**/*\\\" --ignore-unknown\",\n \"graphql-types\": \"graphql-codegen --config codegen.ts && pnpm run format\",\n \"test\": \"vitest run --coverage\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"run-p typecheck:*\",\n \"typecheck:code\": \"tsc --noEmit\",\n \"typecheck:examples\": \"tsc --noEmit --project tsconfig.examples.json\",\n \"preview-docs\": \"pnpm --dir ../../docs/preview run dev\"\n },\n \"devDependencies\": {\n \"@faker-js/faker\": \"^9.4.0\",\n \"@graphql-codegen/add\": \"^5.0.3\",\n \"@graphql-codegen/cli\": \"^5.0.4\",\n \"@graphql-codegen/introspection\": \"^4.0.3\",\n \"@graphql-codegen/typescript\": \"^4.1.3\",\n \"@ladle/react\": \"^5.0.1\",\n \"@shopify/generate-docs\": \"catalog:\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@testing-library/user-event\": \"^14.6.1\",\n \"@types/react\": \"catalog:\",\n \"@types/react-dom\": \"catalog:\",\n \"@vitejs/plugin-react\": \"^6.0.1\",\n \"@vitest/coverage-v8\": \"^3.2.4\",\n \"cpy-cli\": \"^5.0.0\",\n \"eslint\": \"9.19.0\",\n \"eslint-config-prettier\": \"10.0.1\",\n \"eslint-import-resolver-typescript\": \"3.7.0\",\n \"eslint-plugin-eslint-comments\": \"3.2.0\",\n \"eslint-plugin-import\": \"2.31.0\",\n \"eslint-plugin-jest\": \"28.11.0\",\n \"eslint-plugin-jsx-a11y\": \"6.10.2\",\n \"eslint-plugin-node\": \"11.1.0\",\n \"eslint-plugin-prettier\": \"4.2.1\",\n \"eslint-plugin-react\": \"7.37.4\",\n \"eslint-plugin-react-hooks\": \"5.1.0\",\n \"eslint-plugin-simple-import-sort\": \"12.1.1\",\n \"eslint-plugin-tsdoc\": \"0.2.14\",\n \"happy-dom\": \"^20.8.9\",\n \"npm-run-all\": \"^4.1.5\",\n \"react\": \"catalog:\",\n \"react-dom\": \"catalog:\",\n \"rimraf\": \"^6.0.1\",\n \"ts-expect\": \"^1.3.0\",\n \"typescript\": \"5.9.2\",\n \"vite\": \"^8.0.1\",\n \"vitest\": \"^3.2.4\"\n },\n \"peerDependencies\": {\n \"react\": \"^18.3.1 || ~19.0.3 || ~19.1.4 || ^19.2.3\",\n \"react-dom\": \"^18.3.1 || ~19.0.3 || ~19.1.4 || ^19.2.3\",\n \"vite\": \"^5.1.0 || ^6.2.1 || ^7.0.0 || ^8.0.0\"\n },\n \"dependencies\": {\n \"@google/model-viewer\": \"^4.0.0\",\n \"@xstate/fsm\": \"2.0.0\",\n \"ast-v8-to-istanbul\": \"^0.3.11\",\n \"graphql\": \"^16.10.0\",\n \"type-fest\": \"^4.33.0\",\n \"worktop\": \"^0.7.3\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/Shopify/hydrogen.git\",\n \"directory\": \"packages/hydrogen-react\"\n },\n \"bugs\": \"https://github.com/shopify/hydrogen/issues\"\n}\n"],"mappings":""}
|
|
@@ -1,151 +1,139 @@
|
|
|
1
1
|
import { flattenConnection } from "./flatten-connection.mjs";
|
|
2
|
+
//#region src/parse-metafield.ts
|
|
3
|
+
/**
|
|
4
|
+
* A function that uses `metafield.type` to parse the Metafield's `value` or `reference` or `references` (depending on the `metafield.type`) and places the result in `metafield.parsedValue`
|
|
5
|
+
*
|
|
6
|
+
* TypeScript developers can use the type `ParsedMetafields` from this package to get the returned object's type correct. For example:
|
|
7
|
+
*
|
|
8
|
+
* ```
|
|
9
|
+
* parseMetafield<ParsedMetafields['boolean']>({type: 'boolean', value: 'false'}
|
|
10
|
+
* ```
|
|
11
|
+
* @publicDocs
|
|
12
|
+
*/
|
|
2
13
|
function parseMetafield(metafield) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
case "list.article_reference":
|
|
116
|
-
case "list.collection_reference":
|
|
117
|
-
case "list.file_reference":
|
|
118
|
-
case "list.page_reference":
|
|
119
|
-
case "list.product_reference":
|
|
120
|
-
case "list.variant_reference":
|
|
121
|
-
return {
|
|
122
|
-
...metafield,
|
|
123
|
-
parsedValue: flattenConnection(metafield.references ?? void 0)
|
|
124
|
-
};
|
|
125
|
-
default: {
|
|
126
|
-
const typeNotFoundError = `parseMetafield(): the 'metafield.type' you passed in is not supported. Your type: "${metafield.type}". If you believe this is an error, please open an issue on GitHub.`;
|
|
127
|
-
{
|
|
128
|
-
console.error(
|
|
129
|
-
`${typeNotFoundError} Returning 'parsedValue' of 'null'`
|
|
130
|
-
);
|
|
131
|
-
return {
|
|
132
|
-
...metafield,
|
|
133
|
-
parsedValue: null
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
14
|
+
if (!metafield.type) {
|
|
15
|
+
console.error(`parseMetafield(): The 'type' field is required in order to parse the Metafield. Returning 'parsedValue' of 'null'`);
|
|
16
|
+
return {
|
|
17
|
+
...metafield,
|
|
18
|
+
parsedValue: null
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
switch (metafield.type) {
|
|
22
|
+
case "boolean": return {
|
|
23
|
+
...metafield,
|
|
24
|
+
parsedValue: metafield.value === "true"
|
|
25
|
+
};
|
|
26
|
+
case "article_reference":
|
|
27
|
+
case "collection_reference":
|
|
28
|
+
case "file_reference":
|
|
29
|
+
case "page_reference":
|
|
30
|
+
case "product_reference":
|
|
31
|
+
case "variant_reference": return {
|
|
32
|
+
...metafield,
|
|
33
|
+
parsedValue: metafield.reference
|
|
34
|
+
};
|
|
35
|
+
case "color":
|
|
36
|
+
case "multi_line_text_field":
|
|
37
|
+
case "single_line_text_field":
|
|
38
|
+
case "url": return {
|
|
39
|
+
...metafield,
|
|
40
|
+
parsedValue: metafield.value
|
|
41
|
+
};
|
|
42
|
+
case "money": {
|
|
43
|
+
let parsedValue = null;
|
|
44
|
+
try {
|
|
45
|
+
const parsed = parseJSON(metafield.value ?? "");
|
|
46
|
+
if (parsed && typeof parsed === "object" && "currency_code" in parsed) {
|
|
47
|
+
const moneyData = parsed;
|
|
48
|
+
parsedValue = {
|
|
49
|
+
amount: moneyData.amount,
|
|
50
|
+
currencyCode: moneyData.currency_code
|
|
51
|
+
};
|
|
52
|
+
} else if (parsed && typeof parsed === "object" && "currencyCode" in parsed) parsedValue = parsed;
|
|
53
|
+
else parsedValue = parsed;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error(`parseMetafield(): attempted to JSON.parse the 'metafield.value' property, but failed. Returning 'null' for 'parsedValue'`);
|
|
56
|
+
parsedValue = null;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...metafield,
|
|
60
|
+
parsedValue
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
case "dimension":
|
|
64
|
+
case "json":
|
|
65
|
+
case "rating":
|
|
66
|
+
case "volume":
|
|
67
|
+
case "weight":
|
|
68
|
+
case "rich_text_field":
|
|
69
|
+
case "list.color":
|
|
70
|
+
case "list.dimension":
|
|
71
|
+
case "list.number_integer":
|
|
72
|
+
case "list.number_decimal":
|
|
73
|
+
case "list.rating":
|
|
74
|
+
case "list.single_line_text_field":
|
|
75
|
+
case "list.url":
|
|
76
|
+
case "list.volume":
|
|
77
|
+
case "list.weight": {
|
|
78
|
+
let parsedValue = null;
|
|
79
|
+
try {
|
|
80
|
+
parsedValue = parseJSON(metafield.value ?? "");
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(`parseMetafield(): attempted to JSON.parse the 'metafield.value' property, but failed. Returning 'null' for 'parsedValue'`);
|
|
83
|
+
parsedValue = null;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
...metafield,
|
|
87
|
+
parsedValue
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
case "date":
|
|
91
|
+
case "date_time": return {
|
|
92
|
+
...metafield,
|
|
93
|
+
parsedValue: new Date(metafield.value ?? "")
|
|
94
|
+
};
|
|
95
|
+
case "list.date":
|
|
96
|
+
case "list.date_time": {
|
|
97
|
+
const jsonParseValue = parseJSON(metafield?.value ?? "");
|
|
98
|
+
return {
|
|
99
|
+
...metafield,
|
|
100
|
+
parsedValue: jsonParseValue.map((dateString) => new Date(dateString))
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
case "number_decimal":
|
|
104
|
+
case "number_integer": return {
|
|
105
|
+
...metafield,
|
|
106
|
+
parsedValue: Number(metafield.value)
|
|
107
|
+
};
|
|
108
|
+
case "list.article_reference":
|
|
109
|
+
case "list.collection_reference":
|
|
110
|
+
case "list.file_reference":
|
|
111
|
+
case "list.page_reference":
|
|
112
|
+
case "list.product_reference":
|
|
113
|
+
case "list.variant_reference": return {
|
|
114
|
+
...metafield,
|
|
115
|
+
parsedValue: flattenConnection(metafield.references ?? void 0)
|
|
116
|
+
};
|
|
117
|
+
default: {
|
|
118
|
+
const typeNotFoundError = `parseMetafield(): the 'metafield.type' you passed in is not supported. Your type: "${metafield.type}". If you believe this is an error, please open an issue on GitHub.`;
|
|
119
|
+
console.error(`${typeNotFoundError} Returning 'parsedValue' of 'null'`);
|
|
120
|
+
return {
|
|
121
|
+
...metafield,
|
|
122
|
+
parsedValue: null
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
138
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Parses a JSON string while preventing prototype injection attacks.
|
|
129
|
+
*/
|
|
139
130
|
function parseJSON(json) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
return JSON.parse(json);
|
|
131
|
+
if (String(json).includes("__proto__")) return JSON.parse(json, (k, v) => {
|
|
132
|
+
if (k !== "__proto__") return v;
|
|
133
|
+
});
|
|
134
|
+
return JSON.parse(json);
|
|
146
135
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
//# sourceMappingURL=parse-metafield.mjs.map
|
|
136
|
+
//#endregion
|
|
137
|
+
export { parseMetafield };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=parse-metafield.mjs.map
|