@nathapp/nestjs-tenant 0.0.0-stage → 1.0.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 (128) hide show
  1. package/AGENTS.md +142 -0
  2. package/CLAUDE.md +140 -0
  3. package/GEMINI.md +140 -0
  4. package/codex.md +140 -0
  5. package/dist/cache/cache-manager-tenant-cache.d.ts +9 -0
  6. package/dist/cache/cache-manager-tenant-cache.js +17 -0
  7. package/dist/cache/cache-manager-tenant-cache.js.map +1 -0
  8. package/dist/cache/in-memory-tenant-cache.d.ts +13 -0
  9. package/dist/cache/in-memory-tenant-cache.js +61 -0
  10. package/dist/cache/in-memory-tenant-cache.js.map +1 -0
  11. package/dist/cache/index.d.ts +2 -0
  12. package/dist/cache/index.js +19 -0
  13. package/dist/cache/index.js.map +1 -0
  14. package/dist/constant/index.d.ts +1 -0
  15. package/dist/constant/index.js +18 -0
  16. package/dist/constant/index.js.map +1 -0
  17. package/dist/constant/tokens.d.ts +7 -0
  18. package/dist/constant/tokens.js +11 -0
  19. package/dist/constant/tokens.js.map +1 -0
  20. package/dist/decorator/current-tenant.decorator.d.ts +1 -0
  21. package/dist/decorator/current-tenant.decorator.js +12 -0
  22. package/dist/decorator/current-tenant.decorator.js.map +1 -0
  23. package/dist/decorator/index.d.ts +3 -0
  24. package/dist/decorator/index.js +20 -0
  25. package/dist/decorator/index.js.map +1 -0
  26. package/dist/decorator/skip-tenant.decorator.d.ts +2 -0
  27. package/dist/decorator/skip-tenant.decorator.js +8 -0
  28. package/dist/decorator/skip-tenant.decorator.js.map +1 -0
  29. package/dist/decorator/tenant-id.decorator.d.ts +1 -0
  30. package/dist/decorator/tenant-id.decorator.js +16 -0
  31. package/dist/decorator/tenant-id.decorator.js.map +1 -0
  32. package/dist/exception/index.d.ts +2 -0
  33. package/dist/exception/index.js +19 -0
  34. package/dist/exception/index.js.map +1 -0
  35. package/dist/exception/tenant-exception-code.d.ts +15 -0
  36. package/dist/exception/tenant-exception-code.js +36 -0
  37. package/dist/exception/tenant-exception-code.js.map +1 -0
  38. package/dist/exception/tenant.exception.d.ts +6 -0
  39. package/dist/exception/tenant.exception.js +32 -0
  40. package/dist/exception/tenant.exception.js.map +1 -0
  41. package/dist/guard/index.d.ts +1 -0
  42. package/dist/guard/index.js +18 -0
  43. package/dist/guard/index.js.map +1 -0
  44. package/dist/guard/tenant.guard.d.ts +29 -0
  45. package/dist/guard/tenant.guard.js +236 -0
  46. package/dist/guard/tenant.guard.js.map +1 -0
  47. package/dist/i18n/index.d.ts +1 -0
  48. package/dist/i18n/index.js +18 -0
  49. package/dist/i18n/index.js.map +1 -0
  50. package/dist/i18n/merge-platform-locales.d.ts +8 -0
  51. package/dist/i18n/merge-platform-locales.js +100 -0
  52. package/dist/i18n/merge-platform-locales.js.map +1 -0
  53. package/dist/index.d.ts +11 -0
  54. package/dist/index.js +28 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/interface/index.d.ts +9 -0
  57. package/dist/interface/index.js +26 -0
  58. package/dist/interface/index.js.map +1 -0
  59. package/dist/interface/multi-tenant-principal.interface.d.ts +12 -0
  60. package/dist/interface/multi-tenant-principal.interface.js +3 -0
  61. package/dist/interface/multi-tenant-principal.interface.js.map +1 -0
  62. package/dist/interface/tenant-cache.interface.d.ts +5 -0
  63. package/dist/interface/tenant-cache.interface.js +3 -0
  64. package/dist/interface/tenant-cache.interface.js.map +1 -0
  65. package/dist/interface/tenant-context.interface.d.ts +9 -0
  66. package/dist/interface/tenant-context.interface.js +3 -0
  67. package/dist/interface/tenant-context.interface.js.map +1 -0
  68. package/dist/interface/tenant-module-options.interface.d.ts +62 -0
  69. package/dist/interface/tenant-module-options.interface.js +3 -0
  70. package/dist/interface/tenant-module-options.interface.js.map +1 -0
  71. package/dist/interface/tenant-principal-binder.interface.d.ts +6 -0
  72. package/dist/interface/tenant-principal-binder.interface.js +3 -0
  73. package/dist/interface/tenant-principal-binder.interface.js.map +1 -0
  74. package/dist/interface/tenant-repository.interface.d.ts +7 -0
  75. package/dist/interface/tenant-repository.interface.js +3 -0
  76. package/dist/interface/tenant-repository.interface.js.map +1 -0
  77. package/dist/interface/tenant-resolver.interface.d.ts +19 -0
  78. package/dist/interface/tenant-resolver.interface.js +13 -0
  79. package/dist/interface/tenant-resolver.interface.js.map +1 -0
  80. package/dist/interface/tenant-service.interface.d.ts +12 -0
  81. package/dist/interface/tenant-service.interface.js +3 -0
  82. package/dist/interface/tenant-service.interface.js.map +1 -0
  83. package/dist/interface/tenant.interface.d.ts +28 -0
  84. package/dist/interface/tenant.interface.js +10 -0
  85. package/dist/interface/tenant.interface.js.map +1 -0
  86. package/dist/middleware/index.d.ts +1 -0
  87. package/dist/middleware/index.js +18 -0
  88. package/dist/middleware/index.js.map +1 -0
  89. package/dist/middleware/tenant-context.middleware.d.ts +7 -0
  90. package/dist/middleware/tenant-context.middleware.js +28 -0
  91. package/dist/middleware/tenant-context.middleware.js.map +1 -0
  92. package/dist/module/index.d.ts +1 -0
  93. package/dist/module/index.js +18 -0
  94. package/dist/module/index.js.map +1 -0
  95. package/dist/module/tenant.module.d.ts +14 -0
  96. package/dist/module/tenant.module.js +214 -0
  97. package/dist/module/tenant.module.js.map +1 -0
  98. package/dist/resolver/dto-field-tenant.resolver.d.ts +6 -0
  99. package/dist/resolver/dto-field-tenant.resolver.js +36 -0
  100. package/dist/resolver/dto-field-tenant.resolver.js.map +1 -0
  101. package/dist/resolver/header-tenant.resolver.d.ts +11 -0
  102. package/dist/resolver/header-tenant.resolver.js +44 -0
  103. package/dist/resolver/header-tenant.resolver.js.map +1 -0
  104. package/dist/resolver/index.d.ts +5 -0
  105. package/dist/resolver/index.js +22 -0
  106. package/dist/resolver/index.js.map +1 -0
  107. package/dist/resolver/jwt-claim-tenant.resolver.d.ts +10 -0
  108. package/dist/resolver/jwt-claim-tenant.resolver.js +74 -0
  109. package/dist/resolver/jwt-claim-tenant.resolver.js.map +1 -0
  110. package/dist/resolver/path-tenant.resolver.d.ts +6 -0
  111. package/dist/resolver/path-tenant.resolver.js +38 -0
  112. package/dist/resolver/path-tenant.resolver.js.map +1 -0
  113. package/dist/resolver/subdomain-tenant.resolver.d.ts +9 -0
  114. package/dist/resolver/subdomain-tenant.resolver.js +48 -0
  115. package/dist/resolver/subdomain-tenant.resolver.js.map +1 -0
  116. package/dist/service/default-tenant.service.d.ts +22 -0
  117. package/dist/service/default-tenant.service.js +116 -0
  118. package/dist/service/default-tenant.service.js.map +1 -0
  119. package/dist/service/index.d.ts +2 -0
  120. package/dist/service/index.js +19 -0
  121. package/dist/service/index.js.map +1 -0
  122. package/dist/service/tenant-context.service.d.ts +12 -0
  123. package/dist/service/tenant-context.service.js +61 -0
  124. package/dist/service/tenant-context.service.js.map +1 -0
  125. package/i18n/en/tenant.json +15 -0
  126. package/i18n/zh/tenant.json +15 -0
  127. package/package.json +44 -4
  128. package/README.md +0 -3
package/AGENTS.md ADDED
@@ -0,0 +1,142 @@
1
+ # Agent Instructions
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ These instructions apply to all AI coding agents in this project.
7
+
8
+ ---
9
+
10
+ ## Project Metadata
11
+
12
+ > Auto-injected by `nax generate`
13
+
14
+ **Project:** `@nathapp/nestjs-tenant`
15
+
16
+ **Language:** TypeScript
17
+
18
+ **Key dependencies:** typescript
19
+
20
+ **Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check`
21
+
22
+ ---
23
+ # CLAUDE.md — @nathapp/nestjs-tenant
24
+
25
+ Multi-tenant context management for NestJS. Column-based tenancy with automatic request-scoped context.
26
+
27
+ ## Status: ✅ Complete
28
+
29
+ ## Key Files
30
+
31
+ - `lib/interface/` — `ITenant`, `ITenantRepository`, `ITenantService`, `ITenantResolver`, `ITenantContext`, `IMultiTenantPrincipal`, `ITenantPrincipalBinder`
32
+ - `lib/service/default-tenant.service.ts` — Default tenant CRUD with single-tenant mode support
33
+ - `lib/service/tenant-context.service.ts` — AsyncLocalStorage-based request-scoped tenant context
34
+ - `lib/resolver/` — 5 resolvers: `HeaderTenantResolver`, `JwtClaimTenantResolver`, `SubdomainTenantResolver`, `PathTenantResolver`, `DtoFieldTenantResolver`
35
+ - `lib/guard/tenant.guard.ts` — `TenantGuard` resolves + validates tenant per request, sets context
36
+ - `lib/decorator/` — `@CurrentTenant()`, `@SkipTenant()`, `@TenantId()` (DTO param)
37
+ - `lib/module/tenant.module.ts` — `TenantModule.register()` / `registerAsync()`
38
+ - `lib/constant/tokens.ts` — DI tokens: `TENANT_REPOSITORY`, `TENANT_SERVICE`, `TENANT_RESOLVER`, `TENANT_CONTEXT`, `TENANT_MODULE_OPTIONS`, `TENANT_CACHE`, `TENANT_PRINCIPAL_BINDER`
39
+
40
+ ## DI Tokens
41
+
42
+ | Token | Interface | Default |
43
+ |:---|:---|:---|
44
+ | `TENANT_REPOSITORY` | `ITenantRepository` | None (consumer must provide) |
45
+ | `TENANT_SERVICE` | `ITenantService` | `DefaultTenantService` |
46
+ | `TENANT_RESOLVER` | `ITenantResolver` | Configured via module options |
47
+ | `TENANT_CONTEXT` | `ITenantContext` | `TenantContextService` |
48
+ | `TENANT_CACHE` | `ITenantCache` | `InMemoryTenantCache` |
49
+ | `TENANT_PRINCIPAL_BINDER` | `ITenantPrincipalBinder` | None (consumer must provide) |
50
+
51
+ ## Module Registration
52
+
53
+ ```typescript
54
+ TenantModule.register({
55
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
56
+ resolution: { strategy: TenantResolutionStrategy.HEADER, headerName: 'x-tenant-id' },
57
+ // Single-tenant mode (optional, off by default — set enabled: true to arm it).
58
+ // Armed, TenantGuard falls back to defaultTenantId when the configured resolver
59
+ // finds no tenant identifier on the request. headerName is only read by the
60
+ // HEADER strategy; JWT_CLAIM reads claimKey, SUBDOMAIN reads the host, PATH reads
61
+ // pathPrefix, DTO_FIELD reads dtoField, and CUSTOM takes a resolver class.
62
+ //
63
+ // defaultTenantId MUST be a real, existing tenant id. It is not validated at
64
+ // registration: a falsy value is returned like any other resolution result and
65
+ // fails the guard's `if (!resolved)` check, so outside a guard.skipPaths match
66
+ // it rejects with the normal 400 (RESOLUTION_FAILED) — 403 under
67
+ // onTenantMissing: 'forbidden' — while a skip path is allowed unbound instead.
68
+ // The fallback is only "fail-open" when the id is real. Header/subdomain
69
+ // resolution still wins when present, so multi-tenant behaviour is unaffected.
70
+ // Enable only for genuinely single-tenant deployments.
71
+ singleTenant: { enabled: false, defaultTenantId: 'tenant-1' },
72
+ })
73
+ ```
74
+
75
+ ## Supported Wiring
76
+
77
+ Supported production order — `TenantGuard` reads the principal off `request.user`, so register the real guards explicitly in authentication → tenant → authorization order:
78
+
79
+ ```
80
+ JwtAuthGuard (@nathapp/nestjs-auth)
81
+ → TenantGuard (configured resolver + optional principal binding)
82
+ → PermissionAuthGuard (@nathapp/nestjs-auth) + AccountCaslAbilityFactory (@nathapp/nestjs-account)
83
+ ```
84
+
85
+ The resolver strategy controls where the request's tenant ID comes from; principal binding then checks membership in that resolved tenant. These are separate decisions:
86
+
87
+ - `HEADER` resolves `x-tenant-id` (or the configured header name). `require-match` rejects an authenticated principal that is not a member of that header-selected tenant.
88
+ - `JWT_CLAIM` resolves a claim on the authenticated principal: first `user.tenantId`, then `user.extra.tenantId` for claims nested by the core auth provider. It does not read the tenant header.
89
+
90
+ The real guard order, Fastify request path, and tenant AsyncLocalStorage are exercised by `packages/integration-e2e/test/tenant-principal-isolation.spec.ts` for both strategies.
91
+
92
+ ### `guard.principalBinding`
93
+
94
+ | Mode | Behaviour |
95
+ |:---|:---|
96
+ | `off` (default) | No check; the binder is never called |
97
+ | `require-match` | 403 (`TENANT_PRINCIPAL_MISMATCH`) when the principal is not a member of the resolved tenant |
98
+ | `assert` | Dry run — warns on mismatch (and on binder error) and continues; never rejects |
99
+
100
+ There is deliberately **no default binder**. `TenantGuard` injects `TENANT_PRINCIPAL_BINDER` with `@Optional()`, so `require-match` without one would 403 every authenticated request — `TenantModule.register()` / `registerAsync()` throw instead. Supply one:
101
+
102
+ ```typescript
103
+ TenantModule.register({
104
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
105
+ resolution: { strategy: TenantResolutionStrategy.JWT_CLAIM },
106
+ principalBinder: MyTenantPrincipalBinder, // registered as TENANT_PRINCIPAL_BINDER (recommended)
107
+ guard: { principalBinding: { mode: 'require-match' } },
108
+ })
109
+ ```
110
+
111
+ A binder reaching the token from another module needs `guard.principalBinding.binderProvided: true` — the module cannot verify it, and under `register()` (no `imports`) the providing module must be `@Global()` **and export** the token; merely providing it stays invisible. Prefer `principalBinder`: it is the only route the module can resolve for you, and the only such route under `register()`. Under `registerAsync` set `principalBinder` on `TenantModuleAsyncOptions`, not on the options the factory returns.
112
+
113
+ `ITenantPrincipalBinder` is declared here, deliberately not a re-export of `nestjs-iam`'s `ITenantMembershipResolver` — `nestjs-tenant` is the dependency floor and cannot depend on `nestjs-iam`, so the consumer supplies a bridging binder. Implement it as:
114
+
115
+ ```typescript
116
+ interface ITenantPrincipalBinder {
117
+ assertMembership(principal: { id?: string }, tenantId: string): Promise<boolean>;
118
+ }
119
+ ```
120
+
121
+ `principal` is typed `{ id?: string }` and not a broader record: a binder normally bridges `nestjs-iam`'s `IPrincipal`, and an index signature here would reject that (TypeScript grants implicit index signatures to object literal types, not to interfaces). The binder reads `principal.id`; look up anything else off the concrete principal type inside your own implementation.
122
+
123
+ The check runs after `setTenant` and is never cached, so a revoked membership takes effect immediately rather than after `validation.cacheTtl`. It is skipped when the request carries no principal, and skipped for `@SkipTenant()` handlers. Note the asymmetry on `guard.skipPaths`: a matching path is **not** an unbound request — resolution and lookup still run and a found tenant **is** still set on the context and `request.__tenant`; only this assertion is skipped.
124
+
125
+ ### JWT tenant claim
126
+
127
+ `JwtClaimTenantResolver` reads `user[claimKey]` (default `'tenantId'`), then `user.extra[claimKey]`; a dotted `claimKey` such as `'extra.tenantId'` is walked against `user` instead. A function may be passed in place of the key (selector mode). `extra` is where core `SimpleAuthProvider` puts arbitrary claims — it maps a payload to `{ id, username, name, authorities, extra }`, so a top-level-only read resolved nothing for a core-issued JWT. A non-primitive claim resolves to `null`, not `"[object Object]"`.
128
+
129
+ The cross-tenant HTTP acceptance coverage lives in `packages/integration-e2e/test/tenant-principal-isolation.spec.ts`; the OAuth flow tests separately keep their existing `TenantContextService.run()` coverage.
130
+
131
+ ## Testing
132
+
133
+ ```bash
134
+ npm test # run tests
135
+ npm run test:cov # with coverage
136
+ ```
137
+
138
+ ## Gotchas
139
+
140
+ - `TenantContextService` uses `AsyncLocalStorage` — context is lost if you break the async chain (e.g., `setTimeout` without `AsyncResource`)
141
+ - `@SkipTenant()` on a handler skips `TenantGuard` resolution entirely
142
+ - `IMultiTenantPrincipal` extends `IPrincipal` from `@nathapp/nestjs-auth` — adds `tenantId` and `roles`
package/CLAUDE.md ADDED
@@ -0,0 +1,140 @@
1
+ # Project Context
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ ---
7
+
8
+ ## Project Metadata
9
+
10
+ > Auto-injected by `nax generate`
11
+
12
+ **Project:** `@nathapp/nestjs-tenant`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** typescript
17
+
18
+ **Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check`
19
+
20
+ ---
21
+ # CLAUDE.md — @nathapp/nestjs-tenant
22
+
23
+ Multi-tenant context management for NestJS. Column-based tenancy with automatic request-scoped context.
24
+
25
+ ## Status: ✅ Complete
26
+
27
+ ## Key Files
28
+
29
+ - `lib/interface/` — `ITenant`, `ITenantRepository`, `ITenantService`, `ITenantResolver`, `ITenantContext`, `IMultiTenantPrincipal`, `ITenantPrincipalBinder`
30
+ - `lib/service/default-tenant.service.ts` — Default tenant CRUD with single-tenant mode support
31
+ - `lib/service/tenant-context.service.ts` — AsyncLocalStorage-based request-scoped tenant context
32
+ - `lib/resolver/` — 5 resolvers: `HeaderTenantResolver`, `JwtClaimTenantResolver`, `SubdomainTenantResolver`, `PathTenantResolver`, `DtoFieldTenantResolver`
33
+ - `lib/guard/tenant.guard.ts` — `TenantGuard` resolves + validates tenant per request, sets context
34
+ - `lib/decorator/` — `@CurrentTenant()`, `@SkipTenant()`, `@TenantId()` (DTO param)
35
+ - `lib/module/tenant.module.ts` — `TenantModule.register()` / `registerAsync()`
36
+ - `lib/constant/tokens.ts` — DI tokens: `TENANT_REPOSITORY`, `TENANT_SERVICE`, `TENANT_RESOLVER`, `TENANT_CONTEXT`, `TENANT_MODULE_OPTIONS`, `TENANT_CACHE`, `TENANT_PRINCIPAL_BINDER`
37
+
38
+ ## DI Tokens
39
+
40
+ | Token | Interface | Default |
41
+ |:---|:---|:---|
42
+ | `TENANT_REPOSITORY` | `ITenantRepository` | None (consumer must provide) |
43
+ | `TENANT_SERVICE` | `ITenantService` | `DefaultTenantService` |
44
+ | `TENANT_RESOLVER` | `ITenantResolver` | Configured via module options |
45
+ | `TENANT_CONTEXT` | `ITenantContext` | `TenantContextService` |
46
+ | `TENANT_CACHE` | `ITenantCache` | `InMemoryTenantCache` |
47
+ | `TENANT_PRINCIPAL_BINDER` | `ITenantPrincipalBinder` | None (consumer must provide) |
48
+
49
+ ## Module Registration
50
+
51
+ ```typescript
52
+ TenantModule.register({
53
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
54
+ resolution: { strategy: TenantResolutionStrategy.HEADER, headerName: 'x-tenant-id' },
55
+ // Single-tenant mode (optional, off by default — set enabled: true to arm it).
56
+ // Armed, TenantGuard falls back to defaultTenantId when the configured resolver
57
+ // finds no tenant identifier on the request. headerName is only read by the
58
+ // HEADER strategy; JWT_CLAIM reads claimKey, SUBDOMAIN reads the host, PATH reads
59
+ // pathPrefix, DTO_FIELD reads dtoField, and CUSTOM takes a resolver class.
60
+ //
61
+ // defaultTenantId MUST be a real, existing tenant id. It is not validated at
62
+ // registration: a falsy value is returned like any other resolution result and
63
+ // fails the guard's `if (!resolved)` check, so outside a guard.skipPaths match
64
+ // it rejects with the normal 400 (RESOLUTION_FAILED) — 403 under
65
+ // onTenantMissing: 'forbidden' — while a skip path is allowed unbound instead.
66
+ // The fallback is only "fail-open" when the id is real. Header/subdomain
67
+ // resolution still wins when present, so multi-tenant behaviour is unaffected.
68
+ // Enable only for genuinely single-tenant deployments.
69
+ singleTenant: { enabled: false, defaultTenantId: 'tenant-1' },
70
+ })
71
+ ```
72
+
73
+ ## Supported Wiring
74
+
75
+ Supported production order — `TenantGuard` reads the principal off `request.user`, so register the real guards explicitly in authentication → tenant → authorization order:
76
+
77
+ ```
78
+ JwtAuthGuard (@nathapp/nestjs-auth)
79
+ → TenantGuard (configured resolver + optional principal binding)
80
+ → PermissionAuthGuard (@nathapp/nestjs-auth) + AccountCaslAbilityFactory (@nathapp/nestjs-account)
81
+ ```
82
+
83
+ The resolver strategy controls where the request's tenant ID comes from; principal binding then checks membership in that resolved tenant. These are separate decisions:
84
+
85
+ - `HEADER` resolves `x-tenant-id` (or the configured header name). `require-match` rejects an authenticated principal that is not a member of that header-selected tenant.
86
+ - `JWT_CLAIM` resolves a claim on the authenticated principal: first `user.tenantId`, then `user.extra.tenantId` for claims nested by the core auth provider. It does not read the tenant header.
87
+
88
+ The real guard order, Fastify request path, and tenant AsyncLocalStorage are exercised by `packages/integration-e2e/test/tenant-principal-isolation.spec.ts` for both strategies.
89
+
90
+ ### `guard.principalBinding`
91
+
92
+ | Mode | Behaviour |
93
+ |:---|:---|
94
+ | `off` (default) | No check; the binder is never called |
95
+ | `require-match` | 403 (`TENANT_PRINCIPAL_MISMATCH`) when the principal is not a member of the resolved tenant |
96
+ | `assert` | Dry run — warns on mismatch (and on binder error) and continues; never rejects |
97
+
98
+ There is deliberately **no default binder**. `TenantGuard` injects `TENANT_PRINCIPAL_BINDER` with `@Optional()`, so `require-match` without one would 403 every authenticated request — `TenantModule.register()` / `registerAsync()` throw instead. Supply one:
99
+
100
+ ```typescript
101
+ TenantModule.register({
102
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
103
+ resolution: { strategy: TenantResolutionStrategy.JWT_CLAIM },
104
+ principalBinder: MyTenantPrincipalBinder, // registered as TENANT_PRINCIPAL_BINDER (recommended)
105
+ guard: { principalBinding: { mode: 'require-match' } },
106
+ })
107
+ ```
108
+
109
+ A binder reaching the token from another module needs `guard.principalBinding.binderProvided: true` — the module cannot verify it, and under `register()` (no `imports`) the providing module must be `@Global()` **and export** the token; merely providing it stays invisible. Prefer `principalBinder`: it is the only route the module can resolve for you, and the only such route under `register()`. Under `registerAsync` set `principalBinder` on `TenantModuleAsyncOptions`, not on the options the factory returns.
110
+
111
+ `ITenantPrincipalBinder` is declared here, deliberately not a re-export of `nestjs-iam`'s `ITenantMembershipResolver` — `nestjs-tenant` is the dependency floor and cannot depend on `nestjs-iam`, so the consumer supplies a bridging binder. Implement it as:
112
+
113
+ ```typescript
114
+ interface ITenantPrincipalBinder {
115
+ assertMembership(principal: { id?: string }, tenantId: string): Promise<boolean>;
116
+ }
117
+ ```
118
+
119
+ `principal` is typed `{ id?: string }` and not a broader record: a binder normally bridges `nestjs-iam`'s `IPrincipal`, and an index signature here would reject that (TypeScript grants implicit index signatures to object literal types, not to interfaces). The binder reads `principal.id`; look up anything else off the concrete principal type inside your own implementation.
120
+
121
+ The check runs after `setTenant` and is never cached, so a revoked membership takes effect immediately rather than after `validation.cacheTtl`. It is skipped when the request carries no principal, and skipped for `@SkipTenant()` handlers. Note the asymmetry on `guard.skipPaths`: a matching path is **not** an unbound request — resolution and lookup still run and a found tenant **is** still set on the context and `request.__tenant`; only this assertion is skipped.
122
+
123
+ ### JWT tenant claim
124
+
125
+ `JwtClaimTenantResolver` reads `user[claimKey]` (default `'tenantId'`), then `user.extra[claimKey]`; a dotted `claimKey` such as `'extra.tenantId'` is walked against `user` instead. A function may be passed in place of the key (selector mode). `extra` is where core `SimpleAuthProvider` puts arbitrary claims — it maps a payload to `{ id, username, name, authorities, extra }`, so a top-level-only read resolved nothing for a core-issued JWT. A non-primitive claim resolves to `null`, not `"[object Object]"`.
126
+
127
+ The cross-tenant HTTP acceptance coverage lives in `packages/integration-e2e/test/tenant-principal-isolation.spec.ts`; the OAuth flow tests separately keep their existing `TenantContextService.run()` coverage.
128
+
129
+ ## Testing
130
+
131
+ ```bash
132
+ npm test # run tests
133
+ npm run test:cov # with coverage
134
+ ```
135
+
136
+ ## Gotchas
137
+
138
+ - `TenantContextService` uses `AsyncLocalStorage` — context is lost if you break the async chain (e.g., `setTimeout` without `AsyncResource`)
139
+ - `@SkipTenant()` on a handler skips `TenantGuard` resolution entirely
140
+ - `IMultiTenantPrincipal` extends `IPrincipal` from `@nathapp/nestjs-auth` — adds `tenantId` and `roles`
package/GEMINI.md ADDED
@@ -0,0 +1,140 @@
1
+ # Gemini CLI Context
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ ---
7
+
8
+ ## Project Metadata
9
+
10
+ > Auto-injected by `nax generate`
11
+
12
+ **Project:** `@nathapp/nestjs-tenant`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** typescript
17
+
18
+ **Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check`
19
+
20
+ ---
21
+ # CLAUDE.md — @nathapp/nestjs-tenant
22
+
23
+ Multi-tenant context management for NestJS. Column-based tenancy with automatic request-scoped context.
24
+
25
+ ## Status: ✅ Complete
26
+
27
+ ## Key Files
28
+
29
+ - `lib/interface/` — `ITenant`, `ITenantRepository`, `ITenantService`, `ITenantResolver`, `ITenantContext`, `IMultiTenantPrincipal`, `ITenantPrincipalBinder`
30
+ - `lib/service/default-tenant.service.ts` — Default tenant CRUD with single-tenant mode support
31
+ - `lib/service/tenant-context.service.ts` — AsyncLocalStorage-based request-scoped tenant context
32
+ - `lib/resolver/` — 5 resolvers: `HeaderTenantResolver`, `JwtClaimTenantResolver`, `SubdomainTenantResolver`, `PathTenantResolver`, `DtoFieldTenantResolver`
33
+ - `lib/guard/tenant.guard.ts` — `TenantGuard` resolves + validates tenant per request, sets context
34
+ - `lib/decorator/` — `@CurrentTenant()`, `@SkipTenant()`, `@TenantId()` (DTO param)
35
+ - `lib/module/tenant.module.ts` — `TenantModule.register()` / `registerAsync()`
36
+ - `lib/constant/tokens.ts` — DI tokens: `TENANT_REPOSITORY`, `TENANT_SERVICE`, `TENANT_RESOLVER`, `TENANT_CONTEXT`, `TENANT_MODULE_OPTIONS`, `TENANT_CACHE`, `TENANT_PRINCIPAL_BINDER`
37
+
38
+ ## DI Tokens
39
+
40
+ | Token | Interface | Default |
41
+ |:---|:---|:---|
42
+ | `TENANT_REPOSITORY` | `ITenantRepository` | None (consumer must provide) |
43
+ | `TENANT_SERVICE` | `ITenantService` | `DefaultTenantService` |
44
+ | `TENANT_RESOLVER` | `ITenantResolver` | Configured via module options |
45
+ | `TENANT_CONTEXT` | `ITenantContext` | `TenantContextService` |
46
+ | `TENANT_CACHE` | `ITenantCache` | `InMemoryTenantCache` |
47
+ | `TENANT_PRINCIPAL_BINDER` | `ITenantPrincipalBinder` | None (consumer must provide) |
48
+
49
+ ## Module Registration
50
+
51
+ ```typescript
52
+ TenantModule.register({
53
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
54
+ resolution: { strategy: TenantResolutionStrategy.HEADER, headerName: 'x-tenant-id' },
55
+ // Single-tenant mode (optional, off by default — set enabled: true to arm it).
56
+ // Armed, TenantGuard falls back to defaultTenantId when the configured resolver
57
+ // finds no tenant identifier on the request. headerName is only read by the
58
+ // HEADER strategy; JWT_CLAIM reads claimKey, SUBDOMAIN reads the host, PATH reads
59
+ // pathPrefix, DTO_FIELD reads dtoField, and CUSTOM takes a resolver class.
60
+ //
61
+ // defaultTenantId MUST be a real, existing tenant id. It is not validated at
62
+ // registration: a falsy value is returned like any other resolution result and
63
+ // fails the guard's `if (!resolved)` check, so outside a guard.skipPaths match
64
+ // it rejects with the normal 400 (RESOLUTION_FAILED) — 403 under
65
+ // onTenantMissing: 'forbidden' — while a skip path is allowed unbound instead.
66
+ // The fallback is only "fail-open" when the id is real. Header/subdomain
67
+ // resolution still wins when present, so multi-tenant behaviour is unaffected.
68
+ // Enable only for genuinely single-tenant deployments.
69
+ singleTenant: { enabled: false, defaultTenantId: 'tenant-1' },
70
+ })
71
+ ```
72
+
73
+ ## Supported Wiring
74
+
75
+ Supported production order — `TenantGuard` reads the principal off `request.user`, so register the real guards explicitly in authentication → tenant → authorization order:
76
+
77
+ ```
78
+ JwtAuthGuard (@nathapp/nestjs-auth)
79
+ → TenantGuard (configured resolver + optional principal binding)
80
+ → PermissionAuthGuard (@nathapp/nestjs-auth) + AccountCaslAbilityFactory (@nathapp/nestjs-account)
81
+ ```
82
+
83
+ The resolver strategy controls where the request's tenant ID comes from; principal binding then checks membership in that resolved tenant. These are separate decisions:
84
+
85
+ - `HEADER` resolves `x-tenant-id` (or the configured header name). `require-match` rejects an authenticated principal that is not a member of that header-selected tenant.
86
+ - `JWT_CLAIM` resolves a claim on the authenticated principal: first `user.tenantId`, then `user.extra.tenantId` for claims nested by the core auth provider. It does not read the tenant header.
87
+
88
+ The real guard order, Fastify request path, and tenant AsyncLocalStorage are exercised by `packages/integration-e2e/test/tenant-principal-isolation.spec.ts` for both strategies.
89
+
90
+ ### `guard.principalBinding`
91
+
92
+ | Mode | Behaviour |
93
+ |:---|:---|
94
+ | `off` (default) | No check; the binder is never called |
95
+ | `require-match` | 403 (`TENANT_PRINCIPAL_MISMATCH`) when the principal is not a member of the resolved tenant |
96
+ | `assert` | Dry run — warns on mismatch (and on binder error) and continues; never rejects |
97
+
98
+ There is deliberately **no default binder**. `TenantGuard` injects `TENANT_PRINCIPAL_BINDER` with `@Optional()`, so `require-match` without one would 403 every authenticated request — `TenantModule.register()` / `registerAsync()` throw instead. Supply one:
99
+
100
+ ```typescript
101
+ TenantModule.register({
102
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
103
+ resolution: { strategy: TenantResolutionStrategy.JWT_CLAIM },
104
+ principalBinder: MyTenantPrincipalBinder, // registered as TENANT_PRINCIPAL_BINDER (recommended)
105
+ guard: { principalBinding: { mode: 'require-match' } },
106
+ })
107
+ ```
108
+
109
+ A binder reaching the token from another module needs `guard.principalBinding.binderProvided: true` — the module cannot verify it, and under `register()` (no `imports`) the providing module must be `@Global()` **and export** the token; merely providing it stays invisible. Prefer `principalBinder`: it is the only route the module can resolve for you, and the only such route under `register()`. Under `registerAsync` set `principalBinder` on `TenantModuleAsyncOptions`, not on the options the factory returns.
110
+
111
+ `ITenantPrincipalBinder` is declared here, deliberately not a re-export of `nestjs-iam`'s `ITenantMembershipResolver` — `nestjs-tenant` is the dependency floor and cannot depend on `nestjs-iam`, so the consumer supplies a bridging binder. Implement it as:
112
+
113
+ ```typescript
114
+ interface ITenantPrincipalBinder {
115
+ assertMembership(principal: { id?: string }, tenantId: string): Promise<boolean>;
116
+ }
117
+ ```
118
+
119
+ `principal` is typed `{ id?: string }` and not a broader record: a binder normally bridges `nestjs-iam`'s `IPrincipal`, and an index signature here would reject that (TypeScript grants implicit index signatures to object literal types, not to interfaces). The binder reads `principal.id`; look up anything else off the concrete principal type inside your own implementation.
120
+
121
+ The check runs after `setTenant` and is never cached, so a revoked membership takes effect immediately rather than after `validation.cacheTtl`. It is skipped when the request carries no principal, and skipped for `@SkipTenant()` handlers. Note the asymmetry on `guard.skipPaths`: a matching path is **not** an unbound request — resolution and lookup still run and a found tenant **is** still set on the context and `request.__tenant`; only this assertion is skipped.
122
+
123
+ ### JWT tenant claim
124
+
125
+ `JwtClaimTenantResolver` reads `user[claimKey]` (default `'tenantId'`), then `user.extra[claimKey]`; a dotted `claimKey` such as `'extra.tenantId'` is walked against `user` instead. A function may be passed in place of the key (selector mode). `extra` is where core `SimpleAuthProvider` puts arbitrary claims — it maps a payload to `{ id, username, name, authorities, extra }`, so a top-level-only read resolved nothing for a core-issued JWT. A non-primitive claim resolves to `null`, not `"[object Object]"`.
126
+
127
+ The cross-tenant HTTP acceptance coverage lives in `packages/integration-e2e/test/tenant-principal-isolation.spec.ts`; the OAuth flow tests separately keep their existing `TenantContextService.run()` coverage.
128
+
129
+ ## Testing
130
+
131
+ ```bash
132
+ npm test # run tests
133
+ npm run test:cov # with coverage
134
+ ```
135
+
136
+ ## Gotchas
137
+
138
+ - `TenantContextService` uses `AsyncLocalStorage` — context is lost if you break the async chain (e.g., `setTimeout` without `AsyncResource`)
139
+ - `@SkipTenant()` on a handler skips `TenantGuard` resolution entirely
140
+ - `IMultiTenantPrincipal` extends `IPrincipal` from `@nathapp/nestjs-auth` — adds `tenantId` and `roles`
package/codex.md ADDED
@@ -0,0 +1,140 @@
1
+ # Codex Instructions
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ ---
7
+
8
+ ## Project Metadata
9
+
10
+ > Auto-injected by `nax generate`
11
+
12
+ **Project:** `@nathapp/nestjs-tenant`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** typescript
17
+
18
+ **Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check`
19
+
20
+ ---
21
+ # CLAUDE.md — @nathapp/nestjs-tenant
22
+
23
+ Multi-tenant context management for NestJS. Column-based tenancy with automatic request-scoped context.
24
+
25
+ ## Status: ✅ Complete
26
+
27
+ ## Key Files
28
+
29
+ - `lib/interface/` — `ITenant`, `ITenantRepository`, `ITenantService`, `ITenantResolver`, `ITenantContext`, `IMultiTenantPrincipal`, `ITenantPrincipalBinder`
30
+ - `lib/service/default-tenant.service.ts` — Default tenant CRUD with single-tenant mode support
31
+ - `lib/service/tenant-context.service.ts` — AsyncLocalStorage-based request-scoped tenant context
32
+ - `lib/resolver/` — 5 resolvers: `HeaderTenantResolver`, `JwtClaimTenantResolver`, `SubdomainTenantResolver`, `PathTenantResolver`, `DtoFieldTenantResolver`
33
+ - `lib/guard/tenant.guard.ts` — `TenantGuard` resolves + validates tenant per request, sets context
34
+ - `lib/decorator/` — `@CurrentTenant()`, `@SkipTenant()`, `@TenantId()` (DTO param)
35
+ - `lib/module/tenant.module.ts` — `TenantModule.register()` / `registerAsync()`
36
+ - `lib/constant/tokens.ts` — DI tokens: `TENANT_REPOSITORY`, `TENANT_SERVICE`, `TENANT_RESOLVER`, `TENANT_CONTEXT`, `TENANT_MODULE_OPTIONS`, `TENANT_CACHE`, `TENANT_PRINCIPAL_BINDER`
37
+
38
+ ## DI Tokens
39
+
40
+ | Token | Interface | Default |
41
+ |:---|:---|:---|
42
+ | `TENANT_REPOSITORY` | `ITenantRepository` | None (consumer must provide) |
43
+ | `TENANT_SERVICE` | `ITenantService` | `DefaultTenantService` |
44
+ | `TENANT_RESOLVER` | `ITenantResolver` | Configured via module options |
45
+ | `TENANT_CONTEXT` | `ITenantContext` | `TenantContextService` |
46
+ | `TENANT_CACHE` | `ITenantCache` | `InMemoryTenantCache` |
47
+ | `TENANT_PRINCIPAL_BINDER` | `ITenantPrincipalBinder` | None (consumer must provide) |
48
+
49
+ ## Module Registration
50
+
51
+ ```typescript
52
+ TenantModule.register({
53
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
54
+ resolution: { strategy: TenantResolutionStrategy.HEADER, headerName: 'x-tenant-id' },
55
+ // Single-tenant mode (optional, off by default — set enabled: true to arm it).
56
+ // Armed, TenantGuard falls back to defaultTenantId when the configured resolver
57
+ // finds no tenant identifier on the request. headerName is only read by the
58
+ // HEADER strategy; JWT_CLAIM reads claimKey, SUBDOMAIN reads the host, PATH reads
59
+ // pathPrefix, DTO_FIELD reads dtoField, and CUSTOM takes a resolver class.
60
+ //
61
+ // defaultTenantId MUST be a real, existing tenant id. It is not validated at
62
+ // registration: a falsy value is returned like any other resolution result and
63
+ // fails the guard's `if (!resolved)` check, so outside a guard.skipPaths match
64
+ // it rejects with the normal 400 (RESOLUTION_FAILED) — 403 under
65
+ // onTenantMissing: 'forbidden' — while a skip path is allowed unbound instead.
66
+ // The fallback is only "fail-open" when the id is real. Header/subdomain
67
+ // resolution still wins when present, so multi-tenant behaviour is unaffected.
68
+ // Enable only for genuinely single-tenant deployments.
69
+ singleTenant: { enabled: false, defaultTenantId: 'tenant-1' },
70
+ })
71
+ ```
72
+
73
+ ## Supported Wiring
74
+
75
+ Supported production order — `TenantGuard` reads the principal off `request.user`, so register the real guards explicitly in authentication → tenant → authorization order:
76
+
77
+ ```
78
+ JwtAuthGuard (@nathapp/nestjs-auth)
79
+ → TenantGuard (configured resolver + optional principal binding)
80
+ → PermissionAuthGuard (@nathapp/nestjs-auth) + AccountCaslAbilityFactory (@nathapp/nestjs-account)
81
+ ```
82
+
83
+ The resolver strategy controls where the request's tenant ID comes from; principal binding then checks membership in that resolved tenant. These are separate decisions:
84
+
85
+ - `HEADER` resolves `x-tenant-id` (or the configured header name). `require-match` rejects an authenticated principal that is not a member of that header-selected tenant.
86
+ - `JWT_CLAIM` resolves a claim on the authenticated principal: first `user.tenantId`, then `user.extra.tenantId` for claims nested by the core auth provider. It does not read the tenant header.
87
+
88
+ The real guard order, Fastify request path, and tenant AsyncLocalStorage are exercised by `packages/integration-e2e/test/tenant-principal-isolation.spec.ts` for both strategies.
89
+
90
+ ### `guard.principalBinding`
91
+
92
+ | Mode | Behaviour |
93
+ |:---|:---|
94
+ | `off` (default) | No check; the binder is never called |
95
+ | `require-match` | 403 (`TENANT_PRINCIPAL_MISMATCH`) when the principal is not a member of the resolved tenant |
96
+ | `assert` | Dry run — warns on mismatch (and on binder error) and continues; never rejects |
97
+
98
+ There is deliberately **no default binder**. `TenantGuard` injects `TENANT_PRINCIPAL_BINDER` with `@Optional()`, so `require-match` without one would 403 every authenticated request — `TenantModule.register()` / `registerAsync()` throw instead. Supply one:
99
+
100
+ ```typescript
101
+ TenantModule.register({
102
+ repository: MyTenantRepository, // REQUIRED — consumer's ITenantRepository class
103
+ resolution: { strategy: TenantResolutionStrategy.JWT_CLAIM },
104
+ principalBinder: MyTenantPrincipalBinder, // registered as TENANT_PRINCIPAL_BINDER (recommended)
105
+ guard: { principalBinding: { mode: 'require-match' } },
106
+ })
107
+ ```
108
+
109
+ A binder reaching the token from another module needs `guard.principalBinding.binderProvided: true` — the module cannot verify it, and under `register()` (no `imports`) the providing module must be `@Global()` **and export** the token; merely providing it stays invisible. Prefer `principalBinder`: it is the only route the module can resolve for you, and the only such route under `register()`. Under `registerAsync` set `principalBinder` on `TenantModuleAsyncOptions`, not on the options the factory returns.
110
+
111
+ `ITenantPrincipalBinder` is declared here, deliberately not a re-export of `nestjs-iam`'s `ITenantMembershipResolver` — `nestjs-tenant` is the dependency floor and cannot depend on `nestjs-iam`, so the consumer supplies a bridging binder. Implement it as:
112
+
113
+ ```typescript
114
+ interface ITenantPrincipalBinder {
115
+ assertMembership(principal: { id?: string }, tenantId: string): Promise<boolean>;
116
+ }
117
+ ```
118
+
119
+ `principal` is typed `{ id?: string }` and not a broader record: a binder normally bridges `nestjs-iam`'s `IPrincipal`, and an index signature here would reject that (TypeScript grants implicit index signatures to object literal types, not to interfaces). The binder reads `principal.id`; look up anything else off the concrete principal type inside your own implementation.
120
+
121
+ The check runs after `setTenant` and is never cached, so a revoked membership takes effect immediately rather than after `validation.cacheTtl`. It is skipped when the request carries no principal, and skipped for `@SkipTenant()` handlers. Note the asymmetry on `guard.skipPaths`: a matching path is **not** an unbound request — resolution and lookup still run and a found tenant **is** still set on the context and `request.__tenant`; only this assertion is skipped.
122
+
123
+ ### JWT tenant claim
124
+
125
+ `JwtClaimTenantResolver` reads `user[claimKey]` (default `'tenantId'`), then `user.extra[claimKey]`; a dotted `claimKey` such as `'extra.tenantId'` is walked against `user` instead. A function may be passed in place of the key (selector mode). `extra` is where core `SimpleAuthProvider` puts arbitrary claims — it maps a payload to `{ id, username, name, authorities, extra }`, so a top-level-only read resolved nothing for a core-issued JWT. A non-primitive claim resolves to `null`, not `"[object Object]"`.
126
+
127
+ The cross-tenant HTTP acceptance coverage lives in `packages/integration-e2e/test/tenant-principal-isolation.spec.ts`; the OAuth flow tests separately keep their existing `TenantContextService.run()` coverage.
128
+
129
+ ## Testing
130
+
131
+ ```bash
132
+ npm test # run tests
133
+ npm run test:cov # with coverage
134
+ ```
135
+
136
+ ## Gotchas
137
+
138
+ - `TenantContextService` uses `AsyncLocalStorage` — context is lost if you break the async chain (e.g., `setTimeout` without `AsyncResource`)
139
+ - `@SkipTenant()` on a handler skips `TenantGuard` resolution entirely
140
+ - `IMultiTenantPrincipal` extends `IPrincipal` from `@nathapp/nestjs-auth` — adds `tenantId` and `roles`
@@ -0,0 +1,9 @@
1
+ import type { CacheManager } from '@nathapp/nestjs-cache';
2
+ import { ITenantCache } from '../interface/tenant-cache.interface';
3
+ import { Tenant } from '../interface/tenant.interface';
4
+ export declare class CacheManagerTenantCache implements ITenantCache {
5
+ private readonly cache;
6
+ constructor(cache: CacheManager);
7
+ get(key: string): Promise<Tenant | null>;
8
+ set(key: string, tenant: Tenant, ttlMs: number): Promise<void>;
9
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CacheManagerTenantCache = void 0;
4
+ class CacheManagerTenantCache {
5
+ constructor(cache) {
6
+ this.cache = cache;
7
+ }
8
+ async get(key) {
9
+ var _a;
10
+ return (_a = (await this.cache.getOnly(key))) !== null && _a !== void 0 ? _a : null;
11
+ }
12
+ async set(key, tenant, ttlMs) {
13
+ await this.cache.set(key, tenant, ttlMs);
14
+ }
15
+ }
16
+ exports.CacheManagerTenantCache = CacheManagerTenantCache;
17
+ //# sourceMappingURL=cache-manager-tenant-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-manager-tenant-cache.js","sourceRoot":"","sources":["../../lib/cache/cache-manager-tenant-cache.ts"],"names":[],"mappings":";;;AAIA,MAAa,uBAAuB;IAClC,YAA6B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;IAAG,CAAC;IAEpD,KAAK,CAAC,GAAG,CAAC,GAAW;;QACnB,OAAO,MAAA,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAS,GAAG,CAAC,CAAC,mCAAI,IAAI,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,KAAa;QAClD,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AAVD,0DAUC"}
@@ -0,0 +1,13 @@
1
+ import { IClock } from '@nathapp/nestjs-common';
2
+ import { Tenant } from '../interface/tenant.interface';
3
+ import { ITenantCache } from '../interface/tenant-cache.interface';
4
+ export declare class InMemoryTenantCache implements ITenantCache {
5
+ private readonly entries;
6
+ private readonly clock;
7
+ private readonly maxEntries;
8
+ constructor(clockOrOptions?: IClock | {
9
+ maxEntries: number;
10
+ });
11
+ get(key: string): Promise<Tenant | null>;
12
+ set(key: string, tenant: Tenant, ttlMs: number): Promise<void>;
13
+ }