@push.rocks/smartproxy 18.1.0 → 19.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/certificate/certificate-manager.d.ts +150 -0
  3. package/dist_ts/certificate/certificate-manager.js +505 -0
  4. package/dist_ts/certificate/events/simplified-events.d.ts +56 -0
  5. package/dist_ts/certificate/events/simplified-events.js +13 -0
  6. package/dist_ts/certificate/models/certificate-errors.d.ts +69 -0
  7. package/dist_ts/certificate/models/certificate-errors.js +141 -0
  8. package/dist_ts/certificate/models/certificate-strategy.d.ts +60 -0
  9. package/dist_ts/certificate/models/certificate-strategy.js +73 -0
  10. package/dist_ts/certificate/simplified-certificate-manager.d.ts +150 -0
  11. package/dist_ts/certificate/simplified-certificate-manager.js +501 -0
  12. package/dist_ts/common/eventUtils.d.ts +1 -2
  13. package/dist_ts/common/eventUtils.js +2 -1
  14. package/dist_ts/core/models/common-types.d.ts +1 -1
  15. package/dist_ts/core/models/common-types.js +1 -1
  16. package/dist_ts/core/utils/event-utils.d.ts +9 -9
  17. package/dist_ts/core/utils/event-utils.js +6 -14
  18. package/dist_ts/http/index.d.ts +1 -9
  19. package/dist_ts/http/index.js +5 -11
  20. package/dist_ts/http/models/http-types.d.ts +13 -1
  21. package/dist_ts/http/models/http-types.js +1 -1
  22. package/dist_ts/index.d.ts +4 -6
  23. package/dist_ts/index.js +4 -10
  24. package/dist_ts/plugins.d.ts +3 -1
  25. package/dist_ts/plugins.js +4 -2
  26. package/dist_ts/proxies/index.d.ts +3 -2
  27. package/dist_ts/proxies/index.js +4 -5
  28. package/dist_ts/proxies/network-proxy/certificate-manager.d.ts +31 -49
  29. package/dist_ts/proxies/network-proxy/certificate-manager.js +77 -374
  30. package/dist_ts/proxies/network-proxy/models/types.d.ts +12 -1
  31. package/dist_ts/proxies/network-proxy/models/types.js +1 -1
  32. package/dist_ts/proxies/network-proxy/network-proxy.d.ts +2 -7
  33. package/dist_ts/proxies/network-proxy/network-proxy.js +12 -19
  34. package/dist_ts/proxies/network-proxy/simplified-certificate-bridge.d.ts +48 -0
  35. package/dist_ts/proxies/network-proxy/simplified-certificate-bridge.js +76 -0
  36. package/dist_ts/proxies/network-proxy/websocket-handler.js +21 -7
  37. package/dist_ts/proxies/smart-proxy/cert-store.d.ts +10 -0
  38. package/dist_ts/proxies/smart-proxy/cert-store.js +70 -0
  39. package/dist_ts/proxies/smart-proxy/certificate-manager.d.ts +116 -0
  40. package/dist_ts/proxies/smart-proxy/certificate-manager.js +401 -0
  41. package/dist_ts/proxies/smart-proxy/legacy-smart-proxy.d.ts +168 -0
  42. package/dist_ts/proxies/smart-proxy/legacy-smart-proxy.js +642 -0
  43. package/dist_ts/proxies/smart-proxy/models/index.d.ts +1 -1
  44. package/dist_ts/proxies/smart-proxy/models/index.js +1 -5
  45. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +13 -1
  46. package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +26 -0
  47. package/dist_ts/proxies/smart-proxy/models/route-types.js +1 -1
  48. package/dist_ts/proxies/smart-proxy/models/simplified-smartproxy-config.d.ts +65 -0
  49. package/dist_ts/proxies/smart-proxy/models/simplified-smartproxy-config.js +31 -0
  50. package/dist_ts/proxies/smart-proxy/models/smartproxy-options.d.ts +102 -0
  51. package/dist_ts/proxies/smart-proxy/models/smartproxy-options.js +73 -0
  52. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +10 -44
  53. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +66 -202
  54. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +4 -0
  55. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +62 -2
  56. package/dist_ts/proxies/smart-proxy/simplified-smart-proxy.d.ts +41 -0
  57. package/dist_ts/proxies/smart-proxy/simplified-smart-proxy.js +132 -0
  58. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +18 -13
  59. package/dist_ts/proxies/smart-proxy/smart-proxy.js +80 -198
  60. package/package.json +5 -3
  61. package/readme.md +13 -5
  62. package/readme.plan.md +1422 -617
  63. package/ts/00_commitinfo_data.ts +1 -1
  64. package/ts/common/eventUtils.ts +2 -2
  65. package/ts/core/models/common-types.ts +1 -1
  66. package/ts/core/utils/event-utils.ts +12 -21
  67. package/ts/http/index.ts +5 -12
  68. package/ts/http/models/http-types.ts +8 -4
  69. package/ts/index.ts +11 -14
  70. package/ts/plugins.ts +4 -1
  71. package/ts/proxies/index.ts +7 -4
  72. package/ts/proxies/network-proxy/certificate-manager.ts +92 -417
  73. package/ts/proxies/network-proxy/models/types.ts +14 -2
  74. package/ts/proxies/network-proxy/network-proxy.ts +13 -19
  75. package/ts/proxies/network-proxy/websocket-handler.ts +18 -6
  76. package/ts/proxies/smart-proxy/cert-store.ts +86 -0
  77. package/ts/proxies/smart-proxy/certificate-manager.ts +506 -0
  78. package/ts/proxies/smart-proxy/models/index.ts +2 -1
  79. package/ts/proxies/smart-proxy/models/interfaces.ts +14 -1
  80. package/ts/proxies/smart-proxy/models/route-types.ts +34 -4
  81. package/ts/proxies/smart-proxy/network-proxy-bridge.ts +86 -239
  82. package/ts/proxies/smart-proxy/route-connection-handler.ts +74 -1
  83. package/ts/proxies/smart-proxy/smart-proxy.ts +106 -224
  84. package/ts/certificate/acme/acme-factory.ts +0 -48
  85. package/ts/certificate/acme/challenge-handler.ts +0 -110
  86. package/ts/certificate/acme/index.ts +0 -3
  87. package/ts/certificate/events/certificate-events.ts +0 -36
  88. package/ts/certificate/index.ts +0 -75
  89. package/ts/certificate/models/certificate-types.ts +0 -109
  90. package/ts/certificate/providers/cert-provisioner.ts +0 -519
  91. package/ts/certificate/providers/index.ts +0 -3
  92. package/ts/certificate/storage/file-storage.ts +0 -234
  93. package/ts/certificate/storage/index.ts +0 -3
  94. package/ts/certificate/utils/certificate-helpers.ts +0 -50
  95. package/ts/http/port80/acme-interfaces.ts +0 -169
  96. package/ts/http/port80/challenge-responder.ts +0 -246
  97. package/ts/http/port80/index.ts +0 -13
  98. package/ts/http/port80/port80-handler.ts +0 -728
@@ -0,0 +1,168 @@
1
+ import * as plugins from '../../plugins.js';
2
+ import { RouteManager } from './route-manager.js';
3
+ import type { ISmartProxyOptions } from './models/interfaces.js';
4
+ import type { IRouteConfig } from './models/route-types.js';
5
+ /**
6
+ * SmartProxy - Pure route-based API
7
+ *
8
+ * SmartProxy is a unified proxy system that works with routes to define connection handling behavior.
9
+ * Each route contains matching criteria (ports, domains, etc.) and an action to take (forward, redirect, block).
10
+ *
11
+ * Configuration is provided through a set of routes, with each route defining:
12
+ * - What to match (ports, domains, paths, client IPs)
13
+ * - What to do with matching traffic (forward, redirect, block)
14
+ * - How to handle TLS (passthrough, terminate, terminate-and-reencrypt)
15
+ * - Security settings (IP restrictions, connection limits)
16
+ * - Advanced options (timeout, headers, etc.)
17
+ */
18
+ export declare class SmartProxy extends plugins.EventEmitter {
19
+ private portManager;
20
+ private connectionLogger;
21
+ private isShuttingDown;
22
+ private connectionManager;
23
+ private securityManager;
24
+ private tlsManager;
25
+ private networkProxyBridge;
26
+ private timeoutManager;
27
+ routeManager: RouteManager;
28
+ private routeConnectionHandler;
29
+ private nftablesManager;
30
+ private port80Handler;
31
+ private certProvisioner?;
32
+ /**
33
+ * Constructor for SmartProxy
34
+ *
35
+ * @param settingsArg Configuration options containing routes and other settings
36
+ * Routes define how traffic is matched and handled, with each route having:
37
+ * - match: criteria for matching traffic (ports, domains, paths, IPs)
38
+ * - action: what to do with matched traffic (forward, redirect, block)
39
+ *
40
+ * Example:
41
+ * ```ts
42
+ * const proxy = new SmartProxy({
43
+ * routes: [
44
+ * {
45
+ * match: {
46
+ * ports: 443,
47
+ * domains: ['example.com', '*.example.com']
48
+ * },
49
+ * action: {
50
+ * type: 'forward',
51
+ * target: { host: '10.0.0.1', port: 8443 },
52
+ * tls: { mode: 'passthrough' }
53
+ * }
54
+ * }
55
+ * ],
56
+ * defaults: {
57
+ * target: { host: 'localhost', port: 8080 },
58
+ * security: { ipAllowList: ['*'] }
59
+ * }
60
+ * });
61
+ * ```
62
+ */
63
+ constructor(settingsArg: ISmartProxyOptions);
64
+ /**
65
+ * The settings for the SmartProxy
66
+ */
67
+ settings: ISmartProxyOptions;
68
+ /**
69
+ * Initialize the Port80Handler for ACME certificate management
70
+ */
71
+ private initializePort80Handler;
72
+ /**
73
+ * Start the proxy server with support for both configuration types
74
+ */
75
+ start(): Promise<void>;
76
+ /**
77
+ * Extract domain configurations from routes for certificate provisioning
78
+ *
79
+ * Note: This method has been removed as we now work directly with routes
80
+ */
81
+ /**
82
+ * Stop the proxy server
83
+ */
84
+ stop(): Promise<void>;
85
+ /**
86
+ * Updates the domain configurations for the proxy
87
+ *
88
+ * Note: This legacy method has been removed. Use updateRoutes instead.
89
+ */
90
+ updateDomainConfigs(): Promise<void>;
91
+ /**
92
+ * Update routes with new configuration
93
+ *
94
+ * This method replaces the current route configuration with the provided routes.
95
+ * It also provisions certificates for routes that require TLS termination and have
96
+ * `certificate: 'auto'` set in their TLS configuration.
97
+ *
98
+ * @param newRoutes Array of route configurations to use
99
+ *
100
+ * Example:
101
+ * ```ts
102
+ * proxy.updateRoutes([
103
+ * {
104
+ * match: { ports: 443, domains: 'secure.example.com' },
105
+ * action: {
106
+ * type: 'forward',
107
+ * target: { host: '10.0.0.1', port: 8443 },
108
+ * tls: { mode: 'terminate', certificate: 'auto' }
109
+ * }
110
+ * }
111
+ * ]);
112
+ * ```
113
+ */
114
+ updateRoutes(newRoutes: IRouteConfig[]): Promise<void>;
115
+ /**
116
+ * Request a certificate for a specific domain
117
+ *
118
+ * @param domain The domain to request a certificate for
119
+ * @param routeName Optional route name to associate with the certificate
120
+ */
121
+ requestCertificate(domain: string, routeName?: string): Promise<boolean>;
122
+ /**
123
+ * Validates if a domain name is valid for certificate issuance
124
+ */
125
+ private isValidDomain;
126
+ /**
127
+ * Add a new listening port without changing the route configuration
128
+ *
129
+ * This allows you to add a port listener without updating routes.
130
+ * Useful for preparing to listen on a port before adding routes for it.
131
+ *
132
+ * @param port The port to start listening on
133
+ * @returns Promise that resolves when the port is listening
134
+ */
135
+ addListeningPort(port: number): Promise<void>;
136
+ /**
137
+ * Stop listening on a specific port without changing the route configuration
138
+ *
139
+ * This allows you to stop a port listener without updating routes.
140
+ * Useful for temporary maintenance or port changes.
141
+ *
142
+ * @param port The port to stop listening on
143
+ * @returns Promise that resolves when the port is closed
144
+ */
145
+ removeListeningPort(port: number): Promise<void>;
146
+ /**
147
+ * Get a list of all ports currently being listened on
148
+ *
149
+ * @returns Array of port numbers
150
+ */
151
+ getListeningPorts(): number[];
152
+ /**
153
+ * Get statistics about current connections
154
+ */
155
+ getStatistics(): any;
156
+ /**
157
+ * Get a list of eligible domains for ACME certificates
158
+ */
159
+ getEligibleDomainsForCertificates(): string[];
160
+ /**
161
+ * Get NFTables status
162
+ */
163
+ getNfTablesStatus(): Promise<Record<string, any>>;
164
+ /**
165
+ * Get status of certificates managed by Port80Handler
166
+ */
167
+ getCertificateStatus(): any;
168
+ }