@smartsoft001/nestjs 1.1.91 → 2.61.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.
Files changed (62) hide show
  1. package/.eslintrc.json +30 -0
  2. package/README.md +345 -4
  3. package/jest.config.ts +10 -0
  4. package/package.json +12 -46
  5. package/project.json +37 -0
  6. package/src/{index.d.ts → index.ts} +3 -3
  7. package/src/lib/auth/{index.d.ts → index.ts} +1 -0
  8. package/src/lib/auth/jwt.strategy.ts +24 -0
  9. package/src/lib/auth/permission.service.spec.ts +61 -0
  10. package/src/lib/auth/permission.service.ts +34 -0
  11. package/src/lib/decorators/user/user.decorator.ts +26 -0
  12. package/src/lib/filters/execution/exception.filter.ts +89 -0
  13. package/src/lib/filters/execution/execution.filter.spec.ts +107 -0
  14. package/src/lib/filters/index.ts +1 -0
  15. package/src/lib/shared.config.ts +21 -0
  16. package/src/lib/shared.module.ts +55 -0
  17. package/tsconfig.json +22 -0
  18. package/tsconfig.lib.json +10 -0
  19. package/tsconfig.spec.json +15 -0
  20. package/src/index.js +0 -9
  21. package/src/index.js.map +0 -1
  22. package/src/lib/auth/index.js +0 -5
  23. package/src/lib/auth/index.js.map +0 -1
  24. package/src/lib/auth/jwt.strategy.d.ts +0 -8
  25. package/src/lib/auth/jwt.strategy.js +0 -30
  26. package/src/lib/auth/jwt.strategy.js.map +0 -1
  27. package/src/lib/auth/permission.service.d.ts +0 -7
  28. package/src/lib/auth/permission.service.js +0 -28
  29. package/src/lib/auth/permission.service.js.map +0 -1
  30. package/src/lib/controllers/health/health.controller.d.ts +0 -10
  31. package/src/lib/controllers/health/health.controller.js +0 -37
  32. package/src/lib/controllers/health/health.controller.js.map +0 -1
  33. package/src/lib/controllers/index.d.ts +0 -2
  34. package/src/lib/controllers/index.js +0 -8
  35. package/src/lib/controllers/index.js.map +0 -1
  36. package/src/lib/decorators/index.js +0 -5
  37. package/src/lib/decorators/index.js.map +0 -1
  38. package/src/lib/decorators/user/user.decorator.d.ts +0 -1
  39. package/src/lib/decorators/user/user.decorator.js +0 -9
  40. package/src/lib/decorators/user/user.decorator.js.map +0 -1
  41. package/src/lib/filters/exception/exception.filter.d.ts +0 -4
  42. package/src/lib/filters/exception/exception.filter.js +0 -49
  43. package/src/lib/filters/exception/exception.filter.js.map +0 -1
  44. package/src/lib/filters/index.d.ts +0 -1
  45. package/src/lib/filters/index.js +0 -5
  46. package/src/lib/filters/index.js.map +0 -1
  47. package/src/lib/services/health-db/health-db.service.d.ts +0 -7
  48. package/src/lib/services/health-db/health-db.service.js +0 -39
  49. package/src/lib/services/health-db/health-db.service.js.map +0 -1
  50. package/src/lib/services/index.d.ts +0 -3
  51. package/src/lib/services/index.js +0 -10
  52. package/src/lib/services/index.js.map +0 -1
  53. package/src/lib/shared.config.d.ts +0 -15
  54. package/src/lib/shared.config.js +0 -11
  55. package/src/lib/shared.config.js.map +0 -1
  56. package/src/lib/shared.module.d.ts +0 -14
  57. package/src/lib/shared.module.js +0 -49
  58. package/src/lib/shared.module.js.map +0 -1
  59. package/test-setup.d.ts +0 -0
  60. package/test-setup.js +0 -1
  61. package/test-setup.js.map +0 -1
  62. /package/src/lib/decorators/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,89 @@
1
+ import {
2
+ ArgumentsHost,
3
+ Catch,
4
+ ExceptionFilter,
5
+ HttpException,
6
+ HttpStatus,
7
+ Logger,
8
+ } from '@nestjs/common';
9
+ import {
10
+ DomainForbiddenError,
11
+ DomainValidationError,
12
+ } from '@smartsoft001/domain-core';
13
+
14
+ /**
15
+ * Exception filter to handle and format exceptions thrown by the application.
16
+ *
17
+ * @class
18
+ * @implements {ExceptionFilter}
19
+ * @throws {HttpException} If the exception is an instance of HttpException.
20
+ * @throws {DomainValidationError} If the exception is of type DomainValidationError.
21
+ * @throws {DomainForbiddenError} If the exception is of type DomainForbiddenError.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { Module } from '@nestjs/common';
26
+ * import { APP_FILTER } from '@nestjs/core';
27
+ *
28
+ * import { AppExceptionFilter } from '@smartsoft001/nestjs';
29
+ *
30
+ * @Module({
31
+ * providers: [
32
+ * {
33
+ * provide: APP_FILTER,
34
+ * useClass: AppExceptionFilter,
35
+ * },
36
+ * ],
37
+ * })
38
+ * export class AppModule {}
39
+ * ```
40
+ */
41
+ @Catch()
42
+ export class AppExceptionFilter implements ExceptionFilter {
43
+ /**
44
+ * Method to catch and handle exceptions.
45
+ *
46
+ * @param {any} exception - The exception thrown.
47
+ * @param {ArgumentsHost} host - The arguments host.
48
+ */
49
+ catch(exception: any, host: ArgumentsHost) {
50
+ const ctx = host.switchToHttp();
51
+ const response = ctx.getResponse();
52
+
53
+ let status = HttpStatus.INTERNAL_SERVER_ERROR;
54
+ let message = null;
55
+ if (exception instanceof HttpException) {
56
+ status = exception.getStatus();
57
+ message = exception['message'];
58
+ } else if (exception['type'] === DomainValidationError) {
59
+ status = HttpStatus.BAD_REQUEST;
60
+ message = exception['message'];
61
+ } else if (exception['type'] === DomainForbiddenError) {
62
+ status = HttpStatus.FORBIDDEN;
63
+ message = exception['message'];
64
+ } else {
65
+ status = HttpStatus.INTERNAL_SERVER_ERROR;
66
+ message = 'Internal server error';
67
+ }
68
+
69
+ Logger.error(
70
+ exception['stack'] || exception['message'] || exception,
71
+ AppExceptionFilter.name,
72
+ );
73
+
74
+ const result = response.status(status);
75
+ if (message && result.json) {
76
+ result.json({
77
+ details: message,
78
+ });
79
+ } else if (!message && result.json) {
80
+ result.json();
81
+ } else if (message && !result.json) {
82
+ result.send({
83
+ details: message,
84
+ });
85
+ } else {
86
+ result.send();
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,107 @@
1
+ import { ArgumentsHost, HttpException, HttpStatus } from '@nestjs/common';
2
+ import { Test, TestingModule } from '@nestjs/testing';
3
+ import {
4
+ DomainForbiddenError,
5
+ DomainValidationError,
6
+ } from '@smartsoft001/domain-core';
7
+
8
+ import { AppExceptionFilter } from './exception.filter';
9
+
10
+ describe('shared-nestjs: ExceptionFilter', () => {
11
+ let appExceptionFilter: AppExceptionFilter;
12
+
13
+ beforeEach(async () => {
14
+ const module: TestingModule = await Test.createTestingModule({
15
+ providers: [AppExceptionFilter],
16
+ }).compile();
17
+
18
+ appExceptionFilter = module.get<AppExceptionFilter>(AppExceptionFilter);
19
+ });
20
+
21
+ it('should handle HttpException', () => {
22
+ const mockResponse = {
23
+ status: jest.fn().mockReturnThis(),
24
+ json: jest.fn(),
25
+ send: jest.fn(),
26
+ };
27
+ const mockHost = {
28
+ switchToHttp: jest.fn().mockReturnValue({
29
+ getResponse: () => mockResponse,
30
+ }),
31
+ } as unknown as ArgumentsHost;
32
+ const exception = new HttpException('Forbidden', HttpStatus.FORBIDDEN);
33
+
34
+ appExceptionFilter.catch(exception, mockHost);
35
+
36
+ expect(mockResponse.status).toHaveBeenCalledWith(HttpStatus.FORBIDDEN);
37
+ expect(mockResponse.json).toHaveBeenCalledWith({ details: 'Forbidden' });
38
+ });
39
+
40
+ it('should handle DomainValidationError', () => {
41
+ const mockResponse = {
42
+ status: jest.fn().mockReturnThis(),
43
+ json: jest.fn(),
44
+ send: jest.fn(),
45
+ };
46
+ const mockHost = {
47
+ switchToHttp: jest.fn().mockReturnValue({
48
+ getResponse: () => mockResponse,
49
+ }),
50
+ } as unknown as ArgumentsHost;
51
+ const exception = {
52
+ type: DomainValidationError,
53
+ message: 'Validation failed',
54
+ };
55
+
56
+ appExceptionFilter.catch(exception, mockHost);
57
+
58
+ expect(mockResponse.status).toHaveBeenCalledWith(HttpStatus.BAD_REQUEST);
59
+ expect(mockResponse.json).toHaveBeenCalledWith({
60
+ details: 'Validation failed',
61
+ });
62
+ });
63
+
64
+ it('should handle DomainForbiddenError', () => {
65
+ const mockResponse = {
66
+ status: jest.fn().mockReturnThis(),
67
+ json: jest.fn(),
68
+ send: jest.fn(),
69
+ };
70
+ const mockHost = {
71
+ switchToHttp: jest.fn().mockReturnValue({
72
+ getResponse: () => mockResponse,
73
+ }),
74
+ } as unknown as ArgumentsHost;
75
+ const exception = { type: DomainForbiddenError, message: 'Access denied' };
76
+
77
+ appExceptionFilter.catch(exception, mockHost);
78
+
79
+ expect(mockResponse.status).toHaveBeenCalledWith(HttpStatus.FORBIDDEN);
80
+ expect(mockResponse.json).toHaveBeenCalledWith({
81
+ details: 'Access denied',
82
+ });
83
+ });
84
+
85
+ it('should handle internal server error', () => {
86
+ const mockResponse = {
87
+ status: jest.fn().mockReturnThis(),
88
+ json: jest.fn(),
89
+ send: jest.fn(),
90
+ };
91
+ const mockHost = {
92
+ switchToHttp: jest.fn().mockReturnValue({
93
+ getResponse: () => mockResponse,
94
+ }),
95
+ } as unknown as ArgumentsHost;
96
+ const exception = { message: 'Internal server error' };
97
+
98
+ appExceptionFilter.catch(exception, mockHost);
99
+
100
+ expect(mockResponse.status).toHaveBeenCalledWith(
101
+ HttpStatus.INTERNAL_SERVER_ERROR,
102
+ );
103
+ expect(mockResponse.json).toHaveBeenCalledWith({
104
+ details: 'Internal server error',
105
+ });
106
+ });
107
+ });
@@ -0,0 +1 @@
1
+ export * from './execution/exception.filter';
@@ -0,0 +1,21 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ export interface ISharedPermissions {
4
+ create: Array<string>;
5
+ read: Array<string>;
6
+ update: Array<string>;
7
+ delete: Array<string>;
8
+ [key: string]: Array<string>;
9
+ }
10
+
11
+ @Injectable()
12
+ export class SharedConfig {
13
+ tokenConfig?: {
14
+ secretOrPrivateKey: string;
15
+ expiredIn: number;
16
+ };
17
+ permissions?: ISharedPermissions;
18
+ type?: any;
19
+ }
20
+
21
+ export type PermissionType = 'create' | 'read' | 'update' | 'delete' | string;
@@ -0,0 +1,55 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+
3
+ import { JwtStrategy, PermissionService } from './auth';
4
+ import { SharedConfig } from './shared.config';
5
+
6
+ /**
7
+ * SharedModule class provides methods to configure the module's core functionalities and database settings.
8
+ */
9
+ export class SharedModule {
10
+ /**
11
+ * Configures the module's core functionalities.
12
+ *
13
+ * @param {SharedConfig} config - An object containing the module's configuration.
14
+ * @returns {DynamicModule} A DynamicModule object with providers and exports.
15
+ */
16
+ static forFeature(config: SharedConfig): DynamicModule {
17
+ return {
18
+ module: SharedModule,
19
+ providers: [
20
+ { provide: SharedConfig, useValue: config },
21
+ JwtStrategy,
22
+ PermissionService,
23
+ ],
24
+ exports: [
25
+ { provide: SharedConfig, useValue: config },
26
+ PermissionService,
27
+ JwtStrategy,
28
+ ],
29
+ };
30
+ }
31
+
32
+ /**
33
+ * Extends the forFeature() configuration by adding database settings. Use in AppModule.
34
+ *
35
+ * @param {SharedConfig & { db: { host: string; port: number; database: string; username?: string; password?: string; }}} config - An extended SharedConfig object that includes additional database settings.
36
+ * @returns {DynamicModule} A DynamicModule object that imports and exports the forFeature() configuration.
37
+ */
38
+ static forRoot(
39
+ config: SharedConfig & {
40
+ db: {
41
+ host: string;
42
+ port: number;
43
+ database: string;
44
+ username?: string;
45
+ password?: string;
46
+ };
47
+ },
48
+ ): DynamicModule {
49
+ return {
50
+ module: SharedModule,
51
+ imports: [SharedModule.forFeature(config)],
52
+ exports: [SharedModule.forFeature(config)],
53
+ };
54
+ }
55
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "noImplicitOverride": true,
8
+ "noImplicitReturns": true,
9
+ "noFallthroughCasesInSwitch": true,
10
+ "noPropertyAccessFromIndexSignature": true
11
+ },
12
+ "files": [],
13
+ "include": [],
14
+ "references": [
15
+ {
16
+ "path": "./tsconfig.lib.json"
17
+ },
18
+ {
19
+ "path": "./tsconfig.spec.json"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "declaration": true,
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "moduleResolution": "node10",
7
+ "types": ["jest", "node"]
8
+ },
9
+ "include": [
10
+ "jest.config.ts",
11
+ "src/**/*.test.ts",
12
+ "src/**/*.spec.ts",
13
+ "src/**/*.d.ts"
14
+ ]
15
+ }
package/src/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/filters"), exports);
5
- tslib_1.__exportStar(require("./lib/decorators"), exports);
6
- tslib_1.__exportStar(require("./lib/shared.module"), exports);
7
- tslib_1.__exportStar(require("./lib/shared.config"), exports);
8
- tslib_1.__exportStar(require("./lib/auth"), exports);
9
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/shared/nestjs/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,2DAAiC;AACjC,8DAAoC;AACpC,8DAAoC;AACpC,qDAA2B"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./permission.service"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/nestjs/src/lib/auth/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC"}
@@ -1,8 +0,0 @@
1
- import { SharedConfig } from "../shared.config";
2
- declare const JwtStrategy_base: new (...args: any[]) => any;
3
- export declare class JwtStrategy extends JwtStrategy_base {
4
- private config;
5
- constructor(config: SharedConfig);
6
- validate(payload: any): Promise<any>;
7
- }
8
- export {};
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JwtStrategy = void 0;
4
- const tslib_1 = require("tslib");
5
- const passport_jwt_1 = require("passport-jwt");
6
- const passport_1 = require("@nestjs/passport");
7
- const common_1 = require("@nestjs/common");
8
- const shared_config_1 = require("../shared.config");
9
- let JwtStrategy = exports.JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
10
- constructor(config) {
11
- super({
12
- jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
13
- ignoreExpiration: false,
14
- secretOrKey: config.tokenConfig.secretOrPrivateKey,
15
- });
16
- this.config = config;
17
- }
18
- async validate(payload) {
19
- return {
20
- ...payload,
21
- permissions: payload.permissions,
22
- username: payload.sub
23
- };
24
- }
25
- };
26
- exports.JwtStrategy = JwtStrategy = tslib_1.__decorate([
27
- (0, common_1.Injectable)(),
28
- tslib_1.__metadata("design:paramtypes", [shared_config_1.SharedConfig])
29
- ], JwtStrategy);
30
- //# sourceMappingURL=jwt.strategy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../../../../../../../libs/shared/nestjs/src/lib/auth/jwt.strategy.ts"],"names":[],"mappings":";;;;AAAA,+CAAoD;AACpD,+CAAoD;AACpD,2CAA4C;AAE5C,oDAA8C;AAGvC,IAAM,WAAW,yBAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACvD,YAAoB,MAAoB;QACpC,KAAK,CAAC;YACF,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,kBAAkB;SACrD,CAAC,CAAC;QALa,WAAM,GAAN,MAAM,CAAc;IAMxC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAY;QACvB,OAAO;YACH,GAAG,OAAO;YACV,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,OAAO,CAAC,GAAG;SACxB,CAAC;IACN,CAAC;CACJ,CAAA;sBAhBY,WAAW;IADvB,IAAA,mBAAU,GAAE;6CAEmB,4BAAY;GAD/B,WAAW,CAgBvB"}
@@ -1,7 +0,0 @@
1
- import { PermissionType, SharedConfig } from "../shared.config";
2
- import { IUser } from "@smartsoft001/users";
3
- export declare class PermissionService {
4
- private config;
5
- constructor(config: SharedConfig);
6
- valid(type: PermissionType, user: IUser): void;
7
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PermissionService = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const shared_config_1 = require("../shared.config");
7
- const domain_core_1 = require("@smartsoft001/domain-core");
8
- let PermissionService = exports.PermissionService = class PermissionService {
9
- constructor(config) {
10
- this.config = config;
11
- }
12
- valid(type, user) {
13
- if (!this.config.permissions)
14
- return;
15
- const typeConfig = this.config.permissions[type];
16
- if (!typeConfig)
17
- return;
18
- if (!user.permissions)
19
- throw new domain_core_1.DomainForbiddenError(`Context forbidden`);
20
- if (!typeConfig.some(tc => user.permissions.some(up => tc === up)))
21
- throw new domain_core_1.DomainForbiddenError(`Context forbidden`);
22
- }
23
- };
24
- exports.PermissionService = PermissionService = tslib_1.__decorate([
25
- (0, common_1.Injectable)(),
26
- tslib_1.__metadata("design:paramtypes", [shared_config_1.SharedConfig])
27
- ], PermissionService);
28
- //# sourceMappingURL=permission.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"permission.service.js","sourceRoot":"","sources":["../../../../../../../libs/shared/nestjs/src/lib/auth/permission.service.ts"],"names":[],"mappings":";;;;AAAA,2CAA0C;AAE1C,oDAA8D;AAC9D,2DAA+D;AAIxD,IAAM,iBAAiB,+BAAvB,MAAM,iBAAiB;IAC1B,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;IAAI,CAAC;IAE7C,KAAK,CAAC,IAAoB,EAAE,IAAW;QACnC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW;YAAE,OAAO;QAErC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAEjD,IAAI,CAAC,UAAU;YAAE,OAAO;QAExB,IAAI,CAAC,IAAI,CAAC,WAAW;YACjB,MAAM,IAAI,kCAAoB,CAAC,mBAAmB,CAAC,CAAC;QAExD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAC9D,MAAM,IAAI,kCAAoB,CAAC,mBAAmB,CAAC,CAAC;IAC5D,CAAC;CACJ,CAAA;4BAhBY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;6CAEmB,4BAAY;GAD/B,iBAAiB,CAgB7B"}
@@ -1,10 +0,0 @@
1
- import { HealthCheckService, HttpHealthIndicator, MemoryHealthIndicator } from '@nestjs/terminus';
2
- import { HealthDbService } from "../../services";
3
- export declare class HealthController {
4
- private health;
5
- private http;
6
- private memory;
7
- private custom;
8
- constructor(health: HealthCheckService, http: HttpHealthIndicator, memory: MemoryHealthIndicator, custom: HealthDbService);
9
- check(): Promise<import("@nestjs/terminus").HealthCheckResult>;
10
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HealthController = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const terminus_1 = require("@nestjs/terminus");
7
- const services_1 = require("../../services");
8
- let HealthController = exports.HealthController = class HealthController {
9
- constructor(health, http, memory, custom) {
10
- this.health = health;
11
- this.http = http;
12
- this.memory = memory;
13
- this.custom = custom;
14
- }
15
- check() {
16
- return this.health.check([
17
- () => this.http.pingCheck('google', 'https://google.com'),
18
- () => this.memory.checkHeap('memory_heap', 150 * 1024 * 1024),
19
- () => this.custom.isHealthy('database'),
20
- ]);
21
- }
22
- };
23
- tslib_1.__decorate([
24
- (0, common_1.Get)(),
25
- (0, terminus_1.HealthCheck)(),
26
- tslib_1.__metadata("design:type", Function),
27
- tslib_1.__metadata("design:paramtypes", []),
28
- tslib_1.__metadata("design:returntype", void 0)
29
- ], HealthController.prototype, "check", null);
30
- exports.HealthController = HealthController = tslib_1.__decorate([
31
- (0, common_1.Controller)('_app/health'),
32
- tslib_1.__metadata("design:paramtypes", [terminus_1.HealthCheckService,
33
- terminus_1.HttpHealthIndicator,
34
- terminus_1.MemoryHealthIndicator,
35
- services_1.HealthDbService])
36
- ], HealthController);
37
- //# sourceMappingURL=health.controller.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../../../../../../../libs/shared/nestjs/src/lib/controllers/health/health.controller.ts"],"names":[],"mappings":";;;;AAAA,2CAAiD;AACjD,+CAK0B;AAC1B,6CAAiD;AAG1C,IAAM,gBAAgB,8BAAtB,MAAM,gBAAgB;IAC3B,YACU,MAA0B,EAC1B,IAAyB,EACzB,MAA6B,EAC7B,MAAuB;QAHvB,WAAM,GAAN,MAAM,CAAoB;QAC1B,SAAI,GAAJ,IAAI,CAAqB;QACzB,WAAM,GAAN,MAAM,CAAuB;QAC7B,WAAM,GAAN,MAAM,CAAiB;IAC9B,CAAC;IAIJ,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACvB,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,oBAAoB,CAAC;YACzD,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;YAC7D,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;SACxC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAPC;IAFC,IAAA,YAAG,GAAE;IACL,IAAA,sBAAW,GAAE;;;;6CAOb;2BAhBU,gBAAgB;IAD5B,IAAA,mBAAU,EAAC,aAAa,CAAC;6CAGN,6BAAkB;QACpB,8BAAmB;QACjB,gCAAqB;QACrB,0BAAe;GALtB,gBAAgB,CAiB5B"}
@@ -1,2 +0,0 @@
1
- import { HealthController } from "./health/health.controller";
2
- export declare const CONTROLLERS: (typeof HealthController)[];
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONTROLLERS = void 0;
4
- const health_controller_1 = require("./health/health.controller");
5
- exports.CONTROLLERS = [
6
- health_controller_1.HealthController
7
- ];
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/nestjs/src/lib/controllers/index.ts"],"names":[],"mappings":";;;AAAA,kEAA8D;AAEjD,QAAA,WAAW,GAAG;IACzB,oCAAgB;CACjB,CAAC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./user/user.decorator"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/nestjs/src/lib/decorators/index.ts"],"names":[],"mappings":";;;AAAA,gEAAsC"}
@@ -1 +0,0 @@
1
- export declare const User: (...dataOrPipes: any[]) => ParameterDecorator;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.User = void 0;
4
- const common_1 = require("@nestjs/common");
5
- exports.User = (0, common_1.createParamDecorator)((_, context) => {
6
- const [req] = context.getArgs();
7
- return req.user;
8
- });
9
- //# sourceMappingURL=user.decorator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.decorator.js","sourceRoot":"","sources":["../../../../../../../../libs/shared/nestjs/src/lib/decorators/user/user.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAE3D,QAAA,IAAI,GAAG,IAAA,6BAAoB,EAAC,CAAC,CAAC,EAAE,OAAyB,EAAE,EAAE;IACtE,MAAM,CAAE,GAAG,CAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAClC,OAAO,GAAG,CAAC,IAAI,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -1,4 +0,0 @@
1
- import { ArgumentsHost, ExceptionFilter } from "@nestjs/common";
2
- export declare class AppExceptionFilter implements ExceptionFilter {
3
- catch(exception: unknown, host: ArgumentsHost): void;
4
- }
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var AppExceptionFilter_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.AppExceptionFilter = void 0;
5
- const tslib_1 = require("tslib");
6
- const common_1 = require("@nestjs/common");
7
- const domain_core_1 = require("@smartsoft001/domain-core");
8
- let AppExceptionFilter = exports.AppExceptionFilter = AppExceptionFilter_1 = class AppExceptionFilter {
9
- catch(exception, host) {
10
- const ctx = host.switchToHttp();
11
- const response = ctx.getResponse();
12
- let status = common_1.HttpStatus.INTERNAL_SERVER_ERROR;
13
- let message = null;
14
- if (exception instanceof common_1.HttpException) {
15
- status = exception.getStatus();
16
- message = exception["message"];
17
- }
18
- else if (exception["type"] === domain_core_1.DomainValidationError) {
19
- status = common_1.HttpStatus.BAD_REQUEST;
20
- message = exception["message"];
21
- }
22
- else if (exception["type"] === domain_core_1.DomainForbiddenError) {
23
- status = common_1.HttpStatus.FORBIDDEN;
24
- message = exception["message"];
25
- }
26
- common_1.Logger.error(exception["stack"] || exception["message"] || exception, AppExceptionFilter_1.name);
27
- const result = response.status(status);
28
- if (message && result.json) {
29
- result.json({
30
- details: message,
31
- });
32
- }
33
- else if (!message && result.json) {
34
- result.json();
35
- }
36
- else if (message && !result.json) {
37
- result.send({
38
- details: message,
39
- });
40
- }
41
- else {
42
- result.send();
43
- }
44
- }
45
- };
46
- exports.AppExceptionFilter = AppExceptionFilter = AppExceptionFilter_1 = tslib_1.__decorate([
47
- (0, common_1.Catch)()
48
- ], AppExceptionFilter);
49
- //# sourceMappingURL=exception.filter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exception.filter.js","sourceRoot":"","sources":["../../../../../../../../libs/shared/nestjs/src/lib/filters/exception/exception.filter.ts"],"names":[],"mappings":";;;;;AAAA,2CAOwB;AACxB,2DAGmC;AAG5B,IAAM,kBAAkB,uDAAxB,MAAM,kBAAkB;IAC7B,KAAK,CAAC,SAAkB,EAAE,IAAmB;QAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAEnC,IAAI,MAAM,GAAG,mBAAU,CAAC,qBAAqB,CAAC;QAC9C,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI,SAAS,YAAY,sBAAa,EAAE;YACtC,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;YAC/B,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;SAChC;aAAM,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,mCAAqB,EAAE;YACtD,MAAM,GAAG,mBAAU,CAAC,WAAW,CAAC;YAChC,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;SAChC;aAAM,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,kCAAoB,EAAE;YACrD,MAAM,GAAG,mBAAU,CAAC,SAAS,CAAC;YAC9B,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;SAChC;QAED,eAAM,CAAC,KAAK,CACV,SAAS,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,IAAI,SAAS,EACvD,oBAAkB,CAAC,IAAI,CACxB,CAAC;QAEF,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE;YAC1B,MAAM,CAAC,IAAI,CAAC;gBACV,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;SACJ;aAAM,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE;YAClC,MAAM,CAAC,IAAI,EAAE,CAAC;SACf;aAAM,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAClC,MAAM,CAAC,IAAI,CAAC;gBACV,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,CAAC,IAAI,EAAE,CAAC;SACf;IACH,CAAC;CACF,CAAA;6BAtCY,kBAAkB;IAD9B,IAAA,cAAK,GAAE;GACK,kBAAkB,CAsC9B"}
@@ -1 +0,0 @@
1
- export * from './exception/exception.filter';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./exception/exception.filter"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/nestjs/src/lib/filters/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C"}
@@ -1,7 +0,0 @@
1
- import { HealthIndicator, HealthIndicatorResult } from '@nestjs/terminus';
2
- import { IItemRepository } from '@smartsoft001/domain-core';
3
- export declare class HealthDbService extends HealthIndicator {
4
- private repository;
5
- constructor(repository: IItemRepository<any>);
6
- isHealthy(key: string): Promise<HealthIndicatorResult>;
7
- }