@thorprovider/storefront 0.5.0 → 0.6.1
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/assets/templates/app/lib/__STOREFRONT__/commerce.ts +20 -30
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +11 -7
- package/assets/templates/views/account/content.ts +14 -3
- package/assets/templates/views/account/index.tsx +1 -1
- package/assets/templates/views/account/registry.tsx +64 -62
- package/assets/templates/views/account/schema.ts +25 -5
- package/assets/templates/views/product/registry.tsx +112 -14
- package/assets/templates/views/product/schema.ts +42 -7
- package/bin/storefront.js +21 -0
- package/package.json +2 -1
- package/recipes/archetypes.json +13 -9
- package/recipes/catalog.json +16 -35
- package/recipes/recipes.json +3 -5
- package/scripts/candidate.mjs +280 -6
- package/skills/sf-view-gen/assets/recipes/archetypes.json +13 -9
- package/skills/sf-view-gen/assets/recipes/catalog.json +16 -35
- package/skills/sf-view-gen/assets/recipes/recipes.json +3 -5
|
@@ -541,26 +541,9 @@ export async function loadCustomer(token: string | null): Promise<Customer | nul
|
|
|
541
541
|
// The host never talks to the backend SDK directly. `getCustomerOrders`
|
|
542
542
|
// delegates to `@thorprovider/runtime/commerce`, which builds a request-scoped
|
|
543
543
|
// provider carrying exactly the caller's token. The boundary maps the backend
|
|
544
|
-
// orders to a serializable
|
|
545
|
-
// own `currencyCode
|
|
546
|
-
// backend omits is omitted, never invented.
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* Format backend Money for display from its own currency, or undefined when the
|
|
550
|
-
* amount is absent/blank/non-finite. The decimal-string amount is already in
|
|
551
|
-
* major units, so it is never divided by 100.
|
|
552
|
-
*/
|
|
553
|
-
function formatMoney(money?: Money): string | undefined {
|
|
554
|
-
if (!money) return undefined
|
|
555
|
-
const amount = money.amount
|
|
556
|
-
if (typeof amount !== 'string' || amount.trim() === '') return undefined
|
|
557
|
-
const value = Number(amount)
|
|
558
|
-
if (!Number.isFinite(value)) return undefined
|
|
559
|
-
return new Intl.NumberFormat(undefined, {
|
|
560
|
-
style: 'currency',
|
|
561
|
-
currency: money.currencyCode,
|
|
562
|
-
}).format(value)
|
|
563
|
-
}
|
|
544
|
+
// orders to a serializable shape: amounts cross as canonical `Money` (the
|
|
545
|
+
// backend decimal plus its own `currencyCode`, never divided by 100) so the
|
|
546
|
+
// block formats them, and a field the backend omits is omitted, never invented.
|
|
564
547
|
|
|
565
548
|
/** Format an ISO timestamp as a locale date, or return the raw value unchanged. */
|
|
566
549
|
function formatOrderDate(value: string): string {
|
|
@@ -580,13 +563,18 @@ function formatAddress(address: Order['shippingAddress']): string | undefined {
|
|
|
580
563
|
return parts.join(', ')
|
|
581
564
|
}
|
|
582
565
|
|
|
583
|
-
/**
|
|
566
|
+
/**
|
|
567
|
+
* Map one backend order line to its account view, omitting absent optional
|
|
568
|
+
* fields. The backend `lineTotal` crosses the boundary as canonical `Money`: a
|
|
569
|
+
* preformatted string would drop the currency code the block needs to format
|
|
570
|
+
* the amount in the shopper's locale.
|
|
571
|
+
*/
|
|
584
572
|
export function toAccountOrderItemView(item: Order['items'][number]): AccountOrderItemView {
|
|
585
573
|
const view: AccountOrderItemView = {
|
|
586
574
|
id: item.id,
|
|
587
575
|
name: item.title,
|
|
588
576
|
quantity: item.quantity,
|
|
589
|
-
lineTotal:
|
|
577
|
+
lineTotal: item.total,
|
|
590
578
|
}
|
|
591
579
|
if (typeof item.variantTitle === 'string' && item.variantTitle.trim() !== '') {
|
|
592
580
|
view.variant = item.variantTitle
|
|
@@ -596,22 +584,24 @@ export function toAccountOrderItemView(item: Order['items'][number]): AccountOrd
|
|
|
596
584
|
return view
|
|
597
585
|
}
|
|
598
586
|
|
|
599
|
-
/**
|
|
587
|
+
/**
|
|
588
|
+
* Map a backend order to the account view row, omitting absent optional fields.
|
|
589
|
+
* Amounts pass through as canonical `Money` so the block — not this boundary —
|
|
590
|
+
* owns formatting and the unavailable state; an absent optional amount is
|
|
591
|
+
* omitted rather than serialized as `''`.
|
|
592
|
+
*/
|
|
600
593
|
export function toAccountOrderView(order: Order): AccountOrderView {
|
|
601
594
|
const view: AccountOrderView = {
|
|
602
595
|
id: order.id,
|
|
603
596
|
number: order.orderNumber,
|
|
604
597
|
date: formatOrderDate(order.createdAt),
|
|
605
598
|
status: order.status,
|
|
606
|
-
total:
|
|
599
|
+
total: order.total,
|
|
607
600
|
items: order.items.map(toAccountOrderItemView),
|
|
608
601
|
}
|
|
609
|
-
|
|
610
|
-
if (
|
|
611
|
-
|
|
612
|
-
if (tax !== undefined) view.tax = tax
|
|
613
|
-
const shipping = formatMoney(order.shipping)
|
|
614
|
-
if (shipping !== undefined) view.shipping = shipping
|
|
602
|
+
if (order.subtotal !== undefined) view.subtotal = order.subtotal
|
|
603
|
+
if (order.tax !== undefined) view.tax = order.tax
|
|
604
|
+
if (order.shipping !== undefined) view.shipping = order.shipping
|
|
615
605
|
const address = formatAddress(order.shippingAddress)
|
|
616
606
|
if (address !== undefined) view.address = address
|
|
617
607
|
return view
|
|
@@ -95,7 +95,7 @@ export const navCategorySchema = z.object({
|
|
|
95
95
|
emphasis: z.boolean().optional(),
|
|
96
96
|
})
|
|
97
97
|
|
|
98
|
-
// Optional brand seam mirroring the
|
|
98
|
+
// Optional brand seam mirroring the StorefrontNavbar / FooterSection accent props and
|
|
99
99
|
// the StorefrontHero editorial image. Declared locally (see
|
|
100
100
|
// productPresentationSchema) so the scaffold's zod version is the only one in
|
|
101
101
|
// play.
|
|
@@ -105,19 +105,23 @@ export interface StorefrontOrderLineView {
|
|
|
105
105
|
image?: string
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* A single line of a customer order-history row. Amounts stay canonical
|
|
110
|
+
* `Money` (backend identity included) so the block formats them from their own
|
|
111
|
+
* currency; formatting at the boundary would lose the currency code.
|
|
112
|
+
*/
|
|
109
113
|
export interface AccountOrderItemView {
|
|
110
114
|
id: string
|
|
111
115
|
name: string
|
|
112
116
|
variant?: string
|
|
113
117
|
quantity: number
|
|
114
|
-
lineTotal:
|
|
118
|
+
lineTotal: Money
|
|
115
119
|
image?: string
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
/**
|
|
119
123
|
* A customer order-history row, mapped from the backend order for the account
|
|
120
|
-
* view.
|
|
124
|
+
* view. Amounts are carried as canonical `Money` (never preformatted strings);
|
|
121
125
|
* an optional field the backend omits is omitted, never invented.
|
|
122
126
|
*/
|
|
123
127
|
export interface AccountOrderView {
|
|
@@ -125,10 +129,10 @@ export interface AccountOrderView {
|
|
|
125
129
|
number: string
|
|
126
130
|
date: string
|
|
127
131
|
status: string
|
|
128
|
-
total:
|
|
129
|
-
subtotal?:
|
|
130
|
-
tax?:
|
|
131
|
-
shipping?:
|
|
132
|
+
total: Money
|
|
133
|
+
subtotal?: Money
|
|
134
|
+
tax?: Money
|
|
135
|
+
shipping?: Money
|
|
132
136
|
address?: string
|
|
133
137
|
items: AccountOrderItemView[]
|
|
134
138
|
}
|
|
@@ -26,9 +26,20 @@ export const accountContent = {
|
|
|
26
26
|
signInLabel: 'Inicia sesión',
|
|
27
27
|
},
|
|
28
28
|
orders: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
// Canonical `OrderHistory` labels: every string the block renders is owned
|
|
30
|
+
// here, and `{number}` / `{date}` / `{n}` interpolate backend data.
|
|
31
|
+
labels: {
|
|
32
|
+
title: 'Mis pedidos',
|
|
33
|
+
description: 'Consulta tus pedidos anteriores',
|
|
34
|
+
orderLabel: 'Pedido {number}',
|
|
35
|
+
placedOnLabel: 'Realizado el {date}',
|
|
36
|
+
quantityLabel: 'Cantidad: {n}',
|
|
37
|
+
totalLabel: 'Total del pedido',
|
|
38
|
+
viewOrderLabel: 'Ver pedido',
|
|
39
|
+
trackOrderLabel: 'Seguir pedido',
|
|
40
|
+
amountUnavailableLabel: '—',
|
|
41
|
+
emptyLabel: 'Aún no tienes pedidos.',
|
|
42
|
+
},
|
|
32
43
|
errorLabel: 'No se pudieron cargar tus pedidos.',
|
|
33
44
|
loadingLabel: 'Cargando pedidos…',
|
|
34
45
|
},
|
|
@@ -97,7 +97,7 @@ const catalog = {
|
|
|
97
97
|
AccountOrders: {
|
|
98
98
|
props: accountOrdersPropsSchema,
|
|
99
99
|
description:
|
|
100
|
-
"Signed-in customer's order history rendered by
|
|
100
|
+
"Signed-in customer's order history rendered by the canonical `OrderHistory` block (cards) with canonical Money amounts: the block owns the empty state, the host owns loading/error and an inline order detail.",
|
|
101
101
|
},
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
import { useCallback, useEffect, useRef } from 'react'
|
|
15
15
|
import type { ReactNode } from 'react'
|
|
16
16
|
import { Button } from '@thorprovider/blocks/ui/button'
|
|
17
|
-
import { LoginPage } from '@thorprovider/blocks'
|
|
18
|
-
import
|
|
17
|
+
import { LoginPage, OrderHistory, formatMoney } from '@thorprovider/blocks'
|
|
18
|
+
import type {
|
|
19
|
+
OrderHistoryLabels,
|
|
20
|
+
OrderHistoryOrder,
|
|
21
|
+
OrderHistoryStatusTone,
|
|
22
|
+
} from '@thorprovider/blocks'
|
|
19
23
|
import SignUpBlock from '@thorprovider/blocks/blocks/application/signup-forms/signup-page-1'
|
|
20
24
|
import { useStateStore } from '@json-render/react'
|
|
21
25
|
import type { Customer } from '@thorprovider/types'
|
|
@@ -89,43 +93,39 @@ function ReconcilingStatus() {
|
|
|
89
93
|
)
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
// The
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
interface BlockOrder {
|
|
104
|
-
id: string
|
|
105
|
-
date: string
|
|
106
|
-
status: string
|
|
107
|
-
total: string
|
|
108
|
-
items: BlockOrderItem[]
|
|
96
|
+
// Backend order status → badge tone. The status model belongs to the host (the
|
|
97
|
+
// block never compares a status string), so this map is the storefront's own
|
|
98
|
+
// vocabulary; an unknown status keeps the neutral tone and its own label, so no
|
|
99
|
+
// state is invented and no order is mislabelled.
|
|
100
|
+
const ORDER_STATUS_TONES: Record<string, OrderHistoryStatusTone> = {
|
|
101
|
+
pending: 'outline',
|
|
102
|
+
processing: 'secondary',
|
|
103
|
+
completed: 'default',
|
|
104
|
+
cancelled: 'destructive',
|
|
105
|
+
refunded: 'outline',
|
|
109
106
|
}
|
|
110
107
|
|
|
111
|
-
// Map a backend-sourced account order row to the block
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
function toBlockOrder(order: AccountOrderView): BlockOrder {
|
|
108
|
+
// Map a backend-sourced account order row to the canonical block contract.
|
|
109
|
+
// `id` is the REAL backend order id: it is the React key AND the value the block
|
|
110
|
+
// reports, so selection needs no number→id map. Amounts stay canonical `Money`
|
|
111
|
+
// and an absent image/variant is omitted rather than serialized as ''.
|
|
112
|
+
function toOrderHistoryOrder(order: AccountOrderView): OrderHistoryOrder {
|
|
117
113
|
return {
|
|
118
|
-
id: order.
|
|
114
|
+
id: order.id,
|
|
115
|
+
number: order.number,
|
|
119
116
|
date: order.date,
|
|
120
|
-
status:
|
|
117
|
+
status: {
|
|
118
|
+
label: order.status,
|
|
119
|
+
tone: ORDER_STATUS_TONES[order.status] ?? 'secondary',
|
|
120
|
+
},
|
|
121
121
|
total: order.total,
|
|
122
122
|
items: order.items.map((item) => ({
|
|
123
123
|
id: item.id,
|
|
124
124
|
name: item.name,
|
|
125
|
-
image: item.image
|
|
126
|
-
details: item.variant
|
|
127
|
-
price: item.lineTotal,
|
|
125
|
+
...(item.image === undefined ? {} : { image: item.image }),
|
|
126
|
+
...(item.variant === undefined ? {} : { details: item.variant }),
|
|
128
127
|
quantity: item.quantity,
|
|
128
|
+
lineTotal: item.lineTotal,
|
|
129
129
|
})),
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -135,14 +135,20 @@ function toBlockOrder(order: AccountOrderView): BlockOrder {
|
|
|
135
135
|
// the selection so the detail is dismissible (a real open/close cycle, no
|
|
136
136
|
// navigation and no second destination).
|
|
137
137
|
function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: () => void }) {
|
|
138
|
+
// Amounts are formatted at the display site from their own currency; an
|
|
139
|
+
// amount the backend did not supply (or supplied malformed) renders the
|
|
140
|
+
// unavailable marker, never a fabricated zero.
|
|
141
|
+
const amount = (value: AccountOrderView['total']) => formatMoney(value) ?? '—'
|
|
138
142
|
const totals = (
|
|
139
143
|
[
|
|
140
144
|
{ label: 'Subtotal', value: order.subtotal },
|
|
141
145
|
{ label: 'Impuestos', value: order.tax },
|
|
142
146
|
{ label: 'Envío', value: order.shipping },
|
|
143
147
|
{ label: 'Total', value: order.total },
|
|
144
|
-
] as { label: string; value?:
|
|
145
|
-
).filter(
|
|
148
|
+
] as { label: string; value?: AccountOrderView['total'] }[]
|
|
149
|
+
).filter(
|
|
150
|
+
(row): row is { label: string; value: AccountOrderView['total'] } => row.value !== undefined,
|
|
151
|
+
)
|
|
146
152
|
return (
|
|
147
153
|
<div className="mx-auto w-full max-w-7xl px-4 pb-12 sm:px-6 lg:px-8">
|
|
148
154
|
<div className="rounded-lg border p-6">
|
|
@@ -170,7 +176,7 @@ function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: ()
|
|
|
170
176
|
) : null}
|
|
171
177
|
<span className="text-muted-foreground"> × {item.quantity}</span>
|
|
172
178
|
</span>
|
|
173
|
-
<span>{item.lineTotal}</span>
|
|
179
|
+
<span>{amount(item.lineTotal)}</span>
|
|
174
180
|
</li>
|
|
175
181
|
))}
|
|
176
182
|
</ul>
|
|
@@ -178,7 +184,7 @@ function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: ()
|
|
|
178
184
|
{totals.map((row) => (
|
|
179
185
|
<div key={row.label} className="flex justify-between">
|
|
180
186
|
<dt className="text-muted-foreground">{row.label}</dt>
|
|
181
|
-
<dd>{row.value}</dd>
|
|
187
|
+
<dd>{amount(row.value)}</dd>
|
|
182
188
|
</div>
|
|
183
189
|
))}
|
|
184
190
|
</dl>
|
|
@@ -324,12 +330,14 @@ export const registry: ViewRegistry = {
|
|
|
324
330
|
* identity's page lands (a render guard, never the clear mechanism).
|
|
325
331
|
*
|
|
326
332
|
* The backend's real `count` drives pagination, so a page length is never
|
|
327
|
-
* presented as the total
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
+
* presented as the total — the block receives one page and renders exactly it.
|
|
334
|
+
* Selection is keyed by the REAL backend order id, which the canonical
|
|
335
|
+
* `OrderHistory` block reports from `onViewOrder(id)`, and the detail is
|
|
336
|
+
* assembled from the fetched row; the selection id survives paging (returning
|
|
337
|
+
* to the order's page reopens it) and is dismissible with the inline close
|
|
338
|
+
* control. A failed page load shows an actionable retry that re-runs the SAME
|
|
339
|
+
* page (never a fabricated empty history). No token is read, stored, or
|
|
340
|
+
* rendered here.
|
|
333
341
|
*/
|
|
334
342
|
AccountOrders: ({ props }) => {
|
|
335
343
|
const { state, set, getSnapshot } = useStateStore()
|
|
@@ -445,8 +453,14 @@ export const registry: ViewRegistry = {
|
|
|
445
453
|
typeof state.accountSelectedOrderId === 'string' ? state.accountSelectedOrderId : null
|
|
446
454
|
// Selection is keyed by the REAL backend order id, never the display number.
|
|
447
455
|
const selected = selectedId ? orders.find((order) => order.id === selectedId) ?? null : null
|
|
448
|
-
// The block
|
|
449
|
-
|
|
456
|
+
// The canonical block's labels, with the legacy per-key copy (still present in
|
|
457
|
+
// user-owned `content.ts` of an older store) folded in front of them.
|
|
458
|
+
const labels: Partial<OrderHistoryLabels> = {
|
|
459
|
+
...(parsed.labels ?? {}),
|
|
460
|
+
...(parsed.titleLabel === undefined ? {} : { title: parsed.titleLabel }),
|
|
461
|
+
...(parsed.descriptionLabel === undefined ? {} : { description: parsed.descriptionLabel }),
|
|
462
|
+
...(parsed.emptyLabel === undefined ? {} : { emptyLabel: parsed.emptyLabel }),
|
|
463
|
+
}
|
|
450
464
|
|
|
451
465
|
// A reconciliation in flight (task 4.2) hides the held rows rather than
|
|
452
466
|
// presenting them as current. This component stays MOUNTED (its `loadedKeyRef`
|
|
@@ -489,29 +503,17 @@ export const registry: ViewRegistry = {
|
|
|
489
503
|
</div>
|
|
490
504
|
)
|
|
491
505
|
}
|
|
492
|
-
if (orders.length === 0) {
|
|
493
|
-
return (
|
|
494
|
-
<p
|
|
495
|
-
role="status"
|
|
496
|
-
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
497
|
-
>
|
|
498
|
-
{parsed.emptyLabel ?? 'Aún no tienes pedidos.'}
|
|
499
|
-
</p>
|
|
500
|
-
)
|
|
501
|
-
}
|
|
502
506
|
const totalPages = Math.max(1, Math.ceil(count / pageSize))
|
|
503
507
|
return (
|
|
504
508
|
<>
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
set('/accountSelectedOrderId', backendIdByBlockId.get(order.id) ?? null)
|
|
514
|
-
}
|
|
509
|
+
{/* The empty history is the block's own state (`labels.emptyLabel`), so
|
|
510
|
+
there is one empty implementation and no fabricated order. Selection
|
|
511
|
+
is reported by backend order id — no number→id map. */}
|
|
512
|
+
<OrderHistory
|
|
513
|
+
orders={orders.map(toOrderHistoryOrder)}
|
|
514
|
+
presentation="cards"
|
|
515
|
+
labels={labels}
|
|
516
|
+
onViewOrder={(id) => set('/accountSelectedOrderId', id)}
|
|
515
517
|
/>
|
|
516
518
|
{count > pageSize ? (
|
|
517
519
|
<div className="mx-auto flex w-full max-w-7xl items-center justify-between gap-4 px-4 pb-6 sm:px-6 lg:px-8">
|
|
@@ -33,15 +33,35 @@ export const accountRegisterPropsSchema = z.object({
|
|
|
33
33
|
signInLabel: z.string().optional(),
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
// Mirrors the
|
|
37
|
-
// explicit loading/
|
|
36
|
+
// Mirrors the canonical `OrderHistory` label contract the curated view forwards
|
|
37
|
+
// (`labels: Partial<OrderHistoryLabels>`), plus the explicit loading/error copy
|
|
38
|
+
// the registry renders when the block itself cannot be shown. The legacy
|
|
39
|
+
// `titleLabel`/`descriptionLabel`/`emptyLabel` keys are still accepted because
|
|
40
|
+
// `content.ts` is user-owned and survives `sync`; the registry folds them into
|
|
41
|
+
// `labels` instead of dropping a store's copy.
|
|
42
|
+
export const accountOrdersLabelsSchema = z.object({
|
|
43
|
+
title: z.string().optional(),
|
|
44
|
+
description: z.string().optional(),
|
|
45
|
+
orderLabel: z.string().optional(),
|
|
46
|
+
placedOnLabel: z.string().optional(),
|
|
47
|
+
quantityLabel: z.string().optional(),
|
|
48
|
+
totalLabel: z.string().optional(),
|
|
49
|
+
viewOrderLabel: z.string().optional(),
|
|
50
|
+
trackOrderLabel: z.string().optional(),
|
|
51
|
+
amountUnavailableLabel: z.string().optional(),
|
|
52
|
+
emptyLabel: z.string().optional(),
|
|
53
|
+
})
|
|
54
|
+
|
|
38
55
|
export const accountOrdersPropsSchema = z.object({
|
|
56
|
+
labels: accountOrdersLabelsSchema.optional(),
|
|
57
|
+
errorLabel: z.string().optional(),
|
|
58
|
+
loadingLabel: z.string().optional(),
|
|
59
|
+
/** @deprecated Folded into `labels.title`; kept for existing user content. */
|
|
39
60
|
titleLabel: z.string().optional(),
|
|
61
|
+
/** @deprecated Folded into `labels.description`; kept for existing user content. */
|
|
40
62
|
descriptionLabel: z.string().optional(),
|
|
41
|
-
|
|
63
|
+
/** @deprecated Folded into `labels.emptyLabel`; kept for existing user content. */
|
|
42
64
|
emptyLabel: z.string().optional(),
|
|
43
|
-
errorLabel: z.string().optional(),
|
|
44
|
-
loadingLabel: z.string().optional(),
|
|
45
65
|
})
|
|
46
66
|
|
|
47
67
|
// The headless bootstrap and the signed-in panel read their data from the
|
|
@@ -8,8 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { Breadcrumb as BreadcrumbBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/breadcrumb'
|
|
10
10
|
import ProductOverviewBlock from '@thorprovider/blocks/blocks/e-commerce/product-overview/product-overview'
|
|
11
|
-
import
|
|
11
|
+
import ReviewComposerBlock from '@thorprovider/blocks/blocks/e-commerce/reviews/review-composer'
|
|
12
|
+
import ReviewListBlock from '@thorprovider/blocks/blocks/e-commerce/reviews/review-list'
|
|
13
|
+
import ReviewSummaryBlock from '@thorprovider/blocks/blocks/e-commerce/reviews/review-summary'
|
|
12
14
|
import { isAvailableMoney } from '@thorprovider/blocks/contracts'
|
|
15
|
+
import type { ReviewDistribution, ReviewItemData } from '@thorprovider/blocks'
|
|
13
16
|
import { useStateStore } from '@json-render/react'
|
|
14
17
|
import { useProductVisitObservation } from '../../section-observation'
|
|
15
18
|
import type { ViewRegistry } from '../types'
|
|
@@ -88,20 +91,115 @@ export const registry: ViewRegistry = {
|
|
|
88
91
|
},
|
|
89
92
|
Reviews: ({ props, emit }) => {
|
|
90
93
|
const parsed = reviewsPropsSchema.parse(props)
|
|
94
|
+
// The review array is real backend data; the aggregate is derived here, at
|
|
95
|
+
// the host boundary, because the block must never invent one and never
|
|
96
|
+
// derive from review content it renders.
|
|
97
|
+
const reviews: ReviewItemData[] = parsed.reviews.map((review) => ({
|
|
98
|
+
id: review.id,
|
|
99
|
+
author: review.author ?? review.userName ?? '',
|
|
100
|
+
...(review.avatar ?? review.userAvatar
|
|
101
|
+
? { avatar: (review.avatar ?? review.userAvatar) as string }
|
|
102
|
+
: {}),
|
|
103
|
+
date: review.date,
|
|
104
|
+
...(review.dateTime === undefined ? {} : { dateTime: review.dateTime }),
|
|
105
|
+
rating: review.rating,
|
|
106
|
+
content: review.content,
|
|
107
|
+
...(review.helpfulCount ?? review.likes
|
|
108
|
+
? { helpfulCount: (review.helpfulCount ?? review.likes) as number }
|
|
109
|
+
: {}),
|
|
110
|
+
...(review.likedByViewer === undefined ? {} : { likedByViewer: review.likedByViewer }),
|
|
111
|
+
}))
|
|
112
|
+
const summary = parsed.summary ?? deriveReviewSummary(reviews)
|
|
113
|
+
const listLabels = {
|
|
114
|
+
...(parsed.labels ?? {}),
|
|
115
|
+
...(parsed.pageTitle === undefined ? {} : { title: parsed.pageTitle }),
|
|
116
|
+
...(parsed.pageDescription === undefined ? {} : { description: parsed.pageDescription }),
|
|
117
|
+
}
|
|
118
|
+
const composerLabels = parsed.composer?.labels ?? legacyComposerLabels(parsed.form)
|
|
119
|
+
|
|
91
120
|
return (
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
121
|
+
<div className='mx-auto flex w-full max-w-7xl flex-col gap-6 px-4 py-8 sm:px-6 lg:px-8'>
|
|
122
|
+
{summary ? (
|
|
123
|
+
<ReviewSummaryBlock
|
|
124
|
+
averageRating={summary.averageRating}
|
|
125
|
+
totalReviews={summary.totalReviews}
|
|
126
|
+
distribution={summary.distribution}
|
|
127
|
+
/>
|
|
128
|
+
) : null}
|
|
129
|
+
<ReviewListBlock
|
|
130
|
+
reviews={reviews}
|
|
131
|
+
{...(parsed.presentation === undefined ? {} : { presentation: parsed.presentation })}
|
|
132
|
+
labels={listLabels}
|
|
133
|
+
onToggleLike={() => {
|
|
134
|
+
emit('toggleReviewLike')
|
|
135
|
+
}}
|
|
136
|
+
/>
|
|
137
|
+
{parsed.composer || parsed.form ? (
|
|
138
|
+
<ReviewComposerBlock
|
|
139
|
+
{...(composerLabels === undefined ? {} : { labels: composerLabels })}
|
|
140
|
+
{...(parsed.composer?.isSubmitting === undefined
|
|
141
|
+
? {}
|
|
142
|
+
: { isSubmitting: parsed.composer.isSubmitting })}
|
|
143
|
+
{...(parsed.composer?.error === undefined ? {} : { error: parsed.composer.error })}
|
|
144
|
+
onSubmit={() => {
|
|
145
|
+
emit('submitReview')
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
) : null}
|
|
149
|
+
</div>
|
|
105
150
|
)
|
|
106
151
|
},
|
|
107
152
|
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Derive the required aggregate from the real review array the product view
|
|
156
|
+
* already holds. This is host-side data ownership, not block behaviour: the
|
|
157
|
+
* summary block never receives `reviews` and never computes an average.
|
|
158
|
+
*/
|
|
159
|
+
export function deriveReviewSummary(
|
|
160
|
+
reviews: ReviewItemData[],
|
|
161
|
+
):
|
|
162
|
+
| { averageRating: number; totalReviews: number; distribution: ReviewDistribution }
|
|
163
|
+
| undefined {
|
|
164
|
+
if (reviews.length === 0) return undefined
|
|
165
|
+
const distribution: ReviewDistribution = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 }
|
|
166
|
+
let sum = 0
|
|
167
|
+
for (const review of reviews) {
|
|
168
|
+
const bucket = Math.min(5, Math.max(1, Math.round(review.rating))) as 1 | 2 | 3 | 4 | 5
|
|
169
|
+
distribution[bucket] += 1
|
|
170
|
+
sum += review.rating
|
|
171
|
+
}
|
|
172
|
+
return { averageRating: sum / reviews.length, totalReviews: reviews.length, distribution }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Map the numbered form copy onto the canonical composer labels. */
|
|
176
|
+
function legacyComposerLabels(
|
|
177
|
+
form:
|
|
178
|
+
| {
|
|
179
|
+
title: string
|
|
180
|
+
description?: string
|
|
181
|
+
nameLabel: string
|
|
182
|
+
emailLabel: string
|
|
183
|
+
reviewLabel: string
|
|
184
|
+
namePlaceholder: string
|
|
185
|
+
emailPlaceholder: string
|
|
186
|
+
reviewPlaceholder: string
|
|
187
|
+
submitButtonText: string
|
|
188
|
+
submittingButtonText: string
|
|
189
|
+
}
|
|
190
|
+
| undefined,
|
|
191
|
+
): Record<string, string> | undefined {
|
|
192
|
+
if (!form) return undefined
|
|
193
|
+
return {
|
|
194
|
+
title: form.title,
|
|
195
|
+
...(form.description === undefined ? {} : { description: form.description }),
|
|
196
|
+
nameLabel: form.nameLabel,
|
|
197
|
+
emailLabel: form.emailLabel,
|
|
198
|
+
reviewLabel: form.reviewLabel,
|
|
199
|
+
namePlaceholder: form.namePlaceholder,
|
|
200
|
+
emailPlaceholder: form.emailPlaceholder,
|
|
201
|
+
reviewPlaceholder: form.reviewPlaceholder,
|
|
202
|
+
submitLabel: form.submitButtonText,
|
|
203
|
+
submittingLabel: form.submittingButtonText,
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -103,21 +103,45 @@ export const productOverviewPropsSchema = z.object({
|
|
|
103
103
|
freeDeliveryLabel: z.string().optional(),
|
|
104
104
|
})
|
|
105
105
|
|
|
106
|
-
// Mirrors
|
|
106
|
+
// Mirrors the canonical review item cell (real reviews only; never seeded).
|
|
107
|
+
// The legacy `userName`/`userAvatar`/`likes`/`comments` keys stay accepted so a
|
|
108
|
+
// user-owned content file authored against the numbered block keeps parsing;
|
|
109
|
+
// the registry maps them onto the canonical fields.
|
|
107
110
|
export const reviewSchema = z.object({
|
|
108
|
-
id: z.number(),
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
id: z.union([z.string(), z.number()]).transform((value) => String(value)),
|
|
112
|
+
author: z.string().optional(),
|
|
113
|
+
avatar: z.string().optional(),
|
|
111
114
|
date: z.string(),
|
|
115
|
+
dateTime: z.string().optional(),
|
|
112
116
|
rating: z.number(),
|
|
113
117
|
content: z.string(),
|
|
118
|
+
helpfulCount: z.number().optional(),
|
|
119
|
+
likedByViewer: z.boolean().optional(),
|
|
120
|
+
userName: z.string().optional(),
|
|
121
|
+
userAvatar: z.string().optional(),
|
|
114
122
|
likes: z.number().optional(),
|
|
115
123
|
comments: z.number().optional(),
|
|
116
124
|
})
|
|
117
125
|
|
|
126
|
+
// Mirrors the canonical aggregate unit: every value is required, so a summary
|
|
127
|
+
// is rendered only when the host can supply all of it.
|
|
128
|
+
export const reviewSummarySchema = z.object({
|
|
129
|
+
averageRating: z.number(),
|
|
130
|
+
totalReviews: z.number(),
|
|
131
|
+
distribution: z.object({
|
|
132
|
+
1: z.number(),
|
|
133
|
+
2: z.number(),
|
|
134
|
+
3: z.number(),
|
|
135
|
+
4: z.number(),
|
|
136
|
+
5: z.number(),
|
|
137
|
+
}),
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
// Legacy composer copy from the numbered form. Accepted and mapped; new content
|
|
141
|
+
// should author `composer.labels` instead.
|
|
118
142
|
export const reviewFormSchema = z.object({
|
|
119
143
|
title: z.string(),
|
|
120
|
-
description: z.string(),
|
|
144
|
+
description: z.string().optional(),
|
|
121
145
|
nameLabel: z.string(),
|
|
122
146
|
emailLabel: z.string(),
|
|
123
147
|
reviewLabel: z.string(),
|
|
@@ -128,10 +152,21 @@ export const reviewFormSchema = z.object({
|
|
|
128
152
|
submittingButtonText: z.string(),
|
|
129
153
|
})
|
|
130
154
|
|
|
155
|
+
export const reviewComposerSchema = z.object({
|
|
156
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
157
|
+
isSubmitting: z.boolean().optional(),
|
|
158
|
+
error: z.string().optional(),
|
|
159
|
+
})
|
|
160
|
+
|
|
131
161
|
export const reviewsPropsSchema = z.object({
|
|
132
|
-
pageTitle: z.string(),
|
|
133
|
-
pageDescription: z.string().optional(),
|
|
134
162
|
reviews: z.array(reviewSchema),
|
|
163
|
+
summary: reviewSummarySchema.optional(),
|
|
164
|
+
presentation: z.enum(['list', 'carousel']).optional(),
|
|
165
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
166
|
+
composer: reviewComposerSchema.optional(),
|
|
167
|
+
// Legacy keys kept for user-owned content compatibility.
|
|
168
|
+
pageTitle: z.string().optional(),
|
|
169
|
+
pageDescription: z.string().optional(),
|
|
135
170
|
form: reviewFormSchema.optional(),
|
|
136
171
|
reviewsPerPage: z.number().optional(),
|
|
137
172
|
})
|
package/bin/storefront.js
CHANGED
|
@@ -57,10 +57,12 @@ import { scaffoldComposition } from '../scripts/starter.mjs'
|
|
|
57
57
|
import {
|
|
58
58
|
buildInstallPlan,
|
|
59
59
|
CANDIDATE_TOOLSET,
|
|
60
|
+
DEFAULT_REGISTRY,
|
|
60
61
|
findPack,
|
|
61
62
|
parseRuntimeCommerceImports,
|
|
62
63
|
verifyPackExports,
|
|
63
64
|
verifyPackManifest,
|
|
65
|
+
verifyRegistryToolset,
|
|
64
66
|
} from '../scripts/candidate.mjs'
|
|
65
67
|
import {
|
|
66
68
|
declaredOperativeSkills,
|
|
@@ -999,6 +1001,25 @@ async function create(args) {
|
|
|
999
1001
|
return 1
|
|
1000
1002
|
}
|
|
1001
1003
|
|
|
1004
|
+
// Registry preflight: the default path installs exact versions from npm, so
|
|
1005
|
+
// every pin must exist and expose the surface the templates import. This runs
|
|
1006
|
+
// after composition/contract validation and before the first mkdir, external
|
|
1007
|
+
// scaffold, or write. `--packs` is a local development path with its own
|
|
1008
|
+
// packed-candidate guards, so it does not contact the registry.
|
|
1009
|
+
if (!args.packs) {
|
|
1010
|
+
const registry = await verifyRegistryToolset({
|
|
1011
|
+
toolset: CANDIDATE_TOOLSET,
|
|
1012
|
+
cliVersion,
|
|
1013
|
+
templatesDir: join(PKG_ROOT, 'assets', 'templates'),
|
|
1014
|
+
registry: process.env.STOREFRONT_REGISTRY_URL || DEFAULT_REGISTRY,
|
|
1015
|
+
})
|
|
1016
|
+
if (!registry.ok) {
|
|
1017
|
+
console.error('Refusing to create: the pinned candidate is not installable from the registry.')
|
|
1018
|
+
for (const err of registry.errors) console.error(` ${err.code}: ${err.message}`)
|
|
1019
|
+
return 1
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1002
1023
|
console.log('storefront create — deterministic scaffold')
|
|
1003
1024
|
console.log(` name: ${name}`)
|
|
1004
1025
|
console.log(` site name: ${siteName}`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thorprovider/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Deterministic storefront scaffolder and installable OpenCode skill suite for Thor Commerce (Next.js, @thorprovider/blocks, @thorprovider/adapters, Medusa)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "bin/storefront.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"pretest": "node ./scripts/sync-assets.mjs --check",
|
|
24
24
|
"test": "vitest run --config vitest.config.ts",
|
|
25
25
|
"test:integration": "vitest run --config vitest.config.ts tests/scaffold-integration.test.ts tests/starter-integration.test.ts",
|
|
26
|
+
"test:registry": "RUN_SCAFFOLD_INTEGRATION=1 STOREFRONT_ACCEPTANCE_CLI=registry vitest run --config vitest.config.ts tests/scaffold-integration.test.ts tests/starter-integration.test.ts",
|
|
26
27
|
"test:browser": "node ./tests/support/projection-ownership.browser.mjs"
|
|
27
28
|
},
|
|
28
29
|
"publishConfig": {
|
package/recipes/archetypes.json
CHANGED
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
"default": "list",
|
|
80
80
|
"intents": {
|
|
81
81
|
"list": {
|
|
82
|
-
"variant": "
|
|
83
|
-
"when": "A
|
|
82
|
+
"variant": "Reviews",
|
|
83
|
+
"when": "A review collection with the required aggregate summary above it and the reviews in a responsive grid (canonical `presentation: 'list'`)."
|
|
84
84
|
},
|
|
85
|
-
"
|
|
86
|
-
"variant": "
|
|
87
|
-
"when": "
|
|
85
|
+
"carousel": {
|
|
86
|
+
"variant": "Reviews",
|
|
87
|
+
"when": "A review collection with the required aggregate summary above it and the reviews in a carousel (canonical `presentation: 'carousel'`)."
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
},
|
|
@@ -146,11 +146,15 @@
|
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
"account.orders": {
|
|
149
|
-
"default": "
|
|
149
|
+
"default": "cards",
|
|
150
150
|
"intents": {
|
|
151
|
-
"
|
|
152
|
-
"variant": "
|
|
153
|
-
"when": "A signed-in shopper's order history with per
|
|
151
|
+
"cards": {
|
|
152
|
+
"variant": "OrderHistory",
|
|
153
|
+
"when": "A signed-in shopper's order history with one card per order and details on demand (canonical `presentation: 'cards'`)."
|
|
154
|
+
},
|
|
155
|
+
"rows": {
|
|
156
|
+
"variant": "OrderHistory",
|
|
157
|
+
"when": "A compact, list-first order history with one bordered row per order (canonical `presentation: 'rows'`)."
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
}
|
package/recipes/catalog.json
CHANGED
|
@@ -106,35 +106,25 @@
|
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
"product.reviews": {
|
|
109
|
-
"default": "
|
|
109
|
+
"default": "Reviews",
|
|
110
110
|
"variants": {
|
|
111
|
-
"
|
|
111
|
+
"Reviews": {
|
|
112
112
|
"status": "executable",
|
|
113
113
|
"block": "Reviews",
|
|
114
|
-
"dataShape": "Review[]",
|
|
114
|
+
"dataShape": "Review[] & ReviewSummaryInput",
|
|
115
115
|
"events": [
|
|
116
116
|
"toggleReviewLike",
|
|
117
117
|
"submitReview"
|
|
118
118
|
],
|
|
119
|
-
"state": "
|
|
120
|
-
"requirements": [
|
|
121
|
-
"productReviews"
|
|
122
|
-
]
|
|
123
|
-
},
|
|
124
|
-
"ReviewRating2": {
|
|
125
|
-
"status": "held",
|
|
126
|
-
"reason": "block requires an aggregate averageRating/ratingDistribution and carousel controls the canonical Review[] shape does not supply; no verified prop bridge exists",
|
|
127
|
-
"block": "Reviews",
|
|
128
|
-
"dataShape": "Review[] & RatingSummary",
|
|
129
|
-
"events": [
|
|
130
|
-
"like",
|
|
131
|
-
"comment"
|
|
132
|
-
],
|
|
133
|
-
"state": "uncontrolled",
|
|
119
|
+
"state": "controlled",
|
|
134
120
|
"requirements": [
|
|
135
121
|
"productReviews"
|
|
136
122
|
]
|
|
137
123
|
}
|
|
124
|
+
},
|
|
125
|
+
"legacyAliases": {
|
|
126
|
+
"ReviewRating1": "Reviews",
|
|
127
|
+
"ReviewRating2": "Reviews"
|
|
138
128
|
}
|
|
139
129
|
},
|
|
140
130
|
"product.breadcrumb": {
|
|
@@ -339,33 +329,24 @@
|
|
|
339
329
|
}
|
|
340
330
|
},
|
|
341
331
|
"account.orders": {
|
|
342
|
-
"default": "
|
|
332
|
+
"default": "OrderHistory",
|
|
343
333
|
"variants": {
|
|
344
|
-
"
|
|
334
|
+
"OrderHistory": {
|
|
345
335
|
"status": "executable",
|
|
346
|
-
"block": "
|
|
347
|
-
"dataShape": "AccountOrderView[] &
|
|
336
|
+
"block": "OrderHistory",
|
|
337
|
+
"dataShape": "AccountOrderView[] & OrderHistoryLabels",
|
|
348
338
|
"events": [
|
|
349
|
-
"
|
|
339
|
+
"viewOrder"
|
|
350
340
|
],
|
|
351
341
|
"state": "controlled",
|
|
352
342
|
"requirements": [
|
|
353
343
|
"accountCustomer",
|
|
354
344
|
"accountAuthenticated"
|
|
355
345
|
]
|
|
356
|
-
},
|
|
357
|
-
"OrderHistory1": {
|
|
358
|
-
"status": "held",
|
|
359
|
-
"reason": "block models one row per order item (an item-row list), the wrong shape for an order-level history; the canonical order list cannot feed it without inventing an aggregate row",
|
|
360
|
-
"block": "OrderHistory1",
|
|
361
|
-
"dataShape": "OrderHistory1Order[]",
|
|
362
|
-
"events": [],
|
|
363
|
-
"state": "controlled",
|
|
364
|
-
"requirements": [
|
|
365
|
-
"accountCustomer",
|
|
366
|
-
"accountAuthenticated"
|
|
367
|
-
]
|
|
368
346
|
}
|
|
347
|
+
},
|
|
348
|
+
"legacyAliases": {
|
|
349
|
+
"OrderHistory2": "OrderHistory"
|
|
369
350
|
}
|
|
370
351
|
},
|
|
371
352
|
"category.breadcrumb": {
|
package/recipes/recipes.json
CHANGED
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
],
|
|
63
63
|
"defaultVariants": {
|
|
64
64
|
"overview": "ProductOverview",
|
|
65
|
-
"reviews": "
|
|
65
|
+
"reviews": "Reviews",
|
|
66
66
|
"breadcrumb": "Breadcrumb"
|
|
67
67
|
},
|
|
68
68
|
"allowedVariants": {
|
|
@@ -70,8 +70,7 @@
|
|
|
70
70
|
"ProductOverview"
|
|
71
71
|
],
|
|
72
72
|
"reviews": [
|
|
73
|
-
"
|
|
74
|
-
"ReviewRating2"
|
|
73
|
+
"Reviews"
|
|
75
74
|
],
|
|
76
75
|
"breadcrumb": [
|
|
77
76
|
"Breadcrumb"
|
|
@@ -210,8 +209,7 @@
|
|
|
210
209
|
"SignUpPage1"
|
|
211
210
|
],
|
|
212
211
|
"orders": [
|
|
213
|
-
"
|
|
214
|
-
"OrderHistory2"
|
|
212
|
+
"OrderHistory"
|
|
215
213
|
]
|
|
216
214
|
},
|
|
217
215
|
"optionalSections": [],
|
package/scripts/candidate.mjs
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// The concrete versions are real (validated against the monorepo's own install
|
|
12
12
|
// and the npm registry); the actual external build is M1 evidence.
|
|
13
13
|
|
|
14
|
-
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
|
14
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import { tmpdir } from 'node:os'
|
|
15
16
|
import { join } from 'node:path'
|
|
16
17
|
import { gunzipSync } from 'node:zlib'
|
|
17
18
|
|
|
@@ -42,10 +43,10 @@ export const CANDIDATE_TOOLSET = Object.freeze({
|
|
|
42
43
|
'@json-render/next': '0.21.0',
|
|
43
44
|
}),
|
|
44
45
|
local: Object.freeze({
|
|
45
|
-
'@thorprovider/blocks': '0.1
|
|
46
|
-
'@thorprovider/adapters': '5.
|
|
47
|
-
'@thorprovider/runtime': '0.1
|
|
48
|
-
'@thorprovider/types': '
|
|
46
|
+
'@thorprovider/blocks': '3.0.1',
|
|
47
|
+
'@thorprovider/adapters': '5.2.1',
|
|
48
|
+
'@thorprovider/runtime': '0.4.1',
|
|
49
|
+
'@thorprovider/types': '7.0.0',
|
|
49
50
|
}),
|
|
50
51
|
})
|
|
51
52
|
|
|
@@ -223,7 +224,9 @@ export function verifyPackExports({ tgzPath, innerPath, requiredExports }) {
|
|
|
223
224
|
* compile away and need no runtime symbol).
|
|
224
225
|
*/
|
|
225
226
|
export function parseRuntimeCommerceImports(source) {
|
|
226
|
-
const block = source.match(
|
|
227
|
+
const block = source.match(
|
|
228
|
+
/import\s*\{([^}]*)\}\s*from\s*['"]@thorprovider\/runtime\/commerce['"]/,
|
|
229
|
+
)
|
|
227
230
|
if (!block) return []
|
|
228
231
|
return block[1]
|
|
229
232
|
.replace(/\/\/[^\n]*/g, '')
|
|
@@ -234,3 +237,274 @@ export function parseRuntimeCommerceImports(source) {
|
|
|
234
237
|
.map((entry) => entry.replace(/^type\s+/, '').split(/\s+as\s+/)[0].trim())
|
|
235
238
|
.filter(Boolean)
|
|
236
239
|
}
|
|
240
|
+
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
// Registry candidate preflight
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
|
|
245
|
+
export const DEFAULT_REGISTRY = 'https://registry.npmjs.org'
|
|
246
|
+
|
|
247
|
+
function registryFailure(code, message) {
|
|
248
|
+
return { ok: false, code, message }
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** The npm registry metadata URL for one exact package version. */
|
|
252
|
+
export function registryMetadataUrl(name, version, registry = DEFAULT_REGISTRY) {
|
|
253
|
+
return `${registry.replace(/\/+$/, '')}/${encodeURIComponent(name)}/${encodeURIComponent(version)}`
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Concrete (non-wildcard) file targets declared by an `exports` map. */
|
|
257
|
+
export function declaredExportTargets(exportsMap) {
|
|
258
|
+
const targets = new Set()
|
|
259
|
+
const visit = (value) => {
|
|
260
|
+
if (typeof value === 'string') {
|
|
261
|
+
if (!value.includes('*')) targets.add(value.replace(/^\.\//, 'package/'))
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(value)) {
|
|
265
|
+
for (const item of value) visit(item)
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
if (value && typeof value === 'object') {
|
|
269
|
+
for (const item of Object.values(value)) visit(item)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (exportsMap) {
|
|
273
|
+
if (typeof exportsMap === 'string' || Array.isArray(exportsMap)) visit(exportsMap)
|
|
274
|
+
else for (const value of Object.values(exportsMap)) visit(value)
|
|
275
|
+
}
|
|
276
|
+
return [...targets]
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Map a `@thorprovider/blocks/...` specifier to its tarball path. */
|
|
280
|
+
export function blockSpecifierPath(specifier) {
|
|
281
|
+
if (specifier === '@thorprovider/blocks') return 'package/dist/index.mjs'
|
|
282
|
+
if (specifier === '@thorprovider/blocks/contracts') return 'package/dist/lib/contracts.mjs'
|
|
283
|
+
if (specifier === '@thorprovider/blocks/styles.css') return 'package/styles.css'
|
|
284
|
+
if (!specifier.startsWith('@thorprovider/blocks/')) return null
|
|
285
|
+
return `package/dist/${specifier.slice('@thorprovider/blocks/'.length)}.mjs`
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Scan template sources for blocks specifiers and runtime/commerce symbols. */
|
|
289
|
+
export function collectTemplateSurface(templatesDir) {
|
|
290
|
+
const blockImports = new Set()
|
|
291
|
+
const runtimeImports = new Set()
|
|
292
|
+
const walk = (dir) => {
|
|
293
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
294
|
+
if (entry.name === 'node_modules' || entry.name === '.next' || entry.name === 'dist') continue
|
|
295
|
+
const path = join(dir, entry.name)
|
|
296
|
+
if (entry.isDirectory()) {
|
|
297
|
+
walk(path)
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
if (!entry.isFile() || !/\.(?:[cm]?[jt]sx?)$/.test(entry.name)) continue
|
|
301
|
+
const source = readFileSync(path, 'utf8')
|
|
302
|
+
const blockRegex = /(?:from\s*|import\s*)['"](@thorprovider\/blocks(?:\/[^'"]*)?)['"]/g
|
|
303
|
+
for (const match of source.matchAll(blockRegex)) blockImports.add(match[1])
|
|
304
|
+
for (const symbol of parseRuntimeCommerceImports(source)) runtimeImports.add(symbol)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (templatesDir && existsSync(templatesDir)) walk(templatesDir)
|
|
308
|
+
return { blockImports: [...blockImports].sort(), runtimeImports: [...runtimeImports].sort() }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Verify a downloaded artifact exposes the surface the generated host needs.
|
|
313
|
+
* `kind: 'blocks'` checks template deep imports and rejects leaked source;
|
|
314
|
+
* `kind: 'runtime'` checks the commerce symbols the templates import.
|
|
315
|
+
*/
|
|
316
|
+
export function verifyRegistryArtifact({
|
|
317
|
+
tgzPath,
|
|
318
|
+
name,
|
|
319
|
+
version,
|
|
320
|
+
kind,
|
|
321
|
+
blockImports = [],
|
|
322
|
+
runtimeImports = [],
|
|
323
|
+
}) {
|
|
324
|
+
const entries = readPackEntries(tgzPath)
|
|
325
|
+
if (!entries) return registryFailure('E_ARTIFACT_INCOMPLETE', `${name}@${version}: tarball is unreadable`)
|
|
326
|
+
const manifest = readPackManifest(tgzPath)
|
|
327
|
+
if (!manifest) {
|
|
328
|
+
return registryFailure('E_ARTIFACT_INCOMPLETE', `${name}@${version}: tarball has no package.json`)
|
|
329
|
+
}
|
|
330
|
+
if (manifest.name !== name || manifest.version !== version) {
|
|
331
|
+
return registryFailure(
|
|
332
|
+
'E_ARTIFACT_INCOMPLETE',
|
|
333
|
+
`${name}@${version}: tarball declares ${manifest.name}@${manifest.version}`,
|
|
334
|
+
)
|
|
335
|
+
}
|
|
336
|
+
const missing = declaredExportTargets(manifest.exports).filter((target) => !entries[target])
|
|
337
|
+
for (const field of ['main', 'types']) {
|
|
338
|
+
const value = manifest[field]
|
|
339
|
+
if (typeof value !== 'string') continue
|
|
340
|
+
const target = `package/${value.replace(/^\.\//, '')}`
|
|
341
|
+
if (!entries[target]) missing.push(target)
|
|
342
|
+
}
|
|
343
|
+
const workspaceLeaks = []
|
|
344
|
+
for (const field of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
|
|
345
|
+
for (const [dependency, range] of Object.entries(manifest[field] ?? {})) {
|
|
346
|
+
if (typeof range === 'string' && range.startsWith('workspace:')) {
|
|
347
|
+
workspaceLeaks.push(`${field}.${dependency}=${range}`)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (workspaceLeaks.length > 0) {
|
|
352
|
+
return registryFailure(
|
|
353
|
+
'E_WORKSPACE_PROTOCOL_LEAK',
|
|
354
|
+
`${name}@${version}: manifest leaks workspace protocol (${workspaceLeaks.join(', ')})`,
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
if (kind === 'blocks') {
|
|
358
|
+
for (const specifier of blockImports) {
|
|
359
|
+
const target = blockSpecifierPath(specifier)
|
|
360
|
+
if (target && !entries[target]) missing.push(target)
|
|
361
|
+
}
|
|
362
|
+
if (Object.keys(entries).some((entry) => entry.startsWith('package/src/'))) {
|
|
363
|
+
missing.push('package/src/ (source must not ship)')
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (missing.length > 0) {
|
|
367
|
+
const unique = [...new Set(missing)]
|
|
368
|
+
return registryFailure('E_ARTIFACT_INCOMPLETE', `${name}@${version}: missing ${unique.join(', ')}`)
|
|
369
|
+
}
|
|
370
|
+
if (kind === 'runtime') {
|
|
371
|
+
const commerce = entries['package/dist/commerce/index.mjs']
|
|
372
|
+
if (!commerce) {
|
|
373
|
+
return registryFailure('E_ARTIFACT_INCOMPLETE', `${name}@${version}: missing dist/commerce/index.mjs`)
|
|
374
|
+
}
|
|
375
|
+
const source = commerce.toString('utf8')
|
|
376
|
+
const missingSymbols = runtimeImports.filter((symbol) => !new RegExp(`\\b${symbol}\\b`).test(source))
|
|
377
|
+
if (missingSymbols.length > 0) {
|
|
378
|
+
return registryFailure(
|
|
379
|
+
'E_RUNTIME_SURFACE_MISMATCH',
|
|
380
|
+
`${name}@${version}: missing runtime export(s): ${missingSymbols.join(', ')}`,
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return { ok: true }
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Resolve one exact pin against the registry. Metadata is always checked; the
|
|
389
|
+
* tarball is downloaded only when the caller needs to inspect its surface.
|
|
390
|
+
*/
|
|
391
|
+
export async function resolveRegistryCandidate({
|
|
392
|
+
name,
|
|
393
|
+
version,
|
|
394
|
+
registry = DEFAULT_REGISTRY,
|
|
395
|
+
fetchImpl = globalThis.fetch,
|
|
396
|
+
downloadTarball = false,
|
|
397
|
+
}) {
|
|
398
|
+
const url = registryMetadataUrl(name, version, registry)
|
|
399
|
+
let response
|
|
400
|
+
try {
|
|
401
|
+
response = await fetchImpl(url, { headers: { accept: 'application/json' } })
|
|
402
|
+
} catch (cause) {
|
|
403
|
+
return registryFailure('E_REGISTRY_UNREACHABLE', `${name}@${version}: cannot reach ${url} (${cause.message})`)
|
|
404
|
+
}
|
|
405
|
+
if (response.status === 404) {
|
|
406
|
+
return registryFailure('E_PIN_UNPUBLISHED', `${name}@${version} is not published on ${registry}`)
|
|
407
|
+
}
|
|
408
|
+
if (!response.ok) {
|
|
409
|
+
return registryFailure('E_REGISTRY_UNREACHABLE', `${name}@${version}: registry responded ${response.status}`)
|
|
410
|
+
}
|
|
411
|
+
let metadata
|
|
412
|
+
try {
|
|
413
|
+
metadata = await response.json()
|
|
414
|
+
} catch {
|
|
415
|
+
return registryFailure('E_ARTIFACT_INCOMPLETE', `${name}@${version}: registry metadata is not JSON`)
|
|
416
|
+
}
|
|
417
|
+
if (metadata.name !== name || metadata.version !== version) {
|
|
418
|
+
return registryFailure(
|
|
419
|
+
'E_ARTIFACT_INCOMPLETE',
|
|
420
|
+
`${name}@${version}: registry metadata declares ${metadata.name}@${metadata.version}`,
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
const tarballUrl = metadata.dist?.tarball
|
|
424
|
+
if (!tarballUrl) {
|
|
425
|
+
return registryFailure('E_ARTIFACT_INCOMPLETE', `${name}@${version}: metadata has no dist.tarball`)
|
|
426
|
+
}
|
|
427
|
+
if (!downloadTarball) return { ok: true, name, version, metadata, tarballUrl }
|
|
428
|
+
|
|
429
|
+
let tarballResponse
|
|
430
|
+
try {
|
|
431
|
+
tarballResponse = await fetchImpl(tarballUrl)
|
|
432
|
+
} catch (cause) {
|
|
433
|
+
return registryFailure(
|
|
434
|
+
'E_REGISTRY_UNREACHABLE',
|
|
435
|
+
`${name}@${version}: cannot download ${tarballUrl} (${cause.message})`,
|
|
436
|
+
)
|
|
437
|
+
}
|
|
438
|
+
if (!tarballResponse.ok) {
|
|
439
|
+
return registryFailure(
|
|
440
|
+
'E_ARTIFACT_INCOMPLETE',
|
|
441
|
+
`${name}@${version}: tarball download responded ${tarballResponse.status}`,
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
let bytes
|
|
445
|
+
try {
|
|
446
|
+
bytes = Buffer.from(await tarballResponse.arrayBuffer())
|
|
447
|
+
} catch {
|
|
448
|
+
return registryFailure('E_ARTIFACT_INCOMPLETE', `${name}@${version}: tarball body is unreadable`)
|
|
449
|
+
}
|
|
450
|
+
const dir = mkdtempSync(join(tmpdir(), 'thor-registry-candidate-'))
|
|
451
|
+
const tgzPath = join(dir, 'package.tgz')
|
|
452
|
+
writeFileSync(tgzPath, bytes)
|
|
453
|
+
return {
|
|
454
|
+
ok: true,
|
|
455
|
+
name,
|
|
456
|
+
version,
|
|
457
|
+
metadata,
|
|
458
|
+
tarballUrl,
|
|
459
|
+
tgzPath,
|
|
460
|
+
cleanup: () => rmSync(dir, { recursive: true, force: true }),
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Resolve every pin in the candidate toolset. Blocks and runtime are also
|
|
466
|
+
* downloaded and inspected; the other packages only need to exist.
|
|
467
|
+
*/
|
|
468
|
+
export async function verifyRegistryToolset({
|
|
469
|
+
toolset = CANDIDATE_TOOLSET,
|
|
470
|
+
cliVersion,
|
|
471
|
+
templatesDir,
|
|
472
|
+
registry = DEFAULT_REGISTRY,
|
|
473
|
+
fetchImpl = globalThis.fetch,
|
|
474
|
+
}) {
|
|
475
|
+
const { blockImports, runtimeImports } = collectTemplateSurface(templatesDir)
|
|
476
|
+
const pins = { ...toolset.local, ...(cliVersion ? { '@thorprovider/storefront': cliVersion } : {}) }
|
|
477
|
+
const resolved = {}
|
|
478
|
+
const errors = []
|
|
479
|
+
for (const [name, version] of Object.entries(pins)) {
|
|
480
|
+
const inspect =
|
|
481
|
+
name === '@thorprovider/blocks' ||
|
|
482
|
+
name === '@thorprovider/runtime' ||
|
|
483
|
+
name === '@thorprovider/adapters'
|
|
484
|
+
const result = await resolveRegistryCandidate({
|
|
485
|
+
name,
|
|
486
|
+
version,
|
|
487
|
+
registry,
|
|
488
|
+
fetchImpl,
|
|
489
|
+
downloadTarball: inspect,
|
|
490
|
+
})
|
|
491
|
+
if (!result.ok) {
|
|
492
|
+
errors.push({ code: result.code, message: result.message })
|
|
493
|
+
continue
|
|
494
|
+
}
|
|
495
|
+
resolved[name] = result
|
|
496
|
+
if (!inspect) continue
|
|
497
|
+
const artifact = verifyRegistryArtifact({
|
|
498
|
+
tgzPath: result.tgzPath,
|
|
499
|
+
name,
|
|
500
|
+
version,
|
|
501
|
+
kind: name === '@thorprovider/blocks' ? 'blocks' : name === '@thorprovider/runtime' ? 'runtime' : 'package',
|
|
502
|
+
blockImports,
|
|
503
|
+
runtimeImports,
|
|
504
|
+
})
|
|
505
|
+
if (!artifact.ok) errors.push({ code: artifact.code, message: artifact.message })
|
|
506
|
+
}
|
|
507
|
+
for (const result of Object.values(resolved)) result.cleanup?.()
|
|
508
|
+
return { ok: errors.length === 0, errors }
|
|
509
|
+
}
|
|
510
|
+
|
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
"default": "list",
|
|
80
80
|
"intents": {
|
|
81
81
|
"list": {
|
|
82
|
-
"variant": "
|
|
83
|
-
"when": "A
|
|
82
|
+
"variant": "Reviews",
|
|
83
|
+
"when": "A review collection with the required aggregate summary above it and the reviews in a responsive grid (canonical `presentation: 'list'`)."
|
|
84
84
|
},
|
|
85
|
-
"
|
|
86
|
-
"variant": "
|
|
87
|
-
"when": "
|
|
85
|
+
"carousel": {
|
|
86
|
+
"variant": "Reviews",
|
|
87
|
+
"when": "A review collection with the required aggregate summary above it and the reviews in a carousel (canonical `presentation: 'carousel'`)."
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
},
|
|
@@ -146,11 +146,15 @@
|
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
"account.orders": {
|
|
149
|
-
"default": "
|
|
149
|
+
"default": "cards",
|
|
150
150
|
"intents": {
|
|
151
|
-
"
|
|
152
|
-
"variant": "
|
|
153
|
-
"when": "A signed-in shopper's order history with per
|
|
151
|
+
"cards": {
|
|
152
|
+
"variant": "OrderHistory",
|
|
153
|
+
"when": "A signed-in shopper's order history with one card per order and details on demand (canonical `presentation: 'cards'`)."
|
|
154
|
+
},
|
|
155
|
+
"rows": {
|
|
156
|
+
"variant": "OrderHistory",
|
|
157
|
+
"when": "A compact, list-first order history with one bordered row per order (canonical `presentation: 'rows'`)."
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
}
|
|
@@ -106,35 +106,25 @@
|
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
"product.reviews": {
|
|
109
|
-
"default": "
|
|
109
|
+
"default": "Reviews",
|
|
110
110
|
"variants": {
|
|
111
|
-
"
|
|
111
|
+
"Reviews": {
|
|
112
112
|
"status": "executable",
|
|
113
113
|
"block": "Reviews",
|
|
114
|
-
"dataShape": "Review[]",
|
|
114
|
+
"dataShape": "Review[] & ReviewSummaryInput",
|
|
115
115
|
"events": [
|
|
116
116
|
"toggleReviewLike",
|
|
117
117
|
"submitReview"
|
|
118
118
|
],
|
|
119
|
-
"state": "
|
|
120
|
-
"requirements": [
|
|
121
|
-
"productReviews"
|
|
122
|
-
]
|
|
123
|
-
},
|
|
124
|
-
"ReviewRating2": {
|
|
125
|
-
"status": "held",
|
|
126
|
-
"reason": "block requires an aggregate averageRating/ratingDistribution and carousel controls the canonical Review[] shape does not supply; no verified prop bridge exists",
|
|
127
|
-
"block": "Reviews",
|
|
128
|
-
"dataShape": "Review[] & RatingSummary",
|
|
129
|
-
"events": [
|
|
130
|
-
"like",
|
|
131
|
-
"comment"
|
|
132
|
-
],
|
|
133
|
-
"state": "uncontrolled",
|
|
119
|
+
"state": "controlled",
|
|
134
120
|
"requirements": [
|
|
135
121
|
"productReviews"
|
|
136
122
|
]
|
|
137
123
|
}
|
|
124
|
+
},
|
|
125
|
+
"legacyAliases": {
|
|
126
|
+
"ReviewRating1": "Reviews",
|
|
127
|
+
"ReviewRating2": "Reviews"
|
|
138
128
|
}
|
|
139
129
|
},
|
|
140
130
|
"product.breadcrumb": {
|
|
@@ -339,33 +329,24 @@
|
|
|
339
329
|
}
|
|
340
330
|
},
|
|
341
331
|
"account.orders": {
|
|
342
|
-
"default": "
|
|
332
|
+
"default": "OrderHistory",
|
|
343
333
|
"variants": {
|
|
344
|
-
"
|
|
334
|
+
"OrderHistory": {
|
|
345
335
|
"status": "executable",
|
|
346
|
-
"block": "
|
|
347
|
-
"dataShape": "AccountOrderView[] &
|
|
336
|
+
"block": "OrderHistory",
|
|
337
|
+
"dataShape": "AccountOrderView[] & OrderHistoryLabels",
|
|
348
338
|
"events": [
|
|
349
|
-
"
|
|
339
|
+
"viewOrder"
|
|
350
340
|
],
|
|
351
341
|
"state": "controlled",
|
|
352
342
|
"requirements": [
|
|
353
343
|
"accountCustomer",
|
|
354
344
|
"accountAuthenticated"
|
|
355
345
|
]
|
|
356
|
-
},
|
|
357
|
-
"OrderHistory1": {
|
|
358
|
-
"status": "held",
|
|
359
|
-
"reason": "block models one row per order item (an item-row list), the wrong shape for an order-level history; the canonical order list cannot feed it without inventing an aggregate row",
|
|
360
|
-
"block": "OrderHistory1",
|
|
361
|
-
"dataShape": "OrderHistory1Order[]",
|
|
362
|
-
"events": [],
|
|
363
|
-
"state": "controlled",
|
|
364
|
-
"requirements": [
|
|
365
|
-
"accountCustomer",
|
|
366
|
-
"accountAuthenticated"
|
|
367
|
-
]
|
|
368
346
|
}
|
|
347
|
+
},
|
|
348
|
+
"legacyAliases": {
|
|
349
|
+
"OrderHistory2": "OrderHistory"
|
|
369
350
|
}
|
|
370
351
|
},
|
|
371
352
|
"category.breadcrumb": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
],
|
|
63
63
|
"defaultVariants": {
|
|
64
64
|
"overview": "ProductOverview",
|
|
65
|
-
"reviews": "
|
|
65
|
+
"reviews": "Reviews",
|
|
66
66
|
"breadcrumb": "Breadcrumb"
|
|
67
67
|
},
|
|
68
68
|
"allowedVariants": {
|
|
@@ -70,8 +70,7 @@
|
|
|
70
70
|
"ProductOverview"
|
|
71
71
|
],
|
|
72
72
|
"reviews": [
|
|
73
|
-
"
|
|
74
|
-
"ReviewRating2"
|
|
73
|
+
"Reviews"
|
|
75
74
|
],
|
|
76
75
|
"breadcrumb": [
|
|
77
76
|
"Breadcrumb"
|
|
@@ -210,8 +209,7 @@
|
|
|
210
209
|
"SignUpPage1"
|
|
211
210
|
],
|
|
212
211
|
"orders": [
|
|
213
|
-
"
|
|
214
|
-
"OrderHistory2"
|
|
212
|
+
"OrderHistory"
|
|
215
213
|
]
|
|
216
214
|
},
|
|
217
215
|
"optionalSections": [],
|