rezo 1.0.44 → 1.0.45

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 (37) hide show
  1. package/dist/adapters/entries/curl.d.ts +115 -0
  2. package/dist/adapters/entries/fetch.d.ts +115 -0
  3. package/dist/adapters/entries/http.d.ts +115 -0
  4. package/dist/adapters/entries/http2.d.ts +115 -0
  5. package/dist/adapters/entries/react-native.d.ts +115 -0
  6. package/dist/adapters/entries/xhr.d.ts +115 -0
  7. package/dist/adapters/fetch.cjs +18 -0
  8. package/dist/adapters/fetch.js +18 -0
  9. package/dist/adapters/http.cjs +18 -0
  10. package/dist/adapters/http.js +18 -0
  11. package/dist/adapters/http2.cjs +18 -0
  12. package/dist/adapters/http2.js +18 -0
  13. package/dist/adapters/index.cjs +6 -6
  14. package/dist/adapters/xhr.cjs +19 -0
  15. package/dist/adapters/xhr.js +19 -0
  16. package/dist/cache/index.cjs +9 -9
  17. package/dist/core/hooks.cjs +4 -2
  18. package/dist/core/hooks.js +4 -2
  19. package/dist/crawler/index.cjs +40 -40
  20. package/dist/crawler.d.ts +115 -0
  21. package/dist/entries/crawler.cjs +5 -5
  22. package/dist/index.cjs +27 -27
  23. package/dist/index.d.ts +115 -0
  24. package/dist/internal/agents/index.cjs +10 -10
  25. package/dist/platform/browser.d.ts +115 -0
  26. package/dist/platform/bun.d.ts +115 -0
  27. package/dist/platform/deno.d.ts +115 -0
  28. package/dist/platform/node.d.ts +115 -0
  29. package/dist/platform/react-native.d.ts +115 -0
  30. package/dist/platform/worker.d.ts +115 -0
  31. package/dist/proxy/index.cjs +5 -5
  32. package/dist/proxy/index.js +1 -1
  33. package/dist/queue/index.cjs +8 -8
  34. package/dist/responses/universal/index.cjs +11 -11
  35. package/dist/utils/rate-limit-wait.cjs +217 -0
  36. package/dist/utils/rate-limit-wait.js +208 -0
  37. package/package.json +1 -1
@@ -1416,6 +1416,35 @@ export type OnTimeoutHook = (event: TimeoutEvent, config: RezoConfig) => void;
1416
1416
  * Use for cleanup, logging
1417
1417
  */
1418
1418
  export type OnAbortHook = (event: AbortEvent, config: RezoConfig) => void;
1419
+ /**
1420
+ * Rate limit wait event data - fired when waiting due to rate limiting
1421
+ */
1422
+ export interface RateLimitWaitEvent {
1423
+ /** HTTP status code that triggered the wait (e.g., 429, 503) */
1424
+ status: number;
1425
+ /** Time to wait in milliseconds */
1426
+ waitTime: number;
1427
+ /** Current wait attempt number (1-indexed) */
1428
+ attempt: number;
1429
+ /** Maximum wait attempts configured */
1430
+ maxAttempts: number;
1431
+ /** Where the wait time was extracted from */
1432
+ source: "header" | "body" | "function" | "default";
1433
+ /** The header or body path used (if applicable) */
1434
+ sourcePath?: string;
1435
+ /** URL being requested */
1436
+ url: string;
1437
+ /** HTTP method of the request */
1438
+ method: string;
1439
+ /** Timestamp when the wait started */
1440
+ timestamp: number;
1441
+ }
1442
+ /**
1443
+ * Hook called when rate limit wait occurs
1444
+ * Informational only - cannot abort the wait
1445
+ * Use for logging, monitoring, alerting
1446
+ */
1447
+ export type OnRateLimitWaitHook = (event: RateLimitWaitEvent, config: RezoConfig) => void | Promise<void>;
1419
1448
  /**
1420
1449
  * Hook called before a proxy is selected
1421
1450
  * Can return a specific proxy to override selection
@@ -1496,6 +1525,7 @@ export interface RezoHooks {
1496
1525
  onTls: OnTlsHook[];
1497
1526
  onTimeout: OnTimeoutHook[];
1498
1527
  onAbort: OnAbortHook[];
1528
+ onRateLimitWait: OnRateLimitWaitHook[];
1499
1529
  }
1500
1530
  /**
1501
1531
  * Create empty hooks object with all arrays initialized
@@ -2426,6 +2456,91 @@ export interface RezoRequestConfig<D = any> {
2426
2456
  /** Weather to stop or continue retry when certain condition is met*/
2427
2457
  condition?: (error: RezoError) => boolean | Promise<boolean>;
2428
2458
  };
2459
+ /**
2460
+ * Rate limit wait configuration - wait and retry when receiving rate limit responses.
2461
+ *
2462
+ * This feature runs BEFORE the retry system. When a rate-limiting status code is received,
2463
+ * the client will wait for the specified time and automatically retry the request.
2464
+ *
2465
+ * **Basic Usage:**
2466
+ * - `waitOnStatus: true` - Enable waiting on 429 status (default behavior)
2467
+ * - `waitOnStatus: [429, 503]` - Enable waiting on specific status codes
2468
+ *
2469
+ * **Wait Time Sources:**
2470
+ * - `'retry-after'` - Use standard Retry-After header (default)
2471
+ * - `{ header: 'X-RateLimit-Reset' }` - Use custom header
2472
+ * - `{ body: 'retry_after' }` - Extract from JSON response body
2473
+ * - Custom function for complex logic
2474
+ *
2475
+ * @example
2476
+ * ```typescript
2477
+ * // Wait on 429 using Retry-After header
2478
+ * await rezo.get(url, { waitOnStatus: true });
2479
+ *
2480
+ * // Wait on 429 using custom header
2481
+ * await rezo.get(url, {
2482
+ * waitOnStatus: true,
2483
+ * waitTimeSource: { header: 'X-RateLimit-Reset' }
2484
+ * });
2485
+ *
2486
+ * // Wait on 429 extracting time from JSON body
2487
+ * await rezo.get(url, {
2488
+ * waitOnStatus: true,
2489
+ * waitTimeSource: { body: 'data.retry_after' }
2490
+ * });
2491
+ *
2492
+ * // Custom function for complex APIs
2493
+ * await rezo.get(url, {
2494
+ * waitOnStatus: [429, 503],
2495
+ * waitTimeSource: (response) => {
2496
+ * const reset = response.headers.get('x-ratelimit-reset');
2497
+ * return reset ? parseInt(reset) - Math.floor(Date.now() / 1000) : null;
2498
+ * }
2499
+ * });
2500
+ * ```
2501
+ */
2502
+ waitOnStatus?: boolean | number[];
2503
+ /**
2504
+ * Where to extract the wait time from when rate-limited.
2505
+ *
2506
+ * - `'retry-after'` - Standard Retry-After header (default)
2507
+ * - `{ header: string }` - Custom header name (e.g., 'X-RateLimit-Reset')
2508
+ * - `{ body: string }` - JSON path in response body (e.g., 'data.retry_after', 'wait_seconds')
2509
+ * - Function - Custom logic receiving the response, return seconds to wait or null
2510
+ *
2511
+ * @default 'retry-after'
2512
+ */
2513
+ waitTimeSource?: "retry-after" | {
2514
+ header: string;
2515
+ } | {
2516
+ body: string;
2517
+ } | ((response: {
2518
+ status: number;
2519
+ headers: RezoHeaders;
2520
+ data?: any;
2521
+ }) => number | null);
2522
+ /**
2523
+ * Maximum time to wait for rate limit in milliseconds.
2524
+ * If the extracted wait time exceeds this, the request will fail instead of waiting.
2525
+ * Set to 0 for unlimited wait time.
2526
+ *
2527
+ * @default 60000 (60 seconds)
2528
+ */
2529
+ maxWaitTime?: number;
2530
+ /**
2531
+ * Default wait time in milliseconds if the wait time source returns nothing.
2532
+ * Used as fallback when Retry-After header or body path is not present.
2533
+ *
2534
+ * @default 1000 (1 second)
2535
+ */
2536
+ defaultWaitTime?: number;
2537
+ /**
2538
+ * Maximum number of wait attempts before giving up.
2539
+ * After this many waits, the request will proceed to retry logic or fail.
2540
+ *
2541
+ * @default 3
2542
+ */
2543
+ maxWaitAttempts?: number;
2429
2544
  /** Whether to use a secure context for HTTPS requests */
2430
2545
  useSecureContext?: boolean;
2431
2546
  /** Custom secure context for TLS connections */
@@ -1416,6 +1416,35 @@ export type OnTimeoutHook = (event: TimeoutEvent, config: RezoConfig) => void;
1416
1416
  * Use for cleanup, logging
1417
1417
  */
1418
1418
  export type OnAbortHook = (event: AbortEvent, config: RezoConfig) => void;
1419
+ /**
1420
+ * Rate limit wait event data - fired when waiting due to rate limiting
1421
+ */
1422
+ export interface RateLimitWaitEvent {
1423
+ /** HTTP status code that triggered the wait (e.g., 429, 503) */
1424
+ status: number;
1425
+ /** Time to wait in milliseconds */
1426
+ waitTime: number;
1427
+ /** Current wait attempt number (1-indexed) */
1428
+ attempt: number;
1429
+ /** Maximum wait attempts configured */
1430
+ maxAttempts: number;
1431
+ /** Where the wait time was extracted from */
1432
+ source: "header" | "body" | "function" | "default";
1433
+ /** The header or body path used (if applicable) */
1434
+ sourcePath?: string;
1435
+ /** URL being requested */
1436
+ url: string;
1437
+ /** HTTP method of the request */
1438
+ method: string;
1439
+ /** Timestamp when the wait started */
1440
+ timestamp: number;
1441
+ }
1442
+ /**
1443
+ * Hook called when rate limit wait occurs
1444
+ * Informational only - cannot abort the wait
1445
+ * Use for logging, monitoring, alerting
1446
+ */
1447
+ export type OnRateLimitWaitHook = (event: RateLimitWaitEvent, config: RezoConfig) => void | Promise<void>;
1419
1448
  /**
1420
1449
  * Hook called before a proxy is selected
1421
1450
  * Can return a specific proxy to override selection
@@ -1496,6 +1525,7 @@ export interface RezoHooks {
1496
1525
  onTls: OnTlsHook[];
1497
1526
  onTimeout: OnTimeoutHook[];
1498
1527
  onAbort: OnAbortHook[];
1528
+ onRateLimitWait: OnRateLimitWaitHook[];
1499
1529
  }
1500
1530
  /**
1501
1531
  * Create empty hooks object with all arrays initialized
@@ -2426,6 +2456,91 @@ export interface RezoRequestConfig<D = any> {
2426
2456
  /** Weather to stop or continue retry when certain condition is met*/
2427
2457
  condition?: (error: RezoError) => boolean | Promise<boolean>;
2428
2458
  };
2459
+ /**
2460
+ * Rate limit wait configuration - wait and retry when receiving rate limit responses.
2461
+ *
2462
+ * This feature runs BEFORE the retry system. When a rate-limiting status code is received,
2463
+ * the client will wait for the specified time and automatically retry the request.
2464
+ *
2465
+ * **Basic Usage:**
2466
+ * - `waitOnStatus: true` - Enable waiting on 429 status (default behavior)
2467
+ * - `waitOnStatus: [429, 503]` - Enable waiting on specific status codes
2468
+ *
2469
+ * **Wait Time Sources:**
2470
+ * - `'retry-after'` - Use standard Retry-After header (default)
2471
+ * - `{ header: 'X-RateLimit-Reset' }` - Use custom header
2472
+ * - `{ body: 'retry_after' }` - Extract from JSON response body
2473
+ * - Custom function for complex logic
2474
+ *
2475
+ * @example
2476
+ * ```typescript
2477
+ * // Wait on 429 using Retry-After header
2478
+ * await rezo.get(url, { waitOnStatus: true });
2479
+ *
2480
+ * // Wait on 429 using custom header
2481
+ * await rezo.get(url, {
2482
+ * waitOnStatus: true,
2483
+ * waitTimeSource: { header: 'X-RateLimit-Reset' }
2484
+ * });
2485
+ *
2486
+ * // Wait on 429 extracting time from JSON body
2487
+ * await rezo.get(url, {
2488
+ * waitOnStatus: true,
2489
+ * waitTimeSource: { body: 'data.retry_after' }
2490
+ * });
2491
+ *
2492
+ * // Custom function for complex APIs
2493
+ * await rezo.get(url, {
2494
+ * waitOnStatus: [429, 503],
2495
+ * waitTimeSource: (response) => {
2496
+ * const reset = response.headers.get('x-ratelimit-reset');
2497
+ * return reset ? parseInt(reset) - Math.floor(Date.now() / 1000) : null;
2498
+ * }
2499
+ * });
2500
+ * ```
2501
+ */
2502
+ waitOnStatus?: boolean | number[];
2503
+ /**
2504
+ * Where to extract the wait time from when rate-limited.
2505
+ *
2506
+ * - `'retry-after'` - Standard Retry-After header (default)
2507
+ * - `{ header: string }` - Custom header name (e.g., 'X-RateLimit-Reset')
2508
+ * - `{ body: string }` - JSON path in response body (e.g., 'data.retry_after', 'wait_seconds')
2509
+ * - Function - Custom logic receiving the response, return seconds to wait or null
2510
+ *
2511
+ * @default 'retry-after'
2512
+ */
2513
+ waitTimeSource?: "retry-after" | {
2514
+ header: string;
2515
+ } | {
2516
+ body: string;
2517
+ } | ((response: {
2518
+ status: number;
2519
+ headers: RezoHeaders;
2520
+ data?: any;
2521
+ }) => number | null);
2522
+ /**
2523
+ * Maximum time to wait for rate limit in milliseconds.
2524
+ * If the extracted wait time exceeds this, the request will fail instead of waiting.
2525
+ * Set to 0 for unlimited wait time.
2526
+ *
2527
+ * @default 60000 (60 seconds)
2528
+ */
2529
+ maxWaitTime?: number;
2530
+ /**
2531
+ * Default wait time in milliseconds if the wait time source returns nothing.
2532
+ * Used as fallback when Retry-After header or body path is not present.
2533
+ *
2534
+ * @default 1000 (1 second)
2535
+ */
2536
+ defaultWaitTime?: number;
2537
+ /**
2538
+ * Maximum number of wait attempts before giving up.
2539
+ * After this many waits, the request will proceed to retry logic or fail.
2540
+ *
2541
+ * @default 3
2542
+ */
2543
+ maxWaitAttempts?: number;
2429
2544
  /** Whether to use a secure context for HTTPS requests */
2430
2545
  useSecureContext?: boolean;
2431
2546
  /** Custom secure context for TLS connections */
@@ -1416,6 +1416,35 @@ export type OnTimeoutHook = (event: TimeoutEvent, config: RezoConfig) => void;
1416
1416
  * Use for cleanup, logging
1417
1417
  */
1418
1418
  export type OnAbortHook = (event: AbortEvent, config: RezoConfig) => void;
1419
+ /**
1420
+ * Rate limit wait event data - fired when waiting due to rate limiting
1421
+ */
1422
+ export interface RateLimitWaitEvent {
1423
+ /** HTTP status code that triggered the wait (e.g., 429, 503) */
1424
+ status: number;
1425
+ /** Time to wait in milliseconds */
1426
+ waitTime: number;
1427
+ /** Current wait attempt number (1-indexed) */
1428
+ attempt: number;
1429
+ /** Maximum wait attempts configured */
1430
+ maxAttempts: number;
1431
+ /** Where the wait time was extracted from */
1432
+ source: "header" | "body" | "function" | "default";
1433
+ /** The header or body path used (if applicable) */
1434
+ sourcePath?: string;
1435
+ /** URL being requested */
1436
+ url: string;
1437
+ /** HTTP method of the request */
1438
+ method: string;
1439
+ /** Timestamp when the wait started */
1440
+ timestamp: number;
1441
+ }
1442
+ /**
1443
+ * Hook called when rate limit wait occurs
1444
+ * Informational only - cannot abort the wait
1445
+ * Use for logging, monitoring, alerting
1446
+ */
1447
+ export type OnRateLimitWaitHook = (event: RateLimitWaitEvent, config: RezoConfig) => void | Promise<void>;
1419
1448
  /**
1420
1449
  * Hook called before a proxy is selected
1421
1450
  * Can return a specific proxy to override selection
@@ -1496,6 +1525,7 @@ export interface RezoHooks {
1496
1525
  onTls: OnTlsHook[];
1497
1526
  onTimeout: OnTimeoutHook[];
1498
1527
  onAbort: OnAbortHook[];
1528
+ onRateLimitWait: OnRateLimitWaitHook[];
1499
1529
  }
1500
1530
  /**
1501
1531
  * Create empty hooks object with all arrays initialized
@@ -2426,6 +2456,91 @@ export interface RezoRequestConfig<D = any> {
2426
2456
  /** Weather to stop or continue retry when certain condition is met*/
2427
2457
  condition?: (error: RezoError) => boolean | Promise<boolean>;
2428
2458
  };
2459
+ /**
2460
+ * Rate limit wait configuration - wait and retry when receiving rate limit responses.
2461
+ *
2462
+ * This feature runs BEFORE the retry system. When a rate-limiting status code is received,
2463
+ * the client will wait for the specified time and automatically retry the request.
2464
+ *
2465
+ * **Basic Usage:**
2466
+ * - `waitOnStatus: true` - Enable waiting on 429 status (default behavior)
2467
+ * - `waitOnStatus: [429, 503]` - Enable waiting on specific status codes
2468
+ *
2469
+ * **Wait Time Sources:**
2470
+ * - `'retry-after'` - Use standard Retry-After header (default)
2471
+ * - `{ header: 'X-RateLimit-Reset' }` - Use custom header
2472
+ * - `{ body: 'retry_after' }` - Extract from JSON response body
2473
+ * - Custom function for complex logic
2474
+ *
2475
+ * @example
2476
+ * ```typescript
2477
+ * // Wait on 429 using Retry-After header
2478
+ * await rezo.get(url, { waitOnStatus: true });
2479
+ *
2480
+ * // Wait on 429 using custom header
2481
+ * await rezo.get(url, {
2482
+ * waitOnStatus: true,
2483
+ * waitTimeSource: { header: 'X-RateLimit-Reset' }
2484
+ * });
2485
+ *
2486
+ * // Wait on 429 extracting time from JSON body
2487
+ * await rezo.get(url, {
2488
+ * waitOnStatus: true,
2489
+ * waitTimeSource: { body: 'data.retry_after' }
2490
+ * });
2491
+ *
2492
+ * // Custom function for complex APIs
2493
+ * await rezo.get(url, {
2494
+ * waitOnStatus: [429, 503],
2495
+ * waitTimeSource: (response) => {
2496
+ * const reset = response.headers.get('x-ratelimit-reset');
2497
+ * return reset ? parseInt(reset) - Math.floor(Date.now() / 1000) : null;
2498
+ * }
2499
+ * });
2500
+ * ```
2501
+ */
2502
+ waitOnStatus?: boolean | number[];
2503
+ /**
2504
+ * Where to extract the wait time from when rate-limited.
2505
+ *
2506
+ * - `'retry-after'` - Standard Retry-After header (default)
2507
+ * - `{ header: string }` - Custom header name (e.g., 'X-RateLimit-Reset')
2508
+ * - `{ body: string }` - JSON path in response body (e.g., 'data.retry_after', 'wait_seconds')
2509
+ * - Function - Custom logic receiving the response, return seconds to wait or null
2510
+ *
2511
+ * @default 'retry-after'
2512
+ */
2513
+ waitTimeSource?: "retry-after" | {
2514
+ header: string;
2515
+ } | {
2516
+ body: string;
2517
+ } | ((response: {
2518
+ status: number;
2519
+ headers: RezoHeaders;
2520
+ data?: any;
2521
+ }) => number | null);
2522
+ /**
2523
+ * Maximum time to wait for rate limit in milliseconds.
2524
+ * If the extracted wait time exceeds this, the request will fail instead of waiting.
2525
+ * Set to 0 for unlimited wait time.
2526
+ *
2527
+ * @default 60000 (60 seconds)
2528
+ */
2529
+ maxWaitTime?: number;
2530
+ /**
2531
+ * Default wait time in milliseconds if the wait time source returns nothing.
2532
+ * Used as fallback when Retry-After header or body path is not present.
2533
+ *
2534
+ * @default 1000 (1 second)
2535
+ */
2536
+ defaultWaitTime?: number;
2537
+ /**
2538
+ * Maximum number of wait attempts before giving up.
2539
+ * After this many waits, the request will proceed to retry logic or fail.
2540
+ *
2541
+ * @default 3
2542
+ */
2543
+ maxWaitAttempts?: number;
2429
2544
  /** Whether to use a secure context for HTTPS requests */
2430
2545
  useSecureContext?: boolean;
2431
2546
  /** Custom secure context for TLS connections */
@@ -1416,6 +1416,35 @@ export type OnTimeoutHook = (event: TimeoutEvent, config: RezoConfig) => void;
1416
1416
  * Use for cleanup, logging
1417
1417
  */
1418
1418
  export type OnAbortHook = (event: AbortEvent, config: RezoConfig) => void;
1419
+ /**
1420
+ * Rate limit wait event data - fired when waiting due to rate limiting
1421
+ */
1422
+ export interface RateLimitWaitEvent {
1423
+ /** HTTP status code that triggered the wait (e.g., 429, 503) */
1424
+ status: number;
1425
+ /** Time to wait in milliseconds */
1426
+ waitTime: number;
1427
+ /** Current wait attempt number (1-indexed) */
1428
+ attempt: number;
1429
+ /** Maximum wait attempts configured */
1430
+ maxAttempts: number;
1431
+ /** Where the wait time was extracted from */
1432
+ source: "header" | "body" | "function" | "default";
1433
+ /** The header or body path used (if applicable) */
1434
+ sourcePath?: string;
1435
+ /** URL being requested */
1436
+ url: string;
1437
+ /** HTTP method of the request */
1438
+ method: string;
1439
+ /** Timestamp when the wait started */
1440
+ timestamp: number;
1441
+ }
1442
+ /**
1443
+ * Hook called when rate limit wait occurs
1444
+ * Informational only - cannot abort the wait
1445
+ * Use for logging, monitoring, alerting
1446
+ */
1447
+ export type OnRateLimitWaitHook = (event: RateLimitWaitEvent, config: RezoConfig) => void | Promise<void>;
1419
1448
  /**
1420
1449
  * Hook called before a proxy is selected
1421
1450
  * Can return a specific proxy to override selection
@@ -1496,6 +1525,7 @@ export interface RezoHooks {
1496
1525
  onTls: OnTlsHook[];
1497
1526
  onTimeout: OnTimeoutHook[];
1498
1527
  onAbort: OnAbortHook[];
1528
+ onRateLimitWait: OnRateLimitWaitHook[];
1499
1529
  }
1500
1530
  /**
1501
1531
  * Create empty hooks object with all arrays initialized
@@ -2426,6 +2456,91 @@ export interface RezoRequestConfig<D = any> {
2426
2456
  /** Weather to stop or continue retry when certain condition is met*/
2427
2457
  condition?: (error: RezoError) => boolean | Promise<boolean>;
2428
2458
  };
2459
+ /**
2460
+ * Rate limit wait configuration - wait and retry when receiving rate limit responses.
2461
+ *
2462
+ * This feature runs BEFORE the retry system. When a rate-limiting status code is received,
2463
+ * the client will wait for the specified time and automatically retry the request.
2464
+ *
2465
+ * **Basic Usage:**
2466
+ * - `waitOnStatus: true` - Enable waiting on 429 status (default behavior)
2467
+ * - `waitOnStatus: [429, 503]` - Enable waiting on specific status codes
2468
+ *
2469
+ * **Wait Time Sources:**
2470
+ * - `'retry-after'` - Use standard Retry-After header (default)
2471
+ * - `{ header: 'X-RateLimit-Reset' }` - Use custom header
2472
+ * - `{ body: 'retry_after' }` - Extract from JSON response body
2473
+ * - Custom function for complex logic
2474
+ *
2475
+ * @example
2476
+ * ```typescript
2477
+ * // Wait on 429 using Retry-After header
2478
+ * await rezo.get(url, { waitOnStatus: true });
2479
+ *
2480
+ * // Wait on 429 using custom header
2481
+ * await rezo.get(url, {
2482
+ * waitOnStatus: true,
2483
+ * waitTimeSource: { header: 'X-RateLimit-Reset' }
2484
+ * });
2485
+ *
2486
+ * // Wait on 429 extracting time from JSON body
2487
+ * await rezo.get(url, {
2488
+ * waitOnStatus: true,
2489
+ * waitTimeSource: { body: 'data.retry_after' }
2490
+ * });
2491
+ *
2492
+ * // Custom function for complex APIs
2493
+ * await rezo.get(url, {
2494
+ * waitOnStatus: [429, 503],
2495
+ * waitTimeSource: (response) => {
2496
+ * const reset = response.headers.get('x-ratelimit-reset');
2497
+ * return reset ? parseInt(reset) - Math.floor(Date.now() / 1000) : null;
2498
+ * }
2499
+ * });
2500
+ * ```
2501
+ */
2502
+ waitOnStatus?: boolean | number[];
2503
+ /**
2504
+ * Where to extract the wait time from when rate-limited.
2505
+ *
2506
+ * - `'retry-after'` - Standard Retry-After header (default)
2507
+ * - `{ header: string }` - Custom header name (e.g., 'X-RateLimit-Reset')
2508
+ * - `{ body: string }` - JSON path in response body (e.g., 'data.retry_after', 'wait_seconds')
2509
+ * - Function - Custom logic receiving the response, return seconds to wait or null
2510
+ *
2511
+ * @default 'retry-after'
2512
+ */
2513
+ waitTimeSource?: "retry-after" | {
2514
+ header: string;
2515
+ } | {
2516
+ body: string;
2517
+ } | ((response: {
2518
+ status: number;
2519
+ headers: RezoHeaders;
2520
+ data?: any;
2521
+ }) => number | null);
2522
+ /**
2523
+ * Maximum time to wait for rate limit in milliseconds.
2524
+ * If the extracted wait time exceeds this, the request will fail instead of waiting.
2525
+ * Set to 0 for unlimited wait time.
2526
+ *
2527
+ * @default 60000 (60 seconds)
2528
+ */
2529
+ maxWaitTime?: number;
2530
+ /**
2531
+ * Default wait time in milliseconds if the wait time source returns nothing.
2532
+ * Used as fallback when Retry-After header or body path is not present.
2533
+ *
2534
+ * @default 1000 (1 second)
2535
+ */
2536
+ defaultWaitTime?: number;
2537
+ /**
2538
+ * Maximum number of wait attempts before giving up.
2539
+ * After this many waits, the request will proceed to retry logic or fail.
2540
+ *
2541
+ * @default 3
2542
+ */
2543
+ maxWaitAttempts?: number;
2429
2544
  /** Whether to use a secure context for HTTPS requests */
2430
2545
  useSecureContext?: boolean;
2431
2546
  /** Custom secure context for TLS connections */
@@ -1,9 +1,9 @@
1
- const { Agent, HttpProxyAgent, HttpsProxyAgent, SocksProxyAgent } = require('../internal/agents.cjs');
1
+ const { Agent, HttpProxyAgent, HttpsProxyAgent, SocksProxyAgent } = require('../internal/agents/index.cjs');
2
2
  const { parseProxyString } = require('./parse.cjs');
3
- const _mod_ecqdmn = require('./manager.cjs');
4
- exports.ProxyManager = _mod_ecqdmn.ProxyManager;;
5
- const _mod_4x1jdb = require('./parse.cjs');
6
- exports.parseProxyString = _mod_4x1jdb.parseProxyString;;
3
+ const _mod_0wfzka = require('./manager.cjs');
4
+ exports.ProxyManager = _mod_0wfzka.ProxyManager;;
5
+ const _mod_bwzrrk = require('./parse.cjs');
6
+ exports.parseProxyString = _mod_bwzrrk.parseProxyString;;
7
7
  function createOptions(uri, opts) {
8
8
  if (uri instanceof URL || typeof uri === "string") {
9
9
  return {
@@ -3,7 +3,7 @@ import {
3
3
  HttpProxyAgent,
4
4
  HttpsProxyAgent,
5
5
  SocksProxyAgent
6
- } from '../internal/agents.js';
6
+ } from '../internal/agents/index.js';
7
7
  import { parseProxyString } from './parse.js';
8
8
  export { ProxyManager } from './manager.js';
9
9
  export { parseProxyString } from './parse.js';
@@ -1,8 +1,8 @@
1
- const _mod_hijcy5 = require('./queue.cjs');
2
- exports.RezoQueue = _mod_hijcy5.RezoQueue;;
3
- const _mod_ccb3p2 = require('./http-queue.cjs');
4
- exports.HttpQueue = _mod_ccb3p2.HttpQueue;
5
- exports.extractDomain = _mod_ccb3p2.extractDomain;;
6
- const _mod_h69bcv = require('./types.cjs');
7
- exports.Priority = _mod_h69bcv.Priority;
8
- exports.HttpMethodPriority = _mod_h69bcv.HttpMethodPriority;;
1
+ const _mod_cfqi4l = require('./queue.cjs');
2
+ exports.RezoQueue = _mod_cfqi4l.RezoQueue;;
3
+ const _mod_9m2if8 = require('./http-queue.cjs');
4
+ exports.HttpQueue = _mod_9m2if8.HttpQueue;
5
+ exports.extractDomain = _mod_9m2if8.extractDomain;;
6
+ const _mod_w9of0o = require('./types.cjs');
7
+ exports.Priority = _mod_w9of0o.Priority;
8
+ exports.HttpMethodPriority = _mod_w9of0o.HttpMethodPriority;;
@@ -1,11 +1,11 @@
1
- const _mod_gfdadc = require('./event-emitter.cjs');
2
- exports.UniversalEventEmitter = _mod_gfdadc.UniversalEventEmitter;;
3
- const _mod_9z6wit = require('./stream.cjs');
4
- exports.UniversalStreamResponse = _mod_9z6wit.UniversalStreamResponse;
5
- exports.StreamResponse = _mod_9z6wit.StreamResponse;;
6
- const _mod_ybfqy6 = require('./download.cjs');
7
- exports.UniversalDownloadResponse = _mod_ybfqy6.UniversalDownloadResponse;
8
- exports.DownloadResponse = _mod_ybfqy6.DownloadResponse;;
9
- const _mod_48lipr = require('./upload.cjs');
10
- exports.UniversalUploadResponse = _mod_48lipr.UniversalUploadResponse;
11
- exports.UploadResponse = _mod_48lipr.UploadResponse;;
1
+ const _mod_rxkza8 = require('./event-emitter.cjs');
2
+ exports.UniversalEventEmitter = _mod_rxkza8.UniversalEventEmitter;;
3
+ const _mod_gre5wb = require('./stream.cjs');
4
+ exports.UniversalStreamResponse = _mod_gre5wb.UniversalStreamResponse;
5
+ exports.StreamResponse = _mod_gre5wb.StreamResponse;;
6
+ const _mod_xea59w = require('./download.cjs');
7
+ exports.UniversalDownloadResponse = _mod_xea59w.UniversalDownloadResponse;
8
+ exports.DownloadResponse = _mod_xea59w.DownloadResponse;;
9
+ const _mod_1q9fpp = require('./upload.cjs');
10
+ exports.UniversalUploadResponse = _mod_1q9fpp.UniversalUploadResponse;
11
+ exports.UploadResponse = _mod_1q9fpp.UploadResponse;;