@stratum-hq/hono
@stratum-hq/hono provides Hono middleware that extracts tenant identity from requests and sets up AsyncLocalStorage context for downstream handlers.
Installation
Section titled “Installation”npm install @stratum-hq/hono @stratum-hq/sdk @stratum-hq/coreQuick Start
Section titled “Quick Start”import { Hono } from "hono";import { stratumMiddleware } from "@stratum-hq/hono";import { getTenantContext } from "@stratum-hq/sdk";
const app = new Hono();
app.use("*", stratumMiddleware({ // Extract tenant from a header (or use jwtClaim / pathParam) header: "x-tenant-id", // Optional: resolve full tenant context resolve: async (tenantId) => sdkClient.resolveTenant(tenantId),}));
app.get("/users", async (c) => { const tenantId = c.get("tenantId"); // set by the middleware const ctx = getTenantContext(); // full context via AsyncLocalStorage // ...});Features
Section titled “Features”- Tenant extraction – from header, JWT claim, or URL path parameter
- ALS context – sets tenant context via
runWithTenantContextfor downstream handlers - Optional resolve callback – fetch full tenant context from the control plane
- Lightweight – no heavy dependencies, structural types only
