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
|
@@ -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);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UserRolesChangedEvent } from "../../../core/events/appEvent.enum";
|
|
2
|
+
import { AuditService } from "../domain/audit.service";
|
|
3
|
+
export declare class UserRolesChangedListener {
|
|
4
|
+
private readonly audit;
|
|
5
|
+
constructor(audit: AuditService);
|
|
6
|
+
onRolesChanged(event: UserRolesChangedEvent): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UserRolesChangedListener = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
15
|
+
const appEvent_enum_1 = require("../../../core/events/appEvent.enum");
|
|
16
|
+
const audit_service_1 = require("../domain/audit.service");
|
|
17
|
+
const auditDataChange_schema_1 = require("../infra/schema/auditDataChange.schema");
|
|
18
|
+
const asLabel = (names) => names.length ? [...names].sort().join(", ") : "—";
|
|
19
|
+
let UserRolesChangedListener = class UserRolesChangedListener {
|
|
20
|
+
constructor(audit) {
|
|
21
|
+
this.audit = audit;
|
|
22
|
+
}
|
|
23
|
+
async onRolesChanged(event) {
|
|
24
|
+
await this.audit.recordChange({
|
|
25
|
+
entity: "User",
|
|
26
|
+
entityId: event.userId,
|
|
27
|
+
action: auditDataChange_schema_1.AuditDataAction.UPDATE,
|
|
28
|
+
oldData: { roles: asLabel(event.previousRoleNames) },
|
|
29
|
+
newData: { roles: asLabel(event.roleNames) },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.UserRolesChangedListener = UserRolesChangedListener;
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, event_emitter_1.OnEvent)(appEvent_enum_1.AppEvent.USER_ROLES_CHANGED),
|
|
36
|
+
__metadata("design:type", Function),
|
|
37
|
+
__metadata("design:paramtypes", [Object]),
|
|
38
|
+
__metadata("design:returntype", Promise)
|
|
39
|
+
], UserRolesChangedListener.prototype, "onRolesChanged", null);
|
|
40
|
+
exports.UserRolesChangedListener = UserRolesChangedListener = __decorate([
|
|
41
|
+
(0, common_1.Injectable)(),
|
|
42
|
+
__metadata("design:paramtypes", [audit_service_1.AuditService])
|
|
43
|
+
], UserRolesChangedListener);
|
|
@@ -14,6 +14,11 @@ interface RequestCtx {
|
|
|
14
14
|
userAgent?: string;
|
|
15
15
|
}
|
|
16
16
|
export type LoginStatus = "SETUP_REQUIRED" | "TOTP_REQUIRED";
|
|
17
|
+
export interface LoginChallenge {
|
|
18
|
+
status: LoginStatus;
|
|
19
|
+
pendingToken: string;
|
|
20
|
+
expiresInSeconds: number;
|
|
21
|
+
}
|
|
17
22
|
export type SessionUser = AuthenticatedUser;
|
|
18
23
|
export interface LoginSession {
|
|
19
24
|
accessToken: string;
|
|
@@ -42,10 +47,7 @@ export declare class AuthService {
|
|
|
42
47
|
private readonly rbac;
|
|
43
48
|
private dummyHash?;
|
|
44
49
|
constructor(users: UsersService, tokens: TokenService, twoFactor: TwoFactorService, jwt: JwtService, env: EnvService, mailer: MailerService, rbac: RbacService);
|
|
45
|
-
login(dto: LoginCommand): Promise<
|
|
46
|
-
status: LoginStatus;
|
|
47
|
-
pendingToken: string;
|
|
48
|
-
}>;
|
|
50
|
+
login(dto: LoginCommand): Promise<LoginChallenge>;
|
|
49
51
|
setupTotp(pendingToken: string): Promise<TotpSetup>;
|
|
50
52
|
requestEmailCode(pendingToken: string): Promise<{
|
|
51
53
|
sent: boolean;
|
|
@@ -58,6 +60,7 @@ export declare class AuthService {
|
|
|
58
60
|
inspectPasswordToken(token: string): Promise<PasswordTokenCheck>;
|
|
59
61
|
resetPassword(token: string, newPassword: string): Promise<void>;
|
|
60
62
|
private buildPendingToken;
|
|
63
|
+
private pendingExpiresIn;
|
|
61
64
|
private decodePending;
|
|
62
65
|
private signAccessToken;
|
|
63
66
|
toSessionUser(user: User): Promise<SessionUser>;
|
|
@@ -13,6 +13,7 @@ exports.AuthService = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const jwt_1 = require("@nestjs/jwt");
|
|
15
15
|
const env_service_1 = require("../../../core/config/env.service");
|
|
16
|
+
const auditContext_1 = require("../../../core/context/auditContext");
|
|
16
17
|
const appErrorCode_enum_1 = require("../../../core/filters/appErrorCode.enum");
|
|
17
18
|
const mailer_service_1 = require("../../../core/mailer/mailer.service");
|
|
18
19
|
const codedError_util_1 = require("../../../core/utils/codedError.util");
|
|
@@ -30,7 +31,6 @@ function attemptsWarning(prefix, remaining) {
|
|
|
30
31
|
const attempts = remaining === 1 ? "Resta 1 tentativa" : `Restam ${remaining} tentativas`;
|
|
31
32
|
return `${prefix}. ${attempts} antes do bloqueio da conta`;
|
|
32
33
|
}
|
|
33
|
-
const PENDING_EXPIRES = "10m";
|
|
34
34
|
let AuthService = class AuthService {
|
|
35
35
|
constructor(users, tokens, twoFactor, jwt, env, mailer, rbac) {
|
|
36
36
|
this.users = users;
|
|
@@ -69,6 +69,7 @@ let AuthService = class AuthService {
|
|
|
69
69
|
return {
|
|
70
70
|
status: user.twoFactorEnabled ? "TOTP_REQUIRED" : "SETUP_REQUIRED",
|
|
71
71
|
pendingToken,
|
|
72
|
+
expiresInSeconds: this.pendingExpiresIn(pendingToken),
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
75
|
async setupTotp(pendingToken) {
|
|
@@ -77,6 +78,12 @@ let AuthService = class AuthService {
|
|
|
77
78
|
throw new common_1.BadRequestException("2FA já está configurado para esta conta");
|
|
78
79
|
}
|
|
79
80
|
const user = await this.users.findById(payload.sub);
|
|
81
|
+
const pendingSecret = !user.twoFactorEnabled
|
|
82
|
+
? user.twoFactorSecret
|
|
83
|
+
: null;
|
|
84
|
+
if (pendingSecret) {
|
|
85
|
+
return this.twoFactor.rebuildSetup(user.email, pendingSecret);
|
|
86
|
+
}
|
|
80
87
|
const setup = await this.twoFactor.generateSetup(user.email);
|
|
81
88
|
user.twoFactorSecret = this.twoFactor.encrypt(setup.secret);
|
|
82
89
|
await this.users.save(user);
|
|
@@ -208,6 +215,7 @@ let AuthService = class AuthService {
|
|
|
208
215
|
if (!consumed) {
|
|
209
216
|
throw invalidToken();
|
|
210
217
|
}
|
|
218
|
+
(0, auditContext_1.setAuditUser)(consumed.userId);
|
|
211
219
|
await this.users.resetPassword(consumed.userId, newPassword);
|
|
212
220
|
await this.tokens.revokeAllRefresh(consumed.userId);
|
|
213
221
|
}
|
|
@@ -220,9 +228,16 @@ let AuthService = class AuthService {
|
|
|
220
228
|
};
|
|
221
229
|
return this.jwt.signAsync(payload, {
|
|
222
230
|
secret: this.env.get("JWT_PENDING_SECRET"),
|
|
223
|
-
expiresIn:
|
|
231
|
+
expiresIn: this.env.get("JWT_PENDING_EXPIRES"),
|
|
224
232
|
});
|
|
225
233
|
}
|
|
234
|
+
pendingExpiresIn(token) {
|
|
235
|
+
const decoded = this.jwt.decode(token);
|
|
236
|
+
if (!decoded?.exp) {
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
return Math.max(0, decoded.exp - Math.floor(Date.now() / 1000));
|
|
240
|
+
}
|
|
226
241
|
async decodePending(token) {
|
|
227
242
|
try {
|
|
228
243
|
const payload = await this.jwt.verifyAsync(token, {
|
|
@@ -233,8 +248,11 @@ let AuthService = class AuthService {
|
|
|
233
248
|
}
|
|
234
249
|
return payload;
|
|
235
250
|
}
|
|
236
|
-
catch {
|
|
237
|
-
|
|
251
|
+
catch (err) {
|
|
252
|
+
if (err?.name === "TokenExpiredError") {
|
|
253
|
+
throw (0, codedError_util_1.codedUnauthorized)("A verificação expirou. Entre novamente para continuar", appErrorCode_enum_1.AppErrorCode.PENDING_TOKEN_EXPIRED);
|
|
254
|
+
}
|
|
255
|
+
throw new common_1.UnauthorizedException("Token de verificação inválido");
|
|
238
256
|
}
|
|
239
257
|
}
|
|
240
258
|
signAccessToken(user) {
|
|
@@ -9,7 +9,9 @@ export declare class TwoFactorService {
|
|
|
9
9
|
private readonly logger;
|
|
10
10
|
constructor(env: EnvService);
|
|
11
11
|
generateSetup(accountEmail: string): Promise<TotpSetup>;
|
|
12
|
+
private buildSetup;
|
|
12
13
|
encrypt(secret: string): string;
|
|
14
|
+
rebuildSetup(accountEmail: string, storedSecret: string): Promise<TotpSetup>;
|
|
13
15
|
verifyTotp(code: string, storedSecret: string): Promise<boolean>;
|
|
14
16
|
generateBackupCodes(): Promise<{
|
|
15
17
|
plain: string[];
|
|
@@ -55,8 +55,10 @@ let TwoFactorService = TwoFactorService_1 = class TwoFactorService {
|
|
|
55
55
|
this.env = env;
|
|
56
56
|
this.logger = new common_1.Logger(TwoFactorService_1.name);
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
generateSetup(accountEmail) {
|
|
59
|
+
return this.buildSetup(accountEmail, (0, otplib_1.generateSecret)());
|
|
60
|
+
}
|
|
61
|
+
async buildSetup(accountEmail, secret) {
|
|
60
62
|
const issuer = this.env.brand().totpIssuer;
|
|
61
63
|
const otpauthUrl = (0, otplib_1.generateURI)({ issuer, label: accountEmail, secret });
|
|
62
64
|
const qrDataUrl = await QRCode.toDataURL(otpauthUrl);
|
|
@@ -65,6 +67,9 @@ let TwoFactorService = TwoFactorService_1 = class TwoFactorService {
|
|
|
65
67
|
encrypt(secret) {
|
|
66
68
|
return (0, crypto_util_1.encryptSecret)(secret);
|
|
67
69
|
}
|
|
70
|
+
rebuildSetup(accountEmail, storedSecret) {
|
|
71
|
+
return this.buildSetup(accountEmail, (0, crypto_util_1.decryptSecret)(storedSecret));
|
|
72
|
+
}
|
|
68
73
|
async verifyTotp(code, storedSecret) {
|
|
69
74
|
if (!storedSecret) {
|
|
70
75
|
return false;
|
|
@@ -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 }),
|
|
@@ -4,7 +4,7 @@ import { EnvService } from "../../../core/config/env.service";
|
|
|
4
4
|
import { AuthService } from "../domain/auth.service";
|
|
5
5
|
import { PasswordTokenCheck } from "../domain/auth.service";
|
|
6
6
|
import { SessionUser } from "../domain/auth.service";
|
|
7
|
-
import {
|
|
7
|
+
import { LoginChallenge } from "../domain/auth.service";
|
|
8
8
|
import { TotpSetup } from "../domain/twoFactor.service";
|
|
9
9
|
import { LoginCommand } from "./commands/login.command";
|
|
10
10
|
import { ForgotPasswordCommand, ResetPasswordCommand } from "./commands/password.command";
|
|
@@ -25,10 +25,7 @@ export declare class AuthController {
|
|
|
25
25
|
private readonly auth;
|
|
26
26
|
private readonly env;
|
|
27
27
|
constructor(auth: AuthService, env: EnvService);
|
|
28
|
-
login(dto: LoginCommand): Promise<
|
|
29
|
-
status: LoginStatus;
|
|
30
|
-
pendingToken: string;
|
|
31
|
-
}>;
|
|
28
|
+
login(dto: LoginCommand): Promise<LoginChallenge>;
|
|
32
29
|
setupTotp(dto: PendingTokenCommand): Promise<TotpSetup>;
|
|
33
30
|
requestEmailCode(dto: PendingTokenCommand): Promise<{
|
|
34
31
|
sent: boolean;
|
|
@@ -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)()),
|
|
@@ -118,6 +123,7 @@ __decorate([
|
|
|
118
123
|
__decorate([
|
|
119
124
|
(0, public_decorator_1.Public)(),
|
|
120
125
|
(0, throttler_1.Throttle)({ default: { limit: 5, ttl: 60_000 } }),
|
|
126
|
+
(0, auditable_decorator_1.Auditable)("E-mail: código de verificação", { allowSystem: true }),
|
|
121
127
|
(0, common_1.Post)("2fa/email"),
|
|
122
128
|
(0, swagger_1.ApiOperation)({ summary: "Fallback: envia código 2FA por email" }),
|
|
123
129
|
__param(0, (0, common_1.Body)()),
|
|
@@ -128,6 +134,7 @@ __decorate([
|
|
|
128
134
|
__decorate([
|
|
129
135
|
(0, public_decorator_1.Public)(),
|
|
130
136
|
(0, throttler_1.Throttle)({ default: { limit: 10, ttl: 60_000 } }),
|
|
137
|
+
(0, auditable_decorator_1.Auditable)("Verificação de 2FA"),
|
|
131
138
|
(0, common_1.Post)("2fa/verify"),
|
|
132
139
|
(0, swagger_1.ApiOperation)({
|
|
133
140
|
summary: "Login (passo 2): valida código 2FA e emite tokens",
|
|
@@ -153,6 +160,7 @@ __decorate([
|
|
|
153
160
|
], AuthController.prototype, "refresh", null);
|
|
154
161
|
__decorate([
|
|
155
162
|
(0, public_decorator_1.Public)(),
|
|
163
|
+
(0, auditable_decorator_1.Auditable)("Logout"),
|
|
156
164
|
(0, common_1.Post)("logout"),
|
|
157
165
|
(0, common_1.HttpCode)(200),
|
|
158
166
|
(0, swagger_1.ApiOperation)({
|
|
@@ -191,6 +199,7 @@ __decorate([
|
|
|
191
199
|
__decorate([
|
|
192
200
|
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
|
193
201
|
(0, swagger_1.ApiBearerAuth)(),
|
|
202
|
+
(0, auditable_decorator_1.Auditable)("Regeneração de códigos de backup"),
|
|
194
203
|
(0, common_1.Post)("2fa/backup/regenerate"),
|
|
195
204
|
(0, swagger_1.ApiOperation)({
|
|
196
205
|
summary: "Regenera os códigos de backup (confirma com código TOTP)",
|
|
@@ -204,6 +213,7 @@ __decorate([
|
|
|
204
213
|
__decorate([
|
|
205
214
|
(0, public_decorator_1.Public)(),
|
|
206
215
|
(0, throttler_1.Throttle)({ default: { limit: 5, ttl: 60_000 } }),
|
|
216
|
+
(0, auditable_decorator_1.Auditable)("E-mail: redefinição de senha", { allowSystem: true }),
|
|
207
217
|
(0, common_1.Post)("forgot-password"),
|
|
208
218
|
(0, common_1.HttpCode)(200),
|
|
209
219
|
(0, swagger_1.ApiOperation)({ summary: "Solicita email de redefinição de senha" }),
|
|
@@ -226,6 +236,7 @@ __decorate([
|
|
|
226
236
|
], AuthController.prototype, "inspectPasswordToken", null);
|
|
227
237
|
__decorate([
|
|
228
238
|
(0, public_decorator_1.Public)(),
|
|
239
|
+
(0, auditable_decorator_1.Auditable)("Redefinição de senha"),
|
|
229
240
|
(0, common_1.Post)("reset-password"),
|
|
230
241
|
(0, common_1.HttpCode)(200),
|
|
231
242
|
(0, swagger_1.ApiOperation)({ summary: "Redefine a senha usando o token do email" }),
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { EventEmitter2 } from "@nestjs/event-emitter";
|
|
2
2
|
import { EnvService } from "../../../core/config/env.service";
|
|
3
|
-
import { AuditService } from "../../audit/domain/audit.service";
|
|
4
3
|
import { TokenService } from "../../auth/domain/token.service";
|
|
5
4
|
import { NotificationsService } from "../../notifications/domain/notifications.service";
|
|
6
5
|
import { UserRepository } from "../../users/infra/repositories/user.repository";
|
|
7
6
|
export declare class CleanupService {
|
|
8
7
|
private readonly tokens;
|
|
9
|
-
private readonly audit;
|
|
10
8
|
private readonly env;
|
|
11
9
|
private readonly notifications;
|
|
12
10
|
private readonly users;
|
|
13
11
|
private readonly events;
|
|
14
12
|
private readonly logger;
|
|
15
|
-
constructor(tokens: TokenService,
|
|
13
|
+
constructor(tokens: TokenService, env: EnvService, notifications: NotificationsService, users: UserRepository, events: EventEmitter2);
|
|
16
14
|
handleTokenCleanup(): Promise<void>;
|
|
17
|
-
handleAuditLogCleanup(): Promise<void>;
|
|
18
15
|
handleNotificationCleanup(): Promise<void>;
|
|
19
16
|
handlePasswordExpiryWarning(): Promise<void>;
|
|
20
17
|
private daysUntilExpiry;
|
|
@@ -16,15 +16,13 @@ const event_emitter_1 = require("@nestjs/event-emitter");
|
|
|
16
16
|
const schedule_1 = require("@nestjs/schedule");
|
|
17
17
|
const env_service_1 = require("../../../core/config/env.service");
|
|
18
18
|
const appEvent_enum_1 = require("../../../core/events/appEvent.enum");
|
|
19
|
-
const audit_service_1 = require("../../audit/domain/audit.service");
|
|
20
19
|
const token_service_1 = require("../../auth/domain/token.service");
|
|
21
20
|
const notifications_service_1 = require("../../notifications/domain/notifications.service");
|
|
22
21
|
const user_repository_1 = require("../../users/infra/repositories/user.repository");
|
|
23
22
|
const PASSWORD_WARNING_MILESTONES = [7, 3, 1];
|
|
24
23
|
let CleanupService = CleanupService_1 = class CleanupService {
|
|
25
|
-
constructor(tokens,
|
|
24
|
+
constructor(tokens, env, notifications, users, events) {
|
|
26
25
|
this.tokens = tokens;
|
|
27
|
-
this.audit = audit;
|
|
28
26
|
this.env = env;
|
|
29
27
|
this.notifications = notifications;
|
|
30
28
|
this.users = users;
|
|
@@ -39,20 +37,6 @@ let CleanupService = CleanupService_1 = class CleanupService {
|
|
|
39
37
|
}
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
|
-
async handleAuditLogCleanup() {
|
|
43
|
-
await this.run("Limpeza de logs operacionais", async () => {
|
|
44
|
-
const retentionDays = this.env.get("AUDIT_LOG_RETENTION_DAYS");
|
|
45
|
-
const { changes, errors } = await this.audit.cleanupOldLogs(retentionDays);
|
|
46
|
-
if (changes > 0 || errors > 0) {
|
|
47
|
-
this.logger.log(`Logs operacionais removidos (> ${retentionDays}d): ${changes} requisições, ${errors} erros`);
|
|
48
|
-
}
|
|
49
|
-
const dataRetentionDays = this.env.get("AUDIT_DATA_RETENTION_DAYS");
|
|
50
|
-
const dataChanges = await this.audit.cleanupOldDataChanges(dataRetentionDays);
|
|
51
|
-
if (dataChanges > 0) {
|
|
52
|
-
this.logger.log(`Trilha de dados removida (> ${dataRetentionDays}d): ${dataChanges} registros`);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
40
|
async handleNotificationCleanup() {
|
|
57
41
|
await this.run("Limpeza de notificações", async () => {
|
|
58
42
|
const retentionDays = this.env.get("NOTIFICATION_RETENTION_DAYS");
|
|
@@ -112,14 +96,6 @@ __decorate([
|
|
|
112
96
|
__metadata("design:paramtypes", []),
|
|
113
97
|
__metadata("design:returntype", Promise)
|
|
114
98
|
], CleanupService.prototype, "handleTokenCleanup", null);
|
|
115
|
-
__decorate([
|
|
116
|
-
(0, schedule_1.Cron)(process.env.AUDIT_LOG_CLEANUP_CRON ?? "0 3 * * *", {
|
|
117
|
-
name: "audit-log-cleanup",
|
|
118
|
-
}),
|
|
119
|
-
__metadata("design:type", Function),
|
|
120
|
-
__metadata("design:paramtypes", []),
|
|
121
|
-
__metadata("design:returntype", Promise)
|
|
122
|
-
], CleanupService.prototype, "handleAuditLogCleanup", null);
|
|
123
99
|
__decorate([
|
|
124
100
|
(0, schedule_1.Cron)(process.env.NOTIFICATION_CLEANUP_CRON ?? "0 4 * * *", {
|
|
125
101
|
name: "notification-cleanup",
|
|
@@ -139,7 +115,6 @@ __decorate([
|
|
|
139
115
|
exports.CleanupService = CleanupService = CleanupService_1 = __decorate([
|
|
140
116
|
(0, common_1.Injectable)(),
|
|
141
117
|
__metadata("design:paramtypes", [token_service_1.TokenService,
|
|
142
|
-
audit_service_1.AuditService,
|
|
143
118
|
env_service_1.EnvService,
|
|
144
119
|
notifications_service_1.NotificationsService,
|
|
145
120
|
user_repository_1.UserRepository,
|