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.
Files changed (64) hide show
  1. package/README.md +261 -0
  2. package/dist/adapters/curl.cjs +47 -1
  3. package/dist/adapters/curl.js +47 -1
  4. package/dist/adapters/entries/curl.cjs +31 -4
  5. package/dist/adapters/entries/curl.d.ts +2576 -847
  6. package/dist/adapters/entries/curl.js +29 -2
  7. package/dist/adapters/entries/fetch.cjs +31 -2
  8. package/dist/adapters/entries/fetch.d.ts +1753 -15
  9. package/dist/adapters/entries/fetch.js +29 -1
  10. package/dist/adapters/entries/http.cjs +31 -2
  11. package/dist/adapters/entries/http.d.ts +1774 -14
  12. package/dist/adapters/entries/http.js +29 -1
  13. package/dist/adapters/entries/http2.cjs +31 -4
  14. package/dist/adapters/entries/http2.d.ts +1748 -19
  15. package/dist/adapters/entries/http2.js +29 -2
  16. package/dist/adapters/entries/react-native.cjs +31 -2
  17. package/dist/adapters/entries/react-native.d.ts +1753 -14
  18. package/dist/adapters/entries/react-native.js +29 -1
  19. package/dist/adapters/entries/xhr.cjs +31 -2
  20. package/dist/adapters/entries/xhr.d.ts +1753 -15
  21. package/dist/adapters/entries/xhr.js +29 -1
  22. package/dist/adapters/fetch.cjs +24 -20
  23. package/dist/adapters/fetch.js +24 -20
  24. package/dist/adapters/http.cjs +69 -19
  25. package/dist/adapters/http.js +69 -19
  26. package/dist/adapters/http2.cjs +69 -19
  27. package/dist/adapters/http2.js +69 -19
  28. package/dist/adapters/index.cjs +6 -6
  29. package/dist/cache/index.cjs +13 -13
  30. package/dist/core/hooks.cjs +16 -0
  31. package/dist/core/hooks.js +16 -0
  32. package/dist/core/rezo.cjs +23 -1
  33. package/dist/core/rezo.js +23 -1
  34. package/dist/crawler.d.ts +528 -5
  35. package/dist/entries/crawler.cjs +5 -5
  36. package/dist/index.cjs +18 -16
  37. package/dist/index.d.ts +564 -5
  38. package/dist/index.js +1 -0
  39. package/dist/platform/browser.cjs +24 -2
  40. package/dist/platform/browser.d.ts +672 -10
  41. package/dist/platform/browser.js +24 -2
  42. package/dist/platform/bun.cjs +24 -2
  43. package/dist/platform/bun.d.ts +672 -10
  44. package/dist/platform/bun.js +24 -2
  45. package/dist/platform/deno.cjs +24 -2
  46. package/dist/platform/deno.d.ts +672 -10
  47. package/dist/platform/deno.js +24 -2
  48. package/dist/platform/node.cjs +24 -2
  49. package/dist/platform/node.d.ts +672 -10
  50. package/dist/platform/node.js +24 -2
  51. package/dist/platform/react-native.cjs +24 -2
  52. package/dist/platform/react-native.d.ts +672 -10
  53. package/dist/platform/react-native.js +24 -2
  54. package/dist/platform/worker.cjs +24 -2
  55. package/dist/platform/worker.d.ts +672 -10
  56. package/dist/platform/worker.js +24 -2
  57. package/dist/plugin/index.cjs +36 -36
  58. package/dist/proxy/index.cjs +2 -0
  59. package/dist/proxy/index.js +1 -0
  60. package/dist/proxy/manager.cjs +446 -0
  61. package/dist/proxy/manager.js +444 -0
  62. package/dist/utils/http-config.cjs +14 -3
  63. package/dist/utils/http-config.js +14 -3
  64. package/package.json +19 -4
@@ -104,7 +104,7 @@ export type RezoHeadersInit = [
104
104
  string,
105
105
  string
106
106
  ][] | Record<string, string> | Headers | RezoHttpHeaders | RezoHeaders | OutgoingHttpHeaders;
107
- declare class RezoHeaders extends Headers {
107
+ export declare class RezoHeaders extends Headers {
108
108
  constructor(init?: RezoHeadersInit);
109
109
  getAll(name: "set-cookie" | "Set-Cookie"): string[];
110
110
  getSetCookie(): string[];
@@ -194,7 +194,7 @@ declare class Cookie extends TouchCookie {
194
194
  */
195
195
  static isCookie(cookie: any): cookie is Cookie;
196
196
  }
197
- declare class RezoCookieJar extends TouchCookieJar {
197
+ export declare class RezoCookieJar extends TouchCookieJar {
198
198
  constructor();
199
199
  constructor(cookies: Cookie[]);
200
200
  constructor(cookies: Cookie[], url: string);
@@ -283,7 +283,7 @@ export interface Options extends ReadableOptions {
283
283
  maxDataSize?: number;
284
284
  pauseStreams?: boolean;
285
285
  }
286
- declare class RezoFormData extends NodeFormData {
286
+ export declare class RezoFormData extends NodeFormData {
287
287
  constructor(options?: Options);
288
288
  /**
289
289
  * Get field entries as array of [name, value] pairs
@@ -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,12 +1519,29 @@ 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[];
1199
1533
  onTimeout: OnTimeoutHook[];
1200
1534
  onAbort: OnAbortHook[];
1201
1535
  }
1536
+ /**
1537
+ * Create empty hooks object with all arrays initialized
1538
+ */
1539
+ export declare function createDefaultHooks(): RezoHooks;
1540
+ /**
1541
+ * Merge base hooks with override hooks
1542
+ * Overrides are appended to base hooks (base runs first)
1543
+ */
1544
+ export declare function mergeHooks(base: RezoHooks, overrides?: Partial<RezoHooks>): RezoHooks;
1202
1545
  /**
1203
1546
  * Configuration object that encapsulates comprehensive request execution metadata and response processing information.
1204
1547
  * This interface serves as the central configuration hub for HTTP requests, containing both input parameters
@@ -1540,7 +1883,58 @@ export interface RezoConfig {
1540
1883
  */
1541
1884
  useCookies: boolean;
1542
1885
  }
1543
- declare class RezoError<T = any> extends Error {
1886
+ export declare enum RezoErrorCode {
1887
+ CONNECTION_REFUSED = "ECONNREFUSED",
1888
+ CONNECTION_RESET = "ECONNRESET",
1889
+ CONNECTION_TIMEOUT = "ETIMEDOUT",
1890
+ DNS_LOOKUP_FAILED = "ENOTFOUND",
1891
+ DNS_TEMPORARY_FAILURE = "EAI_AGAIN",
1892
+ HOST_UNREACHABLE = "EHOSTUNREACH",
1893
+ NETWORK_UNREACHABLE = "ENETUNREACH",
1894
+ BROKEN_PIPE = "EPIPE",
1895
+ HTTP_ERROR = "REZ_HTTP_ERROR",
1896
+ REDIRECT_DENIED = "REZ_REDIRECT_DENIED",
1897
+ MAX_REDIRECTS = "REZ_MAX_REDIRECTS_EXCEEDED",
1898
+ REDIRECT_CYCLE = "REZ_REDIRECT_CYCLE_DETECTED",
1899
+ MISSING_REDIRECT_LOCATION = "REZ_MISSING_REDIRECT_LOCATION",
1900
+ DECOMPRESSION_ERROR = "REZ_DECOMPRESSION_ERROR",
1901
+ REQUEST_TIMEOUT = "UND_ERR_REQUEST_TIMEOUT",
1902
+ HEADERS_TIMEOUT = "UND_ERR_HEADERS_TIMEOUT",
1903
+ CONNECT_TIMEOUT = "UND_ERR_CONNECT_TIMEOUT",
1904
+ ABORTED = "ABORT_ERR",
1905
+ DOWNLOAD_FAILED = "REZ_DOWNLOAD_FAILED",
1906
+ UPLOAD_FAILED = "REZ_UPLOAD_FAILED",
1907
+ STREAM_ERROR = "REZ_STREAM_ERROR",
1908
+ BODY_TOO_LARGE = "REZ_BODY_TOO_LARGE",
1909
+ RESPONSE_TOO_LARGE = "REZ_RESPONSE_TOO_LARGE",
1910
+ INVALID_JSON = "REZ_INVALID_JSON",
1911
+ INVALID_URL = "ERR_INVALID_URL",
1912
+ INVALID_PROTOCOL = "ERR_INVALID_PROTOCOL",
1913
+ INVALID_ARGUMENT = "ERR_INVALID_ARG_TYPE",
1914
+ FILE_PERMISSION = "REZ_FILE_PERMISSION_ERROR",
1915
+ PROXY_CONNECTION_FAILED = "REZ_PROXY_CONNECTION_FAILED",
1916
+ PROXY_AUTH_FAILED = "REZ_PROXY_AUTHENTICATION_FAILED",
1917
+ PROXY_TARGET_UNREACHABLE = "REZ_PROXY_TARGET_UNREACHABLE",
1918
+ PROXY_TIMEOUT = "REZ_PROXY_TIMEOUT",
1919
+ PROXY_ERROR = "REZ_PROXY_ERROR",
1920
+ PROXY_INVALID_PROTOCOL = "REZ_PROXY_INVALID_PROTOCOL",
1921
+ PROXY_INVALID_CONFIG = "REZ_PROXY_INVALID_HOSTPORT",
1922
+ SOCKS_CONNECTION_FAILED = "REZ_SOCKS_CONNECTION_FAILED",
1923
+ SOCKS_AUTH_FAILED = "REZ_SOCKS_AUTHENTICATION_FAILED",
1924
+ SOCKS_TARGET_UNREACHABLE = "REZ_SOCKS_TARGET_CONNECTION_FAILED",
1925
+ SOCKS_PROTOCOL_ERROR = "REZ_SOCKS_PROTOCOL_ERROR",
1926
+ SOCKS_UNSUPPORTED_VERSION = "REZ_SOCKS_UNSUPPORTED_VERSION",
1927
+ TLS_HANDSHAKE_TIMEOUT = "ERR_TLS_HANDSHAKE_TIMEOUT",
1928
+ TLS_PROTOCOL_ERROR = "EPROTO",
1929
+ TLS_PROTOCOL_VERSION = "ERR_TLS_INVALID_PROTOCOL_VERSION",
1930
+ CERTIFICATE_HOSTNAME_MISMATCH = "ERR_TLS_CERT_ALTNAME_INVALID",
1931
+ CERTIFICATE_EXPIRED = "CERT_HAS_EXPIRED",
1932
+ CERTIFICATE_SELF_SIGNED = "SELF_SIGNED_CERT_IN_CHAIN",
1933
+ CERTIFICATE_VERIFY_FAILED = "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
1934
+ RATE_LIMITED = "REZ_RATE_LIMITED",
1935
+ UNKNOWN_ERROR = "REZ_UNKNOWN_ERROR"
1936
+ }
1937
+ export declare class RezoError<T = any> extends Error {
1544
1938
  readonly code?: string;
1545
1939
  readonly errno?: number;
1546
1940
  readonly config: RezoConfig;
@@ -1589,16 +1983,13 @@ declare class RezoError<T = any> extends Error {
1589
1983
  toString(): string;
1590
1984
  getFullDetails(): string;
1591
1985
  }
1592
- /**
1593
- * Supported proxy protocols for network requests
1594
- */
1595
- export type ProxyProtocol = "http" | "https" | "socks4" | "socks5";
1986
+ type ProxyProtocol$1 = "http" | "https" | "socks4" | "socks5";
1596
1987
  /**
1597
1988
  * Configuration options for proxy connections
1598
1989
  */
1599
1990
  export type ProxyOptions = {
1600
1991
  /** The proxy protocol to use */
1601
- protocol: ProxyProtocol;
1992
+ protocol: ProxyProtocol$1;
1602
1993
  /** Proxy server hostname or IP address */
1603
1994
  host: string;
1604
1995
  /** Proxy server port number */
@@ -1639,6 +2030,51 @@ export type RezoString = string;
1639
2030
  * Standard HTTP methods supported by Rezo
1640
2031
  */
1641
2032
  export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT";
2033
+ /**
2034
+ * Response data types that control how Rezo parses the response body.
2035
+ *
2036
+ * @description
2037
+ * Specifies how the response body should be parsed and returned in `response.data`.
2038
+ * Choose the type that matches your expected response format.
2039
+ *
2040
+ * **Available Types:**
2041
+ *
2042
+ * - `'json'` - Parse response as JSON. Returns parsed object/array.
2043
+ * Best for REST APIs that return JSON data.
2044
+ *
2045
+ * - `'text'` - Return response as a string. No parsing applied.
2046
+ * Best for HTML, XML, plain text, or when you need raw content.
2047
+ *
2048
+ * - `'blob'` - Return as Blob object (browser environments).
2049
+ * Best for binary data in browsers (images, files, etc).
2050
+ *
2051
+ * - `'arrayBuffer'` - Return as ArrayBuffer.
2052
+ * Best for binary data processing, cryptographic operations.
2053
+ *
2054
+ * - `'buffer'` - Return as Node.js Buffer.
2055
+ * Best for binary data in Node.js (files, images, binary protocols).
2056
+ *
2057
+ * - `'auto'` - Auto-detect based on Content-Type header (default).
2058
+ * JSON for `application/json`, text for `text/*`, buffer otherwise.
2059
+ *
2060
+ * **Streaming Operations:**
2061
+ * For streaming, use dedicated methods instead of responseType:
2062
+ * - `rezo.stream(url)` - Returns StreamResponse for real-time data
2063
+ * - `rezo.download(url, saveTo)` - Returns DownloadResponse with progress
2064
+ * - `rezo.upload(url, data)` - Returns UploadResponse with progress
2065
+ *
2066
+ * @example
2067
+ * // Get JSON data (default for JSON APIs)
2068
+ * const { data } = await rezo.get('/api/users', { responseType: 'json' });
2069
+ *
2070
+ * // Get HTML as text
2071
+ * const { data: html } = await rezo.get('/page', { responseType: 'text' });
2072
+ *
2073
+ * // Get image as buffer
2074
+ * const { data: imageBuffer } = await rezo.get('/image.png', { responseType: 'buffer' });
2075
+ *
2076
+ * @default 'auto'
2077
+ */
1642
2078
  type ResponseType$1 = "json" | "text" | "blob" | "arrayBuffer" | "buffer" | "auto";
1643
2079
  /**
1644
2080
  * MIME content types for request/response bodies
@@ -2096,6 +2532,162 @@ declare class ResponseCache {
2096
2532
  get isPersistent(): boolean;
2097
2533
  getConfig(): ResponseCacheConfig;
2098
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
+ declare class ProxyManager {
2557
+ /** Configuration for the proxy manager */
2558
+ readonly config: ProxyManagerConfig;
2559
+ /** Internal proxy states map (proxyId -> state) */
2560
+ private states;
2561
+ /** Current index for sequential rotation */
2562
+ private currentIndex;
2563
+ /** Request counter for current proxy (sequential rotation) */
2564
+ private currentProxyRequests;
2565
+ /** Last selected proxy (for rotation tracking) */
2566
+ private lastSelectedProxy;
2567
+ /** Cooldown timers map (proxyId -> timerId) */
2568
+ private cooldownTimers;
2569
+ /** Total requests through manager */
2570
+ private _totalRequests;
2571
+ /** Total successful requests */
2572
+ private _totalSuccesses;
2573
+ /** Total failed requests */
2574
+ private _totalFailures;
2575
+ /** Proxy hooks */
2576
+ hooks: ProxyHooks;
2577
+ /**
2578
+ * Create a new ProxyManager instance
2579
+ * @param config - Proxy manager configuration
2580
+ */
2581
+ constructor(config: ProxyManagerConfig);
2582
+ /**
2583
+ * Create initial state for a proxy
2584
+ */
2585
+ private createInitialState;
2586
+ /**
2587
+ * Check if a URL should use proxy based on whitelist/blacklist
2588
+ * @param url - The request URL to check
2589
+ * @returns true if URL should use proxy, false if should go direct
2590
+ */
2591
+ shouldProxy(url: string): boolean;
2592
+ /**
2593
+ * Match a URL against a pattern
2594
+ */
2595
+ private matchPattern;
2596
+ /**
2597
+ * Get active proxies (not disabled)
2598
+ */
2599
+ getActive(): ProxyInfo[];
2600
+ /**
2601
+ * Get disabled proxies
2602
+ */
2603
+ getDisabled(): ProxyInfo[];
2604
+ /**
2605
+ * Get proxies in cooldown
2606
+ */
2607
+ getCooldown(): ProxyInfo[];
2608
+ /**
2609
+ * Process expired cooldowns and re-enable proxies
2610
+ */
2611
+ private processExpiredCooldowns;
2612
+ /**
2613
+ * Get next proxy based on rotation strategy
2614
+ * @param url - The request URL (for whitelist/blacklist checking)
2615
+ * @returns Selected proxy or null if should go direct
2616
+ */
2617
+ next(url: string): ProxyInfo | null;
2618
+ /**
2619
+ * Get detailed selection result with reason
2620
+ * @param url - The request URL
2621
+ * @returns Selection result with proxy and reason
2622
+ */
2623
+ select(url: string): ProxySelectionResult;
2624
+ /**
2625
+ * Select proxy based on rotation strategy
2626
+ */
2627
+ private selectProxy;
2628
+ /**
2629
+ * Report a successful request through a proxy
2630
+ * @param proxy - The proxy that succeeded
2631
+ */
2632
+ reportSuccess(proxy: ProxyInfo): void;
2633
+ /**
2634
+ * Report a failed request through a proxy
2635
+ * @param proxy - The proxy that failed
2636
+ * @param error - The error that occurred
2637
+ * @param url - Optional URL for hook context
2638
+ */
2639
+ reportFailure(proxy: ProxyInfo, error: Error, url?: string): void;
2640
+ /**
2641
+ * Disable a proxy from the pool
2642
+ * @param proxy - The proxy to disable
2643
+ * @param reason - Reason for disabling
2644
+ */
2645
+ disableProxy(proxy: ProxyInfo, reason?: "dead" | "limit-reached" | "manual"): void;
2646
+ /**
2647
+ * Enable a previously disabled proxy
2648
+ * @param proxy - The proxy to enable
2649
+ * @param reason - Reason for enabling
2650
+ */
2651
+ enableProxy(proxy: ProxyInfo, reason?: "cooldown-expired" | "manual"): void;
2652
+ /**
2653
+ * Add proxies to the pool
2654
+ * @param proxies - Proxies to add
2655
+ */
2656
+ add(proxies: ProxyInfo | ProxyInfo[]): void;
2657
+ /**
2658
+ * Remove proxies from the pool
2659
+ * @param proxies - Proxies to remove
2660
+ */
2661
+ remove(proxies: ProxyInfo | ProxyInfo[]): void;
2662
+ /**
2663
+ * Reset all proxies - re-enable all and reset counters
2664
+ */
2665
+ reset(): void;
2666
+ /**
2667
+ * Get current status of all proxies
2668
+ */
2669
+ getStatus(): ProxyManagerStatus;
2670
+ /**
2671
+ * Get state for a specific proxy
2672
+ * @param proxy - The proxy to get state for
2673
+ */
2674
+ getProxyState(proxy: ProxyInfo): ProxyState | undefined;
2675
+ /**
2676
+ * Check if any proxies are available
2677
+ */
2678
+ hasAvailableProxies(): boolean;
2679
+ /**
2680
+ * Destroy the manager and cleanup timers
2681
+ */
2682
+ destroy(): void;
2683
+ private runBeforeProxySelectHooksSync;
2684
+ private runAfterProxySelectHooksSync;
2685
+ private runBeforeProxyErrorHooksSync;
2686
+ private runAfterProxyErrorHooksSync;
2687
+ private runAfterProxyRotateHooks;
2688
+ private runAfterProxyDisableHooks;
2689
+ private runAfterProxyEnableHooks;
2690
+ }
2099
2691
  export type queueOptions = Options$1<PriorityQueue, QueueAddOptions>;
2100
2692
  export interface CacheConfig {
2101
2693
  /** Response cache configuration */
@@ -2222,6 +2814,35 @@ export interface RezoDefaultOptions {
2222
2814
  * DNS cache defaults: 1 min TTL, 1000 entries
2223
2815
  */
2224
2816
  cache?: CacheOption;
2817
+ /**
2818
+ * Proxy manager for advanced proxy rotation and pool management
2819
+ * - Provide a `ProxyManager` instance for full control
2820
+ * - Or provide `ProxyManagerConfig` to auto-create internally
2821
+ *
2822
+ * Note: ProxyManager overrides `proxy` option when set.
2823
+ * Use `useProxyManager: false` per-request to bypass.
2824
+ *
2825
+ * @example
2826
+ * ```typescript
2827
+ * // With config (auto-creates ProxyManager)
2828
+ * const client = new Rezo({
2829
+ * proxyManager: {
2830
+ * rotation: 'random',
2831
+ * proxies: [
2832
+ * { protocol: 'socks5', host: '127.0.0.1', port: 1080 },
2833
+ * { protocol: 'http', host: 'proxy.example.com', port: 8080 }
2834
+ * ],
2835
+ * whitelist: ['api.example.com'],
2836
+ * autoDisableDeadProxies: true
2837
+ * }
2838
+ * });
2839
+ *
2840
+ * // With ProxyManager instance
2841
+ * const pm = new ProxyManager({ rotation: 'sequential', proxies: [...] });
2842
+ * const client = new Rezo({ proxyManager: pm });
2843
+ * ```
2844
+ */
2845
+ proxyManager?: ProxyManager | ProxyManagerConfig;
2225
2846
  }
2226
2847
  export interface httpAdapterOverloads {
2227
2848
  request<T = any>(options: RezoRequestOptions): Promise<RezoResponse<T>>;
@@ -3085,7 +3706,14 @@ export declare class Rezo {
3085
3706
  readonly dnsCache?: DNSCache;
3086
3707
  /** The adapter function used for HTTP requests */
3087
3708
  private readonly adapter;
3709
+ /** Proxy manager for advanced proxy rotation and pool management */
3710
+ private readonly _proxyManager;
3088
3711
  constructor(config?: RezoDefaultOptions, adapter?: AdapterFunction);
3712
+ /**
3713
+ * Get the ProxyManager instance (if configured)
3714
+ * @returns ProxyManager instance or null
3715
+ */
3716
+ get proxyManager(): ProxyManager | null;
3089
3717
  /**
3090
3718
  * Clear all caches (response and DNS)
3091
3719
  */
@@ -3191,12 +3819,46 @@ export declare class Rezo {
3191
3819
  */
3192
3820
  upload(url: string | URL, data: Buffer | FormData | RezoFormData | string | Record<string, any>, options?: RezoHttpRequest): RezoUploadResponse;
3193
3821
  }
3822
+ /**
3823
+ * Extended Rezo instance with Axios-compatible static helpers.
3824
+ * Provides drop-in replacement API surface for Axios users.
3825
+ */
3194
3826
  export interface RezoInstance extends Rezo {
3827
+ /** Create a new Rezo instance with custom configuration */
3195
3828
  create(config?: RezoDefaultOptions): Rezo;
3829
+ /** Type guard to check if an error is a RezoError instance */
3830
+ isRezoError: typeof RezoError.isRezoError;
3831
+ /** Check if an error is a cancellation error */
3832
+ isCancel: (error: unknown) => boolean;
3833
+ /** Alias for RezoError (Axios compatibility) */
3834
+ Cancel: typeof RezoError;
3835
+ /** AbortController for request cancellation (Axios compatibility) */
3836
+ CancelToken: typeof AbortController;
3837
+ /** Promise.all wrapper (Axios compatibility) */
3838
+ all: typeof Promise.all;
3839
+ /** Spread array arguments to callback function (Axios compatibility) */
3840
+ spread: <T extends unknown[], R>(callback: (...args: T) => R) => (array: T) => R;
3196
3841
  }
3197
- export declare const rezo: RezoInstance;
3842
+ export declare const isRezoError: typeof RezoError.isRezoError;
3843
+ export declare const Cancel: typeof RezoError;
3844
+ export declare const CancelToken: {
3845
+ new (): AbortController;
3846
+ prototype: AbortController;
3847
+ };
3848
+ export declare const isCancel: (error: unknown) => boolean;
3849
+ export declare const all: {
3850
+ <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
3851
+ <T extends readonly unknown[] | [
3852
+ ]>(values: T): Promise<{
3853
+ -readonly [P in keyof T]: Awaited<T[P]>;
3854
+ }>;
3855
+ };
3856
+ export declare const spread: <T extends unknown[], R>(callback: (...args: T) => R) => (array: T) => R;
3857
+ export declare const VERSION: string;
3858
+ declare const rezo: RezoInstance;
3198
3859
 
3199
3860
  export {
3861
+ ResponseType$1 as ResponseType,
3200
3862
  rezo as default,
3201
3863
  };
3202
3864