@shopify/hydrogen 2026.10.0-preview.3 → 2026.10.0-preview.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cli/index.mjs +150 -36
- package/dist/client/client.d.mts +18 -15
- package/dist/client/client.mjs +10 -5
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/errors.d.mts +41 -19
- package/dist/client/errors.mjs +29 -16
- package/dist/client/errors.mjs.map +1 -1
- package/dist/client/types.d.mts +164 -33
- package/dist/core/analytics/cart-tracker.d.mts +23 -0
- package/dist/core/analytics/cart-tracker.mjs +23 -1
- package/dist/core/analytics/cart-tracker.mjs.map +1 -1
- package/dist/core/analytics/custom-consent.mjs +12 -0
- package/dist/core/analytics/custom-consent.mjs.map +1 -0
- package/dist/core/analytics/events.d.mts +20 -7
- package/dist/core/analytics/events.mjs +16 -0
- package/dist/core/analytics/events.mjs.map +1 -1
- package/dist/core/analytics/index.d.mts +1 -1
- package/dist/core/analytics/types.d.mts +265 -40
- 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 +59 -8
- package/dist/core/cart/actions.mjs +39 -0
- package/dist/core/cart/actions.mjs.map +1 -1
- package/dist/core/cart/attach-quantity-input.d.mts +27 -0
- package/dist/core/cart/attach-quantity-input.mjs +27 -0
- 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 +121 -8
- package/dist/core/cart/cart.mjs +76 -18
- package/dist/core/cart/cart.mjs.map +1 -1
- package/dist/core/cart/cookie.d.mts +19 -0
- package/dist/core/cart/cookie.mjs +19 -0
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +75 -0
- package/dist/core/cart/form.mjs +20 -0
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/get-cart.d.mts +55 -2
- package/dist/core/cart/get-cart.mjs +38 -0
- package/dist/core/cart/get-cart.mjs.map +1 -1
- package/dist/core/cart/index.d.mts +1 -1
- package/dist/core/cart/quantity.d.mts +28 -0
- package/dist/core/cart/quantity.mjs +28 -0
- package/dist/core/cart/quantity.mjs.map +1 -1
- package/dist/core/cart/queries.d.mts +353 -314
- package/dist/core/cart/queries.mjs +16 -1
- package/dist/core/cart/queries.mjs.map +1 -1
- package/dist/core/cart/server-handlers.d.mts +120 -14
- package/dist/core/cart/server-handlers.mjs +6 -10
- package/dist/core/cart/server-handlers.mjs.map +1 -1
- package/dist/core/cart/state.d.mts +180 -1
- package/dist/core/cart/state.mjs +26 -0
- package/dist/core/cart/state.mjs.map +1 -1
- package/dist/core/collection/collection.d.mts +66 -51
- package/dist/core/collection/collection.mjs +16 -3
- package/dist/core/collection/collection.mjs.map +1 -1
- package/dist/core/collection/index.d.mts +1 -1
- package/dist/core/collection/reconciler.d.mts +27 -11
- package/dist/core/collection/reconciler.mjs +8 -4
- package/dist/core/collection/reconciler.mjs.map +1 -1
- package/dist/core/collection/state.d.mts +33 -23
- package/dist/core/collection/state.mjs +4 -3
- package/dist/core/collection/state.mjs.map +1 -1
- package/dist/core/collection/url.d.mts +71 -27
- package/dist/core/collection/url.mjs +63 -25
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.d.mts +2 -1
- package/dist/core/constants.mjs +3 -2
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/headers.mjs +2 -2
- package/dist/core/headers.mjs.map +1 -1
- package/dist/core/index.d.mts +5 -5
- 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 +24 -11
- package/dist/core/money/format.mjs.map +1 -1
- package/dist/core/money/types.d.mts +41 -25
- package/dist/core/observable.mjs +0 -3
- package/dist/core/observable.mjs.map +1 -1
- package/dist/core/predictive-search/form.d.mts +37 -6
- package/dist/core/predictive-search/form.mjs +21 -2
- package/dist/core/predictive-search/form.mjs.map +1 -1
- package/dist/core/predictive-search/index.d.mts +1 -1
- package/dist/core/predictive-search/queries.d.mts +30 -6
- package/dist/core/predictive-search/queries.mjs +11 -1
- package/dist/core/predictive-search/queries.mjs.map +1 -1
- package/dist/core/predictive-search/search.d.mts +41 -10
- package/dist/core/predictive-search/search.mjs +35 -0
- package/dist/core/predictive-search/search.mjs.map +1 -1
- package/dist/core/predictive-search/server-handlers.d.mts +28 -3
- package/dist/core/predictive-search/server-handlers.mjs +9 -3
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/store.d.mts +67 -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 +49 -8
- package/dist/core/predictive-search/url.mjs +17 -0
- 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 +92 -12
- package/dist/core/product/product-form.mjs +56 -4
- package/dist/core/product/product-form.mjs.map +1 -1
- package/dist/core/product/state.d.mts +64 -0
- package/dist/core/product/url.d.mts +22 -10
- 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 -22
- package/dist/core/request-context.mjs +17 -39
- 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 +9 -6
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/ajax-api.mjs +1 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs +1 -1
- package/dist/core/request-routing/interceptors/checkout.mjs +19 -6
- package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/mcp-proxy.mjs +1 -1
- package/dist/core/request-routing/interceptors/proxy.mjs +83 -32
- package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/query-param-redirect.mjs +5 -11
- package/dist/core/request-routing/interceptors/query-param-redirect.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/sfapi-proxy.mjs +19 -1
- package/dist/core/request-routing/interceptors/sfapi-proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/ucp-mcp-proxy.mjs +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 +2 -2
- 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/analytics.mjs +2 -2
- package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/core/shopify-scripts/constants.mjs +1 -1
- package/dist/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/core/shopify-scripts/global.mjs +5 -1
- package/dist/core/shopify-scripts/global.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 +13 -4
- package/dist/core/shopify-scripts/initialize.mjs +22 -7
- package/dist/core/shopify-scripts/initialize.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +58 -24
- 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 +21 -2
- package/dist/core/url.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +95 -4
- package/dist/customer-account/client.mjs +26 -1
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/errors.d.mts +55 -0
- package/dist/customer-account/errors.mjs +31 -0
- package/dist/customer-account/errors.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +56 -0
- package/dist/customer-account/graphql.mjs +41 -0
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.d.mts +166 -45
- package/dist/customer-account/session.mjs +49 -12
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/customer-account/type-resolver.d.mts +22 -0
- package/dist/customer-account-api-types.d.ts +570 -374
- package/dist/customer-account.schema.json +2981 -1527
- package/dist/development/client/client.d.mts +18 -15
- package/dist/development/client/client.mjs +10 -5
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/errors.d.mts +41 -19
- package/dist/development/client/errors.mjs +30 -20
- package/dist/development/client/errors.mjs.map +1 -1
- package/dist/development/client/types.d.mts +164 -33
- package/dist/development/core/analytics/cart-tracker.d.mts +23 -0
- package/dist/development/core/analytics/cart-tracker.mjs +23 -1
- package/dist/development/core/analytics/cart-tracker.mjs.map +1 -1
- package/dist/development/core/analytics/custom-consent.mjs +12 -0
- package/dist/development/core/analytics/custom-consent.mjs.map +1 -0
- package/dist/development/core/analytics/events.d.mts +20 -7
- package/dist/development/core/analytics/events.mjs +16 -0
- package/dist/development/core/analytics/events.mjs.map +1 -1
- package/dist/development/core/analytics/index.d.mts +1 -1
- package/dist/development/core/analytics/types.d.mts +265 -40
- 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 +59 -8
- package/dist/development/core/cart/actions.mjs +39 -0
- package/dist/development/core/cart/actions.mjs.map +1 -1
- package/dist/development/core/cart/attach-quantity-input.d.mts +27 -0
- package/dist/development/core/cart/attach-quantity-input.mjs +27 -0
- 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 +121 -8
- package/dist/development/core/cart/cart.mjs +76 -18
- package/dist/development/core/cart/cart.mjs.map +1 -1
- package/dist/development/core/cart/cookie.d.mts +19 -0
- package/dist/development/core/cart/cookie.mjs +19 -0
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +75 -0
- package/dist/development/core/cart/form.mjs +20 -0
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/get-cart.d.mts +55 -2
- package/dist/development/core/cart/get-cart.mjs +38 -0
- package/dist/development/core/cart/get-cart.mjs.map +1 -1
- package/dist/development/core/cart/index.d.mts +1 -1
- package/dist/development/core/cart/quantity.d.mts +28 -0
- package/dist/development/core/cart/quantity.mjs +28 -0
- package/dist/development/core/cart/quantity.mjs.map +1 -1
- package/dist/development/core/cart/queries.d.mts +410 -371
- package/dist/development/core/cart/queries.mjs +16 -1
- package/dist/development/core/cart/queries.mjs.map +1 -1
- package/dist/development/core/cart/server-handlers.d.mts +120 -14
- package/dist/development/core/cart/server-handlers.mjs +6 -10
- package/dist/development/core/cart/server-handlers.mjs.map +1 -1
- package/dist/development/core/cart/state.d.mts +180 -1
- package/dist/development/core/cart/state.mjs +26 -0
- package/dist/development/core/cart/state.mjs.map +1 -1
- package/dist/development/core/collection/collection.d.mts +66 -51
- package/dist/development/core/collection/collection.mjs +16 -3
- package/dist/development/core/collection/collection.mjs.map +1 -1
- package/dist/development/core/collection/index.d.mts +1 -1
- package/dist/development/core/collection/reconciler.d.mts +27 -11
- 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 +33 -23
- 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 +71 -27
- 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 +1 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/development.d.mts +5 -5
- package/dist/development/core/headers.mjs +2 -2
- package/dist/development/core/headers.mjs.map +1 -1
- package/dist/development/core/index.d.mts +4 -4
- 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 +24 -11
- package/dist/development/core/money/format.mjs.map +1 -1
- package/dist/development/core/money/types.d.mts +41 -25
- package/dist/development/core/observable.mjs +0 -3
- package/dist/development/core/observable.mjs.map +1 -1
- package/dist/development/core/predictive-search/form.d.mts +37 -6
- package/dist/development/core/predictive-search/form.mjs +21 -2
- package/dist/development/core/predictive-search/form.mjs.map +1 -1
- package/dist/development/core/predictive-search/index.d.mts +1 -1
- package/dist/development/core/predictive-search/queries.d.mts +32 -8
- package/dist/development/core/predictive-search/queries.mjs +11 -1
- package/dist/development/core/predictive-search/queries.mjs.map +1 -1
- package/dist/development/core/predictive-search/search.d.mts +41 -10
- package/dist/development/core/predictive-search/search.mjs +35 -0
- package/dist/development/core/predictive-search/search.mjs.map +1 -1
- package/dist/development/core/predictive-search/server-handlers.d.mts +28 -3
- package/dist/development/core/predictive-search/server-handlers.mjs +9 -3
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/store.d.mts +67 -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 +49 -8
- package/dist/development/core/predictive-search/url.mjs +17 -0
- 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 +92 -12
- package/dist/development/core/product/product-form.mjs +56 -4
- package/dist/development/core/product/product-form.mjs.map +1 -1
- package/dist/development/core/product/state.d.mts +64 -0
- package/dist/development/core/product/url.d.mts +22 -10
- 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 -22
- package/dist/development/core/request-context.mjs +17 -39
- 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 +9 -6
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/ajax-api.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/checkout.mjs +19 -6
- package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/mcp-proxy.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/proxy.mjs +83 -32
- package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/query-param-redirect.mjs +5 -11
- package/dist/development/core/request-routing/interceptors/query-param-redirect.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/sfapi-proxy.mjs +19 -1
- package/dist/development/core/request-routing/interceptors/sfapi-proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/ucp-mcp-proxy.mjs +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 +2 -2
- 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/analytics.mjs +2 -2
- package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/constants.mjs +1 -1
- package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/global.mjs +5 -1
- package/dist/development/core/shopify-scripts/global.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 +13 -4
- package/dist/development/core/shopify-scripts/initialize.mjs +22 -7
- package/dist/development/core/shopify-scripts/initialize.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +58 -24
- 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 +21 -2
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/customer-account/session.d.mts +65 -18
- package/dist/development/customer-account/session.mjs +20 -0
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +22 -15
- package/dist/development/graphql/generated/graphql-env.d.mts +459 -16
- package/dist/development/graphql/generated/storefront-api-types.d.mts +128 -2
- package/dist/development/graphql/graphql.d.mts +39 -5
- package/dist/development/graphql/graphql.mjs +29 -0
- package/dist/development/graphql/graphql.mjs.map +1 -1
- package/dist/development/graphql/type-resolver.d.mts +21 -0
- package/dist/development/react/cart.d.mts +144 -27
- package/dist/development/react/cart.mjs +152 -5
- package/dist/development/react/cart.mjs.map +1 -1
- package/dist/development/react/collection.d.mts +42 -26
- package/dist/development/react/collection.mjs +27 -7
- package/dist/development/react/collection.mjs.map +1 -1
- package/dist/development/react/index.d.mts +7 -5
- package/dist/development/react/index.mjs +2 -2
- package/dist/development/react/predictive-search.d.mts +85 -9
- package/dist/development/react/predictive-search.mjs +56 -12
- package/dist/development/react/predictive-search.mjs.map +1 -1
- package/dist/development/react/product.d.mts +45 -15
- package/dist/development/react/product.mjs +18 -13
- 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 +10 -0
- package/dist/development/react/shopify-scripts.mjs.map +1 -1
- package/dist/development/vue/cart.d.mts +94 -10
- package/dist/development/vue/cart.mjs +115 -3
- package/dist/development/vue/cart.mjs.map +1 -1
- package/dist/development/vue/collection.d.mts +91 -5
- package/dist/development/vue/collection.mjs +60 -0
- package/dist/development/vue/collection.mjs.map +1 -1
- package/dist/development/vue/index.d.mts +7 -5
- package/dist/development/vue/index.mjs +2 -2
- package/dist/development/vue/predictive-search.d.mts +48 -6
- package/dist/development/vue/predictive-search.mjs +27 -0
- package/dist/development/vue/predictive-search.mjs.map +1 -1
- package/dist/development/vue/product.d.mts +18 -13
- 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 +32 -3
- package/dist/development/vue/shopify-scripts.mjs +7 -0
- package/dist/development/vue/shopify-scripts.mjs.map +1 -1
- package/dist/globals.d.mts +22 -15
- package/dist/graphql/generated/customer-account-graphql-env.d.mts +1717 -1090
- package/dist/graphql/generated/graphql-env.d.mts +459 -16
- package/dist/graphql/generated/storefront-api-types.d.mts +128 -2
- package/dist/graphql/graphql.d.mts +39 -5
- package/dist/graphql/graphql.mjs +29 -0
- package/dist/graphql/graphql.mjs.map +1 -1
- package/dist/graphql/type-resolver.d.mts +21 -0
- package/dist/react/cart.d.mts +144 -27
- package/dist/react/cart.mjs +152 -5
- package/dist/react/cart.mjs.map +1 -1
- package/dist/react/collection.d.mts +42 -26
- package/dist/react/collection.mjs +27 -7
- package/dist/react/collection.mjs.map +1 -1
- package/dist/react/index.d.mts +7 -5
- package/dist/react/index.mjs +2 -2
- package/dist/react/predictive-search.d.mts +85 -9
- package/dist/react/predictive-search.mjs +56 -12
- package/dist/react/predictive-search.mjs.map +1 -1
- package/dist/react/product.d.mts +45 -15
- package/dist/react/product.mjs +18 -13
- 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 +10 -0
- package/dist/react/shopify-scripts.mjs.map +1 -1
- package/dist/storefront-api-types.d.ts +165 -20
- package/dist/storefront.schema.json +782 -57
- 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/customer-account.mjs +191 -0
- package/dist/vite/customer-account.mjs.map +1 -0
- package/dist/vite/local-https.d.mts +51 -17
- package/dist/vite/local-https.mjs +39 -34
- package/dist/vite/local-https.mjs.map +1 -1
- package/dist/vite/mkcert.mjs +1 -1
- package/dist/vue/cart.d.mts +94 -10
- package/dist/vue/cart.mjs +115 -3
- package/dist/vue/cart.mjs.map +1 -1
- package/dist/vue/collection.d.mts +91 -5
- package/dist/vue/collection.mjs +60 -0
- package/dist/vue/collection.mjs.map +1 -1
- package/dist/vue/index.d.mts +7 -5
- package/dist/vue/index.mjs +2 -2
- package/dist/vue/predictive-search.d.mts +48 -6
- package/dist/vue/predictive-search.mjs +27 -0
- package/dist/vue/predictive-search.mjs.map +1 -1
- package/dist/vue/product.d.mts +18 -13
- 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 +32 -3
- package/dist/vue/shopify-scripts.mjs +7 -0
- package/dist/vue/shopify-scripts.mjs.map +1 -1
- package/package.json +7 -2
- package/skills/hydrogen-analytics/SKILL.md +7 -6
- package/skills/hydrogen-analytics/references/custom-consent.md +52 -0
- package/skills/hydrogen-analytics/references/react.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 +5 -3
- package/skills/hydrogen-local-https/SKILL.md +22 -7
- package/skills/hydrogen-request-handlers/SKILL.md +23 -13
- package/skills/hydrogen-request-handlers/references/nuxt.md +0 -6
- package/skills/hydrogen-setup/references/analytics.md +37 -30
- package/skills/hydrogen-setup/steps/1-inspect-app.md +1 -1
- package/skills/hydrogen-setup/steps/2-scaffold.md +1 -1
- package/skills/hydrogen-setup/steps/6-product-detail-page.md +21 -11
- package/skills/hydrogen-smoke-test/SKILL.md +2 -2
- package/skills/hydrogen-storefront-client/SKILL.md +1 -3
- 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/ts-plugin/package.json +5 -0
- package/dist/core/shopify-scripts/deprecated-cookies.mjs +0 -98
- package/dist/core/shopify-scripts/deprecated-cookies.mjs.map +0 -1
- package/dist/core/shopify-scripts/utils/cookie-domain.mjs +0 -43
- package/dist/core/shopify-scripts/utils/cookie-domain.mjs.map +0 -1
- package/dist/core/shopify-scripts/utils/tracking-values.mjs +0 -65
- package/dist/core/shopify-scripts/utils/tracking-values.mjs.map +0 -1
- package/dist/core/shopify-scripts/utils/uuid.mjs +0 -17
- package/dist/core/shopify-scripts/utils/uuid.mjs.map +0 -1
- package/dist/development/core/shopify-scripts/deprecated-cookies.mjs +0 -98
- package/dist/development/core/shopify-scripts/deprecated-cookies.mjs.map +0 -1
- package/dist/development/core/shopify-scripts/utils/cookie-domain.mjs +0 -43
- package/dist/development/core/shopify-scripts/utils/cookie-domain.mjs.map +0 -1
- package/dist/development/core/shopify-scripts/utils/tracking-values.mjs +0 -65
- package/dist/development/core/shopify-scripts/utils/tracking-values.mjs.map +0 -1
- package/dist/development/core/shopify-scripts/utils/uuid.mjs +0 -17
- package/dist/development/core/shopify-scripts/utils/uuid.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["interface StorefrontApiErrorOptions {\n requestId?: string;\n status?: number;\n cause?: unknown;\n queryText?: string;\n variables?: Record<string, unknown>;\n
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["interface StorefrontApiErrorOptions {\n requestId?: string;\n status?: number;\n cause?: unknown;\n queryText?: string;\n variables?: Record<string, unknown>;\n}\n\n/**\n * Signals that a Storefront API request failed. The client throws the error for an HTTP error\n * status, a network failure, or a response body that isn't a JSON object.\n *\n * GraphQL errors, including `THROTTLED`, don't throw. Read GraphQL errors from the result's\n * `errors` field.\n *\n * When the request context's signal or the call's `signal` aborts before the call, the client\n * throws the abort reason and sends no request. An `AbortError` during the request reaches your\n * code unchanged. Other abort reasons during the request throw a `StorefrontApiError`.\n *\n * @publicDocs\n */\nexport class StorefrontApiError extends Error {\n /** The `x-request-id` header of the Storefront API response, when the response has one. Include the ID in support requests. */\n readonly requestId?: string;\n /** The HTTP status code of the response, when the request reached the server. */\n readonly status?: number;\n /** The GraphQL query that failed. Hydrogen sets the value only in development builds. */\n readonly queryText?: string;\n /** The variables that the client sent with the request. Hydrogen sets the value only in development builds. */\n readonly variables?: Record<string, unknown>;\n\n /** `StorefrontApiError`. `StorefrontTimeoutError` sets its own class name. */\n declare name: string;\n /** Describes the failure, such as the HTTP status that the API returned. */\n declare message: string;\n /** The stack trace, when the JavaScript runtime records one. */\n declare stack?: string;\n\n constructor(message: string, options?: StorefrontApiErrorOptions) {\n super(message, options?.cause ? { cause: options.cause } : undefined);\n this.name = \"StorefrontApiError\";\n this.requestId = options?.requestId;\n this.status = options?.status;\n\n if (__DEV__) {\n this.queryText = options?.queryText;\n this.variables = options?.variables;\n }\n }\n\n /** Makes `Object.prototype.toString` report the error name, such as `[object StorefrontApiError]`. */\n get [Symbol.toStringTag]() {\n return this.name;\n }\n\n /** Returns the error name, message, request ID, and status for logging. The output leaves out the query text, variables, cause, and stack. */\n toJSON(): { name: string; message: string; requestId?: string; status?: number } {\n return {\n name: this.name,\n message: this.message,\n ...(this.requestId != null && { requestId: this.requestId }),\n ...(this.status != null && { status: this.status }),\n };\n }\n}\n\n/**\n * Signals that a Storefront API request ran longer than the client's `defaultTimeoutInMs` setting.\n * Aborts from the request context or the call's `signal` throw other errors.\n *\n * `StorefrontTimeoutError` extends `StorefrontApiError`. Check for `StorefrontTimeoutError` first when\n * you handle both errors.\n *\n * @publicDocs\n */\nexport class StorefrontTimeoutError extends StorefrontApiError {\n /** The timeout that the request exceeded, in milliseconds. */\n readonly timeoutInMs: number;\n\n /** Always `StorefrontTimeoutError`. */\n declare name: string;\n /** States the timeout, such as `\"Storefront API request timed out after 30000ms\"`. */\n declare message: string;\n /** The stack trace, when the JavaScript runtime records one. */\n declare stack?: string;\n\n constructor(timeoutInMs: number, options?: Omit<StorefrontApiErrorOptions, \"cause\">) {\n super(`Storefront API request timed out after ${timeoutInMs}ms`, options);\n this.name = \"StorefrontTimeoutError\";\n this.timeoutInMs = timeoutInMs;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,IAAa,qBAAb,cAAwC,MAAM;;CAE5C,AAAS;;CAET,AAAS;;CAET,AAAS;;CAET,AAAS;CAST,YAAY,SAAiB,SAAqC;AAChE,QAAM,SAAS,SAAS,QAAQ,EAAE,OAAO,QAAQ,OAAO,GAAG,OAAU;AACrE,OAAK,OAAO;AACZ,OAAK,YAAY,SAAS;AAC1B,OAAK,SAAS,SAAS;;;CASzB,KAAK,OAAO,eAAe;AACzB,SAAO,KAAK;;;CAId,SAAiF;AAC/E,SAAO;GACL,MAAM,KAAK;GACX,SAAS,KAAK;GACd,GAAI,KAAK,aAAa,QAAQ,EAAE,WAAW,KAAK,WAAW;GAC3D,GAAI,KAAK,UAAU,QAAQ,EAAE,QAAQ,KAAK,QAAQ;GACnD;;;;;;;;;;;;AAaL,IAAa,yBAAb,cAA4C,mBAAmB;;CAE7D,AAAS;CAST,YAAY,aAAqB,SAAoD;AACnF,QAAM,0CAA0C,YAAY,KAAK,QAAQ;AACzE,OAAK,OAAO;AACZ,OAAK,cAAc"}
|
package/dist/client/types.d.mts
CHANGED
|
@@ -5,83 +5,122 @@ 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>;
|
|
25
|
+
/**
|
|
26
|
+
* A GraphQL error from the Storefront API. The result of a GraphQL call lists GraphQL errors
|
|
27
|
+
* in its `errors` field.
|
|
28
|
+
*/
|
|
18
29
|
interface GraphQLFormattedError {
|
|
30
|
+
/** The error message. */
|
|
19
31
|
readonly message: string;
|
|
32
|
+
/** The lines and columns in the query where the error occurs. */
|
|
20
33
|
readonly locations?: ReadonlyArray<{
|
|
21
34
|
line: number;
|
|
22
35
|
column: number;
|
|
23
36
|
}>;
|
|
37
|
+
/** The path to the response field that failed. */
|
|
24
38
|
readonly path?: ReadonlyArray<string | number>;
|
|
39
|
+
/** Extra details that the Storefront API adds to the error. */
|
|
25
40
|
readonly extensions?: Record<string, unknown>;
|
|
26
41
|
}
|
|
27
42
|
type CommonOptions = {
|
|
43
|
+
/**
|
|
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
|
+
*/
|
|
28
48
|
storeDomain: string;
|
|
29
49
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
50
|
+
* Your Hydrogen storefront's ID. The client sends the ID in the `Shopify-Storefront-Id` header
|
|
51
|
+
* of every request.
|
|
32
52
|
*/
|
|
33
53
|
storefrontId?: string;
|
|
34
54
|
/**
|
|
35
|
-
* Storefront API version
|
|
36
|
-
*
|
|
37
|
-
* version
|
|
38
|
-
*
|
|
39
|
-
* controls type inference, so queries against fields outside that schema need their own typing.
|
|
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.
|
|
40
59
|
*/
|
|
41
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.
|
|
66
|
+
*/
|
|
42
67
|
defaultTimeoutInMs?: number;
|
|
43
|
-
|
|
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. */
|
|
44
73
|
waitUntil?: WaitUntil;
|
|
45
74
|
};
|
|
75
|
+
/** A fetch function, or any function with a compatible signature that resolves to a `Response`. */
|
|
46
76
|
type AnyFetch = typeof globalThis.fetch | ((...args: never[]) => Promise<Response>);
|
|
47
77
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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.
|
|
50
80
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* 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.
|
|
54
83
|
*/
|
|
55
84
|
interface PublicClientOptions<Fetch extends AnyFetch | undefined = typeof globalThis.fetch> extends CommonOptions {
|
|
85
|
+
/** The fetch function that the client calls. Defaults to `globalThis.fetch`. `createStorefrontClient` throws an error when neither exists. */
|
|
56
86
|
fetch?: Fetch;
|
|
87
|
+
/** Your public Storefront API access token. Omit the token for tokenless access. `createStorefrontClient` throws an error for an empty string. */
|
|
57
88
|
publicStorefrontToken?: string | undefined;
|
|
58
89
|
}
|
|
59
90
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* Best for: SSR/server-side requests where you control the fetch
|
|
65
|
-
* layer and can forward trusted buyer context.
|
|
66
|
-
* Token-based access is required for some Storefront API fields, including
|
|
67
|
-
* 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.
|
|
68
94
|
*/
|
|
69
95
|
interface PrivateClientOptions<Fetch extends AnyFetch | undefined = typeof globalThis.fetch> extends CommonOptions {
|
|
96
|
+
/** The fetch function that the client calls. Defaults to `globalThis.fetch`. `createStorefrontClient` throws an error when neither exists. */
|
|
70
97
|
fetch?: Fetch;
|
|
98
|
+
/** Your private Storefront API access token. Keep the token out of browser code. `createStorefrontClient` throws an error when the token is missing. */
|
|
71
99
|
privateStorefrontToken: string;
|
|
72
100
|
}
|
|
73
101
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* Best for: background jobs, webhooks, or server contexts where no
|
|
78
|
-
* 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.
|
|
79
104
|
*/
|
|
80
105
|
interface PrivateNoBuyerContextClientOptions<Fetch extends AnyFetch | undefined = typeof globalThis.fetch> extends CommonOptions {
|
|
106
|
+
/** The fetch function that the client calls. Defaults to `globalThis.fetch`. `createStorefrontClient` throws an error when neither exists. */
|
|
81
107
|
fetch?: Fetch;
|
|
108
|
+
/** Your private Storefront API access token. Keep the token out of browser code. `createStorefrontClient` throws an error when the token is missing. */
|
|
82
109
|
privateStorefrontToken: string;
|
|
83
110
|
}
|
|
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
|
+
*/
|
|
84
116
|
type StorefrontClientOptions = PublicClientOptions | PrivateClientOptions | PrivateNoBuyerContextClientOptions;
|
|
117
|
+
/**
|
|
118
|
+
* The arguments for createStorefrontClient. Set `type` to choose the client, then pass a request
|
|
119
|
+
* context and the matching store settings.
|
|
120
|
+
*
|
|
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.
|
|
123
|
+
*/
|
|
85
124
|
type CreateStorefrontClientArgs<RequestContext extends ShopifyRequestContext = ShopifyRequestContext, Type extends ClientType = ClientType, CacheConfig extends CacheInstance | undefined = CacheInstance | undefined> = {
|
|
86
125
|
type: "public" & Type;
|
|
87
126
|
requestContext: RequestContext;
|
|
@@ -102,17 +141,42 @@ type CreateStorefrontClientArgs<RequestContext extends ShopifyRequestContext = S
|
|
|
102
141
|
};
|
|
103
142
|
};
|
|
104
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. */
|
|
105
145
|
type UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, AutoAddedVariableNames>;
|
|
146
|
+
/** Resolves to `true` when an object type has no required keys. */
|
|
106
147
|
type HasNoRequiredKeys<T> = Record<string, never> extends T ? true : false;
|
|
148
|
+
/**
|
|
149
|
+
* Options that every Storefront API GraphQL call accepts.
|
|
150
|
+
*
|
|
151
|
+
* @publicDocs
|
|
152
|
+
*/
|
|
107
153
|
type StorefrontGraphqlOptions = {
|
|
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
|
+
*/
|
|
108
158
|
signal?: AbortSignal;
|
|
109
159
|
};
|
|
160
|
+
/** The options for a GraphQL call. The call needs `variables` only when the document declares a required variable. */
|
|
110
161
|
type MergedOptions<Doc extends DocLike, Extra extends Record<string, unknown>> = Extra & StorefrontGraphqlOptions & (HasNoRequiredKeys<UserVariables<Doc>> extends true ? {
|
|
111
162
|
variables?: UserVariables<Doc>;
|
|
112
163
|
} : {
|
|
113
164
|
variables: UserVariables<Doc>;
|
|
114
165
|
});
|
|
166
|
+
/**
|
|
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.
|
|
170
|
+
*/
|
|
115
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>>];
|
|
172
|
+
/**
|
|
173
|
+
* The result of a GraphQL call, with the data, any GraphQL errors, and the response headers. Check
|
|
174
|
+
* `errors` before you read `data`.
|
|
175
|
+
*
|
|
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.
|
|
179
|
+
*/
|
|
116
180
|
type StorefrontGraphqlResult<Doc extends DocLike> = {
|
|
117
181
|
data: ResultOfDoc<Doc>;
|
|
118
182
|
errors?: undefined;
|
|
@@ -122,24 +186,91 @@ type StorefrontGraphqlResult<Doc extends DocLike> = {
|
|
|
122
186
|
errors: GraphQLFormattedError[];
|
|
123
187
|
headers: Headers;
|
|
124
188
|
};
|
|
125
|
-
|
|
126
|
-
|
|
189
|
+
/**
|
|
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.
|
|
203
|
+
*
|
|
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.
|
|
210
|
+
*/
|
|
127
211
|
type StorefrontClient<Extra extends Record<string, unknown> = {}, Type extends ClientType = ClientType, RequestContext extends ShopifyRequestContext = ShopifyRequestContext> = {
|
|
128
|
-
type: Type;
|
|
212
|
+
/** The client type that you passed to `createStorefrontClient`. */type: Type; /** The country and language that the client sends for `$country` and `$language` variables. */
|
|
129
213
|
i18n: RequestContext["i18n"];
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
214
|
+
/**
|
|
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.
|
|
218
|
+
*
|
|
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.
|
|
223
|
+
*/
|
|
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`. */
|
|
134
228
|
requestContext: RequestContext;
|
|
135
229
|
};
|
|
230
|
+
/**
|
|
231
|
+
* The type of a client that you create with `type: "public"`.
|
|
232
|
+
*
|
|
233
|
+
* @publicDocs
|
|
234
|
+
*/
|
|
136
235
|
type PublicStorefrontClient<Extra extends Record<string, unknown> = {}, RequestContext extends ShopifyRequestContext = ShopifyRequestContext> = StorefrontClient<Extra, "public", RequestContext>;
|
|
236
|
+
/**
|
|
237
|
+
* The type of a client that you create with `type: "private"`. The client's request context includes `buyerIp`.
|
|
238
|
+
*
|
|
239
|
+
* @publicDocs
|
|
240
|
+
*/
|
|
137
241
|
type PrivateStorefrontClient<Extra extends Record<string, unknown> = {}, RequestContext extends ShopifyRequestContextWithBuyerIp = ShopifyRequestContextWithBuyerIp> = StorefrontClient<Extra, "private", RequestContext>;
|
|
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
|
+
*/
|
|
138
247
|
type RequestScopedPrivateStorefrontClient<Extra extends Record<string, unknown> = {}> = PrivateStorefrontClient<Extra, ShopifyRequestContextWithBuyerIp>;
|
|
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
|
+
*/
|
|
139
253
|
type PrivateNoBuyerContextStorefrontClient<Extra extends Record<string, unknown> = {}, RequestContext extends ShopifyRequestContext = ShopifyRequestContext> = StorefrontClient<Extra, "private_no_buyer_context", RequestContext>;
|
|
254
|
+
/**
|
|
255
|
+
* Type helpers that read the result and variables types of a Storefront API document.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```ts
|
|
259
|
+
* import { gql, type StorefrontApi } from "@shopify/hydrogen";
|
|
260
|
+
*
|
|
261
|
+
* const PRODUCT_QUERY = gql(`query Product($handle: String!) { product(handle: $handle) { title } }`);
|
|
262
|
+
*
|
|
263
|
+
* type Product = StorefrontApi.ResultOf<typeof PRODUCT_QUERY>;
|
|
264
|
+
* type Vars = StorefrontApi.VariablesOf<typeof PRODUCT_QUERY>;
|
|
265
|
+
* ```
|
|
266
|
+
* @publicDocs
|
|
267
|
+
*/
|
|
140
268
|
declare namespace StorefrontApi {
|
|
269
|
+
/** The result type of a document. */
|
|
141
270
|
type ResultOf<Doc extends DocLike> = StorefrontApiResultOf<Doc>;
|
|
271
|
+
/** The variables type of a document. */
|
|
142
272
|
type VariablesOf<Doc extends DocLike> = StorefrontApiVariablesOf<Doc>;
|
|
273
|
+
/** A typed Storefront API document from `gql`, or a gql.tada document node. */
|
|
143
274
|
type DocumentNode = DocLike;
|
|
144
275
|
}
|
|
145
276
|
//#endregion
|
|
@@ -1,7 +1,30 @@
|
|
|
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">;
|
|
6
|
+
/**
|
|
7
|
+
* Publishes cart analytics events when the server confirms a change to the customer's cart. In React, call `useCartAnalytics`.
|
|
8
|
+
*
|
|
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.
|
|
13
|
+
*
|
|
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
|
|
27
|
+
*/
|
|
5
28
|
declare function trackCartAnalytics(store: CartAnalyticsStore): () => void;
|
|
6
29
|
//#endregion
|
|
7
30
|
export { trackCartAnalytics };
|
|
@@ -2,6 +2,28 @@ import { AnalyticsEvent } from "./events.mjs";
|
|
|
2
2
|
import { flattenConnection } from "./utils/flatten-connection.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/core/analytics/cart-tracker.ts
|
|
5
|
+
/**
|
|
6
|
+
* Publishes cart analytics events when the server confirms a change to the customer's cart. In React, call `useCartAnalytics`.
|
|
7
|
+
*
|
|
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.
|
|
12
|
+
*
|
|
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
|
|
26
|
+
*/
|
|
5
27
|
function trackCartAnalytics(store) {
|
|
6
28
|
const analytics = getGlobalAnalytics();
|
|
7
29
|
const state = {
|
|
@@ -120,7 +142,7 @@ function hasPendingCartWork({ pending, revalidating }) {
|
|
|
120
142
|
return revalidating === true || hasPendingCost || pending.note || pending.attributes;
|
|
121
143
|
}
|
|
122
144
|
function getCartUpdatedAt(cart) {
|
|
123
|
-
return
|
|
145
|
+
return cart.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
124
146
|
}
|
|
125
147
|
function syncShopifyCurrency(cart) {
|
|
126
148
|
if (typeof window === "undefined") return;
|
|
@@ -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\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 typeof cart.updatedAt === \"string\" ? 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":"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"}
|
|
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":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/core/analytics/custom-consent.ts
|
|
2
|
+
const CUSTOM_CONSENT = Symbol.for("shopify.hydrogen.custom-consent");
|
|
3
|
+
function initializeCustomConsent(setup) {
|
|
4
|
+
if (typeof window === "undefined") return;
|
|
5
|
+
const initialize = (window.Shopify?.analytics)?.[CUSTOM_CONSENT];
|
|
6
|
+
if (!initialize) throw new Error("Custom consent requires Shopify script tags rendered with consent.mode = \"custom-banner\".");
|
|
7
|
+
initialize(setup);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { initializeCustomConsent };
|
|
12
|
+
//# sourceMappingURL=custom-consent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-consent.mjs","names":[],"sources":["../../../src/core/analytics/custom-consent.ts"],"sourcesContent":["import type { ConsentSetup, StorefrontAnalytics } from \"./types\";\n\n// The inline bus and hydrated app are separate bundles. This private hook passes\n// the app's setup callback to the bus without serializing it into HTML.\nexport const CUSTOM_CONSENT = Symbol.for(\"shopify.hydrogen.custom-consent\");\n\ntype AnalyticsWithCustomConsent = StorefrontAnalytics & {\n [CUSTOM_CONSENT]?: (setup: ConsentSetup) => void;\n};\n\nexport function initializeCustomConsent(setup: ConsentSetup): void {\n if (typeof window === \"undefined\") return;\n\n const analytics: AnalyticsWithCustomConsent | undefined = window.Shopify?.analytics;\n const initialize = analytics?.[CUSTOM_CONSENT];\n if (!initialize) {\n throw new Error(\n 'Custom consent requires Shopify script tags rendered with consent.mode = \"custom-banner\".',\n );\n }\n initialize(setup);\n}\n"],"mappings":";AAIA,MAAa,iBAAiB,OAAO,IAAI,kCAAkC;AAM3E,SAAgB,wBAAwB,OAA2B;AACjE,KAAI,OAAO,WAAW,YAAa;CAGnC,MAAM,cADoD,OAAO,SAAS,aAC3C;AAC/B,KAAI,CAAC,WACH,OAAM,IAAI,MACR,8FACD;AAEH,YAAW,MAAM"}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
//#region src/core/analytics/events.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The names of the analytics events that Hydrogen supports.
|
|
4
|
+
*
|
|
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
|
|
9
|
+
*/
|
|
2
10
|
declare const AnalyticsEvent: {
|
|
3
|
-
PAGE_VIEWED: "page_viewed";
|
|
4
|
-
PRODUCT_VIEWED: "product_viewed";
|
|
5
|
-
COLLECTION_VIEWED: "collection_viewed";
|
|
6
|
-
CART_VIEWED: "cart_viewed";
|
|
7
|
-
SEARCH_VIEWED: "search_viewed";
|
|
8
|
-
CART_UPDATED: "cart_updated";
|
|
9
|
-
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. */
|
|
10
18
|
PRODUCT_REMOVED_FROM_CART: "product_removed_from_cart";
|
|
11
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* The name of a supported analytics event, such as `"page_viewed"`.
|
|
22
|
+
*
|
|
23
|
+
* @publicDocs
|
|
24
|
+
*/
|
|
12
25
|
type AnalyticsEventName = (typeof AnalyticsEvent)[keyof typeof AnalyticsEvent];
|
|
13
26
|
//#endregion
|
|
14
27
|
export { AnalyticsEvent, AnalyticsEventName };
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
//#region src/core/analytics/events.ts
|
|
2
|
+
/**
|
|
3
|
+
* The names of the analytics events that Hydrogen supports.
|
|
4
|
+
*
|
|
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
|
|
9
|
+
*/
|
|
2
10
|
const AnalyticsEvent = {
|
|
11
|
+
/** Publish when a customer views a page. Hydrogen fills in the current URL when the payload has none. */
|
|
3
12
|
PAGE_VIEWED: "page_viewed",
|
|
13
|
+
/** Publish when a customer views a product. The payload lists the viewed products. */
|
|
4
14
|
PRODUCT_VIEWED: "product_viewed",
|
|
15
|
+
/** Publish when a customer views a collection. The payload identifies the collection by ID and handle. */
|
|
5
16
|
COLLECTION_VIEWED: "collection_viewed",
|
|
17
|
+
/** Publish when a customer views the cart. The payload carries the current cart. */
|
|
6
18
|
CART_VIEWED: "cart_viewed",
|
|
19
|
+
/** Publish when a customer views search results. The payload carries the search term. */
|
|
7
20
|
SEARCH_VIEWED: "search_viewed",
|
|
21
|
+
/** Cart tracking publishes this event when the cart changes. */
|
|
8
22
|
CART_UPDATED: "cart_updated",
|
|
23
|
+
/** Cart tracking publishes this event when the customer adds a line or raises a line's quantity. */
|
|
9
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. */
|
|
10
26
|
PRODUCT_REMOVED_FROM_CART: "product_removed_from_cart"
|
|
11
27
|
};
|
|
12
28
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.mjs","names":[],"sources":["../../../src/core/analytics/events.ts"],"sourcesContent":["
|
|
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"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { trackCartAnalytics } from "./cart-tracker.mjs";
|
|
2
2
|
import { AnalyticsEvent, AnalyticsEventName } from "./events.mjs";
|
|
3
|
-
import { AnalyticsCart, AnalyticsCartLine, AnalyticsEventMap, CartLineUpdatePayload, CartUpdatePayload, CartViewPayload, CollectionViewPayload, ConsentConfig,
|
|
3
|
+
import { AnalyticsCart, AnalyticsCartLine, AnalyticsEventMap, AnalyticsTrackingValues, CartLineUpdatePayload, CartUpdatePayload, CartViewPayload, CollectionViewPayload, ConsentConfig, ConsentPreferences, ConsentSetup, OtherData, PageViewPayload, PayloadFor, ProductPayload, ProductViewPayload, SearchViewPayload, ShopAnalytics, StorefrontAnalytics, StorefrontAnalyticsConfig, StorefrontAnalyticsDestination, StorefrontAnalyticsDestinationEventContext, StorefrontAnalyticsDestinationSetupContext } from "./types.mjs";
|