@push.rocks/smartproxy 12.0.0 → 13.1.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 (258) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/certificate/acme/acme-factory.d.ts +17 -0
  3. package/dist_ts/certificate/acme/acme-factory.js +40 -0
  4. package/dist_ts/certificate/acme/challenge-handler.d.ts +44 -0
  5. package/dist_ts/certificate/acme/challenge-handler.js +92 -0
  6. package/dist_ts/certificate/acme/index.d.ts +4 -0
  7. package/dist_ts/certificate/acme/index.js +5 -0
  8. package/dist_ts/certificate/events/certificate-events.d.ts +33 -0
  9. package/dist_ts/certificate/events/certificate-events.js +38 -0
  10. package/dist_ts/certificate/index.d.ts +24 -0
  11. package/dist_ts/certificate/index.js +39 -0
  12. package/dist_ts/certificate/models/certificate-types.d.ts +77 -0
  13. package/dist_ts/certificate/models/certificate-types.js +2 -0
  14. package/dist_ts/certificate/providers/cert-provisioner.d.ts +93 -0
  15. package/dist_ts/certificate/providers/cert-provisioner.js +262 -0
  16. package/dist_ts/certificate/providers/index.d.ts +4 -0
  17. package/dist_ts/certificate/providers/index.js +5 -0
  18. package/dist_ts/certificate/storage/file-storage.d.ts +66 -0
  19. package/dist_ts/certificate/storage/file-storage.js +194 -0
  20. package/dist_ts/certificate/storage/index.d.ts +4 -0
  21. package/dist_ts/certificate/storage/index.js +5 -0
  22. package/dist_ts/certificate/utils/certificate-helpers.d.ts +17 -0
  23. package/dist_ts/certificate/utils/certificate-helpers.js +45 -0
  24. package/dist_ts/common/eventUtils.d.ts +1 -1
  25. package/dist_ts/common/port80-adapter.d.ts +1 -1
  26. package/dist_ts/core/events/index.d.ts +4 -0
  27. package/dist_ts/core/events/index.js +5 -0
  28. package/dist_ts/core/index.d.ts +6 -0
  29. package/dist_ts/core/index.js +8 -0
  30. package/dist_ts/core/models/common-types.d.ts +82 -0
  31. package/dist_ts/core/models/common-types.js +15 -0
  32. package/dist_ts/core/models/index.d.ts +4 -0
  33. package/dist_ts/core/models/index.js +5 -0
  34. package/dist_ts/core/utils/event-utils.d.ts +15 -0
  35. package/dist_ts/core/utils/event-utils.js +19 -0
  36. package/dist_ts/core/utils/index.d.ts +6 -0
  37. package/dist_ts/core/utils/index.js +7 -0
  38. package/dist_ts/core/utils/ip-utils.d.ts +53 -0
  39. package/dist_ts/core/utils/ip-utils.js +153 -0
  40. package/dist_ts/core/utils/validation-utils.d.ts +61 -0
  41. package/dist_ts/core/utils/validation-utils.js +149 -0
  42. package/dist_ts/forwarding/config/domain-config.d.ts +12 -0
  43. package/dist_ts/forwarding/config/domain-config.js +12 -0
  44. package/dist_ts/forwarding/config/domain-manager.d.ts +86 -0
  45. package/dist_ts/forwarding/config/domain-manager.js +242 -0
  46. package/dist_ts/forwarding/config/forwarding-types.d.ts +104 -0
  47. package/dist_ts/forwarding/config/forwarding-types.js +50 -0
  48. package/dist_ts/forwarding/config/index.d.ts +6 -0
  49. package/dist_ts/forwarding/config/index.js +7 -0
  50. package/dist_ts/forwarding/factory/forwarding-factory.d.ts +25 -0
  51. package/dist_ts/forwarding/factory/forwarding-factory.js +138 -0
  52. package/dist_ts/forwarding/factory/index.d.ts +4 -0
  53. package/dist_ts/forwarding/factory/index.js +5 -0
  54. package/dist_ts/forwarding/handlers/base-handler.d.ts +55 -0
  55. package/dist_ts/forwarding/handlers/base-handler.js +94 -0
  56. package/dist_ts/forwarding/handlers/http-handler.d.ts +30 -0
  57. package/dist_ts/forwarding/handlers/http-handler.js +131 -0
  58. package/dist_ts/forwarding/handlers/https-passthrough-handler.d.ts +29 -0
  59. package/dist_ts/forwarding/handlers/https-passthrough-handler.js +162 -0
  60. package/dist_ts/forwarding/handlers/https-terminate-to-http-handler.d.ts +36 -0
  61. package/dist_ts/forwarding/handlers/https-terminate-to-http-handler.js +229 -0
  62. package/dist_ts/forwarding/handlers/https-terminate-to-https-handler.d.ts +35 -0
  63. package/dist_ts/forwarding/handlers/https-terminate-to-https-handler.js +254 -0
  64. package/dist_ts/forwarding/handlers/index.d.ts +8 -0
  65. package/dist_ts/forwarding/handlers/index.js +9 -0
  66. package/dist_ts/forwarding/index.d.ts +19 -0
  67. package/dist_ts/forwarding/index.js +25 -0
  68. package/dist_ts/http/index.d.ts +15 -0
  69. package/dist_ts/http/index.js +20 -0
  70. package/dist_ts/http/models/http-types.d.ts +81 -0
  71. package/dist_ts/http/models/http-types.js +62 -0
  72. package/dist_ts/http/port80/acme-interfaces.d.ts +78 -0
  73. package/dist_ts/http/port80/acme-interfaces.js +6 -0
  74. package/dist_ts/http/port80/challenge-responder.d.ts +53 -0
  75. package/dist_ts/http/port80/challenge-responder.js +203 -0
  76. package/dist_ts/http/port80/index.d.ts +6 -0
  77. package/dist_ts/http/port80/index.js +9 -0
  78. package/dist_ts/http/port80/port80-handler.d.ts +121 -0
  79. package/dist_ts/http/port80/port80-handler.js +554 -0
  80. package/dist_ts/http/redirects/index.d.ts +4 -0
  81. package/dist_ts/http/redirects/index.js +5 -0
  82. package/dist_ts/http/router/index.d.ts +4 -0
  83. package/dist_ts/http/router/index.js +5 -0
  84. package/dist_ts/http/router/proxy-router.d.ts +115 -0
  85. package/dist_ts/http/router/proxy-router.js +325 -0
  86. package/dist_ts/index.d.ts +15 -8
  87. package/dist_ts/index.js +26 -10
  88. package/dist_ts/networkproxy/classes.np.certificatemanager.js +2 -2
  89. package/dist_ts/networkproxy/index.d.ts +1 -6
  90. package/dist_ts/networkproxy/index.js +4 -8
  91. package/dist_ts/plugins.d.ts +2 -1
  92. package/dist_ts/plugins.js +3 -2
  93. package/dist_ts/port80handler/classes.port80handler.d.ts +8 -136
  94. package/dist_ts/port80handler/classes.port80handler.js +14 -567
  95. package/dist_ts/proxies/index.d.ts +6 -0
  96. package/dist_ts/proxies/index.js +8 -0
  97. package/dist_ts/proxies/network-proxy/certificate-manager.d.ts +77 -0
  98. package/dist_ts/proxies/network-proxy/certificate-manager.js +373 -0
  99. package/dist_ts/proxies/network-proxy/connection-pool.d.ts +47 -0
  100. package/dist_ts/proxies/network-proxy/connection-pool.js +210 -0
  101. package/dist_ts/proxies/network-proxy/index.d.ts +10 -0
  102. package/dist_ts/proxies/network-proxy/index.js +12 -0
  103. package/dist_ts/proxies/network-proxy/models/index.d.ts +4 -0
  104. package/dist_ts/proxies/network-proxy/models/index.js +5 -0
  105. package/dist_ts/proxies/network-proxy/models/types.d.ts +80 -0
  106. package/dist_ts/proxies/network-proxy/models/types.js +35 -0
  107. package/dist_ts/proxies/network-proxy/network-proxy.d.ts +118 -0
  108. package/dist_ts/proxies/network-proxy/network-proxy.js +387 -0
  109. package/dist_ts/proxies/network-proxy/request-handler.d.ts +57 -0
  110. package/dist_ts/proxies/network-proxy/request-handler.js +394 -0
  111. package/dist_ts/proxies/network-proxy/websocket-handler.d.ts +38 -0
  112. package/dist_ts/proxies/network-proxy/websocket-handler.js +188 -0
  113. package/dist_ts/proxies/nftables-proxy/index.d.ts +5 -0
  114. package/dist_ts/proxies/nftables-proxy/index.js +6 -0
  115. package/dist_ts/proxies/nftables-proxy/models/errors.d.ts +15 -0
  116. package/dist_ts/proxies/nftables-proxy/models/errors.js +28 -0
  117. package/dist_ts/proxies/nftables-proxy/models/index.d.ts +5 -0
  118. package/dist_ts/proxies/nftables-proxy/models/index.js +6 -0
  119. package/dist_ts/proxies/nftables-proxy/models/interfaces.d.ts +75 -0
  120. package/dist_ts/proxies/nftables-proxy/models/interfaces.js +5 -0
  121. package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +136 -0
  122. package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +1516 -0
  123. package/dist_ts/proxies/smart-proxy/connection-handler.d.ts +39 -0
  124. package/dist_ts/proxies/smart-proxy/connection-handler.js +894 -0
  125. package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +78 -0
  126. package/dist_ts/proxies/smart-proxy/connection-manager.js +378 -0
  127. package/dist_ts/proxies/smart-proxy/domain-config-manager.d.ts +95 -0
  128. package/dist_ts/proxies/smart-proxy/domain-config-manager.js +255 -0
  129. package/dist_ts/proxies/smart-proxy/index.d.ts +13 -0
  130. package/dist_ts/proxies/smart-proxy/index.js +17 -0
  131. package/dist_ts/proxies/smart-proxy/models/index.d.ts +4 -0
  132. package/dist_ts/proxies/smart-proxy/models/index.js +5 -0
  133. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +107 -0
  134. package/dist_ts/proxies/smart-proxy/models/interfaces.js +2 -0
  135. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +62 -0
  136. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +316 -0
  137. package/dist_ts/proxies/smart-proxy/port-range-manager.d.ts +56 -0
  138. package/dist_ts/proxies/smart-proxy/port-range-manager.js +176 -0
  139. package/dist_ts/proxies/smart-proxy/security-manager.d.ts +64 -0
  140. package/dist_ts/proxies/smart-proxy/security-manager.js +149 -0
  141. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +63 -0
  142. package/dist_ts/proxies/smart-proxy/smart-proxy.js +523 -0
  143. package/dist_ts/proxies/smart-proxy/timeout-manager.d.ts +47 -0
  144. package/dist_ts/proxies/smart-proxy/timeout-manager.js +154 -0
  145. package/dist_ts/proxies/smart-proxy/tls-manager.d.ts +57 -0
  146. package/dist_ts/proxies/smart-proxy/tls-manager.js +132 -0
  147. package/dist_ts/smartproxy/classes.pp.networkproxybridge.d.ts +2 -2
  148. package/dist_ts/smartproxy/classes.pp.networkproxybridge.js +1 -1
  149. package/dist_ts/smartproxy/classes.pp.tlsmanager.js +2 -2
  150. package/dist_ts/smartproxy/classes.smartproxy.js +3 -3
  151. package/dist_ts/tls/alerts/index.d.ts +4 -0
  152. package/dist_ts/tls/alerts/index.js +5 -0
  153. package/dist_ts/tls/alerts/tls-alert.d.ts +150 -0
  154. package/dist_ts/tls/alerts/tls-alert.js +226 -0
  155. package/dist_ts/tls/index.d.ts +18 -0
  156. package/dist_ts/tls/index.js +27 -0
  157. package/dist_ts/tls/sni/client-hello-parser.d.ts +100 -0
  158. package/dist_ts/tls/sni/client-hello-parser.js +463 -0
  159. package/dist_ts/tls/sni/index.d.ts +4 -0
  160. package/dist_ts/tls/sni/index.js +5 -0
  161. package/dist_ts/tls/sni/sni-extraction.d.ts +58 -0
  162. package/dist_ts/tls/sni/sni-extraction.js +275 -0
  163. package/dist_ts/tls/sni/sni-handler.d.ts +154 -0
  164. package/dist_ts/tls/sni/sni-handler.js +191 -0
  165. package/dist_ts/tls/utils/index.d.ts +4 -0
  166. package/dist_ts/tls/utils/index.js +5 -0
  167. package/dist_ts/tls/utils/tls-utils.d.ts +158 -0
  168. package/dist_ts/tls/utils/tls-utils.js +187 -0
  169. package/package.json +1 -1
  170. package/readme.md +499 -220
  171. package/readme.plan.md +253 -469
  172. package/ts/00_commitinfo_data.ts +1 -1
  173. package/ts/certificate/acme/acme-factory.ts +48 -0
  174. package/ts/certificate/acme/challenge-handler.ts +110 -0
  175. package/ts/certificate/acme/index.ts +3 -0
  176. package/ts/certificate/events/certificate-events.ts +36 -0
  177. package/ts/certificate/index.ts +67 -0
  178. package/ts/certificate/models/certificate-types.ts +88 -0
  179. package/ts/certificate/providers/cert-provisioner.ts +326 -0
  180. package/ts/certificate/providers/index.ts +3 -0
  181. package/ts/certificate/storage/file-storage.ts +234 -0
  182. package/ts/certificate/storage/index.ts +3 -0
  183. package/ts/certificate/utils/certificate-helpers.ts +50 -0
  184. package/ts/common/eventUtils.ts +1 -1
  185. package/ts/common/port80-adapter.ts +1 -1
  186. package/ts/core/events/index.ts +3 -0
  187. package/ts/core/index.ts +8 -0
  188. package/ts/core/models/common-types.ts +91 -0
  189. package/ts/core/models/index.ts +5 -0
  190. package/ts/core/utils/event-utils.ts +34 -0
  191. package/ts/core/utils/index.ts +7 -0
  192. package/ts/core/utils/ip-utils.ts +175 -0
  193. package/ts/core/utils/validation-utils.ts +177 -0
  194. package/ts/{smartproxy/forwarding → forwarding/config}/domain-config.ts +1 -1
  195. package/ts/{smartproxy/forwarding → forwarding/config}/domain-manager.ts +8 -8
  196. package/ts/{smartproxy/types/forwarding.types.ts → forwarding/config/forwarding-types.ts} +6 -6
  197. package/ts/forwarding/config/index.ts +7 -0
  198. package/ts/{smartproxy/forwarding/forwarding.factory.ts → forwarding/factory/forwarding-factory.ts} +12 -11
  199. package/ts/forwarding/factory/index.ts +5 -0
  200. package/ts/{smartproxy/forwarding/forwarding.handler.ts → forwarding/handlers/base-handler.ts} +2 -2
  201. package/ts/{smartproxy/forwarding/http.handler.ts → forwarding/handlers/http-handler.ts} +13 -4
  202. package/ts/{smartproxy/forwarding/https-passthrough.handler.ts → forwarding/handlers/https-passthrough-handler.ts} +13 -4
  203. package/ts/{smartproxy/forwarding/https-terminate-to-http.handler.ts → forwarding/handlers/https-terminate-to-http-handler.ts} +3 -3
  204. package/ts/{smartproxy/forwarding/https-terminate-to-https.handler.ts → forwarding/handlers/https-terminate-to-https-handler.ts} +3 -3
  205. package/ts/forwarding/handlers/index.ts +9 -0
  206. package/ts/forwarding/index.ts +34 -0
  207. package/ts/http/index.ts +23 -0
  208. package/ts/http/models/http-types.ts +105 -0
  209. package/ts/http/port80/acme-interfaces.ts +85 -0
  210. package/ts/http/port80/challenge-responder.ts +246 -0
  211. package/ts/http/port80/index.ts +13 -0
  212. package/ts/{port80handler/classes.port80handler.ts → http/port80/port80-handler.ts} +164 -161
  213. package/ts/http/redirects/index.ts +3 -0
  214. package/ts/http/router/index.ts +5 -0
  215. package/ts/{classes.router.ts → http/router/proxy-router.ts} +27 -20
  216. package/ts/index.ts +32 -9
  217. package/ts/plugins.ts +2 -1
  218. package/ts/proxies/index.ts +8 -0
  219. package/ts/{networkproxy/classes.np.certificatemanager.ts → proxies/network-proxy/certificate-manager.ts} +17 -16
  220. package/ts/{networkproxy/classes.np.connectionpool.ts → proxies/network-proxy/connection-pool.ts} +3 -3
  221. package/ts/proxies/network-proxy/index.ts +13 -0
  222. package/ts/proxies/network-proxy/models/index.ts +4 -0
  223. package/ts/{networkproxy/classes.np.types.ts → proxies/network-proxy/models/types.ts} +7 -11
  224. package/ts/{networkproxy/classes.np.networkproxy.ts → proxies/network-proxy/network-proxy.ts} +31 -24
  225. package/ts/{networkproxy/classes.np.requesthandler.ts → proxies/network-proxy/request-handler.ts} +12 -7
  226. package/ts/{networkproxy/classes.np.websockethandler.ts → proxies/network-proxy/websocket-handler.ts} +6 -6
  227. package/ts/proxies/nftables-proxy/index.ts +5 -0
  228. package/ts/proxies/nftables-proxy/models/errors.ts +30 -0
  229. package/ts/proxies/nftables-proxy/models/index.ts +5 -0
  230. package/ts/proxies/nftables-proxy/models/interfaces.ts +94 -0
  231. package/ts/{nfttablesproxy/classes.nftablesproxy.ts → proxies/nftables-proxy/nftables-proxy.ts} +24 -126
  232. package/ts/{smartproxy/classes.pp.connectionhandler.ts → proxies/smart-proxy/connection-handler.ts} +12 -12
  233. package/ts/{smartproxy/classes.pp.connectionmanager.ts → proxies/smart-proxy/connection-manager.ts} +8 -8
  234. package/ts/{smartproxy/classes.pp.domainconfigmanager.ts → proxies/smart-proxy/domain-config-manager.ts} +15 -14
  235. package/ts/proxies/smart-proxy/index.ts +18 -0
  236. package/ts/proxies/smart-proxy/models/index.ts +4 -0
  237. package/ts/{smartproxy/classes.pp.interfaces.ts → proxies/smart-proxy/models/interfaces.ts} +12 -8
  238. package/ts/{smartproxy/classes.pp.networkproxybridge.ts → proxies/smart-proxy/network-proxy-bridge.ts} +14 -14
  239. package/ts/{smartproxy/classes.pp.portrangemanager.ts → proxies/smart-proxy/port-range-manager.ts} +1 -1
  240. package/ts/{smartproxy/classes.pp.securitymanager.ts → proxies/smart-proxy/security-manager.ts} +3 -3
  241. package/ts/{smartproxy/classes.smartproxy.ts → proxies/smart-proxy/smart-proxy.ts} +29 -24
  242. package/ts/{smartproxy/classes.pp.timeoutmanager.ts → proxies/smart-proxy/timeout-manager.ts} +3 -3
  243. package/ts/{smartproxy/classes.pp.tlsmanager.ts → proxies/smart-proxy/tls-manager.ts} +3 -3
  244. package/ts/tls/alerts/index.ts +3 -0
  245. package/ts/{smartproxy/classes.pp.tlsalert.ts → tls/alerts/tls-alert.ts} +44 -43
  246. package/ts/tls/index.ts +33 -0
  247. package/ts/tls/sni/client-hello-parser.ts +629 -0
  248. package/ts/tls/sni/index.ts +3 -0
  249. package/ts/tls/sni/sni-extraction.ts +353 -0
  250. package/ts/tls/sni/sni-handler.ts +264 -0
  251. package/ts/tls/utils/index.ts +3 -0
  252. package/ts/tls/utils/tls-utils.ts +201 -0
  253. package/ts/common/acmeFactory.ts +0 -23
  254. package/ts/helpers.certificates.ts +0 -30
  255. package/ts/networkproxy/index.ts +0 -7
  256. package/ts/smartproxy/classes.pp.certprovisioner.ts +0 -200
  257. package/ts/smartproxy/classes.pp.snihandler.ts +0 -1281
  258. package/ts/smartproxy/forwarding/index.ts +0 -52
package/readme.plan.md CHANGED
@@ -1,471 +1,255 @@
1
- # SmartProxy Unified Forwarding Configuration Plan
1
+ # SmartProxy Interface & Type Naming Standardization Plan
2
2
 
3
3
  ## Project Goal
4
- Create a clean, use-case driven forwarding configuration interface for SmartProxy that elegantly handles all forwarding scenarios: SNI-based forwarding, termination-based forwarding (NetworkProxy), HTTP forwarding, and ACME challenge forwarding.
5
-
6
- ## Current State
7
- Currently, SmartProxy has several different forwarding mechanisms configured separately:
8
- 1. **HTTPS/SNI forwarding** via `IDomainConfig` properties
9
- 2. **NetworkProxy forwarding** via `useNetworkProxy` in domain configs
10
- 3. **HTTP forwarding** via Port80Handler's `forward` configuration
11
- 4. **ACME challenge forwarding** via `acmeForward` configuration
12
-
13
- This separation creates configuration complexity and reduced cohesion between related settings.
14
-
15
- ## Proposed Solution: Clean Use-Case Driven Forwarding Interface
16
-
17
- ### Phase 1: Design Streamlined Forwarding Interface
18
-
19
- - [ ] Create a use-case driven `IForwardConfig` interface that simplifies configuration:
20
-
21
- ```typescript
22
- export interface IForwardConfig {
23
- // Define the primary forwarding type - use-case driven approach
24
- type: 'http-only' | 'https-passthrough' | 'https-terminate-to-http' | 'https-terminate-to-https';
25
-
26
- // Target configuration
27
- target: {
28
- host: string | string[]; // Support single host or round-robin
29
- port: number;
30
- };
31
-
32
- // HTTP-specific options
33
- http?: {
34
- enabled?: boolean; // Defaults to true for http-only, optional for others
35
- redirectToHttps?: boolean; // Redirect HTTP to HTTPS
36
- headers?: Record<string, string>; // Custom headers for HTTP responses
37
- };
38
-
39
- // HTTPS-specific options
40
- https?: {
41
- customCert?: { // Use custom cert instead of auto-provisioned
42
- key: string;
43
- cert: string;
44
- };
45
- forwardSni?: boolean; // Forward SNI info in passthrough mode
46
- };
47
-
48
- // ACME certificate handling
49
- acme?: {
50
- enabled?: boolean; // Enable ACME certificate provisioning
51
- maintenance?: boolean; // Auto-renew certificates
52
- production?: boolean; // Use production ACME servers
53
- forwardChallenges?: { // Forward ACME challenges
54
- host: string;
55
- port: number;
56
- useTls?: boolean;
57
- };
58
- };
59
-
60
- // Security options
61
- security?: {
62
- allowedIps?: string[]; // IPs allowed to connect
63
- blockedIps?: string[]; // IPs blocked from connecting
64
- maxConnections?: number; // Max simultaneous connections
65
- };
66
-
67
- // Advanced options
68
- advanced?: {
69
- portRanges?: Array<{ from: number; to: number }>; // Allowed port ranges
70
- networkProxyPort?: number; // Custom NetworkProxy port if using terminate mode
71
- keepAlive?: boolean; // Enable TCP keepalive
72
- timeout?: number; // Connection timeout in ms
73
- headers?: Record<string, string>; // Custom headers with support for variables like {sni}
74
- };
75
- }
76
- ```
77
-
78
- ### Phase 2: Create New Domain Configuration Interface
79
-
80
- - [ ] Replace existing `IDomainConfig` interface with a new one using the forwarding pattern:
81
-
82
- ```typescript
83
- export interface IDomainConfig {
84
- // Core properties
85
- domains: string[]; // Domain patterns to match
86
-
87
- // Unified forwarding configuration
88
- forwarding: IForwardConfig;
89
- }
90
- ```
91
-
92
- ### Phase 3: Implement Forwarding Handler System
93
-
94
- - [ ] Create an implementation strategy focused on the new forwarding types:
95
-
96
- ```typescript
97
- /**
98
- * Base class for all forwarding handlers
99
- */
100
- abstract class ForwardingHandler {
101
- constructor(protected config: IForwardConfig) {}
102
-
103
- abstract handleConnection(socket: Socket): void;
104
- abstract handleHttpRequest(req: IncomingMessage, res: ServerResponse): void;
105
- }
106
-
107
- /**
108
- * Factory for creating the appropriate handler based on forwarding type
109
- */
110
- class ForwardingHandlerFactory {
111
- public static createHandler(config: IForwardConfig): ForwardingHandler {
112
- switch (config.type) {
113
- case 'http-only':
114
- return new HttpForwardingHandler(config);
115
-
116
- case 'https-passthrough':
117
- return new HttpsPassthroughHandler(config);
118
-
119
- case 'https-terminate-to-http':
120
- return new HttpsTerminateToHttpHandler(config);
121
-
122
- case 'https-terminate-to-https':
123
- return new HttpsTerminateToHttpsHandler(config);
124
-
125
- default:
126
- throw new Error(`Unknown forwarding type: ${config.type}`);
127
- }
128
- }
129
- }
130
- ```
131
-
132
- ## Usage Examples for Common Scenarios
133
-
134
- ### 1. Basic HTTP Server
135
-
136
- ```typescript
137
- {
138
- domains: ['example.com'],
139
- forwarding: {
140
- type: 'http-only',
141
- target: {
142
- host: 'localhost',
143
- port: 3000
144
- }
145
- }
146
- }
147
- ```
148
-
149
- ### 2. HTTPS Termination with HTTP Backend
150
-
151
- ```typescript
152
- {
153
- domains: ['secure.example.com'],
154
- forwarding: {
155
- type: 'https-terminate-to-http',
156
- target: {
157
- host: 'localhost',
158
- port: 3000
159
- },
160
- acme: {
161
- production: true // Use production Let's Encrypt
162
- }
163
- }
164
- }
165
- ```
166
-
167
- ### 3. HTTPS Termination with HTTPS Backend
168
-
169
- ```typescript
170
- {
171
- domains: ['secure-backend.example.com'],
172
- forwarding: {
173
- type: 'https-terminate-to-https',
174
- target: {
175
- host: 'internal-api',
176
- port: 8443
177
- },
178
- http: {
179
- redirectToHttps: true // Redirect HTTP requests to HTTPS
180
- }
181
- }
182
- }
183
- ```
184
-
185
- ### 4. SNI Passthrough
186
-
187
- ```typescript
188
- {
189
- domains: ['passthrough.example.com'],
190
- forwarding: {
191
- type: 'https-passthrough',
192
- target: {
193
- host: '10.0.0.5',
194
- port: 443
195
- }
196
- }
197
- }
198
- ```
199
-
200
- ### 5. Mixed HTTP/HTTPS with Custom ACME Forwarding
201
-
202
- ```typescript
203
- {
204
- domains: ['mixed.example.com'],
205
- forwarding: {
206
- type: 'https-terminate-to-http',
207
- target: {
208
- host: 'localhost',
209
- port: 3000
210
- },
211
- http: {
212
- redirectToHttps: false // Allow both HTTP and HTTPS access
213
- },
214
- acme: {
215
- enabled: true,
216
- maintenance: true,
217
- forwardChallenges: {
218
- host: '192.168.1.100',
219
- port: 8080
220
- }
221
- }
222
- }
223
- }
224
- ```
225
-
226
- ### 6. Load-Balanced Backend
227
-
228
- ```typescript
229
- {
230
- domains: ['api.example.com'],
231
- forwarding: {
232
- type: 'https-terminate-to-https',
233
- target: {
234
- host: ['10.0.0.10', '10.0.0.11', '10.0.0.12'], // Round-robin
235
- port: 8443
236
- },
237
- security: {
238
- allowedIps: ['10.0.0.*', '192.168.1.*'] // Restrict access
239
- }
240
- }
241
- }
242
- ```
243
-
244
- ### 7. Advanced Proxy Chain with Custom Headers
245
-
246
- ```typescript
247
- {
248
- domains: ['secure-chain.example.com'],
249
- forwarding: {
250
- type: 'https-terminate-to-https',
251
- target: {
252
- host: 'backend-gateway.internal',
253
- port: 443
254
- },
255
- advanced: {
256
- // Pass original client info to backend
257
- headers: {
258
- 'X-Original-SNI': '{sni}',
259
- 'X-Client-IP': '{clientIp}'
260
- }
261
- }
262
- }
263
- }
264
- ```
265
-
266
- ## Implementation Plan
267
-
268
- ### Task 1: Core Types and Interfaces (Week 1)
269
- - [ ] Create the new `IForwardConfig` interface in `classes.pp.interfaces.ts`
270
- - [ ] Design the new `IDomainConfig` interface using the forwarding property
271
- - [ ] Define the internal data types for expanded configuration
272
-
273
- ### Task 2: Forwarding Handlers (Week 1-2)
274
- - [ ] Create abstract `ForwardingHandler` base class
275
- - [ ] Implement concrete handlers for each forwarding type:
276
- - [ ] `HttpForwardingHandler` - For HTTP-only configurations
277
- - [ ] `HttpsPassthroughHandler` - For SNI passthrough
278
- - [ ] `HttpsTerminateToHttpHandler` - For TLS termination to HTTP backends
279
- - [ ] `HttpsTerminateToHttpsHandler` - For TLS termination to HTTPS backends
280
- - [ ] Implement `ForwardingHandlerFactory` to create the appropriate handler
281
-
282
- ### Task 3: SmartProxy Integration (Week 2-3)
283
- - [ ] Update `SmartProxy` class to use the new forwarding system
284
- - [ ] Modify `ConnectionHandler` to delegate to forwarding handlers
285
- - [ ] Refactor domain configuration processing to use forwarding types
286
- - [ ] Update `Port80Handler` integration to work with the new system
287
-
288
- ### Task 4: Certificate Management (Week 3)
289
- - [ ] Create a certificate management system that works with forwarding types
290
- - [ ] Implement automatic ACME provisioning based on forwarding type
291
- - [ ] Add custom certificate support
292
-
293
- ### Task 5: Testing & Helper Functions (Week 4)
294
- - [ ] Create helper functions for common forwarding patterns
295
- - [ ] Implement comprehensive test suite for each forwarding handler
296
- - [ ] Add validation for forwarding configurations
297
-
298
- ### Task 6: Documentation (Week 4)
299
- - [ ] Create detailed documentation for the new forwarding system
300
- - [ ] Document the forwarding types and their use cases
301
- - [ ] Update README with the new configuration examples
302
-
303
- ## Detailed Type Documentation
304
-
305
- ### Core Forwarding Types
306
-
307
- ```typescript
308
- /**
309
- * The primary forwarding types supported by SmartProxy
310
- */
311
- export type ForwardingType =
312
- | 'http-only' // HTTP forwarding only (no HTTPS)
313
- | 'https-passthrough' // Pass-through TLS traffic (SNI forwarding)
314
- | 'https-terminate-to-http' // Terminate TLS and forward to HTTP backend
315
- | 'https-terminate-to-https'; // Terminate TLS and forward to HTTPS backend
316
- ```
317
-
318
- ### Type-Specific Behavior
319
-
320
- Each forwarding type has specific default behavior:
321
-
322
- #### HTTP-Only
323
- - Handles only HTTP traffic
324
- - No TLS/HTTPS support
325
- - No certificate management
326
-
327
- #### HTTPS Passthrough
328
- - Forwards raw TLS traffic to backend (no termination)
329
- - Passes SNI information through
330
- - No HTTP support (TLS only)
331
- - No certificate management
332
-
333
- #### HTTPS Terminate to HTTP
334
- - Terminates TLS at SmartProxy
335
- - Connects to backend using HTTP (non-TLS)
336
- - Manages certificates automatically (ACME)
337
- - Supports HTTP requests with option to redirect to HTTPS
338
-
339
- #### HTTPS Terminate to HTTPS
340
- - Terminates client TLS at SmartProxy
341
- - Creates new TLS connection to backend
342
- - Manages certificates automatically (ACME)
343
- - Supports HTTP requests with option to redirect to HTTPS
344
-
345
- ## Handler Implementation Strategy
346
-
347
- ```typescript
348
- /**
349
- * Handler for HTTP-only forwarding
350
- */
351
- class HttpForwardingHandler extends ForwardingHandler {
352
- public handleConnection(socket: Socket): void {
353
- // Process HTTP connection
354
- // For HTTP-only, we'll mostly defer to handleHttpRequest
355
- }
356
-
357
- public handleHttpRequest(req: IncomingMessage, res: ServerResponse): void {
358
- // Forward HTTP request to target
359
- const target = this.getTargetFromConfig();
360
- this.proxyRequest(req, res, target);
361
- }
362
- }
363
-
364
- /**
365
- * Handler for HTTPS passthrough (SNI forwarding)
366
- */
367
- class HttpsPassthroughHandler extends ForwardingHandler {
368
- public handleConnection(socket: Socket): void {
369
- // Extract SNI from TLS ClientHello if needed
370
- // Forward raw TLS traffic to target without termination
371
- const target = this.getTargetFromConfig();
372
- this.forwardTlsConnection(socket, target);
373
- }
374
-
375
- public handleHttpRequest(req: IncomingMessage, res: ServerResponse): void {
376
- // HTTP not supported in SNI passthrough mode
377
- res.statusCode = 404;
378
- res.end('HTTP not supported for this domain');
379
- }
380
- }
381
-
382
- /**
383
- * Handler for HTTPS termination with HTTP backend
384
- */
385
- class HttpsTerminateToHttpHandler extends ForwardingHandler {
386
- private tlsContext: SecureContext;
387
-
388
- public async initialize(): Promise<void> {
389
- // Set up TLS termination context
390
- this.tlsContext = await this.createTlsContext();
391
- }
392
-
393
- public handleConnection(socket: Socket): void {
394
- // Terminate TLS
395
- const tlsSocket = this.createTlsSocket(socket, this.tlsContext);
396
-
397
- // Forward to HTTP backend after TLS termination
398
- tlsSocket.on('data', (data) => {
399
- this.forwardToHttpBackend(data);
400
- });
401
- }
402
-
403
- public handleHttpRequest(req: IncomingMessage, res: ServerResponse): void {
404
- if (this.config.http?.redirectToHttps) {
405
- // Redirect to HTTPS if configured
406
- this.redirectToHttps(req, res);
407
- } else {
408
- // Handle HTTP request
409
- const target = this.getTargetFromConfig();
410
- this.proxyRequest(req, res, target);
411
- }
412
- }
413
- }
414
-
415
- /**
416
- * Handler for HTTPS termination with HTTPS backend
417
- */
418
- class HttpsTerminateToHttpsHandler extends ForwardingHandler {
419
- private tlsContext: SecureContext;
420
-
421
- public async initialize(): Promise<void> {
422
- // Set up TLS termination context
423
- this.tlsContext = await this.createTlsContext();
424
- }
425
-
426
- public handleConnection(socket: Socket): void {
427
- // Terminate client TLS
428
- const tlsSocket = this.createTlsSocket(socket, this.tlsContext);
429
-
430
- // Create new TLS connection to backend
431
- tlsSocket.on('data', (data) => {
432
- this.forwardToHttpsBackend(data);
433
- });
434
- }
435
-
436
- public handleHttpRequest(req: IncomingMessage, res: ServerResponse): void {
437
- if (this.config.http?.redirectToHttps) {
438
- // Redirect to HTTPS if configured
439
- this.redirectToHttps(req, res);
440
- } else {
441
- // Handle HTTP request via HTTPS to backend
442
- const target = this.getTargetFromConfig();
443
- this.proxyRequestOverHttps(req, res, target);
444
- }
445
- }
446
- }
447
- ```
448
-
449
- ## Benefits of This Approach
450
-
451
- 1. **Clean, Type-Driven Design**
452
- - Forwarding types clearly express intent
453
- - No backward compatibility compromises
454
- - Code structure follows the domain model
455
-
456
- 2. **Explicit Configuration**
457
- - Configuration directly maps to behavior
458
- - Reduced chance of unexpected behavior
459
-
460
- 3. **Modular Implementation**
461
- - Each forwarding type handled by dedicated class
462
- - Clear separation of concerns
463
- - Easier to test and extend
464
-
465
- 4. **Simplified Mental Model**
466
- - Users think in terms of use cases, not low-level settings
467
- - Configuration matches mental model
468
-
469
- 5. **Future-Proof**
470
- - Easy to add new forwarding types
471
- - Clean extension points for new features
4
+ Standardize interface and type naming throughout the SmartProxy codebase to improve maintainability, readability, and developer experience by:
5
+ 1. Ensuring all interfaces are prefixed with "I"
6
+ 2. Ensuring all type aliases are prefixed with "T"
7
+ 3. Maintaining backward compatibility through type aliases
8
+ 4. Updating documentation to reflect naming conventions
9
+
10
+ ## Phase 2: Core Module Standardization
11
+
12
+ - [ ] Update core module interfaces and types
13
+ - [ ] Rename interfaces in `ts/core/models/common-types.ts`
14
+ - [ ] `AcmeOptions` → `IAcmeOptions`
15
+ - [ ] `DomainOptions` `IDomainOptions`
16
+ - [ ] Other common interfaces
17
+ - [ ] Add backward compatibility aliases
18
+ - [ ] Update imports throughout core module
19
+
20
+ - [ ] Update core utility type definitions
21
+ - [ ] Update `ts/core/utils/validation-utils.ts`
22
+ - [ ] Update `ts/core/utils/ip-utils.ts`
23
+ - [ ] Standardize event type definitions
24
+
25
+ - [ ] Test core module changes
26
+ - [ ] Run unit tests for core modules
27
+ - [ ] Verify type compatibility
28
+ - [ ] Ensure backward compatibility
29
+
30
+ ## Phase 3: Certificate Module Standardization
31
+
32
+ - [ ] Update certificate interfaces
33
+ - [ ] Rename interfaces in `ts/certificate/models/certificate-types.ts`
34
+ - [ ] `CertificateData` `ICertificateData`
35
+ - [ ] `Certificates` `ICertificates`
36
+ - [ ] `CertificateFailure` `ICertificateFailure`
37
+ - [ ] `CertificateExpiring` → `ICertificateExpiring`
38
+ - [ ] `ForwardConfig` → `IForwardConfig`
39
+ - [ ] `DomainForwardConfig` → `IDomainForwardConfig`
40
+ - [ ] Update ACME challenge interfaces
41
+ - [ ] Standardize storage provider interfaces
42
+
43
+ - [ ] Ensure certificate provider compatibility
44
+ - [ ] Update provider implementations
45
+ - [ ] Rename internal interfaces
46
+ - [ ] Maintain public API compatibility
47
+
48
+ - [ ] Test certificate module
49
+ - [ ] Verify ACME functionality
50
+ - [ ] Test certificate provisioning
51
+ - [ ] Validate challenge handling
52
+
53
+ ## Phase 4: Forwarding System Standardization
54
+
55
+ - [ ] Update forwarding configuration interfaces
56
+ - [ ] Rename interfaces in `ts/forwarding/config/forwarding-types.ts`
57
+ - [ ] `TargetConfig` → `ITargetConfig`
58
+ - [ ] `HttpOptions` → `IHttpOptions`
59
+ - [ ] `HttpsOptions` → `IHttpsOptions`
60
+ - [ ] `AcmeForwardingOptions` → `IAcmeForwardingOptions`
61
+ - [ ] `SecurityOptions` → `ISecurityOptions`
62
+ - [ ] `AdvancedOptions` `IAdvancedOptions`
63
+ - [ ] `ForwardConfig` `IForwardConfig`
64
+ - [ ] Rename type definitions
65
+ - [ ] `ForwardingType` → `TForwardingType`
66
+ - [ ] Update domain configuration interfaces
67
+
68
+ - [ ] Standardize handler interfaces
69
+ - [ ] Update base handler interfaces
70
+ - [ ] Rename handler-specific interfaces
71
+ - [ ] Update factory interfaces
72
+
73
+ - [ ] Verify forwarding system functionality
74
+ - [ ] Test all forwarding types
75
+ - [ ] Verify configuration parsing
76
+ - [ ] Ensure backward compatibility
77
+
78
+ ## Phase 5: Proxy Implementation Standardization
79
+
80
+ - [ ] Update SmartProxy interfaces
81
+ - [ ] Rename interfaces in `ts/proxies/smart-proxy/models/interfaces.ts`
82
+ - [ ] Update domain configuration interfaces
83
+ - [ ] Standardize manager interfaces
84
+
85
+ - [ ] Update NetworkProxy interfaces
86
+ - [ ] Rename in `ts/proxies/network-proxy/models/types.ts`
87
+ - [ ] `NetworkProxyOptions` → `INetworkProxyOptions`
88
+ - [ ] `CertificateEntry` → `ICertificateEntry`
89
+ - [ ] `ReverseProxyConfig` → `IReverseProxyConfig`
90
+ - [ ] `ConnectionEntry` → `IConnectionEntry`
91
+ - [ ] `WebSocketWithHeartbeat` → `IWebSocketWithHeartbeat`
92
+ - [ ] `Logger` `ILogger`
93
+ - [ ] Update request handler interfaces
94
+ - [ ] Standardize connection interfaces
95
+
96
+ - [ ] Update NfTablesProxy interfaces
97
+ - [ ] Rename interfaces in `ts/proxies/nftables-proxy/models/interfaces.ts`
98
+ - [ ] Update configuration interfaces
99
+ - [ ] Standardize firewall rule interfaces
100
+
101
+ - [ ] Test proxy implementations
102
+ - [ ] Verify SmartProxy functionality
103
+ - [ ] Test NetworkProxy with renamed interfaces
104
+ - [ ] Validate NfTablesProxy operations
105
+
106
+ ## Phase 6: HTTP & TLS Module Standardization
107
+
108
+ - [ ] Update HTTP interfaces
109
+ - [ ] Rename in `ts/http/port80/acme-interfaces.ts`
110
+ - [ ] `SmartAcmeCert` → `ISmartAcmeCert`
111
+ - [ ] `SmartAcmeOptions` `ISmartAcmeOptions`
112
+ - [ ] `Http01Challenge` → `IHttp01Challenge`
113
+ - [ ] `SmartAcme` → `ISmartAcme`
114
+ - [ ] Standardize router interfaces
115
+ - [ ] Update port80 handler interfaces
116
+ - [ ] Update redirect interfaces
117
+
118
+ - [ ] Update TLS/SNI interfaces
119
+ - [ ] Standardize SNI handler interfaces
120
+ - [ ] Update client hello parser types
121
+ - [ ] Rename TLS alert interfaces
122
+
123
+ - [ ] Test HTTP & TLS functionality
124
+ - [ ] Verify router operation
125
+ - [ ] Test SNI extraction
126
+ - [ ] Validate redirect functionality
127
+
128
+ ## Phase 7: Backward Compatibility Layer
129
+
130
+ - [ ] Implement comprehensive type aliases
131
+ - [ ] Create aliases for all renamed interfaces
132
+ - [ ] Add deprecation notices via JSDoc
133
+ - [ ] Ensure all exports include both named versions
134
+
135
+ - [ ] Update main entry point
136
+ - [ ] Update `ts/index.ts` with all exports
137
+ - [ ] Include both prefixed and non-prefixed names
138
+ - [ ] Organize exports by module
139
+
140
+ - [ ] Add compatibility documentation
141
+ - [ ] Document renaming strategy
142
+ - [ ] Provide migration examples
143
+ - [ ] Create deprecation timeline
144
+
145
+ ## Phase 8: Documentation & Examples
146
+
147
+ - [ ] Update README and API documentation
148
+ - [ ] Update interface references in README.md
149
+ - [ ] Document naming convention in README.md
150
+ - [ ] Update API reference documentation
151
+
152
+ - [ ] Update examples
153
+ - [ ] Modify example code to use new interface names
154
+ - [ ] Add compatibility notes
155
+ - [ ] Create migration examples
156
+
157
+ - [ ] Add contributor guidelines
158
+ - [ ] Document naming conventions
159
+ - [ ] Add interface/type style guide
160
+ - [ ] Update PR templates
161
+
162
+ ## Phase 9: Testing & Validation
163
+
164
+ - [ ] Run comprehensive test suite
165
+ - [ ] Run all unit tests
166
+ - [ ] Execute integration tests
167
+ - [ ] Verify example code
168
+
169
+ - [ ] Build type declarations
170
+ - [ ] Generate TypeScript declaration files
171
+ - [ ] Verify exported types
172
+ - [ ] Validate documentation generation
173
+
174
+ - [ ] Final compatibility check
175
+ - [ ] Verify import compatibility
176
+ - [ ] Test with existing dependent projects
177
+ - [ ] Validate backward compatibility claims
178
+
179
+ ## Implementation Strategy
180
+
181
+ ### Naming Pattern Rules
182
+
183
+ 1. **Interfaces**:
184
+ - All interfaces should be prefixed with "I"
185
+ - Example: `DomainConfig` → `IDomainConfig`
186
+
187
+ 2. **Type Aliases**:
188
+ - All type aliases should be prefixed with "T"
189
+ - Example: `ForwardingType` → `TForwardingType`
190
+
191
+ 3. **Enums**:
192
+ - Enums should be named in PascalCase without prefix
193
+ - Example: `CertificateSource`
194
+
195
+ 4. **Backward Compatibility**:
196
+ - No Backward compatibility. Remove old names.
197
+
198
+ ### Module Implementation Order
199
+
200
+ 1. Core module
201
+ 2. Certificate module
202
+ 3. Forwarding module
203
+ 4. Proxy implementations
204
+ 5. HTTP & TLS modules
205
+ 6. Main exports and entry points
206
+
207
+ ### Testing Strategy
208
+
209
+ For each module:
210
+ 1. Rename interfaces and types
211
+ 2. Add backward compatibility aliases
212
+ 3. Update imports throughout the module
213
+ 4. Run tests to verify functionality
214
+ 5. Commit changes module by module
215
+
216
+ ## File-Specific Changes
217
+
218
+ ### Core Module Files
219
+ - `ts/core/models/common-types.ts` - Primary interfaces
220
+ - `ts/core/utils/validation-utils.ts` - Validation type definitions
221
+ - `ts/core/utils/ip-utils.ts` - IP utility type definitions
222
+ - `ts/core/utils/event-utils.ts` - Event type definitions
223
+
224
+ ### Certificate Module Files
225
+ - `ts/certificate/models/certificate-types.ts` - Certificate interfaces
226
+ - `ts/certificate/acme/acme-factory.ts` - ACME factory types
227
+ - `ts/certificate/providers/cert-provisioner.ts` - Provider interfaces
228
+ - `ts/certificate/storage/file-storage.ts` - Storage interfaces
229
+
230
+ ### Forwarding Module Files
231
+ - `ts/forwarding/config/forwarding-types.ts` - Forwarding interfaces and types
232
+ - `ts/forwarding/config/domain-config.ts` - Domain configuration
233
+ - `ts/forwarding/factory/forwarding-factory.ts` - Factory interfaces
234
+ - `ts/forwarding/handlers/*.ts` - Handler interfaces
235
+
236
+ ### Proxy Module Files
237
+ - `ts/proxies/network-proxy/models/types.ts` - NetworkProxy interfaces
238
+ - `ts/proxies/smart-proxy/models/interfaces.ts` - SmartProxy interfaces
239
+ - `ts/proxies/nftables-proxy/models/interfaces.ts` - NfTables interfaces
240
+ - `ts/proxies/smart-proxy/connection-manager.ts` - Connection types
241
+
242
+ ### HTTP/TLS Module Files
243
+ - `ts/http/models/http-types.ts` - HTTP module interfaces
244
+ - `ts/http/port80/acme-interfaces.ts` - ACME interfaces
245
+ - `ts/tls/sni/client-hello-parser.ts` - TLS parser types
246
+ - `ts/tls/alerts/tls-alert.ts` - TLS alert interfaces
247
+
248
+ ## Success Criteria
249
+
250
+ - All interfaces are prefixed with "I"
251
+ - All type aliases are prefixed with "T"
252
+ - All tests pass with new naming conventions
253
+ - Documentation is updated with new naming conventions
254
+ - Backward compatibility is maintained through type aliases
255
+ - Declaration files correctly export both naming conventions