@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,201 @@
|
|
|
1
|
+
import { ZodError } from 'zod';
|
|
2
|
+
|
|
3
|
+
type ZodValidationIssue = ZodError['issues'][number];
|
|
4
|
+
|
|
5
|
+
export interface ZodFieldError {
|
|
6
|
+
field: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FormattedZodError {
|
|
11
|
+
message: string;
|
|
12
|
+
errors: ZodFieldError[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const TYPE_LABELS: Record<string, string> = {
|
|
16
|
+
string: 'texto',
|
|
17
|
+
number: 'número',
|
|
18
|
+
int: 'número inteiro',
|
|
19
|
+
boolean: 'booleano',
|
|
20
|
+
array: 'lista',
|
|
21
|
+
object: 'objeto',
|
|
22
|
+
undefined: 'indefinido',
|
|
23
|
+
null: 'nulo',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function formatFieldPath(path: PropertyKey[]): string {
|
|
27
|
+
return path.reduce<string>((acc, segment) => {
|
|
28
|
+
if (typeof segment === 'number') {
|
|
29
|
+
return `${acc}[${segment}]`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const segmentLabel = String(segment);
|
|
33
|
+
|
|
34
|
+
return acc ? `${acc}.${segmentLabel}` : segmentLabel;
|
|
35
|
+
}, '');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function formatFieldLabel(field: string): string {
|
|
39
|
+
return field || 'valor';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getExpectedTypeLabel(expected: string): string {
|
|
43
|
+
return TYPE_LABELS[expected] ?? expected;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getReceivedTypeLabel(message: string): string | undefined {
|
|
47
|
+
const match = message.match(/received (\w+)/i);
|
|
48
|
+
if (!match) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return getExpectedTypeLabel(match[1].toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function formatLimitValue(value: number | bigint | undefined): number {
|
|
56
|
+
if (typeof value === 'bigint') {
|
|
57
|
+
return Number(value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return value ?? 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function formatTooSmallMessage(
|
|
64
|
+
fieldLabel: string,
|
|
65
|
+
issue: ZodValidationIssue,
|
|
66
|
+
): string {
|
|
67
|
+
if (issue.code !== 'too_small') {
|
|
68
|
+
return `O campo ${fieldLabel} possui um valor muito pequeno.`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const minimum = formatLimitValue(issue.minimum);
|
|
72
|
+
|
|
73
|
+
if (issue.origin === 'string') {
|
|
74
|
+
if (minimum <= 1) {
|
|
75
|
+
return `O campo ${fieldLabel} é obrigatório.`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return `O campo ${fieldLabel} deve ter no mínimo ${minimum} caracteres.`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (issue.origin === 'number') {
|
|
82
|
+
if (issue.inclusive === false) {
|
|
83
|
+
return `O campo ${fieldLabel} deve ser maior que ${minimum}.`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return `O campo ${fieldLabel} deve ser no mínimo ${minimum}.`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (issue.origin === 'array') {
|
|
90
|
+
if (minimum <= 1) {
|
|
91
|
+
return `O campo ${fieldLabel} deve conter ao menos um item.`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return `O campo ${fieldLabel} deve conter no mínimo ${minimum} itens.`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return `O campo ${fieldLabel} possui um valor muito pequeno.`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function formatTooBigMessage(
|
|
101
|
+
fieldLabel: string,
|
|
102
|
+
issue: ZodValidationIssue,
|
|
103
|
+
): string {
|
|
104
|
+
if (issue.code !== 'too_big') {
|
|
105
|
+
return `O campo ${fieldLabel} possui um valor muito grande.`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const maximum = formatLimitValue(issue.maximum);
|
|
109
|
+
|
|
110
|
+
if (issue.origin === 'string') {
|
|
111
|
+
return `O campo ${fieldLabel} deve ter no máximo ${maximum} caracteres.`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (issue.origin === 'number') {
|
|
115
|
+
return `O campo ${fieldLabel} deve ser no máximo ${maximum}.`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (issue.origin === 'array') {
|
|
119
|
+
return `O campo ${fieldLabel} deve conter no máximo ${maximum} itens.`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return `O campo ${fieldLabel} possui um valor muito grande.`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function formatInvalidTypeMessage(
|
|
126
|
+
fieldLabel: string,
|
|
127
|
+
issue: ZodValidationIssue,
|
|
128
|
+
): string {
|
|
129
|
+
if (issue.code !== 'invalid_type') {
|
|
130
|
+
return `O campo ${fieldLabel} possui um valor inválido.`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const expected = issue.expected
|
|
134
|
+
? getExpectedTypeLabel(issue.expected)
|
|
135
|
+
: 'válido';
|
|
136
|
+
const received = getReceivedTypeLabel(issue.message);
|
|
137
|
+
|
|
138
|
+
if (issue.expected === 'undefined' || received === 'indefinido') {
|
|
139
|
+
return `O campo ${fieldLabel} é obrigatório.`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (received) {
|
|
143
|
+
return `O campo ${fieldLabel} deve ser ${expected}, mas foi recebido ${received}.`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return `O campo ${fieldLabel} deve ser ${expected}.`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function formatInvalidFormatMessage(
|
|
150
|
+
fieldLabel: string,
|
|
151
|
+
issue: ZodValidationIssue,
|
|
152
|
+
): string {
|
|
153
|
+
if (issue.code !== 'invalid_format') {
|
|
154
|
+
return `O campo ${fieldLabel} está em um formato inválido.`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
switch (issue.format) {
|
|
158
|
+
case 'email':
|
|
159
|
+
return `O campo ${fieldLabel} deve ser um e-mail válido.`;
|
|
160
|
+
case 'uuid':
|
|
161
|
+
return `O campo ${fieldLabel} deve ser um UUID válido.`;
|
|
162
|
+
case 'url':
|
|
163
|
+
return `O campo ${fieldLabel} deve ser uma URL válida.`;
|
|
164
|
+
default:
|
|
165
|
+
return `O campo ${fieldLabel} está em um formato inválido.`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function formatIssueMessage(issue: ZodValidationIssue): string {
|
|
170
|
+
const field = formatFieldPath(issue.path);
|
|
171
|
+
const fieldLabel = formatFieldLabel(field);
|
|
172
|
+
|
|
173
|
+
switch (issue.code) {
|
|
174
|
+
case 'too_small':
|
|
175
|
+
return formatTooSmallMessage(fieldLabel, issue);
|
|
176
|
+
case 'too_big':
|
|
177
|
+
return formatTooBigMessage(fieldLabel, issue);
|
|
178
|
+
case 'invalid_type':
|
|
179
|
+
return formatInvalidTypeMessage(fieldLabel, issue);
|
|
180
|
+
case 'invalid_format':
|
|
181
|
+
return formatInvalidFormatMessage(fieldLabel, issue);
|
|
182
|
+
case 'invalid_value':
|
|
183
|
+
return `O campo ${fieldLabel} possui um valor inválido.`;
|
|
184
|
+
default:
|
|
185
|
+
return `O campo ${fieldLabel} possui um valor inválido.`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function formatZodError(error: ZodError): FormattedZodError {
|
|
190
|
+
const errors = error.issues.map((issue) => ({
|
|
191
|
+
field: formatFieldPath(issue.path),
|
|
192
|
+
message: formatIssueMessage(issue),
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
const message =
|
|
196
|
+
errors.length === 1
|
|
197
|
+
? errors[0].message
|
|
198
|
+
: `Foram encontrados ${errors.length} erros de validação.`;
|
|
199
|
+
|
|
200
|
+
return { message, errors };
|
|
201
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type IComparableId = string | number;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { INestApplication, type InjectionToken } from '@nestjs/common';
|
|
2
|
+
import { ModulesContainer } from '@nestjs/core';
|
|
3
|
+
|
|
4
|
+
export function isProviderRegistered(
|
|
5
|
+
app: INestApplication,
|
|
6
|
+
token: InjectionToken,
|
|
7
|
+
): boolean {
|
|
8
|
+
const modulesContainer = app.get(ModulesContainer);
|
|
9
|
+
|
|
10
|
+
return [...modulesContainer.values()].some(
|
|
11
|
+
(module) => module?.providers?.has(token) ?? false,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function resolveAppProvider<T>(
|
|
16
|
+
app: INestApplication,
|
|
17
|
+
token: InjectionToken,
|
|
18
|
+
): T | undefined {
|
|
19
|
+
try {
|
|
20
|
+
const resolved = app.get<T>(token, { strict: false });
|
|
21
|
+
|
|
22
|
+
if (resolved) {
|
|
23
|
+
return resolved;
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
// provider ausente neste contexto
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const modulesContainer = app.get(ModulesContainer);
|
|
30
|
+
|
|
31
|
+
for (const moduleRef of modulesContainer.values()) {
|
|
32
|
+
const provider = moduleRef.providers.get(token);
|
|
33
|
+
|
|
34
|
+
if (provider?.instance) {
|
|
35
|
+
return provider.instance as T;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IUserRepository } from '@/domain/repositories/iuser.repository';
|
|
2
|
+
import { randomString } from '@koalarx/utils';
|
|
3
|
+
|
|
4
|
+
export async function nameToLogin(
|
|
5
|
+
value: string,
|
|
6
|
+
userRepository: IUserRepository,
|
|
7
|
+
) {
|
|
8
|
+
const firstNameAndLast = value.split(/(\s).+\s/).join('');
|
|
9
|
+
const username = firstNameAndLast.toLowerCase().replace(/ /g, '.');
|
|
10
|
+
|
|
11
|
+
let usernameExists = false;
|
|
12
|
+
let result = username;
|
|
13
|
+
|
|
14
|
+
do {
|
|
15
|
+
usernameExists = await userRepository
|
|
16
|
+
.getByLogin(result)
|
|
17
|
+
.then((user) => !!user);
|
|
18
|
+
|
|
19
|
+
if (usernameExists) {
|
|
20
|
+
result = username.concat('#').concat(randomString(4, { numbers: true }));
|
|
21
|
+
}
|
|
22
|
+
} while (usernameExists);
|
|
23
|
+
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import packageJson from '../../../package.json';
|
|
2
|
+
import { ILoggingService } from '@/domain/common/ilogging.service';
|
|
3
|
+
|
|
4
|
+
export async function reportErrorToLogging(
|
|
5
|
+
loggingService: ILoggingService,
|
|
6
|
+
error: Error,
|
|
7
|
+
loggedUsername?: string,
|
|
8
|
+
): Promise<void> {
|
|
9
|
+
try {
|
|
10
|
+
await loggingService.report({
|
|
11
|
+
error,
|
|
12
|
+
packageName: packageJson.name,
|
|
13
|
+
loggedUsername: loggedUsername ?? 'system',
|
|
14
|
+
});
|
|
15
|
+
} catch {
|
|
16
|
+
console.error(error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function resolveApiHost(host: string | undefined, port: number): string {
|
|
2
|
+
const rawHost = host ?? `http://localhost:${port}`;
|
|
3
|
+
const normalized = rawHost.replace(/\/$/, '');
|
|
4
|
+
const hasProtocol =
|
|
5
|
+
normalized.startsWith('http://') || normalized.startsWith('https://');
|
|
6
|
+
|
|
7
|
+
return hasProtocol ? normalized : `http://${normalized}`;
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ObjectClass } from '@/core/base/object-class';
|
|
2
|
+
|
|
3
|
+
export class AuthProviderConfigDto extends ObjectClass<AuthProviderConfigDto> {
|
|
4
|
+
authorizationUrl: string;
|
|
5
|
+
tokenUrl: string;
|
|
6
|
+
userInfoUrl: string;
|
|
7
|
+
clientId: string;
|
|
8
|
+
clientSecret: string;
|
|
9
|
+
state: string;
|
|
10
|
+
redirectUri: string;
|
|
11
|
+
scope: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthProfile } from '@/core/auth/auth-profile.enum';
|
|
2
|
+
import { ObjectClass } from '@/core/base/object-class';
|
|
3
|
+
|
|
4
|
+
export class OAuthUserInfoDto extends ObjectClass<OAuthUserInfoDto> {
|
|
5
|
+
login: string;
|
|
6
|
+
email: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
profile?: AuthProfile;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { JwtClaims } from '@/core/auth/jwt-claims';
|
|
2
|
+
import { AuthProviderConfigDto } from '../dtos/auth-provider-config.dto';
|
|
3
|
+
import { OAuthUserInfoDto } from '../dtos/oauth-user-info.dto';
|
|
4
|
+
|
|
5
|
+
export abstract class IOAuth2Service {
|
|
6
|
+
abstract providerConfig(provider: string): Promise<AuthProviderConfigDto>;
|
|
7
|
+
abstract authLink(provider: string, redirectUri?: string): Promise<string>;
|
|
8
|
+
abstract resolveScalarOAuthFlow(provider: string): Promise<{
|
|
9
|
+
authorizationUrl: string;
|
|
10
|
+
redirectUri: string;
|
|
11
|
+
clientId: string;
|
|
12
|
+
clientSecret: string;
|
|
13
|
+
}>;
|
|
14
|
+
abstract exchangeCode(
|
|
15
|
+
provider: string,
|
|
16
|
+
code: string,
|
|
17
|
+
state: string,
|
|
18
|
+
redirectUri?: string,
|
|
19
|
+
): Promise<OAuthUserInfoDto>;
|
|
20
|
+
/** Troca authorization code do Scalar (sem validar state — o IdP já validou). */
|
|
21
|
+
abstract exchangeScalarCode(
|
|
22
|
+
provider: string,
|
|
23
|
+
code: string,
|
|
24
|
+
redirectUri?: string,
|
|
25
|
+
): Promise<OAuthUserInfoDto>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export abstract class IJwtTokenService {
|
|
29
|
+
abstract signAccessToken(claims: JwtClaims): string;
|
|
30
|
+
abstract signRefreshToken(claims: JwtClaims): string;
|
|
31
|
+
abstract signTokenPair(claims: JwtClaims): {
|
|
32
|
+
accessToken: string;
|
|
33
|
+
access_token: string;
|
|
34
|
+
refreshToken: string;
|
|
35
|
+
refresh_token: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export abstract class ICacheService {
|
|
2
|
+
abstract get(key: string): Promise<string | null>;
|
|
3
|
+
abstract set(key: string, value: string, ttl?: number): Promise<void>;
|
|
4
|
+
abstract setIfNotExists(
|
|
5
|
+
key: string,
|
|
6
|
+
value: string,
|
|
7
|
+
ttl: number,
|
|
8
|
+
): Promise<boolean>;
|
|
9
|
+
abstract invalidate(key: string): Promise<void>;
|
|
10
|
+
abstract invalidateByPrefix(prefix: string): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AuthProfile } from '@/core/auth/auth-profile.enum';
|
|
2
|
+
import { AuthenticatedUser } from '@/core/auth/jwt-claims';
|
|
3
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
4
|
+
|
|
5
|
+
export class LoggedUserInfoDto {
|
|
6
|
+
@AutoMap()
|
|
7
|
+
sub: string;
|
|
8
|
+
|
|
9
|
+
@AutoMap()
|
|
10
|
+
name?: string;
|
|
11
|
+
|
|
12
|
+
@AutoMap()
|
|
13
|
+
profile?: AuthProfile;
|
|
14
|
+
|
|
15
|
+
@AutoMap()
|
|
16
|
+
login?: string;
|
|
17
|
+
|
|
18
|
+
@AutoMap()
|
|
19
|
+
email?: string;
|
|
20
|
+
|
|
21
|
+
static fromAuthenticatedUser(user: AuthenticatedUser): LoggedUserInfoDto {
|
|
22
|
+
return Object.assign(new LoggedUserInfoDto(), {
|
|
23
|
+
sub: user.sub,
|
|
24
|
+
name: user.name,
|
|
25
|
+
profile: user.profile,
|
|
26
|
+
login: user.login,
|
|
27
|
+
email: user.email,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { QUERY_FILTER_PARAMS } from '@/core/constants/query-params';
|
|
2
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
3
|
+
import type { QueryDirectionType } from '@/core/types';
|
|
4
|
+
|
|
5
|
+
export class PaginationDto {
|
|
6
|
+
@AutoMap()
|
|
7
|
+
page?: number = 0;
|
|
8
|
+
|
|
9
|
+
@AutoMap()
|
|
10
|
+
limit?: number = QUERY_FILTER_PARAMS.limit;
|
|
11
|
+
|
|
12
|
+
@AutoMap()
|
|
13
|
+
orderBy?: string = '';
|
|
14
|
+
|
|
15
|
+
@AutoMap()
|
|
16
|
+
direction?: QueryDirectionType = 'asc';
|
|
17
|
+
|
|
18
|
+
skip() {
|
|
19
|
+
return (this.limit ?? 0) * (this.page ?? QUERY_FILTER_PARAMS.page);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
generateOrderBy() {
|
|
23
|
+
if (this.orderBy) {
|
|
24
|
+
const orderByField = this.orderBy.split('.');
|
|
25
|
+
return orderByField.reduceRight(
|
|
26
|
+
(acc, item, index) => ({
|
|
27
|
+
[item]: index === orderByField.length - 1 ? this.direction : acc,
|
|
28
|
+
}),
|
|
29
|
+
{},
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EntityBase } from '@/core/base/entity.base';
|
|
2
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
3
|
+
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
4
|
+
|
|
5
|
+
@Entity('person_address')
|
|
6
|
+
export class PersonAddress extends EntityBase<PersonAddress> {
|
|
7
|
+
@PrimaryGeneratedColumn()
|
|
8
|
+
@AutoMap()
|
|
9
|
+
id: number;
|
|
10
|
+
|
|
11
|
+
@Column()
|
|
12
|
+
@AutoMap()
|
|
13
|
+
address: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
Entity,
|
|
5
|
+
ManyToOne,
|
|
6
|
+
PrimaryGeneratedColumn,
|
|
7
|
+
type Relation,
|
|
8
|
+
} from 'typeorm';
|
|
9
|
+
import type { Person } from './person';
|
|
10
|
+
import { EntityBase } from '@/core/base/entity.base';
|
|
11
|
+
|
|
12
|
+
@Entity('person_contact')
|
|
13
|
+
export class PersonContact extends EntityBase<PersonContact> {
|
|
14
|
+
@PrimaryGeneratedColumn()
|
|
15
|
+
@AutoMap()
|
|
16
|
+
id: number;
|
|
17
|
+
|
|
18
|
+
@Column()
|
|
19
|
+
@AutoMap()
|
|
20
|
+
contact: string;
|
|
21
|
+
|
|
22
|
+
@ManyToOne('Person', 'contacts', {
|
|
23
|
+
onDelete: 'CASCADE',
|
|
24
|
+
orphanedRowAction: 'delete',
|
|
25
|
+
})
|
|
26
|
+
@AutoMap()
|
|
27
|
+
person: Relation<Person>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
Entity,
|
|
5
|
+
JoinColumn,
|
|
6
|
+
OneToMany,
|
|
7
|
+
OneToOne,
|
|
8
|
+
PrimaryGeneratedColumn,
|
|
9
|
+
} from 'typeorm';
|
|
10
|
+
import { PersonAddress } from './person-address';
|
|
11
|
+
import { PersonContact } from './person-contact';
|
|
12
|
+
import { EntityBase } from '@/core/base/entity.base';
|
|
13
|
+
|
|
14
|
+
@Entity('person')
|
|
15
|
+
export class Person extends EntityBase<Person> {
|
|
16
|
+
@PrimaryGeneratedColumn()
|
|
17
|
+
@AutoMap()
|
|
18
|
+
id: number;
|
|
19
|
+
|
|
20
|
+
@Column()
|
|
21
|
+
@AutoMap()
|
|
22
|
+
name: string;
|
|
23
|
+
|
|
24
|
+
@Column({ default: true })
|
|
25
|
+
@AutoMap()
|
|
26
|
+
active: boolean;
|
|
27
|
+
|
|
28
|
+
@OneToOne(() => PersonAddress, {
|
|
29
|
+
cascade: true,
|
|
30
|
+
eager: true,
|
|
31
|
+
onDelete: 'CASCADE',
|
|
32
|
+
})
|
|
33
|
+
@JoinColumn()
|
|
34
|
+
@AutoMap()
|
|
35
|
+
address: PersonAddress;
|
|
36
|
+
|
|
37
|
+
@OneToMany(() => PersonContact, (contact) => contact.person, {
|
|
38
|
+
cascade: true,
|
|
39
|
+
eager: true,
|
|
40
|
+
onDelete: 'CASCADE',
|
|
41
|
+
})
|
|
42
|
+
@AutoMap({ type: () => PersonContact })
|
|
43
|
+
contacts: PersonContact[];
|
|
44
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AuthProfile } from '@/core/auth/auth-profile.enum';
|
|
2
|
+
import { EntityBase } from '@/core/base/entity.base';
|
|
3
|
+
import { AutoMap } from '@/core/tools/mapping';
|
|
4
|
+
import { UserStatus } from '@/domain/entities/user/enums/user-status.enum';
|
|
5
|
+
import {
|
|
6
|
+
Column,
|
|
7
|
+
CreateDateColumn,
|
|
8
|
+
Entity,
|
|
9
|
+
PrimaryGeneratedColumn,
|
|
10
|
+
UpdateDateColumn,
|
|
11
|
+
} from 'typeorm';
|
|
12
|
+
|
|
13
|
+
@Entity('users')
|
|
14
|
+
export class User extends EntityBase<User> {
|
|
15
|
+
@PrimaryGeneratedColumn('uuid')
|
|
16
|
+
@AutoMap()
|
|
17
|
+
id: string;
|
|
18
|
+
|
|
19
|
+
@Column()
|
|
20
|
+
@AutoMap()
|
|
21
|
+
name: string;
|
|
22
|
+
|
|
23
|
+
@Column({ unique: true })
|
|
24
|
+
@AutoMap()
|
|
25
|
+
email: string;
|
|
26
|
+
|
|
27
|
+
@Column({ unique: true })
|
|
28
|
+
@AutoMap()
|
|
29
|
+
login: string;
|
|
30
|
+
|
|
31
|
+
@Column()
|
|
32
|
+
password: string;
|
|
33
|
+
|
|
34
|
+
@Column({ type: 'varchar' })
|
|
35
|
+
@AutoMap()
|
|
36
|
+
profile: AuthProfile;
|
|
37
|
+
|
|
38
|
+
@Column({ type: 'varchar', default: UserStatus.active })
|
|
39
|
+
@AutoMap()
|
|
40
|
+
status: UserStatus;
|
|
41
|
+
|
|
42
|
+
@CreateDateColumn()
|
|
43
|
+
@AutoMap()
|
|
44
|
+
createdAt: Date;
|
|
45
|
+
|
|
46
|
+
@UpdateDateColumn()
|
|
47
|
+
@AutoMap()
|
|
48
|
+
updatedAt: Date;
|
|
49
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ListResponse } from '@/core/types';
|
|
2
|
+
import { PersonQueryDto } from '../dtos/person-query.dto';
|
|
3
|
+
import { Person } from '../entities/person/person';
|
|
4
|
+
|
|
5
|
+
export abstract class IPersonRepository {
|
|
6
|
+
abstract findMany(query: PersonQueryDto): Promise<ListResponse<Person>>;
|
|
7
|
+
abstract findById(id: number): Promise<Person | null>;
|
|
8
|
+
abstract save(person: Person): Promise<Person>;
|
|
9
|
+
abstract delete(person: Person): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { User } from '@/domain/entities/user/user';
|
|
2
|
+
|
|
3
|
+
export abstract class IUserRepository {
|
|
4
|
+
abstract getById(id: string): Promise<User | null>;
|
|
5
|
+
abstract getByEmail(email: string): Promise<User | null>;
|
|
6
|
+
abstract getByLogin(login: string): Promise<User | null>;
|
|
7
|
+
abstract save(user: User): Promise<User>;
|
|
8
|
+
}
|