rezo 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -0
- package/dist/adapters/curl.cjs +47 -1
- package/dist/adapters/curl.js +47 -1
- package/dist/adapters/entries/curl.cjs +31 -4
- package/dist/adapters/entries/curl.d.ts +2576 -847
- package/dist/adapters/entries/curl.js +29 -2
- package/dist/adapters/entries/fetch.cjs +31 -2
- package/dist/adapters/entries/fetch.d.ts +1753 -15
- package/dist/adapters/entries/fetch.js +29 -1
- package/dist/adapters/entries/http.cjs +31 -2
- package/dist/adapters/entries/http.d.ts +1774 -14
- package/dist/adapters/entries/http.js +29 -1
- package/dist/adapters/entries/http2.cjs +31 -4
- package/dist/adapters/entries/http2.d.ts +1748 -19
- package/dist/adapters/entries/http2.js +29 -2
- package/dist/adapters/entries/react-native.cjs +31 -2
- package/dist/adapters/entries/react-native.d.ts +1753 -14
- package/dist/adapters/entries/react-native.js +29 -1
- package/dist/adapters/entries/xhr.cjs +31 -2
- package/dist/adapters/entries/xhr.d.ts +1753 -15
- package/dist/adapters/entries/xhr.js +29 -1
- package/dist/adapters/fetch.cjs +24 -20
- package/dist/adapters/fetch.js +24 -20
- package/dist/adapters/http.cjs +69 -19
- package/dist/adapters/http.js +69 -19
- package/dist/adapters/http2.cjs +69 -19
- package/dist/adapters/http2.js +69 -19
- package/dist/adapters/index.cjs +6 -6
- package/dist/cache/index.cjs +13 -13
- package/dist/core/hooks.cjs +16 -0
- package/dist/core/hooks.js +16 -0
- package/dist/core/rezo.cjs +23 -1
- package/dist/core/rezo.js +23 -1
- package/dist/crawler.d.ts +528 -5
- package/dist/entries/crawler.cjs +5 -5
- package/dist/index.cjs +18 -16
- package/dist/index.d.ts +564 -5
- package/dist/index.js +1 -0
- package/dist/platform/browser.cjs +24 -2
- package/dist/platform/browser.d.ts +672 -10
- package/dist/platform/browser.js +24 -2
- package/dist/platform/bun.cjs +24 -2
- package/dist/platform/bun.d.ts +672 -10
- package/dist/platform/bun.js +24 -2
- package/dist/platform/deno.cjs +24 -2
- package/dist/platform/deno.d.ts +672 -10
- package/dist/platform/deno.js +24 -2
- package/dist/platform/node.cjs +24 -2
- package/dist/platform/node.d.ts +672 -10
- package/dist/platform/node.js +24 -2
- package/dist/platform/react-native.cjs +24 -2
- package/dist/platform/react-native.d.ts +672 -10
- package/dist/platform/react-native.js +24 -2
- package/dist/platform/worker.cjs +24 -2
- package/dist/platform/worker.d.ts +672 -10
- package/dist/platform/worker.js +24 -2
- package/dist/plugin/index.cjs +36 -36
- package/dist/proxy/index.cjs +2 -0
- package/dist/proxy/index.js +1 -0
- package/dist/proxy/manager.cjs +446 -0
- package/dist/proxy/manager.js +444 -0
- package/dist/utils/http-config.cjs +14 -3
- package/dist/utils/http-config.js +14 -3
- package/package.json +19 -4
package/dist/core/hooks.cjs
CHANGED
|
@@ -11,6 +11,14 @@ function createDefaultHooks() {
|
|
|
11
11
|
afterParse: [],
|
|
12
12
|
beforeCookie: [],
|
|
13
13
|
afterCookie: [],
|
|
14
|
+
beforeProxySelect: [],
|
|
15
|
+
afterProxySelect: [],
|
|
16
|
+
beforeProxyError: [],
|
|
17
|
+
afterProxyError: [],
|
|
18
|
+
beforeProxyDisable: [],
|
|
19
|
+
afterProxyDisable: [],
|
|
20
|
+
afterProxyRotate: [],
|
|
21
|
+
afterProxyEnable: [],
|
|
14
22
|
onSocket: [],
|
|
15
23
|
onDns: [],
|
|
16
24
|
onTls: [],
|
|
@@ -33,6 +41,14 @@ function mergeHooks(base, overrides) {
|
|
|
33
41
|
afterParse: [...base.afterParse, ...overrides.afterParse || []],
|
|
34
42
|
beforeCookie: [...base.beforeCookie, ...overrides.beforeCookie || []],
|
|
35
43
|
afterCookie: [...base.afterCookie, ...overrides.afterCookie || []],
|
|
44
|
+
beforeProxySelect: [...base.beforeProxySelect, ...overrides.beforeProxySelect || []],
|
|
45
|
+
afterProxySelect: [...base.afterProxySelect, ...overrides.afterProxySelect || []],
|
|
46
|
+
beforeProxyError: [...base.beforeProxyError, ...overrides.beforeProxyError || []],
|
|
47
|
+
afterProxyError: [...base.afterProxyError, ...overrides.afterProxyError || []],
|
|
48
|
+
beforeProxyDisable: [...base.beforeProxyDisable, ...overrides.beforeProxyDisable || []],
|
|
49
|
+
afterProxyDisable: [...base.afterProxyDisable, ...overrides.afterProxyDisable || []],
|
|
50
|
+
afterProxyRotate: [...base.afterProxyRotate, ...overrides.afterProxyRotate || []],
|
|
51
|
+
afterProxyEnable: [...base.afterProxyEnable, ...overrides.afterProxyEnable || []],
|
|
36
52
|
onSocket: [...base.onSocket, ...overrides.onSocket || []],
|
|
37
53
|
onDns: [...base.onDns, ...overrides.onDns || []],
|
|
38
54
|
onTls: [...base.onTls, ...overrides.onTls || []],
|
package/dist/core/hooks.js
CHANGED
|
@@ -11,6 +11,14 @@ export function createDefaultHooks() {
|
|
|
11
11
|
afterParse: [],
|
|
12
12
|
beforeCookie: [],
|
|
13
13
|
afterCookie: [],
|
|
14
|
+
beforeProxySelect: [],
|
|
15
|
+
afterProxySelect: [],
|
|
16
|
+
beforeProxyError: [],
|
|
17
|
+
afterProxyError: [],
|
|
18
|
+
beforeProxyDisable: [],
|
|
19
|
+
afterProxyDisable: [],
|
|
20
|
+
afterProxyRotate: [],
|
|
21
|
+
afterProxyEnable: [],
|
|
14
22
|
onSocket: [],
|
|
15
23
|
onDns: [],
|
|
16
24
|
onTls: [],
|
|
@@ -33,6 +41,14 @@ export function mergeHooks(base, overrides) {
|
|
|
33
41
|
afterParse: [...base.afterParse, ...overrides.afterParse || []],
|
|
34
42
|
beforeCookie: [...base.beforeCookie, ...overrides.beforeCookie || []],
|
|
35
43
|
afterCookie: [...base.afterCookie, ...overrides.afterCookie || []],
|
|
44
|
+
beforeProxySelect: [...base.beforeProxySelect, ...overrides.beforeProxySelect || []],
|
|
45
|
+
afterProxySelect: [...base.afterProxySelect, ...overrides.afterProxySelect || []],
|
|
46
|
+
beforeProxyError: [...base.beforeProxyError, ...overrides.beforeProxyError || []],
|
|
47
|
+
afterProxyError: [...base.afterProxyError, ...overrides.afterProxyError || []],
|
|
48
|
+
beforeProxyDisable: [...base.beforeProxyDisable, ...overrides.beforeProxyDisable || []],
|
|
49
|
+
afterProxyDisable: [...base.afterProxyDisable, ...overrides.afterProxyDisable || []],
|
|
50
|
+
afterProxyRotate: [...base.afterProxyRotate, ...overrides.afterProxyRotate || []],
|
|
51
|
+
afterProxyEnable: [...base.afterProxyEnable, ...overrides.afterProxyEnable || []],
|
|
36
52
|
onSocket: [...base.onSocket, ...overrides.onSocket || []],
|
|
37
53
|
onDns: [...base.onDns, ...overrides.onDns || []],
|
|
38
54
|
onTls: [...base.onTls, ...overrides.onTls || []],
|
package/dist/core/rezo.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const { RezoURLSearchParams } = require('../utils/data-operations.cjs');
|
|
|
6
6
|
const packageJson = require("../../package.json");
|
|
7
7
|
const { createDefaultHooks, mergeHooks, runVoidHooksSync, runTransformHooks } = require('./hooks.cjs');
|
|
8
8
|
const { ResponseCache, DNSCache } = require('../cache/index.cjs');
|
|
9
|
+
const { ProxyManager } = require('../proxy/manager.cjs');
|
|
9
10
|
let globalAdapter = null;
|
|
10
11
|
function setGlobalAdapter(adapter) {
|
|
11
12
|
globalAdapter = adapter;
|
|
@@ -38,6 +39,7 @@ class Rezo {
|
|
|
38
39
|
responseCache;
|
|
39
40
|
dnsCache;
|
|
40
41
|
adapter;
|
|
42
|
+
_proxyManager = null;
|
|
41
43
|
constructor(config, adapter) {
|
|
42
44
|
if (!adapter && !globalAdapter) {
|
|
43
45
|
throw new Error(`No HTTP adapter configured. Import from a platform-specific entry:
|
|
@@ -68,6 +70,16 @@ class Rezo {
|
|
|
68
70
|
const dnsOptions = typeof config?.cache === "object" && typeof config.cache.dns === "object" ? config.cache.dns : undefined;
|
|
69
71
|
this.dnsCache = new DNSCache(dnsOptions);
|
|
70
72
|
}
|
|
73
|
+
if (config?.proxyManager) {
|
|
74
|
+
if (config.proxyManager instanceof ProxyManager) {
|
|
75
|
+
this._proxyManager = config.proxyManager;
|
|
76
|
+
} else {
|
|
77
|
+
this._proxyManager = new ProxyManager(config.proxyManager);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
get proxyManager() {
|
|
82
|
+
return this._proxyManager;
|
|
71
83
|
}
|
|
72
84
|
clearCache() {
|
|
73
85
|
this.responseCache?.clear();
|
|
@@ -295,7 +307,8 @@ class Rezo {
|
|
|
295
307
|
}
|
|
296
308
|
}
|
|
297
309
|
const executeWithHooks = async () => {
|
|
298
|
-
const
|
|
310
|
+
const mergedDefaults = this._proxyManager ? { ...defaultOptions, _proxyManager: this._proxyManager } : defaultOptions;
|
|
311
|
+
const response = await this.adapter(options, mergedDefaults, jar);
|
|
299
312
|
if (jar.cookieFile) {
|
|
300
313
|
try {
|
|
301
314
|
jar.saveToFile();
|
|
@@ -442,9 +455,18 @@ const defaultTransforms = exports.defaultTransforms = {
|
|
|
442
455
|
}
|
|
443
456
|
]
|
|
444
457
|
};
|
|
458
|
+
const { RezoError } = require('../errors/rezo-error.cjs');
|
|
445
459
|
function createRezoInstance(adapter, config) {
|
|
446
460
|
const instance = new Rezo(config, adapter);
|
|
447
461
|
instance.create = (cfg) => new Rezo(cfg, adapter);
|
|
462
|
+
instance.isRezoError = RezoError.isRezoError;
|
|
463
|
+
instance.isCancel = (error) => {
|
|
464
|
+
return error instanceof RezoError && error.code === "ECONNABORTED";
|
|
465
|
+
};
|
|
466
|
+
instance.Cancel = RezoError;
|
|
467
|
+
instance.CancelToken = AbortController;
|
|
468
|
+
instance.all = Promise.all.bind(Promise);
|
|
469
|
+
instance.spread = (callback) => (array) => callback(...array);
|
|
448
470
|
return instance;
|
|
449
471
|
}
|
|
450
472
|
function createDefaultInstance(config) {
|
package/dist/core/rezo.js
CHANGED
|
@@ -6,6 +6,7 @@ import { RezoURLSearchParams } from '../utils/data-operations.js';
|
|
|
6
6
|
import packageJson from "../../package.json" with { type: 'json' };
|
|
7
7
|
import { createDefaultHooks, mergeHooks, runVoidHooksSync, runTransformHooks } from './hooks.js';
|
|
8
8
|
import { ResponseCache, DNSCache } from '../cache/index.js';
|
|
9
|
+
import { ProxyManager } from '../proxy/manager.js';
|
|
9
10
|
let globalAdapter = null;
|
|
10
11
|
export function setGlobalAdapter(adapter) {
|
|
11
12
|
globalAdapter = adapter;
|
|
@@ -38,6 +39,7 @@ export class Rezo {
|
|
|
38
39
|
responseCache;
|
|
39
40
|
dnsCache;
|
|
40
41
|
adapter;
|
|
42
|
+
_proxyManager = null;
|
|
41
43
|
constructor(config, adapter) {
|
|
42
44
|
if (!adapter && !globalAdapter) {
|
|
43
45
|
throw new Error(`No HTTP adapter configured. Import from a platform-specific entry:
|
|
@@ -68,6 +70,16 @@ export class Rezo {
|
|
|
68
70
|
const dnsOptions = typeof config?.cache === "object" && typeof config.cache.dns === "object" ? config.cache.dns : undefined;
|
|
69
71
|
this.dnsCache = new DNSCache(dnsOptions);
|
|
70
72
|
}
|
|
73
|
+
if (config?.proxyManager) {
|
|
74
|
+
if (config.proxyManager instanceof ProxyManager) {
|
|
75
|
+
this._proxyManager = config.proxyManager;
|
|
76
|
+
} else {
|
|
77
|
+
this._proxyManager = new ProxyManager(config.proxyManager);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
get proxyManager() {
|
|
82
|
+
return this._proxyManager;
|
|
71
83
|
}
|
|
72
84
|
clearCache() {
|
|
73
85
|
this.responseCache?.clear();
|
|
@@ -295,7 +307,8 @@ export class Rezo {
|
|
|
295
307
|
}
|
|
296
308
|
}
|
|
297
309
|
const executeWithHooks = async () => {
|
|
298
|
-
const
|
|
310
|
+
const mergedDefaults = this._proxyManager ? { ...defaultOptions, _proxyManager: this._proxyManager } : defaultOptions;
|
|
311
|
+
const response = await this.adapter(options, mergedDefaults, jar);
|
|
299
312
|
if (jar.cookieFile) {
|
|
300
313
|
try {
|
|
301
314
|
jar.saveToFile();
|
|
@@ -442,9 +455,18 @@ export const defaultTransforms = {
|
|
|
442
455
|
}
|
|
443
456
|
]
|
|
444
457
|
};
|
|
458
|
+
import { RezoError } from '../errors/rezo-error.js';
|
|
445
459
|
export function createRezoInstance(adapter, config) {
|
|
446
460
|
const instance = new Rezo(config, adapter);
|
|
447
461
|
instance.create = (cfg) => new Rezo(cfg, adapter);
|
|
462
|
+
instance.isRezoError = RezoError.isRezoError;
|
|
463
|
+
instance.isCancel = (error) => {
|
|
464
|
+
return error instanceof RezoError && error.code === "ECONNABORTED";
|
|
465
|
+
};
|
|
466
|
+
instance.Cancel = RezoError;
|
|
467
|
+
instance.CancelToken = AbortController;
|
|
468
|
+
instance.all = Promise.all.bind(Promise);
|
|
469
|
+
instance.spread = (callback) => (array) => callback(...array);
|
|
448
470
|
return instance;
|
|
449
471
|
}
|
|
450
472
|
export function createDefaultInstance(config) {
|