feat(resource-server): wire optional paywall into the example host#80
Conversation
`createResourceServerApp` now accepts an optional `paywall`
(`PaywallProvider`) and `paywallConfig` and forwards both to the
underlying `expressMiddleware` + `mountX402b` calls. Setting any
`PAYWALL_*` env var populates a `paywall` block on the parsed env so
a fork of the binary can `import { evmEscrowPaywall }` and hand both
to `createResourceServerApp` to enable HTML 402s for browser
User-Agents. Programmatic clients still see JSON.
Also widens `PaywallConfigLike` in `@bosonprotocol/x402-server-express`
from `Record<string, unknown>` to `object` so concrete `PaywallConfig`
shapes (with named optional fields, no index signature) satisfy it
structurally — required for the example to typecheck without casts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR wires an optional HTML paywall (via @bosonprotocol/x402-paywall) into the resource-server example host, forwarding paywall/paywallConfig through to @bosonprotocol/x402-server-express so browser clients can receive HTML 402 challenges while programmatic clients keep receiving JSON.
Changes:
- Extend
createResourceServerAppto accept optionalpaywall+paywallConfigand forward them into bothexpressMiddlewareandmountX402b. - Add
PAYWALL_*env parsing to produce apaywallconfig block and document it in the example README and index.ts fork guidance. - Add tests that validate the paywall wiring for both
GET /resourceandPOST /x402B/commit, and widenPaywallConfigLikein server-express to accept concretePaywallConfigshapes.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| typescript/packages/server-express/src/internal/x402-challenge.ts | Widens PaywallConfigLike to object to support structurally-typed concrete configs. |
| pnpm-lock.yaml | Adds workspace link for @bosonprotocol/x402-paywall in the example’s deps. |
| examples/resource-server/test/resource-server.test.ts | Adds tests validating HTML/JSON 402 behavior and wiring through both middleware surfaces. |
| examples/resource-server/src/index.ts | Updates fork/reference assembly comment to show paywall provider wiring. |
| examples/resource-server/src/config.ts | Parses PAYWALL_* env vars into an optional env.paywall config block. |
| examples/resource-server/src/app.ts | Adds optional paywall + paywallConfig options and forwards them to server-express adapters. |
| examples/resource-server/README.md | Documents new PAYWALL_* env vars and browser paywall behavior. |
| examples/resource-server/package.json | Adds @bosonprotocol/x402-paywall dependency. |
| .changeset/resource-server-example-paywall.md | Declares version bumps and summarizes the feature + type change. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
3bf8bfd
into
add-x402-server-express-paywall
Summary
createResourceServerAppnow accepts optionalpaywall(PaywallProvider) andpaywallConfig, forwarded to the underlyingexpressMiddlewareandmountX402bcalls.PAYWALL_APP_NAME,PAYWALL_WALLETCONNECT_PROJECT_ID,PAYWALL_TESTNET) populate apaywallblock on the parsed env; setting any of them opts in.src/index.ts's reference assembly comment now shows how a fork wires inevmEscrowPaywallalongside theexchangeReader.expressMiddleware(GET /resource) andmountX402b(POST /x402B/commit) using a stubPaywallProvider. End-to-end coverage against the realevmEscrowPaywalllives one PR up in@bosonprotocol/x402-server-express's own suite.Why this completes the staged rollout
This is the fourth and final PR in the browser-paywall sequence:
Drive-by fix
Widens `PaywallConfigLike` in `@bosonprotocol/x402-server-express` from `Record<string, unknown>` to `object` so concrete `PaywallConfig` shapes (with named optional fields, no index signature) satisfy it structurally. Required for this example to typecheck without casts; the structural-typing intent of `PaywallProviderLike` was already documented in #79.
Notes
Test plan
🤖 Generated with Claude Code