rezo 1.0.2 → 1.0.4
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.
- package/README.md +261 -0
- package/dist/adapters/curl.cjs +47 -1
- package/dist/adapters/curl.js +47 -1
- package/dist/adapters/entries/curl.cjs +31 -4
- package/dist/adapters/entries/curl.d.ts +2576 -847
- package/dist/adapters/entries/curl.js +29 -2
- package/dist/adapters/entries/fetch.cjs +31 -2
- package/dist/adapters/entries/fetch.d.ts +1753 -15
- package/dist/adapters/entries/fetch.js +29 -1
- package/dist/adapters/entries/http.cjs +31 -2
- package/dist/adapters/entries/http.d.ts +1774 -14
- package/dist/adapters/entries/http.js +29 -1
- package/dist/adapters/entries/http2.cjs +31 -4
- package/dist/adapters/entries/http2.d.ts +1748 -19
- package/dist/adapters/entries/http2.js +29 -2
- package/dist/adapters/entries/react-native.cjs +31 -2
- package/dist/adapters/entries/react-native.d.ts +1753 -14
- package/dist/adapters/entries/react-native.js +29 -1
- package/dist/adapters/entries/xhr.cjs +31 -2
- package/dist/adapters/entries/xhr.d.ts +1753 -15
- package/dist/adapters/entries/xhr.js +29 -1
- package/dist/adapters/fetch.cjs +24 -20
- package/dist/adapters/fetch.js +24 -20
- package/dist/adapters/http.cjs +69 -19
- package/dist/adapters/http.js +69 -19
- package/dist/adapters/http2.cjs +69 -19
- package/dist/adapters/http2.js +69 -19
- package/dist/adapters/index.cjs +6 -6
- package/dist/cache/index.cjs +13 -13
- package/dist/core/hooks.cjs +16 -0
- package/dist/core/hooks.js +16 -0
- package/dist/core/rezo.cjs +23 -1
- package/dist/core/rezo.js +23 -1
- package/dist/crawler.d.ts +528 -5
- package/dist/entries/crawler.cjs +5 -5
- package/dist/index.cjs +18 -16
- package/dist/index.d.ts +564 -5
- package/dist/index.js +1 -0
- package/dist/platform/browser.cjs +24 -2
- package/dist/platform/browser.d.ts +672 -10
- package/dist/platform/browser.js +24 -2
- package/dist/platform/bun.cjs +24 -2
- package/dist/platform/bun.d.ts +672 -10
- package/dist/platform/bun.js +24 -2
- package/dist/platform/deno.cjs +24 -2
- package/dist/platform/deno.d.ts +672 -10
- package/dist/platform/deno.js +24 -2
- package/dist/platform/node.cjs +24 -2
- package/dist/platform/node.d.ts +672 -10
- package/dist/platform/node.js +24 -2
- package/dist/platform/react-native.cjs +24 -2
- package/dist/platform/react-native.d.ts +672 -10
- package/dist/platform/react-native.js +24 -2
- package/dist/platform/worker.cjs +24 -2
- package/dist/platform/worker.d.ts +672 -10
- package/dist/platform/worker.js +24 -2
- package/dist/plugin/index.cjs +36 -36
- package/dist/proxy/index.cjs +2 -0
- package/dist/proxy/index.js +1 -0
- package/dist/proxy/manager.cjs +446 -0
- package/dist/proxy/manager.js +444 -0
- package/dist/utils/http-config.cjs +14 -3
- package/dist/utils/http-config.js +14 -3
- package/package.json +19 -4
package/dist/crawler.d.ts
CHANGED
|
@@ -1122,6 +1122,292 @@ export interface RezoDownloadResponse extends DownloadResponse {
|
|
|
1122
1122
|
*/
|
|
1123
1123
|
export interface RezoUploadResponse extends UploadResponse {
|
|
1124
1124
|
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Rezo ProxyManager Types
|
|
1127
|
+
* Type definitions for advanced proxy rotation and management
|
|
1128
|
+
*
|
|
1129
|
+
* @module proxy/types
|
|
1130
|
+
* @author Yuniq Solutions Team
|
|
1131
|
+
* @version 1.0.0
|
|
1132
|
+
*/
|
|
1133
|
+
/** Supported proxy protocols */
|
|
1134
|
+
export type ProxyProtocol = "socks4" | "socks5" | "http" | "https";
|
|
1135
|
+
/**
|
|
1136
|
+
* Proxy information structure
|
|
1137
|
+
* Represents a single proxy server with its connection details
|
|
1138
|
+
*/
|
|
1139
|
+
export interface ProxyInfo {
|
|
1140
|
+
/** Unique identifier for the proxy (auto-generated if not provided) */
|
|
1141
|
+
id?: string;
|
|
1142
|
+
/** The proxy protocol to use */
|
|
1143
|
+
protocol: ProxyProtocol;
|
|
1144
|
+
/** Proxy server hostname or IP address */
|
|
1145
|
+
host: string;
|
|
1146
|
+
/** Proxy server port number */
|
|
1147
|
+
port: number;
|
|
1148
|
+
/** Optional authentication credentials for the proxy */
|
|
1149
|
+
auth?: {
|
|
1150
|
+
/** Username for proxy authentication */
|
|
1151
|
+
username: string;
|
|
1152
|
+
/** Password for proxy authentication */
|
|
1153
|
+
password: string;
|
|
1154
|
+
};
|
|
1155
|
+
/** Optional label for identification/logging */
|
|
1156
|
+
label?: string;
|
|
1157
|
+
/** Optional metadata for custom tracking */
|
|
1158
|
+
metadata?: Record<string, unknown>;
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Proxy rotation strategies
|
|
1162
|
+
* - `random`: Select a random proxy from the pool for each request
|
|
1163
|
+
* - `sequential`: Use proxies in order, optionally rotating after N requests
|
|
1164
|
+
* - `per-proxy-limit`: Use each proxy for a maximum number of requests, then permanently remove
|
|
1165
|
+
*/
|
|
1166
|
+
export type RotationStrategy = "random" | "sequential" | "per-proxy-limit";
|
|
1167
|
+
/**
|
|
1168
|
+
* Rotation configuration for different strategies
|
|
1169
|
+
*/
|
|
1170
|
+
export type RotationConfig = {
|
|
1171
|
+
/** Random selection from available proxies */
|
|
1172
|
+
rotation: "random";
|
|
1173
|
+
} | {
|
|
1174
|
+
/** Sequential rotation through proxy list */
|
|
1175
|
+
rotation: "sequential";
|
|
1176
|
+
/** Number of requests before rotating to next proxy (default: 1) */
|
|
1177
|
+
requestsPerProxy?: number;
|
|
1178
|
+
} | {
|
|
1179
|
+
/** Use each proxy for a limited number of total requests, then remove */
|
|
1180
|
+
rotation: "per-proxy-limit";
|
|
1181
|
+
/** Maximum requests per proxy before permanent removal */
|
|
1182
|
+
limit: number;
|
|
1183
|
+
};
|
|
1184
|
+
/**
|
|
1185
|
+
* Cooldown configuration for disabled proxies
|
|
1186
|
+
*/
|
|
1187
|
+
export interface ProxyCooldownConfig {
|
|
1188
|
+
/** Whether to enable automatic re-enabling after cooldown */
|
|
1189
|
+
enabled: boolean;
|
|
1190
|
+
/** Duration in milliseconds before re-enabling a disabled proxy */
|
|
1191
|
+
durationMs: number;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Base proxy manager configuration (without rotation)
|
|
1195
|
+
* Complete configuration for proxy rotation, filtering, and failure handling
|
|
1196
|
+
*/
|
|
1197
|
+
export interface ProxyManagerBaseConfig {
|
|
1198
|
+
/** Array of proxies to manage */
|
|
1199
|
+
proxies: ProxyInfo[];
|
|
1200
|
+
/**
|
|
1201
|
+
* Whitelist patterns for URLs that should use proxy
|
|
1202
|
+
* - String: exact domain match (e.g., 'api.example.com') or subdomain match (e.g., 'example.com' matches '*.example.com')
|
|
1203
|
+
* - RegExp: regex pattern to test against full URL
|
|
1204
|
+
* If not set, all URLs use proxy
|
|
1205
|
+
*/
|
|
1206
|
+
whitelist?: (string | RegExp)[];
|
|
1207
|
+
/**
|
|
1208
|
+
* Blacklist patterns for URLs that should NOT use proxy (go direct)
|
|
1209
|
+
* - String: exact domain match or subdomain match
|
|
1210
|
+
* - RegExp: regex pattern to test against full URL
|
|
1211
|
+
* Blacklist is checked after whitelist
|
|
1212
|
+
*/
|
|
1213
|
+
blacklist?: (string | RegExp)[];
|
|
1214
|
+
/**
|
|
1215
|
+
* Automatically disable proxies after consecutive failures
|
|
1216
|
+
* @default false
|
|
1217
|
+
*/
|
|
1218
|
+
autoDisableDeadProxies?: boolean;
|
|
1219
|
+
/**
|
|
1220
|
+
* Number of consecutive failures before disabling a proxy
|
|
1221
|
+
* Only applies when autoDisableDeadProxies is true
|
|
1222
|
+
* @default 3
|
|
1223
|
+
*/
|
|
1224
|
+
maxFailures?: number;
|
|
1225
|
+
/**
|
|
1226
|
+
* Cooldown configuration for disabled proxies
|
|
1227
|
+
* If not set or enabled: false, proxies are permanently removed when disabled
|
|
1228
|
+
*/
|
|
1229
|
+
cooldown?: ProxyCooldownConfig;
|
|
1230
|
+
/**
|
|
1231
|
+
* Whether to throw error when no proxy is available
|
|
1232
|
+
* - true (default): Throw RezoError when no proxies available
|
|
1233
|
+
* - false: Proceed with direct connection (no proxy)
|
|
1234
|
+
* @default true
|
|
1235
|
+
*/
|
|
1236
|
+
failWithoutProxy?: boolean;
|
|
1237
|
+
/**
|
|
1238
|
+
* Whether to retry the request with next proxy on failure
|
|
1239
|
+
* @default false
|
|
1240
|
+
*/
|
|
1241
|
+
retryWithNextProxy?: boolean;
|
|
1242
|
+
/**
|
|
1243
|
+
* Maximum retry attempts when retryWithNextProxy is enabled
|
|
1244
|
+
* @default 3
|
|
1245
|
+
*/
|
|
1246
|
+
maxProxyRetries?: number;
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Full proxy manager configuration
|
|
1250
|
+
* Combines base config with rotation strategy
|
|
1251
|
+
*/
|
|
1252
|
+
export type ProxyManagerConfig = ProxyManagerBaseConfig & RotationConfig;
|
|
1253
|
+
/**
|
|
1254
|
+
* Internal proxy state tracking
|
|
1255
|
+
* Used internally by ProxyManager to track usage and failures
|
|
1256
|
+
*/
|
|
1257
|
+
export interface ProxyState {
|
|
1258
|
+
/** The proxy info */
|
|
1259
|
+
proxy: ProxyInfo;
|
|
1260
|
+
/** Number of requests made through this proxy */
|
|
1261
|
+
requestCount: number;
|
|
1262
|
+
/** Number of consecutive failures */
|
|
1263
|
+
failureCount: number;
|
|
1264
|
+
/** Total number of successful requests */
|
|
1265
|
+
successCount: number;
|
|
1266
|
+
/** Total number of failed requests */
|
|
1267
|
+
totalFailures: number;
|
|
1268
|
+
/** Whether the proxy is currently active */
|
|
1269
|
+
isActive: boolean;
|
|
1270
|
+
/** Reason for being disabled (if applicable) */
|
|
1271
|
+
disabledReason?: "dead" | "limit-reached" | "manual";
|
|
1272
|
+
/** Timestamp when proxy was disabled */
|
|
1273
|
+
disabledAt?: number;
|
|
1274
|
+
/** Timestamp when proxy will be re-enabled (if cooldown enabled) */
|
|
1275
|
+
reenableAt?: number;
|
|
1276
|
+
/** Last successful request timestamp */
|
|
1277
|
+
lastSuccessAt?: number;
|
|
1278
|
+
/** Last failure timestamp */
|
|
1279
|
+
lastFailureAt?: number;
|
|
1280
|
+
/** Last error message */
|
|
1281
|
+
lastError?: string;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Proxy manager status snapshot
|
|
1285
|
+
* Provides overview of all proxies in the manager
|
|
1286
|
+
*/
|
|
1287
|
+
export interface ProxyManagerStatus {
|
|
1288
|
+
/** Active proxies available for use */
|
|
1289
|
+
active: ProxyInfo[];
|
|
1290
|
+
/** Disabled proxies (dead or limit reached) */
|
|
1291
|
+
disabled: ProxyInfo[];
|
|
1292
|
+
/** Proxies in cooldown waiting to be re-enabled */
|
|
1293
|
+
cooldown: ProxyInfo[];
|
|
1294
|
+
/** Total number of proxies */
|
|
1295
|
+
total: number;
|
|
1296
|
+
/** Current rotation strategy */
|
|
1297
|
+
rotation: RotationStrategy;
|
|
1298
|
+
/** Total requests made through the manager */
|
|
1299
|
+
totalRequests: number;
|
|
1300
|
+
/** Total successful requests */
|
|
1301
|
+
totalSuccesses: number;
|
|
1302
|
+
/** Total failed requests */
|
|
1303
|
+
totalFailures: number;
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Result from proxy selection
|
|
1307
|
+
*/
|
|
1308
|
+
export interface ProxySelectionResult {
|
|
1309
|
+
/** Selected proxy (null if should go direct) */
|
|
1310
|
+
proxy: ProxyInfo | null;
|
|
1311
|
+
/** Reason for selection result */
|
|
1312
|
+
reason: "selected" | "whitelist-no-match" | "blacklist-match" | "no-proxies-available" | "disabled";
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Context for beforeProxySelect hook
|
|
1316
|
+
*/
|
|
1317
|
+
export interface BeforeProxySelectContext {
|
|
1318
|
+
/** Request URL */
|
|
1319
|
+
url: string;
|
|
1320
|
+
/** Available active proxies */
|
|
1321
|
+
proxies: ProxyInfo[];
|
|
1322
|
+
/** Whether this is a retry attempt */
|
|
1323
|
+
isRetry: boolean;
|
|
1324
|
+
/** Retry count (0 for initial request) */
|
|
1325
|
+
retryCount: number;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Context for afterProxySelect hook
|
|
1329
|
+
*/
|
|
1330
|
+
export interface AfterProxySelectContext {
|
|
1331
|
+
/** Request URL */
|
|
1332
|
+
url: string;
|
|
1333
|
+
/** Selected proxy (null if going direct) */
|
|
1334
|
+
proxy: ProxyInfo | null;
|
|
1335
|
+
/** Selection reason */
|
|
1336
|
+
reason: ProxySelectionResult["reason"];
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Context for beforeProxyError hook
|
|
1340
|
+
*/
|
|
1341
|
+
export interface BeforeProxyErrorContext {
|
|
1342
|
+
/** The proxy that failed */
|
|
1343
|
+
proxy: ProxyInfo;
|
|
1344
|
+
/** The error that occurred */
|
|
1345
|
+
error: Error;
|
|
1346
|
+
/** Request URL */
|
|
1347
|
+
url: string;
|
|
1348
|
+
/** Current failure count for this proxy */
|
|
1349
|
+
failureCount: number;
|
|
1350
|
+
/** Whether proxy will be disabled after this error */
|
|
1351
|
+
willBeDisabled: boolean;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Context for afterProxyError hook
|
|
1355
|
+
*/
|
|
1356
|
+
export interface AfterProxyErrorContext {
|
|
1357
|
+
/** The proxy that failed */
|
|
1358
|
+
proxy: ProxyInfo;
|
|
1359
|
+
/** The error that occurred */
|
|
1360
|
+
error: Error;
|
|
1361
|
+
/** Action taken after error */
|
|
1362
|
+
action: "retry-next-proxy" | "disabled" | "continue";
|
|
1363
|
+
/** Next proxy for retry (if action is 'retry-next-proxy') */
|
|
1364
|
+
nextProxy?: ProxyInfo;
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Context for beforeProxyDisable hook
|
|
1368
|
+
* Return false to prevent disabling
|
|
1369
|
+
*/
|
|
1370
|
+
export interface BeforeProxyDisableContext {
|
|
1371
|
+
/** The proxy about to be disabled */
|
|
1372
|
+
proxy: ProxyInfo;
|
|
1373
|
+
/** Reason for disabling */
|
|
1374
|
+
reason: "dead" | "limit-reached" | "manual";
|
|
1375
|
+
/** Current proxy state */
|
|
1376
|
+
state: ProxyState;
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Context for afterProxyDisable hook
|
|
1380
|
+
*/
|
|
1381
|
+
export interface AfterProxyDisableContext {
|
|
1382
|
+
/** The proxy that was disabled */
|
|
1383
|
+
proxy: ProxyInfo;
|
|
1384
|
+
/** Reason for disabling */
|
|
1385
|
+
reason: "dead" | "limit-reached" | "manual";
|
|
1386
|
+
/** Whether cooldown is enabled for re-enabling */
|
|
1387
|
+
hasCooldown: boolean;
|
|
1388
|
+
/** Timestamp when proxy will be re-enabled (if cooldown enabled) */
|
|
1389
|
+
reenableAt?: number;
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Context for afterProxyRotate hook
|
|
1393
|
+
*/
|
|
1394
|
+
export interface AfterProxyRotateContext {
|
|
1395
|
+
/** Previous proxy (null if first selection) */
|
|
1396
|
+
from: ProxyInfo | null;
|
|
1397
|
+
/** New proxy */
|
|
1398
|
+
to: ProxyInfo;
|
|
1399
|
+
/** Reason for rotation */
|
|
1400
|
+
reason: "scheduled" | "failure" | "limit-reached";
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Context for afterProxyEnable hook
|
|
1404
|
+
*/
|
|
1405
|
+
export interface AfterProxyEnableContext {
|
|
1406
|
+
/** The proxy that was enabled */
|
|
1407
|
+
proxy: ProxyInfo;
|
|
1408
|
+
/** Reason for enabling */
|
|
1409
|
+
reason: "cooldown-expired" | "manual";
|
|
1410
|
+
}
|
|
1125
1411
|
/**
|
|
1126
1412
|
* Context provided to beforeRequest hook
|
|
1127
1413
|
* Contains metadata about the current request state
|
|
@@ -1400,6 +1686,46 @@ export type OnTimeoutHook = (event: TimeoutEvent, config: RezoConfig) => void;
|
|
|
1400
1686
|
* Use for cleanup, logging
|
|
1401
1687
|
*/
|
|
1402
1688
|
export type OnAbortHook = (event: AbortEvent, config: RezoConfig) => void;
|
|
1689
|
+
/**
|
|
1690
|
+
* Hook called before a proxy is selected
|
|
1691
|
+
* Can return a specific proxy to override selection
|
|
1692
|
+
*/
|
|
1693
|
+
export type BeforeProxySelectHook = (context: BeforeProxySelectContext) => ProxyInfo | void | Promise<ProxyInfo | void>;
|
|
1694
|
+
/**
|
|
1695
|
+
* Hook called after a proxy is selected
|
|
1696
|
+
* Use for logging, analytics
|
|
1697
|
+
*/
|
|
1698
|
+
export type AfterProxySelectHook = (context: AfterProxySelectContext) => void | Promise<void>;
|
|
1699
|
+
/**
|
|
1700
|
+
* Hook called before a proxy error is processed
|
|
1701
|
+
* Use for error inspection, custom handling
|
|
1702
|
+
*/
|
|
1703
|
+
export type BeforeProxyErrorHook = (context: BeforeProxyErrorContext) => void | Promise<void>;
|
|
1704
|
+
/**
|
|
1705
|
+
* Hook called after a proxy error is processed
|
|
1706
|
+
* Use for error logging, fallback logic
|
|
1707
|
+
*/
|
|
1708
|
+
export type AfterProxyErrorHook = (context: AfterProxyErrorContext) => void | Promise<void>;
|
|
1709
|
+
/**
|
|
1710
|
+
* Hook called before a proxy is disabled
|
|
1711
|
+
* Return false to prevent disabling
|
|
1712
|
+
*/
|
|
1713
|
+
export type BeforeProxyDisableHook = (context: BeforeProxyDisableContext) => boolean | void | Promise<boolean | void>;
|
|
1714
|
+
/**
|
|
1715
|
+
* Hook called after a proxy is disabled
|
|
1716
|
+
* Use for notifications, logging
|
|
1717
|
+
*/
|
|
1718
|
+
export type AfterProxyDisableHook = (context: AfterProxyDisableContext) => void | Promise<void>;
|
|
1719
|
+
/**
|
|
1720
|
+
* Hook called when proxy rotation occurs
|
|
1721
|
+
* Use for monitoring rotation patterns
|
|
1722
|
+
*/
|
|
1723
|
+
export type AfterProxyRotateHook = (context: AfterProxyRotateContext) => void | Promise<void>;
|
|
1724
|
+
/**
|
|
1725
|
+
* Hook called when a proxy is re-enabled
|
|
1726
|
+
* Use for notifications, logging
|
|
1727
|
+
*/
|
|
1728
|
+
export type AfterProxyEnableHook = (context: AfterProxyEnableContext) => void | Promise<void>;
|
|
1403
1729
|
/**
|
|
1404
1730
|
* Collection of all hook types
|
|
1405
1731
|
* All hooks are arrays to allow multiple handlers
|
|
@@ -1416,6 +1742,14 @@ export interface RezoHooks {
|
|
|
1416
1742
|
afterParse: AfterParseHook[];
|
|
1417
1743
|
beforeCookie: BeforeCookieHook[];
|
|
1418
1744
|
afterCookie: AfterCookieHook[];
|
|
1745
|
+
beforeProxySelect: BeforeProxySelectHook[];
|
|
1746
|
+
afterProxySelect: AfterProxySelectHook[];
|
|
1747
|
+
beforeProxyError: BeforeProxyErrorHook[];
|
|
1748
|
+
afterProxyError: AfterProxyErrorHook[];
|
|
1749
|
+
beforeProxyDisable: BeforeProxyDisableHook[];
|
|
1750
|
+
afterProxyDisable: AfterProxyDisableHook[];
|
|
1751
|
+
afterProxyRotate: AfterProxyRotateHook[];
|
|
1752
|
+
afterProxyEnable: AfterProxyEnableHook[];
|
|
1419
1753
|
onSocket: OnSocketHook[];
|
|
1420
1754
|
onDns: OnDnsHook[];
|
|
1421
1755
|
onTls: OnTlsHook[];
|
|
@@ -1812,16 +2146,13 @@ declare class RezoError<T = any> extends Error {
|
|
|
1812
2146
|
toString(): string;
|
|
1813
2147
|
getFullDetails(): string;
|
|
1814
2148
|
}
|
|
1815
|
-
|
|
1816
|
-
* Supported proxy protocols for network requests
|
|
1817
|
-
*/
|
|
1818
|
-
export type ProxyProtocol = "http" | "https" | "socks4" | "socks5";
|
|
2149
|
+
type ProxyProtocol$1 = "http" | "https" | "socks4" | "socks5";
|
|
1819
2150
|
/**
|
|
1820
2151
|
* Configuration options for proxy connections
|
|
1821
2152
|
*/
|
|
1822
2153
|
export type ProxyOptions = {
|
|
1823
2154
|
/** The proxy protocol to use */
|
|
1824
|
-
protocol: ProxyProtocol;
|
|
2155
|
+
protocol: ProxyProtocol$1;
|
|
1825
2156
|
/** Proxy server hostname or IP address */
|
|
1826
2157
|
host: string;
|
|
1827
2158
|
/** Proxy server port number */
|
|
@@ -2319,6 +2650,162 @@ declare class ResponseCache {
|
|
|
2319
2650
|
get isPersistent(): boolean;
|
|
2320
2651
|
getConfig(): ResponseCacheConfig;
|
|
2321
2652
|
}
|
|
2653
|
+
type BeforeProxySelectHook$1 = (context: BeforeProxySelectContext) => ProxyInfo | void | Promise<ProxyInfo | void>;
|
|
2654
|
+
type AfterProxySelectHook$1 = (context: AfterProxySelectContext) => void | Promise<void>;
|
|
2655
|
+
type BeforeProxyErrorHook$1 = (context: BeforeProxyErrorContext) => void | Promise<void>;
|
|
2656
|
+
type AfterProxyErrorHook$1 = (context: AfterProxyErrorContext) => void | Promise<void>;
|
|
2657
|
+
type BeforeProxyDisableHook$1 = (context: BeforeProxyDisableContext) => boolean | void | Promise<boolean | void>;
|
|
2658
|
+
type AfterProxyDisableHook$1 = (context: AfterProxyDisableContext) => void | Promise<void>;
|
|
2659
|
+
type AfterProxyRotateHook$1 = (context: AfterProxyRotateContext) => void | Promise<void>;
|
|
2660
|
+
type AfterProxyEnableHook$1 = (context: AfterProxyEnableContext) => void | Promise<void>;
|
|
2661
|
+
/**
|
|
2662
|
+
* Proxy hooks collection for ProxyManager events
|
|
2663
|
+
*/
|
|
2664
|
+
export interface ProxyHooks {
|
|
2665
|
+
beforeProxySelect: BeforeProxySelectHook$1[];
|
|
2666
|
+
afterProxySelect: AfterProxySelectHook$1[];
|
|
2667
|
+
beforeProxyError: BeforeProxyErrorHook$1[];
|
|
2668
|
+
afterProxyError: AfterProxyErrorHook$1[];
|
|
2669
|
+
beforeProxyDisable: BeforeProxyDisableHook$1[];
|
|
2670
|
+
afterProxyDisable: AfterProxyDisableHook$1[];
|
|
2671
|
+
afterProxyRotate: AfterProxyRotateHook$1[];
|
|
2672
|
+
afterProxyEnable: AfterProxyEnableHook$1[];
|
|
2673
|
+
}
|
|
2674
|
+
declare class ProxyManager {
|
|
2675
|
+
/** Configuration for the proxy manager */
|
|
2676
|
+
readonly config: ProxyManagerConfig;
|
|
2677
|
+
/** Internal proxy states map (proxyId -> state) */
|
|
2678
|
+
private states;
|
|
2679
|
+
/** Current index for sequential rotation */
|
|
2680
|
+
private currentIndex;
|
|
2681
|
+
/** Request counter for current proxy (sequential rotation) */
|
|
2682
|
+
private currentProxyRequests;
|
|
2683
|
+
/** Last selected proxy (for rotation tracking) */
|
|
2684
|
+
private lastSelectedProxy;
|
|
2685
|
+
/** Cooldown timers map (proxyId -> timerId) */
|
|
2686
|
+
private cooldownTimers;
|
|
2687
|
+
/** Total requests through manager */
|
|
2688
|
+
private _totalRequests;
|
|
2689
|
+
/** Total successful requests */
|
|
2690
|
+
private _totalSuccesses;
|
|
2691
|
+
/** Total failed requests */
|
|
2692
|
+
private _totalFailures;
|
|
2693
|
+
/** Proxy hooks */
|
|
2694
|
+
hooks: ProxyHooks;
|
|
2695
|
+
/**
|
|
2696
|
+
* Create a new ProxyManager instance
|
|
2697
|
+
* @param config - Proxy manager configuration
|
|
2698
|
+
*/
|
|
2699
|
+
constructor(config: ProxyManagerConfig);
|
|
2700
|
+
/**
|
|
2701
|
+
* Create initial state for a proxy
|
|
2702
|
+
*/
|
|
2703
|
+
private createInitialState;
|
|
2704
|
+
/**
|
|
2705
|
+
* Check if a URL should use proxy based on whitelist/blacklist
|
|
2706
|
+
* @param url - The request URL to check
|
|
2707
|
+
* @returns true if URL should use proxy, false if should go direct
|
|
2708
|
+
*/
|
|
2709
|
+
shouldProxy(url: string): boolean;
|
|
2710
|
+
/**
|
|
2711
|
+
* Match a URL against a pattern
|
|
2712
|
+
*/
|
|
2713
|
+
private matchPattern;
|
|
2714
|
+
/**
|
|
2715
|
+
* Get active proxies (not disabled)
|
|
2716
|
+
*/
|
|
2717
|
+
getActive(): ProxyInfo[];
|
|
2718
|
+
/**
|
|
2719
|
+
* Get disabled proxies
|
|
2720
|
+
*/
|
|
2721
|
+
getDisabled(): ProxyInfo[];
|
|
2722
|
+
/**
|
|
2723
|
+
* Get proxies in cooldown
|
|
2724
|
+
*/
|
|
2725
|
+
getCooldown(): ProxyInfo[];
|
|
2726
|
+
/**
|
|
2727
|
+
* Process expired cooldowns and re-enable proxies
|
|
2728
|
+
*/
|
|
2729
|
+
private processExpiredCooldowns;
|
|
2730
|
+
/**
|
|
2731
|
+
* Get next proxy based on rotation strategy
|
|
2732
|
+
* @param url - The request URL (for whitelist/blacklist checking)
|
|
2733
|
+
* @returns Selected proxy or null if should go direct
|
|
2734
|
+
*/
|
|
2735
|
+
next(url: string): ProxyInfo | null;
|
|
2736
|
+
/**
|
|
2737
|
+
* Get detailed selection result with reason
|
|
2738
|
+
* @param url - The request URL
|
|
2739
|
+
* @returns Selection result with proxy and reason
|
|
2740
|
+
*/
|
|
2741
|
+
select(url: string): ProxySelectionResult;
|
|
2742
|
+
/**
|
|
2743
|
+
* Select proxy based on rotation strategy
|
|
2744
|
+
*/
|
|
2745
|
+
private selectProxy;
|
|
2746
|
+
/**
|
|
2747
|
+
* Report a successful request through a proxy
|
|
2748
|
+
* @param proxy - The proxy that succeeded
|
|
2749
|
+
*/
|
|
2750
|
+
reportSuccess(proxy: ProxyInfo): void;
|
|
2751
|
+
/**
|
|
2752
|
+
* Report a failed request through a proxy
|
|
2753
|
+
* @param proxy - The proxy that failed
|
|
2754
|
+
* @param error - The error that occurred
|
|
2755
|
+
* @param url - Optional URL for hook context
|
|
2756
|
+
*/
|
|
2757
|
+
reportFailure(proxy: ProxyInfo, error: Error, url?: string): void;
|
|
2758
|
+
/**
|
|
2759
|
+
* Disable a proxy from the pool
|
|
2760
|
+
* @param proxy - The proxy to disable
|
|
2761
|
+
* @param reason - Reason for disabling
|
|
2762
|
+
*/
|
|
2763
|
+
disableProxy(proxy: ProxyInfo, reason?: "dead" | "limit-reached" | "manual"): void;
|
|
2764
|
+
/**
|
|
2765
|
+
* Enable a previously disabled proxy
|
|
2766
|
+
* @param proxy - The proxy to enable
|
|
2767
|
+
* @param reason - Reason for enabling
|
|
2768
|
+
*/
|
|
2769
|
+
enableProxy(proxy: ProxyInfo, reason?: "cooldown-expired" | "manual"): void;
|
|
2770
|
+
/**
|
|
2771
|
+
* Add proxies to the pool
|
|
2772
|
+
* @param proxies - Proxies to add
|
|
2773
|
+
*/
|
|
2774
|
+
add(proxies: ProxyInfo | ProxyInfo[]): void;
|
|
2775
|
+
/**
|
|
2776
|
+
* Remove proxies from the pool
|
|
2777
|
+
* @param proxies - Proxies to remove
|
|
2778
|
+
*/
|
|
2779
|
+
remove(proxies: ProxyInfo | ProxyInfo[]): void;
|
|
2780
|
+
/**
|
|
2781
|
+
* Reset all proxies - re-enable all and reset counters
|
|
2782
|
+
*/
|
|
2783
|
+
reset(): void;
|
|
2784
|
+
/**
|
|
2785
|
+
* Get current status of all proxies
|
|
2786
|
+
*/
|
|
2787
|
+
getStatus(): ProxyManagerStatus;
|
|
2788
|
+
/**
|
|
2789
|
+
* Get state for a specific proxy
|
|
2790
|
+
* @param proxy - The proxy to get state for
|
|
2791
|
+
*/
|
|
2792
|
+
getProxyState(proxy: ProxyInfo): ProxyState | undefined;
|
|
2793
|
+
/**
|
|
2794
|
+
* Check if any proxies are available
|
|
2795
|
+
*/
|
|
2796
|
+
hasAvailableProxies(): boolean;
|
|
2797
|
+
/**
|
|
2798
|
+
* Destroy the manager and cleanup timers
|
|
2799
|
+
*/
|
|
2800
|
+
destroy(): void;
|
|
2801
|
+
private runBeforeProxySelectHooksSync;
|
|
2802
|
+
private runAfterProxySelectHooksSync;
|
|
2803
|
+
private runBeforeProxyErrorHooksSync;
|
|
2804
|
+
private runAfterProxyErrorHooksSync;
|
|
2805
|
+
private runAfterProxyRotateHooks;
|
|
2806
|
+
private runAfterProxyDisableHooks;
|
|
2807
|
+
private runAfterProxyEnableHooks;
|
|
2808
|
+
}
|
|
2322
2809
|
export type queueOptions = Options$1<PriorityQueue, QueueAddOptions>;
|
|
2323
2810
|
export interface CacheConfig {
|
|
2324
2811
|
/** Response cache configuration */
|
|
@@ -2445,6 +2932,35 @@ export interface RezoDefaultOptions {
|
|
|
2445
2932
|
* DNS cache defaults: 1 min TTL, 1000 entries
|
|
2446
2933
|
*/
|
|
2447
2934
|
cache?: CacheOption;
|
|
2935
|
+
/**
|
|
2936
|
+
* Proxy manager for advanced proxy rotation and pool management
|
|
2937
|
+
* - Provide a `ProxyManager` instance for full control
|
|
2938
|
+
* - Or provide `ProxyManagerConfig` to auto-create internally
|
|
2939
|
+
*
|
|
2940
|
+
* Note: ProxyManager overrides `proxy` option when set.
|
|
2941
|
+
* Use `useProxyManager: false` per-request to bypass.
|
|
2942
|
+
*
|
|
2943
|
+
* @example
|
|
2944
|
+
* ```typescript
|
|
2945
|
+
* // With config (auto-creates ProxyManager)
|
|
2946
|
+
* const client = new Rezo({
|
|
2947
|
+
* proxyManager: {
|
|
2948
|
+
* rotation: 'random',
|
|
2949
|
+
* proxies: [
|
|
2950
|
+
* { protocol: 'socks5', host: '127.0.0.1', port: 1080 },
|
|
2951
|
+
* { protocol: 'http', host: 'proxy.example.com', port: 8080 }
|
|
2952
|
+
* ],
|
|
2953
|
+
* whitelist: ['api.example.com'],
|
|
2954
|
+
* autoDisableDeadProxies: true
|
|
2955
|
+
* }
|
|
2956
|
+
* });
|
|
2957
|
+
*
|
|
2958
|
+
* // With ProxyManager instance
|
|
2959
|
+
* const pm = new ProxyManager({ rotation: 'sequential', proxies: [...] });
|
|
2960
|
+
* const client = new Rezo({ proxyManager: pm });
|
|
2961
|
+
* ```
|
|
2962
|
+
*/
|
|
2963
|
+
proxyManager?: ProxyManager | ProxyManagerConfig;
|
|
2448
2964
|
}
|
|
2449
2965
|
export interface httpAdapterOverloads {
|
|
2450
2966
|
request<T = any>(options: RezoRequestOptions): Promise<RezoResponse<T>>;
|
|
@@ -3305,7 +3821,14 @@ declare class Rezo {
|
|
|
3305
3821
|
readonly dnsCache?: DNSCache;
|
|
3306
3822
|
/** The adapter function used for HTTP requests */
|
|
3307
3823
|
private readonly adapter;
|
|
3824
|
+
/** Proxy manager for advanced proxy rotation and pool management */
|
|
3825
|
+
private readonly _proxyManager;
|
|
3308
3826
|
constructor(config?: RezoDefaultOptions, adapter?: AdapterFunction);
|
|
3827
|
+
/**
|
|
3828
|
+
* Get the ProxyManager instance (if configured)
|
|
3829
|
+
* @returns ProxyManager instance or null
|
|
3830
|
+
*/
|
|
3831
|
+
get proxyManager(): ProxyManager | null;
|
|
3309
3832
|
/**
|
|
3310
3833
|
* Clear all caches (response and DNS)
|
|
3311
3834
|
*/
|
package/dist/entries/crawler.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.Crawler =
|
|
3
|
-
const
|
|
4
|
-
exports.CrawlerOptions =
|
|
5
|
-
exports.Domain =
|
|
1
|
+
const _mod_9syr2y = require('../plugin/crawler.cjs');
|
|
2
|
+
exports.Crawler = _mod_9syr2y.Crawler;;
|
|
3
|
+
const _mod_xywryj = require('../plugin/crawler-options.cjs');
|
|
4
|
+
exports.CrawlerOptions = _mod_xywryj.CrawlerOptions;
|
|
5
|
+
exports.Domain = _mod_xywryj.Domain;;
|
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.Rezo =
|
|
3
|
-
exports.createRezoInstance =
|
|
4
|
-
exports.createDefaultInstance =
|
|
5
|
-
const
|
|
6
|
-
exports.RezoError =
|
|
7
|
-
exports.RezoErrorCode =
|
|
8
|
-
const
|
|
9
|
-
exports.RezoHeaders =
|
|
10
|
-
const
|
|
11
|
-
exports.RezoFormData =
|
|
12
|
-
const
|
|
13
|
-
exports.RezoCookieJar =
|
|
14
|
-
const
|
|
15
|
-
exports.createDefaultHooks =
|
|
16
|
-
exports.mergeHooks =
|
|
1
|
+
const _mod_li4oo6 = require('./core/rezo.cjs');
|
|
2
|
+
exports.Rezo = _mod_li4oo6.Rezo;
|
|
3
|
+
exports.createRezoInstance = _mod_li4oo6.createRezoInstance;
|
|
4
|
+
exports.createDefaultInstance = _mod_li4oo6.createDefaultInstance;;
|
|
5
|
+
const _mod_g7vumm = require('./errors/rezo-error.cjs');
|
|
6
|
+
exports.RezoError = _mod_g7vumm.RezoError;
|
|
7
|
+
exports.RezoErrorCode = _mod_g7vumm.RezoErrorCode;;
|
|
8
|
+
const _mod_lcvlqo = require('./utils/headers.cjs');
|
|
9
|
+
exports.RezoHeaders = _mod_lcvlqo.RezoHeaders;;
|
|
10
|
+
const _mod_vdm8pb = require('./utils/form-data.cjs');
|
|
11
|
+
exports.RezoFormData = _mod_vdm8pb.RezoFormData;;
|
|
12
|
+
const _mod_zocq9d = require('./utils/cookies.cjs');
|
|
13
|
+
exports.RezoCookieJar = _mod_zocq9d.RezoCookieJar;;
|
|
14
|
+
const _mod_uxqfdf = require('./core/hooks.cjs');
|
|
15
|
+
exports.createDefaultHooks = _mod_uxqfdf.createDefaultHooks;
|
|
16
|
+
exports.mergeHooks = _mod_uxqfdf.mergeHooks;;
|
|
17
|
+
const _mod_ztg1xc = require('./proxy/manager.cjs');
|
|
18
|
+
exports.ProxyManager = _mod_ztg1xc.ProxyManager;;
|
|
17
19
|
const { RezoError } = require('./errors/rezo-error.cjs');
|
|
18
20
|
const isRezoError = exports.isRezoError = RezoError.isRezoError;
|
|
19
21
|
const Cancel = exports.Cancel = RezoError;
|