Validate Soroban env vars at build time - #215
Conversation
Add validateEnv(), called from next.config.ts before build/dev/start, which fails fast with an aggregated error instead of letting missing or malformed config silently fall through to demo-mode data or a runtime 500: - NEXT_PUBLIC_FACTORY_CONTRACT_ID: required, must be a valid Soroban contract id (StrKey.isValidContract, matching the check already used in feeBumpGuard.ts) - NEXT_PUBLIC_SOROBAN_RPC_URL: if set, must be a valid URL (has a network-preset fallback otherwise) - STELLAR_FEE_SPONSOR_SECRET: required and must be a valid Stellar secret key in server mode only, since /api/sign-fee-bump does not exist under static export Covered by 7 Vitest cases in validateEnv.test.ts (missing/invalid value per var, static-export vs server-mode branching, happy path). No new dependencies.
❌ Deploy Preview for smart-drop failed.
|
❌ Deploy Preview for spiffy-melomakarona-eb1e8a failed.
|
|
Hi team! I noticed this issue was unassigned but had a few folks in the queue. I had some free time and went ahead and implemented the full solution with Vitest coverage (7/7 passing) just to speed things up in case you need a quick merge. I fully respect the Drips Network assignment process, so feel free to review or handle it however fits your workflow best. Cheers! |
…ntexts Netlify sets CONTEXT to production/deploy-preview/branch-deploy. The strict validateEnv() from the previous commit blocks deploy-preview builds that don't have production Soroban config (NEXT_PUBLIC_FACTORY_CONTRACT_ID, STELLAR_FEE_SPONSOR_SECRET) configured in Netlify - those builds fell into silent demo mode before this PR too, so warn-and-continue there is not a regression, just a louder version of the previous behavior. Local dev/build and the production context stay strict, per the original issue. 9/9 tests green, including two new cases for the strict:false path.
|
Following up on the failed deploy previews above. My validateEnv() from this PR was strict in every context, including Netlify's But that's not the whole story: I also checked out a clean copy of |
Unrelated to this PR's env-validation change, but next build type-checks the whole app, so these also block this branch's own Netlify preview: - getPoolHistory's return type was missing the array brackets - the implementation always returns an array (via .map(...) on success or [] on catch), so every caller consuming it as a single object was wrong. - Account was used (accountCache/inflightAccount maps) but never imported from @stellar/stellar-sdk. Same root-cause fix as PR SmartDropLabs#246 (opened separately against main, since these bugs pre-date this branch); applying it here directly too so this PR's own Netlify checks aren't blocked on SmartDropLabs#246 landing first.
|
Pushed a fix for two pre-existing type errors on this branch (not caused by this PR's env-validation change, but
Same root cause I already fixed separately in #246 (opened against One remaining caveat I can't fix from here: |
Fixes #199.
Adds
validateEnv(), called fromnext.config.tsbeforebuild/dev/start, so the app fails fast with a clear, aggregated error instead of silently falling back to demo-mode data or a runtime 500 when config is missing or malformed.Validates the three variables named in the issue:
NEXT_PUBLIC_FACTORY_CONTRACT_ID— required, must be a valid Soroban contract id (StrKey.isValidContract, the same check already used infeeBumpGuard.ts).NEXT_PUBLIC_SOROBAN_RPC_URL— if set, must be a valid URL (it already has a network-preset fallback, so it isn't required).STELLAR_FEE_SPONSOR_SECRET— required and must be a valid Stellar secret key only in server mode, since the/api/sign-fee-bumproute it backs doesn't exist under static export.Repro from the issue, verified locally: with the vars unset,
npm run buildused to succeed silently in demo mode; with this change it now aborts immediately with:With valid values set,
next buildpasses validation and compiles successfully.Tests
7 new Vitest cases in
src/config/validateEnv.test.ts, all green: happy path, missing/invalid value for each variable individually, and the static-export vs. server-mode branch forSTELLAR_FEE_SPONSOR_SECRET.No new dependencies — reuses
StrKeyfrom@stellar/stellar-sdk, already a project dependency.