@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,171 @@
|
|
|
1
|
+
export const Template = {
|
|
2
|
+
DEFAULT: "default",
|
|
3
|
+
CRUD_SAMPLE: "crudSample"
|
|
4
|
+
};
|
|
5
|
+
export const AuthChoice = {
|
|
6
|
+
NONE: "none",
|
|
7
|
+
JWT: "jwt",
|
|
8
|
+
OAUTH2: "oauth2"
|
|
9
|
+
};
|
|
10
|
+
export const AuthStrategy = {
|
|
11
|
+
JWT: AuthChoice.JWT,
|
|
12
|
+
OAUTH2: AuthChoice.OAUTH2
|
|
13
|
+
};
|
|
14
|
+
export const ExtraFeature = {
|
|
15
|
+
CACHE: "cache",
|
|
16
|
+
HEALTH_CHECK: "health-check",
|
|
17
|
+
INTERNAL_CRON_JOBS: "internal-cron-jobs",
|
|
18
|
+
INTERNAL_EVENT_JOBS: "internal-event-jobs"
|
|
19
|
+
};
|
|
20
|
+
export var InstallModule;
|
|
21
|
+
((InstallModule) => {
|
|
22
|
+
InstallModule["CORE"] = "core";
|
|
23
|
+
InstallModule["AUTH"] = "auth";
|
|
24
|
+
InstallModule["CACHE"] = "cache";
|
|
25
|
+
InstallModule["HEALTH"] = "health";
|
|
26
|
+
InstallModule["INTERNAL_CRON_JOBS"] = "internal-cron-jobs";
|
|
27
|
+
InstallModule["INTERNAL_EVENT_JOBS"] = "internal-event-jobs";
|
|
28
|
+
})(InstallModule ||= {});
|
|
29
|
+
export const AddArgKind = {
|
|
30
|
+
AUTH: "auth",
|
|
31
|
+
FEATURE: "feature"
|
|
32
|
+
};
|
|
33
|
+
export const AuthPromptChoice = {
|
|
34
|
+
SKIP: "skip"
|
|
35
|
+
};
|
|
36
|
+
export const CRUD_BUNDLED_FEATURES = [
|
|
37
|
+
ExtraFeature.CACHE,
|
|
38
|
+
ExtraFeature.INTERNAL_CRON_JOBS,
|
|
39
|
+
ExtraFeature.INTERNAL_EVENT_JOBS
|
|
40
|
+
];
|
|
41
|
+
export const FEATURE_INSTALL_ORDER = [
|
|
42
|
+
ExtraFeature.CACHE,
|
|
43
|
+
ExtraFeature.HEALTH_CHECK,
|
|
44
|
+
ExtraFeature.INTERNAL_CRON_JOBS,
|
|
45
|
+
ExtraFeature.INTERNAL_EVENT_JOBS
|
|
46
|
+
];
|
|
47
|
+
export const TEMPLATE_ALIASES = {
|
|
48
|
+
default: Template.DEFAULT,
|
|
49
|
+
padrao: Template.DEFAULT,
|
|
50
|
+
crud: Template.CRUD_SAMPLE,
|
|
51
|
+
example: Template.CRUD_SAMPLE,
|
|
52
|
+
sample: Template.CRUD_SAMPLE,
|
|
53
|
+
"crud-sample": Template.CRUD_SAMPLE,
|
|
54
|
+
crudsample: Template.CRUD_SAMPLE
|
|
55
|
+
};
|
|
56
|
+
export const FEATURE_ALIASES = {
|
|
57
|
+
cache: ExtraFeature.CACHE,
|
|
58
|
+
redis: ExtraFeature.CACHE,
|
|
59
|
+
health: ExtraFeature.HEALTH_CHECK,
|
|
60
|
+
"health-check": ExtraFeature.HEALTH_CHECK,
|
|
61
|
+
cron: ExtraFeature.INTERNAL_CRON_JOBS,
|
|
62
|
+
"internal-cron-jobs": ExtraFeature.INTERNAL_CRON_JOBS,
|
|
63
|
+
events: ExtraFeature.INTERNAL_EVENT_JOBS,
|
|
64
|
+
"internal-event-jobs": ExtraFeature.INTERNAL_EVENT_JOBS
|
|
65
|
+
};
|
|
66
|
+
export const FEATURE_LABELS = {
|
|
67
|
+
[ExtraFeature.CACHE]: "cache (Redis)",
|
|
68
|
+
[ExtraFeature.HEALTH_CHECK]: "health-check",
|
|
69
|
+
[ExtraFeature.INTERNAL_CRON_JOBS]: "cron jobs",
|
|
70
|
+
[ExtraFeature.INTERNAL_EVENT_JOBS]: "event jobs"
|
|
71
|
+
};
|
|
72
|
+
export const FEATURE_PROMPT_LABELS = {
|
|
73
|
+
[ExtraFeature.CACHE]: "Cache (Redis)",
|
|
74
|
+
[ExtraFeature.HEALTH_CHECK]: "Health check (GET /health)",
|
|
75
|
+
[ExtraFeature.INTERNAL_CRON_JOBS]: "Jobs internos (Cron)",
|
|
76
|
+
[ExtraFeature.INTERNAL_EVENT_JOBS]: "Jobs internos (Eventos)"
|
|
77
|
+
};
|
|
78
|
+
export const TEMPLATE_LABELS = {
|
|
79
|
+
[Template.DEFAULT]: "Padrão",
|
|
80
|
+
[Template.CRUD_SAMPLE]: "Exemplo de CRUD"
|
|
81
|
+
};
|
|
82
|
+
export const ProjectMarker = {
|
|
83
|
+
PERSON_MODULE: "PersonModule",
|
|
84
|
+
SECURITY_MODULE: "SecurityModule",
|
|
85
|
+
AUTH_MODULE: "AuthModule",
|
|
86
|
+
HEALTH_CHECK_MODULE: "HealthCheckModule",
|
|
87
|
+
CACHE_SERVICE_PROVIDER: "CacheServiceProvider",
|
|
88
|
+
OAUTH_AUTH_LINK_HANDLER: "OAuthAuthLinkHandler",
|
|
89
|
+
REDIS_INDICATOR: "RedisIndicator"
|
|
90
|
+
};
|
|
91
|
+
export const DDD_LAYER_FOLDERS = [
|
|
92
|
+
"src/application",
|
|
93
|
+
"src/domain",
|
|
94
|
+
"src/infra",
|
|
95
|
+
"src/host",
|
|
96
|
+
"src/core",
|
|
97
|
+
"src/test"
|
|
98
|
+
];
|
|
99
|
+
export const DEFAULT_PACKAGE_MANAGER = "bun";
|
|
100
|
+
export function mapExtraFeatureToModule(feature) {
|
|
101
|
+
switch (feature) {
|
|
102
|
+
case ExtraFeature.CACHE:
|
|
103
|
+
return "cache" /* CACHE */;
|
|
104
|
+
case ExtraFeature.HEALTH_CHECK:
|
|
105
|
+
return "health" /* HEALTH */;
|
|
106
|
+
case ExtraFeature.INTERNAL_CRON_JOBS:
|
|
107
|
+
return "internal-cron-jobs" /* INTERNAL_CRON_JOBS */;
|
|
108
|
+
case ExtraFeature.INTERNAL_EVENT_JOBS:
|
|
109
|
+
return "internal-event-jobs" /* INTERNAL_EVENT_JOBS */;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function isAuthChoice(value) {
|
|
113
|
+
return value === AuthChoice.NONE || value === AuthChoice.JWT || value === AuthChoice.OAUTH2;
|
|
114
|
+
}
|
|
115
|
+
export function isAuthStrategy(value) {
|
|
116
|
+
return value === AuthStrategy.JWT || value === AuthStrategy.OAUTH2;
|
|
117
|
+
}
|
|
118
|
+
export function parseAuthStrategies(value, template) {
|
|
119
|
+
const normalized = value.trim().toLowerCase();
|
|
120
|
+
if (normalized === AuthChoice.NONE || normalized === "") {
|
|
121
|
+
if (template === Template.CRUD_SAMPLE) {
|
|
122
|
+
throw new Error("Template CRUD exige autenticação. Use: --auth jwt, --auth oauth2 ou --auth jwt,oauth2.");
|
|
123
|
+
}
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const strategies = normalized.split(",").map((item) => item.trim()).filter(Boolean).map((item) => {
|
|
127
|
+
if (isAuthStrategy(item)) {
|
|
128
|
+
return item;
|
|
129
|
+
}
|
|
130
|
+
throw new Error(`Autenticação desconhecida: "${item}". Use: none, jwt, oauth2 ou jwt,oauth2.`);
|
|
131
|
+
});
|
|
132
|
+
return Array.from(new Set(strategies));
|
|
133
|
+
}
|
|
134
|
+
export function formatAuthStrategies(strategies) {
|
|
135
|
+
if (strategies.length === 0) {
|
|
136
|
+
return AuthChoice.NONE;
|
|
137
|
+
}
|
|
138
|
+
return strategies.join(" + ");
|
|
139
|
+
}
|
|
140
|
+
export function resolveAuthStrategiesFromModule(authModuleSource) {
|
|
141
|
+
const strategies = [];
|
|
142
|
+
if (authModuleSource.includes("LoginController")) {
|
|
143
|
+
strategies.push(AuthStrategy.JWT);
|
|
144
|
+
}
|
|
145
|
+
if (authModuleSource.includes(ProjectMarker.OAUTH_AUTH_LINK_HANDLER)) {
|
|
146
|
+
strategies.push(AuthStrategy.OAUTH2);
|
|
147
|
+
}
|
|
148
|
+
return strategies;
|
|
149
|
+
}
|
|
150
|
+
export function resolveAuthStrategyFromModule(authModuleSource) {
|
|
151
|
+
return resolveAuthStrategiesFromModule(authModuleSource)[0] ?? AuthStrategy.JWT;
|
|
152
|
+
}
|
|
153
|
+
export function mergeAuthStrategies(current, incoming) {
|
|
154
|
+
return Array.from(new Set([...current, ...incoming]));
|
|
155
|
+
}
|
|
156
|
+
export function listMissingAuthStrategies(installed) {
|
|
157
|
+
const current = installed === false ? [] : installed;
|
|
158
|
+
return [AuthStrategy.JWT, AuthStrategy.OAUTH2].filter((strategy) => !current.includes(strategy));
|
|
159
|
+
}
|
|
160
|
+
export function mergeCrudSampleFeatures(features) {
|
|
161
|
+
return Array.from(new Set([...CRUD_BUNDLED_FEATURES, ...features]));
|
|
162
|
+
}
|
|
163
|
+
export function resolveNewProjectOptions(template, auth, features) {
|
|
164
|
+
if (template !== Template.CRUD_SAMPLE) {
|
|
165
|
+
return { auth, features };
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
auth: auth.length === 0 ? [AuthStrategy.JWT] : auth,
|
|
169
|
+
features: mergeCrudSampleFeatures(features)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getPackageRoot } from "../utils/get-package-root.js";
|
|
4
|
+
const packageJson = JSON.parse(readFileSync(path.join(getPackageRoot(import.meta.url), "package.json"), "utf8"));
|
|
5
|
+
export const CLI_VERSION = packageJson.version;
|
package/cli/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { CliCommand, CliFlag } from "./constants/cli-commands.js";
|
|
4
|
+
import { printHelp } from "./commands/help.js";
|
|
5
|
+
import { runAdd } from "./commands/add/index.js";
|
|
6
|
+
import { runNew } from "./commands/new/index.js";
|
|
7
|
+
import { runVersion } from "./commands/version.js";
|
|
8
|
+
import { parseCliArgs } from "./utils/cli-options.js";
|
|
9
|
+
const HELP_COMMANDS = new Set([
|
|
10
|
+
CliCommand.HELP,
|
|
11
|
+
CliFlag.HELP,
|
|
12
|
+
CliFlag.HELP_SHORT
|
|
13
|
+
]);
|
|
14
|
+
const VERSION_COMMANDS = new Set([
|
|
15
|
+
CliCommand.VERSION,
|
|
16
|
+
CliFlag.VERSION,
|
|
17
|
+
CliFlag.VERSION_SHORT
|
|
18
|
+
]);
|
|
19
|
+
const NEW_COMMANDS = new Set([
|
|
20
|
+
CliCommand.NEW,
|
|
21
|
+
CliFlag.NEW,
|
|
22
|
+
CliFlag.NEW_SHORT
|
|
23
|
+
]);
|
|
24
|
+
const ADD_COMMANDS = new Set([
|
|
25
|
+
CliCommand.ADD,
|
|
26
|
+
CliFlag.ADD,
|
|
27
|
+
CliFlag.ADD_SHORT
|
|
28
|
+
]);
|
|
29
|
+
async function main() {
|
|
30
|
+
const { command, commandArgs } = parseCliArgs(process.argv.slice(2));
|
|
31
|
+
if (command === undefined || HELP_COMMANDS.has(command)) {
|
|
32
|
+
printHelp();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (VERSION_COMMANDS.has(command)) {
|
|
36
|
+
runVersion();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (NEW_COMMANDS.has(command)) {
|
|
40
|
+
await runNew(commandArgs);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (ADD_COMMANDS.has(command)) {
|
|
44
|
+
await runAdd(commandArgs);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
console.error(`Comando desconhecido: ${command}
|
|
48
|
+
`);
|
|
49
|
+
printHelp();
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
main().catch((error) => {
|
|
53
|
+
console.error(error);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddArgKind,
|
|
3
|
+
AuthStrategy,
|
|
4
|
+
ExtraFeature,
|
|
5
|
+
FEATURE_LABELS,
|
|
6
|
+
formatAuthStrategies,
|
|
7
|
+
mergeAuthStrategies,
|
|
8
|
+
Template
|
|
9
|
+
} from "../constants/domain.js";
|
|
10
|
+
import {
|
|
11
|
+
installModule,
|
|
12
|
+
Modules
|
|
13
|
+
} from "./install-module.js";
|
|
14
|
+
import {
|
|
15
|
+
detectProjectState
|
|
16
|
+
} from "./detect-project-state.js";
|
|
17
|
+
import { formatCode } from "./format-code.js";
|
|
18
|
+
import { runCommand } from "./run-command.js";
|
|
19
|
+
import { getPackageManager } from "./get-package-manager.js";
|
|
20
|
+
import { resolveProjectPath } from "./resolve-project-path.js";
|
|
21
|
+
import { CACHE_PACKAGES } from "../constants/core-packages.js";
|
|
22
|
+
import {
|
|
23
|
+
restorePersonAuthExample,
|
|
24
|
+
restorePersonCacheFeatures,
|
|
25
|
+
restorePersonCronJobs,
|
|
26
|
+
restorePersonEventJobs,
|
|
27
|
+
upgradeCacheToRedis
|
|
28
|
+
} from "./restore-person-features.js";
|
|
29
|
+
import { normalizeAddArgs } from "./normalize-add-args.js";
|
|
30
|
+
import { restoreRedisHealthCheck } from "./patch-health-module.js";
|
|
31
|
+
import { patchAuthInstall } from "./patch-auth-install.js";
|
|
32
|
+
async function ensureMemoryCache(projectName, template) {
|
|
33
|
+
const state = detectProjectState(projectName);
|
|
34
|
+
if (state.cache) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
await installModule(Modules.CACHE, template, projectName, {
|
|
38
|
+
withRedis: false
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function installRedisCache(projectName, template, state) {
|
|
42
|
+
if (state.cache === "redis") {
|
|
43
|
+
return { installed: false, reason: "Cache Redis já está instalado." };
|
|
44
|
+
}
|
|
45
|
+
if (state.cache === "memory") {
|
|
46
|
+
await upgradeCacheToRedis(projectName);
|
|
47
|
+
const packageManager = getPackageManager(projectName);
|
|
48
|
+
await runCommand([packageManager, "add", ...CACHE_PACKAGES], resolveProjectPath(projectName));
|
|
49
|
+
} else {
|
|
50
|
+
await installModule(Modules.CACHE, template, projectName, {
|
|
51
|
+
withRedis: true
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (template === Template.CRUD_SAMPLE) {
|
|
55
|
+
await restorePersonCacheFeatures(projectName);
|
|
56
|
+
}
|
|
57
|
+
if (state.health) {
|
|
58
|
+
restoreRedisHealthCheck(projectName);
|
|
59
|
+
}
|
|
60
|
+
return { installed: true };
|
|
61
|
+
}
|
|
62
|
+
export async function addProjectFeatures(projectName = "", args) {
|
|
63
|
+
const results = [];
|
|
64
|
+
let state = detectProjectState(projectName);
|
|
65
|
+
const template = state.template;
|
|
66
|
+
const orderedArgs = normalizeAddArgs(args);
|
|
67
|
+
for (const arg of orderedArgs) {
|
|
68
|
+
if (arg.kind === AddArgKind.AUTH) {
|
|
69
|
+
const current = state.auth === false ? [] : state.auth;
|
|
70
|
+
const missing = arg.strategies.filter((strategy) => !current.includes(strategy));
|
|
71
|
+
if (missing.length === 0) {
|
|
72
|
+
results.push({
|
|
73
|
+
label: `auth (${formatAuthStrategies(arg.strategies)})`,
|
|
74
|
+
installed: false,
|
|
75
|
+
reason: `Autenticação ${formatAuthStrategies(current)} já está instalada.`
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const next = mergeAuthStrategies(current, missing);
|
|
80
|
+
if (current.length === 0) {
|
|
81
|
+
await ensureMemoryCache(projectName, template);
|
|
82
|
+
await installModule(Modules.AUTH, template, projectName, {
|
|
83
|
+
authStrategies: next
|
|
84
|
+
});
|
|
85
|
+
if (template === Template.CRUD_SAMPLE) {
|
|
86
|
+
await restorePersonAuthExample(projectName);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
await patchAuthInstall(projectName, next);
|
|
90
|
+
}
|
|
91
|
+
results.push({
|
|
92
|
+
label: `auth (${formatAuthStrategies(missing)})`,
|
|
93
|
+
installed: true
|
|
94
|
+
});
|
|
95
|
+
state = detectProjectState(projectName);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
switch (arg.feature) {
|
|
99
|
+
case ExtraFeature.CACHE: {
|
|
100
|
+
const cacheResult = await installRedisCache(projectName, template, state);
|
|
101
|
+
results.push({
|
|
102
|
+
label: FEATURE_LABELS[ExtraFeature.CACHE],
|
|
103
|
+
installed: cacheResult.installed,
|
|
104
|
+
reason: cacheResult.reason
|
|
105
|
+
});
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case ExtraFeature.HEALTH_CHECK: {
|
|
109
|
+
if (state.health) {
|
|
110
|
+
results.push({
|
|
111
|
+
label: FEATURE_LABELS[ExtraFeature.HEALTH_CHECK],
|
|
112
|
+
installed: false,
|
|
113
|
+
reason: "Health check já está instalado."
|
|
114
|
+
});
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
await installModule(Modules.HEALTH, template, projectName, {
|
|
118
|
+
withRedisIndicator: Boolean(state.cache)
|
|
119
|
+
});
|
|
120
|
+
results.push({
|
|
121
|
+
label: FEATURE_LABELS[ExtraFeature.HEALTH_CHECK],
|
|
122
|
+
installed: true
|
|
123
|
+
});
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case ExtraFeature.INTERNAL_CRON_JOBS: {
|
|
127
|
+
if (state.cronJobs) {
|
|
128
|
+
results.push({
|
|
129
|
+
label: FEATURE_LABELS[ExtraFeature.INTERNAL_CRON_JOBS],
|
|
130
|
+
installed: false,
|
|
131
|
+
reason: "Cron jobs já estão instalados."
|
|
132
|
+
});
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
await ensureMemoryCache(projectName, template);
|
|
136
|
+
await installModule(Modules.INTERNAL_CRON_JOBS, template, projectName);
|
|
137
|
+
if (template === Template.CRUD_SAMPLE) {
|
|
138
|
+
await restorePersonCronJobs(projectName);
|
|
139
|
+
}
|
|
140
|
+
results.push({
|
|
141
|
+
label: FEATURE_LABELS[ExtraFeature.INTERNAL_CRON_JOBS],
|
|
142
|
+
installed: true
|
|
143
|
+
});
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case ExtraFeature.INTERNAL_EVENT_JOBS: {
|
|
147
|
+
if (state.eventJobs) {
|
|
148
|
+
results.push({
|
|
149
|
+
label: FEATURE_LABELS[ExtraFeature.INTERNAL_EVENT_JOBS],
|
|
150
|
+
installed: false,
|
|
151
|
+
reason: "Event jobs já estão instalados."
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
await installModule(Modules.INTERNAL_EVENT_JOBS, template, projectName);
|
|
156
|
+
if (template === Template.CRUD_SAMPLE) {
|
|
157
|
+
await restorePersonEventJobs(projectName);
|
|
158
|
+
}
|
|
159
|
+
results.push({
|
|
160
|
+
label: FEATURE_LABELS[ExtraFeature.INTERNAL_EVENT_JOBS],
|
|
161
|
+
installed: true
|
|
162
|
+
});
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
state = detectProjectState(projectName);
|
|
167
|
+
}
|
|
168
|
+
await formatCode(projectName);
|
|
169
|
+
return results;
|
|
170
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AuthStrategy, ExtraFeature, Template } from "../constants/domain.js";
|
|
2
|
+
import {
|
|
3
|
+
installModule,
|
|
4
|
+
mapExtraFeatureToModule,
|
|
5
|
+
Modules,
|
|
6
|
+
resolveProjectFeatures
|
|
7
|
+
} from "./install-module.js";
|
|
8
|
+
import { adjustCrudPersonModule } from "./patch-person-features.js";
|
|
9
|
+
import { cleanDefaultTemplateWithoutAuth } from "./remove-sample-parts.js";
|
|
10
|
+
import { formatCode } from "./format-code.js";
|
|
11
|
+
export async function applyOptionalFeatures(options) {
|
|
12
|
+
const projectName = options.projectName ?? "";
|
|
13
|
+
const projectFeatures = resolveProjectFeatures(options.features, options.auth);
|
|
14
|
+
if (options.template === Template.CRUD_SAMPLE) {
|
|
15
|
+
adjustCrudPersonModule(projectName, {
|
|
16
|
+
cache: projectFeatures.cacheForCrud,
|
|
17
|
+
cronJobs: projectFeatures.cronJobs,
|
|
18
|
+
eventJobs: projectFeatures.eventJobs,
|
|
19
|
+
auth: options.auth.length > 0
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (projectFeatures.cache) {
|
|
23
|
+
await installModule(Modules.CACHE, options.template, projectName, {
|
|
24
|
+
withRedis: projectFeatures.cacheWithRedis,
|
|
25
|
+
skipPackages: options.skipPackages
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (options.auth.length > 0) {
|
|
29
|
+
await installModule(Modules.AUTH, options.template, projectName, {
|
|
30
|
+
authStrategies: options.auth,
|
|
31
|
+
skipPackages: options.skipPackages
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
for (const feature of options.features) {
|
|
35
|
+
if (feature === ExtraFeature.CACHE) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
await installModule(mapExtraFeatureToModule(feature), options.template, projectName, feature === ExtraFeature.HEALTH_CHECK ? {
|
|
39
|
+
withRedisIndicator: projectFeatures.cache,
|
|
40
|
+
skipPackages: options.skipPackages
|
|
41
|
+
} : { skipPackages: options.skipPackages });
|
|
42
|
+
}
|
|
43
|
+
if (options.template === Template.DEFAULT && options.auth.length === 0) {
|
|
44
|
+
await cleanDefaultTemplateWithoutAuth(projectName);
|
|
45
|
+
}
|
|
46
|
+
await formatCode(projectName);
|
|
47
|
+
}
|
|
48
|
+
export { addProjectFeatures } from "./add-project-features.js";
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AuthStrategy } from "../constants/domain.js";
|
|
4
|
+
import {
|
|
5
|
+
appModuleMustContain,
|
|
6
|
+
appModuleMustNotContain,
|
|
7
|
+
authModuleMustContain,
|
|
8
|
+
authModuleMustNotContain,
|
|
9
|
+
cacheConstantsMustContain,
|
|
10
|
+
cacheConstantsMustNotContain,
|
|
11
|
+
defineDocumentationMustContain,
|
|
12
|
+
defineDocumentationMustNotContain,
|
|
13
|
+
envExampleMustContain,
|
|
14
|
+
envExampleMustNotContain,
|
|
15
|
+
envSourceMustContain,
|
|
16
|
+
envSourceMustNotContain,
|
|
17
|
+
forbiddenContentPatterns,
|
|
18
|
+
forbiddenPathsForProfile,
|
|
19
|
+
iauthMustContain,
|
|
20
|
+
iauthMustNotContain,
|
|
21
|
+
requiredPathsForProfile,
|
|
22
|
+
resolveAuthProfile,
|
|
23
|
+
securityModuleMustContain,
|
|
24
|
+
securityModuleMustNotContain
|
|
25
|
+
} from "../constants/auth-strategy-checklist.js";
|
|
26
|
+
import { resolveProjectPath } from "./resolve-project-path.js";
|
|
27
|
+
const CONTENT_SCAN_SKIP = new Set([
|
|
28
|
+
"src/host/open-api/define-documentation.ts",
|
|
29
|
+
"src/test/host/is-public-open-api.spec.ts",
|
|
30
|
+
"src/test/core/auth.guard.spec.ts"
|
|
31
|
+
]);
|
|
32
|
+
function walkSourceFiles(directory, callback) {
|
|
33
|
+
if (!existsSync(directory)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
37
|
+
const absolutePath = path.join(directory, entry.name);
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
walkSourceFiles(absolutePath, (abs, rel) => {
|
|
40
|
+
callback(abs, path.join(entry.name, rel));
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
45
|
+
callback(absolutePath, entry.name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function isOAuthPathSegment(relativePath) {
|
|
50
|
+
const normalized = relativePath.replace(/\\/g, "/").toLowerCase();
|
|
51
|
+
return normalized.includes("/oauth2/") || normalized.includes("/oauth2.") || /(^|\/)oauth[^/]*\.ts$/.test(normalized) || /oauth2[^/]*\.ts$/.test(normalized);
|
|
52
|
+
}
|
|
53
|
+
function isJwtLoginPathSegment(relativePath) {
|
|
54
|
+
const normalized = relativePath.replace(/\\/g, "/").toLowerCase();
|
|
55
|
+
return normalized.includes("/auth/login") || normalized.includes("login.controller.ts") || normalized.includes("login.handler.spec.ts");
|
|
56
|
+
}
|
|
57
|
+
function readOptional(projectRoot, relativePath) {
|
|
58
|
+
const filePath = path.join(projectRoot, relativePath);
|
|
59
|
+
return existsSync(filePath) ? readFileSync(filePath, "utf8") : null;
|
|
60
|
+
}
|
|
61
|
+
function expectContains(violations, label, source, patterns) {
|
|
62
|
+
if (!source) {
|
|
63
|
+
if (patterns.length > 0) {
|
|
64
|
+
violations.push(`missing:${label}`);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const pattern of patterns) {
|
|
69
|
+
if (!source.includes(pattern)) {
|
|
70
|
+
violations.push(`${label}: ausente "${pattern}"`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function expectNotContains(violations, label, source, patterns) {
|
|
75
|
+
if (!source) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
for (const pattern of patterns) {
|
|
79
|
+
if (source.includes(pattern)) {
|
|
80
|
+
violations.push(`${label}: inesperado "${pattern}"`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function listAuthStrategyViolations(projectName = "", selection) {
|
|
85
|
+
const profile = resolveAuthProfile(selection);
|
|
86
|
+
const projectRoot = resolveProjectPath(projectName);
|
|
87
|
+
const violations = [];
|
|
88
|
+
for (const relativePath of requiredPathsForProfile(profile)) {
|
|
89
|
+
if (!existsSync(path.join(projectRoot, relativePath))) {
|
|
90
|
+
violations.push(`path:obrigatório ausente ${relativePath}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const relativePath of forbiddenPathsForProfile(profile)) {
|
|
94
|
+
if (existsSync(path.join(projectRoot, relativePath))) {
|
|
95
|
+
violations.push(`path:proibido presente ${relativePath}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const srcDir = path.join(projectRoot, "src");
|
|
99
|
+
if (profile === "none") {
|
|
100
|
+
walkSourceFiles(srcDir, (_absolutePath, relativePath) => {
|
|
101
|
+
const normalized = relativePath.replace(/\\/g, "/");
|
|
102
|
+
if (isOAuthPathSegment(normalized) || isJwtLoginPathSegment(normalized)) {
|
|
103
|
+
violations.push(`path:src/${normalized}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (profile === "jwt") {
|
|
108
|
+
walkSourceFiles(srcDir, (_absolutePath, relativePath) => {
|
|
109
|
+
const normalized = relativePath.replace(/\\/g, "/");
|
|
110
|
+
if (isOAuthPathSegment(normalized)) {
|
|
111
|
+
violations.push(`path:oauth2 inesperado src/${normalized}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (profile === "oauth2") {
|
|
116
|
+
walkSourceFiles(srcDir, (_absolutePath, relativePath) => {
|
|
117
|
+
const normalized = relativePath.replace(/\\/g, "/");
|
|
118
|
+
if (isJwtLoginPathSegment(normalized)) {
|
|
119
|
+
violations.push(`path:login jwt inesperado src/${normalized}`);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const envExample = readOptional(projectRoot, ".env.example");
|
|
124
|
+
const envSource = readOptional(projectRoot, "src/core/env.ts");
|
|
125
|
+
const iauth = readOptional(projectRoot, "src/domain/auth/services/iauth.service.ts");
|
|
126
|
+
const authModule = readOptional(projectRoot, "src/host/controllers/auth/auth.module.ts");
|
|
127
|
+
const securityModule = readOptional(projectRoot, "src/host/security/security.module.ts");
|
|
128
|
+
const appModule = readOptional(projectRoot, "src/host/app.module.ts");
|
|
129
|
+
const cacheConstants = readOptional(projectRoot, "src/core/constants/cache.constants.ts");
|
|
130
|
+
const defineDocumentation = readOptional(projectRoot, "src/host/open-api/define-documentation.ts");
|
|
131
|
+
expectContains(violations, "env.example", envExample, envExampleMustContain(profile));
|
|
132
|
+
expectNotContains(violations, "env.example", envExample, envExampleMustNotContain(profile));
|
|
133
|
+
expectContains(violations, "env.ts", envSource, envSourceMustContain(profile));
|
|
134
|
+
expectNotContains(violations, "env.ts", envSource, envSourceMustNotContain(profile));
|
|
135
|
+
expectContains(violations, "iauth.service", iauth, iauthMustContain(profile));
|
|
136
|
+
expectNotContains(violations, "iauth.service", iauth, iauthMustNotContain(profile));
|
|
137
|
+
expectContains(violations, "auth.module", authModule, authModuleMustContain(profile));
|
|
138
|
+
expectNotContains(violations, "auth.module", authModule, authModuleMustNotContain(profile));
|
|
139
|
+
expectContains(violations, "security.module", securityModule, securityModuleMustContain(profile));
|
|
140
|
+
expectNotContains(violations, "security.module", securityModule, securityModuleMustNotContain(profile));
|
|
141
|
+
expectContains(violations, "app.module", appModule, appModuleMustContain(profile));
|
|
142
|
+
expectNotContains(violations, "app.module", appModule, appModuleMustNotContain(profile));
|
|
143
|
+
expectContains(violations, "cache.constants", cacheConstants, cacheConstantsMustContain(profile));
|
|
144
|
+
expectNotContains(violations, "cache.constants", cacheConstants, cacheConstantsMustNotContain(profile));
|
|
145
|
+
expectContains(violations, "define-documentation", defineDocumentation, defineDocumentationMustContain(profile));
|
|
146
|
+
expectNotContains(violations, "define-documentation", defineDocumentation, defineDocumentationMustNotContain(profile));
|
|
147
|
+
const forbiddenPatterns = forbiddenContentPatterns(profile);
|
|
148
|
+
if (forbiddenPatterns.length > 0) {
|
|
149
|
+
walkSourceFiles(srcDir, (absolutePath, relativePath) => {
|
|
150
|
+
const normalized = relativePath.replace(/\\/g, "/");
|
|
151
|
+
const srcRelative = `src/${normalized}`;
|
|
152
|
+
if (CONTENT_SCAN_SKIP.has(srcRelative)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const source = readFileSync(absolutePath, "utf8");
|
|
156
|
+
for (const pattern of forbiddenPatterns) {
|
|
157
|
+
if (source.includes(pattern)) {
|
|
158
|
+
violations.push(`content:${srcRelative} contém "${pattern}"`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return [...new Set(violations)].sort();
|
|
164
|
+
}
|
|
165
|
+
export function assertAuthStrategyProject(projectName = "", selection) {
|
|
166
|
+
const profile = resolveAuthProfile(selection);
|
|
167
|
+
const violations = listAuthStrategyViolations(projectName, selection);
|
|
168
|
+
if (violations.length > 0) {
|
|
169
|
+
throw new Error(`Checklist auth "${profile}" falhou:
|
|
170
|
+
${violations.join(`
|
|
171
|
+
`)}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export function assertNoOAuthArtifactsInProject(projectName = "") {
|
|
175
|
+
assertAuthStrategyProject(projectName, [AuthStrategy.JWT]);
|
|
176
|
+
}
|
|
177
|
+
export function listOAuthArtifactViolations(projectName = "") {
|
|
178
|
+
return listAuthStrategyViolations(projectName, [AuthStrategy.JWT]).filter((item) => !item.startsWith("path:obrigatório"));
|
|
179
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
let verbose = false;
|
|
2
|
+
export function setCliVerbose(value) {
|
|
3
|
+
verbose = value;
|
|
4
|
+
}
|
|
5
|
+
export function isCliVerbose() {
|
|
6
|
+
return verbose;
|
|
7
|
+
}
|
|
8
|
+
export function resetCliVerbose() {
|
|
9
|
+
verbose = false;
|
|
10
|
+
}
|
|
11
|
+
export function parseCliArgs(argv) {
|
|
12
|
+
let enabled = false;
|
|
13
|
+
const rest = [];
|
|
14
|
+
for (const arg of argv) {
|
|
15
|
+
if (arg === "--verbose") {
|
|
16
|
+
enabled = true;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
rest.push(arg);
|
|
20
|
+
}
|
|
21
|
+
setCliVerbose(enabled);
|
|
22
|
+
return {
|
|
23
|
+
command: rest[0],
|
|
24
|
+
commandArgs: rest.slice(1),
|
|
25
|
+
verbose: enabled
|
|
26
|
+
};
|
|
27
|
+
}
|