@push.rocks/smartproxy 15.0.2 → 16.0.3

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 (160) 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/core/models/index.d.ts +2 -0
  8. package/dist_ts/core/models/index.js +3 -1
  9. package/dist_ts/core/models/route-context.d.ts +62 -0
  10. package/dist_ts/core/models/route-context.js +43 -0
  11. package/dist_ts/core/models/socket-augmentation.d.ts +12 -0
  12. package/dist_ts/core/models/socket-augmentation.js +18 -0
  13. package/dist_ts/core/utils/event-system.d.ts +200 -0
  14. package/dist_ts/core/utils/event-system.js +224 -0
  15. package/dist_ts/core/utils/index.d.ts +7 -0
  16. package/dist_ts/core/utils/index.js +8 -1
  17. package/dist_ts/core/utils/route-manager.d.ts +118 -0
  18. package/dist_ts/core/utils/route-manager.js +383 -0
  19. package/dist_ts/core/utils/route-utils.d.ts +94 -0
  20. package/dist_ts/core/utils/route-utils.js +264 -0
  21. package/dist_ts/core/utils/security-utils.d.ts +111 -0
  22. package/dist_ts/core/utils/security-utils.js +212 -0
  23. package/dist_ts/core/utils/shared-security-manager.d.ts +110 -0
  24. package/dist_ts/core/utils/shared-security-manager.js +252 -0
  25. package/dist_ts/core/utils/template-utils.d.ts +37 -0
  26. package/dist_ts/core/utils/template-utils.js +104 -0
  27. package/dist_ts/core/utils/websocket-utils.d.ts +23 -0
  28. package/dist_ts/core/utils/websocket-utils.js +86 -0
  29. package/dist_ts/forwarding/config/forwarding-types.d.ts +40 -76
  30. package/dist_ts/forwarding/config/forwarding-types.js +19 -18
  31. package/dist_ts/forwarding/config/index.d.ts +4 -2
  32. package/dist_ts/forwarding/config/index.js +5 -3
  33. package/dist_ts/forwarding/handlers/base-handler.js +3 -1
  34. package/dist_ts/forwarding/index.d.ts +5 -6
  35. package/dist_ts/forwarding/index.js +3 -3
  36. package/dist_ts/http/models/http-types.js +1 -1
  37. package/dist_ts/http/port80/acme-interfaces.d.ts +30 -0
  38. package/dist_ts/http/port80/acme-interfaces.js +46 -1
  39. package/dist_ts/http/port80/port80-handler.d.ts +17 -2
  40. package/dist_ts/http/port80/port80-handler.js +49 -11
  41. package/dist_ts/http/router/index.d.ts +5 -1
  42. package/dist_ts/http/router/index.js +4 -2
  43. package/dist_ts/http/router/route-router.d.ts +108 -0
  44. package/dist_ts/http/router/route-router.js +393 -0
  45. package/dist_ts/index.d.ts +8 -2
  46. package/dist_ts/index.js +10 -3
  47. package/dist_ts/proxies/index.d.ts +7 -2
  48. package/dist_ts/proxies/index.js +10 -4
  49. package/dist_ts/proxies/network-proxy/certificate-manager.d.ts +21 -0
  50. package/dist_ts/proxies/network-proxy/certificate-manager.js +92 -1
  51. package/dist_ts/proxies/network-proxy/context-creator.d.ts +34 -0
  52. package/dist_ts/proxies/network-proxy/context-creator.js +108 -0
  53. package/dist_ts/proxies/network-proxy/function-cache.d.ts +90 -0
  54. package/dist_ts/proxies/network-proxy/function-cache.js +198 -0
  55. package/dist_ts/proxies/network-proxy/http-request-handler.d.ts +40 -0
  56. package/dist_ts/proxies/network-proxy/http-request-handler.js +256 -0
  57. package/dist_ts/proxies/network-proxy/http2-request-handler.d.ts +24 -0
  58. package/dist_ts/proxies/network-proxy/http2-request-handler.js +201 -0
  59. package/dist_ts/proxies/network-proxy/models/types.d.ts +73 -1
  60. package/dist_ts/proxies/network-proxy/models/types.js +242 -1
  61. package/dist_ts/proxies/network-proxy/network-proxy.d.ts +23 -20
  62. package/dist_ts/proxies/network-proxy/network-proxy.js +147 -60
  63. package/dist_ts/proxies/network-proxy/request-handler.d.ts +38 -5
  64. package/dist_ts/proxies/network-proxy/request-handler.js +584 -198
  65. package/dist_ts/proxies/network-proxy/security-manager.d.ts +65 -0
  66. package/dist_ts/proxies/network-proxy/security-manager.js +255 -0
  67. package/dist_ts/proxies/network-proxy/websocket-handler.d.ts +13 -2
  68. package/dist_ts/proxies/network-proxy/websocket-handler.js +238 -20
  69. package/dist_ts/proxies/smart-proxy/index.d.ts +1 -1
  70. package/dist_ts/proxies/smart-proxy/index.js +3 -3
  71. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -66
  72. package/dist_ts/proxies/smart-proxy/models/interfaces.js +5 -4
  73. package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +173 -6
  74. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +20 -7
  75. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +49 -108
  76. package/dist_ts/proxies/smart-proxy/port-manager.d.ts +81 -0
  77. package/dist_ts/proxies/smart-proxy/port-manager.js +166 -0
  78. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +7 -5
  79. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +155 -160
  80. package/dist_ts/proxies/smart-proxy/route-helpers/index.d.ts +9 -0
  81. package/dist_ts/proxies/smart-proxy/route-helpers/index.js +11 -0
  82. package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +5 -125
  83. package/dist_ts/proxies/smart-proxy/route-helpers.js +8 -195
  84. package/dist_ts/proxies/smart-proxy/route-manager.d.ts +14 -11
  85. package/dist_ts/proxies/smart-proxy/route-manager.js +81 -124
  86. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +101 -12
  87. package/dist_ts/proxies/smart-proxy/smart-proxy.js +178 -306
  88. package/dist_ts/proxies/smart-proxy/timeout-manager.js +3 -3
  89. package/dist_ts/proxies/smart-proxy/utils/index.d.ts +12 -0
  90. package/dist_ts/proxies/smart-proxy/utils/index.js +19 -0
  91. package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +240 -0
  92. package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +451 -0
  93. package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.d.ts +51 -0
  94. package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.js +124 -0
  95. package/dist_ts/proxies/smart-proxy/utils/route-patterns.d.ts +131 -0
  96. package/dist_ts/proxies/smart-proxy/utils/route-patterns.js +217 -0
  97. package/dist_ts/proxies/smart-proxy/utils/route-utils.d.ts +79 -0
  98. package/dist_ts/proxies/smart-proxy/utils/route-utils.js +266 -0
  99. package/dist_ts/proxies/smart-proxy/utils/route-validators.d.ts +73 -0
  100. package/dist_ts/proxies/smart-proxy/utils/route-validators.js +264 -0
  101. package/package.json +1 -1
  102. package/readme.md +241 -125
  103. package/readme.plan.md +73 -286
  104. package/ts/00_commitinfo_data.ts +1 -1
  105. package/ts/certificate/index.ts +17 -9
  106. package/ts/certificate/models/certificate-types.ts +37 -16
  107. package/ts/certificate/providers/cert-provisioner.ts +247 -54
  108. package/ts/core/models/index.ts +2 -0
  109. package/ts/core/models/route-context.ts +113 -0
  110. package/ts/core/models/socket-augmentation.ts +33 -0
  111. package/ts/core/utils/event-system.ts +376 -0
  112. package/ts/core/utils/index.ts +7 -0
  113. package/ts/core/utils/route-manager.ts +489 -0
  114. package/ts/core/utils/route-utils.ts +312 -0
  115. package/ts/core/utils/security-utils.ts +309 -0
  116. package/ts/core/utils/shared-security-manager.ts +333 -0
  117. package/ts/core/utils/template-utils.ts +124 -0
  118. package/ts/core/utils/websocket-utils.ts +81 -0
  119. package/ts/forwarding/config/forwarding-types.ts +79 -107
  120. package/ts/forwarding/config/index.ts +4 -2
  121. package/ts/forwarding/handlers/base-handler.ts +4 -2
  122. package/ts/forwarding/index.ts +3 -2
  123. package/ts/http/models/http-types.ts +0 -1
  124. package/ts/http/port80/acme-interfaces.ts +84 -0
  125. package/ts/http/port80/port80-handler.ts +61 -15
  126. package/ts/http/router/index.ts +8 -1
  127. package/ts/http/router/route-router.ts +482 -0
  128. package/ts/index.ts +14 -2
  129. package/ts/proxies/index.ts +12 -3
  130. package/ts/proxies/network-proxy/certificate-manager.ts +114 -10
  131. package/ts/proxies/network-proxy/context-creator.ts +145 -0
  132. package/ts/proxies/network-proxy/function-cache.ts +259 -0
  133. package/ts/proxies/network-proxy/http-request-handler.ts +330 -0
  134. package/ts/proxies/network-proxy/http2-request-handler.ts +255 -0
  135. package/ts/proxies/network-proxy/models/types.ts +312 -1
  136. package/ts/proxies/network-proxy/network-proxy.ts +195 -86
  137. package/ts/proxies/network-proxy/request-handler.ts +698 -246
  138. package/ts/proxies/network-proxy/security-manager.ts +298 -0
  139. package/ts/proxies/network-proxy/websocket-handler.ts +276 -33
  140. package/ts/proxies/smart-proxy/index.ts +2 -12
  141. package/ts/proxies/smart-proxy/models/interfaces.ts +13 -67
  142. package/ts/proxies/smart-proxy/models/route-types.ts +223 -25
  143. package/ts/proxies/smart-proxy/network-proxy-bridge.ts +57 -123
  144. package/ts/proxies/smart-proxy/port-manager.ts +195 -0
  145. package/ts/proxies/smart-proxy/route-connection-handler.ts +191 -225
  146. package/ts/proxies/smart-proxy/route-manager.ts +101 -144
  147. package/ts/proxies/smart-proxy/smart-proxy.ts +206 -377
  148. package/ts/proxies/smart-proxy/timeout-manager.ts +2 -2
  149. package/ts/proxies/smart-proxy/utils/index.ts +40 -0
  150. package/ts/proxies/smart-proxy/utils/route-helpers.ts +621 -0
  151. package/ts/proxies/smart-proxy/utils/route-migration-utils.ts +165 -0
  152. package/ts/proxies/smart-proxy/utils/route-patterns.ts +309 -0
  153. package/ts/proxies/smart-proxy/utils/route-utils.ts +330 -0
  154. package/ts/proxies/smart-proxy/utils/route-validators.ts +288 -0
  155. package/ts/forwarding/config/domain-config.ts +0 -28
  156. package/ts/forwarding/config/domain-manager.ts +0 -283
  157. package/ts/proxies/smart-proxy/connection-handler.ts +0 -1240
  158. package/ts/proxies/smart-proxy/domain-config-manager.ts +0 -441
  159. package/ts/proxies/smart-proxy/port-range-manager.ts +0 -211
  160. package/ts/proxies/smart-proxy/route-helpers.ts +0 -344
package/readme.plan.md CHANGED
@@ -1,316 +1,103 @@
1
- # SmartProxy Fully Unified Configuration Plan (Updated)
1
+ # SmartProxy Configuration Troubleshooting
2
2
 
3
- ## Project Goal
4
- Redesign SmartProxy's configuration for a more elegant, unified, and comprehensible approach by:
5
- 1. Creating a single, unified configuration model that covers both "where to listen" and "how to forward"
6
- 2. Eliminating the confusion between domain configs and port forwarding
7
- 3. Providing a clear, declarative API that makes the intent obvious
8
- 4. Enhancing maintainability and extensibility for future features
9
- 5. Completely removing legacy code to eliminate technical debt
3
+ ## IPv6/IPv4 Mapping Issue
10
4
 
11
- ## Current Issues
5
+ ### Problem Identified
6
+ The SmartProxy is failing to match connections for wildcard domains (like `*.lossless.digital`) when IP restrictions are in place. After extensive debugging, the root cause has been identified:
12
7
 
13
- The current approach has several issues:
8
+ When a connection comes in from an IPv4 address (e.g., `212.95.99.130`), the Node.js server receives it as an IPv6-mapped IPv4 address with the format `::ffff:212.95.99.130`. However, the route configuration is expecting the exact string `212.95.99.130`, causing a mismatch.
14
9
 
15
- 1. **Dual Configuration Systems**:
16
- - Port configuration (`fromPort`, `toPort`, `globalPortRanges`) for "where to listen"
17
- - Domain configuration (`domainConfigs`) for "how to forward"
18
- - Unclear relationship between these two systems
19
-
20
- 2. **Mixed Concerns**:
21
- - Port management is mixed with forwarding logic
22
- - Domain routing is separated from port listening
23
- - Security settings defined in multiple places
24
-
25
- 3. **Complex Logic**:
26
- - PortRangeManager must coordinate with domain configuration
27
- - Implicit rules for handling connections based on port and domain
28
-
29
- 4. **Difficult to Understand and Configure**:
30
- - Two separate configuration hierarchies that must work together
31
- - Unclear which settings take precedence
10
+ From the debug logs:
11
+ ```
12
+ [DEBUG] Route rejected: clientIp mismatch. Request: ::ffff:212.95.99.130, Route patterns: ["212.95.99.130"]
13
+ ```
32
14
 
33
- ## Proposed Solution: Fully Unified Routing Configuration
15
+ ### Solution
34
16
 
35
- Replace both port and domain configuration with a single, unified configuration:
17
+ To fix this issue, update the route configurations to include both formats of the IP address. Here's how to modify the affected route:
36
18
 
37
19
  ```typescript
38
- // The core unified configuration interface
39
- interface IRouteConfig {
40
- // What to match
20
+ // Wildcard domain route for *.lossless.digital
21
+ {
41
22
  match: {
42
- // Listen on these ports (required)
43
- ports: number | number[] | Array<{ from: number, to: number }>;
44
-
45
- // Optional domain patterns to match (default: all domains)
46
- domains?: string | string[];
47
-
48
- // Advanced matching criteria
49
- path?: string; // Match specific paths
50
- clientIp?: string[]; // Match specific client IPs
51
- tlsVersion?: string[]; // Match specific TLS versions
52
- };
53
-
54
- // What to do with matched traffic
23
+ ports: 443,
24
+ domains: ['*.lossless.digital'],
25
+ clientIp: ['212.95.99.130', '::ffff:212.95.99.130'], // Include both formats
26
+ },
55
27
  action: {
56
- // Basic routing
57
- type: 'forward' | 'redirect' | 'block';
58
-
59
- // Target for forwarding
60
- target?: {
61
- host: string | string[]; // Support single host or round-robin
62
- port: number;
63
- preservePort?: boolean; // Use incoming port as target port
64
- };
65
-
66
- // TLS handling
67
- tls?: {
68
- mode: 'passthrough' | 'terminate' | 'terminate-and-reencrypt';
69
- certificate?: 'auto' | { // Auto = use ACME
70
- key: string;
71
- cert: string;
72
- };
73
- };
74
-
75
- // For redirects
76
- redirect?: {
77
- to: string; // URL or template with {domain}, {port}, etc.
78
- status: 301 | 302 | 307 | 308;
79
- };
80
-
81
- // Security options
82
- security?: {
83
- allowedIps?: string[];
84
- blockedIps?: string[];
85
- maxConnections?: number;
86
- authentication?: {
87
- type: 'basic' | 'digest' | 'oauth';
88
- // Auth-specific options
89
- };
90
- };
91
-
92
- // Advanced options
93
- advanced?: {
94
- timeout?: number;
95
- headers?: Record<string, string>;
96
- keepAlive?: boolean;
97
- // etc.
98
- };
99
- };
100
-
101
- // Optional metadata
102
- name?: string; // Human-readable name for this route
103
- description?: string; // Description of the route's purpose
104
- priority?: number; // Controls matching order (higher = matched first)
105
- tags?: string[]; // Arbitrary tags for categorization
106
- }
107
-
108
- // Main SmartProxy options
109
- interface ISmartProxyOptions {
110
- // The unified configuration array (required)
111
- routes: IRouteConfig[];
112
-
113
- // Global/default settings
114
- defaults?: {
115
- target?: {
116
- host: string;
117
- port: number;
118
- };
119
- security?: {
120
- // Global security defaults
121
- };
122
- tls?: {
123
- // Global TLS defaults
124
- };
125
- // ...other defaults
126
- };
127
-
128
- // Other global settings remain (acme, etc.)
129
- acme?: IAcmeOptions;
130
-
131
- // Advanced settings remain as well
132
- // ...
28
+ type: 'forward',
29
+ target: {
30
+ host: '212.95.99.130',
31
+ port: 443
32
+ },
33
+ tls: {
34
+ mode: 'passthrough'
35
+ },
36
+ security: {
37
+ allowedIps: ['212.95.99.130', '::ffff:212.95.99.130'] // Include both formats
38
+ }
39
+ },
40
+ name: 'Wildcard lossless.digital route (IP restricted)'
133
41
  }
134
42
  ```
135
43
 
136
- ## Revised Implementation Plan
137
-
138
- ### Phase 1: Core Design & Interface Definition
139
-
140
- 1. **Define New Core Interfaces**:
141
- - Create `IRouteConfig` interface with `match` and `action` branches
142
- - Define all sub-interfaces for matching and actions
143
- - Create new `ISmartProxyOptions` to use `routes` array exclusively
144
- - Define template variable system for dynamic values
145
-
146
- 2. **Create Helper Functions**:
147
- - `createRoute()` - Basic route creation with reasonable defaults
148
- - `createHttpRoute()`, `createHttpsRoute()`, `createRedirect()` - Common scenarios
149
- - `createLoadBalancer()` - For multi-target setups
150
- - `mergeSecurity()`, `mergeDefaults()` - For combining configs
151
-
152
- 3. **Design Router**:
153
- - Decision tree for route matching algorithm
154
- - Priority system for route ordering
155
- - Optimized lookup strategy for fast routing
156
-
157
- ### Phase 2: Core Implementation
158
-
159
- 1. **Create RouteManager**:
160
- - Build a new RouteManager to replace both PortRangeManager and DomainConfigManager
161
- - Implement port and domain matching in one unified system
162
- - Create efficient route lookup algorithms
163
-
164
- 2. **Implement New ConnectionHandler**:
165
- - Create a new ConnectionHandler built from scratch for routes
166
- - Implement the routing logic with the new match/action pattern
167
- - Support template processing for headers and other dynamic values
168
-
169
- 3. **Implement New SmartProxy Core**:
170
- - Create new SmartProxy implementation using routes exclusively
171
- - Build network servers based on port specifications
172
- - Manage TLS contexts and certificates
173
-
174
- ### Phase 3: Legacy Code Removal
175
-
176
- 1. **Identify Legacy Components**:
177
- - Create an inventory of all files and components to be removed
178
- - Document dependencies between legacy components
179
- - Create a removal plan that minimizes disruption
44
+ ### Alternative Long-Term Fix
180
45
 
181
- 2. **Remove Legacy Components**:
182
- - Remove PortRangeManager and related code
183
- - Remove DomainConfigManager and related code
184
- - Remove old ConnectionHandler implementation
185
- - Remove other legacy components
46
+ A more robust solution would be to modify the SmartProxy codebase to automatically handle IPv6-mapped IPv4 addresses by normalizing them before comparison. This would involve:
186
47
 
187
- 3. **Clean Interface Adaptations**:
188
- - Remove all legacy interfaces and types
189
- - Update type exports to only expose route-based interfaces
190
- - Remove any adapter or backward compatibility code
48
+ 1. Modifying the `matchIpPattern` function in `route-manager.ts` to normalize IPv6-mapped IPv4 addresses:
191
49
 
192
- ### Phase 4: Updated Documentation & Examples
193
-
194
- 1. **Update Core Documentation**:
195
- - Rewrite README.md with a focus on route-based configuration exclusively
196
- - Create interface reference documentation
197
- - Document all template variables
198
-
199
- 2. **Create Example Library**:
200
- - Common configuration patterns using the new API
201
- - Complex use cases for advanced features
202
- - Infrastructure-as-code examples
203
-
204
- 3. **Add Validation Tools**:
205
- - Configuration validator to check for issues
206
- - Schema definitions for IDE autocomplete
207
- - Runtime validation helpers
208
-
209
- ### Phase 5: Testing
210
-
211
- 1. **Unit Tests**:
212
- - Test route matching logic
213
- - Validate priority handling
214
- - Test template processing
215
-
216
- 2. **Integration Tests**:
217
- - Verify full proxy flows with the new system
218
- - Test complex routing scenarios
219
- - Ensure all features work as expected
220
-
221
- 3. **Performance Testing**:
222
- - Benchmark routing performance
223
- - Evaluate memory usage
224
- - Test with large numbers of routes
225
-
226
- ## Implementation Strategy
227
-
228
- ### Code Organization
229
-
230
- 1. **New Files**:
231
- - `route-config.ts` - Core route interfaces
232
- - `route-manager.ts` - Route matching and management
233
- - `route-connection-handler.ts` - Connection handling with routes
234
- - `route-smart-proxy.ts` - Main SmartProxy implementation
235
- - `template-engine.ts` - For variable substitution
236
-
237
- 2. **File Removal**:
238
- - Remove `port-range-manager.ts`
239
- - Remove `domain-config-manager.ts`
240
- - Remove legacy interfaces and adapter code
241
- - Remove backward compatibility shims
242
-
243
- ### Transition Strategy
244
-
245
- 1. **Breaking Change Approach**:
246
- - This will be a major version update with breaking changes
247
- - No backward compatibility will be maintained
248
- - Clear migration documentation will guide users to the new API
249
-
250
- 2. **Package Structure**:
251
- - `@push.rocks/smartproxy` package will be updated to v14.0.0
252
- - Legacy code fully removed, only route-based API exposed
253
- - Support documentation provided for migration
254
-
255
- 3. **Migration Documentation**:
256
- - Provide a migration guide with examples
257
- - Show equivalent route configurations for common legacy patterns
258
- - Offer code transformation helpers for complex setups
50
+ ```typescript
51
+ private matchIpPattern(pattern: string, ip: string): boolean {
52
+ // Normalize IPv6-mapped IPv4 addresses
53
+ const normalizedIp = ip.startsWith('::ffff:') ? ip.substring(7) : ip;
54
+ const normalizedPattern = pattern.startsWith('::ffff:') ? pattern.substring(7) : pattern;
55
+
56
+ // Handle exact match with normalized addresses
57
+ if (normalizedPattern === normalizedIp) {
58
+ return true;
59
+ }
60
+
61
+ // Rest of the existing function...
62
+ }
63
+ ```
259
64
 
260
- ## Benefits of the Clean Approach
65
+ 2. Making similar modifications to other IP-related functions in the codebase.
261
66
 
262
- 1. **Reduced Complexity**:
263
- - No overlapping or conflicting configuration systems
264
- - No dual maintenance of backward compatibility code
265
- - Simplified internal architecture
67
+ ## Wild Card Domain Matching Issue
266
68
 
267
- 2. **Cleaner Code Base**:
268
- - Removal of technical debt
269
- - Better separation of concerns
270
- - More maintainable codebase
69
+ ### Explanation
271
70
 
272
- 3. **Better User Experience**:
273
- - Consistent, predictable API
274
- - No confusing overlapping options
275
- - Clear documentation of one approach, not two
71
+ The wildcard domain matching in SmartProxy works as follows:
276
72
 
277
- 4. **Future-Proof Design**:
278
- - Easier to extend with new features
279
- - Better performance without legacy overhead
280
- - Cleaner foundation for future enhancements
73
+ 1. When a pattern like `*.lossless.digital` is specified, it's converted to a regex: `/^.*\.lossless\.digital$/i`
74
+ 2. This correctly matches any subdomain like `my.lossless.digital`, `api.lossless.digital`, etc.
75
+ 3. However, it does NOT match the apex domain `lossless.digital` (without a subdomain)
281
76
 
282
- ## Migration Support
77
+ If you need to match both the apex domain and subdomains, use a list:
78
+ ```typescript
79
+ domains: ['lossless.digital', '*.lossless.digital']
80
+ ```
283
81
 
284
- While we're removing backward compatibility from the codebase, we'll provide extensive migration support:
82
+ ## Debugging SmartProxy
285
83
 
286
- 1. **Migration Guide**:
287
- - Detailed documentation on moving from legacy to route-based config
288
- - Pattern-matching examples for all common use cases
289
- - Troubleshooting guide for common migration issues
84
+ To debug routing issues in SmartProxy:
290
85
 
291
- 2. **Conversion Tool**:
292
- - Provide a standalone one-time conversion tool
293
- - Takes legacy configuration and outputs route-based equivalents
294
- - Will not be included in the main package to avoid bloat
86
+ 1. Add detailed logging to the `route-manager.js` file in the `dist_ts` directory:
87
+ - `findMatchingRoute` method - to see what criteria are being checked
88
+ - `matchRouteDomain` method - to see domain matching logic
89
+ - `matchDomain` method - to see pattern matching
90
+ - `matchIpPattern` method - to see IP matching logic
295
91
 
296
- 3. **Version Policy**:
297
- - Maintain the legacy version (13.x) for security updates
298
- - Make the route-based version a clear major version change (14.0.0)
299
- - Clearly communicate the breaking changes
92
+ 2. Run the proxy with debugging enabled:
93
+ ```
94
+ pnpm run startNew
95
+ ```
300
96
 
301
- ## Timeline and Versioning
97
+ 3. Monitor the logs for detailed information about the routing process and identify where matches are failing.
302
98
 
303
- 1. **Development**:
304
- - Develop route-based implementation in a separate branch
305
- - Complete full test coverage of new implementation
306
- - Ensure documentation is complete
99
+ ## Priority and Route Order
307
100
 
308
- 2. **Release**:
309
- - Release as version 14.0.0
310
- - Clearly mark as breaking change
311
- - Provide migration guide at release time
101
+ Remember that routes are evaluated in priority order (higher priority first). If multiple routes could match the same request, ensure that the more specific routes have higher priority.
312
102
 
313
- 3. **Support**:
314
- - Offer extended support for migration questions
315
- - Consider maintaining security updates for v13.x for 6 months
316
- - Focus active development on route-based version only
103
+ When routes have the same priority (or none specified), they're evaluated in the order they're defined in the configuration.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartproxy',
6
- version: '15.0.0',
6
+ version: '16.0.3',
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
  }
@@ -24,23 +24,31 @@ export * from './storage/file-storage.js';
24
24
 
25
25
  // Convenience function to create a certificate provisioner with common settings
26
26
  import { CertProvisioner } from './providers/cert-provisioner.js';
27
+ import type { TCertProvisionObject } from './providers/cert-provisioner.js';
27
28
  import { buildPort80Handler } from './acme/acme-factory.js';
28
- import type { IAcmeOptions, IDomainForwardConfig } from './models/certificate-types.js';
29
- import type { IDomainConfig } from '../forwarding/config/domain-config.js';
29
+ import type { IAcmeOptions, IRouteForwardConfig } from './models/certificate-types.js';
30
+ import type { IRouteConfig } from '../proxies/smart-proxy/models/route-types.js';
31
+
32
+ /**
33
+ * Interface for NetworkProxyBridge used by CertProvisioner
34
+ */
35
+ interface ICertNetworkProxyBridge {
36
+ applyExternalCertificate(certData: any): void;
37
+ }
30
38
 
31
39
  /**
32
40
  * Creates a complete certificate provisioning system with default settings
33
- * @param domainConfigs Domain configurations
41
+ * @param routeConfigs Route configurations that may need certificates
34
42
  * @param acmeOptions ACME options for certificate provisioning
35
43
  * @param networkProxyBridge Bridge to apply certificates to network proxy
36
44
  * @param certProvider Optional custom certificate provider
37
45
  * @returns Configured CertProvisioner
38
46
  */
39
47
  export function createCertificateProvisioner(
40
- domainConfigs: IDomainConfig[],
48
+ routeConfigs: IRouteConfig[],
41
49
  acmeOptions: IAcmeOptions,
42
- networkProxyBridge: any, // Placeholder until NetworkProxyBridge is migrated
43
- certProvider?: any // Placeholder until cert provider type is properly defined
50
+ networkProxyBridge: ICertNetworkProxyBridge,
51
+ certProvider?: (domain: string) => Promise<TCertProvisionObject>
44
52
  ): CertProvisioner {
45
53
  // Build the Port80Handler for ACME challenges
46
54
  const port80Handler = buildPort80Handler(acmeOptions);
@@ -50,18 +58,18 @@ export function createCertificateProvisioner(
50
58
  renewThresholdDays = 30,
51
59
  renewCheckIntervalHours = 24,
52
60
  autoRenew = true,
53
- domainForwards = []
61
+ routeForwards = []
54
62
  } = acmeOptions;
55
63
 
56
64
  // Create and return the certificate provisioner
57
65
  return new CertProvisioner(
58
- domainConfigs,
66
+ routeConfigs,
59
67
  port80Handler,
60
68
  networkProxyBridge,
61
69
  certProvider,
62
70
  renewThresholdDays,
63
71
  renewCheckIntervalHours,
64
72
  autoRenew,
65
- domainForwards
73
+ routeForwards
66
74
  );
67
75
  }
@@ -1,4 +1,5 @@
1
1
  import * as plugins from '../../plugins.js';
2
+ import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js';
2
3
 
3
4
  /**
4
5
  * Certificate data structure containing all necessary information
@@ -12,6 +13,11 @@ export interface ICertificateData {
12
13
  // Optional source and renewal information for event emissions
13
14
  source?: 'static' | 'http01' | 'dns01';
14
15
  isRenewal?: boolean;
16
+ // Reference to the route that requested this certificate (if available)
17
+ routeReference?: {
18
+ routeId?: string;
19
+ routeName?: string;
20
+ };
15
21
  }
16
22
 
17
23
  /**
@@ -29,6 +35,10 @@ export interface ICertificateFailure {
29
35
  domain: string;
30
36
  error: string;
31
37
  isRenewal: boolean;
38
+ routeReference?: {
39
+ routeId?: string;
40
+ routeName?: string;
41
+ };
32
42
  }
33
43
 
34
44
  /**
@@ -38,35 +48,46 @@ export interface ICertificateExpiring {
38
48
  domain: string;
39
49
  expiryDate: Date;
40
50
  daysRemaining: number;
51
+ routeReference?: {
52
+ routeId?: string;
53
+ routeName?: string;
54
+ };
41
55
  }
42
56
 
43
57
  /**
44
- * Domain forwarding configuration
58
+ * Route-specific forwarding configuration for ACME challenges
45
59
  */
46
- export interface IForwardConfig {
47
- ip: string;
48
- port: number;
49
- }
50
-
51
- /**
52
- * Domain-specific forwarding configuration for ACME challenges
53
- */
54
- export interface IDomainForwardConfig {
60
+ export interface IRouteForwardConfig {
55
61
  domain: string;
56
- forwardConfig?: IForwardConfig;
57
- acmeForwardConfig?: IForwardConfig;
62
+ target: {
63
+ host: string;
64
+ port: number;
65
+ };
58
66
  sslRedirect?: boolean;
59
67
  }
60
68
 
61
69
  /**
62
- * Domain configuration options
70
+ * Domain configuration options for Port80Handler
71
+ *
72
+ * This is used internally by the Port80Handler to manage domains
73
+ * but will eventually be replaced with route-based options.
63
74
  */
64
75
  export interface IDomainOptions {
65
76
  domainName: string;
66
77
  sslRedirect: boolean; // if true redirects the request to port 443
67
78
  acmeMaintenance: boolean; // tries to always have a valid cert for this domain
68
- forward?: IForwardConfig; // forwards all http requests to that target
69
- acmeForward?: IForwardConfig; // forwards letsencrypt requests to this config
79
+ forward?: {
80
+ ip: string;
81
+ port: number;
82
+ }; // forwards all http requests to that target
83
+ acmeForward?: {
84
+ ip: string;
85
+ port: number;
86
+ }; // forwards letsencrypt requests to this config
87
+ routeReference?: {
88
+ routeId?: string;
89
+ routeName?: string;
90
+ };
70
91
  }
71
92
 
72
93
  /**
@@ -83,6 +104,6 @@ export interface IAcmeOptions {
83
104
  autoRenew?: boolean; // Whether to automatically renew certificates
84
105
  certificateStore?: string; // Directory to store certificates
85
106
  skipConfiguredCerts?: boolean; // Skip domains with existing certificates
86
- domainForwards?: IDomainForwardConfig[]; // Domain-specific forwarding configs
107
+ routeForwards?: IRouteForwardConfig[]; // Route-specific forwarding configs
87
108
  }
88
109