@thorprovider/create-thor-app 4.0.0 → 4.1.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 +31 -68
- package/dist/index.js +158 -629
- package/package.json +1 -1
- package/templates/default/.agents/AGENTS.md +27 -0
- package/templates/default/.env.example +12 -33
- package/templates/default/.eslintrc.json +20 -27
- package/templates/default/README.md +60 -119
- package/templates/default/ai-validator.json +47 -29
- package/templates/default/app/api/revalidate/route.ts +27 -36
- package/templates/default/app/backend-unavailable/page.tsx +3 -7
- package/templates/default/app/error.tsx +1 -2
- package/templates/default/app/global-error.tsx +3 -3
- package/templates/default/app/globals.css +1 -71
- package/templates/default/app/layout.tsx +16 -38
- package/templates/default/app/not-found.tsx +1 -1
- package/templates/default/app/page.tsx +45 -113
- package/templates/default/components/providers/app-providers.tsx +19 -68
- package/templates/default/components/providers/cart-provider.tsx +155 -0
- package/templates/default/components/providers/commerce-provider.tsx +34 -0
- package/templates/default/components/providers/region-provider.tsx +115 -0
- package/templates/default/docs/README.md +52 -37
- package/templates/default/docs/commerce-api.md +58 -125
- package/templates/default/docs/patterns.md +128 -67
- package/templates/default/docs/project-structure.md +58 -50
- package/templates/default/docs/rules.md +44 -42
- package/templates/default/docs/types.md +105 -1024
- package/templates/default/lib/commerce.ts +52 -135
- package/templates/default/lib/env.ts +68 -94
- package/templates/default/lib/utils.ts +18 -0
- package/templates/default/next.config.ts +7 -0
- package/templates/default/package.json +2 -8
- package/templates/default/registry.json +6 -0
- package/templates/default/styles/tokens.css +81 -0
- package/templates/default/components/providers/navigation-provider.tsx +0 -37
- package/templates/default/config/site.config.ts +0 -156
- package/templates/default/docs/components.md +0 -282
- package/templates/default/docs/dependencies.md +0 -61
- package/templates/default/lib/auth-context.tsx +0 -213
- package/templates/default/lib/cart-provider.tsx +0 -53
- package/templates/default/lib/commerce-provider.tsx +0 -48
- package/templates/default/lib/region-detection.ts +0 -73
- package/templates/default/lib/region-provider.tsx +0 -53
- package/templates/default/lib/regions-config.ts +0 -48
- package/templates/default/lib/storefront-config.ts +0 -54
- package/templates/default/next.config.mjs +0 -51
- package/templates/default/proxy.ts +0 -155
- package/templates/default/scripts/generate-regions-config.ts +0 -498
|
@@ -1,165 +1,82 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Commerce Singleton
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* This is the ONLY place where createProvider()
|
|
6
|
-
* NEVER call createProvider() in app/layout.tsx or elsewhere.
|
|
7
|
-
* See: .v0/docs/v0_provider_chain.md
|
|
4
|
+
* FROZEN: V0 reads this file but NEVER modifies it.
|
|
5
|
+
* This is the ONLY place where createProvider() is called.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Usage (server components):
|
|
8
|
+
* import { commerce } from '@/lib/commerce'
|
|
9
|
+
* const products = await commerce.getProducts({ first: 20 })
|
|
11
10
|
*/
|
|
12
11
|
|
|
13
|
-
import { createProvider } from '@thorprovider/adapters'
|
|
14
|
-
import type {
|
|
15
|
-
import { isSupportedProviderType } from '@thorprovider/types'
|
|
16
|
-
import {
|
|
12
|
+
import { createProvider } from '@thorprovider/adapters'
|
|
13
|
+
import type { ProviderTypeString } from '@thorprovider/types'
|
|
14
|
+
import { isSupportedProviderType } from '@thorprovider/types'
|
|
15
|
+
import { getConfiguredProvider, isRealBackendProvider, shouldUseMockProvider } from './env'
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
function normalizeBackendUrl(value?: string): string | undefined {
|
|
20
|
-
if (!value) return undefined;
|
|
21
|
-
const trimmed = value.trim();
|
|
22
|
-
if (!trimmed) return undefined;
|
|
23
|
-
return trimmed.replace(/\/+$/, '');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Lazy singleton — only initialized on first access at runtime, never during build.
|
|
27
|
-
// This allows @thorprovider/core to compile as a package template without env variables present.
|
|
28
|
-
let _commerce: ReturnType<typeof createProvider> | undefined;
|
|
17
|
+
let _commerce: ReturnType<typeof createProvider> | undefined
|
|
29
18
|
|
|
30
19
|
function createCommerceInstance(): ReturnType<typeof createProvider> {
|
|
31
|
-
if (_commerce) return _commerce
|
|
20
|
+
if (_commerce) return _commerce
|
|
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
|
+
}
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const resolvedProviderType: ProviderTypeString = shouldUseMockProvider()
|
|
31
|
+
? 'mock'
|
|
32
|
+
: rawProviderType
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
if (!isSupportedProviderType(rawProviderType)) {
|
|
34
|
+
if (!isSupportedProviderType(resolvedProviderType)) {
|
|
39
35
|
throw new Error(
|
|
40
|
-
`[
|
|
41
|
-
|
|
42
|
-
`Please set NEXT_PUBLIC_COMMERCE_PROVIDER="medusa" in your environment variables.`
|
|
43
|
-
);
|
|
36
|
+
`[commerce] Unsupported provider: "${resolvedProviderType}". Set NEXT_PUBLIC_COMMERCE_PROVIDER to a supported value.`
|
|
37
|
+
)
|
|
44
38
|
}
|
|
45
39
|
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
40
|
+
const baseUrl = (process.env.NEXT_PUBLIC_COMMERCE_API_URL ?? '').replace(/\/+$/, '')
|
|
41
|
+
const apiKey = process.env.NEXT_PUBLIC_COMMERCE_API_KEY ?? ''
|
|
42
|
+
const currencyCode = process.env.NEXT_PUBLIC_DEFAULT_CURRENCY || 'USD'
|
|
43
|
+
const isRealProvider = isRealBackendProvider(resolvedProviderType)
|
|
49
44
|
|
|
50
45
|
_commerce = createProvider({
|
|
51
|
-
provider:
|
|
46
|
+
provider: resolvedProviderType,
|
|
52
47
|
config: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
...(isRealProvider
|
|
49
|
+
? {
|
|
50
|
+
baseUrl,
|
|
51
|
+
publishableKey: apiKey,
|
|
52
|
+
}
|
|
53
|
+
: {}),
|
|
54
|
+
currencyCode,
|
|
55
|
+
siteUrl: process.env.NEXT_PUBLIC_SITE_URL,
|
|
56
56
|
debug: process.env.NODE_ENV === 'development',
|
|
57
|
-
|
|
58
|
-
// Retry configuration - prevents "fetch failed" errors from temporary network issues
|
|
59
57
|
retry: {
|
|
60
|
-
maxRetries: 3,
|
|
61
|
-
timeoutMs: 10000,
|
|
62
|
-
initialDelayMs: 300,
|
|
63
|
-
backoffMultiplier: 2,
|
|
64
|
-
maxDelayMs: 5000,
|
|
58
|
+
maxRetries: 3,
|
|
59
|
+
timeoutMs: 10000,
|
|
60
|
+
initialDelayMs: 300,
|
|
61
|
+
backoffMultiplier: 2,
|
|
62
|
+
maxDelayMs: 5000,
|
|
65
63
|
},
|
|
66
|
-
|
|
67
|
-
// Authentication configuration
|
|
68
64
|
auth: {
|
|
69
|
-
method: 'jwt',
|
|
70
|
-
storage: 'localStorage',
|
|
65
|
+
method: 'jwt',
|
|
66
|
+
storage: 'localStorage',
|
|
71
67
|
},
|
|
72
|
-
|
|
73
|
-
// Admin API configuration (passed to @thorprovider/adapters for inventory + admin dashboard operations)
|
|
74
|
-
// Only configured when API key is present in env
|
|
75
|
-
adminConfig: process.env.COMMERCE_ADMIN_API_KEY
|
|
76
|
-
? {
|
|
77
|
-
apiKey: process.env.COMMERCE_ADMIN_API_KEY,
|
|
78
|
-
}
|
|
79
|
-
: undefined,
|
|
80
68
|
},
|
|
81
|
-
})
|
|
69
|
+
})
|
|
82
70
|
|
|
83
|
-
return _commerce
|
|
71
|
+
return _commerce
|
|
84
72
|
}
|
|
85
73
|
|
|
86
74
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* Transparent Proxy — defers instantiation (and env validation) until first method call.
|
|
90
|
-
* This allows @thorprovider/core to compile as a package template without environment variables.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* import { commerce } from '@/lib/commerce';
|
|
95
|
-
*
|
|
96
|
-
* // Fetch products
|
|
97
|
-
* const products = await commerce.getProducts();
|
|
98
|
-
*
|
|
99
|
-
* // Create cart
|
|
100
|
-
* const cart = await commerce.createCart();
|
|
101
|
-
* ```
|
|
75
|
+
* Lazy commerce proxy — defers instantiation until first method call.
|
|
76
|
+
* Allows the template to compile without env variables (build/CI).
|
|
102
77
|
*/
|
|
103
78
|
export const commerce = new Proxy({} as ReturnType<typeof createProvider>, {
|
|
104
79
|
get(_target, prop: string | symbol) {
|
|
105
|
-
|
|
106
|
-
// and no-op async functions for method calls — prevents build failures.
|
|
107
|
-
if (!isEnvConfigured()) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
return createCommerceInstance()[prop as keyof ReturnType<typeof createProvider>];
|
|
80
|
+
return createCommerceInstance()[prop as keyof ReturnType<typeof createProvider>]
|
|
111
81
|
},
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Initialize storefront context on app startup.
|
|
116
|
-
*
|
|
117
|
-
* Validates that the storefront/sales channel is configured and reachable.
|
|
118
|
-
* For providers where storefront is mandatory (e.g. Medusa), a missing or
|
|
119
|
-
* invalid configuration will throw a `StorefrontConfigError`.
|
|
120
|
-
*
|
|
121
|
-
* MUST be called once before any commerce operation that depends on
|
|
122
|
-
* storefront isolation (product listing, cart creation, etc.).
|
|
123
|
-
*
|
|
124
|
-
* @returns StorefrontContext for the current storefront
|
|
125
|
-
* @throws {StorefrontConfigError} if configuration is invalid and required
|
|
126
|
-
*/
|
|
127
|
-
export async function initializeStorefront(): Promise<StorefrontContext> {
|
|
128
|
-
try {
|
|
129
|
-
const context = await commerce.getStorefrontContext();
|
|
130
|
-
return context;
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (commerce.isStorefrontRequired()) {
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Provider allows optional storefront; use safe defaults
|
|
137
|
-
const rawProvider = (process.env.NEXT_PUBLIC_COMMERCE_PROVIDER || 'medusa') as ProviderTypeString;
|
|
138
|
-
return {
|
|
139
|
-
id: 'default',
|
|
140
|
-
name: 'Default Storefront',
|
|
141
|
-
platformType: rawProvider,
|
|
142
|
-
requiresProductScoping: false,
|
|
143
|
-
currencyCode: process.env.NEXT_PUBLIC_DEFAULT_CURRENCY || 'USD',
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Re-export types from @thorprovider/adapters for convenience
|
|
150
|
-
*/
|
|
151
|
-
export type {
|
|
152
|
-
Product,
|
|
153
|
-
ProductVariant,
|
|
154
|
-
Cart,
|
|
155
|
-
CartItem,
|
|
156
|
-
Collection,
|
|
157
|
-
BackendCapabilities,
|
|
158
|
-
CommerceProvider,
|
|
159
|
-
StorefrontContext,
|
|
160
|
-
} from '@thorprovider/adapters';
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Re-export React provider and hooks
|
|
164
|
-
*/
|
|
165
|
-
export { ClientCommerceProvider, useCommerce, useCapabilities } from './commerce-provider';
|
|
82
|
+
})
|
|
@@ -1,147 +1,121 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Environment Variable Validation (Zod
|
|
2
|
+
* Environment Variable Validation (Zod)
|
|
3
3
|
*
|
|
4
|
-
* FROZEN:
|
|
5
|
-
* Changes
|
|
6
|
-
*
|
|
7
|
-
* Usage in components/lib/commerce.ts:
|
|
8
|
-
* import { env } from './env';
|
|
9
|
-
* const { baseUrl, apiKey } = env;
|
|
10
|
-
*
|
|
11
|
-
* The validated env object is re-exported at module scope to catch errors during build.
|
|
4
|
+
* FROZEN: Validates required environment variables at runtime.
|
|
5
|
+
* Changes require architecture review.
|
|
12
6
|
*/
|
|
13
7
|
|
|
14
|
-
import { z } from 'zod'
|
|
8
|
+
import { z } from 'zod'
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* Optional vars: only validated if provided
|
|
20
|
-
*/
|
|
21
|
-
export const EnvSchema = z.object({
|
|
22
|
-
// Commerce Provider Configuration (REQUIRED)
|
|
10
|
+
const realProviderSchema = z.enum(['medusa', 'shopify', 'bigcommerce'])
|
|
11
|
+
|
|
12
|
+
const BaseEnvSchema = z.object({
|
|
23
13
|
NEXT_PUBLIC_COMMERCE_PROVIDER: z
|
|
24
|
-
.enum(['medusa', 'shopify', 'bigcommerce', 'custom'])
|
|
25
|
-
.default('
|
|
26
|
-
.describe('Commerce backend provider (defaults to medusa)'),
|
|
27
|
-
|
|
28
|
-
NEXT_PUBLIC_COMMERCE_API_URL: z
|
|
29
|
-
.string()
|
|
30
|
-
.url()
|
|
31
|
-
.describe('Your commerce backend API base URL (Medusa, Shopify, etc.)'),
|
|
32
|
-
|
|
33
|
-
NEXT_PUBLIC_COMMERCE_API_KEY: z
|
|
34
|
-
.string()
|
|
35
|
-
.min(1)
|
|
36
|
-
.describe('Public API key for commerce backend'),
|
|
14
|
+
.enum(['mock', 'medusa', 'shopify', 'bigcommerce', 'custom'])
|
|
15
|
+
.default('mock'),
|
|
37
16
|
|
|
38
|
-
// Currency (REQUIRED — defaults to USD)
|
|
39
17
|
NEXT_PUBLIC_DEFAULT_CURRENCY: z
|
|
40
18
|
.string()
|
|
41
|
-
.default('USD')
|
|
42
|
-
.describe('Default currency code (e.g., "USD", "EUR")'),
|
|
19
|
+
.default('USD'),
|
|
43
20
|
|
|
44
|
-
// Health Check (OPTIONAL — used by proxy.ts circuit breaker)
|
|
45
|
-
HEALTH_CHECK_PATH: z
|
|
46
|
-
.string()
|
|
47
|
-
.default('/store/regions')
|
|
48
|
-
.describe('Path used by proxy.ts to verify backend availability'),
|
|
49
|
-
|
|
50
|
-
// Sales Channel (OPTIONAL — multi-tenant stores)
|
|
51
21
|
NEXT_PUBLIC_SALES_CHANNEL_ID: z
|
|
52
22
|
.string()
|
|
53
|
-
.optional()
|
|
54
|
-
.describe('Sales channel ID for multi-tenant stores (required for Medusa)'),
|
|
23
|
+
.optional(),
|
|
55
24
|
|
|
56
|
-
|
|
57
|
-
COMMERCE_ADMIN_EMAIL: z
|
|
25
|
+
FRONTEND_WEBHOOK_SECRET: z
|
|
58
26
|
.string()
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
.describe('Admin email for backend admin API'),
|
|
27
|
+
.optional(),
|
|
28
|
+
})
|
|
62
29
|
|
|
63
|
-
|
|
30
|
+
const RealBackendEnvSchema = BaseEnvSchema.extend({
|
|
31
|
+
NEXT_PUBLIC_COMMERCE_API_URL: z
|
|
64
32
|
.string()
|
|
65
|
-
.
|
|
66
|
-
.optional()
|
|
67
|
-
.describe('Admin password for backend admin API'),
|
|
33
|
+
.url(),
|
|
68
34
|
|
|
69
|
-
|
|
35
|
+
NEXT_PUBLIC_COMMERCE_API_KEY: z
|
|
70
36
|
.string()
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
.describe('Commerce backend admin API URL (defaults to NEXT_PUBLIC_COMMERCE_API_URL)'),
|
|
37
|
+
.min(1),
|
|
38
|
+
})
|
|
74
39
|
|
|
75
|
-
|
|
40
|
+
const MockEnvSchema = BaseEnvSchema.extend({
|
|
41
|
+
NEXT_PUBLIC_COMMERCE_API_URL: z
|
|
76
42
|
.string()
|
|
77
|
-
.optional()
|
|
78
|
-
.transform(v => v ? Number.parseInt(v, 10) : undefined)
|
|
79
|
-
.describe('Admin token TTL in milliseconds'),
|
|
43
|
+
.optional(),
|
|
80
44
|
|
|
81
|
-
|
|
82
|
-
FRONTEND_WEBHOOK_SECRET: z
|
|
45
|
+
NEXT_PUBLIC_COMMERCE_API_KEY: z
|
|
83
46
|
.string()
|
|
84
|
-
.optional()
|
|
85
|
-
|
|
86
|
-
});
|
|
47
|
+
.optional(),
|
|
48
|
+
})
|
|
87
49
|
|
|
88
|
-
export
|
|
50
|
+
export const EnvSchema = MockEnvSchema
|
|
51
|
+
|
|
52
|
+
export type Env = z.infer<typeof EnvSchema>
|
|
53
|
+
|
|
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
|
+
}
|
|
89
75
|
|
|
90
76
|
/**
|
|
91
77
|
* Check whether required commerce env vars are present.
|
|
92
|
-
* Used to bail out gracefully during build/SSG
|
|
78
|
+
* Used to bail out gracefully during build/SSG.
|
|
93
79
|
*/
|
|
94
80
|
export function isEnvConfigured(): boolean {
|
|
95
81
|
return Boolean(
|
|
96
82
|
process.env.NEXT_PUBLIC_COMMERCE_API_URL &&
|
|
97
83
|
process.env.NEXT_PUBLIC_COMMERCE_API_KEY
|
|
98
|
-
)
|
|
84
|
+
)
|
|
99
85
|
}
|
|
100
86
|
|
|
101
87
|
/**
|
|
102
88
|
* Validate and return environment variables.
|
|
103
|
-
* Throws detailed error if validation fails
|
|
89
|
+
* Throws detailed Zod error if validation fails.
|
|
104
90
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* Passing the whole process.env object to Zod would break client-side validation
|
|
108
|
-
* because Next.js only inlines individual property accesses.
|
|
109
|
-
*
|
|
110
|
-
* @throws {Error} if required env vars are missing or invalid
|
|
91
|
+
* NOTE: Each var is referenced individually so Next.js can
|
|
92
|
+
* statically replace NEXT_PUBLIC_* in the client bundle.
|
|
111
93
|
*/
|
|
112
94
|
export function getEnv(): Env {
|
|
113
95
|
try {
|
|
114
|
-
|
|
96
|
+
const rawEnv = {
|
|
115
97
|
NEXT_PUBLIC_COMMERCE_PROVIDER: process.env.NEXT_PUBLIC_COMMERCE_PROVIDER,
|
|
116
98
|
NEXT_PUBLIC_COMMERCE_API_URL: process.env.NEXT_PUBLIC_COMMERCE_API_URL,
|
|
117
99
|
NEXT_PUBLIC_COMMERCE_API_KEY: process.env.NEXT_PUBLIC_COMMERCE_API_KEY,
|
|
118
100
|
NEXT_PUBLIC_DEFAULT_CURRENCY: process.env.NEXT_PUBLIC_DEFAULT_CURRENCY,
|
|
119
|
-
HEALTH_CHECK_PATH: process.env.HEALTH_CHECK_PATH,
|
|
120
101
|
NEXT_PUBLIC_SALES_CHANNEL_ID: process.env.NEXT_PUBLIC_SALES_CHANNEL_ID,
|
|
121
|
-
COMMERCE_ADMIN_EMAIL: process.env.COMMERCE_ADMIN_EMAIL,
|
|
122
|
-
COMMERCE_ADMIN_PASSWORD: process.env.COMMERCE_ADMIN_PASSWORD,
|
|
123
|
-
COMMERCE_ADMIN_API_URL: process.env.COMMERCE_ADMIN_API_URL,
|
|
124
|
-
COMMERCE_ADMIN_TOKEN_TTL_MS: process.env.COMMERCE_ADMIN_TOKEN_TTL_MS,
|
|
125
102
|
FRONTEND_WEBHOOK_SECRET: process.env.FRONTEND_WEBHOOK_SECRET,
|
|
126
|
-
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (shouldUseMockProvider()) {
|
|
106
|
+
return MockEnvSchema.parse(rawEnv)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return RealBackendEnvSchema.parse(rawEnv)
|
|
127
110
|
} catch (error) {
|
|
128
111
|
if (error instanceof z.ZodError) {
|
|
129
112
|
const issues = error.issues
|
|
130
113
|
.map(issue => ` - ${issue.path.join('.')}: ${issue.message}`)
|
|
131
|
-
.join('\n')
|
|
114
|
+
.join('\n')
|
|
132
115
|
throw new Error(
|
|
133
|
-
`Invalid environment variables:\n${issues}\n\
|
|
134
|
-
|
|
135
|
-
);
|
|
116
|
+
`Invalid environment variables:\n${issues}\n\nSee .env.example for correct format.`
|
|
117
|
+
)
|
|
136
118
|
}
|
|
137
|
-
throw error
|
|
119
|
+
throw error
|
|
138
120
|
}
|
|
139
121
|
}
|
|
140
|
-
|
|
141
|
-
// Lazy getter — call getEnv() at runtime, not at module scope (avoids build-time failures
|
|
142
|
-
// when @thorprovider/core is compiled as a package template without environment variables).
|
|
143
|
-
export const env: Env = new Proxy({} as Env, {
|
|
144
|
-
get(_target, prop: string | symbol) {
|
|
145
|
-
return getEnv()[prop as keyof Env];
|
|
146
|
-
},
|
|
147
|
-
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { clsx, type ClassValue } from 'clsx'
|
|
2
2
|
import { twMerge } from 'tailwind-merge'
|
|
3
|
+
import type { Money } from '@thorprovider/types'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Merge Tailwind CSS class names safely.
|
|
@@ -8,3 +9,20 @@ import { twMerge } from 'tailwind-merge'
|
|
|
8
9
|
export function cn(...inputs: ClassValue[]) {
|
|
9
10
|
return twMerge(clsx(inputs))
|
|
10
11
|
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Format a Money object for display.
|
|
15
|
+
*
|
|
16
|
+
* Money.amount is a DECIMAL STRING (e.g. "29.99", NOT cents).
|
|
17
|
+
* This function converts it to a locale-formatted currency string.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* formatPrice({ amount: "29.99", currencyCode: "USD" }) // "$29.99"
|
|
21
|
+
* formatPrice({ amount: "1499.00", currencyCode: "EUR" }) // "€1,499.00"
|
|
22
|
+
*/
|
|
23
|
+
export function formatPrice(money: Money, locale = 'en-US'): string {
|
|
24
|
+
return new Intl.NumberFormat(locale, {
|
|
25
|
+
style: 'currency',
|
|
26
|
+
currency: money.currencyCode,
|
|
27
|
+
}).format(parseFloat(money.amount))
|
|
28
|
+
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thorprovider/core",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Thor Commerce
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Thor Commerce V0-native template. Lean storefront scaffold for V0 AI code generation.",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"prebuild": "PACKAGE_DIR=packages/core tsx ../../scripts/generate-regions-config.ts",
|
|
7
6
|
"build": "next build",
|
|
8
|
-
"predev": "PACKAGE_DIR=packages/core tsx ../../scripts/generate-regions-config.ts",
|
|
9
7
|
"dev": "next dev",
|
|
10
8
|
"start": "next start",
|
|
11
9
|
"type-check": "tsc --noEmit",
|
|
12
|
-
"generate:regions": "PACKAGE_DIR=packages/core tsx ../../scripts/generate-regions-config.ts",
|
|
13
10
|
"generate:agent-index": "node ../../scripts/generate-core-agents-index.cjs"
|
|
14
11
|
},
|
|
15
12
|
"dependencies": {
|
|
16
13
|
"@thorprovider/adapters": "^4.0.0",
|
|
17
|
-
"@thorprovider/components": "^2.0.0",
|
|
18
|
-
"@thorprovider/providers": "^2.0.0",
|
|
19
14
|
"@thorprovider/types": "^3.0.0",
|
|
20
15
|
"clsx": "^2.1.1",
|
|
21
16
|
"next": "16.0.10",
|
|
@@ -31,7 +26,6 @@
|
|
|
31
26
|
"@types/react-dom": "^19",
|
|
32
27
|
"postcss": "^8.5",
|
|
33
28
|
"tailwindcss": "^4.1.9",
|
|
34
|
-
"tsx": "^4.19.2",
|
|
35
29
|
"tw-animate-css": "1.3.3",
|
|
36
30
|
"typescript": "^5"
|
|
37
31
|
},
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design Tokens — shadcn/ui CSS variable naming convention.
|
|
3
|
+
*
|
|
4
|
+
* SWAP THIS FILE to rebrand a client project.
|
|
5
|
+
* Components never reference colors directly — only these tokens.
|
|
6
|
+
*
|
|
7
|
+
* To customize for a client:
|
|
8
|
+
* 1. Replace oklch values below with the client's brand palette.
|
|
9
|
+
* 2. No component files need to change.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
:root {
|
|
13
|
+
--background: oklch(0.98 0.002 90);
|
|
14
|
+
--foreground: oklch(0.15 0 0);
|
|
15
|
+
--card: oklch(1 0 0);
|
|
16
|
+
--card-foreground: oklch(0.15 0 0);
|
|
17
|
+
--popover: oklch(1 0 0);
|
|
18
|
+
--popover-foreground: oklch(0.15 0 0);
|
|
19
|
+
--primary: oklch(0.15 0 0);
|
|
20
|
+
--primary-foreground: oklch(0.98 0.002 90);
|
|
21
|
+
--secondary: oklch(0.96 0.003 90);
|
|
22
|
+
--secondary-foreground: oklch(0.15 0 0);
|
|
23
|
+
--muted: oklch(0.94 0.003 90);
|
|
24
|
+
--muted-foreground: oklch(0.45 0 0);
|
|
25
|
+
--accent: oklch(0.65 0.15 25);
|
|
26
|
+
--accent-foreground: oklch(1 0 0);
|
|
27
|
+
--destructive: oklch(0.55 0.2 25);
|
|
28
|
+
--destructive-foreground: oklch(1 0 0);
|
|
29
|
+
--border: oklch(0.88 0.003 90);
|
|
30
|
+
--input: oklch(0.92 0.003 90);
|
|
31
|
+
--ring: oklch(0.15 0 0);
|
|
32
|
+
--chart-1: oklch(0.646 0.222 41.116);
|
|
33
|
+
--chart-2: oklch(0.6 0.118 184.704);
|
|
34
|
+
--chart-3: oklch(0.398 0.07 227.392);
|
|
35
|
+
--chart-4: oklch(0.828 0.189 84.429);
|
|
36
|
+
--chart-5: oklch(0.769 0.188 70.08);
|
|
37
|
+
--radius: 0.375rem;
|
|
38
|
+
--sidebar: oklch(0.985 0 0);
|
|
39
|
+
--sidebar-foreground: oklch(0.145 0 0);
|
|
40
|
+
--sidebar-primary: oklch(0.205 0 0);
|
|
41
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
42
|
+
--sidebar-accent: oklch(0.97 0 0);
|
|
43
|
+
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
44
|
+
--sidebar-border: oklch(0.922 0 0);
|
|
45
|
+
--sidebar-ring: oklch(0.708 0 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.dark {
|
|
49
|
+
--background: oklch(0.145 0 0);
|
|
50
|
+
--foreground: oklch(0.985 0 0);
|
|
51
|
+
--card: oklch(0.145 0 0);
|
|
52
|
+
--card-foreground: oklch(0.985 0 0);
|
|
53
|
+
--popover: oklch(0.145 0 0);
|
|
54
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
55
|
+
--primary: oklch(0.985 0 0);
|
|
56
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
57
|
+
--secondary: oklch(0.269 0 0);
|
|
58
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
59
|
+
--muted: oklch(0.269 0 0);
|
|
60
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
61
|
+
--accent: oklch(0.269 0 0);
|
|
62
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
63
|
+
--destructive: oklch(0.396 0.141 25.723);
|
|
64
|
+
--destructive-foreground: oklch(0.637 0.237 25.331);
|
|
65
|
+
--border: oklch(0.269 0 0);
|
|
66
|
+
--input: oklch(0.269 0 0);
|
|
67
|
+
--ring: oklch(0.439 0 0);
|
|
68
|
+
--chart-1: oklch(0.488 0.243 264.376);
|
|
69
|
+
--chart-2: oklch(0.696 0.17 162.48);
|
|
70
|
+
--chart-3: oklch(0.769 0.188 70.08);
|
|
71
|
+
--chart-4: oklch(0.627 0.265 303.9);
|
|
72
|
+
--chart-5: oklch(0.645 0.246 16.439);
|
|
73
|
+
--sidebar: oklch(0.205 0 0);
|
|
74
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
75
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
76
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
77
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
78
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
79
|
+
--sidebar-border: oklch(0.269 0 0);
|
|
80
|
+
--sidebar-ring: oklch(0.439 0 0);
|
|
81
|
+
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Client-side Navigation Provider wrapper
|
|
5
|
-
*
|
|
6
|
-
* This component wraps the NavigationProvider from @thorprovider/providers
|
|
7
|
-
* with the appropriate configuration for Next.js App Router.
|
|
8
|
-
*
|
|
9
|
-
* IMPORTANT: Must be a Client Component because it contains functions
|
|
10
|
-
* (resolvers) that cannot be serialized for Server Components.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { NavigationProvider } from '@thorprovider/providers';
|
|
14
|
-
import NextLink from 'next/link';
|
|
15
|
-
import type { ReactNode } from 'react';
|
|
16
|
-
|
|
17
|
-
interface ClientNavigationProviderProps {
|
|
18
|
-
children: ReactNode;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function ClientNavigationProvider({ children }: ClientNavigationProviderProps) {
|
|
22
|
-
return (
|
|
23
|
-
<NavigationProvider
|
|
24
|
-
config={{
|
|
25
|
-
LinkComponent: NextLink,
|
|
26
|
-
resolvers: {
|
|
27
|
-
product: (product) => `/products/${product.handle}`,
|
|
28
|
-
category: (slug) => `/category/${slug}`,
|
|
29
|
-
search: (query) => `/search?q=${encodeURIComponent(query)}`,
|
|
30
|
-
},
|
|
31
|
-
debug: process.env.NODE_ENV === 'development',
|
|
32
|
-
}}
|
|
33
|
-
>
|
|
34
|
-
{children}
|
|
35
|
-
</NavigationProvider>
|
|
36
|
-
);
|
|
37
|
-
}
|