@naman_deep_singh/server-utils 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +19 -5
  2. package/dist/cjs/core/health.d.ts +5 -0
  3. package/dist/cjs/{health.js → core/health.js} +4 -4
  4. package/dist/cjs/{periodic-health.d.ts → core/periodic-health.d.ts} +1 -1
  5. package/dist/cjs/{periodic-health.js → core/periodic-health.js} +4 -4
  6. package/dist/{types → cjs/core}/server.d.ts +8 -7
  7. package/dist/cjs/{server.js → core/server.js} +70 -25
  8. package/dist/cjs/{shutdown.d.ts → core/shutdown.d.ts} +2 -2
  9. package/dist/cjs/{shutdown.js → core/shutdown.js} +2 -1
  10. package/dist/cjs/index.d.ts +14 -14
  11. package/dist/cjs/index.js +10 -10
  12. package/dist/cjs/middleware/auth.middleware.d.ts +7 -0
  13. package/dist/cjs/middleware/auth.middleware.js +41 -0
  14. package/dist/cjs/middleware/cache.middleware.d.ts +2 -0
  15. package/dist/cjs/middleware/cache.middleware.js +58 -0
  16. package/dist/cjs/middleware/errorHandler.middleware.d.ts +2 -0
  17. package/dist/cjs/middleware/errorHandler.middleware.js +30 -0
  18. package/dist/cjs/middleware/index.d.ts +10 -0
  19. package/dist/cjs/middleware/index.js +40 -0
  20. package/dist/cjs/middleware/logging.middleware.d.ts +2 -0
  21. package/dist/cjs/middleware/logging.middleware.js +19 -0
  22. package/dist/cjs/middleware/plugins.middleware.d.ts +14 -0
  23. package/dist/cjs/middleware/plugins.middleware.js +58 -0
  24. package/dist/cjs/middleware/rateLimiter.middleware.d.ts +8 -0
  25. package/dist/cjs/middleware/rateLimiter.middleware.js +35 -0
  26. package/dist/cjs/middleware/requestId.middleware.d.ts +2 -0
  27. package/dist/cjs/middleware/requestId.middleware.js +12 -0
  28. package/dist/cjs/middleware/session.middleware.d.ts +2 -0
  29. package/dist/cjs/middleware/session.middleware.js +53 -0
  30. package/dist/cjs/middleware/validation.middleware.d.ts +11 -0
  31. package/dist/cjs/middleware/validation.middleware.js +67 -0
  32. package/dist/{esm/types.d.ts → cjs/types/index.d.ts} +1 -1
  33. package/dist/cjs/{utils.js → utils/utils.js} +2 -2
  34. package/dist/esm/core/health.d.ts +5 -0
  35. package/dist/esm/{health.js → core/health.js} +4 -4
  36. package/dist/esm/{periodic-health.d.ts → core/periodic-health.d.ts} +1 -1
  37. package/dist/esm/{periodic-health.js → core/periodic-health.js} +4 -4
  38. package/dist/esm/{server.d.ts → core/server.d.ts} +8 -7
  39. package/dist/esm/{server.js → core/server.js} +36 -24
  40. package/dist/esm/{shutdown.d.ts → core/shutdown.d.ts} +2 -2
  41. package/dist/esm/{shutdown.js → core/shutdown.js} +2 -1
  42. package/dist/esm/index.d.ts +14 -14
  43. package/dist/esm/index.js +12 -12
  44. package/dist/esm/middleware/auth.middleware.d.ts +7 -0
  45. package/dist/esm/middleware/auth.middleware.js +38 -0
  46. package/dist/esm/middleware/cache.middleware.d.ts +2 -0
  47. package/dist/esm/middleware/cache.middleware.js +55 -0
  48. package/dist/esm/middleware/errorHandler.middleware.d.ts +2 -0
  49. package/dist/esm/middleware/errorHandler.middleware.js +27 -0
  50. package/dist/esm/middleware/index.d.ts +10 -0
  51. package/dist/esm/middleware/index.js +20 -0
  52. package/dist/esm/middleware/logging.middleware.d.ts +2 -0
  53. package/dist/esm/middleware/logging.middleware.js +16 -0
  54. package/dist/esm/middleware/plugins.middleware.d.ts +14 -0
  55. package/dist/esm/middleware/plugins.middleware.js +47 -0
  56. package/dist/esm/middleware/rateLimiter.middleware.d.ts +8 -0
  57. package/dist/esm/middleware/rateLimiter.middleware.js +32 -0
  58. package/dist/esm/middleware/requestId.middleware.d.ts +2 -0
  59. package/dist/esm/middleware/requestId.middleware.js +9 -0
  60. package/dist/esm/middleware/session.middleware.d.ts +2 -0
  61. package/dist/esm/middleware/session.middleware.js +50 -0
  62. package/dist/esm/middleware/validation.middleware.d.ts +11 -0
  63. package/dist/esm/middleware/validation.middleware.js +64 -0
  64. package/dist/{types/types.d.ts → esm/types/index.d.ts} +1 -1
  65. package/dist/esm/{utils.js → utils/utils.js} +2 -2
  66. package/dist/types/core/health.d.ts +5 -0
  67. package/dist/types/{periodic-health.d.ts → core/periodic-health.d.ts} +1 -1
  68. package/dist/{cjs → types/core}/server.d.ts +8 -7
  69. package/dist/types/{shutdown.d.ts → core/shutdown.d.ts} +2 -2
  70. package/dist/types/index.d.ts +14 -14
  71. package/dist/types/middleware/auth.middleware.d.ts +7 -0
  72. package/dist/types/middleware/cache.middleware.d.ts +2 -0
  73. package/dist/types/middleware/errorHandler.middleware.d.ts +2 -0
  74. package/dist/types/middleware/index.d.ts +10 -0
  75. package/dist/types/middleware/logging.middleware.d.ts +2 -0
  76. package/dist/types/middleware/plugins.middleware.d.ts +14 -0
  77. package/dist/types/middleware/rateLimiter.middleware.d.ts +8 -0
  78. package/dist/types/middleware/requestId.middleware.d.ts +2 -0
  79. package/dist/types/middleware/session.middleware.d.ts +2 -0
  80. package/dist/types/middleware/validation.middleware.d.ts +11 -0
  81. package/dist/{cjs/types.d.ts → types/types/index.d.ts} +1 -1
  82. package/package.json +4 -2
  83. package/dist/cjs/health.d.ts +0 -5
  84. package/dist/cjs/middleware.d.ts +0 -39
  85. package/dist/cjs/middleware.js +0 -348
  86. package/dist/esm/health.d.ts +0 -5
  87. package/dist/esm/middleware.d.ts +0 -39
  88. package/dist/esm/middleware.js +0 -329
  89. package/dist/types/health.d.ts +0 -5
  90. package/dist/types/middleware.d.ts +0 -39
  91. /package/dist/cjs/{types.js → types/index.js} +0 -0
  92. /package/dist/cjs/{utils.d.ts → utils/utils.d.ts} +0 -0
  93. /package/dist/esm/{types.js → types/index.js} +0 -0
  94. /package/dist/esm/{utils.d.ts → utils/utils.d.ts} +0 -0
  95. /package/dist/types/{utils.d.ts → utils/utils.d.ts} +0 -0
@@ -0,0 +1,50 @@
1
+ // Session middleware helper (attaches sessionStore and helpers to req)
2
+ export function useSession(cookieName) {
3
+ return async (req, res, next) => {
4
+ try {
5
+ const store = req.app.locals.sessionStore;
6
+ if (!store)
7
+ return next();
8
+ const name = cookieName || req.app.locals.sessionCookieName || 'sid';
9
+ let sid = req.cookies?.[name];
10
+ if (!sid) {
11
+ const cookieHeader = req.headers.cookie;
12
+ if (cookieHeader) {
13
+ const match = cookieHeader
14
+ .split(';')
15
+ .map((s) => s.trim())
16
+ .find((s) => s.startsWith(`${name}=`));
17
+ if (match)
18
+ sid = match.split('=')[1];
19
+ }
20
+ }
21
+ req.sessionId = sid;
22
+ req.sessionStore = store;
23
+ req.getSession = async () => {
24
+ if (!sid)
25
+ return null;
26
+ try {
27
+ return await store.get(sid);
28
+ }
29
+ catch (err) {
30
+ console.error(`[Session] Failed to get session "${sid}":`, err);
31
+ throw err;
32
+ }
33
+ };
34
+ req.createSession = async (id, data, ttl) => {
35
+ try {
36
+ return await store.create(id, data, ttl);
37
+ }
38
+ catch (err) {
39
+ console.error(`[Session] Failed to create session "${id}":`, err);
40
+ throw err;
41
+ }
42
+ };
43
+ next();
44
+ }
45
+ catch (err) {
46
+ console.error('[Session] Unexpected error in useSession middleware:', err);
47
+ next();
48
+ }
49
+ };
50
+ }
@@ -0,0 +1,11 @@
1
+ import type { RequestHandler } from 'node_modules/@types/express';
2
+ export interface ValidationRule {
3
+ field: string;
4
+ required?: boolean;
5
+ type?: 'string' | 'number' | 'email' | 'boolean';
6
+ minLength?: number;
7
+ maxLength?: number;
8
+ pattern?: RegExp;
9
+ custom?: (value: unknown) => boolean | string;
10
+ }
11
+ export declare function createValidationMiddleware(rules: ValidationRule[]): RequestHandler;
@@ -0,0 +1,64 @@
1
+ import { ValidationError } from '@naman_deep_singh/errors-utils';
2
+ export function createValidationMiddleware(rules) {
3
+ return (req, res, next) => {
4
+ const errors = [];
5
+ for (const rule of rules) {
6
+ const value = req.body[rule.field];
7
+ if (rule.required &&
8
+ (value === undefined || value === null || value === '')) {
9
+ errors.push(`${rule.field} is required`);
10
+ continue;
11
+ }
12
+ if (value === undefined || value === null)
13
+ continue;
14
+ if (rule.type) {
15
+ switch (rule.type) {
16
+ case 'email':
17
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
18
+ if (!emailRegex.test(value)) {
19
+ errors.push(`${rule.field} must be a valid email`);
20
+ }
21
+ break;
22
+ case 'string':
23
+ if (typeof value !== 'string') {
24
+ errors.push(`${rule.field} must be a string`);
25
+ }
26
+ break;
27
+ case 'number':
28
+ if (typeof value !== 'number' && isNaN(Number(value))) {
29
+ errors.push(`${rule.field} must be a number`);
30
+ }
31
+ break;
32
+ case 'boolean':
33
+ if (typeof value !== 'boolean') {
34
+ errors.push(`${rule.field} must be a boolean`);
35
+ }
36
+ break;
37
+ }
38
+ }
39
+ if (rule.minLength && value.length < rule.minLength) {
40
+ errors.push(`${rule.field} must be at least ${rule.minLength} characters`);
41
+ }
42
+ if (rule.maxLength && value.length > rule.maxLength) {
43
+ errors.push(`${rule.field} must be no more than ${rule.maxLength} characters`);
44
+ }
45
+ if (rule.pattern && !rule.pattern.test(value)) {
46
+ errors.push(`${rule.field} format is invalid`);
47
+ }
48
+ if (rule.custom) {
49
+ const result = rule.custom(value);
50
+ if (result !== true) {
51
+ errors.push(typeof result === 'string' ? result : `${rule.field} is invalid`);
52
+ }
53
+ }
54
+ }
55
+ if (errors.length > 0) {
56
+ // Use ValidationError from errors-utils and let error middleware handle response
57
+ const validationError = new ValidationError('Validation failed', {
58
+ validationErrors: errors,
59
+ });
60
+ return next(validationError);
61
+ }
62
+ next();
63
+ };
64
+ }
@@ -1,4 +1,4 @@
1
- import express from 'express';
1
+ import type express from 'express';
2
2
  export interface CorsOptions {
3
3
  origin?: string | string[] | boolean | RegExp | ((origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => void);
4
4
  methods?: string | string[];
@@ -31,8 +31,8 @@ export function getEnvBoolean(key, defaultValue) {
31
31
  return defaultValue;
32
32
  }
33
33
  const normalized = value.toLowerCase();
34
- if (normalized !== "true" && normalized !== "false") {
34
+ if (normalized !== 'true' && normalized !== 'false') {
35
35
  throw new Error(`Environment variable ${key} must be 'true' or 'false'`);
36
36
  }
37
- return normalized === "true";
37
+ return normalized === 'true';
38
38
  }
@@ -0,0 +1,5 @@
1
+ import type { Application, RequestHandler } from 'express';
2
+ import type { HealthCheckConfig, ServerPlugin } from '../types';
3
+ export declare function createHealthCheck(config?: HealthCheckConfig): RequestHandler;
4
+ export declare function withHealthCheck(path?: string, config?: HealthCheckConfig): ServerPlugin;
5
+ export declare function addHealthCheck(app: Application, path?: string, config?: HealthCheckConfig): void;
@@ -1,4 +1,4 @@
1
- import { PeriodicHealthCheckConfig } from './types';
1
+ import type { PeriodicHealthCheckConfig } from '../types';
2
2
  export declare class PeriodicHealthMonitor {
3
3
  private intervals;
4
4
  private config;
@@ -1,6 +1,7 @@
1
- import express from 'express';
2
- import { Server } from 'http';
3
- import { ServerConfig, SocketIOConfig } from './types';
1
+ import { ICache, SessionStore } from '@naman_deep_singh/cache';
2
+ import type { Server } from 'http';
3
+ import type { Application } from 'express';
4
+ import type { ServerConfig, SocketIOConfig } from '../types';
4
5
  export interface GrpcService {
5
6
  service: Record<string, unknown>;
6
7
  implementation: Record<string, (...args: unknown[]) => unknown>;
@@ -26,7 +27,7 @@ export interface ServerInstanceConfig extends Required<Omit<ServerConfig, 'socke
26
27
  socketIO?: SocketIOConfig;
27
28
  }
28
29
  export interface ServerInstance {
29
- app: express.Application;
30
+ app: Application;
30
31
  server?: Server;
31
32
  config: ServerInstanceConfig;
32
33
  start(): Promise<ServerInstance>;
@@ -46,11 +47,11 @@ export interface ServerInfo {
46
47
  startTime: Date;
47
48
  }
48
49
  export declare class ExpressServer implements ServerInstance {
49
- app: express.Application;
50
+ app: Application;
50
51
  server?: Server;
51
52
  config: ServerInstanceConfig;
52
- cache?: import('@naman_deep_singh/cache').ICache<unknown>;
53
- sessionStore?: import('@naman_deep_singh/cache').SessionStore | undefined;
53
+ cache?: ICache<unknown>;
54
+ sessionStore?: SessionStore | undefined;
54
55
  private status;
55
56
  private grpcServices;
56
57
  private grpcServer?;
@@ -1,5 +1,5 @@
1
- import { Server } from 'http';
2
- import { GracefulShutdownConfig, ServerPlugin } from './types';
1
+ import type { Server } from 'http';
2
+ import type { GracefulShutdownConfig, ServerPlugin } from '../types';
3
3
  export declare function createGracefulShutdown(server: Server, config?: GracefulShutdownConfig): void;
4
4
  export declare function withGracefulShutdown(config?: GracefulShutdownConfig): ServerPlugin;
5
5
  export declare function startServerWithShutdown(app: import('express').Application, port: number, shutdownConfig?: GracefulShutdownConfig, serverName?: string, serverVersion?: string): Server;
@@ -1,19 +1,19 @@
1
- export { ExpressServer, createServer } from './server';
2
- export type { ServerInstance, ServerInfo, GrpcService, RpcMethod, WebhookConfig } from './server';
1
+ export { ExpressServer, createServer } from './core/server';
2
+ export type { ServerInstance, ServerInfo, GrpcService, RpcMethod, WebhookConfig, } from './core/server';
3
3
  export { Request, Response, NextFunction, Router, Application } from 'express';
4
4
  export type { RequestHandler, ErrorRequestHandler } from 'express';
5
- export { createHealthCheck, withHealthCheck, addHealthCheck } from './health';
6
- export { createGracefulShutdown, withGracefulShutdown, startServerWithShutdown } from './shutdown';
7
- export { createLoggingMiddleware, createErrorHandler, createRequestIdMiddleware, createValidationMiddleware, createRateLimitMiddleware, createAuthMiddleware, withLogging, withErrorHandler, withRequestId, withValidation, withRateLimit, withAuth, validateFields, rateLimit, requireAuth, cacheResponse, useSession, type ValidationRule, type RateLimitConfig, type AuthConfig } from './middleware';
8
- export { getEnv, getEnvNumber, getEnvBoolean } from './utils';
9
- export { PeriodicHealthMonitor } from './periodic-health';
10
- export type { ServerConfig, HealthCheckConfig, HealthCheck, GracefulShutdownConfig, ServerPlugin, SocketIOConfig, SocketInstance, PeriodicHealthCheckConfig, HealthCheckService } from './types';
11
- import { ExpressServer, createServer } from './server';
12
- import { createHealthCheck, withHealthCheck, addHealthCheck } from './health';
13
- import { createGracefulShutdown, withGracefulShutdown, startServerWithShutdown } from './shutdown';
14
- import { createLoggingMiddleware, createErrorHandler, createRequestIdMiddleware, createValidationMiddleware, createRateLimitMiddleware, createAuthMiddleware, withLogging, withErrorHandler, withRequestId, withValidation, withRateLimit, withAuth, validateFields, rateLimit, requireAuth } from './middleware';
15
- import { getEnv, getEnvNumber, getEnvBoolean } from './utils';
16
- import { PeriodicHealthMonitor } from './periodic-health';
5
+ export { createHealthCheck, withHealthCheck, addHealthCheck, } from './core/health';
6
+ export { createGracefulShutdown, withGracefulShutdown, startServerWithShutdown, } from './core/shutdown';
7
+ export { createLoggingMiddleware, createErrorHandler, createRequestIdMiddleware, createValidationMiddleware, createRateLimitMiddleware, createAuthMiddleware, withLogging, withErrorHandler, withRequestId, withValidation, withRateLimit, withAuth, validateFields, rateLimit, requireAuth, cacheResponse, useSession, type ValidationRule, type RateLimitConfig, type AuthConfig, } from './middleware';
8
+ export { getEnv, getEnvNumber, getEnvBoolean, } from './utils/utils';
9
+ export { PeriodicHealthMonitor } from './core/periodic-health';
10
+ export type { ServerConfig, HealthCheckConfig, HealthCheck, GracefulShutdownConfig, ServerPlugin, SocketIOConfig, SocketInstance, PeriodicHealthCheckConfig, HealthCheckService, } from './types';
11
+ import { addHealthCheck, createHealthCheck, withHealthCheck } from './core/health';
12
+ import { PeriodicHealthMonitor } from './core/periodic-health';
13
+ import { ExpressServer, createServer } from './core/server';
14
+ import { createGracefulShutdown, startServerWithShutdown, withGracefulShutdown } from './core/shutdown';
15
+ import { createAuthMiddleware, createErrorHandler, createLoggingMiddleware, createRateLimitMiddleware, createRequestIdMiddleware, createValidationMiddleware, rateLimit, requireAuth, validateFields, withAuth, withErrorHandler, withLogging, withRateLimit, withRequestId, withValidation } from './middleware';
16
+ import { getEnv, getEnvBoolean, getEnvNumber } from './utils/utils';
17
17
  declare const ServerUtils: {
18
18
  createServer: typeof createServer;
19
19
  ExpressServer: typeof ExpressServer;
@@ -0,0 +1,7 @@
1
+ import type { Request, RequestHandler } from 'node_modules/@types/express';
2
+ export interface AuthConfig {
3
+ secret: string;
4
+ unauthorizedMessage?: string;
5
+ tokenExtractor?: (req: Request) => string | null;
6
+ }
7
+ export declare function createAuthMiddleware(config: AuthConfig): RequestHandler;
@@ -0,0 +1,2 @@
1
+ import type { RequestHandler } from 'node_modules/@types/express';
2
+ export declare function cacheResponse(ttl?: number): RequestHandler;
@@ -0,0 +1,2 @@
1
+ import type { ErrorRequestHandler } from 'node_modules/@types/express';
2
+ export declare function createErrorHandler(): ErrorRequestHandler;
@@ -0,0 +1,10 @@
1
+ export { AuthConfig, createAuthMiddleware } from './auth.middleware';
2
+ export { cacheResponse } from './cache.middleware';
3
+ export { createErrorHandler } from './errorHandler.middleware';
4
+ export { createLoggingMiddleware } from './logging.middleware';
5
+ export { RateLimitConfig, createRateLimitMiddleware, } from './rateLimiter.middleware';
6
+ export { createRequestIdMiddleware } from './requestId.middleware';
7
+ export { useSession } from './session.middleware';
8
+ export { ValidationRule, createValidationMiddleware, } from './validation.middleware';
9
+ export { withLogging, withErrorHandler, withRequestId, withValidation, withRateLimit, withAuth, } from './plugins.middleware';
10
+ export { validateFields, rateLimit, requireAuth, } from './plugins.middleware';
@@ -0,0 +1,2 @@
1
+ import type { RequestHandler } from 'node_modules/@types/express';
2
+ export declare function createLoggingMiddleware(format?: 'simple' | 'detailed'): RequestHandler;
@@ -0,0 +1,14 @@
1
+ import type { RequestHandler } from 'express';
2
+ import type { ServerPlugin } from '../types';
3
+ import type { AuthConfig } from './auth.middleware';
4
+ import type { RateLimitConfig } from './rateLimiter.middleware';
5
+ import type { ValidationRule } from './validation.middleware';
6
+ export declare function withLogging(format?: 'simple' | 'detailed'): ServerPlugin;
7
+ export declare function withErrorHandler(): ServerPlugin;
8
+ export declare function withRequestId(): ServerPlugin;
9
+ export declare function withValidation(rules: ValidationRule[]): ServerPlugin;
10
+ export declare function withRateLimit(config?: RateLimitConfig): ServerPlugin;
11
+ export declare function withAuth(config: AuthConfig): ServerPlugin;
12
+ export declare function validateFields(rules: ValidationRule[]): RequestHandler;
13
+ export declare function rateLimit(config?: RateLimitConfig): RequestHandler;
14
+ export declare function requireAuth(config: AuthConfig): RequestHandler;
@@ -0,0 +1,8 @@
1
+ import type { Request, RequestHandler } from 'node_modules/@types/express';
2
+ export interface RateLimitConfig {
3
+ windowMs?: number;
4
+ maxRequests?: number;
5
+ message?: string;
6
+ keyGenerator?: (req: Request) => string;
7
+ }
8
+ export declare function createRateLimitMiddleware(config?: RateLimitConfig): RequestHandler;
@@ -0,0 +1,2 @@
1
+ import type { RequestHandler } from 'node_modules/@types/express';
2
+ export declare function createRequestIdMiddleware(): RequestHandler;
@@ -0,0 +1,2 @@
1
+ import type { RequestHandler } from 'node_modules/@types/express';
2
+ export declare function useSession(cookieName?: string): RequestHandler;
@@ -0,0 +1,11 @@
1
+ import type { RequestHandler } from 'node_modules/@types/express';
2
+ export interface ValidationRule {
3
+ field: string;
4
+ required?: boolean;
5
+ type?: 'string' | 'number' | 'email' | 'boolean';
6
+ minLength?: number;
7
+ maxLength?: number;
8
+ pattern?: RegExp;
9
+ custom?: (value: unknown) => boolean | string;
10
+ }
11
+ export declare function createValidationMiddleware(rules: ValidationRule[]): RequestHandler;
@@ -1,4 +1,4 @@
1
- import express from 'express';
1
+ import type express from 'express';
2
2
  export interface CorsOptions {
3
3
  origin?: string | string[] | boolean | RegExp | ((origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => void);
4
4
  methods?: string | string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/server-utils",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Extensible server utilities for Express.js microservices with TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -27,7 +27,9 @@
27
27
  "author": "Naman Deep Singh",
28
28
  "license": "ISC",
29
29
  "dependencies": {
30
- "@naman_deep_singh/cache": "^1.2.0",
30
+ "@naman_deep_singh/cache": "^1.3.1",
31
+ "@naman_deep_singh/errors-utils": "^1.1.1",
32
+ "@naman_deep_singh/security": "^1.3.1",
31
33
  "@types/express": "^5.0.5",
32
34
  "cookie-parser": "^1.4.6",
33
35
  "cors": "^2.8.5",
@@ -1,5 +0,0 @@
1
- import express from 'express';
2
- import { HealthCheckConfig, ServerPlugin } from './types';
3
- export declare function createHealthCheck(config?: HealthCheckConfig): express.RequestHandler;
4
- export declare function withHealthCheck(path?: string, config?: HealthCheckConfig): ServerPlugin;
5
- export declare function addHealthCheck(app: express.Application, path?: string, config?: HealthCheckConfig): void;
@@ -1,39 +0,0 @@
1
- import express from 'express';
2
- import { ServerPlugin } from './types';
3
- export declare function createLoggingMiddleware(format?: 'simple' | 'detailed'): express.RequestHandler;
4
- export declare function createErrorHandler(): express.ErrorRequestHandler;
5
- export declare function createRequestIdMiddleware(): express.RequestHandler;
6
- export interface ValidationRule {
7
- field: string;
8
- required?: boolean;
9
- type?: 'string' | 'number' | 'email' | 'boolean';
10
- minLength?: number;
11
- maxLength?: number;
12
- pattern?: RegExp;
13
- custom?: (value: unknown) => boolean | string;
14
- }
15
- export declare function createValidationMiddleware(rules: ValidationRule[]): express.RequestHandler;
16
- export interface RateLimitConfig {
17
- windowMs?: number;
18
- maxRequests?: number;
19
- message?: string;
20
- keyGenerator?: (req: express.Request) => string;
21
- }
22
- export declare function createRateLimitMiddleware(config?: RateLimitConfig): express.RequestHandler;
23
- export interface AuthConfig {
24
- tokenExtractor?: (req: express.Request) => string | null;
25
- tokenValidator?: (token: string) => Promise<unknown> | unknown;
26
- unauthorizedMessage?: string;
27
- }
28
- export declare function createAuthMiddleware(config: AuthConfig): express.RequestHandler;
29
- export declare function withLogging(format?: 'simple' | 'detailed'): ServerPlugin;
30
- export declare function withErrorHandler(): ServerPlugin;
31
- export declare function withRequestId(): ServerPlugin;
32
- export declare function withValidation(rules: ValidationRule[]): ServerPlugin;
33
- export declare function withRateLimit(config?: RateLimitConfig): ServerPlugin;
34
- export declare function withAuth(config: AuthConfig): ServerPlugin;
35
- export declare function validateFields(rules: ValidationRule[]): express.RequestHandler;
36
- export declare function rateLimit(config?: RateLimitConfig): express.RequestHandler;
37
- export declare function requireAuth(config: AuthConfig): express.RequestHandler;
38
- export declare function cacheResponse(ttl?: number): express.RequestHandler;
39
- export declare function useSession(cookieName?: string): express.RequestHandler;