@vritti/api-sdk 0.1.3 → 0.1.5
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 +821 -798
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +672 -650
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -48,7 +48,7 @@ __export(index_exports, {
|
|
|
48
48
|
InternalServerErrorException: () => InternalServerErrorException3,
|
|
49
49
|
LOGGER_MODULE_OPTIONS: () => LOGGER_MODULE_OPTIONS,
|
|
50
50
|
LoggerModule: () => LoggerModule,
|
|
51
|
-
LoggerService: () =>
|
|
51
|
+
LoggerService: () => LoggerService,
|
|
52
52
|
MethodNotAllowedException: () => MethodNotAllowedException,
|
|
53
53
|
NotAcceptableException: () => NotAcceptableException,
|
|
54
54
|
NotFoundException: () => NotFoundException,
|
|
@@ -56,18 +56,19 @@ __export(index_exports, {
|
|
|
56
56
|
Onboarding: () => Onboarding,
|
|
57
57
|
PayloadTooLargeException: () => PayloadTooLargeException,
|
|
58
58
|
PrimaryBaseRepository: () => PrimaryBaseRepository,
|
|
59
|
-
PrimaryDatabaseService: () =>
|
|
59
|
+
PrimaryDatabaseService: () => PrimaryDatabaseService,
|
|
60
60
|
Public: () => Public,
|
|
61
61
|
RequestTimeoutException: () => RequestTimeoutException,
|
|
62
62
|
ServiceUnavailableException: () => ServiceUnavailableException,
|
|
63
63
|
Tenant: () => Tenant,
|
|
64
64
|
TenantBaseRepository: () => TenantBaseRepository,
|
|
65
|
-
TenantContextService: () =>
|
|
65
|
+
TenantContextService: () => TenantContextService,
|
|
66
66
|
TenantDatabaseService: () => TenantDatabaseService,
|
|
67
67
|
TooManyRequestsException: () => TooManyRequestsException,
|
|
68
68
|
UnauthorizedException: () => UnauthorizedException4,
|
|
69
69
|
UnprocessableEntityException: () => UnprocessableEntityException,
|
|
70
70
|
UnsupportedMediaTypeException: () => UnsupportedMediaTypeException,
|
|
71
|
+
UserId: () => UserId,
|
|
71
72
|
ValidationException: () => ValidationException,
|
|
72
73
|
VrittiAuthGuard: () => VrittiAuthGuard,
|
|
73
74
|
addCorrelationIdToResponse: () => addCorrelationIdToResponse,
|
|
@@ -89,10 +90,10 @@ __export(index_exports, {
|
|
|
89
90
|
module.exports = __toCommonJS(index_exports);
|
|
90
91
|
|
|
91
92
|
// src/auth/auth-config.module.ts
|
|
92
|
-
var
|
|
93
|
-
var
|
|
94
|
-
var
|
|
95
|
-
var
|
|
93
|
+
var import_common5 = require("@nestjs/common");
|
|
94
|
+
var import_config4 = require("@nestjs/config");
|
|
95
|
+
var import_core3 = require("@nestjs/core");
|
|
96
|
+
var import_jwt2 = require("@nestjs/jwt");
|
|
96
97
|
|
|
97
98
|
// src/request/request.module.ts
|
|
98
99
|
var import_common2 = require("@nestjs/common");
|
|
@@ -193,7 +194,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
193
194
|
};
|
|
194
195
|
}
|
|
195
196
|
__name(_ts_param, "_ts_param");
|
|
196
|
-
var
|
|
197
|
+
var RequestService = class {
|
|
197
198
|
static {
|
|
198
199
|
__name(this, "RequestService");
|
|
199
200
|
}
|
|
@@ -262,7 +263,7 @@ var RequestService2 = class {
|
|
|
262
263
|
return this.request.headers || {};
|
|
263
264
|
}
|
|
264
265
|
};
|
|
265
|
-
|
|
266
|
+
RequestService = _ts_decorate([
|
|
266
267
|
(0, import_common.Injectable)({
|
|
267
268
|
scope: import_common.Scope.REQUEST
|
|
268
269
|
}),
|
|
@@ -271,7 +272,7 @@ RequestService2 = _ts_decorate([
|
|
|
271
272
|
_ts_metadata("design:paramtypes", [
|
|
272
273
|
typeof FastifyRequest === "undefined" ? Object : FastifyRequest
|
|
273
274
|
])
|
|
274
|
-
],
|
|
275
|
+
], RequestService);
|
|
275
276
|
|
|
276
277
|
// src/request/request.module.ts
|
|
277
278
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -290,16 +291,256 @@ RequestModule = _ts_decorate2([
|
|
|
290
291
|
(0, import_common2.Global)(),
|
|
291
292
|
(0, import_common2.Module)({
|
|
292
293
|
providers: [
|
|
293
|
-
|
|
294
|
+
RequestService
|
|
294
295
|
],
|
|
295
296
|
exports: [
|
|
296
|
-
|
|
297
|
+
RequestService
|
|
297
298
|
]
|
|
298
299
|
})
|
|
299
300
|
], RequestModule);
|
|
300
301
|
|
|
301
302
|
// src/auth/guards/vritti-auth.guard.ts
|
|
303
|
+
var import_common4 = require("@nestjs/common");
|
|
304
|
+
var import_config2 = require("@nestjs/config");
|
|
305
|
+
var import_core2 = require("@nestjs/core");
|
|
306
|
+
var import_jwt = require("@nestjs/jwt");
|
|
307
|
+
|
|
308
|
+
// src/database/services/primary-database.service.ts
|
|
302
309
|
var import_common3 = require("@nestjs/common");
|
|
310
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
311
|
+
var import_node_postgres = require("drizzle-orm/node-postgres");
|
|
312
|
+
var import_pg = require("pg");
|
|
313
|
+
|
|
314
|
+
// src/database/constants.ts
|
|
315
|
+
var DATABASE_MODULE_OPTIONS = Symbol("DATABASE_MODULE_OPTIONS");
|
|
316
|
+
|
|
317
|
+
// src/database/services/primary-database.service.ts
|
|
318
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
319
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
320
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
321
|
+
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;
|
|
322
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
323
|
+
}
|
|
324
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
325
|
+
function _ts_metadata2(k, v) {
|
|
326
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
327
|
+
}
|
|
328
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
329
|
+
function _ts_param2(paramIndex, decorator) {
|
|
330
|
+
return function(target, key) {
|
|
331
|
+
decorator(target, key, paramIndex);
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
__name(_ts_param2, "_ts_param");
|
|
335
|
+
var PrimaryDatabaseService = class _PrimaryDatabaseService {
|
|
336
|
+
static {
|
|
337
|
+
__name(this, "PrimaryDatabaseService");
|
|
338
|
+
}
|
|
339
|
+
options;
|
|
340
|
+
logger = new import_common3.Logger(_PrimaryDatabaseService.name);
|
|
341
|
+
/** PostgreSQL connection pool */
|
|
342
|
+
pool = null;
|
|
343
|
+
/** Drizzle database instance */
|
|
344
|
+
db = null;
|
|
345
|
+
/** In-memory cache: Map<tenantIdentifier, TenantConfig> */
|
|
346
|
+
tenantConfigCache = /* @__PURE__ */ new Map();
|
|
347
|
+
/** Cache TTL in milliseconds */
|
|
348
|
+
cacheTTL;
|
|
349
|
+
constructor(options) {
|
|
350
|
+
this.options = options;
|
|
351
|
+
this.cacheTTL = options.connectionCacheTTL || 3e5;
|
|
352
|
+
}
|
|
353
|
+
async onModuleInit() {
|
|
354
|
+
if (this.options.primaryDb) {
|
|
355
|
+
await this.initializeDrizzleClient();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Initialize connection to primary database using Drizzle
|
|
360
|
+
*/
|
|
361
|
+
async initializeDrizzleClient() {
|
|
362
|
+
try {
|
|
363
|
+
const databaseUrl = this.buildPrimaryDbUrl();
|
|
364
|
+
this.pool = new import_pg.Pool({
|
|
365
|
+
connectionString: databaseUrl,
|
|
366
|
+
max: this.options.maxConnections || 10
|
|
367
|
+
});
|
|
368
|
+
this.logger.debug(`Schema keys passed to drizzle: [${Object.keys(this.options.drizzleSchema || {}).join(", ")}]`);
|
|
369
|
+
this.logger.debug(`Relations keys passed to drizzle: [${Object.keys(this.options.drizzleRelations || {}).join(", ")}]`);
|
|
370
|
+
this.db = (0, import_node_postgres.drizzle)({
|
|
371
|
+
client: this.pool,
|
|
372
|
+
schema: this.options.drizzleSchema,
|
|
373
|
+
relations: this.options.drizzleRelations
|
|
374
|
+
});
|
|
375
|
+
this.logger.debug(`Drizzle query keys after init: [${Object.keys(this.db.query || {}).join(", ")}]`);
|
|
376
|
+
await this.pool.query("SELECT 1");
|
|
377
|
+
this.logger.log("Connected to primary database (tenant registry)");
|
|
378
|
+
} catch (error) {
|
|
379
|
+
this.logger.error("Failed to connect to primary database", error);
|
|
380
|
+
throw new import_common3.InternalServerErrorException("Failed to initialize tenant registry");
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Build connection URL from primary database properties
|
|
385
|
+
*/
|
|
386
|
+
buildPrimaryDbUrl() {
|
|
387
|
+
if (!this.options.primaryDb) {
|
|
388
|
+
throw new Error("Primary database configuration not provided");
|
|
389
|
+
}
|
|
390
|
+
const { host, port = 5432, username, password, database, schema = "public", sslMode = "require" } = this.options.primaryDb;
|
|
391
|
+
let url = `postgresql://${username}:${encodeURIComponent(password)}@${host}:${port}/${database}`;
|
|
392
|
+
const params = new URLSearchParams();
|
|
393
|
+
if (schema) {
|
|
394
|
+
params.set("schema", schema);
|
|
395
|
+
}
|
|
396
|
+
params.set("sslmode", sslMode);
|
|
397
|
+
const queryString = params.toString();
|
|
398
|
+
if (queryString) {
|
|
399
|
+
url += `?${queryString}`;
|
|
400
|
+
}
|
|
401
|
+
this.logger.debug(`Primary DB connection URL: ${this.maskPassword(url)}`);
|
|
402
|
+
return url;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Mask password in connection URL for logging
|
|
406
|
+
*/
|
|
407
|
+
maskPassword(url) {
|
|
408
|
+
return url.replace(/:([^@]+)@/, ":****@");
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get tenant configuration by identifier (ID or subdomain)
|
|
412
|
+
*
|
|
413
|
+
* @param tenantIdentifier Tenant ID or subdomain
|
|
414
|
+
* @returns Tenant configuration or null if not found
|
|
415
|
+
*/
|
|
416
|
+
async getTenantInfo(tenantIdentifier) {
|
|
417
|
+
const cached = this.tenantConfigCache.get(tenantIdentifier);
|
|
418
|
+
if (cached) {
|
|
419
|
+
this.logger.debug(`Cache hit for tenant: ${tenantIdentifier}`);
|
|
420
|
+
return cached;
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
if (!this.db) {
|
|
424
|
+
throw new Error("Primary database client not initialized");
|
|
425
|
+
}
|
|
426
|
+
this.logger.debug(`Querying primary database for tenant: ${tenantIdentifier}`);
|
|
427
|
+
const schema = this.options.drizzleSchema;
|
|
428
|
+
const { tenants, tenantDatabaseConfigs } = schema;
|
|
429
|
+
const result = await this.db.select().from(tenants).leftJoin(tenantDatabaseConfigs, (0, import_drizzle_orm.eq)(tenants.id, tenantDatabaseConfigs.tenantId)).where((0, import_drizzle_orm.or)((0, import_drizzle_orm.eq)(tenants.id, tenantIdentifier), (0, import_drizzle_orm.eq)(tenants.subdomain, tenantIdentifier))).limit(1);
|
|
430
|
+
if (!result.length) {
|
|
431
|
+
this.logger.warn(`Tenant not found: ${tenantIdentifier}`);
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
const row = result[0];
|
|
435
|
+
const tenant = row.tenants;
|
|
436
|
+
const config = row.tenant_database_configs;
|
|
437
|
+
if (tenant.status !== "ACTIVE") {
|
|
438
|
+
this.logger.warn(`Tenant not active: ${tenantIdentifier}`);
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
const info = {
|
|
442
|
+
id: tenant.id,
|
|
443
|
+
subdomain: tenant.subdomain,
|
|
444
|
+
type: tenant.dbType,
|
|
445
|
+
status: tenant.status,
|
|
446
|
+
// For SHARED tenants: schema name
|
|
447
|
+
schemaName: config?.dbSchema || void 0,
|
|
448
|
+
// For DEDICATED tenants: database configuration from TenantDatabaseConfig table
|
|
449
|
+
databaseName: config?.dbName || void 0,
|
|
450
|
+
databaseHost: config?.dbHost || void 0,
|
|
451
|
+
databasePort: config?.dbPort || void 0,
|
|
452
|
+
databaseUsername: config?.dbUsername ? this.decrypt(config.dbUsername) : void 0,
|
|
453
|
+
databasePassword: config?.dbPassword ? this.decrypt(config.dbPassword) : void 0,
|
|
454
|
+
databaseSslMode: config?.dbSslMode || void 0,
|
|
455
|
+
connectionPoolSize: config?.connectionPoolSize || void 0
|
|
456
|
+
};
|
|
457
|
+
this.cacheInfo(info);
|
|
458
|
+
return info;
|
|
459
|
+
} catch (error) {
|
|
460
|
+
this.logger.error(`Failed to fetch tenant info: ${tenantIdentifier}`, error);
|
|
461
|
+
throw new import_common3.InternalServerErrorException("Failed to resolve tenant");
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Cache tenant information with TTL
|
|
466
|
+
*/
|
|
467
|
+
cacheInfo(info) {
|
|
468
|
+
this.tenantConfigCache.set(info.id, info);
|
|
469
|
+
this.tenantConfigCache.set(info.subdomain, info);
|
|
470
|
+
setTimeout(() => {
|
|
471
|
+
this.tenantConfigCache.delete(info.id);
|
|
472
|
+
this.tenantConfigCache.delete(info.subdomain);
|
|
473
|
+
this.logger.debug(`Cache expired for tenant: ${info.subdomain}`);
|
|
474
|
+
}, this.cacheTTL);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Clear cached tenant information
|
|
478
|
+
*
|
|
479
|
+
* Useful when tenant settings are updated and cache needs to be invalidated
|
|
480
|
+
*
|
|
481
|
+
* @param tenantIdentifier Tenant ID or subdomain
|
|
482
|
+
*/
|
|
483
|
+
clearTenantCache(tenantIdentifier) {
|
|
484
|
+
const config = this.tenantConfigCache.get(tenantIdentifier);
|
|
485
|
+
if (config) {
|
|
486
|
+
this.tenantConfigCache.delete(config.id);
|
|
487
|
+
this.tenantConfigCache.delete(config.subdomain);
|
|
488
|
+
this.logger.log(`Cleared cache for tenant: ${tenantIdentifier}`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Clear all cached tenant configurations
|
|
493
|
+
*/
|
|
494
|
+
clearAllCaches() {
|
|
495
|
+
const size = this.tenantConfigCache.size;
|
|
496
|
+
this.tenantConfigCache.clear();
|
|
497
|
+
this.logger.log(`Cleared ${size} cached tenant configs`);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Get the Drizzle database instance for the primary database.
|
|
501
|
+
* This is a synchronous property that returns the initialized Drizzle client.
|
|
502
|
+
*
|
|
503
|
+
* @returns Primary database Drizzle instance
|
|
504
|
+
* @throws Error if primary database client is not initialized
|
|
505
|
+
*/
|
|
506
|
+
get drizzleClient() {
|
|
507
|
+
if (!this.db) {
|
|
508
|
+
throw new Error("Primary database client not initialized");
|
|
509
|
+
}
|
|
510
|
+
return this.db;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Get the Drizzle schema
|
|
514
|
+
*/
|
|
515
|
+
get schema() {
|
|
516
|
+
return this.options.drizzleSchema;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Decrypt database credentials
|
|
520
|
+
*
|
|
521
|
+
* Override this method to implement your encryption strategy
|
|
522
|
+
*
|
|
523
|
+
* @param encrypted Encrypted value
|
|
524
|
+
* @returns Decrypted value
|
|
525
|
+
*/
|
|
526
|
+
decrypt(encrypted) {
|
|
527
|
+
return encrypted;
|
|
528
|
+
}
|
|
529
|
+
async onModuleDestroy() {
|
|
530
|
+
if (this.pool) {
|
|
531
|
+
await this.pool.end();
|
|
532
|
+
this.logger.log("Disconnected from primary database");
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
PrimaryDatabaseService = _ts_decorate3([
|
|
537
|
+
(0, import_common3.Injectable)(),
|
|
538
|
+
_ts_param2(0, (0, import_common3.Inject)(DATABASE_MODULE_OPTIONS)),
|
|
539
|
+
_ts_metadata2("design:type", Function),
|
|
540
|
+
_ts_metadata2("design:paramtypes", [
|
|
541
|
+
typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions
|
|
542
|
+
])
|
|
543
|
+
], PrimaryDatabaseService);
|
|
303
544
|
|
|
304
545
|
// src/auth/utils/token-hash.util.ts
|
|
305
546
|
var crypto = __toESM(require("crypto"), 1);
|
|
@@ -315,17 +556,17 @@ function verifyTokenHash(token, expectedHash) {
|
|
|
315
556
|
__name(verifyTokenHash, "verifyTokenHash");
|
|
316
557
|
|
|
317
558
|
// src/auth/guards/vritti-auth.guard.ts
|
|
318
|
-
function
|
|
559
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
319
560
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
320
561
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
321
562
|
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;
|
|
322
563
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
323
564
|
}
|
|
324
|
-
__name(
|
|
325
|
-
function
|
|
565
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
566
|
+
function _ts_metadata3(k, v) {
|
|
326
567
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
327
568
|
}
|
|
328
|
-
__name(
|
|
569
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
329
570
|
var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
330
571
|
static {
|
|
331
572
|
__name(this, "VrittiAuthGuard");
|
|
@@ -335,7 +576,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
335
576
|
jwtService;
|
|
336
577
|
primaryDatabase;
|
|
337
578
|
requestService;
|
|
338
|
-
logger = new
|
|
579
|
+
logger = new import_common4.Logger(_VrittiAuthGuard.name);
|
|
339
580
|
constructor(reflector, _configService, jwtService, primaryDatabase, requestService) {
|
|
340
581
|
this.reflector = reflector;
|
|
341
582
|
this._configService = _configService;
|
|
@@ -361,17 +602,17 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
361
602
|
const accessToken = this.requestService.getAccessToken();
|
|
362
603
|
if (!accessToken) {
|
|
363
604
|
this.logger.warn("Access token not found in Authorization header");
|
|
364
|
-
throw new
|
|
605
|
+
throw new import_common4.UnauthorizedException("Access token not found");
|
|
365
606
|
}
|
|
366
607
|
const decodedToken = this.jwtService.decode(accessToken);
|
|
367
608
|
if (!decodedToken) {
|
|
368
609
|
this.logger.warn("Failed to decode access token");
|
|
369
|
-
throw new
|
|
610
|
+
throw new import_common4.UnauthorizedException("Invalid token format");
|
|
370
611
|
}
|
|
371
612
|
if (isOnboarding) {
|
|
372
613
|
if (decodedToken.type !== "onboarding") {
|
|
373
614
|
this.logger.warn("Onboarding endpoint requires onboarding token");
|
|
374
|
-
throw new
|
|
615
|
+
throw new import_common4.UnauthorizedException("This endpoint requires an onboarding token");
|
|
375
616
|
}
|
|
376
617
|
const validatedToken2 = this.validateAccessToken(accessToken);
|
|
377
618
|
this.logger.debug("Onboarding token validated successfully");
|
|
@@ -384,7 +625,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
384
625
|
}
|
|
385
626
|
if (decodedToken.type === "onboarding") {
|
|
386
627
|
this.logger.warn("Regular endpoint accessed with onboarding token");
|
|
387
|
-
throw new
|
|
628
|
+
throw new import_common4.UnauthorizedException("Onboarding tokens cannot access this endpoint");
|
|
388
629
|
}
|
|
389
630
|
const validatedToken = this.validateAccessToken(accessToken);
|
|
390
631
|
this.logger.debug("Access token validated successfully");
|
|
@@ -396,7 +637,7 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
396
637
|
const tenantIdentifier = this.requestService.getTenantIdentifier();
|
|
397
638
|
if (!tenantIdentifier) {
|
|
398
639
|
this.logger.warn("Tenant identifier not found in request");
|
|
399
|
-
throw new
|
|
640
|
+
throw new import_common4.UnauthorizedException("Tenant identifier not found");
|
|
400
641
|
}
|
|
401
642
|
this.logger.debug(`Tenant identifier extracted: ${tenantIdentifier}`);
|
|
402
643
|
if (tenantIdentifier === "cloud") {
|
|
@@ -406,20 +647,20 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
406
647
|
const tenantInfo = await this.primaryDatabase.getTenantInfo(tenantIdentifier);
|
|
407
648
|
if (!tenantInfo) {
|
|
408
649
|
this.logger.warn(`Invalid tenant: ${tenantIdentifier}`);
|
|
409
|
-
throw new
|
|
650
|
+
throw new import_common4.UnauthorizedException("Invalid tenant");
|
|
410
651
|
}
|
|
411
652
|
if (tenantInfo.status !== "ACTIVE") {
|
|
412
653
|
this.logger.warn(`Tenant ${tenantIdentifier} has status: ${tenantInfo.status}`);
|
|
413
|
-
throw new
|
|
654
|
+
throw new import_common4.UnauthorizedException(`Tenant is ${tenantInfo.status}`);
|
|
414
655
|
}
|
|
415
656
|
this.logger.debug(`Tenant validated: ${tenantInfo.subdomain} (${tenantInfo.type})`);
|
|
416
657
|
return true;
|
|
417
658
|
} catch (error) {
|
|
418
|
-
if (error instanceof
|
|
659
|
+
if (error instanceof import_common4.UnauthorizedException) {
|
|
419
660
|
throw error;
|
|
420
661
|
}
|
|
421
662
|
this.logger.error("Unexpected error in auth guard", error);
|
|
422
|
-
throw new
|
|
663
|
+
throw new import_common4.UnauthorizedException("Authentication failed");
|
|
423
664
|
}
|
|
424
665
|
}
|
|
425
666
|
/**
|
|
@@ -438,24 +679,24 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
438
679
|
}
|
|
439
680
|
return decoded;
|
|
440
681
|
} catch (error) {
|
|
441
|
-
if (error instanceof
|
|
682
|
+
if (error instanceof import_common4.UnauthorizedException) {
|
|
442
683
|
throw error;
|
|
443
684
|
}
|
|
444
685
|
const jwtError = error;
|
|
445
686
|
if (jwtError?.name === "TokenExpiredError") {
|
|
446
687
|
this.logger.warn(`Access token expired at: ${jwtError?.expiredAt}`);
|
|
447
|
-
throw new
|
|
688
|
+
throw new import_common4.UnauthorizedException("Access token has expired");
|
|
448
689
|
}
|
|
449
690
|
if (jwtError?.name === "JsonWebTokenError") {
|
|
450
691
|
this.logger.warn(`Access token verification failed: ${jwtError?.message}`);
|
|
451
|
-
throw new
|
|
692
|
+
throw new import_common4.UnauthorizedException("Invalid access token");
|
|
452
693
|
}
|
|
453
694
|
if (jwtError?.name === "NotBeforeError") {
|
|
454
695
|
this.logger.warn("Access token used before valid (nbf claim)");
|
|
455
|
-
throw new
|
|
696
|
+
throw new import_common4.UnauthorizedException("Access token not yet valid");
|
|
456
697
|
}
|
|
457
698
|
this.logger.error("Unexpected error validating access token", error);
|
|
458
|
-
throw new
|
|
699
|
+
throw new import_common4.UnauthorizedException("Access token validation failed");
|
|
459
700
|
}
|
|
460
701
|
}
|
|
461
702
|
/**
|
|
@@ -482,37 +723,37 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
482
723
|
const refreshToken = cookies[config.cookie.refreshCookieName];
|
|
483
724
|
if (!refreshToken) {
|
|
484
725
|
this.logger.warn("Session validation failed - refresh token cookie not found");
|
|
485
|
-
throw new
|
|
726
|
+
throw new import_common4.UnauthorizedException("Session validation failed");
|
|
486
727
|
}
|
|
487
728
|
if (!verifyTokenHash(refreshToken, validatedToken.refreshTokenHash)) {
|
|
488
729
|
this.logger.warn("Session validation failed - token binding mismatch");
|
|
489
|
-
throw new
|
|
730
|
+
throw new import_common4.UnauthorizedException("Session validation failed");
|
|
490
731
|
}
|
|
491
732
|
this.logger.debug("Token binding validated successfully");
|
|
492
733
|
}
|
|
493
734
|
};
|
|
494
|
-
VrittiAuthGuard =
|
|
495
|
-
(0,
|
|
496
|
-
scope:
|
|
735
|
+
VrittiAuthGuard = _ts_decorate4([
|
|
736
|
+
(0, import_common4.Injectable)({
|
|
737
|
+
scope: import_common4.Scope.REQUEST
|
|
497
738
|
}),
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
typeof Reflector === "undefined" ? Object : Reflector,
|
|
501
|
-
typeof ConfigService === "undefined" ? Object : ConfigService,
|
|
502
|
-
typeof JwtService === "undefined" ? Object : JwtService,
|
|
739
|
+
_ts_metadata3("design:type", Function),
|
|
740
|
+
_ts_metadata3("design:paramtypes", [
|
|
741
|
+
typeof import_core2.Reflector === "undefined" ? Object : import_core2.Reflector,
|
|
742
|
+
typeof import_config2.ConfigService === "undefined" ? Object : import_config2.ConfigService,
|
|
743
|
+
typeof import_jwt.JwtService === "undefined" ? Object : import_jwt.JwtService,
|
|
503
744
|
typeof PrimaryDatabaseService === "undefined" ? Object : PrimaryDatabaseService,
|
|
504
745
|
typeof RequestService === "undefined" ? Object : RequestService
|
|
505
746
|
])
|
|
506
747
|
], VrittiAuthGuard);
|
|
507
748
|
|
|
508
749
|
// src/auth/auth-config.module.ts
|
|
509
|
-
function
|
|
750
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
510
751
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
511
752
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
512
753
|
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;
|
|
513
754
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
514
755
|
}
|
|
515
|
-
__name(
|
|
756
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
516
757
|
var AuthConfigModule = class _AuthConfigModule {
|
|
517
758
|
static {
|
|
518
759
|
__name(this, "AuthConfigModule");
|
|
@@ -531,14 +772,14 @@ var AuthConfigModule = class _AuthConfigModule {
|
|
|
531
772
|
return {
|
|
532
773
|
module: _AuthConfigModule,
|
|
533
774
|
imports: [
|
|
534
|
-
|
|
775
|
+
import_config4.ConfigModule,
|
|
535
776
|
RequestModule,
|
|
536
|
-
|
|
777
|
+
import_jwt2.JwtModule.registerAsync({
|
|
537
778
|
imports: [
|
|
538
|
-
|
|
779
|
+
import_config4.ConfigModule
|
|
539
780
|
],
|
|
540
781
|
inject: [
|
|
541
|
-
|
|
782
|
+
import_config4.ConfigService
|
|
542
783
|
],
|
|
543
784
|
useFactory: /* @__PURE__ */ __name((config) => ({
|
|
544
785
|
secret: config.get("JWT_SECRET"),
|
|
@@ -550,56 +791,152 @@ var AuthConfigModule = class _AuthConfigModule {
|
|
|
550
791
|
],
|
|
551
792
|
providers: [
|
|
552
793
|
{
|
|
553
|
-
provide:
|
|
794
|
+
provide: import_core3.APP_GUARD,
|
|
554
795
|
useClass: VrittiAuthGuard
|
|
555
796
|
}
|
|
556
797
|
],
|
|
557
798
|
exports: [
|
|
558
|
-
|
|
799
|
+
import_jwt2.JwtModule
|
|
559
800
|
]
|
|
560
801
|
};
|
|
561
802
|
}
|
|
562
803
|
};
|
|
563
|
-
AuthConfigModule =
|
|
564
|
-
(0,
|
|
565
|
-
(0,
|
|
804
|
+
AuthConfigModule = _ts_decorate5([
|
|
805
|
+
(0, import_common5.Global)(),
|
|
806
|
+
(0, import_common5.Module)({})
|
|
566
807
|
], AuthConfigModule);
|
|
567
808
|
|
|
568
809
|
// src/auth/decorators/onboarding.decorator.ts
|
|
569
|
-
var
|
|
570
|
-
var Onboarding = /* @__PURE__ */ __name(() => (0,
|
|
810
|
+
var import_common6 = require("@nestjs/common");
|
|
811
|
+
var Onboarding = /* @__PURE__ */ __name(() => (0, import_common6.SetMetadata)("isOnboarding", true), "Onboarding");
|
|
571
812
|
|
|
572
813
|
// src/auth/decorators/public.decorator.ts
|
|
573
|
-
var
|
|
574
|
-
var Public = /* @__PURE__ */ __name(() => (0,
|
|
814
|
+
var import_common7 = require("@nestjs/common");
|
|
815
|
+
var Public = /* @__PURE__ */ __name(() => (0, import_common7.SetMetadata)("isPublic", true), "Public");
|
|
575
816
|
|
|
576
|
-
// src/
|
|
577
|
-
var
|
|
578
|
-
var
|
|
817
|
+
// src/auth/decorators/user-id.decorator.ts
|
|
818
|
+
var import_common8 = require("@nestjs/common");
|
|
819
|
+
var UserId = (0, import_common8.createParamDecorator)((_data, ctx) => {
|
|
820
|
+
const request = ctx.switchToHttp().getRequest();
|
|
821
|
+
const user = request.user;
|
|
822
|
+
if (!user?.id) {
|
|
823
|
+
throw new Error("User ID not found on request. Ensure route is protected by auth guard.");
|
|
824
|
+
}
|
|
825
|
+
return user.id;
|
|
826
|
+
});
|
|
579
827
|
|
|
580
|
-
// src/database/
|
|
581
|
-
var
|
|
828
|
+
// src/database/database.module.ts
|
|
829
|
+
var import_common13 = require("@nestjs/common");
|
|
830
|
+
var import_core5 = require("@nestjs/core");
|
|
582
831
|
|
|
583
832
|
// src/database/interceptors/message-tenant-context.interceptor.ts
|
|
584
|
-
var
|
|
833
|
+
var import_common10 = require("@nestjs/common");
|
|
585
834
|
var import_operators = require("rxjs/operators");
|
|
586
|
-
|
|
835
|
+
|
|
836
|
+
// src/database/services/tenant-context.service.ts
|
|
837
|
+
var import_common9 = require("@nestjs/common");
|
|
838
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
587
839
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
588
840
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
589
841
|
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;
|
|
590
842
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
591
843
|
}
|
|
592
|
-
__name(
|
|
593
|
-
|
|
844
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
845
|
+
var TenantContextService = class {
|
|
846
|
+
static {
|
|
847
|
+
__name(this, "TenantContextService");
|
|
848
|
+
}
|
|
849
|
+
tenantInfo = null;
|
|
850
|
+
/**
|
|
851
|
+
* Set tenant information for this request/message
|
|
852
|
+
*
|
|
853
|
+
* This is typically called by:
|
|
854
|
+
* - TenantContextInterceptor (for HTTP requests in gateway)
|
|
855
|
+
* - MessageTenantContextInterceptor (for RabbitMQ messages in microservices)
|
|
856
|
+
* - Manual context setup in message handlers
|
|
857
|
+
*
|
|
858
|
+
* @param tenantInfo Complete tenant information
|
|
859
|
+
* @throws Error if tenant context is already set (prevents accidental overwrites)
|
|
860
|
+
*/
|
|
861
|
+
setTenant(tenantInfo) {
|
|
862
|
+
if (this.tenantInfo) {
|
|
863
|
+
throw new Error("Tenant context already set for this request");
|
|
864
|
+
}
|
|
865
|
+
this.tenantInfo = tenantInfo;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Get tenant information for this request/message
|
|
869
|
+
*
|
|
870
|
+
* @returns Tenant information
|
|
871
|
+
* @throws UnauthorizedException if tenant context hasn't been set
|
|
872
|
+
*/
|
|
873
|
+
getTenant() {
|
|
874
|
+
if (!this.tenantInfo) {
|
|
875
|
+
throw new import_common9.UnauthorizedException("Tenant context not set");
|
|
876
|
+
}
|
|
877
|
+
return this.tenantInfo;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Check if tenant context has been set
|
|
881
|
+
*
|
|
882
|
+
* @returns true if tenant context is available
|
|
883
|
+
*/
|
|
884
|
+
hasTenant() {
|
|
885
|
+
return this.tenantInfo !== null;
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Clear tenant context
|
|
889
|
+
*
|
|
890
|
+
* This is useful for cleanup in RabbitMQ message handlers
|
|
891
|
+
* after the message has been processed.
|
|
892
|
+
*
|
|
893
|
+
* HTTP requests don't need manual cleanup as the service
|
|
894
|
+
* instance is destroyed when the request ends.
|
|
895
|
+
*/
|
|
896
|
+
clearTenant() {
|
|
897
|
+
this.tenantInfo = null;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Get tenant ID safely (returns null if not set)
|
|
901
|
+
*
|
|
902
|
+
* @returns Tenant ID or null
|
|
903
|
+
*/
|
|
904
|
+
getTenantIdSafe() {
|
|
905
|
+
return this.tenantInfo?.id ?? null;
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Get tenant subdomain safely (returns null if not set)
|
|
909
|
+
*
|
|
910
|
+
* @returns Tenant subdomain or null
|
|
911
|
+
*/
|
|
912
|
+
getTenantSubdomainSafe() {
|
|
913
|
+
return this.tenantInfo?.subdomain ?? null;
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
TenantContextService = _ts_decorate6([
|
|
917
|
+
(0, import_common9.Injectable)({
|
|
918
|
+
scope: import_common9.Scope.REQUEST
|
|
919
|
+
})
|
|
920
|
+
], TenantContextService);
|
|
921
|
+
|
|
922
|
+
// src/database/interceptors/message-tenant-context.interceptor.ts
|
|
923
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
924
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
925
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
926
|
+
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;
|
|
927
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
928
|
+
}
|
|
929
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
930
|
+
function _ts_metadata4(k, v) {
|
|
594
931
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
595
932
|
}
|
|
596
|
-
__name(
|
|
933
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
597
934
|
var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
598
935
|
static {
|
|
599
936
|
__name(this, "MessageTenantContextInterceptor");
|
|
600
937
|
}
|
|
601
938
|
tenantContext;
|
|
602
|
-
logger = new
|
|
939
|
+
logger = new import_common10.Logger(_MessageTenantContextInterceptor.name);
|
|
603
940
|
constructor(tenantContext) {
|
|
604
941
|
this.tenantContext = tenantContext;
|
|
605
942
|
}
|
|
@@ -644,29 +981,30 @@ var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
|
644
981
|
}
|
|
645
982
|
}
|
|
646
983
|
};
|
|
647
|
-
MessageTenantContextInterceptor =
|
|
648
|
-
(0,
|
|
649
|
-
scope:
|
|
984
|
+
MessageTenantContextInterceptor = _ts_decorate7([
|
|
985
|
+
(0, import_common10.Injectable)({
|
|
986
|
+
scope: import_common10.Scope.REQUEST
|
|
650
987
|
}),
|
|
651
|
-
|
|
652
|
-
|
|
988
|
+
_ts_metadata4("design:type", Function),
|
|
989
|
+
_ts_metadata4("design:paramtypes", [
|
|
653
990
|
typeof TenantContextService === "undefined" ? Object : TenantContextService
|
|
654
991
|
])
|
|
655
992
|
], MessageTenantContextInterceptor);
|
|
656
993
|
|
|
657
994
|
// src/database/interceptors/tenant-context.interceptor.ts
|
|
658
|
-
var
|
|
659
|
-
|
|
995
|
+
var import_common11 = require("@nestjs/common");
|
|
996
|
+
var import_core4 = require("@nestjs/core");
|
|
997
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
660
998
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
661
999
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
662
1000
|
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;
|
|
663
1001
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
664
1002
|
}
|
|
665
|
-
__name(
|
|
666
|
-
function
|
|
1003
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1004
|
+
function _ts_metadata5(k, v) {
|
|
667
1005
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
668
1006
|
}
|
|
669
|
-
__name(
|
|
1007
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
670
1008
|
var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
671
1009
|
static {
|
|
672
1010
|
__name(this, "TenantContextInterceptor");
|
|
@@ -675,7 +1013,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
675
1013
|
tenantContext;
|
|
676
1014
|
primaryDatabase;
|
|
677
1015
|
requestService;
|
|
678
|
-
logger = new
|
|
1016
|
+
logger = new import_common11.Logger(_TenantContextInterceptor.name);
|
|
679
1017
|
constructor(reflector, tenantContext, primaryDatabase, requestService) {
|
|
680
1018
|
this.reflector = reflector;
|
|
681
1019
|
this.tenantContext = tenantContext;
|
|
@@ -696,7 +1034,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
696
1034
|
return next.handle();
|
|
697
1035
|
}
|
|
698
1036
|
if (!tenantIdentifier) {
|
|
699
|
-
throw new
|
|
1037
|
+
throw new import_common11.UnauthorizedException("Tenant identifier not found in request");
|
|
700
1038
|
}
|
|
701
1039
|
this.logger.debug(`Tenant identifier extracted: ${tenantIdentifier}`);
|
|
702
1040
|
if (tenantIdentifier === "cloud") {
|
|
@@ -706,11 +1044,11 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
706
1044
|
const tenantInfo = await this.primaryDatabase.getTenantInfo(tenantIdentifier);
|
|
707
1045
|
if (!tenantInfo) {
|
|
708
1046
|
this.logger.warn(`Invalid tenant: ${tenantIdentifier}`);
|
|
709
|
-
throw new
|
|
1047
|
+
throw new import_common11.UnauthorizedException("Invalid tenant");
|
|
710
1048
|
}
|
|
711
1049
|
if (tenantInfo.status !== "ACTIVE") {
|
|
712
1050
|
this.logger.warn(`Tenant ${tenantIdentifier} has status: ${tenantInfo.status}`);
|
|
713
|
-
throw new
|
|
1051
|
+
throw new import_common11.UnauthorizedException(`Tenant is ${tenantInfo.status}`);
|
|
714
1052
|
}
|
|
715
1053
|
this.logger.debug(`Tenant config loaded: ${tenantInfo.subdomain} (${tenantInfo.type})`);
|
|
716
1054
|
this.tenantContext.setTenant(tenantInfo);
|
|
@@ -723,339 +1061,21 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
723
1061
|
return next.handle();
|
|
724
1062
|
}
|
|
725
1063
|
};
|
|
726
|
-
TenantContextInterceptor =
|
|
727
|
-
(0,
|
|
728
|
-
scope:
|
|
1064
|
+
TenantContextInterceptor = _ts_decorate8([
|
|
1065
|
+
(0, import_common11.Injectable)({
|
|
1066
|
+
scope: import_common11.Scope.REQUEST
|
|
729
1067
|
}),
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
typeof Reflector === "undefined" ? Object : Reflector,
|
|
1068
|
+
_ts_metadata5("design:type", Function),
|
|
1069
|
+
_ts_metadata5("design:paramtypes", [
|
|
1070
|
+
typeof import_core4.Reflector === "undefined" ? Object : import_core4.Reflector,
|
|
733
1071
|
typeof TenantContextService === "undefined" ? Object : TenantContextService,
|
|
734
1072
|
typeof PrimaryDatabaseService === "undefined" ? Object : PrimaryDatabaseService,
|
|
735
1073
|
typeof RequestService === "undefined" ? Object : RequestService
|
|
736
1074
|
])
|
|
737
1075
|
], TenantContextInterceptor);
|
|
738
1076
|
|
|
739
|
-
// src/database/services/primary-database.service.ts
|
|
740
|
-
var import_common9 = require("@nestjs/common");
|
|
741
|
-
var import_drizzle_orm = require("drizzle-orm");
|
|
742
|
-
var import_node_postgres = require("drizzle-orm/node-postgres");
|
|
743
|
-
var import_pg = require("pg");
|
|
744
|
-
function _ts_decorate7(decorators, target, key, desc) {
|
|
745
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
746
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
747
|
-
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;
|
|
748
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
749
|
-
}
|
|
750
|
-
__name(_ts_decorate7, "_ts_decorate");
|
|
751
|
-
function _ts_metadata5(k, v) {
|
|
752
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
753
|
-
}
|
|
754
|
-
__name(_ts_metadata5, "_ts_metadata");
|
|
755
|
-
function _ts_param2(paramIndex, decorator) {
|
|
756
|
-
return function(target, key) {
|
|
757
|
-
decorator(target, key, paramIndex);
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
__name(_ts_param2, "_ts_param");
|
|
761
|
-
var PrimaryDatabaseService2 = class _PrimaryDatabaseService {
|
|
762
|
-
static {
|
|
763
|
-
__name(this, "PrimaryDatabaseService");
|
|
764
|
-
}
|
|
765
|
-
options;
|
|
766
|
-
logger = new import_common9.Logger(_PrimaryDatabaseService.name);
|
|
767
|
-
/** PostgreSQL connection pool */
|
|
768
|
-
pool = null;
|
|
769
|
-
/** Drizzle database instance */
|
|
770
|
-
db = null;
|
|
771
|
-
/** In-memory cache: Map<tenantIdentifier, TenantConfig> */
|
|
772
|
-
tenantConfigCache = /* @__PURE__ */ new Map();
|
|
773
|
-
/** Cache TTL in milliseconds */
|
|
774
|
-
cacheTTL;
|
|
775
|
-
constructor(options) {
|
|
776
|
-
this.options = options;
|
|
777
|
-
this.cacheTTL = options.connectionCacheTTL || 3e5;
|
|
778
|
-
}
|
|
779
|
-
async onModuleInit() {
|
|
780
|
-
if (this.options.primaryDb) {
|
|
781
|
-
await this.initializeDrizzleClient();
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Initialize connection to primary database using Drizzle
|
|
786
|
-
*/
|
|
787
|
-
async initializeDrizzleClient() {
|
|
788
|
-
try {
|
|
789
|
-
const databaseUrl = this.buildPrimaryDbUrl();
|
|
790
|
-
this.pool = new import_pg.Pool({
|
|
791
|
-
connectionString: databaseUrl,
|
|
792
|
-
max: this.options.maxConnections || 10
|
|
793
|
-
});
|
|
794
|
-
this.logger.debug(`Schema keys passed to drizzle: [${Object.keys(this.options.drizzleSchema || {}).join(", ")}]`);
|
|
795
|
-
this.logger.debug(`Relations keys passed to drizzle: [${Object.keys(this.options.drizzleRelations || {}).join(", ")}]`);
|
|
796
|
-
this.db = (0, import_node_postgres.drizzle)({
|
|
797
|
-
client: this.pool,
|
|
798
|
-
schema: this.options.drizzleSchema,
|
|
799
|
-
relations: this.options.drizzleRelations
|
|
800
|
-
});
|
|
801
|
-
this.logger.debug(`Drizzle query keys after init: [${Object.keys(this.db.query || {}).join(", ")}]`);
|
|
802
|
-
await this.pool.query("SELECT 1");
|
|
803
|
-
this.logger.log("Connected to primary database (tenant registry)");
|
|
804
|
-
} catch (error) {
|
|
805
|
-
this.logger.error("Failed to connect to primary database", error);
|
|
806
|
-
throw new import_common9.InternalServerErrorException("Failed to initialize tenant registry");
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* Build connection URL from primary database properties
|
|
811
|
-
*/
|
|
812
|
-
buildPrimaryDbUrl() {
|
|
813
|
-
if (!this.options.primaryDb) {
|
|
814
|
-
throw new Error("Primary database configuration not provided");
|
|
815
|
-
}
|
|
816
|
-
const { host, port = 5432, username, password, database, schema = "public", sslMode = "require" } = this.options.primaryDb;
|
|
817
|
-
let url = `postgresql://${username}:${encodeURIComponent(password)}@${host}:${port}/${database}`;
|
|
818
|
-
const params = new URLSearchParams();
|
|
819
|
-
if (schema) {
|
|
820
|
-
params.set("schema", schema);
|
|
821
|
-
}
|
|
822
|
-
params.set("sslmode", sslMode);
|
|
823
|
-
const queryString = params.toString();
|
|
824
|
-
if (queryString) {
|
|
825
|
-
url += `?${queryString}`;
|
|
826
|
-
}
|
|
827
|
-
this.logger.debug(`Primary DB connection URL: ${this.maskPassword(url)}`);
|
|
828
|
-
return url;
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* Mask password in connection URL for logging
|
|
832
|
-
*/
|
|
833
|
-
maskPassword(url) {
|
|
834
|
-
return url.replace(/:([^@]+)@/, ":****@");
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Get tenant configuration by identifier (ID or subdomain)
|
|
838
|
-
*
|
|
839
|
-
* @param tenantIdentifier Tenant ID or subdomain
|
|
840
|
-
* @returns Tenant configuration or null if not found
|
|
841
|
-
*/
|
|
842
|
-
async getTenantInfo(tenantIdentifier) {
|
|
843
|
-
const cached = this.tenantConfigCache.get(tenantIdentifier);
|
|
844
|
-
if (cached) {
|
|
845
|
-
this.logger.debug(`Cache hit for tenant: ${tenantIdentifier}`);
|
|
846
|
-
return cached;
|
|
847
|
-
}
|
|
848
|
-
try {
|
|
849
|
-
if (!this.db) {
|
|
850
|
-
throw new Error("Primary database client not initialized");
|
|
851
|
-
}
|
|
852
|
-
this.logger.debug(`Querying primary database for tenant: ${tenantIdentifier}`);
|
|
853
|
-
const schema = this.options.drizzleSchema;
|
|
854
|
-
const { tenants, tenantDatabaseConfigs } = schema;
|
|
855
|
-
const result = await this.db.select().from(tenants).leftJoin(tenantDatabaseConfigs, (0, import_drizzle_orm.eq)(tenants.id, tenantDatabaseConfigs.tenantId)).where((0, import_drizzle_orm.or)((0, import_drizzle_orm.eq)(tenants.id, tenantIdentifier), (0, import_drizzle_orm.eq)(tenants.subdomain, tenantIdentifier))).limit(1);
|
|
856
|
-
if (!result.length) {
|
|
857
|
-
this.logger.warn(`Tenant not found: ${tenantIdentifier}`);
|
|
858
|
-
return null;
|
|
859
|
-
}
|
|
860
|
-
const row = result[0];
|
|
861
|
-
const tenant = row.tenants;
|
|
862
|
-
const config = row.tenant_database_configs;
|
|
863
|
-
if (tenant.status !== "ACTIVE") {
|
|
864
|
-
this.logger.warn(`Tenant not active: ${tenantIdentifier}`);
|
|
865
|
-
return null;
|
|
866
|
-
}
|
|
867
|
-
const info = {
|
|
868
|
-
id: tenant.id,
|
|
869
|
-
subdomain: tenant.subdomain,
|
|
870
|
-
type: tenant.dbType,
|
|
871
|
-
status: tenant.status,
|
|
872
|
-
// For SHARED tenants: schema name
|
|
873
|
-
schemaName: config?.dbSchema || void 0,
|
|
874
|
-
// For DEDICATED tenants: database configuration from TenantDatabaseConfig table
|
|
875
|
-
databaseName: config?.dbName || void 0,
|
|
876
|
-
databaseHost: config?.dbHost || void 0,
|
|
877
|
-
databasePort: config?.dbPort || void 0,
|
|
878
|
-
databaseUsername: config?.dbUsername ? this.decrypt(config.dbUsername) : void 0,
|
|
879
|
-
databasePassword: config?.dbPassword ? this.decrypt(config.dbPassword) : void 0,
|
|
880
|
-
databaseSslMode: config?.dbSslMode || void 0,
|
|
881
|
-
connectionPoolSize: config?.connectionPoolSize || void 0
|
|
882
|
-
};
|
|
883
|
-
this.cacheInfo(info);
|
|
884
|
-
return info;
|
|
885
|
-
} catch (error) {
|
|
886
|
-
this.logger.error(`Failed to fetch tenant info: ${tenantIdentifier}`, error);
|
|
887
|
-
throw new import_common9.InternalServerErrorException("Failed to resolve tenant");
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Cache tenant information with TTL
|
|
892
|
-
*/
|
|
893
|
-
cacheInfo(info) {
|
|
894
|
-
this.tenantConfigCache.set(info.id, info);
|
|
895
|
-
this.tenantConfigCache.set(info.subdomain, info);
|
|
896
|
-
setTimeout(() => {
|
|
897
|
-
this.tenantConfigCache.delete(info.id);
|
|
898
|
-
this.tenantConfigCache.delete(info.subdomain);
|
|
899
|
-
this.logger.debug(`Cache expired for tenant: ${info.subdomain}`);
|
|
900
|
-
}, this.cacheTTL);
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Clear cached tenant information
|
|
904
|
-
*
|
|
905
|
-
* Useful when tenant settings are updated and cache needs to be invalidated
|
|
906
|
-
*
|
|
907
|
-
* @param tenantIdentifier Tenant ID or subdomain
|
|
908
|
-
*/
|
|
909
|
-
clearTenantCache(tenantIdentifier) {
|
|
910
|
-
const config = this.tenantConfigCache.get(tenantIdentifier);
|
|
911
|
-
if (config) {
|
|
912
|
-
this.tenantConfigCache.delete(config.id);
|
|
913
|
-
this.tenantConfigCache.delete(config.subdomain);
|
|
914
|
-
this.logger.log(`Cleared cache for tenant: ${tenantIdentifier}`);
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* Clear all cached tenant configurations
|
|
919
|
-
*/
|
|
920
|
-
clearAllCaches() {
|
|
921
|
-
const size = this.tenantConfigCache.size;
|
|
922
|
-
this.tenantConfigCache.clear();
|
|
923
|
-
this.logger.log(`Cleared ${size} cached tenant configs`);
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Get the Drizzle database instance for the primary database.
|
|
927
|
-
* This is a synchronous property that returns the initialized Drizzle client.
|
|
928
|
-
*
|
|
929
|
-
* @returns Primary database Drizzle instance
|
|
930
|
-
* @throws Error if primary database client is not initialized
|
|
931
|
-
*/
|
|
932
|
-
get drizzleClient() {
|
|
933
|
-
if (!this.db) {
|
|
934
|
-
throw new Error("Primary database client not initialized");
|
|
935
|
-
}
|
|
936
|
-
return this.db;
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Get the Drizzle schema
|
|
940
|
-
*/
|
|
941
|
-
get schema() {
|
|
942
|
-
return this.options.drizzleSchema;
|
|
943
|
-
}
|
|
944
|
-
/**
|
|
945
|
-
* Decrypt database credentials
|
|
946
|
-
*
|
|
947
|
-
* Override this method to implement your encryption strategy
|
|
948
|
-
*
|
|
949
|
-
* @param encrypted Encrypted value
|
|
950
|
-
* @returns Decrypted value
|
|
951
|
-
*/
|
|
952
|
-
decrypt(encrypted) {
|
|
953
|
-
return encrypted;
|
|
954
|
-
}
|
|
955
|
-
async onModuleDestroy() {
|
|
956
|
-
if (this.pool) {
|
|
957
|
-
await this.pool.end();
|
|
958
|
-
this.logger.log("Disconnected from primary database");
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
PrimaryDatabaseService2 = _ts_decorate7([
|
|
963
|
-
(0, import_common9.Injectable)(),
|
|
964
|
-
_ts_param2(0, (0, import_common9.Inject)(DATABASE_MODULE_OPTIONS)),
|
|
965
|
-
_ts_metadata5("design:type", Function),
|
|
966
|
-
_ts_metadata5("design:paramtypes", [
|
|
967
|
-
typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions
|
|
968
|
-
])
|
|
969
|
-
], PrimaryDatabaseService2);
|
|
970
|
-
|
|
971
|
-
// src/database/services/tenant-context.service.ts
|
|
972
|
-
var import_common10 = require("@nestjs/common");
|
|
973
|
-
function _ts_decorate8(decorators, target, key, desc) {
|
|
974
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
975
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
976
|
-
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;
|
|
977
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
978
|
-
}
|
|
979
|
-
__name(_ts_decorate8, "_ts_decorate");
|
|
980
|
-
var TenantContextService2 = class {
|
|
981
|
-
static {
|
|
982
|
-
__name(this, "TenantContextService");
|
|
983
|
-
}
|
|
984
|
-
tenantInfo = null;
|
|
985
|
-
/**
|
|
986
|
-
* Set tenant information for this request/message
|
|
987
|
-
*
|
|
988
|
-
* This is typically called by:
|
|
989
|
-
* - TenantContextInterceptor (for HTTP requests in gateway)
|
|
990
|
-
* - MessageTenantContextInterceptor (for RabbitMQ messages in microservices)
|
|
991
|
-
* - Manual context setup in message handlers
|
|
992
|
-
*
|
|
993
|
-
* @param tenantInfo Complete tenant information
|
|
994
|
-
* @throws Error if tenant context is already set (prevents accidental overwrites)
|
|
995
|
-
*/
|
|
996
|
-
setTenant(tenantInfo) {
|
|
997
|
-
if (this.tenantInfo) {
|
|
998
|
-
throw new Error("Tenant context already set for this request");
|
|
999
|
-
}
|
|
1000
|
-
this.tenantInfo = tenantInfo;
|
|
1001
|
-
}
|
|
1002
|
-
/**
|
|
1003
|
-
* Get tenant information for this request/message
|
|
1004
|
-
*
|
|
1005
|
-
* @returns Tenant information
|
|
1006
|
-
* @throws UnauthorizedException if tenant context hasn't been set
|
|
1007
|
-
*/
|
|
1008
|
-
getTenant() {
|
|
1009
|
-
if (!this.tenantInfo) {
|
|
1010
|
-
throw new import_common10.UnauthorizedException("Tenant context not set");
|
|
1011
|
-
}
|
|
1012
|
-
return this.tenantInfo;
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* Check if tenant context has been set
|
|
1016
|
-
*
|
|
1017
|
-
* @returns true if tenant context is available
|
|
1018
|
-
*/
|
|
1019
|
-
hasTenant() {
|
|
1020
|
-
return this.tenantInfo !== null;
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Clear tenant context
|
|
1024
|
-
*
|
|
1025
|
-
* This is useful for cleanup in RabbitMQ message handlers
|
|
1026
|
-
* after the message has been processed.
|
|
1027
|
-
*
|
|
1028
|
-
* HTTP requests don't need manual cleanup as the service
|
|
1029
|
-
* instance is destroyed when the request ends.
|
|
1030
|
-
*/
|
|
1031
|
-
clearTenant() {
|
|
1032
|
-
this.tenantInfo = null;
|
|
1033
|
-
}
|
|
1034
|
-
/**
|
|
1035
|
-
* Get tenant ID safely (returns null if not set)
|
|
1036
|
-
*
|
|
1037
|
-
* @returns Tenant ID or null
|
|
1038
|
-
*/
|
|
1039
|
-
getTenantIdSafe() {
|
|
1040
|
-
return this.tenantInfo?.id ?? null;
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Get tenant subdomain safely (returns null if not set)
|
|
1044
|
-
*
|
|
1045
|
-
* @returns Tenant subdomain or null
|
|
1046
|
-
*/
|
|
1047
|
-
getTenantSubdomainSafe() {
|
|
1048
|
-
return this.tenantInfo?.subdomain ?? null;
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
|
-
TenantContextService2 = _ts_decorate8([
|
|
1052
|
-
(0, import_common10.Injectable)({
|
|
1053
|
-
scope: import_common10.Scope.REQUEST
|
|
1054
|
-
})
|
|
1055
|
-
], TenantContextService2);
|
|
1056
|
-
|
|
1057
1077
|
// src/database/services/tenant-database.service.ts
|
|
1058
|
-
var
|
|
1078
|
+
var import_common12 = require("@nestjs/common");
|
|
1059
1079
|
var import_node_postgres2 = require("drizzle-orm/node-postgres");
|
|
1060
1080
|
var import_pg2 = require("pg");
|
|
1061
1081
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
@@ -1081,7 +1101,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1081
1101
|
}
|
|
1082
1102
|
options;
|
|
1083
1103
|
tenantContext;
|
|
1084
|
-
logger = new
|
|
1104
|
+
logger = new import_common12.Logger(_TenantDatabaseService.name);
|
|
1085
1105
|
/** Connection pool: Map<cacheKey, TenantConnection> */
|
|
1086
1106
|
clients = /* @__PURE__ */ new Map();
|
|
1087
1107
|
/** Track last usage time for idle connection cleanup */
|
|
@@ -1158,7 +1178,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1158
1178
|
};
|
|
1159
1179
|
} catch (error) {
|
|
1160
1180
|
this.logger.error(`Failed to create database connection for tenant: ${tenant.subdomain}`, error);
|
|
1161
|
-
throw new
|
|
1181
|
+
throw new import_common12.InternalServerErrorException("Failed to connect to tenant database");
|
|
1162
1182
|
}
|
|
1163
1183
|
}
|
|
1164
1184
|
/**
|
|
@@ -1251,8 +1271,8 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
1251
1271
|
}
|
|
1252
1272
|
};
|
|
1253
1273
|
TenantDatabaseService = _ts_decorate9([
|
|
1254
|
-
(0,
|
|
1255
|
-
_ts_param3(0, (0,
|
|
1274
|
+
(0, import_common12.Injectable)(),
|
|
1275
|
+
_ts_param3(0, (0, import_common12.Inject)(DATABASE_MODULE_OPTIONS)),
|
|
1256
1276
|
_ts_metadata6("design:type", Function),
|
|
1257
1277
|
_ts_metadata6("design:paramtypes", [
|
|
1258
1278
|
typeof DatabaseModuleOptions === "undefined" ? Object : DatabaseModuleOptions,
|
|
@@ -1339,18 +1359,18 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1339
1359
|
};
|
|
1340
1360
|
const providers = [
|
|
1341
1361
|
asyncProvider,
|
|
1342
|
-
|
|
1343
|
-
|
|
1362
|
+
TenantContextService,
|
|
1363
|
+
PrimaryDatabaseService,
|
|
1344
1364
|
TenantDatabaseService
|
|
1345
1365
|
];
|
|
1346
1366
|
if (mode === "server") {
|
|
1347
1367
|
providers.push({
|
|
1348
|
-
provide:
|
|
1368
|
+
provide: import_core5.APP_INTERCEPTOR,
|
|
1349
1369
|
useClass: TenantContextInterceptor
|
|
1350
1370
|
});
|
|
1351
1371
|
} else {
|
|
1352
1372
|
providers.push({
|
|
1353
|
-
provide:
|
|
1373
|
+
provide: import_core5.APP_INTERCEPTOR,
|
|
1354
1374
|
useClass: MessageTenantContextInterceptor
|
|
1355
1375
|
});
|
|
1356
1376
|
}
|
|
@@ -1362,23 +1382,23 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1362
1382
|
providers,
|
|
1363
1383
|
exports: [
|
|
1364
1384
|
TenantDatabaseService,
|
|
1365
|
-
|
|
1366
|
-
|
|
1385
|
+
TenantContextService,
|
|
1386
|
+
PrimaryDatabaseService,
|
|
1367
1387
|
asyncProvider
|
|
1368
1388
|
]
|
|
1369
1389
|
};
|
|
1370
1390
|
}
|
|
1371
1391
|
};
|
|
1372
1392
|
DatabaseModule = _ts_decorate10([
|
|
1373
|
-
(0,
|
|
1374
|
-
(0,
|
|
1393
|
+
(0, import_common13.Global)(),
|
|
1394
|
+
(0, import_common13.Module)({})
|
|
1375
1395
|
], DatabaseModule);
|
|
1376
1396
|
|
|
1377
1397
|
// src/database/decorators/tenant.decorator.ts
|
|
1378
|
-
var
|
|
1379
|
-
var Tenant = (0,
|
|
1398
|
+
var import_common14 = require("@nestjs/common");
|
|
1399
|
+
var Tenant = (0, import_common14.createParamDecorator)((_data, ctx) => {
|
|
1380
1400
|
const request = ctx.switchToHttp().getRequest();
|
|
1381
|
-
const tenantContext = request.app?.get?.(
|
|
1401
|
+
const tenantContext = request.app?.get?.(TenantContextService);
|
|
1382
1402
|
if (!tenantContext) {
|
|
1383
1403
|
throw new Error("TenantContextService not found.");
|
|
1384
1404
|
}
|
|
@@ -1386,7 +1406,7 @@ var Tenant = (0, import_common13.createParamDecorator)((_data, ctx) => {
|
|
|
1386
1406
|
});
|
|
1387
1407
|
|
|
1388
1408
|
// src/database/repositories/primary-base.repository.ts
|
|
1389
|
-
var
|
|
1409
|
+
var import_common15 = require("@nestjs/common");
|
|
1390
1410
|
var import_drizzle_orm2 = require("drizzle-orm");
|
|
1391
1411
|
function snakeToCamel(str) {
|
|
1392
1412
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -1457,7 +1477,7 @@ var PrimaryBaseRepository = class {
|
|
|
1457
1477
|
this.table = table;
|
|
1458
1478
|
const dbTableName = (0, import_drizzle_orm2.getTableName)(table);
|
|
1459
1479
|
this.tableName = snakeToCamel(dbTableName);
|
|
1460
|
-
this.logger = new
|
|
1480
|
+
this.logger = new import_common15.Logger(this.constructor.name);
|
|
1461
1481
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1462
1482
|
this.logger.debug(`Table name: '${dbTableName}' -> query key: '${this.tableName}'`);
|
|
1463
1483
|
}
|
|
@@ -1697,7 +1717,7 @@ var PrimaryBaseRepository = class {
|
|
|
1697
1717
|
};
|
|
1698
1718
|
|
|
1699
1719
|
// src/database/repositories/tenant-base.repository.ts
|
|
1700
|
-
var
|
|
1720
|
+
var import_common16 = require("@nestjs/common");
|
|
1701
1721
|
var import_drizzle_orm3 = require("drizzle-orm");
|
|
1702
1722
|
var TenantBaseRepository = class {
|
|
1703
1723
|
static {
|
|
@@ -1754,7 +1774,7 @@ var TenantBaseRepository = class {
|
|
|
1754
1774
|
this.database = database;
|
|
1755
1775
|
this.table = table;
|
|
1756
1776
|
this.tableName = (0, import_drizzle_orm3.getTableName)(table);
|
|
1757
|
-
this.logger = new
|
|
1777
|
+
this.logger = new import_common16.Logger(this.constructor.name);
|
|
1758
1778
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1759
1779
|
}
|
|
1760
1780
|
/**
|
|
@@ -1987,11 +2007,11 @@ var TenantBaseRepository = class {
|
|
|
1987
2007
|
};
|
|
1988
2008
|
|
|
1989
2009
|
// src/exceptions/bad-gateway.exception.ts
|
|
1990
|
-
var
|
|
2010
|
+
var import_common18 = require("@nestjs/common");
|
|
1991
2011
|
|
|
1992
2012
|
// src/exceptions/base-field.exception.ts
|
|
1993
|
-
var
|
|
1994
|
-
var BaseFieldException = class extends
|
|
2013
|
+
var import_common17 = require("@nestjs/common");
|
|
2014
|
+
var BaseFieldException = class extends import_common17.HttpException {
|
|
1995
2015
|
static {
|
|
1996
2016
|
__name(this, "BaseFieldException");
|
|
1997
2017
|
}
|
|
@@ -2001,7 +2021,7 @@ var BaseFieldException = class extends import_common16.HttpException {
|
|
|
2001
2021
|
let finalDetail;
|
|
2002
2022
|
if (Array.isArray(statusOrMessageOrErrors)) {
|
|
2003
2023
|
errors = statusOrMessageOrErrors;
|
|
2004
|
-
httpStatus = messageOrStatus ||
|
|
2024
|
+
httpStatus = messageOrStatus || import_common17.HttpStatus.BAD_REQUEST;
|
|
2005
2025
|
finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
|
|
2006
2026
|
} else if (typeof statusOrMessageOrErrors === "string" && typeof messageOrStatus === "string") {
|
|
2007
2027
|
errors = [
|
|
@@ -2046,334 +2066,334 @@ var BadGatewayException = class extends BaseFieldException {
|
|
|
2046
2066
|
}
|
|
2047
2067
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2048
2068
|
if (Array.isArray(messageOrField)) {
|
|
2049
|
-
super(messageOrField,
|
|
2069
|
+
super(messageOrField, import_common18.HttpStatus.BAD_GATEWAY, fieldMessageOrDetail);
|
|
2050
2070
|
} else if (detail !== void 0) {
|
|
2051
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2071
|
+
super(messageOrField, fieldMessageOrDetail, import_common18.HttpStatus.BAD_GATEWAY, detail);
|
|
2052
2072
|
} else if (fieldMessageOrDetail) {
|
|
2053
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2073
|
+
super(messageOrField, fieldMessageOrDetail, import_common18.HttpStatus.BAD_GATEWAY);
|
|
2054
2074
|
} else {
|
|
2055
|
-
super(messageOrField,
|
|
2075
|
+
super(messageOrField, import_common18.HttpStatus.BAD_GATEWAY);
|
|
2056
2076
|
}
|
|
2057
2077
|
}
|
|
2058
2078
|
};
|
|
2059
2079
|
|
|
2060
2080
|
// src/exceptions/bad-request.exception.ts
|
|
2061
|
-
var
|
|
2081
|
+
var import_common19 = require("@nestjs/common");
|
|
2062
2082
|
var BadRequestException = class extends BaseFieldException {
|
|
2063
2083
|
static {
|
|
2064
2084
|
__name(this, "BadRequestException");
|
|
2065
2085
|
}
|
|
2066
2086
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2067
2087
|
if (Array.isArray(messageOrField)) {
|
|
2068
|
-
super(messageOrField,
|
|
2088
|
+
super(messageOrField, import_common19.HttpStatus.BAD_REQUEST, fieldMessageOrDetail);
|
|
2069
2089
|
} else if (detail !== void 0) {
|
|
2070
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2090
|
+
super(messageOrField, fieldMessageOrDetail, import_common19.HttpStatus.BAD_REQUEST, detail);
|
|
2071
2091
|
} else if (fieldMessageOrDetail) {
|
|
2072
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2092
|
+
super(messageOrField, fieldMessageOrDetail, import_common19.HttpStatus.BAD_REQUEST);
|
|
2073
2093
|
} else {
|
|
2074
|
-
super(messageOrField,
|
|
2094
|
+
super(messageOrField, import_common19.HttpStatus.BAD_REQUEST);
|
|
2075
2095
|
}
|
|
2076
2096
|
}
|
|
2077
2097
|
};
|
|
2078
2098
|
|
|
2079
2099
|
// src/exceptions/conflict.exception.ts
|
|
2080
|
-
var
|
|
2100
|
+
var import_common20 = require("@nestjs/common");
|
|
2081
2101
|
var ConflictException = class extends BaseFieldException {
|
|
2082
2102
|
static {
|
|
2083
2103
|
__name(this, "ConflictException");
|
|
2084
2104
|
}
|
|
2085
2105
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2086
2106
|
if (Array.isArray(messageOrField)) {
|
|
2087
|
-
super(messageOrField,
|
|
2107
|
+
super(messageOrField, import_common20.HttpStatus.CONFLICT, fieldMessageOrDetail);
|
|
2088
2108
|
} else if (detail !== void 0) {
|
|
2089
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2109
|
+
super(messageOrField, fieldMessageOrDetail, import_common20.HttpStatus.CONFLICT, detail);
|
|
2090
2110
|
} else if (fieldMessageOrDetail) {
|
|
2091
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2111
|
+
super(messageOrField, fieldMessageOrDetail, import_common20.HttpStatus.CONFLICT);
|
|
2092
2112
|
} else {
|
|
2093
|
-
super(messageOrField,
|
|
2113
|
+
super(messageOrField, import_common20.HttpStatus.CONFLICT);
|
|
2094
2114
|
}
|
|
2095
2115
|
}
|
|
2096
2116
|
};
|
|
2097
2117
|
|
|
2098
2118
|
// src/exceptions/forbidden.exception.ts
|
|
2099
|
-
var
|
|
2119
|
+
var import_common21 = require("@nestjs/common");
|
|
2100
2120
|
var ForbiddenException = class extends BaseFieldException {
|
|
2101
2121
|
static {
|
|
2102
2122
|
__name(this, "ForbiddenException");
|
|
2103
2123
|
}
|
|
2104
2124
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2105
2125
|
if (Array.isArray(messageOrField)) {
|
|
2106
|
-
super(messageOrField,
|
|
2126
|
+
super(messageOrField, import_common21.HttpStatus.FORBIDDEN, fieldMessageOrDetail);
|
|
2107
2127
|
} else if (detail !== void 0) {
|
|
2108
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2128
|
+
super(messageOrField, fieldMessageOrDetail, import_common21.HttpStatus.FORBIDDEN, detail);
|
|
2109
2129
|
} else if (fieldMessageOrDetail) {
|
|
2110
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2130
|
+
super(messageOrField, fieldMessageOrDetail, import_common21.HttpStatus.FORBIDDEN);
|
|
2111
2131
|
} else {
|
|
2112
|
-
super(messageOrField,
|
|
2132
|
+
super(messageOrField, import_common21.HttpStatus.FORBIDDEN);
|
|
2113
2133
|
}
|
|
2114
2134
|
}
|
|
2115
2135
|
};
|
|
2116
2136
|
|
|
2117
2137
|
// src/exceptions/gone.exception.ts
|
|
2118
|
-
var
|
|
2138
|
+
var import_common22 = require("@nestjs/common");
|
|
2119
2139
|
var GoneException = class extends BaseFieldException {
|
|
2120
2140
|
static {
|
|
2121
2141
|
__name(this, "GoneException");
|
|
2122
2142
|
}
|
|
2123
2143
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2124
2144
|
if (Array.isArray(messageOrField)) {
|
|
2125
|
-
super(messageOrField,
|
|
2145
|
+
super(messageOrField, import_common22.HttpStatus.GONE, fieldMessageOrDetail);
|
|
2126
2146
|
} else if (detail !== void 0) {
|
|
2127
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2147
|
+
super(messageOrField, fieldMessageOrDetail, import_common22.HttpStatus.GONE, detail);
|
|
2128
2148
|
} else if (fieldMessageOrDetail) {
|
|
2129
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2149
|
+
super(messageOrField, fieldMessageOrDetail, import_common22.HttpStatus.GONE);
|
|
2130
2150
|
} else {
|
|
2131
|
-
super(messageOrField,
|
|
2151
|
+
super(messageOrField, import_common22.HttpStatus.GONE);
|
|
2132
2152
|
}
|
|
2133
2153
|
}
|
|
2134
2154
|
};
|
|
2135
2155
|
|
|
2136
2156
|
// src/exceptions/internal-server-error.exception.ts
|
|
2137
|
-
var
|
|
2157
|
+
var import_common23 = require("@nestjs/common");
|
|
2138
2158
|
var InternalServerErrorException3 = class extends BaseFieldException {
|
|
2139
2159
|
static {
|
|
2140
2160
|
__name(this, "InternalServerErrorException");
|
|
2141
2161
|
}
|
|
2142
2162
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2143
2163
|
if (Array.isArray(messageOrField)) {
|
|
2144
|
-
super(messageOrField,
|
|
2164
|
+
super(messageOrField, import_common23.HttpStatus.INTERNAL_SERVER_ERROR, fieldMessageOrDetail);
|
|
2145
2165
|
} else if (detail !== void 0) {
|
|
2146
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2166
|
+
super(messageOrField, fieldMessageOrDetail, import_common23.HttpStatus.INTERNAL_SERVER_ERROR, detail);
|
|
2147
2167
|
} else if (fieldMessageOrDetail) {
|
|
2148
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2168
|
+
super(messageOrField, fieldMessageOrDetail, import_common23.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
2149
2169
|
} else {
|
|
2150
|
-
super(messageOrField,
|
|
2170
|
+
super(messageOrField, import_common23.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
2151
2171
|
}
|
|
2152
2172
|
}
|
|
2153
2173
|
};
|
|
2154
2174
|
|
|
2155
2175
|
// src/exceptions/method-not-allowed.exception.ts
|
|
2156
|
-
var
|
|
2176
|
+
var import_common24 = require("@nestjs/common");
|
|
2157
2177
|
var MethodNotAllowedException = class extends BaseFieldException {
|
|
2158
2178
|
static {
|
|
2159
2179
|
__name(this, "MethodNotAllowedException");
|
|
2160
2180
|
}
|
|
2161
2181
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2162
2182
|
if (Array.isArray(messageOrField)) {
|
|
2163
|
-
super(messageOrField,
|
|
2183
|
+
super(messageOrField, import_common24.HttpStatus.METHOD_NOT_ALLOWED, fieldMessageOrDetail);
|
|
2164
2184
|
} else if (detail !== void 0) {
|
|
2165
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2185
|
+
super(messageOrField, fieldMessageOrDetail, import_common24.HttpStatus.METHOD_NOT_ALLOWED, detail);
|
|
2166
2186
|
} else if (fieldMessageOrDetail) {
|
|
2167
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2187
|
+
super(messageOrField, fieldMessageOrDetail, import_common24.HttpStatus.METHOD_NOT_ALLOWED);
|
|
2168
2188
|
} else {
|
|
2169
|
-
super(messageOrField,
|
|
2189
|
+
super(messageOrField, import_common24.HttpStatus.METHOD_NOT_ALLOWED);
|
|
2170
2190
|
}
|
|
2171
2191
|
}
|
|
2172
2192
|
};
|
|
2173
2193
|
|
|
2174
2194
|
// src/exceptions/not-acceptable.exception.ts
|
|
2175
|
-
var
|
|
2195
|
+
var import_common25 = require("@nestjs/common");
|
|
2176
2196
|
var NotAcceptableException = class extends BaseFieldException {
|
|
2177
2197
|
static {
|
|
2178
2198
|
__name(this, "NotAcceptableException");
|
|
2179
2199
|
}
|
|
2180
2200
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2181
2201
|
if (Array.isArray(messageOrField)) {
|
|
2182
|
-
super(messageOrField,
|
|
2202
|
+
super(messageOrField, import_common25.HttpStatus.NOT_ACCEPTABLE, fieldMessageOrDetail);
|
|
2183
2203
|
} else if (detail !== void 0) {
|
|
2184
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2204
|
+
super(messageOrField, fieldMessageOrDetail, import_common25.HttpStatus.NOT_ACCEPTABLE, detail);
|
|
2185
2205
|
} else if (fieldMessageOrDetail) {
|
|
2186
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2206
|
+
super(messageOrField, fieldMessageOrDetail, import_common25.HttpStatus.NOT_ACCEPTABLE);
|
|
2187
2207
|
} else {
|
|
2188
|
-
super(messageOrField,
|
|
2208
|
+
super(messageOrField, import_common25.HttpStatus.NOT_ACCEPTABLE);
|
|
2189
2209
|
}
|
|
2190
2210
|
}
|
|
2191
2211
|
};
|
|
2192
2212
|
|
|
2193
2213
|
// src/exceptions/not-found.exception.ts
|
|
2194
|
-
var
|
|
2214
|
+
var import_common26 = require("@nestjs/common");
|
|
2195
2215
|
var NotFoundException = class extends BaseFieldException {
|
|
2196
2216
|
static {
|
|
2197
2217
|
__name(this, "NotFoundException");
|
|
2198
2218
|
}
|
|
2199
2219
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2200
2220
|
if (Array.isArray(messageOrField)) {
|
|
2201
|
-
super(messageOrField,
|
|
2221
|
+
super(messageOrField, import_common26.HttpStatus.NOT_FOUND, fieldMessageOrDetail);
|
|
2202
2222
|
} else if (detail !== void 0) {
|
|
2203
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2223
|
+
super(messageOrField, fieldMessageOrDetail, import_common26.HttpStatus.NOT_FOUND, detail);
|
|
2204
2224
|
} else if (fieldMessageOrDetail) {
|
|
2205
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2225
|
+
super(messageOrField, fieldMessageOrDetail, import_common26.HttpStatus.NOT_FOUND);
|
|
2206
2226
|
} else {
|
|
2207
|
-
super(messageOrField,
|
|
2227
|
+
super(messageOrField, import_common26.HttpStatus.NOT_FOUND);
|
|
2208
2228
|
}
|
|
2209
2229
|
}
|
|
2210
2230
|
};
|
|
2211
2231
|
|
|
2212
2232
|
// src/exceptions/not-implemented.exception.ts
|
|
2213
|
-
var
|
|
2233
|
+
var import_common27 = require("@nestjs/common");
|
|
2214
2234
|
var NotImplementedException = class extends BaseFieldException {
|
|
2215
2235
|
static {
|
|
2216
2236
|
__name(this, "NotImplementedException");
|
|
2217
2237
|
}
|
|
2218
2238
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2219
2239
|
if (Array.isArray(messageOrField)) {
|
|
2220
|
-
super(messageOrField,
|
|
2240
|
+
super(messageOrField, import_common27.HttpStatus.NOT_IMPLEMENTED, fieldMessageOrDetail);
|
|
2221
2241
|
} else if (detail !== void 0) {
|
|
2222
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2242
|
+
super(messageOrField, fieldMessageOrDetail, import_common27.HttpStatus.NOT_IMPLEMENTED, detail);
|
|
2223
2243
|
} else if (fieldMessageOrDetail) {
|
|
2224
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2244
|
+
super(messageOrField, fieldMessageOrDetail, import_common27.HttpStatus.NOT_IMPLEMENTED);
|
|
2225
2245
|
} else {
|
|
2226
|
-
super(messageOrField,
|
|
2246
|
+
super(messageOrField, import_common27.HttpStatus.NOT_IMPLEMENTED);
|
|
2227
2247
|
}
|
|
2228
2248
|
}
|
|
2229
2249
|
};
|
|
2230
2250
|
|
|
2231
2251
|
// src/exceptions/payload-too-large.exception.ts
|
|
2232
|
-
var
|
|
2252
|
+
var import_common28 = require("@nestjs/common");
|
|
2233
2253
|
var PayloadTooLargeException = class extends BaseFieldException {
|
|
2234
2254
|
static {
|
|
2235
2255
|
__name(this, "PayloadTooLargeException");
|
|
2236
2256
|
}
|
|
2237
2257
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2238
2258
|
if (Array.isArray(messageOrField)) {
|
|
2239
|
-
super(messageOrField,
|
|
2259
|
+
super(messageOrField, import_common28.HttpStatus.PAYLOAD_TOO_LARGE, fieldMessageOrDetail);
|
|
2240
2260
|
} else if (detail !== void 0) {
|
|
2241
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2261
|
+
super(messageOrField, fieldMessageOrDetail, import_common28.HttpStatus.PAYLOAD_TOO_LARGE, detail);
|
|
2242
2262
|
} else if (fieldMessageOrDetail) {
|
|
2243
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2263
|
+
super(messageOrField, fieldMessageOrDetail, import_common28.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
2244
2264
|
} else {
|
|
2245
|
-
super(messageOrField,
|
|
2265
|
+
super(messageOrField, import_common28.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
2246
2266
|
}
|
|
2247
2267
|
}
|
|
2248
2268
|
};
|
|
2249
2269
|
|
|
2250
2270
|
// src/exceptions/request-timeout.exception.ts
|
|
2251
|
-
var
|
|
2271
|
+
var import_common29 = require("@nestjs/common");
|
|
2252
2272
|
var RequestTimeoutException = class extends BaseFieldException {
|
|
2253
2273
|
static {
|
|
2254
2274
|
__name(this, "RequestTimeoutException");
|
|
2255
2275
|
}
|
|
2256
2276
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2257
2277
|
if (Array.isArray(messageOrField)) {
|
|
2258
|
-
super(messageOrField,
|
|
2278
|
+
super(messageOrField, import_common29.HttpStatus.REQUEST_TIMEOUT, fieldMessageOrDetail);
|
|
2259
2279
|
} else if (detail !== void 0) {
|
|
2260
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2280
|
+
super(messageOrField, fieldMessageOrDetail, import_common29.HttpStatus.REQUEST_TIMEOUT, detail);
|
|
2261
2281
|
} else if (fieldMessageOrDetail) {
|
|
2262
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2282
|
+
super(messageOrField, fieldMessageOrDetail, import_common29.HttpStatus.REQUEST_TIMEOUT);
|
|
2263
2283
|
} else {
|
|
2264
|
-
super(messageOrField,
|
|
2284
|
+
super(messageOrField, import_common29.HttpStatus.REQUEST_TIMEOUT);
|
|
2265
2285
|
}
|
|
2266
2286
|
}
|
|
2267
2287
|
};
|
|
2268
2288
|
|
|
2269
2289
|
// src/exceptions/service-unavailable.exception.ts
|
|
2270
|
-
var
|
|
2290
|
+
var import_common30 = require("@nestjs/common");
|
|
2271
2291
|
var ServiceUnavailableException = class extends BaseFieldException {
|
|
2272
2292
|
static {
|
|
2273
2293
|
__name(this, "ServiceUnavailableException");
|
|
2274
2294
|
}
|
|
2275
2295
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2276
2296
|
if (Array.isArray(messageOrField)) {
|
|
2277
|
-
super(messageOrField,
|
|
2297
|
+
super(messageOrField, import_common30.HttpStatus.SERVICE_UNAVAILABLE, fieldMessageOrDetail);
|
|
2278
2298
|
} else if (detail !== void 0) {
|
|
2279
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2299
|
+
super(messageOrField, fieldMessageOrDetail, import_common30.HttpStatus.SERVICE_UNAVAILABLE, detail);
|
|
2280
2300
|
} else if (fieldMessageOrDetail) {
|
|
2281
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2301
|
+
super(messageOrField, fieldMessageOrDetail, import_common30.HttpStatus.SERVICE_UNAVAILABLE);
|
|
2282
2302
|
} else {
|
|
2283
|
-
super(messageOrField,
|
|
2303
|
+
super(messageOrField, import_common30.HttpStatus.SERVICE_UNAVAILABLE);
|
|
2284
2304
|
}
|
|
2285
2305
|
}
|
|
2286
2306
|
};
|
|
2287
2307
|
|
|
2288
2308
|
// src/exceptions/too-many-requests.exception.ts
|
|
2289
|
-
var
|
|
2309
|
+
var import_common31 = require("@nestjs/common");
|
|
2290
2310
|
var TooManyRequestsException = class extends BaseFieldException {
|
|
2291
2311
|
static {
|
|
2292
2312
|
__name(this, "TooManyRequestsException");
|
|
2293
2313
|
}
|
|
2294
2314
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2295
2315
|
if (Array.isArray(messageOrField)) {
|
|
2296
|
-
super(messageOrField,
|
|
2316
|
+
super(messageOrField, import_common31.HttpStatus.TOO_MANY_REQUESTS, fieldMessageOrDetail);
|
|
2297
2317
|
} else if (detail !== void 0) {
|
|
2298
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2318
|
+
super(messageOrField, fieldMessageOrDetail, import_common31.HttpStatus.TOO_MANY_REQUESTS, detail);
|
|
2299
2319
|
} else if (fieldMessageOrDetail) {
|
|
2300
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2320
|
+
super(messageOrField, fieldMessageOrDetail, import_common31.HttpStatus.TOO_MANY_REQUESTS);
|
|
2301
2321
|
} else {
|
|
2302
|
-
super(messageOrField,
|
|
2322
|
+
super(messageOrField, import_common31.HttpStatus.TOO_MANY_REQUESTS);
|
|
2303
2323
|
}
|
|
2304
2324
|
}
|
|
2305
2325
|
};
|
|
2306
2326
|
|
|
2307
2327
|
// src/exceptions/unauthorized.exception.ts
|
|
2308
|
-
var
|
|
2328
|
+
var import_common32 = require("@nestjs/common");
|
|
2309
2329
|
var UnauthorizedException4 = class extends BaseFieldException {
|
|
2310
2330
|
static {
|
|
2311
2331
|
__name(this, "UnauthorizedException");
|
|
2312
2332
|
}
|
|
2313
2333
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2314
2334
|
if (Array.isArray(messageOrField)) {
|
|
2315
|
-
super(messageOrField,
|
|
2335
|
+
super(messageOrField, import_common32.HttpStatus.UNAUTHORIZED, fieldMessageOrDetail);
|
|
2316
2336
|
} else if (detail !== void 0) {
|
|
2317
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2337
|
+
super(messageOrField, fieldMessageOrDetail, import_common32.HttpStatus.UNAUTHORIZED, detail);
|
|
2318
2338
|
} else if (fieldMessageOrDetail) {
|
|
2319
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2339
|
+
super(messageOrField, fieldMessageOrDetail, import_common32.HttpStatus.UNAUTHORIZED);
|
|
2320
2340
|
} else {
|
|
2321
|
-
super(messageOrField,
|
|
2341
|
+
super(messageOrField, import_common32.HttpStatus.UNAUTHORIZED);
|
|
2322
2342
|
}
|
|
2323
2343
|
}
|
|
2324
2344
|
};
|
|
2325
2345
|
|
|
2326
2346
|
// src/exceptions/unprocessable-entity.exception.ts
|
|
2327
|
-
var
|
|
2347
|
+
var import_common33 = require("@nestjs/common");
|
|
2328
2348
|
var UnprocessableEntityException = class extends BaseFieldException {
|
|
2329
2349
|
static {
|
|
2330
2350
|
__name(this, "UnprocessableEntityException");
|
|
2331
2351
|
}
|
|
2332
2352
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2333
2353
|
if (Array.isArray(messageOrField)) {
|
|
2334
|
-
super(messageOrField,
|
|
2354
|
+
super(messageOrField, import_common33.HttpStatus.UNPROCESSABLE_ENTITY, fieldMessageOrDetail);
|
|
2335
2355
|
} else if (detail !== void 0) {
|
|
2336
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2356
|
+
super(messageOrField, fieldMessageOrDetail, import_common33.HttpStatus.UNPROCESSABLE_ENTITY, detail);
|
|
2337
2357
|
} else if (fieldMessageOrDetail) {
|
|
2338
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2358
|
+
super(messageOrField, fieldMessageOrDetail, import_common33.HttpStatus.UNPROCESSABLE_ENTITY);
|
|
2339
2359
|
} else {
|
|
2340
|
-
super(messageOrField,
|
|
2360
|
+
super(messageOrField, import_common33.HttpStatus.UNPROCESSABLE_ENTITY);
|
|
2341
2361
|
}
|
|
2342
2362
|
}
|
|
2343
2363
|
};
|
|
2344
2364
|
|
|
2345
2365
|
// src/exceptions/unsupported-media-type.exception.ts
|
|
2346
|
-
var
|
|
2366
|
+
var import_common34 = require("@nestjs/common");
|
|
2347
2367
|
var UnsupportedMediaTypeException = class extends BaseFieldException {
|
|
2348
2368
|
static {
|
|
2349
2369
|
__name(this, "UnsupportedMediaTypeException");
|
|
2350
2370
|
}
|
|
2351
2371
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2352
2372
|
if (Array.isArray(messageOrField)) {
|
|
2353
|
-
super(messageOrField,
|
|
2373
|
+
super(messageOrField, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE, fieldMessageOrDetail);
|
|
2354
2374
|
} else if (detail !== void 0) {
|
|
2355
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2375
|
+
super(messageOrField, fieldMessageOrDetail, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE, detail);
|
|
2356
2376
|
} else if (fieldMessageOrDetail) {
|
|
2357
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2377
|
+
super(messageOrField, fieldMessageOrDetail, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
|
2358
2378
|
} else {
|
|
2359
|
-
super(messageOrField,
|
|
2379
|
+
super(messageOrField, import_common34.HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
|
2360
2380
|
}
|
|
2361
2381
|
}
|
|
2362
2382
|
};
|
|
2363
2383
|
|
|
2364
2384
|
// src/exceptions/validation.exception.ts
|
|
2365
|
-
var
|
|
2385
|
+
var import_common35 = require("@nestjs/common");
|
|
2366
2386
|
var ValidationException = class extends BaseFieldException {
|
|
2367
2387
|
static {
|
|
2368
2388
|
__name(this, "ValidationException");
|
|
2369
2389
|
}
|
|
2370
2390
|
constructor(errors, detail) {
|
|
2371
|
-
super(errors,
|
|
2391
|
+
super(errors, import_common35.HttpStatus.BAD_REQUEST, detail);
|
|
2372
2392
|
}
|
|
2373
2393
|
};
|
|
2374
2394
|
|
|
2375
2395
|
// src/filters/http-exception.filter.ts
|
|
2376
|
-
var
|
|
2396
|
+
var import_common36 = require("@nestjs/common");
|
|
2377
2397
|
function _ts_decorate11(decorators, target, key, desc) {
|
|
2378
2398
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2379
2399
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2382,7 +2402,7 @@ function _ts_decorate11(decorators, target, key, desc) {
|
|
|
2382
2402
|
}
|
|
2383
2403
|
__name(_ts_decorate11, "_ts_decorate");
|
|
2384
2404
|
function getHttpStatusTitle(status) {
|
|
2385
|
-
const enumKey = Object.entries(
|
|
2405
|
+
const enumKey = Object.entries(import_common36.HttpStatus).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
|
|
2386
2406
|
if (!enumKey) {
|
|
2387
2407
|
return "Error";
|
|
2388
2408
|
}
|
|
@@ -2393,14 +2413,14 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2393
2413
|
static {
|
|
2394
2414
|
__name(this, "HttpExceptionFilter");
|
|
2395
2415
|
}
|
|
2396
|
-
logger = new
|
|
2416
|
+
logger = new import_common36.Logger(_HttpExceptionFilter.name);
|
|
2397
2417
|
catch(exception, host) {
|
|
2398
2418
|
const ctx = host.switchToHttp();
|
|
2399
2419
|
const response = ctx.getResponse();
|
|
2400
|
-
let status =
|
|
2420
|
+
let status = import_common36.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
2401
2421
|
let errors = [];
|
|
2402
2422
|
let detail = "Internal server error";
|
|
2403
|
-
if (exception instanceof
|
|
2423
|
+
if (exception instanceof import_common36.HttpException) {
|
|
2404
2424
|
status = exception.getStatus();
|
|
2405
2425
|
const exceptionResponse = exception.getResponse();
|
|
2406
2426
|
if (typeof exceptionResponse === "object" && exceptionResponse !== null) {
|
|
@@ -2459,11 +2479,11 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2459
2479
|
}
|
|
2460
2480
|
};
|
|
2461
2481
|
HttpExceptionFilter = _ts_decorate11([
|
|
2462
|
-
(0,
|
|
2482
|
+
(0, import_common36.Catch)()
|
|
2463
2483
|
], HttpExceptionFilter);
|
|
2464
2484
|
|
|
2465
2485
|
// src/http/guards/csrf.guard.ts
|
|
2466
|
-
var
|
|
2486
|
+
var import_common37 = require("@nestjs/common");
|
|
2467
2487
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
2468
2488
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2469
2489
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2475,7 +2495,7 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2475
2495
|
static {
|
|
2476
2496
|
__name(this, "CsrfGuard");
|
|
2477
2497
|
}
|
|
2478
|
-
logger = new
|
|
2498
|
+
logger = new import_common37.Logger(_CsrfGuard.name);
|
|
2479
2499
|
async canActivate(context) {
|
|
2480
2500
|
const request = context.switchToHttp().getRequest();
|
|
2481
2501
|
const reply = context.switchToHttp().getResponse();
|
|
@@ -2491,7 +2511,7 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2491
2511
|
const fastifyInstance = request.server;
|
|
2492
2512
|
if (!fastifyInstance.csrfProtection) {
|
|
2493
2513
|
this.logger.error("CSRF protection plugin not found. Ensure @fastify/csrf-protection is registered.");
|
|
2494
|
-
throw new
|
|
2514
|
+
throw new import_common37.ForbiddenException("CSRF protection not configured");
|
|
2495
2515
|
}
|
|
2496
2516
|
await new Promise((resolve, reject) => {
|
|
2497
2517
|
fastifyInstance.csrfProtection(request, reply, (err) => {
|
|
@@ -2506,7 +2526,7 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2506
2526
|
return true;
|
|
2507
2527
|
} catch (error) {
|
|
2508
2528
|
this.logger.warn(`CSRF validation failed for ${request.method} ${request.url}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2509
|
-
throw new
|
|
2529
|
+
throw new import_common37.ForbiddenException({
|
|
2510
2530
|
errors: [
|
|
2511
2531
|
{
|
|
2512
2532
|
field: "csrf",
|
|
@@ -2519,11 +2539,11 @@ var CsrfGuard = class _CsrfGuard {
|
|
|
2519
2539
|
}
|
|
2520
2540
|
};
|
|
2521
2541
|
CsrfGuard = _ts_decorate12([
|
|
2522
|
-
(0,
|
|
2542
|
+
(0, import_common37.Injectable)()
|
|
2523
2543
|
], CsrfGuard);
|
|
2524
2544
|
|
|
2525
2545
|
// src/http/http.module.ts
|
|
2526
|
-
var
|
|
2546
|
+
var import_common38 = require("@nestjs/common");
|
|
2527
2547
|
function _ts_decorate13(decorators, target, key, desc) {
|
|
2528
2548
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2529
2549
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2536,271 +2556,78 @@ var HttpModule = class {
|
|
|
2536
2556
|
__name(this, "HttpModule");
|
|
2537
2557
|
}
|
|
2538
2558
|
};
|
|
2539
|
-
HttpModule = _ts_decorate13([
|
|
2540
|
-
(0,
|
|
2541
|
-
providers: [
|
|
2542
|
-
CsrfGuard
|
|
2543
|
-
],
|
|
2544
|
-
exports: [
|
|
2545
|
-
CsrfGuard
|
|
2546
|
-
]
|
|
2547
|
-
})
|
|
2548
|
-
], HttpModule);
|
|
2549
|
-
|
|
2550
|
-
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2551
|
-
var import_common38 = require("@nestjs/common");
|
|
2552
|
-
var import_operators2 = require("rxjs/operators");
|
|
2553
|
-
|
|
2554
|
-
// src/logger/utils/index.ts
|
|
2555
|
-
var import_node_async_hooks = require("async_hooks");
|
|
2556
|
-
var import_node_crypto = require("crypto");
|
|
2557
|
-
var correlationStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
2558
|
-
function getCorrelationContext() {
|
|
2559
|
-
return correlationStorage.getStore();
|
|
2560
|
-
}
|
|
2561
|
-
__name(getCorrelationContext, "getCorrelationContext");
|
|
2562
|
-
function runWithCorrelationContext(context, callback) {
|
|
2563
|
-
return correlationStorage.run(context, callback);
|
|
2564
|
-
}
|
|
2565
|
-
__name(runWithCorrelationContext, "runWithCorrelationContext");
|
|
2566
|
-
function updateCorrelationContext(updates) {
|
|
2567
|
-
const context = correlationStorage.getStore();
|
|
2568
|
-
if (context) {
|
|
2569
|
-
Object.assign(context, updates);
|
|
2570
|
-
}
|
|
2571
|
-
}
|
|
2572
|
-
__name(updateCorrelationContext, "updateCorrelationContext");
|
|
2573
|
-
var DEFAULT_CORRELATION_HEADER = "x-correlation-id";
|
|
2574
|
-
function generateCorrelationId() {
|
|
2575
|
-
return (0, import_node_crypto.randomUUID)();
|
|
2576
|
-
}
|
|
2577
|
-
__name(generateCorrelationId, "generateCorrelationId");
|
|
2578
|
-
function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_CORRELATION_HEADER) {
|
|
2579
|
-
if (typeof reply.header === "function") {
|
|
2580
|
-
reply.header(headerName, correlationId);
|
|
2581
|
-
} else if (reply.raw && typeof reply.raw.setHeader === "function") {
|
|
2582
|
-
reply.raw.setHeader(headerName, correlationId);
|
|
2583
|
-
}
|
|
2584
|
-
}
|
|
2585
|
-
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
2586
|
-
|
|
2587
|
-
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2588
|
-
function _ts_decorate14(decorators, target, key, desc) {
|
|
2589
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2590
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2591
|
-
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;
|
|
2592
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2593
|
-
}
|
|
2594
|
-
__name(_ts_decorate14, "_ts_decorate");
|
|
2595
|
-
function _ts_metadata7(k, v) {
|
|
2596
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2597
|
-
}
|
|
2598
|
-
__name(_ts_metadata7, "_ts_metadata");
|
|
2599
|
-
function _ts_param4(paramIndex, decorator) {
|
|
2600
|
-
return function(target, key) {
|
|
2601
|
-
decorator(target, key, paramIndex);
|
|
2602
|
-
};
|
|
2603
|
-
}
|
|
2604
|
-
__name(_ts_param4, "_ts_param");
|
|
2605
|
-
var HttpLoggerInterceptor = class {
|
|
2606
|
-
static {
|
|
2607
|
-
__name(this, "HttpLoggerInterceptor");
|
|
2608
|
-
}
|
|
2609
|
-
logger;
|
|
2610
|
-
enableRequestLog;
|
|
2611
|
-
enableResponseLog;
|
|
2612
|
-
slowRequestThreshold;
|
|
2613
|
-
constructor(logger, options) {
|
|
2614
|
-
this.logger = logger;
|
|
2615
|
-
this.enableRequestLog = options?.enableRequestLog ?? true;
|
|
2616
|
-
this.enableResponseLog = options?.enableResponseLog ?? true;
|
|
2617
|
-
this.slowRequestThreshold = options?.slowRequestThreshold ?? 3e3;
|
|
2618
|
-
}
|
|
2619
|
-
intercept(context, next) {
|
|
2620
|
-
if (context.getType() !== "http") {
|
|
2621
|
-
return next.handle();
|
|
2622
|
-
}
|
|
2623
|
-
const httpContext = context.switchToHttp();
|
|
2624
|
-
const request = httpContext.getRequest();
|
|
2625
|
-
const response = httpContext.getResponse();
|
|
2626
|
-
const startTime = Date.now();
|
|
2627
|
-
if (this.enableRequestLog) {
|
|
2628
|
-
this.logRequest(request);
|
|
2629
|
-
}
|
|
2630
|
-
return next.handle().pipe((0, import_operators2.tap)(() => {
|
|
2631
|
-
if (this.enableResponseLog) {
|
|
2632
|
-
const duration = Date.now() - startTime;
|
|
2633
|
-
this.logResponse(request, response, duration);
|
|
2634
|
-
}
|
|
2635
|
-
}), (0, import_operators2.catchError)((error) => {
|
|
2636
|
-
const duration = Date.now() - startTime;
|
|
2637
|
-
this.logError(request, response, duration, error);
|
|
2638
|
-
throw error;
|
|
2639
|
-
}));
|
|
2640
|
-
}
|
|
2641
|
-
logRequest(request) {
|
|
2642
|
-
try {
|
|
2643
|
-
const correlationContext = getCorrelationContext();
|
|
2644
|
-
const metadata = {
|
|
2645
|
-
type: "http_request",
|
|
2646
|
-
method: request.method,
|
|
2647
|
-
url: request.url,
|
|
2648
|
-
correlationId: correlationContext?.correlationId,
|
|
2649
|
-
ip: request.ip,
|
|
2650
|
-
userAgent: request.headers["user-agent"]
|
|
2651
|
-
};
|
|
2652
|
-
this.logger.logWithMetadata("log", `Incoming ${request.method} ${request.url}`, metadata);
|
|
2653
|
-
} catch (error) {
|
|
2654
|
-
this.logger.error("Failed to log HTTP request", error.stack);
|
|
2655
|
-
}
|
|
2656
|
-
}
|
|
2657
|
-
logResponse(request, response, duration) {
|
|
2658
|
-
try {
|
|
2659
|
-
const correlationContext = getCorrelationContext();
|
|
2660
|
-
const statusCode = response.statusCode;
|
|
2661
|
-
const logLevel = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "log";
|
|
2662
|
-
const metadata = {
|
|
2663
|
-
type: "http_response",
|
|
2664
|
-
method: request.method,
|
|
2665
|
-
url: request.url,
|
|
2666
|
-
statusCode,
|
|
2667
|
-
duration,
|
|
2668
|
-
correlationId: correlationContext?.correlationId
|
|
2669
|
-
};
|
|
2670
|
-
if (duration > this.slowRequestThreshold) {
|
|
2671
|
-
metadata.slowRequest = true;
|
|
2672
|
-
}
|
|
2673
|
-
const message = metadata.slowRequest ? `SLOW ${request.method} ${request.url} ${statusCode} - ${duration}ms` : `${request.method} ${request.url} ${statusCode} - ${duration}ms`;
|
|
2674
|
-
this.logger.logWithMetadata(logLevel, message, metadata);
|
|
2675
|
-
} catch (error) {
|
|
2676
|
-
this.logger.error("Failed to log HTTP response", error.stack);
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
logError(request, response, duration, error) {
|
|
2680
|
-
try {
|
|
2681
|
-
const correlationContext = getCorrelationContext();
|
|
2682
|
-
const statusCode = response.statusCode || 500;
|
|
2683
|
-
const metadata = {
|
|
2684
|
-
type: "http_error",
|
|
2685
|
-
method: request.method,
|
|
2686
|
-
url: request.url,
|
|
2687
|
-
statusCode,
|
|
2688
|
-
duration,
|
|
2689
|
-
correlationId: correlationContext?.correlationId,
|
|
2690
|
-
errorName: error?.name || "Error",
|
|
2691
|
-
errorMessage: error?.message || "Unknown error"
|
|
2692
|
-
};
|
|
2693
|
-
if (error?.stack) {
|
|
2694
|
-
metadata.trace = error.stack;
|
|
2695
|
-
}
|
|
2696
|
-
if (error?.response) {
|
|
2697
|
-
metadata.errorDetails = error.response;
|
|
2698
|
-
}
|
|
2699
|
-
const message = `ERROR ${request.method} ${request.url} ${statusCode} - ${error?.message || "Unknown error"}`;
|
|
2700
|
-
this.logger.logWithMetadata("error", message, metadata);
|
|
2701
|
-
} catch (loggingError) {
|
|
2702
|
-
this.logger.error("Failed to log HTTP error", loggingError.stack);
|
|
2703
|
-
}
|
|
2704
|
-
}
|
|
2705
|
-
};
|
|
2706
|
-
HttpLoggerInterceptor = _ts_decorate14([
|
|
2707
|
-
(0, import_common38.Injectable)(),
|
|
2708
|
-
_ts_param4(1, (0, import_common38.Optional)()),
|
|
2709
|
-
_ts_metadata7("design:type", Function),
|
|
2710
|
-
_ts_metadata7("design:paramtypes", [
|
|
2711
|
-
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2712
|
-
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2713
|
-
])
|
|
2714
|
-
], HttpLoggerInterceptor);
|
|
2715
|
-
|
|
2716
|
-
// src/logger/logger.module.ts
|
|
2717
|
-
var import_common41 = require("@nestjs/common");
|
|
2718
|
-
|
|
2719
|
-
// src/logger/middleware/correlation-id.middleware.ts
|
|
2720
|
-
var import_common39 = require("@nestjs/common");
|
|
2721
|
-
function _ts_decorate15(decorators, target, key, desc) {
|
|
2722
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2723
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2724
|
-
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;
|
|
2725
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2726
|
-
}
|
|
2727
|
-
__name(_ts_decorate15, "_ts_decorate");
|
|
2728
|
-
function _ts_metadata8(k, v) {
|
|
2729
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2730
|
-
}
|
|
2731
|
-
__name(_ts_metadata8, "_ts_metadata");
|
|
2732
|
-
var CorrelationIdMiddleware = class {
|
|
2733
|
-
static {
|
|
2734
|
-
__name(this, "CorrelationIdMiddleware");
|
|
2735
|
-
}
|
|
2736
|
-
includeInResponse;
|
|
2737
|
-
responseHeader;
|
|
2738
|
-
constructor(options = {}) {
|
|
2739
|
-
this.includeInResponse = options.includeInResponse ?? true;
|
|
2740
|
-
this.responseHeader = options.responseHeader ?? DEFAULT_CORRELATION_HEADER;
|
|
2741
|
-
}
|
|
2742
|
-
/**
|
|
2743
|
-
* Middleware handler for processing requests.
|
|
2744
|
-
*/
|
|
2745
|
-
use(_req, reply, next) {
|
|
2746
|
-
const correlationId = generateCorrelationId();
|
|
2747
|
-
if (this.includeInResponse) {
|
|
2748
|
-
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2749
|
-
}
|
|
2750
|
-
runWithCorrelationContext({
|
|
2751
|
-
correlationId
|
|
2752
|
-
}, () => {
|
|
2753
|
-
next();
|
|
2754
|
-
});
|
|
2755
|
-
}
|
|
2756
|
-
/**
|
|
2757
|
-
* Fastify hook handler for onRequest.
|
|
2758
|
-
* This is an async function that returns a Promise, ensuring the AsyncLocalStorage
|
|
2759
|
-
* context persists throughout the entire request lifecycle.
|
|
2760
|
-
*/
|
|
2761
|
-
async onRequest(_req, reply) {
|
|
2762
|
-
const correlationId = generateCorrelationId();
|
|
2763
|
-
if (this.includeInResponse) {
|
|
2764
|
-
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2765
|
-
}
|
|
2766
|
-
const store = correlationStorage.getStore();
|
|
2767
|
-
if (!store) {
|
|
2768
|
-
correlationStorage.enterWith({
|
|
2769
|
-
correlationId
|
|
2770
|
-
});
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
};
|
|
2774
|
-
CorrelationIdMiddleware = _ts_decorate15([
|
|
2775
|
-
(0, import_common39.Injectable)(),
|
|
2776
|
-
_ts_metadata8("design:type", Function),
|
|
2777
|
-
_ts_metadata8("design:paramtypes", [
|
|
2778
|
-
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
2779
|
-
])
|
|
2780
|
-
], CorrelationIdMiddleware);
|
|
2559
|
+
HttpModule = _ts_decorate13([
|
|
2560
|
+
(0, import_common38.Module)({
|
|
2561
|
+
providers: [
|
|
2562
|
+
CsrfGuard
|
|
2563
|
+
],
|
|
2564
|
+
exports: [
|
|
2565
|
+
CsrfGuard
|
|
2566
|
+
]
|
|
2567
|
+
})
|
|
2568
|
+
], HttpModule);
|
|
2781
2569
|
|
|
2782
|
-
// src/logger/
|
|
2570
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2783
2571
|
var import_common40 = require("@nestjs/common");
|
|
2572
|
+
var import_operators2 = require("rxjs/operators");
|
|
2573
|
+
|
|
2574
|
+
// src/logger/services/logger.service.ts
|
|
2575
|
+
var import_common39 = require("@nestjs/common");
|
|
2784
2576
|
var import_winston = require("winston");
|
|
2785
2577
|
var import_winston_daily_rotate_file = __toESM(require("winston-daily-rotate-file"), 1);
|
|
2786
|
-
|
|
2578
|
+
|
|
2579
|
+
// src/logger/utils/index.ts
|
|
2580
|
+
var import_node_async_hooks = require("async_hooks");
|
|
2581
|
+
var import_node_crypto = require("crypto");
|
|
2582
|
+
var correlationStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
2583
|
+
function getCorrelationContext() {
|
|
2584
|
+
return correlationStorage.getStore();
|
|
2585
|
+
}
|
|
2586
|
+
__name(getCorrelationContext, "getCorrelationContext");
|
|
2587
|
+
function runWithCorrelationContext(context, callback) {
|
|
2588
|
+
return correlationStorage.run(context, callback);
|
|
2589
|
+
}
|
|
2590
|
+
__name(runWithCorrelationContext, "runWithCorrelationContext");
|
|
2591
|
+
function updateCorrelationContext(updates) {
|
|
2592
|
+
const context = correlationStorage.getStore();
|
|
2593
|
+
if (context) {
|
|
2594
|
+
Object.assign(context, updates);
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
__name(updateCorrelationContext, "updateCorrelationContext");
|
|
2598
|
+
var DEFAULT_CORRELATION_HEADER = "x-correlation-id";
|
|
2599
|
+
function generateCorrelationId() {
|
|
2600
|
+
return (0, import_node_crypto.randomUUID)();
|
|
2601
|
+
}
|
|
2602
|
+
__name(generateCorrelationId, "generateCorrelationId");
|
|
2603
|
+
function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_CORRELATION_HEADER) {
|
|
2604
|
+
if (typeof reply.header === "function") {
|
|
2605
|
+
reply.header(headerName, correlationId);
|
|
2606
|
+
} else if (reply.raw && typeof reply.raw.setHeader === "function") {
|
|
2607
|
+
reply.raw.setHeader(headerName, correlationId);
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
2611
|
+
|
|
2612
|
+
// src/logger/services/logger.service.ts
|
|
2613
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
2787
2614
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2788
2615
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2789
2616
|
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;
|
|
2790
2617
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2791
2618
|
}
|
|
2792
|
-
__name(
|
|
2793
|
-
function
|
|
2619
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
2620
|
+
function _ts_metadata7(k, v) {
|
|
2794
2621
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2795
2622
|
}
|
|
2796
|
-
__name(
|
|
2797
|
-
function
|
|
2623
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
2624
|
+
function _ts_param4(paramIndex, decorator) {
|
|
2798
2625
|
return function(target, key) {
|
|
2799
2626
|
decorator(target, key, paramIndex);
|
|
2800
2627
|
};
|
|
2801
2628
|
}
|
|
2802
|
-
__name(
|
|
2803
|
-
var
|
|
2629
|
+
__name(_ts_param4, "_ts_param");
|
|
2630
|
+
var LoggerService = class _LoggerService {
|
|
2804
2631
|
static {
|
|
2805
2632
|
__name(this, "LoggerService");
|
|
2806
2633
|
}
|
|
@@ -3001,16 +2828,211 @@ ${trace}`;
|
|
|
3001
2828
|
return childLogger;
|
|
3002
2829
|
}
|
|
3003
2830
|
};
|
|
3004
|
-
|
|
2831
|
+
LoggerService = _ts_decorate14([
|
|
2832
|
+
(0, import_common39.Injectable)(),
|
|
2833
|
+
_ts_param4(0, (0, import_common39.Optional)()),
|
|
2834
|
+
_ts_param4(1, (0, import_common39.Optional)()),
|
|
2835
|
+
_ts_metadata7("design:type", Function),
|
|
2836
|
+
_ts_metadata7("design:paramtypes", [
|
|
2837
|
+
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
2838
|
+
typeof Logger === "undefined" ? Object : Logger
|
|
2839
|
+
])
|
|
2840
|
+
], LoggerService);
|
|
2841
|
+
|
|
2842
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2843
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
2844
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2845
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2846
|
+
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;
|
|
2847
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2848
|
+
}
|
|
2849
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
2850
|
+
function _ts_metadata8(k, v) {
|
|
2851
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2852
|
+
}
|
|
2853
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2854
|
+
function _ts_param5(paramIndex, decorator) {
|
|
2855
|
+
return function(target, key) {
|
|
2856
|
+
decorator(target, key, paramIndex);
|
|
2857
|
+
};
|
|
2858
|
+
}
|
|
2859
|
+
__name(_ts_param5, "_ts_param");
|
|
2860
|
+
var HttpLoggerInterceptor = class {
|
|
2861
|
+
static {
|
|
2862
|
+
__name(this, "HttpLoggerInterceptor");
|
|
2863
|
+
}
|
|
2864
|
+
logger;
|
|
2865
|
+
enableRequestLog;
|
|
2866
|
+
enableResponseLog;
|
|
2867
|
+
slowRequestThreshold;
|
|
2868
|
+
constructor(logger, options) {
|
|
2869
|
+
this.logger = logger;
|
|
2870
|
+
this.enableRequestLog = options?.enableRequestLog ?? true;
|
|
2871
|
+
this.enableResponseLog = options?.enableResponseLog ?? true;
|
|
2872
|
+
this.slowRequestThreshold = options?.slowRequestThreshold ?? 3e3;
|
|
2873
|
+
}
|
|
2874
|
+
intercept(context, next) {
|
|
2875
|
+
if (context.getType() !== "http") {
|
|
2876
|
+
return next.handle();
|
|
2877
|
+
}
|
|
2878
|
+
const httpContext = context.switchToHttp();
|
|
2879
|
+
const request = httpContext.getRequest();
|
|
2880
|
+
const response = httpContext.getResponse();
|
|
2881
|
+
const startTime = Date.now();
|
|
2882
|
+
if (this.enableRequestLog) {
|
|
2883
|
+
this.logRequest(request);
|
|
2884
|
+
}
|
|
2885
|
+
return next.handle().pipe((0, import_operators2.tap)(() => {
|
|
2886
|
+
if (this.enableResponseLog) {
|
|
2887
|
+
const duration = Date.now() - startTime;
|
|
2888
|
+
this.logResponse(request, response, duration);
|
|
2889
|
+
}
|
|
2890
|
+
}), (0, import_operators2.catchError)((error) => {
|
|
2891
|
+
const duration = Date.now() - startTime;
|
|
2892
|
+
this.logError(request, response, duration, error);
|
|
2893
|
+
throw error;
|
|
2894
|
+
}));
|
|
2895
|
+
}
|
|
2896
|
+
logRequest(request) {
|
|
2897
|
+
try {
|
|
2898
|
+
const correlationContext = getCorrelationContext();
|
|
2899
|
+
const metadata = {
|
|
2900
|
+
type: "http_request",
|
|
2901
|
+
method: request.method,
|
|
2902
|
+
url: request.url,
|
|
2903
|
+
correlationId: correlationContext?.correlationId,
|
|
2904
|
+
ip: request.ip,
|
|
2905
|
+
userAgent: request.headers["user-agent"]
|
|
2906
|
+
};
|
|
2907
|
+
this.logger.logWithMetadata("log", `Incoming ${request.method} ${request.url}`, metadata);
|
|
2908
|
+
} catch (error) {
|
|
2909
|
+
this.logger.error("Failed to log HTTP request", error.stack);
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
logResponse(request, response, duration) {
|
|
2913
|
+
try {
|
|
2914
|
+
const correlationContext = getCorrelationContext();
|
|
2915
|
+
const statusCode = response.statusCode;
|
|
2916
|
+
const logLevel = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "log";
|
|
2917
|
+
const metadata = {
|
|
2918
|
+
type: "http_response",
|
|
2919
|
+
method: request.method,
|
|
2920
|
+
url: request.url,
|
|
2921
|
+
statusCode,
|
|
2922
|
+
duration,
|
|
2923
|
+
correlationId: correlationContext?.correlationId
|
|
2924
|
+
};
|
|
2925
|
+
if (duration > this.slowRequestThreshold) {
|
|
2926
|
+
metadata.slowRequest = true;
|
|
2927
|
+
}
|
|
2928
|
+
const message = metadata.slowRequest ? `SLOW ${request.method} ${request.url} ${statusCode} - ${duration}ms` : `${request.method} ${request.url} ${statusCode} - ${duration}ms`;
|
|
2929
|
+
this.logger.logWithMetadata(logLevel, message, metadata);
|
|
2930
|
+
} catch (error) {
|
|
2931
|
+
this.logger.error("Failed to log HTTP response", error.stack);
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
logError(request, response, duration, error) {
|
|
2935
|
+
try {
|
|
2936
|
+
const correlationContext = getCorrelationContext();
|
|
2937
|
+
const statusCode = response.statusCode || 500;
|
|
2938
|
+
const metadata = {
|
|
2939
|
+
type: "http_error",
|
|
2940
|
+
method: request.method,
|
|
2941
|
+
url: request.url,
|
|
2942
|
+
statusCode,
|
|
2943
|
+
duration,
|
|
2944
|
+
correlationId: correlationContext?.correlationId,
|
|
2945
|
+
errorName: error?.name || "Error",
|
|
2946
|
+
errorMessage: error?.message || "Unknown error"
|
|
2947
|
+
};
|
|
2948
|
+
if (error?.stack) {
|
|
2949
|
+
metadata.trace = error.stack;
|
|
2950
|
+
}
|
|
2951
|
+
if (error?.response) {
|
|
2952
|
+
metadata.errorDetails = error.response;
|
|
2953
|
+
}
|
|
2954
|
+
const message = `ERROR ${request.method} ${request.url} ${statusCode} - ${error?.message || "Unknown error"}`;
|
|
2955
|
+
this.logger.logWithMetadata("error", message, metadata);
|
|
2956
|
+
} catch (loggingError) {
|
|
2957
|
+
this.logger.error("Failed to log HTTP error", loggingError.stack);
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
};
|
|
2961
|
+
HttpLoggerInterceptor = _ts_decorate15([
|
|
3005
2962
|
(0, import_common40.Injectable)(),
|
|
3006
|
-
_ts_param5(0, (0, import_common40.Optional)()),
|
|
3007
2963
|
_ts_param5(1, (0, import_common40.Optional)()),
|
|
2964
|
+
_ts_metadata8("design:type", Function),
|
|
2965
|
+
_ts_metadata8("design:paramtypes", [
|
|
2966
|
+
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2967
|
+
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2968
|
+
])
|
|
2969
|
+
], HttpLoggerInterceptor);
|
|
2970
|
+
|
|
2971
|
+
// src/logger/logger.module.ts
|
|
2972
|
+
var import_common42 = require("@nestjs/common");
|
|
2973
|
+
|
|
2974
|
+
// src/logger/middleware/correlation-id.middleware.ts
|
|
2975
|
+
var import_common41 = require("@nestjs/common");
|
|
2976
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
2977
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2978
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2979
|
+
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;
|
|
2980
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2981
|
+
}
|
|
2982
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
2983
|
+
function _ts_metadata9(k, v) {
|
|
2984
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2985
|
+
}
|
|
2986
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2987
|
+
var CorrelationIdMiddleware = class {
|
|
2988
|
+
static {
|
|
2989
|
+
__name(this, "CorrelationIdMiddleware");
|
|
2990
|
+
}
|
|
2991
|
+
includeInResponse;
|
|
2992
|
+
responseHeader;
|
|
2993
|
+
constructor(options = {}) {
|
|
2994
|
+
this.includeInResponse = options.includeInResponse ?? true;
|
|
2995
|
+
this.responseHeader = options.responseHeader ?? DEFAULT_CORRELATION_HEADER;
|
|
2996
|
+
}
|
|
2997
|
+
/**
|
|
2998
|
+
* Middleware handler for processing requests.
|
|
2999
|
+
*/
|
|
3000
|
+
use(_req, reply, next) {
|
|
3001
|
+
const correlationId = generateCorrelationId();
|
|
3002
|
+
if (this.includeInResponse) {
|
|
3003
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
3004
|
+
}
|
|
3005
|
+
runWithCorrelationContext({
|
|
3006
|
+
correlationId
|
|
3007
|
+
}, () => {
|
|
3008
|
+
next();
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
/**
|
|
3012
|
+
* Fastify hook handler for onRequest.
|
|
3013
|
+
* This is an async function that returns a Promise, ensuring the AsyncLocalStorage
|
|
3014
|
+
* context persists throughout the entire request lifecycle.
|
|
3015
|
+
*/
|
|
3016
|
+
async onRequest(_req, reply) {
|
|
3017
|
+
const correlationId = generateCorrelationId();
|
|
3018
|
+
if (this.includeInResponse) {
|
|
3019
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
3020
|
+
}
|
|
3021
|
+
const store = correlationStorage.getStore();
|
|
3022
|
+
if (!store) {
|
|
3023
|
+
correlationStorage.enterWith({
|
|
3024
|
+
correlationId
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
};
|
|
3029
|
+
CorrelationIdMiddleware = _ts_decorate16([
|
|
3030
|
+
(0, import_common41.Injectable)(),
|
|
3008
3031
|
_ts_metadata9("design:type", Function),
|
|
3009
3032
|
_ts_metadata9("design:paramtypes", [
|
|
3010
|
-
typeof
|
|
3011
|
-
typeof Logger === "undefined" ? Object : Logger
|
|
3033
|
+
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
3012
3034
|
])
|
|
3013
|
-
],
|
|
3035
|
+
], CorrelationIdMiddleware);
|
|
3014
3036
|
|
|
3015
3037
|
// src/logger/logger.module.ts
|
|
3016
3038
|
function _ts_decorate17(decorators, target, key, desc) {
|
|
@@ -3108,9 +3130,9 @@ function mergeWithDefaults(options = {}) {
|
|
|
3108
3130
|
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
3109
3131
|
function createDefaultLoggerProvider(options) {
|
|
3110
3132
|
return {
|
|
3111
|
-
provide:
|
|
3133
|
+
provide: import_common42.Logger,
|
|
3112
3134
|
useFactory: /* @__PURE__ */ __name(() => {
|
|
3113
|
-
const logger = new
|
|
3135
|
+
const logger = new import_common42.Logger();
|
|
3114
3136
|
if (options.level && typeof logger.setLogLevels === "function") {
|
|
3115
3137
|
const levels = getLevelsUpTo(options.level);
|
|
3116
3138
|
logger.setLogLevels(levels);
|
|
@@ -3133,14 +3155,14 @@ function createLoggerProviders(options = {}) {
|
|
|
3133
3155
|
providers.push(createDefaultLoggerProvider(mergedOptions));
|
|
3134
3156
|
}
|
|
3135
3157
|
providers.push({
|
|
3136
|
-
provide:
|
|
3158
|
+
provide: LoggerService,
|
|
3137
3159
|
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3138
|
-
return new
|
|
3160
|
+
return new LoggerService(opts, defaultLogger);
|
|
3139
3161
|
}, "useFactory"),
|
|
3140
3162
|
inject: [
|
|
3141
3163
|
LOGGER_MODULE_OPTIONS,
|
|
3142
3164
|
{
|
|
3143
|
-
token:
|
|
3165
|
+
token: import_common42.Logger,
|
|
3144
3166
|
optional: true
|
|
3145
3167
|
}
|
|
3146
3168
|
]
|
|
@@ -3164,7 +3186,7 @@ function createLoggerProviders(options = {}) {
|
|
|
3164
3186
|
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3165
3187
|
}, "useFactory"),
|
|
3166
3188
|
inject: [
|
|
3167
|
-
|
|
3189
|
+
LoggerService,
|
|
3168
3190
|
LOGGER_MODULE_OPTIONS
|
|
3169
3191
|
]
|
|
3170
3192
|
});
|
|
@@ -3232,7 +3254,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3232
3254
|
module: _LoggerModule,
|
|
3233
3255
|
providers,
|
|
3234
3256
|
exports: [
|
|
3235
|
-
|
|
3257
|
+
LoggerService,
|
|
3236
3258
|
CorrelationIdMiddleware,
|
|
3237
3259
|
HttpLoggerInterceptor,
|
|
3238
3260
|
LOGGER_MODULE_OPTIONS
|
|
@@ -3291,10 +3313,10 @@ var LoggerModule = class _LoggerModule {
|
|
|
3291
3313
|
...asyncProviders,
|
|
3292
3314
|
// Default logger provider
|
|
3293
3315
|
{
|
|
3294
|
-
provide:
|
|
3316
|
+
provide: import_common42.Logger,
|
|
3295
3317
|
useFactory: /* @__PURE__ */ __name((opts) => {
|
|
3296
3318
|
if (opts.provider === "default") {
|
|
3297
|
-
const logger = new
|
|
3319
|
+
const logger = new import_common42.Logger();
|
|
3298
3320
|
if (opts.level && typeof logger.setLogLevels === "function") {
|
|
3299
3321
|
const levels = getLevelsUpTo(opts.level);
|
|
3300
3322
|
logger.setLogLevels(levels);
|
|
@@ -3309,14 +3331,14 @@ var LoggerModule = class _LoggerModule {
|
|
|
3309
3331
|
},
|
|
3310
3332
|
// Unified logger service
|
|
3311
3333
|
{
|
|
3312
|
-
provide:
|
|
3334
|
+
provide: LoggerService,
|
|
3313
3335
|
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3314
|
-
return new
|
|
3336
|
+
return new LoggerService(opts, defaultLogger);
|
|
3315
3337
|
}, "useFactory"),
|
|
3316
3338
|
inject: [
|
|
3317
3339
|
LOGGER_MODULE_OPTIONS,
|
|
3318
3340
|
{
|
|
3319
|
-
token:
|
|
3341
|
+
token: import_common42.Logger,
|
|
3320
3342
|
optional: true
|
|
3321
3343
|
}
|
|
3322
3344
|
]
|
|
@@ -3342,13 +3364,13 @@ var LoggerModule = class _LoggerModule {
|
|
|
3342
3364
|
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3343
3365
|
}, "useFactory"),
|
|
3344
3366
|
inject: [
|
|
3345
|
-
|
|
3367
|
+
LoggerService,
|
|
3346
3368
|
LOGGER_MODULE_OPTIONS
|
|
3347
3369
|
]
|
|
3348
3370
|
}
|
|
3349
3371
|
],
|
|
3350
3372
|
exports: [
|
|
3351
|
-
|
|
3373
|
+
LoggerService,
|
|
3352
3374
|
CorrelationIdMiddleware,
|
|
3353
3375
|
HttpLoggerInterceptor,
|
|
3354
3376
|
LOGGER_MODULE_OPTIONS
|
|
@@ -3423,8 +3445,8 @@ var LoggerModule = class _LoggerModule {
|
|
|
3423
3445
|
}
|
|
3424
3446
|
};
|
|
3425
3447
|
LoggerModule = _ts_decorate17([
|
|
3426
|
-
(0,
|
|
3427
|
-
(0,
|
|
3448
|
+
(0, import_common42.Global)(),
|
|
3449
|
+
(0, import_common42.Module)({})
|
|
3428
3450
|
], LoggerModule);
|
|
3429
3451
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3430
3452
|
0 && (module.exports = {
|
|
@@ -3465,6 +3487,7 @@ LoggerModule = _ts_decorate17([
|
|
|
3465
3487
|
UnauthorizedException,
|
|
3466
3488
|
UnprocessableEntityException,
|
|
3467
3489
|
UnsupportedMediaTypeException,
|
|
3490
|
+
UserId,
|
|
3468
3491
|
ValidationException,
|
|
3469
3492
|
VrittiAuthGuard,
|
|
3470
3493
|
addCorrelationIdToResponse,
|