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.
Files changed (89) hide show
  1. package/README.md +2 -2
  2. package/dist/core/config/env.schema.d.ts +2 -2
  3. package/dist/core/config/env.schema.js +3 -3
  4. package/dist/core/config/env.service.d.ts +1 -0
  5. package/dist/core/config/env.service.js +3 -0
  6. package/dist/core/context/requestLog.context.d.ts +10 -0
  7. package/dist/core/context/requestLog.context.js +26 -0
  8. package/dist/core/database/migrations/1710000000000-InitialSchema.js +63 -36
  9. package/dist/core/database/migrations/index.js +1 -9
  10. package/dist/core/events/appEvent.enum.d.ts +18 -1
  11. package/dist/core/events/appEvent.enum.js +1 -0
  12. package/dist/core/filters/allExceptions.filter.d.ts +6 -0
  13. package/dist/core/filters/allExceptions.filter.js +47 -2
  14. package/dist/core/query/parseFilter.util.js +6 -4
  15. package/dist/core/utils/ip.util.d.ts +1 -0
  16. package/dist/core/utils/ip.util.js +8 -0
  17. package/dist/coreEntities.d.ts +2 -3
  18. package/dist/coreEntities.js +2 -4
  19. package/dist/features/audit/audit.module.js +4 -7
  20. package/dist/features/audit/domain/audit.service.d.ts +6 -15
  21. package/dist/features/audit/domain/audit.service.js +9 -32
  22. package/dist/features/audit/domain/classifyError.util.d.ts +1 -1
  23. package/dist/features/audit/domain/classifyError.util.js +8 -8
  24. package/dist/features/audit/domain/enums/errorType.enum.d.ts +9 -0
  25. package/dist/features/audit/domain/enums/errorType.enum.js +13 -0
  26. package/dist/features/audit/domain/enums/requestOutcome.enum.d.ts +5 -0
  27. package/dist/features/audit/domain/enums/requestOutcome.enum.js +9 -0
  28. package/dist/features/audit/domain/index.d.ts +2 -0
  29. package/dist/features/audit/domain/index.js +2 -0
  30. package/dist/features/audit/infra/auditData.subscriber.js +17 -9
  31. package/dist/features/audit/infra/index.d.ts +2 -4
  32. package/dist/features/audit/infra/index.js +2 -4
  33. package/dist/features/audit/infra/repositories/requestLog.repository.d.ts +7 -0
  34. package/dist/features/audit/infra/repositories/{auditChange.repository.js → requestLog.repository.js} +10 -10
  35. package/dist/features/audit/infra/schema/auditDataChange.schema.d.ts +3 -3
  36. package/dist/features/audit/infra/schema/auditDataChange.schema.js +8 -7
  37. package/dist/features/audit/infra/schema/requestLog.schema.d.ts +20 -0
  38. package/dist/features/audit/infra/schema/requestLog.schema.js +92 -0
  39. package/dist/features/audit/presentation/audit.controller.d.ts +4 -8
  40. package/dist/features/audit/presentation/audit.controller.js +8 -31
  41. package/dist/features/audit/presentation/audit.interceptor.d.ts +5 -1
  42. package/dist/features/audit/presentation/audit.interceptor.js +47 -28
  43. package/dist/features/audit/presentation/decorators/auditable.decorator.d.ts +3 -0
  44. package/dist/features/audit/presentation/decorators/auditable.decorator.js +7 -0
  45. package/dist/features/audit/presentation/filters/audit.filters.d.ts +1 -2
  46. package/dist/features/audit/presentation/filters/audit.filters.js +65 -49
  47. package/dist/features/audit/presentation/httpError.listener.d.ts +8 -0
  48. package/dist/features/audit/presentation/httpError.listener.js +61 -0
  49. package/dist/features/audit/presentation/index.d.ts +2 -0
  50. package/dist/features/audit/presentation/index.js +2 -0
  51. package/dist/features/audit/presentation/responses/auditDataChange.response.js +1 -1
  52. package/dist/features/audit/presentation/responses/log.response.d.ts +12 -27
  53. package/dist/features/audit/presentation/responses/log.response.js +66 -88
  54. package/dist/features/auth/infra/schema/authToken.schema.d.ts +5 -5
  55. package/dist/features/auth/infra/schema/authToken.schema.js +7 -7
  56. package/dist/features/auth/presentation/auth.controller.js +10 -0
  57. package/dist/features/maintenance/domain/cleanup.service.d.ts +1 -4
  58. package/dist/features/maintenance/domain/cleanup.service.js +1 -21
  59. package/dist/features/maintenance/maintenance.module.js +1 -2
  60. package/dist/features/notifications/domain/enums/channelType.enum.d.ts +5 -5
  61. package/dist/features/notifications/domain/enums/channelType.enum.js +5 -5
  62. package/dist/features/notifications/domain/enums/deliveryStatus.enum.d.ts +6 -6
  63. package/dist/features/notifications/domain/enums/deliveryStatus.enum.js +6 -6
  64. package/dist/features/notifications/domain/enums/notificationType.enum.d.ts +4 -4
  65. package/dist/features/notifications/domain/enums/notificationType.enum.js +4 -4
  66. package/dist/features/notifications/domain/enums/scopeType.enum.d.ts +3 -3
  67. package/dist/features/notifications/domain/enums/scopeType.enum.js +3 -3
  68. package/dist/features/notifications/infra/schema/notification.schema.js +2 -2
  69. package/dist/features/notifications/infra/schema/notificationScope.schema.js +2 -2
  70. package/dist/features/notifications/presentation/commands/createNotification.command.js +2 -2
  71. package/dist/features/notifications/presentation/responses/notification.response.js +1 -1
  72. package/dist/features/rbac/presentation/rbac.controller.js +5 -0
  73. package/dist/features/users/presentation/users.controller.js +5 -0
  74. package/dist/index.d.ts +5 -3
  75. package/dist/index.js +10 -6
  76. package/package.json +1 -1
  77. package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.d.ts +0 -6
  78. package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.js +0 -19
  79. package/dist/core/database/migrations/1786147200000-PermanentAccountLock.d.ts +0 -6
  80. package/dist/core/database/migrations/1786147200000-PermanentAccountLock.js +0 -15
  81. package/dist/core/database/migrations/1786233600000-Notifications.d.ts +0 -6
  82. package/dist/core/database/migrations/1786233600000-Notifications.js +0 -59
  83. package/dist/features/audit/infra/repositories/auditChange.repository.d.ts +0 -7
  84. package/dist/features/audit/infra/repositories/errorLog.repository.d.ts +0 -7
  85. package/dist/features/audit/infra/repositories/errorLog.repository.js +0 -35
  86. package/dist/features/audit/infra/schema/auditChange.schema.d.ts +0 -14
  87. package/dist/features/audit/infra/schema/auditChange.schema.js +0 -68
  88. package/dist/features/audit/infra/schema/errorLog.schema.d.ts +0 -21
  89. package/dist/features/audit/infra/schema/errorLog.schema.js +0 -69
@@ -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, audit: AuditService, env: EnvService, notifications: NotificationsService, users: UserRepository, events: EventEmitter2);
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, audit, env, notifications, users, events) {
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,15 +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
- });
50
- }
51
40
  async handleNotificationCleanup() {
52
41
  await this.run("Limpeza de notificações", async () => {
53
42
  const retentionDays = this.env.get("NOTIFICATION_RETENTION_DAYS");
@@ -107,14 +96,6 @@ __decorate([
107
96
  __metadata("design:paramtypes", []),
108
97
  __metadata("design:returntype", Promise)
109
98
  ], CleanupService.prototype, "handleTokenCleanup", null);
110
- __decorate([
111
- (0, schedule_1.Cron)(process.env.AUDIT_LOG_CLEANUP_CRON ?? "0 3 * * *", {
112
- name: "audit-log-cleanup",
113
- }),
114
- __metadata("design:type", Function),
115
- __metadata("design:paramtypes", []),
116
- __metadata("design:returntype", Promise)
117
- ], CleanupService.prototype, "handleAuditLogCleanup", null);
118
99
  __decorate([
119
100
  (0, schedule_1.Cron)(process.env.NOTIFICATION_CLEANUP_CRON ?? "0 4 * * *", {
120
101
  name: "notification-cleanup",
@@ -134,7 +115,6 @@ __decorate([
134
115
  exports.CleanupService = CleanupService = CleanupService_1 = __decorate([
135
116
  (0, common_1.Injectable)(),
136
117
  __metadata("design:paramtypes", [token_service_1.TokenService,
137
- audit_service_1.AuditService,
138
118
  env_service_1.EnvService,
139
119
  notifications_service_1.NotificationsService,
140
120
  user_repository_1.UserRepository,
@@ -8,7 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MaintenanceModule = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
- const audit_module_1 = require("../audit/audit.module");
12
11
  const auth_module_1 = require("../auth/auth.module");
13
12
  const cleanup_service_1 = require("./domain/cleanup.service");
14
13
  const notifications_module_1 = require("../notifications/notifications.module");
@@ -18,7 +17,7 @@ let MaintenanceModule = class MaintenanceModule {
18
17
  exports.MaintenanceModule = MaintenanceModule;
19
18
  exports.MaintenanceModule = MaintenanceModule = __decorate([
20
19
  (0, common_1.Module)({
21
- imports: [auth_module_1.AuthModule, audit_module_1.AuditModule, notifications_module_1.NotificationsModule, users_module_1.UsersModule],
20
+ imports: [auth_module_1.AuthModule, notifications_module_1.NotificationsModule, users_module_1.UsersModule],
22
21
  providers: [cleanup_service_1.CleanupService],
23
22
  })
24
23
  ], MaintenanceModule);
@@ -1,7 +1,7 @@
1
1
  export declare enum ChannelType {
2
- IN_APP = "IN_APP",
3
- EMAIL = "EMAIL",
4
- PUSH = "PUSH",
5
- SMS = "SMS",
6
- WHATSAPP = "WHATSAPP"
2
+ IN_APP = 0,
3
+ EMAIL = 1,
4
+ PUSH = 2,
5
+ SMS = 3,
6
+ WHATSAPP = 4
7
7
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChannelType = void 0;
4
4
  var ChannelType;
5
5
  (function (ChannelType) {
6
- ChannelType["IN_APP"] = "IN_APP";
7
- ChannelType["EMAIL"] = "EMAIL";
8
- ChannelType["PUSH"] = "PUSH";
9
- ChannelType["SMS"] = "SMS";
10
- ChannelType["WHATSAPP"] = "WHATSAPP";
6
+ ChannelType[ChannelType["IN_APP"] = 0] = "IN_APP";
7
+ ChannelType[ChannelType["EMAIL"] = 1] = "EMAIL";
8
+ ChannelType[ChannelType["PUSH"] = 2] = "PUSH";
9
+ ChannelType[ChannelType["SMS"] = 3] = "SMS";
10
+ ChannelType[ChannelType["WHATSAPP"] = 4] = "WHATSAPP";
11
11
  })(ChannelType || (exports.ChannelType = ChannelType = {}));
@@ -1,8 +1,8 @@
1
1
  export declare enum DeliveryStatus {
2
- PENDING = "PENDING",
3
- QUEUED = "QUEUED",
4
- SENT = "SENT",
5
- DELIVERED = "DELIVERED",
6
- FAILED = "FAILED",
7
- CANCELLED = "CANCELLED"
2
+ PENDING = 0,
3
+ QUEUED = 1,
4
+ SENT = 2,
5
+ DELIVERED = 3,
6
+ FAILED = 4,
7
+ CANCELLED = 5
8
8
  }
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeliveryStatus = void 0;
4
4
  var DeliveryStatus;
5
5
  (function (DeliveryStatus) {
6
- DeliveryStatus["PENDING"] = "PENDING";
7
- DeliveryStatus["QUEUED"] = "QUEUED";
8
- DeliveryStatus["SENT"] = "SENT";
9
- DeliveryStatus["DELIVERED"] = "DELIVERED";
10
- DeliveryStatus["FAILED"] = "FAILED";
11
- DeliveryStatus["CANCELLED"] = "CANCELLED";
6
+ DeliveryStatus[DeliveryStatus["PENDING"] = 0] = "PENDING";
7
+ DeliveryStatus[DeliveryStatus["QUEUED"] = 1] = "QUEUED";
8
+ DeliveryStatus[DeliveryStatus["SENT"] = 2] = "SENT";
9
+ DeliveryStatus[DeliveryStatus["DELIVERED"] = 3] = "DELIVERED";
10
+ DeliveryStatus[DeliveryStatus["FAILED"] = 4] = "FAILED";
11
+ DeliveryStatus[DeliveryStatus["CANCELLED"] = 5] = "CANCELLED";
12
12
  })(DeliveryStatus || (exports.DeliveryStatus = DeliveryStatus = {}));
@@ -1,6 +1,6 @@
1
1
  export declare enum NotificationType {
2
- INFO = "INFO",
3
- SUCCESS = "SUCCESS",
4
- WARNING = "WARNING",
5
- ERROR = "ERROR"
2
+ INFO = 0,
3
+ SUCCESS = 1,
4
+ WARNING = 2,
5
+ ERROR = 3
6
6
  }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NotificationType = void 0;
4
4
  var NotificationType;
5
5
  (function (NotificationType) {
6
- NotificationType["INFO"] = "INFO";
7
- NotificationType["SUCCESS"] = "SUCCESS";
8
- NotificationType["WARNING"] = "WARNING";
9
- NotificationType["ERROR"] = "ERROR";
6
+ NotificationType[NotificationType["INFO"] = 0] = "INFO";
7
+ NotificationType[NotificationType["SUCCESS"] = 1] = "SUCCESS";
8
+ NotificationType[NotificationType["WARNING"] = 2] = "WARNING";
9
+ NotificationType[NotificationType["ERROR"] = 3] = "ERROR";
10
10
  })(NotificationType || (exports.NotificationType = NotificationType = {}));
@@ -1,5 +1,5 @@
1
1
  export declare enum ScopeType {
2
- USER = "USER",
3
- ROLE = "ROLE",
4
- ALL = "ALL"
2
+ USER = 0,
3
+ ROLE = 1,
4
+ ALL = 2
5
5
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ScopeType = void 0;
4
4
  var ScopeType;
5
5
  (function (ScopeType) {
6
- ScopeType["USER"] = "USER";
7
- ScopeType["ROLE"] = "ROLE";
8
- ScopeType["ALL"] = "ALL";
6
+ ScopeType[ScopeType["USER"] = 0] = "USER";
7
+ ScopeType[ScopeType["ROLE"] = 1] = "ROLE";
8
+ ScopeType[ScopeType["ALL"] = 2] = "ALL";
9
9
  })(ScopeType || (exports.ScopeType = ScopeType = {}));
@@ -31,8 +31,8 @@ __decorate([
31
31
  __metadata("design:type", Object)
32
32
  ], Notification.prototype, "payload", void 0);
33
33
  __decorate([
34
- (0, typeorm_1.Column)({ type: "enum", enum: notificationType_enum_1.NotificationType }),
35
- __metadata("design:type", String)
34
+ (0, typeorm_1.Column)({ type: "tinyint", unsigned: true }),
35
+ __metadata("design:type", Number)
36
36
  ], Notification.prototype, "type", void 0);
37
37
  __decorate([
38
38
  (0, typeorm_1.Column)({ name: "created_by", type: "char", length: 36, nullable: true }),
@@ -22,8 +22,8 @@ __decorate([
22
22
  __metadata("design:type", String)
23
23
  ], NotificationScope.prototype, "notificationId", void 0);
24
24
  __decorate([
25
- (0, typeorm_1.Column)({ name: "scope_type", type: "enum", enum: scopeType_enum_1.ScopeType }),
26
- __metadata("design:type", String)
25
+ (0, typeorm_1.Column)({ name: "scope_type", type: "tinyint", unsigned: true }),
26
+ __metadata("design:type", Number)
27
27
  ], NotificationScope.prototype, "scopeType", void 0);
28
28
  __decorate([
29
29
  (0, typeorm_1.Column)({ name: "scope_key", type: "varchar", length: 100, nullable: true }),
@@ -21,7 +21,7 @@ exports.NotificationTargetCommand = NotificationTargetCommand;
21
21
  __decorate([
22
22
  (0, swagger_1.ApiProperty)({ enum: scopeType_enum_1.ScopeType, enumName: "ScopeType" }),
23
23
  (0, class_validator_1.IsEnum)(scopeType_enum_1.ScopeType),
24
- __metadata("design:type", String)
24
+ __metadata("design:type", Number)
25
25
  ], NotificationTargetCommand.prototype, "type", void 0);
26
26
  __decorate([
27
27
  (0, swagger_1.ApiProperty)({
@@ -50,7 +50,7 @@ __decorate([
50
50
  __decorate([
51
51
  (0, swagger_1.ApiProperty)({ enum: notificationType_enum_1.NotificationType, enumName: "NotificationType" }),
52
52
  (0, class_validator_1.IsEnum)(notificationType_enum_1.NotificationType),
53
- __metadata("design:type", String)
53
+ __metadata("design:type", Number)
54
54
  ], CreateNotificationCommand.prototype, "type", void 0);
55
55
  __decorate([
56
56
  (0, swagger_1.ApiProperty)({ type: [NotificationTargetCommand] }),
@@ -32,7 +32,7 @@ __decorate([
32
32
  ], UserNotificationResponse.prototype, "body", void 0);
33
33
  __decorate([
34
34
  (0, swagger_1.ApiProperty)({ enum: notificationType_enum_1.NotificationType, enumName: "NotificationType" }),
35
- __metadata("design:type", String)
35
+ __metadata("design:type", Number)
36
36
  ], UserNotificationResponse.prototype, "type", void 0);
37
37
  __decorate([
38
38
  (0, swagger_1.ApiProperty)({
@@ -18,6 +18,7 @@ const swagger_1 = require("@nestjs/swagger");
18
18
  const currentUser_decorator_1 = require("../../../core/auth/decorators/currentUser.decorator");
19
19
  const requirePermission_decorator_1 = require("../../../core/auth/decorators/requirePermission.decorator");
20
20
  const permissions_guard_1 = require("../../../core/auth/guards/permissions.guard");
21
+ const auditable_decorator_1 = require("../../audit/presentation/decorators/auditable.decorator");
21
22
  const rbac_service_1 = require("../domain/rbac.service");
22
23
  const createAction_command_1 = require("./commands/createAction.command");
23
24
  const createGroup_command_1 = require("./commands/createGroup.command");
@@ -318,6 +319,7 @@ __decorate([
318
319
  __metadata("design:returntype", Promise)
319
320
  ], RbacController.prototype, "deleteGroup", null);
320
321
  __decorate([
322
+ (0, auditable_decorator_1.Auditable)("Usuário adicionado ao grupo"),
321
323
  (0, common_1.Post)("groups/:id/users/:userId"),
322
324
  (0, common_1.HttpCode)(204),
323
325
  (0, requirePermission_decorator_1.RequirePermission)("groups:update:any"),
@@ -328,6 +330,7 @@ __decorate([
328
330
  __metadata("design:returntype", Promise)
329
331
  ], RbacController.prototype, "addUserToGroup", null);
330
332
  __decorate([
333
+ (0, auditable_decorator_1.Auditable)("Usuário removido do grupo"),
331
334
  (0, common_1.Delete)("groups/:id/users/:userId"),
332
335
  (0, common_1.HttpCode)(204),
333
336
  (0, requirePermission_decorator_1.RequirePermission)("groups:update:any"),
@@ -384,6 +387,7 @@ __decorate([
384
387
  __metadata("design:returntype", Promise)
385
388
  ], RbacController.prototype, "deleteRole", null);
386
389
  __decorate([
390
+ (0, auditable_decorator_1.Auditable)("Permissão concedida ao papel"),
387
391
  (0, common_1.Post)("roles/:id/permissions/:permissionId"),
388
392
  (0, requirePermission_decorator_1.RequirePermission)("roles:update:any"),
389
393
  (0, swagger_1.ApiOkResponse)({ type: rbac_response_1.RoleResponse }),
@@ -395,6 +399,7 @@ __decorate([
395
399
  __metadata("design:returntype", Promise)
396
400
  ], RbacController.prototype, "addPermissionToRole", null);
397
401
  __decorate([
402
+ (0, auditable_decorator_1.Auditable)("Permissão removida do papel"),
398
403
  (0, common_1.Delete)("roles/:id/permissions/:permissionId"),
399
404
  (0, requirePermission_decorator_1.RequirePermission)("roles:update:any"),
400
405
  (0, swagger_1.ApiOkResponse)({ type: rbac_response_1.RoleResponse }),
@@ -22,6 +22,7 @@ const requirePermission_decorator_1 = require("../../../core/auth/decorators/req
22
22
  const permissions_guard_1 = require("../../../core/auth/guards/permissions.guard");
23
23
  const filterSchema_response_1 = require("../../../core/query/filterSchema.response");
24
24
  const pagination_util_1 = require("../../../core/utils/pagination.util");
25
+ const auditable_decorator_1 = require("../../audit/presentation/decorators/auditable.decorator");
25
26
  const avatar_service_1 = require("../domain/avatar.service");
26
27
  const users_service_1 = require("../domain/users.service");
27
28
  const changePassword_command_1 = require("./commands/changePassword.command");
@@ -105,6 +106,7 @@ __decorate([
105
106
  __metadata("design:returntype", Promise)
106
107
  ], UsersController.prototype, "updateMe", null);
107
108
  __decorate([
109
+ (0, auditable_decorator_1.Auditable)("Troca da própria senha"),
108
110
  (0, common_1.Patch)("me/password"),
109
111
  (0, common_1.HttpCode)(204),
110
112
  __param(0, (0, currentUser_decorator_1.CurrentUser)("id")),
@@ -198,6 +200,7 @@ __decorate([
198
200
  __metadata("design:returntype", Promise)
199
201
  ], UsersController.prototype, "setActive", null);
200
202
  __decorate([
203
+ (0, auditable_decorator_1.Auditable)("Redefinição de senha por administrador"),
201
204
  (0, common_1.Post)(":id/reset-password"),
202
205
  (0, common_1.HttpCode)(204),
203
206
  (0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
@@ -208,6 +211,7 @@ __decorate([
208
211
  __metadata("design:returntype", Promise)
209
212
  ], UsersController.prototype, "sendPasswordResetLink", null);
210
213
  __decorate([
214
+ (0, auditable_decorator_1.Auditable)("Envio de link de primeiro acesso"),
211
215
  (0, common_1.Post)(":id/first-access-link"),
212
216
  (0, common_1.HttpCode)(204),
213
217
  (0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
@@ -218,6 +222,7 @@ __decorate([
218
222
  __metadata("design:returntype", Promise)
219
223
  ], UsersController.prototype, "sendFirstAccessLink", null);
220
224
  __decorate([
225
+ (0, auditable_decorator_1.Auditable)("Reset de 2FA por administrador"),
221
226
  (0, common_1.Post)(":id/reset-2fa"),
222
227
  (0, common_1.HttpCode)(204),
223
228
  (0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
package/dist/index.d.ts CHANGED
@@ -31,9 +31,8 @@ export { PaginationMetaResponse } from "./core/utils/paginationMeta.response";
31
31
  export { BaseEntity } from "./core/database/base.schema";
32
32
  export { seedAdmin } from "./core/database/seeds/seedAdmin";
33
33
  export { seedPermissions } from "./core/database/seeds/seedPermissions";
34
- export { AuditChange } from "./features/audit/infra/schema/auditChange.schema";
35
34
  export { AuditDataChange } from "./features/audit/infra/schema/auditDataChange.schema";
36
- export { ErrorLog } from "./features/audit/infra/schema/errorLog.schema";
35
+ export { RequestLog } from "./features/audit/infra/schema/requestLog.schema";
37
36
  export { AuthToken } from "./features/auth/infra/schema/authToken.schema";
38
37
  export { Notification } from "./features/notifications/infra/schema/notification.schema";
39
38
  export { NotificationRead } from "./features/notifications/infra/schema/notificationRead.schema";
@@ -47,9 +46,12 @@ export { Scope } from "./features/rbac/infra/schema/scope.schema";
47
46
  export { PasswordHistory } from "./features/users/infra/schema/passwordHistory.schema";
48
47
  export { User } from "./features/users/infra/schema/user.schema";
49
48
  export { auditContext, AuditContextStore } from "./core/context/auditContext";
50
- export { AppEvent, SystemCleanupFailedEvent, UserLockedEvent, UserPasswordExpiringEvent, UserPasswordResetRequestedEvent, UserRolesChangedEvent, UserTwoFactorResetEvent, } from "./core/events/appEvent.enum";
49
+ export { AppEvent, HttpErrorEvent, SystemCleanupFailedEvent, UserLockedEvent, UserPasswordExpiringEvent, UserPasswordResetRequestedEvent, UserRolesChangedEvent, UserTwoFactorResetEvent, } from "./core/events/appEvent.enum";
51
50
  export { AppErrorCode } from "./core/filters/appErrorCode.enum";
52
51
  export { codedBadRequest, codedTooManyRequests, codedUnauthorized, } from "./core/utils/codedError.util";
52
+ export { ErrorType } from "./features/audit/domain/enums/errorType.enum";
53
+ export { RequestOutcome } from "./features/audit/domain/enums/requestOutcome.enum";
54
+ export { Auditable } from "./features/audit/presentation/decorators/auditable.decorator";
53
55
  export { BaseGateway, SocketData } from "./core/websocket/baseGateway";
54
56
  export { NOTIFICATIONS_NAMESPACE, roleRoom, SESSION_REFRESH_EVENT, userRoom, } from "./core/websocket/socket.constants";
55
57
  export { SOCKET_EVENT_VERSION, SocketEvent, wrapSocketEvent, } from "./core/websocket/socketEvent.envelope";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorLog = exports.AuditDataChange = exports.AuditChange = exports.seedPermissions = exports.seedAdmin = exports.BaseEntity = exports.PaginationMetaResponse = exports.resolveOrder = exports.PaginationQuery = exports.Paginated = exports.parseFilter = exports.paginateWithFilter = exports.resolveCatalogOrder = exports.toFilterSchema = exports.FilterOptionResponse = exports.FilterFieldResponse = exports.FilterOperator = exports.FilterCombinator = exports.FilterFieldType = exports.FILTER_MAX_NODES = exports.FILTER_MAX_LENGTH = exports.FILTER_MAX_IN_ITEMS = exports.FILTER_MAX_DEPTH = exports.DEFAULT_OPERATORS = exports.applyFilter = exports.PermissionsGuard = exports.JwtAuthGuard = exports.CsrfGuard = exports.AppThrottlerGuard = exports.RequirePermission = exports.RequireAnyPermission = exports.PERMISSIONS_KEY = exports.ANY_PERMISSIONS_KEY = exports.Public = exports.IS_PUBLIC_KEY = exports.CurrentUser = exports.setAuthCookies = exports.REFRESH_COOKIE = exports.clearAuthCookies = exports.ACCESS_COOKIE = exports.EnvService = exports.validateEnv = exports.envSchema = exports.ConfigModule = exports.RlCoreModule = exports.coreEntities = exports.coreMigrations = exports.createCoreDataSource = exports.CoreModule = exports.bootstrapCore = void 0;
4
- exports.normalizeIp = exports.sha256 = exports.randomToken = exports.numericCode = exports.backupCode = exports.encryptSecret = exports.decryptSecret = exports.MailerService = exports.createAppLogger = exports.WS_USER_RESOLVER = exports.WsAuthService = exports.wrapSocketEvent = exports.SOCKET_EVENT_VERSION = exports.userRoom = exports.SESSION_REFRESH_EVENT = exports.roleRoom = exports.NOTIFICATIONS_NAMESPACE = exports.BaseGateway = exports.codedUnauthorized = exports.codedTooManyRequests = exports.codedBadRequest = exports.AppErrorCode = exports.AppEvent = exports.auditContext = exports.User = exports.PasswordHistory = exports.Scope = exports.Role = exports.Resource = exports.Permission = exports.Group = exports.Action = exports.NotificationScope = exports.NotificationRead = exports.Notification = exports.AuthToken = void 0;
3
+ exports.AuthToken = exports.RequestLog = exports.AuditDataChange = exports.seedPermissions = exports.seedAdmin = exports.BaseEntity = exports.PaginationMetaResponse = exports.resolveOrder = exports.PaginationQuery = exports.Paginated = exports.parseFilter = exports.paginateWithFilter = exports.resolveCatalogOrder = exports.toFilterSchema = exports.FilterOptionResponse = exports.FilterFieldResponse = exports.FilterOperator = exports.FilterCombinator = exports.FilterFieldType = exports.FILTER_MAX_NODES = exports.FILTER_MAX_LENGTH = exports.FILTER_MAX_IN_ITEMS = exports.FILTER_MAX_DEPTH = exports.DEFAULT_OPERATORS = exports.applyFilter = exports.PermissionsGuard = exports.JwtAuthGuard = exports.CsrfGuard = exports.AppThrottlerGuard = exports.RequirePermission = exports.RequireAnyPermission = exports.PERMISSIONS_KEY = exports.ANY_PERMISSIONS_KEY = exports.Public = exports.IS_PUBLIC_KEY = exports.CurrentUser = exports.setAuthCookies = exports.REFRESH_COOKIE = exports.clearAuthCookies = exports.ACCESS_COOKIE = exports.EnvService = exports.validateEnv = exports.envSchema = exports.ConfigModule = exports.RlCoreModule = exports.coreEntities = exports.coreMigrations = exports.createCoreDataSource = exports.CoreModule = exports.bootstrapCore = void 0;
4
+ exports.normalizeIp = exports.sha256 = exports.randomToken = exports.numericCode = exports.backupCode = exports.encryptSecret = exports.decryptSecret = exports.MailerService = exports.createAppLogger = exports.WS_USER_RESOLVER = exports.WsAuthService = exports.wrapSocketEvent = exports.SOCKET_EVENT_VERSION = exports.userRoom = exports.SESSION_REFRESH_EVENT = exports.roleRoom = exports.NOTIFICATIONS_NAMESPACE = exports.BaseGateway = exports.Auditable = exports.RequestOutcome = exports.ErrorType = exports.codedUnauthorized = exports.codedTooManyRequests = exports.codedBadRequest = exports.AppErrorCode = exports.AppEvent = exports.auditContext = exports.User = exports.PasswordHistory = exports.Scope = exports.Role = exports.Resource = exports.Permission = exports.Group = exports.Action = exports.NotificationScope = exports.NotificationRead = exports.Notification = void 0;
5
5
  var bootstrapCore_util_1 = require("./core/bootstrap/bootstrapCore.util");
6
6
  Object.defineProperty(exports, "bootstrapCore", { enumerable: true, get: function () { return bootstrapCore_util_1.bootstrapCore; } });
7
7
  var core_module_1 = require("./core/core.module");
@@ -79,12 +79,10 @@ var seedAdmin_1 = require("./core/database/seeds/seedAdmin");
79
79
  Object.defineProperty(exports, "seedAdmin", { enumerable: true, get: function () { return seedAdmin_1.seedAdmin; } });
80
80
  var seedPermissions_1 = require("./core/database/seeds/seedPermissions");
81
81
  Object.defineProperty(exports, "seedPermissions", { enumerable: true, get: function () { return seedPermissions_1.seedPermissions; } });
82
- var auditChange_schema_1 = require("./features/audit/infra/schema/auditChange.schema");
83
- Object.defineProperty(exports, "AuditChange", { enumerable: true, get: function () { return auditChange_schema_1.AuditChange; } });
84
82
  var auditDataChange_schema_1 = require("./features/audit/infra/schema/auditDataChange.schema");
85
83
  Object.defineProperty(exports, "AuditDataChange", { enumerable: true, get: function () { return auditDataChange_schema_1.AuditDataChange; } });
86
- var errorLog_schema_1 = require("./features/audit/infra/schema/errorLog.schema");
87
- Object.defineProperty(exports, "ErrorLog", { enumerable: true, get: function () { return errorLog_schema_1.ErrorLog; } });
84
+ var requestLog_schema_1 = require("./features/audit/infra/schema/requestLog.schema");
85
+ Object.defineProperty(exports, "RequestLog", { enumerable: true, get: function () { return requestLog_schema_1.RequestLog; } });
88
86
  var authToken_schema_1 = require("./features/auth/infra/schema/authToken.schema");
89
87
  Object.defineProperty(exports, "AuthToken", { enumerable: true, get: function () { return authToken_schema_1.AuthToken; } });
90
88
  var notification_schema_1 = require("./features/notifications/infra/schema/notification.schema");
@@ -119,6 +117,12 @@ var codedError_util_1 = require("./core/utils/codedError.util");
119
117
  Object.defineProperty(exports, "codedBadRequest", { enumerable: true, get: function () { return codedError_util_1.codedBadRequest; } });
120
118
  Object.defineProperty(exports, "codedTooManyRequests", { enumerable: true, get: function () { return codedError_util_1.codedTooManyRequests; } });
121
119
  Object.defineProperty(exports, "codedUnauthorized", { enumerable: true, get: function () { return codedError_util_1.codedUnauthorized; } });
120
+ var errorType_enum_1 = require("./features/audit/domain/enums/errorType.enum");
121
+ Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return errorType_enum_1.ErrorType; } });
122
+ var requestOutcome_enum_1 = require("./features/audit/domain/enums/requestOutcome.enum");
123
+ Object.defineProperty(exports, "RequestOutcome", { enumerable: true, get: function () { return requestOutcome_enum_1.RequestOutcome; } });
124
+ var auditable_decorator_1 = require("./features/audit/presentation/decorators/auditable.decorator");
125
+ Object.defineProperty(exports, "Auditable", { enumerable: true, get: function () { return auditable_decorator_1.Auditable; } });
122
126
  var baseGateway_1 = require("./core/websocket/baseGateway");
123
127
  Object.defineProperty(exports, "BaseGateway", { enumerable: true, get: function () { return baseGateway_1.BaseGateway; } });
124
128
  var socket_constants_1 = require("./core/websocket/socket.constants");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rl-core-api",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Core NestJS: autenticação com 2FA, RBAC, auditoria, notificações e listagens com filtro dinâmico",
5
5
  "author": "Rodrigo Liberti",
6
6
  "license": "MIT",
@@ -1,6 +0,0 @@
1
- import { MigrationInterface, QueryRunner } from "typeorm";
2
- export declare class FirstAccessTokenType1786060800000 implements MigrationInterface {
3
- name: string;
4
- up(queryRunner: QueryRunner): Promise<void>;
5
- down(queryRunner: QueryRunner): Promise<void>;
6
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FirstAccessTokenType1786060800000 = void 0;
4
- class FirstAccessTokenType1786060800000 {
5
- constructor() {
6
- this.name = "FirstAccessTokenType1786060800000";
7
- }
8
- async up(queryRunner) {
9
- await queryRunner.query(`
10
- ALTER TABLE auth_tokens
11
- MODIFY COLUMN type ENUM('password_reset','first_access','two_factor_email','refresh_token','totp_used') NOT NULL
12
- `);
13
- }
14
- async down(queryRunner) {
15
- await queryRunner.query(`DELETE FROM auth_tokens WHERE type = 'first_access'`);
16
- await queryRunner.query(`ALTER TABLE auth_tokens MODIFY COLUMN type varchar(30) NOT NULL`);
17
- }
18
- }
19
- exports.FirstAccessTokenType1786060800000 = FirstAccessTokenType1786060800000;
@@ -1,6 +0,0 @@
1
- import { MigrationInterface, QueryRunner } from "typeorm";
2
- export declare class PermanentAccountLock1786147200000 implements MigrationInterface {
3
- name: string;
4
- up(queryRunner: QueryRunner): Promise<void>;
5
- down(queryRunner: QueryRunner): Promise<void>;
6
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PermanentAccountLock1786147200000 = void 0;
4
- class PermanentAccountLock1786147200000 {
5
- constructor() {
6
- this.name = "PermanentAccountLock1786147200000";
7
- }
8
- async up(queryRunner) {
9
- await queryRunner.query(`ALTER TABLE users DROP COLUMN locked_until`);
10
- }
11
- async down(queryRunner) {
12
- await queryRunner.query(`ALTER TABLE users ADD COLUMN locked_until datetime NULL`);
13
- }
14
- }
15
- exports.PermanentAccountLock1786147200000 = PermanentAccountLock1786147200000;
@@ -1,6 +0,0 @@
1
- import { MigrationInterface, QueryRunner } from "typeorm";
2
- export declare class Notifications1786233600000 implements MigrationInterface {
3
- name: string;
4
- up(queryRunner: QueryRunner): Promise<void>;
5
- down(queryRunner: QueryRunner): Promise<void>;
6
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Notifications1786233600000 = void 0;
4
- class Notifications1786233600000 {
5
- constructor() {
6
- this.name = "Notifications1786233600000";
7
- }
8
- async up(queryRunner) {
9
- const ts = `
10
- created_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
11
- updated_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
12
- deleted_at datetime(6) NULL
13
- `;
14
- await queryRunner.query(`
15
- CREATE TABLE notifications (
16
- id char(36) NOT NULL,
17
- title varchar(255) NOT NULL,
18
- body text NOT NULL,
19
- payload json NULL,
20
- type enum('INFO','SUCCESS','WARNING','ERROR') NOT NULL,
21
- created_by char(36) NULL,
22
- ${ts},
23
- PRIMARY KEY (id),
24
- KEY IDX_notifications_created_at (created_at)
25
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
26
- `);
27
- await queryRunner.query(`
28
- CREATE TABLE notification_scopes (
29
- id char(36) NOT NULL,
30
- notification_id char(36) NOT NULL,
31
- scope_type enum('USER','ROLE','ALL') NOT NULL,
32
- scope_key varchar(100) NULL,
33
- ${ts},
34
- PRIMARY KEY (id),
35
- KEY IDX_notification_scopes_notification (notification_id),
36
- KEY IDX_notification_scopes_target (scope_type, scope_key),
37
- CONSTRAINT FK_notification_scopes_notification
38
- FOREIGN KEY (notification_id) REFERENCES notifications (id) ON DELETE CASCADE
39
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
40
- `);
41
- await queryRunner.query(`
42
- CREATE TABLE notification_reads (
43
- notification_id char(36) NOT NULL,
44
- user_id char(36) NOT NULL,
45
- read_at datetime NOT NULL,
46
- PRIMARY KEY (notification_id, user_id),
47
- KEY IDX_notification_reads_user (user_id),
48
- CONSTRAINT FK_notification_reads_notification
49
- FOREIGN KEY (notification_id) REFERENCES notifications (id) ON DELETE CASCADE
50
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
51
- `);
52
- }
53
- async down(queryRunner) {
54
- await queryRunner.query(`DROP TABLE notification_reads`);
55
- await queryRunner.query(`DROP TABLE notification_scopes`);
56
- await queryRunner.query(`DROP TABLE notifications`);
57
- }
58
- }
59
- exports.Notifications1786233600000 = Notifications1786233600000;
@@ -1,7 +0,0 @@
1
- import { DataSource, Repository } from "typeorm";
2
- import { PaginationQuery } from "../../../../core/utils/pagination.util";
3
- import { AuditChange } from "../schema/auditChange.schema";
4
- export declare class AuditChangeRepository extends Repository<AuditChange> {
5
- constructor(dataSource: DataSource);
6
- findPaginated(query: PaginationQuery): Promise<[AuditChange[], number]>;
7
- }
@@ -1,7 +0,0 @@
1
- import { DataSource, Repository } from "typeorm";
2
- import { PaginationQuery } from "../../../../core/utils/pagination.util";
3
- import { ErrorLog } from "../schema/errorLog.schema";
4
- export declare class ErrorLogRepository extends Repository<ErrorLog> {
5
- constructor(dataSource: DataSource);
6
- findPaginated(query: PaginationQuery): Promise<[ErrorLog[], number]>;
7
- }
@@ -1,35 +0,0 @@
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.ErrorLogRepository = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const typeorm_1 = require("typeorm");
15
- const paginateWithFilter_util_1 = require("../../../../core/query/paginateWithFilter.util");
16
- const errorLog_schema_1 = require("../schema/errorLog.schema");
17
- const audit_filters_1 = require("../../presentation/filters/audit.filters");
18
- let ErrorLogRepository = class ErrorLogRepository extends typeorm_1.Repository {
19
- constructor(dataSource) {
20
- super(errorLog_schema_1.ErrorLog, dataSource.createEntityManager());
21
- }
22
- findPaginated(query) {
23
- return (0, paginateWithFilter_util_1.paginateWithFilter)(this.createQueryBuilder("errorLog"), {
24
- query,
25
- catalog: audit_filters_1.ERROR_LOGS_FILTER_CATALOG,
26
- defaultSort: "createdAt",
27
- searchFields: ["message", "path"],
28
- });
29
- }
30
- };
31
- exports.ErrorLogRepository = ErrorLogRepository;
32
- exports.ErrorLogRepository = ErrorLogRepository = __decorate([
33
- (0, common_1.Injectable)(),
34
- __metadata("design:paramtypes", [typeorm_1.DataSource])
35
- ], ErrorLogRepository);
@@ -1,14 +0,0 @@
1
- import { BaseEntity } from "../../../../core/database/base.schema";
2
- export declare class AuditChange extends BaseEntity {
3
- userId?: string | null;
4
- action: string;
5
- entity?: string | null;
6
- entityId?: string | null;
7
- method?: string | null;
8
- path?: string | null;
9
- ipAddress?: string | null;
10
- statusCode?: number | null;
11
- durationMs?: number | null;
12
- requestId?: string | null;
13
- metadata?: Record<string, unknown> | null;
14
- }