@xfilecom/backend-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.module.d.ts +40 -0
- package/dist/core.module.js +195 -0
- package/dist/core.module.js.map +1 -0
- package/dist/database/database.constants.d.ts +2 -0
- package/dist/database/database.constants.js +6 -0
- package/dist/database/database.constants.js.map +1 -0
- package/dist/database/database.module.d.ts +19 -0
- package/dist/database/database.module.js +56 -0
- package/dist/database/database.module.js.map +1 -0
- package/dist/database/database.query.d.ts +103 -0
- package/dist/database/database.query.js +369 -0
- package/dist/database/database.query.js.map +1 -0
- package/dist/database/database.service.d.ts +18 -0
- package/dist/database/database.service.js +110 -0
- package/dist/database/database.service.js.map +1 -0
- package/dist/decorators/public.decorator.d.ts +2 -0
- package/dist/decorators/public.decorator.js +8 -0
- package/dist/decorators/public.decorator.js.map +1 -0
- package/dist/decorators/roles.decorator.d.ts +2 -0
- package/dist/decorators/roles.decorator.js +8 -0
- package/dist/decorators/roles.decorator.js.map +1 -0
- package/dist/decorators/user.decorator.d.ts +7 -0
- package/dist/decorators/user.decorator.js +10 -0
- package/dist/decorators/user.decorator.js.map +1 -0
- package/dist/filters/exception.filter.d.ts +36 -0
- package/dist/filters/exception.filter.js +201 -0
- package/dist/filters/exception.filter.js.map +1 -0
- package/dist/filters/i18n-exception.filter.d.ts +18 -0
- package/dist/filters/i18n-exception.filter.js +227 -0
- package/dist/filters/i18n-exception.filter.js.map +1 -0
- package/dist/filters/microservice-gateway-exception.filter.d.ts +4 -0
- package/dist/filters/microservice-gateway-exception.filter.js +64 -0
- package/dist/filters/microservice-gateway-exception.filter.js.map +1 -0
- package/dist/filters/rpc-response-exception.filter.d.ts +6 -0
- package/dist/filters/rpc-response-exception.filter.js +24 -0
- package/dist/filters/rpc-response-exception.filter.js.map +1 -0
- package/dist/guards/jwt-auth.guard.d.ts +14 -0
- package/dist/guards/jwt-auth.guard.js +103 -0
- package/dist/guards/jwt-auth.guard.js.map +1 -0
- package/dist/guards/roles.guard.d.ts +7 -0
- package/dist/guards/roles.guard.js +47 -0
- package/dist/guards/roles.guard.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/database-check.interceptor.d.ts +12 -0
- package/dist/interceptors/database-check.interceptor.js +60 -0
- package/dist/interceptors/database-check.interceptor.js.map +1 -0
- package/dist/interceptors/error-handling.interceptor.d.ts +8 -0
- package/dist/interceptors/error-handling.interceptor.js +33 -0
- package/dist/interceptors/error-handling.interceptor.js.map +1 -0
- package/dist/interceptors/logging.interceptor.d.ts +22 -0
- package/dist/interceptors/logging.interceptor.js +178 -0
- package/dist/interceptors/logging.interceptor.js.map +1 -0
- package/dist/interceptors/response-transform.interceptor.d.ts +5 -0
- package/dist/interceptors/response-transform.interceptor.js +32 -0
- package/dist/interceptors/response-transform.interceptor.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/auth-lookup.utils.d.ts +23 -0
- package/dist/utils/auth-lookup.utils.js +61 -0
- package/dist/utils/auth-lookup.utils.js.map +1 -0
- package/dist/utils/auth.helpers.d.ts +19 -0
- package/dist/utils/auth.helpers.js +77 -0
- package/dist/utils/auth.helpers.js.map +1 -0
- package/dist/utils/config-loader.utils.d.ts +22 -0
- package/dist/utils/config-loader.utils.js +77 -0
- package/dist/utils/config-loader.utils.js.map +1 -0
- package/dist/utils/config-secret.utils.d.ts +9 -0
- package/dist/utils/config-secret.utils.js +26 -0
- package/dist/utils/config-secret.utils.js.map +1 -0
- package/dist/utils/config.validator.d.ts +13 -0
- package/dist/utils/config.validator.js +82 -0
- package/dist/utils/config.validator.js.map +1 -0
- package/dist/utils/controller.helpers.d.ts +59 -0
- package/dist/utils/controller.helpers.js +117 -0
- package/dist/utils/controller.helpers.js.map +1 -0
- package/dist/utils/crypto.utils.d.ts +12 -0
- package/dist/utils/crypto.utils.js +53 -0
- package/dist/utils/crypto.utils.js.map +1 -0
- package/dist/utils/env.utils.d.ts +8 -0
- package/dist/utils/env.utils.js +27 -0
- package/dist/utils/env.utils.js.map +1 -0
- package/dist/utils/error.utils.d.ts +7 -0
- package/dist/utils/error.utils.js +72 -0
- package/dist/utils/error.utils.js.map +1 -0
- package/dist/utils/hash-verification.utils.d.ts +35 -0
- package/dist/utils/hash-verification.utils.js +133 -0
- package/dist/utils/hash-verification.utils.js.map +1 -0
- package/dist/utils/logger.helpers.d.ts +71 -0
- package/dist/utils/logger.helpers.js +293 -0
- package/dist/utils/logger.helpers.js.map +1 -0
- package/dist/utils/logging.config.d.ts +6 -0
- package/dist/utils/logging.config.js +42 -0
- package/dist/utils/logging.config.js.map +1 -0
- package/dist/utils/rpc-exception.utils.d.ts +7 -0
- package/dist/utils/rpc-exception.utils.js +53 -0
- package/dist/utils/rpc-exception.utils.js.map +1 -0
- package/dist/utils/service.helpers.d.ts +22 -0
- package/dist/utils/service.helpers.js +73 -0
- package/dist/utils/service.helpers.js.map +1 -0
- package/dist/utils/yaml-config.loader.d.ts +15 -0
- package/dist/utils/yaml-config.loader.js +219 -0
- package/dist/utils/yaml-config.loader.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var JwtAuthGuard_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.JwtAuthGuard = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const core_1 = require("@nestjs/core");
|
|
16
|
+
const public_decorator_1 = require("../decorators/public.decorator");
|
|
17
|
+
let JwtAuthGuard = JwtAuthGuard_1 = class JwtAuthGuard {
|
|
18
|
+
constructor(reflector) {
|
|
19
|
+
this.reflector = reflector;
|
|
20
|
+
this.logger = new common_1.Logger(JwtAuthGuard_1.name);
|
|
21
|
+
this.passportJwtStrategy = null;
|
|
22
|
+
this.loadPassportJwtStrategy();
|
|
23
|
+
}
|
|
24
|
+
loadPassportJwtStrategy() {
|
|
25
|
+
try {
|
|
26
|
+
const passportJwt = require('passport-jwt');
|
|
27
|
+
this.passportJwtStrategy = passportJwt.Strategy;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
this.logger.warn('passport-jwt not found. JWT authentication will be skipped. ' +
|
|
31
|
+
'Install passport-jwt and @nestjs/passport to enable JWT authentication.');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
canActivate(context) {
|
|
35
|
+
const isPublic = this.reflector.getAllAndOverride(public_decorator_1.IS_PUBLIC_KEY, [
|
|
36
|
+
context.getHandler(),
|
|
37
|
+
context.getClass(),
|
|
38
|
+
]);
|
|
39
|
+
if (isPublic) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (!this.passportJwtStrategy) {
|
|
43
|
+
this.logger.warn('JWT authentication is not configured. Endpoint is accessible without authentication. ' +
|
|
44
|
+
'This should not happen in production.');
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (this.isHttpContext(context)) {
|
|
48
|
+
return this.validateHttpRequest(context);
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
isHttpContext(context) {
|
|
53
|
+
return context.getType() === 'http';
|
|
54
|
+
}
|
|
55
|
+
async validateHttpRequest(context) {
|
|
56
|
+
const request = context.switchToHttp().getRequest();
|
|
57
|
+
const token = this.extractTokenFromHeader(request);
|
|
58
|
+
if (!token) {
|
|
59
|
+
throw new common_1.UnauthorizedException('No token provided');
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const jwtSecret = process.env.JWT_SECRET;
|
|
63
|
+
if (!jwtSecret) {
|
|
64
|
+
this.logger.warn('JWT_SECRET is not set. JWT validation will fail. ' +
|
|
65
|
+
'Set JWT_SECRET environment variable to enable JWT authentication.');
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const jwt = require('jsonwebtoken');
|
|
69
|
+
const decoded = jwt.verify(token, jwtSecret);
|
|
70
|
+
request.user = decoded;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error.name === 'JsonWebTokenError') {
|
|
75
|
+
throw new common_1.UnauthorizedException('Invalid token');
|
|
76
|
+
}
|
|
77
|
+
if (error.name === 'TokenExpiredError') {
|
|
78
|
+
throw new common_1.UnauthorizedException('Token expired');
|
|
79
|
+
}
|
|
80
|
+
throw new common_1.UnauthorizedException('Token validation failed');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
extractTokenFromHeader(request) {
|
|
84
|
+
const authHeader = request.headers?.authorization;
|
|
85
|
+
if (!authHeader) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const [type, token] = authHeader.split(' ') ?? [];
|
|
89
|
+
return type === 'Bearer' ? token : null;
|
|
90
|
+
}
|
|
91
|
+
handleRequest(err, user, info) {
|
|
92
|
+
if (err || !user) {
|
|
93
|
+
throw err || new common_1.UnauthorizedException('Invalid or expired token');
|
|
94
|
+
}
|
|
95
|
+
return user;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
99
|
+
exports.JwtAuthGuard = JwtAuthGuard = JwtAuthGuard_1 = __decorate([
|
|
100
|
+
(0, common_1.Injectable)(),
|
|
101
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
102
|
+
], JwtAuthGuard);
|
|
103
|
+
//# sourceMappingURL=jwt-auth.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../src/guards/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,qEAA+D;AAWxD,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAIvB,YACU,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QAJb,WAAM,GAAG,IAAI,eAAM,CAAC,cAAY,CAAC,IAAI,CAAC,CAAC;QAChD,wBAAmB,GAAQ,IAAI,CAAC;QAMtC,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAKO,uBAAuB;QAC7B,IAAI,CAAC;YAEH,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;YAC5C,IAAI,CAAC,mBAAmB,GAAG,WAAW,CAAC,QAAQ,CAAC;QAClD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,8DAA8D;gBAC9D,yEAAyE,CAC1E,CAAC;QACJ,CAAC;IACH,CAAC;IAKD,WAAW,CAAC,OAAyB;QAEnC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,gCAAa,EAAE;YACxE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAGD,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,CAA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AI,KAAK,mBAAmB,EAAE,CAAC;gBACvC,MAAM,IAAI,8BAAqB,CAAC,eAAe,CAAC,CAAC;YACnD,CAAC;YACD,MAAM,IAAI,8BAAqB,CAAC,yBAAyB,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAKO,sBAAsB,CAAC,OAAY;QACzC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC;QAClD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAClD,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1C,CAAC;IAKD,aAAa,CAAC,GAAQ,EAAE,IAAS,EAAE,IAAS;QAC1C,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,GAAG,IAAI,IAAI,8BAAqB,CAAC,0BAA0B,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAjIY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAMU,gBAAS;GALnB,YAAY,CAiIxB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
export declare class RolesGuard implements CanActivate {
|
|
4
|
+
private reflector;
|
|
5
|
+
constructor(reflector: Reflector);
|
|
6
|
+
canActivate(context: ExecutionContext): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RolesGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const roles_decorator_1 = require("../decorators/roles.decorator");
|
|
16
|
+
const ROLE_KEY = 'role';
|
|
17
|
+
let RolesGuard = class RolesGuard {
|
|
18
|
+
constructor(reflector) {
|
|
19
|
+
this.reflector = reflector;
|
|
20
|
+
}
|
|
21
|
+
canActivate(context) {
|
|
22
|
+
const requiredRoles = this.reflector.getAllAndOverride(roles_decorator_1.ROLES_KEY, [
|
|
23
|
+
context.getHandler(),
|
|
24
|
+
context.getClass(),
|
|
25
|
+
]);
|
|
26
|
+
if (!requiredRoles?.length) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
const request = context.switchToHttp().getRequest();
|
|
30
|
+
const user = request?.user;
|
|
31
|
+
const userRole = user?.[ROLE_KEY];
|
|
32
|
+
if (userRole == null) {
|
|
33
|
+
throw new common_1.ForbiddenException('User role not found');
|
|
34
|
+
}
|
|
35
|
+
const allowed = requiredRoles.some((r) => String(r) === String(userRole));
|
|
36
|
+
if (!allowed) {
|
|
37
|
+
throw new common_1.ForbiddenException(`Required role(s): ${requiredRoles.join(', ')}. Current: ${userRole}`);
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.RolesGuard = RolesGuard;
|
|
43
|
+
exports.RolesGuard = RolesGuard = __decorate([
|
|
44
|
+
(0, common_1.Injectable)(),
|
|
45
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
46
|
+
], RolesGuard);
|
|
47
|
+
//# sourceMappingURL=roles.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.guard.js","sourceRoot":"","sources":["../../src/guards/roles.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AACzC,mEAA0D;AAG1D,MAAM,QAAQ,GAAG,MAAM,CAAC;AAmBjB,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C,WAAW,CAAC,OAAyB;QACnC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAW,2BAAS,EAAE;YAC1E,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;QAC3B,MAAM,QAAQ,GAAG,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC;QAElC,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,2BAAkB,CAAC,qBAAqB,CAAC,CAAC;QACtD,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,2BAAkB,CAC1B,qBAAqB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,QAAQ,EAAE,CACtE,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA9BY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;qCAEoB,gBAAS;GAD7B,UAAU,CA8BtB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export * from './core.module';
|
|
2
|
+
export * from './database/database.module';
|
|
3
|
+
export * from './database/database.service';
|
|
4
|
+
export * from './database/database.query';
|
|
5
|
+
export * from './utils/controller.helpers';
|
|
6
|
+
export { CommonResponseDto, CommonErrorDto, PaginationMeta, ResponseMeta } from './utils/controller.helpers';
|
|
7
|
+
export * from './utils/service.helpers';
|
|
8
|
+
export * from './utils/error.utils';
|
|
9
|
+
export { toRpcPayload, exceptionToResponse, type RpcResponsePayload, } from './utils/rpc-exception.utils';
|
|
10
|
+
export * from './utils/auth.helpers';
|
|
11
|
+
export * from './utils/logger.helpers';
|
|
12
|
+
export { ILogWriter, ConsoleLogWriter, FileLogWriter, FileLogWriterOptions, LogLevelName, LOG_LEVEL_ORDER, isLevelEnabled, } from './utils/logger.helpers';
|
|
13
|
+
export * from './interceptors/logging.interceptor';
|
|
14
|
+
export { LoggingInterceptorOptions } from './interceptors/logging.interceptor';
|
|
15
|
+
export * from './interceptors/error-handling.interceptor';
|
|
16
|
+
export * from './interceptors/response-transform.interceptor';
|
|
17
|
+
export * from './interceptors/database-check.interceptor';
|
|
18
|
+
export * from './guards/jwt-auth.guard';
|
|
19
|
+
export * from './guards/roles.guard';
|
|
20
|
+
export { AllExceptionsFilter, ExceptionFilterOptions } from './filters/exception.filter';
|
|
21
|
+
export { I18nExceptionFilter, type I18nMessageShape, } from './filters/i18n-exception.filter';
|
|
22
|
+
export { MicroserviceGatewayExceptionFilter } from './filters/microservice-gateway-exception.filter';
|
|
23
|
+
export { RpcResponseExceptionFilter } from './filters/rpc-response-exception.filter';
|
|
24
|
+
export * from './decorators/public.decorator';
|
|
25
|
+
export { User, JwtUser } from './decorators/user.decorator';
|
|
26
|
+
export { Roles, ROLES_KEY } from './decorators/roles.decorator';
|
|
27
|
+
export * from './utils/config.validator';
|
|
28
|
+
export { getAppEnv, isDevelopment, isProduction, isStaging, currentAppEnv, isDev, isProd, type AppEnv, } from './utils/env.utils';
|
|
29
|
+
export { getLoggingConfigFromEnv } from './utils/logging.config';
|
|
30
|
+
export { loadApplicationYaml, loadApplicationYamlSync, LoadApplicationYamlOptions, DEFAULT_CONFIG_FILENAMES, ENV_CONFIG_FILENAME_PATTERN, CONFIG_SOURCE_ENV_KEY, type ConfigSource, } from './utils/yaml-config.loader';
|
|
31
|
+
export { resolveConfigRootDir, createConfigLoader, DEFAULT_CONFIG_ROOT_CANDIDATES, type ResolveConfigRootDirOptions, type CreateConfigLoaderOptions, type GetServiceConfigOverrides, } from './utils/config-loader.utils';
|
|
32
|
+
export { pbkdf2HashPassword, pbkdf2VerifyPassword, deriveKeySha256, PBKDF2_DEFAULT_ITERATIONS, PBKDF2_DEFAULT_KEYLEN, PBKDF2_DEFAULT_DIGEST, PBKDF2_SALT_BYTES, type Pbkdf2Options, } from './utils/crypto.utils';
|
|
33
|
+
export { hashValue, compareValue, hashEmail, compareEmail, emailNormalizer, digitsNormalizer, BUILT_IN_NORMALIZERS, getProfileConfig, hashByKey, compareByKey, lookupHash, compareLookupHash, HashVerificationConfig, HashVerificationConfigMap, type LookupHashOptions, } from './utils/hash-verification.utils';
|
|
34
|
+
export { getOptionalSecret, getEncryptionKey, type ConfigGetter, type GetOptionalSecretOptions, } from './utils/config-secret.utils';
|
|
35
|
+
export { findUserByLookupHash, authenticateWithHashLookup, type DrizzleDb, type FindUserByLookupHashOptions, type AuthenticateWithHashLookupOptions, } from './utils/auth-lookup.utils';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.compareLookupHash = exports.lookupHash = exports.compareByKey = exports.hashByKey = exports.getProfileConfig = exports.BUILT_IN_NORMALIZERS = exports.digitsNormalizer = exports.emailNormalizer = exports.compareEmail = exports.hashEmail = exports.compareValue = exports.hashValue = exports.PBKDF2_SALT_BYTES = exports.PBKDF2_DEFAULT_DIGEST = exports.PBKDF2_DEFAULT_KEYLEN = exports.PBKDF2_DEFAULT_ITERATIONS = exports.deriveKeySha256 = exports.pbkdf2VerifyPassword = exports.pbkdf2HashPassword = exports.DEFAULT_CONFIG_ROOT_CANDIDATES = exports.createConfigLoader = exports.resolveConfigRootDir = exports.CONFIG_SOURCE_ENV_KEY = exports.ENV_CONFIG_FILENAME_PATTERN = exports.DEFAULT_CONFIG_FILENAMES = exports.loadApplicationYamlSync = exports.loadApplicationYaml = exports.getLoggingConfigFromEnv = exports.isProd = exports.isDev = exports.currentAppEnv = exports.isStaging = exports.isProduction = exports.isDevelopment = exports.getAppEnv = exports.ROLES_KEY = exports.Roles = exports.User = exports.RpcResponseExceptionFilter = exports.MicroserviceGatewayExceptionFilter = exports.I18nExceptionFilter = exports.AllExceptionsFilter = exports.isLevelEnabled = exports.LOG_LEVEL_ORDER = exports.FileLogWriter = exports.ConsoleLogWriter = exports.exceptionToResponse = exports.toRpcPayload = exports.CommonErrorDto = exports.CommonResponseDto = void 0;
|
|
18
|
+
exports.authenticateWithHashLookup = exports.findUserByLookupHash = exports.getEncryptionKey = exports.getOptionalSecret = void 0;
|
|
19
|
+
__exportStar(require("./core.module"), exports);
|
|
20
|
+
__exportStar(require("./database/database.module"), exports);
|
|
21
|
+
__exportStar(require("./database/database.service"), exports);
|
|
22
|
+
__exportStar(require("./database/database.query"), exports);
|
|
23
|
+
__exportStar(require("./utils/controller.helpers"), exports);
|
|
24
|
+
var controller_helpers_1 = require("./utils/controller.helpers");
|
|
25
|
+
Object.defineProperty(exports, "CommonResponseDto", { enumerable: true, get: function () { return controller_helpers_1.CommonResponseDto; } });
|
|
26
|
+
Object.defineProperty(exports, "CommonErrorDto", { enumerable: true, get: function () { return controller_helpers_1.CommonErrorDto; } });
|
|
27
|
+
__exportStar(require("./utils/service.helpers"), exports);
|
|
28
|
+
__exportStar(require("./utils/error.utils"), exports);
|
|
29
|
+
var rpc_exception_utils_1 = require("./utils/rpc-exception.utils");
|
|
30
|
+
Object.defineProperty(exports, "toRpcPayload", { enumerable: true, get: function () { return rpc_exception_utils_1.toRpcPayload; } });
|
|
31
|
+
Object.defineProperty(exports, "exceptionToResponse", { enumerable: true, get: function () { return rpc_exception_utils_1.exceptionToResponse; } });
|
|
32
|
+
__exportStar(require("./utils/auth.helpers"), exports);
|
|
33
|
+
__exportStar(require("./utils/logger.helpers"), exports);
|
|
34
|
+
var logger_helpers_1 = require("./utils/logger.helpers");
|
|
35
|
+
Object.defineProperty(exports, "ConsoleLogWriter", { enumerable: true, get: function () { return logger_helpers_1.ConsoleLogWriter; } });
|
|
36
|
+
Object.defineProperty(exports, "FileLogWriter", { enumerable: true, get: function () { return logger_helpers_1.FileLogWriter; } });
|
|
37
|
+
Object.defineProperty(exports, "LOG_LEVEL_ORDER", { enumerable: true, get: function () { return logger_helpers_1.LOG_LEVEL_ORDER; } });
|
|
38
|
+
Object.defineProperty(exports, "isLevelEnabled", { enumerable: true, get: function () { return logger_helpers_1.isLevelEnabled; } });
|
|
39
|
+
__exportStar(require("./interceptors/logging.interceptor"), exports);
|
|
40
|
+
__exportStar(require("./interceptors/error-handling.interceptor"), exports);
|
|
41
|
+
__exportStar(require("./interceptors/response-transform.interceptor"), exports);
|
|
42
|
+
__exportStar(require("./interceptors/database-check.interceptor"), exports);
|
|
43
|
+
__exportStar(require("./guards/jwt-auth.guard"), exports);
|
|
44
|
+
__exportStar(require("./guards/roles.guard"), exports);
|
|
45
|
+
var exception_filter_1 = require("./filters/exception.filter");
|
|
46
|
+
Object.defineProperty(exports, "AllExceptionsFilter", { enumerable: true, get: function () { return exception_filter_1.AllExceptionsFilter; } });
|
|
47
|
+
var i18n_exception_filter_1 = require("./filters/i18n-exception.filter");
|
|
48
|
+
Object.defineProperty(exports, "I18nExceptionFilter", { enumerable: true, get: function () { return i18n_exception_filter_1.I18nExceptionFilter; } });
|
|
49
|
+
var microservice_gateway_exception_filter_1 = require("./filters/microservice-gateway-exception.filter");
|
|
50
|
+
Object.defineProperty(exports, "MicroserviceGatewayExceptionFilter", { enumerable: true, get: function () { return microservice_gateway_exception_filter_1.MicroserviceGatewayExceptionFilter; } });
|
|
51
|
+
var rpc_response_exception_filter_1 = require("./filters/rpc-response-exception.filter");
|
|
52
|
+
Object.defineProperty(exports, "RpcResponseExceptionFilter", { enumerable: true, get: function () { return rpc_response_exception_filter_1.RpcResponseExceptionFilter; } });
|
|
53
|
+
__exportStar(require("./decorators/public.decorator"), exports);
|
|
54
|
+
var user_decorator_1 = require("./decorators/user.decorator");
|
|
55
|
+
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_decorator_1.User; } });
|
|
56
|
+
var roles_decorator_1 = require("./decorators/roles.decorator");
|
|
57
|
+
Object.defineProperty(exports, "Roles", { enumerable: true, get: function () { return roles_decorator_1.Roles; } });
|
|
58
|
+
Object.defineProperty(exports, "ROLES_KEY", { enumerable: true, get: function () { return roles_decorator_1.ROLES_KEY; } });
|
|
59
|
+
__exportStar(require("./utils/config.validator"), exports);
|
|
60
|
+
var env_utils_1 = require("./utils/env.utils");
|
|
61
|
+
Object.defineProperty(exports, "getAppEnv", { enumerable: true, get: function () { return env_utils_1.getAppEnv; } });
|
|
62
|
+
Object.defineProperty(exports, "isDevelopment", { enumerable: true, get: function () { return env_utils_1.isDevelopment; } });
|
|
63
|
+
Object.defineProperty(exports, "isProduction", { enumerable: true, get: function () { return env_utils_1.isProduction; } });
|
|
64
|
+
Object.defineProperty(exports, "isStaging", { enumerable: true, get: function () { return env_utils_1.isStaging; } });
|
|
65
|
+
Object.defineProperty(exports, "currentAppEnv", { enumerable: true, get: function () { return env_utils_1.currentAppEnv; } });
|
|
66
|
+
Object.defineProperty(exports, "isDev", { enumerable: true, get: function () { return env_utils_1.isDev; } });
|
|
67
|
+
Object.defineProperty(exports, "isProd", { enumerable: true, get: function () { return env_utils_1.isProd; } });
|
|
68
|
+
var logging_config_1 = require("./utils/logging.config");
|
|
69
|
+
Object.defineProperty(exports, "getLoggingConfigFromEnv", { enumerable: true, get: function () { return logging_config_1.getLoggingConfigFromEnv; } });
|
|
70
|
+
var yaml_config_loader_1 = require("./utils/yaml-config.loader");
|
|
71
|
+
Object.defineProperty(exports, "loadApplicationYaml", { enumerable: true, get: function () { return yaml_config_loader_1.loadApplicationYaml; } });
|
|
72
|
+
Object.defineProperty(exports, "loadApplicationYamlSync", { enumerable: true, get: function () { return yaml_config_loader_1.loadApplicationYamlSync; } });
|
|
73
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG_FILENAMES", { enumerable: true, get: function () { return yaml_config_loader_1.DEFAULT_CONFIG_FILENAMES; } });
|
|
74
|
+
Object.defineProperty(exports, "ENV_CONFIG_FILENAME_PATTERN", { enumerable: true, get: function () { return yaml_config_loader_1.ENV_CONFIG_FILENAME_PATTERN; } });
|
|
75
|
+
Object.defineProperty(exports, "CONFIG_SOURCE_ENV_KEY", { enumerable: true, get: function () { return yaml_config_loader_1.CONFIG_SOURCE_ENV_KEY; } });
|
|
76
|
+
var config_loader_utils_1 = require("./utils/config-loader.utils");
|
|
77
|
+
Object.defineProperty(exports, "resolveConfigRootDir", { enumerable: true, get: function () { return config_loader_utils_1.resolveConfigRootDir; } });
|
|
78
|
+
Object.defineProperty(exports, "createConfigLoader", { enumerable: true, get: function () { return config_loader_utils_1.createConfigLoader; } });
|
|
79
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG_ROOT_CANDIDATES", { enumerable: true, get: function () { return config_loader_utils_1.DEFAULT_CONFIG_ROOT_CANDIDATES; } });
|
|
80
|
+
var crypto_utils_1 = require("./utils/crypto.utils");
|
|
81
|
+
Object.defineProperty(exports, "pbkdf2HashPassword", { enumerable: true, get: function () { return crypto_utils_1.pbkdf2HashPassword; } });
|
|
82
|
+
Object.defineProperty(exports, "pbkdf2VerifyPassword", { enumerable: true, get: function () { return crypto_utils_1.pbkdf2VerifyPassword; } });
|
|
83
|
+
Object.defineProperty(exports, "deriveKeySha256", { enumerable: true, get: function () { return crypto_utils_1.deriveKeySha256; } });
|
|
84
|
+
Object.defineProperty(exports, "PBKDF2_DEFAULT_ITERATIONS", { enumerable: true, get: function () { return crypto_utils_1.PBKDF2_DEFAULT_ITERATIONS; } });
|
|
85
|
+
Object.defineProperty(exports, "PBKDF2_DEFAULT_KEYLEN", { enumerable: true, get: function () { return crypto_utils_1.PBKDF2_DEFAULT_KEYLEN; } });
|
|
86
|
+
Object.defineProperty(exports, "PBKDF2_DEFAULT_DIGEST", { enumerable: true, get: function () { return crypto_utils_1.PBKDF2_DEFAULT_DIGEST; } });
|
|
87
|
+
Object.defineProperty(exports, "PBKDF2_SALT_BYTES", { enumerable: true, get: function () { return crypto_utils_1.PBKDF2_SALT_BYTES; } });
|
|
88
|
+
var hash_verification_utils_1 = require("./utils/hash-verification.utils");
|
|
89
|
+
Object.defineProperty(exports, "hashValue", { enumerable: true, get: function () { return hash_verification_utils_1.hashValue; } });
|
|
90
|
+
Object.defineProperty(exports, "compareValue", { enumerable: true, get: function () { return hash_verification_utils_1.compareValue; } });
|
|
91
|
+
Object.defineProperty(exports, "hashEmail", { enumerable: true, get: function () { return hash_verification_utils_1.hashEmail; } });
|
|
92
|
+
Object.defineProperty(exports, "compareEmail", { enumerable: true, get: function () { return hash_verification_utils_1.compareEmail; } });
|
|
93
|
+
Object.defineProperty(exports, "emailNormalizer", { enumerable: true, get: function () { return hash_verification_utils_1.emailNormalizer; } });
|
|
94
|
+
Object.defineProperty(exports, "digitsNormalizer", { enumerable: true, get: function () { return hash_verification_utils_1.digitsNormalizer; } });
|
|
95
|
+
Object.defineProperty(exports, "BUILT_IN_NORMALIZERS", { enumerable: true, get: function () { return hash_verification_utils_1.BUILT_IN_NORMALIZERS; } });
|
|
96
|
+
Object.defineProperty(exports, "getProfileConfig", { enumerable: true, get: function () { return hash_verification_utils_1.getProfileConfig; } });
|
|
97
|
+
Object.defineProperty(exports, "hashByKey", { enumerable: true, get: function () { return hash_verification_utils_1.hashByKey; } });
|
|
98
|
+
Object.defineProperty(exports, "compareByKey", { enumerable: true, get: function () { return hash_verification_utils_1.compareByKey; } });
|
|
99
|
+
Object.defineProperty(exports, "lookupHash", { enumerable: true, get: function () { return hash_verification_utils_1.lookupHash; } });
|
|
100
|
+
Object.defineProperty(exports, "compareLookupHash", { enumerable: true, get: function () { return hash_verification_utils_1.compareLookupHash; } });
|
|
101
|
+
var config_secret_utils_1 = require("./utils/config-secret.utils");
|
|
102
|
+
Object.defineProperty(exports, "getOptionalSecret", { enumerable: true, get: function () { return config_secret_utils_1.getOptionalSecret; } });
|
|
103
|
+
Object.defineProperty(exports, "getEncryptionKey", { enumerable: true, get: function () { return config_secret_utils_1.getEncryptionKey; } });
|
|
104
|
+
var auth_lookup_utils_1 = require("./utils/auth-lookup.utils");
|
|
105
|
+
Object.defineProperty(exports, "findUserByLookupHash", { enumerable: true, get: function () { return auth_lookup_utils_1.findUserByLookupHash; } });
|
|
106
|
+
Object.defineProperty(exports, "authenticateWithHashLookup", { enumerable: true, get: function () { return auth_lookup_utils_1.authenticateWithHashLookup; } });
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,gDAA8B;AAG9B,6DAA2C;AAC3C,8DAA4C;AAC5C,4DAA0C;AAG1C,6DAA2C;AAC3C,iEAKoC;AAJlC,uHAAA,iBAAiB,OAAA;AACjB,oHAAA,cAAc,OAAA;AAIhB,0DAAwC;AACxC,sDAAoC;AACpC,mEAIqC;AAHnC,mHAAA,YAAY,OAAA;AACZ,0HAAA,mBAAmB,OAAA;AAGrB,uDAAqC;AACrC,yDAAuC;AACvC,yDAQgC;AAN9B,kHAAA,gBAAgB,OAAA;AAChB,+GAAA,aAAa,OAAA;AAGb,iHAAA,eAAe,OAAA;AACf,gHAAA,cAAc,OAAA;AAIhB,qEAAmD;AAEnD,4EAA0D;AAC1D,gFAA8D;AAC9D,4EAA0D;AAG1D,0DAAwC;AACxC,uDAAqC;AAGrC,+DAAyF;AAAhF,uHAAA,mBAAmB,OAAA;AAC5B,yEAGyC;AAFvC,4HAAA,mBAAmB,OAAA;AAGrB,yGAAqG;AAA5F,2JAAA,kCAAkC,OAAA;AAC3C,yFAAqF;AAA5E,2IAAA,0BAA0B,OAAA;AAGnC,gEAA8C;AAC9C,8DAA4D;AAAnD,sGAAA,IAAI,OAAA;AACb,gEAAgE;AAAvD,wGAAA,KAAK,OAAA;AAAE,4GAAA,SAAS,OAAA;AAGzB,2DAAyC;AAGzC,+CAS2B;AARzB,sGAAA,SAAS,OA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js/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { DatabaseService } from '../database/database.service';
|
|
5
|
+
export declare class DatabaseCheckInterceptor implements NestInterceptor {
|
|
6
|
+
private readonly databaseService?;
|
|
7
|
+
private readonly reflector;
|
|
8
|
+
constructor(databaseService?: DatabaseService, reflector?: Reflector);
|
|
9
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
10
|
+
private checkDatabase;
|
|
11
|
+
private isPublicEndpoint;
|
|
12
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DatabaseCheckInterceptor = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const core_1 = require("@nestjs/core");
|
|
18
|
+
const database_service_1 = require("../database/database.service");
|
|
19
|
+
const public_decorator_1 = require("../decorators/public.decorator");
|
|
20
|
+
let DatabaseCheckInterceptor = class DatabaseCheckInterceptor {
|
|
21
|
+
constructor(databaseService, reflector = new core_1.Reflector()) {
|
|
22
|
+
this.databaseService = databaseService;
|
|
23
|
+
this.reflector = reflector;
|
|
24
|
+
}
|
|
25
|
+
intercept(context, next) {
|
|
26
|
+
const isPublic = this.isPublicEndpoint(context);
|
|
27
|
+
if (isPublic) {
|
|
28
|
+
return next.handle();
|
|
29
|
+
}
|
|
30
|
+
const contextType = context.getType();
|
|
31
|
+
if (contextType === 'rpc') {
|
|
32
|
+
return next.handle();
|
|
33
|
+
}
|
|
34
|
+
return this.checkDatabase(context, next);
|
|
35
|
+
}
|
|
36
|
+
checkDatabase(context, next) {
|
|
37
|
+
if (this.databaseService && !this.databaseService.isConnected()) {
|
|
38
|
+
throw new common_1.ServiceUnavailableException({
|
|
39
|
+
error: 'Database connection not available',
|
|
40
|
+
code: 'DB_NOT_CONNECTED',
|
|
41
|
+
message: 'The database service is currently unavailable. Please try again later.',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return next.handle();
|
|
45
|
+
}
|
|
46
|
+
isPublicEndpoint(context) {
|
|
47
|
+
return this.reflector.getAllAndOverride(public_decorator_1.IS_PUBLIC_KEY, [
|
|
48
|
+
context.getHandler(),
|
|
49
|
+
context.getClass(),
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.DatabaseCheckInterceptor = DatabaseCheckInterceptor;
|
|
54
|
+
exports.DatabaseCheckInterceptor = DatabaseCheckInterceptor = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__param(0, (0, common_1.Optional)()),
|
|
57
|
+
__metadata("design:paramtypes", [database_service_1.DatabaseService,
|
|
58
|
+
core_1.Reflector])
|
|
59
|
+
], DatabaseCheckInterceptor);
|
|
60
|
+
//# sourceMappingURL=database-check.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-check.interceptor.js","sourceRoot":"","sources":["../../src/interceptors/database-check.interceptor.ts"],"names":[],"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BAAwB;IADpC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCAAoC,kCAAe;QAClC,gBAAS;GAH5B,wBAAwB,CAsDpC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ErrorUtils } from '../utils/error.utils';
|
|
4
|
+
export declare class ErrorHandlingInterceptor implements NestInterceptor {
|
|
5
|
+
private readonly errorUtils;
|
|
6
|
+
constructor(errorUtils: ErrorUtils);
|
|
7
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ErrorHandlingInterceptor = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const rxjs_1 = require("rxjs");
|
|
15
|
+
const operators_1 = require("rxjs/operators");
|
|
16
|
+
const error_utils_1 = require("../utils/error.utils");
|
|
17
|
+
let ErrorHandlingInterceptor = class ErrorHandlingInterceptor {
|
|
18
|
+
constructor(errorUtils) {
|
|
19
|
+
this.errorUtils = errorUtils;
|
|
20
|
+
}
|
|
21
|
+
intercept(context, next) {
|
|
22
|
+
return next.handle().pipe((0, operators_1.catchError)((error) => {
|
|
23
|
+
const errorDto = this.errorUtils.fromException(error);
|
|
24
|
+
return (0, rxjs_1.throwError)(() => errorDto);
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.ErrorHandlingInterceptor = ErrorHandlingInterceptor;
|
|
29
|
+
exports.ErrorHandlingInterceptor = ErrorHandlingInterceptor = __decorate([
|
|
30
|
+
(0, common_1.Injectable)(),
|
|
31
|
+
__metadata("design:paramtypes", [error_utils_1.ErrorUtils])
|
|
32
|
+
], ErrorHandlingInterceptor);
|
|
33
|
+
//# sourceMappingURL=error-handling.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling.interceptor.js","sourceRoot":"","sources":["../../src/interceptors/error-handling.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,+BAA8C;AAC9C,8CAA4C;AAC5C,sDAAkD;AAG3C,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACnC,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEvD,SAAS,CAAC,OAAyB,EAAE,IAAiB;QACpD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,sBAAU,EAAC,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACtD,OAAO,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AAXY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAE8B,wBAAU;GADxC,wBAAwB,CAWpC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { LogLevelName, LoggerHelpers } from '../utils/logger.helpers';
|
|
4
|
+
export interface LoggingInterceptorOptions {
|
|
5
|
+
logLevel?: 'none' | LogLevelName;
|
|
6
|
+
logRequestBody?: boolean;
|
|
7
|
+
logResponseBody?: boolean;
|
|
8
|
+
logRpcResponseBody?: boolean;
|
|
9
|
+
excludeFields?: string[];
|
|
10
|
+
maxBodyLength?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class LoggingInterceptor implements NestInterceptor {
|
|
13
|
+
private readonly logger;
|
|
14
|
+
private readonly options;
|
|
15
|
+
constructor(logger?: LoggerHelpers, options?: LoggingInterceptorOptions);
|
|
16
|
+
private shouldLog;
|
|
17
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
18
|
+
private sanitizeData;
|
|
19
|
+
private formatBody;
|
|
20
|
+
private logHttpRequest;
|
|
21
|
+
private logRpcRequest;
|
|
22
|
+
}
|