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,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paginateWithFilter = void 0;
|
|
4
|
+
const applyFilter_util_1 = require("./applyFilter.util");
|
|
5
|
+
const filterOperator_enum_1 = require("./filterOperator.enum");
|
|
6
|
+
const filterSort_util_1 = require("./filterSort.util");
|
|
7
|
+
const parseFilter_util_1 = require("./parseFilter.util");
|
|
8
|
+
const paginateWithFilter = async (qb, options) => {
|
|
9
|
+
const { query, catalog, defaultSort, permissions, searchFields } = options;
|
|
10
|
+
(0, applyFilter_util_1.applyFilter)(qb, (0, parseFilter_util_1.parseFilter)(query.filter, catalog, permissions));
|
|
11
|
+
applySearch(qb, query.search, catalog, searchFields);
|
|
12
|
+
const order = (0, filterSort_util_1.resolveCatalogOrder)(query.sortBy, query.sortDir, catalog, qb.alias, defaultSort);
|
|
13
|
+
return await qb
|
|
14
|
+
.orderBy(order.column, order.direction)
|
|
15
|
+
.skip((query.page - 1) * query.limit)
|
|
16
|
+
.take(query.limit)
|
|
17
|
+
.getManyAndCount();
|
|
18
|
+
};
|
|
19
|
+
exports.paginateWithFilter = paginateWithFilter;
|
|
20
|
+
const applySearch = (qb, search, catalog, searchFields) => {
|
|
21
|
+
if (!search || !searchFields?.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const parts = searchFields
|
|
25
|
+
.map((name, index) => {
|
|
26
|
+
const definition = catalog.find((item) => item.field === name);
|
|
27
|
+
if (!definition || definition.relation) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return (0, applyFilter_util_1.buildOperatorSql)(`${qb.alias}.${definition.column}`, filterOperator_enum_1.FilterOperator.Substring, search, `s${index}`);
|
|
31
|
+
})
|
|
32
|
+
.filter((part) => part !== null);
|
|
33
|
+
if (parts.length === 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
qb.andWhere(`(${parts.map((part) => part.sql).join(" OR ")})`, Object.assign({}, ...parts.map((part) => part.params)));
|
|
37
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFilter = void 0;
|
|
4
|
+
const appErrorCode_enum_1 = require("../filters/appErrorCode.enum");
|
|
5
|
+
const filter_constants_1 = require("./filter.constants");
|
|
6
|
+
const filterFieldType_enum_1 = require("./filterFieldType.enum");
|
|
7
|
+
const filterOperator_enum_1 = require("./filterOperator.enum");
|
|
8
|
+
const codedError_util_1 = require("../utils/codedError.util");
|
|
9
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10
|
+
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
11
|
+
const NULLABILITY_OPERATORS = [
|
|
12
|
+
filterOperator_enum_1.FilterOperator.Is,
|
|
13
|
+
filterOperator_enum_1.FilterOperator.Not,
|
|
14
|
+
];
|
|
15
|
+
const LIST_OPERATORS = [
|
|
16
|
+
filterOperator_enum_1.FilterOperator.In,
|
|
17
|
+
filterOperator_enum_1.FilterOperator.NotIn,
|
|
18
|
+
];
|
|
19
|
+
const PAIR_OPERATORS = [
|
|
20
|
+
filterOperator_enum_1.FilterOperator.Between,
|
|
21
|
+
filterOperator_enum_1.FilterOperator.NotBetween,
|
|
22
|
+
];
|
|
23
|
+
const TEXT_OPERATORS = [
|
|
24
|
+
filterOperator_enum_1.FilterOperator.Like,
|
|
25
|
+
filterOperator_enum_1.FilterOperator.NotLike,
|
|
26
|
+
filterOperator_enum_1.FilterOperator.StartsWith,
|
|
27
|
+
filterOperator_enum_1.FilterOperator.EndsWith,
|
|
28
|
+
filterOperator_enum_1.FilterOperator.Substring,
|
|
29
|
+
];
|
|
30
|
+
const UPPER_BOUND_OPERATORS = [filterOperator_enum_1.FilterOperator.Lte];
|
|
31
|
+
const OPERATORS = new Set(Object.values(filterOperator_enum_1.FilterOperator));
|
|
32
|
+
const COMBINATORS = new Set(Object.values(filterOperator_enum_1.FilterCombinator));
|
|
33
|
+
const invalid = (message) => (0, codedError_util_1.codedBadRequest)(message, appErrorCode_enum_1.AppErrorCode.INVALID_FILTER);
|
|
34
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35
|
+
const parseFilter = (raw, catalog, permissions) => {
|
|
36
|
+
if (!raw || raw.trim() === "") {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (raw.length > filter_constants_1.FILTER_MAX_LENGTH) {
|
|
40
|
+
throw invalid(`Filtro maior que ${filter_constants_1.FILTER_MAX_LENGTH} caracteres`);
|
|
41
|
+
}
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(raw);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw invalid("Filtro inválido: não é um JSON válido");
|
|
48
|
+
}
|
|
49
|
+
if (!isPlainObject(parsed)) {
|
|
50
|
+
throw invalid("Filtro inválido: esperado um objeto");
|
|
51
|
+
}
|
|
52
|
+
const context = { catalog, permissions, nodes: 0 };
|
|
53
|
+
return parseObject(parsed, context, filterOperator_enum_1.FilterCombinator.And, 0);
|
|
54
|
+
};
|
|
55
|
+
exports.parseFilter = parseFilter;
|
|
56
|
+
const parseObject = (source, context, combinator, depth) => {
|
|
57
|
+
if (depth > filter_constants_1.FILTER_MAX_DEPTH) {
|
|
58
|
+
throw invalid(`Filtro aninhado além de ${filter_constants_1.FILTER_MAX_DEPTH} níveis`);
|
|
59
|
+
}
|
|
60
|
+
const nodes = [];
|
|
61
|
+
for (const [key, value] of Object.entries(source)) {
|
|
62
|
+
if (COMBINATORS.has(key)) {
|
|
63
|
+
nodes.push(parseCombinator(key, value, context, depth));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
nodes.push(parseField(key, value, context, depth));
|
|
67
|
+
}
|
|
68
|
+
if (nodes.length === 0) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return nodes.length === 1 ? nodes[0] : { combinator, nodes };
|
|
72
|
+
};
|
|
73
|
+
const parseCombinator = (combinator, value, context, depth) => {
|
|
74
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
75
|
+
throw invalid(`"${combinator}" espera uma lista de condições`);
|
|
76
|
+
}
|
|
77
|
+
const nodes = value.map((entry) => {
|
|
78
|
+
if (!isPlainObject(entry)) {
|
|
79
|
+
throw invalid(`"${combinator}" espera objetos na lista`);
|
|
80
|
+
}
|
|
81
|
+
const node = parseObject(entry, context, filterOperator_enum_1.FilterCombinator.And, depth + 1);
|
|
82
|
+
if (!node) {
|
|
83
|
+
throw invalid(`"${combinator}" tem uma condição vazia`);
|
|
84
|
+
}
|
|
85
|
+
return node;
|
|
86
|
+
});
|
|
87
|
+
return { combinator, nodes };
|
|
88
|
+
};
|
|
89
|
+
const parseField = (field, value, context, depth) => {
|
|
90
|
+
const definition = context.catalog.find((item) => item.field === field);
|
|
91
|
+
if (!definition ||
|
|
92
|
+
definition.filterable === false ||
|
|
93
|
+
(definition.permission &&
|
|
94
|
+
!context.permissions?.includes(definition.permission))) {
|
|
95
|
+
throw invalid(`Campo "${field}" não é filtrável`);
|
|
96
|
+
}
|
|
97
|
+
const operators = isPlainObject(value)
|
|
98
|
+
? value
|
|
99
|
+
: { [filterOperator_enum_1.FilterOperator.Eq]: value };
|
|
100
|
+
const conditions = Object.entries(operators).map(([operator, operand]) => parseCondition(definition, operator, operand, context));
|
|
101
|
+
if (conditions.length === 0) {
|
|
102
|
+
throw invalid(`Campo "${field}" veio sem operador`);
|
|
103
|
+
}
|
|
104
|
+
if (conditions.length === 1) {
|
|
105
|
+
return conditions[0];
|
|
106
|
+
}
|
|
107
|
+
if (depth >= filter_constants_1.FILTER_MAX_DEPTH) {
|
|
108
|
+
throw invalid(`Filtro aninhado além de ${filter_constants_1.FILTER_MAX_DEPTH} níveis`);
|
|
109
|
+
}
|
|
110
|
+
return { combinator: filterOperator_enum_1.FilterCombinator.And, nodes: conditions };
|
|
111
|
+
};
|
|
112
|
+
const parseCondition = (definition, rawOperator, value, context) => {
|
|
113
|
+
if (!OPERATORS.has(rawOperator)) {
|
|
114
|
+
throw invalid(`Operador "${rawOperator}" não existe`);
|
|
115
|
+
}
|
|
116
|
+
const operator = rawOperator;
|
|
117
|
+
const allowed = definition.operators?.length
|
|
118
|
+
? definition.operators
|
|
119
|
+
: filter_constants_1.DEFAULT_OPERATORS[definition.type];
|
|
120
|
+
if (!allowed.includes(operator)) {
|
|
121
|
+
throw invalid(`Operador "${operator}" não é aceito no campo "${definition.field}"`);
|
|
122
|
+
}
|
|
123
|
+
context.nodes += 1;
|
|
124
|
+
if (context.nodes > filter_constants_1.FILTER_MAX_NODES) {
|
|
125
|
+
throw invalid(`Filtro com mais de ${filter_constants_1.FILTER_MAX_NODES} condições`);
|
|
126
|
+
}
|
|
127
|
+
return { field: definition, operator, value: coerce(definition, operator, value) };
|
|
128
|
+
};
|
|
129
|
+
const coerce = (definition, operator, value) => {
|
|
130
|
+
if (NULLABILITY_OPERATORS.includes(operator)) {
|
|
131
|
+
if (value !== null && typeof value !== "boolean") {
|
|
132
|
+
throw invalid(`"${operator}" em "${definition.field}" espera null, true ou false`);
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
if (LIST_OPERATORS.includes(operator)) {
|
|
137
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
138
|
+
throw invalid(`"${operator}" em "${definition.field}" espera uma lista`);
|
|
139
|
+
}
|
|
140
|
+
if (value.length > filter_constants_1.FILTER_MAX_IN_ITEMS) {
|
|
141
|
+
throw invalid(`"${operator}" em "${definition.field}" aceita no máximo ${filter_constants_1.FILTER_MAX_IN_ITEMS} itens`);
|
|
142
|
+
}
|
|
143
|
+
return value.map((item) => coerceScalar(definition, item));
|
|
144
|
+
}
|
|
145
|
+
if (PAIR_OPERATORS.includes(operator)) {
|
|
146
|
+
if (!Array.isArray(value) || value.length !== 2) {
|
|
147
|
+
throw invalid(`"${operator}" em "${definition.field}" espera exatamente dois valores`);
|
|
148
|
+
}
|
|
149
|
+
return [
|
|
150
|
+
coerceScalar(definition, value[0]),
|
|
151
|
+
coerceScalar(definition, value[1], true),
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
if (TEXT_OPERATORS.includes(operator)) {
|
|
155
|
+
if (typeof value !== "string" || value === "") {
|
|
156
|
+
throw invalid(`"${operator}" em "${definition.field}" espera um texto não vazio`);
|
|
157
|
+
}
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
return coerceScalar(definition, value, UPPER_BOUND_OPERATORS.includes(operator));
|
|
161
|
+
};
|
|
162
|
+
const coerceScalar = (definition, value, upperBound = false) => {
|
|
163
|
+
const { field, type } = definition;
|
|
164
|
+
switch (type) {
|
|
165
|
+
case filterFieldType_enum_1.FilterFieldType.Text:
|
|
166
|
+
if (typeof value !== "string") {
|
|
167
|
+
throw invalid(`"${field}" espera um texto`);
|
|
168
|
+
}
|
|
169
|
+
return value;
|
|
170
|
+
case filterFieldType_enum_1.FilterFieldType.Number: {
|
|
171
|
+
const parsed = typeof value === "string" ? Number(value) : value;
|
|
172
|
+
if (typeof parsed !== "number" || !Number.isFinite(parsed)) {
|
|
173
|
+
throw invalid(`"${field}" espera um número`);
|
|
174
|
+
}
|
|
175
|
+
return parsed;
|
|
176
|
+
}
|
|
177
|
+
case filterFieldType_enum_1.FilterFieldType.Boolean:
|
|
178
|
+
if (typeof value === "boolean") {
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
if (value === "true" || value === "false") {
|
|
182
|
+
return value === "true";
|
|
183
|
+
}
|
|
184
|
+
throw invalid(`"${field}" espera true ou false`);
|
|
185
|
+
case filterFieldType_enum_1.FilterFieldType.Date:
|
|
186
|
+
case filterFieldType_enum_1.FilterFieldType.DateTime: {
|
|
187
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
188
|
+
throw invalid(`"${field}" espera uma data`);
|
|
189
|
+
}
|
|
190
|
+
const date = new Date(value);
|
|
191
|
+
if (Number.isNaN(date.getTime())) {
|
|
192
|
+
throw invalid(`"${field}" espera uma data válida (ISO 8601)`);
|
|
193
|
+
}
|
|
194
|
+
if (upperBound && typeof value === "string" && DATE_ONLY.test(value)) {
|
|
195
|
+
date.setUTCHours(23, 59, 59, 999);
|
|
196
|
+
}
|
|
197
|
+
return date;
|
|
198
|
+
}
|
|
199
|
+
case filterFieldType_enum_1.FilterFieldType.Enum: {
|
|
200
|
+
if (typeof value !== "string") {
|
|
201
|
+
throw invalid(`"${field}" espera um dos valores da lista`);
|
|
202
|
+
}
|
|
203
|
+
const options = definition.options ?? [];
|
|
204
|
+
if (!options.some((option) => option.value === value)) {
|
|
205
|
+
throw invalid(`"${value}" não é um valor válido para "${field}"`);
|
|
206
|
+
}
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
case filterFieldType_enum_1.FilterFieldType.Select:
|
|
210
|
+
if (typeof value !== "string" || value === "") {
|
|
211
|
+
throw invalid(`"${field}" espera um texto não vazio`);
|
|
212
|
+
}
|
|
213
|
+
return value;
|
|
214
|
+
case filterFieldType_enum_1.FilterFieldType.Uuid:
|
|
215
|
+
if (typeof value !== "string" || !UUID_PATTERN.test(value)) {
|
|
216
|
+
throw invalid(`"${field}" espera um UUID`);
|
|
217
|
+
}
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BadRequestException, HttpException, UnauthorizedException } from "@nestjs/common";
|
|
2
|
+
import { AppErrorCode } from "../filters/appErrorCode.enum";
|
|
3
|
+
export declare function codedUnauthorized(message: string, errorCode: AppErrorCode): UnauthorizedException;
|
|
4
|
+
export declare function codedBadRequest(message: string, errorCode: AppErrorCode): BadRequestException;
|
|
5
|
+
export declare function codedTooManyRequests(message: string, errorCode: AppErrorCode): HttpException;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codedUnauthorized = codedUnauthorized;
|
|
4
|
+
exports.codedBadRequest = codedBadRequest;
|
|
5
|
+
exports.codedTooManyRequests = codedTooManyRequests;
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
function codedUnauthorized(message, errorCode) {
|
|
8
|
+
return new common_1.UnauthorizedException({
|
|
9
|
+
message,
|
|
10
|
+
error: "Unauthorized",
|
|
11
|
+
errorCode,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function codedBadRequest(message, errorCode) {
|
|
15
|
+
return new common_1.BadRequestException({
|
|
16
|
+
message,
|
|
17
|
+
error: "Bad Request",
|
|
18
|
+
errorCode,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function codedTooManyRequests(message, errorCode) {
|
|
22
|
+
return new common_1.HttpException({ message, error: "Too Many Requests", errorCode }, common_1.HttpStatus.TOO_MANY_REQUESTS);
|
|
23
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encryptSecret = encryptSecret;
|
|
4
|
+
exports.decryptSecret = decryptSecret;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const logger = new common_1.Logger("CryptoUtil");
|
|
8
|
+
const ALGO = "aes-256-gcm";
|
|
9
|
+
function key() {
|
|
10
|
+
const hex = process.env.TOTP_ENC_KEY ?? "";
|
|
11
|
+
return Buffer.from(hex, "hex");
|
|
12
|
+
}
|
|
13
|
+
function encryptSecret(plain) {
|
|
14
|
+
const iv = (0, crypto_1.randomBytes)(12);
|
|
15
|
+
const cipher = (0, crypto_1.createCipheriv)(ALGO, key(), iv);
|
|
16
|
+
const enc = Buffer.concat([cipher.update(plain, "utf8"), cipher.final()]);
|
|
17
|
+
const tag = cipher.getAuthTag();
|
|
18
|
+
return `${iv.toString("hex")}:${tag.toString("hex")}:${enc.toString("hex")}`;
|
|
19
|
+
}
|
|
20
|
+
function decryptSecret(stored) {
|
|
21
|
+
const parts = stored.split(":");
|
|
22
|
+
if (parts.length !== 3) {
|
|
23
|
+
return stored;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const [ivHex, tagHex, dataHex] = parts;
|
|
27
|
+
const decipher = (0, crypto_1.createDecipheriv)(ALGO, key(), Buffer.from(ivHex, "hex"));
|
|
28
|
+
decipher.setAuthTag(Buffer.from(tagHex, "hex"));
|
|
29
|
+
const dec = Buffer.concat([
|
|
30
|
+
decipher.update(Buffer.from(dataHex, "hex")),
|
|
31
|
+
decipher.final(),
|
|
32
|
+
]);
|
|
33
|
+
return dec.toString("utf8");
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
logger.warn(`Falha ao descriptografar segredo (assumindo legado): ${err.message}`);
|
|
37
|
+
return stored;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function hashPassword(plain: string): Promise<string>;
|
|
2
|
+
export declare function verifyPassword(hash: string, plain: string): Promise<boolean>;
|
|
3
|
+
export declare function sha256(value: string): string;
|
|
4
|
+
export declare function randomToken(bytes?: number): string;
|
|
5
|
+
export declare function numericCode(): string;
|
|
6
|
+
export declare function backupCode(): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.hashPassword = hashPassword;
|
|
37
|
+
exports.verifyPassword = verifyPassword;
|
|
38
|
+
exports.sha256 = sha256;
|
|
39
|
+
exports.randomToken = randomToken;
|
|
40
|
+
exports.numericCode = numericCode;
|
|
41
|
+
exports.backupCode = backupCode;
|
|
42
|
+
const argon2 = __importStar(require("argon2"));
|
|
43
|
+
const crypto_1 = require("crypto");
|
|
44
|
+
async function hashPassword(plain) {
|
|
45
|
+
return argon2.hash(plain, { type: argon2.argon2id });
|
|
46
|
+
}
|
|
47
|
+
async function verifyPassword(hash, plain) {
|
|
48
|
+
try {
|
|
49
|
+
return await argon2.verify(hash, plain);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function sha256(value) {
|
|
56
|
+
return (0, crypto_1.createHash)("sha256").update(value).digest("hex");
|
|
57
|
+
}
|
|
58
|
+
function randomToken(bytes = 48) {
|
|
59
|
+
return (0, crypto_1.randomBytes)(bytes).toString("hex");
|
|
60
|
+
}
|
|
61
|
+
function numericCode() {
|
|
62
|
+
return (0, crypto_1.randomInt)(100000, 1000000).toString();
|
|
63
|
+
}
|
|
64
|
+
function backupCode() {
|
|
65
|
+
const raw = (0, crypto_1.randomBytes)(4).toString("hex").toUpperCase();
|
|
66
|
+
return `${raw.slice(0, 4)}-${raw.slice(4, 8)}`;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeIp(ip: string | undefined): string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeIp = normalizeIp;
|
|
4
|
+
function normalizeIp(ip) {
|
|
5
|
+
if (!ip) {
|
|
6
|
+
return ip;
|
|
7
|
+
}
|
|
8
|
+
if (ip === "::1") {
|
|
9
|
+
return "127.0.0.1";
|
|
10
|
+
}
|
|
11
|
+
if (ip.startsWith("::ffff:")) {
|
|
12
|
+
return ip.slice("::ffff:".length);
|
|
13
|
+
}
|
|
14
|
+
return ip;
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type SortDir = "ASC" | "DESC";
|
|
2
|
+
export declare class PaginationQuery {
|
|
3
|
+
page: number;
|
|
4
|
+
limit: number;
|
|
5
|
+
search?: string;
|
|
6
|
+
sortBy?: string;
|
|
7
|
+
sortDir?: SortDir;
|
|
8
|
+
filter?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveOrder<T extends string>(sortBy: string | undefined, sortDir: SortDir | undefined, allowed: readonly T[], fallback: T): Record<string, SortDir>;
|
|
11
|
+
export interface PaginationMeta {
|
|
12
|
+
total: number;
|
|
13
|
+
page: number;
|
|
14
|
+
limit: number;
|
|
15
|
+
totalPages: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class Paginated<T> {
|
|
18
|
+
items: T[];
|
|
19
|
+
meta: PaginationMeta;
|
|
20
|
+
constructor(items: T[], total: number, page: number, limit: number);
|
|
21
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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.Paginated = exports.PaginationQuery = void 0;
|
|
13
|
+
exports.resolveOrder = resolveOrder;
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const class_transformer_1 = require("class-transformer");
|
|
16
|
+
const class_validator_1 = require("class-validator");
|
|
17
|
+
const filter_constants_1 = require("../query/filter.constants");
|
|
18
|
+
class PaginationQuery {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.page = 1;
|
|
21
|
+
this.limit = 20;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PaginationQuery = PaginationQuery;
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, swagger_1.ApiProperty)({ required: false, default: 1 }),
|
|
27
|
+
(0, class_validator_1.IsOptional)(),
|
|
28
|
+
(0, class_transformer_1.Type)(() => Number),
|
|
29
|
+
(0, class_validator_1.IsInt)(),
|
|
30
|
+
(0, class_validator_1.Min)(1),
|
|
31
|
+
__metadata("design:type", Number)
|
|
32
|
+
], PaginationQuery.prototype, "page", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, swagger_1.ApiProperty)({ required: false, default: 20 }),
|
|
35
|
+
(0, class_validator_1.IsOptional)(),
|
|
36
|
+
(0, class_transformer_1.Type)(() => Number),
|
|
37
|
+
(0, class_validator_1.IsInt)(),
|
|
38
|
+
(0, class_validator_1.Min)(1),
|
|
39
|
+
(0, class_validator_1.Max)(100),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], PaginationQuery.prototype, "limit", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, swagger_1.ApiProperty)({ required: false }),
|
|
44
|
+
(0, class_validator_1.IsOptional)(),
|
|
45
|
+
(0, class_validator_1.IsString)(),
|
|
46
|
+
__metadata("design:type", String)
|
|
47
|
+
], PaginationQuery.prototype, "search", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, swagger_1.ApiProperty)({
|
|
50
|
+
required: false,
|
|
51
|
+
description: "Coluna para ordenar (whitelist por endpoint)",
|
|
52
|
+
}),
|
|
53
|
+
(0, class_validator_1.IsOptional)(),
|
|
54
|
+
(0, class_validator_1.IsString)(),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], PaginationQuery.prototype, "sortBy", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, swagger_1.ApiProperty)({ required: false, enum: ["ASC", "DESC"] }),
|
|
59
|
+
(0, class_validator_1.IsOptional)(),
|
|
60
|
+
(0, class_validator_1.IsIn)(["ASC", "DESC"]),
|
|
61
|
+
__metadata("design:type", String)
|
|
62
|
+
], PaginationQuery.prototype, "sortDir", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, swagger_1.ApiProperty)({
|
|
65
|
+
required: false,
|
|
66
|
+
description: 'JSON, ex.: {"name":{"$SUBSTRING":"ana"}}',
|
|
67
|
+
}),
|
|
68
|
+
(0, class_validator_1.IsOptional)(),
|
|
69
|
+
(0, class_validator_1.IsString)(),
|
|
70
|
+
(0, class_validator_1.MaxLength)(filter_constants_1.FILTER_MAX_LENGTH),
|
|
71
|
+
__metadata("design:type", String)
|
|
72
|
+
], PaginationQuery.prototype, "filter", void 0);
|
|
73
|
+
function resolveOrder(sortBy, sortDir, allowed, fallback) {
|
|
74
|
+
const column = allowed.includes(sortBy ?? "")
|
|
75
|
+
? sortBy
|
|
76
|
+
: fallback;
|
|
77
|
+
return { [column]: sortDir ?? "DESC" };
|
|
78
|
+
}
|
|
79
|
+
class Paginated {
|
|
80
|
+
constructor(items, total, page, limit) {
|
|
81
|
+
this.items = items;
|
|
82
|
+
this.meta = {
|
|
83
|
+
total,
|
|
84
|
+
page,
|
|
85
|
+
limit,
|
|
86
|
+
totalPages: Math.max(1, Math.ceil(total / limit)),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Paginated = Paginated;
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, swagger_1.ApiProperty)({ isArray: true }),
|
|
93
|
+
__metadata("design:type", Array)
|
|
94
|
+
], Paginated.prototype, "items", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, swagger_1.ApiProperty)(),
|
|
97
|
+
__metadata("design:type", Object)
|
|
98
|
+
], Paginated.prototype, "meta", void 0);
|
|
@@ -0,0 +1,32 @@
|
|
|
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.PaginationMetaResponse = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
class PaginationMetaResponse {
|
|
15
|
+
}
|
|
16
|
+
exports.PaginationMetaResponse = PaginationMetaResponse;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, swagger_1.ApiProperty)({ example: 42 }),
|
|
19
|
+
__metadata("design:type", Number)
|
|
20
|
+
], PaginationMetaResponse.prototype, "total", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, swagger_1.ApiProperty)({ example: 1 }),
|
|
23
|
+
__metadata("design:type", Number)
|
|
24
|
+
], PaginationMetaResponse.prototype, "page", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, swagger_1.ApiProperty)({ example: 20 }),
|
|
27
|
+
__metadata("design:type", Number)
|
|
28
|
+
], PaginationMetaResponse.prototype, "limit", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, swagger_1.ApiProperty)({ example: 3 }),
|
|
31
|
+
__metadata("design:type", Number)
|
|
32
|
+
], PaginationMetaResponse.prototype, "totalPages", void 0);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WEAK_PASSWORD_MESSAGE = exports.STRONG_PASSWORD_REGEX = void 0;
|
|
4
|
+
exports.STRONG_PASSWORD_REGEX = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*(),.?":{}|<>]).{8,}$/;
|
|
5
|
+
exports.WEAK_PASSWORD_MESSAGE = "A senha deve ter ao menos 8 caracteres, incluindo maiúscula, minúscula, número e caractere especial";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Logger } from "@nestjs/common";
|
|
2
|
+
import { OnGatewayConnection, OnGatewayDisconnect } from "@nestjs/websockets";
|
|
3
|
+
import { Server, Socket } from "socket.io";
|
|
4
|
+
import { AuthenticatedUser } from "../auth/authenticatedUser.interface";
|
|
5
|
+
import { EnvService } from "../config/env.service";
|
|
6
|
+
import { WsAuthService } from "./wsAuth.service";
|
|
7
|
+
export interface SocketData {
|
|
8
|
+
user: AuthenticatedUser;
|
|
9
|
+
expiryTimer?: NodeJS.Timeout;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class BaseGateway implements OnGatewayConnection, OnGatewayDisconnect {
|
|
12
|
+
protected readonly wsAuth: WsAuthService;
|
|
13
|
+
protected readonly env: EnvService;
|
|
14
|
+
protected abstract server: Server;
|
|
15
|
+
protected readonly logger: Logger;
|
|
16
|
+
constructor(wsAuth: WsAuthService, env: EnvService);
|
|
17
|
+
handleConnection(socket: Socket): Promise<void>;
|
|
18
|
+
handleDisconnect(socket: Socket): void;
|
|
19
|
+
protected emitTo<T>(rooms: string[], event: string, data: T): void;
|
|
20
|
+
private scheduleExpiry;
|
|
21
|
+
}
|