@shopify/hydrogen 2026.10.0-preview.4 → 2026.10.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/dist/cli/index.mjs +23 -12
- package/dist/client/client.d.mts +18 -15
- package/dist/client/client.mjs +8 -3
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/errors.d.mts +35 -13
- package/dist/client/errors.mjs +23 -13
- package/dist/client/errors.mjs.map +1 -1
- package/dist/client/types.d.mts +140 -90
- package/dist/core/analytics/cart-tracker.d.mts +19 -10
- package/dist/core/analytics/cart-tracker.mjs +18 -10
- package/dist/core/analytics/cart-tracker.mjs.map +1 -1
- package/dist/core/analytics/events.d.mts +17 -11
- package/dist/core/analytics/events.mjs +13 -4
- package/dist/core/analytics/events.mjs.map +1 -1
- package/dist/core/analytics/types.d.mts +207 -118
- package/dist/core/analytics/utils/flatten-connection.d.mts +11 -9
- package/dist/core/analytics/utils/flatten-connection.mjs +7 -6
- package/dist/core/analytics/utils/flatten-connection.mjs.map +1 -1
- package/dist/core/cache/fetch-with-cache.d.mts +24 -4
- package/dist/core/cache/fetch-with-cache.mjs +17 -2
- package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/core/cache/key.d.mts +2 -0
- package/dist/core/cache/key.mjs.map +1 -1
- package/dist/core/cache/run-with-cache.d.mts +56 -8
- package/dist/core/cache/run-with-cache.mjs +17 -6
- package/dist/core/cache/run-with-cache.mjs.map +1 -1
- package/dist/core/cache/store.d.mts +8 -6
- package/dist/core/cache/store.mjs.map +1 -1
- package/dist/core/cache/strategies.d.mts +27 -2
- package/dist/core/cache/strategies.mjs +6 -0
- package/dist/core/cache/strategies.mjs.map +1 -1
- package/dist/core/cart/actions.d.mts +37 -30
- package/dist/core/cart/actions.mjs +21 -9
- package/dist/core/cart/actions.mjs.map +1 -1
- package/dist/core/cart/attach-quantity-input.d.mts +8 -7
- package/dist/core/cart/attach-quantity-input.mjs +8 -7
- package/dist/core/cart/attach-quantity-input.mjs.map +1 -1
- package/dist/core/cart/buyer-identity-sync.d.mts +7 -6
- package/dist/core/cart/buyer-identity-sync.mjs.map +1 -1
- package/dist/core/cart/cart.d.mts +59 -46
- package/dist/core/cart/cart.mjs +46 -29
- package/dist/core/cart/cart.mjs.map +1 -1
- package/dist/core/cart/cookie.d.mts +8 -4
- package/dist/core/cart/cookie.mjs +8 -4
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +34 -20
- package/dist/core/cart/form.mjs +6 -4
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/get-cart.d.mts +27 -15
- package/dist/core/cart/get-cart.mjs +13 -8
- package/dist/core/cart/get-cart.mjs.map +1 -1
- package/dist/core/cart/quantity.d.mts +16 -5
- package/dist/core/cart/quantity.mjs +16 -5
- package/dist/core/cart/quantity.mjs.map +1 -1
- package/dist/core/cart/queries.d.mts +25 -19
- package/dist/core/cart/queries.mjs +15 -1
- package/dist/core/cart/queries.mjs.map +1 -1
- package/dist/core/cart/server-handlers.d.mts +82 -45
- package/dist/core/cart/server-handlers.mjs +4 -0
- package/dist/core/cart/server-handlers.mjs.map +1 -1
- package/dist/core/cart/state.d.mts +110 -64
- package/dist/core/cart/state.mjs +24 -6
- package/dist/core/cart/state.mjs.map +1 -1
- package/dist/core/collection/collection.d.mts +52 -53
- package/dist/core/collection/collection.mjs +5 -3
- package/dist/core/collection/collection.mjs.map +1 -1
- package/dist/core/collection/reconciler.d.mts +23 -16
- package/dist/core/collection/reconciler.mjs +8 -4
- package/dist/core/collection/reconciler.mjs.map +1 -1
- package/dist/core/collection/state.d.mts +31 -26
- package/dist/core/collection/state.mjs +4 -3
- package/dist/core/collection/state.mjs.map +1 -1
- package/dist/core/collection/url.d.mts +70 -29
- package/dist/core/collection/url.mjs +63 -25
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.d.mts +1 -0
- package/dist/core/constants.mjs +1 -0
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/logging/logging.d.mts +14 -8
- package/dist/core/logging/logging.mjs +15 -10
- package/dist/core/logging/logging.mjs.map +1 -1
- package/dist/core/logging/types.d.mts +28 -11
- package/dist/core/logging/types.mjs.map +1 -1
- package/dist/core/money/format.d.mts +6 -4
- package/dist/core/money/format.mjs +19 -9
- package/dist/core/money/format.mjs.map +1 -1
- package/dist/core/money/types.d.mts +41 -25
- package/dist/core/predictive-search/form.d.mts +37 -7
- package/dist/core/predictive-search/form.mjs +21 -3
- package/dist/core/predictive-search/form.mjs.map +1 -1
- package/dist/core/predictive-search/queries.d.mts +18 -30
- package/dist/core/predictive-search/queries.mjs +7 -3
- package/dist/core/predictive-search/queries.mjs.map +1 -1
- package/dist/core/predictive-search/search.d.mts +25 -27
- package/dist/core/predictive-search/search.mjs +20 -19
- package/dist/core/predictive-search/search.mjs.map +1 -1
- package/dist/core/predictive-search/server-handlers.d.mts +25 -26
- package/dist/core/predictive-search/server-handlers.mjs +4 -0
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/store.d.mts +65 -24
- package/dist/core/predictive-search/store.mjs +12 -1
- package/dist/core/predictive-search/store.mjs.map +1 -1
- package/dist/core/predictive-search/url.d.mts +36 -37
- package/dist/core/predictive-search/url.mjs +14 -6
- package/dist/core/predictive-search/url.mjs.map +1 -1
- package/dist/core/product/form.d.mts +63 -16
- package/dist/core/product/form.mjs +8 -2
- package/dist/core/product/form.mjs.map +1 -1
- package/dist/core/product/options.d.mts +8 -10
- package/dist/core/product/options.mjs +8 -10
- package/dist/core/product/options.mjs.map +1 -1
- package/dist/core/product/product-form.d.mts +77 -29
- package/dist/core/product/product-form.mjs +32 -10
- package/dist/core/product/product-form.mjs.map +1 -1
- package/dist/core/product/state.d.mts +55 -32
- package/dist/core/product/url.d.mts +19 -13
- package/dist/core/product/url.mjs +10 -10
- package/dist/core/product/url.mjs.map +1 -1
- package/dist/core/request-context.d.mts +77 -19
- package/dist/core/request-context.mjs +5 -1
- package/dist/core/request-context.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-redirects.d.mts +12 -4
- package/dist/core/request-routing/handle-shopify-redirects.mjs +9 -2
- package/dist/core/request-routing/handle-shopify-redirects.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-routes.d.mts +5 -5
- package/dist/core/request-routing/handle-shopify-routes.mjs +7 -5
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/proxy.mjs +79 -43
- package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/ucp-profile-proxy.mjs +69 -0
- package/dist/core/request-routing/interceptors/ucp-profile-proxy.mjs.map +1 -0
- package/dist/core/request-routing/interceptors/url-redirects.mjs +6 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/well-known.mjs +1 -1
- package/dist/core/request-routing/interceptors/well-known.mjs.map +1 -1
- package/dist/core/request-routing/registered-routes.d.mts +12 -0
- package/dist/core/request-routing/registered-routes.mjs +12 -0
- package/dist/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/core/request-routing/route-types.d.mts +43 -18
- package/dist/core/shop-pay/shop-pay.d.mts +71 -35
- package/dist/core/shop-pay/shop-pay.mjs +36 -10
- package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/core/shopify-scripts/index.d.mts +15 -5
- package/dist/core/shopify-scripts/index.mjs +15 -5
- package/dist/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/core/shopify-scripts/initialize.d.mts +12 -4
- package/dist/core/shopify-scripts/initialize.mjs +12 -4
- package/dist/core/shopify-scripts/initialize.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +58 -25
- package/dist/core/standard-routes/build.d.mts +11 -12
- package/dist/core/standard-routes/build.mjs +11 -12
- package/dist/core/standard-routes/build.mjs.map +1 -1
- package/dist/core/standard-routes/types.d.mts +30 -24
- package/dist/core/url.mjs +2 -1
- package/dist/core/url.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +36 -69
- package/dist/customer-account/client.mjs +7 -8
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/errors.d.mts +45 -36
- package/dist/customer-account/errors.mjs +21 -36
- package/dist/customer-account/errors.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +11 -23
- package/dist/customer-account/graphql.mjs +3 -9
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.d.mts +130 -100
- package/dist/customer-account/session.mjs +32 -10
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/customer-account/type-resolver.d.mts +7 -8
- package/dist/development/client/client.d.mts +18 -15
- package/dist/development/client/client.mjs +8 -3
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/errors.d.mts +35 -13
- package/dist/development/client/errors.mjs +23 -13
- package/dist/development/client/errors.mjs.map +1 -1
- package/dist/development/client/types.d.mts +140 -90
- package/dist/development/core/analytics/cart-tracker.d.mts +19 -10
- package/dist/development/core/analytics/cart-tracker.mjs +18 -10
- package/dist/development/core/analytics/cart-tracker.mjs.map +1 -1
- package/dist/development/core/analytics/events.d.mts +17 -11
- package/dist/development/core/analytics/events.mjs +13 -4
- package/dist/development/core/analytics/events.mjs.map +1 -1
- package/dist/development/core/analytics/types.d.mts +207 -118
- package/dist/development/core/analytics/utils/flatten-connection.d.mts +11 -9
- package/dist/development/core/analytics/utils/flatten-connection.mjs +7 -6
- package/dist/development/core/analytics/utils/flatten-connection.mjs.map +1 -1
- package/dist/development/core/cache/fetch-with-cache.d.mts +24 -4
- package/dist/development/core/cache/fetch-with-cache.mjs +17 -2
- package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/development/core/cache/key.d.mts +2 -0
- package/dist/development/core/cache/key.mjs.map +1 -1
- package/dist/development/core/cache/run-with-cache.d.mts +56 -8
- package/dist/development/core/cache/run-with-cache.mjs +17 -6
- package/dist/development/core/cache/run-with-cache.mjs.map +1 -1
- package/dist/development/core/cache/store.d.mts +8 -6
- package/dist/development/core/cache/store.mjs.map +1 -1
- package/dist/development/core/cache/strategies.d.mts +27 -2
- package/dist/development/core/cache/strategies.mjs +6 -0
- package/dist/development/core/cache/strategies.mjs.map +1 -1
- package/dist/development/core/cart/actions.d.mts +37 -30
- package/dist/development/core/cart/actions.mjs +21 -9
- package/dist/development/core/cart/actions.mjs.map +1 -1
- package/dist/development/core/cart/attach-quantity-input.d.mts +8 -7
- package/dist/development/core/cart/attach-quantity-input.mjs +8 -7
- package/dist/development/core/cart/attach-quantity-input.mjs.map +1 -1
- package/dist/development/core/cart/buyer-identity-sync.d.mts +6 -5
- package/dist/development/core/cart/buyer-identity-sync.mjs.map +1 -1
- package/dist/development/core/cart/cart.d.mts +59 -46
- package/dist/development/core/cart/cart.mjs +46 -29
- package/dist/development/core/cart/cart.mjs.map +1 -1
- package/dist/development/core/cart/cookie.d.mts +8 -4
- package/dist/development/core/cart/cookie.mjs +8 -4
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +34 -20
- package/dist/development/core/cart/form.mjs +6 -4
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/get-cart.d.mts +27 -15
- package/dist/development/core/cart/get-cart.mjs +13 -8
- package/dist/development/core/cart/get-cart.mjs.map +1 -1
- package/dist/development/core/cart/quantity.d.mts +16 -5
- package/dist/development/core/cart/quantity.mjs +16 -5
- package/dist/development/core/cart/quantity.mjs.map +1 -1
- package/dist/development/core/cart/queries.d.mts +25 -19
- package/dist/development/core/cart/queries.mjs +15 -1
- package/dist/development/core/cart/queries.mjs.map +1 -1
- package/dist/development/core/cart/server-handlers.d.mts +82 -45
- package/dist/development/core/cart/server-handlers.mjs +4 -0
- package/dist/development/core/cart/server-handlers.mjs.map +1 -1
- package/dist/development/core/cart/state.d.mts +110 -64
- package/dist/development/core/cart/state.mjs +24 -6
- package/dist/development/core/cart/state.mjs.map +1 -1
- package/dist/development/core/collection/collection.d.mts +52 -53
- package/dist/development/core/collection/collection.mjs +5 -3
- package/dist/development/core/collection/collection.mjs.map +1 -1
- package/dist/development/core/collection/reconciler.d.mts +23 -16
- package/dist/development/core/collection/reconciler.mjs +8 -4
- package/dist/development/core/collection/reconciler.mjs.map +1 -1
- package/dist/development/core/collection/state.d.mts +31 -26
- package/dist/development/core/collection/state.mjs +4 -3
- package/dist/development/core/collection/state.mjs.map +1 -1
- package/dist/development/core/collection/url.d.mts +70 -29
- package/dist/development/core/collection/url.mjs +63 -25
- package/dist/development/core/collection/url.mjs.map +1 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/logging/logging.d.mts +14 -8
- package/dist/development/core/logging/logging.mjs +15 -10
- package/dist/development/core/logging/logging.mjs.map +1 -1
- package/dist/development/core/logging/types.d.mts +28 -11
- package/dist/development/core/logging/types.mjs.map +1 -1
- package/dist/development/core/money/format.d.mts +6 -4
- package/dist/development/core/money/format.mjs +19 -9
- package/dist/development/core/money/format.mjs.map +1 -1
- package/dist/development/core/money/types.d.mts +41 -25
- package/dist/development/core/predictive-search/form.d.mts +37 -7
- package/dist/development/core/predictive-search/form.mjs +21 -3
- package/dist/development/core/predictive-search/form.mjs.map +1 -1
- package/dist/development/core/predictive-search/queries.d.mts +18 -30
- package/dist/development/core/predictive-search/queries.mjs +7 -3
- package/dist/development/core/predictive-search/queries.mjs.map +1 -1
- package/dist/development/core/predictive-search/search.d.mts +25 -27
- package/dist/development/core/predictive-search/search.mjs +20 -19
- package/dist/development/core/predictive-search/search.mjs.map +1 -1
- package/dist/development/core/predictive-search/server-handlers.d.mts +25 -26
- package/dist/development/core/predictive-search/server-handlers.mjs +4 -0
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/store.d.mts +65 -24
- package/dist/development/core/predictive-search/store.mjs +12 -1
- package/dist/development/core/predictive-search/store.mjs.map +1 -1
- package/dist/development/core/predictive-search/url.d.mts +36 -37
- package/dist/development/core/predictive-search/url.mjs +14 -6
- package/dist/development/core/predictive-search/url.mjs.map +1 -1
- package/dist/development/core/product/form.d.mts +63 -16
- package/dist/development/core/product/form.mjs +8 -2
- package/dist/development/core/product/form.mjs.map +1 -1
- package/dist/development/core/product/options.d.mts +8 -10
- package/dist/development/core/product/options.mjs +8 -10
- package/dist/development/core/product/options.mjs.map +1 -1
- package/dist/development/core/product/product-form.d.mts +77 -29
- package/dist/development/core/product/product-form.mjs +32 -10
- package/dist/development/core/product/product-form.mjs.map +1 -1
- package/dist/development/core/product/state.d.mts +55 -32
- package/dist/development/core/product/url.d.mts +19 -13
- package/dist/development/core/product/url.mjs +10 -10
- package/dist/development/core/product/url.mjs.map +1 -1
- package/dist/development/core/request-context.d.mts +77 -19
- package/dist/development/core/request-context.mjs +5 -1
- package/dist/development/core/request-context.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-redirects.d.mts +12 -4
- package/dist/development/core/request-routing/handle-shopify-redirects.mjs +9 -2
- package/dist/development/core/request-routing/handle-shopify-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.development.d.mts +9 -1
- package/dist/development/core/request-routing/handle-shopify-routes.development.mjs +7 -0
- package/dist/development/core/request-routing/handle-shopify-routes.development.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.mjs +7 -5
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/proxy.mjs +79 -43
- package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/ucp-profile-proxy.mjs +69 -0
- package/dist/development/core/request-routing/interceptors/ucp-profile-proxy.mjs.map +1 -0
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs +6 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/well-known.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/well-known.mjs.map +1 -1
- package/dist/development/core/request-routing/registered-routes.d.mts +12 -0
- package/dist/development/core/request-routing/registered-routes.mjs +12 -0
- package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/route-types.d.mts +43 -18
- package/dist/development/core/shop-pay/shop-pay.d.mts +71 -35
- package/dist/development/core/shop-pay/shop-pay.mjs +36 -10
- package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/index.d.mts +15 -5
- package/dist/development/core/shopify-scripts/index.mjs +15 -5
- package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/initialize.d.mts +12 -4
- package/dist/development/core/shopify-scripts/initialize.mjs +12 -4
- package/dist/development/core/shopify-scripts/initialize.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +58 -25
- package/dist/development/core/standard-routes/build.d.mts +11 -12
- package/dist/development/core/standard-routes/build.mjs +11 -12
- package/dist/development/core/standard-routes/build.mjs.map +1 -1
- package/dist/development/core/standard-routes/types.d.mts +30 -24
- package/dist/development/core/url.mjs +2 -1
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/customer-account/session.d.mts +45 -54
- package/dist/development/customer-account/session.mjs +20 -4
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +20 -11
- package/dist/development/graphql/generated/storefront-api-types.d.mts +127 -1
- package/dist/development/graphql/graphql.d.mts +17 -16
- package/dist/development/graphql/graphql.mjs +7 -8
- package/dist/development/graphql/graphql.mjs.map +1 -1
- package/dist/development/graphql/type-resolver.d.mts +15 -8
- package/dist/development/react/cart.d.mts +78 -32
- package/dist/development/react/cart.mjs +56 -29
- package/dist/development/react/cart.mjs.map +1 -1
- package/dist/development/react/collection.d.mts +40 -22
- package/dist/development/react/collection.mjs +27 -7
- package/dist/development/react/collection.mjs.map +1 -1
- package/dist/development/react/predictive-search.d.mts +65 -50
- package/dist/development/react/predictive-search.mjs +23 -21
- package/dist/development/react/predictive-search.mjs.map +1 -1
- package/dist/development/react/product.d.mts +45 -16
- package/dist/development/react/product.mjs +13 -11
- package/dist/development/react/product.mjs.map +1 -1
- package/dist/development/react/shop-pay.d.mts +15 -0
- package/dist/development/react/shop-pay.mjs +9 -0
- package/dist/development/react/shop-pay.mjs.map +1 -1
- package/dist/development/react/shopify-scripts.d.mts +23 -2
- package/dist/development/react/shopify-scripts.mjs +9 -0
- package/dist/development/react/shopify-scripts.mjs.map +1 -1
- package/dist/development/vue/cart.d.mts +28 -23
- package/dist/development/vue/cart.mjs +42 -25
- package/dist/development/vue/cart.mjs.map +1 -1
- package/dist/development/vue/collection.d.mts +20 -12
- package/dist/development/vue/collection.mjs +15 -7
- package/dist/development/vue/collection.mjs.map +1 -1
- package/dist/development/vue/index.d.mts +2 -2
- package/dist/development/vue/index.mjs +2 -2
- package/dist/development/vue/predictive-search.d.mts +31 -36
- package/dist/development/vue/predictive-search.mjs +16 -22
- package/dist/development/vue/predictive-search.mjs.map +1 -1
- package/dist/development/vue/product.d.mts +16 -15
- package/dist/development/vue/product.mjs +11 -11
- package/dist/development/vue/product.mjs.map +1 -1
- package/dist/development/vue/shop-pay.d.mts +14 -17
- package/dist/development/vue/shop-pay.mjs +8 -0
- package/dist/development/vue/shop-pay.mjs.map +1 -1
- package/dist/development/vue/shopify-scripts.d.mts +11 -0
- package/dist/development/vue/shopify-scripts.mjs +6 -0
- package/dist/development/vue/shopify-scripts.mjs.map +1 -1
- package/dist/globals.d.mts +20 -11
- package/dist/graphql/generated/storefront-api-types.d.mts +127 -1
- package/dist/graphql/graphql.d.mts +17 -16
- package/dist/graphql/graphql.mjs +7 -8
- package/dist/graphql/graphql.mjs.map +1 -1
- package/dist/graphql/type-resolver.d.mts +15 -8
- package/dist/react/cart.d.mts +78 -32
- package/dist/react/cart.mjs +56 -29
- package/dist/react/cart.mjs.map +1 -1
- package/dist/react/collection.d.mts +40 -22
- package/dist/react/collection.mjs +27 -7
- package/dist/react/collection.mjs.map +1 -1
- package/dist/react/predictive-search.d.mts +65 -50
- package/dist/react/predictive-search.mjs +23 -21
- package/dist/react/predictive-search.mjs.map +1 -1
- package/dist/react/product.d.mts +45 -16
- package/dist/react/product.mjs +13 -11
- package/dist/react/product.mjs.map +1 -1
- package/dist/react/shop-pay.d.mts +15 -0
- package/dist/react/shop-pay.mjs +9 -0
- package/dist/react/shop-pay.mjs.map +1 -1
- package/dist/react/shopify-scripts.d.mts +23 -2
- package/dist/react/shopify-scripts.mjs +9 -0
- package/dist/react/shopify-scripts.mjs.map +1 -1
- package/dist/ts-plugin/index.cjs +6 -0
- package/dist/ts-plugin/index.cjs.map +1 -1
- package/dist/ts-plugin/index.d.cts +6 -0
- package/dist/vite/local-https.d.mts +51 -17
- package/dist/vite/local-https.mjs +26 -5
- package/dist/vite/local-https.mjs.map +1 -1
- package/dist/vue/cart.d.mts +28 -23
- package/dist/vue/cart.mjs +42 -25
- package/dist/vue/cart.mjs.map +1 -1
- package/dist/vue/collection.d.mts +20 -12
- package/dist/vue/collection.mjs +15 -7
- package/dist/vue/collection.mjs.map +1 -1
- package/dist/vue/index.d.mts +2 -2
- package/dist/vue/index.mjs +2 -2
- package/dist/vue/predictive-search.d.mts +31 -36
- package/dist/vue/predictive-search.mjs +16 -22
- package/dist/vue/predictive-search.mjs.map +1 -1
- package/dist/vue/product.d.mts +16 -15
- package/dist/vue/product.mjs +11 -11
- package/dist/vue/product.mjs.map +1 -1
- package/dist/vue/shop-pay.d.mts +14 -17
- package/dist/vue/shop-pay.mjs +8 -0
- package/dist/vue/shop-pay.mjs.map +1 -1
- package/dist/vue/shopify-scripts.d.mts +11 -0
- package/dist/vue/shopify-scripts.mjs +6 -0
- package/dist/vue/shopify-scripts.mjs.map +1 -1
- package/package.json +3 -1
- package/skills/hydrogen-analytics/SKILL.md +1 -1
- package/skills/hydrogen-cart-ui/SKILL.md +28 -2
- package/skills/hydrogen-collection-browser/SKILL.md +9 -1
- package/skills/hydrogen-collection-browser/references/nextjs.md +1 -1
- package/skills/hydrogen-collection-browser/references/nuxt.md +1 -1
- package/skills/hydrogen-collection-browser/references/react.md +151 -32
- package/skills/hydrogen-customer-account/SKILL.md +2 -0
- package/skills/hydrogen-request-handlers/SKILL.md +21 -11
- package/skills/hydrogen-setup/references/analytics.md +14 -8
- package/skills/hydrogen-setup/steps/1-inspect-app.md +2 -2
- package/skills/hydrogen-setup/steps/6-product-detail-page.md +21 -11
- package/skills/hydrogen-storefront-client/SKILL.md +1 -1
- package/skills/hydrogen-storefront-client/references/caching.md +2 -0
- package/skills/hydrogen-variant-form/SKILL.md +25 -7
- package/skills/hydrogen-variant-form/references/nextjs.md +39 -4
- package/skills/hydrogen-variant-form/references/nuxt.md +83 -42
- package/skills/hydrogen-variant-form/references/react.md +45 -9
|
@@ -3,53 +3,78 @@ import { StorefrontClient } from "../../client/types.mjs";
|
|
|
3
3
|
import { ShopifyRouteTemplates } from "../standard-routes/types.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/core/request-routing/route-types.d.ts
|
|
6
|
+
/** A value or a promise for that value. */
|
|
6
7
|
type Awaitable<T> = T | Promise<T>;
|
|
8
|
+
/** The session storage that route handlers and the customer session read and write. Implement the methods with your app's session. */
|
|
7
9
|
type ShopifyRouteSessionManager = {
|
|
8
|
-
getSessionOrigin(): Awaitable<string>;
|
|
9
|
-
getSessionItem(key: string): Awaitable<unknown>;
|
|
10
|
-
setSessionItem(key: string, value: unknown): Awaitable<void>;
|
|
11
|
-
removeSessionItem(key: string): Awaitable<void>;
|
|
10
|
+
/** Returns your storefront's HTTPS origin. Customer account sign-in builds its OAuth redirect URL from the origin. */getSessionOrigin(): Awaitable<string>; /** Returns the session value stored under a key. */
|
|
11
|
+
getSessionItem(key: string): Awaitable<unknown>; /** Stores a value in the session under a key. */
|
|
12
|
+
setSessionItem(key: string, value: unknown): Awaitable<void>; /** Deletes the session value stored under a key. */
|
|
13
|
+
removeSessionItem(key: string): Awaitable<void>; /** Saves session changes and returns the headers, such as a cookie, to add to the response. */
|
|
12
14
|
commit?(): Awaitable<HeadersInit | void>;
|
|
13
15
|
};
|
|
16
|
+
/** The values that Hydrogen passes to each registered route handler. */
|
|
14
17
|
type ShopifyRouteHandlerContext = {
|
|
15
|
-
request: Request;
|
|
16
|
-
sessionManager: ShopifyRouteSessionManager;
|
|
17
|
-
storefrontClient: StorefrontClient;
|
|
18
|
+
/** The incoming request that matched the handler's pathname and method. */request: Request; /** Your app's session storage for the current request. */
|
|
19
|
+
sessionManager: ShopifyRouteSessionManager; /** The Storefront API client for the current request. */
|
|
20
|
+
storefrontClient: StorefrontClient; /** The current request's context, the same one the Storefront API client uses. */
|
|
18
21
|
requestContext: ShopifyRequestContext;
|
|
19
22
|
};
|
|
23
|
+
/** A route handler result that Hydrogen sends as a `200` JSON response. */
|
|
20
24
|
type ShopifyRouteJsonResult<TData = unknown> = {
|
|
21
|
-
type: "json";
|
|
22
|
-
data: TData;
|
|
25
|
+
/** Set to `json` for a JSON response. */type: "json"; /** The value that Hydrogen serializes as the response body. */
|
|
26
|
+
data: TData; /** Extra headers for the response. Hydrogen sets `content-type` to `application/json` and overrides any value you pass. */
|
|
23
27
|
headers?: HeadersInit;
|
|
24
28
|
};
|
|
29
|
+
/** The HTTP status codes a route handler can use for a redirect. */
|
|
25
30
|
type ShopifyRedirectStatus = 301 | 302 | 303 | 307 | 308;
|
|
31
|
+
/** A route handler result that Hydrogen sends as a redirect response. */
|
|
26
32
|
type ShopifyRouteRedirectResult = {
|
|
27
|
-
type: "redirect";
|
|
28
|
-
location: string; /** HTTP redirect status. Defaults to 303
|
|
29
|
-
status?: ShopifyRedirectStatus;
|
|
33
|
+
/** Set to `redirect` for a redirect response. */type: "redirect"; /** The redirect target. Hydrogen resolves a relative path against the request's origin. */
|
|
34
|
+
location: string; /** The HTTP redirect status. Defaults to `303`. */
|
|
35
|
+
status?: ShopifyRedirectStatus; /** Extra headers for the redirect response. */
|
|
30
36
|
headers?: HeadersInit;
|
|
31
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* The code and message that an error result sends in the response body's `error` field.
|
|
40
|
+
*
|
|
41
|
+
* @publicDocs
|
|
42
|
+
*/
|
|
32
43
|
type ShopifyRouteError = {
|
|
33
|
-
code: string;
|
|
44
|
+
/** A machine-readable error code. */code: string; /** A human-readable error message. */
|
|
34
45
|
message: string;
|
|
35
46
|
};
|
|
47
|
+
/** A route handler result that Hydrogen sends as a JSON error response. */
|
|
36
48
|
type ShopifyRouteErrorResult<TError extends ShopifyRouteError = ShopifyRouteError> = {
|
|
37
|
-
type: "error";
|
|
38
|
-
error: TError;
|
|
39
|
-
status?: number;
|
|
49
|
+
/** Set to `error` for an error response. */type: "error"; /** The error that Hydrogen serializes as the response body's `error` field. */
|
|
50
|
+
error: TError; /** The HTTP status for the error response. Defaults to `400`. */
|
|
51
|
+
status?: number; /** Extra headers for the error response. Hydrogen sets `content-type` to `application/json` and overrides any value you pass. */
|
|
40
52
|
headers?: HeadersInit;
|
|
41
53
|
};
|
|
54
|
+
/** The JSON, redirect, or error result that a route handler returns. */
|
|
42
55
|
type ShopifyRouteHandlerResult<TData = unknown, TError extends ShopifyRouteError = ShopifyRouteError> = ShopifyRouteJsonResult<TData> | ShopifyRouteRedirectResult | ShopifyRouteErrorResult<TError>;
|
|
56
|
+
/** A route handler function that also carries the pathname and HTTP method it matches. */
|
|
43
57
|
type CallableRouteHandler<TContext, TResult, TPathname extends string = string, TMethod extends string = string> = ((context: TContext) => Promise<TResult>) & {
|
|
44
58
|
readonly pathname: TPathname;
|
|
45
59
|
readonly method: TMethod;
|
|
46
60
|
};
|
|
61
|
+
/** A handler for one pathname and HTTP method, created with createShopifyRouteHandler. */
|
|
47
62
|
type ShopifyRouteHandler<TPathname extends string = string, TMethod extends string = string> = CallableRouteHandler<ShopifyRouteHandlerContext, ShopifyRouteHandlerResult, TPathname, TMethod>;
|
|
63
|
+
/**
|
|
64
|
+
* An object of route handlers keyed by name. Pass an array of groups to `handleShopifyRoutes` as `handlers`.
|
|
65
|
+
*
|
|
66
|
+
* @publicDocs
|
|
67
|
+
*/
|
|
48
68
|
type ShopifyRouteHandlerGroup = Record<string, ShopifyRouteHandler>;
|
|
49
|
-
|
|
69
|
+
/** The request, its context and session, the Storefront API client, your route templates, and your handler groups. */
|
|
70
|
+
interface HydrogenRoutesOptions extends ShopifyRouteHandlerContext {
|
|
71
|
+
/**
|
|
72
|
+
* Your app's route templates. Hydrogen redirects Liquid-style `?variant=` URLs on your product paths and on Shopify's default product paths.
|
|
73
|
+
*/
|
|
50
74
|
routeTemplates?: ShopifyRouteTemplates;
|
|
75
|
+
/** The handler groups for your app's custom endpoints. */
|
|
51
76
|
handlers?: readonly ShopifyRouteHandlerGroup[];
|
|
52
|
-
}
|
|
77
|
+
}
|
|
53
78
|
type HydrogenRouteHandler<TExtraOptions extends object = object> = (options: HydrogenRoutesOptions & TExtraOptions) => null | Promise<Response>;
|
|
54
79
|
//#endregion
|
|
55
80
|
export { CallableRouteHandler, HydrogenRouteHandler, ShopifyRedirectStatus, ShopifyRouteError, ShopifyRouteErrorResult, ShopifyRouteHandler, ShopifyRouteHandlerContext, ShopifyRouteHandlerGroup, ShopifyRouteHandlerResult, ShopifyRouteJsonResult, ShopifyRouteRedirectResult, ShopifyRouteSessionManager };
|
|
@@ -1,55 +1,67 @@
|
|
|
1
1
|
//#region src/core/shop-pay/shop-pay.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Tag name of the Shop Pay button custom element, `hydrogen-shop-pay-button`.
|
|
4
|
+
*
|
|
5
|
+
* Use the tag directly on a framework without a Hydrogen binding.
|
|
6
|
+
*
|
|
7
|
+
* @publicDocs
|
|
8
|
+
*/
|
|
2
9
|
declare const SHOP_PAY_BUTTON_TAG_NAME = "hydrogen-shop-pay-button";
|
|
10
|
+
/** Checkout target, attribution, and display settings shared by every Shop Pay button. */
|
|
3
11
|
type ShopPayButtonBaseOptions = {
|
|
4
12
|
/**
|
|
5
|
-
* Absolute checkout base URL. Omit
|
|
6
|
-
* `/cart` permalink paths, which
|
|
7
|
-
* store's
|
|
13
|
+
* Absolute checkout base URL. Omit the URL to link to the same-origin `/checkout` and
|
|
14
|
+
* `/cart` permalink paths, which Hydrogen's Shopify route handler redirects to the
|
|
15
|
+
* store's checkout.
|
|
16
|
+
*
|
|
17
|
+
* Pass the cart's checkout URL when your app doesn't send same-origin checkout paths through the Shopify route handler. The button URL keeps the query params of the checkout URL, replaces any params that Shop Pay sets, and drops the hash. A bare domain such as `my-store.myshopify.com` gets an HTTPS scheme. The Shop Pay functions throw an error when the value isn't a valid URL.
|
|
8
18
|
*/
|
|
9
19
|
checkoutUrl?: string;
|
|
10
20
|
/**
|
|
11
|
-
* Checkout payment mode. Defaults to `
|
|
12
|
-
* `
|
|
13
|
-
* Installments.
|
|
21
|
+
* Checkout payment mode. Defaults to `shop_pay`. Use
|
|
22
|
+
* `shop_pay_installments` to open Shop Pay Installments at checkout.
|
|
14
23
|
*/
|
|
15
24
|
paymentOption?: "shop_pay" | "shop_pay_installments";
|
|
16
25
|
/**
|
|
17
|
-
* Attribution source
|
|
18
|
-
* `
|
|
26
|
+
* Attribution source that the checkout URL carries as `source`.
|
|
27
|
+
* Defaults to `hydrogen`. Most storefronts shouldn't change the source.
|
|
19
28
|
*/
|
|
20
29
|
source?: string;
|
|
21
30
|
/**
|
|
22
|
-
*
|
|
23
|
-
* Only pass a value when Shopify has provided one for the integration.
|
|
31
|
+
* Attribution token that the checkout URL carries as `source_token`.
|
|
24
32
|
*/
|
|
25
33
|
sourceToken?: string;
|
|
26
34
|
/**
|
|
27
|
-
* Content Security Policy nonce
|
|
35
|
+
* Content Security Policy nonce for the button's style element.
|
|
36
|
+
*
|
|
37
|
+
* The nonce covers only the style element. Custom width and border radius values render as an inline style attribute, which a strict Content Security Policy must allow.
|
|
28
38
|
*/
|
|
29
39
|
nonce?: string;
|
|
30
40
|
/**
|
|
31
|
-
* Sales channel that
|
|
32
|
-
* needs explicit `
|
|
41
|
+
* Sales channel that the checkout URL carries as `channel`. Omit the channel unless
|
|
42
|
+
* checkout needs explicit `headless` or `hydrogen` attribution.
|
|
33
43
|
*/
|
|
34
44
|
channel?: "headless" | "hydrogen";
|
|
35
45
|
/**
|
|
36
|
-
* Disables the button.
|
|
46
|
+
* Disables the button. A disabled button renders without an `href` and with
|
|
37
47
|
* `aria-disabled="true"`.
|
|
38
48
|
*/
|
|
39
49
|
disabled?: boolean;
|
|
40
50
|
/**
|
|
41
|
-
* CSS width
|
|
42
|
-
*
|
|
51
|
+
* CSS width of the button, such as `100%`. Defaults to `260px`.
|
|
52
|
+
*
|
|
53
|
+
* Pass a single CSS value. The Shop Pay functions throw an error when the width contains a semicolon or a curly brace.
|
|
43
54
|
*/
|
|
44
55
|
width?: string;
|
|
45
56
|
/**
|
|
46
|
-
* CSS border radius
|
|
47
|
-
*
|
|
57
|
+
* CSS border radius of the button, such as `8px`. Defaults to `12px`.
|
|
58
|
+
*
|
|
59
|
+
* Pass a single CSS value. The Shop Pay functions throw an error when the radius contains a semicolon or a curly brace.
|
|
48
60
|
*/
|
|
49
61
|
borderRadius?: string;
|
|
50
62
|
/**
|
|
51
|
-
* Localized accessible label for the
|
|
52
|
-
*
|
|
63
|
+
* Localized accessible label for the button. Defaults to `"Buy with Shop Pay"`.
|
|
64
|
+
* Keep the brand name Shop Pay untranslated and in Latin script in every locale.
|
|
53
65
|
*
|
|
54
66
|
* @example English
|
|
55
67
|
* `"Buy with Shop Pay"`
|
|
@@ -65,37 +77,61 @@ type ShopPayButtonBaseOptions = {
|
|
|
65
77
|
*/
|
|
66
78
|
accessibilityLabel?: string;
|
|
67
79
|
};
|
|
80
|
+
/** A variant ID and an optional quantity for a Shop Pay checkout. */
|
|
68
81
|
type ShopPayVariantWithQuantity = {
|
|
69
|
-
/**
|
|
82
|
+
/** Product variant GID or numeric variant ID. Product IDs throw an error. */id: string; /** Quantity of the variant. Defaults to `1`. */
|
|
70
83
|
quantity?: number;
|
|
71
84
|
};
|
|
85
|
+
/** Variants for a Shop Pay checkout, as all ID strings or all objects with an ID and a quantity. */
|
|
72
86
|
type ShopPayVariants = readonly string[] | readonly ShopPayVariantWithQuantity[];
|
|
73
|
-
|
|
87
|
+
/** Checkout target, variants, attribution, and display settings for a Shop Pay button. */
|
|
88
|
+
interface ShopPayButtonOptions extends ShopPayButtonBaseOptions {
|
|
74
89
|
/**
|
|
75
|
-
* Variants
|
|
76
|
-
*
|
|
90
|
+
* Variants that the customer buys right away through a Shopify cart permalink. Omit the variants
|
|
91
|
+
* to check out the current cart.
|
|
92
|
+
*
|
|
93
|
+
* Pass either all variant ID strings or all objects with an `id` and an optional `quantity`. Each quantity must be a positive integer. The Shop Pay functions throw an error for product IDs, non-numeric variant IDs, invalid quantities, and mixed formats.
|
|
77
94
|
*/
|
|
78
95
|
variants?: ShopPayVariants;
|
|
79
|
-
}
|
|
96
|
+
}
|
|
80
97
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
98
|
+
* Returns the checkout URL for a Shop Pay button. Use the URL to build your own Shop Pay link.
|
|
99
|
+
*
|
|
100
|
+
* With variants, the URL is a cart permalink that checks out those variants. Without variants, the URL checks out the current cart.
|
|
101
|
+
*
|
|
102
|
+
* @param options The variants, checkout URL, payment mode, attribution, and disabled state for the checkout URL.
|
|
103
|
+
* @returns The checkout URL, or `null` when `disabled` is `true`.
|
|
104
|
+
* @publicDocs
|
|
84
105
|
*/
|
|
85
106
|
declare function getShopPayButtonUrl(options: ShopPayButtonOptions): string | null;
|
|
86
107
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* JavaScript.
|
|
90
|
-
*
|
|
108
|
+
* Returns the Shop Pay button as an HTML string for server templates and frameworks without a Hydrogen binding.
|
|
109
|
+
*
|
|
110
|
+
* On the server, the markup includes the button's styles and link, and the button works without client JavaScript. In the browser, the function returns an empty element that renders the button when you add the element to the page.
|
|
111
|
+
*
|
|
112
|
+
* @param options The variants, checkout URL, and display settings for the button.
|
|
113
|
+
* @returns The Shop Pay button markup.
|
|
114
|
+
* @publicDocs
|
|
91
115
|
*/
|
|
92
116
|
declare function renderShopPayButton(options: ShopPayButtonOptions): string;
|
|
93
117
|
/**
|
|
94
|
-
* Creates
|
|
95
|
-
*
|
|
118
|
+
* Creates a Shop Pay button element in the browser. Append the element to the page.
|
|
119
|
+
*
|
|
120
|
+
* The function requires a DOM. Use `renderShopPayButton` during server rendering.
|
|
121
|
+
*
|
|
122
|
+
* @param options The variants, checkout URL, and display settings for the button.
|
|
123
|
+
* @returns The Shop Pay button element, ready to append to the page.
|
|
124
|
+
* @publicDocs
|
|
96
125
|
*/
|
|
97
126
|
declare function createShopPayButton(options: ShopPayButtonOptions): HTMLElement;
|
|
98
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* Registers the Shop Pay button custom element in the browser. Call the function when you use the `hydrogen-shop-pay-button` tag directly on a framework without a Hydrogen binding.
|
|
129
|
+
*
|
|
130
|
+
* The Hydrogen Shop Pay components, `createShopPayButton`, and `renderShopPayButton` register the element for you. The function does nothing during server rendering or when the browser already has the element.
|
|
131
|
+
*
|
|
132
|
+
* @returns Nothing.
|
|
133
|
+
* @publicDocs
|
|
134
|
+
*/
|
|
99
135
|
declare function defineShopPayButton(): void;
|
|
100
136
|
//#endregion
|
|
101
137
|
export { SHOP_PAY_BUTTON_TAG_NAME, ShopPayButtonOptions, createShopPayButton, defineShopPayButton, getShopPayButtonUrl, renderShopPayButton };
|
|
@@ -6,6 +6,13 @@ const DEFAULT_SOURCE = "hydrogen";
|
|
|
6
6
|
const DEFAULT_ACCESSIBILITY_LABEL = "Buy with Shop Pay";
|
|
7
7
|
const ERROR_PREFIX = "[hydrogen:error:ShopPay]";
|
|
8
8
|
const CAN_USE_DOM = typeof document !== "undefined";
|
|
9
|
+
/**
|
|
10
|
+
* Tag name of the Shop Pay button custom element, `hydrogen-shop-pay-button`.
|
|
11
|
+
*
|
|
12
|
+
* Use the tag directly on a framework without a Hydrogen binding.
|
|
13
|
+
*
|
|
14
|
+
* @publicDocs
|
|
15
|
+
*/
|
|
9
16
|
const SHOP_PAY_BUTTON_TAG_NAME = "hydrogen-shop-pay-button";
|
|
10
17
|
const SHOP_PAY_BUTTON_CLASS_NAME = "shop-pay-button";
|
|
11
18
|
const SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES = [
|
|
@@ -25,9 +32,13 @@ const SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES = [
|
|
|
25
32
|
const SHOP_PAY_BUTTON_STYLES = `:host{display:block}.${SHOP_PAY_BUTTON_CLASS_NAME}{position:relative;display:flex;align-items:center;box-sizing:border-box;margin:0;padding:10px 16px;overflow:visible;width:260px;border:none;border-radius:12px;background-color:#5433eb;color:#fff;cursor:pointer;text-decoration:none;transition:all .15s cubic-bezier(.4,0,.2,1)}.${SHOP_PAY_BUTTON_CLASS_NAME}:hover{background-color:#4524db}.${SHOP_PAY_BUTTON_CLASS_NAME}:focus-visible{outline:none;box-shadow:0 0 0 3px #9c83f8}.${SHOP_PAY_BUTTON_CLASS_NAME}[aria-disabled=true]{opacity:.5;pointer-events:none;cursor:default}.${SHOP_PAY_BUTTON_CLASS_NAME}__logo{position:relative;display:inline-block;margin:0 auto;width:88px;height:auto}`;
|
|
26
33
|
const SHOP_PAY_LOGO_SVG = `<svg class="${SHOP_PAY_BUTTON_CLASS_NAME}__logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 99 25" aria-hidden="true" focusable="false"><path fill="currentColor" d="M70.842 7.915h2.25c1.561 0 2.328.642 2.328 1.715 0 1.074-.739 1.715-2.259 1.715h-2.32v-3.43ZM80.525 16.142c-.879 0-1.227-.474-1.227-.948 0-.642.725-.935 2.147-1.102l1.115-.125c-.07 1.227-.892 2.175-2.035 2.175Z"/><path fill="currentColor" fill-rule="evenodd" d="M65.645.5a3.64 3.64 0 0 0-3.64 3.64V20.7a3.64 3.64 0 0 0 3.64 3.64h29.668a3.64 3.64 0 0 0 3.64-3.64V4.14A3.64 3.64 0 0 0 95.314.5H65.645Zm5.197 16.674v-4.197h2.64c2.412 0 3.695-1.353 3.695-3.402 0-2.05-1.283-3.277-3.695-3.277h-4.341v10.876h1.7Zm9.334.223c1.297 0 2.147-.572 2.538-1.548.112 1.088.767 1.645 2.189 1.269l.014-1.157c-.572.055-.683-.154-.683-.753v-2.845c0-1.673-1.102-2.663-3.138-2.663-2.008 0-3.165 1.004-3.165 2.705h1.562c0-.809.572-1.297 1.576-1.297 1.06 0 1.547.46 1.534 1.255v.363l-1.8.195c-2.021.223-3.137.99-3.137 2.329 0 1.101.781 2.147 2.51 2.147Zm9.906.32c-.711 1.73-1.855 2.245-3.64 2.245h-.766V18.54h.822c.977 0 1.45-.307 1.966-1.185L85.3 9.923h1.757l2.259 5.424 2.008-5.424h1.715l-2.956 7.795Z" clip-rule="evenodd"/><path fill="currentColor" d="M6.992 11.055c-2.359-.509-3.41-.708-3.41-1.612 0-.85.711-1.274 2.134-1.274 1.25 0 2.165.544 2.839 1.61.05.081.155.11.241.066l2.655-1.335a.186.186 0 0 0 .076-.259c-1.102-1.9-3.137-2.94-5.818-2.94C2.188 5.311 0 7.037 0 9.781c0 2.915 2.664 3.651 5.027 4.16 2.362.51 3.417.709 3.417 1.613s-.769 1.33-2.303 1.33c-1.416 0-2.467-.644-3.102-1.896a.186.186 0 0 0-.251-.082L.14 16.21a.188.188 0 0 0-.083.253c1.051 2.102 3.207 3.285 6.087 3.285 3.668 0 5.885-1.698 5.885-4.527 0-2.83-2.677-3.651-5.037-4.16v-.007ZM21.218 5.311c-1.505 0-2.835.531-3.791 1.477-.06.057-.159.015-.159-.067V.687A.185.185 0 0 0 17.081.5h-3.322a.185.185 0 0 0-.187.187v18.73c0 .104.083.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-1.587 1.223-2.804 2.87-2.804 1.649 0 2.843 1.191 2.843 2.804v8.216c0 .104.082.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-3.452-2.274-5.89-5.459-5.89ZM33.415 4.774c-1.803 0-3.493.55-4.706 1.343a.186.186 0 0 0-.06.25l1.464 2.488c.054.089.168.12.257.066a5.853 5.853 0 0 1 3.052-.834c2.899 0 5.03 2.036 5.03 4.726 0 2.292-1.706 3.99-3.868 3.99-1.762 0-2.985-1.022-2.985-2.463 0-.825.352-1.502 1.27-1.98a.183.183 0 0 0 .073-.258l-1.381-2.327a.187.187 0 0 0-.226-.079c-1.85.683-3.15 2.327-3.15 4.533 0 3.338 2.67 5.83 6.396 5.83 4.35 0 7.478-3 7.478-7.303 0-4.612-3.64-7.982-8.644-7.982ZM51.776 5.283c-1.68 0-3.182.62-4.277 1.707a.093.093 0 0 1-.16-.066v-1.31a.185.185 0 0 0-.187-.186h-3.235a.185.185 0 0 0-.188.187v18.702c0 .104.083.186.188.186h3.32a.185.185 0 0 0 .188-.186v-6.133c0-.082.099-.123.16-.07 1.091 1.012 2.536 1.603 4.19 1.603 3.897 0 6.936-3.139 6.936-7.217 0-4.078-3.042-7.217-6.935-7.217Zm-.63 11.266c-2.215 0-3.895-1.754-3.895-4.074S48.928 8.4 51.147 8.4c2.22 0 3.893 1.726 3.893 4.075 0 2.348-1.651 4.074-3.896 4.074h.003Z"/></svg>`;
|
|
27
34
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
35
|
+
* Returns the checkout URL for a Shop Pay button. Use the URL to build your own Shop Pay link.
|
|
36
|
+
*
|
|
37
|
+
* With variants, the URL is a cart permalink that checks out those variants. Without variants, the URL checks out the current cart.
|
|
38
|
+
*
|
|
39
|
+
* @param options The variants, checkout URL, payment mode, attribution, and disabled state for the checkout URL.
|
|
40
|
+
* @returns The checkout URL, or `null` when `disabled` is `true`.
|
|
41
|
+
* @publicDocs
|
|
31
42
|
*/
|
|
32
43
|
function getShopPayButtonUrl(options) {
|
|
33
44
|
if (options.disabled) return null;
|
|
@@ -41,10 +52,13 @@ function getShopPayButtonUrl(options) {
|
|
|
41
52
|
return url.toString();
|
|
42
53
|
}
|
|
43
54
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* JavaScript.
|
|
47
|
-
*
|
|
55
|
+
* Returns the Shop Pay button as an HTML string for server templates and frameworks without a Hydrogen binding.
|
|
56
|
+
*
|
|
57
|
+
* On the server, the markup includes the button's styles and link, and the button works without client JavaScript. In the browser, the function returns an empty element that renders the button when you add the element to the page.
|
|
58
|
+
*
|
|
59
|
+
* @param options The variants, checkout URL, and display settings for the button.
|
|
60
|
+
* @returns The Shop Pay button markup.
|
|
61
|
+
* @publicDocs
|
|
48
62
|
*/
|
|
49
63
|
function renderShopPayButton(options) {
|
|
50
64
|
defineShopPayButton();
|
|
@@ -53,8 +67,13 @@ function renderShopPayButton(options) {
|
|
|
53
67
|
return `<${SHOP_PAY_BUTTON_TAG_NAME}${attributes ? ` ${attributes}` : ""}>${content}</${SHOP_PAY_BUTTON_TAG_NAME}>`;
|
|
54
68
|
}
|
|
55
69
|
/**
|
|
56
|
-
* Creates
|
|
57
|
-
*
|
|
70
|
+
* Creates a Shop Pay button element in the browser. Append the element to the page.
|
|
71
|
+
*
|
|
72
|
+
* The function requires a DOM. Use `renderShopPayButton` during server rendering.
|
|
73
|
+
*
|
|
74
|
+
* @param options The variants, checkout URL, and display settings for the button.
|
|
75
|
+
* @returns The Shop Pay button element, ready to append to the page.
|
|
76
|
+
* @publicDocs
|
|
58
77
|
*/
|
|
59
78
|
function createShopPayButton(options) {
|
|
60
79
|
defineShopPayButton();
|
|
@@ -72,7 +91,14 @@ function initializeShopPayButtonElement(element, options) {
|
|
|
72
91
|
}
|
|
73
92
|
renderShopPayButtonShadowRoot(shadowRoot, options);
|
|
74
93
|
}
|
|
75
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Registers the Shop Pay button custom element in the browser. Call the function when you use the `hydrogen-shop-pay-button` tag directly on a framework without a Hydrogen binding.
|
|
96
|
+
*
|
|
97
|
+
* The Hydrogen Shop Pay components, `createShopPayButton`, and `renderShopPayButton` register the element for you. The function does nothing during server rendering or when the browser already has the element.
|
|
98
|
+
*
|
|
99
|
+
* @returns Nothing.
|
|
100
|
+
* @publicDocs
|
|
101
|
+
*/
|
|
76
102
|
function defineShopPayButton() {
|
|
77
103
|
if (typeof customElements === "undefined" || typeof HTMLElement === "undefined" || customElements.get("hydrogen-shop-pay-button")) return;
|
|
78
104
|
customElements.define(SHOP_PAY_BUTTON_TAG_NAME, class extends HTMLElement {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shop-pay.mjs","names":["#connected"],"sources":["../../../../src/core/shop-pay/shop-pay.ts"],"sourcesContent":["import { normalizeStoreDomain } from \"../url\";\nimport { parseGid } from \"../utils/parse-gid\";\n\nconst DEFAULT_SOURCE = \"hydrogen\";\nconst DEFAULT_ACCESSIBILITY_LABEL = \"Buy with Shop Pay\";\nconst ERROR_PREFIX = \"[hydrogen:error:ShopPay]\";\nconst CAN_USE_DOM = typeof document !== \"undefined\";\nexport const SHOP_PAY_BUTTON_TAG_NAME = \"hydrogen-shop-pay-button\";\nexport const SHOP_PAY_BUTTON_CLASS_NAME = \"shop-pay-button\";\nconst SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES = [\n \"accessibility-label\",\n \"border-radius\",\n \"channel\",\n \"checkout-url\",\n \"disabled\",\n \"nonce\",\n \"payment-option\",\n \"source\",\n \"source-token\",\n \"variants\",\n \"width\",\n] as const;\n\n/** Button styles matching the hosted shop-js pay button. */\nexport const SHOP_PAY_BUTTON_STYLES =\n `:host{display:block}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}{position:relative;display:flex;align-items:center;box-sizing:border-box;margin:0;padding:10px 16px;overflow:visible;width:260px;border:none;border-radius:12px;background-color:#5433eb;color:#fff;cursor:pointer;text-decoration:none;transition:all .15s cubic-bezier(.4,0,.2,1)}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:hover{background-color:#4524db}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:focus-visible{outline:none;box-shadow:0 0 0 3px #9c83f8}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}[aria-disabled=true]{opacity:.5;pointer-events:none;cursor:default}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}__logo{position:relative;display:inline-block;margin:0 auto;width:88px;height:auto}`;\n\nconst SHOP_PAY_LOGO_SVG =\n `<svg class=\"${SHOP_PAY_BUTTON_CLASS_NAME}__logo\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 99 25\" aria-hidden=\"true\" focusable=\"false\">` +\n '<path fill=\"currentColor\" d=\"M70.842 7.915h2.25c1.561 0 2.328.642 2.328 1.715 0 1.074-.739 1.715-2.259 1.715h-2.32v-3.43ZM80.525 16.142c-.879 0-1.227-.474-1.227-.948 0-.642.725-.935 2.147-1.102l1.115-.125c-.07 1.227-.892 2.175-2.035 2.175Z\"/>' +\n '<path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M65.645.5a3.64 3.64 0 0 0-3.64 3.64V20.7a3.64 3.64 0 0 0 3.64 3.64h29.668a3.64 3.64 0 0 0 3.64-3.64V4.14A3.64 3.64 0 0 0 95.314.5H65.645Zm5.197 16.674v-4.197h2.64c2.412 0 3.695-1.353 3.695-3.402 0-2.05-1.283-3.277-3.695-3.277h-4.341v10.876h1.7Zm9.334.223c1.297 0 2.147-.572 2.538-1.548.112 1.088.767 1.645 2.189 1.269l.014-1.157c-.572.055-.683-.154-.683-.753v-2.845c0-1.673-1.102-2.663-3.138-2.663-2.008 0-3.165 1.004-3.165 2.705h1.562c0-.809.572-1.297 1.576-1.297 1.06 0 1.547.46 1.534 1.255v.363l-1.8.195c-2.021.223-3.137.99-3.137 2.329 0 1.101.781 2.147 2.51 2.147Zm9.906.32c-.711 1.73-1.855 2.245-3.64 2.245h-.766V18.54h.822c.977 0 1.45-.307 1.966-1.185L85.3 9.923h1.757l2.259 5.424 2.008-5.424h1.715l-2.956 7.795Z\" clip-rule=\"evenodd\"/>' +\n '<path fill=\"currentColor\" d=\"M6.992 11.055c-2.359-.509-3.41-.708-3.41-1.612 0-.85.711-1.274 2.134-1.274 1.25 0 2.165.544 2.839 1.61.05.081.155.11.241.066l2.655-1.335a.186.186 0 0 0 .076-.259c-1.102-1.9-3.137-2.94-5.818-2.94C2.188 5.311 0 7.037 0 9.781c0 2.915 2.664 3.651 5.027 4.16 2.362.51 3.417.709 3.417 1.613s-.769 1.33-2.303 1.33c-1.416 0-2.467-.644-3.102-1.896a.186.186 0 0 0-.251-.082L.14 16.21a.188.188 0 0 0-.083.253c1.051 2.102 3.207 3.285 6.087 3.285 3.668 0 5.885-1.698 5.885-4.527 0-2.83-2.677-3.651-5.037-4.16v-.007ZM21.218 5.311c-1.505 0-2.835.531-3.791 1.477-.06.057-.159.015-.159-.067V.687A.185.185 0 0 0 17.081.5h-3.322a.185.185 0 0 0-.187.187v18.73c0 .104.083.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-1.587 1.223-2.804 2.87-2.804 1.649 0 2.843 1.191 2.843 2.804v8.216c0 .104.082.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-3.452-2.274-5.89-5.459-5.89ZM33.415 4.774c-1.803 0-3.493.55-4.706 1.343a.186.186 0 0 0-.06.25l1.464 2.488c.054.089.168.12.257.066a5.853 5.853 0 0 1 3.052-.834c2.899 0 5.03 2.036 5.03 4.726 0 2.292-1.706 3.99-3.868 3.99-1.762 0-2.985-1.022-2.985-2.463 0-.825.352-1.502 1.27-1.98a.183.183 0 0 0 .073-.258l-1.381-2.327a.187.187 0 0 0-.226-.079c-1.85.683-3.15 2.327-3.15 4.533 0 3.338 2.67 5.83 6.396 5.83 4.35 0 7.478-3 7.478-7.303 0-4.612-3.64-7.982-8.644-7.982ZM51.776 5.283c-1.68 0-3.182.62-4.277 1.707a.093.093 0 0 1-.16-.066v-1.31a.185.185 0 0 0-.187-.186h-3.235a.185.185 0 0 0-.188.187v18.702c0 .104.083.186.188.186h3.32a.185.185 0 0 0 .188-.186v-6.133c0-.082.099-.123.16-.07 1.091 1.012 2.536 1.603 4.19 1.603 3.897 0 6.936-3.139 6.936-7.217 0-4.078-3.042-7.217-6.935-7.217Zm-.63 11.266c-2.215 0-3.895-1.754-3.895-4.074S48.928 8.4 51.147 8.4c2.22 0 3.893 1.726 3.893 4.075 0 2.348-1.651 4.074-3.896 4.074h.003Z\"/>' +\n \"</svg>\";\n\ntype ShopPayButtonBaseOptions = {\n /**\n * Absolute checkout base URL. Omit it to emit same-origin `/checkout` and\n * `/cart` permalink paths, which `handleShopifyRoutes` redirects to the\n * store's real checkout.\n */\n checkoutUrl?: string;\n /**\n * Checkout payment mode. Defaults to `\"shop_pay\"`. Use\n * `\"shop_pay_installments\"` only when the checkout path should open Shop Pay\n * Installments.\n */\n paymentOption?: \"shop_pay\" | \"shop_pay_installments\";\n /**\n * Attribution source appended to the checkout URL as `source`. Defaults to\n * `\"hydrogen\"`. Most storefronts should not override this.\n */\n source?: string;\n /**\n * Optional attribution token appended to the checkout URL as `source_token`.\n * Only pass a value when Shopify has provided one for the integration.\n */\n sourceToken?: string;\n /**\n * Content Security Policy nonce applied to the shadow root's inline style.\n */\n nonce?: string;\n /**\n * Sales channel that issued the Storefront API token. Omit it unless checkout\n * needs explicit `\"headless\"` or `\"hydrogen\"` attribution.\n */\n channel?: \"headless\" | \"hydrogen\";\n /**\n * Disables the button. Disabled buttons render without an `href` and include\n * `aria-disabled=\"true\"`.\n */\n disabled?: boolean;\n /**\n * CSS width for the rendered anchor, for example `\"100%\"`. Omit it to use\n * the Shop Pay default width.\n */\n width?: string;\n /**\n * CSS border radius for the rendered anchor, for example `\"8px\"`. Omit it to\n * use the Shop Pay default radius.\n */\n borderRadius?: string;\n /**\n * Localized accessible label for the Shop Pay logo. Defaults to `\"Buy with Shop Pay\"`.\n * Never translate the brand name `\"Shop Pay\"`; keep it in Latin script in every locale.\n *\n * @example English\n * `\"Buy with Shop Pay\"`\n *\n * @example Japanese\n * `\"Shop Payで購入\"`\n *\n * @example Hindi\n * `\"Shop Pay से खरीदें\"`\n *\n * @example Arabic\n * `\"الشراء باستخدام Shop Pay\"`\n */\n accessibilityLabel?: string;\n};\n\ntype ShopPayVariantWithQuantity = {\n /** ProductVariant GID or bare numeric ProductVariant ID. Product IDs are invalid. */\n id: string;\n /** Quantity for this variant. Defaults to `1`. */\n quantity?: number;\n};\n\ntype ShopPayVariant = string | ShopPayVariantWithQuantity;\ntype ShopPayVariants = readonly string[] | readonly ShopPayVariantWithQuantity[];\n\nexport type ShopPayButtonOptions = ShopPayButtonBaseOptions & {\n /**\n * Variants to check out immediately via a Shopify cart permalink. Omit this\n * for cart checkout mode, where `/checkout` checks out the current cart.\n */\n variants?: ShopPayVariants;\n};\n\n/**\n * Builds the checkout URL the Shop Pay button navigates to, or `null` when the\n * button is disabled. Variant mode produces a cart permalink; otherwise the\n * current cart checks out.\n */\nexport function getShopPayButtonUrl(options: ShopPayButtonOptions): string | null {\n if (options.disabled) return null;\n\n const variants = getShopPayVariants(options);\n\n if (!options.checkoutUrl) {\n const search = getShopPaySearchParams(options);\n return `${variants ? `/cart/${variants}` : \"/checkout\"}?${search}`;\n }\n\n const url = variants\n ? getShopPayVariantModeUrl(options.checkoutUrl, variants)\n : getShopPayCheckoutModeUrl(options.checkoutUrl);\n\n for (const [name, value] of getShopPaySearchParams(options)) {\n url.searchParams.set(name, value);\n }\n\n return url.toString();\n}\n\n/**\n * Renders the Shop Pay button as an HTML string: a self-contained wrapper\n * element carrying the styles and anchor it needs to work without client\n * JavaScript. Use it from server templates or frameworks without a Hydrogen\n * binding.\n */\nexport function renderShopPayButton(options: ShopPayButtonOptions): string {\n defineShopPayButton();\n const attributes = serializeAttributes(getShopPayButtonElementAttributes(options));\n const content = CAN_USE_DOM ? \"\" : getShopPayButtonDeclarativeShadowDomHtml(options);\n return `<${SHOP_PAY_BUTTON_TAG_NAME}${attributes ? ` ${attributes}` : \"\"}>${content}</${SHOP_PAY_BUTTON_TAG_NAME}>`;\n}\n\n/**\n * Creates the Shop Pay button as a detached DOM element. The returned element\n * carries the button styles with it.\n */\nexport function createShopPayButton(options: ShopPayButtonOptions): HTMLElement {\n defineShopPayButton();\n const element = document.createElement(SHOP_PAY_BUTTON_TAG_NAME);\n initializeShopPayButtonElement(element, options);\n\n return element;\n}\n\nexport function initializeShopPayButtonElement(\n element: HTMLElement,\n options: ShopPayButtonOptions,\n): void {\n syncShopPayButtonElementAttributes(element, getShopPayButtonElementAttributes(options));\n\n const shadowRoot = element.shadowRoot ?? element.attachShadow({ mode: \"open\" });\n const template = element.querySelector(\"template[shadowrootmode]\");\n\n if (template instanceof HTMLTemplateElement) {\n shadowRoot.append(template.content.cloneNode(true));\n template.remove();\n }\n\n renderShopPayButtonShadowRoot(shadowRoot, options);\n}\n\n/** Registers the Shop Pay custom element. No-ops during SSR or when already registered. */\nexport function defineShopPayButton(): void {\n if (\n typeof customElements === \"undefined\" ||\n typeof HTMLElement === \"undefined\" ||\n customElements.get(SHOP_PAY_BUTTON_TAG_NAME)\n ) {\n return;\n }\n\n customElements.define(\n SHOP_PAY_BUTTON_TAG_NAME,\n class extends HTMLElement {\n #connected = false;\n\n static observedAttributes = SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES;\n\n connectedCallback(): void {\n this.#connected = true;\n initializeShopPayButtonElement(this, getShopPayButtonOptions(this));\n }\n\n attributeChangedCallback(): void {\n if (!this.#connected || !this.shadowRoot) return;\n renderShopPayButtonShadowRoot(this.shadowRoot, getShopPayButtonOptions(this));\n }\n },\n );\n}\n\n/** Anchor attributes shared by server and browser shadow-root rendering. */\nexport function getShopPayButtonAnchorAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {\n class: SHOP_PAY_BUTTON_CLASS_NAME,\n target: \"_self\",\n };\n\n const href = getShopPayButtonUrl(options);\n if (href) {\n attributes.href = href;\n } else {\n attributes.role = \"link\";\n attributes[\"aria-disabled\"] = \"true\";\n }\n\n const style = serializeStyleProperties(getShopPayButtonStyleProperties(options));\n if (style) attributes.style = style;\n\n attributes[\"aria-label\"] = getShopPayAccessibilityLabel(options.accessibilityLabel);\n\n return attributes;\n}\n\nexport function getShopPayButtonElementContentHtml(options: ShopPayButtonOptions): string {\n return `<style${getShopPayButtonStyleNonceAttribute(options)}>${SHOP_PAY_BUTTON_STYLES}</style><a ${serializeAttributes(getShopPayButtonAnchorAttributes(options))}>${getShopPayButtonContentHtml()}</a>`;\n}\n\nexport function getShopPayButtonDeclarativeShadowDomHtml(options: ShopPayButtonOptions): string {\n return `<template shadowrootmode=\"open\" shadowroot=\"open\">${getShopPayButtonElementContentHtml(options)}</template>`;\n}\n\nexport function getShopPayButtonElementAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {};\n const variants = getShopPayVariants(options);\n\n if (hasContent(options.accessibilityLabel)) {\n attributes[\"accessibility-label\"] = options.accessibilityLabel.trim();\n }\n if (hasContent(options.borderRadius)) {\n attributes[\"border-radius\"] = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n if (options.channel) attributes.channel = options.channel;\n if (options.checkoutUrl !== undefined) attributes[\"checkout-url\"] = options.checkoutUrl;\n if (options.disabled) attributes.disabled = \"\";\n if (hasContent(options.nonce)) attributes.nonce = options.nonce.trim();\n if (options.paymentOption) attributes[\"payment-option\"] = options.paymentOption;\n if (options.source !== undefined) attributes.source = options.source;\n if (options.sourceToken !== undefined) attributes[\"source-token\"] = options.sourceToken;\n if (variants) attributes.variants = variants;\n if (hasContent(options.width)) {\n attributes.width = normalizeCssValue(\"width\", options.width);\n }\n\n return attributes;\n}\n\n/** Inner HTML for the shadow root's anchor. */\nexport function getShopPayButtonContentHtml(): string {\n return SHOP_PAY_LOGO_SVG;\n}\n\nfunction getShopPayButtonStyleProperties(\n options: Pick<ShopPayButtonOptions, \"width\" | \"borderRadius\">,\n): Record<string, string> {\n const style: Record<string, string> = {};\n\n if (hasContent(options.width)) style.width = normalizeCssValue(\"width\", options.width);\n if (hasContent(options.borderRadius)) {\n style.borderRadius = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n\n return style;\n}\n\nfunction getShopPaySearchParams(options: ShopPayButtonOptions): URLSearchParams {\n const params = new URLSearchParams();\n params.set(\"payment\", options.paymentOption ?? \"shop_pay\");\n\n const source = options.source ?? DEFAULT_SOURCE;\n if (source) params.set(\"source\", source);\n if (options.sourceToken) params.set(\"source_token\", options.sourceToken);\n if (options.channel) params.set(\"channel\", options.channel);\n\n return params;\n}\n\nfunction getShopPayCheckoutModeUrl(checkoutUrl: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n if (url.pathname === \"/\") url.pathname = \"/checkout\";\n url.hash = \"\";\n return url;\n}\n\nfunction getShopPayVariantModeUrl(checkoutUrl: string, variants: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n url.pathname = `/cart/${variants}`;\n url.hash = \"\";\n return url;\n}\n\nfunction parseCheckoutUrl(checkoutUrl: string): URL {\n try {\n return new URL(normalizeStoreDomain(checkoutUrl.trim()));\n } catch {\n throw shopPayError('Shop Pay requires a valid \"checkoutUrl\" value.');\n }\n}\n\nfunction getShopPayVariants(options: ShopPayButtonOptions): string | undefined {\n const variantsInput: readonly ShopPayVariant[] | undefined = options.variants;\n\n if (!Array.isArray(variantsInput) || variantsInput.length === 0) return undefined;\n\n if (variantsInput.every(isVariantId)) {\n return variantsInput.map((id) => `${normalizeVariantId(id)}:1`).join(\",\");\n }\n\n if (variantsInput.every(isVariantWithQuantity)) {\n return variantsInput\n .map(({ id, quantity }) => {\n return `${normalizeVariantId(id)}:${normalizeQuantity(quantity)}`;\n })\n .join(\",\");\n }\n\n throw shopPayError(\n \"Shop Pay variants must be either variant IDs or objects with an id and quantity.\",\n );\n}\n\nfunction isVariantId(variant: ShopPayVariant): variant is string {\n return typeof variant === \"string\";\n}\n\nfunction getShopPayButtonOptions(element: HTMLElement): ShopPayButtonOptions {\n return {\n accessibilityLabel: element.getAttribute(\"accessibility-label\") ?? undefined,\n borderRadius: element.getAttribute(\"border-radius\") ?? undefined,\n channel: parseChannel(element.getAttribute(\"channel\")),\n checkoutUrl: element.getAttribute(\"checkout-url\") ?? undefined,\n disabled: element.hasAttribute(\"disabled\"),\n nonce: element.nonce || element.getAttribute(\"nonce\") || undefined,\n paymentOption: parsePaymentOption(element.getAttribute(\"payment-option\")),\n source: element.getAttribute(\"source\") ?? undefined,\n sourceToken: element.getAttribute(\"source-token\") ?? undefined,\n variants: parseVariantsAttribute(element.getAttribute(\"variants\")),\n width: element.getAttribute(\"width\") ?? undefined,\n };\n}\n\nfunction parseVariantsAttribute(value: string | null): ShopPayVariants | undefined {\n if (!value) return undefined;\n\n return value.split(\",\").map((entry) => {\n const [id = \"\", quantity] = entry.split(\":\");\n return { id, quantity: quantity === undefined ? undefined : Number(quantity) };\n });\n}\n\nfunction parsePaymentOption(value: string | null): ShopPayButtonOptions[\"paymentOption\"] {\n return value === \"shop_pay\" || value === \"shop_pay_installments\" ? value : undefined;\n}\n\nfunction parseChannel(value: string | null): ShopPayButtonOptions[\"channel\"] {\n return value === \"headless\" || value === \"hydrogen\" ? value : undefined;\n}\n\nfunction renderShopPayButtonShadowRoot(\n shadowRoot: ShadowRoot,\n options: ShopPayButtonOptions,\n): void {\n let style = shadowRoot.querySelector(\"style\");\n if (!(style instanceof HTMLStyleElement)) {\n style = shadowRoot.ownerDocument.createElement(\"style\");\n shadowRoot.prepend(style);\n }\n\n const nextNonce = hasContent(options.nonce) ? options.nonce.trim() : undefined;\n const nonceChanged = (style.nonce || undefined) !== nextNonce;\n if (nextNonce) {\n style.nonce = nextNonce;\n } else {\n style.removeAttribute(\"nonce\");\n }\n if (nonceChanged) style.textContent = \"\";\n if (style.textContent !== SHOP_PAY_BUTTON_STYLES) style.textContent = SHOP_PAY_BUTTON_STYLES;\n\n let anchor = shadowRoot.querySelector(\"a\");\n if (!(anchor instanceof HTMLAnchorElement)) {\n anchor = shadowRoot.ownerDocument.createElement(\"a\");\n shadowRoot.append(anchor);\n }\n\n syncAttributes(anchor, getShopPayButtonAnchorAttributes(options));\n const content = getShopPayButtonContentHtml();\n if (anchor.innerHTML !== content) anchor.innerHTML = content;\n}\n\nfunction syncAttributes(element: Element, attributes: Record<string, string>): void {\n for (const name of element.getAttributeNames()) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction syncShopPayButtonElementAttributes(\n element: Element,\n attributes: Record<string, string>,\n): void {\n for (const name of SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction isVariantWithQuantity(\n variant: ShopPayVariant | undefined,\n): variant is ShopPayVariantWithQuantity {\n return typeof variant === \"object\" && variant !== null && typeof variant.id === \"string\";\n}\n\nfunction normalizeVariantId(id: string): string {\n const parsed = parseGid(id);\n const bareId = parsed.id || id.trim();\n\n if (parsed.resource && parsed.resource !== \"ProductVariant\") {\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n }\n\n if (/^\\d+$/.test(bareId)) return bareId;\n\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n}\n\nfunction normalizeQuantity(quantity = 1): number {\n if (!Number.isInteger(quantity) || quantity < 1) {\n throw shopPayError(\"Shop Pay variant quantities must be positive integers.\");\n }\n\n return quantity;\n}\n\nfunction escapeText(value: string): string {\n return value.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\");\n}\n\nfunction escapeAttribute(value: string): string {\n return escapeText(value).replace(/\"/g, \""\");\n}\n\nfunction getShopPayAccessibilityLabel(label: string | undefined): string {\n return hasContent(label) ? label.trim() : DEFAULT_ACCESSIBILITY_LABEL;\n}\n\nfunction getShopPayButtonStyleNonceAttribute(options: Pick<ShopPayButtonOptions, \"nonce\">): string {\n return hasContent(options.nonce) ? ` nonce=\"${escapeAttribute(options.nonce.trim())}\"` : \"\";\n}\n\nfunction hasContent(value: string | undefined): value is string {\n return typeof value === \"string\" && value.trim() !== \"\";\n}\n\nfunction normalizeCssValue(name: \"width\" | \"borderRadius\", value: string): string {\n const normalized = value.trim();\n if (/[;{}]/.test(normalized)) {\n throw shopPayError(`Shop Pay ${name} must be a single CSS value.`);\n }\n return normalized;\n}\n\nfunction serializeAttributes(attributes: Record<string, string>): string {\n return Object.entries(attributes)\n .map(([name, value]) => `${name}=\"${escapeAttribute(value)}\"`)\n .join(\" \");\n}\n\nfunction serializeStyleProperties(style: Record<string, string>): string {\n return Object.entries(style)\n .map(([name, value]) => `${hyphenateStyleName(name)}:${value}`)\n .join(\";\");\n}\n\nfunction hyphenateStyleName(name: string): string {\n return name.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);\n}\n\nfunction shopPayError(message: string): Error {\n return new Error(`${ERROR_PREFIX} ${message}`);\n}\n"],"mappings":";;;;AAGA,MAAM,iBAAiB;AACvB,MAAM,8BAA8B;AACpC,MAAM,eAAe;AACrB,MAAM,cAAc,OAAO,aAAa;AACxC,MAAa,2BAA2B;AACxC,MAAa,6BAA6B;AAC1C,MAAM,sCAAsC;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,yBACX,wBACI,2BAA2B,uRAC3B,2BAA2B,mCAC3B,2BAA2B,4DAC3B,2BAA2B,sEAC3B,2BAA2B;AAEjC,MAAM,oBACJ,eAAe,2BAA2B;;;;;;AA+F5C,SAAgB,oBAAoB,SAA8C;AAChF,KAAI,QAAQ,SAAU,QAAO;CAE7B,MAAM,WAAW,mBAAmB,QAAQ;AAE5C,KAAI,CAAC,QAAQ,aAAa;EACxB,MAAM,SAAS,uBAAuB,QAAQ;AAC9C,SAAO,GAAG,WAAW,SAAS,aAAa,YAAY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D,QAAO,KAAK,QAAQ,WAAW,UAAU,IAAI,MAAM,aAAa,GAAG;;AAGrE,SAAS,aAAa,SAAwB;AAC5C,wBAAO,IAAI,MAAM,GAAG,aAAa,GAAG,UAAU"}
|
|
1
|
+
{"version":3,"file":"shop-pay.mjs","names":["#connected"],"sources":["../../../../src/core/shop-pay/shop-pay.ts"],"sourcesContent":["import { normalizeStoreDomain } from \"../url\";\nimport { parseGid } from \"../utils/parse-gid\";\n\nconst DEFAULT_SOURCE = \"hydrogen\";\nconst DEFAULT_ACCESSIBILITY_LABEL = \"Buy with Shop Pay\";\nconst ERROR_PREFIX = \"[hydrogen:error:ShopPay]\";\nconst CAN_USE_DOM = typeof document !== \"undefined\";\n/**\n * Tag name of the Shop Pay button custom element, `hydrogen-shop-pay-button`.\n *\n * Use the tag directly on a framework without a Hydrogen binding.\n *\n * @publicDocs\n */\nexport const SHOP_PAY_BUTTON_TAG_NAME = \"hydrogen-shop-pay-button\";\nexport const SHOP_PAY_BUTTON_CLASS_NAME = \"shop-pay-button\";\nconst SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES = [\n \"accessibility-label\",\n \"border-radius\",\n \"channel\",\n \"checkout-url\",\n \"disabled\",\n \"nonce\",\n \"payment-option\",\n \"source\",\n \"source-token\",\n \"variants\",\n \"width\",\n] as const;\n\n/** Button styles matching the hosted shop-js pay button. */\nexport const SHOP_PAY_BUTTON_STYLES =\n `:host{display:block}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}{position:relative;display:flex;align-items:center;box-sizing:border-box;margin:0;padding:10px 16px;overflow:visible;width:260px;border:none;border-radius:12px;background-color:#5433eb;color:#fff;cursor:pointer;text-decoration:none;transition:all .15s cubic-bezier(.4,0,.2,1)}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:hover{background-color:#4524db}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:focus-visible{outline:none;box-shadow:0 0 0 3px #9c83f8}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}[aria-disabled=true]{opacity:.5;pointer-events:none;cursor:default}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}__logo{position:relative;display:inline-block;margin:0 auto;width:88px;height:auto}`;\n\nconst SHOP_PAY_LOGO_SVG =\n `<svg class=\"${SHOP_PAY_BUTTON_CLASS_NAME}__logo\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 99 25\" aria-hidden=\"true\" focusable=\"false\">` +\n '<path fill=\"currentColor\" d=\"M70.842 7.915h2.25c1.561 0 2.328.642 2.328 1.715 0 1.074-.739 1.715-2.259 1.715h-2.32v-3.43ZM80.525 16.142c-.879 0-1.227-.474-1.227-.948 0-.642.725-.935 2.147-1.102l1.115-.125c-.07 1.227-.892 2.175-2.035 2.175Z\"/>' +\n '<path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M65.645.5a3.64 3.64 0 0 0-3.64 3.64V20.7a3.64 3.64 0 0 0 3.64 3.64h29.668a3.64 3.64 0 0 0 3.64-3.64V4.14A3.64 3.64 0 0 0 95.314.5H65.645Zm5.197 16.674v-4.197h2.64c2.412 0 3.695-1.353 3.695-3.402 0-2.05-1.283-3.277-3.695-3.277h-4.341v10.876h1.7Zm9.334.223c1.297 0 2.147-.572 2.538-1.548.112 1.088.767 1.645 2.189 1.269l.014-1.157c-.572.055-.683-.154-.683-.753v-2.845c0-1.673-1.102-2.663-3.138-2.663-2.008 0-3.165 1.004-3.165 2.705h1.562c0-.809.572-1.297 1.576-1.297 1.06 0 1.547.46 1.534 1.255v.363l-1.8.195c-2.021.223-3.137.99-3.137 2.329 0 1.101.781 2.147 2.51 2.147Zm9.906.32c-.711 1.73-1.855 2.245-3.64 2.245h-.766V18.54h.822c.977 0 1.45-.307 1.966-1.185L85.3 9.923h1.757l2.259 5.424 2.008-5.424h1.715l-2.956 7.795Z\" clip-rule=\"evenodd\"/>' +\n '<path fill=\"currentColor\" d=\"M6.992 11.055c-2.359-.509-3.41-.708-3.41-1.612 0-.85.711-1.274 2.134-1.274 1.25 0 2.165.544 2.839 1.61.05.081.155.11.241.066l2.655-1.335a.186.186 0 0 0 .076-.259c-1.102-1.9-3.137-2.94-5.818-2.94C2.188 5.311 0 7.037 0 9.781c0 2.915 2.664 3.651 5.027 4.16 2.362.51 3.417.709 3.417 1.613s-.769 1.33-2.303 1.33c-1.416 0-2.467-.644-3.102-1.896a.186.186 0 0 0-.251-.082L.14 16.21a.188.188 0 0 0-.083.253c1.051 2.102 3.207 3.285 6.087 3.285 3.668 0 5.885-1.698 5.885-4.527 0-2.83-2.677-3.651-5.037-4.16v-.007ZM21.218 5.311c-1.505 0-2.835.531-3.791 1.477-.06.057-.159.015-.159-.067V.687A.185.185 0 0 0 17.081.5h-3.322a.185.185 0 0 0-.187.187v18.73c0 .104.083.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-1.587 1.223-2.804 2.87-2.804 1.649 0 2.843 1.191 2.843 2.804v8.216c0 .104.082.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-3.452-2.274-5.89-5.459-5.89ZM33.415 4.774c-1.803 0-3.493.55-4.706 1.343a.186.186 0 0 0-.06.25l1.464 2.488c.054.089.168.12.257.066a5.853 5.853 0 0 1 3.052-.834c2.899 0 5.03 2.036 5.03 4.726 0 2.292-1.706 3.99-3.868 3.99-1.762 0-2.985-1.022-2.985-2.463 0-.825.352-1.502 1.27-1.98a.183.183 0 0 0 .073-.258l-1.381-2.327a.187.187 0 0 0-.226-.079c-1.85.683-3.15 2.327-3.15 4.533 0 3.338 2.67 5.83 6.396 5.83 4.35 0 7.478-3 7.478-7.303 0-4.612-3.64-7.982-8.644-7.982ZM51.776 5.283c-1.68 0-3.182.62-4.277 1.707a.093.093 0 0 1-.16-.066v-1.31a.185.185 0 0 0-.187-.186h-3.235a.185.185 0 0 0-.188.187v18.702c0 .104.083.186.188.186h3.32a.185.185 0 0 0 .188-.186v-6.133c0-.082.099-.123.16-.07 1.091 1.012 2.536 1.603 4.19 1.603 3.897 0 6.936-3.139 6.936-7.217 0-4.078-3.042-7.217-6.935-7.217Zm-.63 11.266c-2.215 0-3.895-1.754-3.895-4.074S48.928 8.4 51.147 8.4c2.22 0 3.893 1.726 3.893 4.075 0 2.348-1.651 4.074-3.896 4.074h.003Z\"/>' +\n \"</svg>\";\n\n/** Checkout target, attribution, and display settings shared by every Shop Pay button. */\ntype ShopPayButtonBaseOptions = {\n /**\n * Absolute checkout base URL. Omit the URL to link to the same-origin `/checkout` and\n * `/cart` permalink paths, which Hydrogen's Shopify route handler redirects to the\n * store's checkout.\n *\n * Pass the cart's checkout URL when your app doesn't send same-origin checkout paths through the Shopify route handler. The button URL keeps the query params of the checkout URL, replaces any params that Shop Pay sets, and drops the hash. A bare domain such as `my-store.myshopify.com` gets an HTTPS scheme. The Shop Pay functions throw an error when the value isn't a valid URL.\n */\n checkoutUrl?: string;\n /**\n * Checkout payment mode. Defaults to `shop_pay`. Use\n * `shop_pay_installments` to open Shop Pay Installments at checkout.\n */\n paymentOption?: \"shop_pay\" | \"shop_pay_installments\";\n /**\n * Attribution source that the checkout URL carries as `source`.\n * Defaults to `hydrogen`. Most storefronts shouldn't change the source.\n */\n source?: string;\n /**\n * Attribution token that the checkout URL carries as `source_token`.\n */\n sourceToken?: string;\n /**\n * Content Security Policy nonce for the button's style element.\n *\n * The nonce covers only the style element. Custom width and border radius values render as an inline style attribute, which a strict Content Security Policy must allow.\n */\n nonce?: string;\n /**\n * Sales channel that the checkout URL carries as `channel`. Omit the channel unless\n * checkout needs explicit `headless` or `hydrogen` attribution.\n */\n channel?: \"headless\" | \"hydrogen\";\n /**\n * Disables the button. A disabled button renders without an `href` and with\n * `aria-disabled=\"true\"`.\n */\n disabled?: boolean;\n /**\n * CSS width of the button, such as `100%`. Defaults to `260px`.\n *\n * Pass a single CSS value. The Shop Pay functions throw an error when the width contains a semicolon or a curly brace.\n */\n width?: string;\n /**\n * CSS border radius of the button, such as `8px`. Defaults to `12px`.\n *\n * Pass a single CSS value. The Shop Pay functions throw an error when the radius contains a semicolon or a curly brace.\n */\n borderRadius?: string;\n /**\n * Localized accessible label for the button. Defaults to `\"Buy with Shop Pay\"`.\n * Keep the brand name Shop Pay untranslated and in Latin script in every locale.\n *\n * @example English\n * `\"Buy with Shop Pay\"`\n *\n * @example Japanese\n * `\"Shop Payで購入\"`\n *\n * @example Hindi\n * `\"Shop Pay से खरीदें\"`\n *\n * @example Arabic\n * `\"الشراء باستخدام Shop Pay\"`\n */\n accessibilityLabel?: string;\n};\n\n/** A variant ID and an optional quantity for a Shop Pay checkout. */\ntype ShopPayVariantWithQuantity = {\n /** Product variant GID or numeric variant ID. Product IDs throw an error. */\n id: string;\n /** Quantity of the variant. Defaults to `1`. */\n quantity?: number;\n};\n\ntype ShopPayVariant = string | ShopPayVariantWithQuantity;\n/** Variants for a Shop Pay checkout, as all ID strings or all objects with an ID and a quantity. */\ntype ShopPayVariants = readonly string[] | readonly ShopPayVariantWithQuantity[];\n\n/** Checkout target, variants, attribution, and display settings for a Shop Pay button. */\nexport interface ShopPayButtonOptions extends ShopPayButtonBaseOptions {\n /**\n * Variants that the customer buys right away through a Shopify cart permalink. Omit the variants\n * to check out the current cart.\n *\n * Pass either all variant ID strings or all objects with an `id` and an optional `quantity`. Each quantity must be a positive integer. The Shop Pay functions throw an error for product IDs, non-numeric variant IDs, invalid quantities, and mixed formats.\n */\n variants?: ShopPayVariants;\n}\n\n/**\n * Returns the checkout URL for a Shop Pay button. Use the URL to build your own Shop Pay link.\n *\n * With variants, the URL is a cart permalink that checks out those variants. Without variants, the URL checks out the current cart.\n *\n * @param options The variants, checkout URL, payment mode, attribution, and disabled state for the checkout URL.\n * @returns The checkout URL, or `null` when `disabled` is `true`.\n * @publicDocs\n */\nexport function getShopPayButtonUrl(options: ShopPayButtonOptions): string | null {\n if (options.disabled) return null;\n\n const variants = getShopPayVariants(options);\n\n if (!options.checkoutUrl) {\n const search = getShopPaySearchParams(options);\n return `${variants ? `/cart/${variants}` : \"/checkout\"}?${search}`;\n }\n\n const url = variants\n ? getShopPayVariantModeUrl(options.checkoutUrl, variants)\n : getShopPayCheckoutModeUrl(options.checkoutUrl);\n\n for (const [name, value] of getShopPaySearchParams(options)) {\n url.searchParams.set(name, value);\n }\n\n return url.toString();\n}\n\n/**\n * Returns the Shop Pay button as an HTML string for server templates and frameworks without a Hydrogen binding.\n *\n * On the server, the markup includes the button's styles and link, and the button works without client JavaScript. In the browser, the function returns an empty element that renders the button when you add the element to the page.\n *\n * @param options The variants, checkout URL, and display settings for the button.\n * @returns The Shop Pay button markup.\n * @publicDocs\n */\nexport function renderShopPayButton(options: ShopPayButtonOptions): string {\n defineShopPayButton();\n const attributes = serializeAttributes(getShopPayButtonElementAttributes(options));\n const content = CAN_USE_DOM ? \"\" : getShopPayButtonDeclarativeShadowDomHtml(options);\n return `<${SHOP_PAY_BUTTON_TAG_NAME}${attributes ? ` ${attributes}` : \"\"}>${content}</${SHOP_PAY_BUTTON_TAG_NAME}>`;\n}\n\n/**\n * Creates a Shop Pay button element in the browser. Append the element to the page.\n *\n * The function requires a DOM. Use `renderShopPayButton` during server rendering.\n *\n * @param options The variants, checkout URL, and display settings for the button.\n * @returns The Shop Pay button element, ready to append to the page.\n * @publicDocs\n */\nexport function createShopPayButton(options: ShopPayButtonOptions): HTMLElement {\n defineShopPayButton();\n const element = document.createElement(SHOP_PAY_BUTTON_TAG_NAME);\n initializeShopPayButtonElement(element, options);\n\n return element;\n}\n\nexport function initializeShopPayButtonElement(\n element: HTMLElement,\n options: ShopPayButtonOptions,\n): void {\n syncShopPayButtonElementAttributes(element, getShopPayButtonElementAttributes(options));\n\n const shadowRoot = element.shadowRoot ?? element.attachShadow({ mode: \"open\" });\n const template = element.querySelector(\"template[shadowrootmode]\");\n\n if (template instanceof HTMLTemplateElement) {\n shadowRoot.append(template.content.cloneNode(true));\n template.remove();\n }\n\n renderShopPayButtonShadowRoot(shadowRoot, options);\n}\n\n/**\n * Registers the Shop Pay button custom element in the browser. Call the function when you use the `hydrogen-shop-pay-button` tag directly on a framework without a Hydrogen binding.\n *\n * The Hydrogen Shop Pay components, `createShopPayButton`, and `renderShopPayButton` register the element for you. The function does nothing during server rendering or when the browser already has the element.\n *\n * @returns Nothing.\n * @publicDocs\n */\nexport function defineShopPayButton(): void {\n if (\n typeof customElements === \"undefined\" ||\n typeof HTMLElement === \"undefined\" ||\n customElements.get(SHOP_PAY_BUTTON_TAG_NAME)\n ) {\n return;\n }\n\n customElements.define(\n SHOP_PAY_BUTTON_TAG_NAME,\n class extends HTMLElement {\n #connected = false;\n\n static observedAttributes = SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES;\n\n connectedCallback(): void {\n this.#connected = true;\n initializeShopPayButtonElement(this, getShopPayButtonOptions(this));\n }\n\n attributeChangedCallback(): void {\n if (!this.#connected || !this.shadowRoot) return;\n renderShopPayButtonShadowRoot(this.shadowRoot, getShopPayButtonOptions(this));\n }\n },\n );\n}\n\n/** Anchor attributes shared by server and browser shadow-root rendering. */\nexport function getShopPayButtonAnchorAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {\n class: SHOP_PAY_BUTTON_CLASS_NAME,\n target: \"_self\",\n };\n\n const href = getShopPayButtonUrl(options);\n if (href) {\n attributes.href = href;\n } else {\n attributes.role = \"link\";\n attributes[\"aria-disabled\"] = \"true\";\n }\n\n const style = serializeStyleProperties(getShopPayButtonStyleProperties(options));\n if (style) attributes.style = style;\n\n attributes[\"aria-label\"] = getShopPayAccessibilityLabel(options.accessibilityLabel);\n\n return attributes;\n}\n\nexport function getShopPayButtonElementContentHtml(options: ShopPayButtonOptions): string {\n return `<style${getShopPayButtonStyleNonceAttribute(options)}>${SHOP_PAY_BUTTON_STYLES}</style><a ${serializeAttributes(getShopPayButtonAnchorAttributes(options))}>${getShopPayButtonContentHtml()}</a>`;\n}\n\nexport function getShopPayButtonDeclarativeShadowDomHtml(options: ShopPayButtonOptions): string {\n return `<template shadowrootmode=\"open\" shadowroot=\"open\">${getShopPayButtonElementContentHtml(options)}</template>`;\n}\n\nexport function getShopPayButtonElementAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {};\n const variants = getShopPayVariants(options);\n\n if (hasContent(options.accessibilityLabel)) {\n attributes[\"accessibility-label\"] = options.accessibilityLabel.trim();\n }\n if (hasContent(options.borderRadius)) {\n attributes[\"border-radius\"] = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n if (options.channel) attributes.channel = options.channel;\n if (options.checkoutUrl !== undefined) attributes[\"checkout-url\"] = options.checkoutUrl;\n if (options.disabled) attributes.disabled = \"\";\n if (hasContent(options.nonce)) attributes.nonce = options.nonce.trim();\n if (options.paymentOption) attributes[\"payment-option\"] = options.paymentOption;\n if (options.source !== undefined) attributes.source = options.source;\n if (options.sourceToken !== undefined) attributes[\"source-token\"] = options.sourceToken;\n if (variants) attributes.variants = variants;\n if (hasContent(options.width)) {\n attributes.width = normalizeCssValue(\"width\", options.width);\n }\n\n return attributes;\n}\n\n/** Inner HTML for the shadow root's anchor. */\nexport function getShopPayButtonContentHtml(): string {\n return SHOP_PAY_LOGO_SVG;\n}\n\nfunction getShopPayButtonStyleProperties(\n options: Pick<ShopPayButtonOptions, \"width\" | \"borderRadius\">,\n): Record<string, string> {\n const style: Record<string, string> = {};\n\n if (hasContent(options.width)) style.width = normalizeCssValue(\"width\", options.width);\n if (hasContent(options.borderRadius)) {\n style.borderRadius = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n\n return style;\n}\n\nfunction getShopPaySearchParams(options: ShopPayButtonOptions): URLSearchParams {\n const params = new URLSearchParams();\n params.set(\"payment\", options.paymentOption ?? \"shop_pay\");\n\n const source = options.source ?? DEFAULT_SOURCE;\n if (source) params.set(\"source\", source);\n if (options.sourceToken) params.set(\"source_token\", options.sourceToken);\n if (options.channel) params.set(\"channel\", options.channel);\n\n return params;\n}\n\nfunction getShopPayCheckoutModeUrl(checkoutUrl: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n if (url.pathname === \"/\") url.pathname = \"/checkout\";\n url.hash = \"\";\n return url;\n}\n\nfunction getShopPayVariantModeUrl(checkoutUrl: string, variants: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n url.pathname = `/cart/${variants}`;\n url.hash = \"\";\n return url;\n}\n\nfunction parseCheckoutUrl(checkoutUrl: string): URL {\n try {\n return new URL(normalizeStoreDomain(checkoutUrl.trim()));\n } catch {\n throw shopPayError('Shop Pay requires a valid \"checkoutUrl\" value.');\n }\n}\n\nfunction getShopPayVariants(options: ShopPayButtonOptions): string | undefined {\n const variantsInput: readonly ShopPayVariant[] | undefined = options.variants;\n\n if (!Array.isArray(variantsInput) || variantsInput.length === 0) return undefined;\n\n if (variantsInput.every(isVariantId)) {\n return variantsInput.map((id) => `${normalizeVariantId(id)}:1`).join(\",\");\n }\n\n if (variantsInput.every(isVariantWithQuantity)) {\n return variantsInput\n .map(({ id, quantity }) => {\n return `${normalizeVariantId(id)}:${normalizeQuantity(quantity)}`;\n })\n .join(\",\");\n }\n\n throw shopPayError(\n \"Shop Pay variants must be either variant IDs or objects with an id and quantity.\",\n );\n}\n\nfunction isVariantId(variant: ShopPayVariant): variant is string {\n return typeof variant === \"string\";\n}\n\nfunction getShopPayButtonOptions(element: HTMLElement): ShopPayButtonOptions {\n return {\n accessibilityLabel: element.getAttribute(\"accessibility-label\") ?? undefined,\n borderRadius: element.getAttribute(\"border-radius\") ?? undefined,\n channel: parseChannel(element.getAttribute(\"channel\")),\n checkoutUrl: element.getAttribute(\"checkout-url\") ?? undefined,\n disabled: element.hasAttribute(\"disabled\"),\n nonce: element.nonce || element.getAttribute(\"nonce\") || undefined,\n paymentOption: parsePaymentOption(element.getAttribute(\"payment-option\")),\n source: element.getAttribute(\"source\") ?? undefined,\n sourceToken: element.getAttribute(\"source-token\") ?? undefined,\n variants: parseVariantsAttribute(element.getAttribute(\"variants\")),\n width: element.getAttribute(\"width\") ?? undefined,\n };\n}\n\nfunction parseVariantsAttribute(value: string | null): ShopPayVariants | undefined {\n if (!value) return undefined;\n\n return value.split(\",\").map((entry) => {\n const [id = \"\", quantity] = entry.split(\":\");\n return { id, quantity: quantity === undefined ? undefined : Number(quantity) };\n });\n}\n\nfunction parsePaymentOption(value: string | null): ShopPayButtonOptions[\"paymentOption\"] {\n return value === \"shop_pay\" || value === \"shop_pay_installments\" ? value : undefined;\n}\n\nfunction parseChannel(value: string | null): ShopPayButtonOptions[\"channel\"] {\n return value === \"headless\" || value === \"hydrogen\" ? value : undefined;\n}\n\nfunction renderShopPayButtonShadowRoot(\n shadowRoot: ShadowRoot,\n options: ShopPayButtonOptions,\n): void {\n let style = shadowRoot.querySelector(\"style\");\n if (!(style instanceof HTMLStyleElement)) {\n style = shadowRoot.ownerDocument.createElement(\"style\");\n shadowRoot.prepend(style);\n }\n\n const nextNonce = hasContent(options.nonce) ? options.nonce.trim() : undefined;\n const nonceChanged = (style.nonce || undefined) !== nextNonce;\n if (nextNonce) {\n style.nonce = nextNonce;\n } else {\n style.removeAttribute(\"nonce\");\n }\n if (nonceChanged) style.textContent = \"\";\n if (style.textContent !== SHOP_PAY_BUTTON_STYLES) style.textContent = SHOP_PAY_BUTTON_STYLES;\n\n let anchor = shadowRoot.querySelector(\"a\");\n if (!(anchor instanceof HTMLAnchorElement)) {\n anchor = shadowRoot.ownerDocument.createElement(\"a\");\n shadowRoot.append(anchor);\n }\n\n syncAttributes(anchor, getShopPayButtonAnchorAttributes(options));\n const content = getShopPayButtonContentHtml();\n if (anchor.innerHTML !== content) anchor.innerHTML = content;\n}\n\nfunction syncAttributes(element: Element, attributes: Record<string, string>): void {\n for (const name of element.getAttributeNames()) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction syncShopPayButtonElementAttributes(\n element: Element,\n attributes: Record<string, string>,\n): void {\n for (const name of SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction isVariantWithQuantity(\n variant: ShopPayVariant | undefined,\n): variant is ShopPayVariantWithQuantity {\n return typeof variant === \"object\" && variant !== null && typeof variant.id === \"string\";\n}\n\nfunction normalizeVariantId(id: string): string {\n const parsed = parseGid(id);\n const bareId = parsed.id || id.trim();\n\n if (parsed.resource && parsed.resource !== \"ProductVariant\") {\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n }\n\n if (/^\\d+$/.test(bareId)) return bareId;\n\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n}\n\nfunction normalizeQuantity(quantity = 1): number {\n if (!Number.isInteger(quantity) || quantity < 1) {\n throw shopPayError(\"Shop Pay variant quantities must be positive integers.\");\n }\n\n return quantity;\n}\n\nfunction escapeText(value: string): string {\n return value.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\");\n}\n\nfunction escapeAttribute(value: string): string {\n return escapeText(value).replace(/\"/g, \""\");\n}\n\nfunction getShopPayAccessibilityLabel(label: string | undefined): string {\n return hasContent(label) ? label.trim() : DEFAULT_ACCESSIBILITY_LABEL;\n}\n\nfunction getShopPayButtonStyleNonceAttribute(options: Pick<ShopPayButtonOptions, \"nonce\">): string {\n return hasContent(options.nonce) ? ` nonce=\"${escapeAttribute(options.nonce.trim())}\"` : \"\";\n}\n\nfunction hasContent(value: string | undefined): value is string {\n return typeof value === \"string\" && value.trim() !== \"\";\n}\n\nfunction normalizeCssValue(name: \"width\" | \"borderRadius\", value: string): string {\n const normalized = value.trim();\n if (/[;{}]/.test(normalized)) {\n throw shopPayError(`Shop Pay ${name} must be a single CSS value.`);\n }\n return normalized;\n}\n\nfunction serializeAttributes(attributes: Record<string, string>): string {\n return Object.entries(attributes)\n .map(([name, value]) => `${name}=\"${escapeAttribute(value)}\"`)\n .join(\" \");\n}\n\nfunction serializeStyleProperties(style: Record<string, string>): string {\n return Object.entries(style)\n .map(([name, value]) => `${hyphenateStyleName(name)}:${value}`)\n .join(\";\");\n}\n\nfunction hyphenateStyleName(name: string): string {\n return name.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);\n}\n\nfunction shopPayError(message: string): Error {\n return new Error(`${ERROR_PREFIX} ${message}`);\n}\n"],"mappings":";;;;AAGA,MAAM,iBAAiB;AACvB,MAAM,8BAA8B;AACpC,MAAM,eAAe;AACrB,MAAM,cAAc,OAAO,aAAa;;;;;;;;AAQxC,MAAa,2BAA2B;AACxC,MAAa,6BAA6B;AAC1C,MAAM,sCAAsC;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,yBACX,wBACI,2BAA2B,uRAC3B,2BAA2B,mCAC3B,2BAA2B,4DAC3B,2BAA2B,sEAC3B,2BAA2B;AAEjC,MAAM,oBACJ,eAAe,2BAA2B;;;;;;;;;;AA6G5C,SAAgB,oBAAoB,SAA8C;AAChF,KAAI,QAAQ,SAAU,QAAO;CAE7B,MAAM,WAAW,mBAAmB,QAAQ;AAE5C,KAAI,CAAC,QAAQ,aAAa;EACxB,MAAM,SAAS,uBAAuB,QAAQ;AAC9C,SAAO,GAAG,WAAW,SAAS,aAAa,YAAY,GAAG;;CAG5D,MAAM,MAAM,WACR,yBAAyB,QAAQ,aAAa,SAAS,GACvD,0BAA0B,QAAQ,YAAY;AAElD,MAAK,MAAM,CAAC,MAAM,UAAU,uBAAuB,QAAQ,CACzD,KAAI,aAAa,IAAI,MAAM,MAAM;AAGnC,QAAO,IAAI,UAAU;;;;;;;;;;;AAYvB,SAAgB,oBAAoB,SAAuC;AACzE,sBAAqB;CACrB,MAAM,aAAa,oBAAoB,kCAAkC,QAAQ,CAAC;CAClF,MAAM,UAAU,cAAc,KAAK,y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|
5
|
-
* Returns
|
|
5
|
+
* Returns Shopify's storefront script and link tags as descriptors.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Render the descriptors in the document head during server rendering, then call
|
|
8
|
+
* `initializeShopifyScripts` in the browser. Keep the tags in the returned order. The inline
|
|
9
|
+
* scripts set up globals that later scripts read.
|
|
10
|
+
*
|
|
11
|
+
* @param options - The shop details, the localization, the consent configuration, and the features whose scripts to load.
|
|
12
|
+
* @returns The link tags, the script tags, and a combined list with links first.
|
|
13
|
+
* @publicDocs
|
|
10
14
|
*/
|
|
11
15
|
declare function getShopifyScriptTags({
|
|
12
16
|
account,
|
|
@@ -20,7 +24,13 @@ declare function getShopifyScriptTags({
|
|
|
20
24
|
inbox
|
|
21
25
|
}: ShopifyScriptTagsOptions): ShopifyScriptTagDescriptors;
|
|
22
26
|
/**
|
|
23
|
-
* Renders
|
|
27
|
+
* Renders Shopify's storefront script and link tags to HTML strings.
|
|
28
|
+
*
|
|
29
|
+
* Use the function when your framework accepts raw HTML in the document head.
|
|
30
|
+
*
|
|
31
|
+
* @param options The shop details and the features, such as account and analytics, whose scripts to load.
|
|
32
|
+
* @returns One HTML string per tag, with link tags first.
|
|
33
|
+
* @publicDocs
|
|
24
34
|
*/
|
|
25
35
|
declare function renderShopifyScriptTags(options: ShopifyScriptTagsOptions): string[];
|
|
26
36
|
//#endregion
|
|
@@ -7,11 +7,15 @@ import { initializeShopifyScripts } from "./initialize.mjs";
|
|
|
7
7
|
|
|
8
8
|
//#region src/core/shopify-scripts/index.ts
|
|
9
9
|
/**
|
|
10
|
-
* Returns
|
|
10
|
+
* Returns Shopify's storefront script and link tags as descriptors.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Render the descriptors in the document head during server rendering, then call
|
|
13
|
+
* `initializeShopifyScripts` in the browser. Keep the tags in the returned order. The inline
|
|
14
|
+
* scripts set up globals that later scripts read.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The shop details, the localization, the consent configuration, and the features whose scripts to load.
|
|
17
|
+
* @returns The link tags, the script tags, and a combined list with links first.
|
|
18
|
+
* @publicDocs
|
|
15
19
|
*/
|
|
16
20
|
function getShopifyScriptTags({ account = false, analytics, consent, debug, i18n, nonce, shop, shopifyAnalytics = true, inbox = false }) {
|
|
17
21
|
const nonceAttributes = nonce !== void 0 ? { nonce } : void 0;
|
|
@@ -136,7 +140,13 @@ function getShopifyScriptTags({ account = false, analytics, consent, debug, i18n
|
|
|
136
140
|
};
|
|
137
141
|
}
|
|
138
142
|
/**
|
|
139
|
-
* Renders
|
|
143
|
+
* Renders Shopify's storefront script and link tags to HTML strings.
|
|
144
|
+
*
|
|
145
|
+
* Use the function when your framework accepts raw HTML in the document head.
|
|
146
|
+
*
|
|
147
|
+
* @param options The shop details and the features, such as account and analytics, whose scripts to load.
|
|
148
|
+
* @returns One HTML string per tag, with link tags first.
|
|
149
|
+
* @publicDocs
|
|
140
150
|
*/
|
|
141
151
|
function renderShopifyScriptTags(options) {
|
|
142
152
|
return getShopifyScriptTags(options).tags.map(renderShopifyScriptTag);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/index.ts"],"sourcesContent":["import { getShopifyAnalyticsBusScript, getShopifyAnalyticsConfig } from \"./analytics\";\nimport {\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_SCRIPT_ID,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n} from \"./constants\";\nimport { getShopifyGlobalBootstrapScript } from \"./global\";\nimport { getPerfKitScript } from \"./perfkit\";\nimport { renderShopifyScriptTag } from \"./render\";\nimport type {\n ShopifyLinkDescriptor,\n ShopifyScriptDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n} from \"./types\";\n\nexport {\n CONSENT_TRACKING_API_LOADED_EVENT,\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_PERF_KIT_SCRIPT,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n SHOPIFY_STOREFRONT_WEBMCP_SCRIPT,\n VISITOR_CONSENT_COLLECTED_EVENT,\n} from \"./constants\";\nexport { getShopifyGlobal, getShopifyGlobalBootstrapScript } from \"./global\";\nexport { initializeShopifyScripts } from \"./initialize\";\nexport { renderShopifyScriptTag } from \"./render\";\nexport type {\n ShopifyScriptsAnalyticsConfig,\n ShopifyRoutesOptions,\n ShopifyScriptTagDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n ShopifyScriptsOptions,\n ShopifyScriptsI18n,\n ShopifyScriptsShop,\n} from \"./types\";\n\n/**\n * Returns
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/index.ts"],"sourcesContent":["import { getShopifyAnalyticsBusScript, getShopifyAnalyticsConfig } from \"./analytics\";\nimport {\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_SCRIPT_ID,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n} from \"./constants\";\nimport { getShopifyGlobalBootstrapScript } from \"./global\";\nimport { getPerfKitScript } from \"./perfkit\";\nimport { renderShopifyScriptTag } from \"./render\";\nimport type {\n ShopifyLinkDescriptor,\n ShopifyScriptDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n} from \"./types\";\n\nexport {\n CONSENT_TRACKING_API_LOADED_EVENT,\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_PERF_KIT_SCRIPT,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n SHOPIFY_STOREFRONT_WEBMCP_SCRIPT,\n VISITOR_CONSENT_COLLECTED_EVENT,\n} from \"./constants\";\nexport { getShopifyGlobal, getShopifyGlobalBootstrapScript } from \"./global\";\nexport { initializeShopifyScripts } from \"./initialize\";\nexport { renderShopifyScriptTag } from \"./render\";\nexport type {\n ShopifyScriptsAnalyticsConfig,\n ShopifyRoutesOptions,\n ShopifyScriptTagDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n ShopifyScriptsOptions,\n ShopifyScriptsI18n,\n ShopifyScriptsShop,\n} from \"./types\";\n\n/**\n * Returns Shopify's storefront script and link tags as descriptors.\n *\n * Render the descriptors in the document head during server rendering, then call\n * `initializeShopifyScripts` in the browser. Keep the tags in the returned order. The inline\n * scripts set up globals that later scripts read.\n *\n * @param options - The shop details, the localization, the consent configuration, and the features whose scripts to load.\n * @returns The link tags, the script tags, and a combined list with links first.\n * @publicDocs\n */\n// oxlint-disable-next-line complexity -- ordered assembly of optional Shopify script tags; each flag adds one branch and splitting would obscure the required load order\nexport function getShopifyScriptTags({\n account = false,\n analytics,\n consent,\n debug,\n i18n,\n nonce,\n shop,\n shopifyAnalytics = true,\n inbox = false,\n}: ShopifyScriptTagsOptions): ShopifyScriptTagDescriptors {\n const nonceAttributes = nonce !== undefined ? { nonce } : undefined;\n const analyticsConfig = getShopifyAnalyticsConfig({ analytics, consent, shop });\n\n const links: ShopifyLinkDescriptor[] = [\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_CDN_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_SHOP_APP_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"prefetch\",\n as: \"script\",\n href: SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n crossorigin: \"anonymous\",\n },\n },\n ];\n const scripts: ShopifyScriptDescriptor[] = [\n {\n tagName: \"script\",\n attributes: { id: \"shopify-global-bootstrap\", ...nonceAttributes },\n innerHTML: getShopifyGlobalBootstrapScript({ i18n, shop }),\n },\n {\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-actions\",\n type: \"module\",\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n },\n },\n ];\n\n if (__DEV__ && debug?.standardEventsInspector) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-events-inspector\",\n defer: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n },\n });\n }\n\n if (inbox) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-inbox\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_INBOX_SCRIPT,\n },\n });\n }\n\n if (account) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-account\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_ACCOUNT_SCRIPT,\n },\n });\n }\n\n // Install readiness listeners before loading the async consent library so a\n // cached script cannot finish initialization before Hydrogen starts listening.\n scripts.push({\n tagName: \"script\",\n attributes: { id: \"shopify-analytics-bus\", ...nonceAttributes },\n innerHTML: getShopifyAnalyticsBusScript(analyticsConfig),\n });\n\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: SHOPIFY_CONSENT_SCRIPT_ID,\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src:\n consent?.mode === \"default-banner\"\n ? SHOPIFY_PRIVACY_BANNER_SCRIPT\n : SHOPIFY_CONSENT_API_SCRIPT,\n },\n });\n\n if (shopifyAnalytics) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-storefront-analytics\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n },\n });\n }\n\n const perfKitScript = getPerfKitScript(shop, nonceAttributes);\n if (perfKitScript) {\n scripts.push(perfKitScript);\n }\n\n return {\n links,\n scripts,\n get tags() {\n return [...links, ...scripts];\n },\n };\n}\n\n/**\n * Renders Shopify's storefront script and link tags to HTML strings.\n *\n * Use the function when your framework accepts raw HTML in the document head.\n *\n * @param options The shop details and the features, such as account and analytics, whose scripts to load.\n * @returns One HTML string per tag, with link tags first.\n * @publicDocs\n */\nexport function renderShopifyScriptTags(options: ShopifyScriptTagsOptions): string[] {\n return getShopifyScriptTags(options).tags.map(renderShopifyScriptTag);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,qBAAqB,EACnC,UAAU,OACV,WACA,SACA,OACA,MACA,OACA,MACA,mBAAmB,MACnB,QAAQ,SACgD;CACxD,MAAM,kBAAkB,UAAU,SAAY,EAAE,OAAO,GAAG;CAC1D,MAAM,kBAAkB,0BAA0B;EAAE;EAAW;EAAS;EAAM,CAAC;CAE/E,MAAM,QAAiC;EACrC;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,MAAM;IACP;GACF;EACD;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,MAAM;IACP;GACF;EACD;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,IAAI;IACJ,MAAM;IACN,aAAa;IACd;GACF;EACF;CACD,MAAM,UAAqC,CACzC;EACE,SAAS;EACT,YAAY;GAAE,IAAI;GAA4B,GAAG;GAAiB;EAClE,WAAW,gCAAgC;GAAE;GAAM;GAAM,CAAC;EAC3D,EACD;EACE,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CACF;AAED,KAAe,OAAO,wBACpB,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;AAGJ,KAAI,MACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;AAGJ,KAAI,QACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;AAKJ,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GAAE,IAAI;GAAyB,GAAG;GAAiB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