@futdevpro/nts-dynamo 1.15.157 → 1.15.163

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 (642) hide show
  1. package/LICENSE +17 -17
  2. package/build/_modules/account-security/_enums/account-challenge-purpose.type-enum.d.ts +7 -1
  3. package/build/_modules/account-security/_enums/account-challenge-purpose.type-enum.d.ts.map +1 -1
  4. package/build/_modules/account-security/_enums/account-challenge-purpose.type-enum.js +6 -0
  5. package/build/_modules/account-security/_enums/account-challenge-purpose.type-enum.js.map +1 -1
  6. package/build/_modules/account-security/account-challenge.control-service.d.ts +1 -1
  7. package/build/_modules/account-security/account-challenge.control-service.d.ts.map +1 -1
  8. package/build/_modules/account-security/account-challenge.control-service.js +1 -1
  9. package/build/_modules/account-security/account-challenge.control-service.js.map +1 -1
  10. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.d.ts +71 -0
  11. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.d.ts.map +1 -0
  12. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.js +3 -0
  13. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.js.map +1 -0
  14. package/build/_modules/privacy-lifecycle/index.d.ts +3 -0
  15. package/build/_modules/privacy-lifecycle/index.d.ts.map +1 -1
  16. package/build/_modules/privacy-lifecycle/index.js +5 -1
  17. package/build/_modules/privacy-lifecycle/index.js.map +1 -1
  18. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.d.ts +48 -0
  19. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.d.ts.map +1 -0
  20. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.js +332 -0
  21. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.js.map +1 -0
  22. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.d.ts +25 -0
  23. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.d.ts.map +1 -0
  24. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.js +126 -0
  25. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.js.map +1 -0
  26. package/package.json +11 -4
  27. package/.c8rc.json +0 -26
  28. package/.copilot/patterns.json +0 -8
  29. package/.cursor/rules/__assistant_guide.mdc +0 -30
  30. package/.cursor/rules/__main.mdc +0 -64
  31. package/.cursor/rules/_ag_backend-structure.mdc +0 -86
  32. package/.cursor/rules/_ag_backend.mdc +0 -16
  33. package/.cursor/rules/_ag_debug.mdc +0 -8
  34. package/.cursor/rules/_ag_documentation_writing_rules.mdc +0 -372
  35. package/.cursor/rules/_ag_file-refactoring.mdc +0 -113
  36. package/.cursor/rules/_ag_fixes_rules.mdc +0 -6
  37. package/.cursor/rules/_ag_frontend-structure.mdc +0 -87
  38. package/.cursor/rules/_ag_frontend.mdc +0 -40
  39. package/.cursor/rules/_ag_import-rules.mdc +0 -45
  40. package/.cursor/rules/_ag_naming.mdc +0 -116
  41. package/.cursor/rules/_ag_running_commands.mdc +0 -5
  42. package/.cursor/rules/_ag_server-controller.mdc +0 -6
  43. package/.cursor/rules/_ag_should-be.mdc +0 -7
  44. package/.cursor/rules/_ag_swearing.mdc +0 -47
  45. package/.cursor/rules/ai_development_guide.md +0 -61
  46. package/.cursor/rules/ai_directives.md +0 -114
  47. package/.cursor/rules/cursor-rules.md +0 -160
  48. package/.cursor/rules/default-command.mdc +0 -465
  49. package/.cursor/rules/error_code_pattern.md +0 -40
  50. package/.cursor/rules/saved rule mcp server use.md +0 -16
  51. package/.dynamo/pipeline.cicd.config.json +0 -190
  52. package/.dynamo/version-bump.config.json +0 -5
  53. package/.github/workflows/main.yml +0 -438
  54. package/.husky/pre-commit +0 -3
  55. package/.vscode/settings.json +0 -11
  56. package/BuildPackage.bat +0 -1
  57. package/HOWTO.md +0 -15
  58. package/__documentations/2026-04-28-logs-module.md +0 -49
  59. package/__documentations/2026-05-17-oai-compatible-providers.md +0 -229
  60. package/__documentations/2026-05-17-static-client-serving-howto.md +0 -144
  61. package/__documentations/2026-06-01-fr041-cors-middleware.md +0 -96
  62. package/__documentations/2026-06-01-fr047-p2p3-function-calling.md +0 -81
  63. package/__documentations/2026-06-15-fr193-memory-guard.md +0 -73
  64. package/__documentations/2026-08-08-fr292-app-version-header.md +0 -38
  65. package/__documentations/2026-08-14-field-encryption-mongoose-document-spread.md +0 -124
  66. package/__documentations/2026-08-18-artifact-compiler.md +0 -46
  67. package/__documentations/2026-08-18-mongo-transaction-control-service.md +0 -82
  68. package/__documentations/2026-08-18-standalone-account-security-and-privacy-bedrock.md +0 -132
  69. package/__documentations/2026-08-21-distributed-rate-limit-bfr-ctm-010.md +0 -59
  70. package/__documentations/2026-08-22-bfr-ctm-018-content-free-endpoint-errors.md +0 -54
  71. package/__documentations/2026-08-22-bfr-ctm-020-content-free-request-telemetry.md +0 -65
  72. package/__documentations/2026-08-22-content-free-process-error-boundary.md +0 -111
  73. package/__documentations/2026-08-22-npm-token-state-classifier.md +0 -92
  74. package/__documentations/nts-integration-tests-2026-03-17.md +0 -26
  75. package/__documentations/plans/BEDROCK-HYPERPLAN.md +0 -95
  76. package/_specifications/BACKLOG.md +0 -92
  77. package/_specifications/TODO.md +0 -15
  78. package/_specifications/agent.md +0 -138
  79. package/eslint.config.js +0 -3
  80. package/nodemon.json +0 -24
  81. package/pnpm-workspace.yaml +0 -6
  82. package/scripts/_seed-out/aim-seed.fixtures.ts +0 -161
  83. package/scripts/_seed-out/image-raw.json +0 -1
  84. package/scripts/_seed-out/llm-expand-raw.json +0 -60
  85. package/scripts/_seed-out/sample-image.png +0 -0
  86. package/scripts/_seed-out/seed-raw.json +0 -153
  87. package/scripts/ai-fixture-seed.js +0 -126
  88. package/scripts/run-coverage-tests.js +0 -28
  89. package/spec/support/helpers/spec-reporter-loader.js +0 -359
  90. package/spec/support/helpers/ts-node-helper.js +0 -93
  91. package/spec/support/jasmine.coverage.json +0 -24
  92. package/spec/support/jasmine.json +0 -24
  93. package/src/_assets/dynamo-nts-logo-128.png +0 -0
  94. package/src/_assets/dynamo-nts-logo-256.png +0 -0
  95. package/src/_assets/dynamo-nts-logo-512.png +0 -0
  96. package/src/_assets/dynamo-nts-logo-64.png +0 -0
  97. package/src/_collections/app-version-header.util.spec.ts +0 -108
  98. package/src/_collections/app-version-header.util.ts +0 -74
  99. package/src/_collections/archive-service-registry.const.ts +0 -21
  100. package/src/_collections/archive.util.spec.ts +0 -57
  101. package/src/_collections/archive.util.ts +0 -18
  102. package/src/_collections/atlas-default-db-options.const.ts +0 -10
  103. package/src/_collections/client-safe-error.util.spec.ts +0 -151
  104. package/src/_collections/client-safe-error.util.ts +0 -107
  105. package/src/_collections/default-fallback-cache-max-age.const.spec.ts +0 -11
  106. package/src/_collections/default-fallback-cache-max-age.const.ts +0 -2
  107. package/src/_collections/default-not-found-page.const.spec.ts +0 -19
  108. package/src/_collections/default-not-found-page.const.ts +0 -22
  109. package/src/_collections/default-socket-path.const.spec.ts +0 -12
  110. package/src/_collections/default-socket-path.const.ts +0 -2
  111. package/src/_collections/field-encryption.util.spec.ts +0 -195
  112. package/src/_collections/field-encryption.util.ts +0 -222
  113. package/src/_collections/get-environment-settings.util.spec.ts +0 -210
  114. package/src/_collections/get-environment-settings.util.ts +0 -49
  115. package/src/_collections/global-settings.const.ts +0 -126
  116. package/src/_collections/load-shed.util.spec.ts +0 -62
  117. package/src/_collections/load-shed.util.ts +0 -51
  118. package/src/_collections/mongo-reconnect-guard.util.spec.ts +0 -52
  119. package/src/_collections/mongo-reconnect-guard.util.ts +0 -172
  120. package/src/_collections/npm-token-check.util.spec.ts +0 -218
  121. package/src/_collections/npm-token-check.util.ts +0 -327
  122. package/src/_collections/sample.env +0 -21
  123. package/src/_collections/security-headers.util.spec.ts +0 -98
  124. package/src/_collections/security-headers.util.ts +0 -96
  125. package/src/_collections/signed-url.util.spec.ts +0 -198
  126. package/src/_collections/signed-url.util.ts +0 -170
  127. package/src/_collections/star.controller.spec.ts +0 -224
  128. package/src/_collections/star.controller.ts +0 -130
  129. package/src/_collections/static-cache-control.util.spec.ts +0 -47
  130. package/src/_collections/static-cache-control.util.ts +0 -25
  131. package/src/_enums/data-model-type.enum.ts +0 -14
  132. package/src/_enums/data-service-function.enum.ts +0 -24
  133. package/src/_enums/predefined-data-types.enum.ts +0 -17
  134. package/src/_enums/route-security.enum.ts +0 -12
  135. package/src/_models/control-models/api-call-params.control-model.spec.ts +0 -152
  136. package/src/_models/control-models/api-call-params.control-model.ts +0 -142
  137. package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +0 -52
  138. package/src/_models/control-models/app-ext-system-controls.control-model.ts +0 -9
  139. package/src/_models/control-models/app-params.control-model.spec.ts +0 -229
  140. package/src/_models/control-models/app-params.control-model.ts +0 -137
  141. package/src/_models/control-models/app-system-controls.control-model.spec.ts +0 -31
  142. package/src/_models/control-models/app-system-controls.control-model.ts +0 -9
  143. package/src/_models/control-models/endpoint-params.control-model.spec.ts +0 -754
  144. package/src/_models/control-models/endpoint-params.control-model.ts +0 -575
  145. package/src/_models/control-models/http-settings.control-model.spec.ts +0 -77
  146. package/src/_models/control-models/http-settings.control-model.ts +0 -37
  147. package/src/_models/control-models/system-control.control-model.spec.ts +0 -27
  148. package/src/_models/control-models/system-control.control-model.ts +0 -12
  149. package/src/_models/data-models/schema-migration.data-model.ts +0 -50
  150. package/src/_models/interfaces/app-version-header-settings.interface.ts +0 -17
  151. package/src/_models/interfaces/certification-settings.interface.ts +0 -7
  152. package/src/_models/interfaces/compare-data-options.interface.ts +0 -27
  153. package/src/_models/interfaces/compare-data-result.interface.ts +0 -12
  154. package/src/_models/interfaces/cors-settings.interface.spec.ts +0 -52
  155. package/src/_models/interfaces/cors-settings.interface.ts +0 -56
  156. package/src/_models/interfaces/db-query-options.interface.ts +0 -33
  157. package/src/_models/interfaces/environment-settings.interface.ts +0 -59
  158. package/src/_models/interfaces/global-log-settings.interface.ts +0 -171
  159. package/src/_models/interfaces/global-service-settings.interface.ts +0 -47
  160. package/src/_models/interfaces/global-settings.interface.ts +0 -294
  161. package/src/_models/interfaces/migration-entry.interface.ts +0 -19
  162. package/src/_models/interfaces/mongo-transaction-settings.interface.ts +0 -9
  163. package/src/_models/interfaces/request-telemetry-settings.interface.ts +0 -9
  164. package/src/_models/interfaces/request-telemetry-snapshot.interface.ts +0 -30
  165. package/src/_models/interfaces/routing-module-settings.interface.ts +0 -21
  166. package/src/_models/interfaces/security-headers-settings.interface.ts +0 -50
  167. package/src/_models/interfaces/signed-url-verify-result.interface.ts +0 -13
  168. package/src/_models/interfaces/static-client-settings.interface.spec.ts +0 -29
  169. package/src/_models/interfaces/static-client-settings.interface.ts +0 -36
  170. package/src/_models/types/db-update.type.ts +0 -100
  171. package/src/_modules/account-security/_enums/account-challenge-purpose.type-enum.ts +0 -5
  172. package/src/_modules/account-security/_enums/account-refresh-token-state.type-enum.ts +0 -6
  173. package/src/_modules/account-security/_enums/account-session-state.type-enum.ts +0 -6
  174. package/src/_modules/account-security/_models/account-challenge-adapter.interface.ts +0 -17
  175. package/src/_modules/account-security/_models/account-challenge-issued.interface.ts +0 -6
  176. package/src/_modules/account-security/_models/account-challenge-record.interface.ts +0 -13
  177. package/src/_modules/account-security/_models/account-challenge-result.interface.ts +0 -8
  178. package/src/_modules/account-security/_models/account-challenge-settings.interface.ts +0 -9
  179. package/src/_modules/account-security/_models/account-password-policy.interface.ts +0 -11
  180. package/src/_modules/account-security/_models/account-password-verification.interface.ts +0 -5
  181. package/src/_modules/account-security/_models/account-refresh-token-record.interface.ts +0 -13
  182. package/src/_modules/account-security/_models/account-session-adapter.interface.ts +0 -19
  183. package/src/_modules/account-security/_models/account-session-claims.interface.ts +0 -7
  184. package/src/_modules/account-security/_models/account-session-context.interface.ts +0 -6
  185. package/src/_modules/account-security/_models/account-session-create.interface.ts +0 -8
  186. package/src/_modules/account-security/_models/account-session-record.interface.ts +0 -21
  187. package/src/_modules/account-security/_models/account-session-rotate.interface.ts +0 -11
  188. package/src/_modules/account-security/_models/account-session-settings.interface.ts +0 -11
  189. package/src/_modules/account-security/_models/account-session-token-pair.interface.ts +0 -8
  190. package/src/_modules/account-security/_models/account-session-view.interface.ts +0 -13
  191. package/src/_modules/account-security/account-challenge.control-service.spec.ts +0 -195
  192. package/src/_modules/account-security/account-challenge.control-service.ts +0 -164
  193. package/src/_modules/account-security/account-password.control-service.spec.ts +0 -96
  194. package/src/_modules/account-security/account-password.control-service.ts +0 -288
  195. package/src/_modules/account-security/account-session.control-service.spec.ts +0 -294
  196. package/src/_modules/account-security/account-session.control-service.ts +0 -376
  197. package/src/_modules/account-security/index.ts +0 -31
  198. package/src/_modules/admin-auth/_models/admin-api-key-config.interface.ts +0 -33
  199. package/src/_modules/admin-auth/admin-api-key.auth-service.spec.ts +0 -200
  200. package/src/_modules/admin-auth/admin-api-key.auth-service.ts +0 -220
  201. package/src/_modules/admin-auth/index.ts +0 -2
  202. package/src/_modules/ai/_collections/ai-model-config-validator.util.spec.ts +0 -150
  203. package/src/_modules/ai/_collections/ai-model-config-validator.util.ts +0 -131
  204. package/src/_modules/ai/_collections/ai-provider-error.util.ts +0 -144
  205. package/src/_modules/ai/_models/ai-input-interfaces.ts +0 -117
  206. package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +0 -16
  207. package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.ts +0 -14
  208. package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.ts +0 -56
  209. package/src/_modules/ai/_models/interfaces/dynts-ai-provider-error.interface.ts +0 -16
  210. package/src/_modules/ai/_modules/ai-mock/_collections/aim-default-collection.util.spec.ts +0 -72
  211. package/src/_modules/ai/_modules/ai-mock/_collections/aim-default-collection.util.ts +0 -71
  212. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-match.util.spec.ts +0 -57
  213. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-match.util.ts +0 -60
  214. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-serializer.util.spec.ts +0 -56
  215. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-serializer.util.ts +0 -117
  216. package/src/_modules/ai/_modules/ai-mock/_enums/aim-modality.enum.ts +0 -28
  217. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-call-input.interface.ts +0 -14
  218. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-error.interface.ts +0 -11
  219. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-fixture.interface.ts +0 -30
  220. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-request.interface.ts +0 -19
  221. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-service-collection.interface.ts +0 -20
  222. package/src/_modules/ai/_modules/ai-mock/_services/ai-embedding-mock.service.spec.ts +0 -115
  223. package/src/_modules/ai/_modules/ai-mock/_services/ai-embedding-mock.service.ts +0 -233
  224. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-harness.service.spec.ts +0 -134
  225. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-harness.service.ts +0 -127
  226. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-pipeline.spec.ts +0 -105
  227. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-store.service.spec.ts +0 -50
  228. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-store.service.ts +0 -65
  229. package/src/_modules/ai/_modules/ai-mock/_services/aim-integration-proof.spec.ts +0 -92
  230. package/src/_modules/ai/_modules/ai-mock/_services/aim-mock.service.spec.ts +0 -112
  231. package/src/_modules/ai/_modules/ai-mock/_services/aim-mock.service.ts +0 -155
  232. package/src/_modules/ai/_modules/ai-mock/fixtures/aim-text.fixtures.ts +0 -649
  233. package/src/_modules/ai/_modules/ai-mock/index.ts +0 -47
  234. package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +0 -138
  235. package/src/_modules/ai/_modules/anthropic/index.ts +0 -5
  236. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +0 -242
  237. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.ts +0 -639
  238. package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.spec.ts +0 -295
  239. package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.ts +0 -552
  240. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +0 -209
  241. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.ts +0 -85
  242. package/src/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.ts +0 -8
  243. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.ts +0 -146
  244. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.ts +0 -163
  245. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.ts +0 -100
  246. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.ts +0 -68
  247. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.ts +0 -18
  248. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.ts +0 -19
  249. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.ts +0 -25
  250. package/src/_modules/ai/_modules/document-ai/index.ts +0 -30
  251. package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +0 -189
  252. package/src/_modules/ai/_modules/fdp-ai/index.ts +0 -5
  253. package/src/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.ts +0 -9
  254. package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +0 -83
  255. package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +0 -76
  256. package/src/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +0 -45
  257. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +0 -8
  258. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +0 -7
  259. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +0 -57
  260. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.ts +0 -293
  261. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.ts +0 -572
  262. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +0 -342
  263. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.ts +0 -435
  264. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +0 -550
  265. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.ts +0 -631
  266. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +0 -332
  267. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.ts +0 -132
  268. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +0 -462
  269. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +0 -635
  270. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +0 -489
  271. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.tools.spec.ts +0 -173
  272. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +0 -1085
  273. package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +0 -157
  274. package/src/_modules/ai/_modules/open-ai/index.ts +0 -74
  275. package/src/_modules/ai/_services/ai-embedding-provider.registry.spec.ts +0 -110
  276. package/src/_modules/ai/_services/ai-embedding-provider.registry.ts +0 -114
  277. package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +0 -98
  278. package/src/_modules/ai/_services/ai-embedding.service-base.ts +0 -48
  279. package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +0 -229
  280. package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +0 -68
  281. package/src/_modules/ai/_services/ai-llm.service-base.reconciler.spec.ts +0 -133
  282. package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +0 -250
  283. package/src/_modules/ai/_services/ai-llm.service-base.ts +0 -599
  284. package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +0 -158
  285. package/src/_modules/ai/_services/ai-provider.service-base.ts +0 -67
  286. package/src/_modules/ai/_services/ai-user-key.service-base.ts +0 -59
  287. package/src/_modules/ai/_services/lmstudio-embedding.control-service.spec.ts +0 -197
  288. package/src/_modules/ai/_services/lmstudio-embedding.control-service.ts +0 -399
  289. package/src/_modules/ai/index.ts +0 -33
  290. package/src/_modules/artifact-compiler/_enums/artifact-compile-outcome.type-enum.ts +0 -5
  291. package/src/_modules/artifact-compiler/_enums/artifact-compile-stage.type-enum.ts +0 -8
  292. package/src/_modules/artifact-compiler/_enums/artifact-retry-class.type-enum.ts +0 -6
  293. package/src/_modules/artifact-compiler/_models/artifact-compile.interface.ts +0 -35
  294. package/src/_modules/artifact-compiler/artifact-compiler.control-service.spec.ts +0 -151
  295. package/src/_modules/artifact-compiler/artifact-compiler.control-service.ts +0 -356
  296. package/src/_modules/artifact-compiler/index.ts +0 -9
  297. package/src/_modules/assistant/_collections/ass-global-settings.const.ts +0 -13
  298. package/src/_modules/assistant/_collections/ass.util.spec.ts +0 -176
  299. package/src/_modules/assistant/_collections/ass.util.ts +0 -50
  300. package/src/_modules/assistant/_models/ass-global-settings.interface.ts +0 -15
  301. package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +0 -140
  302. package/src/_modules/assistant/_services/ass-io.control-service.ts +0 -74
  303. package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +0 -192
  304. package/src/_modules/assistant/_services/ass-main.control-service.ts +0 -107
  305. package/src/_modules/assistant/index.ts +0 -19
  306. package/src/_modules/bot/_collections/bot-default-commands.const.ts +0 -12
  307. package/src/_modules/bot/_collections/bot-global-settings.const.ts +0 -39
  308. package/src/_modules/bot/_models/bot-channel-wrapper.interface.ts +0 -62
  309. package/src/_modules/bot/_models/bot-command.interface.ts +0 -8
  310. package/src/_modules/bot/_models/bot-global-settings.interface.ts +0 -96
  311. package/src/_modules/bot/_models/bot-last-mention-date.interface.ts +0 -6
  312. package/src/_modules/bot/_models/bot-last-message-date.interface.ts +0 -5
  313. package/src/_modules/bot/_models/bot-message-wrapper.interface.ts +0 -90
  314. package/src/_modules/bot/_models/bot-user-wrapper.interface.ts +0 -41
  315. package/src/_modules/bot/_modules/discord-bot/_models/dib-platform.types.ts +0 -10
  316. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +0 -431
  317. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.ts +0 -641
  318. package/src/_modules/bot/_modules/discord-bot/index.ts +0 -12
  319. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +0 -160
  320. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.ts +0 -55
  321. package/src/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.ts +0 -15
  322. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +0 -374
  323. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.ts +0 -447
  324. package/src/_modules/bot/_modules/dynamo-bot/index.ts +0 -15
  325. package/src/_modules/bot/_modules/slack-bot/_models/slb-platform.types.ts +0 -9
  326. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +0 -344
  327. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.ts +0 -197
  328. package/src/_modules/bot/_modules/slack-bot/index.ts +0 -12
  329. package/src/_modules/bot/_modules/teams-bot/_models/teb-platform.types.ts +0 -9
  330. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +0 -345
  331. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.ts +0 -197
  332. package/src/_modules/bot/_modules/teams-bot/index.ts +0 -11
  333. package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +0 -116
  334. package/src/_modules/bot/_services/bot-commands.control-service.ts +0 -158
  335. package/src/_modules/bot/_services/bot-io.control-service.spec.ts +0 -285
  336. package/src/_modules/bot/_services/bot-io.control-service.ts +0 -329
  337. package/src/_modules/bot/_services/bot-main.control-service.spec.ts +0 -208
  338. package/src/_modules/bot/_services/bot-main.control-service.ts +0 -489
  339. package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +0 -349
  340. package/src/_modules/bot/_services/bot-messaging-provider.service-base.ts +0 -158
  341. package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +0 -111
  342. package/src/_modules/bot/_services/bot-routines.control-service.ts +0 -78
  343. package/src/_modules/bot/index.ts +0 -37
  344. package/src/_modules/custom-data/custom-data.controller.spec.ts +0 -49
  345. package/src/_modules/custom-data/custom-data.controller.ts +0 -67
  346. package/src/_modules/custom-data/custom-data.data-service.spec.ts +0 -54
  347. package/src/_modules/custom-data/custom-data.data-service.ts +0 -22
  348. package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +0 -28
  349. package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +0 -24
  350. package/src/_modules/custom-data/index.ts +0 -9
  351. package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.spec.ts +0 -176
  352. package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.ts +0 -203
  353. package/src/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.ts +0 -33
  354. package/src/_modules/data-readers/index.ts +0 -11
  355. package/src/_modules/defaults/_collections/default-endpoints.util.ts +0 -487
  356. package/src/_modules/defaults/_models/default-user.data-model.ts +0 -72
  357. package/src/_modules/defaults/_services/default-auth.service.spec.ts +0 -269
  358. package/src/_modules/defaults/_services/default-auth.service.ts +0 -177
  359. package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +0 -42
  360. package/src/_modules/defaults/_services/default-socket-events.service.ts +0 -61
  361. package/src/_modules/defaults/_services/default-user.data-service.spec.ts +0 -187
  362. package/src/_modules/defaults/_services/default-user.data-service.ts +0 -98
  363. package/src/_modules/defaults/index.ts +0 -17
  364. package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +0 -19
  365. package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +0 -366
  366. package/src/_modules/discord-assistant/_collections/dias.util.ts +0 -133
  367. package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +0 -20
  368. package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +0 -53
  369. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +0 -177
  370. package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +0 -108
  371. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +0 -69
  372. package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +0 -22
  373. package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +0 -27
  374. package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +0 -195
  375. package/src/_modules/discord-assistant/_services/dias.service-base.ts +0 -77
  376. package/src/_modules/discord-assistant/index.ts +0 -38
  377. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +0 -34
  378. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +0 -11
  379. package/src/_modules/discord-assistant-voiced/index.ts +0 -36
  380. package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +0 -17
  381. package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +0 -56
  382. package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +0 -214
  383. package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +0 -387
  384. package/src/_modules/discord-bot/_models/dibo-command.interface.ts +0 -12
  385. package/src/_modules/discord-bot/_models/dibo-global-settings.interface.ts +0 -98
  386. package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +0 -8
  387. package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +0 -6
  388. package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +0 -154
  389. package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +0 -153
  390. package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +0 -264
  391. package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +0 -306
  392. package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +0 -408
  393. package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +0 -488
  394. package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +0 -105
  395. package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +0 -97
  396. package/src/_modules/discord-bot/index.ts +0 -36
  397. package/src/_modules/local-vector-search/_enums/lvs-search-mode.enum.ts +0 -35
  398. package/src/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.ts +0 -60
  399. package/src/_modules/local-vector-search/_models/lvs-search-result.interface.ts +0 -17
  400. package/src/_modules/local-vector-search/_services/lvs-bm25.util.spec.ts +0 -159
  401. package/src/_modules/local-vector-search/_services/lvs-bm25.util.ts +0 -206
  402. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +0 -418
  403. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.ts +0 -276
  404. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +0 -480
  405. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.ts +0 -416
  406. package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.spec.ts +0 -214
  407. package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.ts +0 -186
  408. package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.spec.ts +0 -167
  409. package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.ts +0 -130
  410. package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.ts +0 -509
  411. package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.ts +0 -323
  412. package/src/_modules/local-vector-search/index.ts +0 -17
  413. package/src/_modules/logs/_models/file-log-entry.interface.ts +0 -13
  414. package/src/_modules/logs/_models/file-log-read-result.interface.ts +0 -37
  415. package/src/_modules/logs/file-log.service.spec.ts +0 -341
  416. package/src/_modules/logs/file-log.service.ts +0 -466
  417. package/src/_modules/logs/file-logs.controller.spec.ts +0 -245
  418. package/src/_modules/logs/file-logs.controller.ts +0 -165
  419. package/src/_modules/logs/get-file-logs-routing-module.util.ts +0 -51
  420. package/src/_modules/logs/get-logs-routing-module.util.ts +0 -36
  421. package/src/_modules/logs/index.ts +0 -11
  422. package/src/_modules/logs/log-buffer.service.ts +0 -101
  423. package/src/_modules/logs/logs.controller.ts +0 -109
  424. package/src/_modules/logs/logs.service.ts +0 -100
  425. package/src/_modules/mcp/_models/interfaces/dynts-mcp.interface.ts +0 -111
  426. package/src/_modules/mcp/_services/dynts-mcp-server.service-base.spec.ts +0 -151
  427. package/src/_modules/mcp/_services/dynts-mcp-server.service-base.ts +0 -125
  428. package/src/_modules/mcp/_services/dynts-mcp.adapter.ts +0 -168
  429. package/src/_modules/mcp/index.ts +0 -13
  430. package/src/_modules/messaging/README.md +0 -354
  431. package/src/_modules/messaging/_collections/get-messaging-routing-module.util.ts +0 -26
  432. package/src/_modules/messaging/_collections/msg-global-settings.const.ts +0 -22
  433. package/src/_modules/messaging/_collections/msg.util.spec.ts +0 -226
  434. package/src/_modules/messaging/_collections/msg.util.ts +0 -83
  435. package/src/_modules/messaging/_models/msg-global-settings.interface.ts +0 -37
  436. package/src/_modules/messaging/_services/msg-conversation.data-service.ts +0 -146
  437. package/src/_modules/messaging/_services/msg-events.service.spec.ts +0 -219
  438. package/src/_modules/messaging/_services/msg-events.service.ts +0 -267
  439. package/src/_modules/messaging/_services/msg-integration.control-service.ts +0 -180
  440. package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +0 -147
  441. package/src/_modules/messaging/_services/msg-main.control-service.ts +0 -572
  442. package/src/_modules/messaging/_services/msg-message.data-service.ts +0 -129
  443. package/src/_modules/messaging/_services/msg.controller.spec.ts +0 -201
  444. package/src/_modules/messaging/_services/msg.controller.ts +0 -370
  445. package/src/_modules/messaging/index.ts +0 -30
  446. package/src/_modules/mock/app-extended-server.mock.ts +0 -201
  447. package/src/_modules/mock/app-integration-test.mock.ts +0 -51
  448. package/src/_modules/mock/app-params.mock.spec.ts +0 -21
  449. package/src/_modules/mock/app-params.mock.ts +0 -9
  450. package/src/_modules/mock/app-server.mock.ts +0 -188
  451. package/src/_modules/mock/auth-service.mock.spec.ts +0 -47
  452. package/src/_modules/mock/auth-service.mock.ts +0 -28
  453. package/src/_modules/mock/controller.mock.spec.ts +0 -26
  454. package/src/_modules/mock/controller.mock.ts +0 -16
  455. package/src/_modules/mock/data-model.mock.spec.ts +0 -111
  456. package/src/_modules/mock/data-model.mock.ts +0 -82
  457. package/src/_modules/mock/email-service-collection.mock.spec.ts +0 -24
  458. package/src/_modules/mock/email-service-collection.mock.ts +0 -15
  459. package/src/_modules/mock/email-service.mock.spec.ts +0 -17
  460. package/src/_modules/mock/email-service.mock.ts +0 -20
  461. package/src/_modules/mock/email-template.mock.html +0 -15
  462. package/src/_modules/mock/endpoint.mock.ts +0 -91
  463. package/src/_modules/mock/socket-client.mock.spec.ts +0 -40
  464. package/src/_modules/mock/socket-client.mock.ts +0 -45
  465. package/src/_modules/mock/socket-server.mock.spec.ts +0 -44
  466. package/src/_modules/mock/socket-server.mock.ts +0 -46
  467. package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +0 -107
  468. package/src/_modules/oauth2/_routes/oauth2.controller.ts +0 -99
  469. package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +0 -254
  470. package/src/_modules/oauth2/_services/oauth2.auth-service.ts +0 -232
  471. package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +0 -585
  472. package/src/_modules/oauth2/_services/oauth2.control-service.ts +0 -654
  473. package/src/_modules/oauth2/index.ts +0 -17
  474. package/src/_modules/privacy-lifecycle/_enums/privacy-consent-decision.type-enum.ts +0 -5
  475. package/src/_modules/privacy-lifecycle/_enums/privacy-contributor-action.type-enum.ts +0 -10
  476. package/src/_modules/privacy-lifecycle/_enums/privacy-contributor-outcome.type-enum.ts +0 -7
  477. package/src/_modules/privacy-lifecycle/_enums/privacy-request-state.type-enum.ts +0 -15
  478. package/src/_modules/privacy-lifecycle/_enums/privacy-request.type-enum.ts +0 -9
  479. package/src/_modules/privacy-lifecycle/_models/privacy-consent-input.interface.ts +0 -12
  480. package/src/_modules/privacy-lifecycle/_models/privacy-consent-persistence-result.interface.ts +0 -7
  481. package/src/_modules/privacy-lifecycle/_models/privacy-consent-record.interface.ts +0 -15
  482. package/src/_modules/privacy-lifecycle/_models/privacy-consent-result.interface.ts +0 -7
  483. package/src/_modules/privacy-lifecycle/_models/privacy-consent-view.interface.ts +0 -13
  484. package/src/_modules/privacy-lifecycle/_models/privacy-contributor-context.interface.ts +0 -9
  485. package/src/_modules/privacy-lifecycle/_models/privacy-contributor-outcome.interface.ts +0 -14
  486. package/src/_modules/privacy-lifecycle/_models/privacy-contributor-plan.interface.ts +0 -8
  487. package/src/_modules/privacy-lifecycle/_models/privacy-contributor.interface.ts +0 -17
  488. package/src/_modules/privacy-lifecycle/_models/privacy-ledger-adapter.interface.ts +0 -21
  489. package/src/_modules/privacy-lifecycle/_models/privacy-ledger-result.interface.ts +0 -9
  490. package/src/_modules/privacy-lifecycle/_models/privacy-ledger-settings.interface.ts +0 -7
  491. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-input.interface.ts +0 -10
  492. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-persistence-result.interface.ts +0 -7
  493. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-result.interface.ts +0 -7
  494. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-view.interface.ts +0 -11
  495. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance.interface.ts +0 -13
  496. package/src/_modules/privacy-lifecycle/_models/privacy-lifecycle-adapter.interface.ts +0 -19
  497. package/src/_modules/privacy-lifecycle/_models/privacy-lifecycle-settings.interface.ts +0 -9
  498. package/src/_modules/privacy-lifecycle/_models/privacy-request-create-result.interface.ts +0 -7
  499. package/src/_modules/privacy-lifecycle/_models/privacy-request-open.interface.ts +0 -10
  500. package/src/_modules/privacy-lifecycle/_models/privacy-request-persistence-create-result.interface.ts +0 -7
  501. package/src/_modules/privacy-lifecycle/_models/privacy-request-record.interface.ts +0 -21
  502. package/src/_modules/privacy-lifecycle/_models/privacy-request-result.interface.ts +0 -8
  503. package/src/_modules/privacy-lifecycle/_models/privacy-request-view.interface.ts +0 -20
  504. package/src/_modules/privacy-lifecycle/index.ts +0 -40
  505. package/src/_modules/privacy-lifecycle/privacy-ledger.control-service.spec.ts +0 -206
  506. package/src/_modules/privacy-lifecycle/privacy-ledger.control-service.ts +0 -253
  507. package/src/_modules/privacy-lifecycle/privacy-lifecycle.control-service.spec.ts +0 -353
  508. package/src/_modules/privacy-lifecycle/privacy-lifecycle.control-service.ts +0 -586
  509. package/src/_modules/rate-limit/_enums/rate-limit-store-kind.type-enum.ts +0 -5
  510. package/src/_modules/rate-limit/_models/rate-limit-config.interface.ts +0 -82
  511. package/src/_modules/rate-limit/_models/rate-limit-consume-request.interface.ts +0 -9
  512. package/src/_modules/rate-limit/_models/rate-limit-consume-result.interface.ts +0 -6
  513. package/src/_modules/rate-limit/_models/rate-limit-policy.interface.ts +0 -16
  514. package/src/_modules/rate-limit/_models/rate-limit-store.interface.ts +0 -9
  515. package/src/_modules/rate-limit/index.ts +0 -8
  516. package/src/_modules/rate-limit/rate-limit-in-memory.store.ts +0 -91
  517. package/src/_modules/rate-limit/rate-limit.middleware.spec.ts +0 -488
  518. package/src/_modules/rate-limit/rate-limit.middleware.ts +0 -504
  519. package/src/_modules/scheduler/_models/scheduler-job.interface.ts +0 -35
  520. package/src/_modules/scheduler/get-scheduler-routing-module.util.ts +0 -33
  521. package/src/_modules/scheduler/index.ts +0 -8
  522. package/src/_modules/scheduler/scheduler.controller.spec.ts +0 -42
  523. package/src/_modules/scheduler/scheduler.controller.ts +0 -69
  524. package/src/_modules/scheduler/scheduler.service.spec.ts +0 -141
  525. package/src/_modules/scheduler/scheduler.service.ts +0 -176
  526. package/src/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.ts +0 -22
  527. package/src/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.ts +0 -82
  528. package/src/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.ts +0 -107
  529. package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.spec.ts +0 -312
  530. package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.ts +0 -311
  531. package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.spec.ts +0 -123
  532. package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.ts +0 -108
  533. package/src/_modules/scoped-config/index.ts +0 -17
  534. package/src/_modules/server/errors/errors.control-service.spec.ts +0 -246
  535. package/src/_modules/server/errors/errors.control-service.ts +0 -100
  536. package/src/_modules/server/errors/errors.controller.spec.ts +0 -340
  537. package/src/_modules/server/errors/errors.controller.ts +0 -559
  538. package/src/_modules/server/errors/errors.data-service.spec.ts +0 -480
  539. package/src/_modules/server/errors/errors.data-service.ts +0 -867
  540. package/src/_modules/server/index.ts +0 -40
  541. package/src/_modules/server/safe-diagnostic/safe-diagnostic-cause.type-enum.ts +0 -8
  542. package/src/_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum.ts +0 -20
  543. package/src/_modules/server/safe-diagnostic/safe-diagnostic.control-service.spec.ts +0 -124
  544. package/src/_modules/server/safe-diagnostic/safe-diagnostic.control-service.ts +0 -99
  545. package/src/_modules/server/safe-diagnostic/safe-diagnostic.interface.ts +0 -20
  546. package/src/_modules/server/server-status/db-readiness-probe-code.type-enum.ts +0 -13
  547. package/src/_modules/server/server-status/db-readiness-probe-stage.type-enum.ts +0 -7
  548. package/src/_modules/server/server-status/db-readiness-probe.control-service.spec.ts +0 -235
  549. package/src/_modules/server/server-status/db-readiness-probe.control-service.ts +0 -158
  550. package/src/_modules/server/server-status/db-readiness-probe.interface.ts +0 -20
  551. package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +0 -70
  552. package/src/_modules/server/server-status/server-status-snapshot.control-service.ts +0 -17
  553. package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +0 -77
  554. package/src/_modules/server/server-status/server-status-snapshot.data-service.ts +0 -37
  555. package/src/_modules/server/server-status/server-status.control-service.spec.ts +0 -672
  556. package/src/_modules/server/server-status/server-status.control-service.ts +0 -491
  557. package/src/_modules/server/server-status/server-status.controller.spec.ts +0 -276
  558. package/src/_modules/server/server-status/server-status.controller.ts +0 -336
  559. package/src/_modules/socket/_enums/socket-security.enum.ts +0 -11
  560. package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +0 -32
  561. package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +0 -22
  562. package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +0 -165
  563. package/src/_modules/socket/_models/socket-presence.control-model.ts +0 -211
  564. package/src/_modules/socket/_models/socket-server-service-params.control-model.spec.ts +0 -69
  565. package/src/_modules/socket/_models/socket-server-service-params.control-model.ts +0 -33
  566. package/src/_modules/socket/_services/socket-client.service.spec.ts +0 -15
  567. package/src/_modules/socket/_services/socket-client.service.ts +0 -260
  568. package/src/_modules/socket/_services/socket-server.service.spec.ts +0 -272
  569. package/src/_modules/socket/_services/socket-server.service.ts +0 -1037
  570. package/src/_modules/socket/app-extended.integration.spec.ts +0 -85
  571. package/src/_modules/socket/app-extended.server.ts +0 -648
  572. package/src/_modules/socket/index.ts +0 -42
  573. package/src/_modules/test/get-test-routing-module.util.spec.ts +0 -28
  574. package/src/_modules/test/get-test-routing-module.util.ts +0 -23
  575. package/src/_modules/test/index.ts +0 -12
  576. package/src/_modules/test/test.controller.spec.ts +0 -72
  577. package/src/_modules/test/test.controller.ts +0 -115
  578. package/src/_modules/test-email-sink/_collections/test-email-pattern.const.ts +0 -10
  579. package/src/_modules/test-email-sink/_models/data-models/dynts-sent-test-mail.data-model.ts +0 -41
  580. package/src/_modules/test-email-sink/_services/dynts-test-email-sink.service.spec.ts +0 -112
  581. package/src/_modules/test-email-sink/_services/dynts-test-email-sink.service.ts +0 -141
  582. package/src/_modules/test-email-sink/get-sent-mail-routing-module.util.ts +0 -29
  583. package/src/_modules/test-email-sink/index.ts +0 -11
  584. package/src/_modules/test-email-sink/test-email-sink.controller.ts +0 -83
  585. package/src/_modules/usage/get-usage-routing-module.util.ts +0 -23
  586. package/src/_modules/usage/index.ts +0 -15
  587. package/src/_modules/usage/usage.controller.spec.ts +0 -106
  588. package/src/_modules/usage/usage.controller.ts +0 -140
  589. package/src/_modules/usage/usage.data-service.spec.ts +0 -332
  590. package/src/_modules/usage/usage.data-service.ts +0 -185
  591. package/src/_services/base/api.service-base.spec.ts +0 -125
  592. package/src/_services/base/api.service-base.ts +0 -75
  593. package/src/_services/base/archive-data.service.spec.ts +0 -209
  594. package/src/_services/base/archive-data.service.ts +0 -228
  595. package/src/_services/base/data.service.spec.ts +0 -784
  596. package/src/_services/base/data.service.ts +0 -2792
  597. package/src/_services/base/db.service.encryption.spec.ts +0 -76
  598. package/src/_services/base/db.service.spec.ts +0 -160
  599. package/src/_services/base/db.service.ts +0 -1698
  600. package/src/_services/base/singleton.service-base.spec.ts +0 -28
  601. package/src/_services/base/singleton.service-base.ts +0 -24
  602. package/src/_services/base/singleton.service.spec.ts +0 -114
  603. package/src/_services/base/singleton.service.ts +0 -38
  604. package/src/_services/core/api.service.spec.ts +0 -187
  605. package/src/_services/core/api.service.ts +0 -627
  606. package/src/_services/core/auth.service.spec.ts +0 -159
  607. package/src/_services/core/auth.service.ts +0 -174
  608. package/src/_services/core/collection-growth-monitor.service.spec.ts +0 -119
  609. package/src/_services/core/collection-growth-monitor.service.ts +0 -234
  610. package/src/_services/core/db-stats.service.ts +0 -104
  611. package/src/_services/core/diagnostics.service.spec.ts +0 -44
  612. package/src/_services/core/diagnostics.service.ts +0 -158
  613. package/src/_services/core/email.service.spec.ts +0 -85
  614. package/src/_services/core/email.service.ts +0 -757
  615. package/src/_services/core/event-loop-diag.service.spec.ts +0 -22
  616. package/src/_services/core/event-loop-diag.service.ts +0 -144
  617. package/src/_services/core/global.service.spec.ts +0 -292
  618. package/src/_services/core/global.service.ts +0 -488
  619. package/src/_services/core/memory-guard.service.spec.ts +0 -245
  620. package/src/_services/core/memory-guard.service.ts +0 -481
  621. package/src/_services/core/migration-runner.service.spec.ts +0 -91
  622. package/src/_services/core/migration-runner.service.ts +0 -106
  623. package/src/_services/core/mongo-transaction.control-service.spec.ts +0 -165
  624. package/src/_services/core/mongo-transaction.control-service.ts +0 -148
  625. package/src/_services/core/request-hunter.service.spec.ts +0 -124
  626. package/src/_services/core/request-hunter.service.ts +0 -157
  627. package/src/_services/core/request-telemetry.control-service.spec.ts +0 -217
  628. package/src/_services/core/request-telemetry.control-service.ts +0 -381
  629. package/src/_services/core/service-collection.service.spec.ts +0 -46
  630. package/src/_services/core/service-collection.service.ts +0 -6
  631. package/src/_services/route/controller.service.spec.ts +0 -53
  632. package/src/_services/route/controller.service.ts +0 -148
  633. package/src/_services/route/routing-module.service.spec.ts +0 -98
  634. package/src/_services/route/routing-module.service.ts +0 -339
  635. package/src/_services/server/app-safe-diagnostic.spec.ts +0 -124
  636. package/src/_services/server/app.server-retention.spec.ts +0 -106
  637. package/src/_services/server/app.server.ts +0 -1979
  638. package/src/_services/shared.static-service.spec.ts +0 -133
  639. package/src/_services/shared.static-service.ts +0 -107
  640. package/src/index.ts +0 -120
  641. package/tsconfig.app.json +0 -12
  642. package/tsconfig.json +0 -42
@@ -1,1979 +0,0 @@
1
-
2
- import Mongoose = require('mongoose');
3
- import Express = require('express');
4
- /* import Mongoose from 'mongoose';
5
- import Express from 'express'; */
6
-
7
- import * as BodyParser from 'body-parser';
8
- import * as FileSystem from 'fs';
9
- import * as Http from 'http';
10
- import * as Https from 'https';
11
- import * as Path from 'path';
12
- import * as dotenv from 'dotenv'
13
-
14
- /* import { version } from '../../../package.json'; */
15
-
16
- import {
17
- DyFM_AnyError,
18
- DyFM_Array,
19
- DyFM_Async,
20
- DyFM_Error,
21
- DyFM_error_defaults,
22
- DyFM_Error_Settings,
23
- DyFM_ErrorLevel,
24
- DyFM_Log,
25
- DyFM_resolveRetentionTtlSeconds,
26
- megabyte,
27
- second
28
- } from '@futdevpro/fsm-dynamo';
29
-
30
- import { DyNTS_defaultFallbackCacheMaxAge } from '../../_collections/default-fallback-cache-max-age.const';
31
- import { DyNTS_defaultNotFoundPageHtml } from '../../_collections/default-not-found-page.const';
32
- import { DyNTS_global_settings } from '../../_collections/global-settings.const';
33
- import { DyNTS_ClientSafeError_Util } from '../../_collections/client-safe-error.util';
34
- import { DyNTS_getEnvironment_settings } from '../../_collections/get-environment-settings.util';
35
- import { DyNTS_createSecurityHeadersMiddleware } from '../../_collections/security-headers.util';
36
- import { DyNTS_createLoadShedMiddleware } from '../../_collections/load-shed.util';
37
- import { DyNTS_createAppVersionHeaderMiddleware } from '../../_collections/app-version-header.util';
38
- import { DyNTS_AppVersionHeader_Settings } from '../../_models/interfaces/app-version-header-settings.interface';
39
- import { DyNTS_RequestTelemetry_Settings } from '../../_models/interfaces/request-telemetry-settings.interface';
40
- import { DyNTS_SecurityHeaders_Settings } from '../../_models/interfaces/security-headers-settings.interface';
41
- import { startMongoReconnectGuard } from '../../_collections/mongo-reconnect-guard.util';
42
- import { DyNTS_resolveStaticCacheControlHeader } from '../../_collections/static-cache-control.util';
43
- import { DyNTS_RouteSecurity } from '../../_enums/route-security.enum';
44
- import { DyNTS_App_Params } from '../../_models/control-models/app-params.control-model';
45
- import {
46
- DyNTS_AppSystemControls
47
- } from '../../_models/control-models/app-system-controls.control-model';
48
- import {
49
- DyNTS_Endpoint_Params
50
- } from '../../_models/control-models/endpoint-params.control-model';
51
- import { DyNTS_Http_Settings } from '../../_models/control-models/http-settings.control-model';
52
- import {
53
- DyNTS_Certification_Settings
54
- } from '../../_models/interfaces/certification-settings.interface';
55
- import {
56
- DyNTS_GlobalService_Settings
57
- } from '../../_models/interfaces/global-service-settings.interface';
58
- import {
59
- DyNTS_StaticClient_Settings
60
- } from '../../_models/interfaces/static-client-settings.interface';
61
- import {
62
- DyNTS_Cors_Settings
63
- } from '../../_models/interfaces/cors-settings.interface';
64
- import { DyNTS_DBService } from '../base/db.service';
65
- import { DyNTS_SingletonService } from '../base/singleton.service';
66
- import { DyNTS_GlobalService } from '../core/global.service';
67
- import { DyNTS_CollectionGrowthMonitor } from '../core/collection-growth-monitor.service';
68
- import { DyNTS_MemoryGuard } from '../core/memory-guard.service';
69
- import { DyNTS_EventLoopDiag } from '../core/event-loop-diag.service';
70
- import { DyNTS_RequestTelemetry_ControlService } from '../core/request-telemetry.control-service';
71
- import { DyNTS_RoutingModule } from '../route/routing-module.service';
72
- import { DyNTS_getStarRoute } from '../../_collections/star.controller';
73
- import { DyNTS_SafeDiagnosticStage_Type } from '../../_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum';
74
- import { DyNTS_SafeDiagnostic_Interface } from '../../_modules/server/safe-diagnostic/safe-diagnostic.interface';
75
- import {
76
- DyNTS_SafeDiagnostic_ControlService
77
- } from '../../_modules/server/safe-diagnostic/safe-diagnostic.control-service';
78
-
79
- /**
80
- *
81
- * function MyDecorator(config: any) {
82
- return function (target: Function) {
83
- // attach metadata or modify target
84
- target.prototype.myMeta = config;
85
- };
86
- }
87
-
88
- @MyDecorator({ role: 'admin' })
89
- class User {
90
- printRole() {
91
- console.log((this as any).myMeta.role); // → "admin"
92
- }
93
- }
94
-
95
- */
96
-
97
- /**
98
- * This will be the MAIN service of our server project,
99
- * follow the types and type instructions while setting up your project
100
- *
101
- * In this service, there are abstract functions that you will need to implement,
102
- * where you need to set up the main params for your application.
103
- *
104
- * (after the example, you can find the list of services you can/should setup)
105
- *
106
- * @example
107
- * export class App extends DyNTS_AppExtended {
108
- *
109
- * ...
110
- *
111
- * // Setting up App params, and preparing project global settings
112
- * setupAppParams(): void {
113
- * this.params = new DyNTS_AppParams({
114
- * name: 'Warbots Server',
115
- * title: warbotsTitleLog,
116
- * version: version,
117
- * dbName: 'warbots',
118
- * });
119
- *
120
- * // dynamoNTS_GlobalSettings.logRequestsContent = false;
121
- * }
122
- *
123
- * ...
124
- *
125
- * // Setting up DBServices
126
- * setGlobalServiceCollection(): void {
127
- * DyNTS_GlobalService.setServices({
128
- * authService: AuthService.getInstance(),
129
- * emailServiceCollection: EmailServiceCollectionService.getInstance(),
130
- * dbModels: [
131
- * userModelParams,
132
- * userDataModelParams,
133
- * userOptionsModelParams,
134
- * userStatisticsModelParams,
135
- * userAchievementsModelParams,
136
- * userNotificationsModelParams,
137
- *
138
- * matchStatisticsModelParams,
139
- * matchDataModelParams,
140
-
141
- * DyFM_usageSession_dataParams,
142
- * DyFM_customData_dataParams,
143
- * ]
144
- * });
145
- * }
146
- *
147
- * ...
148
- *
149
- * // Setting up Routes
150
- * setupRoutingModules(): void {
151
- * this.httpPort = env.port;
152
-
153
- * this.routingModules = [
154
- * new DyNTS_RoutingModule({
155
- * route: '/user',
156
- * controllers: [
157
- * UserController.getInstance(),
158
- * UserDataController.getInstance(),
159
- * UserOptionsController.getInstance(),
160
- * UserStatisticsController.getInstance(),
161
- * UserAchievementsController.getInstance(),
162
- * UserNotificationsController.getInstance()
163
- * ]
164
- * }),
165
- * new DyNTS_RoutingModule({
166
- * route: '/match',
167
- * controllers: [
168
- * MatchController.getInstance(),
169
- * MatchDistributionController.getInstance(),
170
- * MatchStatisticsController.getInstance(),
171
- * ]
172
- * }),
173
- * new DyNTS_RoutingModule({
174
- * route: '/server',
175
- * controllers: [
176
- * ServerController.getInstance(),
177
- * ]
178
- * }),
179
-
180
- * getTestRoutingModule(),
181
- * getUsageRoutingModule()
182
- * ];
183
- * }
184
- * }
185
- *
186
- * //
187
- * // The Services available
188
- * //
189
- * // Authentication Service
190
- * // A commonly used basic service,
191
- * // which is necessary fur certain functions (such as registering call issuers)
192
- * //
193
- * // This will handle Authentication Token checking/refreshing,
194
- * // checking issuer's identifier and routeParams,
195
- * // handling JWT Token, or maybe with OAuth2 or other commonly used security procedures
196
- * //
197
- * // You can create one with this Dynamo Object:
198
- * //
199
- *
200
- * @example
201
- * // follow the instructions on the abstract class (DyNTS_AuthService)
202
- * export class AuthService extends DyNTS_AuthService {}
203
- *
204
- *
205
- *
206
- * //
207
- */
208
-
209
- /**
210
- * This will be the MAIN service of our server project,
211
- * follow the types and type instructions while setting up your project
212
- *
213
- * In this service, there are abstract functions that you will need to implement,
214
- * where you need to set up the main params for your application.
215
- *
216
- * (after the example, you can find the list of services you can/should setup)
217
- *
218
- * You need to setup the following functions:
219
- * ```ts
220
- * // this is where you set up the main params for your application
221
- * getAppParams(): DyNTS_AppParams
222
- *
223
- * // this is where you connect your main services
224
- * getGlobalServiceSettings(): DyNTS_GlobalService_Settings
225
- *
226
- * // this is where you set up your ports
227
- * getPorts(): DyNTS_PortSettings
228
- *
229
- * // this is where you set up your routes
230
- * getRoutingModules(): DyNTS_RoutingModule[]
231
- *
232
- *
233
- *
234
- * ```
235
- * optionally you can setup the following functions:
236
- * ```ts
237
- * // this is where you set up your certifications
238
- * getCertificationSettings(): DyNTS_CertificationSettings
239
- *
240
- * // this is where you set up additional root services
241
- * getRootServices(): DyNTS_SingletonService[]
242
- *
243
- * // this is where you set up your initial db entries
244
- * createEntries(): void
245
- *
246
- * // this is where you can define post setup processes
247
- * postProcess(): void
248
- *
249
- *
250
- *
251
- * ```
252
- *
253
- */
254
-
255
- /** FR-258 / SR-2 — one entry from `collection.indexes()` (only the fields the TTL-installer reads). */
256
- export interface DyNTS_TtlIndexInfo {
257
- name?: string;
258
- key?: Record<string, number>;
259
- expireAfterSeconds?: number;
260
- }
261
-
262
- /**
263
- * FR-258 / SR-2 — the minimal native-driver collection surface the TTL-installer needs. Declared
264
- * structurally (not importing mongodb types) so it stays dependency-light and is trivially mockable
265
- * in unit tests.
266
- */
267
- export interface DyNTS_TtlIndexCollection {
268
- indexes?: () => Promise<DyNTS_TtlIndexInfo[]>;
269
- createIndex: (keys: Record<string, number>, options: { expireAfterSeconds: number }) => Promise<unknown>;
270
- dropIndex?: (name: string) => Promise<unknown>;
271
- }
272
-
273
- /**
274
- * FR-258 / SR-2 — outcome of {@link DyNTS_App.ensureRetentionTtlIndex}.
275
- * - `created`: no `__created` TTL index existed → one was created.
276
- * - `noop`: an index with the SAME TTL already existed → nothing done.
277
- * - `differs`: an index exists with a DIFFERENT TTL (or a non-TTL `__created` index) → left UNTOUCHED,
278
- * only a warning is emitted. We deliberately DO NOT drop+recreate at boot: rebuilding a TTL index on a
279
- * multi-GB production collection is a heavy server-side op that can starve concurrent boot queries (e.g.
280
- * the health-probe) and trip a fail-safe deploy revert. A deliberate retention CHANGE must be applied via
281
- * maintenance, not silently at every startup.
282
- */
283
- export type DyNTS_TtlIndexAction = 'created' | 'differs' | 'noop';
284
-
285
- export abstract class DyNTS_App extends DyNTS_SingletonService {
286
-
287
- protected systemControls: DyNTS_AppSystemControls = new DyNTS_AppSystemControls();
288
- get started(): boolean {
289
- return this.systemControls.app.started;
290
- }
291
- protected get superStarted(): boolean {
292
- return this.systemControls.app.started;
293
- }
294
- protected constructErrors: (Error | DyFM_Error)[] = [];
295
-
296
- /* removed since cant use version from package.json
297
- private readonly _ntsVersion: string = 'v01.07.18';
298
- protected get ntsVersion(): string {
299
- return this._ntsVersion;
300
- } */
301
-
302
- get serverName(): string {
303
- return this.params.name;
304
- }
305
-
306
- private _params: DyNTS_App_Params;
307
- protected get params(): DyNTS_App_Params {
308
- return this._params;
309
- }
310
-
311
- protected mongoose = Mongoose;
312
-
313
- private _security: DyNTS_RouteSecurity;
314
- protected get security(): DyNTS_RouteSecurity {
315
- return this._security;
316
- }
317
-
318
- protected _portSettings: DyNTS_Http_Settings = new DyNTS_Http_Settings();
319
- protected get portSettings(): DyNTS_Http_Settings {
320
- return this._portSettings;
321
- }
322
-
323
- private _cert?: DyNTS_Certification_Settings;
324
- protected get cert(): DyNTS_Certification_Settings {
325
- return this._cert;
326
- }
327
-
328
- protected openExpress: Express.Application;
329
- protected secureExpress: Express.Application;
330
- protected httpsServer: Https.Server;
331
- protected httpServer: Http.Server;
332
-
333
- private globalService: DyNTS_GlobalService;
334
- private _rootServices: DyNTS_SingletonService[] = [];
335
-
336
- private _routingModules: DyNTS_RoutingModule[] = [];
337
-
338
- protected readonly defaultReadyTimeout: number = 30 * second;
339
-
340
- override readonly defaultErrorUserMsg =
341
- `We encountered an unhandled Server Error, ` +
342
- `\nplease contact the responsible development team.` +
343
- `\n(Internal Server error)`;
344
-
345
- get logSetup(): boolean {
346
- return DyNTS_global_settings.log_settings.setup;
347
- }
348
- get deepLog(): boolean {
349
- return DyNTS_global_settings.log_settings.deep;
350
- }
351
- get fnLogs(): boolean {
352
- return DyNTS_global_settings.log_settings.functions;
353
- }
354
- debugLog: boolean = DyNTS_global_settings.log_settings.server_debug;
355
-
356
- private reportSafeDiagnostic(
357
- code: string,
358
- stage: DyNTS_SafeDiagnosticStage_Type,
359
- error?: unknown,
360
- status: number = 500
361
- ): DyNTS_SafeDiagnostic_Interface {
362
- const configuredPrefix: string | undefined = DyNTS_global_settings.systemShortCodeName;
363
- const prefix: string = configuredPrefix && /^[A-Z][A-Z0-9_-]{1,31}$/.test(configuredPrefix)
364
- ? configuredPrefix
365
- : 'DYNTS';
366
-
367
- return DyNTS_SafeDiagnostic_ControlService.report({
368
- code: `${prefix}|${code}`,
369
- stage: stage,
370
- error: error,
371
- status: status,
372
- });
373
- }
374
-
375
- private forwardSafeDiagnostic(diagnostic: DyNTS_SafeDiagnostic_Interface): void {
376
- try {
377
- const pending: Promise<void> | undefined = DyNTS_GlobalService.globalErrorHandler?.(
378
- DyNTS_SafeDiagnostic_ControlService.toError(diagnostic)
379
- );
380
-
381
- void pending?.catch((error: unknown): void => {
382
- this.reportSafeDiagnostic(
383
- 'DYNTS-AS0-GLOBAL-HANDLER-REJECTED',
384
- DyNTS_SafeDiagnosticStage_Type.globalErrorHandler,
385
- error
386
- );
387
- });
388
- } catch (error) {
389
- this.reportSafeDiagnostic(
390
- 'DYNTS-AS0-GLOBAL-HANDLER-THREW',
391
- DyNTS_SafeDiagnosticStage_Type.globalErrorHandler,
392
- error
393
- );
394
- }
395
- }
396
-
397
- constructor(/* extended?: boolean */){
398
- super();
399
-
400
- /* dotenv.config() */
401
-
402
- process.on(
403
- 'unhandledRejection',
404
- (reason: unknown): void => {
405
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
406
- 'DYNTS-AS0-BASE-UR',
407
- DyNTS_SafeDiagnosticStage_Type.unhandledRejection,
408
- reason
409
- );
410
-
411
- this.forwardSafeDiagnostic(diagnostic);
412
- }
413
- );
414
-
415
- this.asyncConstruct(/* extended */).catch((error: unknown): void => {
416
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
417
- 'DYNTS-AS0-BOOTSTRAP-FAILED',
418
- DyNTS_SafeDiagnosticStage_Type.bootstrap,
419
- error
420
- );
421
-
422
- this.forwardSafeDiagnostic(diagnostic);
423
-
424
- process.exit(1);
425
- });
426
- }
427
-
428
- protected async asyncConstruct(extended?: boolean): Promise<void> {
429
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. asyncConstruct');
430
-
431
- try {
432
- this.systemControls.app.init = true;
433
- this._params = this.getAppParams();
434
- DyFM_Log.log(
435
- `\n\n\n\n\n\n\n\n\n\n` +
436
- `Starting ${this._params?.name}... ` +
437
- /* `v${version}` + */
438
- `\n\n\n\n\n\n\n\n\n\n`
439
- );
440
-
441
- if (!this._params) {
442
- throw new Error('getAppParams() must return a DyNTS_AppParams object!');
443
- }
444
-
445
- if (this.params.systemShortCodeName) {
446
- DyNTS_global_settings.systemShortCodeName = this.params.systemShortCodeName;
447
- }
448
-
449
- if (this.params.systemName) {
450
- DyNTS_global_settings.systemName = this.params.systemName;
451
- DyFM_error_defaults.issuerSystem = this.params.systemName;
452
- }
453
-
454
- if (this.params.version) {
455
- DyNTS_global_settings.systemVersion = this.params.version;
456
- DyFM_error_defaults.systemVersion = this.params.version;
457
- }
458
-
459
- process.stdout.write(
460
- String.fromCharCode(27) + ']0;' +
461
- this._params?.name +
462
- String.fromCharCode(7)
463
- );
464
-
465
- DyFM_error_defaults.issuerSystem = this._params.systemName;
466
-
467
- this.overrideDynamoNTSGlobalSettings?.();
468
-
469
- if (DyNTS_global_settings.log_settings.setup) {
470
- DyFM_Log.S_info(`env settings;\n`, {
471
- systemName: DyNTS_global_settings.systemName,
472
- systemShortCodeName: DyNTS_global_settings.systemShortCodeName,
473
- systemVersion: DyNTS_global_settings.systemVersion,
474
- environment: DyNTS_global_settings.env_settings.environment,
475
- /* log_settings: DyNTS_global_settings.log_settings,
476
- env_settings: DyNTS_global_settings.env_settings, */
477
- });
478
- }
479
-
480
- this.globalService = DyNTS_GlobalService.getInstance();
481
- await DyNTS_GlobalService.setServices(this.getGlobalServiceCollection());
482
- DyNTS_GlobalService.setParams(this.params);
483
-
484
- if (this.getPortSettings) {
485
- this._portSettings = this.getPortSettings();
486
- }
487
-
488
- if (this.getCertificationSettings) {
489
- this._cert = this.getCertificationSettings();
490
- }
491
-
492
- if (this.getApiBasePath) {
493
- DyNTS_global_settings.baseUrl = this.getApiBasePath();
494
- }
495
-
496
- if (this.getRoutingModules) {
497
- this._routingModules = this.getRoutingModules();
498
-
499
- // ezt egyelőre csak tesztelem, nem kerül be
500
- /* if (
501
- !DyNTS_global_settings.dontCreateDefaultRoute &&
502
- !this._routingModules.some((routingModule: DyNTS_RoutingModule): boolean => routingModule.route === '/*')
503
- ) {
504
- this._routingModules.push(
505
- DyNTS_getStarRoute()
506
- );
507
- } */
508
- }
509
-
510
- if (this._params.dbUri) {
511
- await this.startDB();
512
-
513
- // createEntries csak akkor fut, ha a DB tényleg fel-jött.
514
- // Ha a startDB jelezte a hibát, de továbbment, akkor a started flag false marad,
515
- // és nem próbálunk meg írni egy nem létező kapcsolatra.
516
- if (this.createEntries && this.systemControls.mongoose.started) {
517
- await this.createEntries();
518
- }
519
- } else {
520
- DyFM_Log.log(
521
- `\nNo database connection created.`,
522
- );
523
- }
524
-
525
- if (this._routingModules?.length) {
526
- if (this.logSetup) DyFM_Log.log('\nsetting up express routes...');
527
-
528
- this.setSecurity();
529
-
530
- await this.initExpresses();
531
- await this.startExpresses();
532
-
533
- if (this._security !== DyNTS_RouteSecurity.secure) {
534
- await this.mountOpenRoutes();
535
- }
536
-
537
- if (this._security !== DyNTS_RouteSecurity.open && this._cert) {
538
- await this.mountSecureRoutes();
539
- }
540
-
541
- // Generikus, auth-agnosztikus extension-point: custom middleware az API
542
- // route-ok UTÁN, de a SPA static catch-all (mountStaticClient) ELŐTT.
543
- await this.mountCustomMiddleware();
544
-
545
- await this.mountStaticClient();
546
-
547
- if (this.logSetup) {
548
- DyFM_Log.log(`\nRoutes mounted.... server using security: ${this._security}`);
549
- }
550
- } else {
551
- DyFM_Log.warn(
552
- `\nNo routes mounted!`,
553
- );
554
- }
555
-
556
- if (this.getRootServices) {
557
- this._rootServices = await this.getRootServices();
558
- }
559
-
560
- if (this.postProcess) {
561
- await this.postProcess().catch((error: unknown): void => {
562
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
563
- 'DYNTS-AS0-POST-PROCESS-FAILED',
564
- DyNTS_SafeDiagnosticStage_Type.postProcess,
565
- error
566
- );
567
-
568
- this.forwardSafeDiagnostic(diagnostic);
569
- });
570
- }
571
-
572
- // FR-193 — bedrock OOM korai-figyelmeztetés: feltelepítjük a heap-watchdogot, ha
573
- // engedélyezve (DyNTS_global_settings.memoryGuard.enabled, default true). Biztonságos:
574
- // a guard egy könnyű setInterval, ami SOHA nem dob; csak near-OOM küszöböknél hagy
575
- // tartós nyomot az error-sinkbe, mielőtt a fatal heap-OOM megölné a process-t.
576
- try {
577
- if (DyNTS_global_settings.memoryGuard?.enabled) {
578
- DyNTS_MemoryGuard.getInstance().install();
579
- }
580
- } catch (memoryGuardError: unknown) {
581
- this.reportSafeDiagnostic(
582
- 'DYNTS-AS0-MEMORY-GUARD-SKIPPED',
583
- DyNTS_SafeDiagnosticStage_Type.memoryGuard,
584
- memoryGuardError
585
- );
586
- }
587
-
588
- // BFR-OVERSEER-007 — event-loop-lag diag a MemoryGuard MELLÉ: a „process él, HTTP néma" wedge
589
- // belső mérése (natív histogram, olcsó). Observation-only, sosem dob; a /server/diag olvas belőle.
590
- try {
591
- DyNTS_EventLoopDiag.getInstance().install();
592
- } catch (eventLoopDiagError: unknown) {
593
- this.reportSafeDiagnostic(
594
- 'DYNTS-AS0-EVENT-LOOP-DIAG-SKIPPED',
595
- DyNTS_SafeDiagnosticStage_Type.eventLoopDiagnostic,
596
- eventLoopDiagError
597
- );
598
- }
599
-
600
- // FR-258 / SR-4 — proactive collection-growth monitor (companion to the MemoryGuard). Warns
601
- // into the Errors-sink when a collection grows unbounded, BEFORE it can be loaded into heap and
602
- // OOM. Default-on, observation-only, never throws.
603
- try {
604
- if (DyNTS_global_settings.collectionGrowthMonitor?.enabled) {
605
- DyNTS_CollectionGrowthMonitor.getInstance().install();
606
- }
607
- } catch (cgmError: unknown) {
608
- this.reportSafeDiagnostic(
609
- 'DYNTS-AS0-COLLECTION-GROWTH-MONITOR-SKIPPED',
610
- DyNTS_SafeDiagnosticStage_Type.collectionGrowthMonitor,
611
- cgmError
612
- );
613
- }
614
-
615
- if (!extended) {
616
- await this.ready();
617
-
618
- if (this.params.title) {
619
- DyFM_Log.success(this.params.title);
620
- }
621
- DyFM_Log.info(`Version: ${this.params.version}`);
622
- /* DyFM_Log.info(`NTS Version: ${this.ntsVersion}`); */
623
- DyFM_Log.H_success(`${this.params.name} started successfully.`);
624
- }
625
- } catch (error) {
626
- this.constructErrors.push(error);
627
-
628
- throw new DyFM_Error({
629
- ...this._getDefaultErrorSettings('asyncConstruct', error),
630
-
631
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-001`,
632
- additionalContent: {
633
- constructErrors: this.constructErrors,
634
- systemControls: this.systemControls,
635
- systemReadies: {
636
- app: this.systemControls.app.getIsReady(),
637
- mongoose: this.systemControls.mongoose.getIsReady(),
638
- httpServer: this.systemControls.httpServer.getIsReady(),
639
- httpsServer: this.systemControls.httpsServer.getIsReady(),
640
- },
641
- },
642
- });
643
- }
644
- }
645
-
646
- async ready(timeout: number = this.defaultReadyTimeout): Promise<void> {
647
- try {
648
- if (this.fnLogs) DyFM_Log.log('\nfn:. ready');
649
-
650
- await DyFM_Async.delay(100);
651
-
652
- let ready: boolean = false;
653
- const start: number = +new Date();
654
-
655
- if (this.constructErrors.length) {
656
- this.reportSafeDiagnostic(
657
- 'DYNTS-AS0-READINESS-CONSTRUCT-ERROR',
658
- DyNTS_SafeDiagnosticStage_Type.readiness,
659
- this.constructErrors[0]
660
- );
661
-
662
- throw new DyFM_Error({
663
- ...this._getDefaultErrorSettings(
664
- 'ready',
665
- new Error(`"${this._params.name}" start failed.`)
666
- ),
667
-
668
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R01`,
669
- additionalContent:
670
- this.constructErrors.length === 1 ?
671
- { error: this.constructErrors[0] } :
672
- { errors: this.constructErrors },
673
- });
674
- }
675
-
676
- while (!ready && +new Date() - start < timeout) {
677
- if (this.systemControls.app.init) {
678
- ready = (
679
- this.systemControls.mongoose.getIsReady() &&
680
- this.systemControls.httpServer.getIsReady() &&
681
- this.systemControls.httpsServer.getIsReady()
682
- );
683
- }
684
-
685
- if (!ready) {
686
- await DyFM_Async.wait(100);
687
- }
688
- }
689
-
690
- if (timeout < +new Date() - start) {
691
- this.reportSafeDiagnostic(
692
- 'DYNTS-AS0-READINESS-TIMEOUT',
693
- DyNTS_SafeDiagnosticStage_Type.readiness,
694
- this.constructErrors[0] ?? new Error('readiness-timeout')
695
- );
696
-
697
- throw new DyFM_Error({
698
- ...this._getDefaultErrorSettings(
699
- 'ready',
700
- new Error(`"${this._params.name}" start failed. TIMEOUT`)
701
- ),
702
-
703
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R02`,
704
- additionalContent: {
705
- constructErrors: this.constructErrors,
706
- systemControls: this.systemControls,
707
- systemReadies: {
708
- mongoose: this.systemControls.mongoose.getIsReady(),
709
- httpServer: this.systemControls.httpServer.getIsReady(),
710
- httpsServer: this.systemControls.httpsServer.getIsReady(),
711
- },
712
- },
713
- });
714
- }
715
-
716
- if (this.constructErrors.length) {
717
- this.reportSafeDiagnostic(
718
- 'DYNTS-AS0-READINESS-LATE-CONSTRUCT-ERROR',
719
- DyNTS_SafeDiagnosticStage_Type.readiness,
720
- this.constructErrors[0]
721
- );
722
-
723
- throw new DyFM_Error({
724
- ...this._getDefaultErrorSettings(
725
- 'ready',
726
- new Error(`"${this._params.name}" start failed.`)
727
- ),
728
-
729
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R03`,
730
- additionalContent: this.constructErrors,
731
- });
732
- }
733
-
734
- if (ready) {
735
- this.systemControls.app.started = true;
736
-
737
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. ready: return');
738
-
739
- return;
740
- }
741
-
742
- this.systemControls.app.started = false;
743
-
744
- let msg: string = `"${this._params.name}" start failed. UNKNOWN`;
745
-
746
- if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
747
- msg += `\nMongoose start failed.`;
748
- }
749
-
750
- if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
751
- msg += `\nHTTP Server start failed.`;
752
- }
753
-
754
- if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
755
- msg += `\nHTTPS Server start failed.`;
756
- }
757
-
758
- this.reportSafeDiagnostic(
759
- 'DYNTS-AS0-READINESS-UNKNOWN',
760
- DyNTS_SafeDiagnosticStage_Type.readiness,
761
- this.constructErrors[0] ?? new Error('readiness-unknown')
762
- );
763
-
764
- throw new DyFM_Error({
765
- ...this._getDefaultErrorSettings('ready', new Error(msg)),
766
-
767
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R04`,
768
- additionalContent: {
769
- constructErrors: this.constructErrors,
770
- systemControls: this.systemControls,
771
- systemReadies: {
772
- app: this.systemControls.app.getIsReady(),
773
- mongoose: this.systemControls.mongoose.getIsReady(),
774
- httpServer: this.systemControls.httpServer.getIsReady(),
775
- httpsServer: this.systemControls.httpsServer.getIsReady(),
776
- },
777
- },
778
- error: this.constructErrors?.[0] ?? new Error(),
779
- });
780
- } catch (error) {
781
- throw new DyFM_Error({
782
- ...this._getDefaultErrorSettings('ready', error),
783
-
784
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-READY0`,
785
- });
786
- }
787
- }
788
-
789
- protected getSimplifiedConstructErrors(): string[] {
790
- return this.constructErrors.map((error: any): any => {
791
- if (error instanceof DyFM_Error) {
792
- return error.getErrorSimplified();
793
- } else {
794
- return error;
795
- }
796
- });
797
- }
798
-
799
- async stop(dontLog?: boolean): Promise<void> {
800
- try {
801
- DyFM_Log.info('\nstopping server...\n');
802
-
803
- await this.ready();
804
-
805
- if (this.started) {
806
-
807
- if (this.systemControls.mongoose.init) {
808
- DyFM_Log.info(`\nstopping Mongoose....`);
809
-
810
- let tryCount: number = 0;
811
-
812
- while (
813
- !this.systemControls.mongoose.started &&
814
- !this.constructErrors.length &&
815
- tryCount++ < 10
816
- ) {
817
- DyFM_Log.warn(`Mongoose not even started yet....`);
818
- await DyFM_Async.wait(second);
819
- }
820
- this.systemControls.mongoose.started = false;
821
-
822
- if (this.mongoose) {
823
- await DyFM_Array.asyncForEach(
824
- Object.keys(this.mongoose.models),
825
- async (modelName): Promise<void> => {
826
- this.mongoose.deleteModel(modelName);
827
- }
828
- );
829
-
830
- const disconnect: Promise<void> = new Promise((resolve): void => {
831
- this.mongoose.connection.on('disconnecting', (): void => {
832
- resolve();
833
- });
834
- });
835
-
836
- await this.mongoose.disconnect();
837
- await this.mongoose.connection.close();
838
- await disconnect;
839
-
840
- this.mongoose.connection.removeAllListeners();
841
-
842
- while (
843
- this.mongoose.connection.readyState !== 0 &&
844
- !this.constructErrors.length
845
- ) {
846
- DyFM_Log.warn(`\nMongoose still not disconnected....`);
847
- await DyFM_Async.wait(second);
848
- }
849
- } else {
850
- DyFM_Log.error(`\nMongoose not found.`);
851
- }
852
- this.systemControls.mongoose.init = false;
853
- }
854
-
855
- if (this.systemControls.httpServer.init) {
856
- this.systemControls.httpServer.started = false;
857
-
858
- if (this.httpServer) {
859
- await new Promise((resolve): void => {
860
- this.httpServer.close(resolve);
861
- });
862
- } else {
863
- DyFM_Log.error(`\nHTTP Server not found.`);
864
- }
865
- this.systemControls.httpServer.init = false;
866
- }
867
-
868
- if (this.systemControls.httpsServer.init) {
869
- this.systemControls.httpsServer.started = false;
870
-
871
- if (this.httpsServer) {
872
- await new Promise((resolve): void => {
873
- this.httpsServer.close(resolve);
874
- });
875
- } else {
876
- DyFM_Log.error(`\nHTTPS Server not found.`);
877
- }
878
- this.systemControls.httpsServer.init = false;
879
- }
880
-
881
- await DyFM_Async.wait(second);
882
-
883
- if (!dontLog) {
884
- DyFM_Log.H_log(`"${this._params.name}" stopped successfully.`);
885
- }
886
- }
887
- } catch (error) {
888
- throw new DyFM_Error({
889
- ...this._getDefaultErrorSettings('stop', error),
890
-
891
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-STOP0`,
892
- });
893
- }
894
- }
895
-
896
- /**
897
- *
898
- */
899
- private async startDB(): Promise<void> {
900
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. startDB');
901
- else if (this.logSetup) DyFM_Log.log('\nstarting DB connection...');
902
-
903
- if (!this._params.dbUri) {
904
- throw new DyFM_Error({
905
- ...this._getDefaultErrorSettings('startDB', new Error('DB URI is not set.')),
906
-
907
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
908
- });
909
- }
910
-
911
- if (!this._params.dbOptions) {
912
- throw new DyFM_Error({
913
- ...this._getDefaultErrorSettings('startDB', new Error('DB OPTIONS are not set.')),
914
-
915
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
916
- });
917
- }
918
-
919
- if (this.systemControls.mongoose.init || this.systemControls.mongoose.started) {
920
- throw new DyFM_Error({
921
- ...this._getDefaultErrorSettings('startDB', new Error('Mongoose is already initialized.')),
922
-
923
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
924
- });
925
- }
926
-
927
- try {
928
- await new Promise<void>(
929
- (resolve, reject): void => {
930
- this.systemControls.mongoose.init = true;
931
-
932
- this.mongoose.connection
933
- .once('open', (): void => {
934
- this.systemControls.mongoose.started = true;
935
- DyFM_Log.success('\nConnected to MongoDB.\n');
936
-
937
- resolve();
938
-
939
- // FR-258 / SR-2 — install declared-retention TTL indexes. DEFERRED + fire-and-forget +
940
- // fully non-fatal: a create-if-missing index op (and the `indexes()` probes) must NOT
941
- // compete with boot-readiness. We delay it well past the deploy health-probe window so a
942
- // cold boot is never slowed by it, then run it detached. `.unref()` keeps it from holding
943
- // the event loop open. Any failure is logged but never crashes the app. (`'differs'` never
944
- // rebuilds a live index — see ensureRetentionTtlIndex.)
945
- const ttlInstallTimer: ReturnType<typeof setTimeout> = setTimeout((): void => {
946
- void this.installRetentionTtlIndexes();
947
- }, 30000);
948
- if (typeof ttlInstallTimer.unref === 'function') { ttlInstallTimer.unref(); }
949
- })
950
- .on('error', (error): void => {
951
- if (!this.systemControls.mongoose.started) {
952
- // Initial DB-csatlakozás sikertelen:
953
- // jelezzük a hibát (log + globalErrorHandler), de NEM szakítjuk meg az
954
- // App startup-ot (nincs constructErrors push, nincs reject).
955
- // A mongoose.init-et resetteljük, hogy a ready() ne várjon a DB-re.
956
- // Ha a mongoose később mégis tudna csatlakozni, az 'open' event
957
- // beállítja a started flag-et, így a runtime DB-műveletek elindulnak.
958
- this.systemControls.mongoose.init = false;
959
-
960
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
961
- 'DYNTS-AS0-SDB1',
962
- DyNTS_SafeDiagnosticStage_Type.databaseConnect,
963
- error,
964
- 503
965
- );
966
-
967
- this.forwardSafeDiagnostic(diagnostic);
968
-
969
- resolve();
970
-
971
- } else {
972
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
973
- 'DYNTS-AS0-SDB2',
974
- DyNTS_SafeDiagnosticStage_Type.databaseRuntime,
975
- error,
976
- 503
977
- );
978
-
979
- this.forwardSafeDiagnostic(diagnostic);
980
- }
981
- });
982
-
983
- try {
984
- this.mongoose.connect(
985
- this._params.dbUri,
986
- this._params.dbOptions
987
- /* {
988
- directConnection: true,
989
- } */
990
- );
991
- } catch (error) {
992
- throw new DyFM_Error({
993
- ...this._getDefaultErrorSettings('startDB', error),
994
-
995
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB3`,
996
- });
997
- }
998
- }
999
- );
1000
- } catch (error) {
1001
- throw new DyFM_Error({
1002
- ...this._getDefaultErrorSettings('startDB', error),
1003
-
1004
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
1005
- });
1006
- }
1007
-
1008
- // 2026-06-20 — Mongo reconnect-guard. A MongoDB-driver a hostnevet connect-kor EGYSZER
1009
- // resolválja + cache-eli az IP-t; ha a Mongo-konténert recreate-elik (új docker-network IP),
1010
- // a driver a HALOTT IP-n ragad → ECONNREFUSED + buffering-timeout, és a service magától SOHA
1011
- // nem áll vissza. A guard sustained-disconnect (readyState !== 1) esetén — a driver saját
1012
- // grace-e UTÁN — TELJES disconnect()+connect()-et csinál → ÚJ MongoClient → ÚJ DNS-resolve →
1013
- // új IP → reconnect. Best-effort, always-on, healthy connection-t (===1) SOHA nem bánt; csak
1014
- // konténer-IP-frissítés, nem ír adatot. Lásd: mongo-reconnect-guard.util.ts.
1015
- try {
1016
- startMongoReconnectGuard({
1017
- getReadyState: (): number => this.mongoose.connection.readyState,
1018
- reconnect: async (): Promise<void> => {
1019
- await this.mongoose.disconnect().catch((): void => undefined);
1020
- await this.mongoose.connect(this._params.dbUri, this._params.dbOptions);
1021
- },
1022
- log: (msg: string): void => {
1023
- this.reportSafeDiagnostic(
1024
- 'DYNTS-AS0-MONGO-RECONNECT-EVENT',
1025
- DyNTS_SafeDiagnosticStage_Type.mongoReconnectGuard,
1026
- msg,
1027
- 503
1028
- );
1029
- },
1030
- });
1031
- } catch (guardErr) {
1032
- this.reportSafeDiagnostic(
1033
- 'DYNTS-AS0-MONGO-RECONNECT-FAILED',
1034
- DyNTS_SafeDiagnosticStage_Type.mongoReconnectGuard,
1035
- guardErr,
1036
- 503
1037
- );
1038
- }
1039
- }
1040
-
1041
- /**
1042
- * FR-258 / SR-2 — install MongoDB TTL indexes for every data-model that declared `retention`.
1043
- *
1044
- * Runs ONCE right after the DB connection opens. For each registered DB service (including the
1045
- * auto-created `_archived` siblings, which inherit the parent model's `retention`), it ensures a
1046
- * TTL index on the `__created` Date field with the resolved `expireAfterSeconds` — so MongoDB
1047
- * NATIVELY auto-deletes documents older than the configured age. This is the fleet-wide defense
1048
- * against the unbounded-collection-growth → in-memory-load → GC-thrash/OOM class.
1049
- *
1050
- * Guarantees:
1051
- * - **Non-fatal** — any error is logged but NEVER blocks startup (called fire-and-forget).
1052
- * - **Idempotent** — an existing index with the same TTL is a no-op; a CHANGED retention (different
1053
- * `expireAfterSeconds`, or an existing non-TTL `__created` index) is reconciled by drop+recreate
1054
- * (the field index is restored immediately, so query coverage is preserved).
1055
- */
1056
- private async installRetentionTtlIndexes(): Promise<void> {
1057
- try {
1058
- const services: DyNTS_DBService<any>[] = DyNTS_GlobalService.getAllDBServices();
1059
- let ensured: number = 0;
1060
-
1061
- for (const service of services) {
1062
- const ttlSeconds: number | undefined = DyFM_resolveRetentionTtlSeconds(service?.dataParams?.retention);
1063
- if (!ttlSeconds) { continue; }
1064
-
1065
- const dataName: string = service.dataParams.dataName;
1066
- // The mongoose Model exposes the native driver collection (.indexes / .createIndex / .dropIndex).
1067
- const collection: DyNTS_TtlIndexCollection | undefined =
1068
- (service?.dataModel as unknown as { collection?: DyNTS_TtlIndexCollection })?.collection;
1069
- if (!collection || typeof collection.createIndex !== 'function') { continue; }
1070
-
1071
- try {
1072
- const action: DyNTS_TtlIndexAction = await DyNTS_App.ensureRetentionTtlIndex(collection, ttlSeconds);
1073
- if (action === 'created') {
1074
- ensured++;
1075
- if (this.logSetup) {
1076
- DyFM_Log.success(
1077
- `[FR-258 retention] TTL index created on "${dataName}" — ` +
1078
- `${Math.round(ttlSeconds / 86400)}d (${ttlSeconds}s)`,
1079
- );
1080
- }
1081
- } else if (action === 'differs') {
1082
- // Live index has a different TTL — left untouched at boot (see ensureRetentionTtlIndex doc).
1083
- this.reportSafeDiagnostic(
1084
- 'DYNTS-AS0-RETENTION-INDEX-DIFFERS',
1085
- DyNTS_SafeDiagnosticStage_Type.retention,
1086
- new Error('retention-index-differs')
1087
- );
1088
- }
1089
- } catch (idxErr: unknown) {
1090
- this.reportSafeDiagnostic(
1091
- 'DYNTS-AS0-RETENTION-INDEX-FAILED',
1092
- DyNTS_SafeDiagnosticStage_Type.retention,
1093
- idxErr
1094
- );
1095
- }
1096
- }
1097
-
1098
- if (ensured > 0) {
1099
- DyFM_Log.success(`[FR-258 retention] ${ensured} TTL index(es) ensured (auto-retention active).`);
1100
- }
1101
- } catch (err: unknown) {
1102
- this.reportSafeDiagnostic(
1103
- 'DYNTS-AS0-RETENTION-INSTALLER-FAILED',
1104
- DyNTS_SafeDiagnosticStage_Type.retention,
1105
- err
1106
- );
1107
- }
1108
- }
1109
-
1110
- /**
1111
- * FR-258 / SR-2 — ensure a single `{ __created: 1 }` TTL index with the given `expireAfterSeconds`.
1112
- * Extracted as a pure-ish static so it is unit-testable with a mock collection. Idempotent + BOOT-SAFE:
1113
- * - no existing `__created` index → create it → `'created'`
1114
- * - existing with the SAME TTL → no-op → `'noop'`
1115
- * - existing with a DIFFERENT TTL / non-TTL → leave it as-is → `'differs'` (warn only — NO drop+recreate)
1116
- *
1117
- * The `'differs'` case intentionally does NOT mutate the live index. Dropping + recreating a TTL index on a
1118
- * large (multi-GB) production collection is a heavy server-side operation; doing it automatically inside the
1119
- * startup path can starve the concurrent boot queries (including the deploy health-probe) and trigger a
1120
- * fail-safe revert. Create-if-missing is the essential growth-prevention behaviour; a deliberate retention
1121
- * CHANGE on an already-indexed collection is a maintenance action, not a silent every-boot rebuild.
1122
- */
1123
- static async ensureRetentionTtlIndex(
1124
- collection: DyNTS_TtlIndexCollection,
1125
- ttlSeconds: number,
1126
- ): Promise<DyNTS_TtlIndexAction> {
1127
- const existingList: DyNTS_TtlIndexInfo[] = typeof collection.indexes === 'function'
1128
- ? await collection.indexes().catch((): DyNTS_TtlIndexInfo[] => [])
1129
- : [];
1130
- const existing: DyNTS_TtlIndexInfo | undefined =
1131
- existingList.find((ix): boolean => !!ix?.key && ix.key.__created === 1);
1132
-
1133
- if (!existing) {
1134
- await collection.createIndex({ __created: 1 }, { expireAfterSeconds: ttlSeconds });
1135
- return 'created';
1136
- }
1137
- if (existing.expireAfterSeconds === ttlSeconds) {
1138
- return 'noop';
1139
- }
1140
- // Retention differs from the live index (or it is a non-TTL `__created` index). Leave it UNTOUCHED at
1141
- // boot — only report it. Avoids a heavy drop+recreate competing with boot-readiness on a large collection.
1142
- return 'differs';
1143
- }
1144
-
1145
- /**
1146
- *
1147
- */
1148
- private async initExpresses(): Promise<void> {
1149
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. initExpresses');
1150
-
1151
- try {
1152
- if (this._security && this._security !== DyNTS_RouteSecurity.secure) {
1153
- if (this._portSettings.httpPort === undefined || this._portSettings.httpPort === null) {
1154
- let errorMsg: string =
1155
- `\nYou have open routes, but httpPort is not set!` +
1156
- `\nThere are ${this._routingModules.filter(
1157
- m => m.security != DyNTS_RouteSecurity.secure
1158
- ).length} open/both routes` +
1159
- `\nroot security: ${this._security}` +
1160
- `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
1161
-
1162
- errorMsg += '\n\nThe routes setted to use open server:';
1163
- this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
1164
- if (module.security != DyNTS_RouteSecurity.secure) {
1165
- errorMsg += `\n ${module.route} (security: ${module.security})`;
1166
- errorMsg += `\n subroutes using open sever:`;
1167
- module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
1168
- if (endpoint.security != DyNTS_RouteSecurity.secure) {
1169
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
1170
- }
1171
- });
1172
- }
1173
- });
1174
-
1175
- const error = new Error(`Open routes cannot be established!\n${errorMsg}`);
1176
- const errorStack: string[] = error.stack.split('\n');
1177
-
1178
- errorStack.splice(1, 2);
1179
- error.stack = errorStack.join('\n');
1180
-
1181
- this.reportSafeDiagnostic(
1182
- 'DYNTS-AS0-OPEN-ROUTE-CONFIGURATION',
1183
- DyNTS_SafeDiagnosticStage_Type.routing,
1184
- error
1185
- );
1186
-
1187
- throw error;
1188
- }
1189
-
1190
- await this.initOpenExpress();
1191
- }
1192
-
1193
- if (this._security && this._security !== DyNTS_RouteSecurity.open) {
1194
- if (!this._cert || !this._portSettings.httpsPort) {
1195
- let errorMsg: string =
1196
- `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
1197
- `\nThere are ${this._routingModules.filter(
1198
- m => m.security && m.security !== DyNTS_RouteSecurity.open
1199
- ).length} secure routes` +
1200
- `\nroot security: ${this._security}` +
1201
- `\nset...` +
1202
- `\n(missing exact howto...)` +
1203
- /* `\n httpsPort and` +
1204
- `\n cert: {` +
1205
- `\n keyPath: FileSystem.PathLike,` +
1206
- `\n certPath: FileSystem.PathLike,` +
1207
- `\n }` + */
1208
- `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
1209
-
1210
- errorMsg += '\n\nThe routes setted to use secure server:';
1211
- this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
1212
- if (module.security && module.security !== DyNTS_RouteSecurity.open) {
1213
- errorMsg += `\n ${module.route} (security: ${module.security})`;
1214
- errorMsg += `\n location: ${module.stackLocation}`;
1215
- errorMsg += `\n subroutes using secure sever:`;
1216
- module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
1217
- if (endpoint.security && endpoint.security !== DyNTS_RouteSecurity.open) {
1218
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
1219
- errorMsg += `\n location: ${endpoint.stackLocation}`;
1220
- }
1221
- });
1222
- }
1223
- });
1224
-
1225
- const error = new Error(`Secure routes cannot be established!\n${errorMsg}`);
1226
- const errorStack: string[] = error.stack.split('\n');
1227
-
1228
- errorStack.splice(1, 2);
1229
- error.stack = errorStack.join('\n');
1230
-
1231
- this.reportSafeDiagnostic(
1232
- 'DYNTS-AS0-SECURE-ROUTE-CONFIGURATION',
1233
- DyNTS_SafeDiagnosticStage_Type.routing,
1234
- error
1235
- );
1236
-
1237
- throw error;
1238
- }
1239
-
1240
- await this.initSecureExpress();
1241
- }
1242
- } catch (error) {
1243
- throw new DyFM_Error({
1244
- ...this._getDefaultErrorSettings('initExpresses', error),
1245
-
1246
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-IE0`,
1247
- });
1248
- }
1249
- }
1250
-
1251
- /**
1252
- *
1253
- */
1254
- protected async initOpenExpress(): Promise<void> {
1255
- if (this.fnLogs) DyFM_Log.log('\nfn:. initOpenExpress');
1256
- this.openExpress = Express();
1257
- this.openExpress.set('maxHeaderSize', 10 * megabyte); // 1024 * 1024 * 10, // 10MB
1258
- this.openExpress.use(BodyParser.urlencoded(this._portSettings.httpUrlencoded));
1259
- this.openExpress.use(BodyParser.json(this._portSettings.httpJson));
1260
- // BFR-011 / SEC-R2-8 — security headerek a CORS ELŐTT (az OPTIONS preflight-válaszok is kapják).
1261
- this.mountSecurityHeaders(this.openExpress);
1262
- // FR-041 — CORS allowlist enforcement. No-op if getCorsSettings() is not overridden.
1263
- this.mountCors(this.openExpress);
1264
- // FR-292 — a deployolt app-verzio minden valaszon. A CORS UTAN kell, mert az
1265
- // `Access-Control-Expose-Headers`-hoz HOZZAFUZ (kulonben a CORS felulirna).
1266
- this.mountAppVersionHeader(this.openExpress);
1267
- this.mountRequestTelemetry(this.openExpress);
1268
- // BFR-OVERSEER-009 — opt-in auto-load-shed 503 CRITICAL memória-nyomásnál (esszenciális utak kivételével).
1269
- if (DyNTS_global_settings.memoryGuard?.loadShedEnabled) {
1270
- this.openExpress.use(DyNTS_createLoadShedMiddleware());
1271
- }
1272
- }
1273
-
1274
- /**
1275
- *
1276
- */
1277
- protected async initSecureExpress(): Promise<void> {
1278
- if (this.fnLogs) DyFM_Log.log('\nfn:. initSecureExpress');
1279
- this.secureExpress = Express();
1280
- this.secureExpress.use(BodyParser.urlencoded(this._portSettings.httpsUrlencoded));
1281
- this.secureExpress.use(BodyParser.json(this._portSettings.httpsJson));
1282
- // BFR-011 / SEC-R2-8 — security headerek a CORS ELŐTT (mint az open expressen).
1283
- this.mountSecurityHeaders(this.secureExpress);
1284
- // FR-041 — CORS allowlist enforcement (same as open express).
1285
- this.mountCors(this.secureExpress);
1286
- // FR-292 — a deployolt app-verzio minden valaszon (mint az open expressen).
1287
- this.mountAppVersionHeader(this.secureExpress);
1288
- this.mountRequestTelemetry(this.secureExpress);
1289
- // BFR-OVERSEER-009 — opt-in auto-load-shed 503 (mint az open expressen).
1290
- if (DyNTS_global_settings.memoryGuard?.loadShedEnabled) {
1291
- this.secureExpress.use(DyNTS_createLoadShedMiddleware());
1292
- }
1293
-
1294
- const options = {
1295
- key: FileSystem.readFileSync(this._cert.keyPath),
1296
- cert: FileSystem.readFileSync(this._cert.certPath),
1297
- maxHeaderSize: 10 * megabyte, // 1024 * 1024 * 10, // 10MB
1298
- };
1299
-
1300
- this.httpsServer = Https.createServer(options, this.secureExpress);
1301
- }
1302
-
1303
- /**
1304
- *
1305
- */
1306
- private async startExpresses(): Promise<void> {
1307
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. startExpresses');
1308
-
1309
- try {
1310
- if (this._security && this._security !== DyNTS_RouteSecurity.open) {
1311
- await new Promise<void>((resolve, reject): void => {
1312
- this.systemControls.httpsServer.init = true;
1313
- this.httpsServer
1314
- .listen(
1315
- this._portSettings.httpsPort,
1316
- this.params.secureHost,
1317
- this.params.expressBacklog,
1318
- (): void => {
1319
- this.systemControls.httpsServer.started = true;
1320
- DyFM_Log.success(
1321
- `\nHTTPS (secure) server is listening on port: ` +
1322
- `${this.params.secureHost}:${this._portSettings.httpsPort}`
1323
- );
1324
-
1325
- resolve();
1326
- })
1327
- .on('error', (error: unknown): void => {
1328
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
1329
- 'DYNTS-AS0-HTTPS-ERROR',
1330
- DyNTS_SafeDiagnosticStage_Type.httpsServer,
1331
- error,
1332
- 503
1333
- );
1334
-
1335
- if (!this.systemControls.httpsServer.started) {
1336
- const d_error: DyFM_Error = new DyFM_Error({
1337
- ...this._getDefaultErrorSettings('startExpresses', error),
1338
-
1339
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE1`,
1340
- message: `HTTPS (secure) start server ERROR`,
1341
- });
1342
-
1343
- this.constructErrors.push(d_error);
1344
- this.forwardSafeDiagnostic(diagnostic);
1345
-
1346
- reject(d_error);
1347
-
1348
- } else {
1349
- this.forwardSafeDiagnostic(diagnostic);
1350
- }
1351
- })
1352
- .on('uncaughtException', (exception): void => {
1353
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
1354
- 'DYNTS-AS0-HTTPS-UNCAUGHT',
1355
- DyNTS_SafeDiagnosticStage_Type.httpsServer,
1356
- exception
1357
- );
1358
-
1359
- this.forwardSafeDiagnostic(diagnostic);
1360
- });
1361
- });
1362
- }
1363
-
1364
- if (this._security && this._security !== DyNTS_RouteSecurity.secure) {
1365
- this.systemControls.httpServer.init = true;
1366
- await new Promise<void>((resolve, reject): void => {
1367
- this.httpServer = this.openExpress
1368
- .listen(
1369
- this._portSettings.httpPort,
1370
- this.params.openHost,
1371
- this.params.expressBacklog,
1372
- (): void => {
1373
- this.systemControls.httpServer.started = true;
1374
-
1375
- const resolvedPort: number = this.httpServer?.address?.()?.['port'] ?? this._portSettings.httpPort;
1376
-
1377
- if (this._portSettings.httpPort === 0) {
1378
- DyFM_Log.H_warn(
1379
- `\nHTTP (open) server is using a randomly selected port by the OS: ${resolvedPort}` +
1380
- `\n (httpPort was set to 0 — this is intended for testing only)`
1381
- );
1382
- }
1383
-
1384
- DyFM_Log.success(
1385
- `\nHTTP (open) server is listening on port: ` +
1386
- `${this.params.openHost}:${resolvedPort}`
1387
- );
1388
-
1389
- resolve();
1390
- }
1391
- )
1392
- .on('error', (error: unknown): void => {
1393
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
1394
- 'DYNTS-AS0-HTTP-ERROR',
1395
- DyNTS_SafeDiagnosticStage_Type.httpServer,
1396
- error,
1397
- 503
1398
- );
1399
-
1400
- if (!this.systemControls.httpServer.started) {
1401
- const d_error: DyFM_Error = new DyFM_Error({
1402
- ...this._getDefaultErrorSettings('startExpresses', error),
1403
-
1404
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE3`,
1405
- message: `HTTP (open) start server ERROR`,
1406
- });
1407
-
1408
- this.constructErrors.push(d_error);
1409
- this.forwardSafeDiagnostic(diagnostic);
1410
-
1411
- reject(d_error);
1412
-
1413
- } else {
1414
- this.forwardSafeDiagnostic(diagnostic);
1415
- }
1416
- })
1417
- .on('uncaughtException', (exception): void => {
1418
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
1419
- 'DYNTS-AS0-HTTP-UNCAUGHT',
1420
- DyNTS_SafeDiagnosticStage_Type.httpServer,
1421
- exception
1422
- );
1423
-
1424
- this.forwardSafeDiagnostic(diagnostic);
1425
- });
1426
- });
1427
- }
1428
- } catch (error) {
1429
- throw new DyFM_Error({
1430
- ...this._getDefaultErrorSettings('startExpresses', error),
1431
-
1432
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE0`,
1433
- });
1434
- }
1435
- }
1436
-
1437
- /**
1438
- *
1439
- */
1440
- private async expressErrorHandling(error, req, res, next): Promise<void> {
1441
- try {
1442
- if (error) {
1443
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
1444
- 'DYNTS-AS0-EXPRESS-ERROR',
1445
- DyNTS_SafeDiagnosticStage_Type.expressFallback,
1446
- error
1447
- );
1448
-
1449
- this.forwardSafeDiagnostic(diagnostic);
1450
-
1451
- // Kliens-safe strip (BFR-FDPAUTHSERVICE-002): az express-error út eddig NYERS error-t küldött
1452
- // (0 strip) — DyFM-nél belső stack/verzió/issuer, axios-jellegű error-nál akár auth-header is
1453
- // kimehetett. A strip-szabályok SSOT-ja a DyNTS_ClientSafeError_Util.
1454
- res.send(DyNTS_ClientSafeError_Util.toClientSafe(error))
1455
- } else {
1456
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
1457
- 'DYNTS-AS0-EXPRESS-MISSING-ERROR',
1458
- DyNTS_SafeDiagnosticStage_Type.expressFallback
1459
- );
1460
-
1461
- this.forwardSafeDiagnostic(diagnostic);
1462
- }
1463
- } catch (error) {
1464
- const diagnostic: DyNTS_SafeDiagnostic_Interface = this.reportSafeDiagnostic(
1465
- 'DYNTS-AS0-EXPRESS-MULTILEVEL',
1466
- DyNTS_SafeDiagnosticStage_Type.expressFallback,
1467
- error
1468
- );
1469
-
1470
- this.forwardSafeDiagnostic(diagnostic);
1471
- }
1472
- }
1473
-
1474
- /**
1475
- *
1476
- */
1477
- private async mountSecureRoutes (): Promise<void> {
1478
- try {
1479
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountSecureRoutes');
1480
-
1481
- if (!this.secureExpress) {
1482
- throw new Error(
1483
- 'secureExpress was not initialized. ' +
1484
- 'Secure routes require getCertificationSettings and httpsPort, and cert files must exist.' +
1485
- '\n\nYou need to set security to secure or both in any route and set httpsPort in getPortSettings.' +
1486
- '\n\nYou need to set cert files in getCertificationSettings.'
1487
- );
1488
- }
1489
-
1490
- this.secureExpress.use(
1491
- (error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
1492
- );
1493
-
1494
- await DyFM_Array.asyncForEach(
1495
- this._routingModules,
1496
- async (module: DyNTS_RoutingModule): Promise<void> => {
1497
- if (module.security !== DyNTS_RouteSecurity.open) {
1498
- if (this.logSetup) {
1499
- DyFM_Log.log(`route mount (secure): ${module.route}`);
1500
- }
1501
-
1502
- const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
1503
- (mod: DyNTS_RoutingModule): boolean => mod.route === module.route
1504
- );
1505
-
1506
- if (1 < existingRoutes.length) {
1507
- const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1508
- /* const errorStack: string[] = error.stack.split('\n');
1509
-
1510
- errorStack.splice(1, 4);
1511
- error.stack = errorStack.join('\n'); */
1512
- error.stack = module.stackLocation;
1513
-
1514
- this.reportSafeDiagnostic(
1515
- 'DYNTS-AS0-SECURE-ROUTE-DUPLICATION',
1516
- DyNTS_SafeDiagnosticStage_Type.routing,
1517
- error
1518
- );
1519
-
1520
- throw new DyFM_Error({
1521
- ...this._getDefaultErrorSettings('mountSecureRoutes', error),
1522
-
1523
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MSR1`,
1524
- message: `ROUTE DUPLICATION: ${module.route}`,
1525
- });
1526
- }
1527
-
1528
- this.secureExpress.use(module.route, module.secureRouter);
1529
- }
1530
- }
1531
- );
1532
- } catch (error) {
1533
- throw new DyFM_Error({
1534
- ...this._getDefaultErrorSettings('mountSecureRoutes', error),
1535
-
1536
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MSR0`,
1537
- });
1538
- }
1539
- }
1540
-
1541
- /**
1542
- *
1543
- */
1544
- private async mountOpenRoutes(): Promise<void> {
1545
- try {
1546
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountOpenRoutes');
1547
-
1548
- if (!this.openExpress) {
1549
- throw new Error(
1550
- 'openExpress was not initialized. Open routes require getOpenExpress and httpPort.' +
1551
- '\n\nYou need to set security to open or both in any route and set httpPort in getPortSettings.'
1552
- );
1553
- }
1554
-
1555
- this.openExpress.use(
1556
- (error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
1557
- );
1558
-
1559
- await DyFM_Array.asyncForEach(
1560
- this._routingModules,
1561
- async (module: DyNTS_RoutingModule): Promise<void> => {
1562
- if (module.security !== DyNTS_RouteSecurity.secure) {
1563
- if (this.logSetup) {
1564
- DyFM_Log.log(`route mount (open): ${module.route}`);
1565
- }
1566
-
1567
- const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
1568
- (mod: DyNTS_RoutingModule): boolean => mod.route === module.route
1569
- );
1570
-
1571
- if (1 < existingRoutes.length) {
1572
- const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1573
- /* const errorStack: string[] = error.stack.split('\n');
1574
-
1575
- errorStack.splice(1, 4);
1576
- error.stack = errorStack.join('\n'); */
1577
- error.stack = module.stackLocation;
1578
-
1579
- this.reportSafeDiagnostic(
1580
- 'DYNTS-AS0-OPEN-ROUTE-DUPLICATION',
1581
- DyNTS_SafeDiagnosticStage_Type.routing,
1582
- error
1583
- );
1584
-
1585
- throw new DyFM_Error({
1586
- ...this._getDefaultErrorSettings('mountOpenRoutes', error),
1587
-
1588
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MOR1`,
1589
- message: `ROUTE DUPLICATION: ${module.route}`,
1590
- });
1591
- }
1592
-
1593
- this.openExpress.use(module.route, module.openRouter);
1594
- }
1595
- }
1596
- );
1597
- } catch (error) {
1598
- throw new DyFM_Error({
1599
- ...this._getDefaultErrorSettings('mountOpenRoutes', error),
1600
-
1601
- errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MOR0`,
1602
- });
1603
- }
1604
- }
1605
-
1606
- /**
1607
- * FR-041 — CORS middleware. Echoes a matching `Access-Control-Allow-Origin`
1608
- * for any request whose Origin header is in `getCorsSettings().allowedOrigins`,
1609
- * adds the canonical `Access-Control-*` companion headers, and short-circuits
1610
- * the OPTIONS preflight with a 204.
1611
- *
1612
- * No-op when the subclass does NOT override `getCorsSettings()` — preserves
1613
- * back-compat for apps that have always been same-origin and never needed
1614
- * CORS (the typical pre-FR-041 case).
1615
- *
1616
- * Why hand-rolled instead of the `cors` npm package:
1617
- * - ~30 lines, zero new dependency.
1618
- * - Full control over Vary/credentials/preflight semantics.
1619
- * - Aligns with FDP "no unnecessary deps" philosophy.
1620
- */
1621
- /**
1622
- * BFR-011 / SEC-R2-8 — security response-headerek mountolása (a `mountCors` tükörképe).
1623
- * A `DyNTS_global_settings.securityHeaders` alapján (default-ON) minden válaszra ráteszi a
1624
- * biztonsági headereket + eltávolítja az `x-powered-by`-t. A CORS-mount ELŐTT hívandó, hogy az
1625
- * OPTIONS preflight-válaszok (amiket a mountCors 204-gyel rövidre zár) is megkapják.
1626
- */
1627
- protected mountSecurityHeaders(express: Express.Application): void {
1628
- const settings: DyNTS_SecurityHeaders_Settings | undefined = DyNTS_global_settings.securityHeaders;
1629
- if (!settings || !settings.enabled) {
1630
- return;
1631
- }
1632
-
1633
- if (settings.removePoweredBy !== false) {
1634
- express.disable('x-powered-by');
1635
- }
1636
-
1637
- express.use(DyNTS_createSecurityHeadersMiddleware(
1638
- settings,
1639
- DyNTS_getEnvironment_settings().environment,
1640
- ));
1641
- }
1642
-
1643
- /**
1644
- * FR-292 — a deployolt app-verziot minden valaszra rateszi (`X-App-Version`), hogy a
1645
- * bongeszoben NYITVA HAGYOTT SPA eszrevegye, ha kozben ujabb kliens-build ment ki.
1646
- *
1647
- * Nem polling: a jelzes a MAR MENO API-hivasokon utazik. Az `enabled` default TRUE — egy
1648
- * informativ response-header, ami se PII-t, se belso reszletet nem szivarogtat, viszont
1649
- * enelkul minden app kulon-kulon epitene ugyanezt.
1650
- */
1651
- protected mountAppVersionHeader(express: Express.Application): void {
1652
- const settings: DyNTS_AppVersionHeader_Settings | undefined = DyNTS_global_settings.appVersionHeader;
1653
- if (settings?.enabled === false) {
1654
- return;
1655
- }
1656
- express.use(DyNTS_createAppVersionHeaderMiddleware(
1657
- (): string => DyNTS_global_settings.systemVersion,
1658
- settings?.headerName,
1659
- ));
1660
- }
1661
-
1662
- /** Mounts opt-in correlation and aggregate metrics before load shedding and every API route. */
1663
- protected mountRequestTelemetry(express: Express.Application): void {
1664
- const settings: DyNTS_RequestTelemetry_Settings | undefined = this.getRequestTelemetrySettings?.();
1665
- if (settings?.enabled !== true) {
1666
- return;
1667
- }
1668
-
1669
- const telemetry: DyNTS_RequestTelemetry_ControlService =
1670
- DyNTS_RequestTelemetry_ControlService.getInstance();
1671
- telemetry.configure(settings);
1672
- express.use(telemetry.createMiddleware());
1673
- }
1674
-
1675
- protected mountCors(express: Express.Application): void {
1676
- const settings: DyNTS_Cors_Settings | undefined = this.getCorsSettings?.();
1677
- if (!settings) {
1678
- return;
1679
- }
1680
-
1681
- const allowCreds: boolean = settings.allowCredentials !== false;
1682
- const methods: string[] = settings.allowedMethods ?? [
1683
- 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS',
1684
- ];
1685
- const headers: string[] = settings.allowedHeaders ?? [
1686
- 'Authorization', 'Content-Type', 'X-Admin-Key', 'X-Requested-With',
1687
- ];
1688
- const exposed: string[] = settings.exposedHeaders ?? [
1689
- 'Content-Length', 'Content-Type',
1690
- ];
1691
- const maxAge: number = settings.maxAgeSeconds ?? 86400;
1692
-
1693
- const isAllowed: (origin: string) => boolean = (origin: string): boolean => {
1694
- if (settings.allowedOrigins === '*') return true;
1695
- if (typeof settings.allowedOrigins === 'function') {
1696
- return settings.allowedOrigins(origin);
1697
- }
1698
- return settings.allowedOrigins.includes(origin);
1699
- };
1700
-
1701
- express.use((req: Express.Request, res: Express.Response, next: Express.NextFunction): void => {
1702
- const origin: string | undefined = req.headers.origin;
1703
- if (origin && isAllowed(origin)) {
1704
- // Echo the matching origin (NOT wildcard) because credentials require it.
1705
- res.setHeader('Access-Control-Allow-Origin', origin);
1706
- if (allowCreds) {
1707
- res.setHeader('Access-Control-Allow-Credentials', 'true');
1708
- }
1709
- res.setHeader('Access-Control-Allow-Methods', methods.join(', '));
1710
- res.setHeader('Access-Control-Allow-Headers', headers.join(', '));
1711
- res.setHeader('Access-Control-Expose-Headers', exposed.join(', '));
1712
- res.setHeader('Access-Control-Max-Age', String(maxAge));
1713
- res.setHeader('Vary', 'Origin');
1714
- }
1715
- if (req.method === 'OPTIONS') {
1716
- res.status(204).end();
1717
- return;
1718
- }
1719
- next();
1720
- });
1721
- }
1722
-
1723
- /**
1724
- * Generikus, auth-agnosztikus extension-point orchestrator. A `registerCustomMiddleware`
1725
- * hookot hívja (ha a subclass override-olja) minden AKTÍV Express instance-ra
1726
- * (open + secure), az API route-ok UTÁN, de a SPA static catch-all (`app.get('*')`)
1727
- * ELŐTT — ez az EGYETLEN korrekt pont egy sub-path middleware-hez (pl. reverse-proxy),
1728
- * mert a catch-all minden utána mountolt route-ot elnyel. No-op ha nincs override (back-compat).
1729
- */
1730
- private async mountCustomMiddleware(): Promise<void> {
1731
- if (!this.registerCustomMiddleware) {
1732
- return;
1733
- }
1734
-
1735
- if (this.openExpress) {
1736
- await this.registerCustomMiddleware(this.openExpress, DyNTS_RouteSecurity.open);
1737
- }
1738
-
1739
- if (this.secureExpress) {
1740
- await this.registerCustomMiddleware(this.secureExpress, DyNTS_RouteSecurity.secure);
1741
- }
1742
-
1743
- if (this.logSetup) {
1744
- DyFM_Log.log('\nCustom middleware registered (pre-static).');
1745
- }
1746
- }
1747
-
1748
- /**
1749
- * Ha getStaticClientSettings() visszaad beállításokat, a client static fájlok a '/' alatt
1750
- * lesznek kiszolgálva (API route-ok után). SPA fallback opcionális (fallbackPath).
1751
- * Asset cache (assetCacheMaxAge, assetCacheImmutable) és fallback cache (fallbackCacheMaxAge)
1752
- * opcionálisak; ha nincs megadva fallbackCacheMaxAge, DyNTS_defaultFallbackCacheMaxAge (0) marad.
1753
- */
1754
- private async mountStaticClient(): Promise<void> {
1755
- const settings: DyNTS_StaticClient_Settings | undefined = this.getStaticClientSettings?.();
1756
- if (!settings) {
1757
- return;
1758
- }
1759
-
1760
- const absoluteRoot: string = Path.isAbsolute(settings.root)
1761
- ? settings.root
1762
- : Path.resolve(process.cwd(), settings.root);
1763
-
1764
- const hasAssetCache: boolean =
1765
- settings.assetCacheMaxAge !== undefined || settings.assetCacheImmutable === true;
1766
- const staticOptions: { setHeaders: (res: Express.Response, filePath: string) => void } | undefined =
1767
- hasAssetCache && settings.assetCacheMaxAge !== undefined
1768
- ? {
1769
- setHeaders: (res: Express.Response, filePath: string): void => {
1770
- // A HTML entry-fájlok (index.html) no-cache-t kapnak, a hash-elt asset-ek
1771
- // immutable long-cache-t — lásd DyNTS_resolveStaticCacheControlHeader (served-stale-index fix).
1772
- res.setHeader(
1773
- 'Cache-Control',
1774
- DyNTS_resolveStaticCacheControlHeader({
1775
- filePath: filePath,
1776
- assetCacheMaxAge: settings.assetCacheMaxAge!,
1777
- assetCacheImmutable: settings.assetCacheImmutable === true,
1778
- }),
1779
- );
1780
- },
1781
- }
1782
- : undefined;
1783
-
1784
- const staticMiddleware: Express.Handler =
1785
- staticOptions
1786
- ? Express.static(absoluteRoot, staticOptions)
1787
- : Express.static(absoluteRoot);
1788
-
1789
- const fallbackMaxAge: number =
1790
- settings.fallbackCacheMaxAge ?? DyNTS_defaultFallbackCacheMaxAge;
1791
-
1792
- // API-namespace guard (BFR-DYNAMOBUILDER-001): a catch-all fallback NE fedje az API-prefixeket —
1793
- // egy ismeretlen `GET /api/...` 404 JSON-t kapjon, ne megtévesztő `200 + index.html`-t.
1794
- // Konfigurálható (fallbackExcludePrefixes); default a bevett FDP namespace-pár.
1795
- const excludePrefixes: string[] = settings.fallbackExcludePrefixes ?? ['/api', '/auth-api'];
1796
- const isApiNamespacePath = (path: string): boolean =>
1797
- excludePrefixes.some((prefix: string): boolean => path === prefix || path.startsWith(`${prefix}/`));
1798
-
1799
- if (this.openExpress) {
1800
- this.openExpress.use('/', staticMiddleware);
1801
- if (settings.fallbackPath) {
1802
- this.openExpress.get('*', (req: Express.Request, res: Express.Response): void => {
1803
- if (isApiNamespacePath(req.path)) {
1804
- res.status(404).send({ message: `Unknown API endpoint: ${req.path}` });
1805
- return;
1806
- }
1807
- res.setHeader('Cache-Control', `max-age=${fallbackMaxAge}`);
1808
- res.sendFile(settings.fallbackPath!, { root: absoluteRoot });
1809
- });
1810
- } else {
1811
- this.openExpress.get('*', (req: Express.Request, res: Express.Response): void => {
1812
- if (isApiNamespacePath(req.path)) {
1813
- res.status(404).send({ message: `Unknown API endpoint: ${req.path}` });
1814
- return;
1815
- }
1816
- res.status(404).type('html').send(DyNTS_defaultNotFoundPageHtml);
1817
- });
1818
- }
1819
- }
1820
-
1821
- if (this.secureExpress) {
1822
- this.secureExpress.use('/', staticMiddleware);
1823
- if (settings.fallbackPath) {
1824
- this.secureExpress.get('*', (req: Express.Request, res: Express.Response): void => {
1825
- if (isApiNamespacePath(req.path)) {
1826
- res.status(404).send({ message: `Unknown API endpoint: ${req.path}` });
1827
- return;
1828
- }
1829
- res.setHeader('Cache-Control', `max-age=${fallbackMaxAge}`);
1830
- res.sendFile(settings.fallbackPath!, { root: absoluteRoot });
1831
- });
1832
- } else {
1833
- this.secureExpress.get('*', (req: Express.Request, res: Express.Response): void => {
1834
- if (isApiNamespacePath(req.path)) {
1835
- res.status(404).send({ message: `Unknown API endpoint: ${req.path}` });
1836
- return;
1837
- }
1838
- res.status(404).type('html').send(DyNTS_defaultNotFoundPageHtml);
1839
- });
1840
- }
1841
- }
1842
-
1843
- if (this.logSetup) {
1844
- DyFM_Log.log(`\nStatic client mounted at / (root: ${absoluteRoot})`);
1845
- }
1846
- }
1847
-
1848
- /**
1849
- *
1850
- */
1851
- private setSecurity(): void {
1852
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. setSecurity');
1853
- this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
1854
- if (!module.security) {
1855
- DyFM_Log.warn(`RoutingModule security is not set for ${module.route}\n`);
1856
-
1857
- } else if (!this._security) {
1858
- this._security = module.security;
1859
-
1860
- } else if (this._security !== module.security) {
1861
- this._security = DyNTS_RouteSecurity.both;
1862
- }
1863
- });
1864
-
1865
- if (!this._security) {
1866
- let msg = `Could not set security for the server! (${this.security})`;
1867
-
1868
- msg += '\n RoutingModules:';
1869
- this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
1870
- msg += `\n ${module.route} (security: ${module.security})`;
1871
- });
1872
-
1873
- if (this._routingModules.length === 0) {
1874
- msg += '\n - no RoutingModule found -\n';
1875
- }
1876
- DyFM_Log.warn(msg);
1877
- }
1878
- }
1879
-
1880
- private _getDefaultErrorSettings(
1881
- fnName: string,
1882
- error: DyFM_AnyError
1883
- ): DyFM_Error_Settings {
1884
- return {
1885
- status: (error as DyFM_Error)?.___status ?? 500,
1886
- message: (error as Error)?.message ??
1887
- (error as DyFM_Error)?._message ??
1888
- `${fnName} was UNSUCCESSFUL (NTS)`,
1889
- userMessage: (error as DyFM_Error)?.__userMessage ?? this.defaultErrorUserMsg,
1890
- addECToUserMsg: !(error as DyFM_Error)?.__userMessage,
1891
- issuerService: `${this?.constructor?.name}-DyNTS_App`,
1892
- level: DyFM_ErrorLevel.fatal,
1893
- error: error,
1894
- systemVersion: DyNTS_global_settings.systemVersion,
1895
- };
1896
- }
1897
-
1898
- /**
1899
- * MISSING Description (TODO)
1900
- */
1901
- abstract getAppParams(): DyNTS_App_Params;
1902
-
1903
- /**
1904
- * MISSING Description (TODO)
1905
- */
1906
- abstract getGlobalServiceCollection(): DyNTS_GlobalService_Settings;
1907
-
1908
- /**
1909
- * MISSING Description (TODO)
1910
- */
1911
- abstract getPortSettings(): DyNTS_Http_Settings;
1912
-
1913
- /**
1914
- * MISSING Description (TODO)
1915
- */
1916
- overrideDynamoNTSGlobalSettings?(): void;
1917
-
1918
- /**
1919
- * Ha megadva, a visszaadott értéket használjuk a route prefix-ként
1920
- * (DyNTS_global_settings.baseUrl felülírása erre az app-ra).
1921
- */
1922
- getApiBasePath?(): string;
1923
-
1924
- /**
1925
- * MISSING Description (TODO)
1926
- */
1927
- getRoutingModules?(): DyNTS_RoutingModule[];
1928
-
1929
- /**
1930
- * MISSING Description (TODO)
1931
- */
1932
- getRootServices?(): Promise<any[]>;
1933
-
1934
- /**
1935
- * MISSING Description (TODO)
1936
- */
1937
- getCertificationSettings?(): DyNTS_Certification_Settings;
1938
-
1939
- /**
1940
- * Ha megadva, a client static fájlok a '/' alatt lesznek kiszolgálva (API route-ok után).
1941
- * Opcionális fallbackPath pl. SPA index.html-hez.
1942
- */
1943
- getStaticClientSettings?(): DyNTS_StaticClient_Settings | undefined;
1944
-
1945
- /**
1946
- * FR-041 — Ha megadva, CORS middleware mount-olódik mindkét Express instance-ra
1947
- * (open + secure). Az `allowedOrigins` listán szereplő Origin-eket echo-zza vissza,
1948
- * `Access-Control-Allow-Credentials: true`-val (default) együtt a Bearer JWT
1949
- * cross-domain auth flow miatt. OPTIONS preflight 204-gyel rövidre záródik.
1950
- * Ha undefined → no CORS headers, no preflight handling — back-compat.
1951
- */
1952
- getCorsSettings?(): DyNTS_Cors_Settings | undefined;
1953
-
1954
- /** Enables content-free request correlation and event-driven aggregate metrics before API routing. */
1955
- getRequestTelemetrySettings?(): DyNTS_RequestTelemetry_Settings | undefined;
1956
-
1957
- /**
1958
- * Opcionális generikus hook: custom Express middleware regisztrálása az API route-ok
1959
- * UTÁN és a SPA static catch-all ELŐTT. Auth-AGNOSZTIKUS framework extension-point —
1960
- * a subclass (pl. FDP base App) ezen keresztül mount-olhat reverse-proxyt egy sub-path-re
1961
- * (pl. `/auth-api`), ami a `app.get('*')` catch-all elé kell kerüljön. A hívási időzítést
1962
- * lásd: `mountCustomMiddleware`. Undefined → no-op (back-compat).
1963
- */
1964
- registerCustomMiddleware?(
1965
- express: Express.Application,
1966
- security: DyNTS_RouteSecurity,
1967
- ): void | Promise<void>;
1968
-
1969
- /**
1970
- * MISSING Description (TODO)
1971
- */
1972
- createEntries?(): Promise<void>;
1973
-
1974
- /**
1975
- * MISSING Description (TODO)
1976
- */
1977
- postProcess?(): Promise<void>;
1978
-
1979
- }