@thorprovider/create-thor-app 4.1.0 → 4.1.2
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 +45 -0
- package/dist/index.js +4 -5
- package/package.json +1 -1
- package/templates/default/.agents/AGENTS.md +27 -1
- package/templates/default/ai-validator.json +33 -2
- package/templates/default/app/page.tsx +2 -43
- package/templates/default/components/providers/cart-provider.tsx +0 -12
- package/templates/default/components/providers/commerce-provider.tsx +1 -2
- package/templates/default/components/providers/region-provider.tsx +0 -10
- package/templates/default/docs/README.md +16 -0
- package/templates/default/docs/commerce-api.md +9 -0
- package/templates/default/docs/decision-matrix.md +54 -0
- package/templates/default/docs/patterns.md +112 -0
- package/templates/default/docs/project-structure.md +11 -0
- package/templates/default/docs/rules.md +28 -0
- package/templates/default/lib/commerce.ts +10 -26
- package/templates/default/lib/env.ts +11 -55
- package/templates/default/next-env.d.ts +1 -1
- package/templates/default/package.json +3 -2
package/README.md
CHANGED
|
@@ -426,6 +426,49 @@ The package is structured for maintainability:
|
|
|
426
426
|
| `src/helpers/agents-dir.ts` | .agents/ directory generation (AGENTS.md + context/ + skills/) |
|
|
427
427
|
| `tsup.config.ts` | Build config + template bundling hook |
|
|
428
428
|
|
|
429
|
+
## How V0 is Programmed for ThorBuilder
|
|
430
|
+
|
|
431
|
+
ThorBuilder does not rely on a single prompt. V0 is guided through multiple aligned mechanisms that must stay in sync as the codebase evolves.
|
|
432
|
+
|
|
433
|
+
### Guardrail Layers
|
|
434
|
+
|
|
435
|
+
1. **Template `.agents/AGENTS.md`**
|
|
436
|
+
- Compact mission, architecture, runtime, and conflict-resolution rules
|
|
437
|
+
- Used as project-level instructions and persisted for later chat injection
|
|
438
|
+
|
|
439
|
+
2. **Template docs** (`templates/default/docs/`)
|
|
440
|
+
- `types.md` → domain contracts
|
|
441
|
+
- `commerce-api.md` → all allowed `commerce.*` methods
|
|
442
|
+
- `patterns.md` → canonical implementation patterns
|
|
443
|
+
- `rules.md` → non-negotiable constraints
|
|
444
|
+
- `project-structure.md` → file ownership and boundaries
|
|
445
|
+
- `decision-matrix.md` → fast architecture decisions when prompts create pressure to drift
|
|
446
|
+
|
|
447
|
+
3. **Validator rules** (`templates/default/ai-validator.json`)
|
|
448
|
+
- Regex-based post-generation checks that catch architectural drift
|
|
449
|
+
- Examples: backend SDK imports, raw backend fetches, env gating, alternate backend stacks
|
|
450
|
+
|
|
451
|
+
4. **Dynamic ThorBuilder prompt injection**
|
|
452
|
+
- `thor-commerce-builder/lib/thor-context.ts` injects project config, guardrail policy, and backend guidance at chat time
|
|
453
|
+
- Mode-aware: mock, incomplete real backend config, or live backend configured
|
|
454
|
+
|
|
455
|
+
### Core Programming Rules for V0
|
|
456
|
+
|
|
457
|
+
- Build a **ThorCommerce storefront**, not a generic web app
|
|
458
|
+
- Use **`commerce.*` only** for backend access in starter/app code
|
|
459
|
+
- Never integrate vendors directly via SDKs or raw fetch in L5
|
|
460
|
+
- Respect mock-first / live-immediate runtime behavior
|
|
461
|
+
- Live backend data is authoritative when configured and available
|
|
462
|
+
- Demo fixtures are allowed only for presentation-oriented sections in mock/incomplete mode
|
|
463
|
+
|
|
464
|
+
### Maintenance Rule
|
|
465
|
+
|
|
466
|
+
If you change ThorCommerce architecture, adapters, starter boundaries, or runtime behavior, review **all guardrail layers** together. Do not update AGENTS or validator rules in isolation.
|
|
467
|
+
|
|
468
|
+
See also:
|
|
469
|
+
- `V0_GUARDRAILS_MAINTENANCE.md`
|
|
470
|
+
- `templates/default/docs/decision-matrix.md`
|
|
471
|
+
|
|
429
472
|
### Dual-mode detection
|
|
430
473
|
|
|
431
474
|
`findMonorepoRoot()` walks up the directory tree looking for `packages/core/package.json`:
|
|
@@ -446,6 +489,8 @@ yarn changeset
|
|
|
446
489
|
|
|
447
490
|
Include `@thorprovider/create-thor-app` in a changeset whenever you change the CLI, its bundled template, or any publishable behavior consumers depend on.
|
|
448
491
|
|
|
492
|
+
When a release includes `@thorprovider/types` or `@thorprovider/adapters`, release automation also auto-bumps `@thorprovider/create-thor-app` so the published starter template keeps those dependency versions aligned.
|
|
493
|
+
|
|
449
494
|
---
|
|
450
495
|
|
|
451
496
|
## License
|
package/dist/index.js
CHANGED
|
@@ -918,7 +918,7 @@ async function createApp(opts) {
|
|
|
918
918
|
});
|
|
919
919
|
log(" \u2713 package.json updated", c.green);
|
|
920
920
|
const envOverrides = {
|
|
921
|
-
|
|
921
|
+
...commerceProvider && { NEXT_PUBLIC_COMMERCE_PROVIDER: commerceProvider },
|
|
922
922
|
...commerceApiUrl && { NEXT_PUBLIC_COMMERCE_API_URL: commerceApiUrl },
|
|
923
923
|
...commerceApiKey && { NEXT_PUBLIC_COMMERCE_API_KEY: commerceApiKey }
|
|
924
924
|
};
|
|
@@ -1016,9 +1016,8 @@ async function createApp(opts) {
|
|
|
1016
1016
|
${step++}. Backend already configured (via CLI flags) \u2713`, c.green);
|
|
1017
1017
|
} else {
|
|
1018
1018
|
log(`
|
|
1019
|
-
${step++}.
|
|
1020
|
-
log(
|
|
1021
|
-
log(` When ready, edit ${relPath}/.env and set NEXT_PUBLIC_COMMERCE_PROVIDER, NEXT_PUBLIC_COMMERCE_API_URL, and NEXT_PUBLIC_COMMERCE_API_KEY`, c.yellow);
|
|
1019
|
+
${step++}. Configure your backend:`, c.cyan);
|
|
1020
|
+
log(` Edit ${relPath}/.env with your commerce backend URL and API key`, c.yellow);
|
|
1022
1021
|
}
|
|
1023
1022
|
if (!remoteCreated && !skipRemote) {
|
|
1024
1023
|
const vis = process.env.GITHUB_REPO_VISIBILITY === "public" ? "--public" : "--private";
|
|
@@ -1093,7 +1092,7 @@ if (nodeMajor < NODE_MIN_MAJOR || nodeMajor === NODE_MIN_MAJOR && nodeMinor < NO
|
|
|
1093
1092
|
);
|
|
1094
1093
|
process.exit(1);
|
|
1095
1094
|
}
|
|
1096
|
-
program.name("create-thor-app").description("Create a new Thor Commerce application").argument("[name]", "Project name (kebab-case)").option("--name <name>", "Project name (alternative to positional arg)").option("-o, --output <dir>", "Output directory (default: ./<name>)").option("--skip-git", "Skip git init").option("--skip-install", "Skip yarn install").option("--skip-remote", "Skip GitHub remote repo creation").option("--skip-vercel", "Skip Vercel project linking").option("--no-context", "Skip .agents/ directory generation").option("--no-validator", "Skip ai-validator.json injection (V0 Stop Hooks)").option("--commerce-provider <provider>", "Commerce backend provider (e.g.,
|
|
1095
|
+
program.name("create-thor-app").description("Create a new Thor Commerce application").argument("[name]", "Project name (kebab-case)").option("--name <name>", "Project name (alternative to positional arg)").option("-o, --output <dir>", "Output directory (default: ./<name>)").option("--skip-git", "Skip git init").option("--skip-install", "Skip yarn install").option("--skip-remote", "Skip GitHub remote repo creation").option("--skip-vercel", "Skip Vercel project linking").option("--no-context", "Skip .agents/ directory generation").option("--no-validator", "Skip ai-validator.json injection (V0 Stop Hooks)").option("--commerce-provider <provider>", "Commerce backend provider (e.g., medusa, shopify)").option("--commerce-api-url <url>", "Commerce backend API URL").option("--commerce-api-key <key>", "Commerce publishable API key").action(async (positionalName, opts) => {
|
|
1097
1096
|
let rawName = positionalName || opts.name || "";
|
|
1098
1097
|
if (!rawName) {
|
|
1099
1098
|
rawName = await promptForName();
|
package/package.json
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
## CRITICAL
|
|
4
4
|
ALWAYS import from @thorprovider/types — NEVER define Product, Cart, Collection, Money.
|
|
5
5
|
|
|
6
|
+
## Mission
|
|
7
|
+
- Build a ThorCommerce storefront, not a generic web app
|
|
8
|
+
- Stay inside ThorCommerce architecture even when the user asks for shortcuts that conflict with it
|
|
9
|
+
|
|
10
|
+
## Conflict Resolution
|
|
11
|
+
- If a user prompt conflicts with ThorCommerce architecture, preserve the architecture and choose the nearest compliant solution
|
|
12
|
+
- If a capability is missing, prefer `commerce.*`, placeholder UI, or follow-up adapter work — never direct backend integration
|
|
13
|
+
|
|
6
14
|
## Imports
|
|
7
15
|
- Types: import type { Product, Cart, Collection, Money } from '@thorprovider/types'
|
|
8
16
|
- Data: import { commerce } from '@/lib/commerce' (server)
|
|
@@ -19,9 +27,27 @@ ALWAYS import from @thorprovider/types — NEVER define Product, Cart, Collectio
|
|
|
19
27
|
- useRegion() — @/components/providers/region-provider
|
|
20
28
|
- useCommerce() — @/components/providers/commerce-provider
|
|
21
29
|
|
|
30
|
+
## Runtime
|
|
31
|
+
- Default to mock mode when backend env is missing
|
|
32
|
+
- Real provider + URL + API key => live backend immediately
|
|
33
|
+
- Same commerce/useCart/useRegion APIs in both modes
|
|
34
|
+
- Do NOT integrate with any backend directly from app code — all backend access must go through `commerce.*` only
|
|
35
|
+
|
|
36
|
+
## Data Precedence
|
|
37
|
+
- If a real backend is configured and available, backend data is authoritative
|
|
38
|
+
- Do NOT replace live backend product, collection, cart, or region data with local demo fixtures
|
|
39
|
+
- If a live backend is unreachable, show proper unavailable/error UX instead of faking a real catalog
|
|
40
|
+
|
|
41
|
+
## Demo Data Policy
|
|
42
|
+
- In mock mode or incomplete backend configuration, you MAY create isolated local demo fixtures for presentation-only sections
|
|
43
|
+
- Use demo fixtures for featured grids, hero merchandising, comparison tables, and editorial/demo content
|
|
44
|
+
- Keep demo fixtures typed with @thorprovider/types and isolated in modules like lib/demo-data/* or lib/demo-catalog.ts
|
|
45
|
+
- Do NOT replace the commerce runtime globally with local demo data
|
|
46
|
+
- Do NOT gate storefront rendering on environment-variable checks
|
|
47
|
+
|
|
22
48
|
## Stack
|
|
23
49
|
Next.js 16, React 19, TS strict, Tailwind 4, shadcn/ui.
|
|
24
50
|
Server Components default. 'use client' only for interactivity.
|
|
25
51
|
|
|
26
52
|
## Docs
|
|
27
|
-
docs/types.md (types), docs/patterns.md (examples).
|
|
53
|
+
docs/types.md (types), docs/patterns.md (examples), docs/rules.md (constraints), docs/commerce-api.md (methods).
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
{
|
|
9
9
|
"id": "no-backend-sdk-imports",
|
|
10
10
|
"filePattern": "**/*.{ts,tsx}",
|
|
11
|
-
"pattern": "from\\s+['\"]@medusajs/js-sdk['\"]|from\\s+['\"]@shopify/api['\"]",
|
|
12
|
-
"description": "Never import backend SDKs directly —
|
|
11
|
+
"pattern": "from\\s+['\"]@medusajs/js-sdk['\"]|from\\s+['\"]@shopify/api['\"]|from\\s+['\"]@shopify/storefront-api-client['\"]|from\\s+['\"]@bigcommerce/|from\\s+['\"]@woocommerce/|from\\s+['\"]@spree/|from\\s+['\"]@magento/",
|
|
12
|
+
"description": "Never import backend SDKs directly — all backend integration must go through commerce.* from @/lib/commerce"
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
"id": "no-raw-commerce-fetch",
|
|
@@ -108,12 +108,43 @@
|
|
|
108
108
|
"pattern": "createProvider\\(",
|
|
109
109
|
"description": "Never call createProvider() in app/ — import commerce from @/lib/commerce (singleton)"
|
|
110
110
|
},
|
|
111
|
+
{
|
|
112
|
+
"id": "no-env-gating-in-pages",
|
|
113
|
+
"filePattern": "app/**/*.{ts,tsx}",
|
|
114
|
+
"pattern": "isEnvConfigured\\(|process\\.env\\.NEXT_PUBLIC_COMMERCE_API_(URL|KEY)|process\\.env\\.NEXT_PUBLIC_COMMERCE_PROVIDER",
|
|
115
|
+
"description": "Do not gate storefront rendering on commerce env vars in app code — use the backend-optional runtime and commerce.*"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": "no-provider-branching-in-app",
|
|
119
|
+
"filePattern": "app/**/*.{ts,tsx}",
|
|
120
|
+
"pattern": "NEXT_PUBLIC_COMMERCE_PROVIDER|commerce\\.isMock\\s*\\?|commerce\\.isMock\\s*&&|isMockMode\\s*\\?",
|
|
121
|
+
"description": "Do not create separate app-level provider branches for mock vs live — keep one storefront architecture using commerce.*"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"id": "no-direct-backend-fetch",
|
|
125
|
+
"filePattern": "app/**/*.{ts,tsx}",
|
|
126
|
+
"pattern": "fetch\\(.*(/store/|/admin/|/api/graphql|/graphql|products|collections)",
|
|
127
|
+
"description": "Never integrate with backend endpoints directly from app code — use commerce.* methods only",
|
|
128
|
+
"required": false
|
|
129
|
+
},
|
|
111
130
|
{
|
|
112
131
|
"id": "no-thorprovider-components-import",
|
|
113
132
|
"filePattern": "**/*.{ts,tsx}",
|
|
114
133
|
"pattern": "from\\s+['\"]@thorprovider/components['\"]|from\\s+['\"]@thorprovider/providers['\"]",
|
|
115
134
|
"description": "Do not import from @thorprovider/components or @thorprovider/providers — use local providers from @/components/providers/ and shadcn/ui for UI"
|
|
116
135
|
},
|
|
136
|
+
{
|
|
137
|
+
"id": "no-alternate-backend-stacks-in-app",
|
|
138
|
+
"filePattern": "app/**/*.{ts,tsx}",
|
|
139
|
+
"pattern": "from\\s+['\"]@supabase/|from\\s+['\"]firebase|from\\s+['\"]@prisma/client['\"]|from\\s+['\"]graphql-request['\"]|from\\s+['\"]@apollo/client['\"]",
|
|
140
|
+
"description": "Do not introduce alternate backend/data clients into starter app code — preserve ThorCommerce architecture"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"id": "no-alternate-backend-stacks-in-components",
|
|
144
|
+
"filePattern": "components/**/*.{ts,tsx}",
|
|
145
|
+
"pattern": "from\\s+['\"]@supabase/|from\\s+['\"]firebase|from\\s+['\"]@prisma/client['\"]|from\\s+['\"]graphql-request['\"]|from\\s+['\"]@apollo/client['\"]",
|
|
146
|
+
"description": "Do not introduce alternate backend/data clients into starter UI code — use commerce.* and local providers"
|
|
147
|
+
},
|
|
117
148
|
{
|
|
118
149
|
"id": "use-format-price",
|
|
119
150
|
"filePattern": "**/*.tsx",
|
|
@@ -1,55 +1,14 @@
|
|
|
1
1
|
// V0 replaces this with the actual storefront homepage
|
|
2
2
|
import { commerce } from '@/lib/commerce'
|
|
3
|
-
import { formatPrice } from '@/lib/utils'
|
|
4
3
|
import type { Product } from '@thorprovider/types'
|
|
5
4
|
|
|
6
5
|
export default async function HomePage() {
|
|
7
6
|
const products: Product[] = await commerce.getProducts({ first: 8 })
|
|
8
|
-
const isMockMode = commerce.isMock === true
|
|
9
7
|
|
|
10
8
|
return (
|
|
11
9
|
<main className="container mx-auto px-4 py-8">
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
<h1 className="text-3xl font-bold">Store</h1>
|
|
15
|
-
<p className="text-muted-foreground">{products.length} products available</p>
|
|
16
|
-
</div>
|
|
17
|
-
|
|
18
|
-
<div className="rounded-full border px-4 py-2 text-sm text-muted-foreground">
|
|
19
|
-
{isMockMode
|
|
20
|
-
? 'Using mock catalog — connect a backend to switch to live commerce data.'
|
|
21
|
-
: 'Connected to live commerce data.'}
|
|
22
|
-
</div>
|
|
23
|
-
</div>
|
|
24
|
-
|
|
25
|
-
<div className="mt-8 grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
26
|
-
{products.slice(0, 4).map((product) => {
|
|
27
|
-
const previewPrice = product.variants[0]?.price
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<article key={product.id} className="rounded-xl border bg-card p-4 text-card-foreground">
|
|
31
|
-
<div className="aspect-square overflow-hidden rounded-lg bg-muted">
|
|
32
|
-
{product.featuredImage ? (
|
|
33
|
-
<img
|
|
34
|
-
alt={product.featuredImage.altText || product.title}
|
|
35
|
-
className="h-full w-full object-cover"
|
|
36
|
-
src={product.featuredImage.url}
|
|
37
|
-
/>
|
|
38
|
-
) : null}
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<div className="mt-4 space-y-1">
|
|
42
|
-
<h2 className="font-semibold">{product.title}</h2>
|
|
43
|
-
<p className="line-clamp-2 text-sm text-muted-foreground">{product.description}</p>
|
|
44
|
-
{previewPrice ? (
|
|
45
|
-
<p className="text-sm font-medium">{formatPrice(previewPrice)}</p>
|
|
46
|
-
) : null}
|
|
47
|
-
</div>
|
|
48
|
-
</article>
|
|
49
|
-
)
|
|
50
|
-
})}
|
|
51
|
-
</div>
|
|
52
|
-
|
|
10
|
+
<h1 className="text-3xl font-bold">Store</h1>
|
|
11
|
+
<p className="text-muted-foreground">{products.length} products available</p>
|
|
53
12
|
{/* V0: Generate the actual storefront homepage here */}
|
|
54
13
|
</main>
|
|
55
14
|
)
|
|
@@ -37,7 +37,6 @@ export interface CartContextValue {
|
|
|
37
37
|
const CartContext = createContext<CartContextValue | null>(null)
|
|
38
38
|
|
|
39
39
|
const CART_ID_KEY = 'thor-cart-id'
|
|
40
|
-
const CART_PROVIDER_KEY = 'thor-cart-provider'
|
|
41
40
|
|
|
42
41
|
export function CartProvider({ children }: { children: ReactNode }) {
|
|
43
42
|
const [cart, setCart] = useState<Cart | null>(null)
|
|
@@ -53,15 +52,6 @@ export function CartProvider({ children }: { children: ReactNode }) {
|
|
|
53
52
|
;(async () => {
|
|
54
53
|
try {
|
|
55
54
|
setIsLoading(true)
|
|
56
|
-
const currentProvider = commerce.isMock ? 'mock' : 'live'
|
|
57
|
-
const storedProvider = localStorage.getItem(CART_PROVIDER_KEY)
|
|
58
|
-
|
|
59
|
-
if (storedProvider && storedProvider !== currentProvider) {
|
|
60
|
-
localStorage.removeItem(CART_ID_KEY)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
localStorage.setItem(CART_PROVIDER_KEY, currentProvider)
|
|
64
|
-
|
|
65
55
|
const cartId = localStorage.getItem(CART_ID_KEY)
|
|
66
56
|
if (cartId) {
|
|
67
57
|
const loaded = await commerce.getCart(cartId)
|
|
@@ -84,7 +74,6 @@ export function CartProvider({ children }: { children: ReactNode }) {
|
|
|
84
74
|
const newCart = await commerce.createCart()
|
|
85
75
|
setCart(newCart)
|
|
86
76
|
if (newCart.id) localStorage.setItem(CART_ID_KEY, newCart.id)
|
|
87
|
-
localStorage.setItem(CART_PROVIDER_KEY, commerce.isMock ? 'mock' : 'live')
|
|
88
77
|
return newCart
|
|
89
78
|
}, [cart])
|
|
90
79
|
|
|
@@ -138,7 +127,6 @@ export function CartProvider({ children }: { children: ReactNode }) {
|
|
|
138
127
|
const clearCart = useCallback(() => {
|
|
139
128
|
setCart(null)
|
|
140
129
|
localStorage.removeItem(CART_ID_KEY)
|
|
141
|
-
localStorage.removeItem(CART_PROVIDER_KEY)
|
|
142
130
|
}, [])
|
|
143
131
|
|
|
144
132
|
return (
|
|
@@ -14,14 +14,13 @@ import type { ReactNode } from 'react'
|
|
|
14
14
|
export interface CommerceContextValue {
|
|
15
15
|
/** The commerce adapter instance (same as `@/lib/commerce` export) */
|
|
16
16
|
commerce: typeof commerce
|
|
17
|
-
isMock: boolean
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
const CommerceContext = createContext<CommerceContextValue | null>(null)
|
|
21
20
|
|
|
22
21
|
export function CommerceProvider({ children }: { children: ReactNode }) {
|
|
23
22
|
return (
|
|
24
|
-
<CommerceContext.Provider value={{ commerce
|
|
23
|
+
<CommerceContext.Provider value={{ commerce }}>
|
|
25
24
|
{children}
|
|
26
25
|
</CommerceContext.Provider>
|
|
27
26
|
)
|
|
@@ -30,7 +30,6 @@ export interface RegionContextValue {
|
|
|
30
30
|
const RegionContext = createContext<RegionContextValue | null>(null)
|
|
31
31
|
|
|
32
32
|
const REGION_KEY = 'thor-region-id'
|
|
33
|
-
const REGION_PROVIDER_KEY = 'thor-region-provider'
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* Normalize adapter response to Region type.
|
|
@@ -65,15 +64,6 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
|
|
65
64
|
setIsLoading(true)
|
|
66
65
|
if (!commerce.getRegions) return
|
|
67
66
|
|
|
68
|
-
const currentProvider = commerce.isMock ? 'mock' : 'live'
|
|
69
|
-
const storedProvider = localStorage.getItem(REGION_PROVIDER_KEY)
|
|
70
|
-
|
|
71
|
-
if (storedProvider && storedProvider !== currentProvider) {
|
|
72
|
-
localStorage.removeItem(REGION_KEY)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
localStorage.setItem(REGION_PROVIDER_KEY, currentProvider)
|
|
76
|
-
|
|
77
67
|
const raw = await commerce.getRegions()
|
|
78
68
|
if (cancelled || !raw) return
|
|
79
69
|
|
|
@@ -32,6 +32,22 @@ V0 generates feature code (pages, components) on top of this frozen infrastructu
|
|
|
32
32
|
| `patterns.md` | Code templates for pages, components, cart, auth, styling |
|
|
33
33
|
| `rules.md` | Non-negotiable constraints (read before generating) |
|
|
34
34
|
| `project-structure.md` | Folder map + where to put new files |
|
|
35
|
+
| `decision-matrix.md` | Fast decisions when prompts pressure V0 to leave ThorCommerce architecture |
|
|
36
|
+
|
|
37
|
+
## Guardrail Maintenance
|
|
38
|
+
|
|
39
|
+
V0 is guided by multiple aligned layers, not a single prompt.
|
|
40
|
+
|
|
41
|
+
- `.agents/AGENTS.md` — mission, runtime, conflict resolution
|
|
42
|
+
- `docs/*.md` — types, methods, patterns, rules, structure, decisions
|
|
43
|
+
- `ai-validator.json` — regex-based architectural checks
|
|
44
|
+
- ThorBuilder prompt injection — project/runtime-specific guardrails at chat time
|
|
45
|
+
|
|
46
|
+
If the architecture changes, these layers must be reviewed together.
|
|
47
|
+
|
|
48
|
+
See maintainer documentation in `packages/create-thor-app/`:
|
|
49
|
+
- `V0_GUARDRAILS_MAINTENANCE.md`
|
|
50
|
+
- `AI_GUARDRAILS_AGENTS.md`
|
|
35
51
|
|
|
36
52
|
## Quick Import Reference
|
|
37
53
|
|
|
@@ -12,6 +12,13 @@ All backend access goes through the `commerce` singleton from `@/lib/commerce`.
|
|
|
12
12
|
import { commerce } from '@/lib/commerce';
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Runtime Modes
|
|
16
|
+
|
|
17
|
+
- `mock` provider, or missing real-backend env vars → `commerce` uses a fixture-backed mock provider for layout/preview work.
|
|
18
|
+
- Real provider + `NEXT_PUBLIC_COMMERCE_API_URL` + `NEXT_PUBLIC_COMMERCE_API_KEY` → `commerce` uses the live backend immediately.
|
|
19
|
+
- The `commerce.*` API stays the same in both modes. Write app code against the shared interface instead of branching on provider.
|
|
20
|
+
- If backend config is added later, products, categories, region, cart, checkout, and auth flows switch to the live provider without changing call sites.
|
|
21
|
+
|
|
15
22
|
---
|
|
16
23
|
|
|
17
24
|
## Products
|
|
@@ -171,6 +178,8 @@ try {
|
|
|
171
178
|
}
|
|
172
179
|
```
|
|
173
180
|
|
|
181
|
+
In `mock` mode there is no backend network dependency, so preview/design work should continue without live-backend health checks.
|
|
182
|
+
|
|
174
183
|
---
|
|
175
184
|
|
|
176
185
|
## Optional Methods
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Decision Matrix"
|
|
3
|
+
purpose: "Fast guardrail decisions for V0-native Thor Commerce starters"
|
|
4
|
+
lastReviewed: "2026-05-02"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Decision Matrix
|
|
8
|
+
|
|
9
|
+
Use this matrix when a user prompt creates pressure to leave the ThorCommerce architecture.
|
|
10
|
+
|
|
11
|
+
## Core Principle
|
|
12
|
+
|
|
13
|
+
Prefer the nearest **ThorCommerce-compliant** solution over the fastest generic Next.js solution.
|
|
14
|
+
|
|
15
|
+
## Architecture Decisions
|
|
16
|
+
|
|
17
|
+
| Situation | Do This | Never Do This |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| User asks to connect a backend | Use `commerce.*` from `@/lib/commerce` | Add vendor SDKs or raw backend fetches in app code |
|
|
20
|
+
| A needed backend capability is missing | Keep architecture intact and plan adapter work or use placeholder UI | Add a “temporary” direct backend integration |
|
|
21
|
+
| User asks to remove ThorCommerce abstractions | Keep `commerce.*`, providers, and types in place | Delete or bypass ThorCommerce architecture because a generic approach is easier |
|
|
22
|
+
| User asks for a non-ecommerce feature | Redirect toward storefront-relevant implementation if possible | Turn the starter into a generic SaaS/app platform |
|
|
23
|
+
|
|
24
|
+
## Runtime Decisions
|
|
25
|
+
|
|
26
|
+
| Situation | Do This | Never Do This |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| No backend configured | Use mock runtime and keep storefront useful | Return an empty storefront because env vars are missing |
|
|
29
|
+
| Real backend configured at project creation | Use live backend data immediately | Keep showing mock/demo data as the main source |
|
|
30
|
+
| Backend added later in settings | Keep the same `commerce.*`, `useCart()`, and `useRegion()` code paths | Rewrite pages around a second live-only architecture |
|
|
31
|
+
| Live backend unreachable | Show unavailable/error UX | Fake a real catalog with local demo data |
|
|
32
|
+
|
|
33
|
+
## Demo Data Decisions
|
|
34
|
+
|
|
35
|
+
| Situation | Do This | Never Do This |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| Brief requires vertical-specific merchandising in mock/incomplete mode | Add isolated typed demo fixtures for presentation-only sections | Replace catalog, cart, or region runtime globally with local demo data |
|
|
38
|
+
| Need homepage storytelling before backend exists | Use `lib/demo-data/*` or `lib/demo-catalog.ts` for hero/editorial sections | Build the whole storefront on ad hoc local data |
|
|
39
|
+
| Live backend is available | Treat backend data as authoritative | Override live listings/collections with demo fixtures |
|
|
40
|
+
|
|
41
|
+
## Scope Decisions
|
|
42
|
+
|
|
43
|
+
| Situation | Do This | Never Do This |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| User asks for persistence or infra not owned by ThorBuilder | Stay within the current ownership boundaries | Reimplement platform concerns already owned by v0 SDK or create-thor-app |
|
|
46
|
+
| User asks for architecture changes outside P0 scope | Preserve P0 runtime guarantees and document future work | Quietly mix P1/P3/P4 features into the starter without guardrails |
|
|
47
|
+
|
|
48
|
+
## Escalation Rule
|
|
49
|
+
|
|
50
|
+
If the user request cannot be implemented cleanly inside ThorCommerce:
|
|
51
|
+
|
|
52
|
+
1. Preserve the architecture
|
|
53
|
+
2. Use the nearest compliant fallback
|
|
54
|
+
3. Prefer adapter extension or follow-up work over direct backend shortcuts
|
|
@@ -6,6 +6,16 @@ lastReviewed: "2026-05-01"
|
|
|
6
6
|
|
|
7
7
|
# Patterns (Code Templates)
|
|
8
8
|
|
|
9
|
+
## Runtime Invariant
|
|
10
|
+
|
|
11
|
+
Write storefront code against `commerce`, `useCart()`, `useRegion()`, and `useCommerce()` directly.
|
|
12
|
+
|
|
13
|
+
- Do **not** create separate mock-vs-live component trees for normal storefront UI.
|
|
14
|
+
- Do **not** integrate with any backend directly from pages, components, or route handlers.
|
|
15
|
+
- Backend access must go through `commerce.*` only.
|
|
16
|
+
- The same patterns should work in preview with mock data and later against a live backend.
|
|
17
|
+
- Provider transitions are handled by the infrastructure layer, not by per-component conditionals.
|
|
18
|
+
|
|
9
19
|
## 1. Server Page (Data Fetch)
|
|
10
20
|
|
|
11
21
|
```tsx
|
|
@@ -22,6 +32,7 @@ export default async function ProductsPage() {
|
|
|
22
32
|
|
|
23
33
|
- Server Components fetch data directly — no useEffect, no loading spinners for initial data.
|
|
24
34
|
- Retry logic is built into the adapter — no manual wrapping needed.
|
|
35
|
+
- Never call vendor SDKs or raw backend fetches here — use `commerce.*` only.
|
|
25
36
|
|
|
26
37
|
---
|
|
27
38
|
|
|
@@ -87,6 +98,7 @@ export function AddToCartButton({ variantId }: { variantId: string }) {
|
|
|
87
98
|
|
|
88
99
|
- Import `useCart` from `@/components/providers/cart-provider`.
|
|
89
100
|
- Cart methods: `addItem(variantId, quantity)`, `removeItem(lineItemId)`, `updateQuantity(lineItemId, qty)`, `clearCart()`.
|
|
101
|
+
- When the storefront switches from mock to live backend, `CartProvider` resets incompatible persisted cart state automatically.
|
|
90
102
|
|
|
91
103
|
---
|
|
92
104
|
|
|
@@ -114,6 +126,7 @@ export function CurrencySelector() {
|
|
|
114
126
|
```
|
|
115
127
|
|
|
116
128
|
- Import `useRegion` from `@/components/providers/region-provider`.
|
|
129
|
+
- When the provider changes between mock and live, `RegionProvider` clears stale persisted region state automatically.
|
|
117
130
|
|
|
118
131
|
---
|
|
119
132
|
|
|
@@ -177,6 +190,105 @@ const customer = await commerce.auth.getCurrentCustomer();
|
|
|
177
190
|
|
|
178
191
|
---
|
|
179
192
|
|
|
193
|
+
## 8. Backend Integration Boundary
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
// Correct — backend access always goes through commerce.*
|
|
197
|
+
import { commerce } from '@/lib/commerce';
|
|
198
|
+
|
|
199
|
+
const products = await commerce.getProducts({ first: 12 });
|
|
200
|
+
const collection = await commerce.getCollection('featured');
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
// Wrong — never integrate with a backend directly from the app
|
|
205
|
+
import Medusa from '@medusajs/js-sdk';
|
|
206
|
+
|
|
207
|
+
const medusa = new Medusa({
|
|
208
|
+
baseUrl: process.env.NEXT_PUBLIC_COMMERCE_API_URL!,
|
|
209
|
+
publishableKey: process.env.NEXT_PUBLIC_COMMERCE_API_KEY!,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const products = await medusa.store.product.list();
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
// Wrong — never bypass adapters with raw fetch
|
|
217
|
+
const response = await fetch(`${process.env.NEXT_PUBLIC_COMMERCE_API_URL}/products`);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
- V0 must not add direct Medusa, Shopify, BigCommerce, or other backend integrations.
|
|
221
|
+
- V0 must only use the local commerce singleton: `import { commerce } from '@/lib/commerce'`.
|
|
222
|
+
- If a capability is needed, check `docs/commerce-api.md` first and call the matching `commerce.*` method.
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 9. Demo Fixtures for Mock/Incomplete Mode
|
|
227
|
+
|
|
228
|
+
Use this only for presentation-oriented sections when the brief requires vertical-specific merchandising that is not yet represented by the generic mock catalog.
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
// lib/demo-catalog.ts
|
|
232
|
+
import type { Product } from '@thorprovider/types';
|
|
233
|
+
|
|
234
|
+
export const demoFeaturedProducts: Product[] = [
|
|
235
|
+
// Typed demo fixtures for hero/editorial sections only
|
|
236
|
+
];
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
```tsx
|
|
240
|
+
// app/page.tsx
|
|
241
|
+
import { commerce } from '@/lib/commerce';
|
|
242
|
+
import type { Product } from '@thorprovider/types';
|
|
243
|
+
import { demoFeaturedProducts } from '@/lib/demo-catalog';
|
|
244
|
+
import { HeroSpotlight } from '@/components/hero-spotlight';
|
|
245
|
+
import { ProductGrid } from '@/components/product-grid';
|
|
246
|
+
|
|
247
|
+
export default async function HomePage() {
|
|
248
|
+
const products: Product[] = await commerce.getProducts({ first: 8 });
|
|
249
|
+
const heroProducts = commerce.isMock === true
|
|
250
|
+
? demoFeaturedProducts
|
|
251
|
+
: products.slice(0, 4);
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<main>
|
|
255
|
+
<HeroSpotlight products={heroProducts} />
|
|
256
|
+
<ProductGrid products={products} />
|
|
257
|
+
</main>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
- Live backend data remains authoritative when configured and available.
|
|
263
|
+
- Use demo fixtures only in mock mode or incomplete backend configuration.
|
|
264
|
+
- Keep demo fixtures isolated in `lib/demo-data/*` or `lib/demo-catalog.ts`.
|
|
265
|
+
- Do not replace normal product listings, collections, cart, or region flows with demo fixtures.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## 10. What NOT to Do in Backend-Optional Mode
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
// Wrong — do not gate storefront rendering on env checks
|
|
273
|
+
if (!process.env.NEXT_PUBLIC_COMMERCE_API_URL) {
|
|
274
|
+
return <div>No products yet</div>;
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
```tsx
|
|
279
|
+
// Wrong — do not branch into a separate backend integration path
|
|
280
|
+
if (process.env.NEXT_PUBLIC_COMMERCE_PROVIDER === 'medusa') {
|
|
281
|
+
// direct vendor SDK integration
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
// Correct — same commerce.* interface in mock and live modes
|
|
287
|
+
const products = await commerce.getProducts({ first: 8 });
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
180
292
|
## Import Path Summary
|
|
181
293
|
|
|
182
294
|
| What | Import From |
|
|
@@ -40,6 +40,8 @@ lib/
|
|
|
40
40
|
commerce.ts ← Commerce singleton — FROZEN
|
|
41
41
|
env.ts ← Zod environment schema — FROZEN
|
|
42
42
|
utils.ts ← cn() + formatPrice()
|
|
43
|
+
demo-data/ ← Optional typed demo fixtures for presentation-only sections in mock/incomplete mode
|
|
44
|
+
demo-catalog.ts ← Optional single-file demo fallback for brief-specific merchandising
|
|
43
45
|
|
|
44
46
|
docs/
|
|
45
47
|
types.md ← Full @thorprovider/types reference
|
|
@@ -57,6 +59,7 @@ docs/
|
|
|
57
59
|
| Reusable UI primitive | `npx shadcn@latest add [component]` → `components/ui/` |
|
|
58
60
|
| API route | `app/api/[route]/route.ts` |
|
|
59
61
|
| Environment variables | `.env.local` |
|
|
62
|
+
| Typed demo fixtures for mock/incomplete presentation fallback | `lib/demo-data/*` or `lib/demo-catalog.ts` |
|
|
60
63
|
|
|
61
64
|
## Component Decision
|
|
62
65
|
|
|
@@ -80,8 +83,16 @@ Need a UI element?
|
|
|
80
83
|
|------|-------|--------------|
|
|
81
84
|
| `lib/commerce.ts` | Infrastructure | Never |
|
|
82
85
|
| `lib/env.ts` | Infrastructure | Never |
|
|
86
|
+
| `lib/demo-data/*` | Feature support | Yes — only for isolated presentation-only fixtures |
|
|
87
|
+
| `lib/demo-catalog.ts` | Feature support | Yes — only for isolated presentation-only fixtures |
|
|
83
88
|
| `components/providers/*` | Infrastructure | Never |
|
|
84
89
|
| `styles/tokens.css` | Brand config | Only via create-thor-app flags |
|
|
85
90
|
| `app/globals.css` | Design tokens | Only to add custom tokens |
|
|
86
91
|
| `app/**/*.tsx` | Feature code | Yes — V0 creates pages |
|
|
87
92
|
| `components/**/*.tsx` | Feature code | Yes — V0 creates components |
|
|
93
|
+
|
|
94
|
+
## Backend Access Boundary
|
|
95
|
+
|
|
96
|
+
- Never integrate with any backend directly from `app/`, `components/`, or route handlers.
|
|
97
|
+
- All commerce/backend access must go through `import { commerce } from '@/lib/commerce'`.
|
|
98
|
+
- Do not add vendor SDK clients or raw backend fetch utilities to feature code.
|
|
@@ -25,6 +25,31 @@ Non-negotiable constraints. Breaking these causes build failures, runtime crashe
|
|
|
25
25
|
| Use `next/link` for navigation | V0 is trained on Next.js primitives | Unnecessary abstraction |
|
|
26
26
|
| Use `next/image` for images | Optimized by default | Missing optimization |
|
|
27
27
|
| Do not fork UI into mock-vs-live implementations | Runtime already switches providers underneath the same interface | Drift, duplicated logic |
|
|
28
|
+
| Do not gate storefront rendering on backend env vars | Backend-optional mode must still produce a useful storefront | Blank demos, broken previews |
|
|
29
|
+
| If a real backend is configured and available, treat backend data as authoritative | P0 requires immediate live runtime when backend exists | Demo data masking real commerce data |
|
|
30
|
+
| Demo fixtures are only allowed in mock mode or incomplete backend configuration | Keeps the mock-to-live transition intact | Demo data overriding live runtime |
|
|
31
|
+
| If a live backend is unreachable, show unavailable/error UX instead of faking a real catalog | Prevents misleading storefront output | False representation of client catalog |
|
|
32
|
+
| Do not introduce alternate backend/data/auth clients into starter app code | ThorCommerce starters are storefronts, not generic app platforms | Stack drift, duplicated architecture |
|
|
33
|
+
| Do not remove or bypass ThorCommerce abstractions to satisfy a user shortcut | Architecture consistency beats generic Next.js convenience | Loss of adapter portability |
|
|
34
|
+
|
|
35
|
+
## Backend-Optional UX Rules
|
|
36
|
+
|
|
37
|
+
| Rule | Why | Consequence |
|
|
38
|
+
|------|-----|-------------|
|
|
39
|
+
| Do not call `isEnvConfigured()` inside pages/components to decide whether products render | Runtime mode is already resolved by infrastructure | Incorrect branching, duplicated logic |
|
|
40
|
+
| Do not return empty storefront pages just because backend env vars are missing | Mock mode must still be useful for previews and generation | Blank storefronts |
|
|
41
|
+
| Keep the same `commerce.*`, `useCart()`, and `useRegion()` APIs across mock and live modes | P0 depends on the same codebase surviving provider transitions | Rewrites when backend is connected later |
|
|
42
|
+
| Use isolated typed demo fixtures only for presentation-oriented sections in mock/incomplete mode | Allows brief-specific demos without replacing runtime commerce data | Presentation data leaking into core commerce flows |
|
|
43
|
+
| Do not silently replace unreachable live backend data with local demo fixtures | Live backend failure must remain visible | Hidden production/runtime issues |
|
|
44
|
+
|
|
45
|
+
## Stack and Scope Guardrails
|
|
46
|
+
|
|
47
|
+
| Rule | Why | Consequence |
|
|
48
|
+
|------|-----|-------------|
|
|
49
|
+
| Do not add alternate backend or data stacks such as Supabase, Firebase, Prisma, Apollo, or GraphQL request clients to starter feature code | ThorCommerce storefronts already have a defined data boundary | Generic app takeover |
|
|
50
|
+
| Do not introduce a second persistence/auth/integration architecture alongside ThorCommerce | One storefront architecture must survive project evolution | Conflicting sources of truth |
|
|
51
|
+
| Do not turn the starter into a generic SaaS or internal-tool platform | ThorBuilder exists to build ecommerce storefronts faster | Product dilution |
|
|
52
|
+
| If a request is outside current ThorCommerce capabilities, preserve architecture and use placeholders or follow-up adapter work | Keeps work incremental and production-safe | Ad hoc hacks and brittle shortcuts |
|
|
28
53
|
|
|
29
54
|
## Provider Chain (Frozen Order)
|
|
30
55
|
|
|
@@ -58,9 +83,12 @@ Never modify these — they are infrastructure:
|
|
|
58
83
|
- [ ] No `@thorprovider/components` or `@thorprovider/providers` imports?
|
|
59
84
|
- [ ] No backend SDK imports (`@medusajs/*`, `@shopify/*`)?
|
|
60
85
|
- [ ] No raw `fetch(COMMERCE_API_URL...)` calls?
|
|
86
|
+
- [ ] No env-based gating that disables storefront rendering?
|
|
87
|
+
- [ ] No alternate backend/data/auth clients (Supabase/Firebase/Prisma/Apollo/etc.) added to starter code?
|
|
61
88
|
- [ ] All prices rendered via `formatPrice()`?
|
|
62
89
|
- [ ] Using `product.handle` in URLs?
|
|
63
90
|
- [ ] No hardcoded hex/rgb colors?
|
|
64
91
|
- [ ] Types from `@thorprovider/types` (not redefined locally)?
|
|
65
92
|
- [ ] `tsc --noEmit` passes?
|
|
66
93
|
- [ ] Server components fetch; client components receive data via props?
|
|
94
|
+
- [ ] Live backend data remains authoritative when configured?
|
|
@@ -12,47 +12,30 @@
|
|
|
12
12
|
import { createProvider } from '@thorprovider/adapters'
|
|
13
13
|
import type { ProviderTypeString } from '@thorprovider/types'
|
|
14
14
|
import { isSupportedProviderType } from '@thorprovider/types'
|
|
15
|
-
import {
|
|
15
|
+
import { isEnvConfigured } from './env'
|
|
16
16
|
|
|
17
17
|
let _commerce: ReturnType<typeof createProvider> | undefined
|
|
18
18
|
|
|
19
19
|
function createCommerceInstance(): ReturnType<typeof createProvider> {
|
|
20
20
|
if (_commerce) return _commerce
|
|
21
21
|
|
|
22
|
-
const rawProviderType =
|
|
23
|
-
|
|
24
|
-
if (rawProviderType === 'custom') {
|
|
25
|
-
throw new Error(
|
|
26
|
-
'[commerce] The "custom" provider is not supported by the V0-native template runtime. Configure a supported real backend or use mock mode.'
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const resolvedProviderType: ProviderTypeString = shouldUseMockProvider()
|
|
31
|
-
? 'mock'
|
|
32
|
-
: rawProviderType
|
|
33
|
-
|
|
34
|
-
if (!isSupportedProviderType(resolvedProviderType)) {
|
|
22
|
+
const rawProviderType = process.env.NEXT_PUBLIC_COMMERCE_PROVIDER || 'medusa'
|
|
23
|
+
if (!isSupportedProviderType(rawProviderType)) {
|
|
35
24
|
throw new Error(
|
|
36
|
-
`[commerce] Unsupported provider: "${
|
|
25
|
+
`[commerce] Unsupported provider: "${rawProviderType}". Set NEXT_PUBLIC_COMMERCE_PROVIDER to a supported value.`
|
|
37
26
|
)
|
|
38
27
|
}
|
|
39
28
|
|
|
29
|
+
const providerType: ProviderTypeString = rawProviderType
|
|
40
30
|
const baseUrl = (process.env.NEXT_PUBLIC_COMMERCE_API_URL ?? '').replace(/\/+$/, '')
|
|
41
31
|
const apiKey = process.env.NEXT_PUBLIC_COMMERCE_API_KEY ?? ''
|
|
42
|
-
const currencyCode = process.env.NEXT_PUBLIC_DEFAULT_CURRENCY || 'USD'
|
|
43
|
-
const isRealProvider = isRealBackendProvider(resolvedProviderType)
|
|
44
32
|
|
|
45
33
|
_commerce = createProvider({
|
|
46
|
-
provider:
|
|
34
|
+
provider: providerType,
|
|
47
35
|
config: {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
publishableKey: apiKey,
|
|
52
|
-
}
|
|
53
|
-
: {}),
|
|
54
|
-
currencyCode,
|
|
55
|
-
siteUrl: process.env.NEXT_PUBLIC_SITE_URL,
|
|
36
|
+
baseUrl,
|
|
37
|
+
publishableKey: apiKey,
|
|
38
|
+
currencyCode: process.env.NEXT_PUBLIC_DEFAULT_CURRENCY || 'USD',
|
|
56
39
|
debug: process.env.NODE_ENV === 'development',
|
|
57
40
|
retry: {
|
|
58
41
|
maxRetries: 3,
|
|
@@ -77,6 +60,7 @@ function createCommerceInstance(): ReturnType<typeof createProvider> {
|
|
|
77
60
|
*/
|
|
78
61
|
export const commerce = new Proxy({} as ReturnType<typeof createProvider>, {
|
|
79
62
|
get(_target, prop: string | symbol) {
|
|
63
|
+
if (!isEnvConfigured()) return undefined
|
|
80
64
|
return createCommerceInstance()[prop as keyof ReturnType<typeof createProvider>]
|
|
81
65
|
},
|
|
82
66
|
})
|
|
@@ -7,27 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import { z } from 'zod'
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const BaseEnvSchema = z.object({
|
|
10
|
+
export const EnvSchema = z.object({
|
|
13
11
|
NEXT_PUBLIC_COMMERCE_PROVIDER: z
|
|
14
|
-
.enum(['
|
|
15
|
-
.default('
|
|
16
|
-
|
|
17
|
-
NEXT_PUBLIC_DEFAULT_CURRENCY: z
|
|
18
|
-
.string()
|
|
19
|
-
.default('USD'),
|
|
12
|
+
.enum(['medusa', 'shopify', 'bigcommerce', 'custom'])
|
|
13
|
+
.default('medusa'),
|
|
20
14
|
|
|
21
|
-
NEXT_PUBLIC_SALES_CHANNEL_ID: z
|
|
22
|
-
.string()
|
|
23
|
-
.optional(),
|
|
24
|
-
|
|
25
|
-
FRONTEND_WEBHOOK_SECRET: z
|
|
26
|
-
.string()
|
|
27
|
-
.optional(),
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
const RealBackendEnvSchema = BaseEnvSchema.extend({
|
|
31
15
|
NEXT_PUBLIC_COMMERCE_API_URL: z
|
|
32
16
|
.string()
|
|
33
17
|
.url(),
|
|
@@ -35,44 +19,22 @@ const RealBackendEnvSchema = BaseEnvSchema.extend({
|
|
|
35
19
|
NEXT_PUBLIC_COMMERCE_API_KEY: z
|
|
36
20
|
.string()
|
|
37
21
|
.min(1),
|
|
38
|
-
})
|
|
39
22
|
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
NEXT_PUBLIC_DEFAULT_CURRENCY: z
|
|
24
|
+
.string()
|
|
25
|
+
.default('USD'),
|
|
26
|
+
|
|
27
|
+
NEXT_PUBLIC_SALES_CHANNEL_ID: z
|
|
42
28
|
.string()
|
|
43
29
|
.optional(),
|
|
44
30
|
|
|
45
|
-
|
|
31
|
+
FRONTEND_WEBHOOK_SECRET: z
|
|
46
32
|
.string()
|
|
47
33
|
.optional(),
|
|
48
34
|
})
|
|
49
35
|
|
|
50
|
-
export const EnvSchema = MockEnvSchema
|
|
51
|
-
|
|
52
36
|
export type Env = z.infer<typeof EnvSchema>
|
|
53
37
|
|
|
54
|
-
export function getConfiguredProvider(): Env['NEXT_PUBLIC_COMMERCE_PROVIDER'] {
|
|
55
|
-
return BaseEnvSchema.shape.NEXT_PUBLIC_COMMERCE_PROVIDER.parse(
|
|
56
|
-
process.env.NEXT_PUBLIC_COMMERCE_PROVIDER
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function isRealBackendProvider(
|
|
61
|
-
provider: string | undefined
|
|
62
|
-
): provider is z.infer<typeof realProviderSchema> {
|
|
63
|
-
return realProviderSchema.safeParse(provider).success
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function shouldUseMockProvider(): boolean {
|
|
67
|
-
const provider = getConfiguredProvider()
|
|
68
|
-
|
|
69
|
-
if (provider === 'mock') {
|
|
70
|
-
return true
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return !isRealBackendProvider(provider) || !isEnvConfigured()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
38
|
/**
|
|
77
39
|
* Check whether required commerce env vars are present.
|
|
78
40
|
* Used to bail out gracefully during build/SSG.
|
|
@@ -93,20 +55,14 @@ export function isEnvConfigured(): boolean {
|
|
|
93
55
|
*/
|
|
94
56
|
export function getEnv(): Env {
|
|
95
57
|
try {
|
|
96
|
-
|
|
58
|
+
return EnvSchema.parse({
|
|
97
59
|
NEXT_PUBLIC_COMMERCE_PROVIDER: process.env.NEXT_PUBLIC_COMMERCE_PROVIDER,
|
|
98
60
|
NEXT_PUBLIC_COMMERCE_API_URL: process.env.NEXT_PUBLIC_COMMERCE_API_URL,
|
|
99
61
|
NEXT_PUBLIC_COMMERCE_API_KEY: process.env.NEXT_PUBLIC_COMMERCE_API_KEY,
|
|
100
62
|
NEXT_PUBLIC_DEFAULT_CURRENCY: process.env.NEXT_PUBLIC_DEFAULT_CURRENCY,
|
|
101
63
|
NEXT_PUBLIC_SALES_CHANNEL_ID: process.env.NEXT_PUBLIC_SALES_CHANNEL_ID,
|
|
102
64
|
FRONTEND_WEBHOOK_SECRET: process.env.FRONTEND_WEBHOOK_SECRET,
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (shouldUseMockProvider()) {
|
|
106
|
-
return MockEnvSchema.parse(rawEnv)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return RealBackendEnvSchema.parse(rawEnv)
|
|
65
|
+
})
|
|
110
66
|
} catch (error) {
|
|
111
67
|
if (error instanceof z.ZodError) {
|
|
112
68
|
const issues = error.issues
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="next" />
|
|
2
2
|
/// <reference types="next/image-types/global" />
|
|
3
|
-
import "./.next/types/routes.d.ts";
|
|
3
|
+
import "./.next/dev/types/routes.d.ts";
|
|
4
4
|
|
|
5
5
|
// NOTE: This file should not be edited
|
|
6
6
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thorprovider/core",
|
|
3
3
|
"version": "2.0.0",
|
|
4
|
+
"private": true,
|
|
4
5
|
"description": "Thor Commerce V0-native template. Lean storefront scaffold for V0 AI code generation.",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"build": "next build",
|
|
@@ -10,8 +11,8 @@
|
|
|
10
11
|
"generate:agent-index": "node ../../scripts/generate-core-agents-index.cjs"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"@thorprovider/adapters": "^4.
|
|
14
|
-
"@thorprovider/types": "^3.
|
|
14
|
+
"@thorprovider/adapters": "^4.2.0",
|
|
15
|
+
"@thorprovider/types": "^3.2.0",
|
|
15
16
|
"clsx": "^2.1.1",
|
|
16
17
|
"next": "16.0.10",
|
|
17
18
|
"react": "19.2.0",
|