@futdevpro/nts-dynamo 1.15.64 → 1.15.68

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 (932) hide show
  1. package/.c8rc.json +26 -26
  2. package/.copilot/patterns.json +7 -7
  3. package/.cursor/rules/__assistant_guide.mdc +30 -30
  4. package/.cursor/rules/__main.mdc +64 -64
  5. package/.cursor/rules/_ag_backend-structure.mdc +85 -85
  6. package/.cursor/rules/_ag_backend.mdc +16 -16
  7. package/.cursor/rules/_ag_debug.mdc +7 -7
  8. package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -372
  9. package/.cursor/rules/_ag_file-refactoring.mdc +113 -113
  10. package/.cursor/rules/_ag_fixes_rules.mdc +5 -5
  11. package/.cursor/rules/_ag_frontend-structure.mdc +86 -86
  12. package/.cursor/rules/_ag_frontend.mdc +39 -39
  13. package/.cursor/rules/_ag_import-rules.mdc +44 -44
  14. package/.cursor/rules/_ag_naming.mdc +115 -115
  15. package/.cursor/rules/_ag_running_commands.mdc +4 -4
  16. package/.cursor/rules/_ag_server-controller.mdc +5 -5
  17. package/.cursor/rules/_ag_should-be.mdc +6 -6
  18. package/.cursor/rules/_ag_swearing.mdc +47 -47
  19. package/.cursor/rules/ai_development_guide.md +60 -60
  20. package/.cursor/rules/ai_directives.md +114 -114
  21. package/.cursor/rules/cursor-rules.md +160 -160
  22. package/.cursor/rules/default-command.mdc +464 -464
  23. package/.cursor/rules/error_code_pattern.md +39 -39
  24. package/.cursor/rules/saved rule mcp server use.md +15 -15
  25. package/.dynamo/pipeline.cicd.config.json +180 -180
  26. package/.dynamo/version-bump.config.json +5 -5
  27. package/.github/workflows/main.yml +438 -438
  28. package/.husky/pre-commit +3 -3
  29. package/.vscode/settings.json +10 -10
  30. package/HOWTO.md +15 -15
  31. package/LICENSE +21 -21
  32. package/README.md +678 -678
  33. package/__documentations/2026-04-28-logs-module.md +49 -49
  34. package/__documentations/2026-05-17-oai-compatible-providers.md +229 -229
  35. package/__documentations/2026-05-17-static-client-serving-howto.md +144 -144
  36. package/__documentations/2026-06-01-fr041-cors-middleware.md +96 -96
  37. package/__documentations/2026-06-01-fr047-p2p3-function-calling.md +81 -81
  38. package/__documentations/2026-06-15-fr193-memory-guard.md +73 -73
  39. package/__documentations/nts-integration-tests-2026-03-17.md +26 -26
  40. package/_specifications/BACKLOG.md +92 -92
  41. package/_specifications/TODO.md +15 -15
  42. package/_specifications/agent.md +138 -138
  43. package/build/_collections/archive.util.d.ts +12 -12
  44. package/build/_collections/archive.util.js +18 -18
  45. package/build/_collections/atlas-default-db-options.const.d.ts +2 -2
  46. package/build/_collections/atlas-default-db-options.const.js +9 -9
  47. package/build/_collections/default-fallback-cache-max-age.const.d.ts +2 -2
  48. package/build/_collections/default-fallback-cache-max-age.const.js +5 -5
  49. package/build/_collections/default-not-found-page.const.d.ts +5 -5
  50. package/build/_collections/default-not-found-page.const.js +24 -24
  51. package/build/_collections/default-socket-path.const.d.ts +2 -2
  52. package/build/_collections/default-socket-path.const.js +5 -5
  53. package/build/_collections/get-environment-settings.util.d.ts +2 -2
  54. package/build/_collections/get-environment-settings.util.js +43 -43
  55. package/build/_collections/global-settings.const.d.ts +6 -6
  56. package/build/_collections/global-settings.const.js +69 -69
  57. package/build/_collections/mongo-reconnect-guard.util.d.ts +73 -73
  58. package/build/_collections/mongo-reconnect-guard.util.js +110 -110
  59. package/build/_collections/star.controller.d.ts +7 -7
  60. package/build/_collections/star.controller.js +97 -97
  61. package/build/_enums/data-model-type.enum.d.ts +13 -13
  62. package/build/_enums/data-model-type.enum.js +17 -17
  63. package/build/_enums/data-service-function.enum.d.ts +18 -18
  64. package/build/_enums/data-service-function.enum.js +24 -24
  65. package/build/_enums/predefined-data-types.enum.d.ts +15 -15
  66. package/build/_enums/predefined-data-types.enum.js +19 -19
  67. package/build/_enums/route-security.enum.d.ts +11 -11
  68. package/build/_enums/route-security.enum.js +15 -15
  69. package/build/_models/control-models/api-call-params.control-model.d.ts +79 -79
  70. package/build/_models/control-models/api-call-params.control-model.js +101 -101
  71. package/build/_models/control-models/app-ext-system-controls.control-model.d.ts +6 -6
  72. package/build/_models/control-models/app-ext-system-controls.control-model.js +10 -10
  73. package/build/_models/control-models/app-params.control-model.d.ts +51 -51
  74. package/build/_models/control-models/app-params.control-model.js +119 -119
  75. package/build/_models/control-models/app-system-controls.control-model.d.ts +7 -7
  76. package/build/_models/control-models/app-system-controls.control-model.js +11 -11
  77. package/build/_models/control-models/endpoint-params.control-model.d.ts +114 -114
  78. package/build/_models/control-models/endpoint-params.control-model.js +442 -442
  79. package/build/_models/control-models/http-settings.control-model.d.ts +17 -17
  80. package/build/_models/control-models/http-settings.control-model.js +34 -34
  81. package/build/_models/control-models/system-control.control-model.d.ts +5 -5
  82. package/build/_models/control-models/system-control.control-model.js +11 -11
  83. package/build/_models/interfaces/certification-settings.interface.d.ts +5 -5
  84. package/build/_models/interfaces/certification-settings.interface.js +2 -2
  85. package/build/_models/interfaces/compare-data-options.interface.d.ts +26 -26
  86. package/build/_models/interfaces/compare-data-options.interface.js +2 -2
  87. package/build/_models/interfaces/compare-data-result.interface.d.ts +12 -12
  88. package/build/_models/interfaces/compare-data-result.interface.js +2 -2
  89. package/build/_models/interfaces/cors-settings.interface.d.ts +51 -51
  90. package/build/_models/interfaces/cors-settings.interface.js +2 -2
  91. package/build/_models/interfaces/environment-settings.interface.d.ts +34 -34
  92. package/build/_models/interfaces/environment-settings.interface.js +2 -2
  93. package/build/_models/interfaces/global-log-settings.interface.d.ts +145 -145
  94. package/build/_models/interfaces/global-log-settings.interface.js +2 -2
  95. package/build/_models/interfaces/global-service-settings.interface.d.ts +30 -30
  96. package/build/_models/interfaces/global-service-settings.interface.js +2 -2
  97. package/build/_models/interfaces/global-settings.interface.d.ts +161 -161
  98. package/build/_models/interfaces/global-settings.interface.js +2 -2
  99. package/build/_models/interfaces/routing-module-settings.interface.d.ts +19 -19
  100. package/build/_models/interfaces/routing-module-settings.interface.js +2 -2
  101. package/build/_models/interfaces/static-client-settings.interface.d.ts +28 -28
  102. package/build/_models/interfaces/static-client-settings.interface.js +2 -2
  103. package/build/_models/types/db-update.type.d.ts +129 -129
  104. package/build/_models/types/db-update.type.js +2 -2
  105. package/build/_modules/admin-auth/_models/admin-api-key-config.interface.d.ts +31 -31
  106. package/build/_modules/admin-auth/_models/admin-api-key-config.interface.js +2 -2
  107. package/build/_modules/admin-auth/admin-api-key.auth-service.d.ts +89 -89
  108. package/build/_modules/admin-auth/admin-api-key.auth-service.js +194 -194
  109. package/build/_modules/admin-auth/index.d.ts +2 -2
  110. package/build/_modules/admin-auth/index.js +5 -5
  111. package/build/_modules/ai/_models/ai-input-interfaces.d.ts +53 -53
  112. package/build/_modules/ai/_models/ai-input-interfaces.js +5 -5
  113. package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts +16 -16
  114. package/build/_modules/ai/_models/ai-test-generation-result.interface.js +2 -2
  115. package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.d.ts +13 -13
  116. package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.js +2 -2
  117. package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.d.ts +49 -49
  118. package/build/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.js +2 -2
  119. package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts +35 -35
  120. package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js +117 -117
  121. package/build/_modules/ai/_modules/anthropic/index.d.ts +2 -2
  122. package/build/_modules/ai/_modules/anthropic/index.js +7 -7
  123. package/build/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.d.ts +84 -84
  124. package/build/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.js +467 -467
  125. package/build/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.d.ts +109 -109
  126. package/build/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.js +418 -418
  127. package/build/_modules/ai/_modules/document-ai/_collections/dai-document.util.d.ts +28 -28
  128. package/build/_modules/ai/_modules/document-ai/_collections/dai-document.util.js +73 -73
  129. package/build/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.d.ts +6 -6
  130. package/build/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.js +10 -10
  131. package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.d.ts +51 -51
  132. package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.js +132 -132
  133. package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.d.ts +47 -47
  134. package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.js +136 -136
  135. package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.d.ts +17 -17
  136. package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.js +76 -76
  137. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.d.ts +49 -49
  138. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.js +2 -2
  139. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.d.ts +8 -8
  140. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.js +2 -2
  141. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.d.ts +11 -11
  142. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.js +2 -2
  143. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.d.ts +12 -12
  144. package/build/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.js +2 -2
  145. package/build/_modules/ai/_modules/document-ai/index.d.ts +12 -12
  146. package/build/_modules/ai/_modules/document-ai/index.js +27 -27
  147. package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts +34 -34
  148. package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js +128 -128
  149. package/build/_modules/ai/_modules/fdp-ai/index.d.ts +2 -2
  150. package/build/_modules/ai/_modules/fdp-ai/index.js +7 -7
  151. package/build/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.d.ts +2 -2
  152. package/build/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.js +8 -8
  153. package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts +2 -2
  154. package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js +74 -74
  155. package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts +2 -2
  156. package/build/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js +67 -67
  157. package/build/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.js +42 -42
  158. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts +5 -5
  159. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js +2 -2
  160. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js +6 -6
  161. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts +51 -51
  162. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js +2 -2
  163. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.d.ts +21 -21
  164. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.js +187 -187
  165. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.d.ts +26 -26
  166. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.js +278 -278
  167. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.d.ts +22 -22
  168. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.js +322 -322
  169. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.d.ts +119 -119
  170. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.js +480 -480
  171. package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.d.ts +25 -25
  172. package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.js +103 -103
  173. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +169 -169
  174. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js +479 -479
  175. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts +201 -201
  176. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js +579 -579
  177. package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts +39 -39
  178. package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js +110 -110
  179. package/build/_modules/ai/_modules/open-ai/index.d.ts +14 -14
  180. package/build/_modules/ai/_modules/open-ai/index.js +55 -55
  181. package/build/_modules/ai/_services/ai-embedding-mock.service.d.ts +80 -80
  182. package/build/_modules/ai/_services/ai-embedding-mock.service.js +166 -166
  183. package/build/_modules/ai/_services/ai-embedding-provider.registry.d.ts +51 -51
  184. package/build/_modules/ai/_services/ai-embedding-provider.registry.js +78 -78
  185. package/build/_modules/ai/_services/ai-embedding.service-base.d.ts +41 -41
  186. package/build/_modules/ai/_services/ai-embedding.service-base.js +11 -11
  187. package/build/_modules/ai/_services/ai-llm-chat.service-base.d.ts +39 -39
  188. package/build/_modules/ai/_services/ai-llm-chat.service-base.js +11 -11
  189. package/build/_modules/ai/_services/ai-llm.service-base.d.ts +132 -132
  190. package/build/_modules/ai/_services/ai-llm.service-base.js +313 -313
  191. package/build/_modules/ai/_services/ai-provider.service-base.d.ts +46 -46
  192. package/build/_modules/ai/_services/ai-provider.service-base.js +43 -43
  193. package/build/_modules/ai/_services/ai-user-key.service-base.d.ts +44 -44
  194. package/build/_modules/ai/_services/ai-user-key.service-base.js +14 -14
  195. package/build/_modules/ai/_services/lmstudio-embedding.control-service.d.ts +110 -110
  196. package/build/_modules/ai/_services/lmstudio-embedding.control-service.js +297 -297
  197. package/build/_modules/ai/index.d.ts +13 -13
  198. package/build/_modules/ai/index.js +22 -22
  199. package/build/_modules/assistant/_collections/ass-global-settings.const.d.ts +2 -2
  200. package/build/_modules/assistant/_collections/ass-global-settings.const.js +14 -14
  201. package/build/_modules/assistant/_collections/ass.util.d.ts +15 -15
  202. package/build/_modules/assistant/_collections/ass.util.js +42 -42
  203. package/build/_modules/assistant/_models/ass-global-settings.interface.d.ts +13 -13
  204. package/build/_modules/assistant/_models/ass-global-settings.interface.js +2 -2
  205. package/build/_modules/assistant/_services/ass-io.control-service.d.ts +19 -19
  206. package/build/_modules/assistant/_services/ass-io.control-service.js +57 -57
  207. package/build/_modules/assistant/_services/ass-main.control-service.d.ts +32 -32
  208. package/build/_modules/assistant/_services/ass-main.control-service.js +65 -65
  209. package/build/_modules/assistant/index.d.ts +6 -6
  210. package/build/_modules/assistant/index.js +18 -18
  211. package/build/_modules/bot/_collections/bot-default-commands.const.d.ts +2 -2
  212. package/build/_modules/bot/_collections/bot-default-commands.const.js +13 -13
  213. package/build/_modules/bot/_collections/bot-global-settings.const.d.ts +2 -2
  214. package/build/_modules/bot/_collections/bot-global-settings.const.js +31 -31
  215. package/build/_modules/bot/_models/bot-channel-wrapper.interface.d.ts +25 -25
  216. package/build/_modules/bot/_models/bot-channel-wrapper.interface.js +38 -38
  217. package/build/_modules/bot/_models/bot-command.interface.d.ts +7 -7
  218. package/build/_modules/bot/_models/bot-command.interface.js +2 -2
  219. package/build/_modules/bot/_models/bot-global-settings.interface.d.ts +85 -85
  220. package/build/_modules/bot/_models/bot-global-settings.interface.js +2 -2
  221. package/build/_modules/bot/_models/bot-last-mention-date.interface.d.ts +6 -6
  222. package/build/_modules/bot/_models/bot-last-mention-date.interface.js +2 -2
  223. package/build/_modules/bot/_models/bot-last-message-date.interface.d.ts +5 -5
  224. package/build/_modules/bot/_models/bot-last-message-date.interface.js +2 -2
  225. package/build/_modules/bot/_models/bot-message-wrapper.interface.d.ts +37 -37
  226. package/build/_modules/bot/_models/bot-message-wrapper.interface.js +54 -54
  227. package/build/_modules/bot/_models/bot-user-wrapper.interface.d.ts +23 -23
  228. package/build/_modules/bot/_models/bot-user-wrapper.interface.js +28 -28
  229. package/build/_modules/bot/_modules/discord-bot/_models/dib-platform.types.js +10 -10
  230. package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.d.ts +69 -69
  231. package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.js +497 -497
  232. package/build/_modules/bot/_modules/discord-bot/index.d.ts +1 -1
  233. package/build/_modules/bot/_modules/discord-bot/index.js +12 -12
  234. package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.d.ts +16 -16
  235. package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.js +42 -42
  236. package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.d.ts +9 -9
  237. package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.js +2 -2
  238. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.d.ts +59 -59
  239. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.js +349 -349
  240. package/build/_modules/bot/_modules/dynamo-bot/index.d.ts +3 -3
  241. package/build/_modules/bot/_modules/dynamo-bot/index.js +15 -15
  242. package/build/_modules/bot/_modules/slack-bot/_models/slb-platform.types.d.ts +6 -6
  243. package/build/_modules/bot/_modules/slack-bot/_models/slb-platform.types.js +2 -2
  244. package/build/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.d.ts +56 -56
  245. package/build/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.js +137 -137
  246. package/build/_modules/bot/_modules/slack-bot/index.d.ts +2 -2
  247. package/build/_modules/bot/_modules/slack-bot/index.js +12 -12
  248. package/build/_modules/bot/_modules/teams-bot/_models/teb-platform.types.d.ts +6 -6
  249. package/build/_modules/bot/_modules/teams-bot/_models/teb-platform.types.js +2 -2
  250. package/build/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.d.ts +56 -56
  251. package/build/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.js +137 -137
  252. package/build/_modules/bot/_modules/teams-bot/index.d.ts +2 -2
  253. package/build/_modules/bot/_modules/teams-bot/index.js +12 -12
  254. package/build/_modules/bot/_services/bot-commands.control-service.d.ts +12 -12
  255. package/build/_modules/bot/_services/bot-commands.control-service.js +117 -117
  256. package/build/_modules/bot/_services/bot-io.control-service.d.ts +23 -23
  257. package/build/_modules/bot/_services/bot-io.control-service.js +226 -226
  258. package/build/_modules/bot/_services/bot-main.control-service.d.ts +35 -35
  259. package/build/_modules/bot/_services/bot-main.control-service.js +195 -195
  260. package/build/_modules/bot/_services/bot-messaging-provider.service-base.d.ts +71 -71
  261. package/build/_modules/bot/_services/bot-messaging-provider.service-base.js +15 -15
  262. package/build/_modules/bot/_services/bot-routines.control-service.d.ts +13 -13
  263. package/build/_modules/bot/_services/bot-routines.control-service.js +59 -59
  264. package/build/_modules/bot/index.d.ts +17 -17
  265. package/build/_modules/bot/index.js +36 -36
  266. package/build/_modules/custom-data/custom-data.controller.d.ts +5 -5
  267. package/build/_modules/custom-data/custom-data.controller.js +56 -56
  268. package/build/_modules/custom-data/custom-data.data-service.d.ts +5 -5
  269. package/build/_modules/custom-data/custom-data.data-service.js +11 -11
  270. package/build/_modules/custom-data/get-custom-data-routing-module.util.d.ts +3 -3
  271. package/build/_modules/custom-data/get-custom-data-routing-module.util.js +16 -16
  272. package/build/_modules/custom-data/index.d.ts +4 -4
  273. package/build/_modules/custom-data/index.js +9 -9
  274. package/build/_modules/data-readers/_collections/dynts-sqlite-reader.util.d.ts +58 -58
  275. package/build/_modules/data-readers/_collections/dynts-sqlite-reader.util.js +168 -168
  276. package/build/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.d.ts +31 -31
  277. package/build/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.js +7 -7
  278. package/build/_modules/data-readers/index.d.ts +2 -2
  279. package/build/_modules/data-readers/index.js +10 -10
  280. package/build/_modules/defaults/_collections/default-endpoints.util.d.ts +248 -248
  281. package/build/_modules/defaults/_collections/default-endpoints.util.js +386 -386
  282. package/build/_modules/defaults/_models/default-user.data-model.d.ts +19 -19
  283. package/build/_modules/defaults/_models/default-user.data-model.js +72 -72
  284. package/build/_modules/defaults/_services/default-auth.service.d.ts +50 -50
  285. package/build/_modules/defaults/_services/default-auth.service.js +158 -158
  286. package/build/_modules/defaults/_services/default-socket-events.service.d.ts +23 -23
  287. package/build/_modules/defaults/_services/default-socket-events.service.js +60 -60
  288. package/build/_modules/defaults/_services/default-user.data-service.d.ts +24 -24
  289. package/build/_modules/defaults/_services/default-user.data-service.js +87 -87
  290. package/build/_modules/defaults/index.d.ts +5 -5
  291. package/build/_modules/defaults/index.js +17 -17
  292. package/build/_modules/discord-assistant/_collections/dias-global-settings.const.d.ts +2 -2
  293. package/build/_modules/discord-assistant/_collections/dias-global-settings.const.js +16 -16
  294. package/build/_modules/discord-assistant/_collections/dias.util.d.ts +31 -31
  295. package/build/_modules/discord-assistant/_collections/dias.util.js +85 -85
  296. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.d.ts +17 -17
  297. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js +2 -2
  298. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts +8 -8
  299. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js +46 -46
  300. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +17 -17
  301. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +123 -123
  302. package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts +10 -10
  303. package/build/_modules/discord-assistant/_services/dias-io.control-service.js +49 -49
  304. package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts +3 -3
  305. package/build/_modules/discord-assistant/_services/dias-main.control-service.js +7 -7
  306. package/build/_modules/discord-assistant/_services/dias.service-base.d.ts +18 -18
  307. package/build/_modules/discord-assistant/_services/dias.service-base.js +46 -46
  308. package/build/_modules/discord-assistant/index.d.ts +11 -11
  309. package/build/_modules/discord-assistant/index.js +24 -24
  310. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts +3 -3
  311. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js +7 -7
  312. package/build/_modules/discord-assistant-voiced/index.d.ts +2 -2
  313. package/build/_modules/discord-assistant-voiced/index.js +28 -28
  314. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts +2 -2
  315. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js +12 -12
  316. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts +2 -2
  317. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js +43 -43
  318. package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts +22 -22
  319. package/build/_modules/discord-bot/_collections/dibo-operations.util.js +275 -275
  320. package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts +7 -7
  321. package/build/_modules/discord-bot/_models/dibo-command.interface.js +2 -2
  322. package/build/_modules/discord-bot/_models/dibo-global-settings.interface.d.ts +87 -87
  323. package/build/_modules/discord-bot/_models/dibo-global-settings.interface.js +2 -2
  324. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts +6 -6
  325. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js +2 -2
  326. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts +5 -5
  327. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js +2 -2
  328. package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts +11 -11
  329. package/build/_modules/discord-bot/_services/dibo-commands.control-service.js +109 -109
  330. package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts +21 -21
  331. package/build/_modules/discord-bot/_services/dibo-io.control-service.js +218 -218
  332. package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts +89 -89
  333. package/build/_modules/discord-bot/_services/dibo-main.control-service.js +363 -363
  334. package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +13 -13
  335. package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +73 -73
  336. package/build/_modules/discord-bot/index.d.ts +11 -11
  337. package/build/_modules/discord-bot/index.js +30 -30
  338. package/build/_modules/local-vector-search/_enums/lvs-search-mode.enum.d.ts +34 -34
  339. package/build/_modules/local-vector-search/_enums/lvs-search-mode.enum.js +38 -38
  340. package/build/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.d.ts +35 -35
  341. package/build/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.js +53 -53
  342. package/build/_modules/local-vector-search/_models/lvs-search-result.interface.d.ts +16 -16
  343. package/build/_modules/local-vector-search/_models/lvs-search-result.interface.js +2 -2
  344. package/build/_modules/local-vector-search/_services/lvs-bm25.util.d.ts +88 -88
  345. package/build/_modules/local-vector-search/_services/lvs-bm25.util.js +189 -189
  346. package/build/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.d.ts +26 -26
  347. package/build/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.js +197 -197
  348. package/build/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.d.ts +145 -145
  349. package/build/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.js +294 -294
  350. package/build/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.d.ts +69 -69
  351. package/build/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.js +122 -122
  352. package/build/_modules/local-vector-search/_services/lvs-vector-persist.data-service.d.ts +42 -42
  353. package/build/_modules/local-vector-search/_services/lvs-vector-persist.data-service.js +71 -71
  354. package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.d.ts +70 -70
  355. package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.js +181 -181
  356. package/build/_modules/local-vector-search/index.d.ts +8 -8
  357. package/build/_modules/local-vector-search/index.js +15 -15
  358. package/build/_modules/logs/_models/file-log-entry.interface.d.ts +13 -13
  359. package/build/_modules/logs/_models/file-log-entry.interface.js +2 -2
  360. package/build/_modules/logs/_models/file-log-read-result.interface.d.ts +35 -35
  361. package/build/_modules/logs/_models/file-log-read-result.interface.js +2 -2
  362. package/build/_modules/logs/file-log.service.d.ts +132 -132
  363. package/build/_modules/logs/file-log.service.js +444 -444
  364. package/build/_modules/logs/file-logs.controller.d.ts +40 -40
  365. package/build/_modules/logs/file-logs.controller.js +138 -138
  366. package/build/_modules/logs/get-file-logs-routing-module.util.d.ts +31 -31
  367. package/build/_modules/logs/get-file-logs-routing-module.util.js +37 -37
  368. package/build/_modules/logs/get-logs-routing-module.util.d.ts +18 -18
  369. package/build/_modules/logs/get-logs-routing-module.util.js +31 -31
  370. package/build/_modules/logs/index.d.ts +8 -8
  371. package/build/_modules/logs/index.js +15 -15
  372. package/build/_modules/logs/log-buffer.service.d.ts +37 -37
  373. package/build/_modules/logs/log-buffer.service.js +96 -96
  374. package/build/_modules/logs/logs.controller.d.ts +26 -26
  375. package/build/_modules/logs/logs.controller.js +89 -89
  376. package/build/_modules/logs/logs.service.d.ts +39 -39
  377. package/build/_modules/logs/logs.service.js +96 -96
  378. package/build/_modules/mcp/_models/interfaces/dynts-mcp.interface.d.ts +108 -108
  379. package/build/_modules/mcp/_models/interfaces/dynts-mcp.interface.js +13 -13
  380. package/build/_modules/mcp/_services/dynts-mcp-server.service-base.d.ts +70 -70
  381. package/build/_modules/mcp/_services/dynts-mcp-server.service-base.js +98 -98
  382. package/build/_modules/mcp/_services/dynts-mcp.adapter.d.ts +56 -56
  383. package/build/_modules/mcp/_services/dynts-mcp.adapter.js +138 -138
  384. package/build/_modules/mcp/index.d.ts +3 -3
  385. package/build/_modules/mcp/index.js +12 -12
  386. package/build/_modules/messaging/_collections/get-messaging-routing-module.util.d.ts +7 -7
  387. package/build/_modules/messaging/_collections/get-messaging-routing-module.util.js +20 -20
  388. package/build/_modules/messaging/_collections/msg-global-settings.const.d.ts +5 -5
  389. package/build/_modules/messaging/_collections/msg-global-settings.const.js +22 -22
  390. package/build/_modules/messaging/_collections/msg.util.d.ts +24 -24
  391. package/build/_modules/messaging/_collections/msg.util.js +62 -62
  392. package/build/_modules/messaging/_models/msg-global-settings.interface.d.ts +28 -28
  393. package/build/_modules/messaging/_models/msg-global-settings.interface.js +2 -2
  394. package/build/_modules/messaging/_services/msg-conversation.data-service.d.ts +28 -28
  395. package/build/_modules/messaging/_services/msg-conversation.data-service.js +109 -109
  396. package/build/_modules/messaging/_services/msg-events.service.d.ts +61 -61
  397. package/build/_modules/messaging/_services/msg-events.service.js +203 -203
  398. package/build/_modules/messaging/_services/msg-integration.control-service.js +180 -180
  399. package/build/_modules/messaging/_services/msg-main.control-service.d.ts +62 -62
  400. package/build/_modules/messaging/_services/msg-main.control-service.js +428 -428
  401. package/build/_modules/messaging/_services/msg-message.data-service.d.ts +28 -28
  402. package/build/_modules/messaging/_services/msg-message.data-service.js +103 -103
  403. package/build/_modules/messaging/_services/msg.controller.d.ts +12 -12
  404. package/build/_modules/messaging/_services/msg.controller.js +256 -256
  405. package/build/_modules/messaging/index.d.ts +10 -10
  406. package/build/_modules/messaging/index.js +27 -27
  407. package/build/_modules/mock/app-extended-server.mock.d.ts +41 -41
  408. package/build/_modules/mock/app-extended-server.mock.js +169 -169
  409. package/build/_modules/mock/app-integration-test.mock.d.ts +19 -19
  410. package/build/_modules/mock/app-integration-test.mock.js +45 -45
  411. package/build/_modules/mock/app-params.mock.d.ts +2 -2
  412. package/build/_modules/mock/app-params.mock.js +9 -9
  413. package/build/_modules/mock/app-server.mock.d.ts +41 -41
  414. package/build/_modules/mock/app-server.mock.js +148 -148
  415. package/build/_modules/mock/auth-service.mock.d.ts +10 -10
  416. package/build/_modules/mock/auth-service.mock.js +19 -19
  417. package/build/_modules/mock/controller.mock.d.ts +5 -5
  418. package/build/_modules/mock/controller.mock.js +14 -14
  419. package/build/_modules/mock/data-model.mock.d.ts +26 -26
  420. package/build/_modules/mock/data-model.mock.js +72 -72
  421. package/build/_modules/mock/email-service-collection.mock.d.ts +7 -7
  422. package/build/_modules/mock/email-service-collection.mock.js +12 -12
  423. package/build/_modules/mock/email-service.mock.d.ts +4 -4
  424. package/build/_modules/mock/email-service.mock.js +20 -20
  425. package/build/_modules/mock/endpoint.mock.d.ts +8 -8
  426. package/build/_modules/mock/endpoint.mock.js +79 -79
  427. package/build/_modules/mock/socket-client.mock.d.ts +9 -9
  428. package/build/_modules/mock/socket-client.mock.js +38 -38
  429. package/build/_modules/mock/socket-server.mock.d.ts +15 -15
  430. package/build/_modules/mock/socket-server.mock.js +32 -32
  431. package/build/_modules/oauth2/_routes/oauth2.controller.d.ts +16 -16
  432. package/build/_modules/oauth2/_routes/oauth2.controller.js +96 -96
  433. package/build/_modules/oauth2/_services/oauth2.auth-service.d.ts +30 -30
  434. package/build/_modules/oauth2/_services/oauth2.auth-service.js +215 -215
  435. package/build/_modules/oauth2/_services/oauth2.control-service.d.ts +132 -132
  436. package/build/_modules/oauth2/_services/oauth2.control-service.js +576 -576
  437. package/build/_modules/oauth2/index.d.ts +3 -3
  438. package/build/_modules/oauth2/index.js +14 -14
  439. package/build/_modules/rate-limit/_models/rate-limit-config.interface.d.ts +61 -61
  440. package/build/_modules/rate-limit/_models/rate-limit-config.interface.js +2 -2
  441. package/build/_modules/rate-limit/_models/rate-limit-policy.interface.d.ts +15 -15
  442. package/build/_modules/rate-limit/_models/rate-limit-policy.interface.js +2 -2
  443. package/build/_modules/rate-limit/index.d.ts +3 -3
  444. package/build/_modules/rate-limit/index.js +5 -5
  445. package/build/_modules/rate-limit/rate-limit.middleware.d.ts +132 -132
  446. package/build/_modules/rate-limit/rate-limit.middleware.js +289 -289
  447. package/build/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.d.ts +18 -18
  448. package/build/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.js +22 -22
  449. package/build/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.d.ts +43 -43
  450. package/build/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.js +67 -67
  451. package/build/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.d.ts +88 -88
  452. package/build/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.js +11 -11
  453. package/build/_modules/scoped-config/_services/dynts-scoped-config.control-service.d.ts +83 -83
  454. package/build/_modules/scoped-config/_services/dynts-scoped-config.control-service.js +219 -219
  455. package/build/_modules/scoped-config/_services/dynts-scoped-config.data-service.d.ts +53 -53
  456. package/build/_modules/scoped-config/_services/dynts-scoped-config.data-service.js +75 -75
  457. package/build/_modules/scoped-config/index.d.ts +5 -5
  458. package/build/_modules/scoped-config/index.js +14 -14
  459. package/build/_modules/server/errors/errors.control-service.d.ts +21 -19
  460. package/build/_modules/server/errors/errors.control-service.d.ts.map +1 -1
  461. package/build/_modules/server/errors/errors.control-service.js +10 -10
  462. package/build/_modules/server/errors/errors.control-service.js.map +1 -1
  463. package/build/_modules/server/errors/errors.controller.d.ts +100 -99
  464. package/build/_modules/server/errors/errors.controller.d.ts.map +1 -1
  465. package/build/_modules/server/errors/errors.controller.js +355 -313
  466. package/build/_modules/server/errors/errors.controller.js.map +1 -1
  467. package/build/_modules/server/errors/errors.data-service.d.ts +64 -47
  468. package/build/_modules/server/errors/errors.data-service.d.ts.map +1 -1
  469. package/build/_modules/server/errors/errors.data-service.js +628 -552
  470. package/build/_modules/server/errors/errors.data-service.js.map +1 -1
  471. package/build/_modules/server/index.d.ts +7 -7
  472. package/build/_modules/server/index.js +26 -26
  473. package/build/_modules/server/server-status/server-status-snapshot.control-service.d.ts +4 -4
  474. package/build/_modules/server/server-status/server-status-snapshot.control-service.js +7 -7
  475. package/build/_modules/server/server-status/server-status-snapshot.data-service.d.ts +6 -6
  476. package/build/_modules/server/server-status/server-status-snapshot.data-service.js +22 -22
  477. package/build/_modules/server/server-status/server-status.control-service.d.ts +74 -74
  478. package/build/_modules/server/server-status/server-status.control-service.js +234 -234
  479. package/build/_modules/server/server-status/server-status.controller.d.ts +84 -84
  480. package/build/_modules/server/server-status/server-status.controller.js +172 -172
  481. package/build/_modules/socket/_enums/socket-security.enum.d.ts +10 -10
  482. package/build/_modules/socket/_enums/socket-security.enum.js +14 -14
  483. package/build/_modules/socket/_models/socket-client-service-params.control-model.d.ts +8 -8
  484. package/build/_modules/socket/_models/socket-client-service-params.control-model.js +16 -16
  485. package/build/_modules/socket/_models/socket-presence.control-model.d.ts +25 -25
  486. package/build/_modules/socket/_models/socket-presence.control-model.js +139 -139
  487. package/build/_modules/socket/_models/socket-server-service-params.control-model.d.ts +12 -12
  488. package/build/_modules/socket/_models/socket-server-service-params.control-model.js +20 -20
  489. package/build/_modules/socket/_services/socket-client.service.d.ts +37 -37
  490. package/build/_modules/socket/_services/socket-client.service.js +196 -196
  491. package/build/_modules/socket/_services/socket-server.service.d.ts +94 -94
  492. package/build/_modules/socket/_services/socket-server.service.js +689 -689
  493. package/build/_modules/socket/app-extended.server.d.ts +145 -145
  494. package/build/_modules/socket/app-extended.server.js +506 -506
  495. package/build/_modules/socket/index.d.ts +8 -8
  496. package/build/_modules/socket/index.js +35 -35
  497. package/build/_modules/test/get-test-routing-module.util.d.ts +3 -3
  498. package/build/_modules/test/get-test-routing-module.util.js +16 -16
  499. package/build/_modules/test/index.d.ts +3 -3
  500. package/build/_modules/test/index.js +11 -11
  501. package/build/_modules/test/test.controller.d.ts +5 -5
  502. package/build/_modules/test/test.controller.js +103 -103
  503. package/build/_modules/usage/get-usage-routing-module.util.d.ts +3 -3
  504. package/build/_modules/usage/get-usage-routing-module.util.js +16 -16
  505. package/build/_modules/usage/index.d.ts +4 -4
  506. package/build/_modules/usage/index.js +13 -13
  507. package/build/_modules/usage/usage.controller.d.ts +6 -6
  508. package/build/_modules/usage/usage.controller.js +95 -95
  509. package/build/_modules/usage/usage.data-service.d.ts +17 -17
  510. package/build/_modules/usage/usage.data-service.js +135 -135
  511. package/build/_services/base/api.service-base.d.ts +9 -9
  512. package/build/_services/base/api.service-base.js +46 -46
  513. package/build/_services/base/archive-data.service.d.ts +25 -25
  514. package/build/_services/base/archive-data.service.js +140 -140
  515. package/build/_services/base/data.service.d.ts +381 -381
  516. package/build/_services/base/data.service.js +2068 -2068
  517. package/build/_services/base/db.service.d.ts +393 -393
  518. package/build/_services/base/db.service.js +1256 -1256
  519. package/build/_services/base/singleton.service-base.d.ts +8 -8
  520. package/build/_services/base/singleton.service-base.js +21 -21
  521. package/build/_services/base/singleton.service.d.ts +11 -11
  522. package/build/_services/base/singleton.service.js +31 -31
  523. package/build/_services/core/api.service.d.ts +45 -45
  524. package/build/_services/core/api.service.js +436 -436
  525. package/build/_services/core/auth.service.d.ts +129 -129
  526. package/build/_services/core/auth.service.js +59 -59
  527. package/build/_services/core/email.service.d.ts +77 -77
  528. package/build/_services/core/email.service.js +489 -489
  529. package/build/_services/core/global.service.d.ts +76 -76
  530. package/build/_services/core/global.service.js +370 -370
  531. package/build/_services/core/memory-guard.service.d.ts +110 -110
  532. package/build/_services/core/memory-guard.service.js +197 -197
  533. package/build/_services/core/service-collection.service.d.ts +4 -4
  534. package/build/_services/core/service-collection.service.js +7 -7
  535. package/build/_services/route/controller.service.d.ts +124 -124
  536. package/build/_services/route/controller.service.js +95 -95
  537. package/build/_services/route/routing-module.service.d.ts +80 -80
  538. package/build/_services/route/routing-module.service.js +250 -250
  539. package/build/_services/server/app.server.d.ts +352 -352
  540. package/build/_services/server/app.server.js +1323 -1323
  541. package/build/_services/shared.static-service.d.ts +36 -36
  542. package/build/_services/shared.static-service.js +72 -72
  543. package/build/index.d.ts +43 -43
  544. package/build/index.js +80 -80
  545. package/eslint.config.js +3 -3
  546. package/nodemon.json +24 -24
  547. package/package.json +416 -417
  548. package/pnpm-workspace.yaml +5 -5
  549. package/scripts/run-coverage-tests.js +28 -28
  550. package/spec/support/helpers/spec-reporter-loader.js +359 -359
  551. package/spec/support/helpers/ts-node-helper.js +93 -93
  552. package/spec/support/jasmine.coverage.json +24 -24
  553. package/spec/support/jasmine.json +24 -24
  554. package/src/_collections/archive.util.spec.ts +57 -57
  555. package/src/_collections/archive.util.ts +18 -18
  556. package/src/_collections/atlas-default-db-options.const.ts +9 -9
  557. package/src/_collections/default-fallback-cache-max-age.const.spec.ts +11 -11
  558. package/src/_collections/default-fallback-cache-max-age.const.ts +2 -2
  559. package/src/_collections/default-not-found-page.const.spec.ts +19 -19
  560. package/src/_collections/default-not-found-page.const.ts +22 -22
  561. package/src/_collections/default-socket-path.const.spec.ts +12 -12
  562. package/src/_collections/default-socket-path.const.ts +2 -2
  563. package/src/_collections/get-environment-settings.util.spec.ts +210 -210
  564. package/src/_collections/get-environment-settings.util.ts +48 -48
  565. package/src/_collections/global-settings.const.ts +89 -89
  566. package/src/_collections/mongo-reconnect-guard.util.spec.ts +52 -52
  567. package/src/_collections/mongo-reconnect-guard.util.ts +172 -172
  568. package/src/_collections/sample.env +21 -21
  569. package/src/_collections/star.controller.spec.ts +224 -224
  570. package/src/_collections/star.controller.ts +129 -129
  571. package/src/_enums/data-model-type.enum.ts +14 -14
  572. package/src/_enums/data-service-function.enum.ts +24 -24
  573. package/src/_enums/predefined-data-types.enum.ts +16 -16
  574. package/src/_enums/route-security.enum.ts +12 -12
  575. package/src/_models/control-models/api-call-params.control-model.spec.ts +152 -152
  576. package/src/_models/control-models/api-call-params.control-model.ts +142 -142
  577. package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -52
  578. package/src/_models/control-models/app-ext-system-controls.control-model.ts +9 -9
  579. package/src/_models/control-models/app-params.control-model.spec.ts +225 -225
  580. package/src/_models/control-models/app-params.control-model.ts +136 -136
  581. package/src/_models/control-models/app-system-controls.control-model.spec.ts +31 -31
  582. package/src/_models/control-models/app-system-controls.control-model.ts +9 -9
  583. package/src/_models/control-models/endpoint-params.control-model.spec.ts +627 -627
  584. package/src/_models/control-models/endpoint-params.control-model.ts +627 -627
  585. package/src/_models/control-models/http-settings.control-model.spec.ts +77 -77
  586. package/src/_models/control-models/http-settings.control-model.ts +37 -37
  587. package/src/_models/control-models/system-control.control-model.spec.ts +27 -27
  588. package/src/_models/control-models/system-control.control-model.ts +12 -12
  589. package/src/_models/interfaces/certification-settings.interface.ts +7 -7
  590. package/src/_models/interfaces/compare-data-options.interface.ts +27 -27
  591. package/src/_models/interfaces/compare-data-result.interface.ts +12 -12
  592. package/src/_models/interfaces/cors-settings.interface.spec.ts +52 -52
  593. package/src/_models/interfaces/cors-settings.interface.ts +56 -56
  594. package/src/_models/interfaces/environment-settings.interface.ts +59 -59
  595. package/src/_models/interfaces/global-log-settings.interface.ts +171 -171
  596. package/src/_models/interfaces/global-service-settings.interface.ts +47 -47
  597. package/src/_models/interfaces/global-settings.interface.ts +185 -185
  598. package/src/_models/interfaces/routing-module-settings.interface.ts +21 -21
  599. package/src/_models/interfaces/static-client-settings.interface.spec.ts +29 -29
  600. package/src/_models/interfaces/static-client-settings.interface.ts +28 -28
  601. package/src/_models/types/db-update.type.ts +100 -100
  602. package/src/_modules/admin-auth/_models/admin-api-key-config.interface.ts +33 -33
  603. package/src/_modules/admin-auth/admin-api-key.auth-service.spec.ts +200 -200
  604. package/src/_modules/admin-auth/admin-api-key.auth-service.ts +220 -220
  605. package/src/_modules/admin-auth/index.ts +2 -2
  606. package/src/_modules/ai/_models/ai-input-interfaces.ts +117 -117
  607. package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +16 -16
  608. package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.ts +14 -14
  609. package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.ts +56 -56
  610. package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +138 -138
  611. package/src/_modules/ai/_modules/anthropic/index.ts +5 -5
  612. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -242
  613. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.ts +639 -639
  614. package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.spec.ts +295 -295
  615. package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.ts +552 -552
  616. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -209
  617. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.ts +85 -85
  618. package/src/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.ts +7 -7
  619. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.ts +146 -146
  620. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.ts +162 -162
  621. package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.ts +99 -99
  622. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.ts +68 -68
  623. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.ts +18 -18
  624. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.ts +19 -19
  625. package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.ts +25 -25
  626. package/src/_modules/ai/_modules/document-ai/index.ts +30 -30
  627. package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +189 -189
  628. package/src/_modules/ai/_modules/fdp-ai/index.ts +5 -5
  629. package/src/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.ts +9 -9
  630. package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +82 -82
  631. package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +75 -75
  632. package/src/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +45 -45
  633. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +7 -7
  634. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +7 -7
  635. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +57 -57
  636. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.ts +292 -292
  637. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.ts +572 -572
  638. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -342
  639. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.ts +435 -435
  640. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -550
  641. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.ts +630 -630
  642. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +332 -332
  643. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.ts +132 -132
  644. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -462
  645. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +634 -634
  646. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +489 -489
  647. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.tools.spec.ts +173 -173
  648. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +1033 -1033
  649. package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +157 -157
  650. package/src/_modules/ai/_modules/open-ai/index.ts +74 -74
  651. package/src/_modules/ai/_services/ai-embedding-mock.service.spec.ts +115 -115
  652. package/src/_modules/ai/_services/ai-embedding-mock.service.ts +233 -233
  653. package/src/_modules/ai/_services/ai-embedding-provider.registry.spec.ts +110 -110
  654. package/src/_modules/ai/_services/ai-embedding-provider.registry.ts +114 -114
  655. package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -98
  656. package/src/_modules/ai/_services/ai-embedding.service-base.ts +48 -48
  657. package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -229
  658. package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +68 -68
  659. package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -250
  660. package/src/_modules/ai/_services/ai-llm.service-base.ts +519 -519
  661. package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +158 -158
  662. package/src/_modules/ai/_services/ai-provider.service-base.ts +67 -67
  663. package/src/_modules/ai/_services/ai-user-key.service-base.ts +59 -59
  664. package/src/_modules/ai/_services/lmstudio-embedding.control-service.spec.ts +197 -197
  665. package/src/_modules/ai/_services/lmstudio-embedding.control-service.ts +399 -399
  666. package/src/_modules/ai/index.ts +23 -23
  667. package/src/_modules/assistant/_collections/ass-global-settings.const.ts +13 -13
  668. package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -176
  669. package/src/_modules/assistant/_collections/ass.util.ts +50 -50
  670. package/src/_modules/assistant/_models/ass-global-settings.interface.ts +15 -15
  671. package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -140
  672. package/src/_modules/assistant/_services/ass-io.control-service.ts +74 -74
  673. package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -192
  674. package/src/_modules/assistant/_services/ass-main.control-service.ts +107 -107
  675. package/src/_modules/assistant/index.ts +19 -19
  676. package/src/_modules/bot/_collections/bot-default-commands.const.ts +12 -12
  677. package/src/_modules/bot/_collections/bot-global-settings.const.ts +39 -39
  678. package/src/_modules/bot/_models/bot-channel-wrapper.interface.ts +62 -62
  679. package/src/_modules/bot/_models/bot-command.interface.ts +8 -8
  680. package/src/_modules/bot/_models/bot-global-settings.interface.ts +96 -96
  681. package/src/_modules/bot/_models/bot-last-mention-date.interface.ts +6 -6
  682. package/src/_modules/bot/_models/bot-last-message-date.interface.ts +5 -5
  683. package/src/_modules/bot/_models/bot-message-wrapper.interface.ts +90 -90
  684. package/src/_modules/bot/_models/bot-user-wrapper.interface.ts +41 -41
  685. package/src/_modules/bot/_modules/discord-bot/_models/dib-platform.types.ts +9 -9
  686. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -431
  687. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.ts +641 -641
  688. package/src/_modules/bot/_modules/discord-bot/index.ts +12 -12
  689. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -160
  690. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.ts +55 -55
  691. package/src/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.ts +15 -15
  692. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -374
  693. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.ts +447 -447
  694. package/src/_modules/bot/_modules/dynamo-bot/index.ts +15 -15
  695. package/src/_modules/bot/_modules/slack-bot/_models/slb-platform.types.ts +9 -9
  696. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -344
  697. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.ts +197 -197
  698. package/src/_modules/bot/_modules/slack-bot/index.ts +12 -12
  699. package/src/_modules/bot/_modules/teams-bot/_models/teb-platform.types.ts +9 -9
  700. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -345
  701. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.ts +197 -197
  702. package/src/_modules/bot/_modules/teams-bot/index.ts +11 -11
  703. package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -116
  704. package/src/_modules/bot/_services/bot-commands.control-service.ts +158 -158
  705. package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -285
  706. package/src/_modules/bot/_services/bot-io.control-service.ts +329 -329
  707. package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -208
  708. package/src/_modules/bot/_services/bot-main.control-service.ts +489 -489
  709. package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -349
  710. package/src/_modules/bot/_services/bot-messaging-provider.service-base.ts +158 -158
  711. package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -111
  712. package/src/_modules/bot/_services/bot-routines.control-service.ts +78 -78
  713. package/src/_modules/bot/index.ts +37 -37
  714. package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -49
  715. package/src/_modules/custom-data/custom-data.controller.ts +67 -67
  716. package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -54
  717. package/src/_modules/custom-data/custom-data.data-service.ts +21 -21
  718. package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -28
  719. package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +24 -24
  720. package/src/_modules/custom-data/index.ts +9 -9
  721. package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.spec.ts +176 -176
  722. package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.ts +203 -203
  723. package/src/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.ts +33 -33
  724. package/src/_modules/data-readers/index.ts +11 -11
  725. package/src/_modules/defaults/_collections/default-endpoints.util.ts +487 -487
  726. package/src/_modules/defaults/_models/default-user.data-model.ts +72 -72
  727. package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -269
  728. package/src/_modules/defaults/_services/default-auth.service.ts +177 -177
  729. package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -42
  730. package/src/_modules/defaults/_services/default-socket-events.service.ts +61 -61
  731. package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -187
  732. package/src/_modules/defaults/_services/default-user.data-service.ts +98 -98
  733. package/src/_modules/defaults/index.ts +17 -17
  734. package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +19 -19
  735. package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -366
  736. package/src/_modules/discord-assistant/_collections/dias.util.ts +132 -132
  737. package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +19 -19
  738. package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +52 -52
  739. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +177 -177
  740. package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -108
  741. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +69 -69
  742. package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -22
  743. package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +27 -27
  744. package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -195
  745. package/src/_modules/discord-assistant/_services/dias.service-base.ts +76 -76
  746. package/src/_modules/discord-assistant/index.ts +38 -38
  747. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -34
  748. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +11 -11
  749. package/src/_modules/discord-assistant-voiced/index.ts +36 -36
  750. package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +16 -16
  751. package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +55 -55
  752. package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -214
  753. package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +387 -387
  754. package/src/_modules/discord-bot/_models/dibo-command.interface.ts +12 -12
  755. package/src/_modules/discord-bot/_models/dibo-global-settings.interface.ts +98 -98
  756. package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +7 -7
  757. package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +6 -6
  758. package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -154
  759. package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +153 -153
  760. package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -264
  761. package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +306 -306
  762. package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -408
  763. package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +487 -487
  764. package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -105
  765. package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +97 -97
  766. package/src/_modules/discord-bot/index.ts +36 -36
  767. package/src/_modules/local-vector-search/_enums/lvs-search-mode.enum.ts +35 -35
  768. package/src/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.ts +60 -60
  769. package/src/_modules/local-vector-search/_models/lvs-search-result.interface.ts +17 -17
  770. package/src/_modules/local-vector-search/_services/lvs-bm25.util.spec.ts +159 -159
  771. package/src/_modules/local-vector-search/_services/lvs-bm25.util.ts +206 -206
  772. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -418
  773. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.ts +276 -276
  774. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +480 -480
  775. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.ts +416 -416
  776. package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.spec.ts +198 -198
  777. package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.ts +150 -150
  778. package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.spec.ts +167 -167
  779. package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.ts +108 -108
  780. package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.ts +393 -393
  781. package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.ts +220 -220
  782. package/src/_modules/local-vector-search/index.ts +16 -16
  783. package/src/_modules/logs/_models/file-log-entry.interface.ts +13 -13
  784. package/src/_modules/logs/_models/file-log-read-result.interface.ts +37 -37
  785. package/src/_modules/logs/file-log.service.spec.ts +341 -341
  786. package/src/_modules/logs/file-log.service.ts +466 -466
  787. package/src/_modules/logs/file-logs.controller.spec.ts +245 -245
  788. package/src/_modules/logs/file-logs.controller.ts +165 -165
  789. package/src/_modules/logs/get-file-logs-routing-module.util.ts +51 -51
  790. package/src/_modules/logs/get-logs-routing-module.util.ts +36 -36
  791. package/src/_modules/logs/index.ts +11 -11
  792. package/src/_modules/logs/log-buffer.service.ts +101 -101
  793. package/src/_modules/logs/logs.controller.ts +109 -109
  794. package/src/_modules/logs/logs.service.ts +100 -100
  795. package/src/_modules/mcp/_models/interfaces/dynts-mcp.interface.ts +111 -111
  796. package/src/_modules/mcp/_services/dynts-mcp-server.service-base.spec.ts +151 -151
  797. package/src/_modules/mcp/_services/dynts-mcp-server.service-base.ts +125 -125
  798. package/src/_modules/mcp/_services/dynts-mcp.adapter.ts +168 -168
  799. package/src/_modules/mcp/index.ts +13 -13
  800. package/src/_modules/messaging/README.md +354 -354
  801. package/src/_modules/messaging/_collections/get-messaging-routing-module.util.ts +26 -26
  802. package/src/_modules/messaging/_collections/msg-global-settings.const.ts +22 -22
  803. package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -226
  804. package/src/_modules/messaging/_collections/msg.util.ts +83 -83
  805. package/src/_modules/messaging/_models/msg-global-settings.interface.ts +37 -37
  806. package/src/_modules/messaging/_services/msg-conversation.data-service.ts +146 -146
  807. package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -219
  808. package/src/_modules/messaging/_services/msg-events.service.ts +267 -267
  809. package/src/_modules/messaging/_services/msg-integration.control-service.ts +179 -179
  810. package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -147
  811. package/src/_modules/messaging/_services/msg-main.control-service.ts +571 -571
  812. package/src/_modules/messaging/_services/msg-message.data-service.ts +129 -129
  813. package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -201
  814. package/src/_modules/messaging/_services/msg.controller.ts +370 -370
  815. package/src/_modules/messaging/index.ts +30 -30
  816. package/src/_modules/mock/app-extended-server.mock.ts +201 -201
  817. package/src/_modules/mock/app-integration-test.mock.ts +51 -51
  818. package/src/_modules/mock/app-params.mock.spec.ts +21 -21
  819. package/src/_modules/mock/app-params.mock.ts +9 -9
  820. package/src/_modules/mock/app-server.mock.ts +188 -188
  821. package/src/_modules/mock/auth-service.mock.spec.ts +47 -47
  822. package/src/_modules/mock/auth-service.mock.ts +28 -28
  823. package/src/_modules/mock/controller.mock.spec.ts +26 -26
  824. package/src/_modules/mock/controller.mock.ts +16 -16
  825. package/src/_modules/mock/data-model.mock.spec.ts +111 -111
  826. package/src/_modules/mock/data-model.mock.ts +82 -82
  827. package/src/_modules/mock/email-service-collection.mock.spec.ts +24 -24
  828. package/src/_modules/mock/email-service-collection.mock.ts +15 -15
  829. package/src/_modules/mock/email-service.mock.spec.ts +17 -17
  830. package/src/_modules/mock/email-service.mock.ts +20 -20
  831. package/src/_modules/mock/email-template.mock.html +14 -14
  832. package/src/_modules/mock/endpoint.mock.ts +91 -91
  833. package/src/_modules/mock/socket-client.mock.spec.ts +40 -40
  834. package/src/_modules/mock/socket-client.mock.ts +45 -45
  835. package/src/_modules/mock/socket-server.mock.spec.ts +44 -44
  836. package/src/_modules/mock/socket-server.mock.ts +46 -46
  837. package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -107
  838. package/src/_modules/oauth2/_routes/oauth2.controller.ts +98 -98
  839. package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -254
  840. package/src/_modules/oauth2/_services/oauth2.auth-service.ts +232 -232
  841. package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -585
  842. package/src/_modules/oauth2/_services/oauth2.control-service.ts +653 -653
  843. package/src/_modules/oauth2/index.ts +17 -17
  844. package/src/_modules/rate-limit/_models/rate-limit-config.interface.ts +69 -69
  845. package/src/_modules/rate-limit/_models/rate-limit-policy.interface.ts +16 -16
  846. package/src/_modules/rate-limit/index.ts +3 -3
  847. package/src/_modules/rate-limit/rate-limit.middleware.spec.ts +264 -264
  848. package/src/_modules/rate-limit/rate-limit.middleware.ts +343 -343
  849. package/src/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.ts +22 -22
  850. package/src/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.ts +82 -82
  851. package/src/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.ts +107 -107
  852. package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.spec.ts +312 -312
  853. package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.ts +311 -311
  854. package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.spec.ts +123 -123
  855. package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.ts +108 -108
  856. package/src/_modules/scoped-config/index.ts +17 -17
  857. package/src/_modules/server/errors/errors.control-service.spec.ts +246 -238
  858. package/src/_modules/server/errors/errors.control-service.ts +100 -85
  859. package/src/_modules/server/errors/errors.controller.spec.ts +249 -241
  860. package/src/_modules/server/errors/errors.controller.ts +489 -431
  861. package/src/_modules/server/errors/errors.data-service.spec.ts +480 -361
  862. package/src/_modules/server/errors/errors.data-service.ts +816 -722
  863. package/src/_modules/server/index.ts +30 -30
  864. package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -70
  865. package/src/_modules/server/server-status/server-status-snapshot.control-service.ts +17 -17
  866. package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -77
  867. package/src/_modules/server/server-status/server-status-snapshot.data-service.ts +37 -37
  868. package/src/_modules/server/server-status/server-status.control-service.spec.ts +584 -576
  869. package/src/_modules/server/server-status/server-status.control-service.ts +396 -396
  870. package/src/_modules/server/server-status/server-status.controller.spec.ts +248 -240
  871. package/src/_modules/server/server-status/server-status.controller.ts +253 -253
  872. package/src/_modules/socket/_enums/socket-security.enum.ts +11 -11
  873. package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +32 -32
  874. package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +22 -22
  875. package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +164 -164
  876. package/src/_modules/socket/_models/socket-presence.control-model.ts +210 -210
  877. package/src/_modules/socket/_models/socket-server-service-params.control-model.spec.ts +46 -46
  878. package/src/_modules/socket/_models/socket-server-service-params.control-model.ts +22 -22
  879. package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -15
  880. package/src/_modules/socket/_services/socket-client.service.ts +260 -260
  881. package/src/_modules/socket/_services/socket-server.service.spec.ts +11 -11
  882. package/src/_modules/socket/_services/socket-server.service.ts +1068 -1068
  883. package/src/_modules/socket/app-extended.integration.spec.ts +85 -85
  884. package/src/_modules/socket/app-extended.server.ts +630 -630
  885. package/src/_modules/socket/index.ts +42 -42
  886. package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -28
  887. package/src/_modules/test/get-test-routing-module.util.ts +23 -23
  888. package/src/_modules/test/index.ts +11 -11
  889. package/src/_modules/test/test.controller.spec.ts +72 -72
  890. package/src/_modules/test/test.controller.ts +115 -115
  891. package/src/_modules/usage/get-usage-routing-module.util.ts +22 -22
  892. package/src/_modules/usage/index.ts +15 -15
  893. package/src/_modules/usage/usage.controller.spec.ts +81 -81
  894. package/src/_modules/usage/usage.controller.ts +126 -126
  895. package/src/_modules/usage/usage.data-service.spec.ts +332 -332
  896. package/src/_modules/usage/usage.data-service.ts +185 -185
  897. package/src/_services/base/api.service-base.spec.ts +125 -125
  898. package/src/_services/base/api.service-base.ts +74 -74
  899. package/src/_services/base/archive-data.service.spec.ts +196 -196
  900. package/src/_services/base/archive-data.service.ts +216 -216
  901. package/src/_services/base/data.service.spec.ts +674 -674
  902. package/src/_services/base/data.service.ts +2719 -2719
  903. package/src/_services/base/db.service.spec.ts +73 -73
  904. package/src/_services/base/db.service.ts +1575 -1575
  905. package/src/_services/base/singleton.service-base.spec.ts +28 -28
  906. package/src/_services/base/singleton.service-base.ts +24 -24
  907. package/src/_services/base/singleton.service.spec.ts +114 -114
  908. package/src/_services/base/singleton.service.ts +38 -38
  909. package/src/_services/core/api.service.spec.ts +140 -140
  910. package/src/_services/core/api.service.ts +607 -607
  911. package/src/_services/core/auth.service.spec.ts +159 -159
  912. package/src/_services/core/auth.service.ts +174 -174
  913. package/src/_services/core/email.service.spec.ts +85 -85
  914. package/src/_services/core/email.service.ts +742 -742
  915. package/src/_services/core/global.service.spec.ts +292 -292
  916. package/src/_services/core/global.service.ts +475 -475
  917. package/src/_services/core/memory-guard.service.spec.ts +165 -165
  918. package/src/_services/core/memory-guard.service.ts +281 -281
  919. package/src/_services/core/service-collection.service.spec.ts +46 -46
  920. package/src/_services/core/service-collection.service.ts +6 -6
  921. package/src/_services/route/controller.service.spec.ts +53 -53
  922. package/src/_services/route/controller.service.ts +148 -148
  923. package/src/_services/route/routing-module.service.spec.ts +98 -98
  924. package/src/_services/route/routing-module.service.ts +330 -330
  925. package/src/_services/server/app.server.ts +1747 -1747
  926. package/src/_services/shared.static-service.spec.ts +99 -99
  927. package/src/_services/shared.static-service.ts +78 -78
  928. package/src/index.ts +96 -96
  929. package/tsconfig.app.json +12 -12
  930. package/tsconfig.json +42 -42
  931. package/.dynamo/logs/cicd-pipeline/output.log +0 -2771
  932. package/.dynamo/logs/cicd-pipeline/status.json +0 -94
@@ -1,1324 +1,1324 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DyNTS_App = void 0;
4
- const tslib_1 = require("tslib");
5
- const Mongoose = require("mongoose");
6
- const Express = require("express");
7
- /* import Mongoose from 'mongoose';
8
- import Express from 'express'; */
9
- const BodyParser = tslib_1.__importStar(require("body-parser"));
10
- const FileSystem = tslib_1.__importStar(require("fs"));
11
- const Https = tslib_1.__importStar(require("https"));
12
- const Path = tslib_1.__importStar(require("path"));
13
- /* import { version } from '../../../package.json'; */
14
- const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
15
- const default_fallback_cache_max_age_const_1 = require("../../_collections/default-fallback-cache-max-age.const");
16
- const default_not_found_page_const_1 = require("../../_collections/default-not-found-page.const");
17
- const global_settings_const_1 = require("../../_collections/global-settings.const");
18
- const mongo_reconnect_guard_util_1 = require("../../_collections/mongo-reconnect-guard.util");
19
- const route_security_enum_1 = require("../../_enums/route-security.enum");
20
- const app_system_controls_control_model_1 = require("../../_models/control-models/app-system-controls.control-model");
21
- const http_settings_control_model_1 = require("../../_models/control-models/http-settings.control-model");
22
- const singleton_service_1 = require("../base/singleton.service");
23
- const global_service_1 = require("../core/global.service");
24
- const memory_guard_service_1 = require("../core/memory-guard.service");
25
- /**
26
- *
27
- * function MyDecorator(config: any) {
28
- return function (target: Function) {
29
- // attach metadata or modify target
30
- target.prototype.myMeta = config;
31
- };
32
- }
33
-
34
- @MyDecorator({ role: 'admin' })
35
- class User {
36
- printRole() {
37
- console.log((this as any).myMeta.role); // → "admin"
38
- }
39
- }
40
-
41
- */
42
- /**
43
- * This will be the MAIN service of our server project,
44
- * follow the types and type instructions while setting up your project
45
- *
46
- * In this service, there are abstract functions that you will need to implement,
47
- * where you need to set up the main params for your application.
48
- *
49
- * (after the example, you can find the list of services you can/should setup)
50
- *
51
- * @example
52
- * export class App extends DyNTS_AppExtended {
53
- *
54
- * ...
55
- *
56
- * // Setting up App params, and preparing project global settings
57
- * setupAppParams(): void {
58
- * this.params = new DyNTS_AppParams({
59
- * name: 'Warbots Server',
60
- * title: warbotsTitleLog,
61
- * version: version,
62
- * dbName: 'warbots',
63
- * });
64
- *
65
- * // dynamoNTS_GlobalSettings.logRequestsContent = false;
66
- * }
67
- *
68
- * ...
69
- *
70
- * // Setting up DBServices
71
- * setGlobalServiceCollection(): void {
72
- * DyNTS_GlobalService.setServices({
73
- * authService: AuthService.getInstance(),
74
- * emailServiceCollection: EmailServiceCollectionService.getInstance(),
75
- * dbModels: [
76
- * userModelParams,
77
- * userDataModelParams,
78
- * userOptionsModelParams,
79
- * userStatisticsModelParams,
80
- * userAchievementsModelParams,
81
- * userNotificationsModelParams,
82
- *
83
- * matchStatisticsModelParams,
84
- * matchDataModelParams,
85
-
86
- * DyFM_usageSession_dataParams,
87
- * DyFM_customData_dataParams,
88
- * ]
89
- * });
90
- * }
91
- *
92
- * ...
93
- *
94
- * // Setting up Routes
95
- * setupRoutingModules(): void {
96
- * this.httpPort = env.port;
97
-
98
- * this.routingModules = [
99
- * new DyNTS_RoutingModule({
100
- * route: '/user',
101
- * controllers: [
102
- * UserController.getInstance(),
103
- * UserDataController.getInstance(),
104
- * UserOptionsController.getInstance(),
105
- * UserStatisticsController.getInstance(),
106
- * UserAchievementsController.getInstance(),
107
- * UserNotificationsController.getInstance()
108
- * ]
109
- * }),
110
- * new DyNTS_RoutingModule({
111
- * route: '/match',
112
- * controllers: [
113
- * MatchController.getInstance(),
114
- * MatchDistributionController.getInstance(),
115
- * MatchStatisticsController.getInstance(),
116
- * ]
117
- * }),
118
- * new DyNTS_RoutingModule({
119
- * route: '/server',
120
- * controllers: [
121
- * ServerController.getInstance(),
122
- * ]
123
- * }),
124
-
125
- * getTestRoutingModule(),
126
- * getUsageRoutingModule()
127
- * ];
128
- * }
129
- * }
130
- *
131
- * //
132
- * // The Services available
133
- * //
134
- * // Authentication Service
135
- * // A commonly used basic service,
136
- * // which is necessary fur certain functions (such as registering call issuers)
137
- * //
138
- * // This will handle Authentication Token checking/refreshing,
139
- * // checking issuer's identifier and routeParams,
140
- * // handling JWT Token, or maybe with OAuth2 or other commonly used security procedures
141
- * //
142
- * // You can create one with this Dynamo Object:
143
- * //
144
- *
145
- * @example
146
- * // follow the instructions on the abstract class (DyNTS_AuthService)
147
- * export class AuthService extends DyNTS_AuthService {}
148
- *
149
- *
150
- *
151
- * //
152
- */
153
- /**
154
- * This will be the MAIN service of our server project,
155
- * follow the types and type instructions while setting up your project
156
- *
157
- * In this service, there are abstract functions that you will need to implement,
158
- * where you need to set up the main params for your application.
159
- *
160
- * (after the example, you can find the list of services you can/should setup)
161
- *
162
- * You need to setup the following functions:
163
- * ```ts
164
- * // this is where you set up the main params for your application
165
- * getAppParams(): DyNTS_AppParams
166
- *
167
- * // this is where you connect your main services
168
- * getGlobalServiceSettings(): DyNTS_GlobalService_Settings
169
- *
170
- * // this is where you set up your ports
171
- * getPorts(): DyNTS_PortSettings
172
- *
173
- * // this is where you set up your routes
174
- * getRoutingModules(): DyNTS_RoutingModule[]
175
- *
176
- *
177
- *
178
- * ```
179
- * optionally you can setup the following functions:
180
- * ```ts
181
- * // this is where you set up your certifications
182
- * getCertificationSettings(): DyNTS_CertificationSettings
183
- *
184
- * // this is where you set up additional root services
185
- * getRootServices(): DyNTS_SingletonService[]
186
- *
187
- * // this is where you set up your initial db entries
188
- * createEntries(): void
189
- *
190
- * // this is where you can define post setup processes
191
- * postProcess(): void
192
- *
193
- *
194
- *
195
- * ```
196
- *
197
- */
198
- class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
199
- systemControls = new app_system_controls_control_model_1.DyNTS_AppSystemControls();
200
- get started() {
201
- return this.systemControls.app.started;
202
- }
203
- get superStarted() {
204
- return this.systemControls.app.started;
205
- }
206
- constructErrors = [];
207
- /* removed since cant use version from package.json
208
- private readonly _ntsVersion: string = 'v01.07.18';
209
- protected get ntsVersion(): string {
210
- return this._ntsVersion;
211
- } */
212
- get serverName() {
213
- return this.params.name;
214
- }
215
- _params;
216
- get params() {
217
- return this._params;
218
- }
219
- mongoose = Mongoose;
220
- _security;
221
- get security() {
222
- return this._security;
223
- }
224
- _portSettings = new http_settings_control_model_1.DyNTS_Http_Settings();
225
- get portSettings() {
226
- return this._portSettings;
227
- }
228
- _cert;
229
- get cert() {
230
- return this._cert;
231
- }
232
- openExpress;
233
- secureExpress;
234
- httpsServer;
235
- httpServer;
236
- globalService;
237
- _rootServices = [];
238
- _routingModules = [];
239
- defaultReadyTimeout = 30 * fsm_dynamo_1.second;
240
- defaultErrorUserMsg = `We encountered an unhandled Server Error, ` +
241
- `\nplease contact the responsible development team.` +
242
- `\n(Internal Server error)`;
243
- get logSetup() {
244
- return global_settings_const_1.DyNTS_global_settings.log_settings.setup;
245
- }
246
- get deepLog() {
247
- return global_settings_const_1.DyNTS_global_settings.log_settings.deep;
248
- }
249
- get fnLogs() {
250
- return global_settings_const_1.DyNTS_global_settings.log_settings.functions;
251
- }
252
- debugLog = global_settings_const_1.DyNTS_global_settings.log_settings.server_debug;
253
- constructor( /* extended?: boolean */) {
254
- super();
255
- /* dotenv.config() */
256
- process.on('unhandledRejection', (reason_theError, p_passWhatIsThis_maybeThePromise) => {
257
- if (reason_theError instanceof fsm_dynamo_1.DyFM_Error) {
258
- reason_theError.logSimple('Unhandled Rejection');
259
- }
260
- else {
261
- fsm_dynamo_1.DyFM_Log.H_error('Unhandled Rejection:', p_passWhatIsThis_maybeThePromise?.toString(), '\n Rejection reason:', reason_theError?.stack?.split('at')?.[0],
262
- /* '\n ErrorCode:', (reason as any)?.code, */
263
- '\n\n Stack:', reason_theError?.stack?.replaceAll?.('\n at', '\n at'));
264
- }
265
- try {
266
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(new fsm_dynamo_1.DyFM_Error({
267
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-BASE-UR`,
268
- message: `Unhandled Rejection!: "${reason_theError?.stack?.split('at')?.[0]}"`,
269
- userMessage: this.defaultErrorUserMsg,
270
- addECToUserMsg: true,
271
- error: reason_theError,
272
- additionalContent: {
273
- reason: reason_theError,
274
- rejectedPromise: p_passWhatIsThis_maybeThePromise,
275
- },
276
- systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
277
- level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
278
- }));
279
- }
280
- catch (error) {
281
- fsm_dynamo_1.DyFM_Log.error('globalErrorHandler (MULTILEVEL) ERROR:', error);
282
- }
283
- });
284
- this.asyncConstruct( /* extended */).catch((error) => {
285
- if (error instanceof fsm_dynamo_1.DyFM_Error) {
286
- if (error.additionalContent?.constructErrors?.length) {
287
- error.additionalContent.constructErrors.forEach((errorItem) => {
288
- fsm_dynamo_1.DyFM_Error.logSimple('(constructor asyncConstruct.catch) error:', errorItem);
289
- /* if (errorItem instanceof DyFM_Error) {
290
- errorItem.logSimple(`(constructor asyncConstruct.catch) error:\n`);
291
- } else {
292
- DyFM_Log.H_warn(
293
- '(constructor asyncConstruct.catch) additional error content:\n',
294
- errorItem
295
- );
296
- } */
297
- });
298
- }
299
- else {
300
- fsm_dynamo_1.DyFM_Log.H_warn('(constructor asyncConstruct.catch) additional error content:\n', error?.additionalContent);
301
- }
302
- }
303
- fsm_dynamo_1.DyFM_Error.logSimple('(constructor asyncConstruct.catch) error:', error);
304
- /* if (
305
- !DyNTS_global_settings.log_settings.highDetailedLogs &&
306
- (error instanceof DyFM_Error)
307
- ) {
308
- error.logSimple(
309
- `Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)` +
310
- '\n all error messages (from this stack):\n\n"' +
311
- error._messages.join('"\n\n"') + '"\n\n'
312
- );
313
- } else if (error instanceof DyFM_Error) {
314
- DyFM_Log.H_error(
315
- `Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)`,
316
- `\n ERROR:`, error
317
- );
318
- } */
319
- const message = error?.additionalContent?.constructErrors?.flatMap((errorItem) => {
320
- return errorItem?._messages ?? [];
321
- })?.join?.('\n') ??
322
- error?.errors?.flatMap((errorItem) => errorItem?._messages ?? [errorItem?.message])?.join?.('\n') ??
323
- error?.message ??
324
- 'UNKNOWN';
325
- fsm_dynamo_1.DyFM_Log.testError('Application start failed:\n', message);
326
- process.exit(1);
327
- });
328
- }
329
- async asyncConstruct(extended) {
330
- if (this.fnLogs && this.deepLog)
331
- fsm_dynamo_1.DyFM_Log.log('\nfn:. asyncConstruct');
332
- try {
333
- this.systemControls.app.init = true;
334
- this._params = this.getAppParams();
335
- fsm_dynamo_1.DyFM_Log.log(`\n\n\n\n\n\n\n\n\n\n` +
336
- `Starting ${this._params?.name}... ` +
337
- /* `v${version}` + */
338
- `\n\n\n\n\n\n\n\n\n\n`);
339
- if (!this._params) {
340
- throw new Error('getAppParams() must return a DyNTS_AppParams object!');
341
- }
342
- if (this.params.systemShortCodeName) {
343
- global_settings_const_1.DyNTS_global_settings.systemShortCodeName = this.params.systemShortCodeName;
344
- }
345
- if (this.params.systemName) {
346
- global_settings_const_1.DyNTS_global_settings.systemName = this.params.systemName;
347
- fsm_dynamo_1.DyFM_error_defaults.issuerSystem = this.params.systemName;
348
- }
349
- if (this.params.version) {
350
- global_settings_const_1.DyNTS_global_settings.systemVersion = this.params.version;
351
- fsm_dynamo_1.DyFM_error_defaults.systemVersion = this.params.version;
352
- }
353
- process.stdout.write(String.fromCharCode(27) + ']0;' +
354
- this._params?.name +
355
- String.fromCharCode(7));
356
- fsm_dynamo_1.DyFM_error_defaults.issuerSystem = this._params.systemName;
357
- this.overrideDynamoNTSGlobalSettings?.();
358
- if (global_settings_const_1.DyNTS_global_settings.log_settings.setup) {
359
- fsm_dynamo_1.DyFM_Log.S_info(`env settings;\n`, {
360
- systemName: global_settings_const_1.DyNTS_global_settings.systemName,
361
- systemShortCodeName: global_settings_const_1.DyNTS_global_settings.systemShortCodeName,
362
- systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
363
- environment: global_settings_const_1.DyNTS_global_settings.env_settings.environment,
364
- /* log_settings: DyNTS_global_settings.log_settings,
365
- env_settings: DyNTS_global_settings.env_settings, */
366
- });
367
- }
368
- this.globalService = global_service_1.DyNTS_GlobalService.getInstance();
369
- await global_service_1.DyNTS_GlobalService.setServices(this.getGlobalServiceCollection());
370
- global_service_1.DyNTS_GlobalService.setParams(this.params);
371
- if (this.getPortSettings) {
372
- this._portSettings = this.getPortSettings();
373
- }
374
- if (this.getCertificationSettings) {
375
- this._cert = this.getCertificationSettings();
376
- }
377
- if (this.getApiBasePath) {
378
- global_settings_const_1.DyNTS_global_settings.baseUrl = this.getApiBasePath();
379
- }
380
- if (this.getRoutingModules) {
381
- this._routingModules = this.getRoutingModules();
382
- // ezt egyelőre csak tesztelem, nem kerül be
383
- /* if (
384
- !DyNTS_global_settings.dontCreateDefaultRoute &&
385
- !this._routingModules.some((routingModule: DyNTS_RoutingModule): boolean => routingModule.route === '/*')
386
- ) {
387
- this._routingModules.push(
388
- DyNTS_getStarRoute()
389
- );
390
- } */
391
- }
392
- if (this._params.dbUri) {
393
- await this.startDB();
394
- // createEntries csak akkor fut, ha a DB tényleg fel-jött.
395
- // Ha a startDB jelezte a hibát, de továbbment, akkor a started flag false marad,
396
- // és nem próbálunk meg írni egy nem létező kapcsolatra.
397
- if (this.createEntries && this.systemControls.mongoose.started) {
398
- await this.createEntries();
399
- }
400
- }
401
- else {
402
- fsm_dynamo_1.DyFM_Log.log(`\nNo database connection created.`);
403
- }
404
- if (this._routingModules?.length) {
405
- if (this.logSetup)
406
- fsm_dynamo_1.DyFM_Log.log('\nsetting up express routes...');
407
- this.setSecurity();
408
- await this.initExpresses();
409
- await this.startExpresses();
410
- if (this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
411
- await this.mountOpenRoutes();
412
- }
413
- if (this._security !== route_security_enum_1.DyNTS_RouteSecurity.open && this._cert) {
414
- await this.mountSecureRoutes();
415
- }
416
- // Generikus, auth-agnosztikus extension-point: custom middleware az API
417
- // route-ok UTÁN, de a SPA static catch-all (mountStaticClient) ELŐTT.
418
- await this.mountCustomMiddleware();
419
- await this.mountStaticClient();
420
- if (this.logSetup) {
421
- fsm_dynamo_1.DyFM_Log.log(`\nRoutes mounted.... server using security: ${this._security}`);
422
- }
423
- }
424
- else {
425
- fsm_dynamo_1.DyFM_Log.warn(`\nNo routes mounted!`);
426
- }
427
- if (this.getRootServices) {
428
- this._rootServices = await this.getRootServices();
429
- }
430
- if (this.postProcess) {
431
- await this.postProcess().catch((error) => {
432
- fsm_dynamo_1.DyFM_Error.logSimple(`"${this._params.name}" postProcess failed:`, error);
433
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(error);
434
- });
435
- }
436
- // FR-193 — bedrock OOM korai-figyelmeztetés: feltelepítjük a heap-watchdogot, ha
437
- // engedélyezve (DyNTS_global_settings.memoryGuard.enabled, default true). Biztonságos:
438
- // a guard egy könnyű setInterval, ami SOHA nem dob; csak near-OOM küszöböknél hagy
439
- // tartós nyomot az error-sinkbe, mielőtt a fatal heap-OOM megölné a process-t.
440
- try {
441
- if (global_settings_const_1.DyNTS_global_settings.memoryGuard?.enabled) {
442
- memory_guard_service_1.DyNTS_MemoryGuard.getInstance().install();
443
- }
444
- }
445
- catch (memoryGuardError) {
446
- fsm_dynamo_1.DyFM_Log.warn('[DyNTS_MemoryGuard] auto-install skipped (non-fatal):', memoryGuardError);
447
- }
448
- if (!extended) {
449
- await this.ready();
450
- if (this.params.title) {
451
- fsm_dynamo_1.DyFM_Log.success(this.params.title);
452
- }
453
- fsm_dynamo_1.DyFM_Log.info(`Version: ${this.params.version}`);
454
- /* DyFM_Log.info(`NTS Version: ${this.ntsVersion}`); */
455
- fsm_dynamo_1.DyFM_Log.H_success(`${this.params.name} started successfully.`);
456
- }
457
- }
458
- catch (error) {
459
- this.constructErrors.push(error);
460
- if (this.deepLog) {
461
- if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
462
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed (in asyncConstruct (highDetailedLog)). `, `\n\n construct ERRORS:`, this.constructErrors, '\n\nlast error:', error);
463
- }
464
- else {
465
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed (in asyncConstruct). `, `\n\n construct ERRORS:`, this.getSimplifiedConstructErrors(), '\n\nlast error:', error instanceof fsm_dynamo_1.DyFM_Error ? error.getErrorSimplified() : error);
466
- }
467
- }
468
- throw new fsm_dynamo_1.DyFM_Error({
469
- ...this._getDefaultErrorSettings('asyncConstruct', error),
470
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-001`,
471
- additionalContent: {
472
- constructErrors: this.constructErrors,
473
- systemControls: this.systemControls,
474
- systemReadies: {
475
- app: this.systemControls.app.getIsReady(),
476
- mongoose: this.systemControls.mongoose.getIsReady(),
477
- httpServer: this.systemControls.httpServer.getIsReady(),
478
- httpsServer: this.systemControls.httpsServer.getIsReady(),
479
- },
480
- },
481
- });
482
- }
483
- }
484
- async ready(timeout = this.defaultReadyTimeout) {
485
- try {
486
- if (this.fnLogs)
487
- fsm_dynamo_1.DyFM_Log.log('\nfn:. ready');
488
- await fsm_dynamo_1.DyFM_Async.delay(100);
489
- let ready = false;
490
- const start = +new Date();
491
- if (this.constructErrors.length) {
492
- if (this.deepLog) {
493
- if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
494
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 1)`, `\n construct ERRORS:`, this.constructErrors);
495
- }
496
- else {
497
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 1)`, `\n construct ERRORS:`, this.getSimplifiedConstructErrors());
498
- }
499
- }
500
- throw new fsm_dynamo_1.DyFM_Error({
501
- ...this._getDefaultErrorSettings('ready', new Error(`"${this._params.name}" start failed.`)),
502
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R01`,
503
- additionalContent: this.constructErrors.length === 1 ?
504
- { error: this.constructErrors[0] } :
505
- { errors: this.constructErrors },
506
- });
507
- }
508
- while (!ready && +new Date() - start < timeout) {
509
- if (this.systemControls.app.init) {
510
- ready = (this.systemControls.mongoose.getIsReady() &&
511
- this.systemControls.httpServer.getIsReady() &&
512
- this.systemControls.httpsServer.getIsReady());
513
- }
514
- else {
515
- fsm_dynamo_1.DyFM_Log.error(`"${this._params.name}" APP NOT INITIALIZED while trying to get ready.`);
516
- }
517
- if (!ready) {
518
- await fsm_dynamo_1.DyFM_Async.wait(100);
519
- }
520
- }
521
- if (timeout < +new Date() - start) {
522
- if (this.deepLog) {
523
- if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
524
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; TIMEOUT check)`, `\n construct ERRORS:`, this.constructErrors);
525
- }
526
- else {
527
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; TIMEOUT check)`, `\n construct ERRORS:`, this.getSimplifiedConstructErrors());
528
- }
529
- }
530
- throw new fsm_dynamo_1.DyFM_Error({
531
- ...this._getDefaultErrorSettings('ready', new Error(`"${this._params.name}" start failed. TIMEOUT`)),
532
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R02`,
533
- additionalContent: {
534
- constructErrors: this.constructErrors,
535
- systemControls: this.systemControls,
536
- systemReadies: {
537
- mongoose: this.systemControls.mongoose.getIsReady(),
538
- httpServer: this.systemControls.httpServer.getIsReady(),
539
- httpsServer: this.systemControls.httpsServer.getIsReady(),
540
- },
541
- },
542
- });
543
- }
544
- if (this.constructErrors.length) {
545
- if (this.deepLog) {
546
- if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
547
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 2)`, `\n construct ERRORS:`, this.constructErrors);
548
- }
549
- else {
550
- fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 2)`, `\n construct ERRORS:`, this.getSimplifiedConstructErrors());
551
- }
552
- }
553
- throw new fsm_dynamo_1.DyFM_Error({
554
- ...this._getDefaultErrorSettings('ready', new Error(`"${this._params.name}" start failed.`)),
555
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R03`,
556
- additionalContent: this.constructErrors,
557
- });
558
- }
559
- if (ready) {
560
- this.systemControls.app.started = true;
561
- if (this.fnLogs && this.deepLog)
562
- fsm_dynamo_1.DyFM_Log.log('\nfn:. ready: return');
563
- return;
564
- }
565
- this.systemControls.app.started = false;
566
- let msg = `"${this._params.name}" start failed. UNKNOWN`;
567
- if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
568
- msg += `\nMongoose start failed.`;
569
- }
570
- if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
571
- msg += `\nHTTP Server start failed.`;
572
- }
573
- if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
574
- msg += `\nHTTPS Server start failed.`;
575
- }
576
- fsm_dynamo_1.DyFM_Log.error(msg, this.constructErrors);
577
- throw new fsm_dynamo_1.DyFM_Error({
578
- ...this._getDefaultErrorSettings('ready', new Error(msg)),
579
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R04`,
580
- additionalContent: {
581
- constructErrors: this.constructErrors,
582
- systemControls: this.systemControls,
583
- systemReadies: {
584
- app: this.systemControls.app.getIsReady(),
585
- mongoose: this.systemControls.mongoose.getIsReady(),
586
- httpServer: this.systemControls.httpServer.getIsReady(),
587
- httpsServer: this.systemControls.httpsServer.getIsReady(),
588
- },
589
- },
590
- error: this.constructErrors?.[0] ?? new Error(),
591
- });
592
- }
593
- catch (error) {
594
- throw new fsm_dynamo_1.DyFM_Error({
595
- ...this._getDefaultErrorSettings('ready', error),
596
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-READY0`,
597
- });
598
- }
599
- }
600
- getSimplifiedConstructErrors() {
601
- return this.constructErrors.map((error) => {
602
- if (error instanceof fsm_dynamo_1.DyFM_Error) {
603
- return error.getErrorSimplified();
604
- }
605
- else {
606
- return error;
607
- }
608
- });
609
- }
610
- async stop(dontLog) {
611
- try {
612
- fsm_dynamo_1.DyFM_Log.info('\nstopping server...\n');
613
- await this.ready();
614
- if (this.started) {
615
- if (this.systemControls.mongoose.init) {
616
- fsm_dynamo_1.DyFM_Log.info(`\nstopping Mongoose....`);
617
- let tryCount = 0;
618
- while (!this.systemControls.mongoose.started &&
619
- !this.constructErrors.length &&
620
- tryCount++ < 10) {
621
- fsm_dynamo_1.DyFM_Log.warn(`Mongoose not even started yet....`);
622
- await fsm_dynamo_1.DyFM_Async.wait(fsm_dynamo_1.second);
623
- }
624
- this.systemControls.mongoose.started = false;
625
- if (this.mongoose) {
626
- await fsm_dynamo_1.DyFM_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
627
- this.mongoose.deleteModel(modelName);
628
- });
629
- const disconnect = new Promise((resolve) => {
630
- this.mongoose.connection.on('disconnecting', () => {
631
- resolve();
632
- });
633
- });
634
- await this.mongoose.disconnect();
635
- await this.mongoose.connection.close();
636
- await disconnect;
637
- this.mongoose.connection.removeAllListeners();
638
- while (this.mongoose.connection.readyState !== 0 &&
639
- !this.constructErrors.length) {
640
- fsm_dynamo_1.DyFM_Log.warn(`\nMongoose still not disconnected....`);
641
- await fsm_dynamo_1.DyFM_Async.wait(fsm_dynamo_1.second);
642
- }
643
- }
644
- else {
645
- fsm_dynamo_1.DyFM_Log.error(`\nMongoose not found.`);
646
- }
647
- this.systemControls.mongoose.init = false;
648
- }
649
- if (this.systemControls.httpServer.init) {
650
- this.systemControls.httpServer.started = false;
651
- if (this.httpServer) {
652
- await new Promise((resolve) => {
653
- this.httpServer.close(resolve);
654
- });
655
- }
656
- else {
657
- fsm_dynamo_1.DyFM_Log.error(`\nHTTP Server not found.`);
658
- }
659
- this.systemControls.httpServer.init = false;
660
- }
661
- if (this.systemControls.httpsServer.init) {
662
- this.systemControls.httpsServer.started = false;
663
- if (this.httpsServer) {
664
- await new Promise((resolve) => {
665
- this.httpsServer.close(resolve);
666
- });
667
- }
668
- else {
669
- fsm_dynamo_1.DyFM_Log.error(`\nHTTPS Server not found.`);
670
- }
671
- this.systemControls.httpsServer.init = false;
672
- }
673
- await fsm_dynamo_1.DyFM_Async.wait(fsm_dynamo_1.second);
674
- if (!dontLog) {
675
- fsm_dynamo_1.DyFM_Log.H_log(`"${this._params.name}" stopped successfully.`);
676
- }
677
- }
678
- }
679
- catch (error) {
680
- throw new fsm_dynamo_1.DyFM_Error({
681
- ...this._getDefaultErrorSettings('stop', error),
682
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-STOP0`,
683
- });
684
- }
685
- }
686
- /**
687
- *
688
- */
689
- async startDB() {
690
- if (this.fnLogs && this.deepLog)
691
- fsm_dynamo_1.DyFM_Log.log('\nfn:. startDB');
692
- else if (this.logSetup)
693
- fsm_dynamo_1.DyFM_Log.log('\nstarting DB connection...');
694
- if (!this._params.dbUri) {
695
- throw new fsm_dynamo_1.DyFM_Error({
696
- ...this._getDefaultErrorSettings('startDB', new Error('DB URI is not set.')),
697
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
698
- });
699
- }
700
- if (!this._params.dbOptions) {
701
- throw new fsm_dynamo_1.DyFM_Error({
702
- ...this._getDefaultErrorSettings('startDB', new Error('DB OPTIONS are not set.')),
703
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
704
- });
705
- }
706
- if (this.systemControls.mongoose.init || this.systemControls.mongoose.started) {
707
- throw new fsm_dynamo_1.DyFM_Error({
708
- ...this._getDefaultErrorSettings('startDB', new Error('Mongoose is already initialized.')),
709
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
710
- });
711
- }
712
- try {
713
- await new Promise((resolve, reject) => {
714
- this.systemControls.mongoose.init = true;
715
- this.mongoose.connection
716
- .once('open', () => {
717
- this.systemControls.mongoose.started = true;
718
- fsm_dynamo_1.DyFM_Log.success(`\nConnected to MongoDB (${this._params.dbUri})\n`);
719
- resolve();
720
- })
721
- .on('error', (error) => {
722
- if (!this.systemControls.mongoose.started) {
723
- // Initial DB-csatlakozás sikertelen:
724
- // jelezzük a hibát (log + globalErrorHandler), de NEM szakítjuk meg az
725
- // App startup-ot (nincs constructErrors push, nincs reject).
726
- // A mongoose.init-et resetteljük, hogy a ready() ne várjon a DB-re.
727
- // Ha a mongoose később mégis tudna csatlakozni, az 'open' event
728
- // beállítja a started flag-et, így a runtime DB-műveletek elindulnak.
729
- this.systemControls.mongoose.init = false;
730
- const d_error = new fsm_dynamo_1.DyFM_Error({
731
- ...this._getDefaultErrorSettings('startDB', error),
732
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB1`,
733
- message: `Unable to connect to MongoDB server (${this._params.dbUri}), ` +
734
- `ERROR: ${error}`,
735
- level: fsm_dynamo_1.DyFM_ErrorLevel.serious,
736
- });
737
- fsm_dynamo_1.DyFM_Log.H_error(`\nUnable to connect to MongoDB server (${this._params.dbUri}).` +
738
- `\nServer will continue WITHOUT DB connection.` +
739
- `\nDB-using endpoints will fail at runtime until connection recovers.`);
740
- if (this.debugLog)
741
- fsm_dynamo_1.DyFM_Log.S_error(`\nMongoDB connect ERROR: `, error);
742
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
743
- resolve();
744
- }
745
- else {
746
- if (this.debugLog)
747
- fsm_dynamo_1.DyFM_Log.error('\nMongoDB ERROR: ', error);
748
- const d_error = new fsm_dynamo_1.DyFM_Error({
749
- ...this._getDefaultErrorSettings('mongoose.connection.on(error)', error),
750
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB2`,
751
- message: `MongoDB ERROR: ${error}`,
752
- level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
753
- });
754
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
755
- }
756
- });
757
- try {
758
- this.mongoose.connect(this._params.dbUri, this._params.dbOptions
759
- /* {
760
- directConnection: true,
761
- } */
762
- );
763
- }
764
- catch (error) {
765
- throw new fsm_dynamo_1.DyFM_Error({
766
- ...this._getDefaultErrorSettings('startDB', error),
767
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB3`,
768
- });
769
- }
770
- });
771
- }
772
- catch (error) {
773
- throw new fsm_dynamo_1.DyFM_Error({
774
- ...this._getDefaultErrorSettings('startDB', error),
775
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
776
- });
777
- }
778
- // 2026-06-20 — Mongo reconnect-guard. A MongoDB-driver a hostnevet connect-kor EGYSZER
779
- // resolválja + cache-eli az IP-t; ha a Mongo-konténert recreate-elik (új docker-network IP),
780
- // a driver a HALOTT IP-n ragad → ECONNREFUSED + buffering-timeout, és a service magától SOHA
781
- // nem áll vissza. A guard sustained-disconnect (readyState !== 1) esetén — a driver saját
782
- // grace-e UTÁN — TELJES disconnect()+connect()-et csinál → ÚJ MongoClient → ÚJ DNS-resolve →
783
- // új IP → reconnect. Best-effort, always-on, healthy connection-t (===1) SOHA nem bánt; csak
784
- // konténer-IP-frissítés, nem ír adatot. Lásd: mongo-reconnect-guard.util.ts.
785
- try {
786
- (0, mongo_reconnect_guard_util_1.startMongoReconnectGuard)({
787
- getReadyState: () => this.mongoose.connection.readyState,
788
- reconnect: async () => {
789
- await this.mongoose.disconnect().catch(() => undefined);
790
- await this.mongoose.connect(this._params.dbUri, this._params.dbOptions);
791
- },
792
- log: (msg) => fsm_dynamo_1.DyFM_Log.warn(msg),
793
- });
794
- }
795
- catch (guardErr) {
796
- fsm_dynamo_1.DyFM_Log.warn(`[mongo-reconnect-guard] failed to start (non-fatal): ${guardErr instanceof Error ? guardErr.message : String(guardErr)}`);
797
- }
798
- }
799
- /**
800
- *
801
- */
802
- async initExpresses() {
803
- if (this.fnLogs && this.deepLog)
804
- fsm_dynamo_1.DyFM_Log.log('\nfn:. initExpresses');
805
- try {
806
- if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
807
- if (this._portSettings.httpPort === undefined || this._portSettings.httpPort === null) {
808
- let errorMsg = `\nYou have open routes, but httpPort is not set!` +
809
- `\nThere are ${this._routingModules.filter(m => m.security != route_security_enum_1.DyNTS_RouteSecurity.secure).length} open/both routes` +
810
- `\nroot security: ${this._security}` +
811
- `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
812
- errorMsg += '\n\nThe routes setted to use open server:';
813
- this._routingModules.forEach((module) => {
814
- if (module.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
815
- errorMsg += `\n ${module.route} (security: ${module.security})`;
816
- errorMsg += `\n subroutes using open sever:`;
817
- module.endpoints.forEach((endpoint) => {
818
- if (endpoint.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
819
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
820
- }
821
- });
822
- }
823
- });
824
- const error = new Error(`Open routes cannot be established!\n${errorMsg}`);
825
- const errorStack = error.stack.split('\n');
826
- errorStack.splice(1, 2);
827
- error.stack = errorStack.join('\n');
828
- fsm_dynamo_1.DyFM_Log.error(errorMsg);
829
- throw error;
830
- }
831
- await this.initOpenExpress();
832
- }
833
- if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
834
- if (!this._cert || !this._portSettings.httpsPort) {
835
- let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
836
- `\nThere are ${this._routingModules.filter(m => m.security && m.security !== route_security_enum_1.DyNTS_RouteSecurity.open).length} secure routes` +
837
- `\nroot security: ${this._security}` +
838
- `\nset...` +
839
- `\n(missing exact howto...)` +
840
- /* `\n httpsPort and` +
841
- `\n cert: {` +
842
- `\n keyPath: FileSystem.PathLike,` +
843
- `\n certPath: FileSystem.PathLike,` +
844
- `\n }` + */
845
- `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
846
- errorMsg += '\n\nThe routes setted to use secure server:';
847
- this._routingModules.forEach((module) => {
848
- if (module.security && module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
849
- errorMsg += `\n ${module.route} (security: ${module.security})`;
850
- errorMsg += `\n location: ${module.stackLocation}`;
851
- errorMsg += `\n subroutes using secure sever:`;
852
- module.endpoints.forEach((endpoint) => {
853
- if (endpoint.security && endpoint.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
854
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
855
- errorMsg += `\n location: ${endpoint.stackLocation}`;
856
- }
857
- });
858
- }
859
- });
860
- const error = new Error(`Secure routes cannot be established!\n${errorMsg}`);
861
- const errorStack = error.stack.split('\n');
862
- errorStack.splice(1, 2);
863
- error.stack = errorStack.join('\n');
864
- fsm_dynamo_1.DyFM_Log.error(errorMsg);
865
- throw error;
866
- }
867
- await this.initSecureExpress();
868
- }
869
- }
870
- catch (error) {
871
- throw new fsm_dynamo_1.DyFM_Error({
872
- ...this._getDefaultErrorSettings('initExpresses', error),
873
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-IE0`,
874
- });
875
- }
876
- }
877
- /**
878
- *
879
- */
880
- async initOpenExpress() {
881
- if (this.fnLogs)
882
- fsm_dynamo_1.DyFM_Log.log('\nfn:. initOpenExpress');
883
- this.openExpress = Express();
884
- this.openExpress.set('maxHeaderSize', 10 * fsm_dynamo_1.megabyte); // 1024 * 1024 * 10, // 10MB
885
- this.openExpress.use(BodyParser.urlencoded(this._portSettings.httpUrlencoded));
886
- this.openExpress.use(BodyParser.json(this._portSettings.httpJson));
887
- // FR-041 — CORS allowlist enforcement. No-op if getCorsSettings() is not overridden.
888
- this.mountCors(this.openExpress);
889
- }
890
- /**
891
- *
892
- */
893
- async initSecureExpress() {
894
- if (this.fnLogs)
895
- fsm_dynamo_1.DyFM_Log.log('\nfn:. initSecureExpress');
896
- this.secureExpress = Express();
897
- this.secureExpress.use(BodyParser.urlencoded(this._portSettings.httpsUrlencoded));
898
- this.secureExpress.use(BodyParser.json(this._portSettings.httpsJson));
899
- // FR-041 — CORS allowlist enforcement (same as open express).
900
- this.mountCors(this.secureExpress);
901
- const options = {
902
- key: FileSystem.readFileSync(this._cert.keyPath),
903
- cert: FileSystem.readFileSync(this._cert.certPath),
904
- maxHeaderSize: 10 * fsm_dynamo_1.megabyte, // 1024 * 1024 * 10, // 10MB
905
- };
906
- this.httpsServer = Https.createServer(options, this.secureExpress);
907
- }
908
- /**
909
- *
910
- */
911
- async startExpresses() {
912
- if (this.fnLogs && this.deepLog)
913
- fsm_dynamo_1.DyFM_Log.log('\nfn:. startExpresses');
914
- try {
915
- if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
916
- await new Promise((resolve, reject) => {
917
- this.systemControls.httpsServer.init = true;
918
- this.httpsServer
919
- .listen(this._portSettings.httpsPort, this.params.secureHost, this.params.expressBacklog, () => {
920
- this.systemControls.httpsServer.started = true;
921
- fsm_dynamo_1.DyFM_Log.success(`\nHTTPS (secure) server is listening on port: ` +
922
- `${this.params.secureHost}:${this._portSettings.httpsPort}`);
923
- resolve();
924
- })
925
- .on('error', (error) => {
926
- if (this.debugLog)
927
- fsm_dynamo_1.DyFM_Log.error(`\nHTTPS (secure) server ERROR`, error);
928
- if (!this.systemControls.httpsServer.started) {
929
- const d_error = new fsm_dynamo_1.DyFM_Error({
930
- ...this._getDefaultErrorSettings('startExpresses', error),
931
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE1`,
932
- message: `HTTPS (secure) start server ERROR`,
933
- });
934
- this.constructErrors.push(d_error);
935
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
936
- reject(d_error);
937
- }
938
- else {
939
- const d_error = new fsm_dynamo_1.DyFM_Error({
940
- ...this._getDefaultErrorSettings('httpsServer.on(error)', error),
941
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE2`,
942
- message: `HTTPS (secure) server ERROR`,
943
- level: fsm_dynamo_1.DyFM_ErrorLevel.serious,
944
- });
945
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
946
- }
947
- })
948
- .on('uncaughtException', (exception) => {
949
- const d_error = new fsm_dynamo_1.DyFM_Error({
950
- ...this._getDefaultErrorSettings('httpsServer.on(uncaughtException)', exception),
951
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE3`,
952
- message: `HTTPS (secure) server uncaughtException`,
953
- level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
954
- });
955
- if (this.debugLog)
956
- fsm_dynamo_1.DyFM_Log.warn(`\nHTTPS (secure) server uncaughtException`, d_error);
957
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
958
- });
959
- });
960
- }
961
- if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
962
- this.systemControls.httpServer.init = true;
963
- await new Promise((resolve, reject) => {
964
- this.httpServer = this.openExpress
965
- .listen(this._portSettings.httpPort, this.params.openHost, this.params.expressBacklog, () => {
966
- this.systemControls.httpServer.started = true;
967
- const resolvedPort = this.httpServer?.address?.()?.['port'] ?? this._portSettings.httpPort;
968
- if (this._portSettings.httpPort === 0) {
969
- fsm_dynamo_1.DyFM_Log.H_warn(`\nHTTP (open) server is using a randomly selected port by the OS: ${resolvedPort}` +
970
- `\n (httpPort was set to 0 — this is intended for testing only)`);
971
- }
972
- fsm_dynamo_1.DyFM_Log.success(`\nHTTP (open) server is listening on port: ` +
973
- `${this.params.openHost}:${resolvedPort}`);
974
- resolve();
975
- })
976
- .on('error', (error) => {
977
- if (this.debugLog)
978
- fsm_dynamo_1.DyFM_Log.error(`\nHTTP (open) server ERROR`, error);
979
- if (!this.systemControls.httpServer.started) {
980
- const d_error = new fsm_dynamo_1.DyFM_Error({
981
- ...this._getDefaultErrorSettings('startExpresses', error),
982
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE3`,
983
- message: `HTTP (open) start server ERROR`,
984
- });
985
- this.constructErrors.push(d_error);
986
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
987
- reject(d_error);
988
- }
989
- else {
990
- const d_error = new fsm_dynamo_1.DyFM_Error({
991
- ...this._getDefaultErrorSettings('httpServer.on(error)', error),
992
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE4`,
993
- message: `HTTP (open) server ERROR`,
994
- level: fsm_dynamo_1.DyFM_ErrorLevel.serious,
995
- });
996
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
997
- }
998
- })
999
- .on('uncaughtException', (exception) => {
1000
- const d_error = new fsm_dynamo_1.DyFM_Error({
1001
- ...this._getDefaultErrorSettings('httpServer.on(uncaughtException)', exception),
1002
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE5`,
1003
- message: `HTTP (open) server uncaughtException`,
1004
- level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
1005
- });
1006
- if (this.debugLog) {
1007
- fsm_dynamo_1.DyFM_Log.warn(`\nHTTP (open) server uncaughtException`, d_error);
1008
- }
1009
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
1010
- });
1011
- });
1012
- }
1013
- }
1014
- catch (error) {
1015
- throw new fsm_dynamo_1.DyFM_Error({
1016
- ...this._getDefaultErrorSettings('startExpresses', error),
1017
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE0`,
1018
- });
1019
- }
1020
- }
1021
- /**
1022
- *
1023
- */
1024
- async expressErrorHandling(error, req, res, next) {
1025
- try {
1026
- if (error) {
1027
- const d_error = new fsm_dynamo_1.DyFM_Error({
1028
- ...this._getDefaultErrorSettings('expressErrorHandling', error),
1029
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-EEH1`,
1030
- message: `Express ERROR`,
1031
- additionalContent: {
1032
- req,
1033
- res,
1034
- },
1035
- level: fsm_dynamo_1.DyFM_ErrorLevel.error,
1036
- });
1037
- await global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error, req, res);
1038
- res.send(error);
1039
- }
1040
- else {
1041
- fsm_dynamo_1.DyFM_Log.H_error('WTF??? express error; without error?...' +
1042
- '\nerr:', error, '\nreq:', req, '\nres:', res);
1043
- }
1044
- }
1045
- catch (error) {
1046
- fsm_dynamo_1.DyFM_Log.H_error('MULTILEVEL ERROR (expressErrorHandling)....' +
1047
- '\n', error);
1048
- }
1049
- }
1050
- /**
1051
- *
1052
- */
1053
- async mountSecureRoutes() {
1054
- try {
1055
- if (this.fnLogs && this.deepLog)
1056
- fsm_dynamo_1.DyFM_Log.log('\nfn:. mountSecureRoutes');
1057
- if (!this.secureExpress) {
1058
- throw new Error('secureExpress was not initialized. ' +
1059
- 'Secure routes require getCertificationSettings and httpsPort, and cert files must exist.' +
1060
- '\n\nYou need to set security to secure or both in any route and set httpsPort in getPortSettings.' +
1061
- '\n\nYou need to set cert files in getCertificationSettings.');
1062
- }
1063
- this.secureExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
1064
- await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
1065
- if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
1066
- if (this.logSetup) {
1067
- fsm_dynamo_1.DyFM_Log.log(`route mount (secure): ${module.route}`);
1068
- }
1069
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
1070
- if (1 < existingRoutes.length) {
1071
- const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1072
- /* const errorStack: string[] = error.stack.split('\n');
1073
-
1074
- errorStack.splice(1, 4);
1075
- error.stack = errorStack.join('\n'); */
1076
- error.stack = module.stackLocation;
1077
- fsm_dynamo_1.DyFM_Log.S_error(`ROUTE DUPLICATION: ${module.route}`, error);
1078
- throw new fsm_dynamo_1.DyFM_Error({
1079
- ...this._getDefaultErrorSettings('mountSecureRoutes', error),
1080
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MSR1`,
1081
- message: `ROUTE DUPLICATION: ${module.route}`,
1082
- });
1083
- }
1084
- this.secureExpress.use(module.route, module.secureRouter);
1085
- }
1086
- });
1087
- }
1088
- catch (error) {
1089
- throw new fsm_dynamo_1.DyFM_Error({
1090
- ...this._getDefaultErrorSettings('mountSecureRoutes', error),
1091
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MSR0`,
1092
- });
1093
- }
1094
- }
1095
- /**
1096
- *
1097
- */
1098
- async mountOpenRoutes() {
1099
- try {
1100
- if (this.fnLogs && this.deepLog)
1101
- fsm_dynamo_1.DyFM_Log.log('\nfn:. mountOpenRoutes');
1102
- if (!this.openExpress) {
1103
- throw new Error('openExpress was not initialized. Open routes require getOpenExpress and httpPort.' +
1104
- '\n\nYou need to set security to open or both in any route and set httpPort in getPortSettings.');
1105
- }
1106
- this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
1107
- await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
1108
- if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
1109
- if (this.logSetup) {
1110
- fsm_dynamo_1.DyFM_Log.log(`route mount (open): ${module.route}`);
1111
- }
1112
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
1113
- if (1 < existingRoutes.length) {
1114
- const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1115
- /* const errorStack: string[] = error.stack.split('\n');
1116
-
1117
- errorStack.splice(1, 4);
1118
- error.stack = errorStack.join('\n'); */
1119
- error.stack = module.stackLocation;
1120
- fsm_dynamo_1.DyFM_Log.S_error(`ROUTE DUPLICATION: ${module.route}`, error);
1121
- throw new fsm_dynamo_1.DyFM_Error({
1122
- ...this._getDefaultErrorSettings('mountOpenRoutes', error),
1123
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MOR1`,
1124
- message: `ROUTE DUPLICATION: ${module.route}`,
1125
- });
1126
- }
1127
- this.openExpress.use(module.route, module.openRouter);
1128
- }
1129
- });
1130
- }
1131
- catch (error) {
1132
- throw new fsm_dynamo_1.DyFM_Error({
1133
- ...this._getDefaultErrorSettings('mountOpenRoutes', error),
1134
- errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MOR0`,
1135
- });
1136
- }
1137
- }
1138
- /**
1139
- * FR-041 — CORS middleware. Echoes a matching `Access-Control-Allow-Origin`
1140
- * for any request whose Origin header is in `getCorsSettings().allowedOrigins`,
1141
- * adds the canonical `Access-Control-*` companion headers, and short-circuits
1142
- * the OPTIONS preflight with a 204.
1143
- *
1144
- * No-op when the subclass does NOT override `getCorsSettings()` — preserves
1145
- * back-compat for apps that have always been same-origin and never needed
1146
- * CORS (the typical pre-FR-041 case).
1147
- *
1148
- * Why hand-rolled instead of the `cors` npm package:
1149
- * - ~30 lines, zero new dependency.
1150
- * - Full control over Vary/credentials/preflight semantics.
1151
- * - Aligns with FDP "no unnecessary deps" philosophy.
1152
- */
1153
- mountCors(express) {
1154
- const settings = this.getCorsSettings?.();
1155
- if (!settings) {
1156
- return;
1157
- }
1158
- const allowCreds = settings.allowCredentials !== false;
1159
- const methods = settings.allowedMethods ?? [
1160
- 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS',
1161
- ];
1162
- const headers = settings.allowedHeaders ?? [
1163
- 'Authorization', 'Content-Type', 'X-Admin-Key', 'X-Requested-With',
1164
- ];
1165
- const exposed = settings.exposedHeaders ?? [
1166
- 'Content-Length', 'Content-Type',
1167
- ];
1168
- const maxAge = settings.maxAgeSeconds ?? 86400;
1169
- const isAllowed = (origin) => {
1170
- if (settings.allowedOrigins === '*')
1171
- return true;
1172
- if (typeof settings.allowedOrigins === 'function') {
1173
- return settings.allowedOrigins(origin);
1174
- }
1175
- return settings.allowedOrigins.includes(origin);
1176
- };
1177
- express.use((req, res, next) => {
1178
- const origin = req.headers.origin;
1179
- if (origin && isAllowed(origin)) {
1180
- // Echo the matching origin (NOT wildcard) because credentials require it.
1181
- res.setHeader('Access-Control-Allow-Origin', origin);
1182
- if (allowCreds) {
1183
- res.setHeader('Access-Control-Allow-Credentials', 'true');
1184
- }
1185
- res.setHeader('Access-Control-Allow-Methods', methods.join(', '));
1186
- res.setHeader('Access-Control-Allow-Headers', headers.join(', '));
1187
- res.setHeader('Access-Control-Expose-Headers', exposed.join(', '));
1188
- res.setHeader('Access-Control-Max-Age', String(maxAge));
1189
- res.setHeader('Vary', 'Origin');
1190
- }
1191
- if (req.method === 'OPTIONS') {
1192
- res.status(204).end();
1193
- return;
1194
- }
1195
- next();
1196
- });
1197
- }
1198
- /**
1199
- * Generikus, auth-agnosztikus extension-point orchestrator. A `registerCustomMiddleware`
1200
- * hookot hívja (ha a subclass override-olja) minden AKTÍV Express instance-ra
1201
- * (open + secure), az API route-ok UTÁN, de a SPA static catch-all (`app.get('*')`)
1202
- * ELŐTT — ez az EGYETLEN korrekt pont egy sub-path middleware-hez (pl. reverse-proxy),
1203
- * mert a catch-all minden utána mountolt route-ot elnyel. No-op ha nincs override (back-compat).
1204
- */
1205
- async mountCustomMiddleware() {
1206
- if (!this.registerCustomMiddleware) {
1207
- return;
1208
- }
1209
- if (this.openExpress) {
1210
- await this.registerCustomMiddleware(this.openExpress, route_security_enum_1.DyNTS_RouteSecurity.open);
1211
- }
1212
- if (this.secureExpress) {
1213
- await this.registerCustomMiddleware(this.secureExpress, route_security_enum_1.DyNTS_RouteSecurity.secure);
1214
- }
1215
- if (this.logSetup) {
1216
- fsm_dynamo_1.DyFM_Log.log('\nCustom middleware registered (pre-static).');
1217
- }
1218
- }
1219
- /**
1220
- * Ha getStaticClientSettings() visszaad beállításokat, a client static fájlok a '/' alatt
1221
- * lesznek kiszolgálva (API route-ok után). SPA fallback opcionális (fallbackPath).
1222
- * Asset cache (assetCacheMaxAge, assetCacheImmutable) és fallback cache (fallbackCacheMaxAge)
1223
- * opcionálisak; ha nincs megadva fallbackCacheMaxAge, DyNTS_defaultFallbackCacheMaxAge (0) marad.
1224
- */
1225
- async mountStaticClient() {
1226
- const settings = this.getStaticClientSettings?.();
1227
- if (!settings) {
1228
- return;
1229
- }
1230
- const absoluteRoot = Path.isAbsolute(settings.root)
1231
- ? settings.root
1232
- : Path.resolve(process.cwd(), settings.root);
1233
- const hasAssetCache = settings.assetCacheMaxAge !== undefined || settings.assetCacheImmutable === true;
1234
- const staticOptions = hasAssetCache && settings.assetCacheMaxAge !== undefined
1235
- ? {
1236
- setHeaders: (res) => {
1237
- const maxAge = settings.assetCacheMaxAge;
1238
- const immutable = settings.assetCacheImmutable === true ? ', immutable' : '';
1239
- res.setHeader('Cache-Control', `max-age=${maxAge}${immutable}`);
1240
- },
1241
- }
1242
- : undefined;
1243
- const staticMiddleware = staticOptions
1244
- ? Express.static(absoluteRoot, staticOptions)
1245
- : Express.static(absoluteRoot);
1246
- const fallbackMaxAge = settings.fallbackCacheMaxAge ?? default_fallback_cache_max_age_const_1.DyNTS_defaultFallbackCacheMaxAge;
1247
- if (this.openExpress) {
1248
- this.openExpress.use('/', staticMiddleware);
1249
- if (settings.fallbackPath) {
1250
- this.openExpress.get('*', (req, res) => {
1251
- res.setHeader('Cache-Control', `max-age=${fallbackMaxAge}`);
1252
- res.sendFile(settings.fallbackPath, { root: absoluteRoot });
1253
- });
1254
- }
1255
- else {
1256
- this.openExpress.get('*', (req, res) => {
1257
- res.status(404).type('html').send(default_not_found_page_const_1.DyNTS_defaultNotFoundPageHtml);
1258
- });
1259
- }
1260
- }
1261
- if (this.secureExpress) {
1262
- this.secureExpress.use('/', staticMiddleware);
1263
- if (settings.fallbackPath) {
1264
- this.secureExpress.get('*', (req, res) => {
1265
- res.setHeader('Cache-Control', `max-age=${fallbackMaxAge}`);
1266
- res.sendFile(settings.fallbackPath, { root: absoluteRoot });
1267
- });
1268
- }
1269
- else {
1270
- this.secureExpress.get('*', (req, res) => {
1271
- res.status(404).type('html').send(default_not_found_page_const_1.DyNTS_defaultNotFoundPageHtml);
1272
- });
1273
- }
1274
- }
1275
- if (this.logSetup) {
1276
- fsm_dynamo_1.DyFM_Log.log(`\nStatic client mounted at / (root: ${absoluteRoot})`);
1277
- }
1278
- }
1279
- /**
1280
- *
1281
- */
1282
- setSecurity() {
1283
- if (this.fnLogs && this.deepLog)
1284
- fsm_dynamo_1.DyFM_Log.log('\nfn:. setSecurity');
1285
- this._routingModules.forEach((module) => {
1286
- if (!module.security) {
1287
- fsm_dynamo_1.DyFM_Log.warn(`RoutingModule security is not set for ${module.route}\n`);
1288
- }
1289
- else if (!this._security) {
1290
- this._security = module.security;
1291
- }
1292
- else if (this._security !== module.security) {
1293
- this._security = route_security_enum_1.DyNTS_RouteSecurity.both;
1294
- }
1295
- });
1296
- if (!this._security) {
1297
- let msg = `Could not set security for the server! (${this.security})`;
1298
- msg += '\n RoutingModules:';
1299
- this._routingModules.forEach((module) => {
1300
- msg += `\n ${module.route} (security: ${module.security})`;
1301
- });
1302
- if (this._routingModules.length === 0) {
1303
- msg += '\n - no RoutingModule found -\n';
1304
- }
1305
- fsm_dynamo_1.DyFM_Log.warn(msg);
1306
- }
1307
- }
1308
- _getDefaultErrorSettings(fnName, error) {
1309
- return {
1310
- status: error?.___status ?? 500,
1311
- message: error?.message ??
1312
- error?._message ??
1313
- `${fnName} was UNSUCCESSFUL (NTS)`,
1314
- userMessage: error?.__userMessage ?? this.defaultErrorUserMsg,
1315
- addECToUserMsg: !error?.__userMessage,
1316
- issuerService: `${this?.constructor?.name}-DyNTS_App`,
1317
- level: fsm_dynamo_1.DyFM_ErrorLevel.fatal,
1318
- error: error,
1319
- systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
1320
- };
1321
- }
1322
- }
1323
- exports.DyNTS_App = DyNTS_App;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DyNTS_App = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const Mongoose = require("mongoose");
6
+ const Express = require("express");
7
+ /* import Mongoose from 'mongoose';
8
+ import Express from 'express'; */
9
+ const BodyParser = tslib_1.__importStar(require("body-parser"));
10
+ const FileSystem = tslib_1.__importStar(require("fs"));
11
+ const Https = tslib_1.__importStar(require("https"));
12
+ const Path = tslib_1.__importStar(require("path"));
13
+ /* import { version } from '../../../package.json'; */
14
+ const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
15
+ const default_fallback_cache_max_age_const_1 = require("../../_collections/default-fallback-cache-max-age.const");
16
+ const default_not_found_page_const_1 = require("../../_collections/default-not-found-page.const");
17
+ const global_settings_const_1 = require("../../_collections/global-settings.const");
18
+ const mongo_reconnect_guard_util_1 = require("../../_collections/mongo-reconnect-guard.util");
19
+ const route_security_enum_1 = require("../../_enums/route-security.enum");
20
+ const app_system_controls_control_model_1 = require("../../_models/control-models/app-system-controls.control-model");
21
+ const http_settings_control_model_1 = require("../../_models/control-models/http-settings.control-model");
22
+ const singleton_service_1 = require("../base/singleton.service");
23
+ const global_service_1 = require("../core/global.service");
24
+ const memory_guard_service_1 = require("../core/memory-guard.service");
25
+ /**
26
+ *
27
+ * function MyDecorator(config: any) {
28
+ return function (target: Function) {
29
+ // attach metadata or modify target
30
+ target.prototype.myMeta = config;
31
+ };
32
+ }
33
+
34
+ @MyDecorator({ role: 'admin' })
35
+ class User {
36
+ printRole() {
37
+ console.log((this as any).myMeta.role); // → "admin"
38
+ }
39
+ }
40
+
41
+ */
42
+ /**
43
+ * This will be the MAIN service of our server project,
44
+ * follow the types and type instructions while setting up your project
45
+ *
46
+ * In this service, there are abstract functions that you will need to implement,
47
+ * where you need to set up the main params for your application.
48
+ *
49
+ * (after the example, you can find the list of services you can/should setup)
50
+ *
51
+ * @example
52
+ * export class App extends DyNTS_AppExtended {
53
+ *
54
+ * ...
55
+ *
56
+ * // Setting up App params, and preparing project global settings
57
+ * setupAppParams(): void {
58
+ * this.params = new DyNTS_AppParams({
59
+ * name: 'Warbots Server',
60
+ * title: warbotsTitleLog,
61
+ * version: version,
62
+ * dbName: 'warbots',
63
+ * });
64
+ *
65
+ * // dynamoNTS_GlobalSettings.logRequestsContent = false;
66
+ * }
67
+ *
68
+ * ...
69
+ *
70
+ * // Setting up DBServices
71
+ * setGlobalServiceCollection(): void {
72
+ * DyNTS_GlobalService.setServices({
73
+ * authService: AuthService.getInstance(),
74
+ * emailServiceCollection: EmailServiceCollectionService.getInstance(),
75
+ * dbModels: [
76
+ * userModelParams,
77
+ * userDataModelParams,
78
+ * userOptionsModelParams,
79
+ * userStatisticsModelParams,
80
+ * userAchievementsModelParams,
81
+ * userNotificationsModelParams,
82
+ *
83
+ * matchStatisticsModelParams,
84
+ * matchDataModelParams,
85
+
86
+ * DyFM_usageSession_dataParams,
87
+ * DyFM_customData_dataParams,
88
+ * ]
89
+ * });
90
+ * }
91
+ *
92
+ * ...
93
+ *
94
+ * // Setting up Routes
95
+ * setupRoutingModules(): void {
96
+ * this.httpPort = env.port;
97
+
98
+ * this.routingModules = [
99
+ * new DyNTS_RoutingModule({
100
+ * route: '/user',
101
+ * controllers: [
102
+ * UserController.getInstance(),
103
+ * UserDataController.getInstance(),
104
+ * UserOptionsController.getInstance(),
105
+ * UserStatisticsController.getInstance(),
106
+ * UserAchievementsController.getInstance(),
107
+ * UserNotificationsController.getInstance()
108
+ * ]
109
+ * }),
110
+ * new DyNTS_RoutingModule({
111
+ * route: '/match',
112
+ * controllers: [
113
+ * MatchController.getInstance(),
114
+ * MatchDistributionController.getInstance(),
115
+ * MatchStatisticsController.getInstance(),
116
+ * ]
117
+ * }),
118
+ * new DyNTS_RoutingModule({
119
+ * route: '/server',
120
+ * controllers: [
121
+ * ServerController.getInstance(),
122
+ * ]
123
+ * }),
124
+
125
+ * getTestRoutingModule(),
126
+ * getUsageRoutingModule()
127
+ * ];
128
+ * }
129
+ * }
130
+ *
131
+ * //
132
+ * // The Services available
133
+ * //
134
+ * // Authentication Service
135
+ * // A commonly used basic service,
136
+ * // which is necessary fur certain functions (such as registering call issuers)
137
+ * //
138
+ * // This will handle Authentication Token checking/refreshing,
139
+ * // checking issuer's identifier and routeParams,
140
+ * // handling JWT Token, or maybe with OAuth2 or other commonly used security procedures
141
+ * //
142
+ * // You can create one with this Dynamo Object:
143
+ * //
144
+ *
145
+ * @example
146
+ * // follow the instructions on the abstract class (DyNTS_AuthService)
147
+ * export class AuthService extends DyNTS_AuthService {}
148
+ *
149
+ *
150
+ *
151
+ * //
152
+ */
153
+ /**
154
+ * This will be the MAIN service of our server project,
155
+ * follow the types and type instructions while setting up your project
156
+ *
157
+ * In this service, there are abstract functions that you will need to implement,
158
+ * where you need to set up the main params for your application.
159
+ *
160
+ * (after the example, you can find the list of services you can/should setup)
161
+ *
162
+ * You need to setup the following functions:
163
+ * ```ts
164
+ * // this is where you set up the main params for your application
165
+ * getAppParams(): DyNTS_AppParams
166
+ *
167
+ * // this is where you connect your main services
168
+ * getGlobalServiceSettings(): DyNTS_GlobalService_Settings
169
+ *
170
+ * // this is where you set up your ports
171
+ * getPorts(): DyNTS_PortSettings
172
+ *
173
+ * // this is where you set up your routes
174
+ * getRoutingModules(): DyNTS_RoutingModule[]
175
+ *
176
+ *
177
+ *
178
+ * ```
179
+ * optionally you can setup the following functions:
180
+ * ```ts
181
+ * // this is where you set up your certifications
182
+ * getCertificationSettings(): DyNTS_CertificationSettings
183
+ *
184
+ * // this is where you set up additional root services
185
+ * getRootServices(): DyNTS_SingletonService[]
186
+ *
187
+ * // this is where you set up your initial db entries
188
+ * createEntries(): void
189
+ *
190
+ * // this is where you can define post setup processes
191
+ * postProcess(): void
192
+ *
193
+ *
194
+ *
195
+ * ```
196
+ *
197
+ */
198
+ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
199
+ systemControls = new app_system_controls_control_model_1.DyNTS_AppSystemControls();
200
+ get started() {
201
+ return this.systemControls.app.started;
202
+ }
203
+ get superStarted() {
204
+ return this.systemControls.app.started;
205
+ }
206
+ constructErrors = [];
207
+ /* removed since cant use version from package.json
208
+ private readonly _ntsVersion: string = 'v01.07.18';
209
+ protected get ntsVersion(): string {
210
+ return this._ntsVersion;
211
+ } */
212
+ get serverName() {
213
+ return this.params.name;
214
+ }
215
+ _params;
216
+ get params() {
217
+ return this._params;
218
+ }
219
+ mongoose = Mongoose;
220
+ _security;
221
+ get security() {
222
+ return this._security;
223
+ }
224
+ _portSettings = new http_settings_control_model_1.DyNTS_Http_Settings();
225
+ get portSettings() {
226
+ return this._portSettings;
227
+ }
228
+ _cert;
229
+ get cert() {
230
+ return this._cert;
231
+ }
232
+ openExpress;
233
+ secureExpress;
234
+ httpsServer;
235
+ httpServer;
236
+ globalService;
237
+ _rootServices = [];
238
+ _routingModules = [];
239
+ defaultReadyTimeout = 30 * fsm_dynamo_1.second;
240
+ defaultErrorUserMsg = `We encountered an unhandled Server Error, ` +
241
+ `\nplease contact the responsible development team.` +
242
+ `\n(Internal Server error)`;
243
+ get logSetup() {
244
+ return global_settings_const_1.DyNTS_global_settings.log_settings.setup;
245
+ }
246
+ get deepLog() {
247
+ return global_settings_const_1.DyNTS_global_settings.log_settings.deep;
248
+ }
249
+ get fnLogs() {
250
+ return global_settings_const_1.DyNTS_global_settings.log_settings.functions;
251
+ }
252
+ debugLog = global_settings_const_1.DyNTS_global_settings.log_settings.server_debug;
253
+ constructor( /* extended?: boolean */) {
254
+ super();
255
+ /* dotenv.config() */
256
+ process.on('unhandledRejection', (reason_theError, p_passWhatIsThis_maybeThePromise) => {
257
+ if (reason_theError instanceof fsm_dynamo_1.DyFM_Error) {
258
+ reason_theError.logSimple('Unhandled Rejection');
259
+ }
260
+ else {
261
+ fsm_dynamo_1.DyFM_Log.H_error('Unhandled Rejection:', p_passWhatIsThis_maybeThePromise?.toString(), '\n Rejection reason:', reason_theError?.stack?.split('at')?.[0],
262
+ /* '\n ErrorCode:', (reason as any)?.code, */
263
+ '\n\n Stack:', reason_theError?.stack?.replaceAll?.('\n at', '\n at'));
264
+ }
265
+ try {
266
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(new fsm_dynamo_1.DyFM_Error({
267
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-BASE-UR`,
268
+ message: `Unhandled Rejection!: "${reason_theError?.stack?.split('at')?.[0]}"`,
269
+ userMessage: this.defaultErrorUserMsg,
270
+ addECToUserMsg: true,
271
+ error: reason_theError,
272
+ additionalContent: {
273
+ reason: reason_theError,
274
+ rejectedPromise: p_passWhatIsThis_maybeThePromise,
275
+ },
276
+ systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
277
+ level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
278
+ }));
279
+ }
280
+ catch (error) {
281
+ fsm_dynamo_1.DyFM_Log.error('globalErrorHandler (MULTILEVEL) ERROR:', error);
282
+ }
283
+ });
284
+ this.asyncConstruct( /* extended */).catch((error) => {
285
+ if (error instanceof fsm_dynamo_1.DyFM_Error) {
286
+ if (error.additionalContent?.constructErrors?.length) {
287
+ error.additionalContent.constructErrors.forEach((errorItem) => {
288
+ fsm_dynamo_1.DyFM_Error.logSimple('(constructor asyncConstruct.catch) error:', errorItem);
289
+ /* if (errorItem instanceof DyFM_Error) {
290
+ errorItem.logSimple(`(constructor asyncConstruct.catch) error:\n`);
291
+ } else {
292
+ DyFM_Log.H_warn(
293
+ '(constructor asyncConstruct.catch) additional error content:\n',
294
+ errorItem
295
+ );
296
+ } */
297
+ });
298
+ }
299
+ else {
300
+ fsm_dynamo_1.DyFM_Log.H_warn('(constructor asyncConstruct.catch) additional error content:\n', error?.additionalContent);
301
+ }
302
+ }
303
+ fsm_dynamo_1.DyFM_Error.logSimple('(constructor asyncConstruct.catch) error:', error);
304
+ /* if (
305
+ !DyNTS_global_settings.log_settings.highDetailedLogs &&
306
+ (error instanceof DyFM_Error)
307
+ ) {
308
+ error.logSimple(
309
+ `Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)` +
310
+ '\n all error messages (from this stack):\n\n"' +
311
+ error._messages.join('"\n\n"') + '"\n\n'
312
+ );
313
+ } else if (error instanceof DyFM_Error) {
314
+ DyFM_Log.H_error(
315
+ `Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)`,
316
+ `\n ERROR:`, error
317
+ );
318
+ } */
319
+ const message = error?.additionalContent?.constructErrors?.flatMap((errorItem) => {
320
+ return errorItem?._messages ?? [];
321
+ })?.join?.('\n') ??
322
+ error?.errors?.flatMap((errorItem) => errorItem?._messages ?? [errorItem?.message])?.join?.('\n') ??
323
+ error?.message ??
324
+ 'UNKNOWN';
325
+ fsm_dynamo_1.DyFM_Log.testError('Application start failed:\n', message);
326
+ process.exit(1);
327
+ });
328
+ }
329
+ async asyncConstruct(extended) {
330
+ if (this.fnLogs && this.deepLog)
331
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. asyncConstruct');
332
+ try {
333
+ this.systemControls.app.init = true;
334
+ this._params = this.getAppParams();
335
+ fsm_dynamo_1.DyFM_Log.log(`\n\n\n\n\n\n\n\n\n\n` +
336
+ `Starting ${this._params?.name}... ` +
337
+ /* `v${version}` + */
338
+ `\n\n\n\n\n\n\n\n\n\n`);
339
+ if (!this._params) {
340
+ throw new Error('getAppParams() must return a DyNTS_AppParams object!');
341
+ }
342
+ if (this.params.systemShortCodeName) {
343
+ global_settings_const_1.DyNTS_global_settings.systemShortCodeName = this.params.systemShortCodeName;
344
+ }
345
+ if (this.params.systemName) {
346
+ global_settings_const_1.DyNTS_global_settings.systemName = this.params.systemName;
347
+ fsm_dynamo_1.DyFM_error_defaults.issuerSystem = this.params.systemName;
348
+ }
349
+ if (this.params.version) {
350
+ global_settings_const_1.DyNTS_global_settings.systemVersion = this.params.version;
351
+ fsm_dynamo_1.DyFM_error_defaults.systemVersion = this.params.version;
352
+ }
353
+ process.stdout.write(String.fromCharCode(27) + ']0;' +
354
+ this._params?.name +
355
+ String.fromCharCode(7));
356
+ fsm_dynamo_1.DyFM_error_defaults.issuerSystem = this._params.systemName;
357
+ this.overrideDynamoNTSGlobalSettings?.();
358
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.setup) {
359
+ fsm_dynamo_1.DyFM_Log.S_info(`env settings;\n`, {
360
+ systemName: global_settings_const_1.DyNTS_global_settings.systemName,
361
+ systemShortCodeName: global_settings_const_1.DyNTS_global_settings.systemShortCodeName,
362
+ systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
363
+ environment: global_settings_const_1.DyNTS_global_settings.env_settings.environment,
364
+ /* log_settings: DyNTS_global_settings.log_settings,
365
+ env_settings: DyNTS_global_settings.env_settings, */
366
+ });
367
+ }
368
+ this.globalService = global_service_1.DyNTS_GlobalService.getInstance();
369
+ await global_service_1.DyNTS_GlobalService.setServices(this.getGlobalServiceCollection());
370
+ global_service_1.DyNTS_GlobalService.setParams(this.params);
371
+ if (this.getPortSettings) {
372
+ this._portSettings = this.getPortSettings();
373
+ }
374
+ if (this.getCertificationSettings) {
375
+ this._cert = this.getCertificationSettings();
376
+ }
377
+ if (this.getApiBasePath) {
378
+ global_settings_const_1.DyNTS_global_settings.baseUrl = this.getApiBasePath();
379
+ }
380
+ if (this.getRoutingModules) {
381
+ this._routingModules = this.getRoutingModules();
382
+ // ezt egyelőre csak tesztelem, nem kerül be
383
+ /* if (
384
+ !DyNTS_global_settings.dontCreateDefaultRoute &&
385
+ !this._routingModules.some((routingModule: DyNTS_RoutingModule): boolean => routingModule.route === '/*')
386
+ ) {
387
+ this._routingModules.push(
388
+ DyNTS_getStarRoute()
389
+ );
390
+ } */
391
+ }
392
+ if (this._params.dbUri) {
393
+ await this.startDB();
394
+ // createEntries csak akkor fut, ha a DB tényleg fel-jött.
395
+ // Ha a startDB jelezte a hibát, de továbbment, akkor a started flag false marad,
396
+ // és nem próbálunk meg írni egy nem létező kapcsolatra.
397
+ if (this.createEntries && this.systemControls.mongoose.started) {
398
+ await this.createEntries();
399
+ }
400
+ }
401
+ else {
402
+ fsm_dynamo_1.DyFM_Log.log(`\nNo database connection created.`);
403
+ }
404
+ if (this._routingModules?.length) {
405
+ if (this.logSetup)
406
+ fsm_dynamo_1.DyFM_Log.log('\nsetting up express routes...');
407
+ this.setSecurity();
408
+ await this.initExpresses();
409
+ await this.startExpresses();
410
+ if (this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
411
+ await this.mountOpenRoutes();
412
+ }
413
+ if (this._security !== route_security_enum_1.DyNTS_RouteSecurity.open && this._cert) {
414
+ await this.mountSecureRoutes();
415
+ }
416
+ // Generikus, auth-agnosztikus extension-point: custom middleware az API
417
+ // route-ok UTÁN, de a SPA static catch-all (mountStaticClient) ELŐTT.
418
+ await this.mountCustomMiddleware();
419
+ await this.mountStaticClient();
420
+ if (this.logSetup) {
421
+ fsm_dynamo_1.DyFM_Log.log(`\nRoutes mounted.... server using security: ${this._security}`);
422
+ }
423
+ }
424
+ else {
425
+ fsm_dynamo_1.DyFM_Log.warn(`\nNo routes mounted!`);
426
+ }
427
+ if (this.getRootServices) {
428
+ this._rootServices = await this.getRootServices();
429
+ }
430
+ if (this.postProcess) {
431
+ await this.postProcess().catch((error) => {
432
+ fsm_dynamo_1.DyFM_Error.logSimple(`"${this._params.name}" postProcess failed:`, error);
433
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(error);
434
+ });
435
+ }
436
+ // FR-193 — bedrock OOM korai-figyelmeztetés: feltelepítjük a heap-watchdogot, ha
437
+ // engedélyezve (DyNTS_global_settings.memoryGuard.enabled, default true). Biztonságos:
438
+ // a guard egy könnyű setInterval, ami SOHA nem dob; csak near-OOM küszöböknél hagy
439
+ // tartós nyomot az error-sinkbe, mielőtt a fatal heap-OOM megölné a process-t.
440
+ try {
441
+ if (global_settings_const_1.DyNTS_global_settings.memoryGuard?.enabled) {
442
+ memory_guard_service_1.DyNTS_MemoryGuard.getInstance().install();
443
+ }
444
+ }
445
+ catch (memoryGuardError) {
446
+ fsm_dynamo_1.DyFM_Log.warn('[DyNTS_MemoryGuard] auto-install skipped (non-fatal):', memoryGuardError);
447
+ }
448
+ if (!extended) {
449
+ await this.ready();
450
+ if (this.params.title) {
451
+ fsm_dynamo_1.DyFM_Log.success(this.params.title);
452
+ }
453
+ fsm_dynamo_1.DyFM_Log.info(`Version: ${this.params.version}`);
454
+ /* DyFM_Log.info(`NTS Version: ${this.ntsVersion}`); */
455
+ fsm_dynamo_1.DyFM_Log.H_success(`${this.params.name} started successfully.`);
456
+ }
457
+ }
458
+ catch (error) {
459
+ this.constructErrors.push(error);
460
+ if (this.deepLog) {
461
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
462
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed (in asyncConstruct (highDetailedLog)). `, `\n\n construct ERRORS:`, this.constructErrors, '\n\nlast error:', error);
463
+ }
464
+ else {
465
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed (in asyncConstruct). `, `\n\n construct ERRORS:`, this.getSimplifiedConstructErrors(), '\n\nlast error:', error instanceof fsm_dynamo_1.DyFM_Error ? error.getErrorSimplified() : error);
466
+ }
467
+ }
468
+ throw new fsm_dynamo_1.DyFM_Error({
469
+ ...this._getDefaultErrorSettings('asyncConstruct', error),
470
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-001`,
471
+ additionalContent: {
472
+ constructErrors: this.constructErrors,
473
+ systemControls: this.systemControls,
474
+ systemReadies: {
475
+ app: this.systemControls.app.getIsReady(),
476
+ mongoose: this.systemControls.mongoose.getIsReady(),
477
+ httpServer: this.systemControls.httpServer.getIsReady(),
478
+ httpsServer: this.systemControls.httpsServer.getIsReady(),
479
+ },
480
+ },
481
+ });
482
+ }
483
+ }
484
+ async ready(timeout = this.defaultReadyTimeout) {
485
+ try {
486
+ if (this.fnLogs)
487
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. ready');
488
+ await fsm_dynamo_1.DyFM_Async.delay(100);
489
+ let ready = false;
490
+ const start = +new Date();
491
+ if (this.constructErrors.length) {
492
+ if (this.deepLog) {
493
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
494
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 1)`, `\n construct ERRORS:`, this.constructErrors);
495
+ }
496
+ else {
497
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 1)`, `\n construct ERRORS:`, this.getSimplifiedConstructErrors());
498
+ }
499
+ }
500
+ throw new fsm_dynamo_1.DyFM_Error({
501
+ ...this._getDefaultErrorSettings('ready', new Error(`"${this._params.name}" start failed.`)),
502
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R01`,
503
+ additionalContent: this.constructErrors.length === 1 ?
504
+ { error: this.constructErrors[0] } :
505
+ { errors: this.constructErrors },
506
+ });
507
+ }
508
+ while (!ready && +new Date() - start < timeout) {
509
+ if (this.systemControls.app.init) {
510
+ ready = (this.systemControls.mongoose.getIsReady() &&
511
+ this.systemControls.httpServer.getIsReady() &&
512
+ this.systemControls.httpsServer.getIsReady());
513
+ }
514
+ else {
515
+ fsm_dynamo_1.DyFM_Log.error(`"${this._params.name}" APP NOT INITIALIZED while trying to get ready.`);
516
+ }
517
+ if (!ready) {
518
+ await fsm_dynamo_1.DyFM_Async.wait(100);
519
+ }
520
+ }
521
+ if (timeout < +new Date() - start) {
522
+ if (this.deepLog) {
523
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
524
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; TIMEOUT check)`, `\n construct ERRORS:`, this.constructErrors);
525
+ }
526
+ else {
527
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; TIMEOUT check)`, `\n construct ERRORS:`, this.getSimplifiedConstructErrors());
528
+ }
529
+ }
530
+ throw new fsm_dynamo_1.DyFM_Error({
531
+ ...this._getDefaultErrorSettings('ready', new Error(`"${this._params.name}" start failed. TIMEOUT`)),
532
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R02`,
533
+ additionalContent: {
534
+ constructErrors: this.constructErrors,
535
+ systemControls: this.systemControls,
536
+ systemReadies: {
537
+ mongoose: this.systemControls.mongoose.getIsReady(),
538
+ httpServer: this.systemControls.httpServer.getIsReady(),
539
+ httpsServer: this.systemControls.httpsServer.getIsReady(),
540
+ },
541
+ },
542
+ });
543
+ }
544
+ if (this.constructErrors.length) {
545
+ if (this.deepLog) {
546
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
547
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 2)`, `\n construct ERRORS:`, this.constructErrors);
548
+ }
549
+ else {
550
+ fsm_dynamo_1.DyFM_Log.H_error(`"${this._params.name}" start failed. (ready; constructErrors check 2)`, `\n construct ERRORS:`, this.getSimplifiedConstructErrors());
551
+ }
552
+ }
553
+ throw new fsm_dynamo_1.DyFM_Error({
554
+ ...this._getDefaultErrorSettings('ready', new Error(`"${this._params.name}" start failed.`)),
555
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R03`,
556
+ additionalContent: this.constructErrors,
557
+ });
558
+ }
559
+ if (ready) {
560
+ this.systemControls.app.started = true;
561
+ if (this.fnLogs && this.deepLog)
562
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. ready: return');
563
+ return;
564
+ }
565
+ this.systemControls.app.started = false;
566
+ let msg = `"${this._params.name}" start failed. UNKNOWN`;
567
+ if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
568
+ msg += `\nMongoose start failed.`;
569
+ }
570
+ if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
571
+ msg += `\nHTTP Server start failed.`;
572
+ }
573
+ if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
574
+ msg += `\nHTTPS Server start failed.`;
575
+ }
576
+ fsm_dynamo_1.DyFM_Log.error(msg, this.constructErrors);
577
+ throw new fsm_dynamo_1.DyFM_Error({
578
+ ...this._getDefaultErrorSettings('ready', new Error(msg)),
579
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-R04`,
580
+ additionalContent: {
581
+ constructErrors: this.constructErrors,
582
+ systemControls: this.systemControls,
583
+ systemReadies: {
584
+ app: this.systemControls.app.getIsReady(),
585
+ mongoose: this.systemControls.mongoose.getIsReady(),
586
+ httpServer: this.systemControls.httpServer.getIsReady(),
587
+ httpsServer: this.systemControls.httpsServer.getIsReady(),
588
+ },
589
+ },
590
+ error: this.constructErrors?.[0] ?? new Error(),
591
+ });
592
+ }
593
+ catch (error) {
594
+ throw new fsm_dynamo_1.DyFM_Error({
595
+ ...this._getDefaultErrorSettings('ready', error),
596
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-READY0`,
597
+ });
598
+ }
599
+ }
600
+ getSimplifiedConstructErrors() {
601
+ return this.constructErrors.map((error) => {
602
+ if (error instanceof fsm_dynamo_1.DyFM_Error) {
603
+ return error.getErrorSimplified();
604
+ }
605
+ else {
606
+ return error;
607
+ }
608
+ });
609
+ }
610
+ async stop(dontLog) {
611
+ try {
612
+ fsm_dynamo_1.DyFM_Log.info('\nstopping server...\n');
613
+ await this.ready();
614
+ if (this.started) {
615
+ if (this.systemControls.mongoose.init) {
616
+ fsm_dynamo_1.DyFM_Log.info(`\nstopping Mongoose....`);
617
+ let tryCount = 0;
618
+ while (!this.systemControls.mongoose.started &&
619
+ !this.constructErrors.length &&
620
+ tryCount++ < 10) {
621
+ fsm_dynamo_1.DyFM_Log.warn(`Mongoose not even started yet....`);
622
+ await fsm_dynamo_1.DyFM_Async.wait(fsm_dynamo_1.second);
623
+ }
624
+ this.systemControls.mongoose.started = false;
625
+ if (this.mongoose) {
626
+ await fsm_dynamo_1.DyFM_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
627
+ this.mongoose.deleteModel(modelName);
628
+ });
629
+ const disconnect = new Promise((resolve) => {
630
+ this.mongoose.connection.on('disconnecting', () => {
631
+ resolve();
632
+ });
633
+ });
634
+ await this.mongoose.disconnect();
635
+ await this.mongoose.connection.close();
636
+ await disconnect;
637
+ this.mongoose.connection.removeAllListeners();
638
+ while (this.mongoose.connection.readyState !== 0 &&
639
+ !this.constructErrors.length) {
640
+ fsm_dynamo_1.DyFM_Log.warn(`\nMongoose still not disconnected....`);
641
+ await fsm_dynamo_1.DyFM_Async.wait(fsm_dynamo_1.second);
642
+ }
643
+ }
644
+ else {
645
+ fsm_dynamo_1.DyFM_Log.error(`\nMongoose not found.`);
646
+ }
647
+ this.systemControls.mongoose.init = false;
648
+ }
649
+ if (this.systemControls.httpServer.init) {
650
+ this.systemControls.httpServer.started = false;
651
+ if (this.httpServer) {
652
+ await new Promise((resolve) => {
653
+ this.httpServer.close(resolve);
654
+ });
655
+ }
656
+ else {
657
+ fsm_dynamo_1.DyFM_Log.error(`\nHTTP Server not found.`);
658
+ }
659
+ this.systemControls.httpServer.init = false;
660
+ }
661
+ if (this.systemControls.httpsServer.init) {
662
+ this.systemControls.httpsServer.started = false;
663
+ if (this.httpsServer) {
664
+ await new Promise((resolve) => {
665
+ this.httpsServer.close(resolve);
666
+ });
667
+ }
668
+ else {
669
+ fsm_dynamo_1.DyFM_Log.error(`\nHTTPS Server not found.`);
670
+ }
671
+ this.systemControls.httpsServer.init = false;
672
+ }
673
+ await fsm_dynamo_1.DyFM_Async.wait(fsm_dynamo_1.second);
674
+ if (!dontLog) {
675
+ fsm_dynamo_1.DyFM_Log.H_log(`"${this._params.name}" stopped successfully.`);
676
+ }
677
+ }
678
+ }
679
+ catch (error) {
680
+ throw new fsm_dynamo_1.DyFM_Error({
681
+ ...this._getDefaultErrorSettings('stop', error),
682
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-STOP0`,
683
+ });
684
+ }
685
+ }
686
+ /**
687
+ *
688
+ */
689
+ async startDB() {
690
+ if (this.fnLogs && this.deepLog)
691
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. startDB');
692
+ else if (this.logSetup)
693
+ fsm_dynamo_1.DyFM_Log.log('\nstarting DB connection...');
694
+ if (!this._params.dbUri) {
695
+ throw new fsm_dynamo_1.DyFM_Error({
696
+ ...this._getDefaultErrorSettings('startDB', new Error('DB URI is not set.')),
697
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
698
+ });
699
+ }
700
+ if (!this._params.dbOptions) {
701
+ throw new fsm_dynamo_1.DyFM_Error({
702
+ ...this._getDefaultErrorSettings('startDB', new Error('DB OPTIONS are not set.')),
703
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
704
+ });
705
+ }
706
+ if (this.systemControls.mongoose.init || this.systemControls.mongoose.started) {
707
+ throw new fsm_dynamo_1.DyFM_Error({
708
+ ...this._getDefaultErrorSettings('startDB', new Error('Mongoose is already initialized.')),
709
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
710
+ });
711
+ }
712
+ try {
713
+ await new Promise((resolve, reject) => {
714
+ this.systemControls.mongoose.init = true;
715
+ this.mongoose.connection
716
+ .once('open', () => {
717
+ this.systemControls.mongoose.started = true;
718
+ fsm_dynamo_1.DyFM_Log.success(`\nConnected to MongoDB (${this._params.dbUri})\n`);
719
+ resolve();
720
+ })
721
+ .on('error', (error) => {
722
+ if (!this.systemControls.mongoose.started) {
723
+ // Initial DB-csatlakozás sikertelen:
724
+ // jelezzük a hibát (log + globalErrorHandler), de NEM szakítjuk meg az
725
+ // App startup-ot (nincs constructErrors push, nincs reject).
726
+ // A mongoose.init-et resetteljük, hogy a ready() ne várjon a DB-re.
727
+ // Ha a mongoose később mégis tudna csatlakozni, az 'open' event
728
+ // beállítja a started flag-et, így a runtime DB-műveletek elindulnak.
729
+ this.systemControls.mongoose.init = false;
730
+ const d_error = new fsm_dynamo_1.DyFM_Error({
731
+ ...this._getDefaultErrorSettings('startDB', error),
732
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB1`,
733
+ message: `Unable to connect to MongoDB server (${this._params.dbUri}), ` +
734
+ `ERROR: ${error}`,
735
+ level: fsm_dynamo_1.DyFM_ErrorLevel.serious,
736
+ });
737
+ fsm_dynamo_1.DyFM_Log.H_error(`\nUnable to connect to MongoDB server (${this._params.dbUri}).` +
738
+ `\nServer will continue WITHOUT DB connection.` +
739
+ `\nDB-using endpoints will fail at runtime until connection recovers.`);
740
+ if (this.debugLog)
741
+ fsm_dynamo_1.DyFM_Log.S_error(`\nMongoDB connect ERROR: `, error);
742
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
743
+ resolve();
744
+ }
745
+ else {
746
+ if (this.debugLog)
747
+ fsm_dynamo_1.DyFM_Log.error('\nMongoDB ERROR: ', error);
748
+ const d_error = new fsm_dynamo_1.DyFM_Error({
749
+ ...this._getDefaultErrorSettings('mongoose.connection.on(error)', error),
750
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB2`,
751
+ message: `MongoDB ERROR: ${error}`,
752
+ level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
753
+ });
754
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
755
+ }
756
+ });
757
+ try {
758
+ this.mongoose.connect(this._params.dbUri, this._params.dbOptions
759
+ /* {
760
+ directConnection: true,
761
+ } */
762
+ );
763
+ }
764
+ catch (error) {
765
+ throw new fsm_dynamo_1.DyFM_Error({
766
+ ...this._getDefaultErrorSettings('startDB', error),
767
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB3`,
768
+ });
769
+ }
770
+ });
771
+ }
772
+ catch (error) {
773
+ throw new fsm_dynamo_1.DyFM_Error({
774
+ ...this._getDefaultErrorSettings('startDB', error),
775
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SDB0`,
776
+ });
777
+ }
778
+ // 2026-06-20 — Mongo reconnect-guard. A MongoDB-driver a hostnevet connect-kor EGYSZER
779
+ // resolválja + cache-eli az IP-t; ha a Mongo-konténert recreate-elik (új docker-network IP),
780
+ // a driver a HALOTT IP-n ragad → ECONNREFUSED + buffering-timeout, és a service magától SOHA
781
+ // nem áll vissza. A guard sustained-disconnect (readyState !== 1) esetén — a driver saját
782
+ // grace-e UTÁN — TELJES disconnect()+connect()-et csinál → ÚJ MongoClient → ÚJ DNS-resolve →
783
+ // új IP → reconnect. Best-effort, always-on, healthy connection-t (===1) SOHA nem bánt; csak
784
+ // konténer-IP-frissítés, nem ír adatot. Lásd: mongo-reconnect-guard.util.ts.
785
+ try {
786
+ (0, mongo_reconnect_guard_util_1.startMongoReconnectGuard)({
787
+ getReadyState: () => this.mongoose.connection.readyState,
788
+ reconnect: async () => {
789
+ await this.mongoose.disconnect().catch(() => undefined);
790
+ await this.mongoose.connect(this._params.dbUri, this._params.dbOptions);
791
+ },
792
+ log: (msg) => fsm_dynamo_1.DyFM_Log.warn(msg),
793
+ });
794
+ }
795
+ catch (guardErr) {
796
+ fsm_dynamo_1.DyFM_Log.warn(`[mongo-reconnect-guard] failed to start (non-fatal): ${guardErr instanceof Error ? guardErr.message : String(guardErr)}`);
797
+ }
798
+ }
799
+ /**
800
+ *
801
+ */
802
+ async initExpresses() {
803
+ if (this.fnLogs && this.deepLog)
804
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. initExpresses');
805
+ try {
806
+ if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
807
+ if (this._portSettings.httpPort === undefined || this._portSettings.httpPort === null) {
808
+ let errorMsg = `\nYou have open routes, but httpPort is not set!` +
809
+ `\nThere are ${this._routingModules.filter(m => m.security != route_security_enum_1.DyNTS_RouteSecurity.secure).length} open/both routes` +
810
+ `\nroot security: ${this._security}` +
811
+ `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
812
+ errorMsg += '\n\nThe routes setted to use open server:';
813
+ this._routingModules.forEach((module) => {
814
+ if (module.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
815
+ errorMsg += `\n ${module.route} (security: ${module.security})`;
816
+ errorMsg += `\n subroutes using open sever:`;
817
+ module.endpoints.forEach((endpoint) => {
818
+ if (endpoint.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
819
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
820
+ }
821
+ });
822
+ }
823
+ });
824
+ const error = new Error(`Open routes cannot be established!\n${errorMsg}`);
825
+ const errorStack = error.stack.split('\n');
826
+ errorStack.splice(1, 2);
827
+ error.stack = errorStack.join('\n');
828
+ fsm_dynamo_1.DyFM_Log.error(errorMsg);
829
+ throw error;
830
+ }
831
+ await this.initOpenExpress();
832
+ }
833
+ if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
834
+ if (!this._cert || !this._portSettings.httpsPort) {
835
+ let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
836
+ `\nThere are ${this._routingModules.filter(m => m.security && m.security !== route_security_enum_1.DyNTS_RouteSecurity.open).length} secure routes` +
837
+ `\nroot security: ${this._security}` +
838
+ `\nset...` +
839
+ `\n(missing exact howto...)` +
840
+ /* `\n httpsPort and` +
841
+ `\n cert: {` +
842
+ `\n keyPath: FileSystem.PathLike,` +
843
+ `\n certPath: FileSystem.PathLike,` +
844
+ `\n }` + */
845
+ `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
846
+ errorMsg += '\n\nThe routes setted to use secure server:';
847
+ this._routingModules.forEach((module) => {
848
+ if (module.security && module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
849
+ errorMsg += `\n ${module.route} (security: ${module.security})`;
850
+ errorMsg += `\n location: ${module.stackLocation}`;
851
+ errorMsg += `\n subroutes using secure sever:`;
852
+ module.endpoints.forEach((endpoint) => {
853
+ if (endpoint.security && endpoint.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
854
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
855
+ errorMsg += `\n location: ${endpoint.stackLocation}`;
856
+ }
857
+ });
858
+ }
859
+ });
860
+ const error = new Error(`Secure routes cannot be established!\n${errorMsg}`);
861
+ const errorStack = error.stack.split('\n');
862
+ errorStack.splice(1, 2);
863
+ error.stack = errorStack.join('\n');
864
+ fsm_dynamo_1.DyFM_Log.error(errorMsg);
865
+ throw error;
866
+ }
867
+ await this.initSecureExpress();
868
+ }
869
+ }
870
+ catch (error) {
871
+ throw new fsm_dynamo_1.DyFM_Error({
872
+ ...this._getDefaultErrorSettings('initExpresses', error),
873
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-IE0`,
874
+ });
875
+ }
876
+ }
877
+ /**
878
+ *
879
+ */
880
+ async initOpenExpress() {
881
+ if (this.fnLogs)
882
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. initOpenExpress');
883
+ this.openExpress = Express();
884
+ this.openExpress.set('maxHeaderSize', 10 * fsm_dynamo_1.megabyte); // 1024 * 1024 * 10, // 10MB
885
+ this.openExpress.use(BodyParser.urlencoded(this._portSettings.httpUrlencoded));
886
+ this.openExpress.use(BodyParser.json(this._portSettings.httpJson));
887
+ // FR-041 — CORS allowlist enforcement. No-op if getCorsSettings() is not overridden.
888
+ this.mountCors(this.openExpress);
889
+ }
890
+ /**
891
+ *
892
+ */
893
+ async initSecureExpress() {
894
+ if (this.fnLogs)
895
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. initSecureExpress');
896
+ this.secureExpress = Express();
897
+ this.secureExpress.use(BodyParser.urlencoded(this._portSettings.httpsUrlencoded));
898
+ this.secureExpress.use(BodyParser.json(this._portSettings.httpsJson));
899
+ // FR-041 — CORS allowlist enforcement (same as open express).
900
+ this.mountCors(this.secureExpress);
901
+ const options = {
902
+ key: FileSystem.readFileSync(this._cert.keyPath),
903
+ cert: FileSystem.readFileSync(this._cert.certPath),
904
+ maxHeaderSize: 10 * fsm_dynamo_1.megabyte, // 1024 * 1024 * 10, // 10MB
905
+ };
906
+ this.httpsServer = Https.createServer(options, this.secureExpress);
907
+ }
908
+ /**
909
+ *
910
+ */
911
+ async startExpresses() {
912
+ if (this.fnLogs && this.deepLog)
913
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. startExpresses');
914
+ try {
915
+ if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
916
+ await new Promise((resolve, reject) => {
917
+ this.systemControls.httpsServer.init = true;
918
+ this.httpsServer
919
+ .listen(this._portSettings.httpsPort, this.params.secureHost, this.params.expressBacklog, () => {
920
+ this.systemControls.httpsServer.started = true;
921
+ fsm_dynamo_1.DyFM_Log.success(`\nHTTPS (secure) server is listening on port: ` +
922
+ `${this.params.secureHost}:${this._portSettings.httpsPort}`);
923
+ resolve();
924
+ })
925
+ .on('error', (error) => {
926
+ if (this.debugLog)
927
+ fsm_dynamo_1.DyFM_Log.error(`\nHTTPS (secure) server ERROR`, error);
928
+ if (!this.systemControls.httpsServer.started) {
929
+ const d_error = new fsm_dynamo_1.DyFM_Error({
930
+ ...this._getDefaultErrorSettings('startExpresses', error),
931
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE1`,
932
+ message: `HTTPS (secure) start server ERROR`,
933
+ });
934
+ this.constructErrors.push(d_error);
935
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
936
+ reject(d_error);
937
+ }
938
+ else {
939
+ const d_error = new fsm_dynamo_1.DyFM_Error({
940
+ ...this._getDefaultErrorSettings('httpsServer.on(error)', error),
941
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE2`,
942
+ message: `HTTPS (secure) server ERROR`,
943
+ level: fsm_dynamo_1.DyFM_ErrorLevel.serious,
944
+ });
945
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
946
+ }
947
+ })
948
+ .on('uncaughtException', (exception) => {
949
+ const d_error = new fsm_dynamo_1.DyFM_Error({
950
+ ...this._getDefaultErrorSettings('httpsServer.on(uncaughtException)', exception),
951
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE3`,
952
+ message: `HTTPS (secure) server uncaughtException`,
953
+ level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
954
+ });
955
+ if (this.debugLog)
956
+ fsm_dynamo_1.DyFM_Log.warn(`\nHTTPS (secure) server uncaughtException`, d_error);
957
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
958
+ });
959
+ });
960
+ }
961
+ if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
962
+ this.systemControls.httpServer.init = true;
963
+ await new Promise((resolve, reject) => {
964
+ this.httpServer = this.openExpress
965
+ .listen(this._portSettings.httpPort, this.params.openHost, this.params.expressBacklog, () => {
966
+ this.systemControls.httpServer.started = true;
967
+ const resolvedPort = this.httpServer?.address?.()?.['port'] ?? this._portSettings.httpPort;
968
+ if (this._portSettings.httpPort === 0) {
969
+ fsm_dynamo_1.DyFM_Log.H_warn(`\nHTTP (open) server is using a randomly selected port by the OS: ${resolvedPort}` +
970
+ `\n (httpPort was set to 0 — this is intended for testing only)`);
971
+ }
972
+ fsm_dynamo_1.DyFM_Log.success(`\nHTTP (open) server is listening on port: ` +
973
+ `${this.params.openHost}:${resolvedPort}`);
974
+ resolve();
975
+ })
976
+ .on('error', (error) => {
977
+ if (this.debugLog)
978
+ fsm_dynamo_1.DyFM_Log.error(`\nHTTP (open) server ERROR`, error);
979
+ if (!this.systemControls.httpServer.started) {
980
+ const d_error = new fsm_dynamo_1.DyFM_Error({
981
+ ...this._getDefaultErrorSettings('startExpresses', error),
982
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE3`,
983
+ message: `HTTP (open) start server ERROR`,
984
+ });
985
+ this.constructErrors.push(d_error);
986
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
987
+ reject(d_error);
988
+ }
989
+ else {
990
+ const d_error = new fsm_dynamo_1.DyFM_Error({
991
+ ...this._getDefaultErrorSettings('httpServer.on(error)', error),
992
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE4`,
993
+ message: `HTTP (open) server ERROR`,
994
+ level: fsm_dynamo_1.DyFM_ErrorLevel.serious,
995
+ });
996
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
997
+ }
998
+ })
999
+ .on('uncaughtException', (exception) => {
1000
+ const d_error = new fsm_dynamo_1.DyFM_Error({
1001
+ ...this._getDefaultErrorSettings('httpServer.on(uncaughtException)', exception),
1002
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE5`,
1003
+ message: `HTTP (open) server uncaughtException`,
1004
+ level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
1005
+ });
1006
+ if (this.debugLog) {
1007
+ fsm_dynamo_1.DyFM_Log.warn(`\nHTTP (open) server uncaughtException`, d_error);
1008
+ }
1009
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
1010
+ });
1011
+ });
1012
+ }
1013
+ }
1014
+ catch (error) {
1015
+ throw new fsm_dynamo_1.DyFM_Error({
1016
+ ...this._getDefaultErrorSettings('startExpresses', error),
1017
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-SE0`,
1018
+ });
1019
+ }
1020
+ }
1021
+ /**
1022
+ *
1023
+ */
1024
+ async expressErrorHandling(error, req, res, next) {
1025
+ try {
1026
+ if (error) {
1027
+ const d_error = new fsm_dynamo_1.DyFM_Error({
1028
+ ...this._getDefaultErrorSettings('expressErrorHandling', error),
1029
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-EEH1`,
1030
+ message: `Express ERROR`,
1031
+ additionalContent: {
1032
+ req,
1033
+ res,
1034
+ },
1035
+ level: fsm_dynamo_1.DyFM_ErrorLevel.error,
1036
+ });
1037
+ await global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error, req, res);
1038
+ res.send(error);
1039
+ }
1040
+ else {
1041
+ fsm_dynamo_1.DyFM_Log.H_error('WTF??? express error; without error?...' +
1042
+ '\nerr:', error, '\nreq:', req, '\nres:', res);
1043
+ }
1044
+ }
1045
+ catch (error) {
1046
+ fsm_dynamo_1.DyFM_Log.H_error('MULTILEVEL ERROR (expressErrorHandling)....' +
1047
+ '\n', error);
1048
+ }
1049
+ }
1050
+ /**
1051
+ *
1052
+ */
1053
+ async mountSecureRoutes() {
1054
+ try {
1055
+ if (this.fnLogs && this.deepLog)
1056
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. mountSecureRoutes');
1057
+ if (!this.secureExpress) {
1058
+ throw new Error('secureExpress was not initialized. ' +
1059
+ 'Secure routes require getCertificationSettings and httpsPort, and cert files must exist.' +
1060
+ '\n\nYou need to set security to secure or both in any route and set httpsPort in getPortSettings.' +
1061
+ '\n\nYou need to set cert files in getCertificationSettings.');
1062
+ }
1063
+ this.secureExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
1064
+ await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
1065
+ if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
1066
+ if (this.logSetup) {
1067
+ fsm_dynamo_1.DyFM_Log.log(`route mount (secure): ${module.route}`);
1068
+ }
1069
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
1070
+ if (1 < existingRoutes.length) {
1071
+ const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1072
+ /* const errorStack: string[] = error.stack.split('\n');
1073
+
1074
+ errorStack.splice(1, 4);
1075
+ error.stack = errorStack.join('\n'); */
1076
+ error.stack = module.stackLocation;
1077
+ fsm_dynamo_1.DyFM_Log.S_error(`ROUTE DUPLICATION: ${module.route}`, error);
1078
+ throw new fsm_dynamo_1.DyFM_Error({
1079
+ ...this._getDefaultErrorSettings('mountSecureRoutes', error),
1080
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MSR1`,
1081
+ message: `ROUTE DUPLICATION: ${module.route}`,
1082
+ });
1083
+ }
1084
+ this.secureExpress.use(module.route, module.secureRouter);
1085
+ }
1086
+ });
1087
+ }
1088
+ catch (error) {
1089
+ throw new fsm_dynamo_1.DyFM_Error({
1090
+ ...this._getDefaultErrorSettings('mountSecureRoutes', error),
1091
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MSR0`,
1092
+ });
1093
+ }
1094
+ }
1095
+ /**
1096
+ *
1097
+ */
1098
+ async mountOpenRoutes() {
1099
+ try {
1100
+ if (this.fnLogs && this.deepLog)
1101
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. mountOpenRoutes');
1102
+ if (!this.openExpress) {
1103
+ throw new Error('openExpress was not initialized. Open routes require getOpenExpress and httpPort.' +
1104
+ '\n\nYou need to set security to open or both in any route and set httpPort in getPortSettings.');
1105
+ }
1106
+ this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
1107
+ await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
1108
+ if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
1109
+ if (this.logSetup) {
1110
+ fsm_dynamo_1.DyFM_Log.log(`route mount (open): ${module.route}`);
1111
+ }
1112
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
1113
+ if (1 < existingRoutes.length) {
1114
+ const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1115
+ /* const errorStack: string[] = error.stack.split('\n');
1116
+
1117
+ errorStack.splice(1, 4);
1118
+ error.stack = errorStack.join('\n'); */
1119
+ error.stack = module.stackLocation;
1120
+ fsm_dynamo_1.DyFM_Log.S_error(`ROUTE DUPLICATION: ${module.route}`, error);
1121
+ throw new fsm_dynamo_1.DyFM_Error({
1122
+ ...this._getDefaultErrorSettings('mountOpenRoutes', error),
1123
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MOR1`,
1124
+ message: `ROUTE DUPLICATION: ${module.route}`,
1125
+ });
1126
+ }
1127
+ this.openExpress.use(module.route, module.openRouter);
1128
+ }
1129
+ });
1130
+ }
1131
+ catch (error) {
1132
+ throw new fsm_dynamo_1.DyFM_Error({
1133
+ ...this._getDefaultErrorSettings('mountOpenRoutes', error),
1134
+ errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-AS0-MOR0`,
1135
+ });
1136
+ }
1137
+ }
1138
+ /**
1139
+ * FR-041 — CORS middleware. Echoes a matching `Access-Control-Allow-Origin`
1140
+ * for any request whose Origin header is in `getCorsSettings().allowedOrigins`,
1141
+ * adds the canonical `Access-Control-*` companion headers, and short-circuits
1142
+ * the OPTIONS preflight with a 204.
1143
+ *
1144
+ * No-op when the subclass does NOT override `getCorsSettings()` — preserves
1145
+ * back-compat for apps that have always been same-origin and never needed
1146
+ * CORS (the typical pre-FR-041 case).
1147
+ *
1148
+ * Why hand-rolled instead of the `cors` npm package:
1149
+ * - ~30 lines, zero new dependency.
1150
+ * - Full control over Vary/credentials/preflight semantics.
1151
+ * - Aligns with FDP "no unnecessary deps" philosophy.
1152
+ */
1153
+ mountCors(express) {
1154
+ const settings = this.getCorsSettings?.();
1155
+ if (!settings) {
1156
+ return;
1157
+ }
1158
+ const allowCreds = settings.allowCredentials !== false;
1159
+ const methods = settings.allowedMethods ?? [
1160
+ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS',
1161
+ ];
1162
+ const headers = settings.allowedHeaders ?? [
1163
+ 'Authorization', 'Content-Type', 'X-Admin-Key', 'X-Requested-With',
1164
+ ];
1165
+ const exposed = settings.exposedHeaders ?? [
1166
+ 'Content-Length', 'Content-Type',
1167
+ ];
1168
+ const maxAge = settings.maxAgeSeconds ?? 86400;
1169
+ const isAllowed = (origin) => {
1170
+ if (settings.allowedOrigins === '*')
1171
+ return true;
1172
+ if (typeof settings.allowedOrigins === 'function') {
1173
+ return settings.allowedOrigins(origin);
1174
+ }
1175
+ return settings.allowedOrigins.includes(origin);
1176
+ };
1177
+ express.use((req, res, next) => {
1178
+ const origin = req.headers.origin;
1179
+ if (origin && isAllowed(origin)) {
1180
+ // Echo the matching origin (NOT wildcard) because credentials require it.
1181
+ res.setHeader('Access-Control-Allow-Origin', origin);
1182
+ if (allowCreds) {
1183
+ res.setHeader('Access-Control-Allow-Credentials', 'true');
1184
+ }
1185
+ res.setHeader('Access-Control-Allow-Methods', methods.join(', '));
1186
+ res.setHeader('Access-Control-Allow-Headers', headers.join(', '));
1187
+ res.setHeader('Access-Control-Expose-Headers', exposed.join(', '));
1188
+ res.setHeader('Access-Control-Max-Age', String(maxAge));
1189
+ res.setHeader('Vary', 'Origin');
1190
+ }
1191
+ if (req.method === 'OPTIONS') {
1192
+ res.status(204).end();
1193
+ return;
1194
+ }
1195
+ next();
1196
+ });
1197
+ }
1198
+ /**
1199
+ * Generikus, auth-agnosztikus extension-point orchestrator. A `registerCustomMiddleware`
1200
+ * hookot hívja (ha a subclass override-olja) minden AKTÍV Express instance-ra
1201
+ * (open + secure), az API route-ok UTÁN, de a SPA static catch-all (`app.get('*')`)
1202
+ * ELŐTT — ez az EGYETLEN korrekt pont egy sub-path middleware-hez (pl. reverse-proxy),
1203
+ * mert a catch-all minden utána mountolt route-ot elnyel. No-op ha nincs override (back-compat).
1204
+ */
1205
+ async mountCustomMiddleware() {
1206
+ if (!this.registerCustomMiddleware) {
1207
+ return;
1208
+ }
1209
+ if (this.openExpress) {
1210
+ await this.registerCustomMiddleware(this.openExpress, route_security_enum_1.DyNTS_RouteSecurity.open);
1211
+ }
1212
+ if (this.secureExpress) {
1213
+ await this.registerCustomMiddleware(this.secureExpress, route_security_enum_1.DyNTS_RouteSecurity.secure);
1214
+ }
1215
+ if (this.logSetup) {
1216
+ fsm_dynamo_1.DyFM_Log.log('\nCustom middleware registered (pre-static).');
1217
+ }
1218
+ }
1219
+ /**
1220
+ * Ha getStaticClientSettings() visszaad beállításokat, a client static fájlok a '/' alatt
1221
+ * lesznek kiszolgálva (API route-ok után). SPA fallback opcionális (fallbackPath).
1222
+ * Asset cache (assetCacheMaxAge, assetCacheImmutable) és fallback cache (fallbackCacheMaxAge)
1223
+ * opcionálisak; ha nincs megadva fallbackCacheMaxAge, DyNTS_defaultFallbackCacheMaxAge (0) marad.
1224
+ */
1225
+ async mountStaticClient() {
1226
+ const settings = this.getStaticClientSettings?.();
1227
+ if (!settings) {
1228
+ return;
1229
+ }
1230
+ const absoluteRoot = Path.isAbsolute(settings.root)
1231
+ ? settings.root
1232
+ : Path.resolve(process.cwd(), settings.root);
1233
+ const hasAssetCache = settings.assetCacheMaxAge !== undefined || settings.assetCacheImmutable === true;
1234
+ const staticOptions = hasAssetCache && settings.assetCacheMaxAge !== undefined
1235
+ ? {
1236
+ setHeaders: (res) => {
1237
+ const maxAge = settings.assetCacheMaxAge;
1238
+ const immutable = settings.assetCacheImmutable === true ? ', immutable' : '';
1239
+ res.setHeader('Cache-Control', `max-age=${maxAge}${immutable}`);
1240
+ },
1241
+ }
1242
+ : undefined;
1243
+ const staticMiddleware = staticOptions
1244
+ ? Express.static(absoluteRoot, staticOptions)
1245
+ : Express.static(absoluteRoot);
1246
+ const fallbackMaxAge = settings.fallbackCacheMaxAge ?? default_fallback_cache_max_age_const_1.DyNTS_defaultFallbackCacheMaxAge;
1247
+ if (this.openExpress) {
1248
+ this.openExpress.use('/', staticMiddleware);
1249
+ if (settings.fallbackPath) {
1250
+ this.openExpress.get('*', (req, res) => {
1251
+ res.setHeader('Cache-Control', `max-age=${fallbackMaxAge}`);
1252
+ res.sendFile(settings.fallbackPath, { root: absoluteRoot });
1253
+ });
1254
+ }
1255
+ else {
1256
+ this.openExpress.get('*', (req, res) => {
1257
+ res.status(404).type('html').send(default_not_found_page_const_1.DyNTS_defaultNotFoundPageHtml);
1258
+ });
1259
+ }
1260
+ }
1261
+ if (this.secureExpress) {
1262
+ this.secureExpress.use('/', staticMiddleware);
1263
+ if (settings.fallbackPath) {
1264
+ this.secureExpress.get('*', (req, res) => {
1265
+ res.setHeader('Cache-Control', `max-age=${fallbackMaxAge}`);
1266
+ res.sendFile(settings.fallbackPath, { root: absoluteRoot });
1267
+ });
1268
+ }
1269
+ else {
1270
+ this.secureExpress.get('*', (req, res) => {
1271
+ res.status(404).type('html').send(default_not_found_page_const_1.DyNTS_defaultNotFoundPageHtml);
1272
+ });
1273
+ }
1274
+ }
1275
+ if (this.logSetup) {
1276
+ fsm_dynamo_1.DyFM_Log.log(`\nStatic client mounted at / (root: ${absoluteRoot})`);
1277
+ }
1278
+ }
1279
+ /**
1280
+ *
1281
+ */
1282
+ setSecurity() {
1283
+ if (this.fnLogs && this.deepLog)
1284
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. setSecurity');
1285
+ this._routingModules.forEach((module) => {
1286
+ if (!module.security) {
1287
+ fsm_dynamo_1.DyFM_Log.warn(`RoutingModule security is not set for ${module.route}\n`);
1288
+ }
1289
+ else if (!this._security) {
1290
+ this._security = module.security;
1291
+ }
1292
+ else if (this._security !== module.security) {
1293
+ this._security = route_security_enum_1.DyNTS_RouteSecurity.both;
1294
+ }
1295
+ });
1296
+ if (!this._security) {
1297
+ let msg = `Could not set security for the server! (${this.security})`;
1298
+ msg += '\n RoutingModules:';
1299
+ this._routingModules.forEach((module) => {
1300
+ msg += `\n ${module.route} (security: ${module.security})`;
1301
+ });
1302
+ if (this._routingModules.length === 0) {
1303
+ msg += '\n - no RoutingModule found -\n';
1304
+ }
1305
+ fsm_dynamo_1.DyFM_Log.warn(msg);
1306
+ }
1307
+ }
1308
+ _getDefaultErrorSettings(fnName, error) {
1309
+ return {
1310
+ status: error?.___status ?? 500,
1311
+ message: error?.message ??
1312
+ error?._message ??
1313
+ `${fnName} was UNSUCCESSFUL (NTS)`,
1314
+ userMessage: error?.__userMessage ?? this.defaultErrorUserMsg,
1315
+ addECToUserMsg: !error?.__userMessage,
1316
+ issuerService: `${this?.constructor?.name}-DyNTS_App`,
1317
+ level: fsm_dynamo_1.DyFM_ErrorLevel.fatal,
1318
+ error: error,
1319
+ systemVersion: global_settings_const_1.DyNTS_global_settings.systemVersion,
1320
+ };
1321
+ }
1322
+ }
1323
+ exports.DyNTS_App = DyNTS_App;
1324
1324
  //# sourceMappingURL=app.server.js.map