Skip to content

feat(resource-server): wire optional paywall into the example host#80

Merged
levalleux-ludo merged 3 commits into
add-x402-server-express-paywallfrom
add-x402-paywall-example
May 21, 2026
Merged

feat(resource-server): wire optional paywall into the example host#80
levalleux-ludo merged 3 commits into
add-x402-server-express-paywallfrom
add-x402-paywall-example

Conversation

@levalleux-ludo
Copy link
Copy Markdown
Member

Summary

  • createResourceServerApp now accepts optional paywall (PaywallProvider) and paywallConfig, forwarded to the underlying expressMiddleware and mountX402b calls.
  • New env vars (PAYWALL_APP_NAME, PAYWALL_WALLETCONNECT_PROJECT_ID, PAYWALL_TESTNET) populate a paywall block on the parsed env; setting any of them opts in.
  • src/index.ts's reference assembly comment now shows how a fork wires in evmEscrowPaywall alongside the exchangeReader.
  • Two new tests verify the wiring through both expressMiddleware (GET /resource) and mountX402b (POST /x402B/commit) using a stub PaywallProvider. End-to-end coverage against the real evmEscrowPaywall lives 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:

  1. feat: add initial implementation of x402-client-browser with tests and docs #77 `@bosonprotocol/x402-client-browser` — viem WalletClient / EIP-1193 → Signer adapters
  2. feat: add @bosonprotocol/x402-paywall package #78 `@bosonprotocol/x402-paywall` — React+wagmi paywall bundle + `generateHtml` server entry
  3. feat(server-express): add paywall + paywallConfig options #79 `@bosonprotocol/x402-server-express` — `paywall:` option + Accept content negotiation
  4. feat(resource-server): wire optional paywall into the example host #80 (this PR) — example host wiring; fork `src/index.ts`, set `PAYWALL_*` env vars, browse to `/resource` and see the paywall

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

  • `pnpm --filter @bosonprotocol/x402-example-resource-server build` — clean
  • `pnpm --filter @bosonprotocol/x402-example-resource-server test` — 14/14 (11 existing + 3 new)
  • Repo-wide `pnpm build` — 16/16 successful
  • Repo-wide `pnpm test` — 32/32 successful
  • Repo-wide `pnpm lint` — 16/16 successful
  • Repo-wide `pnpm format:check` — clean
  • Manual browser smoke test — needs a forked binary with `ExchangeReader` wired in and a live facilitator; deferred to your local environment.

🤖 Generated with Claude Code

`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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5623093a-4981-4b05-8ed9-9636ba83dcc2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-x402-paywall-example

Comment @coderabbitai help to get the list of available commands and usage tips.

@levalleux-ludo levalleux-ludo marked this pull request as ready for review May 21, 2026 13:39
Copilot AI review requested due to automatic review settings May 21, 2026 13:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 createResourceServerApp to accept optional paywall + paywallConfig and forward them into both expressMiddleware and mountX402b.
  • Add PAYWALL_* env parsing to produce a paywall config block and document it in the example README and index.ts fork guidance.
  • Add tests that validate the paywall wiring for both GET /resource and POST /x402B/commit, and widen PaywallConfigLike in server-express to accept concrete PaywallConfig shapes.

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.

Comment thread examples/resource-server/src/config.ts
Comment thread examples/resource-server/README.md Outdated
levalleux-ludo and others added 2 commits May 21, 2026 17:25
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@levalleux-ludo levalleux-ludo merged commit 3bf8bfd into add-x402-server-express-paywall May 21, 2026
1 check passed
@levalleux-ludo levalleux-ludo deleted the add-x402-paywall-example branch May 26, 2026 09:03
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.

2 participants