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,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var JwtStrategy_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.JwtStrategy = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const passport_1 = require("@nestjs/passport");
|
|
16
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
17
|
+
const env_service_1 = require("../../../../core/config/env.service");
|
|
18
|
+
const auth_service_1 = require("../../domain/auth.service");
|
|
19
|
+
const users_service_1 = require("../../../users/domain/users.service");
|
|
20
|
+
const cookieExtractor = (req) => {
|
|
21
|
+
const cookies = req?.cookies;
|
|
22
|
+
return cookies?.access_token ?? null;
|
|
23
|
+
};
|
|
24
|
+
let JwtStrategy = JwtStrategy_1 = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, "jwt") {
|
|
25
|
+
constructor(env, users, auth) {
|
|
26
|
+
super({
|
|
27
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromExtractors([
|
|
28
|
+
cookieExtractor,
|
|
29
|
+
passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
30
|
+
]),
|
|
31
|
+
ignoreExpiration: false,
|
|
32
|
+
secretOrKey: env.get("JWT_ACCESS_SECRET"),
|
|
33
|
+
});
|
|
34
|
+
this.env = env;
|
|
35
|
+
this.users = users;
|
|
36
|
+
this.auth = auth;
|
|
37
|
+
this.logger = new common_1.Logger(JwtStrategy_1.name);
|
|
38
|
+
}
|
|
39
|
+
async validate(payload) {
|
|
40
|
+
if (payload.purpose !== "access") {
|
|
41
|
+
throw new common_1.UnauthorizedException("Token inválido para esta operação");
|
|
42
|
+
}
|
|
43
|
+
const user = await this.users.findById(payload.sub).catch((err) => {
|
|
44
|
+
this.logger.warn(`Falha ao buscar usuário autenticado (${payload.sub}): ${err.message}`);
|
|
45
|
+
return null;
|
|
46
|
+
});
|
|
47
|
+
if (!user || !user.isActive) {
|
|
48
|
+
throw new common_1.UnauthorizedException("Usuário inválido ou inativo");
|
|
49
|
+
}
|
|
50
|
+
return this.auth.toSessionUser(user);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.JwtStrategy = JwtStrategy;
|
|
54
|
+
exports.JwtStrategy = JwtStrategy = JwtStrategy_1 = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__metadata("design:paramtypes", [env_service_1.EnvService,
|
|
57
|
+
users_service_1.UsersService,
|
|
58
|
+
auth_service_1.AuthService])
|
|
59
|
+
], JwtStrategy);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TokenModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
12
|
+
const domain_1 = require("./domain");
|
|
13
|
+
const infra_1 = require("./infra");
|
|
14
|
+
let TokenModule = class TokenModule {
|
|
15
|
+
};
|
|
16
|
+
exports.TokenModule = TokenModule;
|
|
17
|
+
exports.TokenModule = TokenModule = __decorate([
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [typeorm_1.TypeOrmModule.forFeature([infra_1.AuthToken])],
|
|
20
|
+
providers: [infra_1.AuthTokenRepository, domain_1.TokenService],
|
|
21
|
+
exports: [infra_1.AuthTokenRepository, domain_1.TokenService],
|
|
22
|
+
})
|
|
23
|
+
], TokenModule);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EventEmitter2 } from "@nestjs/event-emitter";
|
|
2
|
+
import { EnvService } from "../../../core/config/env.service";
|
|
3
|
+
import { AuditService } from "../../audit/domain/audit.service";
|
|
4
|
+
import { TokenService } from "../../auth/domain/token.service";
|
|
5
|
+
import { NotificationsService } from "../../notifications/domain/notifications.service";
|
|
6
|
+
import { UserRepository } from "../../users/infra/repositories/user.repository";
|
|
7
|
+
export declare class CleanupService {
|
|
8
|
+
private readonly tokens;
|
|
9
|
+
private readonly audit;
|
|
10
|
+
private readonly env;
|
|
11
|
+
private readonly notifications;
|
|
12
|
+
private readonly users;
|
|
13
|
+
private readonly events;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
constructor(tokens: TokenService, audit: AuditService, env: EnvService, notifications: NotificationsService, users: UserRepository, events: EventEmitter2);
|
|
16
|
+
handleTokenCleanup(): Promise<void>;
|
|
17
|
+
handleAuditLogCleanup(): Promise<void>;
|
|
18
|
+
handleNotificationCleanup(): Promise<void>;
|
|
19
|
+
handlePasswordExpiryWarning(): Promise<void>;
|
|
20
|
+
private daysUntilExpiry;
|
|
21
|
+
private run;
|
|
22
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var CleanupService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.CleanupService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
16
|
+
const schedule_1 = require("@nestjs/schedule");
|
|
17
|
+
const env_service_1 = require("../../../core/config/env.service");
|
|
18
|
+
const appEvent_enum_1 = require("../../../core/events/appEvent.enum");
|
|
19
|
+
const audit_service_1 = require("../../audit/domain/audit.service");
|
|
20
|
+
const token_service_1 = require("../../auth/domain/token.service");
|
|
21
|
+
const notifications_service_1 = require("../../notifications/domain/notifications.service");
|
|
22
|
+
const user_repository_1 = require("../../users/infra/repositories/user.repository");
|
|
23
|
+
const PASSWORD_WARNING_MILESTONES = [7, 3, 1];
|
|
24
|
+
let CleanupService = CleanupService_1 = class CleanupService {
|
|
25
|
+
constructor(tokens, audit, env, notifications, users, events) {
|
|
26
|
+
this.tokens = tokens;
|
|
27
|
+
this.audit = audit;
|
|
28
|
+
this.env = env;
|
|
29
|
+
this.notifications = notifications;
|
|
30
|
+
this.users = users;
|
|
31
|
+
this.events = events;
|
|
32
|
+
this.logger = new common_1.Logger(CleanupService_1.name);
|
|
33
|
+
}
|
|
34
|
+
async handleTokenCleanup() {
|
|
35
|
+
await this.run("Limpeza de tokens", async () => {
|
|
36
|
+
const removed = await this.tokens.cleanExpired();
|
|
37
|
+
if (removed > 0) {
|
|
38
|
+
this.logger.log(`Tokens expirados removidos: ${removed}`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async handleAuditLogCleanup() {
|
|
43
|
+
await this.run("Limpeza de logs operacionais", async () => {
|
|
44
|
+
const retentionDays = this.env.get("AUDIT_LOG_RETENTION_DAYS");
|
|
45
|
+
const { changes, errors } = await this.audit.cleanupOldLogs(retentionDays);
|
|
46
|
+
if (changes > 0 || errors > 0) {
|
|
47
|
+
this.logger.log(`Logs operacionais removidos (> ${retentionDays}d): ${changes} requisições, ${errors} erros`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async handleNotificationCleanup() {
|
|
52
|
+
await this.run("Limpeza de notificações", async () => {
|
|
53
|
+
const retentionDays = this.env.get("NOTIFICATION_RETENTION_DAYS");
|
|
54
|
+
const removed = await this.notifications.cleanupOldRead(retentionDays);
|
|
55
|
+
if (removed > 0) {
|
|
56
|
+
this.logger.log(`Notificações lidas removidas (> ${retentionDays}d): ${removed}`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async handlePasswordExpiryWarning() {
|
|
61
|
+
await this.run("Aviso de senha a vencer", async () => {
|
|
62
|
+
const maxAge = this.env.get("PASSWORD_MAX_AGE_DAYS");
|
|
63
|
+
const candidates = await this.users.findWithPasswordExpiringIn(maxAge, PASSWORD_WARNING_MILESTONES);
|
|
64
|
+
for (const user of candidates) {
|
|
65
|
+
const daysLeft = this.daysUntilExpiry(user.passwordChangedAt, maxAge);
|
|
66
|
+
if (!PASSWORD_WARNING_MILESTONES.includes(daysLeft)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
this.events.emit(appEvent_enum_1.AppEvent.USER_PASSWORD_EXPIRING, {
|
|
70
|
+
userId: user.id,
|
|
71
|
+
daysLeft,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
daysUntilExpiry(passwordChangedAt, maxAgeDays) {
|
|
77
|
+
if (!passwordChangedAt) {
|
|
78
|
+
return -1;
|
|
79
|
+
}
|
|
80
|
+
const expiresAt = new Date(passwordChangedAt);
|
|
81
|
+
expiresAt.setDate(expiresAt.getDate() + maxAgeDays);
|
|
82
|
+
expiresAt.setHours(0, 0, 0, 0);
|
|
83
|
+
const today = new Date();
|
|
84
|
+
today.setHours(0, 0, 0, 0);
|
|
85
|
+
return Math.round((expiresAt.getTime() - today.getTime()) / (24 * 60 * 60 * 1000));
|
|
86
|
+
}
|
|
87
|
+
async run(routine, job) {
|
|
88
|
+
try {
|
|
89
|
+
await job();
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
93
|
+
this.logger.error(`${routine} falhou: ${reason}`);
|
|
94
|
+
this.events.emit(appEvent_enum_1.AppEvent.SYSTEM_CLEANUP_FAILED, {
|
|
95
|
+
routine,
|
|
96
|
+
reason,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.CleanupService = CleanupService;
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, schedule_1.Cron)(process.env.TOKEN_CLEANUP_CRON ?? "0 */6 * * *", {
|
|
104
|
+
name: "token-cleanup",
|
|
105
|
+
}),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", []),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], CleanupService.prototype, "handleTokenCleanup", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, schedule_1.Cron)(process.env.AUDIT_LOG_CLEANUP_CRON ?? "0 3 * * *", {
|
|
112
|
+
name: "audit-log-cleanup",
|
|
113
|
+
}),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", []),
|
|
116
|
+
__metadata("design:returntype", Promise)
|
|
117
|
+
], CleanupService.prototype, "handleAuditLogCleanup", null);
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, schedule_1.Cron)(process.env.NOTIFICATION_CLEANUP_CRON ?? "0 4 * * *", {
|
|
120
|
+
name: "notification-cleanup",
|
|
121
|
+
}),
|
|
122
|
+
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", []),
|
|
124
|
+
__metadata("design:returntype", Promise)
|
|
125
|
+
], CleanupService.prototype, "handleNotificationCleanup", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, schedule_1.Cron)(process.env.PASSWORD_EXPIRY_WARNING_CRON ?? "0 8 * * *", {
|
|
128
|
+
name: "password-expiry-warning",
|
|
129
|
+
}),
|
|
130
|
+
__metadata("design:type", Function),
|
|
131
|
+
__metadata("design:paramtypes", []),
|
|
132
|
+
__metadata("design:returntype", Promise)
|
|
133
|
+
], CleanupService.prototype, "handlePasswordExpiryWarning", null);
|
|
134
|
+
exports.CleanupService = CleanupService = CleanupService_1 = __decorate([
|
|
135
|
+
(0, common_1.Injectable)(),
|
|
136
|
+
__metadata("design:paramtypes", [token_service_1.TokenService,
|
|
137
|
+
audit_service_1.AuditService,
|
|
138
|
+
env_service_1.EnvService,
|
|
139
|
+
notifications_service_1.NotificationsService,
|
|
140
|
+
user_repository_1.UserRepository,
|
|
141
|
+
event_emitter_1.EventEmitter2])
|
|
142
|
+
], CleanupService);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MaintenanceModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const audit_module_1 = require("../audit/audit.module");
|
|
12
|
+
const auth_module_1 = require("../auth/auth.module");
|
|
13
|
+
const cleanup_service_1 = require("./domain/cleanup.service");
|
|
14
|
+
const notifications_module_1 = require("../notifications/notifications.module");
|
|
15
|
+
const users_module_1 = require("../users/users.module");
|
|
16
|
+
let MaintenanceModule = class MaintenanceModule {
|
|
17
|
+
};
|
|
18
|
+
exports.MaintenanceModule = MaintenanceModule;
|
|
19
|
+
exports.MaintenanceModule = MaintenanceModule = __decorate([
|
|
20
|
+
(0, common_1.Module)({
|
|
21
|
+
imports: [auth_module_1.AuthModule, audit_module_1.AuditModule, notifications_module_1.NotificationsModule, users_module_1.UsersModule],
|
|
22
|
+
providers: [cleanup_service_1.CleanupService],
|
|
23
|
+
})
|
|
24
|
+
], MaintenanceModule);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelType = void 0;
|
|
4
|
+
var ChannelType;
|
|
5
|
+
(function (ChannelType) {
|
|
6
|
+
ChannelType["IN_APP"] = "IN_APP";
|
|
7
|
+
ChannelType["EMAIL"] = "EMAIL";
|
|
8
|
+
ChannelType["PUSH"] = "PUSH";
|
|
9
|
+
ChannelType["SMS"] = "SMS";
|
|
10
|
+
ChannelType["WHATSAPP"] = "WHATSAPP";
|
|
11
|
+
})(ChannelType || (exports.ChannelType = ChannelType = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeliveryStatus = void 0;
|
|
4
|
+
var DeliveryStatus;
|
|
5
|
+
(function (DeliveryStatus) {
|
|
6
|
+
DeliveryStatus["PENDING"] = "PENDING";
|
|
7
|
+
DeliveryStatus["QUEUED"] = "QUEUED";
|
|
8
|
+
DeliveryStatus["SENT"] = "SENT";
|
|
9
|
+
DeliveryStatus["DELIVERED"] = "DELIVERED";
|
|
10
|
+
DeliveryStatus["FAILED"] = "FAILED";
|
|
11
|
+
DeliveryStatus["CANCELLED"] = "CANCELLED";
|
|
12
|
+
})(DeliveryStatus || (exports.DeliveryStatus = DeliveryStatus = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationType = void 0;
|
|
4
|
+
var NotificationType;
|
|
5
|
+
(function (NotificationType) {
|
|
6
|
+
NotificationType["INFO"] = "INFO";
|
|
7
|
+
NotificationType["SUCCESS"] = "SUCCESS";
|
|
8
|
+
NotificationType["WARNING"] = "WARNING";
|
|
9
|
+
NotificationType["ERROR"] = "ERROR";
|
|
10
|
+
})(NotificationType || (exports.NotificationType = NotificationType = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopeType = void 0;
|
|
4
|
+
var ScopeType;
|
|
5
|
+
(function (ScopeType) {
|
|
6
|
+
ScopeType["USER"] = "USER";
|
|
7
|
+
ScopeType["ROLE"] = "ROLE";
|
|
8
|
+
ScopeType["ALL"] = "ALL";
|
|
9
|
+
})(ScopeType || (exports.ScopeType = ScopeType = {}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import { AuthenticatedUser } from "../../../core/auth/authenticatedUser.interface";
|
|
3
|
+
import { Paginated, PaginationQuery } from "../../../core/utils/pagination.util";
|
|
4
|
+
import { NotificationType } from "./enums/notificationType.enum";
|
|
5
|
+
import { ScopeType } from "./enums/scopeType.enum";
|
|
6
|
+
import { NotificationRepository } from "../infra/repositories/notification.repository";
|
|
7
|
+
import { NotificationReadRepository } from "../infra/repositories/notificationRead.repository";
|
|
8
|
+
import { NotificationScopeRepository } from "../infra/repositories/notificationScope.repository";
|
|
9
|
+
import { Notification } from "../infra/schema/notification.schema";
|
|
10
|
+
export interface NotificationTarget {
|
|
11
|
+
type: ScopeType;
|
|
12
|
+
key?: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface PublishNotificationParams {
|
|
15
|
+
title: string;
|
|
16
|
+
body: string;
|
|
17
|
+
type: NotificationType;
|
|
18
|
+
targets: NotificationTarget[];
|
|
19
|
+
payload?: Record<string, unknown> | null;
|
|
20
|
+
createdBy?: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface UserNotification {
|
|
23
|
+
id: string;
|
|
24
|
+
title: string;
|
|
25
|
+
body: string;
|
|
26
|
+
type: NotificationType;
|
|
27
|
+
route: string | null;
|
|
28
|
+
read: boolean;
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
}
|
|
31
|
+
export declare class NotificationsService {
|
|
32
|
+
private readonly notifications;
|
|
33
|
+
private readonly scopes;
|
|
34
|
+
private readonly reads;
|
|
35
|
+
private readonly dataSource;
|
|
36
|
+
constructor(notifications: NotificationRepository, scopes: NotificationScopeRepository, reads: NotificationReadRepository, dataSource: DataSource);
|
|
37
|
+
publish(params: PublishNotificationParams): Promise<Notification>;
|
|
38
|
+
findByUser(user: AuthenticatedUser, query: PaginationQuery): Promise<Paginated<UserNotification>>;
|
|
39
|
+
countUnread(user: AuthenticatedUser): Promise<number>;
|
|
40
|
+
markAsRead(id: string, user: AuthenticatedUser): Promise<void>;
|
|
41
|
+
markAllAsRead(user: AuthenticatedUser): Promise<void>;
|
|
42
|
+
cleanupOldRead(retentionDays: number): Promise<number>;
|
|
43
|
+
private visibilityOf;
|
|
44
|
+
private toUserNotification;
|
|
45
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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.NotificationsService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const pagination_util_1 = require("../../../core/utils/pagination.util");
|
|
16
|
+
const scopeType_enum_1 = require("./enums/scopeType.enum");
|
|
17
|
+
const notification_repository_1 = require("../infra/repositories/notification.repository");
|
|
18
|
+
const notificationRead_repository_1 = require("../infra/repositories/notificationRead.repository");
|
|
19
|
+
const notificationScope_repository_1 = require("../infra/repositories/notificationScope.repository");
|
|
20
|
+
const notification_schema_1 = require("../infra/schema/notification.schema");
|
|
21
|
+
const notificationScope_schema_1 = require("../infra/schema/notificationScope.schema");
|
|
22
|
+
let NotificationsService = class NotificationsService {
|
|
23
|
+
constructor(notifications, scopes, reads, dataSource) {
|
|
24
|
+
this.notifications = notifications;
|
|
25
|
+
this.scopes = scopes;
|
|
26
|
+
this.reads = reads;
|
|
27
|
+
this.dataSource = dataSource;
|
|
28
|
+
}
|
|
29
|
+
async publish(params) {
|
|
30
|
+
return await this.dataSource.transaction(async (manager) => {
|
|
31
|
+
const notification = manager.create(notification_schema_1.Notification, {
|
|
32
|
+
title: params.title,
|
|
33
|
+
body: params.body,
|
|
34
|
+
type: params.type,
|
|
35
|
+
payload: params.payload ?? null,
|
|
36
|
+
createdBy: params.createdBy ?? null,
|
|
37
|
+
});
|
|
38
|
+
const saved = await manager.save(notification);
|
|
39
|
+
const scopes = params.targets.map((target) => manager.create(notificationScope_schema_1.NotificationScope, {
|
|
40
|
+
notificationId: saved.id,
|
|
41
|
+
scopeType: target.type,
|
|
42
|
+
scopeKey: target.type === scopeType_enum_1.ScopeType.ALL ? null : target.key,
|
|
43
|
+
}));
|
|
44
|
+
await manager.save(scopes);
|
|
45
|
+
return saved;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async findByUser(user, query) {
|
|
49
|
+
const { page, limit } = query;
|
|
50
|
+
const [items, total] = await this.notifications.findVisibleToUser(this.visibilityOf(user), page, limit);
|
|
51
|
+
return new pagination_util_1.Paginated(items.map((item) => this.toUserNotification(item)), total, page, limit);
|
|
52
|
+
}
|
|
53
|
+
async countUnread(user) {
|
|
54
|
+
return await this.notifications.countUnread(this.visibilityOf(user));
|
|
55
|
+
}
|
|
56
|
+
async markAsRead(id, user) {
|
|
57
|
+
const visible = await this.notifications.isVisibleToUser(id, this.visibilityOf(user));
|
|
58
|
+
if (!visible) {
|
|
59
|
+
throw new common_1.NotFoundException("Notificação não encontrada");
|
|
60
|
+
}
|
|
61
|
+
await this.reads.markAsRead([id], user.id);
|
|
62
|
+
}
|
|
63
|
+
async markAllAsRead(user) {
|
|
64
|
+
const ids = await this.notifications.findUnreadIds(this.visibilityOf(user));
|
|
65
|
+
await this.reads.markAsRead(ids, user.id);
|
|
66
|
+
}
|
|
67
|
+
async cleanupOldRead(retentionDays) {
|
|
68
|
+
const limit = new Date();
|
|
69
|
+
limit.setDate(limit.getDate() - retentionDays);
|
|
70
|
+
const result = await this.notifications
|
|
71
|
+
.createQueryBuilder()
|
|
72
|
+
.softDelete()
|
|
73
|
+
.where("created_at < :limit", { limit })
|
|
74
|
+
.andWhere(`EXISTS (SELECT 1 FROM notification_reads r WHERE r.notification_id = id)`)
|
|
75
|
+
.execute();
|
|
76
|
+
return result.affected ?? 0;
|
|
77
|
+
}
|
|
78
|
+
visibilityOf(user) {
|
|
79
|
+
return { userId: user.id, roleNames: user.roles ?? [] };
|
|
80
|
+
}
|
|
81
|
+
toUserNotification(notification) {
|
|
82
|
+
const payload = notification.payload;
|
|
83
|
+
return {
|
|
84
|
+
id: notification.id,
|
|
85
|
+
title: notification.title,
|
|
86
|
+
body: notification.body,
|
|
87
|
+
type: notification.type,
|
|
88
|
+
route: payload?.route ?? null,
|
|
89
|
+
read: (notification.reads?.length ?? 0) > 0,
|
|
90
|
+
createdAt: notification.createdAt,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.NotificationsService = NotificationsService;
|
|
95
|
+
exports.NotificationsService = NotificationsService = __decorate([
|
|
96
|
+
(0, common_1.Injectable)(),
|
|
97
|
+
__metadata("design:paramtypes", [notification_repository_1.NotificationRepository,
|
|
98
|
+
notificationScope_repository_1.NotificationScopeRepository,
|
|
99
|
+
notificationRead_repository_1.NotificationReadRepository,
|
|
100
|
+
typeorm_1.DataSource])
|
|
101
|
+
], NotificationsService);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DataSource, Repository } from "typeorm";
|
|
2
|
+
import { Notification } from "../schema/notification.schema";
|
|
3
|
+
export interface VisibilityParams {
|
|
4
|
+
userId: string;
|
|
5
|
+
roleNames: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare class NotificationRepository extends Repository<Notification> {
|
|
8
|
+
constructor(dataSource: DataSource);
|
|
9
|
+
findVisibleToUser(params: VisibilityParams, page: number, limit: number): Promise<[Notification[], number]>;
|
|
10
|
+
countUnread(params: VisibilityParams): Promise<number>;
|
|
11
|
+
isVisibleToUser(notificationId: string, params: VisibilityParams): Promise<boolean>;
|
|
12
|
+
findUnreadIds(params: VisibilityParams): Promise<string[]>;
|
|
13
|
+
private baseVisibleQuery;
|
|
14
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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.NotificationRepository = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const scopeType_enum_1 = require("../../domain/enums/scopeType.enum");
|
|
16
|
+
const notification_schema_1 = require("../schema/notification.schema");
|
|
17
|
+
const VISIBLE_TO_USER = `EXISTS (
|
|
18
|
+
SELECT 1 FROM notification_scopes scope
|
|
19
|
+
WHERE scope.notification_id = notification.id
|
|
20
|
+
AND scope.deleted_at IS NULL
|
|
21
|
+
AND (
|
|
22
|
+
(scope.scope_type = :userScope AND scope.scope_key = :userId)
|
|
23
|
+
OR (scope.scope_type = :roleScope AND scope.scope_key IN (:...roleNames))
|
|
24
|
+
OR scope.scope_type = :allScope
|
|
25
|
+
)
|
|
26
|
+
)`;
|
|
27
|
+
const NO_ROLES = ["-"];
|
|
28
|
+
let NotificationRepository = class NotificationRepository extends typeorm_1.Repository {
|
|
29
|
+
constructor(dataSource) {
|
|
30
|
+
super(notification_schema_1.Notification, dataSource.createEntityManager());
|
|
31
|
+
}
|
|
32
|
+
async findVisibleToUser(params, page, limit) {
|
|
33
|
+
return await this.baseVisibleQuery(params)
|
|
34
|
+
.orderBy("notification.createdAt", "DESC")
|
|
35
|
+
.skip((page - 1) * limit)
|
|
36
|
+
.take(limit)
|
|
37
|
+
.getManyAndCount();
|
|
38
|
+
}
|
|
39
|
+
async countUnread(params) {
|
|
40
|
+
return await this.baseVisibleQuery(params)
|
|
41
|
+
.andWhere("read.notification_id IS NULL")
|
|
42
|
+
.getCount();
|
|
43
|
+
}
|
|
44
|
+
async isVisibleToUser(notificationId, params) {
|
|
45
|
+
const count = await this.baseVisibleQuery(params)
|
|
46
|
+
.andWhere("notification.id = :notificationId", { notificationId })
|
|
47
|
+
.getCount();
|
|
48
|
+
return count > 0;
|
|
49
|
+
}
|
|
50
|
+
async findUnreadIds(params) {
|
|
51
|
+
const rows = await this.baseVisibleQuery(params)
|
|
52
|
+
.andWhere("read.notification_id IS NULL")
|
|
53
|
+
.select("notification.id", "id")
|
|
54
|
+
.getRawMany();
|
|
55
|
+
return rows.map((row) => row.id);
|
|
56
|
+
}
|
|
57
|
+
baseVisibleQuery(params) {
|
|
58
|
+
return this.createQueryBuilder("notification")
|
|
59
|
+
.leftJoinAndSelect("notification.reads", "read", "read.user_id = :userId", { userId: params.userId })
|
|
60
|
+
.where("notification.deletedAt IS NULL")
|
|
61
|
+
.andWhere(VISIBLE_TO_USER, {
|
|
62
|
+
userScope: scopeType_enum_1.ScopeType.USER,
|
|
63
|
+
roleScope: scopeType_enum_1.ScopeType.ROLE,
|
|
64
|
+
allScope: scopeType_enum_1.ScopeType.ALL,
|
|
65
|
+
userId: params.userId,
|
|
66
|
+
roleNames: params.roleNames.length > 0 ? params.roleNames : NO_ROLES,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.NotificationRepository = NotificationRepository;
|
|
71
|
+
exports.NotificationRepository = NotificationRepository = __decorate([
|
|
72
|
+
(0, common_1.Injectable)(),
|
|
73
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
74
|
+
], NotificationRepository);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DataSource, Repository } from "typeorm";
|
|
2
|
+
import { NotificationRead } from "../schema/notificationRead.schema";
|
|
3
|
+
export declare class NotificationReadRepository extends Repository<NotificationRead> {
|
|
4
|
+
constructor(dataSource: DataSource);
|
|
5
|
+
markAsRead(notificationIds: string[], userId: string): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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.NotificationReadRepository = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const notificationRead_schema_1 = require("../schema/notificationRead.schema");
|
|
16
|
+
let NotificationReadRepository = class NotificationReadRepository extends typeorm_1.Repository {
|
|
17
|
+
constructor(dataSource) {
|
|
18
|
+
super(notificationRead_schema_1.NotificationRead, dataSource.createEntityManager());
|
|
19
|
+
}
|
|
20
|
+
async markAsRead(notificationIds, userId) {
|
|
21
|
+
if (notificationIds.length === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await this.createQueryBuilder()
|
|
25
|
+
.insert()
|
|
26
|
+
.into(notificationRead_schema_1.NotificationRead)
|
|
27
|
+
.values(notificationIds.map((notificationId) => ({
|
|
28
|
+
notificationId,
|
|
29
|
+
userId,
|
|
30
|
+
readAt: new Date(),
|
|
31
|
+
})))
|
|
32
|
+
.orIgnore()
|
|
33
|
+
.execute();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.NotificationReadRepository = NotificationReadRepository;
|
|
37
|
+
exports.NotificationReadRepository = NotificationReadRepository = __decorate([
|
|
38
|
+
(0, common_1.Injectable)(),
|
|
39
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
40
|
+
], NotificationReadRepository);
|