@push.rocks/smartproxy 15.0.2 → 16.0.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 (80) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/certificate/index.d.ts +10 -4
  3. package/dist_ts/certificate/index.js +5 -7
  4. package/dist_ts/certificate/models/certificate-types.d.ts +35 -15
  5. package/dist_ts/certificate/providers/cert-provisioner.d.ts +41 -15
  6. package/dist_ts/certificate/providers/cert-provisioner.js +201 -41
  7. package/dist_ts/forwarding/config/forwarding-types.d.ts +40 -76
  8. package/dist_ts/forwarding/config/forwarding-types.js +19 -18
  9. package/dist_ts/forwarding/config/index.d.ts +4 -2
  10. package/dist_ts/forwarding/config/index.js +5 -3
  11. package/dist_ts/forwarding/handlers/base-handler.js +3 -1
  12. package/dist_ts/forwarding/index.d.ts +5 -6
  13. package/dist_ts/forwarding/index.js +3 -3
  14. package/dist_ts/http/models/http-types.js +1 -1
  15. package/dist_ts/http/port80/acme-interfaces.d.ts +30 -0
  16. package/dist_ts/http/port80/acme-interfaces.js +46 -1
  17. package/dist_ts/http/port80/port80-handler.d.ts +17 -2
  18. package/dist_ts/http/port80/port80-handler.js +49 -11
  19. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +2 -61
  20. package/dist_ts/proxies/smart-proxy/models/interfaces.js +5 -4
  21. package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +118 -4
  22. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +70 -4
  23. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +193 -43
  24. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +2 -5
  25. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +25 -146
  26. package/dist_ts/proxies/smart-proxy/route-helpers/index.d.ts +7 -0
  27. package/dist_ts/proxies/smart-proxy/route-helpers/index.js +9 -0
  28. package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +54 -1
  29. package/dist_ts/proxies/smart-proxy/route-helpers.js +102 -1
  30. package/dist_ts/proxies/smart-proxy/route-manager.d.ts +3 -9
  31. package/dist_ts/proxies/smart-proxy/route-manager.js +3 -115
  32. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +72 -10
  33. package/dist_ts/proxies/smart-proxy/smart-proxy.js +135 -268
  34. package/dist_ts/proxies/smart-proxy/timeout-manager.js +3 -3
  35. package/dist_ts/proxies/smart-proxy/utils/index.d.ts +12 -0
  36. package/dist_ts/proxies/smart-proxy/utils/index.js +19 -0
  37. package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +174 -0
  38. package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +332 -0
  39. package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.d.ts +51 -0
  40. package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.js +124 -0
  41. package/dist_ts/proxies/smart-proxy/utils/route-patterns.d.ts +131 -0
  42. package/dist_ts/proxies/smart-proxy/utils/route-patterns.js +217 -0
  43. package/dist_ts/proxies/smart-proxy/utils/route-utils.d.ts +79 -0
  44. package/dist_ts/proxies/smart-proxy/utils/route-utils.js +266 -0
  45. package/dist_ts/proxies/smart-proxy/utils/route-validators.d.ts +73 -0
  46. package/dist_ts/proxies/smart-proxy/utils/route-validators.js +242 -0
  47. package/package.json +1 -1
  48. package/readme.md +139 -111
  49. package/readme.plan.md +164 -312
  50. package/ts/00_commitinfo_data.ts +1 -1
  51. package/ts/certificate/index.ts +17 -9
  52. package/ts/certificate/models/certificate-types.ts +37 -16
  53. package/ts/certificate/providers/cert-provisioner.ts +247 -54
  54. package/ts/forwarding/config/forwarding-types.ts +79 -107
  55. package/ts/forwarding/config/index.ts +4 -2
  56. package/ts/forwarding/handlers/base-handler.ts +4 -2
  57. package/ts/forwarding/index.ts +3 -2
  58. package/ts/http/models/http-types.ts +0 -1
  59. package/ts/http/port80/acme-interfaces.ts +84 -0
  60. package/ts/http/port80/port80-handler.ts +61 -15
  61. package/ts/proxies/smart-proxy/models/interfaces.ts +7 -64
  62. package/ts/proxies/smart-proxy/models/route-types.ts +152 -22
  63. package/ts/proxies/smart-proxy/network-proxy-bridge.ts +226 -55
  64. package/ts/proxies/smart-proxy/route-connection-handler.ts +36 -205
  65. package/ts/proxies/smart-proxy/route-helpers/index.ts +9 -0
  66. package/ts/proxies/smart-proxy/route-helpers.ts +165 -11
  67. package/ts/proxies/smart-proxy/route-manager.ts +3 -130
  68. package/ts/proxies/smart-proxy/smart-proxy.ts +157 -329
  69. package/ts/proxies/smart-proxy/timeout-manager.ts +2 -2
  70. package/ts/proxies/smart-proxy/utils/index.ts +40 -0
  71. package/ts/proxies/smart-proxy/utils/route-helpers.ts +455 -0
  72. package/ts/proxies/smart-proxy/utils/route-migration-utils.ts +165 -0
  73. package/ts/proxies/smart-proxy/utils/route-patterns.ts +309 -0
  74. package/ts/proxies/smart-proxy/utils/route-utils.ts +330 -0
  75. package/ts/proxies/smart-proxy/utils/route-validators.ts +269 -0
  76. package/ts/forwarding/config/domain-config.ts +0 -28
  77. package/ts/forwarding/config/domain-manager.ts +0 -283
  78. package/ts/proxies/smart-proxy/connection-handler.ts +0 -1240
  79. package/ts/proxies/smart-proxy/port-range-manager.ts +0 -211
  80. /package/ts/proxies/smart-proxy/{domain-config-manager.ts → domain-config-manager.ts.bak} +0 -0
package/readme.md CHANGED
@@ -105,63 +105,86 @@ Install via npm:
105
105
  npm install @push.rocks/smartproxy
106
106
  ```
107
107
 
108
- ## Quick Start with SmartProxy v14.0.0
108
+ ## Quick Start with SmartProxy
109
109
 
110
- SmartProxy v14.0.0 introduces a new unified route-based configuration system that makes configuring proxies more flexible and intuitive.
110
+ SmartProxy v16.0.0 continues the evolution of the unified route-based configuration system making your proxy setup more flexible and intuitive with improved helper functions.
111
111
 
112
112
  ```typescript
113
- import {
114
- SmartProxy,
115
- createHttpRoute,
116
- createHttpsRoute,
117
- createPassthroughRoute,
118
- createHttpToHttpsRedirect
113
+ import {
114
+ SmartProxy,
115
+ createHttpRoute,
116
+ createHttpsTerminateRoute,
117
+ createHttpsPassthroughRoute,
118
+ createHttpToHttpsRedirect,
119
+ createCompleteHttpsServer,
120
+ createLoadBalancerRoute,
121
+ createStaticFileRoute,
122
+ createApiRoute,
123
+ createWebSocketRoute,
124
+ createSecurityConfig
119
125
  } from '@push.rocks/smartproxy';
120
126
 
121
127
  // Create a new SmartProxy instance with route-based configuration
122
128
  const proxy = new SmartProxy({
123
- // Define all your routing rules in one array
129
+ // Define all your routing rules in a single array
124
130
  routes: [
125
131
  // Basic HTTP route - forward traffic from port 80 to internal service
126
- createHttpRoute({
127
- ports: 80,
128
- domains: 'api.example.com',
129
- target: { host: 'localhost', port: 3000 }
130
- }),
132
+ createHttpRoute('api.example.com', { host: 'localhost', port: 3000 }),
131
133
 
132
134
  // HTTPS route with TLS termination and automatic certificates
133
- createHttpsRoute({
134
- ports: 443,
135
- domains: 'secure.example.com',
136
- target: { host: 'localhost', port: 8080 },
135
+ createHttpsTerminateRoute('secure.example.com', { host: 'localhost', port: 8080 }, {
137
136
  certificate: 'auto' // Use Let's Encrypt
138
137
  }),
139
138
 
140
139
  // HTTPS passthrough for legacy systems
141
- createPassthroughRoute({
142
- ports: 443,
143
- domains: 'legacy.example.com',
144
- target: { host: '192.168.1.10', port: 443 }
140
+ createHttpsPassthroughRoute('legacy.example.com', { host: '192.168.1.10', port: 443 }),
141
+
142
+ // Redirect HTTP to HTTPS for all domains and subdomains
143
+ createHttpToHttpsRedirect(['example.com', '*.example.com']),
144
+
145
+ // Complete HTTPS server (creates both HTTPS route and HTTP redirect)
146
+ ...createCompleteHttpsServer('complete.example.com', { host: 'localhost', port: 3000 }, {
147
+ certificate: 'auto'
145
148
  }),
146
149
 
147
- // Redirect HTTP to HTTPS
148
- createHttpToHttpsRedirect({
149
- domains: ['example.com', '*.example.com']
150
+ // API route with CORS headers
151
+ createApiRoute('api.service.com', '/v1', { host: 'api-backend', port: 8081 }, {
152
+ useTls: true,
153
+ certificate: 'auto',
154
+ addCorsHeaders: true
150
155
  }),
151
156
 
152
- // Complex load balancer setup with security controls
153
- createLoadBalancerRoute({
154
- domains: ['app.example.com'],
155
- targets: ['192.168.1.10', '192.168.1.11', '192.168.1.12'],
156
- targetPort: 8080,
157
- tlsMode: 'terminate',
157
+ // WebSocket route for real-time communication
158
+ createWebSocketRoute('ws.example.com', '/socket', { host: 'socket-server', port: 8082 }, {
159
+ useTls: true,
158
160
  certificate: 'auto',
159
- security: {
160
- allowedIps: ['10.0.0.*', '192.168.1.*'],
161
- blockedIps: ['1.2.3.4'],
162
- maxConnections: 1000
161
+ pingInterval: 30000
162
+ }),
163
+
164
+ // Static file server for web assets
165
+ createStaticFileRoute('static.example.com', '/var/www/html', {
166
+ serveOnHttps: true,
167
+ certificate: 'auto',
168
+ indexFiles: ['index.html', 'index.htm', 'default.html']
169
+ }),
170
+
171
+ // Load balancer with multiple backend servers
172
+ createLoadBalancerRoute(
173
+ 'app.example.com',
174
+ ['192.168.1.10', '192.168.1.11', '192.168.1.12'],
175
+ 8080,
176
+ {
177
+ tls: {
178
+ mode: 'terminate',
179
+ certificate: 'auto'
180
+ },
181
+ security: createSecurityConfig({
182
+ allowedIps: ['10.0.0.*', '192.168.1.*'],
183
+ blockedIps: ['1.2.3.4'],
184
+ maxConnections: 1000
185
+ })
163
186
  }
164
- })
187
+ )
165
188
  ],
166
189
 
167
190
  // Global settings that apply to all routes
@@ -189,9 +212,7 @@ await proxy.start();
189
212
 
190
213
  // Dynamically add new routes later
191
214
  await proxy.addRoutes([
192
- createHttpsRoute({
193
- domains: 'new-domain.com',
194
- target: { host: 'localhost', port: 9000 },
215
+ createHttpsTerminateRoute('new-domain.com', { host: 'localhost', port: 9000 }, {
195
216
  certificate: 'auto'
196
217
  })
197
218
  ]);
@@ -445,33 +466,33 @@ const route = {
445
466
  name: 'Web Server'
446
467
  };
447
468
 
448
- // Use the helper function:
449
- const route = createHttpRoute({
450
- domains: 'example.com',
451
- target: { host: 'localhost', port: 8080 },
469
+ // Use the helper function for cleaner syntax:
470
+ const route = createHttpRoute('example.com', { host: 'localhost', port: 8080 }, {
452
471
  name: 'Web Server'
453
472
  });
454
473
  ```
455
474
 
456
475
  Available helper functions:
457
- - `createRoute()` - Basic function to create any route configuration
458
476
  - `createHttpRoute()` - Create an HTTP forwarding route
459
- - `createHttpsRoute()` - Create an HTTPS route with TLS termination
460
- - `createPassthroughRoute()` - Create an HTTPS passthrough route
461
- - `createRedirectRoute()` - Create a generic redirect route
477
+ - `createHttpsTerminateRoute()` - Create an HTTPS route with TLS termination
478
+ - `createHttpsPassthroughRoute()` - Create an HTTPS passthrough route
462
479
  - `createHttpToHttpsRedirect()` - Create an HTTP to HTTPS redirect
480
+ - `createCompleteHttpsServer()` - Create a complete HTTPS server setup with HTTP redirect
481
+ - `createLoadBalancerRoute()` - Create a route for load balancing across multiple backends
482
+ - `createStaticFileRoute()` - Create a route for serving static files
483
+ - `createApiRoute()` - Create an API route with path matching and CORS support
484
+ - `createWebSocketRoute()` - Create a route for WebSocket connections
485
+ - `createPortRange()` - Helper to create port range configurations
486
+ - `createSecurityConfig()` - Helper to create security configuration objects
463
487
  - `createBlockRoute()` - Create a route to block specific traffic
464
- - `createLoadBalancerRoute()` - Create a route for load balancing
465
- - `createHttpsServer()` - Create a complete HTTPS server setup with HTTP redirect
488
+ - `createTestRoute()` - Create a test route for debugging and testing
466
489
 
467
490
  ## What You Can Do with SmartProxy
468
491
 
469
492
  1. **Route-Based Traffic Management**
470
493
  ```typescript
471
494
  // Route requests for different domains to different backend servers
472
- createHttpsRoute({
473
- domains: 'api.example.com',
474
- target: { host: 'api-server', port: 3000 },
495
+ createHttpsTerminateRoute('api.example.com', { host: 'api-server', port: 3000 }, {
475
496
  certificate: 'auto'
476
497
  })
477
498
  ```
@@ -479,9 +500,7 @@ Available helper functions:
479
500
  2. **Automatic SSL with Let's Encrypt**
480
501
  ```typescript
481
502
  // Get and automatically renew certificates
482
- createHttpsRoute({
483
- domains: 'secure.example.com',
484
- target: { host: 'localhost', port: 8080 },
503
+ createHttpsTerminateRoute('secure.example.com', { host: 'localhost', port: 8080 }, {
485
504
  certificate: 'auto'
486
505
  })
487
506
  ```
@@ -489,21 +508,23 @@ Available helper functions:
489
508
  3. **Load Balancing**
490
509
  ```typescript
491
510
  // Distribute traffic across multiple backend servers
492
- createLoadBalancerRoute({
493
- domains: 'app.example.com',
494
- targets: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
495
- targetPort: 8080,
496
- tlsMode: 'terminate',
497
- certificate: 'auto'
498
- })
511
+ createLoadBalancerRoute(
512
+ 'app.example.com',
513
+ ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
514
+ 8080,
515
+ {
516
+ tls: {
517
+ mode: 'terminate',
518
+ certificate: 'auto'
519
+ }
520
+ }
521
+ )
499
522
  ```
500
523
 
501
524
  4. **Security Controls**
502
525
  ```typescript
503
526
  // Restrict access based on IP addresses
504
- createHttpsRoute({
505
- domains: 'admin.example.com',
506
- target: { host: 'localhost', port: 8080 },
527
+ createHttpsTerminateRoute('admin.example.com', { host: 'localhost', port: 8080 }, {
507
528
  certificate: 'auto',
508
529
  security: {
509
530
  allowedIps: ['10.0.0.*', '192.168.1.*'],
@@ -515,19 +536,14 @@ Available helper functions:
515
536
  5. **Wildcard Domains**
516
537
  ```typescript
517
538
  // Handle all subdomains with one config
518
- createPassthroughRoute({
519
- domains: ['example.com', '*.example.com'],
520
- target: { host: 'backend-server', port: 443 }
521
- })
539
+ createHttpsPassthroughRoute(['example.com', '*.example.com'], { host: 'backend-server', port: 443 })
522
540
  ```
523
541
 
524
542
  6. **Path-Based Routing**
525
543
  ```typescript
526
544
  // Route based on URL path
527
- createHttpsRoute({
528
- domains: 'example.com',
529
- path: '/api/*',
530
- target: { host: 'api-server', port: 3000 },
545
+ createApiRoute('example.com', '/api', { host: 'api-server', port: 3000 }, {
546
+ useTls: true,
531
547
  certificate: 'auto'
532
548
  })
533
549
  ```
@@ -535,8 +551,7 @@ Available helper functions:
535
551
  7. **Block Malicious Traffic**
536
552
  ```typescript
537
553
  // Block traffic from specific IPs
538
- createBlockRoute({
539
- ports: [80, 443],
554
+ createBlockRoute([80, 443], {
540
555
  clientIp: ['1.2.3.*', '5.6.7.*'],
541
556
  priority: 1000 // High priority to ensure blocking
542
557
  })
@@ -607,19 +622,20 @@ const redirect = new SslRedirect(80);
607
622
  await redirect.start();
608
623
  ```
609
624
 
610
- ## Migration from v13.x to v14.0.0
625
+ ## Migration to v16.0.0
611
626
 
612
- Version 14.0.0 introduces a breaking change with the new route-based configuration system:
627
+ Version 16.0.0 completes the migration to a fully unified route-based configuration system with improved helper functions:
613
628
 
614
629
  ### Key Changes
615
630
 
616
- 1. **Configuration Structure**: The configuration now uses the match/action pattern instead of the old domain-based and port-based approach
617
- 2. **SmartProxy Options**: Now takes an array of route configurations instead of `domainConfigs` and port ranges
618
- 3. **Helper Functions**: New helper functions have been introduced to simplify configuration
631
+ 1. **Pure Route-Based API**: The configuration now exclusively uses the match/action pattern with no legacy interfaces
632
+ 2. **Improved Helper Functions**: Enhanced helper functions with cleaner parameter signatures
633
+ 3. **Removed Legacy Support**: Legacy domain-based APIs have been completely removed
634
+ 4. **More Route Pattern Helpers**: Additional helper functions for common routing patterns
619
635
 
620
636
  ### Migration Example
621
637
 
622
- **v13.x Configuration**:
638
+ **Legacy Configuration (pre-v14)**:
623
639
  ```typescript
624
640
  import { SmartProxy, createDomainConfig, httpOnly, tlsTerminateToHttp } from '@push.rocks/smartproxy';
625
641
 
@@ -635,29 +651,48 @@ const proxy = new SmartProxy({
635
651
  });
636
652
  ```
637
653
 
638
- **v14.0.0 Configuration**:
654
+ **Current Configuration (v16.0.0)**:
639
655
  ```typescript
640
- import { SmartProxy, createHttpsRoute } from '@push.rocks/smartproxy';
656
+ import { SmartProxy, createHttpsTerminateRoute } from '@push.rocks/smartproxy';
641
657
 
642
658
  const proxy = new SmartProxy({
643
659
  routes: [
644
- createHttpsRoute({
645
- ports: 443,
646
- domains: 'example.com',
647
- target: { host: 'localhost', port: 8080 },
660
+ createHttpsTerminateRoute('example.com', { host: 'localhost', port: 8080 }, {
648
661
  certificate: 'auto'
649
662
  })
650
- ]
663
+ ],
664
+ acme: {
665
+ enabled: true,
666
+ useProduction: true
667
+ }
651
668
  });
652
669
  ```
653
670
 
654
- ### Migration Steps
671
+ ### Migration from v14.x/v15.x to v16.0.0
672
+
673
+ If you're already using route-based configuration, update your helper function calls:
674
+
675
+ ```typescript
676
+ // Old v14.x/v15.x style:
677
+ createHttpsRoute({
678
+ domains: 'example.com',
679
+ target: { host: 'localhost', port: 8080 },
680
+ certificate: 'auto'
681
+ })
682
+
683
+ // New v16.0.0 style:
684
+ createHttpsTerminateRoute('example.com', { host: 'localhost', port: 8080 }, {
685
+ certificate: 'auto'
686
+ })
687
+ ```
688
+
689
+ ### Complete Migration Steps
655
690
 
656
- 1. Replace `domainConfigs` with an array of route configurations using `routes`
657
- 2. Convert each domain configuration to use the new helper functions
658
- 3. Update any code that uses `updateDomainConfigs()` to use `addRoutes()` or `updateRoutes()`
659
- 4. For port-only configurations, create route configurations with port matching only
660
- 5. For SNI-based routing, SNI is now automatically enabled when needed
691
+ 1. Replace any remaining `domainConfigs` with route-based configuration using the `routes` array
692
+ 2. Update helper function calls to use the newer parameter format (domain first, target second, options third)
693
+ 3. Use the new specific helper functions (e.g., `createHttpsTerminateRoute` instead of `createHttpsRoute`)
694
+ 4. Update any code that uses `updateDomainConfigs()` to use `addRoutes()` or `updateRoutes()`
695
+ 5. For port-only configurations, create route configurations with port matching only
661
696
 
662
697
  ## Architecture & Flow Diagrams
663
698
 
@@ -806,33 +841,26 @@ The SmartProxy component with route-based configuration offers a clean, unified
806
841
  Create a flexible API gateway to route traffic to different microservices based on domain and path:
807
842
 
808
843
  ```typescript
809
- import { SmartProxy, createHttpsRoute } from '@push.rocks/smartproxy';
844
+ import { SmartProxy, createApiRoute, createHttpsTerminateRoute } from '@push.rocks/smartproxy';
810
845
 
811
846
  const apiGateway = new SmartProxy({
812
847
  routes: [
813
848
  // Users API
814
- createHttpsRoute({
815
- ports: 443,
816
- domains: 'api.example.com',
817
- path: '/users/*',
818
- target: { host: 'users-service', port: 3000 },
819
- certificate: 'auto'
849
+ createApiRoute('api.example.com', '/users', { host: 'users-service', port: 3000 }, {
850
+ useTls: true,
851
+ certificate: 'auto',
852
+ addCorsHeaders: true
820
853
  }),
821
854
 
822
855
  // Products API
823
- createHttpsRoute({
824
- ports: 443,
825
- domains: 'api.example.com',
826
- path: '/products/*',
827
- target: { host: 'products-service', port: 3001 },
828
- certificate: 'auto'
856
+ createApiRoute('api.example.com', '/products', { host: 'products-service', port: 3001 }, {
857
+ useTls: true,
858
+ certificate: 'auto',
859
+ addCorsHeaders: true
829
860
  }),
830
861
 
831
862
  // Admin dashboard with extra security
832
- createHttpsRoute({
833
- ports: 443,
834
- domains: 'admin.example.com',
835
- target: { host: 'admin-dashboard', port: 8080 },
863
+ createHttpsTerminateRoute('admin.example.com', { host: 'admin-dashboard', port: 8080 }, {
836
864
  certificate: 'auto',
837
865
  security: {
838
866
  allowedIps: ['10.0.0.*', '192.168.1.*'] // Only allow internal network