@naman_deep_singh/server-utils 1.0.7 → 1.0.8

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.
package/dist/index.d.ts CHANGED
@@ -6,14 +6,14 @@ export { createHealthCheck, withHealthCheck, addHealthCheck } from './health';
6
6
  export { createGracefulShutdown, withGracefulShutdown, startServerWithShutdown } from './shutdown';
7
7
  export { createLoggingMiddleware, createErrorHandler, createRequestIdMiddleware, createValidationMiddleware, createRateLimitMiddleware, createAuthMiddleware, withLogging, withErrorHandler, withRequestId, withValidation, withRateLimit, withAuth, validateFields, rateLimit, requireAuth, type ValidationRule, type RateLimitConfig, type AuthConfig } from './middleware';
8
8
  export { getEnv, getEnvNumber, getEnvBoolean } from './utils';
9
- export { PeriodicHealthMonitor, createPeriodicHealthMonitor } from './periodic-health';
9
+ export { PeriodicHealthMonitor } from './periodic-health';
10
10
  export type { ServerConfig, HealthCheckConfig, HealthCheck, GracefulShutdownConfig, ServerPlugin, SocketIOConfig, SocketInstance, PeriodicHealthCheckConfig, HealthCheckService } from './types';
11
11
  import { ExpressServer, createServer } from './server';
12
12
  import { createHealthCheck, withHealthCheck, addHealthCheck } from './health';
13
13
  import { createGracefulShutdown, withGracefulShutdown, startServerWithShutdown } from './shutdown';
14
14
  import { createLoggingMiddleware, createErrorHandler, createRequestIdMiddleware, createValidationMiddleware, createRateLimitMiddleware, createAuthMiddleware, withLogging, withErrorHandler, withRequestId, withValidation, withRateLimit, withAuth, validateFields, rateLimit, requireAuth } from './middleware';
15
15
  import { getEnv, getEnvNumber, getEnvBoolean } from './utils';
16
- import { PeriodicHealthMonitor, createPeriodicHealthMonitor } from './periodic-health';
16
+ import { PeriodicHealthMonitor } from './periodic-health';
17
17
  declare const ServerUtils: {
18
18
  createServer: typeof createServer;
19
19
  ExpressServer: typeof ExpressServer;
@@ -42,6 +42,5 @@ declare const ServerUtils: {
42
42
  getEnvNumber: typeof getEnvNumber;
43
43
  getEnvBoolean: typeof getEnvBoolean;
44
44
  PeriodicHealthMonitor: typeof PeriodicHealthMonitor;
45
- createPeriodicHealthMonitor: typeof createPeriodicHealthMonitor;
46
45
  };
47
46
  export default ServerUtils;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPeriodicHealthMonitor = exports.PeriodicHealthMonitor = exports.getEnvBoolean = exports.getEnvNumber = exports.getEnv = exports.requireAuth = exports.rateLimit = exports.validateFields = exports.withAuth = exports.withRateLimit = exports.withValidation = exports.withRequestId = exports.withErrorHandler = exports.withLogging = exports.createAuthMiddleware = exports.createRateLimitMiddleware = exports.createValidationMiddleware = exports.createRequestIdMiddleware = exports.createErrorHandler = exports.createLoggingMiddleware = exports.startServerWithShutdown = exports.withGracefulShutdown = exports.createGracefulShutdown = exports.addHealthCheck = exports.withHealthCheck = exports.createHealthCheck = exports.Router = exports.createServer = exports.ExpressServer = void 0;
3
+ exports.PeriodicHealthMonitor = exports.getEnvBoolean = exports.getEnvNumber = exports.getEnv = exports.requireAuth = exports.rateLimit = exports.validateFields = exports.withAuth = exports.withRateLimit = exports.withValidation = exports.withRequestId = exports.withErrorHandler = exports.withLogging = exports.createAuthMiddleware = exports.createRateLimitMiddleware = exports.createValidationMiddleware = exports.createRequestIdMiddleware = exports.createErrorHandler = exports.createLoggingMiddleware = exports.startServerWithShutdown = exports.withGracefulShutdown = exports.createGracefulShutdown = exports.addHealthCheck = exports.withHealthCheck = exports.createHealthCheck = exports.Router = exports.createServer = exports.ExpressServer = void 0;
4
4
  // Core server utilities
5
5
  var server_1 = require("./server");
6
6
  Object.defineProperty(exports, "ExpressServer", { enumerable: true, get: function () { return server_1.ExpressServer; } });
@@ -43,7 +43,6 @@ Object.defineProperty(exports, "getEnvBoolean", { enumerable: true, get: functio
43
43
  // Periodic health monitoring
44
44
  var periodic_health_1 = require("./periodic-health");
45
45
  Object.defineProperty(exports, "PeriodicHealthMonitor", { enumerable: true, get: function () { return periodic_health_1.PeriodicHealthMonitor; } });
46
- Object.defineProperty(exports, "createPeriodicHealthMonitor", { enumerable: true, get: function () { return periodic_health_1.createPeriodicHealthMonitor; } });
47
46
  // Import all exports for default export
48
47
  const server_2 = require("./server");
49
48
  const health_2 = require("./health");
@@ -86,6 +85,5 @@ const ServerUtils = {
86
85
  getEnvBoolean: utils_2.getEnvBoolean,
87
86
  // Periodic Health Monitoring
88
87
  PeriodicHealthMonitor: periodic_health_2.PeriodicHealthMonitor,
89
- createPeriodicHealthMonitor: periodic_health_2.createPeriodicHealthMonitor
90
88
  };
91
89
  exports.default = ServerUtils;
@@ -9,4 +9,3 @@ export declare class PeriodicHealthMonitor {
9
9
  private checkServiceHealth;
10
10
  getHealthStatus(): Promise<Record<string, boolean>>;
11
11
  }
12
- export declare function createPeriodicHealthMonitor(config: PeriodicHealthCheckConfig, serviceName: string): PeriodicHealthMonitor;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PeriodicHealthMonitor = void 0;
4
- exports.createPeriodicHealthMonitor = createPeriodicHealthMonitor;
5
4
  class PeriodicHealthMonitor {
6
5
  constructor(config, serviceName) {
7
6
  this.intervals = [];
@@ -67,6 +66,3 @@ class PeriodicHealthMonitor {
67
66
  }
68
67
  }
69
68
  exports.PeriodicHealthMonitor = PeriodicHealthMonitor;
70
- function createPeriodicHealthMonitor(config, serviceName) {
71
- return new PeriodicHealthMonitor(config, serviceName);
72
- }
package/dist/server.js CHANGED
@@ -93,7 +93,7 @@ class ExpressServer {
93
93
  }
94
94
  setupPeriodicHealthMonitoring() {
95
95
  if (this.config.periodicHealthCheck?.enabled) {
96
- this.healthMonitor = (0, periodic_health_1.createPeriodicHealthMonitor)(this.config.periodicHealthCheck, this.config.name);
96
+ this.healthMonitor = new periodic_health_1.PeriodicHealthMonitor(this.config.periodicHealthCheck, this.config.name);
97
97
  }
98
98
  }
99
99
  async start() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/server-utils",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Extensible server utilities for Express.js microservices with TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -13,15 +13,15 @@ export { createHealthCheck, withHealthCheck, addHealthCheck } from './health';
13
13
  export { createGracefulShutdown, withGracefulShutdown, startServerWithShutdown } from './shutdown';
14
14
 
15
15
  // Middleware utilities
16
- export {
17
- createLoggingMiddleware,
18
- createErrorHandler,
16
+ export {
17
+ createLoggingMiddleware,
18
+ createErrorHandler,
19
19
  createRequestIdMiddleware,
20
20
  createValidationMiddleware,
21
21
  createRateLimitMiddleware,
22
22
  createAuthMiddleware,
23
- withLogging,
24
- withErrorHandler,
23
+ withLogging,
24
+ withErrorHandler,
25
25
  withRequestId,
26
26
  withValidation,
27
27
  withRateLimit,
@@ -42,14 +42,14 @@ export {
42
42
  } from './utils';
43
43
 
44
44
  // Periodic health monitoring
45
- export { PeriodicHealthMonitor, createPeriodicHealthMonitor } from './periodic-health';
45
+ export { PeriodicHealthMonitor } from './periodic-health';
46
46
 
47
47
  // Types
48
- export type {
49
- ServerConfig,
50
- HealthCheckConfig,
51
- HealthCheck,
52
- GracefulShutdownConfig,
48
+ export type {
49
+ ServerConfig,
50
+ HealthCheckConfig,
51
+ HealthCheck,
52
+ GracefulShutdownConfig,
53
53
  ServerPlugin,
54
54
  SocketIOConfig,
55
55
  SocketInstance,
@@ -61,15 +61,15 @@ export type {
61
61
  import { ExpressServer, createServer } from './server';
62
62
  import { createHealthCheck, withHealthCheck, addHealthCheck } from './health';
63
63
  import { createGracefulShutdown, withGracefulShutdown, startServerWithShutdown } from './shutdown';
64
- import {
65
- createLoggingMiddleware,
66
- createErrorHandler,
64
+ import {
65
+ createLoggingMiddleware,
66
+ createErrorHandler,
67
67
  createRequestIdMiddleware,
68
68
  createValidationMiddleware,
69
69
  createRateLimitMiddleware,
70
70
  createAuthMiddleware,
71
- withLogging,
72
- withErrorHandler,
71
+ withLogging,
72
+ withErrorHandler,
73
73
  withRequestId,
74
74
  withValidation,
75
75
  withRateLimit,
@@ -79,24 +79,24 @@ import {
79
79
  requireAuth
80
80
  } from './middleware';
81
81
  import { getEnv, getEnvNumber, getEnvBoolean } from './utils';
82
- import { PeriodicHealthMonitor, createPeriodicHealthMonitor } from './periodic-health';
82
+ import { PeriodicHealthMonitor } from './periodic-health';
83
83
 
84
84
  // Default export for namespace usage
85
85
  const ServerUtils = {
86
86
  // Server creation
87
87
  createServer,
88
88
  ExpressServer,
89
-
89
+
90
90
  // Health checks
91
91
  createHealthCheck,
92
92
  withHealthCheck,
93
93
  addHealthCheck,
94
-
94
+
95
95
  // Graceful shutdown
96
96
  createGracefulShutdown,
97
97
  withGracefulShutdown,
98
98
  startServerWithShutdown,
99
-
99
+
100
100
  // Middleware
101
101
  createLoggingMiddleware,
102
102
  createErrorHandler,
@@ -113,15 +113,14 @@ const ServerUtils = {
113
113
  validateFields,
114
114
  rateLimit,
115
115
  requireAuth,
116
-
116
+
117
117
  // Utils
118
118
  getEnv,
119
119
  getEnvNumber,
120
120
  getEnvBoolean,
121
-
121
+
122
122
  // Periodic Health Monitoring
123
123
  PeriodicHealthMonitor,
124
- createPeriodicHealthMonitor
125
124
  };
126
125
 
127
126
  export default ServerUtils;
@@ -16,12 +16,12 @@ export class PeriodicHealthMonitor {
16
16
  }
17
17
 
18
18
  const interval = this.config.interval || 30000;
19
-
19
+
20
20
  this.config.services.forEach(service => {
21
21
  const intervalId = setInterval(async () => {
22
22
  await this.checkServiceHealth(service);
23
23
  }, interval);
24
-
24
+
25
25
  this.intervals.push(intervalId);
26
26
  });
27
27
 
@@ -49,7 +49,7 @@ export class PeriodicHealthMonitor {
49
49
  });
50
50
 
51
51
  clearTimeout(timeoutId);
52
-
52
+
53
53
  if (response.ok) {
54
54
  console.log(`🟢 ${service.name} is healthy`);
55
55
  return true;
@@ -71,7 +71,7 @@ export class PeriodicHealthMonitor {
71
71
  }
72
72
 
73
73
  const results: Record<string, boolean> = {};
74
-
74
+
75
75
  await Promise.all(
76
76
  this.config.services.map(async service => {
77
77
  results[service.name] = await this.checkServiceHealth(service);
@@ -80,8 +80,4 @@ export class PeriodicHealthMonitor {
80
80
 
81
81
  return results;
82
82
  }
83
- }
84
-
85
- export function createPeriodicHealthMonitor(config: PeriodicHealthCheckConfig, serviceName: string): PeriodicHealthMonitor {
86
- return new PeriodicHealthMonitor(config, serviceName);
87
83
  }
package/src/server.ts CHANGED
@@ -2,7 +2,7 @@ import express from 'express';
2
2
  import { Server } from 'http';
3
3
  import { ServerConfig, SocketIOConfig, SocketInstance } from './types';
4
4
  import { createGracefulShutdown } from './shutdown';
5
- import { PeriodicHealthMonitor, createPeriodicHealthMonitor } from './periodic-health';
5
+ import { PeriodicHealthMonitor } from './periodic-health';
6
6
  import crypto from 'crypto';
7
7
 
8
8
  export interface GrpcService {
@@ -95,7 +95,7 @@ export class ExpressServer implements ServerInstance {
95
95
 
96
96
  // Apply middleware based on configuration
97
97
  this.setupMiddleware();
98
-
98
+
99
99
  // Setup periodic health monitoring
100
100
  this.setupPeriodicHealthMonitoring();
101
101
  }
@@ -161,7 +161,7 @@ export class ExpressServer implements ServerInstance {
161
161
 
162
162
  private setupPeriodicHealthMonitoring(): void {
163
163
  if (this.config.periodicHealthCheck?.enabled) {
164
- this.healthMonitor = createPeriodicHealthMonitor(
164
+ this.healthMonitor = new PeriodicHealthMonitor(
165
165
  this.config.periodicHealthCheck,
166
166
  this.config.name
167
167
  );
@@ -360,7 +360,7 @@ export class ExpressServer implements ServerInstance {
360
360
  };
361
361
 
362
362
  // Configure CORS
363
- const corsConfig = config.cors === true
363
+ const corsConfig = config.cors === true
364
364
  ? { origin: '*', methods: ['GET', 'POST'] }
365
365
  : config.cors || undefined;
366
366