@seas-computing/nestjs-healthcheck 0.0.5-9 → 0.0.6

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 CHANGED
@@ -13,9 +13,14 @@ npm install @seas-computing/nestjs-healthcheck
13
13
 
14
14
  ## Usage
15
15
 
16
- Add the `HealthCheckController` to the consuming application's `AppModule` (or other root module), along with providers for the `CONFIG_SERVICE`, `TypeOrmHealthIndicator`, `HttpHealthIndicator`, and `RedisHealthService`.
16
+ To add the nestjs healthcheck system, you should make the following changes in the consuming application's `AppModule` (or other root module):
17
+ - be sure that the `ConfigModule` is at the top of the imports list
18
+ - import and register the `HealthcheckModule` using `registerAsync`
19
+ - import `TypeOrmModule` and `RedisModule`
17
20
 
18
- Example from makerspace:
21
+ In the `ConfigService`, configuration values (i.e. `HealthcheckModuleOptions`) should be made available and passed as options to the `HealthcheckModule`.
22
+
23
+ Example `app.module` from [makerspace](https://github.huit.harvard.edu/SEAS/makerspace/blob/feature/add-healthcheck-module/src/server/app.module.ts):
19
24
  ```ts
20
25
  @Module({
21
26
  imports: [
@@ -80,7 +85,27 @@ Example from makerspace:
80
85
  AttendanceModule,
81
86
  UserModule,
82
87
  KioskModule,
83
- HealthCheckModule, // Add HealthCheckModule
88
+ HealthcheckModule.registerAsync({ // Add HealthCheckModule
89
+ imports: [ConfigModule],
90
+ inject: [ConfigService],
91
+ useFactory: (configService: ConfigService): HealthcheckModuleOptions => {
92
+ const casHealthcheckUrl = configService.casCheckURL;
93
+ if (!casHealthcheckUrl) throw new Error('casCheckURL is not defined or is invalid in configuration.');
94
+ try {
95
+ new URL(casHealthcheckUrl);
96
+ } catch (error) {
97
+ if (error instanceof Error) {
98
+ throw new Error(`casCheckURL is not a valid URL. ${error}`);
99
+ } else {
100
+ throw error;
101
+ }
102
+ }
103
+ return {
104
+ ...configService.healthcheckConfig,
105
+ casCheckURL: casHealthcheckUrl,
106
+ };
107
+ },
108
+ }),
84
109
  ],
85
110
  controllers: [],
86
111
  providers: [],
@@ -100,4 +125,74 @@ class AppModule implements NestModule {
100
125
 
101
126
  export { AppModule };
102
127
 
128
+ ```
129
+
130
+ Examples of additions to `config.service.ts` from [makerspace](https://github.huit.harvard.edu/SEAS/makerspace/blob/feature/add-healthcheck-module/src/server/config/config.service.ts):
131
+
132
+ ```ts
133
+ /**
134
+ * Returns the full healthcheck endpoint for HarvardKey CAS, which will be sent to
135
+ * the Healthcheck Module. It strips out any auth credentials, query strings, and
136
+ * hashes, normalizes the path to ensure there is only one `/cas` segment, and
137
+ * appends `/logout` to the end.
138
+ */
139
+ public get casCheckURL(): string {
140
+ const {
141
+ origin,
142
+ pathname,
143
+ } = this.casURL;
144
+ let cleanPath = pathname.replace(/\/$/, '');
145
+ cleanPath = cleanPath.replace(/\/(login|logout)$/, '');
146
+ if (!cleanPath.endsWith('/cas')) {
147
+ cleanPath += '/cas';
148
+ }
149
+ return `${origin}${cleanPath}/logout`;
150
+ }
151
+
152
+ public get healthcheckConfig(): HealthcheckModuleOptions {
153
+ return {
154
+ casCheckURL: this.casCheckURL,
155
+ dbOptions: this.dbOptions,
156
+ redisUrl: this.redisURL,
157
+ version: this.buildVersion,
158
+ strategy: this.isProduction
159
+ ? HEALTH_STRATEGY_NAME.HEALTHCHECK
160
+ : HEALTH_STRATEGY_NAME.DEV,
161
+ };
162
+ }
163
+ ```
164
+
165
+ ## Sample Response
166
+
167
+ You should receive a response that looks like this:
168
+
169
+ ```json
170
+ {
171
+ "status": "ok",
172
+ "info": {
173
+ "database": {
174
+ "status": "up"
175
+ },
176
+ "harvard-key": {
177
+ "status": "up"
178
+ },
179
+ "redis": {
180
+ "status": "up",
181
+ "result": "PONG"
182
+ }
183
+ },
184
+ "error": {},
185
+ "details": {
186
+ "database": {
187
+ "status": "up"
188
+ },
189
+ "harvard-key": {
190
+ "status": "up"
191
+ },
192
+ "redis": {
193
+ "status": "up",
194
+ "result": "PONG"
195
+ }
196
+ }
197
+ }
103
198
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAGA,IAAY,oBAkBX;AAlBD,WAAY,oBAAoB;IAI9B,2DAAmC,CAAA;IAanC,2CAAmB,CAAA;AACrB,CAAC,EAlBW,oBAAoB,oCAApB,oBAAoB,QAkB/B"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAGA,IAAY,oBAqBX;AArBD,WAAY,oBAAoB;IAI9B,2DAAmC,CAAA;IAgBnC,2CAAmB,CAAA;AACrB,CAAC,EArBW,oBAAoB,oCAApB,oBAAoB,QAqB/B"}
@@ -9,6 +9,6 @@ export declare class HealthCheckController {
9
9
  private redisHealth;
10
10
  constructor(config: ConfigServiceInterface, health: HealthCheckService, db: TypeOrmHealthIndicator, http: HttpHealthIndicator, redisHealth: RedisHealthService);
11
11
  getHealthCheck(): Promise<HealthCheckResult & {
12
- version: string;
12
+ buildVersion: string;
13
13
  }>;
14
14
  }
@@ -16,8 +16,8 @@ exports.HealthCheckController = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const swagger_1 = require("@nestjs/swagger");
18
18
  const terminus_1 = require("@nestjs/terminus");
19
- const ConfigServiceInterface_1 = require("./types/ConfigServiceInterface");
20
19
  const RedisHealthService_1 = require("./RedisHealthService");
20
+ const healthcheck_module_definition_1 = require("./healthcheck.module-definition");
21
21
  let HealthCheckController = class HealthCheckController {
22
22
  constructor(config, health, db, http, redisHealth) {
23
23
  this.config = config;
@@ -29,12 +29,12 @@ let HealthCheckController = class HealthCheckController {
29
29
  async getHealthCheck() {
30
30
  const status = await this.health.check([
31
31
  () => this.db.pingCheck('database'),
32
- () => this.http.pingCheck('harvard-key', `${this.config.casBaseURL}/cas/logout`),
32
+ () => this.http.pingCheck('harvard-key', this.config.casCheckURL),
33
33
  async () => this.redisHealth.checkRedisConnection(),
34
34
  ]);
35
35
  return {
36
36
  ...status,
37
- version: this.config.buildVersion,
37
+ buildVersion: this.config.buildVersion,
38
38
  };
39
39
  }
40
40
  };
@@ -56,7 +56,7 @@ __decorate([
56
56
  exports.HealthCheckController = HealthCheckController = __decorate([
57
57
  (0, swagger_1.ApiTags)('Health Check'),
58
58
  (0, common_1.Controller)('health-check'),
59
- __param(0, (0, common_1.Inject)(ConfigServiceInterface_1.CONFIG_SERVICE)),
59
+ __param(0, (0, common_1.Inject)(healthcheck_module_definition_1.MODULE_OPTIONS_TOKEN)),
60
60
  __param(1, (0, common_1.Inject)(terminus_1.HealthCheckService)),
61
61
  __param(2, (0, common_1.Inject)(terminus_1.TypeOrmHealthIndicator)),
62
62
  __param(3, (0, common_1.Inject)(terminus_1.HttpHealthIndicator)),
@@ -1 +1 @@
1
- {"version":3,"file":"healthcheck.controller.js","sourceRoot":"","sources":["../../src/healthcheck.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyD;AACzD,6CAAuE;AACvE,+CAAmI;AACnI,2EAAwF;AACxF,6DAA0D;AAInD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAEhC,YACkC,MAA8B,EAC1B,MAA0B,EACtB,EAA0B,EAC7B,IAAyB,EAC1B,WAA+B;QAJnC,WAAM,GAAN,MAAM,CAAwB;QAC1B,WAAM,GAAN,MAAM,CAAoB;QACtB,OAAE,GAAF,EAAE,CAAwB;QAC7B,SAAI,GAAJ,IAAI,CAAqB;QAC1B,gBAAW,GAAX,WAAW,CAAoB;IAClE,CAAC;IAcS,AAAN,KAAK,CAAC,cAAc;QAEzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACrC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC;YACnC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CACvB,aAAa,EACb,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,aAAa,CACvC;YACD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AAqB,CAsCjC"}
@@ -2,3 +2,6 @@ export { HealthcheckModule } from './healthcheck.module';
2
2
  export * from './healthcheck.controller';
3
3
  export * from './RedisHealthService';
4
4
  export * from './types/ConfigServiceInterface';
5
+ export * from './types/healthcheckModuleOptions';
6
+ export * from './constants';
7
+ export * from './healthcheck.module-definition';
package/dist/src/index.js CHANGED
@@ -20,4 +20,7 @@ Object.defineProperty(exports, "HealthcheckModule", { enumerable: true, get: fun
20
20
  __exportStar(require("./healthcheck.controller"), exports);
21
21
  __exportStar(require("./RedisHealthService"), exports);
22
22
  __exportStar(require("./types/ConfigServiceInterface"), exports);
23
+ __exportStar(require("./types/healthcheckModuleOptions"), exports);
24
+ __exportStar(require("./constants"), exports);
25
+ __exportStar(require("./healthcheck.module-definition"), exports);
23
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2DAAyD;AAAhD,uHAAA,iBAAiB,OAAA;AAC1B,2DAAyC;AACzC,uDAAqC;AACrC,iEAA+C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2DAAyD;AAAhD,uHAAA,iBAAiB,OAAA;AAC1B,2DAAyC;AACzC,uDAAqC;AACrC,iEAA+C;AAC/C,mEAAiD;AACjD,8CAA4B;AAC5B,kEAAgD"}
@@ -1,5 +1,4 @@
1
- export declare const CONFIG_SERVICE = "CONFIG_SERVICE";
2
1
  export interface ConfigServiceInterface {
3
- casBaseURL: string;
2
+ casCheckURL: string;
4
3
  buildVersion: string;
5
4
  }
@@ -1,5 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONFIG_SERVICE = void 0;
4
- exports.CONFIG_SERVICE = 'CONFIG_SERVICE';
5
3
  //# sourceMappingURL=ConfigServiceInterface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigServiceInterface.js","sourceRoot":"","sources":["../../../src/types/ConfigServiceInterface.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,gBAAgB,CAAC"}
1
+ {"version":3,"file":"ConfigServiceInterface.js","sourceRoot":"","sources":["../../../src/types/ConfigServiceInterface.ts"],"names":[],"mappings":""}
@@ -1,9 +1,9 @@
1
1
  import { TypeOrmModuleOptions } from '@nestjs/typeorm';
2
2
  import { HEALTH_STRATEGY_NAME } from '../constants';
3
3
  export interface HealthcheckModuleOptions {
4
- casBaseURL: string;
4
+ casCheckURL: string;
5
5
  dbOptions: TypeOrmModuleOptions;
6
6
  redisUrl: string;
7
- version: string;
7
+ buildVersion: string;
8
8
  strategy: HEALTH_STRATEGY_NAME;
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seas-computing/nestjs-healthcheck",
3
- "version": "0.0.5-9",
3
+ "version": "0.0.6",
4
4
  "description": "A standalone healthcheck module for NestJS apps",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",