@push.rocks/smartproxy 21.1.6 → 22.4.2

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 (103) hide show
  1. package/changelog.md +89 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/core/utils/shared-security-manager.d.ts +17 -0
  4. package/dist_ts/core/utils/shared-security-manager.js +66 -1
  5. package/dist_ts/proxies/http-proxy/default-certificates.d.ts +54 -0
  6. package/dist_ts/proxies/http-proxy/default-certificates.js +127 -0
  7. package/dist_ts/proxies/http-proxy/http-proxy.d.ts +1 -1
  8. package/dist_ts/proxies/http-proxy/http-proxy.js +9 -14
  9. package/dist_ts/proxies/http-proxy/index.d.ts +5 -1
  10. package/dist_ts/proxies/http-proxy/index.js +6 -2
  11. package/dist_ts/proxies/http-proxy/security-manager.d.ts +4 -12
  12. package/dist_ts/proxies/http-proxy/security-manager.js +66 -99
  13. package/dist_ts/proxies/nftables-proxy/index.d.ts +1 -0
  14. package/dist_ts/proxies/nftables-proxy/index.js +2 -1
  15. package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +4 -26
  16. package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +84 -236
  17. package/dist_ts/proxies/nftables-proxy/utils/index.d.ts +9 -0
  18. package/dist_ts/proxies/nftables-proxy/utils/index.js +12 -0
  19. package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.d.ts +66 -0
  20. package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.js +131 -0
  21. package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.d.ts +39 -0
  22. package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.js +112 -0
  23. package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.d.ts +59 -0
  24. package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.js +130 -0
  25. package/dist_ts/proxies/smart-proxy/certificate-manager.js +4 -3
  26. package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +13 -2
  27. package/dist_ts/proxies/smart-proxy/connection-manager.js +16 -6
  28. package/dist_ts/proxies/smart-proxy/http-proxy-bridge.js +35 -10
  29. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +0 -1
  30. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +17 -0
  31. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +72 -9
  32. package/dist_ts/proxies/smart-proxy/security-manager.d.ts +14 -12
  33. package/dist_ts/proxies/smart-proxy/security-manager.js +80 -74
  34. package/dist_ts/proxies/smart-proxy/smart-proxy.js +1 -2
  35. package/dist_ts/proxies/smart-proxy/tls-manager.d.ts +2 -9
  36. package/dist_ts/proxies/smart-proxy/tls-manager.js +3 -26
  37. package/dist_ts/proxies/smart-proxy/utils/index.d.ts +1 -1
  38. package/dist_ts/proxies/smart-proxy/utils/index.js +3 -4
  39. package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.d.ts +49 -0
  40. package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.js +108 -0
  41. package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.d.ts +57 -0
  42. package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.js +89 -0
  43. package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.d.ts +17 -0
  44. package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.js +32 -0
  45. package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.d.ts +68 -0
  46. package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.js +117 -0
  47. package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.d.ts +17 -0
  48. package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.js +27 -0
  49. package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.d.ts +63 -0
  50. package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.js +105 -0
  51. package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.d.ts +83 -0
  52. package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.js +126 -0
  53. package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.d.ts +47 -0
  54. package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.js +66 -0
  55. package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.d.ts +70 -0
  56. package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.js +287 -0
  57. package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.d.ts +46 -0
  58. package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.js +67 -0
  59. package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +4 -457
  60. package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +6 -950
  61. package/dist_ts/proxies/smart-proxy/utils/route-utils.js +2 -2
  62. package/dist_ts/proxies/smart-proxy/utils/route-validator.d.ts +67 -1
  63. package/dist_ts/proxies/smart-proxy/utils/route-validator.js +266 -6
  64. package/npmextra.json +12 -6
  65. package/package.json +34 -24
  66. package/readme.hints.md +184 -1
  67. package/readme.md +235 -172
  68. package/ts/00_commitinfo_data.ts +1 -1
  69. package/ts/core/utils/shared-security-manager.ts +98 -13
  70. package/ts/proxies/http-proxy/default-certificates.ts +150 -0
  71. package/ts/proxies/http-proxy/http-proxy.ts +9 -15
  72. package/ts/proxies/http-proxy/index.ts +6 -1
  73. package/ts/proxies/http-proxy/security-manager.ts +141 -161
  74. package/ts/proxies/nftables-proxy/index.ts +1 -0
  75. package/ts/proxies/nftables-proxy/nftables-proxy.ts +116 -290
  76. package/ts/proxies/nftables-proxy/utils/index.ts +38 -0
  77. package/ts/proxies/nftables-proxy/utils/nft-command-executor.ts +162 -0
  78. package/ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.ts +125 -0
  79. package/ts/proxies/nftables-proxy/utils/nft-rule-validator.ts +156 -0
  80. package/ts/proxies/smart-proxy/certificate-manager.ts +3 -2
  81. package/ts/proxies/smart-proxy/connection-manager.ts +21 -8
  82. package/ts/proxies/smart-proxy/http-proxy-bridge.ts +39 -13
  83. package/ts/proxies/smart-proxy/models/interfaces.ts +0 -1
  84. package/ts/proxies/smart-proxy/route-connection-handler.ts +88 -16
  85. package/ts/proxies/smart-proxy/security-manager.ts +98 -86
  86. package/ts/proxies/smart-proxy/smart-proxy.ts +0 -2
  87. package/ts/proxies/smart-proxy/tls-manager.ts +1 -37
  88. package/ts/proxies/smart-proxy/utils/index.ts +3 -5
  89. package/ts/proxies/smart-proxy/utils/route-helpers/api-helpers.ts +144 -0
  90. package/ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.ts +124 -0
  91. package/ts/proxies/smart-proxy/utils/route-helpers/http-helpers.ts +40 -0
  92. package/ts/proxies/smart-proxy/utils/route-helpers/https-helpers.ts +163 -0
  93. package/ts/proxies/smart-proxy/utils/route-helpers/index.ts +62 -0
  94. package/ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.ts +154 -0
  95. package/ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.ts +202 -0
  96. package/ts/proxies/smart-proxy/utils/route-helpers/security-helpers.ts +96 -0
  97. package/ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.ts +337 -0
  98. package/ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.ts +98 -0
  99. package/ts/proxies/smart-proxy/utils/route-helpers.ts +5 -1302
  100. package/ts/proxies/smart-proxy/utils/route-utils.ts +1 -1
  101. package/ts/proxies/smart-proxy/utils/route-validator.ts +289 -7
  102. package/ts/proxies/http-proxy/certificate-manager.ts +0 -244
  103. package/ts/proxies/smart-proxy/utils/route-validators.ts +0 -283
package/readme.md CHANGED
@@ -2,32 +2,40 @@
2
2
 
3
3
  **The Swiss Army Knife of Node.js Proxies** - A unified, high-performance proxy toolkit that handles everything from simple HTTP forwarding to complex enterprise routing scenarios.
4
4
 
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install @push.rocks/smartproxy
9
+ # or
10
+ pnpm add @push.rocks/smartproxy
11
+ ```
12
+
13
+ ## Issue Reporting and Security
14
+
15
+ For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
16
+
5
17
  ## 🎯 What is SmartProxy?
6
18
 
7
19
  SmartProxy is a modern, production-ready proxy solution that brings order to the chaos of traffic management. Whether you're building microservices, deploying edge infrastructure, or need a battle-tested reverse proxy, SmartProxy has you covered.
8
20
 
9
21
  ### ⚡ Key Features
10
22
 
11
- - **🔀 Unified Route-Based Configuration** - Clean match/action patterns for intuitive traffic routing
12
- - **🔒 Automatic SSL/TLS with Let's Encrypt** - Zero-config HTTPS with automatic certificate provisioning
13
- - **🎯 Flexible Matching Patterns** - Route by port, domain, path, client IP, TLS version, or custom logic
14
- - **🚄 High-Performance Forwarding** - Choose between user-space or kernel-level (NFTables) forwarding
15
- - **⚖️ Built-in Load Balancing** - Distribute traffic across multiple backends with health checks
16
- - **🛡️ Enterprise Security** - IP filtering, rate limiting, authentication, and connection limits
17
- - **🔌 WebSocket Support** - First-class WebSocket proxying with ping/pong management
18
- - **🎮 Custom Socket Handlers** - Implement any protocol with full socket control
19
- - **📊 Dynamic Port Management** - Add/remove ports at runtime without restarts
20
- - **🔧 Protocol Detection** - Smart protocol detection for mixed-mode operation
21
-
22
- ## 📦 Installation
23
-
24
- ```bash
25
- npm install @push.rocks/smartproxy
26
- ```
23
+ | Feature | Description |
24
+ |---------|-------------|
25
+ | 🔀 **Unified Route-Based Config** | Clean match/action patterns for intuitive traffic routing |
26
+ | 🔒 **Automatic SSL/TLS** | Zero-config HTTPS with Let's Encrypt ACME integration |
27
+ | 🎯 **Flexible Matching** | Route by port, domain, path, client IP, TLS version, or custom logic |
28
+ | 🚄 **High-Performance** | Choose between user-space or kernel-level (NFTables) forwarding |
29
+ | ⚖️ **Load Balancing** | Distribute traffic with health checks and multiple algorithms |
30
+ | 🛡️ **Enterprise Security** | IP filtering, rate limiting, authentication, connection limits |
31
+ | 🔌 **WebSocket Support** | First-class WebSocket proxying with ping/pong keep-alive |
32
+ | 🎮 **Custom Protocols** | Socket handlers for implementing any protocol |
33
+ | 📊 **Live Metrics** | Real-time throughput, connection counts, and performance data |
34
+ | 🔧 **Dynamic Management** | Add/remove ports and routes at runtime without restarts |
27
35
 
28
36
  ## 🚀 Quick Start
29
37
 
30
- Let's get you up and running in 30 seconds:
38
+ Get up and running in 30 seconds:
31
39
 
32
40
  ```typescript
33
41
  import { SmartProxy, createCompleteHttpsServer } from '@push.rocks/smartproxy';
@@ -35,14 +43,14 @@ import { SmartProxy, createCompleteHttpsServer } from '@push.rocks/smartproxy';
35
43
  // Create a proxy with automatic HTTPS
36
44
  const proxy = new SmartProxy({
37
45
  acme: {
38
- email: 'ssl@example.com', // Your email for Let's Encrypt
39
- useProduction: true // Use Let's Encrypt production servers
46
+ email: 'ssl@yourdomain.com', // Your email for Let's Encrypt
47
+ useProduction: true // Use production servers
40
48
  },
41
49
  routes: [
42
- // Complete HTTPS setup with one line
43
- ...createCompleteHttpsServer('app.example.com', {
44
- host: 'localhost',
45
- port: 3000
50
+ // Complete HTTPS setup in one line! ✨
51
+ ...createCompleteHttpsServer('app.example.com', {
52
+ host: 'localhost',
53
+ port: 3000
46
54
  }, {
47
55
  certificate: 'auto' // Magic! 🎩
48
56
  })
@@ -57,10 +65,11 @@ console.log('🚀 Proxy running with automatic HTTPS!');
57
65
 
58
66
  ### 🏗️ Route-Based Architecture
59
67
 
60
- SmartProxy uses a powerful match/action pattern that makes routing predictable and maintainable:
68
+ SmartProxy uses a powerful **match/action** pattern that makes routing predictable and maintainable:
61
69
 
62
70
  ```typescript
63
71
  {
72
+ name: 'api-route',
64
73
  match: {
65
74
  ports: 443,
66
75
  domains: 'api.example.com',
@@ -74,22 +83,31 @@ SmartProxy uses a powerful match/action pattern that makes routing predictable a
74
83
  }
75
84
  ```
76
85
 
77
- Every route has:
78
- - **Match criteria** - What traffic to capture
79
- - **Action** - What to do with it
80
- - **Security** (optional) - Access controls and limits
81
- - **Metadata** (optional) - Name, priority, tags
86
+ Every route consists of:
87
+ - **Match** - What traffic to capture (ports, domains, paths, IPs)
88
+ - **Action** - What to do with it (forward, redirect, block, socket-handler)
89
+ - **Security** (optional) - Access controls, rate limits, authentication
90
+ - **Name/Priority** (optional) - For identification and ordering
91
+
92
+ ### 🔄 TLS Modes
93
+
94
+ SmartProxy supports three TLS handling modes:
95
+
96
+ | Mode | Description | Use Case |
97
+ |------|-------------|----------|
98
+ | `passthrough` | Forward encrypted traffic as-is | Backend handles TLS |
99
+ | `terminate` | Decrypt at proxy, forward plain | Standard reverse proxy |
100
+ | `terminate-and-reencrypt` | Decrypt, then re-encrypt to backend | Zero-trust environments |
82
101
 
83
102
  ## 💡 Common Use Cases
84
103
 
85
- ### 🌐 Simple HTTP to HTTPS Redirect
104
+ ### 🌐 HTTP to HTTPS Redirect
86
105
 
87
106
  ```typescript
88
107
  import { SmartProxy, createHttpToHttpsRedirect } from '@push.rocks/smartproxy';
89
108
 
90
109
  const proxy = new SmartProxy({
91
110
  routes: [
92
- // Redirect all HTTP traffic to HTTPS
93
111
  createHttpToHttpsRedirect(['example.com', '*.example.com'])
94
112
  ]
95
113
  });
@@ -133,7 +151,8 @@ const route = createWebSocketRoute(
133
151
  path: '/socket',
134
152
  useTls: true,
135
153
  certificate: 'auto',
136
- pingInterval: 30000 // Keep connections alive
154
+ pingInterval: 30000, // Keep connections alive
155
+ pingTimeout: 10000
137
156
  }
138
157
  );
139
158
  ```
@@ -154,51 +173,64 @@ let route = createApiGatewayRoute(
154
173
  }
155
174
  );
156
175
 
157
- // Add rate limiting
176
+ // Add rate limiting - 100 requests per minute per IP
158
177
  route = addRateLimiting(route, {
159
178
  maxRequests: 100,
160
- window: 60, // seconds
179
+ window: 60,
161
180
  keyBy: 'ip'
162
181
  });
163
182
  ```
164
183
 
165
184
  ### 🎮 Custom Protocol Handler
166
185
 
186
+ SmartProxy lets you implement any protocol with full socket control:
187
+
167
188
  ```typescript
168
189
  import { createSocketHandlerRoute, SocketHandlers } from '@push.rocks/smartproxy';
169
190
 
170
- // Pre-built handlers
191
+ // Use pre-built handlers
171
192
  const echoRoute = createSocketHandlerRoute(
172
- 'echo.example.com',
173
- 7777,
193
+ 'echo.example.com',
194
+ 7777,
174
195
  SocketHandlers.echo
175
196
  );
176
197
 
177
- // Custom handler
198
+ // Or create your own custom protocol
178
199
  const customRoute = createSocketHandlerRoute(
179
200
  'custom.example.com',
180
201
  9999,
181
202
  async (socket, context) => {
182
203
  console.log(`Connection from ${context.clientIp}`);
183
-
184
204
  socket.write('Welcome to my custom protocol!\n');
185
-
205
+
186
206
  socket.on('data', (data) => {
187
207
  const command = data.toString().trim();
188
-
189
- if (command === 'HELLO') {
190
- socket.write('World!\n');
191
- } else if (command === 'EXIT') {
192
- socket.end('Goodbye!\n');
208
+ switch (command) {
209
+ case 'PING': socket.write('PONG\n'); break;
210
+ case 'TIME': socket.write(`${new Date().toISOString()}\n`); break;
211
+ case 'QUIT': socket.end('Goodbye!\n'); break;
212
+ default: socket.write(`Unknown: ${command}\n`);
193
213
  }
194
214
  });
195
215
  }
196
216
  );
197
217
  ```
198
218
 
219
+ **Pre-built Socket Handlers:**
220
+
221
+ | Handler | Description |
222
+ |---------|-------------|
223
+ | `SocketHandlers.echo` | Echo server - returns everything sent |
224
+ | `SocketHandlers.proxy(host, port)` | TCP proxy to another server |
225
+ | `SocketHandlers.lineProtocol(handler)` | Line-based text protocol |
226
+ | `SocketHandlers.httpResponse(code, body)` | Simple HTTP response |
227
+ | `SocketHandlers.httpRedirect(url, code)` | HTTP redirect with templates |
228
+ | `SocketHandlers.httpServer(handler)` | Full HTTP request/response handling |
229
+ | `SocketHandlers.block(message)` | Block with optional message |
230
+
199
231
  ### ⚡ High-Performance NFTables Forwarding
200
232
 
201
- For ultra-low latency, use kernel-level forwarding (Linux only, requires root):
233
+ For ultra-low latency on Linux, use kernel-level forwarding (requires root):
202
234
 
203
235
  ```typescript
204
236
  import { createNfTablesTerminateRoute } from '@push.rocks/smartproxy';
@@ -209,8 +241,8 @@ const route = createNfTablesTerminateRoute(
209
241
  {
210
242
  ports: 443,
211
243
  certificate: 'auto',
212
- preserveSourceIP: true,
213
- maxRate: '1gbps'
244
+ preserveSourceIP: true, // Backend sees real client IP
245
+ maxRate: '1gbps' // QoS rate limiting
214
246
  }
215
247
  );
216
248
  ```
@@ -223,21 +255,18 @@ Route traffic based on runtime conditions:
223
255
 
224
256
  ```typescript
225
257
  {
258
+ name: 'business-hours-only',
226
259
  match: {
227
260
  ports: 443,
228
- customMatcher: async (context) => {
229
- // Route based on time of day
230
- const hour = new Date().getHours();
231
- return hour >= 9 && hour < 17; // Business hours only
232
- }
261
+ domains: 'internal.example.com'
233
262
  },
234
263
  action: {
235
264
  type: 'forward',
236
265
  targets: [{
237
266
  host: (context) => {
238
- // Dynamic host selection
239
- return context.path.startsWith('/premium')
240
- ? 'premium-backend'
267
+ // Dynamic host selection based on path
268
+ return context.path?.startsWith('/premium')
269
+ ? 'premium-backend'
241
270
  : 'standard-backend';
242
271
  },
243
272
  port: 8080
@@ -248,30 +277,29 @@ Route traffic based on runtime conditions:
248
277
 
249
278
  ### 🔒 Security Controls
250
279
 
251
- Comprehensive security options per route:
280
+ Comprehensive per-route security options:
252
281
 
253
282
  ```typescript
254
283
  {
284
+ name: 'secure-api',
285
+ match: { ports: 443, domains: 'api.example.com' },
286
+ action: {
287
+ type: 'forward',
288
+ targets: [{ host: 'api-backend', port: 8080 }]
289
+ },
255
290
  security: {
256
291
  // IP-based access control
257
292
  ipAllowList: ['10.0.0.0/8', '192.168.*'],
258
293
  ipBlockList: ['192.168.1.100'],
259
-
294
+
260
295
  // Connection limits
261
296
  maxConnections: 1000,
262
297
  maxConnectionsPerIp: 10,
263
-
298
+
264
299
  // Rate limiting
265
300
  rateLimit: {
266
301
  maxRequests: 100,
267
302
  windowMs: 60000
268
- },
269
-
270
- // Authentication
271
- authentication: {
272
- type: 'jwt',
273
- secret: process.env.JWT_SECRET,
274
- algorithms: ['HS256']
275
303
  }
276
304
  }
277
305
  }
@@ -282,7 +310,7 @@ Comprehensive security options per route:
282
310
  Control your proxy without restarts:
283
311
 
284
312
  ```typescript
285
- // Add/remove ports dynamically
313
+ // Dynamic port management
286
314
  await proxy.addListeningPort(8443);
287
315
  await proxy.removeListeningPort(8080);
288
316
 
@@ -291,25 +319,31 @@ await proxy.updateRoutes([...newRoutes]);
291
319
 
292
320
  // Monitor status
293
321
  const status = proxy.getStatus();
322
+ console.log(`Active connections: ${status.activeConnections}`);
323
+
324
+ // Get detailed metrics
294
325
  const metrics = proxy.getMetrics();
326
+ console.log(`Throughput: ${metrics.throughput.bytesPerSecond} bytes/sec`);
295
327
 
296
328
  // Certificate management
297
- await proxy.renewCertificate('example.com');
298
329
  const certInfo = proxy.getCertificateInfo('example.com');
330
+ console.log(`Certificate expires: ${certInfo.expiresAt}`);
299
331
  ```
300
332
 
301
333
  ### 🔄 Header Manipulation
302
334
 
303
- Transform requests and responses:
335
+ Transform requests and responses with template variables:
304
336
 
305
337
  ```typescript
306
338
  {
307
339
  action: {
340
+ type: 'forward',
341
+ targets: [{ host: 'backend', port: 8080 }],
308
342
  headers: {
309
343
  request: {
310
- 'X-Real-IP': '{clientIp}', // Template variables
344
+ 'X-Real-IP': '{clientIp}',
311
345
  'X-Request-ID': '{uuid}',
312
- 'X-Custom': 'value'
346
+ 'X-Forwarded-Proto': 'https'
313
347
  },
314
348
  response: {
315
349
  'X-Powered-By': 'SmartProxy',
@@ -327,13 +361,15 @@ SmartProxy is built with a modular, extensible architecture:
327
361
 
328
362
  ```
329
363
  SmartProxy
330
- ├── 📋 Route Manager # Route matching and prioritization
331
- ├── 🔌 Port Manager # Dynamic port lifecycle
332
- ├── 🔒 Certificate Manager # ACME/Let's Encrypt automation
333
- ├── 🚦 Connection Manager # Connection pooling and limits
334
- ├── 📊 Metrics Collector # Performance monitoring
335
- ├── 🛡️ Security Manager # Access control and rate limiting
336
- └── 🔧 Protocol Detectors # Smart protocol identification
364
+ ├── 📋 RouteManager # Route matching and prioritization
365
+ ├── 🔌 PortManager # Dynamic port lifecycle management
366
+ ├── 🔒 SmartCertManager # ACME/Let's Encrypt automation
367
+ ├── 🚦 ConnectionManager # Connection pooling and tracking
368
+ ├── 📊 MetricsCollector # Real-time performance monitoring
369
+ ├── 🛡️ SecurityManager # Access control and rate limiting
370
+ ├── 🔧 ProtocolDetector # Smart HTTP/TLS/WebSocket detection
371
+ ├── ⚡ NFTablesManager # Kernel-level forwarding (Linux)
372
+ └── 🌐 HttpProxyBridge # HTTP/HTTPS request handling
337
373
  ```
338
374
 
339
375
  ## 🎯 Route Configuration Reference
@@ -346,87 +382,115 @@ interface IRouteMatch {
346
382
  domains?: string | string[]; // 'example.com', '*.example.com'
347
383
  path?: string; // '/api/*', '/users/:id'
348
384
  clientIp?: string | string[]; // '10.0.0.0/8', ['192.168.*']
349
- protocol?: 'tcp' | 'udp' | 'http' | 'https' | 'ws' | 'wss';
350
385
  tlsVersion?: string | string[]; // ['TLSv1.2', 'TLSv1.3']
351
- customMatcher?: (context) => boolean; // Custom logic
352
386
  }
353
387
  ```
354
388
 
355
389
  ### Action Types
356
390
 
391
+ | Type | Description |
392
+ |------|-------------|
393
+ | `forward` | Proxy to one or more backend targets |
394
+ | `redirect` | HTTP redirect with status code |
395
+ | `block` | Block the connection |
396
+ | `socket-handler` | Custom socket handling function |
397
+
398
+ ### TLS Options
399
+
357
400
  ```typescript
358
- interface IRouteAction {
359
- type: 'forward' | 'redirect' | 'block' | 'socket-handler';
360
-
361
- // For 'forward'
362
- targets?: Array<{
363
- host: string | string[] | ((context) => string);
364
- port: number | ((context) => number);
365
- }>;
366
-
367
- // For 'redirect'
368
- redirectUrl?: string; // With {domain}, {path}, {clientIp} templates
369
- redirectCode?: number; // 301, 302, etc.
370
-
371
- // For 'socket-handler'
372
- socketHandler?: (socket, context) => void | Promise<void>;
373
-
374
- // TLS options
375
- tls?: {
376
- mode: 'terminate' | 'passthrough' | 'terminate-and-reencrypt';
377
- certificate: 'auto' | { key: string; cert: string };
378
- };
379
-
380
- // WebSocket options
381
- websocket?: {
382
- enabled: boolean;
383
- pingInterval?: number;
384
- pingTimeout?: number;
401
+ interface IRouteTls {
402
+ mode: 'passthrough' | 'terminate' | 'terminate-and-reencrypt';
403
+ certificate: 'auto' | { key: string; cert: string };
404
+ // For terminate-and-reencrypt:
405
+ reencrypt?: {
406
+ host: string;
407
+ port: number;
408
+ ca?: string; // Custom CA for backend
385
409
  };
386
410
  }
387
411
  ```
388
412
 
413
+ ## 🛠️ Helper Functions Reference
414
+
415
+ All helpers are fully typed and documented:
416
+
417
+ ```typescript
418
+ import {
419
+ // HTTP/HTTPS
420
+ createHttpRoute,
421
+ createHttpsTerminateRoute,
422
+ createHttpsPassthroughRoute,
423
+ createHttpToHttpsRedirect,
424
+ createCompleteHttpsServer,
425
+
426
+ // Load Balancing
427
+ createLoadBalancerRoute,
428
+ createSmartLoadBalancer,
429
+
430
+ // API & WebSocket
431
+ createApiRoute,
432
+ createApiGatewayRoute,
433
+ createWebSocketRoute,
434
+
435
+ // Custom Protocols
436
+ createSocketHandlerRoute,
437
+ SocketHandlers,
438
+
439
+ // NFTables (Linux)
440
+ createNfTablesRoute,
441
+ createNfTablesTerminateRoute,
442
+ createCompleteNfTablesHttpsServer,
443
+
444
+ // Dynamic Routing
445
+ createPortMappingRoute,
446
+ createOffsetPortMappingRoute,
447
+ createDynamicRoute,
448
+
449
+ // Security Modifiers
450
+ addRateLimiting,
451
+ addBasicAuth,
452
+ addJwtAuth
453
+ } from '@push.rocks/smartproxy';
454
+ ```
455
+
389
456
  ## 🐛 Troubleshooting
390
457
 
391
458
  ### Certificate Issues
392
- - ✅ Ensure domain points to your server
393
- - ✅ Port 80 must be accessible for ACME challenges
394
- - ✅ Check DNS propagation with `nslookup`
395
- - ✅ Verify email in ACME configuration
459
+ - ✅ Ensure domain DNS points to your server
460
+ - ✅ Port 80 must be accessible for ACME HTTP-01 challenges
461
+ - ✅ Check DNS propagation with `dig` or `nslookup`
462
+ - ✅ Verify the email in ACME configuration is valid
396
463
 
397
464
  ### Connection Problems
398
- - ✅ Check route priorities (higher = matched first)
399
- - ✅ Verify security rules aren't blocking
400
- - ✅ Test with `curl -v` for detailed output
401
- - ✅ Enable debug mode for verbose logging
465
+ - ✅ Check route priorities (higher number = matched first)
466
+ - ✅ Verify security rules aren't blocking legitimate traffic
467
+ - ✅ Test with `curl -v` for detailed connection output
468
+ - ✅ Enable debug logging for verbose output
402
469
 
403
470
  ### Performance Tuning
404
- - ✅ Use NFTables for high-traffic routes
405
- - ✅ Enable connection pooling
406
- - ✅ Adjust keep-alive settings
407
- - ✅ Monitor with built-in metrics
471
+ - ✅ Use NFTables forwarding for high-traffic routes (Linux only)
472
+ - ✅ Enable connection keep-alive where appropriate
473
+ - ✅ Monitor metrics to identify bottlenecks
474
+ - ✅ Adjust `maxConnections` based on your server resources
408
475
 
409
476
  ### Debug Mode
477
+
410
478
  ```typescript
411
479
  const proxy = new SmartProxy({
412
- debug: true, // Enable verbose logging
480
+ enableDetailedLogging: true, // Verbose connection logging
413
481
  routes: [...]
414
482
  });
415
483
  ```
416
484
 
417
- ## 🚀 Migration from v20.x to v21.x
418
-
419
- No breaking changes! v21.x adds enhanced socket cleanup, improved connection tracking, and better process exit handling.
420
-
421
485
  ## 🏆 Best Practices
422
486
 
423
- 1. **📝 Use Helper Functions** - They provide sensible defaults and prevent errors
424
- 2. **🎯 Set Route Priorities** - More specific routes should have higher priority
425
- 3. **🔒 Always Enable Security** - Use IP filtering and rate limiting for public services
426
- 4. **📊 Monitor Performance** - Use metrics to identify bottlenecks
427
- 5. **🔄 Regular Certificate Checks** - Monitor expiration and renewal status
428
- 6. **🛑 Graceful Shutdown** - Always call `proxy.stop()` for clean shutdown
429
- 7. **🎮 Test Your Routes** - Use the route testing utilities before production
487
+ 1. **📝 Use Helper Functions** - They provide sensible defaults and prevent common mistakes
488
+ 2. **🎯 Set Route Priorities** - More specific routes should have higher priority values
489
+ 3. **🔒 Enable Security** - Always use IP filtering and rate limiting for public services
490
+ 4. **📊 Monitor Metrics** - Use the built-in metrics to identify issues early
491
+ 5. **🔄 Certificate Monitoring** - Set up alerts for certificate expiration
492
+ 6. **🛑 Graceful Shutdown** - Always call `proxy.stop()` for clean connection termination
493
+ 7. **🔧 Test Routes** - Validate your route configurations before deploying to production
430
494
 
431
495
  ## 📖 API Documentation
432
496
 
@@ -434,74 +498,73 @@ No breaking changes! v21.x adds enhanced socket cleanup, improved connection tra
434
498
 
435
499
  ```typescript
436
500
  class SmartProxy {
437
- constructor(options: IRoutedSmartProxyOptions);
438
-
501
+ constructor(options: ISmartProxyOptions);
502
+
439
503
  // Lifecycle
440
504
  start(): Promise<void>;
441
505
  stop(): Promise<void>;
442
-
506
+
443
507
  // Route Management
444
508
  updateRoutes(routes: IRouteConfig[]): Promise<void>;
445
- addRoute(route: IRouteConfig): Promise<void>;
446
- removeRoute(routeName: string): Promise<void>;
447
- findMatchingRoute(context: Partial<IRouteContext>): IRouteConfig | null;
448
-
509
+
449
510
  // Port Management
450
511
  addListeningPort(port: number): Promise<void>;
451
512
  removeListeningPort(port: number): Promise<void>;
452
513
  getListeningPorts(): number[];
453
-
454
- // Certificate Management
455
- getCertificateInfo(domain: string): ICertificateInfo | null;
456
- renewCertificate(domain: string): Promise<void>;
457
-
514
+
458
515
  // Monitoring
459
516
  getStatus(): IProxyStatus;
460
- getMetrics(): IProxyMetrics;
517
+ getMetrics(): IMetrics;
518
+
519
+ // Certificate Management
520
+ getCertificateInfo(domain: string): ICertStatus | null;
461
521
  }
462
522
  ```
463
523
 
464
- ### Helper Functions
465
-
466
- All helper functions are fully typed and documented. Import them from the main package:
524
+ ### Configuration Options
467
525
 
468
526
  ```typescript
469
- import {
470
- createHttpRoute,
471
- createHttpsTerminateRoute,
472
- createHttpsPassthroughRoute,
473
- createHttpToHttpsRedirect,
474
- createCompleteHttpsServer,
475
- createLoadBalancerRoute,
476
- createApiRoute,
477
- createWebSocketRoute,
478
- createSocketHandlerRoute,
479
- createNfTablesRoute,
480
- createPortMappingRoute,
481
- createDynamicRoute,
482
- createApiGatewayRoute,
483
- addRateLimiting,
484
- addBasicAuth,
485
- addJwtAuth,
486
- SocketHandlers
487
- } from '@push.rocks/smartproxy';
527
+ interface ISmartProxyOptions {
528
+ routes: IRouteConfig[]; // Required: array of route configs
529
+
530
+ // ACME/Let's Encrypt
531
+ acme?: {
532
+ email: string; // Contact email
533
+ useProduction?: boolean; // Use production servers (default: false)
534
+ port?: number; // Challenge port (default: 80)
535
+ renewThresholdDays?: number; // Days before expiry to renew (default: 30)
536
+ };
537
+
538
+ // Defaults
539
+ defaults?: {
540
+ target?: { host: string; port: number };
541
+ security?: IRouteSecurity;
542
+ tls?: IRouteTls;
543
+ };
544
+
545
+ // Behavior
546
+ enableDetailedLogging?: boolean;
547
+ gracefulShutdownTimeout?: number; // ms to wait for connections to close
548
+ }
488
549
  ```
489
550
 
490
551
  ## License and Legal Information
491
552
 
492
- This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
553
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
493
554
 
494
555
  **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
495
556
 
496
557
  ### Trademarks
497
558
 
498
- This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
559
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
560
+
561
+ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
499
562
 
500
563
  ### Company Information
501
564
 
502
- Task Venture Capital GmbH
503
- Registered at District court Bremen HRB 35230 HB, Germany
565
+ Task Venture Capital GmbH
566
+ Registered at District Court Bremen HRB 35230 HB, Germany
504
567
 
505
- For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
568
+ For any legal inquiries or further information, please contact us via email at hello@task.vc.
506
569
 
507
- By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
570
+ By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartproxy',
6
- version: '21.1.6',
6
+ version: '22.4.2',
7
7
  description: 'A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.'
8
8
  }