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/index.d.ts
CHANGED
|
@@ -899,6 +899,292 @@ export interface RezoDownloadResponse extends DownloadResponse {
|
|
|
899
899
|
*/
|
|
900
900
|
export interface RezoUploadResponse extends UploadResponse {
|
|
901
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Rezo ProxyManager Types
|
|
904
|
+
* Type definitions for advanced proxy rotation and management
|
|
905
|
+
*
|
|
906
|
+
* @module proxy/types
|
|
907
|
+
* @author Yuniq Solutions Team
|
|
908
|
+
* @version 1.0.0
|
|
909
|
+
*/
|
|
910
|
+
/** Supported proxy protocols */
|
|
911
|
+
export type ProxyProtocol = "socks4" | "socks5" | "http" | "https";
|
|
912
|
+
/**
|
|
913
|
+
* Proxy information structure
|
|
914
|
+
* Represents a single proxy server with its connection details
|
|
915
|
+
*/
|
|
916
|
+
export interface ProxyInfo {
|
|
917
|
+
/** Unique identifier for the proxy (auto-generated if not provided) */
|
|
918
|
+
id?: string;
|
|
919
|
+
/** The proxy protocol to use */
|
|
920
|
+
protocol: ProxyProtocol;
|
|
921
|
+
/** Proxy server hostname or IP address */
|
|
922
|
+
host: string;
|
|
923
|
+
/** Proxy server port number */
|
|
924
|
+
port: number;
|
|
925
|
+
/** Optional authentication credentials for the proxy */
|
|
926
|
+
auth?: {
|
|
927
|
+
/** Username for proxy authentication */
|
|
928
|
+
username: string;
|
|
929
|
+
/** Password for proxy authentication */
|
|
930
|
+
password: string;
|
|
931
|
+
};
|
|
932
|
+
/** Optional label for identification/logging */
|
|
933
|
+
label?: string;
|
|
934
|
+
/** Optional metadata for custom tracking */
|
|
935
|
+
metadata?: Record<string, unknown>;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Proxy rotation strategies
|
|
939
|
+
* - `random`: Select a random proxy from the pool for each request
|
|
940
|
+
* - `sequential`: Use proxies in order, optionally rotating after N requests
|
|
941
|
+
* - `per-proxy-limit`: Use each proxy for a maximum number of requests, then permanently remove
|
|
942
|
+
*/
|
|
943
|
+
export type RotationStrategy = "random" | "sequential" | "per-proxy-limit";
|
|
944
|
+
/**
|
|
945
|
+
* Rotation configuration for different strategies
|
|
946
|
+
*/
|
|
947
|
+
export type RotationConfig = {
|
|
948
|
+
/** Random selection from available proxies */
|
|
949
|
+
rotation: "random";
|
|
950
|
+
} | {
|
|
951
|
+
/** Sequential rotation through proxy list */
|
|
952
|
+
rotation: "sequential";
|
|
953
|
+
/** Number of requests before rotating to next proxy (default: 1) */
|
|
954
|
+
requestsPerProxy?: number;
|
|
955
|
+
} | {
|
|
956
|
+
/** Use each proxy for a limited number of total requests, then remove */
|
|
957
|
+
rotation: "per-proxy-limit";
|
|
958
|
+
/** Maximum requests per proxy before permanent removal */
|
|
959
|
+
limit: number;
|
|
960
|
+
};
|
|
961
|
+
/**
|
|
962
|
+
* Cooldown configuration for disabled proxies
|
|
963
|
+
*/
|
|
964
|
+
export interface ProxyCooldownConfig {
|
|
965
|
+
/** Whether to enable automatic re-enabling after cooldown */
|
|
966
|
+
enabled: boolean;
|
|
967
|
+
/** Duration in milliseconds before re-enabling a disabled proxy */
|
|
968
|
+
durationMs: number;
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Base proxy manager configuration (without rotation)
|
|
972
|
+
* Complete configuration for proxy rotation, filtering, and failure handling
|
|
973
|
+
*/
|
|
974
|
+
export interface ProxyManagerBaseConfig {
|
|
975
|
+
/** Array of proxies to manage */
|
|
976
|
+
proxies: ProxyInfo[];
|
|
977
|
+
/**
|
|
978
|
+
* Whitelist patterns for URLs that should use proxy
|
|
979
|
+
* - String: exact domain match (e.g., 'api.example.com') or subdomain match (e.g., 'example.com' matches '*.example.com')
|
|
980
|
+
* - RegExp: regex pattern to test against full URL
|
|
981
|
+
* If not set, all URLs use proxy
|
|
982
|
+
*/
|
|
983
|
+
whitelist?: (string | RegExp)[];
|
|
984
|
+
/**
|
|
985
|
+
* Blacklist patterns for URLs that should NOT use proxy (go direct)
|
|
986
|
+
* - String: exact domain match or subdomain match
|
|
987
|
+
* - RegExp: regex pattern to test against full URL
|
|
988
|
+
* Blacklist is checked after whitelist
|
|
989
|
+
*/
|
|
990
|
+
blacklist?: (string | RegExp)[];
|
|
991
|
+
/**
|
|
992
|
+
* Automatically disable proxies after consecutive failures
|
|
993
|
+
* @default false
|
|
994
|
+
*/
|
|
995
|
+
autoDisableDeadProxies?: boolean;
|
|
996
|
+
/**
|
|
997
|
+
* Number of consecutive failures before disabling a proxy
|
|
998
|
+
* Only applies when autoDisableDeadProxies is true
|
|
999
|
+
* @default 3
|
|
1000
|
+
*/
|
|
1001
|
+
maxFailures?: number;
|
|
1002
|
+
/**
|
|
1003
|
+
* Cooldown configuration for disabled proxies
|
|
1004
|
+
* If not set or enabled: false, proxies are permanently removed when disabled
|
|
1005
|
+
*/
|
|
1006
|
+
cooldown?: ProxyCooldownConfig;
|
|
1007
|
+
/**
|
|
1008
|
+
* Whether to throw error when no proxy is available
|
|
1009
|
+
* - true (default): Throw RezoError when no proxies available
|
|
1010
|
+
* - false: Proceed with direct connection (no proxy)
|
|
1011
|
+
* @default true
|
|
1012
|
+
*/
|
|
1013
|
+
failWithoutProxy?: boolean;
|
|
1014
|
+
/**
|
|
1015
|
+
* Whether to retry the request with next proxy on failure
|
|
1016
|
+
* @default false
|
|
1017
|
+
*/
|
|
1018
|
+
retryWithNextProxy?: boolean;
|
|
1019
|
+
/**
|
|
1020
|
+
* Maximum retry attempts when retryWithNextProxy is enabled
|
|
1021
|
+
* @default 3
|
|
1022
|
+
*/
|
|
1023
|
+
maxProxyRetries?: number;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Full proxy manager configuration
|
|
1027
|
+
* Combines base config with rotation strategy
|
|
1028
|
+
*/
|
|
1029
|
+
export type ProxyManagerConfig = ProxyManagerBaseConfig & RotationConfig;
|
|
1030
|
+
/**
|
|
1031
|
+
* Internal proxy state tracking
|
|
1032
|
+
* Used internally by ProxyManager to track usage and failures
|
|
1033
|
+
*/
|
|
1034
|
+
export interface ProxyState {
|
|
1035
|
+
/** The proxy info */
|
|
1036
|
+
proxy: ProxyInfo;
|
|
1037
|
+
/** Number of requests made through this proxy */
|
|
1038
|
+
requestCount: number;
|
|
1039
|
+
/** Number of consecutive failures */
|
|
1040
|
+
failureCount: number;
|
|
1041
|
+
/** Total number of successful requests */
|
|
1042
|
+
successCount: number;
|
|
1043
|
+
/** Total number of failed requests */
|
|
1044
|
+
totalFailures: number;
|
|
1045
|
+
/** Whether the proxy is currently active */
|
|
1046
|
+
isActive: boolean;
|
|
1047
|
+
/** Reason for being disabled (if applicable) */
|
|
1048
|
+
disabledReason?: "dead" | "limit-reached" | "manual";
|
|
1049
|
+
/** Timestamp when proxy was disabled */
|
|
1050
|
+
disabledAt?: number;
|
|
1051
|
+
/** Timestamp when proxy will be re-enabled (if cooldown enabled) */
|
|
1052
|
+
reenableAt?: number;
|
|
1053
|
+
/** Last successful request timestamp */
|
|
1054
|
+
lastSuccessAt?: number;
|
|
1055
|
+
/** Last failure timestamp */
|
|
1056
|
+
lastFailureAt?: number;
|
|
1057
|
+
/** Last error message */
|
|
1058
|
+
lastError?: string;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Proxy manager status snapshot
|
|
1062
|
+
* Provides overview of all proxies in the manager
|
|
1063
|
+
*/
|
|
1064
|
+
export interface ProxyManagerStatus {
|
|
1065
|
+
/** Active proxies available for use */
|
|
1066
|
+
active: ProxyInfo[];
|
|
1067
|
+
/** Disabled proxies (dead or limit reached) */
|
|
1068
|
+
disabled: ProxyInfo[];
|
|
1069
|
+
/** Proxies in cooldown waiting to be re-enabled */
|
|
1070
|
+
cooldown: ProxyInfo[];
|
|
1071
|
+
/** Total number of proxies */
|
|
1072
|
+
total: number;
|
|
1073
|
+
/** Current rotation strategy */
|
|
1074
|
+
rotation: RotationStrategy;
|
|
1075
|
+
/** Total requests made through the manager */
|
|
1076
|
+
totalRequests: number;
|
|
1077
|
+
/** Total successful requests */
|
|
1078
|
+
totalSuccesses: number;
|
|
1079
|
+
/** Total failed requests */
|
|
1080
|
+
totalFailures: number;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Result from proxy selection
|
|
1084
|
+
*/
|
|
1085
|
+
export interface ProxySelectionResult {
|
|
1086
|
+
/** Selected proxy (null if should go direct) */
|
|
1087
|
+
proxy: ProxyInfo | null;
|
|
1088
|
+
/** Reason for selection result */
|
|
1089
|
+
reason: "selected" | "whitelist-no-match" | "blacklist-match" | "no-proxies-available" | "disabled";
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Context for beforeProxySelect hook
|
|
1093
|
+
*/
|
|
1094
|
+
export interface BeforeProxySelectContext {
|
|
1095
|
+
/** Request URL */
|
|
1096
|
+
url: string;
|
|
1097
|
+
/** Available active proxies */
|
|
1098
|
+
proxies: ProxyInfo[];
|
|
1099
|
+
/** Whether this is a retry attempt */
|
|
1100
|
+
isRetry: boolean;
|
|
1101
|
+
/** Retry count (0 for initial request) */
|
|
1102
|
+
retryCount: number;
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Context for afterProxySelect hook
|
|
1106
|
+
*/
|
|
1107
|
+
export interface AfterProxySelectContext {
|
|
1108
|
+
/** Request URL */
|
|
1109
|
+
url: string;
|
|
1110
|
+
/** Selected proxy (null if going direct) */
|
|
1111
|
+
proxy: ProxyInfo | null;
|
|
1112
|
+
/** Selection reason */
|
|
1113
|
+
reason: ProxySelectionResult["reason"];
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Context for beforeProxyError hook
|
|
1117
|
+
*/
|
|
1118
|
+
export interface BeforeProxyErrorContext {
|
|
1119
|
+
/** The proxy that failed */
|
|
1120
|
+
proxy: ProxyInfo;
|
|
1121
|
+
/** The error that occurred */
|
|
1122
|
+
error: Error;
|
|
1123
|
+
/** Request URL */
|
|
1124
|
+
url: string;
|
|
1125
|
+
/** Current failure count for this proxy */
|
|
1126
|
+
failureCount: number;
|
|
1127
|
+
/** Whether proxy will be disabled after this error */
|
|
1128
|
+
willBeDisabled: boolean;
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Context for afterProxyError hook
|
|
1132
|
+
*/
|
|
1133
|
+
export interface AfterProxyErrorContext {
|
|
1134
|
+
/** The proxy that failed */
|
|
1135
|
+
proxy: ProxyInfo;
|
|
1136
|
+
/** The error that occurred */
|
|
1137
|
+
error: Error;
|
|
1138
|
+
/** Action taken after error */
|
|
1139
|
+
action: "retry-next-proxy" | "disabled" | "continue";
|
|
1140
|
+
/** Next proxy for retry (if action is 'retry-next-proxy') */
|
|
1141
|
+
nextProxy?: ProxyInfo;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Context for beforeProxyDisable hook
|
|
1145
|
+
* Return false to prevent disabling
|
|
1146
|
+
*/
|
|
1147
|
+
export interface BeforeProxyDisableContext {
|
|
1148
|
+
/** The proxy about to be disabled */
|
|
1149
|
+
proxy: ProxyInfo;
|
|
1150
|
+
/** Reason for disabling */
|
|
1151
|
+
reason: "dead" | "limit-reached" | "manual";
|
|
1152
|
+
/** Current proxy state */
|
|
1153
|
+
state: ProxyState;
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Context for afterProxyDisable hook
|
|
1157
|
+
*/
|
|
1158
|
+
export interface AfterProxyDisableContext {
|
|
1159
|
+
/** The proxy that was disabled */
|
|
1160
|
+
proxy: ProxyInfo;
|
|
1161
|
+
/** Reason for disabling */
|
|
1162
|
+
reason: "dead" | "limit-reached" | "manual";
|
|
1163
|
+
/** Whether cooldown is enabled for re-enabling */
|
|
1164
|
+
hasCooldown: boolean;
|
|
1165
|
+
/** Timestamp when proxy will be re-enabled (if cooldown enabled) */
|
|
1166
|
+
reenableAt?: number;
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Context for afterProxyRotate hook
|
|
1170
|
+
*/
|
|
1171
|
+
export interface AfterProxyRotateContext {
|
|
1172
|
+
/** Previous proxy (null if first selection) */
|
|
1173
|
+
from: ProxyInfo | null;
|
|
1174
|
+
/** New proxy */
|
|
1175
|
+
to: ProxyInfo;
|
|
1176
|
+
/** Reason for rotation */
|
|
1177
|
+
reason: "scheduled" | "failure" | "limit-reached";
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Context for afterProxyEnable hook
|
|
1181
|
+
*/
|
|
1182
|
+
export interface AfterProxyEnableContext {
|
|
1183
|
+
/** The proxy that was enabled */
|
|
1184
|
+
proxy: ProxyInfo;
|
|
1185
|
+
/** Reason for enabling */
|
|
1186
|
+
reason: "cooldown-expired" | "manual";
|
|
1187
|
+
}
|
|
902
1188
|
/**
|
|
903
1189
|
* Context provided to beforeRequest hook
|
|
904
1190
|
* Contains metadata about the current request state
|
|
@@ -1177,6 +1463,46 @@ export type OnTimeoutHook = (event: TimeoutEvent, config: RezoConfig) => void;
|
|
|
1177
1463
|
* Use for cleanup, logging
|
|
1178
1464
|
*/
|
|
1179
1465
|
export type OnAbortHook = (event: AbortEvent, config: RezoConfig) => void;
|
|
1466
|
+
/**
|
|
1467
|
+
* Hook called before a proxy is selected
|
|
1468
|
+
* Can return a specific proxy to override selection
|
|
1469
|
+
*/
|
|
1470
|
+
export type BeforeProxySelectHook = (context: BeforeProxySelectContext) => ProxyInfo | void | Promise<ProxyInfo | void>;
|
|
1471
|
+
/**
|
|
1472
|
+
* Hook called after a proxy is selected
|
|
1473
|
+
* Use for logging, analytics
|
|
1474
|
+
*/
|
|
1475
|
+
export type AfterProxySelectHook = (context: AfterProxySelectContext) => void | Promise<void>;
|
|
1476
|
+
/**
|
|
1477
|
+
* Hook called before a proxy error is processed
|
|
1478
|
+
* Use for error inspection, custom handling
|
|
1479
|
+
*/
|
|
1480
|
+
export type BeforeProxyErrorHook = (context: BeforeProxyErrorContext) => void | Promise<void>;
|
|
1481
|
+
/**
|
|
1482
|
+
* Hook called after a proxy error is processed
|
|
1483
|
+
* Use for error logging, fallback logic
|
|
1484
|
+
*/
|
|
1485
|
+
export type AfterProxyErrorHook = (context: AfterProxyErrorContext) => void | Promise<void>;
|
|
1486
|
+
/**
|
|
1487
|
+
* Hook called before a proxy is disabled
|
|
1488
|
+
* Return false to prevent disabling
|
|
1489
|
+
*/
|
|
1490
|
+
export type BeforeProxyDisableHook = (context: BeforeProxyDisableContext) => boolean | void | Promise<boolean | void>;
|
|
1491
|
+
/**
|
|
1492
|
+
* Hook called after a proxy is disabled
|
|
1493
|
+
* Use for notifications, logging
|
|
1494
|
+
*/
|
|
1495
|
+
export type AfterProxyDisableHook = (context: AfterProxyDisableContext) => void | Promise<void>;
|
|
1496
|
+
/**
|
|
1497
|
+
* Hook called when proxy rotation occurs
|
|
1498
|
+
* Use for monitoring rotation patterns
|
|
1499
|
+
*/
|
|
1500
|
+
export type AfterProxyRotateHook = (context: AfterProxyRotateContext) => void | Promise<void>;
|
|
1501
|
+
/**
|
|
1502
|
+
* Hook called when a proxy is re-enabled
|
|
1503
|
+
* Use for notifications, logging
|
|
1504
|
+
*/
|
|
1505
|
+
export type AfterProxyEnableHook = (context: AfterProxyEnableContext) => void | Promise<void>;
|
|
1180
1506
|
/**
|
|
1181
1507
|
* Collection of all hook types
|
|
1182
1508
|
* All hooks are arrays to allow multiple handlers
|
|
@@ -1193,6 +1519,14 @@ export interface RezoHooks {
|
|
|
1193
1519
|
afterParse: AfterParseHook[];
|
|
1194
1520
|
beforeCookie: BeforeCookieHook[];
|
|
1195
1521
|
afterCookie: AfterCookieHook[];
|
|
1522
|
+
beforeProxySelect: BeforeProxySelectHook[];
|
|
1523
|
+
afterProxySelect: AfterProxySelectHook[];
|
|
1524
|
+
beforeProxyError: BeforeProxyErrorHook[];
|
|
1525
|
+
afterProxyError: AfterProxyErrorHook[];
|
|
1526
|
+
beforeProxyDisable: BeforeProxyDisableHook[];
|
|
1527
|
+
afterProxyDisable: AfterProxyDisableHook[];
|
|
1528
|
+
afterProxyRotate: AfterProxyRotateHook[];
|
|
1529
|
+
afterProxyEnable: AfterProxyEnableHook[];
|
|
1196
1530
|
onSocket: OnSocketHook[];
|
|
1197
1531
|
onDns: OnDnsHook[];
|
|
1198
1532
|
onTls: OnTlsHook[];
|
|
@@ -1649,16 +1983,13 @@ export declare class RezoError<T = any> extends Error {
|
|
|
1649
1983
|
toString(): string;
|
|
1650
1984
|
getFullDetails(): string;
|
|
1651
1985
|
}
|
|
1652
|
-
|
|
1653
|
-
* Supported proxy protocols for network requests
|
|
1654
|
-
*/
|
|
1655
|
-
export type ProxyProtocol = "http" | "https" | "socks4" | "socks5";
|
|
1986
|
+
type ProxyProtocol$1 = "http" | "https" | "socks4" | "socks5";
|
|
1656
1987
|
/**
|
|
1657
1988
|
* Configuration options for proxy connections
|
|
1658
1989
|
*/
|
|
1659
1990
|
export type ProxyOptions = {
|
|
1660
1991
|
/** The proxy protocol to use */
|
|
1661
|
-
protocol: ProxyProtocol;
|
|
1992
|
+
protocol: ProxyProtocol$1;
|
|
1662
1993
|
/** Proxy server hostname or IP address */
|
|
1663
1994
|
host: string;
|
|
1664
1995
|
/** Proxy server port number */
|
|
@@ -2201,6 +2532,181 @@ declare class ResponseCache {
|
|
|
2201
2532
|
get isPersistent(): boolean;
|
|
2202
2533
|
getConfig(): ResponseCacheConfig;
|
|
2203
2534
|
}
|
|
2535
|
+
type BeforeProxySelectHook$1 = (context: BeforeProxySelectContext) => ProxyInfo | void | Promise<ProxyInfo | void>;
|
|
2536
|
+
type AfterProxySelectHook$1 = (context: AfterProxySelectContext) => void | Promise<void>;
|
|
2537
|
+
type BeforeProxyErrorHook$1 = (context: BeforeProxyErrorContext) => void | Promise<void>;
|
|
2538
|
+
type AfterProxyErrorHook$1 = (context: AfterProxyErrorContext) => void | Promise<void>;
|
|
2539
|
+
type BeforeProxyDisableHook$1 = (context: BeforeProxyDisableContext) => boolean | void | Promise<boolean | void>;
|
|
2540
|
+
type AfterProxyDisableHook$1 = (context: AfterProxyDisableContext) => void | Promise<void>;
|
|
2541
|
+
type AfterProxyRotateHook$1 = (context: AfterProxyRotateContext) => void | Promise<void>;
|
|
2542
|
+
type AfterProxyEnableHook$1 = (context: AfterProxyEnableContext) => void | Promise<void>;
|
|
2543
|
+
/**
|
|
2544
|
+
* Proxy hooks collection for ProxyManager events
|
|
2545
|
+
*/
|
|
2546
|
+
export interface ProxyHooks {
|
|
2547
|
+
beforeProxySelect: BeforeProxySelectHook$1[];
|
|
2548
|
+
afterProxySelect: AfterProxySelectHook$1[];
|
|
2549
|
+
beforeProxyError: BeforeProxyErrorHook$1[];
|
|
2550
|
+
afterProxyError: AfterProxyErrorHook$1[];
|
|
2551
|
+
beforeProxyDisable: BeforeProxyDisableHook$1[];
|
|
2552
|
+
afterProxyDisable: AfterProxyDisableHook$1[];
|
|
2553
|
+
afterProxyRotate: AfterProxyRotateHook$1[];
|
|
2554
|
+
afterProxyEnable: AfterProxyEnableHook$1[];
|
|
2555
|
+
}
|
|
2556
|
+
/**
|
|
2557
|
+
* ProxyManager - Advanced proxy rotation and pool management
|
|
2558
|
+
*
|
|
2559
|
+
* @example
|
|
2560
|
+
* ```typescript
|
|
2561
|
+
* const manager = new ProxyManager({
|
|
2562
|
+
* rotation: 'random',
|
|
2563
|
+
* proxies: [
|
|
2564
|
+
* { protocol: 'socks5', host: '127.0.0.1', port: 1080 },
|
|
2565
|
+
* { protocol: 'http', host: 'proxy.example.com', port: 8080 }
|
|
2566
|
+
* ],
|
|
2567
|
+
* whitelist: ['api.example.com', /^https:\/\/secure\./],
|
|
2568
|
+
* autoDisableDeadProxies: true,
|
|
2569
|
+
* maxFailures: 3
|
|
2570
|
+
* });
|
|
2571
|
+
*
|
|
2572
|
+
* const proxy = manager.next('https://api.example.com/data');
|
|
2573
|
+
* ```
|
|
2574
|
+
*/
|
|
2575
|
+
export declare class ProxyManager {
|
|
2576
|
+
/** Configuration for the proxy manager */
|
|
2577
|
+
readonly config: ProxyManagerConfig;
|
|
2578
|
+
/** Internal proxy states map (proxyId -> state) */
|
|
2579
|
+
private states;
|
|
2580
|
+
/** Current index for sequential rotation */
|
|
2581
|
+
private currentIndex;
|
|
2582
|
+
/** Request counter for current proxy (sequential rotation) */
|
|
2583
|
+
private currentProxyRequests;
|
|
2584
|
+
/** Last selected proxy (for rotation tracking) */
|
|
2585
|
+
private lastSelectedProxy;
|
|
2586
|
+
/** Cooldown timers map (proxyId -> timerId) */
|
|
2587
|
+
private cooldownTimers;
|
|
2588
|
+
/** Total requests through manager */
|
|
2589
|
+
private _totalRequests;
|
|
2590
|
+
/** Total successful requests */
|
|
2591
|
+
private _totalSuccesses;
|
|
2592
|
+
/** Total failed requests */
|
|
2593
|
+
private _totalFailures;
|
|
2594
|
+
/** Proxy hooks */
|
|
2595
|
+
hooks: ProxyHooks;
|
|
2596
|
+
/**
|
|
2597
|
+
* Create a new ProxyManager instance
|
|
2598
|
+
* @param config - Proxy manager configuration
|
|
2599
|
+
*/
|
|
2600
|
+
constructor(config: ProxyManagerConfig);
|
|
2601
|
+
/**
|
|
2602
|
+
* Create initial state for a proxy
|
|
2603
|
+
*/
|
|
2604
|
+
private createInitialState;
|
|
2605
|
+
/**
|
|
2606
|
+
* Check if a URL should use proxy based on whitelist/blacklist
|
|
2607
|
+
* @param url - The request URL to check
|
|
2608
|
+
* @returns true if URL should use proxy, false if should go direct
|
|
2609
|
+
*/
|
|
2610
|
+
shouldProxy(url: string): boolean;
|
|
2611
|
+
/**
|
|
2612
|
+
* Match a URL against a pattern
|
|
2613
|
+
*/
|
|
2614
|
+
private matchPattern;
|
|
2615
|
+
/**
|
|
2616
|
+
* Get active proxies (not disabled)
|
|
2617
|
+
*/
|
|
2618
|
+
getActive(): ProxyInfo[];
|
|
2619
|
+
/**
|
|
2620
|
+
* Get disabled proxies
|
|
2621
|
+
*/
|
|
2622
|
+
getDisabled(): ProxyInfo[];
|
|
2623
|
+
/**
|
|
2624
|
+
* Get proxies in cooldown
|
|
2625
|
+
*/
|
|
2626
|
+
getCooldown(): ProxyInfo[];
|
|
2627
|
+
/**
|
|
2628
|
+
* Process expired cooldowns and re-enable proxies
|
|
2629
|
+
*/
|
|
2630
|
+
private processExpiredCooldowns;
|
|
2631
|
+
/**
|
|
2632
|
+
* Get next proxy based on rotation strategy
|
|
2633
|
+
* @param url - The request URL (for whitelist/blacklist checking)
|
|
2634
|
+
* @returns Selected proxy or null if should go direct
|
|
2635
|
+
*/
|
|
2636
|
+
next(url: string): ProxyInfo | null;
|
|
2637
|
+
/**
|
|
2638
|
+
* Get detailed selection result with reason
|
|
2639
|
+
* @param url - The request URL
|
|
2640
|
+
* @returns Selection result with proxy and reason
|
|
2641
|
+
*/
|
|
2642
|
+
select(url: string): ProxySelectionResult;
|
|
2643
|
+
/**
|
|
2644
|
+
* Select proxy based on rotation strategy
|
|
2645
|
+
*/
|
|
2646
|
+
private selectProxy;
|
|
2647
|
+
/**
|
|
2648
|
+
* Report a successful request through a proxy
|
|
2649
|
+
* @param proxy - The proxy that succeeded
|
|
2650
|
+
*/
|
|
2651
|
+
reportSuccess(proxy: ProxyInfo): void;
|
|
2652
|
+
/**
|
|
2653
|
+
* Report a failed request through a proxy
|
|
2654
|
+
* @param proxy - The proxy that failed
|
|
2655
|
+
* @param error - The error that occurred
|
|
2656
|
+
* @param url - Optional URL for hook context
|
|
2657
|
+
*/
|
|
2658
|
+
reportFailure(proxy: ProxyInfo, error: Error, url?: string): void;
|
|
2659
|
+
/**
|
|
2660
|
+
* Disable a proxy from the pool
|
|
2661
|
+
* @param proxy - The proxy to disable
|
|
2662
|
+
* @param reason - Reason for disabling
|
|
2663
|
+
*/
|
|
2664
|
+
disableProxy(proxy: ProxyInfo, reason?: "dead" | "limit-reached" | "manual"): void;
|
|
2665
|
+
/**
|
|
2666
|
+
* Enable a previously disabled proxy
|
|
2667
|
+
* @param proxy - The proxy to enable
|
|
2668
|
+
* @param reason - Reason for enabling
|
|
2669
|
+
*/
|
|
2670
|
+
enableProxy(proxy: ProxyInfo, reason?: "cooldown-expired" | "manual"): void;
|
|
2671
|
+
/**
|
|
2672
|
+
* Add proxies to the pool
|
|
2673
|
+
* @param proxies - Proxies to add
|
|
2674
|
+
*/
|
|
2675
|
+
add(proxies: ProxyInfo | ProxyInfo[]): void;
|
|
2676
|
+
/**
|
|
2677
|
+
* Remove proxies from the pool
|
|
2678
|
+
* @param proxies - Proxies to remove
|
|
2679
|
+
*/
|
|
2680
|
+
remove(proxies: ProxyInfo | ProxyInfo[]): void;
|
|
2681
|
+
/**
|
|
2682
|
+
* Reset all proxies - re-enable all and reset counters
|
|
2683
|
+
*/
|
|
2684
|
+
reset(): void;
|
|
2685
|
+
/**
|
|
2686
|
+
* Get current status of all proxies
|
|
2687
|
+
*/
|
|
2688
|
+
getStatus(): ProxyManagerStatus;
|
|
2689
|
+
/**
|
|
2690
|
+
* Get state for a specific proxy
|
|
2691
|
+
* @param proxy - The proxy to get state for
|
|
2692
|
+
*/
|
|
2693
|
+
getProxyState(proxy: ProxyInfo): ProxyState | undefined;
|
|
2694
|
+
/**
|
|
2695
|
+
* Check if any proxies are available
|
|
2696
|
+
*/
|
|
2697
|
+
hasAvailableProxies(): boolean;
|
|
2698
|
+
/**
|
|
2699
|
+
* Destroy the manager and cleanup timers
|
|
2700
|
+
*/
|
|
2701
|
+
destroy(): void;
|
|
2702
|
+
private runBeforeProxySelectHooksSync;
|
|
2703
|
+
private runAfterProxySelectHooksSync;
|
|
2704
|
+
private runBeforeProxyErrorHooksSync;
|
|
2705
|
+
private runAfterProxyErrorHooksSync;
|
|
2706
|
+
private runAfterProxyRotateHooks;
|
|
2707
|
+
private runAfterProxyDisableHooks;
|
|
2708
|
+
private runAfterProxyEnableHooks;
|
|
2709
|
+
}
|
|
2204
2710
|
export type queueOptions = Options$1<PriorityQueue, QueueAddOptions>;
|
|
2205
2711
|
export interface CacheConfig {
|
|
2206
2712
|
/** Response cache configuration */
|
|
@@ -2327,6 +2833,35 @@ export interface RezoDefaultOptions {
|
|
|
2327
2833
|
* DNS cache defaults: 1 min TTL, 1000 entries
|
|
2328
2834
|
*/
|
|
2329
2835
|
cache?: CacheOption;
|
|
2836
|
+
/**
|
|
2837
|
+
* Proxy manager for advanced proxy rotation and pool management
|
|
2838
|
+
* - Provide a `ProxyManager` instance for full control
|
|
2839
|
+
* - Or provide `ProxyManagerConfig` to auto-create internally
|
|
2840
|
+
*
|
|
2841
|
+
* Note: ProxyManager overrides `proxy` option when set.
|
|
2842
|
+
* Use `useProxyManager: false` per-request to bypass.
|
|
2843
|
+
*
|
|
2844
|
+
* @example
|
|
2845
|
+
* ```typescript
|
|
2846
|
+
* // With config (auto-creates ProxyManager)
|
|
2847
|
+
* const client = new Rezo({
|
|
2848
|
+
* proxyManager: {
|
|
2849
|
+
* rotation: 'random',
|
|
2850
|
+
* proxies: [
|
|
2851
|
+
* { protocol: 'socks5', host: '127.0.0.1', port: 1080 },
|
|
2852
|
+
* { protocol: 'http', host: 'proxy.example.com', port: 8080 }
|
|
2853
|
+
* ],
|
|
2854
|
+
* whitelist: ['api.example.com'],
|
|
2855
|
+
* autoDisableDeadProxies: true
|
|
2856
|
+
* }
|
|
2857
|
+
* });
|
|
2858
|
+
*
|
|
2859
|
+
* // With ProxyManager instance
|
|
2860
|
+
* const pm = new ProxyManager({ rotation: 'sequential', proxies: [...] });
|
|
2861
|
+
* const client = new Rezo({ proxyManager: pm });
|
|
2862
|
+
* ```
|
|
2863
|
+
*/
|
|
2864
|
+
proxyManager?: ProxyManager | ProxyManagerConfig;
|
|
2330
2865
|
}
|
|
2331
2866
|
export interface httpAdapterOverloads {
|
|
2332
2867
|
request<T = any>(options: RezoRequestOptions): Promise<RezoResponse<T>>;
|
|
@@ -3190,7 +3725,14 @@ export declare class Rezo {
|
|
|
3190
3725
|
readonly dnsCache?: DNSCache;
|
|
3191
3726
|
/** The adapter function used for HTTP requests */
|
|
3192
3727
|
private readonly adapter;
|
|
3728
|
+
/** Proxy manager for advanced proxy rotation and pool management */
|
|
3729
|
+
private readonly _proxyManager;
|
|
3193
3730
|
constructor(config?: RezoDefaultOptions, adapter?: AdapterFunction);
|
|
3731
|
+
/**
|
|
3732
|
+
* Get the ProxyManager instance (if configured)
|
|
3733
|
+
* @returns ProxyManager instance or null
|
|
3734
|
+
*/
|
|
3735
|
+
get proxyManager(): ProxyManager | null;
|
|
3194
3736
|
/**
|
|
3195
3737
|
* Clear all caches (response and DNS)
|
|
3196
3738
|
*/
|
|
@@ -3296,8 +3838,25 @@ export declare class Rezo {
|
|
|
3296
3838
|
*/
|
|
3297
3839
|
upload(url: string | URL, data: Buffer | FormData | RezoFormData | string | Record<string, any>, options?: RezoHttpRequest): RezoUploadResponse;
|
|
3298
3840
|
}
|
|
3841
|
+
/**
|
|
3842
|
+
* Extended Rezo instance with Axios-compatible static helpers.
|
|
3843
|
+
* Provides drop-in replacement API surface for Axios users.
|
|
3844
|
+
*/
|
|
3299
3845
|
export interface RezoInstance extends Rezo {
|
|
3846
|
+
/** Create a new Rezo instance with custom configuration */
|
|
3300
3847
|
create(config?: RezoDefaultOptions): Rezo;
|
|
3848
|
+
/** Type guard to check if an error is a RezoError instance */
|
|
3849
|
+
isRezoError: typeof RezoError.isRezoError;
|
|
3850
|
+
/** Check if an error is a cancellation error */
|
|
3851
|
+
isCancel: (error: unknown) => boolean;
|
|
3852
|
+
/** Alias for RezoError (Axios compatibility) */
|
|
3853
|
+
Cancel: typeof RezoError;
|
|
3854
|
+
/** AbortController for request cancellation (Axios compatibility) */
|
|
3855
|
+
CancelToken: typeof AbortController;
|
|
3856
|
+
/** Promise.all wrapper (Axios compatibility) */
|
|
3857
|
+
all: typeof Promise.all;
|
|
3858
|
+
/** Spread array arguments to callback function (Axios compatibility) */
|
|
3859
|
+
spread: <T extends unknown[], R>(callback: (...args: T) => R) => (array: T) => R;
|
|
3301
3860
|
}
|
|
3302
3861
|
/**
|
|
3303
3862
|
* Create a Rezo instance with a specific adapter.
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { RezoHeaders } from './utils/headers.js';
|
|
|
8
8
|
export { RezoFormData } from './utils/form-data.js';
|
|
9
9
|
export { RezoCookieJar } from './utils/cookies.js';
|
|
10
10
|
export { createDefaultHooks, mergeHooks } from './core/hooks.js';
|
|
11
|
+
export { ProxyManager } from './proxy/manager.js';
|
|
11
12
|
import { RezoError } from './errors/rezo-error.js';
|
|
12
13
|
export const isRezoError = RezoError.isRezoError;
|
|
13
14
|
export const Cancel = RezoError;
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
const { executeRequest } = require('../adapters/fetch.cjs');
|
|
2
2
|
const { setGlobalAdapter, createRezoInstance, Rezo } = require('../core/rezo.cjs');
|
|
3
|
+
const { RezoError, RezoErrorCode } = require('../errors/rezo-error.cjs');
|
|
4
|
+
const { RezoHeaders } = require('../utils/headers.cjs');
|
|
5
|
+
const { RezoFormData } = require('../utils/form-data.cjs');
|
|
6
|
+
const { RezoCookieJar } = require('../utils/cookies.cjs');
|
|
7
|
+
const { createDefaultHooks, mergeHooks } = require('../core/hooks.cjs');
|
|
8
|
+
const packageJson = require("../../package.json");
|
|
9
|
+
|
|
10
|
+
exports.Rezo = Rezo;
|
|
11
|
+
exports.RezoError = RezoError;
|
|
12
|
+
exports.RezoErrorCode = RezoErrorCode;
|
|
13
|
+
exports.RezoHeaders = RezoHeaders;
|
|
14
|
+
exports.RezoFormData = RezoFormData;
|
|
15
|
+
exports.RezoCookieJar = RezoCookieJar;
|
|
16
|
+
exports.createDefaultHooks = createDefaultHooks;
|
|
17
|
+
exports.mergeHooks = mergeHooks;
|
|
18
|
+
const isRezoError = exports.isRezoError = RezoError.isRezoError;
|
|
19
|
+
const Cancel = exports.Cancel = RezoError;
|
|
20
|
+
const CancelToken = exports.CancelToken = AbortController;
|
|
21
|
+
const isCancel = exports.isCancel = (error) => {
|
|
22
|
+
return error instanceof RezoError && error.code === "ECONNABORTED";
|
|
23
|
+
};
|
|
24
|
+
const all = exports.all = Promise.all.bind(Promise);
|
|
25
|
+
const spread = exports.spread = (callback) => (array) => callback(...array);
|
|
26
|
+
const VERSION = exports.VERSION = packageJson.version;
|
|
3
27
|
setGlobalAdapter(executeRequest);
|
|
4
28
|
const rezo = createRezoInstance(executeRequest);
|
|
5
29
|
|
|
6
|
-
exports.Rezo = Rezo;
|
|
7
|
-
exports.rezo = rezo;
|
|
8
30
|
exports.default = rezo;
|
|
9
31
|
module.exports = Object.assign(rezo, exports);
|