Feature: add @x402/elysia adapter#2
Conversation
New package `@x402/elysia` providing an Elysia plugin for the x402
payment protocol. Mirrors the `@x402/hono` API surface:
- `paymentMiddleware` – Elysia plugin guarding routes with x402 checks
- `paymentMiddlewareFromHTTPServer` – lower-level variant
- `paymentMiddlewareFromConfig` – convenience variant
- `ElysiaAdapter` – HTTPAdapter implementation wrapping Elysia Context
- `setSettlementOverrides` – helper for per-request settlement overrides
Hooks are registered with `{ as: 'global' }` so the plugin guards routes
added to the parent app (required for Elysia 1.x plugin scoping).
38 vitest tests, build (ESM + CJS + DTS), lint, and format all pass.
Made-with: Cursor
- Document setSettlementOverrides / SETTLEMENT_OVERRIDES_HEADER /
SettlementOverrides as forward-compat shims (no-op in this fork's
@x402/core today); noted in settlement-headers.ts, middleware.ts,
README, CHANGELOG, and changeset
- Narrow peerDependencies.elysia from ^1.0.0 to ^1.2.0 to reflect
the minimum version where { as: 'global' } scoping and .state()
typing are reliable
- Add Supeer Labs to contributors in package.json
Made-with: Cursor
|
Additional precisions added in this commit: Settlement overrides — forward-compat shim
Peer dep narrowed to
Contributors Added |
|
Hey @ctibo , as per our discussions on meeting, we take this in and go for adding it as new customized x402 tolling packages that are useful to all chains and serve ALgorand as well but do not exist on Coinbase. |
Summary
@x402/elysiapackage undertypescript/packages/http/elysia/, providing an Elysia framework adapter for the x402 payment protocol.@x402/honoAPI surface and package shape (same scripts, tooling, exports, and test patterns).What's included
src/adapter.tsElysiaAdapterimplementingHTTPAdapterfrom@x402/coresrc/middleware.tspaymentMiddleware,paymentMiddlewareFromHTTPServer,paymentMiddlewareFromConfigsrc/settlement-headers.tssetSettlementOverrideshelper + header utilitiessrc/response-buffer.tsBufferfor settlementsrc/index.tssrc/adapter.test.tsElysiaAdaptersrc/index.test.tsKey design decisions
{ as: 'global' }— required in Elysia 1.x so the plugin guards routes added to the parent app after.use(). Without this, hooks are scoped locally to the plugin only.SETTLEMENT_OVERRIDES_HEADERis declared locally (not imported from@x402/core) because it is not yet exported from core. A comment notes where to switch once upstream exports it.responseHeadersin transport context: passed for parity withx402-foundation/expressv2.9.0. Cast throughas unknown as HTTPTransportContextuntil@x402/core's type is updated to include the field.Elysiaexplicitly — avoids TypeScript errors caused by the.state()call widening the store type.Changeset
.changeset/elysia-adapter-initial.mddeclares aminorbump for@x402/elysia.Test plan
pnpm --filter @x402/elysia build— ESM + CJS + DTS all succeedpnpm --filter @x402/elysia test— 38/38 vitest tests passpnpm --filter @x402/elysia lint:check— ESLint cleanpnpm --filter @x402/elysia format:check— Prettier clean