@cargolift-cdi/common 1.0.20 → 1.0.21
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/dist/errors/application.error.d.ts +1 -1
- package/dist/errors/application.error.js +2 -6
- package/dist/errors/application.error.js.map +1 -1
- package/dist/errors/base.error.js +1 -5
- package/dist/errors/base.error.js.map +1 -1
- package/dist/errors/business.error.d.ts +1 -1
- package/dist/errors/business.error.js +2 -6
- package/dist/errors/business.error.js.map +1 -1
- package/dist/errors/not-found-business.error.d.ts +2 -2
- package/dist/errors/not-found-business.error.js +2 -6
- package/dist/errors/not-found-business.error.js.map +1 -1
- package/dist/filters/api-exceptions.filter.d.ts +1 -1
- package/dist/filters/api-exceptions.filter.js +9 -12
- package/dist/filters/api-exceptions.filter.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -21
- package/dist/index.js.map +1 -1
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.js +4 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/logger.interface.d.ts +34 -0
- package/dist/logger/logger.interface.js +2 -0
- package/dist/logger/logger.interface.js.map +1 -0
- package/dist/logger/logger.module.d.ts +2 -0
- package/dist/logger/logger.module.js +19 -0
- package/dist/logger/logger.module.js.map +1 -0
- package/dist/logger/logger.service.d.ts +21 -0
- package/dist/logger/logger.service.js +137 -0
- package/dist/logger/logger.service.js.map +1 -0
- package/dist/middleware/api-logger.middleware.js +9 -12
- package/dist/middleware/api-logger.middleware.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -2
- package/dist/errors/generic-business.error.d.ts +0 -6
- package/dist/errors/generic-business.error.js +0 -17
- package/dist/errors/generic-business.error.js.map +0 -1
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ApplicationError = void 0;
|
|
4
|
-
const base_error_1 = require("./base.error");
|
|
5
|
-
class ApplicationError extends base_error_1.BaseError {
|
|
1
|
+
import { BaseError } from "./base.error.js";
|
|
2
|
+
export class ApplicationError extends BaseError {
|
|
6
3
|
constructor(message, code, options) {
|
|
7
4
|
super(message ?? "Generic Application error", code ?? "APPLICATION_ERROR", options);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.ApplicationError = ApplicationError;
|
|
11
7
|
//# sourceMappingURL=application.error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.error.js","sourceRoot":"","sources":["../../src/errors/application.error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"application.error.js","sourceRoot":"","sources":["../../src/errors/application.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAE1D,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAC7C,YAAY,OAAgB,EAAE,IAAa,EAAE,OAAsB;QACjE,KAAK,CAAC,OAAO,IAAI,2BAA2B,EAAE,IAAI,IAAI,mBAAmB,EAAE,OAAO,CAAC,CAAC;IACtF,CAAC;CACF"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseError = void 0;
|
|
4
|
-
class BaseError extends Error {
|
|
1
|
+
export class BaseError extends Error {
|
|
5
2
|
constructor(message, code, options) {
|
|
6
3
|
super(message);
|
|
7
4
|
this.code = code ?? "UnknownError";
|
|
@@ -37,5 +34,4 @@ class BaseError extends Error {
|
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
exports.BaseError = BaseError;
|
|
41
37
|
//# sourceMappingURL=base.error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.error.js","sourceRoot":"","sources":["../../src/errors/base.error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.error.js","sourceRoot":"","sources":["../../src/errors/base.error.ts"],"names":[],"mapp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CAAC;CACF"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BusinessError = void 0;
|
|
4
|
-
const base_error_1 = require("./base.error");
|
|
5
|
-
class BusinessError extends base_error_1.BaseError {
|
|
1
|
+
import { BaseError } from "./base.error.js";
|
|
2
|
+
export class BusinessError extends BaseError {
|
|
6
3
|
constructor(message, code, options) {
|
|
7
4
|
super(message ?? "Unknown Business error", code ?? "BUSINESS_ERROR", options);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.BusinessError = BusinessError;
|
|
11
7
|
//# sourceMappingURL=business.error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"business.error.js","sourceRoot":"","sources":["../../src/errors/business.error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"business.error.js","sourceRoot":"","sources":["../../src/errors/business.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAE1D,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,YAAY,OAAgB,EAAE,IAAa,EAAE,OAAsB;QACjE,KAAK,CAAC,OAAO,IAAI,wBAAwB,EAAE,IAAI,IAAI,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAChF,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorOptions } from "./base.error";
|
|
2
|
-
import { BusinessError } from "./business.error";
|
|
1
|
+
import { ErrorOptions } from "./base.error.js";
|
|
2
|
+
import { BusinessError } from "./business.error.js";
|
|
3
3
|
export declare class NotFoundBusinessError extends BusinessError {
|
|
4
4
|
constructor(message: string, resourceType: string, resourceId: string | number, options?: ErrorOptions);
|
|
5
5
|
get resourceType(): string | undefined;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.NotFoundBusinessError = void 0;
|
|
4
|
-
const business_error_1 = require("./business.error");
|
|
5
|
-
class NotFoundBusinessError extends business_error_1.BusinessError {
|
|
1
|
+
import { BusinessError } from "./business.error.js";
|
|
2
|
+
export class NotFoundBusinessError extends BusinessError {
|
|
6
3
|
constructor(message, resourceType, resourceId, options) {
|
|
7
4
|
super(message ?? `${resourceType} '${resourceId}' not found`, "BUSINESS_RESOURCE_NOT_FOUND", {
|
|
8
5
|
...options,
|
|
@@ -20,5 +17,4 @@ class NotFoundBusinessError extends business_error_1.BusinessError {
|
|
|
20
17
|
return this.data?.resourceId ?? undefined;
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
exports.NotFoundBusinessError = NotFoundBusinessError;
|
|
24
20
|
//# sourceMappingURL=not-found-business.error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not-found-business.error.js","sourceRoot":"","sources":["../../src/errors/not-found-business.error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"not-found-business.error.js","sourceRoot":"","sources":["../../src/errors/not-found-business.error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAe,EAAE,YAAoB,EAAE,UAA2B,EAAE,OAAsB;QACpG,KAAK,CACH,OAAO,IAAI,GAAG,YAAY,KAAK,UAAU,aAAa,EACtD,6BAA6B,EAC7B;YACE,GAAG,OAAO;YACV,IAAI,EAAE;gBACJ,YAAY;gBACZ,UAAU;gBACV,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;aACzB;SACF,CACF,CAAC;IACJ,CAAC;IAED,IAAI,YAAY;QACd,OAAQ,IAAI,CAAC,IAAI,EAAE,YAAuB,IAAI,SAAS,CAAC;IAC1D,CAAC;IAED,IAAI,UAAU;QACZ,OAAQ,IAAI,CAAC,IAAI,EAAE,UAA8B,IAAI,SAAS,CAAC;IACjE,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
2
|
-
import { LoggerContextService } from '
|
|
2
|
+
import { LoggerContextService } from '../logger/logger.service.js';
|
|
3
3
|
export declare class APIExceptionsFilter implements ExceptionFilter {
|
|
4
4
|
private readonly logger;
|
|
5
5
|
constructor(logger: LoggerContextService);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,10 +7,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
|
-
const util_logger_1 = require("@cargolift-cdi/util-logger");
|
|
10
|
+
import { Catch, HttpException, Logger, Injectable, Scope } from '@nestjs/common';
|
|
11
|
+
import { LoggerContextService } from '../logger/logger.service.js';
|
|
15
12
|
let APIExceptionsFilter = class APIExceptionsFilter {
|
|
16
13
|
constructor(logger) {
|
|
17
14
|
this.logger = logger;
|
|
@@ -34,7 +31,7 @@ let APIExceptionsFilter = class APIExceptionsFilter {
|
|
|
34
31
|
const ctx = host.switchToHttp();
|
|
35
32
|
const response = ctx.getResponse();
|
|
36
33
|
const request = ctx.getRequest();
|
|
37
|
-
const status = exception instanceof
|
|
34
|
+
const status = exception instanceof HttpException
|
|
38
35
|
? exception.getStatus()
|
|
39
36
|
: 500;
|
|
40
37
|
let errorMsg = '';
|
|
@@ -85,7 +82,7 @@ let APIExceptionsFilter = class APIExceptionsFilter {
|
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
84
|
else {
|
|
88
|
-
|
|
85
|
+
Logger.error(errorMsg + ': ' + exception?.response?.message || exception?.message || '' || exception?.err?.message || '', exception?.stack, 'APIExceptionsFilter');
|
|
89
86
|
}
|
|
90
87
|
response.status(status).json({
|
|
91
88
|
message: exception?.response?.message || errorMsg || 'Erro ao processar solicitação',
|
|
@@ -97,10 +94,10 @@ let APIExceptionsFilter = class APIExceptionsFilter {
|
|
|
97
94
|
});
|
|
98
95
|
}
|
|
99
96
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(
|
|
103
|
-
(
|
|
104
|
-
__metadata("design:paramtypes", [util_logger_1.LoggerContextService])
|
|
97
|
+
APIExceptionsFilter = __decorate([
|
|
98
|
+
Injectable({ scope: Scope.REQUEST }),
|
|
99
|
+
Catch(),
|
|
100
|
+
__metadata("design:paramtypes", [LoggerContextService])
|
|
105
101
|
], APIExceptionsFilter);
|
|
102
|
+
export { APIExceptionsFilter };
|
|
106
103
|
//# sourceMappingURL=api-exceptions.filter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-exceptions.filter.js","sourceRoot":"","sources":["../../src/filters/api-exceptions.filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-exceptions.filter.js","sourceRoot":"","sources":["../../src/filters/api-exceptions.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAmB,KAAK,EAAiB,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAK5D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC5B,YAA6B,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;IACzD,CAAC;IAEO,UAAU,CAAC,KAAK;QACpB,QAAO,KAAK,EAAE,IAAI,EAAE,CAAC;YACjB,K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E,IAAI,SAAS,EAAE,GAAG,EAAE,OAAO,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACtJ,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,OAAO,IAAI,SAAS,EAAE,OAAO,IAAI,EAAE,IAAI,SAAS,EAAE,GAAG,EAAE,OAAO,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAC9I,CAAC;QACL,CAAC;aAAM,CAAC;YAEJ,MAAM,CAAC,KAAK,CACR,QAAQ,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,OAAO,IAAI,SAAS,EAAE,OAAO,IAAI,EAAE,IAAI,SAAS,EAAE,GAAG,EAAE,OAAO,IAAI,EAAE,EAC3G,SAAS,EAAE,KAAK,EAChB,qBAAqB,CACxB,CAAC;QACN,CAAC;QAGD,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YACzB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,IAAI,QAAQ,IAAI,+BAA+B;YACpF,KAAK,EAAE;gBACH,UAAU,EAAE,MAAM;gBAClB,IAAI,EAAE,OAAO,CAAC,GAAG;gBACjB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACtC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AArHY,mBAAmB;IAF/B,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IACpC,KAAK,EAAE;qCAEiC,oBAAoB;GADhD,mBAAmB,CAqH/B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export * from "./filters/api-exceptions.filter";
|
|
2
|
-
export * from './middleware/api-logger.middleware';
|
|
3
|
-
export * from "./errors/business.error";
|
|
4
|
-
export * from "./errors/not-found-business.error";
|
|
5
|
-
export * from "./errors/application.error";
|
|
1
|
+
export * from "./filters/api-exceptions.filter.js";
|
|
2
|
+
export * from './middleware/api-logger.middleware.js';
|
|
3
|
+
export * from "./errors/business.error.js";
|
|
4
|
+
export * from "./errors/not-found-business.error.js";
|
|
5
|
+
export * from "./errors/application.error.js";
|
|
6
|
+
export * from './logger/logger.service.js';
|
|
7
|
+
export * from './logger/logger.module.js';
|
|
8
|
+
export * from './logger/logger.interface.js';
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./filters/api-exceptions.filter"), exports);
|
|
18
|
-
__exportStar(require("./middleware/api-logger.middleware"), exports);
|
|
19
|
-
__exportStar(require("./errors/business.error"), exports);
|
|
20
|
-
__exportStar(require("./errors/not-found-business.error"), exports);
|
|
21
|
-
__exportStar(require("./errors/application.error"), exports);
|
|
1
|
+
export * from "./filters/api-exceptions.filter.js";
|
|
2
|
+
export * from './middleware/api-logger.middleware.js';
|
|
3
|
+
export * from "./errors/business.error.js";
|
|
4
|
+
export * from "./errors/not-found-business.error.js";
|
|
5
|
+
export * from "./errors/application.error.js";
|
|
6
|
+
export * from './logger/logger.service.js';
|
|
7
|
+
export * from './logger/logger.module.js';
|
|
8
|
+
export * from './logger/logger.interface.js';
|
|
22
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,oCAAoC,CAAC;AAGnD,cAAc,uCAAuC,CAAC;AAGtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,+BAA+B,CAAC;AAG9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface ApplicationInfo {
|
|
2
|
+
name: string;
|
|
3
|
+
function?: string;
|
|
4
|
+
action?: string;
|
|
5
|
+
method?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CallerInfo {
|
|
8
|
+
type: 'user' | 'api' | 'system';
|
|
9
|
+
id?: string;
|
|
10
|
+
details?: {
|
|
11
|
+
name?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface LogTrace {
|
|
16
|
+
name?: string;
|
|
17
|
+
application: string;
|
|
18
|
+
function: string;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Error {
|
|
22
|
+
type: ErrorType;
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
stack_trace?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface LogContext {
|
|
28
|
+
correlation_id?: string;
|
|
29
|
+
trace?: LogTrace[];
|
|
30
|
+
application?: ApplicationInfo;
|
|
31
|
+
caller_info?: CallerInfo;
|
|
32
|
+
error?: Error;
|
|
33
|
+
}
|
|
34
|
+
export type ErrorType = 'business' | 'application' | 'none';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.interface.js","sourceRoot":"","sources":["../../src/logger/logger.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module, Global } from '@nestjs/common';
|
|
8
|
+
import { LoggerContextService } from './logger.service.js';
|
|
9
|
+
let LoggerModule = class LoggerModule {
|
|
10
|
+
};
|
|
11
|
+
LoggerModule = __decorate([
|
|
12
|
+
Global(),
|
|
13
|
+
Module({
|
|
14
|
+
providers: [LoggerContextService],
|
|
15
|
+
exports: [LoggerContextService],
|
|
16
|
+
})
|
|
17
|
+
], LoggerModule);
|
|
18
|
+
export { LoggerModule };
|
|
19
|
+
//# sourceMappingURL=logger.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.module.js","sourceRoot":"","sources":["../../src/logger/logger.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAQpD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,YAAY;IALxB,MAAM,EAAE;IACR,MAAM,CAAC;QACN,SAAS,EAAE,CAAC,oBAAoB,CAAC;QACjC,OAAO,EAAE,CAAC,oBAAoB,CAAC;KAChC,CAAC;GACW,YAAY,CAAG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LoggerService } from '@nestjs/common';
|
|
2
|
+
import { LogContext } from './logger.interface.js';
|
|
3
|
+
import type { RabbitMQMessage } from '@cargolift-cdi/types';
|
|
4
|
+
export declare class LoggerContextService implements LoggerService {
|
|
5
|
+
private pinoLogger;
|
|
6
|
+
private context;
|
|
7
|
+
constructor();
|
|
8
|
+
setDefaultContext(req?: any, rabbitMQMessage?: RabbitMQMessage): void;
|
|
9
|
+
setContextRequest(req: any): void;
|
|
10
|
+
setContextRabbitMQ(rabbitMQMessage: RabbitMQMessage): void;
|
|
11
|
+
setContext(context?: LogContext, req?: any, rabbitMQMessage?: RabbitMQMessage): void;
|
|
12
|
+
getContext(): Partial<LogContext>;
|
|
13
|
+
isContextSet(): boolean;
|
|
14
|
+
private buildLog;
|
|
15
|
+
info(message: string, extraContext?: Record<string, any>): void;
|
|
16
|
+
debug(message: string, extraContext?: Record<string, any>): void;
|
|
17
|
+
log(message: string, extraContext?: Record<string, any>): void;
|
|
18
|
+
error(message: string, error?: Record<string, any>, extraContext?: Record<string, any>): void;
|
|
19
|
+
warn(message: any, ...optionalParams: any[]): void;
|
|
20
|
+
businessError(message: string, extraContext?: Record<string, any>): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Injectable, Scope } from '@nestjs/common';
|
|
11
|
+
import pino from 'pino';
|
|
12
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
13
|
+
let LoggerContextService = class LoggerContextService {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.context = {};
|
|
16
|
+
const transportOptions = {
|
|
17
|
+
target: 'pino-pretty',
|
|
18
|
+
options: {
|
|
19
|
+
colorize: true,
|
|
20
|
+
translateTime: 'SYS:dd/mm/yyyy HH:MM:ss.l',
|
|
21
|
+
ignore: process.env.LOG_DEBUG_IGNORE || 'pid,hostname,trace,correlation_id,application,message',
|
|
22
|
+
messageFormat: "{message}",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
this.pinoLogger = pino({
|
|
26
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
27
|
+
transport: process.env.NODE_ENV === 'development' ? transportOptions : undefined,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
setDefaultContext(req, rabbitMQMessage) {
|
|
31
|
+
this.setContext(null, req, rabbitMQMessage);
|
|
32
|
+
}
|
|
33
|
+
setContextRequest(req) {
|
|
34
|
+
this.setContext(null, req);
|
|
35
|
+
}
|
|
36
|
+
setContextRabbitMQ(rabbitMQMessage) {
|
|
37
|
+
this.setContext(null, undefined, rabbitMQMessage);
|
|
38
|
+
}
|
|
39
|
+
setContext(context, req, rabbitMQMessage) {
|
|
40
|
+
let trace = [];
|
|
41
|
+
const xTrace = req?.headers?.['x-trace'] || rabbitMQMessage?.properties?.headers?.['x-trace'];
|
|
42
|
+
const xCorrelation = req?.correlationId || req?.headers?.['x-correlation-id'] || rabbitMQMessage?.properties?.headers?.['x-correlation-id'];
|
|
43
|
+
this.context = Object.assign(this.context, context);
|
|
44
|
+
this.context.correlation_id =
|
|
45
|
+
this.context.correlation_id ||
|
|
46
|
+
context?.correlation_id ||
|
|
47
|
+
xCorrelation ||
|
|
48
|
+
uuidv4();
|
|
49
|
+
if (!this.context.application) {
|
|
50
|
+
this.context.application = {
|
|
51
|
+
name: process.env.npm_package_name,
|
|
52
|
+
function: req?.originalUrl || req?.url || rabbitMQMessage?.fields?.routingKey || rabbitMQMessage?.properties?.headers?.pattern || 'unknown',
|
|
53
|
+
method: req?.method || undefined,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (xTrace) {
|
|
57
|
+
try {
|
|
58
|
+
const traceObj = typeof xTrace === 'string' ? JSON.parse(xTrace) : xTrace;
|
|
59
|
+
if (Array.isArray(traceObj)) {
|
|
60
|
+
for (const item of traceObj) {
|
|
61
|
+
if (item && typeof item === 'object') {
|
|
62
|
+
trace.push(item);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (typeof traceObj === 'object' && traceObj !== null) {
|
|
67
|
+
trace.push(traceObj);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
trace = [];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
trace.push({
|
|
75
|
+
application: this.context.application.name,
|
|
76
|
+
function: this.context.application.function,
|
|
77
|
+
timestamp: new Date().toISOString(),
|
|
78
|
+
});
|
|
79
|
+
this.context.trace = trace;
|
|
80
|
+
if (!this.context.trace)
|
|
81
|
+
this.context.trace = [];
|
|
82
|
+
if (req) {
|
|
83
|
+
req.correlationId = this.context.correlation_id;
|
|
84
|
+
req.logContext = { ...this.context };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
getContext() {
|
|
88
|
+
return { ...this.context };
|
|
89
|
+
}
|
|
90
|
+
isContextSet() {
|
|
91
|
+
return !!(this.context && this.context.application && this.context.correlation_id);
|
|
92
|
+
}
|
|
93
|
+
buildLog(message, logType, extraContext = {}) {
|
|
94
|
+
return {
|
|
95
|
+
message,
|
|
96
|
+
logType: logType,
|
|
97
|
+
...this.context,
|
|
98
|
+
...extraContext,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
info(message, extraContext) {
|
|
102
|
+
this.pinoLogger.info(this.buildLog(message, 'application', extraContext));
|
|
103
|
+
}
|
|
104
|
+
debug(message, extraContext) {
|
|
105
|
+
this.pinoLogger.debug(this.buildLog(message, 'application', extraContext));
|
|
106
|
+
}
|
|
107
|
+
log(message, extraContext) {
|
|
108
|
+
this.info(message, extraContext);
|
|
109
|
+
}
|
|
110
|
+
error(message, error, extraContext) {
|
|
111
|
+
let errorData = {};
|
|
112
|
+
if (error) {
|
|
113
|
+
try {
|
|
114
|
+
errorData = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)));
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
errorData = { error: 'Failed to serialize error object' };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.pinoLogger.error(this.buildLog(message, 'application', {
|
|
121
|
+
...extraContext,
|
|
122
|
+
error: errorData
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
warn(message, ...optionalParams) {
|
|
126
|
+
throw new Error('Method not implemented.');
|
|
127
|
+
}
|
|
128
|
+
businessError(message, extraContext) {
|
|
129
|
+
this.pinoLogger.error(this.buildLog(message, 'business', extraContext));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
LoggerContextService = __decorate([
|
|
133
|
+
Injectable({ scope: Scope.REQUEST }),
|
|
134
|
+
__metadata("design:paramtypes", [])
|
|
135
|
+
], LoggerContextService);
|
|
136
|
+
export { LoggerContextService };
|
|
137
|
+
//# sourceMappingURL=logger.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.service.js","sourceRoot":"","sources":["../../src/logger/logger.service.ts"],"names":[],"mappings":";;;;;;;;;AA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,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF,CAAA;AAzLY,oBAAoB;IADhC,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;;GACxB,oBAAoB,CAyLhC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,18 +7,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const common_1 = require("@nestjs/common");
|
|
15
|
-
const core_1 = require("@nestjs/core");
|
|
10
|
+
import { Injectable } from '@nestjs/common';
|
|
11
|
+
import { ModuleRef, ContextIdFactory } from '@nestjs/core';
|
|
12
|
+
import { LoggerContextService } from '../logger/logger.service.js';
|
|
16
13
|
let APILoggerMiddleware = class APILoggerMiddleware {
|
|
17
14
|
constructor(moduleRef) {
|
|
18
15
|
this.moduleRef = moduleRef;
|
|
19
16
|
}
|
|
20
17
|
async use(req, res, next) {
|
|
21
|
-
const contextId =
|
|
22
|
-
const logger = await this.moduleRef.resolve(
|
|
18
|
+
const contextId = ContextIdFactory.getByRequest(req);
|
|
19
|
+
const logger = await this.moduleRef.resolve(LoggerContextService, contextId, { strict: false });
|
|
23
20
|
const startHr = typeof process.hrtime.bigint === 'function' ? process.hrtime.bigint() : null;
|
|
24
21
|
try {
|
|
25
22
|
const url = req?.originalUrl || req?.url;
|
|
@@ -81,9 +78,9 @@ let APILoggerMiddleware = class APILoggerMiddleware {
|
|
|
81
78
|
return out;
|
|
82
79
|
}
|
|
83
80
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
(
|
|
87
|
-
__metadata("design:paramtypes", [core_1.ModuleRef])
|
|
81
|
+
APILoggerMiddleware = __decorate([
|
|
82
|
+
Injectable(),
|
|
83
|
+
__metadata("design:paramtypes", [ModuleRef])
|
|
88
84
|
], APILoggerMiddleware);
|
|
85
|
+
export { APILoggerMiddleware };
|
|
89
86
|
//# sourceMappingURL=api-logger.middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-logger.middleware.js","sourceRoot":"","sources":["../../src/middleware/api-logger.middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-logger.middleware.js","sourceRoot":"","sources":["../../src/middleware/api-logger.middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAkB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAG5D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAI,CAAC;IAEtD,KAAK,CAAC,GAAG,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAc;QAE1C,MAAM,SAAS,GAAG,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,oBAAoB,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAGhG,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC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