@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.
Files changed (499) hide show
  1. package/README.md +106 -444
  2. package/cli/commands/add/index.js +97 -0
  3. package/cli/commands/help.js +44 -0
  4. package/cli/commands/new/configure-test-runner.js +13 -0
  5. package/cli/commands/new/create-ddd-structure.js +52 -0
  6. package/cli/commands/new/create-empty-nest-project.js +58 -0
  7. package/cli/commands/new/fix-lint-config.js +24 -0
  8. package/cli/commands/new/index.js +202 -0
  9. package/cli/commands/version.js +5 -0
  10. package/cli/constants/auth-strategy-artifacts.js +56 -0
  11. package/cli/constants/auth-strategy-checklist.js +314 -0
  12. package/cli/constants/cli-commands.js +24 -0
  13. package/cli/constants/cli-project-checklist.js +289 -0
  14. package/cli/constants/core-packages.js +34 -0
  15. package/cli/constants/domain.js +171 -0
  16. package/cli/constants/package-manager.js +5 -0
  17. package/cli/constants/version.js +5 -0
  18. package/cli/index.js +55 -0
  19. package/cli/types/index.js +0 -0
  20. package/cli/utils/add-project-features.js +170 -0
  21. package/cli/utils/apply-optional-features.js +48 -0
  22. package/cli/utils/auth-strategy-validation.js +179 -0
  23. package/cli/utils/cancel.js +8 -0
  24. package/cli/utils/cli-options.js +27 -0
  25. package/cli/utils/cli-project-validation.js +157 -0
  26. package/cli/utils/detect-project-state.js +131 -0
  27. package/cli/utils/format-code.js +9 -0
  28. package/cli/utils/get-package-manager.js +12 -0
  29. package/cli/utils/get-package-root.js +19 -0
  30. package/cli/utils/get-source-code-path.js +15 -0
  31. package/cli/utils/install-module.js +258 -0
  32. package/cli/utils/normalize-add-args.js +25 -0
  33. package/cli/utils/parse-new-args.js +127 -0
  34. package/cli/utils/patch-auth-install.js +224 -0
  35. package/cli/utils/patch-define-documentation.js +222 -0
  36. package/cli/utils/patch-env.js +106 -0
  37. package/cli/utils/patch-generated-project.js +21 -0
  38. package/cli/utils/patch-health-module.js +80 -0
  39. package/cli/utils/patch-infra-module.js +62 -0
  40. package/cli/utils/patch-jobs-module.js +103 -0
  41. package/cli/utils/patch-main.js +15 -0
  42. package/cli/utils/patch-person-features.js +127 -0
  43. package/cli/utils/project-files.js +11 -0
  44. package/cli/utils/prune-auth-strategies.js +116 -0
  45. package/cli/utils/prune-core-auth.js +17 -0
  46. package/cli/utils/remove-sample-parts.js +203 -0
  47. package/cli/utils/resolve-project-path.js +19 -0
  48. package/cli/utils/restore-person-features.js +64 -0
  49. package/cli/utils/run-command.js +31 -0
  50. package/cli/utils/sync-auth-strategy-files.js +63 -0
  51. package/koala-nest/.env.example +34 -0
  52. package/koala-nest/.prettierrc +4 -0
  53. package/koala-nest/README.md +51 -0
  54. package/koala-nest/bunfig.toml +7 -0
  55. package/koala-nest/eslint.config.mjs +55 -0
  56. package/koala-nest/nest-cli.json +9 -0
  57. package/koala-nest/package.json +79 -0
  58. package/koala-nest/src/application/auth/common/auth-token.response.ts +15 -0
  59. package/koala-nest/src/application/auth/common/user-claims.ts +6 -0
  60. package/koala-nest/src/application/auth/login/login.handler.ts +42 -0
  61. package/koala-nest/src/application/auth/login/login.request.ts +9 -0
  62. package/koala-nest/src/application/auth/login/login.response.ts +3 -0
  63. package/koala-nest/src/application/auth/login/login.validator.ts +12 -0
  64. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.handler.ts +24 -0
  65. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.request.ts +10 -0
  66. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.response.ts +6 -0
  67. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.validator.ts +12 -0
  68. package/koala-nest/src/application/auth/oauth2/callback/oauth-callback.response.ts +10 -0
  69. package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.handler.ts +73 -0
  70. package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.request.ts +16 -0
  71. package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.validator.ts +14 -0
  72. package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-oauth-token.handler.ts +35 -0
  73. package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-token.types.ts +1 -0
  74. package/koala-nest/src/application/auth/refresh-token/refresh-token.handler.ts +26 -0
  75. package/koala-nest/src/application/auth/user-info/user-info.handler.ts +30 -0
  76. package/koala-nest/src/application/auth/user-info/user-info.response.ts +20 -0
  77. package/koala-nest/src/application/common/created-registre.response.ts +20 -0
  78. package/koala-nest/src/application/common/pagination.request.ts +41 -0
  79. package/koala-nest/src/application/common/request-handler.base.ts +3 -0
  80. package/koala-nest/src/application/common/request-validator.base.ts +33 -0
  81. package/koala-nest/src/application/mapping/mapping.provider.ts +9 -0
  82. package/koala-nest/src/application/mapping/person.mapper.ts +44 -0
  83. package/koala-nest/src/application/person/create/create-person.handler.ts +34 -0
  84. package/koala-nest/src/application/person/create/create-person.request.ts +29 -0
  85. package/koala-nest/src/application/person/create/create-person.response.ts +3 -0
  86. package/koala-nest/src/application/person/create/create-person.validator.ts +9 -0
  87. package/koala-nest/src/application/person/delete/delete-person.handler.ts +22 -0
  88. package/koala-nest/src/application/person/find-person-or-throw.ts +16 -0
  89. package/koala-nest/src/application/person/jobs/cron/create-person.job.ts +58 -0
  90. package/koala-nest/src/application/person/jobs/cron/delete-inactive.job.ts +57 -0
  91. package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.event.ts +4 -0
  92. package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.handler.ts +54 -0
  93. package/koala-nest/src/application/person/jobs/events/person/person-event.job.ts +19 -0
  94. package/koala-nest/src/application/person/person.schemas.ts +21 -0
  95. package/koala-nest/src/application/person/read/read-person.handler.ts +22 -0
  96. package/koala-nest/src/application/person/read/read-person.response.ts +44 -0
  97. package/koala-nest/src/application/person/read-many/read-many-person.handler.ts +63 -0
  98. package/koala-nest/src/application/person/read-many/read-many-person.request.ts +13 -0
  99. package/koala-nest/src/application/person/read-many/read-many-person.response.ts +30 -0
  100. package/koala-nest/src/application/person/read-many/read-many-person.validator.ts +15 -0
  101. package/koala-nest/src/application/person/update/update-person.handler.ts +51 -0
  102. package/koala-nest/src/application/person/update/update-person.request.ts +41 -0
  103. package/koala-nest/src/application/person/update/update-person.validator.ts +9 -0
  104. package/koala-nest/src/core/auth/assert-user-active.ts +18 -0
  105. package/koala-nest/src/core/auth/auth-profile.enum.ts +7 -0
  106. package/koala-nest/src/core/auth/auth-routes.ts +5 -0
  107. package/koala-nest/src/core/auth/auth.constants.ts +6 -0
  108. package/koala-nest/src/core/auth/jwt-claims.ts +23 -0
  109. package/koala-nest/src/core/auth/oauth-provider.registry.ts +94 -0
  110. package/koala-nest/src/core/auth/parse-jwt-expires-in.ts +30 -0
  111. package/koala-nest/src/core/auth/parse-oauth2-provider-env.ts +56 -0
  112. package/koala-nest/src/core/auth/resolve-refresh-token.ts +40 -0
  113. package/koala-nest/src/core/background-services/cron-service/cron-job.handler.base.ts +65 -0
  114. package/koala-nest/src/core/background-services/event-service/event-class.ts +5 -0
  115. package/koala-nest/src/core/background-services/event-service/event-handler.base.ts +17 -0
  116. package/koala-nest/src/core/background-services/event-service/event-job.ts +31 -0
  117. package/koala-nest/src/core/background-services/event-service/event-queue.ts +107 -0
  118. package/koala-nest/src/core/base/entity.base.ts +3 -0
  119. package/koala-nest/src/core/base/object-class.ts +14 -0
  120. package/koala-nest/src/core/constants/cache.constants.ts +16 -0
  121. package/koala-nest/src/core/constants/cron.constants.ts +14 -0
  122. package/koala-nest/src/core/constants/query-params.ts +7 -0
  123. package/koala-nest/src/core/env.ts +42 -0
  124. package/koala-nest/src/core/schemas/boolean.schema.ts +24 -0
  125. package/koala-nest/src/core/schemas/document-number-mask.ts +22 -0
  126. package/koala-nest/src/core/schemas/document-number.schema.ts +21 -0
  127. package/koala-nest/src/core/schemas/document-number.utils.ts +15 -0
  128. package/koala-nest/src/core/schemas/email.schema.ts +13 -0
  129. package/koala-nest/src/core/schemas/index.ts +6 -0
  130. package/koala-nest/src/core/schemas/list-query.schema.ts +18 -0
  131. package/koala-nest/src/core/schemas/native-enum.schema.ts +36 -0
  132. package/koala-nest/src/core/tools/mapping/auto-map.ts +14 -0
  133. package/koala-nest/src/core/tools/mapping/auto-mapper.ts +102 -0
  134. package/koala-nest/src/core/tools/mapping/create-map.ts +11 -0
  135. package/koala-nest/src/core/tools/mapping/for-member.ts +16 -0
  136. package/koala-nest/src/core/tools/mapping/index.ts +4 -0
  137. package/koala-nest/src/core/tools/mapping/mapping-store.ts +121 -0
  138. package/koala-nest/src/core/types/auth-provider-config-response.type.ts +5 -0
  139. package/koala-nest/src/core/types/index.ts +5 -0
  140. package/koala-nest/src/core/utils/build-list-cache-key.ts +19 -0
  141. package/koala-nest/src/core/utils/cron-expression-to-boolean.ts +65 -0
  142. package/koala-nest/src/core/utils/env.config.ts +17 -0
  143. package/koala-nest/src/core/utils/filter-request-params.ts +29 -0
  144. package/koala-nest/src/core/utils/format-typeorm-error.ts +173 -0
  145. package/koala-nest/src/core/utils/format-zod-error.ts +201 -0
  146. package/koala-nest/src/core/utils/hash-password.ts +5 -0
  147. package/koala-nest/src/core/utils/icomparable.ts +1 -0
  148. package/koala-nest/src/core/utils/is-provider-registered.ts +40 -0
  149. package/koala-nest/src/core/utils/name-to-login.ts +25 -0
  150. package/koala-nest/src/core/utils/person-list-cache.ts +7 -0
  151. package/koala-nest/src/core/utils/report-error.ts +18 -0
  152. package/koala-nest/src/core/utils/resolve-api-host.ts +8 -0
  153. package/koala-nest/src/core/utils/time.constants.ts +5 -0
  154. package/koala-nest/src/domain/auth/dtos/auth-provider-config.dto.ts +12 -0
  155. package/koala-nest/src/domain/auth/dtos/oauth-user-info.dto.ts +9 -0
  156. package/koala-nest/src/domain/auth/services/iauth.service.ts +37 -0
  157. package/koala-nest/src/domain/common/icache.service.ts +11 -0
  158. package/koala-nest/src/domain/common/ilogging.service.ts +9 -0
  159. package/koala-nest/src/domain/common/ired-lock.service.ts +4 -0
  160. package/koala-nest/src/domain/dtos/logged-user-info.dto.ts +30 -0
  161. package/koala-nest/src/domain/dtos/pagination.dto.ts +35 -0
  162. package/koala-nest/src/domain/dtos/person-query.dto.ts +10 -0
  163. package/koala-nest/src/domain/entities/person/person-address.ts +14 -0
  164. package/koala-nest/src/domain/entities/person/person-contact.ts +28 -0
  165. package/koala-nest/src/domain/entities/person/person.ts +44 -0
  166. package/koala-nest/src/domain/entities/user/enums/user-status.enum.ts +6 -0
  167. package/koala-nest/src/domain/entities/user/user.ts +49 -0
  168. package/koala-nest/src/domain/repositories/iperson.repository.ts +10 -0
  169. package/koala-nest/src/domain/repositories/iuser.repository.ts +8 -0
  170. package/koala-nest/src/domain/services/ilogged-user-info.service.ts +5 -0
  171. package/koala-nest/src/host/app.module.ts +27 -0
  172. package/koala-nest/src/host/controllers/auth/auth.module.ts +38 -0
  173. package/koala-nest/src/host/controllers/auth/login.controller.ts +41 -0
  174. package/koala-nest/src/host/controllers/auth/refresh-token.controller.ts +24 -0
  175. package/koala-nest/src/host/controllers/auth/router.config.ts +9 -0
  176. package/koala-nest/src/host/controllers/auth/user-info.controller.ts +19 -0
  177. package/koala-nest/src/host/controllers/common/controller.base.ts +9 -0
  178. package/koala-nest/src/host/controllers/common/controller.module.ts +10 -0
  179. package/koala-nest/src/host/controllers/common/router-config.base.ts +14 -0
  180. package/koala-nest/src/host/controllers/health-check/health-check.controller.ts +29 -0
  181. package/koala-nest/src/host/controllers/health-check/health-check.module.ts +22 -0
  182. package/koala-nest/src/host/controllers/oauth2/auth-link.controller.ts +29 -0
  183. package/koala-nest/src/host/controllers/oauth2/exchange-code.controller.ts +29 -0
  184. package/koala-nest/src/host/controllers/oauth2/oauth-callback.controller.ts +28 -0
  185. package/koala-nest/src/host/controllers/oauth2/router.config.ts +9 -0
  186. package/koala-nest/src/host/controllers/oauth2/scalar-token.controller.ts +16 -0
  187. package/koala-nest/src/host/controllers/person/create-person.controller.ts +23 -0
  188. package/koala-nest/src/host/controllers/person/delete-person.controller.ts +23 -0
  189. package/koala-nest/src/host/controllers/person/person.module.ts +39 -0
  190. package/koala-nest/src/host/controllers/person/read-many-person.controller.ts +24 -0
  191. package/koala-nest/src/host/controllers/person/read-person.controller.ts +21 -0
  192. package/koala-nest/src/host/controllers/person/router.config.ts +9 -0
  193. package/koala-nest/src/host/controllers/person/update-person.controller.ts +22 -0
  194. package/koala-nest/src/host/decorators/api-exclude-endpoint-diff-develop.decorator.ts +9 -0
  195. package/koala-nest/src/host/decorators/api-property-enum.decorator.ts +49 -0
  196. package/koala-nest/src/host/decorators/api-property-only-develop.decorator.ts +19 -0
  197. package/koala-nest/src/host/decorators/controller.decorator.ts +10 -0
  198. package/koala-nest/src/host/decorators/is-public.decorator.ts +82 -0
  199. package/koala-nest/src/host/decorators/restriction-by-profile.decorator.ts +13 -0
  200. package/koala-nest/src/host/decorators/scalar-token-endpoint.decorator.ts +14 -0
  201. package/koala-nest/src/host/filters/errors.filter.ts +99 -0
  202. package/koala-nest/src/host/jobs/jobs-bootstrap.service.ts +61 -0
  203. package/koala-nest/src/host/jobs/jobs.module.ts +41 -0
  204. package/koala-nest/src/host/jobs/jobs.tokens.ts +2 -0
  205. package/koala-nest/src/host/main.ts +43 -0
  206. package/koala-nest/src/host/open-api/define-documentation.ts +210 -0
  207. package/koala-nest/src/host/security/guards/auth.guard.ts +107 -0
  208. package/koala-nest/src/host/security/guards/profiles.guard.ts +32 -0
  209. package/koala-nest/src/host/security/security.module.ts +62 -0
  210. package/koala-nest/src/host/security/strategies/jwt.strategy.ts +61 -0
  211. package/koala-nest/src/infra/auth/jwt-token.service.ts +48 -0
  212. package/koala-nest/src/infra/auth/oauth2-auth.service.ts +208 -0
  213. package/koala-nest/src/infra/common/cache-service.provider.ts +47 -0
  214. package/koala-nest/src/infra/common/env.service.ts +12 -0
  215. package/koala-nest/src/infra/common/in-memory-cache.service.ts +71 -0
  216. package/koala-nest/src/infra/common/logging.service.ts +19 -0
  217. package/koala-nest/src/infra/common/red-lock.service.ts +44 -0
  218. package/koala-nest/src/infra/common/redis-cache.service.ts +72 -0
  219. package/koala-nest/src/infra/database/data-source-factory.ts +23 -0
  220. package/koala-nest/src/infra/database/database.module.ts +19 -0
  221. package/koala-nest/src/infra/database/migrations/1781281330533-Init.ts +67 -0
  222. package/koala-nest/src/infra/database/migrations/generate-migration.ts +26 -0
  223. package/koala-nest/src/infra/database/migrations/migration-datasource.ts +14 -0
  224. package/koala-nest/src/infra/infra.module.ts +29 -0
  225. package/koala-nest/src/infra/repositories/person.repository.ts +49 -0
  226. package/koala-nest/src/infra/repositories/repository.base.ts +20 -0
  227. package/koala-nest/src/infra/repositories/repository.module.ts +16 -0
  228. package/koala-nest/src/infra/repositories/user.repository.ts +38 -0
  229. package/koala-nest/src/infra/services/database.indicator.service.ts +17 -0
  230. package/koala-nest/src/infra/services/logged-user-info.service.ts +32 -0
  231. package/koala-nest/src/infra/services/redis.indicator.service.ts +66 -0
  232. package/koala-nest/src/test/app-auth-test.module.ts +32 -0
  233. package/koala-nest/src/test/app-test.module.ts +22 -0
  234. package/koala-nest/src/test/application/auth-link.handler.spec.ts +22 -0
  235. package/koala-nest/src/test/application/create-person.handler.spec.ts +39 -0
  236. package/koala-nest/src/test/application/create-person.job.spec.ts +55 -0
  237. package/koala-nest/src/test/application/delete-inactive.job.spec.ts +35 -0
  238. package/koala-nest/src/test/application/delete-person.handler.spec.ts +46 -0
  239. package/koala-nest/src/test/application/exchange-code.handler.spec.ts +67 -0
  240. package/koala-nest/src/test/application/inactive-person.handler.spec.ts +48 -0
  241. package/koala-nest/src/test/application/login.handler.spec.ts +55 -0
  242. package/koala-nest/src/test/application/read-many-person.handler.spec.ts +64 -0
  243. package/koala-nest/src/test/application/read-person.handler.spec.ts +44 -0
  244. package/koala-nest/src/test/application/refresh-token.handler.spec.ts +34 -0
  245. package/koala-nest/src/test/application/scalar-oauth-token.handler.spec.ts +63 -0
  246. package/koala-nest/src/test/application/update-person.handler.spec.ts +78 -0
  247. package/koala-nest/src/test/bun-test-globals.d.ts +1 -0
  248. package/koala-nest/src/test/core/auth.guard.spec.ts +77 -0
  249. package/koala-nest/src/test/core/build-list-cache-key.spec.ts +29 -0
  250. package/koala-nest/src/test/core/cron-expression-to-boolean.spec.ts +22 -0
  251. package/koala-nest/src/test/core/cron-job.handler.spec.ts +40 -0
  252. package/koala-nest/src/test/core/env.config.spec.ts +14 -0
  253. package/koala-nest/src/test/core/env.spec.ts +61 -0
  254. package/koala-nest/src/test/core/event-queue.spec.ts +53 -0
  255. package/koala-nest/src/test/core/format-typeorm-error.spec.ts +42 -0
  256. package/koala-nest/src/test/core/format-zod-error.spec.ts +38 -0
  257. package/koala-nest/src/test/core/is-provider-registered.spec.ts +35 -0
  258. package/koala-nest/src/test/core/jwt.strategy.spec.ts +38 -0
  259. package/koala-nest/src/test/core/mapping.spec.ts +177 -0
  260. package/koala-nest/src/test/core/oauth-provider.registry.spec.ts +79 -0
  261. package/koala-nest/src/test/core/profiles.guard.spec.ts +42 -0
  262. package/koala-nest/src/test/core/resolve-api-host.spec.ts +20 -0
  263. package/koala-nest/src/test/core/schemas.spec.ts +95 -0
  264. package/koala-nest/src/test/create-auth-e2e-test-app.ts +22 -0
  265. package/koala-nest/src/test/create-e2e-test-app.ts +14 -0
  266. package/koala-nest/src/test/e2e-context.ts +7 -0
  267. package/koala-nest/src/test/host/controllers/auth/auth.controller.e2e.spec.ts +87 -0
  268. package/koala-nest/src/test/host/controllers/person/lazy-loading.e2e.spec.ts +181 -0
  269. package/koala-nest/src/test/host/controllers/person/person.controller.e2e.spec.ts +148 -0
  270. package/koala-nest/src/test/host/errors.filter.spec.ts +75 -0
  271. package/koala-nest/src/test/host/is-public-open-api.spec.ts +60 -0
  272. package/koala-nest/src/test/host/oauth-callback.controller.spec.ts +18 -0
  273. package/koala-nest/src/test/infra/cache-service.provider.spec.ts +21 -0
  274. package/koala-nest/src/test/infra/in-memory-cache.service.spec.ts +49 -0
  275. package/koala-nest/src/test/infra/jwt-token.service.spec.ts +28 -0
  276. package/koala-nest/src/test/infra/logged-user-info.service.spec.ts +33 -0
  277. package/koala-nest/src/test/infra/oauth2-auth.service.spec.ts +112 -0
  278. package/koala-nest/src/test/infra/red-lock.service.spec.ts +43 -0
  279. package/koala-nest/src/test/infra/redis-cache.service.spec.ts +100 -0
  280. package/koala-nest/src/test/infra/redis-indicator.service.spec.ts +75 -0
  281. package/koala-nest/src/test/mockup/person/person.entities.ts +35 -0
  282. package/koala-nest/src/test/mockup/person/person.requests.ts +23 -0
  283. package/koala-nest/src/test/mockup/person/person.responses.ts +31 -0
  284. package/koala-nest/src/test/services/cache.stub.ts +41 -0
  285. package/koala-nest/src/test/services/fake-logging.service.ts +13 -0
  286. package/koala-nest/src/test/services/fake-red-lock.service.ts +11 -0
  287. package/koala-nest/src/test/services/logged-user-info.fake-service.ts +18 -0
  288. package/koala-nest/src/test/setup-e2e.ts +66 -0
  289. package/koala-nest/src/test/setup.ts +1 -0
  290. package/koala-nest/src/test/utils/configure-test-app.ts +24 -0
  291. package/koala-nest/src/test/utils/create-e2e-database.ts +50 -0
  292. package/koala-nest/src/test/utils/e2e-database-client.ts +9 -0
  293. package/koala-nest/src/test/utils/guard-test-context.ts +28 -0
  294. package/koala-nest/src/test/utils/jwt-test-keys.ts +27 -0
  295. package/koala-nest/tsconfig.build.json +8 -0
  296. package/koala-nest/tsconfig.json +36 -0
  297. package/koala-nest/tsconfig.spec.json +11 -0
  298. package/package.json +19 -29
  299. package/core/backgroud-services/cron-service/cron-job.handler.base.d.ts +0 -16
  300. package/core/backgroud-services/cron-service/cron-job.handler.base.js +0 -49
  301. package/core/backgroud-services/event-service/event-class.d.ts +0 -5
  302. package/core/backgroud-services/event-service/event-class.js +0 -11
  303. package/core/backgroud-services/event-service/event-handler.base.d.ts +0 -8
  304. package/core/backgroud-services/event-service/event-handler.base.js +0 -14
  305. package/core/backgroud-services/event-service/event-is-trigger.d.ts +0 -3
  306. package/core/backgroud-services/event-service/event-is-trigger.js +0 -7
  307. package/core/backgroud-services/event-service/event-job.d.ts +0 -13
  308. package/core/backgroud-services/event-service/event-job.js +0 -21
  309. package/core/backgroud-services/event-service/event-queue.d.ts +0 -18
  310. package/core/backgroud-services/event-service/event-queue.js +0 -65
  311. package/core/constants/query-params.d.ts +0 -6
  312. package/core/constants/query-params.js +0 -8
  313. package/core/controllers/base.controller.d.ts +0 -4
  314. package/core/controllers/base.controller.js +0 -6
  315. package/core/controllers/controller.decorator.d.ts +0 -2
  316. package/core/controllers/controller.decorator.js +0 -11
  317. package/core/controllers/created-registre-response.base.d.ts +0 -10
  318. package/core/controllers/created-registre-response.base.js +0 -35
  319. package/core/controllers/list-response.base.d.ts +0 -4
  320. package/core/controllers/list-response.base.js +0 -21
  321. package/core/controllers/pagination.request.d.ts +0 -10
  322. package/core/controllers/pagination.request.js +0 -56
  323. package/core/controllers/router-config.base.d.ts +0 -7
  324. package/core/controllers/router-config.base.js +0 -18
  325. package/core/controllers/schemas/boolean.schema.d.ts +0 -2
  326. package/core/controllers/schemas/boolean.schema.js +0 -12
  327. package/core/controllers/schemas/document-number.schema.d.ts +0 -1
  328. package/core/controllers/schemas/document-number.schema.js +0 -26
  329. package/core/controllers/schemas/email.schema.d.ts +0 -1
  330. package/core/controllers/schemas/email.schema.js +0 -13
  331. package/core/controllers/schemas/list-query.schema.d.ts +0 -17
  332. package/core/controllers/schemas/list-query.schema.js +0 -19
  333. package/core/controllers/schemas/native-enum.schema.d.ts +0 -7
  334. package/core/controllers/schemas/native-enum.schema.js +0 -28
  335. package/core/controllers/schemas/set-mask-document-number.schema.d.ts +0 -1
  336. package/core/controllers/schemas/set-mask-document-number.schema.js +0 -13
  337. package/core/database/entity.base.d.ts +0 -27
  338. package/core/database/entity.base.js +0 -145
  339. package/core/database/entity.decorator.d.ts +0 -12
  340. package/core/database/entity.decorator.js +0 -37
  341. package/core/database/prisma-client-with-custom-transaction.interface.d.ts +0 -8
  342. package/core/database/prisma-client-with-custom-transaction.interface.js +0 -2
  343. package/core/database/prisma-resolver.d.ts +0 -2
  344. package/core/database/prisma-resolver.js +0 -74
  345. package/core/database/prisma-transactional-client.d.ts +0 -11
  346. package/core/database/prisma-transactional-client.js +0 -25
  347. package/core/database/prisma.service.d.ts +0 -24
  348. package/core/database/prisma.service.js +0 -104
  349. package/core/database/repository.base.d.ts +0 -82
  350. package/core/database/repository.base.js +0 -668
  351. package/core/dtos/pagination.dto.d.ts +0 -9
  352. package/core/dtos/pagination.dto.js +0 -49
  353. package/core/errors/bad-request.error.d.ts +0 -5
  354. package/core/errors/bad-request.error.js +0 -10
  355. package/core/errors/conflict.error.d.ts +0 -4
  356. package/core/errors/conflict.error.js +0 -10
  357. package/core/errors/error.base.d.ts +0 -4
  358. package/core/errors/error.base.js +0 -11
  359. package/core/errors/no-content.error.d.ts +0 -5
  360. package/core/errors/no-content.error.js +0 -10
  361. package/core/errors/not-allowed.error.d.ts +0 -5
  362. package/core/errors/not-allowed.error.js +0 -10
  363. package/core/errors/resource-not-found.error.d.ts +0 -5
  364. package/core/errors/resource-not-found.error.js +0 -10
  365. package/core/errors/use-case-error.d.ts +0 -3
  366. package/core/errors/use-case-error.js +0 -2
  367. package/core/errors/user-already-exist.error.d.ts +0 -4
  368. package/core/errors/user-already-exist.error.js +0 -10
  369. package/core/errors/wrong-credentials.error.d.ts +0 -4
  370. package/core/errors/wrong-credentials.error.js +0 -10
  371. package/core/health-check/health-check.controller.d.ts +0 -5
  372. package/core/health-check/health-check.controller.js +0 -32
  373. package/core/health-check/health-check.module.d.ts +0 -2
  374. package/core/health-check/health-check.module.js +0 -19
  375. package/core/index.d.ts +0 -18
  376. package/core/index.js +0 -7
  377. package/core/koala-app.d.ts +0 -64
  378. package/core/koala-app.js +0 -258
  379. package/core/koala-global-vars.d.ts +0 -7
  380. package/core/koala-global-vars.js +0 -9
  381. package/core/koala-nest-database.module.d.ts +0 -16
  382. package/core/koala-nest-database.module.js +0 -52
  383. package/core/koala-nest-http.module.d.ts +0 -13
  384. package/core/koala-nest-http.module.js +0 -37
  385. package/core/koala-nest.module.d.ts +0 -17
  386. package/core/koala-nest.module.js +0 -66
  387. package/core/mapping/auto-mapping-class-context.d.ts +0 -16
  388. package/core/mapping/auto-mapping-class-context.js +0 -18
  389. package/core/mapping/auto-mapping-context.d.ts +0 -11
  390. package/core/mapping/auto-mapping-context.js +0 -24
  391. package/core/mapping/auto-mapping-list.d.ts +0 -28
  392. package/core/mapping/auto-mapping-list.js +0 -99
  393. package/core/mapping/auto-mapping-profile.d.ts +0 -3
  394. package/core/mapping/auto-mapping-profile.js +0 -6
  395. package/core/mapping/auto-mapping.decorator.d.ts +0 -9
  396. package/core/mapping/auto-mapping.decorator.js +0 -27
  397. package/core/mapping/auto-mapping.module.d.ts +0 -5
  398. package/core/mapping/auto-mapping.module.js +0 -29
  399. package/core/mapping/auto-mapping.service.d.ts +0 -20
  400. package/core/mapping/auto-mapping.service.js +0 -197
  401. package/core/mapping/create-map.d.ts +0 -3
  402. package/core/mapping/create-map.js +0 -7
  403. package/core/mapping/for-member.d.ts +0 -5
  404. package/core/mapping/for-member.js +0 -8
  405. package/core/request-overflow/request-handler.base.d.ts +0 -4
  406. package/core/request-overflow/request-handler.base.js +0 -6
  407. package/core/request-overflow/request-result.d.ts +0 -15
  408. package/core/request-overflow/request-result.js +0 -37
  409. package/core/request-overflow/request-validator.base.d.ts +0 -7
  410. package/core/request-overflow/request-validator.base.js +0 -26
  411. package/core/security/strategies/api-key.strategy.d.ts +0 -16
  412. package/core/security/strategies/api-key.strategy.js +0 -31
  413. package/core/utils/assing-object.d.ts +0 -5
  414. package/core/utils/assing-object.js +0 -6
  415. package/core/utils/automap-cycle-context.d.ts +0 -6
  416. package/core/utils/automap-cycle-context.js +0 -33
  417. package/core/utils/env.config.d.ts +0 -6
  418. package/core/utils/env.config.js +0 -18
  419. package/core/utils/filter-request-params.d.ts +0 -13
  420. package/core/utils/filter-request-params.js +0 -22
  421. package/core/utils/find-on-list.d.ts +0 -2
  422. package/core/utils/find-on-list.js +0 -13
  423. package/core/utils/generate-prisma-include-schema.d.ts +0 -9
  424. package/core/utils/generate-prisma-include-schema.js +0 -60
  425. package/core/utils/get-type-by-prop.d.ts +0 -2
  426. package/core/utils/get-type-by-prop.js +0 -11
  427. package/core/utils/hydrate-entity-from-cache.d.ts +0 -22
  428. package/core/utils/hydrate-entity-from-cache.js +0 -76
  429. package/core/utils/instanciate-class-with-dependencies-injection.d.ts +0 -2
  430. package/core/utils/instanciate-class-with-dependencies-injection.js +0 -10
  431. package/core/utils/interfaces/icomparable.d.ts +0 -5
  432. package/core/utils/interfaces/icomparable.js +0 -6
  433. package/core/utils/is-plain-object.d.ts +0 -1
  434. package/core/utils/is-plain-object.js +0 -8
  435. package/core/utils/list.d.ts +0 -39
  436. package/core/utils/list.js +0 -167
  437. package/core/utils/promise-all.d.ts +0 -7
  438. package/core/utils/promise-all.js +0 -19
  439. package/core/utils/proxy.d.ts +0 -1
  440. package/core/utils/proxy.js +0 -27
  441. package/core/utils/set-mask-document-number.d.ts +0 -1
  442. package/core/utils/set-mask-document-number.js +0 -13
  443. package/core/validators/file-validator.d.ts +0 -27
  444. package/core/validators/file-validator.js +0 -94
  445. package/decorators/api-exclude-endpoint-diff-develop.decorator.d.ts +0 -1
  446. package/decorators/api-exclude-endpoint-diff-develop.decorator.js +0 -9
  447. package/decorators/api-property-enum.decorator.d.ts +0 -8
  448. package/decorators/api-property-enum.decorator.js +0 -21
  449. package/decorators/api-property-only-develop.decorator.d.ts +0 -2
  450. package/decorators/api-property-only-develop.decorator.js +0 -9
  451. package/decorators/cookies.decorator.d.ts +0 -1
  452. package/decorators/cookies.decorator.js +0 -8
  453. package/decorators/is-public.decorator.d.ts +0 -2
  454. package/decorators/is-public.decorator.js +0 -7
  455. package/decorators/upload.decorator.d.ts +0 -1
  456. package/decorators/upload.decorator.js +0 -18
  457. package/env/env.d.ts +0 -25
  458. package/env/env.js +0 -14
  459. package/env/env.module.d.ts +0 -2
  460. package/env/env.module.js +0 -20
  461. package/env/env.service.d.ts +0 -7
  462. package/env/env.service.js +0 -28
  463. package/filters/domain-errors.filter.d.ts +0 -18
  464. package/filters/domain-errors.filter.js +0 -92
  465. package/filters/global-exception.filter.d.ts +0 -8
  466. package/filters/global-exception.filter.js +0 -68
  467. package/filters/prisma-validation-exception.filter.d.ts +0 -10
  468. package/filters/prisma-validation-exception.filter.js +0 -82
  469. package/filters/zod-errors.filter.d.ts +0 -9
  470. package/filters/zod-errors.filter.js +0 -60
  471. package/services/logging/ilogging.service.d.ts +0 -16
  472. package/services/logging/ilogging.service.js +0 -6
  473. package/services/logging/logging.service.d.ts +0 -4
  474. package/services/logging/logging.service.js +0 -20
  475. package/services/redis/iredis.service.d.ts +0 -6
  476. package/services/redis/iredis.service.js +0 -6
  477. package/services/redis/redis.service.d.ts +0 -14
  478. package/services/redis/redis.service.js +0 -65
  479. package/services/redlock/ired-lock.service.d.ts +0 -4
  480. package/services/redlock/ired-lock.service.js +0 -6
  481. package/services/redlock/red-lock.service.d.ts +0 -9
  482. package/services/redlock/red-lock.service.js +0 -46
  483. package/test/koala-app-test-dependencies.d.ts +0 -10
  484. package/test/koala-app-test-dependencies.js +0 -13
  485. package/test/koala-app-test.d.ts +0 -22
  486. package/test/koala-app-test.js +0 -77
  487. package/test/repositories/in-memory-base.repository.d.ts +0 -17
  488. package/test/repositories/in-memory-base.repository.js +0 -67
  489. package/test/services/fake-logging.service.d.ts +0 -4
  490. package/test/services/fake-logging.service.js +0 -9
  491. package/test/services/fake-red-lock.service.d.ts +0 -5
  492. package/test/services/fake-red-lock.service.js +0 -11
  493. package/test/utils/create-e2e-database.d.ts +0 -7
  494. package/test/utils/create-e2e-database.js +0 -38
  495. package/test/utils/e2e-database-client.d.ts +0 -7
  496. package/test/utils/e2e-database-client.js +0 -12
  497. package/test/utils/wait-for.d.ts +0 -1
  498. package/test/utils/wait-for.js +0 -21
  499. package/tsconfig.lib.tsbuildinfo +0 -1
@@ -0,0 +1,203 @@
1
+ import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { removeImportLines } from "./project-files.js";
4
+ import { patchAppModuleJobs } from "./patch-jobs-module.js";
5
+ import { resolveProjectPath } from "./resolve-project-path.js";
6
+ import { stripMainOptionalFeatures } from "./patch-main.js";
7
+ import { stripDefineDocumentationAuth } from "./patch-define-documentation.js";
8
+ import { stripEnvAuth } from "./patch-env.js";
9
+ import { pruneCoreAuthForSlimTemplate } from "./prune-core-auth.js";
10
+ import { syncCacheConstantsWithoutOAuth } from "./sync-auth-strategy-files.js";
11
+ const partsToRemove = [
12
+ {
13
+ path: "src/infra/repositories/repository.module.ts",
14
+ removeImports: [
15
+ "@/domain/repositories/iperson.repository",
16
+ "@/infra/repositories/person.repository",
17
+ "./person.repository",
18
+ "@/domain/repositories/iuser.repository",
19
+ "@/infra/repositories/user.repository"
20
+ ],
21
+ replace: [
22
+ {
23
+ from: `providers: [
24
+ { provide: IPersonRepository, useClass: PersonRepository },
25
+ { provide: IUserRepository, useClass: UserRepository },
26
+ ],
27
+ `,
28
+ to: ""
29
+ },
30
+ {
31
+ from: `providers: [{ provide: IPersonRepository, useClass: PersonRepository }],
32
+ `,
33
+ to: ""
34
+ },
35
+ {
36
+ from: `providers: [{ provide: IUserRepository, useClass: UserRepository }],
37
+ `,
38
+ to: ""
39
+ },
40
+ { from: ", IPersonRepository", to: "" },
41
+ { from: ", IUserRepository", to: "" }
42
+ ]
43
+ },
44
+ {
45
+ path: "src/infra/database/data-source-factory.ts",
46
+ removeImports: [
47
+ "@/domain/entities/person/person",
48
+ "@/domain/entities/person/person-address",
49
+ "@/domain/entities/person/person-contact",
50
+ "@/domain/entities/user/user"
51
+ ],
52
+ replace: [
53
+ {
54
+ from: "entities: [Person, PersonAddress, PersonContact, User],",
55
+ to: "entities: [],"
56
+ },
57
+ {
58
+ from: "entities: [Person, PersonAddress, PersonContact],",
59
+ to: "entities: [],"
60
+ },
61
+ {
62
+ from: "entities: [User],",
63
+ to: "entities: [],"
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ path: "src/host/app.module.ts",
69
+ removeImports: [
70
+ "./controllers/person/person.module",
71
+ "@/application/person/jobs/events/person/inactive-person/inactive-person.handler",
72
+ "@/application/person/jobs/cron/create-person.job",
73
+ "@/application/person/jobs/cron/delete-inactive.job"
74
+ ],
75
+ replace: [
76
+ { from: `PersonModule,
77
+ `, to: "" },
78
+ { from: `imports: [PersonModule],
79
+ `, to: "" }
80
+ ]
81
+ },
82
+ {
83
+ path: "src/application/mapping/mapping.provider.ts",
84
+ removeImports: ["./person.mapper"],
85
+ replace: [{ from: "PersonMapper.createMap();", to: "" }]
86
+ }
87
+ ];
88
+ const defaultTemplatePathsToRemove = [
89
+ "src/test/application",
90
+ "src/test/mockup/person",
91
+ "src/test/host/controllers/person/person.controller.e2e.spec.ts",
92
+ "src/test/host/controllers/person/lazy-loading.e2e.spec.ts",
93
+ "src/test/host/controllers/auth/auth.controller.e2e.spec.ts",
94
+ "src/test/app-auth-test.module.ts",
95
+ "src/test/create-auth-e2e-test-app.ts"
96
+ ];
97
+ const defaultTemplatePathsToRemoveWithoutAuth = [
98
+ "src/test/application/auth-link.handler.spec.ts",
99
+ "src/test/application/exchange-code.handler.spec.ts",
100
+ "src/test/application/login.handler.spec.ts",
101
+ "src/test/application/refresh-token.handler.spec.ts",
102
+ "src/test/application/scalar-oauth-token.handler.spec.ts",
103
+ "src/test/core/auth.guard.spec.ts",
104
+ "src/test/core/jwt.strategy.spec.ts",
105
+ "src/test/core/oauth-provider.registry.spec.ts",
106
+ "src/test/core/profiles.guard.spec.ts",
107
+ "src/test/host/is-public-open-api.spec.ts",
108
+ "src/test/host/oauth-callback.controller.spec.ts",
109
+ "src/test/infra/jwt-token.service.spec.ts",
110
+ "src/test/infra/logged-user-info.service.spec.ts",
111
+ "src/test/infra/oauth2-auth.service.spec.ts",
112
+ "src/test/services/logged-user-info.fake-service.ts",
113
+ "src/test/utils/jwt-test-keys.ts",
114
+ "src/test/core/env.spec.ts",
115
+ "src/test/core/oauth-provider.registry.spec.ts",
116
+ "src/host/decorators/scalar-token-endpoint.decorator.ts",
117
+ "src/host/decorators/restriction-by-profile.decorator.ts"
118
+ ];
119
+ const defaultTemplateAuthArtifactPaths = [
120
+ "src/application/auth",
121
+ "src/domain/auth",
122
+ "src/domain/entities/user",
123
+ "src/domain/repositories/iuser.repository.ts",
124
+ "src/domain/dtos/logged-user-info.dto.ts",
125
+ "src/domain/services",
126
+ "src/infra/auth",
127
+ "src/infra/repositories/user.repository.ts",
128
+ "src/infra/services/logged-user-info.service.ts",
129
+ "src/host/security",
130
+ "src/host/controllers/auth",
131
+ "src/host/controllers/oauth2",
132
+ "src/core/types/auth-provider-config-response.type.ts",
133
+ "src/core/utils/hash-password.ts",
134
+ "src/core/utils/name-to-login.ts"
135
+ ];
136
+ function removePaths(projectName, paths) {
137
+ for (const relativePath of paths) {
138
+ rmSync(path.join(resolveProjectPath(projectName), relativePath), {
139
+ recursive: true,
140
+ force: true
141
+ });
142
+ }
143
+ }
144
+ export async function removeSampleParts(projectName) {
145
+ for (const part of partsToRemove) {
146
+ const partPath = path.join(resolveProjectPath(projectName), part.path);
147
+ let content = readFileSync(partPath, "utf8");
148
+ if (part.removeImports?.length) {
149
+ content = removeImportLines(content, part.removeImports);
150
+ }
151
+ for (const replace of part.replace ?? []) {
152
+ content = content.replace(replace.from, replace.to);
153
+ }
154
+ writeFileSync(partPath, content, "utf8");
155
+ }
156
+ patchAppModuleJobs(projectName, { eventHandlers: [], cronJobs: [] });
157
+ removePaths(projectName, defaultTemplatePathsToRemove);
158
+ }
159
+ export async function cleanDefaultTemplateWithoutAuth(projectName) {
160
+ stripDefaultProjectAuth(projectName);
161
+ stripDefineDocumentationAuth(projectName);
162
+ stripEnvAuth(projectName);
163
+ removePaths(projectName, defaultTemplatePathsToRemoveWithoutAuth);
164
+ removePaths(projectName, defaultTemplateAuthArtifactPaths);
165
+ pruneCoreAuthForSlimTemplate(projectName);
166
+ syncCacheConstantsWithoutOAuth(projectName);
167
+ }
168
+ function patchAppModuleForInfra(content) {
169
+ if (content.includes("InfraModule")) {
170
+ return content;
171
+ }
172
+ const patched = content.replace("import { ConfigModule } from '@nestjs/config';", `import { ConfigModule } from '@nestjs/config';
173
+ import { InfraModule } from '@/infra/infra.module';`);
174
+ return patched.replace(/(ConfigModule\.forRoot\(\{[\s\S]*?\}\),)\n/, `$1
175
+ InfraModule,
176
+ `);
177
+ }
178
+ function stripDefaultProjectAuth(projectName) {
179
+ const projectRoot = resolveProjectPath(projectName);
180
+ const appModulePath = path.join(projectRoot, "src/host/app.module.ts");
181
+ const mainPath = path.join(projectRoot, "src/host/main.ts");
182
+ if (existsSync(appModulePath)) {
183
+ patchAppModuleJobs(projectName, { eventHandlers: [], cronJobs: [] });
184
+ let appModule = readFileSync(appModulePath, "utf8");
185
+ appModule = removeImportLines(appModule, [
186
+ "./controllers/auth/auth.module",
187
+ "./security/security.module"
188
+ ]);
189
+ appModule = appModule.replace(/\s*SecurityModule,\n/g, "").replace(/\s*AuthModule,\n/g, "");
190
+ appModule = patchAppModuleForInfra(appModule);
191
+ writeFileSync(appModulePath, appModule, "utf8");
192
+ }
193
+ if (existsSync(mainPath)) {
194
+ let main = readFileSync(mainPath, "utf8");
195
+ main = removeImportLines(main, [
196
+ "./security/guards/auth.guard",
197
+ "./security/guards/profiles.guard"
198
+ ]);
199
+ main = main.replace(/\n {2}app\.useGlobalGuards\([\s\S]*?\);\n/, `
200
+ `);
201
+ writeFileSync(mainPath, stripMainOptionalFeatures(main), "utf8");
202
+ }
203
+ }
@@ -0,0 +1,19 @@
1
+ import path from "node:path";
2
+ import { existsSync } from "node:fs";
3
+ export function resolveProjectPath(projectName) {
4
+ const cwd = process.cwd();
5
+ if (!projectName || projectName === ".") {
6
+ return cwd;
7
+ }
8
+ if (path.isAbsolute(projectName)) {
9
+ return projectName;
10
+ }
11
+ const nestedPath = path.join(cwd, projectName);
12
+ if (existsSync(path.join(nestedPath, "package.json"))) {
13
+ return nestedPath;
14
+ }
15
+ if (path.basename(cwd) === projectName && existsSync(path.join(cwd, "package.json"))) {
16
+ return cwd;
17
+ }
18
+ return nestedPath;
19
+ }
@@ -0,0 +1,64 @@
1
+ import { cpSync, existsSync, mkdirSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { getSourceCodePath } from "./get-source-code-path.js";
4
+ import { patchAppModuleExampleJobs } from "./patch-jobs-module.js";
5
+ import { resolveProjectPath } from "./resolve-project-path.js";
6
+ function projectFile(projectName, relativePath) {
7
+ return path.join(resolveProjectPath(projectName), relativePath);
8
+ }
9
+ function hasPersonModule(projectName) {
10
+ return existsSync(projectFile(projectName, "src/host/controllers/person/person.module.ts"));
11
+ }
12
+ export function copyFromTemplate(relativePath, projectName = "") {
13
+ const sourcePath = path.join(getSourceCodePath(), relativePath);
14
+ const targetPath = projectFile(projectName, relativePath);
15
+ mkdirSync(path.dirname(targetPath), { recursive: true });
16
+ cpSync(sourcePath, targetPath, { recursive: true, force: true });
17
+ }
18
+ export async function restorePersonCacheFeatures(projectName) {
19
+ if (!hasPersonModule(projectName)) {
20
+ return;
21
+ }
22
+ const files = [
23
+ "src/application/person/create/create-person.handler.ts",
24
+ "src/application/person/update/update-person.handler.ts",
25
+ "src/application/person/delete/delete-person.handler.ts",
26
+ "src/application/person/read-many/read-many-person.handler.ts",
27
+ "src/application/person/jobs/events/person/inactive-person/inactive-person.handler.ts",
28
+ "src/core/utils/person-list-cache.ts",
29
+ "src/core/utils/build-list-cache-key.ts"
30
+ ];
31
+ for (const file of files) {
32
+ copyFromTemplate(file, projectName);
33
+ }
34
+ }
35
+ export async function restorePersonCronJobs(projectName) {
36
+ if (!hasPersonModule(projectName)) {
37
+ return;
38
+ }
39
+ copyFromTemplate("src/application/person/jobs/cron", projectName);
40
+ patchAppModuleExampleJobs(projectName, {
41
+ eventJobs: existsSync(projectFile(projectName, "src/application/person/jobs/events/person/inactive-person/inactive-person.handler.ts")),
42
+ cronJobs: true
43
+ });
44
+ }
45
+ export async function restorePersonEventJobs(projectName) {
46
+ if (!hasPersonModule(projectName)) {
47
+ return;
48
+ }
49
+ copyFromTemplate("src/application/person/jobs/events", projectName);
50
+ patchAppModuleExampleJobs(projectName, {
51
+ eventJobs: true,
52
+ cronJobs: existsSync(projectFile(projectName, "src/application/person/jobs/cron/create-person.job.ts"))
53
+ });
54
+ }
55
+ export async function restorePersonAuthExample(projectName) {
56
+ if (!hasPersonModule(projectName)) {
57
+ return;
58
+ }
59
+ copyFromTemplate("src/host/controllers/person/delete-person.controller.ts", projectName);
60
+ }
61
+ export async function upgradeCacheToRedis(projectName) {
62
+ copyFromTemplate("src/infra/common/redis-cache.service.ts", projectName);
63
+ copyFromTemplate("src/infra/common/cache-service.provider.ts", projectName);
64
+ }
@@ -0,0 +1,31 @@
1
+ import { spawn } from "node:child_process";
2
+ import { isCliVerbose } from "./cli-options.js";
3
+ export function runCommand(command, cwd = process.cwd(), options = {}) {
4
+ return new Promise((resolve, reject) => {
5
+ const verbose = options.verbose ?? isCliVerbose();
6
+ const childProcess = spawn(command[0], command.slice(1), {
7
+ cwd,
8
+ stdio: verbose ? "inherit" : "pipe"
9
+ });
10
+ let stderr = "";
11
+ childProcess.stderr?.on("data", (chunk) => {
12
+ if (verbose) {
13
+ return;
14
+ }
15
+ stderr += chunk.toString();
16
+ });
17
+ childProcess.on("close", (code) => {
18
+ if (code !== 0) {
19
+ if (!verbose && stderr.trim()) {
20
+ process.stderr.write(stderr);
21
+ }
22
+ reject(new Error(`Command ${command.join(" ")} failed with code ${code}`));
23
+ return;
24
+ }
25
+ resolve();
26
+ });
27
+ childProcess.on("error", (error) => {
28
+ reject(error);
29
+ });
30
+ });
31
+ }
@@ -0,0 +1,63 @@
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 envSpecJwtOnly = `import { describe, expect, it } from 'bun:test';
7
+ import { envSchema } from '@/core/env';
8
+
9
+ describe('envSchema', () => {
10
+ it('interpreta CRON_JOBS_ENABLED=false como desabilitado', () => {
11
+ const env = envSchema.parse({
12
+ NODE_ENV: 'test',
13
+ DATABASE_URL: 'postgres://localhost/test',
14
+ CRON_JOBS_ENABLED: 'false',
15
+ });
16
+
17
+ expect(env.CRON_JOBS_ENABLED).toBe(false);
18
+ });
19
+ });
20
+ `;
21
+ const cacheConstantsJwtOnly = `/** Prefixos e chaves do cache distribuído / em memória. */
22
+ export const CacheKeyPrefix = {
23
+ RED_LOCK: 'redLock:',
24
+ } as const;
25
+
26
+ /** TTLs em segundos para entradas de cache. */
27
+ export const CacheTtlSeconds = {
28
+ /** Listagem paginada de Person (2 minutos). */
29
+ PERSON_LIST: 120,
30
+ } as const;
31
+
32
+ /** TTL padrão do RedLock quando não derivado do cron (segundos). */
33
+ export const DEFAULT_RED_LOCK_TTL_SECONDS = 30;
34
+ `;
35
+ function writeCacheConstantsWithoutOAuth(projectName) {
36
+ writeProjectFile(projectName, "src/core/constants/cache.constants.ts", cacheConstantsJwtOnly);
37
+ }
38
+ function writeProjectFile(projectName, relativePath, content) {
39
+ const filePath = path.join(resolveProjectPath(projectName), relativePath);
40
+ mkdirSync(path.dirname(filePath), { recursive: true });
41
+ writeFileSync(filePath, content);
42
+ }
43
+ function restoreProjectFile(projectName, relativePath) {
44
+ cpSync(path.join(getSourceCodePath(), relativePath), path.join(resolveProjectPath(projectName), relativePath), { force: true });
45
+ }
46
+ export function syncAuthStrategySupportFiles(projectName, strategies) {
47
+ const hasJwt = strategies.includes(AuthStrategy.JWT);
48
+ const hasOauth = strategies.includes(AuthStrategy.OAUTH2);
49
+ if (hasJwt && !hasOauth) {
50
+ writeProjectFile(projectName, "src/test/core/env.spec.ts", envSpecJwtOnly);
51
+ writeCacheConstantsWithoutOAuth(projectName);
52
+ return;
53
+ }
54
+ for (const relativePath of [
55
+ "src/test/core/env.spec.ts",
56
+ "src/core/constants/cache.constants.ts"
57
+ ]) {
58
+ restoreProjectFile(projectName, relativePath);
59
+ }
60
+ }
61
+ export function syncCacheConstantsWithoutOAuth(projectName) {
62
+ writeCacheConstantsWithoutOAuth(projectName);
63
+ }
@@ -0,0 +1,34 @@
1
+ PORT=3000
2
+ NODE_ENV=develop
3
+ DATABASE_URL=postgresql://postgres:root@localhost:5432/koala_nest
4
+
5
+ # Redis (opcional)
6
+ # Instância única: pode omitir — usa memória local (cache, state OAuth2, lock de CronJob em dev).
7
+ # Várias réplicas: recomendado para cache/lock/state OAuth2 consistentes entre processos.
8
+ # REDIS_CONNECTION_STRING=redis://localhost:6379
9
+ # CACHE_KEY_PREFIX=koala-nest
10
+
11
+ # Cron jobs de exemplo (create/delete person). Habilitado no template para demonstração em dev.
12
+ CRON_JOBS_ENABLED=true
13
+ BOOTSTRAP_DELAY_MS=0
14
+
15
+ # JWT (RS256 — chaves em base64) — ative com `kl-nest new --auth jwt` ou `kl-nest add auth jwt`
16
+ JWT_PRIVATE_KEY=
17
+ JWT_PUBLIC_KEY=
18
+ JWT_ACCESS_TOKEN_EXPIRES_IN=15m
19
+ JWT_REFRESH_TOKEN_EXPIRES_IN=7d
20
+ API_HOST=http://localhost:3000
21
+
22
+ # Usuário demo (migration Init): admin@example.com / admin123
23
+
24
+ # OAuth2 — N provedores via OAUTH2_PROVIDERS (google,microsoft são exemplos)
25
+ # Para cada CHAVE: OAUTH2_{CHAVE}_DOMAIN (OIDC) ou URLs manuais (_AUTHORIZATION_URL, _TOKEN_URL, _USERINFO_URL)
26
+ OAUTH2_PROVIDERS=google,microsoft
27
+ OAUTH2_GOOGLE_DOMAIN=https://accounts.google.com
28
+ OAUTH2_GOOGLE_CLIENT_ID=
29
+ OAUTH2_GOOGLE_CLIENT_SECRET=
30
+ OAUTH2_GOOGLE_SCOPE=openid profile email
31
+ OAUTH2_MICROSOFT_DOMAIN=https://login.microsoftonline.com/common/v2.0
32
+ OAUTH2_MICROSOFT_CLIENT_ID=
33
+ OAUTH2_MICROSOFT_CLIENT_SECRET=
34
+ OAUTH2_MICROSOFT_SCOPE=openid profile email
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
@@ -0,0 +1,51 @@
1
+ # Koala Nest
2
+
3
+ Template NestJS com arquitetura em camadas (application, domain, host, infra) usado pela CLI `kl-nest`.
4
+
5
+ ## Documentação
6
+
7
+ A documentação completa está em [`libs/doc`](../../doc). Para subir o site localmente, na raiz do monorepo:
8
+
9
+ ```bash
10
+ bun run dev:docs
11
+ ```
12
+
13
+ ## Desenvolvimento local
14
+
15
+ ```bash
16
+ bun install
17
+ cp .env.example .env
18
+ bun run build
19
+ bun run start:dev
20
+ ```
21
+
22
+ Documentação OpenAPI/Scalar: `http://localhost:3000/doc`
23
+
24
+ ## Testes
25
+
26
+ ```bash
27
+ bun run test # unitários da lib (Bun)
28
+ bun run test:e2e # E2E da lib (requer DATABASE_URL)
29
+ ```
30
+
31
+ Testes da CLI e da documentação ficam em `libs/cli` e `libs/doc/site` — na raiz do monorepo use `bun run test:cli` e `bun run test:docs`.
32
+
33
+ ## Autenticação
34
+
35
+ O template **Exemplo de CRUD** sobe apenas `PersonModule`. Ao criar um projeto com `kl-nest new`, a CLI instala JWT ou OAuth2 e aplica patches em `app.module.ts` e `main.ts` (`SecurityModule`, `AuthModule`, guards globais).
36
+
37
+ ## Dependências Koala
38
+
39
+ | Pacote | Uso |
40
+ |--------|-----|
41
+ | [`@koalarx/utils`](https://www.npmjs.com/package/@koalarx/utils) | `delay`, validação/máscara CPF-CNPJ, utilitários de string/data |
42
+
43
+ Veja a [documentação Koala Utils](../../doc/markdown/pt/core/koala-utils.md).
44
+
45
+ ## Scripts úteis
46
+
47
+ | Script | Descrição |
48
+ |--------|-----------|
49
+ | `start:debug` | Nest em watch com inspector |
50
+ | `migration:run` | Aplica migrations TypeORM |
51
+ | `migration:generate` | Gera migration a partir das entidades |
@@ -0,0 +1,7 @@
1
+ [test]
2
+ root = "src"
3
+ preload = ["./src/test/setup.ts"]
4
+ timeoutMs = 60000
5
+
6
+ [loader]
7
+ ".ts" = "tsx"
@@ -0,0 +1,55 @@
1
+ // @ts-check
2
+ import eslint from '@eslint/js';
3
+ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
4
+ import globals from 'globals';
5
+ import tseslint from 'typescript-eslint';
6
+
7
+ const sharedRules = {
8
+ '@typescript-eslint/no-explicit-any': 'off',
9
+ '@typescript-eslint/no-floating-promises': 'off',
10
+ '@typescript-eslint/no-unsafe-argument': 'off',
11
+ '@typescript-eslint/no-unsafe-call': 'off',
12
+ '@typescript-eslint/no-unsafe-member-access': 'off',
13
+ '@typescript-eslint/no-unsafe-assignment': 'off',
14
+ '@typescript-eslint/no-unsafe-return': 'off',
15
+ '@typescript-eslint/no-unsafe-function-type': 'off',
16
+ '@typescript-eslint/no-unused-vars': [
17
+ 'error',
18
+ {
19
+ argsIgnorePattern: '^_',
20
+ varsIgnorePattern: '^_',
21
+ },
22
+ ],
23
+ 'prettier/prettier': ['error', { endOfLine: 'auto' }],
24
+ };
25
+
26
+ export default tseslint.config(
27
+ {
28
+ ignores: ['eslint.config.mjs'],
29
+ },
30
+ eslint.configs.recommended,
31
+ ...tseslint.configs.recommendedTypeChecked,
32
+ eslintPluginPrettierRecommended,
33
+ {
34
+ languageOptions: {
35
+ globals: {
36
+ ...globals.node,
37
+ ...globals.jest,
38
+ },
39
+ sourceType: 'module',
40
+ parserOptions: {
41
+ project: ['./tsconfig.json', './tsconfig.spec.json'],
42
+ tsconfigRootDir: import.meta.dirname,
43
+ },
44
+ },
45
+ rules: sharedRules,
46
+ },
47
+ {
48
+ files: ['src/test/**/*.ts'],
49
+ rules: {
50
+ '@typescript-eslint/require-await': 'off',
51
+ '@typescript-eslint/no-misused-promises': 'off',
52
+ '@typescript-eslint/await-thenable': 'off',
53
+ },
54
+ },
55
+ );
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/nest-cli",
3
+ "collection": "@nestjs/schematics",
4
+ "sourceRoot": "src",
5
+ "entryFile": "host/main",
6
+ "compilerOptions": {
7
+ "deleteOutDir": true
8
+ }
9
+ }
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "koala-nest",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "author": "",
6
+ "private": true,
7
+ "license": "UNLICENSED",
8
+ "scripts": {
9
+ "build": "nest build",
10
+ "format": "prettier --write \"src/**/*.ts\"",
11
+ "format:cli": "prettier --write \"../cli/**/*.ts\"",
12
+ "format:all": "prettier --write \"src/**/*.ts\" \"../cli/**/*.ts\"",
13
+ "fix:all": "prettier --write \"src/**/*.ts\" \"../cli/**/*.ts\" && eslint \"src/**/*.ts\" --fix && cd ../cli && ../koala-nest/node_modules/.bin/eslint \"**/*.ts\" --fix",
14
+ "start": "nest start",
15
+ "start:dev": "nest start --watch",
16
+ "start:debug": "nest start --debug --watch",
17
+ "start:prod": "node dist/host/main",
18
+ "lint": "eslint \"src/**/*.ts\" --fix",
19
+ "lint:all": "eslint \"src/**/*.ts\" --fix && cd ../cli && ../koala-nest/node_modules/.bin/eslint \"**/*.ts\" --fix",
20
+ "test": "bun test src/test/core/ src/test/application/ src/test/infra/ src/test/host/is-public-open-api.spec.ts src/test/host/oauth-callback.controller.spec.ts src/test/host/errors.filter.spec.ts",
21
+ "test:e2e": "bun test --preload ./src/test/setup-e2e.ts src/test/host/controllers/",
22
+ "test:watch": "bun test --watch",
23
+ "migration:generate": "bun ./src/infra/database/migrations/generate-migration.ts",
24
+ "migration:run": "bun ./node_modules/typeorm/cli.js migration:run -d ./src/infra/database/migrations/migration-datasource.ts",
25
+ "migration:revert": "bun ./node_modules/typeorm/cli.js migration:revert -d ./src/infra/database/migrations/migration-datasource.ts"
26
+ },
27
+ "dependencies": {
28
+ "@koalarx/utils": "^4.2.3",
29
+ "@nestjs/axios": "^4.0.1",
30
+ "@nestjs/common": "^11.0.1",
31
+ "@nestjs/config": "^4.0.4",
32
+ "@nestjs/core": "^11.0.1",
33
+ "@nestjs/jwt": "^11.0.0",
34
+ "@nestjs/passport": "^11.0.0",
35
+ "@nestjs/platform-express": "^11.0.1",
36
+ "@nestjs/swagger": "^11.4.4",
37
+ "@nestjs/terminus": "^11.0.0",
38
+ "@scalar/nestjs-api-reference": "^1.2.3",
39
+ "bcrypt": "^6.0.0",
40
+ "cookie-parser": "^1.4.7",
41
+ "cron-parser": "^5.5.0",
42
+ "ioredis": "^5.11.1",
43
+ "passport": "^0.7.0",
44
+ "passport-jwt": "^4.0.1",
45
+ "pg": "^8.21.0",
46
+ "reflect-metadata": "^0.2.2",
47
+ "rxjs": "^7.8.1",
48
+ "typeorm": "^1.0.0",
49
+ "zod": "^4.4.3"
50
+ },
51
+ "devDependencies": {
52
+ "@eslint/eslintrc": "^3.2.0",
53
+ "@eslint/js": "^9.18.0",
54
+ "@nestjs/cli": "^11.0.0",
55
+ "@nestjs/schematics": "^11.0.0",
56
+ "@nestjs/testing": "^11.0.1",
57
+ "@types/bun": "^1.3.14",
58
+ "@types/cookie-parser": "^1.4.10",
59
+ "@types/express": "^5.0.0",
60
+ "@types/node": "^22.10.7",
61
+ "@types/passport-jwt": "^4.0.1",
62
+ "@types/pg": "^8.11.6",
63
+ "@types/supertest": "^6.0.2",
64
+ "dotenv": "^16.4.7",
65
+ "eslint": "^9.18.0",
66
+ "eslint-config-prettier": "^10.0.1",
67
+ "eslint-plugin-prettier": "^5.2.2",
68
+ "globals": "^16.0.0",
69
+ "prettier": "^3.4.2",
70
+ "source-map-support": "^0.5.21",
71
+ "supertest": "^7.1.0",
72
+ "ts-jest": "^29.2.5",
73
+ "ts-loader": "^9.5.2",
74
+ "ts-node": "^10.9.2",
75
+ "tsconfig-paths": "^4.2.0",
76
+ "typescript": "^5.7.3",
77
+ "typescript-eslint": "^8.20.0"
78
+ }
79
+ }
@@ -0,0 +1,15 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+
3
+ export class AuthTokenResponse {
4
+ @ApiProperty()
5
+ accessToken: string;
6
+
7
+ @ApiProperty({ name: 'access_token' })
8
+ access_token: string;
9
+
10
+ @ApiProperty()
11
+ refreshToken: string;
12
+
13
+ @ApiProperty({ name: 'refresh_token' })
14
+ refresh_token: string;
15
+ }
@@ -0,0 +1,6 @@
1
+ import { JwtClaims } from '@/core/auth/jwt-claims';
2
+ import { User } from '@/domain/entities/user/user';
3
+
4
+ export function userToJwtClaims(user: User): JwtClaims {
5
+ return { sub: user.id };
6
+ }