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,164 @@
|
|
|
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.PaginatedErrorLogsResponse = exports.ErrorLogResponse = exports.PaginatedRequestLogsResponse = exports.RequestLogResponse = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const paginationMeta_response_1 = require("../../../../core/utils/paginationMeta.response");
|
|
15
|
+
const errorLog_schema_1 = require("../../infra/schema/errorLog.schema");
|
|
16
|
+
const auditDataChange_response_1 = require("./auditDataChange.response");
|
|
17
|
+
class RequestLogResponse {
|
|
18
|
+
}
|
|
19
|
+
exports.RequestLogResponse = RequestLogResponse;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, swagger_1.ApiProperty)({ format: "uuid" }),
|
|
22
|
+
__metadata("design:type", String)
|
|
23
|
+
], RequestLogResponse.prototype, "id", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, swagger_1.ApiProperty)({ example: "GET /api/v1/users" }),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], RequestLogResponse.prototype, "action", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, example: "User" }),
|
|
30
|
+
__metadata("design:type", Object)
|
|
31
|
+
], RequestLogResponse.prototype, "entity", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
34
|
+
__metadata("design:type", Object)
|
|
35
|
+
], RequestLogResponse.prototype, "entityId", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, example: "GET" }),
|
|
38
|
+
__metadata("design:type", Object)
|
|
39
|
+
], RequestLogResponse.prototype, "method", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
42
|
+
__metadata("design:type", Object)
|
|
43
|
+
], RequestLogResponse.prototype, "path", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true, example: 200 }),
|
|
46
|
+
__metadata("design:type", Object)
|
|
47
|
+
], RequestLogResponse.prototype, "statusCode", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true, example: 42 }),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], 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
|
+
__decorate([
|
|
65
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
66
|
+
__metadata("design:type", Object)
|
|
67
|
+
], RequestLogResponse.prototype, "userId", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, swagger_1.ApiProperty)({ type: auditDataChange_response_1.AuditUserRefResponse, required: false, nullable: true }),
|
|
70
|
+
__metadata("design:type", Object)
|
|
71
|
+
], RequestLogResponse.prototype, "user", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, swagger_1.ApiProperty)({ format: "date-time" }),
|
|
74
|
+
__metadata("design:type", Date)
|
|
75
|
+
], RequestLogResponse.prototype, "createdAt", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, swagger_1.ApiProperty)({ format: "date-time" }),
|
|
78
|
+
__metadata("design:type", Date)
|
|
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 }),
|
|
108
|
+
__metadata("design:type", Object)
|
|
109
|
+
], ErrorLogResponse.prototype, "statusCode", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, swagger_1.ApiProperty)(),
|
|
112
|
+
__metadata("design:type", String)
|
|
113
|
+
], ErrorLogResponse.prototype, "message", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
116
|
+
__metadata("design:type", Object)
|
|
117
|
+
], ErrorLogResponse.prototype, "stack", void 0);
|
|
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);
|
|
122
|
+
__decorate([
|
|
123
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
124
|
+
__metadata("design:type", Object)
|
|
125
|
+
], ErrorLogResponse.prototype, "path", void 0);
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, example: "10.0.0.1" }),
|
|
128
|
+
__metadata("design:type", Object)
|
|
129
|
+
], ErrorLogResponse.prototype, "ipAddress", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true, format: "uuid" }),
|
|
132
|
+
__metadata("design:type", Object)
|
|
133
|
+
], ErrorLogResponse.prototype, "requestId", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, swagger_1.ApiProperty)({ type: String, required: false, nullable: true }),
|
|
136
|
+
__metadata("design:type", Object)
|
|
137
|
+
], ErrorLogResponse.prototype, "userId", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
(0, swagger_1.ApiProperty)({ type: auditDataChange_response_1.AuditUserRefResponse, required: false, nullable: true }),
|
|
140
|
+
__metadata("design:type", Object)
|
|
141
|
+
], ErrorLogResponse.prototype, "user", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
(0, swagger_1.ApiProperty)({ format: "date-time" }),
|
|
144
|
+
__metadata("design:type", Date)
|
|
145
|
+
], ErrorLogResponse.prototype, "createdAt", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
(0, swagger_1.ApiProperty)({ format: "date-time" }),
|
|
148
|
+
__metadata("design:type", Date)
|
|
149
|
+
], ErrorLogResponse.prototype, "updatedAt", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, swagger_1.ApiProperty)({ type: String, format: "date-time", required: false, nullable: true }),
|
|
152
|
+
__metadata("design:type", Object)
|
|
153
|
+
], ErrorLogResponse.prototype, "deletedAt", void 0);
|
|
154
|
+
class PaginatedErrorLogsResponse {
|
|
155
|
+
}
|
|
156
|
+
exports.PaginatedErrorLogsResponse = PaginatedErrorLogsResponse;
|
|
157
|
+
__decorate([
|
|
158
|
+
(0, swagger_1.ApiProperty)({ type: [ErrorLogResponse] }),
|
|
159
|
+
__metadata("design:type", Array)
|
|
160
|
+
], PaginatedErrorLogsResponse.prototype, "items", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
(0, swagger_1.ApiProperty)({ type: paginationMeta_response_1.PaginationMetaResponse }),
|
|
163
|
+
__metadata("design:type", paginationMeta_response_1.PaginationMetaResponse)
|
|
164
|
+
], PaginatedErrorLogsResponse.prototype, "meta", void 0);
|
|
@@ -0,0 +1,55 @@
|
|
|
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.AuthModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const core_1 = require("@nestjs/core");
|
|
12
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
13
|
+
const passport_1 = require("@nestjs/passport");
|
|
14
|
+
const jwtAuth_guard_1 = require("../../core/auth/guards/jwtAuth.guard");
|
|
15
|
+
const env_service_1 = require("../../core/config/env.service");
|
|
16
|
+
const wsAuth_service_1 = require("../../core/websocket/wsAuth.service");
|
|
17
|
+
const wsUserResolver_interface_1 = require("../../core/websocket/wsUserResolver.interface");
|
|
18
|
+
const domain_1 = require("./domain");
|
|
19
|
+
const presentation_1 = require("./presentation");
|
|
20
|
+
const token_module_1 = require("./token.module");
|
|
21
|
+
const rbac_module_1 = require("../rbac/rbac.module");
|
|
22
|
+
const users_module_1 = require("../users/users.module");
|
|
23
|
+
let AuthModule = class AuthModule {
|
|
24
|
+
};
|
|
25
|
+
exports.AuthModule = AuthModule;
|
|
26
|
+
exports.AuthModule = AuthModule = __decorate([
|
|
27
|
+
(0, common_1.Module)({
|
|
28
|
+
imports: [
|
|
29
|
+
token_module_1.TokenModule,
|
|
30
|
+
passport_1.PassportModule,
|
|
31
|
+
jwt_1.JwtModule.registerAsync({
|
|
32
|
+
inject: [env_service_1.EnvService],
|
|
33
|
+
useFactory: (env) => ({
|
|
34
|
+
secret: env.get("JWT_ACCESS_SECRET"),
|
|
35
|
+
signOptions: {
|
|
36
|
+
expiresIn: env.get("JWT_ACCESS_EXPIRES"),
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
}),
|
|
40
|
+
users_module_1.UsersModule,
|
|
41
|
+
rbac_module_1.RbacModule,
|
|
42
|
+
],
|
|
43
|
+
controllers: [presentation_1.AuthController],
|
|
44
|
+
providers: [
|
|
45
|
+
domain_1.AuthService,
|
|
46
|
+
domain_1.TwoFactorService,
|
|
47
|
+
presentation_1.JwtStrategy,
|
|
48
|
+
{ provide: core_1.APP_GUARD, useClass: jwtAuth_guard_1.JwtAuthGuard },
|
|
49
|
+
domain_1.WsUserResolverService,
|
|
50
|
+
{ provide: wsUserResolver_interface_1.WS_USER_RESOLVER, useExisting: domain_1.WsUserResolverService },
|
|
51
|
+
wsAuth_service_1.WsAuthService,
|
|
52
|
+
],
|
|
53
|
+
exports: [token_module_1.TokenModule, wsAuth_service_1.WsAuthService],
|
|
54
|
+
})
|
|
55
|
+
], AuthModule);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { JwtService } from "@nestjs/jwt";
|
|
2
|
+
import { AuthenticatedUser } from "../../../core/auth/authenticatedUser.interface";
|
|
3
|
+
import { EnvService } from "../../../core/config/env.service";
|
|
4
|
+
import { MailerService } from "../../../core/mailer/mailer.service";
|
|
5
|
+
import { PasswordTokenPurpose, PasswordTokenStatus, TokenService } from "./token.service";
|
|
6
|
+
import { TotpSetup, TwoFactorService } from "./twoFactor.service";
|
|
7
|
+
import { LoginCommand } from "../presentation/commands/login.command";
|
|
8
|
+
import { VerifyTwoFactorCommand } from "../presentation/commands/twoFactor.command";
|
|
9
|
+
import { RbacService } from "../../rbac/domain/rbac.service";
|
|
10
|
+
import { UsersService } from "../../users/domain/users.service";
|
|
11
|
+
import { User } from "../../users/infra/schema/user.schema";
|
|
12
|
+
interface RequestCtx {
|
|
13
|
+
ipAddress?: string;
|
|
14
|
+
userAgent?: string;
|
|
15
|
+
}
|
|
16
|
+
export type LoginStatus = "SETUP_REQUIRED" | "TOTP_REQUIRED";
|
|
17
|
+
export type SessionUser = AuthenticatedUser;
|
|
18
|
+
export interface LoginSession {
|
|
19
|
+
accessToken: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
user: SessionUser;
|
|
22
|
+
}
|
|
23
|
+
export interface VerifiedSession extends LoginSession {
|
|
24
|
+
backupCodes?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface RefreshedTokens {
|
|
27
|
+
accessToken: string;
|
|
28
|
+
refreshToken: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PasswordTokenCheck {
|
|
31
|
+
valid: boolean;
|
|
32
|
+
status: PasswordTokenStatus;
|
|
33
|
+
purpose?: PasswordTokenPurpose;
|
|
34
|
+
}
|
|
35
|
+
export declare class AuthService {
|
|
36
|
+
private readonly users;
|
|
37
|
+
private readonly tokens;
|
|
38
|
+
private readonly twoFactor;
|
|
39
|
+
private readonly jwt;
|
|
40
|
+
private readonly env;
|
|
41
|
+
private readonly mailer;
|
|
42
|
+
private readonly rbac;
|
|
43
|
+
private dummyHash?;
|
|
44
|
+
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
|
+
}>;
|
|
49
|
+
setupTotp(pendingToken: string): Promise<TotpSetup>;
|
|
50
|
+
requestEmailCode(pendingToken: string): Promise<{
|
|
51
|
+
sent: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
verifyTwoFactor(dto: VerifyTwoFactorCommand, ctx: RequestCtx): Promise<VerifiedSession>;
|
|
54
|
+
regenerateBackupCodes(userId: string, code: string): Promise<string[]>;
|
|
55
|
+
refresh(rawToken: string | undefined, ctx: RequestCtx): Promise<RefreshedTokens>;
|
|
56
|
+
logout(rawRefreshToken?: string): Promise<void>;
|
|
57
|
+
forgotPassword(email: string): Promise<void>;
|
|
58
|
+
inspectPasswordToken(token: string): Promise<PasswordTokenCheck>;
|
|
59
|
+
resetPassword(token: string, newPassword: string): Promise<void>;
|
|
60
|
+
private buildPendingToken;
|
|
61
|
+
private decodePending;
|
|
62
|
+
private signAccessToken;
|
|
63
|
+
toSessionUser(user: User): Promise<SessionUser>;
|
|
64
|
+
private finalizeLogin;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,289 @@
|
|
|
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.AuthService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
15
|
+
const env_service_1 = require("../../../core/config/env.service");
|
|
16
|
+
const appErrorCode_enum_1 = require("../../../core/filters/appErrorCode.enum");
|
|
17
|
+
const mailer_service_1 = require("../../../core/mailer/mailer.service");
|
|
18
|
+
const codedError_util_1 = require("../../../core/utils/codedError.util");
|
|
19
|
+
const hash_util_1 = require("../../../core/utils/hash.util");
|
|
20
|
+
const token_service_1 = require("./token.service");
|
|
21
|
+
const twoFactor_service_1 = require("./twoFactor.service");
|
|
22
|
+
const rbac_service_1 = require("../../rbac/domain/rbac.service");
|
|
23
|
+
const users_service_1 = require("../../users/domain/users.service");
|
|
24
|
+
const BACKUP_FORMAT = /^[A-Za-z0-9]{4}-[A-Za-z0-9]{4}$/;
|
|
25
|
+
const ACCOUNT_INACTIVE_MESSAGE = "Conta desativada. Entre em contato com o administrador do sistema";
|
|
26
|
+
const ACCOUNT_LOCKED_MESSAGE = "Conta bloqueada por excesso de tentativas. Peça ao administrador o envio de um novo link para definir sua senha";
|
|
27
|
+
const accountLocked = () => (0, codedError_util_1.codedUnauthorized)(ACCOUNT_LOCKED_MESSAGE, appErrorCode_enum_1.AppErrorCode.ACCOUNT_LOCKED);
|
|
28
|
+
const accountInactive = () => (0, codedError_util_1.codedUnauthorized)(ACCOUNT_INACTIVE_MESSAGE, appErrorCode_enum_1.AppErrorCode.ACCOUNT_INACTIVE);
|
|
29
|
+
function attemptsWarning(prefix, remaining) {
|
|
30
|
+
const attempts = remaining === 1 ? "Resta 1 tentativa" : `Restam ${remaining} tentativas`;
|
|
31
|
+
return `${prefix}. ${attempts} antes do bloqueio da conta`;
|
|
32
|
+
}
|
|
33
|
+
const PENDING_EXPIRES = "10m";
|
|
34
|
+
let AuthService = class AuthService {
|
|
35
|
+
constructor(users, tokens, twoFactor, jwt, env, mailer, rbac) {
|
|
36
|
+
this.users = users;
|
|
37
|
+
this.tokens = tokens;
|
|
38
|
+
this.twoFactor = twoFactor;
|
|
39
|
+
this.jwt = jwt;
|
|
40
|
+
this.env = env;
|
|
41
|
+
this.mailer = mailer;
|
|
42
|
+
this.rbac = rbac;
|
|
43
|
+
}
|
|
44
|
+
async login(dto) {
|
|
45
|
+
const generic = (0, codedError_util_1.codedUnauthorized)("Credenciais inválidas", appErrorCode_enum_1.AppErrorCode.INVALID_CREDENTIALS);
|
|
46
|
+
const user = await this.users.findByEmail(dto.email);
|
|
47
|
+
if (!user) {
|
|
48
|
+
this.dummyHash ??= (0, hash_util_1.hashPassword)("dummy-password-for-timing-safety");
|
|
49
|
+
await (0, hash_util_1.verifyPassword)(await this.dummyHash, dto.password);
|
|
50
|
+
throw generic;
|
|
51
|
+
}
|
|
52
|
+
if (!user.isActive) {
|
|
53
|
+
throw accountInactive();
|
|
54
|
+
}
|
|
55
|
+
const maxAttempts = this.env.get("LOGIN_MAX_ATTEMPTS");
|
|
56
|
+
if (user.isLocked(maxAttempts)) {
|
|
57
|
+
throw accountLocked();
|
|
58
|
+
}
|
|
59
|
+
const ok = await (0, hash_util_1.verifyPassword)(user.password, dto.password);
|
|
60
|
+
if (!ok) {
|
|
61
|
+
const remaining = await this.users.registerFailedLogin(user);
|
|
62
|
+
if (remaining === 0) {
|
|
63
|
+
throw accountLocked();
|
|
64
|
+
}
|
|
65
|
+
throw (0, codedError_util_1.codedUnauthorized)(attemptsWarning("Credenciais inválidas", remaining), appErrorCode_enum_1.AppErrorCode.INVALID_CREDENTIALS);
|
|
66
|
+
}
|
|
67
|
+
await this.users.clearLock(user);
|
|
68
|
+
const pendingToken = await this.buildPendingToken(user);
|
|
69
|
+
return {
|
|
70
|
+
status: user.twoFactorEnabled ? "TOTP_REQUIRED" : "SETUP_REQUIRED",
|
|
71
|
+
pendingToken,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async setupTotp(pendingToken) {
|
|
75
|
+
const payload = await this.decodePending(pendingToken);
|
|
76
|
+
if (payload.enrolled) {
|
|
77
|
+
throw new common_1.BadRequestException("2FA já está configurado para esta conta");
|
|
78
|
+
}
|
|
79
|
+
const user = await this.users.findById(payload.sub);
|
|
80
|
+
const setup = await this.twoFactor.generateSetup(user.email);
|
|
81
|
+
user.twoFactorSecret = this.twoFactor.encrypt(setup.secret);
|
|
82
|
+
await this.users.save(user);
|
|
83
|
+
return setup;
|
|
84
|
+
}
|
|
85
|
+
async requestEmailCode(pendingToken) {
|
|
86
|
+
const payload = await this.decodePending(pendingToken);
|
|
87
|
+
if (!payload.enrolled) {
|
|
88
|
+
throw new common_1.BadRequestException("Configure o aplicativo autenticador antes de usar o email como fallback");
|
|
89
|
+
}
|
|
90
|
+
const user = await this.users.findById(payload.sub);
|
|
91
|
+
const code = await this.tokens.issueTwoFactorEmailCode(user.id);
|
|
92
|
+
await this.mailer.sendTwoFactorCode(user.email, code, user.name);
|
|
93
|
+
return { sent: true };
|
|
94
|
+
}
|
|
95
|
+
async verifyTwoFactor(dto, ctx) {
|
|
96
|
+
const payload = await this.decodePending(dto.pendingToken);
|
|
97
|
+
const user = await this.users.findById(payload.sub);
|
|
98
|
+
const maxAttempts = this.env.get("LOGIN_MAX_ATTEMPTS");
|
|
99
|
+
if (user.isLocked(maxAttempts)) {
|
|
100
|
+
throw accountLocked();
|
|
101
|
+
}
|
|
102
|
+
let valid = false;
|
|
103
|
+
let remainingBackup = null;
|
|
104
|
+
const isBackup = dto.method === "backup" || BACKUP_FORMAT.test(dto.code);
|
|
105
|
+
if (isBackup) {
|
|
106
|
+
if (user.backupCodes?.length) {
|
|
107
|
+
remainingBackup = await this.twoFactor.consumeBackupCode(dto.code.toUpperCase(), user.backupCodes);
|
|
108
|
+
valid = remainingBackup !== null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if (dto.method === "email") {
|
|
112
|
+
valid = await this.tokens.consumeTwoFactorEmailCode(user.id, dto.code);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const alreadyUsed = await this.tokens.isTotpCodeUsed(user.id, dto.code);
|
|
116
|
+
valid =
|
|
117
|
+
!alreadyUsed &&
|
|
118
|
+
(await this.twoFactor.verifyTotp(dto.code, user.twoFactorSecret ?? ""));
|
|
119
|
+
if (valid) {
|
|
120
|
+
await this.tokens.markTotpCodeUsed(user.id, dto.code);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
valid = await this.tokens.consumeTwoFactorEmailCode(user.id, dto.code);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!valid) {
|
|
127
|
+
const remaining = await this.users.registerFailedLogin(user);
|
|
128
|
+
if (remaining === 0) {
|
|
129
|
+
throw accountLocked();
|
|
130
|
+
}
|
|
131
|
+
throw (0, codedError_util_1.codedUnauthorized)(attemptsWarning("Código de verificação inválido", remaining), appErrorCode_enum_1.AppErrorCode.INVALID_TWO_FACTOR_CODE);
|
|
132
|
+
}
|
|
133
|
+
await this.users.clearLock(user);
|
|
134
|
+
let backupCodes;
|
|
135
|
+
if (!user.twoFactorEnabled) {
|
|
136
|
+
const generated = await this.twoFactor.generateBackupCodes();
|
|
137
|
+
user.twoFactorEnabled = true;
|
|
138
|
+
user.twoFactorConfirmedAt = new Date();
|
|
139
|
+
user.backupCodes = generated.hashed;
|
|
140
|
+
backupCodes = generated.plain;
|
|
141
|
+
}
|
|
142
|
+
else if (remainingBackup) {
|
|
143
|
+
user.backupCodes = remainingBackup;
|
|
144
|
+
}
|
|
145
|
+
await this.users.save(user);
|
|
146
|
+
const tokens = await this.finalizeLogin(user, ctx);
|
|
147
|
+
return { ...tokens, backupCodes };
|
|
148
|
+
}
|
|
149
|
+
async regenerateBackupCodes(userId, code) {
|
|
150
|
+
const user = await this.users.findById(userId);
|
|
151
|
+
if (!user.twoFactorEnabled || !user.twoFactorSecret) {
|
|
152
|
+
throw new common_1.BadRequestException("2FA não está configurado");
|
|
153
|
+
}
|
|
154
|
+
const alreadyUsed = await this.tokens.isTotpCodeUsed(userId, code);
|
|
155
|
+
const valid = !alreadyUsed &&
|
|
156
|
+
(await this.twoFactor.verifyTotp(code, user.twoFactorSecret));
|
|
157
|
+
if (!valid) {
|
|
158
|
+
throw new common_1.UnauthorizedException("Código TOTP inválido");
|
|
159
|
+
}
|
|
160
|
+
await this.tokens.markTotpCodeUsed(userId, code);
|
|
161
|
+
const generated = await this.twoFactor.generateBackupCodes();
|
|
162
|
+
user.backupCodes = generated.hashed;
|
|
163
|
+
await this.users.save(user);
|
|
164
|
+
return generated.plain;
|
|
165
|
+
}
|
|
166
|
+
async refresh(rawToken, ctx) {
|
|
167
|
+
if (!rawToken) {
|
|
168
|
+
throw new common_1.UnauthorizedException("Refresh token ausente");
|
|
169
|
+
}
|
|
170
|
+
const { userId, rawToken: newRefresh } = await this.tokens.rotateRefreshToken(rawToken, ctx);
|
|
171
|
+
const user = await this.users.findById(userId);
|
|
172
|
+
if (!user.isActive) {
|
|
173
|
+
throw accountInactive();
|
|
174
|
+
}
|
|
175
|
+
const accessToken = await this.signAccessToken(user);
|
|
176
|
+
return { accessToken, refreshToken: newRefresh };
|
|
177
|
+
}
|
|
178
|
+
async logout(rawRefreshToken) {
|
|
179
|
+
if (!rawRefreshToken) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
await this.tokens.revokeByRawToken(rawRefreshToken);
|
|
183
|
+
}
|
|
184
|
+
async forgotPassword(email) {
|
|
185
|
+
const user = await this.users.findByEmail(email);
|
|
186
|
+
if (!user || !user.isActive) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const token = await this.tokens.issuePasswordReset(user.id);
|
|
190
|
+
await this.mailer.sendPasswordReset(user.email, token, user.name);
|
|
191
|
+
}
|
|
192
|
+
async inspectPasswordToken(token) {
|
|
193
|
+
const inspection = await this.tokens.inspectPasswordToken(token);
|
|
194
|
+
return {
|
|
195
|
+
valid: inspection.status === token_service_1.PasswordTokenStatus.VALID,
|
|
196
|
+
status: inspection.status,
|
|
197
|
+
purpose: inspection.purpose,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
async resetPassword(token, newPassword) {
|
|
201
|
+
const invalidToken = () => new common_1.BadRequestException("Token de redefinição inválido ou expirado");
|
|
202
|
+
const inspection = await this.tokens.inspectPasswordToken(token);
|
|
203
|
+
if (inspection.status !== token_service_1.PasswordTokenStatus.VALID || !inspection.userId) {
|
|
204
|
+
throw invalidToken();
|
|
205
|
+
}
|
|
206
|
+
await this.users.assertPasswordNotReused(inspection.userId, newPassword);
|
|
207
|
+
const consumed = await this.tokens.consumePasswordToken(token);
|
|
208
|
+
if (!consumed) {
|
|
209
|
+
throw invalidToken();
|
|
210
|
+
}
|
|
211
|
+
await this.users.resetPassword(consumed.userId, newPassword);
|
|
212
|
+
await this.tokens.revokeAllRefresh(consumed.userId);
|
|
213
|
+
}
|
|
214
|
+
async buildPendingToken(user) {
|
|
215
|
+
const payload = {
|
|
216
|
+
sub: user.id,
|
|
217
|
+
email: user.email,
|
|
218
|
+
purpose: "2fa",
|
|
219
|
+
enrolled: user.twoFactorEnabled,
|
|
220
|
+
};
|
|
221
|
+
return this.jwt.signAsync(payload, {
|
|
222
|
+
secret: this.env.get("JWT_PENDING_SECRET"),
|
|
223
|
+
expiresIn: PENDING_EXPIRES,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
async decodePending(token) {
|
|
227
|
+
try {
|
|
228
|
+
const payload = await this.jwt.verifyAsync(token, {
|
|
229
|
+
secret: this.env.get("JWT_PENDING_SECRET"),
|
|
230
|
+
});
|
|
231
|
+
if (payload.purpose !== "2fa") {
|
|
232
|
+
throw new Error("purpose inválido");
|
|
233
|
+
}
|
|
234
|
+
return payload;
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
throw new common_1.UnauthorizedException("Token de verificação inválido ou expirado");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
signAccessToken(user) {
|
|
241
|
+
const payload = {
|
|
242
|
+
sub: user.id,
|
|
243
|
+
email: user.email,
|
|
244
|
+
purpose: "access",
|
|
245
|
+
};
|
|
246
|
+
return this.jwt.signAsync(payload, {
|
|
247
|
+
secret: this.env.get("JWT_ACCESS_SECRET"),
|
|
248
|
+
expiresIn: this.env.get("JWT_ACCESS_EXPIRES"),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
async toSessionUser(user) {
|
|
252
|
+
const [permissions, roles] = await Promise.all([
|
|
253
|
+
this.rbac.getUserPermissionCodes(user.id),
|
|
254
|
+
this.rbac.getUserRoleNames(user.id),
|
|
255
|
+
]);
|
|
256
|
+
return {
|
|
257
|
+
id: user.id,
|
|
258
|
+
email: user.email,
|
|
259
|
+
name: user.name,
|
|
260
|
+
lastName: user.lastName,
|
|
261
|
+
avatar: user.avatar,
|
|
262
|
+
roles,
|
|
263
|
+
permissions,
|
|
264
|
+
twoFactorEnabled: user.twoFactorEnabled,
|
|
265
|
+
passwordExpired: user.isPasswordExpired(this.env.get("PASSWORD_MAX_AGE_DAYS")),
|
|
266
|
+
mustChangePassword: user.mustChangePassword,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
async finalizeLogin(user, ctx) {
|
|
270
|
+
const accessToken = await this.signAccessToken(user);
|
|
271
|
+
const { rawToken } = await this.tokens.issueRefreshToken(user.id, undefined, ctx);
|
|
272
|
+
return {
|
|
273
|
+
accessToken,
|
|
274
|
+
refreshToken: rawToken,
|
|
275
|
+
user: await this.toSessionUser(user),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
exports.AuthService = AuthService;
|
|
280
|
+
exports.AuthService = AuthService = __decorate([
|
|
281
|
+
(0, common_1.Injectable)(),
|
|
282
|
+
__metadata("design:paramtypes", [users_service_1.UsersService,
|
|
283
|
+
token_service_1.TokenService,
|
|
284
|
+
twoFactor_service_1.TwoFactorService,
|
|
285
|
+
jwt_1.JwtService,
|
|
286
|
+
env_service_1.EnvService,
|
|
287
|
+
mailer_service_1.MailerService,
|
|
288
|
+
rbac_service_1.RbacService])
|
|
289
|
+
], AuthService);
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./auth.service"), exports);
|
|
18
|
+
__exportStar(require("./jwtPayload.interface"), exports);
|
|
19
|
+
__exportStar(require("./token.service"), exports);
|
|
20
|
+
__exportStar(require("./twoFactor.service"), exports);
|
|
21
|
+
__exportStar(require("./wsUserResolver.service"), exports);
|