@koalarx/nest 3.1.50 → 4.0.2
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 +126 -439
- package/cli/commands/add/index.js +97 -0
- package/cli/commands/help.js +44 -0
- package/cli/commands/new/configure-test-runner.js +13 -0
- package/cli/commands/new/create-ddd-structure.js +52 -0
- package/cli/commands/new/create-empty-nest-project.js +58 -0
- package/cli/commands/new/fix-lint-config.js +24 -0
- package/cli/commands/new/index.js +202 -0
- package/cli/commands/version.js +5 -0
- package/cli/constants/auth-strategy-artifacts.js +56 -0
- package/cli/constants/auth-strategy-checklist.js +314 -0
- package/cli/constants/cli-commands.js +24 -0
- package/cli/constants/cli-project-checklist.js +289 -0
- package/cli/constants/core-packages.js +34 -0
- package/cli/constants/domain.js +171 -0
- package/cli/constants/package-manager.js +5 -0
- package/cli/constants/version.js +5 -0
- package/cli/index.js +55 -0
- package/cli/types/index.js +0 -0
- package/cli/utils/add-project-features.js +170 -0
- package/cli/utils/apply-optional-features.js +48 -0
- package/cli/utils/auth-strategy-validation.js +179 -0
- package/cli/utils/cancel.js +8 -0
- package/cli/utils/cli-options.js +27 -0
- package/cli/utils/cli-project-validation.js +157 -0
- package/cli/utils/detect-project-state.js +131 -0
- package/cli/utils/format-code.js +9 -0
- package/cli/utils/get-package-manager.js +12 -0
- package/cli/utils/get-package-root.js +19 -0
- package/cli/utils/get-source-code-path.js +15 -0
- package/cli/utils/install-module.js +258 -0
- package/cli/utils/normalize-add-args.js +25 -0
- package/cli/utils/parse-new-args.js +127 -0
- package/cli/utils/patch-auth-install.js +224 -0
- package/cli/utils/patch-define-documentation.js +222 -0
- package/cli/utils/patch-env.js +106 -0
- package/cli/utils/patch-generated-project.js +21 -0
- package/cli/utils/patch-health-module.js +80 -0
- package/cli/utils/patch-infra-module.js +62 -0
- package/cli/utils/patch-jobs-module.js +103 -0
- package/cli/utils/patch-main.js +15 -0
- package/cli/utils/patch-person-features.js +127 -0
- package/cli/utils/project-files.js +11 -0
- package/cli/utils/prune-auth-strategies.js +116 -0
- package/cli/utils/prune-core-auth.js +17 -0
- package/cli/utils/remove-sample-parts.js +203 -0
- package/cli/utils/resolve-project-path.js +19 -0
- package/cli/utils/restore-person-features.js +64 -0
- package/cli/utils/run-command.js +31 -0
- package/cli/utils/sync-auth-strategy-files.js +63 -0
- package/koala-nest/.env.example +34 -0
- package/koala-nest/.prettierrc +4 -0
- package/koala-nest/README.md +51 -0
- package/koala-nest/bunfig.toml +7 -0
- package/koala-nest/eslint.config.mjs +55 -0
- package/koala-nest/nest-cli.json +9 -0
- package/koala-nest/package.json +79 -0
- package/koala-nest/src/application/auth/common/auth-token.response.ts +15 -0
- package/koala-nest/src/application/auth/common/user-claims.ts +6 -0
- package/koala-nest/src/application/auth/login/login.handler.ts +42 -0
- package/koala-nest/src/application/auth/login/login.request.ts +9 -0
- package/koala-nest/src/application/auth/login/login.response.ts +3 -0
- package/koala-nest/src/application/auth/login/login.validator.ts +12 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.handler.ts +24 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.request.ts +10 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.response.ts +6 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.validator.ts +12 -0
- package/koala-nest/src/application/auth/oauth2/callback/oauth-callback.response.ts +10 -0
- package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.handler.ts +73 -0
- package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.request.ts +16 -0
- package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.validator.ts +14 -0
- package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-oauth-token.handler.ts +35 -0
- package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-token.types.ts +1 -0
- package/koala-nest/src/application/auth/refresh-token/refresh-token.handler.ts +26 -0
- package/koala-nest/src/application/auth/user-info/user-info.handler.ts +30 -0
- package/koala-nest/src/application/auth/user-info/user-info.response.ts +20 -0
- package/koala-nest/src/application/common/created-registre.response.ts +20 -0
- package/koala-nest/src/application/common/pagination.request.ts +41 -0
- package/koala-nest/src/application/common/request-handler.base.ts +3 -0
- package/koala-nest/src/application/common/request-validator.base.ts +33 -0
- package/koala-nest/src/application/mapping/mapping.provider.ts +9 -0
- package/koala-nest/src/application/mapping/person.mapper.ts +44 -0
- package/koala-nest/src/application/person/create/create-person.handler.ts +34 -0
- package/koala-nest/src/application/person/create/create-person.request.ts +29 -0
- package/koala-nest/src/application/person/create/create-person.response.ts +3 -0
- package/koala-nest/src/application/person/create/create-person.validator.ts +9 -0
- package/koala-nest/src/application/person/delete/delete-person.handler.ts +22 -0
- package/koala-nest/src/application/person/find-person-or-throw.ts +16 -0
- package/koala-nest/src/application/person/jobs/cron/create-person.job.ts +58 -0
- package/koala-nest/src/application/person/jobs/cron/delete-inactive.job.ts +57 -0
- package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.event.ts +4 -0
- package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.handler.ts +54 -0
- package/koala-nest/src/application/person/jobs/events/person/person-event.job.ts +19 -0
- package/koala-nest/src/application/person/person.schemas.ts +21 -0
- package/koala-nest/src/application/person/read/read-person.handler.ts +22 -0
- package/koala-nest/src/application/person/read/read-person.response.ts +44 -0
- package/koala-nest/src/application/person/read-many/read-many-person.handler.ts +63 -0
- package/koala-nest/src/application/person/read-many/read-many-person.request.ts +13 -0
- package/koala-nest/src/application/person/read-many/read-many-person.response.ts +30 -0
- package/koala-nest/src/application/person/read-many/read-many-person.validator.ts +15 -0
- package/koala-nest/src/application/person/update/update-person.handler.ts +51 -0
- package/koala-nest/src/application/person/update/update-person.request.ts +41 -0
- package/koala-nest/src/application/person/update/update-person.validator.ts +9 -0
- package/koala-nest/src/core/auth/assert-user-active.ts +18 -0
- package/koala-nest/src/core/auth/auth-profile.enum.ts +7 -0
- package/koala-nest/src/core/auth/auth-routes.ts +5 -0
- package/koala-nest/src/core/auth/auth.constants.ts +6 -0
- package/koala-nest/src/core/auth/jwt-claims.ts +23 -0
- package/koala-nest/src/core/auth/oauth-provider.registry.ts +94 -0
- package/koala-nest/src/core/auth/parse-jwt-expires-in.ts +30 -0
- package/koala-nest/src/core/auth/parse-oauth2-provider-env.ts +56 -0
- package/koala-nest/src/core/auth/resolve-refresh-token.ts +40 -0
- package/koala-nest/src/core/background-services/cron-service/cron-job.handler.base.ts +65 -0
- package/koala-nest/src/core/background-services/event-service/event-class.ts +5 -0
- package/koala-nest/src/core/background-services/event-service/event-handler.base.ts +17 -0
- package/koala-nest/src/core/background-services/event-service/event-job.ts +31 -0
- package/koala-nest/src/core/background-services/event-service/event-queue.ts +107 -0
- package/koala-nest/src/core/base/entity.base.ts +3 -0
- package/koala-nest/src/core/base/object-class.ts +14 -0
- package/koala-nest/src/core/constants/cache.constants.ts +16 -0
- package/koala-nest/src/core/constants/cron.constants.ts +14 -0
- package/koala-nest/src/core/constants/query-params.ts +7 -0
- package/koala-nest/src/core/env.ts +42 -0
- package/koala-nest/src/core/schemas/boolean.schema.ts +24 -0
- package/koala-nest/src/core/schemas/document-number-mask.ts +22 -0
- package/koala-nest/src/core/schemas/document-number.schema.ts +21 -0
- package/koala-nest/src/core/schemas/document-number.utils.ts +15 -0
- package/koala-nest/src/core/schemas/email.schema.ts +13 -0
- package/koala-nest/src/core/schemas/index.ts +6 -0
- package/koala-nest/src/core/schemas/list-query.schema.ts +18 -0
- package/koala-nest/src/core/schemas/native-enum.schema.ts +36 -0
- package/koala-nest/src/core/tools/mapping/auto-map.ts +14 -0
- package/koala-nest/src/core/tools/mapping/auto-mapper.ts +102 -0
- package/koala-nest/src/core/tools/mapping/create-map.ts +11 -0
- package/koala-nest/src/core/tools/mapping/for-member.ts +16 -0
- package/koala-nest/src/core/tools/mapping/index.ts +4 -0
- package/koala-nest/src/core/tools/mapping/mapping-store.ts +121 -0
- package/koala-nest/src/core/types/auth-provider-config-response.type.ts +5 -0
- package/koala-nest/src/core/types/index.ts +5 -0
- package/koala-nest/src/core/utils/build-list-cache-key.ts +19 -0
- package/koala-nest/src/core/utils/cron-expression-to-boolean.ts +65 -0
- package/koala-nest/src/core/utils/env.config.ts +17 -0
- package/koala-nest/src/core/utils/filter-request-params.ts +29 -0
- package/koala-nest/src/core/utils/format-typeorm-error.ts +173 -0
- package/koala-nest/src/core/utils/format-zod-error.ts +201 -0
- package/koala-nest/src/core/utils/hash-password.ts +5 -0
- package/koala-nest/src/core/utils/icomparable.ts +1 -0
- package/koala-nest/src/core/utils/is-provider-registered.ts +40 -0
- package/koala-nest/src/core/utils/name-to-login.ts +25 -0
- package/koala-nest/src/core/utils/person-list-cache.ts +7 -0
- package/koala-nest/src/core/utils/report-error.ts +18 -0
- package/koala-nest/src/core/utils/resolve-api-host.ts +8 -0
- package/koala-nest/src/core/utils/time.constants.ts +5 -0
- package/koala-nest/src/domain/auth/dtos/auth-provider-config.dto.ts +12 -0
- package/koala-nest/src/domain/auth/dtos/oauth-user-info.dto.ts +9 -0
- package/koala-nest/src/domain/auth/services/iauth.service.ts +37 -0
- package/koala-nest/src/domain/common/icache.service.ts +11 -0
- package/koala-nest/src/domain/common/ilogging.service.ts +9 -0
- package/koala-nest/src/domain/common/ired-lock.service.ts +4 -0
- package/koala-nest/src/domain/dtos/logged-user-info.dto.ts +30 -0
- package/koala-nest/src/domain/dtos/pagination.dto.ts +35 -0
- package/koala-nest/src/domain/dtos/person-query.dto.ts +10 -0
- package/koala-nest/src/domain/entities/person/person-address.ts +14 -0
- package/koala-nest/src/domain/entities/person/person-contact.ts +28 -0
- package/koala-nest/src/domain/entities/person/person.ts +44 -0
- package/koala-nest/src/domain/entities/user/enums/user-status.enum.ts +6 -0
- package/koala-nest/src/domain/entities/user/user.ts +49 -0
- package/koala-nest/src/domain/repositories/iperson.repository.ts +10 -0
- package/koala-nest/src/domain/repositories/iuser.repository.ts +8 -0
- package/koala-nest/src/domain/services/ilogged-user-info.service.ts +5 -0
- package/koala-nest/src/host/app.module.ts +27 -0
- package/koala-nest/src/host/controllers/auth/auth.module.ts +38 -0
- package/koala-nest/src/host/controllers/auth/login.controller.ts +41 -0
- package/koala-nest/src/host/controllers/auth/refresh-token.controller.ts +24 -0
- package/koala-nest/src/host/controllers/auth/router.config.ts +9 -0
- package/koala-nest/src/host/controllers/auth/user-info.controller.ts +19 -0
- package/koala-nest/src/host/controllers/common/controller.base.ts +9 -0
- package/koala-nest/src/host/controllers/common/controller.module.ts +10 -0
- package/koala-nest/src/host/controllers/common/router-config.base.ts +14 -0
- package/koala-nest/src/host/controllers/health-check/health-check.controller.ts +29 -0
- package/koala-nest/src/host/controllers/health-check/health-check.module.ts +22 -0
- package/koala-nest/src/host/controllers/oauth2/auth-link.controller.ts +29 -0
- package/koala-nest/src/host/controllers/oauth2/exchange-code.controller.ts +29 -0
- package/koala-nest/src/host/controllers/oauth2/oauth-callback.controller.ts +28 -0
- package/koala-nest/src/host/controllers/oauth2/router.config.ts +9 -0
- package/koala-nest/src/host/controllers/oauth2/scalar-token.controller.ts +16 -0
- package/koala-nest/src/host/controllers/person/create-person.controller.ts +23 -0
- package/koala-nest/src/host/controllers/person/delete-person.controller.ts +23 -0
- package/koala-nest/src/host/controllers/person/person.module.ts +39 -0
- package/koala-nest/src/host/controllers/person/read-many-person.controller.ts +24 -0
- package/koala-nest/src/host/controllers/person/read-person.controller.ts +21 -0
- package/koala-nest/src/host/controllers/person/router.config.ts +9 -0
- package/koala-nest/src/host/controllers/person/update-person.controller.ts +22 -0
- package/koala-nest/src/host/decorators/api-exclude-endpoint-diff-develop.decorator.ts +9 -0
- package/koala-nest/src/host/decorators/api-property-enum.decorator.ts +49 -0
- package/koala-nest/src/host/decorators/api-property-only-develop.decorator.ts +19 -0
- package/koala-nest/src/host/decorators/controller.decorator.ts +10 -0
- package/koala-nest/src/host/decorators/is-public.decorator.ts +82 -0
- package/koala-nest/src/host/decorators/restriction-by-profile.decorator.ts +13 -0
- package/koala-nest/src/host/decorators/scalar-token-endpoint.decorator.ts +14 -0
- package/koala-nest/src/host/filters/errors.filter.ts +99 -0
- package/koala-nest/src/host/jobs/jobs-bootstrap.service.ts +61 -0
- package/koala-nest/src/host/jobs/jobs.module.ts +41 -0
- package/koala-nest/src/host/jobs/jobs.tokens.ts +2 -0
- package/koala-nest/src/host/main.ts +43 -0
- package/koala-nest/src/host/open-api/define-documentation.ts +210 -0
- package/koala-nest/src/host/security/guards/auth.guard.ts +107 -0
- package/koala-nest/src/host/security/guards/profiles.guard.ts +32 -0
- package/koala-nest/src/host/security/security.module.ts +62 -0
- package/koala-nest/src/host/security/strategies/jwt.strategy.ts +61 -0
- package/koala-nest/src/infra/auth/jwt-token.service.ts +48 -0
- package/koala-nest/src/infra/auth/oauth2-auth.service.ts +208 -0
- package/koala-nest/src/infra/common/cache-service.provider.ts +47 -0
- package/koala-nest/src/infra/common/env.service.ts +12 -0
- package/koala-nest/src/infra/common/in-memory-cache.service.ts +71 -0
- package/koala-nest/src/infra/common/logging.service.ts +19 -0
- package/koala-nest/src/infra/common/red-lock.service.ts +44 -0
- package/koala-nest/src/infra/common/redis-cache.service.ts +72 -0
- package/koala-nest/src/infra/database/data-source-factory.ts +23 -0
- package/koala-nest/src/infra/database/database.module.ts +19 -0
- package/koala-nest/src/infra/database/migrations/1781281330533-Init.ts +67 -0
- package/koala-nest/src/infra/database/migrations/generate-migration.ts +26 -0
- package/koala-nest/src/infra/database/migrations/migration-datasource.ts +14 -0
- package/koala-nest/src/infra/infra.module.ts +29 -0
- package/koala-nest/src/infra/repositories/person.repository.ts +49 -0
- package/koala-nest/src/infra/repositories/repository.base.ts +20 -0
- package/koala-nest/src/infra/repositories/repository.module.ts +16 -0
- package/koala-nest/src/infra/repositories/user.repository.ts +38 -0
- package/koala-nest/src/infra/services/database.indicator.service.ts +17 -0
- package/koala-nest/src/infra/services/logged-user-info.service.ts +32 -0
- package/koala-nest/src/infra/services/redis.indicator.service.ts +66 -0
- package/koala-nest/src/test/app-auth-test.module.ts +32 -0
- package/koala-nest/src/test/app-test.module.ts +22 -0
- package/koala-nest/src/test/application/auth-link.handler.spec.ts +22 -0
- package/koala-nest/src/test/application/create-person.handler.spec.ts +39 -0
- package/koala-nest/src/test/application/create-person.job.spec.ts +55 -0
- package/koala-nest/src/test/application/delete-inactive.job.spec.ts +35 -0
- package/koala-nest/src/test/application/delete-person.handler.spec.ts +46 -0
- package/koala-nest/src/test/application/exchange-code.handler.spec.ts +67 -0
- package/koala-nest/src/test/application/inactive-person.handler.spec.ts +48 -0
- package/koala-nest/src/test/application/login.handler.spec.ts +55 -0
- package/koala-nest/src/test/application/read-many-person.handler.spec.ts +64 -0
- package/koala-nest/src/test/application/read-person.handler.spec.ts +44 -0
- package/koala-nest/src/test/application/refresh-token.handler.spec.ts +34 -0
- package/koala-nest/src/test/application/scalar-oauth-token.handler.spec.ts +63 -0
- package/koala-nest/src/test/application/update-person.handler.spec.ts +78 -0
- package/koala-nest/src/test/bun-test-globals.d.ts +1 -0
- package/koala-nest/src/test/core/auth.guard.spec.ts +77 -0
- package/koala-nest/src/test/core/build-list-cache-key.spec.ts +29 -0
- package/koala-nest/src/test/core/cron-expression-to-boolean.spec.ts +22 -0
- package/koala-nest/src/test/core/cron-job.handler.spec.ts +40 -0
- package/koala-nest/src/test/core/env.config.spec.ts +14 -0
- package/koala-nest/src/test/core/env.spec.ts +61 -0
- package/koala-nest/src/test/core/event-queue.spec.ts +53 -0
- package/koala-nest/src/test/core/format-typeorm-error.spec.ts +42 -0
- package/koala-nest/src/test/core/format-zod-error.spec.ts +38 -0
- package/koala-nest/src/test/core/is-provider-registered.spec.ts +35 -0
- package/koala-nest/src/test/core/jwt.strategy.spec.ts +38 -0
- package/koala-nest/src/test/core/mapping.spec.ts +177 -0
- package/koala-nest/src/test/core/oauth-provider.registry.spec.ts +79 -0
- package/koala-nest/src/test/core/profiles.guard.spec.ts +42 -0
- package/koala-nest/src/test/core/resolve-api-host.spec.ts +20 -0
- package/koala-nest/src/test/core/schemas.spec.ts +95 -0
- package/koala-nest/src/test/create-auth-e2e-test-app.ts +22 -0
- package/koala-nest/src/test/create-e2e-test-app.ts +14 -0
- package/koala-nest/src/test/e2e-context.ts +7 -0
- package/koala-nest/src/test/host/controllers/auth/auth.controller.e2e.spec.ts +87 -0
- package/koala-nest/src/test/host/controllers/person/lazy-loading.e2e.spec.ts +181 -0
- package/koala-nest/src/test/host/controllers/person/person.controller.e2e.spec.ts +148 -0
- package/koala-nest/src/test/host/errors.filter.spec.ts +75 -0
- package/koala-nest/src/test/host/is-public-open-api.spec.ts +60 -0
- package/koala-nest/src/test/host/oauth-callback.controller.spec.ts +18 -0
- package/koala-nest/src/test/infra/cache-service.provider.spec.ts +21 -0
- package/koala-nest/src/test/infra/in-memory-cache.service.spec.ts +49 -0
- package/koala-nest/src/test/infra/jwt-token.service.spec.ts +28 -0
- package/koala-nest/src/test/infra/logged-user-info.service.spec.ts +33 -0
- package/koala-nest/src/test/infra/oauth2-auth.service.spec.ts +112 -0
- package/koala-nest/src/test/infra/red-lock.service.spec.ts +43 -0
- package/koala-nest/src/test/infra/redis-cache.service.spec.ts +100 -0
- package/koala-nest/src/test/infra/redis-indicator.service.spec.ts +75 -0
- package/koala-nest/src/test/mockup/person/person.entities.ts +35 -0
- package/koala-nest/src/test/mockup/person/person.requests.ts +23 -0
- package/koala-nest/src/test/mockup/person/person.responses.ts +31 -0
- package/koala-nest/src/test/services/cache.stub.ts +41 -0
- package/koala-nest/src/test/services/fake-logging.service.ts +13 -0
- package/koala-nest/src/test/services/fake-red-lock.service.ts +11 -0
- package/koala-nest/src/test/services/logged-user-info.fake-service.ts +18 -0
- package/koala-nest/src/test/setup-e2e.ts +66 -0
- package/koala-nest/src/test/setup.ts +1 -0
- package/koala-nest/src/test/utils/configure-test-app.ts +24 -0
- package/koala-nest/src/test/utils/create-e2e-database.ts +50 -0
- package/koala-nest/src/test/utils/e2e-database-client.ts +9 -0
- package/koala-nest/src/test/utils/guard-test-context.ts +28 -0
- package/koala-nest/src/test/utils/jwt-test-keys.ts +27 -0
- package/koala-nest/tsconfig.build.json +8 -0
- package/koala-nest/tsconfig.json +36 -0
- package/koala-nest/tsconfig.spec.json +11 -0
- package/package.json +19 -29
- package/core/backgroud-services/cron-service/cron-job.handler.base.d.ts +0 -16
- package/core/backgroud-services/cron-service/cron-job.handler.base.js +0 -49
- package/core/backgroud-services/event-service/event-class.d.ts +0 -5
- package/core/backgroud-services/event-service/event-class.js +0 -11
- package/core/backgroud-services/event-service/event-handler.base.d.ts +0 -8
- package/core/backgroud-services/event-service/event-handler.base.js +0 -14
- package/core/backgroud-services/event-service/event-is-trigger.d.ts +0 -3
- package/core/backgroud-services/event-service/event-is-trigger.js +0 -7
- package/core/backgroud-services/event-service/event-job.d.ts +0 -13
- package/core/backgroud-services/event-service/event-job.js +0 -21
- package/core/backgroud-services/event-service/event-queue.d.ts +0 -18
- package/core/backgroud-services/event-service/event-queue.js +0 -65
- package/core/constants/query-params.d.ts +0 -6
- package/core/constants/query-params.js +0 -8
- package/core/controllers/base.controller.d.ts +0 -4
- package/core/controllers/base.controller.js +0 -6
- package/core/controllers/controller.decorator.d.ts +0 -2
- package/core/controllers/controller.decorator.js +0 -11
- package/core/controllers/created-registre-response.base.d.ts +0 -10
- package/core/controllers/created-registre-response.base.js +0 -35
- package/core/controllers/list-response.base.d.ts +0 -4
- package/core/controllers/list-response.base.js +0 -21
- package/core/controllers/pagination.request.d.ts +0 -10
- package/core/controllers/pagination.request.js +0 -56
- package/core/controllers/router-config.base.d.ts +0 -7
- package/core/controllers/router-config.base.js +0 -18
- package/core/controllers/schemas/boolean.schema.d.ts +0 -2
- package/core/controllers/schemas/boolean.schema.js +0 -12
- package/core/controllers/schemas/document-number.schema.d.ts +0 -1
- package/core/controllers/schemas/document-number.schema.js +0 -26
- package/core/controllers/schemas/email.schema.d.ts +0 -1
- package/core/controllers/schemas/email.schema.js +0 -13
- package/core/controllers/schemas/list-query.schema.d.ts +0 -17
- package/core/controllers/schemas/list-query.schema.js +0 -19
- package/core/controllers/schemas/native-enum.schema.d.ts +0 -7
- package/core/controllers/schemas/native-enum.schema.js +0 -28
- package/core/controllers/schemas/set-mask-document-number.schema.d.ts +0 -1
- package/core/controllers/schemas/set-mask-document-number.schema.js +0 -13
- package/core/database/entity.base.d.ts +0 -27
- package/core/database/entity.base.js +0 -145
- package/core/database/entity.decorator.d.ts +0 -12
- package/core/database/entity.decorator.js +0 -37
- package/core/database/prisma-client-with-custom-transaction.interface.d.ts +0 -8
- package/core/database/prisma-client-with-custom-transaction.interface.js +0 -2
- package/core/database/prisma-resolver.d.ts +0 -2
- package/core/database/prisma-resolver.js +0 -74
- package/core/database/prisma-transactional-client.d.ts +0 -11
- package/core/database/prisma-transactional-client.js +0 -25
- package/core/database/prisma.service.d.ts +0 -24
- package/core/database/prisma.service.js +0 -104
- package/core/database/repository.base.d.ts +0 -83
- package/core/database/repository.base.js +0 -668
- package/core/dtos/pagination.dto.d.ts +0 -9
- package/core/dtos/pagination.dto.js +0 -49
- package/core/errors/bad-request.error.d.ts +0 -5
- package/core/errors/bad-request.error.js +0 -10
- package/core/errors/conflict.error.d.ts +0 -4
- package/core/errors/conflict.error.js +0 -10
- package/core/errors/error.base.d.ts +0 -4
- package/core/errors/error.base.js +0 -11
- package/core/errors/no-content.error.d.ts +0 -5
- package/core/errors/no-content.error.js +0 -10
- package/core/errors/not-allowed.error.d.ts +0 -5
- package/core/errors/not-allowed.error.js +0 -10
- package/core/errors/resource-not-found.error.d.ts +0 -5
- package/core/errors/resource-not-found.error.js +0 -10
- package/core/errors/use-case-error.d.ts +0 -3
- package/core/errors/use-case-error.js +0 -2
- package/core/errors/user-already-exist.error.d.ts +0 -4
- package/core/errors/user-already-exist.error.js +0 -10
- package/core/errors/wrong-credentials.error.d.ts +0 -4
- package/core/errors/wrong-credentials.error.js +0 -10
- package/core/health-check/health-check.controller.d.ts +0 -5
- package/core/health-check/health-check.controller.js +0 -32
- package/core/health-check/health-check.module.d.ts +0 -2
- package/core/health-check/health-check.module.js +0 -19
- package/core/index.d.ts +0 -18
- package/core/index.js +0 -7
- package/core/koala-app.d.ts +0 -64
- package/core/koala-app.js +0 -258
- package/core/koala-global-vars.d.ts +0 -7
- package/core/koala-global-vars.js +0 -9
- package/core/koala-nest-database.module.d.ts +0 -16
- package/core/koala-nest-database.module.js +0 -52
- package/core/koala-nest-http.module.d.ts +0 -13
- package/core/koala-nest-http.module.js +0 -37
- package/core/koala-nest.module.d.ts +0 -17
- package/core/koala-nest.module.js +0 -66
- package/core/mapping/auto-mapping-class-context.d.ts +0 -16
- package/core/mapping/auto-mapping-class-context.js +0 -18
- package/core/mapping/auto-mapping-context.d.ts +0 -11
- package/core/mapping/auto-mapping-context.js +0 -24
- package/core/mapping/auto-mapping-list.d.ts +0 -28
- package/core/mapping/auto-mapping-list.js +0 -99
- package/core/mapping/auto-mapping-profile.d.ts +0 -3
- package/core/mapping/auto-mapping-profile.js +0 -6
- package/core/mapping/auto-mapping.decorator.d.ts +0 -9
- package/core/mapping/auto-mapping.decorator.js +0 -27
- package/core/mapping/auto-mapping.module.d.ts +0 -5
- package/core/mapping/auto-mapping.module.js +0 -29
- package/core/mapping/auto-mapping.service.d.ts +0 -20
- package/core/mapping/auto-mapping.service.js +0 -197
- package/core/mapping/create-map.d.ts +0 -3
- package/core/mapping/create-map.js +0 -7
- package/core/mapping/for-member.d.ts +0 -5
- package/core/mapping/for-member.js +0 -8
- package/core/request-overflow/request-handler.base.d.ts +0 -4
- package/core/request-overflow/request-handler.base.js +0 -6
- package/core/request-overflow/request-result.d.ts +0 -15
- package/core/request-overflow/request-result.js +0 -37
- package/core/request-overflow/request-validator.base.d.ts +0 -7
- package/core/request-overflow/request-validator.base.js +0 -26
- package/core/security/strategies/api-key.strategy.d.ts +0 -16
- package/core/security/strategies/api-key.strategy.js +0 -31
- package/core/utils/assing-object.d.ts +0 -5
- package/core/utils/assing-object.js +0 -6
- package/core/utils/automap-cycle-context.d.ts +0 -6
- package/core/utils/automap-cycle-context.js +0 -33
- package/core/utils/env.config.d.ts +0 -6
- package/core/utils/env.config.js +0 -18
- package/core/utils/filter-request-params.d.ts +0 -13
- package/core/utils/filter-request-params.js +0 -22
- package/core/utils/find-on-list.d.ts +0 -2
- package/core/utils/find-on-list.js +0 -13
- package/core/utils/generate-prisma-include-schema.d.ts +0 -9
- package/core/utils/generate-prisma-include-schema.js +0 -60
- package/core/utils/get-type-by-prop.d.ts +0 -2
- package/core/utils/get-type-by-prop.js +0 -11
- package/core/utils/hydrate-entity-from-cache.d.ts +0 -22
- package/core/utils/hydrate-entity-from-cache.js +0 -76
- package/core/utils/instanciate-class-with-dependencies-injection.d.ts +0 -2
- package/core/utils/instanciate-class-with-dependencies-injection.js +0 -10
- package/core/utils/interfaces/icomparable.d.ts +0 -5
- package/core/utils/interfaces/icomparable.js +0 -6
- package/core/utils/is-plain-object.d.ts +0 -1
- package/core/utils/is-plain-object.js +0 -8
- package/core/utils/list.d.ts +0 -39
- package/core/utils/list.js +0 -167
- package/core/utils/promise-all.d.ts +0 -7
- package/core/utils/promise-all.js +0 -19
- package/core/utils/proxy.d.ts +0 -1
- package/core/utils/proxy.js +0 -27
- package/core/utils/set-mask-document-number.d.ts +0 -1
- package/core/utils/set-mask-document-number.js +0 -13
- package/core/validators/file-validator.d.ts +0 -27
- package/core/validators/file-validator.js +0 -94
- package/decorators/api-exclude-endpoint-diff-develop.decorator.d.ts +0 -1
- package/decorators/api-exclude-endpoint-diff-develop.decorator.js +0 -9
- package/decorators/api-property-enum.decorator.d.ts +0 -8
- package/decorators/api-property-enum.decorator.js +0 -21
- package/decorators/api-property-only-develop.decorator.d.ts +0 -2
- package/decorators/api-property-only-develop.decorator.js +0 -9
- package/decorators/cookies.decorator.d.ts +0 -1
- package/decorators/cookies.decorator.js +0 -8
- package/decorators/is-public.decorator.d.ts +0 -2
- package/decorators/is-public.decorator.js +0 -7
- package/decorators/upload.decorator.d.ts +0 -1
- package/decorators/upload.decorator.js +0 -18
- package/env/env.d.ts +0 -25
- package/env/env.js +0 -14
- package/env/env.module.d.ts +0 -2
- package/env/env.module.js +0 -20
- package/env/env.service.d.ts +0 -7
- package/env/env.service.js +0 -28
- package/filters/domain-errors.filter.d.ts +0 -18
- package/filters/domain-errors.filter.js +0 -92
- package/filters/global-exception.filter.d.ts +0 -8
- package/filters/global-exception.filter.js +0 -68
- package/filters/prisma-validation-exception.filter.d.ts +0 -10
- package/filters/prisma-validation-exception.filter.js +0 -82
- package/filters/zod-errors.filter.d.ts +0 -9
- package/filters/zod-errors.filter.js +0 -60
- package/services/logging/ilogging.service.d.ts +0 -16
- package/services/logging/ilogging.service.js +0 -6
- package/services/logging/logging.service.d.ts +0 -4
- package/services/logging/logging.service.js +0 -20
- package/services/redis/iredis.service.d.ts +0 -6
- package/services/redis/iredis.service.js +0 -6
- package/services/redis/redis.service.d.ts +0 -14
- package/services/redis/redis.service.js +0 -65
- package/services/redlock/ired-lock.service.d.ts +0 -4
- package/services/redlock/ired-lock.service.js +0 -6
- package/services/redlock/red-lock.service.d.ts +0 -9
- package/services/redlock/red-lock.service.js +0 -46
- package/test/koala-app-test-dependencies.d.ts +0 -10
- package/test/koala-app-test-dependencies.js +0 -13
- package/test/koala-app-test.d.ts +0 -22
- package/test/koala-app-test.js +0 -77
- package/test/repositories/in-memory-base.repository.d.ts +0 -17
- package/test/repositories/in-memory-base.repository.js +0 -67
- package/test/services/fake-logging.service.d.ts +0 -4
- package/test/services/fake-logging.service.js +0 -9
- package/test/services/fake-red-lock.service.d.ts +0 -5
- package/test/services/fake-red-lock.service.js +0 -11
- package/test/utils/create-e2e-database.d.ts +0 -7
- package/test/utils/create-e2e-database.js +0 -38
- package/test/utils/e2e-database-client.d.ts +0 -7
- package/test/utils/e2e-database-client.js +0 -12
- package/test/utils/wait-for.d.ts +0 -1
- package/test/utils/wait-for.js +0 -21
- package/tsconfig.lib.tsbuildinfo +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CronExpression } from '@/core/constants/cron.constants';
|
|
2
|
+
import { CreatePersonHandler } from '@/application/person/create/create-person.handler';
|
|
3
|
+
import { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
4
|
+
import {
|
|
5
|
+
CronJobHandlerBase,
|
|
6
|
+
CronJobSettings,
|
|
7
|
+
cronJobSettings,
|
|
8
|
+
} from '@/core/background-services/cron-service/cron-job.handler.base';
|
|
9
|
+
import { EventQueue } from '@/core/background-services/event-service/event-queue';
|
|
10
|
+
import { ILoggingService } from '@/domain/common/ilogging.service';
|
|
11
|
+
import { IRedLockService } from '@/domain/common/ired-lock.service';
|
|
12
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
13
|
+
import { InactivePersonEvent } from '@/application/person/jobs/events/person/inactive-person/inactive-person.event';
|
|
14
|
+
import { PersonEventJob } from '@/application/person/jobs/events/person/person-event.job';
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class CreatePersonJob extends CronJobHandlerBase {
|
|
18
|
+
private readonly logger = new Logger(CreatePersonJob.name);
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
redlockService: IRedLockService,
|
|
22
|
+
loggingService: ILoggingService,
|
|
23
|
+
private readonly createPerson: CreatePersonHandler,
|
|
24
|
+
private readonly repository: IPersonRepository,
|
|
25
|
+
) {
|
|
26
|
+
super(redlockService, loggingService);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected settings(): Promise<CronJobSettings> {
|
|
30
|
+
return Promise.resolve(cronJobSettings(CronExpression.EVERY_15_SECONDS));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected async run(): Promise<void> {
|
|
34
|
+
this.logger.debug('Iniciando criação de pessoa...');
|
|
35
|
+
|
|
36
|
+
const created = await this.createPerson.handle({
|
|
37
|
+
name: 'John Doe',
|
|
38
|
+
contacts: [{ contact: '22999999999@example.com' }],
|
|
39
|
+
address: { address: 'Street 1' },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const person = await this.repository.findById(created.id);
|
|
43
|
+
|
|
44
|
+
if (person) {
|
|
45
|
+
this.logger.log(`Pessoa criada com sucesso. ID: ${person.id}`);
|
|
46
|
+
|
|
47
|
+
const jobs = new PersonEventJob();
|
|
48
|
+
jobs.addEvent(new InactivePersonEvent());
|
|
49
|
+
EventQueue.dispatchEventsForAggregate(jobs._id);
|
|
50
|
+
|
|
51
|
+
this.logger.log('Evento de inativação disparado.');
|
|
52
|
+
} else {
|
|
53
|
+
this.logger.log('Pessoa não encontrada após criação.');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.logger.log('Job concluído.');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CronExpression } from '@/core/constants/cron.constants';
|
|
2
|
+
import { DeletePersonHandler } from '@/application/person/delete/delete-person.handler';
|
|
3
|
+
import { ReadManyPersonHandler } from '@/application/person/read-many/read-many-person.handler';
|
|
4
|
+
import { ReadManyPersonRequest } from '@/application/person/read-many/read-many-person.request';
|
|
5
|
+
import {
|
|
6
|
+
CronJobHandlerBase,
|
|
7
|
+
CronJobSettings,
|
|
8
|
+
cronJobSettings,
|
|
9
|
+
} from '@/core/background-services/cron-service/cron-job.handler.base';
|
|
10
|
+
import { ILoggingService } from '@/domain/common/ilogging.service';
|
|
11
|
+
import { IRedLockService } from '@/domain/common/ired-lock.service';
|
|
12
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
13
|
+
|
|
14
|
+
@Injectable()
|
|
15
|
+
export class DeleteInactiveJob extends CronJobHandlerBase {
|
|
16
|
+
private readonly logger = new Logger(DeleteInactiveJob.name);
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
redlockService: IRedLockService,
|
|
20
|
+
loggingService: ILoggingService,
|
|
21
|
+
private readonly readManyPerson: ReadManyPersonHandler,
|
|
22
|
+
private readonly deletePerson: DeletePersonHandler,
|
|
23
|
+
) {
|
|
24
|
+
super(redlockService, loggingService);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected settings(): Promise<CronJobSettings> {
|
|
28
|
+
return Promise.resolve(cronJobSettings(CronExpression.EVERY_15_SECONDS));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async run(): Promise<void> {
|
|
32
|
+
this.logger.debug('Iniciando remoção de pessoas inativas...');
|
|
33
|
+
|
|
34
|
+
const request = new ReadManyPersonRequest();
|
|
35
|
+
request.active = false;
|
|
36
|
+
|
|
37
|
+
const result = await this.readManyPerson.handle(request);
|
|
38
|
+
|
|
39
|
+
if (result.items.length === 0) {
|
|
40
|
+
this.logger.log('Nenhuma pessoa inativa encontrada.');
|
|
41
|
+
this.logger.log('Job concluído sem ação.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.logger.debug('Removendo pessoas inativas...', result.items.length);
|
|
46
|
+
|
|
47
|
+
for (const person of result.items) {
|
|
48
|
+
await this.deletePerson.handle(person.id);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.logger.log(
|
|
52
|
+
'Pessoas inativas removidas com sucesso.',
|
|
53
|
+
result.items.length,
|
|
54
|
+
);
|
|
55
|
+
this.logger.log('Job concluído.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PersonQueryDto } from '@/domain/dtos/person-query.dto';
|
|
2
|
+
import { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
3
|
+
import { ICacheService } from '@/domain/common/icache.service';
|
|
4
|
+
import { invalidatePersonListCache } from '@/core/utils/person-list-cache';
|
|
5
|
+
import { EventHandlerBase } from '@/core/background-services/event-service/event-handler.base';
|
|
6
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
7
|
+
import { InactivePersonEvent } from './inactive-person.event';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class InactivePersonHandler extends EventHandlerBase<InactivePersonEvent> {
|
|
11
|
+
private readonly logger = new Logger(InactivePersonHandler.name);
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
private readonly repository: IPersonRepository,
|
|
15
|
+
private readonly cache: ICacheService,
|
|
16
|
+
) {
|
|
17
|
+
super(InactivePersonEvent);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async handleEvent(_event: InactivePersonEvent): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
this.logger.log('Recebido evento de inativação de pessoas.');
|
|
23
|
+
this.logger.debug('Iniciando inativação de pessoas ativas...');
|
|
24
|
+
|
|
25
|
+
const query = new PersonQueryDto();
|
|
26
|
+
query.active = true;
|
|
27
|
+
query.limit = 1000;
|
|
28
|
+
query.page = 0;
|
|
29
|
+
|
|
30
|
+
const { items } = await this.repository.findMany(query);
|
|
31
|
+
|
|
32
|
+
if (items.length === 0) {
|
|
33
|
+
this.logger.log('Nenhuma pessoa ativa encontrada.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.logger.debug('Inativando pessoas ativas...', items.length);
|
|
38
|
+
|
|
39
|
+
for (const person of items) {
|
|
40
|
+
person.active = false;
|
|
41
|
+
await this.repository.save(person);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await invalidatePersonListCache(this.cache);
|
|
45
|
+
|
|
46
|
+
this.logger.log('Pessoas inativadas com sucesso.', items.length);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
49
|
+
|
|
50
|
+
this.logger.error(`Erro ao processar evento de inativação: ${message}`);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Person } from '@/domain/entities/person/person';
|
|
2
|
+
import { EventHandlerBase } from '@/core/background-services/event-service/event-handler.base';
|
|
3
|
+
import { EventJob } from '@/core/background-services/event-service/event-job';
|
|
4
|
+
import { Type } from '@nestjs/common';
|
|
5
|
+
import { InactivePersonHandler } from './inactive-person/inactive-person.handler';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Agregado de eventos do domínio Person.
|
|
9
|
+
*
|
|
10
|
+
* `defineHandlers()` é usado pelo `EventQueue` no dispatch para rotear cada
|
|
11
|
+
* evento ao handler correto. Os handlers também precisam estar em
|
|
12
|
+
* `JobsModule.register({ eventHandlers })` para o Nest instanciá-los e chamar
|
|
13
|
+
* `setupSubscriptions()`.
|
|
14
|
+
*/
|
|
15
|
+
export class PersonEventJob extends EventJob<Person> {
|
|
16
|
+
defineHandlers(): Type<EventHandlerBase>[] {
|
|
17
|
+
return [InactivePersonHandler];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const personAddressSchema = (withId = false) =>
|
|
4
|
+
z.object({
|
|
5
|
+
...(withId ? { id: z.number().positive() } : {}),
|
|
6
|
+
address: z.string().min(1),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const personContactSchema = (withId = false) =>
|
|
10
|
+
z.object({
|
|
11
|
+
...(withId ? { id: z.number().positive().optional() } : {}),
|
|
12
|
+
contact: z.string().min(1),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const personBodySchema = (withId = false) =>
|
|
16
|
+
z.object({
|
|
17
|
+
...(withId ? { id: z.number().positive() } : {}),
|
|
18
|
+
name: z.string().min(1),
|
|
19
|
+
address: personAddressSchema(withId),
|
|
20
|
+
contacts: z.array(personContactSchema(withId)),
|
|
21
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RequestHandlerBase } from '@/application/common/request-handler.base';
|
|
2
|
+
import { findPersonOrThrow } from '@/application/person/find-person-or-throw';
|
|
3
|
+
import { AutoMapper } from '@/core/tools/mapping';
|
|
4
|
+
import { Person } from '@/domain/entities/person/person';
|
|
5
|
+
import { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
6
|
+
import { Injectable } from '@nestjs/common';
|
|
7
|
+
import { ReadPersonResponse } from './read-person.response';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class ReadPersonHandler extends RequestHandlerBase<
|
|
11
|
+
number,
|
|
12
|
+
ReadPersonResponse
|
|
13
|
+
> {
|
|
14
|
+
constructor(private readonly repository: IPersonRepository) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async handle(id: number): Promise<ReadPersonResponse> {
|
|
19
|
+
const person = await findPersonOrThrow(this.repository, id);
|
|
20
|
+
return AutoMapper.map(person, Person, ReadPersonResponse);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
2
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
3
|
+
|
|
4
|
+
export class ReadPersonAddressResponse {
|
|
5
|
+
@ApiProperty({ example: 1 })
|
|
6
|
+
@AutoMap()
|
|
7
|
+
id: number;
|
|
8
|
+
|
|
9
|
+
@ApiProperty({ example: '123 Main St' })
|
|
10
|
+
@AutoMap()
|
|
11
|
+
address: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ReadPersonContactResponse {
|
|
15
|
+
@ApiProperty({ example: 1 })
|
|
16
|
+
@AutoMap()
|
|
17
|
+
id: number;
|
|
18
|
+
|
|
19
|
+
@ApiProperty({ example: 'john.doe@example.com' })
|
|
20
|
+
@AutoMap()
|
|
21
|
+
contact: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ReadPersonResponse {
|
|
25
|
+
@ApiProperty({ example: 1 })
|
|
26
|
+
@AutoMap()
|
|
27
|
+
id: number;
|
|
28
|
+
|
|
29
|
+
@ApiProperty({ example: 'John Doe' })
|
|
30
|
+
@AutoMap()
|
|
31
|
+
name: string;
|
|
32
|
+
|
|
33
|
+
@ApiProperty({ example: true })
|
|
34
|
+
@AutoMap()
|
|
35
|
+
active: boolean;
|
|
36
|
+
|
|
37
|
+
@ApiProperty({ type: () => ReadPersonAddressResponse })
|
|
38
|
+
@AutoMap()
|
|
39
|
+
address: ReadPersonAddressResponse;
|
|
40
|
+
|
|
41
|
+
@ApiProperty({ type: () => ReadPersonContactResponse, isArray: true })
|
|
42
|
+
@AutoMap({ type: () => ReadPersonContactResponse })
|
|
43
|
+
contacts: ReadPersonContactResponse[];
|
|
44
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CacheTtlSeconds } from '@/core/constants/cache.constants';
|
|
2
|
+
import { RequestHandlerBase } from '@/application/common/request-handler.base';
|
|
3
|
+
import { AutoMapper } from '@/core/tools/mapping';
|
|
4
|
+
import { buildListCacheKey } from '@/core/utils/build-list-cache-key';
|
|
5
|
+
import { PERSON_LIST_CACHE_PREFIX } from '@/core/utils/person-list-cache';
|
|
6
|
+
import { ICacheService } from '@/domain/common/icache.service';
|
|
7
|
+
import { PersonQueryDto } from '@/domain/dtos/person-query.dto';
|
|
8
|
+
import { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
9
|
+
import { Injectable } from '@nestjs/common';
|
|
10
|
+
import { ReadManyPersonRequest } from './read-many-person.request';
|
|
11
|
+
import {
|
|
12
|
+
ReadManyPersonResponse,
|
|
13
|
+
ReadManyPersonResponseItem,
|
|
14
|
+
} from './read-many-person.response';
|
|
15
|
+
import { ReadManyPersonValidator } from './read-many-person.validator';
|
|
16
|
+
import { Person } from '@/domain/entities/person/person';
|
|
17
|
+
|
|
18
|
+
const PERSON_LIST_CACHE_TTL_SECONDS = CacheTtlSeconds.PERSON_LIST;
|
|
19
|
+
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class ReadManyPersonHandler extends RequestHandlerBase<
|
|
22
|
+
ReadManyPersonRequest,
|
|
23
|
+
ReadManyPersonResponse
|
|
24
|
+
> {
|
|
25
|
+
constructor(
|
|
26
|
+
private readonly repository: IPersonRepository,
|
|
27
|
+
private readonly cache: ICacheService,
|
|
28
|
+
) {
|
|
29
|
+
super();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async handle(req: ReadManyPersonRequest): Promise<ReadManyPersonResponse> {
|
|
33
|
+
const query = AutoMapper.map(
|
|
34
|
+
new ReadManyPersonValidator(req).validate(),
|
|
35
|
+
ReadManyPersonRequest,
|
|
36
|
+
PersonQueryDto,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const cacheKey = buildListCacheKey(PERSON_LIST_CACHE_PREFIX, query);
|
|
40
|
+
const cached = await this.cache.get(cacheKey);
|
|
41
|
+
|
|
42
|
+
if (cached) {
|
|
43
|
+
return ReadManyPersonResponse.from(JSON.parse(cached));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const response = ReadManyPersonResponse.from(
|
|
47
|
+
await this.repository.findMany(query).then((result) => ({
|
|
48
|
+
items: result.items.map((item) =>
|
|
49
|
+
AutoMapper.map(item, Person, ReadManyPersonResponseItem),
|
|
50
|
+
),
|
|
51
|
+
count: result.count,
|
|
52
|
+
})),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
await this.cache.set(
|
|
56
|
+
cacheKey,
|
|
57
|
+
JSON.stringify(response),
|
|
58
|
+
PERSON_LIST_CACHE_TTL_SECONDS,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PaginationRequest } from '@/application/common/pagination.request';
|
|
2
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
3
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
4
|
+
|
|
5
|
+
export class ReadManyPersonRequest extends PaginationRequest {
|
|
6
|
+
@ApiProperty({ required: false })
|
|
7
|
+
@AutoMap()
|
|
8
|
+
name?: string;
|
|
9
|
+
|
|
10
|
+
@ApiProperty({ required: false })
|
|
11
|
+
@AutoMap()
|
|
12
|
+
active?: boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ObjectClass } from '@/core/base/object-class';
|
|
2
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
3
|
+
import { ListResponse } from '@/core/types';
|
|
4
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
5
|
+
|
|
6
|
+
export class ReadManyPersonResponseItem {
|
|
7
|
+
@ApiProperty()
|
|
8
|
+
@AutoMap()
|
|
9
|
+
id: number;
|
|
10
|
+
|
|
11
|
+
@ApiProperty()
|
|
12
|
+
@AutoMap()
|
|
13
|
+
name: string;
|
|
14
|
+
|
|
15
|
+
@ApiProperty()
|
|
16
|
+
@AutoMap()
|
|
17
|
+
active: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ReadManyPersonResponse extends ObjectClass<
|
|
21
|
+
ListResponse<ReadManyPersonResponseItem>
|
|
22
|
+
> {
|
|
23
|
+
@ApiProperty({ type: [ReadManyPersonResponseItem] })
|
|
24
|
+
@AutoMap({ type: () => ReadManyPersonResponseItem })
|
|
25
|
+
items: ReadManyPersonResponseItem[];
|
|
26
|
+
|
|
27
|
+
@ApiProperty()
|
|
28
|
+
@AutoMap()
|
|
29
|
+
count: number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RequestValidatorBase } from '@/application/common/request-validator.base';
|
|
2
|
+
import { booleanSchema, LIST_QUERY_SCHEMA } from '@/core/schemas';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ReadManyPersonRequest } from './read-many-person.request';
|
|
5
|
+
|
|
6
|
+
export class ReadManyPersonValidator extends RequestValidatorBase<ReadManyPersonRequest> {
|
|
7
|
+
protected get schema() {
|
|
8
|
+
return LIST_QUERY_SCHEMA.and(
|
|
9
|
+
z.object({
|
|
10
|
+
name: z.string().optional().nullable(),
|
|
11
|
+
active: booleanSchema(),
|
|
12
|
+
}),
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RequestHandlerBase } from '@/application/common/request-handler.base';
|
|
2
|
+
import { findPersonOrThrow } from '@/application/person/find-person-or-throw';
|
|
3
|
+
import { PersonContact } from '@/domain/entities/person/person-contact';
|
|
4
|
+
import { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
5
|
+
import { Injectable } from '@nestjs/common';
|
|
6
|
+
import { UpdatePersonRequest } from './update-person.request';
|
|
7
|
+
import { UpdatePersonValidator } from './update-person.validator';
|
|
8
|
+
import { ICacheService } from '@/domain/common/icache.service';
|
|
9
|
+
import { invalidatePersonListCache } from '@/core/utils/person-list-cache';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class UpdatePersonHandler extends RequestHandlerBase<
|
|
13
|
+
UpdatePersonRequest,
|
|
14
|
+
void
|
|
15
|
+
> {
|
|
16
|
+
constructor(
|
|
17
|
+
private readonly repository: IPersonRepository,
|
|
18
|
+
private readonly cache: ICacheService,
|
|
19
|
+
) {
|
|
20
|
+
super();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async handle(request: UpdatePersonRequest): Promise<void> {
|
|
24
|
+
const validated = new UpdatePersonValidator(request).validate();
|
|
25
|
+
const person = await findPersonOrThrow(this.repository, validated.id);
|
|
26
|
+
|
|
27
|
+
person.name = validated.name;
|
|
28
|
+
person.address.address = validated.address.address;
|
|
29
|
+
|
|
30
|
+
person.contacts = validated.contacts.map((contactRequest) => {
|
|
31
|
+
if (contactRequest.id) {
|
|
32
|
+
const existing = person.contacts.find(
|
|
33
|
+
(contact) => contact.id === contactRequest.id,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (existing) {
|
|
37
|
+
existing.contact = contactRequest.contact;
|
|
38
|
+
return existing;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const contact = new PersonContact();
|
|
43
|
+
contact.contact = contactRequest.contact;
|
|
44
|
+
contact.person = person;
|
|
45
|
+
return contact;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await this.repository.save(person);
|
|
49
|
+
await invalidatePersonListCache(this.cache);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ObjectClass } from '@/core/base/object-class';
|
|
2
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
3
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
4
|
+
|
|
5
|
+
export class UpdatePersonAddressRequest extends ObjectClass<UpdatePersonAddressRequest> {
|
|
6
|
+
@ApiProperty({ example: 1 })
|
|
7
|
+
@AutoMap()
|
|
8
|
+
id: number;
|
|
9
|
+
|
|
10
|
+
@ApiProperty({ example: '123 Main St' })
|
|
11
|
+
@AutoMap()
|
|
12
|
+
address: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class UpdatePersonContactRequest extends ObjectClass<UpdatePersonContactRequest> {
|
|
16
|
+
@ApiProperty({ example: 1 })
|
|
17
|
+
@AutoMap()
|
|
18
|
+
id: number;
|
|
19
|
+
|
|
20
|
+
@ApiProperty({ example: 'john.doe@example.com' })
|
|
21
|
+
@AutoMap()
|
|
22
|
+
contact: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class UpdatePersonRequest extends ObjectClass<UpdatePersonRequest> {
|
|
26
|
+
@ApiProperty({ example: 1 })
|
|
27
|
+
@AutoMap()
|
|
28
|
+
id: number;
|
|
29
|
+
|
|
30
|
+
@ApiProperty({ example: 'John Doe' })
|
|
31
|
+
@AutoMap()
|
|
32
|
+
name: string;
|
|
33
|
+
|
|
34
|
+
@ApiProperty({ type: () => UpdatePersonAddressRequest })
|
|
35
|
+
@AutoMap()
|
|
36
|
+
address: UpdatePersonAddressRequest;
|
|
37
|
+
|
|
38
|
+
@ApiProperty({ type: () => UpdatePersonContactRequest, isArray: true })
|
|
39
|
+
@AutoMap({ type: () => UpdatePersonContactRequest })
|
|
40
|
+
contacts: UpdatePersonContactRequest[];
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RequestValidatorBase } from '@/application/common/request-validator.base';
|
|
2
|
+
import { personBodySchema } from '@/application/person/person.schemas';
|
|
3
|
+
import { UpdatePersonRequest } from './update-person.request';
|
|
4
|
+
|
|
5
|
+
export class UpdatePersonValidator extends RequestValidatorBase<UpdatePersonRequest> {
|
|
6
|
+
protected get schema() {
|
|
7
|
+
return personBodySchema(true);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UserStatus } from '@/domain/entities/user/enums/user-status.enum';
|
|
2
|
+
import { ForbiddenException } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
type UserWithStatus = { status: UserStatus };
|
|
5
|
+
|
|
6
|
+
export function assertUserIsActive(user: UserWithStatus): void {
|
|
7
|
+
if (user.status === UserStatus.inactive) {
|
|
8
|
+
throw new ForbiddenException('User is inactive');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (user.status === UserStatus.blocked) {
|
|
12
|
+
throw new ForbiddenException('User is blocked');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (user.status === UserStatus.pending) {
|
|
16
|
+
throw new ForbiddenException('User is pending');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AuthProfile } from './auth-profile.enum';
|
|
3
|
+
|
|
4
|
+
export const jwtClaimsSchema = z.object({
|
|
5
|
+
sub: z.string().min(1),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export type JwtClaims = z.infer<typeof jwtClaimsSchema>;
|
|
9
|
+
|
|
10
|
+
export const jwtPayloadSchema = jwtClaimsSchema.extend({
|
|
11
|
+
exp: z.number().optional(),
|
|
12
|
+
iat: z.number().optional(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export type JwtPayload = z.infer<typeof jwtPayloadSchema>;
|
|
16
|
+
|
|
17
|
+
export type AuthenticatedUser = JwtClaims & {
|
|
18
|
+
name?: string;
|
|
19
|
+
profile?: AuthProfile;
|
|
20
|
+
login?: string;
|
|
21
|
+
email?: string;
|
|
22
|
+
refreshToken?: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { EnvService } from '@/infra/common/env.service';
|
|
2
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
export interface OAuthProviderEnvConfig {
|
|
5
|
+
key: string;
|
|
6
|
+
domain?: string;
|
|
7
|
+
clientId: string;
|
|
8
|
+
clientSecret: string;
|
|
9
|
+
scope: string;
|
|
10
|
+
redirectPath?: string;
|
|
11
|
+
authorizationUrl?: string;
|
|
12
|
+
tokenUrl?: string;
|
|
13
|
+
userInfoUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Registry genérico de provedores OAuth2.
|
|
18
|
+
*
|
|
19
|
+
* Suporta **qualquer quantidade** de providers em `OAUTH2_PROVIDERS` (lista separada por vírgula).
|
|
20
|
+
* Para cada CHAVE, configure `OAUTH2_{CHAVE}_*` — google/microsoft no `.env.example` são só exemplos.
|
|
21
|
+
*
|
|
22
|
+
* Provedor OIDC (terceiro): `OAUTH2_{CHAVE}_DOMAIN` → discovery automático.
|
|
23
|
+
* Servidor OAuth próprio: `_AUTHORIZATION_URL`, `_TOKEN_URL`, `_USERINFO_URL` (sem `_DOMAIN`).
|
|
24
|
+
*/
|
|
25
|
+
@Injectable()
|
|
26
|
+
export class OAuthProviderRegistry {
|
|
27
|
+
constructor(private readonly env: EnvService) {}
|
|
28
|
+
|
|
29
|
+
listProviders(): string[] {
|
|
30
|
+
const raw = this.env.get('OAUTH2_PROVIDERS');
|
|
31
|
+
|
|
32
|
+
if (!raw) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return raw
|
|
37
|
+
.split(',')
|
|
38
|
+
.map((item) => item.trim().toLowerCase())
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
listConfiguredProviders(): string[] {
|
|
43
|
+
return this.listProviders().filter((key) => {
|
|
44
|
+
try {
|
|
45
|
+
this.getProvider(key);
|
|
46
|
+
return true;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getProvider(key: string): OAuthProviderEnvConfig {
|
|
54
|
+
const normalizedKey = key.trim().toLowerCase();
|
|
55
|
+
const entry = this.env.get('OAUTH2_PROVIDER_ENV')[normalizedKey];
|
|
56
|
+
const domain = entry?.domain;
|
|
57
|
+
const clientId = entry?.clientId;
|
|
58
|
+
const clientSecret = entry?.clientSecret;
|
|
59
|
+
const scope = entry?.scope;
|
|
60
|
+
const redirectPath = entry?.redirectPath;
|
|
61
|
+
const authorizationUrl = entry?.authorizationUrl;
|
|
62
|
+
const tokenUrl = entry?.tokenUrl;
|
|
63
|
+
const userInfoUrl = entry?.userInfoUrl;
|
|
64
|
+
|
|
65
|
+
const hasManualEndpoints = authorizationUrl && tokenUrl && userInfoUrl;
|
|
66
|
+
const hasDiscoveryDomain = Boolean(domain);
|
|
67
|
+
|
|
68
|
+
if (!clientId || !clientSecret || !scope) {
|
|
69
|
+
const prefix = `OAUTH2_${normalizedKey.toUpperCase()}`;
|
|
70
|
+
throw new NotFoundException(
|
|
71
|
+
`Provedor OAuth2 "${normalizedKey}" não configurado. Verifique variáveis ${prefix}_* no .env`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!hasManualEndpoints && !hasDiscoveryDomain) {
|
|
76
|
+
const prefix = `OAUTH2_${normalizedKey.toUpperCase()}`;
|
|
77
|
+
throw new NotFoundException(
|
|
78
|
+
`Provedor OAuth2 "${normalizedKey}" incompleto. Defina ${prefix}_DOMAIN (OIDC) ou ${prefix}_AUTHORIZATION_URL, ${prefix}_TOKEN_URL e ${prefix}_USERINFO_URL`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
key: normalizedKey,
|
|
84
|
+
domain,
|
|
85
|
+
clientId,
|
|
86
|
+
clientSecret,
|
|
87
|
+
scope,
|
|
88
|
+
redirectPath: redirectPath ?? '/sso/callback',
|
|
89
|
+
authorizationUrl,
|
|
90
|
+
tokenUrl,
|
|
91
|
+
userInfoUrl,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|