Skip to content

fix(#57): add environment validation with Zod#519

Merged
Smartdevs17 merged 3 commits into
Smartdevs17:mainfrom
rindicomfort:fix/57-env-validation
Jun 1, 2026
Merged

fix(#57): add environment validation with Zod#519
Smartdevs17 merged 3 commits into
Smartdevs17:mainfrom
rindicomfort:fix/57-env-validation

Conversation

@rindicomfort
Copy link
Copy Markdown
Contributor

Summary

Closes #57

Adds a Zod-based environment validation layer that runs at app startup, replacing silent process.env reads with a single validated, type-safe env singleton.

Files

src/config/env.ts (new)

Zod schema covering every environment variable the app consumes:

Variable Type Required Default
APP_ENV development|staging|production no development
EXPO_PUBLIC_API_URL URL string no sandbox URL
SUBTRACKR_API_KEY string no
WALLET_CONNECT_PROJECT_ID non-empty string no placeholder
WEBHOOK_SECRET string no
STELLAR_MAINNET_PROXY/STORAGE/SUBSCRIPTION_ID string no
STELLAR_TESTNET_PROXY/STORAGE/SUBSCRIPTION_ID string no

Behaviour:

  • validateEnv() calls safeParse and formats all Zod issues into a single human-readable message with one bullet per failing variable
  • Production (APP_ENV=production): throws Error — app refuses to start with a broken config (fail fast)
  • Development / staging: logs a console.warn with the full issue list and continues with defaults
  • Exports a validated env singleton — import env instead of process.env anywhere for type-safe access
  • All variables documented with JSDoc inline comments

App.tsx (updated)

  • Imports src/config/env at the top of the module so validation runs before any other code
  • Replaces process.env.WALLET_CONNECT_PROJECT_ID || 'YOUR_PROJECT_ID' with env.WALLET_CONNECT_PROJECT_ID

Acceptance Criteria

  • Schema defined for all env vars
  • Validation runs on app start (module-load time, before UI renders)
  • Clear errors for missing/invalid vars (formatted bullet list)
  • Type-safe access via env singleton (Env type inferred from schema)
  • Optional vars handled with .optional() / .default()
  • All vars documented inline

- 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
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@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! 🚀

Learn more about application limits

@Smartdevs17 Smartdevs17 merged commit bf242a3 into Smartdevs17:main Jun 1, 2026
3 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📱 Add environment validation with zod

2 participants