@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
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IRouteConfig,
|
|
3
|
+
IRouteMatch,
|
|
4
|
+
IRouteAction,
|
|
5
|
+
IRouteTarget,
|
|
6
|
+
IRouteTls,
|
|
7
|
+
IRouteRedirect,
|
|
8
|
+
IRouteSecurity,
|
|
9
|
+
IRouteAdvanced
|
|
10
|
+
} from './models/route-types.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Basic helper function to create a route configuration
|
|
14
|
+
*/
|
|
15
|
+
export function createRoute(
|
|
16
|
+
match: IRouteMatch,
|
|
17
|
+
action: IRouteAction,
|
|
18
|
+
metadata?: {
|
|
19
|
+
name?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
priority?: number;
|
|
22
|
+
tags?: string[];
|
|
23
|
+
}
|
|
24
|
+
): IRouteConfig {
|
|
25
|
+
return {
|
|
26
|
+
match,
|
|
27
|
+
action,
|
|
28
|
+
...metadata
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a basic HTTP route configuration
|
|
34
|
+
*/
|
|
35
|
+
export function createHttpRoute(
|
|
36
|
+
options: {
|
|
37
|
+
ports?: number | number[]; // Default: 80
|
|
38
|
+
domains?: string | string[];
|
|
39
|
+
path?: string;
|
|
40
|
+
target: IRouteTarget;
|
|
41
|
+
headers?: Record<string, string>;
|
|
42
|
+
security?: IRouteSecurity;
|
|
43
|
+
name?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
priority?: number;
|
|
46
|
+
tags?: string[];
|
|
47
|
+
}
|
|
48
|
+
): IRouteConfig {
|
|
49
|
+
return createRoute(
|
|
50
|
+
{
|
|
51
|
+
ports: options.ports || 80,
|
|
52
|
+
...(options.domains ? { domains: options.domains } : {}),
|
|
53
|
+
...(options.path ? { path: options.path } : {})
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'forward',
|
|
57
|
+
target: options.target,
|
|
58
|
+
...(options.headers || options.security ? {
|
|
59
|
+
advanced: {
|
|
60
|
+
...(options.headers ? { headers: options.headers } : {})
|
|
61
|
+
},
|
|
62
|
+
...(options.security ? { security: options.security } : {})
|
|
63
|
+
} : {})
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: options.name || 'HTTP Route',
|
|
67
|
+
description: options.description,
|
|
68
|
+
priority: options.priority,
|
|
69
|
+
tags: options.tags
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create an HTTPS route configuration with TLS termination
|
|
76
|
+
*/
|
|
77
|
+
export function createHttpsRoute(
|
|
78
|
+
options: {
|
|
79
|
+
ports?: number | number[]; // Default: 443
|
|
80
|
+
domains: string | string[];
|
|
81
|
+
path?: string;
|
|
82
|
+
target: IRouteTarget;
|
|
83
|
+
tlsMode?: 'terminate' | 'terminate-and-reencrypt';
|
|
84
|
+
certificate?: 'auto' | { key: string; cert: string };
|
|
85
|
+
headers?: Record<string, string>;
|
|
86
|
+
security?: IRouteSecurity;
|
|
87
|
+
name?: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
priority?: number;
|
|
90
|
+
tags?: string[];
|
|
91
|
+
}
|
|
92
|
+
): IRouteConfig {
|
|
93
|
+
return createRoute(
|
|
94
|
+
{
|
|
95
|
+
ports: options.ports || 443,
|
|
96
|
+
domains: options.domains,
|
|
97
|
+
...(options.path ? { path: options.path } : {})
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: 'forward',
|
|
101
|
+
target: options.target,
|
|
102
|
+
tls: {
|
|
103
|
+
mode: options.tlsMode || 'terminate',
|
|
104
|
+
certificate: options.certificate || 'auto'
|
|
105
|
+
},
|
|
106
|
+
...(options.headers || options.security ? {
|
|
107
|
+
advanced: {
|
|
108
|
+
...(options.headers ? { headers: options.headers } : {})
|
|
109
|
+
},
|
|
110
|
+
...(options.security ? { security: options.security } : {})
|
|
111
|
+
} : {})
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: options.name || 'HTTPS Route',
|
|
115
|
+
description: options.description,
|
|
116
|
+
priority: options.priority,
|
|
117
|
+
tags: options.tags
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Create an HTTPS passthrough route configuration
|
|
124
|
+
*/
|
|
125
|
+
export function createPassthroughRoute(
|
|
126
|
+
options: {
|
|
127
|
+
ports?: number | number[]; // Default: 443
|
|
128
|
+
domains?: string | string[];
|
|
129
|
+
target: IRouteTarget;
|
|
130
|
+
security?: IRouteSecurity;
|
|
131
|
+
name?: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
priority?: number;
|
|
134
|
+
tags?: string[];
|
|
135
|
+
}
|
|
136
|
+
): IRouteConfig {
|
|
137
|
+
return createRoute(
|
|
138
|
+
{
|
|
139
|
+
ports: options.ports || 443,
|
|
140
|
+
...(options.domains ? { domains: options.domains } : {})
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: 'forward',
|
|
144
|
+
target: options.target,
|
|
145
|
+
tls: {
|
|
146
|
+
mode: 'passthrough'
|
|
147
|
+
},
|
|
148
|
+
...(options.security ? { security: options.security } : {})
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: options.name || 'HTTPS Passthrough Route',
|
|
152
|
+
description: options.description,
|
|
153
|
+
priority: options.priority,
|
|
154
|
+
tags: options.tags
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Create a redirect route configuration
|
|
161
|
+
*/
|
|
162
|
+
export function createRedirectRoute(
|
|
163
|
+
options: {
|
|
164
|
+
ports?: number | number[]; // Default: 80
|
|
165
|
+
domains?: string | string[];
|
|
166
|
+
path?: string;
|
|
167
|
+
redirectTo: string;
|
|
168
|
+
statusCode?: 301 | 302 | 307 | 308;
|
|
169
|
+
name?: string;
|
|
170
|
+
description?: string;
|
|
171
|
+
priority?: number;
|
|
172
|
+
tags?: string[];
|
|
173
|
+
}
|
|
174
|
+
): IRouteConfig {
|
|
175
|
+
return createRoute(
|
|
176
|
+
{
|
|
177
|
+
ports: options.ports || 80,
|
|
178
|
+
...(options.domains ? { domains: options.domains } : {}),
|
|
179
|
+
...(options.path ? { path: options.path } : {})
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: 'redirect',
|
|
183
|
+
redirect: {
|
|
184
|
+
to: options.redirectTo,
|
|
185
|
+
status: options.statusCode || 301
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: options.name || 'Redirect Route',
|
|
190
|
+
description: options.description,
|
|
191
|
+
priority: options.priority,
|
|
192
|
+
tags: options.tags
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Create an HTTP to HTTPS redirect route configuration
|
|
199
|
+
*/
|
|
200
|
+
export function createHttpToHttpsRedirect(
|
|
201
|
+
options: {
|
|
202
|
+
domains: string | string[];
|
|
203
|
+
statusCode?: 301 | 302 | 307 | 308;
|
|
204
|
+
name?: string;
|
|
205
|
+
priority?: number;
|
|
206
|
+
}
|
|
207
|
+
): IRouteConfig {
|
|
208
|
+
const domainArray = Array.isArray(options.domains) ? options.domains : [options.domains];
|
|
209
|
+
|
|
210
|
+
return createRedirectRoute({
|
|
211
|
+
ports: 80,
|
|
212
|
+
domains: options.domains,
|
|
213
|
+
redirectTo: 'https://{domain}{path}',
|
|
214
|
+
statusCode: options.statusCode || 301,
|
|
215
|
+
name: options.name || `HTTP to HTTPS Redirect for ${domainArray.join(', ')}`,
|
|
216
|
+
priority: options.priority || 100 // High priority for redirects
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Create a block route configuration
|
|
222
|
+
*/
|
|
223
|
+
export function createBlockRoute(
|
|
224
|
+
options: {
|
|
225
|
+
ports: number | number[];
|
|
226
|
+
domains?: string | string[];
|
|
227
|
+
clientIp?: string[];
|
|
228
|
+
name?: string;
|
|
229
|
+
description?: string;
|
|
230
|
+
priority?: number;
|
|
231
|
+
tags?: string[];
|
|
232
|
+
}
|
|
233
|
+
): IRouteConfig {
|
|
234
|
+
return createRoute(
|
|
235
|
+
{
|
|
236
|
+
ports: options.ports,
|
|
237
|
+
...(options.domains ? { domains: options.domains } : {}),
|
|
238
|
+
...(options.clientIp ? { clientIp: options.clientIp } : {})
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
type: 'block'
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: options.name || 'Block Route',
|
|
245
|
+
description: options.description,
|
|
246
|
+
priority: options.priority || 1000, // Very high priority for blocks
|
|
247
|
+
tags: options.tags
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Create a load balancer route configuration
|
|
254
|
+
*/
|
|
255
|
+
export function createLoadBalancerRoute(
|
|
256
|
+
options: {
|
|
257
|
+
ports?: number | number[]; // Default: 443
|
|
258
|
+
domains: string | string[];
|
|
259
|
+
path?: string;
|
|
260
|
+
targets: string[]; // Array of host names/IPs for load balancing
|
|
261
|
+
targetPort: number;
|
|
262
|
+
tlsMode?: 'passthrough' | 'terminate' | 'terminate-and-reencrypt';
|
|
263
|
+
certificate?: 'auto' | { key: string; cert: string };
|
|
264
|
+
headers?: Record<string, string>;
|
|
265
|
+
security?: IRouteSecurity;
|
|
266
|
+
name?: string;
|
|
267
|
+
description?: string;
|
|
268
|
+
tags?: string[];
|
|
269
|
+
}
|
|
270
|
+
): IRouteConfig {
|
|
271
|
+
const useTls = options.tlsMode !== undefined;
|
|
272
|
+
const defaultPort = useTls ? 443 : 80;
|
|
273
|
+
|
|
274
|
+
return createRoute(
|
|
275
|
+
{
|
|
276
|
+
ports: options.ports || defaultPort,
|
|
277
|
+
domains: options.domains,
|
|
278
|
+
...(options.path ? { path: options.path } : {})
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
type: 'forward',
|
|
282
|
+
target: {
|
|
283
|
+
host: options.targets,
|
|
284
|
+
port: options.targetPort
|
|
285
|
+
},
|
|
286
|
+
...(useTls ? {
|
|
287
|
+
tls: {
|
|
288
|
+
mode: options.tlsMode!,
|
|
289
|
+
...(options.tlsMode !== 'passthrough' && options.certificate ? {
|
|
290
|
+
certificate: options.certificate
|
|
291
|
+
} : {})
|
|
292
|
+
}
|
|
293
|
+
} : {}),
|
|
294
|
+
...(options.headers || options.security ? {
|
|
295
|
+
advanced: {
|
|
296
|
+
...(options.headers ? { headers: options.headers } : {})
|
|
297
|
+
},
|
|
298
|
+
...(options.security ? { security: options.security } : {})
|
|
299
|
+
} : {})
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: options.name || 'Load Balanced Route',
|
|
303
|
+
description: options.description || `Load balancing across ${options.targets.length} backends`,
|
|
304
|
+
tags: options.tags
|
|
305
|
+
}
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Create a complete HTTPS server configuration with HTTP redirect
|
|
311
|
+
*/
|
|
312
|
+
export function createHttpsServer(
|
|
313
|
+
options: {
|
|
314
|
+
domains: string | string[];
|
|
315
|
+
target: IRouteTarget;
|
|
316
|
+
certificate?: 'auto' | { key: string; cert: string };
|
|
317
|
+
security?: IRouteSecurity;
|
|
318
|
+
addHttpRedirect?: boolean;
|
|
319
|
+
name?: string;
|
|
320
|
+
}
|
|
321
|
+
): IRouteConfig[] {
|
|
322
|
+
const routes: IRouteConfig[] = [];
|
|
323
|
+
const domainArray = Array.isArray(options.domains) ? options.domains : [options.domains];
|
|
324
|
+
|
|
325
|
+
// Add HTTPS route
|
|
326
|
+
routes.push(createHttpsRoute({
|
|
327
|
+
domains: options.domains,
|
|
328
|
+
target: options.target,
|
|
329
|
+
certificate: options.certificate || 'auto',
|
|
330
|
+
security: options.security,
|
|
331
|
+
name: options.name || `HTTPS Server for ${domainArray.join(', ')}`
|
|
332
|
+
}));
|
|
333
|
+
|
|
334
|
+
// Add HTTP to HTTPS redirect if requested
|
|
335
|
+
if (options.addHttpRedirect !== false) {
|
|
336
|
+
routes.push(createHttpToHttpsRedirect({
|
|
337
|
+
domains: options.domains,
|
|
338
|
+
name: `HTTP to HTTPS Redirect for ${domainArray.join(', ')}`,
|
|
339
|
+
priority: 100
|
|
340
|
+
}));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return routes;
|
|
344
|
+
}
|