@thorprovider/storefront 0.6.3 → 0.9.0

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.
Files changed (161) hide show
  1. package/README.md +22 -2
  2. package/assets/templates/AGENTS.md +14 -2
  3. package/assets/templates/app/app/[[...slug]]/page.tsx +9 -2
  4. package/assets/templates/app/lib/__STOREFRONT__/account-address.ts +129 -0
  5. package/assets/templates/app/lib/__STOREFRONT__/account-lifecycle.client.tsx +2 -2
  6. package/assets/templates/app/lib/__STOREFRONT__/account-private.core.ts +143 -0
  7. package/assets/templates/app/lib/__STOREFRONT__/account-profile.ts +220 -0
  8. package/assets/templates/app/lib/__STOREFRONT__/actions.ts +1234 -75
  9. package/assets/templates/app/lib/__STOREFRONT__/addresses-port.ts +107 -0
  10. package/assets/templates/app/lib/__STOREFRONT__/checkout-shipping.core.ts +37 -0
  11. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +460 -35
  12. package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +240 -0
  13. package/assets/templates/app/lib/__STOREFRONT__/customer-profile-port.ts +103 -0
  14. package/assets/templates/app/lib/__STOREFRONT__/order-detail-port.ts +26 -0
  15. package/assets/templates/app/lib/__STOREFRONT__/orders-port.ts +30 -0
  16. package/assets/templates/app/lib/__STOREFRONT__/ports.ts +18 -0
  17. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +4 -4
  18. package/assets/templates/app/lib/__STOREFRONT__/session.ts +24 -6
  19. package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +28 -1
  20. package/assets/templates/app/lib/__STOREFRONT__/views/sections/address-book-advanced.client.tsx +29 -0
  21. package/assets/templates/app/lib/__STOREFRONT__/views/sections/checkout-commerce-v1.client.tsx +19 -0
  22. package/assets/templates/app/lib/__STOREFRONT__/views/sections/checkout-commerce-v1.tsx +16 -0
  23. package/assets/templates/app/lib/__STOREFRONT__/views/sections/customer-profile.client.tsx +27 -0
  24. package/assets/templates/app/lib/__STOREFRONT__/views/sections/index.ts +5 -1
  25. package/assets/templates/app/lib/__STOREFRONT__/views/sections/marketplace-product-card.client.tsx +19 -0
  26. package/assets/templates/app/lib/__STOREFRONT__/views/sections/marketplace-product-card.tsx +16 -0
  27. package/assets/templates/app/lib/__STOREFRONT__/views/sections/mega-menu-universal.client.tsx +19 -0
  28. package/assets/templates/app/lib/__STOREFRONT__/views/sections/mega-menu-universal.tsx +16 -0
  29. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.address-book-advanced.ts +437 -0
  30. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.checkout-commerce-v1.ts +398 -0
  31. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.customer-profile.ts +138 -0
  32. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.marketplace-product-card.ts +67 -0
  33. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.mega-menu-universal.ts +76 -0
  34. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.universal-banner.ts +217 -0
  35. package/assets/templates/app/lib/__STOREFRONT__/views/sections/universal-banner.client.tsx +24 -0
  36. package/assets/templates/app/lib/__STOREFRONT__/views/sections/universal-banner.tsx +16 -0
  37. package/assets/templates/features/checkout/handlers.ts +348 -33
  38. package/assets/templates/features/checkout/state.ts +79 -3
  39. package/assets/templates/features/customer-addresses/handlers.ts +11 -0
  40. package/assets/templates/features/customer-addresses/state.ts +33 -0
  41. package/assets/templates/features/customer-auth/state.ts +10 -0
  42. package/assets/templates/features/customer-profile/handlers.ts +11 -0
  43. package/assets/templates/features/customer-profile/state.ts +18 -0
  44. package/assets/templates/views/account/address-book-advanced.defaults.ts +534 -0
  45. package/assets/templates/views/account/assembly/assembly.json +41 -0
  46. package/assets/templates/views/account/assembly/index.skeleton.tsx +229 -0
  47. package/assets/templates/views/account/assembly/registry.skeleton.tsx +1116 -0
  48. package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/binding.json +5 -0
  49. package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/catalog.part +4 -0
  50. package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/element.part +5 -0
  51. package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/registry.part +1 -0
  52. package/assets/templates/views/account/assembly/slots/addresses/cards/catalog.part +5 -0
  53. package/assets/templates/views/account/assembly/slots/addresses/cards/element.part +10 -0
  54. package/assets/templates/views/account/assembly/slots/addresses/cards/registry.part +1 -0
  55. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/catalog.part +5 -0
  56. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/element.part +5 -0
  57. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/registry.part +1 -0
  58. package/assets/templates/views/account/assembly/slots/login/card/catalog.part +4 -0
  59. package/assets/templates/views/account/assembly/slots/login/card/element.part +13 -0
  60. package/assets/templates/views/account/assembly/slots/login/card/registry.part +1 -0
  61. package/assets/templates/views/account/assembly/slots/orders/OrderHistory/catalog.part +5 -0
  62. package/assets/templates/views/account/assembly/slots/orders/OrderHistory/element.part +5 -0
  63. package/assets/templates/views/account/assembly/slots/orders/OrderHistory/registry.part +2 -0
  64. package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/binding.json +5 -0
  65. package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/catalog.part +5 -0
  66. package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/element.part +5 -0
  67. package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/registry.part +1 -0
  68. package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/binding.json +5 -0
  69. package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/catalog.part +4 -0
  70. package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/element.part +5 -0
  71. package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/registry.part +1 -0
  72. package/assets/templates/views/account/assembly/slots/profile/form/catalog.part +5 -0
  73. package/assets/templates/views/account/assembly/slots/profile/form/element.part +10 -0
  74. package/assets/templates/views/account/assembly/slots/profile/form/registry.part +1 -0
  75. package/assets/templates/views/account/assembly/slots/register/SignUpPage1/catalog.part +4 -0
  76. package/assets/templates/views/account/assembly/slots/register/SignUpPage1/element.part +13 -0
  77. package/assets/templates/views/account/assembly/slots/register/SignUpPage1/registry.part +1 -0
  78. package/assets/templates/views/account/assembly/slots/summary/stack/catalog.part +5 -0
  79. package/assets/templates/views/account/assembly/slots/summary/stack/element.part +5 -0
  80. package/assets/templates/views/account/assembly/slots/summary/stack/registry.part +1 -0
  81. package/assets/templates/views/account/assembly/slots/summary/tabs/catalog.part +5 -0
  82. package/assets/templates/views/account/assembly/slots/summary/tabs/element.part +5 -0
  83. package/assets/templates/views/account/assembly/slots/summary/tabs/registry.part +1 -0
  84. package/assets/templates/views/account/content.ts +326 -0
  85. package/assets/templates/views/account/customer-profile.defaults.ts +136 -0
  86. package/assets/templates/views/account/index.tsx +218 -35
  87. package/assets/templates/views/account/order-detail.client.tsx +35 -0
  88. package/assets/templates/views/account/order-detail.defaults.ts +457 -0
  89. package/assets/templates/views/account/orders-advanced.client.tsx +166 -0
  90. package/assets/templates/views/account/orders-advanced.defaults.ts +230 -0
  91. package/assets/templates/views/account/registry.tsx +944 -369
  92. package/assets/templates/views/account/schema.ts +50 -0
  93. package/assets/templates/views/account/sections-data.ts +2 -0
  94. package/assets/templates/views/cart/content.ts +1 -0
  95. package/assets/templates/views/category/assembly/index.skeleton.tsx +1 -0
  96. package/assets/templates/views/category/assembly/slots/filter/CategoryListing/element.part +1 -0
  97. package/assets/templates/views/category/content.ts +2 -0
  98. package/assets/templates/views/category/index.tsx +2 -0
  99. package/assets/templates/views/category/sections-data.ts +2 -0
  100. package/assets/templates/views/checkout/checkout-commerce-hosted.tsx +1089 -0
  101. package/assets/templates/views/checkout/content.ts +114 -2
  102. package/assets/templates/views/checkout/index.tsx +7 -1
  103. package/assets/templates/views/checkout/props.ts +70 -22
  104. package/assets/templates/views/checkout/registry.tsx +400 -71
  105. package/assets/templates/views/checkout/schema.ts +260 -9
  106. package/assets/templates/views/home/assembly/assembly.json +28 -0
  107. package/assets/templates/views/home/assembly/index.skeleton.tsx +1 -0
  108. package/assets/templates/views/home/content.ts +2 -0
  109. package/assets/templates/views/home/index.tsx +1 -0
  110. package/assets/templates/views/home/sections-data.ts +2 -0
  111. package/assets/templates/views/product/content.ts +1 -0
  112. package/assets/templates/views/static/content.ts +1 -0
  113. package/bin/storefront.js +343 -13
  114. package/package.json +2 -1
  115. package/recipes/adapter-surface.json +158 -0
  116. package/recipes/archetypes.json +38 -3
  117. package/recipes/catalog.json +138 -1
  118. package/recipes/feature.schema.json +9 -0
  119. package/recipes/features.json +72 -1
  120. package/recipes/manifest.schema.json +5 -0
  121. package/recipes/recipe.schema.json +14 -2
  122. package/recipes/recipes.json +35 -5
  123. package/recipes/section.schema.json +112 -0
  124. package/recipes/sections.json +289 -3
  125. package/recipes/validate.mjs +83 -1
  126. package/scripts/adapter-surface.mjs +41 -0
  127. package/scripts/agent-blocks.mjs +700 -0
  128. package/scripts/block-validator.mjs +45 -0
  129. package/scripts/candidate.mjs +5 -4
  130. package/scripts/composers.mjs +7 -2
  131. package/scripts/default-sections.mjs +78 -0
  132. package/scripts/file-classes.mjs +15 -0
  133. package/scripts/generate-adapter-surface.mjs +148 -0
  134. package/scripts/operations.mjs +100 -0
  135. package/scripts/reconcile.mjs +67 -39
  136. package/scripts/section-configure.mjs +316 -0
  137. package/scripts/sync-assets.mjs +1 -0
  138. package/scripts/view-assembly.mjs +101 -14
  139. package/skills/sf-feature/SKILL.md +19 -0
  140. package/skills/sf-view-gen/SKILL.md +79 -7
  141. package/skills/sf-view-gen/assets/recipes/archetypes.json +38 -3
  142. package/skills/sf-view-gen/assets/recipes/catalog.json +138 -1
  143. package/skills/sf-view-gen/assets/recipes/features.json +72 -1
  144. package/skills/sf-view-gen/assets/recipes/recipes.json +35 -5
  145. package/skills/sf-view-gen/assets/recipes/section.schema.json +112 -0
  146. package/skills/sf-view-gen/assets/recipes/sections.json +289 -3
  147. package/skills/sf-view-gen/assets/templates/views/sections/checkout-commerce-v1.client.tsx +19 -0
  148. package/skills/sf-view-gen/assets/templates/views/sections/checkout-commerce-v1.tsx +16 -0
  149. package/skills/sf-view-gen/assets/templates/views/sections/marketplace-product-card.client.tsx +19 -0
  150. package/skills/sf-view-gen/assets/templates/views/sections/marketplace-product-card.tsx +16 -0
  151. package/skills/sf-view-gen/assets/templates/views/sections/mega-menu-universal.client.tsx +19 -0
  152. package/skills/sf-view-gen/assets/templates/views/sections/mega-menu-universal.tsx +16 -0
  153. package/skills/sf-view-gen/assets/templates/views/sections/schema.checkout-commerce-v1.ts +398 -0
  154. package/skills/sf-view-gen/assets/templates/views/sections/schema.marketplace-product-card.ts +67 -0
  155. package/skills/sf-view-gen/assets/templates/views/sections/schema.mega-menu-universal.ts +76 -0
  156. package/skills/sf-view-gen/assets/templates/views/sections/schema.universal-banner.ts +217 -0
  157. package/skills/sf-view-gen/assets/templates/views/sections/universal-banner.client.tsx +24 -0
  158. package/skills/sf-view-gen/assets/templates/views/sections/universal-banner.tsx +16 -0
  159. package/skills/sf-view-gen/scripts/validate.mjs +83 -1
  160. package/skills/storefront-workflow/SKILL.md +5 -0
  161. package/skills/storefront-workflow/references/mobile-responsiveness.md +1 -1
@@ -10,25 +10,71 @@ import { useEffect, useRef } from 'react'
10
10
  import { Button } from '@thorprovider/blocks/ui/button'
11
11
  import CheckoutBlock from '@thorprovider/blocks/blocks/e-commerce/checkout-forms/checkout'
12
12
  import CheckoutConfirmationBlock from '@thorprovider/blocks/blocks/e-commerce/checkout-forms/checkout-confirmation'
13
+ import { CheckoutConfirmationView } from '@thorprovider/blocks'
14
+ import { CheckoutCommerceHostedAdapter } from './checkout-commerce-hosted'
15
+ import { useNextApp } from '@json-render/next'
13
16
  import { useStateStore } from '@json-render/react'
14
- import { loadCheckoutAction, reconcileReceiptAction } from '../../actions'
17
+ import {
18
+ loadCheckoutAction,
19
+ loadCheckoutLocationsAction,
20
+ loadCheckoutPrefillAction,
21
+ reconcileReceiptAction,
22
+ } from '../../actions'
23
+ import type {
24
+ CheckoutAddressValues,
25
+ CheckoutContactValues,
26
+ CheckoutShippingGroup,
27
+ } from '@thorprovider/blocks'
15
28
  import type { CartStatePatch, PlaceOrderResult } from '../../commerce'
16
29
  import type { ViewRegistry } from '../types'
17
- import { checkoutConfirmationPropsSchema, checkoutPropsSchema } from './schema'
30
+ import {
31
+ checkoutConfirmationPropsSchema,
32
+ checkoutPropsSchema,
33
+ validateCheckoutContactPhone,
34
+ validateCheckoutShippingAddress,
35
+ } from './schema'
18
36
 
19
- // Address fields whose change can complete the address; when the full address
20
- // is present the handler syncs it to the backend and loads eligible shipping.
21
- const ADDRESS_FIELDS = new Set([
22
- 'email',
23
- 'firstName',
24
- 'lastName',
25
- 'phone',
26
- 'address',
27
- 'city',
28
- 'state',
29
- 'zipCode',
30
- 'country',
31
- ])
37
+ /** Normalize malformed error state before clearing a single phone field. */
38
+ export function clearPhoneFieldError(
39
+ errors: unknown,
40
+ groupName: 'contact' | 'shippingAddress',
41
+ ): Record<string, unknown> {
42
+ const next =
43
+ errors !== null && typeof errors === 'object' && !Array.isArray(errors)
44
+ ? { ...(errors as Record<string, unknown>) }
45
+ : {}
46
+ const group = next[groupName]
47
+ if (group && typeof group === 'object' && !Array.isArray(group)) {
48
+ const fields = { ...(group as Record<string, unknown>) }
49
+ delete fields.phone
50
+ next[groupName] = fields
51
+ }
52
+ return next
53
+ }
54
+
55
+ function flatToContact(values: Record<string, unknown>): CheckoutContactValues {
56
+ const str = (key: string) => (typeof values[key] === 'string' ? (values[key] as string) : '')
57
+ return {
58
+ email: str('email'),
59
+ firstName: str('firstName'),
60
+ lastName: str('lastName'),
61
+ phone: str('phone'),
62
+ }
63
+ }
64
+
65
+ function flatToAddress(values: Record<string, unknown>): CheckoutAddressValues {
66
+ const str = (key: string) => (typeof values[key] === 'string' ? (values[key] as string) : '')
67
+ return {
68
+ firstName: str('firstName'),
69
+ lastName: str('lastName'),
70
+ address1: str('address'),
71
+ city: str('city'),
72
+ province: str('state'),
73
+ postalCode: str('zipCode'),
74
+ countryCode: str('country'),
75
+ phone: str('phone'),
76
+ }
77
+ }
32
78
 
33
79
  export const registry: ViewRegistry = {
34
80
  /**
@@ -39,6 +85,7 @@ export const registry: ViewRegistry = {
39
85
  */
40
86
  CheckoutBoot: () => {
41
87
  const { state, set } = useStateStore()
88
+ const { navigate } = useNextApp()
42
89
  const booted = useRef(false)
43
90
  useEffect(() => {
44
91
  if (booted.current) return
@@ -47,9 +94,14 @@ export const registry: ViewRegistry = {
47
94
  const applyResult = (result: PlaceOrderResult) => {
48
95
  set('/checkoutPending', false)
49
96
  if (result.status === 'order') {
50
- // ONE atomic write carries the order and its backend lines, so an SSR
51
- // refresh cannot drop the lines.
52
- set('/lastReceipt', { order: result.order, lines: result.lines })
97
+ // ONE atomic write carries the order, its backend lines and the
98
+ // host-confirmed confirmation model, so an SSR refresh cannot drop
99
+ // the confirmation data.
100
+ set('/lastReceipt', {
101
+ order: result.order,
102
+ lines: result.lines,
103
+ confirmation: result.confirmation,
104
+ })
53
105
  set('/orderStatus', 'complete')
54
106
  set('/checkoutError', null)
55
107
  set('/checkoutErrorKind', null)
@@ -59,6 +111,14 @@ export const registry: ViewRegistry = {
59
111
  set('/cartQuantity', 0)
60
112
  set('/cartCompleted', true)
61
113
  set('/checkoutSelectedShippingOptionId', null)
114
+ // The completed cart's delivery groups are gone with it.
115
+ set('/checkoutShippingGroups', [])
116
+ set('/checkoutShippingGroupProducts', {})
117
+ set('/checkoutShippingState', 'idle')
118
+ return
119
+ }
120
+ if (result.code === 'AUTH_REQUIRED') {
121
+ navigate('/account')
62
122
  return
63
123
  }
64
124
  set('/orderStatus', result.status === 'cart-error' ? 'error' : result.status)
@@ -90,10 +150,18 @@ export const registry: ViewRegistry = {
90
150
  }
91
151
  if (state.cartId) {
92
152
  set('/checkoutPending', true)
93
- void loadCheckoutAction()
153
+ void loadCheckoutAction({
154
+ // Reconcile the shopper's per-group selections by stable identity on
155
+ // a re-entry into the checkout.
156
+ previousShippingGroups: (state.checkoutShippingGroups ?? []) as CheckoutShippingGroup[],
157
+ })
94
158
  .then((result) => {
95
159
  set('/checkoutPending', false)
96
160
  if (!result.ok) {
161
+ if (result.code === 'AUTH_REQUIRED') {
162
+ navigate('/account')
163
+ return
164
+ }
97
165
  set('/checkoutError', result.error)
98
166
  set('/checkoutErrorKind', 'error')
99
167
  return
@@ -107,8 +175,64 @@ export const registry: ViewRegistry = {
107
175
  set('/checkoutSelectedShippingOptionId', cart.cartSelectedShippingOptionId)
108
176
  if (result.countries) set('/checkoutCountries', result.countries)
109
177
  if (result.paymentMethods) set('/checkoutPaymentMethods', result.paymentMethods)
110
- if (result.shippingOptions) set('/checkoutShippingOptions', result.shippingOptions)
178
+ // The backend group quote is authoritative and mapped 1:1 — the
179
+ // host never wraps the flat option list into one group (D7).
180
+ set('/checkoutShippingGroups', result.shippingGroups ?? [])
181
+ set('/checkoutShippingGroupProducts', result.shippingGroupProducts ?? {})
182
+ if (result.shippingError) {
183
+ // Delivery failures stay in the delivery state only (R1): the
184
+ // block renders the error/unavailable copy and its own retry.
185
+ // `unavailable` means the provider cannot serve grouped delivery.
186
+ set('/checkoutShippingState', result.shippingState ?? 'error')
187
+ } else {
188
+ set('/checkoutShippingState', 'idle')
189
+ }
190
+
191
+ const flat = (state.checkout ?? {}) as Record<string, unknown>
192
+ const contact = flatToContact(flat)
193
+ const shippingAddress = flatToAddress(flat)
194
+ const countries = result.countries ?? []
195
+ set('/checkoutContact', contact)
196
+ set('/checkoutShippingAddress', shippingAddress)
197
+ set('/checkoutBillingAddress', shippingAddress)
198
+ set('/checkoutSameAsShipping', true)
199
+ set('/checkout/paymentMethod', typeof flat.paymentMethod === 'string' ? flat.paymentMethod : '')
200
+ set('/checkoutShippingLocations', { countries, provinces: [], cities: [] })
201
+ set('/checkoutBillingLocations', { countries, provinces: [], cities: [] })
202
+ set('/checkoutPaymentState', 'idle')
111
203
  set('/checkoutError', null)
204
+
205
+ void loadCheckoutPrefillAction({
206
+ contact,
207
+ shippingAddress,
208
+ sameAsShipping: true,
209
+ })
210
+ .then((prefill) => {
211
+ if (!prefill.ok) {
212
+ if (prefill.code === 'AUTH_REQUIRED') {
213
+ navigate('/account')
214
+ }
215
+ return
216
+ }
217
+ set('/checkoutContact', prefill.contact)
218
+ set('/checkoutShippingAddress', prefill.shippingAddress)
219
+ if (prefill.billingAddress) set('/checkoutBillingAddress', prefill.billingAddress)
220
+ set('/checkoutSameAsShipping', prefill.sameAsShipping)
221
+ set('/checkoutCustomer', prefill.customer)
222
+ set('/checkoutSavedAddresses', prefill.savedAddresses)
223
+ set('/checkoutShippingLocations', prefill.shippingLocations)
224
+ set('/checkoutBillingLocations', prefill.billingLocations)
225
+ if (prefill.customerUnavailable) {
226
+ set('/checkoutInterruption', {
227
+ kind: 'session-expired',
228
+ severity: 'info',
229
+ title: 'No pudimos cargar tu cuenta',
230
+ message: 'Puedes continuar y completar los datos manualmente.',
231
+ actions: ['retry'],
232
+ })
233
+ }
234
+ })
235
+ .catch(bootError('loadCheckoutPrefill'))
112
236
  })
113
237
  .catch(bootError('loadCheckout'))
114
238
  return
@@ -120,16 +244,92 @@ export const registry: ViewRegistry = {
120
244
  }, [])
121
245
  return null
122
246
  },
123
- Checkout: ({ props, emit }) => {
247
+ // One-line rollback: Checkout: ({ props, emit }) => registry.CheckoutCanonical({ props, emit }),
248
+ // The shell `main` paints no padding, so this host supplies the page canvas
249
+ // the design block deliberately does not paint (block-viewport-ownership).
250
+ // Width and gutters stay consistent with the /account view container; the
251
+ // rollback target keeps its own frame, so it is not wrapped twice.
252
+ Checkout: ({ props, emit }) => (
253
+ <div className="mx-auto w-full max-w-7xl px-4 py-10 sm:px-6 lg:px-8">
254
+ <CheckoutCommerceHostedAdapter
255
+ props={props}
256
+ emit={emit}
257
+ loadLocations={loadCheckoutLocationsAction}
258
+ />
259
+ </div>
260
+ ),
261
+ // Retained in the element map as the one-line rollback target for the hosted route.
262
+ CheckoutCanonical: ({ props, emit }) => {
124
263
  const { state, set } = useStateStore()
125
264
  const parsed = checkoutPropsSchema.parse(props)
126
265
  const unresolved = state.checkoutErrorKind === 'unresolved'
127
266
  const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
128
267
  const checkoutError = typeof state.checkoutError === 'string' ? state.checkoutError : undefined
268
+ // A failed/unsupported grouped quote owns the delivery state, so the retry
269
+ // for its submit-time error must refresh the quote, not re-place the order.
270
+ const shippingFailed =
271
+ state.checkoutShippingState === 'error' || state.checkoutShippingState === 'unavailable'
272
+ const managementEnabled = Boolean(parsed.customer)
273
+
274
+ const setFlatAddress = (address: CheckoutAddressValues) => {
275
+ set('/checkout/address', address.address1)
276
+ set('/checkout/firstName', address.firstName)
277
+ set('/checkout/lastName', address.lastName)
278
+ set('/checkout/city', address.city)
279
+ set('/checkout/state', address.province ?? '')
280
+ set('/checkout/zipCode', address.postalCode ?? '')
281
+ set('/checkout/country', address.countryCode)
282
+ set('/checkout/phone', address.phone ?? '')
283
+ }
284
+
285
+ const flatField = (field: keyof CheckoutAddressValues) =>
286
+ field === 'address1'
287
+ ? 'address'
288
+ : field === 'province'
289
+ ? 'state'
290
+ : field === 'postalCode'
291
+ ? 'zipCode'
292
+ : field === 'countryCode'
293
+ ? 'country'
294
+ : field
295
+
296
+ const updateShipping = (field: keyof CheckoutAddressValues, value: string) => {
297
+ set(`/checkoutShippingAddress/${field}`, value)
298
+ set(`/checkout/${flatField(field)}`, value)
299
+ if (field === 'phone') {
300
+ set(
301
+ '/checkoutFieldErrors',
302
+ clearPhoneFieldError(state.checkoutFieldErrors, 'shippingAddress'),
303
+ )
304
+ }
305
+ if (field === 'countryCode') {
306
+ set('/checkoutShippingLocations', {
307
+ ...(parsed.shippingLocations ?? { countries: [], provinces: [], cities: [] }),
308
+ provinces: [],
309
+ cities: [],
310
+ provincesState: 'pending',
311
+ citiesState: 'idle',
312
+ })
313
+ set('/checkoutLocationRequest', { kind: 'shipping', level: 'provinces' })
314
+ emit('loadCheckoutLocations')
315
+ }
316
+ if (field === 'province') {
317
+ set('/checkoutShippingLocations', {
318
+ ...(parsed.shippingLocations ?? { countries: [], provinces: [], cities: [] }),
319
+ cities: [],
320
+ citiesState: 'pending',
321
+ })
322
+ set('/checkoutLocationRequest', { kind: 'shipping', level: 'cities' })
323
+ emit('loadCheckoutLocations')
324
+ }
325
+ }
326
+
129
327
  return (
130
328
  <CheckoutBlock
131
329
  presentation={parsed.presentation ?? 'stepper'}
132
330
  showReviewStep={parsed.showReviewStep}
331
+ requireContactPhone={parsed.requireContactPhone ?? false}
332
+ requireShippingPhone={parsed.requireShippingPhone ?? false}
133
333
  labels={{
134
334
  ...parsed.labels,
135
335
  ...(parsed.title ? { title: parsed.title } : {}),
@@ -137,30 +337,139 @@ export const registry: ViewRegistry = {
137
337
  ...(cartError ? { totalsErrorLabel: cartError } : {}),
138
338
  submitErrorActionLabel: unresolved ? 'Reconciliar' : 'Reintentar',
139
339
  }}
140
- orderSummary={parsed.orderSummary}
141
- totalsState={state.cartPending ? 'pending' : cartError ? 'error' : 'idle'}
142
- onRetryTotals={() => emit('syncCheckoutAddress')}
143
- countries={parsed.countries}
144
- shippingOptions={parsed.shippingOptions}
145
- selectedShippingOptionId={parsed.selectedShippingOptionId ?? undefined}
146
- onSelectShippingOption={(id) => {
147
- set('/checkoutSelectedShippingOptionId', id)
340
+ contact={parsed.contact}
341
+ onContactChange={(field, value) => {
342
+ set(`/checkoutContact/${field}`, value)
343
+ set(`/checkout/${field}`, value)
344
+ if (field === 'phone') {
345
+ set('/checkoutFieldErrors', clearPhoneFieldError(state.checkoutFieldErrors, 'contact'))
346
+ }
347
+ }}
348
+ shippingAddress={parsed.shippingAddress}
349
+ onShippingAddressChange={updateShipping}
350
+ billingAddress={parsed.billingAddress}
351
+ sameAsShipping={parsed.sameAsShipping}
352
+ onSameAsShippingChange={(same) => set('/checkoutSameAsShipping', same)}
353
+ validateStep={(step) => {
354
+ if (step === 'contact') {
355
+ const errors = validateCheckoutContactPhone(
356
+ parsed.contact,
357
+ parsed.requireContactPhone ?? false,
358
+ )
359
+ set('/checkoutFieldErrors', { contact: errors })
360
+ return Object.keys(errors).length === 0
361
+ }
362
+ if (step !== 'shipping') return true
363
+ const errors = validateCheckoutShippingAddress(
364
+ parsed.shippingAddress,
365
+ parsed.requireShippingPhone ?? false,
366
+ )
367
+ set('/checkoutFieldErrors', { shippingAddress: errors })
368
+ if (Object.keys(errors).length > 0) return false
369
+ // A failed grouped quote, or a provider that cannot serve grouped
370
+ // delivery at all, is reported explicitly and must not be bypassed by
371
+ // submitting as if the cart had no delivery (design D7).
372
+ const shippingState = state.checkoutShippingState
373
+ if (shippingState === 'error' || shippingState === 'unavailable') return false
374
+ // Every returned backend group needs a real option and one selected
375
+ // option. An EMPTY group list is not a shipping cart, so it stays
376
+ // allowed; the host never invents a group to fill the gap.
377
+ const groups = parsed.shippingGroups ?? []
378
+ return groups.every(
379
+ (group) => group.options.length > 0 && Boolean(group.selectedOptionId),
380
+ )
381
+ }}
382
+ onStepChange={(step) => {
383
+ if (step === 'payment') emit('syncCheckoutAddress')
384
+ }}
385
+ onBillingAddressChange={(field, value) =>
386
+ set(`/checkoutBillingAddress/${field}`, value)
387
+ }
388
+ customer={parsed.customer}
389
+ savedAddresses={parsed.savedAddresses}
390
+ onSelectSavedAddress={(id) => {
391
+ const saved = parsed.savedAddresses?.find((address) => address.id === id)
392
+ if (!saved) return
393
+ set('/checkoutShippingAddress', saved.address)
394
+ setFlatAddress(saved.address)
395
+ emit('syncCheckoutAddress')
396
+ }}
397
+ onCreateSavedAddress={
398
+ managementEnabled ? () => emit('createSavedAddress') : undefined
399
+ }
400
+ onUpdateSavedAddress={
401
+ managementEnabled
402
+ ? (id) => {
403
+ set('/checkoutSavedAddressTargetId', id)
404
+ emit('updateSavedAddress')
405
+ }
406
+ : undefined
407
+ }
408
+ onDeleteSavedAddress={
409
+ managementEnabled
410
+ ? (id) => {
411
+ set('/checkoutSavedAddressTargetId', id)
412
+ emit('deleteSavedAddress')
413
+ }
414
+ : undefined
415
+ }
416
+ onStartNewAddress={managementEnabled ? () => emit('startNewAddress') : undefined}
417
+ onCancelNewAddress={managementEnabled ? () => emit('cancelNewAddress') : undefined}
418
+ savedAddressState={parsed.savedAddressState}
419
+ shippingLocations={parsed.shippingLocations}
420
+ billingLocations={parsed.billingLocations}
421
+ onRetryLocations={(kind, level) => {
422
+ set('/checkoutLocationRequest', { kind, level })
423
+ emit('loadCheckoutLocations')
424
+ }}
425
+ shippingGroups={parsed.shippingGroups}
426
+ shippingState={parsed.shippingState}
427
+ onRetryShipping={() => emit('syncCheckoutAddress')}
428
+ onSelectShippingOption={(groupId, optionId) => {
429
+ const groups = parsed.shippingGroups ?? []
430
+ set(
431
+ '/checkoutShippingGroups',
432
+ groups.map((group) =>
433
+ group.id === groupId ? { ...group, selectedOptionId: optionId } : group,
434
+ ),
435
+ )
436
+ set('/checkoutSelectedShippingOptionId', optionId)
148
437
  emit('selectShippingMethod')
149
438
  }}
150
439
  paymentMethods={parsed.paymentMethods}
151
- values={parsed.values}
440
+ paymentState={parsed.paymentState}
441
+ paymentMethod={parsed.paymentMethod}
442
+ onSelectPaymentMethod={(id) => {
443
+ set('/checkout/paymentMethod', id)
444
+ set('/checkoutSelectedPaymentMethod', id)
445
+ }}
446
+ adjustmentPayments={parsed.adjustmentPayments}
447
+ orderSummary={parsed.orderSummary}
448
+ totalsState={state.cartPending ? 'pending' : cartError ? 'error' : 'idle'}
449
+ onRetryTotals={() => emit('syncCheckoutAddress')}
450
+ promoCode={(state.checkout as Record<string, unknown> | undefined)?.promoCode as string | undefined}
451
+ onPromoCodeChange={(value) => set('/checkout/promoCode', value)}
152
452
  fieldErrors={parsed.fieldErrors}
153
453
  fieldDescriptions={parsed.fieldDescriptions}
154
- onChange={(field, value) => {
155
- set(`/checkout/${field}`, value)
156
- if (ADDRESS_FIELDS.has(field)) emit('syncCheckoutAddress')
454
+ availability={parsed.availability}
455
+ interruption={parsed.interruption}
456
+ onInterruptionAction={() => set('/checkoutInterruption', null)}
457
+ onSubmit={(snapshot) => {
458
+ set('/checkoutSubmission', snapshot)
459
+ emit('placeOrder')
157
460
  }}
158
- onSubmit={() => emit('placeOrder')}
159
461
  submitting={Boolean(state.checkoutPending)}
160
462
  submitError={checkoutError}
161
- // An ambiguous completion offers RECONCILE only; a definite failure
162
- // (cart-with-error or pre-completion error) offers a controlled retry.
163
- onRetrySubmit={unresolved ? () => emit('reconcileOrder') : () => emit('placeOrder')}
463
+ // An ambiguous completion offers RECONCILE only; a delivery failure
464
+ // refreshes the quote; a definite order failure (cart-with-error or
465
+ // pre-completion error) offers a controlled retry.
466
+ onRetrySubmit={
467
+ unresolved
468
+ ? () => emit('reconcileOrder')
469
+ : shippingFailed
470
+ ? () => emit('syncCheckoutAddress')
471
+ : () => emit('placeOrder')
472
+ }
164
473
  />
165
474
  )
166
475
  },
@@ -177,43 +486,63 @@ export const registry: ViewRegistry = {
177
486
  ),
178
487
  CheckoutConfirmation: ({ props, emit }) => {
179
488
  const parsed = checkoutConfirmationPropsSchema.parse(props)
489
+ // The shell `main` paints no padding, so the confirmation gets the same
490
+ // host-provided page canvas as the checkout form and empty state.
491
+ const canvasClassName = 'mx-auto w-full max-w-7xl px-4 py-10 sm:px-6 lg:px-8'
492
+ // The designer confirmation is the production screen. The canonical block
493
+ // remains only for receipts created before the confirmation contract.
494
+ if (parsed.receipt.confirmation) {
495
+ return (
496
+ <div className={canvasClassName}>
497
+ <CheckoutConfirmationView
498
+ confirmation={parsed.receipt.confirmation}
499
+ labels={parsed.labels ?? {}}
500
+ locale={parsed.receipt.confirmation.locale}
501
+ currencyCode={parsed.receipt.confirmation.currencyCode}
502
+ onContinueShopping={() => emit('continueShopping')}
503
+ />
504
+ </div>
505
+ )
506
+ }
180
507
  // Forward every neutral label from user-owned content to the block, so the
181
508
  // curated flow never falls back to the block's non-neutral defaults.
182
509
  return (
183
- <CheckoutConfirmationBlock
184
- order={parsed.receipt.order}
185
- orderLines={parsed.receipt.lines}
186
- fulfilmentDetails={parsed.fulfilmentDetails}
187
- titleLabel={parsed.titleLabel}
188
- orderPlacedLabel={parsed.orderPlacedLabel}
189
- orderPlacedNoEmailLabel={parsed.orderPlacedNoEmailLabel}
190
- itemsLabel={parsed.itemsLabel}
191
- quantityLabel={parsed.quantityLabel}
192
- subtotalLabel={parsed.subtotalLabel}
193
- discountLabel={parsed.discountLabel}
194
- shippingLabel={parsed.shippingLabel}
195
- taxLabel={parsed.taxLabel}
196
- totalLabel={parsed.totalLabel}
197
- freeLabel={parsed.freeLabel}
198
- amountUnavailableLabel={parsed.amountUnavailableLabel}
199
- shippingAddressLabel={parsed.shippingAddressLabel}
200
- billingAddressLabel={parsed.billingAddressLabel}
201
- continueShoppingLabel={parsed.continueShoppingLabel}
202
- contactSupportLabel={parsed.contactSupportLabel}
203
- supportLabel={parsed.supportLabel}
204
- progressLabel={parsed.progressLabel}
205
- estimatedDeliveryLabel={parsed.estimatedDeliveryLabel}
206
- currentStageLabel={parsed.currentStageLabel}
207
- inProgressLabel={parsed.inProgressLabel}
208
- expectedByLabel={parsed.expectedByLabel}
209
- completedLabel={parsed.completedLabel}
210
- statusLabel={parsed.statusLabel}
211
- locationLabel={parsed.locationLabel}
212
- trackOrderLabel={parsed.trackOrderLabel}
213
- continueShoppingHref={parsed.continueShoppingHref ?? '#'}
214
- supportHref={parsed.supportHref}
215
- onContinueShopping={() => emit('continueShopping')}
216
- />
510
+ <div className={canvasClassName}>
511
+ <CheckoutConfirmationBlock
512
+ order={parsed.receipt.order}
513
+ orderLines={parsed.receipt.lines}
514
+ fulfilmentDetails={parsed.fulfilmentDetails}
515
+ titleLabel={parsed.titleLabel}
516
+ orderPlacedLabel={parsed.orderPlacedLabel}
517
+ orderPlacedNoEmailLabel={parsed.orderPlacedNoEmailLabel}
518
+ itemsLabel={parsed.itemsLabel}
519
+ quantityLabel={parsed.quantityLabel}
520
+ subtotalLabel={parsed.subtotalLabel}
521
+ discountLabel={parsed.discountLabel}
522
+ shippingLabel={parsed.shippingLabel}
523
+ taxLabel={parsed.taxLabel}
524
+ totalLabel={parsed.totalLabel}
525
+ freeLabel={parsed.freeLabel}
526
+ amountUnavailableLabel={parsed.amountUnavailableLabel}
527
+ shippingAddressLabel={parsed.shippingAddressLabel}
528
+ billingAddressLabel={parsed.billingAddressLabel}
529
+ continueShoppingLabel={parsed.continueShoppingLabel}
530
+ contactSupportLabel={parsed.contactSupportLabel}
531
+ supportLabel={parsed.supportLabel}
532
+ progressLabel={parsed.progressLabel}
533
+ estimatedDeliveryLabel={parsed.estimatedDeliveryLabel}
534
+ currentStageLabel={parsed.currentStageLabel}
535
+ inProgressLabel={parsed.inProgressLabel}
536
+ expectedByLabel={parsed.expectedByLabel}
537
+ completedLabel={parsed.completedLabel}
538
+ statusLabel={parsed.statusLabel}
539
+ locationLabel={parsed.locationLabel}
540
+ trackOrderLabel={parsed.trackOrderLabel}
541
+ continueShoppingHref={parsed.continueShoppingHref ?? '#'}
542
+ supportHref={parsed.supportHref}
543
+ onContinueShopping={() => emit('continueShopping')}
544
+ />
545
+ </div>
217
546
  )
218
547
  },
219
548
  }