@stratum-hq/nestjs 0.2.4 → 0.3.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. 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,64 @@
1
+ # @stratum-hq/nestjs
2
+
3
+ First-class [NestJS](https://nestjs.com) integration for [Stratum](https://github.com/stratum-hq/Stratum) — a guard that resolves tenants from incoming requests, a `@Tenant()` parameter decorator, and a DI module.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @stratum-hq/nestjs @stratum-hq/sdk @stratum-hq/core
9
+ ```
10
+
11
+ Peer dependencies: `@nestjs/common >= 10`, `@nestjs/core >= 10`, `reflect-metadata`.
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { Module } from "@nestjs/common";
17
+ import { StratumModule } from "@stratum-hq/nestjs";
18
+
19
+ @Module({
20
+ imports: [
21
+ StratumModule.forRoot({
22
+ controlPlaneUrl: "http://localhost:3001",
23
+ apiKey: "sk_live_your_key",
24
+ jwtSecret: process.env.JWT_SECRET, // optional: enables JWT verification
25
+ jwtClaimPath: "tenant_id",
26
+ }),
27
+ ],
28
+ })
29
+ export class AppModule {}
30
+ ```
31
+
32
+ The module is `@Global()`, so import it once. Then use the guard and decorator in your controllers:
33
+
34
+ ```typescript
35
+ import { Controller, Get, UseGuards } from "@nestjs/common";
36
+ import { StratumGuard, Tenant } from "@stratum-hq/nestjs";
37
+
38
+ @Controller("data")
39
+ @UseGuards(StratumGuard)
40
+ export class DataController {
41
+ @Get()
42
+ getData(@Tenant() tenant) {
43
+ return { tenantId: tenant.tenant_id, config: tenant.resolved_config };
44
+ }
45
+ }
46
+ ```
47
+
48
+ ## API
49
+
50
+ - **`StratumModule.forRoot(options)` / `forRootAsync(options)`** — register the SDK client for DI. `forRootAsync` supports `useFactory` + `inject` for config that depends on other providers (e.g. `ConfigService`).
51
+ - **`StratumGuard`** — resolves the tenant from the `X-Tenant-ID` header, a verified JWT claim, or custom `resolvers` (in that order). Sets `req.tenant` (full `TenantContext`), plus `req.impersonating` / `req.originalTenantId` when impersonation is enabled. Throws `UnauthorizedException` (401) if no tenant is found.
52
+ - **`@Tenant()`** — parameter decorator that extracts `req.tenant`.
53
+ - **`StratumContextInterceptor`** — binds the resolved context to AsyncLocalStorage so services can call `getTenantContext()` from `@stratum-hq/sdk` without the request object.
54
+
55
+ Optional `impersonation` and `resolvers` options let you support admin impersonation (`X-Impersonate-Tenant`) and subdomain-based resolution.
56
+
57
+ ## Links
58
+
59
+ - Documentation: https://docs.stratum-hq.org/packages/nestjs/
60
+ - GitHub: https://github.com/stratum-hq/Stratum
61
+
62
+ ## License
63
+
64
+ MIT © Christian Crank
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stratum-hq/nestjs",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Stratum NestJS integration — StratumGuard, @Tenant() decorator, and StratumModule",
5
5
  "keywords": [
6
6
  "multi-tenancy",
@@ -42,8 +42,8 @@
42
42
  "peerDependencies": {
43
43
  "@nestjs/common": ">=10.0.0",
44
44
  "@nestjs/core": ">=10.0.0",
45
- "@stratum-hq/core": ">=0.2.0",
46
- "@stratum-hq/sdk": ">=0.2.0",
45
+ "@stratum-hq/core": ">=0.3.0",
46
+ "@stratum-hq/sdk": ">=0.3.0",
47
47
  "reflect-metadata": ">=0.1.13"
48
48
  },
49
49
  "devDependencies": {
@@ -55,5 +55,10 @@
55
55
  "reflect-metadata": "^0.1.13",
56
56
  "typescript": "^5.4.0",
57
57
  "vitest": "^1.6.0"
58
+ },
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "https://github.com/stratum-hq/Stratum.git",
62
+ "directory": "packages/nestjs"
58
63
  }
59
64
  }