@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
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { defineActions } from "../../core/dist/actions/registry.js";
|
|
3
|
+
import "../../core/dist/index.js";
|
|
4
|
+
import { loggableErrorName } from "../../utils/loggable-error-name.js";
|
|
5
|
+
import { CUSTOMER_ADDRESS_BOOK_IDENTITY, CUSTOMER_ADDRESS_CREATE, CUSTOMER_ADDRESS_DELETE, CUSTOMER_ADDRESS_UPDATE } from "./operations.js";
|
|
6
|
+
import { useMutation } from "@apollo/client/react";
|
|
7
|
+
import { useCallback, useMemo } from "react";
|
|
8
|
+
import { CombinedGraphQLErrors } from "@apollo/client/errors";
|
|
9
|
+
//#region src/sdk/address/use-address-actions.ts
|
|
10
|
+
const NETWORK_ERROR = {
|
|
11
|
+
code: "NETWORK_ERROR",
|
|
12
|
+
message: "Unable to complete the request. Please try again.",
|
|
13
|
+
field: null
|
|
14
|
+
};
|
|
15
|
+
const UNAUTHORIZED_ERROR = {
|
|
16
|
+
code: "UNAUTHORIZED",
|
|
17
|
+
message: "Your session has expired. Please sign in again.",
|
|
18
|
+
field: null
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The writes answer an expired session with a top-level `UNAUTHORIZED`, never a `userError`.
|
|
22
|
+
* Collapsing it into `NETWORK_ERROR` would offer a retry that cannot succeed, so it keeps its own
|
|
23
|
+
* code and the caller can send the shopper back to sign-in.
|
|
24
|
+
*/
|
|
25
|
+
function toUserError(error) {
|
|
26
|
+
if (CombinedGraphQLErrors.is(error) && error.errors.some(({ extensions }) => extensions?.code === "UNAUTHORIZED")) return UNAUTHORIZED_ERROR;
|
|
27
|
+
return NETWORK_ERROR;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Takes the address out of the cached address book, then evicts its entity. Apollo hides a dangling
|
|
31
|
+
* reference when it reads a list, so the evict alone would empty the visible list; the explicit edit
|
|
32
|
+
* keeps the stored array free of references to an entity that is gone. With no book cached, only the
|
|
33
|
+
* evict runs.
|
|
34
|
+
*/
|
|
35
|
+
function dropAddress(cache, id) {
|
|
36
|
+
const book = cache.readQuery({ query: CUSTOMER_ADDRESS_BOOK_IDENTITY })?.customerAddressBook;
|
|
37
|
+
if (book) cache.modify({
|
|
38
|
+
id: cache.identify(book),
|
|
39
|
+
fields: { addresses(existing, { readField }) {
|
|
40
|
+
return existing.filter((reference) => readField("id", reference) !== id);
|
|
41
|
+
} }
|
|
42
|
+
});
|
|
43
|
+
cache.evict({ id: cache.identify({
|
|
44
|
+
__typename: "CustomerAddress",
|
|
45
|
+
id
|
|
46
|
+
}) });
|
|
47
|
+
}
|
|
48
|
+
/** True when the server says the address is not among the shopper's own: gone, or never theirs. */
|
|
49
|
+
function isNotFound(userErrors) {
|
|
50
|
+
return userErrors?.some(({ code }) => code === "NOT_FOUND") ?? false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The `address` namespace hook. Registered with the first-party action registry via `addressActions`
|
|
54
|
+
* below; the compiler-emitted `AddressActionProvider` calls it and threads the narrowed methods into
|
|
55
|
+
* each consumer's `$actions.address`.
|
|
56
|
+
*/
|
|
57
|
+
function useAddressActions() {
|
|
58
|
+
const [createMutation] = useMutation(CUSTOMER_ADDRESS_CREATE, { update(cache, { data }) {
|
|
59
|
+
const address = data?.customerAddressCreate.customerAddress;
|
|
60
|
+
if (!address) return;
|
|
61
|
+
const book = cache.readQuery({ query: CUSTOMER_ADDRESS_BOOK_IDENTITY })?.customerAddressBook;
|
|
62
|
+
if (!book) return;
|
|
63
|
+
cache.modify({
|
|
64
|
+
id: cache.identify(book),
|
|
65
|
+
fields: { addresses(existing, { readField, toReference }) {
|
|
66
|
+
if (existing.some((reference) => readField("id", reference) === address.id)) return existing;
|
|
67
|
+
const created = toReference(address);
|
|
68
|
+
return created ? [...existing, created] : existing;
|
|
69
|
+
} }
|
|
70
|
+
});
|
|
71
|
+
} });
|
|
72
|
+
const [updateMutation] = useMutation(CUSTOMER_ADDRESS_UPDATE, { update(cache, { data }, { variables }) {
|
|
73
|
+
if (variables && isNotFound(data?.customerAddressUpdate.userErrors)) dropAddress(cache, variables.id);
|
|
74
|
+
} });
|
|
75
|
+
const [removeMutation] = useMutation(CUSTOMER_ADDRESS_DELETE, { update(cache, { data }, { variables }) {
|
|
76
|
+
const payload = data?.customerAddressDelete;
|
|
77
|
+
if (!payload) return;
|
|
78
|
+
if (payload.userErrors.length === 0 && payload.deletedCustomerAddressId) dropAddress(cache, payload.deletedCustomerAddressId);
|
|
79
|
+
else if (variables && isNotFound(payload.userErrors)) dropAddress(cache, variables.id);
|
|
80
|
+
} });
|
|
81
|
+
const create = useCallback(async (payload) => {
|
|
82
|
+
try {
|
|
83
|
+
return (await createMutation({ variables: { input: payload } })).data?.customerAddressCreate.userErrors ?? [];
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error("[address.create] customerAddressCreate failed", loggableErrorName(error));
|
|
86
|
+
return [toUserError(error)];
|
|
87
|
+
}
|
|
88
|
+
}, [createMutation]);
|
|
89
|
+
const update = useCallback(async ({ id, ...input }) => {
|
|
90
|
+
try {
|
|
91
|
+
return (await updateMutation({ variables: {
|
|
92
|
+
id,
|
|
93
|
+
input
|
|
94
|
+
} })).data?.customerAddressUpdate.userErrors ?? [];
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("[address.update] customerAddressUpdate failed", loggableErrorName(error));
|
|
97
|
+
return [toUserError(error)];
|
|
98
|
+
}
|
|
99
|
+
}, [updateMutation]);
|
|
100
|
+
const remove = useCallback(async ({ id }) => {
|
|
101
|
+
try {
|
|
102
|
+
return (await removeMutation({ variables: { id } })).data?.customerAddressDelete.userErrors ?? [];
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("[address.remove] customerAddressDelete failed", loggableErrorName(error));
|
|
105
|
+
return [toUserError(error)];
|
|
106
|
+
}
|
|
107
|
+
}, [removeMutation]);
|
|
108
|
+
return useMemo(() => ({
|
|
109
|
+
create,
|
|
110
|
+
update,
|
|
111
|
+
remove
|
|
112
|
+
}), [
|
|
113
|
+
create,
|
|
114
|
+
update,
|
|
115
|
+
remove
|
|
116
|
+
]);
|
|
117
|
+
}
|
|
118
|
+
defineActions({
|
|
119
|
+
namespace: "address",
|
|
120
|
+
description: "Mutation-backed writes against the shopper's saved addresses (create, update, remove).",
|
|
121
|
+
provider: {
|
|
122
|
+
name: "AddressActionProvider",
|
|
123
|
+
importPath: "@vtex/faststore/internal/client"
|
|
124
|
+
},
|
|
125
|
+
methods: {
|
|
126
|
+
create: {
|
|
127
|
+
description: "Save a new address and add it to the cached address book (async/pessimistic). Resolves the payload userErrors.",
|
|
128
|
+
payload: [
|
|
129
|
+
{
|
|
130
|
+
name: "country",
|
|
131
|
+
type: "string"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "recipientName",
|
|
135
|
+
type: "string",
|
|
136
|
+
optional: true
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "street",
|
|
140
|
+
type: "string",
|
|
141
|
+
optional: true
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: "number",
|
|
145
|
+
type: "string",
|
|
146
|
+
optional: true
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "complement",
|
|
150
|
+
type: "string",
|
|
151
|
+
optional: true
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: "neighborhood",
|
|
155
|
+
type: "string",
|
|
156
|
+
optional: true
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "city",
|
|
160
|
+
type: "string",
|
|
161
|
+
optional: true
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "state",
|
|
165
|
+
type: "string",
|
|
166
|
+
optional: true
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: "postalCode",
|
|
170
|
+
type: "string",
|
|
171
|
+
optional: true
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "reference",
|
|
175
|
+
type: "string",
|
|
176
|
+
optional: true
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
update: {
|
|
181
|
+
description: "Change a saved address (async/pessimistic). Omitted fields are kept; an empty string erases. Resolves the payload userErrors.",
|
|
182
|
+
payload: [
|
|
183
|
+
{
|
|
184
|
+
name: "id",
|
|
185
|
+
type: "string"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "recipientName",
|
|
189
|
+
type: "string",
|
|
190
|
+
optional: true
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: "street",
|
|
194
|
+
type: "string",
|
|
195
|
+
optional: true
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: "number",
|
|
199
|
+
type: "string",
|
|
200
|
+
optional: true
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "complement",
|
|
204
|
+
type: "string",
|
|
205
|
+
optional: true
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "neighborhood",
|
|
209
|
+
type: "string",
|
|
210
|
+
optional: true
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "city",
|
|
214
|
+
type: "string",
|
|
215
|
+
optional: true
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: "state",
|
|
219
|
+
type: "string",
|
|
220
|
+
optional: true
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "postalCode",
|
|
224
|
+
type: "string",
|
|
225
|
+
optional: true
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "reference",
|
|
229
|
+
type: "string",
|
|
230
|
+
optional: true
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
},
|
|
234
|
+
remove: {
|
|
235
|
+
description: "Remove a saved address once the server confirms (async/pessimistic). Resolves the payload userErrors.",
|
|
236
|
+
payload: [{
|
|
237
|
+
name: "id",
|
|
238
|
+
type: "string"
|
|
239
|
+
}]
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
use: useAddressActions
|
|
243
|
+
});
|
|
244
|
+
//#endregion
|
|
245
|
+
export { useAddressActions };
|
|
246
|
+
|
|
247
|
+
//# sourceMappingURL=use-address-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-address-actions.js","names":[],"sources":["../../../src/sdk/address/use-address-actions.ts"],"sourcesContent":["'use client';\n\nimport type { ApolloCache, Reference } from '@apollo/client';\nimport { CombinedGraphQLErrors } from '@apollo/client/errors';\nimport { useMutation } from '@apollo/client/react';\nimport { defineActions } from '@vtex/fs-core';\nimport { useCallback, useMemo } from 'react';\nimport { loggableErrorName } from '../../utils/loggable-error-name.js';\nimport {\n type AddressCreatePayload,\n type AddressRemovePayload,\n type AddressUpdatePayload,\n CUSTOMER_ADDRESS_BOOK_IDENTITY,\n CUSTOMER_ADDRESS_CREATE,\n CUSTOMER_ADDRESS_DELETE,\n CUSTOMER_ADDRESS_UPDATE,\n type CustomerAddressUserError,\n} from './operations.js';\n\nexport type {\n AddressCreatePayload,\n AddressRemovePayload,\n AddressUpdatePayload,\n CustomerAddressUserError,\n} from './operations.js';\n\n/**\n * The `address` action namespace: the one sanctioned client write surface for the shopper's saved\n * addresses (docs/storefront-core/adr-0010-actions-own-the-write-side.md,\n * docs/features/my-account-address-book/rfc.md § Address actions).\n *\n * Every method is async and pessimistic: the cache changes only after the server answers. Each\n * resolves to the payload's `userErrors` (empty on success), with their `field`, so the caller can\n * mark the field. None rejects for an expected outcome. ADR-0010 has handlers surface `userErrors`\n * through the `notifications` action; that action does not exist yet, so the caller presents them.\n */\nexport type AddressActions = Readonly<{\n /** Save a new address. Appends it to the cached address book on success. Never rejects. */\n create: (payload: AddressCreatePayload) => Promise<readonly CustomerAddressUserError[]>;\n /**\n * Change a saved address. Omit a field to keep it; an empty string erases it. Subscribers update\n * through the normalized cache. Never rejects.\n */\n update: (payload: AddressUpdatePayload) => Promise<readonly CustomerAddressUserError[]>;\n /**\n * Remove a saved address. The list changes only once the server confirms. A `NOT_FOUND` answer\n * means the server no longer has it, so it leaves the cache too. Never rejects.\n */\n remove: (payload: AddressRemovePayload) => Promise<readonly CustomerAddressUserError[]>;\n}>;\n\nconst NETWORK_ERROR: CustomerAddressUserError = {\n code: 'NETWORK_ERROR',\n message: 'Unable to complete the request. Please try again.',\n field: null,\n};\n\nconst UNAUTHORIZED_ERROR: CustomerAddressUserError = {\n code: 'UNAUTHORIZED',\n message: 'Your session has expired. Please sign in again.',\n field: null,\n};\n\n/**\n * The writes answer an expired session with a top-level `UNAUTHORIZED`, never a `userError`.\n * Collapsing it into `NETWORK_ERROR` would offer a retry that cannot succeed, so it keeps its own\n * code and the caller can send the shopper back to sign-in.\n */\nfunction toUserError(error: unknown): CustomerAddressUserError {\n if (CombinedGraphQLErrors.is(error) && error.errors.some(({ extensions }) => extensions?.code === 'UNAUTHORIZED')) {\n return UNAUTHORIZED_ERROR;\n }\n return NETWORK_ERROR;\n}\n\n/**\n * Takes the address out of the cached address book, then evicts its entity. Apollo hides a dangling\n * reference when it reads a list, so the evict alone would empty the visible list; the explicit edit\n * keeps the stored array free of references to an entity that is gone. With no book cached, only the\n * evict runs.\n */\nfunction dropAddress(cache: ApolloCache, id: string): void {\n const book = cache.readQuery({ query: CUSTOMER_ADDRESS_BOOK_IDENTITY })?.customerAddressBook;\n if (book) {\n cache.modify({\n id: cache.identify(book),\n fields: {\n addresses(existing: readonly Reference[], { readField }) {\n return existing.filter((reference) => readField('id', reference) !== id);\n },\n },\n });\n }\n cache.evict({ id: cache.identify({ __typename: 'CustomerAddress', id }) });\n}\n\n/** True when the server says the address is not among the shopper's own: gone, or never theirs. */\nfunction isNotFound(userErrors: readonly CustomerAddressUserError[] | undefined): boolean {\n return userErrors?.some(({ code }) => code === 'NOT_FOUND') ?? false;\n}\n\n/**\n * The `address` namespace hook. Registered with the first-party action registry via `addressActions`\n * below; the compiler-emitted `AddressActionProvider` calls it and threads the narrowed methods into\n * each consumer's `$actions.address`.\n */\nexport function useAddressActions(): AddressActions {\n const [createMutation] = useMutation(CUSTOMER_ADDRESS_CREATE, {\n update(cache, { data }) {\n const address = data?.customerAddressCreate.customerAddress;\n if (!address) return;\n // Read from the cache only: no mounted list means nothing to append to, and the entity the\n // payload just normalized is all this write leaves behind.\n const book = cache.readQuery({ query: CUSTOMER_ADDRESS_BOOK_IDENTITY })?.customerAddressBook;\n if (!book) return;\n cache.modify({\n id: cache.identify(book),\n fields: {\n addresses(existing: readonly Reference[], { readField, toReference }) {\n if (existing.some((reference) => readField('id', reference) === address.id)) {\n return existing;\n }\n const created = toReference(address);\n return created ? [...existing, created] : existing;\n },\n },\n });\n },\n });\n\n const [updateMutation] = useMutation(CUSTOMER_ADDRESS_UPDATE, {\n update(cache, { data }, { variables }) {\n if (variables && isNotFound(data?.customerAddressUpdate.userErrors)) dropAddress(cache, variables.id);\n },\n });\n\n const [removeMutation] = useMutation(CUSTOMER_ADDRESS_DELETE, {\n update(cache, { data }, { variables }) {\n const payload = data?.customerAddressDelete;\n if (!payload) return;\n if (payload.userErrors.length === 0 && payload.deletedCustomerAddressId) {\n dropAddress(cache, payload.deletedCustomerAddressId);\n } else if (variables && isNotFound(payload.userErrors)) {\n dropAddress(cache, variables.id);\n }\n },\n });\n\n const create = useCallback<AddressActions['create']>(\n async (payload) => {\n try {\n const result = await createMutation({ variables: { input: payload } });\n return result.data?.customerAddressCreate.userErrors ?? [];\n } catch (error) {\n // Log only the error name: the message can echo a submitted address value (PII).\n console.error('[address.create] customerAddressCreate failed', loggableErrorName(error));\n return [toUserError(error)];\n }\n },\n [createMutation],\n );\n\n const update = useCallback<AddressActions['update']>(\n async ({ id, ...input }) => {\n try {\n // Forwarded unmapped: an empty string is an explicit erase and must survive to the wire.\n const result = await updateMutation({ variables: { id, input } });\n return result.data?.customerAddressUpdate.userErrors ?? [];\n } catch (error) {\n console.error('[address.update] customerAddressUpdate failed', loggableErrorName(error));\n return [toUserError(error)];\n }\n },\n [updateMutation],\n );\n\n const remove = useCallback<AddressActions['remove']>(\n async ({ id }) => {\n try {\n const result = await removeMutation({ variables: { id } });\n return result.data?.customerAddressDelete.userErrors ?? [];\n } catch (error) {\n console.error('[address.remove] customerAddressDelete failed', loggableErrorName(error));\n return [toUserError(error)];\n }\n },\n [removeMutation],\n );\n\n return useMemo(() => ({ create, update, remove }), [create, update, remove]);\n}\n\n/**\n * Declares the `address` action namespace: the single source of truth for its method/payload\n * metadata, runtime provider, and `use` hook. The native catalog builder\n * (`scripts/build-catalog.mjs`) statically reads this call to emit `actions.json`; at runtime\n * `AddressActionProvider` calls `useAddressActions` directly.\n */\nexport const addressActions = defineActions({\n namespace: 'address',\n description: \"Mutation-backed writes against the shopper's saved addresses (create, update, remove).\",\n provider: { name: 'AddressActionProvider', importPath: '@vtex/faststore/internal/client' },\n methods: {\n create: {\n description:\n 'Save a new address and add it to the cached address book (async/pessimistic). Resolves the payload userErrors.',\n payload: [\n { name: 'country', type: 'string' },\n { name: 'recipientName', type: 'string', optional: true },\n { name: 'street', type: 'string', optional: true },\n { name: 'number', type: 'string', optional: true },\n { name: 'complement', type: 'string', optional: true },\n { name: 'neighborhood', type: 'string', optional: true },\n { name: 'city', type: 'string', optional: true },\n { name: 'state', type: 'string', optional: true },\n { name: 'postalCode', type: 'string', optional: true },\n { name: 'reference', type: 'string', optional: true },\n ],\n },\n update: {\n description:\n 'Change a saved address (async/pessimistic). Omitted fields are kept; an empty string erases. Resolves the payload userErrors.',\n payload: [\n { name: 'id', type: 'string' },\n { name: 'recipientName', type: 'string', optional: true },\n { name: 'street', type: 'string', optional: true },\n { name: 'number', type: 'string', optional: true },\n { name: 'complement', type: 'string', optional: true },\n { name: 'neighborhood', type: 'string', optional: true },\n { name: 'city', type: 'string', optional: true },\n { name: 'state', type: 'string', optional: true },\n { name: 'postalCode', type: 'string', optional: true },\n { name: 'reference', type: 'string', optional: true },\n ],\n },\n remove: {\n description:\n 'Remove a saved address once the server confirms (async/pessimistic). Resolves the payload userErrors.',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AAgB,MAAM;KAAU,UAAU;IAAK;IACvD;KAAE,MAAM;KAAQ,MAAM;KAAU,UAAU;IAAK;IAC/C;KAAE,MAAM;KAAS,MAAM;KAAU,UAAU;IAAK;IAChD;KAAE,MAAM;KAAc,MAAM;KAAU,UAAU;IAAK;IACrD;KAAE,MAAM;KAAa,MAAM;KAAU,UAAU;IAAK;GACtD;EACF;EACA,QAAQ;GACN,aACE;GACF,SAAS,CAAC;IAAE,MAAM;IAAM,MAAM;GAAS,CAAC;EAC1C;CACF;CACA,KAAK;AACP,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { withRequestTimeout } from "../shipping/request-timeout.js";
|
|
3
|
+
import { loggableErrorName } from "../../utils/loggable-error-name.js";
|
|
4
|
+
import { ADDRESS_BY_POSTAL_CODE } from "./postal-code-lookup-operations.js";
|
|
5
|
+
import { getApolloContext } from "@apollo/client/react";
|
|
6
|
+
import { useCallback, useContext } from "react";
|
|
7
|
+
//#region src/sdk/address/use-address-by-postal-code.ts
|
|
8
|
+
const FAILED = { status: "failed" };
|
|
9
|
+
/**
|
|
10
|
+
* Postal-code lookup SDK hook (specs/sfs-3430-address-by-postal-code.md).
|
|
11
|
+
*
|
|
12
|
+
* Returns a callback that runs the `AddressByPostalCode` query once per call and never rejects. It
|
|
13
|
+
* reads the client from `getApolloContext()` (a non-throwing read, like `useShippingSimulation`), and
|
|
14
|
+
* skips the cache: a lookup is a shopper's postal code, so it is neither read from nor written to the
|
|
15
|
+
* normalized cache. The hook does not check `hasPostalCodeLookup(country)`; the caller decides
|
|
16
|
+
* whether a country is worth a request, and when to ask and which reply is stale.
|
|
17
|
+
*
|
|
18
|
+
* A failure logs the error's name, as the address actions do, and never the country, the postal
|
|
19
|
+
* code, or a message.
|
|
20
|
+
*/
|
|
21
|
+
function useAddressByPostalCode() {
|
|
22
|
+
const { client } = useContext(getApolloContext());
|
|
23
|
+
return useCallback(async ({ country, postalCode }) => {
|
|
24
|
+
try {
|
|
25
|
+
if (!client) throw new Error("No Apollo client is available.");
|
|
26
|
+
const result = await withRequestTimeout((signal) => client.query({
|
|
27
|
+
query: ADDRESS_BY_POSTAL_CODE,
|
|
28
|
+
variables: {
|
|
29
|
+
country,
|
|
30
|
+
postalCode
|
|
31
|
+
},
|
|
32
|
+
fetchPolicy: "no-cache",
|
|
33
|
+
context: { fetchOptions: { signal } }
|
|
34
|
+
}));
|
|
35
|
+
if (result.error) throw result.error;
|
|
36
|
+
if (!result.data) throw new Error("The lookup returned no data.");
|
|
37
|
+
const address = result.data.addressByPostalCode;
|
|
38
|
+
if (!address) return { status: "notFound" };
|
|
39
|
+
return {
|
|
40
|
+
status: "found",
|
|
41
|
+
address: {
|
|
42
|
+
city: address.city ?? null,
|
|
43
|
+
state: address.state ?? null,
|
|
44
|
+
street: address.street ?? null,
|
|
45
|
+
neighborhood: address.neighborhood ?? null
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("[address.postalCodeLookup] addressByPostalCode failed", loggableErrorName(error));
|
|
50
|
+
return FAILED;
|
|
51
|
+
}
|
|
52
|
+
}, [client]);
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { useAddressByPostalCode };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=use-address-by-postal-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-address-by-postal-code.js","names":[],"sources":["../../../src/sdk/address/use-address-by-postal-code.ts"],"sourcesContent":["'use client';\n\nimport { getApolloContext } from '@apollo/client/react';\nimport { useCallback, useContext } from 'react';\nimport { loggableErrorName } from '../../utils/loggable-error-name.js';\nimport { withRequestTimeout } from '../shipping/request-timeout.js';\nimport { ADDRESS_BY_POSTAL_CODE } from './postal-code-lookup-operations.js';\n\n/**\n * The fields the platform resolves for a postal code. Each is `null` where the platform left it\n * blank, and the state is as the platform codes it, so it may not match a select's option values.\n */\nexport type PostalCodeLookupFields = Readonly<{\n city: string | null;\n state: string | null;\n street: string | null;\n neighborhood: string | null;\n}>;\n\n/**\n * The three things a lookup can come to. `notFound` is a code the platform does not know; `failed`\n * is a lookup that could not run (no client, a GraphQL error, a transport error, a timeout). The two\n * never look alike, so a caller can show an outage differently from a typo.\n */\nexport type PostalCodeLookupResult =\n | Readonly<{ status: 'found'; address: PostalCodeLookupFields }>\n | Readonly<{ status: 'notFound' }>\n | Readonly<{ status: 'failed' }>;\n\nconst FAILED: PostalCodeLookupResult = { status: 'failed' };\n\n/**\n * Postal-code lookup SDK hook (specs/sfs-3430-address-by-postal-code.md).\n *\n * Returns a callback that runs the `AddressByPostalCode` query once per call and never rejects. It\n * reads the client from `getApolloContext()` (a non-throwing read, like `useShippingSimulation`), and\n * skips the cache: a lookup is a shopper's postal code, so it is neither read from nor written to the\n * normalized cache. The hook does not check `hasPostalCodeLookup(country)`; the caller decides\n * whether a country is worth a request, and when to ask and which reply is stale.\n *\n * A failure logs the error's name, as the address actions do, and never the country, the postal\n * code, or a message.\n */\nexport function useAddressByPostalCode(): (input: {\n country: string;\n postalCode: string;\n}) => Promise<PostalCodeLookupResult> {\n const { client } = useContext(getApolloContext());\n\n return useCallback(\n async ({ country, postalCode }): Promise<PostalCodeLookupResult> => {\n try {\n if (!client) {\n throw new Error('No Apollo client is available.');\n }\n const result = await withRequestTimeout((signal) =>\n client.query({\n query: ADDRESS_BY_POSTAL_CODE,\n variables: { country, postalCode },\n fetchPolicy: 'no-cache',\n context: { fetchOptions: { signal } },\n }),\n );\n\n if (result.error) {\n throw result.error;\n }\n if (!result.data) {\n throw new Error('The lookup returned no data.');\n }\n\n const address = result.data.addressByPostalCode;\n if (!address) {\n return { status: 'notFound' };\n }\n return {\n status: 'found',\n address: {\n city: address.city ?? null,\n state: address.state ?? null,\n street: address.street ?? null,\n neighborhood: address.neighborhood ?? null,\n },\n };\n } catch (error) {\n console.error('[address.postalCodeLookup] addressByPostalCode failed', loggableErrorName(error));\n return FAILED;\n }\n },\n [client],\n );\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,SAAiC,EAAE,QAAQ,SAAS;;;;;;;;;;;;;AAc1D,SAAgB,yBAGsB;CACpC,MAAM,EAAE,WAAW,WAAW,iBAAiB,CAAC;CAEhD,OAAO,YACL,OAAO,EAAE,SAAS,iBAAkD;EAClE,IAAI;GACF,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,gCAAgC;GAElD,MAAM,SAAS,MAAM,oBAAoB,WACvC,OAAO,MAAM;IACX,OAAO;IACP,WAAW;KAAE;KAAS;IAAW;IACjC,aAAa;IACb,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE;GACtC,CAAC,CACH;GAEA,IAAI,OAAO,OACT,MAAM,OAAO;GAEf,IAAI,CAAC,OAAO,MACV,MAAM,IAAI,MAAM,8BAA8B;GAGhD,MAAM,UAAU,OAAO,KAAK;GAC5B,IAAI,CAAC,SACH,OAAO,EAAE,QAAQ,WAAW;GAE9B,OAAO;IACL,QAAQ;IACR,SAAS;KACP,MAAM,QAAQ,QAAQ;KACtB,OAAO,QAAQ,SAAS;KACxB,QAAQ,QAAQ,UAAU;KAC1B,cAAc,QAAQ,gBAAgB;IACxC;GACF;EACF,SAAS,OAAO;GACd,QAAQ,MAAM,yDAAyD,kBAAkB,KAAK,CAAC;GAC/F,OAAO;EACT;CACF,GACA,CAAC,MAAM,CACT;AACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ACCOUNT_MAX_LENGTH } from "./constants.js";
|
|
2
|
+
import { resolveLibraryError } from "./messages.js";
|
|
3
|
+
import { declaredMaxLength, toFormValues } from "./schema.js";
|
|
4
|
+
import { createFormState, getVisibleFields, resolveFieldOptions, validate } from "@vtex/country-forms";
|
|
5
|
+
//#region src/sdk/address/validate-address.ts
|
|
6
|
+
const REQUIRED = {
|
|
7
|
+
code: "required",
|
|
8
|
+
messageId: "fs/address.error.required"
|
|
9
|
+
};
|
|
10
|
+
const INVALID = {
|
|
11
|
+
code: "invalid",
|
|
12
|
+
messageId: "fs/address.error.invalid"
|
|
13
|
+
};
|
|
14
|
+
function isAddressField(name) {
|
|
15
|
+
return Object.hasOwn(ACCOUNT_MAX_LENGTH, name);
|
|
16
|
+
}
|
|
17
|
+
function isOutsideOptions(field, values, fields) {
|
|
18
|
+
const value = values[field.name] ?? "";
|
|
19
|
+
if (field.type !== "select" || value === "") return false;
|
|
20
|
+
const controller = fields.find(({ name }) => name === field.dependsOn);
|
|
21
|
+
if (controller && ((values[controller.name] ?? "") === "" || isOutsideOptions(controller, values, fields))) return false;
|
|
22
|
+
return !(resolveFieldOptions(field, values) ?? []).some((option) => option.value === value);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks a draft or a stored address against its country's rules and the account's own rules, and
|
|
26
|
+
* returns at most one error per field. A field's first error wins, in this order: the library's,
|
|
27
|
+
* a select value outside its options, then the account's maximum length.
|
|
28
|
+
*
|
|
29
|
+
* The account's rules cover what the library does not: `recipientName` must not be blank,
|
|
30
|
+
* `reference` and the address name may be empty, every free-text field has a maximum length, and a
|
|
31
|
+
* select's value must be one of the options the library resolves. Keys outside the ten address
|
|
32
|
+
* fields are ignored, so a merged record can carry `geoCoordinate` as it is.
|
|
33
|
+
*/
|
|
34
|
+
function validateAddress(values, rules) {
|
|
35
|
+
const text = toFormValues(values);
|
|
36
|
+
const fields = getVisibleFields(rules.schema, text);
|
|
37
|
+
const errors = {};
|
|
38
|
+
const declared = new Map(rules.schema.fields.map((field) => [field.name, field]));
|
|
39
|
+
const libraryErrors = validate(createFormState(rules.schema, text), rules.schema);
|
|
40
|
+
for (const [name, key] of Object.entries(libraryErrors)) {
|
|
41
|
+
const field = declared.get(name);
|
|
42
|
+
if (isAddressField(name) && field) errors[name] = resolveLibraryError(key, {
|
|
43
|
+
country: rules.country,
|
|
44
|
+
maxLength: declaredMaxLength(field)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
for (const field of fields) if (isAddressField(field.name) && !errors[field.name] && isOutsideOptions(field, text, fields)) errors[field.name] = INVALID;
|
|
48
|
+
if ((values.recipientName ?? "").trim() === "" && !errors.recipientName) errors.recipientName = REQUIRED;
|
|
49
|
+
for (const name of Object.keys(ACCOUNT_MAX_LENGTH).filter(isAddressField)) {
|
|
50
|
+
const maxLength = ACCOUNT_MAX_LENGTH[name];
|
|
51
|
+
if (!errors[name] && (values[name] ?? "").length > maxLength) errors[name] = {
|
|
52
|
+
code: "tooLong",
|
|
53
|
+
messageId: "fs/address.error.too-long",
|
|
54
|
+
values: { maxLength }
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return errors;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { validateAddress };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=validate-address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-address.js","names":[],"sources":["../../../src/sdk/address/validate-address.ts"],"sourcesContent":["import {\n createFormState,\n type FieldDefinition,\n type FormValues,\n getVisibleFields,\n resolveFieldOptions,\n validate,\n} from '@vtex/country-forms';\nimport { ACCOUNT_MAX_LENGTH } from './constants.js';\nimport { resolveLibraryError } from './messages.js';\nimport { declaredMaxLength, toFormValues } from './schema.js';\nimport type { AddressErrors, AddressFieldError, AddressFieldName, AddressValues, CountryRules } from './types.js';\n\nconst REQUIRED: AddressFieldError = { code: 'required', messageId: 'fs/address.error.required' };\nconst INVALID: AddressFieldError = { code: 'invalid', messageId: 'fs/address.error.invalid' };\n\nfunction isAddressField(name: string): name is AddressFieldName {\n return Object.hasOwn(ACCOUNT_MAX_LENGTH, name);\n}\n\nfunction isOutsideOptions(field: FieldDefinition, values: FormValues, fields: readonly FieldDefinition[]): boolean {\n const value = values[field.name] ?? '';\n if (field.type !== 'select' || value === '') {\n return false;\n }\n\n // A dependent list exists only for a valid controller; the controller carries its own error.\n const controller = fields.find(({ name }) => name === field.dependsOn);\n if (controller && ((values[controller.name] ?? '') === '' || isOutsideOptions(controller, values, fields))) {\n return false;\n }\n\n return !(resolveFieldOptions(field, values) ?? []).some((option) => option.value === value);\n}\n\n/**\n * Checks a draft or a stored address against its country's rules and the account's own rules, and\n * returns at most one error per field. A field's first error wins, in this order: the library's,\n * a select value outside its options, then the account's maximum length.\n *\n * The account's rules cover what the library does not: `recipientName` must not be blank,\n * `reference` and the address name may be empty, every free-text field has a maximum length, and a\n * select's value must be one of the options the library resolves. Keys outside the ten address\n * fields are ignored, so a merged record can carry `geoCoordinate` as it is.\n */\nexport function validateAddress(values: AddressValues, rules: CountryRules): AddressErrors {\n const text = toFormValues(values);\n const fields = getVisibleFields(rules.schema, text);\n const errors: Partial<Record<AddressFieldName, AddressFieldError>> = {};\n\n const declared = new Map(rules.schema.fields.map((field) => [field.name, field]));\n const libraryErrors = validate(createFormState(rules.schema, text), rules.schema);\n for (const [name, key] of Object.entries(libraryErrors)) {\n const field = declared.get(name);\n if (isAddressField(name) && field) {\n errors[name] = resolveLibraryError(key, { country: rules.country, maxLength: declaredMaxLength(field) });\n }\n }\n\n for (const field of fields) {\n if (isAddressField(field.name) && !errors[field.name] && isOutsideOptions(field, text, fields)) {\n errors[field.name] = INVALID;\n }\n }\n\n if ((values.recipientName ?? '').trim() === '' && !errors.recipientName) {\n errors.recipientName = REQUIRED;\n }\n\n for (const name of Object.keys(ACCOUNT_MAX_LENGTH).filter(isAddressField)) {\n const maxLength = ACCOUNT_MAX_LENGTH[name];\n if (!errors[name] && (values[name] ?? '').length > maxLength) {\n errors[name] = { code: 'tooLong', messageId: 'fs/address.error.too-long', values: { maxLength } };\n }\n }\n\n return errors;\n}\n"],"mappings":";;;;;AAaA,MAAM,WAA8B;CAAE,MAAM;CAAY,WAAW;AAA4B;AAC/F,MAAM,UAA6B;CAAE,MAAM;CAAW,WAAW;AAA2B;AAE5F,SAAS,eAAe,MAAwC;CAC9D,OAAO,OAAO,OAAO,oBAAoB,IAAI;AAC/C;AAEA,SAAS,iBAAiB,OAAwB,Q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rC,IAAI,CAAC,OAAO,UAAU,OAAO,SAAS,GAAA,CAAI,SAAS,WACjD,OAAO,QAAQ;GAAE,MAAM;GAAW,WAAW;GAA6B,QAAQ,EAAE,UAAU;EAAE;CAEpG;CAEA,OAAO;AACT"}
|
|
@@ -4,11 +4,36 @@ import { InMemoryCache } from "@apollo/client";
|
|
|
4
4
|
/**
|
|
5
5
|
* Per-entity normalization and field-merge rules for the Storefront cache.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* "
|
|
7
|
+
* The cart and the order share three types whose ids neither can scope
|
|
8
|
+
* (docs/features/order-placed/rfc.md, 3.4): a totalizer's id is its category
|
|
9
|
+
* ("Items"), which the cart's totalizer line selects by; an address's id is the
|
|
10
|
+
* saved address itself, masked on the order and not on the cart; and a
|
|
11
|
+
* customization's id is the assembly ("Engraving"), which two lines of one cart
|
|
12
|
+
* already share. Normalized, one record would overwrite the other, so each is
|
|
13
|
+
* stored inside the record that holds it, and replaced on every write: safe
|
|
14
|
+
* while every fragment selects the same subfields of each.
|
|
15
|
+
*
|
|
16
|
+
* The lists that hold them are the server's whole answer, so each write
|
|
17
|
+
* replaces the list (`merge: false`). Apollo does the same by default, but warns
|
|
18
|
+
* that data may be lost whenever such a list shrinks, as when a discount line
|
|
19
|
+
* leaves the cart's totalizers; a merge by id would keep that stale line.
|
|
20
|
+
*
|
|
21
|
+
* Other domain entries arrive with the particles that need them — see
|
|
22
|
+
* docs/storefront-core/reference-free-particle-model.md § Typed documents and the shared cache.
|
|
10
23
|
*/
|
|
11
|
-
const
|
|
24
|
+
const replaceList = { merge: false };
|
|
25
|
+
const typePolicies = {
|
|
26
|
+
CartTotalizer: { keyFields: false },
|
|
27
|
+
Address: { keyFields: false },
|
|
28
|
+
CartItemCustomization: { keyFields: false },
|
|
29
|
+
Cart: { fields: { totalizers: replaceList } },
|
|
30
|
+
CartItem: { fields: { customizations: replaceList } },
|
|
31
|
+
CartItemComposition: { fields: { customizations: replaceList } },
|
|
32
|
+
Shipping: { fields: { savedAddresses: replaceList } },
|
|
33
|
+
Order: { fields: { totals: replaceList } },
|
|
34
|
+
SellerOrder: { fields: { totals: replaceList } },
|
|
35
|
+
OrderItem: { fields: { customizations: replaceList } }
|
|
36
|
+
};
|
|
12
37
|
/**
|
|
13
38
|
* The single source of truth for InMemoryCache configuration. Both the
|
|
14
39
|
* server-side `createClient` and the client-side `StorefrontProvider`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storefront-cache.js","names":[],"sources":["../../../src/sdk/cache/storefront-cache.ts"],"sourcesContent":["import { InMemoryCache, type InMemoryCacheConfig, type TypePolicies } from '@apollo/client';\nimport { possibleTypes } from '../generated/fragment-types.js';\n\n/**\n * Per-entity normalization and field-merge rules for the Storefront cache.\n *\n *
|
|
1
|
+
{"version":3,"file":"storefront-cache.js","names":[],"sources":["../../../src/sdk/cache/storefront-cache.ts"],"sourcesContent":["import { InMemoryCache, type InMemoryCacheConfig, type TypePolicies } from '@apollo/client';\nimport { possibleTypes } from '../generated/fragment-types.js';\n\n/**\n * Per-entity normalization and field-merge rules for the Storefront cache.\n *\n * The cart and the order share three types whose ids neither can scope\n * (docs/features/order-placed/rfc.md, 3.4): a totalizer's id is its category\n * (\"Items\"), which the cart's totalizer line selects by; an address's id is the\n * saved address itself, masked on the order and not on the cart; and a\n * customization's id is the assembly (\"Engraving\"), which two lines of one cart\n * already share. Normalized, one record would overwrite the other, so each is\n * stored inside the record that holds it, and replaced on every write: safe\n * while every fragment selects the same subfields of each.\n *\n * The lists that hold them are the server's whole answer, so each write\n * replaces the list (`merge: false`). Apollo does the same by default, but warns\n * that data may be lost whenever such a list shrinks, as when a discount line\n * leaves the cart's totalizers; a merge by id would keep that stale line.\n *\n * Other domain entries arrive with the particles that need them — see\n * docs/storefront-core/reference-free-particle-model.md § Typed documents and the shared cache.\n */\nconst replaceList = { merge: false } as const;\n\nexport const typePolicies: TypePolicies = {\n CartTotalizer: { keyFields: false },\n Address: { keyFields: false },\n CartItemCustomization: { keyFields: false },\n Cart: { fields: { totalizers: replaceList } },\n CartItem: { fields: { customizations: replaceList } },\n CartItemComposition: { fields: { customizations: replaceList } },\n Shipping: { fields: { savedAddresses: replaceList } },\n Order: { fields: { totals: replaceList } },\n SellerOrder: { fields: { totals: replaceList } },\n OrderItem: { fields: { customizations: replaceList } },\n};\n\nexport { possibleTypes };\n\n/**\n * The single source of truth for InMemoryCache configuration. Both the\n * server-side `createClient` and the client-side `StorefrontProvider`\n * consume this so SSR and CSR normalize entities identically.\n */\nexport function getCacheConfig(): InMemoryCacheConfig {\n return {\n typePolicies,\n possibleTypes,\n };\n}\n\n/**\n * The only place an `InMemoryCache` is constructed on the server path.\n * The client-side provider builds its cache from `getCacheConfig()` so the\n * config is shared verbatim without coupling to a specific InMemoryCache\n * subclass (the Next.js integration ships its own SSR-aware variant).\n */\nexport function buildCache(): InMemoryCache {\n return new InMemoryCache(getCacheConfig());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,cAAc,EAAE,OAAO,MAAM;AAEnC,MAAa,eAA6B;CACxC,eAAe,EAAE,WAAW,MAAM;CAClC,SAAS,EAAE,WAAW,MAAM;CAC5B,uBAAuB,EAAE,WAAW,MAAM;CAC1C,MAAM,EAAE,QAAQ,EAAE,YAAY,YAAY,EAAE;CAC5C,UAAU,EAAE,QAAQ,EAAE,gBAAgB,YAAY,EAAE;CACpD,qBAAqB,EAAE,QAAQ,EAAE,gBAAgB,YAAY,EAAE;CAC/D,UAAU,EAAE,QAAQ,EAAE,gBAAgB,YAAY,EAAE;CACpD,OAAO,EAAE,QAAQ,EAAE,QAAQ,YAAY,EAAE;CACzC,aAAa,EAAE,QAAQ,EAAE,QAAQ,YAAY,EAAE;CAC/C,WAAW,EAAE,QAAQ,EAAE,gBAAgB,YAAY,EAAE;AACvD;;;;;;AASA,SAAgB,iBAAsC;CACpD,OAAO;EACL;EACA;CACF;AACF;;;;;;;AAQA,SAAgB,aAA4B;CAC1C,OAAO,IAAI,cAAc,eAAe,CAAC;AAC3C"}
|
|
@@ -17,6 +17,8 @@ export type FetchPageDataOptions<TVars extends OperationVariables> = {} extends
|
|
|
17
17
|
export type FetchPageDataResult<TData> = {
|
|
18
18
|
data: TData | null;
|
|
19
19
|
error?: ErrorLike;
|
|
20
|
+
/** Response keys of top-level fields that resolved to null beside an error at their path. */
|
|
21
|
+
failedFields: string[];
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Runs a single query against the provided Apollo Client with the options
|
|
@@ -33,6 +35,15 @@ export type FetchPageDataResult<TData> = {
|
|
|
33
35
|
* partial `data` the server produced. Callers who need to distinguish the
|
|
34
36
|
* two can inspect `result.error` with `CombinedGraphQLErrors.is()` from
|
|
35
37
|
* `@apollo/client/errors`.
|
|
38
|
+
*
|
|
39
|
+
* `failedFields` names the root fields a section cannot render from this
|
|
40
|
+
* result: `null` in `data` with an error whose `path` starts at them. A null
|
|
41
|
+
* with no error is a legitimate absence, and an error below a root that kept
|
|
42
|
+
* its data leaves that root renderable, so neither counts. With no data at
|
|
43
|
+
* all, a failed non-null root nulled the whole response, and every root an
|
|
44
|
+
* error's `path` starts at counts. The browser skips
|
|
45
|
+
* seeding a result with failed fields and asks again
|
|
46
|
+
* (docs/storefront-core/reference-data-layer-runtime.md § Page scope).
|
|
36
47
|
*/
|
|
37
48
|
export declare function fetchPageData<TData = unknown, TVars extends OperationVariables = OperationVariables>(client: ApolloClient, document: DocumentNode | TypedDocumentNode<TData, TVars>, options?: FetchPageDataOptions<TVars>): Promise<FetchPageDataResult<TData>>;
|
|
38
49
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getFailedFields } from "../data/failed-fields.js";
|
|
1
2
|
//#region src/sdk/client/fetch-page-data.ts
|
|
2
3
|
/**
|
|
3
4
|
* Runs a single query against the provided Apollo Client with the options
|
|
@@ -14,6 +15,15 @@
|
|
|
14
15
|
* partial `data` the server produced. Callers who need to distinguish the
|
|
15
16
|
* two can inspect `result.error` with `CombinedGraphQLErrors.is()` from
|
|
16
17
|
* `@apollo/client/errors`.
|
|
18
|
+
*
|
|
19
|
+
* `failedFields` names the root fields a section cannot render from this
|
|
20
|
+
* result: `null` in `data` with an error whose `path` starts at them. A null
|
|
21
|
+
* with no error is a legitimate absence, and an error below a root that kept
|
|
22
|
+
* its data leaves that root renderable, so neither counts. With no data at
|
|
23
|
+
* all, a failed non-null root nulled the whole response, and every root an
|
|
24
|
+
* error's `path` starts at counts. The browser skips
|
|
25
|
+
* seeding a result with failed fields and asks again
|
|
26
|
+
* (docs/storefront-core/reference-data-layer-runtime.md § Page scope).
|
|
17
27
|
*/
|
|
18
28
|
async function fetchPageData(client, document, options = {}) {
|
|
19
29
|
const result = await client.query({
|
|
@@ -24,7 +34,8 @@ async function fetchPageData(client, document, options = {}) {
|
|
|
24
34
|
});
|
|
25
35
|
return {
|
|
26
36
|
data: result.data ?? null,
|
|
27
|
-
...result.error ? { error: result.error } : {}
|
|
37
|
+
...result.error ? { error: result.error } : {},
|
|
38
|
+
failedFields: getFailedFields(result.data, result.error)
|
|
28
39
|
};
|
|
29
40
|
}
|
|
30
41
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-page-data.js","names":[],"sources":["../../../src/sdk/client/fetch-page-data.ts"],"sourcesContent":["import type { ApolloClient, DocumentNode, ErrorLike, OperationVariables, TypedDocumentNode } from '@apollo/client';\n\n/**\n * Options bag accepted by {@link fetchPageData}.\n *\n * Mirrors Apollo Client 4.x's own `VariablesOption<TVars>` shape: when\n * `TVars` has no required keys (the default `OperationVariables`), variables\n * are optional; when the caller supplies a concrete variables object with\n * required fields, variables become required — matching the contract of the\n * underlying `client.query` call.\n */\n// biome-ignore lint/complexity/noBannedTypes: `{} extends TVars` is the idiomatic probe for \"variables has no required keys\" — same pattern Apollo itself uses.\nexport type FetchPageDataOptions<TVars extends OperationVariables> = {} extends TVars\n ? { variables?: TVars }\n : { variables: TVars };\n\nexport type FetchPageDataResult<TData> = {\n data: TData | null;\n error?: ErrorLike;\n};\n\n/**\n * Runs a single query against the provided Apollo Client with the options\n * required for stateless RSC rendering (`errorPolicy: 'all'` — partial data\n * is returned alongside the error — and `fetchPolicy: 'no-cache'` — the\n * client's cache is never consulted, so a long-lived module-level client\n * cannot leak state across requests).\n *\n * Never constructs a client itself; callers own the client lifetime via\n * the generated `utils/query-client.ts` or a direct `createClient()` call.\n *\n * Under `errorPolicy: 'all'`, Apollo reports every failure — GraphQL errors\n * and transport-level errors alike — via the `error` field alongside any\n * partial `data` the server produced. Callers who need to distinguish the\n * two can inspect `result.error` with `CombinedGraphQLErrors.is()` from\n * `@apollo/client/errors`.\n */\nexport async function fetchPageData<TData = unknown, TVars extends OperationVariables = OperationVariables>(\n client: ApolloClient,\n document: DocumentNode | TypedDocumentNode<TData, TVars>,\n options: FetchPageDataOptions<TVars> = {} as FetchPageDataOptions<TVars>,\n): Promise<FetchPageDataResult<TData>> {\n const result = await client.query<TData, TVars>({\n ...options,\n query: document,\n errorPolicy: 'all',\n fetchPolicy: 'no-cache',\n });\n\n return {\n data: result.data ?? null,\n ...(result.error ? { error: result.error } : {}),\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch-page-data.js","names":[],"sources":["../../../src/sdk/client/fetch-page-data.ts"],"sourcesContent":["import type { ApolloClient, DocumentNode, ErrorLike, OperationVariables, TypedDocumentNode } from '@apollo/client';\nimport { getFailedFields } from '../data/failed-fields.js';\n\n/**\n * Options bag accepted by {@link fetchPageData}.\n *\n * Mirrors Apollo Client 4.x's own `VariablesOption<TVars>` shape: when\n * `TVars` has no required keys (the default `OperationVariables`), variables\n * are optional; when the caller supplies a concrete variables object with\n * required fields, variables become required — matching the contract of the\n * underlying `client.query` call.\n */\n// biome-ignore lint/complexity/noBannedTypes: `{} extends TVars` is the idiomatic probe for \"variables has no required keys\" — same pattern Apollo itself uses.\nexport type FetchPageDataOptions<TVars extends OperationVariables> = {} extends TVars\n ? { variables?: TVars }\n : { variables: TVars };\n\nexport type FetchPageDataResult<TData> = {\n data: TData | null;\n error?: ErrorLike;\n /** Response keys of top-level fields that resolved to null beside an error at their path. */\n failedFields: string[];\n};\n\n/**\n * Runs a single query against the provided Apollo Client with the options\n * required for stateless RSC rendering (`errorPolicy: 'all'` — partial data\n * is returned alongside the error — and `fetchPolicy: 'no-cache'` — the\n * client's cache is never consulted, so a long-lived module-level client\n * cannot leak state across requests).\n *\n * Never constructs a client itself; callers own the client lifetime via\n * the generated `utils/query-client.ts` or a direct `createClient()` call.\n *\n * Under `errorPolicy: 'all'`, Apollo reports every failure — GraphQL errors\n * and transport-level errors alike — via the `error` field alongside any\n * partial `data` the server produced. Callers who need to distinguish the\n * two can inspect `result.error` with `CombinedGraphQLErrors.is()` from\n * `@apollo/client/errors`.\n *\n * `failedFields` names the root fields a section cannot render from this\n * result: `null` in `data` with an error whose `path` starts at them. A null\n * with no error is a legitimate absence, and an error below a root that kept\n * its data leaves that root renderable, so neither counts. With no data at\n * all, a failed non-null root nulled the whole response, and every root an\n * error's `path` starts at counts. The browser skips\n * seeding a result with failed fields and asks again\n * (docs/storefront-core/reference-data-layer-runtime.md § Page scope).\n */\nexport async function fetchPageData<TData = unknown, TVars extends OperationVariables = OperationVariables>(\n client: ApolloClient,\n document: DocumentNode | TypedDocumentNode<TData, TVars>,\n options: FetchPageDataOptions<TVars> = {} as FetchPageDataOptions<TVars>,\n): Promise<FetchPageDataResult<TData>> {\n const result = await client.query<TData, TVars>({\n ...options,\n query: document,\n errorPolicy: 'all',\n fetchPolicy: 'no-cache',\n });\n\n return {\n data: result.data ?? null,\n ...(result.error ? { error: result.error } : {}),\n failedFields: getFailedFields(result.data, result.error),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,eAAsB,cACpB,QACA,UACA,UAAuC,CAAC,GACH;CACrC,MAAM,SAAS,MAAM,OAAO,MAAoB;EAC9C,GAAG;EACH,OAAO;EACP,aAAa;EACb,aAAa;CACf,CAAC;CAED,OAAO;EACL,MAAM,OAAO,QAAQ;EACrB,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,IAAI,CAAC;EAC9C,cAAc,gBAAgB,OAAO,MAAM,OAAO,KAAK;CACzD;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ownValue } from "../../utils/own-value.js";
|
|
1
2
|
import { cache } from "react";
|
|
2
3
|
import { cookies, draftMode } from "next/headers";
|
|
3
4
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
@@ -571,14 +572,6 @@ function blobByteLength(blob) {
|
|
|
571
572
|
function isRecord(value) {
|
|
572
573
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
573
574
|
}
|
|
574
|
-
/**
|
|
575
|
-
* Own-property read. Every object keyed by an authored id here comes from `JSON.parse` or a plain
|
|
576
|
-
* literal, so it carries `Object.prototype`: a key named `__proto__` or `constructor` would resolve
|
|
577
|
-
* to something inherited instead of to `undefined`, and the absent-key branch would never be taken.
|
|
578
|
-
*/
|
|
579
|
-
function ownValue(source, key) {
|
|
580
|
-
return Object.hasOwn(source, key) ? source[key] : void 0;
|
|
581
|
-
}
|
|
582
575
|
/** Property check instead of `instanceof`: `AbortSignal.timeout` rejects with a `DOMException`. */
|
|
583
576
|
function isTimeoutError(error) {
|
|
584
577
|
if (typeof error !== "object" || error === null) return false;
|