rezo 1.0.4 → 1.0.6

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 (47) hide show
  1. package/README.md +352 -9
  2. package/dist/adapters/curl.cjs +796 -0
  3. package/dist/adapters/curl.js +796 -0
  4. package/dist/adapters/entries/curl.d.ts +2332 -20
  5. package/dist/adapters/entries/fetch.d.ts +289 -20
  6. package/dist/adapters/entries/http.d.ts +289 -20
  7. package/dist/adapters/entries/http2.d.ts +289 -20
  8. package/dist/adapters/entries/react-native.d.ts +289 -20
  9. package/dist/adapters/entries/xhr.d.ts +289 -20
  10. package/dist/adapters/index.cjs +6 -6
  11. package/dist/adapters/picker.cjs +2 -2
  12. package/dist/adapters/picker.js +2 -2
  13. package/dist/cache/index.cjs +13 -13
  14. package/dist/core/rezo.cjs +2 -2
  15. package/dist/core/rezo.js +2 -2
  16. package/dist/crawler.d.ts +291 -22
  17. package/dist/entries/crawler.cjs +5 -5
  18. package/dist/index.cjs +23 -18
  19. package/dist/index.d.ts +556 -20
  20. package/dist/index.js +1 -0
  21. package/dist/platform/browser.d.ts +289 -20
  22. package/dist/platform/bun.d.ts +289 -20
  23. package/dist/platform/deno.d.ts +289 -20
  24. package/dist/platform/node.d.ts +289 -20
  25. package/dist/platform/react-native.d.ts +289 -20
  26. package/dist/platform/worker.d.ts +289 -20
  27. package/dist/plugin/crawler-options.cjs +1 -1
  28. package/dist/plugin/crawler-options.js +1 -1
  29. package/dist/plugin/crawler.cjs +2 -2
  30. package/dist/plugin/crawler.js +2 -2
  31. package/dist/plugin/index.cjs +36 -36
  32. package/dist/proxy/index.cjs +2 -2
  33. package/dist/proxy/manager.cjs +14 -1
  34. package/dist/proxy/manager.js +14 -1
  35. package/dist/queue/http-queue.cjs +313 -0
  36. package/dist/queue/http-queue.js +312 -0
  37. package/dist/queue/index.cjs +8 -0
  38. package/dist/queue/index.js +6 -0
  39. package/dist/queue/queue.cjs +346 -0
  40. package/dist/queue/queue.js +344 -0
  41. package/dist/queue/types.cjs +17 -0
  42. package/dist/queue/types.js +17 -0
  43. package/dist/types/curl-options.cjs +25 -0
  44. package/dist/types/curl-options.js +25 -0
  45. package/dist/utils/http-config.cjs +0 -15
  46. package/dist/utils/http-config.js +0 -15
  47. package/package.json +1 -2
package/dist/crawler.d.ts CHANGED
@@ -6,9 +6,6 @@ import { Agent as HttpsAgent } from 'node:https';
6
6
  import { Socket } from 'node:net';
7
7
  import { Readable, Writable, WritableOptions } from 'node:stream';
8
8
  import { SecureContext, TLSSocket } from 'node:tls';
9
- import PQueue from 'p-queue';
10
- import { Options as Options$1, QueueAddOptions } from 'p-queue';
11
- import PriorityQueue from 'p-queue/dist/priority-queue';
12
9
  import { Cookie as TouchCookie, CookieJar as TouchCookieJar, CreateCookieOptions } from 'tough-cookie';
13
10
 
14
11
  /**
@@ -1195,8 +1192,17 @@ export interface ProxyCooldownConfig {
1195
1192
  * Complete configuration for proxy rotation, filtering, and failure handling
1196
1193
  */
1197
1194
  export interface ProxyManagerBaseConfig {
1198
- /** Array of proxies to manage */
1199
- proxies: ProxyInfo[];
1195
+ /**
1196
+ * Array of proxies to manage
1197
+ * Accepts ProxyInfo objects or proxy URL strings (parsed via parseProxyString)
1198
+ * @example
1199
+ * proxies: [
1200
+ * { protocol: 'http', host: '127.0.0.1', port: 8080 },
1201
+ * 'socks5://user:pass@proxy.example.com:1080',
1202
+ * 'http://proxy.example.com:3128'
1203
+ * ]
1204
+ */
1205
+ proxies: (ProxyInfo | string)[];
1200
1206
  /**
1201
1207
  * Whitelist patterns for URLs that should use proxy
1202
1208
  * - String: exact domain match (e.g., 'api.example.com') or subdomain match (e.g., 'example.com' matches '*.example.com')
@@ -2146,6 +2152,275 @@ declare class RezoError<T = any> extends Error {
2146
2152
  toString(): string;
2147
2153
  getFullDetails(): string;
2148
2154
  }
2155
+ /**
2156
+ * Queue configuration options
2157
+ */
2158
+ export interface QueueConfig {
2159
+ /** Maximum concurrent tasks (default: Infinity) */
2160
+ concurrency?: number;
2161
+ /** Auto-start processing when tasks are added (default: true) */
2162
+ autoStart?: boolean;
2163
+ /** Timeout per task in milliseconds (default: none) */
2164
+ timeout?: number;
2165
+ /** Throw on timeout vs silently fail (default: true) */
2166
+ throwOnTimeout?: boolean;
2167
+ /** Interval between task starts in ms for rate limiting */
2168
+ interval?: number;
2169
+ /** Max tasks to start per interval (default: Infinity) */
2170
+ intervalCap?: number;
2171
+ /** Carry over unused interval capacity to next interval */
2172
+ carryoverConcurrencyCount?: boolean;
2173
+ }
2174
+ /**
2175
+ * Task options when adding to queue
2176
+ */
2177
+ export interface TaskOptions {
2178
+ /** Task priority (higher runs first, default: 0) */
2179
+ priority?: number;
2180
+ /** Task-specific timeout (overrides queue default) */
2181
+ timeout?: number;
2182
+ /** Unique ID for tracking/cancellation */
2183
+ id?: string;
2184
+ /** Signal for external cancellation */
2185
+ signal?: AbortSignal;
2186
+ }
2187
+ /**
2188
+ * Current queue state
2189
+ */
2190
+ export interface QueueState {
2191
+ /** Number of tasks currently running */
2192
+ pending: number;
2193
+ /** Number of tasks waiting in queue */
2194
+ size: number;
2195
+ /** Total tasks (pending + size) */
2196
+ total: number;
2197
+ /** Is queue paused */
2198
+ isPaused: boolean;
2199
+ /** Is queue idle (no tasks) */
2200
+ isIdle: boolean;
2201
+ }
2202
+ /**
2203
+ * Queue statistics
2204
+ */
2205
+ export interface QueueStats {
2206
+ /** Total tasks added since creation */
2207
+ added: number;
2208
+ /** Total tasks processed (started) */
2209
+ processed: number;
2210
+ /** Total successful completions */
2211
+ completed: number;
2212
+ /** Total failures */
2213
+ failed: number;
2214
+ /** Total timeouts */
2215
+ timedOut: number;
2216
+ /** Total cancellations */
2217
+ cancelled: number;
2218
+ /** Average task duration (ms) */
2219
+ averageDuration: number;
2220
+ /** Tasks per second (rolling average) */
2221
+ throughput: number;
2222
+ }
2223
+ /**
2224
+ * Queue event types
2225
+ */
2226
+ export interface QueueEvents {
2227
+ /** Task added to queue */
2228
+ add: {
2229
+ id: string;
2230
+ priority: number;
2231
+ };
2232
+ /** Task started executing */
2233
+ start: {
2234
+ id: string;
2235
+ };
2236
+ /** Task completed successfully */
2237
+ completed: {
2238
+ id: string;
2239
+ result: any;
2240
+ duration: number;
2241
+ };
2242
+ /** Task failed with error */
2243
+ error: {
2244
+ id: string;
2245
+ error: Error;
2246
+ };
2247
+ /** Task timed out */
2248
+ timeout: {
2249
+ id: string;
2250
+ };
2251
+ /** Task cancelled */
2252
+ cancelled: {
2253
+ id: string;
2254
+ };
2255
+ /** Queue became active (was idle, now processing) */
2256
+ active: undefined;
2257
+ /** Queue became idle (all tasks done) */
2258
+ idle: undefined;
2259
+ /** Queue was paused */
2260
+ paused: undefined;
2261
+ /** Queue was resumed */
2262
+ resumed: undefined;
2263
+ /** Next task about to run */
2264
+ next: undefined;
2265
+ /** Queue was emptied (no pending tasks) */
2266
+ empty: undefined;
2267
+ }
2268
+ /**
2269
+ * Event handler type
2270
+ */
2271
+ export type EventHandler<T> = (data: T) => void;
2272
+ /**
2273
+ * Task function type
2274
+ */
2275
+ export type TaskFunction<T> = () => Promise<T>;
2276
+ declare class RezoQueue<T = any> {
2277
+ private queue;
2278
+ private pendingCount;
2279
+ private isPausedFlag;
2280
+ private intervalId?;
2281
+ private intervalCount;
2282
+ private intervalStart;
2283
+ private eventHandlers;
2284
+ private statsData;
2285
+ private totalDuration;
2286
+ private throughputWindow;
2287
+ private readonly throughputWindowSize;
2288
+ private idlePromise?;
2289
+ private emptyPromise?;
2290
+ readonly config: Required<QueueConfig>;
2291
+ /**
2292
+ * Create a new RezoQueue
2293
+ * @param config - Queue configuration options
2294
+ */
2295
+ constructor(config?: QueueConfig);
2296
+ /**
2297
+ * Get current queue state
2298
+ */
2299
+ get state(): QueueState;
2300
+ /**
2301
+ * Get queue statistics
2302
+ */
2303
+ get stats(): QueueStats;
2304
+ /**
2305
+ * Get/set concurrency limit
2306
+ */
2307
+ get concurrency(): number;
2308
+ set concurrency(value: number);
2309
+ /**
2310
+ * Number of pending (running) tasks
2311
+ */
2312
+ get pending(): number;
2313
+ /**
2314
+ * Number of tasks waiting in queue
2315
+ */
2316
+ get size(): number;
2317
+ /**
2318
+ * Check if queue is paused
2319
+ */
2320
+ get isPaused(): boolean;
2321
+ /**
2322
+ * Add a task to the queue
2323
+ * @param fn - Async function to execute
2324
+ * @param options - Task options
2325
+ * @returns Promise resolving to task result
2326
+ */
2327
+ add<R = T>(fn: TaskFunction<R>, options?: TaskOptions): Promise<R>;
2328
+ /**
2329
+ * Add multiple tasks to the queue
2330
+ * @param fns - Array of async functions
2331
+ * @param options - Task options (applied to all)
2332
+ * @returns Promise resolving to array of results
2333
+ */
2334
+ addAll<R = T>(fns: TaskFunction<R>[], options?: TaskOptions): Promise<R[]>;
2335
+ /**
2336
+ * Pause queue processing (running tasks continue)
2337
+ */
2338
+ pause(): void;
2339
+ /**
2340
+ * Resume queue processing
2341
+ */
2342
+ start(): void;
2343
+ /**
2344
+ * Clear all pending tasks from queue
2345
+ */
2346
+ clear(): void;
2347
+ /**
2348
+ * Cancel a specific task by ID
2349
+ * @param id - Task ID to cancel
2350
+ * @returns true if task was found and cancelled
2351
+ */
2352
+ cancel(id: string): boolean;
2353
+ /**
2354
+ * Cancel all tasks matching a predicate
2355
+ * @param predicate - Function to test each task
2356
+ * @returns Number of tasks cancelled
2357
+ */
2358
+ cancelBy(predicate: (task: {
2359
+ id: string;
2360
+ priority: number;
2361
+ }) => boolean): number;
2362
+ /**
2363
+ * Wait for queue to become idle (no running or pending tasks)
2364
+ */
2365
+ onIdle(): Promise<void>;
2366
+ /**
2367
+ * Wait for queue to be empty (no pending tasks, but may have running)
2368
+ */
2369
+ onEmpty(): Promise<void>;
2370
+ /**
2371
+ * Wait for queue size to be less than limit
2372
+ * @param limit - Size threshold
2373
+ */
2374
+ onSizeLessThan(limit: number): Promise<void>;
2375
+ /**
2376
+ * Register an event handler
2377
+ * @param event - Event name
2378
+ * @param handler - Handler function
2379
+ */
2380
+ on<E extends keyof QueueEvents>(event: E, handler: EventHandler<QueueEvents[E]>): void;
2381
+ /**
2382
+ * Remove an event handler
2383
+ * @param event - Event name
2384
+ * @param handler - Handler function to remove
2385
+ */
2386
+ off<E extends keyof QueueEvents>(event: E, handler: EventHandler<QueueEvents[E]>): void;
2387
+ /**
2388
+ * Destroy the queue and cleanup resources
2389
+ */
2390
+ destroy(): void;
2391
+ /**
2392
+ * Insert task into queue maintaining priority order (highest first)
2393
+ */
2394
+ private insertByPriority;
2395
+ /**
2396
+ * Try to run next task if capacity available
2397
+ */
2398
+ private tryRunNext;
2399
+ /**
2400
+ * Execute a task
2401
+ */
2402
+ private runTask;
2403
+ /**
2404
+ * Record task duration for statistics
2405
+ */
2406
+ private recordDuration;
2407
+ /**
2408
+ * Start interval-based rate limiting
2409
+ */
2410
+ private startInterval;
2411
+ /**
2412
+ * Emit an event
2413
+ */
2414
+ protected emit<E extends keyof QueueEvents>(event: E, data: QueueEvents[E]): void;
2415
+ /**
2416
+ * Check if queue became empty
2417
+ */
2418
+ private checkEmpty;
2419
+ /**
2420
+ * Check if queue became idle
2421
+ */
2422
+ private checkIdle;
2423
+ }
2149
2424
  type ProxyProtocol$1 = "http" | "https" | "socks4" | "socks5";
2150
2425
  /**
2151
2426
  * Configuration options for proxy connections
@@ -2222,7 +2497,7 @@ export interface RezoRequestConfig<D = any> {
2222
2497
  /**
2223
2498
  * Queue to use for request execution
2224
2499
  */
2225
- queue?: PQueue | null;
2500
+ queue?: RezoQueue | null;
2226
2501
  /**
2227
2502
  * Controls how the response body is parsed and returned in `response.data`.
2228
2503
  *
@@ -2312,10 +2587,6 @@ export interface RezoRequestConfig<D = any> {
2312
2587
  autoSetOrigin?: boolean;
2313
2588
  treat302As303?: boolean;
2314
2589
  startNewRequest?: boolean;
2315
- /** Whether to use HTTP/2 protocol */
2316
- http2?: boolean;
2317
- /** Whether to use cURL adapter */
2318
- curl?: boolean;
2319
2590
  /**
2320
2591
  * DNS cache configuration for faster repeated requests.
2321
2592
  *
@@ -2419,6 +2690,12 @@ export interface RezoRequestConfig<D = any> {
2419
2690
  withCredentials?: boolean;
2420
2691
  /** Proxy configuration (URL string or detailed options) */
2421
2692
  proxy?: string | ProxyOptions;
2693
+ /**
2694
+ * Whether to use ProxyManager for this request
2695
+ * Set to false to bypass ProxyManager even when one is configured
2696
+ * @default true (uses ProxyManager if configured)
2697
+ */
2698
+ useProxyManager?: boolean;
2422
2699
  /** Whether to enable automatic cookie handling */
2423
2700
  useCookies?: boolean;
2424
2701
  /** Custom cookie jar for managing cookies */
@@ -2440,8 +2717,6 @@ export interface RezoRequestConfig<D = any> {
2440
2717
  transformRequest?: Array<(data: any, headers: RezoHeaders) => any>;
2441
2718
  /** Array of functions to transform response data */
2442
2719
  transformResponse?: Array<(data: any) => any>;
2443
- /** Adapter to use for the request (name or custom function) */
2444
- adapter?: string | ((config: RezoRequestConfig) => Promise<any>);
2445
2720
  /** AbortSignal to cancel the request */
2446
2721
  signal?: AbortSignal;
2447
2722
  /** File path to save the response to (for downloads) */
@@ -2806,7 +3081,7 @@ declare class ProxyManager {
2806
3081
  private runAfterProxyDisableHooks;
2807
3082
  private runAfterProxyEnableHooks;
2808
3083
  }
2809
- export type queueOptions = Options$1<PriorityQueue, QueueAddOptions>;
3084
+ export type queueOptions = QueueConfig;
2810
3085
  export interface CacheConfig {
2811
3086
  /** Response cache configuration */
2812
3087
  response?: boolean | ResponseCacheConfig;
@@ -2865,10 +3140,6 @@ export interface RezoDefaultOptions {
2865
3140
  keepAlive?: boolean;
2866
3141
  /** Whether to detect and prevent redirect cycles */
2867
3142
  enableRedirectCycleDetection?: boolean;
2868
- /** Whether to use HTTP/2 protocol */
2869
- http2?: boolean;
2870
- /** Whether to use cURL adapter */
2871
- curl?: boolean;
2872
3143
  /** Whether to send cookies and authorization headers with cross-origin requests */
2873
3144
  withCredentials?: boolean;
2874
3145
  /** Proxy configuration (URL string or detailed options) */
@@ -2907,8 +3178,6 @@ export interface RezoDefaultOptions {
2907
3178
  transformRequest?: RezoHttpRequest["transformRequest"];
2908
3179
  /** Array of functions to transform response data */
2909
3180
  transformResponse?: RezoHttpRequest["transformResponse"];
2910
- /** Adapter to use for the request (name or custom function) */
2911
- adapter?: RezoHttpRequest["adapter"];
2912
3181
  /** Browser simulation configuration for user agent spoofing */
2913
3182
  browser?: RezoHttpRequest["browser"];
2914
3183
  /** Enable debug logging for the request */
@@ -3808,7 +4077,7 @@ export interface httpAdapterPutOverloads {
3808
4077
  */
3809
4078
  export type AdapterFunction<T = any> = (options: RezoRequestConfig, defaultOptions: RezoDefaultOptions, jar: RezoCookieJar) => Promise<RezoResponse<T> | RezoStreamResponse | RezoDownloadResponse | RezoUploadResponse>;
3810
4079
  declare class Rezo {
3811
- protected queue: PQueue | null;
4080
+ protected queue: RezoQueue | null;
3812
4081
  protected isQueueEnabled: boolean;
3813
4082
  defaults: RezoDefaultOptions;
3814
4083
  hooks: RezoHooks;
@@ -6041,7 +6310,7 @@ export declare class CrawlerOptions {
6041
6310
  /**
6042
6311
  * Internal method to process and add rate limiter configurations
6043
6312
  * @param options - Limiter configuration object with enable flag and queue options
6044
- * @description Validates and stores rate limiter configurations, creating PQueue instances
6313
+ * @description Validates and stores rate limiter configurations, creating RezoQueue instances
6045
6314
  * for each valid configuration. Supports domain-specific or global rate limiting.
6046
6315
  * @private
6047
6316
  */
@@ -6205,7 +6474,7 @@ export declare class CrawlerOptions {
6205
6474
  * ```
6206
6475
  */
6207
6476
  getAdapter(url: string, type: "proxies", useGlobal?: boolean, random?: boolean): IProxy | null;
6208
- getAdapter(url: string, type: "limiters", useGlobal?: boolean, random?: boolean): PQueue | null;
6477
+ getAdapter(url: string, type: "limiters", useGlobal?: boolean, random?: boolean): RezoQueue | null;
6209
6478
  getAdapter(url: string, type: "oxylabs", useGlobal?: boolean, random?: boolean): Oxylabs | null;
6210
6479
  getAdapter(url: string, type: "decodo", useGlobal?: boolean, random?: boolean): Decodo | null;
6211
6480
  getAdapter(url: string, type: "headers", useGlobal?: boolean, random?: boolean): OutgoingHttpHeaders | null;
@@ -1,5 +1,5 @@
1
- const _mod_9syr2y = require('../plugin/crawler.cjs');
2
- exports.Crawler = _mod_9syr2y.Crawler;;
3
- const _mod_xywryj = require('../plugin/crawler-options.cjs');
4
- exports.CrawlerOptions = _mod_xywryj.CrawlerOptions;
5
- exports.Domain = _mod_xywryj.Domain;;
1
+ const _mod_8o6t31 = require('../plugin/crawler.cjs');
2
+ exports.Crawler = _mod_8o6t31.Crawler;;
3
+ const _mod_a2uxv0 = require('../plugin/crawler-options.cjs');
4
+ exports.CrawlerOptions = _mod_a2uxv0.CrawlerOptions;
5
+ exports.Domain = _mod_a2uxv0.Domain;;
package/dist/index.cjs CHANGED
@@ -1,21 +1,26 @@
1
- const _mod_li4oo6 = require('./core/rezo.cjs');
2
- exports.Rezo = _mod_li4oo6.Rezo;
3
- exports.createRezoInstance = _mod_li4oo6.createRezoInstance;
4
- exports.createDefaultInstance = _mod_li4oo6.createDefaultInstance;;
5
- const _mod_g7vumm = require('./errors/rezo-error.cjs');
6
- exports.RezoError = _mod_g7vumm.RezoError;
7
- exports.RezoErrorCode = _mod_g7vumm.RezoErrorCode;;
8
- const _mod_lcvlqo = require('./utils/headers.cjs');
9
- exports.RezoHeaders = _mod_lcvlqo.RezoHeaders;;
10
- const _mod_vdm8pb = require('./utils/form-data.cjs');
11
- exports.RezoFormData = _mod_vdm8pb.RezoFormData;;
12
- const _mod_zocq9d = require('./utils/cookies.cjs');
13
- exports.RezoCookieJar = _mod_zocq9d.RezoCookieJar;;
14
- const _mod_uxqfdf = require('./core/hooks.cjs');
15
- exports.createDefaultHooks = _mod_uxqfdf.createDefaultHooks;
16
- exports.mergeHooks = _mod_uxqfdf.mergeHooks;;
17
- const _mod_ztg1xc = require('./proxy/manager.cjs');
18
- exports.ProxyManager = _mod_ztg1xc.ProxyManager;;
1
+ const _mod_b7ju2q = require('./core/rezo.cjs');
2
+ exports.Rezo = _mod_b7ju2q.Rezo;
3
+ exports.createRezoInstance = _mod_b7ju2q.createRezoInstance;
4
+ exports.createDefaultInstance = _mod_b7ju2q.createDefaultInstance;;
5
+ const _mod_cnsb78 = require('./errors/rezo-error.cjs');
6
+ exports.RezoError = _mod_cnsb78.RezoError;
7
+ exports.RezoErrorCode = _mod_cnsb78.RezoErrorCode;;
8
+ const _mod_skuirr = require('./utils/headers.cjs');
9
+ exports.RezoHeaders = _mod_skuirr.RezoHeaders;;
10
+ const _mod_57nl1j = require('./utils/form-data.cjs');
11
+ exports.RezoFormData = _mod_57nl1j.RezoFormData;;
12
+ const _mod_ue7zge = require('./utils/cookies.cjs');
13
+ exports.RezoCookieJar = _mod_ue7zge.RezoCookieJar;;
14
+ const _mod_lm33u8 = require('./core/hooks.cjs');
15
+ exports.createDefaultHooks = _mod_lm33u8.createDefaultHooks;
16
+ exports.mergeHooks = _mod_lm33u8.mergeHooks;;
17
+ const _mod_biuxmx = require('./proxy/manager.cjs');
18
+ exports.ProxyManager = _mod_biuxmx.ProxyManager;;
19
+ const _mod_aekrq7 = require('./queue/index.cjs');
20
+ exports.RezoQueue = _mod_aekrq7.RezoQueue;
21
+ exports.HttpQueue = _mod_aekrq7.HttpQueue;
22
+ exports.Priority = _mod_aekrq7.Priority;
23
+ exports.HttpMethodPriority = _mod_aekrq7.HttpMethodPriority;;
19
24
  const { RezoError } = require('./errors/rezo-error.cjs');
20
25
  const isRezoError = exports.isRezoError = RezoError.isRezoError;
21
26
  const Cancel = exports.Cancel = RezoError;