@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
@@ -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
+ }
@@ -3,7 +3,7 @@
3
3
  // Generated by Thor Commerce storefront (template: assets/templates/app/lib/__STOREFRONT__/registry.tsx)
4
4
  // Base registry for the app shell plus every registered view's registry fragment.
5
5
  //
6
- // The shell renders the live backend cart: the Navbar mini-cart and the cart
6
+ // The shell renders the live backend cart: the StorefrontNavbar mini-cart and the cart
7
7
  // drawer read the authoritative cart state and dispatch cart mutations to the
8
8
  // Server Actions. A listing card's add-to-cart adds the product's first
9
9
  // purchasable variant (the card shortcut); opening a product from a listing
@@ -12,35 +12,33 @@
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 { FooterSection, Navbar, StorefrontNavbar } from '@thorprovider/blocks'
20
+ import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
21
+ import type { BackToTopProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
22
+ import type { MobileBottomNavProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
23
+ import type { SkipToContentProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/skip-to-content'
28
24
  import { isAvailableMoney } from '@thorprovider/blocks/contracts'
29
25
  import type { Money } from '@thorprovider/types'
30
26
  import { catalog } from './catalog'
31
27
  import type { CartLineState, CartTotalsState } from './state'
32
28
  import { useStorefrontHandlers } from './handlers'
33
29
  import { cartViewAvailable, checkoutAvailable, mountedFeatureNames } from './composition'
30
+ import { accountStoreUser } from './account-user.core'
31
+ import type { AccountIdentity, AccountResolution } from './account-session.core'
34
32
  import {
35
33
  bannerPropsSchema,
36
34
  footerPropsSchema,
37
35
  navbarPropsSchema,
38
- productCardPropsSchema,
36
+ productGridPropsSchema,
39
37
  storefrontNavbarPropsSchema,
40
38
  } from './schema'
41
39
  import { viewRegistries } from './views/registry'
42
40
 
43
- // Navbar4 accepts its own mini-cart line shape (`qty`), distinct from the block
41
+ // StorefrontNavbar accepts its own mini-cart line shape (`qty`), distinct from the block
44
42
  // `CartItem` contract (`quantity`). Types are local so the asymmetry is explicit.
45
43
  interface NavCartItem {
46
44
  id: string
@@ -52,7 +50,7 @@ interface NavCartItem {
52
50
  lineTotal?: Money
53
51
  }
54
52
 
55
- /** CartLineState -> Navbar4 cart line. `price` is legacy; the authoritative
53
+ /** CartLineState -> StorefrontNavbar cart line. `price` is legacy; the authoritative
56
54
  * subtotal and per-line total are passed separately, so neither is computed
57
55
  * from the line. */
58
56
  function toNavCartItems(cart: CartLineState[]): NavCartItem[] {
@@ -154,6 +152,16 @@ const baseComponents = {
154
152
  StorefrontNavbar: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
155
153
  const parsed = storefrontNavbarPropsSchema.parse(props)
156
154
  const { state, set } = useStateStore()
155
+ // The one session→chrome bridge. It reads the shared account state the
156
+ // lifecycle seeds/writes directly from the store (never importing the
157
+ // lifecycle module, so an unmounted customer-auth leaves no account wiring in
158
+ // this always-present client registry — the 4.3 invariant). Every
159
+ // auth-specific prop below is gated on the mounted capability.
160
+ const authMounted = mountedFeatureNames.includes('customer-auth')
161
+ const identity = (state.accountCustomer ?? null) as AccountIdentity | null
162
+ const accountResolution = (
163
+ typeof state.accountResolution === 'string' ? state.accountResolution : 'unresolved'
164
+ ) as AccountResolution | 'unresolved'
157
165
  const cart = (state.cart ?? []) as CartLineState[]
158
166
  const totals = state.cartTotals as CartTotalsState | null
159
167
  const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
@@ -169,7 +177,7 @@ const baseComponents = {
169
177
  isAvailableMoney(totals.subtotal) &&
170
178
  isAvailableMoney(totals.total)
171
179
  return (
172
- <Navbar4
180
+ <StorefrontNavbar
173
181
  storeCategories={parsed.storeCategories}
174
182
  shippingNote={parsed.shippingNote}
175
183
  utilityLinks={parsed.utilityLinks}
@@ -178,6 +186,24 @@ const baseComponents = {
178
186
  logoAccent={parsed.logoAccent}
179
187
  className={parsed.className}
180
188
  accountHref={parsed.accountHref}
189
+ // Signed-in identity + account feedback, only while customer-auth is
190
+ // mounted. `user` is mapped from the shared allowlisted identity; the
191
+ // account menu items and destination come from the parsed element props
192
+ // (derived spec defaults, overridable by the user-owned shell).
193
+ user={authMounted ? accountStoreUser(identity) ?? undefined : undefined}
194
+ accountMenuItems={parsed.accountMenuItems}
195
+ accountPending={
196
+ authMounted
197
+ ? state.accountPending === true || state.accountReconciling === true
198
+ : undefined
199
+ }
200
+ accountUnavailable={authMounted ? accountResolution === 'unavailable' : undefined}
201
+ // Sign-out binds to the feature's existing `logout` action and retry to
202
+ // the lifecycle's existing `retryAccountSession` action (the same one the
203
+ // account boundary emits). No help action exists, so none is fabricated
204
+ // (onHelp stays unbound).
205
+ onSignOut={authMounted ? () => emit('logout') : undefined}
206
+ onAccountRetry={authMounted ? () => emit('retryAccountSession') : undefined}
181
207
  // The current route marks the matching category link as the current page
182
208
  // (accessibly, beyond color alone); no link is marked when it does not
183
209
  // match any destination.
@@ -231,39 +257,42 @@ const baseComponents = {
231
257
  />
232
258
  )
233
259
  },
234
- Navbar: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
260
+ Navbar: ({ props }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
235
261
  const parsed = navbarPropsSchema.parse(props)
236
262
  return (
237
- <Navbar1
238
- navLinks={parsed.navLinks}
263
+ <Navbar
264
+ presentation={parsed.presentation}
239
265
  logoText={parsed.logoText}
240
266
  logoHref={parsed.logoHref}
241
267
  currentPath={parsed.currentPath}
268
+ links={parsed.links}
269
+ featured={parsed.featured}
242
270
  signIn={parsed.signIn}
243
271
  cta={parsed.cta}
244
- cartCount={parsed.cartCount}
245
- onOpenCart={() => emit('openCart')}
272
+ // Page-level navigation owns no commerce state: the cart affordance and
273
+ // its `openCart` intent belong to the StorefrontNavbar shell (D5).
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')
@@ -278,12 +307,14 @@ const baseComponents = {
278
307
  Footer: ({ props }: { props: Record<string, unknown> }) => {
279
308
  const parsed = footerPropsSchema.parse(props)
280
309
  return (
281
- <FooterSection1
310
+ <FooterSection
311
+ presentation="brand-columns"
282
312
  brandName={parsed.brandName}
283
313
  brandAccent={parsed.brandAccent}
284
314
  brandDescription={parsed.brandDescription}
285
315
  linkColumns={parsed.linkColumns}
286
316
  className={parsed.className}
317
+ linkBehavior="native"
287
318
  // The scaffold ships no newsletter submit callback. The seam's
288
319
  // `newsletter` is content only, so the block swallows it and renders no
289
320
  // form. Wiring a real host callback (which would enable the form) is an
@@ -11,9 +11,34 @@ export const ctaSchema = z.object({
11
11
  href: z.string().optional(),
12
12
  })
13
13
 
14
- export const navLinkSchema = z.object({
14
+ export const navbarItemSchema = z.object({
15
+ label: z.string(),
16
+ href: z.string(),
17
+ description: z.string().optional(),
18
+ /** Key resolved through the shell's host-bound icon map. */
19
+ icon: z.string().optional(),
20
+ })
21
+
22
+ export const navbarGroupSchema = z.object({
23
+ title: z.string().optional(),
24
+ items: z.array(navbarItemSchema),
25
+ })
26
+
27
+ export const navbarLinkSchema = z.object({
15
28
  label: z.string(),
16
29
  href: z.string().optional(),
30
+ groups: z.array(navbarGroupSchema).optional(),
31
+ emphasis: z.boolean().optional(),
32
+ })
33
+
34
+ export const navbarFeaturedSchema = z.object({
35
+ eyebrow: z.string(),
36
+ title: z.string(),
37
+ description: z.string().optional(),
38
+ href: z.string(),
39
+ linkLabel: z.string().optional(),
40
+ image: z.string().optional(),
41
+ imageAlt: z.string().optional(),
17
42
  })
18
43
 
19
44
  const footerLinkSchema = z.object({
@@ -29,25 +54,35 @@ const footerLinkColumnSchema = z.object({
29
54
  // Declared locally so the scaffold's zod version is the only one in play.
30
55
  // Cross-major schema assignment (@thorprovider/blocks ships zod v3) breaks the
31
56
  // defineCatalog contract, so the block contract is mirrored here instead.
32
- export const shellProductSchema = z.object({
57
+ // Mirrors the `ProductPresentation` contract of the canonical `ProductCard`:
58
+ // price is canonical `Money` (decimal major-unit string + currency code); an
59
+ // unresolved price is an empty Money (the card renders an unavailable state,
60
+ // never a zero); optional evidence (rating, badge) renders only when supplied.
61
+ export const productPresentationSchema = z.object({
33
62
  id: z.union([z.string(), z.number()]),
34
63
  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(),
64
+ image: z.string().optional(),
65
+ imageAlt: z.string().optional(),
66
+ href: z.string().optional(),
67
+ price: z.object({ amount: z.string(), currencyCode: z.string() }),
68
+ compareAtPrice: z.object({ amount: z.string(), currencyCode: z.string() }).optional(),
69
+ rating: z.number().optional(),
40
70
  badge: z.string().optional(),
41
71
  })
42
72
 
73
+ // Mirrors the canonical page-level `Navbar` contract. Presentation is bounded to
74
+ // `bar`/`mega`/`floating`; the cart and account affordances belong to the
75
+ // `StorefrontNavbar` shell below, so no cart prop exists here.
43
76
  export const navbarPropsSchema = z.object({
44
- navLinks: z.array(navLinkSchema),
77
+ presentation: z.enum(['bar', 'mega', 'floating']).optional(),
45
78
  logoText: z.string(),
46
79
  logoHref: z.string().optional(),
47
80
  currentPath: z.string().optional(),
81
+ links: z.array(navbarLinkSchema),
82
+ featured: navbarFeaturedSchema.optional(),
48
83
  signIn: ctaSchema.optional(),
49
84
  cta: ctaSchema.optional(),
50
- cartCount: z.number().optional(),
85
+ className: z.string().optional(),
51
86
  })
52
87
 
53
88
  // Mirrors the StorefrontNavbar block contract in this scaffold. `storeCategories`
@@ -60,14 +95,35 @@ export const navCategorySchema = z.object({
60
95
  emphasis: z.boolean().optional(),
61
96
  })
62
97
 
63
- // 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.
98
+ // Optional brand seam mirroring the Navbar4 / FooterSection accent props and
99
+ // the StorefrontHero editorial image. Declared locally (see
100
+ // productPresentationSchema) so the scaffold's zod version is the only one in
101
+ // play.
66
102
  export const shellAccentSchema = z.object({
67
103
  text: z.string(),
68
104
  className: z.string().optional(),
69
105
  })
70
106
 
107
+ // Account chrome data mirrors, declared locally (see productPresentationSchema)
108
+ // so the scaffold's zod version is the only one in play. They mirror the
109
+ // `@thorprovider/blocks` `StoreUser` / `AccountMenuItem` contracts the navbar
110
+ // account menu renders. Callbacks (`onSignOut`, `onHelp`, `onAccountRetry`) are
111
+ // deliberately ABSENT: they are consumer bindings, not serializable props, so a
112
+ // spec/JSON payload can never carry a function.
113
+ export const storeUserSchema = z.object({
114
+ name: z.string(),
115
+ email: z.string(),
116
+ avatar: z.string().optional(),
117
+ initials: z.string(),
118
+ })
119
+
120
+ export const accountMenuItemSchema = z.object({
121
+ label: z.string(),
122
+ href: z.string(),
123
+ description: z.string().optional(),
124
+ icon: z.enum(['orders', 'wishlist', 'addresses', 'settings']).optional(),
125
+ })
126
+
71
127
  export const storefrontNavbarPropsSchema = z.object({
72
128
  storeCategories: z.array(navCategorySchema),
73
129
  shippingNote: z.string().optional(),
@@ -77,6 +133,13 @@ export const storefrontNavbarPropsSchema = z.object({
77
133
  logoAccent: shellAccentSchema.optional(),
78
134
  className: z.string().optional(),
79
135
  accountHref: z.string().optional(),
136
+ // Signed-in identity, account links, and account feedback states, derived from
137
+ // the shared session by the registry when customer-auth is mounted. All
138
+ // optional so a fresh or older user-owned shell without them still parses.
139
+ user: storeUserSchema.optional(),
140
+ accountMenuItems: z.array(accountMenuItemSchema).optional(),
141
+ accountPending: z.boolean().optional(),
142
+ accountUnavailable: z.boolean().optional(),
80
143
  // Held global search (E2 task 5.4): the generated shell opts out of the
81
144
  // navbar search control while no verified global search contract exists.
82
145
  showSearch: z.boolean().optional(),
@@ -90,10 +153,15 @@ export const bannerPropsSchema = z.object({
90
153
  avatars: z.array(z.string()).optional(),
91
154
  })
92
155
 
93
- export const productCardPropsSchema = z.object({
94
- products: z.array(shellProductSchema),
156
+ export const productGridPropsSchema = z.object({
157
+ items: z.array(productPresentationSchema),
158
+ presentation: z.enum(['classic', 'minimal', 'rich']).optional(),
95
159
  heading: z.string().optional(),
96
- maxItems: z.number().optional(),
160
+ maxItems: z.number().int().positive().optional(),
161
+ wishlistedIds: z.array(z.union([z.string(), z.number()])).readonly().optional(),
162
+ loading: z.boolean().optional(),
163
+ skeletonCount: z.number().int().positive().optional(),
164
+ emptyLabel: z.string().optional(),
97
165
  })
98
166
 
99
167
  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. */
@@ -24,7 +24,7 @@ export const navbarShellProps = {
24
24
  // Global navigation search is held until a verified backend search contract
25
25
  // exists (E2 task 5.4), so the generated storefront presents NO search
26
26
  // control. A merchant may set this to `true` to opt in once the contract is
27
- // verified; the `Navbar4` block still defaults to visible for legacy
27
+ // verified; the `StorefrontNavbar` block still defaults to visible for legacy
28
28
  // consumers that do not set this prop.
29
29
  showSearch: false,
30
30
  }
@@ -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: {