Skip to content

fix(x402): share single validated config across Express and Vercel ru… - #379

Merged
Emmy123222 merged 1 commit into
Emmy123222:mainfrom
DevRushd:fix/108-shared-x402-config
Sep 3, 2026
Merged

fix(x402): share single validated config across Express and Vercel ru…#379
Emmy123222 merged 1 commit into
Emmy123222:mainfrom
DevRushd:fix/108-shared-x402-config

Conversation

@DevRushd

Copy link
Copy Markdown
Contributor

Share one x402 route and asset configuration across runtimes

Problem

Express (server/index.ts) and Vercel (api/search.ts) each independently hardcoded their own x402 payment configuration — network, asset, amount, payTo, timeout, and fee sponsorship. Any future change to one runtime's config could silently drift out of sync, breaking payment consistency across deployments.

Solution

Created a single validated source of truth at src/lib/x402Config.ts that both runtimes consume:

  • X402Config interface — typed configuration object with runtime validation
  • getX402Config() — memoized function that reads from constants.ts and validates all required fields on first call, throwing descriptive errors for missing/invalid values
  • buildPaymentRequiredPayload() — generates a standards-compliant x402-payment-required response body from the shared config (used by Vercel)
  • buildExpressRoutes() — mounts the x402 payment middleware on Express routes using the same shared config (used by Express)
  • getX402ConfigSnapshot() — exported for snapshot testing

Both server/index.ts and api/search.ts now import from this single module instead of defining config inline.

Files Changed

File Change
src/lib/x402Config.ts New — shared config module
src/lib/x402Config.test.ts New — 25 tests (validation, snapshot comparison, runtime parity)
server/index.ts Refactored to use buildExpressRoutes() from shared config
api/search.ts Refactored to use buildPaymentRequiredPayload() from shared config
server/validateQuery.test.ts Updated env setup for compatibility with new import-time validation

Tests

  • 25 new tests in x402Config.test.ts covering:
    • Config validation (missing fields, invalid values, memoization)
    • Snapshot comparison between Express and Vercel payment requirement payloads
    • Runtime parity verification
  • All 224 tests pass across 17 test files

Validation

  • ✅ TypeScript compilation passes (tsc --noEmit) for server, API, and frontend configs
  • ✅ Full test suite passes (224/224)
  • ✅ Branch rebased on latest upstream/mainno merge conflicts
  • ✅ Express, Vercel, browser, and MCP behavior aligned through shared config
  • ✅ x402 settlement semantics preserved

Closes #108

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@DevRushd 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

@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@DevRushd is attempting to deploy a commit to the Emmanuel's projects Team on Vercel.

A member of the Team first needs to authorize it.

@AbuJulaybeeb AbuJulaybeeb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase the whole branch

@AbuJulaybeeb AbuJulaybeeb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve conflicts

…ntimes (Emmy123222#108)

Introduce src/lib/x402Config.ts as the single source of truth for x402
payment route and asset configuration. Both Express (server/index.ts) and
Vercel (api/search.ts) now import this module, eliminating protocol drift
between the two runtimes.

Changes:
- New src/lib/x402Config.ts with validated getters for network, asset,
  amount, payTo, timeout, and fee sponsorship
- server/index.ts updated to use buildExpressRoutes() from x402Config
- api/search.ts updated to use buildPaymentRequiredPayload() from x402Config
- 25 new snapshot tests in x402Config.test.ts comparing Express/Vercel output
- validateQuery.test.ts env setup fixed for x402Config initialization

Closes Emmy123222#108

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@DevRushd
DevRushd force-pushed the fix/108-shared-x402-config branch from a82df30 to 728198e Compare September 2, 2026 11:40
@DevRushd

DevRushd commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@AbuJulaybeeb I have resolved conflicts and rebase the branch. Kindly review and merge

@Emmy123222
Emmy123222 merged commit 712fcc3 into Emmy123222:main Sep 3, 2026
0 of 2 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.

Share one x402 route and asset configuration across runtimes

3 participants