@stratum-hq/nestjs 1.3.1 → 1.3.2

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/README.md CHANGED
@@ -42,13 +42,14 @@ The module is `@Global()`, so import it once. Then use the guard and decorator i
42
42
 
43
43
  ```typescript
44
44
  import { Controller, Get, UseGuards } from "@nestjs/common";
45
+ import type { ResolvedTenantContext } from "@stratum-hq/core";
45
46
  import { StratumGuard, Tenant } from "@stratum-hq/nestjs";
46
47
 
47
48
  @Controller("data")
48
49
  @UseGuards(StratumGuard)
49
50
  export class DataController {
50
51
  @Get()
51
- getData(@Tenant() tenant) {
52
+ getData(@Tenant() tenant: ResolvedTenantContext) {
52
53
  return { tenantId: tenant.tenant_id, config: tenant.resolved_config };
53
54
  }
54
55
  }
@@ -57,7 +58,7 @@ export class DataController {
57
58
  ## API
58
59
 
59
60
  - **`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`).
60
- - **`StratumGuard`**: resolves the tenant from a verified JWT claim, then the `X-Tenant-ID` header, then custom `resolvers`. When `jwtSecret` or `jwtVerify` is set, the guard reads the header only with `trustTenantHeader: true`, and it rejects a Bearer token that fails verification with 401. Set `jwtAudience` / `jwtIssuer` to also reject tokens whose `aud` / `iss` claim does not match. Sets `req.tenant` (full `TenantContext`), plus `req.impersonating` / `req.originalTenantId` when impersonation is enabled. Throws `UnauthorizedException` (401) if the request has no tenant ID, `NotFoundException` (404) if the tenant does not exist, `ForbiddenException` (403) if the tenant is suspended or access is denied, and `GoneException` (410) if the tenant is archived. A control plane timeout throws `GatewayTimeoutException` (504). A rejected SDK API key throws `InternalServerErrorException` (500) and writes the cause to `console.error`.
61
+ - **`StratumGuard`**: resolves the tenant from a verified JWT claim, then the `X-Tenant-ID` header, then custom `resolvers`. When `jwtSecret` or `jwtVerify` is set, the guard reads the header only with `trustTenantHeader: true`, and it rejects a Bearer token that fails verification with 401. Set `jwtAudience` / `jwtIssuer` to also reject tokens whose `aud` / `iss` claim does not match. Sets `req.tenant` (the `ResolvedTenantContext`), plus `req.impersonating` / `req.originalTenantId` when impersonation is enabled. Throws `UnauthorizedException` (401) if the request has no tenant ID, `NotFoundException` (404) if the tenant does not exist, `ForbiddenException` (403) if the tenant is suspended or access is denied, and `GoneException` (410) if the tenant is archived. A control plane timeout throws `GatewayTimeoutException` (504). A rejected SDK API key throws `InternalServerErrorException` (500) and writes the cause to `console.error`.
61
62
  - **`@Tenant()`**: parameter decorator that extracts `req.tenant`.
62
63
  - **`StratumContextInterceptor`**: binds the resolved context to AsyncLocalStorage so services can call `getTenantContext()` from `@stratum-hq/sdk` without the request object.
63
64
 
@@ -30,7 +30,7 @@ let StratumModule = StratumModule_1 = class StratumModule {
30
30
  return {
31
31
  module: StratumModule_1,
32
32
  providers: [clientProvider, optionsProvider, StratumGuard, { provide: APP_INTERCEPTOR, useClass: StratumContextInterceptor }],
33
- exports: [STRATUM_CLIENT, StratumGuard],
33
+ exports: [STRATUM_CLIENT, STRATUM_OPTIONS, StratumGuard],
34
34
  };
35
35
  }
36
36
  /**
@@ -58,7 +58,7 @@ let StratumModule = StratumModule_1 = class StratumModule {
58
58
  module: StratumModule_1,
59
59
  imports: asyncOptions.imports ?? [],
60
60
  providers: [optionsProvider, clientProvider, StratumGuard, { provide: APP_INTERCEPTOR, useClass: StratumContextInterceptor }],
61
- exports: [STRATUM_CLIENT, StratumGuard],
61
+ exports: [STRATUM_CLIENT, STRATUM_OPTIONS, StratumGuard],
62
62
  };
63
63
  }
64
64
  };
@@ -1 +1 @@
1
- {"version":3,"file":"stratum.module.js","sourceRoot":"","sources":["../src/stratum.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,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AAa,CAuDzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stratum-hq/nestjs",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "NestJS multi-tenancy: tenant guard, @Tenant() decorator, and module for Stratum",
5
5
  "keywords": [
6
6
  "multi-tenancy",
@@ -52,6 +52,7 @@
52
52
  "devDependencies": {
53
53
  "@nestjs/common": "^12.1.2",
54
54
  "@nestjs/core": "^12.1.2",
55
+ "@nestjs/platform-express": "^12.1.2",
55
56
  "@nestjs/testing": "^12.1.2",
56
57
  "@stratum-hq/core": "*",
57
58
  "@stratum-hq/sdk": "*",