feat(config): type-safe config module with Zod validation#33
Merged
oomokaro1 merged 2 commits intoJun 24, 2026
Conversation
Introduces a Zod-validated ConfigModule that replaces scattered process.env reads across the codebase with a single typed ConfigService. - src/config/config.schema.ts: full Zod schema with coercions, transforms, and environment-specific validation (production rejects defaults) - src/config/config.module.ts: NestJS ConfigModule wrapper (isGlobal: true) - scripts/config-check.ts + npm run config:check: validates .env without starting the app, useful in CI / Docker health checks - Injects ConfigService into: CheckoutService, StellarService, RedisService, AuthService, PaymentDetectorService, WebhookQueueService, DynamicCorsMiddleware - Updates all specs to provide ConfigService mocks; adds 14 new config tests - jest-setup.ts: adds test env vars required by Zod schema - .env.example: rewritten with all vars, required vs optional annotations Closes OrbitStream#11
oomokaro1
approved these changes
Jun 24, 2026
oomokaro1
left a comment
Contributor
There was a problem hiding this comment.
LGTM — type-safe config module with Zod validation. Merge conflicts resolved, only minor lint issues remaining (extra blank lines in checkout.service.spec.ts). Approving to unblock merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11
What changed
Zod schema (
src/config/config.schema.ts)z.coerce), URL validation, string minimums, enum checks, and defaultsCORS_ALLOWED_ORIGINStransforms a comma-separated string intostring[]STELLAR_NETWORK_PASSPHRASEis optional (derived from the network enum at runtime)validate()export: crashes with a descriptive, field-level error on invalid input; in production all defaultable keys must be explicitly set (no silent fallbacks); in development missing defaults emit aconsole.warnConfig module (
src/config/config.module.ts)@nestjs/config'sConfigModule.forRootwithisGlobal: true,cache: true, and the ZodvalidatehookAppModuleimports it first so validation runs at bootstrap — misconfiguration surfaces immediately, not mid-requestAll
process.env.*reads migrated toConfigServiceCheckoutService,StellarService,RedisService,AuthService,PaymentDetectorService,WebhookQueueService,DynamicCorsMiddleware— all now injectConfigService<Config>with{ infer: true }for full TypeScript type inferenceconfig:checkscriptscripts/config-check.ts— callsvalidate(process.env)and exits 0/1"config:check": "ts-node scripts/config-check.ts"added topackage.json— useful for CI/CD and Docker health checks.env.exampleTests (
src/config/config.schema.spec.ts— 14 tests)DATABASE_URL, shortJWT_SECRET, invalid URL, non-G receiving account, unknownSTELLAR_NETWORK— all rejectedvalidate()throws a descriptive field-level message on invalid inputHow to test