@futdevpro/nts-dynamo 1.15.157 → 1.15.160

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 (634) hide show
  1. package/LICENSE +17 -17
  2. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.d.ts +71 -0
  3. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.d.ts.map +1 -0
  4. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.js +3 -0
  5. package/build/_modules/privacy-lifecycle/_models/privacy-export-artifact.interface.js.map +1 -0
  6. package/build/_modules/privacy-lifecycle/index.d.ts +3 -0
  7. package/build/_modules/privacy-lifecycle/index.d.ts.map +1 -1
  8. package/build/_modules/privacy-lifecycle/index.js +5 -1
  9. package/build/_modules/privacy-lifecycle/index.js.map +1 -1
  10. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.d.ts +48 -0
  11. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.d.ts.map +1 -0
  12. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.js +332 -0
  13. package/build/_modules/privacy-lifecycle/privacy-export-artifact.control-service.js.map +1 -0
  14. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.d.ts +25 -0
  15. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.d.ts.map +1 -0
  16. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.js +126 -0
  17. package/build/_modules/privacy-lifecycle/privacy-export-artifact.mongo-store.js.map +1 -0
  18. package/package.json +11 -4
  19. package/.c8rc.json +0 -26
  20. package/.copilot/patterns.json +0 -8
  21. package/.cursor/rules/__assistant_guide.mdc +0 -30
  22. package/.cursor/rules/__main.mdc +0 -64
  23. package/.cursor/rules/_ag_backend-structure.mdc +0 -86
  24. package/.cursor/rules/_ag_backend.mdc +0 -16
  25. package/.cursor/rules/_ag_debug.mdc +0 -8
  26. package/.cursor/rules/_ag_documentation_writing_rules.mdc +0 -372
  27. package/.cursor/rules/_ag_file-refactoring.mdc +0 -113
  28. package/.cursor/rules/_ag_fixes_rules.mdc +0 -6
  29. package/.cursor/rules/_ag_frontend-structure.mdc +0 -87
  30. package/.cursor/rules/_ag_frontend.mdc +0 -40
  31. package/.cursor/rules/_ag_import-rules.mdc +0 -45
  32. package/.cursor/rules/_ag_naming.mdc +0 -116
  33. package/.cursor/rules/_ag_running_commands.mdc +0 -5
  34. package/.cursor/rules/_ag_server-controller.mdc +0 -6
  35. package/.cursor/rules/_ag_should-be.mdc +0 -7
  36. package/.cursor/rules/_ag_swearing.mdc +0 -47
  37. package/.cursor/rules/ai_development_guide.md +0 -61
  38. package/.cursor/rules/ai_directives.md +0 -114
  39. package/.cursor/rules/cursor-rules.md +0 -160
  40. package/.cursor/rules/default-command.mdc +0 -465
  41. package/.cursor/rules/error_code_pattern.md +0 -40
  42. package/.cursor/rules/saved rule mcp server use.md +0 -16
  43. package/.dynamo/pipeline.cicd.config.json +0 -190
  44. package/.dynamo/version-bump.config.json +0 -5
  45. package/.github/workflows/main.yml +0 -438
  46. package/.husky/pre-commit +0 -3
  47. package/.vscode/settings.json +0 -11
  48. package/BuildPackage.bat +0 -1
  49. package/HOWTO.md +0 -15
  50. package/__documentations/2026-04-28-logs-module.md +0 -49
  51. package/__documentations/2026-05-17-oai-compatible-providers.md +0 -229
  52. package/__documentations/2026-05-17-static-client-serving-howto.md +0 -144
  53. package/__documentations/2026-06-01-fr041-cors-middleware.md +0 -96
  54. package/__documentations/2026-06-01-fr047-p2p3-function-calling.md +0 -81
  55. package/__documentations/2026-06-15-fr193-memory-guard.md +0 -73
  56. package/__documentations/2026-08-08-fr292-app-version-header.md +0 -38
  57. package/__documentations/2026-08-14-field-encryption-mongoose-document-spread.md +0 -124
  58. package/__documentations/2026-08-18-artifact-compiler.md +0 -46
  59. package/__documentations/2026-08-18-mongo-transaction-control-service.md +0 -82
  60. package/__documentations/2026-08-18-standalone-account-security-and-privacy-bedrock.md +0 -132
  61. package/__documentations/2026-08-21-distributed-rate-limit-bfr-ctm-010.md +0 -59
  62. package/__documentations/2026-08-22-bfr-ctm-018-content-free-endpoint-errors.md +0 -54
  63. package/__documentations/2026-08-22-bfr-ctm-020-content-free-request-telemetry.md +0 -65
  64. package/__documentations/2026-08-22-content-free-process-error-boundary.md +0 -111
  65. package/__documentations/2026-08-22-npm-token-state-classifier.md +0 -92
  66. package/__documentations/nts-integration-tests-2026-03-17.md +0 -26
  67. package/__documentations/plans/BEDROCK-HYPERPLAN.md +0 -95
  68. package/_specifications/BACKLOG.md +0 -92
  69. package/_specifications/TODO.md +0 -15
  70. package/_specifications/agent.md +0 -138
  71. package/eslint.config.js +0 -3
  72. package/nodemon.json +0 -24
  73. package/pnpm-workspace.yaml +0 -6
  74. package/scripts/_seed-out/aim-seed.fixtures.ts +0 -161
  75. package/scripts/_seed-out/image-raw.json +0 -1
  76. package/scripts/_seed-out/llm-expand-raw.json +0 -60
  77. package/scripts/_seed-out/sample-image.png +0 -0
  78. package/scripts/_seed-out/seed-raw.json +0 -153
  79. package/scripts/ai-fixture-seed.js +0 -126
  80. package/scripts/run-coverage-tests.js +0 -28
  81. package/spec/support/helpers/spec-reporter-loader.js +0 -359
  82. package/spec/support/helpers/ts-node-helper.js +0 -93
  83. package/spec/support/jasmine.coverage.json +0 -24
  84. package/spec/support/jasmine.json +0 -24
  85. package/src/_assets/dynamo-nts-logo-128.png +0 -0
  86. package/src/_assets/dynamo-nts-logo-256.png +0 -0
  87. package/src/_assets/dynamo-nts-logo-512.png +0 -0
  88. package/src/_assets/dynamo-nts-logo-64.png +0 -0
  89. package/src/_collections/app-version-header.util.spec.ts +0 -108
  90. package/src/_collections/app-version-header.util.ts +0 -74
  91. package/src/_collections/archive-service-registry.const.ts +0 -21
  92. package/src/_collections/archive.util.spec.ts +0 -57
  93. package/src/_collections/archive.util.ts +0 -18
  94. package/src/_collections/atlas-default-db-options.const.ts +0 -10
  95. package/src/_collections/client-safe-error.util.spec.ts +0 -151
  96. package/src/_collections/client-safe-error.util.ts +0 -107
  97. package/src/_collections/default-fallback-cache-max-age.const.spec.ts +0 -11
  98. package/src/_collections/default-fallback-cache-max-age.const.ts +0 -2
  99. package/src/_collections/default-not-found-page.const.spec.ts +0 -19
  100. package/src/_collections/default-not-found-page.const.ts +0 -22
  101. package/src/_collections/default-socket-path.const.spec.ts +0 -12
  102. package/src/_collections/default-socket-path.const.ts +0 -2
  103. package/src/_collections/field-encryption.util.spec.ts +0 -195
  104. package/src/_collections/field-encryption.util.ts +0 -222
  105. package/src/_collections/get-environment-settings.util.spec.ts +0 -210
  106. package/src/_collections/get-environment-settings.util.ts +0 -49
  107. package/src/_collections/global-settings.const.ts +0 -126
  108. package/src/_collections/load-shed.util.spec.ts +0 -62
  109. package/src/_collections/load-shed.util.ts +0 -51
  110. package/src/_collections/mongo-reconnect-guard.util.spec.ts +0 -52
  111. package/src/_collections/mongo-reconnect-guard.util.ts +0 -172
  112. package/src/_collections/npm-token-check.util.spec.ts +0 -218
  113. package/src/_collections/npm-token-check.util.ts +0 -327
  114. package/src/_collections/sample.env +0 -21
  115. package/src/_collections/security-headers.util.spec.ts +0 -98
  116. package/src/_collections/security-headers.util.ts +0 -96
  117. package/src/_collections/signed-url.util.spec.ts +0 -198
  118. package/src/_collections/signed-url.util.ts +0 -170
  119. package/src/_collections/star.controller.spec.ts +0 -224
  120. package/src/_collections/star.controller.ts +0 -130
  121. package/src/_collections/static-cache-control.util.spec.ts +0 -47
  122. package/src/_collections/static-cache-control.util.ts +0 -25
  123. package/src/_enums/data-model-type.enum.ts +0 -14
  124. package/src/_enums/data-service-function.enum.ts +0 -24
  125. package/src/_enums/predefined-data-types.enum.ts +0 -17
  126. package/src/_enums/route-security.enum.ts +0 -12
  127. package/src/_models/control-models/api-call-params.control-model.spec.ts +0 -152
  128. package/src/_models/control-models/api-call-params.control-model.ts +0 -142
  129. package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +0 -52
  130. package/src/_models/control-models/app-ext-system-controls.control-model.ts +0 -9
  131. package/src/_models/control-models/app-params.control-model.spec.ts +0 -229
  132. package/src/_models/control-models/app-params.control-model.ts +0 -137
  133. package/src/_models/control-models/app-system-controls.control-model.spec.ts +0 -31
  134. package/src/_models/control-models/app-system-controls.control-model.ts +0 -9
  135. package/src/_models/control-models/endpoint-params.control-model.spec.ts +0 -754
  136. package/src/_models/control-models/endpoint-params.control-model.ts +0 -575
  137. package/src/_models/control-models/http-settings.control-model.spec.ts +0 -77
  138. package/src/_models/control-models/http-settings.control-model.ts +0 -37
  139. package/src/_models/control-models/system-control.control-model.spec.ts +0 -27
  140. package/src/_models/control-models/system-control.control-model.ts +0 -12
  141. package/src/_models/data-models/schema-migration.data-model.ts +0 -50
  142. package/src/_models/interfaces/app-version-header-settings.interface.ts +0 -17
  143. package/src/_models/interfaces/certification-settings.interface.ts +0 -7
  144. package/src/_models/interfaces/compare-data-options.interface.ts +0 -27
  145. package/src/_models/interfaces/compare-data-result.interface.ts +0 -12
  146. package/src/_models/interfaces/cors-settings.interface.spec.ts +0 -52
  147. package/src/_models/interfaces/cors-settings.interface.ts +0 -56
  148. package/src/_models/interfaces/db-query-options.interface.ts +0 -33
  149. package/src/_models/interfaces/environment-settings.interface.ts +0 -59
  150. package/src/_models/interfaces/global-log-settings.interface.ts +0 -171
  151. package/src/_models/interfaces/global-service-settings.interface.ts +0 -47
  152. package/src/_models/interfaces/global-settings.interface.ts +0 -294
  153. package/src/_models/interfaces/migration-entry.interface.ts +0 -19
  154. package/src/_models/interfaces/mongo-transaction-settings.interface.ts +0 -9
  155. package/src/_models/interfaces/request-telemetry-settings.interface.ts +0 -9
  156. package/src/_models/interfaces/request-telemetry-snapshot.interface.ts +0 -30
  157. package/src/_models/interfaces/routing-module-settings.interface.ts +0 -21
  158. package/src/_models/interfaces/security-headers-settings.interface.ts +0 -50
  159. package/src/_models/interfaces/signed-url-verify-result.interface.ts +0 -13
  160. package/src/_models/interfaces/static-client-settings.interface.spec.ts +0 -29
  161. package/src/_models/interfaces/static-client-settings.interface.ts +0 -36
  162. package/src/_models/types/db-update.type.ts +0 -100
  163. package/src/_modules/account-security/_enums/account-challenge-purpose.type-enum.ts +0 -5
  164. package/src/_modules/account-security/_enums/account-refresh-token-state.type-enum.ts +0 -6
  165. package/src/_modules/account-security/_enums/account-session-state.type-enum.ts +0 -6
  166. package/src/_modules/account-security/_models/account-challenge-adapter.interface.ts +0 -17
  167. package/src/_modules/account-security/_models/account-challenge-issued.interface.ts +0 -6
  168. package/src/_modules/account-security/_models/account-challenge-record.interface.ts +0 -13
  169. package/src/_modules/account-security/_models/account-challenge-result.interface.ts +0 -8
  170. package/src/_modules/account-security/_models/account-challenge-settings.interface.ts +0 -9
  171. package/src/_modules/account-security/_models/account-password-policy.interface.ts +0 -11
  172. package/src/_modules/account-security/_models/account-password-verification.interface.ts +0 -5
  173. package/src/_modules/account-security/_models/account-refresh-token-record.interface.ts +0 -13
  174. package/src/_modules/account-security/_models/account-session-adapter.interface.ts +0 -19
  175. package/src/_modules/account-security/_models/account-session-claims.interface.ts +0 -7
  176. package/src/_modules/account-security/_models/account-session-context.interface.ts +0 -6
  177. package/src/_modules/account-security/_models/account-session-create.interface.ts +0 -8
  178. package/src/_modules/account-security/_models/account-session-record.interface.ts +0 -21
  179. package/src/_modules/account-security/_models/account-session-rotate.interface.ts +0 -11
  180. package/src/_modules/account-security/_models/account-session-settings.interface.ts +0 -11
  181. package/src/_modules/account-security/_models/account-session-token-pair.interface.ts +0 -8
  182. package/src/_modules/account-security/_models/account-session-view.interface.ts +0 -13
  183. package/src/_modules/account-security/account-challenge.control-service.spec.ts +0 -195
  184. package/src/_modules/account-security/account-challenge.control-service.ts +0 -164
  185. package/src/_modules/account-security/account-password.control-service.spec.ts +0 -96
  186. package/src/_modules/account-security/account-password.control-service.ts +0 -288
  187. package/src/_modules/account-security/account-session.control-service.spec.ts +0 -294
  188. package/src/_modules/account-security/account-session.control-service.ts +0 -376
  189. package/src/_modules/account-security/index.ts +0 -31
  190. package/src/_modules/admin-auth/_models/admin-api-key-config.interface.ts +0 -33
  191. package/src/_modules/admin-auth/admin-api-key.auth-service.spec.ts +0 -200
  192. package/src/_modules/admin-auth/admin-api-key.auth-service.ts +0 -220
  193. package/src/_modules/admin-auth/index.ts +0 -2
  194. package/src/_modules/ai/_collections/ai-model-config-validator.util.spec.ts +0 -150
  195. package/src/_modules/ai/_collections/ai-model-config-validator.util.ts +0 -131
  196. package/src/_modules/ai/_collections/ai-provider-error.util.ts +0 -144
  197. package/src/_modules/ai/_models/ai-input-interfaces.ts +0 -117
  198. package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +0 -16
  199. package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.ts +0 -14
  200. package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.ts +0 -56
  201. package/src/_modules/ai/_models/interfaces/dynts-ai-provider-error.interface.ts +0 -16
  202. package/src/_modules/ai/_modules/ai-mock/_collections/aim-default-collection.util.spec.ts +0 -72
  203. package/src/_modules/ai/_modules/ai-mock/_collections/aim-default-collection.util.ts +0 -71
  204. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-match.util.spec.ts +0 -57
  205. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-match.util.ts +0 -60
  206. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-serializer.util.spec.ts +0 -56
  207. package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-serializer.util.ts +0 -117
  208. package/src/_modules/ai/_modules/ai-mock/_enums/aim-modality.enum.ts +0 -28
  209. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-call-input.interface.ts +0 -14
  210. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-error.interface.ts +0 -11
  211. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-fixture.interface.ts +0 -30
  212. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-request.interface.ts +0 -19
  213. package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-service-collection.interface.ts +0 -20
  214. package/src/_modules/ai/_modules/ai-mock/_services/ai-embedding-mock.service.spec.ts +0 -115
  215. package/src/_modules/ai/_modules/ai-mock/_services/ai-embedding-mock.service.ts +0 -233
  216. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-harness.service.spec.ts +0 -134
  217. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-harness.service.ts +0 -127
  218. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-pipeline.spec.ts +0 -105
  219. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-store.service.spec.ts +0 -50
  220. package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-store.service.ts +0 -65
  221. package/src/_modules/ai/_modules/ai-mock/_services/aim-integration-proof.spec.ts +0 -92
  222. package/src/_modules/ai/_modules/ai-mock/_services/aim-mock.service.spec.ts +0 -112
  223. package/src/_modules/ai/_modules/ai-mock/_services/aim-mock.service.ts +0 -155
  224. package/src/_modules/ai/_modules/ai-mock/fixtures/aim-text.fixtures.ts +0 -649
  225. package/src/_modules/ai/_modules/ai-mock/index.ts +0 -47
  226. package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +0 -138
  227. package/src/_modules/ai/_modules/anthropic/index.ts +0 -5
  228. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +0 -242
  229. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.ts +0 -639
  230. package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.spec.ts +0 -295
  231. package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.ts +0 -552
  232. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +0 -209
  233. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.ts +0 -85
  234. package/src/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.ts +0 -8
  235. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.ts +0 -146
  236. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.ts +0 -163
  237. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.ts +0 -100
  238. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.ts +0 -68
  239. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.ts +0 -18
  240. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.ts +0 -19
  241. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.ts +0 -25
  242. package/src/_modules/ai/_modules/document-ai/index.ts +0 -30
  243. package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +0 -189
  244. package/src/_modules/ai/_modules/fdp-ai/index.ts +0 -5
  245. package/src/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.ts +0 -9
  246. package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +0 -83
  247. package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +0 -76
  248. package/src/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +0 -45
  249. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +0 -8
  250. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +0 -7
  251. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +0 -57
  252. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.ts +0 -293
  253. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.ts +0 -572
  254. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +0 -342
  255. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.ts +0 -435
  256. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +0 -550
  257. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.ts +0 -631
  258. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +0 -332
  259. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.ts +0 -132
  260. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +0 -462
  261. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +0 -635
  262. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +0 -489
  263. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.tools.spec.ts +0 -173
  264. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +0 -1085
  265. package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +0 -157
  266. package/src/_modules/ai/_modules/open-ai/index.ts +0 -74
  267. package/src/_modules/ai/_services/ai-embedding-provider.registry.spec.ts +0 -110
  268. package/src/_modules/ai/_services/ai-embedding-provider.registry.ts +0 -114
  269. package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +0 -98
  270. package/src/_modules/ai/_services/ai-embedding.service-base.ts +0 -48
  271. package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +0 -229
  272. package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +0 -68
  273. package/src/_modules/ai/_services/ai-llm.service-base.reconciler.spec.ts +0 -133
  274. package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +0 -250
  275. package/src/_modules/ai/_services/ai-llm.service-base.ts +0 -599
  276. package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +0 -158
  277. package/src/_modules/ai/_services/ai-provider.service-base.ts +0 -67
  278. package/src/_modules/ai/_services/ai-user-key.service-base.ts +0 -59
  279. package/src/_modules/ai/_services/lmstudio-embedding.control-service.spec.ts +0 -197
  280. package/src/_modules/ai/_services/lmstudio-embedding.control-service.ts +0 -399
  281. package/src/_modules/ai/index.ts +0 -33
  282. package/src/_modules/artifact-compiler/_enums/artifact-compile-outcome.type-enum.ts +0 -5
  283. package/src/_modules/artifact-compiler/_enums/artifact-compile-stage.type-enum.ts +0 -8
  284. package/src/_modules/artifact-compiler/_enums/artifact-retry-class.type-enum.ts +0 -6
  285. package/src/_modules/artifact-compiler/_models/artifact-compile.interface.ts +0 -35
  286. package/src/_modules/artifact-compiler/artifact-compiler.control-service.spec.ts +0 -151
  287. package/src/_modules/artifact-compiler/artifact-compiler.control-service.ts +0 -356
  288. package/src/_modules/artifact-compiler/index.ts +0 -9
  289. package/src/_modules/assistant/_collections/ass-global-settings.const.ts +0 -13
  290. package/src/_modules/assistant/_collections/ass.util.spec.ts +0 -176
  291. package/src/_modules/assistant/_collections/ass.util.ts +0 -50
  292. package/src/_modules/assistant/_models/ass-global-settings.interface.ts +0 -15
  293. package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +0 -140
  294. package/src/_modules/assistant/_services/ass-io.control-service.ts +0 -74
  295. package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +0 -192
  296. package/src/_modules/assistant/_services/ass-main.control-service.ts +0 -107
  297. package/src/_modules/assistant/index.ts +0 -19
  298. package/src/_modules/bot/_collections/bot-default-commands.const.ts +0 -12
  299. package/src/_modules/bot/_collections/bot-global-settings.const.ts +0 -39
  300. package/src/_modules/bot/_models/bot-channel-wrapper.interface.ts +0 -62
  301. package/src/_modules/bot/_models/bot-command.interface.ts +0 -8
  302. package/src/_modules/bot/_models/bot-global-settings.interface.ts +0 -96
  303. package/src/_modules/bot/_models/bot-last-mention-date.interface.ts +0 -6
  304. package/src/_modules/bot/_models/bot-last-message-date.interface.ts +0 -5
  305. package/src/_modules/bot/_models/bot-message-wrapper.interface.ts +0 -90
  306. package/src/_modules/bot/_models/bot-user-wrapper.interface.ts +0 -41
  307. package/src/_modules/bot/_modules/discord-bot/_models/dib-platform.types.ts +0 -10
  308. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +0 -431
  309. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.ts +0 -641
  310. package/src/_modules/bot/_modules/discord-bot/index.ts +0 -12
  311. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +0 -160
  312. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.ts +0 -55
  313. package/src/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.ts +0 -15
  314. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +0 -374
  315. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.ts +0 -447
  316. package/src/_modules/bot/_modules/dynamo-bot/index.ts +0 -15
  317. package/src/_modules/bot/_modules/slack-bot/_models/slb-platform.types.ts +0 -9
  318. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +0 -344
  319. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.ts +0 -197
  320. package/src/_modules/bot/_modules/slack-bot/index.ts +0 -12
  321. package/src/_modules/bot/_modules/teams-bot/_models/teb-platform.types.ts +0 -9
  322. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +0 -345
  323. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.ts +0 -197
  324. package/src/_modules/bot/_modules/teams-bot/index.ts +0 -11
  325. package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +0 -116
  326. package/src/_modules/bot/_services/bot-commands.control-service.ts +0 -158
  327. package/src/_modules/bot/_services/bot-io.control-service.spec.ts +0 -285
  328. package/src/_modules/bot/_services/bot-io.control-service.ts +0 -329
  329. package/src/_modules/bot/_services/bot-main.control-service.spec.ts +0 -208
  330. package/src/_modules/bot/_services/bot-main.control-service.ts +0 -489
  331. package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +0 -349
  332. package/src/_modules/bot/_services/bot-messaging-provider.service-base.ts +0 -158
  333. package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +0 -111
  334. package/src/_modules/bot/_services/bot-routines.control-service.ts +0 -78
  335. package/src/_modules/bot/index.ts +0 -37
  336. package/src/_modules/custom-data/custom-data.controller.spec.ts +0 -49
  337. package/src/_modules/custom-data/custom-data.controller.ts +0 -67
  338. package/src/_modules/custom-data/custom-data.data-service.spec.ts +0 -54
  339. package/src/_modules/custom-data/custom-data.data-service.ts +0 -22
  340. package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +0 -28
  341. package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +0 -24
  342. package/src/_modules/custom-data/index.ts +0 -9
  343. package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.spec.ts +0 -176
  344. package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.ts +0 -203
  345. package/src/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.ts +0 -33
  346. package/src/_modules/data-readers/index.ts +0 -11
  347. package/src/_modules/defaults/_collections/default-endpoints.util.ts +0 -487
  348. package/src/_modules/defaults/_models/default-user.data-model.ts +0 -72
  349. package/src/_modules/defaults/_services/default-auth.service.spec.ts +0 -269
  350. package/src/_modules/defaults/_services/default-auth.service.ts +0 -177
  351. package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +0 -42
  352. package/src/_modules/defaults/_services/default-socket-events.service.ts +0 -61
  353. package/src/_modules/defaults/_services/default-user.data-service.spec.ts +0 -187
  354. package/src/_modules/defaults/_services/default-user.data-service.ts +0 -98
  355. package/src/_modules/defaults/index.ts +0 -17
  356. package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +0 -19
  357. package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +0 -366
  358. package/src/_modules/discord-assistant/_collections/dias.util.ts +0 -133
  359. package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +0 -20
  360. package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +0 -53
  361. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +0 -177
  362. package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +0 -108
  363. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +0 -69
  364. package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +0 -22
  365. package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +0 -27
  366. package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +0 -195
  367. package/src/_modules/discord-assistant/_services/dias.service-base.ts +0 -77
  368. package/src/_modules/discord-assistant/index.ts +0 -38
  369. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +0 -34
  370. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +0 -11
  371. package/src/_modules/discord-assistant-voiced/index.ts +0 -36
  372. package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +0 -17
  373. package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +0 -56
  374. package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +0 -214
  375. package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +0 -387
  376. package/src/_modules/discord-bot/_models/dibo-command.interface.ts +0 -12
  377. package/src/_modules/discord-bot/_models/dibo-global-settings.interface.ts +0 -98
  378. package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +0 -8
  379. package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +0 -6
  380. package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +0 -154
  381. package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +0 -153
  382. package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +0 -264
  383. package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +0 -306
  384. package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +0 -408
  385. package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +0 -488
  386. package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +0 -105
  387. package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +0 -97
  388. package/src/_modules/discord-bot/index.ts +0 -36
  389. package/src/_modules/local-vector-search/_enums/lvs-search-mode.enum.ts +0 -35
  390. package/src/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.ts +0 -60
  391. package/src/_modules/local-vector-search/_models/lvs-search-result.interface.ts +0 -17
  392. package/src/_modules/local-vector-search/_services/lvs-bm25.util.spec.ts +0 -159
  393. package/src/_modules/local-vector-search/_services/lvs-bm25.util.ts +0 -206
  394. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +0 -418
  395. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.ts +0 -276
  396. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +0 -480
  397. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.ts +0 -416
  398. package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.spec.ts +0 -214
  399. package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.ts +0 -186
  400. package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.spec.ts +0 -167
  401. package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.ts +0 -130
  402. package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.ts +0 -509
  403. package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.ts +0 -323
  404. package/src/_modules/local-vector-search/index.ts +0 -17
  405. package/src/_modules/logs/_models/file-log-entry.interface.ts +0 -13
  406. package/src/_modules/logs/_models/file-log-read-result.interface.ts +0 -37
  407. package/src/_modules/logs/file-log.service.spec.ts +0 -341
  408. package/src/_modules/logs/file-log.service.ts +0 -466
  409. package/src/_modules/logs/file-logs.controller.spec.ts +0 -245
  410. package/src/_modules/logs/file-logs.controller.ts +0 -165
  411. package/src/_modules/logs/get-file-logs-routing-module.util.ts +0 -51
  412. package/src/_modules/logs/get-logs-routing-module.util.ts +0 -36
  413. package/src/_modules/logs/index.ts +0 -11
  414. package/src/_modules/logs/log-buffer.service.ts +0 -101
  415. package/src/_modules/logs/logs.controller.ts +0 -109
  416. package/src/_modules/logs/logs.service.ts +0 -100
  417. package/src/_modules/mcp/_models/interfaces/dynts-mcp.interface.ts +0 -111
  418. package/src/_modules/mcp/_services/dynts-mcp-server.service-base.spec.ts +0 -151
  419. package/src/_modules/mcp/_services/dynts-mcp-server.service-base.ts +0 -125
  420. package/src/_modules/mcp/_services/dynts-mcp.adapter.ts +0 -168
  421. package/src/_modules/mcp/index.ts +0 -13
  422. package/src/_modules/messaging/README.md +0 -354
  423. package/src/_modules/messaging/_collections/get-messaging-routing-module.util.ts +0 -26
  424. package/src/_modules/messaging/_collections/msg-global-settings.const.ts +0 -22
  425. package/src/_modules/messaging/_collections/msg.util.spec.ts +0 -226
  426. package/src/_modules/messaging/_collections/msg.util.ts +0 -83
  427. package/src/_modules/messaging/_models/msg-global-settings.interface.ts +0 -37
  428. package/src/_modules/messaging/_services/msg-conversation.data-service.ts +0 -146
  429. package/src/_modules/messaging/_services/msg-events.service.spec.ts +0 -219
  430. package/src/_modules/messaging/_services/msg-events.service.ts +0 -267
  431. package/src/_modules/messaging/_services/msg-integration.control-service.ts +0 -180
  432. package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +0 -147
  433. package/src/_modules/messaging/_services/msg-main.control-service.ts +0 -572
  434. package/src/_modules/messaging/_services/msg-message.data-service.ts +0 -129
  435. package/src/_modules/messaging/_services/msg.controller.spec.ts +0 -201
  436. package/src/_modules/messaging/_services/msg.controller.ts +0 -370
  437. package/src/_modules/messaging/index.ts +0 -30
  438. package/src/_modules/mock/app-extended-server.mock.ts +0 -201
  439. package/src/_modules/mock/app-integration-test.mock.ts +0 -51
  440. package/src/_modules/mock/app-params.mock.spec.ts +0 -21
  441. package/src/_modules/mock/app-params.mock.ts +0 -9
  442. package/src/_modules/mock/app-server.mock.ts +0 -188
  443. package/src/_modules/mock/auth-service.mock.spec.ts +0 -47
  444. package/src/_modules/mock/auth-service.mock.ts +0 -28
  445. package/src/_modules/mock/controller.mock.spec.ts +0 -26
  446. package/src/_modules/mock/controller.mock.ts +0 -16
  447. package/src/_modules/mock/data-model.mock.spec.ts +0 -111
  448. package/src/_modules/mock/data-model.mock.ts +0 -82
  449. package/src/_modules/mock/email-service-collection.mock.spec.ts +0 -24
  450. package/src/_modules/mock/email-service-collection.mock.ts +0 -15
  451. package/src/_modules/mock/email-service.mock.spec.ts +0 -17
  452. package/src/_modules/mock/email-service.mock.ts +0 -20
  453. package/src/_modules/mock/email-template.mock.html +0 -15
  454. package/src/_modules/mock/endpoint.mock.ts +0 -91
  455. package/src/_modules/mock/socket-client.mock.spec.ts +0 -40
  456. package/src/_modules/mock/socket-client.mock.ts +0 -45
  457. package/src/_modules/mock/socket-server.mock.spec.ts +0 -44
  458. package/src/_modules/mock/socket-server.mock.ts +0 -46
  459. package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +0 -107
  460. package/src/_modules/oauth2/_routes/oauth2.controller.ts +0 -99
  461. package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +0 -254
  462. package/src/_modules/oauth2/_services/oauth2.auth-service.ts +0 -232
  463. package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +0 -585
  464. package/src/_modules/oauth2/_services/oauth2.control-service.ts +0 -654
  465. package/src/_modules/oauth2/index.ts +0 -17
  466. package/src/_modules/privacy-lifecycle/_enums/privacy-consent-decision.type-enum.ts +0 -5
  467. package/src/_modules/privacy-lifecycle/_enums/privacy-contributor-action.type-enum.ts +0 -10
  468. package/src/_modules/privacy-lifecycle/_enums/privacy-contributor-outcome.type-enum.ts +0 -7
  469. package/src/_modules/privacy-lifecycle/_enums/privacy-request-state.type-enum.ts +0 -15
  470. package/src/_modules/privacy-lifecycle/_enums/privacy-request.type-enum.ts +0 -9
  471. package/src/_modules/privacy-lifecycle/_models/privacy-consent-input.interface.ts +0 -12
  472. package/src/_modules/privacy-lifecycle/_models/privacy-consent-persistence-result.interface.ts +0 -7
  473. package/src/_modules/privacy-lifecycle/_models/privacy-consent-record.interface.ts +0 -15
  474. package/src/_modules/privacy-lifecycle/_models/privacy-consent-result.interface.ts +0 -7
  475. package/src/_modules/privacy-lifecycle/_models/privacy-consent-view.interface.ts +0 -13
  476. package/src/_modules/privacy-lifecycle/_models/privacy-contributor-context.interface.ts +0 -9
  477. package/src/_modules/privacy-lifecycle/_models/privacy-contributor-outcome.interface.ts +0 -14
  478. package/src/_modules/privacy-lifecycle/_models/privacy-contributor-plan.interface.ts +0 -8
  479. package/src/_modules/privacy-lifecycle/_models/privacy-contributor.interface.ts +0 -17
  480. package/src/_modules/privacy-lifecycle/_models/privacy-ledger-adapter.interface.ts +0 -21
  481. package/src/_modules/privacy-lifecycle/_models/privacy-ledger-result.interface.ts +0 -9
  482. package/src/_modules/privacy-lifecycle/_models/privacy-ledger-settings.interface.ts +0 -7
  483. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-input.interface.ts +0 -10
  484. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-persistence-result.interface.ts +0 -7
  485. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-result.interface.ts +0 -7
  486. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-view.interface.ts +0 -11
  487. package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance.interface.ts +0 -13
  488. package/src/_modules/privacy-lifecycle/_models/privacy-lifecycle-adapter.interface.ts +0 -19
  489. package/src/_modules/privacy-lifecycle/_models/privacy-lifecycle-settings.interface.ts +0 -9
  490. package/src/_modules/privacy-lifecycle/_models/privacy-request-create-result.interface.ts +0 -7
  491. package/src/_modules/privacy-lifecycle/_models/privacy-request-open.interface.ts +0 -10
  492. package/src/_modules/privacy-lifecycle/_models/privacy-request-persistence-create-result.interface.ts +0 -7
  493. package/src/_modules/privacy-lifecycle/_models/privacy-request-record.interface.ts +0 -21
  494. package/src/_modules/privacy-lifecycle/_models/privacy-request-result.interface.ts +0 -8
  495. package/src/_modules/privacy-lifecycle/_models/privacy-request-view.interface.ts +0 -20
  496. package/src/_modules/privacy-lifecycle/index.ts +0 -40
  497. package/src/_modules/privacy-lifecycle/privacy-ledger.control-service.spec.ts +0 -206
  498. package/src/_modules/privacy-lifecycle/privacy-ledger.control-service.ts +0 -253
  499. package/src/_modules/privacy-lifecycle/privacy-lifecycle.control-service.spec.ts +0 -353
  500. package/src/_modules/privacy-lifecycle/privacy-lifecycle.control-service.ts +0 -586
  501. package/src/_modules/rate-limit/_enums/rate-limit-store-kind.type-enum.ts +0 -5
  502. package/src/_modules/rate-limit/_models/rate-limit-config.interface.ts +0 -82
  503. package/src/_modules/rate-limit/_models/rate-limit-consume-request.interface.ts +0 -9
  504. package/src/_modules/rate-limit/_models/rate-limit-consume-result.interface.ts +0 -6
  505. package/src/_modules/rate-limit/_models/rate-limit-policy.interface.ts +0 -16
  506. package/src/_modules/rate-limit/_models/rate-limit-store.interface.ts +0 -9
  507. package/src/_modules/rate-limit/index.ts +0 -8
  508. package/src/_modules/rate-limit/rate-limit-in-memory.store.ts +0 -91
  509. package/src/_modules/rate-limit/rate-limit.middleware.spec.ts +0 -488
  510. package/src/_modules/rate-limit/rate-limit.middleware.ts +0 -504
  511. package/src/_modules/scheduler/_models/scheduler-job.interface.ts +0 -35
  512. package/src/_modules/scheduler/get-scheduler-routing-module.util.ts +0 -33
  513. package/src/_modules/scheduler/index.ts +0 -8
  514. package/src/_modules/scheduler/scheduler.controller.spec.ts +0 -42
  515. package/src/_modules/scheduler/scheduler.controller.ts +0 -69
  516. package/src/_modules/scheduler/scheduler.service.spec.ts +0 -141
  517. package/src/_modules/scheduler/scheduler.service.ts +0 -176
  518. package/src/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.ts +0 -22
  519. package/src/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.ts +0 -82
  520. package/src/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.ts +0 -107
  521. package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.spec.ts +0 -312
  522. package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.ts +0 -311
  523. package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.spec.ts +0 -123
  524. package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.ts +0 -108
  525. package/src/_modules/scoped-config/index.ts +0 -17
  526. package/src/_modules/server/errors/errors.control-service.spec.ts +0 -246
  527. package/src/_modules/server/errors/errors.control-service.ts +0 -100
  528. package/src/_modules/server/errors/errors.controller.spec.ts +0 -340
  529. package/src/_modules/server/errors/errors.controller.ts +0 -559
  530. package/src/_modules/server/errors/errors.data-service.spec.ts +0 -480
  531. package/src/_modules/server/errors/errors.data-service.ts +0 -867
  532. package/src/_modules/server/index.ts +0 -40
  533. package/src/_modules/server/safe-diagnostic/safe-diagnostic-cause.type-enum.ts +0 -8
  534. package/src/_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum.ts +0 -20
  535. package/src/_modules/server/safe-diagnostic/safe-diagnostic.control-service.spec.ts +0 -124
  536. package/src/_modules/server/safe-diagnostic/safe-diagnostic.control-service.ts +0 -99
  537. package/src/_modules/server/safe-diagnostic/safe-diagnostic.interface.ts +0 -20
  538. package/src/_modules/server/server-status/db-readiness-probe-code.type-enum.ts +0 -13
  539. package/src/_modules/server/server-status/db-readiness-probe-stage.type-enum.ts +0 -7
  540. package/src/_modules/server/server-status/db-readiness-probe.control-service.spec.ts +0 -235
  541. package/src/_modules/server/server-status/db-readiness-probe.control-service.ts +0 -158
  542. package/src/_modules/server/server-status/db-readiness-probe.interface.ts +0 -20
  543. package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +0 -70
  544. package/src/_modules/server/server-status/server-status-snapshot.control-service.ts +0 -17
  545. package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +0 -77
  546. package/src/_modules/server/server-status/server-status-snapshot.data-service.ts +0 -37
  547. package/src/_modules/server/server-status/server-status.control-service.spec.ts +0 -672
  548. package/src/_modules/server/server-status/server-status.control-service.ts +0 -491
  549. package/src/_modules/server/server-status/server-status.controller.spec.ts +0 -276
  550. package/src/_modules/server/server-status/server-status.controller.ts +0 -336
  551. package/src/_modules/socket/_enums/socket-security.enum.ts +0 -11
  552. package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +0 -32
  553. package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +0 -22
  554. package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +0 -165
  555. package/src/_modules/socket/_models/socket-presence.control-model.ts +0 -211
  556. package/src/_modules/socket/_models/socket-server-service-params.control-model.spec.ts +0 -69
  557. package/src/_modules/socket/_models/socket-server-service-params.control-model.ts +0 -33
  558. package/src/_modules/socket/_services/socket-client.service.spec.ts +0 -15
  559. package/src/_modules/socket/_services/socket-client.service.ts +0 -260
  560. package/src/_modules/socket/_services/socket-server.service.spec.ts +0 -272
  561. package/src/_modules/socket/_services/socket-server.service.ts +0 -1037
  562. package/src/_modules/socket/app-extended.integration.spec.ts +0 -85
  563. package/src/_modules/socket/app-extended.server.ts +0 -648
  564. package/src/_modules/socket/index.ts +0 -42
  565. package/src/_modules/test/get-test-routing-module.util.spec.ts +0 -28
  566. package/src/_modules/test/get-test-routing-module.util.ts +0 -23
  567. package/src/_modules/test/index.ts +0 -12
  568. package/src/_modules/test/test.controller.spec.ts +0 -72
  569. package/src/_modules/test/test.controller.ts +0 -115
  570. package/src/_modules/test-email-sink/_collections/test-email-pattern.const.ts +0 -10
  571. package/src/_modules/test-email-sink/_models/data-models/dynts-sent-test-mail.data-model.ts +0 -41
  572. package/src/_modules/test-email-sink/_services/dynts-test-email-sink.service.spec.ts +0 -112
  573. package/src/_modules/test-email-sink/_services/dynts-test-email-sink.service.ts +0 -141
  574. package/src/_modules/test-email-sink/get-sent-mail-routing-module.util.ts +0 -29
  575. package/src/_modules/test-email-sink/index.ts +0 -11
  576. package/src/_modules/test-email-sink/test-email-sink.controller.ts +0 -83
  577. package/src/_modules/usage/get-usage-routing-module.util.ts +0 -23
  578. package/src/_modules/usage/index.ts +0 -15
  579. package/src/_modules/usage/usage.controller.spec.ts +0 -106
  580. package/src/_modules/usage/usage.controller.ts +0 -140
  581. package/src/_modules/usage/usage.data-service.spec.ts +0 -332
  582. package/src/_modules/usage/usage.data-service.ts +0 -185
  583. package/src/_services/base/api.service-base.spec.ts +0 -125
  584. package/src/_services/base/api.service-base.ts +0 -75
  585. package/src/_services/base/archive-data.service.spec.ts +0 -209
  586. package/src/_services/base/archive-data.service.ts +0 -228
  587. package/src/_services/base/data.service.spec.ts +0 -784
  588. package/src/_services/base/data.service.ts +0 -2792
  589. package/src/_services/base/db.service.encryption.spec.ts +0 -76
  590. package/src/_services/base/db.service.spec.ts +0 -160
  591. package/src/_services/base/db.service.ts +0 -1698
  592. package/src/_services/base/singleton.service-base.spec.ts +0 -28
  593. package/src/_services/base/singleton.service-base.ts +0 -24
  594. package/src/_services/base/singleton.service.spec.ts +0 -114
  595. package/src/_services/base/singleton.service.ts +0 -38
  596. package/src/_services/core/api.service.spec.ts +0 -187
  597. package/src/_services/core/api.service.ts +0 -627
  598. package/src/_services/core/auth.service.spec.ts +0 -159
  599. package/src/_services/core/auth.service.ts +0 -174
  600. package/src/_services/core/collection-growth-monitor.service.spec.ts +0 -119
  601. package/src/_services/core/collection-growth-monitor.service.ts +0 -234
  602. package/src/_services/core/db-stats.service.ts +0 -104
  603. package/src/_services/core/diagnostics.service.spec.ts +0 -44
  604. package/src/_services/core/diagnostics.service.ts +0 -158
  605. package/src/_services/core/email.service.spec.ts +0 -85
  606. package/src/_services/core/email.service.ts +0 -757
  607. package/src/_services/core/event-loop-diag.service.spec.ts +0 -22
  608. package/src/_services/core/event-loop-diag.service.ts +0 -144
  609. package/src/_services/core/global.service.spec.ts +0 -292
  610. package/src/_services/core/global.service.ts +0 -488
  611. package/src/_services/core/memory-guard.service.spec.ts +0 -245
  612. package/src/_services/core/memory-guard.service.ts +0 -481
  613. package/src/_services/core/migration-runner.service.spec.ts +0 -91
  614. package/src/_services/core/migration-runner.service.ts +0 -106
  615. package/src/_services/core/mongo-transaction.control-service.spec.ts +0 -165
  616. package/src/_services/core/mongo-transaction.control-service.ts +0 -148
  617. package/src/_services/core/request-hunter.service.spec.ts +0 -124
  618. package/src/_services/core/request-hunter.service.ts +0 -157
  619. package/src/_services/core/request-telemetry.control-service.spec.ts +0 -217
  620. package/src/_services/core/request-telemetry.control-service.ts +0 -381
  621. package/src/_services/core/service-collection.service.spec.ts +0 -46
  622. package/src/_services/core/service-collection.service.ts +0 -6
  623. package/src/_services/route/controller.service.spec.ts +0 -53
  624. package/src/_services/route/controller.service.ts +0 -148
  625. package/src/_services/route/routing-module.service.spec.ts +0 -98
  626. package/src/_services/route/routing-module.service.ts +0 -339
  627. package/src/_services/server/app-safe-diagnostic.spec.ts +0 -124
  628. package/src/_services/server/app.server-retention.spec.ts +0 -106
  629. package/src/_services/server/app.server.ts +0 -1979
  630. package/src/_services/shared.static-service.spec.ts +0 -133
  631. package/src/_services/shared.static-service.ts +0 -107
  632. package/src/index.ts +0 -120
  633. package/tsconfig.app.json +0 -12
  634. 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
- }