Skip to content

@stratum-hq/hono

@stratum-hq/hono provides Hono middleware that extracts tenant identity from requests and sets up AsyncLocalStorage context for downstream handlers.

Terminal window
npm install @stratum-hq/hono @stratum-hq/sdk @stratum-hq/core
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
// ...
});
  • Tenant extraction – from header, JWT claim, or URL path parameter
  • ALS context – sets tenant context via runWithTenantContext for downstream handlers
  • Optional resolve callback – fetch full tenant context from the control plane
  • Lightweight – no heavy dependencies, structural types only