@thorprovider/storefront 0.4.0-mvp.2 → 0.4.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 (106) hide show
  1. package/README.md +10 -12
  2. package/assets/templates/app/app/[[...slug]]/page.tsx +14 -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__/handlers.core.ts +3 -3
  16. package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +17 -18
  17. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +209 -0
  18. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.ts +247 -0
  19. package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +48 -19
  20. package/assets/templates/app/lib/__STOREFRONT__/schema.ts +49 -11
  21. package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +3 -5
  22. package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +25 -0
  23. package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +4 -2
  24. package/assets/templates/app/lib/__STOREFRONT__/views/sections/cta.client.tsx +1 -1
  25. package/assets/templates/app/lib/__STOREFRONT__/views/sections/faq.client.tsx +1 -1
  26. package/assets/templates/app/lib/__STOREFRONT__/views/sections/logoCloud.tsx +1 -1
  27. package/assets/templates/app/lib/__STOREFRONT__/views/sections/pricing.tsx +1 -1
  28. package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.client.tsx +16 -16
  29. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +1 -1
  30. package/assets/templates/app/lib/__STOREFRONT__/views/sections/statistics.tsx +1 -1
  31. package/assets/templates/app/lib/__STOREFRONT__/views/sections/testimonials.tsx +1 -1
  32. package/assets/templates/features/customer-auth/handlers.ts +19 -23
  33. package/assets/templates/features/customer-auth/state.ts +21 -0
  34. package/assets/templates/views/account/index.tsx +19 -7
  35. package/assets/templates/views/account/registry.tsx +234 -155
  36. package/assets/templates/views/cart/data.ts +7 -7
  37. package/assets/templates/views/cart/registry.tsx +4 -3
  38. package/assets/templates/views/category/assembly/assembly.json +1 -1
  39. package/assets/templates/views/category/assembly/registry.skeleton.tsx +6 -6
  40. package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +1 -1
  41. package/assets/templates/views/category/registry.tsx +7 -7
  42. package/assets/templates/views/checkout/registry.tsx +3 -5
  43. package/assets/templates/views/home/assembly/assembly.json +4 -4
  44. package/assets/templates/views/home/assembly/index.skeleton.tsx +2 -1
  45. package/assets/templates/views/home/assembly/registry.skeleton.tsx +4 -1
  46. package/assets/templates/views/home/assembly/slots/benefits/cards/binding.json +5 -0
  47. package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/registry.part +7 -1
  48. package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
  49. package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/registry.part +6 -1
  50. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/binding.json +5 -0
  51. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/catalog.part +8 -0
  52. package/assets/templates/views/home/assembly/slots/categories/{ProductCategory2 → CategoryGrid}/element.part +1 -1
  53. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/registry.part +31 -0
  54. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/binding.json +5 -0
  55. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/catalog.part +4 -0
  56. package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/registry.part +3 -1
  57. package/assets/templates/views/home/content.ts +22 -0
  58. package/assets/templates/views/home/index.tsx +11 -6
  59. package/assets/templates/views/home/props.ts +1 -0
  60. package/assets/templates/views/home/registry.tsx +39 -15
  61. package/assets/templates/views/home/schema.ts +141 -24
  62. package/assets/templates/views/product/data.ts +1 -1
  63. package/assets/templates/views/product/registry.tsx +10 -6
  64. package/assets/templates/views/product/schema.ts +36 -1
  65. package/package.json +4 -5
  66. package/recipes/archetypes.json +25 -25
  67. package/recipes/catalog.json +213 -160
  68. package/recipes/catalog.mjs +10 -0
  69. package/recipes/catalog.schema.json +4 -0
  70. package/recipes/features.json +3 -3
  71. package/recipes/recipes.json +138 -40
  72. package/recipes/sections.json +2 -2
  73. package/recipes/validate.mjs +21 -4
  74. package/scripts/candidate.mjs +2 -2
  75. package/scripts/file-classes.mjs +10 -0
  76. package/scripts/ownership-conflict.mjs +5 -2
  77. package/scripts/view-assembly.mjs +10 -2
  78. package/scripts/view-selection.mjs +1 -1
  79. package/skills/sf-view-gen/assets/recipes/archetypes.json +25 -25
  80. package/skills/sf-view-gen/assets/recipes/catalog.json +213 -160
  81. package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
  82. package/skills/sf-view-gen/assets/recipes/features.json +3 -3
  83. package/skills/sf-view-gen/assets/recipes/recipes.json +138 -40
  84. package/skills/sf-view-gen/assets/recipes/sections.json +2 -2
  85. package/skills/sf-view-gen/assets/templates/views/sections/cta.client.tsx +1 -1
  86. package/skills/sf-view-gen/assets/templates/views/sections/faq.client.tsx +1 -1
  87. package/skills/sf-view-gen/assets/templates/views/sections/logoCloud.client.tsx +1 -1
  88. package/skills/sf-view-gen/assets/templates/views/sections/pricing.client.tsx +1 -1
  89. package/skills/sf-view-gen/assets/templates/views/sections/products.client.tsx +16 -16
  90. package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +1 -1
  91. package/skills/sf-view-gen/assets/templates/views/sections/statistics.client.tsx +1 -1
  92. package/skills/sf-view-gen/assets/templates/views/sections/testimonials.client.tsx +1 -1
  93. package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
  94. package/skills/sf-view-gen/scripts/validate.mjs +21 -4
  95. package/assets/templates/views/home/assembly/slots/benefits/Feature1/binding.json +0 -5
  96. package/assets/templates/views/home/assembly/slots/benefits/Feature2/binding.json +0 -5
  97. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/binding.json +0 -5
  98. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/catalog.part +0 -4
  99. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/registry.part +0 -16
  100. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/binding.json +0 -5
  101. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/catalog.part +0 -4
  102. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/catalog.part +0 -0
  103. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/element.part +0 -0
  104. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/catalog.part +0 -0
  105. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/element.part +0 -0
  106. /package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/element.part +0 -0
@@ -0,0 +1,247 @@
1
+ // Generated by Thor Commerce storefront (template: assets/templates/app/lib/__STOREFRONT__/projection-ownership.ts)
2
+ //
3
+ // Client-owned projection arbitration for the storefront renderer.
4
+ //
5
+ // `@json-render/react`'s StateProvider re-applies the initial values whose
6
+ // flattened pointers changed between two *server* projections. A client edit
7
+ // made with `set()` lives only in the store, so a changed server projection for
8
+ // the same key overwrites it. Storefront state is therefore split:
9
+ //
10
+ // - server-owned keys (route/catalog/spec/SEO/product data): the server always
11
+ // wins, so navigation keeps working;
12
+ // - client-owned keys (`CLIENT_OWNED_KEYS` = the account slice the SSR projects
13
+ // and the cart slice the cart Server Actions mutate): seeded from the first
14
+ // projection and then protected, so a later (or older) projection cannot
15
+ // overwrite a live cart or a newer local auth result.
16
+ //
17
+ // A mutation can `claim` a client-owned key with a generation (its value wins
18
+ // until release). Authoritative reconciliation releases the slice back to the
19
+ // server: `currentToken(keys)` + `release(token)` downgrades a claim OR a seed,
20
+ // so a tab that only seeded (mounted then never mutated) can still adopt a later
21
+ // logout/expiry projection without a prior local mutation. The generation guards
22
+ // make an older in-flight result unable to release or supersede a newer claim
23
+ // (task 3.3).
24
+ //
25
+ // INVARIANT: the ledger orders CLAIMS, not server projections. A `release` hands
26
+ // the slice to the next server projection and carries no age evidence, so any
27
+ // authoritative result that is displayed MUST be claimed (a newer claim wins
28
+ // until release) — never released to the server after display. The client helper
29
+ // `claimResolved(values, guard)` performs the generation guard + claim
30
+ // atomically; `reconcileAccount` is only an explicit transfer that accepts the
31
+ // next server refresh.
32
+ //
33
+ // Framework-free: no React/Next import, no global state, no token. The per-tab
34
+ // instance lives in `./projection-ownership.client`. `claim`/`seed` store only
35
+ // the declared keys, so a value carrying extra (for example secret) fields can
36
+ // never reach the projection.
37
+
38
+ /** The account state keys the catch-all SSR seeds and an auth mutation owns. */
39
+ export const ACCOUNT_OWNED_KEYS = [
40
+ 'accountCustomer',
41
+ 'accountAuthenticated',
42
+ 'accountResolution',
43
+ ] as const
44
+
45
+ /**
46
+ * The cart slice the cart Server Actions mutate locally and the SSR seeds. The
47
+ * server's read-failure/status flags (`cartReadError`, `receiptAvailable`) are
48
+ * deliberately NOT here: they are server-owned so an outage still surfaces.
49
+ */
50
+ export const CART_OWNED_KEYS = [
51
+ 'cart',
52
+ 'cartTotals',
53
+ 'cartId',
54
+ 'cartQuantity',
55
+ 'cartCompleted',
56
+ 'cartSelectedShippingOptionId',
57
+ ] as const
58
+
59
+ /** Every key the renderer protects from a changed server projection. */
60
+ export const CLIENT_OWNED_KEYS = [...ACCOUNT_OWNED_KEYS, ...CART_OWNED_KEYS] as const
61
+
62
+ /**
63
+ * A claim handle. `generation` is monotonic per ownership instance and is the
64
+ * token downstream mutation/reconciliation paths use to discard stale work.
65
+ */
66
+ export interface OwnershipToken {
67
+ readonly generation: number
68
+ readonly keys: readonly string[]
69
+ }
70
+
71
+ /** How a client-owned key is currently governed. */
72
+ export type OwnershipAuthority = 'seed' | 'client' | 'server'
73
+
74
+ /** The ownership ledger the renderer arbitrates against. */
75
+ export interface ProjectionOwnership {
76
+ /** The latest generation issued; 0 before any claim. */
77
+ generation(): number
78
+ /**
79
+ * Capture the first server value of every client-owned key not yet seen, so it
80
+ * is protected from later projections. Idempotent: an already-seeded key is
81
+ * never overwritten, and an existing claim is never replaced.
82
+ */
83
+ seed(projection: Record<string, unknown> | undefined): void
84
+ /**
85
+ * Take client ownership of `keys` with `values` (every key must be present),
86
+ * superseding any earlier claim for those keys. Returns the generation token.
87
+ */
88
+ claim(keys: readonly string[], values: Record<string, unknown>): OwnershipToken
89
+ /**
90
+ * The generation token for the current ownership (seed or claim) of `keys`, or
91
+ * null when they are already server-owned. Use it to release a SEEDED slice
92
+ * during authoritative reconciliation, without a prior local mutation.
93
+ */
94
+ currentToken(keys: readonly string[]): OwnershipToken | null
95
+ /**
96
+ * Return authority to the server for the keys of `token` when it is still the
97
+ * current ownership (seed or claim). An older token is ignored, so a late
98
+ * reconciliation cannot drop a newer claim.
99
+ */
100
+ release(token: OwnershipToken): void
101
+ /** True while `token` is still the current client claim for all its keys. */
102
+ isCurrent(token: OwnershipToken): boolean
103
+ /** True while `key` is protected from the server projection. */
104
+ isOwned(key: string): boolean
105
+ /** The client-owned key/value overlay across every seeded/claimed key. */
106
+ overlay(): Record<string, unknown>
107
+ /**
108
+ * Acquire the per-tab auth-mutation gate. Returns false when another auth
109
+ * mutation/reconciliation already holds it, so two consumers sharing this tab
110
+ * (the global mount, an account form, a nav sign-out control) cannot issue
111
+ * concurrent auth requests. The gate is per-tab state on this ledger — never a
112
+ * module global — so it cannot leak across requests, tabs, or store contexts.
113
+ */
114
+ acquireMutationGate(): boolean
115
+ /** Release the per-tab auth-mutation gate (the acquirer only). */
116
+ releaseMutationGate(): void
117
+ /** True while an auth mutation/reconciliation holds the gate. */
118
+ isMutationGateHeld(): boolean
119
+ }
120
+
121
+ interface OwnedEntry {
122
+ authority: OwnershipAuthority
123
+ generation: number
124
+ value: unknown
125
+ }
126
+
127
+ /** Create one per-tab ownership ledger. */
128
+ export function createProjectionOwnership(): ProjectionOwnership {
129
+ const owned = new Map<string, OwnedEntry>()
130
+ let generation = 0
131
+ // Per-tab auth-mutation gate: one in-flight auth request at a time across
132
+ // every consumer that shares this ledger (the global mount, the account forms,
133
+ // a future nav sign-out). Deliberately NOT a module global — a new ledger per
134
+ // tab/request keeps tabs and store contexts isolated.
135
+ let mutationGateHeld = false
136
+
137
+ return {
138
+ generation: () => generation,
139
+ seed(projection) {
140
+ if (!projection) return
141
+ for (const key of CLIENT_OWNED_KEYS) {
142
+ if (owned.has(key)) continue
143
+ if (Object.prototype.hasOwnProperty.call(projection, key)) {
144
+ owned.set(key, { authority: 'seed', generation: 0, value: projection[key] })
145
+ }
146
+ }
147
+ },
148
+ claim(keys, values) {
149
+ const missing = keys.filter((key) => !Object.prototype.hasOwnProperty.call(values, key))
150
+ if (missing.length > 0) {
151
+ throw new Error(
152
+ `ProjectionOwnership.claim: missing value(s) for owned key(s): ${missing.join(', ')}`,
153
+ )
154
+ }
155
+ generation += 1
156
+ const token: OwnershipToken = { generation, keys: [...keys] }
157
+ for (const key of keys) owned.set(key, { authority: 'client', generation, value: values[key] })
158
+ return token
159
+ },
160
+ release(token) {
161
+ for (const key of token.keys) {
162
+ const entry = owned.get(key)
163
+ if (entry && entry.authority !== 'server' && entry.generation === token.generation) {
164
+ owned.set(key, { authority: 'server', generation: token.generation, value: undefined })
165
+ }
166
+ }
167
+ },
168
+ currentToken(keys) {
169
+ // Assumes a slice's keys share one generation: `claimAccount` always passes
170
+ // all ACCOUNT_OWNED_KEYS and `page.tsx` seeds the whole account slice or
171
+ // none. A key absent from the first projection yields null (no-op release).
172
+ let generationForKeys = -1
173
+ for (const key of keys) {
174
+ const entry = owned.get(key)
175
+ if (!entry || entry.authority === 'server') return null
176
+ generationForKeys = Math.max(generationForKeys, entry.generation)
177
+ }
178
+ return generationForKeys < 0 ? null : { generation: generationForKeys, keys: [...keys] }
179
+ },
180
+ isCurrent(token) {
181
+ return token.keys.every((key) => {
182
+ const entry = owned.get(key)
183
+ return entry?.authority === 'client' && entry.generation === token.generation
184
+ })
185
+ },
186
+ isOwned(key) {
187
+ const entry = owned.get(key)
188
+ return entry !== undefined && entry.authority !== 'server'
189
+ },
190
+ overlay() {
191
+ const result: Record<string, unknown> = {}
192
+ for (const [key, entry] of owned) {
193
+ if (entry.authority !== 'server') result[key] = entry.value
194
+ }
195
+ return result
196
+ },
197
+ acquireMutationGate() {
198
+ if (mutationGateHeld) return false
199
+ mutationGateHeld = true
200
+ return true
201
+ },
202
+ releaseMutationGate() {
203
+ mutationGateHeld = false
204
+ },
205
+ isMutationGateHeld() {
206
+ return mutationGateHeld
207
+ },
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Merge the client-owned overlay over a server projection. Server-owned keys are
213
+ * always taken from the server, so a protected cart/account slice never freezes
214
+ * the route/catalog data. When nothing is owned the original projection is
215
+ * returned by reference.
216
+ */
217
+ export function arbitrateProjection(
218
+ ownership: ProjectionOwnership,
219
+ serverProjection: Record<string, unknown> | undefined,
220
+ ): Record<string, unknown> {
221
+ const base = serverProjection ?? {}
222
+ const overlay = ownership.overlay()
223
+ if (Object.keys(overlay).length === 0) return base
224
+ return { ...base, ...overlay }
225
+ }
226
+
227
+ /** A projection stabilized by serialized content, so an equivalent refresh is a no-op. */
228
+ export interface StabilizedProjection {
229
+ readonly key: string
230
+ readonly value: Record<string, unknown>
231
+ }
232
+
233
+ /**
234
+ * Keep the previous stabilized projection while the serialized content is
235
+ * unchanged, so `StateProvider` does not re-apply identical server values (which
236
+ * would reset client-owned state). A genuinely changed projection yields a new
237
+ * value. This is the reference-stability the renderer relies on.
238
+ */
239
+ export function stabilizeProjection(
240
+ previous: StabilizedProjection | null,
241
+ projection: Record<string, unknown> | undefined,
242
+ ): StabilizedProjection {
243
+ const value = projection ?? {}
244
+ const key = JSON.stringify(value)
245
+ if (previous && previous.key === key) return previous
246
+ return { key, value }
247
+ }
@@ -12,30 +12,30 @@
12
12
  import { defineRegistry, useStateStore } from '@json-render/react'
13
13
  import { useEffect } from 'react'
14
14
  import { usePathname } from 'next/navigation'
15
- import {
16
- BackToTop as BackToTopBlock,
17
- Banner1,
18
- FooterSection1,
19
- MobileBottomNav as MobileBottomNavBlock,
20
- Navbar1,
21
- Navbar4,
22
- ProductCard1,
23
- SkipToContent as SkipToContentBlock,
24
- type BackToTopProps,
25
- type MobileBottomNavProps,
26
- type SkipToContentProps,
27
- } from '@thorprovider/blocks'
15
+ import { BackToTop as BackToTopBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
16
+ import { MobileBottomNav as MobileBottomNavBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
17
+ import { SkipToContent as SkipToContentBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/skip-to-content'
18
+ import Banner1 from '@thorprovider/blocks/blocks/marketing/banners/banner-1'
19
+ import FooterSection1 from '@thorprovider/blocks/blocks/marketing/footers/footer-section-1'
20
+ import Navbar1 from '@thorprovider/blocks/blocks/marketing/navbars/navbar-1'
21
+ import Navbar4 from '@thorprovider/blocks/blocks/marketing/navbars/navbar-4'
22
+ import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
23
+ import type { BackToTopProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
24
+ import type { MobileBottomNavProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
25
+ import type { SkipToContentProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/skip-to-content'
28
26
  import { isAvailableMoney } from '@thorprovider/blocks/contracts'
29
27
  import type { Money } from '@thorprovider/types'
30
28
  import { catalog } from './catalog'
31
29
  import type { CartLineState, CartTotalsState } from './state'
32
30
  import { useStorefrontHandlers } from './handlers'
33
31
  import { cartViewAvailable, checkoutAvailable, mountedFeatureNames } from './composition'
32
+ import { accountStoreUser } from './account-user.core'
33
+ import type { AccountIdentity, AccountResolution } from './account-session.core'
34
34
  import {
35
35
  bannerPropsSchema,
36
36
  footerPropsSchema,
37
37
  navbarPropsSchema,
38
- productCardPropsSchema,
38
+ productGridPropsSchema,
39
39
  storefrontNavbarPropsSchema,
40
40
  } from './schema'
41
41
  import { viewRegistries } from './views/registry'
@@ -154,6 +154,16 @@ const baseComponents = {
154
154
  StorefrontNavbar: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
155
155
  const parsed = storefrontNavbarPropsSchema.parse(props)
156
156
  const { state, set } = useStateStore()
157
+ // The one session→chrome bridge. It reads the shared account state the
158
+ // lifecycle seeds/writes directly from the store (never importing the
159
+ // lifecycle module, so an unmounted customer-auth leaves no account wiring in
160
+ // this always-present client registry — the 4.3 invariant). Every
161
+ // auth-specific prop below is gated on the mounted capability.
162
+ const authMounted = mountedFeatureNames.includes('customer-auth')
163
+ const identity = (state.accountCustomer ?? null) as AccountIdentity | null
164
+ const accountResolution = (
165
+ typeof state.accountResolution === 'string' ? state.accountResolution : 'unresolved'
166
+ ) as AccountResolution | 'unresolved'
157
167
  const cart = (state.cart ?? []) as CartLineState[]
158
168
  const totals = state.cartTotals as CartTotalsState | null
159
169
  const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
@@ -178,6 +188,24 @@ const baseComponents = {
178
188
  logoAccent={parsed.logoAccent}
179
189
  className={parsed.className}
180
190
  accountHref={parsed.accountHref}
191
+ // Signed-in identity + account feedback, only while customer-auth is
192
+ // mounted. `user` is mapped from the shared allowlisted identity; the
193
+ // account menu items and destination come from the parsed element props
194
+ // (derived spec defaults, overridable by the user-owned shell).
195
+ user={authMounted ? accountStoreUser(identity) ?? undefined : undefined}
196
+ accountMenuItems={parsed.accountMenuItems}
197
+ accountPending={
198
+ authMounted
199
+ ? state.accountPending === true || state.accountReconciling === true
200
+ : undefined
201
+ }
202
+ accountUnavailable={authMounted ? accountResolution === 'unavailable' : undefined}
203
+ // Sign-out binds to the feature's existing `logout` action and retry to
204
+ // the lifecycle's existing `retryAccountSession` action (the same one the
205
+ // account boundary emits). No help action exists, so none is fabricated
206
+ // (onHelp stays unbound).
207
+ onSignOut={authMounted ? () => emit('logout') : undefined}
208
+ onAccountRetry={authMounted ? () => emit('retryAccountSession') : undefined}
181
209
  // The current route marks the matching category link as the current page
182
210
  // (accessibly, beyond color alone); no link is marked when it does not
183
211
  // match any destination.
@@ -246,24 +274,25 @@ const baseComponents = {
246
274
  />
247
275
  )
248
276
  },
249
- ProductCard: ({
277
+ ProductGrid: ({
250
278
  props,
251
279
  emit,
252
280
  }: {
253
281
  props: Record<string, unknown>
254
282
  emit: (event: string) => void
255
283
  }) => {
256
- const parsed = productCardPropsSchema.parse(props)
284
+ const parsed = productGridPropsSchema.parse(props)
257
285
  const { set } = useStateStore()
258
286
  const select = (product: unknown) => {
259
287
  set('/lastClicked', product)
260
288
  }
261
289
  return (
262
- <ProductCard1
263
- products={parsed.products}
290
+ <ProductGridBlock
291
+ items={parsed.items}
292
+ presentation={parsed.presentation}
264
293
  heading={parsed.heading}
265
294
  maxItems={parsed.maxItems}
266
- // This base card opens the detail so a variant is chosen explicitly.
295
+ // The canonical listing opens the detail so a variant is chosen explicitly.
267
296
  onAddToCart={(product) => {
268
297
  select(product)
269
298
  emit('openProduct')
@@ -29,14 +29,19 @@ const footerLinkColumnSchema = z.object({
29
29
  // Declared locally so the scaffold's zod version is the only one in play.
30
30
  // Cross-major schema assignment (@thorprovider/blocks ships zod v3) breaks the
31
31
  // defineCatalog contract, so the block contract is mirrored here instead.
32
- export const shellProductSchema = z.object({
32
+ // Mirrors the `ProductPresentation` contract of the canonical `ProductCard`:
33
+ // price is canonical `Money` (decimal major-unit string + currency code); an
34
+ // unresolved price is an empty Money (the card renders an unavailable state,
35
+ // never a zero); optional evidence (rating, badge) renders only when supplied.
36
+ export const productPresentationSchema = z.object({
33
37
  id: z.union([z.string(), z.number()]),
34
38
  title: z.string(),
35
- price: z.number(),
36
- originalPrice: z.number().optional(),
37
- // Required: the ProductCard1 block contract demands `image: string`, and the
38
- // runtime's card projection always fills it (PRODUCT_IMAGE_FALLBACK).
39
- image: z.string(),
39
+ image: z.string().optional(),
40
+ imageAlt: z.string().optional(),
41
+ href: z.string().optional(),
42
+ price: z.object({ amount: z.string(), currencyCode: z.string() }),
43
+ compareAtPrice: z.object({ amount: z.string(), currencyCode: z.string() }).optional(),
44
+ rating: z.number().optional(),
40
45
  badge: z.string().optional(),
41
46
  })
42
47
 
@@ -61,13 +66,34 @@ export const navCategorySchema = z.object({
61
66
  })
62
67
 
63
68
  // Optional brand seam mirroring the Navbar4 / FooterSection1 accent props and
64
- // the StorefrontHero1 editorial image. Declared locally (see shellProductSchema)
65
- // so the scaffold's zod version is the only one in play.
69
+ // the StorefrontHero editorial image. Declared locally (see
70
+ // productPresentationSchema) so the scaffold's zod version is the only one in
71
+ // play.
66
72
  export const shellAccentSchema = z.object({
67
73
  text: z.string(),
68
74
  className: z.string().optional(),
69
75
  })
70
76
 
77
+ // Account chrome data mirrors, declared locally (see productPresentationSchema)
78
+ // so the scaffold's zod version is the only one in play. They mirror the
79
+ // `@thorprovider/blocks` `StoreUser` / `AccountMenuItem` contracts the navbar
80
+ // account menu renders. Callbacks (`onSignOut`, `onHelp`, `onAccountRetry`) are
81
+ // deliberately ABSENT: they are consumer bindings, not serializable props, so a
82
+ // spec/JSON payload can never carry a function.
83
+ export const storeUserSchema = z.object({
84
+ name: z.string(),
85
+ email: z.string(),
86
+ avatar: z.string().optional(),
87
+ initials: z.string(),
88
+ })
89
+
90
+ export const accountMenuItemSchema = z.object({
91
+ label: z.string(),
92
+ href: z.string(),
93
+ description: z.string().optional(),
94
+ icon: z.enum(['orders', 'wishlist', 'addresses', 'settings']).optional(),
95
+ })
96
+
71
97
  export const storefrontNavbarPropsSchema = z.object({
72
98
  storeCategories: z.array(navCategorySchema),
73
99
  shippingNote: z.string().optional(),
@@ -77,6 +103,13 @@ export const storefrontNavbarPropsSchema = z.object({
77
103
  logoAccent: shellAccentSchema.optional(),
78
104
  className: z.string().optional(),
79
105
  accountHref: z.string().optional(),
106
+ // Signed-in identity, account links, and account feedback states, derived from
107
+ // the shared session by the registry when customer-auth is mounted. All
108
+ // optional so a fresh or older user-owned shell without them still parses.
109
+ user: storeUserSchema.optional(),
110
+ accountMenuItems: z.array(accountMenuItemSchema).optional(),
111
+ accountPending: z.boolean().optional(),
112
+ accountUnavailable: z.boolean().optional(),
80
113
  // Held global search (E2 task 5.4): the generated shell opts out of the
81
114
  // navbar search control while no verified global search contract exists.
82
115
  showSearch: z.boolean().optional(),
@@ -90,10 +123,15 @@ export const bannerPropsSchema = z.object({
90
123
  avatars: z.array(z.string()).optional(),
91
124
  })
92
125
 
93
- export const productCardPropsSchema = z.object({
94
- products: z.array(shellProductSchema),
126
+ export const productGridPropsSchema = z.object({
127
+ items: z.array(productPresentationSchema),
128
+ presentation: z.enum(['classic', 'minimal', 'rich']).optional(),
95
129
  heading: z.string().optional(),
96
- maxItems: z.number().optional(),
130
+ maxItems: z.number().int().positive().optional(),
131
+ wishlistedIds: z.array(z.union([z.string(), z.number()])).readonly().optional(),
132
+ loading: z.boolean().optional(),
133
+ skeletonCount: z.number().int().positive().optional(),
134
+ emptyLabel: z.string().optional(),
97
135
  })
98
136
 
99
137
  export const footerPropsSchema = z.object({
@@ -23,11 +23,9 @@ import {
23
23
  MERCHANDISING_SECTION_MAX_ITEMS,
24
24
  sectionSourceSchema,
25
25
  } from '@thorprovider/runtime/contracts'
26
- import {
27
- PRODUCT_IMAGE_FALLBACK,
28
- isCompleteFiniteDecimal,
29
- type ProductPresentation,
30
- } from '@thorprovider/blocks'
26
+ import { PRODUCT_IMAGE_FALLBACK } from '@thorprovider/blocks/contracts'
27
+ import { isCompleteFiniteDecimal } from '@thorprovider/blocks/lib/money'
28
+ import type { ProductPresentation } from '@thorprovider/blocks/contracts'
31
29
  import type { Product, StoreContext } from '@thorprovider/types'
32
30
 
33
31
  /** Per-instance section selection config, keyed by the section's stable id. */
@@ -52,6 +52,16 @@ const navigabilityConfig = (mountedFeatureConfigs['navigability'] ?? {}) as {
52
52
  }
53
53
  const showBackToTop = navigabilityConfig.showBackToTop !== false
54
54
 
55
+ // Account chrome is contributed only when customer-auth is mounted. The default
56
+ // account menu is DERIVED and minimal — the account surface only, with a real
57
+ // link (no dead `#`); extra account destinations are a deferred, per-storefront
58
+ // concern. A user-owned shell may override the destination/items via
59
+ // `navbarShellProps` (spread last).
60
+ const authMounted = mountedFeatureNames.includes('customer-auth')
61
+ const DEFAULT_ACCOUNT_MENU_ITEMS = [
62
+ { label: 'Pedidos', href: '/account', icon: 'orders' as const },
63
+ ]
64
+
55
65
  const shellElements: Record<string, StorefrontElement> = {
56
66
  // Navigability chrome, present only when the feature is installed. The skip
57
67
  // link is the first focusable element (rendered before the notices); the
@@ -106,6 +116,12 @@ const shellElements: Record<string, StorefrontElement> = {
106
116
  utilityLinks: [],
107
117
  logoText: '__SITE_NAME__',
108
118
  logoHref: '/',
119
+ // Gated account defaults, injected BEFORE the shell spread so an authored
120
+ // `accountHref`/`accountMenuItems` in the user-owned shell wins. A
121
+ // non-adopter passes neither and keeps its baseline chrome exactly.
122
+ ...(authMounted
123
+ ? { accountHref: '/account', accountMenuItems: DEFAULT_ACCOUNT_MENU_ITEMS }
124
+ : {}),
109
125
  // Optional wordmark accent and surface classes, configured in the
110
126
  // user-owned shell seam. Spread last so merchant edits win.
111
127
  ...navbarShellProps,
@@ -116,6 +132,15 @@ const shellElements: Record<string, StorefrontElement> = {
116
132
  goToCheckout: { action: 'goToCheckout' },
117
133
  applyQuantityDelta: { action: 'applyQuantityDelta' },
118
134
  removeFromCart: { action: 'removeFromCart' },
135
+ // The account sign-out and retry reuse customer-auth's existing `logout`
136
+ // and `retryAccountSession` actions (the latter is what the account
137
+ // boundary emits too); wired only while the capability is mounted.
138
+ ...(authMounted
139
+ ? {
140
+ logout: { action: 'logout' },
141
+ retryAccountSession: { action: 'retryAccountSession' },
142
+ }
143
+ : {}),
119
144
  },
120
145
  },
121
146
  footer: {
@@ -8,7 +8,7 @@
8
8
  import type {
9
9
  CardProduct,
10
10
  FeaturedProduct,
11
- ProductCategory2Category,
11
+ ProductCategoryItem,
12
12
  ProductDetailProduct,
13
13
  } from '@thorprovider/blocks'
14
14
  import type { Money, PaymentMethod } from '@thorprovider/types'
@@ -165,7 +165,8 @@ export type OrderStatus = 'idle' | 'pending' | 'error' | 'unresolved' | 'complet
165
165
 
166
166
  export interface StorefrontCoreState {
167
167
  heroProducts: FeaturedProduct[]
168
- categories: ProductCategory2Category[]
168
+ categories: ProductCategoryItem[]
169
+ categoryQuery: string
169
170
  navCategories: NavCategory[]
170
171
  categoryProducts: CardProduct[]
171
172
  /** Canonical product detail: real variants, options, availability, and Money. */
@@ -229,6 +230,7 @@ export interface StorefrontState extends StorefrontCoreState {
229
230
  export const storefrontCoreState: StorefrontCoreState = {
230
231
  heroProducts: [],
231
232
  categories: [],
233
+ categoryQuery: '',
232
234
  navCategories: [],
233
235
  categoryProducts: [],
234
236
  selectedProduct: null,
@@ -5,7 +5,7 @@
5
5
  // 'use client' boundary, but this fragment keeps the explicit client boundary so
6
6
  // the section composes identically in any consumer graph.
7
7
 
8
- import { CtaSection1 as CtaBlock } from '@thorprovider/blocks'
8
+ import CtaBlock from '@thorprovider/blocks/blocks/marketing/cta/cta-section-1'
9
9
  import { ctaSection1PropsSchema } from './schema.cta'
10
10
  import type { ViewRegistry } from '../types'
11
11
 
@@ -5,7 +5,7 @@
5
5
  // 'use client' boundary, but this fragment keeps the explicit client boundary so
6
6
  // the section composes identically in any consumer graph.
7
7
 
8
- import { FaqBlock1 as FaqBlock } from '@thorprovider/blocks'
8
+ import FaqBlock from '@thorprovider/blocks/blocks/marketing/faq/faq-block-1'
9
9
  import { faqPropsSchema } from './schema.faq'
10
10
  import type { ViewRegistry } from '../types'
11
11
 
@@ -1,6 +1,6 @@
1
1
  // Optional section fragment: logoCloud (mirrors recipes/sections.json)
2
2
 
3
- import { LogoCloud1 as LogoCloudBlock } from '@thorprovider/blocks'
3
+ import LogoCloudBlock from '@thorprovider/blocks/blocks/marketing/logo-clouds/logo-cloud-1'
4
4
  import { z } from 'zod'
5
5
 
6
6
  // Mirrors the LogoCloud1Platform/LogoCloud1Props block contracts. `id` is a
@@ -1,6 +1,6 @@
1
1
  // Optional section fragment: pricing (mirrors recipes/sections.json)
2
2
 
3
- import { PricingSection1 as PricingBlock } from '@thorprovider/blocks'
3
+ import PricingBlock from '@thorprovider/blocks/blocks/marketing/pricing/pricing-section-1'
4
4
  import { z } from 'zod'
5
5
 
6
6
  // Mirrors the PricingTier/PricingSection1Props block contracts.
@@ -2,16 +2,14 @@
2
2
 
3
3
  // Optional section fragment: products (mirrors recipes/sections.json) — client registry.
4
4
  // The matching server-side catalog lives in products.tsx. A data-bound section
5
- // renders one of two verified presentations (ProductCard1 grid, or the combined
6
- // grid-and-carousel ProductShowcase1) chosen by the resolved `variant`. The
7
- // selection and resolved products arrive through the view state; this boundary
8
- // only validates them and wires navigation/purchase callbacks.
5
+ // renders one of two verified presentations (the canonical ProductGrid listing,
6
+ // or the combined grid-and-carousel ProductShowcase1) chosen by the resolved
7
+ // `variant`. The selection and resolved products arrive through the view state;
8
+ // this boundary only validates them and wires navigation/purchase callbacks.
9
9
 
10
- import {
11
- ProductCard1 as ProductCard1Block,
12
- ProductShowcase1 as ProductShowcase1Block,
13
- type ProductCard1Product,
14
- } from '@thorprovider/blocks'
10
+ import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
11
+ import ProductShowcase1Block from '@thorprovider/blocks/blocks/e-commerce/product-list/product-showcase-1'
12
+ import type { ProductPresentation } from '@thorprovider/blocks/contracts'
15
13
  import { useStateStore } from '@json-render/react'
16
14
  import { useSectionObservation } from '../../section-observation'
17
15
  import { productsPropsSchema, type ProductsStatus } from './schema.products'
@@ -65,7 +63,7 @@ export const productsRegistry: ViewRegistry = {
65
63
 
66
64
  // The detail affordance opens the product so a variant is chosen explicitly.
67
65
  // It is also the section's observation origin (disabled by default).
68
- const openProduct = (product: ProductCard1Product) => {
66
+ const openProduct = (product: ProductPresentation) => {
69
67
  noteProductClick(product)
70
68
  set('/lastClicked', product)
71
69
  emit('openProduct')
@@ -74,15 +72,12 @@ export const productsRegistry: ViewRegistry = {
74
72
  // Product-card shortcut: the add affordance adds the product's first
75
73
  // purchasable variant (resolved server-side from the product id), then opens
76
74
  // the mini-cart. It is not the section's observation origin.
77
- const addToCart = (product: ProductCard1Product) => {
75
+ const addToCart = (product: ProductPresentation) => {
78
76
  set('/lastClicked', product)
79
77
  emit('addClickedToCart')
80
78
  }
81
79
 
82
80
  const shared = {
83
- products: parsed.products,
84
- heading: parsed.heading,
85
- description: parsed.description,
86
81
  onAddToCart: addToCart,
87
82
  onProductClick: openProduct,
88
83
  }
@@ -90,9 +85,14 @@ export const productsRegistry: ViewRegistry = {
90
85
  return (
91
86
  <div ref={containerRef}>
92
87
  {parsed.variant === 'ProductShowcase1' ? (
93
- <ProductShowcase1Block {...shared} />
88
+ <ProductShowcase1Block
89
+ {...shared}
90
+ heading={parsed.heading}
91
+ description={parsed.description}
92
+ products={parsed.products}
93
+ />
94
94
  ) : (
95
- <ProductCard1Block {...shared} />
95
+ <ProductGridBlock {...shared} heading={parsed.heading} items={parsed.products} />
96
96
  )}
97
97
  </div>
98
98
  )