@cargolift-cdi/lib-common 0.0.54 → 0.0.56
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/__tests__/payload-util/payload-util.test.js +4 -4
- package/dist/__tests__/payload-util/payload-util.test.js.map +1 -1
- package/dist/auth/auth.guard.js +12 -1
- package/dist/auth/auth.guard.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/auth/user.decorator.d.ts +0 -1
- package/dist/auth/user.decorator.js +0 -6
- package/dist/auth/user.decorator.js.map +0 -1
- package/dist/errors/business.error.d.ts +0 -7
- package/dist/errors/business.error.js +0 -12
- package/dist/errors/business.error.js.map +0 -1
- package/dist/filters/api-exceptions.filter.d.ts +0 -8
- package/dist/filters/api-exceptions.filter.js +0 -113
- package/dist/filters/api-exceptions.filter.js.map +0 -1
- package/dist/middleware/api-logger.middleware.d.ts +0 -8
- package/dist/middleware/api-logger.middleware.js +0 -83
- package/dist/middleware/api-logger.middleware.js.map +0 -1
- package/dist/nestjs/filters/api-exceptions.filter.d.ts +0 -8
- package/dist/nestjs/filters/api-exceptions.filter.js +0 -113
- package/dist/nestjs/filters/api-exceptions.filter.js.map +0 -1
- package/dist/nestjs/middleware/api-logger.middleware.d.ts +0 -8
- package/dist/nestjs/middleware/api-logger.middleware.js +0 -83
- package/dist/nestjs/middleware/api-logger.middleware.js.map +0 -1
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const User: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.decorator.js","sourceRoot":"","sources":["../../src/auth/user.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;AAExE,MAAM,CAAC,MAAM,IAAI,GAAG,oBAAoB,CAAC,CAAC,IAAwB,EAAE,GAAqB,EAAE,EAAE;IAC3F,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAC5C,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;AAC5C,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BaseError, ErrorOptions } from "./base.error.js";
|
|
2
|
-
export declare class BusinessError extends BaseError {
|
|
3
|
-
constructor(message?: string, code?: string, options?: ErrorOptions);
|
|
4
|
-
}
|
|
5
|
-
export declare class BusinessFatalError extends BusinessError {
|
|
6
|
-
constructor(message?: string, code?: string, options?: ErrorOptions);
|
|
7
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseError } from "./base.error.js";
|
|
2
|
-
export class BusinessError extends BaseError {
|
|
3
|
-
constructor(message, code, options) {
|
|
4
|
-
super(message ?? "Unknown Business error", code ?? "BUSINESS_ERROR", { ...options, retryable: true });
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export class BusinessFatalError extends BusinessError {
|
|
8
|
-
constructor(message, code, options) {
|
|
9
|
-
super(message ?? "Unknown Business fatal error", code ?? "BUSINESS_FATAL_ERROR", { ...options, retryable: false });
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=business.error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"business.error.js","sourceRoot":"","sources":["../../src/errors/business.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAK1D,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,YAAY,OAAgB,EAAE,IAAa,EAAE,OAAsB;QACjE,KAAK,CAAC,OAAO,IAAI,wBAAwB,EAAE,IAAI,IAAI,gBAAgB,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxG,CAAC;CACF;AACD,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IACnD,YAAY,OAAgB,EAAE,IAAa,EAAE,OAAsB;QACjE,KAAK,CAAC,OAAO,IAAI,8BAA8B,EAAE,IAAI,IAAI,sBAAsB,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACrH,CAAC;CACF"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ExceptionFilter, ArgumentsHost } from "@nestjs/common";
|
|
2
|
-
import { LoggerContextService } from "../logger/logger.service.js";
|
|
3
|
-
export declare class APIExceptionsFilter implements ExceptionFilter {
|
|
4
|
-
private readonly logger;
|
|
5
|
-
constructor(logger: LoggerContextService);
|
|
6
|
-
private getMessage;
|
|
7
|
-
catch(exception: any, host: ArgumentsHost): void;
|
|
8
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
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 { Catch, HttpException, Logger, Injectable, Scope } from "@nestjs/common";
|
|
11
|
-
import { LoggerContextService } from "../logger/logger.service.js";
|
|
12
|
-
let APIExceptionsFilter = class APIExceptionsFilter {
|
|
13
|
-
constructor(logger) {
|
|
14
|
-
this.logger = logger;
|
|
15
|
-
}
|
|
16
|
-
getMessage(error) {
|
|
17
|
-
if (typeof error === "string") {
|
|
18
|
-
return error.split("\n")[0];
|
|
19
|
-
}
|
|
20
|
-
switch (error?.code) {
|
|
21
|
-
case "EHOSTUNREACH":
|
|
22
|
-
case "ECONNREFUSED":
|
|
23
|
-
case "ENETUNREACH":
|
|
24
|
-
case "ECONNRESET":
|
|
25
|
-
case "ETIMEDOUT":
|
|
26
|
-
case "ENOTFOUND":
|
|
27
|
-
return "Erro interno => " + error?.code || "Erro desconhecido";
|
|
28
|
-
case 406:
|
|
29
|
-
return "Erro interno => Operation failed: QueueDeclare; 406 (PRECONDITION-FAILED)";
|
|
30
|
-
}
|
|
31
|
-
return error?.message || "Erro interno inesperado #1";
|
|
32
|
-
}
|
|
33
|
-
catch(exception, host) {
|
|
34
|
-
const ctx = host.switchToHttp();
|
|
35
|
-
const response = ctx.getResponse();
|
|
36
|
-
const request = ctx.getRequest();
|
|
37
|
-
const status = exception instanceof HttpException ? exception.getStatus() : 500;
|
|
38
|
-
let errorMsg = "";
|
|
39
|
-
let errorCode = "";
|
|
40
|
-
let trace = "";
|
|
41
|
-
if (!exception) {
|
|
42
|
-
errorMsg = "Erro interno inesperado #2";
|
|
43
|
-
}
|
|
44
|
-
else if (typeof exception === "string") {
|
|
45
|
-
errorMsg = exception.split("\n")[0];
|
|
46
|
-
}
|
|
47
|
-
else if (exception?.response?.code) {
|
|
48
|
-
errorCode = exception?.response?.code;
|
|
49
|
-
trace = exception?.response?.stack || undefined;
|
|
50
|
-
errorMsg = this.getMessage(exception?.response);
|
|
51
|
-
}
|
|
52
|
-
else if (exception.err) {
|
|
53
|
-
errorCode = exception.err.code || exception.err?.status || "";
|
|
54
|
-
errorMsg = this.getMessage(exception.err);
|
|
55
|
-
}
|
|
56
|
-
else if (exception.message) {
|
|
57
|
-
errorCode = exception.code || exception?.status || "";
|
|
58
|
-
errorMsg = this.getMessage(exception);
|
|
59
|
-
}
|
|
60
|
-
else if (exception.toString && typeof exception.toString === "function") {
|
|
61
|
-
errorMsg = exception.toString();
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
try {
|
|
65
|
-
exception = JSON.stringify(exception);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
errorMsg = exception.toString();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (!trace) {
|
|
72
|
-
trace = exception?.response?.stack || exception?.stack || exception?.err?.stack || exception.response || exception.toString || undefined;
|
|
73
|
-
}
|
|
74
|
-
if (!this.logger.isContextSet()) {
|
|
75
|
-
this.logger?.setContextRequest(request || response);
|
|
76
|
-
}
|
|
77
|
-
const error = {
|
|
78
|
-
code: errorCode || (status >= 400 && status < 500 ? "BAD_REQUEST" : "INTERNAL_ERROR"),
|
|
79
|
-
message: exception?.response?.message || exception?.message || exception?.err?.message || "Erro interno inesperado #4",
|
|
80
|
-
stack_trace: trace,
|
|
81
|
-
cause: exception?.cause || null,
|
|
82
|
-
};
|
|
83
|
-
if (this.logger?.error) {
|
|
84
|
-
if (status >= 400 && status < 500) {
|
|
85
|
-
this.logger.businessError(errorMsg + ": " + exception?.response?.message || exception?.message || "" || exception?.err?.message || "", error);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
this.logger.error(errorMsg + ": " + exception?.response?.message || exception?.message || "" || exception?.err?.message || "", error);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
Logger.error(exception?.response?.message || exception?.message || exception?.err?.message || errorMsg, trace, "APIExceptionsFilter");
|
|
93
|
-
}
|
|
94
|
-
response.status(status).json({
|
|
95
|
-
message: status >= 400 && status < 500
|
|
96
|
-
? exception?.response?.message || errorMsg || "Erro interno ao processar solicitação"
|
|
97
|
-
: "Erro interno ao processar solicitação",
|
|
98
|
-
error: {
|
|
99
|
-
message: errorMsg,
|
|
100
|
-
statusCode: status,
|
|
101
|
-
path: request.url,
|
|
102
|
-
timestamp: new Date().toISOString(),
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
APIExceptionsFilter = __decorate([
|
|
108
|
-
Injectable({ scope: Scope.REQUEST }),
|
|
109
|
-
Catch(),
|
|
110
|
-
__metadata("design:paramtypes", [LoggerContextService])
|
|
111
|
-
], APIExceptionsFilter);
|
|
112
|
-
export { APIExceptionsFilter };
|
|
113
|
-
//# sourceMappingURL=api-exceptions.filter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;IAC9B,YAA6B,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;IAAG,CAAC;IAGrD,UAAU,CAAC,KAAK;QACtB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,CAAC;QACD,QAAQ,KAAK,EAAE,IAAI,EAAE,CAAC;YACpB,KAAK,cAAc,CAAC;YACpB,KAAK,cAAc,CAAC;YACpB,KAAK,aAAa,CAAC;YACnB,KAAK,YAAY,CAAC;YAClB,KAAK,WAAW,CAAC;YACjB,KAAK,WAAW;gBACd,OAAO,kBAAkB,GAAG,KAAK,EAAE,IAAI,IAAI,mBAAmB,CAAC;YAEjE,KAAK,GAAG;gBACN,OAAO,2EAA2E,CAAC;QACvF,CAAC;QACD,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;AArIY,mBAAmB;IAF/B,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IACpC,KAAK,EAAE;qCAE+B,oBAAoB;GAD9C,mBAAmB,CAqI/B"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
-
import { ModuleRef } from '@nestjs/core';
|
|
3
|
-
export declare class APILoggerMiddleware implements NestMiddleware {
|
|
4
|
-
private readonly moduleRef;
|
|
5
|
-
constructor(moduleRef: ModuleRef);
|
|
6
|
-
use(req: any, res: any, next: Function): Promise<void>;
|
|
7
|
-
private safeBody;
|
|
8
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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 } from '@nestjs/common';
|
|
11
|
-
import { ModuleRef, ContextIdFactory } from '@nestjs/core';
|
|
12
|
-
import { LoggerContextService } from '../logger/logger.service.js';
|
|
13
|
-
import { runWithLoggerContext } from '../logger/logger.async-context.js';
|
|
14
|
-
let APILoggerMiddleware = class APILoggerMiddleware {
|
|
15
|
-
constructor(moduleRef) {
|
|
16
|
-
this.moduleRef = moduleRef;
|
|
17
|
-
}
|
|
18
|
-
async use(req, res, next) {
|
|
19
|
-
req.timestamp_start = req.headers['x-request-start'] || (new Date()).toISOString();
|
|
20
|
-
const contextId = ContextIdFactory.getByRequest(req);
|
|
21
|
-
const logger = await this.moduleRef.resolve(LoggerContextService, contextId, { strict: false });
|
|
22
|
-
const startHr = typeof process.hrtime.bigint === 'function' ? process.hrtime.bigint() : null;
|
|
23
|
-
const url = req?.originalUrl || req?.url;
|
|
24
|
-
runWithLoggerContext({}, () => {
|
|
25
|
-
try {
|
|
26
|
-
if (!logger.isContextSet()) {
|
|
27
|
-
logger.setContextRequest(req);
|
|
28
|
-
}
|
|
29
|
-
logger.debug(`HTTP ${req?.method} ${url} [${res?.statusCode}] - Request received`, {
|
|
30
|
-
application: {
|
|
31
|
-
...logger.getContext().application || {},
|
|
32
|
-
action: 'request',
|
|
33
|
-
},
|
|
34
|
-
source: {
|
|
35
|
-
ip: req?.ip || req?.headers?.['x-forwarded-for'] || req?.connection?.remoteAddress || 'unknown',
|
|
36
|
-
user_agent: req?.headers?.['user-agent'] || 'unknown',
|
|
37
|
-
},
|
|
38
|
-
data: {
|
|
39
|
-
request: { method: req?.method, path: url },
|
|
40
|
-
payload: this.safeBody(req?.body),
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
res?.on?.('finish', () => {
|
|
44
|
-
const endHr = typeof process.hrtime.bigint === 'function' ? process.hrtime.bigint() : null;
|
|
45
|
-
const durationMs = startHr && endHr ? Number((endHr - startHr) / BigInt(1_000_000)) : undefined;
|
|
46
|
-
logger.debug(`HTTP ${req?.method} ${url} [${res?.statusCode}] - Response sent`, {
|
|
47
|
-
application: {
|
|
48
|
-
...logger.getContext().application || {},
|
|
49
|
-
action: 'response',
|
|
50
|
-
},
|
|
51
|
-
data: {
|
|
52
|
-
response: { statusCode: res?.statusCode, durationMs },
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
next();
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
safeBody(body) {
|
|
65
|
-
if (!body || typeof body !== 'object')
|
|
66
|
-
return body;
|
|
67
|
-
const redact = new Set(['password', 'senha', 'token', 'access_token', 'authorization']);
|
|
68
|
-
if (Array.isArray(body)) {
|
|
69
|
-
return body.slice(0, 20).map((item) => (typeof item === 'object' ? this.safeBody(item) : item));
|
|
70
|
-
}
|
|
71
|
-
const out = {};
|
|
72
|
-
for (const [k, v] of Object.entries(body)) {
|
|
73
|
-
out[k] = redact.has(k.toLowerCase()) ? '***' : (typeof v === 'object' && v !== null ? this.safeBody(v) : v);
|
|
74
|
-
}
|
|
75
|
-
return out;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
APILoggerMiddleware = __decorate([
|
|
79
|
-
Injectable(),
|
|
80
|
-
__metadata("design:paramtypes", [ModuleRef])
|
|
81
|
-
], APILoggerMiddleware);
|
|
82
|
-
export { APILoggerMiddleware };
|
|
83
|
-
//# sourceMappingURL=api-logger.middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AACnE,OAAO,EAAE,oBAAoB,EAAyC,MAAM,mCAAmC,CAAC;AAGzG,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;QAC1C,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,OAAO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,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAClG,CAAC;QACD,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9G,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AAnEY,mBAAmB;IAD/B,UAAU,EAAE;qCAE6B,SAAS;GADtC,mBAAmB,CAmE/B"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ExceptionFilter, ArgumentsHost } from "@nestjs/common";
|
|
2
|
-
import { LoggerContextService } from "../../logger/logger.service.js";
|
|
3
|
-
export declare class HTTPExceptionsFilter implements ExceptionFilter {
|
|
4
|
-
private readonly logger;
|
|
5
|
-
constructor(logger: LoggerContextService);
|
|
6
|
-
private getMessage;
|
|
7
|
-
catch(exception: any, host: ArgumentsHost): void;
|
|
8
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
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 { Catch, HttpException, Logger, Injectable, Scope } from "@nestjs/common";
|
|
11
|
-
import { LoggerContextService } from "../../logger/logger.service.js";
|
|
12
|
-
let HTTPExceptionsFilter = class HTTPExceptionsFilter {
|
|
13
|
-
constructor(logger) {
|
|
14
|
-
this.logger = logger;
|
|
15
|
-
}
|
|
16
|
-
getMessage(error) {
|
|
17
|
-
if (typeof error === "string") {
|
|
18
|
-
return error.split("\n")[0];
|
|
19
|
-
}
|
|
20
|
-
switch (error?.code) {
|
|
21
|
-
case "EHOSTUNREACH":
|
|
22
|
-
case "ECONNREFUSED":
|
|
23
|
-
case "ENETUNREACH":
|
|
24
|
-
case "ECONNRESET":
|
|
25
|
-
case "ETIMEDOUT":
|
|
26
|
-
case "ENOTFOUND":
|
|
27
|
-
return "Erro interno => " + error?.code || "Erro desconhecido";
|
|
28
|
-
case 406:
|
|
29
|
-
return "Erro interno => Operation failed: QueueDeclare; 406 (PRECONDITION-FAILED)";
|
|
30
|
-
}
|
|
31
|
-
return error?.message || "Erro interno inesperado #1";
|
|
32
|
-
}
|
|
33
|
-
catch(exception, host) {
|
|
34
|
-
const ctx = host.switchToHttp();
|
|
35
|
-
const response = ctx.getResponse();
|
|
36
|
-
const request = ctx.getRequest();
|
|
37
|
-
const status = exception instanceof HttpException ? exception.getStatus() : 500;
|
|
38
|
-
let errorMsg = "";
|
|
39
|
-
let errorCode = "";
|
|
40
|
-
let trace = "";
|
|
41
|
-
if (!exception) {
|
|
42
|
-
errorMsg = "Erro interno inesperado #2";
|
|
43
|
-
}
|
|
44
|
-
else if (typeof exception === "string") {
|
|
45
|
-
errorMsg = exception.split("\n")[0];
|
|
46
|
-
}
|
|
47
|
-
else if (exception?.response?.code) {
|
|
48
|
-
errorCode = exception?.response?.code;
|
|
49
|
-
trace = exception?.response?.stack || undefined;
|
|
50
|
-
errorMsg = this.getMessage(exception?.response);
|
|
51
|
-
}
|
|
52
|
-
else if (exception.err) {
|
|
53
|
-
errorCode = exception.err.code || exception.err?.status || "";
|
|
54
|
-
errorMsg = this.getMessage(exception.err);
|
|
55
|
-
}
|
|
56
|
-
else if (exception.message) {
|
|
57
|
-
errorCode = exception.code || exception?.status || "";
|
|
58
|
-
errorMsg = this.getMessage(exception);
|
|
59
|
-
}
|
|
60
|
-
else if (exception.toString && typeof exception.toString === "function") {
|
|
61
|
-
errorMsg = exception.toString();
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
try {
|
|
65
|
-
exception = JSON.stringify(exception);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
errorMsg = exception.toString();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (!trace) {
|
|
72
|
-
trace = exception?.response?.stack || exception?.stack || exception?.err?.stack || exception.response || exception.toString || undefined;
|
|
73
|
-
}
|
|
74
|
-
if (!this.logger.isContextSet()) {
|
|
75
|
-
this.logger?.setContextRequest(request || response);
|
|
76
|
-
}
|
|
77
|
-
const error = {
|
|
78
|
-
code: errorCode || (status >= 400 && status < 500 ? "BAD_REQUEST" : "INTERNAL_ERROR"),
|
|
79
|
-
message: exception?.response?.message || exception?.message || exception?.err?.message || "Erro interno inesperado #4",
|
|
80
|
-
stack_trace: trace,
|
|
81
|
-
cause: exception?.cause || null,
|
|
82
|
-
};
|
|
83
|
-
if (this.logger?.error) {
|
|
84
|
-
if (status >= 400 && status < 500) {
|
|
85
|
-
this.logger.businessError(errorMsg + ": " + exception?.response?.message || exception?.message || "" || exception?.err?.message || "", error);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
this.logger.error(errorMsg + ": " + exception?.response?.message || exception?.message || "" || exception?.err?.message || "", error);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
Logger.error(exception?.response?.message || exception?.message || exception?.err?.message || errorMsg, trace, "APIExceptionsFilter");
|
|
93
|
-
}
|
|
94
|
-
response.status(status).json({
|
|
95
|
-
message: status >= 400 && status < 500
|
|
96
|
-
? exception?.response?.message || errorMsg || "Erro interno ao processar solicitação"
|
|
97
|
-
: "Erro interno ao processar solicitação",
|
|
98
|
-
error: {
|
|
99
|
-
message: errorMsg,
|
|
100
|
-
statusCode: status,
|
|
101
|
-
path: request.url,
|
|
102
|
-
timestamp: new Date().toISOString(),
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
HTTPExceptionsFilter = __decorate([
|
|
108
|
-
Injectable({ scope: Scope.REQUEST }),
|
|
109
|
-
Catch(),
|
|
110
|
-
__metadata("design:paramtypes", [LoggerContextService])
|
|
111
|
-
], HTTPExceptionsFilter);
|
|
112
|
-
export { HTTPExceptionsFilter };
|
|
113
|
-
//# sourceMappingURL=api-exceptions.filter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-exceptions.filter.js","sourceRoot":"","sources":["../../../src/nestjs/filters/api-exceptions.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAmB,KAAK,EAAiB,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAyB,MAAM,gBAAgB,CAAC;AACxI,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAK/D,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;I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IAAI,SAAS,EAAE,GAAG,EAAE,OAAO,IAAI,QAAQ,EACzF,KAAK,EACL,qBAAqB,CACtB,CAAC;QACJ,CAAC;QAED,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YAC3B,OAAO,EACL,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;gBAC3B,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,IAAI,QAAQ,IAAI,uCAAuC;gBACrF,CAAC,CAAC,uCAAuC;YAC7C,KAAK,EAAE;gBACL,OAAO,EAAE,QAAQ;gBACjB,UAAU,EAAE,MAAM;gBAClB,IAAI,EAAE,OAAO,CAAC,GAAG;gBACjB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA5GY,oBAAoB;IAFhC,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IACpC,KAAK,EAAE;qCAE+B,oBAAoB;GAD9C,oBAAoB,CA4GhC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
-
import { ModuleRef } from '@nestjs/core';
|
|
3
|
-
export declare class APILoggerMiddleware implements NestMiddleware {
|
|
4
|
-
private readonly moduleRef;
|
|
5
|
-
constructor(moduleRef: ModuleRef);
|
|
6
|
-
use(req: any, res: any, next: Function): Promise<void>;
|
|
7
|
-
private safeBody;
|
|
8
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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 } from '@nestjs/common';
|
|
11
|
-
import { ModuleRef, ContextIdFactory } from '@nestjs/core';
|
|
12
|
-
import { LoggerContextService } from '../logger/logger.service.js';
|
|
13
|
-
import { runWithLoggerContext } from '../logger/logger.async-context.js';
|
|
14
|
-
let APILoggerMiddleware = class APILoggerMiddleware {
|
|
15
|
-
constructor(moduleRef) {
|
|
16
|
-
this.moduleRef = moduleRef;
|
|
17
|
-
}
|
|
18
|
-
async use(req, res, next) {
|
|
19
|
-
req.timestamp_start = req.headers['x-request-start'] || (new Date()).toISOString();
|
|
20
|
-
const contextId = ContextIdFactory.getByRequest(req);
|
|
21
|
-
const logger = await this.moduleRef.resolve(LoggerContextService, contextId, { strict: false });
|
|
22
|
-
const startHr = typeof process.hrtime.bigint === 'function' ? process.hrtime.bigint() : null;
|
|
23
|
-
const url = req?.originalUrl || req?.url;
|
|
24
|
-
runWithLoggerContext({}, () => {
|
|
25
|
-
try {
|
|
26
|
-
if (!logger.isContextSet()) {
|
|
27
|
-
logger.setContextRequest(req);
|
|
28
|
-
}
|
|
29
|
-
logger.debug(`HTTP ${req?.method} ${url} [${res?.statusCode}] - Request received`, {
|
|
30
|
-
application: {
|
|
31
|
-
...logger.getContext().application || {},
|
|
32
|
-
action: 'request',
|
|
33
|
-
},
|
|
34
|
-
source: {
|
|
35
|
-
ip: req?.ip || req?.headers?.['x-forwarded-for'] || req?.connection?.remoteAddress || 'unknown',
|
|
36
|
-
user_agent: req?.headers?.['user-agent'] || 'unknown',
|
|
37
|
-
},
|
|
38
|
-
data: {
|
|
39
|
-
request: { method: req?.method, path: url },
|
|
40
|
-
payload: this.safeBody(req?.body),
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
res?.on?.('finish', () => {
|
|
44
|
-
const endHr = typeof process.hrtime.bigint === 'function' ? process.hrtime.bigint() : null;
|
|
45
|
-
const durationMs = startHr && endHr ? Number((endHr - startHr) / BigInt(1_000_000)) : undefined;
|
|
46
|
-
logger.debug(`HTTP ${req?.method} ${url} [${res?.statusCode}] - Response sent`, {
|
|
47
|
-
application: {
|
|
48
|
-
...logger.getContext().application || {},
|
|
49
|
-
action: 'response',
|
|
50
|
-
},
|
|
51
|
-
data: {
|
|
52
|
-
response: { statusCode: res?.statusCode, durationMs },
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
next();
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
safeBody(body) {
|
|
65
|
-
if (!body || typeof body !== 'object')
|
|
66
|
-
return body;
|
|
67
|
-
const redact = new Set(['password', 'senha', 'token', 'access_token', 'authorization']);
|
|
68
|
-
if (Array.isArray(body)) {
|
|
69
|
-
return body.slice(0, 20).map((item) => (typeof item === 'object' ? this.safeBody(item) : item));
|
|
70
|
-
}
|
|
71
|
-
const out = {};
|
|
72
|
-
for (const [k, v] of Object.entries(body)) {
|
|
73
|
-
out[k] = redact.has(k.toLowerCase()) ? '***' : (typeof v === 'object' && v !== null ? this.safeBody(v) : v);
|
|
74
|
-
}
|
|
75
|
-
return out;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
APILoggerMiddleware = __decorate([
|
|
79
|
-
Injectable(),
|
|
80
|
-
__metadata("design:paramtypes", [ModuleRef])
|
|
81
|
-
], APILoggerMiddleware);
|
|
82
|
-
export { APILoggerMiddleware };
|
|
83
|
-
//# sourceMappingURL=api-logger.middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-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