@push.rocks/smartproxy 4.3.0 → 5.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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartproxy',
6
- version: '4.3.0',
6
+ version: '5.0.0',
7
7
  description: 'A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLG1PQUFtTztDQUNqUCxDQUFBIn0=
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Custom error classes for better error handling
3
+ */
4
+ export declare class NftBaseError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare class NftValidationError extends NftBaseError {
8
+ constructor(message: string);
9
+ }
10
+ export declare class NftExecutionError extends NftBaseError {
11
+ constructor(message: string);
12
+ }
13
+ export declare class NftResourceError extends NftBaseError {
14
+ constructor(message: string);
15
+ }
16
+ /**
17
+ * Represents a port range for forwarding
18
+ */
19
+ export interface IPortRange {
20
+ from: number;
21
+ to: number;
22
+ }
23
+ /**
24
+ * Settings for NfTablesProxy.
25
+ */
26
+ export interface INfTableProxySettings {
27
+ fromPort: number | IPortRange | Array<number | IPortRange>;
28
+ toPort: number | IPortRange | Array<number | IPortRange>;
29
+ toHost?: string;
30
+ preserveSourceIP?: boolean;
31
+ deleteOnExit?: boolean;
32
+ protocol?: 'tcp' | 'udp' | 'all';
33
+ enableLogging?: boolean;
34
+ ipv6Support?: boolean;
35
+ logFormat?: 'plain' | 'json';
36
+ allowedSourceIPs?: string[];
37
+ bannedSourceIPs?: string[];
38
+ useIPSets?: boolean;
39
+ forceCleanSlate?: boolean;
40
+ tableName?: string;
41
+ maxRetries?: number;
42
+ retryDelayMs?: number;
43
+ useAdvancedNAT?: boolean;
44
+ qos?: {
45
+ enabled: boolean;
46
+ maxRate?: string;
47
+ priority?: number;
48
+ markConnections?: boolean;
49
+ };
50
+ netProxyIntegration?: {
51
+ enabled: boolean;
52
+ redirectLocalhost?: boolean;
53
+ sslTerminationPort?: number;
54
+ };
55
+ }
56
+ /**
57
+ * Interface for status reporting
58
+ */
59
+ export interface INfTablesStatus {
60
+ active: boolean;
61
+ ruleCount: {
62
+ total: number;
63
+ added: number;
64
+ verified: number;
65
+ };
66
+ tablesConfigured: {
67
+ family: string;
68
+ tableName: string;
69
+ }[];
70
+ metrics: {
71
+ forwardedConnections?: number;
72
+ activeConnections?: number;
73
+ bytesForwarded?: {
74
+ sent: number;
75
+ received: number;
76
+ };
77
+ };
78
+ qosEnabled?: boolean;
79
+ ipSetsConfigured?: {
80
+ name: string;
81
+ elementCount: number;
82
+ type: string;
83
+ }[];
84
+ }
85
+ /**
86
+ * NfTablesProxy sets up nftables NAT rules to forward TCP traffic.
87
+ * Enhanced with multi-port support, IPv6, connection tracking, metrics,
88
+ * and more advanced features.
89
+ */
90
+ export declare class NfTablesProxy {
91
+ settings: INfTableProxySettings;
92
+ private rules;
93
+ private ipSets;
94
+ private ruleTag;
95
+ private tableName;
96
+ private tempFilePath;
97
+ private static NFT_CMD;
98
+ constructor(settings: INfTableProxySettings);
99
+ /**
100
+ * Validates settings to prevent command injection and ensure valid values
101
+ */
102
+ private validateSettings;
103
+ /**
104
+ * Normalizes port specifications into an array of port ranges
105
+ */
106
+ private normalizePortSpec;
107
+ /**
108
+ * Execute a command with retry capability
109
+ */
110
+ private executeWithRetry;
111
+ /**
112
+ * Execute system command synchronously with multiple attempts
113
+ */
114
+ private executeWithRetrySync;
115
+ /**
116
+ * Checks if nftables is available and the required modules are loaded
117
+ */
118
+ private checkNftablesAvailability;
119
+ /**
120
+ * Creates the necessary tables and chains
121
+ */
122
+ private setupTablesAndChains;
123
+ /**
124
+ * Creates IP sets for efficient filtering of large IP lists
125
+ */
126
+ private createIPSet;
127
+ /**
128
+ * Adds source IP filtering rules, potentially using IP sets for efficiency
129
+ */
130
+ private addSourceIPFilters;
131
+ /**
132
+ * Gets a comma-separated list of all ports from a port specification
133
+ */
134
+ private getAllPorts;
135
+ /**
136
+ * Configures advanced NAT with connection tracking
137
+ */
138
+ private setupAdvancedNAT;
139
+ /**
140
+ * Adds port forwarding rules
141
+ */
142
+ private addPortForwardingRules;
143
+ /**
144
+ * Adds port forwarding rules for the case where one toPortRange maps to multiple fromPortRanges
145
+ */
146
+ private addPortMappings;
147
+ /**
148
+ * Adds port forwarding rules for pairs of fromPortRanges and toPortRanges
149
+ */
150
+ private addPortPairMappings;
151
+ /**
152
+ * Setup quality of service rules
153
+ */
154
+ private addTrafficShaping;
155
+ /**
156
+ * Setup NetworkProxy integration rules
157
+ */
158
+ private setupNetworkProxyIntegration;
159
+ /**
160
+ * Verify that a rule was successfully applied
161
+ */
162
+ private verifyRuleApplication;
163
+ /**
164
+ * Rolls back rules in case of error during setup
165
+ */
166
+ private rollbackRules;
167
+ /**
168
+ * Checks if nftables table exists
169
+ */
170
+ private tableExists;
171
+ /**
172
+ * Get system metrics like connection counts
173
+ */
174
+ private getSystemMetrics;
175
+ /**
176
+ * Get status of IP sets
177
+ */
178
+ private getIPSetStatus;
179
+ /**
180
+ * Get detailed status about the current state of the proxy
181
+ */
182
+ getStatus(): Promise<INfTablesStatus>;
183
+ /**
184
+ * Performs a dry run to see what commands would be executed without actually applying them
185
+ */
186
+ dryRun(): Promise<string[]>;
187
+ /**
188
+ * Starts the proxy by setting up all nftables rules
189
+ */
190
+ start(): Promise<void>;
191
+ /**
192
+ * Stops the proxy by removing all added rules
193
+ */
194
+ stop(): Promise<void>;
195
+ /**
196
+ * Synchronous version of stop, for use in exit handlers
197
+ */
198
+ stopSync(): void;
199
+ /**
200
+ * Cleans up empty tables
201
+ */
202
+ private cleanupEmptyTables;
203
+ /**
204
+ * Synchronous version of cleanupEmptyTables
205
+ */
206
+ private cleanupEmptyTablesSync;
207
+ /**
208
+ * Removes all nftables rules created by this module
209
+ */
210
+ static cleanSlate(): Promise<void>;
211
+ /**
212
+ * Synchronous version of cleanSlate
213
+ */
214
+ static cleanSlateSync(): void;
215
+ /**
216
+ * Improved logging with structured output
217
+ */
218
+ private log;
219
+ }