@push.rocks/smartproxy 10.2.0 → 12.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 +1 -1
- package/dist_ts/common/port80-adapter.d.ts +11 -0
- package/dist_ts/common/port80-adapter.js +61 -0
- package/dist_ts/examples/forwarding-example.d.ts +1 -0
- package/dist_ts/examples/forwarding-example.js +96 -0
- package/dist_ts/index.d.ts +1 -0
- package/dist_ts/index.js +3 -1
- package/dist_ts/smartproxy/classes.pp.connectionhandler.js +179 -30
- package/dist_ts/smartproxy/classes.pp.domainconfigmanager.d.ts +39 -0
- package/dist_ts/smartproxy/classes.pp.domainconfigmanager.js +172 -20
- package/dist_ts/smartproxy/classes.pp.interfaces.d.ts +3 -11
- package/dist_ts/smartproxy/classes.pp.portrangemanager.js +17 -10
- package/dist_ts/smartproxy/classes.pp.securitymanager.d.ts +19 -2
- package/dist_ts/smartproxy/classes.pp.securitymanager.js +27 -4
- package/dist_ts/smartproxy/classes.pp.timeoutmanager.js +3 -3
- package/dist_ts/smartproxy/classes.smartproxy.js +45 -13
- package/dist_ts/smartproxy/forwarding/domain-config.d.ts +12 -0
- package/dist_ts/smartproxy/forwarding/domain-config.js +12 -0
- package/dist_ts/smartproxy/forwarding/domain-manager.d.ts +86 -0
- package/dist_ts/smartproxy/forwarding/domain-manager.js +241 -0
- package/dist_ts/smartproxy/forwarding/forwarding.factory.d.ts +24 -0
- package/dist_ts/smartproxy/forwarding/forwarding.factory.js +137 -0
- package/dist_ts/smartproxy/forwarding/forwarding.handler.d.ts +55 -0
- package/dist_ts/smartproxy/forwarding/forwarding.handler.js +94 -0
- package/dist_ts/smartproxy/forwarding/http.handler.d.ts +25 -0
- package/dist_ts/smartproxy/forwarding/http.handler.js +123 -0
- package/dist_ts/smartproxy/forwarding/https-passthrough.handler.d.ts +24 -0
- package/dist_ts/smartproxy/forwarding/https-passthrough.handler.js +154 -0
- package/dist_ts/smartproxy/forwarding/https-terminate-to-http.handler.d.ts +36 -0
- package/dist_ts/smartproxy/forwarding/https-terminate-to-http.handler.js +229 -0
- package/dist_ts/smartproxy/forwarding/https-terminate-to-https.handler.d.ts +35 -0
- package/dist_ts/smartproxy/forwarding/https-terminate-to-https.handler.js +254 -0
- package/dist_ts/smartproxy/forwarding/index.d.ts +16 -0
- package/dist_ts/smartproxy/forwarding/index.js +23 -0
- package/dist_ts/smartproxy/types/forwarding.types.d.ts +104 -0
- package/dist_ts/smartproxy/types/forwarding.types.js +50 -0
- package/package.json +2 -2
- package/readme.md +158 -8
- package/readme.plan.md +471 -42
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/common/port80-adapter.ts +87 -0
- package/ts/index.ts +3 -0
- package/ts/smartproxy/classes.pp.connectionhandler.ts +231 -44
- package/ts/smartproxy/classes.pp.domainconfigmanager.ts +198 -24
- package/ts/smartproxy/classes.pp.interfaces.ts +3 -11
- package/ts/smartproxy/classes.pp.portrangemanager.ts +17 -10
- package/ts/smartproxy/classes.pp.securitymanager.ts +29 -5
- package/ts/smartproxy/classes.pp.timeoutmanager.ts +3 -3
- package/ts/smartproxy/classes.smartproxy.ts +68 -15
- package/ts/smartproxy/forwarding/domain-config.ts +28 -0
- package/ts/smartproxy/forwarding/domain-manager.ts +283 -0
- package/ts/smartproxy/forwarding/forwarding.factory.ts +155 -0
- package/ts/smartproxy/forwarding/forwarding.handler.ts +127 -0
- package/ts/smartproxy/forwarding/http.handler.ts +140 -0
- package/ts/smartproxy/forwarding/https-passthrough.handler.ts +182 -0
- package/ts/smartproxy/forwarding/https-terminate-to-http.handler.ts +264 -0
- package/ts/smartproxy/forwarding/https-terminate-to-https.handler.ts +292 -0
- package/ts/smartproxy/forwarding/index.ts +52 -0
- package/ts/smartproxy/types/forwarding.types.ts +162 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type * as plugins from '../../plugins.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The primary forwarding types supported by SmartProxy
|
|
5
|
+
*/
|
|
6
|
+
export type ForwardingType =
|
|
7
|
+
| 'http-only' // HTTP forwarding only (no HTTPS)
|
|
8
|
+
| 'https-passthrough' // Pass-through TLS traffic (SNI forwarding)
|
|
9
|
+
| 'https-terminate-to-http' // Terminate TLS and forward to HTTP backend
|
|
10
|
+
| 'https-terminate-to-https'; // Terminate TLS and forward to HTTPS backend
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Target configuration for forwarding
|
|
14
|
+
*/
|
|
15
|
+
export interface ITargetConfig {
|
|
16
|
+
host: string | string[]; // Support single host or round-robin
|
|
17
|
+
port: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* HTTP-specific options for forwarding
|
|
22
|
+
*/
|
|
23
|
+
export interface IHttpOptions {
|
|
24
|
+
enabled?: boolean; // Whether HTTP is enabled
|
|
25
|
+
redirectToHttps?: boolean; // Redirect HTTP to HTTPS
|
|
26
|
+
headers?: Record<string, string>; // Custom headers for HTTP responses
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* HTTPS-specific options for forwarding
|
|
31
|
+
*/
|
|
32
|
+
export interface IHttpsOptions {
|
|
33
|
+
customCert?: { // Use custom cert instead of auto-provisioned
|
|
34
|
+
key: string;
|
|
35
|
+
cert: string;
|
|
36
|
+
};
|
|
37
|
+
forwardSni?: boolean; // Forward SNI info in passthrough mode
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* ACME certificate handling options
|
|
42
|
+
*/
|
|
43
|
+
export interface IAcmeForwardingOptions {
|
|
44
|
+
enabled?: boolean; // Enable ACME certificate provisioning
|
|
45
|
+
maintenance?: boolean; // Auto-renew certificates
|
|
46
|
+
production?: boolean; // Use production ACME servers
|
|
47
|
+
forwardChallenges?: { // Forward ACME challenges
|
|
48
|
+
host: string;
|
|
49
|
+
port: number;
|
|
50
|
+
useTls?: boolean;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Security options for forwarding
|
|
56
|
+
*/
|
|
57
|
+
export interface ISecurityOptions {
|
|
58
|
+
allowedIps?: string[]; // IPs allowed to connect
|
|
59
|
+
blockedIps?: string[]; // IPs blocked from connecting
|
|
60
|
+
maxConnections?: number; // Max simultaneous connections
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Advanced options for forwarding
|
|
65
|
+
*/
|
|
66
|
+
export interface IAdvancedOptions {
|
|
67
|
+
portRanges?: Array<{ from: number; to: number }>; // Allowed port ranges
|
|
68
|
+
networkProxyPort?: number; // Custom NetworkProxy port if using terminate mode
|
|
69
|
+
keepAlive?: boolean; // Enable TCP keepalive
|
|
70
|
+
timeout?: number; // Connection timeout in ms
|
|
71
|
+
headers?: Record<string, string>; // Custom headers with support for variables like {sni}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Unified forwarding configuration interface
|
|
76
|
+
*/
|
|
77
|
+
export interface IForwardConfig {
|
|
78
|
+
// Define the primary forwarding type - use-case driven approach
|
|
79
|
+
type: ForwardingType;
|
|
80
|
+
|
|
81
|
+
// Target configuration
|
|
82
|
+
target: ITargetConfig;
|
|
83
|
+
|
|
84
|
+
// Protocol options
|
|
85
|
+
http?: IHttpOptions;
|
|
86
|
+
https?: IHttpsOptions;
|
|
87
|
+
acme?: IAcmeForwardingOptions;
|
|
88
|
+
|
|
89
|
+
// Security and advanced options
|
|
90
|
+
security?: ISecurityOptions;
|
|
91
|
+
advanced?: IAdvancedOptions;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Event types emitted by forwarding handlers
|
|
96
|
+
*/
|
|
97
|
+
export enum ForwardingHandlerEvents {
|
|
98
|
+
CONNECTED = 'connected',
|
|
99
|
+
DISCONNECTED = 'disconnected',
|
|
100
|
+
ERROR = 'error',
|
|
101
|
+
DATA_FORWARDED = 'data-forwarded',
|
|
102
|
+
HTTP_REQUEST = 'http-request',
|
|
103
|
+
HTTP_RESPONSE = 'http-response',
|
|
104
|
+
CERTIFICATE_NEEDED = 'certificate-needed',
|
|
105
|
+
CERTIFICATE_LOADED = 'certificate-loaded'
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Base interface for forwarding handlers
|
|
110
|
+
*/
|
|
111
|
+
export interface IForwardingHandler extends plugins.EventEmitter {
|
|
112
|
+
initialize(): Promise<void>;
|
|
113
|
+
handleConnection(socket: plugins.net.Socket): void;
|
|
114
|
+
handleHttpRequest(req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse): void;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Helper function types for common forwarding patterns
|
|
119
|
+
*/
|
|
120
|
+
export const httpOnly = (
|
|
121
|
+
partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, 'target'>
|
|
122
|
+
): IForwardConfig => ({
|
|
123
|
+
type: 'http-only',
|
|
124
|
+
target: partialConfig.target,
|
|
125
|
+
http: { enabled: true, ...(partialConfig.http || {}) },
|
|
126
|
+
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
127
|
+
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export const tlsTerminateToHttp = (
|
|
131
|
+
partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, 'target'>
|
|
132
|
+
): IForwardConfig => ({
|
|
133
|
+
type: 'https-terminate-to-http',
|
|
134
|
+
target: partialConfig.target,
|
|
135
|
+
https: { ...(partialConfig.https || {}) },
|
|
136
|
+
acme: { enabled: true, maintenance: true, ...(partialConfig.acme || {}) },
|
|
137
|
+
http: { enabled: true, redirectToHttps: true, ...(partialConfig.http || {}) },
|
|
138
|
+
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
139
|
+
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export const tlsTerminateToHttps = (
|
|
143
|
+
partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, 'target'>
|
|
144
|
+
): IForwardConfig => ({
|
|
145
|
+
type: 'https-terminate-to-https',
|
|
146
|
+
target: partialConfig.target,
|
|
147
|
+
https: { ...(partialConfig.https || {}) },
|
|
148
|
+
acme: { enabled: true, maintenance: true, ...(partialConfig.acme || {}) },
|
|
149
|
+
http: { enabled: true, redirectToHttps: true, ...(partialConfig.http || {}) },
|
|
150
|
+
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
151
|
+
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export const httpsPassthrough = (
|
|
155
|
+
partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, 'target'>
|
|
156
|
+
): IForwardConfig => ({
|
|
157
|
+
type: 'https-passthrough',
|
|
158
|
+
target: partialConfig.target,
|
|
159
|
+
https: { forwardSni: true, ...(partialConfig.https || {}) },
|
|
160
|
+
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
161
|
+
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
162
|
+
});
|