@vritti/api-sdk 0.1.2 → 0.1.4
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 +521 -529
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1026 -1029
- package/dist/index.d.ts +1026 -1029
- package/dist/index.js +507 -515
- package/dist/index.js.map +1 -1
- package/package.json +9 -15
package/dist/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
+
// src/auth/auth-config.module.ts
|
|
5
|
+
import { Global as Global2, Module as Module2 } from "@nestjs/common";
|
|
6
|
+
import { ConfigModule, ConfigService as ConfigService2 } from "@nestjs/config";
|
|
7
|
+
import { APP_GUARD } from "@nestjs/core";
|
|
8
|
+
import { JwtModule } from "@nestjs/jwt";
|
|
9
|
+
|
|
10
|
+
// src/request/request.module.ts
|
|
11
|
+
import { Global, Module } from "@nestjs/common";
|
|
12
|
+
|
|
13
|
+
// src/request/services/request.service.ts
|
|
14
|
+
import { Inject, Injectable, Scope } from "@nestjs/common";
|
|
15
|
+
import { REQUEST } from "@nestjs/core";
|
|
16
|
+
|
|
4
17
|
// src/config/index.ts
|
|
5
18
|
var defaultConfig = {
|
|
6
19
|
cookie: {
|
|
@@ -75,31 +88,7 @@ function getJwtExpiry() {
|
|
|
75
88
|
}
|
|
76
89
|
__name(getJwtExpiry, "getJwtExpiry");
|
|
77
90
|
|
|
78
|
-
// src/auth/utils/token-hash.util.ts
|
|
79
|
-
import * as crypto from "crypto";
|
|
80
|
-
function hashToken(token) {
|
|
81
|
-
return crypto.createHash("sha256").update(token).digest("hex");
|
|
82
|
-
}
|
|
83
|
-
__name(hashToken, "hashToken");
|
|
84
|
-
function verifyTokenHash(token, expectedHash) {
|
|
85
|
-
const computedHash = hashToken(token);
|
|
86
|
-
if (computedHash.length !== expectedHash.length) return false;
|
|
87
|
-
return crypto.timingSafeEqual(Buffer.from(computedHash, "hex"), Buffer.from(expectedHash, "hex"));
|
|
88
|
-
}
|
|
89
|
-
__name(verifyTokenHash, "verifyTokenHash");
|
|
90
|
-
|
|
91
|
-
// src/auth/auth-config.module.ts
|
|
92
|
-
import { Global as Global2, Module as Module2 } from "@nestjs/common";
|
|
93
|
-
import { ConfigModule, ConfigService as ConfigService2 } from "@nestjs/config";
|
|
94
|
-
import { APP_GUARD } from "@nestjs/core";
|
|
95
|
-
import { JwtModule } from "@nestjs/jwt";
|
|
96
|
-
|
|
97
|
-
// src/request/request.module.ts
|
|
98
|
-
import { Global, Module } from "@nestjs/common";
|
|
99
|
-
|
|
100
91
|
// src/request/services/request.service.ts
|
|
101
|
-
import { Inject, Injectable, Scope } from "@nestjs/common";
|
|
102
|
-
import { REQUEST } from "@nestjs/core";
|
|
103
92
|
function _ts_decorate(decorators, target, key, desc) {
|
|
104
93
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
105
94
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -166,7 +155,7 @@ var RequestService = class {
|
|
|
166
155
|
}
|
|
167
156
|
}
|
|
168
157
|
return null;
|
|
169
|
-
} catch (
|
|
158
|
+
} catch (_error) {
|
|
170
159
|
return null;
|
|
171
160
|
}
|
|
172
161
|
}
|
|
@@ -223,16 +212,16 @@ RequestModule = _ts_decorate2([
|
|
|
223
212
|
], RequestModule);
|
|
224
213
|
|
|
225
214
|
// src/auth/guards/vritti-auth.guard.ts
|
|
226
|
-
import { Injectable as Injectable3, Logger as
|
|
215
|
+
import { Injectable as Injectable3, Logger as Logger3, Scope as Scope2, UnauthorizedException } from "@nestjs/common";
|
|
227
216
|
import { ConfigService } from "@nestjs/config";
|
|
228
217
|
import { Reflector } from "@nestjs/core";
|
|
229
218
|
import { JwtService } from "@nestjs/jwt";
|
|
230
219
|
|
|
231
220
|
// src/database/services/primary-database.service.ts
|
|
232
|
-
import { Inject as Inject2, Injectable as Injectable2, InternalServerErrorException, Logger } from "@nestjs/common";
|
|
233
|
-
import { Pool } from "pg";
|
|
234
|
-
import { drizzle } from "drizzle-orm/node-postgres";
|
|
221
|
+
import { Inject as Inject2, Injectable as Injectable2, InternalServerErrorException, Logger as Logger2 } from "@nestjs/common";
|
|
235
222
|
import { eq, or } from "drizzle-orm";
|
|
223
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
224
|
+
import { Pool } from "pg";
|
|
236
225
|
|
|
237
226
|
// src/database/constants.ts
|
|
238
227
|
var DATABASE_MODULE_OPTIONS = Symbol("DATABASE_MODULE_OPTIONS");
|
|
@@ -260,7 +249,7 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
|
|
|
260
249
|
__name(this, "PrimaryDatabaseService");
|
|
261
250
|
}
|
|
262
251
|
options;
|
|
263
|
-
logger = new
|
|
252
|
+
logger = new Logger2(_PrimaryDatabaseService.name);
|
|
264
253
|
/** PostgreSQL connection pool */
|
|
265
254
|
pool = null;
|
|
266
255
|
/** Drizzle database instance */
|
|
@@ -465,6 +454,19 @@ PrimaryDatabaseService = _ts_decorate3([
|
|
|
465
454
|
])
|
|
466
455
|
], PrimaryDatabaseService);
|
|
467
456
|
|
|
457
|
+
// src/auth/utils/token-hash.util.ts
|
|
458
|
+
import * as crypto from "crypto";
|
|
459
|
+
function hashToken(token) {
|
|
460
|
+
return crypto.createHash("sha256").update(token).digest("hex");
|
|
461
|
+
}
|
|
462
|
+
__name(hashToken, "hashToken");
|
|
463
|
+
function verifyTokenHash(token, expectedHash) {
|
|
464
|
+
const computedHash = hashToken(token);
|
|
465
|
+
if (computedHash.length !== expectedHash.length) return false;
|
|
466
|
+
return crypto.timingSafeEqual(Buffer.from(computedHash, "hex"), Buffer.from(expectedHash, "hex"));
|
|
467
|
+
}
|
|
468
|
+
__name(verifyTokenHash, "verifyTokenHash");
|
|
469
|
+
|
|
468
470
|
// src/auth/guards/vritti-auth.guard.ts
|
|
469
471
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
470
472
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -482,14 +484,14 @@ var VrittiAuthGuard = class _VrittiAuthGuard {
|
|
|
482
484
|
__name(this, "VrittiAuthGuard");
|
|
483
485
|
}
|
|
484
486
|
reflector;
|
|
485
|
-
|
|
487
|
+
_configService;
|
|
486
488
|
jwtService;
|
|
487
489
|
primaryDatabase;
|
|
488
490
|
requestService;
|
|
489
|
-
logger = new
|
|
490
|
-
constructor(reflector,
|
|
491
|
+
logger = new Logger3(_VrittiAuthGuard.name);
|
|
492
|
+
constructor(reflector, _configService, jwtService, primaryDatabase, requestService) {
|
|
491
493
|
this.reflector = reflector;
|
|
492
|
-
this.
|
|
494
|
+
this._configService = _configService;
|
|
493
495
|
this.jwtService = jwtService;
|
|
494
496
|
this.primaryDatabase = primaryDatabase;
|
|
495
497
|
this.requestService = requestService;
|
|
@@ -716,12 +718,20 @@ AuthConfigModule = _ts_decorate5([
|
|
|
716
718
|
Module2({})
|
|
717
719
|
], AuthConfigModule);
|
|
718
720
|
|
|
721
|
+
// src/auth/decorators/onboarding.decorator.ts
|
|
722
|
+
import { SetMetadata } from "@nestjs/common";
|
|
723
|
+
var Onboarding = /* @__PURE__ */ __name(() => SetMetadata("isOnboarding", true), "Onboarding");
|
|
724
|
+
|
|
725
|
+
// src/auth/decorators/public.decorator.ts
|
|
726
|
+
import { SetMetadata as SetMetadata2 } from "@nestjs/common";
|
|
727
|
+
var Public = /* @__PURE__ */ __name(() => SetMetadata2("isPublic", true), "Public");
|
|
728
|
+
|
|
719
729
|
// src/database/database.module.ts
|
|
720
730
|
import { Global as Global3, Module as Module3 } from "@nestjs/common";
|
|
721
731
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
722
732
|
|
|
723
733
|
// src/database/interceptors/message-tenant-context.interceptor.ts
|
|
724
|
-
import { Injectable as Injectable5, Logger as
|
|
734
|
+
import { Injectable as Injectable5, Logger as Logger4, Scope as Scope4 } from "@nestjs/common";
|
|
725
735
|
import { tap } from "rxjs/operators";
|
|
726
736
|
|
|
727
737
|
// src/database/services/tenant-context.service.ts
|
|
@@ -827,7 +837,7 @@ var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
|
827
837
|
__name(this, "MessageTenantContextInterceptor");
|
|
828
838
|
}
|
|
829
839
|
tenantContext;
|
|
830
|
-
logger = new
|
|
840
|
+
logger = new Logger4(_MessageTenantContextInterceptor.name);
|
|
831
841
|
constructor(tenantContext) {
|
|
832
842
|
this.tenantContext = tenantContext;
|
|
833
843
|
}
|
|
@@ -836,7 +846,7 @@ var MessageTenantContextInterceptor = class _MessageTenantContextInterceptor {
|
|
|
836
846
|
if (contextType === "rpc") {
|
|
837
847
|
const rpcContext = context.switchToRpc();
|
|
838
848
|
const payload = rpcContext.getData();
|
|
839
|
-
if (payload
|
|
849
|
+
if (payload?.tenant) {
|
|
840
850
|
const tenant = payload.tenant;
|
|
841
851
|
this.logger.debug(`Setting tenant context from message: ${tenant.subdomain}`);
|
|
842
852
|
try {
|
|
@@ -883,7 +893,7 @@ MessageTenantContextInterceptor = _ts_decorate7([
|
|
|
883
893
|
], MessageTenantContextInterceptor);
|
|
884
894
|
|
|
885
895
|
// src/database/interceptors/tenant-context.interceptor.ts
|
|
886
|
-
import { Injectable as Injectable6, Logger as
|
|
896
|
+
import { Injectable as Injectable6, Logger as Logger5, Scope as Scope5, UnauthorizedException as UnauthorizedException3 } from "@nestjs/common";
|
|
887
897
|
import { Reflector as Reflector2 } from "@nestjs/core";
|
|
888
898
|
function _ts_decorate8(decorators, target, key, desc) {
|
|
889
899
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -904,7 +914,7 @@ var TenantContextInterceptor = class _TenantContextInterceptor {
|
|
|
904
914
|
tenantContext;
|
|
905
915
|
primaryDatabase;
|
|
906
916
|
requestService;
|
|
907
|
-
logger = new
|
|
917
|
+
logger = new Logger5(_TenantContextInterceptor.name);
|
|
908
918
|
constructor(reflector, tenantContext, primaryDatabase, requestService) {
|
|
909
919
|
this.reflector = reflector;
|
|
910
920
|
this.tenantContext = tenantContext;
|
|
@@ -966,9 +976,9 @@ TenantContextInterceptor = _ts_decorate8([
|
|
|
966
976
|
], TenantContextInterceptor);
|
|
967
977
|
|
|
968
978
|
// src/database/services/tenant-database.service.ts
|
|
969
|
-
import { Inject as Inject3, Injectable as Injectable7, InternalServerErrorException as InternalServerErrorException2, Logger as
|
|
970
|
-
import { Pool as Pool2 } from "pg";
|
|
979
|
+
import { Inject as Inject3, Injectable as Injectable7, InternalServerErrorException as InternalServerErrorException2, Logger as Logger6 } from "@nestjs/common";
|
|
971
980
|
import { drizzle as drizzle2 } from "drizzle-orm/node-postgres";
|
|
981
|
+
import { Pool as Pool2 } from "pg";
|
|
972
982
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
973
983
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
974
984
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -992,7 +1002,7 @@ var TenantDatabaseService = class _TenantDatabaseService {
|
|
|
992
1002
|
}
|
|
993
1003
|
options;
|
|
994
1004
|
tenantContext;
|
|
995
|
-
logger = new
|
|
1005
|
+
logger = new Logger6(_TenantDatabaseService.name);
|
|
996
1006
|
/** Connection pool: Map<cacheKey, TenantConnection> */
|
|
997
1007
|
clients = /* @__PURE__ */ new Map();
|
|
998
1008
|
/** Track last usage time for idle connection cleanup */
|
|
@@ -1211,7 +1221,7 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1211
1221
|
* })
|
|
1212
1222
|
*/
|
|
1213
1223
|
static forServer(options) {
|
|
1214
|
-
return
|
|
1224
|
+
return _DatabaseModule.createDynamicModule(options, "server");
|
|
1215
1225
|
}
|
|
1216
1226
|
/**
|
|
1217
1227
|
* Configure DatabaseModule for Microservice/Messaging mode (RabbitMQ workers)
|
|
@@ -1233,7 +1243,7 @@ var DatabaseModule = class _DatabaseModule {
|
|
|
1233
1243
|
* })
|
|
1234
1244
|
*/
|
|
1235
1245
|
static forMicroservice(options) {
|
|
1236
|
-
return
|
|
1246
|
+
return _DatabaseModule.createDynamicModule(options, "microservice");
|
|
1237
1247
|
}
|
|
1238
1248
|
/**
|
|
1239
1249
|
* Internal helper to create dynamic module with conditional interceptor registration
|
|
@@ -1285,9 +1295,20 @@ DatabaseModule = _ts_decorate10([
|
|
|
1285
1295
|
Module3({})
|
|
1286
1296
|
], DatabaseModule);
|
|
1287
1297
|
|
|
1298
|
+
// src/database/decorators/tenant.decorator.ts
|
|
1299
|
+
import { createParamDecorator } from "@nestjs/common";
|
|
1300
|
+
var Tenant = createParamDecorator((_data, ctx) => {
|
|
1301
|
+
const request = ctx.switchToHttp().getRequest();
|
|
1302
|
+
const tenantContext = request.app?.get?.(TenantContextService);
|
|
1303
|
+
if (!tenantContext) {
|
|
1304
|
+
throw new Error("TenantContextService not found.");
|
|
1305
|
+
}
|
|
1306
|
+
return tenantContext.getTenant();
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1288
1309
|
// src/database/repositories/primary-base.repository.ts
|
|
1289
|
-
import { Logger as
|
|
1290
|
-
import { eq as eq2,
|
|
1310
|
+
import { Logger as Logger7 } from "@nestjs/common";
|
|
1311
|
+
import { eq as eq2, getTableName, sql } from "drizzle-orm";
|
|
1291
1312
|
function snakeToCamel(str) {
|
|
1292
1313
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1293
1314
|
}
|
|
@@ -1357,7 +1378,7 @@ var PrimaryBaseRepository = class {
|
|
|
1357
1378
|
this.table = table;
|
|
1358
1379
|
const dbTableName = getTableName(table);
|
|
1359
1380
|
this.tableName = snakeToCamel(dbTableName);
|
|
1360
|
-
this.logger = new
|
|
1381
|
+
this.logger = new Logger7(this.constructor.name);
|
|
1361
1382
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1362
1383
|
this.logger.debug(`Table name: '${dbTableName}' -> query key: '${this.tableName}'`);
|
|
1363
1384
|
}
|
|
@@ -1597,8 +1618,8 @@ var PrimaryBaseRepository = class {
|
|
|
1597
1618
|
};
|
|
1598
1619
|
|
|
1599
1620
|
// src/database/repositories/tenant-base.repository.ts
|
|
1600
|
-
import { Logger as
|
|
1601
|
-
import { eq as eq3,
|
|
1621
|
+
import { Logger as Logger8 } from "@nestjs/common";
|
|
1622
|
+
import { eq as eq3, getTableName as getTableName2, sql as sql2 } from "drizzle-orm";
|
|
1602
1623
|
var TenantBaseRepository = class {
|
|
1603
1624
|
static {
|
|
1604
1625
|
__name(this, "TenantBaseRepository");
|
|
@@ -1654,7 +1675,7 @@ var TenantBaseRepository = class {
|
|
|
1654
1675
|
this.database = database;
|
|
1655
1676
|
this.table = table;
|
|
1656
1677
|
this.tableName = getTableName2(table);
|
|
1657
|
-
this.logger = new
|
|
1678
|
+
this.logger = new Logger8(this.constructor.name);
|
|
1658
1679
|
this.logger.debug(`Initialized ${this.constructor.name}`);
|
|
1659
1680
|
}
|
|
1660
1681
|
/**
|
|
@@ -1886,270 +1907,82 @@ var TenantBaseRepository = class {
|
|
|
1886
1907
|
}
|
|
1887
1908
|
};
|
|
1888
1909
|
|
|
1889
|
-
// src/
|
|
1890
|
-
import {
|
|
1891
|
-
var Tenant = createParamDecorator((data, ctx) => {
|
|
1892
|
-
const request = ctx.switchToHttp().getRequest();
|
|
1893
|
-
const tenantContext = request.app?.get?.(TenantContextService);
|
|
1894
|
-
if (!tenantContext) {
|
|
1895
|
-
throw new Error("TenantContextService not found.");
|
|
1896
|
-
}
|
|
1897
|
-
return tenantContext.getTenant();
|
|
1898
|
-
});
|
|
1899
|
-
|
|
1900
|
-
// src/auth/decorators/onboarding.decorator.ts
|
|
1901
|
-
import { SetMetadata } from "@nestjs/common";
|
|
1902
|
-
var Onboarding = /* @__PURE__ */ __name(() => SetMetadata("isOnboarding", true), "Onboarding");
|
|
1903
|
-
|
|
1904
|
-
// src/auth/decorators/public.decorator.ts
|
|
1905
|
-
import { SetMetadata as SetMetadata2 } from "@nestjs/common";
|
|
1906
|
-
var Public = /* @__PURE__ */ __name(() => SetMetadata2("isPublic", true), "Public");
|
|
1907
|
-
|
|
1908
|
-
// src/http/http.module.ts
|
|
1909
|
-
import { Module as Module4 } from "@nestjs/common";
|
|
1910
|
+
// src/exceptions/bad-gateway.exception.ts
|
|
1911
|
+
import { HttpStatus as HttpStatus2 } from "@nestjs/common";
|
|
1910
1912
|
|
|
1911
|
-
// src/
|
|
1912
|
-
import {
|
|
1913
|
-
|
|
1914
|
-
function _ts_decorate11(decorators, target, key, desc) {
|
|
1915
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1916
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1917
|
-
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;
|
|
1918
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1919
|
-
}
|
|
1920
|
-
__name(_ts_decorate11, "_ts_decorate");
|
|
1921
|
-
function _ts_metadata7(k, v) {
|
|
1922
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1923
|
-
}
|
|
1924
|
-
__name(_ts_metadata7, "_ts_metadata");
|
|
1925
|
-
var CsrfGuard = class _CsrfGuard {
|
|
1913
|
+
// src/exceptions/base-field.exception.ts
|
|
1914
|
+
import { HttpException, HttpStatus } from "@nestjs/common";
|
|
1915
|
+
var BaseFieldException = class extends HttpException {
|
|
1926
1916
|
static {
|
|
1927
|
-
__name(this, "
|
|
1928
|
-
}
|
|
1929
|
-
reflector;
|
|
1930
|
-
logger = new Logger8(_CsrfGuard.name);
|
|
1931
|
-
constructor(reflector) {
|
|
1932
|
-
this.reflector = reflector;
|
|
1917
|
+
__name(this, "BaseFieldException");
|
|
1933
1918
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
if (
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
field: "csrf",
|
|
1968
|
-
message: "Invalid or missing CSRF token"
|
|
1969
|
-
}
|
|
1970
|
-
],
|
|
1971
|
-
message: "CSRF validation failed"
|
|
1972
|
-
});
|
|
1919
|
+
constructor(statusOrMessageOrErrors, messageOrStatus, statusOrDetail, detail) {
|
|
1920
|
+
let errors;
|
|
1921
|
+
let httpStatus;
|
|
1922
|
+
let finalDetail;
|
|
1923
|
+
if (Array.isArray(statusOrMessageOrErrors)) {
|
|
1924
|
+
errors = statusOrMessageOrErrors;
|
|
1925
|
+
httpStatus = messageOrStatus || HttpStatus.BAD_REQUEST;
|
|
1926
|
+
finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
|
|
1927
|
+
} else if (typeof statusOrMessageOrErrors === "string" && typeof messageOrStatus === "string") {
|
|
1928
|
+
errors = [
|
|
1929
|
+
{
|
|
1930
|
+
field: statusOrMessageOrErrors,
|
|
1931
|
+
message: messageOrStatus
|
|
1932
|
+
}
|
|
1933
|
+
];
|
|
1934
|
+
httpStatus = statusOrDetail;
|
|
1935
|
+
finalDetail = detail;
|
|
1936
|
+
} else if (typeof statusOrMessageOrErrors === "string") {
|
|
1937
|
+
errors = [
|
|
1938
|
+
{
|
|
1939
|
+
message: statusOrMessageOrErrors
|
|
1940
|
+
}
|
|
1941
|
+
];
|
|
1942
|
+
httpStatus = messageOrStatus;
|
|
1943
|
+
finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
|
|
1944
|
+
} else {
|
|
1945
|
+
errors = [
|
|
1946
|
+
{
|
|
1947
|
+
message: "An error occurred"
|
|
1948
|
+
}
|
|
1949
|
+
];
|
|
1950
|
+
httpStatus = statusOrMessageOrErrors;
|
|
1951
|
+
finalDetail = void 0;
|
|
1973
1952
|
}
|
|
1953
|
+
const response = finalDetail !== void 0 ? {
|
|
1954
|
+
errors,
|
|
1955
|
+
detail: finalDetail
|
|
1956
|
+
} : {
|
|
1957
|
+
errors
|
|
1958
|
+
};
|
|
1959
|
+
super(response, httpStatus);
|
|
1974
1960
|
}
|
|
1975
1961
|
};
|
|
1976
|
-
CsrfGuard = _ts_decorate11([
|
|
1977
|
-
Injectable8(),
|
|
1978
|
-
_ts_metadata7("design:type", Function),
|
|
1979
|
-
_ts_metadata7("design:paramtypes", [
|
|
1980
|
-
typeof Reflector3 === "undefined" ? Object : Reflector3
|
|
1981
|
-
])
|
|
1982
|
-
], CsrfGuard);
|
|
1983
1962
|
|
|
1984
|
-
// src/
|
|
1985
|
-
|
|
1986
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1987
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1988
|
-
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;
|
|
1989
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1990
|
-
}
|
|
1991
|
-
__name(_ts_decorate12, "_ts_decorate");
|
|
1992
|
-
var HttpModule = class {
|
|
1963
|
+
// src/exceptions/bad-gateway.exception.ts
|
|
1964
|
+
var BadGatewayException = class extends BaseFieldException {
|
|
1993
1965
|
static {
|
|
1994
|
-
__name(this, "
|
|
1966
|
+
__name(this, "BadGatewayException");
|
|
1967
|
+
}
|
|
1968
|
+
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
1969
|
+
if (Array.isArray(messageOrField)) {
|
|
1970
|
+
super(messageOrField, HttpStatus2.BAD_GATEWAY, fieldMessageOrDetail);
|
|
1971
|
+
} else if (detail !== void 0) {
|
|
1972
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus2.BAD_GATEWAY, detail);
|
|
1973
|
+
} else if (fieldMessageOrDetail) {
|
|
1974
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus2.BAD_GATEWAY);
|
|
1975
|
+
} else {
|
|
1976
|
+
super(messageOrField, HttpStatus2.BAD_GATEWAY);
|
|
1977
|
+
}
|
|
1995
1978
|
}
|
|
1996
1979
|
};
|
|
1997
|
-
HttpModule = _ts_decorate12([
|
|
1998
|
-
Module4({
|
|
1999
|
-
providers: [
|
|
2000
|
-
CsrfGuard
|
|
2001
|
-
],
|
|
2002
|
-
exports: [
|
|
2003
|
-
CsrfGuard
|
|
2004
|
-
]
|
|
2005
|
-
})
|
|
2006
|
-
], HttpModule);
|
|
2007
1980
|
|
|
2008
|
-
// src/
|
|
2009
|
-
import {
|
|
2010
|
-
|
|
2011
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2012
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2013
|
-
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;
|
|
2014
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2015
|
-
}
|
|
2016
|
-
__name(_ts_decorate13, "_ts_decorate");
|
|
2017
|
-
function getHttpStatusTitle(status) {
|
|
2018
|
-
const enumKey = Object.entries(HttpStatus).find(([key, value]) => value === status && isNaN(Number(key)))?.[0];
|
|
2019
|
-
if (!enumKey) {
|
|
2020
|
-
return "Error";
|
|
2021
|
-
}
|
|
2022
|
-
return enumKey.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
2023
|
-
}
|
|
2024
|
-
__name(getHttpStatusTitle, "getHttpStatusTitle");
|
|
2025
|
-
var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
1981
|
+
// src/exceptions/bad-request.exception.ts
|
|
1982
|
+
import { HttpStatus as HttpStatus3 } from "@nestjs/common";
|
|
1983
|
+
var BadRequestException = class extends BaseFieldException {
|
|
2026
1984
|
static {
|
|
2027
|
-
__name(this, "
|
|
2028
|
-
}
|
|
2029
|
-
logger = new Logger9(_HttpExceptionFilter.name);
|
|
2030
|
-
catch(exception, host) {
|
|
2031
|
-
const ctx = host.switchToHttp();
|
|
2032
|
-
const response = ctx.getResponse();
|
|
2033
|
-
let status = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
2034
|
-
let errors = [];
|
|
2035
|
-
let detail = "Internal server error";
|
|
2036
|
-
if (exception instanceof HttpException) {
|
|
2037
|
-
status = exception.getStatus();
|
|
2038
|
-
const exceptionResponse = exception.getResponse();
|
|
2039
|
-
if (typeof exceptionResponse === "object" && exceptionResponse !== null) {
|
|
2040
|
-
const responseObj = exceptionResponse;
|
|
2041
|
-
if ("errors" in responseObj && Array.isArray(responseObj.errors)) {
|
|
2042
|
-
errors = responseObj.errors;
|
|
2043
|
-
detail = ("detail" in responseObj ? responseObj.detail : void 0) || exception.message;
|
|
2044
|
-
} else if ("message" in responseObj && Array.isArray(responseObj.message)) {
|
|
2045
|
-
errors = responseObj.message.map((msg) => {
|
|
2046
|
-
if (typeof msg === "object" && "property" in msg && "constraints" in msg) {
|
|
2047
|
-
const constraintValues = Object.values(msg.constraints);
|
|
2048
|
-
return {
|
|
2049
|
-
field: msg.property,
|
|
2050
|
-
message: constraintValues[0] ?? "Validation failed"
|
|
2051
|
-
};
|
|
2052
|
-
}
|
|
2053
|
-
return {
|
|
2054
|
-
message: typeof msg === "string" ? msg : JSON.stringify(msg)
|
|
2055
|
-
};
|
|
2056
|
-
});
|
|
2057
|
-
detail = "Validation failed";
|
|
2058
|
-
} else if ("message" in responseObj) {
|
|
2059
|
-
const message = responseObj.message;
|
|
2060
|
-
errors = [
|
|
2061
|
-
{
|
|
2062
|
-
message: Array.isArray(message) ? message.join(", ") : message
|
|
2063
|
-
}
|
|
2064
|
-
];
|
|
2065
|
-
detail = ("error" in responseObj ? responseObj.error : void 0) || exception.message;
|
|
2066
|
-
}
|
|
2067
|
-
} else if (typeof exceptionResponse === "string") {
|
|
2068
|
-
errors = [
|
|
2069
|
-
{
|
|
2070
|
-
message: exceptionResponse
|
|
2071
|
-
}
|
|
2072
|
-
];
|
|
2073
|
-
detail = exceptionResponse;
|
|
2074
|
-
}
|
|
2075
|
-
} else {
|
|
2076
|
-
const errorMessage = exception instanceof Error ? exception.message : "Unknown error";
|
|
2077
|
-
const stack = exception instanceof Error ? exception.stack : void 0;
|
|
2078
|
-
this.logger.error(`Unexpected error: ${errorMessage}`, stack);
|
|
2079
|
-
errors = [
|
|
2080
|
-
{
|
|
2081
|
-
message: "An unexpected error occurred"
|
|
2082
|
-
}
|
|
2083
|
-
];
|
|
2084
|
-
}
|
|
2085
|
-
const problemDetails = {
|
|
2086
|
-
title: getHttpStatusTitle(status),
|
|
2087
|
-
status,
|
|
2088
|
-
detail,
|
|
2089
|
-
errors
|
|
2090
|
-
};
|
|
2091
|
-
response.status(status).send(problemDetails);
|
|
2092
|
-
}
|
|
2093
|
-
};
|
|
2094
|
-
HttpExceptionFilter = _ts_decorate13([
|
|
2095
|
-
Catch()
|
|
2096
|
-
], HttpExceptionFilter);
|
|
2097
|
-
|
|
2098
|
-
// src/exceptions/base-field.exception.ts
|
|
2099
|
-
import { HttpException as HttpException2, HttpStatus as HttpStatus2 } from "@nestjs/common";
|
|
2100
|
-
var BaseFieldException = class extends HttpException2 {
|
|
2101
|
-
static {
|
|
2102
|
-
__name(this, "BaseFieldException");
|
|
2103
|
-
}
|
|
2104
|
-
constructor(statusOrMessageOrErrors, messageOrStatus, statusOrDetail, detail) {
|
|
2105
|
-
let errors;
|
|
2106
|
-
let httpStatus;
|
|
2107
|
-
let finalDetail;
|
|
2108
|
-
if (Array.isArray(statusOrMessageOrErrors)) {
|
|
2109
|
-
errors = statusOrMessageOrErrors;
|
|
2110
|
-
httpStatus = messageOrStatus || HttpStatus2.BAD_REQUEST;
|
|
2111
|
-
finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
|
|
2112
|
-
} else if (typeof statusOrMessageOrErrors === "string" && typeof messageOrStatus === "string") {
|
|
2113
|
-
errors = [
|
|
2114
|
-
{
|
|
2115
|
-
field: statusOrMessageOrErrors,
|
|
2116
|
-
message: messageOrStatus
|
|
2117
|
-
}
|
|
2118
|
-
];
|
|
2119
|
-
httpStatus = statusOrDetail;
|
|
2120
|
-
finalDetail = detail;
|
|
2121
|
-
} else if (typeof statusOrMessageOrErrors === "string") {
|
|
2122
|
-
errors = [
|
|
2123
|
-
{
|
|
2124
|
-
message: statusOrMessageOrErrors
|
|
2125
|
-
}
|
|
2126
|
-
];
|
|
2127
|
-
httpStatus = messageOrStatus;
|
|
2128
|
-
finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
|
|
2129
|
-
} else {
|
|
2130
|
-
errors = [
|
|
2131
|
-
{
|
|
2132
|
-
message: "An error occurred"
|
|
2133
|
-
}
|
|
2134
|
-
];
|
|
2135
|
-
httpStatus = statusOrMessageOrErrors;
|
|
2136
|
-
finalDetail = void 0;
|
|
2137
|
-
}
|
|
2138
|
-
const response = finalDetail !== void 0 ? {
|
|
2139
|
-
errors,
|
|
2140
|
-
detail: finalDetail
|
|
2141
|
-
} : {
|
|
2142
|
-
errors
|
|
2143
|
-
};
|
|
2144
|
-
super(response, httpStatus);
|
|
2145
|
-
}
|
|
2146
|
-
};
|
|
2147
|
-
|
|
2148
|
-
// src/exceptions/bad-request.exception.ts
|
|
2149
|
-
import { HttpStatus as HttpStatus3 } from "@nestjs/common";
|
|
2150
|
-
var BadRequestException = class extends BaseFieldException {
|
|
2151
|
-
static {
|
|
2152
|
-
__name(this, "BadRequestException");
|
|
1985
|
+
__name(this, "BadRequestException");
|
|
2153
1986
|
}
|
|
2154
1987
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2155
1988
|
if (Array.isArray(messageOrField)) {
|
|
@@ -2164,28 +1997,28 @@ var BadRequestException = class extends BaseFieldException {
|
|
|
2164
1997
|
}
|
|
2165
1998
|
};
|
|
2166
1999
|
|
|
2167
|
-
// src/exceptions/
|
|
2000
|
+
// src/exceptions/conflict.exception.ts
|
|
2168
2001
|
import { HttpStatus as HttpStatus4 } from "@nestjs/common";
|
|
2169
|
-
var
|
|
2002
|
+
var ConflictException = class extends BaseFieldException {
|
|
2170
2003
|
static {
|
|
2171
|
-
__name(this, "
|
|
2004
|
+
__name(this, "ConflictException");
|
|
2172
2005
|
}
|
|
2173
2006
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2174
2007
|
if (Array.isArray(messageOrField)) {
|
|
2175
|
-
super(messageOrField, HttpStatus4.
|
|
2008
|
+
super(messageOrField, HttpStatus4.CONFLICT, fieldMessageOrDetail);
|
|
2176
2009
|
} else if (detail !== void 0) {
|
|
2177
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus4.
|
|
2010
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus4.CONFLICT, detail);
|
|
2178
2011
|
} else if (fieldMessageOrDetail) {
|
|
2179
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus4.
|
|
2012
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus4.CONFLICT);
|
|
2180
2013
|
} else {
|
|
2181
|
-
super(messageOrField, HttpStatus4.
|
|
2014
|
+
super(messageOrField, HttpStatus4.CONFLICT);
|
|
2182
2015
|
}
|
|
2183
2016
|
}
|
|
2184
2017
|
};
|
|
2185
2018
|
|
|
2186
2019
|
// src/exceptions/forbidden.exception.ts
|
|
2187
2020
|
import { HttpStatus as HttpStatus5 } from "@nestjs/common";
|
|
2188
|
-
var
|
|
2021
|
+
var ForbiddenException = class extends BaseFieldException {
|
|
2189
2022
|
static {
|
|
2190
2023
|
__name(this, "ForbiddenException");
|
|
2191
2024
|
}
|
|
@@ -2202,222 +2035,230 @@ var ForbiddenException2 = class extends BaseFieldException {
|
|
|
2202
2035
|
}
|
|
2203
2036
|
};
|
|
2204
2037
|
|
|
2205
|
-
// src/exceptions/
|
|
2038
|
+
// src/exceptions/gone.exception.ts
|
|
2206
2039
|
import { HttpStatus as HttpStatus6 } from "@nestjs/common";
|
|
2207
|
-
var
|
|
2040
|
+
var GoneException = class extends BaseFieldException {
|
|
2208
2041
|
static {
|
|
2209
|
-
__name(this, "
|
|
2042
|
+
__name(this, "GoneException");
|
|
2210
2043
|
}
|
|
2211
2044
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2212
2045
|
if (Array.isArray(messageOrField)) {
|
|
2213
|
-
super(messageOrField, HttpStatus6.
|
|
2046
|
+
super(messageOrField, HttpStatus6.GONE, fieldMessageOrDetail);
|
|
2214
2047
|
} else if (detail !== void 0) {
|
|
2215
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus6.
|
|
2048
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus6.GONE, detail);
|
|
2216
2049
|
} else if (fieldMessageOrDetail) {
|
|
2217
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus6.
|
|
2050
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus6.GONE);
|
|
2218
2051
|
} else {
|
|
2219
|
-
super(messageOrField, HttpStatus6.
|
|
2052
|
+
super(messageOrField, HttpStatus6.GONE);
|
|
2220
2053
|
}
|
|
2221
2054
|
}
|
|
2222
2055
|
};
|
|
2223
2056
|
|
|
2224
|
-
// src/exceptions/
|
|
2057
|
+
// src/exceptions/internal-server-error.exception.ts
|
|
2225
2058
|
import { HttpStatus as HttpStatus7 } from "@nestjs/common";
|
|
2226
|
-
var
|
|
2059
|
+
var InternalServerErrorException3 = class extends BaseFieldException {
|
|
2227
2060
|
static {
|
|
2228
|
-
__name(this, "
|
|
2061
|
+
__name(this, "InternalServerErrorException");
|
|
2229
2062
|
}
|
|
2230
2063
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2231
2064
|
if (Array.isArray(messageOrField)) {
|
|
2232
|
-
super(messageOrField, HttpStatus7.
|
|
2065
|
+
super(messageOrField, HttpStatus7.INTERNAL_SERVER_ERROR, fieldMessageOrDetail);
|
|
2233
2066
|
} else if (detail !== void 0) {
|
|
2234
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus7.
|
|
2067
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus7.INTERNAL_SERVER_ERROR, detail);
|
|
2235
2068
|
} else if (fieldMessageOrDetail) {
|
|
2236
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus7.
|
|
2069
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus7.INTERNAL_SERVER_ERROR);
|
|
2237
2070
|
} else {
|
|
2238
|
-
super(messageOrField, HttpStatus7.
|
|
2071
|
+
super(messageOrField, HttpStatus7.INTERNAL_SERVER_ERROR);
|
|
2239
2072
|
}
|
|
2240
2073
|
}
|
|
2241
2074
|
};
|
|
2242
2075
|
|
|
2243
|
-
// src/exceptions/
|
|
2076
|
+
// src/exceptions/method-not-allowed.exception.ts
|
|
2244
2077
|
import { HttpStatus as HttpStatus8 } from "@nestjs/common";
|
|
2245
|
-
var
|
|
2078
|
+
var MethodNotAllowedException = class extends BaseFieldException {
|
|
2246
2079
|
static {
|
|
2247
|
-
__name(this, "
|
|
2080
|
+
__name(this, "MethodNotAllowedException");
|
|
2248
2081
|
}
|
|
2249
2082
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2250
2083
|
if (Array.isArray(messageOrField)) {
|
|
2251
|
-
super(messageOrField, HttpStatus8.
|
|
2084
|
+
super(messageOrField, HttpStatus8.METHOD_NOT_ALLOWED, fieldMessageOrDetail);
|
|
2252
2085
|
} else if (detail !== void 0) {
|
|
2253
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus8.
|
|
2086
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus8.METHOD_NOT_ALLOWED, detail);
|
|
2254
2087
|
} else if (fieldMessageOrDetail) {
|
|
2255
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus8.
|
|
2088
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus8.METHOD_NOT_ALLOWED);
|
|
2256
2089
|
} else {
|
|
2257
|
-
super(messageOrField, HttpStatus8.
|
|
2090
|
+
super(messageOrField, HttpStatus8.METHOD_NOT_ALLOWED);
|
|
2258
2091
|
}
|
|
2259
2092
|
}
|
|
2260
2093
|
};
|
|
2261
2094
|
|
|
2262
|
-
// src/exceptions/
|
|
2095
|
+
// src/exceptions/not-acceptable.exception.ts
|
|
2263
2096
|
import { HttpStatus as HttpStatus9 } from "@nestjs/common";
|
|
2264
|
-
var
|
|
2097
|
+
var NotAcceptableException = class extends BaseFieldException {
|
|
2265
2098
|
static {
|
|
2266
|
-
__name(this, "
|
|
2099
|
+
__name(this, "NotAcceptableException");
|
|
2267
2100
|
}
|
|
2268
|
-
constructor(
|
|
2269
|
-
|
|
2101
|
+
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2102
|
+
if (Array.isArray(messageOrField)) {
|
|
2103
|
+
super(messageOrField, HttpStatus9.NOT_ACCEPTABLE, fieldMessageOrDetail);
|
|
2104
|
+
} else if (detail !== void 0) {
|
|
2105
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus9.NOT_ACCEPTABLE, detail);
|
|
2106
|
+
} else if (fieldMessageOrDetail) {
|
|
2107
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus9.NOT_ACCEPTABLE);
|
|
2108
|
+
} else {
|
|
2109
|
+
super(messageOrField, HttpStatus9.NOT_ACCEPTABLE);
|
|
2110
|
+
}
|
|
2270
2111
|
}
|
|
2271
2112
|
};
|
|
2272
2113
|
|
|
2273
|
-
// src/exceptions/
|
|
2114
|
+
// src/exceptions/not-found.exception.ts
|
|
2274
2115
|
import { HttpStatus as HttpStatus10 } from "@nestjs/common";
|
|
2275
|
-
var
|
|
2116
|
+
var NotFoundException = class extends BaseFieldException {
|
|
2276
2117
|
static {
|
|
2277
|
-
__name(this, "
|
|
2118
|
+
__name(this, "NotFoundException");
|
|
2278
2119
|
}
|
|
2279
2120
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2280
2121
|
if (Array.isArray(messageOrField)) {
|
|
2281
|
-
super(messageOrField, HttpStatus10.
|
|
2122
|
+
super(messageOrField, HttpStatus10.NOT_FOUND, fieldMessageOrDetail);
|
|
2282
2123
|
} else if (detail !== void 0) {
|
|
2283
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus10.
|
|
2124
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus10.NOT_FOUND, detail);
|
|
2284
2125
|
} else if (fieldMessageOrDetail) {
|
|
2285
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus10.
|
|
2126
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus10.NOT_FOUND);
|
|
2286
2127
|
} else {
|
|
2287
|
-
super(messageOrField, HttpStatus10.
|
|
2128
|
+
super(messageOrField, HttpStatus10.NOT_FOUND);
|
|
2288
2129
|
}
|
|
2289
2130
|
}
|
|
2290
2131
|
};
|
|
2291
2132
|
|
|
2292
|
-
// src/exceptions/
|
|
2133
|
+
// src/exceptions/not-implemented.exception.ts
|
|
2293
2134
|
import { HttpStatus as HttpStatus11 } from "@nestjs/common";
|
|
2294
|
-
var
|
|
2135
|
+
var NotImplementedException = class extends BaseFieldException {
|
|
2295
2136
|
static {
|
|
2296
|
-
__name(this, "
|
|
2137
|
+
__name(this, "NotImplementedException");
|
|
2297
2138
|
}
|
|
2298
2139
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2299
2140
|
if (Array.isArray(messageOrField)) {
|
|
2300
|
-
super(messageOrField, HttpStatus11.
|
|
2141
|
+
super(messageOrField, HttpStatus11.NOT_IMPLEMENTED, fieldMessageOrDetail);
|
|
2301
2142
|
} else if (detail !== void 0) {
|
|
2302
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus11.
|
|
2143
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus11.NOT_IMPLEMENTED, detail);
|
|
2303
2144
|
} else if (fieldMessageOrDetail) {
|
|
2304
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus11.
|
|
2145
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus11.NOT_IMPLEMENTED);
|
|
2305
2146
|
} else {
|
|
2306
|
-
super(messageOrField, HttpStatus11.
|
|
2147
|
+
super(messageOrField, HttpStatus11.NOT_IMPLEMENTED);
|
|
2307
2148
|
}
|
|
2308
2149
|
}
|
|
2309
2150
|
};
|
|
2310
2151
|
|
|
2311
|
-
// src/exceptions/
|
|
2152
|
+
// src/exceptions/payload-too-large.exception.ts
|
|
2312
2153
|
import { HttpStatus as HttpStatus12 } from "@nestjs/common";
|
|
2313
|
-
var
|
|
2154
|
+
var PayloadTooLargeException = class extends BaseFieldException {
|
|
2314
2155
|
static {
|
|
2315
|
-
__name(this, "
|
|
2156
|
+
__name(this, "PayloadTooLargeException");
|
|
2316
2157
|
}
|
|
2317
2158
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2318
2159
|
if (Array.isArray(messageOrField)) {
|
|
2319
|
-
super(messageOrField, HttpStatus12.
|
|
2160
|
+
super(messageOrField, HttpStatus12.PAYLOAD_TOO_LARGE, fieldMessageOrDetail);
|
|
2320
2161
|
} else if (detail !== void 0) {
|
|
2321
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus12.
|
|
2162
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus12.PAYLOAD_TOO_LARGE, detail);
|
|
2322
2163
|
} else if (fieldMessageOrDetail) {
|
|
2323
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus12.
|
|
2164
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus12.PAYLOAD_TOO_LARGE);
|
|
2324
2165
|
} else {
|
|
2325
|
-
super(messageOrField, HttpStatus12.
|
|
2166
|
+
super(messageOrField, HttpStatus12.PAYLOAD_TOO_LARGE);
|
|
2326
2167
|
}
|
|
2327
2168
|
}
|
|
2328
2169
|
};
|
|
2329
2170
|
|
|
2330
|
-
// src/exceptions/
|
|
2171
|
+
// src/exceptions/request-timeout.exception.ts
|
|
2331
2172
|
import { HttpStatus as HttpStatus13 } from "@nestjs/common";
|
|
2332
|
-
var
|
|
2173
|
+
var RequestTimeoutException = class extends BaseFieldException {
|
|
2333
2174
|
static {
|
|
2334
|
-
__name(this, "
|
|
2175
|
+
__name(this, "RequestTimeoutException");
|
|
2335
2176
|
}
|
|
2336
2177
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2337
2178
|
if (Array.isArray(messageOrField)) {
|
|
2338
|
-
super(messageOrField, HttpStatus13.
|
|
2179
|
+
super(messageOrField, HttpStatus13.REQUEST_TIMEOUT, fieldMessageOrDetail);
|
|
2339
2180
|
} else if (detail !== void 0) {
|
|
2340
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus13.
|
|
2181
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus13.REQUEST_TIMEOUT, detail);
|
|
2341
2182
|
} else if (fieldMessageOrDetail) {
|
|
2342
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus13.
|
|
2183
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus13.REQUEST_TIMEOUT);
|
|
2343
2184
|
} else {
|
|
2344
|
-
super(messageOrField, HttpStatus13.
|
|
2185
|
+
super(messageOrField, HttpStatus13.REQUEST_TIMEOUT);
|
|
2345
2186
|
}
|
|
2346
2187
|
}
|
|
2347
2188
|
};
|
|
2348
2189
|
|
|
2349
|
-
// src/exceptions/
|
|
2190
|
+
// src/exceptions/service-unavailable.exception.ts
|
|
2350
2191
|
import { HttpStatus as HttpStatus14 } from "@nestjs/common";
|
|
2351
|
-
var
|
|
2192
|
+
var ServiceUnavailableException = class extends BaseFieldException {
|
|
2352
2193
|
static {
|
|
2353
|
-
__name(this, "
|
|
2194
|
+
__name(this, "ServiceUnavailableException");
|
|
2354
2195
|
}
|
|
2355
2196
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2356
2197
|
if (Array.isArray(messageOrField)) {
|
|
2357
|
-
super(messageOrField, HttpStatus14.
|
|
2198
|
+
super(messageOrField, HttpStatus14.SERVICE_UNAVAILABLE, fieldMessageOrDetail);
|
|
2358
2199
|
} else if (detail !== void 0) {
|
|
2359
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus14.
|
|
2200
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus14.SERVICE_UNAVAILABLE, detail);
|
|
2360
2201
|
} else if (fieldMessageOrDetail) {
|
|
2361
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus14.
|
|
2202
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus14.SERVICE_UNAVAILABLE);
|
|
2362
2203
|
} else {
|
|
2363
|
-
super(messageOrField, HttpStatus14.
|
|
2204
|
+
super(messageOrField, HttpStatus14.SERVICE_UNAVAILABLE);
|
|
2364
2205
|
}
|
|
2365
2206
|
}
|
|
2366
2207
|
};
|
|
2367
2208
|
|
|
2368
|
-
// src/exceptions/
|
|
2209
|
+
// src/exceptions/too-many-requests.exception.ts
|
|
2369
2210
|
import { HttpStatus as HttpStatus15 } from "@nestjs/common";
|
|
2370
|
-
var
|
|
2211
|
+
var TooManyRequestsException = class extends BaseFieldException {
|
|
2371
2212
|
static {
|
|
2372
|
-
__name(this, "
|
|
2213
|
+
__name(this, "TooManyRequestsException");
|
|
2373
2214
|
}
|
|
2374
2215
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2375
2216
|
if (Array.isArray(messageOrField)) {
|
|
2376
|
-
super(messageOrField, HttpStatus15.
|
|
2217
|
+
super(messageOrField, HttpStatus15.TOO_MANY_REQUESTS, fieldMessageOrDetail);
|
|
2377
2218
|
} else if (detail !== void 0) {
|
|
2378
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus15.
|
|
2219
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus15.TOO_MANY_REQUESTS, detail);
|
|
2379
2220
|
} else if (fieldMessageOrDetail) {
|
|
2380
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus15.
|
|
2221
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus15.TOO_MANY_REQUESTS);
|
|
2381
2222
|
} else {
|
|
2382
|
-
super(messageOrField, HttpStatus15.
|
|
2223
|
+
super(messageOrField, HttpStatus15.TOO_MANY_REQUESTS);
|
|
2383
2224
|
}
|
|
2384
2225
|
}
|
|
2385
2226
|
};
|
|
2386
2227
|
|
|
2387
|
-
// src/exceptions/
|
|
2228
|
+
// src/exceptions/unauthorized.exception.ts
|
|
2388
2229
|
import { HttpStatus as HttpStatus16 } from "@nestjs/common";
|
|
2389
|
-
var
|
|
2230
|
+
var UnauthorizedException4 = class extends BaseFieldException {
|
|
2390
2231
|
static {
|
|
2391
|
-
__name(this, "
|
|
2232
|
+
__name(this, "UnauthorizedException");
|
|
2392
2233
|
}
|
|
2393
2234
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2394
2235
|
if (Array.isArray(messageOrField)) {
|
|
2395
|
-
super(messageOrField, HttpStatus16.
|
|
2236
|
+
super(messageOrField, HttpStatus16.UNAUTHORIZED, fieldMessageOrDetail);
|
|
2396
2237
|
} else if (detail !== void 0) {
|
|
2397
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus16.
|
|
2238
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus16.UNAUTHORIZED, detail);
|
|
2398
2239
|
} else if (fieldMessageOrDetail) {
|
|
2399
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus16.
|
|
2240
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus16.UNAUTHORIZED);
|
|
2400
2241
|
} else {
|
|
2401
|
-
super(messageOrField, HttpStatus16.
|
|
2242
|
+
super(messageOrField, HttpStatus16.UNAUTHORIZED);
|
|
2402
2243
|
}
|
|
2403
2244
|
}
|
|
2404
2245
|
};
|
|
2405
2246
|
|
|
2406
|
-
// src/exceptions/
|
|
2247
|
+
// src/exceptions/unprocessable-entity.exception.ts
|
|
2407
2248
|
import { HttpStatus as HttpStatus17 } from "@nestjs/common";
|
|
2408
|
-
var
|
|
2249
|
+
var UnprocessableEntityException = class extends BaseFieldException {
|
|
2409
2250
|
static {
|
|
2410
|
-
__name(this, "
|
|
2251
|
+
__name(this, "UnprocessableEntityException");
|
|
2411
2252
|
}
|
|
2412
2253
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2413
2254
|
if (Array.isArray(messageOrField)) {
|
|
2414
|
-
super(messageOrField, HttpStatus17.
|
|
2255
|
+
super(messageOrField, HttpStatus17.UNPROCESSABLE_ENTITY, fieldMessageOrDetail);
|
|
2415
2256
|
} else if (detail !== void 0) {
|
|
2416
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus17.
|
|
2257
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus17.UNPROCESSABLE_ENTITY, detail);
|
|
2417
2258
|
} else if (fieldMessageOrDetail) {
|
|
2418
|
-
super(messageOrField, fieldMessageOrDetail, HttpStatus17.
|
|
2259
|
+
super(messageOrField, fieldMessageOrDetail, HttpStatus17.UNPROCESSABLE_ENTITY);
|
|
2419
2260
|
} else {
|
|
2420
|
-
super(messageOrField, HttpStatus17.
|
|
2261
|
+
super(messageOrField, HttpStatus17.UNPROCESSABLE_ENTITY);
|
|
2421
2262
|
}
|
|
2422
2263
|
}
|
|
2423
2264
|
};
|
|
@@ -2441,49 +2282,198 @@ var UnsupportedMediaTypeException = class extends BaseFieldException {
|
|
|
2441
2282
|
}
|
|
2442
2283
|
};
|
|
2443
2284
|
|
|
2444
|
-
// src/exceptions/
|
|
2285
|
+
// src/exceptions/validation.exception.ts
|
|
2445
2286
|
import { HttpStatus as HttpStatus19 } from "@nestjs/common";
|
|
2446
|
-
var
|
|
2287
|
+
var ValidationException = class extends BaseFieldException {
|
|
2447
2288
|
static {
|
|
2448
|
-
__name(this, "
|
|
2289
|
+
__name(this, "ValidationException");
|
|
2449
2290
|
}
|
|
2450
|
-
constructor(
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2291
|
+
constructor(errors, detail) {
|
|
2292
|
+
super(errors, HttpStatus19.BAD_REQUEST, detail);
|
|
2293
|
+
}
|
|
2294
|
+
};
|
|
2295
|
+
|
|
2296
|
+
// src/filters/http-exception.filter.ts
|
|
2297
|
+
import { Catch, HttpException as HttpException2, HttpStatus as HttpStatus20, Logger as Logger9 } from "@nestjs/common";
|
|
2298
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
2299
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2300
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2301
|
+
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;
|
|
2302
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2303
|
+
}
|
|
2304
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
2305
|
+
function getHttpStatusTitle(status) {
|
|
2306
|
+
const enumKey = Object.entries(HttpStatus20).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
|
|
2307
|
+
if (!enumKey) {
|
|
2308
|
+
return "Error";
|
|
2309
|
+
}
|
|
2310
|
+
return enumKey.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
2311
|
+
}
|
|
2312
|
+
__name(getHttpStatusTitle, "getHttpStatusTitle");
|
|
2313
|
+
var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
2314
|
+
static {
|
|
2315
|
+
__name(this, "HttpExceptionFilter");
|
|
2316
|
+
}
|
|
2317
|
+
logger = new Logger9(_HttpExceptionFilter.name);
|
|
2318
|
+
catch(exception, host) {
|
|
2319
|
+
const ctx = host.switchToHttp();
|
|
2320
|
+
const response = ctx.getResponse();
|
|
2321
|
+
let status = HttpStatus20.INTERNAL_SERVER_ERROR;
|
|
2322
|
+
let errors = [];
|
|
2323
|
+
let detail = "Internal server error";
|
|
2324
|
+
if (exception instanceof HttpException2) {
|
|
2325
|
+
status = exception.getStatus();
|
|
2326
|
+
const exceptionResponse = exception.getResponse();
|
|
2327
|
+
if (typeof exceptionResponse === "object" && exceptionResponse !== null) {
|
|
2328
|
+
const responseObj = exceptionResponse;
|
|
2329
|
+
if ("errors" in responseObj && Array.isArray(responseObj.errors)) {
|
|
2330
|
+
errors = responseObj.errors;
|
|
2331
|
+
detail = ("detail" in responseObj ? responseObj.detail : void 0) || exception.message;
|
|
2332
|
+
} else if ("message" in responseObj && Array.isArray(responseObj.message)) {
|
|
2333
|
+
errors = responseObj.message.map((msg) => {
|
|
2334
|
+
if (typeof msg === "object" && "property" in msg && "constraints" in msg) {
|
|
2335
|
+
const constraintValues = Object.values(msg.constraints);
|
|
2336
|
+
return {
|
|
2337
|
+
field: msg.property,
|
|
2338
|
+
message: constraintValues[0] ?? "Validation failed"
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
return {
|
|
2342
|
+
message: typeof msg === "string" ? msg : JSON.stringify(msg)
|
|
2343
|
+
};
|
|
2344
|
+
});
|
|
2345
|
+
detail = "Validation failed";
|
|
2346
|
+
} else if ("message" in responseObj) {
|
|
2347
|
+
const message = responseObj.message;
|
|
2348
|
+
errors = [
|
|
2349
|
+
{
|
|
2350
|
+
message: Array.isArray(message) ? message.join(", ") : message
|
|
2351
|
+
}
|
|
2352
|
+
];
|
|
2353
|
+
detail = ("error" in responseObj ? responseObj.error : void 0) || exception.message;
|
|
2354
|
+
}
|
|
2355
|
+
} else if (typeof exceptionResponse === "string") {
|
|
2356
|
+
errors = [
|
|
2357
|
+
{
|
|
2358
|
+
message: exceptionResponse
|
|
2359
|
+
}
|
|
2360
|
+
];
|
|
2361
|
+
detail = exceptionResponse;
|
|
2362
|
+
}
|
|
2457
2363
|
} else {
|
|
2458
|
-
|
|
2364
|
+
const errorMessage = exception instanceof Error ? exception.message : "Unknown error";
|
|
2365
|
+
const stack = exception instanceof Error ? exception.stack : void 0;
|
|
2366
|
+
this.logger.error(`Unexpected error: ${errorMessage}`, stack);
|
|
2367
|
+
errors = [
|
|
2368
|
+
{
|
|
2369
|
+
message: "An unexpected error occurred"
|
|
2370
|
+
}
|
|
2371
|
+
];
|
|
2459
2372
|
}
|
|
2373
|
+
const problemDetails = {
|
|
2374
|
+
title: getHttpStatusTitle(status),
|
|
2375
|
+
status,
|
|
2376
|
+
detail,
|
|
2377
|
+
errors
|
|
2378
|
+
};
|
|
2379
|
+
response.status(status).send(problemDetails);
|
|
2460
2380
|
}
|
|
2461
2381
|
};
|
|
2382
|
+
HttpExceptionFilter = _ts_decorate11([
|
|
2383
|
+
Catch()
|
|
2384
|
+
], HttpExceptionFilter);
|
|
2462
2385
|
|
|
2463
|
-
// src/
|
|
2464
|
-
import {
|
|
2465
|
-
|
|
2386
|
+
// src/http/guards/csrf.guard.ts
|
|
2387
|
+
import { ForbiddenException as ForbiddenException2, Injectable as Injectable8, Logger as Logger10 } from "@nestjs/common";
|
|
2388
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2389
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2390
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2391
|
+
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;
|
|
2392
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2393
|
+
}
|
|
2394
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
2395
|
+
var CsrfGuard = class _CsrfGuard {
|
|
2466
2396
|
static {
|
|
2467
|
-
__name(this, "
|
|
2397
|
+
__name(this, "CsrfGuard");
|
|
2468
2398
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2399
|
+
logger = new Logger10(_CsrfGuard.name);
|
|
2400
|
+
async canActivate(context) {
|
|
2401
|
+
const request = context.switchToHttp().getRequest();
|
|
2402
|
+
const reply = context.switchToHttp().getResponse();
|
|
2403
|
+
const safeMethods = [
|
|
2404
|
+
"GET",
|
|
2405
|
+
"HEAD",
|
|
2406
|
+
"OPTIONS"
|
|
2407
|
+
];
|
|
2408
|
+
if (safeMethods.includes(request.method)) {
|
|
2409
|
+
return true;
|
|
2410
|
+
}
|
|
2411
|
+
try {
|
|
2412
|
+
const fastifyInstance = request.server;
|
|
2413
|
+
if (!fastifyInstance.csrfProtection) {
|
|
2414
|
+
this.logger.error("CSRF protection plugin not found. Ensure @fastify/csrf-protection is registered.");
|
|
2415
|
+
throw new ForbiddenException2("CSRF protection not configured");
|
|
2416
|
+
}
|
|
2417
|
+
await new Promise((resolve, reject) => {
|
|
2418
|
+
fastifyInstance.csrfProtection(request, reply, (err) => {
|
|
2419
|
+
if (err) {
|
|
2420
|
+
reject(err);
|
|
2421
|
+
} else {
|
|
2422
|
+
resolve();
|
|
2423
|
+
}
|
|
2424
|
+
});
|
|
2425
|
+
});
|
|
2426
|
+
this.logger.debug(`CSRF validation successful for ${request.method} ${request.url}`);
|
|
2427
|
+
return true;
|
|
2428
|
+
} catch (error) {
|
|
2429
|
+
this.logger.warn(`CSRF validation failed for ${request.method} ${request.url}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2430
|
+
throw new ForbiddenException2({
|
|
2431
|
+
errors: [
|
|
2432
|
+
{
|
|
2433
|
+
field: "csrf",
|
|
2434
|
+
message: "Invalid or missing CSRF token"
|
|
2435
|
+
}
|
|
2436
|
+
],
|
|
2437
|
+
message: "CSRF validation failed"
|
|
2438
|
+
});
|
|
2478
2439
|
}
|
|
2479
2440
|
}
|
|
2480
2441
|
};
|
|
2442
|
+
CsrfGuard = _ts_decorate12([
|
|
2443
|
+
Injectable8()
|
|
2444
|
+
], CsrfGuard);
|
|
2481
2445
|
|
|
2482
|
-
// src/
|
|
2483
|
-
import {
|
|
2446
|
+
// src/http/http.module.ts
|
|
2447
|
+
import { Module as Module4 } from "@nestjs/common";
|
|
2448
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
2449
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2450
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2451
|
+
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;
|
|
2452
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2453
|
+
}
|
|
2454
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
2455
|
+
var HttpModule = class {
|
|
2456
|
+
static {
|
|
2457
|
+
__name(this, "HttpModule");
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
HttpModule = _ts_decorate13([
|
|
2461
|
+
Module4({
|
|
2462
|
+
providers: [
|
|
2463
|
+
CsrfGuard
|
|
2464
|
+
],
|
|
2465
|
+
exports: [
|
|
2466
|
+
CsrfGuard
|
|
2467
|
+
]
|
|
2468
|
+
})
|
|
2469
|
+
], HttpModule);
|
|
2470
|
+
|
|
2471
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2472
|
+
import { Injectable as Injectable10, Optional as Optional2 } from "@nestjs/common";
|
|
2473
|
+
import { catchError, tap as tap2 } from "rxjs/operators";
|
|
2484
2474
|
|
|
2485
2475
|
// src/logger/services/logger.service.ts
|
|
2486
|
-
import { Injectable as Injectable9,
|
|
2476
|
+
import { Injectable as Injectable9, Optional } from "@nestjs/common";
|
|
2487
2477
|
import { createLogger, format, transports } from "winston";
|
|
2488
2478
|
import DailyRotateFile from "winston-daily-rotate-file";
|
|
2489
2479
|
|
|
@@ -2528,17 +2518,17 @@ function _ts_decorate14(decorators, target, key, desc) {
|
|
|
2528
2518
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2529
2519
|
}
|
|
2530
2520
|
__name(_ts_decorate14, "_ts_decorate");
|
|
2531
|
-
function
|
|
2521
|
+
function _ts_metadata7(k, v) {
|
|
2532
2522
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2533
2523
|
}
|
|
2534
|
-
__name(
|
|
2524
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
2535
2525
|
function _ts_param4(paramIndex, decorator) {
|
|
2536
2526
|
return function(target, key) {
|
|
2537
2527
|
decorator(target, key, paramIndex);
|
|
2538
2528
|
};
|
|
2539
2529
|
}
|
|
2540
2530
|
__name(_ts_param4, "_ts_param");
|
|
2541
|
-
var
|
|
2531
|
+
var LoggerService = class _LoggerService {
|
|
2542
2532
|
static {
|
|
2543
2533
|
__name(this, "LoggerService");
|
|
2544
2534
|
}
|
|
@@ -2590,7 +2580,8 @@ var LoggerService2 = class _LoggerService {
|
|
|
2590
2580
|
].filter(Boolean);
|
|
2591
2581
|
let output = parts.join(" ");
|
|
2592
2582
|
if (trace) {
|
|
2593
|
-
output +=
|
|
2583
|
+
output += `
|
|
2584
|
+
${trace}`;
|
|
2594
2585
|
}
|
|
2595
2586
|
return output;
|
|
2596
2587
|
}), format.colorize({
|
|
@@ -2738,19 +2729,18 @@ var LoggerService2 = class _LoggerService {
|
|
|
2738
2729
|
return childLogger;
|
|
2739
2730
|
}
|
|
2740
2731
|
};
|
|
2741
|
-
|
|
2732
|
+
LoggerService = _ts_decorate14([
|
|
2742
2733
|
Injectable9(),
|
|
2743
2734
|
_ts_param4(0, Optional()),
|
|
2744
2735
|
_ts_param4(1, Optional()),
|
|
2745
|
-
|
|
2746
|
-
|
|
2736
|
+
_ts_metadata7("design:type", Function),
|
|
2737
|
+
_ts_metadata7("design:paramtypes", [
|
|
2747
2738
|
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
2748
|
-
typeof
|
|
2739
|
+
typeof Logger === "undefined" ? Object : Logger
|
|
2749
2740
|
])
|
|
2750
|
-
],
|
|
2741
|
+
], LoggerService);
|
|
2751
2742
|
|
|
2752
|
-
// src/logger/
|
|
2753
|
-
import { Injectable as Injectable10 } from "@nestjs/common";
|
|
2743
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2754
2744
|
function _ts_decorate15(decorators, target, key, desc) {
|
|
2755
2745
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2756
2746
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2758,74 +2748,10 @@ function _ts_decorate15(decorators, target, key, desc) {
|
|
|
2758
2748
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2759
2749
|
}
|
|
2760
2750
|
__name(_ts_decorate15, "_ts_decorate");
|
|
2761
|
-
function
|
|
2762
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2763
|
-
}
|
|
2764
|
-
__name(_ts_metadata9, "_ts_metadata");
|
|
2765
|
-
var CorrelationIdMiddleware = class {
|
|
2766
|
-
static {
|
|
2767
|
-
__name(this, "CorrelationIdMiddleware");
|
|
2768
|
-
}
|
|
2769
|
-
includeInResponse;
|
|
2770
|
-
responseHeader;
|
|
2771
|
-
constructor(options = {}) {
|
|
2772
|
-
this.includeInResponse = options.includeInResponse ?? true;
|
|
2773
|
-
this.responseHeader = options.responseHeader ?? DEFAULT_CORRELATION_HEADER;
|
|
2774
|
-
}
|
|
2775
|
-
/**
|
|
2776
|
-
* Middleware handler for processing requests.
|
|
2777
|
-
*/
|
|
2778
|
-
use(req, reply, next) {
|
|
2779
|
-
const correlationId = generateCorrelationId();
|
|
2780
|
-
if (this.includeInResponse) {
|
|
2781
|
-
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2782
|
-
}
|
|
2783
|
-
runWithCorrelationContext({
|
|
2784
|
-
correlationId
|
|
2785
|
-
}, () => {
|
|
2786
|
-
next();
|
|
2787
|
-
});
|
|
2788
|
-
}
|
|
2789
|
-
/**
|
|
2790
|
-
* Fastify hook handler for onRequest.
|
|
2791
|
-
* This is an async function that returns a Promise, ensuring the AsyncLocalStorage
|
|
2792
|
-
* context persists throughout the entire request lifecycle.
|
|
2793
|
-
*/
|
|
2794
|
-
async onRequest(req, reply) {
|
|
2795
|
-
const correlationId = generateCorrelationId();
|
|
2796
|
-
if (this.includeInResponse) {
|
|
2797
|
-
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2798
|
-
}
|
|
2799
|
-
const store = correlationStorage.getStore();
|
|
2800
|
-
if (!store) {
|
|
2801
|
-
correlationStorage.enterWith({
|
|
2802
|
-
correlationId
|
|
2803
|
-
});
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
};
|
|
2807
|
-
CorrelationIdMiddleware = _ts_decorate15([
|
|
2808
|
-
Injectable10(),
|
|
2809
|
-
_ts_metadata9("design:type", Function),
|
|
2810
|
-
_ts_metadata9("design:paramtypes", [
|
|
2811
|
-
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
2812
|
-
])
|
|
2813
|
-
], CorrelationIdMiddleware);
|
|
2814
|
-
|
|
2815
|
-
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2816
|
-
import { Injectable as Injectable11, Optional as Optional2 } from "@nestjs/common";
|
|
2817
|
-
import { tap as tap2, catchError } from "rxjs/operators";
|
|
2818
|
-
function _ts_decorate16(decorators, target, key, desc) {
|
|
2819
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2820
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2821
|
-
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;
|
|
2822
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2823
|
-
}
|
|
2824
|
-
__name(_ts_decorate16, "_ts_decorate");
|
|
2825
|
-
function _ts_metadata10(k, v) {
|
|
2751
|
+
function _ts_metadata8(k, v) {
|
|
2826
2752
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2827
2753
|
}
|
|
2828
|
-
__name(
|
|
2754
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2829
2755
|
function _ts_param5(paramIndex, decorator) {
|
|
2830
2756
|
return function(target, key) {
|
|
2831
2757
|
decorator(target, key, paramIndex);
|
|
@@ -2933,16 +2859,82 @@ var HttpLoggerInterceptor = class {
|
|
|
2933
2859
|
}
|
|
2934
2860
|
}
|
|
2935
2861
|
};
|
|
2936
|
-
HttpLoggerInterceptor =
|
|
2937
|
-
|
|
2862
|
+
HttpLoggerInterceptor = _ts_decorate15([
|
|
2863
|
+
Injectable10(),
|
|
2938
2864
|
_ts_param5(1, Optional2()),
|
|
2939
|
-
|
|
2940
|
-
|
|
2865
|
+
_ts_metadata8("design:type", Function),
|
|
2866
|
+
_ts_metadata8("design:paramtypes", [
|
|
2941
2867
|
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2942
2868
|
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2943
2869
|
])
|
|
2944
2870
|
], HttpLoggerInterceptor);
|
|
2945
2871
|
|
|
2872
|
+
// src/logger/logger.module.ts
|
|
2873
|
+
import { Global as Global4, Logger as Logger11, Module as Module5 } from "@nestjs/common";
|
|
2874
|
+
|
|
2875
|
+
// src/logger/middleware/correlation-id.middleware.ts
|
|
2876
|
+
import { Injectable as Injectable11 } from "@nestjs/common";
|
|
2877
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
2878
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2879
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2880
|
+
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;
|
|
2881
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2882
|
+
}
|
|
2883
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
2884
|
+
function _ts_metadata9(k, v) {
|
|
2885
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2886
|
+
}
|
|
2887
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2888
|
+
var CorrelationIdMiddleware = class {
|
|
2889
|
+
static {
|
|
2890
|
+
__name(this, "CorrelationIdMiddleware");
|
|
2891
|
+
}
|
|
2892
|
+
includeInResponse;
|
|
2893
|
+
responseHeader;
|
|
2894
|
+
constructor(options = {}) {
|
|
2895
|
+
this.includeInResponse = options.includeInResponse ?? true;
|
|
2896
|
+
this.responseHeader = options.responseHeader ?? DEFAULT_CORRELATION_HEADER;
|
|
2897
|
+
}
|
|
2898
|
+
/**
|
|
2899
|
+
* Middleware handler for processing requests.
|
|
2900
|
+
*/
|
|
2901
|
+
use(_req, reply, next) {
|
|
2902
|
+
const correlationId = generateCorrelationId();
|
|
2903
|
+
if (this.includeInResponse) {
|
|
2904
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2905
|
+
}
|
|
2906
|
+
runWithCorrelationContext({
|
|
2907
|
+
correlationId
|
|
2908
|
+
}, () => {
|
|
2909
|
+
next();
|
|
2910
|
+
});
|
|
2911
|
+
}
|
|
2912
|
+
/**
|
|
2913
|
+
* Fastify hook handler for onRequest.
|
|
2914
|
+
* This is an async function that returns a Promise, ensuring the AsyncLocalStorage
|
|
2915
|
+
* context persists throughout the entire request lifecycle.
|
|
2916
|
+
*/
|
|
2917
|
+
async onRequest(_req, reply) {
|
|
2918
|
+
const correlationId = generateCorrelationId();
|
|
2919
|
+
if (this.includeInResponse) {
|
|
2920
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2921
|
+
}
|
|
2922
|
+
const store = correlationStorage.getStore();
|
|
2923
|
+
if (!store) {
|
|
2924
|
+
correlationStorage.enterWith({
|
|
2925
|
+
correlationId
|
|
2926
|
+
});
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
};
|
|
2930
|
+
CorrelationIdMiddleware = _ts_decorate16([
|
|
2931
|
+
Injectable11(),
|
|
2932
|
+
_ts_metadata9("design:type", Function),
|
|
2933
|
+
_ts_metadata9("design:paramtypes", [
|
|
2934
|
+
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
2935
|
+
])
|
|
2936
|
+
], CorrelationIdMiddleware);
|
|
2937
|
+
|
|
2946
2938
|
// src/logger/logger.module.ts
|
|
2947
2939
|
function _ts_decorate17(decorators, target, key, desc) {
|
|
2948
2940
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3064,9 +3056,9 @@ function createLoggerProviders(options = {}) {
|
|
|
3064
3056
|
providers.push(createDefaultLoggerProvider(mergedOptions));
|
|
3065
3057
|
}
|
|
3066
3058
|
providers.push({
|
|
3067
|
-
provide:
|
|
3059
|
+
provide: LoggerService,
|
|
3068
3060
|
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3069
|
-
return new
|
|
3061
|
+
return new LoggerService(opts, defaultLogger);
|
|
3070
3062
|
}, "useFactory"),
|
|
3071
3063
|
inject: [
|
|
3072
3064
|
LOGGER_MODULE_OPTIONS,
|
|
@@ -3095,7 +3087,7 @@ function createLoggerProviders(options = {}) {
|
|
|
3095
3087
|
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3096
3088
|
}, "useFactory"),
|
|
3097
3089
|
inject: [
|
|
3098
|
-
|
|
3090
|
+
LoggerService,
|
|
3099
3091
|
LOGGER_MODULE_OPTIONS
|
|
3100
3092
|
]
|
|
3101
3093
|
});
|
|
@@ -3163,7 +3155,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3163
3155
|
module: _LoggerModule,
|
|
3164
3156
|
providers,
|
|
3165
3157
|
exports: [
|
|
3166
|
-
|
|
3158
|
+
LoggerService,
|
|
3167
3159
|
CorrelationIdMiddleware,
|
|
3168
3160
|
HttpLoggerInterceptor,
|
|
3169
3161
|
LOGGER_MODULE_OPTIONS
|
|
@@ -3214,7 +3206,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3214
3206
|
* ```
|
|
3215
3207
|
*/
|
|
3216
3208
|
static forRootAsync(options) {
|
|
3217
|
-
const asyncProviders =
|
|
3209
|
+
const asyncProviders = _LoggerModule.createAsyncProviders(options);
|
|
3218
3210
|
return {
|
|
3219
3211
|
module: _LoggerModule,
|
|
3220
3212
|
imports: options.imports || [],
|
|
@@ -3240,9 +3232,9 @@ var LoggerModule = class _LoggerModule {
|
|
|
3240
3232
|
},
|
|
3241
3233
|
// Unified logger service
|
|
3242
3234
|
{
|
|
3243
|
-
provide:
|
|
3235
|
+
provide: LoggerService,
|
|
3244
3236
|
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3245
|
-
return new
|
|
3237
|
+
return new LoggerService(opts, defaultLogger);
|
|
3246
3238
|
}, "useFactory"),
|
|
3247
3239
|
inject: [
|
|
3248
3240
|
LOGGER_MODULE_OPTIONS,
|
|
@@ -3273,13 +3265,13 @@ var LoggerModule = class _LoggerModule {
|
|
|
3273
3265
|
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3274
3266
|
}, "useFactory"),
|
|
3275
3267
|
inject: [
|
|
3276
|
-
|
|
3268
|
+
LoggerService,
|
|
3277
3269
|
LOGGER_MODULE_OPTIONS
|
|
3278
3270
|
]
|
|
3279
3271
|
}
|
|
3280
3272
|
],
|
|
3281
3273
|
exports: [
|
|
3282
|
-
|
|
3274
|
+
LoggerService,
|
|
3283
3275
|
CorrelationIdMiddleware,
|
|
3284
3276
|
HttpLoggerInterceptor,
|
|
3285
3277
|
LOGGER_MODULE_OPTIONS
|
|
@@ -3290,7 +3282,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3290
3282
|
* Configures middleware for the module.
|
|
3291
3283
|
* Middleware is registered globally in main.ts using Fastify hooks.
|
|
3292
3284
|
*/
|
|
3293
|
-
configure(
|
|
3285
|
+
configure(_consumer) {
|
|
3294
3286
|
}
|
|
3295
3287
|
/**
|
|
3296
3288
|
* Creates async providers for dynamic module configuration.
|
|
@@ -3298,11 +3290,11 @@ var LoggerModule = class _LoggerModule {
|
|
|
3298
3290
|
static createAsyncProviders(options) {
|
|
3299
3291
|
if (options.useFactory) {
|
|
3300
3292
|
return [
|
|
3301
|
-
|
|
3293
|
+
_LoggerModule.createAsyncOptionsProvider(options)
|
|
3302
3294
|
];
|
|
3303
3295
|
}
|
|
3304
3296
|
const providers = [
|
|
3305
|
-
|
|
3297
|
+
_LoggerModule.createAsyncOptionsProvider(options)
|
|
3306
3298
|
];
|
|
3307
3299
|
if (options.useClass) {
|
|
3308
3300
|
providers.push({
|
|
@@ -3320,7 +3312,7 @@ var LoggerModule = class _LoggerModule {
|
|
|
3320
3312
|
return {
|
|
3321
3313
|
provide: LOGGER_MODULE_OPTIONS,
|
|
3322
3314
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
3323
|
-
const userOptions = await options.useFactory(...args);
|
|
3315
|
+
const userOptions = await options.useFactory?.(...args);
|
|
3324
3316
|
return mergeWithDefaults(userOptions);
|
|
3325
3317
|
}, "useFactory"),
|
|
3326
3318
|
inject: options.inject || []
|
|
@@ -3367,7 +3359,7 @@ export {
|
|
|
3367
3359
|
CsrfGuard,
|
|
3368
3360
|
DEFAULT_CORRELATION_HEADER,
|
|
3369
3361
|
DatabaseModule,
|
|
3370
|
-
|
|
3362
|
+
ForbiddenException,
|
|
3371
3363
|
GoneException,
|
|
3372
3364
|
HttpExceptionFilter,
|
|
3373
3365
|
HttpLoggerInterceptor,
|
|
@@ -3375,7 +3367,7 @@ export {
|
|
|
3375
3367
|
InternalServerErrorException3 as InternalServerErrorException,
|
|
3376
3368
|
LOGGER_MODULE_OPTIONS,
|
|
3377
3369
|
LoggerModule,
|
|
3378
|
-
|
|
3370
|
+
LoggerService,
|
|
3379
3371
|
MethodNotAllowedException,
|
|
3380
3372
|
NotAcceptableException,
|
|
3381
3373
|
NotFoundException,
|