@vtex/faststore 0.0.7 → 0.0.8
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 +43 -0
- package/dist/actions.json +152 -1
- package/dist/catalog.json +1264 -142
- package/dist/cli/index.d.ts +512 -63
- package/dist/cli/index.js +2098 -686
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/server-runtime.js +44 -24
- package/dist/cli/server-runtime.js.map +1 -1
- package/dist/client.d.ts +5 -1
- package/dist/client.js +5 -1
- package/dist/components.d.ts +34 -7
- package/dist/components.js +38 -11
- package/dist/content-types.json +523 -0
- package/dist/core/dist/define-component.d.ts +6 -1
- package/dist/docs/account-access-gate.md +4 -4
- package/dist/docs/account-address-book.md +519 -0
- package/dist/docs/account-entry-point.md +1 -1
- package/dist/docs/account-menu.md +5 -5
- package/dist/docs/alert-dialog.md +2 -2
- package/dist/docs/billing-address.md +17 -9
- package/dist/docs/card-entry.md +37 -6
- package/dist/docs/cardholder-document.md +16 -14
- package/dist/docs/cart-item.md +1 -1
- package/dist/docs/cart.md +8 -8
- package/dist/docs/client-profile-fieldset.md +7 -5
- package/dist/docs/copy-text.md +84 -0
- package/dist/docs/document-field.md +8 -8
- package/dist/docs/footer-link-group.md +2 -2
- package/dist/docs/header-root.md +1 -1
- package/dist/docs/incentives.md +2 -2
- package/dist/docs/logo.md +5 -5
- package/dist/docs/my-account-profile.md +4 -4
- package/dist/docs/navigation-link-list.md +2 -2
- package/dist/docs/navigation-link.md +3 -3
- package/dist/docs/order-cancel.md +52 -0
- package/dist/docs/order-delivery-address.md +63 -0
- package/dist/docs/order-delivery-group.md +83 -0
- package/dist/docs/order-details-back.md +41 -0
- package/dist/docs/order-details-header.md +48 -0
- package/dist/docs/order-list-row.md +46 -0
- package/dist/docs/order-list-search.md +101 -0
- package/dist/docs/order-list-views.md +97 -0
- package/dist/docs/order-list.md +94 -0
- package/dist/docs/order-payment.md +94 -0
- package/dist/docs/order-placed-date.md +49 -0
- package/dist/docs/order-placed-payment-summary.md +13 -15
- package/dist/docs/order-placed.md +225 -0
- package/dist/docs/order-progress.md +88 -0
- package/dist/docs/order-status-badge.md +91 -0
- package/dist/docs/order-summary.md +53 -0
- package/dist/docs/payment-method-badges.md +14 -3
- package/dist/docs/place-order.md +13 -9
- package/dist/docs/saved-cards.md +2 -2
- package/dist/docs/select.md +19 -6
- package/dist/docs/session.md +1 -1
- package/dist/docs/shipping-address.md +1 -1
- package/dist/docs/sign-in-redirect.md +6 -6
- package/dist/docs/toast.md +7 -3
- package/dist/index.d.ts +6 -2
- package/dist/index.js +2 -1
- package/dist/internal/client.d.ts +6 -1
- package/dist/internal/client.js +7 -2
- package/dist/internal/server.d.ts +6 -2
- package/dist/internal/server.js +6 -2
- package/dist/matter/account-access-gate/account-access-gate.d.ts +2 -1
- package/dist/matter/account-access-gate/account-access-gate.js +19 -16
- package/dist/matter/account-access-gate/account-access-gate.js.map +1 -1
- package/dist/matter/account-address-book/account-address-book-delete.d.ts +60 -0
- package/dist/matter/account-address-book/account-address-book-delete.js +184 -0
- package/dist/matter/account-address-book/account-address-book-delete.js.map +1 -0
- package/dist/matter/account-address-book/account-address-book-deliverability.d.ts +19 -0
- package/dist/matter/account-address-book/account-address-book-deliverability.js +50 -0
- package/dist/matter/account-address-book/account-address-book-deliverability.js.map +1 -0
- package/dist/matter/account-address-book/account-address-book-form-parts.d.ts +42 -0
- package/dist/matter/account-address-book/account-address-book-form-parts.js +146 -0
- package/dist/matter/account-address-book/account-address-book-form-parts.js.map +1 -0
- package/dist/matter/account-address-book/account-address-book-profile-notice.d.ts +25 -0
- package/dist/matter/account-address-book/account-address-book-profile-notice.js +72 -0
- package/dist/matter/account-address-book/account-address-book-profile-notice.js.map +1 -0
- package/dist/matter/account-address-book/account-address-book.d.ts +120 -0
- package/dist/matter/account-address-book/account-address-book.js +469 -0
- package/dist/matter/account-address-book/account-address-book.js.map +1 -0
- package/dist/matter/account-address-book/account-address-country-switch.js +59 -0
- package/dist/matter/account-address-book/account-address-country-switch.js.map +1 -0
- package/dist/matter/account-address-book/account-address-country.d.ts +36 -0
- package/dist/matter/account-address-book/account-address-country.js +151 -0
- package/dist/matter/account-address-book/account-address-country.js.map +1 -0
- package/dist/matter/account-address-book/account-address-first-line.js +11 -0
- package/dist/matter/account-address-book/account-address-first-line.js.map +1 -0
- package/dist/matter/account-address-book/account-address-form-context.d.ts +55 -0
- package/dist/matter/account-address-book/account-address-form-context.js +14 -0
- package/dist/matter/account-address-book/account-address-form-context.js.map +1 -0
- package/dist/matter/account-address-book/account-address-form.d.ts +85 -0
- package/dist/matter/account-address-book/account-address-form.js +946 -0
- package/dist/matter/account-address-book/account-address-form.js.map +1 -0
- package/dist/matter/account-address-book/account-address-postal-autofill.js +189 -0
- package/dist/matter/account-address-book/account-address-postal-autofill.js.map +1 -0
- package/dist/matter/account-address-book/account-address-record.d.ts +26 -0
- package/dist/matter/account-address-book/account-address-record.js +138 -0
- package/dist/matter/account-address-book/account-address-record.js.map +1 -0
- package/dist/matter/account-entry-point/account-entry-point.js +11 -11
- package/dist/matter/account-entry-point/account-entry-point.js.map +1 -1
- package/dist/matter/account-menu/account-menu.d.ts +7 -3
- package/dist/matter/account-menu/account-menu.js +69 -28
- package/dist/matter/account-menu/account-menu.js.map +1 -1
- package/dist/matter/billing-address/billing-address.d.ts +30 -17
- package/dist/matter/billing-address/billing-address.js +128 -33
- package/dist/matter/billing-address/billing-address.js.map +1 -1
- package/dist/matter/breadcrumb/breadcrumb.js +2 -2
- package/dist/matter/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/matter/card-entry/card-capture.js +4 -3
- package/dist/matter/card-entry/card-capture.js.map +1 -1
- package/dist/matter/card-entry/card-entry.d.ts +5 -3
- package/dist/matter/card-entry/card-entry.js +77 -27
- package/dist/matter/card-entry/card-entry.js.map +1 -1
- package/dist/matter/cardholder-document/cardholder-document.d.ts +10 -9
- package/dist/matter/cardholder-document/cardholder-document.js +36 -16
- package/dist/matter/cardholder-document/cardholder-document.js.map +1 -1
- package/dist/matter/cart/cart.d.ts +7 -2
- package/dist/matter/cart/cart.js +29 -26
- package/dist/matter/cart/cart.js.map +1 -1
- package/dist/matter/cart-item/cart-item.js +2 -2
- package/dist/matter/cart-item/cart-item.js.map +1 -1
- package/dist/matter/client-preferences/client-preferences-fieldset.js +1 -1
- package/dist/matter/client-profile-form/client-profile-fieldset.js +8 -5
- package/dist/matter/client-profile-form/client-profile-fieldset.js.map +1 -1
- package/dist/matter/identity-edit/identity-edit.js +3 -3
- package/dist/matter/identity-edit/identity-edit.js.map +1 -1
- package/dist/matter/identity-summary/identity-summary.js +2 -2
- package/dist/matter/identity-summary/identity-summary.js.map +1 -1
- package/dist/matter/my-account-profile/my-account-profile.d.ts +3 -3
- package/dist/matter/my-account-profile/my-account-profile.js +4 -4
- package/dist/matter/my-account-profile/my-account-profile.js.map +1 -1
- package/dist/matter/order-cancel/order-cancel.d.ts +110 -0
- package/dist/matter/order-cancel/order-cancel.js +344 -0
- package/dist/matter/order-cancel/order-cancel.js.map +1 -0
- package/dist/matter/order-delivery-address/order-delivery-address.d.ts +73 -0
- package/dist/matter/order-delivery-address/order-delivery-address.js +172 -0
- package/dist/matter/order-delivery-address/order-delivery-address.js.map +1 -0
- package/dist/matter/order-delivery-group/order-delivery-group.d.ts +128 -0
- package/dist/matter/order-delivery-group/order-delivery-group.js +408 -0
- package/dist/matter/order-delivery-group/order-delivery-group.js.map +1 -0
- package/dist/matter/order-details-header/order-details-header.d.ts +104 -0
- package/dist/matter/order-details-header/order-details-header.js +190 -0
- package/dist/matter/order-details-header/order-details-header.js.map +1 -0
- package/dist/matter/order-list/customer-orders-filter.d.ts +12 -0
- package/dist/matter/order-list/customer-orders-filter.js +30 -0
- package/dist/matter/order-list/customer-orders-filter.js.map +1 -0
- package/dist/matter/order-list/order-list.d.ts +121 -0
- package/dist/matter/order-list/order-list.js +395 -0
- package/dist/matter/order-list/order-list.js.map +1 -0
- package/dist/matter/order-list-row/order-list-row.d.ts +44 -0
- package/dist/matter/order-list-row/order-list-row.js +127 -0
- package/dist/matter/order-list-row/order-list-row.js.map +1 -0
- package/dist/matter/order-list-search/order-list-search.d.ts +72 -0
- package/dist/matter/order-list-search/order-list-search.js +296 -0
- package/dist/matter/order-list-search/order-list-search.js.map +1 -0
- package/dist/matter/order-list-views/order-list-views.d.ts +65 -0
- package/dist/matter/order-list-views/order-list-views.js +154 -0
- package/dist/matter/order-list-views/order-list-views.js.map +1 -0
- package/dist/matter/order-payment/order-payment.d.ts +83 -0
- package/dist/matter/order-payment/order-payment.js +258 -0
- package/dist/matter/order-payment/order-payment.js.map +1 -0
- package/dist/matter/order-placed/order-placed-deliveries.d.ts +145 -0
- package/dist/matter/order-placed/order-placed-deliveries.js +380 -0
- package/dist/matter/order-placed/order-placed-deliveries.js.map +1 -0
- package/dist/matter/order-placed/order-placed.d.ts +122 -0
- package/dist/matter/order-placed/order-placed.js +452 -0
- package/dist/matter/order-placed/order-placed.js.map +1 -0
- package/dist/matter/order-placed-date/order-placed-date.d.ts +45 -0
- package/dist/matter/order-placed-date/order-placed-date.js +92 -0
- package/dist/matter/order-placed-date/order-placed-date.js.map +1 -0
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.d.ts +5 -8
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.js +29 -81
- package/dist/matter/order-placed-payment-summary/order-placed-payment-summary.js.map +1 -1
- package/dist/matter/order-progress/order-progress.d.ts +85 -0
- package/dist/matter/order-progress/order-progress.js +203 -0
- package/dist/matter/order-progress/order-progress.js.map +1 -0
- package/dist/matter/order-summary/order-summary.d.ts +81 -0
- package/dist/matter/order-summary/order-summary.js +192 -0
- package/dist/matter/order-summary/order-summary.js.map +1 -0
- package/dist/matter/payment/cardholder-document-rule.d.ts +35 -0
- package/dist/matter/payment/cardholder-document-rule.js +35 -0
- package/dist/matter/payment/cardholder-document-rule.js.map +1 -0
- package/dist/matter/payment/payment-card-capture.js +38 -23
- package/dist/matter/payment/payment-card-capture.js.map +1 -1
- package/dist/matter/payment/payment-controller.js +11 -0
- package/dist/matter/payment/payment-controller.js.map +1 -1
- package/dist/matter/payment/payment-method-badges.js +4 -2
- package/dist/matter/payment/payment-method-badges.js.map +1 -1
- package/dist/matter/payment/payment.js +11 -0
- package/dist/matter/payment/payment.js.map +1 -1
- package/dist/matter/payment/use-payment-method-selection.d.ts +39 -0
- package/dist/matter/payment/use-payment-method-selection.js +30 -2
- package/dist/matter/payment/use-payment-method-selection.js.map +1 -1
- package/dist/matter/payment/use-payment-submit-gate.d.ts +16 -2
- package/dist/matter/payment/use-payment-submit-gate.js +42 -14
- package/dist/matter/payment/use-payment-submit-gate.js.map +1 -1
- package/dist/matter/place-order/place-order.d.ts +12 -7
- package/dist/matter/place-order/place-order.js +126 -103
- package/dist/matter/place-order/place-order.js.map +1 -1
- package/dist/matter/pricing/pricing.js +5 -5
- package/dist/matter/pricing/pricing.js.map +1 -1
- package/dist/matter/region/region.js +1 -1
- package/dist/matter/saved-cards/saved-cards.js +26 -15
- package/dist/matter/saved-cards/saved-cards.js.map +1 -1
- package/dist/matter/session/session.js +2 -2
- package/dist/matter/session/session.js.map +1 -1
- package/dist/matter/shipping-address/country-descriptors.d.ts +1 -0
- package/dist/matter/shipping-address/country-descriptors.js +23 -1
- package/dist/matter/shipping-address/country-descriptors.js.map +1 -1
- package/dist/matter/shipping-address/shipping-address.js +62 -14
- package/dist/matter/shipping-address/shipping-address.js.map +1 -1
- package/dist/matter/shipping-simulator/shipping-simulator.d.ts +1 -1
- package/dist/matter/shipping-simulator/shipping-simulator.js.map +1 -1
- package/dist/matter/sign-in-redirect/sign-in-redirect.js +48 -10
- package/dist/matter/sign-in-redirect/sign-in-redirect.js.map +1 -1
- package/dist/matter/variant-selector/variant-selector.js +2 -2
- package/dist/matter/variant-selector/variant-selector.js.map +1 -1
- package/dist/particles/address-summary/address-summary.js +2 -2
- package/dist/particles/address-summary/address-summary.js.map +1 -1
- package/dist/particles/alert-dialog/alert-dialog.d.ts +5 -1
- package/dist/particles/alert-dialog/alert-dialog.js +5 -2
- package/dist/particles/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/particles/copy-text/copy-text.d.ts +28 -0
- package/dist/particles/copy-text/copy-text.js +140 -0
- package/dist/particles/copy-text/copy-text.js.map +1 -0
- package/dist/particles/document-field/document-field.d.ts +34 -5
- package/dist/particles/document-field/document-field.js +115 -19
- package/dist/particles/document-field/document-field.js.map +1 -1
- package/dist/particles/field/field.js +1 -1
- package/dist/particles/field/field.js.map +1 -1
- package/dist/particles/footer-link-group/footer-link-group.d.ts +6 -2
- package/dist/particles/footer-link-group/footer-link-group.js +18 -7
- package/dist/particles/footer-link-group/footer-link-group.js.map +1 -1
- package/dist/particles/incentives/incentives.d.ts +6 -2
- package/dist/particles/incentives/incentives.js +7 -2
- package/dist/particles/incentives/incentives.js.map +1 -1
- package/dist/particles/logo/logo.d.ts +3 -2
- package/dist/particles/logo/logo.js +20 -8
- package/dist/particles/logo/logo.js.map +1 -1
- package/dist/particles/navigation-link/navigation-link.d.ts +2 -3
- package/dist/particles/navigation-link/navigation-link.js +4 -4
- package/dist/particles/navigation-link/navigation-link.js.map +1 -1
- package/dist/particles/navigation-link-list/navigation-link-list.d.ts +6 -2
- package/dist/particles/navigation-link-list/navigation-link-list.js +18 -7
- package/dist/particles/navigation-link-list/navigation-link-list.js.map +1 -1
- package/dist/particles/order-details-back/order-details-back.d.ts +28 -0
- package/dist/particles/order-details-back/order-details-back.js +52 -0
- package/dist/particles/order-details-back/order-details-back.js.map +1 -0
- package/dist/particles/order-status-badge/order-status-badge.d.ts +19 -0
- package/dist/particles/order-status-badge/order-status-badge.js +50 -0
- package/dist/particles/order-status-badge/order-status-badge.js.map +1 -0
- package/dist/particles/phone-field/phone-field.js +2 -2
- package/dist/particles/phone-field/phone-field.js.map +1 -1
- package/dist/particles/select/select.js +6 -6
- package/dist/particles/select/select.js.map +1 -1
- package/dist/particles/toast/toast.d.ts +1 -1
- package/dist/particles/toast/toast.js +32 -6
- package/dist/particles/toast/toast.js.map +1 -1
- package/dist/schema.graphql +1014 -28
- package/dist/sdk/actions/address-action-provider.d.ts +16 -0
- package/dist/sdk/actions/address-action-provider.js +20 -0
- package/dist/sdk/actions/address-action-provider.js.map +1 -0
- package/dist/sdk/actions/analytics-action-provider.js +1 -1
- package/dist/sdk/actions/index.d.ts +3 -1
- package/dist/sdk/actions/index.js +3 -1
- package/dist/sdk/actions/order-action-provider.d.ts +12 -0
- package/dist/sdk/actions/order-action-provider.js +16 -0
- package/dist/sdk/actions/order-action-provider.js.map +1 -0
- package/dist/sdk/actions/types.d.ts +6 -2
- package/dist/sdk/address/address-fields.js +38 -0
- package/dist/sdk/address/address-fields.js.map +1 -0
- package/dist/sdk/address/checkout-readiness.js +17 -0
- package/dist/sdk/address/checkout-readiness.js.map +1 -0
- package/dist/sdk/address/constants.js +60 -0
- package/dist/sdk/address/constants.js.map +1 -0
- package/dist/sdk/address/country-display.js +19 -0
- package/dist/sdk/address/country-display.js.map +1 -0
- package/dist/sdk/address/country-rules.js +30 -0
- package/dist/sdk/address/country-rules.js.map +1 -0
- package/dist/sdk/address/format-address.js +18 -0
- package/dist/sdk/address/format-address.js.map +1 -0
- package/dist/sdk/address/iso-countries.js +262 -0
- package/dist/sdk/address/iso-countries.js.map +1 -0
- package/dist/sdk/address/layouts.js +56 -0
- package/dist/sdk/address/layouts.js.map +1 -0
- package/dist/sdk/address/messages.js +97 -0
- package/dist/sdk/address/messages.js.map +1 -0
- package/dist/sdk/address/operations.d.ts +54 -0
- package/dist/sdk/address/operations.js +83 -0
- package/dist/sdk/address/operations.js.map +1 -0
- package/dist/sdk/address/postal-code-lookup-operations.js +23 -0
- package/dist/sdk/address/postal-code-lookup-operations.js.map +1 -0
- package/dist/sdk/address/postal-code.js +11 -0
- package/dist/sdk/address/postal-code.js.map +1 -0
- package/dist/sdk/address/schema.js +14 -0
- package/dist/sdk/address/schema.js.map +1 -0
- package/dist/sdk/address/server-fields.js +25 -0
- package/dist/sdk/address/server-fields.js.map +1 -0
- package/dist/sdk/address/switch-country.js +57 -0
- package/dist/sdk/address/switch-country.js.map +1 -0
- package/dist/sdk/address/types.d.ts +26 -0
- package/dist/sdk/address/use-address-actions.d.ts +29 -0
- package/dist/sdk/address/use-address-actions.js +247 -0
- package/dist/sdk/address/use-address-actions.js.map +1 -0
- package/dist/sdk/address/use-address-by-postal-code.js +57 -0
- package/dist/sdk/address/use-address-by-postal-code.js.map +1 -0
- package/dist/sdk/address/validate-address.js +62 -0
- package/dist/sdk/address/validate-address.js.map +1 -0
- package/dist/sdk/cache/storefront-cache.js +29 -4
- package/dist/sdk/cache/storefront-cache.js.map +1 -1
- package/dist/sdk/client/fetch-page-data.d.ts +11 -0
- package/dist/sdk/client/fetch-page-data.js +12 -1
- package/dist/sdk/client/fetch-page-data.js.map +1 -1
- package/dist/sdk/content/create-content-runtime.js +1 -8
- package/dist/sdk/content/create-content-runtime.js.map +1 -1
- package/dist/sdk/data/failed-fields.js +23 -0
- package/dist/sdk/data/failed-fields.js.map +1 -0
- package/dist/sdk/data/index.js +2 -2
- package/dist/sdk/data/page-reactive-data-root.d.ts +45 -7
- package/dist/sdk/data/page-reactive-data-root.js +88 -12
- package/dist/sdk/data/page-reactive-data-root.js.map +1 -1
- package/dist/sdk/data/reactive-list-item-data-provider.js +2 -2
- package/dist/sdk/generated/fragment-types.js +2 -0
- package/dist/sdk/generated/fragment-types.js.map +1 -1
- package/dist/sdk/generated/gql.js +3 -1
- package/dist/sdk/generated/gql.js.map +1 -1
- package/dist/sdk/generated/graphql.d.ts +8 -0
- package/dist/sdk/generated/graphql.js +212 -1
- package/dist/sdk/generated/graphql.js.map +1 -1
- package/dist/sdk/i18n/messages/en-US.js +138 -1
- package/dist/sdk/i18n/messages/en-US.json +138 -1
- package/dist/sdk/i18n/messages/en-US.json.d.ts +137 -0
- package/dist/sdk/i18n/messages/es-ES.js +138 -1
- package/dist/sdk/i18n/messages/es-ES.json +138 -1
- package/dist/sdk/i18n/messages/pt-BR.js +138 -1
- package/dist/sdk/i18n/messages/pt-BR.json +138 -1
- package/dist/sdk/navigation/current-page.js +30 -0
- package/dist/sdk/navigation/current-page.js.map +1 -0
- package/dist/sdk/navigation/not-found-log.d.ts +28 -0
- package/dist/sdk/navigation/not-found-log.js +133 -0
- package/dist/sdk/navigation/not-found-log.js.map +1 -0
- package/dist/sdk/navigation/path.js +25 -0
- package/dist/sdk/navigation/path.js.map +1 -0
- package/dist/sdk/navigation/redirect.d.ts +11 -0
- package/dist/sdk/navigation/redirect.js +22 -0
- package/dist/sdk/navigation/redirect.js.map +1 -0
- package/dist/sdk/navigation/report.js +70 -0
- package/dist/sdk/navigation/report.js.map +1 -0
- package/dist/sdk/navigation/resolve-storefront-href.d.ts +12 -0
- package/dist/sdk/navigation/resolve-storefront-href.js +214 -0
- package/dist/sdk/navigation/resolve-storefront-href.js.map +1 -0
- package/dist/sdk/navigation/route-identity-provider.d.ts +11 -0
- package/dist/sdk/navigation/route-identity-provider.js +20 -0
- package/dist/sdk/navigation/route-identity-provider.js.map +1 -0
- package/dist/sdk/navigation/route-map-provider.d.ts +19 -0
- package/dist/sdk/navigation/route-map-provider.js +29 -0
- package/dist/sdk/navigation/route-map-provider.js.map +1 -0
- package/dist/sdk/navigation/storefront-link.d.ts +16 -0
- package/dist/sdk/navigation/storefront-link.js +66 -0
- package/dist/sdk/navigation/storefront-link.js.map +1 -0
- package/dist/sdk/navigation/types.d.ts +45 -0
- package/dist/sdk/navigation/use-storefront-navigation.d.ts +26 -0
- package/dist/sdk/navigation/use-storefront-navigation.js +73 -0
- package/dist/sdk/navigation/use-storefront-navigation.js.map +1 -0
- package/dist/sdk/navigation/use-storefront-route.d.ts +26 -0
- package/dist/sdk/navigation/use-storefront-route.js +87 -0
- package/dist/sdk/navigation/use-storefront-route.js.map +1 -0
- package/dist/sdk/navigation/use-storefront-search-params.d.ts +11 -0
- package/dist/sdk/navigation/use-storefront-search-params.js +16 -0
- package/dist/sdk/navigation/use-storefront-search-params.js.map +1 -0
- package/dist/sdk/orders/completion-badge.d.ts +8 -0
- package/dist/sdk/orders/completion-badge.js +47 -0
- package/dist/sdk/orders/completion-badge.js.map +1 -0
- package/dist/sdk/orders/order-operations.d.ts +19 -0
- package/dist/sdk/orders/order-operations.js +21 -0
- package/dist/sdk/orders/order-operations.js.map +1 -0
- package/dist/sdk/orders/use-order-actions.d.ts +23 -0
- package/dist/sdk/orders/use-order-actions.js +62 -0
- package/dist/sdk/orders/use-order-actions.js.map +1 -0
- package/dist/sdk/payment/gateway-origin.js +26 -13
- package/dist/sdk/payment/gateway-origin.js.map +1 -1
- package/dist/sdk/payment/gateway.d.ts +14 -2
- package/dist/sdk/payment/gateway.js +32 -14
- package/dist/sdk/payment/gateway.js.map +1 -1
- package/dist/sdk/payment/operations.js +11 -0
- package/dist/sdk/payment/operations.js.map +1 -1
- package/dist/sdk/payment/submission-registry.d.ts +2 -1
- package/dist/sdk/payment/submission-registry.js +12 -8
- package/dist/sdk/payment/submission-registry.js.map +1 -1
- package/dist/sdk/payment/use-payment-actions.d.ts +5 -3
- package/dist/sdk/payment/use-payment-actions.js +5 -2
- package/dist/sdk/payment/use-payment-actions.js.map +1 -1
- package/dist/sdk/payment/use-place-order.d.ts +6 -3
- package/dist/sdk/payment/use-place-order.js +333 -143
- package/dist/sdk/payment/use-place-order.js.map +1 -1
- package/dist/sdk/seo/page-alternates.d.ts +55 -0
- package/dist/sdk/seo/page-alternates.js +132 -0
- package/dist/sdk/seo/page-alternates.js.map +1 -0
- package/dist/utils/own-value.js +19 -0
- package/dist/utils/own-value.js.map +1 -0
- package/dist/utils/safe-href.d.ts +4 -4
- package/dist/utils/safe-href.js +31 -22
- package/dist/utils/safe-href.js.map +1 -1
- package/package.json +5 -1
- package/skills/storefront-asset/SKILL.md +111 -0
- package/skills/storefront-asset/references/api-side.md +153 -0
- package/skills/storefront-asset/references/findings.md +40 -0
- package/skills/storefront-asset/references/ui-side.md +94 -0
- package/src/styles/tailwind.css +27 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { MessageId, Messages } from "../sdk/i18n/locales.js";
|
|
2
2
|
import "../sdk/i18n/client.js";
|
|
3
3
|
import { gql } from "../sdk/graphql-tag.js";
|
|
4
|
+
import { AddressActionProvider, AddressActionProviderProps } from "../sdk/actions/address-action-provider.js";
|
|
4
5
|
import { AnalyticsActionProvider, AnalyticsActionProviderProps } from "../sdk/actions/analytics-action-provider.js";
|
|
5
6
|
import { CartActionProvider, CartActionProviderProps } from "../sdk/actions/cart-action-provider.js";
|
|
6
7
|
import { IdentityActionProvider, IdentityActionProviderProps } from "../sdk/actions/identity-action-provider.js";
|
|
8
|
+
import { OrderActionProvider, OrderActionProviderProps } from "../sdk/actions/order-action-provider.js";
|
|
7
9
|
import { PaymentActionProvider, PaymentActionProviderProps } from "../sdk/actions/payment-action-provider.js";
|
|
8
10
|
import { RegionActionProvider, RegionActionProviderProps } from "../sdk/actions/region-action-provider.js";
|
|
9
11
|
import { SessionActionProvider, SessionActionProviderProps } from "../sdk/actions/session-action-provider.js";
|
|
@@ -19,8 +21,11 @@ import { ClientVariablesMap, PageReactiveDataRoot, PageReactiveDataRootProps, Re
|
|
|
19
21
|
import { ReactiveDataProvider, ReactiveDataProviderProps } from "../sdk/data/reactive-data-provider.js";
|
|
20
22
|
import { ReactiveListItemDataProvider, ReactiveListItemDataProviderProps } from "../sdk/data/reactive-list-item-data-provider.js";
|
|
21
23
|
import "../sdk/data/index.js";
|
|
24
|
+
import { RouteMapProvider, RouteMapProviderProps, ToLogicalPath } from "../sdk/navigation/route-map-provider.js";
|
|
25
|
+
import { reportNotFoundRequest } from "../sdk/navigation/not-found-log.js";
|
|
26
|
+
import { RouteIdentityProvider, RouteIdentityProviderProps } from "../sdk/navigation/route-identity-provider.js";
|
|
22
27
|
import { StorefrontProvider, StorefrontProviderProps } from "../sdk/provider/storefront-provider.js";
|
|
23
28
|
import "../sdk/provider/index.js";
|
|
24
29
|
import { cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, miniCartOpenVar, orderFormIdVar } from "../sdk/state/cart.js";
|
|
25
30
|
import { SelectedVariant, publishedVariantIdFor, selectedVariantVar } from "../sdk/state/variant-selector.js";
|
|
26
|
-
export { AnalyticsActionProvider, type AnalyticsActionProviderProps, CartActionProvider, type CartActionProviderProps, type ClientVariablesMap, DataOverrideContext, HotDataProvider, type HotDataProviderProps, IdentityActionProvider, type IdentityActionProviderProps, type ListItemRef, ListItemRefContext, type MessageId, type Messages, MultipleReactiveDataProvider, type MultipleReactiveDataProviderEntity, type MultipleReactiveDataProviderProps, PageReactiveDataRoot, type PageReactiveDataRootProps, PaymentActionProvider, type PaymentActionProviderProps, ReactiveDataProvider, type ReactiveDataProviderProps, ReactiveListItemDataProvider, type ReactiveListItemDataProviderProps, ReactiveRootContext, type ReactiveRootContextValue, RegionActionProvider, type RegionActionProviderProps, type SelectedVariant, SessionActionProvider, type SessionActionProviderProps, ShippingActionProvider, type ShippingActionProviderProps, StorefrontProvider, type StorefrontProviderProps, buildOptimisticDecrease, buildOptimisticIncrease, buildOptimisticRemove, buildStorefrontContextHeaders, cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, gql, miniCartOpenVar, orderFormIdVar, publishedVariantIdFor, selectedVariantVar, useDataOverride, useListItemRef };
|
|
31
|
+
export { AddressActionProvider, type AddressActionProviderProps, AnalyticsActionProvider, type AnalyticsActionProviderProps, CartActionProvider, type CartActionProviderProps, type ClientVariablesMap, DataOverrideContext, HotDataProvider, type HotDataProviderProps, IdentityActionProvider, type IdentityActionProviderProps, type ListItemRef, ListItemRefContext, type MessageId, type Messages, MultipleReactiveDataProvider, type MultipleReactiveDataProviderEntity, type MultipleReactiveDataProviderProps, OrderActionProvider, type OrderActionProviderProps, PageReactiveDataRoot, type PageReactiveDataRootProps, PaymentActionProvider, type PaymentActionProviderProps, ReactiveDataProvider, type ReactiveDataProviderProps, ReactiveListItemDataProvider, type ReactiveListItemDataProviderProps, ReactiveRootContext, type ReactiveRootContextValue, RegionActionProvider, type RegionActionProviderProps, RouteIdentityProvider, type RouteIdentityProviderProps, RouteMapProvider, type RouteMapProviderProps, type SelectedVariant, SessionActionProvider, type SessionActionProviderProps, ShippingActionProvider, type ShippingActionProviderProps, StorefrontProvider, type StorefrontProviderProps, type ToLogicalPath, buildOptimisticDecrease, buildOptimisticIncrease, buildOptimisticRemove, buildStorefrontContextHeaders, cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, gql, miniCartOpenVar, orderFormIdVar, publishedVariantIdFor, reportNotFoundRequest, selectedVariantVar, useDataOverride, useListItemRef };
|
package/dist/internal/client.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { gql } from "../sdk/graphql-tag.js";
|
|
2
|
+
import { RouteMapProvider } from "../sdk/navigation/route-map-provider.js";
|
|
3
|
+
import { RouteIdentityProvider } from "../sdk/navigation/route-identity-provider.js";
|
|
2
4
|
import { DataOverrideContext, useDataOverride } from "../sdk/data/data-override-context.js";
|
|
5
|
+
import { ListItemRefContext, useListItemRef } from "../sdk/data/list-item-ref-context.js";
|
|
3
6
|
import { PageReactiveDataRoot, ReactiveRootContext } from "../sdk/data/page-reactive-data-root.js";
|
|
4
7
|
import { HotDataProvider } from "../sdk/data/hot-data-provider.js";
|
|
5
8
|
import { publishedVariantIdFor, selectedVariantVar } from "../sdk/state/variant-selector.js";
|
|
6
9
|
import { cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, miniCartOpenVar, orderFormIdVar } from "../sdk/state/cart.js";
|
|
7
10
|
import { buildOptimisticDecrease, buildOptimisticIncrease, buildOptimisticRemove } from "../sdk/cart/optimistic.js";
|
|
8
|
-
import {
|
|
11
|
+
import { AddressActionProvider } from "../sdk/actions/address-action-provider.js";
|
|
9
12
|
import { AnalyticsActionProvider } from "../sdk/actions/analytics-action-provider.js";
|
|
10
13
|
import { CartActionProvider } from "../sdk/actions/cart-action-provider.js";
|
|
11
14
|
import { IdentityActionProvider } from "../sdk/actions/identity-action-provider.js";
|
|
15
|
+
import { OrderActionProvider } from "../sdk/actions/order-action-provider.js";
|
|
12
16
|
import { PaymentActionProvider } from "../sdk/actions/payment-action-provider.js";
|
|
13
17
|
import { RegionActionProvider } from "../sdk/actions/region-action-provider.js";
|
|
14
18
|
import { SessionActionProvider } from "../sdk/actions/session-action-provider.js";
|
|
@@ -19,7 +23,8 @@ import { MultipleReactiveDataProvider } from "../sdk/data/multiple-reactive-data
|
|
|
19
23
|
import { ReactiveDataProvider } from "../sdk/data/reactive-data-provider.js";
|
|
20
24
|
import { ReactiveListItemDataProvider } from "../sdk/data/reactive-list-item-data-provider.js";
|
|
21
25
|
import "../sdk/data/index.js";
|
|
26
|
+
import { reportNotFoundRequest } from "../sdk/navigation/not-found-log.js";
|
|
22
27
|
import { StorefrontProvider } from "../sdk/provider/storefront-provider.js";
|
|
23
28
|
import "../sdk/provider/index.js";
|
|
24
29
|
import "../sdk/state/index.js";
|
|
25
|
-
export { AnalyticsActionProvider, CartActionProvider, DataOverrideContext, HotDataProvider, IdentityActionProvider, ListItemRefContext, MultipleReactiveDataProvider, PageReactiveDataRoot, PaymentActionProvider, ReactiveDataProvider, ReactiveListItemDataProvider, ReactiveRootContext, RegionActionProvider, SessionActionProvider, ShippingActionProvider, StorefrontProvider, buildOptimisticDecrease, buildOptimisticIncrease, buildOptimisticRemove, buildStorefrontContextHeaders, cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, gql, miniCartOpenVar, orderFormIdVar, publishedVariantIdFor, selectedVariantVar, useDataOverride, useListItemRef };
|
|
30
|
+
export { AddressActionProvider, AnalyticsActionProvider, CartActionProvider, DataOverrideContext, HotDataProvider, IdentityActionProvider, ListItemRefContext, MultipleReactiveDataProvider, OrderActionProvider, PageReactiveDataRoot, PaymentActionProvider, ReactiveDataProvider, ReactiveListItemDataProvider, ReactiveRootContext, RegionActionProvider, RouteIdentityProvider, RouteMapProvider, SessionActionProvider, ShippingActionProvider, StorefrontProvider, buildOptimisticDecrease, buildOptimisticIncrease, buildOptimisticRemove, buildStorefrontContextHeaders, cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, gql, miniCartOpenVar, orderFormIdVar, publishedVariantIdFor, reportNotFoundRequest, selectedVariantVar, useDataOverride, useListItemRef };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { resolveStorefrontHref } from "../sdk/navigation/resolve-storefront-href.js";
|
|
1
2
|
import { buildStorefrontContextHeaders } from "../sdk/context/headers.js";
|
|
3
|
+
import { customerOrdersFilter } from "../matter/order-list/customer-orders-filter.js";
|
|
2
4
|
import { CreateClientOptions, createClient } from "../sdk/client/create-client.js";
|
|
3
5
|
import { FetchPageDataOptions, FetchPageDataResult, fetchPageData } from "../sdk/client/fetch-page-data.js";
|
|
4
6
|
import { PreloadQueryRegistry, RegisterPreloadQueryOptions, registerPreloadQuery } from "../sdk/client/register-preload-query.js";
|
|
5
7
|
import { ContentVariableField, ContentVariablesSpec, VariablesFromContentOptions, variablesFromContent } from "../sdk/data/variables-from-content.js";
|
|
6
8
|
import { getIntl, loadMessages } from "../sdk/i18n/server.js";
|
|
9
|
+
import { permanentRedirectToStorefrontPage, redirectToStorefrontPage } from "../sdk/navigation/redirect.js";
|
|
10
|
+
import { AlternateBinding, BuildPageAlternatesOptions, CATALOG_ROUTE_ALTERNATES_QUERY, PageAlternates, RouteParams, RouteVariant, buildPageAlternates, catalogClusterPaths, routeLogicalPath } from "../sdk/seo/page-alternates.js";
|
|
7
11
|
import { ServerSessionRead, readServerSession } from "../sdk/session/read-server-session.js";
|
|
8
|
-
import {
|
|
12
|
+
import { signInTarget } from "../utils/safe-href.js";
|
|
9
13
|
import { PreloadQueryProps } from "@apollo/client-integration-nextjs";
|
|
10
|
-
export { type ContentVariableField, type ContentVariablesSpec, type CreateClientOptions, type FetchPageDataOptions, type FetchPageDataResult, type PreloadQueryProps, type PreloadQueryRegistry, type RegisterPreloadQueryOptions, type ServerSessionRead, type VariablesFromContentOptions, buildStorefrontContextHeaders, createClient, fetchPageData, getIntl, loadMessages, readServerSession, registerPreloadQuery,
|
|
14
|
+
export { type AlternateBinding, type BuildPageAlternatesOptions, CATALOG_ROUTE_ALTERNATES_QUERY, type ContentVariableField, type ContentVariablesSpec, type CreateClientOptions, type FetchPageDataOptions, type FetchPageDataResult, type PageAlternates, type PreloadQueryProps, type PreloadQueryRegistry, type RegisterPreloadQueryOptions, type RouteParams, type RouteVariant, type ServerSessionRead, type VariablesFromContentOptions, buildPageAlternates, buildStorefrontContextHeaders, catalogClusterPaths, createClient, customerOrdersFilter, fetchPageData, getIntl, loadMessages, permanentRedirectToStorefrontPage, readServerSession, redirectToStorefrontPage, registerPreloadQuery, resolveStorefrontHref, routeLogicalPath, signInTarget, variablesFromContent };
|
package/dist/internal/server.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { signInTarget } from "../utils/safe-href.js";
|
|
2
|
+
import { resolveStorefrontHref } from "../sdk/navigation/resolve-storefront-href.js";
|
|
2
3
|
import { buildStorefrontContextHeaders } from "../sdk/context/headers.js";
|
|
4
|
+
import { customerOrdersFilter } from "../matter/order-list/customer-orders-filter.js";
|
|
3
5
|
import { createClient } from "../sdk/client/create-client.js";
|
|
4
6
|
import { fetchPageData } from "../sdk/client/fetch-page-data.js";
|
|
5
7
|
import { registerPreloadQuery } from "../sdk/client/register-preload-query.js";
|
|
6
8
|
import { variablesFromContent } from "../sdk/data/variables-from-content.js";
|
|
7
9
|
import { getIntl, loadMessages } from "../sdk/i18n/server.js";
|
|
10
|
+
import { permanentRedirectToStorefrontPage, redirectToStorefrontPage } from "../sdk/navigation/redirect.js";
|
|
11
|
+
import { CATALOG_ROUTE_ALTERNATES_QUERY, buildPageAlternates, catalogClusterPaths, routeLogicalPath } from "../sdk/seo/page-alternates.js";
|
|
8
12
|
import { readServerSession } from "../sdk/session/read-server-session.js";
|
|
9
|
-
export { buildStorefrontContextHeaders, createClient, fetchPageData, getIntl, loadMessages, readServerSession, registerPreloadQuery,
|
|
13
|
+
export { CATALOG_ROUTE_ALTERNATES_QUERY, buildPageAlternates, buildStorefrontContextHeaders, catalogClusterPaths, createClient, customerOrdersFilter, fetchPageData, getIntl, loadMessages, permanentRedirectToStorefrontPage, readServerSession, redirectToStorefrontPage, registerPreloadQuery, resolveStorefrontHref, routeLogicalPath, signInTarget, variablesFromContent };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ContentValue } from "../../core/dist/define-content-type.js";
|
|
2
2
|
import { ComponentDefinition } from "../../core/dist/define-component.js";
|
|
3
3
|
import "../../core/dist/index.js";
|
|
4
|
+
import { PageRef } from "../../sdk/navigation/types.js";
|
|
4
5
|
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
5
6
|
//#region src/matter/account-access-gate/account-access-gate.d.ts
|
|
6
7
|
export declare const AccountAccessGateContent: {
|
|
@@ -62,7 +63,7 @@ export type AccountAccessGateNoticeProps = Omit<ComponentPropsWithRef<'output'>,
|
|
|
62
63
|
/** The message for this reason. Nothing renders in its place when unauthored. */
|
|
63
64
|
message?: string;
|
|
64
65
|
/** Where the link out leads, built by the gate from the page the shopper is on. */
|
|
65
|
-
signInHref: string;
|
|
66
|
+
signInHref: PageRef | string;
|
|
66
67
|
/** Label of the link out. No label, no link. */
|
|
67
68
|
signInLabel?: string;
|
|
68
69
|
};
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
import { defineComponent } from "../../core/dist/define-component.js";
|
|
3
3
|
import { defineContentType } from "../../core/dist/define-content-type.js";
|
|
4
4
|
import "../../core/dist/index.js";
|
|
5
|
+
import { signInTarget } from "../../utils/safe-href.js";
|
|
6
|
+
import { useStorefrontNavigation } from "../../sdk/navigation/use-storefront-navigation.js";
|
|
7
|
+
import { useStorefrontRoute } from "../../sdk/navigation/use-storefront-route.js";
|
|
5
8
|
import { useSession } from "../session/session.js";
|
|
6
|
-
import { resolveSignInHref } from "../../utils/safe-href.js";
|
|
7
9
|
import { NavigationLink } from "../../particles/navigation-link/navigation-link.js";
|
|
8
10
|
import { useSessionRevalidation } from "../../sdk/session/use-session-revalidation.js";
|
|
9
11
|
import { useSignOutIntent, withdrawSignOutIntent } from "./sign-out-intent.js";
|
|
10
12
|
import { useEffect, useRef, useState } from "react";
|
|
11
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
import { usePathname, useRouter } from "next/navigation";
|
|
13
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
14
|
import { flushSync } from "react-dom";
|
|
14
15
|
//#region src/matter/account-access-gate/account-access-gate.tsx
|
|
15
16
|
const AccountAccessGateContent = defineContentType({
|
|
@@ -71,7 +72,7 @@ const AccountAccessGateDefinition = defineComponent({
|
|
|
71
72
|
label: "Sign-in Link Label"
|
|
72
73
|
}
|
|
73
74
|
},
|
|
74
|
-
guideline: "The account's single access decision: place it once in the account layout, wrapping the body, and every page that declares that layout inherits it — never restate it per section. It renders its children only for a logged-in shopper; it shows a composed loading look while the session resolves, replaces the current history entry with the sign-in destination for a visitor who arrived signed out (identified counts as signed out), tells a shopper whose session ended mid-visit rather than bouncing them, and stands down while AccountMenuSignOut navigates. It redirects at most once per visit: a shopper who comes back from sign-in still signed out gets a message and a link rather than a second hop. Must be inside SessionRoot, which the same layout hosts. Never place the
|
|
75
|
+
guideline: "The account's single access decision: place it once in the account layout, wrapping the body, and every page that declares that layout inherits it — never restate it per section. It renders its children only for a logged-in shopper; it shows a composed loading look while the session resolves, replaces the current history entry with the sign-in destination for a visitor who arrived signed out (identified counts as signed out), tells a shopper whose session ended mid-visit rather than bouncing them, and stands down while AccountMenuSignOut navigates. It redirects at most once per visit: a shopper who comes back from sign-in still signed out gets a message and a link rather than a second hop. Must be inside SessionRoot, which the same layout hosts. Never place the sign-in page under it — the gate redirects there, and a gated sign-in page would redirect to itself."
|
|
75
76
|
});
|
|
76
77
|
/** The one automatic hop the gate has already spent, surviving the full document load out to the
|
|
77
78
|
* platform and back, and no further than this tab. */
|
|
@@ -79,19 +80,15 @@ const SIGN_IN_ATTEMPT_KEY = "fs::account-access-gate::sign-in-attempt";
|
|
|
79
80
|
function AccountAccessGate({ loadingLabel, expiredMessage, signInIncompleteMessage, signInLabel, $content, children }) {
|
|
80
81
|
const { state, loading } = useSession();
|
|
81
82
|
const signingOut = useSignOutIntent();
|
|
82
|
-
const
|
|
83
|
-
const
|
|
83
|
+
const { path, search } = useStorefrontRoute();
|
|
84
|
+
const { hrefFor, replace } = useStorefrontNavigation();
|
|
84
85
|
const revalidate = useSessionRevalidation();
|
|
85
86
|
const [wasSignedIn, setWasSignedIn] = useState(false);
|
|
86
87
|
const [unconfirmed, setUnconfirmed] = useState(false);
|
|
87
88
|
const [revalidating, setRevalidating] = useState(false);
|
|
88
89
|
const restoreGeneration = useRef(0);
|
|
89
90
|
const [hopSpent, setHopSpent] = useState(null);
|
|
90
|
-
const
|
|
91
|
-
useEffect(() => {
|
|
92
|
-
setSearch(globalThis.location.search);
|
|
93
|
-
});
|
|
94
|
-
const returnPath = pathname === null ? null : `${pathname}${search ?? ""}`;
|
|
91
|
+
const returnPath = `${path}${search ?? ""}`;
|
|
95
92
|
const outcome = resolveOutcome({
|
|
96
93
|
signingOut,
|
|
97
94
|
unconfirmed,
|
|
@@ -118,10 +115,15 @@ function AccountAccessGate({ loadingLabel, expiredMessage, signInIncompleteMessa
|
|
|
118
115
|
setHopSpent(true);
|
|
119
116
|
return;
|
|
120
117
|
}
|
|
121
|
-
const
|
|
118
|
+
const target = signInTarget(returnPath);
|
|
119
|
+
const destination = hrefFor(target);
|
|
120
|
+
if (destination === null) {
|
|
121
|
+
setHopSpent(true);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
122
124
|
recordSignInAttempt(destination);
|
|
123
125
|
setHopSpent(false);
|
|
124
|
-
|
|
126
|
+
replace(target);
|
|
125
127
|
return;
|
|
126
128
|
}
|
|
127
129
|
case "stand-down":
|
|
@@ -133,7 +135,8 @@ function AccountAccessGate({ loadingLabel, expiredMessage, signInIncompleteMessa
|
|
|
133
135
|
hopSpent,
|
|
134
136
|
search,
|
|
135
137
|
returnPath,
|
|
136
|
-
|
|
138
|
+
hrefFor,
|
|
139
|
+
replace
|
|
137
140
|
]);
|
|
138
141
|
useEffect(() => {
|
|
139
142
|
function handlePageHide(event) {
|
|
@@ -181,13 +184,13 @@ function AccountAccessGate({ loadingLabel, expiredMessage, signInIncompleteMessa
|
|
|
181
184
|
"data-fs-account-access-gate": "",
|
|
182
185
|
children: entryLoadingLabel
|
|
183
186
|
});
|
|
184
|
-
case "account": return /* @__PURE__ */ jsx(Fragment, { children });
|
|
187
|
+
case "account": return /* @__PURE__ */ jsx(Fragment$1, { children });
|
|
185
188
|
case "expired":
|
|
186
189
|
case "sign-in-incomplete": return /* @__PURE__ */ jsx(AccountAccessGateNotice, {
|
|
187
190
|
"data-fs-account-access-gate": "",
|
|
188
191
|
reason: outcome === "expired" ? "expired" : "sign-in-incomplete",
|
|
189
192
|
message: outcome === "expired" ? entryExpiredMessage : entryIncompleteMessage,
|
|
190
|
-
signInHref:
|
|
193
|
+
signInHref: signInTarget(returnPath),
|
|
191
194
|
signInLabel: entrySignInLabel
|
|
192
195
|
});
|
|
193
196
|
default: return assertUnreachable(outcome);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-access-gate.js","names":[],"sources":["../../../src/matter/account-access-gate/account-access-gate.tsx"],"sourcesContent":["'use client';\n\nimport { type ContentValue, defineComponent, defineContentType } from '@vtex/fs-core';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { type ComponentPropsWithRef, type ReactNode, useEffect, useRef, useState } from 'react';\nimport { flushSync } from 'react-dom';\nimport { NavigationLink } from '../../particles/navigation-link/navigation-link.js';\nimport { useSessionRevalidation } from '../../sdk/session/use-session-revalidation.js';\nimport { resolveSignInHref } from '../../utils/safe-href.js';\nimport { type SessionState, useSession } from '../session/session.js';\nimport { useSignOutIntent, withdrawSignOutIntent } from './sign-out-intent.js';\n\n// Nothing is required, following the shipped identity components: an entry may author any subset, and\n// a slice missing a required property is shape-invalid, which drops the whole element rather than the\n// one field.\nexport const AccountAccessGateContent = defineContentType({\n id: 'account-access-gate',\n title: 'Account Access Gate',\n description: 'What the shopper is told while the account resolves and when it will not open for them.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n loadingLabel: { type: 'string', minLength: 1, title: 'Loading announcement' },\n expiredMessage: { type: 'string', minLength: 1, title: 'Session ended message' },\n signInIncompleteMessage: { type: 'string', minLength: 1, title: 'Sign-in did not complete message' },\n signInLabel: { type: 'string', minLength: 1, title: 'Sign-in link label' },\n },\n },\n});\n\n/** Why the account will not open, as a bounded value: a style target and the choice of message. */\nexport type AccountAccessGateNoticeReason = 'expired' | 'sign-in-incomplete';\n\n/** Props for {@link AccountAccessGate}. It renders a different element per outcome and forwards no\n * element props of its own; each rendered part carries its own. */\nexport type AccountAccessGateProps = {\n /** Text announced while the session resolves. */\n loadingLabel?: string;\n /** What a shopper whose session ended mid-visit is told. */\n expiredMessage?: string;\n /** What a shopper who came back from sign-in still signed out is told. */\n signInIncompleteMessage?: string;\n /** Label of the link out of either notice. Without it no link renders — a focusable link a screen\n * reader announces as its bare URL is worse than no control at all. */\n signInLabel?: string;\n /** Merchant-authored fields, sliced from the layout content entry; win over the props field by field\n * when present. Absent in a non-CMS store — the props are the fallback. */\n $content?: ContentValue<typeof AccountAccessGateContent>;\n /** The account. Rendered only for a signed-in shopper. */\n children?: ReactNode;\n};\n\n/** Props for {@link AccountAccessGateLoading}. Extends native `<output>` attributes. */\nexport type AccountAccessGateLoadingProps = ComponentPropsWithRef<'output'>;\n\n/** Props for {@link AccountAccessGateNotice}. Extends native `<output>` attributes. */\nexport type AccountAccessGateNoticeProps = Omit<ComponentPropsWithRef<'output'>, 'children'> & {\n reason: AccountAccessGateNoticeReason;\n /** The message for this reason. Nothing renders in its place when unauthored. */\n message?: string;\n /** Where the link out leads, built by the gate from the page the shopper is on. */\n signInHref: string;\n /** Label of the link out. No label, no link. */\n signInLabel?: string;\n};\n\nexport const AccountAccessGateDefinition = defineComponent<AccountAccessGateProps>({\n name: 'AccountAccessGate',\n importPath: '@vtex/faststore/components',\n component: AccountAccessGate,\n content: AccountAccessGateContent,\n editor: { label: 'Account Access Gate', category: 'identity' },\n requiresContext: 'session',\n schema: {\n // Mirrored from the content model on purpose, as every content-bearing component in the library\n // does: the entry wins when published, and this is what a store without a CMS authors.\n loadingLabel: { type: 'string', label: 'Loading Announcement' },\n expiredMessage: { type: 'string', label: 'Session Ended Message' },\n signInIncompleteMessage: { type: 'string', label: 'Sign-in Did Not Complete Message' },\n signInLabel: { type: 'string', label: 'Sign-in Link Label' },\n },\n guideline:\n \"The account's single access decision: place it once in the account layout, wrapping the body, and every page that declares that layout inherits it — never restate it per section. It renders its children only for a logged-in shopper; it shows a composed loading look while the session resolves, replaces the current history entry with the sign-in destination for a visitor who arrived signed out (identified counts as signed out), tells a shopper whose session ended mid-visit rather than bouncing them, and stands down while AccountMenuSignOut navigates. It redirects at most once per visit: a shopper who comes back from sign-in still signed out gets a message and a link rather than a second hop. Must be inside SessionRoot, which the same layout hosts. Never place the /login route under it — the gate redirects there, and a gated /login would redirect to itself.\",\n});\n\n/** The one automatic hop the gate has already spent, surviving the full document load out to the\n * platform and back, and no further than this tab. */\nconst SIGN_IN_ATTEMPT_KEY = 'fs::account-access-gate::sign-in-attempt';\n\n/**\n * What the gate renders, in precedence order. `signing-in` covers both the frame that decides whether\n * the hop is still available and the frame after the replace is issued: they render the same nothing,\n * and only the effect tells them apart.\n */\ntype AccountAccessGateOutcome = 'stand-down' | 'expired' | 'loading' | 'account' | 'sign-in-incomplete' | 'signing-in';\n\nexport function AccountAccessGate({\n loadingLabel,\n expiredMessage,\n signInIncompleteMessage,\n signInLabel,\n $content,\n children,\n}: Readonly<AccountAccessGateProps>) {\n const { state, loading } = useSession();\n const signingOut = useSignOutIntent();\n const pathname = usePathname();\n const router = useRouter();\n const revalidate = useSessionRevalidation();\n\n // Whether this gate has ever resolved to a signed-in shopper. It is what separates a session that\n // ended from a visitor who arrived signed out — the tri-state spells both `anonymous`.\n const [wasSignedIn, setWasSignedIn] = useState(false);\n // A revalidation that could not answer. It outranks `loading` because the discard that preceded it\n // is what leaves the session unresolved, so nothing else is coming to end that wait.\n const [unconfirmed, setUnconfirmed] = useState(false);\n // A re-read in flight. The gate withholds the account for itself rather than waiting to be told:\n // discarding the cached session leaves the data layer unresolved, but it reaches the gate only once\n // the watched query has re-read, and the account must be gone in the frame the restore arrives.\n const [revalidating, setRevalidating] = useState(false);\n // Which re-read the gate is still listening to. Two restores in a row put two answers in flight, and\n // the older one may land last.\n const restoreGeneration = useRef(0);\n // `null` until the arrival path has read the record. Read from an effect rather than from the render\n // body: session storage does not exist on the server, and a value that appeared between the server\n // pass and hydration would change what renders underneath it.\n const [hopSpent, setHopSpent] = useState<boolean | null>(null);\n // `null` until the document has been read, for the same two reasons, and read from the document\n // rather than through `useSearchParams()`, which would require a `Suspense` boundary the generator\n // does not emit on a prerendered route — the reason `SignInRedirect` gives for reading it this way.\n const [search, setSearch] = useState<string | null>(null);\n\n // Deliberately on every commit rather than on mount: `usePathname()` re-renders the gate when the\n // path changes but says nothing about the query, and a shopper who pages through their orders\n // changes only the query. Setting the same string is a bail-out, so this does not loop.\n useEffect(() => {\n setSearch(globalThis.location.search);\n });\n\n // Where the shopper comes back to. `usePathname()` yields the path alone, so a gate that stopped\n // there would return someone reading `/pvt/orders?page=2` to the first page of it.\n const returnPath = pathname === null ? null : `${pathname}${search ?? ''}`;\n\n const outcome = resolveOutcome({ signingOut, unconfirmed, revalidating, loading, state, wasSignedIn, hopSpent });\n\n useEffect(() => {\n switch (outcome) {\n case 'account':\n setWasSignedIn(true);\n setUnconfirmed(false);\n clearSignInAttempt();\n return;\n case 'expired':\n case 'sign-in-incomplete':\n // Every outcome that is not the hop returns it: a shopper who signs in, browses, and comes\n // back later arrives fresh rather than carrying a spent attempt from an earlier one.\n clearSignInAttempt();\n return;\n case 'signing-in': {\n // One more frame before deciding, until the document has been read: a hop recorded against the\n // bare path is the one the shopper comes back to, and there is no second chance at it.\n if (hopSpent !== null || search === null) {\n return;\n }\n if (readSignInAttempt() !== null) {\n setHopSpent(true);\n return;\n }\n const destination = resolveSignInHref(returnPath);\n recordSignInAttempt(destination);\n setHopSpent(false);\n // Replace rather than push: back from the platform's login should reach the page the shopper\n // came from, not the account that threw them at it.\n // react-doctor-disable-next-line nextjs-no-client-side-redirect -- the session resolves on the client, so the server has nothing to decide with\n router.replace(destination);\n return;\n }\n case 'stand-down':\n case 'loading':\n return;\n default:\n assertUnreachable(outcome);\n }\n }, [outcome, hopSpent, search, returnPath, router]);\n\n useEffect(() => {\n function handlePageHide(event: PageTransitionEvent): void {\n if (!event.persisted) {\n return;\n }\n // What the browser freezes is the DOM, and a restore puts that same DOM back before any script\n // runs. Standing the account down on the way out rather than on the way back is what keeps the\n // restored document from showing it in the frames before `pageshow` can decide again.\n flushSync(() => {\n setRevalidating(true);\n });\n }\n\n function handlePageShow(event: PageTransitionEvent): void {\n // An ordinary load re-decides by mounting. Only a restore resumes a heap that already holds an\n // answer, and `persisted` is the browser's own word for it.\n if (!event.persisted) {\n return;\n }\n const generation = restoreGeneration.current + 1;\n restoreGeneration.current = generation;\n // The navigation this authorized has already happened; a restored document holding it would\n // stand down forever. Withdrawn before the re-read so the gate is deciding again by the time\n // the answer lands.\n withdrawSignOutIntent();\n setUnconfirmed(false);\n setRevalidating(true);\n void revalidate().then((result) => {\n // A later restore has already asked the same question, and its answer is the one that counts.\n // This one describes a session the gate has since discarded a second time.\n if (generation !== restoreGeneration.current) {\n return;\n }\n setRevalidating(false);\n switch (result) {\n case 'failed':\n setUnconfirmed(true);\n return;\n case 'revalidated':\n case 'unavailable':\n // Nothing left to distrust: either the session was re-read, or there was no cached\n // session to discard in the first place and the one in the tree came from a prop.\n return;\n default:\n assertUnreachable(result);\n }\n });\n }\n\n globalThis.addEventListener('pagehide', handlePageHide);\n globalThis.addEventListener('pageshow', handlePageShow);\n return () => {\n globalThis.removeEventListener('pagehide', handlePageHide);\n globalThis.removeEventListener('pageshow', handlePageShow);\n };\n }, [revalidate]);\n\n // The intent authorizes one transition and this gate is its only reader, so it must not survive the\n // gate. A sign-out that navigates client-side takes the account layout down without reloading the\n // document, and nothing else would ever take the flag back: the next account page the shopper opens\n // would mount into a standing intent and render nothing at all, with no error to explain it.\n useEffect(() => withdrawSignOutIntent, []);\n\n // Blank entry fields fall through, so clearing one in the Admin reads as unauthored.\n const entryLoadingLabel = $content?.loadingLabel?.trim() ? $content.loadingLabel : loadingLabel;\n const entryExpiredMessage = $content?.expiredMessage?.trim() ? $content.expiredMessage : expiredMessage;\n const entryIncompleteMessage = $content?.signInIncompleteMessage?.trim()\n ? $content.signInIncompleteMessage\n : signInIncompleteMessage;\n const entrySignInLabel = $content?.signInLabel?.trim() ? $content.signInLabel : signInLabel;\n\n switch (outcome) {\n case 'stand-down':\n case 'signing-in':\n return null;\n case 'loading':\n return (\n // The part carries its own hook; the component's identity travels from here, which is how a\n // store targets it by name the way every other component is targeted.\n <AccountAccessGateLoading data-fs-account-access-gate=\"\">{entryLoadingLabel}</AccountAccessGateLoading>\n );\n case 'account':\n return <>{children}</>;\n case 'expired':\n case 'sign-in-incomplete':\n return (\n <AccountAccessGateNotice\n data-fs-account-access-gate=\"\"\n reason={outcome === 'expired' ? 'expired' : 'sign-in-incomplete'}\n message={outcome === 'expired' ? entryExpiredMessage : entryIncompleteMessage}\n signInHref={resolveSignInHref(returnPath)}\n signInLabel={entrySignInLabel}\n />\n );\n default:\n return assertUnreachable(outcome);\n }\n}\n\n/**\n * The whole decision, as one ordered read of the gate's inputs.\n *\n * `signingOut` outranks everything, including a session still reading `loggedIn`: the sign-out records\n * its intent before it awaits the mutation, and the frame between the payload landing and the document\n * load starting is exactly the one this ordering protects.\n *\n * `loading` outranks the tri-state for the reason `AccountEntryPoint` gives: an unresolved session\n * reports `anonymous`, so reading the state first would bounce a shopper who is signed in. A re-read\n * in flight reads as the same wait: the session it is checking is one the gate has stopped believing.\n */\nfunction resolveOutcome({\n signingOut,\n unconfirmed,\n revalidating,\n loading,\n state,\n wasSignedIn,\n hopSpent,\n}: {\n signingOut: boolean;\n unconfirmed: boolean;\n revalidating: boolean;\n loading: boolean;\n state: SessionState;\n wasSignedIn: boolean;\n hopSpent: boolean | null;\n}): AccountAccessGateOutcome {\n if (signingOut) {\n return 'stand-down';\n }\n // A re-read that could not answer says nothing about how the shopper got here, so the notice keeps\n // the history the gate already has. Telling someone who never reached the account that their session\n // ended names an event that never happened; the incomplete sign-in is the one they actually had.\n if (unconfirmed) {\n return wasSignedIn ? 'expired' : 'sign-in-incomplete';\n }\n if (revalidating || loading) {\n return 'loading';\n }\n if (state === 'loggedIn') {\n return 'account';\n }\n if (wasSignedIn) {\n return 'expired';\n }\n return hopSpent === true ? 'sign-in-incomplete' : 'signing-in';\n}\n\nfunction assertUnreachable(outcome: never): never {\n throw new Error(`[AccountAccessGate] unhandled outcome: ${String(outcome)}`);\n}\n\n/**\n * The look of a session that has not answered yet. A real part with its own hook rather than an ad hoc\n * spinner, so a store can style it and a story can render it.\n */\nexport function AccountAccessGateLoading({ className, children, ...props }: AccountAccessGateLoadingProps) {\n return (\n <output {...props} aria-live=\"polite\" className={className} data-fs-account-access-gate-loading=\"\">\n {children}\n </output>\n );\n}\n\n/**\n * What renders in the account's place when it will not open: the message for this reason, and a link\n * the shopper may take back into sign-in.\n *\n * The link is the whole of the escape from a sign-in loop. The gate stops redirecting after one\n * automatic hop, so the next attempt is a click rather than a bounce — and a shopper who keeps landing\n * here at least lands on a page that says so.\n */\nexport function AccountAccessGateNotice({\n reason,\n message,\n signInHref,\n signInLabel,\n className,\n ...props\n}: AccountAccessGateNoticeProps) {\n return (\n <output\n {...props}\n aria-live=\"polite\"\n className={className}\n data-fs-account-access-gate-notice=\"\"\n data-fs-account-access-gate-notice-reason={reason}\n >\n {message ? <span data-fs-account-access-gate-notice-message=\"\">{message}</span> : null}\n {signInLabel?.trim() ? (\n <NavigationLink\n href={signInHref}\n // The destination is a trampoline that redirects on mount, so the default prefetch would\n // fire that GET from a page the shopper may never leave.\n prefetch={false}\n data-fs-account-access-gate-notice-action=\"\"\n >\n {signInLabel}\n </NavigationLink>\n ) : null}\n </output>\n );\n}\n\n/**\n * Session storage, guarded at every access. A browser that refuses it — a shopper blocking site data —\n * throws rather than returning null, and a gate that cannot read its own record still has a shopper to\n * get to sign-in. A refusal therefore reads as \"no record\", which spends the hop; the cost is that the\n * loop protection is absent in that browser, which is the lesser of the two failures.\n */\nfunction readSignInAttempt(): string | null {\n try {\n return globalThis.sessionStorage.getItem(SIGN_IN_ATTEMPT_KEY);\n } catch {\n return null;\n }\n}\n\nfunction recordSignInAttempt(destination: string): void {\n try {\n globalThis.sessionStorage.setItem(SIGN_IN_ATTEMPT_KEY, destination);\n } catch {\n // Nothing to fall back to: the record is the only thing that outlives the hop.\n }\n}\n\nfunction clearSignInAttempt(): void {\n try {\n globalThis.sessionStorage.removeItem(SIGN_IN_ATTEMPT_KEY);\n } catch {\n // Nothing was written either, so there is nothing to undo.\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAa,2BAA2B,kBAAkB;CACxD,IAAI;CACJ,OAAO;CACP,aAAa;CACb,QAAQ;EACN,MAAM;EACN,sBAAsB;EACtB,YAAY;GACV,cAAc;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAuB;GAC5E,gBAAgB;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAwB;GAC/E,yBAAyB;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAmC;GACnG,aAAa;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAqB;EAC3E;CACF;AACF,CAAC;AAsCD,MAAa,8BAA8B,gBAAwC;CACjF,MAAM;CACN,YAAY;CACZ,WAAW;CACX,SAAS;CACT,QAAQ;EAAE,OAAO;E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Q;EACN,OAAO;CACT;AACF;AAEA,SAAS,oBAAoB,aAA2B;CACtD,IAAI;EACF,WAAW,eAAe,QAAQ,qBAAqB,WAAW;CACpE,QAAQ,CAER;AACF;AAEA,SAAS,qBAA2B;CAClC,IAAI;EACF,WAAW,eAAe,WAAW,mBAAmB;CAC1D,QAAQ,CAER;AACF"}
|
|
1
|
+
{"version":3,"file":"account-access-gate.js","names":[],"sources":["../../../src/matter/account-access-gate/account-access-gate.tsx"],"sourcesContent":["'use client';\n\nimport { type ContentValue, defineComponent, defineContentType } from '@vtex/fs-core';\nimport { type ComponentPropsWithRef, type ReactNode, useEffect, useRef, useState } from 'react';\nimport { flushSync } from 'react-dom';\nimport { NavigationLink } from '../../particles/navigation-link/navigation-link.js';\nimport type { PageRef } from '../../sdk/navigation/types.js';\nimport { useStorefrontNavigation } from '../../sdk/navigation/use-storefront-navigation.js';\nimport { useStorefrontRoute } from '../../sdk/navigation/use-storefront-route.js';\nimport { useSessionRevalidation } from '../../sdk/session/use-session-revalidation.js';\nimport { signInTarget } from '../../utils/safe-href.js';\nimport { type SessionState, useSession } from '../session/session.js';\nimport { useSignOutIntent, withdrawSignOutIntent } from './sign-out-intent.js';\n\n// Nothing is required, following the shipped identity components: an entry may author any subset, and\n// a slice missing a required property is shape-invalid, which drops the whole element rather than the\n// one field.\nexport const AccountAccessGateContent = defineContentType({\n id: 'account-access-gate',\n title: 'Account Access Gate',\n description: 'What the shopper is told while the account resolves and when it will not open for them.',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n loadingLabel: { type: 'string', minLength: 1, title: 'Loading announcement' },\n expiredMessage: { type: 'string', minLength: 1, title: 'Session ended message' },\n signInIncompleteMessage: { type: 'string', minLength: 1, title: 'Sign-in did not complete message' },\n signInLabel: { type: 'string', minLength: 1, title: 'Sign-in link label' },\n },\n },\n});\n\n/** Why the account will not open, as a bounded value: a style target and the choice of message. */\nexport type AccountAccessGateNoticeReason = 'expired' | 'sign-in-incomplete';\n\n/** Props for {@link AccountAccessGate}. It renders a different element per outcome and forwards no\n * element props of its own; each rendered part carries its own. */\nexport type AccountAccessGateProps = {\n /** Text announced while the session resolves. */\n loadingLabel?: string;\n /** What a shopper whose session ended mid-visit is told. */\n expiredMessage?: string;\n /** What a shopper who came back from sign-in still signed out is told. */\n signInIncompleteMessage?: string;\n /** Label of the link out of either notice. Without it no link renders — a focusable link a screen\n * reader announces as its bare URL is worse than no control at all. */\n signInLabel?: string;\n /** Merchant-authored fields, sliced from the layout content entry; win over the props field by field\n * when present. Absent in a non-CMS store — the props are the fallback. */\n $content?: ContentValue<typeof AccountAccessGateContent>;\n /** The account. Rendered only for a signed-in shopper. */\n children?: ReactNode;\n};\n\n/** Props for {@link AccountAccessGateLoading}. Extends native `<output>` attributes. */\nexport type AccountAccessGateLoadingProps = ComponentPropsWithRef<'output'>;\n\n/** Props for {@link AccountAccessGateNotice}. Extends native `<output>` attributes. */\nexport type AccountAccessGateNoticeProps = Omit<ComponentPropsWithRef<'output'>, 'children'> & {\n reason: AccountAccessGateNoticeReason;\n /** The message for this reason. Nothing renders in its place when unauthored. */\n message?: string;\n /** Where the link out leads, built by the gate from the page the shopper is on. */\n signInHref: PageRef | string;\n /** Label of the link out. No label, no link. */\n signInLabel?: string;\n};\n\nexport const AccountAccessGateDefinition = defineComponent<AccountAccessGateProps>({\n name: 'AccountAccessGate',\n importPath: '@vtex/faststore/components',\n component: AccountAccessGate,\n content: AccountAccessGateContent,\n editor: { label: 'Account Access Gate', category: 'identity' },\n requiresContext: 'session',\n schema: {\n // Mirrored from the content model on purpose, as every content-bearing component in the library\n // does: the entry wins when published, and this is what a store without a CMS authors.\n loadingLabel: { type: 'string', label: 'Loading Announcement' },\n expiredMessage: { type: 'string', label: 'Session Ended Message' },\n signInIncompleteMessage: { type: 'string', label: 'Sign-in Did Not Complete Message' },\n signInLabel: { type: 'string', label: 'Sign-in Link Label' },\n },\n guideline:\n \"The account's single access decision: place it once in the account layout, wrapping the body, and every page that declares that layout inherits it — never restate it per section. It renders its children only for a logged-in shopper; it shows a composed loading look while the session resolves, replaces the current history entry with the sign-in destination for a visitor who arrived signed out (identified counts as signed out), tells a shopper whose session ended mid-visit rather than bouncing them, and stands down while AccountMenuSignOut navigates. It redirects at most once per visit: a shopper who comes back from sign-in still signed out gets a message and a link rather than a second hop. Must be inside SessionRoot, which the same layout hosts. Never place the sign-in page under it — the gate redirects there, and a gated sign-in page would redirect to itself.\",\n});\n\n/** The one automatic hop the gate has already spent, surviving the full document load out to the\n * platform and back, and no further than this tab. */\nconst SIGN_IN_ATTEMPT_KEY = 'fs::account-access-gate::sign-in-attempt';\n\n/**\n * What the gate renders, in precedence order. `signing-in` covers both the frame that decides whether\n * the hop is still available and the frame after the replace is issued: they render the same nothing,\n * and only the effect tells them apart.\n */\ntype AccountAccessGateOutcome = 'stand-down' | 'expired' | 'loading' | 'account' | 'sign-in-incomplete' | 'signing-in';\n\nexport function AccountAccessGate({\n loadingLabel,\n expiredMessage,\n signInIncompleteMessage,\n signInLabel,\n $content,\n children,\n}: Readonly<AccountAccessGateProps>) {\n const { state, loading } = useSession();\n const signingOut = useSignOutIntent();\n // `search` is `null` on the server and during hydration, and re-read on every render of the gate:\n // a shopper who pages through their orders changes only the query.\n const { path, search } = useStorefrontRoute();\n const { hrefFor, replace } = useStorefrontNavigation();\n const revalidate = useSessionRevalidation();\n\n // Whether this gate has ever resolved to a signed-in shopper. It is what separates a session that\n // ended from a visitor who arrived signed out — the tri-state spells both `anonymous`.\n const [wasSignedIn, setWasSignedIn] = useState(false);\n // A revalidation that could not answer. It outranks `loading` because the discard that preceded it\n // is what leaves the session unresolved, so nothing else is coming to end that wait.\n const [unconfirmed, setUnconfirmed] = useState(false);\n // A re-read in flight. The gate withholds the account for itself rather than waiting to be told:\n // discarding the cached session leaves the data layer unresolved, but it reaches the gate only once\n // the watched query has re-read, and the account must be gone in the frame the restore arrives.\n const [revalidating, setRevalidating] = useState(false);\n // Which re-read the gate is still listening to. Two restores in a row put two answers in flight, and\n // the older one may land last.\n const restoreGeneration = useRef(0);\n // `null` until the arrival path has read the record. Read from an effect rather than from the render\n // body: session storage does not exist on the server, and a value that appeared between the server\n // pass and hydration would change what renders underneath it.\n const [hopSpent, setHopSpent] = useState<boolean | null>(null);\n\n // Where the shopper comes back to: the logical path, which the sign-in route prefixes on the way back.\n // The path alone would return someone reading `/pvt/orders?page=2` to the first page of it.\n const returnPath = `${path}${search ?? ''}`;\n\n const outcome = resolveOutcome({ signingOut, unconfirmed, revalidating, loading, state, wasSignedIn, hopSpent });\n\n useEffect(() => {\n switch (outcome) {\n case 'account':\n setWasSignedIn(true);\n setUnconfirmed(false);\n clearSignInAttempt();\n return;\n case 'expired':\n case 'sign-in-incomplete':\n // Every outcome that is not the hop returns it: a shopper who signs in, browses, and comes\n // back later arrives fresh rather than carrying a spent attempt from an earlier one.\n clearSignInAttempt();\n return;\n case 'signing-in': {\n // One more frame before deciding, until the document has been read: a hop recorded against the\n // bare path is the one the shopper comes back to, and there is no second chance at it.\n if (hopSpent !== null || search === null) {\n return;\n }\n if (readSignInAttempt() !== null) {\n setHopSpent(true);\n return;\n }\n const target = signInTarget(returnPath);\n // The record is the resolved href, but the navigation takes the target: `replace` adds the\n // binding's base path, and handing it the href would add it twice.\n const destination = hrefFor(target);\n // A store with no sign-in page has nowhere to send the shopper. `hrefFor` already logged it;\n // the notice is what keeps the page from staying blank.\n if (destination === null) {\n setHopSpent(true);\n return;\n }\n recordSignInAttempt(destination);\n setHopSpent(false);\n // Replace rather than push: back from the platform's login should reach the page the shopper\n // came from, not the account that threw them at it.\n // react-doctor-disable-next-line nextjs-no-client-side-redirect -- the session resolves on the client, so the server has nothing to decide with\n replace(target);\n return;\n }\n case 'stand-down':\n case 'loading':\n return;\n default:\n assertUnreachable(outcome);\n }\n }, [outcome, hopSpent, search, returnPath, hrefFor, replace]);\n\n useEffect(() => {\n function handlePageHide(event: PageTransitionEvent): void {\n if (!event.persisted) {\n return;\n }\n // What the browser freezes is the DOM, and a restore puts that same DOM back before any script\n // runs. Standing the account down on the way out rather than on the way back is what keeps the\n // restored document from showing it in the frames before `pageshow` can decide again.\n flushSync(() => {\n setRevalidating(true);\n });\n }\n\n function handlePageShow(event: PageTransitionEvent): void {\n // An ordinary load re-decides by mounting. Only a restore resumes a heap that already holds an\n // answer, and `persisted` is the browser's own word for it.\n if (!event.persisted) {\n return;\n }\n const generation = restoreGeneration.current + 1;\n restoreGeneration.current = generation;\n // The navigation this authorized has already happened; a restored document holding it would\n // stand down forever. Withdrawn before the re-read so the gate is deciding again by the time\n // the answer lands.\n withdrawSignOutIntent();\n setUnconfirmed(false);\n setRevalidating(true);\n void revalidate().then((result) => {\n // A later restore has already asked the same question, and its answer is the one that counts.\n // This one describes a session the gate has since discarded a second time.\n if (generation !== restoreGeneration.current) {\n return;\n }\n setRevalidating(false);\n switch (result) {\n case 'failed':\n setUnconfirmed(true);\n return;\n case 'revalidated':\n case 'unavailable':\n // Nothing left to distrust: either the session was re-read, or there was no cached\n // session to discard in the first place and the one in the tree came from a prop.\n return;\n default:\n assertUnreachable(result);\n }\n });\n }\n\n globalThis.addEventListener('pagehide', handlePageHide);\n globalThis.addEventListener('pageshow', handlePageShow);\n return () => {\n globalThis.removeEventListener('pagehide', handlePageHide);\n globalThis.removeEventListener('pageshow', handlePageShow);\n };\n }, [revalidate]);\n\n // The intent authorizes one transition and this gate is its only reader, so it must not survive the\n // gate. A sign-out that navigates client-side takes the account layout down without reloading the\n // document, and nothing else would ever take the flag back: the next account page the shopper opens\n // would mount into a standing intent and render nothing at all, with no error to explain it.\n useEffect(() => withdrawSignOutIntent, []);\n\n // Blank entry fields fall through, so clearing one in the Admin reads as unauthored.\n const entryLoadingLabel = $content?.loadingLabel?.trim() ? $content.loadingLabel : loadingLabel;\n const entryExpiredMessage = $content?.expiredMessage?.trim() ? $content.expiredMessage : expiredMessage;\n const entryIncompleteMessage = $content?.signInIncompleteMessage?.trim()\n ? $content.signInIncompleteMessage\n : signInIncompleteMessage;\n const entrySignInLabel = $content?.signInLabel?.trim() ? $content.signInLabel : signInLabel;\n\n switch (outcome) {\n case 'stand-down':\n case 'signing-in':\n return null;\n case 'loading':\n return (\n // The part carries its own hook; the component's identity travels from here, which is how a\n // store targets it by name the way every other component is targeted.\n <AccountAccessGateLoading data-fs-account-access-gate=\"\">{entryLoadingLabel}</AccountAccessGateLoading>\n );\n case 'account':\n return <>{children}</>;\n case 'expired':\n case 'sign-in-incomplete':\n return (\n <AccountAccessGateNotice\n data-fs-account-access-gate=\"\"\n reason={outcome === 'expired' ? 'expired' : 'sign-in-incomplete'}\n message={outcome === 'expired' ? entryExpiredMessage : entryIncompleteMessage}\n signInHref={signInTarget(returnPath)}\n signInLabel={entrySignInLabel}\n />\n );\n default:\n return assertUnreachable(outcome);\n }\n}\n\n/**\n * The whole decision, as one ordered read of the gate's inputs.\n *\n * `signingOut` outranks everything, including a session still reading `loggedIn`: the sign-out records\n * its intent before it awaits the mutation, and the frame between the payload landing and the document\n * load starting is exactly the one this ordering protects.\n *\n * `loading` outranks the tri-state for the reason `AccountEntryPoint` gives: an unresolved session\n * reports `anonymous`, so reading the state first would bounce a shopper who is signed in. A re-read\n * in flight reads as the same wait: the session it is checking is one the gate has stopped believing.\n */\nfunction resolveOutcome({\n signingOut,\n unconfirmed,\n revalidating,\n loading,\n state,\n wasSignedIn,\n hopSpent,\n}: {\n signingOut: boolean;\n unconfirmed: boolean;\n revalidating: boolean;\n loading: boolean;\n state: SessionState;\n wasSignedIn: boolean;\n hopSpent: boolean | null;\n}): AccountAccessGateOutcome {\n if (signingOut) {\n return 'stand-down';\n }\n // A re-read that could not answer says nothing about how the shopper got here, so the notice keeps\n // the history the gate already has. Telling someone who never reached the account that their session\n // ended names an event that never happened; the incomplete sign-in is the one they actually had.\n if (unconfirmed) {\n return wasSignedIn ? 'expired' : 'sign-in-incomplete';\n }\n if (revalidating || loading) {\n return 'loading';\n }\n if (state === 'loggedIn') {\n return 'account';\n }\n if (wasSignedIn) {\n return 'expired';\n }\n return hopSpent === true ? 'sign-in-incomplete' : 'signing-in';\n}\n\nfunction assertUnreachable(outcome: never): never {\n throw new Error(`[AccountAccessGate] unhandled outcome: ${String(outcome)}`);\n}\n\n/**\n * The look of a session that has not answered yet. A real part with its own hook rather than an ad hoc\n * spinner, so a store can style it and a story can render it.\n */\nexport function AccountAccessGateLoading({ className, children, ...props }: AccountAccessGateLoadingProps) {\n return (\n <output {...props} aria-live=\"polite\" className={className} data-fs-account-access-gate-loading=\"\">\n {children}\n </output>\n );\n}\n\n/**\n * What renders in the account's place when it will not open: the message for this reason, and a link\n * the shopper may take back into sign-in.\n *\n * The link is the whole of the escape from a sign-in loop. The gate stops redirecting after one\n * automatic hop, so the next attempt is a click rather than a bounce — and a shopper who keeps landing\n * here at least lands on a page that says so.\n */\nexport function AccountAccessGateNotice({\n reason,\n message,\n signInHref,\n signInLabel,\n className,\n ...props\n}: AccountAccessGateNoticeProps) {\n return (\n <output\n {...props}\n aria-live=\"polite\"\n className={className}\n data-fs-account-access-gate-notice=\"\"\n data-fs-account-access-gate-notice-reason={reason}\n >\n {message ? <span data-fs-account-access-gate-notice-message=\"\">{message}</span> : null}\n {signInLabel?.trim() ? (\n <NavigationLink\n href={signInHref}\n // The destination is a trampoline that redirects on mount, so the default prefetch would\n // fire that GET from a page the shopper may never leave.\n prefetch={false}\n data-fs-account-access-gate-notice-action=\"\"\n >\n {signInLabel}\n </NavigationLink>\n ) : null}\n </output>\n );\n}\n\n/**\n * Session storage, guarded at every access. A browser that refuses it — a shopper blocking site data —\n * throws rather than returning null, and a gate that cannot read its own record still has a shopper to\n * get to sign-in. A refusal therefore reads as \"no record\", which spends the hop; the cost is that the\n * loop protection is absent in that browser, which is the lesser of the two failures.\n */\nfunction readSignInAttempt(): string | null {\n try {\n return globalThis.sessionStorage.getItem(SIGN_IN_ATTEMPT_KEY);\n } catch {\n return null;\n }\n}\n\nfunction recordSignInAttempt(destination: string): void {\n try {\n globalThis.sessionStorage.setItem(SIGN_IN_ATTEMPT_KEY, destination);\n } catch {\n // Nothing to fall back to: the record is the only thing that outlives the hop.\n }\n}\n\nfunction clearSignInAttempt(): void {\n try {\n globalThis.sessionStorage.removeItem(SIGN_IN_ATTEMPT_KEY);\n } catch {\n // Nothing was written either, so there is nothing to undo.\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,2BAA2B,kBAAkB;CACxD,IAAI;CACJ,OAAO;CACP,aAAa;CACb,QAAQ;EACN,MAAM;EACN,sBAAsB;EACtB,YAAY;GACV,cAAc;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAuB;GAC5E,gBAAgB;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAwB;GAC/E,yBAAyB;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAmC;GACnG,aAAa;IAAE,MAAM;IAAU,WAAW;IAAG,OAAO;GAAqB;EAC3E;CACF;AACF,CAAC;AAsCD,MAAa,8BAA8B,gBAAwC;CACjF,MAAM;CACN,YAAY;CACZ,WAAW;CACX,SAAS;CACT,QAAQ;EAAE,OAAO;EAAuB,UAAU;CAAW;CAC7D,iBAAiB;CACjB,QAAQ;EAGN,cAAc;GAAE,MAAM;GAAU,OAAO;EAAuB;EAC9D,gBAAgB;GAAE,MAAM;GAAU,OAAO;EAAwB;EACjE,yBAAyB;GAAE,MAAM;GAAU,OAAO;EAAmC;EACrF,aAAa;GAAE,MAAM;GAAU,OAAO;EAAqB;CAC7D;CACA,WACE;AACJ,CAAC;;;AAID,MAAM,sBAAsB;AAS5B,SAAgB,kBAAkB,EAChC,cACA,gBACA,yBACA,aACA,UACA,YACmC;CACnC,MAAM,EAAE,OAAO,YAAY,WAAW;CACtC,MAAM,aAAa,iBAAiB;CAGpC,MAAM,EAAE,MAAM,WAAW,mBAAmB;CAC5C,MAAM,EAAE,SAAS,YAAY,wBAAwB;CACrD,MAAM,aAAa,uBAAuB;CAI1C,MAAM,CAAC,aAAa,kBAAkB,SAAS,KA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AAS,kBAAkB,SAAuB;CAChD,MAAM,IAAI,MAAM,0CAA0C,OAAO,OAAO,GAAG;AAC7E;;;;;AAMA,SAAgB,yBAAyB,EAAE,WAAW,UAAU,GAAG,SAAwC;CACzG,OACE,oBAAC,UAAD;EAAQ,GAAI;EAAO,aAAU;EAAoB;EAAW,uCAAoC;EAC7F;CACK,CAAA;AAEZ;;;;;;;;;AAUA,SAAgB,wBAAwB,EACtC,QACA,SACA,YACA,aACA,WACA,GAAG,SAC4B;CAC/B,OACE,qBAAC,UAAD;EACE,GAAI;EACJ,aAAU;EACC;EACX,sCAAmC;EACnC,6CAA2C;EAL7C,UAAA,CAOG,UAAU,oBAAC,QAAD;GAAM,8CAA2C;GAAI,UAAA;EAAc,CAAA,IAAI,MACjF,aAAa,KAAK,IACjB,oBAAC,gBAAD;GACE,MAAM;GAGN,UAAU;GACV,6CAA0C;GAEzC,UAAA;EACa,CAAA,IACd,IACE;;AAEZ;;;;;;;AAQA,SAAS,oBAAmC;CAC1C,IAAI;EACF,OAAO,WAAW,eAAe,QAAQ,mBAAmB;CAC9D,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,oBAAoB,aAA2B;CACtD,IAAI;EACF,WAAW,eAAe,QAAQ,qBAAqB,WAAW;CACpE,QAAQ,CAER;AACF;AAEA,SAAS,qBAA2B;CAClC,IAAI;EACF,WAAW,eAAe,WAAW,mBAAmB;CAC1D,QAAQ,CAER;AACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ComponentDefinition } from "../../core/dist/define-component.js";
|
|
2
|
+
import "../../core/dist/index.js";
|
|
3
|
+
import { ComponentActions } from "../../sdk/actions/types.js";
|
|
4
|
+
import { ComponentPropsWithRef } from "react";
|
|
5
|
+
//#region src/matter/account-address-book/account-address-book-delete.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Deleting an address (specs/sfs-3437-address-book-delete.md, RFC REQ-04). The book's root holds which
|
|
8
|
+
* address is waiting for an answer; a trigger in each entry asks, and one confirmation under the root
|
|
9
|
+
* puts the question and dispatches `$actions.address.remove`. The confirmation never edits the list:
|
|
10
|
+
* the entry leaves through the cache edit the action makes.
|
|
11
|
+
*/
|
|
12
|
+
export type AccountAddressBookDeleteTriggerProps = ComponentPropsWithRef<'button'> & {
|
|
13
|
+
/** The button's visible text. A blank value falls back to the catalog copy. */
|
|
14
|
+
label?: string;
|
|
15
|
+
};
|
|
16
|
+
export type AccountAddressBookDeleteConfirmProps = Readonly<{
|
|
17
|
+
/** Goes on the popup, the one element a store can size and place: the dialog renders in a portal. */
|
|
18
|
+
className?: string;
|
|
19
|
+
/** The question. A blank value falls back to the catalog copy. */
|
|
20
|
+
title?: string;
|
|
21
|
+
/** What deleting means. The address's first line always shows before it. A blank value falls back to the catalog copy. */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** The label of the control that backs out. A blank value falls back to the catalog copy. */
|
|
24
|
+
cancelLabel?: string;
|
|
25
|
+
/** The label of the control that deletes. A blank value falls back to the catalog copy. */
|
|
26
|
+
confirmLabel?: string;
|
|
27
|
+
/** Toast after the address is deleted. A blank value falls back to the catalog copy. */
|
|
28
|
+
deletedMessage?: string;
|
|
29
|
+
/** Shown in the prompt when the address was not deleted. A blank value falls back to the catalog copy. */
|
|
30
|
+
failedMessage?: string;
|
|
31
|
+
/** Shown in the prompt when the session expired. A blank value falls back to the catalog copy. */
|
|
32
|
+
unauthorizedMessage?: string;
|
|
33
|
+
/** Injected by the compiler from `actions: { address: [...] }`; the address write surface. */
|
|
34
|
+
$actions?: ComponentActions;
|
|
35
|
+
}>;
|
|
36
|
+
export declare function AccountAddressBookDeleteTrigger({ label, className, children, onClick, ...props }: AccountAddressBookDeleteTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare function AccountAddressBookDeleteConfirm({ className, title, description, cancelLabel, confirmLabel, deletedMessage, failedMessage, unauthorizedMessage, $actions: $actionsProp }: AccountAddressBookDeleteConfirmProps): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare const AccountAddressBookDeleteTriggerDefinition: ComponentDefinition<AccountAddressBookDeleteTriggerProps>;
|
|
39
|
+
export declare const AccountAddressBookDeleteConfirmDefinition: ComponentDefinition<Readonly<{
|
|
40
|
+
/** Goes on the popup, the one element a store can size and place: the dialog renders in a portal. */
|
|
41
|
+
className?: string;
|
|
42
|
+
/** The question. A blank value falls back to the catalog copy. */
|
|
43
|
+
title?: string;
|
|
44
|
+
/** What deleting means. The address's first line always shows before it. A blank value falls back to the catalog copy. */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** The label of the control that backs out. A blank value falls back to the catalog copy. */
|
|
47
|
+
cancelLabel?: string;
|
|
48
|
+
/** The label of the control that deletes. A blank value falls back to the catalog copy. */
|
|
49
|
+
confirmLabel?: string;
|
|
50
|
+
/** Toast after the address is deleted. A blank value falls back to the catalog copy. */
|
|
51
|
+
deletedMessage?: string;
|
|
52
|
+
/** Shown in the prompt when the address was not deleted. A blank value falls back to the catalog copy. */
|
|
53
|
+
failedMessage?: string;
|
|
54
|
+
/** Shown in the prompt when the session expired. A blank value falls back to the catalog copy. */
|
|
55
|
+
unauthorizedMessage?: string;
|
|
56
|
+
/** Injected by the compiler from `actions: { address: [...] }`; the address write surface. */
|
|
57
|
+
$actions?: ComponentActions;
|
|
58
|
+
}>>;
|
|
59
|
+
//#endregion
|
|
60
|
+
//# sourceMappingURL=account-address-book-delete.d.ts.map
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { defineComponent } from "../../core/dist/define-component.js";
|
|
3
|
+
import "../../core/dist/index.js";
|
|
4
|
+
import { useIntl } from "../../sdk/i18n/client.js";
|
|
5
|
+
import { useActionsOverride } from "../../sdk/actions/actions-override-context.js";
|
|
6
|
+
import { resolveAuthoredCopy } from "../../utils/resolve-authored-copy.js";
|
|
7
|
+
import { loggableErrorName } from "../../utils/loggable-error-name.js";
|
|
8
|
+
import { Button } from "../../particles/button/button.js";
|
|
9
|
+
import { useAccountAddressBook, useAccountAddressBookItem } from "./account-address-book.js";
|
|
10
|
+
import { AlertDialog } from "../../particles/alert-dialog/alert-dialog.js";
|
|
11
|
+
import { useToast } from "../../particles/toast/toast.js";
|
|
12
|
+
import { firstLine } from "./account-address-first-line.js";
|
|
13
|
+
import { useRef, useState } from "react";
|
|
14
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
//#region src/matter/account-address-book/account-address-book-delete.tsx
|
|
16
|
+
/**
|
|
17
|
+
* What a result means for the prompt. An empty result is a removal, and so is `NOT_FOUND`: the server no
|
|
18
|
+
* longer has the address, which is what the shopper asked for, and the action already took it out of
|
|
19
|
+
* the cache. Anything else leaves the address listed.
|
|
20
|
+
*/
|
|
21
|
+
function deleteError(userErrors) {
|
|
22
|
+
if (userErrors.length === 0 || userErrors.some(({ code }) => code === "NOT_FOUND")) return null;
|
|
23
|
+
return userErrors.some(({ code }) => code === "UNAUTHORIZED") ? "unauthorized" : "deleteFailed";
|
|
24
|
+
}
|
|
25
|
+
function AccountAddressBookDeleteTrigger({ label, className, children, onClick, ...props }) {
|
|
26
|
+
const { requestDelete } = useAccountAddressBook();
|
|
27
|
+
const address = useAccountAddressBookItem();
|
|
28
|
+
const intl = useIntl();
|
|
29
|
+
const text = resolveAuthoredCopy(label, intl.formatMessage({ id: "fs/address-delete.trigger" }));
|
|
30
|
+
const line = firstLine(address);
|
|
31
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
32
|
+
"aria-label": line === "" ? void 0 : `${text} ${line}`,
|
|
33
|
+
...props,
|
|
34
|
+
type: "button",
|
|
35
|
+
className,
|
|
36
|
+
onClick: (event) => {
|
|
37
|
+
onClick?.(event);
|
|
38
|
+
requestDelete(address, event.currentTarget);
|
|
39
|
+
},
|
|
40
|
+
"data-fs-account-address-book-delete": "",
|
|
41
|
+
children: children ?? text
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function AccountAddressBookDeleteConfirm({ className, title, description, cancelLabel, confirmLabel, deletedMessage, failedMessage, unauthorizedMessage, $actions: $actionsProp }) {
|
|
45
|
+
const toast = useToast();
|
|
46
|
+
const intl = useIntl();
|
|
47
|
+
const $actions = useActionsOverride($actionsProp);
|
|
48
|
+
const { pendingDelete, endDelete, openForm, close } = useAccountAddressBook();
|
|
49
|
+
const [pending, setPending] = useState(false);
|
|
50
|
+
const pendingRef = useRef(false);
|
|
51
|
+
const [error, setError] = useState(null);
|
|
52
|
+
const line = pendingDelete ? firstLine(pendingDelete) : "";
|
|
53
|
+
const errorMessage = error === "unauthorized" ? resolveAuthoredCopy(unauthorizedMessage, intl.formatMessage({ id: "fs/address-delete.error.unauthorized" })) : resolveAuthoredCopy(failedMessage, intl.formatMessage({ id: "fs/address-delete.error.failed" }));
|
|
54
|
+
function finish() {
|
|
55
|
+
setError(null);
|
|
56
|
+
endDelete();
|
|
57
|
+
}
|
|
58
|
+
function deleted(id) {
|
|
59
|
+
toast.add({
|
|
60
|
+
title: resolveAuthoredCopy(deletedMessage, intl.formatMessage({ id: "fs/address-delete.deleted" })),
|
|
61
|
+
type: "success"
|
|
62
|
+
});
|
|
63
|
+
if (openForm?.mode === "edit" && openForm.address.id === id) close();
|
|
64
|
+
finish();
|
|
65
|
+
}
|
|
66
|
+
async function confirm() {
|
|
67
|
+
if (pendingRef.current || pendingDelete === null) return;
|
|
68
|
+
const remove = $actions?.address?.remove;
|
|
69
|
+
if (!remove) {
|
|
70
|
+
setError("deleteFailed");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const { id } = pendingDelete;
|
|
74
|
+
pendingRef.current = true;
|
|
75
|
+
setPending(true);
|
|
76
|
+
setError(null);
|
|
77
|
+
try {
|
|
78
|
+
const failure = deleteError(await remove({ id }));
|
|
79
|
+
if (failure) setError(failure);
|
|
80
|
+
else deleted(id);
|
|
81
|
+
} catch (error_) {
|
|
82
|
+
console.error("[AccountAddressBookDeleteConfirm] address.remove failed", loggableErrorName(error_));
|
|
83
|
+
setError("deleteFailed");
|
|
84
|
+
} finally {
|
|
85
|
+
pendingRef.current = false;
|
|
86
|
+
setPending(false);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return /* @__PURE__ */ jsx(AlertDialog.Root, {
|
|
90
|
+
open: pendingDelete !== null,
|
|
91
|
+
onOpenChange: (next) => {
|
|
92
|
+
if (!next && !pendingRef.current) finish();
|
|
93
|
+
},
|
|
94
|
+
children: /* @__PURE__ */ jsxs(AlertDialog.Portal, { children: [/* @__PURE__ */ jsx(AlertDialog.Backdrop, {}), /* @__PURE__ */ jsx(AlertDialog.Viewport, { children: /* @__PURE__ */ jsxs(AlertDialog.Popup, {
|
|
95
|
+
className,
|
|
96
|
+
"data-fs-account-address-book-delete-confirm": "",
|
|
97
|
+
children: [
|
|
98
|
+
/* @__PURE__ */ jsx(AlertDialog.Title, { children: resolveAuthoredCopy(title, intl.formatMessage({ id: "fs/address-delete.title" })) }),
|
|
99
|
+
/* @__PURE__ */ jsxs(AlertDialog.Description, { children: [line === "" ? null : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
100
|
+
"data-fs-account-address-book-delete-address": "",
|
|
101
|
+
children: line
|
|
102
|
+
}), " "] }), resolveAuthoredCopy(description, intl.formatMessage({ id: "fs/address-delete.description" }))] }),
|
|
103
|
+
error === null ? null : /* @__PURE__ */ jsx("p", {
|
|
104
|
+
role: "alert",
|
|
105
|
+
"data-fs-account-address-book-delete-error": "",
|
|
106
|
+
children: errorMessage
|
|
107
|
+
}),
|
|
108
|
+
/* @__PURE__ */ jsx(AlertDialog.Close, {
|
|
109
|
+
disabled: pending,
|
|
110
|
+
children: resolveAuthoredCopy(cancelLabel, intl.formatMessage({ id: "fs/address-delete.cancel" }))
|
|
111
|
+
}),
|
|
112
|
+
/* @__PURE__ */ jsx(Button, {
|
|
113
|
+
type: "button",
|
|
114
|
+
disabled: pending,
|
|
115
|
+
"aria-busy": pending || void 0,
|
|
116
|
+
onClick: confirm,
|
|
117
|
+
"data-fs-account-address-book-delete-submit": "",
|
|
118
|
+
children: resolveAuthoredCopy(confirmLabel, intl.formatMessage({ id: "fs/address-delete.confirm" }))
|
|
119
|
+
})
|
|
120
|
+
]
|
|
121
|
+
}) })] })
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const AccountAddressBookDeleteTriggerDefinition = defineComponent({
|
|
125
|
+
name: "AccountAddressBookDeleteTrigger",
|
|
126
|
+
importPath: "@vtex/faststore/components",
|
|
127
|
+
component: AccountAddressBookDeleteTrigger,
|
|
128
|
+
requiresContext: "account-address-book-item",
|
|
129
|
+
editor: {
|
|
130
|
+
label: "Account Address Book Delete Trigger",
|
|
131
|
+
category: "action"
|
|
132
|
+
},
|
|
133
|
+
schema: { label: {
|
|
134
|
+
type: "string",
|
|
135
|
+
label: "Button label"
|
|
136
|
+
} },
|
|
137
|
+
guideline: "Asks to delete the address of the entry it sits in. Nothing is deleted until the shopper confirms in an AccountAddressBookDeleteConfirm. Its accessible name adds the address's first line, so a list of them is told apart. Place it inside AccountAddressBookItem, and one AccountAddressBookDeleteConfirm under the root to ask the question."
|
|
138
|
+
});
|
|
139
|
+
const AccountAddressBookDeleteConfirmDefinition = defineComponent({
|
|
140
|
+
name: "AccountAddressBookDeleteConfirm",
|
|
141
|
+
importPath: "@vtex/faststore/components",
|
|
142
|
+
component: AccountAddressBookDeleteConfirm,
|
|
143
|
+
requiresContext: "account-address-book",
|
|
144
|
+
actions: { address: ["remove"] },
|
|
145
|
+
editor: {
|
|
146
|
+
label: "Account Address Book Delete Confirm",
|
|
147
|
+
category: "layout"
|
|
148
|
+
},
|
|
149
|
+
schema: {
|
|
150
|
+
title: {
|
|
151
|
+
type: "string",
|
|
152
|
+
label: "Question"
|
|
153
|
+
},
|
|
154
|
+
description: {
|
|
155
|
+
type: "string",
|
|
156
|
+
label: "What deleting means"
|
|
157
|
+
},
|
|
158
|
+
cancelLabel: {
|
|
159
|
+
type: "string",
|
|
160
|
+
label: "Cancel label"
|
|
161
|
+
},
|
|
162
|
+
confirmLabel: {
|
|
163
|
+
type: "string",
|
|
164
|
+
label: "Delete label"
|
|
165
|
+
},
|
|
166
|
+
deletedMessage: {
|
|
167
|
+
type: "string",
|
|
168
|
+
label: "Address deleted message"
|
|
169
|
+
},
|
|
170
|
+
failedMessage: {
|
|
171
|
+
type: "string",
|
|
172
|
+
label: "Not deleted message"
|
|
173
|
+
},
|
|
174
|
+
unauthorizedMessage: {
|
|
175
|
+
type: "string",
|
|
176
|
+
label: "Session expired message"
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
guideline: "The alert dialog that asks before an address is deleted, one per address book, opened by AccountAddressBookDeleteTrigger. Names the address, takes focus on Cancel, and closes only on Cancel or Escape: a click outside does nothing. Confirming removes the address, shows a toast and closes; a refusal keeps the dialog open with a message and lets the shopper try again. While the call runs, nothing closes it. Deleting the last address leaves the book empty, so compose an AccountAddressBookEmpty. Requires a ToastProvider ancestor, since the success toast throws without one. Place it under AccountAddressBookRoot. See account-address-book.md."
|
|
180
|
+
});
|
|
181
|
+
//#endregion
|
|
182
|
+
export { AccountAddressBookDeleteConfirm, AccountAddressBookDeleteConfirmDefinition, AccountAddressBookDeleteTrigger, AccountAddressBookDeleteTriggerDefinition };
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=account-address-book-delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-address-book-delete.js","names":[],"sources":["../../../src/matter/account-address-book/account-address-book-delete.tsx"],"sourcesContent":["'use client';\n\nimport { defineComponent } from '@vtex/fs-core';\nimport { type ComponentPropsWithRef, useRef, useState } from 'react';\nimport { AlertDialog } from '../../particles/alert-dialog/alert-dialog.js';\nimport { Button } from '../../particles/button/button.js';\nimport { useToast } from '../../particles/toast/toast.js';\nimport { useActionsOverride } from '../../sdk/actions/actions-override-context.js';\nimport type { ComponentActions } from '../../sdk/actions/types.js';\nimport type { CustomerAddressUserError } from '../../sdk/address/operations.js';\nimport { useIntl } from '../../sdk/i18n/client.js';\nimport { loggableErrorName } from '../../utils/loggable-error-name.js';\nimport { resolveAuthoredCopy } from '../../utils/resolve-authored-copy.js';\nimport { useAccountAddressBook, useAccountAddressBookItem } from './account-address-book.js';\nimport { firstLine } from './account-address-first-line.js';\n\n/**\n * Deleting an address (specs/sfs-3437-address-book-delete.md, RFC REQ-04). The book's root holds which\n * address is waiting for an answer; a trigger in each entry asks, and one confirmation under the root\n * puts the question and dispatches `$actions.address.remove`. The confirmation never edits the list:\n * the entry leaves through the cache edit the action makes.\n */\n\nexport type AccountAddressBookDeleteTriggerProps = ComponentPropsWithRef<'button'> & {\n /** The button's visible text. A blank value falls back to the catalog copy. */\n label?: string;\n};\n\nexport type AccountAddressBookDeleteConfirmProps = Readonly<{\n /** Goes on the popup, the one element a store can size and place: the dialog renders in a portal. */\n className?: string;\n /** The question. A blank value falls back to the catalog copy. */\n title?: string;\n /** What deleting means. The address's first line always shows before it. A blank value falls back to the catalog copy. */\n description?: string;\n /** The label of the control that backs out. A blank value falls back to the catalog copy. */\n cancelLabel?: string;\n /** The label of the control that deletes. A blank value falls back to the catalog copy. */\n confirmLabel?: string;\n /** Toast after the address is deleted. A blank value falls back to the catalog copy. */\n deletedMessage?: string;\n /** Shown in the prompt when the address was not deleted. A blank value falls back to the catalog copy. */\n failedMessage?: string;\n /** Shown in the prompt when the session expired. A blank value falls back to the catalog copy. */\n unauthorizedMessage?: string;\n /** Injected by the compiler from `actions: { address: [...] }`; the address write surface. */\n $actions?: ComponentActions;\n}>;\n\ntype DeleteError = 'unauthorized' | 'deleteFailed';\n\n/**\n * What a result means for the prompt. An empty result is a removal, and so is `NOT_FOUND`: the server no\n * longer has the address, which is what the shopper asked for, and the action already took it out of\n * the cache. Anything else leaves the address listed.\n */\nfunction deleteError(userErrors: readonly CustomerAddressUserError[]): DeleteError | null {\n if (userErrors.length === 0 || userErrors.some(({ code }) => code === 'NOT_FOUND')) return null;\n return userErrors.some(({ code }) => code === 'UNAUTHORIZED') ? 'unauthorized' : 'deleteFailed';\n}\n\nexport function AccountAddressBookDeleteTrigger({\n label,\n className,\n children,\n onClick,\n ...props\n}: AccountAddressBookDeleteTriggerProps) {\n const { requestDelete } = useAccountAddressBook();\n const address = useAccountAddressBookItem();\n const intl = useIntl();\n const text = resolveAuthoredCopy(label, intl.formatMessage({ id: 'fs/address-delete.trigger' }));\n const line = firstLine(address);\n\n return (\n <Button\n aria-label={line === '' ? undefined : `${text} ${line}`}\n {...props}\n type=\"button\"\n className={className}\n onClick={(event) => {\n onClick?.(event);\n requestDelete(address, event.currentTarget);\n }}\n data-fs-account-address-book-delete=\"\"\n >\n {children ?? text}\n </Button>\n );\n}\n\nexport function AccountAddressBookDeleteConfirm({\n className,\n title,\n description,\n cancelLabel,\n confirmLabel,\n deletedMessage,\n failedMessage,\n unauthorizedMessage,\n $actions: $actionsProp,\n}: AccountAddressBookDeleteConfirmProps) {\n // Enforces the ToastProvider ancestor: the hook throws outside one.\n const toast = useToast();\n const intl = useIntl();\n const $actions = useActionsOverride($actionsProp);\n const { pendingDelete, endDelete, openForm, close } = useAccountAddressBook();\n const [pending, setPending] = useState(false);\n const pendingRef = useRef(false);\n const [error, setError] = useState<DeleteError | null>(null);\n\n const line = pendingDelete ? firstLine(pendingDelete) : '';\n const errorMessage =\n error === 'unauthorized'\n ? resolveAuthoredCopy(unauthorizedMessage, intl.formatMessage({ id: 'fs/address-delete.error.unauthorized' }))\n : resolveAuthoredCopy(failedMessage, intl.formatMessage({ id: 'fs/address-delete.error.failed' }));\n\n function finish() {\n setError(null);\n endDelete();\n }\n\n function deleted(id: string) {\n toast.add({\n title: resolveAuthoredCopy(deletedMessage, intl.formatMessage({ id: 'fs/address-delete.deleted' })),\n type: 'success',\n });\n // An edit of this very address would only fail with `NOT_FOUND`, so it goes with the address.\n if (openForm?.mode === 'edit' && openForm.address.id === id) close();\n finish();\n }\n\n async function confirm() {\n if (pendingRef.current || pendingDelete === null) return;\n const remove = $actions?.address?.remove;\n if (!remove) {\n // A composition gap (the provider chain never delivered the action) is otherwise a dead button.\n setError('deleteFailed');\n return;\n }\n\n const { id } = pendingDelete;\n pendingRef.current = true;\n setPending(true);\n setError(null);\n try {\n const failure = deleteError(await remove({ id }));\n if (failure) setError(failure);\n else deleted(id);\n } catch (error_) {\n // Log only the error name: a message can echo an address value.\n console.error('[AccountAddressBookDeleteConfirm] address.remove failed', loggableErrorName(error_));\n setError('deleteFailed');\n } finally {\n pendingRef.current = false;\n setPending(false);\n }\n }\n\n return (\n <AlertDialog.Root\n open={pendingDelete !== null}\n onOpenChange={(next) => {\n // Nothing closes the prompt while the call runs: its outcome has to land in front of the shopper.\n if (!next && !pendingRef.current) finish();\n }}\n >\n <AlertDialog.Portal>\n <AlertDialog.Backdrop />\n <AlertDialog.Viewport>\n <AlertDialog.Popup className={className} data-fs-account-address-book-delete-confirm=\"\">\n <AlertDialog.Title>\n {resolveAuthoredCopy(title, intl.formatMessage({ id: 'fs/address-delete.title' }))}\n </AlertDialog.Title>\n <AlertDialog.Description>\n {line === '' ? null : (\n <>\n <span data-fs-account-address-book-delete-address=\"\">{line}</span>{' '}\n </>\n )}\n {resolveAuthoredCopy(description, intl.formatMessage({ id: 'fs/address-delete.description' }))}\n </AlertDialog.Description>\n {error === null ? null : (\n <p role=\"alert\" data-fs-account-address-book-delete-error=\"\">\n {errorMessage}\n </p>\n )}\n <AlertDialog.Close disabled={pending}>\n {resolveAuthoredCopy(cancelLabel, intl.formatMessage({ id: 'fs/address-delete.cancel' }))}\n </AlertDialog.Close>\n <Button\n type=\"button\"\n disabled={pending}\n aria-busy={pending || undefined}\n onClick={confirm}\n data-fs-account-address-book-delete-submit=\"\"\n >\n {resolveAuthoredCopy(confirmLabel, intl.formatMessage({ id: 'fs/address-delete.confirm' }))}\n </Button>\n </AlertDialog.Popup>\n </AlertDialog.Viewport>\n </AlertDialog.Portal>\n </AlertDialog.Root>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Definitions\n// ---------------------------------------------------------------------------\n\nexport const AccountAddressBookDeleteTriggerDefinition = defineComponent<AccountAddressBookDeleteTriggerProps>({\n name: 'AccountAddressBookDeleteTrigger',\n importPath: '@vtex/faststore/components',\n component: AccountAddressBookDeleteTrigger,\n requiresContext: 'account-address-book-item',\n editor: { label: 'Account Address Book Delete Trigger', category: 'action' },\n schema: {\n label: { type: 'string', label: 'Button label' },\n },\n guideline:\n \"Asks to delete the address of the entry it sits in. Nothing is deleted until the shopper confirms in an AccountAddressBookDeleteConfirm. Its accessible name adds the address's first line, so a list of them is told apart. Place it inside AccountAddressBookItem, and one AccountAddressBookDeleteConfirm under the root to ask the question.\",\n});\n\nexport const AccountAddressBookDeleteConfirmDefinition = defineComponent<AccountAddressBookDeleteConfirmProps>({\n name: 'AccountAddressBookDeleteConfirm',\n importPath: '@vtex/faststore/components',\n component: AccountAddressBookDeleteConfirm,\n requiresContext: 'account-address-book',\n actions: { address: ['remove'] },\n editor: { label: 'Account Address Book Delete Confirm', category: 'layout' },\n schema: {\n title: { type: 'string', label: 'Question' },\n description: { type: 'string', label: 'What deleting means' },\n cancelLabel: { type: 'string', label: 'Cancel label' },\n confirmLabel: { type: 'string', label: 'Delete label' },\n deletedMessage: { type: 'string', label: 'Address deleted message' },\n failedMessage: { type: 'string', label: 'Not deleted message' },\n unauthorizedMessage: { type: 'string', label: 'Session expired message' },\n },\n guideline:\n 'The alert dialog that asks before an address is deleted, one per address book, opened by AccountAddressBookDeleteTrigger. Names the address, takes focus on Cancel, and closes only on Cancel or Escape: a click outside does nothing. Confirming removes the address, shows a toast and closes; a refusal keeps the dialog open with a message and lets the shopper try again. While the call runs, nothing closes it. Deleting the last address leaves the book empty, so compose an AccountAddressBookEmpty. Requires a ToastProvider ancestor, since the success toast throws without one. Place it under AccountAddressBookRoot. See account-address-book.md.',\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwDA,SAAS,YAAY,YAAqE;CACxF,IAAI,WAAW,WAAW,KAAK,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