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,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var MailerService_1;
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.MailerService = void 0;
|
|
47
|
+
const common_1 = require("@nestjs/common");
|
|
48
|
+
const nodemailer = __importStar(require("nodemailer"));
|
|
49
|
+
const env_service_1 = require("../config/env.service");
|
|
50
|
+
let MailerService = MailerService_1 = class MailerService {
|
|
51
|
+
constructor(env) {
|
|
52
|
+
this.env = env;
|
|
53
|
+
this.logger = new common_1.Logger(MailerService_1.name);
|
|
54
|
+
this.transporter = nodemailer.createTransport({
|
|
55
|
+
host: this.env.get("EMAIL_HOST"),
|
|
56
|
+
port: this.env.get("EMAIL_PORT"),
|
|
57
|
+
secure: this.env.get("EMAIL_SECURE"),
|
|
58
|
+
auth: {
|
|
59
|
+
user: this.env.get("EMAIL_USER"),
|
|
60
|
+
pass: this.env.get("EMAIL_PASSWORD"),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async send(to, subject, html) {
|
|
65
|
+
const from = `"${this.env.get("EMAIL_FROM_NAME")}" <${this.env.get("EMAIL_FROM")}>`;
|
|
66
|
+
try {
|
|
67
|
+
await this.transporter.sendMail({ from, to, subject, html });
|
|
68
|
+
this.logger.log(`Email enviado: ${subject} -> ${to}`);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
this.logger.error(`Falha ao enviar email para ${to}`, error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
escapeHtml(value) {
|
|
76
|
+
return value
|
|
77
|
+
.replace(/&/g, "&")
|
|
78
|
+
.replace(/</g, "<")
|
|
79
|
+
.replace(/>/g, ">")
|
|
80
|
+
.replace(/"/g, """)
|
|
81
|
+
.replace(/'/g, "'");
|
|
82
|
+
}
|
|
83
|
+
layout(title, body) {
|
|
84
|
+
return `
|
|
85
|
+
<div style="font-family: Arial, sans-serif; padding: 20px; max-width: 600px; margin: 0 auto;">
|
|
86
|
+
<h2 style="color: #333;">${title}</h2>
|
|
87
|
+
${body}
|
|
88
|
+
<hr style="border: none; border-top: 1px solid #ddd; margin: 30px 0;">
|
|
89
|
+
<p style="color: #999; font-size: 12px;">Mensagem automática, não responda.</p>
|
|
90
|
+
</div>`;
|
|
91
|
+
}
|
|
92
|
+
async sendTwoFactorCode(to, code, userName) {
|
|
93
|
+
const expiry = this.env.get("TWO_FACTOR_EMAIL_CODE_EXPIRY");
|
|
94
|
+
const body = `
|
|
95
|
+
<p>Olá ${this.escapeHtml(userName)},</p>
|
|
96
|
+
<p>Seu código de verificação (2FA) é:</p>
|
|
97
|
+
<div style="text-align:center;margin:30px 0;">
|
|
98
|
+
<div style="background:#f5f5f5;padding:20px;border-radius:5px;display:inline-block;">
|
|
99
|
+
<h1 style="margin:0;font-size:36px;letter-spacing:8px;color:#007bff;">${code}</h1>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
<p><strong>Este código expira em ${expiry} minutos.</strong></p>
|
|
103
|
+
<p>Se você não tentou fazer login, proteja sua conta imediatamente.</p>`;
|
|
104
|
+
await this.send(to, "Seu código de verificação (2FA)", this.layout("Autenticação em duas etapas", body));
|
|
105
|
+
}
|
|
106
|
+
async sendPasswordReset(to, token, userName) {
|
|
107
|
+
const url = `${this.env.get("APP_URL")}/reset-password?token=${token}`;
|
|
108
|
+
const expiry = this.env.get("PASSWORD_RESET_TOKEN_EXPIRY");
|
|
109
|
+
const body = `
|
|
110
|
+
<p>Olá ${this.escapeHtml(userName)},</p>
|
|
111
|
+
<p>Recebemos uma solicitação para redefinir sua senha. Clique no botão abaixo:</p>
|
|
112
|
+
<div style="text-align:center;margin:30px 0;">
|
|
113
|
+
<a href="${url}" style="background:#007bff;color:#fff;padding:12px 30px;text-decoration:none;border-radius:5px;display:inline-block;">Redefinir senha</a>
|
|
114
|
+
</div>
|
|
115
|
+
<p>Ou copie e cole este link no navegador:</p>
|
|
116
|
+
<p style="word-break:break-all;color:#666;">${url}</p>
|
|
117
|
+
<p><strong>Este link expira em ${expiry} minutos.</strong></p>
|
|
118
|
+
<p>Se você não solicitou, ignore este email.</p>`;
|
|
119
|
+
await this.send(to, "Redefinição de senha", this.layout("Redefinição de senha", body));
|
|
120
|
+
}
|
|
121
|
+
formatExpiry(minutes) {
|
|
122
|
+
if (minutes < 60) {
|
|
123
|
+
return `${minutes} minutos`;
|
|
124
|
+
}
|
|
125
|
+
const hours = Math.round(minutes / 60);
|
|
126
|
+
return hours === 1 ? "1 hora" : `${hours} horas`;
|
|
127
|
+
}
|
|
128
|
+
async sendFirstAccess(to, token, userName) {
|
|
129
|
+
const url = `${this.env.get("APP_URL")}/reset-password?token=${token}`;
|
|
130
|
+
const expiry = this.formatExpiry(this.env.get("FIRST_ACCESS_TOKEN_EXPIRY"));
|
|
131
|
+
const body = `
|
|
132
|
+
<p>Olá ${this.escapeHtml(userName)},</p>
|
|
133
|
+
<p>Sua conta foi criada. Para acessar o sistema, defina sua senha clicando no botão abaixo:</p>
|
|
134
|
+
<div style="text-align:center;margin:30px 0;">
|
|
135
|
+
<a href="${url}" style="background:#007bff;color:#fff;padding:12px 30px;text-decoration:none;border-radius:5px;display:inline-block;">Definir minha senha</a>
|
|
136
|
+
</div>
|
|
137
|
+
<p>Ou copie e cole este link no navegador:</p>
|
|
138
|
+
<p style="word-break:break-all;color:#666;">${url}</p>
|
|
139
|
+
<p><strong>Este link expira em ${expiry}.</strong></p>
|
|
140
|
+
<p>No primeiro login você também precisará configurar a autenticação em duas etapas (2FA).</p>`;
|
|
141
|
+
await this.send(to, "Defina sua senha de primeiro acesso", this.layout("Primeiro acesso", body));
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
exports.MailerService = MailerService;
|
|
145
|
+
exports.MailerService = MailerService = MailerService_1 = __decorate([
|
|
146
|
+
(0, common_1.Injectable)(),
|
|
147
|
+
__metadata("design:paramtypes", [env_service_1.EnvService])
|
|
148
|
+
], MailerService);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@nestjs/core");
|
|
4
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const app_module_1 = require("../../app.module");
|
|
8
|
+
async function exportOpenapi() {
|
|
9
|
+
const app = await core_1.NestFactory.create(app_module_1.AppModule, { logger: false });
|
|
10
|
+
const config = new swagger_1.DocumentBuilder()
|
|
11
|
+
.setTitle("Core API")
|
|
12
|
+
.setDescription("Auth + 2FA obrigatório (TOTP) + RBAC + auditoria")
|
|
13
|
+
.setVersion("1.0")
|
|
14
|
+
.addBearerAuth()
|
|
15
|
+
.addCookieAuth("access_token")
|
|
16
|
+
.build();
|
|
17
|
+
const document = swagger_1.SwaggerModule.createDocument(app, config);
|
|
18
|
+
const target = (0, path_1.join)(process.cwd(), "..", "..", "openapi.json");
|
|
19
|
+
(0, fs_1.writeFileSync)(target, `${JSON.stringify(document, null, 2)}\n`);
|
|
20
|
+
await app.close();
|
|
21
|
+
const paths = Object.keys(document.paths).length;
|
|
22
|
+
const schemas = Object.keys(document.components?.schemas ?? {}).length;
|
|
23
|
+
console.log(`openapi.json gerado: ${paths} rotas, ${schemas} schemas`);
|
|
24
|
+
}
|
|
25
|
+
void exportOpenapi();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ObjectLiteral, SelectQueryBuilder } from "typeorm";
|
|
2
|
+
import { FilterGroup, FilterNode } from "./filterField.interface";
|
|
3
|
+
import { FilterOperator } from "./filterOperator.enum";
|
|
4
|
+
export interface FilterSql {
|
|
5
|
+
sql: string;
|
|
6
|
+
params: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare const isFilterGroup: (node: FilterNode) => node is FilterGroup;
|
|
9
|
+
export declare const escapeLike: (value: string) => string;
|
|
10
|
+
export declare const buildOperatorSql: (column: string, operator: FilterOperator, value: unknown, param: string) => FilterSql;
|
|
11
|
+
export declare const applyFilter: <T extends ObjectLiteral>(qb: SelectQueryBuilder<T>, node: FilterNode | null) => SelectQueryBuilder<T>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyFilter = exports.buildOperatorSql = exports.escapeLike = exports.isFilterGroup = void 0;
|
|
4
|
+
const filterOperator_enum_1 = require("./filterOperator.enum");
|
|
5
|
+
const isFilterGroup = (node) => "combinator" in node;
|
|
6
|
+
exports.isFilterGroup = isFilterGroup;
|
|
7
|
+
const escapeLike = (value) => value.replace(/[\\%_]/g, (char) => `\\${char}`);
|
|
8
|
+
exports.escapeLike = escapeLike;
|
|
9
|
+
const buildOperatorSql = (column, operator, value, param) => {
|
|
10
|
+
const one = (sql, bound = value) => ({
|
|
11
|
+
sql,
|
|
12
|
+
params: { [param]: bound },
|
|
13
|
+
});
|
|
14
|
+
switch (operator) {
|
|
15
|
+
case filterOperator_enum_1.FilterOperator.Eq:
|
|
16
|
+
return one(`${column} = :${param}`);
|
|
17
|
+
case filterOperator_enum_1.FilterOperator.Ne:
|
|
18
|
+
return one(`${column} <> :${param}`);
|
|
19
|
+
case filterOperator_enum_1.FilterOperator.Is:
|
|
20
|
+
return { sql: `${column} IS ${nullabilityOperand(value)}`, params: {} };
|
|
21
|
+
case filterOperator_enum_1.FilterOperator.Not:
|
|
22
|
+
return {
|
|
23
|
+
sql: `${column} IS NOT ${nullabilityOperand(value)}`,
|
|
24
|
+
params: {},
|
|
25
|
+
};
|
|
26
|
+
case filterOperator_enum_1.FilterOperator.Gt:
|
|
27
|
+
return one(`${column} > :${param}`);
|
|
28
|
+
case filterOperator_enum_1.FilterOperator.Gte:
|
|
29
|
+
return one(`${column} >= :${param}`);
|
|
30
|
+
case filterOperator_enum_1.FilterOperator.Lt:
|
|
31
|
+
return one(`${column} < :${param}`);
|
|
32
|
+
case filterOperator_enum_1.FilterOperator.Lte:
|
|
33
|
+
return one(`${column} <= :${param}`);
|
|
34
|
+
case filterOperator_enum_1.FilterOperator.Between:
|
|
35
|
+
case filterOperator_enum_1.FilterOperator.NotBetween: {
|
|
36
|
+
const [from, to] = value;
|
|
37
|
+
const negation = operator === filterOperator_enum_1.FilterOperator.NotBetween ? "NOT " : "";
|
|
38
|
+
return {
|
|
39
|
+
sql: `${column} ${negation}BETWEEN :${param}_from AND :${param}_to`,
|
|
40
|
+
params: { [`${param}_from`]: from, [`${param}_to`]: to },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
case filterOperator_enum_1.FilterOperator.In:
|
|
44
|
+
return one(`${column} IN (:...${param})`);
|
|
45
|
+
case filterOperator_enum_1.FilterOperator.NotIn:
|
|
46
|
+
return one(`${column} NOT IN (:...${param})`);
|
|
47
|
+
case filterOperator_enum_1.FilterOperator.Like:
|
|
48
|
+
return one(`${column} LIKE :${param}`);
|
|
49
|
+
case filterOperator_enum_1.FilterOperator.NotLike:
|
|
50
|
+
return one(`${column} NOT LIKE :${param}`);
|
|
51
|
+
case filterOperator_enum_1.FilterOperator.StartsWith:
|
|
52
|
+
return one(`${column} LIKE :${param}`, `${(0, exports.escapeLike)(String(value))}%`);
|
|
53
|
+
case filterOperator_enum_1.FilterOperator.EndsWith:
|
|
54
|
+
return one(`${column} LIKE :${param}`, `%${(0, exports.escapeLike)(String(value))}`);
|
|
55
|
+
case filterOperator_enum_1.FilterOperator.Substring:
|
|
56
|
+
return one(`${column} LIKE :${param}`, `%${(0, exports.escapeLike)(String(value))}%`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.buildOperatorSql = buildOperatorSql;
|
|
60
|
+
const nullabilityOperand = (value) => {
|
|
61
|
+
if (value === null) {
|
|
62
|
+
return "NULL";
|
|
63
|
+
}
|
|
64
|
+
return value === true ? "TRUE" : "FALSE";
|
|
65
|
+
};
|
|
66
|
+
const applyFilter = (qb, node) => {
|
|
67
|
+
if (!node) {
|
|
68
|
+
return qb;
|
|
69
|
+
}
|
|
70
|
+
const context = { qb, alias: qb.alias, index: 0 };
|
|
71
|
+
const { sql, params } = buildNodeSql(node, context);
|
|
72
|
+
return qb.andWhere(sql, params);
|
|
73
|
+
};
|
|
74
|
+
exports.applyFilter = applyFilter;
|
|
75
|
+
const buildNodeSql = (node, context) => {
|
|
76
|
+
if ((0, exports.isFilterGroup)(node)) {
|
|
77
|
+
const parts = node.nodes.map((child) => buildNodeSql(child, context));
|
|
78
|
+
const glue = node.combinator === filterOperator_enum_1.FilterCombinator.Or ? " OR " : " AND ";
|
|
79
|
+
return {
|
|
80
|
+
sql: `(${parts.map((part) => part.sql).join(glue)})`,
|
|
81
|
+
params: Object.assign({}, ...parts.map((part) => part.params)),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return buildConditionSql(node, context);
|
|
85
|
+
};
|
|
86
|
+
const buildConditionSql = (condition, context) => {
|
|
87
|
+
const param = `f${context.index++}`;
|
|
88
|
+
const { relation } = condition.field;
|
|
89
|
+
if (relation?.kind === "toMany") {
|
|
90
|
+
return buildExistsSql(condition, context, param);
|
|
91
|
+
}
|
|
92
|
+
const alias = relation ? relation.alias : context.alias;
|
|
93
|
+
if (relation) {
|
|
94
|
+
ensureJoin(context, relation.property, relation.alias);
|
|
95
|
+
}
|
|
96
|
+
return (0, exports.buildOperatorSql)(`${alias}.${condition.field.column}`, condition.operator, condition.value, param);
|
|
97
|
+
};
|
|
98
|
+
const ensureJoin = (context, property, alias) => {
|
|
99
|
+
const joined = context.qb.expressionMap.joinAttributes.some((join) => join.alias.name === alias);
|
|
100
|
+
if (!joined) {
|
|
101
|
+
context.qb.leftJoin(`${context.alias}.${property}`, alias);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const buildExistsSql = (condition, context, param) => {
|
|
105
|
+
const relation = condition.field.relation;
|
|
106
|
+
const metadata = context.qb.expressionMap.mainAlias?.metadata;
|
|
107
|
+
if (!relation || !metadata) {
|
|
108
|
+
throw new Error("applyFilter: relação to-many sem metadata da entidade raiz");
|
|
109
|
+
}
|
|
110
|
+
const primaryKey = metadata.primaryColumns[0].propertyName;
|
|
111
|
+
const rootAlias = `${relation.alias}_root_${param}`;
|
|
112
|
+
const joinAlias = `${relation.alias}_${param}`;
|
|
113
|
+
const inner = (0, exports.buildOperatorSql)(`${joinAlias}.${condition.field.column}`, condition.operator, condition.value, param);
|
|
114
|
+
const subQuery = context.qb.connection
|
|
115
|
+
.createQueryBuilder()
|
|
116
|
+
.select("1")
|
|
117
|
+
.from(metadata.target, rootAlias)
|
|
118
|
+
.innerJoin(`${rootAlias}.${relation.property}`, joinAlias)
|
|
119
|
+
.where(`${rootAlias}.${primaryKey} = ${context.alias}.${primaryKey}`)
|
|
120
|
+
.andWhere(inner.sql);
|
|
121
|
+
return { sql: `EXISTS (${subQuery.getQuery()})`, params: inner.params };
|
|
122
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FilterFieldType } from "./filterFieldType.enum";
|
|
2
|
+
import { FilterOperator } from "./filterOperator.enum";
|
|
3
|
+
export declare const FILTER_MAX_LENGTH = 4000;
|
|
4
|
+
export declare const FILTER_MAX_DEPTH = 3;
|
|
5
|
+
export declare const FILTER_MAX_NODES = 50;
|
|
6
|
+
export declare const FILTER_MAX_IN_ITEMS = 100;
|
|
7
|
+
export declare const DEFAULT_OPERATORS: Readonly<Record<FilterFieldType, readonly FilterOperator[]>>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_OPERATORS = exports.FILTER_MAX_IN_ITEMS = exports.FILTER_MAX_NODES = exports.FILTER_MAX_DEPTH = exports.FILTER_MAX_LENGTH = void 0;
|
|
4
|
+
const filterFieldType_enum_1 = require("./filterFieldType.enum");
|
|
5
|
+
const filterOperator_enum_1 = require("./filterOperator.enum");
|
|
6
|
+
exports.FILTER_MAX_LENGTH = 4000;
|
|
7
|
+
exports.FILTER_MAX_DEPTH = 3;
|
|
8
|
+
exports.FILTER_MAX_NODES = 50;
|
|
9
|
+
exports.FILTER_MAX_IN_ITEMS = 100;
|
|
10
|
+
const ORDERING_OPERATORS = [
|
|
11
|
+
filterOperator_enum_1.FilterOperator.Gt,
|
|
12
|
+
filterOperator_enum_1.FilterOperator.Gte,
|
|
13
|
+
filterOperator_enum_1.FilterOperator.Lt,
|
|
14
|
+
filterOperator_enum_1.FilterOperator.Lte,
|
|
15
|
+
filterOperator_enum_1.FilterOperator.Between,
|
|
16
|
+
filterOperator_enum_1.FilterOperator.NotBetween,
|
|
17
|
+
];
|
|
18
|
+
const NULLABILITY = [filterOperator_enum_1.FilterOperator.Is, filterOperator_enum_1.FilterOperator.Not];
|
|
19
|
+
exports.DEFAULT_OPERATORS = {
|
|
20
|
+
[filterFieldType_enum_1.FilterFieldType.Text]: [
|
|
21
|
+
filterOperator_enum_1.FilterOperator.Substring,
|
|
22
|
+
filterOperator_enum_1.FilterOperator.StartsWith,
|
|
23
|
+
filterOperator_enum_1.FilterOperator.EndsWith,
|
|
24
|
+
filterOperator_enum_1.FilterOperator.Like,
|
|
25
|
+
filterOperator_enum_1.FilterOperator.NotLike,
|
|
26
|
+
filterOperator_enum_1.FilterOperator.Eq,
|
|
27
|
+
filterOperator_enum_1.FilterOperator.Ne,
|
|
28
|
+
filterOperator_enum_1.FilterOperator.In,
|
|
29
|
+
filterOperator_enum_1.FilterOperator.NotIn,
|
|
30
|
+
...NULLABILITY,
|
|
31
|
+
],
|
|
32
|
+
[filterFieldType_enum_1.FilterFieldType.Number]: [
|
|
33
|
+
filterOperator_enum_1.FilterOperator.Eq,
|
|
34
|
+
filterOperator_enum_1.FilterOperator.Ne,
|
|
35
|
+
...ORDERING_OPERATORS,
|
|
36
|
+
filterOperator_enum_1.FilterOperator.In,
|
|
37
|
+
filterOperator_enum_1.FilterOperator.NotIn,
|
|
38
|
+
...NULLABILITY,
|
|
39
|
+
],
|
|
40
|
+
[filterFieldType_enum_1.FilterFieldType.Date]: [...ORDERING_OPERATORS, ...NULLABILITY],
|
|
41
|
+
[filterFieldType_enum_1.FilterFieldType.DateTime]: [...ORDERING_OPERATORS, ...NULLABILITY],
|
|
42
|
+
[filterFieldType_enum_1.FilterFieldType.Boolean]: [filterOperator_enum_1.FilterOperator.Eq, ...NULLABILITY],
|
|
43
|
+
[filterFieldType_enum_1.FilterFieldType.Enum]: [
|
|
44
|
+
filterOperator_enum_1.FilterOperator.In,
|
|
45
|
+
filterOperator_enum_1.FilterOperator.NotIn,
|
|
46
|
+
filterOperator_enum_1.FilterOperator.Eq,
|
|
47
|
+
filterOperator_enum_1.FilterOperator.Ne,
|
|
48
|
+
...NULLABILITY,
|
|
49
|
+
],
|
|
50
|
+
[filterFieldType_enum_1.FilterFieldType.Select]: [
|
|
51
|
+
filterOperator_enum_1.FilterOperator.In,
|
|
52
|
+
filterOperator_enum_1.FilterOperator.NotIn,
|
|
53
|
+
filterOperator_enum_1.FilterOperator.Eq,
|
|
54
|
+
filterOperator_enum_1.FilterOperator.Ne,
|
|
55
|
+
...NULLABILITY,
|
|
56
|
+
],
|
|
57
|
+
[filterFieldType_enum_1.FilterFieldType.Uuid]: [
|
|
58
|
+
filterOperator_enum_1.FilterOperator.Eq,
|
|
59
|
+
filterOperator_enum_1.FilterOperator.Ne,
|
|
60
|
+
filterOperator_enum_1.FilterOperator.In,
|
|
61
|
+
filterOperator_enum_1.FilterOperator.NotIn,
|
|
62
|
+
...NULLABILITY,
|
|
63
|
+
],
|
|
64
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FilterFieldType } from "./filterFieldType.enum";
|
|
2
|
+
import { FilterCombinator, FilterOperator } from "./filterOperator.enum";
|
|
3
|
+
export interface FilterOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FilterRelation {
|
|
8
|
+
property: string;
|
|
9
|
+
alias: string;
|
|
10
|
+
kind: "toOne" | "toMany";
|
|
11
|
+
}
|
|
12
|
+
export interface FilterFieldDefinition {
|
|
13
|
+
field: string;
|
|
14
|
+
column: string;
|
|
15
|
+
label: string;
|
|
16
|
+
type: FilterFieldType;
|
|
17
|
+
operators?: FilterOperator[];
|
|
18
|
+
options?: FilterOption[];
|
|
19
|
+
optionsUrl?: string;
|
|
20
|
+
relation?: FilterRelation;
|
|
21
|
+
permission?: string;
|
|
22
|
+
sortable?: boolean;
|
|
23
|
+
filterable?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type FilterCatalog = readonly FilterFieldDefinition[];
|
|
26
|
+
export interface FilterCondition {
|
|
27
|
+
field: FilterFieldDefinition;
|
|
28
|
+
operator: FilterOperator;
|
|
29
|
+
value: unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface FilterGroup {
|
|
32
|
+
combinator: FilterCombinator;
|
|
33
|
+
nodes: FilterNode[];
|
|
34
|
+
}
|
|
35
|
+
export type FilterNode = FilterCondition | FilterGroup;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterFieldType = void 0;
|
|
4
|
+
var FilterFieldType;
|
|
5
|
+
(function (FilterFieldType) {
|
|
6
|
+
FilterFieldType["Text"] = "TEXT";
|
|
7
|
+
FilterFieldType["Number"] = "NUMBER";
|
|
8
|
+
FilterFieldType["Date"] = "DATE";
|
|
9
|
+
FilterFieldType["DateTime"] = "DATETIME";
|
|
10
|
+
FilterFieldType["Boolean"] = "BOOLEAN";
|
|
11
|
+
FilterFieldType["Enum"] = "ENUM";
|
|
12
|
+
FilterFieldType["Select"] = "SELECT";
|
|
13
|
+
FilterFieldType["Uuid"] = "UUID";
|
|
14
|
+
})(FilterFieldType || (exports.FilterFieldType = FilterFieldType = {}));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare enum FilterOperator {
|
|
2
|
+
Eq = "$EQ",
|
|
3
|
+
Ne = "$NE",
|
|
4
|
+
Is = "$IS",
|
|
5
|
+
Not = "$NOT",
|
|
6
|
+
Gt = "$GT",
|
|
7
|
+
Gte = "$GTE",
|
|
8
|
+
Lt = "$LT",
|
|
9
|
+
Lte = "$LTE",
|
|
10
|
+
Between = "$BETWEEN",
|
|
11
|
+
NotBetween = "$NOTBETWEEN",
|
|
12
|
+
In = "$IN",
|
|
13
|
+
NotIn = "$NOTIN",
|
|
14
|
+
Like = "$LIKE",
|
|
15
|
+
NotLike = "$NOTLIKE",
|
|
16
|
+
StartsWith = "$STARTSWITH",
|
|
17
|
+
EndsWith = "$ENDSWITH",
|
|
18
|
+
Substring = "$SUBSTRING"
|
|
19
|
+
}
|
|
20
|
+
export declare enum FilterCombinator {
|
|
21
|
+
And = "$AND",
|
|
22
|
+
Or = "$OR"
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterCombinator = exports.FilterOperator = void 0;
|
|
4
|
+
var FilterOperator;
|
|
5
|
+
(function (FilterOperator) {
|
|
6
|
+
FilterOperator["Eq"] = "$EQ";
|
|
7
|
+
FilterOperator["Ne"] = "$NE";
|
|
8
|
+
FilterOperator["Is"] = "$IS";
|
|
9
|
+
FilterOperator["Not"] = "$NOT";
|
|
10
|
+
FilterOperator["Gt"] = "$GT";
|
|
11
|
+
FilterOperator["Gte"] = "$GTE";
|
|
12
|
+
FilterOperator["Lt"] = "$LT";
|
|
13
|
+
FilterOperator["Lte"] = "$LTE";
|
|
14
|
+
FilterOperator["Between"] = "$BETWEEN";
|
|
15
|
+
FilterOperator["NotBetween"] = "$NOTBETWEEN";
|
|
16
|
+
FilterOperator["In"] = "$IN";
|
|
17
|
+
FilterOperator["NotIn"] = "$NOTIN";
|
|
18
|
+
FilterOperator["Like"] = "$LIKE";
|
|
19
|
+
FilterOperator["NotLike"] = "$NOTLIKE";
|
|
20
|
+
FilterOperator["StartsWith"] = "$STARTSWITH";
|
|
21
|
+
FilterOperator["EndsWith"] = "$ENDSWITH";
|
|
22
|
+
FilterOperator["Substring"] = "$SUBSTRING";
|
|
23
|
+
})(FilterOperator || (exports.FilterOperator = FilterOperator = {}));
|
|
24
|
+
var FilterCombinator;
|
|
25
|
+
(function (FilterCombinator) {
|
|
26
|
+
FilterCombinator["And"] = "$AND";
|
|
27
|
+
FilterCombinator["Or"] = "$OR";
|
|
28
|
+
})(FilterCombinator || (exports.FilterCombinator = FilterCombinator = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FilterCatalog, FilterOption } from "./filterField.interface";
|
|
2
|
+
import { FilterFieldType } from "./filterFieldType.enum";
|
|
3
|
+
import { FilterOperator } from "./filterOperator.enum";
|
|
4
|
+
export declare class FilterOptionResponse implements FilterOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class FilterFieldResponse {
|
|
9
|
+
field: string;
|
|
10
|
+
label: string;
|
|
11
|
+
type: FilterFieldType;
|
|
12
|
+
operators: FilterOperator[];
|
|
13
|
+
options?: FilterOptionResponse[];
|
|
14
|
+
optionsUrl?: string;
|
|
15
|
+
sortable: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const toFilterSchema: (catalog: FilterCatalog, permissions?: string[]) => FilterFieldResponse[];
|
|
@@ -0,0 +1,82 @@
|
|
|
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.toFilterSchema = exports.FilterFieldResponse = exports.FilterOptionResponse = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const filter_constants_1 = require("./filter.constants");
|
|
15
|
+
const filterFieldType_enum_1 = require("./filterFieldType.enum");
|
|
16
|
+
const filterOperator_enum_1 = require("./filterOperator.enum");
|
|
17
|
+
class FilterOptionResponse {
|
|
18
|
+
}
|
|
19
|
+
exports.FilterOptionResponse = FilterOptionResponse;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, swagger_1.ApiProperty)(),
|
|
22
|
+
__metadata("design:type", String)
|
|
23
|
+
], FilterOptionResponse.prototype, "value", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, swagger_1.ApiProperty)(),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], FilterOptionResponse.prototype, "label", void 0);
|
|
28
|
+
class FilterFieldResponse {
|
|
29
|
+
}
|
|
30
|
+
exports.FilterFieldResponse = FilterFieldResponse;
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, swagger_1.ApiProperty)(),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], FilterFieldResponse.prototype, "field", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, swagger_1.ApiProperty)(),
|
|
37
|
+
__metadata("design:type", String)
|
|
38
|
+
], FilterFieldResponse.prototype, "label", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, swagger_1.ApiProperty)({ enum: filterFieldType_enum_1.FilterFieldType, enumName: "FilterFieldType" }),
|
|
41
|
+
__metadata("design:type", String)
|
|
42
|
+
], FilterFieldResponse.prototype, "type", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, swagger_1.ApiProperty)({
|
|
45
|
+
enum: filterOperator_enum_1.FilterOperator,
|
|
46
|
+
enumName: "FilterOperator",
|
|
47
|
+
isArray: true,
|
|
48
|
+
}),
|
|
49
|
+
__metadata("design:type", Array)
|
|
50
|
+
], FilterFieldResponse.prototype, "operators", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, swagger_1.ApiProperty)({ type: FilterOptionResponse, isArray: true, required: false }),
|
|
53
|
+
__metadata("design:type", Array)
|
|
54
|
+
], FilterFieldResponse.prototype, "options", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, swagger_1.ApiProperty)({
|
|
57
|
+
required: false,
|
|
58
|
+
description: "Endpoint que lista as opções de um campo SELECT",
|
|
59
|
+
}),
|
|
60
|
+
__metadata("design:type", String)
|
|
61
|
+
], FilterFieldResponse.prototype, "optionsUrl", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, swagger_1.ApiProperty)(),
|
|
64
|
+
__metadata("design:type", Boolean)
|
|
65
|
+
], FilterFieldResponse.prototype, "sortable", void 0);
|
|
66
|
+
const toFilterSchema = (catalog, permissions) => catalog
|
|
67
|
+
.filter((field) => field.filterable !== false &&
|
|
68
|
+
(!field.permission || (permissions ?? []).includes(field.permission)))
|
|
69
|
+
.map((field) => ({
|
|
70
|
+
field: field.field,
|
|
71
|
+
label: field.label,
|
|
72
|
+
type: field.type,
|
|
73
|
+
operators: [
|
|
74
|
+
...(field.operators?.length
|
|
75
|
+
? field.operators
|
|
76
|
+
: filter_constants_1.DEFAULT_OPERATORS[field.type]),
|
|
77
|
+
],
|
|
78
|
+
options: field.options,
|
|
79
|
+
optionsUrl: field.optionsUrl,
|
|
80
|
+
sortable: field.sortable ?? false,
|
|
81
|
+
}));
|
|
82
|
+
exports.toFilterSchema = toFilterSchema;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FilterCatalog } from "./filterField.interface";
|
|
2
|
+
import { SortDir } from "../utils/pagination.util";
|
|
3
|
+
export interface CatalogOrder {
|
|
4
|
+
column: string;
|
|
5
|
+
direction: SortDir;
|
|
6
|
+
}
|
|
7
|
+
export declare const resolveCatalogOrder: (sortBy: string | undefined, sortDir: SortDir | undefined, catalog: FilterCatalog, alias: string, fallback: string) => CatalogOrder;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveCatalogOrder = void 0;
|
|
4
|
+
const resolveCatalogOrder = (sortBy, sortDir, catalog, alias, fallback) => {
|
|
5
|
+
const chosen = catalog.find((field) => field.field === sortBy && field.sortable && !field.relation);
|
|
6
|
+
const column = chosen?.column ??
|
|
7
|
+
catalog.find((field) => field.field === fallback)?.column ??
|
|
8
|
+
fallback;
|
|
9
|
+
return { column: `${alias}.${column}`, direction: sortDir ?? "DESC" };
|
|
10
|
+
};
|
|
11
|
+
exports.resolveCatalogOrder = resolveCatalogOrder;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ObjectLiteral, SelectQueryBuilder } from "typeorm";
|
|
2
|
+
import { FilterCatalog } from "./filterField.interface";
|
|
3
|
+
import { PaginationQuery } from "../utils/pagination.util";
|
|
4
|
+
export interface PaginateWithFilterOptions {
|
|
5
|
+
query: PaginationQuery;
|
|
6
|
+
catalog: FilterCatalog;
|
|
7
|
+
defaultSort: string;
|
|
8
|
+
permissions?: string[];
|
|
9
|
+
searchFields?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
export declare const paginateWithFilter: <T extends ObjectLiteral>(qb: SelectQueryBuilder<T>, options: PaginateWithFilterOptions) => Promise<[T[], number]>;
|