@catbee/utils 2.0.0-next.0 → 2.0.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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +102 -52
  3. package/array/index.cjs +215 -74
  4. package/array/index.d.ts +345 -2
  5. package/array/index.mjs +201 -74
  6. package/async/index.cjs +116 -39
  7. package/async/index.d.ts +292 -2
  8. package/async/index.mjs +116 -40
  9. package/cache/index.cjs +2 -2
  10. package/cache/index.d.ts +156 -2
  11. package/cache/index.mjs +3 -3
  12. package/config/index.cjs +80 -66
  13. package/config/index.d.ts +65 -3
  14. package/config/index.mjs +77 -65
  15. package/context-store/index.cjs +2 -3
  16. package/context-store/index.d.ts +193 -2
  17. package/context-store/index.mjs +2 -3
  18. package/crypto/index.cjs +55 -5
  19. package/crypto/index.d.ts +225 -2
  20. package/crypto/index.mjs +52 -7
  21. package/date/index.cjs +676 -2
  22. package/date/index.d.ts +676 -2
  23. package/date/index.mjs +665 -3
  24. package/decorator/index.cjs +2172 -0
  25. package/{decorators/decorators.utils.d.ts → decorator/index.d.ts} +58 -54
  26. package/decorator/index.mjs +2131 -0
  27. package/{dir → directory}/index.cjs +5 -4
  28. package/{dir/dir.utils.d.ts → directory/index.d.ts} +24 -21
  29. package/{dir → directory}/index.mjs +5 -4
  30. package/env/index.cjs +100 -68
  31. package/env/index.d.ts +391 -2
  32. package/env/index.mjs +100 -68
  33. package/exception/index.cjs +1 -1
  34. package/exception/index.d.ts +233 -2
  35. package/exception/index.mjs +1 -1
  36. package/fs/index.cjs +71 -37
  37. package/fs/index.d.ts +206 -2
  38. package/fs/index.mjs +65 -35
  39. package/http-status-codes/index.cjs +1 -1
  40. package/http-status-codes/index.d.ts +268 -2
  41. package/http-status-codes/index.mjs +1 -1
  42. package/id/index.cjs +1 -1
  43. package/id/index.d.ts +38 -2
  44. package/id/index.mjs +1 -1
  45. package/index.cjs +13 -13
  46. package/index.d.ts +5 -5
  47. package/index.mjs +5 -5
  48. package/logger/index.cjs +13 -15
  49. package/logger/index.d.ts +190 -2
  50. package/logger/index.mjs +14 -16
  51. package/middleware/index.cjs +1 -1
  52. package/middleware/index.d.ts +104 -2
  53. package/middleware/index.mjs +1 -1
  54. package/object/index.cjs +379 -0
  55. package/{obj/obj.utils.d.ts → object/index.d.ts} +73 -33
  56. package/object/index.mjs +360 -0
  57. package/package.json +41 -23
  58. package/performance/index.cjs +4 -4
  59. package/performance/index.d.ts +139 -2
  60. package/performance/index.mjs +4 -4
  61. package/request/index.cjs +37 -25
  62. package/request/index.d.ts +242 -3
  63. package/request/index.mjs +37 -25
  64. package/response/index.cjs +1 -1
  65. package/response/index.d.ts +319 -3
  66. package/response/index.mjs +1 -1
  67. package/server/index.cjs +249 -146
  68. package/server/index.d.ts +866 -5
  69. package/server/index.mjs +248 -144
  70. package/stream/index.cjs +1 -1
  71. package/stream/index.d.ts +91 -2
  72. package/stream/index.mjs +1 -1
  73. package/string/index.cjs +34 -1
  74. package/string/index.d.ts +146 -2
  75. package/string/index.mjs +31 -2
  76. package/type/index.cjs +19 -2
  77. package/type/index.d.ts +144 -2
  78. package/type/index.mjs +17 -3
  79. package/types/index.cjs +1 -1
  80. package/types/index.d.ts +775 -5
  81. package/types/index.mjs +1 -1
  82. package/url/index.cjs +63 -5
  83. package/url/index.d.ts +200 -2
  84. package/url/index.mjs +59 -6
  85. package/{validate → validation}/index.cjs +91 -44
  86. package/{validate/validate.utils.d.ts → validation/index.d.ts} +33 -24
  87. package/{validate → validation}/index.mjs +87 -44
  88. package/array/array.utils.d.ts +0 -191
  89. package/async/async.utils.d.ts +0 -296
  90. package/cache/cache.utils.d.ts +0 -176
  91. package/config/config.d.ts +0 -57
  92. package/context-store/context-store.utils.d.ts +0 -212
  93. package/crypto/crypto.utils.d.ts +0 -183
  94. package/date/date.utils.d.ts +0 -190
  95. package/decorators/index.cjs +0 -913
  96. package/decorators/index.d.ts +0 -25
  97. package/decorators/index.mjs +0 -872
  98. package/dir/index.d.ts +0 -25
  99. package/env/env.utils.d.ts +0 -400
  100. package/exception/exception.utils.d.ts +0 -253
  101. package/fs/fs.utils.d.ts +0 -196
  102. package/http-status-codes/http-status-codes.d.ts +0 -289
  103. package/id/id.utils.d.ts +0 -59
  104. package/logger/logger.utils.d.ts +0 -210
  105. package/middleware/middleware.utils.d.ts +0 -123
  106. package/obj/index.cjs +0 -317
  107. package/obj/index.d.ts +0 -25
  108. package/obj/index.mjs +0 -301
  109. package/performance/performance.utils.d.ts +0 -159
  110. package/request/request.utils.d.ts +0 -109
  111. package/response/response.utils.d.ts +0 -186
  112. package/server/server.builder.d.ts +0 -531
  113. package/server/server.d.ts +0 -303
  114. package/stream/stream.utils.d.ts +0 -111
  115. package/string/string.utils.d.ts +0 -124
  116. package/type/type.utils.d.ts +0 -129
  117. package/types/api-response.d.ts +0 -175
  118. package/types/common.d.ts +0 -148
  119. package/types/config.d.ts +0 -88
  120. package/types/server.d.ts +0 -291
  121. package/url/url.utils.d.ts +0 -164
  122. package/validate/index.d.ts +0 -25
package/server/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -22,7 +22,868 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export { ExpressServer } from './server';
26
- export { ServerConfigBuilder } from './server.builder';
27
- export { DependencyErrors } from './server';
28
- export * from '../types/server';
25
+ import * as prom_client from 'prom-client';
26
+ import express, { Express, Router } from 'express';
27
+ import http from 'node:http';
28
+ import https from 'node:https';
29
+ import { CatbeeServerConfig, CatbeeServerHooks } from '@catbee/utils/types';
30
+
31
+ /**
32
+ * Map of critical dependencies to their error messages.
33
+ */
34
+ declare const DependencyErrors: {
35
+ express: string;
36
+ helmet: string;
37
+ cors: string;
38
+ compression: string;
39
+ 'express-rate-limit': string;
40
+ 'cookie-parser': string;
41
+ '@scalar/express-api-reference': string;
42
+ 'prom-client': string;
43
+ };
44
+ /**
45
+ * Production-ready Express server with enterprise features.
46
+ *
47
+ * Core Features:
48
+ * - Security: Helmet, CORS, rate limiting, timeouts
49
+ * - Monitoring: Request logs, metrics, health checks
50
+ * - Performance: Compression, caching, static files
51
+ * - Reliability: Graceful shutdown, error handling
52
+ * - Developer UX: OpenAPI docs, debugging tools
53
+ * - Extensibility: Hooks, middleware, custom routes
54
+ *
55
+ * Designed for microservices and production workloads.
56
+ * Includes K8s readiness probes and zero-downtime support.
57
+ */
58
+ declare class ExpressServer {
59
+ /** Prometheus client registry for metrics collection */
60
+ private readonly register;
61
+ /** HTTP server instance (null when not running) */
62
+ protected server: http.Server | https.Server | null;
63
+ /** Merged configuration with defaults applied */
64
+ protected config: CatbeeServerConfig;
65
+ /** User-defined lifecycle hooks */
66
+ protected hooks: CatbeeServerHooks;
67
+ /** Global API prefix (from config) */
68
+ protected globalPrefix: string;
69
+ /** Internal fallback router */
70
+ private readonly rootRouter;
71
+ /** User-supplied router */
72
+ private externalRouter?;
73
+ /** Internal Express app instance */
74
+ private readonly app;
75
+ /** Set of active WebSocket connections */
76
+ private readonly connections;
77
+ /** Flag indicating if the server is shutting down */
78
+ private isShuttingDown;
79
+ /**
80
+ * Collection of registered health check functions.
81
+ * These are executed when the health check endpoint is accessed.
82
+ */
83
+ private readonly healthChecks;
84
+ /** Prometheus metrics for monitoring */
85
+ private readonly requestCounter?;
86
+ private readonly routeTimings?;
87
+ private readonly requestSizes?;
88
+ private readonly clientIPs?;
89
+ /** Promise that resolves when initialization (middleware + routes) is complete */
90
+ private readonly initPromise;
91
+ /**
92
+ * Initializes server with intelligent defaults and security best practices.
93
+ * All settings can be customized via config and hooks.
94
+ *
95
+ * Default Security:
96
+ * - Secure headers (Helmet)
97
+ * - Rate limiting
98
+ * - Request timeouts
99
+ * - Body size limits
100
+ * - CORS protection
101
+ *
102
+ * Default Monitoring:
103
+ * - Request/Response logging
104
+ * - Prometheus metrics
105
+ * - Health checks
106
+ * - Request tracing
107
+ */
108
+ constructor(config: Partial<CatbeeServerConfig>, hooks?: CatbeeServerHooks);
109
+ /**
110
+ * Execute a lifecycle hook safely with comprehensive error handling.
111
+ * Prevents hook failures from crashing the server while logging issues.
112
+ *
113
+ * @param hook Name of the lifecycle hook to execute
114
+ * @param args Arguments to pass to the hook function
115
+ */
116
+ private runHook;
117
+ /**
118
+ * Initialize the Express server with middleware and routes.
119
+ */
120
+ private initialize;
121
+ /**
122
+ * Configure and register all middlewares in the optimal order.
123
+ *
124
+ * Middleware Order (CRITICAL - don't change without understanding implications):
125
+ * 1. Basic server configuration (trust proxy, x-powered-by)
126
+ * 2. Request ID generation (for tracing)
127
+ * 3. Request context setup (for logging correlation)
128
+ * 4. Timeout protection (prevents hanging requests)
129
+ * 5. Response time tracking (for performance monitoring)
130
+ * 6. Request logging (after ID/context setup)
131
+ * 7. Custom request hooks
132
+ * 8. Security middleware (rate limiting, CORS, Helmet)
133
+ * 9. Response compression
134
+ * 10. Static file serving
135
+ * 11. Request parsing (body parsing, cookies)
136
+ * 12. API documentation (OpenAPI)
137
+ * 13. Global headers
138
+ * 14. Custom response hooks
139
+ */
140
+ protected setupMiddleware(): Promise<void>;
141
+ /**
142
+ * Set up basic middleware (trust proxy, request ID, context).
143
+ */
144
+ private setupBasicMiddleware;
145
+ /**
146
+ * Set up security middleware (Helmet, CORS).
147
+ */
148
+ private setupSecurityMiddleware;
149
+ /**
150
+ * Set up global headers middleware.
151
+ */
152
+ private setupGlobalHeaders;
153
+ /**
154
+ * Set up request timeout middleware.
155
+ */
156
+ private setupTimeoutMiddleware;
157
+ /**
158
+ * Set up response time tracking middleware.
159
+ */
160
+ private setupResponseTimeMiddleware;
161
+ /**
162
+ * Set up rate limiting middleware.
163
+ */
164
+ private setupRateLimitingMiddleware;
165
+ /**
166
+ * Set up request logging middleware.
167
+ */
168
+ private setupRequestLoggingMiddleware;
169
+ /**
170
+ * Set up response compression middleware.
171
+ */
172
+ private setupCompressionMiddleware;
173
+ /**
174
+ * Set up static file serving middleware.
175
+ */
176
+ private setupStaticFilesMiddleware;
177
+ /**
178
+ * Set up body parsing middleware.
179
+ */
180
+ private setupBodyParsingMiddleware;
181
+ /**
182
+ * Set up cookie parsing middleware.
183
+ */
184
+ private setupCookieParsingMiddleware;
185
+ /**
186
+ * Set up OpenAPI documentation middleware.
187
+ */
188
+ private setupOpenApiMiddleware;
189
+ /**
190
+ * Set up metrics tracking middleware.
191
+ */
192
+ private setupMetricsMiddleware;
193
+ /**
194
+ * Configure server routes and error handling.
195
+ * Sets up in following order:
196
+ *
197
+ * 1. Built-in routes (health, metrics)
198
+ * 2. Application routes
199
+ * 3. 404 handler
200
+ * 4. Error handler
201
+ */
202
+ protected setupRoutes(): Promise<void>;
203
+ /**
204
+ * Execute health check and return response.
205
+ */
206
+ private handleHealthCheckRequest;
207
+ /**
208
+ * Execute all registered health checks and return results.
209
+ */
210
+ private executeHealthChecks;
211
+ /**
212
+ * Register a new health check function for monitoring service dependencies.
213
+ *
214
+ * Health checks are executed when the health endpoint is accessed and
215
+ * help determine if the service is ready to handle requests.
216
+ *
217
+ * Examples:
218
+ * - Database connectivity
219
+ * - External service availability
220
+ * - File system access
221
+ * - Memory/CPU usage checks
222
+ *
223
+ * @param name Unique identifier for the check (used in detailed responses)
224
+ * @param check Function returning boolean or Promise<boolean> indicating health
225
+ * @returns This instance for method chaining
226
+ */
227
+ registerHealthCheck(name: string, check: () => Promise<boolean> | boolean): this;
228
+ /**
229
+ * Run registered health checks and return whether the service is ready.
230
+ * Useful for readiness probes in deployment tooling.
231
+ *
232
+ * @returns Promise resolving to `true` when all checks pass, otherwise `false`.
233
+ */
234
+ ready(): Promise<boolean>;
235
+ /**
236
+ * Get the underlying Express application instance.
237
+ * Use this for advanced Express features not exposed by this wrapper.
238
+ *
239
+ * @returns The raw Express app instance
240
+ */
241
+ getApp(): Express;
242
+ /**
243
+ * Get the active HTTP/HTTPS server instance.
244
+ * Returns null if the server is not currently running.
245
+ *
246
+ * @returns The HTTP/HTTPS server instance or null
247
+ */
248
+ getServer(): http.Server | https.Server | null;
249
+ /**
250
+ * Start the HTTP server and begin listening for requests.
251
+ *
252
+ * This method:
253
+ * - Executes beforeStart hooks
254
+ * - Binds to the configured host/port
255
+ * - Sets up error handling for startup failures
256
+ * - Executes afterStart hooks on success
257
+ * - Logs startup information
258
+ *
259
+ * @returns Promise resolving to the running HTTP server instance
260
+ * @throws Error if server fails to start or port is already in use
261
+ */
262
+ start(): Promise<http.Server | https.Server>;
263
+ /**
264
+ * Create HTTP or HTTPS server instance.
265
+ */
266
+ private createServerInstance;
267
+ /**
268
+ * Set up connection tracking for graceful shutdown.
269
+ */
270
+ private setupConnectionTracking;
271
+ /**
272
+ * Set up error handling for server startup.
273
+ */
274
+ private setupServerErrorHandling;
275
+ /**
276
+ * Log server startup information.
277
+ */
278
+ private logServerStartInfo;
279
+ /**
280
+ * Stop the HTTP server gracefully.
281
+ *
282
+ * This method:
283
+ * - Executes beforeStop hooks
284
+ * - Stops accepting new connections
285
+ * - Waits for existing connections to finish
286
+ * - Closes the server
287
+ * - Executes afterStop hooks
288
+ * - Logs shutdown information
289
+ *
290
+ * Graceful shutdown ensures:
291
+ * - No requests are dropped
292
+ * - Resources are properly cleaned up
293
+ * - Monitoring systems are notified
294
+ */
295
+ stop(force?: boolean): Promise<void>;
296
+ /**
297
+ * Perform graceful server shutdown with timeout.
298
+ */
299
+ private gracefulShutdown;
300
+ /**
301
+ * Enable graceful shutdown on OS signals for production deployment.
302
+ *
303
+ * This is essential for:
304
+ * - Container orchestration (Docker, Kubernetes)
305
+ * - Process managers (PM2, systemd)
306
+ * - Load balancer health checks
307
+ * - Zero-downtime deployments
308
+ *
309
+ * @param signals Array of process signals to listen for (default: SIGINT, SIGTERM)
310
+ */
311
+ enableGracefulShutdown(signals?: NodeJS.Signals[]): this;
312
+ /**
313
+ * Set an externally created base router.
314
+ * This will override the internal rootRouter.
315
+ */
316
+ setBaseRouter(router: Router): this;
317
+ /**
318
+ * Create and register a new router (only used if not injecting one externally - use `setBaseRouter` instead).
319
+ */
320
+ createRouter(prefix?: string): Router;
321
+ /**
322
+ * Register a new route handler with support for multiple HTTP methods.
323
+ * The route is automatically registered under the globalPrefix if set.
324
+ *
325
+ * @param methods Array of HTTP methods (get, post, put, delete, etc.)
326
+ * @param path Route path with Express path patterns support
327
+ * @param handlers One or more Express request handlers (middleware + final handler)
328
+ * @returns This instance for method chaining
329
+ */
330
+ registerRoute(methods: Array<keyof Pick<Express, 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head'>>, path: string, ...handlers: Array<express.RequestHandler>): this;
331
+ /**
332
+ * Register custom middleware with optional path restriction.
333
+ *
334
+ * Use this for:
335
+ * - Adding authentication to specific routes
336
+ * - Custom logging or validation
337
+ * - Request transformation
338
+ * - Third-party middleware integration
339
+ *
340
+ * @param path Optional path prefix or middleware function if no path
341
+ * @param middleware Middleware handler (required if path is provided)
342
+ * @returns This instance for method chaining
343
+ */
344
+ registerMiddleware(path: string | express.RequestHandler, middleware?: express.RequestHandler): this;
345
+ /**
346
+ * Register one or more middleware functions to be applied globally.
347
+ * This is a simpler alternative to registerMiddleware when you just want
348
+ * to add middleware without path restrictions.
349
+ *
350
+ * @param middlewares One or more Express middleware functions
351
+ * @returns This instance for method chaining
352
+ */
353
+ useMiddleware(...middlewares: express.RequestHandler[]): this;
354
+ /**
355
+ * Get Prometheus registry (to add custom counters/histograms)
356
+ *
357
+ * @return {*} {client.Registry}
358
+ */
359
+ getMetricsRegistry(): typeof prom_client.Registry;
360
+ /**
361
+ * Get server configuration
362
+ *
363
+ * @return {*} {CatbeeServerConfig}
364
+ */
365
+ getConfig(): CatbeeServerConfig;
366
+ /**
367
+ * Wait until server initialization (middleware + routes) has completed.
368
+ * Useful for integration tests that inspect app before starting.
369
+ */
370
+ waitUntilReady(): Promise<void>;
371
+ private normalizePath;
372
+ private normalizeRouteForMetrics;
373
+ /**
374
+ * Destroy all active connections (gracefully if possible).
375
+ * If a connection does not close cleanly, it will be force-destroyed.
376
+ */
377
+ private destroyConnections;
378
+ private validateHttpsFiles;
379
+ private hasBuildMarker;
380
+ private throwDependancyError;
381
+ }
382
+
383
+ /**
384
+ * Builder class for creating and configuring an Express server configuration.
385
+ *
386
+ * This class provides a fluent interface to configure all aspects of the Express server
387
+ * including security settings, middleware, routing, and more.
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * const serverConfig = new ServerConfigBuilder()
392
+ * .withPort(3000)
393
+ * .withHost('localhost')
394
+ * .enableCors()
395
+ * .enableHelmet()
396
+ * .build();
397
+ * ```
398
+ */
399
+ declare class ServerConfigBuilder {
400
+ private config;
401
+ /**
402
+ * Validates that a port number is valid and usable.
403
+ *
404
+ * @private
405
+ * @param port - The port number to validate
406
+ * @throws {Error} If port is not an integer or is outside the valid range (1-65535)
407
+ */
408
+ private validatePort;
409
+ /**
410
+ * Sets the port the server will listen on.
411
+ *
412
+ * @param port - The port number (1-65535)
413
+ * @returns The builder instance for chaining
414
+ * @throws {Error} If port is invalid
415
+ * @default 3000 (can be overridden via PORT env variable)
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * builder.withPort(3000)
420
+ * ```
421
+ */
422
+ withPort(port: number): this;
423
+ /**
424
+ * Sets the hostname the server will bind to.
425
+ *
426
+ * @param host - The hostname (e.g., 'localhost', '0.0.0.0', '127.0.0.1')
427
+ * @returns The builder instance for chaining
428
+ * @default '0.0.0.0' (can be overridden via HOST env variable)
429
+ *
430
+ * @example
431
+ * ```typescript
432
+ * builder.withHost('0.0.0.0') // Listen on all interfaces
433
+ * ```
434
+ */
435
+ withHost(host: string): this;
436
+ /**
437
+ * Configures Cross-Origin Resource Sharing (CORS) for the server.
438
+ *
439
+ * @param opts - CORS options object or boolean (true to enable with defaults, false to disable)
440
+ * @returns The builder instance for chaining
441
+ * @default false (CORS is disabled by default)
442
+ *
443
+ * @example
444
+ * ```typescript
445
+ * // Enable CORS with default options
446
+ * builder.withCors(true)
447
+ *
448
+ * // Configure CORS with specific options
449
+ * builder.withCors({
450
+ * origin: ['https://example.com'],
451
+ * methods: ['GET', 'POST']
452
+ * })
453
+ * ```
454
+ */
455
+ withCors(opts: CatbeeServerConfig['cors']): this;
456
+ /**
457
+ * Enables CORS with default settings
458
+ *
459
+ * @returns The builder instance for chaining
460
+ */
461
+ enableCors(): this;
462
+ /**
463
+ * Disables CORS
464
+ *
465
+ * @returns The builder instance for chaining
466
+ */
467
+ disableCors(): this;
468
+ /**
469
+ * Configures the Helmet middleware for setting HTTP security headers.
470
+ *
471
+ * @param opts - Helmet options object or boolean (true to enable with defaults, false to disable)
472
+ * @returns The builder instance for chaining
473
+ * @default false (Helmet is disabled by default)
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * // Enable Helmet with default settings
478
+ * builder.withHelmet(true)
479
+ *
480
+ * // Configure Helmet with specific options
481
+ * builder.withHelmet({
482
+ * contentSecurityPolicy: false,
483
+ * xssFilter: true
484
+ * })
485
+ * ```
486
+ */
487
+ withHelmet(opts: CatbeeServerConfig['helmet']): this;
488
+ /**
489
+ * Enables Helmet with default settings
490
+ *
491
+ * @returns The builder instance for chaining
492
+ */
493
+ enableHelmet(): this;
494
+ /**
495
+ * Disables Helmet
496
+ *
497
+ * @returns The builder instance for chaining
498
+ */
499
+ disableHelmet(): this;
500
+ /**
501
+ * Configures response compression middleware.
502
+ *
503
+ * @param opts - Compression options object or boolean (true to enable with defaults, false to disable)
504
+ * @returns The builder instance for chaining
505
+ * @default false (Compression is disabled by default)
506
+ *
507
+ * @example
508
+ * ```typescript
509
+ * // Enable compression with default settings
510
+ * builder.withCompression(true)
511
+ *
512
+ * // Configure compression with specific options
513
+ * builder.withCompression({
514
+ * level: 6,
515
+ * threshold: 1024
516
+ * })
517
+ * ```
518
+ */
519
+ withCompression(opts: CatbeeServerConfig['compression']): this;
520
+ /**
521
+ * Enables compression with default settings
522
+ *
523
+ * @returns The builder instance for chaining
524
+ */
525
+ enableCompression(): this;
526
+ /**
527
+ * Disables compression
528
+ *
529
+ * @returns The builder instance for chaining
530
+ */
531
+ disableCompression(): this;
532
+ /**
533
+ * Configures rate limiting to protect against brute-force attacks.
534
+ *
535
+ * @param opts - Rate limit configuration options
536
+ * @returns The builder instance for chaining
537
+ * @default - { enable: false, windowMs: 15 * 60 * 1000, max: 100, message: 'Too many requests', standardHeaders: true, legacyHeaders: false }
538
+ *
539
+ * @example
540
+ * ```typescript
541
+ * builder.withRateLimit({
542
+ * enable: true,
543
+ * windowMs: 15 * 60 * 1000, // 15 minutes
544
+ * max: 100 // limit each IP to 100 requests per windowMs
545
+ * })
546
+ * ```
547
+ */
548
+ withRateLimit(opts: Partial<CatbeeServerConfig['rateLimit']>): this;
549
+ /**
550
+ * Enables rate limiting with default or custom settings
551
+ *
552
+ * @param opts - Optional rate limit configuration (max requests, window, etc.)
553
+ * @returns The builder instance for chaining
554
+ */
555
+ enableRateLimit(opts?: Omit<Partial<NonNullable<CatbeeServerConfig['rateLimit']>>, 'enable'>): this;
556
+ /**
557
+ * Disables rate limiting
558
+ *
559
+ * @returns The builder instance for chaining
560
+ */
561
+ disableRateLimit(): this;
562
+ /**
563
+ * Configures HTTP request logging middleware.
564
+ *
565
+ * @param opts - Request logging configuration options
566
+ * @returns The builder instance for chaining
567
+ * @default - { enable: true in dev/false in prod, ignorePaths: ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'], skipNotFoundRoutes: false }
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * builder.withRequestLogging({
572
+ * enable: true,
573
+ * ignorePaths: ['/health', '/metrics'],
574
+ * skipNotFoundRoutes: true
575
+ * })
576
+ * ```
577
+ */
578
+ withRequestLogging(opts: Partial<NonNullable<CatbeeServerConfig['requestLogging']>>): this;
579
+ /**
580
+ * Enables request logging with default or custom settings
581
+ *
582
+ * @param opts - Optional request logging configuration
583
+ * @returns The builder instance for chaining
584
+ */
585
+ enableRequestLogging(opts?: Omit<Partial<NonNullable<CatbeeServerConfig['requestLogging']>>, 'enable'>): this;
586
+ /**
587
+ * Disables request logging
588
+ *
589
+ * @returns The builder instance for chaining
590
+ */
591
+ disableRequestLogging(): this;
592
+ /**
593
+ * Configures server metrics collection and endpoints.
594
+ *
595
+ * @param opts - Metrics configuration options
596
+ * @returns The builder instance for chaining
597
+ * @default - { enable: false, path: '/metrics', withGlobalPrefix: false }
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * builder.withMetrics({
602
+ * enable: true,
603
+ * path: '/metrics'
604
+ * })
605
+ * ```
606
+ */
607
+ withMetrics(opts: Partial<NonNullable<CatbeeServerConfig['metrics']>>): this;
608
+ /**
609
+ * Enables Prometheus metrics collection and endpoint
610
+ *
611
+ * @param opts - Optional metrics configuration
612
+ * @returns The builder instance for chaining
613
+ */
614
+ enableMetrics(opts?: Omit<Partial<NonNullable<CatbeeServerConfig['metrics']>>, 'enable'>): this;
615
+ /**
616
+ * Disables Prometheus metrics
617
+ *
618
+ * @returns The builder instance for chaining
619
+ */
620
+ disableMetrics(): this;
621
+ /**
622
+ * Configures server health check endpoint.
623
+ *
624
+ * @param opts - Health check configuration options
625
+ * @returns The builder instance for chaining
626
+ * @default - { path: '/healthz', detailed: true, withGlobalPrefix: false }
627
+ *
628
+ * @example
629
+ * ```typescript
630
+ * builder.withHealthCheck({
631
+ * path: '/health',
632
+ * detailed: true
633
+ * })
634
+ * ```
635
+ */
636
+ withHealthCheck(opts: Partial<NonNullable<CatbeeServerConfig['healthCheck']>>): this;
637
+ /**
638
+ * Configures OpenAPI/Swagger documentation for the API.
639
+ *
640
+ * @param opts - OpenAPI configuration options
641
+ * @returns The builder instance for chaining
642
+ * @default - { enable: false, mountPath: '/docs', verbose: false, withGlobalPrefix: false }
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * builder.withOpenApi({
647
+ * enable: true,
648
+ * path: '/api-docs',
649
+ * filePath: './openapi.yaml'
650
+ * })
651
+ * ```
652
+ */
653
+ withOpenApi(opts: Partial<NonNullable<CatbeeServerConfig['openApi']>>): this;
654
+ /**
655
+ * Enables OpenAPI documentation with required file path
656
+ *
657
+ * @param filePath - Path to OpenAPI specification file (required)
658
+ * @param opts - Optional OpenAPI configuration
659
+ * @returns The builder instance for chaining
660
+ */
661
+ enableOpenApi(filePath: string, opts?: Omit<Partial<NonNullable<CatbeeServerConfig['openApi']>>, 'enable' | 'filePath'>): this;
662
+ /**
663
+ * Disables OpenAPI documentation
664
+ *
665
+ * @returns The builder instance for chaining
666
+ */
667
+ disableOpenApi(): this;
668
+ /**
669
+ * Configures the server as a microservice with versioning.
670
+ *
671
+ * @param opts - Microservice configuration options including app name and service version
672
+ * @returns The builder instance for chaining
673
+ * @default - { isMicroservice: false, appName: 'express_app' }
674
+ *
675
+ * @example
676
+ * ```typescript
677
+ * builder.withMicroService({
678
+ * appName: 'user-service',
679
+ * serviceVersion: {
680
+ * enable: true,
681
+ * version: '1.2.3'
682
+ * }
683
+ * })
684
+ * ```
685
+ */
686
+ withMicroService(opts: {
687
+ appName: NonNullable<CatbeeServerConfig['appName']>;
688
+ serviceVersion: Partial<NonNullable<CatbeeServerConfig['serviceVersion']>>;
689
+ }): this;
690
+ /**
691
+ * Configures the trust proxy settings to determine if X-Forwarded-* headers should be trusted.
692
+ *
693
+ * @param opts - Trust proxy configuration options
694
+ * @returns The builder instance for chaining
695
+ * @default false
696
+ *
697
+ * @example
698
+ * ```typescript
699
+ * // Trust proxy headers (useful when behind a load balancer)
700
+ * builder.withTrustProxy(true)
701
+ * ```
702
+ */
703
+ withTrustProxy(opts: NonNullable<CatbeeServerConfig['trustProxy']>): this;
704
+ /**
705
+ * Configures the request ID middleware for tracing requests across services.
706
+ *
707
+ * @param opts - Request ID configuration options
708
+ * @returns The builder instance for chaining
709
+ * @default - { headerName: 'x-request-id', exposeHeader: true }
710
+ *
711
+ * @example
712
+ * ```typescript
713
+ * builder.withRequestId({
714
+ * headerName: 'X-Request-Id',
715
+ * generator: () => crypto.randomUUID()
716
+ * })
717
+ * ```
718
+ */
719
+ withRequestId(opts: Partial<NonNullable<CatbeeServerConfig['requestId']>>): this;
720
+ /**
721
+ * Configures the response time middleware for measuring request processing times.
722
+ *
723
+ * @param opts - Response time configuration options
724
+ * @returns The builder instance for chaining
725
+ * @default - { enable: false, addHeader: true, logOnComplete: false }
726
+ *
727
+ * @example
728
+ * ```typescript
729
+ * builder.withResponseTime({
730
+ * enable: true,
731
+ * addHeader: true,
732
+ * logOnComplete: true
733
+ * })
734
+ * ```
735
+ */
736
+ withResponseTime(opts: Partial<NonNullable<CatbeeServerConfig['responseTime']>>): this;
737
+ /**
738
+ * Enables response time tracking with default or custom settings
739
+ *
740
+ * @param opts - Optional response time configuration
741
+ * @returns The builder instance for chaining
742
+ */
743
+ enableResponseTime(opts?: Omit<Partial<NonNullable<CatbeeServerConfig['responseTime']>>, 'enable'>): this;
744
+ /**
745
+ * Disables response time tracking
746
+ *
747
+ * @returns The builder instance for chaining
748
+ */
749
+ disableResponseTime(): this;
750
+ /**
751
+ * Configures the body parser middleware options for parsing request bodies.
752
+ *
753
+ * @param opts - Body parser configuration options
754
+ * @returns The builder instance for chaining
755
+ * @default - { json: { limit: '1mb' }, urlencoded: { extended: true, limit: '1mb' } }
756
+ *
757
+ * @example
758
+ * ```typescript
759
+ * builder.withBodyParser({
760
+ * json: {
761
+ * limit: '1mb'
762
+ * },
763
+ * urlencoded: {
764
+ * extended: true,
765
+ * limit: '1mb'
766
+ * }
767
+ * })
768
+ * ```
769
+ */
770
+ withBodyParser(opts: NonNullable<CatbeeServerConfig['bodyParser']>): this;
771
+ /**
772
+ * Configures cookie parsing middleware.
773
+ *
774
+ * @param opts - Cookie parser options or boolean (true to enable with defaults, false to disable)
775
+ * @returns The builder instance for chaining
776
+ * @default false
777
+ *
778
+ * @example
779
+ * ```typescript
780
+ * // Enable cookie parsing with default options
781
+ * builder.withCookies(true)
782
+ *
783
+ * // Enable cookie parsing with specific options
784
+ * builder.withCookies({
785
+ * secret: 'your-secret-key',
786
+ * secure: true
787
+ * })
788
+ * ```
789
+ */
790
+ withCookies(opts: CatbeeServerConfig['cookieParser']): this;
791
+ /**
792
+ * Adds a static folder to serve files from.
793
+ *
794
+ * @param folder - Static folder configuration
795
+ * @returns The builder instance for chaining
796
+ *
797
+ * @example
798
+ * ```typescript
799
+ * builder.withStaticFolder({
800
+ * path: '/assets',
801
+ * directory: './public',
802
+ * options: { maxAge: '1d' }
803
+ * })
804
+ * ```
805
+ */
806
+ withStaticFolder(folder: NonNullable<CatbeeServerConfig['staticFolders']>[number]): this;
807
+ /**
808
+ * Sets global headers to be included in all responses.
809
+ *
810
+ * @param headers - Object containing header name/value pairs or functions that return values
811
+ * @returns The builder instance for chaining
812
+ * @default - {}
813
+ *
814
+ * @example
815
+ * ```typescript
816
+ * builder.withGlobalHeaders({
817
+ * 'X-Powered-By': 'Catbee',
818
+ * 'Server-Time': () => new Date().toISOString()
819
+ * })
820
+ * ```
821
+ */
822
+ withGlobalHeaders(headers: NonNullable<CatbeeServerConfig['globalHeaders']>): this;
823
+ /**
824
+ * Sets a global prefix for all routes.
825
+ *
826
+ * @param prefix - The prefix to prepend to all routes (e.g., '/api/v1')
827
+ * @returns The builder instance for chaining
828
+ * @default '/'
829
+ *
830
+ * @example
831
+ * ```typescript
832
+ * builder.withGlobalPrefix('/api/v1')
833
+ * ```
834
+ */
835
+ withGlobalPrefix(prefix: string): this;
836
+ /**
837
+ * Applies custom configuration overrides directly.
838
+ *
839
+ * @param overrides - Custom configuration options to merge
840
+ * @returns The builder instance for chaining
841
+ *
842
+ * @example
843
+ * ```typescript
844
+ * builder.withCustom({
845
+ * port: 8080,
846
+ * customMiddleware: myMiddlewareFunction
847
+ * })
848
+ * ```
849
+ */
850
+ withCustom(overrides: Partial<CatbeeServerConfig>): this;
851
+ /**
852
+ * Configures HTTPS server options.
853
+ *
854
+ * @param opts - HTTPS configuration (key, cert, ca, passphrase, etc.)
855
+ * @returns The builder instance for chaining
856
+ *
857
+ * @example
858
+ * ```typescript
859
+ * builder.withHttps({
860
+ * key: './localhost-key.pem',
861
+ * cert: './localhost-cert.pem'
862
+ * })
863
+ * ```
864
+ */
865
+ withHttps(opts: NonNullable<CatbeeServerConfig['https']>): this;
866
+ /**
867
+ * Builds and returns the final server configuration.
868
+ *
869
+ * This method merges the user-specified configuration with default values,
870
+ * ensures all sections with 'enable' flags are properly structured, and
871
+ * produces the final configuration to be used by the server.
872
+ *
873
+ * @returns The complete ServerConfig object
874
+ *
875
+ * @example
876
+ * ```typescript
877
+ * const config = new ServerConfigBuilder()
878
+ * .withPort(3000)
879
+ * .withHost('localhost')
880
+ * .withCors(true)
881
+ * .build();
882
+ * ```
883
+ */
884
+ build(): Readonly<CatbeeServerConfig>;
885
+ private mergeConfig;
886
+ private setEnabled;
887
+ }
888
+
889
+ export { DependencyErrors, ExpressServer, ServerConfigBuilder };