@catbee/utils 0.0.6 → 0.0.8-next.0

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 (249) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +77 -1107
  3. package/build/index.cjs +6888 -0
  4. package/build/index.d.ts +5242 -0
  5. package/build/index.mjs +6615 -0
  6. package/package.json +26 -95
  7. package/build/esm/config.d.ts +0 -130
  8. package/build/esm/config.js +0 -145
  9. package/build/esm/config.js.map +0 -1
  10. package/build/esm/index.d.ts +0 -27
  11. package/build/esm/index.js +0 -50
  12. package/build/esm/index.js.map +0 -1
  13. package/build/esm/servers/server.builder.d.ts +0 -625
  14. package/build/esm/servers/server.builder.js +0 -722
  15. package/build/esm/servers/server.builder.js.map +0 -1
  16. package/build/esm/servers/server.d.ts +0 -256
  17. package/build/esm/servers/server.js +0 -1211
  18. package/build/esm/servers/server.js.map +0 -1
  19. package/build/esm/types/api-response.d.ts +0 -124
  20. package/build/esm/types/api-response.js +0 -25
  21. package/build/esm/types/api-response.js.map +0 -1
  22. package/build/esm/types/index.d.ts +0 -125
  23. package/build/esm/types/index.js +0 -25
  24. package/build/esm/types/index.js.map +0 -1
  25. package/build/esm/types/server.d.ts +0 -285
  26. package/build/esm/types/server.js +0 -25
  27. package/build/esm/types/server.js.map +0 -1
  28. package/build/esm/utils/array.utils.d.ts +0 -168
  29. package/build/esm/utils/array.utils.js +0 -382
  30. package/build/esm/utils/array.utils.js.map +0 -1
  31. package/build/esm/utils/async.utils.d.ts +0 -174
  32. package/build/esm/utils/async.utils.js +0 -652
  33. package/build/esm/utils/async.utils.js.map +0 -1
  34. package/build/esm/utils/cache.utils.d.ts +0 -153
  35. package/build/esm/utils/cache.utils.js +0 -499
  36. package/build/esm/utils/cache.utils.js.map +0 -1
  37. package/build/esm/utils/context-store.utils.d.ts +0 -186
  38. package/build/esm/utils/context-store.utils.js +0 -304
  39. package/build/esm/utils/context-store.utils.js.map +0 -1
  40. package/build/esm/utils/crypto.utils.d.ts +0 -160
  41. package/build/esm/utils/crypto.utils.js +0 -375
  42. package/build/esm/utils/crypto.utils.js.map +0 -1
  43. package/build/esm/utils/decorators.utils.d.ts +0 -315
  44. package/build/esm/utils/decorators.utils.js +0 -666
  45. package/build/esm/utils/decorators.utils.js.map +0 -1
  46. package/build/esm/utils/dir.utils.d.ts +0 -196
  47. package/build/esm/utils/dir.utils.js +0 -998
  48. package/build/esm/utils/dir.utils.js.map +0 -1
  49. package/build/esm/utils/env.utils.d.ts +0 -377
  50. package/build/esm/utils/env.utils.js +0 -873
  51. package/build/esm/utils/env.utils.js.map +0 -1
  52. package/build/esm/utils/exception.utils.d.ts +0 -230
  53. package/build/esm/utils/exception.utils.js +0 -559
  54. package/build/esm/utils/exception.utils.js.map +0 -1
  55. package/build/esm/utils/fs.utils.d.ts +0 -164
  56. package/build/esm/utils/fs.utils.js +0 -580
  57. package/build/esm/utils/fs.utils.js.map +0 -1
  58. package/build/esm/utils/http-status-codes.d.ts +0 -266
  59. package/build/esm/utils/http-status-codes.js +0 -295
  60. package/build/esm/utils/http-status-codes.js.map +0 -1
  61. package/build/esm/utils/id.utils.d.ts +0 -36
  62. package/build/esm/utils/id.utils.js +0 -87
  63. package/build/esm/utils/id.utils.js.map +0 -1
  64. package/build/esm/utils/logger.utils.d.ts +0 -166
  65. package/build/esm/utils/logger.utils.js +0 -347
  66. package/build/esm/utils/logger.utils.js.map +0 -1
  67. package/build/esm/utils/middleware.utils.d.ts +0 -83
  68. package/build/esm/utils/middleware.utils.js +0 -205
  69. package/build/esm/utils/middleware.utils.js.map +0 -1
  70. package/build/esm/utils/obj.utils.d.ts +0 -124
  71. package/build/esm/utils/obj.utils.js +0 -519
  72. package/build/esm/utils/obj.utils.js.map +0 -1
  73. package/build/esm/utils/request.utils.d.ts +0 -77
  74. package/build/esm/utils/request.utils.js +0 -196
  75. package/build/esm/utils/request.utils.js.map +0 -1
  76. package/build/esm/utils/response.utils.d.ts +0 -163
  77. package/build/esm/utils/response.utils.js +0 -284
  78. package/build/esm/utils/response.utils.js.map +0 -1
  79. package/build/esm/utils/string.utils.d.ts +0 -93
  80. package/build/esm/utils/string.utils.js +0 -169
  81. package/build/esm/utils/string.utils.js.map +0 -1
  82. package/build/esm/utils/url.utils.d.ts +0 -141
  83. package/build/esm/utils/url.utils.js +0 -381
  84. package/build/esm/utils/url.utils.js.map +0 -1
  85. package/build/esm/utils/validate.utils.d.ts +0 -177
  86. package/build/esm/utils/validate.utils.js +0 -336
  87. package/build/esm/utils/validate.utils.js.map +0 -1
  88. package/build/esnext/config.d.ts +0 -130
  89. package/build/esnext/config.js +0 -145
  90. package/build/esnext/config.js.map +0 -1
  91. package/build/esnext/index.d.ts +0 -27
  92. package/build/esnext/index.js +0 -50
  93. package/build/esnext/index.js.map +0 -1
  94. package/build/esnext/servers/server.builder.d.ts +0 -625
  95. package/build/esnext/servers/server.builder.js +0 -677
  96. package/build/esnext/servers/server.builder.js.map +0 -1
  97. package/build/esnext/servers/server.d.ts +0 -256
  98. package/build/esnext/servers/server.js +0 -918
  99. package/build/esnext/servers/server.js.map +0 -1
  100. package/build/esnext/types/api-response.d.ts +0 -124
  101. package/build/esnext/types/api-response.js +0 -25
  102. package/build/esnext/types/api-response.js.map +0 -1
  103. package/build/esnext/types/index.d.ts +0 -125
  104. package/build/esnext/types/index.js +0 -25
  105. package/build/esnext/types/index.js.map +0 -1
  106. package/build/esnext/types/server.d.ts +0 -285
  107. package/build/esnext/types/server.js +0 -25
  108. package/build/esnext/types/server.js.map +0 -1
  109. package/build/esnext/utils/array.utils.d.ts +0 -168
  110. package/build/esnext/utils/array.utils.js +0 -345
  111. package/build/esnext/utils/array.utils.js.map +0 -1
  112. package/build/esnext/utils/async.utils.d.ts +0 -174
  113. package/build/esnext/utils/async.utils.js +0 -430
  114. package/build/esnext/utils/async.utils.js.map +0 -1
  115. package/build/esnext/utils/cache.utils.d.ts +0 -153
  116. package/build/esnext/utils/cache.utils.js +0 -293
  117. package/build/esnext/utils/cache.utils.js.map +0 -1
  118. package/build/esnext/utils/context-store.utils.d.ts +0 -186
  119. package/build/esnext/utils/context-store.utils.js +0 -286
  120. package/build/esnext/utils/context-store.utils.js.map +0 -1
  121. package/build/esnext/utils/crypto.utils.d.ts +0 -160
  122. package/build/esnext/utils/crypto.utils.js +0 -276
  123. package/build/esnext/utils/crypto.utils.js.map +0 -1
  124. package/build/esnext/utils/decorators.utils.d.ts +0 -315
  125. package/build/esnext/utils/decorators.utils.js +0 -504
  126. package/build/esnext/utils/decorators.utils.js.map +0 -1
  127. package/build/esnext/utils/dir.utils.d.ts +0 -196
  128. package/build/esnext/utils/dir.utils.js +0 -477
  129. package/build/esnext/utils/dir.utils.js.map +0 -1
  130. package/build/esnext/utils/env.utils.d.ts +0 -377
  131. package/build/esnext/utils/env.utils.js +0 -785
  132. package/build/esnext/utils/env.utils.js.map +0 -1
  133. package/build/esnext/utils/exception.utils.d.ts +0 -230
  134. package/build/esnext/utils/exception.utils.js +0 -381
  135. package/build/esnext/utils/exception.utils.js.map +0 -1
  136. package/build/esnext/utils/fs.utils.d.ts +0 -164
  137. package/build/esnext/utils/fs.utils.js +0 -349
  138. package/build/esnext/utils/fs.utils.js.map +0 -1
  139. package/build/esnext/utils/http-status-codes.d.ts +0 -266
  140. package/build/esnext/utils/http-status-codes.js +0 -295
  141. package/build/esnext/utils/http-status-codes.js.map +0 -1
  142. package/build/esnext/utils/id.utils.d.ts +0 -36
  143. package/build/esnext/utils/id.utils.js +0 -84
  144. package/build/esnext/utils/id.utils.js.map +0 -1
  145. package/build/esnext/utils/logger.utils.d.ts +0 -166
  146. package/build/esnext/utils/logger.utils.js +0 -306
  147. package/build/esnext/utils/logger.utils.js.map +0 -1
  148. package/build/esnext/utils/middleware.utils.d.ts +0 -83
  149. package/build/esnext/utils/middleware.utils.js +0 -198
  150. package/build/esnext/utils/middleware.utils.js.map +0 -1
  151. package/build/esnext/utils/obj.utils.d.ts +0 -124
  152. package/build/esnext/utils/obj.utils.js +0 -413
  153. package/build/esnext/utils/obj.utils.js.map +0 -1
  154. package/build/esnext/utils/request.utils.d.ts +0 -77
  155. package/build/esnext/utils/request.utils.js +0 -168
  156. package/build/esnext/utils/request.utils.js.map +0 -1
  157. package/build/esnext/utils/response.utils.d.ts +0 -163
  158. package/build/esnext/utils/response.utils.js +0 -247
  159. package/build/esnext/utils/response.utils.js.map +0 -1
  160. package/build/esnext/utils/string.utils.d.ts +0 -93
  161. package/build/esnext/utils/string.utils.js +0 -165
  162. package/build/esnext/utils/string.utils.js.map +0 -1
  163. package/build/esnext/utils/url.utils.d.ts +0 -141
  164. package/build/esnext/utils/url.utils.js +0 -304
  165. package/build/esnext/utils/url.utils.js.map +0 -1
  166. package/build/esnext/utils/validate.utils.d.ts +0 -177
  167. package/build/esnext/utils/validate.utils.js +0 -320
  168. package/build/esnext/utils/validate.utils.js.map +0 -1
  169. package/build/src/config.d.ts +0 -130
  170. package/build/src/config.js +0 -150
  171. package/build/src/config.js.map +0 -1
  172. package/build/src/index.d.ts +0 -27
  173. package/build/src/index.js +0 -69
  174. package/build/src/index.js.map +0 -1
  175. package/build/src/servers/server.builder.d.ts +0 -625
  176. package/build/src/servers/server.builder.js +0 -681
  177. package/build/src/servers/server.builder.js.map +0 -1
  178. package/build/src/servers/server.d.ts +0 -256
  179. package/build/src/servers/server.js +0 -958
  180. package/build/src/servers/server.js.map +0 -1
  181. package/build/src/types/api-response.d.ts +0 -124
  182. package/build/src/types/api-response.js +0 -26
  183. package/build/src/types/api-response.js.map +0 -1
  184. package/build/src/types/index.d.ts +0 -125
  185. package/build/src/types/index.js +0 -26
  186. package/build/src/types/index.js.map +0 -1
  187. package/build/src/types/server.d.ts +0 -285
  188. package/build/src/types/server.js +0 -26
  189. package/build/src/types/server.js.map +0 -1
  190. package/build/src/utils/array.utils.d.ts +0 -168
  191. package/build/src/utils/array.utils.js +0 -364
  192. package/build/src/utils/array.utils.js.map +0 -1
  193. package/build/src/utils/async.utils.d.ts +0 -174
  194. package/build/src/utils/async.utils.js +0 -447
  195. package/build/src/utils/async.utils.js.map +0 -1
  196. package/build/src/utils/cache.utils.d.ts +0 -153
  197. package/build/src/utils/cache.utils.js +0 -297
  198. package/build/src/utils/cache.utils.js.map +0 -1
  199. package/build/src/utils/context-store.utils.d.ts +0 -186
  200. package/build/src/utils/context-store.utils.js +0 -293
  201. package/build/src/utils/context-store.utils.js.map +0 -1
  202. package/build/src/utils/crypto.utils.d.ts +0 -160
  203. package/build/src/utils/crypto.utils.js +0 -293
  204. package/build/src/utils/crypto.utils.js.map +0 -1
  205. package/build/src/utils/decorators.utils.d.ts +0 -315
  206. package/build/src/utils/decorators.utils.js +0 -516
  207. package/build/src/utils/decorators.utils.js.map +0 -1
  208. package/build/src/utils/dir.utils.d.ts +0 -196
  209. package/build/src/utils/dir.utils.js +0 -501
  210. package/build/src/utils/dir.utils.js.map +0 -1
  211. package/build/src/utils/env.utils.d.ts +0 -377
  212. package/build/src/utils/env.utils.js +0 -789
  213. package/build/src/utils/env.utils.js.map +0 -1
  214. package/build/src/utils/exception.utils.d.ts +0 -230
  215. package/build/src/utils/exception.utils.js +0 -407
  216. package/build/src/utils/exception.utils.js.map +0 -1
  217. package/build/src/utils/fs.utils.d.ts +0 -164
  218. package/build/src/utils/fs.utils.js +0 -372
  219. package/build/src/utils/fs.utils.js.map +0 -1
  220. package/build/src/utils/http-status-codes.d.ts +0 -266
  221. package/build/src/utils/http-status-codes.js +0 -298
  222. package/build/src/utils/http-status-codes.js.map +0 -1
  223. package/build/src/utils/id.utils.d.ts +0 -36
  224. package/build/src/utils/id.utils.js +0 -91
  225. package/build/src/utils/id.utils.js.map +0 -1
  226. package/build/src/utils/logger.utils.d.ts +0 -166
  227. package/build/src/utils/logger.utils.js +0 -352
  228. package/build/src/utils/logger.utils.js.map +0 -1
  229. package/build/src/utils/middleware.utils.d.ts +0 -83
  230. package/build/src/utils/middleware.utils.js +0 -205
  231. package/build/src/utils/middleware.utils.js.map +0 -1
  232. package/build/src/utils/obj.utils.d.ts +0 -124
  233. package/build/src/utils/obj.utils.js +0 -429
  234. package/build/src/utils/obj.utils.js.map +0 -1
  235. package/build/src/utils/request.utils.d.ts +0 -77
  236. package/build/src/utils/request.utils.js +0 -175
  237. package/build/src/utils/request.utils.js.map +0 -1
  238. package/build/src/utils/response.utils.d.ts +0 -163
  239. package/build/src/utils/response.utils.js +0 -260
  240. package/build/src/utils/response.utils.js.map +0 -1
  241. package/build/src/utils/string.utils.d.ts +0 -93
  242. package/build/src/utils/string.utils.js +0 -179
  243. package/build/src/utils/string.utils.js.map +0 -1
  244. package/build/src/utils/url.utils.d.ts +0 -141
  245. package/build/src/utils/url.utils.js +0 -317
  246. package/build/src/utils/url.utils.js.map +0 -1
  247. package/build/src/utils/validate.utils.d.ts +0 -177
  248. package/build/src/utils/validate.utils.js +0 -345
  249. package/build/src/utils/validate.utils.js.map +0 -1
@@ -1,681 +0,0 @@
1
- "use strict";
2
- /*
3
- * The MIT License
4
- *
5
- * Copyright (c) 2025 Catbee Technologies
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ServerConfigBuilder = exports.BUILD_MARKER = void 0;
27
- const obj_utils_1 = require("../utils/obj.utils");
28
- const config_1 = require("../config");
29
- const validate_utils_1 = require("../utils/validate.utils");
30
- /**
31
- * Builder class for creating and configuring an Express server configuration.
32
- *
33
- * This class provides a fluent interface to configure all aspects of the Express server
34
- * including security settings, middleware, routing, and more.
35
- *
36
- * @example
37
- * ```typescript
38
- * const serverConfig = new ServerConfigBuilder()
39
- * .withPort(3000)
40
- * .withHost('localhost')
41
- * .enableCors()
42
- * .enableHelmet()
43
- * .build();
44
- * ```
45
- */
46
- exports.BUILD_MARKER = Symbol.for('catbee.express.server.build');
47
- class ServerConfigBuilder {
48
- constructor() {
49
- this.config = {};
50
- }
51
- /**
52
- * Validates that a port number is valid and usable.
53
- *
54
- * @private
55
- * @param port - The port number to validate
56
- * @throws {Error} If port is not an integer or is outside the valid range (1-65535)
57
- */
58
- validatePort(port) {
59
- if (!(0, validate_utils_1.isPort)(port)) {
60
- throw new Error(`Port must be a valid number between 1 and 65535, got: ${port}`);
61
- }
62
- }
63
- /**
64
- * Sets the port the server will listen on.
65
- *
66
- * @param port - The port number (1-65535)
67
- * @returns The builder instance for chaining
68
- * @throws {Error} If port is invalid
69
- * @default 3000 (can be overridden via PORT env variable)
70
- *
71
- * @example
72
- * ```typescript
73
- * builder.withPort(3000)
74
- * ```
75
- */
76
- withPort(port) {
77
- this.validatePort(port);
78
- this.config.port = port;
79
- return this;
80
- }
81
- /**
82
- * Sets the hostname the server will bind to.
83
- *
84
- * @param host - The hostname (e.g., 'localhost', '0.0.0.0', '127.0.0.1')
85
- * @returns The builder instance for chaining
86
- * @default '0.0.0.0' (can be overridden via HOST env variable)
87
- *
88
- * @example
89
- * ```typescript
90
- * builder.withHost('0.0.0.0') // Listen on all interfaces
91
- * ```
92
- */
93
- withHost(host) {
94
- this.config.host = host;
95
- return this;
96
- }
97
- /**
98
- * Configures Cross-Origin Resource Sharing (CORS) for the server.
99
- *
100
- * @param opts - CORS options object or boolean (true to enable with defaults, false to disable)
101
- * @returns The builder instance for chaining
102
- * @default false (CORS is disabled by default)
103
- *
104
- * @example
105
- * ```typescript
106
- * // Enable CORS with default options
107
- * builder.withCors(true)
108
- *
109
- * // Configure CORS with specific options
110
- * builder.withCors({
111
- * origin: ['https://example.com'],
112
- * methods: ['GET', 'POST']
113
- * })
114
- * ```
115
- */
116
- withCors(opts) {
117
- this.config.cors = opts;
118
- return this;
119
- }
120
- /**
121
- * Enables CORS with default settings
122
- *
123
- * @returns The builder instance for chaining
124
- */
125
- enableCors() {
126
- return this.withCors(true);
127
- }
128
- /**
129
- * Disables CORS
130
- *
131
- * @returns The builder instance for chaining
132
- */
133
- disableCors() {
134
- return this.withCors(false);
135
- }
136
- /**
137
- * Configures the Helmet middleware for setting HTTP security headers.
138
- *
139
- * @param opts - Helmet options object or boolean (true to enable with defaults, false to disable)
140
- * @returns The builder instance for chaining
141
- * @default false (Helmet is disabled by default)
142
- *
143
- * @example
144
- * ```typescript
145
- * // Enable Helmet with default settings
146
- * builder.withHelmet(true)
147
- *
148
- * // Configure Helmet with specific options
149
- * builder.withHelmet({
150
- * contentSecurityPolicy: false,
151
- * xssFilter: true
152
- * })
153
- * ```
154
- */
155
- withHelmet(opts) {
156
- this.config.helmet = opts;
157
- return this;
158
- }
159
- /**
160
- * Enables Helmet with default settings
161
- *
162
- * @returns The builder instance for chaining
163
- */
164
- enableHelmet() {
165
- return this.withHelmet(true);
166
- }
167
- /**
168
- * Disables Helmet
169
- *
170
- * @returns The builder instance for chaining
171
- */
172
- disableHelmet() {
173
- return this.withHelmet(false);
174
- }
175
- /**
176
- * Configures response compression middleware.
177
- *
178
- * @param opts - Compression options object or boolean (true to enable with defaults, false to disable)
179
- * @returns The builder instance for chaining
180
- * @default false (Compression is disabled by default)
181
- *
182
- * @example
183
- * ```typescript
184
- * // Enable compression with default settings
185
- * builder.withCompression(true)
186
- *
187
- * // Configure compression with specific options
188
- * builder.withCompression({
189
- * level: 6,
190
- * threshold: 1024
191
- * })
192
- * ```
193
- */
194
- withCompression(opts) {
195
- this.config.compression = opts;
196
- return this;
197
- }
198
- /**
199
- * Enables compression with default settings
200
- *
201
- * @returns The builder instance for chaining
202
- */
203
- enableCompression() {
204
- return this.withCompression(true);
205
- }
206
- /**
207
- * Disables compression
208
- *
209
- * @returns The builder instance for chaining
210
- */
211
- disableCompression() {
212
- return this.withCompression(false);
213
- }
214
- /**
215
- * Configures rate limiting to protect against brute-force attacks.
216
- *
217
- * @param opts - Rate limit configuration options
218
- * @returns The builder instance for chaining
219
- * @default { enable: false, windowMs: 15 * 60 * 1000, max: 100, message: 'Too many requests', standardHeaders: true, legacyHeaders: false }
220
- *
221
- * @example
222
- * ```typescript
223
- * builder.withRateLimit({
224
- * enable: true,
225
- * windowMs: 15 * 60 * 1000, // 15 minutes
226
- * max: 100 // limit each IP to 100 requests per windowMs
227
- * })
228
- * ```
229
- */
230
- withRateLimit(opts) {
231
- this.mergeConfig('rateLimit', opts);
232
- return this;
233
- }
234
- /**
235
- * Enables rate limiting with default or custom settings
236
- *
237
- * @param opts - Optional rate limit configuration (max requests, window, etc.)
238
- * @returns The builder instance for chaining
239
- */
240
- enableRateLimit(opts = {}) {
241
- return this.setEnabled('rateLimit', true, opts);
242
- }
243
- /**
244
- * Disables rate limiting
245
- *
246
- * @returns The builder instance for chaining
247
- */
248
- disableRateLimit() {
249
- return this.setEnabled('rateLimit', false);
250
- }
251
- /**
252
- * Configures HTTP request logging middleware.
253
- *
254
- * @param opts - Request logging configuration options
255
- * @returns The builder instance for chaining
256
- * @default { enable: true in dev/false in prod, ignorePaths: ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'], skipNotFoundRoutes: false }
257
- *
258
- * @example
259
- * ```typescript
260
- * builder.withRequestLogging({
261
- * enable: true,
262
- * ignorePaths: ['/health', '/metrics'],
263
- * skipNotFoundRoutes: true
264
- * })
265
- * ```
266
- */
267
- withRequestLogging(opts) {
268
- this.mergeConfig('requestLogging', opts);
269
- return this;
270
- }
271
- /**
272
- * Enables request logging with default or custom settings
273
- *
274
- * @param opts - Optional request logging configuration
275
- * @returns The builder instance for chaining
276
- */
277
- enableRequestLogging(opts = {}) {
278
- return this.setEnabled('requestLogging', true, opts);
279
- }
280
- /**
281
- * Disables request logging
282
- *
283
- * @returns The builder instance for chaining
284
- */
285
- disableRequestLogging() {
286
- return this.setEnabled('requestLogging', false);
287
- }
288
- /**
289
- * Configures server metrics collection and endpoints.
290
- *
291
- * @param opts - Metrics configuration options
292
- * @returns The builder instance for chaining
293
- * @default { enable: false, path: '/metrics', withGlobalPrefix: false }
294
- *
295
- * @example
296
- * ```typescript
297
- * builder.withMetrics({
298
- * enable: true,
299
- * path: '/metrics'
300
- * })
301
- * ```
302
- */
303
- withMetrics(opts) {
304
- this.mergeConfig('metrics', opts);
305
- return this;
306
- }
307
- /**
308
- * Enables Prometheus metrics collection and endpoint
309
- *
310
- * @param opts - Optional metrics configuration
311
- * @returns The builder instance for chaining
312
- */
313
- enableMetrics(opts = {}) {
314
- return this.setEnabled('metrics', true, opts);
315
- }
316
- /**
317
- * Disables Prometheus metrics
318
- *
319
- * @returns The builder instance for chaining
320
- */
321
- disableMetrics() {
322
- return this.setEnabled('metrics', false);
323
- }
324
- /**
325
- * Configures server health check endpoint.
326
- *
327
- * @param opts - Health check configuration options
328
- * @returns The builder instance for chaining
329
- * @default { path: '/healthz', detailed: true, withGlobalPrefix: false }
330
- *
331
- * @example
332
- * ```typescript
333
- * builder.withHealthCheck({
334
- * path: '/health',
335
- * detailed: true
336
- * })
337
- * ```
338
- */
339
- withHealthCheck(opts) {
340
- this.mergeConfig('healthCheck', opts);
341
- return this;
342
- }
343
- /**
344
- * Configures OpenAPI/Swagger documentation for the API.
345
- *
346
- * @param opts - OpenAPI configuration options
347
- * @returns The builder instance for chaining
348
- * @default { enable: false, mountPath: '/docs', verbose: false, withGlobalPrefix: false }
349
- *
350
- * @example
351
- * ```typescript
352
- * builder.withOpenApi({
353
- * enable: true,
354
- * path: '/api-docs',
355
- * filePath: './openapi.yaml'
356
- * })
357
- * ```
358
- */
359
- withOpenApi(opts) {
360
- this.mergeConfig('openApi', opts);
361
- return this;
362
- }
363
- /**
364
- * Enables OpenAPI documentation with required file path
365
- *
366
- * @param filePath - Path to OpenAPI specification file (required)
367
- * @param opts - Optional OpenAPI configuration
368
- * @returns The builder instance for chaining
369
- */
370
- enableOpenApi(filePath, opts = {}) {
371
- this.setEnabled('openApi', true, Object.assign({ filePath }, opts));
372
- return this;
373
- }
374
- /**
375
- * Disables OpenAPI documentation
376
- *
377
- * @returns The builder instance for chaining
378
- */
379
- disableOpenApi() {
380
- return this.setEnabled('openApi', false);
381
- }
382
- /**
383
- * Configures the server as a microservice with versioning.
384
- *
385
- * @param opts - Microservice configuration options including app name and service version
386
- * @returns The builder instance for chaining
387
- * @default { isMicroservice: false, appName: 'express_app' }
388
- *
389
- * @example
390
- * ```typescript
391
- * builder.withMicroService({
392
- * appName: 'user-service',
393
- * serviceVersion: {
394
- * enable: true,
395
- * version: '1.2.3'
396
- * }
397
- * })
398
- * ```
399
- */
400
- withMicroService(opts) {
401
- this.config.isMicroservice = true;
402
- this.config.appName = opts.appName;
403
- this.mergeConfig('serviceVersion', opts.serviceVersion);
404
- return this;
405
- }
406
- /**
407
- * Configures the trust proxy settings to determine if X-Forwarded-* headers should be trusted.
408
- *
409
- * @param opts - Trust proxy configuration options
410
- * @returns The builder instance for chaining
411
- * @default false
412
- *
413
- * @example
414
- * ```typescript
415
- * // Trust proxy headers (useful when behind a load balancer)
416
- * builder.withTrustProxy(true)
417
- * ```
418
- */
419
- withTrustProxy(opts) {
420
- this.config.trustProxy = opts;
421
- return this;
422
- }
423
- /**
424
- * Configures the request ID middleware for tracing requests across services.
425
- *
426
- * @param opts - Request ID configuration options
427
- * @returns The builder instance for chaining
428
- * @default { headerName: 'x-request-id', exposeHeader: true }
429
- *
430
- * @example
431
- * ```typescript
432
- * builder.withRequestId({
433
- * headerName: 'X-Request-Id',
434
- * generator: () => crypto.randomUUID()
435
- * })
436
- * ```
437
- */
438
- withRequestId(opts) {
439
- this.mergeConfig('requestId', opts);
440
- return this;
441
- }
442
- /**
443
- * Configures the response time middleware for measuring request processing times.
444
- *
445
- * @param opts - Response time configuration options
446
- * @returns The builder instance for chaining
447
- * @default { enable: false, addHeader: true, logOnComplete: false }
448
- *
449
- * @example
450
- * ```typescript
451
- * builder.withResponseTime({
452
- * enable: true,
453
- * addHeader: true,
454
- * logOnComplete: true
455
- * })
456
- * ```
457
- */
458
- withResponseTime(opts) {
459
- this.mergeConfig('responseTime', opts);
460
- return this;
461
- }
462
- /**
463
- * Enables response time tracking with default or custom settings
464
- *
465
- * @param opts - Optional response time configuration
466
- * @returns The builder instance for chaining
467
- */
468
- enableResponseTime(opts = {}) {
469
- this.setEnabled('responseTime', true, opts);
470
- return this;
471
- }
472
- /**
473
- * Disables response time tracking
474
- *
475
- * @returns The builder instance for chaining
476
- */
477
- disableResponseTime() {
478
- return this.setEnabled('responseTime', false);
479
- }
480
- /**
481
- * Configures the body parser middleware options for parsing request bodies.
482
- *
483
- * @param opts - Body parser configuration options
484
- * @returns The builder instance for chaining
485
- * @default { json: { limit: '1mb' }, urlencoded: { extended: true, limit: '1mb' } }
486
- *
487
- * @example
488
- * ```typescript
489
- * builder.withBodyParser({
490
- * json: {
491
- * limit: '1mb'
492
- * },
493
- * urlencoded: {
494
- * extended: true,
495
- * limit: '1mb'
496
- * }
497
- * })
498
- * ```
499
- */
500
- withBodyParser(opts) {
501
- var _a;
502
- this.config.bodyParser = (0, obj_utils_1.deepObjMerge)({}, (_a = this.config.bodyParser) !== null && _a !== void 0 ? _a : {}, opts);
503
- return this;
504
- }
505
- /**
506
- * Configures cookie parsing middleware.
507
- *
508
- * @param opts - Cookie parser options or boolean (true to enable with defaults, false to disable)
509
- * @returns The builder instance for chaining
510
- * @default false
511
- *
512
- * @example
513
- * ```typescript
514
- * // Enable cookie parsing with default options
515
- * builder.withCookies(true)
516
- *
517
- * // Enable cookie parsing with specific options
518
- * builder.withCookies({
519
- * secret: 'your-secret-key',
520
- * secure: true
521
- * })
522
- * ```
523
- */
524
- withCookies(opts) {
525
- this.config.cookieParser = opts;
526
- return this;
527
- }
528
- /**
529
- * Configures the logger used by the server.
530
- *
531
- * @param opts - Logger configuration options
532
- * @returns The builder instance for chaining
533
- * @default { name: 'express_app', level: 'info', prettyPrint: true in dev, singleLine: false }
534
- *
535
- * @example
536
- * ```typescript
537
- * builder.withLogger({
538
- * level: 'info',
539
- * prettyPrint: true,
540
- * singleLine: false
541
- * })
542
- * ```
543
- */
544
- withLogger(opts) {
545
- this.mergeConfig('logger', opts);
546
- return this;
547
- }
548
- /**
549
- * Adds a static folder to serve files from.
550
- *
551
- * @param folder - Static folder configuration
552
- * @returns The builder instance for chaining
553
- *
554
- * @example
555
- * ```typescript
556
- * builder.withStaticFolder({
557
- * path: '/assets',
558
- * directory: './public',
559
- * options: { maxAge: '1d' }
560
- * })
561
- * ```
562
- */
563
- withStaticFolder(folder) {
564
- var _a;
565
- if (!folder.path)
566
- throw new Error('Static folder requires a path');
567
- const folders = [...((_a = this.config.staticFolders) !== null && _a !== void 0 ? _a : []), folder];
568
- this.config.staticFolders = Array.from(new Map(folders.map(f => [f.path, f])).values());
569
- return this;
570
- }
571
- /**
572
- * Sets global headers to be included in all responses.
573
- *
574
- * @param headers - Object containing header name/value pairs or functions that return values
575
- * @returns The builder instance for chaining
576
- * @default {}
577
- *
578
- * @example
579
- * ```typescript
580
- * builder.withGlobalHeaders({
581
- * 'X-Powered-By': 'Catbee',
582
- * 'Server-Time': () => new Date().toISOString()
583
- * })
584
- * ```
585
- */
586
- withGlobalHeaders(headers) {
587
- this.mergeConfig('globalHeaders', headers);
588
- return this;
589
- }
590
- /**
591
- * Sets a global prefix for all routes.
592
- *
593
- * @param prefix - The prefix to prepend to all routes (e.g., '/api/v1')
594
- * @returns The builder instance for chaining
595
- * @default '/'
596
- *
597
- * @example
598
- * ```typescript
599
- * builder.withGlobalPrefix('/api/v1')
600
- * ```
601
- */
602
- withGlobalPrefix(prefix) {
603
- this.config.globalPrefix = prefix;
604
- return this;
605
- }
606
- /**
607
- * Applies custom configuration overrides directly.
608
- *
609
- * @param overrides - Custom configuration options to merge
610
- * @returns The builder instance for chaining
611
- *
612
- * @example
613
- * ```typescript
614
- * builder.withCustom({
615
- * port: 8080,
616
- * customMiddleware: myMiddlewareFunction
617
- * })
618
- * ```
619
- */
620
- withCustom(overrides) {
621
- this.config = (0, obj_utils_1.deepObjMerge)({}, this.config, overrides);
622
- return this;
623
- }
624
- /**
625
- * Configures HTTPS server options.
626
- *
627
- * @param opts - HTTPS configuration (key, cert, ca, passphrase, etc.)
628
- * @returns The builder instance for chaining
629
- *
630
- * @example
631
- * ```typescript
632
- * builder.withHttps({
633
- * key: './localhost-key.pem',
634
- * cert: './localhost-cert.pem'
635
- * })
636
- * ```
637
- */
638
- withHttps(opts) {
639
- this.config.https = opts;
640
- return this;
641
- }
642
- /**
643
- * Builds and returns the final server configuration.
644
- *
645
- * This method merges the user-specified configuration with default values,
646
- * ensures all sections with 'enable' flags are properly structured, and
647
- * produces the final configuration to be used by the server.
648
- *
649
- * @returns The complete ServerConfig object
650
- *
651
- * @example
652
- * ```typescript
653
- * const config = new ServerConfigBuilder()
654
- * .withPort(3000)
655
- * .withHost('localhost')
656
- * .withCors(true)
657
- * .build();
658
- * ```
659
- */
660
- build() {
661
- var _a;
662
- const config = (0, obj_utils_1.deepObjMerge)({}, config_1.defaultServerConfig, this.config);
663
- // Common validation
664
- if (((_a = config.openApi) === null || _a === void 0 ? void 0 : _a.enable) && !config.openApi.filePath) {
665
- throw new Error('OpenAPI is enabled but no filePath is specified');
666
- }
667
- return Object.freeze(Object.assign(Object.assign({}, config), { [exports.BUILD_MARKER]: true }));
668
- }
669
- mergeConfig(key, value) {
670
- const current = typeof this.config[key] === 'object' && this.config[key] !== null
671
- ? this.config[key]
672
- : {};
673
- this.config[key] = (0, obj_utils_1.deepObjMerge)({}, current, value);
674
- }
675
- setEnabled(key, enable, overrides = {}) {
676
- this.mergeConfig(key, Object.assign(Object.assign({}, overrides), { enable }));
677
- return this;
678
- }
679
- }
680
- exports.ServerConfigBuilder = ServerConfigBuilder;
681
- //# sourceMappingURL=server.builder.js.map