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,56 @@
|
|
|
1
|
+
import { EnvService } from "../../../core/config/env.service";
|
|
2
|
+
import { AuthTokenRepository } from "../infra/repositories/authToken.repository";
|
|
3
|
+
import { TokenType } from "../infra/schema/authToken.schema";
|
|
4
|
+
export interface RotationResult {
|
|
5
|
+
userId: string;
|
|
6
|
+
rawToken: string;
|
|
7
|
+
family: string;
|
|
8
|
+
}
|
|
9
|
+
export declare enum PasswordTokenStatus {
|
|
10
|
+
VALID = "valid",
|
|
11
|
+
INVALID = "invalid",
|
|
12
|
+
EXPIRED = "expired",
|
|
13
|
+
USED = "used"
|
|
14
|
+
}
|
|
15
|
+
export type PasswordTokenPurpose = TokenType.PASSWORD_RESET | TokenType.FIRST_ACCESS;
|
|
16
|
+
export interface PasswordTokenInspection {
|
|
17
|
+
status: PasswordTokenStatus;
|
|
18
|
+
purpose?: PasswordTokenPurpose;
|
|
19
|
+
userId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ConsumedPasswordToken {
|
|
22
|
+
userId: string;
|
|
23
|
+
purpose: PasswordTokenPurpose;
|
|
24
|
+
}
|
|
25
|
+
export declare class TokenService {
|
|
26
|
+
private readonly repo;
|
|
27
|
+
private readonly env;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
constructor(repo: AuthTokenRepository, env: EnvService);
|
|
30
|
+
private persist;
|
|
31
|
+
private minutesFromNow;
|
|
32
|
+
issueRefreshToken(userId: string, family?: string, ctx?: {
|
|
33
|
+
ipAddress?: string;
|
|
34
|
+
userAgent?: string;
|
|
35
|
+
}): Promise<{
|
|
36
|
+
rawToken: string;
|
|
37
|
+
family: string;
|
|
38
|
+
}>;
|
|
39
|
+
rotateRefreshToken(rawToken: string, ctx?: {
|
|
40
|
+
ipAddress?: string;
|
|
41
|
+
userAgent?: string;
|
|
42
|
+
}): Promise<RotationResult>;
|
|
43
|
+
revokeFamily(family: string): Promise<void>;
|
|
44
|
+
revokeAllRefresh(userId: string): Promise<void>;
|
|
45
|
+
revokeByRawToken(rawToken: string): Promise<void>;
|
|
46
|
+
issueTwoFactorEmailCode(userId: string): Promise<string>;
|
|
47
|
+
consumeTwoFactorEmailCode(userId: string, code: string): Promise<boolean>;
|
|
48
|
+
private issuePasswordToken;
|
|
49
|
+
issuePasswordReset(userId: string): Promise<string>;
|
|
50
|
+
issueFirstAccess(userId: string): Promise<string>;
|
|
51
|
+
inspectPasswordToken(rawToken: string): Promise<PasswordTokenInspection>;
|
|
52
|
+
consumePasswordToken(rawToken: string): Promise<ConsumedPasswordToken | null>;
|
|
53
|
+
isTotpCodeUsed(userId: string, code: string): Promise<boolean>;
|
|
54
|
+
markTotpCodeUsed(userId: string, code: string): Promise<void>;
|
|
55
|
+
cleanExpired(): Promise<number>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
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 TokenService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.TokenService = exports.PasswordTokenStatus = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const typeorm_1 = require("typeorm");
|
|
16
|
+
const uuid_1 = require("uuid");
|
|
17
|
+
const env_service_1 = require("../../../core/config/env.service");
|
|
18
|
+
const hash_util_1 = require("../../../core/utils/hash.util");
|
|
19
|
+
const authToken_repository_1 = require("../infra/repositories/authToken.repository");
|
|
20
|
+
const authToken_schema_1 = require("../infra/schema/authToken.schema");
|
|
21
|
+
var PasswordTokenStatus;
|
|
22
|
+
(function (PasswordTokenStatus) {
|
|
23
|
+
PasswordTokenStatus["VALID"] = "valid";
|
|
24
|
+
PasswordTokenStatus["INVALID"] = "invalid";
|
|
25
|
+
PasswordTokenStatus["EXPIRED"] = "expired";
|
|
26
|
+
PasswordTokenStatus["USED"] = "used";
|
|
27
|
+
})(PasswordTokenStatus || (exports.PasswordTokenStatus = PasswordTokenStatus = {}));
|
|
28
|
+
const PASSWORD_TOKEN_TYPES = [
|
|
29
|
+
authToken_schema_1.TokenType.PASSWORD_RESET,
|
|
30
|
+
authToken_schema_1.TokenType.FIRST_ACCESS,
|
|
31
|
+
];
|
|
32
|
+
let TokenService = TokenService_1 = class TokenService {
|
|
33
|
+
constructor(repo, env) {
|
|
34
|
+
this.repo = repo;
|
|
35
|
+
this.env = env;
|
|
36
|
+
this.logger = new common_1.Logger(TokenService_1.name);
|
|
37
|
+
}
|
|
38
|
+
async persist(params) {
|
|
39
|
+
return this.repo.save(this.repo.create({
|
|
40
|
+
userId: params.userId,
|
|
41
|
+
tokenHash: (0, hash_util_1.sha256)(params.rawToken),
|
|
42
|
+
type: params.type,
|
|
43
|
+
family: params.family ?? null,
|
|
44
|
+
expiresAt: params.expiresAt,
|
|
45
|
+
ipAddress: params.ipAddress,
|
|
46
|
+
userAgent: params.userAgent,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
minutesFromNow(minutes) {
|
|
50
|
+
return new Date(Date.now() + minutes * 60_000);
|
|
51
|
+
}
|
|
52
|
+
async issueRefreshToken(userId, family, ctx) {
|
|
53
|
+
const rawToken = (0, hash_util_1.randomToken)(48);
|
|
54
|
+
const fam = family ?? (0, uuid_1.v7)();
|
|
55
|
+
await this.persist({
|
|
56
|
+
userId,
|
|
57
|
+
rawToken,
|
|
58
|
+
type: authToken_schema_1.TokenType.REFRESH_TOKEN,
|
|
59
|
+
family: fam,
|
|
60
|
+
expiresAt: this.minutesFromNow(this.env.get("JWT_REFRESH_EXPIRES_MINUTES")),
|
|
61
|
+
ipAddress: ctx?.ipAddress,
|
|
62
|
+
userAgent: ctx?.userAgent,
|
|
63
|
+
});
|
|
64
|
+
return { rawToken, family: fam };
|
|
65
|
+
}
|
|
66
|
+
async rotateRefreshToken(rawToken, ctx) {
|
|
67
|
+
const tokenHash = (0, hash_util_1.sha256)(rawToken);
|
|
68
|
+
const stored = await this.repo.findOne({
|
|
69
|
+
where: { tokenHash, type: authToken_schema_1.TokenType.REFRESH_TOKEN },
|
|
70
|
+
});
|
|
71
|
+
if (!stored) {
|
|
72
|
+
throw new common_1.UnauthorizedException("Refresh token inválido");
|
|
73
|
+
}
|
|
74
|
+
if (stored.used || stored.revoked) {
|
|
75
|
+
this.logger.warn(`Reuso de refresh token detectado (família ${stored.family})`);
|
|
76
|
+
if (stored.family) {
|
|
77
|
+
await this.revokeFamily(stored.family);
|
|
78
|
+
}
|
|
79
|
+
throw new common_1.UnauthorizedException("Refresh token reutilizado — sessão revogada");
|
|
80
|
+
}
|
|
81
|
+
if (stored.isExpired()) {
|
|
82
|
+
throw new common_1.UnauthorizedException("Refresh token expirado");
|
|
83
|
+
}
|
|
84
|
+
stored.used = true;
|
|
85
|
+
await this.repo.save(stored);
|
|
86
|
+
const { rawToken: newRaw, family } = await this.issueRefreshToken(stored.userId, stored.family ?? undefined, ctx);
|
|
87
|
+
return { userId: stored.userId, rawToken: newRaw, family };
|
|
88
|
+
}
|
|
89
|
+
async revokeFamily(family) {
|
|
90
|
+
await this.repo.update({ family }, { revoked: true });
|
|
91
|
+
}
|
|
92
|
+
async revokeAllRefresh(userId) {
|
|
93
|
+
await this.repo.update({ userId, type: authToken_schema_1.TokenType.REFRESH_TOKEN }, { revoked: true });
|
|
94
|
+
}
|
|
95
|
+
async revokeByRawToken(rawToken) {
|
|
96
|
+
const stored = await this.repo.findOne({
|
|
97
|
+
where: { tokenHash: (0, hash_util_1.sha256)(rawToken), type: authToken_schema_1.TokenType.REFRESH_TOKEN },
|
|
98
|
+
});
|
|
99
|
+
if (!stored) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (stored.family) {
|
|
103
|
+
await this.revokeFamily(stored.family);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
await this.repo.update({ id: stored.id }, { revoked: true });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async issueTwoFactorEmailCode(userId) {
|
|
110
|
+
await this.repo.update({ userId, type: authToken_schema_1.TokenType.TWO_FACTOR_EMAIL, used: false }, { used: true });
|
|
111
|
+
const code = (0, hash_util_1.numericCode)();
|
|
112
|
+
await this.persist({
|
|
113
|
+
userId,
|
|
114
|
+
rawToken: code,
|
|
115
|
+
type: authToken_schema_1.TokenType.TWO_FACTOR_EMAIL,
|
|
116
|
+
expiresAt: this.minutesFromNow(this.env.get("TWO_FACTOR_EMAIL_CODE_EXPIRY")),
|
|
117
|
+
});
|
|
118
|
+
return code;
|
|
119
|
+
}
|
|
120
|
+
async consumeTwoFactorEmailCode(userId, code) {
|
|
121
|
+
const stored = await this.repo.findOne({
|
|
122
|
+
where: { userId, tokenHash: (0, hash_util_1.sha256)(code), type: authToken_schema_1.TokenType.TWO_FACTOR_EMAIL },
|
|
123
|
+
});
|
|
124
|
+
if (!stored || !stored.isValid()) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
stored.used = true;
|
|
128
|
+
await this.repo.save(stored);
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
async issuePasswordToken(userId, type, expiryMinutes) {
|
|
132
|
+
await this.repo.update({ userId, type, used: false }, { used: true });
|
|
133
|
+
const rawToken = (0, hash_util_1.randomToken)(32);
|
|
134
|
+
await this.persist({
|
|
135
|
+
userId,
|
|
136
|
+
rawToken,
|
|
137
|
+
type,
|
|
138
|
+
expiresAt: this.minutesFromNow(expiryMinutes),
|
|
139
|
+
});
|
|
140
|
+
return rawToken;
|
|
141
|
+
}
|
|
142
|
+
async issuePasswordReset(userId) {
|
|
143
|
+
return this.issuePasswordToken(userId, authToken_schema_1.TokenType.PASSWORD_RESET, this.env.get("PASSWORD_RESET_TOKEN_EXPIRY"));
|
|
144
|
+
}
|
|
145
|
+
async issueFirstAccess(userId) {
|
|
146
|
+
return this.issuePasswordToken(userId, authToken_schema_1.TokenType.FIRST_ACCESS, this.env.get("FIRST_ACCESS_TOKEN_EXPIRY"));
|
|
147
|
+
}
|
|
148
|
+
async inspectPasswordToken(rawToken) {
|
|
149
|
+
const stored = await this.repo.findOne({
|
|
150
|
+
where: { tokenHash: (0, hash_util_1.sha256)(rawToken), type: (0, typeorm_1.In)(PASSWORD_TOKEN_TYPES) },
|
|
151
|
+
});
|
|
152
|
+
if (!stored) {
|
|
153
|
+
return { status: PasswordTokenStatus.INVALID };
|
|
154
|
+
}
|
|
155
|
+
if (stored.used || stored.revoked) {
|
|
156
|
+
return { status: PasswordTokenStatus.USED };
|
|
157
|
+
}
|
|
158
|
+
if (stored.isExpired()) {
|
|
159
|
+
return { status: PasswordTokenStatus.EXPIRED };
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
status: PasswordTokenStatus.VALID,
|
|
163
|
+
purpose: stored.type,
|
|
164
|
+
userId: stored.userId,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async consumePasswordToken(rawToken) {
|
|
168
|
+
const stored = await this.repo.findOne({
|
|
169
|
+
where: { tokenHash: (0, hash_util_1.sha256)(rawToken), type: (0, typeorm_1.In)(PASSWORD_TOKEN_TYPES) },
|
|
170
|
+
});
|
|
171
|
+
if (!stored || !stored.isValid()) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
stored.used = true;
|
|
175
|
+
await this.repo.save(stored);
|
|
176
|
+
return {
|
|
177
|
+
userId: stored.userId,
|
|
178
|
+
purpose: stored.type,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
async isTotpCodeUsed(userId, code) {
|
|
182
|
+
const stored = await this.repo.findOne({
|
|
183
|
+
where: { userId, tokenHash: (0, hash_util_1.sha256)(code), type: authToken_schema_1.TokenType.TOTP_USED },
|
|
184
|
+
});
|
|
185
|
+
return !!stored && !stored.isExpired();
|
|
186
|
+
}
|
|
187
|
+
async markTotpCodeUsed(userId, code) {
|
|
188
|
+
await this.persist({
|
|
189
|
+
userId,
|
|
190
|
+
rawToken: code,
|
|
191
|
+
type: authToken_schema_1.TokenType.TOTP_USED,
|
|
192
|
+
expiresAt: this.minutesFromNow(2),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
async cleanExpired() {
|
|
196
|
+
const result = await this.repo.delete({ expiresAt: (0, typeorm_1.LessThan)(new Date()) });
|
|
197
|
+
return result.affected ?? 0;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
exports.TokenService = TokenService;
|
|
201
|
+
exports.TokenService = TokenService = TokenService_1 = __decorate([
|
|
202
|
+
(0, common_1.Injectable)(),
|
|
203
|
+
__metadata("design:paramtypes", [authToken_repository_1.AuthTokenRepository,
|
|
204
|
+
env_service_1.EnvService])
|
|
205
|
+
], TokenService);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EnvService } from "../../../core/config/env.service";
|
|
2
|
+
export interface TotpSetup {
|
|
3
|
+
secret: string;
|
|
4
|
+
otpauthUrl: string;
|
|
5
|
+
qrDataUrl: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class TwoFactorService {
|
|
8
|
+
private readonly env;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
constructor(env: EnvService);
|
|
11
|
+
generateSetup(accountEmail: string): Promise<TotpSetup>;
|
|
12
|
+
encrypt(secret: string): string;
|
|
13
|
+
verifyTotp(code: string, storedSecret: string): Promise<boolean>;
|
|
14
|
+
generateBackupCodes(): Promise<{
|
|
15
|
+
plain: string[];
|
|
16
|
+
hashed: string[];
|
|
17
|
+
}>;
|
|
18
|
+
consumeBackupCode(code: string, hashedCodes: string[]): Promise<string[] | null>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var TwoFactorService_1;
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.TwoFactorService = void 0;
|
|
47
|
+
const common_1 = require("@nestjs/common");
|
|
48
|
+
const otplib_1 = require("otplib");
|
|
49
|
+
const QRCode = __importStar(require("qrcode"));
|
|
50
|
+
const env_service_1 = require("../../../core/config/env.service");
|
|
51
|
+
const crypto_util_1 = require("../../../core/utils/crypto.util");
|
|
52
|
+
const hash_util_1 = require("../../../core/utils/hash.util");
|
|
53
|
+
let TwoFactorService = TwoFactorService_1 = class TwoFactorService {
|
|
54
|
+
constructor(env) {
|
|
55
|
+
this.env = env;
|
|
56
|
+
this.logger = new common_1.Logger(TwoFactorService_1.name);
|
|
57
|
+
}
|
|
58
|
+
async generateSetup(accountEmail) {
|
|
59
|
+
const secret = (0, otplib_1.generateSecret)();
|
|
60
|
+
const issuer = this.env.get("TOTP_ISSUER");
|
|
61
|
+
const otpauthUrl = (0, otplib_1.generateURI)({ issuer, label: accountEmail, secret });
|
|
62
|
+
const qrDataUrl = await QRCode.toDataURL(otpauthUrl);
|
|
63
|
+
return { secret, otpauthUrl, qrDataUrl };
|
|
64
|
+
}
|
|
65
|
+
encrypt(secret) {
|
|
66
|
+
return (0, crypto_util_1.encryptSecret)(secret);
|
|
67
|
+
}
|
|
68
|
+
async verifyTotp(code, storedSecret) {
|
|
69
|
+
if (!storedSecret) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const result = await (0, otplib_1.verify)({
|
|
74
|
+
token: code,
|
|
75
|
+
secret: (0, crypto_util_1.decryptSecret)(storedSecret),
|
|
76
|
+
});
|
|
77
|
+
return result.valid;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
this.logger.warn(`Falha ao verificar código TOTP: ${err.message}`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async generateBackupCodes() {
|
|
85
|
+
const count = this.env.get("BACKUP_CODES_COUNT");
|
|
86
|
+
const plain = Array.from({ length: count }, () => (0, hash_util_1.backupCode)());
|
|
87
|
+
const hashed = await Promise.all(plain.map((c) => (0, hash_util_1.hashPassword)(c)));
|
|
88
|
+
return { plain, hashed };
|
|
89
|
+
}
|
|
90
|
+
async consumeBackupCode(code, hashedCodes) {
|
|
91
|
+
for (let i = 0; i < hashedCodes.length; i++) {
|
|
92
|
+
if (await (0, hash_util_1.verifyPassword)(hashedCodes[i], code)) {
|
|
93
|
+
return hashedCodes.filter((_, idx) => idx !== i);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.TwoFactorService = TwoFactorService;
|
|
100
|
+
exports.TwoFactorService = TwoFactorService = TwoFactorService_1 = __decorate([
|
|
101
|
+
(0, common_1.Injectable)(),
|
|
102
|
+
__metadata("design:paramtypes", [env_service_1.EnvService])
|
|
103
|
+
], TwoFactorService);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthenticatedUser } from "../../../core/auth/authenticatedUser.interface";
|
|
2
|
+
import { WsUserResolver } from "../../../core/websocket/wsUserResolver.interface";
|
|
3
|
+
import { AuthService } from "./auth.service";
|
|
4
|
+
import { UsersService } from "../../users/domain/users.service";
|
|
5
|
+
export declare class WsUserResolverService implements WsUserResolver {
|
|
6
|
+
private readonly users;
|
|
7
|
+
private readonly auth;
|
|
8
|
+
constructor(users: UsersService, auth: AuthService);
|
|
9
|
+
resolve(userId: string): Promise<AuthenticatedUser | null>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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.WsUserResolverService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const auth_service_1 = require("./auth.service");
|
|
15
|
+
const users_service_1 = require("../../users/domain/users.service");
|
|
16
|
+
let WsUserResolverService = class WsUserResolverService {
|
|
17
|
+
constructor(users, auth) {
|
|
18
|
+
this.users = users;
|
|
19
|
+
this.auth = auth;
|
|
20
|
+
}
|
|
21
|
+
async resolve(userId) {
|
|
22
|
+
const user = await this.users.findById(userId).catch(() => null);
|
|
23
|
+
if (!user || !user.isActive) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return await this.auth.toSessionUser(user);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.WsUserResolverService = WsUserResolverService;
|
|
30
|
+
exports.WsUserResolverService = WsUserResolverService = __decorate([
|
|
31
|
+
(0, common_1.Injectable)(),
|
|
32
|
+
__metadata("design:paramtypes", [users_service_1.UsersService,
|
|
33
|
+
auth_service_1.AuthService])
|
|
34
|
+
], WsUserResolverService);
|
|
@@ -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("./repositories/authToken.repository"), exports);
|
|
18
|
+
__exportStar(require("./schema/authToken.schema"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
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.AuthTokenRepository = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const authToken_schema_1 = require("../schema/authToken.schema");
|
|
16
|
+
let AuthTokenRepository = class AuthTokenRepository extends typeorm_1.Repository {
|
|
17
|
+
constructor(dataSource) {
|
|
18
|
+
super(authToken_schema_1.AuthToken, dataSource.createEntityManager());
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.AuthTokenRepository = AuthTokenRepository;
|
|
22
|
+
exports.AuthTokenRepository = AuthTokenRepository = __decorate([
|
|
23
|
+
(0, common_1.Injectable)(),
|
|
24
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
25
|
+
], AuthTokenRepository);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseEntity } from "../../../../core/database/base.schema";
|
|
2
|
+
export declare enum TokenType {
|
|
3
|
+
PASSWORD_RESET = "password_reset",
|
|
4
|
+
FIRST_ACCESS = "first_access",
|
|
5
|
+
TWO_FACTOR_EMAIL = "two_factor_email",
|
|
6
|
+
REFRESH_TOKEN = "refresh_token",
|
|
7
|
+
TOTP_USED = "totp_used"
|
|
8
|
+
}
|
|
9
|
+
export declare class AuthToken extends BaseEntity {
|
|
10
|
+
userId: string;
|
|
11
|
+
tokenHash: string;
|
|
12
|
+
type: TokenType;
|
|
13
|
+
family?: string | null;
|
|
14
|
+
expiresAt: Date;
|
|
15
|
+
used: boolean;
|
|
16
|
+
revoked: boolean;
|
|
17
|
+
ipAddress?: string | null;
|
|
18
|
+
userAgent?: string | null;
|
|
19
|
+
isExpired(): boolean;
|
|
20
|
+
isValid(): boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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.AuthToken = exports.TokenType = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const base_schema_1 = require("../../../../core/database/base.schema");
|
|
15
|
+
var TokenType;
|
|
16
|
+
(function (TokenType) {
|
|
17
|
+
TokenType["PASSWORD_RESET"] = "password_reset";
|
|
18
|
+
TokenType["FIRST_ACCESS"] = "first_access";
|
|
19
|
+
TokenType["TWO_FACTOR_EMAIL"] = "two_factor_email";
|
|
20
|
+
TokenType["REFRESH_TOKEN"] = "refresh_token";
|
|
21
|
+
TokenType["TOTP_USED"] = "totp_used";
|
|
22
|
+
})(TokenType || (exports.TokenType = TokenType = {}));
|
|
23
|
+
let AuthToken = class AuthToken extends base_schema_1.BaseEntity {
|
|
24
|
+
isExpired() {
|
|
25
|
+
return new Date() > this.expiresAt;
|
|
26
|
+
}
|
|
27
|
+
isValid() {
|
|
28
|
+
return !this.used && !this.revoked && !this.isExpired();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.AuthToken = AuthToken;
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, typeorm_1.Column)({ name: "user_id", type: "char", length: 36 }),
|
|
34
|
+
__metadata("design:type", String)
|
|
35
|
+
], AuthToken.prototype, "userId", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, typeorm_1.Column)({ name: "token_hash", type: "varchar", length: 255 }),
|
|
38
|
+
__metadata("design:type", String)
|
|
39
|
+
], AuthToken.prototype, "tokenHash", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, typeorm_1.Column)({ type: "enum", enum: TokenType }),
|
|
42
|
+
__metadata("design:type", String)
|
|
43
|
+
], AuthToken.prototype, "type", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typeorm_1.Column)({ name: "family", type: "char", length: 36, nullable: true }),
|
|
46
|
+
__metadata("design:type", Object)
|
|
47
|
+
], AuthToken.prototype, "family", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, typeorm_1.Column)({ name: "expires_at", type: "datetime" }),
|
|
50
|
+
__metadata("design:type", Date)
|
|
51
|
+
], AuthToken.prototype, "expiresAt", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, typeorm_1.Column)({ type: "boolean", default: false }),
|
|
54
|
+
__metadata("design:type", Boolean)
|
|
55
|
+
], AuthToken.prototype, "used", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, typeorm_1.Column)({ type: "boolean", default: false }),
|
|
58
|
+
__metadata("design:type", Boolean)
|
|
59
|
+
], AuthToken.prototype, "revoked", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, typeorm_1.Column)({ name: "ip_address", type: "varchar", length: 45, nullable: true }),
|
|
62
|
+
__metadata("design:type", Object)
|
|
63
|
+
], AuthToken.prototype, "ipAddress", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, typeorm_1.Column)({ name: "user_agent", type: "text", nullable: true }),
|
|
66
|
+
__metadata("design:type", Object)
|
|
67
|
+
], AuthToken.prototype, "userAgent", void 0);
|
|
68
|
+
exports.AuthToken = AuthToken = __decorate([
|
|
69
|
+
(0, typeorm_1.Entity)("auth_tokens"),
|
|
70
|
+
(0, typeorm_1.Index)(["tokenHash", "type"]),
|
|
71
|
+
(0, typeorm_1.Index)(["userId", "type"]),
|
|
72
|
+
(0, typeorm_1.Index)(["family"])
|
|
73
|
+
], AuthToken);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
import { AuthenticatedUser } from "../../../core/auth/authenticatedUser.interface";
|
|
3
|
+
import { EnvService } from "../../../core/config/env.service";
|
|
4
|
+
import { AuthService } from "../domain/auth.service";
|
|
5
|
+
import { PasswordTokenCheck } from "../domain/auth.service";
|
|
6
|
+
import { SessionUser } from "../domain/auth.service";
|
|
7
|
+
import { LoginStatus } from "../domain/auth.service";
|
|
8
|
+
import { TotpSetup } from "../domain/twoFactor.service";
|
|
9
|
+
import { LoginCommand } from "./commands/login.command";
|
|
10
|
+
import { ForgotPasswordCommand, ResetPasswordCommand } from "./commands/password.command";
|
|
11
|
+
import { RefreshTokenCommand } from "./commands/refreshToken.command";
|
|
12
|
+
import { PendingTokenCommand, RegenerateBackupCommand, VerifyTwoFactorCommand } from "./commands/twoFactor.command";
|
|
13
|
+
export interface VerifyResponse {
|
|
14
|
+
user: SessionUser;
|
|
15
|
+
backupCodes?: string[];
|
|
16
|
+
accessToken?: string;
|
|
17
|
+
refreshToken?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RefreshResponse {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
accessToken?: string;
|
|
22
|
+
refreshToken?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class AuthController {
|
|
25
|
+
private readonly auth;
|
|
26
|
+
private readonly env;
|
|
27
|
+
constructor(auth: AuthService, env: EnvService);
|
|
28
|
+
login(dto: LoginCommand): Promise<{
|
|
29
|
+
status: LoginStatus;
|
|
30
|
+
pendingToken: string;
|
|
31
|
+
}>;
|
|
32
|
+
setupTotp(dto: PendingTokenCommand): Promise<TotpSetup>;
|
|
33
|
+
requestEmailCode(dto: PendingTokenCommand): Promise<{
|
|
34
|
+
sent: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
verify(dto: VerifyTwoFactorCommand, req: Request, res: Response): Promise<VerifyResponse>;
|
|
37
|
+
refresh(dto: RefreshTokenCommand, req: Request, res: Response): Promise<RefreshResponse>;
|
|
38
|
+
logout(dto: RefreshTokenCommand, req: Request, res: Response): Promise<{
|
|
39
|
+
ok: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
profile(user: AuthenticatedUser): AuthenticatedUser;
|
|
42
|
+
myPermissions(user: AuthenticatedUser): {
|
|
43
|
+
roles: string[];
|
|
44
|
+
permissions: string[];
|
|
45
|
+
};
|
|
46
|
+
regenerateBackup(userId: string, dto: RegenerateBackupCommand): Promise<{
|
|
47
|
+
backupCodes: string[];
|
|
48
|
+
}>;
|
|
49
|
+
forgotPassword(dto: ForgotPasswordCommand): Promise<{
|
|
50
|
+
ok: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
inspectPasswordToken(token: string): Promise<PasswordTokenCheck>;
|
|
53
|
+
resetPassword(dto: ResetPasswordCommand): Promise<{
|
|
54
|
+
ok: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
}
|