@stratum-hq/hono 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/package.json +8 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Christian Crank
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @stratum-hq/hono
|
|
2
|
+
|
|
3
|
+
[Hono](https://hono.dev) middleware for [Stratum](https://github.com/stratum-hq/Stratum) — extracts tenant identity from a request and sets up AsyncLocalStorage context for downstream handlers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @stratum-hq/hono @stratum-hq/sdk @stratum-hq/core hono
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Hono } from "hono";
|
|
15
|
+
import { stratumMiddleware } from "@stratum-hq/hono";
|
|
16
|
+
import { getTenantContext } from "@stratum-hq/sdk";
|
|
17
|
+
|
|
18
|
+
const app = new Hono();
|
|
19
|
+
|
|
20
|
+
app.use("*", stratumMiddleware({
|
|
21
|
+
header: "x-tenant-id",
|
|
22
|
+
// Optional: fetch the full tenant context (ancestry, config, permissions)
|
|
23
|
+
resolve: async (tenantId) => sdkClient.resolveTenant(tenantId),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
app.get("/users", (c) => {
|
|
27
|
+
const tenantId = c.get("tenantId"); // raw ID set by the middleware
|
|
28
|
+
const ctx = getTenantContext(); // full context via AsyncLocalStorage
|
|
29
|
+
return c.json({ tenantId, config: ctx.resolved_config });
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Options
|
|
34
|
+
|
|
35
|
+
`stratumMiddleware(options)` extracts the tenant ID from exactly one source, in this precedence:
|
|
36
|
+
|
|
37
|
+
| Option | Behavior |
|
|
38
|
+
|--------|----------|
|
|
39
|
+
| `jwtClaim` | Read the claim from Hono's `jwtPayload` context variable |
|
|
40
|
+
| `pathParam` | Read a URL path parameter (`c.req.param(name)`) |
|
|
41
|
+
| `header` | Read a request header (default: `x-tenant-id`) |
|
|
42
|
+
| `resolve` | Optional callback `(tenantId) => TenantContext` to populate ancestry, config, and permissions |
|
|
43
|
+
|
|
44
|
+
If no tenant ID is found, the middleware responds with `400 { error: "Missing tenant ID" }`. Without a `resolve` callback the context is a placeholder (empty config/permissions) — provide `resolve` for real tenant data.
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- Tenant extraction from header, JWT claim, or path parameter
|
|
49
|
+
- Binds tenant context via `runWithTenantContext` so downstream handlers can call `getTenantContext()`
|
|
50
|
+
- Lightweight — structural types only, no heavy dependencies
|
|
51
|
+
|
|
52
|
+
## Links
|
|
53
|
+
|
|
54
|
+
- Documentation: https://docs.stratum-hq.org/packages/hono/
|
|
55
|
+
- GitHub: https://github.com/stratum-hq/Stratum
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT © Christian Crank
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stratum-hq/hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Stratum Hono integration — tenant extraction middleware with ALS context",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"multi-tenancy",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@stratum-hq/core": ">=0.
|
|
41
|
-
"@stratum-hq/sdk": ">=0.
|
|
40
|
+
"@stratum-hq/core": ">=0.3.0",
|
|
41
|
+
"@stratum-hq/sdk": ">=0.3.0",
|
|
42
42
|
"hono": ">=4.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -47,5 +47,10 @@
|
|
|
47
47
|
"hono": "^4.0.0",
|
|
48
48
|
"typescript": "^5.4.0",
|
|
49
49
|
"vitest": "^1.6.0"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/stratum-hq/Stratum.git",
|
|
54
|
+
"directory": "packages/hono"
|
|
50
55
|
}
|
|
51
56
|
}
|