rl-core-api 0.2.0 → 0.4.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 +2 -2
- package/dist/core/config/env.schema.d.ts +2 -2
- 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/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/index.js +1 -9
- package/dist/core/events/appEvent.enum.d.ts +18 -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/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/coreEntities.d.ts +2 -3
- package/dist/coreEntities.js +2 -4
- package/dist/features/audit/audit.module.js +4 -7
- package/dist/features/audit/domain/audit.service.d.ts +6 -15
- package/dist/features/audit/domain/audit.service.js +9 -32
- 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 +17 -9
- 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 +47 -28
- package/dist/features/audit/presentation/decorators/auditable.decorator.d.ts +3 -0
- package/dist/features/audit/presentation/decorators/auditable.decorator.js +7 -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 +2 -0
- package/dist/features/audit/presentation/index.js +2 -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/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.js +10 -0
- package/dist/features/maintenance/domain/cleanup.service.d.ts +1 -4
- package/dist/features/maintenance/domain/cleanup.service.js +1 -21
- 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/responses/notification.response.js +1 -1
- package/dist/features/rbac/presentation/rbac.controller.js +5 -0
- package/dist/features/users/presentation/users.controller.js +5 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +10 -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.d.ts +0 -6
- 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,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,5 @@ 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);
|
|
@@ -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
|
-
}
|
|
@@ -9,10 +9,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.PaginatedRequestLogsResponse = exports.RequestLogResponse = void 0;
|
|
13
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
14
14
|
const paginationMeta_response_1 = require("../../../../core/utils/paginationMeta.response");
|
|
15
|
-
const
|
|
15
|
+
const errorType_enum_1 = require("../../domain/enums/errorType.enum");
|
|
16
|
+
const requestOutcome_enum_1 = require("../../domain/enums/requestOutcome.enum");
|
|
16
17
|
const auditDataChange_response_1 = require("./auditDataChange.response");
|
|
17
18
|
class RequestLogResponse {
|
|
18
19
|
}
|
|
@@ -22,25 +23,45 @@ __decorate([
|
|
|
22
23
|
__metadata("design:type", String)
|
|
23
24
|
], RequestLogResponse.prototype, "id", void 0);
|
|
24
25
|
__decorate([
|
|
25
|
-
(0, swagger_1.ApiProperty)({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
(0, swagger_1.ApiProperty)({
|
|
27
|
+
enum: requestOutcome_enum_1.RequestOutcome,
|
|
28
|
+
enumName: "RequestOutcome",
|
|
29
|
+
description: "0 = sucesso, 1 = erro, 2 = abortada",
|
|
30
|
+
example: requestOutcome_enum_1.RequestOutcome.SUCCESS,
|
|
31
|
+
}),
|
|
32
|
+
__metadata("design:type", Number)
|
|
33
|
+
], RequestLogResponse.prototype, "outcome", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, swagger_1.ApiProperty)({
|
|
36
|
+
type: String,
|
|
37
|
+
required: false,
|
|
38
|
+
nullable: true,
|
|
39
|
+
example: "Login",
|
|
40
|
+
}),
|
|
30
41
|
__metadata("design:type", Object)
|
|
31
|
-
], RequestLogResponse.prototype, "
|
|
32
|
-
__decorate([
|
|
33
|
-
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
34
|
-
__metadata("design:type", Object)
|
|
35
|
-
], RequestLogResponse.prototype, "entityId", void 0);
|
|
42
|
+
], RequestLogResponse.prototype, "action", void 0);
|
|
36
43
|
__decorate([
|
|
37
|
-
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, example: "
|
|
44
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, example: "POST" }),
|
|
38
45
|
__metadata("design:type", Object)
|
|
39
46
|
], RequestLogResponse.prototype, "method", void 0);
|
|
40
47
|
__decorate([
|
|
41
|
-
(0, swagger_1.ApiProperty)({
|
|
48
|
+
(0, swagger_1.ApiProperty)({
|
|
49
|
+
type: String,
|
|
50
|
+
required: false,
|
|
51
|
+
nullable: true,
|
|
52
|
+
example: "/api/v1/users/9f3c…",
|
|
53
|
+
}),
|
|
42
54
|
__metadata("design:type", Object)
|
|
43
55
|
], RequestLogResponse.prototype, "path", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, swagger_1.ApiProperty)({
|
|
58
|
+
type: String,
|
|
59
|
+
required: false,
|
|
60
|
+
nullable: true,
|
|
61
|
+
example: "/users/:id",
|
|
62
|
+
}),
|
|
63
|
+
__metadata("design:type", Object)
|
|
64
|
+
], RequestLogResponse.prototype, "route", void 0);
|
|
44
65
|
__decorate([
|
|
45
66
|
(0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true, example: 200 }),
|
|
46
67
|
__metadata("design:type", Object)
|
|
@@ -49,18 +70,6 @@ __decorate([
|
|
|
49
70
|
(0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true, example: 42 }),
|
|
50
71
|
__metadata("design:type", Object)
|
|
51
72
|
], RequestLogResponse.prototype, "durationMs", void 0);
|
|
52
|
-
__decorate([
|
|
53
|
-
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, example: "10.0.0.1" }),
|
|
54
|
-
__metadata("design:type", Object)
|
|
55
|
-
], RequestLogResponse.prototype, "ipAddress", void 0);
|
|
56
|
-
__decorate([
|
|
57
|
-
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, format: "uuid" }),
|
|
58
|
-
__metadata("design:type", Object)
|
|
59
|
-
], RequestLogResponse.prototype, "requestId", void 0);
|
|
60
|
-
__decorate([
|
|
61
|
-
(0, swagger_1.ApiProperty)({ type: Object, required: false, nullable: true }),
|
|
62
|
-
__metadata("design:type", Object)
|
|
63
|
-
], RequestLogResponse.prototype, "metadata", void 0);
|
|
64
73
|
__decorate([
|
|
65
74
|
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
66
75
|
__metadata("design:type", Object)
|
|
@@ -70,95 +79,64 @@ __decorate([
|
|
|
70
79
|
__metadata("design:type", Object)
|
|
71
80
|
], RequestLogResponse.prototype, "user", void 0);
|
|
72
81
|
__decorate([
|
|
73
|
-
(0, swagger_1.ApiProperty)({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
], RequestLogResponse.prototype, "updatedAt", void 0);
|
|
80
|
-
__decorate([
|
|
81
|
-
(0, swagger_1.ApiProperty)({ type: String, format: "date-time", required: false, nullable: true }),
|
|
82
|
-
__metadata("design:type", Object)
|
|
83
|
-
], RequestLogResponse.prototype, "deletedAt", void 0);
|
|
84
|
-
class PaginatedRequestLogsResponse {
|
|
85
|
-
}
|
|
86
|
-
exports.PaginatedRequestLogsResponse = PaginatedRequestLogsResponse;
|
|
87
|
-
__decorate([
|
|
88
|
-
(0, swagger_1.ApiProperty)({ type: [RequestLogResponse] }),
|
|
89
|
-
__metadata("design:type", Array)
|
|
90
|
-
], PaginatedRequestLogsResponse.prototype, "items", void 0);
|
|
91
|
-
__decorate([
|
|
92
|
-
(0, swagger_1.ApiProperty)({ type: paginationMeta_response_1.PaginationMetaResponse }),
|
|
93
|
-
__metadata("design:type", paginationMeta_response_1.PaginationMetaResponse)
|
|
94
|
-
], PaginatedRequestLogsResponse.prototype, "meta", void 0);
|
|
95
|
-
class ErrorLogResponse {
|
|
96
|
-
}
|
|
97
|
-
exports.ErrorLogResponse = ErrorLogResponse;
|
|
98
|
-
__decorate([
|
|
99
|
-
(0, swagger_1.ApiProperty)({ format: "uuid" }),
|
|
100
|
-
__metadata("design:type", String)
|
|
101
|
-
], ErrorLogResponse.prototype, "id", void 0);
|
|
102
|
-
__decorate([
|
|
103
|
-
(0, swagger_1.ApiProperty)({ enum: errorLog_schema_1.ErrorType, enumName: "ErrorType" }),
|
|
104
|
-
__metadata("design:type", String)
|
|
105
|
-
], ErrorLogResponse.prototype, "type", void 0);
|
|
106
|
-
__decorate([
|
|
107
|
-
(0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true, example: 500 }),
|
|
82
|
+
(0, swagger_1.ApiProperty)({
|
|
83
|
+
type: String,
|
|
84
|
+
required: false,
|
|
85
|
+
nullable: true,
|
|
86
|
+
description: "HMAC do IP — não é reversível ao endereço original",
|
|
87
|
+
}),
|
|
108
88
|
__metadata("design:type", Object)
|
|
109
|
-
],
|
|
110
|
-
__decorate([
|
|
111
|
-
(0, swagger_1.ApiProperty)(),
|
|
112
|
-
__metadata("design:type", String)
|
|
113
|
-
], ErrorLogResponse.prototype, "message", void 0);
|
|
89
|
+
], RequestLogResponse.prototype, "ipHash", void 0);
|
|
114
90
|
__decorate([
|
|
115
91
|
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
116
92
|
__metadata("design:type", Object)
|
|
117
|
-
],
|
|
118
|
-
__decorate([
|
|
119
|
-
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, example: "POST" }),
|
|
120
|
-
__metadata("design:type", Object)
|
|
121
|
-
], ErrorLogResponse.prototype, "method", void 0);
|
|
93
|
+
], RequestLogResponse.prototype, "userAgent", void 0);
|
|
122
94
|
__decorate([
|
|
123
|
-
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
95
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, format: "uuid" }),
|
|
124
96
|
__metadata("design:type", Object)
|
|
125
|
-
],
|
|
97
|
+
], RequestLogResponse.prototype, "requestId", void 0);
|
|
126
98
|
__decorate([
|
|
127
|
-
(0, swagger_1.ApiProperty)({
|
|
99
|
+
(0, swagger_1.ApiProperty)({
|
|
100
|
+
enum: errorType_enum_1.ErrorType,
|
|
101
|
+
enumName: "ErrorType",
|
|
102
|
+
required: false,
|
|
103
|
+
nullable: true,
|
|
104
|
+
description: "0 = validação, 1 = autenticação, 2 = não encontrado, 3 = limite, 4 = banco, 5 = integração, 6 = interno",
|
|
105
|
+
}),
|
|
128
106
|
__metadata("design:type", Object)
|
|
129
|
-
],
|
|
107
|
+
], RequestLogResponse.prototype, "errorType", void 0);
|
|
130
108
|
__decorate([
|
|
131
|
-
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true
|
|
109
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
132
110
|
__metadata("design:type", Object)
|
|
133
|
-
],
|
|
111
|
+
], RequestLogResponse.prototype, "errorCode", void 0);
|
|
134
112
|
__decorate([
|
|
135
113
|
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
136
114
|
__metadata("design:type", Object)
|
|
137
|
-
],
|
|
115
|
+
], RequestLogResponse.prototype, "errorMessage", void 0);
|
|
138
116
|
__decorate([
|
|
139
|
-
(0, swagger_1.ApiProperty)({ type:
|
|
117
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
140
118
|
__metadata("design:type", Object)
|
|
141
|
-
],
|
|
119
|
+
], RequestLogResponse.prototype, "errorStack", void 0);
|
|
142
120
|
__decorate([
|
|
143
121
|
(0, swagger_1.ApiProperty)({ format: "date-time" }),
|
|
144
122
|
__metadata("design:type", Date)
|
|
145
|
-
],
|
|
123
|
+
], RequestLogResponse.prototype, "createdAt", void 0);
|
|
146
124
|
__decorate([
|
|
147
125
|
(0, swagger_1.ApiProperty)({ format: "date-time" }),
|
|
148
126
|
__metadata("design:type", Date)
|
|
149
|
-
],
|
|
127
|
+
], RequestLogResponse.prototype, "updatedAt", void 0);
|
|
150
128
|
__decorate([
|
|
151
129
|
(0, swagger_1.ApiProperty)({ type: String, format: "date-time", required: false, nullable: true }),
|
|
152
130
|
__metadata("design:type", Object)
|
|
153
|
-
],
|
|
154
|
-
class
|
|
131
|
+
], RequestLogResponse.prototype, "deletedAt", void 0);
|
|
132
|
+
class PaginatedRequestLogsResponse {
|
|
155
133
|
}
|
|
156
|
-
exports.
|
|
134
|
+
exports.PaginatedRequestLogsResponse = PaginatedRequestLogsResponse;
|
|
157
135
|
__decorate([
|
|
158
|
-
(0, swagger_1.ApiProperty)({ type: [
|
|
136
|
+
(0, swagger_1.ApiProperty)({ type: [RequestLogResponse] }),
|
|
159
137
|
__metadata("design:type", Array)
|
|
160
|
-
],
|
|
138
|
+
], PaginatedRequestLogsResponse.prototype, "items", void 0);
|
|
161
139
|
__decorate([
|
|
162
140
|
(0, swagger_1.ApiProperty)({ type: paginationMeta_response_1.PaginationMetaResponse }),
|
|
163
141
|
__metadata("design:type", paginationMeta_response_1.PaginationMetaResponse)
|
|
164
|
-
],
|
|
142
|
+
], PaginatedRequestLogsResponse.prototype, "meta", void 0);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseEntity } from "../../../../core/database/base.schema";
|
|
2
2
|
export declare enum TokenType {
|
|
3
|
-
PASSWORD_RESET =
|
|
4
|
-
FIRST_ACCESS =
|
|
5
|
-
TWO_FACTOR_EMAIL =
|
|
6
|
-
REFRESH_TOKEN =
|
|
7
|
-
TOTP_USED =
|
|
3
|
+
PASSWORD_RESET = 0,
|
|
4
|
+
FIRST_ACCESS = 1,
|
|
5
|
+
TWO_FACTOR_EMAIL = 2,
|
|
6
|
+
REFRESH_TOKEN = 3,
|
|
7
|
+
TOTP_USED = 4
|
|
8
8
|
}
|
|
9
9
|
export declare class AuthToken extends BaseEntity {
|
|
10
10
|
userId: string;
|
|
@@ -14,11 +14,11 @@ const typeorm_1 = require("typeorm");
|
|
|
14
14
|
const base_schema_1 = require("../../../../core/database/base.schema");
|
|
15
15
|
var TokenType;
|
|
16
16
|
(function (TokenType) {
|
|
17
|
-
TokenType["PASSWORD_RESET"] = "
|
|
18
|
-
TokenType["FIRST_ACCESS"] = "
|
|
19
|
-
TokenType["TWO_FACTOR_EMAIL"] = "
|
|
20
|
-
TokenType["REFRESH_TOKEN"] = "
|
|
21
|
-
TokenType["TOTP_USED"] = "
|
|
17
|
+
TokenType[TokenType["PASSWORD_RESET"] = 0] = "PASSWORD_RESET";
|
|
18
|
+
TokenType[TokenType["FIRST_ACCESS"] = 1] = "FIRST_ACCESS";
|
|
19
|
+
TokenType[TokenType["TWO_FACTOR_EMAIL"] = 2] = "TWO_FACTOR_EMAIL";
|
|
20
|
+
TokenType[TokenType["REFRESH_TOKEN"] = 3] = "REFRESH_TOKEN";
|
|
21
|
+
TokenType[TokenType["TOTP_USED"] = 4] = "TOTP_USED";
|
|
22
22
|
})(TokenType || (exports.TokenType = TokenType = {}));
|
|
23
23
|
let AuthToken = class AuthToken extends base_schema_1.BaseEntity {
|
|
24
24
|
isExpired() {
|
|
@@ -38,8 +38,8 @@ __decorate([
|
|
|
38
38
|
__metadata("design:type", String)
|
|
39
39
|
], AuthToken.prototype, "tokenHash", void 0);
|
|
40
40
|
__decorate([
|
|
41
|
-
(0, typeorm_1.Column)({ type: "
|
|
42
|
-
__metadata("design:type",
|
|
41
|
+
(0, typeorm_1.Column)({ type: "tinyint", unsigned: true }),
|
|
42
|
+
__metadata("design:type", Number)
|
|
43
43
|
], AuthToken.prototype, "type", void 0);
|
|
44
44
|
__decorate([
|
|
45
45
|
(0, typeorm_1.Column)({ name: "family", type: "char", length: 36, nullable: true }),
|
|
@@ -21,7 +21,9 @@ const currentUser_decorator_1 = require("../../../core/auth/decorators/currentUs
|
|
|
21
21
|
const public_decorator_1 = require("../../../core/auth/decorators/public.decorator");
|
|
22
22
|
const jwtAuth_guard_1 = require("../../../core/auth/guards/jwtAuth.guard");
|
|
23
23
|
const env_service_1 = require("../../../core/config/env.service");
|
|
24
|
+
const requestLog_context_1 = require("../../../core/context/requestLog.context");
|
|
24
25
|
const ip_util_1 = require("../../../core/utils/ip.util");
|
|
26
|
+
const auditable_decorator_1 = require("../../audit/presentation/decorators/auditable.decorator");
|
|
25
27
|
const auth_service_1 = require("../domain/auth.service");
|
|
26
28
|
const clientType_enum_1 = require("./commands/clientType.enum");
|
|
27
29
|
const login_command_1 = require("./commands/login.command");
|
|
@@ -51,6 +53,7 @@ let AuthController = class AuthController {
|
|
|
51
53
|
}
|
|
52
54
|
async verify(dto, req, res) {
|
|
53
55
|
const { accessToken, refreshToken, user, backupCodes } = await this.auth.verifyTwoFactor(dto, ctxFrom(req));
|
|
56
|
+
(0, requestLog_context_1.setRequestLogUser)(req, user.id);
|
|
54
57
|
if (dto.client === clientType_enum_1.ClientType.MOBILE) {
|
|
55
58
|
return { user, backupCodes, accessToken, refreshToken };
|
|
56
59
|
}
|
|
@@ -99,6 +102,7 @@ exports.AuthController = AuthController;
|
|
|
99
102
|
__decorate([
|
|
100
103
|
(0, public_decorator_1.Public)(),
|
|
101
104
|
(0, throttler_1.Throttle)({ default: { limit: 10, ttl: 60_000 } }),
|
|
105
|
+
(0, auditable_decorator_1.Auditable)("Login"),
|
|
102
106
|
(0, common_1.Post)("login"),
|
|
103
107
|
(0, swagger_1.ApiOperation)({ summary: "Login (passo 1): valida email+senha e exige 2FA" }),
|
|
104
108
|
__param(0, (0, common_1.Body)()),
|
|
@@ -108,6 +112,7 @@ __decorate([
|
|
|
108
112
|
], AuthController.prototype, "login", null);
|
|
109
113
|
__decorate([
|
|
110
114
|
(0, public_decorator_1.Public)(),
|
|
115
|
+
(0, auditable_decorator_1.Auditable)("Configuração de 2FA"),
|
|
111
116
|
(0, common_1.Post)("2fa/setup"),
|
|
112
117
|
(0, swagger_1.ApiOperation)({ summary: "Gera segredo/QR TOTP no primeiro acesso" }),
|
|
113
118
|
__param(0, (0, common_1.Body)()),
|
|
@@ -128,6 +133,7 @@ __decorate([
|
|
|
128
133
|
__decorate([
|
|
129
134
|
(0, public_decorator_1.Public)(),
|
|
130
135
|
(0, throttler_1.Throttle)({ default: { limit: 10, ttl: 60_000 } }),
|
|
136
|
+
(0, auditable_decorator_1.Auditable)("Verificação de 2FA"),
|
|
131
137
|
(0, common_1.Post)("2fa/verify"),
|
|
132
138
|
(0, swagger_1.ApiOperation)({
|
|
133
139
|
summary: "Login (passo 2): valida código 2FA e emite tokens",
|
|
@@ -153,6 +159,7 @@ __decorate([
|
|
|
153
159
|
], AuthController.prototype, "refresh", null);
|
|
154
160
|
__decorate([
|
|
155
161
|
(0, public_decorator_1.Public)(),
|
|
162
|
+
(0, auditable_decorator_1.Auditable)("Logout"),
|
|
156
163
|
(0, common_1.Post)("logout"),
|
|
157
164
|
(0, common_1.HttpCode)(200),
|
|
158
165
|
(0, swagger_1.ApiOperation)({
|
|
@@ -191,6 +198,7 @@ __decorate([
|
|
|
191
198
|
__decorate([
|
|
192
199
|
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
|
193
200
|
(0, swagger_1.ApiBearerAuth)(),
|
|
201
|
+
(0, auditable_decorator_1.Auditable)("Regeneração de códigos de backup"),
|
|
194
202
|
(0, common_1.Post)("2fa/backup/regenerate"),
|
|
195
203
|
(0, swagger_1.ApiOperation)({
|
|
196
204
|
summary: "Regenera os códigos de backup (confirma com código TOTP)",
|
|
@@ -204,6 +212,7 @@ __decorate([
|
|
|
204
212
|
__decorate([
|
|
205
213
|
(0, public_decorator_1.Public)(),
|
|
206
214
|
(0, throttler_1.Throttle)({ default: { limit: 5, ttl: 60_000 } }),
|
|
215
|
+
(0, auditable_decorator_1.Auditable)("Solicitação de redefinição de senha"),
|
|
207
216
|
(0, common_1.Post)("forgot-password"),
|
|
208
217
|
(0, common_1.HttpCode)(200),
|
|
209
218
|
(0, swagger_1.ApiOperation)({ summary: "Solicita email de redefinição de senha" }),
|
|
@@ -226,6 +235,7 @@ __decorate([
|
|
|
226
235
|
], AuthController.prototype, "inspectPasswordToken", null);
|
|
227
236
|
__decorate([
|
|
228
237
|
(0, public_decorator_1.Public)(),
|
|
238
|
+
(0, auditable_decorator_1.Auditable)("Redefinição de senha"),
|
|
229
239
|
(0, common_1.Post)("reset-password"),
|
|
230
240
|
(0, common_1.HttpCode)(200),
|
|
231
241
|
(0, swagger_1.ApiOperation)({ summary: "Redefine a senha usando o token do email" }),
|