@morojs/moro 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/README.md +256 -74
  2. package/dist/core/auth/morojs-adapter.js +20 -20
  3. package/dist/core/auth/morojs-adapter.js.map +1 -1
  4. package/dist/core/config/file-loader.d.ts +6 -1
  5. package/dist/core/config/file-loader.js +249 -19
  6. package/dist/core/config/file-loader.js.map +1 -1
  7. package/dist/core/config/index.d.ts +12 -41
  8. package/dist/core/config/index.js +54 -65
  9. package/dist/core/config/index.js.map +1 -1
  10. package/dist/core/config/loader.d.ts +7 -0
  11. package/dist/core/config/loader.js +269 -0
  12. package/dist/core/config/loader.js.map +1 -0
  13. package/dist/core/config/schema.d.ts +2 -2
  14. package/dist/core/config/schema.js +44 -52
  15. package/dist/core/config/schema.js.map +1 -1
  16. package/dist/core/config/utils.d.ts +3 -10
  17. package/dist/core/config/utils.js +58 -31
  18. package/dist/core/config/utils.js.map +1 -1
  19. package/dist/core/config/validation.d.ts +17 -0
  20. package/dist/core/config/validation.js +131 -0
  21. package/dist/core/config/validation.js.map +1 -0
  22. package/dist/core/database/adapters/drizzle.d.ts +1 -1
  23. package/dist/core/database/adapters/drizzle.js +11 -18
  24. package/dist/core/database/adapters/drizzle.js.map +1 -1
  25. package/dist/core/database/adapters/index.d.ts +7 -7
  26. package/dist/core/database/adapters/index.js +29 -19
  27. package/dist/core/database/adapters/index.js.map +1 -1
  28. package/dist/core/database/adapters/mongodb.d.ts +1 -13
  29. package/dist/core/database/adapters/mongodb.js +10 -46
  30. package/dist/core/database/adapters/mongodb.js.map +1 -1
  31. package/dist/core/database/adapters/mysql.d.ts +1 -14
  32. package/dist/core/database/adapters/mysql.js +9 -19
  33. package/dist/core/database/adapters/mysql.js.map +1 -1
  34. package/dist/core/database/adapters/postgresql.d.ts +2 -12
  35. package/dist/core/database/adapters/postgresql.js +9 -19
  36. package/dist/core/database/adapters/postgresql.js.map +1 -1
  37. package/dist/core/database/adapters/redis.d.ts +1 -12
  38. package/dist/core/database/adapters/redis.js +13 -48
  39. package/dist/core/database/adapters/redis.js.map +1 -1
  40. package/dist/core/database/adapters/sqlite.d.ts +1 -3
  41. package/dist/core/database/adapters/sqlite.js +8 -19
  42. package/dist/core/database/adapters/sqlite.js.map +1 -1
  43. package/dist/core/database/index.d.ts +2 -2
  44. package/dist/core/database/index.js +18 -2
  45. package/dist/core/database/index.js.map +1 -1
  46. package/dist/core/docs/index.d.ts +9 -9
  47. package/dist/core/docs/index.js +35 -14
  48. package/dist/core/docs/index.js.map +1 -1
  49. package/dist/core/docs/openapi-generator.d.ts +2 -2
  50. package/dist/core/docs/openapi-generator.js +16 -11
  51. package/dist/core/docs/openapi-generator.js.map +1 -1
  52. package/dist/core/docs/schema-to-openapi.d.ts +2 -2
  53. package/dist/core/docs/schema-to-openapi.js +11 -5
  54. package/dist/core/docs/schema-to-openapi.js.map +1 -1
  55. package/dist/core/docs/simple-docs.d.ts +1 -1
  56. package/dist/core/docs/simple-docs.js +9 -4
  57. package/dist/core/docs/simple-docs.js.map +1 -1
  58. package/dist/core/docs/swagger-ui.d.ts +2 -2
  59. package/dist/core/docs/swagger-ui.js +29 -26
  60. package/dist/core/docs/swagger-ui.js.map +1 -1
  61. package/dist/core/docs/zod-to-openapi.js +28 -31
  62. package/dist/core/docs/zod-to-openapi.js.map +1 -1
  63. package/dist/core/events/event-bus.d.ts +1 -1
  64. package/dist/core/events/event-bus.js +10 -6
  65. package/dist/core/events/event-bus.js.map +1 -1
  66. package/dist/core/events/index.d.ts +2 -2
  67. package/dist/core/events/index.js +5 -1
  68. package/dist/core/events/index.js.map +1 -1
  69. package/dist/core/framework.d.ts +12 -19
  70. package/dist/core/framework.js +100 -277
  71. package/dist/core/framework.js.map +1 -1
  72. package/dist/core/http/http-server.d.ts +1 -13
  73. package/dist/core/http/http-server.js +85 -175
  74. package/dist/core/http/http-server.js.map +1 -1
  75. package/dist/core/http/index.d.ts +3 -4
  76. package/dist/core/http/index.js +8 -3
  77. package/dist/core/http/index.js.map +1 -1
  78. package/dist/core/http/router.d.ts +1 -13
  79. package/dist/core/http/router.js +43 -117
  80. package/dist/core/http/router.js.map +1 -1
  81. package/dist/core/logger/filters.d.ts +1 -1
  82. package/dist/core/logger/filters.js +23 -20
  83. package/dist/core/logger/filters.js.map +1 -1
  84. package/dist/core/logger/index.d.ts +3 -3
  85. package/dist/core/logger/index.js +24 -2
  86. package/dist/core/logger/index.js.map +1 -1
  87. package/dist/core/logger/logger.d.ts +14 -30
  88. package/dist/core/logger/logger.js +223 -398
  89. package/dist/core/logger/logger.js.map +1 -1
  90. package/dist/core/logger/outputs.d.ts +1 -1
  91. package/dist/core/logger/outputs.js +17 -8
  92. package/dist/core/logger/outputs.js.map +1 -1
  93. package/dist/core/middleware/built-in/adapters/cache/file.d.ts +1 -1
  94. package/dist/core/middleware/built-in/adapters/cache/file.js +47 -10
  95. package/dist/core/middleware/built-in/adapters/cache/file.js.map +1 -1
  96. package/dist/core/middleware/built-in/adapters/cache/index.d.ts +4 -4
  97. package/dist/core/middleware/built-in/adapters/cache/index.js +17 -10
  98. package/dist/core/middleware/built-in/adapters/cache/index.js.map +1 -1
  99. package/dist/core/middleware/built-in/adapters/cache/memory.d.ts +1 -1
  100. package/dist/core/middleware/built-in/adapters/cache/memory.js +7 -3
  101. package/dist/core/middleware/built-in/adapters/cache/memory.js.map +1 -1
  102. package/dist/core/middleware/built-in/adapters/cache/redis.d.ts +1 -3
  103. package/dist/core/middleware/built-in/adapters/cache/redis.js +9 -11
  104. package/dist/core/middleware/built-in/adapters/cache/redis.js.map +1 -1
  105. package/dist/core/middleware/built-in/adapters/cdn/azure.d.ts +1 -1
  106. package/dist/core/middleware/built-in/adapters/cdn/azure.js +7 -3
  107. package/dist/core/middleware/built-in/adapters/cdn/azure.js.map +1 -1
  108. package/dist/core/middleware/built-in/adapters/cdn/cloudflare.d.ts +1 -1
  109. package/dist/core/middleware/built-in/adapters/cdn/cloudflare.js +7 -3
  110. package/dist/core/middleware/built-in/adapters/cdn/cloudflare.js.map +1 -1
  111. package/dist/core/middleware/built-in/adapters/cdn/cloudfront.d.ts +1 -3
  112. package/dist/core/middleware/built-in/adapters/cdn/cloudfront.js +10 -12
  113. package/dist/core/middleware/built-in/adapters/cdn/cloudfront.js.map +1 -1
  114. package/dist/core/middleware/built-in/adapters/cdn/index.d.ts +4 -4
  115. package/dist/core/middleware/built-in/adapters/cdn/index.js +17 -10
  116. package/dist/core/middleware/built-in/adapters/cdn/index.js.map +1 -1
  117. package/dist/core/middleware/built-in/adapters/index.d.ts +4 -4
  118. package/dist/core/middleware/built-in/adapters/index.js +23 -4
  119. package/dist/core/middleware/built-in/adapters/index.js.map +1 -1
  120. package/dist/core/middleware/built-in/auth-helpers.js +22 -11
  121. package/dist/core/middleware/built-in/auth-helpers.js.map +1 -1
  122. package/dist/core/middleware/built-in/auth-providers.d.ts +1 -1
  123. package/dist/core/middleware/built-in/auth-providers.js +9 -4
  124. package/dist/core/middleware/built-in/auth-providers.js.map +1 -1
  125. package/dist/core/middleware/built-in/auth.d.ts +2 -2
  126. package/dist/core/middleware/built-in/auth.js +26 -93
  127. package/dist/core/middleware/built-in/auth.js.map +1 -1
  128. package/dist/core/middleware/built-in/cache.d.ts +2 -2
  129. package/dist/core/middleware/built-in/cache.js +12 -11
  130. package/dist/core/middleware/built-in/cache.js.map +1 -1
  131. package/dist/core/middleware/built-in/cdn.d.ts +2 -2
  132. package/dist/core/middleware/built-in/cdn.js +9 -5
  133. package/dist/core/middleware/built-in/cdn.js.map +1 -1
  134. package/dist/core/middleware/built-in/cookie.d.ts +1 -1
  135. package/dist/core/middleware/built-in/cookie.js +7 -3
  136. package/dist/core/middleware/built-in/cookie.js.map +1 -1
  137. package/dist/core/middleware/built-in/cors.d.ts +1 -1
  138. package/dist/core/middleware/built-in/cors.js +7 -3
  139. package/dist/core/middleware/built-in/cors.js.map +1 -1
  140. package/dist/core/middleware/built-in/csp.d.ts +1 -1
  141. package/dist/core/middleware/built-in/csp.js +8 -5
  142. package/dist/core/middleware/built-in/csp.js.map +1 -1
  143. package/dist/core/middleware/built-in/csrf.d.ts +1 -1
  144. package/dist/core/middleware/built-in/csrf.js +8 -5
  145. package/dist/core/middleware/built-in/csrf.js.map +1 -1
  146. package/dist/core/middleware/built-in/error-tracker.js +7 -3
  147. package/dist/core/middleware/built-in/error-tracker.js.map +1 -1
  148. package/dist/core/middleware/built-in/index.d.ts +27 -28
  149. package/dist/core/middleware/built-in/index.js +78 -48
  150. package/dist/core/middleware/built-in/index.js.map +1 -1
  151. package/dist/core/middleware/built-in/performance-monitor.js +7 -3
  152. package/dist/core/middleware/built-in/performance-monitor.js.map +1 -1
  153. package/dist/core/middleware/built-in/rate-limit.d.ts +1 -1
  154. package/dist/core/middleware/built-in/rate-limit.js +7 -3
  155. package/dist/core/middleware/built-in/rate-limit.js.map +1 -1
  156. package/dist/core/middleware/built-in/request-logger.js +8 -5
  157. package/dist/core/middleware/built-in/request-logger.js.map +1 -1
  158. package/dist/core/middleware/built-in/session.d.ts +2 -2
  159. package/dist/core/middleware/built-in/session.js +15 -11
  160. package/dist/core/middleware/built-in/session.js.map +1 -1
  161. package/dist/core/middleware/built-in/sse.d.ts +1 -1
  162. package/dist/core/middleware/built-in/sse.js +14 -12
  163. package/dist/core/middleware/built-in/sse.js.map +1 -1
  164. package/dist/core/middleware/built-in/validation.d.ts +1 -1
  165. package/dist/core/middleware/built-in/validation.js +7 -3
  166. package/dist/core/middleware/built-in/validation.js.map +1 -1
  167. package/dist/core/middleware/index.d.ts +4 -4
  168. package/dist/core/middleware/index.js +28 -8
  169. package/dist/core/middleware/index.js.map +1 -1
  170. package/dist/core/modules/auto-discovery.d.ts +2 -19
  171. package/dist/core/modules/auto-discovery.js +74 -391
  172. package/dist/core/modules/auto-discovery.js.map +1 -1
  173. package/dist/core/modules/index.d.ts +2 -2
  174. package/dist/core/modules/index.js +9 -2
  175. package/dist/core/modules/index.js.map +1 -1
  176. package/dist/core/modules/modules.d.ts +3 -3
  177. package/dist/core/modules/modules.js +54 -23
  178. package/dist/core/modules/modules.js.map +1 -1
  179. package/dist/core/networking/adapters/index.d.ts +3 -4
  180. package/dist/core/networking/adapters/index.js +7 -3
  181. package/dist/core/networking/adapters/index.js.map +1 -1
  182. package/dist/core/networking/adapters/socketio-adapter.d.ts +1 -1
  183. package/dist/core/networking/adapters/socketio-adapter.js +40 -5
  184. package/dist/core/networking/adapters/socketio-adapter.js.map +1 -1
  185. package/dist/core/networking/adapters/ws-adapter.d.ts +2 -2
  186. package/dist/core/networking/adapters/ws-adapter.js +43 -8
  187. package/dist/core/networking/adapters/ws-adapter.js.map +1 -1
  188. package/dist/core/networking/index.d.ts +2 -3
  189. package/dist/core/networking/index.js +7 -2
  190. package/dist/core/networking/index.js.map +1 -1
  191. package/dist/core/networking/service-discovery.js +12 -8
  192. package/dist/core/networking/service-discovery.js.map +1 -1
  193. package/dist/core/networking/websocket-adapter.js +2 -1
  194. package/dist/core/networking/websocket-adapter.js.map +1 -1
  195. package/dist/core/networking/websocket-manager.d.ts +3 -3
  196. package/dist/core/networking/websocket-manager.js +11 -9
  197. package/dist/core/networking/websocket-manager.js.map +1 -1
  198. package/dist/core/routing/app-integration.d.ts +2 -2
  199. package/dist/core/routing/app-integration.js +12 -7
  200. package/dist/core/routing/app-integration.js.map +1 -1
  201. package/dist/core/routing/index.d.ts +2 -22
  202. package/dist/core/routing/index.js +27 -185
  203. package/dist/core/routing/index.js.map +1 -1
  204. package/dist/core/runtime/aws-lambda-adapter.d.ts +3 -3
  205. package/dist/core/runtime/aws-lambda-adapter.js +6 -2
  206. package/dist/core/runtime/aws-lambda-adapter.js.map +1 -1
  207. package/dist/core/runtime/base-adapter.d.ts +2 -2
  208. package/dist/core/runtime/base-adapter.js +7 -3
  209. package/dist/core/runtime/base-adapter.js.map +1 -1
  210. package/dist/core/runtime/cloudflare-workers-adapter.d.ts +3 -3
  211. package/dist/core/runtime/cloudflare-workers-adapter.js +6 -2
  212. package/dist/core/runtime/cloudflare-workers-adapter.js.map +1 -1
  213. package/dist/core/runtime/index.d.ts +12 -12
  214. package/dist/core/runtime/index.js +35 -22
  215. package/dist/core/runtime/index.js.map +1 -1
  216. package/dist/core/runtime/node-adapter.d.ts +4 -4
  217. package/dist/core/runtime/node-adapter.js +49 -18
  218. package/dist/core/runtime/node-adapter.js.map +1 -1
  219. package/dist/core/runtime/vercel-edge-adapter.d.ts +3 -3
  220. package/dist/core/runtime/vercel-edge-adapter.js +6 -2
  221. package/dist/core/runtime/vercel-edge-adapter.js.map +1 -1
  222. package/dist/core/utilities/circuit-breaker.js +5 -1
  223. package/dist/core/utilities/circuit-breaker.js.map +1 -1
  224. package/dist/core/utilities/container.js +22 -12
  225. package/dist/core/utilities/container.js.map +1 -1
  226. package/dist/core/utilities/hooks.d.ts +2 -2
  227. package/dist/core/utilities/hooks.js +12 -7
  228. package/dist/core/utilities/hooks.js.map +1 -1
  229. package/dist/core/utilities/index.d.ts +4 -5
  230. package/dist/core/utilities/index.js +19 -5
  231. package/dist/core/utilities/index.js.map +1 -1
  232. package/dist/core/validation/adapters.d.ts +1 -1
  233. package/dist/core/validation/adapters.js +26 -15
  234. package/dist/core/validation/adapters.js.map +1 -1
  235. package/dist/core/validation/index.d.ts +4 -6
  236. package/dist/core/validation/index.js +28 -57
  237. package/dist/core/validation/index.js.map +1 -1
  238. package/dist/core/validation/schema-interface.js +9 -3
  239. package/dist/core/validation/schema-interface.js.map +1 -1
  240. package/dist/index.d.ts +52 -51
  241. package/dist/index.js +132 -23
  242. package/dist/index.js.map +1 -1
  243. package/dist/moro.d.ts +10 -61
  244. package/dist/moro.js +237 -575
  245. package/dist/moro.js.map +1 -1
  246. package/dist/types/auth.js +9 -3
  247. package/dist/types/auth.js.map +1 -1
  248. package/dist/types/cache.js +2 -1
  249. package/dist/types/cdn.js +2 -1
  250. package/dist/types/config.d.ts +2 -70
  251. package/dist/types/config.js +2 -1
  252. package/dist/types/config.js.map +1 -1
  253. package/dist/types/core.d.ts +42 -36
  254. package/dist/types/core.js +2 -1
  255. package/dist/types/database.js +2 -1
  256. package/dist/types/discovery.js +2 -1
  257. package/dist/types/events.js +2 -1
  258. package/dist/types/hooks.d.ts +1 -1
  259. package/dist/types/hooks.js +2 -1
  260. package/dist/types/http.d.ts +1 -16
  261. package/dist/types/http.js +2 -1
  262. package/dist/types/logger.d.ts +0 -7
  263. package/dist/types/logger.js +2 -1
  264. package/dist/types/module.d.ts +0 -11
  265. package/dist/types/module.js +2 -1
  266. package/dist/types/runtime.d.ts +1 -1
  267. package/dist/types/runtime.js +2 -1
  268. package/dist/types/session.js +2 -1
  269. package/package.json +52 -19
  270. package/src/core/auth/morojs-adapter.ts +13 -18
  271. package/src/core/config/file-loader.ts +273 -13
  272. package/src/core/config/index.ts +34 -83
  273. package/src/core/config/loader.ts +633 -0
  274. package/src/core/config/schema.ts +33 -44
  275. package/src/core/config/utils.ts +31 -24
  276. package/src/core/config/validation.ts +140 -0
  277. package/src/core/database/README.md +16 -26
  278. package/src/core/database/adapters/drizzle.ts +6 -18
  279. package/src/core/database/adapters/index.ts +13 -13
  280. package/src/core/database/adapters/mongodb.ts +5 -53
  281. package/src/core/database/adapters/mysql.ts +4 -32
  282. package/src/core/database/adapters/postgresql.ts +5 -30
  283. package/src/core/database/adapters/redis.ts +8 -61
  284. package/src/core/database/adapters/sqlite.ts +3 -19
  285. package/src/core/database/index.ts +2 -2
  286. package/src/core/docs/index.ts +8 -8
  287. package/src/core/docs/openapi-generator.ts +4 -4
  288. package/src/core/docs/schema-to-openapi.ts +6 -3
  289. package/src/core/docs/simple-docs.ts +2 -2
  290. package/src/core/docs/swagger-ui.ts +16 -19
  291. package/src/core/docs/zod-to-openapi.ts +34 -34
  292. package/src/core/events/event-bus.ts +2 -2
  293. package/src/core/events/index.ts +2 -2
  294. package/src/core/framework.ts +67 -311
  295. package/src/core/http/http-server.ts +45 -190
  296. package/src/core/http/index.ts +3 -4
  297. package/src/core/http/router.ts +40 -129
  298. package/src/core/logger/filters.ts +5 -13
  299. package/src/core/logger/index.ts +3 -4
  300. package/src/core/logger/logger.ts +216 -435
  301. package/src/core/logger/outputs.ts +3 -1
  302. package/src/core/middleware/built-in/adapters/cache/file.ts +3 -3
  303. package/src/core/middleware/built-in/adapters/cache/index.ts +7 -7
  304. package/src/core/middleware/built-in/adapters/cache/memory.ts +2 -2
  305. package/src/core/middleware/built-in/adapters/cache/redis.ts +4 -18
  306. package/src/core/middleware/built-in/adapters/cdn/azure.ts +2 -2
  307. package/src/core/middleware/built-in/adapters/cdn/cloudflare.ts +2 -2
  308. package/src/core/middleware/built-in/adapters/cdn/cloudfront.ts +5 -16
  309. package/src/core/middleware/built-in/adapters/cdn/index.ts +7 -7
  310. package/src/core/middleware/built-in/adapters/index.ts +4 -4
  311. package/src/core/middleware/built-in/auth-helpers.ts +1 -1
  312. package/src/core/middleware/built-in/auth-providers.ts +1 -1
  313. package/src/core/middleware/built-in/auth.ts +21 -102
  314. package/src/core/middleware/built-in/cache.ts +6 -8
  315. package/src/core/middleware/built-in/cdn.ts +4 -4
  316. package/src/core/middleware/built-in/cookie.ts +2 -2
  317. package/src/core/middleware/built-in/cors.ts +2 -2
  318. package/src/core/middleware/built-in/csp.ts +3 -3
  319. package/src/core/middleware/built-in/csrf.ts +3 -3
  320. package/src/core/middleware/built-in/error-tracker.ts +1 -1
  321. package/src/core/middleware/built-in/index.ts +30 -38
  322. package/src/core/middleware/built-in/performance-monitor.ts +1 -1
  323. package/src/core/middleware/built-in/rate-limit.ts +2 -2
  324. package/src/core/middleware/built-in/request-logger.ts +1 -3
  325. package/src/core/middleware/built-in/session.ts +8 -7
  326. package/src/core/middleware/built-in/sse.ts +9 -11
  327. package/src/core/middleware/built-in/validation.ts +2 -2
  328. package/src/core/middleware/index.ts +6 -6
  329. package/src/core/modules/auto-discovery.ts +15 -478
  330. package/src/core/modules/index.ts +2 -2
  331. package/src/core/modules/modules.ts +12 -23
  332. package/src/core/networking/adapters/index.ts +3 -4
  333. package/src/core/networking/adapters/socketio-adapter.ts +3 -5
  334. package/src/core/networking/adapters/ws-adapter.ts +9 -8
  335. package/src/core/networking/index.ts +2 -3
  336. package/src/core/networking/service-discovery.ts +7 -6
  337. package/src/core/networking/websocket-manager.ts +7 -7
  338. package/src/core/routing/app-integration.ts +3 -3
  339. package/src/core/routing/index.ts +17 -201
  340. package/src/core/runtime/aws-lambda-adapter.ts +3 -3
  341. package/src/core/runtime/base-adapter.ts +2 -2
  342. package/src/core/runtime/cloudflare-workers-adapter.ts +3 -3
  343. package/src/core/runtime/index.ts +13 -13
  344. package/src/core/runtime/node-adapter.ts +10 -16
  345. package/src/core/runtime/vercel-edge-adapter.ts +3 -3
  346. package/src/core/utilities/hooks.ts +3 -3
  347. package/src/core/utilities/index.ts +4 -5
  348. package/src/core/validation/adapters.ts +1 -1
  349. package/src/core/validation/index.ts +16 -68
  350. package/src/index.ts +66 -73
  351. package/src/moro.ts +204 -685
  352. package/src/types/config.ts +2 -71
  353. package/src/types/core.ts +47 -49
  354. package/src/types/hooks.ts +1 -1
  355. package/src/types/http.ts +1 -23
  356. package/src/types/logger.ts +0 -9
  357. package/src/types/module.ts +0 -12
  358. package/src/types/runtime.ts +1 -1
  359. package/tsconfig.json +2 -4
  360. package/dist/core/config/config-manager.d.ts +0 -44
  361. package/dist/core/config/config-manager.js +0 -104
  362. package/dist/core/config/config-manager.js.map +0 -1
  363. package/dist/core/config/config-sources.d.ts +0 -21
  364. package/dist/core/config/config-sources.js +0 -499
  365. package/dist/core/config/config-sources.js.map +0 -1
  366. package/dist/core/config/config-validator.d.ts +0 -21
  367. package/dist/core/config/config-validator.js +0 -788
  368. package/dist/core/config/config-validator.js.map +0 -1
  369. package/dist/core/http/uws-http-server.d.ts +0 -64
  370. package/dist/core/http/uws-http-server.js +0 -688
  371. package/dist/core/http/uws-http-server.js.map +0 -1
  372. package/dist/core/middleware/built-in/jwt-helpers.d.ts +0 -118
  373. package/dist/core/middleware/built-in/jwt-helpers.js +0 -218
  374. package/dist/core/middleware/built-in/jwt-helpers.js.map +0 -1
  375. package/dist/core/networking/adapters/uws-adapter.d.ts +0 -44
  376. package/dist/core/networking/adapters/uws-adapter.js +0 -513
  377. package/dist/core/networking/adapters/uws-adapter.js.map +0 -1
  378. package/dist/core/utilities/package-utils.d.ts +0 -38
  379. package/dist/core/utilities/package-utils.js +0 -57
  380. package/dist/core/utilities/package-utils.js.map +0 -1
  381. package/jest.config.mjs +0 -41
  382. package/src/core/config/config-manager.ts +0 -133
  383. package/src/core/config/config-sources.ts +0 -596
  384. package/src/core/config/config-validator.ts +0 -1113
  385. package/src/core/http/uws-http-server.ts +0 -794
  386. package/src/core/middleware/built-in/jwt-helpers.ts +0 -243
  387. package/src/core/networking/adapters/uws-adapter.ts +0 -619
  388. package/src/core/utilities/package-utils.ts +0 -59
@@ -1,1113 +0,0 @@
1
- /**
2
- * Configuration Validator - Type-Safe Schema Validation
3
- *
4
- * This module provides runtime validation for configuration objects using
5
- * simple TypeScript functions that match the type definitions exactly.
6
- */
7
-
8
- import { AppConfig } from '../../types/config.js';
9
- import { createFrameworkLogger } from '../logger/index.js';
10
-
11
- const logger = createFrameworkLogger('ConfigValidator');
12
-
13
- /**
14
- * Configuration validation error with detailed context
15
- */
16
- export class ConfigValidationError extends Error {
17
- constructor(
18
- public readonly field: string,
19
- public readonly value: unknown,
20
- public readonly expectedType: string,
21
- message: string
22
- ) {
23
- super(`Configuration validation failed for '${field}': ${message}`);
24
- this.name = 'ConfigValidationError';
25
- }
26
- }
27
-
28
- /**
29
- * Validate and normalize a complete configuration object
30
- * This ensures type safety and provides helpful error messages
31
- */
32
- export function validateConfig(config: any): AppConfig {
33
- logger.debug('Validating configuration');
34
-
35
- try {
36
- const validatedConfig: AppConfig = {
37
- server: validateServerConfig(config.server, 'server'),
38
- serviceDiscovery: validateServiceDiscoveryConfig(config.serviceDiscovery, 'serviceDiscovery'),
39
- database: validateDatabaseConfig(config.database, 'database'),
40
- modules: validateModuleDefaultsConfig(config.modules, 'modules'),
41
- logging: validateLoggingConfig(config.logging, 'logging'),
42
- security: validateSecurityConfig(config.security, 'security'),
43
- external: validateExternalServicesConfig(config.external, 'external'),
44
- performance: validatePerformanceConfig(config.performance, 'performance'),
45
- websocket: validateWebSocketConfig(config.websocket, 'websocket'),
46
- };
47
-
48
- logger.debug('Configuration validation successful');
49
- return validatedConfig;
50
- } catch (error) {
51
- if (error instanceof ConfigValidationError) {
52
- logger.error(`❌ Configuration validation failed for '${error.field}':`, error.message);
53
-
54
- // Provide helpful hints
55
- provideValidationHints(error);
56
-
57
- throw error;
58
- }
59
-
60
- logger.error('❌ Unexpected configuration validation error:', String(error));
61
- throw new Error(`Configuration validation failed: ${String(error)}`);
62
- }
63
- }
64
-
65
- /**
66
- * Validate server configuration
67
- */
68
- function validateServerConfig(config: any, path: string) {
69
- if (!config || typeof config !== 'object') {
70
- throw new ConfigValidationError(
71
- path,
72
- config,
73
- 'object',
74
- 'Server configuration must be an object'
75
- );
76
- }
77
-
78
- const result: any = {
79
- port: validatePort(config.port, `${path}.port`),
80
- host: validateString(config.host, `${path}.host`),
81
- maxConnections: validateNumber(config.maxConnections, `${path}.maxConnections`, { min: 1 }),
82
- timeout: validateNumber(config.timeout, `${path}.timeout`, { min: 1000 }),
83
- bodySizeLimit: validateString(config.bodySizeLimit, `${path}.bodySizeLimit`),
84
- requestTracking: {
85
- enabled: validateBoolean(config.requestTracking?.enabled, `${path}.requestTracking.enabled`),
86
- },
87
- errorBoundary: {
88
- enabled: validateBoolean(config.errorBoundary?.enabled, `${path}.errorBoundary.enabled`),
89
- },
90
- };
91
-
92
- // Optional uWebSockets configuration
93
- if (config.useUWebSockets !== undefined) {
94
- result.useUWebSockets = validateBoolean(config.useUWebSockets, `${path}.useUWebSockets`);
95
- }
96
-
97
- // Optional SSL configuration
98
- if (config.ssl !== undefined) {
99
- result.ssl = validateSSLConfig(config.ssl, `${path}.ssl`);
100
- }
101
-
102
- return result;
103
- }
104
-
105
- /**
106
- * Validate SSL configuration
107
- */
108
- function validateSSLConfig(config: any, path: string) {
109
- if (!config || typeof config !== 'object') {
110
- throw new ConfigValidationError(path, config, 'object', 'SSL configuration must be an object');
111
- }
112
-
113
- const result: any = {};
114
-
115
- if (config.key_file_name !== undefined) {
116
- result.key_file_name = validateString(config.key_file_name, `${path}.key_file_name`);
117
- }
118
- if (config.cert_file_name !== undefined) {
119
- result.cert_file_name = validateString(config.cert_file_name, `${path}.cert_file_name`);
120
- }
121
- if (config.passphrase !== undefined) {
122
- result.passphrase = validateString(config.passphrase, `${path}.passphrase`);
123
- }
124
-
125
- return result;
126
- }
127
-
128
- /**
129
- * Validate service discovery configuration
130
- */
131
- function validateServiceDiscoveryConfig(config: any, path: string) {
132
- if (!config || typeof config !== 'object') {
133
- throw new ConfigValidationError(
134
- path,
135
- config,
136
- 'object',
137
- 'Service discovery configuration must be an object'
138
- );
139
- }
140
-
141
- return {
142
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
143
- type: validateEnum(config.type, ['memory', 'consul', 'kubernetes'], `${path}.type`),
144
- consulUrl: validateString(config.consulUrl, `${path}.consulUrl`),
145
- kubernetesNamespace: validateString(config.kubernetesNamespace, `${path}.kubernetesNamespace`),
146
- healthCheckInterval: validateNumber(config.healthCheckInterval, `${path}.healthCheckInterval`, {
147
- min: 1000,
148
- }),
149
- retryAttempts: validateNumber(config.retryAttempts, `${path}.retryAttempts`, { min: 0 }),
150
- };
151
- }
152
-
153
- /**
154
- * Validate database configuration
155
- */
156
- function validateDatabaseConfig(config: any, path: string) {
157
- if (!config || typeof config !== 'object') {
158
- throw new ConfigValidationError(
159
- path,
160
- config,
161
- 'object',
162
- 'Database configuration must be an object'
163
- );
164
- }
165
-
166
- const result: any = {};
167
-
168
- // Optional URL
169
- if (config.url !== undefined) {
170
- result.url = validateString(config.url, `${path}.url`);
171
- }
172
-
173
- // Optional Redis - only validate if present
174
- if (config.redis !== undefined) {
175
- result.redis = validateRedisConfig(config.redis, `${path}.redis`);
176
- }
177
-
178
- // Optional MySQL - only validate if present
179
- if (config.mysql !== undefined) {
180
- result.mysql = validateMySQLConfig(config.mysql, `${path}.mysql`);
181
- }
182
-
183
- // Optional PostgreSQL - only validate if present
184
- if (config.postgresql !== undefined) {
185
- result.postgresql = validatePostgreSQLConfig(config.postgresql, `${path}.postgresql`);
186
- }
187
-
188
- // Optional SQLite - only validate if present
189
- if (config.sqlite !== undefined) {
190
- result.sqlite = validateSQLiteConfig(config.sqlite, `${path}.sqlite`);
191
- }
192
-
193
- // Optional MongoDB - only validate if present
194
- if (config.mongodb !== undefined) {
195
- result.mongodb = validateMongoDBConfig(config.mongodb, `${path}.mongodb`);
196
- }
197
-
198
- return result;
199
- }
200
-
201
- /**
202
- * Validate Redis configuration
203
- */
204
- function validateRedisConfig(config: any, path: string) {
205
- if (!config || typeof config !== 'object') {
206
- throw new ConfigValidationError(
207
- path,
208
- config,
209
- 'object',
210
- 'Redis configuration must be an object'
211
- );
212
- }
213
-
214
- return {
215
- url: validateString(config.url, `${path}.url`),
216
- maxRetries: validateNumber(config.maxRetries, `${path}.maxRetries`, { min: 0 }),
217
- retryDelay: validateNumber(config.retryDelay, `${path}.retryDelay`, { min: 0 }),
218
- keyPrefix: validateString(config.keyPrefix, `${path}.keyPrefix`),
219
- };
220
- }
221
-
222
- /**
223
- * Validate MySQL configuration
224
- */
225
- function validateMySQLConfig(config: any, path: string) {
226
- if (!config || typeof config !== 'object') {
227
- throw new ConfigValidationError(
228
- path,
229
- config,
230
- 'object',
231
- 'MySQL configuration must be an object'
232
- );
233
- }
234
-
235
- const result: any = {
236
- host: validateString(config.host, `${path}.host`),
237
- port: validatePort(config.port, `${path}.port`),
238
- connectionLimit: validateNumber(config.connectionLimit, `${path}.connectionLimit`, { min: 1 }),
239
- acquireTimeout: validateNumber(config.acquireTimeout, `${path}.acquireTimeout`, { min: 1000 }),
240
- timeout: validateNumber(config.timeout, `${path}.timeout`, { min: 1000 }),
241
- };
242
-
243
- // Optional fields
244
- if (config.database !== undefined) {
245
- result.database = validateString(config.database, `${path}.database`);
246
- }
247
- if (config.username !== undefined) {
248
- result.username = validateString(config.username, `${path}.username`);
249
- }
250
- if (config.password !== undefined) {
251
- result.password = validateString(config.password, `${path}.password`);
252
- }
253
-
254
- return result;
255
- }
256
-
257
- /**
258
- * Validate PostgreSQL configuration
259
- */
260
- function validatePostgreSQLConfig(config: any, path: string) {
261
- if (!config || typeof config !== 'object') {
262
- throw new ConfigValidationError(
263
- path,
264
- config,
265
- 'object',
266
- 'PostgreSQL configuration must be an object'
267
- );
268
- }
269
-
270
- const result: any = {
271
- host: validateString(config.host, `${path}.host`),
272
- port: validatePort(config.port, `${path}.port`),
273
- connectionLimit: validateNumber(config.connectionLimit, `${path}.connectionLimit`, { min: 1 }),
274
- };
275
-
276
- // Optional fields
277
- if (config.database !== undefined) {
278
- result.database = validateString(config.database, `${path}.database`);
279
- }
280
- if (config.user !== undefined) {
281
- result.user = validateString(config.user, `${path}.user`);
282
- }
283
- if (config.password !== undefined) {
284
- result.password = validateString(config.password, `${path}.password`);
285
- }
286
- if (config.ssl !== undefined) {
287
- result.ssl = validateBoolean(config.ssl, `${path}.ssl`);
288
- }
289
-
290
- return result;
291
- }
292
-
293
- /**
294
- * Validate SQLite configuration
295
- */
296
- function validateSQLiteConfig(config: any, path: string) {
297
- if (!config || typeof config !== 'object') {
298
- throw new ConfigValidationError(
299
- path,
300
- config,
301
- 'object',
302
- 'SQLite configuration must be an object'
303
- );
304
- }
305
-
306
- const result: any = {
307
- filename: validateString(config.filename, `${path}.filename`),
308
- };
309
-
310
- // Optional fields
311
- if (config.memory !== undefined) {
312
- result.memory = validateBoolean(config.memory, `${path}.memory`);
313
- }
314
- if (config.verbose !== undefined) {
315
- result.verbose = validateBoolean(config.verbose, `${path}.verbose`);
316
- }
317
-
318
- return result;
319
- }
320
-
321
- /**
322
- * Validate MongoDB configuration
323
- */
324
- function validateMongoDBConfig(config: any, path: string) {
325
- if (!config || typeof config !== 'object') {
326
- throw new ConfigValidationError(
327
- path,
328
- config,
329
- 'object',
330
- 'MongoDB configuration must be an object'
331
- );
332
- }
333
-
334
- const result: any = {};
335
-
336
- // Either url or host+port
337
- if (config.url !== undefined) {
338
- result.url = validateString(config.url, `${path}.url`);
339
- }
340
- if (config.host !== undefined) {
341
- result.host = validateString(config.host, `${path}.host`);
342
- }
343
- if (config.port !== undefined) {
344
- result.port = validatePort(config.port, `${path}.port`);
345
- }
346
- if (config.database !== undefined) {
347
- result.database = validateString(config.database, `${path}.database`);
348
- }
349
- if (config.username !== undefined) {
350
- result.username = validateString(config.username, `${path}.username`);
351
- }
352
- if (config.password !== undefined) {
353
- result.password = validateString(config.password, `${path}.password`);
354
- }
355
-
356
- return result;
357
- }
358
-
359
- /**
360
- * Validate module defaults configuration
361
- */
362
- function validateModuleDefaultsConfig(config: any, path: string) {
363
- if (!config || typeof config !== 'object') {
364
- throw new ConfigValidationError(
365
- path,
366
- config,
367
- 'object',
368
- 'Module defaults configuration must be an object'
369
- );
370
- }
371
-
372
- return {
373
- cache: validateCacheConfig(config.cache, `${path}.cache`),
374
- rateLimit: validateRateLimitConfig(config.rateLimit, `${path}.rateLimit`),
375
- validation: validateValidationConfig(config.validation, `${path}.validation`),
376
- autoDiscovery: validateAutoDiscoveryConfig(config.autoDiscovery, `${path}.autoDiscovery`),
377
- };
378
- }
379
-
380
- /**
381
- * Validate auto-discovery configuration
382
- */
383
- function validateAutoDiscoveryConfig(config: any, path: string) {
384
- if (!config || typeof config !== 'object') {
385
- throw new ConfigValidationError(
386
- path,
387
- config,
388
- 'object',
389
- 'Auto-discovery configuration must be an object'
390
- );
391
- }
392
-
393
- return {
394
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
395
- paths: validateStringArray(config.paths, `${path}.paths`),
396
- patterns: validateStringArray(config.patterns, `${path}.patterns`),
397
- recursive: validateBoolean(config.recursive, `${path}.recursive`),
398
- loadingStrategy: validateEnum(
399
- config.loadingStrategy,
400
- ['eager', 'lazy', 'conditional'],
401
- `${path}.loadingStrategy`
402
- ),
403
- watchForChanges: validateBoolean(config.watchForChanges, `${path}.watchForChanges`),
404
- ignorePatterns: validateStringArray(config.ignorePatterns, `${path}.ignorePatterns`),
405
- loadOrder: validateEnum(
406
- config.loadOrder,
407
- ['alphabetical', 'dependency', 'custom'],
408
- `${path}.loadOrder`
409
- ),
410
- failOnError: validateBoolean(config.failOnError, `${path}.failOnError`),
411
- maxDepth: validateNumber(config.maxDepth, `${path}.maxDepth`),
412
- };
413
- }
414
-
415
- /**
416
- * Validate cache configuration
417
- */
418
- function validateCacheConfig(config: any, path: string) {
419
- if (!config || typeof config !== 'object') {
420
- throw new ConfigValidationError(
421
- path,
422
- config,
423
- 'object',
424
- 'Cache configuration must be an object'
425
- );
426
- }
427
-
428
- return {
429
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
430
- defaultTtl: validateNumber(config.defaultTtl, `${path}.defaultTtl`, { min: 0 }),
431
- maxSize: validateNumber(config.maxSize, `${path}.maxSize`, { min: 1 }),
432
- strategy: validateEnum(config.strategy, ['lru', 'lfu', 'fifo'], `${path}.strategy`),
433
- };
434
- }
435
-
436
- /**
437
- * Validate rate limit configuration
438
- */
439
- function validateRateLimitConfig(config: any, path: string) {
440
- if (!config || typeof config !== 'object') {
441
- throw new ConfigValidationError(
442
- path,
443
- config,
444
- 'object',
445
- 'Rate limit configuration must be an object'
446
- );
447
- }
448
-
449
- return {
450
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
451
- defaultRequests: validateNumber(config.defaultRequests, `${path}.defaultRequests`, { min: 1 }),
452
- defaultWindow: validateNumber(config.defaultWindow, `${path}.defaultWindow`, { min: 1000 }),
453
- skipSuccessfulRequests: validateBoolean(
454
- config.skipSuccessfulRequests,
455
- `${path}.skipSuccessfulRequests`
456
- ),
457
- skipFailedRequests: validateBoolean(config.skipFailedRequests, `${path}.skipFailedRequests`),
458
- };
459
- }
460
-
461
- /**
462
- * Validate validation configuration
463
- */
464
- function validateValidationConfig(config: any, path: string) {
465
- if (!config || typeof config !== 'object') {
466
- throw new ConfigValidationError(
467
- path,
468
- config,
469
- 'object',
470
- 'Validation configuration must be an object'
471
- );
472
- }
473
-
474
- return {
475
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
476
- stripUnknown: validateBoolean(config.stripUnknown, `${path}.stripUnknown`),
477
- abortEarly: validateBoolean(config.abortEarly, `${path}.abortEarly`),
478
- };
479
- }
480
-
481
- /**
482
- * Validate logging configuration
483
- */
484
- function validateLoggingConfig(config: any, path: string) {
485
- if (!config || typeof config !== 'object') {
486
- throw new ConfigValidationError(
487
- path,
488
- config,
489
- 'object',
490
- 'Logging configuration must be an object'
491
- );
492
- }
493
-
494
- return {
495
- level: validateEnum(config.level, ['debug', 'info', 'warn', 'error', 'fatal'], `${path}.level`),
496
- format: validateEnum(config.format, ['pretty', 'json', 'compact'], `${path}.format`),
497
- enableColors: validateBoolean(config.enableColors, `${path}.enableColors`),
498
- enableTimestamp: validateBoolean(config.enableTimestamp, `${path}.enableTimestamp`),
499
- enableContext: validateBoolean(config.enableContext, `${path}.enableContext`),
500
- outputs: validateLoggingOutputsConfig(config.outputs, `${path}.outputs`),
501
- };
502
- }
503
-
504
- /**
505
- * Validate logging outputs configuration
506
- */
507
- function validateLoggingOutputsConfig(config: any, path: string) {
508
- if (!config || typeof config !== 'object') {
509
- throw new ConfigValidationError(
510
- path,
511
- config,
512
- 'object',
513
- 'Logging outputs configuration must be an object'
514
- );
515
- }
516
-
517
- return {
518
- console: validateBoolean(config.console, `${path}.console`),
519
- file: validateLoggingFileConfig(config.file, `${path}.file`),
520
- webhook: validateLoggingWebhookConfig(config.webhook, `${path}.webhook`),
521
- };
522
- }
523
-
524
- /**
525
- * Validate logging file configuration
526
- */
527
- function validateLoggingFileConfig(config: any, path: string) {
528
- if (!config || typeof config !== 'object') {
529
- throw new ConfigValidationError(
530
- path,
531
- config,
532
- 'object',
533
- 'Logging file configuration must be an object'
534
- );
535
- }
536
-
537
- return {
538
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
539
- path: validateString(config.path, `${path}.path`),
540
- maxSize: validateString(config.maxSize, `${path}.maxSize`),
541
- maxFiles: validateNumber(config.maxFiles, `${path}.maxFiles`, { min: 1 }),
542
- };
543
- }
544
-
545
- /**
546
- * Validate logging webhook configuration
547
- */
548
- function validateLoggingWebhookConfig(config: any, path: string) {
549
- if (!config || typeof config !== 'object') {
550
- throw new ConfigValidationError(
551
- path,
552
- config,
553
- 'object',
554
- 'Logging webhook configuration must be an object'
555
- );
556
- }
557
-
558
- const result: any = {
559
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
560
- headers: validateObject(config.headers, `${path}.headers`),
561
- };
562
-
563
- // Optional URL
564
- if (config.url !== undefined) {
565
- result.url = validateString(config.url, `${path}.url`);
566
- }
567
-
568
- return result;
569
- }
570
-
571
- /**
572
- * Validate security configuration
573
- */
574
- function validateSecurityConfig(config: any, path: string) {
575
- if (!config || typeof config !== 'object') {
576
- throw new ConfigValidationError(
577
- path,
578
- config,
579
- 'object',
580
- 'Security configuration must be an object'
581
- );
582
- }
583
-
584
- return {
585
- cors: validateCorsConfig(config.cors, `${path}.cors`),
586
- helmet: validateHelmetConfig(config.helmet, `${path}.helmet`),
587
- rateLimit: validateSecurityRateLimitConfig(config.rateLimit, `${path}.rateLimit`),
588
- };
589
- }
590
-
591
- /**
592
- * Validate CORS configuration
593
- */
594
- function validateCorsConfig(config: any, path: string) {
595
- if (!config || typeof config !== 'object') {
596
- throw new ConfigValidationError(path, config, 'object', 'CORS configuration must be an object');
597
- }
598
-
599
- return {
600
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
601
- origin: validateCorsOrigin(config.origin, `${path}.origin`),
602
- methods: validateStringArray(config.methods, `${path}.methods`),
603
- allowedHeaders: validateStringArray(config.allowedHeaders, `${path}.allowedHeaders`),
604
- credentials: validateBoolean(config.credentials, `${path}.credentials`),
605
- };
606
- }
607
-
608
- /**
609
- * Validate CORS origin (can be string, array, or boolean)
610
- */
611
- function validateCorsOrigin(value: any, path: string): string | string[] | boolean {
612
- if (typeof value === 'boolean' || typeof value === 'string') {
613
- return value;
614
- }
615
- if (Array.isArray(value)) {
616
- return validateStringArray(value, path);
617
- }
618
- throw new ConfigValidationError(
619
- path,
620
- value,
621
- 'string | string[] | boolean',
622
- 'Must be a string, array of strings, or boolean'
623
- );
624
- }
625
-
626
- /**
627
- * Validate helmet configuration
628
- */
629
- function validateHelmetConfig(config: any, path: string) {
630
- if (!config || typeof config !== 'object') {
631
- throw new ConfigValidationError(
632
- path,
633
- config,
634
- 'object',
635
- 'Helmet configuration must be an object'
636
- );
637
- }
638
-
639
- return {
640
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
641
- contentSecurityPolicy: validateBoolean(
642
- config.contentSecurityPolicy,
643
- `${path}.contentSecurityPolicy`
644
- ),
645
- hsts: validateBoolean(config.hsts, `${path}.hsts`),
646
- noSniff: validateBoolean(config.noSniff, `${path}.noSniff`),
647
- frameguard: validateBoolean(config.frameguard, `${path}.frameguard`),
648
- };
649
- }
650
-
651
- /**
652
- * Validate security rate limit configuration
653
- */
654
- function validateSecurityRateLimitConfig(config: any, path: string) {
655
- if (!config || typeof config !== 'object') {
656
- throw new ConfigValidationError(
657
- path,
658
- config,
659
- 'object',
660
- 'Security rate limit configuration must be an object'
661
- );
662
- }
663
-
664
- return {
665
- global: validateGlobalRateLimitConfig(config.global, `${path}.global`),
666
- };
667
- }
668
-
669
- /**
670
- * Validate global rate limit configuration
671
- */
672
- function validateGlobalRateLimitConfig(config: any, path: string) {
673
- if (!config || typeof config !== 'object') {
674
- throw new ConfigValidationError(
675
- path,
676
- config,
677
- 'object',
678
- 'Global rate limit configuration must be an object'
679
- );
680
- }
681
-
682
- return {
683
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
684
- requests: validateNumber(config.requests, `${path}.requests`, { min: 1 }),
685
- window: validateNumber(config.window, `${path}.window`, { min: 1000 }),
686
- };
687
- }
688
-
689
- /**
690
- * Validate external services configuration
691
- */
692
- function validateExternalServicesConfig(config: any, path: string) {
693
- if (!config || typeof config !== 'object') {
694
- throw new ConfigValidationError(
695
- path,
696
- config,
697
- 'object',
698
- 'External services configuration must be an object'
699
- );
700
- }
701
-
702
- const result: any = {};
703
-
704
- // Optional services - only validate if present
705
- if (config.stripe !== undefined) {
706
- result.stripe = validateStripeConfig(config.stripe, `${path}.stripe`);
707
- }
708
- if (config.paypal !== undefined) {
709
- result.paypal = validatePayPalConfig(config.paypal, `${path}.paypal`);
710
- }
711
- if (config.smtp !== undefined) {
712
- result.smtp = validateSMTPConfig(config.smtp, `${path}.smtp`);
713
- }
714
-
715
- return result;
716
- }
717
-
718
- /**
719
- * Validate Stripe configuration
720
- */
721
- function validateStripeConfig(config: any, path: string) {
722
- if (!config || typeof config !== 'object') {
723
- throw new ConfigValidationError(
724
- path,
725
- config,
726
- 'object',
727
- 'Stripe configuration must be an object'
728
- );
729
- }
730
-
731
- const result: any = {};
732
-
733
- // Optional fields
734
- if (config.secretKey !== undefined) {
735
- result.secretKey = validateString(config.secretKey, `${path}.secretKey`);
736
- }
737
- if (config.publishableKey !== undefined) {
738
- result.publishableKey = validateString(config.publishableKey, `${path}.publishableKey`);
739
- }
740
- if (config.webhookSecret !== undefined) {
741
- result.webhookSecret = validateString(config.webhookSecret, `${path}.webhookSecret`);
742
- }
743
- if (config.apiVersion !== undefined) {
744
- result.apiVersion = validateString(config.apiVersion, `${path}.apiVersion`);
745
- } else {
746
- result.apiVersion = '2023-10-16'; // Default API version
747
- }
748
-
749
- return result;
750
- }
751
-
752
- /**
753
- * Validate PayPal configuration
754
- */
755
- function validatePayPalConfig(config: any, path: string) {
756
- if (!config || typeof config !== 'object') {
757
- throw new ConfigValidationError(
758
- path,
759
- config,
760
- 'object',
761
- 'PayPal configuration must be an object'
762
- );
763
- }
764
-
765
- const result: any = {
766
- environment: validateEnum(config.environment, ['sandbox', 'production'], `${path}.environment`),
767
- };
768
-
769
- // Optional fields
770
- if (config.clientId !== undefined) {
771
- result.clientId = validateString(config.clientId, `${path}.clientId`);
772
- }
773
- if (config.clientSecret !== undefined) {
774
- result.clientSecret = validateString(config.clientSecret, `${path}.clientSecret`);
775
- }
776
- if (config.webhookId !== undefined) {
777
- result.webhookId = validateString(config.webhookId, `${path}.webhookId`);
778
- }
779
-
780
- return result;
781
- }
782
-
783
- /**
784
- * Validate SMTP configuration
785
- */
786
- function validateSMTPConfig(config: any, path: string) {
787
- if (!config || typeof config !== 'object') {
788
- throw new ConfigValidationError(path, config, 'object', 'SMTP configuration must be an object');
789
- }
790
-
791
- const result: any = {
792
- port: validatePort(config.port, `${path}.port`),
793
- secure: validateBoolean(config.secure, `${path}.secure`),
794
- };
795
-
796
- // Optional fields
797
- if (config.host !== undefined) {
798
- result.host = validateString(config.host, `${path}.host`);
799
- }
800
- if (config.username !== undefined) {
801
- result.username = validateString(config.username, `${path}.username`);
802
- }
803
- if (config.password !== undefined) {
804
- result.password = validateString(config.password, `${path}.password`);
805
- }
806
-
807
- return result;
808
- }
809
-
810
- /**
811
- * Validate performance configuration
812
- */
813
- function validatePerformanceConfig(config: any, path: string) {
814
- if (!config || typeof config !== 'object') {
815
- throw new ConfigValidationError(
816
- path,
817
- config,
818
- 'object',
819
- 'Performance configuration must be an object'
820
- );
821
- }
822
-
823
- return {
824
- compression: validateCompressionConfig(config.compression, `${path}.compression`),
825
- circuitBreaker: validateCircuitBreakerConfig(config.circuitBreaker, `${path}.circuitBreaker`),
826
- clustering: validateClusteringConfig(config.clustering, `${path}.clustering`),
827
- };
828
- }
829
-
830
- /**
831
- * Validate compression configuration
832
- */
833
- function validateCompressionConfig(config: any, path: string) {
834
- if (!config || typeof config !== 'object') {
835
- throw new ConfigValidationError(
836
- path,
837
- config,
838
- 'object',
839
- 'Compression configuration must be an object'
840
- );
841
- }
842
-
843
- return {
844
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
845
- level: validateNumber(config.level, `${path}.level`, { min: 1, max: 9 }),
846
- threshold: validateNumber(config.threshold, `${path}.threshold`, { min: 0 }),
847
- };
848
- }
849
-
850
- /**
851
- * Validate circuit breaker configuration
852
- */
853
- function validateCircuitBreakerConfig(config: any, path: string) {
854
- if (!config || typeof config !== 'object') {
855
- throw new ConfigValidationError(
856
- path,
857
- config,
858
- 'object',
859
- 'Circuit breaker configuration must be an object'
860
- );
861
- }
862
-
863
- return {
864
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
865
- failureThreshold: validateNumber(config.failureThreshold, `${path}.failureThreshold`, {
866
- min: 1,
867
- }),
868
- resetTimeout: validateNumber(config.resetTimeout, `${path}.resetTimeout`, { min: 1000 }),
869
- monitoringPeriod: validateNumber(config.monitoringPeriod, `${path}.monitoringPeriod`, {
870
- min: 1000,
871
- }),
872
- };
873
- }
874
-
875
- /**
876
- * Validate clustering configuration
877
- */
878
- function validateClusteringConfig(config: any, path: string) {
879
- if (!config || typeof config !== 'object') {
880
- throw new ConfigValidationError(
881
- path,
882
- config,
883
- 'object',
884
- 'Clustering configuration must be an object'
885
- );
886
- }
887
-
888
- const result: any = {
889
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
890
- };
891
-
892
- // Workers can be number or 'auto'
893
- if (typeof config.workers === 'string' && config.workers === 'auto') {
894
- result.workers = 'auto';
895
- } else {
896
- result.workers = validateNumber(config.workers, `${path}.workers`, { min: 1 });
897
- }
898
-
899
- // Optional memoryPerWorkerGB
900
- if (config.memoryPerWorkerGB !== undefined) {
901
- result.memoryPerWorkerGB = validateNumber(
902
- config.memoryPerWorkerGB,
903
- `${path}.memoryPerWorkerGB`,
904
- { min: 0.1 }
905
- );
906
- }
907
-
908
- return result;
909
- }
910
-
911
- /**
912
- * Validate WebSocket configuration
913
- */
914
- function validateWebSocketConfig(config: any, path: string) {
915
- if (!config || typeof config !== 'object') {
916
- throw new ConfigValidationError(
917
- path,
918
- config,
919
- 'object',
920
- 'WebSocket configuration must be an object'
921
- );
922
- }
923
-
924
- const result: any = {
925
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
926
- };
927
-
928
- // Optional fields
929
- if (config.adapter !== undefined) {
930
- result.adapter = validateString(config.adapter, `${path}.adapter`);
931
- }
932
- if (config.compression !== undefined) {
933
- result.compression = validateBoolean(config.compression, `${path}.compression`);
934
- }
935
- if (config.customIdGenerator !== undefined) {
936
- result.customIdGenerator = config.customIdGenerator; // Function - no validation needed
937
- }
938
- if (config.options !== undefined) {
939
- result.options = validateWebSocketOptions(config.options, `${path}.options`);
940
- }
941
-
942
- return result;
943
- }
944
-
945
- /**
946
- * Validate WebSocket options
947
- */
948
- function validateWebSocketOptions(config: any, path: string) {
949
- if (!config || typeof config !== 'object') {
950
- throw new ConfigValidationError(path, config, 'object', 'WebSocket options must be an object');
951
- }
952
-
953
- const result: any = {};
954
-
955
- if (config.cors !== undefined) {
956
- result.cors = validateWebSocketCorsOptions(config.cors, `${path}.cors`);
957
- }
958
- if (config.path !== undefined) {
959
- result.path = validateString(config.path, `${path}.path`);
960
- }
961
- if (config.maxPayloadLength !== undefined) {
962
- result.maxPayloadLength = validateNumber(config.maxPayloadLength, `${path}.maxPayloadLength`, {
963
- min: 1024,
964
- });
965
- }
966
-
967
- return result;
968
- }
969
-
970
- /**
971
- * Validate WebSocket CORS options
972
- */
973
- function validateWebSocketCorsOptions(config: any, path: string) {
974
- if (!config || typeof config !== 'object') {
975
- throw new ConfigValidationError(
976
- path,
977
- config,
978
- 'object',
979
- 'WebSocket CORS options must be an object'
980
- );
981
- }
982
-
983
- const result: any = {};
984
-
985
- if (config.origin !== undefined) {
986
- result.origin = validateCorsOrigin(config.origin, `${path}.origin`);
987
- }
988
- if (config.credentials !== undefined) {
989
- result.credentials = validateBoolean(config.credentials, `${path}.credentials`);
990
- }
991
-
992
- return result;
993
- }
994
-
995
- // Basic validation functions
996
-
997
- function validatePort(value: any, path: string): number {
998
- const num = Number(value);
999
- if (isNaN(num) || num < 1 || num > 65535) {
1000
- throw new ConfigValidationError(
1001
- path,
1002
- value,
1003
- 'number (1-65535)',
1004
- 'Must be a number between 1 and 65535'
1005
- );
1006
- }
1007
- return num;
1008
- }
1009
-
1010
- function validateBoolean(value: any, path: string): boolean {
1011
- if (value === 'true' || value === true) return true;
1012
- if (value === 'false' || value === false) return false;
1013
- if (value === '1' || value === 1) return true;
1014
- if (value === '0' || value === 0) return false;
1015
- throw new ConfigValidationError(
1016
- path,
1017
- value,
1018
- 'boolean',
1019
- 'Must be a boolean (true/false) or numeric (1/0)'
1020
- );
1021
- }
1022
-
1023
- function validateNumber(
1024
- value: any,
1025
- path: string,
1026
- options: { min?: number; max?: number } = {}
1027
- ): number {
1028
- const num = Number(value);
1029
- if (isNaN(num)) {
1030
- throw new ConfigValidationError(path, value, 'number', 'Must be a valid number');
1031
- }
1032
- if (options.min !== undefined && num < options.min) {
1033
- throw new ConfigValidationError(
1034
- path,
1035
- value,
1036
- `number >= ${options.min}`,
1037
- `Must be at least ${options.min}`
1038
- );
1039
- }
1040
- if (options.max !== undefined && num > options.max) {
1041
- throw new ConfigValidationError(
1042
- path,
1043
- value,
1044
- `number <= ${options.max}`,
1045
- `Must be at most ${options.max}`
1046
- );
1047
- }
1048
- return num;
1049
- }
1050
-
1051
- function validateString(value: any, path: string): string {
1052
- if (typeof value !== 'string') {
1053
- throw new ConfigValidationError(path, value, 'string', 'Must be a string');
1054
- }
1055
- return value;
1056
- }
1057
-
1058
- function validateEnum<T extends string>(value: any, validValues: readonly T[], path: string): T {
1059
- const str = validateString(value, path);
1060
- if (!validValues.includes(str as T)) {
1061
- throw new ConfigValidationError(
1062
- path,
1063
- value,
1064
- `one of: ${validValues.join(', ')}`,
1065
- `Must be one of: ${validValues.join(', ')}`
1066
- );
1067
- }
1068
- return str as T;
1069
- }
1070
-
1071
- function validateStringArray(value: any, path: string): string[] {
1072
- if (!Array.isArray(value)) {
1073
- // Try to parse comma-separated string
1074
- if (typeof value === 'string') {
1075
- return value
1076
- .split(',')
1077
- .map(s => s.trim())
1078
- .filter(s => s.length > 0);
1079
- }
1080
- throw new ConfigValidationError(
1081
- path,
1082
- value,
1083
- 'string[]',
1084
- 'Must be an array or comma-separated string'
1085
- );
1086
- }
1087
- return value.map((item, index) => validateString(item, `${path}[${index}]`));
1088
- }
1089
-
1090
- function validateObject(value: any, path: string): Record<string, string> {
1091
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
1092
- throw new ConfigValidationError(path, value, 'object', 'Must be an object');
1093
- }
1094
- return value;
1095
- }
1096
-
1097
- /**
1098
- * Provide helpful validation hints based on the error
1099
- */
1100
- function provideValidationHints(error: ConfigValidationError): void {
1101
- if (error.field.includes('port')) {
1102
- logger.error(' 💡 Hint: Ports must be numbers between 1 and 65535');
1103
- }
1104
- if (error.field.includes('url')) {
1105
- logger.error(' 💡 Hint: URLs must include protocol (http:// or https://)');
1106
- }
1107
- if (error.field.includes('environment')) {
1108
- logger.error(' 💡 Hint: NODE_ENV must be one of: development, staging, production');
1109
- }
1110
- if (error.field.includes('level')) {
1111
- logger.error(' 💡 Hint: Log level must be one of: debug, info, warn, error, fatal');
1112
- }
1113
- }