forked from ritik4ever/stellar-goal-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateEnv.ts
More file actions
52 lines (48 loc) · 1.84 KB
/
Copy pathvalidateEnv.ts
File metadata and controls
52 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { z } from 'zod';
const envSchema = z.object({
// Required
CONTRACT_ID: z.string().min(1, 'CONTRACT_ID is required for Soroban pledge signing'),
// Optional with documented defaults
PORT: z.string().optional().describe('default: 3001'),
NODE_ENV: z.string().optional().describe('default: development'),
LOG_LEVEL: z
.enum(['debug', 'info', 'warn', 'error', 'silent'])
.optional()
.describe('default: info'),
DB_PATH: z.string().optional().describe('default: backend/data/campaigns.db'),
SOROBAN_RPC_URL: z
.string()
.url()
.optional()
.describe('default: testnet RPC in non-production; required in production'),
SOROBAN_NETWORK_PASSPHRASE: z
.string()
.optional()
.describe('default: testnet passphrase in non-production; required in production'),
ALLOWED_ASSETS: z.string().optional().describe('default: USDC,XLM'),
ALLOWED_ORIGINS: z.string().optional().describe('default: (empty — all origins allowed in dev)'),
ASSET_ADDRESSES: z.string().optional().describe('default: XLM and USDC testnet addresses'),
CONTRACT_AMOUNT_DECIMALS: z
.string()
.regex(/^\d+$/, 'CONTRACT_AMOUNT_DECIMALS must be a non-negative integer')
.optional()
.describe('default: 2'),
DEFAULT_MAX_PER_CONTRIBUTOR: z
.string()
.regex(/^\d+$/, 'DEFAULT_MAX_PER_CONTRIBUTOR must be a non-negative integer')
.optional()
.describe('default: 0 (no limit)'),
});
export function validateEnv(): void {
const result = envSchema.safeParse(process.env);
if (!result.success) {
const missing = result.error.issues.map(
(issue) => ` - ${issue.path.join('.')}: ${issue.message}`,
);
// eslint-disable-next-line no-console
console.error(
`\n[startup] Environment validation failed. Fix the following before starting:\n${missing.join('\n')}\n`,
);
process.exit(1);
}
}