@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.
- package/README.md +10 -12
- package/assets/templates/app/app/[[...slug]]/page.tsx +14 -1
- package/assets/templates/app/app/[[...slug]]/renderer.tsx +43 -12
- package/assets/templates/app/lib/__STOREFRONT__/account-boundary.client.tsx +76 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-lifecycle.client.tsx +461 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-mutation.client.ts +46 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-private.core.ts +103 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-reconcile.client.ts +465 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +177 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-session.ts +44 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +65 -0
- package/assets/templates/app/lib/__STOREFRONT__/actions.ts +76 -27
- package/assets/templates/app/lib/__STOREFRONT__/catalog.ts +4 -4
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +0 -10
- package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +3 -3
- package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +17 -18
- package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +209 -0
- package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.ts +247 -0
- package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +48 -19
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +49 -11
- package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +3 -5
- package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +25 -0
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +4 -2
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/cta.client.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/faq.client.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/logoCloud.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/pricing.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.client.tsx +16 -16
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/statistics.tsx +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/testimonials.tsx +1 -1
- package/assets/templates/features/customer-auth/handlers.ts +19 -23
- package/assets/templates/features/customer-auth/state.ts +21 -0
- package/assets/templates/views/account/index.tsx +19 -7
- package/assets/templates/views/account/registry.tsx +234 -155
- package/assets/templates/views/cart/data.ts +7 -7
- package/assets/templates/views/cart/registry.tsx +4 -3
- package/assets/templates/views/category/assembly/assembly.json +1 -1
- package/assets/templates/views/category/assembly/registry.skeleton.tsx +6 -6
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +1 -1
- package/assets/templates/views/category/registry.tsx +7 -7
- package/assets/templates/views/checkout/registry.tsx +3 -5
- package/assets/templates/views/home/assembly/assembly.json +4 -4
- package/assets/templates/views/home/assembly/index.skeleton.tsx +2 -1
- package/assets/templates/views/home/assembly/registry.skeleton.tsx +4 -1
- package/assets/templates/views/home/assembly/slots/benefits/cards/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/registry.part +7 -1
- package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/registry.part +6 -1
- package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/catalog.part +8 -0
- package/assets/templates/views/home/assembly/slots/categories/{ProductCategory2 → CategoryGrid}/element.part +1 -1
- package/assets/templates/views/home/assembly/slots/categories/CategoryGrid/registry.part +31 -0
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero/catalog.part +4 -0
- package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/registry.part +3 -1
- package/assets/templates/views/home/content.ts +22 -0
- package/assets/templates/views/home/index.tsx +11 -6
- package/assets/templates/views/home/props.ts +1 -0
- package/assets/templates/views/home/registry.tsx +39 -15
- package/assets/templates/views/home/schema.ts +141 -24
- package/assets/templates/views/product/data.ts +1 -1
- package/assets/templates/views/product/registry.tsx +10 -6
- package/assets/templates/views/product/schema.ts +36 -1
- package/package.json +4 -5
- package/recipes/archetypes.json +25 -25
- package/recipes/catalog.json +213 -160
- package/recipes/catalog.mjs +10 -0
- package/recipes/catalog.schema.json +4 -0
- package/recipes/features.json +3 -3
- package/recipes/recipes.json +138 -40
- package/recipes/sections.json +2 -2
- package/recipes/validate.mjs +21 -4
- package/scripts/candidate.mjs +2 -2
- package/scripts/file-classes.mjs +10 -0
- package/scripts/ownership-conflict.mjs +5 -2
- package/scripts/view-assembly.mjs +10 -2
- package/scripts/view-selection.mjs +1 -1
- package/skills/sf-view-gen/assets/recipes/archetypes.json +25 -25
- package/skills/sf-view-gen/assets/recipes/catalog.json +213 -160
- package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
- package/skills/sf-view-gen/assets/recipes/features.json +3 -3
- package/skills/sf-view-gen/assets/recipes/recipes.json +138 -40
- package/skills/sf-view-gen/assets/recipes/sections.json +2 -2
- package/skills/sf-view-gen/assets/templates/views/sections/cta.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/faq.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/logoCloud.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/pricing.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/products.client.tsx +16 -16
- package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/statistics.client.tsx +1 -1
- package/skills/sf-view-gen/assets/templates/views/sections/testimonials.client.tsx +1 -1
- package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
- package/skills/sf-view-gen/scripts/validate.mjs +21 -4
- package/assets/templates/views/home/assembly/slots/benefits/Feature1/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/benefits/Feature2/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/catalog.part +0 -4
- package/assets/templates/views/home/assembly/slots/categories/ProductCategory2/registry.part +0 -16
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/binding.json +0 -5
- package/assets/templates/views/home/assembly/slots/hero/StorefrontHero1/catalog.part +0 -4
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/catalog.part +0 -0
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → cards}/element.part +0 -0
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/catalog.part +0 -0
- /package/assets/templates/views/home/assembly/slots/benefits/{Feature2 → split}/element.part +0 -0
- /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
|
|
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
|
|
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 {
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
9
|
-
//
|
|
10
|
-
//
|
|
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
|
-
//
|
|
26
|
-
// panel.
|
|
27
|
-
//
|
|
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:
|
|
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,
|