@vritti/api-sdk 0.2.2 → 0.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.
- package/dist/index.cjs +1192 -686
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +146 -4
- package/dist/index.d.ts +146 -4
- package/dist/index.js +1130 -634
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -14,6 +14,225 @@ import { Global, Module } from "@nestjs/common";
|
|
|
14
14
|
import { Inject, Injectable, Scope } from "@nestjs/common";
|
|
15
15
|
import { REQUEST } from "@nestjs/core";
|
|
16
16
|
|
|
17
|
+
// src/exceptions/bad-gateway.exception.ts
|
|
18
|
+
import { HttpStatus } from "@nestjs/common";
|
|
19
|
+
|
|
20
|
+
// src/exceptions/base-field.exception.ts
|
|
21
|
+
import { HttpException } from "@nestjs/common";
|
|
22
|
+
var HttpProblemException = class extends HttpException {
|
|
23
|
+
static {
|
|
24
|
+
__name(this, "HttpProblemException");
|
|
25
|
+
}
|
|
26
|
+
constructor(detailOrOptions, httpStatus) {
|
|
27
|
+
const options = typeof detailOrOptions === "string" ? {
|
|
28
|
+
detail: detailOrOptions
|
|
29
|
+
} : detailOrOptions;
|
|
30
|
+
super({
|
|
31
|
+
type: options.type ?? "about:blank",
|
|
32
|
+
label: options.label,
|
|
33
|
+
detail: options.detail,
|
|
34
|
+
errors: options.errors ?? []
|
|
35
|
+
}, httpStatus);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/exceptions/bad-gateway.exception.ts
|
|
40
|
+
var BadGatewayException = class extends HttpProblemException {
|
|
41
|
+
static {
|
|
42
|
+
__name(this, "BadGatewayException");
|
|
43
|
+
}
|
|
44
|
+
constructor(detailOrOptions) {
|
|
45
|
+
super(detailOrOptions ?? "Bad Gateway", HttpStatus.BAD_GATEWAY);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/exceptions/bad-request.exception.ts
|
|
50
|
+
import { HttpStatus as HttpStatus2 } from "@nestjs/common";
|
|
51
|
+
var BadRequestException = class extends HttpProblemException {
|
|
52
|
+
static {
|
|
53
|
+
__name(this, "BadRequestException");
|
|
54
|
+
}
|
|
55
|
+
constructor(detailOrOptions) {
|
|
56
|
+
super(detailOrOptions ?? "Bad Request", HttpStatus2.BAD_REQUEST);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/exceptions/conflict.exception.ts
|
|
61
|
+
import { HttpStatus as HttpStatus3 } from "@nestjs/common";
|
|
62
|
+
var ConflictException = class extends HttpProblemException {
|
|
63
|
+
static {
|
|
64
|
+
__name(this, "ConflictException");
|
|
65
|
+
}
|
|
66
|
+
constructor(detailOrOptions) {
|
|
67
|
+
super(detailOrOptions ?? "Conflict", HttpStatus3.CONFLICT);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/exceptions/forbidden.exception.ts
|
|
72
|
+
import { HttpStatus as HttpStatus4 } from "@nestjs/common";
|
|
73
|
+
var ForbiddenException = class extends HttpProblemException {
|
|
74
|
+
static {
|
|
75
|
+
__name(this, "ForbiddenException");
|
|
76
|
+
}
|
|
77
|
+
constructor(detailOrOptions) {
|
|
78
|
+
super(detailOrOptions ?? "Forbidden", HttpStatus4.FORBIDDEN);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/exceptions/gone.exception.ts
|
|
83
|
+
import { HttpStatus as HttpStatus5 } from "@nestjs/common";
|
|
84
|
+
var GoneException = class extends HttpProblemException {
|
|
85
|
+
static {
|
|
86
|
+
__name(this, "GoneException");
|
|
87
|
+
}
|
|
88
|
+
constructor(detailOrOptions) {
|
|
89
|
+
super(detailOrOptions ?? "Gone", HttpStatus5.GONE);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/exceptions/internal-server-error.exception.ts
|
|
94
|
+
import { HttpStatus as HttpStatus6 } from "@nestjs/common";
|
|
95
|
+
var InternalServerErrorException = class extends HttpProblemException {
|
|
96
|
+
static {
|
|
97
|
+
__name(this, "InternalServerErrorException");
|
|
98
|
+
}
|
|
99
|
+
constructor(detailOrOptions) {
|
|
100
|
+
super(detailOrOptions ?? "Internal Server Error", HttpStatus6.INTERNAL_SERVER_ERROR);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/exceptions/method-not-allowed.exception.ts
|
|
105
|
+
import { HttpStatus as HttpStatus7 } from "@nestjs/common";
|
|
106
|
+
var MethodNotAllowedException = class extends HttpProblemException {
|
|
107
|
+
static {
|
|
108
|
+
__name(this, "MethodNotAllowedException");
|
|
109
|
+
}
|
|
110
|
+
constructor(detailOrOptions) {
|
|
111
|
+
super(detailOrOptions ?? "Method Not Allowed", HttpStatus7.METHOD_NOT_ALLOWED);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/exceptions/not-acceptable.exception.ts
|
|
116
|
+
import { HttpStatus as HttpStatus8 } from "@nestjs/common";
|
|
117
|
+
var NotAcceptableException = class extends HttpProblemException {
|
|
118
|
+
static {
|
|
119
|
+
__name(this, "NotAcceptableException");
|
|
120
|
+
}
|
|
121
|
+
constructor(detailOrOptions) {
|
|
122
|
+
super(detailOrOptions ?? "Not Acceptable", HttpStatus8.NOT_ACCEPTABLE);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/exceptions/not-found.exception.ts
|
|
127
|
+
import { HttpStatus as HttpStatus9 } from "@nestjs/common";
|
|
128
|
+
var NotFoundException = class extends HttpProblemException {
|
|
129
|
+
static {
|
|
130
|
+
__name(this, "NotFoundException");
|
|
131
|
+
}
|
|
132
|
+
constructor(detailOrOptions) {
|
|
133
|
+
super(detailOrOptions ?? "Not Found", HttpStatus9.NOT_FOUND);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/exceptions/not-implemented.exception.ts
|
|
138
|
+
import { HttpStatus as HttpStatus10 } from "@nestjs/common";
|
|
139
|
+
var NotImplementedException = class extends HttpProblemException {
|
|
140
|
+
static {
|
|
141
|
+
__name(this, "NotImplementedException");
|
|
142
|
+
}
|
|
143
|
+
constructor(detailOrOptions) {
|
|
144
|
+
super(detailOrOptions ?? "Not Implemented", HttpStatus10.NOT_IMPLEMENTED);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/exceptions/payload-too-large.exception.ts
|
|
149
|
+
import { HttpStatus as HttpStatus11 } from "@nestjs/common";
|
|
150
|
+
var PayloadTooLargeException = class extends HttpProblemException {
|
|
151
|
+
static {
|
|
152
|
+
__name(this, "PayloadTooLargeException");
|
|
153
|
+
}
|
|
154
|
+
constructor(detailOrOptions) {
|
|
155
|
+
super(detailOrOptions ?? "Payload Too Large", HttpStatus11.PAYLOAD_TOO_LARGE);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/exceptions/request-timeout.exception.ts
|
|
160
|
+
import { HttpStatus as HttpStatus12 } from "@nestjs/common";
|
|
161
|
+
var RequestTimeoutException = class extends HttpProblemException {
|
|
162
|
+
static {
|
|
163
|
+
__name(this, "RequestTimeoutException");
|
|
164
|
+
}
|
|
165
|
+
constructor(detailOrOptions) {
|
|
166
|
+
super(detailOrOptions ?? "Request Timeout", HttpStatus12.REQUEST_TIMEOUT);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/exceptions/service-unavailable.exception.ts
|
|
171
|
+
import { HttpStatus as HttpStatus13 } from "@nestjs/common";
|
|
172
|
+
var ServiceUnavailableException = class extends HttpProblemException {
|
|
173
|
+
static {
|
|
174
|
+
__name(this, "ServiceUnavailableException");
|
|
175
|
+
}
|
|
176
|
+
constructor(detailOrOptions) {
|
|
177
|
+
super(detailOrOptions ?? "Service Unavailable", HttpStatus13.SERVICE_UNAVAILABLE);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/exceptions/too-many-requests.exception.ts
|
|
182
|
+
import { HttpStatus as HttpStatus14 } from "@nestjs/common";
|
|
183
|
+
var TooManyRequestsException = class extends HttpProblemException {
|
|
184
|
+
static {
|
|
185
|
+
__name(this, "TooManyRequestsException");
|
|
186
|
+
}
|
|
187
|
+
constructor(detailOrOptions) {
|
|
188
|
+
super(detailOrOptions ?? "Too Many Requests", HttpStatus14.TOO_MANY_REQUESTS);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/exceptions/unauthorized.exception.ts
|
|
193
|
+
import { HttpStatus as HttpStatus15 } from "@nestjs/common";
|
|
194
|
+
var UnauthorizedException = class extends HttpProblemException {
|
|
195
|
+
static {
|
|
196
|
+
__name(this, "UnauthorizedException");
|
|
197
|
+
}
|
|
198
|
+
constructor(detailOrOptions) {
|
|
199
|
+
super(detailOrOptions ?? "Unauthorized", HttpStatus15.UNAUTHORIZED);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/exceptions/unprocessable-entity.exception.ts
|
|
204
|
+
import { HttpStatus as HttpStatus16 } from "@nestjs/common";
|
|
205
|
+
var UnprocessableEntityException = class extends HttpProblemException {
|
|
206
|
+
static {
|
|
207
|
+
__name(this, "UnprocessableEntityException");
|
|
208
|
+
}
|
|
209
|
+
constructor(detailOrOptions) {
|
|
210
|
+
super(detailOrOptions ?? "Unprocessable Entity", HttpStatus16.UNPROCESSABLE_ENTITY);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/exceptions/unsupported-media-type.exception.ts
|
|
215
|
+
import { HttpStatus as HttpStatus17 } from "@nestjs/common";
|
|
216
|
+
var UnsupportedMediaTypeException = class extends HttpProblemException {
|
|
217
|
+
static {
|
|
218
|
+
__name(this, "UnsupportedMediaTypeException");
|
|
219
|
+
}
|
|
220
|
+
constructor(detailOrOptions) {
|
|
221
|
+
super(detailOrOptions ?? "Unsupported Media Type", HttpStatus17.UNSUPPORTED_MEDIA_TYPE);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/exceptions/validation.exception.ts
|
|
226
|
+
import { HttpStatus as HttpStatus18 } from "@nestjs/common";
|
|
227
|
+
var ValidationException = class extends HttpProblemException {
|
|
228
|
+
static {
|
|
229
|
+
__name(this, "ValidationException");
|
|
230
|
+
}
|
|
231
|
+
constructor(detailOrOptions) {
|
|
232
|
+
super(detailOrOptions ?? "Validation Failed", HttpStatus18.BAD_REQUEST);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
17
236
|
// src/config/index.ts
|
|
18
237
|
var defaultConfig = {
|
|
19
238
|
cookie: {
|
|
@@ -70,19 +289,36 @@ function resetConfig() {
|
|
|
70
289
|
}
|
|
71
290
|
__name(resetConfig, "resetConfig");
|
|
72
291
|
function getRefreshCookieOptions() {
|
|
73
|
-
|
|
292
|
+
return {
|
|
74
293
|
httpOnly: true,
|
|
75
294
|
secure: currentConfig.cookie.refreshCookieSecure,
|
|
76
295
|
sameSite: currentConfig.cookie.refreshCookieSameSite,
|
|
77
296
|
path: currentConfig.cookie.refreshCookiePath,
|
|
78
|
-
maxAge: currentConfig.cookie.refreshCookieMaxAge
|
|
297
|
+
maxAge: currentConfig.cookie.refreshCookieMaxAge,
|
|
298
|
+
...currentConfig.cookie.refreshCookieDomain && {
|
|
299
|
+
domain: currentConfig.cookie.refreshCookieDomain
|
|
300
|
+
}
|
|
79
301
|
};
|
|
80
|
-
if (currentConfig.cookie.refreshCookieDomain) {
|
|
81
|
-
options.domain = currentConfig.cookie.refreshCookieDomain;
|
|
82
|
-
}
|
|
83
|
-
return options;
|
|
84
302
|
}
|
|
85
303
|
__name(getRefreshCookieOptions, "getRefreshCookieOptions");
|
|
304
|
+
function getRefreshCookieOptionsForHost(hostname) {
|
|
305
|
+
const baseDomain = currentConfig.cookie.refreshCookieDomain;
|
|
306
|
+
if (!baseDomain) {
|
|
307
|
+
throw new Error("refreshCookieDomain must be configured before using getRefreshCookieOptionsForHost");
|
|
308
|
+
}
|
|
309
|
+
if (!hostname.endsWith(`.${baseDomain}`)) {
|
|
310
|
+
throw new UnauthorizedException("Invalid request host.");
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
httpOnly: true,
|
|
314
|
+
secure: currentConfig.cookie.refreshCookieSecure,
|
|
315
|
+
sameSite: currentConfig.cookie.refreshCookieSameSite,
|
|
316
|
+
path: currentConfig.cookie.refreshCookiePath,
|
|
317
|
+
maxAge: currentConfig.cookie.refreshCookieMaxAge,
|
|
318
|
+
domain: hostname
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
__name(getRefreshCookieOptionsForHost, "getRefreshCookieOptionsForHost");
|
|
86
322
|
function getJwtExpiry() {
|
|
87
323
|
return {
|
|
88
324
|
access: currentConfig.jwt.accessTokenExpiry,
|
|
@@ -93,9 +329,9 @@ function getJwtExpiry() {
|
|
|
93
329
|
__name(getJwtExpiry, "getJwtExpiry");
|
|
94
330
|
|
|
95
331
|
// src/request/services/request.service.ts
|
|
96
|
-
function _ts_decorate(decorators, target, key,
|
|
97
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
98
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
332
|
+
function _ts_decorate(decorators, target, key, desc2) {
|
|
333
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
334
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
99
335
|
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;
|
|
100
336
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
101
337
|
}
|
|
@@ -172,9 +408,9 @@ RequestService = _ts_decorate([
|
|
|
172
408
|
], RequestService);
|
|
173
409
|
|
|
174
410
|
// src/request/request.module.ts
|
|
175
|
-
function _ts_decorate2(decorators, target, key,
|
|
176
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
177
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
411
|
+
function _ts_decorate2(decorators, target, key, desc2) {
|
|
412
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
413
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
178
414
|
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;
|
|
179
415
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
180
416
|
}
|
|
@@ -197,7 +433,7 @@ RequestModule = _ts_decorate2([
|
|
|
197
433
|
], RequestModule);
|
|
198
434
|
|
|
199
435
|
// src/auth/guards/vritti-auth.guard.ts
|
|
200
|
-
import { ForbiddenException, Injectable as Injectable2, Logger as Logger2, Scope as Scope2, UnauthorizedException } from "@nestjs/common";
|
|
436
|
+
import { ForbiddenException as ForbiddenException2, Injectable as Injectable2, Logger as Logger2, Scope as Scope2, UnauthorizedException as UnauthorizedException2 } from "@nestjs/common";
|
|
201
437
|
import { SSE_METADATA } from "@nestjs/common/constants";
|
|
202
438
|
import { ConfigService } from "@nestjs/config";
|
|
203
439
|
import { Reflector } from "@nestjs/core";
|
|
@@ -227,9 +463,9 @@ function verifyTokenHash(token, expectedHash) {
|
|
|
227
463
|
__name(verifyTokenHash, "verifyTokenHash");
|
|
228
464
|
|
|
229
465
|
// src/auth/guards/vritti-auth.guard.ts
|
|
230
|
-
function _ts_decorate3(decorators, target, key,
|
|
231
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
232
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
466
|
+
function _ts_decorate3(decorators, target, key, desc2) {
|
|
467
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
468
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
233
469
|
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;
|
|
234
470
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
235
471
|
}
|
|
@@ -285,21 +521,21 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
285
521
|
try {
|
|
286
522
|
const accessToken = this.requestService.getAccessToken();
|
|
287
523
|
if (!accessToken) {
|
|
288
|
-
throw new
|
|
524
|
+
throw new UnauthorizedException2("Access token not found");
|
|
289
525
|
}
|
|
290
526
|
const decodedAccessToken = this.validateAccessToken(accessToken);
|
|
291
527
|
if (decodedAccessToken.tokenType !== "access") {
|
|
292
|
-
throw new
|
|
528
|
+
throw new UnauthorizedException2("Invalid token type");
|
|
293
529
|
}
|
|
294
530
|
this.validateRefreshTokenBinding(decodedAccessToken);
|
|
295
531
|
if (isOnboarding && decodedAccessToken.sessionType !== "ONBOARDING") {
|
|
296
|
-
throw new
|
|
532
|
+
throw new UnauthorizedException2("This endpoint requires an onboarding session");
|
|
297
533
|
}
|
|
298
534
|
if (isReset && decodedAccessToken.sessionType !== "RESET") {
|
|
299
|
-
throw new
|
|
535
|
+
throw new UnauthorizedException2("This endpoint requires a reset session");
|
|
300
536
|
}
|
|
301
537
|
if (!isOnboarding && !isReset && (decodedAccessToken.sessionType === "ONBOARDING" || decodedAccessToken.sessionType === "RESET")) {
|
|
302
|
-
throw new
|
|
538
|
+
throw new UnauthorizedException2(`${decodedAccessToken.sessionType} sessions cannot access this endpoint`);
|
|
303
539
|
}
|
|
304
540
|
request.sessionInfo = {
|
|
305
541
|
userId: decodedAccessToken.userId,
|
|
@@ -308,11 +544,11 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
308
544
|
};
|
|
309
545
|
return true;
|
|
310
546
|
} catch (error) {
|
|
311
|
-
if (error instanceof
|
|
547
|
+
if (error instanceof UnauthorizedException2) {
|
|
312
548
|
throw error;
|
|
313
549
|
}
|
|
314
550
|
this.logger.error("Unexpected error in auth guard", error);
|
|
315
|
-
throw new
|
|
551
|
+
throw new UnauthorizedException2("Authentication failed");
|
|
316
552
|
}
|
|
317
553
|
}
|
|
318
554
|
// Validates JWT signature, expiry, and not-before claims
|
|
@@ -320,50 +556,50 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
320
556
|
try {
|
|
321
557
|
return this.jwtService.verify(token);
|
|
322
558
|
} catch (error) {
|
|
323
|
-
if (error instanceof
|
|
559
|
+
if (error instanceof UnauthorizedException2) throw error;
|
|
324
560
|
const jwtError = error;
|
|
325
561
|
if (jwtError?.name === "TokenExpiredError") {
|
|
326
|
-
throw new
|
|
562
|
+
throw new UnauthorizedException2("Access token has expired");
|
|
327
563
|
}
|
|
328
564
|
if (jwtError?.name === "JsonWebTokenError") {
|
|
329
|
-
throw new
|
|
565
|
+
throw new UnauthorizedException2("Invalid access token");
|
|
330
566
|
}
|
|
331
567
|
if (jwtError?.name === "NotBeforeError") {
|
|
332
|
-
throw new
|
|
568
|
+
throw new UnauthorizedException2("Access token not yet valid");
|
|
333
569
|
}
|
|
334
|
-
throw new
|
|
570
|
+
throw new UnauthorizedException2("Access token validation failed");
|
|
335
571
|
}
|
|
336
572
|
}
|
|
337
573
|
// Validates that the access token is bound to the refresh token in the cookie
|
|
338
574
|
validateRefreshTokenBinding(decodedAccessToken) {
|
|
339
575
|
if (!decodedAccessToken.refreshTokenHash) {
|
|
340
|
-
throw new
|
|
576
|
+
throw new UnauthorizedException2("Token missing refresh token binding");
|
|
341
577
|
}
|
|
342
578
|
const refreshToken = this.requestService.getRefreshToken();
|
|
343
579
|
if (!refreshToken) {
|
|
344
|
-
throw new
|
|
580
|
+
throw new UnauthorizedException2("Session validation failed");
|
|
345
581
|
}
|
|
346
582
|
if (!verifyTokenHash(refreshToken, decodedAccessToken.refreshTokenHash)) {
|
|
347
|
-
throw new
|
|
583
|
+
throw new UnauthorizedException2("Session validation failed");
|
|
348
584
|
}
|
|
349
585
|
}
|
|
350
586
|
// Authenticates SSE connections using the refresh token httpOnly cookie
|
|
351
587
|
handleSseAuth(request, isOnboarding) {
|
|
352
588
|
const refreshToken = this.requestService.getRefreshToken();
|
|
353
589
|
if (!refreshToken) {
|
|
354
|
-
throw new
|
|
590
|
+
throw new UnauthorizedException2("Authentication required");
|
|
355
591
|
}
|
|
356
592
|
let decoded;
|
|
357
593
|
try {
|
|
358
594
|
decoded = this.jwtService.verify(refreshToken);
|
|
359
595
|
} catch {
|
|
360
|
-
throw new
|
|
596
|
+
throw new UnauthorizedException2("Invalid or expired session");
|
|
361
597
|
}
|
|
362
598
|
if (decoded.tokenType !== "refresh") {
|
|
363
|
-
throw new
|
|
599
|
+
throw new UnauthorizedException2("Invalid token type");
|
|
364
600
|
}
|
|
365
601
|
if (isOnboarding && decoded.sessionType !== "ONBOARDING") {
|
|
366
|
-
throw new
|
|
602
|
+
throw new UnauthorizedException2("This endpoint requires an onboarding session");
|
|
367
603
|
}
|
|
368
604
|
request.sessionInfo = {
|
|
369
605
|
userId: decoded.userId,
|
|
@@ -384,7 +620,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
384
620
|
const fastifyInstance = request.server;
|
|
385
621
|
const csrfProtection = fastifyInstance.csrfProtection;
|
|
386
622
|
if (!csrfProtection) {
|
|
387
|
-
throw new
|
|
623
|
+
throw new ForbiddenException2("CSRF protection not configured");
|
|
388
624
|
}
|
|
389
625
|
await new Promise((resolve, reject) => {
|
|
390
626
|
const originalSend = reply.send.bind(reply);
|
|
@@ -400,7 +636,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
400
636
|
});
|
|
401
637
|
});
|
|
402
638
|
} catch (error) {
|
|
403
|
-
throw new
|
|
639
|
+
throw new ForbiddenException2({
|
|
404
640
|
errors: [
|
|
405
641
|
{
|
|
406
642
|
field: "csrf",
|
|
@@ -465,9 +701,9 @@ var TokenType = /* @__PURE__ */ (function(TokenType2) {
|
|
|
465
701
|
})({});
|
|
466
702
|
|
|
467
703
|
// src/auth/services/jwt-auth.service.ts
|
|
468
|
-
function _ts_decorate4(decorators, target, key,
|
|
469
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
470
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
704
|
+
function _ts_decorate4(decorators, target, key, desc2) {
|
|
705
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
706
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
471
707
|
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;
|
|
472
708
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
473
709
|
}
|
|
@@ -548,9 +784,9 @@ JwtAuthService = _ts_decorate4([
|
|
|
548
784
|
], JwtAuthService);
|
|
549
785
|
|
|
550
786
|
// src/auth/auth-config.module.ts
|
|
551
|
-
function _ts_decorate5(decorators, target, key,
|
|
552
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
553
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
787
|
+
function _ts_decorate5(decorators, target, key, desc2) {
|
|
788
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
789
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
554
790
|
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;
|
|
555
791
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
556
792
|
}
|
|
@@ -613,6 +849,18 @@ var AccessToken = createParamDecorator((_data, ctx) => {
|
|
|
613
849
|
return authHeader?.replace("Bearer ", "") || "";
|
|
614
850
|
});
|
|
615
851
|
|
|
852
|
+
// src/auth/decorators/cookie-domain.decorator.ts
|
|
853
|
+
import { createParamDecorator as createParamDecorator2 } from "@nestjs/common";
|
|
854
|
+
var CookieDomain = createParamDecorator2((_data, ctx) => {
|
|
855
|
+
const request = ctx.switchToHttp().getRequest();
|
|
856
|
+
const forwarded = request.headers["x-forwarded-host"];
|
|
857
|
+
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
858
|
+
const hostStr = raw ?? request.hostname;
|
|
859
|
+
const domain = hostStr.split(":")[0] ?? hostStr;
|
|
860
|
+
const baseDomain = getConfig().cookie.refreshCookieDomain ?? "";
|
|
861
|
+
return domain.endsWith(`.${baseDomain}`) ? domain : baseDomain;
|
|
862
|
+
});
|
|
863
|
+
|
|
616
864
|
// src/auth/decorators/onboarding.decorator.ts
|
|
617
865
|
import { SetMetadata as SetMetadata3 } from "@nestjs/common";
|
|
618
866
|
var Onboarding = /* @__PURE__ */ __name(() => SetMetadata3("isOnboarding", true), "Onboarding");
|
|
@@ -621,9 +869,20 @@ var Onboarding = /* @__PURE__ */ __name(() => SetMetadata3("isOnboarding", true)
|
|
|
621
869
|
import { SetMetadata as SetMetadata4 } from "@nestjs/common";
|
|
622
870
|
var Public = /* @__PURE__ */ __name(() => SetMetadata4("isPublic", true), "Public");
|
|
623
871
|
|
|
872
|
+
// src/auth/decorators/refresh-cookie-options.decorator.ts
|
|
873
|
+
import { createParamDecorator as createParamDecorator3 } from "@nestjs/common";
|
|
874
|
+
var RefreshCookieOptions = createParamDecorator3((_data, ctx) => {
|
|
875
|
+
const request = ctx.switchToHttp().getRequest();
|
|
876
|
+
const forwarded = request.headers["x-forwarded-host"];
|
|
877
|
+
const raw = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
878
|
+
const hostStr = raw ?? request.hostname;
|
|
879
|
+
const domain = hostStr.split(":")[0] ?? hostStr;
|
|
880
|
+
return getRefreshCookieOptionsForHost(domain);
|
|
881
|
+
});
|
|
882
|
+
|
|
624
883
|
// src/auth/decorators/refresh-token-cookie.decorator.ts
|
|
625
|
-
import { createParamDecorator as
|
|
626
|
-
var RefreshTokenCookie =
|
|
884
|
+
import { createParamDecorator as createParamDecorator4 } from "@nestjs/common";
|
|
885
|
+
var RefreshTokenCookie = createParamDecorator4((_data, ctx) => {
|
|
627
886
|
const request = ctx.switchToHttp().getRequest();
|
|
628
887
|
const cookies = request.cookies ?? {};
|
|
629
888
|
const config = getConfig();
|
|
@@ -631,8 +890,8 @@ var RefreshTokenCookie = createParamDecorator2((_data, ctx) => {
|
|
|
631
890
|
});
|
|
632
891
|
|
|
633
892
|
// src/auth/decorators/session-data.decorator.ts
|
|
634
|
-
import { createParamDecorator as
|
|
635
|
-
var SessionData =
|
|
893
|
+
import { createParamDecorator as createParamDecorator5 } from "@nestjs/common";
|
|
894
|
+
var SessionData = createParamDecorator5((_data, ctx) => {
|
|
636
895
|
const request = ctx.switchToHttp().getRequest();
|
|
637
896
|
const sessionInfo = request.sessionInfo;
|
|
638
897
|
if (!sessionInfo?.sessionId) {
|
|
@@ -646,8 +905,8 @@ var SessionData = createParamDecorator3((_data, ctx) => {
|
|
|
646
905
|
});
|
|
647
906
|
|
|
648
907
|
// src/auth/decorators/user-id.decorator.ts
|
|
649
|
-
import { createParamDecorator as
|
|
650
|
-
var UserId =
|
|
908
|
+
import { createParamDecorator as createParamDecorator6 } from "@nestjs/common";
|
|
909
|
+
var UserId = createParamDecorator6((_data, ctx) => {
|
|
651
910
|
const request = ctx.switchToHttp().getRequest();
|
|
652
911
|
const sessionInfo = request.sessionInfo;
|
|
653
912
|
if (!sessionInfo?.userId) {
|
|
@@ -656,21 +915,20 @@ var UserId = createParamDecorator4((_data, ctx) => {
|
|
|
656
915
|
return sessionInfo.userId;
|
|
657
916
|
});
|
|
658
917
|
|
|
659
|
-
// src/
|
|
660
|
-
import {
|
|
661
|
-
import {
|
|
918
|
+
// src/cache/cache.module.ts
|
|
919
|
+
import { Module as Module3 } from "@nestjs/common";
|
|
920
|
+
import { ConfigModule as ConfigModule2 } from "@nestjs/config";
|
|
662
921
|
|
|
663
|
-
// src/
|
|
664
|
-
|
|
922
|
+
// src/cache/cache.service.ts
|
|
923
|
+
import { Inject as Inject2, Injectable as Injectable4, Logger as Logger4 } from "@nestjs/common";
|
|
665
924
|
|
|
666
|
-
// src/
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
925
|
+
// src/cache/constants.ts
|
|
926
|
+
var CACHE_PROVIDER = Symbol("CACHE_PROVIDER");
|
|
927
|
+
|
|
928
|
+
// src/cache/cache.service.ts
|
|
929
|
+
function _ts_decorate6(decorators, target, key, desc2) {
|
|
930
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
931
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
674
932
|
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;
|
|
675
933
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
676
934
|
}
|
|
@@ -685,14 +943,220 @@ function _ts_param2(paramIndex, decorator) {
|
|
|
685
943
|
};
|
|
686
944
|
}
|
|
687
945
|
__name(_ts_param2, "_ts_param");
|
|
688
|
-
var
|
|
946
|
+
var CacheService = class _CacheService {
|
|
689
947
|
static {
|
|
690
|
-
__name(this, "
|
|
948
|
+
__name(this, "CacheService");
|
|
691
949
|
}
|
|
692
|
-
|
|
693
|
-
logger = new Logger4(
|
|
694
|
-
|
|
695
|
-
|
|
950
|
+
provider;
|
|
951
|
+
logger = new Logger4(_CacheService.name);
|
|
952
|
+
constructor(provider) {
|
|
953
|
+
this.provider = provider;
|
|
954
|
+
}
|
|
955
|
+
// Stores a value with mandatory TTL — errors are logged and swallowed so DB writes still succeed
|
|
956
|
+
async set(key, value, ttlSeconds) {
|
|
957
|
+
try {
|
|
958
|
+
await this.provider.set(key, value, ttlSeconds);
|
|
959
|
+
} catch (err) {
|
|
960
|
+
this.logger.error(`Cache set failed for key "${key}"`, err);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
// Returns cached value or null on miss or any Redis error — callers fall back to DB
|
|
964
|
+
async get(key) {
|
|
965
|
+
try {
|
|
966
|
+
return await this.provider.get(key);
|
|
967
|
+
} catch (err) {
|
|
968
|
+
this.logger.error(`Cache get failed for key "${key}"`, err);
|
|
969
|
+
return null;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
// Deletes one or more keys — errors are logged and swallowed
|
|
973
|
+
async del(...keys) {
|
|
974
|
+
try {
|
|
975
|
+
await this.provider.del(...keys);
|
|
976
|
+
} catch (err) {
|
|
977
|
+
this.logger.error(`Cache del failed for keys "${keys.join(", ")}"`, err);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
// Returns all keys matching a glob pattern — returns empty array on error
|
|
981
|
+
async scanKeys(pattern) {
|
|
982
|
+
try {
|
|
983
|
+
return await this.provider.scanKeys(pattern);
|
|
984
|
+
} catch (err) {
|
|
985
|
+
this.logger.error(`Cache scanKeys failed for pattern "${pattern}"`, err);
|
|
986
|
+
return [];
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
// Returns raw memory info from the provider — returns empty string on error
|
|
990
|
+
async getMemoryInfo() {
|
|
991
|
+
try {
|
|
992
|
+
return await this.provider.getMemoryInfo();
|
|
993
|
+
} catch (err) {
|
|
994
|
+
this.logger.error("Cache getMemoryInfo failed", err);
|
|
995
|
+
return "";
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
CacheService = _ts_decorate6([
|
|
1000
|
+
Injectable4(),
|
|
1001
|
+
_ts_param2(0, Inject2(CACHE_PROVIDER)),
|
|
1002
|
+
_ts_metadata4("design:type", Function),
|
|
1003
|
+
_ts_metadata4("design:paramtypes", [
|
|
1004
|
+
typeof ICacheProvider === "undefined" ? Object : ICacheProvider
|
|
1005
|
+
])
|
|
1006
|
+
], CacheService);
|
|
1007
|
+
|
|
1008
|
+
// src/cache/providers/redis.provider.ts
|
|
1009
|
+
import { Injectable as Injectable5, Logger as Logger5 } from "@nestjs/common";
|
|
1010
|
+
import { ConfigService as ConfigService4 } from "@nestjs/config";
|
|
1011
|
+
import Redis from "ioredis";
|
|
1012
|
+
function _ts_decorate7(decorators, target, key, desc2) {
|
|
1013
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1014
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1015
|
+
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;
|
|
1016
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1017
|
+
}
|
|
1018
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
1019
|
+
function _ts_metadata5(k, v) {
|
|
1020
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1021
|
+
}
|
|
1022
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
1023
|
+
var RedisCacheProvider = class _RedisCacheProvider {
|
|
1024
|
+
static {
|
|
1025
|
+
__name(this, "RedisCacheProvider");
|
|
1026
|
+
}
|
|
1027
|
+
configService;
|
|
1028
|
+
logger = new Logger5(_RedisCacheProvider.name);
|
|
1029
|
+
client;
|
|
1030
|
+
constructor(configService) {
|
|
1031
|
+
this.configService = configService;
|
|
1032
|
+
}
|
|
1033
|
+
// Creates the ioredis client and attaches connection/error listeners
|
|
1034
|
+
onModuleInit() {
|
|
1035
|
+
const url = this.configService.getOrThrow("REDIS_URL");
|
|
1036
|
+
this.client = new Redis(url, {
|
|
1037
|
+
lazyConnect: true,
|
|
1038
|
+
maxRetriesPerRequest: 3
|
|
1039
|
+
});
|
|
1040
|
+
this.client.on("connect", () => this.logger.log("Redis connected"));
|
|
1041
|
+
this.client.on("error", (err) => this.logger.error("Redis error", err));
|
|
1042
|
+
}
|
|
1043
|
+
// Gracefully closes the ioredis connection on app shutdown
|
|
1044
|
+
async onModuleDestroy() {
|
|
1045
|
+
await this.client.quit();
|
|
1046
|
+
this.logger.log("Redis disconnected");
|
|
1047
|
+
}
|
|
1048
|
+
// Serializes value to JSON and stores with a mandatory TTL
|
|
1049
|
+
async set(key, value, ttlSeconds) {
|
|
1050
|
+
const json = JSON.stringify(value);
|
|
1051
|
+
await this.client.setex(key, ttlSeconds, json);
|
|
1052
|
+
}
|
|
1053
|
+
// Reads the stored JSON string and parses back to the original type
|
|
1054
|
+
async get(key) {
|
|
1055
|
+
const json = await this.client.get(key);
|
|
1056
|
+
if (!json) return null;
|
|
1057
|
+
return JSON.parse(json);
|
|
1058
|
+
}
|
|
1059
|
+
// Deletes one or more keys in a single command
|
|
1060
|
+
async del(...keys) {
|
|
1061
|
+
if (keys.length > 0) {
|
|
1062
|
+
await this.client.del(...keys);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
// Cursor-iterates all keys matching a glob pattern — never uses KEYS command
|
|
1066
|
+
async scanKeys(pattern) {
|
|
1067
|
+
const keys = [];
|
|
1068
|
+
let cursor = "0";
|
|
1069
|
+
do {
|
|
1070
|
+
const [nextCursor, batch] = await this.client.scan(cursor, "MATCH", pattern, "COUNT", 100);
|
|
1071
|
+
cursor = nextCursor;
|
|
1072
|
+
keys.push(...batch);
|
|
1073
|
+
} while (cursor !== "0");
|
|
1074
|
+
return keys;
|
|
1075
|
+
}
|
|
1076
|
+
// Returns raw INFO memory output for memory monitoring
|
|
1077
|
+
async getMemoryInfo() {
|
|
1078
|
+
return this.client.info("memory");
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
RedisCacheProvider = _ts_decorate7([
|
|
1082
|
+
Injectable5(),
|
|
1083
|
+
_ts_metadata5("design:type", Function),
|
|
1084
|
+
_ts_metadata5("design:paramtypes", [
|
|
1085
|
+
typeof ConfigService4 === "undefined" ? Object : ConfigService4
|
|
1086
|
+
])
|
|
1087
|
+
], RedisCacheProvider);
|
|
1088
|
+
|
|
1089
|
+
// src/cache/cache.module.ts
|
|
1090
|
+
function _ts_decorate8(decorators, target, key, desc2) {
|
|
1091
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1092
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1093
|
+
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;
|
|
1094
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1095
|
+
}
|
|
1096
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1097
|
+
var CacheModule = class {
|
|
1098
|
+
static {
|
|
1099
|
+
__name(this, "CacheModule");
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
CacheModule = _ts_decorate8([
|
|
1103
|
+
Module3({
|
|
1104
|
+
imports: [
|
|
1105
|
+
ConfigModule2
|
|
1106
|
+
],
|
|
1107
|
+
providers: [
|
|
1108
|
+
RedisCacheProvider,
|
|
1109
|
+
{
|
|
1110
|
+
provide: CACHE_PROVIDER,
|
|
1111
|
+
useExisting: RedisCacheProvider
|
|
1112
|
+
},
|
|
1113
|
+
CacheService
|
|
1114
|
+
],
|
|
1115
|
+
exports: [
|
|
1116
|
+
RedisCacheProvider,
|
|
1117
|
+
CACHE_PROVIDER,
|
|
1118
|
+
CacheService
|
|
1119
|
+
]
|
|
1120
|
+
})
|
|
1121
|
+
], CacheModule);
|
|
1122
|
+
|
|
1123
|
+
// src/database/database.module.ts
|
|
1124
|
+
import { Global as Global3, Module as Module4 } from "@nestjs/common";
|
|
1125
|
+
import { Reflector as Reflector3 } from "@nestjs/core";
|
|
1126
|
+
|
|
1127
|
+
// src/database/constants.ts
|
|
1128
|
+
var DATABASE_MODULE_OPTIONS = Symbol("DATABASE_MODULE_OPTIONS");
|
|
1129
|
+
|
|
1130
|
+
// src/database/services/primary-database.service.ts
|
|
1131
|
+
import { Inject as Inject3, Injectable as Injectable6, InternalServerErrorException as InternalServerErrorException2, Logger as Logger6 } from "@nestjs/common";
|
|
1132
|
+
import { eq, or } from "drizzle-orm";
|
|
1133
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
1134
|
+
import { Pool } from "pg";
|
|
1135
|
+
function _ts_decorate9(decorators, target, key, desc2) {
|
|
1136
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1137
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1138
|
+
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;
|
|
1139
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1140
|
+
}
|
|
1141
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1142
|
+
function _ts_metadata6(k, v) {
|
|
1143
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1144
|
+
}
|
|
1145
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
1146
|
+
function _ts_param3(paramIndex, decorator) {
|
|
1147
|
+
return function(target, key) {
|
|
1148
|
+
decorator(target, key, paramIndex);
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
__name(_ts_param3, "_ts_param");
|
|
1152
|
+
var PrimaryDatabaseService = class _PrimaryDatabaseService {
|
|
1153
|
+
static {
|
|
1154
|
+
__name(this, "PrimaryDatabaseService");
|
|
1155
|
+
}
|
|
1156
|
+
options;
|
|
1157
|
+
logger = new Logger6(_PrimaryDatabaseService.name);
|
|
1158
|
+
pool = null;
|
|
1159
|
+
db = null;
|
|
696
1160
|
tenantConfigCache = /* @__PURE__ */ new Map();
|
|
697
1161
|
cacheTTL;
|
|
698
1162
|
constructor(options) {
|
|
@@ -724,7 +1188,7 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
|
|
|
724
1188
|
this.logger.log("Connected to primary database (tenant registry)");
|
|
725
1189
|
} catch (error) {
|
|
726
1190
|
this.logger.error("Failed to connect to primary database", error);
|
|
727
|
-
throw new
|
|
1191
|
+
throw new InternalServerErrorException2("Failed to initialize tenant registry");
|
|
728
1192
|
}
|
|
729
1193
|
}
|
|
730
1194
|
// Builds the PostgreSQL connection URL from primary database config properties
|
|
@@ -796,7 +1260,7 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
|
|
|
796
1260
|
return info;
|
|
797
1261
|
} catch (error) {
|
|
798
1262
|
this.logger.error(`Failed to fetch tenant info: ${tenantIdentifier}`, error);
|
|
799
|
-
throw new
|
|
1263
|
+
throw new InternalServerErrorException2("Failed to resolve tenant");
|
|
800
1264
|
}
|
|
801
1265
|
}
|
|
802
1266
|
// Caches tenant info by both ID and subdomain with TTL expiration
|
|
@@ -846,24 +1310,24 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
|
|
|
846
1310
|
}
|
|
847
1311
|
}
|
|
848
1312
|
};
|
|
849
|
-
PrimaryDatabaseService =
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
1313
|
+
PrimaryDatabaseService = _ts_decorate9([
|
|
1314
|
+
Injectable6(),
|
|
1315
|
+
_ts_param3(0, Inject3(DATABASE_MODULE_OPTIONS)),
|
|
1316
|
+
_ts_metadata6("design:type", Function),
|
|
1317
|
+
_ts_metadata6("design:paramtypes", [
|
|
854
1318
|
typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions
|
|
855
1319
|
])
|
|
856
1320
|
], PrimaryDatabaseService);
|
|
857
1321
|
|
|
858
1322
|
// src/database/services/tenant-context.service.ts
|
|
859
|
-
import { Injectable as
|
|
860
|
-
function
|
|
861
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
862
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1323
|
+
import { Injectable as Injectable7, Scope as Scope3, UnauthorizedException as UnauthorizedException3 } from "@nestjs/common";
|
|
1324
|
+
function _ts_decorate10(decorators, target, key, desc2) {
|
|
1325
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1326
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
863
1327
|
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;
|
|
864
1328
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
865
1329
|
}
|
|
866
|
-
__name(
|
|
1330
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
867
1331
|
var TenantContextService = class {
|
|
868
1332
|
static {
|
|
869
1333
|
__name(this, "TenantContextService");
|
|
@@ -879,7 +1343,7 @@ var TenantContextService = class {
|
|
|
879
1343
|
// Returns the tenant info for this request, throwing if context is not set
|
|
880
1344
|
getTenant() {
|
|
881
1345
|
if (!this.tenantInfo) {
|
|
882
|
-
throw new
|
|
1346
|
+
throw new UnauthorizedException3("Tenant context not set");
|
|
883
1347
|
}
|
|
884
1348
|
return this.tenantInfo;
|
|
885
1349
|
}
|
|
@@ -900,40 +1364,40 @@ var TenantContextService = class {
|
|
|
900
1364
|
return this.tenantInfo?.subdomain ?? null;
|
|
901
1365
|
}
|
|
902
1366
|
};
|
|
903
|
-
TenantContextService =
|
|
904
|
-
|
|
1367
|
+
TenantContextService = _ts_decorate10([
|
|
1368
|
+
Injectable7({
|
|
905
1369
|
scope: Scope3.REQUEST
|
|
906
1370
|
})
|
|
907
1371
|
], TenantContextService);
|
|
908
1372
|
|
|
909
1373
|
// src/database/services/tenant-database.service.ts
|
|
910
|
-
import { Inject as
|
|
1374
|
+
import { Inject as Inject4, Injectable as Injectable8, InternalServerErrorException as InternalServerErrorException3, Logger as Logger7 } from "@nestjs/common";
|
|
911
1375
|
import { drizzle as drizzle2 } from "drizzle-orm/node-postgres";
|
|
912
1376
|
import { Pool as Pool2 } from "pg";
|
|
913
|
-
function
|
|
914
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
915
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1377
|
+
function _ts_decorate11(decorators, target, key, desc2) {
|
|
1378
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1379
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
916
1380
|
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;
|
|
917
1381
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
918
1382
|
}
|
|
919
|
-
__name(
|
|
920
|
-
function
|
|
1383
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1384
|
+
function _ts_metadata7(k, v) {
|
|
921
1385
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
922
1386
|
}
|
|
923
|
-
__name(
|
|
924
|
-
function
|
|
1387
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
1388
|
+
function _ts_param4(paramIndex, decorator) {
|
|
925
1389
|
return function(target, key) {
|
|
926
1390
|
decorator(target, key, paramIndex);
|
|
927
1391
|
};
|
|
928
1392
|
}
|
|
929
|
-
__name(
|
|
1393
|
+
__name(_ts_param4, "_ts_param");
|
|
930
1394
|
var TenantDatabaseService = class _TenantDatabaseService {
|
|
931
1395
|
static {
|
|
932
1396
|
__name(this, "TenantDatabaseService");
|
|
933
1397
|
}
|
|
934
1398
|
options;
|
|
935
1399
|
tenantContext;
|
|
936
|
-
logger = new
|
|
1400
|
+
logger = new Logger7(_TenantDatabaseService.name);
|
|
937
1401
|
clients = /* @__PURE__ */ new Map();
|
|
938
1402
|
clientLastUsed = /* @__PURE__ */ new Map();
|
|
939
1403
|
cleanupInterval;
|
|
@@ -985,7 +1449,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
985
1449
|
};
|
|
986
1450
|
} catch (error) {
|
|
987
1451
|
this.logger.error(`Failed to create database connection for tenant: ${tenant.subdomain}`, error);
|
|
988
|
-
throw new
|
|
1452
|
+
throw new InternalServerErrorException3("Failed to connect to tenant database");
|
|
989
1453
|
}
|
|
990
1454
|
}
|
|
991
1455
|
// Builds the PostgreSQL connection URL for a dedicated tenant database
|
|
@@ -1065,24 +1529,24 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1065
1529
|
this.logger.log("All database connections closed");
|
|
1066
1530
|
}
|
|
1067
1531
|
};
|
|
1068
|
-
TenantDatabaseService =
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1532
|
+
TenantDatabaseService = _ts_decorate11([
|
|
1533
|
+
Injectable8(),
|
|
1534
|
+
_ts_param4(0, Inject4(DATABASE_MODULE_OPTIONS)),
|
|
1535
|
+
_ts_metadata7("design:type", Function),
|
|
1536
|
+
_ts_metadata7("design:paramtypes", [
|
|
1073
1537
|
typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions,
|
|
1074
1538
|
typeof TenantContextService === "undefined" ? Object : TenantContextService
|
|
1075
1539
|
])
|
|
1076
1540
|
], TenantDatabaseService);
|
|
1077
1541
|
|
|
1078
1542
|
// src/database/database.module.ts
|
|
1079
|
-
function
|
|
1080
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1081
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1543
|
+
function _ts_decorate12(decorators, target, key, desc2) {
|
|
1544
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1545
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1082
1546
|
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;
|
|
1083
1547
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1084
1548
|
}
|
|
1085
|
-
__name(
|
|
1549
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1086
1550
|
var DatabaseModule = class _DatabaseModule {
|
|
1087
1551
|
static {
|
|
1088
1552
|
__name(this, "DatabaseModule");
|
|
@@ -1128,14 +1592,14 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1128
1592
|
};
|
|
1129
1593
|
}
|
|
1130
1594
|
};
|
|
1131
|
-
DatabaseModule =
|
|
1595
|
+
DatabaseModule = _ts_decorate12([
|
|
1132
1596
|
Global3(),
|
|
1133
|
-
|
|
1597
|
+
Module4({})
|
|
1134
1598
|
], DatabaseModule);
|
|
1135
1599
|
|
|
1136
1600
|
// src/database/decorators/tenant.decorator.ts
|
|
1137
|
-
import { createParamDecorator as
|
|
1138
|
-
var Tenant =
|
|
1601
|
+
import { createParamDecorator as createParamDecorator7 } from "@nestjs/common";
|
|
1602
|
+
var Tenant = createParamDecorator7((_data, ctx) => {
|
|
1139
1603
|
const request = ctx.switchToHttp().getRequest();
|
|
1140
1604
|
const tenantContext = request.app?.get?.(TenantContextService);
|
|
1141
1605
|
if (!tenantContext) {
|
|
@@ -1148,17 +1612,17 @@ var Tenant = createParamDecorator5((_data, ctx) => {
|
|
|
1148
1612
|
import { ApiPropertyOptional } from "@nestjs/swagger";
|
|
1149
1613
|
import { Type } from "class-transformer";
|
|
1150
1614
|
import { IsInt, IsOptional, IsString, Min } from "class-validator";
|
|
1151
|
-
function
|
|
1152
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1153
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
1615
|
+
function _ts_decorate13(decorators, target, key, desc2) {
|
|
1616
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1617
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1154
1618
|
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;
|
|
1155
1619
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1156
1620
|
}
|
|
1157
|
-
__name(
|
|
1158
|
-
function
|
|
1621
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1622
|
+
function _ts_metadata8(k, v) {
|
|
1159
1623
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1160
1624
|
}
|
|
1161
|
-
__name(
|
|
1625
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
1162
1626
|
var SelectOptionsQueryDto = class {
|
|
1163
1627
|
static {
|
|
1164
1628
|
__name(this, "SelectOptionsQueryDto");
|
|
@@ -1170,18 +1634,19 @@ var SelectOptionsQueryDto = class {
|
|
|
1170
1634
|
excludeIds;
|
|
1171
1635
|
valueKey;
|
|
1172
1636
|
labelKey;
|
|
1637
|
+
descriptionKey;
|
|
1173
1638
|
groupIdKey;
|
|
1174
1639
|
};
|
|
1175
|
-
|
|
1640
|
+
_ts_decorate13([
|
|
1176
1641
|
ApiPropertyOptional({
|
|
1177
1642
|
description: "Search term to filter by label",
|
|
1178
1643
|
example: "united"
|
|
1179
1644
|
}),
|
|
1180
1645
|
IsOptional(),
|
|
1181
1646
|
IsString(),
|
|
1182
|
-
|
|
1647
|
+
_ts_metadata8("design:type", String)
|
|
1183
1648
|
], SelectOptionsQueryDto.prototype, "search", void 0);
|
|
1184
|
-
|
|
1649
|
+
_ts_decorate13([
|
|
1185
1650
|
ApiPropertyOptional({
|
|
1186
1651
|
description: "Maximum number of results",
|
|
1187
1652
|
example: 20,
|
|
@@ -1191,9 +1656,9 @@ _ts_decorate10([
|
|
|
1191
1656
|
Type(() => Number),
|
|
1192
1657
|
IsInt(),
|
|
1193
1658
|
Min(1),
|
|
1194
|
-
|
|
1659
|
+
_ts_metadata8("design:type", Number)
|
|
1195
1660
|
], SelectOptionsQueryDto.prototype, "limit", void 0);
|
|
1196
|
-
|
|
1661
|
+
_ts_decorate13([
|
|
1197
1662
|
ApiPropertyOptional({
|
|
1198
1663
|
description: "Number of results to skip",
|
|
1199
1664
|
example: 0,
|
|
@@ -1203,27 +1668,27 @@ _ts_decorate10([
|
|
|
1203
1668
|
Type(() => Number),
|
|
1204
1669
|
IsInt(),
|
|
1205
1670
|
Min(0),
|
|
1206
|
-
|
|
1671
|
+
_ts_metadata8("design:type", Number)
|
|
1207
1672
|
], SelectOptionsQueryDto.prototype, "offset", void 0);
|
|
1208
|
-
|
|
1673
|
+
_ts_decorate13([
|
|
1209
1674
|
ApiPropertyOptional({
|
|
1210
1675
|
description: "Comma-separated values to fetch specific options",
|
|
1211
1676
|
example: "1,2,3"
|
|
1212
1677
|
}),
|
|
1213
1678
|
IsOptional(),
|
|
1214
1679
|
IsString(),
|
|
1215
|
-
|
|
1680
|
+
_ts_metadata8("design:type", String)
|
|
1216
1681
|
], SelectOptionsQueryDto.prototype, "values", void 0);
|
|
1217
|
-
|
|
1682
|
+
_ts_decorate13([
|
|
1218
1683
|
ApiPropertyOptional({
|
|
1219
1684
|
description: "Comma-separated IDs to exclude from results (already selected)",
|
|
1220
1685
|
example: "5,10"
|
|
1221
1686
|
}),
|
|
1222
1687
|
IsOptional(),
|
|
1223
1688
|
IsString(),
|
|
1224
|
-
|
|
1689
|
+
_ts_metadata8("design:type", String)
|
|
1225
1690
|
], SelectOptionsQueryDto.prototype, "excludeIds", void 0);
|
|
1226
|
-
|
|
1691
|
+
_ts_decorate13([
|
|
1227
1692
|
ApiPropertyOptional({
|
|
1228
1693
|
description: "Column name for option value",
|
|
1229
1694
|
example: "id",
|
|
@@ -1231,9 +1696,9 @@ _ts_decorate10([
|
|
|
1231
1696
|
}),
|
|
1232
1697
|
IsOptional(),
|
|
1233
1698
|
IsString(),
|
|
1234
|
-
|
|
1699
|
+
_ts_metadata8("design:type", String)
|
|
1235
1700
|
], SelectOptionsQueryDto.prototype, "valueKey", void 0);
|
|
1236
|
-
|
|
1701
|
+
_ts_decorate13([
|
|
1237
1702
|
ApiPropertyOptional({
|
|
1238
1703
|
description: "Column name for option label",
|
|
1239
1704
|
example: "name",
|
|
@@ -1241,21 +1706,193 @@ _ts_decorate10([
|
|
|
1241
1706
|
}),
|
|
1242
1707
|
IsOptional(),
|
|
1243
1708
|
IsString(),
|
|
1244
|
-
|
|
1709
|
+
_ts_metadata8("design:type", String)
|
|
1245
1710
|
], SelectOptionsQueryDto.prototype, "labelKey", void 0);
|
|
1246
|
-
|
|
1711
|
+
_ts_decorate13([
|
|
1712
|
+
ApiPropertyOptional({
|
|
1713
|
+
description: "Column name for option description",
|
|
1714
|
+
example: "description"
|
|
1715
|
+
}),
|
|
1716
|
+
IsOptional(),
|
|
1717
|
+
IsString(),
|
|
1718
|
+
_ts_metadata8("design:type", String)
|
|
1719
|
+
], SelectOptionsQueryDto.prototype, "descriptionKey", void 0);
|
|
1720
|
+
_ts_decorate13([
|
|
1247
1721
|
ApiPropertyOptional({
|
|
1248
1722
|
description: "Column name for group ID",
|
|
1249
1723
|
example: "regionId"
|
|
1250
1724
|
}),
|
|
1251
1725
|
IsOptional(),
|
|
1252
1726
|
IsString(),
|
|
1253
|
-
|
|
1727
|
+
_ts_metadata8("design:type", String)
|
|
1254
1728
|
], SelectOptionsQueryDto.prototype, "groupIdKey", void 0);
|
|
1255
1729
|
|
|
1730
|
+
// src/database/dto/success-response.dto.ts
|
|
1731
|
+
import { ApiProperty } from "@nestjs/swagger";
|
|
1732
|
+
import { IsBoolean, IsNotEmpty, IsString as IsString2 } from "class-validator";
|
|
1733
|
+
function _ts_decorate14(decorators, target, key, desc2) {
|
|
1734
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1735
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1736
|
+
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;
|
|
1737
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1738
|
+
}
|
|
1739
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
1740
|
+
function _ts_metadata9(k, v) {
|
|
1741
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1742
|
+
}
|
|
1743
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1744
|
+
var SuccessResponseDto = class {
|
|
1745
|
+
static {
|
|
1746
|
+
__name(this, "SuccessResponseDto");
|
|
1747
|
+
}
|
|
1748
|
+
success;
|
|
1749
|
+
message;
|
|
1750
|
+
};
|
|
1751
|
+
_ts_decorate14([
|
|
1752
|
+
ApiProperty({
|
|
1753
|
+
example: true
|
|
1754
|
+
}),
|
|
1755
|
+
IsNotEmpty(),
|
|
1756
|
+
IsBoolean(),
|
|
1757
|
+
_ts_metadata9("design:type", Boolean)
|
|
1758
|
+
], SuccessResponseDto.prototype, "success", void 0);
|
|
1759
|
+
_ts_decorate14([
|
|
1760
|
+
ApiProperty({
|
|
1761
|
+
example: "Operation completed successfully"
|
|
1762
|
+
}),
|
|
1763
|
+
IsNotEmpty(),
|
|
1764
|
+
IsString2(),
|
|
1765
|
+
_ts_metadata9("design:type", String)
|
|
1766
|
+
], SuccessResponseDto.prototype, "message", void 0);
|
|
1767
|
+
|
|
1768
|
+
// src/database/dto/table-response.dto.ts
|
|
1769
|
+
import { ApiProperty as ApiProperty2, ApiPropertyOptional as ApiPropertyOptional2 } from "@nestjs/swagger";
|
|
1770
|
+
function _ts_decorate15(decorators, target, key, desc2) {
|
|
1771
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
1772
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1773
|
+
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;
|
|
1774
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1775
|
+
}
|
|
1776
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
1777
|
+
function _ts_metadata10(k, v) {
|
|
1778
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1779
|
+
}
|
|
1780
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
1781
|
+
var TableResponseDto = class {
|
|
1782
|
+
static {
|
|
1783
|
+
__name(this, "TableResponseDto");
|
|
1784
|
+
}
|
|
1785
|
+
result;
|
|
1786
|
+
count;
|
|
1787
|
+
state;
|
|
1788
|
+
activeViewId;
|
|
1789
|
+
};
|
|
1790
|
+
_ts_decorate15([
|
|
1791
|
+
ApiProperty2(),
|
|
1792
|
+
_ts_metadata10("design:type", Array)
|
|
1793
|
+
], TableResponseDto.prototype, "result", void 0);
|
|
1794
|
+
_ts_decorate15([
|
|
1795
|
+
ApiProperty2(),
|
|
1796
|
+
_ts_metadata10("design:type", Number)
|
|
1797
|
+
], TableResponseDto.prototype, "count", void 0);
|
|
1798
|
+
_ts_decorate15([
|
|
1799
|
+
ApiProperty2(),
|
|
1800
|
+
_ts_metadata10("design:type", typeof TableViewState === "undefined" ? Object : TableViewState)
|
|
1801
|
+
], TableResponseDto.prototype, "state", void 0);
|
|
1802
|
+
_ts_decorate15([
|
|
1803
|
+
ApiPropertyOptional2({
|
|
1804
|
+
nullable: true
|
|
1805
|
+
}),
|
|
1806
|
+
_ts_metadata10("design:type", Object)
|
|
1807
|
+
], TableResponseDto.prototype, "activeViewId", void 0);
|
|
1808
|
+
|
|
1809
|
+
// src/database/filter/filter.processor.ts
|
|
1810
|
+
import { and, asc, desc, eq as eq2, gt, gte, ilike, lt, lte, ne, notIlike, or as or2 } from "drizzle-orm";
|
|
1811
|
+
var FilterProcessor = class {
|
|
1812
|
+
static {
|
|
1813
|
+
__name(this, "FilterProcessor");
|
|
1814
|
+
}
|
|
1815
|
+
// Returns undefined if no conditions (Drizzle accepts undefined as "no WHERE")
|
|
1816
|
+
static buildWhere(filters = [], fieldMap) {
|
|
1817
|
+
const conditions = filters.flatMap((f) => {
|
|
1818
|
+
const def = fieldMap[f.field];
|
|
1819
|
+
if (!def) return [];
|
|
1820
|
+
if ("expression" in def) return [
|
|
1821
|
+
def.expression(f.value)
|
|
1822
|
+
];
|
|
1823
|
+
const { column: col } = def;
|
|
1824
|
+
const val = f.value;
|
|
1825
|
+
switch (f.operator) {
|
|
1826
|
+
case "equals":
|
|
1827
|
+
if (def.type === "boolean") return [
|
|
1828
|
+
eq2(col, val === "true" || val === 1)
|
|
1829
|
+
];
|
|
1830
|
+
return [
|
|
1831
|
+
eq2(col, val)
|
|
1832
|
+
];
|
|
1833
|
+
case "notEquals":
|
|
1834
|
+
if (def.type === "boolean") return [
|
|
1835
|
+
ne(col, val === "true" || val === 1)
|
|
1836
|
+
];
|
|
1837
|
+
return [
|
|
1838
|
+
ne(col, val)
|
|
1839
|
+
];
|
|
1840
|
+
case "contains":
|
|
1841
|
+
return [
|
|
1842
|
+
ilike(col, `%${val}%`)
|
|
1843
|
+
];
|
|
1844
|
+
case "notContains":
|
|
1845
|
+
return [
|
|
1846
|
+
notIlike(col, `%${val}%`)
|
|
1847
|
+
];
|
|
1848
|
+
case "gt":
|
|
1849
|
+
return [
|
|
1850
|
+
gt(col, val)
|
|
1851
|
+
];
|
|
1852
|
+
case "gte":
|
|
1853
|
+
return [
|
|
1854
|
+
gte(col, val)
|
|
1855
|
+
];
|
|
1856
|
+
case "lt":
|
|
1857
|
+
return [
|
|
1858
|
+
lt(col, val)
|
|
1859
|
+
];
|
|
1860
|
+
case "lte":
|
|
1861
|
+
return [
|
|
1862
|
+
lte(col, val)
|
|
1863
|
+
];
|
|
1864
|
+
default:
|
|
1865
|
+
return [];
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
return conditions.length ? and(...conditions) : void 0;
|
|
1869
|
+
}
|
|
1870
|
+
// Builds a search WHERE — OR across all string fields when columnId is 'all', otherwise a single ilike
|
|
1871
|
+
static buildSearch(search, fieldMap) {
|
|
1872
|
+
if (!search?.value) return void 0;
|
|
1873
|
+
if (search.columnId === "all") {
|
|
1874
|
+
const conditions = Object.values(fieldMap).filter((def2) => "column" in def2 && def2.type === "string").map((def2) => ilike(def2.column, `%${search.value}%`));
|
|
1875
|
+
return conditions.length ? or2(...conditions) : void 0;
|
|
1876
|
+
}
|
|
1877
|
+
const def = fieldMap[search.columnId];
|
|
1878
|
+
if (!def || !("column" in def)) return void 0;
|
|
1879
|
+
return ilike(def.column, `%${search.value}%`);
|
|
1880
|
+
}
|
|
1881
|
+
// Maps each SortCondition to an asc/desc SQL expression
|
|
1882
|
+
static buildOrderBy(sort = [], fieldMap) {
|
|
1883
|
+
return sort.flatMap((s) => {
|
|
1884
|
+
const def = fieldMap[s.field];
|
|
1885
|
+
if (!def || !("column" in def)) return [];
|
|
1886
|
+
return [
|
|
1887
|
+
s.direction === "asc" ? asc(def.column) : desc(def.column)
|
|
1888
|
+
];
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
};
|
|
1892
|
+
|
|
1256
1893
|
// src/database/repositories/primary-base.repository.ts
|
|
1257
|
-
import { Logger as
|
|
1258
|
-
import { and, asc, eq as
|
|
1894
|
+
import { Logger as Logger8 } from "@nestjs/common";
|
|
1895
|
+
import { and as and2, asc as asc2, eq as eq3, getTableName, ilike as ilike2, inArray, notInArray, sql } from "drizzle-orm";
|
|
1259
1896
|
function snakeToCamel(str) {
|
|
1260
1897
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1261
1898
|
}
|
|
@@ -1286,7 +1923,7 @@ var PrimaryBaseRepository = class {
|
|
|
1286
1923
|
this.table = table;
|
|
1287
1924
|
const dbTableName = getTableName(table);
|
|
1288
1925
|
this.tableName = snakeToCamel(dbTableName);
|
|
1289
|
-
this.logger = new
|
|
1926
|
+
this.logger = new Logger8(this.constructor.name);
|
|
1290
1927
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1291
1928
|
this.logger.debug(`Table name: '${dbTableName}' -> query key: '${this.tableName}'`);
|
|
1292
1929
|
}
|
|
@@ -1319,12 +1956,32 @@ var PrimaryBaseRepository = class {
|
|
|
1319
1956
|
this.logger.debug("Finding multiple records");
|
|
1320
1957
|
return this.model.findMany(options);
|
|
1321
1958
|
}
|
|
1959
|
+
// Builds a select query with optional custom fields, join, filter, ordering, and pagination
|
|
1960
|
+
buildSelectQuery(options) {
|
|
1961
|
+
const base = options?.select ? this.db.select(options.select).from(this.table) : this.db.select().from(this.table);
|
|
1962
|
+
const joined = options?.leftJoin ? base.leftJoin(options.leftJoin.table, options.leftJoin.on) : base;
|
|
1963
|
+
const filtered = options?.where ? joined.where(options.where) : joined;
|
|
1964
|
+
const ordered = options?.orderBy?.length ? filtered.orderBy(...options.orderBy) : filtered;
|
|
1965
|
+
const limited = options?.limit ? ordered.limit(options.limit) : ordered;
|
|
1966
|
+
return options?.offset ? limited.offset(options.offset) : limited;
|
|
1967
|
+
}
|
|
1968
|
+
// Returns paginated result and total count, with optional custom select, LEFT JOIN, and ordering
|
|
1969
|
+
async findAllAndCount(options) {
|
|
1970
|
+
const [count, result] = await Promise.all([
|
|
1971
|
+
this.count(options?.where),
|
|
1972
|
+
this.buildSelectQuery(options)
|
|
1973
|
+
]);
|
|
1974
|
+
return {
|
|
1975
|
+
result,
|
|
1976
|
+
count
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1322
1979
|
// Updates a record by ID and returns the updated record
|
|
1323
1980
|
async update(id, data) {
|
|
1324
1981
|
this.logger.log(`Updating record with ID: ${id}`);
|
|
1325
1982
|
const idColumn = this.table.id;
|
|
1326
1983
|
if (!idColumn) throw new Error(`Table '${this.tableName}' has no 'id' column`);
|
|
1327
|
-
const results = await this.db.update(this.table).set(data).where(
|
|
1984
|
+
const results = await this.db.update(this.table).set(data).where(eq3(idColumn, id)).returning();
|
|
1328
1985
|
const record = results[0];
|
|
1329
1986
|
if (!record) throw new Error(`${this.tableName}: database operation returned no record`);
|
|
1330
1987
|
return record;
|
|
@@ -1342,7 +1999,7 @@ var PrimaryBaseRepository = class {
|
|
|
1342
1999
|
this.logger.log(`Deleting record with ID: ${id}`);
|
|
1343
2000
|
const idColumn = this.table.id;
|
|
1344
2001
|
if (!idColumn) throw new Error(`Table '${this.tableName}' has no 'id' column`);
|
|
1345
|
-
const results = await this.db.delete(this.table).where(
|
|
2002
|
+
const results = await this.db.delete(this.table).where(eq3(idColumn, id)).returning();
|
|
1346
2003
|
const record = results[0];
|
|
1347
2004
|
if (!record) throw new Error(`${this.tableName}: database operation returned no record`);
|
|
1348
2005
|
return record;
|
|
@@ -1382,20 +2039,44 @@ var PrimaryBaseRepository = class {
|
|
|
1382
2039
|
if (!valueCol) throw new Error(`Column '${config.value}' not found in table '${this.tableName}'`);
|
|
1383
2040
|
const labelCol = tableColumns[config.label];
|
|
1384
2041
|
if (!labelCol) throw new Error(`Column '${config.label}' not found in table '${this.tableName}'`);
|
|
2042
|
+
let descriptionCol = config.description ? tableColumns[config.description] : void 0;
|
|
2043
|
+
if (!descriptionCol && config.description && config.joins) {
|
|
2044
|
+
for (const join of config.joins) {
|
|
2045
|
+
const joinCols = join.table;
|
|
2046
|
+
if (joinCols[config.description]) {
|
|
2047
|
+
descriptionCol = joinCols[config.description];
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
1385
2052
|
if (parsedValues && parsedValues.length > 0) {
|
|
1386
2053
|
const selectCols = {
|
|
1387
2054
|
value: valueCol,
|
|
1388
2055
|
label: labelCol
|
|
1389
2056
|
};
|
|
2057
|
+
if (descriptionCol) selectCols.description = descriptionCol;
|
|
1390
2058
|
if (config.groupId) {
|
|
1391
2059
|
const groupIdCol = tableColumns[config.groupId];
|
|
1392
2060
|
if (groupIdCol) selectCols.groupId = groupIdCol;
|
|
1393
2061
|
}
|
|
1394
|
-
|
|
2062
|
+
let valuesQuery = this.db.select(selectCols).from(this.table).$dynamic();
|
|
2063
|
+
if (config.joins) {
|
|
2064
|
+
for (const join of config.joins) {
|
|
2065
|
+
if (join.type === "inner") {
|
|
2066
|
+
valuesQuery = valuesQuery.innerJoin(join.table, join.on);
|
|
2067
|
+
} else {
|
|
2068
|
+
valuesQuery = valuesQuery.leftJoin(join.table, join.on);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
const rows2 = await valuesQuery.where(inArray(valueCol, parsedValues));
|
|
1395
2073
|
return {
|
|
1396
2074
|
options: rows2.map((row) => ({
|
|
1397
2075
|
value: row.value,
|
|
1398
2076
|
label: String(row.label),
|
|
2077
|
+
...descriptionCol && row.description != null ? {
|
|
2078
|
+
description: row.description
|
|
2079
|
+
} : {},
|
|
1399
2080
|
...config.groupId && row.groupId != null ? {
|
|
1400
2081
|
groupId: row.groupId
|
|
1401
2082
|
} : {}
|
|
@@ -1411,13 +2092,14 @@ var PrimaryBaseRepository = class {
|
|
|
1411
2092
|
label: labelCol,
|
|
1412
2093
|
totalCount: sql`count(*) over()`.mapWith(Number)
|
|
1413
2094
|
};
|
|
2095
|
+
if (descriptionCol) selectFields.description = descriptionCol;
|
|
1414
2096
|
if (config.groupId) {
|
|
1415
2097
|
const groupIdCol = tableColumns[config.groupId];
|
|
1416
2098
|
if (groupIdCol) selectFields.groupId = groupIdCol;
|
|
1417
2099
|
}
|
|
1418
2100
|
const conditions = [];
|
|
1419
2101
|
if (config.search) {
|
|
1420
|
-
conditions.push(
|
|
2102
|
+
conditions.push(ilike2(labelCol, `%${config.search}%`));
|
|
1421
2103
|
}
|
|
1422
2104
|
if (parsedExcludeIds.length > 0) {
|
|
1423
2105
|
conditions.push(notInArray(valueCol, parsedExcludeIds));
|
|
@@ -1426,30 +2108,45 @@ var PrimaryBaseRepository = class {
|
|
|
1426
2108
|
for (const [field, val] of Object.entries(config.where)) {
|
|
1427
2109
|
const column = tableColumns[field];
|
|
1428
2110
|
if (column) {
|
|
1429
|
-
conditions.push(
|
|
2111
|
+
conditions.push(eq3(column, val));
|
|
1430
2112
|
}
|
|
1431
2113
|
}
|
|
1432
2114
|
}
|
|
2115
|
+
if (config.conditions) {
|
|
2116
|
+
conditions.push(...config.conditions);
|
|
2117
|
+
}
|
|
1433
2118
|
const orderByKey = config.orderBy ? Object.keys(config.orderBy)[0] : void 0;
|
|
1434
2119
|
const orderByCol = orderByKey ? tableColumns[orderByKey] ?? labelCol : labelCol;
|
|
1435
2120
|
const limit = Number(config.limit) || 20;
|
|
1436
2121
|
const offset = Number(config.offset) || 0;
|
|
1437
2122
|
let query = this.db.select(selectFields).from(this.table).$dynamic();
|
|
2123
|
+
if (config.joins) {
|
|
2124
|
+
for (const join of config.joins) {
|
|
2125
|
+
if (join.type === "inner") {
|
|
2126
|
+
query = query.innerJoin(join.table, join.on);
|
|
2127
|
+
} else {
|
|
2128
|
+
query = query.leftJoin(join.table, join.on);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
1438
2132
|
if (conditions.length > 0) {
|
|
1439
|
-
query = query.where(conditions.length === 1 ? conditions[0] :
|
|
2133
|
+
query = query.where(conditions.length === 1 ? conditions[0] : and2(...conditions));
|
|
1440
2134
|
}
|
|
1441
2135
|
const orderClauses = [];
|
|
1442
2136
|
if (config.groupId) {
|
|
1443
2137
|
const groupIdCol = tableColumns[config.groupId];
|
|
1444
|
-
if (groupIdCol) orderClauses.push(
|
|
2138
|
+
if (groupIdCol) orderClauses.push(asc2(groupIdCol));
|
|
1445
2139
|
}
|
|
1446
|
-
orderClauses.push(
|
|
2140
|
+
orderClauses.push(asc2(orderByCol));
|
|
1447
2141
|
query = query.orderBy(...orderClauses).limit(limit).offset(offset);
|
|
1448
2142
|
const rows = await query;
|
|
1449
2143
|
const totalCount = rows.length > 0 ? rows[0].totalCount : 0;
|
|
1450
2144
|
const options = rows.map((row) => ({
|
|
1451
2145
|
value: row.value,
|
|
1452
2146
|
label: String(row.label),
|
|
2147
|
+
...descriptionCol && row.description != null ? {
|
|
2148
|
+
description: row.description
|
|
2149
|
+
} : {},
|
|
1453
2150
|
...config.groupId && row.groupId != null ? {
|
|
1454
2151
|
groupId: row.groupId
|
|
1455
2152
|
} : {}
|
|
@@ -1466,7 +2163,7 @@ var PrimaryBaseRepository = class {
|
|
|
1466
2163
|
const groupRows = await this.db.select({
|
|
1467
2164
|
id: groupIdCol,
|
|
1468
2165
|
name: groupNameCol
|
|
1469
|
-
}).from(config.groupTable).orderBy(
|
|
2166
|
+
}).from(config.groupTable).orderBy(asc2(groupNameCol));
|
|
1470
2167
|
resolvedGroups = groupRows.map((r) => ({
|
|
1471
2168
|
id: r.id,
|
|
1472
2169
|
name: String(r.name)
|
|
@@ -1484,8 +2181,8 @@ var PrimaryBaseRepository = class {
|
|
|
1484
2181
|
};
|
|
1485
2182
|
|
|
1486
2183
|
// src/database/repositories/tenant-base.repository.ts
|
|
1487
|
-
import { Logger as
|
|
1488
|
-
import { and as
|
|
2184
|
+
import { Logger as Logger9 } from "@nestjs/common";
|
|
2185
|
+
import { and as and3, asc as asc3, eq as eq4, getTableName as getTableName2, ilike as ilike3, inArray as inArray2, notInArray as notInArray2, sql as sql2 } from "drizzle-orm";
|
|
1489
2186
|
var TenantBaseRepository = class {
|
|
1490
2187
|
static {
|
|
1491
2188
|
__name(this, "TenantBaseRepository");
|
|
@@ -1504,7 +2201,7 @@ var TenantBaseRepository = class {
|
|
|
1504
2201
|
this.database = database;
|
|
1505
2202
|
this.table = table;
|
|
1506
2203
|
this.tableName = getTableName2(table);
|
|
1507
|
-
this.logger = new
|
|
2204
|
+
this.logger = new Logger9(this.constructor.name);
|
|
1508
2205
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1509
2206
|
}
|
|
1510
2207
|
// Creates a new record and returns it
|
|
@@ -1520,7 +2217,7 @@ var TenantBaseRepository = class {
|
|
|
1520
2217
|
this.logger.debug(`Finding record by ID: ${id}`);
|
|
1521
2218
|
const idColumn = this.table.id;
|
|
1522
2219
|
if (!idColumn) throw new Error(`Table '${this.tableName}' has no 'id' column`);
|
|
1523
|
-
const results = await this.db.select().from(this.table).where(
|
|
2220
|
+
const results = await this.db.select().from(this.table).where(eq4(idColumn, id)).limit(1);
|
|
1524
2221
|
return results[0] ?? null;
|
|
1525
2222
|
}
|
|
1526
2223
|
// Finds a single record matching the given SQL condition
|
|
@@ -1552,7 +2249,7 @@ var TenantBaseRepository = class {
|
|
|
1552
2249
|
this.logger.log(`Updating record with ID: ${id}`);
|
|
1553
2250
|
const idColumn = this.table.id;
|
|
1554
2251
|
if (!idColumn) throw new Error(`Table '${this.tableName}' has no 'id' column`);
|
|
1555
|
-
const results = await this.db.update(this.table).set(data).where(
|
|
2252
|
+
const results = await this.db.update(this.table).set(data).where(eq4(idColumn, id)).returning();
|
|
1556
2253
|
const record = results[0];
|
|
1557
2254
|
if (!record) throw new Error(`${this.tableName}: database operation returned no record`);
|
|
1558
2255
|
return record;
|
|
@@ -1570,7 +2267,7 @@ var TenantBaseRepository = class {
|
|
|
1570
2267
|
this.logger.log(`Deleting record with ID: ${id}`);
|
|
1571
2268
|
const idColumn = this.table.id;
|
|
1572
2269
|
if (!idColumn) throw new Error(`Table '${this.tableName}' has no 'id' column`);
|
|
1573
|
-
const results = await this.db.delete(this.table).where(
|
|
2270
|
+
const results = await this.db.delete(this.table).where(eq4(idColumn, id)).returning();
|
|
1574
2271
|
const record = results[0];
|
|
1575
2272
|
if (!record) throw new Error(`${this.tableName}: database operation returned no record`);
|
|
1576
2273
|
return record;
|
|
@@ -1645,7 +2342,7 @@ var TenantBaseRepository = class {
|
|
|
1645
2342
|
}
|
|
1646
2343
|
const conditions = [];
|
|
1647
2344
|
if (config.search) {
|
|
1648
|
-
conditions.push(
|
|
2345
|
+
conditions.push(ilike3(labelCol, `%${config.search}%`));
|
|
1649
2346
|
}
|
|
1650
2347
|
if (parsedExcludeIds.length > 0) {
|
|
1651
2348
|
conditions.push(notInArray2(valueCol, parsedExcludeIds));
|
|
@@ -1654,7 +2351,7 @@ var TenantBaseRepository = class {
|
|
|
1654
2351
|
for (const [field, val] of Object.entries(config.where)) {
|
|
1655
2352
|
const column = tableColumns[field];
|
|
1656
2353
|
if (column) {
|
|
1657
|
-
conditions.push(
|
|
2354
|
+
conditions.push(eq4(column, val));
|
|
1658
2355
|
}
|
|
1659
2356
|
}
|
|
1660
2357
|
}
|
|
@@ -1664,14 +2361,14 @@ var TenantBaseRepository = class {
|
|
|
1664
2361
|
const offset = Number(config.offset) || 0;
|
|
1665
2362
|
let query = this.db.select(selectFields).from(this.table).$dynamic();
|
|
1666
2363
|
if (conditions.length > 0) {
|
|
1667
|
-
query = query.where(conditions.length === 1 ? conditions[0] :
|
|
2364
|
+
query = query.where(conditions.length === 1 ? conditions[0] : and3(...conditions));
|
|
1668
2365
|
}
|
|
1669
2366
|
const orderClauses = [];
|
|
1670
2367
|
if (config.groupId) {
|
|
1671
2368
|
const groupIdCol = tableColumns[config.groupId];
|
|
1672
|
-
if (groupIdCol) orderClauses.push(
|
|
2369
|
+
if (groupIdCol) orderClauses.push(asc3(groupIdCol));
|
|
1673
2370
|
}
|
|
1674
|
-
orderClauses.push(
|
|
2371
|
+
orderClauses.push(asc3(orderByCol));
|
|
1675
2372
|
query = query.orderBy(...orderClauses).limit(limit).offset(offset);
|
|
1676
2373
|
const rows = await query;
|
|
1677
2374
|
const totalCount = rows.length > 0 ? rows[0].totalCount : 0;
|
|
@@ -1694,7 +2391,7 @@ var TenantBaseRepository = class {
|
|
|
1694
2391
|
const groupRows = await this.db.select({
|
|
1695
2392
|
id: groupIdCol,
|
|
1696
2393
|
name: groupNameCol
|
|
1697
|
-
}).from(config.groupTable).orderBy(
|
|
2394
|
+
}).from(config.groupTable).orderBy(asc3(groupNameCol));
|
|
1698
2395
|
resolvedGroups = groupRows.map((r) => ({
|
|
1699
2396
|
id: r.id,
|
|
1700
2397
|
name: String(r.name)
|
|
@@ -1712,30 +2409,30 @@ var TenantBaseRepository = class {
|
|
|
1712
2409
|
};
|
|
1713
2410
|
|
|
1714
2411
|
// src/email/email.module.ts
|
|
1715
|
-
import { Global as Global4, Module as
|
|
1716
|
-
import { ConfigModule as
|
|
2412
|
+
import { Global as Global4, Module as Module5 } from "@nestjs/common";
|
|
2413
|
+
import { ConfigModule as ConfigModule3 } from "@nestjs/config";
|
|
1717
2414
|
|
|
1718
2415
|
// src/email/email.service.ts
|
|
1719
2416
|
import { BrevoClient, BrevoError, BrevoTimeoutError } from "@getbrevo/brevo";
|
|
1720
|
-
import { Injectable as
|
|
1721
|
-
import { ConfigService as
|
|
1722
|
-
function
|
|
1723
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
1724
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
2417
|
+
import { Injectable as Injectable9, Logger as Logger10 } from "@nestjs/common";
|
|
2418
|
+
import { ConfigService as ConfigService5 } from "@nestjs/config";
|
|
2419
|
+
function _ts_decorate16(decorators, target, key, desc2) {
|
|
2420
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
2421
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
1725
2422
|
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;
|
|
1726
2423
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1727
2424
|
}
|
|
1728
|
-
__name(
|
|
1729
|
-
function
|
|
2425
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
2426
|
+
function _ts_metadata11(k, v) {
|
|
1730
2427
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1731
2428
|
}
|
|
1732
|
-
__name(
|
|
2429
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
1733
2430
|
var EmailService = class _EmailService {
|
|
1734
2431
|
static {
|
|
1735
2432
|
__name(this, "EmailService");
|
|
1736
2433
|
}
|
|
1737
2434
|
configService;
|
|
1738
|
-
logger = new
|
|
2435
|
+
logger = new Logger10(_EmailService.name);
|
|
1739
2436
|
brevoClient;
|
|
1740
2437
|
senderEmail;
|
|
1741
2438
|
senderName;
|
|
@@ -2109,393 +2806,174 @@ This is an automated message, please do not reply.
|
|
|
2109
2806
|
Hello <strong>${name}</strong>,
|
|
2110
2807
|
</p>
|
|
2111
2808
|
<p style="margin: 0 0 30px; color: #333333; font-size: 16px; line-height: 1.6;">
|
|
2112
|
-
Your recent email address change has been successfully reverted. Your email is now:
|
|
2113
|
-
</p>
|
|
2114
|
-
|
|
2115
|
-
<div style="background-color: #d4edda; padding: 20px; border-radius: 8px; margin: 30px 0; text-align: center;">
|
|
2116
|
-
<p style="margin: 0; color: #155724; font-size: 18px; font-weight: 600; font-family: monospace;">
|
|
2117
|
-
${email}
|
|
2118
|
-
</p>
|
|
2119
|
-
</div>
|
|
2120
|
-
|
|
2121
|
-
<p style="margin: 30px 0 20px; color: #666666; font-size: 14px; line-height: 1.6;">
|
|
2122
|
-
If you did not request this revert, please contact our support team immediately.
|
|
2123
|
-
</p>
|
|
2124
|
-
</td>
|
|
2125
|
-
</tr>
|
|
2126
|
-
|
|
2127
|
-
<!-- Footer -->
|
|
2128
|
-
<tr>
|
|
2129
|
-
<td style="padding: 30px 40px; border-top: 1px solid #e0e0e0; text-align: center;">
|
|
2130
|
-
<p style="margin: 0; color: #999999; font-size: 12px; line-height: 1.5;">
|
|
2131
|
-
Vritti AI Cloud - Cloud Management Platform
|
|
2132
|
-
</p>
|
|
2133
|
-
<p style="margin: 8px 0 0; color: #999999; font-size: 12px; line-height: 1.5;">
|
|
2134
|
-
This is an automated message, please do not reply.
|
|
2135
|
-
</p>
|
|
2136
|
-
</td>
|
|
2137
|
-
</tr>
|
|
2138
|
-
</table>
|
|
2139
|
-
</td>
|
|
2140
|
-
</tr>
|
|
2141
|
-
</table>
|
|
2142
|
-
</body>
|
|
2143
|
-
</html>
|
|
2144
|
-
`;
|
|
2145
|
-
const textContent = `
|
|
2146
|
-
Hello ${name},
|
|
2147
|
-
|
|
2148
|
-
Your recent email address change has been successfully reverted. Your email is now:
|
|
2149
|
-
|
|
2150
|
-
${email}
|
|
2151
|
-
|
|
2152
|
-
If you did not request this revert, please contact our support team immediately.
|
|
2153
|
-
|
|
2154
|
-
---
|
|
2155
|
-
Vritti AI Cloud - Cloud Management Platform
|
|
2156
|
-
This is an automated message, please do not reply.
|
|
2157
|
-
`.trim();
|
|
2158
|
-
await this.sendEmail({
|
|
2159
|
-
to: [
|
|
2160
|
-
{
|
|
2161
|
-
email,
|
|
2162
|
-
name
|
|
2163
|
-
}
|
|
2164
|
-
],
|
|
2165
|
-
subject,
|
|
2166
|
-
htmlContent,
|
|
2167
|
-
textContent
|
|
2168
|
-
});
|
|
2169
|
-
this.logger.log(`Email revert confirmation sent to ${email}`);
|
|
2170
|
-
}
|
|
2171
|
-
// Verifies Brevo API connectivity — a 400 response means the API is reachable
|
|
2172
|
-
async verifyConnection() {
|
|
2173
|
-
try {
|
|
2174
|
-
await this.brevoClient.transactionalEmails.sendTransacEmail({
|
|
2175
|
-
sender: {
|
|
2176
|
-
email: this.senderEmail,
|
|
2177
|
-
name: this.senderName
|
|
2178
|
-
},
|
|
2179
|
-
to: [
|
|
2180
|
-
{
|
|
2181
|
-
email: this.senderEmail
|
|
2182
|
-
}
|
|
2183
|
-
],
|
|
2184
|
-
subject: "Connection Test",
|
|
2185
|
-
htmlContent: "<p>Test</p>"
|
|
2186
|
-
});
|
|
2187
|
-
return true;
|
|
2188
|
-
} catch (err) {
|
|
2189
|
-
if (err instanceof BrevoError && err.statusCode === 400) {
|
|
2190
|
-
return true;
|
|
2191
|
-
}
|
|
2192
|
-
this.logger.error("Brevo connection verification failed:", err);
|
|
2193
|
-
return false;
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
// Sends a transactional email via Brevo — retries handled internally by BrevoClient
|
|
2197
|
-
async sendEmail(emailData) {
|
|
2198
|
-
try {
|
|
2199
|
-
const result = await this.brevoClient.transactionalEmails.sendTransacEmail({
|
|
2200
|
-
sender: {
|
|
2201
|
-
email: this.senderEmail,
|
|
2202
|
-
name: this.senderName
|
|
2203
|
-
},
|
|
2204
|
-
to: emailData.to,
|
|
2205
|
-
subject: emailData.subject,
|
|
2206
|
-
htmlContent: emailData.htmlContent,
|
|
2207
|
-
textContent: emailData.textContent
|
|
2208
|
-
});
|
|
2209
|
-
this.logger.debug(`Email sent successfully. Message ID: ${result.messageId}`);
|
|
2210
|
-
} catch (err) {
|
|
2211
|
-
if (err instanceof BrevoTimeoutError) {
|
|
2212
|
-
this.logger.error("Brevo request timed out after retries.");
|
|
2213
|
-
throw new Error("Email sending failed: timeout");
|
|
2214
|
-
}
|
|
2215
|
-
if (err instanceof BrevoError) {
|
|
2216
|
-
if (err.statusCode === 429) {
|
|
2217
|
-
this.logger.error("Brevo rate limit exceeded after retries.");
|
|
2218
|
-
throw new Error("Email sending failed: rate limit exceeded");
|
|
2219
|
-
}
|
|
2220
|
-
if (err.statusCode === 401) {
|
|
2221
|
-
this.logger.error("Brevo authentication failed. Check your API key.");
|
|
2222
|
-
throw new Error("Email service authentication failed");
|
|
2223
|
-
}
|
|
2224
|
-
if (err.statusCode === 400) {
|
|
2225
|
-
this.logger.error("Bad request to Brevo API:", err.message);
|
|
2226
|
-
throw new Error(`Invalid email parameters: ${err.message}`);
|
|
2227
|
-
}
|
|
2228
|
-
this.logger.error(`Brevo API error ${err.statusCode}:`, err.message);
|
|
2229
|
-
throw new Error(`Email sending failed: ${err.message}`);
|
|
2230
|
-
}
|
|
2231
|
-
throw err;
|
|
2232
|
-
}
|
|
2233
|
-
}
|
|
2234
|
-
};
|
|
2235
|
-
EmailService = _ts_decorate11([
|
|
2236
|
-
Injectable7(),
|
|
2237
|
-
_ts_metadata7("design:type", Function),
|
|
2238
|
-
_ts_metadata7("design:paramtypes", [
|
|
2239
|
-
typeof ConfigService4 === "undefined" ? Object : ConfigService4
|
|
2240
|
-
])
|
|
2241
|
-
], EmailService);
|
|
2242
|
-
|
|
2243
|
-
// src/email/email.module.ts
|
|
2244
|
-
function _ts_decorate12(decorators, target, key, desc) {
|
|
2245
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2246
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2247
|
-
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;
|
|
2248
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2249
|
-
}
|
|
2250
|
-
__name(_ts_decorate12, "_ts_decorate");
|
|
2251
|
-
var EmailModule = class {
|
|
2252
|
-
static {
|
|
2253
|
-
__name(this, "EmailModule");
|
|
2254
|
-
}
|
|
2255
|
-
};
|
|
2256
|
-
EmailModule = _ts_decorate12([
|
|
2257
|
-
Global4(),
|
|
2258
|
-
Module4({
|
|
2259
|
-
imports: [
|
|
2260
|
-
ConfigModule2
|
|
2261
|
-
],
|
|
2262
|
-
providers: [
|
|
2263
|
-
EmailService
|
|
2264
|
-
],
|
|
2265
|
-
exports: [
|
|
2266
|
-
EmailService
|
|
2267
|
-
]
|
|
2268
|
-
})
|
|
2269
|
-
], EmailModule);
|
|
2270
|
-
|
|
2271
|
-
// src/exceptions/bad-gateway.exception.ts
|
|
2272
|
-
import { HttpStatus } from "@nestjs/common";
|
|
2273
|
-
|
|
2274
|
-
// src/exceptions/base-field.exception.ts
|
|
2275
|
-
import { HttpException } from "@nestjs/common";
|
|
2276
|
-
var HttpProblemException = class extends HttpException {
|
|
2277
|
-
static {
|
|
2278
|
-
__name(this, "HttpProblemException");
|
|
2279
|
-
}
|
|
2280
|
-
constructor(detailOrOptions, httpStatus) {
|
|
2281
|
-
const options = typeof detailOrOptions === "string" ? {
|
|
2282
|
-
detail: detailOrOptions
|
|
2283
|
-
} : detailOrOptions;
|
|
2284
|
-
super({
|
|
2285
|
-
type: options.type ?? "about:blank",
|
|
2286
|
-
label: options.label,
|
|
2287
|
-
detail: options.detail,
|
|
2288
|
-
errors: options.errors ?? []
|
|
2289
|
-
}, httpStatus);
|
|
2290
|
-
}
|
|
2291
|
-
};
|
|
2292
|
-
|
|
2293
|
-
// src/exceptions/bad-gateway.exception.ts
|
|
2294
|
-
var BadGatewayException = class extends HttpProblemException {
|
|
2295
|
-
static {
|
|
2296
|
-
__name(this, "BadGatewayException");
|
|
2297
|
-
}
|
|
2298
|
-
constructor(detailOrOptions) {
|
|
2299
|
-
super(detailOrOptions ?? "Bad Gateway", HttpStatus.BAD_GATEWAY);
|
|
2300
|
-
}
|
|
2301
|
-
};
|
|
2302
|
-
|
|
2303
|
-
// src/exceptions/bad-request.exception.ts
|
|
2304
|
-
import { HttpStatus as HttpStatus2 } from "@nestjs/common";
|
|
2305
|
-
var BadRequestException = class extends HttpProblemException {
|
|
2306
|
-
static {
|
|
2307
|
-
__name(this, "BadRequestException");
|
|
2308
|
-
}
|
|
2309
|
-
constructor(detailOrOptions) {
|
|
2310
|
-
super(detailOrOptions ?? "Bad Request", HttpStatus2.BAD_REQUEST);
|
|
2311
|
-
}
|
|
2312
|
-
};
|
|
2313
|
-
|
|
2314
|
-
// src/exceptions/conflict.exception.ts
|
|
2315
|
-
import { HttpStatus as HttpStatus3 } from "@nestjs/common";
|
|
2316
|
-
var ConflictException = class extends HttpProblemException {
|
|
2317
|
-
static {
|
|
2318
|
-
__name(this, "ConflictException");
|
|
2319
|
-
}
|
|
2320
|
-
constructor(detailOrOptions) {
|
|
2321
|
-
super(detailOrOptions ?? "Conflict", HttpStatus3.CONFLICT);
|
|
2322
|
-
}
|
|
2323
|
-
};
|
|
2324
|
-
|
|
2325
|
-
// src/exceptions/forbidden.exception.ts
|
|
2326
|
-
import { HttpStatus as HttpStatus4 } from "@nestjs/common";
|
|
2327
|
-
var ForbiddenException2 = class extends HttpProblemException {
|
|
2328
|
-
static {
|
|
2329
|
-
__name(this, "ForbiddenException");
|
|
2330
|
-
}
|
|
2331
|
-
constructor(detailOrOptions) {
|
|
2332
|
-
super(detailOrOptions ?? "Forbidden", HttpStatus4.FORBIDDEN);
|
|
2333
|
-
}
|
|
2334
|
-
};
|
|
2335
|
-
|
|
2336
|
-
// src/exceptions/gone.exception.ts
|
|
2337
|
-
import { HttpStatus as HttpStatus5 } from "@nestjs/common";
|
|
2338
|
-
var GoneException = class extends HttpProblemException {
|
|
2339
|
-
static {
|
|
2340
|
-
__name(this, "GoneException");
|
|
2341
|
-
}
|
|
2342
|
-
constructor(detailOrOptions) {
|
|
2343
|
-
super(detailOrOptions ?? "Gone", HttpStatus5.GONE);
|
|
2344
|
-
}
|
|
2345
|
-
};
|
|
2346
|
-
|
|
2347
|
-
// src/exceptions/internal-server-error.exception.ts
|
|
2348
|
-
import { HttpStatus as HttpStatus6 } from "@nestjs/common";
|
|
2349
|
-
var InternalServerErrorException3 = class extends HttpProblemException {
|
|
2350
|
-
static {
|
|
2351
|
-
__name(this, "InternalServerErrorException");
|
|
2352
|
-
}
|
|
2353
|
-
constructor(detailOrOptions) {
|
|
2354
|
-
super(detailOrOptions ?? "Internal Server Error", HttpStatus6.INTERNAL_SERVER_ERROR);
|
|
2355
|
-
}
|
|
2356
|
-
};
|
|
2357
|
-
|
|
2358
|
-
// src/exceptions/method-not-allowed.exception.ts
|
|
2359
|
-
import { HttpStatus as HttpStatus7 } from "@nestjs/common";
|
|
2360
|
-
var MethodNotAllowedException = class extends HttpProblemException {
|
|
2361
|
-
static {
|
|
2362
|
-
__name(this, "MethodNotAllowedException");
|
|
2363
|
-
}
|
|
2364
|
-
constructor(detailOrOptions) {
|
|
2365
|
-
super(detailOrOptions ?? "Method Not Allowed", HttpStatus7.METHOD_NOT_ALLOWED);
|
|
2366
|
-
}
|
|
2367
|
-
};
|
|
2368
|
-
|
|
2369
|
-
// src/exceptions/not-acceptable.exception.ts
|
|
2370
|
-
import { HttpStatus as HttpStatus8 } from "@nestjs/common";
|
|
2371
|
-
var NotAcceptableException = class extends HttpProblemException {
|
|
2372
|
-
static {
|
|
2373
|
-
__name(this, "NotAcceptableException");
|
|
2374
|
-
}
|
|
2375
|
-
constructor(detailOrOptions) {
|
|
2376
|
-
super(detailOrOptions ?? "Not Acceptable", HttpStatus8.NOT_ACCEPTABLE);
|
|
2377
|
-
}
|
|
2378
|
-
};
|
|
2379
|
-
|
|
2380
|
-
// src/exceptions/not-found.exception.ts
|
|
2381
|
-
import { HttpStatus as HttpStatus9 } from "@nestjs/common";
|
|
2382
|
-
var NotFoundException = class extends HttpProblemException {
|
|
2383
|
-
static {
|
|
2384
|
-
__name(this, "NotFoundException");
|
|
2385
|
-
}
|
|
2386
|
-
constructor(detailOrOptions) {
|
|
2387
|
-
super(detailOrOptions ?? "Not Found", HttpStatus9.NOT_FOUND);
|
|
2388
|
-
}
|
|
2389
|
-
};
|
|
2390
|
-
|
|
2391
|
-
// src/exceptions/not-implemented.exception.ts
|
|
2392
|
-
import { HttpStatus as HttpStatus10 } from "@nestjs/common";
|
|
2393
|
-
var NotImplementedException = class extends HttpProblemException {
|
|
2394
|
-
static {
|
|
2395
|
-
__name(this, "NotImplementedException");
|
|
2396
|
-
}
|
|
2397
|
-
constructor(detailOrOptions) {
|
|
2398
|
-
super(detailOrOptions ?? "Not Implemented", HttpStatus10.NOT_IMPLEMENTED);
|
|
2399
|
-
}
|
|
2400
|
-
};
|
|
2809
|
+
Your recent email address change has been successfully reverted. Your email is now:
|
|
2810
|
+
</p>
|
|
2401
2811
|
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
}
|
|
2408
|
-
constructor(detailOrOptions) {
|
|
2409
|
-
super(detailOrOptions ?? "Payload Too Large", HttpStatus11.PAYLOAD_TOO_LARGE);
|
|
2410
|
-
}
|
|
2411
|
-
};
|
|
2812
|
+
<div style="background-color: #d4edda; padding: 20px; border-radius: 8px; margin: 30px 0; text-align: center;">
|
|
2813
|
+
<p style="margin: 0; color: #155724; font-size: 18px; font-weight: 600; font-family: monospace;">
|
|
2814
|
+
${email}
|
|
2815
|
+
</p>
|
|
2816
|
+
</div>
|
|
2412
2817
|
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
}
|
|
2419
|
-
constructor(detailOrOptions) {
|
|
2420
|
-
super(detailOrOptions ?? "Request Timeout", HttpStatus12.REQUEST_TIMEOUT);
|
|
2421
|
-
}
|
|
2422
|
-
};
|
|
2818
|
+
<p style="margin: 30px 0 20px; color: #666666; font-size: 14px; line-height: 1.6;">
|
|
2819
|
+
If you did not request this revert, please contact our support team immediately.
|
|
2820
|
+
</p>
|
|
2821
|
+
</td>
|
|
2822
|
+
</tr>
|
|
2423
2823
|
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2824
|
+
<!-- Footer -->
|
|
2825
|
+
<tr>
|
|
2826
|
+
<td style="padding: 30px 40px; border-top: 1px solid #e0e0e0; text-align: center;">
|
|
2827
|
+
<p style="margin: 0; color: #999999; font-size: 12px; line-height: 1.5;">
|
|
2828
|
+
Vritti AI Cloud - Cloud Management Platform
|
|
2829
|
+
</p>
|
|
2830
|
+
<p style="margin: 8px 0 0; color: #999999; font-size: 12px; line-height: 1.5;">
|
|
2831
|
+
This is an automated message, please do not reply.
|
|
2832
|
+
</p>
|
|
2833
|
+
</td>
|
|
2834
|
+
</tr>
|
|
2835
|
+
</table>
|
|
2836
|
+
</td>
|
|
2837
|
+
</tr>
|
|
2838
|
+
</table>
|
|
2839
|
+
</body>
|
|
2840
|
+
</html>
|
|
2841
|
+
`;
|
|
2842
|
+
const textContent = `
|
|
2843
|
+
Hello ${name},
|
|
2434
2844
|
|
|
2435
|
-
|
|
2436
|
-
import { HttpStatus as HttpStatus14 } from "@nestjs/common";
|
|
2437
|
-
var TooManyRequestsException = class extends HttpProblemException {
|
|
2438
|
-
static {
|
|
2439
|
-
__name(this, "TooManyRequestsException");
|
|
2440
|
-
}
|
|
2441
|
-
constructor(detailOrOptions) {
|
|
2442
|
-
super(detailOrOptions ?? "Too Many Requests", HttpStatus14.TOO_MANY_REQUESTS);
|
|
2443
|
-
}
|
|
2444
|
-
};
|
|
2845
|
+
Your recent email address change has been successfully reverted. Your email is now:
|
|
2445
2846
|
|
|
2446
|
-
|
|
2447
|
-
import { HttpStatus as HttpStatus15 } from "@nestjs/common";
|
|
2448
|
-
var UnauthorizedException3 = class extends HttpProblemException {
|
|
2449
|
-
static {
|
|
2450
|
-
__name(this, "UnauthorizedException");
|
|
2451
|
-
}
|
|
2452
|
-
constructor(detailOrOptions) {
|
|
2453
|
-
super(detailOrOptions ?? "Unauthorized", HttpStatus15.UNAUTHORIZED);
|
|
2454
|
-
}
|
|
2455
|
-
};
|
|
2847
|
+
${email}
|
|
2456
2848
|
|
|
2457
|
-
|
|
2458
|
-
import { HttpStatus as HttpStatus16 } from "@nestjs/common";
|
|
2459
|
-
var UnprocessableEntityException = class extends HttpProblemException {
|
|
2460
|
-
static {
|
|
2461
|
-
__name(this, "UnprocessableEntityException");
|
|
2462
|
-
}
|
|
2463
|
-
constructor(detailOrOptions) {
|
|
2464
|
-
super(detailOrOptions ?? "Unprocessable Entity", HttpStatus16.UNPROCESSABLE_ENTITY);
|
|
2465
|
-
}
|
|
2466
|
-
};
|
|
2849
|
+
If you did not request this revert, please contact our support team immediately.
|
|
2467
2850
|
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2851
|
+
---
|
|
2852
|
+
Vritti AI Cloud - Cloud Management Platform
|
|
2853
|
+
This is an automated message, please do not reply.
|
|
2854
|
+
`.trim();
|
|
2855
|
+
await this.sendEmail({
|
|
2856
|
+
to: [
|
|
2857
|
+
{
|
|
2858
|
+
email,
|
|
2859
|
+
name
|
|
2860
|
+
}
|
|
2861
|
+
],
|
|
2862
|
+
subject,
|
|
2863
|
+
htmlContent,
|
|
2864
|
+
textContent
|
|
2865
|
+
});
|
|
2866
|
+
this.logger.log(`Email revert confirmation sent to ${email}`);
|
|
2473
2867
|
}
|
|
2474
|
-
|
|
2475
|
-
|
|
2868
|
+
// Verifies Brevo API connectivity — a 400 response means the API is reachable
|
|
2869
|
+
async verifyConnection() {
|
|
2870
|
+
try {
|
|
2871
|
+
await this.brevoClient.transactionalEmails.sendTransacEmail({
|
|
2872
|
+
sender: {
|
|
2873
|
+
email: this.senderEmail,
|
|
2874
|
+
name: this.senderName
|
|
2875
|
+
},
|
|
2876
|
+
to: [
|
|
2877
|
+
{
|
|
2878
|
+
email: this.senderEmail
|
|
2879
|
+
}
|
|
2880
|
+
],
|
|
2881
|
+
subject: "Connection Test",
|
|
2882
|
+
htmlContent: "<p>Test</p>"
|
|
2883
|
+
});
|
|
2884
|
+
return true;
|
|
2885
|
+
} catch (err) {
|
|
2886
|
+
if (err instanceof BrevoError && err.statusCode === 400) {
|
|
2887
|
+
return true;
|
|
2888
|
+
}
|
|
2889
|
+
this.logger.error("Brevo connection verification failed:", err);
|
|
2890
|
+
return false;
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
// Sends a transactional email via Brevo — retries handled internally by BrevoClient
|
|
2894
|
+
async sendEmail(emailData) {
|
|
2895
|
+
try {
|
|
2896
|
+
const result = await this.brevoClient.transactionalEmails.sendTransacEmail({
|
|
2897
|
+
sender: {
|
|
2898
|
+
email: this.senderEmail,
|
|
2899
|
+
name: this.senderName
|
|
2900
|
+
},
|
|
2901
|
+
to: emailData.to,
|
|
2902
|
+
subject: emailData.subject,
|
|
2903
|
+
htmlContent: emailData.htmlContent,
|
|
2904
|
+
textContent: emailData.textContent
|
|
2905
|
+
});
|
|
2906
|
+
this.logger.debug(`Email sent successfully. Message ID: ${result.messageId}`);
|
|
2907
|
+
} catch (err) {
|
|
2908
|
+
if (err instanceof BrevoTimeoutError) {
|
|
2909
|
+
this.logger.error("Brevo request timed out after retries.");
|
|
2910
|
+
throw new Error("Email sending failed: timeout");
|
|
2911
|
+
}
|
|
2912
|
+
if (err instanceof BrevoError) {
|
|
2913
|
+
if (err.statusCode === 429) {
|
|
2914
|
+
this.logger.error("Brevo rate limit exceeded after retries.");
|
|
2915
|
+
throw new Error("Email sending failed: rate limit exceeded");
|
|
2916
|
+
}
|
|
2917
|
+
if (err.statusCode === 401) {
|
|
2918
|
+
this.logger.error("Brevo authentication failed. Check your API key.");
|
|
2919
|
+
throw new Error("Email service authentication failed");
|
|
2920
|
+
}
|
|
2921
|
+
if (err.statusCode === 400) {
|
|
2922
|
+
this.logger.error("Bad request to Brevo API:", err.message);
|
|
2923
|
+
throw new Error(`Invalid email parameters: ${err.message}`);
|
|
2924
|
+
}
|
|
2925
|
+
this.logger.error(`Brevo API error ${err.statusCode}:`, err.message);
|
|
2926
|
+
throw new Error(`Email sending failed: ${err.message}`);
|
|
2927
|
+
}
|
|
2928
|
+
throw err;
|
|
2929
|
+
}
|
|
2476
2930
|
}
|
|
2477
2931
|
};
|
|
2932
|
+
EmailService = _ts_decorate16([
|
|
2933
|
+
Injectable9(),
|
|
2934
|
+
_ts_metadata11("design:type", Function),
|
|
2935
|
+
_ts_metadata11("design:paramtypes", [
|
|
2936
|
+
typeof ConfigService5 === "undefined" ? Object : ConfigService5
|
|
2937
|
+
])
|
|
2938
|
+
], EmailService);
|
|
2478
2939
|
|
|
2479
|
-
// src/
|
|
2480
|
-
|
|
2481
|
-
var
|
|
2940
|
+
// src/email/email.module.ts
|
|
2941
|
+
function _ts_decorate17(decorators, target, key, desc2) {
|
|
2942
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
2943
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
2944
|
+
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;
|
|
2945
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2946
|
+
}
|
|
2947
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
2948
|
+
var EmailModule = class {
|
|
2482
2949
|
static {
|
|
2483
|
-
__name(this, "
|
|
2484
|
-
}
|
|
2485
|
-
constructor(detailOrOptions) {
|
|
2486
|
-
super(detailOrOptions ?? "Validation Failed", HttpStatus18.BAD_REQUEST);
|
|
2950
|
+
__name(this, "EmailModule");
|
|
2487
2951
|
}
|
|
2488
2952
|
};
|
|
2953
|
+
EmailModule = _ts_decorate17([
|
|
2954
|
+
Global4(),
|
|
2955
|
+
Module5({
|
|
2956
|
+
imports: [
|
|
2957
|
+
ConfigModule3
|
|
2958
|
+
],
|
|
2959
|
+
providers: [
|
|
2960
|
+
EmailService
|
|
2961
|
+
],
|
|
2962
|
+
exports: [
|
|
2963
|
+
EmailService
|
|
2964
|
+
]
|
|
2965
|
+
})
|
|
2966
|
+
], EmailModule);
|
|
2489
2967
|
|
|
2490
2968
|
// src/filters/http-exception.filter.ts
|
|
2491
|
-
import { Catch, HttpException as HttpException2, HttpStatus as HttpStatus19, Logger as
|
|
2492
|
-
function
|
|
2493
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2494
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
2969
|
+
import { Catch, HttpException as HttpException2, HttpStatus as HttpStatus19, Logger as Logger11 } from "@nestjs/common";
|
|
2970
|
+
function _ts_decorate18(decorators, target, key, desc2) {
|
|
2971
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
2972
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
2495
2973
|
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;
|
|
2496
2974
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2497
2975
|
}
|
|
2498
|
-
__name(
|
|
2976
|
+
__name(_ts_decorate18, "_ts_decorate");
|
|
2499
2977
|
function getHttpStatusTitle(status) {
|
|
2500
2978
|
const enumKey = Object.entries(HttpStatus19).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
|
|
2501
2979
|
if (!enumKey) {
|
|
@@ -2508,7 +2986,7 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2508
2986
|
static {
|
|
2509
2987
|
__name(this, "HttpExceptionFilter");
|
|
2510
2988
|
}
|
|
2511
|
-
logger = new
|
|
2989
|
+
logger = new Logger11(_HttpExceptionFilter.name);
|
|
2512
2990
|
catch(exception, host) {
|
|
2513
2991
|
const ctx = host.switchToHttp();
|
|
2514
2992
|
const response = ctx.getResponse();
|
|
@@ -2548,10 +3026,14 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2548
3026
|
} else if (typeof exceptionResponse === "string") {
|
|
2549
3027
|
detail = exceptionResponse;
|
|
2550
3028
|
}
|
|
3029
|
+
} else if (this.isAxiosError(exception)) {
|
|
3030
|
+
const axiosStatus = exception.response?.status;
|
|
3031
|
+
const axiosDetail = exception.response?.data?.message || exception.response?.data?.detail || exception.message;
|
|
3032
|
+
const url = exception.config?.url;
|
|
3033
|
+
status = HttpStatus19.BAD_GATEWAY;
|
|
3034
|
+
detail = `Upstream service error${axiosStatus ? ` (${axiosStatus})` : ""}: ${axiosDetail}`;
|
|
3035
|
+
this.logger.error(`Upstream API error [${axiosStatus}]: ${axiosDetail} \u2014 URL: ${url}`, exception.stack);
|
|
2551
3036
|
} else {
|
|
2552
|
-
const errorMessage = exception instanceof Error ? exception.message : "Unknown error";
|
|
2553
|
-
const stack = exception instanceof Error ? exception.stack : void 0;
|
|
2554
|
-
this.logger.error(`Unexpected error: ${errorMessage}`, stack);
|
|
2555
3037
|
detail = "An unexpected error occurred";
|
|
2556
3038
|
}
|
|
2557
3039
|
const problemDetails = {
|
|
@@ -2567,17 +3049,21 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2567
3049
|
};
|
|
2568
3050
|
response.header("Content-Type", "application/problem+json").status(status).send(problemDetails);
|
|
2569
3051
|
}
|
|
3052
|
+
// Duck-type check for AxiosError without importing axios
|
|
3053
|
+
isAxiosError(error) {
|
|
3054
|
+
return error instanceof Error && error.isAxiosError === true;
|
|
3055
|
+
}
|
|
2570
3056
|
};
|
|
2571
|
-
HttpExceptionFilter =
|
|
3057
|
+
HttpExceptionFilter = _ts_decorate18([
|
|
2572
3058
|
Catch()
|
|
2573
3059
|
], HttpExceptionFilter);
|
|
2574
3060
|
|
|
2575
3061
|
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2576
|
-
import { Injectable as
|
|
3062
|
+
import { Injectable as Injectable11, Optional as Optional2 } from "@nestjs/common";
|
|
2577
3063
|
import { catchError, tap } from "rxjs/operators";
|
|
2578
3064
|
|
|
2579
3065
|
// src/logger/services/logger.service.ts
|
|
2580
|
-
import { Injectable as
|
|
3066
|
+
import { Injectable as Injectable10, Optional } from "@nestjs/common";
|
|
2581
3067
|
import { createLogger, format, transports } from "winston";
|
|
2582
3068
|
import DailyRotateFile from "winston-daily-rotate-file";
|
|
2583
3069
|
|
|
@@ -2615,23 +3101,23 @@ function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_C
|
|
|
2615
3101
|
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
2616
3102
|
|
|
2617
3103
|
// src/logger/services/logger.service.ts
|
|
2618
|
-
function
|
|
2619
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2620
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3104
|
+
function _ts_decorate19(decorators, target, key, desc2) {
|
|
3105
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
3106
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
2621
3107
|
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;
|
|
2622
3108
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2623
3109
|
}
|
|
2624
|
-
__name(
|
|
2625
|
-
function
|
|
3110
|
+
__name(_ts_decorate19, "_ts_decorate");
|
|
3111
|
+
function _ts_metadata12(k, v) {
|
|
2626
3112
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2627
3113
|
}
|
|
2628
|
-
__name(
|
|
2629
|
-
function
|
|
3114
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
3115
|
+
function _ts_param5(paramIndex, decorator) {
|
|
2630
3116
|
return function(target, key) {
|
|
2631
3117
|
decorator(target, key, paramIndex);
|
|
2632
3118
|
};
|
|
2633
3119
|
}
|
|
2634
|
-
__name(
|
|
3120
|
+
__name(_ts_param5, "_ts_param");
|
|
2635
3121
|
var LoggerService = class _LoggerService {
|
|
2636
3122
|
static {
|
|
2637
3123
|
__name(this, "LoggerService");
|
|
@@ -2823,35 +3309,35 @@ ${trace}`;
|
|
|
2823
3309
|
return childLogger;
|
|
2824
3310
|
}
|
|
2825
3311
|
};
|
|
2826
|
-
LoggerService =
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
3312
|
+
LoggerService = _ts_decorate19([
|
|
3313
|
+
Injectable10(),
|
|
3314
|
+
_ts_param5(0, Optional()),
|
|
3315
|
+
_ts_param5(1, Optional()),
|
|
3316
|
+
_ts_metadata12("design:type", Function),
|
|
3317
|
+
_ts_metadata12("design:paramtypes", [
|
|
2832
3318
|
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
2833
3319
|
typeof Logger === "undefined" ? Object : Logger
|
|
2834
3320
|
])
|
|
2835
3321
|
], LoggerService);
|
|
2836
3322
|
|
|
2837
3323
|
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2838
|
-
function
|
|
2839
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2840
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3324
|
+
function _ts_decorate20(decorators, target, key, desc2) {
|
|
3325
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
3326
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
2841
3327
|
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;
|
|
2842
3328
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2843
3329
|
}
|
|
2844
|
-
__name(
|
|
2845
|
-
function
|
|
3330
|
+
__name(_ts_decorate20, "_ts_decorate");
|
|
3331
|
+
function _ts_metadata13(k, v) {
|
|
2846
3332
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2847
3333
|
}
|
|
2848
|
-
__name(
|
|
2849
|
-
function
|
|
3334
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
3335
|
+
function _ts_param6(paramIndex, decorator) {
|
|
2850
3336
|
return function(target, key) {
|
|
2851
3337
|
decorator(target, key, paramIndex);
|
|
2852
3338
|
};
|
|
2853
3339
|
}
|
|
2854
|
-
__name(
|
|
3340
|
+
__name(_ts_param6, "_ts_param");
|
|
2855
3341
|
var HttpLoggerInterceptor = class {
|
|
2856
3342
|
static {
|
|
2857
3343
|
__name(this, "HttpLoggerInterceptor");
|
|
@@ -2954,32 +3440,32 @@ var HttpLoggerInterceptor = class {
|
|
|
2954
3440
|
}
|
|
2955
3441
|
}
|
|
2956
3442
|
};
|
|
2957
|
-
HttpLoggerInterceptor =
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
3443
|
+
HttpLoggerInterceptor = _ts_decorate20([
|
|
3444
|
+
Injectable11(),
|
|
3445
|
+
_ts_param6(1, Optional2()),
|
|
3446
|
+
_ts_metadata13("design:type", Function),
|
|
3447
|
+
_ts_metadata13("design:paramtypes", [
|
|
2962
3448
|
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2963
3449
|
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2964
3450
|
])
|
|
2965
3451
|
], HttpLoggerInterceptor);
|
|
2966
3452
|
|
|
2967
3453
|
// src/logger/logger.module.ts
|
|
2968
|
-
import { Global as Global5, Logger as
|
|
3454
|
+
import { Global as Global5, Logger as Logger12, Module as Module6 } from "@nestjs/common";
|
|
2969
3455
|
|
|
2970
3456
|
// src/logger/middleware/correlation-id.middleware.ts
|
|
2971
|
-
import { Injectable as
|
|
2972
|
-
function
|
|
2973
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
2974
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3457
|
+
import { Injectable as Injectable12 } from "@nestjs/common";
|
|
3458
|
+
function _ts_decorate21(decorators, target, key, desc2) {
|
|
3459
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
3460
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
2975
3461
|
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;
|
|
2976
3462
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2977
3463
|
}
|
|
2978
|
-
__name(
|
|
2979
|
-
function
|
|
3464
|
+
__name(_ts_decorate21, "_ts_decorate");
|
|
3465
|
+
function _ts_metadata14(k, v) {
|
|
2980
3466
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2981
3467
|
}
|
|
2982
|
-
__name(
|
|
3468
|
+
__name(_ts_metadata14, "_ts_metadata");
|
|
2983
3469
|
var CorrelationIdMiddleware = class {
|
|
2984
3470
|
static {
|
|
2985
3471
|
__name(this, "CorrelationIdMiddleware");
|
|
@@ -3016,22 +3502,22 @@ var CorrelationIdMiddleware = class {
|
|
|
3016
3502
|
}
|
|
3017
3503
|
}
|
|
3018
3504
|
};
|
|
3019
|
-
CorrelationIdMiddleware =
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3505
|
+
CorrelationIdMiddleware = _ts_decorate21([
|
|
3506
|
+
Injectable12(),
|
|
3507
|
+
_ts_metadata14("design:type", Function),
|
|
3508
|
+
_ts_metadata14("design:paramtypes", [
|
|
3023
3509
|
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
3024
3510
|
])
|
|
3025
3511
|
], CorrelationIdMiddleware);
|
|
3026
3512
|
|
|
3027
3513
|
// src/logger/logger.module.ts
|
|
3028
|
-
function
|
|
3029
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3030
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3514
|
+
function _ts_decorate22(decorators, target, key, desc2) {
|
|
3515
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
3516
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
3031
3517
|
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;
|
|
3032
3518
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3033
3519
|
}
|
|
3034
|
-
__name(
|
|
3520
|
+
__name(_ts_decorate22, "_ts_decorate");
|
|
3035
3521
|
var LOGGER_MODULE_OPTIONS = Symbol("LOGGER_MODULE_OPTIONS");
|
|
3036
3522
|
var DEFAULT_LOGGER_OPTIONS = {
|
|
3037
3523
|
provider: "winston",
|
|
@@ -3108,9 +3594,9 @@ function mergeWithDefaults(options = {}) {
|
|
|
3108
3594
|
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
3109
3595
|
function createDefaultLoggerProvider(options) {
|
|
3110
3596
|
return {
|
|
3111
|
-
provide:
|
|
3597
|
+
provide: Logger12,
|
|
3112
3598
|
useFactory: /* @__PURE__ */ __name(() => {
|
|
3113
|
-
const logger = new
|
|
3599
|
+
const logger = new Logger12();
|
|
3114
3600
|
if (options.level) {
|
|
3115
3601
|
const levels = getLevelsUpTo(options.level);
|
|
3116
3602
|
logger.setLogLevels?.(levels);
|
|
@@ -3140,7 +3626,7 @@ function createLoggerProviders(options = {}) {
|
|
|
3140
3626
|
inject: [
|
|
3141
3627
|
LOGGER_MODULE_OPTIONS,
|
|
3142
3628
|
{
|
|
3143
|
-
token:
|
|
3629
|
+
token: Logger12,
|
|
3144
3630
|
optional: true
|
|
3145
3631
|
}
|
|
3146
3632
|
]
|
|
@@ -3219,10 +3705,10 @@ var LoggerModule = class _LoggerModule {
|
|
|
3219
3705
|
...asyncProviders,
|
|
3220
3706
|
// Default logger provider
|
|
3221
3707
|
{
|
|
3222
|
-
provide:
|
|
3708
|
+
provide: Logger12,
|
|
3223
3709
|
useFactory: /* @__PURE__ */ __name((opts) => {
|
|
3224
3710
|
if (opts.provider === "default") {
|
|
3225
|
-
const logger = new
|
|
3711
|
+
const logger = new Logger12();
|
|
3226
3712
|
if (opts.level) {
|
|
3227
3713
|
const levels = getLevelsUpTo(opts.level);
|
|
3228
3714
|
logger.setLogLevels?.(levels);
|
|
@@ -3244,7 +3730,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3244
3730
|
inject: [
|
|
3245
3731
|
LOGGER_MODULE_OPTIONS,
|
|
3246
3732
|
{
|
|
3247
|
-
token:
|
|
3733
|
+
token: Logger12,
|
|
3248
3734
|
optional: true
|
|
3249
3735
|
}
|
|
3250
3736
|
]
|
|
@@ -3343,13 +3829,13 @@ var LoggerModule = class _LoggerModule {
|
|
|
3343
3829
|
throw new Error("LoggerModule.forRootAsync() requires one of: useFactory, useClass, or useExisting");
|
|
3344
3830
|
}
|
|
3345
3831
|
};
|
|
3346
|
-
LoggerModule =
|
|
3832
|
+
LoggerModule = _ts_decorate22([
|
|
3347
3833
|
Global5(),
|
|
3348
|
-
|
|
3834
|
+
Module6({})
|
|
3349
3835
|
], LoggerModule);
|
|
3350
3836
|
|
|
3351
3837
|
// src/root/root.module.ts
|
|
3352
|
-
import { Module as
|
|
3838
|
+
import { Module as Module7 } from "@nestjs/common";
|
|
3353
3839
|
|
|
3354
3840
|
// src/root/controllers/app.controller.ts
|
|
3355
3841
|
import { Controller, Get } from "@nestjs/common";
|
|
@@ -3370,14 +3856,14 @@ function ApiHealthCheck() {
|
|
|
3370
3856
|
__name(ApiHealthCheck, "ApiHealthCheck");
|
|
3371
3857
|
|
|
3372
3858
|
// src/root/services/app.service.ts
|
|
3373
|
-
import { Injectable as
|
|
3374
|
-
function
|
|
3375
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3376
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3859
|
+
import { Injectable as Injectable13 } from "@nestjs/common";
|
|
3860
|
+
function _ts_decorate23(decorators, target, key, desc2) {
|
|
3861
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
3862
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
3377
3863
|
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;
|
|
3378
3864
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3379
3865
|
}
|
|
3380
|
-
__name(
|
|
3866
|
+
__name(_ts_decorate23, "_ts_decorate");
|
|
3381
3867
|
var AppService = class {
|
|
3382
3868
|
static {
|
|
3383
3869
|
__name(this, "AppService");
|
|
@@ -3387,22 +3873,22 @@ var AppService = class {
|
|
|
3387
3873
|
return `Hello World!`;
|
|
3388
3874
|
}
|
|
3389
3875
|
};
|
|
3390
|
-
AppService =
|
|
3391
|
-
|
|
3876
|
+
AppService = _ts_decorate23([
|
|
3877
|
+
Injectable13()
|
|
3392
3878
|
], AppService);
|
|
3393
3879
|
|
|
3394
3880
|
// src/root/controllers/app.controller.ts
|
|
3395
|
-
function
|
|
3396
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3397
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3881
|
+
function _ts_decorate24(decorators, target, key, desc2) {
|
|
3882
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
3883
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
3398
3884
|
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;
|
|
3399
3885
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3400
3886
|
}
|
|
3401
|
-
__name(
|
|
3402
|
-
function
|
|
3887
|
+
__name(_ts_decorate24, "_ts_decorate");
|
|
3888
|
+
function _ts_metadata15(k, v) {
|
|
3403
3889
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3404
3890
|
}
|
|
3405
|
-
__name(
|
|
3891
|
+
__name(_ts_metadata15, "_ts_metadata");
|
|
3406
3892
|
var AppController = class {
|
|
3407
3893
|
static {
|
|
3408
3894
|
__name(this, "AppController");
|
|
@@ -3416,19 +3902,19 @@ var AppController = class {
|
|
|
3416
3902
|
return this.appService.getHello();
|
|
3417
3903
|
}
|
|
3418
3904
|
};
|
|
3419
|
-
|
|
3905
|
+
_ts_decorate24([
|
|
3420
3906
|
Get(),
|
|
3421
3907
|
Public(),
|
|
3422
3908
|
ApiHealthCheck(),
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3909
|
+
_ts_metadata15("design:type", Function),
|
|
3910
|
+
_ts_metadata15("design:paramtypes", []),
|
|
3911
|
+
_ts_metadata15("design:returntype", String)
|
|
3426
3912
|
], AppController.prototype, "getHello", null);
|
|
3427
|
-
AppController =
|
|
3913
|
+
AppController = _ts_decorate24([
|
|
3428
3914
|
ApiTags("Health"),
|
|
3429
3915
|
Controller(),
|
|
3430
|
-
|
|
3431
|
-
|
|
3916
|
+
_ts_metadata15("design:type", Function),
|
|
3917
|
+
_ts_metadata15("design:paramtypes", [
|
|
3432
3918
|
typeof AppService === "undefined" ? Object : AppService
|
|
3433
3919
|
])
|
|
3434
3920
|
], AppController);
|
|
@@ -3465,23 +3951,23 @@ function ApiGetCsrfToken() {
|
|
|
3465
3951
|
__name(ApiGetCsrfToken, "ApiGetCsrfToken");
|
|
3466
3952
|
|
|
3467
3953
|
// src/root/controllers/csrf.controller.ts
|
|
3468
|
-
function
|
|
3469
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3470
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
3954
|
+
function _ts_decorate25(decorators, target, key, desc2) {
|
|
3955
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
3956
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
3471
3957
|
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;
|
|
3472
3958
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3473
3959
|
}
|
|
3474
|
-
__name(
|
|
3475
|
-
function
|
|
3960
|
+
__name(_ts_decorate25, "_ts_decorate");
|
|
3961
|
+
function _ts_metadata16(k, v) {
|
|
3476
3962
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3477
3963
|
}
|
|
3478
|
-
__name(
|
|
3479
|
-
function
|
|
3964
|
+
__name(_ts_metadata16, "_ts_metadata");
|
|
3965
|
+
function _ts_param7(paramIndex, decorator) {
|
|
3480
3966
|
return function(target, key) {
|
|
3481
3967
|
decorator(target, key, paramIndex);
|
|
3482
3968
|
};
|
|
3483
3969
|
}
|
|
3484
|
-
__name(
|
|
3970
|
+
__name(_ts_param7, "_ts_param");
|
|
3485
3971
|
var CsrfController = class {
|
|
3486
3972
|
static {
|
|
3487
3973
|
__name(this, "CsrfController");
|
|
@@ -3494,40 +3980,40 @@ var CsrfController = class {
|
|
|
3494
3980
|
};
|
|
3495
3981
|
}
|
|
3496
3982
|
};
|
|
3497
|
-
|
|
3983
|
+
_ts_decorate25([
|
|
3498
3984
|
Get2("token"),
|
|
3499
3985
|
Public(),
|
|
3500
3986
|
HttpCode(HttpStatus20.OK),
|
|
3501
3987
|
ApiGetCsrfToken(),
|
|
3502
|
-
|
|
3988
|
+
_ts_param7(0, Res({
|
|
3503
3989
|
passthrough: true
|
|
3504
3990
|
})),
|
|
3505
|
-
|
|
3506
|
-
|
|
3991
|
+
_ts_metadata16("design:type", Function),
|
|
3992
|
+
_ts_metadata16("design:paramtypes", [
|
|
3507
3993
|
typeof FastifyReply === "undefined" ? Object : FastifyReply
|
|
3508
3994
|
]),
|
|
3509
|
-
|
|
3995
|
+
_ts_metadata16("design:returntype", Object)
|
|
3510
3996
|
], CsrfController.prototype, "getToken", null);
|
|
3511
|
-
CsrfController =
|
|
3997
|
+
CsrfController = _ts_decorate25([
|
|
3512
3998
|
ApiTags2("CSRF"),
|
|
3513
3999
|
Controller2("csrf")
|
|
3514
4000
|
], CsrfController);
|
|
3515
4001
|
|
|
3516
4002
|
// src/root/root.module.ts
|
|
3517
|
-
function
|
|
3518
|
-
var c = arguments.length, r = c < 3 ? target :
|
|
3519
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key,
|
|
4003
|
+
function _ts_decorate26(decorators, target, key, desc2) {
|
|
4004
|
+
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
4005
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
3520
4006
|
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;
|
|
3521
4007
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3522
4008
|
}
|
|
3523
|
-
__name(
|
|
4009
|
+
__name(_ts_decorate26, "_ts_decorate");
|
|
3524
4010
|
var RootModule = class {
|
|
3525
4011
|
static {
|
|
3526
4012
|
__name(this, "RootModule");
|
|
3527
4013
|
}
|
|
3528
4014
|
};
|
|
3529
|
-
RootModule =
|
|
3530
|
-
|
|
4015
|
+
RootModule = _ts_decorate26([
|
|
4016
|
+
Module7({
|
|
3531
4017
|
controllers: [
|
|
3532
4018
|
AppController,
|
|
3533
4019
|
CsrfController
|
|
@@ -3752,18 +4238,23 @@ export {
|
|
|
3752
4238
|
AuthConfigModule,
|
|
3753
4239
|
BadGatewayException,
|
|
3754
4240
|
BadRequestException,
|
|
4241
|
+
CACHE_PROVIDER,
|
|
4242
|
+
CacheModule,
|
|
4243
|
+
CacheService,
|
|
3755
4244
|
ConflictException,
|
|
4245
|
+
CookieDomain,
|
|
3756
4246
|
CorrelationIdMiddleware,
|
|
3757
4247
|
DEFAULT_CORRELATION_HEADER,
|
|
3758
4248
|
DatabaseModule,
|
|
3759
4249
|
EmailModule,
|
|
3760
4250
|
EmailService,
|
|
3761
|
-
|
|
4251
|
+
FilterProcessor,
|
|
4252
|
+
ForbiddenException,
|
|
3762
4253
|
GoneException,
|
|
3763
4254
|
HttpExceptionFilter,
|
|
3764
4255
|
HttpLoggerInterceptor,
|
|
3765
4256
|
HttpProblemException,
|
|
3766
|
-
|
|
4257
|
+
InternalServerErrorException,
|
|
3767
4258
|
JwtAuthService,
|
|
3768
4259
|
LOGGER_MODULE_OPTIONS,
|
|
3769
4260
|
LoggerModule,
|
|
@@ -3778,6 +4269,8 @@ export {
|
|
|
3778
4269
|
PrimaryDatabaseService,
|
|
3779
4270
|
Public,
|
|
3780
4271
|
RESET_KEY,
|
|
4272
|
+
RedisCacheProvider,
|
|
4273
|
+
RefreshCookieOptions,
|
|
3781
4274
|
RefreshTokenCookie,
|
|
3782
4275
|
RequestTimeoutException,
|
|
3783
4276
|
Reset,
|
|
@@ -3787,13 +4280,15 @@ export {
|
|
|
3787
4280
|
ServiceUnavailableException,
|
|
3788
4281
|
SessionData,
|
|
3789
4282
|
SkipCsrf,
|
|
4283
|
+
SuccessResponseDto,
|
|
4284
|
+
TableResponseDto,
|
|
3790
4285
|
Tenant,
|
|
3791
4286
|
TenantBaseRepository,
|
|
3792
4287
|
TenantContextService,
|
|
3793
4288
|
TenantDatabaseService,
|
|
3794
4289
|
TokenType,
|
|
3795
4290
|
TooManyRequestsException,
|
|
3796
|
-
|
|
4291
|
+
UnauthorizedException,
|
|
3797
4292
|
UnprocessableEntityException,
|
|
3798
4293
|
UnsupportedMediaTypeException,
|
|
3799
4294
|
UserId,
|
|
@@ -3810,6 +4305,7 @@ export {
|
|
|
3810
4305
|
getHttpStatusTitle,
|
|
3811
4306
|
getJwtExpiry,
|
|
3812
4307
|
getRefreshCookieOptions,
|
|
4308
|
+
getRefreshCookieOptionsForHost,
|
|
3813
4309
|
getTokenExpiry,
|
|
3814
4310
|
hashToken,
|
|
3815
4311
|
jwtConfigFactory,
|