@thorprovider/storefront 0.4.0-mvp.0 → 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 +174 -156
- package/VENDOR.md +69 -0
- package/assets/openspec/config.yaml +38 -0
- package/assets/templates/AGENTS.md +76 -0
- package/assets/templates/app/app/[[...slug]]/page.tsx +56 -2
- package/assets/templates/app/app/[[...slug]]/renderer.tsx +44 -2
- package/assets/templates/app/app/globals.css +5 -8
- package/assets/templates/app/app/layout.tsx +1 -5
- package/assets/templates/app/app/robots.ts +9 -3
- package/assets/templates/app/app/sitemap.ts +64 -5
- 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 +135 -16
- package/assets/templates/app/lib/__STOREFRONT__/catalog.ts +19 -9
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +61 -0
- package/assets/templates/app/lib/__STOREFRONT__/composition.ts +26 -0
- package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +36 -4
- 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 +123 -62
- package/assets/templates/app/lib/__STOREFRONT__/runtime.ts +3 -0
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +78 -25
- package/assets/templates/app/lib/__STOREFRONT__/section-observation.ts +182 -0
- package/assets/templates/app/lib/__STOREFRONT__/section-sources.ts +128 -0
- package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +31 -7
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +4 -0
- package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +81 -26
- package/assets/templates/app/lib/__STOREFRONT__/spec/seo.ts +165 -0
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +4 -2
- package/assets/templates/app/lib/__STOREFRONT__/store-context.ts +26 -7
- 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/index.ts +2 -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 +100 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/products.tsx +19 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +39 -0
- 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/checkout/handlers.ts +6 -0
- package/assets/templates/features/customer-auth/handlers.ts +19 -23
- package/assets/templates/features/customer-auth/state.ts +31 -1
- package/assets/templates/views/account/index.tsx +20 -8
- package/assets/templates/views/account/registry.tsx +294 -154
- package/assets/templates/views/account/schema.ts +1 -0
- package/assets/templates/views/cart/content.ts +11 -0
- package/assets/templates/views/cart/data.ts +23 -0
- package/assets/templates/views/cart/index.tsx +53 -0
- package/assets/templates/views/cart/props.ts +12 -0
- package/assets/templates/views/cart/registry.tsx +82 -0
- package/assets/templates/views/cart/schema.ts +52 -0
- package/assets/templates/views/category/assembly/assembly.json +2 -1
- package/assets/templates/views/category/assembly/index.skeleton.tsx +64 -6
- package/assets/templates/views/category/assembly/registry.skeleton.tsx +7 -6
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/binding.json +5 -0
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/catalog.part +4 -0
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/element.part +7 -0
- package/assets/templates/views/category/assembly/slots/breadcrumb/Breadcrumb/registry.part +18 -0
- package/assets/templates/views/category/index.tsx +76 -7
- package/assets/templates/views/category/props.ts +7 -0
- package/assets/templates/views/category/registry.tsx +25 -6
- package/assets/templates/views/category/schema.ts +13 -0
- package/assets/templates/views/checkout/registry.tsx +3 -5
- package/assets/templates/views/home/assembly/assembly.json +12 -3
- package/assets/templates/views/home/assembly/index.skeleton.tsx +24 -5
- 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/StorefrontHero/element.part +5 -0
- package/assets/templates/views/home/assembly/slots/hero/{StorefrontHero1 → StorefrontHero}/registry.part +5 -3
- package/assets/templates/views/home/content.ts +22 -0
- package/assets/templates/views/home/data.ts +9 -0
- package/assets/templates/views/home/index.tsx +34 -11
- package/assets/templates/views/home/props.ts +1 -0
- package/assets/templates/views/home/registry.tsx +41 -17
- package/assets/templates/views/home/schema.ts +141 -24
- package/assets/templates/views/product/data.ts +5 -3
- package/assets/templates/views/product/index.tsx +49 -5
- package/assets/templates/views/product/props.ts +7 -0
- package/assets/templates/views/product/registry.tsx +34 -5
- package/assets/templates/views/product/schema.ts +49 -1
- package/assets/templates/views/static/content.ts +4 -4
- package/assets/templates/views/static/index.tsx +1 -1
- package/bin/storefront.js +1231 -154
- package/examples/merchandising/category-led.json +37 -0
- package/examples/merchandising/collection-led.json +37 -0
- package/package.json +10 -7
- package/recipes/archetypes.json +33 -46
- package/recipes/catalog.json +245 -153
- package/recipes/catalog.mjs +10 -0
- package/recipes/catalog.schema.json +4 -0
- package/recipes/features.json +28 -5
- package/recipes/recipe.schema.json +1 -1
- package/recipes/recipes.json +159 -59
- package/recipes/sections.json +10 -0
- package/recipes/validate.mjs +75 -4
- package/scripts/candidate.mjs +4 -4
- package/scripts/composers.mjs +25 -5
- package/scripts/env-file.mjs +86 -0
- package/scripts/file-classes.mjs +15 -0
- package/scripts/migrate-english-routes.mjs +276 -0
- package/scripts/ownership-conflict.mjs +5 -2
- package/scripts/pinning.mjs +74 -5
- package/scripts/plan-apply.mjs +149 -5
- package/scripts/reconcile.mjs +49 -11
- package/scripts/render-templates.mjs +97 -44
- package/scripts/section-config.mjs +253 -0
- package/scripts/starter.mjs +17 -0
- package/scripts/theme/color.mjs +185 -0
- package/scripts/theme/css-theme.mjs +233 -0
- package/scripts/theme/fonts.mjs +123 -0
- package/scripts/theme/import-export.mjs +125 -0
- package/scripts/theme/preset.mjs +93 -0
- package/scripts/theme/theme-plan.mjs +292 -0
- package/scripts/theme/tokens.mjs +137 -0
- package/scripts/view-assembly.mjs +57 -3
- package/scripts/view-selection.mjs +1 -1
- package/skills/sf-feature/SKILL.md +32 -19
- package/skills/sf-setup/SKILL.md +79 -0
- package/skills/sf-theme-gen/SKILL.md +99 -36
- package/skills/sf-theme-gen/references/shadcn-theming.md +87 -0
- package/skills/{shadcn-theming/references/templates → sf-theme-gen/references}/theme-setup.md +15 -19
- package/skills/{shadcn-theming → sf-theme-gen}/references/theming-guide.md +6 -11
- package/skills/sf-view-gen/SKILL.md +63 -40
- package/skills/sf-view-gen/assets/recipes/archetypes.json +33 -46
- package/skills/sf-view-gen/assets/recipes/catalog.json +245 -153
- package/skills/sf-view-gen/assets/recipes/catalog.schema.json +4 -0
- package/skills/sf-view-gen/assets/recipes/features.json +28 -5
- package/skills/sf-view-gen/assets/recipes/recipes.json +159 -59
- package/skills/sf-view-gen/assets/recipes/sections.json +10 -0
- 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 +100 -0
- package/skills/sf-view-gen/assets/templates/views/sections/products.tsx +19 -0
- package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +39 -0
- 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/{json-render-core/SKILL.md → sf-view-gen/references/json-render-core.md} +4 -27
- package/skills/{json-render-next/SKILL.md → sf-view-gen/references/json-render-next.md} +5 -8
- package/skills/{json-render-react/SKILL.md → sf-view-gen/references/json-render-react.md} +3 -5
- package/skills/{json-render-shadcn/SKILL.md → sf-view-gen/references/json-render-shadcn.md} +3 -5
- package/skills/sf-view-gen/references/views.md +28 -37
- package/skills/sf-view-gen/scripts/catalog.mjs +10 -0
- package/skills/sf-view-gen/scripts/validate.mjs +75 -4
- package/skills/storefront-workflow/SKILL.md +94 -31
- package/skills/{storefront-best-practices/reference/design.md → storefront-workflow/references/design-consistency.md} +13 -29
- package/CHANGELOG.md +0 -84
- 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/hero/StorefrontHero1/element.part +0 -5
- package/assets/templates/views/user-panel/index.tsx +0 -106
- package/assets/templates/views/user-panel/registry.tsx +0 -54
- package/assets/templates/views/user-panel/schema.ts +0 -79
- package/commands/sf-add-view.md +0 -57
- package/commands/sf-feature.md +0 -28
- package/commands/sf-theme.md +0 -26
- package/commands/sf-view.md +0 -67
- package/skills/building-storefronts/SKILL.md +0 -178
- package/skills/building-storefronts/references/frontend-integration.md +0 -229
- package/skills/json-render-remotion/SKILL.md +0 -111
- package/skills/json-render-solid/SKILL.md +0 -204
- package/skills/nextjs-shadcn/SKILL.md +0 -367
- package/skills/nextjs-shadcn/references/architecture.md +0 -499
- package/skills/nextjs-shadcn/references/project-setup.md +0 -162
- package/skills/nextjs-shadcn/references/shadcn-platform.md +0 -261
- package/skills/nextjs-shadcn/references/sidebar.md +0 -274
- package/skills/nextjs-shadcn/references/styling.md +0 -555
- package/skills/shadcn-component-discovery/SKILL.md +0 -273
- package/skills/shadcn-component-discovery/references/registries.md +0 -226
- package/skills/shadcn-theming/SKILL.md +0 -104
- package/skills/storefront-best-practices/SKILL.md +0 -421
- package/skills/storefront-best-practices/reference/components/breadcrumbs.md +0 -123
- package/skills/storefront-best-practices/reference/components/cart-popup.md +0 -189
- package/skills/storefront-best-practices/reference/components/country-selector.md +0 -298
- package/skills/storefront-best-practices/reference/components/footer.md +0 -112
- package/skills/storefront-best-practices/reference/components/hero.md +0 -241
- package/skills/storefront-best-practices/reference/components/megamenu.md +0 -239
- package/skills/storefront-best-practices/reference/components/navbar.md +0 -397
- package/skills/storefront-best-practices/reference/components/popups.md +0 -221
- package/skills/storefront-best-practices/reference/components/product-card.md +0 -125
- package/skills/storefront-best-practices/reference/components/product-reviews.md +0 -217
- package/skills/storefront-best-practices/reference/components/product-slider.md +0 -174
- package/skills/storefront-best-practices/reference/components/search.md +0 -101
- package/skills/storefront-best-practices/reference/connecting-to-backend.md +0 -391
- package/skills/storefront-best-practices/reference/features/promotions.md +0 -307
- package/skills/storefront-best-practices/reference/features/wishlist.md +0 -230
- package/skills/storefront-best-practices/reference/layouts/account.md +0 -380
- package/skills/storefront-best-practices/reference/layouts/cart.md +0 -316
- package/skills/storefront-best-practices/reference/layouts/checkout.md +0 -486
- package/skills/storefront-best-practices/reference/layouts/home-page.md +0 -264
- package/skills/storefront-best-practices/reference/layouts/order-confirmation.md +0 -231
- package/skills/storefront-best-practices/reference/layouts/product-details.md +0 -527
- package/skills/storefront-best-practices/reference/layouts/product-listing.md +0 -520
- package/skills/storefront-best-practices/reference/layouts/static-pages.md +0 -356
- package/skills/storefront-best-practices/reference/medusa.md +0 -307
- /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/skills/{storefront-best-practices/reference → storefront-workflow/references}/mobile-responsiveness.md +0 -0
- /package/skills/{storefront-best-practices/reference → storefront-workflow/references}/seo.md +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Generated by Thor Commerce storefront (template: assets/templates/app/lib/__STOREFRONT__/account-user.core.ts)
|
|
2
|
+
//
|
|
3
|
+
// Pure, framework-free mapper from the allowlisted account identity
|
|
4
|
+
// (`./account-session.core`) to the navbar block's `StoreUser` shape.
|
|
5
|
+
//
|
|
6
|
+
// The navbar account menu renders `@thorprovider/blocks`' `StoreUser`
|
|
7
|
+
// (`{ name, email, avatar?, initials }`), which differs from the allowlisted
|
|
8
|
+
// identity (`{ id, email, firstName|null, lastName|null }`). The mapping lives
|
|
9
|
+
// in this DERIVED module — regenerated by the CLI — rather than in the
|
|
10
|
+
// user-owned `mappers.ts` (seeded once, never rewritten by `reconcile`, so a new
|
|
11
|
+
// required export there would break older storefronts on upgrade).
|
|
12
|
+
//
|
|
13
|
+
// No Next.js/React, no I/O, no env: the same identity always maps to the same
|
|
14
|
+
// user, and the block dependency is `import type` only (erased at build).
|
|
15
|
+
|
|
16
|
+
import type { StoreUser } from '@thorprovider/blocks'
|
|
17
|
+
import type { AccountIdentity } from './account-session.core'
|
|
18
|
+
|
|
19
|
+
/** Trim a nullable name, collapsing `null`/`undefined`/whitespace to `''`. */
|
|
20
|
+
function namePart(value: string | null | undefined): string {
|
|
21
|
+
return value?.trim() ?? ''
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The email local-part: text before the first `@` (empty when there is none). */
|
|
25
|
+
function emailLocalPart(email: string): string {
|
|
26
|
+
const at = email.indexOf('@')
|
|
27
|
+
return (at === -1 ? email : email.slice(0, at)).trim()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Deterministic uppercase initials for the display name. When both name parts
|
|
32
|
+
* are present, the first character of each; otherwise the first two characters
|
|
33
|
+
* of the resolved name (the single name part, or the email local-part).
|
|
34
|
+
* `toUpperCase` (not `toLocaleUpperCase`) keeps the rule locale-independent.
|
|
35
|
+
*/
|
|
36
|
+
function initialsOf(firstName: string, lastName: string, displayName: string): string {
|
|
37
|
+
if (firstName !== '' && lastName !== '') {
|
|
38
|
+
return (firstName[0] + lastName[0]).toUpperCase()
|
|
39
|
+
}
|
|
40
|
+
return displayName.slice(0, 2).toUpperCase()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Map one allowlisted account identity to the navbar `StoreUser`, or `null`
|
|
45
|
+
* when there is no authenticated identity (so the account menu is not
|
|
46
|
+
* rendered). `name` joins the trimmed names with a single space and falls back
|
|
47
|
+
* to the email local-part when both are absent; `avatar` is always absent, so
|
|
48
|
+
* the block renders its initials fallback instead of an empty image source.
|
|
49
|
+
*/
|
|
50
|
+
export function accountStoreUser(identity: AccountIdentity | null): StoreUser | null {
|
|
51
|
+
if (!identity) return null
|
|
52
|
+
|
|
53
|
+
const firstName = namePart(identity.firstName)
|
|
54
|
+
const lastName = namePart(identity.lastName)
|
|
55
|
+
const joined = [firstName, lastName].filter((part) => part !== '').join(' ')
|
|
56
|
+
// Never an empty name while an email exists: the local-part is the documented
|
|
57
|
+
// fallback, and the full email covers a degenerate local-part-less address.
|
|
58
|
+
const displayName = joined !== '' ? joined : emailLocalPart(identity.email) || identity.email
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
name: displayName,
|
|
62
|
+
email: identity.email,
|
|
63
|
+
initials: initialsOf(firstName, lastName, displayName),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -27,14 +27,16 @@ import {
|
|
|
27
27
|
createGuestCart,
|
|
28
28
|
endSession,
|
|
29
29
|
loadCheckoutCountries,
|
|
30
|
-
loadCustomer,
|
|
31
30
|
loadOrders,
|
|
31
|
+
loadOrdersPage,
|
|
32
32
|
loadPaymentMethods,
|
|
33
|
+
loadProductDetail,
|
|
33
34
|
loadShippingMethods,
|
|
34
35
|
readCart,
|
|
35
36
|
reconcileOrder,
|
|
36
37
|
registerShopper,
|
|
37
38
|
removeLine,
|
|
39
|
+
resolveProductCartTarget,
|
|
38
40
|
saveShippingAddress,
|
|
39
41
|
selectShipping,
|
|
40
42
|
setLineQuantity,
|
|
@@ -45,6 +47,8 @@ import {
|
|
|
45
47
|
type CartStatePatch,
|
|
46
48
|
type PlaceOrderResult,
|
|
47
49
|
} from './commerce'
|
|
50
|
+
import { readAccountSession } from './account-session'
|
|
51
|
+
import { accountIdentitySchema, type AccountIdentity } from './account-session.core'
|
|
48
52
|
import { getStoreContext } from './store-context'
|
|
49
53
|
import {
|
|
50
54
|
bindHostSessionCart,
|
|
@@ -78,9 +82,26 @@ type CheckoutActionResult =
|
|
|
78
82
|
}
|
|
79
83
|
| { ok: false; error: string; fieldErrors?: CheckoutFieldErrors }
|
|
80
84
|
|
|
81
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Structured result for a login/register auth action. It carries ONLY the
|
|
87
|
+
* allowlisted display identity (id/email/names) — never a token or customer
|
|
88
|
+
* metadata — so the client can project it into shared account state directly.
|
|
89
|
+
* An identity that fails the display allowlist is a failure, never a claimed
|
|
90
|
+
* authenticated state.
|
|
91
|
+
*/
|
|
82
92
|
type AuthActionResult =
|
|
83
|
-
| { ok: true; customer:
|
|
93
|
+
| { ok: true; customer: AccountIdentity | null }
|
|
94
|
+
| { ok: false; error: string }
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Structured result for the reader-backed current-customer load. It carries
|
|
98
|
+
* only the allowlisted display identity — never a token or customer metadata.
|
|
99
|
+
* `AccountIdentity` is a structural subset of `Customer` (whose other fields
|
|
100
|
+
* are optional), so this stays assignable wherever the legacy auth result is
|
|
101
|
+
* consumed.
|
|
102
|
+
*/
|
|
103
|
+
type AccountActionResult =
|
|
104
|
+
| { ok: true; customer: AccountIdentity | null }
|
|
84
105
|
| { ok: false; error: string }
|
|
85
106
|
|
|
86
107
|
/** Structured result for logout; the authoritative cookie clear is the outcome. */
|
|
@@ -91,6 +112,11 @@ type OrdersActionResult =
|
|
|
91
112
|
| { ok: true; orders: AccountOrderView[] }
|
|
92
113
|
| { ok: false; error: string }
|
|
93
114
|
|
|
115
|
+
/** Structured result for a paginated customer order-history load. */
|
|
116
|
+
type OrdersPageActionResult =
|
|
117
|
+
| { ok: true; orders: AccountOrderView[]; count: number; limit: number; offset: number }
|
|
118
|
+
| { ok: false; error: string }
|
|
119
|
+
|
|
94
120
|
/** Basic email shape check; a boundary guard, not a full RFC validation. */
|
|
95
121
|
const EMAIL_PATTERN = /\S+@\S+\.\S+/
|
|
96
122
|
|
|
@@ -108,6 +134,20 @@ function toError(error: unknown, fallback: string): string {
|
|
|
108
134
|
return error instanceof Error && error.message.trim() !== '' ? error.message : fallback
|
|
109
135
|
}
|
|
110
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Allowlist a backend customer to the serializable display identity before it
|
|
139
|
+
* crosses the Server Action boundary. Returns `null` for a confirmed anonymous
|
|
140
|
+
* result, the parsed identity for a valid customer, and `undefined` for a
|
|
141
|
+
* response that fails the allowlist (for example a missing id/email) so the
|
|
142
|
+
* caller reports a failure instead of storing an unrestricted customer object
|
|
143
|
+
* (design D1: only id/email/names may enter client state; no token/metadata).
|
|
144
|
+
*/
|
|
145
|
+
function toDisplayIdentity(customer: Customer | null): AccountIdentity | null | undefined {
|
|
146
|
+
if (!customer) return null
|
|
147
|
+
const parsed = accountIdentitySchema.safeParse(customer)
|
|
148
|
+
return parsed.success ? parsed.data : undefined
|
|
149
|
+
}
|
|
150
|
+
|
|
111
151
|
/**
|
|
112
152
|
* Resolve the active cart id, creating and binding a new backend cart when the
|
|
113
153
|
* session has none or its cart was completed. A new cart after a completed one
|
|
@@ -152,6 +192,36 @@ export async function addToCartAction(input: {
|
|
|
152
192
|
}
|
|
153
193
|
}
|
|
154
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Add a product's FIRST purchasable variant by the public product handle the
|
|
197
|
+
* card presents — the product-card shortcut. The variant is resolved server-side
|
|
198
|
+
* from the backend detail (card data carries no variant ids); a product with no
|
|
199
|
+
* purchasable variant returns a truthful error and adds nothing. The product
|
|
200
|
+
* detail remains the explicit-selection surface (change
|
|
201
|
+
* storefront-card-add-to-cart-handle-resolution).
|
|
202
|
+
*/
|
|
203
|
+
export async function addToCartByHandleAction(input: {
|
|
204
|
+
productHandle: string
|
|
205
|
+
quantity?: number
|
|
206
|
+
}): Promise<CartActionResult> {
|
|
207
|
+
try {
|
|
208
|
+
const productHandle =
|
|
209
|
+
typeof input?.productHandle === 'string' ? input.productHandle : ''
|
|
210
|
+
if (productHandle === '') return { ok: false, error: 'Producto no válido.' }
|
|
211
|
+
const quantity =
|
|
212
|
+
Number.isFinite(input?.quantity) && (input.quantity as number) > 0
|
|
213
|
+
? Math.floor(input.quantity as number)
|
|
214
|
+
: 1
|
|
215
|
+
const { detail } = await loadProductDetail(productHandle)
|
|
216
|
+
const target = resolveProductCartTarget(detail)
|
|
217
|
+
if (!target.ok) return { ok: false, error: target.error }
|
|
218
|
+
const { cartId, context } = await ensureActiveCartId()
|
|
219
|
+
return { ok: true, cart: await addVariant(cartId, target.variantId, quantity, context) }
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return { ok: false, error: toError(error, 'No se pudo agregar el producto.') }
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
155
225
|
/** Set a backend cart line to an ABSOLUTE quantity by its line-item id. */
|
|
156
226
|
export async function setLineQuantityAction(input: {
|
|
157
227
|
lineId: string
|
|
@@ -436,8 +506,13 @@ export async function loginAction(input: {
|
|
|
436
506
|
if (outcome.requiresAction) {
|
|
437
507
|
return { ok: false, error: 'Se requiere un paso adicional para iniciar sesión.' }
|
|
438
508
|
}
|
|
509
|
+
const identity = toDisplayIdentity(outcome.customer)
|
|
510
|
+
if (identity === undefined) {
|
|
511
|
+
logServerError('loginAction', new Error('customer failed the display allowlist'))
|
|
512
|
+
return { ok: false, error: 'No se pudo verificar la cuenta.' }
|
|
513
|
+
}
|
|
439
514
|
if (outcome.token) await writeAuthToken(context, outcome.token)
|
|
440
|
-
return { ok: true, customer:
|
|
515
|
+
return { ok: true, customer: identity }
|
|
441
516
|
} catch (error) {
|
|
442
517
|
logServerError('loginAction', error)
|
|
443
518
|
return { ok: false, error: toError(error, 'No se pudo iniciar sesión.') }
|
|
@@ -477,8 +552,13 @@ export async function registerAction(input: {
|
|
|
477
552
|
if (outcome.requiresAction) {
|
|
478
553
|
return { ok: false, error: 'Se requiere un paso adicional para iniciar sesión.' }
|
|
479
554
|
}
|
|
555
|
+
const identity = toDisplayIdentity(outcome.customer)
|
|
556
|
+
if (identity === undefined) {
|
|
557
|
+
logServerError('registerAction', new Error('customer failed the display allowlist'))
|
|
558
|
+
return { ok: false, error: 'No se pudo verificar la cuenta.' }
|
|
559
|
+
}
|
|
480
560
|
if (outcome.token) await writeAuthToken(context, outcome.token)
|
|
481
|
-
return { ok: true, customer:
|
|
561
|
+
return { ok: true, customer: identity }
|
|
482
562
|
} catch (error) {
|
|
483
563
|
logServerError('registerAction', error)
|
|
484
564
|
return { ok: false, error: toError(error, 'No se pudo crear la cuenta.') }
|
|
@@ -505,17 +585,22 @@ export async function logoutAction(): Promise<LogoutActionResult> {
|
|
|
505
585
|
}
|
|
506
586
|
}
|
|
507
587
|
|
|
508
|
-
/**
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
588
|
+
/**
|
|
589
|
+
* Resolve the current customer from the verified auth cookie, or null. It
|
|
590
|
+
* reuses the shared host session reader so the account action and the server
|
|
591
|
+
* render agree on cookie/customer resolution. The result carries only the
|
|
592
|
+
* allowlisted display identity (id/email/names), never metadata or a token, and
|
|
593
|
+
* an operational failure stays a retryable error rather than a fake sign-out.
|
|
594
|
+
*/
|
|
595
|
+
export async function loadAccountAction(): Promise<AccountActionResult> {
|
|
596
|
+
const outcome = await readAccountSession()
|
|
597
|
+
if (outcome.status === 'authenticated') return { ok: true, customer: outcome.identity }
|
|
598
|
+
if (outcome.status === 'anonymous') return { ok: true, customer: null }
|
|
599
|
+
// Keep the sanitized detail in the server log; the shopper sees the
|
|
600
|
+
// established Spanish wording. An outage stays a retryable error, never a
|
|
601
|
+
// claim that the session ended.
|
|
602
|
+
logServerError('loadAccountAction', outcome.error)
|
|
603
|
+
return { ok: false, error: 'No se pudo cargar la cuenta.' }
|
|
519
604
|
}
|
|
520
605
|
|
|
521
606
|
// ---------------------------------------------------------------------------
|
|
@@ -540,3 +625,37 @@ export async function loadOrdersAction(): Promise<OrdersActionResult> {
|
|
|
540
625
|
return { ok: false, error: toError(error, 'No se pudieron cargar tus pedidos.') }
|
|
541
626
|
}
|
|
542
627
|
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Load ONE bounded page of the authenticated customer's channel-scoped order
|
|
631
|
+
* history through the additive paginated contract, returning the backend's real
|
|
632
|
+
* `count`. A missing token resolves to an empty page with `count: 0` without
|
|
633
|
+
* contacting the backend. This action touches ONLY the auth cookie — never the
|
|
634
|
+
* guest session cookie or the cart — and no token is logged or returned.
|
|
635
|
+
*/
|
|
636
|
+
export async function loadOrdersPageAction(input?: {
|
|
637
|
+
page?: number
|
|
638
|
+
pageSize?: number
|
|
639
|
+
}): Promise<OrdersPageActionResult> {
|
|
640
|
+
const context = getStoreContext()
|
|
641
|
+
const token = await readAuthToken(context)
|
|
642
|
+
const page = Number.isInteger(input?.page) && (input?.page as number) > 0 ? (input?.page as number) : 1
|
|
643
|
+
const pageSize =
|
|
644
|
+
Number.isInteger(input?.pageSize) && (input?.pageSize as number) > 0
|
|
645
|
+
? (input?.pageSize as number)
|
|
646
|
+
: 10
|
|
647
|
+
if (!token) return { ok: true, orders: [], count: 0, limit: pageSize, offset: (page - 1) * pageSize }
|
|
648
|
+
try {
|
|
649
|
+
const result = await loadOrdersPage(token, { page, pageSize }, context)
|
|
650
|
+
return {
|
|
651
|
+
ok: true,
|
|
652
|
+
orders: result.orders,
|
|
653
|
+
count: result.count,
|
|
654
|
+
limit: result.limit,
|
|
655
|
+
offset: result.offset,
|
|
656
|
+
}
|
|
657
|
+
} catch (error) {
|
|
658
|
+
logServerError('loadOrdersPageAction', error)
|
|
659
|
+
return { ok: false, error: toError(error, 'No se pudieron cargar tus pedidos.') }
|
|
660
|
+
}
|
|
661
|
+
}
|
|
@@ -7,11 +7,13 @@ import { defineCatalog } from '@json-render/core'
|
|
|
7
7
|
import { schema } from '@json-render/react/schema'
|
|
8
8
|
import { z } from 'zod'
|
|
9
9
|
import {
|
|
10
|
+
backToTopPropsSchema,
|
|
10
11
|
bannerPropsSchema,
|
|
11
|
-
cartDrawerPropsSchema,
|
|
12
12
|
footerPropsSchema,
|
|
13
|
+
mobileBottomNavPropsSchema,
|
|
13
14
|
navbarPropsSchema,
|
|
14
|
-
|
|
15
|
+
productGridPropsSchema,
|
|
16
|
+
skipToContentPropsSchema,
|
|
15
17
|
storefrontNavbarPropsSchema,
|
|
16
18
|
} from './schema'
|
|
17
19
|
import { views } from './views'
|
|
@@ -43,22 +45,30 @@ const baseComponents = {
|
|
|
43
45
|
props: storefrontNavbarPropsSchema,
|
|
44
46
|
description: 'Store navigation bar with category menu and cart.',
|
|
45
47
|
},
|
|
46
|
-
CartDrawer: {
|
|
47
|
-
props: cartDrawerPropsSchema,
|
|
48
|
-
description: 'Slide-over shopping cart.',
|
|
49
|
-
},
|
|
50
48
|
Banner: {
|
|
51
49
|
props: bannerPropsSchema,
|
|
52
50
|
description: 'Announcement banner above the header.',
|
|
53
51
|
},
|
|
54
|
-
|
|
55
|
-
props:
|
|
56
|
-
description: '
|
|
52
|
+
ProductGrid: {
|
|
53
|
+
props: productGridPropsSchema,
|
|
54
|
+
description: 'Product grid listing, rendered as a grid of product cells.',
|
|
57
55
|
},
|
|
58
56
|
Footer: {
|
|
59
57
|
props: footerPropsSchema,
|
|
60
58
|
description: 'Site footer.',
|
|
61
59
|
},
|
|
60
|
+
SkipToContent: {
|
|
61
|
+
props: skipToContentPropsSchema,
|
|
62
|
+
description: 'Keyboard bypass link to the main content landmark.',
|
|
63
|
+
},
|
|
64
|
+
BackToTop: {
|
|
65
|
+
props: backToTopPropsSchema,
|
|
66
|
+
description: 'Scroll-to-top control revealed past a threshold.',
|
|
67
|
+
},
|
|
68
|
+
MobileBottomNav: {
|
|
69
|
+
props: mobileBottomNavPropsSchema,
|
|
70
|
+
description: 'Mobile-only bottom navigation for primary destinations.',
|
|
71
|
+
},
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
const viewComponents = Object.assign({}, ...views.map((view) => view.catalog))
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
getCheckoutCountries,
|
|
40
40
|
getCurrentCustomer,
|
|
41
41
|
getCustomerOrders,
|
|
42
|
+
getCustomerOrdersPage,
|
|
42
43
|
getEligibleShippingMethods,
|
|
43
44
|
getPaymentMethodsByRegion,
|
|
44
45
|
getProductDetailByHandle,
|
|
@@ -47,6 +48,7 @@ import {
|
|
|
47
48
|
reconcileCart,
|
|
48
49
|
registerCustomer,
|
|
49
50
|
removeCartLines,
|
|
51
|
+
selectFirstPurchasableVariant,
|
|
50
52
|
selectShippingMethod,
|
|
51
53
|
toAbsoluteLineUpdate,
|
|
52
54
|
updateCartLines,
|
|
@@ -263,6 +265,29 @@ export async function loadProductDetail(handle: string): Promise<CatalogDetailRe
|
|
|
263
265
|
return { detail, source }
|
|
264
266
|
}
|
|
265
267
|
|
|
268
|
+
/** The resolved add-to-cart target for a product-card shortcut. */
|
|
269
|
+
export type ProductCartTarget =
|
|
270
|
+
| { ok: true; variantId: string }
|
|
271
|
+
| { ok: false; error: string }
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Resolve the product-card add-to-cart target: the product's FIRST purchasable
|
|
275
|
+
* variant (available for sale AND with a resolvable price), identified by its
|
|
276
|
+
* backend variant id. This is the explicit card exception to the product-detail
|
|
277
|
+
* rule that never falls back to a first variant (change
|
|
278
|
+
* storefront-card-add-to-cart). A product with no purchasable variant — or an
|
|
279
|
+
* unknown product — returns a truthful error and adds nothing.
|
|
280
|
+
*/
|
|
281
|
+
export function resolveProductCartTarget(
|
|
282
|
+
detail: CatalogProductDetail | undefined,
|
|
283
|
+
): ProductCartTarget {
|
|
284
|
+
const variant = detail ? selectFirstPurchasableVariant(detail) : undefined
|
|
285
|
+
if (!variant) {
|
|
286
|
+
return { ok: false, error: 'Este producto no tiene variantes disponibles.' }
|
|
287
|
+
}
|
|
288
|
+
return { ok: true, variantId: variant.id }
|
|
289
|
+
}
|
|
290
|
+
|
|
266
291
|
/** The context-scoped backend cart projected for the UI, or undefined when absent. */
|
|
267
292
|
export async function readCart(
|
|
268
293
|
cartId: string,
|
|
@@ -605,4 +630,40 @@ export async function loadOrders(
|
|
|
605
630
|
return orders.map(toAccountOrderView)
|
|
606
631
|
}
|
|
607
632
|
|
|
633
|
+
/**
|
|
634
|
+
* The additive paginated history window projected for the account view.
|
|
635
|
+
* `count` is the backend's real total for the authenticated customer on the
|
|
636
|
+
* store's channel; it is never the page length.
|
|
637
|
+
*/
|
|
638
|
+
export interface AccountOrdersPage {
|
|
639
|
+
orders: AccountOrderView[]
|
|
640
|
+
count: number
|
|
641
|
+
limit: number
|
|
642
|
+
offset: number
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Load one bounded page of the authenticated customer's channel-scoped history
|
|
647
|
+
* through the additive paginated contract. A missing token yields an empty page
|
|
648
|
+
* with `count: 0` (the runtime builds no provider); it never fabricates an order.
|
|
649
|
+
*/
|
|
650
|
+
export async function loadOrdersPage(
|
|
651
|
+
token: string | null,
|
|
652
|
+
options: { page?: number; pageSize?: number } = {},
|
|
653
|
+
context: StoreContext = getStoreContext(),
|
|
654
|
+
): Promise<AccountOrdersPage> {
|
|
655
|
+
const page = await getCustomerOrdersPage({
|
|
656
|
+
token,
|
|
657
|
+
page: options.page,
|
|
658
|
+
pageSize: options.pageSize,
|
|
659
|
+
salesChannelId: context.salesChannelId,
|
|
660
|
+
})
|
|
661
|
+
return {
|
|
662
|
+
orders: page.orders.map(toAccountOrderView),
|
|
663
|
+
count: page.count,
|
|
664
|
+
limit: page.limit,
|
|
665
|
+
offset: page.offset,
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
608
669
|
export type { Money }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Generated by Thor Commerce storefront (composition composer: features).
|
|
2
|
+
// Do not edit by hand — the manifest is the source of truth; run `storefront sync`.
|
|
3
|
+
// Installed manifest catalog features, in stable order, with their persisted
|
|
4
|
+
// config. This is the generation seam the catalog URL boundary consumes to
|
|
5
|
+
// reject parameters owned by a feature that is not installed, and the seam the
|
|
6
|
+
// single controlled CategoryFilter2 reads to select its control
|
|
7
|
+
// visibility/config from the installed manifest only.
|
|
8
|
+
|
|
9
|
+
import type { CatalogFeatureName } from '@thorprovider/runtime/contracts'
|
|
10
|
+
|
|
11
|
+
export const mountedFeatures: readonly CatalogFeatureName[] = []
|
|
12
|
+
|
|
13
|
+
// Every installed feature name, unfiltered by the catalog URL boundary. The
|
|
14
|
+
// general presence seam cross-cutting features read to gate their own
|
|
15
|
+
// contributions (e.g. the navigability feature's shell chrome).
|
|
16
|
+
export const mountedFeatureNames: readonly string[] = []
|
|
17
|
+
|
|
18
|
+
export const mountedFeatureConfigs: Partial<Record<string, Record<string, unknown>>> = {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Typed route/action availability derived from the installed manifest. The
|
|
22
|
+
// generated host uses these to hide links to routes that are not installed,
|
|
23
|
+
// so a removed view never leaves an active dead-end navigation target.
|
|
24
|
+
export const cartViewAvailable = false
|
|
25
|
+
|
|
26
|
+
export const checkoutAvailable = false
|
|
@@ -15,6 +15,7 @@ import { useActions, useStateStore } from '@json-render/react'
|
|
|
15
15
|
import { useNextApp } from '@json-render/next'
|
|
16
16
|
import {
|
|
17
17
|
addToCartAction,
|
|
18
|
+
addToCartByHandleAction,
|
|
18
19
|
applyQuantityDeltaAction,
|
|
19
20
|
ensureCartAction,
|
|
20
21
|
loadCartStateAction,
|
|
@@ -22,6 +23,8 @@ import {
|
|
|
22
23
|
setLineQuantityAction,
|
|
23
24
|
} from './actions'
|
|
24
25
|
import type { CartStatePatch } from './commerce'
|
|
26
|
+
import { cartViewAvailable } from './composition'
|
|
27
|
+
import { recordConfirmedTransition } from './section-observation'
|
|
25
28
|
|
|
26
29
|
/** A product-like object the views leave in `/lastClicked` (card/hero shortcut). */
|
|
27
30
|
interface ClickedProduct {
|
|
@@ -81,10 +84,30 @@ export function useCoreHandlers() {
|
|
|
81
84
|
if (result.ok) {
|
|
82
85
|
applyCart(result.cart)
|
|
83
86
|
set('/cartOpen', true)
|
|
87
|
+
// A confirmed cart transition — observed only after the mutation
|
|
88
|
+
// succeeded, and only when a section origin exists (default: off).
|
|
89
|
+
recordConfirmedTransition('cart_add_confirmed')
|
|
84
90
|
} else fail(result.error)
|
|
85
91
|
})
|
|
86
92
|
.catch(onError('addToCart'))
|
|
87
93
|
},
|
|
94
|
+
addClickedToCart: () => {
|
|
95
|
+
// Product-card shortcut: add the clicked product's first purchasable
|
|
96
|
+
// variant. The backend variant id is resolved server-side from the
|
|
97
|
+
// public handle the card carries for navigation.
|
|
98
|
+
const product = get('/lastClicked') as ClickedProduct | null
|
|
99
|
+
if (!product?.id) return
|
|
100
|
+
begin()
|
|
101
|
+
void addToCartByHandleAction({ productHandle: String(product.id) })
|
|
102
|
+
.then((result) => {
|
|
103
|
+
if (result.ok) {
|
|
104
|
+
applyCart(result.cart)
|
|
105
|
+
set('/cartOpen', true)
|
|
106
|
+
recordConfirmedTransition('cart_add_confirmed')
|
|
107
|
+
} else fail(result.error)
|
|
108
|
+
})
|
|
109
|
+
.catch(onError('addClickedToCart'))
|
|
110
|
+
},
|
|
88
111
|
ensureCart: () => {
|
|
89
112
|
begin()
|
|
90
113
|
void ensureCartAction()
|
|
@@ -141,17 +164,26 @@ export function useCoreHandlers() {
|
|
|
141
164
|
openProduct: () => {
|
|
142
165
|
const product = get('/lastClicked') as ClickedProduct | null
|
|
143
166
|
if (!product?.id) return
|
|
144
|
-
navigate(`/
|
|
167
|
+
navigate(`/products/${product.id}`)
|
|
145
168
|
},
|
|
146
169
|
openCategory: () => {
|
|
147
|
-
|
|
148
|
-
|
|
170
|
+
// `/lastCategory` already holds the category href the card was given
|
|
171
|
+
// (`StoreCategory.href`, e.g. `/categories/jackets`); navigate it as-is
|
|
172
|
+
// so the route scope is not prefixed twice.
|
|
173
|
+
const href = get('/lastCategory') as string | null
|
|
174
|
+
navigate(href ?? '/categories')
|
|
149
175
|
},
|
|
150
176
|
goHome: () => {
|
|
151
177
|
set('/cartOpen', false)
|
|
152
178
|
navigate('/')
|
|
153
179
|
},
|
|
154
|
-
goToCart: () =>
|
|
180
|
+
goToCart: () => {
|
|
181
|
+
// Visibility only: dismiss the lateral and go to the review route. The
|
|
182
|
+
// navigation is guarded by the installed composition so a store without
|
|
183
|
+
// the cart view never routes to a missing page.
|
|
184
|
+
set('/cartOpen', false)
|
|
185
|
+
if (cartViewAvailable) navigate('/cart')
|
|
186
|
+
},
|
|
155
187
|
submitReview: () => {},
|
|
156
188
|
toggleReviewLike: () => {},
|
|
157
189
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Kept out of the views so a view module stays a pure server spec; mappers are
|
|
4
4
|
// data-only and imported where the loader builds block props.
|
|
5
5
|
|
|
6
|
-
import type { CardProduct, FeaturedProduct,
|
|
6
|
+
import type { CardProduct, FeaturedProduct, ProductCategoryItem, StoreCategory } from '@thorprovider/blocks'
|
|
7
7
|
|
|
8
8
|
export const CATEGORY_IMAGE_FALLBACK =
|
|
9
9
|
"data:image/svg+xml;charset=utf-8," +
|
|
@@ -11,33 +11,32 @@ export const CATEGORY_IMAGE_FALLBACK =
|
|
|
11
11
|
`<svg xmlns='http://www.w3.org/2000/svg' width='600' height='480'><rect width='100%' height='100%' fill='#e2e8f0'/><g fill='none' stroke='#94a3b8' stroke-width='12' stroke-linecap='round'><path d='M120 240h360M300 120v240'/><path d='M200 180h50M200 240h50M200 300h50'/><path d='M350 180h50M350 240h50M350 300h50'/></g></svg>`,
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
-
/** CardProduct → FeaturedProduct (
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
/** CardProduct → FeaturedProduct (canonical StorefrontHero). Only fields the
|
|
15
|
+
* backend really carries are forwarded: the block renders honest omission for
|
|
16
|
+
* every host-supplied evidence field (brand, rating, reviews, stock, colors). */
|
|
17
17
|
export function toFeaturedProduct(card: CardProduct): FeaturedProduct {
|
|
18
18
|
return {
|
|
19
19
|
id: String(card.id),
|
|
20
20
|
name: card.title,
|
|
21
|
-
brand: '',
|
|
22
21
|
price: card.price,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
isOnSale: Boolean(card.originalPrice),
|
|
22
|
+
// Only a real compare-at price is forwarded: the block renders a discount
|
|
23
|
+
// treatment solely from an `originalPrice > price` pair, and never from a
|
|
24
|
+
// fabricated one. Popularity/review/stock fields are omitted — the block
|
|
25
|
+
// renders nothing for them instead of claiming `rating: 0` or `inStock`.
|
|
26
|
+
originalPrice: card.originalPrice,
|
|
29
27
|
image: card.image ?? '',
|
|
30
|
-
|
|
28
|
+
tag: card.badge,
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
/** StoreCategory (what @thorprovider/runtime/commerce's getCatalog returns) →
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
33
|
+
* ProductCategoryItem (block). The runtime projection keeps only label/href and
|
|
34
|
+
* carries no product count, so `itemCount` is unknown here: it is OMITTED (the
|
|
35
|
+
* block then renders no count) rather than fabricated as `0`. A genuine `0`
|
|
36
|
+
* supplied by a richer source is preserved because `itemCount` is optional.
|
|
37
|
+
* `image` seeds the storefront's editorial category imagery — the brand overlay
|
|
38
|
+
* rekeys it by backend handle; the block also supplies a neutral placeholder. */
|
|
39
|
+
export function toCategoryCard(category: StoreCategory): ProductCategoryItem {
|
|
41
40
|
return {
|
|
42
41
|
id: category.label,
|
|
43
42
|
handle: category.href,
|