@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
package/README.md
CHANGED
|
@@ -297,15 +297,11 @@ held post-MVP and rejected before any write. `create` seeds `home` and `cart`;
|
|
|
297
297
|
`--starter` seeds every curated view and feature. Home editorial (`faq`, `cta`) and
|
|
298
298
|
data-bound `products` sections: see [Product sections](docs/product-sections.md).
|
|
299
299
|
|
|
300
|
-
**Cart lifecycle and checkout independence.** The cart review is a normal view,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
the
|
|
304
|
-
|
|
305
|
-
checkout are independent: review works without checkout (its action is hidden),
|
|
306
|
-
and adding `checkout` never adds the cart view. The CLI derives
|
|
307
|
-
`cartViewAvailable`/`checkoutAvailable` from the installed views/features into
|
|
308
|
-
`composition.ts`, which the generated wiring reads.
|
|
300
|
+
**Cart lifecycle and checkout independence.** The cart review is a normal view, not a shell element: `view add cart` installs it, `view remove cart` drops it (which also hides the lateral's "View cart" action and leaves `/cart` unrouted; the navbar icon still opens the compact lateral). `sync` never silently adds it to an existing store — upgrading is an explicit `view add cart`.
|
|
301
|
+
Cart and checkout are independent: review works without checkout (its action is hidden), and adding `checkout` never adds the cart view. The CLI derives `cartViewAvailable`/`checkoutAvailable` from the installed views/features into `composition.ts`, which the generated wiring reads.
|
|
302
|
+
|
|
303
|
+
**Account lifecycle (customer-auth).** The `customer-auth` feature owns the `/account` route, the request-scoped session read, cross-tab/foreground reconciliation, and the navbar account chrome, toggled together by `storefront feature add|remove customer-auth`; the account chrome follows the scaffold's user-owned/derived split.
|
|
304
|
+
See [Account lifecycle](docs/account-lifecycle.md) — the single canonical source — for the reader, the shared client lifecycle, the real panel scope, and sync behaviour.
|
|
309
305
|
|
|
310
306
|
**Prerequisites and pinning.** Node `>=20.9.0`, `node-modules` linker, and the
|
|
311
307
|
canonical Yarn pinned in the generated `package.json` as
|
|
@@ -358,7 +354,9 @@ different `formatVersion` → `E_INVALID_ENVELOPE`). Operation names are
|
|
|
358
354
|
`section add|remove|move`/`sections [<view>]` over `section.add|remove|reorder` (see [Product sections](docs/product-sections.md)).
|
|
359
355
|
|
|
360
356
|
**What E1 proves.** The only executable non-default swap is `home.benefits`
|
|
361
|
-
`
|
|
357
|
+
`cards → split` (the canonical `Feature` presentations; identical `BenefitsItem[]`
|
|
358
|
+
data shape, no bridge; the retired `Feature1`/`Feature2` names resolve as legacy
|
|
359
|
+
aliases); every bridged
|
|
362
360
|
variant is `held`. A feature may declare a `config` and `mounts`; the bounded `benefits`
|
|
363
361
|
feature mounts at `home.benefits` with `{ "presentation": "compact" | "detailed" }`,
|
|
364
362
|
claims the slot exactly once, and preserves user-owned content on removal. Checkout
|
|
@@ -415,8 +413,8 @@ model adds value and make the rest a reliable script.
|
|
|
415
413
|
- **Truthful output**: a versioned recipe/catalog exposes every slot and variant with an
|
|
416
414
|
`executable` or `held` status and a reason. Only executable variants render; a held
|
|
417
415
|
variant is rejected before any write, so a site is never presented with a choice that
|
|
418
|
-
silently does nothing. E1 ships a small proven set (`home.benefits`
|
|
419
|
-
`
|
|
416
|
+
silently does nothing. E1 ships a small proven set (`home.benefits`
|
|
417
|
+
`cards`↔`split`); bridged variants and optional sections stay held.
|
|
420
418
|
|
|
421
419
|
## Generated project structure
|
|
422
420
|
|
|
@@ -4,6 +4,9 @@ import { notFound } from 'next/navigation'
|
|
|
4
4
|
import { buildBreadcrumbListJsonLd, serializeJsonLd } from '@thorprovider/runtime/contracts'
|
|
5
5
|
import { __STOREFRONT_CAMEL__App } from '@/lib/__STOREFRONT__/runtime'
|
|
6
6
|
import { readCartStateForRender } from '@/lib/__STOREFRONT__/cart-state'
|
|
7
|
+
import { readAccountSession } from '@/lib/__STOREFRONT__/account-session'
|
|
8
|
+
import { toAccountInitialState } from '@/lib/__STOREFRONT__/account-session.core'
|
|
9
|
+
import { mountedFeatureNames } from '@/lib/__STOREFRONT__/composition'
|
|
7
10
|
import { StorefrontRenderer } from './renderer'
|
|
8
11
|
|
|
9
12
|
export const { generateMetadata, generateStaticParams } = __STOREFRONT_CAMEL__App
|
|
@@ -23,7 +26,17 @@ export default async function Page({
|
|
|
23
26
|
// Read the signed cookie and load the backend cart for the initial render.
|
|
24
27
|
// This never creates a cart; a guest identity is issued by a Server Action.
|
|
25
28
|
const cartState = await readCartStateForRender()
|
|
26
|
-
|
|
29
|
+
|
|
30
|
+
// Seed the request-scoped account identity BEFORE the shell renders, and only
|
|
31
|
+
// when the customer-auth capability is mounted: an unmounted feature performs
|
|
32
|
+
// no auth resolution. The reader is render-safe and request-scoped (no shared
|
|
33
|
+
// cache, so concurrent requests and store contexts stay isolated); only the
|
|
34
|
+
// allowlisted display identity enters the initial state, never a token.
|
|
35
|
+
const accountState = mountedFeatureNames.includes('customer-auth')
|
|
36
|
+
? toAccountInitialState(await readAccountSession())
|
|
37
|
+
: {}
|
|
38
|
+
|
|
39
|
+
const initialState = { ...(data.initialState ?? {}), ...cartState, ...accountState }
|
|
27
40
|
|
|
28
41
|
// Entity structured data is server-rendered from the real loaded entity and
|
|
29
42
|
// sanitized so entity text cannot terminate the script element.
|
|
@@ -5,17 +5,48 @@
|
|
|
5
5
|
import { useRef } from 'react'
|
|
6
6
|
import { PageRenderer } from '@json-render/next'
|
|
7
7
|
import type { PageData } from '@json-render/next'
|
|
8
|
+
import {
|
|
9
|
+
arbitrateProjection,
|
|
10
|
+
createProjectionOwnership,
|
|
11
|
+
stabilizeProjection,
|
|
12
|
+
type ProjectionOwnership,
|
|
13
|
+
type StabilizedProjection,
|
|
14
|
+
} from '@/lib/__STOREFRONT__/projection-ownership'
|
|
15
|
+
import { ProjectionOwnershipProvider } from '@/lib/__STOREFRONT__/projection-ownership.client'
|
|
8
16
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
17
|
+
export interface StorefrontRendererProps extends PageData {
|
|
18
|
+
/**
|
|
19
|
+
* The per-tab ownership ledger, injected for composition/tests. The renderer
|
|
20
|
+
* creates and keeps one internally when omitted.
|
|
21
|
+
*/
|
|
22
|
+
ownership?: ProjectionOwnership
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function StorefrontRenderer({ initialState, ownership: injected, ...data }: StorefrontRendererProps) {
|
|
26
|
+
const ownershipRef = useRef<ProjectionOwnership | null>(null)
|
|
27
|
+
if (ownershipRef.current === null) {
|
|
28
|
+
ownershipRef.current = injected ?? createProjectionOwnership()
|
|
29
|
+
}
|
|
30
|
+
const ownership = ownershipRef.current
|
|
31
|
+
|
|
32
|
+
// The server recomputes `initialState` on every render and a Server Action
|
|
33
|
+
// triggers an RSC refresh, so the prop is a fresh object each time even when
|
|
34
|
+
// its content is unchanged. Capture the first client-owned (account + cart)
|
|
35
|
+
// values so a later or older projection cannot overwrite a live cart or a
|
|
36
|
+
// newer local auth result, then arbitrate (a claim overrides the seed) and
|
|
37
|
+
// keep a STABLE reference while the serialized content is unchanged so
|
|
38
|
+
// `@json-render/react`'s StateProvider does not re-apply identical values and
|
|
39
|
+
// reset client-owned state. Server-owned keys always propagate, so navigation
|
|
40
|
+
// keeps working.
|
|
41
|
+
ownership.seed(initialState)
|
|
42
|
+
const projection = arbitrateProjection(ownership, initialState)
|
|
43
|
+
const stableRef = useRef<StabilizedProjection | null>(null)
|
|
44
|
+
const stable = stabilizeProjection(stableRef.current, projection)
|
|
45
|
+
stableRef.current = stable
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<ProjectionOwnershipProvider ownership={ownership}>
|
|
49
|
+
<PageRenderer {...data} initialState={stable.value} />
|
|
50
|
+
</ProjectionOwnershipProvider>
|
|
51
|
+
)
|
|
21
52
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
// Generated by Thor Commerce storefront (template: assets/templates/app/lib/__STOREFRONT__/account-boundary.client.tsx)
|
|
4
|
+
//
|
|
5
|
+
// The `/account` route's passive account boundary. It reads the shared account
|
|
6
|
+
// state and renders ONE thing: an accessible, retryable "unavailable" status —
|
|
7
|
+
// and only when the server resolution could not establish the session. It NEVER
|
|
8
|
+
// fetches or owns identity on mount (the retired `AccountBoot` behaviour), so
|
|
9
|
+
// visiting or navigating to `/account` introduces no competing identity
|
|
10
|
+
// bootstrap; the identity always comes from the shared lifecycle/SSR seed.
|
|
11
|
+
//
|
|
12
|
+
// The retry is a bound action (`retryAccountSession`, registered by the globally
|
|
13
|
+
// mounted lifecycle): the boundary is presentational and dependency-free, and
|
|
14
|
+
// the recovery edge lives in the one shared lifecycle, not in a route fetch.
|
|
15
|
+
|
|
16
|
+
import { useStateStore } from '@json-render/react'
|
|
17
|
+
import type { BaseComponentProps } from '@json-render/react'
|
|
18
|
+
|
|
19
|
+
export function AccountBoundary({ emit }: Pick<BaseComponentProps, 'emit'>) {
|
|
20
|
+
const { state } = useStateStore() as { state: Record<string, unknown> }
|
|
21
|
+
const resolution =
|
|
22
|
+
typeof state.accountResolution === 'string' ? state.accountResolution : 'unresolved'
|
|
23
|
+
// A cross-tab/foreground reconciliation is in flight (task 4.2): present a
|
|
24
|
+
// neutral pending surface instead of the sign-in form (which would fake a
|
|
25
|
+
// signed-out state before the server confirms it) or a stale unavailable
|
|
26
|
+
// status. The authenticated region handles its own pending surface, so this
|
|
27
|
+
// branch is only for the non-authenticated case.
|
|
28
|
+
if (state.accountReconciling === true && state.accountAuthenticated !== true) {
|
|
29
|
+
return (
|
|
30
|
+
<p
|
|
31
|
+
role="status"
|
|
32
|
+
aria-live="polite"
|
|
33
|
+
data-account-reconciling="1"
|
|
34
|
+
className="text-muted-foreground mx-auto max-w-md px-4 py-12 text-center text-sm"
|
|
35
|
+
>
|
|
36
|
+
Actualizando tu cuenta…
|
|
37
|
+
</p>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
// Resolved (authenticated/anonymous) or pre-projection: nothing to show. Only
|
|
41
|
+
// an unavailable resolution (a transport/server outage, never a fake
|
|
42
|
+
// sign-out) surfaces the retryable status.
|
|
43
|
+
if (resolution !== 'unavailable') return null
|
|
44
|
+
|
|
45
|
+
const pending = state.accountPending === true
|
|
46
|
+
const error = typeof state.accountError === 'string' ? state.accountError : null
|
|
47
|
+
// The message is the announced live status region; the retry control is a
|
|
48
|
+
// sibling (a native button, so it is keyboard-operable) that references the
|
|
49
|
+
// message as its accessible description. Keeping the interactive control OUT
|
|
50
|
+
// of the live region avoids re-announcing the button on every status update
|
|
51
|
+
// (task 4.3).
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
data-account-boundary="unavailable"
|
|
55
|
+
className="mx-auto flex max-w-md flex-col items-center gap-3 px-4 py-12 text-center"
|
|
56
|
+
>
|
|
57
|
+
<p
|
|
58
|
+
id="account-unavailable-message"
|
|
59
|
+
role="status"
|
|
60
|
+
aria-live="polite"
|
|
61
|
+
className="text-muted-foreground text-sm"
|
|
62
|
+
>
|
|
63
|
+
{error ?? 'No pudimos verificar tu sesión. Revisa tu conexión e inténtalo de nuevo.'}
|
|
64
|
+
</p>
|
|
65
|
+
<button
|
|
66
|
+
type="button"
|
|
67
|
+
disabled={pending}
|
|
68
|
+
aria-describedby="account-unavailable-message"
|
|
69
|
+
onClick={() => emit?.('retry')}
|
|
70
|
+
className="bg-primary text-primary-foreground focus-visible:ring-ring rounded-md px-4 py-2 text-sm font-medium transition-colors hover:opacity-90 focus-visible:ring-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-60"
|
|
71
|
+
>
|
|
72
|
+
{pending ? 'Reintentando…' : 'Reintentar'}
|
|
73
|
+
</button>
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|