@thorprovider/create-thor-app 4.1.0 → 4.1.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/README.md CHANGED
@@ -446,6 +446,8 @@ yarn changeset
446
446
 
447
447
  Include `@thorprovider/create-thor-app` in a changeset whenever you change the CLI, its bundled template, or any publishable behavior consumers depend on.
448
448
 
449
+ 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.
450
+
449
451
  ---
450
452
 
451
453
  ## 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
- NEXT_PUBLIC_COMMERCE_PROVIDER: commerceProvider ?? (commerceApiUrl && commerceApiKey ? "medusa" : "mock"),
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++}. Optional: connect a real backend later`, c.cyan);
1020
- log(" The scaffold starts in mock mode so you can design immediately.", c.yellow);
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., mock, medusa, shopify)").option("--commerce-api-url <url>", "Commerce backend API URL").option("--commerce-api-key <key>", "Commerce publishable API key").action(async (positionalName, opts) => {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thorprovider/create-thor-app",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "CLI to scaffold a new Thor Commerce V0-native application",
5
5
  "type": "module",
6
6
  "bin": "./dist/index.js",
@@ -19,9 +19,14 @@ ALWAYS import from @thorprovider/types — NEVER define Product, Cart, Collectio
19
19
  - useRegion() — @/components/providers/region-provider
20
20
  - useCommerce() — @/components/providers/commerce-provider
21
21
 
22
+ ## Runtime
23
+ - Default to mock mode when backend env is missing
24
+ - Real provider + URL + API key => live backend immediately
25
+ - Same commerce/useCart/useRegion APIs in both modes
26
+
22
27
  ## Stack
23
28
  Next.js 16, React 19, TS strict, Tailwind 4, shadcn/ui.
24
29
  Server Components default. 'use client' only for interactivity.
25
30
 
26
31
  ## Docs
27
- docs/types.md (types), docs/patterns.md (examples).
32
+ docs/types.md (types), docs/patterns.md (examples).
@@ -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
- <div className="flex flex-col gap-3 md:flex-row md:items-end md:justify-between">
13
- <div>
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, isMock: commerce.isMock === true }}>
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
 
@@ -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
@@ -6,6 +6,14 @@ 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
+ - The same patterns should work in preview with mock data and later against a live backend.
15
+ - Provider transitions are handled by the infrastructure layer, not by per-component conditionals.
16
+
9
17
  ## 1. Server Page (Data Fetch)
10
18
 
11
19
  ```tsx
@@ -87,6 +95,7 @@ export function AddToCartButton({ variantId }: { variantId: string }) {
87
95
 
88
96
  - Import `useCart` from `@/components/providers/cart-provider`.
89
97
  - Cart methods: `addItem(variantId, quantity)`, `removeItem(lineItemId)`, `updateQuantity(lineItemId, qty)`, `clearCart()`.
98
+ - When the storefront switches from mock to live backend, `CartProvider` resets incompatible persisted cart state automatically.
90
99
 
91
100
  ---
92
101
 
@@ -114,6 +123,7 @@ export function CurrencySelector() {
114
123
  ```
115
124
 
116
125
  - Import `useRegion` from `@/components/providers/region-provider`.
126
+ - When the provider changes between mock and live, `RegionProvider` clears stale persisted region state automatically.
117
127
 
118
128
  ---
119
129
 
@@ -24,7 +24,6 @@ Non-negotiable constraints. Breaking these causes build failures, runtime crashe
24
24
  | No hardcoded `#hex` / `rgb()` colors | CSS tokens enable dark mode + theming | Dark mode breaks |
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
- | Do not fork UI into mock-vs-live implementations | Runtime already switches providers underneath the same interface | Drift, duplicated logic |
28
27
 
29
28
  ## Provider Chain (Frozen Order)
30
29
 
@@ -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 { getConfiguredProvider, isRealBackendProvider, shouldUseMockProvider } from './env'
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 = getConfiguredProvider()
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: "${resolvedProviderType}". Set NEXT_PUBLIC_COMMERCE_PROVIDER to a supported value.`
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: resolvedProviderType,
34
+ provider: providerType,
47
35
  config: {
48
- ...(isRealProvider
49
- ? {
50
- baseUrl,
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 realProviderSchema = z.enum(['medusa', 'shopify', 'bigcommerce'])
11
-
12
- const BaseEnvSchema = z.object({
10
+ export const EnvSchema = z.object({
13
11
  NEXT_PUBLIC_COMMERCE_PROVIDER: z
14
- .enum(['mock', 'medusa', 'shopify', 'bigcommerce', 'custom'])
15
- .default('mock'),
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
- const MockEnvSchema = BaseEnvSchema.extend({
41
- NEXT_PUBLIC_COMMERCE_API_URL: z
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
- NEXT_PUBLIC_COMMERCE_API_KEY: z
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
- const rawEnv = {
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.0.0",
14
- "@thorprovider/types": "^3.0.0",
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",