@thorprovider/storefront 0.15.0 → 0.15.2

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 (28) hide show
  1. package/README.md +9 -4
  2. package/assets/templates/app/app/[[...slug]]/page.tsx +22 -4
  3. package/assets/templates/app/app/layout.tsx +2 -2
  4. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +11 -4
  5. package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +7 -4
  6. package/assets/templates/app/lib/__STOREFRONT__/header-universal.ts +363 -0
  7. package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +49 -1
  8. package/assets/templates/app/lib/__STOREFRONT__/schema.ts +52 -0
  9. package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +43 -0
  10. package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +4 -0
  11. package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +16 -43
  12. package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +8 -0
  13. package/assets/templates/app/lib/__STOREFRONT__/store-context.ts +84 -18
  14. package/assets/templates/app/lib/__STOREFRONT__/views/sections/header-universal.client.tsx +33 -0
  15. package/assets/templates/app/lib/__STOREFRONT__/views/sections/header-universal.tsx +16 -0
  16. package/assets/templates/app/lib/__STOREFRONT__/views/sections/index.ts +2 -1
  17. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.header-universal.ts +360 -0
  18. package/assets/templates/views/cart/registry.tsx +9 -0
  19. package/assets/templates/views/checkout/checkout-commerce-hosted.tsx +5 -1
  20. package/package.json +1 -1
  21. package/recipes/sections.json +18 -0
  22. package/scripts/candidate.mjs +2 -2
  23. package/scripts/env-file.mjs +5 -0
  24. package/scripts/file-classes.mjs +7 -2
  25. package/skills/sf-view-gen/assets/recipes/sections.json +18 -0
  26. package/skills/sf-view-gen/assets/templates/views/sections/header-universal.client.tsx +33 -0
  27. package/skills/sf-view-gen/assets/templates/views/sections/header-universal.tsx +16 -0
  28. package/skills/sf-view-gen/assets/templates/views/sections/schema.header-universal.ts +360 -0
package/README.md CHANGED
@@ -196,10 +196,15 @@ scopes the store, `MEDUSA_REGION_ID` supplies currency, countries, and shipping,
196
196
 
197
197
  `THOR_DATA_SOURCE` selects the mode **explicitly** and is never inferred from a failure.
198
198
  `mock` renders labelled demo data and resolves a fixture store context in code (channel
199
- `mock-sales-channel`, region `mock-region-us`, currency `USD`), so no context variables
200
- are required. `medusa` uses the real backend: a missing provider or invalid config is a
201
- **visible error** — never a silent fallback to demo data. Run `storefront setup`, then
202
- restart `yarn dev`.
199
+ `mock-sales-channel`, region `mock-region-uy`, currency `UYU`, locale `es-UY`), so no
200
+ context variables are required. `medusa` uses the real backend: a missing provider or
201
+ invalid config is a **visible error** — never a silent fallback to demo data. Run
202
+ `storefront setup`, then restart `yarn dev`.
203
+
204
+ `THOR_STORE_LOCALE` (BCP-47, e.g. `es-UY`) is the store's single shopper locale: it
205
+ governs `<html lang>` and every monetary surface — cart, cart sheet, checkout summary
206
+ and order confirmation all format with it. Optional; unset or blank falls back to
207
+ `es-UY`, matching the mock Uruguay region.
203
208
 
204
209
  ### Feature capability gating
205
210
 
@@ -3,11 +3,14 @@
3
3
  import { notFound } from 'next/navigation'
4
4
  import { buildBreadcrumbListJsonLd, serializeJsonLd } from '@thorprovider/runtime/contracts'
5
5
  import { getCatalog } from '@thorprovider/runtime/commerce'
6
+ import type { UniversalMainMenuData } from '@thorprovider/blocks'
6
7
  import { __STOREFRONT_CAMEL__App } from '@/lib/__STOREFRONT__/runtime'
8
+ import { buildDemoHeaderMenu, buildHeaderMenu } from '@/lib/__STOREFRONT__/header-universal'
7
9
  import { readCartStateForRender } from '@/lib/__STOREFRONT__/cart-state'
8
10
  import { readAccountSession } from '@/lib/__STOREFRONT__/account-session'
9
11
  import { toAccountInitialState } from '@/lib/__STOREFRONT__/account-session.core'
10
12
  import { mountedFeatureNames, backendCapabilities } from '@/lib/__STOREFRONT__/composition'
13
+ import { getStoreLocale } from '@/lib/__STOREFRONT__/store-context'
11
14
  import { StorefrontRenderer } from './renderer'
12
15
 
13
16
  export const { generateMetadata, generateStaticParams } = __STOREFRONT_CAMEL__App
@@ -24,15 +27,25 @@ export default async function Page({
24
27
  const data = await __STOREFRONT_CAMEL__App.getPageData({ params, searchParams })
25
28
  if (!data) return notFound()
26
29
 
27
- // The shared shell is rendered for every route, so resolve its category links
28
- // here rather than relying on a particular view loader. `getCatalog()` is
30
+ // The shared shell is rendered for every route, so resolve its navigation here
31
+ // rather than relying on a particular view loader. `getCatalog()` is
29
32
  // request-cached by the commerce bridge and is shared with the view loader.
33
+ // The header's menu is the storefront's real catalog taxonomy for a LIVE
34
+ // catalog; without one (mock or no backend) it is the design-B demo taxonomy.
35
+ // The legacy `navCategories` flat list is kept for consumers that still read
36
+ // it.
30
37
  let navCategories: { label: string; href: string }[] = []
38
+ let headerMenu: UniversalMainMenuData = buildDemoHeaderMenu()
31
39
  try {
32
- navCategories = (await getCatalog()).categories.map(({ label, href }) => ({ label, href }))
40
+ const catalog = await getCatalog()
41
+ navCategories = catalog.categories.map(({ label, href }) => ({ label, href }))
42
+ headerMenu =
43
+ catalog.source === 'medusa'
44
+ ? buildHeaderMenu(catalog.categoriesRaw ?? [])
45
+ : buildDemoHeaderMenu()
33
46
  } catch (error) {
34
47
  // A failed catalog read must not invent links or take down otherwise usable
35
- // page content; keep the shell empty and leave a diagnostic for operators.
48
+ // page content; keep the demo taxonomy and leave a diagnostic for operators.
36
49
  console.error('[storefront] Failed to resolve shared navigation categories', error)
37
50
  }
38
51
 
@@ -59,6 +72,11 @@ export default async function Page({
59
72
  const initialState = {
60
73
  ...(data.initialState ?? {}),
61
74
  navCategories,
75
+ // The shopper locale is resolved server-side (env-backed) and seeded for
76
+ // every route so the client registries build the same money formatter the
77
+ // shell's `<html lang>` uses. `getStoreLocale` never throws, so a
78
+ // misconfigured context still renders its visible cart/config error.
79
+ storeLocale: getStoreLocale(),
62
80
  ...cartState,
63
81
  ...accountState,
64
82
  }
@@ -5,7 +5,7 @@ import { Geist } from 'next/font/google'
5
5
  import { ThemeProvider } from 'next-themes'
6
6
  import { StorefrontProvider } from '@thorprovider/runtime/host-glue/providers'
7
7
  import { registry } from '@/lib/__STOREFRONT__/registry'
8
- import { getSiteUrl } from '@/lib/__STOREFRONT__/store-context'
8
+ import { getSiteUrl, getStoreLocale } from '@/lib/__STOREFRONT__/store-context'
9
9
  import './globals.css'
10
10
 
11
11
  const geist = Geist({
@@ -32,7 +32,7 @@ export default function RootLayout({
32
32
  children,
33
33
  }: Readonly<{ children: React.ReactNode }>) {
34
34
  return (
35
- <html lang="es" className={geist.variable} suppressHydrationWarning>
35
+ <html lang={getStoreLocale()} className={geist.variable} suppressHydrationWarning>
36
36
  <body className="font-sans antialiased">
37
37
  <ThemeProvider attribute="class" defaultTheme="__STOREFRONT_MODE__" enableSystem>
38
38
  <StorefrontProvider registry={registry}>
@@ -99,7 +99,7 @@ import type {
99
99
  StorefrontOrder,
100
100
  StorefrontOrderLineView,
101
101
  } from './state.core'
102
- import { assertBackendConfigured, getDataSource, getStoreContext, type StoreDataSource } from './store-context'
102
+ import { assertBackendConfigured, getDataSource, getStoreContext, getStoreLocale, type StoreDataSource } from './store-context'
103
103
  // The query engine is imported through its server-safe subpath: the package
104
104
  // root is a client entry (`'use client'`), so a Server Action cannot call a
105
105
  // function exported from it (React refuses a client function on the server).
@@ -294,14 +294,21 @@ export function toCheckoutFieldErrors(errors: CheckoutFieldError[]): CheckoutFie
294
294
  return grouped
295
295
  }
296
296
 
297
- /** Map the runtime's discriminated completion to the host result union. */
298
- export function toPlaceOrderResult(result: CartCompletionResult): PlaceOrderResult {
297
+ /**
298
+ * Map the runtime's discriminated completion to the host result union. The
299
+ * confirmation carries the store's shopper locale; callers may pass it
300
+ * explicitly, otherwise it resolves from the host environment (server-side).
301
+ */
302
+ export function toPlaceOrderResult(
303
+ result: CartCompletionResult,
304
+ locale: string = getStoreLocale(),
305
+ ): PlaceOrderResult {
299
306
  if (result.type === 'order') {
300
307
  return {
301
308
  status: 'order',
302
309
  order: toStorefrontOrder(result.order),
303
310
  lines: toOrderLines(result.order),
304
- confirmation: toStorefrontConfirmation(result.order),
311
+ confirmation: toStorefrontConfirmation(result.order, locale),
305
312
  ...(result.paymentSummary ? { paymentSummary: result.paymentSummary } : {}),
306
313
  }
307
314
  }
@@ -122,8 +122,11 @@ function normalizeImageUrl(url: string | null | undefined): string | undefined {
122
122
  * Build the designer confirmation from the host-confirmed order. The order is
123
123
  * the single source: addresses, delivery method, payment label and totals are
124
124
  * only included when the backend reports them; the view omits what is absent.
125
+ * The caller supplies the store's shopper locale so the confirmation formats
126
+ * money identically to the cart and checkout (design D4) — never a hardcoded
127
+ * presentation locale.
125
128
  */
126
- export function toStorefrontConfirmation(order: Order): StorefrontConfirmation {
129
+ export function toStorefrontConfirmation(order: Order, locale: string): StorefrontConfirmation {
127
130
  const shippingAddress = order.shippingAddress
128
131
  const recipient = shippingAddress
129
132
  ? `${shippingAddress.firstName} ${shippingAddress.lastName}`.trim()
@@ -267,9 +270,9 @@ export function toStorefrontConfirmation(order: Order): StorefrontConfirmation {
267
270
  billingDetail: billing ? addressDetail(billing) : '',
268
271
  customerName,
269
272
  customerEmail: order.email,
270
- // The storefront's money presentation uses the design's en-US dollar
271
- // format; copy stays in the store language.
272
- locale: 'en-US',
273
+ // The store's shopper locale, supplied by the host from the store context;
274
+ // copy stays in the store language.
275
+ locale,
273
276
  currencyCode: order.total.currencyCode,
274
277
  }
275
278
  }
@@ -0,0 +1,363 @@
1
+ // Thor Commerce shell data: the universal header's authored config and the
2
+ // menu builder that turns the storefront's own catalog taxonomy into the
3
+ // header's navigation.
4
+ //
5
+ // Derived (package-owned): regenerate on `storefront sync`. The header's menu
6
+ // IS the universal main menu — there is no horizontal category strip and no
7
+ // separate mega menu.
8
+ //
9
+ // Two navigation sources, one seam:
10
+ // - `buildHeaderMenu` maps the provider's real `ProductCategory[]` taxonomy
11
+ // (id/name/handle/description/productCount/image + parentCategoryId) to a
12
+ // `UniversalMainMenuData`, so hrefs are the storefront's real
13
+ // `/categories/<handle>` routes and images/counts are whatever the backend
14
+ // supplies. This is the live-catalog path and is preferred when a live
15
+ // (Medusa) catalog is present.
16
+ // - `buildDemoHeaderMenu` is a clearly-labelled DEMO taxonomy — the design-B
17
+ // delivery demo — used when no live catalog is present. Its categories reuse
18
+ // the starter's real catalog handles as hrefs (never `#`) and are enriched to
19
+ // the full menu shape (children, badges, counts, descriptions, the season
20
+ // promotion card and the demo labels).
21
+
22
+ import { createDefaultConfig } from '@thorprovider/blocks/blocks/designs/header-universal/contracts'
23
+ import type {
24
+ HeaderConfig,
25
+ HeaderContext,
26
+ HeaderModule,
27
+ } from '@thorprovider/blocks/blocks/designs/header-universal/contracts'
28
+ import type { UniversalMainMenuData, UniversalMainMenuItem } from '@thorprovider/blocks'
29
+ import type { ProductCategory } from '@thorprovider/types'
30
+
31
+ /**
32
+ * The starter header. The demo feeds the commerce surface the starter can
33
+ * honestly render: the announcement, the search field, the account/wishlist/
34
+ * cart accesses and the main menu. The horizontal category strip (`navigation`)
35
+ * and the region/language/support accesses stay off — the starter feeds no data
36
+ * for them, and the support module's default `/help` action is a route the
37
+ * scaffold does not serve.
38
+ */
39
+ export function createStorefrontHeaderConfig(): HeaderConfig {
40
+ const base = createDefaultConfig()
41
+
42
+ // Keep the demo surface and drop the host-optional modules the starter does
43
+ // not use (the `navigation` strip, region/language/support, and every other
44
+ // preset module).
45
+ const kept = new Set([
46
+ 'announcement',
47
+ 'logo',
48
+ 'main-menu',
49
+ 'search',
50
+ 'account',
51
+ 'cart',
52
+ ])
53
+ const wishlistModule: HeaderModule = {
54
+ id: 'wishlist',
55
+ type: 'wishlist',
56
+ enabled: true,
57
+ requires: 'saved-items',
58
+ props: { showCount: true },
59
+ // The starter has no dedicated wishlist route; the icon navigates to the
60
+ // account surface where saved items live.
61
+ actions: { click: { name: 'navigate', payload: { href: '/account' } } },
62
+ }
63
+ const modules = [
64
+ ...base.modules
65
+ .filter((module) => kept.has(module.id))
66
+ .map((module) => {
67
+ if (module.id !== 'search') return module
68
+ // The demo search is always a bar (never the icon fallback): the block
69
+ // measures its container client-side, so the server render would
70
+ // otherwise fall back to the base-breakpoint icon and the search field
71
+ // copy would never appear in the SSR HTML.
72
+ return { ...module, responsive: undefined }
73
+ }),
74
+ wishlistModule,
75
+ ]
76
+
77
+ const layout = base.layout.map((row) => {
78
+ if (row.id === 'main') {
79
+ return {
80
+ ...row,
81
+ zones: {
82
+ start: ['logo', 'main-menu'],
83
+ center: ['search'],
84
+ end: ['account', 'wishlist', 'cart'],
85
+ },
86
+ }
87
+ }
88
+ if (row.id === 'utility') {
89
+ // Only the announcement; region/language/support are removed above.
90
+ return { ...row, zones: { start: ['announcement'], center: [], end: [] } }
91
+ }
92
+ return row
93
+ })
94
+
95
+ return {
96
+ ...base,
97
+ // The shell `Layout` already wraps the header slot in a sticky `<header>`,
98
+ // so the block itself stays static rather than stacking another sticky.
99
+ behavior: { ...base.behavior, position: 'static' },
100
+ layout,
101
+ modules,
102
+ // The demo feeds every capability the enriched modules require.
103
+ capabilities: {
104
+ catalog: true,
105
+ 'catalog-search': true,
106
+ checkout: true,
107
+ 'customer-account': true,
108
+ 'saved-items': true,
109
+ },
110
+ visibilityRules: [],
111
+ }
112
+ }
113
+
114
+ /** Per-module copy the header block reads through `labels[module.type]`. */
115
+ export const storefrontHeaderLabels: Record<string, Record<string, string>> = {
116
+ logo: { home: 'Inicio' },
117
+ 'main-menu': { triggerLabel: 'Menú' },
118
+ search: {
119
+ label: 'Buscar',
120
+ placeholder: 'Buscar productos, marcas o SKU',
121
+ submit: 'Buscar',
122
+ },
123
+ cart: { label: 'Carrito' },
124
+ account: { account: 'Cuenta' },
125
+ wishlist: { label: 'Favoritos' },
126
+ announcement: { link: 'Ver más' },
127
+ }
128
+
129
+ /** The live-catalog menu labels: the trigger is `Menú`, the rest are required. */
130
+ const HEADER_MENU_LABELS: UniversalMainMenuData['labels'] = {
131
+ menuTrigger: 'Menú',
132
+ menuTitle: 'Categorías',
133
+ close: 'Cerrar menú',
134
+ back: 'Volver',
135
+ openSubmenu: 'Abrir {name}',
136
+ viewAll: 'Ver todo {name}',
137
+ productCount: '{count} productos',
138
+ productCountOne: '1 producto',
139
+ featured: 'Destacado',
140
+ empty: 'No hay categorías disponibles',
141
+ emptyHint: 'El catálogo se está actualizando.',
142
+ panelLabel: 'Menú de {name}',
143
+ railLabel: 'Categorías',
144
+ levelLabel: 'Nivel {level}',
145
+ noImage: 'Sin imagen',
146
+ }
147
+
148
+ /** The demo labels: identical to the live set except the design-B menu title. */
149
+ const DEMO_MENU_LABELS: UniversalMainMenuData['labels'] = {
150
+ ...HEADER_MENU_LABELS,
151
+ menuTitle: 'Todo empieza aquí',
152
+ }
153
+
154
+ /**
155
+ * The shared menu config: hybrid layout, container-anchored panel, light ghost
156
+ * trigger. Both the live taxonomy and the demo taxonomy render identically.
157
+ */
158
+ function buildMenuConfig(): UniversalMainMenuData['config'] {
159
+ return {
160
+ layouts: {
161
+ default: 'hybrid',
162
+ desktop: 'hybrid',
163
+ mobile: 'hybrid',
164
+ bindings: {},
165
+ options: {},
166
+ },
167
+ behavior: {
168
+ platform: 'auto',
169
+ anchor: 'container',
170
+ trigger: 'ghost',
171
+ mobilePattern: 'drill-down',
172
+ openOnHover: true,
173
+ openDelayMs: 200,
174
+ closeDelayMs: 160,
175
+ direction: 'auto',
176
+ },
177
+ transition: {
178
+ panel: 'slide',
179
+ level: 'fade',
180
+ duration: 'base',
181
+ respectReducedMotion: true,
182
+ },
183
+ }
184
+ }
185
+
186
+ function toMenuItem(category: ProductCategory): UniversalMainMenuItem {
187
+ return {
188
+ id: category.id,
189
+ label: category.name,
190
+ href: `/categories/${category.handle}`,
191
+ ...(category.description ? { description: category.description } : {}),
192
+ ...(category.image ? { image: { src: category.image, alt: category.name } } : {}),
193
+ ...(category.productCount !== undefined ? { count: category.productCount } : {}),
194
+ }
195
+ }
196
+
197
+ /** Build the recursive menu tree from the provider's flat taxonomy. */
198
+ function buildTree(categories: ProductCategory[]): UniversalMainMenuItem[] {
199
+ const byParent = new Map<string | undefined, ProductCategory[]>()
200
+ for (const category of categories) {
201
+ const list = byParent.get(category.parentCategoryId)
202
+ if (list) list.push(category)
203
+ else byParent.set(category.parentCategoryId, [category])
204
+ }
205
+ const build = (parentId: string | undefined): UniversalMainMenuItem[] =>
206
+ (byParent.get(parentId) ?? []).map((category) => {
207
+ const children = build(category.id)
208
+ return {
209
+ ...toMenuItem(category),
210
+ ...(children.length > 0 ? { children } : {}),
211
+ }
212
+ })
213
+ return build(undefined)
214
+ }
215
+
216
+ /**
217
+ * The header's LIVE navigation source: a `UniversalMainMenuData` whose
218
+ * categories are the storefront's real catalog taxonomy. The panel is
219
+ * container-anchored and the trigger is the light ghost control.
220
+ */
221
+ export function buildHeaderMenu(categories: ProductCategory[]): UniversalMainMenuData {
222
+ return {
223
+ categories: buildTree(categories),
224
+ config: buildMenuConfig(),
225
+ labels: HEADER_MENU_LABELS,
226
+ }
227
+ }
228
+
229
+ /**
230
+ * The design-B delivery demo taxonomy. Demo-only: the starter's real catalog
231
+ * handles are reused as hrefs so every link resolves to a real route (never
232
+ * `#`), while the menu is enriched to the full shape the designer delivered —
233
+ * children (a featured grid), badges (`Nuevo`, `-30%`), counts, descriptions,
234
+ * the season promotion card and the demo labels. Fed only when no live catalog
235
+ * is present.
236
+ */
237
+ const DEMO_MENU_CATEGORIES: UniversalMainMenuItem[] = [
238
+ {
239
+ id: 'demo-jackets',
240
+ label: 'Jackets',
241
+ href: '/categories/jackets',
242
+ description: 'Outerwear and layering pieces.',
243
+ count: 12,
244
+ badge: { label: 'Nuevo', tone: 'accent' },
245
+ children: [
246
+ { id: 'demo-jackets-quilted', label: 'Quilted', href: '/categories/jackets', count: 6 },
247
+ { id: 'demo-jackets-coats', label: 'Coats', href: '/categories/dresses', count: 4 },
248
+ { id: 'demo-jackets-layers', label: 'Light layers', href: '/categories/accessories', count: 2 },
249
+ ],
250
+ },
251
+ {
252
+ id: 'demo-dresses',
253
+ label: 'Dresses',
254
+ href: '/categories/dresses',
255
+ description: 'Editorial silhouettes for seasonal collections.',
256
+ count: 9,
257
+ },
258
+ {
259
+ id: 'demo-home',
260
+ label: 'Home',
261
+ href: '/categories/home',
262
+ description: 'Decor and living objects for lifestyle layouts.',
263
+ count: 14,
264
+ },
265
+ {
266
+ id: 'demo-accessories',
267
+ label: 'Accessories',
268
+ href: '/categories/accessories',
269
+ description: 'Complementary products for cart and bundle flows.',
270
+ count: 7,
271
+ },
272
+ {
273
+ id: 'demo-furniture',
274
+ label: 'Furniture',
275
+ href: '/categories/furniture',
276
+ description: 'Statement pieces for the home, including oversized and fragile deliveries.',
277
+ count: 5,
278
+ badge: { label: '-30%', tone: 'promo' },
279
+ },
280
+ ]
281
+
282
+ /** The design-B season promotion card (demo copy). */
283
+ const DEMO_PROMOTION: UniversalMainMenuData['promotion'] = {
284
+ id: 'demo-promo-invierno',
285
+ eyebrow: 'COLECCIÓN DE INVIERNO',
286
+ title: 'Textiles que abrigan la casa',
287
+ description: 'Lana virgen y lino lavado, tejidos en talleres locales.',
288
+ href: '/categories/home',
289
+ ctaLabel: 'Ver la colección',
290
+ }
291
+
292
+ /**
293
+ * The header's DEMO navigation source: the full design-B taxonomy. The panel is
294
+ * open in the first paint so the designer sees the rail, the featured grid and
295
+ * the promotion card without a click.
296
+ */
297
+ export function buildDemoHeaderMenu(): UniversalMainMenuData {
298
+ return {
299
+ categories: DEMO_MENU_CATEGORIES,
300
+ config: buildMenuConfig(),
301
+ labels: DEMO_MENU_LABELS,
302
+ promotion: DEMO_PROMOTION,
303
+ preview: { defaultOpen: true },
304
+ }
305
+ }
306
+
307
+ /**
308
+ * The runtime context the shell feeds the header. This is the clearly-labelled
309
+ * DEMO state: the announcement, cart badge (3), wishlist count (4) and account
310
+ * access are demo copy fed so the full design-B header renders in the starter —
311
+ * never a real commerce read. Region/language stay empty (their modules are
312
+ * removed from the config, so nothing reads them). The live catalog/menu seam
313
+ * is the `menu` argument (built by the host from the real taxonomy or the demo
314
+ * taxonomy above).
315
+ */
316
+ export function buildHeaderContext(
317
+ siteName: string,
318
+ menu?: UniversalMainMenuData,
319
+ accent?: string,
320
+ ): HeaderContext {
321
+ return {
322
+ brand: { name: siteName, href: '/', ...(accent ? { accent } : {}) },
323
+ menu,
324
+ cart: {
325
+ state: 'ready',
326
+ // Demo badge count only: no real cart lines are fabricated.
327
+ lines: [],
328
+ quantity: 3,
329
+ lineCount: 0,
330
+ currency: 'EUR',
331
+ shippingGroups: 0,
332
+ subtotalUnavailableLabel: 'Envío calculado al finalizar la compra',
333
+ promotions: [],
334
+ },
335
+ account: { state: 'guest', menu: [] },
336
+ wishlist: { count: 4, lists: 1 },
337
+ regions: { activeId: '', options: [] },
338
+ languages: { activeCode: '', options: [] },
339
+ locations: { enabled: false, options: [] },
340
+ announcements: [
341
+ {
342
+ id: 'demo-free-shipping',
343
+ message: 'Envío gratis desde 250 EUR',
344
+ href: '/categories',
345
+ linkLabel: 'Ver más',
346
+ tone: 'accent',
347
+ dismissible: false,
348
+ },
349
+ ],
350
+ notifications: { available: false, unread: 0, items: [] },
351
+ openComponents: [],
352
+ now: new Date().toISOString(),
353
+ capabilities: {
354
+ catalog: true,
355
+ 'catalog-search': true,
356
+ checkout: true,
357
+ 'customer-account': true,
358
+ 'saved-items': true,
359
+ },
360
+ context: 'guest',
361
+ page: 'home',
362
+ }
363
+ }
@@ -10,13 +10,14 @@
10
10
  // navigates to the detail, where a variant is chosen explicitly.
11
11
 
12
12
  import { defineRegistry, useStateStore } from '@json-render/react'
13
+ import { useNextApp } from '@json-render/next'
13
14
  import { useEffect } from 'react'
14
15
  import { usePathname } from 'next/navigation'
15
16
  import { BackToTop as BackToTopBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
16
17
  import { MobileBottomNav as MobileBottomNavBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
17
18
  import { SkipToContent as SkipToContentBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/skip-to-content'
18
19
  import Banner1 from '@thorprovider/blocks/blocks/marketing/banners/banner-1'
19
- import { Navbar, StorefrontNavbar, UniversalFooter } from '@thorprovider/blocks'
20
+ import { HeaderUniversal, Navbar, StorefrontNavbar, UniversalFooter } from '@thorprovider/blocks'
20
21
  import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
21
22
  import type { BackToTopProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
22
23
  import type { MobileBottomNavProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
@@ -25,10 +26,12 @@ import { isAvailableMoney } from '@thorprovider/blocks/contracts'
25
26
  import type { Money } from '@thorprovider/types'
26
27
  import { catalog } from './catalog'
27
28
  import type { CartLineState, CartTotalsState } from './state'
29
+ import { createStoreMoneyFormatter, DEFAULT_STORE_LOCALE } from './store-context'
28
30
  import { useStorefrontHandlers } from './handlers'
29
31
  import { cartViewAvailable, checkoutAvailable, mountedFeatureNames } from './composition'
30
32
  import { accountStoreUser } from './account-user.core'
31
33
  import { toUniversalFooterProps } from './footer-content'
34
+ import { buildHeaderContext, createStorefrontHeaderConfig, storefrontHeaderLabels } from './header-universal'
32
35
  import type { AccountIdentity, AccountResolution } from './account-session.core'
33
36
  import {
34
37
  bannerPropsSchema,
@@ -36,6 +39,7 @@ import {
36
39
  navbarPropsSchema,
37
40
  productGridPropsSchema,
38
41
  storefrontNavbarPropsSchema,
42
+ universalHeaderShellPropsSchema,
39
43
  } from './schema'
40
44
  import { viewRegistries } from './views/registry'
41
45
 
@@ -165,6 +169,14 @@ const baseComponents = {
165
169
  ) as AccountResolution | 'unresolved'
166
170
  const cart = (state.cart ?? []) as CartLineState[]
167
171
  const totals = state.cartTotals as CartTotalsState | null
172
+ // One money formatter for the whole shell, built from the shopper locale
173
+ // the catch-all host seeded (the same locale as `<html lang>`). The navbar
174
+ // forwards it to the cart sheet, so every chrome money surface agrees.
175
+ const storeLocale =
176
+ typeof state.storeLocale === 'string' && state.storeLocale.trim() !== ''
177
+ ? state.storeLocale
178
+ : DEFAULT_STORE_LOCALE
179
+ const formatMoney = createStoreMoneyFormatter(storeLocale)
168
180
  const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
169
181
  const readError = typeof state.cartReadError === 'string' ? state.cartReadError : undefined
170
182
  const errorLabel = cartError ?? readError
@@ -186,6 +198,9 @@ const baseComponents = {
186
198
  logoHref={parsed.logoHref}
187
199
  logoAccent={parsed.logoAccent}
188
200
  className={parsed.className}
201
+ // Chrome copy in the store language, authored in the user-owned shell
202
+ // (`shell/content.ts`); omitted fields keep the block's English default.
203
+ labels={parsed.labels}
189
204
  accountHref={parsed.accountHref}
190
205
  // Signed-in identity + account feedback, only while customer-auth is
191
206
  // mounted. `user` is mapped from the shared allowlisted identity; the
@@ -215,6 +230,7 @@ const baseComponents = {
215
230
  showSearch={parsed.showSearch ?? false}
216
231
  items={toNavCartItems(cart)}
217
232
  subtotal={totals?.subtotal}
233
+ formatMoney={formatMoney}
218
234
  // One shared lateral: visibility is driven by the shared `cartOpen`
219
235
  // state (a successful add opens it; navigation dismisses it). The
220
236
  // canonical line amounts and lifecycle states come from the same cart
@@ -241,6 +257,37 @@ const baseComponents = {
241
257
  />
242
258
  )
243
259
  },
260
+ HeaderUniversal: ({ props }: { props: Record<string, unknown> }) => {
261
+ const parsed = universalHeaderShellPropsSchema.parse(props)
262
+ const { navigate } = useNextApp()
263
+ const config = createStorefrontHeaderConfig()
264
+ const context = buildHeaderContext(
265
+ parsed.siteName,
266
+ parsed.menu,
267
+ parsed.logoAccent?.text.trim() || undefined,
268
+ )
269
+ // The block prevents the default anchor navigation and emits `navigate`
270
+ // instead, so the host resolves it to client navigation (the logo and every
271
+ // menu destination). Any other action name is intentionally unhandled: the
272
+ // starter header has no cart/account/search surface.
273
+ const handleAction = (action: {
274
+ name: string
275
+ payload?: Record<string, string | number | boolean>
276
+ }) => {
277
+ if (action.name === 'navigate' && typeof action.payload?.href === 'string') {
278
+ navigate(action.payload.href)
279
+ }
280
+ }
281
+ return (
282
+ <HeaderUniversal
283
+ config={config}
284
+ context={context}
285
+ labels={storefrontHeaderLabels}
286
+ className={parsed.className}
287
+ onAction={handleAction}
288
+ />
289
+ )
290
+ },
244
291
  Banner: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
245
292
  const parsed = bannerPropsSchema.parse(props)
246
293
  const { set } = useStateStore()
@@ -251,6 +298,7 @@ const baseComponents = {
251
298
  href={parsed.href}
252
299
  linkLabel={parsed.linkLabel}
253
300
  avatars={parsed.avatars}
301
+ dismissLabel={parsed.dismissLabel}
254
302
  onDismiss={() => {
255
303
  set('/bannerDismissed', true)
256
304
  emit('dismissBanner')