@saplings/middleware
v0.18.0
Published
Compose Node HTTP middleware for correlation IDs, authentication, validation, caching, and request limits.
Readme
@saplings/middleware
Compose Node HTTP middleware for correlation IDs, authentication, validation, caching, and request limits.
Install
npm install @saplings/middleware @saplings/validationsQuick start
import { correlationId, requireAuth, validate } from '@saplings/middleware';
import { z } from '@saplings/validations';
const createProjectMiddleware = [
correlationId(),
requireAuth(),
validate({ body: z.object({ name: z.string().min(1).max(80) }) }),
];API and integration
- Mount bounded parsing and trusted authentication before the protected middleware.
requireAuth()expects a populated server-side Sapling context. validate(schemas)callssafeParseAsyncand places validated values inreq.validated. Install your error middleware after the routes.createMiddleware(config?)constructs middleware from configuration. In-memory cache and idempotency stores are local process state. Use an appropriate shared implementation for multiple replicas.
Read the integration guide for configuration and operational details.
Verified gateway identity
requireGatewayAssertion({ verify, rawBody }) integrates the Harbor assertion verifier before authorization. Capture the exact bounded request bytes, including an empty byte array for empty requests. Mount before route authorization and supply a shared atomic nonce store to the verifier. Only the verified tenant and subject are assigned; load roles and permissions separately. Missing or invalid assertions and verifier errors fail closed.
