@mondart/nestjs-common-module 2.2.5 → 2.3.1

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/README.md ADDED
@@ -0,0 +1,8 @@
1
+
2
+ ### Make release
3
+
4
+ #### after push to target version branch run the following command to create a release:
5
+
6
+ ```bash
7
+ $ gh release create vx.x.x --target branch -t vx.x.x --notes ""
8
+ ```
@@ -3,7 +3,10 @@ export declare const CACHING_MODULE_OPTIONS = "CACHING_MODULE_OPTIONS";
3
3
  export interface CachingModuleOptions {
4
4
  host: string;
5
5
  port: number;
6
+ username?: string;
6
7
  password: string;
8
+ database?: number;
9
+ tls?: boolean;
7
10
  namespace?: string;
8
11
  ttl?: number;
9
12
  }
@@ -25,6 +25,13 @@ let CachingModule = CachingModule_1 = class CachingModule {
25
25
  new redis_1.Keyv({
26
26
  store: new redis_1.default({
27
27
  url: `redis://${cachingOptions.host}:${cachingOptions.port}`,
28
+ socket: {
29
+ host: cachingOptions.host,
30
+ port: cachingOptions.port,
31
+ tls: cachingOptions.tls || false,
32
+ },
33
+ database: cachingOptions.database,
34
+ username: cachingOptions.username || 'default',
28
35
  password: cachingOptions.password,
29
36
  }),
30
37
  }, {
@@ -59,6 +66,13 @@ let CachingModule = CachingModule_1 = class CachingModule {
59
66
  new redis_1.Keyv({
60
67
  store: new redis_1.default({
61
68
  url: `redis://${cachingOptions.host}:${cachingOptions.port}`,
69
+ socket: {
70
+ host: cachingOptions.host,
71
+ port: cachingOptions.port,
72
+ tls: cachingOptions.tls || false,
73
+ },
74
+ database: cachingOptions.database,
75
+ username: cachingOptions.username || 'default',
62
76
  password: cachingOptions.password,
63
77
  }),
64
78
  }, {
@@ -0,0 +1,34 @@
1
+ import { ModuleMetadata, Type } from '@nestjs/common';
2
+ import { SASLOptions } from 'kafkajs';
3
+ import tls from 'tls';
4
+ export declare const HEALTH_CHECK_MODULE_OPTIONS = "HEALTH_CHECK_MODULE_OPTIONS";
5
+ export interface HealthCheckModuleOptions {
6
+ http?: {
7
+ docsUrl: string;
8
+ };
9
+ redis?: {
10
+ host: string;
11
+ port: number;
12
+ password?: string;
13
+ };
14
+ bull?: {
15
+ host: string;
16
+ port: number;
17
+ password?: string;
18
+ };
19
+ kafka?: {
20
+ clientId: string;
21
+ brokers: string[];
22
+ sasl?: SASLOptions;
23
+ ssl?: tls.ConnectionOptions;
24
+ };
25
+ }
26
+ export interface HealthCheckModuleFactory {
27
+ createModuleOptions: () => Promise<HealthCheckModuleOptions> | HealthCheckModuleOptions;
28
+ }
29
+ export interface HealthCheckModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
30
+ inject?: any[];
31
+ useClass?: Type<HealthCheckModuleFactory>;
32
+ useExisting?: Type<HealthCheckModuleFactory>;
33
+ useFactory?: (...args: any[]) => Promise<HealthCheckModuleOptions> | HealthCheckModuleOptions;
34
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HEALTH_CHECK_MODULE_OPTIONS = void 0;
4
+ exports.HEALTH_CHECK_MODULE_OPTIONS = 'HEALTH_CHECK_MODULE_OPTIONS';
@@ -0,0 +1,15 @@
1
+ import { HealthCheckService, HttpHealthIndicator, MicroserviceHealthIndicator, TypeOrmHealthIndicator } from '@nestjs/terminus';
2
+ import { HealthCheckModuleOptions } from './health-check-options.interface';
3
+ export declare class HealthCheckController {
4
+ private health;
5
+ private http;
6
+ private db;
7
+ private microservice;
8
+ private options;
9
+ constructor(health: HealthCheckService, http: HttpHealthIndicator, db: TypeOrmHealthIndicator, microservice: MicroserviceHealthIndicator, options: HealthCheckModuleOptions);
10
+ checkHttp(): Promise<import("@nestjs/terminus").HealthCheckResult>;
11
+ checkTypeOrm(): Promise<import("@nestjs/terminus").HealthCheckResult>;
12
+ checkRedis(): Promise<import("@nestjs/terminus").HealthCheckResult>;
13
+ checkBull(): Promise<import("@nestjs/terminus").HealthCheckResult>;
14
+ checkKafka(): Promise<import("@nestjs/terminus").HealthCheckResult>;
15
+ }
@@ -0,0 +1,120 @@
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.HealthCheckController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const microservices_1 = require("@nestjs/microservices");
18
+ const terminus_1 = require("@nestjs/terminus");
19
+ const health_check_options_interface_1 = require("./health-check-options.interface");
20
+ let HealthCheckController = class HealthCheckController {
21
+ constructor(health, http, db, microservice, options) {
22
+ this.health = health;
23
+ this.http = http;
24
+ this.db = db;
25
+ this.microservice = microservice;
26
+ this.options = options;
27
+ }
28
+ checkHttp() {
29
+ return this.health.check([
30
+ () => this.http.pingCheck('app-docs', this.options?.http?.docsUrl),
31
+ ]);
32
+ }
33
+ checkTypeOrm() {
34
+ return this.health.check([async () => this.db.pingCheck('typeorm')]);
35
+ }
36
+ checkRedis() {
37
+ return this.health.check([
38
+ async () => this.microservice.pingCheck('redis', {
39
+ transport: microservices_1.Transport.REDIS,
40
+ options: {
41
+ host: this.options?.redis?.host,
42
+ port: this.options?.redis?.port,
43
+ password: this.options?.redis?.password,
44
+ },
45
+ }),
46
+ ]);
47
+ }
48
+ checkBull() {
49
+ return this.health.check([
50
+ async () => this.microservice.pingCheck('redis', {
51
+ transport: microservices_1.Transport.REDIS,
52
+ options: {
53
+ host: this.options?.bull?.host,
54
+ port: this.options?.bull?.port,
55
+ password: this.options?.bull?.password,
56
+ },
57
+ }),
58
+ ]);
59
+ }
60
+ checkKafka() {
61
+ return this.health.check([
62
+ async () => this.microservice.pingCheck('kafka', {
63
+ transport: microservices_1.Transport.KAFKA,
64
+ timeout: 2000,
65
+ options: {
66
+ client: {
67
+ clientId: this.options?.kafka?.clientId,
68
+ brokers: this.options?.kafka?.brokers,
69
+ sasl: this.options?.kafka?.sasl,
70
+ ssl: this.options?.kafka?.ssl,
71
+ },
72
+ },
73
+ }),
74
+ ]);
75
+ }
76
+ };
77
+ exports.HealthCheckController = HealthCheckController;
78
+ __decorate([
79
+ (0, common_1.Get)('http'),
80
+ (0, terminus_1.HealthCheck)(),
81
+ __metadata("design:type", Function),
82
+ __metadata("design:paramtypes", []),
83
+ __metadata("design:returntype", void 0)
84
+ ], HealthCheckController.prototype, "checkHttp", null);
85
+ __decorate([
86
+ (0, common_1.Get)('database'),
87
+ (0, terminus_1.HealthCheck)(),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", []),
90
+ __metadata("design:returntype", void 0)
91
+ ], HealthCheckController.prototype, "checkTypeOrm", null);
92
+ __decorate([
93
+ (0, common_1.Get)('redis'),
94
+ (0, terminus_1.HealthCheck)(),
95
+ __metadata("design:type", Function),
96
+ __metadata("design:paramtypes", []),
97
+ __metadata("design:returntype", void 0)
98
+ ], HealthCheckController.prototype, "checkRedis", null);
99
+ __decorate([
100
+ (0, common_1.Get)('bull'),
101
+ (0, terminus_1.HealthCheck)(),
102
+ __metadata("design:type", Function),
103
+ __metadata("design:paramtypes", []),
104
+ __metadata("design:returntype", void 0)
105
+ ], HealthCheckController.prototype, "checkBull", null);
106
+ __decorate([
107
+ (0, common_1.Get)('kafka'),
108
+ (0, terminus_1.HealthCheck)(),
109
+ __metadata("design:type", Function),
110
+ __metadata("design:paramtypes", []),
111
+ __metadata("design:returntype", void 0)
112
+ ], HealthCheckController.prototype, "checkKafka", null);
113
+ exports.HealthCheckController = HealthCheckController = __decorate([
114
+ (0, common_1.Controller)('health-check'),
115
+ __param(4, (0, common_1.Inject)(health_check_options_interface_1.HEALTH_CHECK_MODULE_OPTIONS)),
116
+ __metadata("design:paramtypes", [terminus_1.HealthCheckService,
117
+ terminus_1.HttpHealthIndicator,
118
+ terminus_1.TypeOrmHealthIndicator,
119
+ terminus_1.MicroserviceHealthIndicator, Object])
120
+ ], HealthCheckController);
@@ -0,0 +1,8 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { HealthCheckModuleAsyncOptions, HealthCheckModuleOptions } from './health-check-options.interface';
3
+ export declare class HealthCheckModule {
4
+ static register(options: HealthCheckModuleOptions): DynamicModule;
5
+ static registerAsync(options: HealthCheckModuleAsyncOptions): DynamicModule;
6
+ private static createAsyncOptionsProvider;
7
+ private static createAsyncProviders;
8
+ }
@@ -0,0 +1,85 @@
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 HealthCheckModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.HealthCheckModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const health_check_controller_1 = require("./health-check.controller");
13
+ const terminus_1 = require("@nestjs/terminus");
14
+ const axios_1 = require("@nestjs/axios");
15
+ const health_check_options_interface_1 = require("./health-check-options.interface");
16
+ let HealthCheckModule = HealthCheckModule_1 = class HealthCheckModule {
17
+ static register(options) {
18
+ return {
19
+ module: HealthCheckModule_1,
20
+ imports: [terminus_1.TerminusModule, axios_1.HttpModule],
21
+ providers: [
22
+ terminus_1.HealthCheckService,
23
+ {
24
+ provide: health_check_options_interface_1.HEALTH_CHECK_MODULE_OPTIONS,
25
+ useValue: options,
26
+ },
27
+ ],
28
+ controllers: [health_check_controller_1.HealthCheckController],
29
+ exports: [],
30
+ };
31
+ }
32
+ static registerAsync(options) {
33
+ const asyncOptionsProvider = this.createAsyncOptionsProvider(options);
34
+ return {
35
+ module: HealthCheckModule_1,
36
+ imports: [...(options.imports || []), asyncOptionsProvider],
37
+ providers: [],
38
+ controllers: [health_check_controller_1.HealthCheckController],
39
+ exports: [],
40
+ };
41
+ }
42
+ static createAsyncOptionsProvider(options) {
43
+ const providers = this.createAsyncProviders(options);
44
+ return {
45
+ module: HealthCheckModule_1,
46
+ imports: [terminus_1.TerminusModule, axios_1.HttpModule],
47
+ providers,
48
+ exports: [terminus_1.TerminusModule, axios_1.HttpModule, health_check_options_interface_1.HEALTH_CHECK_MODULE_OPTIONS],
49
+ };
50
+ }
51
+ static createAsyncProviders(options) {
52
+ if (options.useFactory) {
53
+ return [
54
+ {
55
+ provide: health_check_options_interface_1.HEALTH_CHECK_MODULE_OPTIONS,
56
+ useFactory: options.useFactory,
57
+ inject: options.inject || [],
58
+ },
59
+ ];
60
+ }
61
+ const useClass = options.useClass || options.useExisting;
62
+ if (useClass) {
63
+ return [
64
+ {
65
+ provide: health_check_options_interface_1.HEALTH_CHECK_MODULE_OPTIONS,
66
+ useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
67
+ inject: [options.useExisting || options.useClass],
68
+ },
69
+ ...(options.useClass
70
+ ? [
71
+ {
72
+ provide: options.useClass,
73
+ useClass: options.useClass,
74
+ },
75
+ ]
76
+ : []),
77
+ ];
78
+ }
79
+ throw new Error('Invalid HealthCheckModuleAsyncOptions');
80
+ }
81
+ };
82
+ exports.HealthCheckModule = HealthCheckModule;
83
+ exports.HealthCheckModule = HealthCheckModule = HealthCheckModule_1 = __decorate([
84
+ (0, common_1.Module)({})
85
+ ], HealthCheckModule);
@@ -0,0 +1,3 @@
1
+ export * from './health-check.module';
2
+ export * from './health-check.controller';
3
+ export * from './health-check-options.interface';
@@ -0,0 +1,19 @@
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
+ __exportStar(require("./health-check.module"), exports);
18
+ __exportStar(require("./health-check.controller"), exports);
19
+ __exportStar(require("./health-check-options.interface"), exports);
@@ -3,3 +3,4 @@ export * from './saga';
3
3
  export * from './caching';
4
4
  export * from './keycloak';
5
5
  export * from './core-crud';
6
+ export * from './health-check';
package/dist/lib/index.js CHANGED
@@ -19,3 +19,4 @@ __exportStar(require("./saga"), exports);
19
19
  __exportStar(require("./caching"), exports);
20
20
  __exportStar(require("./keycloak"), exports);
21
21
  __exportStar(require("./core-crud"), exports);
22
+ __exportStar(require("./health-check"), exports);