@thorprovider/storefront 0.4.0-mvp.2 → 0.5.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 (129) hide show
  1. package/README.md +13 -13
  2. package/assets/templates/app/app/[[...slug]]/page.tsx +32 -1
  3. package/assets/templates/app/app/[[...slug]]/renderer.tsx +43 -12
  4. package/assets/templates/app/lib/__STOREFRONT__/account-boundary.client.tsx +76 -0
  5. package/assets/templates/app/lib/__STOREFRONT__/account-lifecycle.client.tsx +461 -0
  6. package/assets/templates/app/lib/__STOREFRONT__/account-mutation.client.ts +46 -0
  7. package/assets/templates/app/lib/__STOREFRONT__/account-private.core.ts +103 -0
  8. package/assets/templates/app/lib/__STOREFRONT__/account-reconcile.client.ts +465 -0
  9. package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +177 -0
  10. package/assets/templates/app/lib/__STOREFRONT__/account-session.ts +44 -0
  11. package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +65 -0
  12. package/assets/templates/app/lib/__STOREFRONT__/actions.ts +76 -27
  13. package/assets/templates/app/lib/__STOREFRONT__/catalog.ts +4 -4
  14. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +0 -10
  15. package/assets/templates/app/lib/__STOREFRONT__/composition.ts +1 -1
  16. package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +3 -3
  17. package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +17 -18
  18. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +209 -0
  19. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.ts +247 -0
  20. package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +60 -29
  21. package/assets/templates/app/lib/__STOREFRONT__/schema.ts +83 -15
  22. package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +3 -5
  23. package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +1 -1
  24. package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +25 -0
  25. package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +7 -10
  26. package/assets/templates/app/lib/__STOREFRONT__/views/sections/cta.client.tsx +1 -1
  27. package/assets/templates/app/lib/__STOREFRONT__/views/sections/faq.client.tsx +1 -1
  28. package/assets/templates/app/lib/__STOREFRONT__/views/sections/logoCloud.tsx +1 -1
  29. package/assets/templates/app/lib/__STOREFRONT__/views/sections/pricing.tsx +1 -1
  30. package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.client.tsx +16 -16
  31. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +1 -1
  32. package/assets/templates/app/lib/__STOREFRONT__/views/sections/statistics.tsx +1 -1
  33. package/assets/templates/app/lib/__STOREFRONT__/views/sections/testimonials.tsx +26 -19
  34. package/assets/templates/features/checkout/state.ts +0 -5
  35. package/assets/templates/features/customer-auth/handlers.ts +19 -23
  36. package/assets/templates/features/customer-auth/state.ts +21 -0
  37. package/assets/templates/views/account/index.tsx +19 -7
  38. package/assets/templates/views/account/registry.tsx +263 -155
  39. package/assets/templates/views/account/schema.ts +1 -1
  40. package/assets/templates/views/cart/data.ts +7 -7
  41. package/assets/templates/views/cart/registry.tsx +4 -3
  42. package/assets/templates/views/category/assembly/assembly.json +2 -2
  43. package/assets/templates/views/category/assembly/index.skeleton.tsx +11 -7
  44. package/assets/templates/views/category/assembly/registry.skeleton.tsx +9 -9
  45. package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +1 -1
  46. package/assets/templates/views/category/assembly/slots/filter/CategoryListing/catalog.part +5 -0
  47. package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/element.part +5 -3
  48. package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/registry.part +9 -5
  49. package/assets/templates/views/category/content.ts +2 -1
  50. package/assets/templates/views/category/index.tsx +19 -13
  51. package/assets/templates/views/category/props.ts +1 -1
  52. package/assets/templates/views/category/registry.tsx +19 -15
  53. package/assets/templates/views/category/schema.ts +48 -21
  54. package/assets/templates/views/checkout/content.ts +60 -0
  55. package/assets/templates/views/checkout/props.ts +4 -5
  56. package/assets/templates/views/checkout/registry.tsx +12 -10
  57. package/assets/templates/views/checkout/schema.ts +10 -16
  58. package/assets/templates/views/home/assembly/assembly.json +4 -4
  59. package/assets/templates/views/home/assembly/index.skeleton.tsx +2 -3
  60. package/assets/templates/views/home/assembly/registry.skeleton.tsx +4 -1
  61. package/assets/templates/views/home/assembly/slots/benefits/cards/binding.json +5 -0
  62. package/assets/templates/views/home/assembly/slots/benefits/cards/registry.part +17 -0
  63. package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
  64. package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → split}/registry.part +6 -2
  65. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/binding.json +5 -0
  66. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/catalog.part +8 -0
  67. package/assets/templates/views/home/assembly/slots/categories/{ProductCategory2 → CategoryGrid}/element.part +1 -1
  68. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/registry.part +31 -0
  69. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/binding.json +5 -0
  70. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/catalog.part +4 -0
  71. package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/registry.part +3 -1
  72. package/assets/templates/views/home/content.ts +22 -0
  73. package/assets/templates/views/home/index.tsx +11 -8
  74. package/assets/templates/views/home/props.ts +1 -0
  75. package/assets/templates/views/home/registry.tsx +39 -15
  76. package/assets/templates/views/home/schema.ts +141 -24
  77. package/assets/templates/views/product/data.ts +1 -1
  78. package/assets/templates/views/product/registry.tsx +10 -6
  79. package/assets/templates/views/product/schema.ts +36 -1
  80. package/examples/merchandising/category-led.json +1 -1
  81. package/examples/merchandising/collection-led.json +1 -1
  82. package/package.json +4 -5
  83. package/recipes/archetypes.json +39 -43
  84. package/recipes/catalog.json +212 -202
  85. package/recipes/catalog.mjs +10 -0
  86. package/recipes/catalog.schema.json +4 -0
  87. package/recipes/features.json +5 -5
  88. package/recipes/recipes.json +137 -43
  89. package/recipes/sections.json +4 -4
  90. package/recipes/validate.mjs +21 -4
  91. package/scripts/candidate.mjs +2 -2
  92. package/scripts/composers.mjs +2 -2
  93. package/scripts/file-classes.mjs +10 -0
  94. package/scripts/logical-controls.mjs +4 -4
  95. package/scripts/operation-registry.mjs +1 -1
  96. package/scripts/ownership-conflict.mjs +5 -2
  97. package/scripts/view-assembly.mjs +12 -4
  98. package/scripts/view-selection.mjs +1 -1
  99. package/skills/sf-view-gen/assets/recipes/archetypes.json +39 -43
  100. package/skills/sf-view-gen/assets/recipes/catalog.json +212 -202
  101. package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
  102. package/skills/sf-view-gen/assets/recipes/features.json +5 -5
  103. package/skills/sf-view-gen/assets/recipes/recipes.json +137 -43
  104. package/skills/sf-view-gen/assets/recipes/sections.json +4 -4
  105. package/skills/sf-view-gen/assets/templates/views/sections/cta.client.tsx +1 -1
  106. package/skills/sf-view-gen/assets/templates/views/sections/faq.client.tsx +1 -1
  107. package/skills/sf-view-gen/assets/templates/views/sections/logoCloud.client.tsx +1 -1
  108. package/skills/sf-view-gen/assets/templates/views/sections/pricing.client.tsx +1 -1
  109. package/skills/sf-view-gen/assets/templates/views/sections/products.client.tsx +16 -16
  110. package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +1 -1
  111. package/skills/sf-view-gen/assets/templates/views/sections/schema.testimonials.ts +21 -11
  112. package/skills/sf-view-gen/assets/templates/views/sections/statistics.client.tsx +1 -1
  113. package/skills/sf-view-gen/assets/templates/views/sections/testimonials.client.tsx +2 -8
  114. package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
  115. package/skills/sf-view-gen/scripts/validate.mjs +21 -4
  116. package/assets/templates/views/category/assembly/slots/filter/CategoryFilter2/catalog.part +0 -5
  117. package/assets/templates/views/home/assembly/slots/benefits/Feature1/binding.json +0 -5
  118. package/assets/templates/views/home/assembly/slots/benefits/Feature2/binding.json +0 -5
  119. package/assets/templates/views/home/assembly/slots/benefits/Feature2/registry.part +0 -10
  120. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/binding.json +0 -5
  121. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/catalog.part +0 -4
  122. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/registry.part +0 -16
  123. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/binding.json +0 -5
  124. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/catalog.part +0 -4
  125. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/catalog.part +0 -0
  126. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/element.part +0 -0
  127. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/catalog.part +0 -0
  128. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/element.part +0 -0
  129. /package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/element.part +0 -0
@@ -11,22 +11,18 @@
11
11
  // written to the json-render state store, so no password reaches client state,
12
12
  // HTML, or logs. Only the non-secret result (customer/error) is stored.
13
13
 
14
- import { useEffect, useRef } from 'react'
15
- import {
16
- Button,
17
- LoginPage1 as LoginBlock,
18
- OrderHistory2,
19
- SignUpPage1 as SignUpBlock,
20
- } from '@thorprovider/blocks'
14
+ import { useCallback, useEffect, useRef } from 'react'
15
+ import type { ReactNode } from 'react'
16
+ import { Button } from '@thorprovider/blocks/ui/button'
17
+ import { LoginPage } from '@thorprovider/blocks'
18
+ import OrderHistory2 from '@thorprovider/blocks/blocks/e-commerce/order-history/order-history-2'
19
+ import SignUpBlock from '@thorprovider/blocks/blocks/application/signup-forms/signup-page-1'
21
20
  import { useStateStore } from '@json-render/react'
22
21
  import type { Customer } from '@thorprovider/types'
23
- import {
24
- loadAccountAction,
25
- loadOrdersPageAction,
26
- loginAction,
27
- logoutAction,
28
- registerAction,
29
- } from '../../actions'
22
+ import { loadOrdersPageAction } from '../../actions'
23
+ import { ACCOUNT_ORDERS_DEFAULT_PAGE_SIZE, accountIdentityKey } from '../../account-private.core'
24
+ import { AccountBoundary } from '../../account-boundary.client'
25
+ import { useAccountLifecycle } from '../../account-lifecycle.client'
30
26
  import type { AccountOrderView } from '../../state.core'
31
27
  import type { ViewRegistry } from '../types'
32
28
  import {
@@ -35,39 +31,8 @@ import {
35
31
  accountRegisterPropsSchema,
36
32
  } from './schema'
37
33
 
38
- // The structured result the auth Server Actions return (see ../../actions).
39
- type AuthResult = { ok: true; customer: Customer | null } | { ok: false; error: string }
40
- type SetState = (path: string, value: unknown) => void
41
-
42
34
  /** Bounded page size for the account order-history window. */
43
- const ORDERS_PAGE_SIZE = 10
44
-
45
- // Apply a settled auth result truthfully: a failure sets an error and NEVER a
46
- // logged-in state; a success stores the customer (or null) and nothing else.
47
- function applyAuthResult(set: SetState, result: AuthResult): void {
48
- set('/accountPending', false)
49
- if (result.ok) {
50
- set('/accountCustomer', result.customer)
51
- set('/accountAuthenticated', result.customer !== null)
52
- set('/accountError', null)
53
- set('/accountMode', 'login')
54
- return
55
- }
56
- set('/accountError', result.error)
57
- }
58
-
59
- // A rejected Server Action (network/RPC) must clear pending and surface a
60
- // message; never swallow it. Only a non-secret context line is logged.
61
- function authFailure(set: SetState, scope: string) {
62
- return (error: unknown) => {
63
- console.error(
64
- `[storefront/account] ${scope} failed`,
65
- error instanceof Error ? error.message : error,
66
- )
67
- set('/accountPending', false)
68
- set('/accountError', 'No se pudo completar la operación. Inténtalo de nuevo.')
69
- }
70
- }
35
+ const ORDERS_PAGE_SIZE = ACCOUNT_ORDERS_DEFAULT_PAGE_SIZE
71
36
 
72
37
  // Non-secret status surface for the block pages, which expose no error/pending
73
38
  // prop of their own. Renders nothing when there is no pending work or error.
@@ -84,6 +49,46 @@ function AuthNotice({ pending, error }: { pending: boolean; error: string | null
84
49
  )
85
50
  }
86
51
 
52
+ // The page side of the auth contract. The blocks render only the form: they no
53
+ // longer paint a viewport-height surface, declare a page landmark, or centre
54
+ // themselves, because a generated storefront mounts them inside the default
55
+ // chrome (notice + banner + navbar + footer) and the page — not the block — owns
56
+ // the viewport. This wrapper is the extracted shell, kept so the shopper-visible
57
+ // result of every auth surface is unchanged. It lives in a derived template
58
+ // (CLI-owned) and stays theme-driven: the backdrop uses the same semantic
59
+ // tokens, so dark mode and any preset resolve here too.
60
+ function AuthCanvas({ stack = false, children }: { stack?: boolean; children: ReactNode }) {
61
+ return (
62
+ <section
63
+ className={`from-background to-muted/50 relative isolate flex min-h-dvh w-full items-center justify-center overflow-hidden bg-linear-to-br ${stack ? 'flex-col' : ''}`}
64
+ >
65
+ <div
66
+ className={`relative z-10 container mx-auto flex min-h-dvh items-center justify-center px-4 py-12 ${stack ? 'flex-col' : ''}`}
67
+ >
68
+ {children}
69
+ </div>
70
+ </section>
71
+ )
72
+ }
73
+
74
+ // Neutral pending surface shown while a cross-tab/foreground reconciliation is
75
+ // in flight (task 4.2). It replaces the previously held identity/orders so no
76
+ // stale private data is presented as current during the server round-trip; it
77
+ // is NOT a signed-out or unavailable state, and the held data is never
78
+ // destroyed (a same-identity re-resolution re-presents it without a refetch).
79
+ function ReconcilingStatus() {
80
+ return (
81
+ <p
82
+ role="status"
83
+ aria-live="polite"
84
+ data-account-reconciling="1"
85
+ className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
86
+ >
87
+ Actualizando tu cuenta…
88
+ </p>
89
+ )
90
+ }
91
+
87
92
  // The OrderHistory2 block's order shape (see @thorprovider/blocks). Kept local
88
93
  // so the registry maps the account order rows to the block contract without a
89
94
  // shared dependency on block internals.
@@ -126,8 +131,10 @@ function toBlockOrder(order: AccountOrderView): BlockOrder {
126
131
  }
127
132
 
128
133
  // Inline order detail assembled from the already-fetched list row (no second
129
- // backend request). Only fields the backend supplied are shown.
130
- function OrderDetail({ order }: { order: AccountOrderView }) {
134
+ // backend request). Only fields the backend supplied are shown. `onClose` clears
135
+ // the selection so the detail is dismissible (a real open/close cycle, no
136
+ // navigation and no second destination).
137
+ function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: () => void }) {
131
138
  const totals = (
132
139
  [
133
140
  { label: 'Subtotal', value: order.subtotal },
@@ -139,10 +146,17 @@ function OrderDetail({ order }: { order: AccountOrderView }) {
139
146
  return (
140
147
  <div className="mx-auto w-full max-w-7xl px-4 pb-12 sm:px-6 lg:px-8">
141
148
  <div className="rounded-lg border p-6">
142
- <h3 className="text-lg font-semibold">Pedido {order.number}</h3>
143
- <p className="text-muted-foreground mt-1 text-sm">
144
- {order.date} · {order.status}
145
- </p>
149
+ <div className="flex items-start justify-between gap-4">
150
+ <div>
151
+ <h3 className="text-lg font-semibold">Pedido {order.number}</h3>
152
+ <p className="text-muted-foreground mt-1 text-sm">
153
+ {order.date} · {order.status}
154
+ </p>
155
+ </div>
156
+ <Button type="button" variant="outline" size="sm" onClick={onClose}>
157
+ Cerrar
158
+ </Button>
159
+ </div>
146
160
  {order.address ? (
147
161
  <p className="text-muted-foreground mt-2 text-sm">{order.address}</p>
148
162
  ) : null}
@@ -175,107 +189,99 @@ function OrderDetail({ order }: { order: AccountOrderView }) {
175
189
 
176
190
  export const registry: ViewRegistry = {
177
191
  /**
178
- * Headless bootstrap rendered on the account route. It resolves the current
179
- * customer from the cookie-authorized Server Action once, so a reload keeps
180
- * the signed-in state without re-entering credentials. It never reads a token.
192
+ * Passive account boundary. It renders only the retryable "unavailable"
193
+ * status (via the shared lifecycle's `retryAccountSession` action) and NEVER
194
+ * fetches or owns identity on mount: the shared lifecycle/SSR seed already
195
+ * supplies the account state on every route, so `/account` introduces no
196
+ * competing identity bootstrap or mount race.
181
197
  */
182
- AccountBoot: () => {
183
- const { set } = useStateStore()
184
- const booted = useRef(false)
185
- useEffect(() => {
186
- if (booted.current) return
187
- booted.current = true
188
- void loadAccountAction()
189
- .then((result) => {
190
- if (!result.ok) {
191
- set('/accountCustomer', null)
192
- set('/accountAuthenticated', false)
193
- set('/accountError', result.error)
194
- return
195
- }
196
- set('/accountCustomer', result.customer)
197
- set('/accountAuthenticated', result.customer !== null)
198
- set('/accountError', null)
199
- })
200
- .catch((error) => {
201
- console.error(
202
- '[storefront/account] loadAccount failed',
203
- error instanceof Error ? error.message : error,
204
- )
205
- set('/accountCustomer', null)
206
- set('/accountAuthenticated', false)
207
- set('/accountError', 'No se pudo cargar la cuenta. Inténtalo de nuevo.')
208
- })
209
- }, [])
210
- return null
211
- },
198
+ AccountBoot: ({ emit }) => <AccountBoundary emit={emit} />,
212
199
  AccountLogin: ({ props, emit }) => {
213
- const { state, set } = useStateStore()
200
+ const { state } = useStateStore()
201
+ const lifecycle = useAccountLifecycle()
214
202
  const parsed = accountLoginPropsSchema.parse(props)
215
203
  const error = typeof state.accountError === 'string' ? state.accountError : null
216
204
  const pending = Boolean(state.accountPending)
217
205
  return (
218
206
  <>
219
207
  <AuthNotice pending={pending} error={error} />
220
- <LoginBlock
221
- logoText={parsed.logoText}
222
- welcomeTitleLabel={parsed.welcomeTitleLabel}
223
- welcomeDescriptionLabel={parsed.welcomeDescriptionLabel}
224
- emailLabel={parsed.emailLabel}
225
- passwordLabel={parsed.passwordLabel}
226
- signInLabel={parsed.signInLabel}
227
- createAccountLabel={parsed.createAccountLabel}
228
- // The credentials stay in the block's local state and go straight to
229
- // the Server Action; they are never written to the store.
230
- onSubmit={(data) => {
231
- set('/accountPending', true)
232
- set('/accountError', null)
233
- void loginAction({ email: data.email, password: data.password })
234
- .then((result) => applyAuthResult(set, result))
235
- .catch(authFailure(set, 'login'))
236
- }}
237
- onCreateAccount={() => emit('showRegister')}
238
- />
208
+ {/* The block exposes no pending/disabled prop, so the registry disables
209
+ the whole form natively while a mutation is pending: a disabled
210
+ fieldset freezes the submit control and the inputs without clearing
211
+ them, and `display: contents` leaves the layout untouched. The
212
+ shared lifecycle also drops a same-tick duplicate before React
213
+ re-renders, so no duplicate request is issued in the interim. */}
214
+ <AuthCanvas>
215
+ <fieldset disabled={pending} aria-busy={pending} className="contents">
216
+ <LoginPage
217
+ presentation="card"
218
+ logoText={parsed.logoText}
219
+ welcomeTitleLabel={parsed.welcomeTitleLabel}
220
+ welcomeDescriptionLabel={parsed.welcomeDescriptionLabel}
221
+ emailLabel={parsed.emailLabel}
222
+ passwordLabel={parsed.passwordLabel}
223
+ signInLabel={parsed.signInLabel}
224
+ createAccountLabel={parsed.createAccountLabel}
225
+ rememberMeLabel="Recuérdame"
226
+ // The credentials stay in the block's local state and go straight to
227
+ // the shared lifecycle (which calls the Server Action); they are never
228
+ // written to the store. The lifecycle owns pending/error, the
229
+ // generation guard, duplicate prevention, and the server refresh, so
230
+ // the mounted form is never remounted and its input survives a failure.
231
+ onSubmit={(data) => {
232
+ void lifecycle.login({ email: data.email, password: data.password })
233
+ }}
234
+ onCreateAccount={() => emit('showRegister')}
235
+ />
236
+ </fieldset>
237
+ </AuthCanvas>
239
238
  </>
240
239
  )
241
240
  },
242
241
  AccountRegister: ({ props, emit }) => {
243
- const { state, set } = useStateStore()
242
+ const { state } = useStateStore()
243
+ const lifecycle = useAccountLifecycle()
244
244
  const parsed = accountRegisterPropsSchema.parse(props)
245
245
  const error = typeof state.accountError === 'string' ? state.accountError : null
246
246
  const pending = Boolean(state.accountPending)
247
247
  return (
248
248
  <>
249
249
  <AuthNotice pending={pending} error={error} />
250
- <SignUpBlock
251
- logoText={parsed.logoText}
252
- createAccountTitleLabel={parsed.createAccountTitleLabel}
253
- createAccountDescriptionLabel={parsed.createAccountDescriptionLabel}
254
- fullNameLabel={parsed.fullNameLabel}
255
- emailLabel={parsed.emailLabel}
256
- passwordLabel={parsed.passwordLabel}
257
- createAccountLabel={parsed.createAccountLabel}
258
- signInLabel={parsed.signInLabel}
259
- onSubmit={(data) => {
260
- const parts = data.fullName.trim().split(/\s+/).filter(Boolean)
261
- set('/accountPending', true)
262
- set('/accountError', null)
263
- void registerAction({
264
- email: data.email,
265
- password: data.password,
266
- first_name: parts[0] ?? '',
267
- last_name: parts.slice(1).join(' '),
268
- })
269
- .then((result) => applyAuthResult(set, result))
270
- .catch(authFailure(set, 'register'))
271
- }}
272
- onSignIn={() => emit('showLogin')}
273
- />
250
+ {/* Same native pending-disable as the login form (the block exposes no
251
+ pending prop); input values persist across a failed mutation. */}
252
+ <AuthCanvas stack>
253
+ <fieldset disabled={pending} aria-busy={pending} className="contents">
254
+ <SignUpBlock
255
+ logoText={parsed.logoText}
256
+ createAccountTitleLabel={parsed.createAccountTitleLabel}
257
+ createAccountDescriptionLabel={parsed.createAccountDescriptionLabel}
258
+ fullNameLabel={parsed.fullNameLabel}
259
+ emailLabel={parsed.emailLabel}
260
+ passwordLabel={parsed.passwordLabel}
261
+ createAccountLabel={parsed.createAccountLabel}
262
+ signInLabel={parsed.signInLabel}
263
+ onSubmit={(data) => {
264
+ const parts = data.fullName.trim().split(/\s+/).filter(Boolean)
265
+ void lifecycle.register({
266
+ email: data.email,
267
+ password: data.password,
268
+ firstName: parts[0] ?? '',
269
+ lastName: parts.slice(1).join(' '),
270
+ })
271
+ }}
272
+ onSignIn={() => emit('showLogin')}
273
+ />
274
+ </fieldset>
275
+ </AuthCanvas>
274
276
  </>
275
277
  )
276
278
  },
277
279
  AccountPanel: ({ emit }) => {
278
280
  const { state } = useStateStore()
281
+ const { reconciling } = useAccountLifecycle()
282
+ // A reconciliation in flight hides the held identity rather than presenting
283
+ // it as current (task 4.2); the panel stays mounted so nothing is destroyed.
284
+ if (reconciling) return <ReconcilingStatus />
279
285
  const customer = (state.accountCustomer ?? null) as Customer | null
280
286
  const error = typeof state.accountError === 'string' ? state.accountError : null
281
287
  const pending = Boolean(state.accountPending)
@@ -300,24 +306,78 @@ export const registry: ViewRegistry = {
300
306
  )
301
307
  },
302
308
  /**
303
- * Signed-in order history. The first page loads once from the cookie-authorized
304
- * Server Action; later pages load on demand, each scoped to the authenticated
305
- * customer's channel. The backend's real `count` drives pagination, so a page
306
- * length is never presented as the total. Selection is keyed by the REAL
307
- * backend order id (via a number→id map), so an opened detail stays stable
308
- * across paging and reload. No token is read, stored, or rendered here.
309
+ * Signed-in order history, scoped to the CURRENT shopper identity. The first
310
+ * page loads from the cookie-authorized Server Action; later pages load on
311
+ * demand, each scoped to the authenticated customer's channel. Loading is keyed
312
+ * by the shared lifecycle's `identityKey` (customer id, or `anonymous`) plus a
313
+ * per-component generation:
314
+ *
315
+ * - the first-page effect reloads on an identity CHANGE (a boolean flag
316
+ * cannot detect a customer switch) and lazy-loads only on `/account`;
317
+ * - every `loadPage` captures the live key/generation at request time and
318
+ * discards its result if either changed, so a previous customer's rows,
319
+ * count, page, selection, or detail never reappear;
320
+ * - the private STORE slice is cleared by the shared lifecycle write path
321
+ * (`claimAccount`) AT the trigger, not by this view, so it is cleared even
322
+ * when the panel unmounts (logout/expiry/unavailable); this view only
323
+ * HIDES rows whose key is not the current identity until the new
324
+ * identity's page lands (a render guard, never the clear mechanism).
325
+ *
326
+ * The backend's real `count` drives pagination, so a page length is never
327
+ * presented as the total. Selection is keyed by the REAL backend order id (via
328
+ * a number→id map) and the detail is assembled from the fetched row; the
329
+ * selection id survives paging (returning to the order's page reopens it) and
330
+ * is dismissible with the inline close control. A failed page load shows an
331
+ * actionable retry that re-runs the SAME page (never a fabricated empty
332
+ * history). No token is read, stored, or rendered here.
309
333
  */
310
334
  AccountOrders: ({ props }) => {
311
- const { state, set } = useStateStore()
335
+ const { state, set, getSnapshot } = useStateStore()
312
336
  const parsed = accountOrdersPropsSchema.parse(props)
313
- const authenticated = Boolean(state.accountAuthenticated)
314
- const loadedForAuth = useRef(false)
337
+ const { identityKey, reconciling } = useAccountLifecycle()
338
+
339
+ // Bumped on every identity change so a response from a previous identity — or
340
+ // a previous visit to the same identity — is discarded even if the key later
341
+ // returns.
342
+ const generationRef = useRef(0)
343
+ // The identity key the currently DISPLAYED rows belong to; null until a load
344
+ // for the current identity succeeds. A render whose key differs hides the
345
+ // rows immediately, so a previous customer's orders never paint after the
346
+ // identity changes, before the shared clear even runs.
347
+ const loadedKeyRef = useRef<string | null>(null)
348
+ // The page of the MOST RECENT request (not the last successful one), so the
349
+ // error-state retry re-runs the exact page the shopper asked for — including
350
+ // a failed next/prev page. Local to the panel: an identity change unmounts it
351
+ // (the `/accountAuthenticated` gate), so it never leaks across shoppers.
352
+ const requestedPageRef = useRef(1)
353
+
354
+ // Read the LIVE identity key from the store so an async response can discard
355
+ // itself even if this component has since re-rendered or unmounted: the store
356
+ // outlives the component, unlike a render closure.
357
+ const currentIdentityKey = useCallback(
358
+ () =>
359
+ accountIdentityKey(
360
+ (getSnapshot().accountCustomer ?? null) as { id?: string | null } | null,
361
+ ),
362
+ [getSnapshot],
363
+ )
315
364
 
316
365
  const loadPage = (page: number) => {
366
+ // Capture the identity key + generation BEFORE the request; the response is
367
+ // discarded if either changed while it was in flight.
368
+ const capturedKey = currentIdentityKey()
369
+ const capturedGeneration = generationRef.current
370
+ requestedPageRef.current = page
317
371
  set('/accountOrdersPending', true)
318
372
  set('/accountOrdersError', null)
319
373
  void loadOrdersPageAction({ page, pageSize: ORDERS_PAGE_SIZE })
320
374
  .then((result) => {
375
+ if (
376
+ currentIdentityKey() !== capturedKey ||
377
+ generationRef.current !== capturedGeneration
378
+ ) {
379
+ return
380
+ }
321
381
  set('/accountOrdersPending', false)
322
382
  if (result.ok) {
323
383
  set('/accountOrders', result.orders)
@@ -325,11 +385,18 @@ export const registry: ViewRegistry = {
325
385
  set('/accountOrdersPage', page)
326
386
  set('/accountOrdersPageSize', result.limit)
327
387
  set('/accountOrdersError', null)
388
+ loadedKeyRef.current = capturedKey
328
389
  return
329
390
  }
330
391
  set('/accountOrdersError', result.error)
331
392
  })
332
393
  .catch((error) => {
394
+ if (
395
+ currentIdentityKey() !== capturedKey ||
396
+ generationRef.current !== capturedGeneration
397
+ ) {
398
+ return
399
+ }
333
400
  console.error(
334
401
  '[storefront/account] loadOrders failed',
335
402
  error instanceof Error ? error.message : error,
@@ -340,24 +407,33 @@ export const registry: ViewRegistry = {
340
407
  }
341
408
 
342
409
  useEffect(() => {
343
- // Load the first page when the customer becomes authenticated, and reload
344
- // after a re-login, so the history appears without a manual reload. A
345
- // guest load is never attempted; the flag resets when the session ends.
346
- if (!authenticated) {
347
- loadedForAuth.current = false
348
- return
410
+ // On a real identity CHANGE, bump the generation (discarding the previous
411
+ // identity's in-flight page) and forget the displayed key, then load page
412
+ // 1 for the new identity. The private STORE slice is cleared by the shared
413
+ // lifecycle write path (`claimAccount`) at the trigger — NOT here — so the
414
+ // reset already happened even when this panel was unmounted (logout /
415
+ // expiry / unavailable). This effect only drives the fetch; a
416
+ // same-identity re-resolution leaves `identityKey` unchanged, so it does
417
+ // not re-run and the rows/selection survive. A guest/unavailable identity
418
+ // never fetches.
419
+ if (loadedKeyRef.current !== identityKey) {
420
+ generationRef.current += 1
421
+ loadedKeyRef.current = null
349
422
  }
350
- if (loadedForAuth.current) return
351
- loadedForAuth.current = true
423
+ if (identityKey === 'anonymous') return
424
+ if (loadedKeyRef.current === identityKey) return
352
425
  loadPage(1)
353
426
  // eslint-disable-next-line react-hooks/exhaustive-deps
354
- }, [authenticated])
427
+ }, [identityKey])
355
428
 
356
429
  const pending = Boolean(state.accountOrdersPending)
357
430
  const error = typeof state.accountOrdersError === 'string' ? state.accountOrdersError : null
358
- const orders = Array.isArray(state.accountOrders)
431
+ const allOrders = Array.isArray(state.accountOrders)
359
432
  ? (state.accountOrders as AccountOrderView[])
360
433
  : []
434
+ // Only rows loaded FOR the current identity may display: a stale row set from
435
+ // a previous customer is hidden until the new identity's page lands.
436
+ const orders = loadedKeyRef.current === identityKey ? allOrders : []
361
437
  const count =
362
438
  typeof state.accountOrdersCount === 'number' ? state.accountOrdersCount : orders.length
363
439
  const page = typeof state.accountOrdersPage === 'number' ? state.accountOrdersPage : 1
@@ -372,23 +448,53 @@ export const registry: ViewRegistry = {
372
448
  // The block row carries the display number; resolve it back to the backend id.
373
449
  const backendIdByBlockId = new Map(orders.map((order) => [order.number, order.id]))
374
450
 
451
+ // A reconciliation in flight (task 4.2) hides the held rows rather than
452
+ // presenting them as current. This component stays MOUNTED (its `loadedKeyRef`
453
+ // and generation survive), so a same-identity re-resolution re-presents the
454
+ // held rows after settle WITHOUT a refetch; an identity change still clears
455
+ // through the claim write path.
456
+ if (reconciling) {
457
+ return <ReconcilingStatus />
458
+ }
375
459
  if (pending) {
376
460
  return (
377
- <p className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm">
461
+ <p
462
+ role="status"
463
+ aria-live="polite"
464
+ className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
465
+ >
378
466
  {parsed.loadingLabel ?? 'Cargando pedidos…'}
379
467
  </p>
380
468
  )
381
469
  }
382
470
  if (error) {
471
+ // A failed load is NOT an empty history: the error is announced and the
472
+ // shopper gets an actionable retry that re-runs the page that failed (a
473
+ // button, never inert text). No token, no direct HTTP — the retry calls the
474
+ // same cookie-authorized Server Action as the initial load.
383
475
  return (
384
- <p role="alert" className="text-destructive mx-auto max-w-7xl px-4 py-8 text-sm">
385
- {error}
386
- </p>
476
+ <div className="mx-auto flex w-full max-w-7xl flex-col items-start gap-3 px-4 py-8 sm:px-6 lg:px-8">
477
+ <p role="alert" className="text-destructive text-sm">
478
+ {error}
479
+ </p>
480
+ <Button
481
+ type="button"
482
+ variant="outline"
483
+ size="sm"
484
+ disabled={pending}
485
+ onClick={() => loadPage(requestedPageRef.current)}
486
+ >
487
+ Reintentar
488
+ </Button>
489
+ </div>
387
490
  )
388
491
  }
389
492
  if (orders.length === 0) {
390
493
  return (
391
- <p className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm">
494
+ <p
495
+ role="status"
496
+ className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
497
+ >
392
498
  {parsed.emptyLabel ?? 'Aún no tienes pedidos.'}
393
499
  </p>
394
500
  )
@@ -432,7 +538,9 @@ export const registry: ViewRegistry = {
432
538
  </div>
433
539
  </div>
434
540
  ) : null}
435
- {selected ? <OrderDetail order={selected} /> : null}
541
+ {selected ? (
542
+ <OrderDetail order={selected} onClose={() => set('/accountSelectedOrderId', null)} />
543
+ ) : null}
436
544
  </>
437
545
  )
438
546
  },
@@ -9,7 +9,7 @@
9
9
 
10
10
  import { z } from 'zod'
11
11
 
12
- // Mirrors the LoginPage1 optional props. Every prop is optional with a neutral
12
+ // Mirrors the canonical LoginPage optional props. Every prop is optional with a neutral
13
13
  // default in the block, so the curated view forwards only the labels it owns.
14
14
  export const accountLoginPropsSchema = z.object({
15
15
  logoText: z.string().optional(),
@@ -1,20 +1,20 @@
1
1
  // Thor Commerce view data: cart (user-owned)
2
- // Pure mapping from the shared host cart state to the ShoppingCart4 block props.
2
+ // Pure mapping from the shared host cart state to the ShoppingCart block props.
3
3
  // No React and no server imports so it can be imported from either boundary.
4
4
 
5
- import type { ShoppingCart4Item } from '@thorprovider/blocks'
5
+ import type { ShoppingCartItem } from '@thorprovider/blocks'
6
6
  import type { CartLineState } from '../../state'
7
7
 
8
8
  /**
9
- * Maps backend cart lines to the cart block's item shape. `price` stays 0 (the
10
- * legacy numeric field) because the block renders the canonical `lineTotal`
11
- * Money; an absent image is left undefined rather than serialized as "".
9
+ * Maps backend cart lines to the cart block's item shape. The block renders the
10
+ * canonical `lineTotal` Money verbatim, so only canonical Money fields are
11
+ * supplied — no legacy numeric `price` placeholder. An absent image is left
12
+ * undefined rather than serialized as "".
12
13
  */
13
- export const toCartViewItems = (cart: CartLineState[]): ShoppingCart4Item[] =>
14
+ export const toCartViewItems = (cart: CartLineState[]): ShoppingCartItem[] =>
14
15
  cart.map(line => ({
15
16
  id: line.id,
16
17
  name: line.name,
17
- price: 0,
18
18
  quantity: line.quantity,
19
19
  image: line.image,
20
20
  variant: line.variant,
@@ -1,12 +1,13 @@
1
1
  'use client'
2
2
 
3
3
  // Thor Commerce view registry: cart
4
- // Renders the standalone cart review page (page-mode ShoppingCart4) from the
4
+ // Renders the standalone cart review page (page-mode ShoppingCart) from the
5
5
  // shared host cart state. Quantity updates use the ABSOLUTE line quantity keyed
6
6
  // by backend line id; removal uses the same line id. Checkout is only offered
7
7
  // when the checkout capability is installed and the cart is ready.
8
8
 
9
- import { Button, ShoppingCart4 } from '@thorprovider/blocks'
9
+ import { Button } from '@thorprovider/blocks/ui/button'
10
+ import ShoppingCart from '@thorprovider/blocks/blocks/e-commerce/shopping-carts/shopping-cart'
10
11
  import { isAvailableMoney } from '@thorprovider/blocks/contracts'
11
12
  import { useStateStore } from '@json-render/react'
12
13
  import { checkoutAvailable } from '../../composition'
@@ -49,7 +50,7 @@ export const registry: ViewRegistry = {
49
50
  }
50
51
 
51
52
  return (
52
- <ShoppingCart4
53
+ <ShoppingCart
53
54
  presentation='page'
54
55
  items={toCartViewItems(cart)}
55
56
  promotions={[]}
@@ -2,11 +2,11 @@
2
2
  "view": "category",
3
3
  "slots": [
4
4
  { "id": "category.breadcrumb", "slot": "breadcrumb", "default": "Breadcrumb" },
5
- { "id": "category.filter", "slot": "filter", "default": "CategoryFilter2" },
5
+ { "id": "category.filter", "slot": "filter", "default": "CategoryListing" },
6
6
  {
7
7
  "id": "category.productCard",
8
8
  "slot": "productCard",
9
- "default": "ProductCard1",
9
+ "default": "ProductGrid",
10
10
  "nested": true
11
11
  }
12
12
  ],