@thorprovider/storefront 0.4.0-mvp.0 → 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 (225) hide show
  1. package/README.md +174 -156
  2. package/VENDOR.md +69 -0
  3. package/assets/openspec/config.yaml +38 -0
  4. package/assets/templates/AGENTS.md +76 -0
  5. package/assets/templates/app/app/[[...slug]]/page.tsx +56 -2
  6. package/assets/templates/app/app/[[...slug]]/renderer.tsx +44 -2
  7. package/assets/templates/app/app/globals.css +5 -8
  8. package/assets/templates/app/app/layout.tsx +1 -5
  9. package/assets/templates/app/app/robots.ts +9 -3
  10. package/assets/templates/app/app/sitemap.ts +64 -5
  11. package/assets/templates/app/lib/__STOREFRONT__/account-boundary.client.tsx +76 -0
  12. package/assets/templates/app/lib/__STOREFRONT__/account-lifecycle.client.tsx +461 -0
  13. package/assets/templates/app/lib/__STOREFRONT__/account-mutation.client.ts +46 -0
  14. package/assets/templates/app/lib/__STOREFRONT__/account-private.core.ts +103 -0
  15. package/assets/templates/app/lib/__STOREFRONT__/account-reconcile.client.ts +465 -0
  16. package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +177 -0
  17. package/assets/templates/app/lib/__STOREFRONT__/account-session.ts +44 -0
  18. package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +65 -0
  19. package/assets/templates/app/lib/__STOREFRONT__/actions.ts +135 -16
  20. package/assets/templates/app/lib/__STOREFRONT__/catalog.ts +19 -9
  21. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +61 -0
  22. package/assets/templates/app/lib/__STOREFRONT__/composition.ts +26 -0
  23. package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +36 -4
  24. package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +17 -18
  25. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +209 -0
  26. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.ts +247 -0
  27. package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +123 -62
  28. package/assets/templates/app/lib/__STOREFRONT__/runtime.ts +3 -0
  29. package/assets/templates/app/lib/__STOREFRONT__/schema.ts +78 -25
  30. package/assets/templates/app/lib/__STOREFRONT__/section-observation.ts +182 -0
  31. package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +128 -0
  32. package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +31 -7
  33. package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +4 -0
  34. package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +81 -26
  35. package/assets/templates/app/lib/__STOREFRONT__/spec/seo.ts +165 -0
  36. package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +4 -2
  37. package/assets/templates/app/lib/__STOREFRONT__/store-context.ts +26 -7
  38. package/assets/templates/app/lib/__STOREFRONT__/views/sections/cta.client.tsx +1 -1
  39. package/assets/templates/app/lib/__STOREFRONT__/views/sections/faq.client.tsx +1 -1
  40. package/assets/templates/app/lib/__STOREFRONT__/views/sections/index.ts +2 -1
  41. package/assets/templates/app/lib/__STOREFRONT__/views/sections/logoCloud.tsx +1 -1
  42. package/assets/templates/app/lib/__STOREFRONT__/views/sections/pricing.tsx +1 -1
  43. package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.client.tsx +100 -0
  44. package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.tsx +19 -0
  45. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +39 -0
  46. package/assets/templates/app/lib/__STOREFRONT__/views/sections/statistics.tsx +1 -1
  47. package/assets/templates/app/lib/__STOREFRONT__/views/sections/testimonials.tsx +1 -1
  48. package/assets/templates/features/checkout/handlers.ts +6 -0
  49. package/assets/templates/features/customer-auth/handlers.ts +19 -23
  50. package/assets/templates/features/customer-auth/state.ts +31 -1
  51. package/assets/templates/views/account/index.tsx +20 -8
  52. package/assets/templates/views/account/registry.tsx +294 -154
  53. package/assets/templates/views/account/schema.ts +1 -0
  54. package/assets/templates/views/cart/content.ts +11 -0
  55. package/assets/templates/views/cart/data.ts +23 -0
  56. package/assets/templates/views/cart/index.tsx +53 -0
  57. package/assets/templates/views/cart/props.ts +12 -0
  58. package/assets/templates/views/cart/registry.tsx +82 -0
  59. package/assets/templates/views/cart/schema.ts +52 -0
  60. package/assets/templates/views/category/assembly/assembly.json +2 -1
  61. package/assets/templates/views/category/assembly/index.skeleton.tsx +64 -6
  62. package/assets/templates/views/category/assembly/registry.skeleton.tsx +7 -6
  63. package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +5 -0
  64. package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/catalog.part +4 -0
  65. package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/element.part +7 -0
  66. package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/registry.part +18 -0
  67. package/assets/templates/views/category/index.tsx +76 -7
  68. package/assets/templates/views/category/props.ts +7 -0
  69. package/assets/templates/views/category/registry.tsx +25 -6
  70. package/assets/templates/views/category/schema.ts +13 -0
  71. package/assets/templates/views/checkout/registry.tsx +3 -5
  72. package/assets/templates/views/home/assembly/assembly.json +12 -3
  73. package/assets/templates/views/home/assembly/index.skeleton.tsx +24 -5
  74. package/assets/templates/views/home/assembly/registry.skeleton.tsx +4 -1
  75. package/assets/templates/views/home/assembly/slots/benefits/cards/binding.json +5 -0
  76. package/assets/templates/views/home/assembly/slots/benefits/cards/registry.part +17 -0
  77. package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
  78. package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → split}/registry.part +6 -2
  79. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/binding.json +5 -0
  80. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/catalog.part +8 -0
  81. package/assets/templates/views/home/assembly/slots/categories/{ProductCategory2 → CategoryGrid}/element.part +1 -1
  82. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/registry.part +31 -0
  83. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/binding.json +5 -0
  84. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/catalog.part +4 -0
  85. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/element.part +5 -0
  86. package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/registry.part +5 -3
  87. package/assets/templates/views/home/content.ts +22 -0
  88. package/assets/templates/views/home/data.ts +9 -0
  89. package/assets/templates/views/home/index.tsx +34 -11
  90. package/assets/templates/views/home/props.ts +1 -0
  91. package/assets/templates/views/home/registry.tsx +41 -17
  92. package/assets/templates/views/home/schema.ts +141 -24
  93. package/assets/templates/views/product/data.ts +5 -3
  94. package/assets/templates/views/product/index.tsx +49 -5
  95. package/assets/templates/views/product/props.ts +7 -0
  96. package/assets/templates/views/product/registry.tsx +34 -5
  97. package/assets/templates/views/product/schema.ts +49 -1
  98. package/assets/templates/views/static/content.ts +4 -4
  99. package/assets/templates/views/static/index.tsx +1 -1
  100. package/bin/storefront.js +1231 -154
  101. package/examples/merchandising/category-led.json +37 -0
  102. package/examples/merchandising/collection-led.json +37 -0
  103. package/package.json +10 -7
  104. package/recipes/archetypes.json +33 -46
  105. package/recipes/catalog.json +245 -153
  106. package/recipes/catalog.mjs +10 -0
  107. package/recipes/catalog.schema.json +4 -0
  108. package/recipes/features.json +28 -5
  109. package/recipes/recipe.schema.json +1 -1
  110. package/recipes/recipes.json +159 -59
  111. package/recipes/sections.json +10 -0
  112. package/recipes/validate.mjs +75 -4
  113. package/scripts/candidate.mjs +4 -4
  114. package/scripts/composers.mjs +25 -5
  115. package/scripts/env-file.mjs +86 -0
  116. package/scripts/file-classes.mjs +15 -0
  117. package/scripts/migrate-english-routes.mjs +276 -0
  118. package/scripts/ownership-conflict.mjs +5 -2
  119. package/scripts/pinning.mjs +74 -5
  120. package/scripts/plan-apply.mjs +149 -5
  121. package/scripts/reconcile.mjs +49 -11
  122. package/scripts/render-templates.mjs +97 -44
  123. package/scripts/section-config.mjs +253 -0
  124. package/scripts/starter.mjs +17 -0
  125. package/scripts/theme/color.mjs +185 -0
  126. package/scripts/theme/css-theme.mjs +233 -0
  127. package/scripts/theme/fonts.mjs +123 -0
  128. package/scripts/theme/import-export.mjs +125 -0
  129. package/scripts/theme/preset.mjs +93 -0
  130. package/scripts/theme/theme-plan.mjs +292 -0
  131. package/scripts/theme/tokens.mjs +137 -0
  132. package/scripts/view-assembly.mjs +57 -3
  133. package/scripts/view-selection.mjs +1 -1
  134. package/skills/sf-feature/SKILL.md +32 -19
  135. package/skills/sf-setup/SKILL.md +79 -0
  136. package/skills/sf-theme-gen/SKILL.md +99 -36
  137. package/skills/sf-theme-gen/references/shadcn-theming.md +87 -0
  138. package/skills/{shadcn-theming/references/templates → sf-theme-gen/references}/theme-setup.md +15 -19
  139. package/skills/{shadcn-theming → sf-theme-gen}/references/theming-guide.md +6 -11
  140. package/skills/sf-view-gen/SKILL.md +63 -40
  141. package/skills/sf-view-gen/assets/recipes/archetypes.json +33 -46
  142. package/skills/sf-view-gen/assets/recipes/catalog.json +245 -153
  143. package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
  144. package/skills/sf-view-gen/assets/recipes/features.json +28 -5
  145. package/skills/sf-view-gen/assets/recipes/recipes.json +159 -59
  146. package/skills/sf-view-gen/assets/recipes/sections.json +10 -0
  147. package/skills/sf-view-gen/assets/templates/views/sections/cta.client.tsx +1 -1
  148. package/skills/sf-view-gen/assets/templates/views/sections/faq.client.tsx +1 -1
  149. package/skills/sf-view-gen/assets/templates/views/sections/logoCloud.client.tsx +1 -1
  150. package/skills/sf-view-gen/assets/templates/views/sections/pricing.client.tsx +1 -1
  151. package/skills/sf-view-gen/assets/templates/views/sections/products.client.tsx +100 -0
  152. package/skills/sf-view-gen/assets/templates/views/sections/products.tsx +19 -0
  153. package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +39 -0
  154. package/skills/sf-view-gen/assets/templates/views/sections/statistics.client.tsx +1 -1
  155. package/skills/sf-view-gen/assets/templates/views/sections/testimonials.client.tsx +1 -1
  156. package/skills/{json-render-core/SKILL.md → sf-view-gen/references/json-render-core.md} +4 -27
  157. package/skills/{json-render-next/SKILL.md → sf-view-gen/references/json-render-next.md} +5 -8
  158. package/skills/{json-render-react/SKILL.md → sf-view-gen/references/json-render-react.md} +3 -5
  159. package/skills/{json-render-shadcn/SKILL.md → sf-view-gen/references/json-render-shadcn.md} +3 -5
  160. package/skills/sf-view-gen/references/views.md +28 -37
  161. package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
  162. package/skills/sf-view-gen/scripts/validate.mjs +75 -4
  163. package/skills/storefront-workflow/SKILL.md +94 -31
  164. package/skills/{storefront-best-practices/reference/design.md → storefront-workflow/references/design-consistency.md} +13 -29
  165. package/CHANGELOG.md +0 -84
  166. package/assets/templates/views/home/assembly/slots/benefits/Feature1/binding.json +0 -5
  167. package/assets/templates/views/home/assembly/slots/benefits/Feature2/binding.json +0 -5
  168. package/assets/templates/views/home/assembly/slots/benefits/Feature2/registry.part +0 -10
  169. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/binding.json +0 -5
  170. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/catalog.part +0 -4
  171. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/registry.part +0 -16
  172. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/binding.json +0 -5
  173. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/catalog.part +0 -4
  174. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/element.part +0 -5
  175. package/assets/templates/views/user-panel/index.tsx +0 -106
  176. package/assets/templates/views/user-panel/registry.tsx +0 -54
  177. package/assets/templates/views/user-panel/schema.ts +0 -79
  178. package/commands/sf-add-view.md +0 -57
  179. package/commands/sf-feature.md +0 -28
  180. package/commands/sf-theme.md +0 -26
  181. package/commands/sf-view.md +0 -67
  182. package/skills/building-storefronts/SKILL.md +0 -178
  183. package/skills/building-storefronts/references/frontend-integration.md +0 -229
  184. package/skills/json-render-remotion/SKILL.md +0 -111
  185. package/skills/json-render-solid/SKILL.md +0 -204
  186. package/skills/nextjs-shadcn/SKILL.md +0 -367
  187. package/skills/nextjs-shadcn/references/architecture.md +0 -499
  188. package/skills/nextjs-shadcn/references/project-setup.md +0 -162
  189. package/skills/nextjs-shadcn/references/shadcn-platform.md +0 -261
  190. package/skills/nextjs-shadcn/references/sidebar.md +0 -274
  191. package/skills/nextjs-shadcn/references/styling.md +0 -555
  192. package/skills/shadcn-component-discovery/SKILL.md +0 -273
  193. package/skills/shadcn-component-discovery/references/registries.md +0 -226
  194. package/skills/shadcn-theming/SKILL.md +0 -104
  195. package/skills/storefront-best-practices/SKILL.md +0 -421
  196. package/skills/storefront-best-practices/reference/components/breadcrumbs.md +0 -123
  197. package/skills/storefront-best-practices/reference/components/cart-popup.md +0 -189
  198. package/skills/storefront-best-practices/reference/components/country-selector.md +0 -298
  199. package/skills/storefront-best-practices/reference/components/footer.md +0 -112
  200. package/skills/storefront-best-practices/reference/components/hero.md +0 -241
  201. package/skills/storefront-best-practices/reference/components/megamenu.md +0 -239
  202. package/skills/storefront-best-practices/reference/components/navbar.md +0 -397
  203. package/skills/storefront-best-practices/reference/components/popups.md +0 -221
  204. package/skills/storefront-best-practices/reference/components/product-card.md +0 -125
  205. package/skills/storefront-best-practices/reference/components/product-reviews.md +0 -217
  206. package/skills/storefront-best-practices/reference/components/product-slider.md +0 -174
  207. package/skills/storefront-best-practices/reference/components/search.md +0 -101
  208. package/skills/storefront-best-practices/reference/connecting-to-backend.md +0 -391
  209. package/skills/storefront-best-practices/reference/features/promotions.md +0 -307
  210. package/skills/storefront-best-practices/reference/features/wishlist.md +0 -230
  211. package/skills/storefront-best-practices/reference/layouts/account.md +0 -380
  212. package/skills/storefront-best-practices/reference/layouts/cart.md +0 -316
  213. package/skills/storefront-best-practices/reference/layouts/checkout.md +0 -486
  214. package/skills/storefront-best-practices/reference/layouts/home-page.md +0 -264
  215. package/skills/storefront-best-practices/reference/layouts/order-confirmation.md +0 -231
  216. package/skills/storefront-best-practices/reference/layouts/product-details.md +0 -527
  217. package/skills/storefront-best-practices/reference/layouts/product-listing.md +0 -520
  218. package/skills/storefront-best-practices/reference/layouts/static-pages.md +0 -356
  219. package/skills/storefront-best-practices/reference/medusa.md +0 -307
  220. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/catalog.part +0 -0
  221. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/element.part +0 -0
  222. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/catalog.part +0 -0
  223. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/element.part +0 -0
  224. /package/skills/{storefront-best-practices/reference → storefront-workflow/references}/mobile-responsiveness.md +0 -0
  225. /package/skills/{storefront-best-practices/reference → storefront-workflow/references}/seo.md +0 -0
@@ -5,28 +5,37 @@
5
5
  //
6
6
  // The shell renders the live backend cart: the Navbar mini-cart and the cart
7
7
  // drawer read the authoritative cart state and dispatch cart mutations to the
8
- // Server Actions. Add-to-cart from a listing navigates to the product detail so
9
- // a variant is chosen explicitly (there is no first-variant shortcut).
8
+ // Server Actions. A listing card's add-to-cart adds the product's first
9
+ // purchasable variant (the card shortcut); opening a product from a listing
10
+ // navigates to the detail, where a variant is chosen explicitly.
10
11
 
11
12
  import { defineRegistry, useStateStore } from '@json-render/react'
12
- import {
13
- Banner1,
14
- FooterSection1,
15
- Navbar1,
16
- Navbar4,
17
- ProductCard1,
18
- ShoppingCart4,
19
- } from '@thorprovider/blocks'
13
+ import { useEffect } from 'react'
14
+ import { usePathname } from 'next/navigation'
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'
26
+ import { isAvailableMoney } from '@thorprovider/blocks/contracts'
27
+ import type { Money } from '@thorprovider/types'
20
28
  import { catalog } from './catalog'
21
29
  import type { CartLineState, CartTotalsState } from './state'
22
30
  import { useStorefrontHandlers } from './handlers'
23
- import { resolveIcon } from './icon-map'
31
+ import { cartViewAvailable, checkoutAvailable, mountedFeatureNames } from './composition'
32
+ import { accountStoreUser } from './account-user.core'
33
+ import type { AccountIdentity, AccountResolution } from './account-session.core'
24
34
  import {
25
35
  bannerPropsSchema,
26
- cartDrawerPropsSchema,
27
36
  footerPropsSchema,
28
37
  navbarPropsSchema,
29
- productCardPropsSchema,
38
+ productGridPropsSchema,
30
39
  storefrontNavbarPropsSchema,
31
40
  } from './schema'
32
41
  import { viewRegistries } from './views/registry'
@@ -40,10 +49,12 @@ interface NavCartItem {
40
49
  price: number
41
50
  qty: number
42
51
  image?: string
52
+ lineTotal?: Money
43
53
  }
44
54
 
45
55
  /** CartLineState -> Navbar4 cart line. `price` is legacy; the authoritative
46
- * subtotal is passed separately, so it is never computed from the line. */
56
+ * subtotal and per-line total are passed separately, so neither is computed
57
+ * from the line. */
47
58
  function toNavCartItems(cart: CartLineState[]): NavCartItem[] {
48
59
  return cart.map((line) => ({
49
60
  id: line.id,
@@ -52,19 +63,36 @@ function toNavCartItems(cart: CartLineState[]): NavCartItem[] {
52
63
  price: 0,
53
64
  qty: line.quantity,
54
65
  image: line.image,
66
+ lineTotal: line.lineTotal,
55
67
  }))
56
68
  }
57
69
 
58
70
  const baseComponents = {
59
71
  Layout: ({ children, slots }: { children?: React.ReactNode; slots?: Record<string, React.ReactNode> }) => {
60
72
  useStorefrontHandlers()
73
+ const { set } = useStateStore()
74
+ const pathname = usePathname()
75
+ // The mobile bottom navigation is feature-gated; when it is installed the
76
+ // main content reserves bottom padding so the fixed bar never obscures it.
77
+ const hasBottomNav = mountedFeatureNames.includes('navigability')
78
+ // Central dismissal: any route or history change closes the shared cart
79
+ // lateral, so it never lingers across navigation (forward/back included).
80
+ useEffect(() => {
81
+ set('/cartOpen', false)
82
+ }, [pathname, set])
61
83
  return (
62
84
  <div className="flex min-h-screen flex-col">
85
+ {slots?.chrome}
63
86
  {slots?.notices}
64
87
  <header className="sticky top-0 z-40 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
65
88
  {slots?.header}
66
89
  </header>
67
- <main className="flex-1">{children}</main>
90
+ <main
91
+ id="main-content"
92
+ className={hasBottomNav ? 'flex-1 pb-16 md:pb-0' : 'flex-1'}
93
+ >
94
+ {children}
95
+ </main>
68
96
  <footer>{slots?.footer}</footer>
69
97
  </div>
70
98
  )
@@ -72,6 +100,22 @@ const baseComponents = {
72
100
  // Neutral page root: renders the route page without shell chrome. Using it
73
101
  // instead of `Layout` keeps the shell from mounting twice per page.
74
102
  Page: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
103
+ // Navigability chrome, feature-gated by the shell spec (only referenced when
104
+ // the feature is installed). Props are cast to the block contracts; the
105
+ // catalog schema is the runtime guard.
106
+ SkipToContent: ({ props }: { props: Record<string, unknown> }) => {
107
+ const p = props as unknown as SkipToContentProps
108
+ return <SkipToContentBlock {...p} />
109
+ },
110
+ BackToTop: ({ props }: { props: Record<string, unknown> }) => {
111
+ const p = props as unknown as BackToTopProps
112
+ return <BackToTopBlock {...p} />
113
+ },
114
+ MobileBottomNav: ({ props }: { props: Record<string, unknown> }) => {
115
+ const pathname = usePathname()
116
+ const p = props as unknown as MobileBottomNavProps
117
+ return <MobileBottomNavBlock {...p} currentHref={p.currentHref ?? pathname} />
118
+ },
75
119
  // Reserved top region for system/status messages. Self-gates on state and
76
120
  // collapses to nothing when there is no notice. A configured mock is labelled
77
121
  // as demo data; a real-mode failure is surfaced visibly, never hidden.
@@ -110,8 +154,30 @@ const baseComponents = {
110
154
  StorefrontNavbar: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
111
155
  const parsed = storefrontNavbarPropsSchema.parse(props)
112
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'
113
167
  const cart = (state.cart ?? []) as CartLineState[]
114
168
  const totals = state.cartTotals as CartTotalsState | null
169
+ const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
170
+ const readError = typeof state.cartReadError === 'string' ? state.cartReadError : undefined
171
+ const errorLabel = cartError ?? readError
172
+ const cartState = state.cartPending ? 'pending' : errorLabel ? 'error' : 'idle'
173
+ // Checkout is offered only when the required backend amounts are present and
174
+ // valid: a missing/malformed subtotal, total, or line amount blocks it, while
175
+ // an undetermined shipping amount does not (AC-CART-4.4 / UC-CART-7).
176
+ const amountsValid =
177
+ cart.every((line) => isAvailableMoney(line.lineTotal)) &&
178
+ totals !== null &&
179
+ isAvailableMoney(totals.subtotal) &&
180
+ isAvailableMoney(totals.total)
115
181
  return (
116
182
  <Navbar4
117
183
  storeCategories={parsed.storeCategories}
@@ -122,13 +188,48 @@ const baseComponents = {
122
188
  logoAccent={parsed.logoAccent}
123
189
  className={parsed.className}
124
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}
209
+ // The current route marks the matching category link as the current page
210
+ // (accessibly, beyond color alone); no link is marked when it does not
211
+ // match any destination.
212
+ currentPath={usePathname()}
125
213
  // Held global search (E2 task 5.4): default to hidden so no global
126
214
  // search is presented while the contract is unverified; the user-owned
127
215
  // shell seam may opt in with `showSearch: true`.
128
216
  showSearch={parsed.showSearch ?? false}
129
217
  items={toNavCartItems(cart)}
130
218
  subtotal={totals?.subtotal}
131
- onViewCart={() => emit('openCart')}
219
+ // One shared lateral: visibility is driven by the shared `cartOpen`
220
+ // state (a successful add opens it; navigation dismisses it). The
221
+ // canonical line amounts and lifecycle states come from the same cart
222
+ // state the standalone `/cart` view reads.
223
+ canonicalCart
224
+ cartState={cartState}
225
+ cartErrorLabel={errorLabel}
226
+ onCartRetry={() => emit('refreshCart')}
227
+ cartOpen={state.cartOpen === true}
228
+ onCartOpenChange={(open) => set('/cartOpen', open)}
229
+ checkoutUnavailable={!checkoutAvailable}
230
+ checkoutDisabled={cartState !== 'idle' || cart.length === 0 || !amountsValid}
231
+ viewCartUnavailable={!cartViewAvailable}
232
+ onViewCart={() => emit('goToCart')}
132
233
  onCheckout={() => emit('goToCheckout')}
133
234
  onQtyChange={(id, delta) => {
134
235
  set('/qtyDelta', { id, delta })
@@ -141,47 +242,6 @@ const baseComponents = {
141
242
  />
142
243
  )
143
244
  },
144
- CartDrawer: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
145
- const parsed = cartDrawerPropsSchema.parse(props)
146
- const { state, set } = useStateStore()
147
- const cart = (state.cart ?? []) as CartLineState[]
148
- const totals = state.cartTotals as CartTotalsState | null
149
- const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
150
- return (
151
- <ShoppingCart4
152
- items={cart.map((line) => ({
153
- id: line.id,
154
- name: line.name,
155
- price: 0,
156
- quantity: line.quantity,
157
- image: line.image,
158
- variant: line.variant,
159
- lineTotal: line.lineTotal,
160
- unitPrice: line.unitPrice,
161
- }))}
162
- promotions={parsed.promotions.map((promo) => ({
163
- threshold: promo.threshold,
164
- reward: promo.reward,
165
- icon: resolveIcon(promo.icon),
166
- }))}
167
- totals={totals ?? undefined}
168
- totalsState={state.cartPending ? 'pending' : cartError ? 'error' : 'idle'}
169
- totalsErrorLabel={cartError}
170
- onRetryTotals={() => emit('refreshCart')}
171
- onQuantityChange={(id, quantity) => {
172
- const line = cart.find((candidate) => candidate.id === id)
173
- if (!line) return
174
- set('/qtyUpdate', { id, merchandiseId: line.merchandiseId, quantity })
175
- emit('updateQuantity')
176
- }}
177
- onRemove={(id) => {
178
- set('/lastRemoved', id)
179
- emit('removeFromCart')
180
- }}
181
- onCheckout={() => emit('goToCheckout')}
182
- />
183
- )
184
- },
185
245
  Banner: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
186
246
  const parsed = bannerPropsSchema.parse(props)
187
247
  const { set } = useStateStore()
@@ -214,24 +274,25 @@ const baseComponents = {
214
274
  />
215
275
  )
216
276
  },
217
- ProductCard: ({
277
+ ProductGrid: ({
218
278
  props,
219
279
  emit,
220
280
  }: {
221
281
  props: Record<string, unknown>
222
282
  emit: (event: string) => void
223
283
  }) => {
224
- const parsed = productCardPropsSchema.parse(props)
284
+ const parsed = productGridPropsSchema.parse(props)
225
285
  const { set } = useStateStore()
226
286
  const select = (product: unknown) => {
227
287
  set('/lastClicked', product)
228
288
  }
229
289
  return (
230
- <ProductCard1
231
- products={parsed.products}
290
+ <ProductGridBlock
291
+ items={parsed.items}
292
+ presentation={parsed.presentation}
232
293
  heading={parsed.heading}
233
294
  maxItems={parsed.maxItems}
234
- // No first-variant shortcut: open the detail so a variant is chosen.
295
+ // The canonical listing opens the detail so a variant is chosen explicitly.
235
296
  onAddToCart={(product) => {
236
297
  select(product)
237
298
  emit('openProduct')
@@ -5,6 +5,8 @@
5
5
  import type { StorefrontLoaderFn } from '@thorprovider/runtime/render-core/app'
6
6
  import { createStorefrontApp } from '@thorprovider/runtime/render-core/app'
7
7
  import { __STOREFRONT_CAMEL__Spec } from './spec'
8
+ import { entitySeoExtractors } from './spec/seo'
9
+ import { getSiteUrl } from './store-context'
8
10
  import { views } from './views'
9
11
 
10
12
  const loaders: Record<string, StorefrontLoaderFn> = Object.assign({}, ...views.map((view) => view.loader))
@@ -12,6 +14,7 @@ const loaders: Record<string, StorefrontLoaderFn> = Object.assign({}, ...views.m
12
14
  export const __STOREFRONT_CAMEL__App = createStorefrontApp({
13
15
  spec: __STOREFRONT_CAMEL__Spec,
14
16
  loaders,
17
+ entitySeo: { siteUrl: getSiteUrl(), extract: entitySeoExtractors },
15
18
  })
16
19
 
17
20
  export type { StorefrontLoaderFn }
@@ -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,40 +66,55 @@ 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
- shippingNote: z.string(),
99
+ shippingNote: z.string().optional(),
74
100
  utilityLinks: z.array(z.object({ label: z.string(), href: z.string() })),
75
101
  logoText: z.string(),
76
102
  logoHref: z.string().optional(),
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(),
83
116
  })
84
117
 
85
- // Mirrors ShoppingCart4 (block) minus the runtime-bound `items`; the registry
86
- // fills items from /cart. promotions carry icon NAMES resolved via icon-map.
87
- export const cartPromotionSchema = z.object({
88
- threshold: z.number(),
89
- reward: z.string(),
90
- icon: z.string(),
91
- })
92
-
93
- export const cartDrawerPropsSchema = z.object({
94
- promotions: z.array(cartPromotionSchema),
95
- taxRate: z.number().optional(),
96
- })
97
-
98
118
  export const bannerPropsSchema = z.object({
99
119
  badge: z.string().optional(),
100
120
  message: z.string(),
@@ -103,10 +123,15 @@ export const bannerPropsSchema = z.object({
103
123
  avatars: z.array(z.string()).optional(),
104
124
  })
105
125
 
106
- export const productCardPropsSchema = z.object({
107
- products: z.array(shellProductSchema),
126
+ export const productGridPropsSchema = z.object({
127
+ items: z.array(productPresentationSchema),
128
+ presentation: z.enum(['classic', 'minimal', 'rich']).optional(),
108
129
  heading: z.string().optional(),
109
- 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(),
110
135
  })
111
136
 
112
137
  export const footerPropsSchema = z.object({
@@ -119,3 +144,31 @@ export const footerPropsSchema = z.object({
119
144
  .object({ placeholder: z.string().optional(), buttonLabel: z.string().optional() })
120
145
  .optional(),
121
146
  })
147
+
148
+ // Navigability chrome contracts, mirrored from @thorprovider/blocks so the
149
+ // shell catalog/registry share the scaffold's zod version.
150
+ export const skipToContentPropsSchema = z.object({
151
+ targetId: z.string(),
152
+ label: z.string().optional(),
153
+ className: z.string().optional(),
154
+ })
155
+
156
+ export const backToTopPropsSchema = z.object({
157
+ threshold: z.number().optional(),
158
+ label: z.string().optional(),
159
+ className: z.string().optional(),
160
+ })
161
+
162
+ export const mobileBottomNavItemSchema = z.object({
163
+ id: z.string().optional(),
164
+ label: z.string(),
165
+ href: z.string(),
166
+ icon: z.string().optional(),
167
+ })
168
+
169
+ export const mobileBottomNavPropsSchema = z.object({
170
+ items: z.array(mobileBottomNavItemSchema),
171
+ currentHref: z.string().optional(),
172
+ ariaLabel: z.string().optional(),
173
+ className: z.string().optional(),
174
+ })
@@ -0,0 +1,182 @@
1
+ 'use client'
2
+
3
+ // Generated by Thor Commerce storefront (host: section observation)
4
+ //
5
+ // Optional, host-owned merchandising observation. DISABLED BY DEFAULT: nothing is
6
+ // observed, transmitted, or stored until the host registers an adapter through
7
+ // `configureSectionObservation`. The pure controller (validation, impression
8
+ // dedupe, conservative lineage) lives in @thorprovider/runtime/contracts; this
9
+ // module only adds the browser glue (visibility, per-view-visit identity) and the
10
+ // adapter seam. Adapter failures never interrupt navigation, cart, or checkout.
11
+
12
+ import { useEffect, useRef, useState } from 'react'
13
+ import {
14
+ createInMemoryRecorder,
15
+ createObservationController,
16
+ type ConfirmedEvent,
17
+ type ObservationContext,
18
+ type ObservationController,
19
+ type SectionObservationAdapter,
20
+ } from '@thorprovider/runtime/contracts'
21
+
22
+ let controller: ObservationController | null = null
23
+ let viewVisitId: string | null = null
24
+ let viewVisitSeq = 0
25
+
26
+ function nextViewVisitId(): string {
27
+ viewVisitSeq += 1
28
+ return `${Date.now().toString(36)}-${viewVisitSeq}`
29
+ }
30
+
31
+ /** Stable for one view visit (page load). */
32
+ function getViewVisitId(): string {
33
+ if (!viewVisitId) viewVisitId = nextViewVisitId()
34
+ return viewVisitId
35
+ }
36
+
37
+ function reportFailure(scope: string, error: unknown): void {
38
+ console.error(
39
+ `[storefront/observation] ${scope} failed`,
40
+ error instanceof Error ? error.message : error,
41
+ )
42
+ }
43
+
44
+ /** Register (or clear) the host adapter. Null disables observation entirely. */
45
+ export function configureSectionObservation(adapter: SectionObservationAdapter | null): void {
46
+ controller = adapter
47
+ ? createObservationController({
48
+ adapter,
49
+ onError: (error) => reportFailure('adapter', error),
50
+ })
51
+ : null
52
+ }
53
+
54
+ export function isSectionObservationEnabled(): boolean {
55
+ return controller !== null
56
+ }
57
+
58
+ export function getSectionObservationController(): ObservationController | null {
59
+ return controller
60
+ }
61
+
62
+ /** An in-memory recorder for verification/tests (never a production sink). */
63
+ export function createInMemorySectionRecorder(): ReturnType<typeof createInMemoryRecorder> {
64
+ return createInMemoryRecorder()
65
+ }
66
+
67
+ export function setSectionObservationContext(context?: ObservationContext): void {
68
+ try {
69
+ controller?.setContext(context)
70
+ } catch (error) {
71
+ reportFailure('setContext', error)
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Observe a confirmed host transition. Only recorded when a section origin
77
+ * exists for the current session/context; otherwise it stays unattributed.
78
+ */
79
+ export function recordConfirmedTransition(
80
+ event: ConfirmedEvent,
81
+ input?: { productHandle?: string; destination?: string },
82
+ ): void {
83
+ try {
84
+ controller?.noteConfirmed(event, input)
85
+ } catch (error) {
86
+ reportFailure(event, error)
87
+ }
88
+ }
89
+
90
+ export interface UseSectionObservationInput {
91
+ sectionId: string
92
+ sectionType: string
93
+ sectionVariant?: string
94
+ objective?: string
95
+ context?: ObservationContext
96
+ }
97
+
98
+ /**
99
+ * Observe a section's exposure and product clicks. When observation is disabled
100
+ * no IntersectionObserver is attached and the returned callback is a no-op.
101
+ */
102
+ export function useSectionObservation(input: UseSectionObservationInput) {
103
+ const enabled = isSectionObservationEnabled() && input.sectionId.length > 0
104
+ const containerRef = useRef<HTMLDivElement | null>(null)
105
+ const [inView, setInView] = useState(false)
106
+ const { sectionId, sectionType, sectionVariant, objective, context } = input
107
+
108
+ useEffect(() => {
109
+ if (!enabled) return
110
+ const element = containerRef.current
111
+ if (!element || typeof IntersectionObserver === 'undefined') return
112
+ const observer = new IntersectionObserver(
113
+ (entries) => {
114
+ for (const entry of entries) {
115
+ if (entry.intersectionRatio >= 0.5) setInView(true)
116
+ }
117
+ },
118
+ { threshold: [0.5] },
119
+ )
120
+ observer.observe(element)
121
+ return () => observer.disconnect()
122
+ }, [enabled])
123
+
124
+ useEffect(() => {
125
+ if (!enabled || !inView) return
126
+ const timer = setTimeout(() => {
127
+ controller?.observeImpression({
128
+ viewVisitId: getViewVisitId(),
129
+ sectionId,
130
+ sectionType,
131
+ ...(sectionVariant ? { sectionVariant } : {}),
132
+ ...(objective ? { objective } : {}),
133
+ ...(context ? { context } : {}),
134
+ })
135
+ }, 1000)
136
+ return () => clearTimeout(timer)
137
+ }, [enabled, inView, sectionId, sectionType, sectionVariant, objective, context])
138
+
139
+ const noteProductClick = (product: { id: string | number; href?: string }): void => {
140
+ if (!enabled) return
141
+ try {
142
+ controller?.noteClick({
143
+ viewVisitId: getViewVisitId(),
144
+ sectionId,
145
+ sectionType,
146
+ ...(sectionVariant ? { sectionVariant } : {}),
147
+ ...(objective ? { objective } : {}),
148
+ ...(context ? { context } : {}),
149
+ productHandle: String(product.id),
150
+ ...(product.href ? { destination: product.href } : {}),
151
+ })
152
+ } catch (error) {
153
+ reportFailure('noteClick', error)
154
+ }
155
+ }
156
+
157
+ return { containerRef, noteProductClick, enabled }
158
+ }
159
+
160
+ /**
161
+ * Observe a successfully rendered product destination. Recorded only when it
162
+ * matches the current section origin; otherwise it stays unattributed.
163
+ */
164
+ export function useProductVisitObservation(
165
+ productHandle: string | null | undefined,
166
+ destination?: string,
167
+ ): void {
168
+ const enabled = isSectionObservationEnabled()
169
+
170
+ useEffect(() => {
171
+ if (!enabled || !productHandle) return
172
+ try {
173
+ controller?.noteProductVisit({
174
+ viewVisitId: getViewVisitId(),
175
+ productHandle: String(productHandle),
176
+ ...(destination ? { destination } : {}),
177
+ })
178
+ } catch (error) {
179
+ reportFailure('noteProductVisit', error)
180
+ }
181
+ }, [enabled, productHandle, destination])
182
+ }