@thorprovider/storefront 0.4.0-mvp.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +10 -12
  2. package/assets/templates/app/app/[[...slug]]/page.tsx +14 -1
  3. package/assets/templates/app/app/[[...slug]]/renderer.tsx +43 -12
  4. package/assets/templates/app/lib/__STOREFRONT__/account-boundary.client.tsx +76 -0
  5. package/assets/templates/app/lib/__STOREFRONT__/account-lifecycle.client.tsx +461 -0
  6. package/assets/templates/app/lib/__STOREFRONT__/account-mutation.client.ts +46 -0
  7. package/assets/templates/app/lib/__STOREFRONT__/account-private.core.ts +103 -0
  8. package/assets/templates/app/lib/__STOREFRONT__/account-reconcile.client.ts +465 -0
  9. package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +177 -0
  10. package/assets/templates/app/lib/__STOREFRONT__/account-session.ts +44 -0
  11. package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +65 -0
  12. package/assets/templates/app/lib/__STOREFRONT__/actions.ts +76 -27
  13. package/assets/templates/app/lib/__STOREFRONT__/catalog.ts +4 -4
  14. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +0 -10
  15. package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +3 -3
  16. package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +17 -18
  17. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +209 -0
  18. package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.ts +247 -0
  19. package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +48 -19
  20. package/assets/templates/app/lib/__STOREFRONT__/schema.ts +49 -11
  21. package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +3 -5
  22. package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +25 -0
  23. package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +4 -2
  24. package/assets/templates/app/lib/__STOREFRONT__/views/sections/cta.client.tsx +1 -1
  25. package/assets/templates/app/lib/__STOREFRONT__/views/sections/faq.client.tsx +1 -1
  26. package/assets/templates/app/lib/__STOREFRONT__/views/sections/logoCloud.tsx +1 -1
  27. package/assets/templates/app/lib/__STOREFRONT__/views/sections/pricing.tsx +1 -1
  28. package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.client.tsx +16 -16
  29. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +1 -1
  30. package/assets/templates/app/lib/__STOREFRONT__/views/sections/statistics.tsx +1 -1
  31. package/assets/templates/app/lib/__STOREFRONT__/views/sections/testimonials.tsx +1 -1
  32. package/assets/templates/features/customer-auth/handlers.ts +19 -23
  33. package/assets/templates/features/customer-auth/state.ts +21 -0
  34. package/assets/templates/views/account/index.tsx +19 -7
  35. package/assets/templates/views/account/registry.tsx +234 -155
  36. package/assets/templates/views/cart/data.ts +7 -7
  37. package/assets/templates/views/cart/registry.tsx +4 -3
  38. package/assets/templates/views/category/assembly/assembly.json +1 -1
  39. package/assets/templates/views/category/assembly/registry.skeleton.tsx +6 -6
  40. package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +1 -1
  41. package/assets/templates/views/category/registry.tsx +7 -7
  42. package/assets/templates/views/checkout/registry.tsx +3 -5
  43. package/assets/templates/views/home/assembly/assembly.json +4 -4
  44. package/assets/templates/views/home/assembly/index.skeleton.tsx +2 -1
  45. package/assets/templates/views/home/assembly/registry.skeleton.tsx +4 -1
  46. package/assets/templates/views/home/assembly/slots/benefits/cards/binding.json +5 -0
  47. package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/registry.part +7 -1
  48. package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
  49. package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/registry.part +6 -1
  50. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/binding.json +5 -0
  51. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/catalog.part +8 -0
  52. package/assets/templates/views/home/assembly/slots/categories/{ProductCategory2 → CategoryGrid}/element.part +1 -1
  53. package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/registry.part +31 -0
  54. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/binding.json +5 -0
  55. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/catalog.part +4 -0
  56. package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/registry.part +3 -1
  57. package/assets/templates/views/home/content.ts +22 -0
  58. package/assets/templates/views/home/index.tsx +11 -6
  59. package/assets/templates/views/home/props.ts +1 -0
  60. package/assets/templates/views/home/registry.tsx +39 -15
  61. package/assets/templates/views/home/schema.ts +141 -24
  62. package/assets/templates/views/product/data.ts +1 -1
  63. package/assets/templates/views/product/registry.tsx +10 -6
  64. package/assets/templates/views/product/schema.ts +36 -1
  65. package/package.json +4 -5
  66. package/recipes/archetypes.json +25 -25
  67. package/recipes/catalog.json +213 -160
  68. package/recipes/catalog.mjs +10 -0
  69. package/recipes/catalog.schema.json +4 -0
  70. package/recipes/features.json +3 -3
  71. package/recipes/recipes.json +138 -40
  72. package/recipes/sections.json +2 -2
  73. package/recipes/validate.mjs +21 -4
  74. package/scripts/candidate.mjs +2 -2
  75. package/scripts/file-classes.mjs +10 -0
  76. package/scripts/ownership-conflict.mjs +5 -2
  77. package/scripts/view-assembly.mjs +10 -2
  78. package/scripts/view-selection.mjs +1 -1
  79. package/skills/sf-view-gen/assets/recipes/archetypes.json +25 -25
  80. package/skills/sf-view-gen/assets/recipes/catalog.json +213 -160
  81. package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
  82. package/skills/sf-view-gen/assets/recipes/features.json +3 -3
  83. package/skills/sf-view-gen/assets/recipes/recipes.json +138 -40
  84. package/skills/sf-view-gen/assets/recipes/sections.json +2 -2
  85. package/skills/sf-view-gen/assets/templates/views/sections/cta.client.tsx +1 -1
  86. package/skills/sf-view-gen/assets/templates/views/sections/faq.client.tsx +1 -1
  87. package/skills/sf-view-gen/assets/templates/views/sections/logoCloud.client.tsx +1 -1
  88. package/skills/sf-view-gen/assets/templates/views/sections/pricing.client.tsx +1 -1
  89. package/skills/sf-view-gen/assets/templates/views/sections/products.client.tsx +16 -16
  90. package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +1 -1
  91. package/skills/sf-view-gen/assets/templates/views/sections/statistics.client.tsx +1 -1
  92. package/skills/sf-view-gen/assets/templates/views/sections/testimonials.client.tsx +1 -1
  93. package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
  94. package/skills/sf-view-gen/scripts/validate.mjs +21 -4
  95. package/assets/templates/views/home/assembly/slots/benefits/Feature1/binding.json +0 -5
  96. package/assets/templates/views/home/assembly/slots/benefits/Feature2/binding.json +0 -5
  97. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/binding.json +0 -5
  98. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/catalog.part +0 -4
  99. package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/registry.part +0 -16
  100. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/binding.json +0 -5
  101. package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/catalog.part +0 -4
  102. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/catalog.part +0 -0
  103. /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/element.part +0 -0
  104. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/catalog.part +0 -0
  105. /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/element.part +0 -0
  106. /package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/element.part +0 -0
@@ -5,7 +5,7 @@
5
5
  // section renders exactly what the host mapped from the catalog result.
6
6
 
7
7
  import { z } from 'zod'
8
- import { productPresentationSchema } from '@thorprovider/blocks'
8
+ import { productPresentationSchema } from '@thorprovider/blocks/contracts'
9
9
 
10
10
  // The per-instance resolution status the host loader computes for a data-bound
11
11
  // section. `ready`/`empty` carry resolved products; the remaining states carry no
@@ -1,6 +1,6 @@
1
1
  // Optional section fragment: statistics (mirrors recipes/sections.json)
2
2
 
3
- import { Statistic1 as StatisticBlock } from '@thorprovider/blocks'
3
+ import StatisticBlock from '@thorprovider/blocks/blocks/marketing/statistics/statistic-1'
4
4
  import { z } from 'zod'
5
5
  import { resolveIcon } from '../../icon-map'
6
6
 
@@ -1,6 +1,6 @@
1
1
  // Optional section fragment: testimonials (mirrors recipes/sections.json)
2
2
 
3
- import { Testimonial1 as TestimonialBlock } from '@thorprovider/blocks'
3
+ import TestimonialBlock from '@thorprovider/blocks/blocks/marketing/testimonials/testimonial-1'
4
4
  import { z } from 'zod'
5
5
 
6
6
  // Mirrors the Testimonial1Item/Testimonial1Props block contracts.
@@ -6,14 +6,26 @@
6
6
  // registration are invoked directly by the view registry (their credential
7
7
  // payload must never enter the state store); these handlers own the non-secret
8
8
  // state transitions: the sign-in / sign-up toggle and logout.
9
+ //
10
+ // This hook is also the GLOBAL MOUNT of the shared account lifecycle: because
11
+ // the handlers composer runs inside the shell Layout, calling
12
+ // `useAccountLifecycleMount()` activates the one shared account lifecycle on
13
+ // every storefront route (only while customer-auth is installed). The lifecycle
14
+ // reads the SSR-seeded identity and never fetches on mount/navigation, so there
15
+ // is no competing route bootstrap.
9
16
 
10
17
  import { useEffect } from 'react'
11
18
  import { useActions, useStateStore } from '@json-render/react'
12
- import { logoutAction } from '../../actions'
19
+ import { useAccountLifecycleMount } from '../../account-lifecycle.client'
13
20
 
14
21
  export function useCustomerAuthHandlers() {
15
22
  const { set } = useStateStore()
16
23
  const { registerHandler } = useActions()
24
+ // The shared lifecycle coordinator/reconciliation/mutation API for this tab.
25
+ // Mounted here; consumed by the shell, the account panel, and the account
26
+ // boundary. `lifecycle.logout` is stable across renders, so the effect below
27
+ // can capture it once.
28
+ const lifecycle = useAccountLifecycleMount()
17
29
 
18
30
  useEffect(() => {
19
31
  const handlers: Record<string, () => void> = {
@@ -26,28 +38,12 @@ export function useCustomerAuthHandlers() {
26
38
  set('/accountMode', 'login')
27
39
  },
28
40
  logout: () => {
29
- set('/accountPending', true)
30
- set('/accountError', null)
31
- void logoutAction()
32
- .then((result) => {
33
- set('/accountPending', false)
34
- if (result.ok) {
35
- set('/accountCustomer', null)
36
- set('/accountAuthenticated', false)
37
- set('/accountMode', 'login')
38
- return
39
- }
40
- set('/accountError', result.error)
41
- })
42
- .catch((error) => {
43
- // Never swallow: log a non-secret context line and surface a message.
44
- console.error(
45
- '[storefront/account] logout failed',
46
- error instanceof Error ? error.message : error,
47
- )
48
- set('/accountPending', false)
49
- set('/accountError', 'No se pudo cerrar la sesión. Inténtalo de nuevo.')
50
- })
41
+ // The shared lifecycle owns the sign-out mutation: it captures a
42
+ // pre-action generation guard, shows pending, prevents duplicate
43
+ // submits, and on success claims the signed-out projection (all three
44
+ // account keys in lockstep) and refreshes the server. A failure keeps
45
+ // the current valid session — it never claims anonymous.
46
+ void lifecycle.logout()
51
47
  },
52
48
  }
53
49
 
@@ -3,15 +3,29 @@
3
3
  // the manifest; the state composer spreads it over the core state.
4
4
 
5
5
  import type { Customer } from '@thorprovider/types'
6
+ import type { AccountResolution } from '../../account-session.core'
6
7
  import type { AccountOrderView } from '../../state.core'
7
8
 
8
9
  export interface CustomerAuthState {
9
10
  /** The resolved customer, or null when unauthenticated. Never a token. */
10
11
  accountCustomer: Customer | null
11
12
  accountAuthenticated: boolean
13
+ /**
14
+ * The truthful session resolution status seeded by the server projection.
15
+ * `unresolved` is the pre-projection default; `unavailable` is a retryable
16
+ * outage, never a fake sign-out.
17
+ */
18
+ accountResolution: AccountResolution | 'unresolved'
12
19
  /** Which auth surface is mounted: the sign-in page or the registration page. */
13
20
  accountMode: 'login' | 'register'
14
21
  accountPending: boolean
22
+ /**
23
+ * True while a cross-tab invalidation or a foreground/resume recheck is in
24
+ * flight (task 4.2). The `/account` authenticated region presents a neutral
25
+ * pending surface — never previously held identity/orders — until the
26
+ * authoritative re-resolution settles. Never a fake signed-out state.
27
+ */
28
+ accountReconciling: boolean
15
29
  accountError: string | null
16
30
  /** The customer's fetched order-history rows; empty until (or without) a load. */
17
31
  accountOrders: AccountOrderView[]
@@ -32,9 +46,16 @@ export interface CustomerAuthState {
32
46
  export const customerAuthState: CustomerAuthState = {
33
47
  accountCustomer: null,
34
48
  accountAuthenticated: false,
49
+ accountResolution: 'unresolved',
35
50
  accountMode: 'login',
36
51
  accountPending: false,
52
+ accountReconciling: false,
37
53
  accountError: null,
54
+ // The identity-dependent private order slice. Its reset lives in
55
+ // `account-private.core` (`emptyAccountPrivateOrderState`); a contract test
56
+ // keeps these initial values identical so the lifecycle's invalidation cannot
57
+ // drift from the seed. The guest cart slice lives in the core state and is
58
+ // never touched by an identity change.
38
59
  accountOrders: [],
39
60
  accountOrdersPending: false,
40
61
  accountOrdersError: null,
@@ -5,9 +5,11 @@
5
5
  // on the server. Registered by importing it in ../index.ts. Recipe: recipes.json -> "account".
6
6
  //
7
7
  // The initial render does NOT read the auth cookie here (this module is part of
8
- // the client catalog graph). The catch-all page mounts the route and the
9
- // headless `AccountBoot` resolves the current customer through the
10
- // cookie-authorized Server Action, so the token never reaches this module.
8
+ // the client catalog graph). The catch-all page seeds the account identity for
9
+ // every route (tasks 2.1/2.2) and the globally mounted shared account lifecycle
10
+ // (feature customer-auth handlers) owns identity; the headless `AccountBoot`
11
+ // boundary is passive and only surfaces the retryable unavailable status, so no
12
+ // route-level identity fetch happens here.
11
13
 
12
14
  import { getDataSource } from '../../store-context'
13
15
  import { pageRoot } from '../../spec/page-root'
@@ -22,20 +24,27 @@ import {
22
24
  accountRegisterPropsSchema,
23
25
  } from './schema'
24
26
 
25
- // Four surfaces: bootstrap (headless), sign-in, registration, and the signed-in
26
- // panel. The sign-in and registration surfaces are toggled by the `/accountMode`
27
- // state; the panel shows only when `/accountAuthenticated` is true.
27
+ // Surfaces: a passive boundary (headless unavailable/retry), sign-in,
28
+ // registration, and the signed-in panel. Sign-in and registration are toggled
29
+ // by `/accountMode` and hidden while the session is `unavailable`, so an outage
30
+ // shows the retryable boundary rather than a false signed-out form; the panel
31
+ // shows only when `/accountAuthenticated` is true.
28
32
  const elements: Record<string, StorefrontElement> = {
29
33
  'account.boot': {
30
34
  type: 'AccountBoot',
31
35
  props: {},
36
+ on: { retry: { action: 'retryAccountSession' } },
32
37
  },
33
38
  'account.login': {
34
39
  type: 'AccountLogin',
35
40
  visible: {
36
41
  $and: [
37
42
  { $state: '/accountAuthenticated', not: true },
43
+ { $state: '/accountResolution', neq: 'unavailable' },
38
44
  { $state: '/accountMode', eq: 'login' },
45
+ // While a reconciliation is in flight the sign-in form must not appear
46
+ // (that would fake a signed-out state before the server confirms it).
47
+ { $state: '/accountReconciling', not: true },
39
48
  ],
40
49
  },
41
50
  props: accountContent.login,
@@ -46,7 +55,9 @@ const elements: Record<string, StorefrontElement> = {
46
55
  visible: {
47
56
  $and: [
48
57
  { $state: '/accountAuthenticated', not: true },
58
+ { $state: '/accountResolution', neq: 'unavailable' },
49
59
  { $state: '/accountMode', eq: 'register' },
60
+ { $state: '/accountReconciling', not: true },
50
61
  ],
51
62
  },
52
63
  props: accountContent.register,
@@ -68,7 +79,8 @@ const elements: Record<string, StorefrontElement> = {
68
79
  const catalog = {
69
80
  AccountBoot: {
70
81
  props: accountEmptyPropsSchema,
71
- description: 'Headless account bootstrap: resolves the current customer from the auth cookie.',
82
+ description:
83
+ 'Passive account boundary: shows a retryable unavailable status when the session cannot be resolved, otherwise nothing. Never fetches identity.',
72
84
  },
73
85
  AccountLogin: {
74
86
  props: accountLoginPropsSchema,