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,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.envSchema = void 0;
|
|
4
|
+
exports.validateEnv = validateEnv;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const booleanFromString = zod_1.z
|
|
7
|
+
.enum(["true", "false"])
|
|
8
|
+
.transform((v) => v === "true");
|
|
9
|
+
exports.envSchema = zod_1.z
|
|
10
|
+
.object({
|
|
11
|
+
NODE_ENV: zod_1.z
|
|
12
|
+
.enum(["development", "test", "production"])
|
|
13
|
+
.default("development"),
|
|
14
|
+
PORT: zod_1.z.coerce.number().int().positive().default(3108),
|
|
15
|
+
API_PREFIX: zod_1.z.string().default("api"),
|
|
16
|
+
APP_URL: zod_1.z.string().url().default("http://localhost:4000"),
|
|
17
|
+
DB_HOST: zod_1.z.string().min(1),
|
|
18
|
+
DB_PORT: zod_1.z.coerce.number().int().positive().default(3306),
|
|
19
|
+
DB_NAME: zod_1.z.string().min(1),
|
|
20
|
+
DB_USER: zod_1.z.string().min(1),
|
|
21
|
+
DB_PASSWORD: zod_1.z.string().min(1),
|
|
22
|
+
DB_LOGGING: booleanFromString.default(false),
|
|
23
|
+
DB_SSL: booleanFromString.default(false),
|
|
24
|
+
TRUST_PROXY_HOPS: zod_1.z.coerce.number().int().nonnegative().default(1),
|
|
25
|
+
JWT_ACCESS_SECRET: zod_1.z.string().min(32),
|
|
26
|
+
JWT_PENDING_SECRET: zod_1.z.string().min(32),
|
|
27
|
+
JWT_ACCESS_EXPIRES: zod_1.z.string().default("4h"),
|
|
28
|
+
JWT_REFRESH_EXPIRES_MINUTES: zod_1.z.coerce
|
|
29
|
+
.number()
|
|
30
|
+
.int()
|
|
31
|
+
.positive()
|
|
32
|
+
.default(360),
|
|
33
|
+
TOTP_ENC_KEY: zod_1.z
|
|
34
|
+
.string()
|
|
35
|
+
.length(64, "TOTP_ENC_KEY deve ter 64 chars hex (32 bytes)"),
|
|
36
|
+
COOKIE_SECURE: booleanFromString.default(false),
|
|
37
|
+
COOKIE_DOMAIN: zod_1.z.string().default("localhost"),
|
|
38
|
+
TOTP_ISSUER: zod_1.z.string().default("Core App"),
|
|
39
|
+
TWO_FACTOR_EMAIL_CODE_EXPIRY: zod_1.z.coerce
|
|
40
|
+
.number()
|
|
41
|
+
.int()
|
|
42
|
+
.positive()
|
|
43
|
+
.default(10),
|
|
44
|
+
BACKUP_CODES_COUNT: zod_1.z.coerce.number().int().positive().default(10),
|
|
45
|
+
LOGIN_MAX_ATTEMPTS: zod_1.z.coerce.number().int().positive().default(10),
|
|
46
|
+
THROTTLE_TTL_SECONDS: zod_1.z.coerce.number().int().positive().default(60),
|
|
47
|
+
THROTTLE_LIMIT: zod_1.z.coerce.number().int().positive().default(100),
|
|
48
|
+
CORS_ORIGIN: zod_1.z.string().default("http://localhost:4000"),
|
|
49
|
+
LOG_LEVEL: zod_1.z.string().default("debug"),
|
|
50
|
+
EMAIL_HOST: zod_1.z.string().min(1),
|
|
51
|
+
EMAIL_PORT: zod_1.z.coerce.number().int().positive().default(587),
|
|
52
|
+
EMAIL_SECURE: booleanFromString.default(false),
|
|
53
|
+
EMAIL_USER: zod_1.z.string().min(1),
|
|
54
|
+
EMAIL_PASSWORD: zod_1.z.string().min(1),
|
|
55
|
+
EMAIL_FROM: zod_1.z.string().min(1),
|
|
56
|
+
EMAIL_FROM_NAME: zod_1.z.string().default("Core API"),
|
|
57
|
+
PASSWORD_RESET_TOKEN_EXPIRY: zod_1.z.coerce.number().int().positive().default(15),
|
|
58
|
+
FIRST_ACCESS_TOKEN_EXPIRY: zod_1.z.coerce
|
|
59
|
+
.number()
|
|
60
|
+
.int()
|
|
61
|
+
.positive()
|
|
62
|
+
.default(1440),
|
|
63
|
+
PASSWORD_MAX_AGE_DAYS: zod_1.z.coerce.number().int().positive().default(90),
|
|
64
|
+
TOKEN_CLEANUP_CRON: zod_1.z.string().default("0 */6 * * *"),
|
|
65
|
+
AUDIT_LOG_CLEANUP_CRON: zod_1.z.string().default("0 3 * * *"),
|
|
66
|
+
AUDIT_LOG_RETENTION_DAYS: zod_1.z.coerce.number().int().positive().default(30),
|
|
67
|
+
NOTIFICATION_RETENTION_DAYS: zod_1.z.coerce
|
|
68
|
+
.number()
|
|
69
|
+
.int()
|
|
70
|
+
.positive()
|
|
71
|
+
.default(90),
|
|
72
|
+
SEED_ADMIN_NAME: zod_1.z.string().default("Administrador"),
|
|
73
|
+
SEED_ADMIN_EMAIL: zod_1.z.string().email().default("admin@admin.com"),
|
|
74
|
+
SEED_ADMIN_PASSWORD: zod_1.z.string().min(1).default("admin@123"),
|
|
75
|
+
})
|
|
76
|
+
.superRefine((env, ctx) => {
|
|
77
|
+
if (env.NODE_ENV === "production" && !env.COOKIE_SECURE) {
|
|
78
|
+
ctx.addIssue({
|
|
79
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
80
|
+
path: ["COOKIE_SECURE"],
|
|
81
|
+
message: "COOKIE_SECURE deve ser true quando NODE_ENV=production",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
function validateEnv(config) {
|
|
86
|
+
const parsed = exports.envSchema.safeParse(config);
|
|
87
|
+
if (!parsed.success) {
|
|
88
|
+
const issues = parsed.error.issues
|
|
89
|
+
.map((i) => ` - ${i.path.join(".")}: ${i.message}`)
|
|
90
|
+
.join("\n");
|
|
91
|
+
throw new Error(`Variáveis de ambiente inválidas:\n${issues}`);
|
|
92
|
+
}
|
|
93
|
+
return parsed.data;
|
|
94
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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.EnvService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const config_1 = require("@nestjs/config");
|
|
15
|
+
let EnvService = class EnvService {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
get(key) {
|
|
20
|
+
return this.config.get(key, { infer: true });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.EnvService = EnvService;
|
|
24
|
+
exports.EnvService = EnvService = __decorate([
|
|
25
|
+
(0, common_1.Injectable)(),
|
|
26
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
27
|
+
], EnvService);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { EntitySchema } from "typeorm";
|
|
3
|
+
import { EnvValidator } from "./config/config.module";
|
|
4
|
+
export type EntityClass = (new () => object) | EntitySchema;
|
|
5
|
+
export interface CoreModuleOptions {
|
|
6
|
+
entities: EntityClass[];
|
|
7
|
+
validateEnv?: EnvValidator;
|
|
8
|
+
}
|
|
9
|
+
export declare class CoreModule {
|
|
10
|
+
static forRoot(options: CoreModuleOptions): DynamicModule;
|
|
11
|
+
}
|
|
@@ -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 CoreModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CoreModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
14
|
+
const schedule_1 = require("@nestjs/schedule");
|
|
15
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
16
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
17
|
+
const appThrottler_guard_1 = require("./auth/guards/appThrottler.guard");
|
|
18
|
+
const allExceptions_filter_1 = require("./filters/allExceptions.filter");
|
|
19
|
+
const csrf_guard_1 = require("./auth/guards/csrf.guard");
|
|
20
|
+
const config_module_1 = require("./config/config.module");
|
|
21
|
+
const env_service_1 = require("./config/env.service");
|
|
22
|
+
const health_controller_1 = require("./health/health.controller");
|
|
23
|
+
const mailer_module_1 = require("./mailer/mailer.module");
|
|
24
|
+
let CoreModule = CoreModule_1 = class CoreModule {
|
|
25
|
+
static forRoot(options) {
|
|
26
|
+
return {
|
|
27
|
+
module: CoreModule_1,
|
|
28
|
+
imports: [
|
|
29
|
+
config_module_1.ConfigModule.forRoot({ validateEnv: options.validateEnv }),
|
|
30
|
+
mailer_module_1.MailerModule,
|
|
31
|
+
schedule_1.ScheduleModule.forRoot(),
|
|
32
|
+
event_emitter_1.EventEmitterModule.forRoot(),
|
|
33
|
+
typeorm_1.TypeOrmModule.forRootAsync({
|
|
34
|
+
inject: [env_service_1.EnvService],
|
|
35
|
+
useFactory: (env) => ({
|
|
36
|
+
type: "mysql",
|
|
37
|
+
host: env.get("DB_HOST"),
|
|
38
|
+
port: env.get("DB_PORT"),
|
|
39
|
+
username: env.get("DB_USER"),
|
|
40
|
+
password: env.get("DB_PASSWORD"),
|
|
41
|
+
database: env.get("DB_NAME"),
|
|
42
|
+
entities: options.entities,
|
|
43
|
+
synchronize: false,
|
|
44
|
+
logging: env.get("DB_LOGGING"),
|
|
45
|
+
charset: "utf8mb4",
|
|
46
|
+
timezone: "Z",
|
|
47
|
+
ssl: env.get("DB_SSL") ? { rejectUnauthorized: true } : undefined,
|
|
48
|
+
}),
|
|
49
|
+
}),
|
|
50
|
+
throttler_1.ThrottlerModule.forRootAsync({
|
|
51
|
+
inject: [env_service_1.EnvService],
|
|
52
|
+
useFactory: (env) => [
|
|
53
|
+
{
|
|
54
|
+
ttl: env.get("THROTTLE_TTL_SECONDS") * 1000,
|
|
55
|
+
limit: env.get("THROTTLE_LIMIT"),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
controllers: [health_controller_1.HealthController],
|
|
61
|
+
providers: [
|
|
62
|
+
{ provide: core_1.APP_GUARD, useClass: appThrottler_guard_1.AppThrottlerGuard },
|
|
63
|
+
{ provide: core_1.APP_GUARD, useClass: csrf_guard_1.CsrfGuard },
|
|
64
|
+
{ provide: core_1.APP_FILTER, useClass: allExceptions_filter_1.AllExceptionsFilter },
|
|
65
|
+
],
|
|
66
|
+
exports: [mailer_module_1.MailerModule],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.CoreModule = CoreModule;
|
|
71
|
+
exports.CoreModule = CoreModule = CoreModule_1 = __decorate([
|
|
72
|
+
(0, common_1.Module)({})
|
|
73
|
+
], CoreModule);
|
|
@@ -0,0 +1,49 @@
|
|
|
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.BaseEntity = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
class BaseEntity {
|
|
17
|
+
generateId() {
|
|
18
|
+
if (!this.id) {
|
|
19
|
+
this.id = (0, uuid_1.v7)();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.BaseEntity = BaseEntity;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, swagger_1.ApiProperty)({ format: "uuid" }),
|
|
26
|
+
(0, typeorm_1.PrimaryColumn)({ type: "char", length: 36 }),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], BaseEntity.prototype, "id", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, swagger_1.ApiProperty)(),
|
|
31
|
+
(0, typeorm_1.CreateDateColumn)({ name: "created_at" }),
|
|
32
|
+
__metadata("design:type", Date)
|
|
33
|
+
], BaseEntity.prototype, "createdAt", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, swagger_1.ApiProperty)(),
|
|
36
|
+
(0, typeorm_1.UpdateDateColumn)({ name: "updated_at" }),
|
|
37
|
+
__metadata("design:type", Date)
|
|
38
|
+
], BaseEntity.prototype, "updatedAt", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, swagger_1.ApiProperty)({ required: false, nullable: true }),
|
|
41
|
+
(0, typeorm_1.DeleteDateColumn)({ name: "deleted_at", nullable: true }),
|
|
42
|
+
__metadata("design:type", Object)
|
|
43
|
+
], BaseEntity.prototype, "deletedAt", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
46
|
+
__metadata("design:type", Function),
|
|
47
|
+
__metadata("design:paramtypes", []),
|
|
48
|
+
__metadata("design:returntype", void 0)
|
|
49
|
+
], BaseEntity.prototype, "generateId", null);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import { EntityClass } from "../core.module";
|
|
3
|
+
import { MigrationClass } from "./migrations";
|
|
4
|
+
export interface CoreDataSourceOptions {
|
|
5
|
+
entities: EntityClass[];
|
|
6
|
+
migrations: MigrationClass[];
|
|
7
|
+
}
|
|
8
|
+
export declare const createCoreDataSource: (options: CoreDataSourceOptions) => DataSource;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCoreDataSource = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
function requireEnv(name) {
|
|
6
|
+
const value = process.env[name];
|
|
7
|
+
if (!value) {
|
|
8
|
+
throw new Error(`${name} é obrigatória para rodar migrations/seeds (sem valor padrão, por segurança).`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
const createCoreDataSource = (options) => new typeorm_1.DataSource({
|
|
13
|
+
type: "mysql",
|
|
14
|
+
host: requireEnv("DB_HOST"),
|
|
15
|
+
port: Number(process.env.DB_PORT ?? 3306),
|
|
16
|
+
username: requireEnv("DB_USER"),
|
|
17
|
+
password: requireEnv("DB_PASSWORD"),
|
|
18
|
+
database: requireEnv("DB_NAME"),
|
|
19
|
+
entities: options.entities,
|
|
20
|
+
migrations: options.migrations,
|
|
21
|
+
synchronize: false,
|
|
22
|
+
logging: process.env.DB_LOGGING === "true",
|
|
23
|
+
charset: "utf8mb4",
|
|
24
|
+
timezone: "Z",
|
|
25
|
+
ssl: process.env.DB_SSL === "true" ? { rejectUnauthorized: true } : undefined,
|
|
26
|
+
});
|
|
27
|
+
exports.createCoreDataSource = createCoreDataSource;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitialSchema1710000000000 = void 0;
|
|
4
|
+
class InitialSchema1710000000000 {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = "InitialSchema1710000000000";
|
|
7
|
+
}
|
|
8
|
+
async up(queryRunner) {
|
|
9
|
+
const ts = `
|
|
10
|
+
created_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
|
11
|
+
updated_at datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
|
12
|
+
deleted_at datetime(6) NULL
|
|
13
|
+
`;
|
|
14
|
+
await queryRunner.query(`
|
|
15
|
+
CREATE TABLE users (
|
|
16
|
+
id char(36) NOT NULL,
|
|
17
|
+
name varchar(100) NOT NULL,
|
|
18
|
+
last_name varchar(100) NULL,
|
|
19
|
+
phone varchar(20) NULL,
|
|
20
|
+
avatar varchar(500) NULL,
|
|
21
|
+
email varchar(255) NOT NULL,
|
|
22
|
+
password varchar(255) NOT NULL,
|
|
23
|
+
is_active tinyint NOT NULL DEFAULT 1,
|
|
24
|
+
two_factor_enabled tinyint NOT NULL DEFAULT 0,
|
|
25
|
+
two_factor_secret varchar(255) NULL,
|
|
26
|
+
two_factor_confirmed_at datetime NULL,
|
|
27
|
+
backup_codes json NULL,
|
|
28
|
+
failed_login_attempts int NOT NULL DEFAULT 0,
|
|
29
|
+
locked_until datetime NULL,
|
|
30
|
+
password_changed_at datetime NULL,
|
|
31
|
+
must_change_password tinyint NOT NULL DEFAULT 0,
|
|
32
|
+
${ts},
|
|
33
|
+
PRIMARY KEY (id),
|
|
34
|
+
UNIQUE KEY UQ_users_email (email)
|
|
35
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
36
|
+
`);
|
|
37
|
+
await queryRunner.query(`
|
|
38
|
+
CREATE TABLE password_history (
|
|
39
|
+
id char(36) NOT NULL,
|
|
40
|
+
user_id char(36) NOT NULL,
|
|
41
|
+
password_hash varchar(255) NOT NULL,
|
|
42
|
+
${ts},
|
|
43
|
+
PRIMARY KEY (id),
|
|
44
|
+
KEY IDX_password_history_user (user_id)
|
|
45
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
46
|
+
`);
|
|
47
|
+
await queryRunner.query(`
|
|
48
|
+
CREATE TABLE auth_tokens (
|
|
49
|
+
id char(36) NOT NULL,
|
|
50
|
+
user_id char(36) NOT NULL,
|
|
51
|
+
token_hash varchar(255) NOT NULL,
|
|
52
|
+
type varchar(30) NOT NULL,
|
|
53
|
+
family char(36) NULL,
|
|
54
|
+
expires_at datetime NOT NULL,
|
|
55
|
+
used tinyint NOT NULL DEFAULT 0,
|
|
56
|
+
revoked tinyint NOT NULL DEFAULT 0,
|
|
57
|
+
ip_address varchar(45) NULL,
|
|
58
|
+
user_agent text NULL,
|
|
59
|
+
${ts},
|
|
60
|
+
PRIMARY KEY (id),
|
|
61
|
+
KEY IDX_auth_tokens_hash_type (token_hash, type),
|
|
62
|
+
KEY IDX_auth_tokens_user_type (user_id, type),
|
|
63
|
+
KEY IDX_auth_tokens_family (family)
|
|
64
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
65
|
+
`);
|
|
66
|
+
await queryRunner.query(`
|
|
67
|
+
CREATE TABLE resources (
|
|
68
|
+
id char(36) NOT NULL,
|
|
69
|
+
name varchar(100) NOT NULL,
|
|
70
|
+
description varchar(255) NULL,
|
|
71
|
+
is_active tinyint NOT NULL DEFAULT 1,
|
|
72
|
+
${ts},
|
|
73
|
+
PRIMARY KEY (id),
|
|
74
|
+
UNIQUE KEY UQ_resources_name (name)
|
|
75
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
76
|
+
`);
|
|
77
|
+
await queryRunner.query(`
|
|
78
|
+
CREATE TABLE actions (
|
|
79
|
+
id char(36) NOT NULL,
|
|
80
|
+
name varchar(100) NOT NULL,
|
|
81
|
+
description varchar(255) NULL,
|
|
82
|
+
is_active tinyint NOT NULL DEFAULT 1,
|
|
83
|
+
${ts},
|
|
84
|
+
PRIMARY KEY (id),
|
|
85
|
+
UNIQUE KEY UQ_actions_name (name)
|
|
86
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
87
|
+
`);
|
|
88
|
+
await queryRunner.query(`
|
|
89
|
+
CREATE TABLE scopes (
|
|
90
|
+
id char(36) NOT NULL,
|
|
91
|
+
name varchar(100) NOT NULL,
|
|
92
|
+
description varchar(255) NULL,
|
|
93
|
+
is_active tinyint NOT NULL DEFAULT 1,
|
|
94
|
+
${ts},
|
|
95
|
+
PRIMARY KEY (id),
|
|
96
|
+
UNIQUE KEY UQ_scopes_name (name)
|
|
97
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
98
|
+
`);
|
|
99
|
+
await queryRunner.query(`
|
|
100
|
+
CREATE TABLE permissions (
|
|
101
|
+
id char(36) NOT NULL,
|
|
102
|
+
code varchar(150) NOT NULL,
|
|
103
|
+
description varchar(255) NULL,
|
|
104
|
+
is_active tinyint NOT NULL DEFAULT 1,
|
|
105
|
+
resource_id char(36) NOT NULL,
|
|
106
|
+
action_id char(36) NOT NULL,
|
|
107
|
+
scope_id char(36) NOT NULL,
|
|
108
|
+
${ts},
|
|
109
|
+
PRIMARY KEY (id),
|
|
110
|
+
UNIQUE KEY UQ_permissions_code (code),
|
|
111
|
+
KEY IDX_permissions_resource (resource_id),
|
|
112
|
+
KEY IDX_permissions_action (action_id),
|
|
113
|
+
KEY IDX_permissions_scope (scope_id),
|
|
114
|
+
CONSTRAINT FK_permissions_resource FOREIGN KEY (resource_id) REFERENCES resources (id),
|
|
115
|
+
CONSTRAINT FK_permissions_action FOREIGN KEY (action_id) REFERENCES actions (id),
|
|
116
|
+
CONSTRAINT FK_permissions_scope FOREIGN KEY (scope_id) REFERENCES scopes (id)
|
|
117
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
118
|
+
`);
|
|
119
|
+
await queryRunner.query(`
|
|
120
|
+
CREATE TABLE roles (
|
|
121
|
+
id char(36) NOT NULL,
|
|
122
|
+
name varchar(100) NOT NULL,
|
|
123
|
+
description varchar(255) NULL,
|
|
124
|
+
is_active tinyint NOT NULL DEFAULT 1,
|
|
125
|
+
${ts},
|
|
126
|
+
PRIMARY KEY (id),
|
|
127
|
+
UNIQUE KEY UQ_roles_name (name)
|
|
128
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
129
|
+
`);
|
|
130
|
+
await queryRunner.query(`
|
|
131
|
+
CREATE TABLE \`groups\` (
|
|
132
|
+
id char(36) NOT NULL,
|
|
133
|
+
name varchar(100) NOT NULL,
|
|
134
|
+
description varchar(255) NULL,
|
|
135
|
+
type varchar(50) NOT NULL DEFAULT 'team',
|
|
136
|
+
parent_id char(36) NULL,
|
|
137
|
+
is_active tinyint NOT NULL DEFAULT 1,
|
|
138
|
+
${ts},
|
|
139
|
+
PRIMARY KEY (id),
|
|
140
|
+
KEY IDX_groups_parent (parent_id),
|
|
141
|
+
CONSTRAINT FK_groups_parent FOREIGN KEY (parent_id) REFERENCES \`groups\` (id)
|
|
142
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
143
|
+
`);
|
|
144
|
+
await queryRunner.query(`
|
|
145
|
+
CREATE TABLE role_permissions (
|
|
146
|
+
role_id char(36) NOT NULL,
|
|
147
|
+
permission_id char(36) NOT NULL,
|
|
148
|
+
PRIMARY KEY (role_id, permission_id),
|
|
149
|
+
KEY IDX_role_permissions_perm (permission_id),
|
|
150
|
+
CONSTRAINT FK_role_permissions_role FOREIGN KEY (role_id) REFERENCES roles (id) ON DELETE CASCADE,
|
|
151
|
+
CONSTRAINT FK_role_permissions_perm FOREIGN KEY (permission_id) REFERENCES permissions (id) ON DELETE CASCADE
|
|
152
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
153
|
+
`);
|
|
154
|
+
await queryRunner.query(`
|
|
155
|
+
CREATE TABLE user_roles (
|
|
156
|
+
user_id char(36) NOT NULL,
|
|
157
|
+
role_id char(36) NOT NULL,
|
|
158
|
+
PRIMARY KEY (user_id, role_id),
|
|
159
|
+
KEY IDX_user_roles_role (role_id),
|
|
160
|
+
CONSTRAINT FK_user_roles_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
|
|
161
|
+
CONSTRAINT FK_user_roles_role FOREIGN KEY (role_id) REFERENCES roles (id) ON DELETE CASCADE
|
|
162
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
163
|
+
`);
|
|
164
|
+
await queryRunner.query(`
|
|
165
|
+
CREATE TABLE user_permissions (
|
|
166
|
+
user_id char(36) NOT NULL,
|
|
167
|
+
permission_id char(36) NOT NULL,
|
|
168
|
+
PRIMARY KEY (user_id, permission_id),
|
|
169
|
+
KEY IDX_user_permissions_perm (permission_id),
|
|
170
|
+
CONSTRAINT FK_user_permissions_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
|
|
171
|
+
CONSTRAINT FK_user_permissions_perm FOREIGN KEY (permission_id) REFERENCES permissions (id) ON DELETE CASCADE
|
|
172
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
173
|
+
`);
|
|
174
|
+
await queryRunner.query(`
|
|
175
|
+
CREATE TABLE user_groups (
|
|
176
|
+
user_id char(36) NOT NULL,
|
|
177
|
+
group_id char(36) NOT NULL,
|
|
178
|
+
PRIMARY KEY (user_id, group_id),
|
|
179
|
+
KEY IDX_user_groups_group (group_id),
|
|
180
|
+
CONSTRAINT FK_user_groups_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
|
|
181
|
+
CONSTRAINT FK_user_groups_group FOREIGN KEY (group_id) REFERENCES \`groups\` (id) ON DELETE CASCADE
|
|
182
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
183
|
+
`);
|
|
184
|
+
await queryRunner.query(`
|
|
185
|
+
CREATE TABLE group_roles (
|
|
186
|
+
group_id char(36) NOT NULL,
|
|
187
|
+
role_id char(36) NOT NULL,
|
|
188
|
+
PRIMARY KEY (group_id, role_id),
|
|
189
|
+
KEY IDX_group_roles_role (role_id),
|
|
190
|
+
CONSTRAINT FK_group_roles_group FOREIGN KEY (group_id) REFERENCES \`groups\` (id) ON DELETE CASCADE,
|
|
191
|
+
CONSTRAINT FK_group_roles_role FOREIGN KEY (role_id) REFERENCES roles (id) ON DELETE CASCADE
|
|
192
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
193
|
+
`);
|
|
194
|
+
await queryRunner.query(`
|
|
195
|
+
CREATE TABLE audit_changes (
|
|
196
|
+
id char(36) NOT NULL,
|
|
197
|
+
user_id char(36) NULL,
|
|
198
|
+
action varchar(100) NOT NULL,
|
|
199
|
+
entity varchar(100) NULL,
|
|
200
|
+
entity_id varchar(36) NULL,
|
|
201
|
+
method varchar(10) NULL,
|
|
202
|
+
path varchar(255) NULL,
|
|
203
|
+
ip_address varchar(45) NULL,
|
|
204
|
+
metadata json NULL,
|
|
205
|
+
status_code int NULL,
|
|
206
|
+
duration_ms int NULL,
|
|
207
|
+
request_id char(36) NULL,
|
|
208
|
+
${ts},
|
|
209
|
+
PRIMARY KEY (id),
|
|
210
|
+
KEY IDX_audit_changes_user (user_id),
|
|
211
|
+
KEY IDX_audit_changes_entity (entity),
|
|
212
|
+
KEY IDX_audit_changes_request_id (request_id),
|
|
213
|
+
KEY IDX_audit_changes_status_code (status_code)
|
|
214
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
215
|
+
`);
|
|
216
|
+
await queryRunner.query(`
|
|
217
|
+
CREATE TABLE error_logs (
|
|
218
|
+
id char(36) NOT NULL,
|
|
219
|
+
status_code int NULL,
|
|
220
|
+
message varchar(255) NOT NULL,
|
|
221
|
+
stack text NULL,
|
|
222
|
+
method varchar(10) NULL,
|
|
223
|
+
path varchar(255) NULL,
|
|
224
|
+
user_id char(36) NULL,
|
|
225
|
+
ip_address varchar(45) NULL,
|
|
226
|
+
type enum('VALIDATION','AUTH','NOT_FOUND','RATE_LIMIT','DATABASE','INTEGRATION','INTERNAL') NOT NULL DEFAULT 'INTERNAL',
|
|
227
|
+
request_id char(36) NULL,
|
|
228
|
+
${ts},
|
|
229
|
+
PRIMARY KEY (id),
|
|
230
|
+
KEY IDX_error_logs_status (status_code),
|
|
231
|
+
KEY IDX_error_logs_type (type),
|
|
232
|
+
KEY IDX_error_logs_request_id (request_id)
|
|
233
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
234
|
+
`);
|
|
235
|
+
await queryRunner.query(`
|
|
236
|
+
CREATE TABLE audit_data_changes (
|
|
237
|
+
id char(36) NOT NULL,
|
|
238
|
+
entity varchar(100) NOT NULL,
|
|
239
|
+
entity_id varchar(36) NULL,
|
|
240
|
+
action enum('CREATE','UPDATE','DELETE') NOT NULL,
|
|
241
|
+
old_data json NULL,
|
|
242
|
+
new_data json NULL,
|
|
243
|
+
user_id char(36) NULL,
|
|
244
|
+
ip_address varchar(45) NULL,
|
|
245
|
+
${ts},
|
|
246
|
+
PRIMARY KEY (id),
|
|
247
|
+
KEY IDX_audit_data_changes_entity (entity, entity_id),
|
|
248
|
+
KEY IDX_audit_data_changes_user (user_id)
|
|
249
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
250
|
+
`);
|
|
251
|
+
}
|
|
252
|
+
async down(queryRunner) {
|
|
253
|
+
await queryRunner.query("DROP TABLE IF EXISTS audit_data_changes;");
|
|
254
|
+
await queryRunner.query("DROP TABLE IF EXISTS error_logs;");
|
|
255
|
+
await queryRunner.query("DROP TABLE IF EXISTS audit_changes;");
|
|
256
|
+
await queryRunner.query("DROP TABLE IF EXISTS group_roles;");
|
|
257
|
+
await queryRunner.query("DROP TABLE IF EXISTS user_groups;");
|
|
258
|
+
await queryRunner.query("DROP TABLE IF EXISTS user_permissions;");
|
|
259
|
+
await queryRunner.query("DROP TABLE IF EXISTS user_roles;");
|
|
260
|
+
await queryRunner.query("DROP TABLE IF EXISTS role_permissions;");
|
|
261
|
+
await queryRunner.query("DROP TABLE IF EXISTS `groups`;");
|
|
262
|
+
await queryRunner.query("DROP TABLE IF EXISTS roles;");
|
|
263
|
+
await queryRunner.query("DROP TABLE IF EXISTS permissions;");
|
|
264
|
+
await queryRunner.query("DROP TABLE IF EXISTS scopes;");
|
|
265
|
+
await queryRunner.query("DROP TABLE IF EXISTS actions;");
|
|
266
|
+
await queryRunner.query("DROP TABLE IF EXISTS resources;");
|
|
267
|
+
await queryRunner.query("DROP TABLE IF EXISTS auth_tokens;");
|
|
268
|
+
await queryRunner.query("DROP TABLE IF EXISTS password_history;");
|
|
269
|
+
await queryRunner.query("DROP TABLE IF EXISTS users;");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.InitialSchema1710000000000 = InitialSchema1710000000000;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirstAccessTokenType1786060800000 = void 0;
|
|
4
|
+
class FirstAccessTokenType1786060800000 {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = "FirstAccessTokenType1786060800000";
|
|
7
|
+
}
|
|
8
|
+
async up(queryRunner) {
|
|
9
|
+
await queryRunner.query(`
|
|
10
|
+
ALTER TABLE auth_tokens
|
|
11
|
+
MODIFY COLUMN type ENUM('password_reset','first_access','two_factor_email','refresh_token','totp_used') NOT NULL
|
|
12
|
+
`);
|
|
13
|
+
}
|
|
14
|
+
async down(queryRunner) {
|
|
15
|
+
await queryRunner.query(`DELETE FROM auth_tokens WHERE type = 'first_access'`);
|
|
16
|
+
await queryRunner.query(`ALTER TABLE auth_tokens MODIFY COLUMN type varchar(30) NOT NULL`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FirstAccessTokenType1786060800000 = FirstAccessTokenType1786060800000;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermanentAccountLock1786147200000 = void 0;
|
|
4
|
+
class PermanentAccountLock1786147200000 {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = "PermanentAccountLock1786147200000";
|
|
7
|
+
}
|
|
8
|
+
async up(queryRunner) {
|
|
9
|
+
await queryRunner.query(`ALTER TABLE users DROP COLUMN locked_until`);
|
|
10
|
+
}
|
|
11
|
+
async down(queryRunner) {
|
|
12
|
+
await queryRunner.query(`ALTER TABLE users ADD COLUMN locked_until datetime NULL`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.PermanentAccountLock1786147200000 = PermanentAccountLock1786147200000;
|