Repository navigation
Conversation
f041465 to
45b784c
Compare
🦋 Changeset detectedLatest commit: 2a540b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
New `radius-sdk/server` entry point holding the seller core independently of
how requests arrive:
- `radiusPayments()` is a web-standard handler (Request in, Response out) for
Workers without a framework, Bun, Deno, Node 18+, and Next.js / SvelteKit /
Remix route handlers. Paid handlers receive the settled receipt; `wrap()`
gives a single fetch function; `requiresPayment()` is a no-I/O route check.
- `createRadiusServer()` exposes the Radius x402 resource server and a
`routes()` builder for the upstream adapters:
`paymentMiddleware(radius.routes({...}), radius.server)` with
`@x402/express`, `@x402/next` or `@x402/hono`.
- `onSettled` is registered via x402 core's after-settle hook so it fires for
every adapter. Errors it throws are logged by core instead of failing the
request.
- `radius-sdk/hono` becomes a thin wrapper over the handler with unchanged
options and tests; `RadiusHonoAdapter` is removed. facilitator.ts and
scheme.ts move to src/server/.
- `@x402/core` and `@x402/evm` 2.25.0 -> 2.27.0 (the line the upstream
adapters require).
- Examples: `examples/worker-plain` (no framework) and
`examples/express-seller` (`@x402/express`), same API as the Hono worker.
Verified: 123 unit tests + import guard (new test/server.test.ts covers the
handler and Express through the real upstream adapter); 17 e2e tests on
testnet including a real settlement through the plain handler; stock
`radius-cli wallet x402` paid worker-plain under `wrangler dev`
(0xb9e874a455fec5ad1bb39b35ff9614b56a1a2e93fbd859b77cb7f8bc2c62289a) and
express-seller on Node
(0xcd44add4aa1f43c5a7613efa23b27ad52efae7843e28a5188d508341cc80615e).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PtERNnagj1qYiSHvfLpdtu
45b784c to
2a540b6
Compare
|
From Codex: I tested an independent seller while evaluating this generic server shape: Two additions would help
The new malformed-header and failed-settlement tests already cover two faults the EmDash package exposed (its malformed header produced 500; its |
|
Review of the new 1. Settle-before mode buffers every paid response, which breaks streaming. 2. A buyer can pay and get nothing (comment item 1). With the default settle-before, a handler 4xx/5xx after settlement returns the error with a receipt after funds have moved. Suggest a pre-payment check hook (e.g. 3. 4. 5. Minor: the Generated by Claude Code |
|
Consolidating the review items from our discussion:
MCP support is out of scope for this work. |
Makes the seller side framework-agnostic. The Radius-specific pieces (facilitator client,
exactscheme, SBC pricing, gas-sponsoring rules) now live in one x402 resource server that does not know how requests arrive; adapters are thin layers over it.What changes
New
radius-sdk/serverentry point:radiusPayments()— web-standard handler,Requestin,Responseout. Runs on Cloudflare Workers without a framework, Bun, Deno, Node 18+, and Next.js / SvelteKit / Remix route handlers. Paid handlers receive the settled receipt as a second argument;wrap()returns a single fetch function;requiresPayment()checks a route without I/O.createRadiusServer()— exposes the x402 resource server (radius.server) and aroutes()builder, so the upstream adapters work directly:paymentMiddleware(radius.routes({ … }), radius.server)with@x402/express,@x402/nextor@x402/hono.radius.http()returns anx402HTTPResourceServerfor their…FromHTTPServervariants.onSettledis registered through x402 core's after-settle hook, so it fires whichever adapter served the request. It receives the x402 request context;requestOf(context)returns theRequestfor the SDK's own adapters. Behaviour change: an error thrown insideonSettledis logged by core rather than failing the request.radius-sdk/honois now a thin wrapper over the handler: same options, dynamicpayTo/price/onSettledstill receive the Hono context,c.get('radiusPayment')unchanged.RadiusHonoAdapteris removed.facilitator.tsandscheme.tsmove fromsrc/hono/tosrc/server/(still re-exported fromradius-sdk/hono).@x402/core/@x402/evmgo from 2.25.0 to 2.27.0, the line the upstream adapters depend on. The SDK's own handler keeps lazy, request-time facilitator initialisation; the upstream adapters fetch/supportedat construction by default and theirsyncFacilitatorOnStart: falsemeans never rather than lazily, so on Workers callers mustawait radius.server.initialize()themselves. README says so.Examples:
examples/worker-plain(no framework, port 8788) andexamples/express-seller(@x402/express, port 8789), same API as the Honoworker-seller.Verified
test/server.test.tscovers the handler (challenge shape, dynamic payTo/price, browser paywall, settle before/after, failed settlement, malformed header, immutable upstream headers, handler failure paths) and runs Express through the real@x402/expressadapter with a mocked facilitator.onSettledobserved.radius-cli wallet x402paid both new examples on testnet: worker-plain underwrangler dev(0xb9e874a455fec5ad1bb39b35ff9614b56a1a2e93fbd859b77cb7f8bc2c62289a), express-seller on Node (0xcd44add4aa1f43c5a7613efa23b27ad52efae7843e28a5188d508341cc80615e). Both logged the receipt throughonSettled.changeset status: radius-sdk minor, radius-cli patch.🤖 Generated with Claude Code
https://claude.ai/code/session_01PtERNnagj1qYiSHvfLpdtu