@veritas-lex/contract-analysis-package 1.2.3

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 (214) hide show
  1. package/README.md +181 -0
  2. package/dist/auth/auth-core.module.d.ts +21 -0
  3. package/dist/auth/auth-core.module.d.ts.map +1 -0
  4. package/dist/auth/auth-core.module.js +56 -0
  5. package/dist/auth/auth-core.module.js.map +1 -0
  6. package/dist/auth/decorators/current-user.decorator.d.ts +2 -0
  7. package/dist/auth/decorators/current-user.decorator.d.ts.map +1 -0
  8. package/dist/auth/decorators/current-user.decorator.js +9 -0
  9. package/dist/auth/decorators/current-user.decorator.js.map +1 -0
  10. package/dist/auth/decorators/public.decorator.d.ts +3 -0
  11. package/dist/auth/decorators/public.decorator.d.ts.map +1 -0
  12. package/dist/auth/decorators/public.decorator.js +8 -0
  13. package/dist/auth/decorators/public.decorator.js.map +1 -0
  14. package/dist/auth/guards/jwt-auth.guard.d.ts +11 -0
  15. package/dist/auth/guards/jwt-auth.guard.d.ts.map +1 -0
  16. package/dist/auth/guards/jwt-auth.guard.js +39 -0
  17. package/dist/auth/guards/jwt-auth.guard.js.map +1 -0
  18. package/dist/auth/index.d.ts +7 -0
  19. package/dist/auth/index.d.ts.map +1 -0
  20. package/dist/auth/index.js +15 -0
  21. package/dist/auth/index.js.map +1 -0
  22. package/dist/auth/interfaces/jwt-payload.interface.d.ts +24 -0
  23. package/dist/auth/interfaces/jwt-payload.interface.d.ts.map +1 -0
  24. package/dist/auth/interfaces/jwt-payload.interface.js +3 -0
  25. package/dist/auth/interfaces/jwt-payload.interface.js.map +1 -0
  26. package/dist/auth/strategies/base-jwt.strategy.d.ts +47 -0
  27. package/dist/auth/strategies/base-jwt.strategy.d.ts.map +1 -0
  28. package/dist/auth/strategies/base-jwt.strategy.js +162 -0
  29. package/dist/auth/strategies/base-jwt.strategy.js.map +1 -0
  30. package/dist/bootstrap/configure-app.d.ts +50 -0
  31. package/dist/bootstrap/configure-app.d.ts.map +1 -0
  32. package/dist/bootstrap/configure-app.js +117 -0
  33. package/dist/bootstrap/configure-app.js.map +1 -0
  34. package/dist/bootstrap/index.d.ts +3 -0
  35. package/dist/bootstrap/index.d.ts.map +1 -0
  36. package/dist/bootstrap/index.js +6 -0
  37. package/dist/bootstrap/index.js.map +1 -0
  38. package/dist/config/app.config.d.ts +37 -0
  39. package/dist/config/app.config.d.ts.map +1 -0
  40. package/dist/config/app.config.js +28 -0
  41. package/dist/config/app.config.js.map +1 -0
  42. package/dist/config/database.config.d.ts +48 -0
  43. package/dist/config/database.config.d.ts.map +1 -0
  44. package/dist/config/database.config.js +34 -0
  45. package/dist/config/database.config.js.map +1 -0
  46. package/dist/config/doc.config.d.ts +31 -0
  47. package/dist/config/doc.config.d.ts.map +1 -0
  48. package/dist/config/doc.config.js +22 -0
  49. package/dist/config/doc.config.js.map +1 -0
  50. package/dist/config/index.d.ts +17 -0
  51. package/dist/config/index.d.ts.map +1 -0
  52. package/dist/config/index.js +26 -0
  53. package/dist/config/index.js.map +1 -0
  54. package/dist/config/jwt.config.d.ts +19 -0
  55. package/dist/config/jwt.config.d.ts.map +1 -0
  56. package/dist/config/jwt.config.js +28 -0
  57. package/dist/config/jwt.config.js.map +1 -0
  58. package/dist/config/logging.config.d.ts +33 -0
  59. package/dist/config/logging.config.d.ts.map +1 -0
  60. package/dist/config/logging.config.js +106 -0
  61. package/dist/config/logging.config.js.map +1 -0
  62. package/dist/config/redis.config.d.ts +19 -0
  63. package/dist/config/redis.config.d.ts.map +1 -0
  64. package/dist/config/redis.config.js +16 -0
  65. package/dist/config/redis.config.js.map +1 -0
  66. package/dist/config/security.config.d.ts +66 -0
  67. package/dist/config/security.config.d.ts.map +1 -0
  68. package/dist/config/security.config.js +66 -0
  69. package/dist/config/security.config.js.map +1 -0
  70. package/dist/config/storage.config.d.ts +20 -0
  71. package/dist/config/storage.config.d.ts.map +1 -0
  72. package/dist/config/storage.config.js +17 -0
  73. package/dist/config/storage.config.js.map +1 -0
  74. package/dist/config/validation.config.d.ts +62 -0
  75. package/dist/config/validation.config.d.ts.map +1 -0
  76. package/dist/config/validation.config.js +139 -0
  77. package/dist/config/validation.config.js.map +1 -0
  78. package/dist/constants/enums.d.ts +76 -0
  79. package/dist/constants/enums.d.ts.map +1 -0
  80. package/dist/constants/enums.js +92 -0
  81. package/dist/constants/enums.js.map +1 -0
  82. package/dist/constants/file-validation.constants.d.ts +28 -0
  83. package/dist/constants/file-validation.constants.d.ts.map +1 -0
  84. package/dist/constants/file-validation.constants.js +81 -0
  85. package/dist/constants/file-validation.constants.js.map +1 -0
  86. package/dist/constants/index.d.ts +6 -0
  87. package/dist/constants/index.d.ts.map +1 -0
  88. package/dist/constants/index.js +26 -0
  89. package/dist/constants/index.js.map +1 -0
  90. package/dist/constants/pii-classifications.constants.d.ts +27 -0
  91. package/dist/constants/pii-classifications.constants.d.ts.map +1 -0
  92. package/dist/constants/pii-classifications.constants.js +68 -0
  93. package/dist/constants/pii-classifications.constants.js.map +1 -0
  94. package/dist/database/base.entity.d.ts +6 -0
  95. package/dist/database/base.entity.d.ts.map +1 -0
  96. package/dist/database/base.entity.js +32 -0
  97. package/dist/database/base.entity.js.map +1 -0
  98. package/dist/database/database.module.d.ts +32 -0
  99. package/dist/database/database.module.d.ts.map +1 -0
  100. package/dist/database/database.module.js +69 -0
  101. package/dist/database/database.module.js.map +1 -0
  102. package/dist/database/entities/base-audit-log.entity.d.ts +21 -0
  103. package/dist/database/entities/base-audit-log.entity.d.ts.map +1 -0
  104. package/dist/database/entities/base-audit-log.entity.js +90 -0
  105. package/dist/database/entities/base-audit-log.entity.js.map +1 -0
  106. package/dist/database/entities/base-contract-chunk.entity.d.ts +18 -0
  107. package/dist/database/entities/base-contract-chunk.entity.d.ts.map +1 -0
  108. package/dist/database/entities/base-contract-chunk.entity.js +71 -0
  109. package/dist/database/entities/base-contract-chunk.entity.js.map +1 -0
  110. package/dist/database/entities/base-contract-event.entity.d.ts +16 -0
  111. package/dist/database/entities/base-contract-event.entity.d.ts.map +1 -0
  112. package/dist/database/entities/base-contract-event.entity.js +66 -0
  113. package/dist/database/entities/base-contract-event.entity.js.map +1 -0
  114. package/dist/database/entities/base-contract-key-date-rule.entity.d.ts +31 -0
  115. package/dist/database/entities/base-contract-key-date-rule.entity.d.ts.map +1 -0
  116. package/dist/database/entities/base-contract-key-date-rule.entity.js +140 -0
  117. package/dist/database/entities/base-contract-key-date-rule.entity.js.map +1 -0
  118. package/dist/database/entities/base-contract-pii-replacement.entity.d.ts +18 -0
  119. package/dist/database/entities/base-contract-pii-replacement.entity.d.ts.map +1 -0
  120. package/dist/database/entities/base-contract-pii-replacement.entity.js +67 -0
  121. package/dist/database/entities/base-contract-pii-replacement.entity.js.map +1 -0
  122. package/dist/database/entities/base-contract-red-flag.entity.d.ts +27 -0
  123. package/dist/database/entities/base-contract-red-flag.entity.d.ts.map +1 -0
  124. package/dist/database/entities/base-contract-red-flag.entity.js +114 -0
  125. package/dist/database/entities/base-contract-red-flag.entity.js.map +1 -0
  126. package/dist/database/entities/base-contract-task.entity.d.ts +20 -0
  127. package/dist/database/entities/base-contract-task.entity.d.ts.map +1 -0
  128. package/dist/database/entities/base-contract-task.entity.js +87 -0
  129. package/dist/database/entities/base-contract-task.entity.js.map +1 -0
  130. package/dist/database/entities/base-contract-text.entity.d.ts +19 -0
  131. package/dist/database/entities/base-contract-text.entity.d.ts.map +1 -0
  132. package/dist/database/entities/base-contract-text.entity.js +77 -0
  133. package/dist/database/entities/base-contract-text.entity.js.map +1 -0
  134. package/dist/database/entities/base-contract.entity.d.ts +56 -0
  135. package/dist/database/entities/base-contract.entity.d.ts.map +1 -0
  136. package/dist/database/entities/base-contract.entity.js +221 -0
  137. package/dist/database/entities/base-contract.entity.js.map +1 -0
  138. package/dist/database/entities/base-job.entity.d.ts +21 -0
  139. package/dist/database/entities/base-job.entity.d.ts.map +1 -0
  140. package/dist/database/entities/base-job.entity.js +89 -0
  141. package/dist/database/entities/base-job.entity.js.map +1 -0
  142. package/dist/database/entities/base-qna-question.entity.d.ts +22 -0
  143. package/dist/database/entities/base-qna-question.entity.d.ts.map +1 -0
  144. package/dist/database/entities/base-qna-question.entity.js +92 -0
  145. package/dist/database/entities/base-qna-question.entity.js.map +1 -0
  146. package/dist/database/entities/base-scoring-criteria.entity.d.ts +57 -0
  147. package/dist/database/entities/base-scoring-criteria.entity.d.ts.map +1 -0
  148. package/dist/database/entities/base-scoring-criteria.entity.js +376 -0
  149. package/dist/database/entities/base-scoring-criteria.entity.js.map +1 -0
  150. package/dist/database/entities/base-users-profile.entity.d.ts +32 -0
  151. package/dist/database/entities/base-users-profile.entity.d.ts.map +1 -0
  152. package/dist/database/entities/base-users-profile.entity.js +91 -0
  153. package/dist/database/entities/base-users-profile.entity.js.map +1 -0
  154. package/dist/database/entities/index.d.ts +16 -0
  155. package/dist/database/entities/index.d.ts.map +1 -0
  156. package/dist/database/entities/index.js +37 -0
  157. package/dist/database/entities/index.js.map +1 -0
  158. package/dist/database/entities/qna-question-template.entity.d.ts +30 -0
  159. package/dist/database/entities/qna-question-template.entity.d.ts.map +1 -0
  160. package/dist/database/entities/qna-question-template.entity.js +145 -0
  161. package/dist/database/entities/qna-question-template.entity.js.map +1 -0
  162. package/dist/database/entities/qna-response.entity.d.ts +29 -0
  163. package/dist/database/entities/qna-response.entity.d.ts.map +1 -0
  164. package/dist/database/entities/qna-response.entity.js +129 -0
  165. package/dist/database/entities/qna-response.entity.js.map +1 -0
  166. package/dist/database/index.d.ts +7 -0
  167. package/dist/database/index.d.ts.map +1 -0
  168. package/dist/database/index.js +32 -0
  169. package/dist/database/index.js.map +1 -0
  170. package/dist/database/redis.module.d.ts +12 -0
  171. package/dist/database/redis.module.d.ts.map +1 -0
  172. package/dist/database/redis.module.js +40 -0
  173. package/dist/database/redis.module.js.map +1 -0
  174. package/dist/database/redis.provider.d.ts +15 -0
  175. package/dist/database/redis.provider.d.ts.map +1 -0
  176. package/dist/database/redis.provider.js +42 -0
  177. package/dist/database/redis.provider.js.map +1 -0
  178. package/dist/dto/api-response.dto.d.ts +36 -0
  179. package/dist/dto/api-response.dto.d.ts.map +1 -0
  180. package/dist/dto/api-response.dto.js +88 -0
  181. package/dist/dto/api-response.dto.js.map +1 -0
  182. package/dist/dto/index.d.ts +2 -0
  183. package/dist/dto/index.d.ts.map +1 -0
  184. package/dist/dto/index.js +6 -0
  185. package/dist/dto/index.js.map +1 -0
  186. package/dist/filters/all-exceptions.filter.d.ts +43 -0
  187. package/dist/filters/all-exceptions.filter.d.ts.map +1 -0
  188. package/dist/filters/all-exceptions.filter.js +123 -0
  189. package/dist/filters/all-exceptions.filter.js.map +1 -0
  190. package/dist/filters/index.d.ts +3 -0
  191. package/dist/filters/index.d.ts.map +1 -0
  192. package/dist/filters/index.js +6 -0
  193. package/dist/filters/index.js.map +1 -0
  194. package/dist/helpers/crypto.service.d.ts +53 -0
  195. package/dist/helpers/crypto.service.d.ts.map +1 -0
  196. package/dist/helpers/crypto.service.js +153 -0
  197. package/dist/helpers/crypto.service.js.map +1 -0
  198. package/dist/helpers/index.d.ts +2 -0
  199. package/dist/helpers/index.d.ts.map +1 -0
  200. package/dist/helpers/index.js +6 -0
  201. package/dist/helpers/index.js.map +1 -0
  202. package/dist/index.d.ts +17 -0
  203. package/dist/index.d.ts.map +1 -0
  204. package/dist/index.js +86 -0
  205. package/dist/index.js.map +1 -0
  206. package/dist/swagger/index.d.ts +2 -0
  207. package/dist/swagger/index.d.ts.map +1 -0
  208. package/dist/swagger/index.js +6 -0
  209. package/dist/swagger/index.js.map +1 -0
  210. package/dist/swagger/swagger.d.ts +16 -0
  211. package/dist/swagger/swagger.d.ts.map +1 -0
  212. package/dist/swagger/swagger.js +59 -0
  213. package/dist/swagger/swagger.js.map +1 -0
  214. package/package.json +63 -0
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # @ignatg/contract-analysis-package
2
+
3
+ Shared NestJS infrastructure for the Contract Analysis platform. This package extracts duplicated infrastructure code from `contract-analysis-api` and `ai-analysis-api` into a single, versioned package.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @ignatg/contract-analysis-package
9
+ ```
10
+
11
+ Or reference locally during development:
12
+
13
+ ```json
14
+ {
15
+ "dependencies": {
16
+ "@ignatg/contract-analysis-package": "^1.0.0",
17
+ }
18
+ }
19
+ ```
20
+
21
+ ## What's Included
22
+
23
+ | Module | Exports | Description |
24
+ |--------|---------|-------------|
25
+ | **Auth** | `JwtAuthGuard`, `BaseJwtStrategy`, `AuthCoreModule`, `CurrentUser`, `Public` | JWT authentication with Supabase JWKS support |
26
+ | **Config** | `createAppConfig`, `createDatabaseConfig`, `createDocConfig`, `createJwtConfig`, `createLoggingConfig`, `createSecurityConfig`, `buildPinoParams`, `RedisConfig`, `StorageConfig` | Parameterised config factories |
27
+ | **Constants** | `CRITICAL_PII_TYPES`, `HIGH_RISK_PII_TYPES`, `STANDARD_PII_TYPES`, `CONTEXTUAL_ENTITIES`, `ContractStatus`, `JobType`, `JobStatus`, `TaskStatus`, `TaskPriority`, `RiskLevel`, `RuleKind`, `RuleDirection` | PII classification + workflow enums |
28
+ | **Database** | `DatabaseModule`, `BaseEntity`, `RedisModule`, `RedisProvider` | TypeORM + BullMQ infrastructure |
29
+ | **DTO** | `ApiResponseDto` | Standard API response wrapper |
30
+ | **Filters** | `AllExceptionsFilter` | Global exception filter |
31
+ | **Helpers** | `TransformInterceptor` | Response transformation interceptor |
32
+ | **Swagger** | `SwaggerDocs` | Swagger/OpenAPI documentation setup |
33
+ | **Bootstrap** | `configureApp` | Shared application bootstrap helper |
34
+
35
+ ## Usage
36
+
37
+ ### Config Factories
38
+
39
+ Each API calls factory functions with its own defaults:
40
+
41
+ ```typescript
42
+ // config/index.ts
43
+ import {
44
+ createAppConfig,
45
+ createDatabaseConfig,
46
+ createDocConfig,
47
+ createJwtConfig,
48
+ createLoggingConfig,
49
+ createSecurityConfig,
50
+ RedisConfig,
51
+ StorageConfig,
52
+ } from '@ignatg/contract-analysis-package';
53
+
54
+ const AppConfig = createAppConfig({
55
+ name: 'My API',
56
+ port: 3000,
57
+ corsOrigins: 'http://localhost:3333',
58
+ });
59
+
60
+ const DatabaseConfig = createDatabaseConfig({
61
+ defaultDbName: 'mydb',
62
+ defaultPoolMax: 20,
63
+ });
64
+
65
+ const DocConfig = createDocConfig({
66
+ name: 'My API Specification',
67
+ description: 'API documentation',
68
+ });
69
+
70
+ const JwtConfig = createJwtConfig({ strict: true });
71
+ const LoggingConfig = createLoggingConfig({ defaultLevel: 'debug' });
72
+ const SecurityConfig = createSecurityConfig({ includeEncryptionKey: true });
73
+
74
+ export default [
75
+ AppConfig,
76
+ DatabaseConfig,
77
+ DocConfig,
78
+ JwtConfig,
79
+ LoggingConfig,
80
+ SecurityConfig,
81
+ RedisConfig,
82
+ StorageConfig,
83
+ ];
84
+ ```
85
+
86
+ ### Auth Module
87
+
88
+ Extend `BaseJwtStrategy` with your custom `validate()` logic:
89
+
90
+ ```typescript
91
+ import { Injectable } from '@nestjs/common';
92
+ import { ConfigService } from '@nestjs/config';
93
+ import { BaseJwtStrategy, JwtPayload } from '@ignatg/contract-analysis-package';
94
+
95
+ @Injectable()
96
+ export class JwtStrategy extends BaseJwtStrategy {
97
+ constructor(configService: ConfigService) {
98
+ super(configService);
99
+ }
100
+
101
+ validate(payload: JwtPayload) {
102
+ this.validateCorePayload(payload);
103
+ return {
104
+ userId: payload.sub,
105
+ email: payload.email || '',
106
+ role: payload.role || 'user',
107
+ };
108
+ }
109
+ }
110
+ ```
111
+
112
+ ### Bootstrap Helper
113
+
114
+ Simplify your `main.ts`:
115
+
116
+ ```typescript
117
+ import { NestFactory, NestApplication } from '@nestjs/core';
118
+ import { ConfigService } from '@nestjs/config';
119
+ import { Logger } from 'nestjs-pino';
120
+ import { configureApp } from '@ignatg/contract-analysis-package';
121
+ import { MainModule } from './main.module';
122
+
123
+ async function bootstrap() {
124
+ const app = await NestFactory.create<NestApplication>(MainModule, { bufferLogs: true });
125
+ await configureApp(app);
126
+
127
+ const configService = app.get(ConfigService);
128
+ const port = configService.get<number>('app.port');
129
+ const logger = app.get(Logger);
130
+ logger.log(`Main app will serve on PORT ${port}`, 'MainApplication');
131
+ await app.listen(port);
132
+ }
133
+
134
+ bootstrap();
135
+ ```
136
+
137
+ ### Database Module
138
+
139
+ ```typescript
140
+ import { Module } from '@nestjs/common';
141
+ import { DatabaseModule } from '@ignatg/contract-analysis-package';
142
+
143
+ @Module({
144
+ imports: [DatabaseModule.register()],
145
+ })
146
+ export class MainModule {}
147
+ ```
148
+
149
+ ### Shared Enums
150
+
151
+ ```typescript
152
+ import { ContractStatus, JobStatus, RiskLevel } from '@ignatg/contract-analysis-package';
153
+
154
+ // Use in entity files (re-export pattern)
155
+ export { ContractStatus } from '@ignatg/contract-analysis-package';
156
+
157
+ // Use in services
158
+ if (contract.status === ContractStatus.READY) { ... }
159
+ if (job.status === JobStatus.QUEUED) { ... }
160
+ ```
161
+
162
+ Available enums: `ContractStatus`, `JobType`, `JobStatus`, `TaskStatus`, `TaskPriority`, `RiskLevel`, `RuleKind`, `RuleDirection`
163
+
164
+ ## Peer Dependencies
165
+
166
+ This package declares all NestJS ecosystem packages as `peerDependencies` to avoid version conflicts. Your consuming application must have them installed.
167
+
168
+ ## Building
169
+
170
+ ```bash
171
+ npm run build # Compiles TypeScript to dist/
172
+ npm run clean # Removes dist/
173
+ ```
174
+
175
+ ## Publishing
176
+
177
+ Configured for GitHub Packages:
178
+
179
+ ```bash
180
+ npm publish
181
+ ```
@@ -0,0 +1,21 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ /**
3
+ * Auth Core Module
4
+ *
5
+ * Provides the shared Passport + JWT infrastructure that all APIs need.
6
+ * Each API imports this module and registers its own JwtStrategy and guards.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * @Module({
11
+ * imports: [AuthCoreModule.register(), TypeOrmModule.forFeature([User])],
12
+ * providers: [JwtStrategy, JwtAuthGuard, AuthService],
13
+ * exports: [JwtStrategy, JwtAuthGuard],
14
+ * })
15
+ * export class AuthModule {}
16
+ * ```
17
+ */
18
+ export declare class AuthCoreModule {
19
+ static register(): DynamicModule;
20
+ }
21
+ //# sourceMappingURL=auth-core.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-core.module.d.ts","sourceRoot":"","sources":["../../src/auth/auth-core.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKvD;;;;;;;;;;;;;;;GAeG;AACH,qBACa,cAAc;IACzB,MAAM,CAAC,QAAQ,IAAI,aAAa;CAoBjC"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var AuthCoreModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AuthCoreModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const config_1 = require("@nestjs/config");
13
+ const jwt_1 = require("@nestjs/jwt");
14
+ const passport_1 = require("@nestjs/passport");
15
+ /**
16
+ * Auth Core Module
17
+ *
18
+ * Provides the shared Passport + JWT infrastructure that all APIs need.
19
+ * Each API imports this module and registers its own JwtStrategy and guards.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * @Module({
24
+ * imports: [AuthCoreModule.register(), TypeOrmModule.forFeature([User])],
25
+ * providers: [JwtStrategy, JwtAuthGuard, AuthService],
26
+ * exports: [JwtStrategy, JwtAuthGuard],
27
+ * })
28
+ * export class AuthModule {}
29
+ * ```
30
+ */
31
+ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
32
+ static register() {
33
+ return {
34
+ module: AuthCoreModule_1,
35
+ imports: [
36
+ passport_1.PassportModule,
37
+ jwt_1.JwtModule.registerAsync({
38
+ imports: [config_1.ConfigModule],
39
+ useFactory: (configService) => ({
40
+ secret: configService.get("jwt.secret"),
41
+ signOptions: {
42
+ expiresIn: configService.get("jwt.expiresIn") || "7d",
43
+ },
44
+ }),
45
+ inject: [config_1.ConfigService],
46
+ }),
47
+ ],
48
+ exports: [passport_1.PassportModule, jwt_1.JwtModule],
49
+ };
50
+ }
51
+ };
52
+ exports.AuthCoreModule = AuthCoreModule;
53
+ exports.AuthCoreModule = AuthCoreModule = AuthCoreModule_1 = __decorate([
54
+ (0, common_1.Module)({})
55
+ ], AuthCoreModule);
56
+ //# sourceMappingURL=auth-core.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-core.module.js","sourceRoot":"","sources":["../../src/auth/auth-core.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,2CAA6D;AAC7D,qCAAwC;AACxC,+CAAkD;AAElD;;;;;;;;;;;;;;;GAeG;AAEI,IAAM,cAAc,sBAApB,MAAM,cAAc;IACzB,MAAM,CAAC,QAAQ;QACb,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,OAAO,EAAE;gBACP,yBAAc;gBACd,eAAS,CAAC,aAAa,CAAC;oBACtB,OAAO,EAAE,CAAC,qBAAY,CAAC;oBACvB,UAAU,EAAE,CAAC,aAA4B,EAAE,EAAE,CAC3C,CAAC;wBACC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAS,YAAY,CAAC;wBAC/C,WAAW,EAAE;4BACX,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI;yBACtD;qBACF,CAA0C;oBAC7C,MAAM,EAAE,CAAC,sBAAa,CAAC;iBACxB,CAAC;aACH;YACD,OAAO,EAAE,CAAC,yBAAc,EAAE,eAAS,CAAC;SACrC,CAAC;IACJ,CAAC;CACF,CAAA;AArBY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,cAAc,CAqB1B"}
@@ -0,0 +1,2 @@
1
+ export declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
2
+ //# sourceMappingURL=current-user.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.decorator.d.ts","sourceRoot":"","sources":["../../../src/auth/decorators/current-user.decorator.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,mDAKvB,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CurrentUser = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.CurrentUser = (0, common_1.createParamDecorator)((data, ctx) => {
6
+ const request = ctx.switchToHttp().getRequest();
7
+ return request.user;
8
+ });
9
+ //# sourceMappingURL=current-user.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.decorator.js","sourceRoot":"","sources":["../../../src/auth/decorators/current-user.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAE3D,QAAA,WAAW,GAAG,IAAA,6BAAoB,EAC7C,CAAC,IAAa,EAAE,GAAqB,EAAE,EAAE;IACvC,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC,CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const IS_PUBLIC_KEY = "isPublic";
2
+ export declare const Public: () => import("@nestjs/common").CustomDecorator<string>;
3
+ //# sourceMappingURL=public.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.decorator.d.ts","sourceRoot":"","sources":["../../../src/auth/decorators/public.decorator.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,eAAO,MAAM,MAAM,wDAAyC,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Public = exports.IS_PUBLIC_KEY = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.IS_PUBLIC_KEY = "isPublic";
6
+ const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
7
+ exports.Public = Public;
8
+ //# sourceMappingURL=public.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.decorator.js","sourceRoot":"","sources":["../../../src/auth/decorators/public.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,qBAAa,EAAE,IAAI,CAAC,CAAC;AAAhD,QAAA,MAAM,UAA0C"}
@@ -0,0 +1,11 @@
1
+ import { ExecutionContext } from "@nestjs/common";
2
+ import { Reflector } from "@nestjs/core";
3
+ export declare const IS_PUBLIC_KEY = "isPublic";
4
+ declare const JwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
5
+ export declare class JwtAuthGuard extends JwtAuthGuard_base {
6
+ private reflector;
7
+ constructor(reflector: Reflector);
8
+ canActivate(context: ExecutionContext): boolean | Promise<boolean> | import("rxjs").Observable<boolean>;
9
+ }
10
+ export {};
11
+ //# sourceMappingURL=jwt-auth.guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-auth.guard.d.ts","sourceRoot":"","sources":["../../../src/auth/guards/jwt-auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,eAAO,MAAM,aAAa,aAAa,CAAC;;AAExC,qBACa,YAAa,SAAQ,iBAAgB;IACpC,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAIxC,WAAW,CAAC,OAAO,EAAE,gBAAgB;CAYtC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.JwtAuthGuard = exports.IS_PUBLIC_KEY = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const core_1 = require("@nestjs/core");
15
+ const passport_1 = require("@nestjs/passport");
16
+ exports.IS_PUBLIC_KEY = "isPublic";
17
+ let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)("jwt") {
18
+ reflector;
19
+ constructor(reflector) {
20
+ super();
21
+ this.reflector = reflector;
22
+ }
23
+ canActivate(context) {
24
+ const isPublic = this.reflector.getAllAndOverride(exports.IS_PUBLIC_KEY, [
25
+ context.getHandler(),
26
+ context.getClass(),
27
+ ]);
28
+ if (isPublic) {
29
+ return true;
30
+ }
31
+ return super.canActivate(context);
32
+ }
33
+ };
34
+ exports.JwtAuthGuard = JwtAuthGuard;
35
+ exports.JwtAuthGuard = JwtAuthGuard = __decorate([
36
+ (0, common_1.Injectable)(),
37
+ __metadata("design:paramtypes", [core_1.Reflector])
38
+ ], JwtAuthGuard);
39
+ //# sourceMappingURL=jwt-auth.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../../src/auth/guards/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8D;AAC9D,uCAAyC;AACzC,+CAA6C;AAEhC,QAAA,aAAa,GAAG,UAAU,CAAC;AAGjC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,IAAA,oBAAS,EAAC,KAAK,CAAC;IAC5B;IAApB,YAAoB,SAAoB;QACtC,KAAK,EAAE,CAAC;QADU,cAAS,GAAT,SAAS,CAAW;IAExC,CAAC;IAED,WAAW,CAAC,OAAyB;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,qBAAa,EAAE;YACxE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAjBY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAEoB,gBAAS;GAD7B,YAAY,CAiBxB"}
@@ -0,0 +1,7 @@
1
+ export { CurrentUser } from "./decorators/current-user.decorator";
2
+ export { IS_PUBLIC_KEY, Public } from "./decorators/public.decorator";
3
+ export { JwtAuthGuard } from "./guards/jwt-auth.guard";
4
+ export { BaseJwtStrategy } from "./strategies/base-jwt.strategy";
5
+ export { AuthCoreModule } from "./auth-core.module";
6
+ export type { JwtPayload } from "./interfaces/jwt-payload.interface";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthCoreModule = exports.BaseJwtStrategy = exports.JwtAuthGuard = exports.Public = exports.IS_PUBLIC_KEY = exports.CurrentUser = void 0;
4
+ var current_user_decorator_1 = require("./decorators/current-user.decorator");
5
+ Object.defineProperty(exports, "CurrentUser", { enumerable: true, get: function () { return current_user_decorator_1.CurrentUser; } });
6
+ var public_decorator_1 = require("./decorators/public.decorator");
7
+ Object.defineProperty(exports, "IS_PUBLIC_KEY", { enumerable: true, get: function () { return public_decorator_1.IS_PUBLIC_KEY; } });
8
+ Object.defineProperty(exports, "Public", { enumerable: true, get: function () { return public_decorator_1.Public; } });
9
+ var jwt_auth_guard_1 = require("./guards/jwt-auth.guard");
10
+ Object.defineProperty(exports, "JwtAuthGuard", { enumerable: true, get: function () { return jwt_auth_guard_1.JwtAuthGuard; } });
11
+ var base_jwt_strategy_1 = require("./strategies/base-jwt.strategy");
12
+ Object.defineProperty(exports, "BaseJwtStrategy", { enumerable: true, get: function () { return base_jwt_strategy_1.BaseJwtStrategy; } });
13
+ var auth_core_module_1 = require("./auth-core.module");
14
+ Object.defineProperty(exports, "AuthCoreModule", { enumerable: true, get: function () { return auth_core_module_1.AuthCoreModule; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;AAAA,8EAAkE;AAAzD,qHAAA,WAAW,OAAA;AACpB,kEAAsE;AAA7D,iHAAA,aAAa,OAAA;AAAE,0GAAA,MAAM,OAAA;AAC9B,0DAAuD;AAA9C,8GAAA,YAAY,OAAA;AACrB,oEAAiE;AAAxD,oHAAA,eAAe,OAAA;AACxB,uDAAoD;AAA3C,kHAAA,cAAc,OAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * JWT Payload interface for Supabase-issued tokens.
3
+ *
4
+ * Shared across all APIs that validate Supabase JWTs.
5
+ */
6
+ export interface JwtPayload {
7
+ sub: string;
8
+ username?: string;
9
+ email?: string;
10
+ role?: string;
11
+ iat?: number;
12
+ exp?: number;
13
+ /** Supabase audience claim — 'authenticated' for valid user tokens */
14
+ aud?: string;
15
+ /** Supabase user metadata from OAuth or registration */
16
+ user_metadata?: {
17
+ firstName?: string;
18
+ lastName?: string;
19
+ first_name?: string;
20
+ last_name?: string;
21
+ full_name?: string;
22
+ };
23
+ }
24
+ //# sourceMappingURL=jwt-payload.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-payload.interface.d.ts","sourceRoot":"","sources":["../../../src/auth/interfaces/jwt-payload.interface.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,aAAa,CAAC,EAAE;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=jwt-payload.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-payload.interface.js","sourceRoot":"","sources":["../../../src/auth/interfaces/jwt-payload.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ import { ConfigService } from "@nestjs/config";
2
+ import { Strategy } from "passport-jwt";
3
+ import { JwksClient } from "jwks-rsa";
4
+ import { JwtPayload } from "../interfaces/jwt-payload.interface";
5
+ declare const BaseJwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
6
+ validate(...args: any[]): unknown;
7
+ };
8
+ /**
9
+ * Base JWT Strategy for Supabase JWKS (ES256) token verification.
10
+ *
11
+ * Provides shared JWKS client setup, `secretOrKeyProvider` callback,
12
+ * and core payload validation. Each API extends this class with its
13
+ * own `validate()` method to customise the returned user object.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * @Injectable()
18
+ * export class JwtStrategy extends BaseJwtStrategy {
19
+ * constructor(configService: ConfigService) {
20
+ * super(configService);
21
+ * }
22
+ *
23
+ * validate(payload: JwtPayload) {
24
+ * this.validateCorePayload(payload);
25
+ * return { userId: payload.sub, email: payload.email };
26
+ * }
27
+ * }
28
+ * ```
29
+ */
30
+ export declare abstract class BaseJwtStrategy extends BaseJwtStrategy_base {
31
+ protected readonly jwksClient: JwksClient | null;
32
+ constructor(configService: ConfigService);
33
+ /**
34
+ * Validates core JWT claims shared across all APIs.
35
+ * Call this at the top of your `validate()` method.
36
+ *
37
+ * @throws UnauthorizedException if sub, iat, or exp are missing or token is expired
38
+ */
39
+ protected validateCorePayload(payload: JwtPayload): void;
40
+ /**
41
+ * Validate the JWT payload and return the user object.
42
+ * Each API implements this with its own user shape and optional DB lookups.
43
+ */
44
+ abstract validate(payload: JwtPayload): unknown | Promise<unknown>;
45
+ }
46
+ export {};
47
+ //# sourceMappingURL=base-jwt.strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-jwt.strategy.d.ts","sourceRoot":"","sources":["../../../src/auth/strategies/base-jwt.strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAc,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;;;;AAEjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,8BACsB,eAAgB,SAAQ,oBAA0B;IACtE,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAQ;gBAE5C,aAAa,EAAE,aAAa;IAiFxC;;;;;OAKG;IACH,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAmBxD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CACnE"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.BaseJwtStrategy = void 0;
46
+ const common_1 = require("@nestjs/common");
47
+ const config_1 = require("@nestjs/config");
48
+ const passport_1 = require("@nestjs/passport");
49
+ const passport_jwt_1 = require("passport-jwt");
50
+ const jwt = __importStar(require("jsonwebtoken"));
51
+ const jwks_rsa_1 = require("jwks-rsa");
52
+ /**
53
+ * Base JWT Strategy for Supabase JWKS (ES256) token verification.
54
+ *
55
+ * Provides shared JWKS client setup, `secretOrKeyProvider` callback,
56
+ * and core payload validation. Each API extends this class with its
57
+ * own `validate()` method to customise the returned user object.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * @Injectable()
62
+ * export class JwtStrategy extends BaseJwtStrategy {
63
+ * constructor(configService: ConfigService) {
64
+ * super(configService);
65
+ * }
66
+ *
67
+ * validate(payload: JwtPayload) {
68
+ * this.validateCorePayload(payload);
69
+ * return { userId: payload.sub, email: payload.email };
70
+ * }
71
+ * }
72
+ * ```
73
+ */
74
+ let BaseJwtStrategy = class BaseJwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
75
+ jwksClient = null;
76
+ constructor(configService) {
77
+ const supabaseUrl = configService.get("storage.supabase.url");
78
+ let jwksClient = null;
79
+ if (supabaseUrl) {
80
+ const jwksUri = `${supabaseUrl}/auth/v1/.well-known/jwks.json`;
81
+ try {
82
+ jwksClient = new jwks_rsa_1.JwksClient({
83
+ jwksUri,
84
+ cache: true,
85
+ cacheMaxAge: 600000, // 10 minutes
86
+ rateLimit: true,
87
+ jwksRequestsPerMinute: 10,
88
+ });
89
+ }
90
+ catch (error) {
91
+ console.warn("Failed to initialize Supabase JWKS client:", error);
92
+ }
93
+ }
94
+ super({
95
+ jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
96
+ ignoreExpiration: false,
97
+ secretOrKeyProvider: async (_request, rawJwtToken, done) => {
98
+ try {
99
+ if (!rawJwtToken) {
100
+ console.error("[JwtStrategy] No JWT token found in request — check that the frontend sends Authorization: Bearer <token>");
101
+ done(new Error("No token provided"));
102
+ return;
103
+ }
104
+ const decoded = jwt.decode(rawJwtToken, { complete: true });
105
+ if (decoded &&
106
+ typeof decoded === "object" &&
107
+ decoded.payload &&
108
+ decoded.header) {
109
+ const header = decoded.header;
110
+ if (jwksClient && header.kid) {
111
+ try {
112
+ const key = await jwksClient.getSigningKey(header.kid);
113
+ const publicKey = key.getPublicKey();
114
+ done(null, publicKey);
115
+ return;
116
+ }
117
+ catch (error) {
118
+ console.error("[JwtStrategy] Failed to get signing key from JWKS:", error);
119
+ done(error);
120
+ return;
121
+ }
122
+ }
123
+ }
124
+ done(new Error("Invalid token or JWKS not available"));
125
+ }
126
+ catch (error) {
127
+ console.error("[JwtStrategy] Unexpected error in secretOrKeyProvider:", error);
128
+ done(error);
129
+ }
130
+ },
131
+ algorithms: ["ES256"],
132
+ });
133
+ this.jwksClient = jwksClient;
134
+ }
135
+ /**
136
+ * Validates core JWT claims shared across all APIs.
137
+ * Call this at the top of your `validate()` method.
138
+ *
139
+ * @throws UnauthorizedException if sub, iat, or exp are missing or token is expired
140
+ */
141
+ validateCorePayload(payload) {
142
+ if (!payload.sub) {
143
+ throw new common_1.UnauthorizedException("Invalid token: missing subject");
144
+ }
145
+ if (!payload.iat) {
146
+ throw new common_1.UnauthorizedException("Invalid token: missing issued at time");
147
+ }
148
+ if (!payload.exp) {
149
+ throw new common_1.UnauthorizedException("Invalid token: missing expiration time");
150
+ }
151
+ const now = Math.floor(Date.now() / 1000);
152
+ if (payload.exp < now) {
153
+ throw new common_1.UnauthorizedException("Token has expired");
154
+ }
155
+ }
156
+ };
157
+ exports.BaseJwtStrategy = BaseJwtStrategy;
158
+ exports.BaseJwtStrategy = BaseJwtStrategy = __decorate([
159
+ (0, common_1.Injectable)(),
160
+ __metadata("design:paramtypes", [config_1.ConfigService])
161
+ ], BaseJwtStrategy);
162
+ //# sourceMappingURL=base-jwt.strategy.js.map