@@ -215,15 +215,46 @@ To deploy Dongle to production:
215215
216216### Validation & Error Handling
217217
218- - ** Development** (` NODE_ENV=development ` ): Invalid env vars use safe defaults and log warnings
219- - ** Test** (` NODE_ENV=test ` ): Invalid env vars use safe defaults
220- - ** Production** (` NODE_ENV=production ` ): Invalid env vars cause build/startup failure with clear error messages
218+ Environment variables are validated at build time and runtime using Zod schemas ([ ` constants/env.schema.ts ` ] ( ./constants/env.schema.ts ) ):
221219
222- Example error output:
220+ - ** Development** (` NODE_ENV=development ` ): Missing values use safe defaults, validation warnings logged
221+ - ** Test** (` NODE_ENV=test ` ): Missing values use safe defaults
222+ - ** Production** (` NODE_ENV=production ` ): All required values must be explicitly set, invalid values cause startup failure
223+
224+ ** Validation Features:**
225+ - Contract ID format validation (56 chars: C + 55 base32)
226+ - URL validation for RPC endpoints
227+ - Stellar public key validation for admin allowlists
228+ - Production-specific checks (no placeholder contract IDs)
229+ - Admin JWT secret requirement when admin features are enabled
230+
231+ Example validation error output:
232+ ```
233+ ╔══════════════════════════════════════════════════════════════╗
234+ ║ ENVIRONMENT CONFIGURATION ERROR ║
235+ ╚══════════════════════════════════════════════════════════════╝
236+
237+ Environment: PRODUCTION
238+
239+ The following environment variables are invalid:
240+ - NEXT_PUBLIC_PROJECT_REGISTRY_CONTRACT: Development placeholder contract ID not allowed in production. Deploy contracts and set real contract IDs.
241+ - NEXT_PUBLIC_SOROBAN_RPC_URL: Must be a valid HTTPS URL
242+
243+ See:
244+ - dongle/.env.example for configuration template
245+ - dongle/DEPLOYMENT.md for production checklist
246+ - dongle/constants/env.schema.ts for schema reference
223247```
224- Environment Validation Error:
225- - NEXT_PUBLIC_PROJECT_REGISTRY_CONTRACT: Invalid Stellar Contract ID format
226- - NEXT_PUBLIC_SOROBAN_RPC_URL: Invalid URL
248+
249+ ** Programmatic Validation:**
250+ ``` typescript
251+ import { validateEnv , exportJsonSchema } from ' @/constants/env.schema' ;
252+
253+ // Validate environment
254+ const config = validateEnv (process .env , isDevelopment );
255+
256+ // Export JSON Schema for external tools
257+ const jsonSchema = exportJsonSchema ();
227258```
228259
229260## Project Structure
0 commit comments