@push.rocks/smartproxy 13.1.2 → 15.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.
- package/dist_ts/00_commitinfo_data.js +3 -3
- package/dist_ts/proxies/smart-proxy/index.d.ts +5 -3
- package/dist_ts/proxies/smart-proxy/index.js +9 -5
- package/dist_ts/proxies/smart-proxy/models/index.d.ts +2 -0
- package/dist_ts/proxies/smart-proxy/models/index.js +2 -1
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +82 -15
- package/dist_ts/proxies/smart-proxy/models/interfaces.js +10 -1
- package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +133 -0
- package/dist_ts/proxies/smart-proxy/models/route-types.js +2 -0
- package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +55 -0
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +804 -0
- package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +127 -0
- package/dist_ts/proxies/smart-proxy/route-helpers.js +196 -0
- package/dist_ts/proxies/smart-proxy/route-manager.d.ts +103 -0
- package/dist_ts/proxies/smart-proxy/route-manager.js +483 -0
- package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +19 -8
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +239 -46
- package/package.json +2 -2
- package/readme.md +863 -423
- package/readme.plan.md +311 -250
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/proxies/smart-proxy/index.ts +20 -4
- package/ts/proxies/smart-proxy/models/index.ts +4 -0
- package/ts/proxies/smart-proxy/models/interfaces.ts +91 -13
- package/ts/proxies/smart-proxy/models/route-types.ts +184 -0
- package/ts/proxies/smart-proxy/route-connection-handler.ts +1117 -0
- package/ts/proxies/smart-proxy/route-helpers.ts +344 -0
- package/ts/proxies/smart-proxy/route-manager.ts +587 -0
- package/ts/proxies/smart-proxy/smart-proxy.ts +300 -69
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as plugins from '../../../plugins.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IAcmeOptions } from '../../../certificate/models/certificate-types.js';
|
|
3
|
+
import type { IRouteConfig } from './route-types.js';
|
|
4
|
+
import type { TForwardingType } from '../../../forwarding/config/forwarding-types.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Provision object for static or HTTP-01 certificate
|
|
@@ -7,27 +9,102 @@ import type { IForwardConfig } from '../../../forwarding/config/forwarding-types
|
|
|
7
9
|
export type TSmartProxyCertProvisionObject = plugins.tsclass.network.ICert | 'http01';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
12
|
+
* Alias for backward compatibility with code that uses IRoutedSmartProxyOptions
|
|
13
|
+
*/
|
|
14
|
+
export type IRoutedSmartProxyOptions = ISmartProxyOptions;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Legacy domain configuration interface for backward compatibility
|
|
11
18
|
*/
|
|
12
19
|
export interface IDomainConfig {
|
|
13
|
-
domains: string[];
|
|
14
|
-
forwarding:
|
|
20
|
+
domains: string[];
|
|
21
|
+
forwarding: {
|
|
22
|
+
type: TForwardingType;
|
|
23
|
+
target: {
|
|
24
|
+
host: string | string[];
|
|
25
|
+
port: number;
|
|
26
|
+
};
|
|
27
|
+
acme?: {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
maintenance?: boolean;
|
|
30
|
+
production?: boolean;
|
|
31
|
+
forwardChallenges?: {
|
|
32
|
+
host: string;
|
|
33
|
+
port: number;
|
|
34
|
+
useTls?: boolean;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
http?: {
|
|
38
|
+
enabled?: boolean;
|
|
39
|
+
redirectToHttps?: boolean;
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
https?: {
|
|
43
|
+
customCert?: {
|
|
44
|
+
key: string;
|
|
45
|
+
cert: string;
|
|
46
|
+
};
|
|
47
|
+
forwardSni?: boolean;
|
|
48
|
+
};
|
|
49
|
+
security?: {
|
|
50
|
+
allowedIps?: string[];
|
|
51
|
+
blockedIps?: string[];
|
|
52
|
+
maxConnections?: number;
|
|
53
|
+
};
|
|
54
|
+
advanced?: {
|
|
55
|
+
portRanges?: Array<{ from: number; to: number }>;
|
|
56
|
+
networkProxyPort?: number;
|
|
57
|
+
keepAlive?: boolean;
|
|
58
|
+
timeout?: number;
|
|
59
|
+
headers?: Record<string, string>;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
15
62
|
}
|
|
16
63
|
|
|
17
64
|
/**
|
|
18
|
-
*
|
|
65
|
+
* Helper functions for type checking - now always assume route-based config
|
|
66
|
+
*/
|
|
67
|
+
export function isLegacyOptions(options: any): boolean {
|
|
68
|
+
return false; // No longer supporting legacy options
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isRoutedOptions(options: any): boolean {
|
|
72
|
+
return true; // Always assume routed options
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* SmartProxy configuration options
|
|
19
77
|
*/
|
|
20
|
-
import type { IAcmeOptions } from '../../../certificate/models/certificate-types.js';
|
|
21
78
|
export interface ISmartProxyOptions {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
79
|
+
// The unified configuration array (required)
|
|
80
|
+
routes: IRouteConfig[];
|
|
81
|
+
|
|
82
|
+
// Legacy options for backward compatibility
|
|
83
|
+
fromPort?: number;
|
|
84
|
+
toPort?: number;
|
|
26
85
|
sniEnabled?: boolean;
|
|
86
|
+
domainConfigs?: IDomainConfig[];
|
|
87
|
+
targetIP?: string;
|
|
27
88
|
defaultAllowedIPs?: string[];
|
|
28
89
|
defaultBlockedIPs?: string[];
|
|
90
|
+
globalPortRanges?: Array<{ from: number; to: number }>;
|
|
91
|
+
forwardAllGlobalRanges?: boolean;
|
|
29
92
|
preserveSourceIP?: boolean;
|
|
30
93
|
|
|
94
|
+
// Global/default settings
|
|
95
|
+
defaults?: {
|
|
96
|
+
target?: {
|
|
97
|
+
host: string; // Default host to use when not specified in routes
|
|
98
|
+
port: number; // Default port to use when not specified in routes
|
|
99
|
+
};
|
|
100
|
+
security?: {
|
|
101
|
+
allowedIPs?: string[]; // Default allowed IPs
|
|
102
|
+
blockedIPs?: string[]; // Default blocked IPs
|
|
103
|
+
maxConnections?: number; // Default max connections
|
|
104
|
+
};
|
|
105
|
+
preserveSourceIP?: boolean; // Default source IP preservation
|
|
106
|
+
};
|
|
107
|
+
|
|
31
108
|
// TLS options
|
|
32
109
|
pfx?: Buffer;
|
|
33
110
|
key?: string | Buffer | Array<Buffer | string>;
|
|
@@ -50,8 +127,6 @@ export interface ISmartProxyOptions {
|
|
|
50
127
|
inactivityTimeout?: number; // Inactivity timeout (ms), default: 14400000 (4h)
|
|
51
128
|
|
|
52
129
|
gracefulShutdownTimeout?: number; // (ms) maximum time to wait for connections to close during shutdown
|
|
53
|
-
globalPortRanges: Array<{ from: number; to: number }>; // Global allowed port ranges
|
|
54
|
-
forwardAllGlobalRanges?: boolean; // When true, forwards all connections on global port ranges to the global targetIP
|
|
55
130
|
|
|
56
131
|
// Socket optimization settings
|
|
57
132
|
noDelay?: boolean; // Disable Nagle's algorithm (default: true)
|
|
@@ -108,6 +183,9 @@ export interface IConnectionRecord {
|
|
|
108
183
|
pendingData: Buffer[]; // Buffer to hold data during connection setup
|
|
109
184
|
pendingDataSize: number; // Track total size of pending data
|
|
110
185
|
|
|
186
|
+
// Legacy property for backward compatibility
|
|
187
|
+
domainConfig?: IDomainConfig;
|
|
188
|
+
|
|
111
189
|
// Enhanced tracking fields
|
|
112
190
|
bytesReceived: number; // Total bytes received
|
|
113
191
|
bytesSent: number; // Total bytes sent
|
|
@@ -116,7 +194,7 @@ export interface IConnectionRecord {
|
|
|
116
194
|
isTLS: boolean; // Whether this connection is a TLS connection
|
|
117
195
|
tlsHandshakeComplete: boolean; // Whether the TLS handshake is complete
|
|
118
196
|
hasReceivedInitialData: boolean; // Whether initial data has been received
|
|
119
|
-
|
|
197
|
+
routeConfig?: IRouteConfig; // Associated route config for this connection
|
|
120
198
|
|
|
121
199
|
// Keep-alive tracking
|
|
122
200
|
hasKeepAlive: boolean; // Whether keep-alive is enabled for this connection
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import * as plugins from '../../../plugins.js';
|
|
2
|
+
import type { IAcmeOptions } from '../../../certificate/models/certificate-types.js';
|
|
3
|
+
import type { TForwardingType } from '../../../forwarding/config/forwarding-types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Supported action types for route configurations
|
|
7
|
+
*/
|
|
8
|
+
export type TRouteActionType = 'forward' | 'redirect' | 'block';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* TLS handling modes for route configurations
|
|
12
|
+
*/
|
|
13
|
+
export type TTlsMode = 'passthrough' | 'terminate' | 'terminate-and-reencrypt';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Port range specification format
|
|
17
|
+
*/
|
|
18
|
+
export type TPortRange = number | number[] | Array<{ from: number; to: number }>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Route match criteria for incoming requests
|
|
22
|
+
*/
|
|
23
|
+
export interface IRouteMatch {
|
|
24
|
+
// Listen on these ports (required)
|
|
25
|
+
ports: TPortRange;
|
|
26
|
+
|
|
27
|
+
// Optional domain patterns to match (default: all domains)
|
|
28
|
+
domains?: string | string[];
|
|
29
|
+
|
|
30
|
+
// Advanced matching criteria
|
|
31
|
+
path?: string; // Match specific paths
|
|
32
|
+
clientIp?: string[]; // Match specific client IPs
|
|
33
|
+
tlsVersion?: string[]; // Match specific TLS versions
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Target configuration for forwarding
|
|
38
|
+
*/
|
|
39
|
+
export interface IRouteTarget {
|
|
40
|
+
host: string | string[]; // Support single host or round-robin
|
|
41
|
+
port: number;
|
|
42
|
+
preservePort?: boolean; // Use incoming port as target port
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* TLS configuration for route actions
|
|
47
|
+
*/
|
|
48
|
+
export interface IRouteTls {
|
|
49
|
+
mode: TTlsMode;
|
|
50
|
+
certificate?: 'auto' | { // Auto = use ACME
|
|
51
|
+
key: string;
|
|
52
|
+
cert: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Redirect configuration for route actions
|
|
58
|
+
*/
|
|
59
|
+
export interface IRouteRedirect {
|
|
60
|
+
to: string; // URL or template with {domain}, {port}, etc.
|
|
61
|
+
status: 301 | 302 | 307 | 308;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Security options for route actions
|
|
66
|
+
*/
|
|
67
|
+
export interface IRouteSecurity {
|
|
68
|
+
allowedIps?: string[];
|
|
69
|
+
blockedIps?: string[];
|
|
70
|
+
maxConnections?: number;
|
|
71
|
+
authentication?: {
|
|
72
|
+
type: 'basic' | 'digest' | 'oauth';
|
|
73
|
+
// Auth-specific options would go here
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Advanced options for route actions
|
|
79
|
+
*/
|
|
80
|
+
export interface IRouteAdvanced {
|
|
81
|
+
timeout?: number;
|
|
82
|
+
headers?: Record<string, string>;
|
|
83
|
+
keepAlive?: boolean;
|
|
84
|
+
// Additional advanced options would go here
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Action configuration for route handling
|
|
89
|
+
*/
|
|
90
|
+
export interface IRouteAction {
|
|
91
|
+
// Basic routing
|
|
92
|
+
type: TRouteActionType;
|
|
93
|
+
|
|
94
|
+
// Target for forwarding
|
|
95
|
+
target?: IRouteTarget;
|
|
96
|
+
|
|
97
|
+
// TLS handling
|
|
98
|
+
tls?: IRouteTls;
|
|
99
|
+
|
|
100
|
+
// For redirects
|
|
101
|
+
redirect?: IRouteRedirect;
|
|
102
|
+
|
|
103
|
+
// Security options
|
|
104
|
+
security?: IRouteSecurity;
|
|
105
|
+
|
|
106
|
+
// Advanced options
|
|
107
|
+
advanced?: IRouteAdvanced;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The core unified configuration interface
|
|
112
|
+
*/
|
|
113
|
+
export interface IRouteConfig {
|
|
114
|
+
// What to match
|
|
115
|
+
match: IRouteMatch;
|
|
116
|
+
|
|
117
|
+
// What to do with matched traffic
|
|
118
|
+
action: IRouteAction;
|
|
119
|
+
|
|
120
|
+
// Optional metadata
|
|
121
|
+
name?: string; // Human-readable name for this route
|
|
122
|
+
description?: string; // Description of the route's purpose
|
|
123
|
+
priority?: number; // Controls matching order (higher = matched first)
|
|
124
|
+
tags?: string[]; // Arbitrary tags for categorization
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Unified SmartProxy options with routes-based configuration
|
|
129
|
+
*/
|
|
130
|
+
export interface IRoutedSmartProxyOptions {
|
|
131
|
+
// The unified configuration array (required)
|
|
132
|
+
routes: IRouteConfig[];
|
|
133
|
+
|
|
134
|
+
// Global/default settings
|
|
135
|
+
defaults?: {
|
|
136
|
+
target?: {
|
|
137
|
+
host: string;
|
|
138
|
+
port: number;
|
|
139
|
+
};
|
|
140
|
+
security?: IRouteSecurity;
|
|
141
|
+
tls?: IRouteTls;
|
|
142
|
+
// ...other defaults
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Other global settings remain (acme, etc.)
|
|
146
|
+
acme?: IAcmeOptions;
|
|
147
|
+
|
|
148
|
+
// Connection timeouts and other global settings
|
|
149
|
+
initialDataTimeout?: number;
|
|
150
|
+
socketTimeout?: number;
|
|
151
|
+
inactivityCheckInterval?: number;
|
|
152
|
+
maxConnectionLifetime?: number;
|
|
153
|
+
inactivityTimeout?: number;
|
|
154
|
+
gracefulShutdownTimeout?: number;
|
|
155
|
+
|
|
156
|
+
// Socket optimization settings
|
|
157
|
+
noDelay?: boolean;
|
|
158
|
+
keepAlive?: boolean;
|
|
159
|
+
keepAliveInitialDelay?: number;
|
|
160
|
+
maxPendingDataSize?: number;
|
|
161
|
+
|
|
162
|
+
// Enhanced features
|
|
163
|
+
disableInactivityCheck?: boolean;
|
|
164
|
+
enableKeepAliveProbes?: boolean;
|
|
165
|
+
enableDetailedLogging?: boolean;
|
|
166
|
+
enableTlsDebugLogging?: boolean;
|
|
167
|
+
enableRandomizedTimeouts?: boolean;
|
|
168
|
+
allowSessionTicket?: boolean;
|
|
169
|
+
|
|
170
|
+
// Rate limiting and security
|
|
171
|
+
maxConnectionsPerIP?: number;
|
|
172
|
+
connectionRateLimitPerMinute?: number;
|
|
173
|
+
|
|
174
|
+
// Enhanced keep-alive settings
|
|
175
|
+
keepAliveTreatment?: 'standard' | 'extended' | 'immortal';
|
|
176
|
+
keepAliveInactivityMultiplier?: number;
|
|
177
|
+
extendedKeepAliveLifetime?: number;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Optional certificate provider callback. Return 'http01' to use HTTP-01 challenges,
|
|
181
|
+
* or a static certificate object for immediate provisioning.
|
|
182
|
+
*/
|
|
183
|
+
certProvisionFunction?: (domain: string) => Promise<any>;
|
|
184
|
+
}
|