@onivoro/server-pino 24.14.0 → 24.16.0
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/package.json +9 -3
- package/jest.config.ts +0 -11
- package/project.json +0 -33
- package/src/index.ts +0 -5
- package/src/lib/classes/server-pino-config.class.ts +0 -68
- package/src/lib/functions/patch-console.function.ts +0 -47
- package/src/lib/server-pino.module.ts +0 -34
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onivoro/server-pino",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.16.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -9,12 +9,18 @@
|
|
|
9
9
|
"url": "https://github.com/onivoro/monorepo.git"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@onivoro/server-common": "24.
|
|
12
|
+
"@onivoro/server-common": "24.16.0",
|
|
13
13
|
"tslib": "^2.3.0"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"@nestjs/common": "~10.4.6",
|
|
17
17
|
"nestjs-pino": "~4.1.0",
|
|
18
18
|
"pino-http": "~10.3.0"
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"**/*.js",
|
|
22
|
+
"**/*.d.ts",
|
|
23
|
+
"**/*.js.map",
|
|
24
|
+
"README.md"
|
|
25
|
+
]
|
|
20
26
|
}
|
package/jest.config.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
export default {
|
|
3
|
-
displayName: 'lib-server-pino',
|
|
4
|
-
preset: '../../../jest.preset.js',
|
|
5
|
-
testEnvironment: 'node',
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
8
|
-
},
|
|
9
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
10
|
-
coverageDirectory: '../../../coverage/libs/server/pino',
|
|
11
|
-
};
|
package/project.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "lib-server-pino",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/server/pino/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"targets": {
|
|
7
|
-
"build": {
|
|
8
|
-
"executor": "@nx/js:tsc",
|
|
9
|
-
"outputs": ["{options.outputPath}"],
|
|
10
|
-
"options": {
|
|
11
|
-
"outputPath": "dist/libs/server/pino",
|
|
12
|
-
"main": "libs/server/pino/src/index.ts",
|
|
13
|
-
"tsConfig": "libs/server/pino/tsconfig.lib.json",
|
|
14
|
-
"assets": [
|
|
15
|
-
"libs/server/pino/README.md",
|
|
16
|
-
"libs/server/pino/package.json"
|
|
17
|
-
],
|
|
18
|
-
"declaration": true,
|
|
19
|
-
"updateBuildableProjectPackageJsonDependencies": true,
|
|
20
|
-
"rootDir": "libs/server/pino/src"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"publish": {
|
|
24
|
-
"executor": "@nx/js:npm",
|
|
25
|
-
"outputs": [],
|
|
26
|
-
"dependsOn": ["build"],
|
|
27
|
-
"options": {
|
|
28
|
-
"packageRoot": "dist/libs/server/pino"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"tags": []
|
|
33
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { RouteInfo, Type } from "@nestjs/common/interfaces";
|
|
2
|
-
import { randomUUID } from "crypto";
|
|
3
|
-
import { Params } from "nestjs-pino";
|
|
4
|
-
import { IncomingMessage, ServerResponse } from "node:http";
|
|
5
|
-
import { DestinationStream } from "pino";
|
|
6
|
-
import { Options } from "pino-http";
|
|
7
|
-
|
|
8
|
-
export const apiIdHeader = 'x-api-id';
|
|
9
|
-
export const apiKeyHeader = 'x-api-key';
|
|
10
|
-
|
|
11
|
-
export class ServerPinoConfig implements Params {
|
|
12
|
-
exclude?: (string | RouteInfo)[] | undefined;
|
|
13
|
-
pinoHttp?: Options<IncomingMessage, ServerResponse<IncomingMessage>, never> | DestinationStream | [Options<IncomingMessage, ServerResponse<IncomingMessage>, never>, DestinationStream] | undefined;
|
|
14
|
-
forRoutes?: (string | RouteInfo | Type<any>)[] | undefined;
|
|
15
|
-
renameContext?: string | undefined;
|
|
16
|
-
useExisting?: true | undefined;
|
|
17
|
-
|
|
18
|
-
constructor(overrides?: Partial<Params> & { excludeUrls?: (string | RegExp)[] }) {
|
|
19
|
-
const defaultValues = ServerPinoConfig.getDefaultParams(overrides?.excludeUrls);
|
|
20
|
-
|
|
21
|
-
Object.entries({ ...defaultValues, ...(overrides || {}) }).forEach(([key, value]) => {
|
|
22
|
-
(this as any)[key] = value;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
static getDefaultParams(excludeUrls: (string | RegExp)[] = ['/api/health']): Params {
|
|
27
|
-
return {
|
|
28
|
-
pinoHttp: {
|
|
29
|
-
autoLogging: {
|
|
30
|
-
ignore: !!excludeUrls.length
|
|
31
|
-
? (req) => excludeUrls.some(pattern =>
|
|
32
|
-
typeof pattern === 'string'
|
|
33
|
-
? req.url === pattern
|
|
34
|
-
: pattern instanceof RegExp
|
|
35
|
-
? pattern.test((req as any).url)
|
|
36
|
-
: false
|
|
37
|
-
)
|
|
38
|
-
: (req) => false,
|
|
39
|
-
},
|
|
40
|
-
genReqId: () => randomUUID(),
|
|
41
|
-
redact: [
|
|
42
|
-
'req.headers["accept"]',
|
|
43
|
-
'req.headers["accept-encoding"]',
|
|
44
|
-
'req.headers["accept-language"]',
|
|
45
|
-
'req.headers["authorization"]',
|
|
46
|
-
`req.headers["${apiIdHeader}"]`,
|
|
47
|
-
`req.headers["${apiKeyHeader}"]`,
|
|
48
|
-
'req.headers["cache-control"]',
|
|
49
|
-
'req.headers["connection"]',
|
|
50
|
-
'req.headers["cookie"]',
|
|
51
|
-
'req.headers["sec-ch-ua"]',
|
|
52
|
-
'req.headers["sec-ch-ua-mobile"]',
|
|
53
|
-
'req.headers["sec-ch-ua-platform"]',
|
|
54
|
-
'req.headers["sec-fetch-dest"]',
|
|
55
|
-
'req.headers["sec-fetch-mode"]',
|
|
56
|
-
'req.headers["sec-fetch-site"]',
|
|
57
|
-
'req.headers["sec-fetch-user"]',
|
|
58
|
-
'req.headers["cookie"]',
|
|
59
|
-
'res.headers["set-cookie"]',
|
|
60
|
-
'req.headers["upgrade-insecure-requests"]',
|
|
61
|
-
'req.headers["user-agent"]',
|
|
62
|
-
],
|
|
63
|
-
useLevel: 'info',
|
|
64
|
-
transport: undefined,
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { PinoLogger } from 'nestjs-pino';
|
|
2
|
-
|
|
3
|
-
export function patchConsole(logger: PinoLogger) {
|
|
4
|
-
const _console = logger;
|
|
5
|
-
|
|
6
|
-
const original = {
|
|
7
|
-
debug: console.debug,
|
|
8
|
-
error: console.error,
|
|
9
|
-
info: console.info,
|
|
10
|
-
log: console.log,
|
|
11
|
-
trace: console.trace,
|
|
12
|
-
warn: console.warn,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
console.debug = (...args) => {
|
|
16
|
-
_console.debug({msg: args});
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
console.error = (...args) => {
|
|
20
|
-
_console.error({msg: args});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
console.info = (...args) => {
|
|
24
|
-
_console.info({msg: args});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
console.log = (...args) => {
|
|
28
|
-
_console.info({msg: args});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
console.trace = (...args) => {
|
|
32
|
-
_console.trace({msg: args});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
console.warn = (...args) => {
|
|
36
|
-
_console.warn({msg: args});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
_console,
|
|
41
|
-
restore: () => {
|
|
42
|
-
Object.entries(original).forEach(([method, implementation]) => {
|
|
43
|
-
(console as any)[method] = implementation;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
2
|
-
import { LoggerModule, PinoLogger } from 'nestjs-pino';
|
|
3
|
-
import { ServerPinoConfig } from './classes/server-pino-config.class';
|
|
4
|
-
import { moduleFactory } from '@onivoro/server-common';
|
|
5
|
-
import { patchConsole } from './functions/patch-console.function';
|
|
6
|
-
|
|
7
|
-
@Module({})
|
|
8
|
-
export class ServerPinoModule {
|
|
9
|
-
static configure(config: ServerPinoConfig, patchConsoleInstance = false) {
|
|
10
|
-
|
|
11
|
-
if (patchConsoleInstance) {
|
|
12
|
-
patchConsole(new PinoLogger(config));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (process.env.NODE_ENV === 'production') {
|
|
16
|
-
console.log('prod')
|
|
17
|
-
return moduleFactory({
|
|
18
|
-
module: ServerPinoModule,
|
|
19
|
-
imports: [LoggerModule.forRoot(config)],
|
|
20
|
-
providers: [
|
|
21
|
-
{ provide: ServerPinoConfig, useValue: config },
|
|
22
|
-
]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return moduleFactory({
|
|
27
|
-
module: ServerPinoModule,
|
|
28
|
-
providers: [
|
|
29
|
-
{ provide: ServerPinoConfig, useValue: config },
|
|
30
|
-
]
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.server.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../../dist/out-tsc"
|
|
5
|
-
},
|
|
6
|
-
"files": [],
|
|
7
|
-
"include": [],
|
|
8
|
-
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "./tsconfig.lib.json"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"path": "./tsconfig.spec.json"
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
}
|
package/tsconfig.lib.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"types": [
|
|
5
|
-
"jest",
|
|
6
|
-
"node"
|
|
7
|
-
]
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"jest.config.ts",
|
|
11
|
-
"**/*.test.ts",
|
|
12
|
-
"**/*.spec.ts",
|
|
13
|
-
"**/*.test.tsx",
|
|
14
|
-
"**/*.spec.tsx",
|
|
15
|
-
"**/*.test.js",
|
|
16
|
-
"**/*.spec.js",
|
|
17
|
-
"**/*.test.jsx",
|
|
18
|
-
"**/*.spec.jsx",
|
|
19
|
-
"**/*.d.ts"
|
|
20
|
-
]
|
|
21
|
-
}
|