@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.
Files changed (59) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/common/port80-adapter.d.ts +11 -0
  3. package/dist_ts/common/port80-adapter.js +61 -0
  4. package/dist_ts/examples/forwarding-example.d.ts +1 -0
  5. package/dist_ts/examples/forwarding-example.js +96 -0
  6. package/dist_ts/index.d.ts +1 -0
  7. package/dist_ts/index.js +3 -1
  8. package/dist_ts/smartproxy/classes.pp.connectionhandler.js +179 -30
  9. package/dist_ts/smartproxy/classes.pp.domainconfigmanager.d.ts +39 -0
  10. package/dist_ts/smartproxy/classes.pp.domainconfigmanager.js +172 -20
  11. package/dist_ts/smartproxy/classes.pp.interfaces.d.ts +3 -11
  12. package/dist_ts/smartproxy/classes.pp.portrangemanager.js +17 -10
  13. package/dist_ts/smartproxy/classes.pp.securitymanager.d.ts +19 -2
  14. package/dist_ts/smartproxy/classes.pp.securitymanager.js +27 -4
  15. package/dist_ts/smartproxy/classes.pp.timeoutmanager.js +3 -3
  16. package/dist_ts/smartproxy/classes.smartproxy.js +45 -13
  17. package/dist_ts/smartproxy/forwarding/domain-config.d.ts +12 -0
  18. package/dist_ts/smartproxy/forwarding/domain-config.js +12 -0
  19. package/dist_ts/smartproxy/forwarding/domain-manager.d.ts +86 -0
  20. package/dist_ts/smartproxy/forwarding/domain-manager.js +241 -0
  21. package/dist_ts/smartproxy/forwarding/forwarding.factory.d.ts +24 -0
  22. package/dist_ts/smartproxy/forwarding/forwarding.factory.js +137 -0
  23. package/dist_ts/smartproxy/forwarding/forwarding.handler.d.ts +55 -0
  24. package/dist_ts/smartproxy/forwarding/forwarding.handler.js +94 -0
  25. package/dist_ts/smartproxy/forwarding/http.handler.d.ts +25 -0
  26. package/dist_ts/smartproxy/forwarding/http.handler.js +123 -0
  27. package/dist_ts/smartproxy/forwarding/https-passthrough.handler.d.ts +24 -0
  28. package/dist_ts/smartproxy/forwarding/https-passthrough.handler.js +154 -0
  29. package/dist_ts/smartproxy/forwarding/https-terminate-to-http.handler.d.ts +36 -0
  30. package/dist_ts/smartproxy/forwarding/https-terminate-to-http.handler.js +229 -0
  31. package/dist_ts/smartproxy/forwarding/https-terminate-to-https.handler.d.ts +35 -0
  32. package/dist_ts/smartproxy/forwarding/https-terminate-to-https.handler.js +254 -0
  33. package/dist_ts/smartproxy/forwarding/index.d.ts +16 -0
  34. package/dist_ts/smartproxy/forwarding/index.js +23 -0
  35. package/dist_ts/smartproxy/types/forwarding.types.d.ts +104 -0
  36. package/dist_ts/smartproxy/types/forwarding.types.js +50 -0
  37. package/package.json +2 -2
  38. package/readme.md +158 -8
  39. package/readme.plan.md +471 -42
  40. package/ts/00_commitinfo_data.ts +1 -1
  41. package/ts/common/port80-adapter.ts +87 -0
  42. package/ts/index.ts +3 -0
  43. package/ts/smartproxy/classes.pp.connectionhandler.ts +231 -44
  44. package/ts/smartproxy/classes.pp.domainconfigmanager.ts +198 -24
  45. package/ts/smartproxy/classes.pp.interfaces.ts +3 -11
  46. package/ts/smartproxy/classes.pp.portrangemanager.ts +17 -10
  47. package/ts/smartproxy/classes.pp.securitymanager.ts +29 -5
  48. package/ts/smartproxy/classes.pp.timeoutmanager.ts +3 -3
  49. package/ts/smartproxy/classes.smartproxy.ts +68 -15
  50. package/ts/smartproxy/forwarding/domain-config.ts +28 -0
  51. package/ts/smartproxy/forwarding/domain-manager.ts +283 -0
  52. package/ts/smartproxy/forwarding/forwarding.factory.ts +155 -0
  53. package/ts/smartproxy/forwarding/forwarding.handler.ts +127 -0
  54. package/ts/smartproxy/forwarding/http.handler.ts +140 -0
  55. package/ts/smartproxy/forwarding/https-passthrough.handler.ts +182 -0
  56. package/ts/smartproxy/forwarding/https-terminate-to-http.handler.ts +264 -0
  57. package/ts/smartproxy/forwarding/https-terminate-to-https.handler.ts +292 -0
  58. package/ts/smartproxy/forwarding/index.ts +52 -0
  59. package/ts/smartproxy/types/forwarding.types.ts +162 -0
@@ -0,0 +1,104 @@
1
+ import type * as plugins from '../../plugins.js';
2
+ /**
3
+ * The primary forwarding types supported by SmartProxy
4
+ */
5
+ export type ForwardingType = 'http-only' | 'https-passthrough' | 'https-terminate-to-http' | 'https-terminate-to-https';
6
+ /**
7
+ * Target configuration for forwarding
8
+ */
9
+ export interface ITargetConfig {
10
+ host: string | string[];
11
+ port: number;
12
+ }
13
+ /**
14
+ * HTTP-specific options for forwarding
15
+ */
16
+ export interface IHttpOptions {
17
+ enabled?: boolean;
18
+ redirectToHttps?: boolean;
19
+ headers?: Record<string, string>;
20
+ }
21
+ /**
22
+ * HTTPS-specific options for forwarding
23
+ */
24
+ export interface IHttpsOptions {
25
+ customCert?: {
26
+ key: string;
27
+ cert: string;
28
+ };
29
+ forwardSni?: boolean;
30
+ }
31
+ /**
32
+ * ACME certificate handling options
33
+ */
34
+ export interface IAcmeForwardingOptions {
35
+ enabled?: boolean;
36
+ maintenance?: boolean;
37
+ production?: boolean;
38
+ forwardChallenges?: {
39
+ host: string;
40
+ port: number;
41
+ useTls?: boolean;
42
+ };
43
+ }
44
+ /**
45
+ * Security options for forwarding
46
+ */
47
+ export interface ISecurityOptions {
48
+ allowedIps?: string[];
49
+ blockedIps?: string[];
50
+ maxConnections?: number;
51
+ }
52
+ /**
53
+ * Advanced options for forwarding
54
+ */
55
+ export interface IAdvancedOptions {
56
+ portRanges?: Array<{
57
+ from: number;
58
+ to: number;
59
+ }>;
60
+ networkProxyPort?: number;
61
+ keepAlive?: boolean;
62
+ timeout?: number;
63
+ headers?: Record<string, string>;
64
+ }
65
+ /**
66
+ * Unified forwarding configuration interface
67
+ */
68
+ export interface IForwardConfig {
69
+ type: ForwardingType;
70
+ target: ITargetConfig;
71
+ http?: IHttpOptions;
72
+ https?: IHttpsOptions;
73
+ acme?: IAcmeForwardingOptions;
74
+ security?: ISecurityOptions;
75
+ advanced?: IAdvancedOptions;
76
+ }
77
+ /**
78
+ * Event types emitted by forwarding handlers
79
+ */
80
+ export declare enum ForwardingHandlerEvents {
81
+ CONNECTED = "connected",
82
+ DISCONNECTED = "disconnected",
83
+ ERROR = "error",
84
+ DATA_FORWARDED = "data-forwarded",
85
+ HTTP_REQUEST = "http-request",
86
+ HTTP_RESPONSE = "http-response",
87
+ CERTIFICATE_NEEDED = "certificate-needed",
88
+ CERTIFICATE_LOADED = "certificate-loaded"
89
+ }
90
+ /**
91
+ * Base interface for forwarding handlers
92
+ */
93
+ export interface IForwardingHandler extends plugins.EventEmitter {
94
+ initialize(): Promise<void>;
95
+ handleConnection(socket: plugins.net.Socket): void;
96
+ handleHttpRequest(req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse): void;
97
+ }
98
+ /**
99
+ * Helper function types for common forwarding patterns
100
+ */
101
+ export declare const httpOnly: (partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, "target">) => IForwardConfig;
102
+ export declare const tlsTerminateToHttp: (partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, "target">) => IForwardConfig;
103
+ export declare const tlsTerminateToHttps: (partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, "target">) => IForwardConfig;
104
+ export declare const httpsPassthrough: (partialConfig: Partial<IForwardConfig> & Pick<IForwardConfig, "target">) => IForwardConfig;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Event types emitted by forwarding handlers
3
+ */
4
+ export var ForwardingHandlerEvents;
5
+ (function (ForwardingHandlerEvents) {
6
+ ForwardingHandlerEvents["CONNECTED"] = "connected";
7
+ ForwardingHandlerEvents["DISCONNECTED"] = "disconnected";
8
+ ForwardingHandlerEvents["ERROR"] = "error";
9
+ ForwardingHandlerEvents["DATA_FORWARDED"] = "data-forwarded";
10
+ ForwardingHandlerEvents["HTTP_REQUEST"] = "http-request";
11
+ ForwardingHandlerEvents["HTTP_RESPONSE"] = "http-response";
12
+ ForwardingHandlerEvents["CERTIFICATE_NEEDED"] = "certificate-needed";
13
+ ForwardingHandlerEvents["CERTIFICATE_LOADED"] = "certificate-loaded";
14
+ })(ForwardingHandlerEvents || (ForwardingHandlerEvents = {}));
15
+ /**
16
+ * Helper function types for common forwarding patterns
17
+ */
18
+ export const httpOnly = (partialConfig) => ({
19
+ type: 'http-only',
20
+ target: partialConfig.target,
21
+ http: { enabled: true, ...(partialConfig.http || {}) },
22
+ ...(partialConfig.security ? { security: partialConfig.security } : {}),
23
+ ...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
24
+ });
25
+ export const tlsTerminateToHttp = (partialConfig) => ({
26
+ type: 'https-terminate-to-http',
27
+ target: partialConfig.target,
28
+ https: { ...(partialConfig.https || {}) },
29
+ acme: { enabled: true, maintenance: true, ...(partialConfig.acme || {}) },
30
+ http: { enabled: true, redirectToHttps: true, ...(partialConfig.http || {}) },
31
+ ...(partialConfig.security ? { security: partialConfig.security } : {}),
32
+ ...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
33
+ });
34
+ export const tlsTerminateToHttps = (partialConfig) => ({
35
+ type: 'https-terminate-to-https',
36
+ target: partialConfig.target,
37
+ https: { ...(partialConfig.https || {}) },
38
+ acme: { enabled: true, maintenance: true, ...(partialConfig.acme || {}) },
39
+ http: { enabled: true, redirectToHttps: true, ...(partialConfig.http || {}) },
40
+ ...(partialConfig.security ? { security: partialConfig.security } : {}),
41
+ ...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
42
+ });
43
+ export const httpsPassthrough = (partialConfig) => ({
44
+ type: 'https-passthrough',
45
+ target: partialConfig.target,
46
+ https: { forwardSni: true, ...(partialConfig.https || {}) },
47
+ ...(partialConfig.security ? { security: partialConfig.security } : {}),
48
+ ...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
49
+ });
50
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9yd2FyZGluZy50eXBlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4u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sYUFBYSxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUMsRUFBRSxRQUFRLEVBQUUsYUFBYSxDQUFDLFFBQVEsRUFBRSxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUM7Q0FDeEUsQ0FBQyxDQUFDIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartproxy",
3
- "version": "10.2.0",
3
+ "version": "12.0.0",
4
4
  "private": false,
5
5
  "description": "A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.",
6
6
  "main": "dist_ts/index.js",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "scripts": {
76
76
  "test": "(tstest test/)",
77
- "build": "(tsbuild --web --allowimplicitany)",
77
+ "build": "(tsbuild tsfolders --allowimplicitany)",
78
78
  "format": "(gitzone format)",
79
79
  "buildDocs": "tsdoc"
80
80
  }
package/readme.md CHANGED
@@ -6,6 +6,7 @@ A high-performance proxy toolkit for Node.js, offering:
6
6
  - Low-level port forwarding via nftables
7
7
  - HTTP-to-HTTPS and custom URL redirects
8
8
  - Advanced TCP/SNI-based proxying with IP filtering and rules
9
+ - Unified forwarding configuration system for all proxy types
9
10
 
10
11
  ## Exports
11
12
  The following classes and interfaces are provided:
@@ -23,11 +24,14 @@ The following classes and interfaces are provided:
23
24
  TCP/SNI-based proxy with dynamic routing, IP filtering, and unified certificates.
24
25
  - **SniHandler** (ts/smartproxy/classes.pp.snihandler.ts)
25
26
  Static utilities to extract SNI hostnames from TLS handshakes.
27
+ - **Forwarding Handlers** (ts/smartproxy/forwarding/*.ts)
28
+ Unified forwarding handlers for different connection types (HTTP, HTTPS passthrough, TLS termination).
26
29
  - **Interfaces**
27
30
  - IPortProxySettings, IDomainConfig (ts/smartproxy/classes.pp.interfaces.ts)
28
31
  - INetworkProxyOptions (ts/networkproxy/classes.np.types.ts)
29
- - IAcmeOptions, IDomainOptions, IForwardConfig (ts/common/types.ts)
32
+ - IAcmeOptions, IDomainOptions (ts/common/types.ts)
30
33
  - INfTableProxySettings (ts/nfttablesproxy/classes.nftablesproxy.ts)
34
+ - IForwardConfig, ForwardingType (ts/smartproxy/types/forwarding.types.ts)
31
35
 
32
36
  ## Installation
33
37
  Install via npm:
@@ -134,16 +138,37 @@ await nft.stop();
134
138
  ### 5. TCP/SNI Proxy (SmartProxy)
135
139
  ```typescript
136
140
  import { SmartProxy } from '@push.rocks/smartproxy';
141
+ import { createDomainConfig, httpOnly, tlsTerminateToHttp, httpsPassthrough } from '@push.rocks/smartproxy';
137
142
 
138
143
  const smart = new SmartProxy({
139
144
  fromPort: 443,
140
145
  toPort: 8443,
141
146
  domainConfigs: [
142
- {
143
- domains: ['example.com', '*.example.com'],
144
- allowedIPs: ['*'],
145
- targetIPs: ['127.0.0.1'],
146
- }
147
+ // HTTPS passthrough example
148
+ createDomainConfig(['example.com', '*.example.com'],
149
+ httpsPassthrough({
150
+ target: {
151
+ host: '127.0.0.1',
152
+ port: 443
153
+ },
154
+ security: {
155
+ allowedIps: ['*']
156
+ }
157
+ })
158
+ ),
159
+ // HTTPS termination example
160
+ createDomainConfig('secure.example.com',
161
+ tlsTerminateToHttp({
162
+ target: {
163
+ host: 'localhost',
164
+ port: 3000
165
+ },
166
+ acme: {
167
+ enabled: true,
168
+ production: true
169
+ }
170
+ })
171
+ )
147
172
  ],
148
173
  sniEnabled: true
149
174
  });
@@ -386,6 +411,126 @@ Listen for certificate events via EventEmitter:
386
411
 
387
412
  Provide a `certProvisionFunction(domain)` in SmartProxy settings to supply static certs or return `'http01'`.
388
413
 
414
+ ## Unified Forwarding System
415
+
416
+ The SmartProxy Unified Forwarding System provides a clean, use-case driven approach to configuring different types of traffic forwarding. It replaces disparate configuration mechanisms with a unified interface.
417
+
418
+ ### Forwarding Types
419
+
420
+ The system supports four primary forwarding types:
421
+
422
+ 1. **HTTP-only (`http-only`)**: Forwards HTTP traffic to a backend server.
423
+ 2. **HTTPS Passthrough (`https-passthrough`)**: Passes through raw TLS traffic without termination (SNI forwarding).
424
+ 3. **HTTPS Termination to HTTP (`https-terminate-to-http`)**: Terminates TLS and forwards the decrypted traffic to an HTTP backend.
425
+ 4. **HTTPS Termination to HTTPS (`https-terminate-to-https`)**: Terminates TLS and creates a new TLS connection to an HTTPS backend.
426
+
427
+ ### Basic Configuration
428
+
429
+ Each domain is configured with a forwarding type and target:
430
+
431
+ ```typescript
432
+ {
433
+ domains: ['example.com'],
434
+ forwarding: {
435
+ type: 'http-only',
436
+ target: {
437
+ host: 'localhost',
438
+ port: 3000
439
+ }
440
+ }
441
+ }
442
+ ```
443
+
444
+ ### Helper Functions
445
+
446
+ Helper functions are provided for common configurations:
447
+
448
+ ```typescript
449
+ import { createDomainConfig, httpOnly, tlsTerminateToHttp,
450
+ tlsTerminateToHttps, httpsPassthrough } from '@push.rocks/smartproxy';
451
+
452
+ // HTTP-only
453
+ await domainManager.addDomainConfig(
454
+ createDomainConfig('example.com', httpOnly({
455
+ target: { host: 'localhost', port: 3000 }
456
+ }))
457
+ );
458
+
459
+ // HTTPS termination to HTTP
460
+ await domainManager.addDomainConfig(
461
+ createDomainConfig('secure.example.com', tlsTerminateToHttp({
462
+ target: { host: 'localhost', port: 3000 },
463
+ acme: { production: true }
464
+ }))
465
+ );
466
+
467
+ // HTTPS termination to HTTPS
468
+ await domainManager.addDomainConfig(
469
+ createDomainConfig('api.example.com', tlsTerminateToHttps({
470
+ target: { host: 'internal-api', port: 8443 },
471
+ http: { redirectToHttps: true }
472
+ }))
473
+ );
474
+
475
+ // HTTPS passthrough (SNI)
476
+ await domainManager.addDomainConfig(
477
+ createDomainConfig('passthrough.example.com', httpsPassthrough({
478
+ target: { host: '10.0.0.5', port: 443 }
479
+ }))
480
+ );
481
+ ```
482
+
483
+ ### Advanced Configuration
484
+
485
+ For more complex scenarios, additional options can be specified:
486
+
487
+ ```typescript
488
+ {
489
+ domains: ['api.example.com'],
490
+ forwarding: {
491
+ type: 'https-terminate-to-https',
492
+ target: {
493
+ host: ['10.0.0.10', '10.0.0.11'], // Round-robin load balancing
494
+ port: 8443
495
+ },
496
+ http: {
497
+ enabled: true,
498
+ redirectToHttps: true
499
+ },
500
+ https: {
501
+ // Custom certificate instead of ACME-provisioned
502
+ customCert: {
503
+ key: '-----BEGIN PRIVATE KEY-----\n...',
504
+ cert: '-----BEGIN CERTIFICATE-----\n...'
505
+ }
506
+ },
507
+ security: {
508
+ allowedIps: ['10.0.0.*', '192.168.1.*'],
509
+ blockedIps: ['1.2.3.4'],
510
+ maxConnections: 100
511
+ },
512
+ advanced: {
513
+ timeout: 30000,
514
+ headers: {
515
+ 'X-Forwarded-For': '{clientIp}',
516
+ 'X-Original-Host': '{sni}'
517
+ }
518
+ }
519
+ }
520
+ }
521
+ ```
522
+
523
+ ### Extended Configuration Options
524
+
525
+ #### IForwardConfig
526
+ - `type`: 'http-only' | 'https-passthrough' | 'https-terminate-to-http' | 'https-terminate-to-https'
527
+ - `target`: { host: string | string[], port: number }
528
+ - `http?`: { enabled?: boolean, redirectToHttps?: boolean, headers?: Record<string, string> }
529
+ - `https?`: { customCert?: { key: string, cert: string }, forwardSni?: boolean }
530
+ - `acme?`: { enabled?: boolean, maintenance?: boolean, production?: boolean, forwardChallenges?: { host: string, port: number, useTls?: boolean } }
531
+ - `security?`: { allowedIps?: string[], blockedIps?: string[], maxConnections?: number }
532
+ - `advanced?`: { portRanges?: Array<{ from: number, to: number }>, networkProxyPort?: number, keepAlive?: boolean, timeout?: number, headers?: Record<string, string> }
533
+
389
534
  ## Configuration Options
390
535
 
391
536
  ### NetworkProxy (INetworkProxyOptions)
@@ -425,12 +570,14 @@ Provide a `certProvisionFunction(domain)` in SmartProxy settings to supply stati
425
570
 
426
571
  ### SmartProxy (IPortProxySettings)
427
572
  - `fromPort`, `toPort` (number)
428
- - `domainConfigs` (IDomainConfig[])
429
- - `sniEnabled`, `defaultAllowedIPs`, `preserveSourceIP` (booleans)
573
+ - `domainConfigs` (IDomainConfig[]) - Using unified forwarding configuration
574
+ - `sniEnabled`, `preserveSourceIP` (booleans)
575
+ - `defaultAllowedIPs`, `defaultBlockedIPs` (string[]) - Default IP allowlists/blocklists
430
576
  - Timeouts: `initialDataTimeout`, `socketTimeout`, `inactivityTimeout`, etc.
431
577
  - Socket opts: `noDelay`, `keepAlive`, `enableKeepAliveProbes`
432
578
  - `acme` (IAcmeOptions), `certProvisionFunction` (callback)
433
579
  - `useNetworkProxy` (number[]), `networkProxyPort` (number)
580
+ - `globalPortRanges` (Array<{ from: number; to: number }>)
434
581
 
435
582
  ## Troubleshooting
436
583
 
@@ -455,6 +602,9 @@ Provide a `certProvisionFunction(domain)` in SmartProxy settings to supply stati
455
602
  - Increase `initialDataTimeout`/`maxPendingDataSize` for large ClientHello
456
603
  - Enable `enableTlsDebugLogging` to trace handshake
457
604
  - Ensure `allowSessionTicket` and fragmentation support for resumption
605
+ - Double-check forwarding configuration to ensure correct `type` for your use case
606
+ - Use helper functions like `httpOnly()`, `httpsPassthrough()`, etc. to create correct configurations
607
+ - For IP filtering issues, check the `security.allowedIps` and `security.blockedIps` settings
458
608
 
459
609
  ## License and Legal Information
460
610