@catbee/utils 0.0.4 → 0.0.6

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 (213) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +911 -242
  3. package/build/esm/config.d.ts +108 -8
  4. package/build/esm/config.js +122 -6
  5. package/build/esm/config.js.map +1 -1
  6. package/build/esm/index.d.ts +6 -0
  7. package/build/esm/index.js +29 -0
  8. package/build/esm/index.js.map +1 -1
  9. package/build/esm/servers/server.builder.d.ts +625 -0
  10. package/build/esm/servers/server.builder.js +722 -0
  11. package/build/esm/servers/server.builder.js.map +1 -0
  12. package/build/esm/servers/server.d.ts +256 -0
  13. package/build/esm/servers/server.js +1211 -0
  14. package/build/esm/servers/server.js.map +1 -0
  15. package/build/esm/types/api-response.d.ts +5 -7
  16. package/build/esm/types/api-response.js +23 -0
  17. package/build/esm/types/api-response.js.map +1 -1
  18. package/build/esm/types/index.d.ts +125 -0
  19. package/build/esm/types/index.js +25 -0
  20. package/build/esm/types/index.js.map +1 -0
  21. package/build/esm/types/server.d.ts +285 -0
  22. package/build/esm/types/server.js +25 -0
  23. package/build/esm/types/server.js.map +1 -0
  24. package/build/esm/utils/array.utils.js +23 -0
  25. package/build/esm/utils/array.utils.js.map +1 -1
  26. package/build/esm/utils/async.utils.js +23 -0
  27. package/build/esm/utils/async.utils.js.map +1 -1
  28. package/build/esm/utils/cache.utils.js +39 -16
  29. package/build/esm/utils/cache.utils.js.map +1 -1
  30. package/build/esm/utils/context-store.utils.d.ts +1 -1
  31. package/build/esm/utils/context-store.utils.js +24 -1
  32. package/build/esm/utils/context-store.utils.js.map +1 -1
  33. package/build/esm/utils/crypto.utils.js +26 -2
  34. package/build/esm/utils/crypto.utils.js.map +1 -1
  35. package/build/esm/utils/decorators.utils.d.ts +291 -0
  36. package/build/esm/utils/decorators.utils.js +395 -41
  37. package/build/esm/utils/decorators.utils.js.map +1 -1
  38. package/build/esm/utils/dir.utils.js +23 -0
  39. package/build/esm/utils/dir.utils.js.map +1 -1
  40. package/build/esm/utils/env.utils.d.ts +186 -23
  41. package/build/esm/utils/env.utils.js +517 -91
  42. package/build/esm/utils/env.utils.js.map +1 -1
  43. package/build/esm/utils/exception.utils.js +31 -8
  44. package/build/esm/utils/exception.utils.js.map +1 -1
  45. package/build/esm/utils/fs.utils.js +23 -0
  46. package/build/esm/utils/fs.utils.js.map +1 -1
  47. package/build/esm/utils/http-status-codes.js +23 -0
  48. package/build/esm/utils/http-status-codes.js.map +1 -1
  49. package/build/esm/utils/id.utils.js +23 -0
  50. package/build/esm/utils/id.utils.js.map +1 -1
  51. package/build/esm/utils/logger.utils.d.ts +118 -0
  52. package/build/esm/utils/logger.utils.js +251 -15
  53. package/build/esm/utils/logger.utils.js.map +1 -1
  54. package/build/esm/utils/middleware.utils.d.ts +29 -7
  55. package/build/esm/utils/middleware.utils.js +81 -55
  56. package/build/esm/utils/middleware.utils.js.map +1 -1
  57. package/build/esm/utils/obj.utils.d.ts +10 -3
  58. package/build/esm/utils/obj.utils.js +225 -15
  59. package/build/esm/utils/obj.utils.js.map +1 -1
  60. package/build/esm/utils/request.utils.d.ts +77 -0
  61. package/build/esm/utils/request.utils.js +196 -0
  62. package/build/esm/utils/request.utils.js.map +1 -0
  63. package/build/esm/utils/response.utils.d.ts +15 -1
  64. package/build/esm/utils/response.utils.js +55 -4
  65. package/build/esm/utils/response.utils.js.map +1 -1
  66. package/build/esm/utils/string.utils.js +23 -0
  67. package/build/esm/utils/string.utils.js.map +1 -1
  68. package/build/esm/utils/url.utils.js +23 -0
  69. package/build/esm/utils/url.utils.js.map +1 -1
  70. package/build/esm/utils/validate.utils.d.ts +7 -0
  71. package/build/esm/utils/validate.utils.js +35 -2
  72. package/build/esm/utils/validate.utils.js.map +1 -1
  73. package/build/esnext/config.d.ts +108 -8
  74. package/build/esnext/config.js +122 -6
  75. package/build/esnext/config.js.map +1 -1
  76. package/build/esnext/index.d.ts +6 -0
  77. package/build/esnext/index.js +29 -0
  78. package/build/esnext/index.js.map +1 -1
  79. package/build/esnext/servers/server.builder.d.ts +625 -0
  80. package/build/esnext/servers/server.builder.js +677 -0
  81. package/build/esnext/servers/server.builder.js.map +1 -0
  82. package/build/esnext/servers/server.d.ts +256 -0
  83. package/build/esnext/servers/server.js +918 -0
  84. package/build/esnext/servers/server.js.map +1 -0
  85. package/build/esnext/types/api-response.d.ts +5 -7
  86. package/build/esnext/types/api-response.js +23 -0
  87. package/build/esnext/types/api-response.js.map +1 -1
  88. package/build/esnext/types/index.d.ts +125 -0
  89. package/build/esnext/types/index.js +25 -0
  90. package/build/esnext/types/index.js.map +1 -0
  91. package/build/esnext/types/server.d.ts +285 -0
  92. package/build/esnext/types/server.js +25 -0
  93. package/build/esnext/types/server.js.map +1 -0
  94. package/build/esnext/utils/array.utils.js +23 -0
  95. package/build/esnext/utils/array.utils.js.map +1 -1
  96. package/build/esnext/utils/async.utils.js +23 -0
  97. package/build/esnext/utils/async.utils.js.map +1 -1
  98. package/build/esnext/utils/cache.utils.js +39 -16
  99. package/build/esnext/utils/cache.utils.js.map +1 -1
  100. package/build/esnext/utils/context-store.utils.d.ts +1 -1
  101. package/build/esnext/utils/context-store.utils.js +24 -1
  102. package/build/esnext/utils/context-store.utils.js.map +1 -1
  103. package/build/esnext/utils/crypto.utils.js +26 -2
  104. package/build/esnext/utils/crypto.utils.js.map +1 -1
  105. package/build/esnext/utils/decorators.utils.d.ts +291 -0
  106. package/build/esnext/utils/decorators.utils.js +371 -22
  107. package/build/esnext/utils/decorators.utils.js.map +1 -1
  108. package/build/esnext/utils/dir.utils.js +23 -0
  109. package/build/esnext/utils/dir.utils.js.map +1 -1
  110. package/build/esnext/utils/env.utils.d.ts +186 -23
  111. package/build/esnext/utils/env.utils.js +468 -77
  112. package/build/esnext/utils/env.utils.js.map +1 -1
  113. package/build/esnext/utils/exception.utils.js +30 -7
  114. package/build/esnext/utils/exception.utils.js.map +1 -1
  115. package/build/esnext/utils/fs.utils.js +23 -0
  116. package/build/esnext/utils/fs.utils.js.map +1 -1
  117. package/build/esnext/utils/http-status-codes.js +23 -0
  118. package/build/esnext/utils/http-status-codes.js.map +1 -1
  119. package/build/esnext/utils/id.utils.js +23 -0
  120. package/build/esnext/utils/id.utils.js.map +1 -1
  121. package/build/esnext/utils/logger.utils.d.ts +118 -0
  122. package/build/esnext/utils/logger.utils.js +222 -15
  123. package/build/esnext/utils/logger.utils.js.map +1 -1
  124. package/build/esnext/utils/middleware.utils.d.ts +29 -7
  125. package/build/esnext/utils/middleware.utils.js +77 -55
  126. package/build/esnext/utils/middleware.utils.js.map +1 -1
  127. package/build/esnext/utils/obj.utils.d.ts +10 -3
  128. package/build/esnext/utils/obj.utils.js +176 -12
  129. package/build/esnext/utils/obj.utils.js.map +1 -1
  130. package/build/esnext/utils/request.utils.d.ts +77 -0
  131. package/build/esnext/utils/request.utils.js +168 -0
  132. package/build/esnext/utils/request.utils.js.map +1 -0
  133. package/build/esnext/utils/response.utils.d.ts +15 -1
  134. package/build/esnext/utils/response.utils.js +55 -4
  135. package/build/esnext/utils/response.utils.js.map +1 -1
  136. package/build/esnext/utils/string.utils.js +23 -0
  137. package/build/esnext/utils/string.utils.js.map +1 -1
  138. package/build/esnext/utils/url.utils.js +23 -0
  139. package/build/esnext/utils/url.utils.js.map +1 -1
  140. package/build/esnext/utils/validate.utils.d.ts +7 -0
  141. package/build/esnext/utils/validate.utils.js +33 -0
  142. package/build/esnext/utils/validate.utils.js.map +1 -1
  143. package/build/src/config.d.ts +108 -8
  144. package/build/src/config.js +125 -7
  145. package/build/src/config.js.map +1 -1
  146. package/build/src/index.d.ts +6 -0
  147. package/build/src/index.js +32 -0
  148. package/build/src/index.js.map +1 -1
  149. package/build/src/servers/server.builder.d.ts +625 -0
  150. package/build/src/servers/server.builder.js +681 -0
  151. package/build/src/servers/server.builder.js.map +1 -0
  152. package/build/src/servers/server.d.ts +256 -0
  153. package/build/src/servers/server.js +958 -0
  154. package/build/src/servers/server.js.map +1 -0
  155. package/build/src/types/api-response.d.ts +5 -7
  156. package/build/src/types/api-response.js +23 -0
  157. package/build/src/types/api-response.js.map +1 -1
  158. package/build/src/types/index.d.ts +125 -0
  159. package/build/src/types/index.js +26 -0
  160. package/build/src/types/index.js.map +1 -0
  161. package/build/src/types/server.d.ts +285 -0
  162. package/build/src/types/server.js +26 -0
  163. package/build/src/types/server.js.map +1 -0
  164. package/build/src/utils/array.utils.js +23 -0
  165. package/build/src/utils/array.utils.js.map +1 -1
  166. package/build/src/utils/async.utils.js +23 -0
  167. package/build/src/utils/async.utils.js.map +1 -1
  168. package/build/src/utils/cache.utils.js +38 -15
  169. package/build/src/utils/cache.utils.js.map +1 -1
  170. package/build/src/utils/context-store.utils.d.ts +1 -1
  171. package/build/src/utils/context-store.utils.js +24 -1
  172. package/build/src/utils/context-store.utils.js.map +1 -1
  173. package/build/src/utils/crypto.utils.js +25 -1
  174. package/build/src/utils/crypto.utils.js.map +1 -1
  175. package/build/src/utils/decorators.utils.d.ts +291 -0
  176. package/build/src/utils/decorators.utils.js +373 -22
  177. package/build/src/utils/decorators.utils.js.map +1 -1
  178. package/build/src/utils/dir.utils.js +23 -0
  179. package/build/src/utils/dir.utils.js.map +1 -1
  180. package/build/src/utils/env.utils.d.ts +186 -23
  181. package/build/src/utils/env.utils.js +467 -76
  182. package/build/src/utils/env.utils.js.map +1 -1
  183. package/build/src/utils/exception.utils.js +30 -7
  184. package/build/src/utils/exception.utils.js.map +1 -1
  185. package/build/src/utils/fs.utils.js +23 -0
  186. package/build/src/utils/fs.utils.js.map +1 -1
  187. package/build/src/utils/http-status-codes.js +23 -0
  188. package/build/src/utils/http-status-codes.js.map +1 -1
  189. package/build/src/utils/id.utils.js +23 -0
  190. package/build/src/utils/id.utils.js.map +1 -1
  191. package/build/src/utils/logger.utils.d.ts +118 -0
  192. package/build/src/utils/logger.utils.js +228 -15
  193. package/build/src/utils/logger.utils.js.map +1 -1
  194. package/build/src/utils/middleware.utils.d.ts +29 -7
  195. package/build/src/utils/middleware.utils.js +76 -54
  196. package/build/src/utils/middleware.utils.js.map +1 -1
  197. package/build/src/utils/obj.utils.d.ts +10 -3
  198. package/build/src/utils/obj.utils.js +177 -12
  199. package/build/src/utils/obj.utils.js.map +1 -1
  200. package/build/src/utils/request.utils.d.ts +77 -0
  201. package/build/src/utils/request.utils.js +175 -0
  202. package/build/src/utils/request.utils.js.map +1 -0
  203. package/build/src/utils/response.utils.d.ts +15 -1
  204. package/build/src/utils/response.utils.js +56 -4
  205. package/build/src/utils/response.utils.js.map +1 -1
  206. package/build/src/utils/string.utils.js +23 -0
  207. package/build/src/utils/string.utils.js.map +1 -1
  208. package/build/src/utils/url.utils.js +23 -0
  209. package/build/src/utils/url.utils.js.map +1 -1
  210. package/build/src/utils/validate.utils.d.ts +7 -0
  211. package/build/src/utils/validate.utils.js +36 -2
  212. package/build/src/utils/validate.utils.js.map +1 -1
  213. package/package.json +40 -9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.builder.js","sourceRoot":"","sources":["../../../src/servers/server.builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAEtE,MAAM,OAAO,mBAAmB;IAAhC;QACU,WAAM,GAA0B,EAAE,CAAC;IA4qB7C,CAAC;IA1qBC;;;;;;OAMG;IACK,YAAY,CAAC,IAAY;QAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,yDAAyD,IAAI,EAAE,CAAC,CAAC;QACnF,CAAC;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IAEO,WAAW,CAA+B,GAAM,EAAE,KAA4C;QACpG,MAAM,OAAO,GACX,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;YAC/D,CAAC,CAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAkC;YACpD,CAAC,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,CAAiC,CAAC;IACtF,CAAC;IAEO,UAAU,CAChB,GAAM,EACN,MAAe,EACf,YAAmD,EAAE;QAErD,IAAI,CAAC,WAAW,CAAC,GAAG,kCAAO,SAAS,KAAE,MAAM,IAAG,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { deepObjMerge } from '../utils/obj.utils';\nimport { ServerConfig } from '../types/server';\nimport { defaultServerConfig } from '../config';\nimport { isPort } from '../utils/validate.utils';\n\n/**\n * Builder class for creating and configuring an Express server configuration.\n *\n * This class provides a fluent interface to configure all aspects of the Express server\n * including security settings, middleware, routing, and more.\n *\n * @example\n * ```typescript\n * const serverConfig = new ServerConfigBuilder()\n * .withPort(3000)\n * .withHost('localhost')\n * .enableCors()\n * .enableHelmet()\n * .build();\n * ```\n */\n\nexport const BUILD_MARKER = Symbol.for('catbee.express.server.build');\n\nexport class ServerConfigBuilder {\n private config: Partial<ServerConfig> = {};\n\n /**\n * Validates that a port number is valid and usable.\n *\n * @private\n * @param port - The port number to validate\n * @throws {Error} If port is not an integer or is outside the valid range (1-65535)\n */\n private validatePort(port: number): void {\n if (!isPort(port)) {\n throw new Error(`Port must be a valid number between 1 and 65535, got: ${port}`);\n }\n }\n\n /**\n * Sets the port the server will listen on.\n *\n * @param port - The port number (1-65535)\n * @returns The builder instance for chaining\n * @throws {Error} If port is invalid\n * @default 3000 (can be overridden via PORT env variable)\n *\n * @example\n * ```typescript\n * builder.withPort(3000)\n * ```\n */\n withPort(port: number): this {\n this.validatePort(port);\n this.config.port = port;\n return this;\n }\n\n /**\n * Sets the hostname the server will bind to.\n *\n * @param host - The hostname (e.g., 'localhost', '0.0.0.0', '127.0.0.1')\n * @returns The builder instance for chaining\n * @default '0.0.0.0' (can be overridden via HOST env variable)\n *\n * @example\n * ```typescript\n * builder.withHost('0.0.0.0') // Listen on all interfaces\n * ```\n */\n withHost(host: string): this {\n this.config.host = host;\n return this;\n }\n\n /**\n * Configures Cross-Origin Resource Sharing (CORS) for the server.\n *\n * @param opts - CORS options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (CORS is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable CORS with default options\n * builder.withCors(true)\n *\n * // Configure CORS with specific options\n * builder.withCors({\n * origin: ['https://example.com'],\n * methods: ['GET', 'POST']\n * })\n * ```\n */\n withCors(opts: ServerConfig['cors']): this {\n this.config.cors = opts;\n return this;\n }\n\n /**\n * Enables CORS with default settings\n *\n * @returns The builder instance for chaining\n */\n enableCors(): this {\n return this.withCors(true);\n }\n\n /**\n * Disables CORS\n *\n * @returns The builder instance for chaining\n */\n disableCors(): this {\n return this.withCors(false);\n }\n\n /**\n * Configures the Helmet middleware for setting HTTP security headers.\n *\n * @param opts - Helmet options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (Helmet is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable Helmet with default settings\n * builder.withHelmet(true)\n *\n * // Configure Helmet with specific options\n * builder.withHelmet({\n * contentSecurityPolicy: false,\n * xssFilter: true\n * })\n * ```\n */\n withHelmet(opts: ServerConfig['helmet']): this {\n this.config.helmet = opts;\n return this;\n }\n\n /**\n * Enables Helmet with default settings\n *\n * @returns The builder instance for chaining\n */\n enableHelmet(): this {\n return this.withHelmet(true);\n }\n\n /**\n * Disables Helmet\n *\n * @returns The builder instance for chaining\n */\n disableHelmet(): this {\n return this.withHelmet(false);\n }\n\n /**\n * Configures response compression middleware.\n *\n * @param opts - Compression options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (Compression is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable compression with default settings\n * builder.withCompression(true)\n *\n * // Configure compression with specific options\n * builder.withCompression({\n * level: 6,\n * threshold: 1024\n * })\n * ```\n */\n withCompression(opts: ServerConfig['compression']): this {\n this.config.compression = opts;\n return this;\n }\n\n /**\n * Enables compression with default settings\n *\n * @returns The builder instance for chaining\n */\n enableCompression(): this {\n return this.withCompression(true);\n }\n\n /**\n * Disables compression\n *\n * @returns The builder instance for chaining\n */\n disableCompression(): this {\n return this.withCompression(false);\n }\n\n /**\n * Configures rate limiting to protect against brute-force attacks.\n *\n * @param opts - Rate limit configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, windowMs: 15 * 60 * 1000, max: 100, message: 'Too many requests', standardHeaders: true, legacyHeaders: false }\n *\n * @example\n * ```typescript\n * builder.withRateLimit({\n * enable: true,\n * windowMs: 15 * 60 * 1000, // 15 minutes\n * max: 100 // limit each IP to 100 requests per windowMs\n * })\n * ```\n */\n withRateLimit(opts: Partial<ServerConfig['rateLimit']>): this {\n this.mergeConfig('rateLimit', opts as NonNullable<ServerConfig['rateLimit']>);\n return this;\n }\n\n /**\n * Enables rate limiting with default or custom settings\n *\n * @param opts - Optional rate limit configuration (max requests, window, etc.)\n * @returns The builder instance for chaining\n */\n enableRateLimit(opts: Omit<Partial<NonNullable<ServerConfig['rateLimit']>>, 'enable'> = {}): this {\n return this.setEnabled('rateLimit', true, opts);\n }\n\n /**\n * Disables rate limiting\n *\n * @returns The builder instance for chaining\n */\n disableRateLimit(): this {\n return this.setEnabled('rateLimit', false);\n }\n\n /**\n * Configures HTTP request logging middleware.\n *\n * @param opts - Request logging configuration options\n * @returns The builder instance for chaining\n * @default { enable: true in dev/false in prod, ignorePaths: ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'], skipNotFoundRoutes: false }\n *\n * @example\n * ```typescript\n * builder.withRequestLogging({\n * enable: true,\n * ignorePaths: ['/health', '/metrics'],\n * skipNotFoundRoutes: true\n * })\n * ```\n */\n withRequestLogging(opts: Partial<NonNullable<ServerConfig['requestLogging']>>): this {\n this.mergeConfig('requestLogging', opts as NonNullable<ServerConfig['requestLogging']>);\n return this;\n }\n\n /**\n * Enables request logging with default or custom settings\n *\n * @param opts - Optional request logging configuration\n * @returns The builder instance for chaining\n */\n enableRequestLogging(opts: Omit<Partial<NonNullable<ServerConfig['requestLogging']>>, 'enable'> = {}): this {\n return this.setEnabled('requestLogging', true, opts);\n }\n\n /**\n * Disables request logging\n *\n * @returns The builder instance for chaining\n */\n disableRequestLogging(): this {\n return this.setEnabled('requestLogging', false);\n }\n\n /**\n * Configures server metrics collection and endpoints.\n *\n * @param opts - Metrics configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, path: '/metrics', withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withMetrics({\n * enable: true,\n * path: '/metrics'\n * })\n * ```\n */\n withMetrics(opts: Partial<NonNullable<ServerConfig['metrics']>>): this {\n this.mergeConfig('metrics', opts as NonNullable<ServerConfig['metrics']>);\n return this;\n }\n\n /**\n * Enables Prometheus metrics collection and endpoint\n *\n * @param opts - Optional metrics configuration\n * @returns The builder instance for chaining\n */\n enableMetrics(opts: Omit<Partial<NonNullable<ServerConfig['metrics']>>, 'enable'> = {}): this {\n return this.setEnabled('metrics', true, opts);\n }\n\n /**\n * Disables Prometheus metrics\n *\n * @returns The builder instance for chaining\n */\n disableMetrics(): this {\n return this.setEnabled('metrics', false);\n }\n\n /**\n * Configures server health check endpoint.\n *\n * @param opts - Health check configuration options\n * @returns The builder instance for chaining\n * @default { path: '/healthz', detailed: true, withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withHealthCheck({\n * path: '/health',\n * detailed: true\n * })\n * ```\n */\n withHealthCheck(opts: Partial<NonNullable<ServerConfig['healthCheck']>>): this {\n this.mergeConfig('healthCheck', opts as NonNullable<ServerConfig['healthCheck']>);\n return this;\n }\n\n /**\n * Configures OpenAPI/Swagger documentation for the API.\n *\n * @param opts - OpenAPI configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, mountPath: '/docs', verbose: false, withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withOpenApi({\n * enable: true,\n * path: '/api-docs',\n * filePath: './openapi.yaml'\n * })\n * ```\n */\n withOpenApi(opts: Partial<NonNullable<ServerConfig['openApi']>>): this {\n this.mergeConfig('openApi', opts as NonNullable<ServerConfig['openApi']>);\n return this;\n }\n\n /**\n * Enables OpenAPI documentation with required file path\n *\n * @param filePath - Path to OpenAPI specification file (required)\n * @param opts - Optional OpenAPI configuration\n * @returns The builder instance for chaining\n */\n enableOpenApi(\n filePath: string,\n opts: Omit<Partial<NonNullable<ServerConfig['openApi']>>, 'enable' | 'filePath'> = {}\n ): this {\n this.setEnabled('openApi', true, { filePath, ...opts });\n return this;\n }\n\n /**\n * Disables OpenAPI documentation\n *\n * @returns The builder instance for chaining\n */\n disableOpenApi(): this {\n return this.setEnabled('openApi', false);\n }\n\n /**\n * Configures the server as a microservice with versioning.\n *\n * @param opts - Microservice configuration options including app name and service version\n * @returns The builder instance for chaining\n * @default { isMicroservice: false, appName: 'express_app' }\n *\n * @example\n * ```typescript\n * builder.withMicroService({\n * appName: 'user-service',\n * serviceVersion: {\n * enable: true,\n * version: '1.2.3'\n * }\n * })\n * ```\n */\n withMicroService(opts: {\n appName: NonNullable<ServerConfig['appName']>;\n serviceVersion: Partial<NonNullable<ServerConfig['serviceVersion']>>;\n }): this {\n this.config.isMicroservice = true;\n this.config.appName = opts.appName;\n\n this.mergeConfig('serviceVersion', opts.serviceVersion as NonNullable<ServerConfig['serviceVersion']>);\n return this;\n }\n\n /**\n * Configures the trust proxy settings to determine if X-Forwarded-* headers should be trusted.\n *\n * @param opts - Trust proxy configuration options\n * @returns The builder instance for chaining\n * @default false\n *\n * @example\n * ```typescript\n * // Trust proxy headers (useful when behind a load balancer)\n * builder.withTrustProxy(true)\n * ```\n */\n withTrustProxy(opts: NonNullable<ServerConfig['trustProxy']>): this {\n this.config.trustProxy = opts;\n return this;\n }\n\n /**\n * Configures the request ID middleware for tracing requests across services.\n *\n * @param opts - Request ID configuration options\n * @returns The builder instance for chaining\n * @default { headerName: 'x-request-id', exposeHeader: true }\n *\n * @example\n * ```typescript\n * builder.withRequestId({\n * headerName: 'X-Request-Id',\n * generator: () => crypto.randomUUID()\n * })\n * ```\n */\n withRequestId(opts: Partial<NonNullable<ServerConfig['requestId']>>): this {\n this.mergeConfig('requestId', opts as NonNullable<ServerConfig['requestId']>);\n return this;\n }\n\n /**\n * Configures the response time middleware for measuring request processing times.\n *\n * @param opts - Response time configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, addHeader: true, logOnComplete: false }\n *\n * @example\n * ```typescript\n * builder.withResponseTime({\n * enable: true,\n * addHeader: true,\n * logOnComplete: true\n * })\n * ```\n */\n withResponseTime(opts: Partial<NonNullable<ServerConfig['responseTime']>>): this {\n this.mergeConfig('responseTime', opts as NonNullable<ServerConfig['responseTime']>);\n return this;\n }\n\n /**\n * Enables response time tracking with default or custom settings\n *\n * @param opts - Optional response time configuration\n * @returns The builder instance for chaining\n */\n enableResponseTime(opts: Omit<Partial<NonNullable<ServerConfig['responseTime']>>, 'enable'> = {}): this {\n this.setEnabled('responseTime', true, opts);\n return this;\n }\n\n /**\n * Disables response time tracking\n *\n * @returns The builder instance for chaining\n */\n disableResponseTime(): this {\n return this.setEnabled('responseTime', false);\n }\n\n /**\n * Configures the body parser middleware options for parsing request bodies.\n *\n * @param opts - Body parser configuration options\n * @returns The builder instance for chaining\n * @default { json: { limit: '1mb' }, urlencoded: { extended: true, limit: '1mb' } }\n *\n * @example\n * ```typescript\n * builder.withBodyParser({\n * json: {\n * limit: '1mb'\n * },\n * urlencoded: {\n * extended: true,\n * limit: '1mb'\n * }\n * })\n * ```\n */\n withBodyParser(opts: NonNullable<ServerConfig['bodyParser']>): this {\n this.config.bodyParser = deepObjMerge({}, this.config.bodyParser ?? {}, opts);\n return this;\n }\n\n /**\n * Configures cookie parsing middleware.\n *\n * @param opts - Cookie parser options or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false\n *\n * @example\n * ```typescript\n * // Enable cookie parsing with default options\n * builder.withCookies(true)\n *\n * // Enable cookie parsing with specific options\n * builder.withCookies({\n * secret: 'your-secret-key',\n * secure: true\n * })\n * ```\n */\n withCookies(opts: ServerConfig['cookieParser']): this {\n this.config.cookieParser = opts;\n return this;\n }\n\n /**\n * Configures the logger used by the server.\n *\n * @param opts - Logger configuration options\n * @returns The builder instance for chaining\n * @default { name: 'express_app', level: 'info', prettyPrint: true in dev, singleLine: false }\n *\n * @example\n * ```typescript\n * builder.withLogger({\n * level: 'info',\n * prettyPrint: true,\n * singleLine: false\n * })\n * ```\n */\n withLogger(opts: Partial<NonNullable<ServerConfig['logger']>>): this {\n this.mergeConfig('logger', opts as NonNullable<ServerConfig['logger']>);\n return this;\n }\n\n /**\n * Adds a static folder to serve files from.\n *\n * @param folder - Static folder configuration\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withStaticFolder({\n * path: '/assets',\n * directory: './public',\n * options: { maxAge: '1d' }\n * })\n * ```\n */\n withStaticFolder(folder: NonNullable<ServerConfig['staticFolders']>[number]): this {\n if (!folder.path) throw new Error('Static folder requires a path');\n const folders = [...(this.config.staticFolders ?? []), folder];\n this.config.staticFolders = Array.from(new Map(folders.map(f => [f.path, f])).values());\n return this;\n }\n\n /**\n * Sets global headers to be included in all responses.\n *\n * @param headers - Object containing header name/value pairs or functions that return values\n * @returns The builder instance for chaining\n * @default {}\n *\n * @example\n * ```typescript\n * builder.withGlobalHeaders({\n * 'X-Powered-By': 'Catbee',\n * 'Server-Time': () => new Date().toISOString()\n * })\n * ```\n */\n withGlobalHeaders(headers: NonNullable<ServerConfig['globalHeaders']>): this {\n this.mergeConfig('globalHeaders', headers);\n return this;\n }\n\n /**\n * Sets a global prefix for all routes.\n *\n * @param prefix - The prefix to prepend to all routes (e.g., '/api/v1')\n * @returns The builder instance for chaining\n * @default '/'\n *\n * @example\n * ```typescript\n * builder.withGlobalPrefix('/api/v1')\n * ```\n */\n withGlobalPrefix(prefix: string): this {\n this.config.globalPrefix = prefix;\n return this;\n }\n\n /**\n * Applies custom configuration overrides directly.\n *\n * @param overrides - Custom configuration options to merge\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withCustom({\n * port: 8080,\n * customMiddleware: myMiddlewareFunction\n * })\n * ```\n */\n withCustom(overrides: Partial<ServerConfig>): this {\n this.config = deepObjMerge({}, this.config, overrides);\n return this;\n }\n\n /**\n * Configures HTTPS server options.\n *\n * @param opts - HTTPS configuration (key, cert, ca, passphrase, etc.)\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withHttps({\n * key: './localhost-key.pem',\n * cert: './localhost-cert.pem'\n * })\n * ```\n */\n withHttps(opts: NonNullable<ServerConfig['https']>): this {\n this.config.https = opts;\n return this;\n }\n\n /**\n * Builds and returns the final server configuration.\n *\n * This method merges the user-specified configuration with default values,\n * ensures all sections with 'enable' flags are properly structured, and\n * produces the final configuration to be used by the server.\n *\n * @returns The complete ServerConfig object\n *\n * @example\n * ```typescript\n * const config = new ServerConfigBuilder()\n * .withPort(3000)\n * .withHost('localhost')\n * .withCors(true)\n * .build();\n * ```\n */\n build() {\n const config = deepObjMerge({}, defaultServerConfig, this.config) as ServerConfig;\n\n // Common validation\n if (config.openApi?.enable && !config.openApi.filePath) {\n throw new Error('OpenAPI is enabled but no filePath is specified');\n }\n\n return Object.freeze({\n ...config,\n [BUILD_MARKER]: true\n });\n }\n\n private mergeConfig<K extends keyof ServerConfig>(key: K, value: Partial<NonNullable<ServerConfig[K]>>): void {\n const current =\n typeof this.config[key] === 'object' && this.config[key] !== null\n ? (this.config[key] as NonNullable<ServerConfig[K]>)\n : {};\n this.config[key] = deepObjMerge({}, current, value) as NonNullable<ServerConfig[K]>;\n }\n\n private setEnabled<K extends keyof ServerConfig>(\n key: K,\n enable: boolean,\n overrides: Partial<NonNullable<ServerConfig[K]>> = {}\n ): this {\n this.mergeConfig(key, { ...overrides, enable });\n return this;\n }\n}\n"]}
@@ -0,0 +1,256 @@
1
+ import express, { Express, Router } from 'express';
2
+ import http from 'http';
3
+ import https from 'https';
4
+ import client from 'prom-client';
5
+ import { ServerConfig, ServerHooks } from '../types/server';
6
+ /**
7
+ * Production-ready Express server with enterprise features.
8
+ *
9
+ * Core Features:
10
+ * - Security: Helmet, CORS, rate limiting, timeouts
11
+ * - Monitoring: Request logs, metrics, health checks
12
+ * - Performance: Compression, caching, static files
13
+ * - Reliability: Graceful shutdown, error handling
14
+ * - Developer UX: OpenAPI docs, debugging tools
15
+ * - Extensibility: Hooks, middleware, custom routes
16
+ *
17
+ * Designed for microservices and production workloads.
18
+ * Includes K8s readiness probes and zero-downtime support.
19
+ */
20
+ export declare class ExpressServer {
21
+ /** Prometheus client registry for metrics collection */
22
+ private register;
23
+ /** HTTP server instance (null when not running) */
24
+ protected server: http.Server | https.Server | null;
25
+ /** Merged configuration with defaults applied */
26
+ protected config: ServerConfig;
27
+ /** User-defined lifecycle hooks */
28
+ protected hooks: ServerHooks;
29
+ /** Global API prefix (from config) */
30
+ protected globalPrefix: string;
31
+ /** Internal fallback router */
32
+ private rootRouter;
33
+ /** User-supplied router */
34
+ private externalRouter?;
35
+ /** Internal Express app instance */
36
+ private app;
37
+ /** Set of active WebSocket connections */
38
+ private connections;
39
+ /** Flag indicating if the server is shutting down */
40
+ private isShuttingDown;
41
+ /**
42
+ * Collection of registered health check functions.
43
+ * These are executed when the health check endpoint is accessed.
44
+ */
45
+ private healthChecks;
46
+ /** Prometheus metrics for monitoring */
47
+ private requestCounter?;
48
+ private routeTimings?;
49
+ private requestSizes?;
50
+ private clientIPs?;
51
+ /** Promise that resolves when initialization (middleware + routes) is complete */
52
+ private initPromise;
53
+ /**
54
+ * Initializes server with intelligent defaults and security best practices.
55
+ * All settings can be customized via config and hooks.
56
+ *
57
+ * Default Security:
58
+ * - Secure headers (Helmet)
59
+ * - Rate limiting
60
+ * - Request timeouts
61
+ * - Body size limits
62
+ * - CORS protection
63
+ *
64
+ * Default Monitoring:
65
+ * - Request/Response logging
66
+ * - Prometheus metrics
67
+ * - Health checks
68
+ * - Request tracing
69
+ */
70
+ constructor(config: Partial<ServerConfig>, hooks?: ServerHooks);
71
+ /**
72
+ * Execute a lifecycle hook safely with comprehensive error handling.
73
+ * Prevents hook failures from crashing the server while logging issues.
74
+ *
75
+ * @param hook Name of the lifecycle hook to execute
76
+ * @param args Arguments to pass to the hook function
77
+ */
78
+ private runHook;
79
+ /**
80
+ * Initialize the Express server with middleware and routes.
81
+ */
82
+ private initialize;
83
+ /**
84
+ * Configure and register all middlewares in the optimal order.
85
+ *
86
+ * Middleware Order (CRITICAL - don't change without understanding implications):
87
+ * 1. Basic server configuration (trust proxy, x-powered-by)
88
+ * 2. Request ID generation (for tracing)
89
+ * 3. Request context setup (for logging correlation)
90
+ * 4. Timeout protection (prevents hanging requests)
91
+ * 5. Response time tracking (for performance monitoring)
92
+ * 6. Request logging (after ID/context setup)
93
+ * 7. Custom request hooks
94
+ * 8. Security middleware (rate limiting, CORS, Helmet)
95
+ * 9. Response compression
96
+ * 10. Static file serving
97
+ * 11. Request parsing (body parsing, cookies)
98
+ * 12. API documentation (OpenAPI)
99
+ * 13. Global headers
100
+ * 14. Custom response hooks
101
+ */
102
+ protected setupMiddleware(): Promise<void>;
103
+ /**
104
+ * Configure server routes and error handling.
105
+ * Sets up in following order:
106
+ *
107
+ * 1. Built-in routes (health, metrics)
108
+ * 2. Application routes
109
+ * 3. 404 handler
110
+ * 4. Error handler
111
+ */
112
+ protected setupRoutes(): Promise<void>;
113
+ /**
114
+ * Register a new health check function for monitoring service dependencies.
115
+ *
116
+ * Health checks are executed when the health endpoint is accessed and
117
+ * help determine if the service is ready to handle requests.
118
+ *
119
+ * Examples:
120
+ * - Database connectivity
121
+ * - External service availability
122
+ * - File system access
123
+ * - Memory/CPU usage checks
124
+ *
125
+ * @param name Unique identifier for the check (used in detailed responses)
126
+ * @param check Function returning boolean or Promise<boolean> indicating health
127
+ * @returns This instance for method chaining
128
+ */
129
+ registerHealthCheck(name: string, check: () => Promise<boolean> | boolean): this;
130
+ /**
131
+ * Get the underlying Express application instance.
132
+ * Use this for advanced Express features not exposed by this wrapper.
133
+ *
134
+ * @returns The raw Express app instance
135
+ */
136
+ getApp(): Express;
137
+ /**
138
+ * Get the active HTTP/HTTPS server instance.
139
+ * Returns null if the server is not currently running.
140
+ *
141
+ * @returns The HTTP/HTTPS server instance or null
142
+ */
143
+ getServer(): http.Server | https.Server | null;
144
+ /**
145
+ * Start the HTTP server and begin listening for requests.
146
+ *
147
+ * This method:
148
+ * - Executes beforeStart hooks
149
+ * - Binds to the configured host/port
150
+ * - Sets up error handling for startup failures
151
+ * - Executes afterStart hooks on success
152
+ * - Logs startup information
153
+ *
154
+ * @returns Promise resolving to the running HTTP server instance
155
+ * @throws Error if server fails to start or port is already in use
156
+ */
157
+ start(): Promise<http.Server | https.Server>;
158
+ /**
159
+ * Stop the HTTP server gracefully.
160
+ *
161
+ * This method:
162
+ * - Executes beforeStop hooks
163
+ * - Stops accepting new connections
164
+ * - Waits for existing connections to finish
165
+ * - Closes the server
166
+ * - Executes afterStop hooks
167
+ * - Logs shutdown information
168
+ *
169
+ * Graceful shutdown ensures:
170
+ * - No requests are dropped
171
+ * - Resources are properly cleaned up
172
+ * - Monitoring systems are notified
173
+ */
174
+ stop(force?: boolean): Promise<void>;
175
+ /**
176
+ * Enable graceful shutdown on OS signals for production deployment.
177
+ *
178
+ * This is essential for:
179
+ * - Container orchestration (Docker, Kubernetes)
180
+ * - Process managers (PM2, systemd)
181
+ * - Load balancer health checks
182
+ * - Zero-downtime deployments
183
+ *
184
+ * @param signals Array of process signals to listen for (default: SIGINT, SIGTERM)
185
+ */
186
+ enableGracefulShutdown(signals?: NodeJS.Signals[]): void;
187
+ /**
188
+ * Set an externally created base router.
189
+ * This will override the internal rootRouter.
190
+ */
191
+ setBaseRouter(router: Router): void;
192
+ /**
193
+ * Create and register a new router (only used if not injecting one externally - use `setBaseRouter` instead).
194
+ */
195
+ createRouter(prefix?: string): Router;
196
+ /**
197
+ * Register a new route handler with support for multiple HTTP methods.
198
+ * The route is automatically registered under the globalPrefix if set.
199
+ *
200
+ * @param methods Array of HTTP methods (get, post, put, delete, etc.)
201
+ * @param path Route path with Express path patterns support
202
+ * @param handlers One or more Express request handlers (middleware + final handler)
203
+ * @returns This instance for method chaining
204
+ */
205
+ registerRoute(methods: Array<keyof Pick<Express, 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'>>, path: string, ...handlers: Array<express.RequestHandler>): this;
206
+ /**
207
+ * Register custom middleware with optional path restriction.
208
+ *
209
+ * Use this for:
210
+ * - Adding authentication to specific routes
211
+ * - Custom logging or validation
212
+ * - Request transformation
213
+ * - Third-party middleware integration
214
+ *
215
+ * @param path Optional path prefix or middleware function if no path
216
+ * @param middleware Middleware handler (required if path is provided)
217
+ * @returns This instance for method chaining
218
+ */
219
+ registerMiddleware(path: string | express.RequestHandler, middleware?: express.RequestHandler): this;
220
+ /**
221
+ * Register one or more middleware functions to be applied globally.
222
+ * This is a simpler alternative to registerMiddleware when you just want
223
+ * to add middleware without path restrictions.
224
+ *
225
+ * @param middlewares One or more Express middleware functions
226
+ * @returns This instance for method chaining
227
+ */
228
+ useMiddleware(...middlewares: express.RequestHandler[]): this;
229
+ /**
230
+ * Get Prometheus registry (to add custom counters/histograms)
231
+ *
232
+ * @return {*} {client.Registry}
233
+ */
234
+ getMetricsRegistry(): client.Registry;
235
+ /**
236
+ * Get server configuration
237
+ *
238
+ * @return {*} {ServerConfig}
239
+ */
240
+ getConfig(): ServerConfig;
241
+ /**
242
+ * Wait until server initialization (middleware + routes) has completed.
243
+ * Useful for integration tests that inspect app before starting.
244
+ */
245
+ waitUntilReady(): Promise<void>;
246
+ private normalizePath;
247
+ private normalizeRouteForMetrics;
248
+ /**
249
+ * Destroy all active connections (gracefully if possible).
250
+ * If a connection does not close cleanly, it will be force-destroyed.
251
+ */
252
+ private destroyConnections;
253
+ private validateHttpsFiles;
254
+ private static isBuiltServerConfig;
255
+ }
256
+ //# sourceMappingURL=server.d.ts.map