rl-core-api 0.3.0 → 0.5.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/README.md +1 -1
- package/dist/core/auth/actor.interface.d.ts +4 -0
- package/dist/core/auth/actor.interface.js +2 -0
- package/dist/core/auth/permissionScope.util.d.ts +3 -0
- package/dist/core/auth/permissionScope.util.js +10 -0
- package/dist/core/config/env.schema.d.ts +3 -3
- package/dist/core/config/env.schema.js +3 -3
- package/dist/core/config/env.service.d.ts +1 -0
- package/dist/core/config/env.service.js +3 -0
- package/dist/core/context/auditContext.d.ts +1 -0
- package/dist/core/context/auditContext.js +8 -1
- package/dist/core/context/requestLog.context.d.ts +10 -0
- package/dist/core/context/requestLog.context.js +26 -0
- package/dist/core/database/migrations/1710000000000-InitialSchema.js +63 -36
- package/dist/core/database/migrations/{1786233600000-Notifications.d.ts → 1787270400000-GroupManager.d.ts} +1 -1
- package/dist/core/database/migrations/1787270400000-GroupManager.js +26 -0
- package/dist/core/database/migrations/index.js +2 -6
- package/dist/core/events/appEvent.enum.d.ts +19 -1
- package/dist/core/events/appEvent.enum.js +1 -0
- package/dist/core/filters/allExceptions.filter.d.ts +6 -0
- package/dist/core/filters/allExceptions.filter.js +47 -2
- package/dist/core/filters/appErrorCode.enum.d.ts +3 -1
- package/dist/core/filters/appErrorCode.enum.js +2 -0
- package/dist/core/query/parseFilter.util.js +6 -4
- package/dist/core/utils/ip.util.d.ts +1 -0
- package/dist/core/utils/ip.util.js +8 -0
- package/dist/core/websocket/baseGateway.d.ts +1 -0
- package/dist/core/websocket/baseGateway.js +3 -0
- package/dist/coreEntities.d.ts +2 -3
- package/dist/coreEntities.js +2 -4
- package/dist/features/audit/audit.module.js +5 -7
- package/dist/features/audit/domain/audit.service.d.ts +14 -17
- package/dist/features/audit/domain/audit.service.js +22 -35
- package/dist/features/audit/domain/classifyError.util.d.ts +1 -1
- package/dist/features/audit/domain/classifyError.util.js +8 -8
- package/dist/features/audit/domain/enums/errorType.enum.d.ts +9 -0
- package/dist/features/audit/domain/enums/errorType.enum.js +13 -0
- package/dist/features/audit/domain/enums/requestOutcome.enum.d.ts +5 -0
- package/dist/features/audit/domain/enums/requestOutcome.enum.js +9 -0
- package/dist/features/audit/domain/index.d.ts +2 -0
- package/dist/features/audit/domain/index.js +2 -0
- package/dist/features/audit/infra/auditData.subscriber.js +21 -12
- package/dist/features/audit/infra/index.d.ts +2 -4
- package/dist/features/audit/infra/index.js +2 -4
- package/dist/features/audit/infra/repositories/requestLog.repository.d.ts +7 -0
- package/dist/features/audit/infra/repositories/{auditChange.repository.js → requestLog.repository.js} +10 -10
- package/dist/features/audit/infra/schema/auditDataChange.schema.d.ts +3 -3
- package/dist/features/audit/infra/schema/auditDataChange.schema.js +8 -7
- package/dist/features/audit/infra/schema/requestLog.schema.d.ts +20 -0
- package/dist/features/audit/infra/schema/requestLog.schema.js +92 -0
- package/dist/features/audit/presentation/audit.controller.d.ts +4 -8
- package/dist/features/audit/presentation/audit.controller.js +8 -31
- package/dist/features/audit/presentation/audit.interceptor.d.ts +5 -1
- package/dist/features/audit/presentation/audit.interceptor.js +53 -28
- package/dist/features/audit/presentation/decorators/auditable.decorator.d.ts +10 -0
- package/dist/features/audit/presentation/decorators/auditable.decorator.js +10 -0
- package/dist/features/audit/presentation/filters/audit.filters.d.ts +1 -2
- package/dist/features/audit/presentation/filters/audit.filters.js +65 -49
- package/dist/features/audit/presentation/httpError.listener.d.ts +8 -0
- package/dist/features/audit/presentation/httpError.listener.js +61 -0
- package/dist/features/audit/presentation/index.d.ts +3 -0
- package/dist/features/audit/presentation/index.js +3 -0
- package/dist/features/audit/presentation/responses/auditDataChange.response.js +1 -1
- package/dist/features/audit/presentation/responses/log.response.d.ts +12 -27
- package/dist/features/audit/presentation/responses/log.response.js +66 -88
- package/dist/features/audit/presentation/userRolesChanged.listener.d.ts +7 -0
- package/dist/features/audit/presentation/userRolesChanged.listener.js +43 -0
- package/dist/features/auth/domain/auth.service.d.ts +7 -4
- package/dist/features/auth/domain/auth.service.js +22 -4
- package/dist/features/auth/domain/twoFactor.service.d.ts +2 -0
- package/dist/features/auth/domain/twoFactor.service.js +7 -2
- package/dist/features/auth/infra/schema/authToken.schema.d.ts +5 -5
- package/dist/features/auth/infra/schema/authToken.schema.js +7 -7
- package/dist/features/auth/presentation/auth.controller.d.ts +2 -5
- package/dist/features/auth/presentation/auth.controller.js +11 -0
- package/dist/features/maintenance/domain/cleanup.service.d.ts +1 -4
- package/dist/features/maintenance/domain/cleanup.service.js +1 -26
- package/dist/features/maintenance/maintenance.module.js +1 -2
- package/dist/features/notifications/domain/enums/channelType.enum.d.ts +5 -5
- package/dist/features/notifications/domain/enums/channelType.enum.js +5 -5
- package/dist/features/notifications/domain/enums/deliveryStatus.enum.d.ts +6 -6
- package/dist/features/notifications/domain/enums/deliveryStatus.enum.js +6 -6
- package/dist/features/notifications/domain/enums/notificationType.enum.d.ts +4 -4
- package/dist/features/notifications/domain/enums/notificationType.enum.js +4 -4
- package/dist/features/notifications/domain/enums/scopeType.enum.d.ts +3 -3
- package/dist/features/notifications/domain/enums/scopeType.enum.js +3 -3
- package/dist/features/notifications/infra/schema/notification.schema.js +2 -2
- package/dist/features/notifications/infra/schema/notificationScope.schema.js +2 -2
- package/dist/features/notifications/presentation/commands/createNotification.command.js +2 -2
- package/dist/features/notifications/presentation/domainEvents.listener.d.ts +5 -2
- package/dist/features/notifications/presentation/domainEvents.listener.js +24 -2
- package/dist/features/notifications/presentation/responses/notification.response.js +1 -1
- package/dist/features/rbac/domain/rbac.catalog.js +31 -2
- package/dist/features/rbac/domain/rbac.service.d.ts +1 -0
- package/dist/features/rbac/domain/rbac.service.js +14 -0
- package/dist/features/rbac/domain/teamScope.service.d.ts +15 -0
- package/dist/features/rbac/domain/teamScope.service.js +74 -0
- package/dist/features/rbac/infra/repositories/group.repository.d.ts +2 -0
- package/dist/features/rbac/infra/repositories/group.repository.js +26 -0
- package/dist/features/rbac/infra/schema/group.schema.d.ts +1 -0
- package/dist/features/rbac/infra/schema/group.schema.js +5 -0
- package/dist/features/rbac/presentation/commands/createGroup.command.d.ts +1 -0
- package/dist/features/rbac/presentation/commands/createGroup.command.js +7 -0
- package/dist/features/rbac/presentation/rbac.controller.d.ts +1 -0
- package/dist/features/rbac/presentation/rbac.controller.js +16 -0
- package/dist/features/rbac/presentation/responses/rbac.response.d.ts +1 -0
- package/dist/features/rbac/presentation/responses/rbac.response.js +4 -0
- package/dist/features/rbac/rbac.module.js +3 -0
- package/dist/features/users/domain/users.service.d.ts +16 -8
- package/dist/features/users/domain/users.service.js +72 -14
- package/dist/features/users/infra/repositories/user.repository.d.ts +1 -1
- package/dist/features/users/infra/repositories/user.repository.js +9 -1
- package/dist/features/users/presentation/commands/createUser.command.d.ts +1 -0
- package/dist/features/users/presentation/commands/createUser.command.js +8 -0
- package/dist/features/users/presentation/filters/users.filters.js +8 -0
- package/dist/features/users/presentation/users.controller.d.ts +5 -5
- package/dist/features/users/presentation/users.controller.js +38 -27
- package/dist/features/users/users.module.js +2 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +14 -6
- package/package.json +1 -1
- package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.d.ts +0 -6
- package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.js +0 -19
- package/dist/core/database/migrations/1786147200000-PermanentAccountLock.d.ts +0 -6
- package/dist/core/database/migrations/1786147200000-PermanentAccountLock.js +0 -15
- package/dist/core/database/migrations/1786233600000-Notifications.js +0 -59
- package/dist/features/audit/infra/repositories/auditChange.repository.d.ts +0 -7
- package/dist/features/audit/infra/repositories/errorLog.repository.d.ts +0 -7
- package/dist/features/audit/infra/repositories/errorLog.repository.js +0 -35
- package/dist/features/audit/infra/schema/auditChange.schema.d.ts +0 -14
- package/dist/features/audit/infra/schema/auditChange.schema.js +0 -68
- package/dist/features/audit/infra/schema/errorLog.schema.d.ts +0 -21
- package/dist/features/audit/infra/schema/errorLog.schema.js +0 -69
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
2
3
|
import { Observable } from "rxjs";
|
|
4
|
+
import { EnvService } from "../../../core/config/env.service";
|
|
3
5
|
import { AuditService } from "../domain/audit.service";
|
|
4
6
|
export declare class AuditInterceptor implements NestInterceptor {
|
|
5
7
|
private readonly audit;
|
|
6
|
-
|
|
8
|
+
private readonly env;
|
|
9
|
+
private readonly reflector;
|
|
10
|
+
constructor(audit: AuditService, env: EnvService, reflector: Reflector);
|
|
7
11
|
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
8
12
|
}
|
|
@@ -12,15 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AuditInterceptor = void 0;
|
|
13
13
|
const node_crypto_1 = require("node:crypto");
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
+
const core_1 = require("@nestjs/core");
|
|
15
16
|
const rxjs_1 = require("rxjs");
|
|
17
|
+
const env_service_1 = require("../../../core/config/env.service");
|
|
16
18
|
const auditContext_1 = require("../../../core/context/auditContext");
|
|
19
|
+
const requestLog_context_1 = require("../../../core/context/requestLog.context");
|
|
17
20
|
const ip_util_1 = require("../../../core/utils/ip.util");
|
|
18
21
|
const audit_service_1 = require("../domain/audit.service");
|
|
19
|
-
const
|
|
22
|
+
const requestOutcome_enum_1 = require("../domain/enums/requestOutcome.enum");
|
|
23
|
+
const auditable_decorator_1 = require("./decorators/auditable.decorator");
|
|
20
24
|
const REQUEST_ID_HEADER = "x-request-id";
|
|
21
25
|
let AuditInterceptor = class AuditInterceptor {
|
|
22
|
-
constructor(audit) {
|
|
26
|
+
constructor(audit, env, reflector) {
|
|
23
27
|
this.audit = audit;
|
|
28
|
+
this.env = env;
|
|
29
|
+
this.reflector = reflector;
|
|
24
30
|
}
|
|
25
31
|
intercept(context, next) {
|
|
26
32
|
const req = context.switchToHttp().getRequest();
|
|
@@ -32,41 +38,58 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
32
38
|
const requestId = req.headers[REQUEST_ID_HEADER] || (0, node_crypto_1.randomUUID)();
|
|
33
39
|
res.setHeader("X-Request-Id", requestId);
|
|
34
40
|
req.requestId = requestId;
|
|
41
|
+
const auditable = this.reflector.getAllAndOverride(auditable_decorator_1.AUDITABLE_KEY, [context.getHandler(), context.getClass()]);
|
|
42
|
+
const action = auditable
|
|
43
|
+
? (auditable.action ?? `${method} ${req.path}`)
|
|
44
|
+
: null;
|
|
45
|
+
const logContext = { action, startedAt: start, userId: user?.id ?? null };
|
|
46
|
+
(0, requestLog_context_1.setRequestLogContext)(req, logContext);
|
|
35
47
|
res.once("finish", () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
const durationMs = Date.now() - start;
|
|
49
|
+
if (res.statusCode >= 400) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const slow = durationMs >= this.env.get("AUDIT_SLOW_REQUEST_MS");
|
|
53
|
+
if (!action && !slow) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (action && !slow && !auditable.allowSystem && !logContext.userId) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
void this.audit.recordRequest({
|
|
60
|
+
outcome: requestOutcome_enum_1.RequestOutcome.SUCCESS,
|
|
61
|
+
action,
|
|
39
62
|
method,
|
|
40
63
|
path: req.path,
|
|
41
|
-
|
|
64
|
+
route: (0, requestLog_context_1.routePathOf)(req),
|
|
42
65
|
statusCode: res.statusCode,
|
|
66
|
+
durationMs,
|
|
67
|
+
userId: logContext.userId,
|
|
68
|
+
ipHash: (0, ip_util_1.hashIp)(ipAddress, this.env.auditIpSalt()) ?? null,
|
|
69
|
+
userAgent: req.headers["user-agent"]?.slice(0, 255) ?? null,
|
|
70
|
+
requestId,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
res.once("close", () => {
|
|
74
|
+
if (res.writableFinished) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
void this.audit.recordRequest({
|
|
78
|
+
outcome: requestOutcome_enum_1.RequestOutcome.ABORTED,
|
|
79
|
+
action,
|
|
80
|
+
method,
|
|
81
|
+
path: req.path,
|
|
82
|
+
route: (0, requestLog_context_1.routePathOf)(req),
|
|
43
83
|
durationMs: Date.now() - start,
|
|
84
|
+
userId: logContext.userId,
|
|
85
|
+
ipHash: (0, ip_util_1.hashIp)(ipAddress, this.env.auditIpSalt()) ?? null,
|
|
86
|
+
userAgent: req.headers["user-agent"]?.slice(0, 255) ?? null,
|
|
44
87
|
requestId,
|
|
45
88
|
});
|
|
46
89
|
});
|
|
47
90
|
return new rxjs_1.Observable((subscriber) => {
|
|
48
91
|
auditContext_1.auditContext.run({ userId: user?.id ?? null, ipAddress, requestId }, () => {
|
|
49
|
-
next
|
|
50
|
-
.handle()
|
|
51
|
-
.pipe((0, rxjs_1.tap)({
|
|
52
|
-
error: (err) => {
|
|
53
|
-
const status = err?.status ?? 500;
|
|
54
|
-
if (status >= 400) {
|
|
55
|
-
void this.audit.recordError({
|
|
56
|
-
statusCode: status,
|
|
57
|
-
type: (0, classifyError_util_1.classifyError)(err, status),
|
|
58
|
-
message: err?.message ?? "Erro desconhecido",
|
|
59
|
-
stack: err?.stack ?? null,
|
|
60
|
-
method,
|
|
61
|
-
path: req.path,
|
|
62
|
-
userId: user?.id ?? null,
|
|
63
|
-
ipAddress,
|
|
64
|
-
requestId,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
}))
|
|
69
|
-
.subscribe(subscriber);
|
|
92
|
+
next.handle().subscribe(subscriber);
|
|
70
93
|
});
|
|
71
94
|
});
|
|
72
95
|
}
|
|
@@ -74,5 +97,7 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
74
97
|
exports.AuditInterceptor = AuditInterceptor;
|
|
75
98
|
exports.AuditInterceptor = AuditInterceptor = __decorate([
|
|
76
99
|
(0, common_1.Injectable)(),
|
|
77
|
-
__metadata("design:paramtypes", [audit_service_1.AuditService
|
|
100
|
+
__metadata("design:paramtypes", [audit_service_1.AuditService,
|
|
101
|
+
env_service_1.EnvService,
|
|
102
|
+
core_1.Reflector])
|
|
78
103
|
], AuditInterceptor);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CustomDecorator } from "@nestjs/common";
|
|
2
|
+
export declare const AUDITABLE_KEY = "auditable";
|
|
3
|
+
export interface AuditableOptions {
|
|
4
|
+
allowSystem?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface AuditableMetadata {
|
|
7
|
+
action: string | null;
|
|
8
|
+
allowSystem: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const Auditable: (action?: string, options?: AuditableOptions) => CustomDecorator<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auditable = exports.AUDITABLE_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.AUDITABLE_KEY = "auditable";
|
|
6
|
+
const Auditable = (action, options) => (0, common_1.SetMetadata)(exports.AUDITABLE_KEY, {
|
|
7
|
+
action: action ?? null,
|
|
8
|
+
allowSystem: options?.allowSystem ?? false,
|
|
9
|
+
});
|
|
10
|
+
exports.Auditable = Auditable;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { FilterCatalog } from "../../../../core/query/filterField.interface";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const ERROR_LOGS_FILTER_CATALOG: FilterCatalog;
|
|
2
|
+
export declare const REQUEST_LOGS_FILTER_CATALOG: FilterCatalog;
|
|
4
3
|
export declare const AUDIT_DATA_CHANGES_FILTER_CATALOG: FilterCatalog;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AUDIT_DATA_CHANGES_FILTER_CATALOG = exports.
|
|
3
|
+
exports.AUDIT_DATA_CHANGES_FILTER_CATALOG = exports.REQUEST_LOGS_FILTER_CATALOG = void 0;
|
|
4
4
|
const filterFieldType_enum_1 = require("../../../../core/query/filterFieldType.enum");
|
|
5
|
+
const errorType_enum_1 = require("../../domain/enums/errorType.enum");
|
|
6
|
+
const requestOutcome_enum_1 = require("../../domain/enums/requestOutcome.enum");
|
|
5
7
|
const auditDataChange_schema_1 = require("../../infra/schema/auditDataChange.schema");
|
|
6
|
-
const errorLog_schema_1 = require("../../infra/schema/errorLog.schema");
|
|
7
8
|
const TRACKED_ENTITIES = [
|
|
8
9
|
"User",
|
|
9
10
|
"Role",
|
|
@@ -14,7 +15,35 @@ const TRACKED_ENTITIES = [
|
|
|
14
15
|
"Scope",
|
|
15
16
|
];
|
|
16
17
|
const optionsFromValues = (values) => values.map((value) => ({ value, label: value }));
|
|
17
|
-
|
|
18
|
+
const optionsFromEnum = (labels) => Object.entries(labels).map(([value, label]) => ({ value, label }));
|
|
19
|
+
const REQUEST_OUTCOME_LABELS = {
|
|
20
|
+
[requestOutcome_enum_1.RequestOutcome.SUCCESS]: "Sucesso",
|
|
21
|
+
[requestOutcome_enum_1.RequestOutcome.ERROR]: "Erro",
|
|
22
|
+
[requestOutcome_enum_1.RequestOutcome.ABORTED]: "Abortada",
|
|
23
|
+
};
|
|
24
|
+
const ERROR_TYPE_LABELS = {
|
|
25
|
+
[errorType_enum_1.ErrorType.VALIDATION]: "Validação",
|
|
26
|
+
[errorType_enum_1.ErrorType.AUTH]: "Autenticação",
|
|
27
|
+
[errorType_enum_1.ErrorType.NOT_FOUND]: "Não encontrado",
|
|
28
|
+
[errorType_enum_1.ErrorType.RATE_LIMIT]: "Limite de requisições",
|
|
29
|
+
[errorType_enum_1.ErrorType.DATABASE]: "Banco de dados",
|
|
30
|
+
[errorType_enum_1.ErrorType.INTEGRATION]: "Integração",
|
|
31
|
+
[errorType_enum_1.ErrorType.INTERNAL]: "Interno",
|
|
32
|
+
};
|
|
33
|
+
const AUDIT_DATA_ACTION_LABELS = {
|
|
34
|
+
[auditDataChange_schema_1.AuditDataAction.CREATE]: "Criação",
|
|
35
|
+
[auditDataChange_schema_1.AuditDataAction.UPDATE]: "Alteração",
|
|
36
|
+
[auditDataChange_schema_1.AuditDataAction.DELETE]: "Exclusão",
|
|
37
|
+
};
|
|
38
|
+
exports.REQUEST_LOGS_FILTER_CATALOG = [
|
|
39
|
+
{
|
|
40
|
+
field: "outcome",
|
|
41
|
+
column: "outcome",
|
|
42
|
+
label: "Desfecho",
|
|
43
|
+
type: filterFieldType_enum_1.FilterFieldType.Enum,
|
|
44
|
+
options: optionsFromEnum(REQUEST_OUTCOME_LABELS),
|
|
45
|
+
sortable: true,
|
|
46
|
+
},
|
|
18
47
|
{
|
|
19
48
|
field: "action",
|
|
20
49
|
column: "action",
|
|
@@ -27,29 +56,28 @@ exports.AUDIT_CHANGES_FILTER_CATALOG = [
|
|
|
27
56
|
column: "method",
|
|
28
57
|
label: "Método",
|
|
29
58
|
type: filterFieldType_enum_1.FilterFieldType.Enum,
|
|
30
|
-
options: optionsFromValues([
|
|
31
|
-
"GET",
|
|
32
|
-
"POST",
|
|
33
|
-
"PATCH",
|
|
34
|
-
"PUT",
|
|
35
|
-
"DELETE",
|
|
36
|
-
]),
|
|
59
|
+
options: optionsFromValues(["GET", "POST", "PATCH", "PUT", "DELETE"]),
|
|
37
60
|
sortable: true,
|
|
38
61
|
},
|
|
39
62
|
{
|
|
40
|
-
field: "
|
|
41
|
-
column: "
|
|
63
|
+
field: "route",
|
|
64
|
+
column: "route",
|
|
42
65
|
label: "Rota",
|
|
43
66
|
type: filterFieldType_enum_1.FilterFieldType.Text,
|
|
44
67
|
sortable: true,
|
|
45
68
|
},
|
|
69
|
+
{
|
|
70
|
+
field: "path",
|
|
71
|
+
column: "path",
|
|
72
|
+
label: "Caminho",
|
|
73
|
+
type: filterFieldType_enum_1.FilterFieldType.Text,
|
|
74
|
+
},
|
|
46
75
|
{
|
|
47
76
|
field: "statusCode",
|
|
48
77
|
column: "statusCode",
|
|
49
78
|
label: "Status HTTP",
|
|
50
79
|
type: filterFieldType_enum_1.FilterFieldType.Number,
|
|
51
80
|
sortable: true,
|
|
52
|
-
filterable: false,
|
|
53
81
|
},
|
|
54
82
|
{
|
|
55
83
|
field: "durationMs",
|
|
@@ -57,49 +85,24 @@ exports.AUDIT_CHANGES_FILTER_CATALOG = [
|
|
|
57
85
|
label: "Duração (ms)",
|
|
58
86
|
type: filterFieldType_enum_1.FilterFieldType.Number,
|
|
59
87
|
sortable: true,
|
|
60
|
-
filterable: false,
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
field: "userId",
|
|
64
|
-
column: "userId",
|
|
65
|
-
label: "Usuário",
|
|
66
|
-
type: filterFieldType_enum_1.FilterFieldType.Uuid,
|
|
67
88
|
},
|
|
68
|
-
];
|
|
69
|
-
exports.ERROR_LOGS_FILTER_CATALOG = [
|
|
70
89
|
{
|
|
71
|
-
field: "
|
|
72
|
-
column: "
|
|
73
|
-
label: "Tipo",
|
|
90
|
+
field: "errorType",
|
|
91
|
+
column: "errorType",
|
|
92
|
+
label: "Tipo do erro",
|
|
74
93
|
type: filterFieldType_enum_1.FilterFieldType.Enum,
|
|
75
|
-
options:
|
|
76
|
-
sortable: true,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
field: "statusCode",
|
|
80
|
-
column: "statusCode",
|
|
81
|
-
label: "Status HTTP",
|
|
82
|
-
type: filterFieldType_enum_1.FilterFieldType.Number,
|
|
83
|
-
sortable: true,
|
|
84
|
-
filterable: false,
|
|
94
|
+
options: optionsFromEnum(ERROR_TYPE_LABELS),
|
|
85
95
|
},
|
|
86
96
|
{
|
|
87
|
-
field: "
|
|
88
|
-
column: "
|
|
89
|
-
label: "
|
|
97
|
+
field: "errorCode",
|
|
98
|
+
column: "errorCode",
|
|
99
|
+
label: "Código do erro",
|
|
90
100
|
type: filterFieldType_enum_1.FilterFieldType.Text,
|
|
91
101
|
},
|
|
92
102
|
{
|
|
93
|
-
field: "
|
|
94
|
-
column: "
|
|
95
|
-
label: "
|
|
96
|
-
type: filterFieldType_enum_1.FilterFieldType.Enum,
|
|
97
|
-
options: optionsFromValues(["GET", "POST", "PATCH", "PUT", "DELETE"]),
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
field: "path",
|
|
101
|
-
column: "path",
|
|
102
|
-
label: "Rota",
|
|
103
|
+
field: "errorMessage",
|
|
104
|
+
column: "errorMessage",
|
|
105
|
+
label: "Mensagem",
|
|
103
106
|
type: filterFieldType_enum_1.FilterFieldType.Text,
|
|
104
107
|
},
|
|
105
108
|
{
|
|
@@ -108,6 +111,19 @@ exports.ERROR_LOGS_FILTER_CATALOG = [
|
|
|
108
111
|
label: "Usuário",
|
|
109
112
|
type: filterFieldType_enum_1.FilterFieldType.Uuid,
|
|
110
113
|
},
|
|
114
|
+
{
|
|
115
|
+
field: "requestId",
|
|
116
|
+
column: "requestId",
|
|
117
|
+
label: "ID da requisição",
|
|
118
|
+
type: filterFieldType_enum_1.FilterFieldType.Uuid,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
field: "createdAt",
|
|
122
|
+
column: "createdAt",
|
|
123
|
+
label: "Data",
|
|
124
|
+
type: filterFieldType_enum_1.FilterFieldType.DateTime,
|
|
125
|
+
sortable: true,
|
|
126
|
+
},
|
|
111
127
|
];
|
|
112
128
|
exports.AUDIT_DATA_CHANGES_FILTER_CATALOG = [
|
|
113
129
|
{
|
|
@@ -129,7 +145,7 @@ exports.AUDIT_DATA_CHANGES_FILTER_CATALOG = [
|
|
|
129
145
|
column: "action",
|
|
130
146
|
label: "Ação",
|
|
131
147
|
type: filterFieldType_enum_1.FilterFieldType.Enum,
|
|
132
|
-
options:
|
|
148
|
+
options: optionsFromEnum(AUDIT_DATA_ACTION_LABELS),
|
|
133
149
|
sortable: true,
|
|
134
150
|
},
|
|
135
151
|
{
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HttpErrorEvent } from "../../../core/events/appEvent.enum";
|
|
2
|
+
import { AuditService } from "../domain/audit.service";
|
|
3
|
+
export declare class HttpErrorListener {
|
|
4
|
+
private readonly audit;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(audit: AuditService);
|
|
7
|
+
onHttpError(event: HttpErrorEvent): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var HttpErrorListener_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.HttpErrorListener = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
16
|
+
const appEvent_enum_1 = require("../../../core/events/appEvent.enum");
|
|
17
|
+
const audit_service_1 = require("../domain/audit.service");
|
|
18
|
+
const classifyError_util_1 = require("../domain/classifyError.util");
|
|
19
|
+
const requestOutcome_enum_1 = require("../domain/enums/requestOutcome.enum");
|
|
20
|
+
const TEXT_MAX_LENGTH = 255;
|
|
21
|
+
let HttpErrorListener = HttpErrorListener_1 = class HttpErrorListener {
|
|
22
|
+
constructor(audit) {
|
|
23
|
+
this.audit = audit;
|
|
24
|
+
this.logger = new common_1.Logger(HttpErrorListener_1.name);
|
|
25
|
+
}
|
|
26
|
+
async onHttpError(event) {
|
|
27
|
+
try {
|
|
28
|
+
await this.audit.recordRequest({
|
|
29
|
+
outcome: requestOutcome_enum_1.RequestOutcome.ERROR,
|
|
30
|
+
action: event.action ?? null,
|
|
31
|
+
method: event.method,
|
|
32
|
+
path: event.path,
|
|
33
|
+
route: event.route,
|
|
34
|
+
statusCode: event.statusCode,
|
|
35
|
+
durationMs: event.durationMs ?? null,
|
|
36
|
+
userId: event.userId,
|
|
37
|
+
ipHash: event.ipHash,
|
|
38
|
+
userAgent: event.userAgent?.slice(0, TEXT_MAX_LENGTH) ?? null,
|
|
39
|
+
requestId: event.requestId,
|
|
40
|
+
errorType: (0, classifyError_util_1.classifyError)({ name: event.errorName }, event.statusCode),
|
|
41
|
+
errorCode: event.errorCode,
|
|
42
|
+
errorMessage: (event.message || "Erro desconhecido").slice(0, TEXT_MAX_LENGTH),
|
|
43
|
+
errorStack: event.statusCode >= 500 ? (event.stack ?? null) : null,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
this.logger.warn(`Falha ao registrar RequestLog: ${err.message}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.HttpErrorListener = HttpErrorListener;
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, event_emitter_1.OnEvent)(appEvent_enum_1.AppEvent.HTTP_ERROR),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", [Object]),
|
|
56
|
+
__metadata("design:returntype", Promise)
|
|
57
|
+
], HttpErrorListener.prototype, "onHttpError", null);
|
|
58
|
+
exports.HttpErrorListener = HttpErrorListener = HttpErrorListener_1 = __decorate([
|
|
59
|
+
(0, common_1.Injectable)(),
|
|
60
|
+
__metadata("design:paramtypes", [audit_service_1.AuditService])
|
|
61
|
+
], HttpErrorListener);
|
|
@@ -16,3 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./audit.controller"), exports);
|
|
18
18
|
__exportStar(require("./audit.interceptor"), exports);
|
|
19
|
+
__exportStar(require("./decorators/auditable.decorator"), exports);
|
|
20
|
+
__exportStar(require("./httpError.listener"), exports);
|
|
21
|
+
__exportStar(require("./userRolesChanged.listener"), exports);
|
|
@@ -45,7 +45,7 @@ __decorate([
|
|
|
45
45
|
], AuditDataChangeResponse.prototype, "entityId", void 0);
|
|
46
46
|
__decorate([
|
|
47
47
|
(0, swagger_1.ApiProperty)({ enum: auditDataChange_schema_1.AuditDataAction, enumName: "AuditDataAction" }),
|
|
48
|
-
__metadata("design:type",
|
|
48
|
+
__metadata("design:type", Number)
|
|
49
49
|
], AuditDataChangeResponse.prototype, "action", void 0);
|
|
50
50
|
__decorate([
|
|
51
51
|
(0, swagger_1.ApiProperty)({ type: Object, required: false, nullable: true }),
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { PaginationMetaResponse } from "../../../../core/utils/paginationMeta.response";
|
|
2
|
-
import { ErrorType } from "../../
|
|
2
|
+
import { ErrorType } from "../../domain/enums/errorType.enum";
|
|
3
|
+
import { RequestOutcome } from "../../domain/enums/requestOutcome.enum";
|
|
3
4
|
import { AuditUserRefResponse } from "./auditDataChange.response";
|
|
4
5
|
export declare class RequestLogResponse {
|
|
5
6
|
id: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
entityId?: string | null;
|
|
7
|
+
outcome: RequestOutcome;
|
|
8
|
+
action?: string | null;
|
|
9
9
|
method?: string | null;
|
|
10
10
|
path?: string | null;
|
|
11
|
+
route?: string | null;
|
|
11
12
|
statusCode?: number | null;
|
|
12
13
|
durationMs?: number | null;
|
|
13
|
-
ipAddress?: string | null;
|
|
14
|
-
requestId?: string | null;
|
|
15
|
-
metadata?: Record<string, unknown> | null;
|
|
16
14
|
userId?: string | null;
|
|
17
15
|
user?: AuditUserRefResponse | null;
|
|
16
|
+
ipHash?: string | null;
|
|
17
|
+
userAgent?: string | null;
|
|
18
|
+
requestId?: string | null;
|
|
19
|
+
errorType?: ErrorType | null;
|
|
20
|
+
errorCode?: string | null;
|
|
21
|
+
errorMessage?: string | null;
|
|
22
|
+
errorStack?: string | null;
|
|
18
23
|
createdAt: Date;
|
|
19
24
|
updatedAt: Date;
|
|
20
25
|
deletedAt?: Date | null;
|
|
@@ -23,23 +28,3 @@ export declare class PaginatedRequestLogsResponse {
|
|
|
23
28
|
items: RequestLogResponse[];
|
|
24
29
|
meta: PaginationMetaResponse;
|
|
25
30
|
}
|
|
26
|
-
export declare class ErrorLogResponse {
|
|
27
|
-
id: string;
|
|
28
|
-
type: ErrorType;
|
|
29
|
-
statusCode?: number | null;
|
|
30
|
-
message: string;
|
|
31
|
-
stack?: string | null;
|
|
32
|
-
method?: string | null;
|
|
33
|
-
path?: string | null;
|
|
34
|
-
ipAddress?: string | null;
|
|
35
|
-
requestId?: string | null;
|
|
36
|
-
userId?: string | null;
|
|
37
|
-
user?: AuditUserRefResponse | null;
|
|
38
|
-
createdAt: Date;
|
|
39
|
-
updatedAt: Date;
|
|
40
|
-
deletedAt?: Date | null;
|
|
41
|
-
}
|
|
42
|
-
export declare class PaginatedErrorLogsResponse {
|
|
43
|
-
items: ErrorLogResponse[];
|
|
44
|
-
meta: PaginationMetaResponse;
|
|
45
|
-
}
|