@revisium/endpoint 2.6.0-alpha.1 → 2.7.0-alpha.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.
@@ -26,9 +26,11 @@ let HealthController = class HealthController {
26
26
  liveness() {
27
27
  const indicators = [
28
28
  async () => this.prisma.check(),
29
- async () => this.notifications.check(),
30
29
  async () => this.coreApi.check(),
31
30
  ];
31
+ if (this.notifications.available) {
32
+ indicators.push(async () => this.notifications.check());
33
+ }
32
34
  return this.health.check(indicators);
33
35
  }
34
36
  readiness() {
@@ -1 +1 @@
1
- {"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../../../src/endpoint-microservice/health/health.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,6CAAgE;AAChE,+CAAmE;AAEnE,qDAA+E;AAC/E,6DAAwF;AACxF,qEAAwF;AAKjF,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YACmB,MAA0B,EAC1B,MAAqB,EACrB,aAAgC,EAChC,OAAqB;QAHrB,WAAM,GAAN,MAAM,CAAoB;QAC1B,WAAM,GAAN,MAAM,CAAe;QACrB,kBAAa,GAAb,aAAa,CAAmB;QAChC,YAAO,GAAP,OAAO,CAAc;IACrC,CAAC;IAIJ,QAAQ;QACN,MAAM,UAAU,GAA8B;YAC5C,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YAC/B,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE;YACtC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;SACjC,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAID,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;CACF,CAAA;AAzBY,4CAAgB;AAU3B;IAFC,IAAA,YAAG,EAAC,WAAW,CAAC;IAChB,IAAA,sBAAW,GAAE;;;;gDASb;AAID;IAFC,IAAA,YAAG,EAAC,UAAU,CAAC;IACf,IAAA,sBAAW,GAAE;;;;iDAGb;2BAxBU,gBAAgB;IAH5B,IAAA,8BAAoB,GAAE;IACtB,IAAA,iBAAO,EAAC,QAAQ,CAAC;IACjB,IAAA,mBAAU,EAAC,QAAQ,CAAC;qCAGQ,6BAAkB;QAClB,sCAAa;QACN,sCAAiB;QACvB,6BAAY;GAL7B,gBAAgB,CAyB5B"}
1
+ {"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../../../src/endpoint-microservice/health/health.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,6CAAgE;AAChE,+CAAmE;AAEnE,qDAA+E;AAC/E,6DAAwF;AACxF,qEAAwF;AAKjF,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YACmB,MAA0B,EAC1B,MAAqB,EACrB,aAAgC,EAChC,OAAqB;QAHrB,WAAM,GAAN,MAAM,CAAoB;QAC1B,WAAM,GAAN,MAAM,CAAe;QACrB,kBAAa,GAAb,aAAa,CAAmB;QAChC,YAAO,GAAP,OAAO,CAAc;IACrC,CAAC;IAIJ,QAAQ;QACN,MAAM,UAAU,GAA8B;YAC5C,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YAC/B,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;SACjC,CAAC;QAEF,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;YACjC,UAAU,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAID,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;CACF,CAAA;AA5BY,4CAAgB;AAU3B;IAFC,IAAA,YAAG,EAAC,WAAW,CAAC;IAChB,IAAA,sBAAW,GAAE;;;;gDAYb;AAID;IAFC,IAAA,YAAG,EAAC,UAAU,CAAC;IACf,IAAA,sBAAW,GAAE;;;;iDAGb;2BA3BU,gBAAgB;IAH5B,IAAA,8BAAoB,GAAE;IACtB,IAAA,iBAAO,EAAC,QAAQ,CAAC;IACjB,IAAA,mBAAU,EAAC,QAAQ,CAAC;qCAGQ,6BAAkB;QAClB,sCAAa;QACN,sCAAiB;QACvB,6BAAY;GAL7B,gBAAgB,CA4B5B"}
@@ -1,8 +1,20 @@
1
+ import { OnModuleDestroy } from '@nestjs/common';
1
2
  import { ConfigService } from '@nestjs/config';
2
- import { MicroserviceHealthIndicator } from '@nestjs/terminus';
3
- export declare class NotificationCheck {
3
+ import { HealthIndicatorService } from '@nestjs/terminus';
4
+ export declare class NotificationCheck implements OnModuleDestroy {
4
5
  private readonly configService;
5
- private readonly microservice;
6
- constructor(configService: ConfigService, microservice: MicroserviceHealthIndicator);
7
- check(): Promise<import("@nestjs/terminus").HealthIndicatorResult<string>>;
6
+ private readonly healthIndicator;
7
+ private redis?;
8
+ private connectPromise?;
9
+ constructor(configService: ConfigService, healthIndicator: HealthIndicatorService);
10
+ get available(): boolean;
11
+ check(): Promise<import("@nestjs/terminus").HealthIndicatorResult<any, "down", {
12
+ message: string;
13
+ }> | import("@nestjs/terminus").HealthIndicatorResult<"notification", "up", {
14
+ [x: string]: unknown;
15
+ }>>;
16
+ onModuleDestroy(): Promise<void>;
17
+ private getRedis;
18
+ private hasRedisConfiguration;
19
+ private ensureConnected;
8
20
  }
@@ -12,14 +12,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.NotificationCheck = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const config_1 = require("@nestjs/config");
15
- const microservices_1 = require("@nestjs/microservices");
16
15
  const terminus_1 = require("@nestjs/terminus");
16
+ const ioredis_1 = require("ioredis");
17
17
  let NotificationCheck = class NotificationCheck {
18
- constructor(configService, microservice) {
18
+ constructor(configService, healthIndicator) {
19
19
  this.configService = configService;
20
- this.microservice = microservice;
20
+ this.healthIndicator = healthIndicator;
21
+ }
22
+ get available() {
23
+ return this.hasRedisConfiguration();
21
24
  }
22
25
  async check() {
26
+ const indicator = this.healthIndicator.check('notification');
27
+ const redis = this.getRedis();
28
+ try {
29
+ await this.ensureConnected(redis);
30
+ await redis.ping();
31
+ return indicator.up();
32
+ }
33
+ catch (error) {
34
+ return indicator.down(error instanceof Error
35
+ ? error.message
36
+ : 'Redis notification bus is not available');
37
+ }
38
+ }
39
+ async onModuleDestroy() {
40
+ if (!this.redis) {
41
+ return;
42
+ }
43
+ try {
44
+ await this.redis.quit();
45
+ }
46
+ catch {
47
+ this.redis.disconnect();
48
+ }
49
+ }
50
+ getRedis() {
51
+ if (this.redis) {
52
+ return this.redis;
53
+ }
23
54
  const portPath = 'ENDPOINT_PORT';
24
55
  const hostPath = 'ENDPOINT_HOST';
25
56
  const envPort = this.configService.get(portPath);
@@ -31,19 +62,43 @@ let NotificationCheck = class NotificationCheck {
31
62
  if (!host) {
32
63
  throw new Error(`Environment variable not found: ${hostPath}`);
33
64
  }
34
- return this.microservice.pingCheck('notification', {
35
- transport: microservices_1.Transport.REDIS,
36
- options: {
37
- host,
38
- port,
39
- },
65
+ this.redis = new ioredis_1.default({
66
+ host,
67
+ port,
68
+ lazyConnect: true,
69
+ enableOfflineQueue: false,
70
+ maxRetriesPerRequest: 1,
71
+ connectTimeout: 1000,
72
+ retryStrategy: (times) => Math.min(times * 100, 1000),
73
+ });
74
+ this.redis.on('error', () => undefined);
75
+ return this.redis;
76
+ }
77
+ hasRedisConfiguration() {
78
+ return Boolean(this.configService.get('ENDPOINT_HOST') &&
79
+ this.configService.get('ENDPOINT_PORT'));
80
+ }
81
+ async ensureConnected(redis) {
82
+ if (redis.status === 'ready') {
83
+ return;
84
+ }
85
+ if (this.connectPromise) {
86
+ await this.connectPromise;
87
+ return;
88
+ }
89
+ if (redis.status !== 'wait' && redis.status !== 'end') {
90
+ return;
91
+ }
92
+ this.connectPromise = redis.connect().finally(() => {
93
+ this.connectPromise = undefined;
40
94
  });
95
+ await this.connectPromise;
41
96
  }
42
97
  };
43
98
  exports.NotificationCheck = NotificationCheck;
44
99
  exports.NotificationCheck = NotificationCheck = __decorate([
45
100
  (0, common_1.Injectable)(),
46
101
  __metadata("design:paramtypes", [config_1.ConfigService,
47
- terminus_1.MicroserviceHealthIndicator])
102
+ terminus_1.HealthIndicatorService])
48
103
  ], NotificationCheck);
49
104
  //# sourceMappingURL=notification.check.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notification.check.js","sourceRoot":"","sources":["../../../../src/endpoint-microservice/health/notification.check.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgE;AAChE,+CAA+D;AAGxD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACmB,aAA4B,EAC5B,YAAyC;QADzC,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAA6B;IACzD,CAAC;IAEG,KAAK,CAAC,KAAK;QAChB,MAAM,QAAQ,GAAG,eAAe,CAAC;QACjC,MAAM,QAAQ,GAAG,eAAe,CAAC;QAEjC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,QAAQ,CAAC,CAAC;QAEzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEtC,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,QAAQ,CAAC,CAAC;QAEtD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAe,cAAc,EAAE;YAC/D,SAAS,EAAE,yBAAS,CAAC,KAAK;YAC1B,OAAO,EAAE;gBACP,IAAI;gBACJ,IAAI;aACL;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA/BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGuB,sBAAa;QACd,sCAA2B;GAHjD,iBAAiB,CA+B7B"}
1
+ {"version":3,"file":"notification.check.js","sourceRoot":"","sources":["../../../../src/endpoint-microservice/health/notification.check.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA6D;AAC7D,2CAA+C;AAC/C,+CAA0D;AAC1D,qCAA4B;AAGrB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAI5B,YACmB,aAA4B,EAC5B,eAAuC;QADvC,kBAAa,GAAb,aAAa,CAAe;QAC5B,oBAAe,GAAf,eAAe,CAAwB;IACvD,CAAC;IAEJ,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACtC,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAE9B,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YAClC,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,OAAO,SAAS,CAAC,EAAE,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,SAAS,CAAC,IAAI,CACnB,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