@koalarx/nest 3.1.50 → 4.0.1
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 +106 -444
- 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,46 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { NotFoundException } from '@nestjs/common';
|
|
3
|
+
import { DeletePersonHandler } from '@/application/person/delete/delete-person.handler';
|
|
4
|
+
import { Person } from '@/domain/entities/person/person';
|
|
5
|
+
import { PERSON_LIST_CACHE_PREFIX } from '@/core/utils/person-list-cache';
|
|
6
|
+
import type { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
7
|
+
import { CacheStub } from '@/test/services/cache.stub';
|
|
8
|
+
|
|
9
|
+
describe('DeletePersonHandler', () => {
|
|
10
|
+
it('remove pessoa existente e invalida cache', async () => {
|
|
11
|
+
const cache = new CacheStub();
|
|
12
|
+
const person = Person.from({
|
|
13
|
+
id: 1,
|
|
14
|
+
name: 'Jane',
|
|
15
|
+
active: true,
|
|
16
|
+
address: undefined,
|
|
17
|
+
contacts: [],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const deleted: Person[] = [];
|
|
21
|
+
|
|
22
|
+
const repository = {
|
|
23
|
+
findById: async () => person,
|
|
24
|
+
delete: async (entity: Person) => {
|
|
25
|
+
deleted.push(entity);
|
|
26
|
+
},
|
|
27
|
+
} as unknown as IPersonRepository;
|
|
28
|
+
|
|
29
|
+
const handler = new DeletePersonHandler(repository, cache);
|
|
30
|
+
await handler.handle(1);
|
|
31
|
+
|
|
32
|
+
expect(deleted).toEqual([person]);
|
|
33
|
+
expect(cache.invalidateByPrefixCalls).toEqual([PERSON_LIST_CACHE_PREFIX]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('lança NotFoundException quando a pessoa não existe', async () => {
|
|
37
|
+
const repository = {
|
|
38
|
+
findById: async () => null,
|
|
39
|
+
delete: async () => undefined,
|
|
40
|
+
} as unknown as IPersonRepository;
|
|
41
|
+
|
|
42
|
+
const handler = new DeletePersonHandler(repository, new CacheStub());
|
|
43
|
+
|
|
44
|
+
await expect(handler.handle(99)).rejects.toBeInstanceOf(NotFoundException);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { AuthProfile } from '@/core/auth/auth-profile.enum';
|
|
3
|
+
import { OAuthExchangeCodeHandler } from '@/application/auth/oauth2/exchange-code/exchange-code.handler';
|
|
4
|
+
import { UserStatus } from '@/domain/entities/user/enums/user-status.enum';
|
|
5
|
+
import { User } from '@/domain/entities/user/user';
|
|
6
|
+
import type {
|
|
7
|
+
IOAuth2Service,
|
|
8
|
+
IJwtTokenService,
|
|
9
|
+
} from '@/domain/auth/services/iauth.service';
|
|
10
|
+
import type { IUserRepository } from '@/domain/repositories/iuser.repository';
|
|
11
|
+
|
|
12
|
+
describe('OAuthExchangeCodeHandler', () => {
|
|
13
|
+
it('cria usuário quando necessário e retorna par de tokens JWT', async () => {
|
|
14
|
+
const oauth2Service = {
|
|
15
|
+
exchangeCode: async (provider: string, code: string, state: string) => ({
|
|
16
|
+
email: `${provider}-${code}@example.com`,
|
|
17
|
+
login: state,
|
|
18
|
+
name: 'OAuth User',
|
|
19
|
+
profile: AuthProfile.user,
|
|
20
|
+
}),
|
|
21
|
+
} as IOAuth2Service;
|
|
22
|
+
|
|
23
|
+
const savedUser = Object.assign(new User(), {
|
|
24
|
+
id: 'user-oauth-1',
|
|
25
|
+
email: 'google-auth-code@example.com',
|
|
26
|
+
login: 'oauth.user',
|
|
27
|
+
name: 'OAuth User',
|
|
28
|
+
profile: AuthProfile.user,
|
|
29
|
+
status: UserStatus.active,
|
|
30
|
+
password: 'hashed',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const userRepository = {
|
|
34
|
+
getByEmail: async () => null,
|
|
35
|
+
getByLogin: async () => null,
|
|
36
|
+
save: async (user: User) => {
|
|
37
|
+
Object.assign(savedUser, user, { id: 'user-oauth-1' });
|
|
38
|
+
return savedUser;
|
|
39
|
+
},
|
|
40
|
+
} as unknown as IUserRepository;
|
|
41
|
+
|
|
42
|
+
const jwtTokenService = {
|
|
43
|
+
signTokenPair: (claims: { sub: string }) => ({
|
|
44
|
+
accessToken: `access-${claims.sub}`,
|
|
45
|
+
refreshToken: `refresh-${claims.sub}`,
|
|
46
|
+
}),
|
|
47
|
+
} as unknown as IJwtTokenService;
|
|
48
|
+
|
|
49
|
+
const handler = new OAuthExchangeCodeHandler(
|
|
50
|
+
oauth2Service,
|
|
51
|
+
userRepository,
|
|
52
|
+
jwtTokenService,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const result = await handler.handle({
|
|
56
|
+
provider: 'google',
|
|
57
|
+
code: 'auth-code',
|
|
58
|
+
state: 'csrf-state',
|
|
59
|
+
redirectUri: 'http://localhost/callback',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(result).toEqual({
|
|
63
|
+
accessToken: 'access-user-oauth-1',
|
|
64
|
+
refreshToken: 'refresh-user-oauth-1',
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { InactivePersonHandler } from '@/application/person/jobs/events/person/inactive-person/inactive-person.handler';
|
|
3
|
+
import { InactivePersonEvent } from '@/application/person/jobs/events/person/inactive-person/inactive-person.event';
|
|
4
|
+
import { Person } from '@/domain/entities/person/person';
|
|
5
|
+
import { PersonAddress } from '@/domain/entities/person/person-address';
|
|
6
|
+
import { PERSON_LIST_CACHE_PREFIX } from '@/core/utils/person-list-cache';
|
|
7
|
+
import type { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
8
|
+
import { CacheStub } from '@/test/services/cache.stub';
|
|
9
|
+
|
|
10
|
+
describe('InactivePersonHandler', () => {
|
|
11
|
+
it('inativa todas as pessoas ativas e invalida cache', async () => {
|
|
12
|
+
const cache = new CacheStub();
|
|
13
|
+
const activePerson = Person.from({
|
|
14
|
+
id: 1,
|
|
15
|
+
name: 'Jane',
|
|
16
|
+
active: true,
|
|
17
|
+
address: PersonAddress.from({ id: 1, address: 'Street' }),
|
|
18
|
+
contacts: [],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const calls = {
|
|
22
|
+
findMany: [] as Parameters<IPersonRepository['findMany']>,
|
|
23
|
+
save: [] as Person[],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const repository = {
|
|
27
|
+
findMany: async (query: Parameters<IPersonRepository['findMany']>[0]) => {
|
|
28
|
+
calls.findMany.push(query);
|
|
29
|
+
return { items: [activePerson], count: 1 };
|
|
30
|
+
},
|
|
31
|
+
findById: async () => null,
|
|
32
|
+
save: async (person: Person) => {
|
|
33
|
+
calls.save.push(person);
|
|
34
|
+
return person;
|
|
35
|
+
},
|
|
36
|
+
delete: async () => undefined,
|
|
37
|
+
} as unknown as IPersonRepository;
|
|
38
|
+
|
|
39
|
+
const handler = new InactivePersonHandler(repository, cache);
|
|
40
|
+
|
|
41
|
+
await handler.handleEvent(new InactivePersonEvent());
|
|
42
|
+
|
|
43
|
+
expect(calls.findMany[0]?.active).toBe(true);
|
|
44
|
+
expect(activePerson.active).toBe(false);
|
|
45
|
+
expect(calls.save).toEqual([activePerson]);
|
|
46
|
+
expect(cache.invalidateByPrefixCalls).toEqual([PERSON_LIST_CACHE_PREFIX]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AuthProfile } from '@/core/auth/auth-profile.enum';
|
|
2
|
+
import { describe, expect, it } from 'bun:test';
|
|
3
|
+
import { LoginHandler } from '@/application/auth/login/login.handler';
|
|
4
|
+
import { UserStatus } from '@/domain/entities/user/enums/user-status.enum';
|
|
5
|
+
import { User } from '@/domain/entities/user/user';
|
|
6
|
+
import { IUserRepository } from '@/domain/repositories/iuser.repository';
|
|
7
|
+
import { IJwtTokenService } from '@/domain/auth/services/iauth.service';
|
|
8
|
+
import { UnauthorizedException } from '@nestjs/common';
|
|
9
|
+
|
|
10
|
+
describe('LoginHandler', () => {
|
|
11
|
+
const user = Object.assign(new User(), {
|
|
12
|
+
id: 'user-123',
|
|
13
|
+
email: 'admin@example.com',
|
|
14
|
+
login: 'admin.demo',
|
|
15
|
+
password: '$2b$06$eyA412UuUAPsAOBREzXPue1AJW.GLAwjenHRSBVCc1.gB1AcASWo6',
|
|
16
|
+
profile: AuthProfile.admin,
|
|
17
|
+
status: UserStatus.active,
|
|
18
|
+
name: 'Admin Demo',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const userRepository = {
|
|
22
|
+
getByEmail: async (email: string) =>
|
|
23
|
+
email === 'admin@example.com' ? user : null,
|
|
24
|
+
} as unknown as IUserRepository;
|
|
25
|
+
|
|
26
|
+
const jwtTokenService = {
|
|
27
|
+
signTokenPair: (claims: { sub: string }) => ({
|
|
28
|
+
accessToken: `access-${claims.sub}`,
|
|
29
|
+
refreshToken: `refresh-${claims.sub}`,
|
|
30
|
+
}),
|
|
31
|
+
} as unknown as IJwtTokenService;
|
|
32
|
+
|
|
33
|
+
const handler = new LoginHandler(userRepository, jwtTokenService);
|
|
34
|
+
|
|
35
|
+
it('gera par de tokens com credenciais válidas', async () => {
|
|
36
|
+
const result = await handler.handle({
|
|
37
|
+
username: 'admin@example.com',
|
|
38
|
+
password: 'admin123',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(result).toEqual({
|
|
42
|
+
accessToken: 'access-user-123',
|
|
43
|
+
refreshToken: 'refresh-user-123',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('rejeita credenciais inválidas', async () => {
|
|
48
|
+
await expect(
|
|
49
|
+
handler.handle({
|
|
50
|
+
username: 'admin@example.com',
|
|
51
|
+
password: 'wrong-password',
|
|
52
|
+
}),
|
|
53
|
+
).rejects.toThrow(UnauthorizedException);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, expect, it, beforeAll } from 'bun:test';
|
|
2
|
+
import { ReadManyPersonHandler } from '@/application/person/read-many/read-many-person.handler';
|
|
3
|
+
import { ReadManyPersonRequest } from '@/application/person/read-many/read-many-person.request';
|
|
4
|
+
import { PersonMapper } from '@/application/mapping/person.mapper';
|
|
5
|
+
import { Person } from '@/domain/entities/person/person';
|
|
6
|
+
import { PersonAddress } from '@/domain/entities/person/person-address';
|
|
7
|
+
import type { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
8
|
+
import { CacheStub } from '@/test/services/cache.stub';
|
|
9
|
+
|
|
10
|
+
describe('ReadManyPersonHandler', () => {
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
PersonMapper.createMap();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('lista pessoas com paginação mapeada', async () => {
|
|
16
|
+
const person = Person.from({
|
|
17
|
+
id: 1,
|
|
18
|
+
name: 'Jane',
|
|
19
|
+
active: true,
|
|
20
|
+
address: PersonAddress.from({ id: 2, address: 'Street' }),
|
|
21
|
+
contacts: [],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const repository = {
|
|
25
|
+
findMany: async () => ({ items: [person], count: 1 }),
|
|
26
|
+
} as unknown as IPersonRepository;
|
|
27
|
+
|
|
28
|
+
const handler = new ReadManyPersonHandler(repository, new CacheStub());
|
|
29
|
+
const result = await handler.handle(new ReadManyPersonRequest());
|
|
30
|
+
|
|
31
|
+
expect(result.count).toBe(1);
|
|
32
|
+
expect(result.items).toHaveLength(1);
|
|
33
|
+
expect(result.items[0].name).toBe('Jane');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('reutiliza cache para a mesma consulta de listagem', async () => {
|
|
37
|
+
const person = Person.from({
|
|
38
|
+
id: 1,
|
|
39
|
+
name: 'Jane',
|
|
40
|
+
active: true,
|
|
41
|
+
address: PersonAddress.from({ id: 2, address: 'Street' }),
|
|
42
|
+
contacts: [],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
let calls = 0;
|
|
46
|
+
const repository = {
|
|
47
|
+
findMany: async () => {
|
|
48
|
+
calls += 1;
|
|
49
|
+
return { items: [person], count: 1 };
|
|
50
|
+
},
|
|
51
|
+
} as unknown as IPersonRepository;
|
|
52
|
+
|
|
53
|
+
const cache = new CacheStub();
|
|
54
|
+
const handler = new ReadManyPersonHandler(repository, cache);
|
|
55
|
+
const request = new ReadManyPersonRequest();
|
|
56
|
+
|
|
57
|
+
await handler.handle(request);
|
|
58
|
+
await handler.handle(request);
|
|
59
|
+
|
|
60
|
+
expect(calls).toBe(1);
|
|
61
|
+
expect(cache.store.size).toBe(1);
|
|
62
|
+
expect([...cache.store.keys()][0]).toContain('person:list:');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it, beforeAll } from 'bun:test';
|
|
2
|
+
import { NotFoundException } from '@nestjs/common';
|
|
3
|
+
import { ReadPersonHandler } from '@/application/person/read/read-person.handler';
|
|
4
|
+
import { PersonMapper } from '@/application/mapping/person.mapper';
|
|
5
|
+
import { Person } from '@/domain/entities/person/person';
|
|
6
|
+
import { PersonAddress } from '@/domain/entities/person/person-address';
|
|
7
|
+
import type { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
8
|
+
|
|
9
|
+
describe('ReadPersonHandler', () => {
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
PersonMapper.createMap();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('retorna pessoa mapeada quando encontrada', async () => {
|
|
15
|
+
const person = Person.from({
|
|
16
|
+
id: 1,
|
|
17
|
+
name: 'Jane',
|
|
18
|
+
active: true,
|
|
19
|
+
address: PersonAddress.from({ id: 2, address: 'Street' }),
|
|
20
|
+
contacts: [],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const repository = {
|
|
24
|
+
findById: async (id: number) => (id === 1 ? person : null),
|
|
25
|
+
} as unknown as IPersonRepository;
|
|
26
|
+
|
|
27
|
+
const handler = new ReadPersonHandler(repository);
|
|
28
|
+
const result = await handler.handle(1);
|
|
29
|
+
|
|
30
|
+
expect(result.id).toBe(1);
|
|
31
|
+
expect(result.name).toBe('Jane');
|
|
32
|
+
expect(result.address.address).toBe('Street');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('lança NotFoundException quando a pessoa não existe', async () => {
|
|
36
|
+
const repository = {
|
|
37
|
+
findById: async () => null,
|
|
38
|
+
} as unknown as IPersonRepository;
|
|
39
|
+
|
|
40
|
+
const handler = new ReadPersonHandler(repository);
|
|
41
|
+
|
|
42
|
+
await expect(handler.handle(99)).rejects.toBeInstanceOf(NotFoundException);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { AuthProfile } from '@/core/auth/auth-profile.enum';
|
|
3
|
+
import { RefreshTokenHandler } from '@/application/auth/refresh-token/refresh-token.handler';
|
|
4
|
+
import { LoggedUserInfoDto } from '@/domain/dtos/logged-user-info.dto';
|
|
5
|
+
import { IJwtTokenService } from '@/domain/auth/services/iauth.service';
|
|
6
|
+
import { LoggedUserInfoFakeService } from '@/test/services/logged-user-info.fake-service';
|
|
7
|
+
|
|
8
|
+
describe('RefreshTokenHandler', () => {
|
|
9
|
+
it('emite novo par de tokens a partir do usuário logado', async () => {
|
|
10
|
+
const jwtTokenService = {
|
|
11
|
+
signTokenPair: (claims: { sub: string; profile?: AuthProfile }) => ({
|
|
12
|
+
accessToken: `access-${claims.sub}`,
|
|
13
|
+
refreshToken: `refresh-${claims.sub}`,
|
|
14
|
+
}),
|
|
15
|
+
} as unknown as IJwtTokenService;
|
|
16
|
+
|
|
17
|
+
const loggedUserInfo = new LoggedUserInfoFakeService();
|
|
18
|
+
loggedUserInfo.setContext({
|
|
19
|
+
user: Object.assign(new LoggedUserInfoDto(), {
|
|
20
|
+
sub: 'user-1',
|
|
21
|
+
profile: AuthProfile.admin,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const handler = new RefreshTokenHandler(jwtTokenService, loggedUserInfo);
|
|
26
|
+
|
|
27
|
+
const result = await handler.handle();
|
|
28
|
+
|
|
29
|
+
expect(result).toEqual({
|
|
30
|
+
accessToken: 'access-user-1',
|
|
31
|
+
refreshToken: 'refresh-user-1',
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { ScalarOAuthTokenHandler } from '@/application/auth/oauth2/scalar-token/scalar-oauth-token.handler';
|
|
3
|
+
import { OAuthExchangeCodeHandler } from '@/application/auth/oauth2/exchange-code/exchange-code.handler';
|
|
4
|
+
import { BadRequestException } from '@nestjs/common';
|
|
5
|
+
|
|
6
|
+
describe('ScalarOAuthTokenHandler', () => {
|
|
7
|
+
const tokens = {
|
|
8
|
+
accessToken: 'access-token',
|
|
9
|
+
refreshToken: 'refresh-token',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const exchangeCode = {
|
|
13
|
+
handle: async () => tokens,
|
|
14
|
+
} as unknown as OAuthExchangeCodeHandler;
|
|
15
|
+
|
|
16
|
+
const handler = new ScalarOAuthTokenHandler(exchangeCode);
|
|
17
|
+
|
|
18
|
+
it('delega a troca de code/state para o exchange-code handler', async () => {
|
|
19
|
+
const result = await handler.handle({
|
|
20
|
+
provider: 'google',
|
|
21
|
+
code: 'auth-code',
|
|
22
|
+
state: 'state-123',
|
|
23
|
+
redirect_uri: 'http://localhost/callback',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(result).toEqual(tokens);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('aceita ssoCode e redirectUri como aliases do Scalar', async () => {
|
|
30
|
+
const result = await handler.handle({
|
|
31
|
+
provider: 'google',
|
|
32
|
+
ssoCode: 'auth-code',
|
|
33
|
+
redirectUri: 'http://localhost/callback',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(result).toEqual(tokens);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('não exige state (fluxo Scalar authorization code)', async () => {
|
|
40
|
+
const scalarExchange = {
|
|
41
|
+
handle: async (request: { state?: string }) => {
|
|
42
|
+
expect(request.state).toBeUndefined();
|
|
43
|
+
return tokens;
|
|
44
|
+
},
|
|
45
|
+
} as unknown as OAuthExchangeCodeHandler;
|
|
46
|
+
|
|
47
|
+
const scalarHandler = new ScalarOAuthTokenHandler(scalarExchange);
|
|
48
|
+
|
|
49
|
+
await expect(
|
|
50
|
+
scalarHandler.handle({
|
|
51
|
+
provider: 'google',
|
|
52
|
+
code: 'auth-code',
|
|
53
|
+
redirect_uri: 'http://localhost/callback',
|
|
54
|
+
}),
|
|
55
|
+
).resolves.toEqual(tokens);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('lança BadRequestException quando provider ou code estão ausentes', async () => {
|
|
59
|
+
await expect(
|
|
60
|
+
handler.handle({ provider: 'google', code: '' }),
|
|
61
|
+
).rejects.toThrow(BadRequestException);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NotFoundException } from '@nestjs/common';
|
|
2
|
+
import { UpdatePersonHandler } from '@/application/person/update/update-person.handler';
|
|
3
|
+
import { Person } from '@/domain/entities/person/person';
|
|
4
|
+
import { PersonAddress } from '@/domain/entities/person/person-address';
|
|
5
|
+
import { PersonContact } from '@/domain/entities/person/person-contact';
|
|
6
|
+
import { PERSON_LIST_CACHE_PREFIX } from '@/core/utils/person-list-cache';
|
|
7
|
+
import type { IPersonRepository } from '@/domain/repositories/iperson.repository';
|
|
8
|
+
import { CacheStub } from '@/test/services/cache.stub';
|
|
9
|
+
|
|
10
|
+
describe('UpdatePersonHandler', () => {
|
|
11
|
+
it('carrega a entidade existente antes de salvar e invalida cache', async () => {
|
|
12
|
+
const cache = new CacheStub();
|
|
13
|
+
const existingContact = PersonContact.from({
|
|
14
|
+
id: 10,
|
|
15
|
+
contact: 'old@example.com',
|
|
16
|
+
person: undefined as unknown as Person,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const person = Person.from({
|
|
20
|
+
id: 1,
|
|
21
|
+
name: 'Jane',
|
|
22
|
+
active: true,
|
|
23
|
+
address: PersonAddress.from({ id: 5, address: 'Old street' }),
|
|
24
|
+
contacts: [existingContact],
|
|
25
|
+
});
|
|
26
|
+
existingContact.person = person;
|
|
27
|
+
|
|
28
|
+
const calls = {
|
|
29
|
+
findById: [] as number[],
|
|
30
|
+
save: [] as Person[],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const repository = {
|
|
34
|
+
findById: async (id: number) => {
|
|
35
|
+
calls.findById.push(id);
|
|
36
|
+
return id === 1 ? person : null;
|
|
37
|
+
},
|
|
38
|
+
save: async (entity: Person) => {
|
|
39
|
+
calls.save.push(entity);
|
|
40
|
+
return entity;
|
|
41
|
+
},
|
|
42
|
+
} as unknown as IPersonRepository;
|
|
43
|
+
|
|
44
|
+
const handler = new UpdatePersonHandler(repository, cache);
|
|
45
|
+
|
|
46
|
+
await handler.handle({
|
|
47
|
+
id: 1,
|
|
48
|
+
name: 'Jane Updated',
|
|
49
|
+
address: { id: 5, address: 'New street' },
|
|
50
|
+
contacts: [{ id: 10, contact: 'new@example.com' }],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(calls.findById).toEqual([1]);
|
|
54
|
+
expect(person.name).toBe('Jane Updated');
|
|
55
|
+
expect(person.address.address).toBe('New street');
|
|
56
|
+
expect(person.contacts[0].contact).toBe('new@example.com');
|
|
57
|
+
expect(calls.save).toEqual([person]);
|
|
58
|
+
expect(cache.invalidateByPrefixCalls).toEqual([PERSON_LIST_CACHE_PREFIX]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('lança NotFoundException quando a pessoa não existe', async () => {
|
|
62
|
+
const repository = {
|
|
63
|
+
findById: async () => null,
|
|
64
|
+
save: async () => undefined,
|
|
65
|
+
} as unknown as IPersonRepository;
|
|
66
|
+
|
|
67
|
+
const handler = new UpdatePersonHandler(repository, new CacheStub());
|
|
68
|
+
|
|
69
|
+
await expect(
|
|
70
|
+
handler.handle({
|
|
71
|
+
id: 99,
|
|
72
|
+
name: 'Ghost',
|
|
73
|
+
address: { id: 1, address: 'Nowhere' },
|
|
74
|
+
contacts: [],
|
|
75
|
+
}),
|
|
76
|
+
).rejects.toBeInstanceOf(NotFoundException);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="bun-types/test-globals" />
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { applyRefreshTokenForRefreshRoute } from '@/core/auth/resolve-refresh-token';
|
|
3
|
+
import { AuthGuard } from '@/host/security/guards/auth.guard';
|
|
4
|
+
import { IS_PUBLIC_KEY } from '@/host/decorators/is-public.decorator';
|
|
5
|
+
import { Reflector } from '@nestjs/core';
|
|
6
|
+
import { ExecutionContext } from '@nestjs/common';
|
|
7
|
+
|
|
8
|
+
describe('AuthGuard', () => {
|
|
9
|
+
it('permite acesso em rotas marcadas com @IsPublic', async () => {
|
|
10
|
+
const reflector = new Reflector();
|
|
11
|
+
const userRepository = { getById: async () => null } as never;
|
|
12
|
+
const guard = new AuthGuard(reflector, userRepository);
|
|
13
|
+
const handler = () => undefined;
|
|
14
|
+
Reflect.defineMetadata(IS_PUBLIC_KEY, true, handler);
|
|
15
|
+
|
|
16
|
+
const context = {
|
|
17
|
+
getHandler: () => handler,
|
|
18
|
+
getClass: () => class {},
|
|
19
|
+
switchToHttp: () => ({
|
|
20
|
+
getRequest: () => ({ headers: {} }),
|
|
21
|
+
}),
|
|
22
|
+
} as unknown as ExecutionContext;
|
|
23
|
+
|
|
24
|
+
await expect(guard.canActivate(context)).resolves.toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('injeta refreshToken do cookie como Bearer em /auth/refresh', () => {
|
|
28
|
+
const request = {
|
|
29
|
+
url: '/auth/refresh',
|
|
30
|
+
cookies: { refreshToken: 'refresh-from-cookie' },
|
|
31
|
+
headers: {} as Record<string, string | string[] | undefined>,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
applyRefreshTokenForRefreshRoute(request);
|
|
35
|
+
|
|
36
|
+
expect(request.headers.authorization).toBe('Bearer refresh-from-cookie');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('injeta refreshToken do body como Bearer em /auth/refresh', () => {
|
|
40
|
+
const request = {
|
|
41
|
+
url: '/auth/refresh',
|
|
42
|
+
body: { refresh_token: 'refresh-from-body' },
|
|
43
|
+
headers: {} as Record<string, string | string[] | undefined>,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
applyRefreshTokenForRefreshRoute(request);
|
|
47
|
+
|
|
48
|
+
expect(request.headers.authorization).toBe('Bearer refresh-from-body');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('não sobrescreve Bearer já presente em /auth/refresh', () => {
|
|
52
|
+
const request = {
|
|
53
|
+
url: '/auth/refresh',
|
|
54
|
+
cookies: { refreshToken: 'refresh-from-cookie' },
|
|
55
|
+
headers: { authorization: 'Bearer existing-token' },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
applyRefreshTokenForRefreshRoute(request);
|
|
59
|
+
|
|
60
|
+
expect(request.headers.authorization).toBe('Bearer existing-token');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('injeta refresh_token do body mesmo com Authorization Basic (Scalar OAuth)', () => {
|
|
64
|
+
const request = {
|
|
65
|
+
url: '/auth/refresh',
|
|
66
|
+
body: { grant_type: 'refresh_token', refresh_token: 'refresh-oauth' },
|
|
67
|
+
headers: {
|
|
68
|
+
authorization:
|
|
69
|
+
'Basic ' + Buffer.from('client-id:client-secret').toString('base64'),
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
applyRefreshTokenForRefreshRoute(request);
|
|
74
|
+
|
|
75
|
+
expect(request.headers.authorization).toBe('Bearer refresh-oauth');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { buildListCacheKey } from '@/core/utils/build-list-cache-key';
|
|
3
|
+
|
|
4
|
+
describe('buildListCacheKey', () => {
|
|
5
|
+
it('monta chave estável a partir dos filtros da listagem', () => {
|
|
6
|
+
const key = buildListCacheKey('person:list', {
|
|
7
|
+
page: 0,
|
|
8
|
+
limit: 10,
|
|
9
|
+
name: 'Jane',
|
|
10
|
+
active: true,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
expect(key).toBe(
|
|
14
|
+
'person:list:{"active":true,"limit":10,"name":"Jane","page":0}',
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('ignora métodos e filtros vazios ou nulos', () => {
|
|
19
|
+
const key = buildListCacheKey('person:list', {
|
|
20
|
+
page: 0,
|
|
21
|
+
name: undefined,
|
|
22
|
+
active: null,
|
|
23
|
+
orderBy: '',
|
|
24
|
+
skip: () => 0,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
expect(key).toBe('person:list:{"page":0}');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="bun-types/test-globals" />
|
|
2
|
+
|
|
3
|
+
import { cronExpressionToBoolean } from '@/core/utils/cron-expression-to-boolean';
|
|
4
|
+
import { describe, expect, it } from 'bun:test';
|
|
5
|
+
|
|
6
|
+
describe('cronExpressionToBoolean', () => {
|
|
7
|
+
it('retorna true quando o instante atual coincide com o tick da expressão', () => {
|
|
8
|
+
const at = new Date(2024, 5, 12, 12, 0, 0, 1);
|
|
9
|
+
|
|
10
|
+
expect(cronExpressionToBoolean('0 0 12 * * *', at)).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('retorna false quando o instante atual não coincide com o tick da expressão', () => {
|
|
14
|
+
const at = new Date(2024, 5, 12, 12, 0, 1);
|
|
15
|
+
|
|
16
|
+
expect(cronExpressionToBoolean('0 0 12 * * *', at)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('retorna false para expressão inválida', () => {
|
|
20
|
+
expect(cronExpressionToBoolean('not a cron')).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="bun-types/test-globals" />
|
|
2
|
+
|
|
3
|
+
import { delay } from '@koalarx/utils/KlDelay';
|
|
4
|
+
import {
|
|
5
|
+
CronJobHandlerBase,
|
|
6
|
+
CronJobSettings,
|
|
7
|
+
} from '@/core/background-services/cron-service/cron-job.handler.base';
|
|
8
|
+
import { FakeLoggingService } from '@/test/services/fake-logging.service';
|
|
9
|
+
import { FakeRedLockService } from '@/test/services/fake-red-lock.service';
|
|
10
|
+
import { describe, expect, it, spyOn } from 'bun:test';
|
|
11
|
+
|
|
12
|
+
class CronJobTest extends CronJobHandlerBase {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(new FakeRedLockService(), new FakeLoggingService());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected async settings(): Promise<CronJobSettings> {
|
|
18
|
+
return { isActive: true, timeInMinutes: 0.01 };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static async isCalled(): Promise<void> {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected run(): Promise<void> {
|
|
26
|
+
return CronJobTest.isCalled();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('CronJobHandlerBase', () => {
|
|
31
|
+
it('executa o callback do job quando ativo', async () => {
|
|
32
|
+
const callbackSpy = spyOn(CronJobTest, 'isCalled');
|
|
33
|
+
|
|
34
|
+
void new CronJobTest().start();
|
|
35
|
+
|
|
36
|
+
await delay(100);
|
|
37
|
+
|
|
38
|
+
expect(callbackSpy).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
});
|