@vtex/faststore 0.0.10 → 0.0.11
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 +42 -0
- package/README.md +0 -1
- package/dist/actions.json +6 -1
- package/dist/catalog.json +789 -1701
- package/dist/cli/index.d.ts +66 -28
- package/dist/cli/index.js +7371 -512
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/server-runtime.js +41 -60
- package/dist/cli/server-runtime.js.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -2
- package/dist/components.d.ts +63 -57
- package/dist/components.js +60 -54
- package/dist/content-types.json +5785 -754
- package/dist/core/dist/define-component.d.ts +1 -1
- package/dist/core/dist/define-content-type.d.ts +50 -2
- package/dist/core/dist/define-content-type.js +107 -3
- package/dist/core/dist/define-content-type.js.map +1 -1
- package/dist/core/dist/index.d.ts +2 -2
- package/dist/docs/access-code-field.md +1 -1
- package/dist/docs/access-code-sign-in.md +126 -77
- package/dist/docs/account-address-book.md +210 -95
- package/dist/docs/account-menu.md +14 -15
- package/dist/docs/account-saved-cards.md +44 -39
- package/dist/docs/alert-dialog.md +3 -1
- package/dist/docs/avatar.md +4 -2
- package/dist/docs/billing-address.md +99 -30
- package/dist/docs/binding-switcher.md +5 -2
- package/dist/docs/buy-button.md +7 -8
- package/dist/docs/card-entry.md +39 -26
- package/dist/docs/card-summary.md +18 -8
- package/dist/docs/cardholder-document.md +5 -3
- package/dist/docs/carousel.md +5 -4
- package/dist/docs/cart-destination.md +39 -26
- package/dist/docs/cart-item.md +29 -14
- package/dist/docs/cart-totalizer.md +7 -5
- package/dist/docs/cart.md +135 -41
- package/dist/docs/challenge-return.md +135 -0
- package/dist/docs/client-preferences-fieldset.md +10 -5
- package/dist/docs/client-preferences.md +31 -8
- package/dist/docs/client-profile-fieldset.md +20 -6
- package/dist/docs/client-profile.md +12 -3
- package/dist/docs/copy-text.md +9 -7
- package/dist/docs/document-field.md +1 -1
- package/dist/docs/email-field.md +2 -1
- package/dist/docs/email-identification.md +12 -2
- package/dist/docs/footer-copyright.md +4 -2
- package/dist/docs/form.md +54 -18
- package/dist/docs/free-shipping-progress.md +6 -5
- package/dist/docs/identity-edit.md +8 -2
- package/dist/docs/identity-summary.md +18 -5
- package/dist/docs/installments.md +46 -32
- package/dist/docs/my-account-profile.md +16 -11
- package/dist/docs/navigation-link.md +5 -3
- package/dist/docs/order-cancel.md +3 -1
- package/dist/docs/order-delivery-address.md +7 -5
- package/dist/docs/order-delivery-group.md +1 -3
- package/dist/docs/order-details-back.md +1 -1
- package/dist/docs/order-details-header.md +1 -4
- package/dist/docs/order-invoice-download.md +60 -0
- package/dist/docs/order-list-row.md +1 -1
- package/dist/docs/order-list-search.md +13 -20
- package/dist/docs/order-list-views.md +11 -17
- package/dist/docs/order-list.md +12 -5
- package/dist/docs/order-payment.md +9 -7
- package/dist/docs/order-placed-date.md +1 -1
- package/dist/docs/order-placed-payment-summary.md +28 -15
- package/dist/docs/order-placed.md +49 -14
- package/dist/docs/order-progress.md +1 -1
- package/dist/docs/order-status-badge.md +20 -9
- package/dist/docs/order-summary.md +2 -2
- package/dist/docs/order-tracking-link.md +58 -0
- package/dist/docs/payment-method-badges.md +30 -4
- package/dist/docs/payment-methods.md +1 -1
- package/dist/docs/payment.md +36 -17
- package/dist/docs/phone-field.md +4 -4
- package/dist/docs/place-order.md +84 -36
- package/dist/docs/postal-code-field.md +3 -1
- package/dist/docs/pricing.md +21 -23
- package/dist/docs/product-gallery.md +19 -20
- package/dist/docs/product-information.md +13 -9
- package/dist/docs/product-list.md +7 -6
- package/dist/docs/product-shelf.md +0 -1
- package/dist/docs/promotion.md +4 -2
- package/dist/docs/region.md +23 -15
- package/dist/docs/save-card.md +7 -6
- package/dist/docs/saved-cards.md +65 -36
- package/dist/docs/shipping-address.md +57 -21
- package/dist/docs/shipping-simulator.md +53 -15
- package/dist/docs/sign-in-disclosure.md +176 -0
- package/dist/docs/sign-in-form.md +78 -47
- package/dist/docs/sign-in-redirect.md +4 -2
- package/dist/docs/sign-in.md +173 -0
- package/dist/docs/toast.md +15 -4
- package/dist/docs/variant-selector.md +15 -11
- package/dist/graphql/types.d.ts +4 -14
- package/dist/index.d.ts +2 -2
- package/dist/internal/client.d.ts +1 -3
- package/dist/internal/client.js +1 -1
- package/dist/internal/server.d.ts +7 -4
- package/dist/internal/server.js +7 -4
- package/dist/matter/access-code-sign-in/access-code-sign-in.d.ts +250 -66
- package/dist/matter/access-code-sign-in/access-code-sign-in.js +459 -188
- package/dist/matter/access-code-sign-in/access-code-sign-in.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-delete.d.ts +78 -40
- package/dist/matter/account-address-book/account-address-book-delete.js +86 -50
- package/dist/matter/account-address-book/account-address-book-delete.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-deliverability.d.ts +21 -4
- package/dist/matter/account-address-book/account-address-book-deliverability.js +45 -17
- package/dist/matter/account-address-book/account-address-book-deliverability.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-form-parts.d.ts +74 -19
- package/dist/matter/account-address-book/account-address-book-form-parts.js +77 -26
- package/dist/matter/account-address-book/account-address-book-form-parts.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-profile-notice.d.ts +27 -6
- package/dist/matter/account-address-book/account-address-book-profile-notice.js +55 -28
- package/dist/matter/account-address-book/account-address-book-profile-notice.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book.d.ts +67 -14
- package/dist/matter/account-address-book/account-address-book.js +74 -33
- package/dist/matter/account-address-book/account-address-book.js.map +1 -1
- package/dist/matter/account-address-book/account-address-country-switch.js +3 -3
- package/dist/matter/account-address-book/account-address-country-switch.js.map +1 -1
- package/dist/matter/account-address-book/account-address-country.d.ts +66 -20
- package/dist/matter/account-address-book/account-address-country.js +83 -49
- package/dist/matter/account-address-book/account-address-country.js.map +1 -1
- package/dist/matter/account-address-book/account-address-form-context.d.ts +8 -4
- package/dist/matter/account-address-book/account-address-form-context.js.map +1 -1
- package/dist/matter/account-address-book/account-address-form.d.ts +468 -45
- package/dist/matter/account-address-book/account-address-form.js +518 -155
- package/dist/matter/account-address-book/account-address-form.js.map +1 -1
- package/dist/matter/account-address-book/account-address-record.d.ts +27 -6
- package/dist/matter/account-address-book/account-address-record.js +32 -17
- package/dist/matter/account-address-book/account-address-record.js.map +1 -1
- package/dist/matter/account-menu/account-menu.d.ts +34 -17
- package/dist/matter/account-menu/account-menu.js +46 -54
- package/dist/matter/account-menu/account-menu.js.map +1 -1
- package/dist/matter/account-menu-identity/account-menu-identity.js +1 -1
- package/dist/matter/account-saved-cards/account-saved-cards.d.ts +108 -28
- package/dist/matter/account-saved-cards/account-saved-cards.js +177 -122
- package/dist/matter/account-saved-cards/account-saved-cards.js.map +1 -1
- package/dist/matter/billing-address/billing-address.d.ts +156 -74
- package/dist/matter/billing-address/billing-address.js +227 -156
- package/dist/matter/billing-address/billing-address.js.map +1 -1
- package/dist/matter/breadcrumb/breadcrumb.d.ts +21 -3
- package/dist/matter/breadcrumb/breadcrumb.js +24 -9
- package/dist/matter/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/matter/buy-button/buy-button.d.ts +8 -11
- package/dist/matter/buy-button/buy-button.js +10 -19
- package/dist/matter/buy-button/buy-button.js.map +1 -1
- package/dist/matter/card-entry/card-capture.js +12 -4
- package/dist/matter/card-entry/card-capture.js.map +1 -1
- package/dist/matter/card-entry/card-entry.d.ts +123 -32
- package/dist/matter/card-entry/card-entry.js +348 -221
- package/dist/matter/card-entry/card-entry.js.map +1 -1
- package/dist/matter/cart/cart-namespace.d.ts +7 -1
- package/dist/matter/cart/cart-namespace.js +7 -1
- package/dist/matter/cart/cart-namespace.js.map +1 -1
- package/dist/matter/cart/cart.d.ts +402 -61
- package/dist/matter/cart/cart.js +624 -153
- package/dist/matter/cart/cart.js.map +1 -1
- package/dist/matter/cart-destination/cart-destination.d.ts +30 -19
- package/dist/matter/cart-destination/cart-destination.js +160 -70
- package/dist/matter/cart-destination/cart-destination.js.map +1 -1
- package/dist/matter/cart-item/cart-item.d.ts +144 -17
- package/dist/matter/cart-item/cart-item.js +166 -49
- package/dist/matter/cart-item/cart-item.js.map +1 -1
- package/dist/matter/cart-item-compositions/cart-item-compositions.js +1 -1
- package/dist/matter/cart-item-compositions/cart-item-compositions.js.map +1 -1
- package/dist/matter/cart-item-customizations/cart-item-customizations.js +1 -1
- package/dist/matter/cart-item-customizations/cart-item-customizations.js.map +1 -1
- package/dist/matter/cart-item-discounts/cart-item-discounts.js +1 -1
- package/dist/matter/cart-item-discounts/cart-item-discounts.js.map +1 -1
- package/dist/matter/cart-item-seller-info/cart-item-seller-info.js +1 -1
- package/dist/matter/cart-item-seller-info/cart-item-seller-info.js.map +1 -1
- package/dist/matter/cart-item-variations/cart-item-variations.js +1 -1
- package/dist/matter/cart-item-variations/cart-item-variations.js.map +1 -1
- package/dist/matter/cart-totalizer/cart-totalizer.d.ts +43 -9
- package/dist/matter/cart-totalizer/cart-totalizer.js +46 -17
- package/dist/matter/cart-totalizer/cart-totalizer.js.map +1 -1
- package/dist/matter/challenge-return/challenge-return.d.ts +62 -0
- package/dist/matter/challenge-return/challenge-return.js +241 -0
- package/dist/matter/challenge-return/challenge-return.js.map +1 -0
- package/dist/matter/client-preferences/client-preferences-fieldset.d.ts +86 -17
- package/dist/matter/client-preferences/client-preferences-fieldset.js +126 -54
- package/dist/matter/client-preferences/client-preferences-fieldset.js.map +1 -1
- package/dist/matter/client-preferences/client-preferences.d.ts +50 -7
- package/dist/matter/client-preferences/client-preferences.js +84 -15
- package/dist/matter/client-preferences/client-preferences.js.map +1 -1
- package/dist/matter/client-profile/client-profile.d.ts +44 -9
- package/dist/matter/client-profile/client-profile.js +64 -24
- package/dist/matter/client-profile/client-profile.js.map +1 -1
- package/dist/matter/client-profile-form/client-profile-fieldset.d.ts +119 -22
- package/dist/matter/client-profile-form/client-profile-fieldset.js +161 -73
- package/dist/matter/client-profile-form/client-profile-fieldset.js.map +1 -1
- package/dist/matter/delivery-options/delivery-options-accordion.d.ts +49 -4
- package/dist/matter/delivery-options/delivery-options-accordion.js +67 -14
- package/dist/matter/delivery-options/delivery-options-accordion.js.map +1 -1
- package/dist/matter/delivery-options/delivery-options-controller.d.ts +69 -9
- package/dist/matter/delivery-options/delivery-options-controller.js +80 -14
- package/dist/matter/delivery-options/delivery-options-controller.js.map +1 -1
- package/dist/matter/delivery-options/delivery-options.d.ts +37 -2
- package/dist/matter/delivery-options/delivery-options.js +75 -12
- package/dist/matter/delivery-options/delivery-options.js.map +1 -1
- package/dist/matter/delivery-options/use-delivery-option-selection.d.ts +1 -0
- package/dist/matter/delivery-options/use-delivery-option-selection.js +1 -1
- package/dist/matter/delivery-options/use-delivery-option-selection.js.map +1 -1
- package/dist/matter/email-identification/email-identification.d.ts +25 -3
- package/dist/matter/email-identification/email-identification.js +49 -12
- package/dist/matter/email-identification/email-identification.js.map +1 -1
- package/dist/matter/free-shipping-progress/free-shipping-progress.d.ts +79 -7
- package/dist/matter/free-shipping-progress/free-shipping-progress.js +77 -20
- package/dist/matter/free-shipping-progress/free-shipping-progress.js.map +1 -1
- package/dist/matter/identity-edit/identity-edit.d.ts +52 -10
- package/dist/matter/identity-edit/identity-edit.js +47 -19
- package/dist/matter/identity-edit/identity-edit.js.map +1 -1
- package/dist/matter/identity-summary/identity-summary.d.ts +76 -22
- package/dist/matter/identity-summary/identity-summary.js +95 -45
- package/dist/matter/identity-summary/identity-summary.js.map +1 -1
- package/dist/matter/installments/installments-select.d.ts +98 -16
- package/dist/matter/installments/installments-select.js +156 -48
- package/dist/matter/installments/installments-select.js.map +1 -1
- package/dist/matter/installments/installments.d.ts +96 -16
- package/dist/matter/installments/installments.js +115 -40
- package/dist/matter/installments/installments.js.map +1 -1
- package/dist/matter/installments/use-installments-selection.d.ts +1 -0
- package/dist/matter/installments/use-installments-selection.js +8 -3
- package/dist/matter/installments/use-installments-selection.js.map +1 -1
- package/dist/matter/my-account-profile/my-account-profile.d.ts +358 -103
- package/dist/matter/my-account-profile/my-account-profile.js +370 -174
- package/dist/matter/my-account-profile/my-account-profile.js.map +1 -1
- package/dist/matter/order-cancel/order-cancel.d.ts +65 -19
- package/dist/matter/order-cancel/order-cancel.js +118 -51
- package/dist/matter/order-cancel/order-cancel.js.map +1 -1
- package/dist/matter/order-delivery-address/order-delivery-address.d.ts +8 -18
- package/dist/matter/order-delivery-address/order-delivery-address.js +14 -23
- package/dist/matter/order-delivery-address/order-delivery-address.js.map +1 -1
- package/dist/matter/order-delivery-group/order-delivery-group.d.ts +40 -24
- package/dist/matter/order-delivery-group/order-delivery-group.js +64 -74
- package/dist/matter/order-delivery-group/order-delivery-group.js.map +1 -1
- package/dist/matter/order-details-header/order-details-header.d.ts +32 -15
- package/dist/matter/order-details-header/order-details-header.js +66 -58
- package/dist/matter/order-details-header/order-details-header.js.map +1 -1
- package/dist/matter/order-invoice-download/order-invoice-download.d.ts +78 -0
- package/dist/matter/order-invoice-download/order-invoice-download.js +173 -0
- package/dist/matter/order-invoice-download/order-invoice-download.js.map +1 -0
- package/dist/matter/order-list/order-list.d.ts +164 -19
- package/dist/matter/order-list/order-list.js +229 -87
- package/dist/matter/order-list/order-list.js.map +1 -1
- package/dist/matter/order-list-row/order-list-row.d.ts +6 -1
- package/dist/matter/order-list-row/order-list-row.js +3 -2
- package/dist/matter/order-list-row/order-list-row.js.map +1 -1
- package/dist/matter/order-list-search/order-list-search.d.ts +18 -26
- package/dist/matter/order-list-search/order-list-search.js +30 -69
- package/dist/matter/order-list-search/order-list-search.js.map +1 -1
- package/dist/matter/order-list-views/order-list-views.d.ts +15 -22
- package/dist/matter/order-list-views/order-list-views.js +22 -68
- package/dist/matter/order-list-views/order-list-views.js.map +1 -1
- package/dist/matter/order-payment/order-payment.d.ts +33 -10
- package/dist/matter/order-payment/order-payment.js +44 -39
- package/dist/matter/order-payment/order-payment.js.map +1 -1
- package/dist/matter/order-placed/order-placed-deliveries.d.ts +144 -12
- package/dist/matter/order-placed/order-placed-deliveries.js +115 -40
- package/dist/matter/order-placed/order-placed-deliveries.js.map +1 -1
- package/dist/matter/order-placed/order-placed.d.ts +198 -31
- package/dist/matter/order-placed/order-placed.js +230 -139
- package/dist/matter/order-placed/order-placed.js.map +1 -1
- package/dist/matter/order-placed-date/order-placed-date.d.ts +5 -8
- package/dist/matter/order-placed-date/order-placed-date.js +7 -8
- package/dist/matter/order-placed-date/order-placed-date.js.map +1 -1
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.d.ts +90 -17
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.js +93 -117
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.js.map +1 -1
- package/dist/matter/order-progress/order-progress.d.ts +19 -8
- package/dist/matter/order-progress/order-progress.js +37 -45
- package/dist/matter/order-progress/order-progress.js.map +1 -1
- package/dist/matter/order-summary/order-summary.d.ts +19 -9
- package/dist/matter/order-summary/order-summary.js +38 -44
- package/dist/matter/order-summary/order-summary.js.map +1 -1
- package/dist/matter/order-tracking-link/order-tracking-link.d.ts +43 -0
- package/dist/matter/order-tracking-link/order-tracking-link.js +107 -0
- package/dist/matter/order-tracking-link/order-tracking-link.js.map +1 -0
- package/dist/matter/payment/payment-card-capture.js +17 -10
- package/dist/matter/payment/payment-card-capture.js.map +1 -1
- package/dist/matter/payment/payment-controller.d.ts +4 -2
- package/dist/matter/payment/payment-controller.js +30 -9
- package/dist/matter/payment/payment-controller.js.map +1 -1
- package/dist/matter/payment/payment-method-badges.js +1 -1
- package/dist/matter/payment/payment.d.ts +69 -19
- package/dist/matter/payment/payment.js +101 -35
- package/dist/matter/payment/payment.js.map +1 -1
- package/dist/matter/payment/use-payment-method-selection.d.ts +25 -4
- package/dist/matter/payment/use-payment-method-selection.js +94 -32
- package/dist/matter/payment/use-payment-method-selection.js.map +1 -1
- package/dist/matter/payment/use-payment-submit-gate.d.ts +14 -3
- package/dist/matter/payment/use-payment-submit-gate.js +47 -8
- package/dist/matter/payment/use-payment-submit-gate.js.map +1 -1
- package/dist/matter/place-order/place-order.d.ts +171 -57
- package/dist/matter/place-order/place-order.js +376 -185
- package/dist/matter/place-order/place-order.js.map +1 -1
- package/dist/matter/pricing/pricing.d.ts +152 -13
- package/dist/matter/pricing/pricing.js +153 -52
- package/dist/matter/pricing/pricing.js.map +1 -1
- package/dist/matter/product-information/product-information.d.ts +27 -4
- package/dist/matter/product-information/product-information.js +32 -15
- package/dist/matter/product-information/product-information.js.map +1 -1
- package/dist/matter/product-list/product-list.d.ts +24 -6
- package/dist/matter/product-list/product-list.js +32 -26
- package/dist/matter/product-list/product-list.js.map +1 -1
- package/dist/matter/product-shelf/product-shelf.d.ts +1 -3
- package/dist/matter/product-shelf/product-shelf.js +2 -15
- package/dist/matter/product-shelf/product-shelf.js.map +1 -1
- package/dist/matter/region/region.d.ts +33 -16
- package/dist/matter/region/region.js +59 -52
- package/dist/matter/region/region.js.map +1 -1
- package/dist/matter/save-card/save-card.d.ts +43 -8
- package/dist/matter/save-card/save-card.js +61 -23
- package/dist/matter/save-card/save-card.js.map +1 -1
- package/dist/matter/saved-cards/saved-cards.d.ts +113 -21
- package/dist/matter/saved-cards/saved-cards.js +349 -77
- package/dist/matter/saved-cards/saved-cards.js.map +1 -1
- package/dist/matter/shipping-address/address-payload.js +25 -0
- package/dist/matter/shipping-address/address-payload.js.map +1 -0
- package/dist/matter/shipping-address/country-descriptors.js +71 -71
- package/dist/matter/shipping-address/country-descriptors.js.map +1 -1
- package/dist/matter/shipping-address/library-country-descriptors.js +136 -0
- package/dist/matter/shipping-address/library-country-descriptors.js.map +1 -0
- package/dist/matter/shipping-address/shipping-address.d.ts +312 -45
- package/dist/matter/shipping-address/shipping-address.js +443 -188
- package/dist/matter/shipping-address/shipping-address.js.map +1 -1
- package/dist/matter/shipping-simulator/shipping-simulator.d.ts +250 -24
- package/dist/matter/shipping-simulator/shipping-simulator.js +257 -51
- package/dist/matter/shipping-simulator/shipping-simulator.js.map +1 -1
- package/dist/matter/sign-in/sign-in.d.ts +108 -0
- package/dist/matter/sign-in/sign-in.js +285 -0
- package/dist/matter/sign-in/sign-in.js.map +1 -0
- package/dist/matter/sign-in-disclosure/sign-in-disclosure.d.ts +81 -0
- package/dist/matter/sign-in-disclosure/sign-in-disclosure.js +232 -0
- package/dist/matter/sign-in-disclosure/sign-in-disclosure.js.map +1 -0
- package/dist/matter/sign-in-form/sign-in-form.d.ts +93 -62
- package/dist/matter/sign-in-form/sign-in-form.js +134 -144
- package/dist/matter/sign-in-form/sign-in-form.js.map +1 -1
- package/dist/particles/binding-switcher/binding-switcher.d.ts +29 -8
- package/dist/particles/binding-switcher/binding-switcher.js +37 -26
- package/dist/particles/binding-switcher/binding-switcher.js.map +1 -1
- package/dist/particles/card-summary/card-summary.d.ts +38 -8
- package/dist/particles/card-summary/card-summary.js +55 -22
- package/dist/particles/card-summary/card-summary.js.map +1 -1
- package/dist/particles/carousel/carousel.d.ts +99 -11
- package/dist/particles/carousel/carousel.js +103 -35
- package/dist/particles/carousel/carousel.js.map +1 -1
- package/dist/particles/copy-text/copy-text.js +5 -15
- package/dist/particles/copy-text/copy-text.js.map +1 -1
- package/dist/particles/dialog/dialog.d.ts +14 -6
- package/dist/particles/dialog/dialog.js +6 -3
- package/dist/particles/dialog/dialog.js.map +1 -1
- package/dist/particles/drawer/drawer.js +1 -1
- package/dist/particles/drawer/drawer.js.map +1 -1
- package/dist/particles/email-field/email-field.d.ts +2 -1
- package/dist/particles/email-field/email-field.js +2 -1
- package/dist/particles/email-field/email-field.js.map +1 -1
- package/dist/particles/footer-link-group/footer-link-group.js +1 -0
- package/dist/particles/footer-link-group/footer-link-group.js.map +1 -1
- package/dist/particles/form/form.d.ts +85 -13
- package/dist/particles/form/form.js +91 -42
- package/dist/particles/form/form.js.map +1 -1
- package/dist/particles/gallery/gallery.d.ts +129 -12
- package/dist/particles/gallery/gallery.js +121 -34
- package/dist/particles/gallery/gallery.js.map +1 -1
- package/dist/particles/order-details-back/order-details-back.d.ts +5 -3
- package/dist/particles/order-details-back/order-details-back.js +8 -10
- package/dist/particles/order-details-back/order-details-back.js.map +1 -1
- package/dist/particles/order-status-badge/order-status-badge.d.ts +3 -3
- package/dist/particles/order-status-badge/order-status-badge.js +4 -20
- package/dist/particles/order-status-badge/order-status-badge.js.map +1 -1
- package/dist/particles/password-field/password-field.d.ts +1 -1
- package/dist/particles/password-field/password-field.js +2 -4
- package/dist/particles/password-field/password-field.js.map +1 -1
- package/dist/particles/phone-field/phone-field.d.ts +4 -4
- package/dist/particles/phone-field/phone-field.js +8 -11
- package/dist/particles/phone-field/phone-field.js.map +1 -1
- package/dist/particles/spinner/spinner.d.ts +24 -4
- package/dist/particles/spinner/spinner.js +25 -9
- package/dist/particles/spinner/spinner.js.map +1 -1
- package/dist/particles/switch/switch.d.ts +4 -1
- package/dist/particles/switch/switch.js +3 -1
- package/dist/particles/switch/switch.js.map +1 -1
- package/dist/particles/toast/toast.d.ts +29 -3
- package/dist/particles/toast/toast.js +34 -10
- package/dist/particles/toast/toast.js.map +1 -1
- package/dist/schema.graphql +164 -56
- package/dist/sdk/address/address-fields.js +4 -4
- package/dist/sdk/address/address-fields.js.map +1 -1
- package/dist/sdk/address/constants.js +1 -6
- package/dist/sdk/address/constants.js.map +1 -1
- package/dist/sdk/address/messages.js +44 -44
- package/dist/sdk/address/messages.js.map +1 -1
- package/dist/sdk/address/postal-code.js +15 -2
- package/dist/sdk/address/postal-code.js.map +1 -1
- package/dist/sdk/address/types.d.ts +5 -3
- package/dist/sdk/address/validate-address.js +3 -3
- package/dist/sdk/address/validate-address.js.map +1 -1
- package/dist/sdk/analytics/use-analytics-actions.d.ts +1 -1
- package/dist/sdk/analytics/use-analytics-actions.js.map +1 -1
- package/dist/sdk/cart/use-cart-actions.js.map +1 -1
- package/dist/sdk/data/index.js +2 -2
- package/dist/sdk/data/reactive-list-item-data-provider.js +2 -2
- package/dist/sdk/generated/gql.js +1 -1
- package/dist/sdk/generated/gql.js.map +1 -1
- package/dist/sdk/generated/graphql.d.ts +20 -5
- package/dist/sdk/generated/graphql.js +6 -0
- package/dist/sdk/generated/graphql.js.map +1 -1
- package/dist/sdk/i18n/format-error-code.js +23 -0
- package/dist/sdk/i18n/format-error-code.js.map +1 -0
- package/dist/sdk/i18n/message-formatter.d.ts +22 -0
- package/dist/sdk/i18n/message-formatter.js +140 -0
- package/dist/sdk/i18n/message-formatter.js.map +1 -0
- package/dist/sdk/i18n/use-message-formatter.d.ts +8 -0
- package/dist/sdk/i18n/use-message-formatter.js +18 -0
- package/dist/sdk/i18n/use-message-formatter.js.map +1 -0
- package/dist/sdk/identity/use-identity-actions.js.map +1 -1
- package/dist/sdk/navigation/redirect.d.ts +2 -0
- package/dist/sdk/navigation/redirect.js +19 -1
- package/dist/sdk/navigation/redirect.js.map +1 -1
- package/dist/sdk/navigation/types.d.ts +13 -0
- package/dist/sdk/payment/bin-format.js +20 -0
- package/dist/sdk/payment/bin-format.js.map +1 -0
- package/dist/sdk/payment/challenge-return.js +37 -0
- package/dist/sdk/payment/challenge-return.js.map +1 -0
- package/dist/sdk/payment/confirmation-last-four.js +39 -0
- package/dist/sdk/payment/confirmation-last-four.js.map +1 -0
- package/dist/sdk/payment/gateway.d.ts +1 -1
- package/dist/sdk/payment/gateway.js +8 -2
- package/dist/sdk/payment/gateway.js.map +1 -1
- package/dist/sdk/payment/operations.d.ts +1 -0
- package/dist/sdk/payment/operations.js +28 -6
- package/dist/sdk/payment/operations.js.map +1 -1
- package/dist/sdk/payment/resumed-purchase.d.ts +1 -0
- package/dist/sdk/payment/resumed-purchase.js +119 -0
- package/dist/sdk/payment/resumed-purchase.js.map +1 -0
- package/dist/sdk/payment/security-code-mask.js +16 -23
- package/dist/sdk/payment/security-code-mask.js.map +1 -1
- package/dist/sdk/payment/submission-registry.js +6 -2
- package/dist/sdk/payment/submission-registry.js.map +1 -1
- package/dist/sdk/payment/use-payment-actions.d.ts +18 -3
- package/dist/sdk/payment/use-payment-actions.js +23 -3
- package/dist/sdk/payment/use-payment-actions.js.map +1 -1
- package/dist/sdk/payment/use-place-order.d.ts +10 -2
- package/dist/sdk/payment/use-place-order.js +138 -76
- package/dist/sdk/payment/use-place-order.js.map +1 -1
- package/dist/sdk/provider/storefront-provider.d.ts +1 -7
- package/dist/sdk/provider/storefront-provider.js +4 -11
- package/dist/sdk/provider/storefront-provider.js.map +1 -1
- package/dist/sdk/seo/entity-landing.d.ts +24 -0
- package/dist/sdk/seo/entity-landing.js +30 -0
- package/dist/sdk/seo/entity-landing.js.map +1 -0
- package/dist/sdk/seo/page-alternates.d.ts +3 -2
- package/dist/sdk/seo/page-alternates.js +4 -2
- package/dist/sdk/seo/page-alternates.js.map +1 -1
- package/dist/sdk/seo/search-landing.d.ts +42 -0
- package/dist/sdk/seo/search-landing.js +85 -0
- package/dist/sdk/seo/search-landing.js.map +1 -0
- package/dist/sdk/session/mock-session.d.ts +9 -0
- package/dist/sdk/session/mock-session.js +31 -0
- package/dist/sdk/session/mock-session.js.map +1 -0
- package/dist/sdk/session/read-server-session.d.ts +3 -0
- package/dist/sdk/session/read-server-session.js +5 -0
- package/dist/sdk/session/read-server-session.js.map +1 -1
- package/dist/sdk/session/return-path-segment.d.ts +10 -0
- package/dist/sdk/session/return-path-segment.js +15 -0
- package/dist/sdk/session/return-path-segment.js.map +1 -0
- package/dist/sdk/session/use-session-actions.js.map +1 -1
- package/dist/sdk/shipping/use-cart-shipping-simulation.js.map +1 -1
- package/dist/sdk/shipping/use-shipping-actions.js.map +1 -1
- package/dist/sdk/shipping/use-shipping-simulation.js.map +1 -1
- package/dist/utils/safe-href.d.ts +2 -0
- package/package.json +4 -3
- package/skills/storefront-asset/SKILL.md +2 -2
- package/skills/storefront-asset/references/api-side.md +27 -14
- package/skills/storefront-asset/references/findings.md +5 -2
- package/src/styles/tailwind.css +8 -0
- package/dist/matter/shipping-address/country-descriptors.d.ts +0 -1
- package/dist/message-locales.json +0 -7
- package/dist/sdk/i18n/client.d.ts +0 -4
- package/dist/sdk/i18n/client.js +0 -4
- package/dist/sdk/i18n/locales.d.ts +0 -8
- package/dist/sdk/i18n/locales.js +0 -57
- package/dist/sdk/i18n/locales.js.map +0 -1
- package/dist/sdk/i18n/messages/en-US.js +0 -183
- package/dist/sdk/i18n/messages/en-US.js.map +0 -1
- package/dist/sdk/i18n/messages/en-US.json +0 -178
- package/dist/sdk/i18n/messages/en-US.json.d.ts +0 -182
- package/dist/sdk/i18n/messages/es-ES.js +0 -183
- package/dist/sdk/i18n/messages/es-ES.js.map +0 -1
- package/dist/sdk/i18n/messages/es-ES.json +0 -178
- package/dist/sdk/i18n/messages/pt-BR.js +0 -183
- package/dist/sdk/i18n/messages/pt-BR.js.map +0 -1
- package/dist/sdk/i18n/messages/pt-BR.json +0 -178
- package/dist/sdk/i18n/provider.d.ts +0 -1
- package/dist/sdk/i18n/provider.js +0 -30
- package/dist/sdk/i18n/provider.js.map +0 -1
- package/dist/sdk/i18n/server.d.ts +0 -28
- package/dist/sdk/i18n/server.js +0 -59
- package/dist/sdk/i18n/server.js.map +0 -1
- package/dist/utils/resolve-authored-copy.js +0 -18
- package/dist/utils/resolve-authored-copy.js.map +0 -1
- package/dist/utils/substitute-template.js +0 -33
- package/dist/utils/substitute-template.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shipping-simulator.js","names":[],"sources":["../../../src/matter/shipping-simulator/shipping-simulator.tsx"],"sourcesContent":["'use client';\n\nimport { defineComponent } from '@vtex/fs-core';\nimport type { ComponentPropsWithRef } from 'react';\nimport { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react';\nimport { useStorefrontContext } from '../../sdk/context/storefront-context.js';\nimport { useDataOverride } from '../../sdk/data/data-override-context.js';\nimport { FormattedMessage, type MessageId, useIntl } from '../../sdk/i18n/client.js';\nimport type { CartShippingSimulateInput } from '../../sdk/shipping/cart-operations.js';\nimport type { ShippingSimulateInput } from '../../sdk/shipping/operations.js';\nimport { useCartShippingSimulation } from '../../sdk/shipping/use-cart-shipping-simulation.js';\nimport { useShippingSimulation } from '../../sdk/shipping/use-shipping-simulation.js';\nimport { isFiniteAmount } from '../cart/cart.js';\n\n// ---------------------------------------------------------------------------\n// GraphQL Fragment\n// ---------------------------------------------------------------------------\n\nconst fragment = /* GraphQL */ `\n fragment ShippingSimulatorData on Query {\n productBySlug(slug: $slug) {\n variants(first: 1) {\n edges {\n node {\n id\n sellers {\n id\n isDefault\n }\n }\n }\n }\n }\n }\n`;\n\n// ---------------------------------------------------------------------------\n// Raw data types (shape of the fragment result)\n// ---------------------------------------------------------------------------\n\ntype RawShippingSimulatorData = {\n variants: {\n edges: Array<{\n node: {\n id: string;\n sellers: Array<{\n id: string;\n isDefault: boolean;\n }>;\n };\n }>;\n };\n};\n\n// ---------------------------------------------------------------------------\n// Domain types (mirror the shippingSimulation GraphQL contract)\n// ---------------------------------------------------------------------------\n\ntype MoneyValue = { amount: string; currencyCode: string };\n\ntype DeliveryChannel = 'DELIVERY' | 'PICKUP' | 'UNKNOWN';\n\nexport type ShippingEstimateUnit = 'BUSINESS_DAYS' | 'DAYS' | 'HOURS' | 'MINUTES';\n\ntype ShippingEstimate = { value: number; unit: ShippingEstimateUnit };\n\n// Exported alongside `ShippingSimulatorContextValue` so `DeliveryOptionsRoot`\n// (matter/delivery-options) can type against the exact shape the reused leaves expect, with no\n// structural duplication (docs/storefront-core/reference-free-particle-model.md § Read side — state).\nexport type ShippingOption = {\n id: string;\n name: string;\n channel: DeliveryChannel;\n shippingEstimate: ShippingEstimate;\n price: MoneyValue;\n listPrice: MoneyValue;\n};\n\ntype ShippingSimulateErrorCode = 'INVALID_POSTAL_CODE' | 'UNKNOWN';\n\n// Exported with `ShippingSimulationPayload` so the `./client` entry can name the simulate callback's\n// whole contract — the SDK hooks return it and a store writing its own `onSimulate` has to name it.\nexport type ShippingSimulateError = {\n code: ShippingSimulateErrorCode;\n message: string;\n};\n\nexport type ShippingSimulationPayload = {\n shippingOptions: ShippingOption[] | null;\n userErrors: ShippingSimulateError[];\n};\n\ntype Status = 'idle' | 'loading' | 'success' | 'error';\n\nexport type ShippingSimulatorContextValue = {\n postalCode: string;\n setPostalCode: (value: string) => void;\n status: Status;\n shippingOptions: ShippingOption[] | null;\n userErrors: ShippingSimulateError[];\n submit: () => void;\n};\n\nconst SHIPPING_SIMULATOR_CONTEXT_UNSET = Symbol('ShippingSimulatorContextUnset');\n\nexport type ShippingSimulatorRootProps = ComponentPropsWithRef<'div'> & {\n country?: string;\n quantity?: number;\n variantId?: string;\n seller?: string;\n $data?: RawShippingSimulatorData | null;\n shippingOptions?: ShippingOption[];\n userErrors?: ShippingSimulateError[];\n onSimulate?: (input: ShippingSimulateInput) => Promise<ShippingSimulationPayload>;\n onResult?: (result: ShippingSimulationPayload) => void;\n};\n\nexport type CartShippingSimulatorRootProps = ComponentPropsWithRef<'div'> & {\n country?: string;\n shippingOptions?: ShippingOption[];\n userErrors?: ShippingSimulateError[];\n onSimulate?: (input: CartShippingSimulateInput) => Promise<ShippingSimulationPayload>;\n onResult?: (result: ShippingSimulationPayload) => void;\n};\n\nexport type ShippingSimulatorFormProps = ComponentPropsWithRef<'form'>;\n\nexport type ShippingSimulatorInputProps = Omit<ComponentPropsWithRef<'input'>, 'value' | 'onChange'> & {\n format?: boolean;\n};\n\nexport type ShippingSimulatorSubmitProps = ComponentPropsWithRef<'button'>;\n\nexport type ShippingSimulatorLoadingProps = ComponentPropsWithRef<'output'>;\n\nexport type ShippingSimulatorErrorProps = ComponentPropsWithRef<'div'>;\n\nexport type ShippingSimulatorOptionsProps = ComponentPropsWithRef<'ul'> & {\n sortBy?: 'price' | 'estimate';\n maxOptions?: number;\n};\n\nexport type ShippingSimulatorOptionProps = ComponentPropsWithRef<'li'>;\n\nexport type ShippingSimulatorOptionNameProps = ComponentPropsWithRef<'span'>;\n\nexport type ShippingSimulatorOptionEstimateProps = ComponentPropsWithRef<'span'>;\n\nexport type ShippingSimulatorOptionPriceProps = ComponentPropsWithRef<'span'>;\n\nexport type ShippingSimulatorOptionFreeBadgeProps = ComponentPropsWithRef<'span'>;\n\nexport type ShippingSimulatorEmptyProps = ComponentPropsWithRef<'output'>;\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\n// Exported so `DeliveryOptionsRoot` can become a third provider by importing these same Context\n// objects directly (context matching is by identity, not shape). The two hooks below stay\n// module-private — providers need the objects, not the consumer API (Decision 2).\nexport const ShippingSimulatorContext = createContext<\n ShippingSimulatorContextValue | typeof SHIPPING_SIMULATOR_CONTEXT_UNSET\n>(SHIPPING_SIMULATOR_CONTEXT_UNSET);\n\nexport const OptionItemContext = createContext<ShippingOption | null>(null);\n\nfunction useShippingSimulator(): ShippingSimulatorContextValue {\n const ctx = useContext(ShippingSimulatorContext);\n if (ctx === SHIPPING_SIMULATOR_CONTEXT_UNSET) {\n throw new Error('ShippingSimulator components must be used inside ShippingSimulatorRoot.');\n }\n return ctx;\n}\n\nfunction useOptionItem(): ShippingOption {\n const ctx = useContext(OptionItemContext);\n if (!ctx) {\n throw new Error('ShippingSimulatorOption components must be used inside ShippingSimulatorOptions.');\n }\n return ctx;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction formatPrice(value: number, locale: string, currency: string): string {\n return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(value);\n}\n\n// Each unit's whole sentence, and the variable that sentence names.\n//\n// Whole sentence, not a unit fragment interpolated into a wrapper: interpolating a translated\n// fragment into a translated wrapper freezes \"preposition + noun\" order into every language, and\n// hands the translator `em {estimate}` with no way to agree preposition, article or case with a noun\n// they cannot see. The variable is named after what it counts (`{days}`, `{hours}`) rather than a\n// generic `{count}`, for the same reason.\n//\n// A `Record` and not a `switch` with a default: a fifth unit arriving in the GraphQL schema is a\n// type error here, not a silent fallback to the wrong sentence.\n//\n// `variable` is the union of the names those sentences read, never `string`: widened, a typo passes\n// typecheck, lint and every test, and the shopper gets the raw ICU pattern because `onIntlError` is\n// silent in production. The parity assertion in the test file closes the other half of the gap — that\n// the name written here is the one the catalog's message actually names.\nexport const ESTIMATE_MESSAGE: Record<ShippingEstimateUnit, { id: MessageId; variable: 'days' | 'hours' | 'minutes' }> =\n {\n BUSINESS_DAYS: { id: 'fs/shipping.estimate.in-business-days', variable: 'days' },\n DAYS: { id: 'fs/shipping.estimate.in-days', variable: 'days' },\n HOURS: { id: 'fs/shipping.estimate.in-hours', variable: 'hours' },\n MINUTES: { id: 'fs/shipping.estimate.in-minutes', variable: 'minutes' },\n };\n\n// Business days weigh the same as calendar days: exact wall-clock conversion is unknowable and\n// the ranking only needs a consistent order.\nconst ESTIMATE_UNIT_MINUTES: Record<ShippingEstimateUnit, number> = {\n MINUTES: 1,\n HOURS: 60,\n DAYS: 1440,\n BUSINESS_DAYS: 1440,\n};\n\nfunction sortShippingOptions(options: readonly ShippingOption[], sortBy: 'price' | 'estimate'): ShippingOption[] {\n const rank =\n sortBy === 'price'\n ? (option: ShippingOption) => Number(option.price.amount)\n : (option: ShippingOption) => option.shippingEstimate.value * ESTIMATE_UNIT_MINUTES[option.shippingEstimate.unit];\n return [...options].sort((a, b) => rank(a) - rank(b));\n}\n\nfunction normalizePostalCode(value: string): string {\n return value.replace(/\\D/g, '').slice(0, 8);\n}\n\nfunction formatPostalCode(value: string): string {\n const digits = normalizePostalCode(value);\n return digits.length > 5 ? `${digits.slice(0, 5)}-${digits.slice(5)}` : digits;\n}\n\nfunction extractProductFromData(data: RawShippingSimulatorData | null | undefined): {\n variantId: string | null;\n seller: string | null;\n} {\n if (!data) return { variantId: null, seller: null };\n const edge = data.variants?.edges?.[0];\n if (!edge) return { variantId: null, seller: null };\n const { id, sellers } = edge.node;\n const defaultSeller = sellers?.find((s) => s.isDefault) ?? sellers?.[0];\n return { variantId: id ?? null, seller: defaultSeller?.id ?? null };\n}\n\n// ---------------------------------------------------------------------------\n// Definitions\n// ---------------------------------------------------------------------------\n\nexport const ShippingSimulatorRootDefinition = defineComponent<ShippingSimulatorRootProps>({\n name: 'ShippingSimulatorRoot',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorRoot,\n fragment,\n fetchStrategy: 'reactive',\n editor: { label: 'Shipping Simulator', category: 'commerce' },\n schema: {\n country: { type: 'string', default: 'BRA', label: 'Country (ISO-3)' },\n quantity: { type: 'number', default: 1, label: 'Quantity' },\n },\n providesContext: 'shipping-simulator',\n guideline:\n 'Root container for the PDP shipping simulator: a shopper types a postal code and sees a shipping preview for ONE product on a product detail page. Backed by shippingSimulation and a product fragment (productBySlug(slug: $slug)), so it must live on a page with a $slug variable. Use CartShippingSimulatorRoot instead for a whole-cart calculator in the cart/mini-cart. All other ShippingSimulator components must be descendants of this one.',\n});\n\nexport const CartShippingSimulatorRootDefinition = defineComponent<CartShippingSimulatorRootProps>({\n name: 'CartShippingSimulatorRoot',\n importPath: '@vtex/faststore/components',\n component: CartShippingSimulatorRoot,\n editor: { label: 'Cart Shipping Simulator', category: 'commerce' },\n schema: {\n country: { type: 'string', default: 'BRA', label: 'Country (ISO-3)' },\n },\n providesContext: 'shipping-simulator',\n guideline:\n 'Root container for the cart/mini-cart shipping calculator: the shopper types a postal code and sees the shipping options for the WHOLE cart. Backed by cartShippingSimulation (cart sourced server-side via x-order-form-id); needs no CartRoot ancestor and no product fragment. Use ShippingSimulatorRoot instead for a single-product shipping preview on a PDP. All other CartShippingSimulator components must be descendants of this one.',\n});\n\nexport const ShippingSimulatorFormDefinition = defineComponent<ShippingSimulatorFormProps>({\n name: 'ShippingSimulatorForm',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorForm,\n editor: { label: 'Shipping Simulator Form', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Form wrapper that holds ShippingSimulatorInput and ShippingSimulatorSubmit; must be a descendant of ShippingSimulatorRoot.',\n});\n\nexport const ShippingSimulatorInputDefinition = defineComponent<ShippingSimulatorInputProps>({\n name: 'ShippingSimulatorInput',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorInput,\n editor: { label: 'Shipping Simulator Input', category: 'action' },\n schema: {\n format: { type: 'boolean', default: false, label: 'Auto-format CEP (00000-000)' },\n },\n requiresContext: 'shipping-simulator',\n guideline:\n 'Postal-code text input; enable `format` to auto-hyphenate the CEP as the user types (e.g. 01310-100). The placeholder comes from the message catalog. Must be a descendant of ShippingSimulatorForm.',\n});\n\nexport const ShippingSimulatorSubmitDefinition = defineComponent<ShippingSimulatorSubmitProps>({\n name: 'ShippingSimulatorSubmit',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorSubmit,\n editor: { label: 'Shipping Simulator Submit', category: 'action' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline: 'Submit button for the postal-code form; must be a descendant of ShippingSimulatorForm.',\n});\n\nexport const ShippingSimulatorLoadingDefinition = defineComponent<ShippingSimulatorLoadingProps>({\n name: 'ShippingSimulatorLoading',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorLoading,\n editor: { label: 'Shipping Simulator Loading', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Loading indicator shown while a simulation is in progress; must be a descendant of ShippingSimulatorRoot.',\n});\n\nexport const ShippingSimulatorErrorDefinition = defineComponent<ShippingSimulatorErrorProps>({\n name: 'ShippingSimulatorError',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorError,\n editor: { label: 'Shipping Simulator Error', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Error banner shown when the simulation returns validation errors; must be a descendant of ShippingSimulatorRoot.',\n});\n\nexport const ShippingSimulatorOptionsDefinition = defineComponent<ShippingSimulatorOptionsProps>({\n name: 'ShippingSimulatorOptions',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptions,\n editor: { label: 'Shipping Simulator Options', category: 'commerce' },\n schema: {\n sortBy: { type: ['price', 'estimate'] as const, label: 'Sort by' },\n maxOptions: { type: 'number', label: 'Max options' },\n },\n requiresContext: 'shipping-simulator',\n providesContext: 'shipping-simulator-option',\n guideline:\n 'List that renders one ShippingSimulatorOption per available shipping option; must be a descendant of a shipping-simulator Root (PDP or cart). Renders every option in API order by default; set sortBy (\"price\" = cheapest first, \"estimate\" = fastest first) and maxOptions to cap the list — sortBy=\"price\" with maxOptions=1 shows only the cheapest option. See shipping-simulator.md.',\n});\n\nexport const ShippingSimulatorOptionDefinition = defineComponent<ShippingSimulatorOptionProps>({\n name: 'ShippingSimulatorOption',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOption,\n editor: { label: 'Shipping Simulator Option', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Container for a single shipping option row; holds ShippingSimulatorOptionName, ShippingSimulatorOptionEstimate, and ShippingSimulatorOptionPrice. Must be a descendant of ShippingSimulatorOptions.',\n});\n\nexport const ShippingSimulatorOptionNameDefinition = defineComponent<ShippingSimulatorOptionNameProps>({\n name: 'ShippingSimulatorOptionName',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionName,\n editor: { label: 'Option Name', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Displays the shipping option name (e.g. \"Entrega Normal\"); must be a descendant of ShippingSimulatorOption.',\n});\n\nexport const ShippingSimulatorOptionEstimateDefinition = defineComponent<ShippingSimulatorOptionEstimateProps>({\n name: 'ShippingSimulatorOptionEstimate',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionEstimate,\n editor: { label: 'Option Estimate', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Displays the delivery estimate in the active locale, one whole sentence per unit from the message catalog; a zero-value estimate (any unit) reads as an arrival-today message instead, since \"chega em 0 dias úteis\" reads wrong. Must be a descendant of ShippingSimulatorOption.',\n});\n\nexport const ShippingSimulatorOptionPriceDefinition = defineComponent<ShippingSimulatorOptionPriceProps>({\n name: 'ShippingSimulatorOptionPrice',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionPrice,\n editor: { label: 'Option Price', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Displays the shipping price, showing the free-shipping label from the message catalog when the amount is zero; must be a descendant of ShippingSimulatorOption.',\n});\n\nexport const ShippingSimulatorOptionFreeBadgeDefinition = defineComponent<ShippingSimulatorOptionFreeBadgeProps>({\n name: 'ShippingSimulatorOptionFreeBadge',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionFreeBadge,\n editor: { label: 'Option Free Badge', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Badge shown only when the current option price is zero (free shipping); renders nothing otherwise. Must be a descendant of ShippingSimulatorOption. Orthogonal to the free-price replacement text owned by ShippingSimulatorOptionPrice.',\n});\n\nexport const ShippingSimulatorEmptyDefinition = defineComponent<ShippingSimulatorEmptyProps>({\n name: 'ShippingSimulatorEmpty',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorEmpty,\n editor: { label: 'Shipping Simulator Empty', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Message shown when a simulation ran and returned no shipping options (e.g. no carrier common to the whole cart). Renders nothing before the first submit and nothing when options or an error are present. The copy comes from the message catalog; pass children to override. Must be a descendant of a shipping-simulator Root.',\n});\n\n// ---------------------------------------------------------------------------\n// Implementations\n// ---------------------------------------------------------------------------\n\nexport function ShippingSimulatorRoot({\n country = 'BRA',\n quantity = 1,\n variantId: variantIdProp,\n seller: sellerProp,\n $data: $dataProp,\n shippingOptions: shippingOptionsProp,\n userErrors: userErrorsProp,\n onSimulate: onSimulateProp,\n onResult,\n className,\n children,\n ...props\n}: ShippingSimulatorRootProps) {\n const defaultSimulate = useShippingSimulation();\n const onSimulate = onSimulateProp ?? defaultSimulate;\n const intl = useIntl();\n\n const $data = useDataOverride($dataProp);\n const extracted = extractProductFromData($data);\n const variantId = variantIdProp ?? extracted.variantId;\n const seller = sellerProp ?? extracted.seller;\n\n const [postalCode, setPostalCode] = useState('');\n const [status, setStatus] = useState<Status>(() => {\n if (userErrorsProp?.length) return 'error';\n if (shippingOptionsProp) return 'success';\n return 'idle';\n });\n const [shippingOptions, setShippingOptions] = useState<ShippingOption[] | null>(shippingOptionsProp ?? null);\n const [userErrors, setUserErrors] = useState<ShippingSimulateError[]>(userErrorsProp ?? []);\n\n const submissionToken = useRef(0);\n\n const submit = useCallback(() => {\n if (!onSimulate || !variantId || !seller) return;\n\n const normalizedCep = normalizePostalCode(postalCode);\n if (normalizedCep.length !== 8) return;\n\n const token = ++submissionToken.current;\n setStatus('loading');\n setShippingOptions(null);\n setUserErrors([]);\n\n onSimulate({ postalCode: normalizedCep, country, variantId, quantity, seller })\n .then((result) => {\n if (submissionToken.current !== token) return;\n setShippingOptions(result.shippingOptions);\n setUserErrors(result.userErrors);\n setStatus(result.userErrors.length > 0 ? 'error' : 'success');\n onResult?.(result);\n })\n .catch(() => {\n if (submissionToken.current !== token) return;\n // In a handler, not a render: the message goes into state, where only a string fits.\n const fallback: ShippingSimulateError = {\n code: 'UNKNOWN',\n message: intl.formatMessage({ id: 'fs/shipping.calculation-failed' }),\n };\n setShippingOptions(null);\n setUserErrors([fallback]);\n setStatus('error');\n onResult?.({ shippingOptions: null, userErrors: [fallback] });\n });\n }, [country, intl, onResult, onSimulate, postalCode, quantity, seller, variantId]);\n\n const contextValue = useMemo<ShippingSimulatorContextValue>(\n () => ({\n postalCode,\n setPostalCode,\n status,\n shippingOptions,\n userErrors,\n submit,\n }),\n [postalCode, status, shippingOptions, userErrors, submit],\n );\n\n return (\n <ShippingSimulatorContext value={contextValue}>\n <div {...props} className={className} data-fs-shipping-simulator=\"\">\n {children}\n </div>\n </ShippingSimulatorContext>\n );\n}\n\nexport function CartShippingSimulatorRoot({\n country = 'BRA',\n shippingOptions: shippingOptionsProp,\n userErrors: userErrorsProp,\n onSimulate: onSimulateProp,\n onResult,\n className,\n children,\n ...props\n}: CartShippingSimulatorRootProps) {\n const defaultSimulate = useCartShippingSimulation();\n const onSimulate = onSimulateProp ?? defaultSimulate;\n const intl = useIntl();\n\n const [postalCode, setPostalCode] = useState('');\n const [status, setStatus] = useState<Status>(() => {\n if (userErrorsProp?.length) return 'error';\n if (shippingOptionsProp) return 'success';\n return 'idle';\n });\n const [shippingOptions, setShippingOptions] = useState<ShippingOption[] | null>(shippingOptionsProp ?? null);\n const [userErrors, setUserErrors] = useState<ShippingSimulateError[]>(userErrorsProp ?? []);\n\n const submissionToken = useRef(0);\n\n const submit = useCallback(() => {\n const normalizedCep = normalizePostalCode(postalCode);\n if (normalizedCep.length !== 8) return;\n\n const token = ++submissionToken.current;\n setStatus('loading');\n setShippingOptions(null);\n setUserErrors([]);\n\n onSimulate({ postalCode: normalizedCep, country })\n .then((result) => {\n if (submissionToken.current !== token) return;\n setShippingOptions(result.shippingOptions);\n setUserErrors(result.userErrors);\n setStatus(result.userErrors.length > 0 ? 'error' : 'success');\n onResult?.(result);\n })\n .catch(() => {\n if (submissionToken.current !== token) return;\n // In a handler, not a render: the message goes into state, where only a string fits.\n const fallback: ShippingSimulateError = {\n code: 'UNKNOWN',\n message: intl.formatMessage({ id: 'fs/shipping.calculation-failed' }),\n };\n setShippingOptions(null);\n setUserErrors([fallback]);\n setStatus('error');\n onResult?.({ shippingOptions: null, userErrors: [fallback] });\n });\n }, [country, intl, onResult, onSimulate, postalCode]);\n\n const contextValue = useMemo<ShippingSimulatorContextValue>(\n () => ({\n postalCode,\n setPostalCode,\n status,\n shippingOptions,\n userErrors,\n submit,\n }),\n [postalCode, status, shippingOptions, userErrors, submit],\n );\n\n return (\n <ShippingSimulatorContext value={contextValue}>\n <div {...props} className={className} data-fs-shipping-simulator=\"\">\n {children}\n </div>\n </ShippingSimulatorContext>\n );\n}\n\nexport function ShippingSimulatorForm({ className, children, ...props }: ShippingSimulatorFormProps) {\n const { submit } = useShippingSimulator();\n\n return (\n <form\n {...props}\n className={className}\n data-fs-shipping-simulator-form=\"\"\n onSubmit={(event) => {\n event.preventDefault();\n submit();\n }}\n >\n {children}\n </form>\n );\n}\n\nexport function ShippingSimulatorInput({\n className,\n placeholder,\n 'aria-label': ariaLabel,\n format = false,\n ...props\n}: ShippingSimulatorInputProps) {\n const { postalCode, setPostalCode } = useShippingSimulator();\n const intl = useIntl();\n const displayValue = format ? formatPostalCode(postalCode) : postalCode;\n\n return (\n <input\n {...props}\n aria-label={ariaLabel ?? intl.formatMessage({ id: 'fs/shipping.postal-code.aria-label' })}\n className={className}\n data-fs-shipping-simulator-input=\"\"\n type=\"text\"\n value={displayValue}\n onChange={(event) => setPostalCode(normalizePostalCode(event.target.value))}\n placeholder={placeholder ?? intl.formatMessage({ id: 'fs/shipping.postal-code.placeholder' })}\n pattern=\"\\d{5}-?\\d{3}\"\n maxLength={9}\n inputMode=\"numeric\"\n required\n />\n );\n}\n\nexport function ShippingSimulatorSubmit({ className, children, disabled, ...props }: ShippingSimulatorSubmitProps) {\n const { status } = useShippingSimulator();\n const isLoading = status === 'loading';\n\n return (\n <button\n {...props}\n type=\"submit\"\n className={className}\n data-fs-shipping-simulator-submit=\"\"\n disabled={disabled || isLoading}\n aria-busy={isLoading}\n >\n {children}\n </button>\n );\n}\n\nexport function ShippingSimulatorLoading({ className, children, ...props }: ShippingSimulatorLoadingProps) {\n const { status } = useShippingSimulator();\n if (status !== 'loading') return null;\n\n return (\n <output {...props} aria-live=\"polite\" className={className} data-fs-shipping-simulator-loading=\"\">\n {children ?? <FormattedMessage id=\"fs/shipping.calculating\" />}\n </output>\n );\n}\n\nexport function ShippingSimulatorError({ className, children, ...props }: ShippingSimulatorErrorProps) {\n const { userErrors } = useShippingSimulator();\n const [firstError] = userErrors;\n if (!firstError) return null;\n\n return (\n <div {...props} role=\"alert\" className={className} data-fs-shipping-simulator-error=\"\">\n {children ?? firstError.message}\n </div>\n );\n}\n\nexport function ShippingSimulatorOptions({\n sortBy,\n maxOptions,\n className,\n children,\n ...props\n}: ShippingSimulatorOptionsProps) {\n const { shippingOptions } = useShippingSimulator();\n\n const visibleOptions = useMemo(() => {\n if (!shippingOptions) return null;\n const sorted = sortBy ? sortShippingOptions(shippingOptions, sortBy) : shippingOptions;\n return maxOptions && maxOptions > 0 ? sorted.slice(0, maxOptions) : sorted;\n }, [shippingOptions, sortBy, maxOptions]);\n\n if (!visibleOptions || visibleOptions.length === 0) return null;\n\n return (\n <ul {...props} className={className} data-fs-shipping-simulator-options=\"\">\n {visibleOptions.map((option) => (\n <OptionItemContext key={option.id} value={option}>\n {children}\n </OptionItemContext>\n ))}\n </ul>\n );\n}\n\nexport function ShippingSimulatorOption({ className, children, ...props }: ShippingSimulatorOptionProps) {\n const option = useOptionItem();\n\n return (\n <li\n {...props}\n className={className}\n data-fs-shipping-simulator-option=\"\"\n data-fs-shipping-simulator-option-channel={option.channel}\n >\n {children}\n </li>\n );\n}\n\nexport function ShippingSimulatorOptionName({ className, children, ...props }: ShippingSimulatorOptionNameProps) {\n const option = useOptionItem();\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-name=\"\">\n {children ?? option.name}\n </span>\n );\n}\n\nexport function ShippingSimulatorOptionEstimate({\n className,\n children,\n ...props\n}: ShippingSimulatorOptionEstimateProps) {\n const option = useOptionItem();\n const intl = useIntl();\n const { value, unit } = option.shippingEstimate;\n const { id, variable } = ESTIMATE_MESSAGE[unit];\n const text =\n value === 0\n ? intl.formatMessage({ id: 'fs/shipping.estimate.today' })\n : intl.formatMessage({ id }, { [variable]: value });\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-estimate=\"\">\n {children ?? text}\n </span>\n );\n}\n\nfunction isFreeAmount(amount: unknown): boolean {\n return isFiniteAmount(amount) && Number(amount) === 0;\n}\n\nexport function ShippingSimulatorOptionPrice({ className, children, ...props }: ShippingSimulatorOptionPriceProps) {\n const option = useOptionItem();\n const intl = useIntl();\n const { locale, currency } = useStorefrontContext();\n const text = isFreeAmount(option.price.amount)\n ? intl.formatMessage({ id: 'fs/shipping.free-price' })\n : formatPrice(Number(option.price.amount), locale, currency);\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-price=\"\">\n {children ?? text}\n </span>\n );\n}\n\nexport function ShippingSimulatorOptionFreeBadge({\n className,\n children,\n ...props\n}: ShippingSimulatorOptionFreeBadgeProps) {\n const option = useOptionItem();\n if (!isFreeAmount(option.price.amount)) return null;\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-free-badge=\"\">\n {children ?? <FormattedMessage id=\"fs/shipping.free-badge\" />}\n </span>\n );\n}\n\nexport function ShippingSimulatorEmpty({ className, children, ...props }: ShippingSimulatorEmptyProps) {\n const { shippingOptions, userErrors } = useShippingSimulator();\n // Idle (null) → nothing; error → nothing (Error owns it); options present → nothing.\n const simulatedEmpty = Array.isArray(shippingOptions) && shippingOptions.length === 0 && userErrors.length === 0;\n if (!simulatedEmpty) return null;\n\n return (\n <output {...props} aria-live=\"polite\" className={className} data-fs-shipping-simulator-empty=\"\">\n {children ?? <FormattedMessage id=\"fs/shipping.no-options\" />}\n </output>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Namespace export\n// ---------------------------------------------------------------------------\n\nexport const ShippingSimulator = {\n Root: ShippingSimulatorRoot,\n Form: ShippingSimulatorForm,\n Input: ShippingSimulatorInput,\n Submit: ShippingSimulatorSubmit,\n Loading: ShippingSimulatorLoading,\n Error: ShippingSimulatorError,\n Options: ShippingSimulatorOptions,\n Option: ShippingSimulatorOption,\n OptionName: ShippingSimulatorOptionName,\n OptionEstimate: ShippingSimulatorOptionEstimate,\n OptionPrice: ShippingSimulatorOptionPrice,\n OptionFreeBadge: ShippingSimulatorOptionFreeBadge,\n Empty: ShippingSimulatorEmpty,\n};\n\nexport const CartShippingSimulator = {\n Root: CartShippingSimulatorRoot,\n Form: ShippingSimulatorForm,\n Input: ShippingSimulatorInput,\n Submit: ShippingSimulatorSubmit,\n Loading: ShippingSimulatorLoading,\n Error: ShippingSimulatorError,\n Options: ShippingSimulatorOptions,\n Option: ShippingSimulatorOption,\n OptionName: ShippingSimulatorOptionName,\n OptionEstimate: ShippingSimulatorOptionEstimate,\n OptionPrice: ShippingSimulatorOptionPrice,\n OptionFreeBadge: ShippingSimulatorOptionFreeBadge,\n Empty: ShippingSimulatorEmpty,\n};\n"],"mappings":";;;;;;;;;;;;AAkBA,MAAM,WAAyB;;;;;;;;;;;;;;;;;AAqF/B,MAAM,mCAAmC,OAAO,+BAA+B;AA0D/E,MAAa,2BAA2B,cAEtC,gCAAgC;AAElC,MAAa,oBAAoB,cAAqC,IAAI;AAE1E,SAAS,uBAAsD;CAC7D,MAAM,MAAM,WAAW,wBAAwB;CAC/C,IAAI,QAAQ,kCACV,MAAM,IAAI,MAAM,yEAAyE;CAE3F,OAAO;AACT;AAEA,SAAS,gBAAgC;CACvC,MAAM,MAAM,WAAW,iBAAiB;CACxC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,kFAAkF;CAEpG,OAAO;AACT;AAMA,SAAS,YAAY,OAAe,QAAgB,UAA0B;CAC5E,OAAO,IAAI,KAAK,aAAa,QAAQ;EAAE,OAAO;EAAY;CAAS,CAAC,CAAC,CAAC,OAAO,KAAK;AACpF;AAiBA,MAAa,mBACX;CACE,eAAe;EAAE,IAAI;EAAyC,UAAU;CAAO;CAC/E,MAAM;EAAE,IAAI;EAAgC,UAAU;CAAO;CAC7D,OAAO;EAAE,IAAI;EAAiC,UAAU;CAAQ;CAChE,SAAS;EAAE,IAAI;EAAmC,UAAU;CAAU;AACxE;AAIF,MAAM,wBAA8D;CAClE,SAAS;CACT,OAAO;CACP,MAAM;CACN,eAAe;AACjB;AAEA,SAAS,oBAAoB,SAAoC,QAAgD;CAC/G,MAAM,OACJ,WAAW,WACN,WAA2B,OAAO,OAAO,MAAM,MAAM,KACrD,WAA2B,OAAO,iBAAiB,QAAQ,sBAAsB,OAAO,iBAAiB;CAChH,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC;AACtD;AAEA,SAAS,oB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EAAM,GAAI;EAAkB;EAAW,gDAA6C;EACjF,UAAA,YAAY,oBAAC,kBAAD,EAAkB,IAAG,yBAA0B,CAAA;CACxD,CAAA;AAEV;AAEA,SAAgB,uBAAuB,EAAE,WAAW,UAAU,GAAG,SAAsC;CACrG,MAAM,EAAE,iBAAiB,eAAe,qBAAqB;CAG7D,IAAI,EADmB,MAAM,QAAQ,eAAe,KAAK,gBAAgB,WAAW,KAAK,WAAW,WAAW,IAC1F,OAAO;CAE5B,OACE,oBAAC,UAAD;EAAQ,GAAI;EAAO,aAAU;EAAoB;EAAW,oCAAiC;EAC1F,UAAA,YAAY,oBAAC,kBAAD,EAAkB,IAAG,yBAA0B,CAAA;CACtD,CAAA;AAEZ;AAMA,MAAa,oBAAoB;CAC/B,MAAM;CACN,MAAM;CACN,OAAO;CACP,QAAQ;CACR,SAAS;CACT,OAAO;CACP,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,gBAAgB;CAChB,aAAa;CACb,iBAAiB;CACjB,OAAO;AACT;AAEA,MAAa,wBAAwB;CACnC,MAAM;CACN,MAAM;CACN,OAAO;CACP,QAAQ;CACR,SAAS;CACT,OAAO;CACP,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,gBAAgB;CAChB,aAAa;CACb,iBAAiB;CACjB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"shipping-simulator.js","names":[],"sources":["../../../src/matter/shipping-simulator/shipping-simulator.tsx"],"sourcesContent":["'use client';\n\nimport {\n type ContentValue,\n defineComponent,\n defineContentType,\n type MessageFieldName,\n type MessageLocaleProp,\n} from '@vtex/fs-core';\nimport type { ComponentPropsWithRef, ReactElement } from 'react';\nimport { createContext, createElement, useCallback, useContext, useMemo, useRef, useState } from 'react';\nimport { useStorefrontContext } from '../../sdk/context/storefront-context.js';\nimport { useDataOverride } from '../../sdk/data/data-override-context.js';\nimport { formatErrorCode } from '../../sdk/i18n/format-error-code.js';\nimport { useMessageFormatter } from '../../sdk/i18n/use-message-formatter.js';\nimport type { CartShippingSimulateInput } from '../../sdk/shipping/cart-operations.js';\nimport type { ShippingSimulateInput } from '../../sdk/shipping/operations.js';\nimport { useCartShippingSimulation } from '../../sdk/shipping/use-cart-shipping-simulation.js';\nimport { useShippingSimulation } from '../../sdk/shipping/use-shipping-simulation.js';\nimport { isFiniteAmount } from '../cart/cart.js';\nimport type { OrderPlacedDeliveryGroupContent } from '../order-placed/order-placed-deliveries.js';\n\n// ---------------------------------------------------------------------------\n// GraphQL Fragment\n// ---------------------------------------------------------------------------\n\nconst fragment = /* GraphQL */ `\n fragment ShippingSimulatorData on Query {\n productBySlug(slug: $slug) {\n variants(first: 1) {\n edges {\n node {\n id\n sellers {\n id\n isDefault\n }\n }\n }\n }\n }\n }\n`;\n\n// ---------------------------------------------------------------------------\n// Raw data types (shape of the fragment result)\n// ---------------------------------------------------------------------------\n\ntype RawShippingSimulatorData = {\n variants: {\n edges: Array<{\n node: {\n id: string;\n sellers: Array<{\n id: string;\n isDefault: boolean;\n }>;\n };\n }>;\n };\n};\n\n// ---------------------------------------------------------------------------\n// Domain types (mirror the shippingSimulation GraphQL contract)\n// ---------------------------------------------------------------------------\n\ntype MoneyValue = { amount: string; currencyCode: string };\n\ntype DeliveryChannel = 'DELIVERY' | 'PICKUP' | 'UNKNOWN';\n\nexport type ShippingEstimateUnit = 'BUSINESS_DAYS' | 'DAYS' | 'HOURS' | 'MINUTES';\n\ntype ShippingEstimate = { value: number; unit: ShippingEstimateUnit };\n\n// Exported alongside `ShippingSimulatorContextValue` so `DeliveryOptionsRoot`\n// (matter/delivery-options) can type against the exact shape the reused leaves expect, with no\n// structural duplication (docs/storefront-core/reference-free-particle-model.md § Read side — state).\nexport type ShippingOption = {\n id: string;\n name: string;\n channel: DeliveryChannel;\n shippingEstimate: ShippingEstimate;\n price: MoneyValue;\n listPrice: MoneyValue;\n};\n\n// `CALCULATION_FAILED` is client-side: a Root sets it when `onSimulate` rejects, with an empty `message`.\ntype ShippingSimulateErrorCode = 'INVALID_POSTAL_CODE' | 'UNKNOWN' | 'CALCULATION_FAILED';\n\n// Exported with `ShippingSimulationPayload` so the `./client` entry can name the simulate callback's\n// whole contract — the SDK hooks return it and a store writing its own `onSimulate` has to name it.\nexport type ShippingSimulateError = {\n code: ShippingSimulateErrorCode;\n message: string;\n};\n\nexport type ShippingSimulationPayload = {\n shippingOptions: ShippingOption[] | null;\n userErrors: ShippingSimulateError[];\n};\n\ntype Status = 'idle' | 'loading' | 'success' | 'error';\n\nexport type ShippingSimulatorContextValue = {\n postalCode: string;\n setPostalCode: (value: string) => void;\n status: Status;\n shippingOptions: ShippingOption[] | null;\n userErrors: ShippingSimulateError[];\n submit: () => void;\n};\n\nconst SHIPPING_SIMULATOR_CONTEXT_UNSET = Symbol('ShippingSimulatorContextUnset');\n\nexport type ShippingSimulatorRootProps = ComponentPropsWithRef<'div'> & {\n country?: string;\n quantity?: number;\n variantId?: string;\n seller?: string;\n $data?: RawShippingSimulatorData | null;\n shippingOptions?: ShippingOption[];\n userErrors?: ShippingSimulateError[];\n onSimulate?: (input: ShippingSimulateInput) => Promise<ShippingSimulationPayload>;\n onResult?: (result: ShippingSimulationPayload) => void;\n};\n\nexport type CartShippingSimulatorRootProps = ComponentPropsWithRef<'div'> & {\n country?: string;\n shippingOptions?: ShippingOption[];\n userErrors?: ShippingSimulateError[];\n onSimulate?: (input: CartShippingSimulateInput) => Promise<ShippingSimulationPayload>;\n onResult?: (result: ShippingSimulationPayload) => void;\n};\n\nexport type ShippingSimulatorFormProps = ComponentPropsWithRef<'form'>;\n\nexport type ShippingSimulatorInputProps = Omit<\n ComponentPropsWithRef<'input'>,\n 'value' | 'onChange' | 'placeholder' | 'aria-label'\n> &\n MessageLocaleProp & {\n format?: boolean;\n $content?: ContentValue<typeof ShippingSimulatorInputContent>;\n };\n\nexport type ShippingSimulatorSubmitProps = ComponentPropsWithRef<'button'>;\n\nexport type ShippingSimulatorLoadingProps = ComponentPropsWithRef<'output'> &\n MessageLocaleProp & {\n $content?: ContentValue<typeof ShippingSimulatorLoadingContent>;\n };\n\nexport type ShippingSimulatorErrorProps = ComponentPropsWithRef<'div'> &\n MessageLocaleProp & {\n $content?: ContentValue<typeof ShippingSimulatorErrorContent>;\n };\n\nexport type ShippingSimulatorOptionsProps = ComponentPropsWithRef<'ul'> & {\n sortBy?: 'price' | 'estimate';\n maxOptions?: number;\n};\n\n/** An option under `ShippingSimulatorOptions` renders an `li`. */\nexport type ShippingSimulatorOptionProps = ComponentPropsWithRef<'li'>;\n\n/** An option outside `ShippingSimulatorOptions`, such as under `DeliveryOptionsRoot`, renders a `div`. */\nexport type ShippingSimulatorOptionBlockProps = ComponentPropsWithRef<'div'>;\n\nexport type ShippingSimulatorOptionNameProps = ComponentPropsWithRef<'span'>;\n\nexport type ShippingSimulatorOptionEstimateProps = ComponentPropsWithRef<'span'> &\n MessageLocaleProp & {\n $content?: ContentValue<typeof ShippingSimulatorOptionEstimateContent>;\n };\n\nexport type ShippingSimulatorOptionPriceProps = ComponentPropsWithRef<'span'> &\n MessageLocaleProp & {\n $content?: ContentValue<typeof ShippingSimulatorOptionPriceContent>;\n };\n\nexport type ShippingSimulatorOptionFreeBadgeProps = ComponentPropsWithRef<'span'> &\n MessageLocaleProp & {\n $content?: ContentValue<typeof ShippingSimulatorOptionFreeBadgeContent>;\n };\n\nexport type ShippingSimulatorEmptyProps = ComponentPropsWithRef<'output'> &\n MessageLocaleProp & {\n $content?: ContentValue<typeof ShippingSimulatorEmptyContent>;\n };\n\n/** An estimate sentence field, declared alike by the simulator's and the placed order's content types. */\ntype EstimateField = MessageFieldName<typeof ShippingSimulatorOptionEstimateContent> &\n MessageFieldName<typeof OrderPlacedDeliveryGroupContent>;\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\n// Exported so `DeliveryOptionsRoot` can become a third provider by importing these same Context\n// objects directly (context matching is by identity, not shape). The two hooks below stay\n// module-private — providers need the objects, not the consumer API (Decision 2).\nexport const ShippingSimulatorContext = createContext<\n ShippingSimulatorContextValue | typeof SHIPPING_SIMULATOR_CONTEXT_UNSET\n>(SHIPPING_SIMULATOR_CONTEXT_UNSET);\n\nexport const OptionItemContext = createContext<ShippingOption | null>(null);\n\n/**\n * True under `ShippingSimulatorOptions`, whose `ul` makes each option an `li`. Where another root\n * (a radio group) provides the option, an `li` has no list around it, so the option is a `div`.\n * Module-private: the roots that reuse the option leaves do not provide it.\n */\nconst OptionListContext = createContext(false);\n\nfunction useShippingSimulator(): ShippingSimulatorContextValue {\n const ctx = useContext(ShippingSimulatorContext);\n if (ctx === SHIPPING_SIMULATOR_CONTEXT_UNSET) {\n throw new Error('ShippingSimulator components must be used inside ShippingSimulatorRoot.');\n }\n return ctx;\n}\n\nfunction useOptionItem(): ShippingOption {\n const ctx = useContext(OptionItemContext);\n if (!ctx) {\n throw new Error('ShippingSimulatorOption components must be used inside ShippingSimulatorOptions.');\n }\n return ctx;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction formatPrice(value: number, locale: string, currency: string): string {\n return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(value);\n}\n\n// Each unit's whole sentence, and the variable that sentence names.\n//\n// Whole sentence, not a unit fragment interpolated into a wrapper: interpolating a translated\n// fragment into a translated wrapper freezes \"preposition + noun\" order into every language, and\n// hands the translator `em {estimate}` with no way to agree preposition, article or case with a noun\n// they cannot see. The variable is named after what it counts (`{days}`, `{hours}`) rather than a\n// generic `{count}`, for the same reason.\n//\n// A `Record` and not a `switch` with a default: a fifth unit arriving in the GraphQL schema is a\n// type error here, not a silent fallback to the wrong sentence.\n//\n// `field` is a message field of both estimate content types. `variable` is the union of the names\n// those sentences read, never `string`; the parity assertion in the test file checks that each field's\n// `messageArguments` declares it.\nexport const ESTIMATE_MESSAGE: Record<\n ShippingEstimateUnit,\n { field: Exclude<EstimateField, 'today'>; variable: 'days' | 'hours' | 'minutes' }\n> = {\n BUSINESS_DAYS: { field: 'inBusinessDays', variable: 'days' },\n DAYS: { field: 'inDays', variable: 'days' },\n HOURS: { field: 'inHours', variable: 'hours' },\n MINUTES: { field: 'inMinutes', variable: 'minutes' },\n};\n\n// Business days weigh the same as calendar days: exact wall-clock conversion is unknowable and\n// the ranking only needs a consistent order.\nconst ESTIMATE_UNIT_MINUTES: Record<ShippingEstimateUnit, number> = {\n MINUTES: 1,\n HOURS: 60,\n DAYS: 1440,\n BUSINESS_DAYS: 1440,\n};\n\nfunction sortShippingOptions(options: readonly ShippingOption[], sortBy: 'price' | 'estimate'): ShippingOption[] {\n const rank =\n sortBy === 'price'\n ? (option: ShippingOption) => Number(option.price.amount)\n : (option: ShippingOption) => option.shippingEstimate.value * ESTIMATE_UNIT_MINUTES[option.shippingEstimate.unit];\n return [...options].sort((a, b) => rank(a) - rank(b));\n}\n\nfunction normalizePostalCode(value: string): string {\n return value.replace(/\\D/g, '').slice(0, 8);\n}\n\nfunction formatPostalCode(value: string): string {\n const digits = normalizePostalCode(value);\n return digits.length > 5 ? `${digits.slice(0, 5)}-${digits.slice(5)}` : digits;\n}\n\nfunction extractProductFromData(data: RawShippingSimulatorData | null | undefined): {\n variantId: string | null;\n seller: string | null;\n} {\n if (!data) return { variantId: null, seller: null };\n const edge = data.variants?.edges?.[0];\n if (!edge) return { variantId: null, seller: null };\n const { id, sellers } = edge.node;\n const defaultSeller = sellers?.find((s) => s.isDefault) ?? sellers?.[0];\n return { variantId: id ?? null, seller: defaultSeller?.id ?? null };\n}\n\n// ---------------------------------------------------------------------------\n// Definitions\n// ---------------------------------------------------------------------------\n\nexport const ShippingSimulatorRootDefinition = defineComponent<ShippingSimulatorRootProps>({\n name: 'ShippingSimulatorRoot',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorRoot,\n fragment,\n fetchStrategy: 'reactive',\n editor: { label: 'Shipping Simulator', category: 'commerce' },\n schema: {\n country: { type: 'string', default: 'BRA', label: 'Country (ISO-3)' },\n quantity: { type: 'number', default: 1, label: 'Quantity' },\n },\n providesContext: 'shipping-simulator',\n guideline:\n 'Root container for the PDP shipping simulator: a shopper types a postal code and sees a shipping preview for ONE product on a product detail page. Backed by shippingSimulation and a product fragment (productBySlug(slug: $slug)), so it must live on a page with a $slug variable. Use CartShippingSimulatorRoot instead for a whole-cart calculator in the cart/mini-cart. All other ShippingSimulator components must be descendants of this one.',\n});\n\nexport const CartShippingSimulatorRootDefinition = defineComponent<CartShippingSimulatorRootProps>({\n name: 'CartShippingSimulatorRoot',\n importPath: '@vtex/faststore/components',\n component: CartShippingSimulatorRoot,\n editor: { label: 'Cart Shipping Simulator', category: 'commerce' },\n schema: {\n country: { type: 'string', default: 'BRA', label: 'Country (ISO-3)' },\n },\n providesContext: 'shipping-simulator',\n guideline:\n 'Root container for the cart/mini-cart shipping calculator: the shopper types a postal code and sees the shipping options for the WHOLE cart. Backed by cartShippingSimulation (cart sourced server-side via x-order-form-id); needs no CartRoot ancestor and no product fragment. Use ShippingSimulatorRoot instead for a single-product shipping preview on a PDP. All other CartShippingSimulator components must be descendants of this one.',\n});\n\nexport const ShippingSimulatorFormDefinition = defineComponent<ShippingSimulatorFormProps>({\n name: 'ShippingSimulatorForm',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorForm,\n editor: { label: 'Shipping Simulator Form', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Form wrapper that holds ShippingSimulatorInput and ShippingSimulatorSubmit; must be a descendant of ShippingSimulatorRoot.',\n});\n\nexport const ShippingSimulatorInputContent = defineContentType({\n id: 'shipping-simulator-input',\n title: 'Shipping Simulator Input',\n description: \"The postal code input's accessible name and placeholder.\",\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n ariaLabel: { type: 'string', title: 'Accessible name', format: 'icu-message', messageSource: 'Postal code' },\n placeholder: {\n type: 'string',\n title: 'Placeholder',\n format: 'icu-message',\n messageSource: 'Enter your postal code',\n },\n },\n },\n});\n\nexport const ShippingSimulatorInputDefinition = defineComponent<ShippingSimulatorInputProps>({\n name: 'ShippingSimulatorInput',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorInput,\n content: ShippingSimulatorInputContent,\n editor: { label: 'Shipping Simulator Input', category: 'action' },\n schema: {\n format: { type: 'boolean', default: false, label: 'Auto-format CEP (00000-000)' },\n },\n requiresContext: 'shipping-simulator',\n guideline:\n 'Postal-code text input; enable `format` to auto-hyphenate the CEP as the user types (e.g. 01310-100). Its $content holds the ariaLabel and placeholder. Must be a descendant of ShippingSimulatorForm.',\n});\n\nexport const ShippingSimulatorSubmitDefinition = defineComponent<ShippingSimulatorSubmitProps>({\n name: 'ShippingSimulatorSubmit',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorSubmit,\n editor: { label: 'Shipping Simulator Submit', category: 'action' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline: 'Submit button for the postal-code form; must be a descendant of ShippingSimulatorForm.',\n});\n\nexport const ShippingSimulatorLoadingContent = defineContentType({\n id: 'shipping-simulator-loading',\n title: 'Shipping Simulator Loading',\n description: 'Text shown while a simulation runs.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n text: { type: 'string', title: 'Loading text', format: 'icu-message', messageSource: 'Calculating…' },\n },\n },\n});\n\nexport const ShippingSimulatorLoadingDefinition = defineComponent<ShippingSimulatorLoadingProps>({\n name: 'ShippingSimulatorLoading',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorLoading,\n content: ShippingSimulatorLoadingContent,\n editor: { label: 'Shipping Simulator Loading', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Loading indicator shown while a simulation is in progress; must be a descendant of ShippingSimulatorRoot.',\n});\n\nexport const ShippingSimulatorErrorContent = defineContentType({\n id: 'shipping-simulator-error',\n title: 'Shipping Simulator Error',\n description: 'Messages shown when the shipping cannot be calculated, one per error code.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n calculationFailed: {\n type: 'string',\n title: 'Calculation failed message',\n description: 'Shown when a store-supplied simulation callback fails.',\n format: 'icu-message',\n messageSource: 'Unable to calculate shipping. Try again.',\n },\n invalidPostalCode: {\n type: 'string',\n title: 'Invalid postal code',\n description: 'Shown when the postal code is not found or is rejected.',\n format: 'icu-message',\n messageSource: 'Enter a valid postal code.',\n },\n genericErrorMessage: {\n type: 'string',\n title: 'Generic failure message',\n description: 'Shown for a network failure and for every refusal the shopper cannot act on.',\n format: 'icu-message',\n messageSource: 'Unable to calculate shipping. Try again.',\n },\n },\n },\n});\n\nexport const ShippingSimulatorErrorDefinition = defineComponent<ShippingSimulatorErrorProps>({\n name: 'ShippingSimulatorError',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorError,\n content: ShippingSimulatorErrorContent,\n editor: { label: 'Shipping Simulator Error', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Error banner shown when the simulation returns errors; renders nothing otherwise. Words each error code from its $content: invalidPostalCode for a rejected postal code, genericErrorMessage for a network failure and every other refusal, calculationFailed for a failed simulation callback. An unknown code shows genericErrorMessage; authored children replace the message. Must be a descendant of ShippingSimulatorRoot.',\n});\n\nexport const ShippingSimulatorOptionsDefinition = defineComponent<ShippingSimulatorOptionsProps>({\n name: 'ShippingSimulatorOptions',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptions,\n editor: { label: 'Shipping Simulator Options', category: 'commerce' },\n schema: {\n sortBy: { type: ['price', 'estimate'] as const, label: 'Sort by' },\n maxOptions: { type: 'number', label: 'Max options' },\n },\n requiresContext: 'shipping-simulator',\n providesContext: 'shipping-simulator-option',\n guideline:\n 'List that renders one ShippingSimulatorOption per available shipping option; must be a descendant of a shipping-simulator Root (PDP or cart). Renders every option in API order by default; set sortBy (\"price\" = cheapest first, \"estimate\" = fastest first) and maxOptions to cap the list — sortBy=\"price\" with maxOptions=1 shows only the cheapest option. See shipping-simulator.md.',\n});\n\nexport const ShippingSimulatorOptionDefinition = defineComponent<ShippingSimulatorOptionProps>({\n name: 'ShippingSimulatorOption',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOption,\n editor: { label: 'Shipping Simulator Option', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Container for a single shipping option row; holds ShippingSimulatorOptionName, ShippingSimulatorOptionEstimate, and ShippingSimulatorOptionPrice. Must be a descendant of ShippingSimulatorOptions.',\n});\n\nexport const ShippingSimulatorOptionNameDefinition = defineComponent<ShippingSimulatorOptionNameProps>({\n name: 'ShippingSimulatorOptionName',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionName,\n editor: { label: 'Option Name', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Displays the shipping option name (e.g. \"Entrega Normal\"); must be a descendant of ShippingSimulatorOption.',\n});\n\nexport const ShippingSimulatorOptionEstimateContent = defineContentType({\n id: 'shipping-simulator-option-estimate',\n title: 'Shipping Simulator Option Estimate',\n description: 'Delivery estimate sentences, one per unit.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n today: { type: 'string', title: 'Arrives today', format: 'icu-message', messageSource: 'arrives today' },\n inBusinessDays: {\n type: 'string',\n title: 'In business days',\n format: 'icu-message',\n messageSource: 'in {days, plural, one {# business day} other {# business days}}',\n messageArguments: { type: 'object', properties: { days: { type: 'integer' } } },\n messageExample: { days: 3 },\n },\n inDays: {\n type: 'string',\n title: 'In days',\n format: 'icu-message',\n messageSource: 'in {days, plural, one {# day} other {# days}}',\n messageArguments: { type: 'object', properties: { days: { type: 'integer' } } },\n messageExample: { days: 3 },\n },\n inHours: {\n type: 'string',\n title: 'In hours',\n format: 'icu-message',\n messageSource: 'in {hours, plural, one {# hour} other {# hours}}',\n messageArguments: { type: 'object', properties: { hours: { type: 'integer' } } },\n messageExample: { hours: 4 },\n },\n inMinutes: {\n type: 'string',\n title: 'In minutes',\n format: 'icu-message',\n messageSource: 'in {minutes, plural, one {# minute} other {# minutes}}',\n messageArguments: { type: 'object', properties: { minutes: { type: 'integer' } } },\n messageExample: { minutes: 30 },\n },\n },\n },\n});\n\nexport const ShippingSimulatorOptionEstimateDefinition = defineComponent<ShippingSimulatorOptionEstimateProps>({\n name: 'ShippingSimulatorOptionEstimate',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionEstimate,\n content: ShippingSimulatorOptionEstimateContent,\n editor: { label: 'Option Estimate', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Displays the delivery estimate in the active locale, one whole sentence per unit from its $content; a zero-value estimate (any unit) reads as an arrival-today message instead, since \"chega em 0 dias úteis\" reads wrong. Must be a descendant of ShippingSimulatorOption.',\n});\n\nexport const ShippingSimulatorOptionPriceContent = defineContentType({\n id: 'shipping-simulator-option-price',\n title: 'Shipping Simulator Option Price',\n description: 'Text shown instead of a zero shipping price.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n freeLabel: { type: 'string', title: 'Free price label', format: 'icu-message', messageSource: 'Free' },\n },\n },\n});\n\nexport const ShippingSimulatorOptionPriceDefinition = defineComponent<ShippingSimulatorOptionPriceProps>({\n name: 'ShippingSimulatorOptionPrice',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionPrice,\n content: ShippingSimulatorOptionPriceContent,\n editor: { label: 'Option Price', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Displays the shipping price, showing its $content.freeLabel when the amount is zero; must be a descendant of ShippingSimulatorOption.',\n});\n\nexport const ShippingSimulatorOptionFreeBadgeContent = defineContentType({\n id: 'shipping-simulator-option-free-badge',\n title: 'Shipping Simulator Option Free Badge',\n description: 'Badge text of a free shipping option.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n text: { type: 'string', title: 'Badge text', format: 'icu-message', messageSource: 'Free shipping' },\n },\n },\n});\n\nexport const ShippingSimulatorOptionFreeBadgeDefinition = defineComponent<ShippingSimulatorOptionFreeBadgeProps>({\n name: 'ShippingSimulatorOptionFreeBadge',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorOptionFreeBadge,\n content: ShippingSimulatorOptionFreeBadgeContent,\n editor: { label: 'Option Free Badge', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator-option',\n guideline:\n 'Badge shown only when the current option price is zero (free shipping); renders nothing otherwise. Must be a descendant of ShippingSimulatorOption. Orthogonal to the free-price replacement text owned by ShippingSimulatorOptionPrice.',\n});\n\nexport const ShippingSimulatorEmptyContent = defineContentType({\n id: 'shipping-simulator-empty',\n title: 'Shipping Simulator Empty',\n description: 'Message shown when a simulation returns no shipping options.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n text: {\n type: 'string',\n title: 'Empty message',\n format: 'icu-message',\n messageSource: 'No delivery options available for this address.',\n },\n },\n },\n});\n\nexport const ShippingSimulatorEmptyDefinition = defineComponent<ShippingSimulatorEmptyProps>({\n name: 'ShippingSimulatorEmpty',\n importPath: '@vtex/faststore/components',\n component: ShippingSimulatorEmpty,\n content: ShippingSimulatorEmptyContent,\n editor: { label: 'Shipping Simulator Empty', category: 'commerce' },\n schema: {},\n requiresContext: 'shipping-simulator',\n guideline:\n 'Message shown when a simulation ran and returned no shipping options (e.g. no carrier common to the whole cart). Renders nothing before the first submit and nothing when options or an error are present. The copy is its $content.text; pass children to override. Must be a descendant of a shipping-simulator Root.',\n});\n\n// ---------------------------------------------------------------------------\n// Implementations\n// ---------------------------------------------------------------------------\n\nexport function ShippingSimulatorRoot({\n country = 'BRA',\n quantity = 1,\n variantId: variantIdProp,\n seller: sellerProp,\n $data: $dataProp,\n shippingOptions: shippingOptionsProp,\n userErrors: userErrorsProp,\n onSimulate: onSimulateProp,\n onResult,\n className,\n children,\n ...props\n}: ShippingSimulatorRootProps) {\n const defaultSimulate = useShippingSimulation();\n const onSimulate = onSimulateProp ?? defaultSimulate;\n\n const $data = useDataOverride($dataProp);\n const extracted = extractProductFromData($data);\n const variantId = variantIdProp ?? extracted.variantId;\n const seller = sellerProp ?? extracted.seller;\n\n const [postalCode, setPostalCode] = useState('');\n const [status, setStatus] = useState<Status>(() => {\n if (userErrorsProp?.length) return 'error';\n if (shippingOptionsProp) return 'success';\n return 'idle';\n });\n const [shippingOptions, setShippingOptions] = useState<ShippingOption[] | null>(shippingOptionsProp ?? null);\n const [userErrors, setUserErrors] = useState<ShippingSimulateError[]>(userErrorsProp ?? []);\n\n const submissionToken = useRef(0);\n\n const submit = useCallback(() => {\n if (!onSimulate || !variantId || !seller) return;\n\n const normalizedCep = normalizePostalCode(postalCode);\n if (normalizedCep.length !== 8) return;\n\n const token = ++submissionToken.current;\n setStatus('loading');\n setShippingOptions(null);\n setUserErrors([]);\n\n onSimulate({ postalCode: normalizedCep, country, variantId, quantity, seller })\n .then((result) => {\n if (submissionToken.current !== token) return;\n setShippingOptions(result.shippingOptions);\n setUserErrors(result.userErrors);\n setStatus(result.userErrors.length > 0 ? 'error' : 'success');\n onResult?.(result);\n })\n .catch(() => {\n if (submissionToken.current !== token) return;\n // `ShippingSimulatorError` words this code from its own `$content`.\n const fallback: ShippingSimulateError = { code: 'CALCULATION_FAILED', message: '' };\n setShippingOptions(null);\n setUserErrors([fallback]);\n setStatus('error');\n onResult?.({ shippingOptions: null, userErrors: [fallback] });\n });\n }, [country, onResult, onSimulate, postalCode, quantity, seller, variantId]);\n\n const contextValue = useMemo<ShippingSimulatorContextValue>(\n () => ({\n postalCode,\n setPostalCode,\n status,\n shippingOptions,\n userErrors,\n submit,\n }),\n [postalCode, status, shippingOptions, userErrors, submit],\n );\n\n return (\n <ShippingSimulatorContext value={contextValue}>\n <div {...props} className={className} data-fs-shipping-simulator=\"\">\n {children}\n </div>\n </ShippingSimulatorContext>\n );\n}\n\nexport function CartShippingSimulatorRoot({\n country = 'BRA',\n shippingOptions: shippingOptionsProp,\n userErrors: userErrorsProp,\n onSimulate: onSimulateProp,\n onResult,\n className,\n children,\n ...props\n}: CartShippingSimulatorRootProps) {\n const defaultSimulate = useCartShippingSimulation();\n const onSimulate = onSimulateProp ?? defaultSimulate;\n\n const [postalCode, setPostalCode] = useState('');\n const [status, setStatus] = useState<Status>(() => {\n if (userErrorsProp?.length) return 'error';\n if (shippingOptionsProp) return 'success';\n return 'idle';\n });\n const [shippingOptions, setShippingOptions] = useState<ShippingOption[] | null>(shippingOptionsProp ?? null);\n const [userErrors, setUserErrors] = useState<ShippingSimulateError[]>(userErrorsProp ?? []);\n\n const submissionToken = useRef(0);\n\n const submit = useCallback(() => {\n const normalizedCep = normalizePostalCode(postalCode);\n if (normalizedCep.length !== 8) return;\n\n const token = ++submissionToken.current;\n setStatus('loading');\n setShippingOptions(null);\n setUserErrors([]);\n\n onSimulate({ postalCode: normalizedCep, country })\n .then((result) => {\n if (submissionToken.current !== token) return;\n setShippingOptions(result.shippingOptions);\n setUserErrors(result.userErrors);\n setStatus(result.userErrors.length > 0 ? 'error' : 'success');\n onResult?.(result);\n })\n .catch(() => {\n if (submissionToken.current !== token) return;\n // `ShippingSimulatorError` words this code from its own `$content`.\n const fallback: ShippingSimulateError = { code: 'CALCULATION_FAILED', message: '' };\n setShippingOptions(null);\n setUserErrors([fallback]);\n setStatus('error');\n onResult?.({ shippingOptions: null, userErrors: [fallback] });\n });\n }, [country, onResult, onSimulate, postalCode]);\n\n const contextValue = useMemo<ShippingSimulatorContextValue>(\n () => ({\n postalCode,\n setPostalCode,\n status,\n shippingOptions,\n userErrors,\n submit,\n }),\n [postalCode, status, shippingOptions, userErrors, submit],\n );\n\n return (\n <ShippingSimulatorContext value={contextValue}>\n <div {...props} className={className} data-fs-shipping-simulator=\"\">\n {children}\n </div>\n </ShippingSimulatorContext>\n );\n}\n\nexport function ShippingSimulatorForm({ className, children, ...props }: ShippingSimulatorFormProps) {\n const { submit } = useShippingSimulator();\n\n return (\n <form\n {...props}\n className={className}\n data-fs-shipping-simulator-form=\"\"\n onSubmit={(event) => {\n event.preventDefault();\n submit();\n }}\n >\n {children}\n </form>\n );\n}\n\nexport function ShippingSimulatorInput({\n $content,\n $locale,\n className,\n format = false,\n ...props\n}: ShippingSimulatorInputProps) {\n const { postalCode, setPostalCode } = useShippingSimulator();\n const messages = useMessageFormatter(ShippingSimulatorInputContent, $content);\n const displayValue = format ? formatPostalCode(postalCode) : postalCode;\n\n return (\n <input\n {...props}\n aria-label={messages.format('ariaLabel')}\n className={className}\n data-fs-shipping-simulator-input=\"\"\n type=\"text\"\n value={displayValue}\n onChange={(event) => setPostalCode(normalizePostalCode(event.target.value))}\n placeholder={messages.format('placeholder')}\n pattern=\"\\d{5}-?\\d{3}\"\n maxLength={9}\n inputMode=\"numeric\"\n required\n />\n );\n}\n\nexport function ShippingSimulatorSubmit({ className, children, disabled, ...props }: ShippingSimulatorSubmitProps) {\n const { status } = useShippingSimulator();\n const isLoading = status === 'loading';\n\n return (\n <button\n {...props}\n type=\"submit\"\n className={className}\n data-fs-shipping-simulator-submit=\"\"\n disabled={disabled || isLoading}\n aria-busy={isLoading}\n >\n {children}\n </button>\n );\n}\n\nexport function ShippingSimulatorLoading({\n $content,\n $locale,\n className,\n children,\n ...props\n}: ShippingSimulatorLoadingProps) {\n const { status } = useShippingSimulator();\n const { format } = useMessageFormatter(ShippingSimulatorLoadingContent, $content);\n if (status !== 'loading') return null;\n\n return (\n <output {...props} aria-live=\"polite\" className={className} data-fs-shipping-simulator-loading=\"\">\n {children ?? format('text')}\n </output>\n );\n}\n\n/**\n * The message for each code a simulation can return. The default hooks collapse every server code but\n * `INVALID_POSTAL_CODE`, and every transport failure, into `UNKNOWN`.\n */\nexport const SHIPPING_SIMULATOR_ERROR_FIELDS = {\n INVALID_POSTAL_CODE: 'invalidPostalCode',\n UNKNOWN: 'genericErrorMessage',\n CALCULATION_FAILED: 'calculationFailed',\n} as const satisfies Record<ShippingSimulateErrorCode, MessageFieldName<typeof ShippingSimulatorErrorContent>>;\n\nexport function ShippingSimulatorError({\n $content,\n $locale,\n className,\n children,\n ...props\n}: ShippingSimulatorErrorProps) {\n const { userErrors } = useShippingSimulator();\n const { format } = useMessageFormatter(ShippingSimulatorErrorContent, $content);\n const [firstError] = userErrors;\n if (!firstError) return null;\n\n return (\n <div {...props} role=\"alert\" className={className} data-fs-shipping-simulator-error=\"\">\n {children ??\n formatErrorCode(\n ShippingSimulatorErrorContent,\n SHIPPING_SIMULATOR_ERROR_FIELDS,\n firstError,\n format,\n 'genericErrorMessage',\n )}\n </div>\n );\n}\n\nexport function ShippingSimulatorOptions({\n sortBy,\n maxOptions,\n className,\n children,\n ...props\n}: ShippingSimulatorOptionsProps) {\n const { shippingOptions } = useShippingSimulator();\n\n const visibleOptions = useMemo(() => {\n if (!shippingOptions) return null;\n const sorted = sortBy ? sortShippingOptions(shippingOptions, sortBy) : shippingOptions;\n return maxOptions && maxOptions > 0 ? sorted.slice(0, maxOptions) : sorted;\n }, [shippingOptions, sortBy, maxOptions]);\n\n if (!visibleOptions || visibleOptions.length === 0) return null;\n\n return (\n <ul {...props} className={className} data-fs-shipping-simulator-options=\"\">\n <OptionListContext value>\n {visibleOptions.map((option) => (\n <OptionItemContext key={option.id} value={option}>\n {children}\n </OptionItemContext>\n ))}\n </OptionListContext>\n </ul>\n );\n}\n\nexport function ShippingSimulatorOption(props: ShippingSimulatorOptionProps): ReactElement;\nexport function ShippingSimulatorOption(props: ShippingSimulatorOptionBlockProps): ReactElement;\n// Callers see the two overloads; the implementation takes either shape, so no cast is needed.\nexport function ShippingSimulatorOption({\n className,\n children,\n ...props\n}: ShippingSimulatorOptionProps | ShippingSimulatorOptionBlockProps): ReactElement {\n const option = useOptionItem();\n const inList = useContext(OptionListContext);\n\n return createElement(\n inList ? 'li' : 'div',\n {\n ...props,\n className,\n 'data-fs-shipping-simulator-option': '',\n 'data-fs-shipping-simulator-option-channel': option.channel,\n },\n children,\n );\n}\n\nexport function ShippingSimulatorOptionName({ className, children, ...props }: ShippingSimulatorOptionNameProps) {\n const option = useOptionItem();\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-name=\"\">\n {children ?? option.name}\n </span>\n );\n}\n\nexport function ShippingSimulatorOptionEstimate({\n $content,\n $locale,\n className,\n children,\n ...props\n}: ShippingSimulatorOptionEstimateProps) {\n const option = useOptionItem();\n const { format } = useMessageFormatter(ShippingSimulatorOptionEstimateContent, $content);\n\n function estimate() {\n const { value, unit } = option.shippingEstimate;\n if (value === 0) return format('today');\n const { field, variable } = ESTIMATE_MESSAGE[unit];\n // A computed key widens to an index signature; the parity test pins `variable` to `field`.\n return format(field, { [variable]: value } as Record<typeof variable, number>);\n }\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-estimate=\"\">\n {children ?? estimate()}\n </span>\n );\n}\n\nexport function isFreeAmount(amount: unknown): boolean {\n return isFiniteAmount(amount) && Number(amount) === 0;\n}\n\nexport function ShippingSimulatorOptionPrice({\n $content,\n $locale,\n className,\n children,\n ...props\n}: ShippingSimulatorOptionPriceProps) {\n const option = useOptionItem();\n const { format } = useMessageFormatter(ShippingSimulatorOptionPriceContent, $content);\n const { locale, currency } = useStorefrontContext();\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-price=\"\">\n {children ??\n (isFreeAmount(option.price.amount)\n ? format('freeLabel')\n : formatPrice(Number(option.price.amount), locale, currency))}\n </span>\n );\n}\n\nexport function ShippingSimulatorOptionFreeBadge({\n $content,\n $locale,\n className,\n children,\n ...props\n}: ShippingSimulatorOptionFreeBadgeProps) {\n const option = useOptionItem();\n const { format } = useMessageFormatter(ShippingSimulatorOptionFreeBadgeContent, $content);\n if (!isFreeAmount(option.price.amount)) return null;\n\n return (\n <span {...props} className={className} data-fs-shipping-simulator-option-free-badge=\"\">\n {children ?? format('text')}\n </span>\n );\n}\n\nexport function ShippingSimulatorEmpty({\n $content,\n $locale,\n className,\n children,\n ...props\n}: ShippingSimulatorEmptyProps) {\n const { shippingOptions, userErrors } = useShippingSimulator();\n const { format } = useMessageFormatter(ShippingSimulatorEmptyContent, $content);\n // Idle (null) → nothing; error → nothing (Error owns it); options present → nothing.\n const simulatedEmpty = Array.isArray(shippingOptions) && shippingOptions.length === 0 && userErrors.length === 0;\n if (!simulatedEmpty) return null;\n\n return (\n <output {...props} aria-live=\"polite\" className={className} data-fs-shipping-simulator-empty=\"\">\n {children ?? format('text')}\n </output>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Namespace export\n// ---------------------------------------------------------------------------\n\nexport const ShippingSimulator = {\n Root: ShippingSimulatorRoot,\n Form: ShippingSimulatorForm,\n Input: ShippingSimulatorInput,\n Submit: ShippingSimulatorSubmit,\n Loading: ShippingSimulatorLoading,\n Error: ShippingSimulatorError,\n Options: ShippingSimulatorOptions,\n Option: ShippingSimulatorOption,\n OptionName: ShippingSimulatorOptionName,\n OptionEstimate: ShippingSimulatorOptionEstimate,\n OptionPrice: ShippingSimulatorOptionPrice,\n OptionFreeBadge: ShippingSimulatorOptionFreeBadge,\n Empty: ShippingSimulatorEmpty,\n};\n\nexport const CartShippingSimulator = {\n Root: CartShippingSimulatorRoot,\n Form: ShippingSimulatorForm,\n Input: ShippingSimulatorInput,\n Submit: ShippingSimulatorSubmit,\n Loading: ShippingSimulatorLoading,\n Error: ShippingSimulatorError,\n Options: ShippingSimulatorOptions,\n Option: ShippingSimulatorOption,\n OptionName: ShippingSimulatorOptionName,\n OptionEstimate: ShippingSimulatorOptionEstimate,\n OptionPrice: ShippingSimulatorOptionPrice,\n OptionFreeBadge: ShippingSimulatorOptionFreeBadge,\n Empty: ShippingSimulatorEmpty,\n};\n"],"mappings":";;;;;;;;;;;;;;AA0BA,MAAM,WAAyB;;;;;;;;;;;;;;;;;AAsF/B,MAAM,mCAAmC,OAAO,+BAA+B;AAyF/E,MAAa,2BAA2B,cAEtC,gCAAgC;AAElC,MAAa,oBAAoB,cAAqC,IAAI;;;;;;AAO1E,MAAM,oBAAoB,cAAc,KAAK;AAE7C,SAAS,uBAAsD;CAC7D,MAAM,MAAM,WAAW,wBAAwB;CAC/C,IAAI,QAAQ,kCACV,MAAM,IAAI,MAAM,yEAAyE;CAE3F,OAAO;AACT;AAEA,S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OAAO;CAE5B,OACE,oBAAC,UAAD;EAAQ,GAAI;EAAO,aAAU;EAAoB;EAAW,oCAAiC;EAC1F,UAAA,YAAY,OAAO,MAAM;CACpB,CAAA;AAEZ;AAMA,MAAa,oBAAoB;CAC/B,MAAM;CACN,MAAM;CACN,OAAO;CACP,QAAQ;CACR,SAAS;CACT,OAAO;CACP,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,gBAAgB;CAChB,aAAa;CACb,iBAAiB;CACjB,OAAO;AACT;AAEA,MAAa,wBAAwB;CACnC,MAAM;CACN,MAAM;CACN,OAAO;CACP,QAAQ;CACR,SAAS;CACT,OAAO;CACP,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,gBAAgB;CAChB,aAAa;CACb,iBAAiB;CACjB,OAAO;AACT"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ComponentDefinition } from "../../core/dist/define-component.js";
|
|
2
|
+
import "../../core/dist/index.js";
|
|
3
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
4
|
+
//#region src/matter/sign-in/sign-in.d.ts
|
|
5
|
+
/** Colocated fragment slice forwarded by the reactive runtime — one key per root field. */
|
|
6
|
+
export type SignInSlice = {
|
|
7
|
+
clientProfile: {
|
|
8
|
+
email: string | null;
|
|
9
|
+
} | null;
|
|
10
|
+
sessionAuthProviders: {
|
|
11
|
+
passwordAuthentication: boolean;
|
|
12
|
+
accessKeyAuthentication: boolean;
|
|
13
|
+
} | null;
|
|
14
|
+
};
|
|
15
|
+
export type SignInMethod = 'password' | 'accessCode';
|
|
16
|
+
export type SignInContextValue = Readonly<{
|
|
17
|
+
/** The one email draft every sign-in method shares. Seeded from `clientProfile.email` until the shopper edits it. */
|
|
18
|
+
email: string;
|
|
19
|
+
/** Updates the draft; marks it as shopper-touched so the seed no longer overwrites it. */
|
|
20
|
+
setEmail: (email: string) => void;
|
|
21
|
+
/** The active method: the shopper's choice, else the access code when enabled, else the password. */
|
|
22
|
+
method: SignInMethod;
|
|
23
|
+
setMethod: (method: SignInMethod) => void;
|
|
24
|
+
passwordEnabled: boolean;
|
|
25
|
+
accessCodeEnabled: boolean;
|
|
26
|
+
anyMethodEnabled: boolean;
|
|
27
|
+
bothMethodsEnabled: boolean;
|
|
28
|
+
/** Whether the account configuration has arrived. Gate on this before reading any flag above. */
|
|
29
|
+
resolved: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
export type SignInRootProps = Readonly<{
|
|
32
|
+
$data?: SignInSlice | null;
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
}>;
|
|
35
|
+
export type SignInEmailControlProps = ComponentPropsWithRef<'div'> & {
|
|
36
|
+
label?: string;
|
|
37
|
+
placeholder?: string;
|
|
38
|
+
invalidEmailMessage?: string;
|
|
39
|
+
/** The input's `name`. Defaults to `EmailField`'s own (`'email'`). */
|
|
40
|
+
name?: string;
|
|
41
|
+
/** The input's `autocomplete` token. Defaults to `'username'`, the identifier half of the credential pair. */
|
|
42
|
+
autoComplete?: string;
|
|
43
|
+
};
|
|
44
|
+
export type SignInMethodSwitchProps = ComponentPropsWithRef<'div'> & {
|
|
45
|
+
toAccessCodeLabel?: string;
|
|
46
|
+
toPasswordLabel?: string;
|
|
47
|
+
};
|
|
48
|
+
export type SignInMethodOptionProps = ComponentPropsWithRef<'div'> & {
|
|
49
|
+
/** Which method this option selects. Required — the option has no meaning without it. */
|
|
50
|
+
method: SignInMethod;
|
|
51
|
+
label?: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Read the shared email draft, active method and account flags from the nearest `SignInRoot`.
|
|
55
|
+
* Throws outside that subtree — a misplaced part is a composition bug that should surface
|
|
56
|
+
* immediately, mirroring `useSession()`/`useAccessCodeSignIn()`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function useSignIn(): SignInContextValue;
|
|
59
|
+
export declare const SignInRootDefinition: ComponentDefinition<Readonly<{
|
|
60
|
+
$data?: SignInSlice | null;
|
|
61
|
+
children?: ReactNode;
|
|
62
|
+
}>>;
|
|
63
|
+
export declare const SignInEmailControlDefinition: ComponentDefinition<SignInEmailControlProps>;
|
|
64
|
+
export declare const SignInMethodSwitchDefinition: ComponentDefinition<SignInMethodSwitchProps>;
|
|
65
|
+
export declare const SignInMethodOptionDefinition: ComponentDefinition<SignInMethodOptionProps>;
|
|
66
|
+
/**
|
|
67
|
+
* Data-owning provider of the sign-in surface. Reads `sessionAuthProviders` once, owns the shared
|
|
68
|
+
* email draft and the active method, and publishes all of it as the `sign-in` context. It renders no
|
|
69
|
+
* element of its own and always renders `children` — a provider that returned `null` while hosted in
|
|
70
|
+
* a shared layout would take the page with it.
|
|
71
|
+
*
|
|
72
|
+
* `resolved` is the three-condition gate the entity fieldsets use: a reactive `$data` is never `null`
|
|
73
|
+
* at runtime (it falls back to a placeholder slice), so only the two resolution signals plus the
|
|
74
|
+
* presence of `sessionAuthProviders` tell "not arrived yet" from "arrived and disabled".
|
|
75
|
+
*/
|
|
76
|
+
export declare function SignInRoot({ $data: $dataProp, children }: SignInRootProps): import("react/jsx-runtime").JSX.Element;
|
|
77
|
+
/**
|
|
78
|
+
* Catalog metadata only: `SignInRoot` has no loading look because it always renders its children, so
|
|
79
|
+
* this declares that by rendering nothing. The compiler records the `skeleton` name and never renders
|
|
80
|
+
* it; no component body references it.
|
|
81
|
+
*/
|
|
82
|
+
export declare function SignInRootSkeleton(): null;
|
|
83
|
+
export declare function SignInEmailControlSkeleton({ className, ...props }: ComponentPropsWithRef<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
84
|
+
/**
|
|
85
|
+
* The one email field, bound to the Root's shared draft. Renders its skeleton while the account
|
|
86
|
+
* configuration is unresolved, so a slow read does not look like a store with no sign-in, and nothing
|
|
87
|
+
* once the shopper is signed in or the account enables no method.
|
|
88
|
+
*/
|
|
89
|
+
export declare function SignInEmailControl({ label, placeholder, invalidEmailMessage, name, autoComplete, className, ...props }: SignInEmailControlProps): import("react/jsx-runtime").JSX.Element | null;
|
|
90
|
+
/**
|
|
91
|
+
* One toggle button that moves the active method. Renders only when the account enables both
|
|
92
|
+
* methods; the button is labelled with the method it moves to.
|
|
93
|
+
*/
|
|
94
|
+
export declare function SignInMethodSwitch({ toAccessCodeLabel, toPasswordLabel, className, ...props }: SignInMethodSwitchProps): import("react/jsx-runtime").JSX.Element | null;
|
|
95
|
+
/**
|
|
96
|
+
* One selectable method. Renders only when the account enables the method named by `method`, and
|
|
97
|
+
* carries a selected state while that method is the active one — so one option per method gives a
|
|
98
|
+
* store exactly the options its account enables.
|
|
99
|
+
*/
|
|
100
|
+
export declare function SignInMethodOption({ method, label, className, ...props }: SignInMethodOptionProps): import("react/jsx-runtime").JSX.Element | null;
|
|
101
|
+
export declare const SignIn: {
|
|
102
|
+
Root: typeof SignInRoot;
|
|
103
|
+
EmailControl: typeof SignInEmailControl;
|
|
104
|
+
MethodSwitch: typeof SignInMethodSwitch;
|
|
105
|
+
MethodOption: typeof SignInMethodOption;
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
//# sourceMappingURL=sign-in.d.ts.map
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { defineComponent } from "../../core/dist/define-component.js";
|
|
3
|
+
import "../../core/dist/index.js";
|
|
4
|
+
import { EmailField } from "../../particles/email-field/email-field.js";
|
|
5
|
+
import { useDataOverride } from "../../sdk/data/data-override-context.js";
|
|
6
|
+
import { useSession } from "../session/session.js";
|
|
7
|
+
import { Button } from "../../particles/button/button.js";
|
|
8
|
+
import { useEntityDataResolved } from "../../sdk/data/entity-resolution-context.js";
|
|
9
|
+
import { useReactiveDataSettled } from "../../sdk/data/use-reactive-data-settled.js";
|
|
10
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
//#region src/matter/sign-in/sign-in.tsx
|
|
13
|
+
const fragment = `
|
|
14
|
+
fragment SignInData on Query {
|
|
15
|
+
clientProfile {
|
|
16
|
+
__typename
|
|
17
|
+
id
|
|
18
|
+
email
|
|
19
|
+
}
|
|
20
|
+
sessionAuthProviders {
|
|
21
|
+
__typename
|
|
22
|
+
id
|
|
23
|
+
passwordAuthentication
|
|
24
|
+
accessKeyAuthentication
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
const SIGN_IN_CONTEXT_UNSET = Symbol("SignInContextUnset");
|
|
29
|
+
const SignInContext = createContext(SIGN_IN_CONTEXT_UNSET);
|
|
30
|
+
/**
|
|
31
|
+
* Read the shared email draft, active method and account flags from the nearest `SignInRoot`.
|
|
32
|
+
* Throws outside that subtree — a misplaced part is a composition bug that should surface
|
|
33
|
+
* immediately, mirroring `useSession()`/`useAccessCodeSignIn()`.
|
|
34
|
+
*/
|
|
35
|
+
function useSignIn() {
|
|
36
|
+
const ctx = useContext(SignInContext);
|
|
37
|
+
if (ctx === SIGN_IN_CONTEXT_UNSET) throw new Error("useSignIn() must be used inside a <SignInRoot> subtree.");
|
|
38
|
+
return ctx;
|
|
39
|
+
}
|
|
40
|
+
const SignInRootDefinition = defineComponent({
|
|
41
|
+
name: "SignInRoot",
|
|
42
|
+
importPath: "@vtex/faststore/components",
|
|
43
|
+
component: SignInRoot,
|
|
44
|
+
fragment,
|
|
45
|
+
fetchStrategy: "reactive",
|
|
46
|
+
skeleton: SignInRootSkeleton,
|
|
47
|
+
requiresContext: "session",
|
|
48
|
+
providesContext: "sign-in",
|
|
49
|
+
editor: {
|
|
50
|
+
label: "Sign-In Root",
|
|
51
|
+
category: "identity"
|
|
52
|
+
},
|
|
53
|
+
schema: {},
|
|
54
|
+
guideline: "Provider of the sign-in surface: the single read of which sign-in methods the account enables, plus one shared email draft and the active method, published to the SignIn parts below it. Renders no element of its own and always renders its children, whatever the session state or the account configuration. Compose SignInEmailControl and either SignInMethodSwitch or SignInMethodOption inside it. Must be inside SessionRoot. See sign-in.md."
|
|
55
|
+
});
|
|
56
|
+
const SignInEmailControlDefinition = defineComponent({
|
|
57
|
+
name: "SignInEmailControl",
|
|
58
|
+
importPath: "@vtex/faststore/components",
|
|
59
|
+
component: SignInEmailControl,
|
|
60
|
+
skeleton: SignInEmailControlSkeleton,
|
|
61
|
+
requiresContext: "sign-in",
|
|
62
|
+
editor: {
|
|
63
|
+
label: "Sign-In Email",
|
|
64
|
+
category: "identity"
|
|
65
|
+
},
|
|
66
|
+
schema: {
|
|
67
|
+
label: {
|
|
68
|
+
type: "string",
|
|
69
|
+
label: "Label"
|
|
70
|
+
},
|
|
71
|
+
placeholder: {
|
|
72
|
+
type: "string",
|
|
73
|
+
label: "Placeholder"
|
|
74
|
+
},
|
|
75
|
+
invalidEmailMessage: {
|
|
76
|
+
type: "string",
|
|
77
|
+
label: "Invalid email message"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
guideline: "The one email field shared by every sign-in method. Draws a placeholder while the account configuration loads, and renders nothing once signed in or when the account enables no method. Must be inside SignInRoot. See sign-in.md."
|
|
81
|
+
});
|
|
82
|
+
const SignInMethodSwitchDefinition = defineComponent({
|
|
83
|
+
name: "SignInMethodSwitch",
|
|
84
|
+
importPath: "@vtex/faststore/components",
|
|
85
|
+
component: SignInMethodSwitch,
|
|
86
|
+
requiresContext: "sign-in",
|
|
87
|
+
editor: {
|
|
88
|
+
label: "Sign-In Method Switch",
|
|
89
|
+
category: "identity"
|
|
90
|
+
},
|
|
91
|
+
schema: {
|
|
92
|
+
toAccessCodeLabel: {
|
|
93
|
+
type: "string",
|
|
94
|
+
label: "Switch to access code label"
|
|
95
|
+
},
|
|
96
|
+
toPasswordLabel: {
|
|
97
|
+
type: "string",
|
|
98
|
+
label: "Switch to password label"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
guideline: "One toggle button that moves the active sign-in method between the access code and the password. Renders nothing unless the account enables both methods. Must be inside SignInRoot. See sign-in.md."
|
|
102
|
+
});
|
|
103
|
+
const SignInMethodOptionDefinition = defineComponent({
|
|
104
|
+
name: "SignInMethodOption",
|
|
105
|
+
importPath: "@vtex/faststore/components",
|
|
106
|
+
component: SignInMethodOption,
|
|
107
|
+
requiresContext: "sign-in",
|
|
108
|
+
editor: {
|
|
109
|
+
label: "Sign-In Method Option",
|
|
110
|
+
category: "identity"
|
|
111
|
+
},
|
|
112
|
+
schema: {
|
|
113
|
+
method: {
|
|
114
|
+
type: ["password", "accessCode"],
|
|
115
|
+
label: "Method"
|
|
116
|
+
},
|
|
117
|
+
label: {
|
|
118
|
+
type: "string",
|
|
119
|
+
label: "Label"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
guideline: "One selectable sign-in method. Renders nothing when the account disables the method it names, so composing one per method gives a store exactly the options its account enables. Compose it instead of SignInMethodSwitch when both methods should be visible at once, or beside the default method as an escape hatch. Must be inside SignInRoot. See sign-in.md."
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Data-owning provider of the sign-in surface. Reads `sessionAuthProviders` once, owns the shared
|
|
126
|
+
* email draft and the active method, and publishes all of it as the `sign-in` context. It renders no
|
|
127
|
+
* element of its own and always renders `children` — a provider that returned `null` while hosted in
|
|
128
|
+
* a shared layout would take the page with it.
|
|
129
|
+
*
|
|
130
|
+
* `resolved` is the three-condition gate the entity fieldsets use: a reactive `$data` is never `null`
|
|
131
|
+
* at runtime (it falls back to a placeholder slice), so only the two resolution signals plus the
|
|
132
|
+
* presence of `sessionAuthProviders` tell "not arrived yet" from "arrived and disabled".
|
|
133
|
+
*/
|
|
134
|
+
function SignInRoot({ $data: $dataProp, children }) {
|
|
135
|
+
const $data = useDataOverride($dataProp);
|
|
136
|
+
const settled = useReactiveDataSettled();
|
|
137
|
+
const sliceResolved = useEntityDataResolved();
|
|
138
|
+
const providers = $data?.sessionAuthProviders ?? null;
|
|
139
|
+
const resolved = settled && sliceResolved && providers != null;
|
|
140
|
+
const { state } = useSession();
|
|
141
|
+
const passwordEnabled = resolved && providers.passwordAuthentication;
|
|
142
|
+
const accessCodeEnabled = resolved && providers.accessKeyAuthentication;
|
|
143
|
+
const savedEmail = $data?.clientProfile?.email ?? "";
|
|
144
|
+
const [email, setEmail] = useState("");
|
|
145
|
+
const [touched, setTouched] = useState(false);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!touched) setEmail(savedEmail);
|
|
148
|
+
}, [savedEmail, touched]);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (state === "loggedIn") setTouched(false);
|
|
151
|
+
}, [state]);
|
|
152
|
+
const editEmail = useCallback((next) => {
|
|
153
|
+
setTouched(true);
|
|
154
|
+
setEmail(next);
|
|
155
|
+
}, []);
|
|
156
|
+
const [chosenMethod, setChosenMethod] = useState(null);
|
|
157
|
+
const method = chosenMethod !== null && (!resolved || (chosenMethod === "password" ? passwordEnabled : accessCodeEnabled)) ? chosenMethod : accessCodeEnabled ? "accessCode" : "password";
|
|
158
|
+
const contextValue = useMemo(() => ({
|
|
159
|
+
email,
|
|
160
|
+
setEmail: editEmail,
|
|
161
|
+
method,
|
|
162
|
+
setMethod: setChosenMethod,
|
|
163
|
+
passwordEnabled,
|
|
164
|
+
accessCodeEnabled,
|
|
165
|
+
anyMethodEnabled: passwordEnabled || accessCodeEnabled,
|
|
166
|
+
bothMethodsEnabled: passwordEnabled && accessCodeEnabled,
|
|
167
|
+
resolved
|
|
168
|
+
}), [
|
|
169
|
+
email,
|
|
170
|
+
editEmail,
|
|
171
|
+
method,
|
|
172
|
+
passwordEnabled,
|
|
173
|
+
accessCodeEnabled,
|
|
174
|
+
resolved
|
|
175
|
+
]);
|
|
176
|
+
return /* @__PURE__ */ jsx(SignInContext, {
|
|
177
|
+
value: contextValue,
|
|
178
|
+
children
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Catalog metadata only: `SignInRoot` has no loading look because it always renders its children, so
|
|
183
|
+
* this declares that by rendering nothing. The compiler records the `skeleton` name and never renders
|
|
184
|
+
* it; no component body references it.
|
|
185
|
+
*/
|
|
186
|
+
function SignInRootSkeleton() {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function SignInEmailControlSkeleton({ className, ...props }) {
|
|
190
|
+
return /* @__PURE__ */ jsx("div", {
|
|
191
|
+
...props,
|
|
192
|
+
className,
|
|
193
|
+
"data-fs-sign-in-email-skeleton": "",
|
|
194
|
+
"aria-hidden": "true",
|
|
195
|
+
children: /* @__PURE__ */ jsx("span", { "data-fs-sign-in-email-skeleton-line": "" })
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The one email field, bound to the Root's shared draft. Renders its skeleton while the account
|
|
200
|
+
* configuration is unresolved, so a slow read does not look like a store with no sign-in, and nothing
|
|
201
|
+
* once the shopper is signed in or the account enables no method.
|
|
202
|
+
*/
|
|
203
|
+
function SignInEmailControl({ label, placeholder, invalidEmailMessage, name, autoComplete = "username", className, ...props }) {
|
|
204
|
+
const signIn = useSignIn();
|
|
205
|
+
const { state } = useSession();
|
|
206
|
+
if (state === "loggedIn") return null;
|
|
207
|
+
if (!signIn.resolved) return /* @__PURE__ */ jsx(SignInEmailControlSkeleton, {
|
|
208
|
+
...props,
|
|
209
|
+
className
|
|
210
|
+
});
|
|
211
|
+
if (!signIn.anyMethodEnabled) return null;
|
|
212
|
+
return /* @__PURE__ */ jsx("div", {
|
|
213
|
+
...props,
|
|
214
|
+
className,
|
|
215
|
+
"data-fs-sign-in-email": "",
|
|
216
|
+
children: /* @__PURE__ */ jsx(EmailField, {
|
|
217
|
+
label,
|
|
218
|
+
placeholder,
|
|
219
|
+
value: signIn.email,
|
|
220
|
+
onValueChange: signIn.setEmail,
|
|
221
|
+
errorMessage: invalidEmailMessage,
|
|
222
|
+
name,
|
|
223
|
+
autoComplete
|
|
224
|
+
})
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* One toggle button that moves the active method. Renders only when the account enables both
|
|
229
|
+
* methods; the button is labelled with the method it moves to.
|
|
230
|
+
*/
|
|
231
|
+
function SignInMethodSwitch({ toAccessCodeLabel, toPasswordLabel, className, ...props }) {
|
|
232
|
+
const signIn = useSignIn();
|
|
233
|
+
const { state } = useSession();
|
|
234
|
+
if (state === "loggedIn" || !signIn.resolved) return null;
|
|
235
|
+
if (!signIn.bothMethodsEnabled) return null;
|
|
236
|
+
const { method, setMethod } = signIn;
|
|
237
|
+
return /* @__PURE__ */ jsx("div", {
|
|
238
|
+
...props,
|
|
239
|
+
className,
|
|
240
|
+
"data-fs-sign-in-method-switch": "",
|
|
241
|
+
"data-fs-sign-in-method": method,
|
|
242
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
243
|
+
type: "button",
|
|
244
|
+
onClick: () => setMethod(method === "accessCode" ? "password" : "accessCode"),
|
|
245
|
+
"data-fs-sign-in-method-switch-button": "",
|
|
246
|
+
children: method === "password" ? toAccessCodeLabel : toPasswordLabel
|
|
247
|
+
})
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* One selectable method. Renders only when the account enables the method named by `method`, and
|
|
252
|
+
* carries a selected state while that method is the active one — so one option per method gives a
|
|
253
|
+
* store exactly the options its account enables.
|
|
254
|
+
*/
|
|
255
|
+
function SignInMethodOption({ method, label, className, ...props }) {
|
|
256
|
+
const signIn = useSignIn();
|
|
257
|
+
const { state } = useSession();
|
|
258
|
+
if (state === "loggedIn" || !signIn.resolved) return null;
|
|
259
|
+
if (method !== "password" && method !== "accessCode") return null;
|
|
260
|
+
if (!(method === "password" ? signIn.passwordEnabled : signIn.accessCodeEnabled)) return null;
|
|
261
|
+
const selected = signIn.method === method;
|
|
262
|
+
return /* @__PURE__ */ jsx("div", {
|
|
263
|
+
...props,
|
|
264
|
+
className,
|
|
265
|
+
"data-fs-sign-in-method-option": method,
|
|
266
|
+
...selected ? { "data-fs-sign-in-method-option-selected": "" } : {},
|
|
267
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
268
|
+
type: "button",
|
|
269
|
+
"aria-pressed": selected,
|
|
270
|
+
onClick: () => signIn.setMethod(method),
|
|
271
|
+
"data-fs-sign-in-method-option-button": "",
|
|
272
|
+
children: label
|
|
273
|
+
})
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
const SignIn = {
|
|
277
|
+
Root: SignInRoot,
|
|
278
|
+
EmailControl: SignInEmailControl,
|
|
279
|
+
MethodSwitch: SignInMethodSwitch,
|
|
280
|
+
MethodOption: SignInMethodOption
|
|
281
|
+
};
|
|
282
|
+
//#endregion
|
|
283
|
+
export { SignIn, SignInEmailControl, SignInEmailControlDefinition, SignInEmailControlSkeleton, SignInMethodOption, SignInMethodOptionDefinition, SignInMethodSwitch, SignInMethodSwitchDefinition, SignInRoot, SignInRootDefinition, SignInRootSkeleton, useSignIn };
|
|
284
|
+
|
|
285
|
+
//# sourceMappingURL=sign-in.js.map
|