@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,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthStrategy,
|
|
3
|
+
FEATURE_ALIASES,
|
|
4
|
+
parseAuthStrategies,
|
|
5
|
+
Template,
|
|
6
|
+
TEMPLATE_ALIASES
|
|
7
|
+
} from "../constants/domain.js";
|
|
8
|
+
function parseFeatures(value) {
|
|
9
|
+
return value.split(",").map((item) => item.trim().toLowerCase()).filter(Boolean).map((item) => {
|
|
10
|
+
const feature = FEATURE_ALIASES[item];
|
|
11
|
+
if (!feature) {
|
|
12
|
+
throw new Error(`Feature desconhecida: "${item}". Use: cache, health, cron, events.`);
|
|
13
|
+
}
|
|
14
|
+
return feature;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function parseTemplate(value) {
|
|
18
|
+
const template = TEMPLATE_ALIASES[value.toLowerCase()];
|
|
19
|
+
if (!template) {
|
|
20
|
+
throw new Error(`Template desconhecido: "${value}". Use: default, crud.`);
|
|
21
|
+
}
|
|
22
|
+
return template;
|
|
23
|
+
}
|
|
24
|
+
function parsePackageManager(value) {
|
|
25
|
+
if (value === "bun" || value === "npm" || value === "pnpm") {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`Gerenciador desconhecido: "${value}". Use: bun, npm, pnpm.`);
|
|
29
|
+
}
|
|
30
|
+
function parseAuth(value, template) {
|
|
31
|
+
return parseAuthStrategies(value, template);
|
|
32
|
+
}
|
|
33
|
+
export function parseNewArgs(args) {
|
|
34
|
+
let projectName;
|
|
35
|
+
let packageManager;
|
|
36
|
+
let template;
|
|
37
|
+
let auth;
|
|
38
|
+
let features = [];
|
|
39
|
+
let yes = false;
|
|
40
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
41
|
+
const arg = args[index];
|
|
42
|
+
if (!arg) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (arg === "-y" || arg === "--yes") {
|
|
46
|
+
yes = true;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (arg === "--template" || arg === "-t") {
|
|
50
|
+
const value = args[index + 1];
|
|
51
|
+
if (!value) {
|
|
52
|
+
throw new Error("Valor ausente para --template.");
|
|
53
|
+
}
|
|
54
|
+
template = parseTemplate(value);
|
|
55
|
+
index += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (arg === "--package-manager" || arg === "--pm") {
|
|
59
|
+
const value = args[index + 1];
|
|
60
|
+
if (!value) {
|
|
61
|
+
throw new Error("Valor ausente para --package-manager.");
|
|
62
|
+
}
|
|
63
|
+
packageManager = parsePackageManager(value);
|
|
64
|
+
index += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (arg === "--auth") {
|
|
68
|
+
const value = args[index + 1];
|
|
69
|
+
if (!value) {
|
|
70
|
+
throw new Error("Valor ausente para --auth.");
|
|
71
|
+
}
|
|
72
|
+
auth = parseAuth(value, template);
|
|
73
|
+
index += 1;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (arg === "--features") {
|
|
77
|
+
const value = args[index + 1];
|
|
78
|
+
if (!value) {
|
|
79
|
+
throw new Error("Valor ausente para --features.");
|
|
80
|
+
}
|
|
81
|
+
features = parseFeatures(value);
|
|
82
|
+
index += 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (arg.startsWith("-")) {
|
|
86
|
+
throw new Error(`Flag desconhecida: ${arg}`);
|
|
87
|
+
}
|
|
88
|
+
if (!projectName) {
|
|
89
|
+
projectName = arg;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (auth && template === Template.CRUD_SAMPLE && auth.length === 0) {
|
|
93
|
+
throw new Error("Template CRUD exige autenticação. Use: --auth jwt, --auth oauth2 ou --auth jwt,oauth2.");
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
projectName,
|
|
97
|
+
packageManager,
|
|
98
|
+
template,
|
|
99
|
+
auth,
|
|
100
|
+
features,
|
|
101
|
+
yes,
|
|
102
|
+
interactive: !yes
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function assertNewArgsComplete(args) {
|
|
106
|
+
if (!args.projectName) {
|
|
107
|
+
throw new Error("Nome do projeto é obrigatório.");
|
|
108
|
+
}
|
|
109
|
+
if (!args.packageManager) {
|
|
110
|
+
throw new Error("Gerenciador de pacotes é obrigatório.");
|
|
111
|
+
}
|
|
112
|
+
if (!args.template) {
|
|
113
|
+
throw new Error("Template é obrigatório.");
|
|
114
|
+
}
|
|
115
|
+
if (args.auth === undefined) {
|
|
116
|
+
throw new Error("Autenticação é obrigatória.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function buildNewProjectConfig(parsed, overrides) {
|
|
120
|
+
return {
|
|
121
|
+
name: overrides.name,
|
|
122
|
+
packageManager: parsed.packageManager ?? overrides.packageManager,
|
|
123
|
+
template: parsed.template ?? overrides.template,
|
|
124
|
+
auth: parsed.auth ?? overrides.auth,
|
|
125
|
+
features: parsed.features.length > 0 ? parsed.features : overrides.features
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { cpSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AuthStrategy } from "../constants/domain.js";
|
|
4
|
+
import { getSourceCodePath } from "./get-source-code-path.js";
|
|
5
|
+
import { patchMainForAuth } from "./patch-main.js";
|
|
6
|
+
import { removeImportLines } from "./project-files.js";
|
|
7
|
+
import { resolveProjectPath } from "./resolve-project-path.js";
|
|
8
|
+
import { patchEnvForAuthStrategies } from "./patch-env.js";
|
|
9
|
+
import { syncDefineDocumentationForProject } from "./patch-define-documentation.js";
|
|
10
|
+
import { syncAuthStrategySupportFiles } from "./sync-auth-strategy-files.js";
|
|
11
|
+
import {
|
|
12
|
+
installAuthArtifactsForStrategies,
|
|
13
|
+
pruneAuthArtifactsForStrategies
|
|
14
|
+
} from "./prune-auth-strategies.js";
|
|
15
|
+
function patchFile(projectName, relativePath, replacers) {
|
|
16
|
+
const filePath = path.join(resolveProjectPath(projectName), relativePath);
|
|
17
|
+
let content = readFileSync(filePath, "utf8");
|
|
18
|
+
for (const { from, to } of replacers) {
|
|
19
|
+
if (content.includes(from)) {
|
|
20
|
+
content = content.replace(from, to);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
writeFileSync(filePath, content);
|
|
24
|
+
}
|
|
25
|
+
export function patchAppModuleForAuth(content) {
|
|
26
|
+
if (content.includes("import { SecurityModule }")) {
|
|
27
|
+
return content;
|
|
28
|
+
}
|
|
29
|
+
const patched = content.replace("import { Module } from '@nestjs/common';", `import { Module } from '@nestjs/common';
|
|
30
|
+
import { AuthModule } from './controllers/auth/auth.module.js';
|
|
31
|
+
import { SecurityModule } from './security/security.module';`);
|
|
32
|
+
if (patched.includes("PersonModule,")) {
|
|
33
|
+
return patched.replace(" PersonModule,", ` SecurityModule,
|
|
34
|
+
AuthModule,
|
|
35
|
+
PersonModule,`);
|
|
36
|
+
}
|
|
37
|
+
return patched.replace(/(ConfigModule\.forRoot\(\{[\s\S]*?\}\),)\n/, `$1
|
|
38
|
+
SecurityModule,
|
|
39
|
+
AuthModule,
|
|
40
|
+
`);
|
|
41
|
+
}
|
|
42
|
+
export function patchRepositoryForAuth(content) {
|
|
43
|
+
if (content.includes("IUserRepository")) {
|
|
44
|
+
return content;
|
|
45
|
+
}
|
|
46
|
+
let patched = content.replace("import { Module } from '@nestjs/common';", `import { IUserRepository } from '@/domain/repositories/iuser.repository';
|
|
47
|
+
import { Module } from '@nestjs/common';`);
|
|
48
|
+
patched = patched.replace("import { DatabaseModule } from '@/infra/database/database.module';", `import { DatabaseModule } from '@/infra/database/database.module';
|
|
49
|
+
import { UserRepository } from '@/infra/repositories/user.repository';`);
|
|
50
|
+
if (patched.includes("providers: [")) {
|
|
51
|
+
patched = patched.replace("providers: [", `providers: [
|
|
52
|
+
{ provide: IUserRepository, useClass: UserRepository },`);
|
|
53
|
+
} else {
|
|
54
|
+
patched = patched.replace("imports: [DatabaseModule],", `imports: [DatabaseModule],
|
|
55
|
+
providers: [{ provide: IUserRepository, useClass: UserRepository }],`);
|
|
56
|
+
}
|
|
57
|
+
if (patched.includes("exports: [DatabaseModule]")) {
|
|
58
|
+
patched = patched.replace("exports: [DatabaseModule]", "exports: [DatabaseModule, IUserRepository]");
|
|
59
|
+
} else {
|
|
60
|
+
patched = patched.replace("exports: [DatabaseModule,", "exports: [DatabaseModule, IUserRepository,");
|
|
61
|
+
}
|
|
62
|
+
return patched;
|
|
63
|
+
}
|
|
64
|
+
export function patchDataSourceForAuth(content) {
|
|
65
|
+
if (content.includes("@/domain/entities/user/user")) {
|
|
66
|
+
return content;
|
|
67
|
+
}
|
|
68
|
+
return content.replace("import { EnvService } from '@/infra/common/env.service';", `import { User } from '@/domain/entities/user/user';
|
|
69
|
+
import { EnvService } from '@/infra/common/env.service';`).replace(/entities: \[([^\]]*)\],/, (match, entities) => {
|
|
70
|
+
const trimmed = entities.trim();
|
|
71
|
+
if (!trimmed) {
|
|
72
|
+
return "entities: [User],";
|
|
73
|
+
}
|
|
74
|
+
if (trimmed.includes("User")) {
|
|
75
|
+
return match;
|
|
76
|
+
}
|
|
77
|
+
return `entities: [${trimmed}, User],`;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const JWT_OAUTH_IMPORTS = [
|
|
81
|
+
"@/application/auth/oauth2/auth-link/auth-link.handler",
|
|
82
|
+
"@/application/auth/oauth2/exchange-code/exchange-code.handler",
|
|
83
|
+
"@/application/auth/oauth2/scalar-token/scalar-oauth-token.handler",
|
|
84
|
+
"../oauth2/auth-link.controller",
|
|
85
|
+
"../oauth2/exchange-code.controller",
|
|
86
|
+
"../oauth2/oauth-callback.controller",
|
|
87
|
+
"../oauth2/scalar-token.controller"
|
|
88
|
+
];
|
|
89
|
+
const JWT_OAUTH_SYMBOLS = [
|
|
90
|
+
"OAuthAuthLinkController",
|
|
91
|
+
"OAuthExchangeCodeController",
|
|
92
|
+
"OAuthCallbackController",
|
|
93
|
+
"ScalarOAuthTokenController",
|
|
94
|
+
"OAuthAuthLinkHandler",
|
|
95
|
+
"OAuthExchangeCodeHandler",
|
|
96
|
+
"ScalarOAuthTokenHandler"
|
|
97
|
+
];
|
|
98
|
+
export function patchAuthModuleForJwt(content) {
|
|
99
|
+
let patched = removeImportLines(content, JWT_OAUTH_IMPORTS);
|
|
100
|
+
for (const symbol of JWT_OAUTH_SYMBOLS) {
|
|
101
|
+
patched = patched.replace(new RegExp(`\\s*${symbol},\\n`, "g"), "");
|
|
102
|
+
}
|
|
103
|
+
return patched;
|
|
104
|
+
}
|
|
105
|
+
const JWT_LOGIN_IMPORTS = [
|
|
106
|
+
"@/application/auth/login/login.handler",
|
|
107
|
+
"./login.controller"
|
|
108
|
+
];
|
|
109
|
+
const JWT_LOGIN_SYMBOLS = ["LoginController", "LoginHandler"];
|
|
110
|
+
export function patchAuthModuleForOAuth2(content) {
|
|
111
|
+
let patched = removeImportLines(content, JWT_LOGIN_IMPORTS);
|
|
112
|
+
for (const symbol of JWT_LOGIN_SYMBOLS) {
|
|
113
|
+
patched = patched.replace(new RegExp(`\\s*${symbol},\\n`, "g"), "");
|
|
114
|
+
}
|
|
115
|
+
return patched;
|
|
116
|
+
}
|
|
117
|
+
export function applyAuthModuleStrategies(content, strategies) {
|
|
118
|
+
const hasJwt = strategies.includes(AuthStrategy.JWT);
|
|
119
|
+
const hasOauth = strategies.includes(AuthStrategy.OAUTH2);
|
|
120
|
+
if (hasJwt && hasOauth) {
|
|
121
|
+
return content;
|
|
122
|
+
}
|
|
123
|
+
if (hasJwt) {
|
|
124
|
+
return patchAuthModuleForJwt(content);
|
|
125
|
+
}
|
|
126
|
+
if (hasOauth) {
|
|
127
|
+
return patchAuthModuleForOAuth2(content);
|
|
128
|
+
}
|
|
129
|
+
return content;
|
|
130
|
+
}
|
|
131
|
+
export function syncAuthModuleForProject(projectName, strategies) {
|
|
132
|
+
const authModulePath = path.join(resolveProjectPath(projectName), "src/host/controllers/auth/auth.module.ts");
|
|
133
|
+
cpSync(path.join(getSourceCodePath(), "src/host/controllers/auth/auth.module.ts"), authModulePath, { force: true });
|
|
134
|
+
writeFileSync(authModulePath, applyAuthModuleStrategies(readFileSync(authModulePath, "utf8"), strategies));
|
|
135
|
+
}
|
|
136
|
+
const domainAuthServiceJwtOnly = `import { JwtClaims } from '@/core/auth/jwt-claims';
|
|
137
|
+
|
|
138
|
+
export abstract class IJwtTokenService {
|
|
139
|
+
abstract signAccessToken(claims: JwtClaims): string;
|
|
140
|
+
abstract signRefreshToken(claims: JwtClaims): string;
|
|
141
|
+
abstract signTokenPair(claims: JwtClaims): {
|
|
142
|
+
accessToken: string;
|
|
143
|
+
access_token: string;
|
|
144
|
+
refreshToken: string;
|
|
145
|
+
refresh_token: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
export function syncDomainAuthServiceForProject(projectName, strategies) {
|
|
150
|
+
const hasJwt = strategies.includes(AuthStrategy.JWT);
|
|
151
|
+
const hasOauth = strategies.includes(AuthStrategy.OAUTH2);
|
|
152
|
+
const servicePath = path.join(resolveProjectPath(projectName), "src/domain/auth/services/iauth.service.ts");
|
|
153
|
+
mkdirSync(path.dirname(servicePath), { recursive: true });
|
|
154
|
+
if (hasJwt && !hasOauth) {
|
|
155
|
+
writeFileSync(servicePath, domainAuthServiceJwtOnly);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
cpSync(path.join(getSourceCodePath(), "src/domain/auth/services/iauth.service.ts"), servicePath, { force: true });
|
|
159
|
+
}
|
|
160
|
+
const SECURITY_OAUTH_IMPORTS = [
|
|
161
|
+
"@/core/auth/oauth-provider.registry",
|
|
162
|
+
"@/infra/auth/oauth2-auth.service"
|
|
163
|
+
];
|
|
164
|
+
const SECURITY_OAUTH_SYMBOLS = ["OAuthProviderRegistry", "IOAuth2Service"];
|
|
165
|
+
export function patchSecurityModuleForJwt(content) {
|
|
166
|
+
let patched = removeImportLines(content, SECURITY_OAUTH_IMPORTS);
|
|
167
|
+
patched = patched.replace(/import \{\n IJwtTokenService,\n IOAuth2Service,\n\} from '@\/domain\/auth\/services\/iauth.service';/, "import { IJwtTokenService } from '@/domain/auth/services/iauth.service';");
|
|
168
|
+
patched = patched.replace(/\s*\{ provide: IOAuth2Service, useClass: OAuth2AuthService \},\n/g, "");
|
|
169
|
+
for (const symbol of SECURITY_OAUTH_SYMBOLS) {
|
|
170
|
+
patched = patched.replace(new RegExp(`\\s*${symbol},\\s*\\n`, "g"), "");
|
|
171
|
+
patched = patched.replace(new RegExp(`\\s*${symbol},`, "g"), "");
|
|
172
|
+
}
|
|
173
|
+
return patched;
|
|
174
|
+
}
|
|
175
|
+
export function syncSecurityModuleForProject(projectName, strategies) {
|
|
176
|
+
const hasJwt = strategies.includes(AuthStrategy.JWT);
|
|
177
|
+
const hasOauth = strategies.includes(AuthStrategy.OAUTH2);
|
|
178
|
+
const securityModulePath = path.join(resolveProjectPath(projectName), "src/host/security/security.module.ts");
|
|
179
|
+
cpSync(path.join(getSourceCodePath(), "src/host/security/security.module.ts"), securityModulePath, { force: true });
|
|
180
|
+
if (hasJwt && !hasOauth) {
|
|
181
|
+
writeFileSync(securityModulePath, patchSecurityModuleForJwt(readFileSync(securityModulePath, "utf8")));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export async function patchAuthInstall(projectName, strategies) {
|
|
185
|
+
if (strategies.length === 0) {
|
|
186
|
+
throw new Error("Informe ao menos uma estratégia de autenticação.");
|
|
187
|
+
}
|
|
188
|
+
installAuthArtifactsForStrategies(projectName, strategies);
|
|
189
|
+
const projectRoot = resolveProjectPath(projectName);
|
|
190
|
+
const appModulePath = path.join(projectRoot, "src/host/app.module.ts");
|
|
191
|
+
const appModule = readFileSync(appModulePath, "utf8");
|
|
192
|
+
const hasSecurityModule = appModule.includes("SecurityModule");
|
|
193
|
+
if (!hasSecurityModule) {
|
|
194
|
+
writeFileSync(appModulePath, patchAppModuleForAuth(appModule));
|
|
195
|
+
writeFileSync(path.join(projectRoot, "src/infra/repositories/repository.module.ts"), patchRepositoryForAuth(readFileSync(path.join(projectRoot, "src/infra/repositories/repository.module.ts"), "utf8")));
|
|
196
|
+
writeFileSync(path.join(projectRoot, "src/infra/database/data-source-factory.ts"), patchDataSourceForAuth(readFileSync(path.join(projectRoot, "src/infra/database/data-source-factory.ts"), "utf8")));
|
|
197
|
+
const mainPath = path.join(projectRoot, "src/host/main.ts");
|
|
198
|
+
writeFileSync(mainPath, patchMainForAuth(readFileSync(mainPath, "utf8")));
|
|
199
|
+
patchFile(projectName, "src/host/main.ts", [
|
|
200
|
+
{
|
|
201
|
+
from: "import { HttpAdapterHost } from '@nestjs/core';",
|
|
202
|
+
to: `import { HttpAdapterHost } from '@nestjs/core';
|
|
203
|
+
import { AuthGuard } from './security/guards/auth.guard.js';
|
|
204
|
+
import { ProfilesGuard } from './security/guards/profiles.guard';`
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
from: " await app.listen",
|
|
208
|
+
to: ` app.useGlobalGuards(
|
|
209
|
+
await app.resolve(AuthGuard),
|
|
210
|
+
await app.resolve(ProfilesGuard),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
await app.listen`
|
|
214
|
+
}
|
|
215
|
+
]);
|
|
216
|
+
}
|
|
217
|
+
syncAuthModuleForProject(projectName, strategies);
|
|
218
|
+
syncDomainAuthServiceForProject(projectName, strategies);
|
|
219
|
+
syncSecurityModuleForProject(projectName, strategies);
|
|
220
|
+
syncDefineDocumentationForProject(projectName, strategies);
|
|
221
|
+
syncAuthStrategySupportFiles(projectName, strategies);
|
|
222
|
+
pruneAuthArtifactsForStrategies(projectName, strategies);
|
|
223
|
+
patchEnvForAuthStrategies(projectName, strategies);
|
|
224
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { cpSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AuthStrategy } from "../constants/domain.js";
|
|
4
|
+
import { getSourceCodePath } from "./get-source-code-path.js";
|
|
5
|
+
import { resolveProjectPath } from "./resolve-project-path.js";
|
|
6
|
+
const defineDocumentationWithoutAuth = `import { INestApplication } from '@nestjs/common';
|
|
7
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
8
|
+
import { apiReference } from '@scalar/nestjs-api-reference';
|
|
9
|
+
import packageJson from '../../../package.json';
|
|
10
|
+
|
|
11
|
+
const DOC_ENDPOINT = '/doc';
|
|
12
|
+
|
|
13
|
+
export async function defineDocumentation(app: INestApplication) {
|
|
14
|
+
const document = SwaggerModule.createDocument(
|
|
15
|
+
app,
|
|
16
|
+
new DocumentBuilder()
|
|
17
|
+
.setTitle(packageJson.name)
|
|
18
|
+
.setVersion(packageJson.version)
|
|
19
|
+
.build(),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
SwaggerModule.setup(DOC_ENDPOINT, app, document, { swaggerUiEnabled: false });
|
|
23
|
+
|
|
24
|
+
app.use(
|
|
25
|
+
DOC_ENDPOINT,
|
|
26
|
+
apiReference({
|
|
27
|
+
darkMode: true,
|
|
28
|
+
spec: { content: document },
|
|
29
|
+
metaData: {
|
|
30
|
+
title: packageJson.name,
|
|
31
|
+
version: packageJson.version,
|
|
32
|
+
},
|
|
33
|
+
hideModels: true,
|
|
34
|
+
hideDownloadButton: true,
|
|
35
|
+
hideClientButton: true,
|
|
36
|
+
hiddenClients: [
|
|
37
|
+
'libcurl',
|
|
38
|
+
'clj_http',
|
|
39
|
+
'restsharp',
|
|
40
|
+
'native',
|
|
41
|
+
'http1.1',
|
|
42
|
+
'asynchttp',
|
|
43
|
+
'nethttp',
|
|
44
|
+
'okhttp',
|
|
45
|
+
'unirest',
|
|
46
|
+
'xhr',
|
|
47
|
+
'request',
|
|
48
|
+
'nsurlsession',
|
|
49
|
+
'cohttp',
|
|
50
|
+
'guzzle',
|
|
51
|
+
'http1',
|
|
52
|
+
'http2',
|
|
53
|
+
'webrequest',
|
|
54
|
+
'restmethod',
|
|
55
|
+
'requests',
|
|
56
|
+
'httr',
|
|
57
|
+
'httpie',
|
|
58
|
+
'wget',
|
|
59
|
+
'undici',
|
|
60
|
+
],
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
export function stripDefineDocumentationAuth(projectName) {
|
|
66
|
+
const targetPath = path.join(resolveProjectPath(projectName), "src/host/open-api/define-documentation.ts");
|
|
67
|
+
mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
68
|
+
writeFileSync(targetPath, defineDocumentationWithoutAuth, "utf8");
|
|
69
|
+
}
|
|
70
|
+
export function restoreDefineDocumentationWithAuth(projectName) {
|
|
71
|
+
cpSync(path.join(getSourceCodePath(), "src/host/open-api/define-documentation.ts"), path.join(resolveProjectPath(projectName), "src/host/open-api/define-documentation.ts"), { force: true });
|
|
72
|
+
}
|
|
73
|
+
const defineDocumentationJwtOnly = `import { EnvConfig } from '@/core/utils/env.config';
|
|
74
|
+
import { isProviderRegistered } from '@/core/utils/is-provider-registered';
|
|
75
|
+
import { resolveApiHost } from '@/core/utils/resolve-api-host';
|
|
76
|
+
import { IJwtTokenService } from '@/domain/auth/services/iauth.service';
|
|
77
|
+
import {
|
|
78
|
+
applyAuthSecurityToProtectedRoutes,
|
|
79
|
+
syncIsPublicRoutesInOpenApi,
|
|
80
|
+
} from '@/host/decorators/is-public.decorator';
|
|
81
|
+
import { EnvService } from '@/infra/common/env.service';
|
|
82
|
+
import { INestApplication } from '@nestjs/common';
|
|
83
|
+
import { ModulesContainer } from '@nestjs/core';
|
|
84
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
85
|
+
import { apiReference } from '@scalar/nestjs-api-reference';
|
|
86
|
+
import packageJson from '../../../package.json';
|
|
87
|
+
|
|
88
|
+
const DOC_ENDPOINT = '/doc';
|
|
89
|
+
const ACCESS_TOKEN_FIELD = 'accessToken';
|
|
90
|
+
|
|
91
|
+
type DocAuthorization = {
|
|
92
|
+
name: string;
|
|
93
|
+
config: Record<string, unknown>;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
function hasController(app: INestApplication, controllerName: string) {
|
|
97
|
+
const modulesContainer = app.get(ModulesContainer);
|
|
98
|
+
|
|
99
|
+
for (const moduleRef of modulesContainer.values()) {
|
|
100
|
+
for (const wrapper of moduleRef.controllers.values()) {
|
|
101
|
+
if (wrapper.metatype?.name === controllerName) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function buildDocAuthorizations(
|
|
111
|
+
app: INestApplication,
|
|
112
|
+
): Promise<DocAuthorization[]> {
|
|
113
|
+
if (!isProviderRegistered(app, IJwtTokenService)) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const env = app.get(EnvService);
|
|
118
|
+
const hostAddress = resolveApiHost(env.get('API_HOST'), env.get('PORT'));
|
|
119
|
+
const isDevelop = EnvConfig.isEnvDevelop;
|
|
120
|
+
const refreshUrl = \`\${hostAddress}/auth/refresh\`;
|
|
121
|
+
const authorizations: DocAuthorization[] = [];
|
|
122
|
+
|
|
123
|
+
if (hasController(app, 'LoginController')) {
|
|
124
|
+
authorizations.push({
|
|
125
|
+
name: 'JWT',
|
|
126
|
+
config: {
|
|
127
|
+
type: 'oauth2',
|
|
128
|
+
flows: {
|
|
129
|
+
password: {
|
|
130
|
+
tokenUrl: \`\${hostAddress}/auth/login\`,
|
|
131
|
+
refreshUrl,
|
|
132
|
+
username: isDevelop ? 'admin@example.com' : '',
|
|
133
|
+
password: isDevelop ? 'admin123' : '',
|
|
134
|
+
'x-tokenName': ACCESS_TOKEN_FIELD,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return authorizations;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function defineDocumentation(app: INestApplication) {
|
|
145
|
+
const authorizations = await buildDocAuthorizations(app);
|
|
146
|
+
|
|
147
|
+
const documentBuilder = new DocumentBuilder()
|
|
148
|
+
.setTitle(packageJson.name)
|
|
149
|
+
.setVersion(packageJson.version);
|
|
150
|
+
|
|
151
|
+
for (const authorization of authorizations) {
|
|
152
|
+
documentBuilder.addBearerAuth(
|
|
153
|
+
authorization.config as never,
|
|
154
|
+
authorization.name,
|
|
155
|
+
);
|
|
156
|
+
documentBuilder.addSecurityRequirements(authorization.name);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const document = SwaggerModule.createDocument(app, documentBuilder.build());
|
|
160
|
+
|
|
161
|
+
if (authorizations.length > 0) {
|
|
162
|
+
syncIsPublicRoutesInOpenApi(document);
|
|
163
|
+
applyAuthSecurityToProtectedRoutes(
|
|
164
|
+
document,
|
|
165
|
+
authorizations.map((authorization) => authorization.name),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
SwaggerModule.setup(DOC_ENDPOINT, app, document, { swaggerUiEnabled: false });
|
|
170
|
+
|
|
171
|
+
app.use(
|
|
172
|
+
DOC_ENDPOINT,
|
|
173
|
+
apiReference({
|
|
174
|
+
darkMode: true,
|
|
175
|
+
spec: { content: document },
|
|
176
|
+
metaData: {
|
|
177
|
+
title: packageJson.name,
|
|
178
|
+
version: packageJson.version,
|
|
179
|
+
},
|
|
180
|
+
hideModels: true,
|
|
181
|
+
hideDownloadButton: true,
|
|
182
|
+
hideClientButton: true,
|
|
183
|
+
hiddenClients: [
|
|
184
|
+
'libcurl',
|
|
185
|
+
'clj_http',
|
|
186
|
+
'restsharp',
|
|
187
|
+
'native',
|
|
188
|
+
'http1.1',
|
|
189
|
+
'asynchttp',
|
|
190
|
+
'nethttp',
|
|
191
|
+
'okhttp',
|
|
192
|
+
'unirest',
|
|
193
|
+
'xhr',
|
|
194
|
+
'request',
|
|
195
|
+
'nsurlsession',
|
|
196
|
+
'cohttp',
|
|
197
|
+
'guzzle',
|
|
198
|
+
'http1',
|
|
199
|
+
'http2',
|
|
200
|
+
'webrequest',
|
|
201
|
+
'restmethod',
|
|
202
|
+
'requests',
|
|
203
|
+
'httr',
|
|
204
|
+
'httpie',
|
|
205
|
+
'wget',
|
|
206
|
+
'undici',
|
|
207
|
+
],
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
`;
|
|
212
|
+
export function syncDefineDocumentationForProject(projectName, strategies) {
|
|
213
|
+
const hasJwt = strategies.includes(AuthStrategy.JWT);
|
|
214
|
+
const hasOauth = strategies.includes(AuthStrategy.OAUTH2);
|
|
215
|
+
const targetPath = path.join(resolveProjectPath(projectName), "src/host/open-api/define-documentation.ts");
|
|
216
|
+
mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
217
|
+
if (hasJwt && !hasOauth) {
|
|
218
|
+
writeFileSync(targetPath, defineDocumentationJwtOnly);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
restoreDefineDocumentationWithAuth(projectName);
|
|
222
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { cpSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AuthStrategy } from "../constants/domain.js";
|
|
4
|
+
import { getSourceCodePath } from "./get-source-code-path.js";
|
|
5
|
+
import { resolveProjectPath } from "./resolve-project-path.js";
|
|
6
|
+
const envWithoutAuth = `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
|
+
});
|
|
18
|
+
|
|
19
|
+
export type Env = z.infer<typeof envSchema>;
|
|
20
|
+
|
|
21
|
+
export function validateEnvConfig(config: Record<string, unknown>): Env {
|
|
22
|
+
return envSchema.parse(config);
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
const envExampleWithoutAuth = `PORT=3000
|
|
26
|
+
NODE_ENV=develop
|
|
27
|
+
DATABASE_URL=postgresql://postgres:root@localhost:5432/koala_nest
|
|
28
|
+
|
|
29
|
+
# Redis (opcional)
|
|
30
|
+
# Instância única: pode omitir — usa memória local (cache, lock de CronJob em dev).
|
|
31
|
+
# Várias réplicas: recomendado para cache/lock consistentes entre processos.
|
|
32
|
+
# REDIS_CONNECTION_STRING=redis://localhost:6379
|
|
33
|
+
# CACHE_KEY_PREFIX=koala-nest
|
|
34
|
+
|
|
35
|
+
# Cron jobs internos. Ative com \`kl-nest add cron\`.
|
|
36
|
+
CRON_JOBS_ENABLED=false
|
|
37
|
+
BOOTSTRAP_DELAY_MS=0
|
|
38
|
+
`;
|
|
39
|
+
export function stripEnvAuth(projectName) {
|
|
40
|
+
const projectRoot = resolveProjectPath(projectName);
|
|
41
|
+
mkdirSync(path.join(projectRoot, "src/core"), { recursive: true });
|
|
42
|
+
writeFileSync(path.join(projectRoot, "src/core/env.ts"), envWithoutAuth);
|
|
43
|
+
writeFileSync(path.join(projectRoot, ".env.example"), envExampleWithoutAuth);
|
|
44
|
+
}
|
|
45
|
+
export function restoreEnvWithAuth(projectName) {
|
|
46
|
+
const projectRoot = resolveProjectPath(projectName);
|
|
47
|
+
for (const relativePath of ["src/core/env.ts", ".env.example"]) {
|
|
48
|
+
cpSync(path.join(getSourceCodePath(), relativePath), path.join(projectRoot, relativePath), { force: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const envJwtOnly = `import { envBooleanSchema } from '@/core/schemas';
|
|
52
|
+
import { z } from 'zod';
|
|
53
|
+
|
|
54
|
+
export const envSchema = z.object({
|
|
55
|
+
PORT: z.coerce.number().default(3000),
|
|
56
|
+
NODE_ENV: z.enum(['test', 'develop', 'staging', 'production']),
|
|
57
|
+
DATABASE_URL: z.string(),
|
|
58
|
+
REDIS_CONNECTION_STRING: z.string().optional(),
|
|
59
|
+
CACHE_KEY_PREFIX: z.string().optional(),
|
|
60
|
+
CRON_JOBS_ENABLED: envBooleanSchema(false),
|
|
61
|
+
BOOTSTRAP_DELAY_MS: z.coerce.number().default(0),
|
|
62
|
+
JWT_PRIVATE_KEY: z.string().optional(),
|
|
63
|
+
JWT_PUBLIC_KEY: z.string().optional(),
|
|
64
|
+
JWT_ACCESS_TOKEN_EXPIRES_IN: z.string().default('15m'),
|
|
65
|
+
JWT_REFRESH_TOKEN_EXPIRES_IN: z.string().default('7d'),
|
|
66
|
+
API_HOST: z.string().optional(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export type Env = z.infer<typeof envSchema>;
|
|
70
|
+
|
|
71
|
+
export function validateEnvConfig(config: Record<string, unknown>): Env {
|
|
72
|
+
return envSchema.parse(config);
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
const envExampleJwtOnly = `PORT=3000
|
|
76
|
+
NODE_ENV=develop
|
|
77
|
+
DATABASE_URL=postgresql://postgres:root@localhost:5432/koala_nest
|
|
78
|
+
|
|
79
|
+
# Redis (opcional)
|
|
80
|
+
# REDIS_CONNECTION_STRING=redis://localhost:6379
|
|
81
|
+
# CACHE_KEY_PREFIX=koala-nest
|
|
82
|
+
|
|
83
|
+
CRON_JOBS_ENABLED=false
|
|
84
|
+
BOOTSTRAP_DELAY_MS=0
|
|
85
|
+
|
|
86
|
+
# JWT (RS256 — chaves em base64)
|
|
87
|
+
JWT_PRIVATE_KEY=
|
|
88
|
+
JWT_PUBLIC_KEY=
|
|
89
|
+
JWT_ACCESS_TOKEN_EXPIRES_IN=15m
|
|
90
|
+
JWT_REFRESH_TOKEN_EXPIRES_IN=7d
|
|
91
|
+
API_HOST=http://localhost:3000
|
|
92
|
+
|
|
93
|
+
# Usuário demo (migration Init): admin@example.com / admin123
|
|
94
|
+
`;
|
|
95
|
+
export function patchEnvForAuthStrategies(projectName, strategies) {
|
|
96
|
+
const hasJwt = strategies.includes(AuthStrategy.JWT);
|
|
97
|
+
const hasOauth = strategies.includes(AuthStrategy.OAUTH2);
|
|
98
|
+
const projectRoot = resolveProjectPath(projectName);
|
|
99
|
+
mkdirSync(path.join(projectRoot, "src/core"), { recursive: true });
|
|
100
|
+
if (hasJwt && !hasOauth) {
|
|
101
|
+
writeFileSync(path.join(projectRoot, "src/core/env.ts"), envJwtOnly);
|
|
102
|
+
writeFileSync(path.join(projectRoot, ".env.example"), envExampleJwtOnly);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
restoreEnvWithAuth(projectName);
|
|
106
|
+
}
|