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.
- package/LICENSE +202 -0
- package/README.md +1507 -0
- package/assets/icon.svg +37 -0
- package/assets/logo-dark.svg +47 -0
- package/assets/logo.svg +58 -0
- package/dist/adapters/curl.cjs +1034 -0
- package/dist/adapters/curl.js +1031 -0
- package/dist/adapters/entries/curl.cjs +4 -0
- package/dist/adapters/entries/curl.d.ts +2136 -0
- package/dist/adapters/entries/curl.js +2 -0
- package/dist/adapters/entries/fetch.cjs +2 -0
- package/dist/adapters/entries/fetch.d.ts +2127 -0
- package/dist/adapters/entries/fetch.js +1 -0
- package/dist/adapters/entries/http.cjs +2 -0
- package/dist/adapters/entries/http.d.ts +2126 -0
- package/dist/adapters/entries/http.js +1 -0
- package/dist/adapters/entries/http2.cjs +4 -0
- package/dist/adapters/entries/http2.d.ts +2136 -0
- package/dist/adapters/entries/http2.js +2 -0
- package/dist/adapters/entries/react-native.cjs +2 -0
- package/dist/adapters/entries/react-native.d.ts +2126 -0
- package/dist/adapters/entries/react-native.js +1 -0
- package/dist/adapters/entries/xhr.cjs +2 -0
- package/dist/adapters/entries/xhr.d.ts +2127 -0
- package/dist/adapters/entries/xhr.js +1 -0
- package/dist/adapters/fetch.cjs +740 -0
- package/dist/adapters/fetch.js +739 -0
- package/dist/adapters/http.cjs +1153 -0
- package/dist/adapters/http.js +1151 -0
- package/dist/adapters/http2.cjs +957 -0
- package/dist/adapters/http2.js +956 -0
- package/dist/adapters/index.cjs +6 -0
- package/dist/adapters/index.js +7 -0
- package/dist/adapters/picker.cjs +342 -0
- package/dist/adapters/picker.js +331 -0
- package/dist/adapters/react-native.cjs +545 -0
- package/dist/adapters/react-native.js +544 -0
- package/dist/adapters/xhr.cjs +622 -0
- package/dist/adapters/xhr.js +621 -0
- package/dist/cache/dns-cache.cjs +118 -0
- package/dist/cache/dns-cache.js +113 -0
- package/dist/cache/file-cacher.cjs +264 -0
- package/dist/cache/file-cacher.js +261 -0
- package/dist/cache/index.cjs +13 -0
- package/dist/cache/index.js +5 -0
- package/dist/cache/lru-cache.cjs +96 -0
- package/dist/cache/lru-cache.js +93 -0
- package/dist/cache/response-cache.cjs +314 -0
- package/dist/cache/response-cache.js +310 -0
- package/dist/cache/url-store.cjs +288 -0
- package/dist/cache/url-store.js +285 -0
- package/dist/core/hooks.cjs +133 -0
- package/dist/core/hooks.js +120 -0
- package/dist/core/rezo.cjs +464 -0
- package/dist/core/rezo.js +458 -0
- package/dist/crawler.d.ts +6255 -0
- package/dist/dom/index.cjs +1 -0
- package/dist/dom/index.d.ts +23 -0
- package/dist/dom/index.js +1 -0
- package/dist/entries/crawler.cjs +5 -0
- package/dist/entries/crawler.js +2 -0
- package/dist/errors/rezo-error.cjs +722 -0
- package/dist/errors/rezo-error.js +716 -0
- package/dist/index.cjs +34 -0
- package/dist/index.d.ts +3335 -0
- package/dist/index.js +26 -0
- package/dist/platform/browser.cjs +9 -0
- package/dist/platform/browser.d.ts +3203 -0
- package/dist/platform/browser.js +7 -0
- package/dist/platform/bun.cjs +9 -0
- package/dist/platform/bun.d.ts +3203 -0
- package/dist/platform/bun.js +7 -0
- package/dist/platform/deno.cjs +9 -0
- package/dist/platform/deno.d.ts +3203 -0
- package/dist/platform/deno.js +7 -0
- package/dist/platform/node.cjs +9 -0
- package/dist/platform/node.d.ts +3203 -0
- package/dist/platform/node.js +7 -0
- package/dist/platform/react-native.cjs +9 -0
- package/dist/platform/react-native.d.ts +3203 -0
- package/dist/platform/react-native.js +7 -0
- package/dist/platform/worker.cjs +9 -0
- package/dist/platform/worker.d.ts +3203 -0
- package/dist/platform/worker.js +7 -0
- package/dist/plugin/addon/decodo/index.cjs +1 -0
- package/dist/plugin/addon/decodo/index.js +1 -0
- package/dist/plugin/addon/decodo/options.cjs +1 -0
- package/dist/plugin/addon/decodo/options.js +1 -0
- package/dist/plugin/addon/oxylabs/index.cjs +1 -0
- package/dist/plugin/addon/oxylabs/index.js +1 -0
- package/dist/plugin/addon/oxylabs/options.cjs +1 -0
- package/dist/plugin/addon/oxylabs/options.js +1 -0
- package/dist/plugin/crawler-options.cjs +1 -0
- package/dist/plugin/crawler-options.js +1 -0
- package/dist/plugin/crawler.cjs +519 -0
- package/dist/plugin/crawler.js +517 -0
- package/dist/plugin/index.cjs +36 -0
- package/dist/plugin/index.js +32 -0
- package/dist/proxy/index.cjs +142 -0
- package/dist/proxy/index.js +139 -0
- package/dist/responses/buildError.cjs +452 -0
- package/dist/responses/buildError.js +441 -0
- package/dist/responses/buildResponse.cjs +365 -0
- package/dist/responses/buildResponse.js +361 -0
- package/dist/responses/download.cjs +54 -0
- package/dist/responses/download.js +52 -0
- package/dist/responses/stream.cjs +60 -0
- package/dist/responses/stream.js +58 -0
- package/dist/responses/upload.cjs +54 -0
- package/dist/responses/upload.js +52 -0
- package/dist/types/cookies.cjs +394 -0
- package/dist/types/cookies.js +391 -0
- package/dist/types/download.cjs +10 -0
- package/dist/types/download.js +10 -0
- package/dist/types/rezo-request.cjs +131 -0
- package/dist/types/rezo-request.js +131 -0
- package/dist/utils/agent-merger.cjs +111 -0
- package/dist/utils/agent-merger.js +108 -0
- package/dist/utils/compression.cjs +84 -0
- package/dist/utils/compression.js +82 -0
- package/dist/utils/cookies.cjs +514 -0
- package/dist/utils/cookies.js +511 -0
- package/dist/utils/data-operations.cjs +75 -0
- package/dist/utils/data-operations.js +73 -0
- package/dist/utils/form-data.cjs +164 -0
- package/dist/utils/form-data.js +161 -0
- package/dist/utils/headers.cjs +162 -0
- package/dist/utils/headers.js +161 -0
- package/dist/utils/http-config.cjs +723 -0
- package/dist/utils/http-config.js +718 -0
- package/dist/utils/index.cjs +8 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/tools.cjs +18 -0
- package/dist/utils/tools.js +15 -0
- package/package.json +172 -0
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
const { Cookie, RezoCookieJar } = require('./cookies.cjs');
|
|
2
|
+
const RezoFormData = require('./form-data.cjs');
|
|
3
|
+
const { RezoHeaders } = require('./headers.cjs');
|
|
4
|
+
const { RezoURLSearchParams } = require('./data-operations.cjs');
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const { parseProxyString } = require('../proxy/index.cjs');
|
|
7
|
+
const { createDefaultHooks, mergeHooks, serializeHooks } = require('../core/hooks.cjs');
|
|
8
|
+
const ERROR_INFO = exports.ERROR_INFO = {
|
|
9
|
+
ECONNREFUSED: {
|
|
10
|
+
code: -111,
|
|
11
|
+
message: "Connection Refused: The target server actively refused the TCP connection attempt."
|
|
12
|
+
},
|
|
13
|
+
ECONNRESET: {
|
|
14
|
+
code: -104,
|
|
15
|
+
message: "Connection Reset: An existing TCP connection was forcibly closed by the peer (server or intermediary)."
|
|
16
|
+
},
|
|
17
|
+
ETIMEDOUT: {
|
|
18
|
+
code: -110,
|
|
19
|
+
message: "Connection Timeout: Attempt to establish a TCP connection timed out (no response received within the timeout period)."
|
|
20
|
+
},
|
|
21
|
+
ENOTFOUND: {
|
|
22
|
+
code: -3008,
|
|
23
|
+
message: "DNS Lookup Failed: DNS lookup for this hostname failed (domain name does not exist or DNS server error)."
|
|
24
|
+
},
|
|
25
|
+
EAI_AGAIN: {
|
|
26
|
+
code: -3001,
|
|
27
|
+
message: "Temporary DNS Failure: Temporary failure in DNS name resolution; retrying might succeed."
|
|
28
|
+
},
|
|
29
|
+
EPROTO: {
|
|
30
|
+
code: -71,
|
|
31
|
+
message: "Protocol Error: A protocol error occurred, often during the TLS/SSL handshake phase."
|
|
32
|
+
},
|
|
33
|
+
ERR_INVALID_PROTOCOL: {
|
|
34
|
+
code: -1001,
|
|
35
|
+
message: "Invalid URL Protocol: The provided URL uses an unsupported or invalid protocol."
|
|
36
|
+
},
|
|
37
|
+
ERR_TLS_CERT_ALTNAME_INVALID: {
|
|
38
|
+
code: -1002,
|
|
39
|
+
message: "Certificate Invalid Alt Name: The server's SSL/TLS certificate hostname does not match the requested domain (Subject Alternative Name mismatch)."
|
|
40
|
+
},
|
|
41
|
+
ERR_TLS_HANDSHAKE_TIMEOUT: {
|
|
42
|
+
code: -1003,
|
|
43
|
+
message: "TLS Handshake Timeout: The TLS/SSL handshake timed out before completing."
|
|
44
|
+
},
|
|
45
|
+
ERR_TLS_INVALID_PROTOCOL_VERSION: {
|
|
46
|
+
code: -1004,
|
|
47
|
+
message: "Invalid TLS Protocol Version: The client and server could not agree on a mutually supported TLS/SSL protocol version."
|
|
48
|
+
},
|
|
49
|
+
ERR_TLS_RENEGOTIATION_DISABLED: {
|
|
50
|
+
code: -1005,
|
|
51
|
+
message: "TLS Renegotiation Disabled: An attempt at TLS/SSL renegotiation was made, but it is disabled or disallowed by the server/configuration."
|
|
52
|
+
},
|
|
53
|
+
ERR_TLS_CERT_SIGNATURE_ALGORITHM_UNSUPPORTED: {
|
|
54
|
+
code: -1006,
|
|
55
|
+
message: "Unsupported Cert Signature Algorithm: The signature algorithm used in the server's SSL/TLS certificate is not supported or deemed insecure by the client."
|
|
56
|
+
},
|
|
57
|
+
ERR_HTTP_HEADERS_SENT: {
|
|
58
|
+
code: -1007,
|
|
59
|
+
message: "Headers Already Sent: An attempt was made to send HTTP headers after they had already been sent (application logic error)."
|
|
60
|
+
},
|
|
61
|
+
ERR_INVALID_ARG_TYPE: {
|
|
62
|
+
code: -1008,
|
|
63
|
+
message: "Invalid Argument Type: An argument of an incorrect type was passed to the underlying HTTP(S) request function."
|
|
64
|
+
},
|
|
65
|
+
ERR_INVALID_URL: {
|
|
66
|
+
code: -1009,
|
|
67
|
+
message: "Invalid URL: The provided URL is syntactically invalid or cannot be parsed."
|
|
68
|
+
},
|
|
69
|
+
ERR_STREAM_DESTROYED: {
|
|
70
|
+
code: -1010,
|
|
71
|
+
message: "Stream Destroyed: The readable/writable stream associated with the request/response was destroyed prematurely."
|
|
72
|
+
},
|
|
73
|
+
ERR_STREAM_PREMATURE_CLOSE: {
|
|
74
|
+
code: -1011,
|
|
75
|
+
message: "Premature Stream Close: The server closed the connection before sending the complete response body (e.g., incomplete chunked encoding)."
|
|
76
|
+
},
|
|
77
|
+
UND_ERR_CONNECT_TIMEOUT: {
|
|
78
|
+
code: -1020,
|
|
79
|
+
message: "Connect Timeout (rezo): Timeout occurred specifically while waiting for the TCP socket connection to be established."
|
|
80
|
+
},
|
|
81
|
+
UND_ERR_HEADERS_TIMEOUT: {
|
|
82
|
+
code: -1021,
|
|
83
|
+
message: "Headers Timeout (rezo): Timeout occurred while waiting to receive the complete HTTP response headers from the server."
|
|
84
|
+
},
|
|
85
|
+
UND_ERR_SOCKET: {
|
|
86
|
+
code: -1022,
|
|
87
|
+
message: "Socket Error (rezo): An error occurred at the underlying socket level (may wrap other errors like ECONNRESET)."
|
|
88
|
+
},
|
|
89
|
+
UND_ERR_INFO: {
|
|
90
|
+
code: -1023,
|
|
91
|
+
message: "Invalid Request Info (rezo): Internal error related to invalid or missing metadata needed to process the request."
|
|
92
|
+
},
|
|
93
|
+
UND_ERR_ABORTED: {
|
|
94
|
+
code: -1024,
|
|
95
|
+
message: "Request Aborted (rezo): The request was explicitly aborted, often due to a timeout signal or user action."
|
|
96
|
+
},
|
|
97
|
+
ABORT_ERR: {
|
|
98
|
+
code: -1025,
|
|
99
|
+
message: "Request Aborted: The request was explicitly aborted, often due to a timeout signal or user action."
|
|
100
|
+
},
|
|
101
|
+
UND_ERR_REQUEST_TIMEOUT: {
|
|
102
|
+
code: -1026,
|
|
103
|
+
message: "Request Timeout (rezo): The request timed out (check specific connect/headers/body timeouts if applicable)."
|
|
104
|
+
},
|
|
105
|
+
UNQ_UNKOWN_ERROR: {
|
|
106
|
+
code: -9999,
|
|
107
|
+
message: "Unknown Error: An unspecified or unrecognized error occurred during the request."
|
|
108
|
+
},
|
|
109
|
+
UNQ_FILE_PERMISSION_ERROR: {
|
|
110
|
+
code: -1027,
|
|
111
|
+
message: "File Permission Error: Insufficient permissions to read or write a required file."
|
|
112
|
+
},
|
|
113
|
+
UNQ_MISSING_REDIRECT_LOCATION: {
|
|
114
|
+
code: -1028,
|
|
115
|
+
message: "Redirect Location Not Found: Redirect header (Location:) missing in the server's response for a redirect status code (3xx)."
|
|
116
|
+
},
|
|
117
|
+
UNQ_DECOMPRESSION_ERROR: {
|
|
118
|
+
code: -1029,
|
|
119
|
+
message: "Decompression Error: Failed to decompress response body. Data may be corrupt or encoding incorrect."
|
|
120
|
+
},
|
|
121
|
+
UNQ_DOWNLOAD_FAILED: {
|
|
122
|
+
code: -1030,
|
|
123
|
+
message: "Download Failed: The resource could not be fully downloaded due to an unspecified error during data transfer."
|
|
124
|
+
},
|
|
125
|
+
UNQ_HTTP_ERROR: {
|
|
126
|
+
code: -1031,
|
|
127
|
+
message: "HTTP Error: The server responded with a non-successful HTTP status code."
|
|
128
|
+
},
|
|
129
|
+
UNQ_REDIRECT_DENIED: {
|
|
130
|
+
code: -1032,
|
|
131
|
+
message: "Redirect Denied: A redirect response was received, but following redirects is disabled or disallowed by configuration/user."
|
|
132
|
+
},
|
|
133
|
+
UNQ_PROXY_INVALID_PROTOCOL: {
|
|
134
|
+
code: -1033,
|
|
135
|
+
message: "Invalid Proxy Protocol: The specified proxy URL has an invalid or unsupported protocol scheme."
|
|
136
|
+
},
|
|
137
|
+
UNQ_PROXY_INVALID_HOSTPORT: {
|
|
138
|
+
code: -1034,
|
|
139
|
+
message: "Invalid Proxy Host/Port: The hostname or port number provided for the proxy server is invalid or malformed."
|
|
140
|
+
},
|
|
141
|
+
UNQ_SOCKS_CONNECTION_FAILED: {
|
|
142
|
+
code: -1040,
|
|
143
|
+
message: "SOCKS Proxy Connection Failed: Failed to establish connection with the SOCKS proxy server (check host, port, network)."
|
|
144
|
+
},
|
|
145
|
+
UNQ_SOCKS_AUTHENTICATION_FAILED: {
|
|
146
|
+
code: -1041,
|
|
147
|
+
message: "SOCKS Proxy Authentication Failed: Authentication with the SOCKS5 proxy failed (invalid credentials or unsupported method)."
|
|
148
|
+
},
|
|
149
|
+
UNQ_SOCKS_TARGET_CONNECTION_FAILED: {
|
|
150
|
+
code: -1042,
|
|
151
|
+
message: "SOCKS Proxy Target Connection Failed: The SOCKS proxy reported failure connecting to the final destination (e.g., Connection refused, Host unreachable, Network unreachable)."
|
|
152
|
+
},
|
|
153
|
+
UNQ_SOCKS_PROTOCOL_ERROR: {
|
|
154
|
+
code: -1043,
|
|
155
|
+
message: "SOCKS Proxy Protocol Error: Invalid or malformed response received from the SOCKS proxy during handshake or connection."
|
|
156
|
+
},
|
|
157
|
+
UNQ_PROXY_ERROR: {
|
|
158
|
+
code: -1047,
|
|
159
|
+
message: "Proxy Error: An unspecified error occurred while communicating with or through the proxy server."
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
function setSignal() {
|
|
163
|
+
if (this.signal)
|
|
164
|
+
return;
|
|
165
|
+
if (this.timeoutClearInstanse)
|
|
166
|
+
clearTimeout(this.timeoutClearInstanse);
|
|
167
|
+
if (this.timeout && typeof this.timeout === "number" && this.timeout > 100) {
|
|
168
|
+
const controller = new AbortController;
|
|
169
|
+
this.timeoutClearInstanse = setTimeout(() => controller.abort(), this.timeout);
|
|
170
|
+
this.signal = controller.signal;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function getDefaultConfig(config = {}) {
|
|
174
|
+
const curl = await checkCurl();
|
|
175
|
+
return {
|
|
176
|
+
useCurl: config.curl === true,
|
|
177
|
+
isCurl: curl.status || false,
|
|
178
|
+
baseURL: config.baseURL,
|
|
179
|
+
headers: config.headers,
|
|
180
|
+
rejectUnauthorized: config.rejectUnauthorized,
|
|
181
|
+
httpAgent: config.httpAgent,
|
|
182
|
+
httpsAgent: config.httpsAgent,
|
|
183
|
+
debug: config.debug === true,
|
|
184
|
+
maxRedirects: config.maxRedirects,
|
|
185
|
+
retry: config.retry,
|
|
186
|
+
proxy: config.proxy,
|
|
187
|
+
followRedirects: config.followRedirects,
|
|
188
|
+
useCookies: config.enableCookieJar,
|
|
189
|
+
fs: await getFS(),
|
|
190
|
+
timeout: config.timeout ?? config.requestTimeout,
|
|
191
|
+
http2: config.http2 === true,
|
|
192
|
+
hooks: config.hooks,
|
|
193
|
+
cookieFile: config.cookieFile,
|
|
194
|
+
encoding: config.encoding
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
async function getFS() {
|
|
198
|
+
const type = getEnvironment();
|
|
199
|
+
if (type !== "node" && type !== "deno" && type !== "bun" && type !== "cf-worker") {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
return await import("node:fs");
|
|
204
|
+
} catch {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function prepareHTTPOptions(options, jar, addedOptions, config) {
|
|
209
|
+
const validMethods = ["post", "put", "patch"];
|
|
210
|
+
let isNew = false;
|
|
211
|
+
if (!addedOptions.isRedirected || !config || Object.keys(config).length === 0) {
|
|
212
|
+
isNew = true;
|
|
213
|
+
const settions = createConfig(options, jar, addedOptions);
|
|
214
|
+
config = { ...settions.config };
|
|
215
|
+
options = settions.options;
|
|
216
|
+
}
|
|
217
|
+
options.headers = buildHeaders(options.headers);
|
|
218
|
+
let headers = options.headers instanceof RezoHeaders ? options.headers : new RezoHeaders(options.headers || {});
|
|
219
|
+
if (options.headers.has("Cookie")) {
|
|
220
|
+
headers = new RezoHeaders(options.headers.toObject());
|
|
221
|
+
if (!config.useCookies) {
|
|
222
|
+
config.useCookies = true;
|
|
223
|
+
}
|
|
224
|
+
options.headers.delete("Cookie");
|
|
225
|
+
}
|
|
226
|
+
const mainUrl = !isNew && addedOptions.fullUrl ? addedOptions.fullUrl : undefined;
|
|
227
|
+
const forContentType = validMethods.includes(options.method.toLowerCase());
|
|
228
|
+
let fetchOptions = {};
|
|
229
|
+
if (!options.responseType) {
|
|
230
|
+
options.responseType = "auto";
|
|
231
|
+
}
|
|
232
|
+
const cookieJar = config.enableCookieJar ? jar : new RezoCookieJar(config.requestCookies);
|
|
233
|
+
let requestCookies = [];
|
|
234
|
+
fetchOptions.method = options.method;
|
|
235
|
+
if (options.fullUrl) {
|
|
236
|
+
fetchOptions.url = options.fullUrl;
|
|
237
|
+
fetchOptions.fullUrl = options.fullUrl;
|
|
238
|
+
} else {
|
|
239
|
+
fetchOptions.url = options.url;
|
|
240
|
+
}
|
|
241
|
+
let contentType = options.contentType || headers.get("Content-Type") || (forContentType ? "application/json" : undefined);
|
|
242
|
+
if (addedOptions && addedOptions.customHeaders) {
|
|
243
|
+
headers = addedOptions.customHeaders instanceof RezoHeaders ? addedOptions.customHeaders : new RezoHeaders(addedOptions.customHeaders);
|
|
244
|
+
}
|
|
245
|
+
if (headers.has("Cookie")) {
|
|
246
|
+
const cookieString = headers.get("Cookie");
|
|
247
|
+
if (config.useCookies && !addedOptions.redirectedUrl && !addedOptions.isRedirected) {
|
|
248
|
+
cookieJar.setCookiesSync(cookieString, options.url instanceof URL ? options.url.href : options.url);
|
|
249
|
+
}
|
|
250
|
+
headers.delete("Cookie");
|
|
251
|
+
if (options.headers instanceof RezoHeaders) {
|
|
252
|
+
options.headers.delete("Cookie");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
fetchOptions.headers = headers;
|
|
256
|
+
if (options.cookies && config.useCookies) {
|
|
257
|
+
cookieJar.setCookiesSync(options.cookies, options.url instanceof URL ? options.url.href : options.url);
|
|
258
|
+
delete options.cookies;
|
|
259
|
+
delete fetchOptions.cookies;
|
|
260
|
+
}
|
|
261
|
+
if (config.useCookies) {
|
|
262
|
+
if (options.cookies && !addedOptions.redirectedUrl && !addedOptions.isRedirected) {
|
|
263
|
+
cookieJar.setCookiesSync(options.cookies, options.url instanceof URL ? options.url.href : options.url);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
let cookiesString = "";
|
|
267
|
+
if (config.useCookies) {
|
|
268
|
+
requestCookies = cookieJar.getCookiesSync(options.url instanceof URL ? options.url.href : options.url).map((c) => new Cookie(c));
|
|
269
|
+
cookiesString = cookieJar.getCookieStringSync(options.url instanceof URL ? options.url.href : options.url);
|
|
270
|
+
}
|
|
271
|
+
if (options.xsrfCookieName && options.xsrfHeaderName && requestCookies.length > 0) {
|
|
272
|
+
const xsrfCookie = requestCookies.find((c) => c.key === options.xsrfCookieName);
|
|
273
|
+
if (xsrfCookie && xsrfCookie.value) {
|
|
274
|
+
fetchOptions.headers.set(options.xsrfHeaderName, xsrfCookie.value);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (requestCookies.length > 0 && config) {
|
|
278
|
+
if (!config.requestCookies) {
|
|
279
|
+
config.requestCookies = requestCookies;
|
|
280
|
+
} else {
|
|
281
|
+
for (const cookie of requestCookies) {
|
|
282
|
+
config.requestCookies = config.requestCookies.filter((c) => c.key !== cookie.key);
|
|
283
|
+
config.requestCookies.push(cookie);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (options.body) {
|
|
288
|
+
fetchOptions.body = options.body;
|
|
289
|
+
}
|
|
290
|
+
const isFormData = fetchOptions.body && (fetchOptions.body instanceof FormData || fetchOptions.body instanceof RezoFormData);
|
|
291
|
+
if (!isFormData) {
|
|
292
|
+
if (options.multipart || options.json || options.formData || options.form) {
|
|
293
|
+
if (options.formData || options.multipart) {
|
|
294
|
+
if (options.multipart instanceof RezoFormData || options.formData instanceof RezoFormData) {
|
|
295
|
+
const body = options.multipart instanceof RezoFormData ? options.multipart : options.formData;
|
|
296
|
+
contentType = body.getContentType();
|
|
297
|
+
fetchOptions.body = body;
|
|
298
|
+
} else {
|
|
299
|
+
const body = new RezoFormData;
|
|
300
|
+
const _body = options.formData || options.multipart;
|
|
301
|
+
if (_body) {
|
|
302
|
+
Object.entries(_body).forEach(([key, value]) => {
|
|
303
|
+
body.append(key, value);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
contentType = body.getContentType();
|
|
307
|
+
fetchOptions.body = body;
|
|
308
|
+
}
|
|
309
|
+
fetchOptions.headers.set("Content-Type", contentType);
|
|
310
|
+
} else if (options.form) {
|
|
311
|
+
contentType = "application/x-www-form-urlencoded";
|
|
312
|
+
if (typeof options.form === "object") {
|
|
313
|
+
fetchOptions.body = new RezoURLSearchParams(options.form).toString();
|
|
314
|
+
} else {
|
|
315
|
+
fetchOptions.body = options.form;
|
|
316
|
+
}
|
|
317
|
+
fetchOptions.headers.set("Content-Type", contentType);
|
|
318
|
+
} else if (options.json) {
|
|
319
|
+
fetchOptions.body = options.body;
|
|
320
|
+
contentType = "application/json";
|
|
321
|
+
fetchOptions.headers.set("Content-Type", contentType);
|
|
322
|
+
}
|
|
323
|
+
} else if (contentType) {
|
|
324
|
+
const type = contentType.toLowerCase();
|
|
325
|
+
if (type.includes("json")) {
|
|
326
|
+
fetchOptions.headers.set("Content-Type", "application/json");
|
|
327
|
+
if (fetchOptions.body && typeof fetchOptions.body === "object") {
|
|
328
|
+
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
|
329
|
+
}
|
|
330
|
+
} else if (type.includes("x-www-form-urlencoded")) {
|
|
331
|
+
fetchOptions.headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
332
|
+
if (fetchOptions.body && typeof fetchOptions.body === "object") {
|
|
333
|
+
fetchOptions.body = new URLSearchParams(fetchOptions.body).toString();
|
|
334
|
+
}
|
|
335
|
+
} else if (type.includes("multipart")) {
|
|
336
|
+
if (fetchOptions.body && typeof fetchOptions.body === "object") {
|
|
337
|
+
const formData = new RezoFormData;
|
|
338
|
+
Object.entries(fetchOptions.body).forEach(([key, value]) => {
|
|
339
|
+
formData.append(key, value);
|
|
340
|
+
});
|
|
341
|
+
fetchOptions.body = formData;
|
|
342
|
+
}
|
|
343
|
+
} else if (type.includes("text/") || type.includes("/javascript")) {
|
|
344
|
+
fetchOptions.body = fetchOptions.body ? typeof fetchOptions.body === "object" ? JSON.stringify(fetchOptions.body) : fetchOptions.body : "";
|
|
345
|
+
fetchOptions.headers.set("Content-Type", contentType);
|
|
346
|
+
}
|
|
347
|
+
} else if (contentType && !options.withoutContentType) {
|
|
348
|
+
fetchOptions.headers.set("Content-Type", contentType);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (options.withoutContentType || isFormData) {
|
|
352
|
+
fetchOptions.headers.delete("Content-Type");
|
|
353
|
+
}
|
|
354
|
+
if (options.withoutBodyOnRedirect && addedOptions.isRedirected) {
|
|
355
|
+
fetchOptions.body = undefined;
|
|
356
|
+
}
|
|
357
|
+
options.rejectUnauthorized = config.rejectUnauthorized;
|
|
358
|
+
if ((typeof options.autoSetReferer !== "boolean" || options.autoSetReferer) && addedOptions.redirectedUrl) {
|
|
359
|
+
if (!addedOptions.customHeaders)
|
|
360
|
+
fetchOptions.headers.set("Referer", addedOptions.redirectedUrl);
|
|
361
|
+
}
|
|
362
|
+
if (!config.useCookies) {
|
|
363
|
+
fetchOptions.headers.delete("Cookie");
|
|
364
|
+
}
|
|
365
|
+
if (fetchOptions.body && (fetchOptions.body instanceof FormData || fetchOptions.body instanceof RezoFormData)) {
|
|
366
|
+
fetchOptions.headers.delete("Content-Type");
|
|
367
|
+
}
|
|
368
|
+
if (options.proxy) {
|
|
369
|
+
fetchOptions.proxy = options.proxy;
|
|
370
|
+
}
|
|
371
|
+
if (fetchOptions.method.toLowerCase() === "get" && fetchOptions.headers.has("Content-Type")) {
|
|
372
|
+
fetchOptions.headers.delete("Content-Type");
|
|
373
|
+
}
|
|
374
|
+
if (mainUrl || addedOptions.redirectedUrl) {
|
|
375
|
+
fetchOptions.headers.set("host", new URL(fetchOptions.fullUrl).host);
|
|
376
|
+
if ([`POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`].includes(fetchOptions.method.toUpperCase()))
|
|
377
|
+
fetchOptions.headers.set("origin", new URL(mainUrl || fetchOptions.url).origin);
|
|
378
|
+
} else {
|
|
379
|
+
if (!fetchOptions.headers.has("origin") && options.autoSetOrigin) {
|
|
380
|
+
const r = [`POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`].includes(fetchOptions.method.toUpperCase());
|
|
381
|
+
if (r)
|
|
382
|
+
fetchOptions.headers.set("origin", new URL(mainUrl || fetchOptions.url).origin);
|
|
383
|
+
}
|
|
384
|
+
if (mainUrl && !fetchOptions.headers.has("referer") && options.autoSetReferer) {
|
|
385
|
+
fetchOptions.headers.set("referer", mainUrl);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (addedOptions.redirectCode && addedOptions.lastRedirectedUrl) {
|
|
389
|
+
fetchOptions.headers.set("referer", addedOptions.lastRedirectedUrl);
|
|
390
|
+
}
|
|
391
|
+
if (options.responseType) {
|
|
392
|
+
fetchOptions.responseType = options.responseType;
|
|
393
|
+
}
|
|
394
|
+
if (options.httpAgent) {
|
|
395
|
+
fetchOptions.httpAgent = options.httpAgent;
|
|
396
|
+
}
|
|
397
|
+
if (options.httpsAgent) {
|
|
398
|
+
fetchOptions.httpsAgent = options.httpsAgent;
|
|
399
|
+
}
|
|
400
|
+
if (isNew && config) {
|
|
401
|
+
config.originalRequest = fetchOptions;
|
|
402
|
+
}
|
|
403
|
+
fetchOptions.rejectUnauthorized = options.rejectUnauthorized;
|
|
404
|
+
if (options.sessionId) {
|
|
405
|
+
fetchOptions.sessionId = options.sessionId;
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
fetchOptions,
|
|
409
|
+
config,
|
|
410
|
+
options
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function buildHeaders(headers) {
|
|
414
|
+
return headers = headers instanceof RezoHeaders ? headers : new RezoHeaders(headers);
|
|
415
|
+
}
|
|
416
|
+
function createConfig(options, jar, addedOptions) {
|
|
417
|
+
const { defaultOptions } = addedOptions;
|
|
418
|
+
const { fs } = defaultOptions;
|
|
419
|
+
const rawUrl = typeof options.url === "string" ? options.url : options.url.toString();
|
|
420
|
+
options["debug"] = options.debug ?? defaultOptions.debug;
|
|
421
|
+
const {
|
|
422
|
+
autoSetOrigin = false,
|
|
423
|
+
autoSetReferer = false,
|
|
424
|
+
useCookies = typeof defaultOptions.useCookies === "boolean" ? defaultOptions.useCookies : undefined,
|
|
425
|
+
httpAgent = defaultOptions.httpAgent,
|
|
426
|
+
rejectUnauthorized = defaultOptions.rejectUnauthorized,
|
|
427
|
+
httpsAgent = defaultOptions.httpsAgent,
|
|
428
|
+
followRedirects = true,
|
|
429
|
+
withCredentials = typeof defaultOptions.withCredentials === "boolean" ? defaultOptions.withCredentials : undefined,
|
|
430
|
+
enableRedirectCycleDetection = typeof defaultOptions.enableRedirectCycleDetection === "boolean" ? defaultOptions.enableRedirectCycleDetection : false
|
|
431
|
+
} = options;
|
|
432
|
+
delete options.autoSetOrigin;
|
|
433
|
+
delete options.autoSetReferer;
|
|
434
|
+
const requestOptions = {
|
|
435
|
+
...options,
|
|
436
|
+
autoSetOrigin,
|
|
437
|
+
autoSetReferer,
|
|
438
|
+
useCookies,
|
|
439
|
+
followRedirects,
|
|
440
|
+
httpsAgent,
|
|
441
|
+
httpAgent
|
|
442
|
+
};
|
|
443
|
+
if (typeof requestOptions.treat302As303 === "undefined") {
|
|
444
|
+
requestOptions.treat302As303 = true;
|
|
445
|
+
}
|
|
446
|
+
requestOptions.useCookies = typeof useCookies === "boolean" ? useCookies : typeof withCredentials === "boolean" ? withCredentials : true;
|
|
447
|
+
requestOptions.proxy = requestOptions.proxy || defaultOptions.proxy;
|
|
448
|
+
const debug = requestOptions.debug !== undefined ? requestOptions.debug : false;
|
|
449
|
+
const type = getEnvironment();
|
|
450
|
+
if (type !== "node" && type !== "bun" && type !== "deno") {
|
|
451
|
+
if (httpAgent || httpsAgent) {
|
|
452
|
+
throw new Error(`Custom HTTP or HTTPS agents are not supported in '${type}' mode. Please remove 'httpAgent' or 'httpsAgent'.`);
|
|
453
|
+
}
|
|
454
|
+
if (rejectUnauthorized && debug) {
|
|
455
|
+
console.warn(`[WARNING] 'rejectUnauthorized' is enabled in '${type}' mode.
|
|
456
|
+
The built-in fetch API does not support this option directly.
|
|
457
|
+
As a workaround, process.env.NODE_TLS_REJECT_UNAUTHORIZED is being set to '0'.
|
|
458
|
+
` + `⚠️ This disables TLS certificate verification and can expose sensitive data.
|
|
459
|
+
` + `⚠️ Avoid using 'rejectUnauthorized' in '${type}' environments unless absolutely necessary.`);
|
|
460
|
+
if (typeof process !== "undefined")
|
|
461
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const methods = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
465
|
+
const method = methods && methods.includes(options.method.toUpperCase()) ? options.method?.toUpperCase() : "GET";
|
|
466
|
+
requestOptions.method = method;
|
|
467
|
+
if (options.startNewRequest)
|
|
468
|
+
jar?.removeAllCookiesSync();
|
|
469
|
+
const maxRedirects = requestOptions.maxRedirects || 10;
|
|
470
|
+
const saveTo = requestOptions.saveTo || requestOptions.fileName;
|
|
471
|
+
let fileName = undefined;
|
|
472
|
+
requestOptions.timeout = requestOptions.timeout ?? defaultOptions.timeout;
|
|
473
|
+
if (defaultOptions.retry && !requestOptions.retry) {
|
|
474
|
+
requestOptions.retry = {
|
|
475
|
+
maxRetries: defaultOptions.retry.maxRetries && typeof defaultOptions.retry.maxRetries === "number" ? defaultOptions.retry.maxRetries : 0,
|
|
476
|
+
retryDelay: defaultOptions.retry.retryDelay && typeof defaultOptions.retry.retryDelay === "number" ? defaultOptions.retry.retryDelay : 0,
|
|
477
|
+
incrementDelay: defaultOptions.retry.incrementDelay && typeof defaultOptions.retry.incrementDelay === "boolean" ? defaultOptions.retry.incrementDelay : false,
|
|
478
|
+
condition: defaultOptions.retry.condition,
|
|
479
|
+
statusCodes: defaultOptions.retry.statusCodes || [408, 429, 500, 502, 503, 504, 425, 520]
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
requestOptions.followRedirects = typeof requestOptions.followRedirects === "boolean" ? requestOptions.followRedirects : typeof defaultOptions.followRedirects === "boolean" ? defaultOptions.followRedirects : true;
|
|
483
|
+
const retryLimit = typeof requestOptions?.retry?.maxRetries === "number" && requestOptions?.retry?.maxRetries > 0 ? requestOptions?.retry?.maxRetries : 0;
|
|
484
|
+
const retryDelay = typeof requestOptions?.retry?.retryDelay === "number" && requestOptions?.retry?.retryDelay > 0 ? requestOptions?.retry?.retryDelay : 0;
|
|
485
|
+
const retryIncrementDelay = typeof requestOptions?.retry?.incrementDelay === "boolean" ? requestOptions?.retry?.incrementDelay : false;
|
|
486
|
+
const statusCodes = Array.isArray(requestOptions?.retry?.statusCodes) && requestOptions.retry.statusCodes.length > 0 ? requestOptions.retry.statusCodes : [408, 429, 500, 502, 503, 504, 425, 520];
|
|
487
|
+
const redirectCount = 0;
|
|
488
|
+
const params = new RezoURLSearchParams(options.params || {});
|
|
489
|
+
const baseURL = requestOptions.baseURL && (requestOptions.baseURL.startsWith("http://") || requestOptions.baseURL.startsWith("https://")) ? requestOptions.baseURL : defaultOptions.baseURL && (defaultOptions.baseURL.startsWith("http://") || defaultOptions.baseURL.startsWith("https://")) ? defaultOptions.baseURL : undefined;
|
|
490
|
+
const url = new URL(options.url, baseURL);
|
|
491
|
+
params.forEach((value, key) => {
|
|
492
|
+
if (value && !url.searchParams.has(key)) {
|
|
493
|
+
url.searchParams.append(key, value);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
requestOptions.fullUrl = url.href;
|
|
497
|
+
requestOptions.url = options.url;
|
|
498
|
+
requestOptions.baseURL = options.baseURL;
|
|
499
|
+
requestOptions.params = options.params;
|
|
500
|
+
requestOptions["method"] = method;
|
|
501
|
+
requestOptions["headers"] = parseInputHeaders(requestOptions.headers, defaultOptions.headers);
|
|
502
|
+
requestOptions["debug"] = requestOptions["debug"] !== undefined ? requestOptions["debug"] : defaultOptions.debug;
|
|
503
|
+
requestOptions.proxy = typeof requestOptions.proxy === "string" ? parseProxyString(requestOptions.proxy) : requestOptions.proxy;
|
|
504
|
+
requestOptions.useCookies = useCookies;
|
|
505
|
+
const normalizedProxy = requestOptions.proxy ? typeof requestOptions.proxy === "string" ? parseProxyString(requestOptions.proxy) : requestOptions.proxy : null;
|
|
506
|
+
const config = {
|
|
507
|
+
url: requestOptions.url,
|
|
508
|
+
rawUrl,
|
|
509
|
+
baseURL: requestOptions.baseURL || url.origin,
|
|
510
|
+
params: requestOptions.params || {},
|
|
511
|
+
method: requestOptions.method,
|
|
512
|
+
headers: requestOptions.headers,
|
|
513
|
+
maxRedirects,
|
|
514
|
+
retryAttempts: 0,
|
|
515
|
+
http2: requestOptions.http2 === true,
|
|
516
|
+
curl: requestOptions.curl === true,
|
|
517
|
+
timeout: typeof requestOptions.timeout === "number" ? requestOptions.timeout : null,
|
|
518
|
+
enableCookieJar: typeof defaultOptions.enableCookieJar === "boolean" ? defaultOptions.enableCookieJar : true,
|
|
519
|
+
useCookies: typeof requestOptions.useCookies === "boolean" ? requestOptions.useCookies : true,
|
|
520
|
+
cookieJar: requestOptions.cookieJar || jar,
|
|
521
|
+
retry: {
|
|
522
|
+
maxRetries: retryLimit,
|
|
523
|
+
retryDelay,
|
|
524
|
+
incrementDelay: retryIncrementDelay,
|
|
525
|
+
statusCodes,
|
|
526
|
+
condition: requestOptions.retry?.condition || defaultOptions.retry?.condition || ((error) => {
|
|
527
|
+
return error;
|
|
528
|
+
})
|
|
529
|
+
},
|
|
530
|
+
originalRequest: requestOptions,
|
|
531
|
+
redirectCount,
|
|
532
|
+
redirectHistory: [],
|
|
533
|
+
network: {},
|
|
534
|
+
timing: {},
|
|
535
|
+
responseType: requestOptions.responseType,
|
|
536
|
+
proxy: normalizedProxy,
|
|
537
|
+
enableRedirectCycleDetection,
|
|
538
|
+
rejectUnauthorized: typeof rejectUnauthorized === "boolean" ? rejectUnauthorized : true
|
|
539
|
+
};
|
|
540
|
+
config.setSignal = setSignal.bind(config);
|
|
541
|
+
if (requestOptions.encoding || defaultOptions.encoding) {
|
|
542
|
+
config.encoding = requestOptions.encoding || defaultOptions.encoding;
|
|
543
|
+
}
|
|
544
|
+
if (requestOptions.beforeRedirect || defaultOptions.beforeRedirect) {
|
|
545
|
+
config.beforeRedirect = requestOptions.beforeRedirect || defaultOptions.beforeRedirect;
|
|
546
|
+
}
|
|
547
|
+
config.requestCookies = [];
|
|
548
|
+
config.responseCookies = {
|
|
549
|
+
array: [],
|
|
550
|
+
serialized: [],
|
|
551
|
+
netscape: `# Netscape HTTP Cookie File
|
|
552
|
+
# This file was generated by Rezo HTTP client
|
|
553
|
+
# Based on uniqhtt cookie implementation
|
|
554
|
+
`,
|
|
555
|
+
string: "",
|
|
556
|
+
setCookiesString: []
|
|
557
|
+
};
|
|
558
|
+
config.cookieFile = defaultOptions.cookieFile || jar.cookieFile || null;
|
|
559
|
+
const baseHooks = mergeHooks(createDefaultHooks(), defaultOptions.hooks || {});
|
|
560
|
+
const mergedHooks = mergeHooks(baseHooks, requestOptions.hooks || {});
|
|
561
|
+
config.hooks = serializeHooks(mergedHooks);
|
|
562
|
+
if (typeof config.enableCookieJar !== "boolean") {
|
|
563
|
+
config.enableCookieJar = true;
|
|
564
|
+
}
|
|
565
|
+
if (!config.enableCookieJar) {
|
|
566
|
+
config.cookieJar = new RezoCookieJar;
|
|
567
|
+
}
|
|
568
|
+
if (options.httpAgent) {
|
|
569
|
+
config.httpAgent = options.httpAgent;
|
|
570
|
+
}
|
|
571
|
+
if (options.httpsAgent) {
|
|
572
|
+
config.httpsAgent = options.httpsAgent;
|
|
573
|
+
}
|
|
574
|
+
const isSupportedRuntime = type === "node" || type === "bun" || type === "deno";
|
|
575
|
+
if (requestOptions.curl && !defaultOptions.isCurl && debug) {
|
|
576
|
+
const recommendations = isSupportedRuntime ? `Recommendations:
|
|
577
|
+
` + `• Only enable 'curl' mode when absolutely necessary
|
|
578
|
+
` + `• Verify curl is installed and up-to-date on your system
|
|
579
|
+
` + `• For enhanced security, consider using native Rezo HTTP clients instead` : "";
|
|
580
|
+
console.warn(`⚠️ [WARNING]: ${isSupportedRuntime ? `Curl binary not detected in your environment while 'curl' mode is enabled` : `'curl' mode is not supported in '${type}' environment`}
|
|
581
|
+
|
|
582
|
+
` + recommendations);
|
|
583
|
+
}
|
|
584
|
+
if (saveTo) {
|
|
585
|
+
if (!isSupportedRuntime) {
|
|
586
|
+
throw new Error(`You can only use this feature in Node.js, Deno or Bun and not available in Edge or Browser.`);
|
|
587
|
+
} else if (!fs) {
|
|
588
|
+
throw new Error(`You can only use this feature in nodejs module, not in Edge module.`);
|
|
589
|
+
}
|
|
590
|
+
const name = path.basename(saveTo);
|
|
591
|
+
if (checkISPermission && checkISPermission(saveTo.length ? path.dirname(saveTo) : path.resolve(process.cwd()), fs)) {
|
|
592
|
+
const dir = name.length < saveTo.length ? path.dirname(saveTo) : path.join(process.cwd(), "download");
|
|
593
|
+
if (!fs.existsSync(dir)) {
|
|
594
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
595
|
+
}
|
|
596
|
+
fileName = path.join(dir, name);
|
|
597
|
+
config.fileName = fileName;
|
|
598
|
+
} else {
|
|
599
|
+
throw new Error(`Permission denied to save to ${saveTo}`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
config,
|
|
604
|
+
options: requestOptions
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
function getEnvironment() {
|
|
608
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
609
|
+
return "node";
|
|
610
|
+
}
|
|
611
|
+
if (typeof Bun !== "undefined") {
|
|
612
|
+
return "bun";
|
|
613
|
+
}
|
|
614
|
+
if (typeof Deno !== "undefined") {
|
|
615
|
+
return "deno";
|
|
616
|
+
}
|
|
617
|
+
if (typeof caches !== "undefined" && typeof Request !== "undefined" && typeof Response !== "undefined" && typeof addEventListener !== "undefined" && typeof importScripts === "undefined" && typeof window === "undefined") {
|
|
618
|
+
return "cf-worker";
|
|
619
|
+
}
|
|
620
|
+
if (typeof self !== "undefined" && typeof importScripts !== "undefined" && typeof caches !== "undefined" && "serviceWorker" in navigator) {
|
|
621
|
+
return "service-worker";
|
|
622
|
+
}
|
|
623
|
+
if (typeof self !== "undefined" && typeof importScripts !== "undefined" && typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope && typeof window === "undefined") {
|
|
624
|
+
return "web-worker";
|
|
625
|
+
}
|
|
626
|
+
if (typeof WorkerGlobalScope !== "undefined" && typeof self !== "undefined" && self instanceof WorkerGlobalScope) {
|
|
627
|
+
return "worker";
|
|
628
|
+
}
|
|
629
|
+
if (typeof window !== "undefined" && typeof document !== "undefined" && typeof navigator !== "undefined") {
|
|
630
|
+
return "browser";
|
|
631
|
+
}
|
|
632
|
+
return "unknown";
|
|
633
|
+
}
|
|
634
|
+
function parseInputHeaders(headers, defaultHeaders) {
|
|
635
|
+
const requestHeaders = headers instanceof RezoHeaders ? headers : new RezoHeaders(headers !== undefined ? headers : {});
|
|
636
|
+
defaultHeaders = defaultHeaders instanceof RezoHeaders ? defaultHeaders : new RezoHeaders(defaultHeaders !== undefined ? defaultHeaders : {});
|
|
637
|
+
if (defaultHeaders instanceof RezoHeaders) {
|
|
638
|
+
defaultHeaders.forEach((value, key) => {
|
|
639
|
+
if (value && !requestHeaders.has(key)) {
|
|
640
|
+
requestHeaders.append(key, value);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
return requestHeaders;
|
|
645
|
+
}
|
|
646
|
+
function getCode(code) {
|
|
647
|
+
const error = ERROR_INFO[code];
|
|
648
|
+
if (error) {
|
|
649
|
+
return {
|
|
650
|
+
code,
|
|
651
|
+
errno: error.code,
|
|
652
|
+
message: error.message
|
|
653
|
+
};
|
|
654
|
+
} else {
|
|
655
|
+
const error = ERROR_INFO["UNQ_UNKOWN_ERROR"];
|
|
656
|
+
return {
|
|
657
|
+
code: "UNQ_UNKOWN_ERROR",
|
|
658
|
+
errno: error.code,
|
|
659
|
+
message: error.message
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function checkISPermission(currentDir, fs) {
|
|
664
|
+
try {
|
|
665
|
+
fs.accessSync(currentDir, fs.constants.R_OK | fs.constants.W_OK);
|
|
666
|
+
return true;
|
|
667
|
+
} catch {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
async function checkCurl() {
|
|
672
|
+
const type = getEnvironment();
|
|
673
|
+
if (type !== "node" && type !== "deno" && type !== "bun") {
|
|
674
|
+
return { status: false };
|
|
675
|
+
}
|
|
676
|
+
const { execSync } = await import("node:child_process");
|
|
677
|
+
try {
|
|
678
|
+
return curlCheckOption(execSync("curl --version").toString().includes("curl"));
|
|
679
|
+
} catch {
|
|
680
|
+
return curlCheckOption();
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
async function curlCheckOption(isAvailable) {
|
|
684
|
+
const type = getEnvironment();
|
|
685
|
+
if (type !== "node" && type !== "deno" && type !== "bun") {
|
|
686
|
+
return { status: false };
|
|
687
|
+
}
|
|
688
|
+
const { existsSync } = await import("node:fs");
|
|
689
|
+
const os = await import("node:os");
|
|
690
|
+
if (isAvailable)
|
|
691
|
+
return { status: true };
|
|
692
|
+
let message = "Curl is not installed. ";
|
|
693
|
+
const platform = os.platform();
|
|
694
|
+
if (platform === "darwin") {
|
|
695
|
+
message += "Install curl via Homebrew with 'brew install curl' or use 'xcode-select --install' to install command line tools.";
|
|
696
|
+
} else if (platform === "win32") {
|
|
697
|
+
message += "Install curl by downloading it from https://curl.se/windows/ or use a package manager like Chocolatey with 'choco install curl'.";
|
|
698
|
+
} else if (platform === "linux") {
|
|
699
|
+
const isDebian = existsSync("/etc/debian_version");
|
|
700
|
+
const isRedHat = existsSync("/etc/redhat-release");
|
|
701
|
+
const isArch = existsSync("/etc/arch-release");
|
|
702
|
+
if (isDebian) {
|
|
703
|
+
message += "Install curl with 'sudo apt-get install curl'.";
|
|
704
|
+
} else if (isRedHat) {
|
|
705
|
+
message += "Install curl with 'sudo dnf install curl' or 'sudo yum install curl'.";
|
|
706
|
+
} else if (isArch) {
|
|
707
|
+
message += "Install curl with 'sudo pacman -S curl'.";
|
|
708
|
+
} else {
|
|
709
|
+
message += "Install curl using your distribution's package manager.";
|
|
710
|
+
}
|
|
711
|
+
} else {
|
|
712
|
+
message += "Please install curl from https://curl.se/download.html";
|
|
713
|
+
}
|
|
714
|
+
return {
|
|
715
|
+
status: false,
|
|
716
|
+
message
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
721
|
+
exports.getFS = getFS;
|
|
722
|
+
exports.prepareHTTPOptions = prepareHTTPOptions;
|
|
723
|
+
exports.getCode = getCode;
|