@ghentcdh/tools-api 0.0.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 +59 -0
- package/package.json +22 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +6 -0
- package/src/index.js.map +1 -0
- package/src/lib/health/health-api.module.d.ts +2 -0
- package/src/lib/health/health-api.module.js +25 -0
- package/src/lib/health/health-api.module.js.map +1 -0
- package/src/lib/health/health.controller.d.ts +9 -0
- package/src/lib/health/health.controller.js +42 -0
- package/src/lib/health/health.controller.js.map +1 -0
- package/src/lib/health/index.d.ts +1 -0
- package/src/lib/health/index.js +5 -0
- package/src/lib/health/index.js.map +1 -0
- package/src/lib/logging/index.d.ts +1 -0
- package/src/lib/logging/index.js +5 -0
- package/src/lib/logging/index.js.map +1 -0
- package/src/lib/logging/logger.d.ts +15 -0
- package/src/lib/logging/logger.js +72 -0
- package/src/lib/logging/logger.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
This library consist of a group of tools used by the GhentCDH projects.
|
|
2
|
+
|
|
3
|
+
# Health api
|
|
4
|
+
|
|
5
|
+
This will add a health check endpoint to the nestjs application.
|
|
6
|
+
|
|
7
|
+
Add it to the `AppModule` imports
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
|
|
11
|
+
import { HealthApiModule } from '@ghentcdh/tools/health/api';
|
|
12
|
+
|
|
13
|
+
@Module({
|
|
14
|
+
imports: [
|
|
15
|
+
...
|
|
16
|
+
HealthApiModule,
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
export class AppModule {}
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
# Logging api for nestjs application
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
1. adjust the nestjs file `main.ts` to include the logging module
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
|
|
31
|
+
import {Logger as MyLogger} from '@ghentcdh/tools/api';
|
|
32
|
+
|
|
33
|
+
// bootstrap the application
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
async function bootstrap() {
|
|
37
|
+
const app = await NestFactory.create(AppModule);
|
|
38
|
+
//...
|
|
39
|
+
|
|
40
|
+
app.useLogger(new MyLogger())
|
|
41
|
+
//...
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
2. configure the logging environment variable ```LOG_DIR``` in the `.env` file
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
LOG_DIR=/tmp/logs
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
3. Use the logging command
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import {Logger} from '@ghentcdh/tools/api';
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Logger.log('Nest hello api', 'AppController');
|
|
59
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ghentcdh/tools-api",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"tslib": "^2.3.0",
|
|
9
|
+
"@nestjs/axios": "^4.0.0",
|
|
10
|
+
"@nestjs/common": "^10.0.2",
|
|
11
|
+
"@nestjs/config": "^4.0.0",
|
|
12
|
+
"@nestjs/terminus": "^11.0.0",
|
|
13
|
+
"log4js": "^6.9.1",
|
|
14
|
+
"@nx/vite": "20.4.5",
|
|
15
|
+
"vite": "^5.0.0",
|
|
16
|
+
"vite-plugin-node": "^4.0.0"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/GhentCDH/ghentcdh-monorepo.git"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/tools/api/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAE7B,wDAA8B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HealthApiModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = require("@nestjs/axios");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const config_1 = require("@nestjs/config");
|
|
8
|
+
const terminus_1 = require("@nestjs/terminus");
|
|
9
|
+
const health_controller_1 = require("./health.controller");
|
|
10
|
+
let HealthApiModule = class HealthApiModule {
|
|
11
|
+
};
|
|
12
|
+
exports.HealthApiModule = HealthApiModule;
|
|
13
|
+
exports.HealthApiModule = HealthApiModule = tslib_1.__decorate([
|
|
14
|
+
(0, common_1.Module)({
|
|
15
|
+
imports: [terminus_1.TerminusModule,
|
|
16
|
+
axios_1.HttpModule,
|
|
17
|
+
config_1.ConfigModule
|
|
18
|
+
// PrismaModule
|
|
19
|
+
],
|
|
20
|
+
controllers: [health_controller_1.HealthController],
|
|
21
|
+
providers: [],
|
|
22
|
+
exports: [],
|
|
23
|
+
})
|
|
24
|
+
], HealthApiModule);
|
|
25
|
+
//# sourceMappingURL=health-api.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-api.module.js","sourceRoot":"","sources":["../../../../../../../libs/tools/api/src/lib/health/health-api.module.ts"],"names":[],"mappings":";;;;AAAA,yCAAyC;AACzC,2CAAsC;AACtC,2CAA4C;AAC5C,+CAAgD;AAEhD,2DAAqD;AAa9C,IAAM,eAAe,GAArB,MAAM,eAAe;CAC3B,CAAA;AADY,0CAAe;0BAAf,eAAe;IAV3B,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,yBAAc;YACpB,kBAAU;YACV,qBAAY;YACZ,eAAe;SAClB;QACD,WAAW,EAAE,CAAC,oCAAgB,CAAC;QAC/B,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACd,CAAC;GACW,eAAe,CAC3B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { HealthCheckService, HttpHealthIndicator } from '@nestjs/terminus';
|
|
3
|
+
export declare class HealthController {
|
|
4
|
+
private readonly health;
|
|
5
|
+
private http;
|
|
6
|
+
private readonly configService;
|
|
7
|
+
constructor(health: HealthCheckService, http: HttpHealthIndicator, configService: ConfigService);
|
|
8
|
+
check(): Promise<import("@nestjs/terminus").HealthCheckResult>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 config_1 = require("@nestjs/config");
|
|
7
|
+
const terminus_1 = require("@nestjs/terminus");
|
|
8
|
+
// import {
|
|
9
|
+
// HealthCheck,
|
|
10
|
+
// HealthCheckService,
|
|
11
|
+
// PrismaHealthIndicator,
|
|
12
|
+
// } from '@nestjs/terminus';
|
|
13
|
+
// import { PrismaService } from 'src/prisma/prisma.service';
|
|
14
|
+
let HealthController = class HealthController {
|
|
15
|
+
constructor(health, http, configService) {
|
|
16
|
+
this.health = health;
|
|
17
|
+
this.http = http;
|
|
18
|
+
this.configService = configService;
|
|
19
|
+
}
|
|
20
|
+
check() {
|
|
21
|
+
const keycloakHost = this.configService.get('KEYCLOAK_HOST');
|
|
22
|
+
return this.health.check([
|
|
23
|
+
() => this.http.pingCheck('Keycloak', `${keycloakHost}heatlh`),
|
|
24
|
+
// async () => this.prismaHealth.pingCheck('prisma', this.prisma),
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.HealthController = HealthController;
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, common_1.Get)(),
|
|
31
|
+
(0, terminus_1.HealthCheck)(),
|
|
32
|
+
tslib_1.__metadata("design:type", Function),
|
|
33
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
34
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
35
|
+
], HealthController.prototype, "check", null);
|
|
36
|
+
exports.HealthController = HealthController = tslib_1.__decorate([
|
|
37
|
+
(0, common_1.Controller)('health'),
|
|
38
|
+
tslib_1.__metadata("design:paramtypes", [terminus_1.HealthCheckService,
|
|
39
|
+
terminus_1.HttpHealthIndicator,
|
|
40
|
+
config_1.ConfigService])
|
|
41
|
+
], HealthController);
|
|
42
|
+
//# sourceMappingURL=health.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../../../../../../libs/tools/api/src/lib/health/health.controller.ts"],"names":[],"mappings":";;;;AAAA,2CAAiD;AACjD,2CAA+C;AAC/C,+CAI0B;AAE1B,WAAW;AACX,mBAAmB;AACnB,0BAA0B;AAC1B,6BAA6B;AAC7B,6BAA6B;AAC7B,6DAA6D;AAGtD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YACmB,MAA0B,EACnC,IAAyB,EAChB,aAA4B;QAF5B,WAAM,GAAN,MAAM,CAAoB;QACnC,SAAI,GAAJ,IAAI,CAAqB;QAChB,kBAAa,GAAb,aAAa,CAAe;IAG5C,CAAC;IAIJ,KAAK;QACH,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,eAAe,CAAE,CAAC;QAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACvB,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,YAAY,QAAQ,CAAC;YAC9D,kEAAkE;SACnE,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAlBY,4CAAgB;AAW3B;IAFC,IAAA,YAAG,GAAE;IACL,IAAA,sBAAW,GAAE;;;;6CAOb;2BAjBU,gBAAgB;IAD5B,IAAA,mBAAU,EAAC,QAAQ,CAAC;6CAGQ,6BAAkB;QAC7B,8BAAmB;QACD,sBAAa;GAJpC,gBAAgB,CAkB5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './health-api.module';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/tools/api/src/lib/health/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/tools/api/src/lib/logging/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConsoleLogger } from '@nestjs/common';
|
|
2
|
+
export declare class Logger extends ConsoleLogger {
|
|
3
|
+
static debug(context: string, message: string): void;
|
|
4
|
+
static log(context: string, message: string): void;
|
|
5
|
+
static error(context: string, message: string, trace?: any): void;
|
|
6
|
+
static warn(context: string, message: string): void;
|
|
7
|
+
private readonly _logger;
|
|
8
|
+
private static instance;
|
|
9
|
+
private constructor();
|
|
10
|
+
static init(): Logger;
|
|
11
|
+
debug(message: string, context: string): void;
|
|
12
|
+
log(message: string, context: string): void;
|
|
13
|
+
error(message: string, stack?: string, context?: string): void;
|
|
14
|
+
warn(message: string, context: string): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var Logger_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Logger = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const log4js = require("log4js");
|
|
8
|
+
let Logger = Logger_1 = class Logger extends common_1.ConsoleLogger {
|
|
9
|
+
static debug(context, message) {
|
|
10
|
+
// super.debug.apply(message, context);
|
|
11
|
+
Logger_1.instance.debug(message, context);
|
|
12
|
+
}
|
|
13
|
+
static log(context, message) {
|
|
14
|
+
// super.log(message, context);
|
|
15
|
+
console.log(message);
|
|
16
|
+
Logger_1.instance.log(`[${context}]`, message);
|
|
17
|
+
}
|
|
18
|
+
// tslint:disable-next-line:no-any
|
|
19
|
+
static error(context, message, trace) {
|
|
20
|
+
// add your tailored logic here
|
|
21
|
+
// super.error(message, trace);
|
|
22
|
+
console.error(message);
|
|
23
|
+
Logger_1.instance.error(`[${context}]`, message, trace);
|
|
24
|
+
}
|
|
25
|
+
static warn(context, message) {
|
|
26
|
+
// add your tailored logic here
|
|
27
|
+
// super.warn(message, context);
|
|
28
|
+
console.warn(message);
|
|
29
|
+
Logger_1.instance.warn(`[${context}]`, message);
|
|
30
|
+
}
|
|
31
|
+
constructor() {
|
|
32
|
+
super();
|
|
33
|
+
const logDir = process.env['LOG_DIR'] ?? 'logs';
|
|
34
|
+
console.log('logDir:', logDir);
|
|
35
|
+
log4js.configure({
|
|
36
|
+
appenders: { app: { type: "file", filename: `${logDir}/app.log` } },
|
|
37
|
+
categories: { default: { appenders: ["app"], level: "info" } },
|
|
38
|
+
});
|
|
39
|
+
this._logger = log4js.getLogger('app');
|
|
40
|
+
}
|
|
41
|
+
static init() {
|
|
42
|
+
if (!Logger_1.instance) {
|
|
43
|
+
Logger_1.instance = new Logger_1();
|
|
44
|
+
}
|
|
45
|
+
return Logger_1.instance;
|
|
46
|
+
}
|
|
47
|
+
debug(message, context) {
|
|
48
|
+
super.log(message, context);
|
|
49
|
+
this._logger.debug(`[${context}]`, message);
|
|
50
|
+
// this._logger.message(`[${context}]`, message);
|
|
51
|
+
}
|
|
52
|
+
log(message, context) {
|
|
53
|
+
super.log(message, context);
|
|
54
|
+
this._logger.log(`[${context}]`, message);
|
|
55
|
+
}
|
|
56
|
+
error(message, stack, context) {
|
|
57
|
+
// add your tailored logic here
|
|
58
|
+
super.error(message, stack, context);
|
|
59
|
+
this._logger.error(`[${context}]`, message, stack);
|
|
60
|
+
}
|
|
61
|
+
warn(message, context) {
|
|
62
|
+
// add your tailored logic here
|
|
63
|
+
super.warn(message, context);
|
|
64
|
+
this._logger.warn(`[${context}]`, message);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.Logger = Logger;
|
|
68
|
+
exports.Logger = Logger = Logger_1 = tslib_1.__decorate([
|
|
69
|
+
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
70
|
+
tslib_1.__metadata("design:paramtypes", [])
|
|
71
|
+
], Logger);
|
|
72
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../../../libs/tools/api/src/lib/logging/logger.ts"],"names":[],"mappings":";;;;;AAAA,2CAAgE;AAChE,iCAAiC;AAG1B,IAAM,MAAM,cAAZ,MAAM,MAAO,SAAQ,sBAAa;IAC9B,MAAM,CAAC,KAAK,CAAC,OAAe,EAAE,OAAe;QAChD,wCAAwC;QACxC,QAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAEM,MAAM,CAAC,GAAG,CAAC,OAAe,EAAE,OAAe;QAC9C,+BAA+B;QAC/B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;QACtB,QAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,kCAAkC;IAC3B,MAAM,CAAC,KAAK,CAAC,OAAe,EAAE,OAAe,EAAE,KAAW;QAC7D,+BAA+B;QAC/B,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