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
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# rl-core-api
|
|
2
|
+
|
|
3
|
+
Base NestJS para não recomeçar todo projeto pelo login.
|
|
4
|
+
|
|
5
|
+
Instala e o sistema já sobe com autenticação (2FA obrigatório por TOTP), RBAC,
|
|
6
|
+
trilha de auditoria, notificações em WebSocket e listagens paginadas com filtro
|
|
7
|
+
dinâmico. Você escreve só o domínio.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install rl-core-api
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Uso
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// src/app.module.ts
|
|
17
|
+
import { Module } from "@nestjs/common";
|
|
18
|
+
import { RlCoreModule } from "rl-core-api";
|
|
19
|
+
|
|
20
|
+
import { ContasModule } from "@/features/contas/contas.module";
|
|
21
|
+
import { Conta } from "@/features/contas/infra/schema/conta.schema";
|
|
22
|
+
|
|
23
|
+
@Module({
|
|
24
|
+
imports: [RlCoreModule.forRoot({ entities: [Conta] }), ContasModule],
|
|
25
|
+
})
|
|
26
|
+
export class AppModule {}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// src/main.ts
|
|
31
|
+
import { bootstrapCore } from "rl-core-api";
|
|
32
|
+
|
|
33
|
+
import { AppModule } from "@/app.module";
|
|
34
|
+
|
|
35
|
+
void bootstrapCore(AppModule, { title: "Controle Pessoal" });
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// src/data-source.ts — a CLI do TypeORM usa este arquivo
|
|
40
|
+
import "dotenv/config";
|
|
41
|
+
import { coreEntities, coreMigrations, createCoreDataSource } from "rl-core-api";
|
|
42
|
+
|
|
43
|
+
import { CreateContas1790000000000 } from "@/migrations/1790000000000-CreateContas";
|
|
44
|
+
import { Conta } from "@/features/contas/infra/schema/conta.schema";
|
|
45
|
+
|
|
46
|
+
export const AppDataSource = createCoreDataSource({
|
|
47
|
+
entities: [...coreEntities, Conta],
|
|
48
|
+
migrations: [...coreMigrations, CreateContas1790000000000],
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`npm run migration:run` cria as tabelas do core e as suas, na ordem certa. As
|
|
53
|
+
migrations do core vêm no pacote — você nunca copia nem reescreve nenhuma.
|
|
54
|
+
|
|
55
|
+
## O que vem pronto
|
|
56
|
+
|
|
57
|
+
| | |
|
|
58
|
+
|---|---|
|
|
59
|
+
| **Auth** | login, refresh por cookie httpOnly, 2FA obrigatório (TOTP + fallback por e-mail + códigos de backup), primeiro acesso, reset de senha, bloqueio por tentativas, expiração de senha |
|
|
60
|
+
| **RBAC** | resources, actions, scopes, permissions, roles e groups, com guard por `resource:action:scope` |
|
|
61
|
+
| **Auditoria** | trilha de alterações de dados, log de requisições e log de erros, com retenção configurável |
|
|
62
|
+
| **Notificações** | WebSocket com handshake por cookie ou Bearer, escopo resolvido na leitura |
|
|
63
|
+
| **Listagens** | paginação, ordenação e filtro dinâmico com catálogo por listagem (`$AND`/`$OR` aninhados, 17 operadores) |
|
|
64
|
+
| **Infra** | config validada com Zod, mailer, agendador, rate-limit, CSRF, filtro global de exceções, logger Winston |
|
|
65
|
+
|
|
66
|
+
## Configuração
|
|
67
|
+
|
|
68
|
+
O pacote **não traz `.env`** — ele declara o que precisa e quebra no boot se
|
|
69
|
+
faltar. Cada projeto tem os valores dele (banco próprio, segredo JWT próprio).
|
|
70
|
+
Comece pelo `.env.example` do repositório.
|
|
71
|
+
|
|
72
|
+
Para acrescentar variáveis suas, estenda o schema:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { envSchema } from "rl-core-api";
|
|
76
|
+
|
|
77
|
+
export const appEnvSchema = envSchema.extend({
|
|
78
|
+
FUNKO_API_KEY: z.string().min(1),
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Peer dependencies
|
|
83
|
+
|
|
84
|
+
`@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express`, `@nestjs/swagger`,
|
|
85
|
+
`@nestjs/typeorm`, `class-transformer`, `class-validator`, `reflect-metadata`,
|
|
86
|
+
`rxjs`, `typeorm` e `zod` são peers: precisam ser uma instância só, ou a
|
|
87
|
+
injeção de dependência e os decorators param de se enxergar. O npm 7+ instala
|
|
88
|
+
sozinho.
|
|
89
|
+
|
|
90
|
+
## Pacotes irmãos
|
|
91
|
+
|
|
92
|
+
| | |
|
|
93
|
+
|---|---|
|
|
94
|
+
| [`rl-core-front`](https://www.npmjs.com/package/rl-core-front) | as telas em Next.js |
|
|
95
|
+
| `rl_core_app` | o app Flutter, consumido por tag do git |
|
|
96
|
+
|
|
97
|
+
## Licença
|
|
98
|
+
|
|
99
|
+
MIT © Rodrigo Liberti
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AppModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const rlCore_module_1 = require("./rlCore.module");
|
|
12
|
+
let AppModule = class AppModule {
|
|
13
|
+
};
|
|
14
|
+
exports.AppModule = AppModule;
|
|
15
|
+
exports.AppModule = AppModule = __decorate([
|
|
16
|
+
(0, common_1.Module)({
|
|
17
|
+
imports: [rlCore_module_1.RlCoreModule.forRoot()],
|
|
18
|
+
})
|
|
19
|
+
], AppModule);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Request } from "express";
|
|
2
|
+
export interface AuthenticatedUser {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
name: string;
|
|
6
|
+
lastName?: string | null;
|
|
7
|
+
avatar?: string | null;
|
|
8
|
+
roles: string[];
|
|
9
|
+
permissions: string[];
|
|
10
|
+
twoFactorEnabled: boolean;
|
|
11
|
+
passwordExpired: boolean;
|
|
12
|
+
mustChangePassword: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface RequestWithUser extends Request {
|
|
15
|
+
user?: AuthenticatedUser;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
2
|
+
import { EnvService } from "../config/env.service";
|
|
3
|
+
export declare const ACCESS_COOKIE = "access_token";
|
|
4
|
+
export declare const REFRESH_COOKIE = "refresh_token";
|
|
5
|
+
export declare function setAuthCookies(res: Response, env: EnvService, tokens: {
|
|
6
|
+
accessToken: string;
|
|
7
|
+
refreshToken: string;
|
|
8
|
+
}): void;
|
|
9
|
+
export declare function clearAuthCookies(res: Response, env: EnvService): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFRESH_COOKIE = exports.ACCESS_COOKIE = void 0;
|
|
4
|
+
exports.setAuthCookies = setAuthCookies;
|
|
5
|
+
exports.clearAuthCookies = clearAuthCookies;
|
|
6
|
+
exports.ACCESS_COOKIE = "access_token";
|
|
7
|
+
exports.REFRESH_COOKIE = "refresh_token";
|
|
8
|
+
function setAuthCookies(res, env, tokens) {
|
|
9
|
+
const secure = env.get("COOKIE_SECURE");
|
|
10
|
+
const domain = env.get("COOKIE_DOMAIN");
|
|
11
|
+
const common = {
|
|
12
|
+
httpOnly: true,
|
|
13
|
+
secure,
|
|
14
|
+
sameSite: "lax",
|
|
15
|
+
domain,
|
|
16
|
+
path: "/",
|
|
17
|
+
};
|
|
18
|
+
res.cookie(exports.ACCESS_COOKIE, tokens.accessToken, common);
|
|
19
|
+
res.cookie(exports.REFRESH_COOKIE, tokens.refreshToken, {
|
|
20
|
+
...common,
|
|
21
|
+
maxAge: env.get("JWT_REFRESH_EXPIRES_MINUTES") * 60_000,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function clearAuthCookies(res, env) {
|
|
25
|
+
const domain = env.get("COOKIE_DOMAIN");
|
|
26
|
+
res.clearCookie(exports.ACCESS_COOKIE, { domain, path: "/" });
|
|
27
|
+
res.clearCookie(exports.REFRESH_COOKIE, { domain, path: "/" });
|
|
28
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticatedUser } from "../authenticatedUser.interface";
|
|
2
|
+
export declare const CurrentUser: (...dataOrPipes: (keyof AuthenticatedUser | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentUser = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.CurrentUser = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
const user = request.user;
|
|
8
|
+
return data ? user?.[data] : user;
|
|
9
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.IS_PUBLIC_KEY = "isPublic";
|
|
6
|
+
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
7
|
+
exports.Public = Public;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CustomDecorator } from "@nestjs/common";
|
|
2
|
+
export declare const PERMISSIONS_KEY = "requiredPermissions";
|
|
3
|
+
export declare const ANY_PERMISSIONS_KEY = "requiredAnyPermissions";
|
|
4
|
+
export declare const RequirePermission: (...codes: string[]) => CustomDecorator<string>;
|
|
5
|
+
export declare const RequireAnyPermission: (...codes: string[]) => CustomDecorator<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequireAnyPermission = exports.RequirePermission = exports.ANY_PERMISSIONS_KEY = exports.PERMISSIONS_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.PERMISSIONS_KEY = "requiredPermissions";
|
|
6
|
+
exports.ANY_PERMISSIONS_KEY = "requiredAnyPermissions";
|
|
7
|
+
const RequirePermission = (...codes) => (0, common_1.SetMetadata)(exports.PERMISSIONS_KEY, codes);
|
|
8
|
+
exports.RequirePermission = RequirePermission;
|
|
9
|
+
const RequireAnyPermission = (...codes) => (0, common_1.SetMetadata)(exports.ANY_PERMISSIONS_KEY, codes);
|
|
10
|
+
exports.RequireAnyPermission = RequireAnyPermission;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { ThrottlerGuard, ThrottlerLimitDetail } from "@nestjs/throttler";
|
|
3
|
+
export declare class AppThrottlerGuard extends ThrottlerGuard {
|
|
4
|
+
protected throwThrottlingException(_context: ExecutionContext, _throttlerLimitDetail: ThrottlerLimitDetail): Promise<void>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AppThrottlerGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
12
|
+
const appErrorCode_enum_1 = require("../../filters/appErrorCode.enum");
|
|
13
|
+
const codedError_util_1 = require("../../utils/codedError.util");
|
|
14
|
+
const THROTTLE_MESSAGE = "Muitas tentativas em pouco tempo. Aguarde um instante e tente de novo";
|
|
15
|
+
let AppThrottlerGuard = class AppThrottlerGuard extends throttler_1.ThrottlerGuard {
|
|
16
|
+
throwThrottlingException(_context, _throttlerLimitDetail) {
|
|
17
|
+
throw (0, codedError_util_1.codedTooManyRequests)(THROTTLE_MESSAGE, appErrorCode_enum_1.AppErrorCode.TOO_MANY_REQUESTS);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.AppThrottlerGuard = AppThrottlerGuard;
|
|
21
|
+
exports.AppThrottlerGuard = AppThrottlerGuard = __decorate([
|
|
22
|
+
(0, common_1.Injectable)()
|
|
23
|
+
], AppThrottlerGuard);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { EnvService } from "../../config/env.service";
|
|
3
|
+
export declare class CsrfGuard implements CanActivate {
|
|
4
|
+
private readonly env;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(env: EnvService);
|
|
7
|
+
canActivate(context: ExecutionContext): boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
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 CsrfGuard_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.CsrfGuard = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const env_service_1 = require("../../config/env.service");
|
|
16
|
+
const MUTATING = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
17
|
+
let CsrfGuard = CsrfGuard_1 = class CsrfGuard {
|
|
18
|
+
constructor(env) {
|
|
19
|
+
this.env = env;
|
|
20
|
+
this.logger = new common_1.Logger(CsrfGuard_1.name);
|
|
21
|
+
}
|
|
22
|
+
canActivate(context) {
|
|
23
|
+
const req = context.switchToHttp().getRequest();
|
|
24
|
+
if (!MUTATING.has(req.method)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const hasSessionCookie = !!req.cookies?.access_token || !!req.cookies?.refresh_token;
|
|
28
|
+
if (!hasSessionCookie) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const allowed = this.env
|
|
32
|
+
.get("CORS_ORIGIN")
|
|
33
|
+
.split(",")
|
|
34
|
+
.map((o) => o.trim());
|
|
35
|
+
let origin = req.headers.origin ?? null;
|
|
36
|
+
if (!origin && req.headers.referer) {
|
|
37
|
+
try {
|
|
38
|
+
origin = new URL(req.headers.referer).origin;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
this.logger.warn(`Referer inválido: ${req.headers.referer} (${err.message})`);
|
|
42
|
+
origin = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (origin && allowed.includes(origin)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
throw new common_1.ForbiddenException("Origem não permitida (proteção CSRF)");
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.CsrfGuard = CsrfGuard;
|
|
52
|
+
exports.CsrfGuard = CsrfGuard = CsrfGuard_1 = __decorate([
|
|
53
|
+
(0, common_1.Injectable)(),
|
|
54
|
+
__metadata("design:paramtypes", [env_service_1.EnvService])
|
|
55
|
+
], CsrfGuard);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
3
|
+
import { Observable } from "rxjs";
|
|
4
|
+
declare const JwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
5
|
+
export declare class JwtAuthGuard extends JwtAuthGuard_base {
|
|
6
|
+
private readonly reflector;
|
|
7
|
+
constructor(reflector: Reflector);
|
|
8
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
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.JwtAuthGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const passport_1 = require("@nestjs/passport");
|
|
16
|
+
const public_decorator_1 = require("../decorators/public.decorator");
|
|
17
|
+
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)("jwt") {
|
|
18
|
+
constructor(reflector) {
|
|
19
|
+
super();
|
|
20
|
+
this.reflector = reflector;
|
|
21
|
+
}
|
|
22
|
+
canActivate(context) {
|
|
23
|
+
const isPublic = this.reflector.getAllAndOverride(public_decorator_1.IS_PUBLIC_KEY, [
|
|
24
|
+
context.getHandler(),
|
|
25
|
+
context.getClass(),
|
|
26
|
+
]);
|
|
27
|
+
if (isPublic) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return super.canActivate(context);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
34
|
+
exports.JwtAuthGuard = JwtAuthGuard = __decorate([
|
|
35
|
+
(0, common_1.Injectable)(),
|
|
36
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
37
|
+
], JwtAuthGuard);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
3
|
+
export declare class PermissionsGuard implements CanActivate {
|
|
4
|
+
private readonly reflector;
|
|
5
|
+
constructor(reflector: Reflector);
|
|
6
|
+
canActivate(context: ExecutionContext): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.PermissionsGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const requirePermission_decorator_1 = require("../decorators/requirePermission.decorator");
|
|
16
|
+
let PermissionsGuard = class PermissionsGuard {
|
|
17
|
+
constructor(reflector) {
|
|
18
|
+
this.reflector = reflector;
|
|
19
|
+
}
|
|
20
|
+
canActivate(context) {
|
|
21
|
+
const targets = [context.getHandler(), context.getClass()];
|
|
22
|
+
const required = this.reflector.getAllAndOverride(requirePermission_decorator_1.PERMISSIONS_KEY, targets);
|
|
23
|
+
const requiredAny = this.reflector.getAllAndOverride(requirePermission_decorator_1.ANY_PERMISSIONS_KEY, targets);
|
|
24
|
+
if ((!required || required.length === 0) &&
|
|
25
|
+
(!requiredAny || requiredAny.length === 0)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const user = context.switchToHttp().getRequest().user;
|
|
29
|
+
const granted = new Set(user?.permissions ?? []);
|
|
30
|
+
const allOk = !required?.length || required.every((code) => granted.has(code));
|
|
31
|
+
const anyOk = !requiredAny?.length || requiredAny.some((code) => granted.has(code));
|
|
32
|
+
if (!allOk || !anyOk) {
|
|
33
|
+
throw new common_1.ForbiddenException("Permissão insuficiente para esta ação");
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.PermissionsGuard = PermissionsGuard;
|
|
39
|
+
exports.PermissionsGuard = PermissionsGuard = __decorate([
|
|
40
|
+
(0, common_1.Injectable)(),
|
|
41
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
42
|
+
], PermissionsGuard);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IEntryNestModule } from "@nestjs/core";
|
|
2
|
+
import { NestExpressApplication } from "@nestjs/platform-express";
|
|
3
|
+
export interface BootstrapOptions {
|
|
4
|
+
title?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
uploadsDir?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const bootstrapCore: (appModule: IEntryNestModule, options?: BootstrapOptions) => Promise<NestExpressApplication>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.bootstrapCore = void 0;
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const core_1 = require("@nestjs/core");
|
|
9
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
10
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
11
|
+
const helmet_1 = __importDefault(require("helmet"));
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const env_service_1 = require("../config/env.service");
|
|
14
|
+
const winston_config_1 = require("../logger/winston.config");
|
|
15
|
+
const bootstrapCore = async (appModule, options = {}) => {
|
|
16
|
+
const app = await core_1.NestFactory.create(appModule, {
|
|
17
|
+
logger: (0, winston_config_1.createAppLogger)(),
|
|
18
|
+
});
|
|
19
|
+
const env = app.get(env_service_1.EnvService);
|
|
20
|
+
const logger = new common_1.Logger("Bootstrap");
|
|
21
|
+
app.set("trust proxy", env.get("TRUST_PROXY_HOPS"));
|
|
22
|
+
const prefix = env.get("API_PREFIX");
|
|
23
|
+
app.setGlobalPrefix(prefix);
|
|
24
|
+
app.enableVersioning({ type: common_1.VersioningType.URI, defaultVersion: "1" });
|
|
25
|
+
app.use((0, helmet_1.default)({ contentSecurityPolicy: false }));
|
|
26
|
+
app.use((0, cookie_parser_1.default)());
|
|
27
|
+
app.useStaticAssets((0, path_1.join)(process.cwd(), options.uploadsDir ?? "uploads"), {
|
|
28
|
+
prefix: "/uploads/",
|
|
29
|
+
setHeaders: (res) => {
|
|
30
|
+
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
|
|
31
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
app.enableCors({
|
|
35
|
+
origin: env
|
|
36
|
+
.get("CORS_ORIGIN")
|
|
37
|
+
.split(",")
|
|
38
|
+
.map((o) => o.trim()),
|
|
39
|
+
credentials: true,
|
|
40
|
+
});
|
|
41
|
+
app.useGlobalPipes(new common_1.ValidationPipe({
|
|
42
|
+
whitelist: true,
|
|
43
|
+
forbidNonWhitelisted: true,
|
|
44
|
+
transform: true,
|
|
45
|
+
transformOptions: { enableImplicitConversion: true },
|
|
46
|
+
}));
|
|
47
|
+
app.useGlobalInterceptors(new common_1.ClassSerializerInterceptor(app.get(core_1.Reflector)));
|
|
48
|
+
if (env.get("NODE_ENV") !== "production") {
|
|
49
|
+
const config = new swagger_1.DocumentBuilder()
|
|
50
|
+
.setTitle(options.title ?? "Core API")
|
|
51
|
+
.setDescription(options.description ?? "Auth + 2FA obrigatório (TOTP) + RBAC + auditoria")
|
|
52
|
+
.setVersion(options.version ?? "1.0")
|
|
53
|
+
.addBearerAuth()
|
|
54
|
+
.addCookieAuth("access_token")
|
|
55
|
+
.build();
|
|
56
|
+
const document = swagger_1.SwaggerModule.createDocument(app, config);
|
|
57
|
+
swagger_1.SwaggerModule.setup(`${prefix}/docs`, app, document);
|
|
58
|
+
}
|
|
59
|
+
const port = env.get("PORT");
|
|
60
|
+
await app.listen(port);
|
|
61
|
+
logger.log(`${options.title ?? "Core API"} rodando em http://localhost:${port}/${prefix}`);
|
|
62
|
+
if (env.get("NODE_ENV") !== "production") {
|
|
63
|
+
logger.log(`Swagger em http://localhost:${port}/${prefix}/docs`);
|
|
64
|
+
}
|
|
65
|
+
return app;
|
|
66
|
+
};
|
|
67
|
+
exports.bootstrapCore = bootstrapCore;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
export type EnvValidator = (config: Record<string, unknown>) => Record<string, unknown>;
|
|
3
|
+
export interface ConfigModuleOptions {
|
|
4
|
+
validateEnv?: EnvValidator;
|
|
5
|
+
}
|
|
6
|
+
export declare class ConfigModule {
|
|
7
|
+
static forRoot(options?: ConfigModuleOptions): DynamicModule;
|
|
8
|
+
}
|
|
@@ -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 ConfigModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ConfigModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const config_1 = require("@nestjs/config");
|
|
13
|
+
const env_schema_1 = require("./env.schema");
|
|
14
|
+
const env_service_1 = require("./env.service");
|
|
15
|
+
let ConfigModule = ConfigModule_1 = class ConfigModule {
|
|
16
|
+
static forRoot(options = {}) {
|
|
17
|
+
return {
|
|
18
|
+
module: ConfigModule_1,
|
|
19
|
+
global: true,
|
|
20
|
+
imports: [
|
|
21
|
+
config_1.ConfigModule.forRoot({
|
|
22
|
+
isGlobal: true,
|
|
23
|
+
validate: options.validateEnv ?? env_schema_1.validateEnv,
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
providers: [env_service_1.EnvService],
|
|
27
|
+
exports: [env_service_1.EnvService],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.ConfigModule = ConfigModule;
|
|
32
|
+
exports.ConfigModule = ConfigModule = ConfigModule_1 = __decorate([
|
|
33
|
+
(0, common_1.Module)({})
|
|
34
|
+
], ConfigModule);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const envSchema: z.ZodObject<{
|
|
3
|
+
NODE_ENV: z.ZodDefault<z.ZodEnum<{
|
|
4
|
+
development: "development";
|
|
5
|
+
test: "test";
|
|
6
|
+
production: "production";
|
|
7
|
+
}>>;
|
|
8
|
+
PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
9
|
+
API_PREFIX: z.ZodDefault<z.ZodString>;
|
|
10
|
+
APP_URL: z.ZodDefault<z.ZodString>;
|
|
11
|
+
DB_HOST: z.ZodString;
|
|
12
|
+
DB_PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
13
|
+
DB_NAME: z.ZodString;
|
|
14
|
+
DB_USER: z.ZodString;
|
|
15
|
+
DB_PASSWORD: z.ZodString;
|
|
16
|
+
DB_LOGGING: z.ZodDefault<z.ZodPipe<z.ZodEnum<{
|
|
17
|
+
true: "true";
|
|
18
|
+
false: "false";
|
|
19
|
+
}>, z.ZodTransform<boolean, "true" | "false">>>;
|
|
20
|
+
DB_SSL: z.ZodDefault<z.ZodPipe<z.ZodEnum<{
|
|
21
|
+
true: "true";
|
|
22
|
+
false: "false";
|
|
23
|
+
}>, z.ZodTransform<boolean, "true" | "false">>>;
|
|
24
|
+
TRUST_PROXY_HOPS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
25
|
+
JWT_ACCESS_SECRET: z.ZodString;
|
|
26
|
+
JWT_PENDING_SECRET: z.ZodString;
|
|
27
|
+
JWT_ACCESS_EXPIRES: z.ZodDefault<z.ZodString>;
|
|
28
|
+
JWT_REFRESH_EXPIRES_MINUTES: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
29
|
+
TOTP_ENC_KEY: z.ZodString;
|
|
30
|
+
COOKIE_SECURE: z.ZodDefault<z.ZodPipe<z.ZodEnum<{
|
|
31
|
+
true: "true";
|
|
32
|
+
false: "false";
|
|
33
|
+
}>, z.ZodTransform<boolean, "true" | "false">>>;
|
|
34
|
+
COOKIE_DOMAIN: z.ZodDefault<z.ZodString>;
|
|
35
|
+
TOTP_ISSUER: z.ZodDefault<z.ZodString>;
|
|
36
|
+
TWO_FACTOR_EMAIL_CODE_EXPIRY: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
37
|
+
BACKUP_CODES_COUNT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
38
|
+
LOGIN_MAX_ATTEMPTS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
39
|
+
THROTTLE_TTL_SECONDS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
40
|
+
THROTTLE_LIMIT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
41
|
+
CORS_ORIGIN: z.ZodDefault<z.ZodString>;
|
|
42
|
+
LOG_LEVEL: z.ZodDefault<z.ZodString>;
|
|
43
|
+
EMAIL_HOST: z.ZodString;
|
|
44
|
+
EMAIL_PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
45
|
+
EMAIL_SECURE: z.ZodDefault<z.ZodPipe<z.ZodEnum<{
|
|
46
|
+
true: "true";
|
|
47
|
+
false: "false";
|
|
48
|
+
}>, z.ZodTransform<boolean, "true" | "false">>>;
|
|
49
|
+
EMAIL_USER: z.ZodString;
|
|
50
|
+
EMAIL_PASSWORD: z.ZodString;
|
|
51
|
+
EMAIL_FROM: z.ZodString;
|
|
52
|
+
EMAIL_FROM_NAME: z.ZodDefault<z.ZodString>;
|
|
53
|
+
PASSWORD_RESET_TOKEN_EXPIRY: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
54
|
+
FIRST_ACCESS_TOKEN_EXPIRY: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
55
|
+
PASSWORD_MAX_AGE_DAYS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
56
|
+
TOKEN_CLEANUP_CRON: z.ZodDefault<z.ZodString>;
|
|
57
|
+
AUDIT_LOG_CLEANUP_CRON: z.ZodDefault<z.ZodString>;
|
|
58
|
+
AUDIT_LOG_RETENTION_DAYS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
59
|
+
NOTIFICATION_RETENTION_DAYS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
60
|
+
SEED_ADMIN_NAME: z.ZodDefault<z.ZodString>;
|
|
61
|
+
SEED_ADMIN_EMAIL: z.ZodDefault<z.ZodString>;
|
|
62
|
+
SEED_ADMIN_PASSWORD: z.ZodDefault<z.ZodString>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export type Env = z.infer<typeof envSchema>;
|
|
65
|
+
export declare function validateEnv(config: Record<string, unknown>): Env;
|