@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
package/dist/client/types.d.mts
CHANGED
|
@@ -5,106 +5,121 @@ import { AnyStorefrontQueryString, SourceOf, StorefrontQueryString } from "../gr
|
|
|
5
5
|
import { ResultOf, TadaDocumentNode, VariablesOf } from "gql.tada";
|
|
6
6
|
|
|
7
7
|
//#region src/client/types.d.ts
|
|
8
|
+
/** A document that the client's GraphQL method accepts, from `gql` or from `gql`.tada. */
|
|
8
9
|
type DocLike = TadaDocumentNode<any, any> | AnyStorefrontQueryString;
|
|
10
|
+
/** The typed document that Hydrogen infers from a plain query string. */
|
|
9
11
|
type InferredDoc<T extends string> = StorefrontQueryString<InferResult<T>, InferVariables<T>, T>;
|
|
12
|
+
/** The typed document for a GraphQL call. Hydrogen infers the types when you pass a plain query string. */
|
|
10
13
|
type ResolveDoc<D> = D extends DocLike ? D : D extends string ? InferredDoc<D> : never;
|
|
14
|
+
/** The query text of a document as a string literal type. A plain string resolves to itself. */
|
|
11
15
|
type SourceText<Doc> = [SourceOf<Doc>] extends [never] ? Doc extends string ? Doc : never : SourceOf<Doc>;
|
|
16
|
+
/** The operation kind of a document, such as `query`. Resolves to `unknown` when the query text isn't a string literal type. */
|
|
12
17
|
type OperationKindOfDoc<Doc> = [SourceText<Doc>] extends [never] ? "unknown" : string extends SourceText<Doc> ? "unknown" : InferOperationKind<SourceText<Doc>>;
|
|
18
|
+
/** Offers the `cache` option only for documents that TypeScript recognizes as queries. */
|
|
13
19
|
type GraphqlExtraOptionsForDoc<Doc, Extra extends Record<string, unknown>> = OperationKindOfDoc<Doc> extends "query" ? Extra : Omit<Extra, "cache">;
|
|
20
|
+
/** The result type of a `gql` document or a `gql`.tada document node. */
|
|
14
21
|
type ResultOfDoc<Doc> = Doc extends StorefrontQueryString<infer Result, infer _Variables, string> ? Result : Doc extends TadaDocumentNode<any, any> ? ResultOf<Doc> : never;
|
|
15
22
|
type VariablesOfDoc<Doc> = Doc extends StorefrontQueryString<infer _Result, infer Variables, string> ? Variables : Doc extends TadaDocumentNode<any, any> ? VariablesOf<Doc> : never;
|
|
16
23
|
type StorefrontApiResultOf<Doc extends DocLike> = ResultOf<Doc>;
|
|
17
24
|
type StorefrontApiVariablesOf<Doc extends DocLike> = VariablesOf<Doc>;
|
|
18
25
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* Present on the `errors` arm of {@link StorefrontGraphqlResult}.
|
|
26
|
+
* A GraphQL error from the Storefront API. The result of a GraphQL call lists GraphQL errors
|
|
27
|
+
* in its `errors` field.
|
|
23
28
|
*/
|
|
24
29
|
interface GraphQLFormattedError {
|
|
25
|
-
/**
|
|
30
|
+
/** The error message. */
|
|
26
31
|
readonly message: string;
|
|
27
|
-
/**
|
|
32
|
+
/** The lines and columns in the query where the error occurs. */
|
|
28
33
|
readonly locations?: ReadonlyArray<{
|
|
29
34
|
line: number;
|
|
30
35
|
column: number;
|
|
31
36
|
}>;
|
|
32
|
-
/**
|
|
37
|
+
/** The path to the response field that failed. */
|
|
33
38
|
readonly path?: ReadonlyArray<string | number>;
|
|
34
|
-
/**
|
|
39
|
+
/** Extra details that the Storefront API adds to the error. */
|
|
35
40
|
readonly extensions?: Record<string, unknown>;
|
|
36
41
|
}
|
|
37
42
|
type CommonOptions = {
|
|
38
|
-
/** Shopify store domain — e.g. `"my-store.myshopify.com"`. Normalized internally. */storeDomain: string;
|
|
39
43
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
44
|
+
* Your store's domain, such as `my-store.myshopify.com`. Hydrogen adds `https://` when the
|
|
45
|
+
* domain has no protocol, and removes trailing slashes. `createStorefrontClient` throws an error
|
|
46
|
+
* for an empty domain.
|
|
47
|
+
*/
|
|
48
|
+
storeDomain: string;
|
|
49
|
+
/**
|
|
50
|
+
* Your Hydrogen storefront's ID. The client sends the ID in the `Shopify-Storefront-Id` header
|
|
51
|
+
* of every request.
|
|
42
52
|
*/
|
|
43
53
|
storefrontId?: string;
|
|
44
54
|
/**
|
|
45
|
-
* Storefront API version
|
|
46
|
-
*
|
|
47
|
-
* version
|
|
48
|
-
*
|
|
49
|
-
|
|
55
|
+
* The Storefront API version that the client queries. Defaults to the version that Hydrogen
|
|
56
|
+
* bundles. To send some queries to another version, such as `unstable`, create a second client
|
|
57
|
+
* with that version. Type inference always uses Hydrogen's bundled schema. Write your own types
|
|
58
|
+
* for fields outside the bundled schema.
|
|
59
|
+
*/
|
|
60
|
+
apiVersion?: string;
|
|
61
|
+
/**
|
|
62
|
+
* How long a request can run before the client throws a `StorefrontTimeoutError`, in
|
|
63
|
+
* milliseconds. Defaults to `30000`. Set `0` to turn off the timeout. Stale-while-revalidate
|
|
64
|
+
* refreshes use the same timeout, or 30,000 when the timeout is `0`. `createStorefrontClient`
|
|
65
|
+
* throws an error for a negative value.
|
|
50
66
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
defaultTimeoutInMs?: number;
|
|
68
|
+
/**
|
|
69
|
+
* The cache that stores query results. The client caches only queries that pass a `cache`
|
|
70
|
+
* strategy. The client never caches mutations or results with GraphQL errors.
|
|
71
|
+
*/
|
|
72
|
+
cache?: CacheInstance; /** Keeps the runtime alive while the client writes to the cache in the background, such as a worker's `waitUntil` function. Without the function, each cached query waits for its cache write before it resolves. */
|
|
54
73
|
waitUntil?: WaitUntil;
|
|
55
74
|
};
|
|
75
|
+
/** A fetch function, or any function with a compatible signature that resolves to a `Response`. */
|
|
56
76
|
type AnyFetch = typeof globalThis.fetch | ((...args: never[]) => Promise<Response>);
|
|
57
77
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
78
|
+
* Options for a public client, which runs in the browser or a mobile app. Pass a public access
|
|
79
|
+
* token, or omit the token for tokenless access.
|
|
60
80
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* product tags, metaobjects, metafields, menus, and customers.
|
|
81
|
+
* Tokenless access can't read some Storefront API fields, including product tags, metaobjects,
|
|
82
|
+
* metafields, menus, and customers.
|
|
64
83
|
*/
|
|
65
84
|
interface PublicClientOptions<Fetch extends AnyFetch | undefined = typeof globalThis.fetch> extends CommonOptions {
|
|
66
|
-
/**
|
|
85
|
+
/** The fetch function that the client calls. Defaults to `globalThis.fetch`. `createStorefrontClient` throws an error when neither exists. */
|
|
67
86
|
fetch?: Fetch;
|
|
68
|
-
/**
|
|
87
|
+
/** Your public Storefront API access token. Omit the token for tokenless access. `createStorefrontClient` throws an error for an empty string. */
|
|
69
88
|
publicStorefrontToken?: string | undefined;
|
|
70
89
|
}
|
|
71
90
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* Best for: SSR/server-side requests where you control the fetch
|
|
77
|
-
* layer and can forward trusted buyer context.
|
|
78
|
-
* Token-based access is required for some Storefront API fields, including
|
|
79
|
-
* product tags, metaobjects, metafields, menus, and customers.
|
|
91
|
+
* Options for a private client, which runs during server-side rendering and forwards the
|
|
92
|
+
* customer's IP address to the Storefront API. Set `buyerIp` on the request context before you
|
|
93
|
+
* create the client.
|
|
80
94
|
*/
|
|
81
95
|
interface PrivateClientOptions<Fetch extends AnyFetch | undefined = typeof globalThis.fetch> extends CommonOptions {
|
|
82
|
-
/**
|
|
96
|
+
/** The fetch function that the client calls. Defaults to `globalThis.fetch`. `createStorefrontClient` throws an error when neither exists. */
|
|
83
97
|
fetch?: Fetch;
|
|
84
|
-
/**
|
|
98
|
+
/** Your private Storefront API access token. Keep the token out of browser code. `createStorefrontClient` throws an error when the token is missing. */
|
|
85
99
|
privateStorefrontToken: string;
|
|
86
100
|
}
|
|
87
101
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* Best for: background jobs, webhooks, or server contexts where no
|
|
92
|
-
* shopper identity is available.
|
|
102
|
+
* Options for a private client without buyer context, for background jobs, webhooks, and other
|
|
103
|
+
* server code with no customer. The client sends a private access token and no customer IP address.
|
|
93
104
|
*/
|
|
94
105
|
interface PrivateNoBuyerContextClientOptions<Fetch extends AnyFetch | undefined = typeof globalThis.fetch> extends CommonOptions {
|
|
95
|
-
/**
|
|
106
|
+
/** The fetch function that the client calls. Defaults to `globalThis.fetch`. `createStorefrontClient` throws an error when neither exists. */
|
|
96
107
|
fetch?: Fetch;
|
|
97
|
-
/**
|
|
108
|
+
/** Your private Storefront API access token. Keep the token out of browser code. `createStorefrontClient` throws an error when the token is missing. */
|
|
98
109
|
privateStorefrontToken: string;
|
|
99
110
|
}
|
|
100
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* The store settings that you pass as `config` when you create a client. The options depend on the client type.
|
|
113
|
+
*
|
|
114
|
+
* @publicDocs
|
|
115
|
+
*/
|
|
101
116
|
type StorefrontClientOptions = PublicClientOptions | PrivateClientOptions | PrivateNoBuyerContextClientOptions;
|
|
102
117
|
/**
|
|
103
|
-
*
|
|
118
|
+
* The arguments for createStorefrontClient. Set `type` to choose the client, then pass a request
|
|
119
|
+
* context and the matching store settings.
|
|
104
120
|
*
|
|
105
|
-
*
|
|
106
|
-
* `
|
|
107
|
-
* and `"private_no_buyer_context"` requires a private token; `buyerIp` is not forwarded.
|
|
121
|
+
* A public client takes a public token or none. A private client takes a private token and a
|
|
122
|
+
* request context with `buyerIp`. A private client without buyer context takes a private token.
|
|
108
123
|
*/
|
|
109
124
|
type CreateStorefrontClientArgs<RequestContext extends ShopifyRequestContext = ShopifyRequestContext, Type extends ClientType = ClientType, CacheConfig extends CacheInstance | undefined = CacheInstance | undefined> = {
|
|
110
125
|
type: "public" & Type;
|
|
@@ -126,39 +141,41 @@ type CreateStorefrontClientArgs<RequestContext extends ShopifyRequestContext = S
|
|
|
126
141
|
};
|
|
127
142
|
};
|
|
128
143
|
type AutoAddedVariableNames = "country" | "language";
|
|
144
|
+
/** The variables that you pass for a document, without `country` and `language`. The client fills both from the request context. */
|
|
129
145
|
type UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, AutoAddedVariableNames>;
|
|
146
|
+
/** Resolves to `true` when an object type has no required keys. */
|
|
130
147
|
type HasNoRequiredKeys<T> = Record<string, never> extends T ? true : false;
|
|
131
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* Options that every Storefront API GraphQL call accepts.
|
|
150
|
+
*
|
|
151
|
+
* @publicDocs
|
|
152
|
+
*/
|
|
132
153
|
type StorefrontGraphqlOptions = {
|
|
133
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* Cancels the request when the signal aborts. The request context's signal and the client timeout
|
|
156
|
+
* also cancel the request. The signal doesn't cancel a stale-while-revalidate refresh.
|
|
157
|
+
*/
|
|
158
|
+
signal?: AbortSignal;
|
|
134
159
|
};
|
|
160
|
+
/** The options for a GraphQL call. The call needs `variables` only when the document declares a required variable. */
|
|
135
161
|
type MergedOptions<Doc extends DocLike, Extra extends Record<string, unknown>> = Extra & StorefrontGraphqlOptions & (HasNoRequiredKeys<UserVariables<Doc>> extends true ? {
|
|
136
162
|
variables?: UserVariables<Doc>;
|
|
137
163
|
} : {
|
|
138
164
|
variables: UserVariables<Doc>;
|
|
139
165
|
});
|
|
140
166
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* variables, or `[options?]` (optional) when all variables are optional or
|
|
145
|
-
* auto-injected (e.g. `$country`, `$language`).
|
|
167
|
+
* The options argument of a GraphQL call. Pass the options argument when the document declares a
|
|
168
|
+
* required variable. You can leave the options argument out when every variable is optional, or
|
|
169
|
+
* when the only required variables are `$country` and `$language`, which the client fills.
|
|
146
170
|
*/
|
|
147
171
|
type GqlRestParam<Doc extends DocLike, Extra extends Record<string, unknown> = {}> = HasNoRequiredKeys<MergedOptions<Doc, GraphqlExtraOptionsForDoc<Doc, Extra>>> extends true ? [options?: MergedOptions<Doc, GraphqlExtraOptionsForDoc<Doc, Extra>>] : [options: MergedOptions<Doc, GraphqlExtraOptionsForDoc<Doc, Extra>>];
|
|
148
172
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* Discriminated on `errors`:
|
|
173
|
+
* The result of a GraphQL call, with the data, any GraphQL errors, and the response headers. Check
|
|
174
|
+
* `errors` before you read `data`.
|
|
152
175
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* partial (field-level error absorbed by a nullable ancestor). Always
|
|
157
|
-
* inspect `errors` first.
|
|
158
|
-
*
|
|
159
|
-
* `Partial` is deliberately not used: a non-null `data` never has absent
|
|
160
|
-
* top-level keys — failures surface as `null` values already covered by the
|
|
161
|
-
* schema types.
|
|
176
|
+
* Without errors, `data` holds the full result, typed from your document. With errors, `data` is
|
|
177
|
+
* `null` after a request error or after a failed non-null field at the root. Otherwise, `data`
|
|
178
|
+
* holds a partial result, and `null` replaces each failed field or its nearest nullable parent.
|
|
162
179
|
*/
|
|
163
180
|
type StorefrontGraphqlResult<Doc extends DocLike> = {
|
|
164
181
|
data: ResultOfDoc<Doc>;
|
|
@@ -169,41 +186,73 @@ type StorefrontGraphqlResult<Doc extends DocLike> = {
|
|
|
169
186
|
errors: GraphQLFormattedError[];
|
|
170
187
|
headers: Headers;
|
|
171
188
|
};
|
|
172
|
-
/** Base callable signature of `StorefrontClient.graphql` without per-client extra options. Accepts a `gql()` document or a plain string. */
|
|
173
|
-
type StorefrontGraphql = <const Doc extends DocLike | string>(doc: Doc, ...options: GqlRestParam<ResolveDoc<Doc>>) => Promise<StorefrontGraphqlResult<ResolveDoc<Doc>>>;
|
|
174
|
-
type ClientType = /** Public access token or tokenless access. Best for: browser requests. */"public" /** Private token with trusted buyer context. Best for: SSR. */ | "private" /** Private token without buyer context. Best for: background jobs, webhooks. */ | "private_no_buyer_context";
|
|
175
189
|
/**
|
|
176
|
-
*
|
|
190
|
+
* Runs a Storefront API query or mutation. Pass a `gql` document or a plain query string.
|
|
191
|
+
*
|
|
192
|
+
* @publicDocs
|
|
193
|
+
*/
|
|
194
|
+
type StorefrontGraphql =
|
|
195
|
+
/**
|
|
196
|
+
* @param doc - The `gql` document or query string to run.
|
|
197
|
+
* @param options - The variables and abort signal for the call. Pass the options when the document declares a required variable.
|
|
198
|
+
* @returns The response data, any GraphQL errors, and the response headers.
|
|
199
|
+
*/
|
|
200
|
+
<const Doc extends DocLike | string>(doc: Doc, ...options: GqlRestParam<ResolveDoc<Doc>>) => Promise<StorefrontGraphqlResult<ResolveDoc<Doc>>>;
|
|
201
|
+
/**
|
|
202
|
+
* Chooses the kind of Storefront API client to create. Use `public` in the browser, with a public access token or none. Use `private` during server-side rendering, with a private token and the customer's IP address. Use `private_no_buyer_context` in background jobs and webhooks, with a private token and no customer.
|
|
177
203
|
*
|
|
178
|
-
*
|
|
179
|
-
|
|
204
|
+
* @publicDocs
|
|
205
|
+
*/
|
|
206
|
+
type ClientType = /** Runs in the browser with a public access token or none. */"public" /** Runs during server-side rendering with a private token and the customer's IP address. */ | "private" /** Runs in background jobs and webhooks with a private token and no customer. */ | "private_no_buyer_context";
|
|
207
|
+
/**
|
|
208
|
+
* A Storefront API client. Call `graphql()` with a document to run a query or mutation and get a
|
|
209
|
+
* typed result.
|
|
180
210
|
*/
|
|
181
211
|
type StorefrontClient<Extra extends Record<string, unknown> = {}, Type extends ClientType = ClientType, RequestContext extends ShopifyRequestContext = ShopifyRequestContext> = {
|
|
182
|
-
/**
|
|
212
|
+
/** The client type that you passed to `createStorefrontClient`. */type: Type; /** The country and language that the client sends for `$country` and `$language` variables. */
|
|
183
213
|
i18n: RequestContext["i18n"];
|
|
184
214
|
/**
|
|
185
|
-
*
|
|
215
|
+
* Runs a Storefront API query or mutation and returns a typed result. Pass a `gql` document or a
|
|
216
|
+
* plain query string. When the operation declares `$country` or `$language`, the client sets the
|
|
217
|
+
* variable from the request context and overrides any value you pass.
|
|
186
218
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
219
|
+
* The method throws an error when a query passes a `cache` strategy and the client has no cache,
|
|
220
|
+
* or when the strategy uses `private` mode. A catch block for `StorefrontApiError` doesn't catch
|
|
221
|
+
* this configuration error. To cache customer-specific data, use `createRunWithCache` with a key
|
|
222
|
+
* unique to the customer.
|
|
190
223
|
*/
|
|
191
|
-
graphql: <const Doc extends DocLike | string>(doc: Doc, ...options: GqlRestParam<ResolveDoc<Doc>, Extra>) => Promise<StorefrontGraphqlResult<ResolveDoc<Doc>>>; /**
|
|
192
|
-
apiUrl: string; /**
|
|
193
|
-
storeUrl: string; /**
|
|
194
|
-
storefrontId?: string; /** The request context
|
|
224
|
+
graphql: <const Doc extends DocLike | string>(doc: Doc, ...options: GqlRestParam<ResolveDoc<Doc>, Extra>) => Promise<StorefrontGraphqlResult<ResolveDoc<Doc>>>; /** The Storefront API GraphQL endpoint that the client calls. */
|
|
225
|
+
apiUrl: string; /** Your store's URL with its protocol, such as `https://my-store.myshopify.com`. */
|
|
226
|
+
storeUrl: string; /** The storefront ID from the client options. */
|
|
227
|
+
storefrontId?: string; /** The request context that you passed to `createStorefrontClient`. */
|
|
195
228
|
requestContext: RequestContext;
|
|
196
229
|
};
|
|
197
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* The type of a client that you create with `type: "public"`.
|
|
232
|
+
*
|
|
233
|
+
* @publicDocs
|
|
234
|
+
*/
|
|
198
235
|
type PublicStorefrontClient<Extra extends Record<string, unknown> = {}, RequestContext extends ShopifyRequestContext = ShopifyRequestContext> = StorefrontClient<Extra, "public", RequestContext>;
|
|
199
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* The type of a client that you create with `type: "private"`. The client's request context includes `buyerIp`.
|
|
238
|
+
*
|
|
239
|
+
* @publicDocs
|
|
240
|
+
*/
|
|
200
241
|
type PrivateStorefrontClient<Extra extends Record<string, unknown> = {}, RequestContext extends ShopifyRequestContextWithBuyerIp = ShopifyRequestContextWithBuyerIp> = StorefrontClient<Extra, "private", RequestContext>;
|
|
201
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* The type of a private client with the default request context. Use the type to annotate a private client without naming your request context type.
|
|
244
|
+
*
|
|
245
|
+
* @publicDocs
|
|
246
|
+
*/
|
|
202
247
|
type RequestScopedPrivateStorefrontClient<Extra extends Record<string, unknown> = {}> = PrivateStorefrontClient<Extra, ShopifyRequestContextWithBuyerIp>;
|
|
203
|
-
/**
|
|
248
|
+
/**
|
|
249
|
+
* The type of a client that you create with `type: "private_no_buyer_context"`, for background jobs and webhooks.
|
|
250
|
+
*
|
|
251
|
+
* @publicDocs
|
|
252
|
+
*/
|
|
204
253
|
type PrivateNoBuyerContextStorefrontClient<Extra extends Record<string, unknown> = {}, RequestContext extends ShopifyRequestContext = ShopifyRequestContext> = StorefrontClient<Extra, "private_no_buyer_context", RequestContext>;
|
|
205
254
|
/**
|
|
206
|
-
*
|
|
255
|
+
* Type helpers that read the result and variables types of a Storefront API document.
|
|
207
256
|
*
|
|
208
257
|
* @example
|
|
209
258
|
* ```ts
|
|
@@ -214,13 +263,14 @@ type PrivateNoBuyerContextStorefrontClient<Extra extends Record<string, unknown>
|
|
|
214
263
|
* type Product = StorefrontApi.ResultOf<typeof PRODUCT_QUERY>;
|
|
215
264
|
* type Vars = StorefrontApi.VariablesOf<typeof PRODUCT_QUERY>;
|
|
216
265
|
* ```
|
|
266
|
+
* @publicDocs
|
|
217
267
|
*/
|
|
218
268
|
declare namespace StorefrontApi {
|
|
219
|
-
/**
|
|
269
|
+
/** The result type of a document. */
|
|
220
270
|
type ResultOf<Doc extends DocLike> = StorefrontApiResultOf<Doc>;
|
|
221
|
-
/**
|
|
271
|
+
/** The variables type of a document. */
|
|
222
272
|
type VariablesOf<Doc extends DocLike> = StorefrontApiVariablesOf<Doc>;
|
|
223
|
-
/** A typed Storefront API document
|
|
273
|
+
/** A typed Storefront API document from `gql`, or a gql.tada document node. */
|
|
224
274
|
type DocumentNode = DocLike;
|
|
225
275
|
}
|
|
226
276
|
//#endregion
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import { CartStore } from "../cart/cart.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/analytics/cart-tracker.d.ts
|
|
4
|
+
/** A cart store, or any object with the cart store's `getState()` and `subscribe()` methods. */
|
|
4
5
|
type CartAnalyticsStore = Pick<CartStore, "getState" | "subscribe">;
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* Publishes cart analytics events when the server confirms a change to the customer's cart. In React, call `useCartAnalytics`.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
* `product_added_to_cart`
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* page loads and tabs). A store filled from your own cart query must select
|
|
13
|
-
* `updatedAt`, or deduplication can't work.
|
|
9
|
+
* The function publishes `cart_updated` when the cart's update time changes, plus
|
|
10
|
+
* `product_added_to_cart` or `product_removed_from_cart` for each added line, removed
|
|
11
|
+
* line, and quantity change. The function waits until no cart change or reload is in flight.
|
|
12
|
+
* Analytics payloads leave out cart lines without merchandise.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* The function stores the last published cart update in local storage under `cartLastUpdatedAt`
|
|
15
|
+
* to avoid repeat events across page loads and tabs. A store that you fill from your own cart query
|
|
16
|
+
* must select `updatedAt`. Without the update time, the function publishes on every confirmed cart state.
|
|
17
|
+
* The function also sets `window.Shopify.currency.active` to the cart's currency.
|
|
18
|
+
*
|
|
19
|
+
* The function throws when the Shopify analytics bus isn't available, including during server rendering.
|
|
20
|
+
* Render `ShopifyScripts`, then start tracking in a client-only effect, such as `useEffect` or `onMounted`.
|
|
21
|
+
*
|
|
22
|
+
* @param store The cart store to track.
|
|
23
|
+
* @throws {Error} If `window.Shopify.analytics` isn't set, including on the server.
|
|
24
|
+
* Render Shopify's script tags first.
|
|
25
|
+
* @returns A function that stops tracking.
|
|
26
|
+
* @publicDocs
|
|
18
27
|
*/
|
|
19
28
|
declare function trackCartAnalytics(store: CartAnalyticsStore): () => void;
|
|
20
29
|
//#endregion
|
|
@@ -3,18 +3,26 @@ import { flattenConnection } from "./utils/flatten-connection.mjs";
|
|
|
3
3
|
|
|
4
4
|
//#region src/core/analytics/cart-tracker.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Publishes cart analytics events when the server confirms a change to the customer's cart. In React, call `useCartAnalytics`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* `product_added_to_cart`
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* page loads and tabs). A store filled from your own cart query must select
|
|
13
|
-
* `updatedAt`, or deduplication can't work.
|
|
8
|
+
* The function publishes `cart_updated` when the cart's update time changes, plus
|
|
9
|
+
* `product_added_to_cart` or `product_removed_from_cart` for each added line, removed
|
|
10
|
+
* line, and quantity change. The function waits until no cart change or reload is in flight.
|
|
11
|
+
* Analytics payloads leave out cart lines without merchandise.
|
|
14
12
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* The function stores the last published cart update in local storage under `cartLastUpdatedAt`
|
|
14
|
+
* to avoid repeat events across page loads and tabs. A store that you fill from your own cart query
|
|
15
|
+
* must select `updatedAt`. Without the update time, the function publishes on every confirmed cart state.
|
|
16
|
+
* The function also sets `window.Shopify.currency.active` to the cart's currency.
|
|
17
|
+
*
|
|
18
|
+
* The function throws when the Shopify analytics bus isn't available, including during server rendering.
|
|
19
|
+
* Render `ShopifyScripts`, then start tracking in a client-only effect, such as `useEffect` or `onMounted`.
|
|
20
|
+
*
|
|
21
|
+
* @param store The cart store to track.
|
|
22
|
+
* @throws {Error} If `window.Shopify.analytics` isn't set, including on the server.
|
|
23
|
+
* Render Shopify's script tags first.
|
|
24
|
+
* @returns A function that stops tracking.
|
|
25
|
+
* @publicDocs
|
|
18
26
|
*/
|
|
19
27
|
function trackCartAnalytics(store) {
|
|
20
28
|
const analytics = getGlobalAnalytics();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart-tracker.mjs","names":[],"sources":["../../../src/core/analytics/cart-tracker.ts"],"sourcesContent":["import type { CartStore } from \"../cart/cart\";\nimport type { CartData, CartState } from \"../cart/state\";\nimport { AnalyticsEvent } from \"./events\";\nimport type {\n AnalyticsCart,\n AnalyticsCartLine,\n CartUpdatePayload,\n StorefrontAnalytics,\n} from \"./types\";\nimport { flattenConnection } from \"./utils/flatten-connection\";\n\ntype CartTrackerAnalytics = Pick<StorefrontAnalytics, \"publish\" | \"getConfig\">;\ntype CartAnalyticsStore = Pick<CartStore, \"getState\" | \"subscribe\">;\n\ntype CartStorage = {\n updatedAt: string;\n id: string;\n};\n\ntype CartTrackerState = {\n prevCart: AnalyticsCart | null;\n lastEventId: string | null;\n};\n\n/**\n * Subscribes to a cart store and publishes analytics events when the cart changes.\n *\n * Emits `cart_updated` whenever a settled cart's `updatedAt` changes, plus\n * `product_added_to_cart` / `product_removed_from_cart` for each line that was\n * added, removed, or changed quantity. Deduplicates on `updatedAt` with an\n * in-memory cursor (within this subscription) and `localStorage` (across full\n * page loads and tabs). A store filled from your own cart query must select\n * `updatedAt`, or deduplication can't work.\n *\n * @throws {Error} If `window.Shopify.analytics` is not set (including on the server).\n * Render `ShopifyScripts` (or the `getShopifyScriptTags()` output) first.\n * @returns An unsubscribe function that stops tracking.\n */\nexport function trackCartAnalytics(store: CartAnalyticsStore): () => void {\n const analytics = getGlobalAnalytics();\n const state: CartTrackerState = {\n prevCart: toAnalyticsCart(store.getState()),\n lastEventId: null,\n };\n\n if (state.prevCart) syncShopifyCurrency(state.prevCart);\n\n return store.subscribe((cartState) => {\n const cart = toAnalyticsCart(cartState);\n if (!cart) return;\n\n trackCartChange(analytics, state, cart);\n });\n}\n\nfunction trackCartChange(\n analytics: CartTrackerAnalytics,\n state: CartTrackerState,\n cart: AnalyticsCart,\n): void {\n if (!cart || !cart.updatedAt) return;\n\n syncShopifyCurrency(cart);\n\n if (cart.updatedAt === state.prevCart?.updatedAt) return;\n\n let cartLastUpdatedAt: CartStorage | null;\n try {\n cartLastUpdatedAt = JSON.parse(localStorage.getItem(\"cartLastUpdatedAt\") || \"\");\n } catch {\n cartLastUpdatedAt = null;\n }\n\n if (cart.id === cartLastUpdatedAt?.id && cart.updatedAt === cartLastUpdatedAt?.updatedAt) {\n state.prevCart = cart;\n return;\n }\n\n if (cart.updatedAt === state.lastEventId) return;\n state.lastEventId = cart.updatedAt;\n\n const config = analytics.getConfig();\n const payload: CartUpdatePayload = {\n eventTimestamp: Date.now(),\n cart,\n prevCart: state.prevCart,\n shop: config.shop,\n customData: config.customData,\n };\n\n analytics.publish(AnalyticsEvent.CART_UPDATED, payload);\n\n try {\n localStorage.setItem(\n \"cartLastUpdatedAt\",\n JSON.stringify({ id: cart.id, updatedAt: cart.updatedAt }),\n );\n } catch {\n // Safari private browsing or storage quota exceeded; analytics\n // deduplication will rely on in-memory prevCart only for this session.\n }\n\n const previousCartLines = flattenConnection<AnalyticsCartLine>(state.prevCart?.lines);\n const currentCartLines = flattenConnection<AnalyticsCartLine>(cart.lines);\n\n previousCartLines.forEach((prevLine) => {\n const matchedLineId = currentCartLines.filter((line) => prevLine.id === line.id);\n if (matchedLineId.length === 1) {\n const matchedLine = matchedLineId[0];\n if (prevLine.quantity < matchedLine.quantity) {\n analytics.publish(AnalyticsEvent.PRODUCT_ADD_TO_CART, {\n ...payload,\n prevLine,\n currentLine: matchedLine,\n });\n } else if (prevLine.quantity > matchedLine.quantity) {\n analytics.publish(AnalyticsEvent.PRODUCT_REMOVED_FROM_CART, {\n ...payload,\n prevLine,\n currentLine: matchedLine,\n });\n }\n } else {\n analytics.publish(AnalyticsEvent.PRODUCT_REMOVED_FROM_CART, {\n ...payload,\n prevLine,\n });\n }\n });\n\n currentCartLines.forEach((line) => {\n const matchedLineId = previousCartLines.filter((previousLine) => line.id === previousLine.id);\n if (!matchedLineId || matchedLineId.length === 0) {\n analytics.publish(AnalyticsEvent.PRODUCT_ADD_TO_CART, {\n ...payload,\n currentLine: line,\n });\n }\n });\n\n state.prevCart = cart;\n}\n\nfunction getGlobalAnalytics(): CartTrackerAnalytics {\n const analytics = typeof window !== \"undefined\" ? window.Shopify?.analytics : undefined;\n if (!analytics) {\n throw new Error(\n \"Shopify analytics bus is not available. Render ShopifyScripts before calling trackCartAnalytics().\",\n );\n }\n\n return analytics;\n}\n\nfunction toAnalyticsCart(state: CartState): AnalyticsCart | null {\n const cart = state.data;\n if (!cart.id || hasPendingCartWork(state)) return null;\n\n return {\n id: cart.id,\n updatedAt: getCartUpdatedAt(cart),\n cost: cart.cost,\n lines: {\n nodes: cart.lines.nodes.flatMap((line): AnalyticsCartLine[] => {\n const merchandise = line.merchandise;\n if (!merchandise) return [];\n\n const product = merchandise.product;\n const productId = typeof product.id === \"string\" ? product.id : \"\";\n const vendor = typeof product.vendor === \"string\" ? product.vendor : \"\";\n const productType =\n typeof product.productType === \"string\" ? product.productType : undefined;\n\n return [\n {\n id: line.id,\n quantity: line.quantity,\n merchandise: {\n id: merchandise.id,\n title: merchandise.title ?? product.title,\n price: line.cost.amountPerQuantity,\n sku: typeof merchandise.sku === \"string\" ? merchandise.sku : null,\n product: {\n id: productId,\n title: product.title,\n vendor,\n productType,\n handle: product.handle,\n },\n },\n },\n ];\n }),\n },\n };\n}\n\nfunction hasPendingCartWork({ pending, revalidating }: CartState): boolean {\n const hasPendingCost = pending.cost ?? (pending.lines.size > 0 || pending.discountCodes.size > 0);\n return revalidating === true || hasPendingCost || pending.note || pending.attributes;\n}\n\nfunction getCartUpdatedAt(cart: CartData): string {\n return cart.updatedAt ?? new Date().toISOString();\n}\n\nfunction syncShopifyCurrency(cart: AnalyticsCart): void {\n if (typeof window === \"undefined\") return;\n\n const currencyCode = getCartCurrencyCode(cart);\n if (!currencyCode) return;\n\n const normalizedCurrencyCode = currencyCode.toUpperCase();\n const shopifyWindow: { Shopify?: { currency?: { active: string } } } = window;\n const shopify = (shopifyWindow.Shopify ??= {});\n if (shopify.currency?.active === normalizedCurrencyCode) return;\n\n shopify.currency = { active: normalizedCurrencyCode };\n}\n\nfunction getCartCurrencyCode(cart: AnalyticsCart): string | undefined {\n return (\n nonEmptyCurrencyCode(cart.cost?.totalAmount?.currencyCode) ??\n nonEmptyCurrencyCode(cart.cost?.subtotalAmount?.currencyCode) ??\n flattenConnection<AnalyticsCartLine>(cart.lines).find(\n (line) => line.merchandise.price.currencyCode,\n )?.merchandise.price.currencyCode\n );\n}\n\nfunction nonEmptyCurrencyCode(currencyCode: string | undefined): string | undefined {\n return currencyCode || undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsCA,SAAgB,mBAAmB,OAAuC;CACxE,MAAM,YAAY,oBAAoB;CACtC,MAAM,QAA0B;EAC9B,UAAU,gBAAgB,MAAM,UAAU,CAAC;EAC3C,aAAa;EACd;AAED,KAAI,MAAM,SAAU,qBAAoB,MAAM,SAAS;AAEvD,QAAO,MAAM,WAAW,cAAc;EACpC,MAAM,OAAO,gBAAgB,UAAU;AACvC,MAAI,CAAC,KAAM;AAEX,kBAAgB,WAAW,OAAO,KAAK;GACvC;;AAGJ,SAAS,gBACP,WACA,OACA,MACM;AACN,KAAI,CAAC,QAAQ,CAAC,KAAK,UAAW;AAE9B,qBAAoB,KAAK;AAEzB,KAAI,KAAK,cAAc,MAAM,UAAU,UAAW;CAElD,IAAI;AACJ,KAAI;AACF,sBAAoB,KAAK,MAAM,aAAa,QA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nC,MAAM,eAAe,oBAAoB,KAAK;AAC9C,KAAI,CAAC,aAAc;CAEnB,MAAM,yBAAyB,aAAa,aAAa;CACzD,MAAM,gBAAiE;CACvE,MAAM,UAAW,cAAc,YAAY,EAAE;AAC7C,KAAI,QAAQ,UAAU,WAAW,uBAAwB;AAEzD,SAAQ,WAAW,EAAE,QAAQ,wBAAwB;;AAGvD,SAAS,oBAAoB,MAAyC;AACpE,QACE,qBAAqB,KAAK,MAAM,aAAa,aAAa,IAC1D,qBAAqB,KAAK,MAAM,gBAAgB,aAAa,IAC7D,kBAAqC,KAAK,MAAM,CAAC,MAC9C,SAAS,KAAK,YAAY,MAAM,aAClC,EAAE,YAAY,MAAM;;AAIzB,SAAS,qBAAqB,cAAsD;AAClF,QAAO,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"cart-tracker.mjs","names":[],"sources":["../../../src/core/analytics/cart-tracker.ts"],"sourcesContent":["import type { CartStore } from \"../cart/cart\";\nimport type { CartData, CartState } from \"../cart/state\";\nimport { AnalyticsEvent } from \"./events\";\nimport type {\n AnalyticsCart,\n AnalyticsCartLine,\n CartUpdatePayload,\n StorefrontAnalytics,\n} from \"./types\";\nimport { flattenConnection } from \"./utils/flatten-connection\";\n\ntype CartTrackerAnalytics = Pick<StorefrontAnalytics, \"publish\" | \"getConfig\">;\n/** A cart store, or any object with the cart store's `getState()` and `subscribe()` methods. */\ntype CartAnalyticsStore = Pick<CartStore, \"getState\" | \"subscribe\">;\n\ntype CartStorage = {\n updatedAt: string;\n id: string;\n};\n\ntype CartTrackerState = {\n prevCart: AnalyticsCart | null;\n lastEventId: string | null;\n};\n\n/**\n * Publishes cart analytics events when the server confirms a change to the customer's cart. In React, call `useCartAnalytics`.\n *\n * The function publishes `cart_updated` when the cart's update time changes, plus\n * `product_added_to_cart` or `product_removed_from_cart` for each added line, removed\n * line, and quantity change. The function waits until no cart change or reload is in flight.\n * Analytics payloads leave out cart lines without merchandise.\n *\n * The function stores the last published cart update in local storage under `cartLastUpdatedAt`\n * to avoid repeat events across page loads and tabs. A store that you fill from your own cart query\n * must select `updatedAt`. Without the update time, the function publishes on every confirmed cart state.\n * The function also sets `window.Shopify.currency.active` to the cart's currency.\n *\n * The function throws when the Shopify analytics bus isn't available, including during server rendering.\n * Render `ShopifyScripts`, then start tracking in a client-only effect, such as `useEffect` or `onMounted`.\n *\n * @param store The cart store to track.\n * @throws {Error} If `window.Shopify.analytics` isn't set, including on the server.\n * Render Shopify's script tags first.\n * @returns A function that stops tracking.\n * @publicDocs\n */\nexport function trackCartAnalytics(store: CartAnalyticsStore): () => void {\n const analytics = getGlobalAnalytics();\n const state: CartTrackerState = {\n prevCart: toAnalyticsCart(store.getState()),\n lastEventId: null,\n };\n\n if (state.prevCart) syncShopifyCurrency(state.prevCart);\n\n return store.subscribe((cartState) => {\n const cart = toAnalyticsCart(cartState);\n if (!cart) return;\n\n trackCartChange(analytics, state, cart);\n });\n}\n\nfunction trackCartChange(\n analytics: CartTrackerAnalytics,\n state: CartTrackerState,\n cart: AnalyticsCart,\n): void {\n if (!cart || !cart.updatedAt) return;\n\n syncShopifyCurrency(cart);\n\n if (cart.updatedAt === state.prevCart?.updatedAt) return;\n\n let cartLastUpdatedAt: CartStorage | null;\n try {\n cartLastUpdatedAt = JSON.parse(localStorage.getItem(\"cartLastUpdatedAt\") || \"\");\n } catch {\n cartLastUpdatedAt = null;\n }\n\n if (cart.id === cartLastUpdatedAt?.id && cart.updatedAt === cartLastUpdatedAt?.updatedAt) {\n state.prevCart = cart;\n return;\n }\n\n if (cart.updatedAt === state.lastEventId) return;\n state.lastEventId = cart.updatedAt;\n\n const config = analytics.getConfig();\n const payload: CartUpdatePayload = {\n eventTimestamp: Date.now(),\n cart,\n prevCart: state.prevCart,\n shop: config.shop,\n customData: config.customData,\n };\n\n analytics.publish(AnalyticsEvent.CART_UPDATED, payload);\n\n try {\n localStorage.setItem(\n \"cartLastUpdatedAt\",\n JSON.stringify({ id: cart.id, updatedAt: cart.updatedAt }),\n );\n } catch {\n // Safari private browsing or storage quota exceeded; analytics\n // deduplication will rely on in-memory prevCart only for this session.\n }\n\n const previousCartLines = flattenConnection<AnalyticsCartLine>(state.prevCart?.lines);\n const currentCartLines = flattenConnection<AnalyticsCartLine>(cart.lines);\n\n previousCartLines.forEach((prevLine) => {\n const matchedLineId = currentCartLines.filter((line) => prevLine.id === line.id);\n if (matchedLineId.length === 1) {\n const matchedLine = matchedLineId[0];\n if (prevLine.quantity < matchedLine.quantity) {\n analytics.publish(AnalyticsEvent.PRODUCT_ADD_TO_CART, {\n ...payload,\n prevLine,\n currentLine: matchedLine,\n });\n } else if (prevLine.quantity > matchedLine.quantity) {\n analytics.publish(AnalyticsEvent.PRODUCT_REMOVED_FROM_CART, {\n ...payload,\n prevLine,\n currentLine: matchedLine,\n });\n }\n } else {\n analytics.publish(AnalyticsEvent.PRODUCT_REMOVED_FROM_CART, {\n ...payload,\n prevLine,\n });\n }\n });\n\n currentCartLines.forEach((line) => {\n const matchedLineId = previousCartLines.filter((previousLine) => line.id === previousLine.id);\n if (!matchedLineId || matchedLineId.length === 0) {\n analytics.publish(AnalyticsEvent.PRODUCT_ADD_TO_CART, {\n ...payload,\n currentLine: line,\n });\n }\n });\n\n state.prevCart = cart;\n}\n\nfunction getGlobalAnalytics(): CartTrackerAnalytics {\n const analytics = typeof window !== \"undefined\" ? window.Shopify?.analytics : undefined;\n if (!analytics) {\n throw new Error(\n \"Shopify analytics bus is not available. Render ShopifyScripts before calling trackCartAnalytics().\",\n );\n }\n\n return analytics;\n}\n\nfunction toAnalyticsCart(state: CartState): AnalyticsCart | null {\n const cart = state.data;\n if (!cart.id || hasPendingCartWork(state)) return null;\n\n return {\n id: cart.id,\n updatedAt: getCartUpdatedAt(cart),\n cost: cart.cost,\n lines: {\n nodes: cart.lines.nodes.flatMap((line): AnalyticsCartLine[] => {\n const merchandise = line.merchandise;\n if (!merchandise) return [];\n\n const product = merchandise.product;\n const productId = typeof product.id === \"string\" ? product.id : \"\";\n const vendor = typeof product.vendor === \"string\" ? product.vendor : \"\";\n const productType =\n typeof product.productType === \"string\" ? product.productType : undefined;\n\n return [\n {\n id: line.id,\n quantity: line.quantity,\n merchandise: {\n id: merchandise.id,\n title: merchandise.title ?? product.title,\n price: line.cost.amountPerQuantity,\n sku: typeof merchandise.sku === \"string\" ? merchandise.sku : null,\n product: {\n id: productId,\n title: product.title,\n vendor,\n productType,\n handle: product.handle,\n },\n },\n },\n ];\n }),\n },\n };\n}\n\nfunction hasPendingCartWork({ pending, revalidating }: CartState): boolean {\n const hasPendingCost = pending.cost ?? (pending.lines.size > 0 || pending.discountCodes.size > 0);\n return revalidating === true || hasPendingCost || pending.note || pending.attributes;\n}\n\nfunction getCartUpdatedAt(cart: CartData): string {\n return cart.updatedAt ?? new Date().toISOString();\n}\n\nfunction syncShopifyCurrency(cart: AnalyticsCart): void {\n if (typeof window === \"undefined\") return;\n\n const currencyCode = getCartCurrencyCode(cart);\n if (!currencyCode) return;\n\n const normalizedCurrencyCode = currencyCode.toUpperCase();\n const shopifyWindow: { Shopify?: { currency?: { active: string } } } = window;\n const shopify = (shopifyWindow.Shopify ??= {});\n if (shopify.currency?.active === normalizedCurrencyCode) return;\n\n shopify.currency = { active: normalizedCurrencyCode };\n}\n\nfunction getCartCurrencyCode(cart: AnalyticsCart): string | undefined {\n return (\n nonEmptyCurrencyCode(cart.cost?.totalAmount?.currencyCode) ??\n nonEmptyCurrencyCode(cart.cost?.subtotalAmount?.currencyCode) ??\n flattenConnection<AnalyticsCartLine>(cart.lines).find(\n (line) => line.merchandise.price.currencyCode,\n )?.merchandise.price.currencyCode\n );\n}\n\nfunction nonEmptyCurrencyCode(currencyCode: string | undefined): string | undefined {\n return currencyCode || undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,mBAAmB,OAAuC;CACxE,MAAM,YAAY,oBAAoB;CACtC,MAAM,QAA0B;EAC9B,UAAU,gBAAgB,MAAM,UAAU,CAAC;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;MACf;MACA;MACA,QAAQ,QAAQ;MACjB;KACF;IACF,CACF;IACD,EACH;EACF;;AAGH,SAAS,mBAAmB,EAAE,SAAS,gBAAoC;CACzE,MAAM,iBAAiB,QAAQ,SAAS,QAAQ,MAAM,OAAO,KAAK,QAAQ,cAAc,OAAO;AAC/F,QAAO,iBAAiB,QAAQ,kBAAkB,QAAQ,QAAQ,QAAQ;;AAG5E,SAAS,iBAAiB,MAAwB;AAChD,QAAO,KAAK,8BAAa,IAAI,MAAM,EAAC,aAAa;;AAGnD,SAAS,oBAAoB,MAA2B;AACtD,KAAI,OAAO,WAAW,YAAa;CAEnC,MAAM,eAAe,oBAAoB,KAAK;AAC9C,KAAI,CAAC,aAAc;CAEnB,MAAM,yBAAyB,aAAa,aAAa;CACzD,MAAM,gBAAiE;CACvE,MAAM,UAAW,cAAc,YAAY,EAAE;AAC7C,KAAI,QAAQ,UAAU,WAAW,uBAAwB;AAEzD,SAAQ,WAAW,EAAE,QAAQ,wBAAwB;;AAGvD,SAAS,oBAAoB,MAAyC;AACpE,QACE,qBAAqB,KAAK,MAAM,aAAa,aAAa,IAC1D,qBAAqB,KAAK,MAAM,gBAAgB,aAAa,IAC7D,kBAAqC,KAAK,MAAM,CAAC,MAC9C,SAAS,KAAK,YAAY,MAAM,aAClC,EAAE,YAAY,MAAM;;AAIzB,SAAS,qBAAqB,cAAsD;AAClF,QAAO,gBAAgB"}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
//#region src/core/analytics/events.d.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The names of the analytics events that Hydrogen supports.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Pass a constant as the event name when you publish an event or subscribe a destination.
|
|
6
|
+
* TypeScript narrows the payload to match the event name.
|
|
7
|
+
*
|
|
8
|
+
* @publicDocs
|
|
8
9
|
*/
|
|
9
10
|
declare const AnalyticsEvent: {
|
|
10
|
-
PAGE_VIEWED: "page_viewed";
|
|
11
|
-
PRODUCT_VIEWED: "product_viewed";
|
|
12
|
-
COLLECTION_VIEWED: "collection_viewed";
|
|
13
|
-
CART_VIEWED: "cart_viewed";
|
|
14
|
-
SEARCH_VIEWED: "search_viewed";
|
|
15
|
-
CART_UPDATED: "cart_updated";
|
|
16
|
-
PRODUCT_ADD_TO_CART: "product_added_to_cart";
|
|
11
|
+
/** Publish when a customer views a page. Hydrogen fills in the current URL when the payload has none. */PAGE_VIEWED: "page_viewed"; /** Publish when a customer views a product. The payload lists the viewed products. */
|
|
12
|
+
PRODUCT_VIEWED: "product_viewed"; /** Publish when a customer views a collection. The payload identifies the collection by ID and handle. */
|
|
13
|
+
COLLECTION_VIEWED: "collection_viewed"; /** Publish when a customer views the cart. The payload carries the current cart. */
|
|
14
|
+
CART_VIEWED: "cart_viewed"; /** Publish when a customer views search results. The payload carries the search term. */
|
|
15
|
+
SEARCH_VIEWED: "search_viewed"; /** Cart tracking publishes this event when the cart changes. */
|
|
16
|
+
CART_UPDATED: "cart_updated"; /** Cart tracking publishes this event when the customer adds a line or raises a line's quantity. */
|
|
17
|
+
PRODUCT_ADD_TO_CART: "product_added_to_cart"; /** Cart tracking publishes this event when the customer removes a line or lowers a line's quantity. */
|
|
17
18
|
PRODUCT_REMOVED_FROM_CART: "product_removed_from_cart";
|
|
18
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* The name of a supported analytics event, such as `"page_viewed"`.
|
|
22
|
+
*
|
|
23
|
+
* @publicDocs
|
|
24
|
+
*/
|
|
19
25
|
type AnalyticsEventName = (typeof AnalyticsEvent)[keyof typeof AnalyticsEvent];
|
|
20
26
|
//#endregion
|
|
21
27
|
export { AnalyticsEvent, AnalyticsEventName };
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
//#region src/core/analytics/events.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The names of the analytics events that Hydrogen supports.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Pass a constant as the event name when you publish an event or subscribe a destination.
|
|
6
|
+
* TypeScript narrows the payload to match the event name.
|
|
7
|
+
*
|
|
8
|
+
* @publicDocs
|
|
8
9
|
*/
|
|
9
10
|
const AnalyticsEvent = {
|
|
11
|
+
/** Publish when a customer views a page. Hydrogen fills in the current URL when the payload has none. */
|
|
10
12
|
PAGE_VIEWED: "page_viewed",
|
|
13
|
+
/** Publish when a customer views a product. The payload lists the viewed products. */
|
|
11
14
|
PRODUCT_VIEWED: "product_viewed",
|
|
15
|
+
/** Publish when a customer views a collection. The payload identifies the collection by ID and handle. */
|
|
12
16
|
COLLECTION_VIEWED: "collection_viewed",
|
|
17
|
+
/** Publish when a customer views the cart. The payload carries the current cart. */
|
|
13
18
|
CART_VIEWED: "cart_viewed",
|
|
19
|
+
/** Publish when a customer views search results. The payload carries the search term. */
|
|
14
20
|
SEARCH_VIEWED: "search_viewed",
|
|
21
|
+
/** Cart tracking publishes this event when the cart changes. */
|
|
15
22
|
CART_UPDATED: "cart_updated",
|
|
23
|
+
/** Cart tracking publishes this event when the customer adds a line or raises a line's quantity. */
|
|
16
24
|
PRODUCT_ADD_TO_CART: "product_added_to_cart",
|
|
25
|
+
/** Cart tracking publishes this event when the customer removes a line or lowers a line's quantity. */
|
|
17
26
|
PRODUCT_REMOVED_FROM_CART: "product_removed_from_cart"
|
|
18
27
|
};
|
|
19
28
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/core/analytics/events.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/core/analytics/events.ts"],"sourcesContent":["/**\n * The names of the analytics events that Hydrogen supports.\n *\n * Pass a constant as the event name when you publish an event or subscribe a destination.\n * TypeScript narrows the payload to match the event name.\n *\n * @publicDocs\n */\nexport const AnalyticsEvent = {\n /** Publish when a customer views a page. Hydrogen fills in the current URL when the payload has none. */\n PAGE_VIEWED: \"page_viewed\" as const,\n /** Publish when a customer views a product. The payload lists the viewed products. */\n PRODUCT_VIEWED: \"product_viewed\" as const,\n /** Publish when a customer views a collection. The payload identifies the collection by ID and handle. */\n COLLECTION_VIEWED: \"collection_viewed\" as const,\n /** Publish when a customer views the cart. The payload carries the current cart. */\n CART_VIEWED: \"cart_viewed\" as const,\n /** Publish when a customer views search results. The payload carries the search term. */\n SEARCH_VIEWED: \"search_viewed\" as const,\n\n /** Cart tracking publishes this event when the cart changes. */\n CART_UPDATED: \"cart_updated\" as const,\n /** Cart tracking publishes this event when the customer adds a line or raises a line's quantity. */\n PRODUCT_ADD_TO_CART: \"product_added_to_cart\" as const,\n /** Cart tracking publishes this event when the customer removes a line or lowers a line's quantity. */\n PRODUCT_REMOVED_FROM_CART: \"product_removed_from_cart\" as const,\n};\n\n/** The analytics event constants, keyed by constant name. */\ntype AnalyticsEventMap = typeof AnalyticsEvent;\n\n/**\n * The names of the analytics events that Hydrogen supports. Pass a value as the event name when you publish an event or subscribe a destination. TypeScript narrows the payload to match the event name.\n *\n * @publicDocs\n */\nexport interface AnalyticsEventForDocs extends AnalyticsEventMap {}\n\n/**\n * The name of a supported analytics event, such as `\"page_viewed\"`.\n *\n * @publicDocs\n */\nexport type AnalyticsEventName = (typeof AnalyticsEvent)[keyof typeof AnalyticsEvent];\n"],"mappings":";;;;;;;;;AAQA,MAAa,iBAAiB;;CAE5B,aAAa;;CAEb,gBAAgB;;CAEhB,mBAAmB;;CAEnB,aAAa;;CAEb,eAAe;;CAGf,cAAc;;CAEd,qBAAqB;;CAErB,2BAA2B;CAC5B"}
|