@push.rocks/smartproxy 22.4.2 → 22.6.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 (72) hide show
  1. package/changelog.md +28 -0
  2. package/dist_rust/rustproxy +0 -0
  3. package/dist_ts/00_commitinfo_data.js +1 -1
  4. package/dist_ts/index.d.ts +1 -5
  5. package/dist_ts/index.js +3 -9
  6. package/dist_ts/protocols/common/fragment-handler.js +5 -1
  7. package/dist_ts/proxies/index.d.ts +1 -5
  8. package/dist_ts/proxies/index.js +2 -6
  9. package/dist_ts/proxies/smart-proxy/index.d.ts +5 -10
  10. package/dist_ts/proxies/smart-proxy/index.js +7 -13
  11. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -2
  12. package/dist_ts/proxies/smart-proxy/route-preprocessor.d.ts +37 -0
  13. package/dist_ts/proxies/smart-proxy/route-preprocessor.js +103 -0
  14. package/dist_ts/proxies/smart-proxy/rust-binary-locator.d.ts +23 -0
  15. package/dist_ts/proxies/smart-proxy/rust-binary-locator.js +104 -0
  16. package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.d.ts +74 -0
  17. package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.js +146 -0
  18. package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.d.ts +49 -0
  19. package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.js +259 -0
  20. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +39 -157
  21. package/dist_ts/proxies/smart-proxy/smart-proxy.js +224 -621
  22. package/dist_ts/proxies/smart-proxy/socket-handler-server.d.ts +45 -0
  23. package/dist_ts/proxies/smart-proxy/socket-handler-server.js +253 -0
  24. package/dist_ts/routing/index.d.ts +1 -1
  25. package/dist_ts/routing/index.js +3 -3
  26. package/dist_ts/routing/models/http-types.d.ts +119 -4
  27. package/dist_ts/routing/models/http-types.js +93 -5
  28. package/package.json +1 -1
  29. package/readme.md +470 -219
  30. package/ts/00_commitinfo_data.ts +1 -1
  31. package/ts/index.ts +4 -12
  32. package/ts/protocols/common/fragment-handler.ts +4 -0
  33. package/ts/proxies/index.ts +1 -9
  34. package/ts/proxies/smart-proxy/index.ts +6 -13
  35. package/ts/proxies/smart-proxy/models/interfaces.ts +6 -4
  36. package/ts/proxies/smart-proxy/route-preprocessor.ts +122 -0
  37. package/ts/proxies/smart-proxy/rust-binary-locator.ts +112 -0
  38. package/ts/proxies/smart-proxy/rust-metrics-adapter.ts +161 -0
  39. package/ts/proxies/smart-proxy/rust-proxy-bridge.ts +310 -0
  40. package/ts/proxies/smart-proxy/smart-proxy.ts +282 -798
  41. package/ts/proxies/smart-proxy/socket-handler-server.ts +279 -0
  42. package/ts/routing/index.ts +2 -2
  43. package/ts/routing/models/http-types.ts +147 -4
  44. package/ts/proxies/http-proxy/connection-pool.ts +0 -228
  45. package/ts/proxies/http-proxy/context-creator.ts +0 -145
  46. package/ts/proxies/http-proxy/default-certificates.ts +0 -150
  47. package/ts/proxies/http-proxy/function-cache.ts +0 -279
  48. package/ts/proxies/http-proxy/handlers/index.ts +0 -5
  49. package/ts/proxies/http-proxy/http-proxy.ts +0 -669
  50. package/ts/proxies/http-proxy/http-request-handler.ts +0 -331
  51. package/ts/proxies/http-proxy/http2-request-handler.ts +0 -255
  52. package/ts/proxies/http-proxy/index.ts +0 -18
  53. package/ts/proxies/http-proxy/models/http-types.ts +0 -148
  54. package/ts/proxies/http-proxy/models/index.ts +0 -5
  55. package/ts/proxies/http-proxy/models/types.ts +0 -125
  56. package/ts/proxies/http-proxy/request-handler.ts +0 -878
  57. package/ts/proxies/http-proxy/security-manager.ts +0 -413
  58. package/ts/proxies/http-proxy/websocket-handler.ts +0 -581
  59. package/ts/proxies/smart-proxy/acme-state-manager.ts +0 -112
  60. package/ts/proxies/smart-proxy/cert-store.ts +0 -92
  61. package/ts/proxies/smart-proxy/certificate-manager.ts +0 -895
  62. package/ts/proxies/smart-proxy/connection-manager.ts +0 -809
  63. package/ts/proxies/smart-proxy/http-proxy-bridge.ts +0 -213
  64. package/ts/proxies/smart-proxy/metrics-collector.ts +0 -453
  65. package/ts/proxies/smart-proxy/nftables-manager.ts +0 -271
  66. package/ts/proxies/smart-proxy/port-manager.ts +0 -358
  67. package/ts/proxies/smart-proxy/route-connection-handler.ts +0 -1712
  68. package/ts/proxies/smart-proxy/route-orchestrator.ts +0 -297
  69. package/ts/proxies/smart-proxy/security-manager.ts +0 -269
  70. package/ts/proxies/smart-proxy/throughput-tracker.ts +0 -138
  71. package/ts/proxies/smart-proxy/timeout-manager.ts +0 -196
  72. package/ts/proxies/smart-proxy/tls-manager.ts +0 -171
@@ -1,148 +0,0 @@
1
- import * as plugins from '../../../plugins.js';
2
- // Import from protocols for consistent status codes
3
- import { HttpStatus as ProtocolHttpStatus, getStatusText as getProtocolStatusText } from '../../../protocols/http/index.js';
4
-
5
- /**
6
- * HTTP-specific event types
7
- */
8
- export enum HttpEvents {
9
- REQUEST_RECEIVED = 'request-received',
10
- REQUEST_FORWARDED = 'request-forwarded',
11
- REQUEST_HANDLED = 'request-handled',
12
- REQUEST_ERROR = 'request-error',
13
- }
14
-
15
-
16
- // Re-export for backward compatibility with subset of commonly used codes
17
- export const HttpStatus = {
18
- OK: ProtocolHttpStatus.OK,
19
- MOVED_PERMANENTLY: ProtocolHttpStatus.MOVED_PERMANENTLY,
20
- FOUND: ProtocolHttpStatus.FOUND,
21
- TEMPORARY_REDIRECT: ProtocolHttpStatus.TEMPORARY_REDIRECT,
22
- PERMANENT_REDIRECT: ProtocolHttpStatus.PERMANENT_REDIRECT,
23
- BAD_REQUEST: ProtocolHttpStatus.BAD_REQUEST,
24
- UNAUTHORIZED: ProtocolHttpStatus.UNAUTHORIZED,
25
- FORBIDDEN: ProtocolHttpStatus.FORBIDDEN,
26
- NOT_FOUND: ProtocolHttpStatus.NOT_FOUND,
27
- METHOD_NOT_ALLOWED: ProtocolHttpStatus.METHOD_NOT_ALLOWED,
28
- REQUEST_TIMEOUT: ProtocolHttpStatus.REQUEST_TIMEOUT,
29
- TOO_MANY_REQUESTS: ProtocolHttpStatus.TOO_MANY_REQUESTS,
30
- INTERNAL_SERVER_ERROR: ProtocolHttpStatus.INTERNAL_SERVER_ERROR,
31
- NOT_IMPLEMENTED: ProtocolHttpStatus.NOT_IMPLEMENTED,
32
- BAD_GATEWAY: ProtocolHttpStatus.BAD_GATEWAY,
33
- SERVICE_UNAVAILABLE: ProtocolHttpStatus.SERVICE_UNAVAILABLE,
34
- GATEWAY_TIMEOUT: ProtocolHttpStatus.GATEWAY_TIMEOUT,
35
- } as const;
36
-
37
- /**
38
- * Base error class for HTTP-related errors
39
- */
40
- export class HttpError extends Error {
41
- constructor(message: string, public readonly statusCode: number = HttpStatus.INTERNAL_SERVER_ERROR) {
42
- super(message);
43
- this.name = 'HttpError';
44
- }
45
- }
46
-
47
- /**
48
- * Error related to certificate operations
49
- */
50
- export class CertificateError extends HttpError {
51
- constructor(
52
- message: string,
53
- public readonly domain: string,
54
- public readonly isRenewal: boolean = false
55
- ) {
56
- super(`${message} for domain ${domain}${isRenewal ? ' (renewal)' : ''}`, HttpStatus.INTERNAL_SERVER_ERROR);
57
- this.name = 'CertificateError';
58
- }
59
- }
60
-
61
- /**
62
- * Error related to server operations
63
- */
64
- export class ServerError extends HttpError {
65
- constructor(message: string, public readonly code?: string, statusCode: number = HttpStatus.INTERNAL_SERVER_ERROR) {
66
- super(message, statusCode);
67
- this.name = 'ServerError';
68
- }
69
- }
70
-
71
- /**
72
- * Error for bad requests
73
- */
74
- export class BadRequestError extends HttpError {
75
- constructor(message: string) {
76
- super(message, HttpStatus.BAD_REQUEST);
77
- this.name = 'BadRequestError';
78
- }
79
- }
80
-
81
- /**
82
- * Error for not found resources
83
- */
84
- export class NotFoundError extends HttpError {
85
- constructor(message: string = 'Resource not found') {
86
- super(message, HttpStatus.NOT_FOUND);
87
- this.name = 'NotFoundError';
88
- }
89
- }
90
-
91
- /**
92
- * Redirect configuration for HTTP requests
93
- */
94
- export interface IRedirectConfig {
95
- source: string; // Source path or pattern
96
- destination: string; // Destination URL
97
- type: number; // Redirect status code
98
- preserveQuery?: boolean; // Whether to preserve query parameters
99
- }
100
-
101
- /**
102
- * HTTP router configuration
103
- */
104
- export interface IRouterConfig {
105
- routes: Array<{
106
- path: string;
107
- method?: string;
108
- handler: (req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse) => void | Promise<void>;
109
- }>;
110
- notFoundHandler?: (req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse) => void;
111
- errorHandler?: (error: Error, req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse) => void;
112
- }
113
-
114
- /**
115
- * HTTP request method types
116
- */
117
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
118
-
119
-
120
- /**
121
- * Helper function to get HTTP status text
122
- */
123
- export function getStatusText(status: number): string {
124
- return getProtocolStatusText(status as ProtocolHttpStatus);
125
- }
126
-
127
- // Legacy interfaces for backward compatibility
128
- export interface IDomainOptions {
129
- domainName: string;
130
- sslRedirect: boolean;
131
- acmeMaintenance: boolean;
132
- forward?: { ip: string; port: number };
133
- acmeForward?: { ip: string; port: number };
134
- }
135
-
136
- export interface IDomainCertificate {
137
- options: IDomainOptions;
138
- certObtained: boolean;
139
- obtainingInProgress: boolean;
140
- certificate?: string;
141
- privateKey?: string;
142
- expiryDate?: Date;
143
- lastRenewalAttempt?: Date;
144
- }
145
-
146
- // Backward compatibility exports
147
- export { HttpError as Port80HandlerError };
148
- export { CertificateError as CertError };
@@ -1,5 +0,0 @@
1
- /**
2
- * HttpProxy models
3
- */
4
- export * from './types.js';
5
- export * from './http-types.js';
@@ -1,125 +0,0 @@
1
- import * as plugins from '../../../plugins.js';
2
- // Certificate types removed - define IAcmeOptions locally
3
- export interface IAcmeOptions {
4
- enabled: boolean;
5
- email?: string;
6
- accountEmail?: string;
7
- port?: number;
8
- certificateStore?: string;
9
- environment?: 'production' | 'staging';
10
- useProduction?: boolean;
11
- renewThresholdDays?: number;
12
- autoRenew?: boolean;
13
- skipConfiguredCerts?: boolean;
14
- }
15
- import type { IRouteConfig } from '../../smart-proxy/models/route-types.js';
16
-
17
- /**
18
- * Configuration options for HttpProxy
19
- */
20
- export interface IHttpProxyOptions {
21
- port: number;
22
- maxConnections?: number;
23
- keepAliveTimeout?: number;
24
- headersTimeout?: number;
25
- logLevel?: 'error' | 'warn' | 'info' | 'debug';
26
- cors?: {
27
- allowOrigin?: string;
28
- allowMethods?: string;
29
- allowHeaders?: string;
30
- maxAge?: number;
31
- };
32
-
33
- // Settings for SmartProxy integration
34
- connectionPoolSize?: number; // Maximum connections to maintain in the pool to each backend
35
- portProxyIntegration?: boolean; // Flag to indicate this proxy is used by SmartProxy
36
- // Protocol to use when proxying to backends: HTTP/1.x or HTTP/2
37
- backendProtocol?: 'http1' | 'http2';
38
-
39
- // Function cache options
40
- functionCacheSize?: number; // Maximum number of cached function results (default: 1000)
41
- functionCacheTtl?: number; // Time to live for cached function results in ms (default: 5000)
42
-
43
- // ACME certificate management options
44
- acme?: IAcmeOptions;
45
-
46
- // Direct route configurations
47
- routes?: IRouteConfig[];
48
-
49
- // Rate limiting and security
50
- maxConnectionsPerIP?: number; // Maximum simultaneous connections from a single IP
51
- connectionRateLimitPerMinute?: number; // Max new connections per minute from a single IP
52
- }
53
-
54
- /**
55
- * Interface for a certificate entry in the cache
56
- */
57
- export interface ICertificateEntry {
58
- key: string;
59
- cert: string;
60
- expires?: Date;
61
- }
62
-
63
-
64
-
65
- /**
66
- * Interface for connection tracking in the pool
67
- */
68
- export interface IConnectionEntry {
69
- socket: plugins.net.Socket;
70
- lastUsed: number;
71
- isIdle: boolean;
72
- }
73
-
74
- /**
75
- * WebSocket with heartbeat interface
76
- */
77
- export interface IWebSocketWithHeartbeat extends plugins.wsDefault {
78
- lastPong: number;
79
- isAlive: boolean;
80
- }
81
-
82
- /**
83
- * Logger interface for consistent logging across components
84
- */
85
- export interface ILogger {
86
- debug(message: string, data?: any): void;
87
- info(message: string, data?: any): void;
88
- warn(message: string, data?: any): void;
89
- error(message: string, data?: any): void;
90
- }
91
-
92
- /**
93
- * Creates a logger based on the specified log level
94
- */
95
- export function createLogger(logLevel: string = 'info'): ILogger {
96
- const logLevels = {
97
- error: 0,
98
- warn: 1,
99
- info: 2,
100
- debug: 3
101
- };
102
-
103
- return {
104
- debug: (message: string, data?: any) => {
105
- if (logLevels[logLevel] >= logLevels.debug) {
106
- console.log(`[DEBUG] ${message}`, data || '');
107
- }
108
- },
109
- info: (message: string, data?: any) => {
110
- if (logLevels[logLevel] >= logLevels.info) {
111
- console.log(`[INFO] ${message}`, data || '');
112
- }
113
- },
114
- warn: (message: string, data?: any) => {
115
- if (logLevels[logLevel] >= logLevels.warn) {
116
- console.warn(`[WARN] ${message}`, data || '');
117
- }
118
- },
119
- error: (message: string, data?: any) => {
120
- if (logLevels[logLevel] >= logLevels.error) {
121
- console.error(`[ERROR] ${message}`, data || '');
122
- }
123
- }
124
- };
125
- }