Shared contracts for the Suaveplan API middleware tier. Exports ApiMiddlewareError base class and API_MIDDLEWARE_CODES registry (RATE_LIMITED, UNAUTHENTICATED, FORBIDDEN, PAYLOAD_TOO_LARGE, AUDIT_SINK_FAILED) with default HTTP status mapping. Concrete middleware factories live in their own packages (api-middleware-rate-limit, rbac, cors, audit, body-limit, rules).
@suaveplan/api-middleware
Purpose
Shared contracts for the Suaveplan API middleware tier. Exports the stable ApiMiddlewareError base class and API_MIDDLEWARE_CODES registry used across all api-middleware-* packages.
This is a contract-only package — concrete middleware factories (rateLimitMiddleware, rbacMiddleware, corsMiddleware, auditMiddleware, bodyLimitMiddleware, rulesMiddleware) live in their own named packages. The redesigned pipeline order is tenant → auth → rate-limit → rbac → audit → handler; this package supplies the shared error vocabulary and status mappings that every middleware in that pipeline references.
Architecture
Component
Source
Role
API_MIDDLEWARE_CODES
src/error-codes/error-codes.ts
5-code API_MW.* registry
ApiMiddlewareError
src/error-codes/error-codes.ts
Typed error class with HTTP status
DEFAULT_STATUS_BY_CODE
src/error-codes/error-codes.ts
Default HTTP status map (429, 401, 403, 413, 500)
File Structure
src/
index.ts # Exports API_MIDDLEWARE_CODES, ApiMiddlewareError, DEFAULT_STATUS_BY_CODE
error-codes/
error-codes.ts # Registry + error class + status map
error-codes.md
import{API_MIDDLEWARE_CODES,ApiMiddlewareError,}from"@suaveplan/api-middleware";thrownewApiMiddlewareError(API_MIDDLEWARE_CODES.RATE_LIMITED,"too many requests");// status defaults to 429 via DEFAULT_STATUS_BY_CODE