@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
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { CartErrorCode, CartWarningCode } from "../../graphql/generated/storefront-api-types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/cart/state.d.ts
|
|
4
|
-
/**
|
|
4
|
+
/** A monetary value from the Storefront API. */
|
|
5
5
|
interface Money {
|
|
6
|
-
/**
|
|
6
|
+
/** The decimal amount as a string, such as `29.99`. */
|
|
7
7
|
amount: string;
|
|
8
|
-
/** ISO 4217 currency code
|
|
8
|
+
/** The ISO 4217 currency code, such as `USD`. */
|
|
9
9
|
currencyCode: string;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/** The cart's costs from the Storefront API. */
|
|
12
12
|
interface CartCost {
|
|
13
13
|
/** The amount, before taxes and cart-level discounts, for the customer to pay. */
|
|
14
14
|
subtotalAmount: Money;
|
|
15
|
-
/** Final amount the
|
|
15
|
+
/** Final amount the customer pays at checkout. */
|
|
16
16
|
totalAmount: Money;
|
|
17
17
|
/** Estimated amount due at checkout, excluding deferred payments. Equals the subtotal when no deferred payments exist. */
|
|
18
18
|
checkoutChargeAmount: Money;
|
|
19
19
|
}
|
|
20
|
+
/** A cart line's costs from the Storefront API. */
|
|
20
21
|
interface CartLineCost {
|
|
21
22
|
/** Line total after all applicable discounts. */
|
|
22
23
|
totalAmount: Money;
|
|
@@ -27,22 +28,24 @@ interface CartLineCost {
|
|
|
27
28
|
/** Original compare-at unit price, or `null` when no comparison exists. */
|
|
28
29
|
compareAtAmountPerQuantity: Money | null;
|
|
29
30
|
}
|
|
30
|
-
/**
|
|
31
|
+
/** The product variant on a cart line. */
|
|
31
32
|
interface CartLineMerchandise {
|
|
32
33
|
/** Storefront API GID of the product variant. */
|
|
33
34
|
id: string;
|
|
34
|
-
/**
|
|
35
|
+
/** The variant title, such as `"Small / Black"`. */
|
|
35
36
|
title?: string;
|
|
36
|
-
/**
|
|
37
|
+
/** The variant's selected options as name and value pairs. */
|
|
37
38
|
selectedOptions?: Array<{
|
|
38
39
|
name: string;
|
|
39
40
|
value: string;
|
|
40
41
|
}>;
|
|
42
|
+
/** The product that the variant belongs to. */
|
|
41
43
|
product: {
|
|
42
44
|
title: string;
|
|
43
45
|
handle?: string;
|
|
44
46
|
[key: string]: unknown;
|
|
45
47
|
};
|
|
48
|
+
/** The variant image that the cart query selects. */
|
|
46
49
|
image?: {
|
|
47
50
|
id?: string | null;
|
|
48
51
|
url: string;
|
|
@@ -51,25 +54,28 @@ interface CartLineMerchandise {
|
|
|
51
54
|
height?: number | null;
|
|
52
55
|
[key: string]: unknown;
|
|
53
56
|
} | null;
|
|
57
|
+
/** Units available for sale. When your cart fragment selects the field, the store caps the quantity of a `set` submission at this number. */
|
|
54
58
|
quantityAvailable?: number | null;
|
|
59
|
+
/** Extra variant fields from your custom cart fragment, unchanged. */
|
|
55
60
|
[key: string]: unknown;
|
|
56
61
|
}
|
|
57
62
|
/**
|
|
58
63
|
* A single line item in the cart.
|
|
59
64
|
*
|
|
60
|
-
* Each line
|
|
61
|
-
*
|
|
62
|
-
*
|
|
65
|
+
* Each line holds a product variant at a quantity. A line can carry custom
|
|
66
|
+
* attributes, a selling plan allocation for a subscription, or line components
|
|
67
|
+
* for a bundle.
|
|
63
68
|
*/
|
|
64
69
|
interface CartLine {
|
|
65
|
-
/** Storefront API GID
|
|
70
|
+
/** The cart line's Storefront API GID. Look up the line's pending state and errors with this ID. */
|
|
66
71
|
id: string;
|
|
67
72
|
/** Number of units of this merchandise in the cart. */
|
|
68
73
|
quantity: number;
|
|
74
|
+
/** Custom key-value attributes attached to the line. */
|
|
69
75
|
attributes?: Attribute[];
|
|
70
76
|
/** Per-line cost breakdown from the Storefront API. */
|
|
71
77
|
cost: CartLineCost;
|
|
72
|
-
/** The product variant
|
|
78
|
+
/** The product variant on the line. */
|
|
73
79
|
merchandise?: CartLineMerchandise;
|
|
74
80
|
/** Subscription selling plan allocation, or `null` for one-time purchases. */
|
|
75
81
|
sellingPlanAllocation?: {
|
|
@@ -77,6 +83,7 @@ interface CartLine {
|
|
|
77
83
|
id: string;
|
|
78
84
|
};
|
|
79
85
|
} | null;
|
|
86
|
+
/** The parent line's ID when this line is a bundle component. */
|
|
80
87
|
parentRelationship?: {
|
|
81
88
|
parent: {
|
|
82
89
|
id: string;
|
|
@@ -85,52 +92,65 @@ interface CartLine {
|
|
|
85
92
|
/** Nested child lines when this line is a bundle parent. */
|
|
86
93
|
lineComponents?: CartLine[];
|
|
87
94
|
}
|
|
95
|
+
/** The cart's line items in the Storefront API connection shape. */
|
|
88
96
|
interface CartLineConnection {
|
|
97
|
+
/** The cart lines that the cart query returns. */
|
|
89
98
|
nodes: CartLine[];
|
|
99
|
+
/** Extra connection fields from your custom cart fragment, unchanged. */
|
|
90
100
|
[key: string]: unknown;
|
|
91
101
|
}
|
|
92
102
|
/** A discount code applied to the cart. */
|
|
93
103
|
interface DiscountCode {
|
|
104
|
+
/** The discount code text. Look up the code's pending state and errors with this value. */
|
|
94
105
|
code: string;
|
|
95
|
-
/** Whether the code
|
|
106
|
+
/** Whether the code applies to the cart's current contents. A new code reads `false` until the server responds. */
|
|
96
107
|
applicable: boolean;
|
|
97
108
|
}
|
|
98
109
|
/** A validation error returned by a Storefront API cart mutation. */
|
|
99
110
|
interface CartUserError {
|
|
100
111
|
/** Machine-readable error code, or `null` for unclassified errors. */
|
|
101
112
|
code: CartErrorCode | null;
|
|
113
|
+
/** Human-readable error text from the Storefront API. */
|
|
102
114
|
message: string;
|
|
103
|
-
/**
|
|
115
|
+
/** The path to the input field that caused the error, such as `["lines", "0", "quantity"]`. */
|
|
104
116
|
field?: string[];
|
|
105
117
|
}
|
|
106
118
|
/** A non-blocking warning returned by a Storefront API cart mutation. */
|
|
107
119
|
interface CartWarning {
|
|
120
|
+
/** The warning code from the Storefront API. */
|
|
108
121
|
code: CartWarningCode;
|
|
122
|
+
/** Human-readable warning text from the Storefront API. */
|
|
109
123
|
message: string;
|
|
110
124
|
}
|
|
111
|
-
/** Errors and warnings from
|
|
125
|
+
/** Errors and warnings from one cart change. */
|
|
112
126
|
interface CartErrorGroup {
|
|
127
|
+
/** Validation errors that the mutation returned. */
|
|
113
128
|
userErrors: CartUserError[];
|
|
129
|
+
/** Non-blocking warnings that the mutation returned. */
|
|
114
130
|
warnings: CartWarning[];
|
|
115
131
|
}
|
|
116
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* A failed cart request, such as a non-2xx response or a timeout. Canceled requests add no entry.
|
|
134
|
+
*/
|
|
117
135
|
interface CartNetworkEntry {
|
|
136
|
+
/** The error message, or a generic message when the failure has no message of its own. */
|
|
118
137
|
message: string;
|
|
119
|
-
/** HTTP status code when
|
|
138
|
+
/** The HTTP status code, when the endpoint returned a non-2xx response. */
|
|
120
139
|
status?: number;
|
|
121
140
|
}
|
|
122
|
-
/** A key-value pair attached to the cart or to an individual
|
|
141
|
+
/** A key-value pair attached to the cart or to an individual cart line. */
|
|
123
142
|
interface Attribute {
|
|
143
|
+
/** The attribute name. Look up the attribute's errors with this name. */
|
|
124
144
|
key: string;
|
|
145
|
+
/** The attribute value. */
|
|
125
146
|
value: string | null;
|
|
126
147
|
}
|
|
127
148
|
/**
|
|
128
|
-
*
|
|
149
|
+
* Shows which parts of the cart have changes in flight.
|
|
129
150
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* use it to show pending UI on price displays without computing optimistic amounts.
|
|
151
|
+
* Check a line ID or a discount code to show a pending indicator on that item.
|
|
152
|
+
* Check `cost` to show pending UI on prices, which update only when the server
|
|
153
|
+
* responds.
|
|
134
154
|
*
|
|
135
155
|
* @example
|
|
136
156
|
* ```ts
|
|
@@ -148,64 +168,73 @@ interface Attribute {
|
|
|
148
168
|
* ```
|
|
149
169
|
*/
|
|
150
170
|
interface CartPending {
|
|
151
|
-
/** Line IDs with
|
|
171
|
+
/** Line IDs with an add, quantity change, or removal in flight. A new line has an ID that starts with `optimistic:` until the server confirms the line. */
|
|
152
172
|
lines: Set<string>;
|
|
173
|
+
/** `true` while a note update is in flight. */
|
|
153
174
|
note: boolean;
|
|
175
|
+
/** `true` while an attribute update is in flight. */
|
|
154
176
|
attributes: boolean;
|
|
155
|
-
/** Discount codes with
|
|
177
|
+
/** Discount codes with an apply or remove in flight. */
|
|
156
178
|
discountCodes: Set<string>;
|
|
157
|
-
/** `true`
|
|
179
|
+
/** `true` while a change that can affect cart prices is in flight. */
|
|
158
180
|
cost?: boolean;
|
|
159
181
|
}
|
|
160
182
|
/**
|
|
161
|
-
*
|
|
183
|
+
* The cart's errors, grouped by the part of the cart that they affect: lines, the note,
|
|
184
|
+
* attributes, discount codes, or the cart as a whole. Each group has a timestamp in
|
|
185
|
+
* milliseconds since the epoch. Use the timestamps to flag stale errors or dismiss
|
|
186
|
+
* errors after a timeout.
|
|
162
187
|
*
|
|
163
|
-
*
|
|
164
|
-
* `discountCodes`, or `cart` (for cross-cutting errors). Each bucket carries a
|
|
165
|
-
* `*UpdatedAt` timestamp (ms since epoch) so the UI can show stale-error indicators
|
|
166
|
-
* or auto-dismiss after a timeout.
|
|
167
|
-
*
|
|
168
|
-
* `network` collects transport-level failures (timeouts, 5xx) separately from
|
|
169
|
-
* Storefront API user errors.
|
|
188
|
+
* Failed requests go in a network list, apart from Storefront API user errors.
|
|
170
189
|
*/
|
|
171
190
|
interface CartErrorState {
|
|
172
|
-
/**
|
|
191
|
+
/** Errors that don't belong to a line, the note, an attribute, or a discount code. */
|
|
173
192
|
cart: CartErrorGroup;
|
|
174
|
-
/** Errors keyed by
|
|
193
|
+
/** Errors keyed by cart line ID. */
|
|
175
194
|
lines: Map<string, CartErrorGroup>;
|
|
195
|
+
/** Errors for the cart note. */
|
|
176
196
|
note: CartErrorGroup;
|
|
177
|
-
/** Errors keyed by
|
|
197
|
+
/** Errors keyed by attribute name. */
|
|
178
198
|
attributes: Map<string, CartErrorGroup>;
|
|
179
|
-
/** Errors keyed by discount code
|
|
199
|
+
/** Errors keyed by discount code. */
|
|
180
200
|
discountCodes: Map<string, CartErrorGroup>;
|
|
201
|
+
/**
|
|
202
|
+
* Failed cart requests. A failed cart change adds an entry, with an HTTP status when the endpoint returned a non-2xx response. A failed refresh adds an entry with a generic message and no status. A failed first load or a failed load after a reset adds no entry.
|
|
203
|
+
*/
|
|
181
204
|
network: CartNetworkEntry[];
|
|
205
|
+
/** Time in milliseconds since the epoch when the store last recorded any error, or `0` before the first. */
|
|
182
206
|
lastUpdatedAt: number;
|
|
207
|
+
/** Time in milliseconds since the epoch of the last line, discount code, or attribute error, or `0` before any. */
|
|
183
208
|
cartUpdatedAt: number;
|
|
209
|
+
/** Time in milliseconds since the epoch when the store last recorded line errors, or `0` before any. */
|
|
184
210
|
linesUpdatedAt: number;
|
|
211
|
+
/** Time in milliseconds since the epoch when the store last recorded note errors, or `0` before any. */
|
|
185
212
|
noteUpdatedAt: number;
|
|
213
|
+
/** Time in milliseconds since the epoch when the store last recorded attribute errors, or `0` before any. */
|
|
186
214
|
attributesUpdatedAt: number;
|
|
215
|
+
/** Time in milliseconds since the epoch when the store last recorded discount code errors, or `0` before any. */
|
|
187
216
|
discountCodesUpdatedAt: number;
|
|
217
|
+
/** Time in milliseconds since the epoch when the store last recorded a network error, or `0` before any. */
|
|
188
218
|
networkUpdatedAt: number;
|
|
189
219
|
}
|
|
190
220
|
/**
|
|
191
|
-
*
|
|
221
|
+
* The customer's cart, in the shape that the Storefront API returns.
|
|
192
222
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* The index signature allows custom cart query fields to pass through.
|
|
223
|
+
* Cart costs come only from the server. Extra fields from your custom cart
|
|
224
|
+
* fragment appear unchanged.
|
|
196
225
|
*/
|
|
197
226
|
interface CartData {
|
|
198
|
-
/** Storefront API
|
|
227
|
+
/** The cart's Storefront API GID, or `null` when no cart exists yet. */
|
|
199
228
|
id: string | null;
|
|
200
|
-
/**
|
|
229
|
+
/** The cart's last update time in ISO 8601 format. Absent until the first server response. */
|
|
201
230
|
updatedAt?: string;
|
|
202
|
-
/** Shopify checkout URL.
|
|
231
|
+
/** The Shopify checkout URL. The URL can change when the customer logs in or out, or changes tracking consent. */
|
|
203
232
|
checkoutUrl?: string | null;
|
|
204
233
|
/** Sum of all line quantities. */
|
|
205
234
|
totalQuantity: number;
|
|
206
|
-
/**
|
|
235
|
+
/** The cart's subtotal, total, and checkout charge. */
|
|
207
236
|
cost: CartCost;
|
|
208
|
-
/**
|
|
237
|
+
/** Customer-supplied cart note, or `null` or empty when unset. */
|
|
209
238
|
note?: string | null;
|
|
210
239
|
/** Cart-level custom attributes. */
|
|
211
240
|
attributes: Attribute[];
|
|
@@ -213,15 +242,14 @@ interface CartData {
|
|
|
213
242
|
lines: CartLineConnection;
|
|
214
243
|
/** Discount codes applied to the cart, with their applicability. */
|
|
215
244
|
discountCodes: DiscountCode[];
|
|
245
|
+
/** Extra cart fields from your custom cart fragment, unchanged. */
|
|
216
246
|
[key: string]: unknown;
|
|
217
247
|
}
|
|
218
248
|
/**
|
|
219
|
-
*
|
|
249
|
+
* The cart, plus what's loading, pending, and failed.
|
|
220
250
|
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* flows from your server handler configuration, so `data` is typed to match
|
|
224
|
-
* your custom cart query.
|
|
251
|
+
* The cart hooks return values from this state. The data type matches the cart
|
|
252
|
+
* fragment in your cart server handlers.
|
|
225
253
|
*
|
|
226
254
|
* @example
|
|
227
255
|
* ```ts
|
|
@@ -241,29 +269,47 @@ interface CartData {
|
|
|
241
269
|
* ```
|
|
242
270
|
*/
|
|
243
271
|
interface CartState<TData extends CartData = CartData> {
|
|
244
|
-
/** The
|
|
272
|
+
/** The cart, including changes that the server hasn't confirmed yet. */
|
|
245
273
|
data: TData;
|
|
246
|
-
/** `true`
|
|
274
|
+
/** `true` while the store loads the full cart: the first load, a load after `reset()`, or before `connect()` when the store has no initial data. */
|
|
247
275
|
loading: boolean;
|
|
248
|
-
/**
|
|
276
|
+
/** Present while a full cart load runs. The promise resolves, and never rejects, when the load finishes or the store drops the load. */
|
|
249
277
|
readonly readyPromise?: PromiseLike<void>;
|
|
250
|
-
/**
|
|
278
|
+
/** The parts of the cart with changes in flight. */
|
|
251
279
|
pending: CartPending;
|
|
252
|
-
/** `true`
|
|
280
|
+
/** `true` while the store reloads the cart in the background after overlapping cart changes or a `refresh()` call. */
|
|
253
281
|
revalidating?: boolean;
|
|
254
|
-
/**
|
|
282
|
+
/** Errors and warnings, grouped by the part of the cart that they affect. */
|
|
255
283
|
errors: CartErrorState;
|
|
256
284
|
}
|
|
257
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
* Creates an empty error group with no user errors and no warnings.
|
|
287
|
+
*
|
|
288
|
+
* @returns A new error group with empty user error and warning arrays.
|
|
289
|
+
* @publicDocs
|
|
290
|
+
*/
|
|
258
291
|
declare function createEmptyErrorGroup(): CartErrorGroup;
|
|
259
|
-
/**
|
|
292
|
+
/**
|
|
293
|
+
* Creates a cart error state with no errors and every timestamp at `0`.
|
|
294
|
+
*
|
|
295
|
+
* Each call returns new groups, maps, and arrays.
|
|
296
|
+
*
|
|
297
|
+
* @returns A new, empty error state.
|
|
298
|
+
* @publicDocs
|
|
299
|
+
*/
|
|
260
300
|
declare function createEmptyCartErrors(): CartErrorState;
|
|
261
301
|
/**
|
|
262
|
-
* Frozen
|
|
263
|
-
* zero-amount costs.
|
|
302
|
+
* Frozen cart data for an empty cart, with a `null` ID, zero quantities, and
|
|
303
|
+
* zero-amount costs. A cart store without initial data starts from this cart.
|
|
304
|
+
*
|
|
305
|
+
* @publicDocs
|
|
264
306
|
*/
|
|
265
307
|
declare const EMPTY_CART_DATA: CartData;
|
|
266
|
-
/**
|
|
308
|
+
/**
|
|
309
|
+
* Shared empty cart state backed by the empty cart data, with loading set to `true`.
|
|
310
|
+
*
|
|
311
|
+
* @publicDocs
|
|
312
|
+
*/
|
|
267
313
|
declare const EMPTY_CART_STATE: CartState;
|
|
268
314
|
//#endregion
|
|
269
315
|
export { Attribute, CartCost, CartData, CartErrorGroup, CartErrorState, CartLine, CartLineConnection, CartLineCost, CartLineMerchandise, CartNetworkEntry, CartPending, CartState, CartUserError, CartWarning, DiscountCode, EMPTY_CART_DATA, EMPTY_CART_STATE, createEmptyCartErrors, createEmptyErrorGroup };
|
package/dist/core/cart/state.mjs
CHANGED
|
@@ -8,14 +8,26 @@ function createEmptyPending() {
|
|
|
8
8
|
cost: false
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Creates an empty error group with no user errors and no warnings.
|
|
13
|
+
*
|
|
14
|
+
* @returns A new error group with empty user error and warning arrays.
|
|
15
|
+
* @publicDocs
|
|
16
|
+
*/
|
|
12
17
|
function createEmptyErrorGroup() {
|
|
13
18
|
return {
|
|
14
19
|
userErrors: [],
|
|
15
20
|
warnings: []
|
|
16
21
|
};
|
|
17
22
|
}
|
|
18
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Creates a cart error state with no errors and every timestamp at `0`.
|
|
25
|
+
*
|
|
26
|
+
* Each call returns new groups, maps, and arrays.
|
|
27
|
+
*
|
|
28
|
+
* @returns A new, empty error state.
|
|
29
|
+
* @publicDocs
|
|
30
|
+
*/
|
|
19
31
|
function createEmptyCartErrors() {
|
|
20
32
|
return {
|
|
21
33
|
cart: createEmptyErrorGroup(),
|
|
@@ -34,8 +46,10 @@ function createEmptyCartErrors() {
|
|
|
34
46
|
};
|
|
35
47
|
}
|
|
36
48
|
/**
|
|
37
|
-
* Frozen
|
|
38
|
-
* zero-amount costs.
|
|
49
|
+
* Frozen cart data for an empty cart, with a `null` ID, zero quantities, and
|
|
50
|
+
* zero-amount costs. A cart store without initial data starts from this cart.
|
|
51
|
+
*
|
|
52
|
+
* @publicDocs
|
|
39
53
|
*/
|
|
40
54
|
const EMPTY_CART_DATA = Object.freeze({
|
|
41
55
|
id: null,
|
|
@@ -68,7 +82,7 @@ function createCartState(data, { loading = false } = {}) {
|
|
|
68
82
|
errors: createEmptyCartErrors()
|
|
69
83
|
};
|
|
70
84
|
}
|
|
71
|
-
/** Creates an empty
|
|
85
|
+
/** Creates an empty cart state backed by the empty cart data. Loading defaults to `true`. */
|
|
72
86
|
function createEmptyCartState({ loading = true } = {}) {
|
|
73
87
|
return createCartState({
|
|
74
88
|
...EMPTY_CART_DATA,
|
|
@@ -76,7 +90,11 @@ function createEmptyCartState({ loading = true } = {}) {
|
|
|
76
90
|
discountCodes: []
|
|
77
91
|
}, { loading });
|
|
78
92
|
}
|
|
79
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Shared empty cart state backed by the empty cart data, with loading set to `true`.
|
|
95
|
+
*
|
|
96
|
+
* @publicDocs
|
|
97
|
+
*/
|
|
80
98
|
const EMPTY_CART_STATE = createEmptyCartState();
|
|
81
99
|
|
|
82
100
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/core/cart/state.ts"],"sourcesContent":["import type { CartErrorCode, CartWarningCode } from \"../../graphql/generated/storefront-api-types\";\n\n/** Storefront API monetary value — an amount string and ISO 4217 currency code. */\nexport interface Money {\n /** Decimal amount as a string (e.g. `\"29.99\"`). */\n amount: string;\n /** ISO 4217 currency code (e.g. `\"USD\"`, `\"EUR\"`). */\n currencyCode: string;\n}\n\n/** Cart-level cost breakdown returned by the Storefront API. */\nexport interface CartCost {\n /** The amount, before taxes and cart-level discounts, for the customer to pay. */\n subtotalAmount: Money;\n /** Final amount the buyer pays at checkout. */\n totalAmount: Money;\n /** Estimated amount due at checkout, excluding deferred payments. Equals the subtotal when no deferred payments exist. */\n checkoutChargeAmount: Money;\n}\n\nexport interface CartLineCost {\n /** Line total after all applicable discounts. */\n totalAmount: Money;\n /** Line subtotal before line-level discounts. */\n subtotalAmount: Money;\n /** Unit price for a single quantity of this line. */\n amountPerQuantity: Money;\n /** Original compare-at unit price, or `null` when no comparison exists. */\n compareAtAmountPerQuantity: Money | null;\n}\n\n/** Product variant information attached to a {@link CartLine}. */\nexport interface CartLineMerchandise {\n /** Storefront API GID of the product variant. */\n id: string;\n /** Variant title (e.g. `\"Small / Black\"`). */\n title?: string;\n /** Selected variant option name/value pairs (e.g. `{ name: \"Size\", value: \"S\" }`). */\n selectedOptions?: Array<{ name: string; value: string }>;\n product: {\n title: string;\n handle?: string;\n [key: string]: unknown;\n };\n image?: {\n id?: string | null;\n url: string;\n altText?: string | null;\n width?: number | null;\n height?: number | null;\n [key: string]: unknown;\n } | null;\n quantityAvailable?: number | null;\n [key: string]: unknown;\n}\n\n/**\n * A single line item in the cart.\n *\n * Each line represents a product variant at a given quantity. Lines may carry\n * custom {@link Attribute | attributes}, a selling plan allocation (subscriptions),\n * or nested {@link CartLine.lineComponents | line components} (bundles).\n */\nexport interface CartLine {\n /** Storefront API GID of this cart line — used as the key in {@link CartPending.lines}. */\n id: string;\n /** Number of units of this merchandise in the cart. */\n quantity: number;\n attributes?: Attribute[];\n /** Per-line cost breakdown from the Storefront API. */\n cost: CartLineCost;\n /** The product variant this line represents. */\n merchandise?: CartLineMerchandise;\n /** Subscription selling plan allocation, or `null` for one-time purchases. */\n sellingPlanAllocation?: { sellingPlan: { id: string } } | null;\n parentRelationship?: { parent: { id: string } } | null;\n /** Nested child lines when this line is a bundle parent. */\n lineComponents?: CartLine[];\n}\n\nexport interface CartLineConnection {\n nodes: CartLine[];\n [key: string]: unknown;\n}\n\n/** A discount code applied to the cart. */\nexport interface DiscountCode {\n code: string;\n /** Whether the code is applicable to the cart's current contents. Set optimistically to `false` for newly added codes until the server confirms. */\n applicable: boolean;\n}\n\n/** A validation error returned by a Storefront API cart mutation. */\nexport interface CartUserError {\n /** Machine-readable error code, or `null` for unclassified errors. */\n code: CartErrorCode | null;\n message: string;\n /** JSONPath to the input field that caused the error (e.g. `[\"lines\", \"0\", \"quantity\"]`). */\n field?: string[];\n}\n\n/** A non-blocking warning returned by a Storefront API cart mutation. */\nexport interface CartWarning {\n code: CartWarningCode;\n message: string;\n}\n\n/** Errors and warnings from a single cart mutation response. */\nexport interface CartErrorGroup {\n userErrors: CartUserError[];\n warnings: CartWarning[];\n}\n\n/** A network-level error encountered during a cart operation (e.g. non-2xx response, timeout). Aborted requests are not recorded. */\nexport interface CartNetworkEntry {\n message: string;\n /** HTTP status code when available. */\n status?: number;\n}\n\n/** A key-value pair attached to the cart or to an individual {@link CartLine}. */\nexport interface Attribute {\n key: string;\n value: string | null;\n}\n\n/**\n * Tracks which parts of the cart have in-flight mutations.\n *\n * `lines` and `discountCodes` are `Set<string>` keyed by line ID / discount code,\n * enabling per-item pending indicators rather than a single global spinner.\n * `cost` is a boolean because *any* line or discount change affects the total —\n * use it to show pending UI on price displays without computing optimistic amounts.\n *\n * @example\n * ```ts\n * const { pending } = store.getState();\n *\n * // Per-line-item pending indicator\n * if (pending.lines.has(lineId)) {\n * showSpinner(lineId);\n * }\n *\n * // Cart total is stale — show pending UI, don't compute a price\n * if (pending.cost) {\n * dimTotalDisplay();\n * }\n * ```\n */\nexport interface CartPending {\n /** Line IDs with in-flight add, quantity, or remove mutations. New lines use their `optimistic:` ID until the server confirms. */\n lines: Set<string>;\n note: boolean;\n attributes: boolean;\n /** Discount codes with in-flight apply/remove mutations. */\n discountCodes: Set<string>;\n /** `true` when any mutation may affect cart pricing — show pending UI on cost displays. */\n cost?: boolean;\n}\n\n/**\n * Per-resource error tracking for the cart.\n *\n * Errors are bucketed by the resource they affect — `lines`, `note`, `attributes`,\n * `discountCodes`, or `cart` (for cross-cutting errors). Each bucket carries a\n * `*UpdatedAt` timestamp (ms since epoch) so the UI can show stale-error indicators\n * or auto-dismiss after a timeout.\n *\n * `network` collects transport-level failures (timeouts, 5xx) separately from\n * Storefront API user errors.\n */\nexport interface CartErrorState {\n /** Cross-cutting cart errors not attributable to a specific resource. */\n cart: CartErrorGroup;\n /** Errors keyed by {@link CartLine.id}. */\n lines: Map<string, CartErrorGroup>;\n note: CartErrorGroup;\n /** Errors keyed by {@link Attribute.key}. */\n attributes: Map<string, CartErrorGroup>;\n /** Errors keyed by discount code string. */\n discountCodes: Map<string, CartErrorGroup>;\n network: CartNetworkEntry[];\n lastUpdatedAt: number;\n cartUpdatedAt: number;\n linesUpdatedAt: number;\n noteUpdatedAt: number;\n attributesUpdatedAt: number;\n discountCodesUpdatedAt: number;\n networkUpdatedAt: number;\n}\n\n/**\n * Cart data returned by the Storefront API.\n *\n * This is the server's authoritative snapshot — prices, discount applicability,\n * and totals come exclusively from here, never from client-side computation.\n * The index signature allows custom cart query fields to pass through.\n */\nexport interface CartData {\n /** Storefront API Cart GID, or `null` when no cart exists yet. */\n id: string | null;\n /** `Cart.updatedAt` (ISO 8601). Absent until the first server response. */\n updatedAt?: string;\n /** Shopify checkout URL. Changes when buyer identity or consent state changes. */\n checkoutUrl?: string | null;\n /** Sum of all line quantities. */\n totalQuantity: number;\n /** Cart-level cost breakdown (subtotal, total, checkout charge). */\n cost: CartCost;\n /** Buyer-supplied cart note, or `null`/empty when unset. */\n note?: string | null;\n /** Cart-level custom attributes. */\n attributes: Attribute[];\n /** The cart's line items. */\n lines: CartLineConnection;\n /** Discount codes applied to the cart, with their applicability. */\n discountCodes: DiscountCode[];\n [key: string]: unknown;\n}\n\n/**\n * Full observable state of the cart store.\n *\n * Framework adapters subscribe to this via `CartStore.subscribe` (or the\n * framework-specific hooks like `useCart`). The generic `TData` parameter\n * flows from your server handler configuration, so `data` is typed to match\n * your custom cart query.\n *\n * @example\n * ```ts\n * const state = store.getState();\n *\n * if (state.loading) {\n * // Initial cart load in progress — show skeleton\n * }\n *\n * if (state.pending.lines.size > 0) {\n * // One or more lines are mid-mutation — show per-line spinners\n * }\n *\n * if (state.errors.network.length > 0) {\n * // Network errors occurred — show retry prompt\n * }\n * ```\n */\nexport interface CartState<TData extends CartData = CartData> {\n /** The latest server-confirmed cart data, with optimistic projections applied on top. */\n data: TData;\n /** `true` during a full-cart fetch — initial load, after `reset()`, or before connect with no `initialData`. */\n loading: boolean;\n /** Non-rejecting signal that resolves when the current full-cart load settles or is invalidated. */\n readonly readyPromise?: PromiseLike<void>;\n /** Per-resource in-flight mutation tracking. */\n pending: CartPending;\n /** `true` when a background revalidation is in flight (triggered by overlapping mutations or `refresh()`). */\n revalidating?: boolean;\n /** Per-resource error and warning state. */\n errors: CartErrorState;\n}\n\nexport function createEmptyPending(): CartPending {\n return {\n lines: new Set(),\n note: false,\n attributes: false,\n discountCodes: new Set(),\n cost: false,\n };\n}\n\n/** Creates an empty {@link CartErrorGroup} — no user errors, no warnings. */\nexport function createEmptyErrorGroup(): CartErrorGroup {\n return { userErrors: [], warnings: [] };\n}\n\n/** Creates an empty {@link CartErrorState} — all timestamps at `0`, all buckets empty. */\nexport function createEmptyCartErrors(): CartErrorState {\n return {\n cart: createEmptyErrorGroup(),\n lines: new Map(),\n note: createEmptyErrorGroup(),\n attributes: new Map(),\n discountCodes: new Map(),\n network: [],\n lastUpdatedAt: 0,\n cartUpdatedAt: 0,\n linesUpdatedAt: 0,\n noteUpdatedAt: 0,\n attributesUpdatedAt: 0,\n discountCodesUpdatedAt: 0,\n networkUpdatedAt: 0,\n };\n}\n\n/**\n * Frozen {@link CartData} representing an empty cart — `id: null`, zero quantities,\n * zero-amount costs. Used as the initial/fallback value before the first server response.\n */\nexport const EMPTY_CART_DATA: CartData = Object.freeze({\n id: null,\n checkoutUrl: null,\n totalQuantity: 0,\n cost: Object.freeze({\n subtotalAmount: Object.freeze({ amount: \"0\", currencyCode: \"\" }),\n totalAmount: Object.freeze({ amount: \"0\", currencyCode: \"\" }),\n checkoutChargeAmount: Object.freeze({ amount: \"0\", currencyCode: \"\" }),\n }),\n note: \"\",\n attributes: [] as Attribute[],\n lines: Object.freeze({ nodes: [] as CartLine[] }),\n discountCodes: [] as DiscountCode[],\n});\n\nexport function createCartState<TData extends CartData>(\n data: TData,\n { loading = false }: { loading?: boolean } = {},\n): CartState<TData> {\n return {\n data,\n loading,\n pending: createEmptyPending(),\n errors: createEmptyCartErrors(),\n };\n}\n\n/** Creates an empty {@link CartState} backed by {@link EMPTY_CART_DATA}. Defaults to `loading: true`. */\nexport function createEmptyCartState({ loading = true }: { loading?: boolean } = {}): CartState {\n return createCartState(\n {\n ...EMPTY_CART_DATA,\n lines: { nodes: [] },\n discountCodes: [],\n },\n { loading },\n );\n}\n\n/** Shared empty {@link CartState} — backed by {@link EMPTY_CART_DATA}, defaults to `loading: true`. */\nexport const EMPTY_CART_STATE: CartState = createEmptyCartState();\n"],"mappings":";AAoQA,SAAgB,qBAAkC;AAChD,QAAO;EACL,uBAAO,IAAI,KAAK;EAChB,MAAM;EACN,YAAY;EACZ,+BAAe,IAAI,KAAK;EACxB,MAAM;EACP;;;AAIH,SAAgB,wBAAwC;AACtD,QAAO;EAAE,YAAY,EAAE;EAAE,UAAU,EAAE;EAAE;;;AAIzC,SAAgB,wBAAwC;AACtD,QAAO;EACL,MAAM,uBAAuB;EAC7B,uBAAO,IAAI,KAAK;EAChB,MAAM,uBAAuB;EAC7B,4BAAY,IAAI,KAAK;EACrB,+BAAe,IAAI,KAAK;EACxB,SAAS,EAAE;EACX,eAAe;EACf,eAAe;EACf,gBAAgB;EAChB,eAAe;EACf,qBAAqB;EACrB,wBAAwB;EACxB,kBAAkB;EACnB;;;;;;AAOH,MAAa,kBAA4B,OAAO,OAAO;CACrD,IAAI;CACJ,aAAa;CACb,eAAe;CACf,MAAM,OAAO,OAAO;EAClB,gBAAgB,OAAO,OAAO;GAAE,QAAQ;GAAK,cAAc;GAAI,CAAC;EAChE,aAAa,OAAO,OAAO;GAAE,QAAQ;GAAK,cAAc;GAAI,CAAC;EAC7D,sBAAsB,OAAO,OAAO;GAAE,QAAQ;GAAK,cAAc;GAAI,CAAC;EACvE,CAAC;CACF,MAAM;CACN,YAAY,EAAE;CACd,OAAO,OAAO,OAAO,EAAE,OAAO,EAAE,EAAgB,CAAC;CACjD,eAAe,EAAE;CAClB,CAAC;AAEF,SAAgB,gBACd,MACA,EAAE,UAAU,UAAiC,EAAE,EAC7B;AAClB,QAAO;EACL;EACA;EACA,SAAS,oBAAoB;EAC7B,QAAQ,uBAAuB;EAChC;;;AAIH,SAAgB,qBAAqB,EAAE,UAAU,SAAgC,EAAE,EAAa;AAC9F,QAAO,gBACL;EACE,GAAG;EACH,OAAO,EAAE,OAAO,EAAE,EAAE;EACpB,eAAe,EAAE;EAClB,EACD,EAAE,SAAS,CACZ;;;AAIH,MAAa,mBAA8B,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/core/cart/state.ts"],"sourcesContent":["import type { CartErrorCode, CartWarningCode } from \"../../graphql/generated/storefront-api-types\";\n\n/** A monetary value from the Storefront API. */\nexport interface Money {\n /** The decimal amount as a string, such as `29.99`. */\n amount: string;\n /** The ISO 4217 currency code, such as `USD`. */\n currencyCode: string;\n}\n\n/** The cart's costs from the Storefront API. */\nexport interface CartCost {\n /** The amount, before taxes and cart-level discounts, for the customer to pay. */\n subtotalAmount: Money;\n /** Final amount the customer pays at checkout. */\n totalAmount: Money;\n /** Estimated amount due at checkout, excluding deferred payments. Equals the subtotal when no deferred payments exist. */\n checkoutChargeAmount: Money;\n}\n\n/** A cart line's costs from the Storefront API. */\nexport interface CartLineCost {\n /** Line total after all applicable discounts. */\n totalAmount: Money;\n /** Line subtotal before line-level discounts. */\n subtotalAmount: Money;\n /** Unit price for a single quantity of this line. */\n amountPerQuantity: Money;\n /** Original compare-at unit price, or `null` when no comparison exists. */\n compareAtAmountPerQuantity: Money | null;\n}\n\n/** The product variant on a cart line. */\nexport interface CartLineMerchandise {\n /** Storefront API GID of the product variant. */\n id: string;\n /** The variant title, such as `\"Small / Black\"`. */\n title?: string;\n /** The variant's selected options as name and value pairs. */\n selectedOptions?: Array<{ name: string; value: string }>;\n /** The product that the variant belongs to. */\n product: {\n title: string;\n handle?: string;\n [key: string]: unknown;\n };\n /** The variant image that the cart query selects. */\n image?: {\n id?: string | null;\n url: string;\n altText?: string | null;\n width?: number | null;\n height?: number | null;\n [key: string]: unknown;\n } | null;\n /** Units available for sale. When your cart fragment selects the field, the store caps the quantity of a `set` submission at this number. */\n quantityAvailable?: number | null;\n /** Extra variant fields from your custom cart fragment, unchanged. */\n [key: string]: unknown;\n}\n\n/**\n * A single line item in the cart.\n *\n * Each line holds a product variant at a quantity. A line can carry custom\n * attributes, a selling plan allocation for a subscription, or line components\n * for a bundle.\n */\nexport interface CartLine {\n /** The cart line's Storefront API GID. Look up the line's pending state and errors with this ID. */\n id: string;\n /** Number of units of this merchandise in the cart. */\n quantity: number;\n /** Custom key-value attributes attached to the line. */\n attributes?: Attribute[];\n /** Per-line cost breakdown from the Storefront API. */\n cost: CartLineCost;\n /** The product variant on the line. */\n merchandise?: CartLineMerchandise;\n /** Subscription selling plan allocation, or `null` for one-time purchases. */\n sellingPlanAllocation?: { sellingPlan: { id: string } } | null;\n /** The parent line's ID when this line is a bundle component. */\n parentRelationship?: { parent: { id: string } } | null;\n /** Nested child lines when this line is a bundle parent. */\n lineComponents?: CartLine[];\n}\n\n/** The cart's line items in the Storefront API connection shape. */\nexport interface CartLineConnection {\n /** The cart lines that the cart query returns. */\n nodes: CartLine[];\n /** Extra connection fields from your custom cart fragment, unchanged. */\n [key: string]: unknown;\n}\n\n/** A discount code applied to the cart. */\nexport interface DiscountCode {\n /** The discount code text. Look up the code's pending state and errors with this value. */\n code: string;\n /** Whether the code applies to the cart's current contents. A new code reads `false` until the server responds. */\n applicable: boolean;\n}\n\n/** A validation error returned by a Storefront API cart mutation. */\nexport interface CartUserError {\n /** Machine-readable error code, or `null` for unclassified errors. */\n code: CartErrorCode | null;\n /** Human-readable error text from the Storefront API. */\n message: string;\n /** The path to the input field that caused the error, such as `[\"lines\", \"0\", \"quantity\"]`. */\n field?: string[];\n}\n\n/** A non-blocking warning returned by a Storefront API cart mutation. */\nexport interface CartWarning {\n /** The warning code from the Storefront API. */\n code: CartWarningCode;\n /** Human-readable warning text from the Storefront API. */\n message: string;\n}\n\n/** Errors and warnings from one cart change. */\nexport interface CartErrorGroup {\n /** Validation errors that the mutation returned. */\n userErrors: CartUserError[];\n /** Non-blocking warnings that the mutation returned. */\n warnings: CartWarning[];\n}\n\n/**\n * A failed cart request, such as a non-2xx response or a timeout. Canceled requests add no entry.\n */\nexport interface CartNetworkEntry {\n /** The error message, or a generic message when the failure has no message of its own. */\n message: string;\n /** The HTTP status code, when the endpoint returned a non-2xx response. */\n status?: number;\n}\n\n/** A key-value pair attached to the cart or to an individual cart line. */\nexport interface Attribute {\n /** The attribute name. Look up the attribute's errors with this name. */\n key: string;\n /** The attribute value. */\n value: string | null;\n}\n\n/**\n * Shows which parts of the cart have changes in flight.\n *\n * Check a line ID or a discount code to show a pending indicator on that item.\n * Check `cost` to show pending UI on prices, which update only when the server\n * responds.\n *\n * @example\n * ```ts\n * const { pending } = store.getState();\n *\n * // Per-line-item pending indicator\n * if (pending.lines.has(lineId)) {\n * showSpinner(lineId);\n * }\n *\n * // Cart total is stale — show pending UI, don't compute a price\n * if (pending.cost) {\n * dimTotalDisplay();\n * }\n * ```\n */\nexport interface CartPending {\n /** Line IDs with an add, quantity change, or removal in flight. A new line has an ID that starts with `optimistic:` until the server confirms the line. */\n lines: Set<string>;\n /** `true` while a note update is in flight. */\n note: boolean;\n /** `true` while an attribute update is in flight. */\n attributes: boolean;\n /** Discount codes with an apply or remove in flight. */\n discountCodes: Set<string>;\n /** `true` while a change that can affect cart prices is in flight. */\n cost?: boolean;\n}\n\n/**\n * The cart's errors, grouped by the part of the cart that they affect: lines, the note,\n * attributes, discount codes, or the cart as a whole. Each group has a timestamp in\n * milliseconds since the epoch. Use the timestamps to flag stale errors or dismiss\n * errors after a timeout.\n *\n * Failed requests go in a network list, apart from Storefront API user errors.\n */\nexport interface CartErrorState {\n /** Errors that don't belong to a line, the note, an attribute, or a discount code. */\n cart: CartErrorGroup;\n /** Errors keyed by cart line ID. */\n lines: Map<string, CartErrorGroup>;\n /** Errors for the cart note. */\n note: CartErrorGroup;\n /** Errors keyed by attribute name. */\n attributes: Map<string, CartErrorGroup>;\n /** Errors keyed by discount code. */\n discountCodes: Map<string, CartErrorGroup>;\n /**\n * Failed cart requests. A failed cart change adds an entry, with an HTTP status when the endpoint returned a non-2xx response. A failed refresh adds an entry with a generic message and no status. A failed first load or a failed load after a reset adds no entry.\n */\n network: CartNetworkEntry[];\n /** Time in milliseconds since the epoch when the store last recorded any error, or `0` before the first. */\n lastUpdatedAt: number;\n /** Time in milliseconds since the epoch of the last line, discount code, or attribute error, or `0` before any. */\n cartUpdatedAt: number;\n /** Time in milliseconds since the epoch when the store last recorded line errors, or `0` before any. */\n linesUpdatedAt: number;\n /** Time in milliseconds since the epoch when the store last recorded note errors, or `0` before any. */\n noteUpdatedAt: number;\n /** Time in milliseconds since the epoch when the store last recorded attribute errors, or `0` before any. */\n attributesUpdatedAt: number;\n /** Time in milliseconds since the epoch when the store last recorded discount code errors, or `0` before any. */\n discountCodesUpdatedAt: number;\n /** Time in milliseconds since the epoch when the store last recorded a network error, or `0` before any. */\n networkUpdatedAt: number;\n}\n\n/**\n * The customer's cart, in the shape that the Storefront API returns.\n *\n * Cart costs come only from the server. Extra fields from your custom cart\n * fragment appear unchanged.\n */\nexport interface CartData {\n /** The cart's Storefront API GID, or `null` when no cart exists yet. */\n id: string | null;\n /** The cart's last update time in ISO 8601 format. Absent until the first server response. */\n updatedAt?: string;\n /** The Shopify checkout URL. The URL can change when the customer logs in or out, or changes tracking consent. */\n checkoutUrl?: string | null;\n /** Sum of all line quantities. */\n totalQuantity: number;\n /** The cart's subtotal, total, and checkout charge. */\n cost: CartCost;\n /** Customer-supplied cart note, or `null` or empty when unset. */\n note?: string | null;\n /** Cart-level custom attributes. */\n attributes: Attribute[];\n /** The cart's line items. */\n lines: CartLineConnection;\n /** Discount codes applied to the cart, with their applicability. */\n discountCodes: DiscountCode[];\n /** Extra cart fields from your custom cart fragment, unchanged. */\n [key: string]: unknown;\n}\n\n/**\n * The cart, plus what's loading, pending, and failed.\n *\n * The cart hooks return values from this state. The data type matches the cart\n * fragment in your cart server handlers.\n *\n * @example\n * ```ts\n * const state = store.getState();\n *\n * if (state.loading) {\n * // Initial cart load in progress — show skeleton\n * }\n *\n * if (state.pending.lines.size > 0) {\n * // One or more lines are mid-mutation — show per-line spinners\n * }\n *\n * if (state.errors.network.length > 0) {\n * // Network errors occurred — show retry prompt\n * }\n * ```\n */\nexport interface CartState<TData extends CartData = CartData> {\n /** The cart, including changes that the server hasn't confirmed yet. */\n data: TData;\n /** `true` while the store loads the full cart: the first load, a load after `reset()`, or before `connect()` when the store has no initial data. */\n loading: boolean;\n /** Present while a full cart load runs. The promise resolves, and never rejects, when the load finishes or the store drops the load. */\n readonly readyPromise?: PromiseLike<void>;\n /** The parts of the cart with changes in flight. */\n pending: CartPending;\n /** `true` while the store reloads the cart in the background after overlapping cart changes or a `refresh()` call. */\n revalidating?: boolean;\n /** Errors and warnings, grouped by the part of the cart that they affect. */\n errors: CartErrorState;\n}\n\nexport function createEmptyPending(): CartPending {\n return {\n lines: new Set(),\n note: false,\n attributes: false,\n discountCodes: new Set(),\n cost: false,\n };\n}\n\n/**\n * Creates an empty error group with no user errors and no warnings.\n *\n * @returns A new error group with empty user error and warning arrays.\n * @publicDocs\n */\nexport function createEmptyErrorGroup(): CartErrorGroup {\n return { userErrors: [], warnings: [] };\n}\n\n/**\n * Creates a cart error state with no errors and every timestamp at `0`.\n *\n * Each call returns new groups, maps, and arrays.\n *\n * @returns A new, empty error state.\n * @publicDocs\n */\nexport function createEmptyCartErrors(): CartErrorState {\n return {\n cart: createEmptyErrorGroup(),\n lines: new Map(),\n note: createEmptyErrorGroup(),\n attributes: new Map(),\n discountCodes: new Map(),\n network: [],\n lastUpdatedAt: 0,\n cartUpdatedAt: 0,\n linesUpdatedAt: 0,\n noteUpdatedAt: 0,\n attributesUpdatedAt: 0,\n discountCodesUpdatedAt: 0,\n networkUpdatedAt: 0,\n };\n}\n\n/**\n * Frozen cart data for an empty cart, with a `null` ID, zero quantities, and\n * zero-amount costs. A cart store without initial data starts from this cart.\n *\n * @publicDocs\n */\nexport const EMPTY_CART_DATA: CartData = Object.freeze({\n id: null,\n checkoutUrl: null,\n totalQuantity: 0,\n cost: Object.freeze({\n subtotalAmount: Object.freeze({ amount: \"0\", currencyCode: \"\" }),\n totalAmount: Object.freeze({ amount: \"0\", currencyCode: \"\" }),\n checkoutChargeAmount: Object.freeze({ amount: \"0\", currencyCode: \"\" }),\n }),\n note: \"\",\n attributes: [] as Attribute[],\n lines: Object.freeze({ nodes: [] as CartLine[] }),\n discountCodes: [] as DiscountCode[],\n});\n\nexport function createCartState<TData extends CartData>(\n data: TData,\n { loading = false }: { loading?: boolean } = {},\n): CartState<TData> {\n return {\n data,\n loading,\n pending: createEmptyPending(),\n errors: createEmptyCartErrors(),\n };\n}\n\n/** Creates an empty cart state backed by the empty cart data. Loading defaults to `true`. */\nexport function createEmptyCartState({ loading = true }: { loading?: boolean } = {}): CartState {\n return createCartState(\n {\n ...EMPTY_CART_DATA,\n lines: { nodes: [] },\n discountCodes: [],\n },\n { loading },\n );\n}\n\n/**\n * Shared empty cart state backed by the empty cart data, with loading set to `true`.\n *\n * @publicDocs\n */\nexport const EMPTY_CART_STATE: CartState = createEmptyCartState();\n"],"mappings":";AAgSA,SAAgB,qBAAkC;AAChD,QAAO;EACL,uBAAO,IAAI,KAAK;EAChB,MAAM;EACN,YAAY;EACZ,+BAAe,IAAI,KAAK;EACxB,MAAM;EACP;;;;;;;;AASH,SAAgB,wBAAwC;AACtD,QAAO;EAAE,YAAY,EAAE;EAAE,UAAU,EAAE;EAAE;;;;;;;;;;AAWzC,SAAgB,wBAAwC;AACtD,QAAO;EACL,MAAM,uBAAuB;EAC7B,uBAAO,IAAI,KAAK;EAChB,MAAM,uBAAuB;EAC7B,4BAAY,IAAI,KAAK;EACrB,+BAAe,IAAI,KAAK;EACxB,SAAS,EAAE;EACX,eAAe;EACf,eAAe;EACf,gBAAgB;EAChB,eAAe;EACf,qBAAqB;EACrB,wBAAwB;EACxB,kBAAkB;EACnB;;;;;;;;AASH,MAAa,kBAA4B,OAAO,OAAO;CACrD,IAAI;CACJ,aAAa;CACb,eAAe;CACf,MAAM,OAAO,OAAO;EAClB,gBAAgB,OAAO,OAAO;GAAE,QAAQ;GAAK,cAAc;GAAI,CAAC;EAChE,aAAa,OAAO,OAAO;GAAE,QAAQ;GAAK,cAAc;GAAI,CAAC;EAC7D,sBAAsB,OAAO,OAAO;GAAE,QAAQ;GAAK,cAAc;GAAI,CAAC;EACvE,CAAC;CACF,MAAM;CACN,YAAY,EAAE;CACd,OAAO,OAAO,OAAO,EAAE,OAAO,EAAE,EAAgB,CAAC;CACjD,eAAe,EAAE;CAClB,CAAC;AAEF,SAAgB,gBACd,MACA,EAAE,UAAU,UAAiC,EAAE,EAC7B;AAClB,QAAO;EACL;EACA;EACA,SAAS,oBAAoB;EAC7B,QAAQ,uBAAuB;EAChC;;;AAIH,SAAgB,qBAAqB,EAAE,UAAU,SAAgC,EAAE,EAAa;AAC9F,QAAO,gBACL;EACE,GAAG;EACH,OAAO,EAAE,OAAO,EAAE,EAAE;EACpB,eAAe,EAAE;EAClB,EACD,EAAE,SAAS,CACZ;;;;;;;AAQH,MAAa,mBAA8B,sBAAsB"}
|