rl-core-api 0.1.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 +99 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.module.js +19 -0
- package/dist/core/auth/authenticatedUser.interface.d.ts +16 -0
- package/dist/core/auth/authenticatedUser.interface.js +2 -0
- package/dist/core/auth/cookie.util.d.ts +9 -0
- package/dist/core/auth/cookie.util.js +28 -0
- package/dist/core/auth/decorators/currentUser.decorator.d.ts +2 -0
- package/dist/core/auth/decorators/currentUser.decorator.js +9 -0
- package/dist/core/auth/decorators/public.decorator.d.ts +3 -0
- package/dist/core/auth/decorators/public.decorator.js +7 -0
- package/dist/core/auth/decorators/requirePermission.decorator.d.ts +5 -0
- package/dist/core/auth/decorators/requirePermission.decorator.js +10 -0
- package/dist/core/auth/guards/appThrottler.guard.d.ts +5 -0
- package/dist/core/auth/guards/appThrottler.guard.js +23 -0
- package/dist/core/auth/guards/csrf.guard.d.ts +8 -0
- package/dist/core/auth/guards/csrf.guard.js +55 -0
- package/dist/core/auth/guards/jwtAuth.guard.d.ts +10 -0
- package/dist/core/auth/guards/jwtAuth.guard.js +37 -0
- package/dist/core/auth/guards/permissions.guard.d.ts +7 -0
- package/dist/core/auth/guards/permissions.guard.js +42 -0
- package/dist/core/bootstrap/bootstrapCore.util.d.ts +9 -0
- package/dist/core/bootstrap/bootstrapCore.util.js +67 -0
- package/dist/core/config/config.module.d.ts +8 -0
- package/dist/core/config/config.module.js +34 -0
- package/dist/core/config/env.schema.d.ts +65 -0
- package/dist/core/config/env.schema.js +94 -0
- package/dist/core/config/env.service.d.ts +7 -0
- package/dist/core/config/env.service.js +27 -0
- package/dist/core/context/auditContext.d.ts +7 -0
- package/dist/core/context/auditContext.js +5 -0
- package/dist/core/core.module.d.ts +11 -0
- package/dist/core/core.module.js +73 -0
- package/dist/core/database/base.schema.d.ts +7 -0
- package/dist/core/database/base.schema.js +49 -0
- package/dist/core/database/createDataSource.util.d.ts +8 -0
- package/dist/core/database/createDataSource.util.js +27 -0
- package/dist/core/database/migrations/1710000000000-InitialSchema.d.ts +6 -0
- package/dist/core/database/migrations/1710000000000-InitialSchema.js +272 -0
- package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.d.ts +6 -0
- package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.js +19 -0
- package/dist/core/database/migrations/1786147200000-PermanentAccountLock.d.ts +6 -0
- package/dist/core/database/migrations/1786147200000-PermanentAccountLock.js +15 -0
- package/dist/core/database/migrations/1786233600000-Notifications.d.ts +6 -0
- package/dist/core/database/migrations/1786233600000-Notifications.js +59 -0
- package/dist/core/database/migrations/index.d.ts +3 -0
- package/dist/core/database/migrations/index.js +13 -0
- package/dist/core/database/seeds/runSeeds.d.ts +1 -0
- package/dist/core/database/seeds/runSeeds.js +20 -0
- package/dist/core/database/seeds/seedAdmin.d.ts +2 -0
- package/dist/core/database/seeds/seedAdmin.js +44 -0
- package/dist/core/database/seeds/seedPermissions.d.ts +2 -0
- package/dist/core/database/seeds/seedPermissions.js +93 -0
- package/dist/core/events/appEvent.enum.d.ts +31 -0
- package/dist/core/events/appEvent.enum.js +12 -0
- package/dist/core/filters/allExceptions.filter.d.ts +5 -0
- package/dist/core/filters/allExceptions.filter.js +61 -0
- package/dist/core/filters/appErrorCode.enum.d.ts +9 -0
- package/dist/core/filters/appErrorCode.enum.js +13 -0
- package/dist/core/health/health.controller.d.ts +11 -0
- package/dist/core/health/health.controller.js +56 -0
- package/dist/core/logger/winston.config.d.ts +2 -0
- package/dist/core/logger/winston.config.js +74 -0
- package/dist/core/mailer/mailer.module.d.ts +2 -0
- package/dist/core/mailer/mailer.module.js +21 -0
- package/dist/core/mailer/mailer.service.d.ts +14 -0
- package/dist/core/mailer/mailer.service.js +148 -0
- package/dist/core/openapi/exportOpenapi.d.ts +1 -0
- package/dist/core/openapi/exportOpenapi.js +25 -0
- package/dist/core/query/applyFilter.util.d.ts +11 -0
- package/dist/core/query/applyFilter.util.js +122 -0
- package/dist/core/query/filter.constants.d.ts +7 -0
- package/dist/core/query/filter.constants.js +64 -0
- package/dist/core/query/filterField.interface.d.ts +35 -0
- package/dist/core/query/filterField.interface.js +2 -0
- package/dist/core/query/filterFieldType.enum.d.ts +10 -0
- package/dist/core/query/filterFieldType.enum.js +14 -0
- package/dist/core/query/filterOperator.enum.d.ts +23 -0
- package/dist/core/query/filterOperator.enum.js +28 -0
- package/dist/core/query/filterSchema.response.d.ts +17 -0
- package/dist/core/query/filterSchema.response.js +82 -0
- package/dist/core/query/filterSort.util.d.ts +7 -0
- package/dist/core/query/filterSort.util.js +11 -0
- package/dist/core/query/paginateWithFilter.util.d.ts +11 -0
- package/dist/core/query/paginateWithFilter.util.js +37 -0
- package/dist/core/query/parseFilter.util.d.ts +2 -0
- package/dist/core/query/parseFilter.util.js +220 -0
- package/dist/core/utils/codedError.util.d.ts +5 -0
- package/dist/core/utils/codedError.util.js +23 -0
- package/dist/core/utils/crypto.util.d.ts +2 -0
- package/dist/core/utils/crypto.util.js +39 -0
- package/dist/core/utils/hash.util.d.ts +6 -0
- package/dist/core/utils/hash.util.js +67 -0
- package/dist/core/utils/ip.util.d.ts +1 -0
- package/dist/core/utils/ip.util.js +15 -0
- package/dist/core/utils/pagination.util.d.ts +21 -0
- package/dist/core/utils/pagination.util.js +98 -0
- package/dist/core/utils/paginationMeta.response.d.ts +7 -0
- package/dist/core/utils/paginationMeta.response.js +32 -0
- package/dist/core/utils/password.constants.d.ts +2 -0
- package/dist/core/utils/password.constants.js +5 -0
- package/dist/core/websocket/baseGateway.d.ts +21 -0
- package/dist/core/websocket/baseGateway.js +63 -0
- package/dist/core/websocket/socket.constants.d.ts +4 -0
- package/dist/core/websocket/socket.constants.js +9 -0
- package/dist/core/websocket/socketEvent.envelope.d.ts +8 -0
- package/dist/core/websocket/socketEvent.envelope.js +11 -0
- package/dist/core/websocket/socketOrigin.util.d.ts +2 -0
- package/dist/core/websocket/socketOrigin.util.js +15 -0
- package/dist/core/websocket/wsAuth.service.d.ts +20 -0
- package/dist/core/websocket/wsAuth.service.js +97 -0
- package/dist/core/websocket/wsUserResolver.interface.d.ts +5 -0
- package/dist/core/websocket/wsUserResolver.interface.js +4 -0
- package/dist/coreEntities.d.ts +12 -0
- package/dist/coreEntities.js +35 -0
- package/dist/dataSource.d.ts +3 -0
- package/dist/dataSource.js +13 -0
- package/dist/features/audit/audit.module.d.ts +2 -0
- package/dist/features/audit/audit.module.js +44 -0
- package/dist/features/audit/domain/audit.service.d.ts +34 -0
- package/dist/features/audit/domain/audit.service.js +93 -0
- package/dist/features/audit/domain/classifyError.util.d.ts +2 -0
- package/dist/features/audit/domain/classifyError.util.js +24 -0
- package/dist/features/audit/domain/index.d.ts +2 -0
- package/dist/features/audit/domain/index.js +18 -0
- package/dist/features/audit/infra/auditData.subscriber.d.ts +17 -0
- package/dist/features/audit/infra/auditData.subscriber.js +139 -0
- package/dist/features/audit/infra/index.d.ts +7 -0
- package/dist/features/audit/infra/index.js +23 -0
- package/dist/features/audit/infra/repositories/auditChange.repository.d.ts +7 -0
- package/dist/features/audit/infra/repositories/auditChange.repository.js +35 -0
- package/dist/features/audit/infra/repositories/auditDataChange.repository.d.ts +7 -0
- package/dist/features/audit/infra/repositories/auditDataChange.repository.js +35 -0
- package/dist/features/audit/infra/repositories/errorLog.repository.d.ts +7 -0
- package/dist/features/audit/infra/repositories/errorLog.repository.js +35 -0
- package/dist/features/audit/infra/schema/auditChange.schema.d.ts +14 -0
- package/dist/features/audit/infra/schema/auditChange.schema.js +68 -0
- package/dist/features/audit/infra/schema/auditDataChange.schema.d.ts +15 -0
- package/dist/features/audit/infra/schema/auditDataChange.schema.js +56 -0
- package/dist/features/audit/infra/schema/errorLog.schema.d.ts +21 -0
- package/dist/features/audit/infra/schema/errorLog.schema.js +69 -0
- package/dist/features/audit/presentation/audit.controller.d.ts +16 -0
- package/dist/features/audit/presentation/audit.controller.js +107 -0
- package/dist/features/audit/presentation/audit.interceptor.d.ts +8 -0
- package/dist/features/audit/presentation/audit.interceptor.js +78 -0
- package/dist/features/audit/presentation/filters/audit.filters.d.ts +4 -0
- package/dist/features/audit/presentation/filters/audit.filters.js +154 -0
- package/dist/features/audit/presentation/index.d.ts +2 -0
- package/dist/features/audit/presentation/index.js +18 -0
- package/dist/features/audit/presentation/responses/auditDataChange.response.d.ts +25 -0
- package/dist/features/audit/presentation/responses/auditDataChange.response.js +96 -0
- package/dist/features/audit/presentation/responses/log.response.d.ts +45 -0
- package/dist/features/audit/presentation/responses/log.response.js +164 -0
- package/dist/features/auth/auth.module.d.ts +2 -0
- package/dist/features/auth/auth.module.js +55 -0
- package/dist/features/auth/domain/auth.service.d.ts +66 -0
- package/dist/features/auth/domain/auth.service.js +289 -0
- package/dist/features/auth/domain/index.d.ts +5 -0
- package/dist/features/auth/domain/index.js +21 -0
- package/dist/features/auth/domain/jwtPayload.interface.d.ts +11 -0
- package/dist/features/auth/domain/jwtPayload.interface.js +2 -0
- package/dist/features/auth/domain/token.service.d.ts +56 -0
- package/dist/features/auth/domain/token.service.js +205 -0
- package/dist/features/auth/domain/twoFactor.service.d.ts +19 -0
- package/dist/features/auth/domain/twoFactor.service.js +103 -0
- package/dist/features/auth/domain/wsUserResolver.service.d.ts +10 -0
- package/dist/features/auth/domain/wsUserResolver.service.js +34 -0
- package/dist/features/auth/infra/index.d.ts +2 -0
- package/dist/features/auth/infra/index.js +18 -0
- package/dist/features/auth/infra/repositories/authToken.repository.d.ts +5 -0
- package/dist/features/auth/infra/repositories/authToken.repository.js +25 -0
- package/dist/features/auth/infra/schema/authToken.schema.d.ts +21 -0
- package/dist/features/auth/infra/schema/authToken.schema.js +73 -0
- package/dist/features/auth/presentation/auth.controller.d.ts +56 -0
- package/dist/features/auth/presentation/auth.controller.js +242 -0
- package/dist/features/auth/presentation/commands/clientType.enum.d.ts +4 -0
- package/dist/features/auth/presentation/commands/clientType.enum.js +8 -0
- package/dist/features/auth/presentation/commands/login.command.d.ts +4 -0
- package/dist/features/auth/presentation/commands/login.command.js +28 -0
- package/dist/features/auth/presentation/commands/password.command.d.ts +7 -0
- package/dist/features/auth/presentation/commands/password.command.js +37 -0
- package/dist/features/auth/presentation/commands/refreshToken.command.d.ts +3 -0
- package/dist/features/auth/presentation/commands/refreshToken.command.js +26 -0
- package/dist/features/auth/presentation/commands/twoFactor.command.d.ts +12 -0
- package/dist/features/auth/presentation/commands/twoFactor.command.js +68 -0
- package/dist/features/auth/presentation/index.d.ts +7 -0
- package/dist/features/auth/presentation/index.js +23 -0
- package/dist/features/auth/presentation/responses/sessionUser.response.d.ts +19 -0
- package/dist/features/auth/presentation/responses/sessionUser.response.js +90 -0
- package/dist/features/auth/presentation/strategies/jwt.strategy.d.ts +18 -0
- package/dist/features/auth/presentation/strategies/jwt.strategy.js +59 -0
- package/dist/features/auth/token.module.d.ts +2 -0
- package/dist/features/auth/token.module.js +23 -0
- package/dist/features/maintenance/domain/cleanup.service.d.ts +22 -0
- package/dist/features/maintenance/domain/cleanup.service.js +142 -0
- package/dist/features/maintenance/maintenance.module.d.ts +2 -0
- package/dist/features/maintenance/maintenance.module.js +24 -0
- package/dist/features/notifications/domain/enums/channelType.enum.d.ts +7 -0
- package/dist/features/notifications/domain/enums/channelType.enum.js +11 -0
- package/dist/features/notifications/domain/enums/deliveryStatus.enum.d.ts +8 -0
- package/dist/features/notifications/domain/enums/deliveryStatus.enum.js +12 -0
- package/dist/features/notifications/domain/enums/notificationType.enum.d.ts +6 -0
- package/dist/features/notifications/domain/enums/notificationType.enum.js +10 -0
- package/dist/features/notifications/domain/enums/scopeType.enum.d.ts +5 -0
- package/dist/features/notifications/domain/enums/scopeType.enum.js +9 -0
- package/dist/features/notifications/domain/notifications.service.d.ts +45 -0
- package/dist/features/notifications/domain/notifications.service.js +101 -0
- package/dist/features/notifications/infra/repositories/notification.repository.d.ts +14 -0
- package/dist/features/notifications/infra/repositories/notification.repository.js +74 -0
- package/dist/features/notifications/infra/repositories/notificationRead.repository.d.ts +6 -0
- package/dist/features/notifications/infra/repositories/notificationRead.repository.js +40 -0
- package/dist/features/notifications/infra/repositories/notificationScope.repository.d.ts +5 -0
- package/dist/features/notifications/infra/repositories/notificationScope.repository.js +25 -0
- package/dist/features/notifications/infra/schema/notification.schema.d.ts +13 -0
- package/dist/features/notifications/infra/schema/notification.schema.js +52 -0
- package/dist/features/notifications/infra/schema/notificationRead.schema.d.ts +7 -0
- package/dist/features/notifications/infra/schema/notificationRead.schema.js +38 -0
- package/dist/features/notifications/infra/schema/notificationScope.schema.d.ts +9 -0
- package/dist/features/notifications/infra/schema/notificationScope.schema.js +43 -0
- package/dist/features/notifications/notifications.module.d.ts +2 -0
- package/dist/features/notifications/notifications.module.js +45 -0
- package/dist/features/notifications/presentation/commands/createNotification.command.d.ts +13 -0
- package/dist/features/notifications/presentation/commands/createNotification.command.js +72 -0
- package/dist/features/notifications/presentation/domainEvents.listener.d.ts +13 -0
- package/dist/features/notifications/presentation/domainEvents.listener.js +121 -0
- package/dist/features/notifications/presentation/notifications.controller.d.ts +16 -0
- package/dist/features/notifications/presentation/notifications.controller.js +108 -0
- package/dist/features/notifications/presentation/notifications.gateway.d.ts +13 -0
- package/dist/features/notifications/presentation/notifications.gateway.js +58 -0
- package/dist/features/notifications/presentation/notifications.publisher.d.ts +9 -0
- package/dist/features/notifications/presentation/notifications.publisher.js +42 -0
- package/dist/features/notifications/presentation/responses/notification.response.d.ts +18 -0
- package/dist/features/notifications/presentation/responses/notification.response.js +72 -0
- package/dist/features/rbac/domain/index.d.ts +2 -0
- package/dist/features/rbac/domain/index.js +18 -0
- package/dist/features/rbac/domain/rbac.catalog.d.ts +21 -0
- package/dist/features/rbac/domain/rbac.catalog.js +153 -0
- package/dist/features/rbac/domain/rbac.service.d.ts +68 -0
- package/dist/features/rbac/domain/rbac.service.js +436 -0
- package/dist/features/rbac/infra/index.d.ts +12 -0
- package/dist/features/rbac/infra/index.js +28 -0
- package/dist/features/rbac/infra/repositories/action.repository.d.ts +5 -0
- package/dist/features/rbac/infra/repositories/action.repository.js +25 -0
- package/dist/features/rbac/infra/repositories/group.repository.d.ts +5 -0
- package/dist/features/rbac/infra/repositories/group.repository.js +25 -0
- package/dist/features/rbac/infra/repositories/permission.repository.d.ts +5 -0
- package/dist/features/rbac/infra/repositories/permission.repository.js +25 -0
- package/dist/features/rbac/infra/repositories/resource.repository.d.ts +5 -0
- package/dist/features/rbac/infra/repositories/resource.repository.js +25 -0
- package/dist/features/rbac/infra/repositories/role.repository.d.ts +5 -0
- package/dist/features/rbac/infra/repositories/role.repository.js +25 -0
- package/dist/features/rbac/infra/repositories/scope.repository.d.ts +5 -0
- package/dist/features/rbac/infra/repositories/scope.repository.js +25 -0
- package/dist/features/rbac/infra/schema/action.schema.d.ts +6 -0
- package/dist/features/rbac/infra/schema/action.schema.js +36 -0
- package/dist/features/rbac/infra/schema/group.schema.d.ts +12 -0
- package/dist/features/rbac/infra/schema/group.schema.js +60 -0
- package/dist/features/rbac/infra/schema/permission.schema.d.ts +15 -0
- package/dist/features/rbac/infra/schema/permission.schema.js +66 -0
- package/dist/features/rbac/infra/schema/resource.schema.d.ts +6 -0
- package/dist/features/rbac/infra/schema/resource.schema.js +36 -0
- package/dist/features/rbac/infra/schema/role.schema.d.ts +8 -0
- package/dist/features/rbac/infra/schema/role.schema.js +46 -0
- package/dist/features/rbac/infra/schema/scope.schema.d.ts +6 -0
- package/dist/features/rbac/infra/schema/scope.schema.js +36 -0
- package/dist/features/rbac/presentation/commands/createAction.command.d.ts +4 -0
- package/dist/features/rbac/presentation/commands/createAction.command.js +32 -0
- package/dist/features/rbac/presentation/commands/createGroup.command.d.ts +7 -0
- package/dist/features/rbac/presentation/commands/createGroup.command.js +54 -0
- package/dist/features/rbac/presentation/commands/createPermission.command.d.ts +4 -0
- package/dist/features/rbac/presentation/commands/createPermission.command.js +35 -0
- package/dist/features/rbac/presentation/commands/createResource.command.d.ts +4 -0
- package/dist/features/rbac/presentation/commands/createResource.command.js +32 -0
- package/dist/features/rbac/presentation/commands/createRole.command.d.ts +5 -0
- package/dist/features/rbac/presentation/commands/createRole.command.js +38 -0
- package/dist/features/rbac/presentation/commands/createScope.command.d.ts +4 -0
- package/dist/features/rbac/presentation/commands/createScope.command.js +32 -0
- package/dist/features/rbac/presentation/commands/updateAction.command.d.ts +6 -0
- package/dist/features/rbac/presentation/commands/updateAction.command.js +24 -0
- package/dist/features/rbac/presentation/commands/updateGroup.command.d.ts +6 -0
- package/dist/features/rbac/presentation/commands/updateGroup.command.js +24 -0
- package/dist/features/rbac/presentation/commands/updatePermission.command.d.ts +6 -0
- package/dist/features/rbac/presentation/commands/updatePermission.command.js +24 -0
- package/dist/features/rbac/presentation/commands/updateResource.command.d.ts +6 -0
- package/dist/features/rbac/presentation/commands/updateResource.command.js +24 -0
- package/dist/features/rbac/presentation/commands/updateRole.command.d.ts +6 -0
- package/dist/features/rbac/presentation/commands/updateRole.command.js +24 -0
- package/dist/features/rbac/presentation/commands/updateScope.command.d.ts +6 -0
- package/dist/features/rbac/presentation/commands/updateScope.command.js +24 -0
- package/dist/features/rbac/presentation/index.d.ts +13 -0
- package/dist/features/rbac/presentation/index.js +29 -0
- package/dist/features/rbac/presentation/rbac.controller.d.ts +54 -0
- package/dist/features/rbac/presentation/rbac.controller.js +413 -0
- package/dist/features/rbac/presentation/responses/rbac.response.d.ts +47 -0
- package/dist/features/rbac/presentation/responses/rbac.response.js +161 -0
- package/dist/features/rbac/rbac.module.d.ts +2 -0
- package/dist/features/rbac/rbac.module.js +55 -0
- package/dist/features/users/domain/avatar.service.d.ts +4 -0
- package/dist/features/users/domain/avatar.service.js +61 -0
- package/dist/features/users/domain/index.d.ts +2 -0
- package/dist/features/users/domain/index.js +18 -0
- package/dist/features/users/domain/users.service.d.ts +46 -0
- package/dist/features/users/domain/users.service.js +291 -0
- package/dist/features/users/infra/index.d.ts +4 -0
- package/dist/features/users/infra/index.js +20 -0
- package/dist/features/users/infra/repositories/passwordHistory.repository.d.ts +5 -0
- package/dist/features/users/infra/repositories/passwordHistory.repository.js +25 -0
- package/dist/features/users/infra/repositories/user.repository.d.ts +8 -0
- package/dist/features/users/infra/repositories/user.repository.js +56 -0
- package/dist/features/users/infra/schema/passwordHistory.schema.d.ts +5 -0
- package/dist/features/users/infra/schema/passwordHistory.schema.js +29 -0
- package/dist/features/users/infra/schema/user.schema.d.ts +28 -0
- package/dist/features/users/infra/schema/user.schema.js +153 -0
- package/dist/features/users/presentation/commands/changePassword.command.d.ts +4 -0
- package/dist/features/users/presentation/commands/changePassword.command.js +29 -0
- package/dist/features/users/presentation/commands/createUser.command.d.ts +8 -0
- package/dist/features/users/presentation/commands/createUser.command.js +56 -0
- package/dist/features/users/presentation/commands/updateProfile.command.d.ts +5 -0
- package/dist/features/users/presentation/commands/updateProfile.command.js +38 -0
- package/dist/features/users/presentation/commands/updateUser.command.d.ts +5 -0
- package/dist/features/users/presentation/commands/updateUser.command.js +8 -0
- package/dist/features/users/presentation/filters/users.filters.d.ts +3 -0
- package/dist/features/users/presentation/filters/users.filters.js +62 -0
- package/dist/features/users/presentation/index.d.ts +5 -0
- package/dist/features/users/presentation/index.js +21 -0
- package/dist/features/users/presentation/responses/user.response.d.ts +25 -0
- package/dist/features/users/presentation/responses/user.response.js +95 -0
- package/dist/features/users/presentation/users.controller.d.ts +30 -0
- package/dist/features/users/presentation/users.controller.js +247 -0
- package/dist/features/users/users.module.d.ts +2 -0
- package/dist/features/users/users.module.js +42 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +149 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +5 -0
- package/dist/rlCore.module.d.ts +10 -0
- package/dist/rlCore.module.js +42 -0
- package/package.json +139 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseGateway = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const socket_constants_1 = require("./socket.constants");
|
|
6
|
+
const socketEvent_envelope_1 = require("./socketEvent.envelope");
|
|
7
|
+
const socketOrigin_util_1 = require("./socketOrigin.util");
|
|
8
|
+
class BaseGateway {
|
|
9
|
+
constructor(wsAuth, env) {
|
|
10
|
+
this.wsAuth = wsAuth;
|
|
11
|
+
this.env = env;
|
|
12
|
+
this.logger = new common_1.Logger(this.constructor.name);
|
|
13
|
+
}
|
|
14
|
+
async handleConnection(socket) {
|
|
15
|
+
const resolved = await this.wsAuth.resolve(socket);
|
|
16
|
+
if (!resolved) {
|
|
17
|
+
socket.disconnect(true);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (resolved.source === "cookie") {
|
|
21
|
+
const allowed = (0, socketOrigin_util_1.parseAllowedOrigins)(this.env.get("CORS_ORIGIN"));
|
|
22
|
+
if (!(0, socketOrigin_util_1.isAllowedOrigin)(socket.handshake.headers.origin, allowed)) {
|
|
23
|
+
this.logger.warn(`Handshake recusado por origem: ${socket.handshake.headers.origin ?? "(ausente)"}`);
|
|
24
|
+
socket.disconnect(true);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const data = socket.data;
|
|
29
|
+
data.user = resolved.user;
|
|
30
|
+
await socket.join([
|
|
31
|
+
(0, socket_constants_1.userRoom)(resolved.user.id),
|
|
32
|
+
...resolved.user.roles.map(socket_constants_1.roleRoom),
|
|
33
|
+
]);
|
|
34
|
+
this.scheduleExpiry(socket, resolved.expiresAt);
|
|
35
|
+
}
|
|
36
|
+
handleDisconnect(socket) {
|
|
37
|
+
const data = socket.data;
|
|
38
|
+
if (data.expiryTimer) {
|
|
39
|
+
clearTimeout(data.expiryTimer);
|
|
40
|
+
}
|
|
41
|
+
socket.removeAllListeners();
|
|
42
|
+
}
|
|
43
|
+
emitTo(rooms, event, data) {
|
|
44
|
+
const targets = rooms.filter((room) => room.length > 0);
|
|
45
|
+
if (targets.length === 0) {
|
|
46
|
+
this.logger.warn(`Evento ${event} descartado: sem sala de destino`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.server.to(targets).emit(event, (0, socketEvent_envelope_1.wrapSocketEvent)(event, data));
|
|
50
|
+
}
|
|
51
|
+
scheduleExpiry(socket, expiresAt) {
|
|
52
|
+
const ms = expiresAt - Date.now();
|
|
53
|
+
if (ms <= 0) {
|
|
54
|
+
socket.disconnect(true);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const data = socket.data;
|
|
58
|
+
const timer = setTimeout(() => socket.disconnect(true), ms);
|
|
59
|
+
timer.unref();
|
|
60
|
+
data.expiryTimer = timer;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.BaseGateway = BaseGateway;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SESSION_REFRESH_EVENT = exports.roleRoom = exports.userRoom = exports.NOTIFICATIONS_NAMESPACE = void 0;
|
|
4
|
+
exports.NOTIFICATIONS_NAMESPACE = "/notifications";
|
|
5
|
+
const userRoom = (userId) => `user:${userId}`;
|
|
6
|
+
exports.userRoom = userRoom;
|
|
7
|
+
const roleRoom = (roleName) => `role:${roleName}`;
|
|
8
|
+
exports.roleRoom = roleRoom;
|
|
9
|
+
exports.SESSION_REFRESH_EVENT = "session:refresh";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapSocketEvent = exports.SOCKET_EVENT_VERSION = void 0;
|
|
4
|
+
exports.SOCKET_EVENT_VERSION = 1;
|
|
5
|
+
const wrapSocketEvent = (event, data) => ({
|
|
6
|
+
v: exports.SOCKET_EVENT_VERSION,
|
|
7
|
+
event,
|
|
8
|
+
emittedAt: new Date().toISOString(),
|
|
9
|
+
data,
|
|
10
|
+
});
|
|
11
|
+
exports.wrapSocketEvent = wrapSocketEvent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAllowedOrigins = exports.isAllowedOrigin = void 0;
|
|
4
|
+
const isAllowedOrigin = (origin, allowed) => {
|
|
5
|
+
if (!origin) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return allowed.some((entry) => entry.trim() === origin);
|
|
9
|
+
};
|
|
10
|
+
exports.isAllowedOrigin = isAllowedOrigin;
|
|
11
|
+
const parseAllowedOrigins = (corsOrigin) => corsOrigin
|
|
12
|
+
.split(",")
|
|
13
|
+
.map((entry) => entry.trim())
|
|
14
|
+
.filter((entry) => entry.length > 0);
|
|
15
|
+
exports.parseAllowedOrigins = parseAllowedOrigins;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JwtService } from "@nestjs/jwt";
|
|
2
|
+
import { Socket } from "socket.io";
|
|
3
|
+
import { AuthenticatedUser } from "../auth/authenticatedUser.interface";
|
|
4
|
+
import { EnvService } from "../config/env.service";
|
|
5
|
+
import { WsUserResolver } from "./wsUserResolver.interface";
|
|
6
|
+
export type WsTokenSource = "cookie" | "bearer";
|
|
7
|
+
export interface ResolvedWsUser {
|
|
8
|
+
user: AuthenticatedUser;
|
|
9
|
+
source: WsTokenSource;
|
|
10
|
+
expiresAt: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class WsAuthService {
|
|
13
|
+
private readonly jwt;
|
|
14
|
+
private readonly env;
|
|
15
|
+
private readonly resolver;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
constructor(jwt: JwtService, env: EnvService, resolver: WsUserResolver);
|
|
18
|
+
resolve(socket: Socket): Promise<ResolvedWsUser | null>;
|
|
19
|
+
private extractToken;
|
|
20
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var WsAuthService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.WsAuthService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
19
|
+
const cookie_util_1 = require("../auth/cookie.util");
|
|
20
|
+
const env_service_1 = require("../config/env.service");
|
|
21
|
+
const wsUserResolver_interface_1 = require("./wsUserResolver.interface");
|
|
22
|
+
const readCookie = (header, name) => {
|
|
23
|
+
if (!header) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
for (const part of header.split(";")) {
|
|
27
|
+
const separator = part.indexOf("=");
|
|
28
|
+
if (separator < 0) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (part.slice(0, separator).trim() !== name) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const value = part.slice(separator + 1).trim();
|
|
35
|
+
try {
|
|
36
|
+
return decodeURIComponent(value);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|
|
44
|
+
let WsAuthService = WsAuthService_1 = class WsAuthService {
|
|
45
|
+
constructor(jwt, env, resolver) {
|
|
46
|
+
this.jwt = jwt;
|
|
47
|
+
this.env = env;
|
|
48
|
+
this.resolver = resolver;
|
|
49
|
+
this.logger = new common_1.Logger(WsAuthService_1.name);
|
|
50
|
+
}
|
|
51
|
+
async resolve(socket) {
|
|
52
|
+
const extracted = this.extractToken(socket);
|
|
53
|
+
if (!extracted) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const claims = await this.jwt.verifyAsync(extracted.token, { secret: this.env.get("JWT_ACCESS_SECRET") });
|
|
58
|
+
if (claims.purpose !== "access") {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const user = await this.resolver.resolve(claims.sub);
|
|
62
|
+
if (!user) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
user,
|
|
67
|
+
source: extracted.source,
|
|
68
|
+
expiresAt: claims.exp * 1000,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
this.logger.debug(`Handshake recusado: ${err instanceof Error ? err.message : "token inválido"}`);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
extractToken(socket) {
|
|
77
|
+
const fromCookie = readCookie(socket.handshake.headers.cookie, cookie_util_1.ACCESS_COOKIE);
|
|
78
|
+
if (fromCookie) {
|
|
79
|
+
return { token: fromCookie, source: "cookie" };
|
|
80
|
+
}
|
|
81
|
+
const auth = socket.handshake.auth;
|
|
82
|
+
const fromAuth = typeof auth?.token === "string" ? auth.token : undefined;
|
|
83
|
+
const fromHeader = socket.handshake.headers.authorization;
|
|
84
|
+
const bearer = fromAuth ?? fromHeader;
|
|
85
|
+
if (bearer) {
|
|
86
|
+
return { token: bearer.replace(/^Bearer\s+/i, ""), source: "bearer" };
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.WsAuthService = WsAuthService;
|
|
92
|
+
exports.WsAuthService = WsAuthService = WsAuthService_1 = __decorate([
|
|
93
|
+
(0, common_1.Injectable)(),
|
|
94
|
+
__param(2, (0, common_1.Inject)(wsUserResolver_interface_1.WS_USER_RESOLVER)),
|
|
95
|
+
__metadata("design:paramtypes", [jwt_1.JwtService,
|
|
96
|
+
env_service_1.EnvService, Object])
|
|
97
|
+
], WsAuthService);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuditChange } from "./features/audit/infra/schema/auditChange.schema";
|
|
2
|
+
import { AuditDataChange } from "./features/audit/infra/schema/auditDataChange.schema";
|
|
3
|
+
import { ErrorLog } from "./features/audit/infra/schema/errorLog.schema";
|
|
4
|
+
import { AuthToken } from "./features/auth/infra/schema/authToken.schema";
|
|
5
|
+
import { Notification } from "./features/notifications/infra/schema/notification.schema";
|
|
6
|
+
import { NotificationRead } from "./features/notifications/infra/schema/notificationRead.schema";
|
|
7
|
+
import { NotificationScope } from "./features/notifications/infra/schema/notificationScope.schema";
|
|
8
|
+
import { Action } from "./features/rbac/infra/schema/action.schema";
|
|
9
|
+
import { Permission } from "./features/rbac/infra/schema/permission.schema";
|
|
10
|
+
import { PasswordHistory } from "./features/users/infra/schema/passwordHistory.schema";
|
|
11
|
+
import { User } from "./features/users/infra/schema/user.schema";
|
|
12
|
+
export declare const coreEntities: (typeof AuditChange | typeof AuditDataChange | typeof ErrorLog | typeof AuthToken | typeof NotificationRead | typeof Notification | typeof NotificationScope | typeof Action | typeof Permission | typeof PasswordHistory | typeof User)[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coreEntities = void 0;
|
|
4
|
+
const auditChange_schema_1 = require("./features/audit/infra/schema/auditChange.schema");
|
|
5
|
+
const auditDataChange_schema_1 = require("./features/audit/infra/schema/auditDataChange.schema");
|
|
6
|
+
const errorLog_schema_1 = require("./features/audit/infra/schema/errorLog.schema");
|
|
7
|
+
const authToken_schema_1 = require("./features/auth/infra/schema/authToken.schema");
|
|
8
|
+
const notification_schema_1 = require("./features/notifications/infra/schema/notification.schema");
|
|
9
|
+
const notificationRead_schema_1 = require("./features/notifications/infra/schema/notificationRead.schema");
|
|
10
|
+
const notificationScope_schema_1 = require("./features/notifications/infra/schema/notificationScope.schema");
|
|
11
|
+
const action_schema_1 = require("./features/rbac/infra/schema/action.schema");
|
|
12
|
+
const group_schema_1 = require("./features/rbac/infra/schema/group.schema");
|
|
13
|
+
const permission_schema_1 = require("./features/rbac/infra/schema/permission.schema");
|
|
14
|
+
const resource_schema_1 = require("./features/rbac/infra/schema/resource.schema");
|
|
15
|
+
const role_schema_1 = require("./features/rbac/infra/schema/role.schema");
|
|
16
|
+
const scope_schema_1 = require("./features/rbac/infra/schema/scope.schema");
|
|
17
|
+
const passwordHistory_schema_1 = require("./features/users/infra/schema/passwordHistory.schema");
|
|
18
|
+
const user_schema_1 = require("./features/users/infra/schema/user.schema");
|
|
19
|
+
exports.coreEntities = [
|
|
20
|
+
user_schema_1.User,
|
|
21
|
+
passwordHistory_schema_1.PasswordHistory,
|
|
22
|
+
authToken_schema_1.AuthToken,
|
|
23
|
+
resource_schema_1.Resource,
|
|
24
|
+
action_schema_1.Action,
|
|
25
|
+
scope_schema_1.Scope,
|
|
26
|
+
permission_schema_1.Permission,
|
|
27
|
+
role_schema_1.Role,
|
|
28
|
+
group_schema_1.Group,
|
|
29
|
+
auditChange_schema_1.AuditChange,
|
|
30
|
+
errorLog_schema_1.ErrorLog,
|
|
31
|
+
auditDataChange_schema_1.AuditDataChange,
|
|
32
|
+
notification_schema_1.Notification,
|
|
33
|
+
notificationScope_schema_1.NotificationScope,
|
|
34
|
+
notificationRead_schema_1.NotificationRead,
|
|
35
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppDataSource = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const dotenv_1 = require("dotenv");
|
|
6
|
+
const createDataSource_util_1 = require("./core/database/createDataSource.util");
|
|
7
|
+
const migrations_1 = require("./core/database/migrations");
|
|
8
|
+
const coreEntities_1 = require("./coreEntities");
|
|
9
|
+
(0, dotenv_1.config)();
|
|
10
|
+
exports.AppDataSource = (0, createDataSource_util_1.createCoreDataSource)({
|
|
11
|
+
entities: coreEntities_1.coreEntities,
|
|
12
|
+
migrations: migrations_1.coreMigrations,
|
|
13
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AuditModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const core_1 = require("@nestjs/core");
|
|
12
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
13
|
+
const domain_1 = require("./domain");
|
|
14
|
+
const infra_1 = require("./infra");
|
|
15
|
+
const presentation_1 = require("./presentation");
|
|
16
|
+
const user_repository_1 = require("../users/infra/repositories/user.repository");
|
|
17
|
+
const user_schema_1 = require("../users/infra/schema/user.schema");
|
|
18
|
+
let AuditModule = class AuditModule {
|
|
19
|
+
};
|
|
20
|
+
exports.AuditModule = AuditModule;
|
|
21
|
+
exports.AuditModule = AuditModule = __decorate([
|
|
22
|
+
(0, common_1.Module)({
|
|
23
|
+
imports: [
|
|
24
|
+
typeorm_1.TypeOrmModule.forFeature([infra_1.AuditChange, infra_1.ErrorLog, infra_1.AuditDataChange, user_schema_1.User]),
|
|
25
|
+
],
|
|
26
|
+
controllers: [presentation_1.AuditController],
|
|
27
|
+
providers: [
|
|
28
|
+
infra_1.AuditChangeRepository,
|
|
29
|
+
infra_1.ErrorLogRepository,
|
|
30
|
+
infra_1.AuditDataChangeRepository,
|
|
31
|
+
user_repository_1.UserRepository,
|
|
32
|
+
domain_1.AuditService,
|
|
33
|
+
{ provide: core_1.APP_INTERCEPTOR, useClass: presentation_1.AuditInterceptor },
|
|
34
|
+
infra_1.AuditDataSubscriber,
|
|
35
|
+
],
|
|
36
|
+
exports: [
|
|
37
|
+
infra_1.AuditChangeRepository,
|
|
38
|
+
infra_1.ErrorLogRepository,
|
|
39
|
+
infra_1.AuditDataChangeRepository,
|
|
40
|
+
user_repository_1.UserRepository,
|
|
41
|
+
domain_1.AuditService,
|
|
42
|
+
],
|
|
43
|
+
})
|
|
44
|
+
], AuditModule);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Paginated, PaginationQuery } from "../../../core/utils/pagination.util";
|
|
2
|
+
import { AuditChangeRepository } from "../infra/repositories/auditChange.repository";
|
|
3
|
+
import { AuditDataChangeRepository } from "../infra/repositories/auditDataChange.repository";
|
|
4
|
+
import { ErrorLogRepository } from "../infra/repositories/errorLog.repository";
|
|
5
|
+
import { AuditChange } from "../infra/schema/auditChange.schema";
|
|
6
|
+
import { AuditDataChange } from "../infra/schema/auditDataChange.schema";
|
|
7
|
+
import { ErrorLog } from "../infra/schema/errorLog.schema";
|
|
8
|
+
import { UserRepository } from "../../users/infra/repositories/user.repository";
|
|
9
|
+
export type WithUserRef<T> = T & {
|
|
10
|
+
user?: {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
email: string;
|
|
14
|
+
} | null;
|
|
15
|
+
};
|
|
16
|
+
export type AuditDataChangeWithUser = WithUserRef<Pick<AuditDataChange, "id" | "createdAt" | "updatedAt" | "deletedAt" | "entity" | "entityId" | "action" | "oldData" | "newData" | "userId" | "ipAddress">>;
|
|
17
|
+
export declare class AuditService {
|
|
18
|
+
private readonly changeRepo;
|
|
19
|
+
private readonly errorRepo;
|
|
20
|
+
private readonly dataChangeRepo;
|
|
21
|
+
private readonly userRepo;
|
|
22
|
+
private readonly logger;
|
|
23
|
+
constructor(changeRepo: AuditChangeRepository, errorRepo: ErrorLogRepository, dataChangeRepo: AuditDataChangeRepository, userRepo: UserRepository);
|
|
24
|
+
recordChange(data: Partial<AuditChange>): Promise<void>;
|
|
25
|
+
recordError(data: Partial<ErrorLog>): Promise<void>;
|
|
26
|
+
cleanupOldLogs(retentionDays: number): Promise<{
|
|
27
|
+
changes: number;
|
|
28
|
+
errors: number;
|
|
29
|
+
}>;
|
|
30
|
+
listChanges(query: PaginationQuery): Promise<Paginated<WithUserRef<AuditChange>>>;
|
|
31
|
+
listErrors(query: PaginationQuery): Promise<Paginated<WithUserRef<ErrorLog>>>;
|
|
32
|
+
listDataChanges(query: PaginationQuery): Promise<Paginated<AuditDataChangeWithUser>>;
|
|
33
|
+
private enrichWithUser;
|
|
34
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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 AuditService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AuditService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const typeorm_1 = require("typeorm");
|
|
16
|
+
const pagination_util_1 = require("../../../core/utils/pagination.util");
|
|
17
|
+
const auditChange_repository_1 = require("../infra/repositories/auditChange.repository");
|
|
18
|
+
const auditDataChange_repository_1 = require("../infra/repositories/auditDataChange.repository");
|
|
19
|
+
const errorLog_repository_1 = require("../infra/repositories/errorLog.repository");
|
|
20
|
+
const user_repository_1 = require("../../users/infra/repositories/user.repository");
|
|
21
|
+
let AuditService = AuditService_1 = class AuditService {
|
|
22
|
+
constructor(changeRepo, errorRepo, dataChangeRepo, userRepo) {
|
|
23
|
+
this.changeRepo = changeRepo;
|
|
24
|
+
this.errorRepo = errorRepo;
|
|
25
|
+
this.dataChangeRepo = dataChangeRepo;
|
|
26
|
+
this.userRepo = userRepo;
|
|
27
|
+
this.logger = new common_1.Logger(AuditService_1.name);
|
|
28
|
+
}
|
|
29
|
+
async recordChange(data) {
|
|
30
|
+
try {
|
|
31
|
+
await this.changeRepo.save(this.changeRepo.create(data));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
this.logger.warn(`Falha ao gravar AuditChange: ${err.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async recordError(data) {
|
|
38
|
+
try {
|
|
39
|
+
await this.errorRepo.save(this.errorRepo.create(data));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
this.logger.warn(`Falha ao gravar ErrorLog: ${err.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async cleanupOldLogs(retentionDays) {
|
|
46
|
+
const cutoff = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
|
|
47
|
+
const changes = await this.changeRepo.delete({
|
|
48
|
+
createdAt: (0, typeorm_1.LessThan)(cutoff),
|
|
49
|
+
});
|
|
50
|
+
const errors = await this.errorRepo.delete({ createdAt: (0, typeorm_1.LessThan)(cutoff) });
|
|
51
|
+
return { changes: changes.affected ?? 0, errors: errors.affected ?? 0 };
|
|
52
|
+
}
|
|
53
|
+
async listChanges(query) {
|
|
54
|
+
const [items, total] = await this.changeRepo.findPaginated(query);
|
|
55
|
+
return new pagination_util_1.Paginated(await this.enrichWithUser(items), total, query.page, query.limit);
|
|
56
|
+
}
|
|
57
|
+
async listErrors(query) {
|
|
58
|
+
const [items, total] = await this.errorRepo.findPaginated(query);
|
|
59
|
+
return new pagination_util_1.Paginated(await this.enrichWithUser(items), total, query.page, query.limit);
|
|
60
|
+
}
|
|
61
|
+
async listDataChanges(query) {
|
|
62
|
+
const [items, total] = await this.dataChangeRepo.findPaginated(query);
|
|
63
|
+
return new pagination_util_1.Paginated(await this.enrichWithUser(items), total, query.page, query.limit);
|
|
64
|
+
}
|
|
65
|
+
async enrichWithUser(items) {
|
|
66
|
+
const userIds = [
|
|
67
|
+
...new Set(items.map((i) => i.userId).filter((id) => !!id)),
|
|
68
|
+
];
|
|
69
|
+
const usersById = new Map();
|
|
70
|
+
if (userIds.length) {
|
|
71
|
+
const users = await this.userRepo.find({
|
|
72
|
+
where: { id: (0, typeorm_1.In)(userIds) },
|
|
73
|
+
withDeleted: true,
|
|
74
|
+
});
|
|
75
|
+
users.forEach((u) => usersById.set(u.id, u));
|
|
76
|
+
}
|
|
77
|
+
return items.map((item) => {
|
|
78
|
+
const user = item.userId ? usersById.get(item.userId) : undefined;
|
|
79
|
+
return {
|
|
80
|
+
...item,
|
|
81
|
+
user: user ? { id: user.id, name: user.name, email: user.email } : null,
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
exports.AuditService = AuditService;
|
|
87
|
+
exports.AuditService = AuditService = AuditService_1 = __decorate([
|
|
88
|
+
(0, common_1.Injectable)(),
|
|
89
|
+
__metadata("design:paramtypes", [auditChange_repository_1.AuditChangeRepository,
|
|
90
|
+
errorLog_repository_1.ErrorLogRepository,
|
|
91
|
+
auditDataChange_repository_1.AuditDataChangeRepository,
|
|
92
|
+
user_repository_1.UserRepository])
|
|
93
|
+
], AuditService);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classifyError = classifyError;
|
|
4
|
+
const errorLog_schema_1 = require("../infra/schema/errorLog.schema");
|
|
5
|
+
function classifyError(exception, status) {
|
|
6
|
+
if (status === 400) {
|
|
7
|
+
return errorLog_schema_1.ErrorType.VALIDATION;
|
|
8
|
+
}
|
|
9
|
+
if (status === 401 || status === 403) {
|
|
10
|
+
return errorLog_schema_1.ErrorType.AUTH;
|
|
11
|
+
}
|
|
12
|
+
if (status === 404) {
|
|
13
|
+
return errorLog_schema_1.ErrorType.NOT_FOUND;
|
|
14
|
+
}
|
|
15
|
+
if (status === 429) {
|
|
16
|
+
return errorLog_schema_1.ErrorType.RATE_LIMIT;
|
|
17
|
+
}
|
|
18
|
+
const name = exception?.name ?? "";
|
|
19
|
+
if (name.includes("QueryFailedError") ||
|
|
20
|
+
name.includes("EntityNotFoundError")) {
|
|
21
|
+
return errorLog_schema_1.ErrorType.DATABASE;
|
|
22
|
+
}
|
|
23
|
+
return errorLog_schema_1.ErrorType.INTERNAL;
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./audit.service"), exports);
|
|
18
|
+
__exportStar(require("./classifyError.util"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DataSource, EntitySubscriberInterface, InsertEvent, ObjectLiteral, RemoveEvent, SoftRemoveEvent, UpdateEvent } from "typeorm";
|
|
2
|
+
interface AuditableEntity extends ObjectLiteral {
|
|
3
|
+
id?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class AuditDataSubscriber implements EntitySubscriberInterface {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
constructor(dataSource: DataSource);
|
|
8
|
+
afterInsert(event: InsertEvent<AuditableEntity>): Promise<void>;
|
|
9
|
+
afterUpdate(event: UpdateEvent<AuditableEntity>): Promise<void>;
|
|
10
|
+
afterRemove(event: RemoveEvent<AuditableEntity>): Promise<void>;
|
|
11
|
+
afterSoftRemove(event: SoftRemoveEvent<AuditableEntity>): Promise<void>;
|
|
12
|
+
private recordRemoval;
|
|
13
|
+
private snapshot;
|
|
14
|
+
private serialize;
|
|
15
|
+
private persist;
|
|
16
|
+
}
|
|
17
|
+
export {};
|