@push.rocks/smartproxy 22.4.2 → 23.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 (101) hide show
  1. package/changelog.md +36 -0
  2. package/dist_rust/rustproxy +0 -0
  3. package/dist_ts/00_commitinfo_data.js +1 -1
  4. package/dist_ts/index.d.ts +1 -6
  5. package/dist_ts/index.js +3 -11
  6. package/dist_ts/protocols/common/fragment-handler.js +5 -1
  7. package/dist_ts/proxies/index.d.ts +1 -6
  8. package/dist_ts/proxies/index.js +2 -8
  9. package/dist_ts/proxies/smart-proxy/index.d.ts +5 -10
  10. package/dist_ts/proxies/smart-proxy/index.js +7 -13
  11. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -2
  12. package/dist_ts/proxies/smart-proxy/models/route-types.js +1 -1
  13. package/dist_ts/proxies/smart-proxy/route-preprocessor.d.ts +37 -0
  14. package/dist_ts/proxies/smart-proxy/route-preprocessor.js +103 -0
  15. package/dist_ts/proxies/smart-proxy/rust-binary-locator.d.ts +23 -0
  16. package/dist_ts/proxies/smart-proxy/rust-binary-locator.js +104 -0
  17. package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.d.ts +74 -0
  18. package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.js +146 -0
  19. package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.d.ts +49 -0
  20. package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.js +259 -0
  21. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +39 -157
  22. package/dist_ts/proxies/smart-proxy/smart-proxy.js +224 -621
  23. package/dist_ts/proxies/smart-proxy/socket-handler-server.d.ts +45 -0
  24. package/dist_ts/proxies/smart-proxy/socket-handler-server.js +253 -0
  25. package/dist_ts/routing/index.d.ts +1 -1
  26. package/dist_ts/routing/index.js +3 -3
  27. package/dist_ts/routing/models/http-types.d.ts +119 -4
  28. package/dist_ts/routing/models/http-types.js +93 -5
  29. package/package.json +1 -1
  30. package/readme.md +444 -219
  31. package/ts/00_commitinfo_data.ts +1 -1
  32. package/ts/index.ts +4 -15
  33. package/ts/protocols/common/fragment-handler.ts +4 -0
  34. package/ts/proxies/index.ts +1 -12
  35. package/ts/proxies/smart-proxy/index.ts +6 -13
  36. package/ts/proxies/smart-proxy/models/interfaces.ts +6 -4
  37. package/ts/proxies/smart-proxy/models/route-types.ts +0 -2
  38. package/ts/proxies/smart-proxy/route-preprocessor.ts +122 -0
  39. package/ts/proxies/smart-proxy/rust-binary-locator.ts +112 -0
  40. package/ts/proxies/smart-proxy/rust-metrics-adapter.ts +161 -0
  41. package/ts/proxies/smart-proxy/rust-proxy-bridge.ts +310 -0
  42. package/ts/proxies/smart-proxy/smart-proxy.ts +282 -798
  43. package/ts/proxies/smart-proxy/socket-handler-server.ts +279 -0
  44. package/ts/routing/index.ts +2 -2
  45. package/ts/routing/models/http-types.ts +147 -4
  46. package/dist_ts/proxies/nftables-proxy/index.d.ts +0 -6
  47. package/dist_ts/proxies/nftables-proxy/index.js +0 -7
  48. package/dist_ts/proxies/nftables-proxy/models/errors.d.ts +0 -15
  49. package/dist_ts/proxies/nftables-proxy/models/errors.js +0 -28
  50. package/dist_ts/proxies/nftables-proxy/models/index.d.ts +0 -5
  51. package/dist_ts/proxies/nftables-proxy/models/index.js +0 -6
  52. package/dist_ts/proxies/nftables-proxy/models/interfaces.d.ts +0 -75
  53. package/dist_ts/proxies/nftables-proxy/models/interfaces.js +0 -5
  54. package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +0 -124
  55. package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +0 -1374
  56. package/dist_ts/proxies/nftables-proxy/utils/index.d.ts +0 -9
  57. package/dist_ts/proxies/nftables-proxy/utils/index.js +0 -12
  58. package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.d.ts +0 -66
  59. package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.js +0 -131
  60. package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.d.ts +0 -39
  61. package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.js +0 -112
  62. package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.d.ts +0 -59
  63. package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.js +0 -130
  64. package/ts/proxies/http-proxy/connection-pool.ts +0 -228
  65. package/ts/proxies/http-proxy/context-creator.ts +0 -145
  66. package/ts/proxies/http-proxy/default-certificates.ts +0 -150
  67. package/ts/proxies/http-proxy/function-cache.ts +0 -279
  68. package/ts/proxies/http-proxy/handlers/index.ts +0 -5
  69. package/ts/proxies/http-proxy/http-proxy.ts +0 -669
  70. package/ts/proxies/http-proxy/http-request-handler.ts +0 -331
  71. package/ts/proxies/http-proxy/http2-request-handler.ts +0 -255
  72. package/ts/proxies/http-proxy/index.ts +0 -18
  73. package/ts/proxies/http-proxy/models/http-types.ts +0 -148
  74. package/ts/proxies/http-proxy/models/index.ts +0 -5
  75. package/ts/proxies/http-proxy/models/types.ts +0 -125
  76. package/ts/proxies/http-proxy/request-handler.ts +0 -878
  77. package/ts/proxies/http-proxy/security-manager.ts +0 -413
  78. package/ts/proxies/http-proxy/websocket-handler.ts +0 -581
  79. package/ts/proxies/nftables-proxy/index.ts +0 -6
  80. package/ts/proxies/nftables-proxy/models/errors.ts +0 -30
  81. package/ts/proxies/nftables-proxy/models/index.ts +0 -5
  82. package/ts/proxies/nftables-proxy/models/interfaces.ts +0 -94
  83. package/ts/proxies/nftables-proxy/nftables-proxy.ts +0 -1754
  84. package/ts/proxies/nftables-proxy/utils/index.ts +0 -38
  85. package/ts/proxies/nftables-proxy/utils/nft-command-executor.ts +0 -162
  86. package/ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.ts +0 -125
  87. package/ts/proxies/nftables-proxy/utils/nft-rule-validator.ts +0 -156
  88. package/ts/proxies/smart-proxy/acme-state-manager.ts +0 -112
  89. package/ts/proxies/smart-proxy/cert-store.ts +0 -92
  90. package/ts/proxies/smart-proxy/certificate-manager.ts +0 -895
  91. package/ts/proxies/smart-proxy/connection-manager.ts +0 -809
  92. package/ts/proxies/smart-proxy/http-proxy-bridge.ts +0 -213
  93. package/ts/proxies/smart-proxy/metrics-collector.ts +0 -453
  94. package/ts/proxies/smart-proxy/nftables-manager.ts +0 -271
  95. package/ts/proxies/smart-proxy/port-manager.ts +0 -358
  96. package/ts/proxies/smart-proxy/route-connection-handler.ts +0 -1712
  97. package/ts/proxies/smart-proxy/route-orchestrator.ts +0 -297
  98. package/ts/proxies/smart-proxy/security-manager.ts +0 -269
  99. package/ts/proxies/smart-proxy/throughput-tracker.ts +0 -138
  100. package/ts/proxies/smart-proxy/timeout-manager.ts +0 -196
  101. package/ts/proxies/smart-proxy/tls-manager.ts +0 -171
@@ -1,208 +1,90 @@
1
1
  import * as plugins from '../../plugins.js';
2
- import { ConnectionManager } from './connection-manager.js';
3
- import { SecurityManager } from './security-manager.js';
4
- import { TlsManager } from './tls-manager.js';
5
- import { HttpProxyBridge } from './http-proxy-bridge.js';
6
- import { TimeoutManager } from './timeout-manager.js';
7
2
  import { SharedRouteManager as RouteManager } from '../../core/routing/route-manager.js';
8
- import { RouteConnectionHandler } from './route-connection-handler.js';
9
- import { NFTablesManager } from './nftables-manager.js';
10
- import { SmartCertManager, type ICertStatus } from './certificate-manager.js';
11
3
  import type { ISmartProxyOptions } from './models/interfaces.js';
12
4
  import type { IRouteConfig } from './models/route-types.js';
13
- import { AcmeStateManager } from './acme-state-manager.js';
14
- import { MetricsCollector } from './metrics-collector.js';
15
5
  import type { IMetrics } from './models/metrics-types.js';
16
6
  /**
17
- * SmartProxy - Pure route-based API
7
+ * SmartProxy - Rust-backed proxy engine with TypeScript configuration API.
18
8
  *
19
- * SmartProxy is a unified proxy system that works with routes to define connection handling behavior.
20
- * Each route contains matching criteria (ports, domains, etc.) and an action to take (forward, redirect, block).
21
- *
22
- * Configuration is provided through a set of routes, with each route defining:
23
- * - What to match (ports, domains, paths, client IPs)
24
- * - What to do with matching traffic (forward, redirect, block)
25
- * - How to handle TLS (passthrough, terminate, terminate-and-reencrypt)
26
- * - Security settings (IP restrictions, connection limits)
27
- * - Advanced options (timeout, headers, etc.)
9
+ * All networking (TCP, TLS, HTTP reverse proxy, connection management, security,
10
+ * NFTables) is handled by the Rust binary. TypeScript is only:
11
+ * - The npm module interface (types, route helpers)
12
+ * - The thin IPC wrapper (this class)
13
+ * - Socket-handler callback relay (for JS-defined handlers)
14
+ * - Certificate provisioning callbacks (certProvisionFunction)
28
15
  */
29
16
  export declare class SmartProxy extends plugins.EventEmitter {
30
- private portManager;
31
- private connectionLogger;
32
- private isShuttingDown;
33
- connectionManager: ConnectionManager;
34
- securityManager: SecurityManager;
35
- tlsManager: TlsManager;
36
- httpProxyBridge: HttpProxyBridge;
37
- timeoutManager: TimeoutManager;
17
+ settings: ISmartProxyOptions;
38
18
  routeManager: RouteManager;
39
- routeConnectionHandler: RouteConnectionHandler;
40
- nftablesManager: NFTablesManager;
41
- certManager: SmartCertManager | null;
42
- private globalChallengeRouteActive;
19
+ private bridge;
20
+ private preprocessor;
21
+ private socketHandlerServer;
22
+ private metricsAdapter;
43
23
  private routeUpdateLock;
44
- acmeStateManager: AcmeStateManager;
45
- metricsCollector: MetricsCollector;
46
- private routeOrchestrator;
47
- private portUsageMap;
48
- /**
49
- * Constructor for SmartProxy
50
- *
51
- * @param settingsArg Configuration options containing routes and other settings
52
- * Routes define how traffic is matched and handled, with each route having:
53
- * - match: criteria for matching traffic (ports, domains, paths, IPs)
54
- * - action: what to do with matched traffic (forward, redirect, block)
55
- *
56
- * Example:
57
- * ```ts
58
- * const proxy = new SmartProxy({
59
- * routes: [
60
- * {
61
- * match: {
62
- * ports: 443,
63
- * domains: ['example.com', '*.example.com']
64
- * },
65
- * action: {
66
- * type: 'forward',
67
- * target: { host: '10.0.0.1', port: 8443 },
68
- * tls: { mode: 'passthrough' }
69
- * }
70
- * }
71
- * ],
72
- * defaults: {
73
- * target: { host: 'localhost', port: 8080 },
74
- * security: { ipAllowList: ['*'] }
75
- * }
76
- * });
77
- * ```
78
- */
24
+ private stopping;
79
25
  constructor(settingsArg: ISmartProxyOptions);
80
26
  /**
81
- * The settings for the SmartProxy
82
- */
83
- settings: ISmartProxyOptions;
84
- /**
85
- * Helper method to create and configure certificate manager
86
- * This ensures consistent setup including the required ACME callback
87
- */
88
- private createCertificateManager;
89
- /**
90
- * Initialize certificate manager
91
- */
92
- private initializeCertificateManager;
93
- /**
94
- * Check if we have routes with static certificates
95
- */
96
- private hasStaticCertRoutes;
97
- /**
98
- * Start the proxy server with support for both configuration types
27
+ * Start the proxy.
28
+ * Spawns the Rust binary, configures socket relay if needed, sends routes, handles cert provisioning.
99
29
  */
100
30
  start(): Promise<void>;
101
31
  /**
102
- * Extract domain configurations from routes for certificate provisioning
103
- *
104
- * Note: This method has been removed as we now work directly with routes
105
- */
106
- /**
107
- * Stop the proxy server
32
+ * Stop the proxy.
108
33
  */
109
34
  stop(): Promise<void>;
110
35
  /**
111
- * Updates the domain configurations for the proxy
112
- *
113
- * Note: This legacy method has been removed. Use updateRoutes instead.
114
- */
115
- updateDomainConfigs(): Promise<void>;
116
- /**
117
- * Verify the challenge route has been properly removed from routes
118
- */
119
- private verifyChallengeRouteRemoved;
120
- /**
121
- * Update routes with new configuration
122
- *
123
- * This method replaces the current route configuration with the provided routes.
124
- * It also provisions certificates for routes that require TLS termination and have
125
- * `certificate: 'auto'` set in their TLS configuration.
126
- *
127
- * @param newRoutes Array of route configurations to use
128
- *
129
- * Example:
130
- * ```ts
131
- * proxy.updateRoutes([
132
- * {
133
- * match: { ports: 443, domains: 'secure.example.com' },
134
- * action: {
135
- * type: 'forward',
136
- * target: { host: '10.0.0.1', port: 8443 },
137
- * tls: { mode: 'terminate', certificate: 'auto' }
138
- * }
139
- * }
140
- * ]);
141
- * ```
36
+ * Update routes atomically.
142
37
  */
143
38
  updateRoutes(newRoutes: IRouteConfig[]): Promise<void>;
144
39
  /**
145
- * Manually provision a certificate for a route
40
+ * Provision a certificate for a named route.
146
41
  */
147
42
  provisionCertificate(routeName: string): Promise<void>;
148
43
  /**
149
- * Force renewal of a certificate
44
+ * Force renewal of a certificate.
150
45
  */
151
46
  renewCertificate(routeName: string): Promise<void>;
152
47
  /**
153
- * Get certificate status for a route
48
+ * Get certificate status for a route (async - calls Rust).
154
49
  */
155
- getCertificateStatus(routeName: string): ICertStatus | undefined;
50
+ getCertificateStatus(routeName: string): Promise<any>;
156
51
  /**
157
- * Get proxy metrics with clean API
158
- *
159
- * @returns IMetrics interface with grouped metrics methods
52
+ * Get the metrics interface.
160
53
  */
161
54
  getMetrics(): IMetrics;
162
55
  /**
163
- * Validates if a domain name is valid for certificate issuance
56
+ * Get statistics (async - calls Rust).
164
57
  */
165
- private isValidDomain;
58
+ getStatistics(): Promise<any>;
166
59
  /**
167
- * Add a new listening port without changing the route configuration
168
- *
169
- * This allows you to add a port listener without updating routes.
170
- * Useful for preparing to listen on a port before adding routes for it.
171
- *
172
- * @param port The port to start listening on
173
- * @returns Promise that resolves when the port is listening
60
+ * Add a listening port at runtime.
174
61
  */
175
62
  addListeningPort(port: number): Promise<void>;
176
63
  /**
177
- * Stop listening on a specific port without changing the route configuration
178
- *
179
- * This allows you to stop a port listener without updating routes.
180
- * Useful for temporary maintenance or port changes.
181
- *
182
- * @param port The port to stop listening on
183
- * @returns Promise that resolves when the port is closed
64
+ * Remove a listening port at runtime.
184
65
  */
185
66
  removeListeningPort(port: number): Promise<void>;
186
67
  /**
187
- * Get a list of all ports currently being listened on
188
- *
189
- * @returns Array of port numbers
190
- */
191
- getListeningPorts(): number[];
192
- /**
193
- * Get statistics about current connections
68
+ * Get all currently listening ports (async - calls Rust).
194
69
  */
195
- getStatistics(): any;
70
+ getListeningPorts(): Promise<number[]>;
196
71
  /**
197
- * Get a list of eligible domains for ACME certificates
72
+ * Get eligible domains for ACME certificates (sync - reads local routes).
198
73
  */
199
74
  getEligibleDomainsForCertificates(): string[];
200
75
  /**
201
- * Get NFTables status
76
+ * Get NFTables status (async - calls Rust).
202
77
  */
203
78
  getNfTablesStatus(): Promise<Record<string, any>>;
204
79
  /**
205
- * Validate ACME configuration
80
+ * Build the Rust configuration object from TS settings.
206
81
  */
207
- private validateAcmeConfiguration;
82
+ private buildRustConfig;
83
+ /**
84
+ * For routes with certificate: 'auto', call certProvisionFunction if set.
85
+ * If the callback returns a cert object, load it into Rust.
86
+ * If it returns 'http01', let Rust handle ACME.
87
+ */
88
+ private provisionCertificatesViaCallback;
89
+ private isValidDomain;
208
90
  }