@push.rocks/smartproxy 4.2.4 → 4.3.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.
@@ -1,8 +1,40 @@
1
1
  import * as plugins from './plugins.js';
2
2
  /**
3
- * Configuration options for the ACME Certificate Manager
3
+ * Custom error classes for better error handling
4
4
  */
5
- interface IAcmeCertManagerOptions {
5
+ export declare class Port80HandlerError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ export declare class CertificateError extends Port80HandlerError {
9
+ readonly domain: string;
10
+ readonly isRenewal: boolean;
11
+ constructor(message: string, domain: string, isRenewal?: boolean);
12
+ }
13
+ export declare class ServerError extends Port80HandlerError {
14
+ readonly code?: string;
15
+ constructor(message: string, code?: string);
16
+ }
17
+ /**
18
+ * Domain forwarding configuration
19
+ */
20
+ export interface IForwardConfig {
21
+ ip: string;
22
+ port: number;
23
+ }
24
+ /**
25
+ * Domain configuration options
26
+ */
27
+ export interface IDomainOptions {
28
+ domainName: string;
29
+ sslRedirect: boolean;
30
+ acmeMaintenance: boolean;
31
+ forward?: IForwardConfig;
32
+ acmeForward?: IForwardConfig;
33
+ }
34
+ /**
35
+ * Configuration options for the Port80Handler
36
+ */
37
+ interface IPort80HandlerOptions {
6
38
  port?: number;
7
39
  contactEmail?: string;
8
40
  useProduction?: boolean;
@@ -13,27 +45,45 @@ interface IAcmeCertManagerOptions {
13
45
  /**
14
46
  * Certificate data that can be emitted via events or set from outside
15
47
  */
16
- interface ICertificateData {
48
+ export interface ICertificateData {
17
49
  domain: string;
18
50
  certificate: string;
19
51
  privateKey: string;
20
52
  expiryDate: Date;
21
53
  }
22
54
  /**
23
- * Events emitted by the ACME Certificate Manager
55
+ * Events emitted by the Port80Handler
24
56
  */
25
- export declare enum CertManagerEvents {
57
+ export declare enum Port80HandlerEvents {
26
58
  CERTIFICATE_ISSUED = "certificate-issued",
27
59
  CERTIFICATE_RENEWED = "certificate-renewed",
28
60
  CERTIFICATE_FAILED = "certificate-failed",
29
61
  CERTIFICATE_EXPIRING = "certificate-expiring",
30
62
  MANAGER_STARTED = "manager-started",
31
- MANAGER_STOPPED = "manager-stopped"
63
+ MANAGER_STOPPED = "manager-stopped",
64
+ REQUEST_FORWARDED = "request-forwarded"
65
+ }
66
+ /**
67
+ * Certificate failure payload type
68
+ */
69
+ export interface ICertificateFailure {
70
+ domain: string;
71
+ error: string;
72
+ isRenewal: boolean;
73
+ }
74
+ /**
75
+ * Certificate expiry payload type
76
+ */
77
+ export interface ICertificateExpiring {
78
+ domain: string;
79
+ expiryDate: Date;
80
+ daysRemaining: number;
32
81
  }
33
82
  /**
34
- * Improved ACME Certificate Manager with event emission and external certificate management
83
+ * Port80Handler with ACME certificate management and request forwarding capabilities
84
+ * Now with glob pattern support for domain matching
35
85
  */
36
- export declare class AcmeCertManager extends plugins.EventEmitter {
86
+ export declare class Port80Handler extends plugins.EventEmitter {
37
87
  private domainCertificates;
38
88
  private server;
39
89
  private acmeClient;
@@ -42,10 +92,10 @@ export declare class AcmeCertManager extends plugins.EventEmitter {
42
92
  private isShuttingDown;
43
93
  private options;
44
94
  /**
45
- * Creates a new ACME Certificate Manager
95
+ * Creates a new Port80Handler
46
96
  * @param options Configuration options
47
97
  */
48
- constructor(options?: IAcmeCertManagerOptions);
98
+ constructor(options?: IPort80HandlerOptions);
49
99
  /**
50
100
  * Starts the HTTP server for ACME challenges
51
101
  */
@@ -55,10 +105,10 @@ export declare class AcmeCertManager extends plugins.EventEmitter {
55
105
  */
56
106
  stop(): Promise<void>;
57
107
  /**
58
- * Adds a domain to be managed for certificates
59
- * @param domain The domain to add
108
+ * Adds a domain with configuration options
109
+ * @param options Domain configuration options
60
110
  */
61
- addDomain(domain: string): void;
111
+ addDomain(options: IDomainOptions): void;
62
112
  /**
63
113
  * Removes a domain from management
64
114
  * @param domain The domain to remove
@@ -77,6 +127,25 @@ export declare class AcmeCertManager extends plugins.EventEmitter {
77
127
  * @param domain The domain to get the certificate for
78
128
  */
79
129
  getCertificate(domain: string): ICertificateData | null;
130
+ /**
131
+ * Check if a domain is a glob pattern
132
+ * @param domain Domain to check
133
+ * @returns True if the domain is a glob pattern
134
+ */
135
+ private isGlobPattern;
136
+ /**
137
+ * Get domain info for a specific domain, using glob pattern matching if needed
138
+ * @param requestDomain The actual domain from the request
139
+ * @returns The domain info or null if not found
140
+ */
141
+ private getDomainInfoForRequest;
142
+ /**
143
+ * Check if a domain matches a glob pattern
144
+ * @param domain The domain to check
145
+ * @param pattern The pattern to match against
146
+ * @returns True if the domain matches the pattern
147
+ */
148
+ private domainMatchesPattern;
80
149
  /**
81
150
  * Lazy initialization of the ACME client
82
151
  * @returns An ACME client instance
@@ -88,6 +157,14 @@ export declare class AcmeCertManager extends plugins.EventEmitter {
88
157
  * @param res The HTTP response
89
158
  */
90
159
  private handleRequest;
160
+ /**
161
+ * Forwards an HTTP request to the specified target
162
+ * @param req The original request
163
+ * @param res The response object
164
+ * @param target The forwarding target (IP and port)
165
+ * @param requestType Type of request for logging
166
+ */
167
+ private forwardRequest;
91
168
  /**
92
169
  * Serves the ACME HTTP-01 challenge response
93
170
  * @param req The HTTP request
@@ -101,6 +178,13 @@ export declare class AcmeCertManager extends plugins.EventEmitter {
101
178
  * @param isRenewal Whether this is a renewal attempt
102
179
  */
103
180
  private obtainCertificate;
181
+ /**
182
+ * Process ACME authorizations by verifying and completing challenges
183
+ * @param client ACME client
184
+ * @param domain Domain name
185
+ * @param authorizations Authorizations to process
186
+ */
187
+ private processAuthorizations;
104
188
  /**
105
189
  * Starts the certificate renewal timer
106
190
  */
@@ -109,6 +193,18 @@ export declare class AcmeCertManager extends plugins.EventEmitter {
109
193
  * Checks for certificates that need renewal
110
194
  */
111
195
  private checkForRenewals;
196
+ /**
197
+ * Extract expiry date from certificate using a more robust approach
198
+ * @param certificate Certificate PEM string
199
+ * @param domain Domain for logging
200
+ * @returns Extracted expiry date or default
201
+ */
202
+ private extractExpiryDateFromCertificate;
203
+ /**
204
+ * Get a default expiry date (90 days from now)
205
+ * @returns Default expiry date
206
+ */
207
+ private getDefaultExpiryDate;
112
208
  /**
113
209
  * Emits a certificate event with the certificate data
114
210
  * @param eventType The event type to emit