@push.rocks/smartproxy 19.5.3 → 19.5.5

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 (42) hide show
  1. package/dist_ts/core/utils/async-utils.d.ts +81 -0
  2. package/dist_ts/core/utils/async-utils.js +216 -0
  3. package/dist_ts/core/utils/binary-heap.d.ts +73 -0
  4. package/dist_ts/core/utils/binary-heap.js +193 -0
  5. package/dist_ts/core/utils/enhanced-connection-pool.d.ts +110 -0
  6. package/dist_ts/core/utils/enhanced-connection-pool.js +320 -0
  7. package/dist_ts/core/utils/fs-utils.d.ts +144 -0
  8. package/dist_ts/core/utils/fs-utils.js +252 -0
  9. package/dist_ts/core/utils/index.d.ts +5 -2
  10. package/dist_ts/core/utils/index.js +6 -3
  11. package/dist_ts/core/utils/lifecycle-component.d.ts +59 -0
  12. package/dist_ts/core/utils/lifecycle-component.js +195 -0
  13. package/dist_ts/plugins.d.ts +2 -1
  14. package/dist_ts/plugins.js +3 -2
  15. package/dist_ts/proxies/http-proxy/certificate-manager.d.ts +15 -0
  16. package/dist_ts/proxies/http-proxy/certificate-manager.js +49 -2
  17. package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +10 -0
  18. package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +53 -43
  19. package/dist_ts/proxies/smart-proxy/cert-store.js +22 -20
  20. package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +37 -7
  21. package/dist_ts/proxies/smart-proxy/connection-manager.js +257 -180
  22. package/package.json +2 -2
  23. package/readme.hints.md +96 -1
  24. package/readme.md +515 -301
  25. package/readme.plan.md +1135 -221
  26. package/readme.problems.md +167 -83
  27. package/ts/core/utils/async-utils.ts +275 -0
  28. package/ts/core/utils/binary-heap.ts +225 -0
  29. package/ts/core/utils/enhanced-connection-pool.ts +420 -0
  30. package/ts/core/utils/fs-utils.ts +270 -0
  31. package/ts/core/utils/index.ts +5 -2
  32. package/ts/core/utils/lifecycle-component.ts +231 -0
  33. package/ts/plugins.ts +2 -1
  34. package/ts/proxies/http-proxy/certificate-manager.ts +52 -1
  35. package/ts/proxies/nftables-proxy/nftables-proxy.ts +64 -79
  36. package/ts/proxies/smart-proxy/cert-store.ts +26 -20
  37. package/ts/proxies/smart-proxy/connection-manager.ts +291 -189
  38. package/readme.plan2.md +0 -764
  39. package/ts/common/eventUtils.ts +0 -34
  40. package/ts/common/types.ts +0 -91
  41. package/ts/core/utils/event-system.ts +0 -376
  42. package/ts/core/utils/event-utils.ts +0 -25
@@ -1,34 +0,0 @@
1
- // Port80Handler removed - use SmartCertManager instead
2
- import { Port80HandlerEvents } from './types.js';
3
- import type { ICertificateData, ICertificateFailure, ICertificateExpiring } from './types.js';
4
-
5
- /**
6
- * Subscribers callback definitions for Port80Handler events
7
- */
8
- export interface Port80HandlerSubscribers {
9
- onCertificateIssued?: (data: ICertificateData) => void;
10
- onCertificateRenewed?: (data: ICertificateData) => void;
11
- onCertificateFailed?: (data: ICertificateFailure) => void;
12
- onCertificateExpiring?: (data: ICertificateExpiring) => void;
13
- }
14
-
15
- /**
16
- * Subscribes to Port80Handler events based on provided callbacks
17
- */
18
- export function subscribeToPort80Handler(
19
- handler: any,
20
- subscribers: Port80HandlerSubscribers
21
- ): void {
22
- if (subscribers.onCertificateIssued) {
23
- handler.on(Port80HandlerEvents.CERTIFICATE_ISSUED, subscribers.onCertificateIssued);
24
- }
25
- if (subscribers.onCertificateRenewed) {
26
- handler.on(Port80HandlerEvents.CERTIFICATE_RENEWED, subscribers.onCertificateRenewed);
27
- }
28
- if (subscribers.onCertificateFailed) {
29
- handler.on(Port80HandlerEvents.CERTIFICATE_FAILED, subscribers.onCertificateFailed);
30
- }
31
- if (subscribers.onCertificateExpiring) {
32
- handler.on(Port80HandlerEvents.CERTIFICATE_EXPIRING, subscribers.onCertificateExpiring);
33
- }
34
- }
@@ -1,91 +0,0 @@
1
- import * as plugins from '../plugins.js';
2
-
3
- /**
4
- * Shared types for certificate management and domain options
5
- */
6
-
7
- /**
8
- * Domain forwarding configuration
9
- */
10
- export interface IForwardConfig {
11
- ip: string;
12
- port: number;
13
- }
14
-
15
- /**
16
- * Domain configuration options
17
- */
18
- export interface IDomainOptions {
19
- domainName: string;
20
- sslRedirect: boolean; // if true redirects the request to port 443
21
- acmeMaintenance: boolean; // tries to always have a valid cert for this domain
22
- forward?: IForwardConfig; // forwards all http requests to that target
23
- acmeForward?: IForwardConfig; // forwards letsencrypt requests to this config
24
- }
25
-
26
- /**
27
- * Certificate data that can be emitted via events or set from outside
28
- */
29
- export interface ICertificateData {
30
- domain: string;
31
- certificate: string;
32
- privateKey: string;
33
- expiryDate: Date;
34
- }
35
-
36
- /**
37
- * Events emitted by the Port80Handler
38
- */
39
- export enum Port80HandlerEvents {
40
- CERTIFICATE_ISSUED = 'certificate-issued',
41
- CERTIFICATE_RENEWED = 'certificate-renewed',
42
- CERTIFICATE_FAILED = 'certificate-failed',
43
- CERTIFICATE_EXPIRING = 'certificate-expiring',
44
- MANAGER_STARTED = 'manager-started',
45
- MANAGER_STOPPED = 'manager-stopped',
46
- REQUEST_FORWARDED = 'request-forwarded',
47
- }
48
-
49
- /**
50
- * Certificate failure payload type
51
- */
52
- export interface ICertificateFailure {
53
- domain: string;
54
- error: string;
55
- isRenewal: boolean;
56
- }
57
-
58
- /**
59
- * Certificate expiry payload type
60
- */
61
- export interface ICertificateExpiring {
62
- domain: string;
63
- expiryDate: Date;
64
- daysRemaining: number;
65
- }
66
- /**
67
- * Forwarding configuration for specific domains in ACME setup
68
- */
69
- export interface IDomainForwardConfig {
70
- domain: string;
71
- forwardConfig?: IForwardConfig;
72
- acmeForwardConfig?: IForwardConfig;
73
- sslRedirect?: boolean;
74
- }
75
-
76
- /**
77
- * Unified ACME configuration options used across proxies and handlers
78
- */
79
- export interface IAcmeOptions {
80
- accountEmail?: string; // Email for Let's Encrypt account
81
- enabled?: boolean; // Whether ACME is enabled
82
- port?: number; // Port to listen on for ACME challenges (default: 80)
83
- useProduction?: boolean; // Use production environment (default: staging)
84
- httpsRedirectPort?: number; // Port to redirect HTTP requests to HTTPS (default: 443)
85
- renewThresholdDays?: number; // Days before expiry to renew certificates
86
- renewCheckIntervalHours?: number; // How often to check for renewals (in hours)
87
- autoRenew?: boolean; // Whether to automatically renew certificates
88
- certificateStore?: string; // Directory to store certificates
89
- skipConfiguredCerts?: boolean; // Skip domains with existing certificates
90
- domainForwards?: IDomainForwardConfig[]; // Domain-specific forwarding configs
91
- }
@@ -1,376 +0,0 @@
1
- import * as plugins from '../../plugins.js';
2
- import type {
3
- ICertificateData,
4
- ICertificateFailure,
5
- ICertificateExpiring
6
- } from '../models/common-types.js';
7
- import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js';
8
- import { Port80HandlerEvents } from '../models/common-types.js';
9
-
10
- /**
11
- * Standardized event names used throughout the system
12
- */
13
- export enum ProxyEvents {
14
- // Certificate events
15
- CERTIFICATE_ISSUED = 'certificate:issued',
16
- CERTIFICATE_RENEWED = 'certificate:renewed',
17
- CERTIFICATE_FAILED = 'certificate:failed',
18
- CERTIFICATE_EXPIRING = 'certificate:expiring',
19
-
20
- // Component lifecycle events
21
- COMPONENT_STARTED = 'component:started',
22
- COMPONENT_STOPPED = 'component:stopped',
23
-
24
- // Connection events
25
- CONNECTION_ESTABLISHED = 'connection:established',
26
- CONNECTION_CLOSED = 'connection:closed',
27
- CONNECTION_ERROR = 'connection:error',
28
-
29
- // Request events
30
- REQUEST_RECEIVED = 'request:received',
31
- REQUEST_COMPLETED = 'request:completed',
32
- REQUEST_ERROR = 'request:error',
33
-
34
- // Route events
35
- ROUTE_MATCHED = 'route:matched',
36
- ROUTE_UPDATED = 'route:updated',
37
- ROUTE_ERROR = 'route:error',
38
-
39
- // Security events
40
- SECURITY_BLOCKED = 'security:blocked',
41
- SECURITY_BREACH_ATTEMPT = 'security:breach-attempt',
42
-
43
- // TLS events
44
- TLS_HANDSHAKE_STARTED = 'tls:handshake-started',
45
- TLS_HANDSHAKE_COMPLETED = 'tls:handshake-completed',
46
- TLS_HANDSHAKE_FAILED = 'tls:handshake-failed'
47
- }
48
-
49
- /**
50
- * Component types for event metadata
51
- */
52
- export enum ComponentType {
53
- SMART_PROXY = 'smart-proxy',
54
- NETWORK_PROXY = 'network-proxy',
55
- NFTABLES_PROXY = 'nftables-proxy',
56
- PORT80_HANDLER = 'port80-handler',
57
- CERTIFICATE_MANAGER = 'certificate-manager',
58
- ROUTE_MANAGER = 'route-manager',
59
- CONNECTION_MANAGER = 'connection-manager',
60
- TLS_MANAGER = 'tls-manager',
61
- SECURITY_MANAGER = 'security-manager'
62
- }
63
-
64
- /**
65
- * Base event data interface
66
- */
67
- export interface IEventData {
68
- timestamp: number;
69
- componentType: ComponentType;
70
- componentId?: string;
71
- }
72
-
73
- /**
74
- * Certificate event data
75
- */
76
- export interface ICertificateEventData extends IEventData, ICertificateData {
77
- isRenewal?: boolean;
78
- source?: string;
79
- }
80
-
81
- /**
82
- * Certificate failure event data
83
- */
84
- export interface ICertificateFailureEventData extends IEventData, ICertificateFailure {}
85
-
86
- /**
87
- * Certificate expiring event data
88
- */
89
- export interface ICertificateExpiringEventData extends IEventData, ICertificateExpiring {}
90
-
91
- /**
92
- * Component lifecycle event data
93
- */
94
- export interface IComponentEventData extends IEventData {
95
- name: string;
96
- version?: string;
97
- }
98
-
99
- /**
100
- * Connection event data
101
- */
102
- export interface IConnectionEventData extends IEventData {
103
- connectionId: string;
104
- clientIp: string;
105
- serverIp?: string;
106
- port: number;
107
- isTls?: boolean;
108
- domain?: string;
109
- }
110
-
111
- /**
112
- * Request event data
113
- */
114
- export interface IRequestEventData extends IEventData {
115
- connectionId: string;
116
- requestId: string;
117
- method?: string;
118
- path?: string;
119
- statusCode?: number;
120
- duration?: number;
121
- routeId?: string;
122
- routeName?: string;
123
- }
124
-
125
- /**
126
- * Route event data
127
- */
128
- export interface IRouteEventData extends IEventData {
129
- route: IRouteConfig;
130
- context?: any;
131
- }
132
-
133
- /**
134
- * Security event data
135
- */
136
- export interface ISecurityEventData extends IEventData {
137
- clientIp: string;
138
- reason: string;
139
- routeId?: string;
140
- routeName?: string;
141
- }
142
-
143
- /**
144
- * TLS event data
145
- */
146
- export interface ITlsEventData extends IEventData {
147
- connectionId: string;
148
- domain?: string;
149
- clientIp: string;
150
- tlsVersion?: string;
151
- cipherSuite?: string;
152
- sniHostname?: string;
153
- }
154
-
155
- /**
156
- * Logger interface for event system
157
- */
158
- export interface IEventLogger {
159
- info: (message: string, ...args: any[]) => void;
160
- warn: (message: string, ...args: any[]) => void;
161
- error: (message: string, ...args: any[]) => void;
162
- debug?: (message: string, ...args: any[]) => void;
163
- }
164
-
165
- /**
166
- * Event handler type
167
- */
168
- export type EventHandler<T> = (data: T) => void;
169
-
170
- /**
171
- * Helper class to standardize event emission and handling
172
- * across all system components
173
- */
174
- export class EventSystem {
175
- private emitter: plugins.EventEmitter;
176
- private componentType: ComponentType;
177
- private componentId: string;
178
- private logger?: IEventLogger;
179
-
180
- constructor(
181
- componentType: ComponentType,
182
- componentId: string = '',
183
- logger?: IEventLogger
184
- ) {
185
- this.emitter = new plugins.EventEmitter();
186
- this.componentType = componentType;
187
- this.componentId = componentId;
188
- this.logger = logger;
189
- }
190
-
191
- /**
192
- * Emit a certificate issued event
193
- */
194
- public emitCertificateIssued(data: Omit<ICertificateEventData, 'timestamp' | 'componentType' | 'componentId'>): void {
195
- const eventData: ICertificateEventData = {
196
- ...data,
197
- timestamp: Date.now(),
198
- componentType: this.componentType,
199
- componentId: this.componentId
200
- };
201
-
202
- this.logger?.info?.(`Certificate issued for ${data.domain}`);
203
- this.emitter.emit(ProxyEvents.CERTIFICATE_ISSUED, eventData);
204
- }
205
-
206
- /**
207
- * Emit a certificate renewed event
208
- */
209
- public emitCertificateRenewed(data: Omit<ICertificateEventData, 'timestamp' | 'componentType' | 'componentId'>): void {
210
- const eventData: ICertificateEventData = {
211
- ...data,
212
- timestamp: Date.now(),
213
- componentType: this.componentType,
214
- componentId: this.componentId
215
- };
216
-
217
- this.logger?.info?.(`Certificate renewed for ${data.domain}`);
218
- this.emitter.emit(ProxyEvents.CERTIFICATE_RENEWED, eventData);
219
- }
220
-
221
- /**
222
- * Emit a certificate failed event
223
- */
224
- public emitCertificateFailed(data: Omit<ICertificateFailureEventData, 'timestamp' | 'componentType' | 'componentId'>): void {
225
- const eventData: ICertificateFailureEventData = {
226
- ...data,
227
- timestamp: Date.now(),
228
- componentType: this.componentType,
229
- componentId: this.componentId
230
- };
231
-
232
- this.logger?.error?.(`Certificate issuance failed for ${data.domain}: ${data.error}`);
233
- this.emitter.emit(ProxyEvents.CERTIFICATE_FAILED, eventData);
234
- }
235
-
236
- /**
237
- * Emit a certificate expiring event
238
- */
239
- public emitCertificateExpiring(data: Omit<ICertificateExpiringEventData, 'timestamp' | 'componentType' | 'componentId'>): void {
240
- const eventData: ICertificateExpiringEventData = {
241
- ...data,
242
- timestamp: Date.now(),
243
- componentType: this.componentType,
244
- componentId: this.componentId
245
- };
246
-
247
- this.logger?.warn?.(`Certificate expiring for ${data.domain} in ${data.daysRemaining} days`);
248
- this.emitter.emit(ProxyEvents.CERTIFICATE_EXPIRING, eventData);
249
- }
250
-
251
- /**
252
- * Emit a component started event
253
- */
254
- public emitComponentStarted(name: string, version?: string): void {
255
- const eventData: IComponentEventData = {
256
- name,
257
- version,
258
- timestamp: Date.now(),
259
- componentType: this.componentType,
260
- componentId: this.componentId
261
- };
262
-
263
- this.logger?.info?.(`Component ${name} started${version ? ` (v${version})` : ''}`);
264
- this.emitter.emit(ProxyEvents.COMPONENT_STARTED, eventData);
265
- }
266
-
267
- /**
268
- * Emit a component stopped event
269
- */
270
- public emitComponentStopped(name: string): void {
271
- const eventData: IComponentEventData = {
272
- name,
273
- timestamp: Date.now(),
274
- componentType: this.componentType,
275
- componentId: this.componentId
276
- };
277
-
278
- this.logger?.info?.(`Component ${name} stopped`);
279
- this.emitter.emit(ProxyEvents.COMPONENT_STOPPED, eventData);
280
- }
281
-
282
- /**
283
- * Emit a connection established event
284
- */
285
- public emitConnectionEstablished(data: Omit<IConnectionEventData, 'timestamp' | 'componentType' | 'componentId'>): void {
286
- const eventData: IConnectionEventData = {
287
- ...data,
288
- timestamp: Date.now(),
289
- componentType: this.componentType,
290
- componentId: this.componentId
291
- };
292
-
293
- this.logger?.debug?.(`Connection ${data.connectionId} established from ${data.clientIp} on port ${data.port}`);
294
- this.emitter.emit(ProxyEvents.CONNECTION_ESTABLISHED, eventData);
295
- }
296
-
297
- /**
298
- * Emit a connection closed event
299
- */
300
- public emitConnectionClosed(data: Omit<IConnectionEventData, 'timestamp' | 'componentType' | 'componentId'>): void {
301
- const eventData: IConnectionEventData = {
302
- ...data,
303
- timestamp: Date.now(),
304
- componentType: this.componentType,
305
- componentId: this.componentId
306
- };
307
-
308
- this.logger?.debug?.(`Connection ${data.connectionId} closed`);
309
- this.emitter.emit(ProxyEvents.CONNECTION_CLOSED, eventData);
310
- }
311
-
312
- /**
313
- * Emit a route matched event
314
- */
315
- public emitRouteMatched(data: Omit<IRouteEventData, 'timestamp' | 'componentType' | 'componentId'>): void {
316
- const eventData: IRouteEventData = {
317
- ...data,
318
- timestamp: Date.now(),
319
- componentType: this.componentType,
320
- componentId: this.componentId
321
- };
322
-
323
- this.logger?.debug?.(`Route matched: ${data.route.name || data.route.id || 'unnamed'}`);
324
- this.emitter.emit(ProxyEvents.ROUTE_MATCHED, eventData);
325
- }
326
-
327
- /**
328
- * Subscribe to an event
329
- */
330
- public on<T>(event: ProxyEvents, handler: EventHandler<T>): void {
331
- this.emitter.on(event, handler);
332
- }
333
-
334
- /**
335
- * Subscribe to an event once
336
- */
337
- public once<T>(event: ProxyEvents, handler: EventHandler<T>): void {
338
- this.emitter.once(event, handler);
339
- }
340
-
341
- /**
342
- * Unsubscribe from an event
343
- */
344
- public off<T>(event: ProxyEvents, handler: EventHandler<T>): void {
345
- this.emitter.off(event, handler);
346
- }
347
-
348
- /**
349
- * Map Port80Handler events to standard proxy events
350
- */
351
- public subscribePort80HandlerEvents(handler: any): void {
352
- handler.on(Port80HandlerEvents.CERTIFICATE_ISSUED, (data: ICertificateData) => {
353
- this.emitCertificateIssued({
354
- ...data,
355
- isRenewal: false,
356
- source: 'port80handler'
357
- });
358
- });
359
-
360
- handler.on(Port80HandlerEvents.CERTIFICATE_RENEWED, (data: ICertificateData) => {
361
- this.emitCertificateRenewed({
362
- ...data,
363
- isRenewal: true,
364
- source: 'port80handler'
365
- });
366
- });
367
-
368
- handler.on(Port80HandlerEvents.CERTIFICATE_FAILED, (data: ICertificateFailure) => {
369
- this.emitCertificateFailed(data);
370
- });
371
-
372
- handler.on(Port80HandlerEvents.CERTIFICATE_EXPIRING, (data: ICertificateExpiring) => {
373
- this.emitCertificateExpiring(data);
374
- });
375
- }
376
- }
@@ -1,25 +0,0 @@
1
- // Port80Handler has been removed - use SmartCertManager instead
2
- import { Port80HandlerEvents } from '../models/common-types.js';
3
-
4
- // Re-export for backward compatibility
5
- export { Port80HandlerEvents };
6
-
7
- /**
8
- * @deprecated Use SmartCertManager instead
9
- */
10
- export interface IPort80HandlerSubscribers {
11
- onCertificateIssued?: (data: any) => void;
12
- onCertificateRenewed?: (data: any) => void;
13
- onCertificateFailed?: (data: any) => void;
14
- onCertificateExpiring?: (data: any) => void;
15
- }
16
-
17
- /**
18
- * @deprecated Use SmartCertManager instead
19
- */
20
- export function subscribeToPort80Handler(
21
- handler: any,
22
- subscribers: IPort80HandlerSubscribers
23
- ): void {
24
- console.warn('subscribeToPort80Handler is deprecated - use SmartCertManager instead');
25
- }