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.

Installation

Terminal window
npm install @stratum-hq/hono @stratum-hq/sdk @stratum-hq/core

Quick Start

import { Hono } from "hono";
import { stratumMiddleware } from "@stratum-hq/hono";
const app = new Hono();
app.use("*", stratumMiddleware({
// Extract tenant from header, JWT, or path param
extract: (c) => c.req.header("x-tenant-id"),
// Optional: resolve full tenant context
resolve: async (tenantId) => {
return stratum.resolveContext(tenantId);
},
}));
app.get("/users", async (c) => {
// Tenant context available via ALS
const tenantId = Stratum.currentTenantId();
// ...
});

Features

  • 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