@nathapp/nestjs-health 4.0.2 → 4.0.3
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 +33 -0
- package/dist/indicator/cache-health.check.d.ts +4 -1
- package/dist/indicator/cache-health.check.js +19 -5
- package/dist/indicator/cache-health.check.js.map +1 -1
- package/dist/indicator/generic-health.check.d.ts +1 -1
- package/dist/indicator/prisma-health.check.d.ts +4 -1
- package/dist/indicator/prisma-health.check.js +19 -4
- package/dist/indicator/prisma-health.check.js.map +1 -1
- package/dist/indicator/queue-health.check.d.ts +4 -1
- package/dist/indicator/queue-health.check.js +30 -8
- package/dist/indicator/queue-health.check.js.map +1 -1
- package/dist/interface/health-module-options.interface.d.ts +1 -0
- package/dist/interface/health-module-options.interface.js.map +1 -1
- package/dist/module/health.module.d.ts +1 -1
- package/dist/service/health-executor.service.js +21 -3
- package/dist/service/health-executor.service.js.map +1 -1
- package/package.json +5 -4
- package/tsconfig.test.json +16 -0
package/README.md
CHANGED
|
@@ -16,4 +16,37 @@ and exposes Kubernetes-grade **liveness** and **readiness** HTTP probes.
|
|
|
16
16
|
- `HealthModule.register({ liveness, readiness })` wires per-probe indicator
|
|
17
17
|
arrays and a controller exposing `GET /health/live` and `GET /health/ready`.
|
|
18
18
|
|
|
19
|
+
## Diagnostics disclosure (verbose)
|
|
20
|
+
|
|
21
|
+
The built-in `CacheHealthCheck`, `PrismaHealthCheck`, and `QueueHealthCheck`
|
|
22
|
+
adapters default to **`verbose: false`** (SEC-19). Because the readiness route is
|
|
23
|
+
typically unauthenticated, the default response is disclosure-safe:
|
|
24
|
+
|
|
25
|
+
- Successful checks return `{ status: 'up' }` only.
|
|
26
|
+
- A source that reports unhealthy returns `down` with a stable, non-diagnostic
|
|
27
|
+
reason: `'dependency unhealthy'`.
|
|
28
|
+
- A source that throws returns `down` with `reason: 'dependency check failed'`.
|
|
29
|
+
- A built-in adapter with no bound source returns `down` with
|
|
30
|
+
`reason: 'source not provided'`.
|
|
31
|
+
- Source-provided `connections`, `provider`, `message`, and raw error text are
|
|
32
|
+
**never** emitted. The safe `latencyMs` on queue results is kept when present.
|
|
33
|
+
|
|
34
|
+
Set `verbose: true` only on an **access-controlled diagnostics** endpoint:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
HealthModule.register({
|
|
38
|
+
readiness: [CacheHealthCheck, PrismaHealthCheck, QueueHealthCheck],
|
|
39
|
+
verbose: true,
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Verbose mode deliberately exposes dependency-provided detail (connection
|
|
44
|
+
arrays, provider identifiers, source messages, and caught error text). It is
|
|
45
|
+
intended for authenticated/internal diagnostics — do not enable it on a public
|
|
46
|
+
probe.
|
|
47
|
+
|
|
48
|
+
This policy applies to the built-in adapters only. Output from consumer-supplied
|
|
49
|
+
custom adapters (including `GenericHealthCheck`) is consumer-owned and is passed
|
|
50
|
+
through unchanged; this package does not redact arbitrary adapter output.
|
|
51
|
+
|
|
19
52
|
See `docs/superpowers/specs/2026-07-07-nestjs-health-design.md`.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HealthIndicatorService } from '@nestjs/terminus';
|
|
2
|
+
import { HealthModuleOptions } from '../interface/health-module-options.interface';
|
|
2
3
|
export interface CacheHealthSource {
|
|
3
4
|
isHealthy(): Promise<{
|
|
4
5
|
healthy: boolean;
|
|
@@ -14,7 +15,9 @@ type TerminusResult = {
|
|
|
14
15
|
export declare class CacheHealthCheck {
|
|
15
16
|
private readonly healthIndicatorService;
|
|
16
17
|
private readonly source?;
|
|
17
|
-
|
|
18
|
+
private readonly options?;
|
|
19
|
+
constructor(healthIndicatorService: HealthIndicatorService, source?: CacheHealthSource | undefined, options?: HealthModuleOptions | undefined);
|
|
20
|
+
private get verbose();
|
|
18
21
|
isHealthy(key?: string): Promise<TerminusResult>;
|
|
19
22
|
}
|
|
20
23
|
export {};
|
|
@@ -16,11 +16,17 @@ exports.CacheHealthCheck = exports.DEFAULT_CACHE_KEY = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const terminus_1 = require("@nestjs/terminus");
|
|
18
18
|
const health_constants_1 = require("../constant/health.constants");
|
|
19
|
+
const health_module_options_interface_1 = require("../interface/health-module-options.interface");
|
|
19
20
|
exports.DEFAULT_CACHE_KEY = 'cache';
|
|
20
21
|
let CacheHealthCheck = class CacheHealthCheck {
|
|
21
|
-
constructor(healthIndicatorService, source) {
|
|
22
|
+
constructor(healthIndicatorService, source, options) {
|
|
22
23
|
this.healthIndicatorService = healthIndicatorService;
|
|
23
24
|
this.source = source;
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
get verbose() {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.verbose) === true;
|
|
24
30
|
}
|
|
25
31
|
async isHealthy(key = exports.DEFAULT_CACHE_KEY) {
|
|
26
32
|
const indicator = this.healthIndicatorService.check(key);
|
|
@@ -29,14 +35,20 @@ let CacheHealthCheck = class CacheHealthCheck {
|
|
|
29
35
|
}
|
|
30
36
|
try {
|
|
31
37
|
const result = await this.source.isHealthy();
|
|
32
|
-
const details =
|
|
38
|
+
const details = this.verbose
|
|
39
|
+
? { connections: result.connections }
|
|
40
|
+
: result.healthy
|
|
41
|
+
? undefined
|
|
42
|
+
: { reason: 'dependency unhealthy' };
|
|
33
43
|
return result.healthy
|
|
34
44
|
? indicator.up(details)
|
|
35
45
|
: indicator.down(details);
|
|
36
46
|
}
|
|
37
47
|
catch (err) {
|
|
38
|
-
const
|
|
39
|
-
|
|
48
|
+
const details = this.verbose
|
|
49
|
+
? { error: err instanceof Error ? err.message : String(err) }
|
|
50
|
+
: { reason: 'dependency check failed' };
|
|
51
|
+
return indicator.down(details);
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
};
|
|
@@ -45,6 +57,8 @@ exports.CacheHealthCheck = CacheHealthCheck = __decorate([
|
|
|
45
57
|
(0, common_1.Injectable)(),
|
|
46
58
|
__param(1, (0, common_1.Optional)()),
|
|
47
59
|
__param(1, (0, common_1.Inject)(health_constants_1.CACHE_HEALTH_SOURCE)),
|
|
48
|
-
|
|
60
|
+
__param(2, (0, common_1.Optional)()),
|
|
61
|
+
__param(2, (0, common_1.Inject)(health_module_options_interface_1.HEALTH_MODULE_OPTIONS)),
|
|
62
|
+
__metadata("design:paramtypes", [terminus_1.HealthIndicatorService, Object, Object])
|
|
49
63
|
], CacheHealthCheck);
|
|
50
64
|
//# sourceMappingURL=cache-health.check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-health.check.js","sourceRoot":"","sources":["../../lib/indicator/cache-health.check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,+CAA0D;AAC1D,mEAAmE;
|
|
1
|
+
{"version":3,"file":"cache-health.check.js","sourceRoot":"","sources":["../../lib/indicator/cache-health.check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,+CAA0D;AAC1D,mEAAmE;AACnE,kGAGsD;AAYzC,QAAA,iBAAiB,GAAG,OAAO,CAAC;AAkBlC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YACmB,sBAA8C,EAG9C,MAA0B,EAG1B,OAA6B;QAN7B,2BAAsB,GAAtB,sBAAsB,CAAwB;QAG9C,WAAM,GAAN,MAAM,CAAoB;QAG1B,YAAO,GAAP,OAAO,CAAsB;IAC7C,CAAC;IAEJ,IAAY,OAAO;;QACjB,OAAO,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,MAAK,IAAI,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAc,yBAAiB;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEzD,IAAI,CAAC,IAAI,CAAC,MAAM,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7 +4,7 @@ export declare class GenericHealthCheck<TResult = unknown> {
|
|
|
4
4
|
private readonly healthIndicatorService;
|
|
5
5
|
private readonly source?;
|
|
6
6
|
private readonly normalize?;
|
|
7
|
-
constructor(healthIndicatorService: HealthIndicatorService, source?: HealthIndicatorSource<TResult
|
|
7
|
+
constructor(healthIndicatorService: HealthIndicatorService, source?: HealthIndicatorSource<TResult> | undefined, normalize?: HealthNormalize<TResult> | undefined);
|
|
8
8
|
isHealthy(key?: string): Promise<{
|
|
9
9
|
[k: string]: {
|
|
10
10
|
status: 'up' | 'down';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HealthIndicatorService } from '@nestjs/terminus';
|
|
2
|
+
import { HealthModuleOptions } from '../interface/health-module-options.interface';
|
|
2
3
|
export interface PrismaHealthSource {
|
|
3
4
|
isHealthy(): Promise<{
|
|
4
5
|
status: 'up' | 'down';
|
|
@@ -14,7 +15,9 @@ type TerminusResult = {
|
|
|
14
15
|
export declare class PrismaHealthCheck {
|
|
15
16
|
private readonly healthIndicatorService;
|
|
16
17
|
private readonly source?;
|
|
17
|
-
|
|
18
|
+
private readonly options?;
|
|
19
|
+
constructor(healthIndicatorService: HealthIndicatorService, source?: PrismaHealthSource | undefined, options?: HealthModuleOptions | undefined);
|
|
20
|
+
private get verbose();
|
|
18
21
|
isHealthy(key?: string): Promise<TerminusResult>;
|
|
19
22
|
}
|
|
20
23
|
export {};
|
|
@@ -16,11 +16,17 @@ exports.PrismaHealthCheck = exports.DEFAULT_PRISMA_KEY = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const terminus_1 = require("@nestjs/terminus");
|
|
18
18
|
const health_constants_1 = require("../constant/health.constants");
|
|
19
|
+
const health_module_options_interface_1 = require("../interface/health-module-options.interface");
|
|
19
20
|
exports.DEFAULT_PRISMA_KEY = 'prisma';
|
|
20
21
|
let PrismaHealthCheck = class PrismaHealthCheck {
|
|
21
|
-
constructor(healthIndicatorService, source) {
|
|
22
|
+
constructor(healthIndicatorService, source, options) {
|
|
22
23
|
this.healthIndicatorService = healthIndicatorService;
|
|
23
24
|
this.source = source;
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
get verbose() {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.verbose) === true;
|
|
24
30
|
}
|
|
25
31
|
async isHealthy(key = exports.DEFAULT_PRISMA_KEY) {
|
|
26
32
|
const indicator = this.healthIndicatorService.check(key);
|
|
@@ -29,6 +35,11 @@ let PrismaHealthCheck = class PrismaHealthCheck {
|
|
|
29
35
|
}
|
|
30
36
|
try {
|
|
31
37
|
const result = await this.source.isHealthy();
|
|
38
|
+
if (!this.verbose) {
|
|
39
|
+
return result.status === 'up'
|
|
40
|
+
? indicator.up()
|
|
41
|
+
: indicator.down({ reason: 'dependency unhealthy' });
|
|
42
|
+
}
|
|
32
43
|
const details = {};
|
|
33
44
|
if (result.message !== undefined) {
|
|
34
45
|
details.message = result.message;
|
|
@@ -38,8 +49,10 @@ let PrismaHealthCheck = class PrismaHealthCheck {
|
|
|
38
49
|
: indicator.down(details);
|
|
39
50
|
}
|
|
40
51
|
catch (err) {
|
|
41
|
-
const
|
|
42
|
-
|
|
52
|
+
const details = this.verbose
|
|
53
|
+
? { error: err instanceof Error ? err.message : String(err) }
|
|
54
|
+
: { reason: 'dependency check failed' };
|
|
55
|
+
return indicator.down(details);
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
58
|
};
|
|
@@ -48,6 +61,8 @@ exports.PrismaHealthCheck = PrismaHealthCheck = __decorate([
|
|
|
48
61
|
(0, common_1.Injectable)(),
|
|
49
62
|
__param(1, (0, common_1.Optional)()),
|
|
50
63
|
__param(1, (0, common_1.Inject)(health_constants_1.PRISMA_HEALTH_SOURCE)),
|
|
51
|
-
|
|
64
|
+
__param(2, (0, common_1.Optional)()),
|
|
65
|
+
__param(2, (0, common_1.Inject)(health_module_options_interface_1.HEALTH_MODULE_OPTIONS)),
|
|
66
|
+
__metadata("design:paramtypes", [terminus_1.HealthIndicatorService, Object, Object])
|
|
52
67
|
], PrismaHealthCheck);
|
|
53
68
|
//# sourceMappingURL=prisma-health.check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-health.check.js","sourceRoot":"","sources":["../../lib/indicator/prisma-health.check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,+CAA0D;AAC1D,mEAAoE;
|
|
1
|
+
{"version":3,"file":"prisma-health.check.js","sourceRoot":"","sources":["../../lib/indicator/prisma-health.check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,+CAA0D;AAC1D,mEAAoE;AACpE,kGAGsD;AAYzC,QAAA,kBAAkB,GAAG,QAAQ,CAAC;AAiBpC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACmB,sBAA8C,EAG9C,MAA2B,EAG3B,OAA6B;QAN7B,2BAAsB,GAAtB,sBAAsB,CAAwB;QAG9C,WAAM,GAAN,MAAM,CAAqB;QAG3B,YAAO,GAAP,OAAO,CAAsB;IAC7C,CAAC;IAEJ,IAAY,OAAO;;QACjB,OAAO,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,MAAK,IAAI,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAc,0BAAkB;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEzD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAA8B,CAAC;QACxF,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YAC7C,IAAI,CAAC,IAAI,CAAC,OAAO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@nestjs/terminus';
|
|
2
|
+
import { HealthModuleOptions } from '../interface/health-module-options.interface';
|
|
2
3
|
export interface QueueHealthSource {
|
|
3
4
|
isHealthy(): Promise<{
|
|
4
5
|
healthy: boolean;
|
|
@@ -16,7 +17,9 @@ type TerminusResult = {
|
|
|
16
17
|
export declare class QueueHealthCheck {
|
|
17
18
|
private readonly healthIndicatorService;
|
|
18
19
|
private readonly source?;
|
|
19
|
-
|
|
20
|
+
private readonly options?;
|
|
21
|
+
constructor(healthIndicatorService: HealthIndicatorService, source?: QueueHealthSource | undefined, options?: HealthModuleOptions | undefined);
|
|
22
|
+
private get verbose();
|
|
20
23
|
isHealthy(key?: string): Promise<TerminusResult>;
|
|
21
24
|
}
|
|
22
25
|
export {};
|
|
@@ -16,11 +16,17 @@ exports.QueueHealthCheck = exports.DEFAULT_QUEUE_KEY = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const terminus_1 = require("@nestjs/terminus");
|
|
18
18
|
const health_constants_1 = require("../constant/health.constants");
|
|
19
|
+
const health_module_options_interface_1 = require("../interface/health-module-options.interface");
|
|
19
20
|
exports.DEFAULT_QUEUE_KEY = 'queue';
|
|
20
21
|
let QueueHealthCheck = class QueueHealthCheck {
|
|
21
|
-
constructor(healthIndicatorService, source) {
|
|
22
|
+
constructor(healthIndicatorService, source, options) {
|
|
22
23
|
this.healthIndicatorService = healthIndicatorService;
|
|
23
24
|
this.source = source;
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
get verbose() {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.verbose) === true;
|
|
24
30
|
}
|
|
25
31
|
async isHealthy(key = exports.DEFAULT_QUEUE_KEY) {
|
|
26
32
|
const indicator = this.healthIndicatorService.check(key);
|
|
@@ -29,20 +35,34 @@ let QueueHealthCheck = class QueueHealthCheck {
|
|
|
29
35
|
}
|
|
30
36
|
try {
|
|
31
37
|
const result = await this.source.isHealthy();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
if (this.verbose) {
|
|
39
|
+
const details = {
|
|
40
|
+
provider: result.provider,
|
|
41
|
+
connections: result.connections,
|
|
42
|
+
};
|
|
43
|
+
if (result.latencyMs !== undefined) {
|
|
44
|
+
details.latencyMs = result.latencyMs;
|
|
45
|
+
}
|
|
46
|
+
return result.healthy
|
|
47
|
+
? indicator.up(details)
|
|
48
|
+
: indicator.down(details);
|
|
49
|
+
}
|
|
50
|
+
const details = {};
|
|
36
51
|
if (result.latencyMs !== undefined) {
|
|
37
52
|
details.latencyMs = result.latencyMs;
|
|
38
53
|
}
|
|
54
|
+
if (!result.healthy) {
|
|
55
|
+
details.reason = 'dependency unhealthy';
|
|
56
|
+
}
|
|
39
57
|
return result.healthy
|
|
40
58
|
? indicator.up(details)
|
|
41
59
|
: indicator.down(details);
|
|
42
60
|
}
|
|
43
61
|
catch (err) {
|
|
44
|
-
const
|
|
45
|
-
|
|
62
|
+
const details = this.verbose
|
|
63
|
+
? { error: err instanceof Error ? err.message : String(err) }
|
|
64
|
+
: { reason: 'dependency check failed' };
|
|
65
|
+
return indicator.down(details);
|
|
46
66
|
}
|
|
47
67
|
}
|
|
48
68
|
};
|
|
@@ -51,6 +71,8 @@ exports.QueueHealthCheck = QueueHealthCheck = __decorate([
|
|
|
51
71
|
(0, common_1.Injectable)(),
|
|
52
72
|
__param(1, (0, common_1.Optional)()),
|
|
53
73
|
__param(1, (0, common_1.Inject)(health_constants_1.QUEUE_HEALTH_SOURCE)),
|
|
54
|
-
|
|
74
|
+
__param(2, (0, common_1.Optional)()),
|
|
75
|
+
__param(2, (0, common_1.Inject)(health_module_options_interface_1.HEALTH_MODULE_OPTIONS)),
|
|
76
|
+
__metadata("design:paramtypes", [terminus_1.HealthIndicatorService, Object, Object])
|
|
55
77
|
], QueueHealthCheck);
|
|
56
78
|
//# sourceMappingURL=queue-health.check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue-health.check.js","sourceRoot":"","sources":["../../lib/indicator/queue-health.check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,+CAA0D;AAC1D,mEAAmE;
|
|
1
|
+
{"version":3,"file":"queue-health.check.js","sourceRoot":"","sources":["../../lib/indicator/queue-health.check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,+CAA0D;AAC1D,mEAAmE;AACnE,kGAGsD;AAiBzC,QAAA,iBAAiB,GAAG,OAAO,CAAC;AAiBlC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YACmB,sBAA8C,EAG9C,MAA0B,EAG1B,OAA6B;QAN7B,2BAAsB,GAAtB,sBAAsB,CAAwB;QAG9C,WAAM,GAAN,MAAM,CAAoB;QAG1B,YAAO,GAAP,OAAO,CAAsB;IAC7C,CAAC;IAEJ,IAAY,OAAO;;QACjB,OAAO,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,MAAK,IAAI,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAc,yBAAiB;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEzD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAA8B,CAAC;QACxF,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YAC7C,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,MAAM,OAAO,GAIT;oBACF,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,WAAW,EAAE,MAAM,CAAC,WAAW;iBAChC,CAAC;gBACF,IAAI,MAAM,CAAC,SAAS,KAAK,S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A,IAAA,eAAM,EAAC,uDAAqB,CAAC,CAAA;qCALW,iCAAsB;GAFtD,gBAAgB,CA2D5B"}
|
|
@@ -13,6 +13,7 @@ export interface HealthModuleOptions {
|
|
|
13
13
|
liveness?: Type<unknown>[];
|
|
14
14
|
readiness?: Type<unknown>[];
|
|
15
15
|
timeoutMs?: number;
|
|
16
|
+
verbose?: boolean;
|
|
16
17
|
}
|
|
17
18
|
export declare const HEALTH_MODULE_OPTIONS = "HEALTH_MODULE_OPTIONS";
|
|
18
19
|
export interface HealthAsyncModuleOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health-module-options.interface.js","sourceRoot":"","sources":["../../lib/interface/health-module-options.interface.ts"],"names":[],"mappings":";;;AAgCA,wEAiBC;AAhDD,mEAGsC;AA4BtC,SAAgB,8BAA8B,CAC5C,UAA4C;IAE5C,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,YAAY,GAChB,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,YAAY,KAAI,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACnE,CAAC,CAAC,UAAU,CAAC,YAAY;QACzB,CAAC,CAAC,wCAAqB,CAAC;IAC5B,MAAM,aAAa,GACjB,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,KAAI,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACrE,CAAC,CAAC,UAAU,CAAC,aAAa;QAC1B,CAAC,CAAC,yCAAsB,CAAC;IAE7B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AACzC,CAAC;
|
|
1
|
+
{"version":3,"file":"health-module-options.interface.js","sourceRoot":"","sources":["../../lib/interface/health-module-options.interface.ts"],"names":[],"mappings":";;;AAgCA,wEAiBC;AAhDD,mEAGsC;AA4BtC,SAAgB,8BAA8B,CAC5C,UAA4C;IAE5C,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,YAAY,GAChB,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,YAAY,KAAI,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACnE,CAAC,CAAC,UAAU,CAAC,YAAY;QACzB,CAAC,CAAC,wCAAqB,CAAC;IAC5B,MAAM,aAAa,GACjB,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,KAAI,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACrE,CAAC,CAAC,UAAU,CAAC,aAAa;QAC1B,CAAC,CAAC,yCAAsB,CAAC;IAE7B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AACzC,CAAC;AA8BY,QAAA,qBAAqB,GAAG,uBAAuB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import { HealthAsyncModuleOptions, HealthModuleOptions } from '../interface';
|
|
3
|
-
declare const HealthModule_base: import("@nathapp/nestjs-common").ConfigurableModuleCls<HealthModuleOptions, "register", "createOptions",
|
|
3
|
+
declare const HealthModule_base: import("@nathapp/nestjs-common").ConfigurableModuleCls<HealthModuleOptions, "register", "createOptions", object>;
|
|
4
4
|
export declare class HealthModule extends HealthModule_base {
|
|
5
5
|
static register(options?: HealthModuleOptions): DynamicModule;
|
|
6
6
|
static registerAsync(options: HealthAsyncModuleOptions): DynamicModule;
|
|
@@ -36,13 +36,31 @@ let HealthExecutorService = class HealthExecutorService {
|
|
|
36
36
|
var _a;
|
|
37
37
|
const timeoutMs = (_a = this.options.timeoutMs) !== null && _a !== void 0 ? _a : 5000;
|
|
38
38
|
const checks = types.map((T) => {
|
|
39
|
-
const
|
|
39
|
+
const down = (message) => ({
|
|
40
|
+
[T.name]: { status: 'down', message },
|
|
41
|
+
});
|
|
40
42
|
return () => {
|
|
43
|
+
let inst;
|
|
44
|
+
try {
|
|
45
|
+
inst = this.moduleRef.get(T, { strict: false });
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
return Promise.resolve(down(`Health adapter ${T.name} is not a registered provider; add it to HealthModule.register providers`));
|
|
49
|
+
}
|
|
50
|
+
const timeoutMessage = `Health check ${T.name} timed out after ${timeoutMs}ms`;
|
|
41
51
|
let timer;
|
|
42
52
|
const timeout = new Promise((_, reject) => {
|
|
43
|
-
timer = setTimeout(() => reject(new Error(
|
|
53
|
+
timer = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
|
|
44
54
|
});
|
|
45
|
-
return Promise.race([Promise.resolve(inst.isHealthy()), timeout])
|
|
55
|
+
return Promise.race([Promise.resolve().then(() => inst.isHealthy()), timeout])
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
if (err instanceof Error && err.message === timeoutMessage) {
|
|
58
|
+
return down(timeoutMessage);
|
|
59
|
+
}
|
|
60
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
61
|
+
return down(`Health check ${T.name} failed: ${detail}`);
|
|
62
|
+
})
|
|
63
|
+
.finally(() => {
|
|
46
64
|
clearTimeout(timer);
|
|
47
65
|
});
|
|
48
66
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health-executor.service.js","sourceRoot":"","sources":["../../lib/service/health-executor.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0D;AAC1D,uCAAyC;AACzC,+CAAsD;AACtD,+BAAwC;AACxC,kGAGsD;
|
|
1
|
+
{"version":3,"file":"health-executor.service.js","sourceRoot":"","sources":["../../lib/service/health-executor.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0D;AAC1D,uCAAyC;AACzC,+CAAsD;AACtD,+BAAwC;AACxC,kGAGsD;AAkD/C,IAAM,qB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
|
|
2
2
|
"name": "@nathapp/nestjs-health",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "First-party health-check aggregator for NestJS: unifies cache/prisma/queue health behind @nestjs/terminus and exposes liveness/readiness probes",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
"test:cov": "jest --config ./test/jest-test.json --coverage",
|
|
13
13
|
"test:watch": "jest --config ./test/jest-test.json --watch",
|
|
14
14
|
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
15
|
-
"lint": "eslint -c .eslintrc.js",
|
|
16
|
-
"lint:fix": "eslint -c .eslintrc.js --fix"
|
|
15
|
+
"lint": "eslint -c .eslintrc.js \"lib/**/*.ts\" \"test/**/*.ts\"",
|
|
16
|
+
"lint:fix": "eslint -c .eslintrc.js --fix \"lib/**/*.ts\" \"test/**/*.ts\"",
|
|
17
|
+
"type-check:test": "tsc --noEmit -p tsconfig.test.json"
|
|
17
18
|
},
|
|
18
19
|
"author": "William Khoo",
|
|
19
20
|
"license": "ISC",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@nathapp/eslint-config": "1.0.1",
|
|
46
|
-
"@nathapp/nestjs-common": "^4.0.
|
|
47
|
+
"@nathapp/nestjs-common": "^4.0.3",
|
|
47
48
|
"@nathapp/typescript-config": "1.0.1",
|
|
48
49
|
"@nestjs/common": "^11.0.0",
|
|
49
50
|
"@nestjs/core": "^11.0.0",
|