rezo 1.0.10 → 1.0.12

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.
@@ -2502,8 +2502,73 @@ export interface RezoRequestConfig<D = any> {
2502
2502
  maxRedirects?: number;
2503
2503
  /** Whether to automatically decompress response data */
2504
2504
  decompress?: boolean;
2505
- /** Whether to keep the connection alive for reuse */
2505
+ /**
2506
+ * Whether to keep TCP connections alive for reuse across multiple requests.
2507
+ *
2508
+ * When enabled, the underlying TCP connection is kept open after a request completes,
2509
+ * allowing subsequent requests to the same host to reuse the connection. This reduces
2510
+ * latency by avoiding the overhead of establishing new connections (TCP handshake,
2511
+ * TLS negotiation for HTTPS).
2512
+ *
2513
+ * **Behavior:**
2514
+ * - `false` (default) - Connection closes after each request. Process exits immediately.
2515
+ * - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
2516
+ *
2517
+ * **When to use `keepAlive: true`:**
2518
+ * - Making multiple requests to the same host in sequence
2519
+ * - Long-running applications (servers, bots, scrapers)
2520
+ * - Performance-critical applications where connection overhead matters
2521
+ *
2522
+ * **When to use `keepAlive: false` (default):**
2523
+ * - Single requests or scripts that should exit immediately
2524
+ * - CLI tools that make one-off requests
2525
+ * - When you need predictable process termination
2526
+ *
2527
+ * @example
2528
+ * ```typescript
2529
+ * // Default: process exits immediately after request
2530
+ * const { data } = await rezo.get('https://api.example.com/data');
2531
+ *
2532
+ * // Keep connection alive for 1 minute (default) for subsequent requests
2533
+ * const client = new Rezo({ keepAlive: true });
2534
+ * await client.get('https://api.example.com/users');
2535
+ * await client.get('https://api.example.com/posts'); // Reuses connection
2536
+ *
2537
+ * // Custom keep-alive timeout (30 seconds)
2538
+ * const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
2539
+ * ```
2540
+ *
2541
+ * @default false
2542
+ */
2506
2543
  keepAlive?: boolean;
2544
+ /**
2545
+ * How long to keep idle connections alive in milliseconds.
2546
+ *
2547
+ * Only applies when `keepAlive: true`. After this duration of inactivity,
2548
+ * the connection is closed automatically. This prevents resource leaks
2549
+ * from connections that are no longer needed.
2550
+ *
2551
+ * **Note:** Even with keep-alive enabled, the Node.js process can still exit
2552
+ * cleanly when there's no other work to do, thanks to socket unreferencing.
2553
+ *
2554
+ * @example
2555
+ * ```typescript
2556
+ * // Keep connections alive for 30 seconds
2557
+ * const client = new Rezo({
2558
+ * keepAlive: true,
2559
+ * keepAliveMsecs: 30000
2560
+ * });
2561
+ *
2562
+ * // Keep connections alive for 2 minutes
2563
+ * const client = new Rezo({
2564
+ * keepAlive: true,
2565
+ * keepAliveMsecs: 120000
2566
+ * });
2567
+ * ```
2568
+ *
2569
+ * @default 60000 (1 minute)
2570
+ */
2571
+ keepAliveMsecs?: number;
2507
2572
  withoutBodyOnRedirect?: boolean;
2508
2573
  autoSetReferer?: boolean;
2509
2574
  autoSetOrigin?: boolean;
@@ -4104,6 +4169,7 @@ export declare class Rezo {
4104
4169
  private __create;
4105
4170
  /** Get the cookie jar for this instance */
4106
4171
  get cookieJar(): RezoCookieJar;
4172
+ set cookieJar(jar: RezoCookieJar);
4107
4173
  /**
4108
4174
  * Save cookies to file (if cookieFile is configured).
4109
4175
  * Can also specify a different path to save to.
@@ -1,36 +1,36 @@
1
- const _mod_cizrxa = require('./crawler.cjs');
2
- exports.Crawler = _mod_cizrxa.Crawler;;
3
- const _mod_7yd7lj = require('./crawler-options.cjs');
4
- exports.CrawlerOptions = _mod_7yd7lj.CrawlerOptions;;
5
- const _mod_d1skng = require('../cache/file-cacher.cjs');
6
- exports.FileCacher = _mod_d1skng.FileCacher;;
7
- const _mod_lxwyvt = require('../cache/url-store.cjs');
8
- exports.UrlStore = _mod_lxwyvt.UrlStore;;
9
- const _mod_09oe6w = require('./addon/oxylabs/index.cjs');
10
- exports.Oxylabs = _mod_09oe6w.Oxylabs;;
11
- const _mod_3wv0s7 = require('./addon/oxylabs/options.cjs');
12
- exports.OXYLABS_BROWSER_TYPES = _mod_3wv0s7.OXYLABS_BROWSER_TYPES;
13
- exports.OXYLABS_COMMON_LOCALES = _mod_3wv0s7.OXYLABS_COMMON_LOCALES;
14
- exports.OXYLABS_COMMON_GEO_LOCATIONS = _mod_3wv0s7.OXYLABS_COMMON_GEO_LOCATIONS;
15
- exports.OXYLABS_US_STATES = _mod_3wv0s7.OXYLABS_US_STATES;
16
- exports.OXYLABS_EUROPEAN_COUNTRIES = _mod_3wv0s7.OXYLABS_EUROPEAN_COUNTRIES;
17
- exports.OXYLABS_ASIAN_COUNTRIES = _mod_3wv0s7.OXYLABS_ASIAN_COUNTRIES;
18
- exports.getRandomOxylabsBrowserType = _mod_3wv0s7.getRandomBrowserType;
19
- exports.getRandomOxylabsLocale = _mod_3wv0s7.getRandomLocale;
20
- exports.getRandomOxylabsGeoLocation = _mod_3wv0s7.getRandomGeoLocation;;
21
- const _mod_vi6kgn = require('./addon/decodo/index.cjs');
22
- exports.Decodo = _mod_vi6kgn.Decodo;;
23
- const _mod_avxi0i = require('./addon/decodo/options.cjs');
24
- exports.DECODO_DEVICE_TYPES = _mod_avxi0i.DECODO_DEVICE_TYPES;
25
- exports.DECODO_HEADLESS_MODES = _mod_avxi0i.DECODO_HEADLESS_MODES;
26
- exports.DECODO_COMMON_LOCALES = _mod_avxi0i.DECODO_COMMON_LOCALES;
27
- exports.DECODO_COMMON_COUNTRIES = _mod_avxi0i.DECODO_COMMON_COUNTRIES;
28
- exports.DECODO_EUROPEAN_COUNTRIES = _mod_avxi0i.DECODO_EUROPEAN_COUNTRIES;
29
- exports.DECODO_ASIAN_COUNTRIES = _mod_avxi0i.DECODO_ASIAN_COUNTRIES;
30
- exports.DECODO_US_STATES = _mod_avxi0i.DECODO_US_STATES;
31
- exports.DECODO_COMMON_CITIES = _mod_avxi0i.DECODO_COMMON_CITIES;
32
- exports.getRandomDecodoDeviceType = _mod_avxi0i.getRandomDeviceType;
33
- exports.getRandomDecodoLocale = _mod_avxi0i.getRandomLocale;
34
- exports.getRandomDecodoCountry = _mod_avxi0i.getRandomCountry;
35
- exports.getRandomDecodoCity = _mod_avxi0i.getRandomCity;
36
- exports.generateDecodoSessionId = _mod_avxi0i.generateSessionId;;
1
+ const _mod_a9kn57 = require('./crawler.cjs');
2
+ exports.Crawler = _mod_a9kn57.Crawler;;
3
+ const _mod_6ccm6s = require('./crawler-options.cjs');
4
+ exports.CrawlerOptions = _mod_6ccm6s.CrawlerOptions;;
5
+ const _mod_7naagm = require('../cache/file-cacher.cjs');
6
+ exports.FileCacher = _mod_7naagm.FileCacher;;
7
+ const _mod_22i2ua = require('../cache/url-store.cjs');
8
+ exports.UrlStore = _mod_22i2ua.UrlStore;;
9
+ const _mod_37jf5t = require('./addon/oxylabs/index.cjs');
10
+ exports.Oxylabs = _mod_37jf5t.Oxylabs;;
11
+ const _mod_u1lbrx = require('./addon/oxylabs/options.cjs');
12
+ exports.OXYLABS_BROWSER_TYPES = _mod_u1lbrx.OXYLABS_BROWSER_TYPES;
13
+ exports.OXYLABS_COMMON_LOCALES = _mod_u1lbrx.OXYLABS_COMMON_LOCALES;
14
+ exports.OXYLABS_COMMON_GEO_LOCATIONS = _mod_u1lbrx.OXYLABS_COMMON_GEO_LOCATIONS;
15
+ exports.OXYLABS_US_STATES = _mod_u1lbrx.OXYLABS_US_STATES;
16
+ exports.OXYLABS_EUROPEAN_COUNTRIES = _mod_u1lbrx.OXYLABS_EUROPEAN_COUNTRIES;
17
+ exports.OXYLABS_ASIAN_COUNTRIES = _mod_u1lbrx.OXYLABS_ASIAN_COUNTRIES;
18
+ exports.getRandomOxylabsBrowserType = _mod_u1lbrx.getRandomBrowserType;
19
+ exports.getRandomOxylabsLocale = _mod_u1lbrx.getRandomLocale;
20
+ exports.getRandomOxylabsGeoLocation = _mod_u1lbrx.getRandomGeoLocation;;
21
+ const _mod_mozpwt = require('./addon/decodo/index.cjs');
22
+ exports.Decodo = _mod_mozpwt.Decodo;;
23
+ const _mod_g6f0a3 = require('./addon/decodo/options.cjs');
24
+ exports.DECODO_DEVICE_TYPES = _mod_g6f0a3.DECODO_DEVICE_TYPES;
25
+ exports.DECODO_HEADLESS_MODES = _mod_g6f0a3.DECODO_HEADLESS_MODES;
26
+ exports.DECODO_COMMON_LOCALES = _mod_g6f0a3.DECODO_COMMON_LOCALES;
27
+ exports.DECODO_COMMON_COUNTRIES = _mod_g6f0a3.DECODO_COMMON_COUNTRIES;
28
+ exports.DECODO_EUROPEAN_COUNTRIES = _mod_g6f0a3.DECODO_EUROPEAN_COUNTRIES;
29
+ exports.DECODO_ASIAN_COUNTRIES = _mod_g6f0a3.DECODO_ASIAN_COUNTRIES;
30
+ exports.DECODO_US_STATES = _mod_g6f0a3.DECODO_US_STATES;
31
+ exports.DECODO_COMMON_CITIES = _mod_g6f0a3.DECODO_COMMON_CITIES;
32
+ exports.getRandomDecodoDeviceType = _mod_g6f0a3.getRandomDeviceType;
33
+ exports.getRandomDecodoLocale = _mod_g6f0a3.getRandomLocale;
34
+ exports.getRandomDecodoCountry = _mod_g6f0a3.getRandomCountry;
35
+ exports.getRandomDecodoCity = _mod_g6f0a3.getRandomCity;
36
+ exports.generateDecodoSessionId = _mod_g6f0a3.generateSessionId;;
@@ -1,8 +1,8 @@
1
1
  const { SocksProxyAgent: RezoSocksProxy } = require("socks-proxy-agent");
2
2
  const { HttpsProxyAgent: RezoHttpsSocks } = require("https-proxy-agent");
3
3
  const { HttpProxyAgent: RezoHttpSocks } = require("http-proxy-agent");
4
- const _mod_l3fp62 = require('./manager.cjs');
5
- exports.ProxyManager = _mod_l3fp62.ProxyManager;;
4
+ const _mod_448ob0 = require('./manager.cjs');
5
+ exports.ProxyManager = _mod_448ob0.ProxyManager;;
6
6
  function createOptions(uri, opts) {
7
7
  if (uri instanceof URL || typeof uri === "string") {
8
8
  return {
@@ -1,8 +1,8 @@
1
- const _mod_yii8q7 = require('./queue.cjs');
2
- exports.RezoQueue = _mod_yii8q7.RezoQueue;;
3
- const _mod_unk7rd = require('./http-queue.cjs');
4
- exports.HttpQueue = _mod_unk7rd.HttpQueue;
5
- exports.extractDomain = _mod_unk7rd.extractDomain;;
6
- const _mod_6fv9eb = require('./types.cjs');
7
- exports.Priority = _mod_6fv9eb.Priority;
8
- exports.HttpMethodPriority = _mod_6fv9eb.HttpMethodPriority;;
1
+ const _mod_ipfe1q = require('./queue.cjs');
2
+ exports.RezoQueue = _mod_ipfe1q.RezoQueue;;
3
+ const _mod_sc99zf = require('./http-queue.cjs');
4
+ exports.HttpQueue = _mod_sc99zf.HttpQueue;
5
+ exports.extractDomain = _mod_sc99zf.extractDomain;;
6
+ const _mod_4akyyt = require('./types.cjs');
7
+ exports.Priority = _mod_4akyyt.Priority;
8
+ exports.HttpMethodPriority = _mod_4akyyt.HttpMethodPriority;;
@@ -297,11 +297,36 @@ function buildResponse(params) {
297
297
  const rezoHeaders = new RezoHeaders(headers);
298
298
  rezoHeaders.delete("set-cookie");
299
299
  let cookieData;
300
+ const mergedCookiesArray = [];
301
+ const cookieKeyDomainMap = new Map;
302
+ if (config.requestCookies && config.requestCookies.length > 0) {
303
+ for (const cookie of config.requestCookies) {
304
+ const key = `${cookie.key}|${cookie.domain || ""}`;
305
+ mergedCookiesArray.push(cookie);
306
+ cookieKeyDomainMap.set(key, mergedCookiesArray.length - 1);
307
+ }
308
+ }
309
+ let responseCookiesArray = [];
300
310
  if (config.responseCookies && config.responseCookies.array && config.responseCookies.array.length > 0) {
301
- cookieData = config.responseCookies;
311
+ responseCookiesArray = config.responseCookies.array;
302
312
  } else if (cookies.length > 0) {
303
- const cookieJar = new RezoCookieJar;
304
- cookieData = cookieJar.setCookiesSync(cookies, url);
313
+ const tempJar = new RezoCookieJar;
314
+ const parsed = tempJar.setCookiesSync(cookies, url);
315
+ responseCookiesArray = parsed.array;
316
+ }
317
+ for (const cookie of responseCookiesArray) {
318
+ const key = `${cookie.key}|${cookie.domain || ""}`;
319
+ const existingIndex = cookieKeyDomainMap.get(key);
320
+ if (existingIndex !== undefined) {
321
+ mergedCookiesArray[existingIndex] = cookie;
322
+ } else {
323
+ mergedCookiesArray.push(cookie);
324
+ cookieKeyDomainMap.set(key, mergedCookiesArray.length - 1);
325
+ }
326
+ }
327
+ if (mergedCookiesArray.length > 0) {
328
+ const mergedJar = new RezoCookieJar(mergedCookiesArray, url);
329
+ cookieData = mergedJar.cookies();
305
330
  } else {
306
331
  cookieData = {
307
332
  array: [],
@@ -297,11 +297,36 @@ export function buildResponse(params) {
297
297
  const rezoHeaders = new RezoHeaders(headers);
298
298
  rezoHeaders.delete("set-cookie");
299
299
  let cookieData;
300
+ const mergedCookiesArray = [];
301
+ const cookieKeyDomainMap = new Map;
302
+ if (config.requestCookies && config.requestCookies.length > 0) {
303
+ for (const cookie of config.requestCookies) {
304
+ const key = `${cookie.key}|${cookie.domain || ""}`;
305
+ mergedCookiesArray.push(cookie);
306
+ cookieKeyDomainMap.set(key, mergedCookiesArray.length - 1);
307
+ }
308
+ }
309
+ let responseCookiesArray = [];
300
310
  if (config.responseCookies && config.responseCookies.array && config.responseCookies.array.length > 0) {
301
- cookieData = config.responseCookies;
311
+ responseCookiesArray = config.responseCookies.array;
302
312
  } else if (cookies.length > 0) {
303
- const cookieJar = new RezoCookieJar;
304
- cookieData = cookieJar.setCookiesSync(cookies, url);
313
+ const tempJar = new RezoCookieJar;
314
+ const parsed = tempJar.setCookiesSync(cookies, url);
315
+ responseCookiesArray = parsed.array;
316
+ }
317
+ for (const cookie of responseCookiesArray) {
318
+ const key = `${cookie.key}|${cookie.domain || ""}`;
319
+ const existingIndex = cookieKeyDomainMap.get(key);
320
+ if (existingIndex !== undefined) {
321
+ mergedCookiesArray[existingIndex] = cookie;
322
+ } else {
323
+ mergedCookiesArray.push(cookie);
324
+ cookieKeyDomainMap.set(key, mergedCookiesArray.length - 1);
325
+ }
326
+ }
327
+ if (mergedCookiesArray.length > 0) {
328
+ const mergedJar = new RezoCookieJar(mergedCookiesArray, url);
329
+ cookieData = mergedJar.cookies();
305
330
  } else {
306
331
  cookieData = {
307
332
  array: [],
@@ -170,7 +170,11 @@ function setSignal() {
170
170
  clearTimeout(this.timeoutClearInstanse);
171
171
  if (this.timeout && typeof this.timeout === "number" && this.timeout > 100) {
172
172
  const controller = new AbortController;
173
- this.timeoutClearInstanse = setTimeout(() => controller.abort(), this.timeout);
173
+ const timer = setTimeout(() => controller.abort(), this.timeout);
174
+ if (typeof timer === "object" && "unref" in timer) {
175
+ timer.unref();
176
+ }
177
+ this.timeoutClearInstanse = timer;
174
178
  this.signal = controller.signal;
175
179
  }
176
180
  }
@@ -285,6 +289,9 @@ function prepareHTTPOptions(options, jar, addedOptions, config) {
285
289
  }
286
290
  }
287
291
  }
292
+ if (cookiesString) {
293
+ fetchOptions.headers.set("Cookie", cookiesString);
294
+ }
288
295
  if (options.body) {
289
296
  fetchOptions.body = options.body;
290
297
  }
@@ -170,7 +170,11 @@ function setSignal() {
170
170
  clearTimeout(this.timeoutClearInstanse);
171
171
  if (this.timeout && typeof this.timeout === "number" && this.timeout > 100) {
172
172
  const controller = new AbortController;
173
- this.timeoutClearInstanse = setTimeout(() => controller.abort(), this.timeout);
173
+ const timer = setTimeout(() => controller.abort(), this.timeout);
174
+ if (typeof timer === "object" && "unref" in timer) {
175
+ timer.unref();
176
+ }
177
+ this.timeoutClearInstanse = timer;
174
178
  this.signal = controller.signal;
175
179
  }
176
180
  }
@@ -285,6 +289,9 @@ export function prepareHTTPOptions(options, jar, addedOptions, config) {
285
289
  }
286
290
  }
287
291
  }
292
+ if (cookiesString) {
293
+ fetchOptions.headers.set("Cookie", cookiesString);
294
+ }
288
295
  if (options.body) {
289
296
  fetchOptions.body = options.body;
290
297
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rezo",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Lightning-fast, enterprise-grade HTTP client for modern JavaScript. Full HTTP/2 support, intelligent cookie management, multiple adapters (HTTP, Fetch, cURL, XHR), streaming, proxy support (HTTP/HTTPS/SOCKS), and cross-environment compatibility.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",