@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,62 @@
|
|
|
1
|
+
import "../../core/dist/index.js";
|
|
2
|
+
import { ClientPreferenceKey, ClientProfileUserError, CustomerProfileUpdateInput, CustomerProfileUserError } from "./operations.js";
|
|
3
|
+
//#region src/sdk/identity/use-identity-actions.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The `identity` action namespace — the context-free owner of the shopper-profile,
|
|
6
|
+
* consent-preference, and persistent-profile writes
|
|
7
|
+
* (specs/fspg-859-email-field.md, specs/consent-opt-in-component.md,
|
|
8
|
+
* specs/sfs-3286-customer-profile-update-action.md,
|
|
9
|
+
* docs/storefront-core/adr-0010-actions-own-the-write-side.md).
|
|
10
|
+
*
|
|
11
|
+
* It mirrors `useCartActions`: a component anywhere in the tree dispatches the write through the
|
|
12
|
+
* compiler-injected `$actions.identity.*` prop, and the handler calls the corresponding mutation.
|
|
13
|
+
* Every write is **async / pessimistic** (Decision 1): the caller awaits the persisted result. Each
|
|
14
|
+
* call returns its `userErrors` (empty on success) so the caller can surface server-side failures
|
|
15
|
+
* inline; the returned entity self-updates the normalized cache and every reactive subscriber.
|
|
16
|
+
*
|
|
17
|
+
* The first two writes target the cart's sibling identity entities; `customerProfileUpdate` targets
|
|
18
|
+
* the shopper's account profile, which needs no cart at all.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Payload for the profile write. Callers persist only the fields they own; other fields are
|
|
22
|
+
* untouched. The payload is passed through to `ClientProfileUpdateInput` unmapped, so this type
|
|
23
|
+
* mirrors that input verbatim — a stacked field only needs a field to already exist here to reach
|
|
24
|
+
* the wire.
|
|
25
|
+
*/
|
|
26
|
+
export type ClientProfileUpdatePayload = Readonly<{
|
|
27
|
+
email?: string;
|
|
28
|
+
firstName?: string;
|
|
29
|
+
lastName?: string;
|
|
30
|
+
phone?: string;
|
|
31
|
+
document?: string;
|
|
32
|
+
}>;
|
|
33
|
+
/** Payload for the preferences write — one opt-in flag; the other flag is left untouched. */
|
|
34
|
+
export type ClientPreferencesUpdatePayload = Readonly<Partial<Record<ClientPreferenceKey, boolean>>>;
|
|
35
|
+
/**
|
|
36
|
+
* Payload for the persistent-profile write. Mirrors `CustomerProfileUpdateInput` verbatim and is
|
|
37
|
+
* forwarded unmapped, so an omitted field stays untouched upstream and an empty string erases.
|
|
38
|
+
*/
|
|
39
|
+
export type CustomerProfileUpdatePayload = CustomerProfileUpdateInput;
|
|
40
|
+
export type IdentityActions = Readonly<{
|
|
41
|
+
/**
|
|
42
|
+
* Persist the provided profile fields (partial) to the active cart's `clientProfileData`.
|
|
43
|
+
* Async — awaits the mutation before resolving. Returns the resulting `userErrors` (empty on
|
|
44
|
+
* success).
|
|
45
|
+
*/
|
|
46
|
+
clientProfileUpdate: (payload: ClientProfileUpdatePayload) => Promise<readonly ClientProfileUserError[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Persist the provided consent opt-in flag(s) (partial) to the shopper's `ClientPreferences`
|
|
49
|
+
* entity (order-form-backed). Async — awaits the mutation before resolving. Writes ONLY the
|
|
50
|
+
* requested field. Returns the resulting `userErrors` (empty on success).
|
|
51
|
+
*/
|
|
52
|
+
clientPreferencesUpdate: (payload: ClientPreferencesUpdatePayload) => Promise<readonly ClientProfileUserError[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Persist the provided profile fields (partial) to the shopper's persistent, cart-independent
|
|
55
|
+
* account profile. Async — awaits the mutation before resolving. Sends exactly the fields it is
|
|
56
|
+
* given: an omitted field is left untouched, an empty string erases. Returns the resulting
|
|
57
|
+
* `userErrors` (empty on success).
|
|
58
|
+
*/
|
|
59
|
+
customerProfileUpdate: (payload: CustomerProfileUpdatePayload) => Promise<readonly CustomerProfileUserError[]>;
|
|
60
|
+
}>;
|
|
61
|
+
//#endregion
|
|
62
|
+
//# sourceMappingURL=use-identity-actions.d.ts.map
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { defineActions } from "../../core/dist/actions/registry.js";
|
|
3
|
+
import "../../core/dist/index.js";
|
|
4
|
+
import { CLIENT_PREFERENCES_UPDATE, CLIENT_PROFILE_UPDATE, CUSTOMER_PROFILE_UPDATE } from "./operations.js";
|
|
5
|
+
import { useMutation } from "@apollo/client/react";
|
|
6
|
+
import { useCallback, useMemo } from "react";
|
|
7
|
+
import { CombinedGraphQLErrors } from "@apollo/client/errors";
|
|
8
|
+
//#region src/sdk/identity/use-identity-actions.ts
|
|
9
|
+
const NETWORK_PROFILE_ERROR = {
|
|
10
|
+
code: "NETWORK_ERROR",
|
|
11
|
+
message: "Unable to save your details. Please try again."
|
|
12
|
+
};
|
|
13
|
+
const NETWORK_PREFERENCE_ERROR = {
|
|
14
|
+
code: "NETWORK_ERROR",
|
|
15
|
+
message: "Unable to save your preference. Please try again."
|
|
16
|
+
};
|
|
17
|
+
const NETWORK_CUSTOMER_PROFILE_ERROR = {
|
|
18
|
+
code: "NETWORK_ERROR",
|
|
19
|
+
message: "Unable to save your profile. Please try again."
|
|
20
|
+
};
|
|
21
|
+
const UNAUTHORIZED_CUSTOMER_PROFILE_ERROR = {
|
|
22
|
+
code: "UNAUTHORIZED",
|
|
23
|
+
message: "Your session has expired. Please sign in again."
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The profile module answers an anonymous or expired session with a top-level `UNAUTHORIZED`, never
|
|
27
|
+
* a `userError`. Collapsing it into `NETWORK_ERROR` would offer a retry that cannot succeed, so it
|
|
28
|
+
* gets its own code and the caller can send the shopper back to sign-in.
|
|
29
|
+
*/
|
|
30
|
+
function toCustomerProfileError(error) {
|
|
31
|
+
if (CombinedGraphQLErrors.is(error)) {
|
|
32
|
+
if (error.errors.some(({ extensions }) => extensions?.code === "UNAUTHORIZED")) return UNAUTHORIZED_CUSTOMER_PROFILE_ERROR;
|
|
33
|
+
}
|
|
34
|
+
return NETWORK_CUSTOMER_PROFILE_ERROR;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The `identity` namespace hook. Registered with the first-party action registry via `identityActions`
|
|
38
|
+
* below; the compiler-emitted `IdentityActionProvider` calls it and threads the narrowed methods into
|
|
39
|
+
* each consumer's `$actions.identity`.
|
|
40
|
+
*/
|
|
41
|
+
function useIdentityActions() {
|
|
42
|
+
const [profileMutation] = useMutation(CLIENT_PROFILE_UPDATE);
|
|
43
|
+
const [preferencesMutation] = useMutation(CLIENT_PREFERENCES_UPDATE);
|
|
44
|
+
const [customerProfileMutation] = useMutation(CUSTOMER_PROFILE_UPDATE);
|
|
45
|
+
const clientProfileUpdate = useCallback(async (payload) => {
|
|
46
|
+
try {
|
|
47
|
+
return (await profileMutation({ variables: { input: payload } })).data?.clientProfileUpdate?.userErrors ?? [];
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("[identity.clientProfileUpdate] clientProfileUpdate failed", error instanceof Error ? error.name : "UnknownError");
|
|
50
|
+
return [NETWORK_PROFILE_ERROR];
|
|
51
|
+
}
|
|
52
|
+
}, [profileMutation]);
|
|
53
|
+
const clientPreferencesUpdate = useCallback(async (payload) => {
|
|
54
|
+
try {
|
|
55
|
+
return (await preferencesMutation({ variables: { input: payload } })).data?.clientPreferencesUpdate?.userErrors ?? [];
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error("[identity.clientPreferencesUpdate] clientPreferencesUpdate failed", error instanceof Error ? error.name : "UnknownError");
|
|
58
|
+
return [NETWORK_PREFERENCE_ERROR];
|
|
59
|
+
}
|
|
60
|
+
}, [preferencesMutation]);
|
|
61
|
+
const customerProfileUpdate = useCallback(async (payload) => {
|
|
62
|
+
try {
|
|
63
|
+
return (await customerProfileMutation({ variables: { input: payload } })).data?.customerProfileUpdate?.userErrors ?? [];
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error("[identity.customerProfileUpdate] customerProfileUpdate failed", error instanceof Error ? error.name : "UnknownError");
|
|
66
|
+
return [toCustomerProfileError(error)];
|
|
67
|
+
}
|
|
68
|
+
}, [customerProfileMutation]);
|
|
69
|
+
return useMemo(() => ({
|
|
70
|
+
clientProfileUpdate,
|
|
71
|
+
clientPreferencesUpdate,
|
|
72
|
+
customerProfileUpdate
|
|
73
|
+
}), [
|
|
74
|
+
clientProfileUpdate,
|
|
75
|
+
clientPreferencesUpdate,
|
|
76
|
+
customerProfileUpdate
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
defineActions({
|
|
80
|
+
namespace: "identity",
|
|
81
|
+
description: "Mutation-backed writes against the shopper identity entities (client profile, consent preferences, account profile).",
|
|
82
|
+
provider: {
|
|
83
|
+
name: "IdentityActionProvider",
|
|
84
|
+
importPath: "@vtex/faststore/internal/client"
|
|
85
|
+
},
|
|
86
|
+
methods: {
|
|
87
|
+
clientProfileUpdate: {
|
|
88
|
+
description: "Persist profile fields (partial) to the active cart (async strategy). Sending email flips Session.isIdentified.",
|
|
89
|
+
payload: [
|
|
90
|
+
{
|
|
91
|
+
name: "email",
|
|
92
|
+
type: "string",
|
|
93
|
+
optional: true
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "firstName",
|
|
97
|
+
type: "string",
|
|
98
|
+
optional: true
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "lastName",
|
|
102
|
+
type: "string",
|
|
103
|
+
optional: true
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: "phone",
|
|
107
|
+
type: "string",
|
|
108
|
+
optional: true
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "document",
|
|
112
|
+
type: "string",
|
|
113
|
+
optional: true
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
clientPreferencesUpdate: {
|
|
118
|
+
description: "Persist consent opt-in flags (partial) to the active cart (async strategy). Writes only the provided flag(s).",
|
|
119
|
+
payload: [{
|
|
120
|
+
name: "optinNewsLetter",
|
|
121
|
+
type: "boolean",
|
|
122
|
+
optional: true
|
|
123
|
+
}, {
|
|
124
|
+
name: "savePersonalData",
|
|
125
|
+
type: "boolean",
|
|
126
|
+
optional: true
|
|
127
|
+
}]
|
|
128
|
+
},
|
|
129
|
+
customerProfileUpdate: {
|
|
130
|
+
description: "Persist profile fields (partial) to the persistent account profile, not the cart (async strategy). Omitted fields are untouched; an empty string erases.",
|
|
131
|
+
payload: [
|
|
132
|
+
{
|
|
133
|
+
name: "firstName",
|
|
134
|
+
type: "string",
|
|
135
|
+
optional: true
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "lastName",
|
|
139
|
+
type: "string",
|
|
140
|
+
optional: true
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "homePhone",
|
|
144
|
+
type: "string",
|
|
145
|
+
optional: true
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: "mobilePhone",
|
|
149
|
+
type: "string",
|
|
150
|
+
optional: true
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "document",
|
|
154
|
+
type: "string",
|
|
155
|
+
optional: true
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "documentType",
|
|
159
|
+
type: "string",
|
|
160
|
+
optional: true
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "birthDate",
|
|
164
|
+
type: "string",
|
|
165
|
+
optional: true
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "gender",
|
|
169
|
+
type: "string",
|
|
170
|
+
optional: true
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
use: useIdentityActions
|
|
176
|
+
});
|
|
177
|
+
//#endregion
|
|
178
|
+
export { useIdentityActions };
|
|
179
|
+
|
|
180
|
+
//# sourceMappingURL=use-identity-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-identity-actions.js","names":[],"sources":["../../../src/sdk/identity/use-identity-actions.ts"],"sourcesContent":["'use client';\n\nimport { CombinedGraphQLErrors } from '@apollo/client/errors';\nimport { useMutation } from '@apollo/client/react';\nimport { defineActions } from '@vtex/fs-core';\nimport { useCallback, useMemo } from 'react';\nimport {\n CLIENT_PREFERENCES_UPDATE,\n CLIENT_PROFILE_UPDATE,\n type ClientPreferenceKey,\n type ClientProfileUserError,\n CUSTOMER_PROFILE_UPDATE,\n type CustomerProfileUpdateInput,\n type CustomerProfileUserError,\n} from './operations.js';\n\n/**\n * The `identity` action namespace — the context-free owner of the shopper-profile,\n * consent-preference, and persistent-profile writes\n * (specs/fspg-859-email-field.md, specs/consent-opt-in-component.md,\n * specs/sfs-3286-customer-profile-update-action.md,\n * docs/storefront-core/adr-0010-actions-own-the-write-side.md).\n *\n * It mirrors `useCartActions`: a component anywhere in the tree dispatches the write through the\n * compiler-injected `$actions.identity.*` prop, and the handler calls the corresponding mutation.\n * Every write is **async / pessimistic** (Decision 1): the caller awaits the persisted result. Each\n * call returns its `userErrors` (empty on success) so the caller can surface server-side failures\n * inline; the returned entity self-updates the normalized cache and every reactive subscriber.\n *\n * The first two writes target the cart's sibling identity entities; `customerProfileUpdate` targets\n * the shopper's account profile, which needs no cart at all.\n */\n\n/**\n * Payload for the profile write. Callers persist only the fields they own; other fields are\n * untouched. The payload is passed through to `ClientProfileUpdateInput` unmapped, so this type\n * mirrors that input verbatim — a stacked field only needs a field to already exist here to reach\n * the wire.\n */\nexport type ClientProfileUpdatePayload = Readonly<{\n email?: string;\n firstName?: string;\n lastName?: string;\n phone?: string;\n document?: string;\n}>;\n\n/** Payload for the preferences write — one opt-in flag; the other flag is left untouched. */\nexport type ClientPreferencesUpdatePayload = Readonly<Partial<Record<ClientPreferenceKey, boolean>>>;\n\n/**\n * Payload for the persistent-profile write. Mirrors `CustomerProfileUpdateInput` verbatim and is\n * forwarded unmapped, so an omitted field stays untouched upstream and an empty string erases.\n */\nexport type CustomerProfileUpdatePayload = CustomerProfileUpdateInput;\n\nexport type IdentityActions = Readonly<{\n /**\n * Persist the provided profile fields (partial) to the active cart's `clientProfileData`.\n * Async — awaits the mutation before resolving. Returns the resulting `userErrors` (empty on\n * success).\n */\n clientProfileUpdate: (payload: ClientProfileUpdatePayload) => Promise<readonly ClientProfileUserError[]>;\n /**\n * Persist the provided consent opt-in flag(s) (partial) to the shopper's `ClientPreferences`\n * entity (order-form-backed). Async — awaits the mutation before resolving. Writes ONLY the\n * requested field. Returns the resulting `userErrors` (empty on success).\n */\n clientPreferencesUpdate: (payload: ClientPreferencesUpdatePayload) => Promise<readonly ClientProfileUserError[]>;\n /**\n * Persist the provided profile fields (partial) to the shopper's persistent, cart-independent\n * account profile. Async — awaits the mutation before resolving. Sends exactly the fields it is\n * given: an omitted field is left untouched, an empty string erases. Returns the resulting\n * `userErrors` (empty on success).\n */\n customerProfileUpdate: (payload: CustomerProfileUpdatePayload) => Promise<readonly CustomerProfileUserError[]>;\n}>;\n\nconst NETWORK_PROFILE_ERROR: ClientProfileUserError = {\n code: 'NETWORK_ERROR',\n message: 'Unable to save your details. Please try again.',\n};\n\nconst NETWORK_PREFERENCE_ERROR: ClientProfileUserError = {\n code: 'NETWORK_ERROR',\n message: 'Unable to save your preference. Please try again.',\n};\n\nconst NETWORK_CUSTOMER_PROFILE_ERROR: CustomerProfileUserError = {\n code: 'NETWORK_ERROR',\n message: 'Unable to save your profile. Please try again.',\n};\n\nconst UNAUTHORIZED_CUSTOMER_PROFILE_ERROR: CustomerProfileUserError = {\n code: 'UNAUTHORIZED',\n message: 'Your session has expired. Please sign in again.',\n};\n\n/**\n * The profile module answers an anonymous or expired session with a top-level `UNAUTHORIZED`, never\n * a `userError`. Collapsing it into `NETWORK_ERROR` would offer a retry that cannot succeed, so it\n * gets its own code and the caller can send the shopper back to sign-in.\n */\nfunction toCustomerProfileError(error: unknown): CustomerProfileUserError {\n if (CombinedGraphQLErrors.is(error)) {\n const unauthorized = error.errors.some(({ extensions }) => extensions?.code === 'UNAUTHORIZED');\n if (unauthorized) return UNAUTHORIZED_CUSTOMER_PROFILE_ERROR;\n }\n return NETWORK_CUSTOMER_PROFILE_ERROR;\n}\n\n/**\n * The `identity` namespace hook. Registered with the first-party action registry via `identityActions`\n * below; the compiler-emitted `IdentityActionProvider` calls it and threads the narrowed methods into\n * each consumer's `$actions.identity`.\n */\nexport function useIdentityActions(): IdentityActions {\n const [profileMutation] = useMutation(CLIENT_PROFILE_UPDATE);\n const [preferencesMutation] = useMutation(CLIENT_PREFERENCES_UPDATE);\n const [customerProfileMutation] = useMutation(CUSTOMER_PROFILE_UPDATE);\n\n const clientProfileUpdate = useCallback<IdentityActions['clientProfileUpdate']>(\n async (payload) => {\n try {\n const result = await profileMutation({ variables: { input: payload } });\n return result.data?.clientProfileUpdate?.userErrors ?? [];\n } catch (error) {\n // Log only the error name — the message can echo the submitted email (PII).\n console.error(\n '[identity.clientProfileUpdate] clientProfileUpdate failed',\n error instanceof Error ? error.name : 'UnknownError',\n );\n return [NETWORK_PROFILE_ERROR];\n }\n },\n [profileMutation],\n );\n\n const clientPreferencesUpdate = useCallback<IdentityActions['clientPreferencesUpdate']>(\n async (payload) => {\n try {\n const result = await preferencesMutation({ variables: { input: payload } });\n return result.data?.clientPreferencesUpdate?.userErrors ?? [];\n } catch (error) {\n // Log only the error name — mirrors the profile write's PII-safe logging.\n console.error(\n '[identity.clientPreferencesUpdate] clientPreferencesUpdate failed',\n error instanceof Error ? error.name : 'UnknownError',\n );\n return [NETWORK_PREFERENCE_ERROR];\n }\n },\n [preferencesMutation],\n );\n\n const customerProfileUpdate = useCallback<IdentityActions['customerProfileUpdate']>(\n async (payload) => {\n try {\n // Forwarded unmapped: an empty string is an explicit erase and must survive to the wire.\n const result = await customerProfileMutation({ variables: { input: payload } });\n return result.data?.customerProfileUpdate?.userErrors ?? [];\n } catch (error) {\n // Log only the error name — the message can echo a submitted profile value (PII).\n console.error(\n '[identity.customerProfileUpdate] customerProfileUpdate failed',\n error instanceof Error ? error.name : 'UnknownError',\n );\n return [toCustomerProfileError(error)];\n }\n },\n [customerProfileMutation],\n );\n\n return useMemo(\n () => ({ clientProfileUpdate, clientPreferencesUpdate, customerProfileUpdate }),\n [clientProfileUpdate, clientPreferencesUpdate, customerProfileUpdate],\n );\n}\n\n/**\n * Declares the `identity` action namespace — the single source of truth for its method/payload\n * metadata, runtime provider, and `use` hook (mirrors `cartActions`). The native catalog builder\n * (`scripts/build-catalog.mjs`) statically reads this call to emit `actions.json`; at runtime\n * `IdentityActionProvider` calls `useIdentityActions` directly.\n */\nexport const identityActions = defineActions({\n namespace: 'identity',\n description:\n 'Mutation-backed writes against the shopper identity entities (client profile, consent preferences, account profile).',\n provider: { name: 'IdentityActionProvider', importPath: '@vtex/faststore/internal/client' },\n methods: {\n clientProfileUpdate: {\n description:\n 'Persist profile fields (partial) to the active cart (async strategy). Sending email flips Session.isIdentified.',\n payload: [\n { name: 'email', type: 'string', optional: true },\n { name: 'firstName', type: 'string', optional: true },\n { name: 'lastName', type: 'string', optional: true },\n { name: 'phone', type: 'string', optional: true },\n { name: 'document', type: 'string', optional: true },\n ],\n },\n clientPreferencesUpdate: {\n description:\n 'Persist consent opt-in flags (partial) to the active cart (async strategy). Writes only the provided flag(s).',\n payload: [\n { name: 'optinNewsLetter', type: 'boolean', optional: true },\n { name: 'savePersonalData', type: 'boolean', optional: true },\n ],\n },\n customerProfileUpdate: {\n description:\n 'Persist profile fields (partial) to the persistent account profile, not the cart (async strategy). Omitted fields are untouched; an empty string erases.',\n payload: [\n { name: 'firstName', type: 'string', optional: true },\n { name: 'lastName', type: 'string', optional: true },\n { name: 'homePhone', type: 'string', optional: true },\n { name: 'mobilePhone', type: 'string', optional: true },\n { name: 'document', type: 'string', optional: true },\n { name: 'documentType', type: 'string', optional: true },\n { name: 'birthDate', type: 'string', optional: true },\n { name: 'gender', type: 'string', optional: true },\n ],\n },\n },\n use: useIdentityActions,\n});\n"],"mappings":";;;;;;;;AA8EA,MAAM,wBAAgD;CACpD,MAAM;CACN,SAAS;AACX;AAEA,MAAM,2BAAmD;CACvD,MAAM;CACN,SAAS;AACX;AAEA,MAAM,iCAA2D;CAC/D,MAAM;CACN,SAAS;AACX;AAEA,MAAM,sCAAgE;CACpE,MAAM;CACN,SAAS;AACX;;;;;;AAOA,SAAS,uBAAuB,OAA0C;CACxE,IAAI,sBAAsB,GAAG,KAAK,GACX;MAAA,MAAM,OAAO,MAAM,EAAE,iBAAiB,YAAY,SAAS,cACjE,GAAG,OAAO;CAAA;CAE3B,OAAO;AACT;;;;;;AAOA,SAAgB,qBAAsC;CACpD,MAAM,CAAC,mBAAmB,YAAY,qBAAqB;CAC3D,MAAM,CAAC,uBAAuB,YAAY,yBAAyB;CACnE,MAAM,CAAC,2BAA2B,YAAY,uBAAuB;CAErE,MAAM,sBAAsB,YAC1B,OAAO,YAAY;EACjB,IAAI;GAEF,QAAO,MADc,gBAAgB,EAAE,WAAW,EAAE,OAAO,QAAQ,EAAE,CAAC,EAAA,CACxD,MAAM,qBAAqB,cAAc,CAAC;EAC1D,SAAS,OAAO;GAEd,QAAQ,MACN,6DACA,iBAAiB,QAAQ,MAAM,OAAO,cACxC;GACA,OAAO,CAAC,qBAAqB;EAC/B;CACF,GACA,CAAC,eAAe,CAClB;CAEA,MAAM,0BAA0B,YAC9B,OAAO,YAAY;EACjB,IAAI;GAEF,QAAO,MADc,oBAAoB,EAAE,WAAW,EAAE,OAAO,QAAQ,EAAE,CAAC,EAAA,CAC5D,MAAM,yBAAyB,cAAc,CAAC;EAC9D,SAAS,OAAO;GAEd,QAAQ,MACN,qEACA,iBAAiB,QAAQ,MAAM,OAAO,cACxC;GACA,OAAO,CAAC,wBAAwB;EAClC;CACF,GACA,CAAC,mBAAmB,CACtB;CAEA,MAAM,wBAAwB,YAC5B,OAAO,YAAY;EACjB,IAAI;GAGF,QAAO,MADc,wBAAwB,EAAE,WAAW,EAAE,OAAO,QAAQ,EAAE,CAAC,EAAA,CAChE,MAAM,uBAAuB,cAAc,CAAC;EAC5D,SAAS,OAAO;GAEd,QAAQ,MACN,iEACA,iBAAiB,QAAQ,MAAM,OAAO,cACxC;GACA,OAAO,CAAC,uBAAuB,KAAK,CAAC;EACvC;CACF,GACA,CAAC,uBAAuB,CAC1B;CAEA,OAAO,eACE;EAAE;EAAqB;EAAyB;CAAsB,IAC7E;EAAC;EAAqB;EAAyB;CAAqB,CACtE;AACF;AAQ+B,cAAc;CAC3C,WAAW;CACX,aACE;CACF,UAAU;EAAE,MAAM;EAA0B,YAAY;CAAkC;CAC1F,SAAS;EACP,qBAAqB;GACnB,aACE;GACF,SAAS;IACP;KAAE,MAAM;KAAS,MAAM;KAAU,UAAU;IAAK;IAChD;KAAE,MAAM;KAAa,MAAM;KAAU,UAAU;IAAK;IACpD;KAAE,MAAM;KAAY,MAAM;KAAU,UAAU;IAAK;IACnD;KAAE,MAAM;KAAS,MAAM;KAAU,UAAU;IAAK;IAChD;KAAE,MAAM;KAAY,MAAM;KAAU,UAAU;IAAK;GACrD;EACF;EACA,yBAAyB;GACvB,aACE;GACF,SAAS,CACP;IAAE,MAAM;IAAmB,MAAM;IAAW,UAAU;GAAK,GAC3D;IAAE,MAAM;IAAoB,MAAM;IAAW,UAAU;GAAK,CAC9D;EACF;EACA,uBAAuB;GACrB,aACE;GACF,SAAS;IACP;KAAE,MAAM;KAAa,MAAM;KAAU,UAAU;IAAK;IACpD;KAAE,MAAM;KAAY,MAAM;KAAU,UAAU;IAAK;IACnD;KAAE,MAAM;KAAa,MAAM;KAAU,UAAU;IAAK;IACpD;KAAE,MAAM;KAAe,MAAM;KAAU,UAAU;IAAK;IACtD;KAAE,MAAM;KAAY,MAAM;KAAU,UAAU;IAAK;IACnD;KAAE,MAAM;KAAgB,MAAM;KAAU,UAAU;IAAK;IACvD;KAAE,MAAM;KAAa,MAAM;KAAU,UAAU;IAAK;IACpD;KAAE,MAAM;KAAU,MAAM;KAAU,UAAU;IAAK;GACnD;EACF;CACF;CACA,KAAK;AACP,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StorefrontContext } from "../../core/dist/schema/generated/schema.js";
|
|
2
|
+
import "../../core/dist/index.js";
|
|
3
|
+
import { Messages } from "../i18n/locales.js";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
//#region src/sdk/provider/storefront-provider.d.ts
|
|
6
|
+
export type StorefrontProviderProps = Readonly<{
|
|
7
|
+
apiUrl: string;
|
|
8
|
+
/** The compiler-emitted context. Published to the tree and sent on every operation. */
|
|
9
|
+
context: StorefrontContext;
|
|
10
|
+
/**
|
|
11
|
+
* The record the generated root layout resolved for this binding. Omitted means no messages —
|
|
12
|
+
* legal, and only observable once a component renders one.
|
|
13
|
+
*/
|
|
14
|
+
messages?: Messages;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Wraps a React tree in the Apollo context, using the Next.js App Router
|
|
20
|
+
* integration so that `useQuery` / `useSuspenseQuery` results can be
|
|
21
|
+
* streamed from the server SSR pass into the browser cache.
|
|
22
|
+
*
|
|
23
|
+
* On the server a fresh `ApolloClient` is built per request. In the browser it is built once per
|
|
24
|
+
* **document**: `WrapApolloProvider` keeps it at `window[Symbol.for('ApolloClientSingleton')]` and
|
|
25
|
+
* assigns only when that slot is empty, so `makeClient` never runs a second time no matter how the
|
|
26
|
+
* provider re-renders. Everything the factory closes over — the cache and the context headers — is
|
|
27
|
+
* therefore frozen for the document's lifetime, which is why crossing bindings has to be a full
|
|
28
|
+
* document load and why the guard below exists.
|
|
29
|
+
*/
|
|
30
|
+
export declare function StorefrontProvider({ apiUrl, context, messages, headers, children }: StorefrontProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
//#endregion
|
|
32
|
+
//# sourceMappingURL=storefront-provider.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { StorefrontContextProvider } from "../context/storefront-context.js";
|
|
3
|
+
import { MessageProvider } from "../i18n/provider.js";
|
|
4
|
+
import { buildStorefrontContextHeaders } from "../context/headers.js";
|
|
5
|
+
import { getCacheConfig } from "../cache/storefront-cache.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { ApolloLink, HttpLink } from "@apollo/client";
|
|
8
|
+
import { SetContextLink } from "@apollo/client/link/context";
|
|
9
|
+
import { ApolloClient as ApolloClient$1, ApolloNextAppProvider, InMemoryCache as InMemoryCache$1 } from "@apollo/client-integration-nextjs";
|
|
10
|
+
//#region src/sdk/provider/storefront-provider.tsx
|
|
11
|
+
/** One frozen instance, so an omitted `messages` does not hand `IntlProvider` a new object per render. */
|
|
12
|
+
const NO_MESSAGES = Object.freeze({});
|
|
13
|
+
/** Where `WrapApolloProvider` memoizes the browser's one client, per document. */
|
|
14
|
+
const APOLLO_CLIENT_SINGLETON = Symbol.for("ApolloClientSingleton");
|
|
15
|
+
/** The binding a client was built for, stamped by `makeClient` so a later render can compare. */
|
|
16
|
+
const CLIENT_BINDING = Symbol.for("faststore.apolloClientBinding");
|
|
17
|
+
/**
|
|
18
|
+
* Fails when the live client was built for a different binding than the one now rendering.
|
|
19
|
+
*
|
|
20
|
+
* This cannot be fixed by rebuilding: the client is memoized per document, so the cache *and* the
|
|
21
|
+
* baked `x-faststore-*` headers belong to whichever binding loaded the document first. A client-side
|
|
22
|
+
* navigation across bindings would therefore render a correct-looking page filled with the previous
|
|
23
|
+
* binding's data — silent, and worse than a stale cache. Crossing bindings is a full document load;
|
|
24
|
+
* this is the tripwire for anything that tries otherwise.
|
|
25
|
+
*
|
|
26
|
+
* Throws in development so it cannot be missed, warns in production so a shopper is not shown an
|
|
27
|
+
* error page over it. A no-op on the server and before the first client is built.
|
|
28
|
+
*/
|
|
29
|
+
function assertClientMatchesBinding(bindingId) {
|
|
30
|
+
const win = globalThis.window;
|
|
31
|
+
if (!win) return;
|
|
32
|
+
const live = Reflect.get(win, APOLLO_CLIENT_SINGLETON);
|
|
33
|
+
if (!live) return;
|
|
34
|
+
const built = Reflect.get(live, CLIENT_BINDING) ?? null;
|
|
35
|
+
if (built === bindingId) return;
|
|
36
|
+
const message = `StorefrontProvider: the live Apollo client was built for binding ${JSON.stringify(built)} but this render is binding ${JSON.stringify(bindingId)}. The client is memoized per document, so its cache and its \`x-faststore-*\` headers still belong to the previous binding. Navigate between bindings with a full document load (a plain anchor, not \`<Link>\`).`;
|
|
37
|
+
if (process.env.NODE_ENV === "production") {
|
|
38
|
+
console.error(message);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(message);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Debug-only cart-context override. Injects `x-order-form-id` only when the page URL carries
|
|
45
|
+
* `?debug_ofid=<id>`. In normal flow the header is absent: the server resolves the cart from the
|
|
46
|
+
* HttpOnly cookie, which the browser attaches automatically on same-origin requests. No-op during
|
|
47
|
+
* SSR (no `window`).
|
|
48
|
+
*/
|
|
49
|
+
const cartContextLink = new SetContextLink((prevContext) => {
|
|
50
|
+
const win = globalThis.window;
|
|
51
|
+
if (!win) return prevContext;
|
|
52
|
+
const debugOfid = new URLSearchParams(win.location.search).get("debug_ofid");
|
|
53
|
+
if (!debugOfid) return prevContext;
|
|
54
|
+
return {
|
|
55
|
+
...prevContext,
|
|
56
|
+
headers: {
|
|
57
|
+
...prevContext.headers,
|
|
58
|
+
"x-order-form-id": debugOfid
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Wraps a React tree in the Apollo context, using the Next.js App Router
|
|
64
|
+
* integration so that `useQuery` / `useSuspenseQuery` results can be
|
|
65
|
+
* streamed from the server SSR pass into the browser cache.
|
|
66
|
+
*
|
|
67
|
+
* On the server a fresh `ApolloClient` is built per request. In the browser it is built once per
|
|
68
|
+
* **document**: `WrapApolloProvider` keeps it at `window[Symbol.for('ApolloClientSingleton')]` and
|
|
69
|
+
* assigns only when that slot is empty, so `makeClient` never runs a second time no matter how the
|
|
70
|
+
* provider re-renders. Everything the factory closes over — the cache and the context headers — is
|
|
71
|
+
* therefore frozen for the document's lifetime, which is why crossing bindings has to be a full
|
|
72
|
+
* document load and why the guard below exists.
|
|
73
|
+
*/
|
|
74
|
+
function StorefrontProvider({ apiUrl, context, messages, headers, children }) {
|
|
75
|
+
if (typeof apiUrl !== "string" || apiUrl.length === 0) throw new Error("StorefrontProvider: `apiUrl` is required. Set `NEXT_PUBLIC_STOREFRONT_API_URL` in your environment or pass `apiUrl` explicitly.");
|
|
76
|
+
const requestHeaders = {
|
|
77
|
+
...headers,
|
|
78
|
+
...buildStorefrontContextHeaders(context)
|
|
79
|
+
};
|
|
80
|
+
function makeClient() {
|
|
81
|
+
const client = new ApolloClient$1({
|
|
82
|
+
cache: new InMemoryCache$1(getCacheConfig()),
|
|
83
|
+
link: ApolloLink.from([cartContextLink, new HttpLink({
|
|
84
|
+
uri: apiUrl,
|
|
85
|
+
...requestHeaders ? { headers: requestHeaders } : {}
|
|
86
|
+
})]),
|
|
87
|
+
defaultOptions: {
|
|
88
|
+
watchQuery: { errorPolicy: "all" },
|
|
89
|
+
query: { errorPolicy: "all" }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
Reflect.set(client, CLIENT_BINDING, context.bindingId);
|
|
93
|
+
return client;
|
|
94
|
+
}
|
|
95
|
+
assertClientMatchesBinding(context.bindingId);
|
|
96
|
+
return /* @__PURE__ */ jsx(StorefrontContextProvider, {
|
|
97
|
+
context,
|
|
98
|
+
children: /* @__PURE__ */ jsx(MessageProvider, {
|
|
99
|
+
locale: context.locale,
|
|
100
|
+
messages: messages ?? NO_MESSAGES,
|
|
101
|
+
children: /* @__PURE__ */ jsx(ApolloNextAppProvider, {
|
|
102
|
+
makeClient,
|
|
103
|
+
children
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { APOLLO_CLIENT_SINGLETON, StorefrontProvider };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=storefront-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storefront-provider.js","names":["ApolloClient","InMemoryCache"],"sources":["../../../src/sdk/provider/storefront-provider.tsx"],"sourcesContent":["'use client';\n\nimport { ApolloLink, HttpLink } from '@apollo/client';\nimport { SetContextLink } from '@apollo/client/link/context';\nimport { ApolloClient, ApolloNextAppProvider, InMemoryCache } from '@apollo/client-integration-nextjs';\nimport type { StorefrontContext } from '@vtex/fs-core';\nimport type { ReactNode } from 'react';\nimport { getCacheConfig } from '../cache/storefront-cache.js';\nimport { buildStorefrontContextHeaders } from '../context/headers.js';\nimport { StorefrontContextProvider } from '../context/storefront-context.js';\nimport type { Messages } from '../i18n/locales.js';\nimport { MessageProvider } from '../i18n/provider.js';\n\nexport type StorefrontProviderProps = Readonly<{\n apiUrl: string;\n /** The compiler-emitted context. Published to the tree and sent on every operation. */\n context: StorefrontContext;\n /**\n * The record the generated root layout resolved for this binding. Omitted means no messages —\n * legal, and only observable once a component renders one.\n */\n messages?: Messages;\n headers?: Record<string, string>;\n children: ReactNode;\n}>;\n\n/** One frozen instance, so an omitted `messages` does not hand `IntlProvider` a new object per render. */\nconst NO_MESSAGES: Messages = Object.freeze({});\n\n/** Where `WrapApolloProvider` memoizes the browser's one client, per document. */\nexport const APOLLO_CLIENT_SINGLETON = Symbol.for('ApolloClientSingleton');\n\n/** The binding a client was built for, stamped by `makeClient` so a later render can compare. */\nconst CLIENT_BINDING = Symbol.for('faststore.apolloClientBinding');\n\n/**\n * Fails when the live client was built for a different binding than the one now rendering.\n *\n * This cannot be fixed by rebuilding: the client is memoized per document, so the cache *and* the\n * baked `x-faststore-*` headers belong to whichever binding loaded the document first. A client-side\n * navigation across bindings would therefore render a correct-looking page filled with the previous\n * binding's data — silent, and worse than a stale cache. Crossing bindings is a full document load;\n * this is the tripwire for anything that tries otherwise.\n *\n * Throws in development so it cannot be missed, warns in production so a shopper is not shown an\n * error page over it. A no-op on the server and before the first client is built.\n */\nfunction assertClientMatchesBinding(bindingId: string | null): void {\n const win: Window | undefined = globalThis.window;\n if (!win) return;\n const live = Reflect.get(win, APOLLO_CLIENT_SINGLETON);\n if (!live) return;\n const built = (Reflect.get(live as object, CLIENT_BINDING) ?? null) as string | null;\n if (built === bindingId) return;\n\n const message =\n `StorefrontProvider: the live Apollo client was built for binding ${JSON.stringify(built)} but ` +\n `this render is binding ${JSON.stringify(bindingId)}. The client is memoized per document, so ` +\n 'its cache and its `x-faststore-*` headers still belong to the previous binding. Navigate ' +\n 'between bindings with a full document load (a plain anchor, not `<Link>`).';\n if (process.env.NODE_ENV === 'production') {\n console.error(message);\n return;\n }\n throw new Error(message);\n}\n\n/**\n * Debug-only cart-context override. Injects `x-order-form-id` only when the page URL carries\n * `?debug_ofid=<id>`. In normal flow the header is absent: the server resolves the cart from the\n * HttpOnly cookie, which the browser attaches automatically on same-origin requests. No-op during\n * SSR (no `window`).\n */\nconst cartContextLink = new SetContextLink((prevContext) => {\n // Typed as optional: the DOM lib declares `window` non-nullable, but it is absent during SSR.\n const win: Window | undefined = globalThis.window;\n if (!win) return prevContext;\n const debugOfid = new URLSearchParams(win.location.search).get('debug_ofid');\n if (!debugOfid) return prevContext;\n return {\n ...prevContext,\n headers: { ...prevContext.headers, 'x-order-form-id': debugOfid },\n };\n});\n\n/**\n * Wraps a React tree in the Apollo context, using the Next.js App Router\n * integration so that `useQuery` / `useSuspenseQuery` results can be\n * streamed from the server SSR pass into the browser cache.\n *\n * On the server a fresh `ApolloClient` is built per request. In the browser it is built once per\n * **document**: `WrapApolloProvider` keeps it at `window[Symbol.for('ApolloClientSingleton')]` and\n * assigns only when that slot is empty, so `makeClient` never runs a second time no matter how the\n * provider re-renders. Everything the factory closes over — the cache and the context headers — is\n * therefore frozen for the document's lifetime, which is why crossing bindings has to be a full\n * document load and why the guard below exists.\n */\nexport function StorefrontProvider({ apiUrl, context, messages, headers, children }: StorefrontProviderProps) {\n if (typeof apiUrl !== 'string' || apiUrl.length === 0) {\n throw new Error(\n 'StorefrontProvider: `apiUrl` is required. Set ' +\n '`NEXT_PUBLIC_STOREFRONT_API_URL` in your environment or pass ' +\n '`apiUrl` explicitly.',\n );\n }\n\n // Context headers merge last, so a caller cannot send a locale, binding or sales channel that\n // disagrees with the context the app rendered. Requesting a different one is what `context` is for.\n const requestHeaders = { ...headers, ...buildStorefrontContextHeaders(context) };\n\n function makeClient() {\n const client = new ApolloClient({\n cache: new InMemoryCache(getCacheConfig()),\n link: ApolloLink.from([\n cartContextLink,\n new HttpLink({\n uri: apiUrl,\n ...(requestHeaders ? { headers: requestHeaders } : {}),\n }),\n ]),\n // `cart` is non-null (`Cart!`), so an upstream cart failure nulls the whole operation's\n // `data`. 'all' delivers `{ data, error }` instead of throwing, letting the cart subtree\n // degrade in place.\n defaultOptions: {\n watchQuery: { errorPolicy: 'all' },\n query: { errorPolicy: 'all' },\n },\n });\n // Stamp which binding this client's cache and headers belong to, so a later render can tell.\n Reflect.set(client, CLIENT_BINDING, context.bindingId);\n return client;\n }\n\n assertClientMatchesBinding(context.bindingId);\n\n return (\n <StorefrontContextProvider context={context}>\n <MessageProvider locale={context.locale} messages={messages ?? NO_MESSAGES}>\n <ApolloNextAppProvider makeClient={makeClient}>{children}</ApolloNextAppProvider>\n </MessageProvider>\n </StorefrontContextProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;AA2BA,MAAM,cAAwB,OAAO,OAAO,CAAC,CAAC;;AAG9C,MAAa,0BAA0B,OAAO,IAAI,uBAAuB;;AAGzE,MAAM,iBAAiB,OAAO,IAAI,+BAA+B;;;;;;;;;;;;;AAcjE,SAAS,2BAA2B,WAAgC;CAClE,MAAM,MAA0B,WAAW;CAC3C,IAAI,CAAC,KAAK;CACV,MAAM,OAAO,QAAQ,IAAI,KAAK,uBAAuB;CACrD,IAAI,CAAC,MAAM;CACX,MAAM,QAAS,QAAQ,IAAI,MAAgB,cAAc,KAAK;CAC9D,IAAI,UAAU,WAAW;CAEzB,MAAM,UACJ,oEAAoE,KAAK,UAAU,KAAK,EAAE,8BAChE,KAAK,UAAU,SAAS,EAAE;CAGtD,IAAI,QAAQ,IAAI,aAAa,cAAc;EACzC,QAAQ,MAAM,OAAO;EACrB;CACF;CACA,MAAM,IAAI,MAAM,OAAO;AACzB;;;;;;;AAQA,MAAM,kBAAkB,IAAI,gBAAgB,gBAAgB;CAE1D,MAAM,MAA0B,WAAW;CAC3C,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM,YAAY,IAAI,gBAAgB,IAAI,SAAS,MAAM,CAAC,CAAC,IAAI,YAAY;CAC3E,IAAI,CAAC,WAAW,OAAO;CACvB,OAAO;EACL,GAAG;EACH,SAAS;GAAE,GAAG,YAAY;GAAS,mBAAmB;EAAU;CAClE;AACF,CAAC;;;;;;;;;;;;;AAcD,SAAgB,mBAAmB,EAAE,QAAQ,SAAS,UAAU,SAAS,YAAqC;CAC5G,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,GAClD,MAAM,IAAI,MACR,iIAGF;CAKF,MAAM,iBAAiB;EAAE,GAAG;EAAS,GAAG,8BAA8B,OAAO;CAAE;CAE/E,SAAS,aAAa;EACpB,MAAM,SAAS,IAAIA,eAAa;GAC9B,OAAO,IAAIC,gBAAc,eAAe,CAAC;GACzC,MAAM,WAAW,KAAK,CACpB,iBACA,IAAI,SAAS;IACX,KAAK;IACL,GAAI,iBAAiB,EAAE,SAAS,eAAe,IAAI,CAAC;GACtD,CAAC,CACH,CAAC;GAID,gBAAgB;IACd,YAAY,EAAE,aAAa,MAAM;IACjC,OAAO,EAAE,aAAa,MAAM;GAC9B;EACF,CAAC;EAED,QAAQ,IAAI,QAAQ,gBAAgB,QAAQ,SAAS;EACrD,OAAO;CACT;CAEA,2BAA2B,QAAQ,SAAS;CAE5C,OACE,oBAAC,2BAAD;EAAoC;EAClC,UAAA,oBAAC,iBAAD;GAAiB,QAAQ,QAAQ;GAAQ,UAAU,YAAY;GAC7D,UAAA,oBAAC,uBAAD;IAAmC;IAAa;GAAgC,CAAA;EACjE,CAAA;CACQ,CAAA;AAE/B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RegionFragmentFragment } from "../generated/graphql.js";
|
|
2
|
+
import { TypedDocumentNode } from "@apollo/client";
|
|
3
|
+
//#region src/sdk/region/operations.d.ts
|
|
4
|
+
export type RegionEntity = RegionFragmentFragment;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import "./operations.js";
|
|
2
|
+
import { TypedDocumentNode } from "@apollo/client";
|
|
3
|
+
//#region src/sdk/region/region-operations.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The region write document.
|
|
6
|
+
*
|
|
7
|
+
* Authored with the hand `gql` tag and excluded from the codegen `documents` glob (see
|
|
8
|
+
* `codegen.ts`), mirroring `sdk/session/auth-operations.ts`: the codegen `graphql()` factory is
|
|
9
|
+
* reserved for the reactive read path, and plucking this file would emit a duplicate
|
|
10
|
+
* `RegionUpdate` document alongside the hand-written one.
|
|
11
|
+
*
|
|
12
|
+
* The payload selects the full `Region` field set — `__typename` and `id` included — so the response
|
|
13
|
+
* merges into the normalized cache and every `RegionFragment` subscriber re-renders with no refetch.
|
|
14
|
+
* The merge carries the field values; only the nullable `Query.region` root field needs pointing at
|
|
15
|
+
* the entity, which the action's `update` does on the session's first write.
|
|
16
|
+
*
|
|
17
|
+
* Failures follow the repo's two-path contract: a rejected postal code arrives as payload `errors`,
|
|
18
|
+
* while transport and top-level GraphQL failures are infrastructure, mapped by the action handler to
|
|
19
|
+
* the one client-synthesized `NETWORK_ERROR`.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* A typed rejection of a region write. `code` is the server's `RegionErrorCode` (`INVALID_POSTAL_CODE`,
|
|
23
|
+
* `UNSERVED_POSTAL_CODE`) or the client-minted `NETWORK_ERROR`; `RegionError` keys its copy on it.
|
|
24
|
+
*/
|
|
25
|
+
export type RegionUserError = Readonly<{
|
|
26
|
+
code?: string;
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
29
|
+
//#endregion
|
|
30
|
+
//# sourceMappingURL=region-operations.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { gql } from "../graphql-tag.js";
|
|
2
|
+
//#region src/sdk/region/region-operations.ts
|
|
3
|
+
const REGION_UPDATE = gql`
|
|
4
|
+
mutation RegionUpdate($postalCode: String!) {
|
|
5
|
+
regionUpdate(postalCode: $postalCode) {
|
|
6
|
+
__typename
|
|
7
|
+
region {
|
|
8
|
+
__typename
|
|
9
|
+
id
|
|
10
|
+
postalCode
|
|
11
|
+
city
|
|
12
|
+
}
|
|
13
|
+
errors {
|
|
14
|
+
code
|
|
15
|
+
message
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { REGION_UPDATE };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=region-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"region-operations.js","names":[],"sources":["../../../src/sdk/region/region-operations.ts"],"sourcesContent":["import type { TypedDocumentNode } from '@apollo/client';\nimport { gql } from '../graphql-tag.js';\nimport type { RegionEntity } from './operations.js';\n\n/**\n * The region write document.\n *\n * Authored with the hand `gql` tag and excluded from the codegen `documents` glob (see\n * `codegen.ts`), mirroring `sdk/session/auth-operations.ts`: the codegen `graphql()` factory is\n * reserved for the reactive read path, and plucking this file would emit a duplicate\n * `RegionUpdate` document alongside the hand-written one.\n *\n * The payload selects the full `Region` field set — `__typename` and `id` included — so the response\n * merges into the normalized cache and every `RegionFragment` subscriber re-renders with no refetch.\n * The merge carries the field values; only the nullable `Query.region` root field needs pointing at\n * the entity, which the action's `update` does on the session's first write.\n *\n * Failures follow the repo's two-path contract: a rejected postal code arrives as payload `errors`,\n * while transport and top-level GraphQL failures are infrastructure, mapped by the action handler to\n * the one client-synthesized `NETWORK_ERROR`.\n */\n\n/**\n * A typed rejection of a region write. `code` is the server's `RegionErrorCode` (`INVALID_POSTAL_CODE`,\n * `UNSERVED_POSTAL_CODE`) or the client-minted `NETWORK_ERROR`; `RegionError` keys its copy on it.\n */\nexport type RegionUserError = Readonly<{ code?: string; message: string }>;\n\nexport type RegionUpdatePayloadEntity = Readonly<{\n __typename: 'RegionUpdatePayload';\n region: RegionEntity | null;\n errors: readonly RegionUserError[];\n}>;\n\ntype RegionUpdateData = Readonly<{ regionUpdate: RegionUpdatePayloadEntity }>;\n\nexport const REGION_UPDATE: TypedDocumentNode<RegionUpdateData, { postalCode: string }> = gql`\n mutation RegionUpdate($postalCode: String!) {\n regionUpdate(postalCode: $postalCode) {\n __typename\n region {\n __typename\n id\n postalCode\n city\n }\n errors {\n code\n message\n }\n }\n }\n`;\n"],"mappings":";;AAoCA,MAAa,gBAA6E,GAAG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "../../core/dist/index.js";
|
|
2
|
+
import { RegionUserError } from "./region-operations.js";
|
|
3
|
+
//#region src/sdk/region/use-region-actions.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The `region` action namespace — the one sanctioned client write surface for the shopper's active
|
|
6
|
+
* region (docs/storefront-core/adr-0010-actions-own-the-write-side.md).
|
|
7
|
+
*
|
|
8
|
+
* The single action is async/pessimistic: the handler awaits the mutation and only the
|
|
9
|
+
* server-confirmed payload changes the cache. A region cannot be guessed client-side, because the
|
|
10
|
+
* server owns both the postal-code format and the city it resolves to. The handler is stateless — no
|
|
11
|
+
* reactive vars, no module state — since the active value lives in the normalized cache and its
|
|
12
|
+
* persistence is the server's business.
|
|
13
|
+
*
|
|
14
|
+
* `setPostalCode` resolves the payload `errors` (empty on success) and never throws for an expected
|
|
15
|
+
* outcome; infrastructure failures resolve as the synthetic `NETWORK_ERROR`, matching `session` and
|
|
16
|
+
* `identity`.
|
|
17
|
+
*/
|
|
18
|
+
export type RegionActions = Readonly<{
|
|
19
|
+
/** Submits a postal code as the shopper typed it (masked). Resolves to [] on success. Never throws. */
|
|
20
|
+
setPostalCode: (postalCode: string) => Promise<readonly RegionUserError[]>;
|
|
21
|
+
}>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//# sourceMappingURL=use-region-actions.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { defineActions } from "../../core/dist/actions/registry.js";
|
|
3
|
+
import "../../core/dist/index.js";
|
|
4
|
+
import { REGION_UPDATE } from "./region-operations.js";
|
|
5
|
+
import { useMutation } from "@apollo/client/react";
|
|
6
|
+
import { useCallback, useMemo } from "react";
|
|
7
|
+
//#region src/sdk/region/use-region-actions.ts
|
|
8
|
+
const NETWORK_USER_ERROR = {
|
|
9
|
+
code: "NETWORK_ERROR",
|
|
10
|
+
message: "Unable to set your region. Please try again."
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The `region` namespace hook. Registered with the first-party action registry via `regionActions`
|
|
14
|
+
* below; the compiler-emitted `RegionActionProvider` calls it and threads the narrowed method into
|
|
15
|
+
* each consumer's `$actions.region`.
|
|
16
|
+
*
|
|
17
|
+
* A successful write merges the payload into the normalized cache — it selects the full `Region`
|
|
18
|
+
* field set including `id`, so Apollo identifies the entity and every `RegionFragment` subscriber
|
|
19
|
+
* re-renders with no refetch. The merge alone is not enough on the *first* write of a session,
|
|
20
|
+
* though: `Query.region` is nullable, so a shopper who arrives with no region has `null` stored at
|
|
21
|
+
* that root field, and merging an entity never repoints a root field that holds null. The reactive
|
|
22
|
+
* read resolves the entity *through* `Query.region`, so it would keep reading null until a reload.
|
|
23
|
+
* Hence the `update` below, which points the root field at the entity. It is idempotent, so writes
|
|
24
|
+
* after the first cost nothing.
|
|
25
|
+
*
|
|
26
|
+
* The masked value is passed through untouched: the server strips the mask and echoes back a
|
|
27
|
+
* formatted `postalCode`, which keeps one authority on format instead of two that can diverge.
|
|
28
|
+
*/
|
|
29
|
+
function useRegionActions() {
|
|
30
|
+
const [updateMutation] = useMutation(REGION_UPDATE, { update(cache, { data }) {
|
|
31
|
+
const region = data?.regionUpdate.region;
|
|
32
|
+
if (!region) return;
|
|
33
|
+
const id = cache.identify(region);
|
|
34
|
+
if (!id) return;
|
|
35
|
+
cache.modify({ fields: { region: (_existing, { toReference }) => toReference(id) } });
|
|
36
|
+
} });
|
|
37
|
+
const setPostalCode = useCallback(async (postalCode) => {
|
|
38
|
+
try {
|
|
39
|
+
return (await updateMutation({ variables: { postalCode } })).data?.regionUpdate.errors ?? [];
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("[region.setPostalCode] regionUpdate failed", error);
|
|
42
|
+
return [NETWORK_USER_ERROR];
|
|
43
|
+
}
|
|
44
|
+
}, [updateMutation]);
|
|
45
|
+
return useMemo(() => ({ setPostalCode }), [setPostalCode]);
|
|
46
|
+
}
|
|
47
|
+
defineActions({
|
|
48
|
+
namespace: "region",
|
|
49
|
+
description: "Mutation-backed writes against the shopper's active region (postal code).",
|
|
50
|
+
provider: {
|
|
51
|
+
name: "RegionActionProvider",
|
|
52
|
+
importPath: "@vtex/faststore/internal/client"
|
|
53
|
+
},
|
|
54
|
+
methods: { setPostalCode: {
|
|
55
|
+
description: "Set the active region from a postal code, masked or bare (async/pessimistic). Resolves the payload errors.",
|
|
56
|
+
payload: [{
|
|
57
|
+
name: "postalCode",
|
|
58
|
+
type: "string"
|
|
59
|
+
}]
|
|
60
|
+
} },
|
|
61
|
+
use: useRegionActions
|
|
62
|
+
});
|
|
63
|
+
//#endregion
|
|
64
|
+
export { useRegionActions };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=use-region-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-region-actions.js","names":[],"sources":["../../../src/sdk/region/use-region-actions.ts"],"sourcesContent":["'use client';\n\nimport { useMutation } from '@apollo/client/react';\nimport { defineActions } from '@vtex/fs-core';\nimport { useCallback, useMemo } from 'react';\nimport { REGION_UPDATE, type RegionUserError } from './region-operations.js';\n\nexport type { RegionUserError } from './region-operations.js';\n\n/**\n * The `region` action namespace — the one sanctioned client write surface for the shopper's active\n * region (docs/storefront-core/adr-0010-actions-own-the-write-side.md).\n *\n * The single action is async/pessimistic: the handler awaits the mutation and only the\n * server-confirmed payload changes the cache. A region cannot be guessed client-side, because the\n * server owns both the postal-code format and the city it resolves to. The handler is stateless — no\n * reactive vars, no module state — since the active value lives in the normalized cache and its\n * persistence is the server's business.\n *\n * `setPostalCode` resolves the payload `errors` (empty on success) and never throws for an expected\n * outcome; infrastructure failures resolve as the synthetic `NETWORK_ERROR`, matching `session` and\n * `identity`.\n */\nexport type RegionActions = Readonly<{\n /** Submits a postal code as the shopper typed it (masked). Resolves to [] on success. Never throws. */\n setPostalCode: (postalCode: string) => Promise<readonly RegionUserError[]>;\n}>;\n\nconst NETWORK_USER_ERROR: RegionUserError = {\n code: 'NETWORK_ERROR',\n message: 'Unable to set your region. Please try again.',\n};\n\n/**\n * The `region` namespace hook. Registered with the first-party action registry via `regionActions`\n * below; the compiler-emitted `RegionActionProvider` calls it and threads the narrowed method into\n * each consumer's `$actions.region`.\n *\n * A successful write merges the payload into the normalized cache — it selects the full `Region`\n * field set including `id`, so Apollo identifies the entity and every `RegionFragment` subscriber\n * re-renders with no refetch. The merge alone is not enough on the *first* write of a session,\n * though: `Query.region` is nullable, so a shopper who arrives with no region has `null` stored at\n * that root field, and merging an entity never repoints a root field that holds null. The reactive\n * read resolves the entity *through* `Query.region`, so it would keep reading null until a reload.\n * Hence the `update` below, which points the root field at the entity. It is idempotent, so writes\n * after the first cost nothing.\n *\n * The masked value is passed through untouched: the server strips the mask and echoes back a\n * formatted `postalCode`, which keeps one authority on format instead of two that can diverge.\n */\nexport function useRegionActions(): RegionActions {\n const [updateMutation] = useMutation(REGION_UPDATE, {\n update(cache, { data }) {\n const region = data?.regionUpdate.region;\n if (!region) return;\n const id = cache.identify(region);\n if (!id) return;\n cache.modify({\n fields: {\n region: (_existing, { toReference }) => toReference(id),\n },\n });\n },\n });\n\n const setPostalCode = useCallback<RegionActions['setPostalCode']>(\n async (postalCode) => {\n try {\n const result = await updateMutation({ variables: { postalCode } });\n return result.data?.regionUpdate.errors ?? [];\n } catch (error) {\n console.error('[region.setPostalCode] regionUpdate failed', error);\n return [NETWORK_USER_ERROR];\n }\n },\n [updateMutation],\n );\n\n return useMemo(() => ({ setPostalCode }), [setPostalCode]);\n}\n\n/**\n * Declares the `region` action namespace — the single source of truth for its method/payload\n * metadata, runtime provider, and `use` hook (mirrors `sessionActions`). The native catalog builder\n * (`scripts/build-catalog.mjs`) statically reads this call to emit `actions.json`; at runtime\n * `RegionActionProvider` calls `useRegionActions` directly.\n */\nexport const regionActions = defineActions({\n namespace: 'region',\n description: \"Mutation-backed writes against the shopper's active region (postal code).\",\n provider: { name: 'RegionActionProvider', importPath: '@vtex/faststore/internal/client' },\n methods: {\n setPostalCode: {\n description:\n 'Set the active region from a postal code, masked or bare (async/pessimistic). Resolves the payload errors.',\n payload: [{ name: 'postalCode', type: 'string' }],\n },\n },\n use: useRegionActions,\n});\n"],"mappings":";;;;;;;AA4BA,MAAM,qBAAsC;CAC1C,MAAM;CACN,SAAS;AACX;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,mBAAkC;CAChD,MAAM,CAAC,kBAAkB,YAAY,eAAe,EAClD,OAAO,OAAO,EAAE,QAAQ;EACtB,MAAM,SAAS,MAAM,aAAa;EAClC,IAAI,CAAC,QAAQ;EACb,MAAM,KAAK,MAAM,SAAS,MAAM;EAChC,IAAI,CAAC,IAAI;EACT,MAAM,OAAO,EACX,QAAQ,EACN,SAAS,WAAW,EAAE,kBAAkB,YAAY,EAAE,EACxD,EACF,CAAC;CACH,EACF,CAAC;CAED,MAAM,gBAAgB,YACpB,OAAO,eAAe;EACpB,IAAI;GAEF,QAAO,MADc,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,EAAA,CACnD,MAAM,aAAa,UAAU,CAAC;EAC9C,SAAS,OAAO;GACd,QAAQ,MAAM,8CAA8C,KAAK;GACjE,OAAO,CAAC,kBAAkB;EAC5B;CACF,GACA,CAAC,cAAc,CACjB;CAEA,OAAO,eAAe,EAAE,cAAc,IAAI,CAAC,aAAa,CAAC;AAC3D;AAQ6B,cAAc;CACzC,WAAW;CACX,aAAa;CACb,UAAU;EAAE,MAAM;EAAwB,YAAY;CAAkC;CACxF,SAAS,EACP,eAAe;EACb,aACE;EACF,SAAS,CAAC;GAAE,MAAM;GAAc,MAAM;EAAS,CAAC;CAClD,EACF;CACA,KAAK;AACP,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/sdk/seller.ts
|
|
2
|
+
/** Resolves the seller a matter should read for a variant: the one flagged `isDefault`, or the first
|
|
3
|
+
* seller as a fallback when none is marked default. Shared by BuyButton and Pricing so the
|
|
4
|
+
* default-seller rule lives in one place instead of being duplicated per transform. */
|
|
5
|
+
function resolveDefaultSeller(sellers) {
|
|
6
|
+
return sellers.find((seller) => seller.isDefault) ?? sellers[0];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { resolveDefaultSeller };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=seller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seller.js","names":[],"sources":["../../src/sdk/seller.ts"],"sourcesContent":["/** Resolves the seller a matter should read for a variant: the one flagged `isDefault`, or the first\n * seller as a fallback when none is marked default. Shared by BuyButton and Pricing so the\n * default-seller rule lives in one place instead of being duplicated per transform. */\nexport function resolveDefaultSeller<T extends { isDefault: boolean }>(sellers: readonly T[]): T | undefined {\n return sellers.find((seller) => seller.isDefault) ?? sellers[0];\n}\n"],"mappings":";;;;AAGA,SAAgB,qBAAuD,SAAsC;CAC3G,OAAO,QAAQ,MAAM,WAAW,OAAO,SAAS,KAAK,QAAQ;AAC/D"}
|