@onivoro/server-pino 24.16.0 → 24.19.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@onivoro/server-pino",
3
- "version": "24.16.0",
3
+ "version": "24.19.0",
4
4
  "type": "commonjs",
5
- "main": "./index.js",
6
- "types": "./index.d.ts",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/onivoro/monorepo.git"
10
10
  },
11
11
  "dependencies": {
12
- "@onivoro/server-common": "24.16.0",
12
+ "@onivoro/server-common": "24.19.0",
13
13
  "tslib": "^2.3.0"
14
14
  },
15
15
  "peerDependencies": {
@@ -23,4 +23,4 @@
23
23
  "**/*.js.map",
24
24
  "README.md"
25
25
  ]
26
- }
26
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './lib/classes/server-pino-config.class';
2
+ export * from './lib/functions/patch-console.function';
3
+ export * from './lib/server-pino.module';
4
+ //# sourceMappingURL=index.d.ts.map
package/src/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/classes/server-pino-config.class"), exports);
5
+ tslib_1.__exportStar(require("./lib/functions/patch-console.function"), exports);
6
+ tslib_1.__exportStar(require("./lib/server-pino.module"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/server/pino/src/index.ts"],"names":[],"mappings":";;;AAAA,iFAAuD;AAEvD,iFAAuD;AAEvD,mEAAyC"}
@@ -0,0 +1,19 @@
1
+ import { RouteInfo, Type } from "@nestjs/common/interfaces";
2
+ import { Params } from "nestjs-pino";
3
+ import { IncomingMessage, ServerResponse } from "node:http";
4
+ import { DestinationStream } from "pino";
5
+ import { Options } from "pino-http";
6
+ export declare const apiIdHeader = "x-api-id";
7
+ export declare const apiKeyHeader = "x-api-key";
8
+ export declare class ServerPinoConfig implements Params {
9
+ exclude?: (string | RouteInfo)[] | undefined;
10
+ pinoHttp?: Options<IncomingMessage, ServerResponse<IncomingMessage>, never> | DestinationStream | [Options<IncomingMessage, ServerResponse<IncomingMessage>, never>, DestinationStream] | undefined;
11
+ forRoutes?: (string | RouteInfo | Type<any>)[] | undefined;
12
+ renameContext?: string | undefined;
13
+ useExisting?: true | undefined;
14
+ constructor(overrides?: Partial<Params> & {
15
+ excludeUrls?: (string | RegExp)[];
16
+ });
17
+ static getDefaultParams(excludeUrls?: (string | RegExp)[]): Params;
18
+ }
19
+ //# sourceMappingURL=server-pino-config.class.d.ts.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerPinoConfig = exports.apiKeyHeader = exports.apiIdHeader = void 0;
4
+ const crypto_1 = require("crypto");
5
+ exports.apiIdHeader = 'x-api-id';
6
+ exports.apiKeyHeader = 'x-api-key';
7
+ class ServerPinoConfig {
8
+ exclude;
9
+ pinoHttp;
10
+ forRoutes;
11
+ renameContext;
12
+ useExisting;
13
+ constructor(overrides) {
14
+ const defaultValues = ServerPinoConfig.getDefaultParams(overrides?.excludeUrls);
15
+ Object.entries({ ...defaultValues, ...(overrides || {}) }).forEach(([key, value]) => {
16
+ this[key] = value;
17
+ });
18
+ }
19
+ static getDefaultParams(excludeUrls = ['/api/health']) {
20
+ return {
21
+ pinoHttp: {
22
+ autoLogging: {
23
+ ignore: !!excludeUrls.length
24
+ ? (req) => excludeUrls.some(pattern => typeof pattern === 'string'
25
+ ? req.url === pattern
26
+ : pattern instanceof RegExp
27
+ ? pattern.test(req.url)
28
+ : false)
29
+ : (req) => false,
30
+ },
31
+ genReqId: () => (0, crypto_1.randomUUID)(),
32
+ redact: [
33
+ 'req.headers["accept"]',
34
+ 'req.headers["accept-encoding"]',
35
+ 'req.headers["accept-language"]',
36
+ 'req.headers["authorization"]',
37
+ `req.headers["${exports.apiIdHeader}"]`,
38
+ `req.headers["${exports.apiKeyHeader}"]`,
39
+ 'req.headers["cache-control"]',
40
+ 'req.headers["connection"]',
41
+ 'req.headers["cookie"]',
42
+ 'req.headers["sec-ch-ua"]',
43
+ 'req.headers["sec-ch-ua-mobile"]',
44
+ 'req.headers["sec-ch-ua-platform"]',
45
+ 'req.headers["sec-fetch-dest"]',
46
+ 'req.headers["sec-fetch-mode"]',
47
+ 'req.headers["sec-fetch-site"]',
48
+ 'req.headers["sec-fetch-user"]',
49
+ 'req.headers["cookie"]',
50
+ 'res.headers["set-cookie"]',
51
+ 'req.headers["upgrade-insecure-requests"]',
52
+ 'req.headers["user-agent"]',
53
+ ],
54
+ useLevel: 'info',
55
+ transport: undefined,
56
+ }
57
+ };
58
+ }
59
+ }
60
+ exports.ServerPinoConfig = ServerPinoConfig;
61
+ //# sourceMappingURL=server-pino-config.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-pino-config.class.js","sourceRoot":"","sources":["../../../../../../../libs/server/pino/src/lib/classes/server-pino-config.class.ts"],"names":[],"mappings":";;;AACA,mCAAoC;AAMvB,QAAA,WAAW,GAAG,UAAU,CAAC;AACzB,QAAA,YAAY,GAAG,WAAW,CAAC;AAExC,MAAa,gBAAgB;IAC3B,OAAO,CAAsC;IAC7C,QAAQ,CAA4L;IACpM,SAAS,CAAkD;IAC3D,aAAa,CAAsB;IACnC,WAAW,CAAoB;IAE/B,YAAY,SAAmE;QAC7E,MAAM,aAAa,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAEhF,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,aAAa,EAAE,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,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ger: PinoLogger): {
3
+ _console: PinoLogger;
4
+ restore: () => void;
5
+ };
6
+ //# sourceMappingURL=patch-console.function.d.ts.map
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchConsole = patchConsole;
4
+ function patchConsole(logger) {
5
+ const _console = logger;
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
+ console.debug = (...args) => {
15
+ _console.debug({ msg: args });
16
+ };
17
+ console.error = (...args) => {
18
+ _console.error({ msg: args });
19
+ };
20
+ console.info = (...args) => {
21
+ _console.info({ msg: args });
22
+ };
23
+ console.log = (...args) => {
24
+ _console.info({ msg: args });
25
+ };
26
+ console.trace = (...args) => {
27
+ _console.trace({ msg: args });
28
+ };
29
+ console.warn = (...args) => {
30
+ _console.warn({ msg: args });
31
+ };
32
+ return {
33
+ _console,
34
+ restore: () => {
35
+ Object.entries(original).forEach(([method, implementation]) => {
36
+ console[method] = implementation;
37
+ });
38
+ }
39
+ };
40
+ }
41
+ //# sourceMappingURL=patch-console.function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch-console.function.js","sourceRoot":"","sources":["../../../../../../../libs/server/pino/src/lib/functions/patch-console.function.ts"],"names":[],"mappings":";;AAEA,oCA4CC;AA5CD,SAAgB,YAAY,CAAC,MAAkB;IAC3C,MAAM,QAAQ,GAAG,MAAM,CAAC;IAExB,MAAM,QAAQ,GAAG;QACb,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;KACrB,CAAC;IAEF,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI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PinoConfig, patchConsoleInstance?: boolean): any;
4
+ }
5
+ //# sourceMappingURL=server-pino.module.d.ts.map
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var ServerPinoModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ServerPinoModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const nestjs_pino_1 = require("nestjs-pino");
8
+ const server_pino_config_class_1 = require("./classes/server-pino-config.class");
9
+ const server_common_1 = require("@onivoro/server-common");
10
+ const patch_console_function_1 = require("./functions/patch-console.function");
11
+ let ServerPinoModule = ServerPinoModule_1 = class ServerPinoModule {
12
+ static configure(config, patchConsoleInstance = false) {
13
+ if (patchConsoleInstance) {
14
+ (0, patch_console_function_1.patchConsole)(new nestjs_pino_1.PinoLogger(config));
15
+ }
16
+ if (process.env.NODE_ENV === 'production') {
17
+ console.log('prod');
18
+ return (0, server_common_1.moduleFactory)({
19
+ module: ServerPinoModule_1,
20
+ imports: [nestjs_pino_1.LoggerModule.forRoot(config)],
21
+ providers: [
22
+ { provide: server_pino_config_class_1.ServerPinoConfig, useValue: config },
23
+ ]
24
+ });
25
+ }
26
+ return (0, server_common_1.moduleFactory)({
27
+ module: ServerPinoModule_1,
28
+ providers: [
29
+ { provide: server_pino_config_class_1.ServerPinoConfig, useValue: config },
30
+ ]
31
+ });
32
+ }
33
+ };
34
+ exports.ServerPinoModule = ServerPinoModule;
35
+ exports.ServerPinoModule = ServerPinoModule = ServerPinoModule_1 = tslib_1.__decorate([
36
+ (0, common_1.Module)({})
37
+ ], ServerPinoModule);
38
+ //# sourceMappingURL=server-pino.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-pino.module.js","sourceRoot":"","sources":["../../../../../../libs/server/pino/src/lib/server-pino.module.ts"],"names":[],"mappings":";;;;;AAAA,2CAAwC;AACxC,6CAAuD;AACvD,iFAAsE;AACtE,0DAAuD;AACvD,+EAAkE;AAG3D,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAC3B,MAAM,CAAC,SAAS,CAAC,MAAwB,EAAE,oBAAoB,GAAG,KAAK;QAErE,IAAI,oBAAoB,EAAE,CAAC;YACzB,IAAA,qCAAY,EAAC,IAAI,wBAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACb,OAAO,IAAA,6BAAa,EAAC;gBACnB,MAAM,EAAE,kBAAgB;gBACxB,OAAO,EAAE,CAAC,0BAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACvC,SAAS,EAAE;oBACT,EAAE,OAAO,EAAE,2CAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE;iBAChD;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAA,6BAAa,EAAC;YACnB,MAAM,EAAE,kBAAgB;YACxB,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,2CAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE;aAChD;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAzBY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,gBAAgB,CAyB5B"}