@vtex/faststore 0.0.1
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/actions.json +334 -0
- package/dist/catalog.json +6615 -0
- package/dist/client.d.ts +17 -0
- package/dist/client.js +8 -0
- package/dist/components.d.ts +87 -0
- package/dist/components.js +87 -0
- package/dist/content-types.json +684 -0
- package/dist/core/dist/actions/mock-action.d.ts +24 -0
- package/dist/core/dist/actions/mock-action.js +28 -0
- package/dist/core/dist/actions/mock-action.js.map +1 -0
- package/dist/core/dist/actions/registry.d.ts +24 -0
- package/dist/core/dist/actions/registry.js +28 -0
- package/dist/core/dist/actions/registry.js.map +1 -0
- package/dist/core/dist/define-component.d.ts +100 -0
- package/dist/core/dist/define-component.js +8 -0
- package/dist/core/dist/define-component.js.map +1 -0
- package/dist/core/dist/define-content-type.d.ts +95 -0
- package/dist/core/dist/define-content-type.js +283 -0
- package/dist/core/dist/define-content-type.js.map +1 -0
- package/dist/core/dist/index.d.ts +7 -0
- package/dist/core/dist/index.js +5 -0
- package/dist/core/dist/schema/generated/schema.d.ts +28 -0
- package/dist/core/dist/types.d.ts +1 -0
- package/dist/docs/access-code-field.md +100 -0
- package/dist/docs/access-code-sign-in.md +174 -0
- package/dist/docs/account-entry-point.md +155 -0
- package/dist/docs/address-summary.md +50 -0
- package/dist/docs/buy-button.md +162 -0
- package/dist/docs/carousel.md +105 -0
- package/dist/docs/cart-item.md +162 -0
- package/dist/docs/cart-totalizer.md +197 -0
- package/dist/docs/cart.md +495 -0
- package/dist/docs/client-preferences.md +184 -0
- package/dist/docs/client-profile-form.md +192 -0
- package/dist/docs/client-profile.md +117 -0
- package/dist/docs/container.md +97 -0
- package/dist/docs/document-field.md +97 -0
- package/dist/docs/email-field.md +93 -0
- package/dist/docs/email-identification.md +102 -0
- package/dist/docs/footer-copyright.md +112 -0
- package/dist/docs/footer-link-group.md +162 -0
- package/dist/docs/footer-root.md +145 -0
- package/dist/docs/footer-social.md +151 -0
- package/dist/docs/free-shipping-progress.md +87 -0
- package/dist/docs/gallery.md +84 -0
- package/dist/docs/header-root.md +150 -0
- package/dist/docs/identity-edit.md +88 -0
- package/dist/docs/identity-summary.md +106 -0
- package/dist/docs/incentives.md +151 -0
- package/dist/docs/logo.md +135 -0
- package/dist/docs/meter.md +67 -0
- package/dist/docs/navigation-link-list.md +171 -0
- package/dist/docs/navigation-link.md +163 -0
- package/dist/docs/navigation-menu.md +264 -0
- package/dist/docs/payment-methods.md +139 -0
- package/dist/docs/phone-field.md +106 -0
- package/dist/docs/postal-code-field.md +126 -0
- package/dist/docs/pricing.md +499 -0
- package/dist/docs/product-gallery.md +409 -0
- package/dist/docs/product-information.md +295 -0
- package/dist/docs/product-list.md +170 -0
- package/dist/docs/product-quantity.md +88 -0
- package/dist/docs/product-shelf.md +141 -0
- package/dist/docs/promotion.md +109 -0
- package/dist/docs/region.md +225 -0
- package/dist/docs/session.md +123 -0
- package/dist/docs/shipping-address.md +390 -0
- package/dist/docs/shipping-simulator.md +147 -0
- package/dist/docs/sign-in-form.md +117 -0
- package/dist/docs/tabs.md +176 -0
- package/dist/docs/toast.md +124 -0
- package/dist/docs/variant-selector.md +450 -0
- package/dist/graphql/define-subgraph.d.ts +12 -0
- package/dist/graphql/define-subgraph.js +15 -0
- package/dist/graphql/define-subgraph.js.map +1 -0
- package/dist/graphql/gql.d.ts +10 -0
- package/dist/graphql/gql.js +16 -0
- package/dist/graphql/gql.js.map +1 -0
- package/dist/graphql/types.d.ts +88 -0
- package/dist/graphql.d.ts +4 -0
- package/dist/graphql.js +3 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +5 -0
- package/dist/internal/client.d.ts +24 -0
- package/dist/internal/client.js +23 -0
- package/dist/internal/content.d.ts +2 -0
- package/dist/internal/content.js +2 -0
- package/dist/internal/server.d.ts +7 -0
- package/dist/internal/server.js +6 -0
- package/dist/matter/access-code-sign-in/access-code-sign-in.d.ts +111 -0
- package/dist/matter/access-code-sign-in/access-code-sign-in.js +387 -0
- package/dist/matter/access-code-sign-in/access-code-sign-in.js.map +1 -0
- package/dist/matter/account-entry-point/account-entry-point.d.ts +64 -0
- package/dist/matter/account-entry-point/account-entry-point.js +151 -0
- package/dist/matter/account-entry-point/account-entry-point.js.map +1 -0
- package/dist/matter/breadcrumb/breadcrumb.d.ts +40 -0
- package/dist/matter/breadcrumb/breadcrumb.js +155 -0
- package/dist/matter/breadcrumb/breadcrumb.js.map +1 -0
- package/dist/matter/buy-button/buy-button.d.ts +95 -0
- package/dist/matter/buy-button/buy-button.js +259 -0
- package/dist/matter/buy-button/buy-button.js.map +1 -0
- package/dist/matter/cart/cart-namespace.d.ts +48 -0
- package/dist/matter/cart/cart-namespace.js +50 -0
- package/dist/matter/cart/cart-namespace.js.map +1 -0
- package/dist/matter/cart/cart.d.ts +312 -0
- package/dist/matter/cart/cart.js +1034 -0
- package/dist/matter/cart/cart.js.map +1 -0
- package/dist/matter/cart-item/cart-item.d.ts +103 -0
- package/dist/matter/cart-item/cart-item.js +672 -0
- package/dist/matter/cart-item/cart-item.js.map +1 -0
- package/dist/matter/cart-item-compositions/cart-item-compositions.d.ts +49 -0
- package/dist/matter/cart-item-compositions/cart-item-compositions.js +165 -0
- package/dist/matter/cart-item-compositions/cart-item-compositions.js.map +1 -0
- package/dist/matter/cart-item-customizations/cart-item-customizations.d.ts +28 -0
- package/dist/matter/cart-item-customizations/cart-item-customizations.js +73 -0
- package/dist/matter/cart-item-customizations/cart-item-customizations.js.map +1 -0
- package/dist/matter/cart-item-discounts/cart-item-discounts.d.ts +33 -0
- package/dist/matter/cart-item-discounts/cart-item-discounts.js +70 -0
- package/dist/matter/cart-item-discounts/cart-item-discounts.js.map +1 -0
- package/dist/matter/cart-item-seller-info/cart-item-seller-info.d.ts +24 -0
- package/dist/matter/cart-item-seller-info/cart-item-seller-info.js +54 -0
- package/dist/matter/cart-item-seller-info/cart-item-seller-info.js.map +1 -0
- package/dist/matter/cart-item-variations/cart-item-variations.d.ts +27 -0
- package/dist/matter/cart-item-variations/cart-item-variations.js +69 -0
- package/dist/matter/cart-item-variations/cart-item-variations.js.map +1 -0
- package/dist/matter/cart-totalizer/cart-totalizer.d.ts +78 -0
- package/dist/matter/cart-totalizer/cart-totalizer.js +220 -0
- package/dist/matter/cart-totalizer/cart-totalizer.js.map +1 -0
- package/dist/matter/client-preferences/client-preferences.d.ts +50 -0
- package/dist/matter/client-preferences/client-preferences.js +206 -0
- package/dist/matter/client-preferences/client-preferences.js.map +1 -0
- package/dist/matter/client-profile/client-profile.d.ts +59 -0
- package/dist/matter/client-profile/client-profile.js +185 -0
- package/dist/matter/client-profile/client-profile.js.map +1 -0
- package/dist/matter/client-profile-form/client-profile-form.d.ts +126 -0
- package/dist/matter/client-profile-form/client-profile-form.js +660 -0
- package/dist/matter/client-profile-form/client-profile-form.js.map +1 -0
- package/dist/matter/delivery-options/delivery-options-accordion.d.ts +30 -0
- package/dist/matter/delivery-options/delivery-options-accordion.js +189 -0
- package/dist/matter/delivery-options/delivery-options-accordion.js.map +1 -0
- package/dist/matter/delivery-options/delivery-options-controller.d.ts +49 -0
- package/dist/matter/delivery-options/delivery-options-controller.js +203 -0
- package/dist/matter/delivery-options/delivery-options-controller.js.map +1 -0
- package/dist/matter/delivery-options/delivery-options.d.ts +31 -0
- package/dist/matter/delivery-options/delivery-options.js +103 -0
- package/dist/matter/delivery-options/delivery-options.js.map +1 -0
- package/dist/matter/delivery-options/use-delivery-option-selection.d.ts +9 -0
- package/dist/matter/delivery-options/use-delivery-option-selection.js +76 -0
- package/dist/matter/delivery-options/use-delivery-option-selection.js.map +1 -0
- package/dist/matter/email-identification/email-identification.d.ts +37 -0
- package/dist/matter/email-identification/email-identification.js +111 -0
- package/dist/matter/email-identification/email-identification.js.map +1 -0
- package/dist/matter/free-shipping-progress/free-shipping-progress.d.ts +44 -0
- package/dist/matter/free-shipping-progress/free-shipping-progress.js +170 -0
- package/dist/matter/free-shipping-progress/free-shipping-progress.js.map +1 -0
- package/dist/matter/identity-edit/identity-edit.d.ts +52 -0
- package/dist/matter/identity-edit/identity-edit.js +148 -0
- package/dist/matter/identity-edit/identity-edit.js.map +1 -0
- package/dist/matter/identity-summary/identity-summary.d.ts +128 -0
- package/dist/matter/identity-summary/identity-summary.js +344 -0
- package/dist/matter/identity-summary/identity-summary.js.map +1 -0
- package/dist/matter/pricing/pricing.d.ts +162 -0
- package/dist/matter/pricing/pricing.js +793 -0
- package/dist/matter/pricing/pricing.js.map +1 -0
- package/dist/matter/product-gallery/product-gallery.d.ts +23 -0
- package/dist/matter/product-gallery/product-gallery.js +188 -0
- package/dist/matter/product-gallery/product-gallery.js.map +1 -0
- package/dist/matter/product-information/product-information.d.ts +61 -0
- package/dist/matter/product-information/product-information.js +355 -0
- package/dist/matter/product-information/product-information.js.map +1 -0
- package/dist/matter/product-list/product-list.d.ts +86 -0
- package/dist/matter/product-list/product-list.js +342 -0
- package/dist/matter/product-list/product-list.js.map +1 -0
- package/dist/matter/product-quantity/product-quantity.d.ts +50 -0
- package/dist/matter/product-quantity/product-quantity.js +111 -0
- package/dist/matter/product-quantity/product-quantity.js.map +1 -0
- package/dist/matter/product-shelf/product-shelf.d.ts +125 -0
- package/dist/matter/product-shelf/product-shelf.js +376 -0
- package/dist/matter/product-shelf/product-shelf.js.map +1 -0
- package/dist/matter/region/region.d.ts +211 -0
- package/dist/matter/region/region.js +579 -0
- package/dist/matter/region/region.js.map +1 -0
- package/dist/matter/session/session.d.ts +58 -0
- package/dist/matter/session/session.js +112 -0
- package/dist/matter/session/session.js.map +1 -0
- package/dist/matter/shipping-address/country-descriptors.js +101 -0
- package/dist/matter/shipping-address/country-descriptors.js.map +1 -0
- package/dist/matter/shipping-address/shipping-address.d.ts +284 -0
- package/dist/matter/shipping-address/shipping-address.js +1036 -0
- package/dist/matter/shipping-address/shipping-address.js.map +1 -0
- package/dist/matter/shipping-simulator/shipping-simulator.d.ts +143 -0
- package/dist/matter/shipping-simulator/shipping-simulator.js +644 -0
- package/dist/matter/shipping-simulator/shipping-simulator.js.map +1 -0
- package/dist/matter/sign-in-form/sign-in-form.d.ts +79 -0
- package/dist/matter/sign-in-form/sign-in-form.js +226 -0
- package/dist/matter/sign-in-form/sign-in-form.js.map +1 -0
- package/dist/matter/variant-selector/variant-selector.d.ts +183 -0
- package/dist/matter/variant-selector/variant-selector.js +840 -0
- package/dist/matter/variant-selector/variant-selector.js.map +1 -0
- package/dist/message-locales.json +7 -0
- package/dist/particles/access-code-field/access-code-field.d.ts +33 -0
- package/dist/particles/access-code-field/access-code-field.js +95 -0
- package/dist/particles/access-code-field/access-code-field.js.map +1 -0
- package/dist/particles/accordion/accordion.d.ts +45 -0
- package/dist/particles/accordion/accordion.js +156 -0
- package/dist/particles/accordion/accordion.js.map +1 -0
- package/dist/particles/address-summary/address-summary.d.ts +50 -0
- package/dist/particles/address-summary/address-summary.js +129 -0
- package/dist/particles/address-summary/address-summary.js.map +1 -0
- package/dist/particles/badge/badge.d.ts +10 -0
- package/dist/particles/badge/badge.js +27 -0
- package/dist/particles/badge/badge.js.map +1 -0
- package/dist/particles/button/button.d.ts +18 -0
- package/dist/particles/button/button.js +37 -0
- package/dist/particles/button/button.js.map +1 -0
- package/dist/particles/carousel/carousel.d.ts +60 -0
- package/dist/particles/carousel/carousel.js +335 -0
- package/dist/particles/carousel/carousel.js.map +1 -0
- package/dist/particles/checkbox/checkbox.d.ts +40 -0
- package/dist/particles/checkbox/checkbox.js +82 -0
- package/dist/particles/checkbox/checkbox.js.map +1 -0
- package/dist/particles/container/container.d.ts +20 -0
- package/dist/particles/container/container.js +36 -0
- package/dist/particles/container/container.js.map +1 -0
- package/dist/particles/dialog/dialog.d.ts +54 -0
- package/dist/particles/dialog/dialog.js +192 -0
- package/dist/particles/dialog/dialog.js.map +1 -0
- package/dist/particles/document-field/document-field.d.ts +61 -0
- package/dist/particles/document-field/document-field.js +146 -0
- package/dist/particles/document-field/document-field.js.map +1 -0
- package/dist/particles/drawer/drawer.d.ts +52 -0
- package/dist/particles/drawer/drawer.js +183 -0
- package/dist/particles/drawer/drawer.js.map +1 -0
- package/dist/particles/email-field/email-field.d.ts +37 -0
- package/dist/particles/email-field/email-field.js +106 -0
- package/dist/particles/email-field/email-field.js.map +1 -0
- package/dist/particles/field/field.d.ts +50 -0
- package/dist/particles/field/field.js +133 -0
- package/dist/particles/field/field.js.map +1 -0
- package/dist/particles/fieldset/fieldset.d.ts +16 -0
- package/dist/particles/fieldset/fieldset.js +52 -0
- package/dist/particles/fieldset/fieldset.js.map +1 -0
- package/dist/particles/footer-copyright/footer-copyright.d.ts +32 -0
- package/dist/particles/footer-copyright/footer-copyright.js +50 -0
- package/dist/particles/footer-copyright/footer-copyright.js.map +1 -0
- package/dist/particles/footer-link-group/footer-link-group.d.ts +66 -0
- package/dist/particles/footer-link-group/footer-link-group.js +154 -0
- package/dist/particles/footer-link-group/footer-link-group.js.map +1 -0
- package/dist/particles/footer-root/footer-root.d.ts +21 -0
- package/dist/particles/footer-root/footer-root.js +38 -0
- package/dist/particles/footer-root/footer-root.js.map +1 -0
- package/dist/particles/footer-social/footer-social.d.ts +79 -0
- package/dist/particles/footer-social/footer-social.js +176 -0
- package/dist/particles/footer-social/footer-social.js.map +1 -0
- package/dist/particles/gallery/gallery.d.ts +181 -0
- package/dist/particles/gallery/gallery.js +920 -0
- package/dist/particles/gallery/gallery.js.map +1 -0
- package/dist/particles/header-root/header-root.d.ts +21 -0
- package/dist/particles/header-root/header-root.js +38 -0
- package/dist/particles/header-root/header-root.js.map +1 -0
- package/dist/particles/icon/icon.d.ts +22 -0
- package/dist/particles/icon/icon.js +48 -0
- package/dist/particles/icon/icon.js.map +1 -0
- package/dist/particles/image/image.d.ts +13 -0
- package/dist/particles/image/image.js +59 -0
- package/dist/particles/image/image.js.map +1 -0
- package/dist/particles/incentives/incentives.d.ts +85 -0
- package/dist/particles/incentives/incentives.js +200 -0
- package/dist/particles/incentives/incentives.js.map +1 -0
- package/dist/particles/input/input.d.ts +9 -0
- package/dist/particles/input/input.js +28 -0
- package/dist/particles/input/input.js.map +1 -0
- package/dist/particles/logo/logo.d.ts +55 -0
- package/dist/particles/logo/logo.js +96 -0
- package/dist/particles/logo/logo.js.map +1 -0
- package/dist/particles/menu/menu.d.ts +103 -0
- package/dist/particles/menu/menu.js +409 -0
- package/dist/particles/menu/menu.js.map +1 -0
- package/dist/particles/menubar/menubar.d.ts +18 -0
- package/dist/particles/menubar/menubar.js +42 -0
- package/dist/particles/menubar/menubar.js.map +1 -0
- package/dist/particles/meter/meter.d.ts +36 -0
- package/dist/particles/meter/meter.js +132 -0
- package/dist/particles/meter/meter.js.map +1 -0
- package/dist/particles/navigation-link/navigation-link.d.ts +43 -0
- package/dist/particles/navigation-link/navigation-link.js +82 -0
- package/dist/particles/navigation-link/navigation-link.js.map +1 -0
- package/dist/particles/navigation-link-list/navigation-link-list.d.ts +59 -0
- package/dist/particles/navigation-link-list/navigation-link-list.js +103 -0
- package/dist/particles/navigation-link-list/navigation-link-list.js.map +1 -0
- package/dist/particles/navigation-menu/navigation-menu.d.ts +78 -0
- package/dist/particles/navigation-menu/navigation-menu.js +295 -0
- package/dist/particles/navigation-menu/navigation-menu.js.map +1 -0
- package/dist/particles/number-field/number-field.d.ts +46 -0
- package/dist/particles/number-field/number-field.js +169 -0
- package/dist/particles/number-field/number-field.js.map +1 -0
- package/dist/particles/password-field/password-field.d.ts +31 -0
- package/dist/particles/password-field/password-field.js +109 -0
- package/dist/particles/password-field/password-field.js.map +1 -0
- package/dist/particles/payment-methods/payment-methods.d.ts +72 -0
- package/dist/particles/payment-methods/payment-methods.js +151 -0
- package/dist/particles/payment-methods/payment-methods.js.map +1 -0
- package/dist/particles/phone-field/phone-field.d.ts +67 -0
- package/dist/particles/phone-field/phone-field.js +250 -0
- package/dist/particles/phone-field/phone-field.js.map +1 -0
- package/dist/particles/popover/popover.d.ts +68 -0
- package/dist/particles/popover/popover.js +284 -0
- package/dist/particles/popover/popover.js.map +1 -0
- package/dist/particles/postal-code-field/postal-code-field.d.ts +75 -0
- package/dist/particles/postal-code-field/postal-code-field.js +169 -0
- package/dist/particles/postal-code-field/postal-code-field.js.map +1 -0
- package/dist/particles/promotion/promotion.d.ts +46 -0
- package/dist/particles/promotion/promotion.js +78 -0
- package/dist/particles/promotion/promotion.js.map +1 -0
- package/dist/particles/quantity-selector/quantity-selector.d.ts +30 -0
- package/dist/particles/quantity-selector/quantity-selector.js +116 -0
- package/dist/particles/quantity-selector/quantity-selector.js.map +1 -0
- package/dist/particles/radio/radio.d.ts +36 -0
- package/dist/particles/radio/radio.js +76 -0
- package/dist/particles/radio/radio.js.map +1 -0
- package/dist/particles/scroll-area/scroll-area.d.ts +36 -0
- package/dist/particles/scroll-area/scroll-area.js +145 -0
- package/dist/particles/scroll-area/scroll-area.js.map +1 -0
- package/dist/particles/select/select.d.ts +125 -0
- package/dist/particles/select/select.js +478 -0
- package/dist/particles/select/select.js.map +1 -0
- package/dist/particles/separator/separator.d.ts +12 -0
- package/dist/particles/separator/separator.js +33 -0
- package/dist/particles/separator/separator.js.map +1 -0
- package/dist/particles/shared/input-mask.d.ts +5 -0
- package/dist/particles/shared/input-mask.js +58 -0
- package/dist/particles/shared/input-mask.js.map +1 -0
- package/dist/particles/spinner/spinner.d.ts +13 -0
- package/dist/particles/spinner/spinner.js +31 -0
- package/dist/particles/spinner/spinner.js.map +1 -0
- package/dist/particles/switch/switch.d.ts +27 -0
- package/dist/particles/switch/switch.js +59 -0
- package/dist/particles/switch/switch.js.map +1 -0
- package/dist/particles/tabs/tabs.d.ts +45 -0
- package/dist/particles/tabs/tabs.js +164 -0
- package/dist/particles/tabs/tabs.js.map +1 -0
- package/dist/particles/text/text.d.ts +24 -0
- package/dist/particles/text/text.js +40 -0
- package/dist/particles/text/text.js.map +1 -0
- package/dist/particles/toast/toast.d.ts +83 -0
- package/dist/particles/toast/toast.js +194 -0
- package/dist/particles/toast/toast.js.map +1 -0
- package/dist/particles/toggle/toggle.d.ts +26 -0
- package/dist/particles/toggle/toggle.js +61 -0
- package/dist/particles/toggle/toggle.js.map +1 -0
- package/dist/particles/tooltip/tooltip.d.ts +61 -0
- package/dist/particles/tooltip/tooltip.js +240 -0
- package/dist/particles/tooltip/tooltip.js.map +1 -0
- package/dist/schema.graphql +2953 -0
- package/dist/sdk/actions/cart-action-provider.d.ts +19 -0
- package/dist/sdk/actions/cart-action-provider.js +23 -0
- package/dist/sdk/actions/cart-action-provider.js.map +1 -0
- package/dist/sdk/actions/identity-action-provider.d.ts +15 -0
- package/dist/sdk/actions/identity-action-provider.js +19 -0
- package/dist/sdk/actions/identity-action-provider.js.map +1 -0
- package/dist/sdk/actions/index.d.ts +7 -0
- package/dist/sdk/actions/index.js +6 -0
- package/dist/sdk/actions/inject-actions.d.ts +14 -0
- package/dist/sdk/actions/inject-actions.js +36 -0
- package/dist/sdk/actions/inject-actions.js.map +1 -0
- package/dist/sdk/actions/region-action-provider.d.ts +15 -0
- package/dist/sdk/actions/region-action-provider.js +19 -0
- package/dist/sdk/actions/region-action-provider.js.map +1 -0
- package/dist/sdk/actions/session-action-provider.d.ts +15 -0
- package/dist/sdk/actions/session-action-provider.js +19 -0
- package/dist/sdk/actions/session-action-provider.js.map +1 -0
- package/dist/sdk/actions/shipping-action-provider.d.ts +15 -0
- package/dist/sdk/actions/shipping-action-provider.js +19 -0
- package/dist/sdk/actions/shipping-action-provider.js.map +1 -0
- package/dist/sdk/actions/types.d.ts +21 -0
- package/dist/sdk/cache/storefront-cache.js +35 -0
- package/dist/sdk/cache/storefront-cache.js.map +1 -0
- package/dist/sdk/cart/operations.d.ts +31 -0
- package/dist/sdk/cart/operations.js +215 -0
- package/dist/sdk/cart/operations.js.map +1 -0
- package/dist/sdk/cart/optimistic.d.ts +24 -0
- package/dist/sdk/cart/optimistic.js +164 -0
- package/dist/sdk/cart/optimistic.js.map +1 -0
- package/dist/sdk/cart/use-cart-actions.d.ts +56 -0
- package/dist/sdk/cart/use-cart-actions.js +348 -0
- package/dist/sdk/cart/use-cart-actions.js.map +1 -0
- package/dist/sdk/cart/use-cart-validate-on-open.js +50 -0
- package/dist/sdk/cart/use-cart-validate-on-open.js.map +1 -0
- package/dist/sdk/cart/write-gate.js +54 -0
- package/dist/sdk/cart/write-gate.js.map +1 -0
- package/dist/sdk/client/assert-api-url.js +20 -0
- package/dist/sdk/client/assert-api-url.js.map +1 -0
- package/dist/sdk/client/create-client.d.ts +23 -0
- package/dist/sdk/client/create-client.js +46 -0
- package/dist/sdk/client/create-client.js.map +1 -0
- package/dist/sdk/client/fetch-page-data.d.ts +39 -0
- package/dist/sdk/client/fetch-page-data.js +33 -0
- package/dist/sdk/client/fetch-page-data.js.map +1 -0
- package/dist/sdk/client/register-preload-query.d.ts +24 -0
- package/dist/sdk/client/register-preload-query.js +33 -0
- package/dist/sdk/client/register-preload-query.js.map +1 -0
- package/dist/sdk/content/create-content-runtime.d.ts +68 -0
- package/dist/sdk/content/create-content-runtime.js +503 -0
- package/dist/sdk/content/create-content-runtime.js.map +1 -0
- package/dist/sdk/context/headers.d.ts +15 -0
- package/dist/sdk/context/headers.js +21 -0
- package/dist/sdk/context/headers.js.map +1 -0
- package/dist/sdk/context/storefront-context.d.ts +11 -0
- package/dist/sdk/context/storefront-context.js +29 -0
- package/dist/sdk/context/storefront-context.js.map +1 -0
- package/dist/sdk/data/data-override-context.d.ts +12 -0
- package/dist/sdk/data/data-override-context.js +19 -0
- package/dist/sdk/data/data-override-context.js.map +1 -0
- package/dist/sdk/data/entity-subscriber.js +28 -0
- package/dist/sdk/data/entity-subscriber.js.map +1 -0
- package/dist/sdk/data/hot-data-provider.d.ts +19 -0
- package/dist/sdk/data/hot-data-provider.js +33 -0
- package/dist/sdk/data/hot-data-provider.js.map +1 -0
- package/dist/sdk/data/index.d.ts +8 -0
- package/dist/sdk/data/index.js +8 -0
- package/dist/sdk/data/list-item-ref-context.d.ts +20 -0
- package/dist/sdk/data/list-item-ref-context.js +11 -0
- package/dist/sdk/data/list-item-ref-context.js.map +1 -0
- package/dist/sdk/data/multiple-reactive-data-provider.d.ts +32 -0
- package/dist/sdk/data/multiple-reactive-data-provider.js +20 -0
- package/dist/sdk/data/multiple-reactive-data-provider.js.map +1 -0
- package/dist/sdk/data/page-reactive-data-root.d.ts +53 -0
- package/dist/sdk/data/page-reactive-data-root.js +153 -0
- package/dist/sdk/data/page-reactive-data-root.js.map +1 -0
- package/dist/sdk/data/reactive-data-provider.d.ts +25 -0
- package/dist/sdk/data/reactive-data-provider.js +24 -0
- package/dist/sdk/data/reactive-data-provider.js.map +1 -0
- package/dist/sdk/data/reactive-list-item-data-provider.d.ts +26 -0
- package/dist/sdk/data/reactive-list-item-data-provider.js +42 -0
- package/dist/sdk/data/reactive-list-item-data-provider.js.map +1 -0
- package/dist/sdk/data/use-reactive-entity.js +40 -0
- package/dist/sdk/data/use-reactive-entity.js.map +1 -0
- package/dist/sdk/format/client.d.ts +12 -0
- package/dist/sdk/format/client.js +20 -0
- package/dist/sdk/format/client.js.map +1 -0
- package/dist/sdk/format/formatters.d.ts +32 -0
- package/dist/sdk/format/formatters.js +45 -0
- package/dist/sdk/format/formatters.js.map +1 -0
- package/dist/sdk/generated/fragment-types.js +23 -0
- package/dist/sdk/generated/fragment-types.js.map +1 -0
- package/dist/sdk/generated/gql.js +51 -0
- package/dist/sdk/generated/gql.js.map +1 -0
- package/dist/sdk/generated/graphql.d.ts +622 -0
- package/dist/sdk/generated/graphql.js +11917 -0
- package/dist/sdk/generated/graphql.js.map +1 -0
- package/dist/sdk/graphql-tag.d.ts +10 -0
- package/dist/sdk/graphql-tag.js +21 -0
- package/dist/sdk/graphql-tag.js.map +1 -0
- package/dist/sdk/i18n/client.d.ts +4 -0
- package/dist/sdk/i18n/client.js +4 -0
- package/dist/sdk/i18n/locales.d.ts +8 -0
- package/dist/sdk/i18n/locales.js +57 -0
- package/dist/sdk/i18n/locales.js.map +1 -0
- package/dist/sdk/i18n/messages/en-US.js +24 -0
- package/dist/sdk/i18n/messages/en-US.js.map +1 -0
- package/dist/sdk/i18n/messages/en-US.json +19 -0
- package/dist/sdk/i18n/messages/en-US.json.d.ts +23 -0
- package/dist/sdk/i18n/messages/es-ES.js +24 -0
- package/dist/sdk/i18n/messages/es-ES.js.map +1 -0
- package/dist/sdk/i18n/messages/es-ES.json +19 -0
- package/dist/sdk/i18n/messages/pt-BR.js +24 -0
- package/dist/sdk/i18n/messages/pt-BR.js.map +1 -0
- package/dist/sdk/i18n/messages/pt-BR.json +19 -0
- package/dist/sdk/i18n/provider.d.ts +1 -0
- package/dist/sdk/i18n/provider.js +30 -0
- package/dist/sdk/i18n/provider.js.map +1 -0
- package/dist/sdk/i18n/server.d.ts +28 -0
- package/dist/sdk/i18n/server.js +59 -0
- package/dist/sdk/i18n/server.js.map +1 -0
- package/dist/sdk/identity/operations.d.ts +34 -0
- package/dist/sdk/identity/operations.js +78 -0
- package/dist/sdk/identity/operations.js.map +1 -0
- package/dist/sdk/identity/use-identity-actions.d.ts +62 -0
- package/dist/sdk/identity/use-identity-actions.js +180 -0
- package/dist/sdk/identity/use-identity-actions.js.map +1 -0
- package/dist/sdk/provider/index.d.ts +2 -0
- package/dist/sdk/provider/index.js +2 -0
- package/dist/sdk/provider/storefront-provider.d.ts +32 -0
- package/dist/sdk/provider/storefront-provider.js +111 -0
- package/dist/sdk/provider/storefront-provider.js.map +1 -0
- package/dist/sdk/region/operations.d.ts +6 -0
- package/dist/sdk/region/region-operations.d.ts +30 -0
- package/dist/sdk/region/region-operations.js +23 -0
- package/dist/sdk/region/region-operations.js.map +1 -0
- package/dist/sdk/region/use-region-actions.d.ts +23 -0
- package/dist/sdk/region/use-region-actions.js +66 -0
- package/dist/sdk/region/use-region-actions.js.map +1 -0
- package/dist/sdk/seller.js +11 -0
- package/dist/sdk/seller.js.map +1 -0
- package/dist/sdk/session/auth-operations.d.ts +47 -0
- package/dist/sdk/session/auth-operations.js +79 -0
- package/dist/sdk/session/auth-operations.js.map +1 -0
- package/dist/sdk/session/operations.d.ts +6 -0
- package/dist/sdk/session/use-session-actions.d.ts +27 -0
- package/dist/sdk/session/use-session-actions.js +126 -0
- package/dist/sdk/session/use-session-actions.js.map +1 -0
- package/dist/sdk/shipping/cart-operations.d.ts +3 -0
- package/dist/sdk/shipping/cart-operations.js +33 -0
- package/dist/sdk/shipping/cart-operations.js.map +1 -0
- package/dist/sdk/shipping/operations.d.ts +3 -0
- package/dist/sdk/shipping/operations.js +33 -0
- package/dist/sdk/shipping/operations.js.map +1 -0
- package/dist/sdk/shipping/option-select-operations.d.ts +24 -0
- package/dist/sdk/shipping/option-select-operations.js +45 -0
- package/dist/sdk/shipping/option-select-operations.js.map +1 -0
- package/dist/sdk/shipping/request-timeout.js +41 -0
- package/dist/sdk/shipping/request-timeout.js.map +1 -0
- package/dist/sdk/shipping/shipping-operations.d.ts +38 -0
- package/dist/sdk/shipping/shipping-operations.js +77 -0
- package/dist/sdk/shipping/shipping-operations.js.map +1 -0
- package/dist/sdk/shipping/use-cart-shipping-simulation.d.ts +7 -0
- package/dist/sdk/shipping/use-cart-shipping-simulation.js +72 -0
- package/dist/sdk/shipping/use-cart-shipping-simulation.js.map +1 -0
- package/dist/sdk/shipping/use-shipping-actions.d.ts +27 -0
- package/dist/sdk/shipping/use-shipping-actions.js +113 -0
- package/dist/sdk/shipping/use-shipping-actions.js.map +1 -0
- package/dist/sdk/shipping/use-shipping-simulation.d.ts +7 -0
- package/dist/sdk/shipping/use-shipping-simulation.js +72 -0
- package/dist/sdk/shipping/use-shipping-simulation.js.map +1 -0
- package/dist/sdk/state/cart.d.ts +42 -0
- package/dist/sdk/state/cart.js +64 -0
- package/dist/sdk/state/cart.js.map +1 -0
- package/dist/sdk/state/index.js +3 -0
- package/dist/sdk/state/variant-selector.d.ts +17 -0
- package/dist/sdk/state/variant-selector.js +14 -0
- package/dist/sdk/state/variant-selector.js.map +1 -0
- package/dist/utils/safe-href.js +63 -0
- package/dist/utils/safe-href.js.map +1 -0
- package/package.json +84 -0
- package/src/styles/tailwind.css +32 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { gql } from "../graphql-tag.js";
|
|
2
|
+
import { CartFragment } from "../cart/operations.js";
|
|
3
|
+
//#region src/sdk/shipping/shipping-operations.ts
|
|
4
|
+
/**
|
|
5
|
+
* The one client-synthesized error code, carried by the userError that `setAddress` *resolves*
|
|
6
|
+
* (never throws) when the mutation fails at the transport/top-level-GraphQL layer. Consumers use
|
|
7
|
+
* it to route the resolved synthetic failure to the generic upstream error state (Decision 5),
|
|
8
|
+
* distinct from the domain `userErrors` codes that render inline.
|
|
9
|
+
*/
|
|
10
|
+
const SHIPPING_NETWORK_ERROR_CODE = "NETWORK_ERROR";
|
|
11
|
+
const SHIPPING_ADDRESS_UPDATE = gql`
|
|
12
|
+
mutation ShippingAddressUpdate($input: ShippingAddressUpdateInput!) {
|
|
13
|
+
shippingAddressUpdate(input: $input) {
|
|
14
|
+
shipping {
|
|
15
|
+
__typename
|
|
16
|
+
id
|
|
17
|
+
address {
|
|
18
|
+
__typename
|
|
19
|
+
id
|
|
20
|
+
recipientName
|
|
21
|
+
postalCode
|
|
22
|
+
country
|
|
23
|
+
street
|
|
24
|
+
number
|
|
25
|
+
complement
|
|
26
|
+
neighborhood
|
|
27
|
+
city
|
|
28
|
+
state
|
|
29
|
+
}
|
|
30
|
+
savedAddresses {
|
|
31
|
+
__typename
|
|
32
|
+
id
|
|
33
|
+
recipientName
|
|
34
|
+
postalCode
|
|
35
|
+
country
|
|
36
|
+
street
|
|
37
|
+
number
|
|
38
|
+
complement
|
|
39
|
+
neighborhood
|
|
40
|
+
city
|
|
41
|
+
state
|
|
42
|
+
}
|
|
43
|
+
options {
|
|
44
|
+
__typename
|
|
45
|
+
id
|
|
46
|
+
name
|
|
47
|
+
channel
|
|
48
|
+
shippingEstimate {
|
|
49
|
+
value
|
|
50
|
+
unit
|
|
51
|
+
}
|
|
52
|
+
price {
|
|
53
|
+
amount
|
|
54
|
+
currencyCode
|
|
55
|
+
}
|
|
56
|
+
listPrice {
|
|
57
|
+
amount
|
|
58
|
+
currencyCode
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
selectedOptionId
|
|
62
|
+
}
|
|
63
|
+
cart {
|
|
64
|
+
...CartFragment
|
|
65
|
+
}
|
|
66
|
+
userErrors {
|
|
67
|
+
code
|
|
68
|
+
message
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
${CartFragment}
|
|
73
|
+
`;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { SHIPPING_ADDRESS_UPDATE, SHIPPING_NETWORK_ERROR_CODE };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=shipping-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shipping-operations.js","names":[],"sources":["../../../src/sdk/shipping/shipping-operations.ts"],"sourcesContent":["import type { TypedDocumentNode } from '@apollo/client';\nimport { type CartEntity, CartFragment } from '../cart/operations.js';\nimport { gql } from '../graphql-tag.js';\n\n/**\n * Shipping address mutation documents (specs/shipping-address-step.md, US-7).\n *\n * Authored with the hand `gql` tag — the codegen `graphql()` factory is reserved for the reactive\n * read path (`operations.ts`) — and explicitly excluded from the codegen `documents` glob (see\n * `codegen.ts`): the `gql` tag alone is still plucked by `graphql-codegen`, which would duplicate\n * these hand-written types in `sdk/generated/`. The mutation stays hand-typed as a\n * `TypedDocumentNode` (Decision 3 in the spec). The payload projects the full refreshed `shipping`\n * and `cart` state, so the response write into the cache *is* the post-update refresh: `Shipping`'s\n * reactive read flips with no refetch and no imperative cache write.\n *\n * Failures follow ADR-00007's two-path contract: domain outcomes arrive as payload `userErrors`\n * (`ShippingAddressUpdateError`); transport and top-level GraphQL failures are infrastructure,\n * mapped by the handlers in `use-shipping-actions.ts` to the one client-synthesized code,\n * `NETWORK_USER_ERROR`.\n */\n\n/** A typed address-update failure; NETWORK_USER_ERROR is the one client-synthesized code. */\nexport type ShippingAddressUpdateErrorEntity = Readonly<{ code: string; message: string }>;\n\n/**\n * The one client-synthesized error code, carried by the userError that `setAddress` *resolves*\n * (never throws) when the mutation fails at the transport/top-level-GraphQL layer. Consumers use\n * it to route the resolved synthetic failure to the generic upstream error state (Decision 5),\n * distinct from the domain `userErrors` codes that render inline.\n */\nexport const SHIPPING_NETWORK_ERROR_CODE = 'NETWORK_ERROR';\n\nexport type ShippingAddressInput = Readonly<{\n savedAddressId?: string;\n recipientName: string;\n postalCode: string;\n country: string;\n street?: string;\n number?: string;\n complement?: string;\n neighborhood?: string;\n city?: string;\n state?: string;\n}>;\n\n/** The full shippingAddressUpdate mutation payload. */\nexport type ShippingAddressUpdatePayloadEntity = Readonly<{\n __typename: 'ShippingAddressUpdatePayload';\n shipping: {\n __typename: 'Shipping';\n id: string;\n address: {\n __typename: 'Address';\n id?: string | null;\n recipientName?: string | null;\n postalCode?: string | null;\n country: string;\n street?: string | null;\n number?: string | null;\n complement?: string | null;\n neighborhood?: string | null;\n city?: string | null;\n state?: string | null;\n } | null;\n savedAddresses: ReadonlyArray<{\n __typename: 'Address';\n id?: string | null;\n recipientName?: string | null;\n postalCode?: string | null;\n country: string;\n street?: string | null;\n number?: string | null;\n complement?: string | null;\n neighborhood?: string | null;\n city?: string | null;\n state?: string | null;\n }>;\n options: ReadonlyArray<{\n __typename: 'ShippingOption';\n id: string;\n name: string;\n channel: string;\n shippingEstimate: { __typename: 'ShippingEstimate'; value: number; unit: string };\n price: { __typename: 'Money'; amount: number; currencyCode: string };\n listPrice: { __typename: 'Money'; amount: number; currencyCode: string };\n }>;\n selectedOptionId?: string | null;\n } | null;\n cart: CartEntity;\n userErrors: readonly ShippingAddressUpdateErrorEntity[];\n}>;\n\ntype ShippingAddressUpdateData = Readonly<{ shippingAddressUpdate: ShippingAddressUpdatePayloadEntity }>;\n\nexport const SHIPPING_ADDRESS_UPDATE: TypedDocumentNode<ShippingAddressUpdateData, { input: ShippingAddressInput }> =\n gql`\n mutation ShippingAddressUpdate($input: ShippingAddressUpdateInput!) {\n shippingAddressUpdate(input: $input) {\n shipping {\n __typename\n id\n address {\n __typename\n id\n recipientName\n postalCode\n country\n street\n number\n complement\n neighborhood\n city\n state\n }\n savedAddresses {\n __typename\n id\n recipientName\n postalCode\n country\n street\n number\n complement\n neighborhood\n city\n state\n }\n options {\n __typename\n id\n name\n channel\n shippingEstimate {\n value\n unit\n }\n price {\n amount\n currencyCode\n }\n listPrice {\n amount\n currencyCode\n }\n }\n selectedOptionId\n }\n cart {\n ...CartFragment\n }\n userErrors {\n code\n message\n }\n }\n }\n ${CartFragment}\n`;\n"],"mappings":";;;;;;;;;AA8BA,MAAa,8BAA8B;AAgE3C,MAAa,0BACX,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6DD,aAAa"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CartShippingSimulateInput } from "../generated/graphql.js";
|
|
2
|
+
import "./cart-operations.js";
|
|
3
|
+
import { ShippingSimulationPayload } from "../../matter/shipping-simulator/shipping-simulator.js";
|
|
4
|
+
//#region src/sdk/shipping/use-cart-shipping-simulation.d.ts
|
|
5
|
+
export declare function useCartShippingSimulation(): (input: CartShippingSimulateInput) => Promise<ShippingSimulationPayload>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=use-cart-shipping-simulation.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CART_SHIPPING_SIMULATION } from "./cart-operations.js";
|
|
3
|
+
import { withRequestTimeout } from "./request-timeout.js";
|
|
4
|
+
import { getApolloContext } from "@apollo/client/react";
|
|
5
|
+
import { useCallback, useContext } from "react";
|
|
6
|
+
//#region src/sdk/shipping/use-cart-shipping-simulation.ts
|
|
7
|
+
const UNKNOWN_ERROR = {
|
|
8
|
+
code: "UNKNOWN",
|
|
9
|
+
message: "Unable to calculate shipping. Try again."
|
|
10
|
+
};
|
|
11
|
+
function mapErrorCode(code) {
|
|
12
|
+
return code === "INVALID_POSTAL_CODE" ? "INVALID_POSTAL_CODE" : "UNKNOWN";
|
|
13
|
+
}
|
|
14
|
+
function mapOption(option) {
|
|
15
|
+
return {
|
|
16
|
+
id: option.id,
|
|
17
|
+
name: option.name,
|
|
18
|
+
channel: option.channel,
|
|
19
|
+
shippingEstimate: option.shippingEstimate,
|
|
20
|
+
price: {
|
|
21
|
+
amount: option.price.amount,
|
|
22
|
+
currencyCode: option.price.currencyCode
|
|
23
|
+
},
|
|
24
|
+
listPrice: {
|
|
25
|
+
amount: option.listPrice.amount,
|
|
26
|
+
currencyCode: option.listPrice.currencyCode
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function useCartShippingSimulation() {
|
|
31
|
+
const { client } = useContext(getApolloContext());
|
|
32
|
+
return useCallback(async (input) => {
|
|
33
|
+
if (!client) return {
|
|
34
|
+
shippingOptions: null,
|
|
35
|
+
userErrors: [UNKNOWN_ERROR]
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
const result = await withRequestTimeout((signal) => client.query({
|
|
39
|
+
query: CART_SHIPPING_SIMULATION,
|
|
40
|
+
variables: { input },
|
|
41
|
+
fetchPolicy: "no-cache",
|
|
42
|
+
context: { fetchOptions: { signal } }
|
|
43
|
+
}));
|
|
44
|
+
if (result.error || !result.data) return {
|
|
45
|
+
shippingOptions: null,
|
|
46
|
+
userErrors: [UNKNOWN_ERROR]
|
|
47
|
+
};
|
|
48
|
+
const payload = result.data.cartShippingSimulation;
|
|
49
|
+
const userErrors = payload.userErrors.map((error) => ({
|
|
50
|
+
code: mapErrorCode(error.code),
|
|
51
|
+
message: error.message
|
|
52
|
+
}));
|
|
53
|
+
if (userErrors.length > 0) return {
|
|
54
|
+
shippingOptions: null,
|
|
55
|
+
userErrors
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
shippingOptions: payload.shippingOptions?.map(mapOption) ?? null,
|
|
59
|
+
userErrors: []
|
|
60
|
+
};
|
|
61
|
+
} catch {
|
|
62
|
+
return {
|
|
63
|
+
shippingOptions: null,
|
|
64
|
+
userErrors: [UNKNOWN_ERROR]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}, [client]);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { useCartShippingSimulation };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=use-cart-shipping-simulation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-cart-shipping-simulation.js","names":[],"sources":["../../../src/sdk/shipping/use-cart-shipping-simulation.ts"],"sourcesContent":["'use client';\n\nimport { getApolloContext } from '@apollo/client/react';\nimport { useCallback, useContext } from 'react';\nimport type {\n ShippingOption,\n ShippingSimulateError,\n ShippingSimulationPayload,\n} from '../../matter/shipping-simulator/shipping-simulator.js';\nimport type { CartShippingSimulationQuery, ShippingSimulateErrorCode } from '../generated/graphql.js';\nimport { CART_SHIPPING_SIMULATION, type CartShippingSimulateInput } from './cart-operations.js';\nimport { withRequestTimeout } from './request-timeout.js';\n\n/**\n * Cart-scoped shipping-simulation SDK hook.\n *\n * Returns the calculator's `onSimulate(input) => Promise<payload>` callback. It runs the\n * `CartShippingSimulation` query imperatively per submit via the Apollo client read from\n * `getApolloContext()` (a non-throwing read, mirroring `useShippingSimulation`). The input carries\n * a destination only — items come from the cart via `x-order-form-id`, resolved server-side. The\n * mapping matches the PDP hook: the structured `ShippingEstimate { value, unit }` is carried through\n * untouched (the component localizes it), the API `Money` is carried as `{ amount, currencyCode }`,\n * and any transport/GraphQL failure is collapsed to one `UNKNOWN` userError so the calculator's\n * success/error transition stays deterministic.\n */\n\n// The calculator's domain payload is the seam's own type, imported from the component so the\n// binding is a direct assignment and the types never drift from the contract the component's tests\n// assert.\ntype RawOption = NonNullable<CartShippingSimulationQuery['cartShippingSimulation']['shippingOptions']>[number];\n\nconst UNKNOWN_ERROR: ShippingSimulateError = {\n code: 'UNKNOWN',\n message: 'Unable to calculate shipping. Try again.',\n};\n\nfunction mapErrorCode(code: ShippingSimulateErrorCode): ShippingSimulateError['code'] {\n return code === 'INVALID_POSTAL_CODE' ? 'INVALID_POSTAL_CODE' : 'UNKNOWN';\n}\n\nfunction mapOption(option: RawOption): ShippingOption {\n return {\n id: option.id,\n name: option.name,\n channel: option.channel,\n shippingEstimate: option.shippingEstimate,\n price: { amount: option.price.amount, currencyCode: option.price.currencyCode },\n listPrice: { amount: option.listPrice.amount, currencyCode: option.listPrice.currencyCode },\n };\n}\n\nexport function useCartShippingSimulation(): (input: CartShippingSimulateInput) => Promise<ShippingSimulationPayload> {\n // Read the client off Apollo's context directly rather than via `useApolloClient`, which throws at\n // render when no provider is present. The hook is the calculator's default `onSimulate` and runs\n // in every Root render, including presentational tests/stories that mount the Root with their own\n // callback and no ApolloProvider; a missing client only matters when the default callback is\n // actually invoked, where it is mapped to the same UNKNOWN userError as any other failure.\n const { client } = useContext(getApolloContext());\n\n return useCallback(\n async (input: CartShippingSimulateInput): Promise<ShippingSimulationPayload> => {\n if (!client) {\n return { shippingOptions: null, userErrors: [UNKNOWN_ERROR] };\n }\n try {\n const result = await withRequestTimeout((signal) =>\n client.query({\n query: CART_SHIPPING_SIMULATION,\n variables: { input },\n fetchPolicy: 'no-cache',\n context: { fetchOptions: { signal } },\n }),\n );\n\n if (result.error || !result.data) {\n return { shippingOptions: null, userErrors: [UNKNOWN_ERROR] };\n }\n\n const payload = result.data.cartShippingSimulation;\n const userErrors = payload.userErrors.map((error) => ({\n code: mapErrorCode(error.code),\n message: error.message,\n }));\n\n if (userErrors.length > 0) {\n return { shippingOptions: null, userErrors };\n }\n\n return {\n shippingOptions: payload.shippingOptions?.map(mapOption) ?? null,\n userErrors: [],\n };\n } catch {\n return { shippingOptions: null, userErrors: [UNKNOWN_ERROR] };\n }\n },\n [client],\n );\n}\n"],"mappings":";;;;;;AA+BA,MAAM,gBAAuC;CAC3C,MAAM;CACN,SAAS;AACX;AAEA,SAAS,aAAa,MAAgE;CACpF,OAAO,SAAS,wBAAwB,wBAAwB;AAClE;AAEA,SAAS,UAAU,QAAmC;CACpD,OAAO;EACL,IAAI,OAAO;EACX,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,kBAAkB,OAAO;EACzB,OAAO;GAAE,QAAQ,OAAO,MAAM;GAAQ,cAAc,OAAO,MAAM;EAAa;EAC9E,WAAW;GAAE,QAAQ,OAAO,UAAU;GAAQ,cAAc,OAAO,UAAU;EAAa;CAC5F;AACF;AAEA,SAAgB,4BAAsG;CAMpH,MAAM,EAAE,WAAW,WAAW,iBAAiB,CAAC;CAEhD,OAAO,YACL,OAAO,UAAyE;EAC9E,IAAI,CAAC,QACH,OAAO;GAAE,iBAAiB;GAAM,YAAY,CAAC,aAAa;EAAE;EAE9D,IAAI;GACF,MAAM,SAAS,MAAM,oBAAoB,WACvC,OAAO,MAAM;IACX,OAAO;IACP,WAAW,EAAE,MAAM;IACnB,aAAa;IACb,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE;GACtC,CAAC,CACH;GAEA,IAAI,OAAO,SAAS,CAAC,OAAO,MAC1B,OAAO;IAAE,iBAAiB;IAAM,YAAY,CAAC,aAAa;GAAE;GAG9D,MAAM,UAAU,OAAO,KAAK;GAC5B,MAAM,aAAa,QAAQ,WAAW,KAAK,WAAW;IACpD,MAAM,aAAa,MAAM,IAAI;IAC7B,SAAS,MAAM;GACjB,EAAE;GAEF,IAAI,WAAW,SAAS,GACtB,OAAO;IAAE,iBAAiB;IAAM;GAAW;GAG7C,OAAO;IACL,iBAAiB,QAAQ,iBAAiB,IAAI,SAAS,KAAK;IAC5D,YAAY,CAAC;GACf;EACF,QAAQ;GACN,OAAO;IAAE,iBAAiB;IAAM,YAAY,CAAC,aAAa;GAAE;EAC9D;CACF,GACA,CAAC,MAAM,CACT;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "../../core/dist/index.js";
|
|
2
|
+
import { ShippingOptionSelectUserError } from "./option-select-operations.js";
|
|
3
|
+
import { ShippingAddressInput, ShippingAddressUpdateErrorEntity } from "./shipping-operations.js";
|
|
4
|
+
//#region src/sdk/shipping/use-shipping-actions.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The `shipping` action namespace — the sanctioned client write surface against the VTEX orderForm
|
|
7
|
+
* shippingData: delivery-address updates (specs/shipping-address-step.md, US-7;
|
|
8
|
+
* docs/storefront-core/adr-0010-actions-own-the-write-side.md) and cart-scoped delivery-option
|
|
9
|
+
* selection (specs/delivery-options-step.md, Decision 4). Per Decision 4 the two tasks share this one
|
|
10
|
+
* namespace — T2 (`setAddress`) merged first and owns the registration, T3 extends it with
|
|
11
|
+
* `selectOption` here.
|
|
12
|
+
*
|
|
13
|
+
* Both actions are async/pessimistic (Decision 1 of the address spec): the handler awaits the
|
|
14
|
+
* mutation and only the server-confirmed payload changes the cache. Each is stateless (no reactive
|
|
15
|
+
* vars, no module state), resolves its payload `userErrors` (empty on success), and never throws for
|
|
16
|
+
* expected outcomes; an infrastructure failure (network or an upstream GraphQLError) is caught and
|
|
17
|
+
* collapsed to one synthetic network `userError` — no per-code branching (US-4, FR-5). Inputs pass
|
|
18
|
+
* through mutation variables only — never logged, never stored beyond the cache.
|
|
19
|
+
*/
|
|
20
|
+
export type ShippingActions = Readonly<{
|
|
21
|
+
/** Persist the single delivery address (async/pessimistic). Resolves the payload userErrors. */
|
|
22
|
+
setAddress: (address: ShippingAddressInput) => Promise<readonly ShippingAddressUpdateErrorEntity[]>;
|
|
23
|
+
/** Select a delivery option for the whole cart. Resolves the payload userErrors (empty on success). */
|
|
24
|
+
selectOption: (optionId: string) => Promise<readonly ShippingOptionSelectUserError[]>;
|
|
25
|
+
}>;
|
|
26
|
+
//#endregion
|
|
27
|
+
//# sourceMappingURL=use-shipping-actions.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { defineActions } from "../../core/dist/actions/registry.js";
|
|
3
|
+
import "../../core/dist/index.js";
|
|
4
|
+
import { SHIPPING_ADDRESS_UPDATE, SHIPPING_NETWORK_ERROR_CODE } from "./shipping-operations.js";
|
|
5
|
+
import { SHIPPING_OPTION_SELECT } from "./option-select-operations.js";
|
|
6
|
+
import { useMutation } from "@apollo/client/react";
|
|
7
|
+
import { useCallback, useMemo } from "react";
|
|
8
|
+
//#region src/sdk/shipping/use-shipping-actions.ts
|
|
9
|
+
const SET_ADDRESS_NETWORK_ERROR = {
|
|
10
|
+
code: SHIPPING_NETWORK_ERROR_CODE,
|
|
11
|
+
message: "Unable to complete the request. Please try again."
|
|
12
|
+
};
|
|
13
|
+
const SELECT_OPTION_NETWORK_ERROR = {
|
|
14
|
+
code: "NETWORK_ERROR",
|
|
15
|
+
message: "Unable to update the delivery option. Please try again."
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The `shipping` namespace hook. Registered with the first-party action registry via `shippingActions`
|
|
19
|
+
* below; the compiler-emitted `ShippingActionProvider` calls it and threads the narrowed methods into
|
|
20
|
+
* each consumer's `$actions.shipping`. Writes persist purely through the normalized-cache merge of
|
|
21
|
+
* each mutation response (Decision 2 of the address spec) — no refetch, no imperative write.
|
|
22
|
+
*/
|
|
23
|
+
function useShippingActions() {
|
|
24
|
+
const [addressMutation] = useMutation(SHIPPING_ADDRESS_UPDATE);
|
|
25
|
+
const [selectOptionMutation] = useMutation(SHIPPING_OPTION_SELECT);
|
|
26
|
+
const setAddress = useCallback(async (address) => {
|
|
27
|
+
try {
|
|
28
|
+
return (await addressMutation({ variables: { input: address } })).data?.shippingAddressUpdate.userErrors ?? [];
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("[shipping.setAddress] shippingAddressUpdate failed", error);
|
|
31
|
+
return [SET_ADDRESS_NETWORK_ERROR];
|
|
32
|
+
}
|
|
33
|
+
}, [addressMutation]);
|
|
34
|
+
const selectOption = useCallback(async (optionId) => {
|
|
35
|
+
try {
|
|
36
|
+
return (await selectOptionMutation({ variables: { input: { optionId } } })).data?.shippingOptionSelect.userErrors ?? [];
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error("[shipping.selectOption] shippingOptionSelect failed", error);
|
|
39
|
+
return [SELECT_OPTION_NETWORK_ERROR];
|
|
40
|
+
}
|
|
41
|
+
}, [selectOptionMutation]);
|
|
42
|
+
return useMemo(() => ({
|
|
43
|
+
setAddress,
|
|
44
|
+
selectOption
|
|
45
|
+
}), [setAddress, selectOption]);
|
|
46
|
+
}
|
|
47
|
+
defineActions({
|
|
48
|
+
namespace: "shipping",
|
|
49
|
+
description: "Mutation-backed delivery writes against the VTEX orderForm shippingData (address in T2; option in T3).",
|
|
50
|
+
provider: {
|
|
51
|
+
name: "ShippingActionProvider",
|
|
52
|
+
importPath: "@vtex/faststore/internal/client"
|
|
53
|
+
},
|
|
54
|
+
methods: {
|
|
55
|
+
setAddress: {
|
|
56
|
+
description: "Persist the single delivery address in one submit (async/pessimistic). Resolves the payload userErrors.",
|
|
57
|
+
payload: [
|
|
58
|
+
{
|
|
59
|
+
name: "savedAddressId",
|
|
60
|
+
type: "string"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "recipientName",
|
|
64
|
+
type: "string"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "postalCode",
|
|
68
|
+
type: "string"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "country",
|
|
72
|
+
type: "string"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "street",
|
|
76
|
+
type: "string"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "number",
|
|
80
|
+
type: "string"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "complement",
|
|
84
|
+
type: "string"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "neighborhood",
|
|
88
|
+
type: "string"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "city",
|
|
92
|
+
type: "string"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "state",
|
|
96
|
+
type: "string"
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
selectOption: {
|
|
101
|
+
description: "Select a delivery option for the whole cart (async/pessimistic). Resolves the payload userErrors.",
|
|
102
|
+
payload: [{
|
|
103
|
+
name: "optionId",
|
|
104
|
+
type: "string"
|
|
105
|
+
}]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
use: useShippingActions
|
|
109
|
+
});
|
|
110
|
+
//#endregion
|
|
111
|
+
export { useShippingActions };
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=use-shipping-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-shipping-actions.js","names":[],"sources":["../../../src/sdk/shipping/use-shipping-actions.ts"],"sourcesContent":["'use client';\n\nimport { useMutation } from '@apollo/client/react';\nimport { defineActions } from '@vtex/fs-core';\nimport { useCallback, useMemo } from 'react';\nimport { SHIPPING_OPTION_SELECT, type ShippingOptionSelectUserError } from './option-select-operations.js';\nimport {\n SHIPPING_ADDRESS_UPDATE,\n SHIPPING_NETWORK_ERROR_CODE,\n type ShippingAddressInput,\n type ShippingAddressUpdateErrorEntity,\n} from './shipping-operations.js';\n\n/**\n * The `shipping` action namespace — the sanctioned client write surface against the VTEX orderForm\n * shippingData: delivery-address updates (specs/shipping-address-step.md, US-7;\n * docs/storefront-core/adr-0010-actions-own-the-write-side.md) and cart-scoped delivery-option\n * selection (specs/delivery-options-step.md, Decision 4). Per Decision 4 the two tasks share this one\n * namespace — T2 (`setAddress`) merged first and owns the registration, T3 extends it with\n * `selectOption` here.\n *\n * Both actions are async/pessimistic (Decision 1 of the address spec): the handler awaits the\n * mutation and only the server-confirmed payload changes the cache. Each is stateless (no reactive\n * vars, no module state), resolves its payload `userErrors` (empty on success), and never throws for\n * expected outcomes; an infrastructure failure (network or an upstream GraphQLError) is caught and\n * collapsed to one synthetic network `userError` — no per-code branching (US-4, FR-5). Inputs pass\n * through mutation variables only — never logged, never stored beyond the cache.\n */\nexport type ShippingActions = Readonly<{\n /** Persist the single delivery address (async/pessimistic). Resolves the payload userErrors. */\n setAddress: (address: ShippingAddressInput) => Promise<readonly ShippingAddressUpdateErrorEntity[]>;\n /** Select a delivery option for the whole cart. Resolves the payload userErrors (empty on success). */\n selectOption: (optionId: string) => Promise<readonly ShippingOptionSelectUserError[]>;\n}>;\n\nconst SET_ADDRESS_NETWORK_ERROR: ShippingAddressUpdateErrorEntity = {\n code: SHIPPING_NETWORK_ERROR_CODE,\n message: 'Unable to complete the request. Please try again.',\n};\n\nconst SELECT_OPTION_NETWORK_ERROR: ShippingOptionSelectUserError = {\n code: 'NETWORK_ERROR',\n message: 'Unable to update the delivery option. Please try again.',\n};\n\n/**\n * The `shipping` namespace hook. Registered with the first-party action registry via `shippingActions`\n * below; the compiler-emitted `ShippingActionProvider` calls it and threads the narrowed methods into\n * each consumer's `$actions.shipping`. Writes persist purely through the normalized-cache merge of\n * each mutation response (Decision 2 of the address spec) — no refetch, no imperative write.\n */\nexport function useShippingActions(): ShippingActions {\n const [addressMutation] = useMutation(SHIPPING_ADDRESS_UPDATE);\n const [selectOptionMutation] = useMutation(SHIPPING_OPTION_SELECT);\n\n const setAddress = useCallback<ShippingActions['setAddress']>(\n async (address) => {\n try {\n const result = await addressMutation({ variables: { input: address } });\n return result.data?.shippingAddressUpdate.userErrors ?? [];\n } catch (error) {\n console.error('[shipping.setAddress] shippingAddressUpdate failed', error);\n return [SET_ADDRESS_NETWORK_ERROR];\n }\n },\n [addressMutation],\n );\n\n const selectOption = useCallback<ShippingActions['selectOption']>(\n async (optionId) => {\n try {\n const result = await selectOptionMutation({ variables: { input: { optionId } } });\n return result.data?.shippingOptionSelect.userErrors ?? [];\n } catch (error) {\n console.error('[shipping.selectOption] shippingOptionSelect failed', error);\n return [SELECT_OPTION_NETWORK_ERROR];\n }\n },\n [selectOptionMutation],\n );\n\n return useMemo(() => ({ setAddress, selectOption }), [setAddress, selectOption]);\n}\n\n/**\n * Declares the `shipping` action namespace — the single source of truth for its method/payload\n * metadata, runtime provider, and `use` hook (mirrors `cartActions`, `sessionActions`). The native\n * catalog builder (`scripts/build-catalog.mjs`) statically reads this call to emit `actions.json`;\n * at runtime `ShippingActionProvider` calls `useShippingActions` directly.\n */\nexport const shippingActions = defineActions({\n namespace: 'shipping',\n description: 'Mutation-backed delivery writes against the VTEX orderForm shippingData (address in T2; option in T3).',\n provider: { name: 'ShippingActionProvider', importPath: '@vtex/faststore/internal/client' },\n methods: {\n setAddress: {\n description:\n 'Persist the single delivery address in one submit (async/pessimistic). Resolves the payload userErrors.',\n payload: [\n { name: 'savedAddressId', type: 'string' },\n { name: 'recipientName', type: 'string' },\n { name: 'postalCode', type: 'string' },\n { name: 'country', type: 'string' },\n { name: 'street', type: 'string' },\n { name: 'number', type: 'string' },\n { name: 'complement', type: 'string' },\n { name: 'neighborhood', type: 'string' },\n { name: 'city', type: 'string' },\n { name: 'state', type: 'string' },\n ],\n },\n selectOption: {\n description: 'Select a delivery option for the whole cart (async/pessimistic). Resolves the payload userErrors.',\n payload: [{ name: 'optionId', type: 'string' }],\n },\n },\n use: useShippingActions,\n});\n"],"mappings":";;;;;;;;AAmCA,MAAM,4BAA8D;CAClE,MAAM;CACN,SAAS;AACX;AAEA,MAAM,8BAA6D;CACjE,MAAM;CACN,SAAS;AACX;;;;;;;AAQA,SAAgB,qBAAsC;CACpD,MAAM,CAAC,mBAAmB,YAAY,uBAAuB;CAC7D,MAAM,CAAC,wBAAwB,YAAY,sBAAsB;CAEjE,MAAM,aAAa,YACjB,OAAO,YAAY;EACjB,IAAI;GAEF,QAAO,MADc,gBAAgB,EAAE,WAAW,EAAE,OAAO,QAAQ,EAAE,CAAC,EAAA,CACxD,MAAM,sBAAsB,cAAc,CAAC;EAC3D,SAAS,OAAO;GACd,QAAQ,MAAM,sDAAsD,KAAK;GACzE,OAAO,CAAC,yBAAyB;EACnC;CACF,GACA,CAAC,eAAe,CAClB;CAEA,MAAM,eAAe,YACnB,OAAO,aAAa;EAClB,IAAI;GAEF,QAAO,MADc,qBAAqB,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,EAAA,CAClE,MAAM,qBAAqB,cAAc,CAAC;EAC1D,SAAS,OAAO;GACd,QAAQ,MAAM,uDAAuD,KAAK;GAC1E,OAAO,CAAC,2BAA2B;EACrC;CACF,GACA,CAAC,oBAAoB,CACvB;CAEA,OAAO,eAAe;EAAE;EAAY;CAAa,IAAI,CAAC,YAAY,YAAY,CAAC;AACjF;AAQ+B,cAAc;CAC3C,WAAW;CACX,aAAa;CACb,UAAU;EAAE,MAAM;EAA0B,YAAY;CAAkC;CAC1F,SAAS;EACP,YAAY;GACV,aACE;GACF,SAAS;IACP;KAAE,MAAM;KAAkB,MAAM;IAAS;IACzC;KAAE,MAAM;KAAiB,MAAM;IAAS;IACxC;KAAE,MAAM;KAAc,MAAM;IAAS;IACrC;KAAE,MAAM;KAAW,MAAM;IAAS;IAClC;KAAE,MAAM;KAAU,MAAM;IAAS;IACjC;KAAE,MAAM;KAAU,MAAM;IAAS;IACjC;KAAE,MAAM;KAAc,MAAM;IAAS;IACrC;KAAE,MAAM;KAAgB,MAAM;IAAS;IACvC;KAAE,MAAM;KAAQ,MAAM;IAAS;IAC/B;KAAE,MAAM;KAAS,MAAM;IAAS;GAClC;EACF;EACA,cAAc;GACZ,aAAa;GACb,SAAS,CAAC;IAAE,MAAM;IAAY,MAAM;GAAS,CAAC;EAChD;CACF;CACA,KAAK;AACP,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ShippingSimulateInput } from "../generated/graphql.js";
|
|
2
|
+
import "./operations.js";
|
|
3
|
+
import { ShippingSimulationPayload } from "../../matter/shipping-simulator/shipping-simulator.js";
|
|
4
|
+
//#region src/sdk/shipping/use-shipping-simulation.d.ts
|
|
5
|
+
export declare function useShippingSimulation(): (input: ShippingSimulateInput) => Promise<ShippingSimulationPayload>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=use-shipping-simulation.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { withRequestTimeout } from "./request-timeout.js";
|
|
3
|
+
import { SHIPPING_SIMULATION } from "./operations.js";
|
|
4
|
+
import { getApolloContext } from "@apollo/client/react";
|
|
5
|
+
import { useCallback, useContext } from "react";
|
|
6
|
+
//#region src/sdk/shipping/use-shipping-simulation.ts
|
|
7
|
+
const UNKNOWN_ERROR = {
|
|
8
|
+
code: "UNKNOWN",
|
|
9
|
+
message: "Unable to calculate shipping. Try again."
|
|
10
|
+
};
|
|
11
|
+
function mapErrorCode(code) {
|
|
12
|
+
return code === "INVALID_POSTAL_CODE" ? "INVALID_POSTAL_CODE" : "UNKNOWN";
|
|
13
|
+
}
|
|
14
|
+
function mapOption(option) {
|
|
15
|
+
return {
|
|
16
|
+
id: option.id,
|
|
17
|
+
name: option.name,
|
|
18
|
+
channel: option.channel,
|
|
19
|
+
shippingEstimate: option.shippingEstimate,
|
|
20
|
+
price: {
|
|
21
|
+
amount: option.price.amount,
|
|
22
|
+
currencyCode: option.price.currencyCode
|
|
23
|
+
},
|
|
24
|
+
listPrice: {
|
|
25
|
+
amount: option.listPrice.amount,
|
|
26
|
+
currencyCode: option.listPrice.currencyCode
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function useShippingSimulation() {
|
|
31
|
+
const { client } = useContext(getApolloContext());
|
|
32
|
+
return useCallback(async (input) => {
|
|
33
|
+
if (!client) return {
|
|
34
|
+
shippingOptions: null,
|
|
35
|
+
userErrors: [UNKNOWN_ERROR]
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
const result = await withRequestTimeout((signal) => client.query({
|
|
39
|
+
query: SHIPPING_SIMULATION,
|
|
40
|
+
variables: { input },
|
|
41
|
+
fetchPolicy: "no-cache",
|
|
42
|
+
context: { fetchOptions: { signal } }
|
|
43
|
+
}));
|
|
44
|
+
if (result.error || !result.data) return {
|
|
45
|
+
shippingOptions: null,
|
|
46
|
+
userErrors: [UNKNOWN_ERROR]
|
|
47
|
+
};
|
|
48
|
+
const payload = result.data.shippingSimulation;
|
|
49
|
+
const userErrors = payload.userErrors.map((error) => ({
|
|
50
|
+
code: mapErrorCode(error.code),
|
|
51
|
+
message: error.message
|
|
52
|
+
}));
|
|
53
|
+
if (userErrors.length > 0) return {
|
|
54
|
+
shippingOptions: null,
|
|
55
|
+
userErrors
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
shippingOptions: payload.shippingOptions?.map(mapOption) ?? null,
|
|
59
|
+
userErrors: []
|
|
60
|
+
};
|
|
61
|
+
} catch {
|
|
62
|
+
return {
|
|
63
|
+
shippingOptions: null,
|
|
64
|
+
userErrors: [UNKNOWN_ERROR]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}, [client]);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { useShippingSimulation };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=use-shipping-simulation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-shipping-simulation.js","names":[],"sources":["../../../src/sdk/shipping/use-shipping-simulation.ts"],"sourcesContent":["'use client';\n\nimport { getApolloContext } from '@apollo/client/react';\nimport { useCallback, useContext } from 'react';\nimport type {\n ShippingOption,\n ShippingSimulateError,\n ShippingSimulationPayload,\n} from '../../matter/shipping-simulator/shipping-simulator.js';\nimport type { ShippingSimulateErrorCode, ShippingSimulationQuery } from '../generated/graphql.js';\nimport { SHIPPING_SIMULATION, type ShippingSimulateInput } from './operations.js';\nimport { withRequestTimeout } from './request-timeout.js';\n\n/**\n * Shipping-simulation SDK hook (FSPG-815 / specs/fspg-815-minicart-wire-shipping-simulator-pdp.md).\n *\n * Returns the simulator's `onSimulate(input) => Promise<payload>` callback. It runs the\n * `ShippingSimulation` query imperatively per submit via the Apollo client read from\n * `getApolloContext()` (a non-throwing read; see the inline note below). The mapping is thin: the\n * structured `ShippingEstimate { value, unit }` is carried through untouched (the component\n * localizes it, where the `locale` lives), the API `Money` is carried as `{ amount, currencyCode }`,\n * and any transport/GraphQL failure is collapsed to one `UNKNOWN` userError so the component's\n * success/error transition stays deterministic.\n */\n\n// The simulator's domain payload is the seam's own type, imported from the component so the binding\n// is a direct assignment and the types never drift from the contract the component's tests assert.\ntype RawOption = NonNullable<ShippingSimulationQuery['shippingSimulation']['shippingOptions']>[number];\n\nconst UNKNOWN_ERROR: ShippingSimulateError = {\n code: 'UNKNOWN',\n message: 'Unable to calculate shipping. Try again.',\n};\n\nfunction mapErrorCode(code: ShippingSimulateErrorCode): ShippingSimulateError['code'] {\n return code === 'INVALID_POSTAL_CODE' ? 'INVALID_POSTAL_CODE' : 'UNKNOWN';\n}\n\nfunction mapOption(option: RawOption): ShippingOption {\n return {\n id: option.id,\n name: option.name,\n channel: option.channel,\n shippingEstimate: option.shippingEstimate,\n price: { amount: option.price.amount, currencyCode: option.price.currencyCode },\n listPrice: { amount: option.listPrice.amount, currencyCode: option.listPrice.currencyCode },\n };\n}\n\nexport function useShippingSimulation(): (input: ShippingSimulateInput) => Promise<ShippingSimulationPayload> {\n // Read the client off Apollo's context directly rather than via `useApolloClient`, which throws\n // at render when no provider is present. The hook is the default `onSimulate` and runs in every\n // Root render, including presentational tests/stories that mount the Root with their own callback\n // and no ApolloProvider; a missing client only matters when the default callback is actually\n // invoked, where it is mapped to the same UNKNOWN userError as any other failure.\n const { client } = useContext(getApolloContext());\n\n return useCallback(\n async (input: ShippingSimulateInput): Promise<ShippingSimulationPayload> => {\n if (!client) {\n return { shippingOptions: null, userErrors: [UNKNOWN_ERROR] };\n }\n try {\n const result = await withRequestTimeout((signal) =>\n client.query({\n query: SHIPPING_SIMULATION,\n variables: { input },\n fetchPolicy: 'no-cache',\n context: { fetchOptions: { signal } },\n }),\n );\n\n if (result.error || !result.data) {\n return { shippingOptions: null, userErrors: [UNKNOWN_ERROR] };\n }\n\n const payload = result.data.shippingSimulation;\n const userErrors = payload.userErrors.map((error) => ({\n code: mapErrorCode(error.code),\n message: error.message,\n }));\n\n if (userErrors.length > 0) {\n return { shippingOptions: null, userErrors };\n }\n\n return {\n shippingOptions: payload.shippingOptions?.map(mapOption) ?? null,\n userErrors: [],\n };\n } catch {\n return { shippingOptions: null, userErrors: [UNKNOWN_ERROR] };\n }\n },\n [client],\n );\n}\n"],"mappings":";;;;;;AA6BA,MAAM,gBAAuC;CAC3C,MAAM;CACN,SAAS;AACX;AAEA,SAAS,aAAa,MAAgE;CACpF,OAAO,SAAS,wBAAwB,wBAAwB;AAClE;AAEA,SAAS,UAAU,QAAmC;CACpD,OAAO;EACL,IAAI,OAAO;EACX,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,kBAAkB,OAAO;EACzB,OAAO;GAAE,QAAQ,OAAO,MAAM;GAAQ,cAAc,OAAO,MAAM;EAAa;EAC9E,WAAW;GAAE,QAAQ,OAAO,UAAU;GAAQ,cAAc,OAAO,UAAU;EAAa;CAC5F;AACF;AAEA,SAAgB,wBAA8F;CAM5G,MAAM,EAAE,WAAW,WAAW,iBAAiB,CAAC;CAEhD,OAAO,YACL,OAAO,UAAqE;EAC1E,IAAI,CAAC,QACH,OAAO;GAAE,iBAAiB;GAAM,YAAY,CAAC,aAAa;EAAE;EAE9D,IAAI;GACF,MAAM,SAAS,MAAM,oBAAoB,WACvC,OAAO,MAAM;IACX,OAAO;IACP,WAAW,EAAE,MAAM;IACnB,aAAa;IACb,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE;GACtC,CAAC,CACH;GAEA,IAAI,OAAO,SAAS,CAAC,OAAO,MAC1B,OAAO;IAAE,iBAAiB;IAAM,YAAY,CAAC,aAAa;GAAE;GAG9D,MAAM,UAAU,OAAO,KAAK;GAC5B,MAAM,aAAa,QAAQ,WAAW,KAAK,WAAW;IACpD,MAAM,aAAa,MAAM,IAAI;IAC7B,SAAS,MAAM;GACjB,EAAE;GAEF,IAAI,WAAW,SAAS,GACtB,OAAO;IAAE,iBAAiB;IAAM;GAAW;GAG7C,OAAO;IACL,iBAAiB,QAAQ,iBAAiB,IAAI,SAAS,KAAK;IAC5D,YAAY,CAAC;GACf;EACF,QAAQ;GACN,OAAO;IAAE,iBAAiB;IAAM,YAAY,CAAC,aAAa;GAAE;EAC9D;CACF,GACA,CAAC,MAAM,CACT;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/sdk/state/cart.d.ts
|
|
2
|
+
export declare const orderFormIdVar: import("@apollo/client").ReactiveVar<string | null>;
|
|
3
|
+
/**
|
|
4
|
+
* Latest `userErrors` from any cart write, surfaced context-free. The cart action hook publishes
|
|
5
|
+
* here on every call (cleared synchronously at the start of the next call) and `CartError` reads it
|
|
6
|
+
* via `useReactiveVar`, decoupling error display from `CartRoot`'s data context (specs/actions.md
|
|
7
|
+
* FR-9). Stays in client state — never a query variable or request header.
|
|
8
|
+
*/
|
|
9
|
+
export declare const cartUserErrorsVar: import("@apollo/client").ReactiveVar<readonly Readonly<{
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}>[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Monotonic add-success pulse. `addItem` increments it on each successful add (no userErrors); the
|
|
15
|
+
* error and network-catch branches leave it untouched. `CartOpenOnAdd` and `CartRedirectOnAdd` key
|
|
16
|
+
* a `useEffect` on it via `useReactiveVar`, so every successful add re-fires their behavior even when
|
|
17
|
+
* the drawer is already open or was just closed — a boolean would not re-fire on an unchanged value
|
|
18
|
+
* (specs/fspg-822-minicart-open-on-add.md, Decision 2). Client state only — never a query variable
|
|
19
|
+
* or request header.
|
|
20
|
+
*/
|
|
21
|
+
export declare const cartLastAddVar: import("@apollo/client").ReactiveVar<number>;
|
|
22
|
+
/**
|
|
23
|
+
* The mini-cart's open state, surfaced context-free. `CartOpenOnAdd` reads it via `useReactiveVar`
|
|
24
|
+
* to control the `DrawerRoot` and writes it back through `onOpenChange` so the header trigger and
|
|
25
|
+
* manual close (Escape / backdrop / close button) stay in sync. The single source of truth for the
|
|
26
|
+
* controlled drawer; `addItem` never writes it. Client state only — never a query variable or
|
|
27
|
+
* request header.
|
|
28
|
+
*/
|
|
29
|
+
export declare const miniCartOpenVar: import("@apollo/client").ReactiveVar<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Latest `userErrors` from a coupon write (`applyCoupon` / `removeCoupon`), surfaced context-free.
|
|
32
|
+
* A dedicated channel mirroring `cartUserErrorsVar` so coupon feedback sits next to the coupon form
|
|
33
|
+
* and never collides with item-write errors (specs/fspg-830-coupon-entry.md AD-2). The coupon
|
|
34
|
+
* actions publish here on every call (cleared at the start of the next call) and `CartCouponError`
|
|
35
|
+
* reads it via `useReactiveVar`. Stays in client state — never a query variable or request header.
|
|
36
|
+
*/
|
|
37
|
+
export declare const cartCouponErrorsVar: import("@apollo/client").ReactiveVar<readonly Readonly<{
|
|
38
|
+
code: string;
|
|
39
|
+
message: string;
|
|
40
|
+
}>[]>;
|
|
41
|
+
//#endregion
|
|
42
|
+
//# sourceMappingURL=cart.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { makeVar } from "@apollo/client";
|
|
2
|
+
//#region src/sdk/state/cart.ts
|
|
3
|
+
const orderFormIdVar = makeVar(null);
|
|
4
|
+
/**
|
|
5
|
+
* Latest `userErrors` from any cart write, surfaced context-free. The cart action hook publishes
|
|
6
|
+
* here on every call (cleared synchronously at the start of the next call) and `CartError` reads it
|
|
7
|
+
* via `useReactiveVar`, decoupling error display from `CartRoot`'s data context (specs/actions.md
|
|
8
|
+
* FR-9). Stays in client state — never a query variable or request header.
|
|
9
|
+
*/
|
|
10
|
+
const cartUserErrorsVar = makeVar([]);
|
|
11
|
+
/**
|
|
12
|
+
* Monotonic add-success pulse. `addItem` increments it on each successful add (no userErrors); the
|
|
13
|
+
* error and network-catch branches leave it untouched. `CartOpenOnAdd` and `CartRedirectOnAdd` key
|
|
14
|
+
* a `useEffect` on it via `useReactiveVar`, so every successful add re-fires their behavior even when
|
|
15
|
+
* the drawer is already open or was just closed — a boolean would not re-fire on an unchanged value
|
|
16
|
+
* (specs/fspg-822-minicart-open-on-add.md, Decision 2). Client state only — never a query variable
|
|
17
|
+
* or request header.
|
|
18
|
+
*/
|
|
19
|
+
const cartLastAddVar = makeVar(0);
|
|
20
|
+
/**
|
|
21
|
+
* The mini-cart's open state, surfaced context-free. `CartOpenOnAdd` reads it via `useReactiveVar`
|
|
22
|
+
* to control the `DrawerRoot` and writes it back through `onOpenChange` so the header trigger and
|
|
23
|
+
* manual close (Escape / backdrop / close button) stay in sync. The single source of truth for the
|
|
24
|
+
* controlled drawer; `addItem` never writes it. Client state only — never a query variable or
|
|
25
|
+
* request header.
|
|
26
|
+
*/
|
|
27
|
+
const miniCartOpenVar = makeVar(false);
|
|
28
|
+
/**
|
|
29
|
+
* Latest `userErrors` from a coupon write (`applyCoupon` / `removeCoupon`), surfaced context-free.
|
|
30
|
+
* A dedicated channel mirroring `cartUserErrorsVar` so coupon feedback sits next to the coupon form
|
|
31
|
+
* and never collides with item-write errors (specs/fspg-830-coupon-entry.md AD-2). The coupon
|
|
32
|
+
* actions publish here on every call (cleared at the start of the next call) and `CartCouponError`
|
|
33
|
+
* reads it via `useReactiveVar`. Stays in client state — never a query variable or request header.
|
|
34
|
+
*/
|
|
35
|
+
const cartCouponErrorsVar = makeVar([]);
|
|
36
|
+
/**
|
|
37
|
+
* Count of cart writes currently in flight (specs/mini-cart-validation-wiring.md). Every mutating
|
|
38
|
+
* handler in the cart action namespace registers for the lifetime of its call, so `> 0` means a
|
|
39
|
+
* write is outstanding. The stock-validation open call reads this to skip while a write is running —
|
|
40
|
+
* that write's own response already carries current availability, so re-validating would be
|
|
41
|
+
* redundant. `validate` itself is read-only upstream and never registers here. Client state only —
|
|
42
|
+
* never a query variable or request header.
|
|
43
|
+
*/
|
|
44
|
+
const cartWritesInFlightVar = makeVar(0);
|
|
45
|
+
/**
|
|
46
|
+
* Epoch-ms timestamp of when the client last received current availability (`0` = never). Stamped on
|
|
47
|
+
* a successful `validate` and on every successful cart write, because a write's response already
|
|
48
|
+
* carries recomputed availability (specs/mini-cart-validation-wiring.md, Decision 2). The
|
|
49
|
+
* stock-validation open call compares `now - cartAvailabilityFreshAtVar()` against
|
|
50
|
+
* `CART_VALIDATE_STALENESS_MS` and skips while inside the window, so reopening the overlay — or
|
|
51
|
+
* opening it right after an add — does not re-validate. Client state only.
|
|
52
|
+
*/
|
|
53
|
+
const cartAvailabilityFreshAtVar = makeVar(0);
|
|
54
|
+
/**
|
|
55
|
+
* The staleness window for the stock-validation open call, in milliseconds. The single tuning knob:
|
|
56
|
+
* the platform's rate limits under real traffic are not known yet, so this value is a starting point,
|
|
57
|
+
* not a contract (specs/mini-cart-validation-wiring.md). The pre-checkout call ignores it and always
|
|
58
|
+
* runs.
|
|
59
|
+
*/
|
|
60
|
+
const CART_VALIDATE_STALENESS_MS = 3e4;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { CART_VALIDATE_STALENESS_MS, cartAvailabilityFreshAtVar, cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, cartWritesInFlightVar, miniCartOpenVar, orderFormIdVar };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=cart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart.js","names":[],"sources":["../../../src/sdk/state/cart.ts"],"sourcesContent":["import { makeVar } from '@apollo/client';\nimport type { CartUserError } from '../cart/operations.js';\n\n// Session-scoped cart identifier (`Cart.id` from the cart query response). Client state only —\n// never sent as a query variable or request header; the x-order-form-id cookie carries cart\n// context on the transport. Starts null; hydrated when the cart entity arrives, which opens the\n// cart action ready gate. See specs/cart-context-client-migrate.md (Decisions 2, 6).\nexport const orderFormIdVar = makeVar<string | null>(null);\n\n/**\n * Latest `userErrors` from any cart write, surfaced context-free. The cart action hook publishes\n * here on every call (cleared synchronously at the start of the next call) and `CartError` reads it\n * via `useReactiveVar`, decoupling error display from `CartRoot`'s data context (specs/actions.md\n * FR-9). Stays in client state — never a query variable or request header.\n */\nexport const cartUserErrorsVar = makeVar<readonly CartUserError[]>([]);\n\n/**\n * Monotonic add-success pulse. `addItem` increments it on each successful add (no userErrors); the\n * error and network-catch branches leave it untouched. `CartOpenOnAdd` and `CartRedirectOnAdd` key\n * a `useEffect` on it via `useReactiveVar`, so every successful add re-fires their behavior even when\n * the drawer is already open or was just closed — a boolean would not re-fire on an unchanged value\n * (specs/fspg-822-minicart-open-on-add.md, Decision 2). Client state only — never a query variable\n * or request header.\n */\nexport const cartLastAddVar = makeVar<number>(0);\n\n/**\n * The mini-cart's open state, surfaced context-free. `CartOpenOnAdd` reads it via `useReactiveVar`\n * to control the `DrawerRoot` and writes it back through `onOpenChange` so the header trigger and\n * manual close (Escape / backdrop / close button) stay in sync. The single source of truth for the\n * controlled drawer; `addItem` never writes it. Client state only — never a query variable or\n * request header.\n */\nexport const miniCartOpenVar = makeVar<boolean>(false);\n\n/**\n * Latest `userErrors` from a coupon write (`applyCoupon` / `removeCoupon`), surfaced context-free.\n * A dedicated channel mirroring `cartUserErrorsVar` so coupon feedback sits next to the coupon form\n * and never collides with item-write errors (specs/fspg-830-coupon-entry.md AD-2). The coupon\n * actions publish here on every call (cleared at the start of the next call) and `CartCouponError`\n * reads it via `useReactiveVar`. Stays in client state — never a query variable or request header.\n */\nexport const cartCouponErrorsVar = makeVar<readonly CartUserError[]>([]);\n\n/**\n * Count of cart writes currently in flight (specs/mini-cart-validation-wiring.md). Every mutating\n * handler in the cart action namespace registers for the lifetime of its call, so `> 0` means a\n * write is outstanding. The stock-validation open call reads this to skip while a write is running —\n * that write's own response already carries current availability, so re-validating would be\n * redundant. `validate` itself is read-only upstream and never registers here. Client state only —\n * never a query variable or request header.\n */\nexport const cartWritesInFlightVar = makeVar<number>(0);\n\n/**\n * Epoch-ms timestamp of when the client last received current availability (`0` = never). Stamped on\n * a successful `validate` and on every successful cart write, because a write's response already\n * carries recomputed availability (specs/mini-cart-validation-wiring.md, Decision 2). The\n * stock-validation open call compares `now - cartAvailabilityFreshAtVar()` against\n * `CART_VALIDATE_STALENESS_MS` and skips while inside the window, so reopening the overlay — or\n * opening it right after an add — does not re-validate. Client state only.\n */\nexport const cartAvailabilityFreshAtVar = makeVar<number>(0);\n\n/**\n * The staleness window for the stock-validation open call, in milliseconds. The single tuning knob:\n * the platform's rate limits under real traffic are not known yet, so this value is a starting point,\n * not a contract (specs/mini-cart-validation-wiring.md). The pre-checkout call ignores it and always\n * runs.\n */\nexport const CART_VALIDATE_STALENESS_MS = 30_000;\n"],"mappings":";;AAOA,MAAa,iBAAiB,QAAuB,IAAI;;;;;;;AAQzD,MAAa,oBAAoB,QAAkC,CAAC,CAAC;;;;;;;;;AAUrE,MAAa,iBAAiB,QAAgB,CAAC;;;;;;;;AAS/C,MAAa,kBAAkB,QAAiB,KAAK;;;;;;;;AASrD,MAAa,sBAAsB,QAAkC,CAAC,CAAC;;;;;;;;;AAUvE,MAAa,wBAAwB,QAAgB,CAAC;;;;;;;;;AAUtD,MAAa,6BAA6B,QAAgB,CAAC;;;;;;;AAQ3D,MAAa,6BAA6B"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { publishedVariantIdFor, selectedVariantVar } from "./variant-selector.js";
|
|
2
|
+
import { cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, miniCartOpenVar, orderFormIdVar } from "./cart.js";
|
|
3
|
+
export { cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, miniCartOpenVar, orderFormIdVar, publishedVariantIdFor, selectedVariantVar };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/sdk/state/variant-selector.d.ts
|
|
2
|
+
/** The shopper's in-page variant selection, scoped to the product it belongs to. The `productId`
|
|
3
|
+
* is the `Product` Node ID of the PDP that owns the selection; `variantId` is the selected
|
|
4
|
+
* `Variant` Node ID. Scoping prevents a selection made on one PDP from leaking into another after
|
|
5
|
+
* client-side navigation, since this var is a module-global singleton. See specs/sku-selector.md
|
|
6
|
+
* Decision 1. */
|
|
7
|
+
export type SelectedVariant = {
|
|
8
|
+
productId: string;
|
|
9
|
+
variantId: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const selectedVariantVar: import("@apollo/client").ReactiveVar<SelectedVariant | null>;
|
|
12
|
+
/** Resolves the published variant id for `productId`, or `null` when nothing is selected or the
|
|
13
|
+
* current selection belongs to a different product. Pass the value read via
|
|
14
|
+
* `useReactiveVar(selectedVariantVar)` so callers stay reactive. */
|
|
15
|
+
export declare function publishedVariantIdFor(selection: SelectedVariant | null, productId: string | null | undefined): string | null;
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=variant-selector.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { makeVar } from "@apollo/client";
|
|
2
|
+
//#region src/sdk/state/variant-selector.ts
|
|
3
|
+
const selectedVariantVar = makeVar(null);
|
|
4
|
+
/** Resolves the published variant id for `productId`, or `null` when nothing is selected or the
|
|
5
|
+
* current selection belongs to a different product. Pass the value read via
|
|
6
|
+
* `useReactiveVar(selectedVariantVar)` so callers stay reactive. */
|
|
7
|
+
function publishedVariantIdFor(selection, productId) {
|
|
8
|
+
if (!selection || !productId) return null;
|
|
9
|
+
return selection.productId === productId ? selection.variantId : null;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { publishedVariantIdFor, selectedVariantVar };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=variant-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant-selector.js","names":[],"sources":["../../../src/sdk/state/variant-selector.ts"],"sourcesContent":["import { makeVar } from '@apollo/client';\n\n/** The shopper's in-page variant selection, scoped to the product it belongs to. The `productId`\n * is the `Product` Node ID of the PDP that owns the selection; `variantId` is the selected\n * `Variant` Node ID. Scoping prevents a selection made on one PDP from leaking into another after\n * client-side navigation, since this var is a module-global singleton. See specs/sku-selector.md\n * Decision 1. */\nexport type SelectedVariant = {\n productId: string;\n variantId: string;\n};\n\n// Published by the PDP variant swatches; read by sibling matter (gallery, pricing, buy button) so a\n// swatch change refreshes them without a full page navigation. Starts null — the VariantSelectorRoot\n// derivation falls back to the page-supplied SKU (then the first variant) until a shopper activates a\n// swatch.\nexport const selectedVariantVar = makeVar<SelectedVariant | null>(null);\n\n/** Resolves the published variant id for `productId`, or `null` when nothing is selected or the\n * current selection belongs to a different product. Pass the value read via\n * `useReactiveVar(selectedVariantVar)` so callers stay reactive. */\nexport function publishedVariantIdFor(\n selection: SelectedVariant | null,\n productId: string | null | undefined,\n): string | null {\n if (!selection || !productId) return null;\n return selection.productId === productId ? selection.variantId : null;\n}\n"],"mappings":";;AAgBA,MAAa,qBAAqB,QAAgC,IAAI;;;;AAKtE,SAAgB,sBACd,WACA,WACe;CACf,IAAI,CAAC,aAAa,CAAC,WAAW,OAAO;CACrC,OAAO,UAAU,cAAc,YAAY,UAAU,YAAY;AACnE"}
|