rezo 1.0.0

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 (135) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1507 -0
  3. package/assets/icon.svg +37 -0
  4. package/assets/logo-dark.svg +47 -0
  5. package/assets/logo.svg +58 -0
  6. package/dist/adapters/curl.cjs +1034 -0
  7. package/dist/adapters/curl.js +1031 -0
  8. package/dist/adapters/entries/curl.cjs +4 -0
  9. package/dist/adapters/entries/curl.d.ts +2136 -0
  10. package/dist/adapters/entries/curl.js +2 -0
  11. package/dist/adapters/entries/fetch.cjs +2 -0
  12. package/dist/adapters/entries/fetch.d.ts +2127 -0
  13. package/dist/adapters/entries/fetch.js +1 -0
  14. package/dist/adapters/entries/http.cjs +2 -0
  15. package/dist/adapters/entries/http.d.ts +2126 -0
  16. package/dist/adapters/entries/http.js +1 -0
  17. package/dist/adapters/entries/http2.cjs +4 -0
  18. package/dist/adapters/entries/http2.d.ts +2136 -0
  19. package/dist/adapters/entries/http2.js +2 -0
  20. package/dist/adapters/entries/react-native.cjs +2 -0
  21. package/dist/adapters/entries/react-native.d.ts +2126 -0
  22. package/dist/adapters/entries/react-native.js +1 -0
  23. package/dist/adapters/entries/xhr.cjs +2 -0
  24. package/dist/adapters/entries/xhr.d.ts +2127 -0
  25. package/dist/adapters/entries/xhr.js +1 -0
  26. package/dist/adapters/fetch.cjs +740 -0
  27. package/dist/adapters/fetch.js +739 -0
  28. package/dist/adapters/http.cjs +1153 -0
  29. package/dist/adapters/http.js +1151 -0
  30. package/dist/adapters/http2.cjs +957 -0
  31. package/dist/adapters/http2.js +956 -0
  32. package/dist/adapters/index.cjs +6 -0
  33. package/dist/adapters/index.js +7 -0
  34. package/dist/adapters/picker.cjs +342 -0
  35. package/dist/adapters/picker.js +331 -0
  36. package/dist/adapters/react-native.cjs +545 -0
  37. package/dist/adapters/react-native.js +544 -0
  38. package/dist/adapters/xhr.cjs +622 -0
  39. package/dist/adapters/xhr.js +621 -0
  40. package/dist/cache/dns-cache.cjs +118 -0
  41. package/dist/cache/dns-cache.js +113 -0
  42. package/dist/cache/file-cacher.cjs +264 -0
  43. package/dist/cache/file-cacher.js +261 -0
  44. package/dist/cache/index.cjs +13 -0
  45. package/dist/cache/index.js +5 -0
  46. package/dist/cache/lru-cache.cjs +96 -0
  47. package/dist/cache/lru-cache.js +93 -0
  48. package/dist/cache/response-cache.cjs +314 -0
  49. package/dist/cache/response-cache.js +310 -0
  50. package/dist/cache/url-store.cjs +288 -0
  51. package/dist/cache/url-store.js +285 -0
  52. package/dist/core/hooks.cjs +133 -0
  53. package/dist/core/hooks.js +120 -0
  54. package/dist/core/rezo.cjs +464 -0
  55. package/dist/core/rezo.js +458 -0
  56. package/dist/crawler.d.ts +6255 -0
  57. package/dist/dom/index.cjs +1 -0
  58. package/dist/dom/index.d.ts +23 -0
  59. package/dist/dom/index.js +1 -0
  60. package/dist/entries/crawler.cjs +5 -0
  61. package/dist/entries/crawler.js +2 -0
  62. package/dist/errors/rezo-error.cjs +722 -0
  63. package/dist/errors/rezo-error.js +716 -0
  64. package/dist/index.cjs +34 -0
  65. package/dist/index.d.ts +3335 -0
  66. package/dist/index.js +26 -0
  67. package/dist/platform/browser.cjs +9 -0
  68. package/dist/platform/browser.d.ts +3203 -0
  69. package/dist/platform/browser.js +7 -0
  70. package/dist/platform/bun.cjs +9 -0
  71. package/dist/platform/bun.d.ts +3203 -0
  72. package/dist/platform/bun.js +7 -0
  73. package/dist/platform/deno.cjs +9 -0
  74. package/dist/platform/deno.d.ts +3203 -0
  75. package/dist/platform/deno.js +7 -0
  76. package/dist/platform/node.cjs +9 -0
  77. package/dist/platform/node.d.ts +3203 -0
  78. package/dist/platform/node.js +7 -0
  79. package/dist/platform/react-native.cjs +9 -0
  80. package/dist/platform/react-native.d.ts +3203 -0
  81. package/dist/platform/react-native.js +7 -0
  82. package/dist/platform/worker.cjs +9 -0
  83. package/dist/platform/worker.d.ts +3203 -0
  84. package/dist/platform/worker.js +7 -0
  85. package/dist/plugin/addon/decodo/index.cjs +1 -0
  86. package/dist/plugin/addon/decodo/index.js +1 -0
  87. package/dist/plugin/addon/decodo/options.cjs +1 -0
  88. package/dist/plugin/addon/decodo/options.js +1 -0
  89. package/dist/plugin/addon/oxylabs/index.cjs +1 -0
  90. package/dist/plugin/addon/oxylabs/index.js +1 -0
  91. package/dist/plugin/addon/oxylabs/options.cjs +1 -0
  92. package/dist/plugin/addon/oxylabs/options.js +1 -0
  93. package/dist/plugin/crawler-options.cjs +1 -0
  94. package/dist/plugin/crawler-options.js +1 -0
  95. package/dist/plugin/crawler.cjs +519 -0
  96. package/dist/plugin/crawler.js +517 -0
  97. package/dist/plugin/index.cjs +36 -0
  98. package/dist/plugin/index.js +32 -0
  99. package/dist/proxy/index.cjs +142 -0
  100. package/dist/proxy/index.js +139 -0
  101. package/dist/responses/buildError.cjs +452 -0
  102. package/dist/responses/buildError.js +441 -0
  103. package/dist/responses/buildResponse.cjs +365 -0
  104. package/dist/responses/buildResponse.js +361 -0
  105. package/dist/responses/download.cjs +54 -0
  106. package/dist/responses/download.js +52 -0
  107. package/dist/responses/stream.cjs +60 -0
  108. package/dist/responses/stream.js +58 -0
  109. package/dist/responses/upload.cjs +54 -0
  110. package/dist/responses/upload.js +52 -0
  111. package/dist/types/cookies.cjs +394 -0
  112. package/dist/types/cookies.js +391 -0
  113. package/dist/types/download.cjs +10 -0
  114. package/dist/types/download.js +10 -0
  115. package/dist/types/rezo-request.cjs +131 -0
  116. package/dist/types/rezo-request.js +131 -0
  117. package/dist/utils/agent-merger.cjs +111 -0
  118. package/dist/utils/agent-merger.js +108 -0
  119. package/dist/utils/compression.cjs +84 -0
  120. package/dist/utils/compression.js +82 -0
  121. package/dist/utils/cookies.cjs +514 -0
  122. package/dist/utils/cookies.js +511 -0
  123. package/dist/utils/data-operations.cjs +75 -0
  124. package/dist/utils/data-operations.js +73 -0
  125. package/dist/utils/form-data.cjs +164 -0
  126. package/dist/utils/form-data.js +161 -0
  127. package/dist/utils/headers.cjs +162 -0
  128. package/dist/utils/headers.js +161 -0
  129. package/dist/utils/http-config.cjs +723 -0
  130. package/dist/utils/http-config.js +718 -0
  131. package/dist/utils/index.cjs +8 -0
  132. package/dist/utils/index.js +8 -0
  133. package/dist/utils/tools.cjs +18 -0
  134. package/dist/utils/tools.js +15 -0
  135. package/package.json +172 -0
@@ -0,0 +1,142 @@
1
+ const { SocksProxyAgent: RezoSocksProxy } = require("socks-proxy-agent");
2
+ const { HttpsProxyAgent: RezoHttpsSocks } = require("https-proxy-agent");
3
+ const { HttpProxyAgent: RezoHttpSocks } = require("http-proxy-agent");
4
+ function createOptions(uri, opts) {
5
+ if (uri instanceof URL || typeof uri === "string") {
6
+ return {
7
+ uri,
8
+ opts
9
+ };
10
+ }
11
+ const { port, protocol, host, auth, ...config } = uri;
12
+ const authstr = auth ? `${encodeURIComponent(auth.username)}:${encodeURIComponent(auth.password)}@` : "";
13
+ opts = { ...opts || {}, ...config || {} };
14
+ return {
15
+ opts: Object.keys(opts).length > 0 ? opts : undefined,
16
+ uri: `${protocol}://${authstr}${host}:${port}`
17
+ };
18
+ }
19
+ function isIPv4(host) {
20
+ const ipv4Regex = /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/;
21
+ return ipv4Regex.test(host);
22
+ }
23
+ function isDomain(host) {
24
+ const domainRegex = /^(?=.{1,253}$)(?!-)([a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}$/;
25
+ return domainRegex.test(host);
26
+ }
27
+ function isNumeric(value) {
28
+ if (typeof value === "number")
29
+ return isFinite(value);
30
+ if (typeof value === "string" && value.trim() !== "") {
31
+ return !isNaN(Number(value));
32
+ }
33
+ return false;
34
+ }
35
+ function parseProxyString(input) {
36
+ if (!input)
37
+ return null;
38
+ let host = "";
39
+ let port = 0;
40
+ let username;
41
+ let password;
42
+ const proto = input.includes("://") ? input.split("://")[0].toLowerCase() : "";
43
+ const protocol = proto.startsWith("http") ? "http" : proto.startsWith("https") ? "https" : "socks5";
44
+ if (protocol !== "socks5" || input.includes("://")) {
45
+ input = input.split("://")[1];
46
+ }
47
+ const getProxy = (authPart, hostPart) => {
48
+ if (authPart && authPart.includes(":")) {
49
+ const [p1, ..._p2] = authPart.split(":");
50
+ const p2 = _p2.join(":");
51
+ if ((isIPv4(p1) || isDomain(p1)) && isNumeric(p2)) {
52
+ host = p1;
53
+ port = parseInt(p2, 10);
54
+ } else {
55
+ username = p1;
56
+ password = p2;
57
+ }
58
+ }
59
+ if (hostPart && hostPart.includes(":")) {
60
+ const [p1, ..._p2] = hostPart.split(":");
61
+ const p2 = _p2.join(":");
62
+ if ((isIPv4(p1) || isDomain(p1)) && isNumeric(p2)) {
63
+ host = p1;
64
+ port = parseInt(p2, 10);
65
+ } else {
66
+ username = p1;
67
+ password = p2;
68
+ }
69
+ }
70
+ if (!host && !port)
71
+ return null;
72
+ if (username && password) {
73
+ return { protocol, host, port, auth: { username, password } };
74
+ }
75
+ return {
76
+ protocol,
77
+ host,
78
+ port
79
+ };
80
+ };
81
+ input = input.trim();
82
+ if (input.includes("@")) {
83
+ const [authPart, hostPart] = input.split("@");
84
+ if (!authPart && !hostPart)
85
+ return null;
86
+ return getProxy(authPart, hostPart);
87
+ } else if (input.split(":").length === 4 || input.split(":").length === 2) {
88
+ const parts = input.split(":");
89
+ const authPart = input.split(":").length === 2 ? undefined : parts[2] + ":" + parts[3];
90
+ const hostPart = parts[0] + ":" + parts[1];
91
+ return getProxy(authPart || "", hostPart || "");
92
+ } else {
93
+ return null;
94
+ }
95
+ }
96
+ function rezoProxy(uri, over, opts) {
97
+ if (typeof uri === "string") {
98
+ if (typeof over === "string") {
99
+ const config = createOptions(uri, opts);
100
+ if (over === "http") {
101
+ return new RezoHttpSocks(config.uri, config.opts);
102
+ }
103
+ return new RezoHttpsSocks(config.uri, { ...config.opts, rejectUnauthorized: false });
104
+ } else {
105
+ const isHttp = uri.startsWith("http:");
106
+ const isHttps = uri.startsWith("https:");
107
+ const isSocks = uri.startsWith("sock");
108
+ if (isSocks) {
109
+ const config = createOptions(uri, over || opts);
110
+ return new RezoSocksProxy(config.uri, config.opts);
111
+ }
112
+ if (isHttp) {
113
+ const config = createOptions(uri, over || opts);
114
+ return new RezoHttpSocks(config.uri, config.opts);
115
+ }
116
+ if (isHttps) {
117
+ const config = createOptions(uri, over || opts);
118
+ return new RezoHttpsSocks(config.uri, { ...config.opts, rejectUnauthorized: false });
119
+ }
120
+ const proxy = parseProxyString(uri);
121
+ if (proxy) {
122
+ const config = createOptions(proxy, over || opts);
123
+ return new RezoSocksProxy(config.uri, config.opts);
124
+ }
125
+ throw new Error("Invalid proxy protocol");
126
+ }
127
+ }
128
+ if (uri.client) {
129
+ delete uri.client;
130
+ const config = createOptions(uri, opts);
131
+ if (over === "http") {
132
+ return new RezoHttpSocks(config.uri, config.opts);
133
+ }
134
+ console.log(config.uri);
135
+ return new RezoHttpsSocks(config.uri, { ...config.opts, rejectUnauthorized: false });
136
+ }
137
+ const config = createOptions(uri, opts);
138
+ return new RezoSocksProxy(config.uri, config.opts);
139
+ }
140
+
141
+ exports.parseProxyString = parseProxyString;
142
+ exports.rezoProxy = rezoProxy;
@@ -0,0 +1,139 @@
1
+ import { SocksProxyAgent as RezoSocksProxy } from "socks-proxy-agent";
2
+ import { HttpsProxyAgent as RezoHttpsSocks } from "https-proxy-agent";
3
+ import { HttpProxyAgent as RezoHttpSocks } from "http-proxy-agent";
4
+ function createOptions(uri, opts) {
5
+ if (uri instanceof URL || typeof uri === "string") {
6
+ return {
7
+ uri,
8
+ opts
9
+ };
10
+ }
11
+ const { port, protocol, host, auth, ...config } = uri;
12
+ const authstr = auth ? `${encodeURIComponent(auth.username)}:${encodeURIComponent(auth.password)}@` : "";
13
+ opts = { ...opts || {}, ...config || {} };
14
+ return {
15
+ opts: Object.keys(opts).length > 0 ? opts : undefined,
16
+ uri: `${protocol}://${authstr}${host}:${port}`
17
+ };
18
+ }
19
+ function isIPv4(host) {
20
+ const ipv4Regex = /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/;
21
+ return ipv4Regex.test(host);
22
+ }
23
+ function isDomain(host) {
24
+ const domainRegex = /^(?=.{1,253}$)(?!-)([a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}$/;
25
+ return domainRegex.test(host);
26
+ }
27
+ function isNumeric(value) {
28
+ if (typeof value === "number")
29
+ return isFinite(value);
30
+ if (typeof value === "string" && value.trim() !== "") {
31
+ return !isNaN(Number(value));
32
+ }
33
+ return false;
34
+ }
35
+ export function parseProxyString(input) {
36
+ if (!input)
37
+ return null;
38
+ let host = "";
39
+ let port = 0;
40
+ let username;
41
+ let password;
42
+ const proto = input.includes("://") ? input.split("://")[0].toLowerCase() : "";
43
+ const protocol = proto.startsWith("http") ? "http" : proto.startsWith("https") ? "https" : "socks5";
44
+ if (protocol !== "socks5" || input.includes("://")) {
45
+ input = input.split("://")[1];
46
+ }
47
+ const getProxy = (authPart, hostPart) => {
48
+ if (authPart && authPart.includes(":")) {
49
+ const [p1, ..._p2] = authPart.split(":");
50
+ const p2 = _p2.join(":");
51
+ if ((isIPv4(p1) || isDomain(p1)) && isNumeric(p2)) {
52
+ host = p1;
53
+ port = parseInt(p2, 10);
54
+ } else {
55
+ username = p1;
56
+ password = p2;
57
+ }
58
+ }
59
+ if (hostPart && hostPart.includes(":")) {
60
+ const [p1, ..._p2] = hostPart.split(":");
61
+ const p2 = _p2.join(":");
62
+ if ((isIPv4(p1) || isDomain(p1)) && isNumeric(p2)) {
63
+ host = p1;
64
+ port = parseInt(p2, 10);
65
+ } else {
66
+ username = p1;
67
+ password = p2;
68
+ }
69
+ }
70
+ if (!host && !port)
71
+ return null;
72
+ if (username && password) {
73
+ return { protocol, host, port, auth: { username, password } };
74
+ }
75
+ return {
76
+ protocol,
77
+ host,
78
+ port
79
+ };
80
+ };
81
+ input = input.trim();
82
+ if (input.includes("@")) {
83
+ const [authPart, hostPart] = input.split("@");
84
+ if (!authPart && !hostPart)
85
+ return null;
86
+ return getProxy(authPart, hostPart);
87
+ } else if (input.split(":").length === 4 || input.split(":").length === 2) {
88
+ const parts = input.split(":");
89
+ const authPart = input.split(":").length === 2 ? undefined : parts[2] + ":" + parts[3];
90
+ const hostPart = parts[0] + ":" + parts[1];
91
+ return getProxy(authPart || "", hostPart || "");
92
+ } else {
93
+ return null;
94
+ }
95
+ }
96
+ export function rezoProxy(uri, over, opts) {
97
+ if (typeof uri === "string") {
98
+ if (typeof over === "string") {
99
+ const config = createOptions(uri, opts);
100
+ if (over === "http") {
101
+ return new RezoHttpSocks(config.uri, config.opts);
102
+ }
103
+ return new RezoHttpsSocks(config.uri, { ...config.opts, rejectUnauthorized: false });
104
+ } else {
105
+ const isHttp = uri.startsWith("http:");
106
+ const isHttps = uri.startsWith("https:");
107
+ const isSocks = uri.startsWith("sock");
108
+ if (isSocks) {
109
+ const config = createOptions(uri, over || opts);
110
+ return new RezoSocksProxy(config.uri, config.opts);
111
+ }
112
+ if (isHttp) {
113
+ const config = createOptions(uri, over || opts);
114
+ return new RezoHttpSocks(config.uri, config.opts);
115
+ }
116
+ if (isHttps) {
117
+ const config = createOptions(uri, over || opts);
118
+ return new RezoHttpsSocks(config.uri, { ...config.opts, rejectUnauthorized: false });
119
+ }
120
+ const proxy = parseProxyString(uri);
121
+ if (proxy) {
122
+ const config = createOptions(proxy, over || opts);
123
+ return new RezoSocksProxy(config.uri, config.opts);
124
+ }
125
+ throw new Error("Invalid proxy protocol");
126
+ }
127
+ }
128
+ if (uri.client) {
129
+ delete uri.client;
130
+ const config = createOptions(uri, opts);
131
+ if (over === "http") {
132
+ return new RezoHttpSocks(config.uri, config.opts);
133
+ }
134
+ console.log(config.uri);
135
+ return new RezoHttpsSocks(config.uri, { ...config.opts, rejectUnauthorized: false });
136
+ }
137
+ const config = createOptions(uri, opts);
138
+ return new RezoSocksProxy(config.uri, config.opts);
139
+ }