@stacksjs/bun-router 0.0.2
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/LICENSE.md +21 -0
- package/README.md +397 -0
- package/bin/cli.ts +9 -0
- package/dist/auth.d.ts +77 -0
- package/dist/cache/lru-cache.d.ts +88 -0
- package/dist/cache/middleware-memoization.d.ts +101 -0
- package/dist/cache/route-cache-warmer.d.ts +125 -0
- package/dist/cache/sqlite-cache.d.ts +114 -0
- package/dist/cache/streaming-cache.d.ts +86 -0
- package/dist/chunk-r15a48wc.js +25448 -0
- package/dist/cli/colors.d.ts +12 -0
- package/dist/cli/index.d.ts +10 -0
- package/dist/cli/middleware.d.ts +31 -0
- package/dist/cli/openapi.d.ts +17 -0
- package/dist/cli/router.d.ts +15 -0
- package/dist/cli/routes.d.ts +30 -0
- package/dist/cli/utils.d.ts +68 -0
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +3195 -0
- package/dist/config.d.ts +274 -0
- package/dist/container/container.d.ts +141 -0
- package/dist/container/contextual-binding.d.ts +112 -0
- package/dist/container/decorators.d.ts +114 -0
- package/dist/container/service-provider.d.ts +221 -0
- package/dist/development/hot-reload.d.ts +129 -0
- package/dist/development/index.d.ts +144 -0
- package/dist/development/performance-profiler.d.ts +152 -0
- package/dist/development/route-debugger.d.ts +102 -0
- package/dist/development/route-inspector.d.ts +142 -0
- package/dist/development/typescript-utilities.d.ts +116 -0
- package/dist/docs.d.ts +10 -0
- package/dist/errors/circuit-breaker.d.ts +138 -0
- package/dist/errors/error-handler.d.ts +57 -0
- package/dist/errors/error-reporting.d.ts +135 -0
- package/dist/errors/exceptions.d.ts +178 -0
- package/dist/errors/graceful-degradation.d.ts +130 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/router-errors.d.ts +97 -0
- package/dist/file-serving/static-files.d.ts +98 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +13417 -0
- package/dist/middleware/auth.d.ts +34 -0
- package/dist/middleware/content_security_policy.d.ts +54 -0
- package/dist/middleware/cors.d.ts +5 -0
- package/dist/middleware/csrf.d.ts +7 -0
- package/dist/middleware/ddos_protection.d.ts +47 -0
- package/dist/middleware/file_security.d.ts +23 -0
- package/dist/middleware/file_upload.d.ts +41 -0
- package/dist/middleware/helmet.d.ts +54 -0
- package/dist/middleware/index.d.ts +55 -0
- package/dist/middleware/input_validation.d.ts +46 -0
- package/dist/middleware/json_body.d.ts +4 -0
- package/dist/middleware/performance_alerting.d.ts +88 -0
- package/dist/middleware/performance_dashboard.d.ts +97 -0
- package/dist/middleware/performance_monitor.d.ts +236 -0
- package/dist/middleware/pipeline.d.ts +90 -0
- package/dist/middleware/rate_limit.d.ts +33 -0
- package/dist/middleware/request_id.d.ts +4 -0
- package/dist/middleware/request_signing.d.ts +96 -0
- package/dist/middleware/request_tracer.d.ts +76 -0
- package/dist/middleware/response_cache.d.ts +90 -0
- package/dist/middleware/security.d.ts +70 -0
- package/dist/middleware/security_suite.d.ts +46 -0
- package/dist/middleware/session.d.ts +7 -0
- package/dist/model-binding/index.d.ts +17 -0
- package/dist/model-binding/model-middleware.d.ts +80 -0
- package/dist/model-binding/model-registry.d.ts +125 -0
- package/dist/model-binding.d.ts +123 -0
- package/dist/model-resolver-factory.d.ts +31 -0
- package/dist/observability/correlation.d.ts +131 -0
- package/dist/observability/health-checks.d.ts +129 -0
- package/dist/observability/index.d.ts +92 -0
- package/dist/observability/integration.d.ts +112 -0
- package/dist/observability/metrics.d.ts +135 -0
- package/dist/observability/tracing.d.ts +112 -0
- package/dist/optimization/bun-utilities.d.ts +106 -0
- package/dist/query-builder-integration.d.ts +24 -0
- package/dist/request/enhanced-request.d.ts +143 -0
- package/dist/request/macros.d.ts +267 -0
- package/dist/response/macros.d.ts +207 -0
- package/dist/response/response-factory.d.ts +93 -0
- package/dist/router/file-based-routing.d.ts +40 -0
- package/dist/router/file-streaming.d.ts +6 -0
- package/dist/router/fluent-router.d.ts +179 -0
- package/dist/router/fluent-routing.d.ts +198 -0
- package/dist/router/group-organization.d.ts +5 -0
- package/dist/router/handler-resolver.d.ts +13 -0
- package/dist/router/http-methods.d.ts +10 -0
- package/dist/router/index.d.ts +114 -0
- package/dist/router/middleware-integration.d.ts +86 -0
- package/dist/router/middleware.d.ts +5 -0
- package/dist/router/model-binding.d.ts +7 -0
- package/dist/router/optimized-route-matching.d.ts +6 -0
- package/dist/router/route-building.d.ts +5 -0
- package/dist/router/route-compiler.d.ts +67 -0
- package/dist/router/route-matching.d.ts +5 -0
- package/dist/router/route-trie.d.ts +69 -0
- package/dist/router/router.d.ts +133 -0
- package/dist/router/server.d.ts +5 -0
- package/dist/router/validation-integration.d.ts +116 -0
- package/dist/router/view-rendering.d.ts +5 -0
- package/dist/router/websocket.d.ts +5 -0
- package/dist/routing/route-caching.d.ts +105 -0
- package/dist/routing/route-throttling.d.ts +112 -0
- package/dist/routing/subdomain-routing.d.ts +159 -0
- package/dist/streaming/index.d.ts +15 -0
- package/dist/streaming/sse-handler.d.ts +81 -0
- package/dist/streaming/stream-handler.d.ts +81 -0
- package/dist/testing/auth-testing.d.ts +107 -0
- package/dist/testing/file-upload-testing.d.ts +139 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/middleware-testing.d.ts +99 -0
- package/dist/testing/model-binding-testing.d.ts +132 -0
- package/dist/testing/performance-testing.d.ts +202 -0
- package/dist/testing/test-client.d.ts +58 -0
- package/dist/testing/test-request.d.ts +43 -0
- package/dist/testing/test-response.d.ts +45 -0
- package/dist/testing/types.d.ts +206 -0
- package/dist/testing/websocket-testing.d.ts +170 -0
- package/dist/types/controller-types.d.ts +303 -0
- package/dist/types/core.d.ts +526 -0
- package/dist/types/middleware-types.d.ts +315 -0
- package/dist/types/request-response-augmentation.d.ts +373 -0
- package/dist/types/route-inference.d.ts +287 -0
- package/dist/types.d.ts +1620 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/query-preservation.d.ts +31 -0
- package/dist/utils.d.ts +69 -0
- package/dist/validation/validator.d.ts +169 -0
- package/dist/websocket/clustering.d.ts +114 -0
- package/package.json +81 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EnhancedRequest, Middleware, NextFunction } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts and decodes Basic Auth credentials from Authorization header
|
|
4
|
+
*/
|
|
5
|
+
export declare function extractBasicAuth(authHeader: string): { username: string, password: string } | null;
|
|
6
|
+
/**
|
|
7
|
+
* Extracts Bearer token from Authorization header
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractBearerToken(authHeader: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Extracts API key from various sources
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractApiKey(req: EnhancedRequest, source?: 'header' | 'query' | 'cookie', key?: string): string | null;
|
|
14
|
+
// Convenience factory functions for common auth types
|
|
15
|
+
export declare function basicAuth(validator: (credentials: { username: string, password: string }, req: EnhancedRequest) => Promise<boolean> | boolean, options?: Partial<AuthOptions>): AuthMiddleware;
|
|
16
|
+
export declare function bearerAuth(validator: (token: string, req: EnhancedRequest) => Promise<boolean> | boolean, options?: Partial<AuthOptions>): AuthMiddleware;
|
|
17
|
+
export declare function jwtAuth(validator: (token: string, req: EnhancedRequest) => Promise<boolean> | boolean, options?: Partial<AuthOptions>): AuthMiddleware;
|
|
18
|
+
export declare function apiKeyAuth(validator: (apiKey: string, req: EnhancedRequest) => Promise<boolean> | boolean, options?: Partial<AuthOptions>): AuthMiddleware;
|
|
19
|
+
export declare function oauth2Auth(validator: (token: string, req: EnhancedRequest) => Promise<boolean> | boolean, options?: Partial<AuthOptions>): AuthMiddleware;
|
|
20
|
+
export declare interface AuthOptions {
|
|
21
|
+
type: 'basic' | 'bearer' | 'api-key' | 'oauth2' | 'jwt' | 'custom'
|
|
22
|
+
validator: (credentials: any, req: EnhancedRequest) => Promise<boolean> | boolean
|
|
23
|
+
userExtractor?: (credentials: any, req: EnhancedRequest) => Promise<any> | any
|
|
24
|
+
source?: 'header' | 'query' | 'cookie'
|
|
25
|
+
key?: string
|
|
26
|
+
realm?: string
|
|
27
|
+
credentialsExtractor?: (req: EnhancedRequest) => Promise<any> | any
|
|
28
|
+
attachUser?: boolean
|
|
29
|
+
}
|
|
30
|
+
export declare class AuthMiddleware implements Middleware {
|
|
31
|
+
private options: AuthOptions;
|
|
32
|
+
constructor(options: AuthOptions);
|
|
33
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
+
// Factory function for easy use
|
|
3
|
+
export declare function contentSecurityPolicy(options?: CSPOptions): (req: EnhancedRequest, next: NextFunction) => Promise<Response>;
|
|
4
|
+
export declare interface CSPDirectives {
|
|
5
|
+
'default-src'?: string[]
|
|
6
|
+
'script-src'?: string[]
|
|
7
|
+
'script-src-elem'?: string[]
|
|
8
|
+
'script-src-attr'?: string[]
|
|
9
|
+
'style-src'?: string[]
|
|
10
|
+
'style-src-elem'?: string[]
|
|
11
|
+
'style-src-attr'?: string[]
|
|
12
|
+
'img-src'?: string[]
|
|
13
|
+
'font-src'?: string[]
|
|
14
|
+
'connect-src'?: string[]
|
|
15
|
+
'media-src'?: string[]
|
|
16
|
+
'object-src'?: string[]
|
|
17
|
+
'child-src'?: string[]
|
|
18
|
+
'frame-src'?: string[]
|
|
19
|
+
'worker-src'?: string[]
|
|
20
|
+
'frame-ancestors'?: string[]
|
|
21
|
+
'form-action'?: string[]
|
|
22
|
+
'base-uri'?: string[]
|
|
23
|
+
'manifest-src'?: string[]
|
|
24
|
+
'prefetch-src'?: string[]
|
|
25
|
+
'navigate-to'?: string[]
|
|
26
|
+
'report-uri'?: string[]
|
|
27
|
+
'report-to'?: string[]
|
|
28
|
+
'require-trusted-types-for'?: string[]
|
|
29
|
+
'trusted-types'?: string[]
|
|
30
|
+
'upgrade-insecure-requests'?: boolean
|
|
31
|
+
'block-all-mixed-content'?: boolean
|
|
32
|
+
'plugin-types'?: string[]
|
|
33
|
+
'sandbox'?: string[]
|
|
34
|
+
'disown-opener'?: boolean
|
|
35
|
+
}
|
|
36
|
+
export declare interface CSPOptions {
|
|
37
|
+
directives?: CSPDirectives
|
|
38
|
+
reportOnly?: boolean
|
|
39
|
+
reportUri?: string
|
|
40
|
+
reportTo?: string
|
|
41
|
+
useNonces?: boolean
|
|
42
|
+
nonceLength?: number
|
|
43
|
+
upgradeInsecureRequests?: boolean
|
|
44
|
+
blockAllMixedContent?: boolean
|
|
45
|
+
}
|
|
46
|
+
export declare class ContentSecurityPolicy {
|
|
47
|
+
private options: CSPOptions;
|
|
48
|
+
private nonces: Map<string, string>;
|
|
49
|
+
constructor(options?: CSPOptions);
|
|
50
|
+
private generateNonce(): string;
|
|
51
|
+
private buildCSPHeader(): string;
|
|
52
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
53
|
+
getNonce(url: string): string | undefined;
|
|
54
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
+
export declare class Csrf {
|
|
3
|
+
static private tokens: any;
|
|
4
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
5
|
+
private generateToken(secret: string): string;
|
|
6
|
+
private parseCookies(req: Request): Record<string, string>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
+
// Factory function for easy use
|
|
3
|
+
export declare function ddosProtection(options?: DDoSProtectionOptions): (req: EnhancedRequest, next: NextFunction) => Promise<Response>;
|
|
4
|
+
export declare interface DDoSProtectionOptions {
|
|
5
|
+
enabled?: boolean
|
|
6
|
+
maxRequestsPerSecond?: number
|
|
7
|
+
maxRequestsPerMinute?: number
|
|
8
|
+
maxRequestsPerHour?: number
|
|
9
|
+
burstLimit?: number
|
|
10
|
+
windowSize?: number
|
|
11
|
+
blockDuration?: number
|
|
12
|
+
whitelistedIPs?: string[]
|
|
13
|
+
blacklistedIPs?: string[]
|
|
14
|
+
trustProxy?: boolean
|
|
15
|
+
skipSuccessfulRequests?: boolean
|
|
16
|
+
skipFailedRequests?: boolean
|
|
17
|
+
keyGenerator?: (req: EnhancedRequest) => string
|
|
18
|
+
onLimitReached?: (req: EnhancedRequest, rateLimitInfo: any) => Response | Promise<Response>
|
|
19
|
+
store?: 'memory' | 'redis'
|
|
20
|
+
redis?: {
|
|
21
|
+
url: string
|
|
22
|
+
prefix?: string
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
declare interface RequestInfo {
|
|
26
|
+
count: number
|
|
27
|
+
firstRequest: number
|
|
28
|
+
lastRequest: number
|
|
29
|
+
blocked: boolean
|
|
30
|
+
blockExpires?: number
|
|
31
|
+
}
|
|
32
|
+
export declare class DDoSProtection {
|
|
33
|
+
private options: DDoSProtectionOptions;
|
|
34
|
+
private requestStore: Map<string, RequestInfo>;
|
|
35
|
+
private cleanupInterval: Timer | null;
|
|
36
|
+
constructor(options?: DDoSProtectionOptions);
|
|
37
|
+
private defaultKeyGenerator(req: EnhancedRequest): string;
|
|
38
|
+
private startCleanupInterval(): void;
|
|
39
|
+
private isWhitelisted(ip: string): boolean;
|
|
40
|
+
private isBlacklisted(ip: string): boolean;
|
|
41
|
+
private getRateLimitInfo(key: string, now: number): RequestInfo;
|
|
42
|
+
private shouldBlock(info: RequestInfo, now: number): boolean;
|
|
43
|
+
private blockIP(info: RequestInfo, now: number): void;
|
|
44
|
+
private createBlockedResponse(req: EnhancedRequest, info: RequestInfo): Response;
|
|
45
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { UploadedFile } from './file_upload';
|
|
2
|
+
export declare function createFileSecurity(config?: FileSecurityConfig): FileSecurity;
|
|
3
|
+
export declare interface FileSecurityConfig {
|
|
4
|
+
scanForMalware?: boolean
|
|
5
|
+
checkMagicNumbers?: boolean
|
|
6
|
+
sanitizeFilenames?: boolean
|
|
7
|
+
preventExecutableUploads?: boolean
|
|
8
|
+
maxFilenameLength?: number
|
|
9
|
+
}
|
|
10
|
+
export declare class FileSecurity {
|
|
11
|
+
private config: Required<FileSecurityConfig>;
|
|
12
|
+
readonly private FILE_SIGNATURES: Record<string, Uint8Array[]>;
|
|
13
|
+
readonly private EXECUTABLE_EXTENSIONS: any;
|
|
14
|
+
constructor(config?: FileSecurityConfig);
|
|
15
|
+
validateFile(file: UploadedFile): { isValid: boolean, errors: string[] };
|
|
16
|
+
private validateFileSignature(file: UploadedFile): boolean;
|
|
17
|
+
private sanitizeFilename(filename: string): string;
|
|
18
|
+
private getFileExtension(filename: string): string;
|
|
19
|
+
private basicMalwareScan(file: UploadedFile): boolean;
|
|
20
|
+
getSafeFilename(originalName: string): string;
|
|
21
|
+
isAllowedFileType(mimetype: string, allowedTypes: string[]): boolean;
|
|
22
|
+
isWithinSizeLimit(fileSize: number, maxSize: number): boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import FileSecurity from './file_security';
|
|
2
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
3
|
+
import type { FileSecurityConfig } from './file_security';
|
|
4
|
+
// Factory function for easier usage
|
|
5
|
+
export declare function fileUpload(config?: FileUploadConfig): FileUpload;
|
|
6
|
+
// Specialized factory functions
|
|
7
|
+
export declare function singleFileUpload(fieldName: string, config?: FileUploadConfig): FileUpload;
|
|
8
|
+
export declare function multipleFileUpload(maxFiles?: number, config?: FileUploadConfig): FileUpload;
|
|
9
|
+
export declare function imageUpload(config?: FileUploadConfig): FileUpload;
|
|
10
|
+
export declare function documentUpload(config?: FileUploadConfig): FileUpload;
|
|
11
|
+
export declare interface UploadedFile {
|
|
12
|
+
fieldName: string
|
|
13
|
+
originalName: string
|
|
14
|
+
filename: string
|
|
15
|
+
path: string
|
|
16
|
+
size: number
|
|
17
|
+
mimetype: string
|
|
18
|
+
buffer: ArrayBuffer
|
|
19
|
+
}
|
|
20
|
+
export declare interface FileUploadConfig extends FileSecurityConfig {
|
|
21
|
+
destination?: string
|
|
22
|
+
maxFileSize?: number
|
|
23
|
+
maxFiles?: number
|
|
24
|
+
allowedMimeTypes?: string[]
|
|
25
|
+
allowedExtensions?: string[]
|
|
26
|
+
preserveOriginalName?: boolean
|
|
27
|
+
generateUniqueFilename?: boolean
|
|
28
|
+
createDestination?: boolean
|
|
29
|
+
}
|
|
30
|
+
export declare interface FileUploadOptions extends FileUploadConfig {
|
|
31
|
+
fieldName?: string | string[]
|
|
32
|
+
}
|
|
33
|
+
export declare class FileUpload {
|
|
34
|
+
private config: Required<FileUploadConfig>;
|
|
35
|
+
private fileSecurity: FileSecurity;
|
|
36
|
+
constructor(config?: FileUploadConfig);
|
|
37
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
38
|
+
private generateFilename(originalName: string): string;
|
|
39
|
+
private formatBytes(bytes: number): string;
|
|
40
|
+
private createErrorResponse(message: string, status: number): Response;
|
|
41
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
+
export declare interface HelmetOptions {
|
|
3
|
+
contentSecurityPolicy?: boolean | {
|
|
4
|
+
directives?: Record<string, string[]>
|
|
5
|
+
reportOnly?: boolean
|
|
6
|
+
reportUri?: string
|
|
7
|
+
upgradeInsecureRequests?: boolean
|
|
8
|
+
blockAllMixedContent?: boolean
|
|
9
|
+
}
|
|
10
|
+
crossOriginEmbedderPolicy?: boolean | {
|
|
11
|
+
policy?: 'require-corp' | 'credentialless'
|
|
12
|
+
}
|
|
13
|
+
crossOriginOpenerPolicy?: boolean | {
|
|
14
|
+
policy?: 'same-origin' | 'same-origin-allow-popups' | 'unsafe-none'
|
|
15
|
+
}
|
|
16
|
+
crossOriginResourcePolicy?: boolean | {
|
|
17
|
+
policy?: 'same-site' | 'same-origin' | 'cross-origin'
|
|
18
|
+
}
|
|
19
|
+
dnsPrefetchControl?: boolean | {
|
|
20
|
+
allow?: boolean
|
|
21
|
+
}
|
|
22
|
+
expectCt?: boolean | {
|
|
23
|
+
enforce?: boolean
|
|
24
|
+
maxAge?: number
|
|
25
|
+
reportUri?: string
|
|
26
|
+
}
|
|
27
|
+
frameguard?: boolean | {
|
|
28
|
+
action?: 'deny' | 'sameorigin'
|
|
29
|
+
domain?: string
|
|
30
|
+
}
|
|
31
|
+
hidePoweredBy?: boolean
|
|
32
|
+
hsts?: boolean | {
|
|
33
|
+
maxAge?: number
|
|
34
|
+
includeSubDomains?: boolean
|
|
35
|
+
preload?: boolean
|
|
36
|
+
}
|
|
37
|
+
ieNoOpen?: boolean
|
|
38
|
+
noSniff?: boolean
|
|
39
|
+
originAgentCluster?: boolean
|
|
40
|
+
permittedCrossDomainPolicies?: boolean | {
|
|
41
|
+
permittedPolicies?: 'none' | 'master-only' | 'by-content-type' | 'all'
|
|
42
|
+
}
|
|
43
|
+
referrerPolicy?: boolean | {
|
|
44
|
+
policy?: string | string[]
|
|
45
|
+
}
|
|
46
|
+
xssFilter?: boolean | {
|
|
47
|
+
setOnOldIE?: boolean
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export declare class Helmet {
|
|
51
|
+
private options: HelmetOptions;
|
|
52
|
+
constructor(options?: HelmetOptions);
|
|
53
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Auth, { apiKeyAuth, basicAuth, bearerAuth, extractApiKey, extractBasicAuth, extractBearerToken, jwtAuth, oauth2Auth, } from './auth';
|
|
2
|
+
import Cors from './cors';
|
|
3
|
+
import Csrf from './csrf';
|
|
4
|
+
import JsonBody from './json_body';
|
|
5
|
+
import RequestId from './request_id';
|
|
6
|
+
import RequestSigning from './request_signing';
|
|
7
|
+
import Session from './session';
|
|
8
|
+
export type { NonceStore, RequestSigningOptions, SignatureAlgorithm, SignedPart } from './request_signing';
|
|
9
|
+
export declare function auth(): Auth;
|
|
10
|
+
// Factory functions for easier middleware creation
|
|
11
|
+
export declare const cors: () => Cors;
|
|
12
|
+
export declare const jsonBody: () => JsonBody;
|
|
13
|
+
export declare const requestId: () => RequestId;
|
|
14
|
+
export declare const session: () => Session;
|
|
15
|
+
export declare const csrf: () => Csrf;
|
|
16
|
+
export declare const middleware: Proxy;
|
|
17
|
+
export { default as Auth } from './auth';
|
|
18
|
+
export { default as ContentSecurityPolicy } from './content_security_policy';
|
|
19
|
+
export { contentSecurityPolicy } from './content_security_policy';
|
|
20
|
+
export { default as Cors } from './cors';
|
|
21
|
+
export { default as Csrf } from './csrf';
|
|
22
|
+
export { default as DDoSProtection } from './ddos_protection';
|
|
23
|
+
export { ddosProtection } from './ddos_protection';
|
|
24
|
+
export { default as FileSecurity } from './file_security';
|
|
25
|
+
export { default as FileUpload } from './file_upload';
|
|
26
|
+
export { documentUpload, fileUpload, imageUpload, multipleFileUpload, singleFileUpload } from './file_upload';
|
|
27
|
+
export { default as Helmet } from './helmet';
|
|
28
|
+
export { default as InputValidation } from './input_validation';
|
|
29
|
+
export { inputValidation } from './input_validation';
|
|
30
|
+
export { default as JsonBody } from './json_body';
|
|
31
|
+
export { default as PerformanceAlerting, performanceAlerting } from './performance_alerting';
|
|
32
|
+
export { default as PerformanceDashboard, performanceDashboard } from './performance_dashboard';
|
|
33
|
+
export { default as PerformanceMonitor, performanceMonitor } from './performance_monitor';
|
|
34
|
+
export { default as RateLimit } from './rate_limit';
|
|
35
|
+
export { rateLimit } from './rate_limit';
|
|
36
|
+
export { default as RequestId } from './request_id';
|
|
37
|
+
export { InMemoryNonceStore, default as RequestSigning, requestSigning, signRequest, verifySignature } from './request_signing';
|
|
38
|
+
export { SignatureError } from './request_signing';
|
|
39
|
+
export { default as RequestTracer, requestTracer } from './request_tracer';
|
|
40
|
+
export { default as Security } from './security';
|
|
41
|
+
export { security } from './security';
|
|
42
|
+
export { default as SecuritySuite } from './security_suite';
|
|
43
|
+
export { securitySuite } from './security_suite';
|
|
44
|
+
export { default as Session } from './session';
|
|
45
|
+
export {
|
|
46
|
+
apiKeyAuth,
|
|
47
|
+
basicAuth,
|
|
48
|
+
bearerAuth,
|
|
49
|
+
extractApiKey,
|
|
50
|
+
extractBasicAuth,
|
|
51
|
+
extractBearerToken,
|
|
52
|
+
jwtAuth,
|
|
53
|
+
oauth2Auth,
|
|
54
|
+
};
|
|
55
|
+
export default middleware;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
+
// Factory function for easy use
|
|
3
|
+
export declare function inputValidation(options?: InputValidationOptions): (req: EnhancedRequest, next: NextFunction) => Promise<Response>;
|
|
4
|
+
export declare interface ValidationRule {
|
|
5
|
+
type: 'string' | 'number' | 'boolean' | 'email' | 'url' | 'uuid' | 'date' | 'regex' | 'custom'
|
|
6
|
+
required?: boolean
|
|
7
|
+
min?: number
|
|
8
|
+
max?: number
|
|
9
|
+
pattern?: RegExp
|
|
10
|
+
enum?: unknown[]
|
|
11
|
+
custom?: (value: unknown) => boolean | string
|
|
12
|
+
sanitize?: boolean
|
|
13
|
+
transform?: (value: unknown) => unknown
|
|
14
|
+
}
|
|
15
|
+
export declare interface ValidationSchema {
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
export declare interface InputValidationOptions {
|
|
19
|
+
enabled?: boolean
|
|
20
|
+
schemas?: {
|
|
21
|
+
query?: ValidationSchema
|
|
22
|
+
body?: ValidationSchema
|
|
23
|
+
headers?: ValidationSchema
|
|
24
|
+
params?: ValidationSchema
|
|
25
|
+
}
|
|
26
|
+
sanitizeByDefault?: boolean
|
|
27
|
+
strictMode?: boolean
|
|
28
|
+
allowUnknownFields?: boolean
|
|
29
|
+
maxDepth?: number
|
|
30
|
+
onValidationError?: (errors: ValidationError[]) => Response
|
|
31
|
+
}
|
|
32
|
+
export declare interface ValidationError {
|
|
33
|
+
field: string
|
|
34
|
+
message: string
|
|
35
|
+
value: any
|
|
36
|
+
rule: string
|
|
37
|
+
}
|
|
38
|
+
export declare class InputValidation {
|
|
39
|
+
private options: InputValidationOptions;
|
|
40
|
+
constructor(options?: InputValidationOptions);
|
|
41
|
+
private validateValue(value: any, rule: ValidationRule, fieldPath: string): ValidationError[];
|
|
42
|
+
private sanitizeValue(value: any, rule: ValidationRule): any;
|
|
43
|
+
private validateObject(obj: any, schema: ValidationSchema, basePath?: any, depth?: any): ValidationError[];
|
|
44
|
+
private parseRequestBody(req: EnhancedRequest): Promise<any>;
|
|
45
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
+
import type { PerformanceMetrics } from './performance_monitor';
|
|
3
|
+
// Factory function for easy use
|
|
4
|
+
export declare function performanceAlerting(options?: AlertingOptions): PerformanceAlerting;
|
|
5
|
+
export declare interface AlertRule {
|
|
6
|
+
id: string
|
|
7
|
+
name: string
|
|
8
|
+
description?: string
|
|
9
|
+
enabled: boolean
|
|
10
|
+
metric: 'responseTime' | 'errorRate' | 'memoryUsage' | 'cpuUsage' | 'requestRate' | 'custom'
|
|
11
|
+
condition: 'gt' | 'lt' | 'eq' | 'gte' | 'lte'
|
|
12
|
+
threshold: number
|
|
13
|
+
duration?: number
|
|
14
|
+
severity: 'info' | 'warning' | 'critical'
|
|
15
|
+
cooldown?: number
|
|
16
|
+
customEvaluator?: (metrics: PerformanceMetrics[]) => boolean
|
|
17
|
+
}
|
|
18
|
+
export declare interface AlertNotification {
|
|
19
|
+
id: string
|
|
20
|
+
ruleId: string
|
|
21
|
+
ruleName: string
|
|
22
|
+
severity: 'info' | 'warning' | 'critical'
|
|
23
|
+
message: string
|
|
24
|
+
timestamp: number
|
|
25
|
+
resolved: boolean
|
|
26
|
+
resolvedAt?: number
|
|
27
|
+
metadata: Record<string, any>
|
|
28
|
+
}
|
|
29
|
+
export declare interface AlertChannel {
|
|
30
|
+
type: 'webhook' | 'slack' | 'email' | 'console' | 'custom'
|
|
31
|
+
enabled: boolean
|
|
32
|
+
config: {
|
|
33
|
+
url?: string
|
|
34
|
+
token?: string
|
|
35
|
+
channel?: string
|
|
36
|
+
email?: string
|
|
37
|
+
customHandler?: (notification: AlertNotification) => Promise<void>
|
|
38
|
+
}
|
|
39
|
+
filters?: {
|
|
40
|
+
severities?: Array<'info' | 'warning' | 'critical'>
|
|
41
|
+
rules?: string[]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export declare interface AlertingOptions {
|
|
45
|
+
enabled?: boolean
|
|
46
|
+
rules?: AlertRule[]
|
|
47
|
+
channels?: AlertChannel[]
|
|
48
|
+
defaultCooldown?: number
|
|
49
|
+
maxAlerts?: number
|
|
50
|
+
autoResolve?: boolean
|
|
51
|
+
autoResolveTimeout?: number
|
|
52
|
+
}
|
|
53
|
+
export declare class PerformanceAlerting {
|
|
54
|
+
private options: AlertingOptions;
|
|
55
|
+
private rules: Map<string, AlertRule>;
|
|
56
|
+
private channels: AlertChannel[];
|
|
57
|
+
private notifications: AlertNotification[];
|
|
58
|
+
private lastAlertTimes: Map<string, number>;
|
|
59
|
+
private metricsBuffer: PerformanceMetrics[];
|
|
60
|
+
private checkInterval?: Timer;
|
|
61
|
+
constructor(options?: AlertingOptions);
|
|
62
|
+
private addDefaultRules(): void;
|
|
63
|
+
private startAlertingEngine(): void;
|
|
64
|
+
private evaluateRules(): void;
|
|
65
|
+
private extractMetricValues(metrics: PerformanceMetrics[], metricType: string): number[];
|
|
66
|
+
private evaluateCondition(value: number, condition: string, threshold: number): boolean;
|
|
67
|
+
private triggerAlert(rule: AlertRule, value: any, metrics: PerformanceMetrics[]): Promise<void>;
|
|
68
|
+
private formatAlertMessage(rule: AlertRule, value: any, metrics: PerformanceMetrics[]): string;
|
|
69
|
+
private sendNotification(channel: AlertChannel, notification: AlertNotification): Promise<void>;
|
|
70
|
+
private sendConsoleNotification(notification: AlertNotification): void;
|
|
71
|
+
private sendWebhookNotification(channel: AlertChannel, notification: AlertNotification): Promise<void>;
|
|
72
|
+
private sendSlackNotification(channel: AlertChannel, notification: AlertNotification): Promise<void>;
|
|
73
|
+
private sendEmailNotification(channel: AlertChannel, notification: AlertNotification): Promise<void>;
|
|
74
|
+
private cleanupOldNotifications(): void;
|
|
75
|
+
private autoResolveAlerts(): void;
|
|
76
|
+
private generateId(): string;
|
|
77
|
+
addMetrics(metrics: PerformanceMetrics): void;
|
|
78
|
+
addRule(rule: AlertRule): void;
|
|
79
|
+
removeRule(ruleId: string): void;
|
|
80
|
+
updateRule(ruleId: string, updates: Partial<AlertRule>): void;
|
|
81
|
+
addChannel(channel: AlertChannel): void;
|
|
82
|
+
removeChannel(index: number): void;
|
|
83
|
+
getActiveAlerts(): AlertNotification[];
|
|
84
|
+
getAllNotifications(): AlertNotification[];
|
|
85
|
+
resolveAlert(alertId: string): void;
|
|
86
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
+
import type { TraceSpan } from './request_tracer';
|
|
3
|
+
// Factory function for easy use
|
|
4
|
+
export declare function performanceDashboard(options?: DashboardOptions): (req: EnhancedRequest, next: NextFunction) => Promise<Response | null>;
|
|
5
|
+
export declare interface DashboardOptions {
|
|
6
|
+
enabled?: boolean
|
|
7
|
+
path?: string
|
|
8
|
+
title?: string
|
|
9
|
+
refreshInterval?: number
|
|
10
|
+
maxMetrics?: number
|
|
11
|
+
authentication?: {
|
|
12
|
+
enabled?: boolean
|
|
13
|
+
username?: string
|
|
14
|
+
password?: string
|
|
15
|
+
apiKey?: string
|
|
16
|
+
}
|
|
17
|
+
features?: {
|
|
18
|
+
realTimeMetrics?: boolean
|
|
19
|
+
historicalCharts?: boolean
|
|
20
|
+
alertsPanel?: boolean
|
|
21
|
+
tracingView?: boolean
|
|
22
|
+
systemMetrics?: boolean
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare interface DashboardData {
|
|
26
|
+
metrics: {
|
|
27
|
+
current: {
|
|
28
|
+
totalRequests: number
|
|
29
|
+
averageResponseTime: number
|
|
30
|
+
errorRate: number
|
|
31
|
+
requestsPerSecond: number
|
|
32
|
+
memoryUsage: number
|
|
33
|
+
cpuUsage: number
|
|
34
|
+
}
|
|
35
|
+
historical: Array<{
|
|
36
|
+
timestamp: number
|
|
37
|
+
responseTime: number
|
|
38
|
+
memoryUsage: number
|
|
39
|
+
requestCount: number
|
|
40
|
+
errorCount: number
|
|
41
|
+
}>
|
|
42
|
+
distribution: {
|
|
43
|
+
statusCodes: Record<number, number>
|
|
44
|
+
paths: Record<string, number>
|
|
45
|
+
methods: Record<string, number>
|
|
46
|
+
responseTimes: Array<{ range: string, count: number }>
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
alerts: Array<{
|
|
50
|
+
id: string
|
|
51
|
+
type: 'warning' | 'critical'
|
|
52
|
+
message: string
|
|
53
|
+
timestamp: number
|
|
54
|
+
resolved: boolean
|
|
55
|
+
}>
|
|
56
|
+
traces: TraceSpan[]
|
|
57
|
+
system: {
|
|
58
|
+
uptime: number
|
|
59
|
+
nodeVersion: string
|
|
60
|
+
bunVersion: string
|
|
61
|
+
platform: string
|
|
62
|
+
arch: string
|
|
63
|
+
memory: NodeJS.MemoryUsage
|
|
64
|
+
cpu: NodeJS.CpuUsage
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export declare class PerformanceDashboard {
|
|
68
|
+
private options: DashboardOptions;
|
|
69
|
+
private metricsHistory: Array<{
|
|
70
|
+
timestamp: number
|
|
71
|
+
responseTime: number
|
|
72
|
+
memoryUsage: number
|
|
73
|
+
requestCount: number
|
|
74
|
+
errorCount: number
|
|
75
|
+
}>;
|
|
76
|
+
private alerts: Array<{
|
|
77
|
+
id: string
|
|
78
|
+
type: 'warning' | 'critical'
|
|
79
|
+
message: string
|
|
80
|
+
timestamp: number
|
|
81
|
+
resolved: boolean
|
|
82
|
+
}>;
|
|
83
|
+
private startTime: number;
|
|
84
|
+
constructor(options?: DashboardOptions);
|
|
85
|
+
private isAuthenticated(req: EnhancedRequest): boolean;
|
|
86
|
+
private generateDashboardHTML(data: DashboardData): string;
|
|
87
|
+
private getDashboardData(performanceMonitor?: any, requestTracer?: any): Promise<DashboardData>;
|
|
88
|
+
handle(req: EnhancedRequest, next: NextFunction): Promise<Response | null>;
|
|
89
|
+
addAlert(type: 'warning' | 'critical', message: string): void;
|
|
90
|
+
resolveAlert(id: string): void;
|
|
91
|
+
updateMetricsHistory(data: {
|
|
92
|
+
responseTime: number
|
|
93
|
+
memoryUsage: number
|
|
94
|
+
requestCount: number
|
|
95
|
+
errorCount: number
|
|
96
|
+
}): void;
|
|
97
|
+
}
|