@thorprovider/storefront 0.4.0-mvp.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -13
- package/assets/templates/app/app/[[...slug]]/page.tsx +32 -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__/composition.ts +1 -1
- 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 +60 -29
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +83 -15
- package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +3 -5
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +25 -0
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +7 -10
- 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 +26 -19
- package/assets/templates/features/checkout/state.ts +0 -5
- 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 +263 -155
- package/assets/templates/views/account/schema.ts +1 -1
- 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 +2 -2
- package/assets/templates/views/category/assembly/index.skeleton.tsx +11 -7
- package/assets/templates/views/category/assembly/registry.skeleton.tsx +9 -9
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +1 -1
- package/assets/templates/views/category/assembly/slots/filter/CategoryListing/catalog.part +5 -0
- package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/element.part +5 -3
- package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/registry.part +9 -5
- package/assets/templates/views/category/content.ts +2 -1
- package/assets/templates/views/category/index.tsx +19 -13
- package/assets/templates/views/category/props.ts +1 -1
- package/assets/templates/views/category/registry.tsx +19 -15
- package/assets/templates/views/category/schema.ts +48 -21
- package/assets/templates/views/checkout/content.ts +60 -0
- package/assets/templates/views/checkout/props.ts +4 -5
- package/assets/templates/views/checkout/registry.tsx +12 -10
- package/assets/templates/views/checkout/schema.ts +10 -16
- package/assets/templates/views/home/assembly/assembly.json +4 -4
- package/assets/templates/views/home/assembly/index.skeleton.tsx +2 -3
- 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/cards/registry.part +17 -0
- package/assets/templates/views/home/assembly/slots/benefits/split/binding.json +5 -0
- package/assets/templates/views/home/assembly/slots/benefits/{Feature1 → split}/registry.part +6 -2
- 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 -8
- 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/examples/merchandising/category-led.json +1 -1
- package/examples/merchandising/collection-led.json +1 -1
- package/package.json +4 -5
- package/recipes/archetypes.json +39 -43
- package/recipes/catalog.json +212 -202
- package/recipes/catalog.mjs +10 -0
- package/recipes/catalog.schema.json +4 -0
- package/recipes/features.json +5 -5
- package/recipes/recipes.json +137 -43
- package/recipes/sections.json +4 -4
- package/recipes/validate.mjs +21 -4
- package/scripts/candidate.mjs +2 -2
- package/scripts/composers.mjs +2 -2
- package/scripts/file-classes.mjs +10 -0
- package/scripts/logical-controls.mjs +4 -4
- package/scripts/operation-registry.mjs +1 -1
- package/scripts/ownership-conflict.mjs +5 -2
- package/scripts/view-assembly.mjs +12 -4
- package/scripts/view-selection.mjs +1 -1
- package/skills/sf-view-gen/assets/recipes/archetypes.json +39 -43
- package/skills/sf-view-gen/assets/recipes/catalog.json +212 -202
- package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
- package/skills/sf-view-gen/assets/recipes/features.json +5 -5
- package/skills/sf-view-gen/assets/recipes/recipes.json +137 -43
- package/skills/sf-view-gen/assets/recipes/sections.json +4 -4
- 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/schema.testimonials.ts +21 -11
- 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 +2 -8
- package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
- package/skills/sf-view-gen/scripts/validate.mjs +21 -4
- package/assets/templates/views/category/assembly/slots/filter/CategoryFilter2/catalog.part +0 -5
- 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/benefits/Feature2/registry.part +0 -10
- 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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type {
|
|
9
9
|
CardProduct,
|
|
10
10
|
FeaturedProduct,
|
|
11
|
-
|
|
11
|
+
ProductCategoryItem,
|
|
12
12
|
ProductDetailProduct,
|
|
13
13
|
} from '@thorprovider/blocks'
|
|
14
14
|
import type { Money, PaymentMethod } from '@thorprovider/types'
|
|
@@ -52,7 +52,7 @@ export interface CartTotalsState {
|
|
|
52
52
|
total: Money
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/** Mirrors the
|
|
55
|
+
/** Mirrors the canonical Checkout values contract (no card fields). */
|
|
56
56
|
export interface CheckoutFormData {
|
|
57
57
|
email: string
|
|
58
58
|
firstName: string
|
|
@@ -64,12 +64,7 @@ export interface CheckoutFormData {
|
|
|
64
64
|
zipCode: string
|
|
65
65
|
country: string
|
|
66
66
|
paymentMethod: string
|
|
67
|
-
cardNumber: string
|
|
68
|
-
expiryDate: string
|
|
69
|
-
cvv: string
|
|
70
|
-
cardName: string
|
|
71
67
|
saveInfo: boolean
|
|
72
|
-
sameAsBilling: boolean
|
|
73
68
|
newsletter: boolean
|
|
74
69
|
promoCode: string
|
|
75
70
|
}
|
|
@@ -165,8 +160,10 @@ export type OrderStatus = 'idle' | 'pending' | 'error' | 'unresolved' | 'complet
|
|
|
165
160
|
|
|
166
161
|
export interface StorefrontCoreState {
|
|
167
162
|
heroProducts: FeaturedProduct[]
|
|
168
|
-
categories:
|
|
169
|
-
|
|
163
|
+
categories: ProductCategoryItem[]
|
|
164
|
+
categoryQuery: string
|
|
165
|
+
/** Seeded by the catch-all host so a missing navigation source cannot look empty. */
|
|
166
|
+
navCategories?: NavCategory[]
|
|
170
167
|
categoryProducts: CardProduct[]
|
|
171
168
|
/** Canonical product detail: real variants, options, availability, and Money. */
|
|
172
169
|
selectedProduct: ProductDetailProduct | null
|
|
@@ -229,7 +226,7 @@ export interface StorefrontState extends StorefrontCoreState {
|
|
|
229
226
|
export const storefrontCoreState: StorefrontCoreState = {
|
|
230
227
|
heroProducts: [],
|
|
231
228
|
categories: [],
|
|
232
|
-
|
|
229
|
+
categoryQuery: '',
|
|
233
230
|
categoryProducts: [],
|
|
234
231
|
selectedProduct: null,
|
|
235
232
|
selectedVariantId: null,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 'use client' boundary, but this fragment keeps the explicit client boundary so
|
|
6
6
|
// the section composes identically in any consumer graph.
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import CtaBlock from '@thorprovider/blocks/blocks/marketing/cta/cta-section-1'
|
|
9
9
|
import { ctaSection1PropsSchema } from './schema.cta'
|
|
10
10
|
import type { ViewRegistry } from '../types'
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 'use client' boundary, but this fragment keeps the explicit client boundary so
|
|
6
6
|
// the section composes identically in any consumer graph.
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import FaqBlock from '@thorprovider/blocks/blocks/marketing/faq/faq-block-1'
|
|
9
9
|
import { faqPropsSchema } from './schema.faq'
|
|
10
10
|
import type { ViewRegistry } from '../types'
|
|
11
11
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Optional section fragment: logoCloud (mirrors recipes/sections.json)
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import LogoCloudBlock from '@thorprovider/blocks/blocks/marketing/logo-clouds/logo-cloud-1'
|
|
4
4
|
import { z } from 'zod'
|
|
5
5
|
|
|
6
6
|
// Mirrors the LogoCloud1Platform/LogoCloud1Props block contracts. `id` is a
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Optional section fragment: pricing (mirrors recipes/sections.json)
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import PricingBlock from '@thorprovider/blocks/blocks/marketing/pricing/pricing-section-1'
|
|
4
4
|
import { z } from 'zod'
|
|
5
5
|
|
|
6
6
|
// Mirrors the PricingTier/PricingSection1Props block contracts.
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
// Optional section fragment: products (mirrors recipes/sections.json) — client registry.
|
|
4
4
|
// The matching server-side catalog lives in products.tsx. A data-bound section
|
|
5
|
-
// renders one of two verified presentations (
|
|
6
|
-
// grid-and-carousel ProductShowcase1) chosen by the resolved
|
|
7
|
-
// selection and resolved products arrive through the view state;
|
|
8
|
-
// only validates them and wires navigation/purchase callbacks.
|
|
5
|
+
// renders one of two verified presentations (the canonical ProductGrid listing,
|
|
6
|
+
// or the combined grid-and-carousel ProductShowcase1) chosen by the resolved
|
|
7
|
+
// `variant`. The selection and resolved products arrive through the view state;
|
|
8
|
+
// this boundary only validates them and wires navigation/purchase callbacks.
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type ProductCard1Product,
|
|
14
|
-
} from '@thorprovider/blocks'
|
|
10
|
+
import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
|
|
11
|
+
import ProductShowcase1Block from '@thorprovider/blocks/blocks/e-commerce/product-list/product-showcase-1'
|
|
12
|
+
import type { ProductPresentation } from '@thorprovider/blocks/contracts'
|
|
15
13
|
import { useStateStore } from '@json-render/react'
|
|
16
14
|
import { useSectionObservation } from '../../section-observation'
|
|
17
15
|
import { productsPropsSchema, type ProductsStatus } from './schema.products'
|
|
@@ -65,7 +63,7 @@ export const productsRegistry: ViewRegistry = {
|
|
|
65
63
|
|
|
66
64
|
// The detail affordance opens the product so a variant is chosen explicitly.
|
|
67
65
|
// It is also the section's observation origin (disabled by default).
|
|
68
|
-
const openProduct = (product:
|
|
66
|
+
const openProduct = (product: ProductPresentation) => {
|
|
69
67
|
noteProductClick(product)
|
|
70
68
|
set('/lastClicked', product)
|
|
71
69
|
emit('openProduct')
|
|
@@ -74,15 +72,12 @@ export const productsRegistry: ViewRegistry = {
|
|
|
74
72
|
// Product-card shortcut: the add affordance adds the product's first
|
|
75
73
|
// purchasable variant (resolved server-side from the product id), then opens
|
|
76
74
|
// the mini-cart. It is not the section's observation origin.
|
|
77
|
-
const addToCart = (product:
|
|
75
|
+
const addToCart = (product: ProductPresentation) => {
|
|
78
76
|
set('/lastClicked', product)
|
|
79
77
|
emit('addClickedToCart')
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
const shared = {
|
|
83
|
-
products: parsed.products,
|
|
84
|
-
heading: parsed.heading,
|
|
85
|
-
description: parsed.description,
|
|
86
81
|
onAddToCart: addToCart,
|
|
87
82
|
onProductClick: openProduct,
|
|
88
83
|
}
|
|
@@ -90,9 +85,14 @@ export const productsRegistry: ViewRegistry = {
|
|
|
90
85
|
return (
|
|
91
86
|
<div ref={containerRef}>
|
|
92
87
|
{parsed.variant === 'ProductShowcase1' ? (
|
|
93
|
-
<ProductShowcase1Block
|
|
88
|
+
<ProductShowcase1Block
|
|
89
|
+
{...shared}
|
|
90
|
+
heading={parsed.heading}
|
|
91
|
+
description={parsed.description}
|
|
92
|
+
products={parsed.products}
|
|
93
|
+
/>
|
|
94
94
|
) : (
|
|
95
|
-
<
|
|
95
|
+
<ProductGridBlock {...shared} heading={parsed.heading} items={parsed.products} />
|
|
96
96
|
)}
|
|
97
97
|
</div>
|
|
98
98
|
)
|
|
@@ -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,25 +1,38 @@
|
|
|
1
1
|
// Optional section fragment: testimonials (mirrors recipes/sections.json)
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { TestimonialSection } from '@thorprovider/blocks'
|
|
4
4
|
import { z } from 'zod'
|
|
5
5
|
|
|
6
|
-
// Mirrors the Testimonial1Item/Testimonial1Props block contracts.
|
|
7
6
|
const testimonialItemSchema = z.object({
|
|
8
7
|
id: z.string(),
|
|
9
8
|
name: z.string(),
|
|
10
|
-
role: z.string(),
|
|
11
|
-
avatar: z.string(),
|
|
12
9
|
content: z.string(),
|
|
13
|
-
|
|
10
|
+
role: z.string().optional(),
|
|
11
|
+
avatar: z.string().optional(),
|
|
12
|
+
rating: z.number().optional(),
|
|
14
13
|
})
|
|
15
14
|
|
|
16
|
-
const testimonialsPropsSchema = z.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const testimonialsPropsSchema = z.discriminatedUnion('presentation', [
|
|
16
|
+
z.object({
|
|
17
|
+
presentation: z.literal('carousel'),
|
|
18
|
+
carouselLabels: z.object({
|
|
19
|
+
previous: z.string(),
|
|
20
|
+
next: z.string(),
|
|
21
|
+
slide: z.string(),
|
|
22
|
+
}),
|
|
23
|
+
items: z.array(testimonialItemSchema),
|
|
24
|
+
title: z.string().optional(),
|
|
25
|
+
description: z.string().optional(),
|
|
26
|
+
className: z.string().optional(),
|
|
27
|
+
}),
|
|
28
|
+
z.object({
|
|
29
|
+
presentation: z.literal('bento'),
|
|
30
|
+
items: z.array(testimonialItemSchema),
|
|
31
|
+
title: z.string().optional(),
|
|
32
|
+
description: z.string().optional(),
|
|
33
|
+
className: z.string().optional(),
|
|
34
|
+
}),
|
|
35
|
+
])
|
|
23
36
|
|
|
24
37
|
export const testimonialsSection = {
|
|
25
38
|
elementType: 'Testimonials',
|
|
@@ -33,13 +46,7 @@ export const testimonialsSection = {
|
|
|
33
46
|
Testimonials: ({ props }: { props: Record<string, unknown> }) => {
|
|
34
47
|
const parsed = testimonialsPropsSchema.parse(props)
|
|
35
48
|
return (
|
|
36
|
-
<
|
|
37
|
-
title={parsed.title ?? 'Lo que dicen nuestros clientes'}
|
|
38
|
-
items={parsed.items}
|
|
39
|
-
prevLabel={parsed.prevLabel ?? 'Anterior'}
|
|
40
|
-
nextLabel={parsed.nextLabel ?? 'Siguiente'}
|
|
41
|
-
slideAriaLabel={parsed.slideAriaLabel ?? 'Testimonio'}
|
|
42
|
-
/>
|
|
49
|
+
<TestimonialSection {...parsed} />
|
|
43
50
|
)
|
|
44
51
|
},
|
|
45
52
|
},
|
|
@@ -22,12 +22,7 @@ const checkoutFormDefaults: CheckoutFormData = {
|
|
|
22
22
|
zipCode: '',
|
|
23
23
|
country: '',
|
|
24
24
|
paymentMethod: '',
|
|
25
|
-
cardNumber: '',
|
|
26
|
-
expiryDate: '',
|
|
27
|
-
cvv: '',
|
|
28
|
-
cardName: '',
|
|
29
25
|
saveInfo: false,
|
|
30
|
-
sameAsBilling: false,
|
|
31
26
|
newsletter: false,
|
|
32
27
|
promoCode: '',
|
|
33
28
|
}
|
|
@@ -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,
|