@koalarx/nest 3.1.49 → 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 -82
- 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,30 @@
|
|
|
1
|
+
/** Converte `expiresIn` do @nestjs/jwt (ex.: `15m`, `7d`) para segundos. */
|
|
2
|
+
export function parseJwtExpiresInToSeconds(expiresIn: string): number {
|
|
3
|
+
if (/^\d+$/.test(expiresIn)) {
|
|
4
|
+
return parseInt(expiresIn, 10);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const match = expiresIn.match(/^(\d+)(ms|s|m|h|d)$/);
|
|
8
|
+
|
|
9
|
+
if (!match) {
|
|
10
|
+
throw new Error(`JWT expiresIn inválido: ${expiresIn}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const value = parseInt(match[1], 10);
|
|
14
|
+
const unit = match[2];
|
|
15
|
+
|
|
16
|
+
switch (unit) {
|
|
17
|
+
case 'ms':
|
|
18
|
+
return value / 1000;
|
|
19
|
+
case 's':
|
|
20
|
+
return value;
|
|
21
|
+
case 'm':
|
|
22
|
+
return value * 60;
|
|
23
|
+
case 'h':
|
|
24
|
+
return value * 3600;
|
|
25
|
+
case 'd':
|
|
26
|
+
return value * 86400;
|
|
27
|
+
default:
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const OAUTH2_ENV_FIELD = {
|
|
4
|
+
DOMAIN: 'domain',
|
|
5
|
+
CLIENT_ID: 'clientId',
|
|
6
|
+
CLIENT_SECRET: 'clientSecret',
|
|
7
|
+
SCOPE: 'scope',
|
|
8
|
+
REDIRECT_PATH: 'redirectPath',
|
|
9
|
+
AUTHORIZATION_URL: 'authorizationUrl',
|
|
10
|
+
TOKEN_URL: 'tokenUrl',
|
|
11
|
+
USERINFO_URL: 'userInfoUrl',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
const OAUTH2_ENV_PATTERN =
|
|
15
|
+
/^OAUTH2_([A-Z0-9_]+)_(DOMAIN|CLIENT_ID|CLIENT_SECRET|SCOPE|REDIRECT_PATH|AUTHORIZATION_URL|TOKEN_URL|USERINFO_URL)$/;
|
|
16
|
+
|
|
17
|
+
export const oauth2ProviderEnvEntrySchema = z.object({
|
|
18
|
+
domain: z.string().optional(),
|
|
19
|
+
clientId: z.string().optional(),
|
|
20
|
+
clientSecret: z.string().optional(),
|
|
21
|
+
scope: z.string().optional(),
|
|
22
|
+
redirectPath: z.string().optional(),
|
|
23
|
+
authorizationUrl: z.string().optional(),
|
|
24
|
+
tokenUrl: z.string().optional(),
|
|
25
|
+
userInfoUrl: z.string().optional(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export type OAuth2ProviderEnvEntry = z.infer<
|
|
29
|
+
typeof oauth2ProviderEnvEntrySchema
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
export function parseOAuth2ProviderEnv(
|
|
33
|
+
config: Record<string, unknown>,
|
|
34
|
+
): Record<string, OAuth2ProviderEnvEntry> {
|
|
35
|
+
const providers: Record<string, OAuth2ProviderEnvEntry> = {};
|
|
36
|
+
|
|
37
|
+
for (const [key, value] of Object.entries(config)) {
|
|
38
|
+
if (typeof value !== 'string' || !value) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const match = key.match(OAUTH2_ENV_PATTERN);
|
|
43
|
+
|
|
44
|
+
if (!match) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const providerKey = match[1].toLowerCase();
|
|
49
|
+
const field = OAUTH2_ENV_FIELD[match[2] as keyof typeof OAUTH2_ENV_FIELD];
|
|
50
|
+
|
|
51
|
+
providers[providerKey] ??= {};
|
|
52
|
+
providers[providerKey][field] = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return providers;
|
|
56
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AuthHttp } from '@/core/auth/auth.constants';
|
|
2
|
+
import { isAuthRefreshRoute } from '@/core/auth/auth-routes';
|
|
3
|
+
|
|
4
|
+
type RefreshTokenRequest = {
|
|
5
|
+
cookies?: Record<string, string>;
|
|
6
|
+
body?: Record<string, string>;
|
|
7
|
+
headers: Record<string, string | string[] | undefined>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function resolveRefreshTokenFromRequest(
|
|
11
|
+
request: RefreshTokenRequest,
|
|
12
|
+
): string | undefined {
|
|
13
|
+
const authorization = request.headers.authorization;
|
|
14
|
+
|
|
15
|
+
if (typeof authorization === 'string') {
|
|
16
|
+
if (authorization.startsWith(AuthHttp.BEARER_PREFIX)) {
|
|
17
|
+
return authorization.slice(AuthHttp.BEARER_PREFIX.length).trim();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
request.cookies?.[AuthHttp.REFRESH_TOKEN_COOKIE] ??
|
|
23
|
+
request.body?.refresh_token ??
|
|
24
|
+
request.body?.refreshToken
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function applyRefreshTokenForRefreshRoute(
|
|
29
|
+
request: RefreshTokenRequest & { url?: string },
|
|
30
|
+
): void {
|
|
31
|
+
if (!isAuthRefreshRoute(request.url)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const refreshToken = resolveRefreshTokenFromRequest(request);
|
|
36
|
+
|
|
37
|
+
if (refreshToken) {
|
|
38
|
+
request.headers.authorization = `${AuthHttp.BEARER_PREFIX}${refreshToken}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ILoggingService } from '@/domain/common/ilogging.service';
|
|
2
|
+
import { IRedLockService } from '@/domain/common/ired-lock.service';
|
|
3
|
+
import { cronExpressionToBoolean } from '@/core/utils/cron-expression-to-boolean';
|
|
4
|
+
import { DEFAULT_CRON_POLL_MINUTES } from '@/core/constants/cron.constants';
|
|
5
|
+
import { MINUTES_TO_MS, MS_TO_SECONDS } from '@/core/utils/time.constants';
|
|
6
|
+
import { delay } from '@koalarx/utils/KlDelay';
|
|
7
|
+
import { reportErrorToLogging } from '@/core/utils/report-error';
|
|
8
|
+
|
|
9
|
+
export interface CronJobSettings {
|
|
10
|
+
isActive: boolean;
|
|
11
|
+
timeInMinutes: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function cronJobSettings(
|
|
15
|
+
cronExpression: string,
|
|
16
|
+
timeInMinutes = DEFAULT_CRON_POLL_MINUTES,
|
|
17
|
+
): CronJobSettings {
|
|
18
|
+
return {
|
|
19
|
+
isActive: cronExpressionToBoolean(cronExpression),
|
|
20
|
+
timeInMinutes,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export abstract class CronJobHandlerBase {
|
|
25
|
+
constructor(
|
|
26
|
+
private readonly redlockService: IRedLockService,
|
|
27
|
+
private readonly loggingService: ILoggingService,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
protected abstract run(): Promise<void>;
|
|
31
|
+
|
|
32
|
+
protected abstract settings(): Promise<CronJobSettings>;
|
|
33
|
+
|
|
34
|
+
async start(): Promise<void> {
|
|
35
|
+
const name = this.constructor.name;
|
|
36
|
+
|
|
37
|
+
while (true) {
|
|
38
|
+
const settings = await this.settings();
|
|
39
|
+
const timeout = settings.timeInMinutes * MINUTES_TO_MS;
|
|
40
|
+
|
|
41
|
+
if (settings.isActive) {
|
|
42
|
+
const ttlSecondsLock = timeout / MS_TO_SECONDS;
|
|
43
|
+
const acquiredLock = await this.redlockService.acquiredLock(
|
|
44
|
+
name,
|
|
45
|
+
ttlSecondsLock,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (acquiredLock) {
|
|
49
|
+
try {
|
|
50
|
+
await this.run();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
const reportError =
|
|
53
|
+
error instanceof Error ? error : new Error(String(error));
|
|
54
|
+
|
|
55
|
+
await reportErrorToLogging(this.loggingService, reportError);
|
|
56
|
+
} finally {
|
|
57
|
+
await this.redlockService.releaseLock(name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await delay(timeout);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { EventClass } from './event-class';
|
|
3
|
+
import { EventQueue } from './event-queue';
|
|
4
|
+
|
|
5
|
+
export abstract class EventHandlerBase<TEvent extends EventClass = EventClass> {
|
|
6
|
+
constructor(public readonly event: Type<TEvent>) {}
|
|
7
|
+
|
|
8
|
+
abstract handleEvent(event: TEvent): Promise<void>;
|
|
9
|
+
|
|
10
|
+
setupSubscriptions() {
|
|
11
|
+
EventQueue.register(
|
|
12
|
+
this.handleEvent.bind(this),
|
|
13
|
+
this.constructor.name,
|
|
14
|
+
this.event.name,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { EventClass } from './event-class';
|
|
4
|
+
import { EventHandlerBase } from './event-handler.base';
|
|
5
|
+
import { EventQueue } from './event-queue';
|
|
6
|
+
|
|
7
|
+
export abstract class EventJob<TEntity> {
|
|
8
|
+
private _eventQueue: EventClass<TEntity>[] = [];
|
|
9
|
+
|
|
10
|
+
_id = randomUUID();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Lista os handlers que processam eventos deste agregado.
|
|
14
|
+
* Usado pelo `EventQueue.dispatch` para rotear eventos enfileirados.
|
|
15
|
+
* Registre as mesmas classes em `JobsModule.register({ eventHandlers })`.
|
|
16
|
+
*/
|
|
17
|
+
abstract defineHandlers(): Array<Type<EventHandlerBase>>;
|
|
18
|
+
|
|
19
|
+
get eventQueue(): EventClass<TEntity>[] {
|
|
20
|
+
return this._eventQueue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
clearQueue() {
|
|
24
|
+
this._eventQueue = [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
addEvent(event: EventClass<TEntity>): void {
|
|
28
|
+
this._eventQueue.push(event);
|
|
29
|
+
EventQueue.markAggregateForDispatch(this);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { IComparableId } from '@/core/utils/icomparable';
|
|
2
|
+
import { EventClass } from './event-class';
|
|
3
|
+
import { EventJob } from './event-job';
|
|
4
|
+
|
|
5
|
+
type EventJobCallback = (event: EventClass) => void;
|
|
6
|
+
|
|
7
|
+
interface EventQueueJobItem {
|
|
8
|
+
eventClassName: string;
|
|
9
|
+
callback: EventJobCallback;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class EventQueue {
|
|
13
|
+
private static handlersMap: Record<string, EventQueueJobItem[]> = {};
|
|
14
|
+
|
|
15
|
+
private static markedAggregates: EventJob<unknown>[] = [];
|
|
16
|
+
|
|
17
|
+
private static dispatch(event: EventClass) {
|
|
18
|
+
const eventJobHandlers = this.markedAggregates.find((aggregate) =>
|
|
19
|
+
aggregate.eventQueue.find((queuedEvent) => queuedEvent === event),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const eventHandler = Object.keys(this.handlersMap).find((handlerName) =>
|
|
23
|
+
eventJobHandlers
|
|
24
|
+
?.defineHandlers()
|
|
25
|
+
.find(
|
|
26
|
+
(handler) =>
|
|
27
|
+
handler.name === handlerName &&
|
|
28
|
+
this.handlersMap[handler.name].some(
|
|
29
|
+
(job) => job.eventClassName === event.constructor.name,
|
|
30
|
+
),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (eventHandler) {
|
|
35
|
+
const jobs = this.handlersMap[eventHandler];
|
|
36
|
+
|
|
37
|
+
for (const job of jobs) {
|
|
38
|
+
job.callback(event);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private static dispatchAggregateEvents(aggregate: EventJob<unknown>) {
|
|
44
|
+
aggregate.eventQueue.forEach((event) => this.dispatch(event));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private static removeAggregateFromMarkedDispatchList(
|
|
48
|
+
aggregate: EventJob<unknown>,
|
|
49
|
+
) {
|
|
50
|
+
const index = this.markedAggregates.findIndex(
|
|
51
|
+
(item) => item._id === aggregate._id,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
this.markedAggregates.splice(index, 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static markAggregateForDispatch(aggregate: EventJob<unknown>) {
|
|
58
|
+
const aggregateFound = !!this.findMarkedAggregateByID(aggregate._id);
|
|
59
|
+
|
|
60
|
+
if (!aggregateFound) {
|
|
61
|
+
this.markedAggregates.push(aggregate);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static dispatchEventsForAggregate(id: IComparableId) {
|
|
66
|
+
const aggregate = this.findMarkedAggregateByID(id);
|
|
67
|
+
|
|
68
|
+
if (aggregate) {
|
|
69
|
+
this.dispatchAggregateEvents(aggregate);
|
|
70
|
+
aggregate.clearQueue();
|
|
71
|
+
this.removeAggregateFromMarkedDispatchList(aggregate);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static register(
|
|
76
|
+
callback: EventJobCallback,
|
|
77
|
+
handlerClassName: string,
|
|
78
|
+
eventClassName: string,
|
|
79
|
+
) {
|
|
80
|
+
if (!(handlerClassName in this.handlersMap)) {
|
|
81
|
+
this.handlersMap[handlerClassName] = [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.handlersMap[handlerClassName].push({
|
|
85
|
+
eventClassName,
|
|
86
|
+
callback,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static clearHandlers() {
|
|
91
|
+
this.handlersMap = {};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static clearMarkedAggregates() {
|
|
95
|
+
this.markedAggregates = [];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static findMarkedAggregateByID(
|
|
99
|
+
id: IComparableId,
|
|
100
|
+
): EventJob<unknown> | undefined {
|
|
101
|
+
return this.markedAggregates.find((aggregate) => aggregate._id === id);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static getMarkedAggregates() {
|
|
105
|
+
return this.markedAggregates;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ObjectClassProps<T> = {
|
|
2
|
+
[K in keyof T as T[K] extends Function ? never : K]: T[K];
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export abstract class ObjectClass<T = object> {
|
|
6
|
+
declare protected readonly _propsType?: ObjectClassProps<T>;
|
|
7
|
+
|
|
8
|
+
static from<This extends new () => object>(
|
|
9
|
+
this: This,
|
|
10
|
+
props: ObjectClassProps<InstanceType<This>>,
|
|
11
|
+
): InstanceType<This> {
|
|
12
|
+
return Object.assign(new this(), props) as InstanceType<This>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Prefixos e chaves do cache distribuído / em memória. */
|
|
2
|
+
export const CacheKeyPrefix = {
|
|
3
|
+
OAUTH2_STATE: 'oauth2:state:',
|
|
4
|
+
RED_LOCK: 'redLock:',
|
|
5
|
+
} as const;
|
|
6
|
+
|
|
7
|
+
/** TTLs em segundos para entradas de cache. */
|
|
8
|
+
export const CacheTtlSeconds = {
|
|
9
|
+
/** Estado OAuth2 durante o fluxo de autorização (10 minutos). */
|
|
10
|
+
OAUTH2_STATE: 10 * 60,
|
|
11
|
+
/** Listagem paginada de Person (2 minutos). */
|
|
12
|
+
PERSON_LIST: 120,
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
/** TTL padrão do RedLock quando não derivado do cron (segundos). */
|
|
16
|
+
export const DEFAULT_RED_LOCK_TTL_SECONDS = 30;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Expressões cron prontas (segundo = 6 campos). */
|
|
2
|
+
export const CronExpression = {
|
|
3
|
+
/** A cada 15 segundos — intervalo didático para o template de exemplo. */
|
|
4
|
+
EVERY_15_SECONDS: '*/15 * * * * *',
|
|
5
|
+
/** A cada minuto. */
|
|
6
|
+
EVERY_MINUTE: '0 */1 * * * *',
|
|
7
|
+
/** A cada 5 minutos. */
|
|
8
|
+
EVERY_FIVE_MINUTES: '0 */5 * * * *',
|
|
9
|
+
/** A cada hora (minuto 0). */
|
|
10
|
+
HOURLY: '0 0 * * * *',
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
/** Intervalo padrão de poll dos cron jobs (minutos). */
|
|
14
|
+
export const DEFAULT_CRON_POLL_MINUTES = 0.01;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
oauth2ProviderEnvEntrySchema,
|
|
3
|
+
parseOAuth2ProviderEnv,
|
|
4
|
+
type OAuth2ProviderEnvEntry,
|
|
5
|
+
} from '@/core/auth/parse-oauth2-provider-env';
|
|
6
|
+
import { envBooleanSchema } from '@/core/schemas';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
|
|
9
|
+
export const envSchema = z.object({
|
|
10
|
+
PORT: z.coerce.number().default(3000),
|
|
11
|
+
NODE_ENV: z.enum(['test', 'develop', 'staging', 'production']),
|
|
12
|
+
DATABASE_URL: z.string(),
|
|
13
|
+
REDIS_CONNECTION_STRING: z.string().optional(),
|
|
14
|
+
CACHE_KEY_PREFIX: z.string().optional(),
|
|
15
|
+
CRON_JOBS_ENABLED: envBooleanSchema(false),
|
|
16
|
+
BOOTSTRAP_DELAY_MS: z.coerce.number().default(0),
|
|
17
|
+
JWT_PRIVATE_KEY: z.string().optional(),
|
|
18
|
+
JWT_PUBLIC_KEY: z.string().optional(),
|
|
19
|
+
JWT_ACCESS_TOKEN_EXPIRES_IN: z.string().default('15m'),
|
|
20
|
+
JWT_REFRESH_TOKEN_EXPIRES_IN: z.string().default('7d'),
|
|
21
|
+
API_HOST: z.string().optional(),
|
|
22
|
+
OAUTH2_PROVIDERS: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type Env = z.infer<typeof envSchema> & {
|
|
26
|
+
OAUTH2_PROVIDER_ENV: Record<string, OAuth2ProviderEnvEntry>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function validateEnvConfig(config: Record<string, unknown>): Env {
|
|
30
|
+
const parsed = envSchema.parse(config);
|
|
31
|
+
const rawProviders = parseOAuth2ProviderEnv(config);
|
|
32
|
+
const OAUTH2_PROVIDER_ENV: Record<string, OAuth2ProviderEnvEntry> = {};
|
|
33
|
+
|
|
34
|
+
for (const [key, entry] of Object.entries(rawProviders)) {
|
|
35
|
+
OAUTH2_PROVIDER_ENV[key] = oauth2ProviderEnvEntrySchema.parse(entry);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
...parsed,
|
|
40
|
+
OAUTH2_PROVIDER_ENV,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
function parseBoolean(value: unknown) {
|
|
4
|
+
if (value === 'true' || value === true) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (value === 'false' || value === false) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function booleanSchema() {
|
|
16
|
+
return z.preprocess(parseBoolean, z.boolean().optional());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function envBooleanSchema(defaultValue = false) {
|
|
20
|
+
return z.preprocess(
|
|
21
|
+
(value) => parseBoolean(value) ?? defaultValue,
|
|
22
|
+
z.boolean(),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { maskCpf, maskCnpj } from '@koalarx/utils/KlString';
|
|
2
|
+
import {
|
|
3
|
+
isCnpjDocument,
|
|
4
|
+
isCpfDocument,
|
|
5
|
+
unmaskDocumentNumber,
|
|
6
|
+
} from '@/core/schemas/document-number.utils';
|
|
7
|
+
|
|
8
|
+
export function setMaskDocumentNumber(document?: string) {
|
|
9
|
+
if (!document) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (isCpfDocument(document)) {
|
|
14
|
+
return maskCpf(unmaskDocumentNumber(document));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (isCnpjDocument(document)) {
|
|
18
|
+
return maskCnpj(unmaskDocumentNumber(document));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return document;
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { validateCpf, validateCnpj } from '@koalarx/utils/KlString';
|
|
2
|
+
import {
|
|
3
|
+
isCnpjDocument,
|
|
4
|
+
isCpfDocument,
|
|
5
|
+
} from '@/core/schemas/document-number.utils';
|
|
6
|
+
|
|
7
|
+
export function documentNumberSchema(value: string) {
|
|
8
|
+
if (value === '' || value === 'undefined' || value === 'null') {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (isCpfDocument(value)) {
|
|
13
|
+
return validateCpf(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (isCnpjDocument(value)) {
|
|
17
|
+
return validateCnpj(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const DOCUMENT_MASK_PATTERN = /[/.-\s]/gi;
|
|
2
|
+
|
|
3
|
+
export function unmaskDocumentNumber(value: string): string {
|
|
4
|
+
return value.replace(DOCUMENT_MASK_PATTERN, '').toUpperCase();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isCpfDocument(value: string): boolean {
|
|
8
|
+
const unmasked = unmaskDocumentNumber(value);
|
|
9
|
+
|
|
10
|
+
return unmasked.length === 11 && /^\d{11}$/.test(unmasked);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isCnpjDocument(value: string): boolean {
|
|
14
|
+
return unmaskDocumentNumber(value).length === 14;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export function emailSchema(email?: string, isRequired = false) {
|
|
4
|
+
if (isRequired && !email) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (!email) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return z.coerce.string().max(50).pipe(z.email()).safeParse(email).success;
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { booleanSchema, envBooleanSchema } from './boolean.schema';
|
|
2
|
+
export { documentNumberSchema } from './document-number.schema';
|
|
3
|
+
export { setMaskDocumentNumber } from './document-number-mask';
|
|
4
|
+
export { emailSchema } from './email.schema';
|
|
5
|
+
export { LIST_QUERY_SCHEMA } from './list-query.schema';
|
|
6
|
+
export { nativeEnumSchema } from './native-enum.schema';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QUERY_FILTER_PARAMS } from '@/core/constants/query-params';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const LIST_QUERY_SCHEMA = z.object({
|
|
5
|
+
page: z.coerce
|
|
6
|
+
.number()
|
|
7
|
+
.transform((value) => {
|
|
8
|
+
if (value) {
|
|
9
|
+
return value - 1;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return QUERY_FILTER_PARAMS.page;
|
|
13
|
+
})
|
|
14
|
+
.optional(),
|
|
15
|
+
limit: z.coerce.number().default(QUERY_FILTER_PARAMS.limit).optional(),
|
|
16
|
+
orderBy: z.string().optional(),
|
|
17
|
+
direction: z.enum(['asc', 'desc']).default('asc').optional(),
|
|
18
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type NativeEnumLike = Record<string, string | number>;
|
|
4
|
+
|
|
5
|
+
interface NativeEnumInterface<TEnum extends NativeEnumLike> {
|
|
6
|
+
isOptional: (value: string) => TEnum[keyof TEnum] | undefined;
|
|
7
|
+
isRequired: (value: string) => TEnum[keyof TEnum];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function nativeEnumSchema<TEnum extends NativeEnumLike>(
|
|
11
|
+
nativeEnum: TEnum,
|
|
12
|
+
): NativeEnumInterface<TEnum> {
|
|
13
|
+
return {
|
|
14
|
+
isOptional: (value: string) => {
|
|
15
|
+
if (value === 'null' || value === '') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return z.coerce
|
|
20
|
+
.number()
|
|
21
|
+
.transform((parsed) => {
|
|
22
|
+
if (parsed !== undefined) {
|
|
23
|
+
return z.nativeEnum(nativeEnum).parse(parsed);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return undefined;
|
|
27
|
+
})
|
|
28
|
+
.parse(value);
|
|
29
|
+
},
|
|
30
|
+
isRequired: (value: string) =>
|
|
31
|
+
z.coerce
|
|
32
|
+
.number()
|
|
33
|
+
.transform((parsed) => z.nativeEnum(nativeEnum).parse(parsed))
|
|
34
|
+
.parse(value),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { MappingStore } from './mapping-store';
|
|
3
|
+
|
|
4
|
+
interface AutoMapConfig<T> {
|
|
5
|
+
type?: () => Type<T>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function AutoMap<T>(config?: AutoMapConfig<T>) {
|
|
9
|
+
return function (target: any, propertyKey: string) {
|
|
10
|
+
const compositionType: (() => any) | undefined = config?.type;
|
|
11
|
+
|
|
12
|
+
MappingStore.setProp(target.constructor, propertyKey, compositionType);
|
|
13
|
+
};
|
|
14
|
+
}
|