fix(#57): add environment validation with Zod#519
Merged
Conversation
- Add src/config/env.ts with a Zod schema covering all env vars:
APP_ENV (enum: development|staging|production, default: development)
EXPO_PUBLIC_API_URL (url, default: sandbox URL)
SUBTRACKR_API_KEY (optional string)
WALLET_CONNECT_PROJECT_ID (non-empty string, default: placeholder)
WEBHOOK_SECRET (optional — backend only)
STELLAR_MAINNET/TESTNET_PROXY/STORAGE/SUBSCRIPTION_ID (all optional)
- validateEnv() runs safeParse and formats all Zod issues into a
single human-readable message with bullet points per failing var
- Hard-throws in production (APP_ENV=production) so the app refuses
to start with a broken config; warns in dev/staging and continues
- Exports a validated env singleton — import env instead of reading
process.env directly anywhere in the codebase for type-safe access
- All vars documented inline with JSDoc comments
- Import src/config/env at the top of App.tsx so validateEnv() runs at module load time, before any other code executes - Replace bare process.env.WALLET_CONNECT_PROJECT_ID read with env.WALLET_CONNECT_PROJECT_ID from the validated singleton — gives type-safe access and removes the manual || fallback
|
@rindicomfort Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Closes #57
Adds a Zod-based environment validation layer that runs at app startup, replacing silent
process.envreads with a single validated, type-safeenvsingleton.Files
src/config/env.ts(new)Zod schema covering every environment variable the app consumes:
APP_ENVdevelopment|staging|productiondevelopmentEXPO_PUBLIC_API_URLSUBTRACKR_API_KEYWALLET_CONNECT_PROJECT_IDWEBHOOK_SECRETSTELLAR_MAINNET_PROXY/STORAGE/SUBSCRIPTION_IDSTELLAR_TESTNET_PROXY/STORAGE/SUBSCRIPTION_IDBehaviour:
validateEnv()callssafeParseand formats all Zod issues into a single human-readable message with one bullet per failing variableAPP_ENV=production): throwsError— app refuses to start with a broken config (fail fast)console.warnwith the full issue list and continues with defaultsenvsingleton — importenvinstead ofprocess.envanywhere for type-safe accessApp.tsx(updated)src/config/envat the top of the module so validation runs before any other codeprocess.env.WALLET_CONNECT_PROJECT_ID || 'YOUR_PROJECT_ID'withenv.WALLET_CONNECT_PROJECT_IDAcceptance Criteria
envsingleton (Envtype inferred from schema).optional()/.default()