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,2136 @@
|
|
|
1
|
+
import NodeFormData from 'form-data';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { Agent as HttpAgent, OutgoingHttpHeaders } from 'node:http';
|
|
4
|
+
import { Agent as HttpsAgent } from 'node:https';
|
|
5
|
+
import { Socket } from 'node:net';
|
|
6
|
+
import { Readable, Writable, WritableOptions } from 'node:stream';
|
|
7
|
+
import { SecureContext, TLSSocket } from 'node:tls';
|
|
8
|
+
import PQueue from 'p-queue';
|
|
9
|
+
import { Options as Options$1, QueueAddOptions } from 'p-queue';
|
|
10
|
+
import PriorityQueue from 'p-queue/dist/priority-queue';
|
|
11
|
+
import { Cookie as TouchCookie, CookieJar as TouchCookieJar, CreateCookieOptions } from 'tough-cookie';
|
|
12
|
+
|
|
13
|
+
export interface RezoHttpHeaders {
|
|
14
|
+
accept?: string | undefined;
|
|
15
|
+
"accept-encoding"?: string | undefined;
|
|
16
|
+
"accept-language"?: string | undefined;
|
|
17
|
+
"accept-patch"?: string | undefined;
|
|
18
|
+
"accept-ranges"?: string | undefined;
|
|
19
|
+
"access-control-allow-credentials"?: string | undefined;
|
|
20
|
+
"access-control-allow-headers"?: string | undefined;
|
|
21
|
+
"access-control-allow-methods"?: string | undefined;
|
|
22
|
+
"access-control-allow-origin"?: string | undefined;
|
|
23
|
+
"access-control-expose-headers"?: string | undefined;
|
|
24
|
+
"access-control-max-age"?: string | undefined;
|
|
25
|
+
"access-control-request-headers"?: string | undefined;
|
|
26
|
+
"access-control-request-method"?: string | undefined;
|
|
27
|
+
age?: string | undefined;
|
|
28
|
+
allow?: string | undefined;
|
|
29
|
+
"alt-svc"?: string | undefined;
|
|
30
|
+
authorization?: string | undefined;
|
|
31
|
+
"cache-control"?: string | undefined;
|
|
32
|
+
connection?: string | undefined;
|
|
33
|
+
"content-disposition"?: string | undefined;
|
|
34
|
+
"content-encoding"?: string | undefined;
|
|
35
|
+
"content-language"?: string | undefined;
|
|
36
|
+
"content-length"?: string | undefined;
|
|
37
|
+
"content-location"?: string | undefined;
|
|
38
|
+
"content-range"?: string | undefined;
|
|
39
|
+
"content-type"?: string | undefined;
|
|
40
|
+
cookie?: string | undefined;
|
|
41
|
+
date?: string | undefined;
|
|
42
|
+
etag?: string | undefined;
|
|
43
|
+
expect?: string | undefined;
|
|
44
|
+
expires?: string | undefined;
|
|
45
|
+
forwarded?: string | undefined;
|
|
46
|
+
from?: string | undefined;
|
|
47
|
+
host?: string | undefined;
|
|
48
|
+
"if-match"?: string | undefined;
|
|
49
|
+
"if-modified-since"?: string | undefined;
|
|
50
|
+
"if-none-match"?: string | undefined;
|
|
51
|
+
"if-unmodified-since"?: string | undefined;
|
|
52
|
+
"last-modified"?: string | undefined;
|
|
53
|
+
location?: string | undefined;
|
|
54
|
+
origin?: string | undefined;
|
|
55
|
+
pragma?: string | undefined;
|
|
56
|
+
"proxy-authenticate"?: string | undefined;
|
|
57
|
+
"proxy-authorization"?: string | undefined;
|
|
58
|
+
"public-key-pins"?: string | undefined;
|
|
59
|
+
range?: string | undefined;
|
|
60
|
+
referer?: string | undefined;
|
|
61
|
+
"retry-after"?: string | undefined;
|
|
62
|
+
"sec-fetch-site"?: string | undefined;
|
|
63
|
+
"sec-fetch-mode"?: string | undefined;
|
|
64
|
+
"sec-fetch-user"?: string | undefined;
|
|
65
|
+
"sec-fetch-dest"?: string | undefined;
|
|
66
|
+
"sec-websocket-accept"?: string | undefined;
|
|
67
|
+
"sec-websocket-extensions"?: string | undefined;
|
|
68
|
+
"sec-websocket-key"?: string | undefined;
|
|
69
|
+
"sec-websocket-protocol"?: string | undefined;
|
|
70
|
+
"sec-websocket-version"?: string | undefined;
|
|
71
|
+
"strict-transport-security"?: string | undefined;
|
|
72
|
+
tk?: string | undefined;
|
|
73
|
+
trailer?: string | undefined;
|
|
74
|
+
"transfer-encoding"?: string | undefined;
|
|
75
|
+
upgrade?: string | undefined;
|
|
76
|
+
"user-agent"?: string | undefined;
|
|
77
|
+
vary?: string | undefined;
|
|
78
|
+
via?: string | undefined;
|
|
79
|
+
warning?: string | undefined;
|
|
80
|
+
"www-authenticate"?: string | undefined;
|
|
81
|
+
"accept-charset"?: string | undefined;
|
|
82
|
+
"cdn-cache-control"?: string | undefined;
|
|
83
|
+
"content-security-policy"?: string | undefined;
|
|
84
|
+
"content-security-policy-report-only"?: string | undefined;
|
|
85
|
+
dav?: string | undefined;
|
|
86
|
+
dnt?: string | undefined;
|
|
87
|
+
"if-range"?: string | undefined;
|
|
88
|
+
link?: string | undefined;
|
|
89
|
+
"max-forwards"?: string | undefined;
|
|
90
|
+
"public-key-pins-report-only"?: string | undefined;
|
|
91
|
+
"referrer-policy"?: string | undefined;
|
|
92
|
+
refresh?: string | undefined;
|
|
93
|
+
server?: string | undefined;
|
|
94
|
+
te?: string | undefined;
|
|
95
|
+
"upgrade-insecure-requests"?: string | undefined;
|
|
96
|
+
"x-content-type-options"?: string | undefined;
|
|
97
|
+
"x-dns-prefetch-control"?: string | undefined;
|
|
98
|
+
"x-frame-options"?: string | undefined;
|
|
99
|
+
"x-xss-protection"?: string | undefined;
|
|
100
|
+
"set-cookie"?: string[];
|
|
101
|
+
}
|
|
102
|
+
export type RezoHeadersInit = [
|
|
103
|
+
string,
|
|
104
|
+
string
|
|
105
|
+
][] | Record<string, string> | Headers | RezoHttpHeaders | RezoHeaders | OutgoingHttpHeaders;
|
|
106
|
+
declare class RezoHeaders extends Headers {
|
|
107
|
+
constructor(init?: RezoHeadersInit);
|
|
108
|
+
getAll(name: "set-cookie" | "Set-Cookie"): string[];
|
|
109
|
+
getSetCookie(): string[];
|
|
110
|
+
get size(): number;
|
|
111
|
+
setContentType(value: string): this;
|
|
112
|
+
getContentType(): string | undefined;
|
|
113
|
+
setAuthorization(value: string): this;
|
|
114
|
+
setUserAgent(value: string): this;
|
|
115
|
+
getUserAgent(): string | undefined;
|
|
116
|
+
getKeys(): string[];
|
|
117
|
+
getValues(): string[];
|
|
118
|
+
toEntries(): [
|
|
119
|
+
string,
|
|
120
|
+
string | string
|
|
121
|
+
][];
|
|
122
|
+
toNative(): Headers;
|
|
123
|
+
toRaw(): [
|
|
124
|
+
string,
|
|
125
|
+
string
|
|
126
|
+
][];
|
|
127
|
+
toArray(): {
|
|
128
|
+
key: string;
|
|
129
|
+
value: string;
|
|
130
|
+
}[];
|
|
131
|
+
toObject(omit?: Array<keyof RezoHttpHeaders> | keyof RezoHttpHeaders): Record<string, string | string[]>;
|
|
132
|
+
toString(): string;
|
|
133
|
+
set(name: keyof RezoHttpHeaders, value: string): void;
|
|
134
|
+
set(name: string, value: string): void;
|
|
135
|
+
append(name: keyof RezoHttpHeaders, value: string): void;
|
|
136
|
+
append(name: string, value: string): void;
|
|
137
|
+
get(name: keyof RezoHttpHeaders): string | null;
|
|
138
|
+
get(name: string): string | null;
|
|
139
|
+
has(name: keyof RezoHttpHeaders): boolean;
|
|
140
|
+
has(name: string): boolean;
|
|
141
|
+
[Symbol.iterator](): ArrayIterator<[
|
|
142
|
+
string,
|
|
143
|
+
string | string[]
|
|
144
|
+
]>;
|
|
145
|
+
[util.inspect.custom](_depth: number, options: util.InspectOptionsStylized): string;
|
|
146
|
+
get [Symbol.toStringTag](): string;
|
|
147
|
+
}
|
|
148
|
+
export interface SerializedCookie {
|
|
149
|
+
key: string;
|
|
150
|
+
value: string;
|
|
151
|
+
expires?: string;
|
|
152
|
+
maxAge?: number | "Infinity" | "-Infinity";
|
|
153
|
+
domain?: string;
|
|
154
|
+
path?: string;
|
|
155
|
+
secure?: boolean;
|
|
156
|
+
hostOnly?: boolean;
|
|
157
|
+
creation?: string;
|
|
158
|
+
lastAccessed?: string;
|
|
159
|
+
[key: string]: unknown;
|
|
160
|
+
}
|
|
161
|
+
declare class Cookie extends TouchCookie {
|
|
162
|
+
constructor(options?: CreateCookieOptions);
|
|
163
|
+
/**
|
|
164
|
+
* Fixes date fields that may have become strings during JSON deserialization.
|
|
165
|
+
* This is a workaround for tough-cookie's deserialization behavior in Bun/Node.js
|
|
166
|
+
* where Date objects become ISO strings.
|
|
167
|
+
*/
|
|
168
|
+
private fixDateFields;
|
|
169
|
+
private getExpires;
|
|
170
|
+
toNetscapeFormat(): string;
|
|
171
|
+
toSetCookieString(): string;
|
|
172
|
+
/**
|
|
173
|
+
* Retrieves the complete URL from the cookie object
|
|
174
|
+
* @returns {string | undefined} The complete URL including protocol, domain and path. Returns undefined if domain is not set
|
|
175
|
+
* @example
|
|
176
|
+
* const cookie = new Cookie({
|
|
177
|
+
* domain: "example.com",
|
|
178
|
+
* path: "/path",
|
|
179
|
+
* secure: true
|
|
180
|
+
* });
|
|
181
|
+
* cookie.getURL(); // Returns: "https://example.com/path"
|
|
182
|
+
*/
|
|
183
|
+
getURL(): string | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Type guard to check if an object is an instance of Cookie
|
|
186
|
+
* @param cookie - The object to check
|
|
187
|
+
* @returns {boolean} True if the object is a Cookie instance, false otherwise
|
|
188
|
+
* @example
|
|
189
|
+
* const obj = new Cookie();
|
|
190
|
+
* if (Cookie.isCookie(obj)) {
|
|
191
|
+
* // obj is confirmed to be a Cookie instance
|
|
192
|
+
* }
|
|
193
|
+
*/
|
|
194
|
+
static isCookie(cookie: any): cookie is Cookie;
|
|
195
|
+
}
|
|
196
|
+
declare class RezoCookieJar extends TouchCookieJar {
|
|
197
|
+
constructor();
|
|
198
|
+
constructor(cookies: Cookie[]);
|
|
199
|
+
constructor(cookies: Cookie[], url: string);
|
|
200
|
+
private generateCookies;
|
|
201
|
+
cookies(): Cookies;
|
|
202
|
+
parseResponseCookies(cookies: Cookie[]): Cookies;
|
|
203
|
+
static toNetscapeCookie(cookies: Cookie[] | SerializedCookie[]): string;
|
|
204
|
+
static toCookieString(cookies: Cookie[] | SerializedCookie[]): string;
|
|
205
|
+
toCookieString(): string;
|
|
206
|
+
toNetscapeCookie(): string;
|
|
207
|
+
toArray(): Cookie[];
|
|
208
|
+
toSetCookies(): string[];
|
|
209
|
+
toSerializedCookies(): SerializedCookie[];
|
|
210
|
+
setCookiesSync(setCookieArray: string[]): Cookies;
|
|
211
|
+
setCookiesSync(setCookieArray: string[], url: string): Cookies;
|
|
212
|
+
setCookiesSync(cookiesString: string): Cookies;
|
|
213
|
+
setCookiesSync(cookiesString: string, url: string): Cookies;
|
|
214
|
+
setCookiesSync(serializedCookies: SerializedCookie[]): Cookies;
|
|
215
|
+
setCookiesSync(serializedCookies: SerializedCookie[], url: string): Cookies;
|
|
216
|
+
setCookiesSync(cookieArray: Cookie[]): Cookies;
|
|
217
|
+
setCookiesSync(cookieArray: Cookie[], url: string): Cookies;
|
|
218
|
+
private splitSetCookiesString;
|
|
219
|
+
private getUrlFromCookie;
|
|
220
|
+
private parseNetscapeCookies;
|
|
221
|
+
/**
|
|
222
|
+
* Converts Netscape cookie format to an array of Set-Cookie header strings
|
|
223
|
+
*
|
|
224
|
+
* @param netscapeCookieText - Netscape format cookie string
|
|
225
|
+
* @returns Array of Set-Cookie header strings
|
|
226
|
+
*/
|
|
227
|
+
static netscapeCookiesToSetCookieArray(netscapeCookieText: string): string[];
|
|
228
|
+
/** Path to cookie file for persistence */
|
|
229
|
+
private _cookieFile?;
|
|
230
|
+
/** Get the cookie file path */
|
|
231
|
+
get cookieFile(): string | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Load cookies from a file (sync version).
|
|
234
|
+
* - .json files are loaded as serialized JSON cookies
|
|
235
|
+
* - .txt files are loaded as Netscape format cookies
|
|
236
|
+
*
|
|
237
|
+
* This method bypasses public suffix validation for persisted cookies only,
|
|
238
|
+
* keeping normal network cookie validation intact.
|
|
239
|
+
*
|
|
240
|
+
* @param filePath - Path to the cookie file
|
|
241
|
+
* @param defaultUrl - Default URL for cookies without domain (optional)
|
|
242
|
+
*/
|
|
243
|
+
loadFromFile(filePath: string, defaultUrl?: string): void;
|
|
244
|
+
/**
|
|
245
|
+
* Save cookies to a file.
|
|
246
|
+
* - .json files save cookies as serialized JSON
|
|
247
|
+
* - .txt files save cookies in Netscape format
|
|
248
|
+
*
|
|
249
|
+
* @param filePath - Path to save the cookies (defaults to the loaded file path)
|
|
250
|
+
*/
|
|
251
|
+
saveToFile(filePath?: string): void;
|
|
252
|
+
/**
|
|
253
|
+
* Create a new RezoCookieJar from a cookie file.
|
|
254
|
+
* - .json files are loaded as serialized JSON cookies
|
|
255
|
+
* - .txt files are loaded as Netscape format cookies
|
|
256
|
+
*
|
|
257
|
+
* @param filePath - Path to the cookie file
|
|
258
|
+
* @param defaultUrl - Default URL for cookies without domain (optional)
|
|
259
|
+
* @returns A new RezoCookieJar with cookies loaded from the file
|
|
260
|
+
*/
|
|
261
|
+
static fromFile(filePath: string, defaultUrl?: string): RezoCookieJar;
|
|
262
|
+
}
|
|
263
|
+
export interface Cookies {
|
|
264
|
+
array: Cookie[];
|
|
265
|
+
serialized: SerializedCookie[];
|
|
266
|
+
netscape: string;
|
|
267
|
+
string: string;
|
|
268
|
+
setCookiesString: string[];
|
|
269
|
+
}
|
|
270
|
+
export interface ReadableOptions {
|
|
271
|
+
highWaterMark?: number;
|
|
272
|
+
encoding?: string;
|
|
273
|
+
objectMode?: boolean;
|
|
274
|
+
read?(this: Readable, size: number): void;
|
|
275
|
+
destroy?(this: Readable, error: Error | null, callback: (error: Error | null) => void): void;
|
|
276
|
+
autoDestroy?: boolean;
|
|
277
|
+
}
|
|
278
|
+
export interface Options extends ReadableOptions {
|
|
279
|
+
writable?: boolean;
|
|
280
|
+
readable?: boolean;
|
|
281
|
+
dataSize?: number;
|
|
282
|
+
maxDataSize?: number;
|
|
283
|
+
pauseStreams?: boolean;
|
|
284
|
+
}
|
|
285
|
+
declare class RezoFormData extends NodeFormData {
|
|
286
|
+
constructor(options?: Options);
|
|
287
|
+
/**
|
|
288
|
+
* Get field entries as array of [name, value] pairs
|
|
289
|
+
* @returns {Promise<Array<[string, any]>>} Array of field entries
|
|
290
|
+
*/
|
|
291
|
+
getFieldEntries(): Promise<Array<[
|
|
292
|
+
string,
|
|
293
|
+
any
|
|
294
|
+
]>>;
|
|
295
|
+
/**
|
|
296
|
+
* Convert to native FormData
|
|
297
|
+
* @returns {Promise<FormData | null>}
|
|
298
|
+
*/
|
|
299
|
+
toNativeFormData(): Promise<FormData | null>;
|
|
300
|
+
/**
|
|
301
|
+
* Create RezoFormData from native FormData
|
|
302
|
+
* @param {FormData} formData - Native FormData object
|
|
303
|
+
* @param {Options} options - Optional RezoFormData options
|
|
304
|
+
* @returns {Promise<RezoFormData>}
|
|
305
|
+
*/
|
|
306
|
+
static fromNativeFormData(formData: FormData, options?: Options): Promise<RezoFormData>;
|
|
307
|
+
/**
|
|
308
|
+
* Get the content type header for this form data
|
|
309
|
+
* @returns {string} Content type with boundary
|
|
310
|
+
*/
|
|
311
|
+
getContentType(): string;
|
|
312
|
+
/**
|
|
313
|
+
* Convert form data to Buffer
|
|
314
|
+
* @returns {Buffer} Form data as buffer
|
|
315
|
+
*/
|
|
316
|
+
toBuffer(): Buffer;
|
|
317
|
+
/**
|
|
318
|
+
* Create RezoFormData from object
|
|
319
|
+
* @param {Record<string, any>} obj - Object to convert
|
|
320
|
+
* @param {Options} options - Optional RezoFormData options
|
|
321
|
+
* @returns {RezoFormData}
|
|
322
|
+
*/
|
|
323
|
+
static fromObject(obj: Record<string, any>, options?: Options): RezoFormData;
|
|
324
|
+
/**
|
|
325
|
+
* Convert to URL query string
|
|
326
|
+
* Warning: File, Blob, and binary data will be omitted
|
|
327
|
+
* @param {boolean} convertBinaryToBase64 - Convert binary data to base64 strings
|
|
328
|
+
* @returns {Promise<string>} URL query string
|
|
329
|
+
*/
|
|
330
|
+
toUrlQueryString(convertBinaryToBase64?: boolean): Promise<string>;
|
|
331
|
+
/**
|
|
332
|
+
* Convert to URLSearchParams object
|
|
333
|
+
* Warning: File, Blob, and binary data will be omitted
|
|
334
|
+
* @param {boolean} convertBinaryToBase64 - Convert binary data to base64 strings
|
|
335
|
+
* @returns {Promise<URLSearchParams>} URLSearchParams object
|
|
336
|
+
*/
|
|
337
|
+
toURLSearchParams(convertBinaryToBase64?: boolean): Promise<URLSearchParams>;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Emitted when request is initiated
|
|
341
|
+
* Contains basic request configuration without sensitive data
|
|
342
|
+
*/
|
|
343
|
+
export interface RequestStartEvent {
|
|
344
|
+
/** Target URL */
|
|
345
|
+
url: string;
|
|
346
|
+
/** HTTP method */
|
|
347
|
+
method: string;
|
|
348
|
+
/** Request headers being sent */
|
|
349
|
+
headers: RezoHeaders;
|
|
350
|
+
/** Timestamp when request started (performance.now()) */
|
|
351
|
+
timestamp: number;
|
|
352
|
+
/** Request timeout in milliseconds */
|
|
353
|
+
timeout?: number;
|
|
354
|
+
/** Maximum redirects allowed */
|
|
355
|
+
maxRedirects?: number;
|
|
356
|
+
/** Retry configuration */
|
|
357
|
+
retry?: {
|
|
358
|
+
maxRetries?: number;
|
|
359
|
+
delay?: number;
|
|
360
|
+
backoff?: number;
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Emitted when response headers are received (first byte)
|
|
365
|
+
* Provides response metadata before body is processed
|
|
366
|
+
*/
|
|
367
|
+
export interface ResponseHeadersEvent {
|
|
368
|
+
/** HTTP status code */
|
|
369
|
+
status: number;
|
|
370
|
+
/** HTTP status text */
|
|
371
|
+
statusText: string;
|
|
372
|
+
/** Response headers */
|
|
373
|
+
headers: RezoHeaders;
|
|
374
|
+
/** Content-Type header value */
|
|
375
|
+
contentType?: string;
|
|
376
|
+
/** Content-Length header value (bytes) */
|
|
377
|
+
contentLength?: number;
|
|
378
|
+
/** Cookies from Set-Cookie headers */
|
|
379
|
+
cookies?: Cookie[];
|
|
380
|
+
/** Timing information */
|
|
381
|
+
timing: {
|
|
382
|
+
/** Time to first byte (TTFB) in milliseconds */
|
|
383
|
+
firstByte: number;
|
|
384
|
+
/** Total time elapsed so far in milliseconds */
|
|
385
|
+
total: number;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Emitted AFTER a redirect is followed
|
|
390
|
+
* Provides complete redirect information
|
|
391
|
+
*/
|
|
392
|
+
export interface RedirectEvent {
|
|
393
|
+
/** Source URL (where we're redirecting FROM) */
|
|
394
|
+
sourceUrl: string;
|
|
395
|
+
/** Source HTTP status code */
|
|
396
|
+
sourceStatus: number;
|
|
397
|
+
/** Source HTTP status text */
|
|
398
|
+
sourceStatusText: string;
|
|
399
|
+
/** Destination URL (where we're redirecting TO) */
|
|
400
|
+
destinationUrl: string;
|
|
401
|
+
/** Number of redirects followed so far */
|
|
402
|
+
redirectCount: number;
|
|
403
|
+
/** Maximum redirects allowed */
|
|
404
|
+
maxRedirects: number;
|
|
405
|
+
/** Response headers from redirect response */
|
|
406
|
+
headers: RezoHeaders;
|
|
407
|
+
/** Cookies from redirect response */
|
|
408
|
+
cookies: Cookie[];
|
|
409
|
+
/** HTTP method used for the redirect */
|
|
410
|
+
method: string;
|
|
411
|
+
/** Timestamp when redirect occurred */
|
|
412
|
+
timestamp: number;
|
|
413
|
+
/** Duration of this redirect in milliseconds */
|
|
414
|
+
duration: number;
|
|
415
|
+
}
|
|
416
|
+
interface ProgressEvent$1 {
|
|
417
|
+
/** Bytes transferred so far */
|
|
418
|
+
loaded: number;
|
|
419
|
+
/** Total bytes (from Content-Length or file size) */
|
|
420
|
+
total: number;
|
|
421
|
+
/** Progress percentage (0-100) */
|
|
422
|
+
percentage: number;
|
|
423
|
+
/** Current transfer speed in bytes/second */
|
|
424
|
+
speed: number;
|
|
425
|
+
/** Average transfer speed in bytes/second */
|
|
426
|
+
averageSpeed: number;
|
|
427
|
+
/** Estimated time remaining in milliseconds */
|
|
428
|
+
estimatedTime: number;
|
|
429
|
+
/** Timestamp of this progress update */
|
|
430
|
+
timestamp: number;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Emitted when StreamResponse completes
|
|
434
|
+
* Body has already been emitted via 'data' events
|
|
435
|
+
*/
|
|
436
|
+
export interface StreamFinishEvent {
|
|
437
|
+
/** HTTP status code */
|
|
438
|
+
status: number;
|
|
439
|
+
/** HTTP status text */
|
|
440
|
+
statusText: string;
|
|
441
|
+
/** Response headers */
|
|
442
|
+
headers: RezoHeaders;
|
|
443
|
+
/** Content-Type header value */
|
|
444
|
+
contentType?: string;
|
|
445
|
+
/** Content-Length (bytes received) */
|
|
446
|
+
contentLength: number;
|
|
447
|
+
/** Final URL after redirects */
|
|
448
|
+
finalUrl: string;
|
|
449
|
+
/** Cookies received */
|
|
450
|
+
cookies: Cookies;
|
|
451
|
+
/** All URLs traversed (includes redirects) */
|
|
452
|
+
urls: string[];
|
|
453
|
+
/** Timing breakdown */
|
|
454
|
+
timing: {
|
|
455
|
+
/** Total request time in milliseconds */
|
|
456
|
+
total: number;
|
|
457
|
+
/** DNS lookup time in milliseconds */
|
|
458
|
+
dns?: number;
|
|
459
|
+
/** TCP connection time in milliseconds */
|
|
460
|
+
tcp?: number;
|
|
461
|
+
/** TLS handshake time in milliseconds */
|
|
462
|
+
tls?: number;
|
|
463
|
+
/** Time to first byte in milliseconds */
|
|
464
|
+
firstByte?: number;
|
|
465
|
+
/** Content download time in milliseconds */
|
|
466
|
+
download?: number;
|
|
467
|
+
};
|
|
468
|
+
/** Response configuration (execution metadata) */
|
|
469
|
+
config: SanitizedRezoConfig;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Emitted when DownloadResponse completes
|
|
473
|
+
* Body has been saved to file
|
|
474
|
+
*/
|
|
475
|
+
export interface DownloadFinishEvent {
|
|
476
|
+
/** HTTP status code */
|
|
477
|
+
status: number;
|
|
478
|
+
/** HTTP status text */
|
|
479
|
+
statusText: string;
|
|
480
|
+
/** Response headers */
|
|
481
|
+
headers: RezoHeaders;
|
|
482
|
+
/** Content-Type header value */
|
|
483
|
+
contentType?: string;
|
|
484
|
+
/** Content-Length (bytes downloaded) */
|
|
485
|
+
contentLength: number;
|
|
486
|
+
/** Final URL after redirects */
|
|
487
|
+
finalUrl: string;
|
|
488
|
+
/** Cookies received */
|
|
489
|
+
cookies: Cookies;
|
|
490
|
+
/** All URLs traversed (includes redirects) */
|
|
491
|
+
urls: string[];
|
|
492
|
+
/**
|
|
493
|
+
* File name (supports both basename and fullname)
|
|
494
|
+
* - For fileName: 'report.pdf' → returns 'report.pdf'
|
|
495
|
+
* - For saveTo: '/path/to/report.pdf' → returns '/path/to/report.pdf'
|
|
496
|
+
*/
|
|
497
|
+
fileName: string;
|
|
498
|
+
/** File size in bytes */
|
|
499
|
+
fileSize: number;
|
|
500
|
+
/** Timing breakdown */
|
|
501
|
+
timing: {
|
|
502
|
+
/** Total request time in milliseconds */
|
|
503
|
+
total: number;
|
|
504
|
+
/** DNS lookup time in milliseconds */
|
|
505
|
+
dns?: number;
|
|
506
|
+
/** TCP connection time in milliseconds */
|
|
507
|
+
tcp?: number;
|
|
508
|
+
/** TLS handshake time in milliseconds */
|
|
509
|
+
tls?: number;
|
|
510
|
+
/** Time to first byte in milliseconds */
|
|
511
|
+
firstByte?: number;
|
|
512
|
+
/** Download duration in milliseconds */
|
|
513
|
+
download: number;
|
|
514
|
+
};
|
|
515
|
+
/** Average download speed in bytes/second */
|
|
516
|
+
averageSpeed: number;
|
|
517
|
+
/** Response configuration (execution metadata) */
|
|
518
|
+
config: SanitizedRezoConfig;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Emitted when UploadResponse completes
|
|
522
|
+
* Includes server's response body
|
|
523
|
+
*/
|
|
524
|
+
export interface UploadFinishEvent {
|
|
525
|
+
/** Server's response to our upload */
|
|
526
|
+
response: {
|
|
527
|
+
/** HTTP status code */
|
|
528
|
+
status: number;
|
|
529
|
+
/** HTTP status text */
|
|
530
|
+
statusText: string;
|
|
531
|
+
/** Response headers */
|
|
532
|
+
headers: RezoHeaders;
|
|
533
|
+
/** Response body from server */
|
|
534
|
+
data: any;
|
|
535
|
+
/** Content-Type header value */
|
|
536
|
+
contentType?: string;
|
|
537
|
+
/** Response content length */
|
|
538
|
+
contentLength?: number;
|
|
539
|
+
};
|
|
540
|
+
/** Final URL after redirects */
|
|
541
|
+
finalUrl: string;
|
|
542
|
+
/** Cookies received */
|
|
543
|
+
cookies: Cookies;
|
|
544
|
+
/** All URLs traversed (includes redirects) */
|
|
545
|
+
urls: string[];
|
|
546
|
+
/** Upload size in bytes */
|
|
547
|
+
uploadSize: number;
|
|
548
|
+
/** File name if uploading a file */
|
|
549
|
+
fileName?: string;
|
|
550
|
+
/** Timing breakdown */
|
|
551
|
+
timing: {
|
|
552
|
+
/** Total request time in milliseconds */
|
|
553
|
+
total: number;
|
|
554
|
+
/** DNS lookup time in milliseconds */
|
|
555
|
+
dns?: number;
|
|
556
|
+
/** TCP connection time in milliseconds */
|
|
557
|
+
tcp?: number;
|
|
558
|
+
/** TLS handshake time in milliseconds */
|
|
559
|
+
tls?: number;
|
|
560
|
+
/** Upload duration in milliseconds */
|
|
561
|
+
upload: number;
|
|
562
|
+
/** Time waiting for server response in milliseconds */
|
|
563
|
+
waiting: number;
|
|
564
|
+
/** Response download time in milliseconds */
|
|
565
|
+
download?: number;
|
|
566
|
+
};
|
|
567
|
+
/** Average upload speed in bytes/second */
|
|
568
|
+
averageUploadSpeed: number;
|
|
569
|
+
/** Average download speed in bytes/second (for response) */
|
|
570
|
+
averageDownloadSpeed?: number;
|
|
571
|
+
/** Response configuration (execution metadata) */
|
|
572
|
+
config: SanitizedRezoConfig;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Sanitized RezoConfig for event emission
|
|
576
|
+
* Excludes only request body/data, includes all metadata
|
|
577
|
+
*/
|
|
578
|
+
export type SanitizedRezoConfig = Omit<RezoConfig, "data"> & {
|
|
579
|
+
/** Data field explicitly removed */
|
|
580
|
+
data?: never;
|
|
581
|
+
};
|
|
582
|
+
/**
|
|
583
|
+
* Event map for StreamResponse - defines all available events and their signatures
|
|
584
|
+
*/
|
|
585
|
+
export interface StreamResponseEvents {
|
|
586
|
+
close: [
|
|
587
|
+
];
|
|
588
|
+
drain: [
|
|
589
|
+
];
|
|
590
|
+
error: [
|
|
591
|
+
err: RezoError
|
|
592
|
+
];
|
|
593
|
+
finish: [
|
|
594
|
+
info: StreamFinishEvent
|
|
595
|
+
];
|
|
596
|
+
done: [
|
|
597
|
+
info: StreamFinishEvent
|
|
598
|
+
];
|
|
599
|
+
start: [
|
|
600
|
+
info: RequestStartEvent
|
|
601
|
+
];
|
|
602
|
+
initiated: [
|
|
603
|
+
];
|
|
604
|
+
headers: [
|
|
605
|
+
info: ResponseHeadersEvent
|
|
606
|
+
];
|
|
607
|
+
cookies: [
|
|
608
|
+
cookies: Cookie[]
|
|
609
|
+
];
|
|
610
|
+
status: [
|
|
611
|
+
status: number,
|
|
612
|
+
statusText: string
|
|
613
|
+
];
|
|
614
|
+
redirect: [
|
|
615
|
+
info: RedirectEvent
|
|
616
|
+
];
|
|
617
|
+
progress: [
|
|
618
|
+
progress: ProgressEvent$1
|
|
619
|
+
];
|
|
620
|
+
data: [
|
|
621
|
+
chunk: Buffer | string
|
|
622
|
+
];
|
|
623
|
+
pipe: [
|
|
624
|
+
src: Readable
|
|
625
|
+
];
|
|
626
|
+
unpipe: [
|
|
627
|
+
src: Readable
|
|
628
|
+
];
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Complete type-safe event method overrides for StreamResponse
|
|
632
|
+
* All event listener methods return 'this' for chaining
|
|
633
|
+
*/
|
|
634
|
+
export interface StreamResponseEventOverrides {
|
|
635
|
+
on<K extends keyof StreamResponseEvents>(event: K, listener: (...args: StreamResponseEvents[K]) => void): this;
|
|
636
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
637
|
+
once<K extends keyof StreamResponseEvents>(event: K, listener: (...args: StreamResponseEvents[K]) => void): this;
|
|
638
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
639
|
+
addListener<K extends keyof StreamResponseEvents>(event: K, listener: (...args: StreamResponseEvents[K]) => void): this;
|
|
640
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
641
|
+
prependListener<K extends keyof StreamResponseEvents>(event: K, listener: (...args: StreamResponseEvents[K]) => void): this;
|
|
642
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
643
|
+
prependOnceListener<K extends keyof StreamResponseEvents>(event: K, listener: (...args: StreamResponseEvents[K]) => void): this;
|
|
644
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
645
|
+
}
|
|
646
|
+
declare class StreamResponse extends Writable implements StreamResponseEventOverrides {
|
|
647
|
+
private _finished;
|
|
648
|
+
private _encoding?;
|
|
649
|
+
constructor(opts?: WritableOptions);
|
|
650
|
+
/**
|
|
651
|
+
* Set encoding for string chunks
|
|
652
|
+
* @param encoding - Buffer encoding (utf8, ascii, etc.)
|
|
653
|
+
* @returns this for chaining
|
|
654
|
+
*/
|
|
655
|
+
setEncoding(encoding: BufferEncoding): this;
|
|
656
|
+
/**
|
|
657
|
+
* Get current encoding
|
|
658
|
+
*/
|
|
659
|
+
getEncoding(): BufferEncoding | undefined;
|
|
660
|
+
/**
|
|
661
|
+
* Check if stream has finished
|
|
662
|
+
*/
|
|
663
|
+
isFinished(): boolean;
|
|
664
|
+
/**
|
|
665
|
+
* Mark stream as finished (internal use)
|
|
666
|
+
* @internal
|
|
667
|
+
*/
|
|
668
|
+
_markFinished(): void;
|
|
669
|
+
/**
|
|
670
|
+
* Internal write implementation required by Writable
|
|
671
|
+
* Emits 'data' event for each chunk received
|
|
672
|
+
* @internal
|
|
673
|
+
*/
|
|
674
|
+
_write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
675
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
676
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
677
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
678
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
679
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
680
|
+
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
681
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
682
|
+
removeAllListeners(event?: string | symbol): this;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Complete type-safe event method overrides for DownloadResponse
|
|
686
|
+
* All event listener methods return 'this' for chaining
|
|
687
|
+
*/
|
|
688
|
+
export interface DownloadResponseEventOverrides {
|
|
689
|
+
on(event: "error", listener: (err: RezoError) => void): this;
|
|
690
|
+
on(event: "finish", listener: (info: DownloadFinishEvent) => void): this;
|
|
691
|
+
on(event: "done", listener: (info: DownloadFinishEvent) => void): this;
|
|
692
|
+
on(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
693
|
+
on(event: "initiated", listener: () => void): this;
|
|
694
|
+
on(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
695
|
+
on(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
696
|
+
on(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
697
|
+
on(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
698
|
+
on(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
699
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
700
|
+
once(event: "error", listener: (err: RezoError) => void): this;
|
|
701
|
+
once(event: "finish", listener: (info: DownloadFinishEvent) => void): this;
|
|
702
|
+
once(event: "done", listener: (info: DownloadFinishEvent) => void): this;
|
|
703
|
+
once(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
704
|
+
once(event: "initiated", listener: () => void): this;
|
|
705
|
+
once(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
706
|
+
once(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
707
|
+
once(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
708
|
+
once(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
709
|
+
once(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
710
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
711
|
+
addListener(event: "error", listener: (err: RezoError) => void): this;
|
|
712
|
+
addListener(event: "finish", listener: (info: DownloadFinishEvent) => void): this;
|
|
713
|
+
addListener(event: "done", listener: (info: DownloadFinishEvent) => void): this;
|
|
714
|
+
addListener(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
715
|
+
addListener(event: "initiated", listener: () => void): this;
|
|
716
|
+
addListener(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
717
|
+
addListener(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
718
|
+
addListener(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
719
|
+
addListener(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
720
|
+
addListener(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
721
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
722
|
+
prependListener(event: "error", listener: (err: RezoError) => void): this;
|
|
723
|
+
prependListener(event: "finish", listener: (info: DownloadFinishEvent) => void): this;
|
|
724
|
+
prependListener(event: "done", listener: (info: DownloadFinishEvent) => void): this;
|
|
725
|
+
prependListener(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
726
|
+
prependListener(event: "initiated", listener: () => void): this;
|
|
727
|
+
prependListener(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
728
|
+
prependListener(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
729
|
+
prependListener(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
730
|
+
prependListener(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
731
|
+
prependListener(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
732
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
733
|
+
prependOnceListener(event: "error", listener: (err: RezoError) => void): this;
|
|
734
|
+
prependOnceListener(event: "finish", listener: (info: DownloadFinishEvent) => void): this;
|
|
735
|
+
prependOnceListener(event: "done", listener: (info: DownloadFinishEvent) => void): this;
|
|
736
|
+
prependOnceListener(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
737
|
+
prependOnceListener(event: "initiated", listener: () => void): this;
|
|
738
|
+
prependOnceListener(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
739
|
+
prependOnceListener(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
740
|
+
prependOnceListener(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
741
|
+
prependOnceListener(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
742
|
+
prependOnceListener(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
743
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
744
|
+
}
|
|
745
|
+
declare class DownloadResponse extends EventEmitter implements DownloadResponseEventOverrides {
|
|
746
|
+
/** File name (basename or fullname) */
|
|
747
|
+
fileName: string;
|
|
748
|
+
/** Target URL */
|
|
749
|
+
url: string;
|
|
750
|
+
/** HTTP status code (set when headers received) */
|
|
751
|
+
status?: number;
|
|
752
|
+
/** HTTP status text (set when headers received) */
|
|
753
|
+
statusText?: string;
|
|
754
|
+
private _finished;
|
|
755
|
+
constructor(fileName: string, url: string);
|
|
756
|
+
/**
|
|
757
|
+
* Check if download has finished
|
|
758
|
+
*/
|
|
759
|
+
isFinished(): boolean;
|
|
760
|
+
/**
|
|
761
|
+
* Mark download as finished (internal use)
|
|
762
|
+
* @internal
|
|
763
|
+
*/
|
|
764
|
+
_markFinished(): void;
|
|
765
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
766
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
767
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
768
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
769
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
770
|
+
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
771
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
772
|
+
removeAllListeners(event?: string | symbol): this;
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Complete type-safe event method overrides for UploadResponse
|
|
776
|
+
* All event listener methods return 'this' for chaining
|
|
777
|
+
*/
|
|
778
|
+
export interface UploadResponseEventOverrides {
|
|
779
|
+
on(event: "error", listener: (err: RezoError) => void): this;
|
|
780
|
+
on(event: "finish", listener: (info: UploadFinishEvent) => void): this;
|
|
781
|
+
on(event: "done", listener: (info: UploadFinishEvent) => void): this;
|
|
782
|
+
on(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
783
|
+
on(event: "initiated", listener: () => void): this;
|
|
784
|
+
on(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
785
|
+
on(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
786
|
+
on(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
787
|
+
on(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
788
|
+
on(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
789
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
790
|
+
once(event: "error", listener: (err: RezoError) => void): this;
|
|
791
|
+
once(event: "finish", listener: (info: UploadFinishEvent) => void): this;
|
|
792
|
+
once(event: "done", listener: (info: UploadFinishEvent) => void): this;
|
|
793
|
+
once(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
794
|
+
once(event: "initiated", listener: () => void): this;
|
|
795
|
+
once(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
796
|
+
once(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
797
|
+
once(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
798
|
+
once(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
799
|
+
once(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
800
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
801
|
+
addListener(event: "error", listener: (err: RezoError) => void): this;
|
|
802
|
+
addListener(event: "finish", listener: (info: UploadFinishEvent) => void): this;
|
|
803
|
+
addListener(event: "done", listener: (info: UploadFinishEvent) => void): this;
|
|
804
|
+
addListener(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
805
|
+
addListener(event: "initiated", listener: () => void): this;
|
|
806
|
+
addListener(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
807
|
+
addListener(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
808
|
+
addListener(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
809
|
+
addListener(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
810
|
+
addListener(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
811
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
812
|
+
prependListener(event: "error", listener: (err: RezoError) => void): this;
|
|
813
|
+
prependListener(event: "finish", listener: (info: UploadFinishEvent) => void): this;
|
|
814
|
+
prependListener(event: "done", listener: (info: UploadFinishEvent) => void): this;
|
|
815
|
+
prependListener(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
816
|
+
prependListener(event: "initiated", listener: () => void): this;
|
|
817
|
+
prependListener(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
818
|
+
prependListener(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
819
|
+
prependListener(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
820
|
+
prependListener(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
821
|
+
prependListener(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
822
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
823
|
+
prependOnceListener(event: "error", listener: (err: RezoError) => void): this;
|
|
824
|
+
prependOnceListener(event: "finish", listener: (info: UploadFinishEvent) => void): this;
|
|
825
|
+
prependOnceListener(event: "done", listener: (info: UploadFinishEvent) => void): this;
|
|
826
|
+
prependOnceListener(event: "start", listener: (info: RequestStartEvent) => void): this;
|
|
827
|
+
prependOnceListener(event: "initiated", listener: () => void): this;
|
|
828
|
+
prependOnceListener(event: "headers", listener: (info: ResponseHeadersEvent) => void): this;
|
|
829
|
+
prependOnceListener(event: "cookies", listener: (cookies: Cookie[]) => void): this;
|
|
830
|
+
prependOnceListener(event: "status", listener: (status: number, statusText: string) => void): this;
|
|
831
|
+
prependOnceListener(event: "redirect", listener: (info: RedirectEvent) => void): this;
|
|
832
|
+
prependOnceListener(event: "progress", listener: (progress: ProgressEvent$1) => void): this;
|
|
833
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
834
|
+
}
|
|
835
|
+
declare class UploadResponse extends EventEmitter implements UploadResponseEventOverrides {
|
|
836
|
+
/** Target URL */
|
|
837
|
+
url: string;
|
|
838
|
+
/** File name if uploading a file */
|
|
839
|
+
fileName?: string;
|
|
840
|
+
/** HTTP status code (set when headers received) */
|
|
841
|
+
status?: number;
|
|
842
|
+
/** HTTP status text (set when headers received) */
|
|
843
|
+
statusText?: string;
|
|
844
|
+
private _finished;
|
|
845
|
+
constructor(url: string, fileName?: string);
|
|
846
|
+
/**
|
|
847
|
+
* Check if upload has finished
|
|
848
|
+
*/
|
|
849
|
+
isFinished(): boolean;
|
|
850
|
+
/**
|
|
851
|
+
* Mark upload as finished (internal use)
|
|
852
|
+
* @internal
|
|
853
|
+
*/
|
|
854
|
+
_markFinished(): void;
|
|
855
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
856
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
857
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
858
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
859
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
860
|
+
off(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
861
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
862
|
+
removeAllListeners(event?: string | symbol): this;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Standard RezoResponse for non-streaming requests
|
|
866
|
+
* Contains response data, status, headers, cookies, and execution metadata
|
|
867
|
+
*/
|
|
868
|
+
export interface RezoResponse<T = any> {
|
|
869
|
+
data: T;
|
|
870
|
+
status: number;
|
|
871
|
+
statusText: string;
|
|
872
|
+
finalUrl: string;
|
|
873
|
+
cookies: Cookies;
|
|
874
|
+
headers: RezoHeaders;
|
|
875
|
+
contentType: string | undefined;
|
|
876
|
+
contentLength: number;
|
|
877
|
+
urls: string[];
|
|
878
|
+
config: RezoConfig;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* RezoStreamResponse - For responseType: 'stream'
|
|
882
|
+
* Extends StreamResponse class (EventEmitter)
|
|
883
|
+
* Emits 'data' events for response body chunks
|
|
884
|
+
*/
|
|
885
|
+
export interface RezoStreamResponse extends StreamResponse {
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* RezoDownloadResponse - For fileName/saveTo options
|
|
889
|
+
* Extends DownloadResponse class (EventEmitter)
|
|
890
|
+
* Streams response body directly to file
|
|
891
|
+
*/
|
|
892
|
+
export interface RezoDownloadResponse extends DownloadResponse {
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* RezoUploadResponse - For responseType: 'upload'
|
|
896
|
+
* Extends UploadResponse class (EventEmitter)
|
|
897
|
+
* Tracks upload progress and includes server response body
|
|
898
|
+
*/
|
|
899
|
+
export interface RezoUploadResponse extends UploadResponse {
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Context provided to beforeRequest hook
|
|
903
|
+
* Contains metadata about the current request state
|
|
904
|
+
*/
|
|
905
|
+
export interface BeforeRequestContext {
|
|
906
|
+
/** Current retry count (0 for initial request, 1+ for retries) */
|
|
907
|
+
retryCount: number;
|
|
908
|
+
/** Whether this is a redirect follow-up request */
|
|
909
|
+
isRedirect: boolean;
|
|
910
|
+
/** Number of redirects followed so far */
|
|
911
|
+
redirectCount: number;
|
|
912
|
+
/** Timestamp when request processing started */
|
|
913
|
+
startTime: number;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Context provided to afterResponse hook
|
|
917
|
+
* Includes retry capability for token refresh scenarios
|
|
918
|
+
*/
|
|
919
|
+
export interface AfterResponseContext {
|
|
920
|
+
/** Current retry count */
|
|
921
|
+
retryCount: number;
|
|
922
|
+
/** Function to retry request with merged options */
|
|
923
|
+
retryWithMergedOptions: (options: Partial<RezoRequestConfig>) => never;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* DNS resolution event data
|
|
927
|
+
*/
|
|
928
|
+
export interface DnsLookupEvent {
|
|
929
|
+
/** Hostname being resolved */
|
|
930
|
+
hostname: string;
|
|
931
|
+
/** Resolved IP address */
|
|
932
|
+
address: string;
|
|
933
|
+
/** Address family (4 for IPv4, 6 for IPv6) */
|
|
934
|
+
family: 4 | 6;
|
|
935
|
+
/** DNS lookup duration in milliseconds */
|
|
936
|
+
duration: number;
|
|
937
|
+
/** Timestamp when lookup completed */
|
|
938
|
+
timestamp: number;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* TLS handshake event data
|
|
942
|
+
*/
|
|
943
|
+
export interface TlsHandshakeEvent {
|
|
944
|
+
/** TLS protocol version (TLSv1.2, TLSv1.3, etc.) */
|
|
945
|
+
protocol: string;
|
|
946
|
+
/** Cipher suite used */
|
|
947
|
+
cipher: string;
|
|
948
|
+
/** Whether certificate is authorized */
|
|
949
|
+
authorized: boolean;
|
|
950
|
+
/** Authorization error if any */
|
|
951
|
+
authorizationError?: string;
|
|
952
|
+
/** Server certificate info */
|
|
953
|
+
certificate?: {
|
|
954
|
+
subject: string;
|
|
955
|
+
issuer: string;
|
|
956
|
+
validFrom: string;
|
|
957
|
+
validTo: string;
|
|
958
|
+
fingerprint: string;
|
|
959
|
+
};
|
|
960
|
+
/** Handshake duration in milliseconds */
|
|
961
|
+
duration: number;
|
|
962
|
+
/** Timestamp when handshake completed */
|
|
963
|
+
timestamp: number;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Socket event data
|
|
967
|
+
*/
|
|
968
|
+
export interface SocketEvent {
|
|
969
|
+
/** Event type */
|
|
970
|
+
type: "connect" | "close" | "drain" | "error" | "timeout" | "end";
|
|
971
|
+
/** Local address */
|
|
972
|
+
localAddress?: string;
|
|
973
|
+
/** Local port */
|
|
974
|
+
localPort?: number;
|
|
975
|
+
/** Remote address */
|
|
976
|
+
remoteAddress?: string;
|
|
977
|
+
/** Remote port */
|
|
978
|
+
remotePort?: number;
|
|
979
|
+
/** Bytes written */
|
|
980
|
+
bytesWritten?: number;
|
|
981
|
+
/** Bytes read */
|
|
982
|
+
bytesRead?: number;
|
|
983
|
+
/** Error if applicable */
|
|
984
|
+
error?: Error;
|
|
985
|
+
/** Timestamp */
|
|
986
|
+
timestamp: number;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Timeout event data
|
|
990
|
+
*/
|
|
991
|
+
export interface TimeoutEvent {
|
|
992
|
+
/** Type of timeout */
|
|
993
|
+
type: "connect" | "request" | "response" | "socket" | "lookup";
|
|
994
|
+
/** Configured timeout value in milliseconds */
|
|
995
|
+
timeout: number;
|
|
996
|
+
/** Elapsed time before timeout in milliseconds */
|
|
997
|
+
elapsed: number;
|
|
998
|
+
/** URL being requested */
|
|
999
|
+
url: string;
|
|
1000
|
+
/** Timestamp when timeout occurred */
|
|
1001
|
+
timestamp: number;
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Abort event data
|
|
1005
|
+
*/
|
|
1006
|
+
export interface AbortEvent {
|
|
1007
|
+
/** Reason for abort */
|
|
1008
|
+
reason: "user" | "timeout" | "signal" | "error";
|
|
1009
|
+
/** Abort message */
|
|
1010
|
+
message?: string;
|
|
1011
|
+
/** URL being requested */
|
|
1012
|
+
url: string;
|
|
1013
|
+
/** Elapsed time before abort in milliseconds */
|
|
1014
|
+
elapsed: number;
|
|
1015
|
+
/** Timestamp when abort occurred */
|
|
1016
|
+
timestamp: number;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Headers received event data (before body)
|
|
1020
|
+
*/
|
|
1021
|
+
export interface HeadersReceivedEvent {
|
|
1022
|
+
/** HTTP status code */
|
|
1023
|
+
status: number;
|
|
1024
|
+
/** HTTP status text */
|
|
1025
|
+
statusText: string;
|
|
1026
|
+
/** Response headers */
|
|
1027
|
+
headers: RezoHeaders;
|
|
1028
|
+
/** Content-Type header */
|
|
1029
|
+
contentType?: string;
|
|
1030
|
+
/** Content-Length header */
|
|
1031
|
+
contentLength?: number;
|
|
1032
|
+
/** Time to first byte in milliseconds */
|
|
1033
|
+
ttfb: number;
|
|
1034
|
+
/** Timestamp */
|
|
1035
|
+
timestamp: number;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Parse complete event data
|
|
1039
|
+
*/
|
|
1040
|
+
export interface ParseCompleteEvent<T = any> {
|
|
1041
|
+
/** Parsed data */
|
|
1042
|
+
data: T;
|
|
1043
|
+
/** Original raw data before parsing */
|
|
1044
|
+
rawData: string | Buffer;
|
|
1045
|
+
/** Content-Type that triggered parsing */
|
|
1046
|
+
contentType: string;
|
|
1047
|
+
/** Parse duration in milliseconds */
|
|
1048
|
+
parseDuration: number;
|
|
1049
|
+
/** Timestamp */
|
|
1050
|
+
timestamp: number;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Cache event data
|
|
1054
|
+
*/
|
|
1055
|
+
export interface CacheEvent {
|
|
1056
|
+
/** HTTP status code */
|
|
1057
|
+
status: number;
|
|
1058
|
+
/** Response headers */
|
|
1059
|
+
headers: RezoHeaders;
|
|
1060
|
+
/** URL being cached */
|
|
1061
|
+
url: string;
|
|
1062
|
+
/** Cache key if applicable */
|
|
1063
|
+
cacheKey?: string;
|
|
1064
|
+
/** Whether response is cacheable by default */
|
|
1065
|
+
isCacheable: boolean;
|
|
1066
|
+
/** Cache-Control header parsed */
|
|
1067
|
+
cacheControl?: {
|
|
1068
|
+
maxAge?: number;
|
|
1069
|
+
sMaxAge?: number;
|
|
1070
|
+
noCache?: boolean;
|
|
1071
|
+
noStore?: boolean;
|
|
1072
|
+
mustRevalidate?: boolean;
|
|
1073
|
+
private?: boolean;
|
|
1074
|
+
public?: boolean;
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Cookie event data
|
|
1079
|
+
*/
|
|
1080
|
+
export interface CookieEvent {
|
|
1081
|
+
/** Cookie being set/processed */
|
|
1082
|
+
cookie: Cookie;
|
|
1083
|
+
/** Source of cookie (response header, manual set, etc.) */
|
|
1084
|
+
source: "response" | "request" | "manual";
|
|
1085
|
+
/** URL context */
|
|
1086
|
+
url: string;
|
|
1087
|
+
/** Whether cookie is valid */
|
|
1088
|
+
isValid: boolean;
|
|
1089
|
+
/** Validation errors if any */
|
|
1090
|
+
validationErrors?: string[];
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Hook called during options initialization
|
|
1094
|
+
* Use to normalize or validate request options
|
|
1095
|
+
* Must be synchronous
|
|
1096
|
+
*/
|
|
1097
|
+
export type InitHook = (plainOptions: Partial<RezoRequestConfig>, options: RezoRequestConfig) => void;
|
|
1098
|
+
/**
|
|
1099
|
+
* Hook called before request is sent
|
|
1100
|
+
* Use to modify config, add headers, sign requests
|
|
1101
|
+
* Can return early with a Response to bypass actual request
|
|
1102
|
+
*/
|
|
1103
|
+
export type BeforeRequestHook = (config: RezoConfig, context: BeforeRequestContext) => void | Response | Promise<void | Response>;
|
|
1104
|
+
/**
|
|
1105
|
+
* Hook called before following a redirect
|
|
1106
|
+
* Use to inspect/modify redirect behavior
|
|
1107
|
+
*/
|
|
1108
|
+
export type BeforeRedirectHook = (config: RezoConfig, response: RezoResponse) => void | Promise<void>;
|
|
1109
|
+
/**
|
|
1110
|
+
* Hook called before a retry attempt
|
|
1111
|
+
* Use for custom backoff logic, logging
|
|
1112
|
+
*/
|
|
1113
|
+
export type BeforeRetryHook = (config: RezoConfig, error: RezoError, retryCount: number) => void | Promise<void>;
|
|
1114
|
+
/**
|
|
1115
|
+
* Hook called after response is received
|
|
1116
|
+
* Use to transform response, refresh tokens
|
|
1117
|
+
* Can trigger retry via context.retryWithMergedOptions
|
|
1118
|
+
* Return modified response or original
|
|
1119
|
+
*/
|
|
1120
|
+
export type AfterResponseHook<T = any> = (response: RezoResponse<T>, config: RezoConfig, context: AfterResponseContext) => RezoResponse<T> | Promise<RezoResponse<T>>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Hook called before error is thrown
|
|
1123
|
+
* Use to transform errors, add context
|
|
1124
|
+
* Can return custom Error subclasses
|
|
1125
|
+
*/
|
|
1126
|
+
export type BeforeErrorHook = (error: RezoError | Error) => RezoError | Error | Promise<RezoError | Error>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Hook called before caching a response
|
|
1129
|
+
* Return false to prevent caching
|
|
1130
|
+
* Can modify response headers to affect caching behavior
|
|
1131
|
+
*/
|
|
1132
|
+
export type BeforeCacheHook = (event: CacheEvent) => boolean | void;
|
|
1133
|
+
/**
|
|
1134
|
+
* Hook called when response headers are received (before body)
|
|
1135
|
+
* Use to inspect headers, abort early, prepare for response
|
|
1136
|
+
*/
|
|
1137
|
+
export type AfterHeadersHook = (event: HeadersReceivedEvent, config: RezoConfig) => void | Promise<void>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Hook called after response body is parsed
|
|
1140
|
+
* Use to transform parsed data, validate response
|
|
1141
|
+
*/
|
|
1142
|
+
export type AfterParseHook<T = any> = (event: ParseCompleteEvent<T>, config: RezoConfig) => T | Promise<T>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Hook called before a cookie is set
|
|
1145
|
+
* Return false to reject the cookie
|
|
1146
|
+
* Can modify cookie properties
|
|
1147
|
+
*/
|
|
1148
|
+
export type BeforeCookieHook = (event: CookieEvent, config: RezoConfig) => boolean | void | Promise<boolean | void>;
|
|
1149
|
+
/**
|
|
1150
|
+
* Hook called after cookies are processed
|
|
1151
|
+
* Use for cookie logging, analytics
|
|
1152
|
+
*/
|
|
1153
|
+
export type AfterCookieHook = (cookies: Cookie[], config: RezoConfig) => void | Promise<void>;
|
|
1154
|
+
/**
|
|
1155
|
+
* Hook called on socket events
|
|
1156
|
+
* Use for connection monitoring, metrics
|
|
1157
|
+
*/
|
|
1158
|
+
export type OnSocketHook = (event: SocketEvent, socket: Socket | TLSSocket) => void;
|
|
1159
|
+
/**
|
|
1160
|
+
* Hook called when DNS lookup completes
|
|
1161
|
+
* Use for DNS caching, logging, analytics
|
|
1162
|
+
*/
|
|
1163
|
+
export type OnDnsHook = (event: DnsLookupEvent, config: RezoConfig) => void;
|
|
1164
|
+
/**
|
|
1165
|
+
* Hook called when TLS handshake completes
|
|
1166
|
+
* Use for certificate validation, security logging
|
|
1167
|
+
*/
|
|
1168
|
+
export type OnTlsHook = (event: TlsHandshakeEvent, config: RezoConfig) => void;
|
|
1169
|
+
/**
|
|
1170
|
+
* Hook called when timeout occurs
|
|
1171
|
+
* Use for timeout logging, retry decisions
|
|
1172
|
+
*/
|
|
1173
|
+
export type OnTimeoutHook = (event: TimeoutEvent, config: RezoConfig) => void;
|
|
1174
|
+
/**
|
|
1175
|
+
* Hook called when request is aborted
|
|
1176
|
+
* Use for cleanup, logging
|
|
1177
|
+
*/
|
|
1178
|
+
export type OnAbortHook = (event: AbortEvent, config: RezoConfig) => void;
|
|
1179
|
+
/**
|
|
1180
|
+
* Collection of all hook types
|
|
1181
|
+
* All hooks are arrays to allow multiple handlers
|
|
1182
|
+
*/
|
|
1183
|
+
export interface RezoHooks {
|
|
1184
|
+
init: InitHook[];
|
|
1185
|
+
beforeRequest: BeforeRequestHook[];
|
|
1186
|
+
beforeRedirect: BeforeRedirectHook[];
|
|
1187
|
+
beforeRetry: BeforeRetryHook[];
|
|
1188
|
+
afterResponse: AfterResponseHook[];
|
|
1189
|
+
beforeError: BeforeErrorHook[];
|
|
1190
|
+
beforeCache: BeforeCacheHook[];
|
|
1191
|
+
afterHeaders: AfterHeadersHook[];
|
|
1192
|
+
afterParse: AfterParseHook[];
|
|
1193
|
+
beforeCookie: BeforeCookieHook[];
|
|
1194
|
+
afterCookie: AfterCookieHook[];
|
|
1195
|
+
onSocket: OnSocketHook[];
|
|
1196
|
+
onDns: OnDnsHook[];
|
|
1197
|
+
onTls: OnTlsHook[];
|
|
1198
|
+
onTimeout: OnTimeoutHook[];
|
|
1199
|
+
onAbort: OnAbortHook[];
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Configuration object that encapsulates comprehensive request execution metadata and response processing information.
|
|
1203
|
+
* This interface serves as the central configuration hub for HTTP requests, containing both input parameters
|
|
1204
|
+
* and execution tracking data throughout the request lifecycle.
|
|
1205
|
+
*
|
|
1206
|
+
* @interface RezoConfig
|
|
1207
|
+
* @since 1.0.0
|
|
1208
|
+
* @example
|
|
1209
|
+
* ```typescript
|
|
1210
|
+
* const config: RezoConfig = {
|
|
1211
|
+
* originalRequest: requestConfig,
|
|
1212
|
+
* finalUrl: 'https://api.example.com/data',
|
|
1213
|
+
* adapterUsed: 'fetch',
|
|
1214
|
+
* timing: { startTime: Date.now(), endTime: Date.now() + 1000, total: 1000 },
|
|
1215
|
+
* network: { protocol: 'https' },
|
|
1216
|
+
* transfer: { requestSize: 256, responseSize: 1024, headerSize: 128, bodySize: 896 },
|
|
1217
|
+
* retryAttempts: 0,
|
|
1218
|
+
* errors: [],
|
|
1219
|
+
* security: {},
|
|
1220
|
+
* metadata: {}
|
|
1221
|
+
* };
|
|
1222
|
+
* ```
|
|
1223
|
+
*/
|
|
1224
|
+
export interface RezoConfig {
|
|
1225
|
+
/** @description The target URL for the HTTP request */
|
|
1226
|
+
url: string;
|
|
1227
|
+
/** @description HTTP method (GET, POST, PUT, DELETE, etc.) */
|
|
1228
|
+
method: RezoRequestConfig["method"];
|
|
1229
|
+
/** @description HTTP headers to be sent with the request */
|
|
1230
|
+
headers: RezoHeaders;
|
|
1231
|
+
/** @description Request payload data (null when not set) */
|
|
1232
|
+
data?: RezoRequestConfig["body"] | null;
|
|
1233
|
+
/** @description URL query parameters */
|
|
1234
|
+
params?: RezoRequestConfig["params"];
|
|
1235
|
+
/** @description Request timeout in milliseconds (null when not set) */
|
|
1236
|
+
timeout?: number | null;
|
|
1237
|
+
/** @description Expected response data type */
|
|
1238
|
+
responseType?: "json" | "text" | "blob" | "arrayBuffer" | "stream" | "download" | "upload" | "buffer" | "binary";
|
|
1239
|
+
/** @description Basic authentication credentials (null when not set) */
|
|
1240
|
+
auth?: RezoRequestConfig["auth"] | null;
|
|
1241
|
+
/** @description Proxy configuration (null when not set) */
|
|
1242
|
+
proxy?: RezoRequestConfig["proxy"] | null;
|
|
1243
|
+
/** @description Maximum number of redirects to follow */
|
|
1244
|
+
maxRedirects: number;
|
|
1245
|
+
/** @description Base URL for relative requests */
|
|
1246
|
+
baseURL?: string;
|
|
1247
|
+
/** @description Enable HTTP/2 protocol */
|
|
1248
|
+
http2: boolean;
|
|
1249
|
+
/** @description Enable cURL command generation */
|
|
1250
|
+
curl: boolean;
|
|
1251
|
+
/** @description Enable detection of redirect cycles */
|
|
1252
|
+
enableRedirectCycleDetection?: boolean;
|
|
1253
|
+
/** @description Reject unauthorized SSL certificates */
|
|
1254
|
+
rejectUnauthorized?: boolean;
|
|
1255
|
+
/** @description Retry configuration */
|
|
1256
|
+
retry?: RezoRequestConfig["retry"];
|
|
1257
|
+
/** @description Compression settings */
|
|
1258
|
+
compression?: {
|
|
1259
|
+
/** @description Enable compression */
|
|
1260
|
+
enabled?: boolean;
|
|
1261
|
+
/** @description Compression threshold in bytes */
|
|
1262
|
+
threshold?: number;
|
|
1263
|
+
/** @description Supported compression algorithms */
|
|
1264
|
+
algorithms?: string[];
|
|
1265
|
+
};
|
|
1266
|
+
/** @description Enable cookie jar for session management */
|
|
1267
|
+
enableCookieJar?: boolean;
|
|
1268
|
+
/** @description Feature flags for adapter capabilities */
|
|
1269
|
+
features?: {
|
|
1270
|
+
/** @description HTTP/2 support */
|
|
1271
|
+
http2?: boolean;
|
|
1272
|
+
/** @description Compression support */
|
|
1273
|
+
compression?: boolean;
|
|
1274
|
+
/** @description Cookie support */
|
|
1275
|
+
cookies?: boolean;
|
|
1276
|
+
/** @description Redirect support */
|
|
1277
|
+
redirects?: boolean;
|
|
1278
|
+
/** @description Proxy support */
|
|
1279
|
+
proxy?: boolean;
|
|
1280
|
+
/** @description Timeout support */
|
|
1281
|
+
timeout?: boolean;
|
|
1282
|
+
/** @description Retry support */
|
|
1283
|
+
retry?: boolean;
|
|
1284
|
+
/** @description Cache support */
|
|
1285
|
+
cache?: boolean;
|
|
1286
|
+
/** @description Metrics support */
|
|
1287
|
+
metrics?: boolean;
|
|
1288
|
+
/** @description Event support */
|
|
1289
|
+
events?: boolean;
|
|
1290
|
+
/** @description Validation support */
|
|
1291
|
+
validation?: boolean;
|
|
1292
|
+
/** @description Browser support */
|
|
1293
|
+
browser?: boolean;
|
|
1294
|
+
/** @description SSL support */
|
|
1295
|
+
ssl?: boolean;
|
|
1296
|
+
};
|
|
1297
|
+
/** @description Use insecure HTTP parser */
|
|
1298
|
+
insecureHTTPParser: boolean;
|
|
1299
|
+
/** @description Custom adapter implementation */
|
|
1300
|
+
adapter?: any;
|
|
1301
|
+
isSecure?: boolean;
|
|
1302
|
+
/**
|
|
1303
|
+
* @description Rate limiting for network transfer speed (bandwidth throttling)
|
|
1304
|
+
*
|
|
1305
|
+
* Controls the maximum transfer speed in bytes per second.
|
|
1306
|
+
*
|
|
1307
|
+
* - `number`: Applies same limit to both download and upload (e.g., 1024000 = ~1MB/s)
|
|
1308
|
+
* - `[download, upload]`: Different limits for each direction (e.g., [5242880, 1048576] = 5MB/s down, 1MB/s up)
|
|
1309
|
+
* - `0` or `null`: No rate limiting (unlimited speed)
|
|
1310
|
+
*
|
|
1311
|
+
* Common values:
|
|
1312
|
+
* - 1048576 = 1 MB/s
|
|
1313
|
+
* - 5242880 = 5 MB/s
|
|
1314
|
+
* - 10485760 = 10 MB/s
|
|
1315
|
+
*
|
|
1316
|
+
* Note: Actual transfer speed may vary based on network conditions and adapter support.
|
|
1317
|
+
* This feature is adapter-dependent (HTTP adapter supports it, other adapters may vary).
|
|
1318
|
+
*/
|
|
1319
|
+
maxRate: number | [
|
|
1320
|
+
number,
|
|
1321
|
+
number
|
|
1322
|
+
];
|
|
1323
|
+
/** @description Cancellation token for request abortion (null when not set) */
|
|
1324
|
+
cancelToken?: any | null;
|
|
1325
|
+
/** @description AbortSignal for request cancellation (null when not set) */
|
|
1326
|
+
signal?: AbortSignal | null;
|
|
1327
|
+
/** @description Function to set the AbortSignal */
|
|
1328
|
+
setSignal: () => void;
|
|
1329
|
+
/** @description HTTP agent for connection pooling (null when not set) */
|
|
1330
|
+
httpAgent?: RezoRequestConfig["httpAgent"] | null;
|
|
1331
|
+
/** @description HTTPS agent for secure connection pooling (null when not set) */
|
|
1332
|
+
httpsAgent?: RezoRequestConfig["httpsAgent"] | null;
|
|
1333
|
+
/** @description Unix socket path (null when not set) */
|
|
1334
|
+
socketPath?: string | null;
|
|
1335
|
+
/** @description File path to save the response (null when not set) */
|
|
1336
|
+
fileName?: string | null;
|
|
1337
|
+
/**
|
|
1338
|
+
* Array of cookies to be sent with the request.
|
|
1339
|
+
* These cookies are configured before the request is made and will be included in the request headers.
|
|
1340
|
+
*/
|
|
1341
|
+
requestCookies: Cookie[];
|
|
1342
|
+
/**
|
|
1343
|
+
* Cookies received from the server in the response.
|
|
1344
|
+
* These cookies are parsed from the 'Set-Cookie' response headers and can be used for subsequent requests
|
|
1345
|
+
* or session management. Contains multiple formats: array, serialized, netscape, string, setCookiesString.
|
|
1346
|
+
*/
|
|
1347
|
+
responseCookies: Cookies;
|
|
1348
|
+
/**
|
|
1349
|
+
* Path to cookie file for persistence (null when not configured).
|
|
1350
|
+
* - .json files save cookies as serialized JSON
|
|
1351
|
+
* - .txt files save cookies in Netscape format
|
|
1352
|
+
*/
|
|
1353
|
+
cookieFile?: string | null;
|
|
1354
|
+
/**
|
|
1355
|
+
* Request lifecycle hooks for intercepting and modifying request/response behavior.
|
|
1356
|
+
* null when no hooks are registered, otherwise contains only hooks with registered functions.
|
|
1357
|
+
* Empty arrays are not included - only hooks with actual handlers appear.
|
|
1358
|
+
*
|
|
1359
|
+
* Available hooks:
|
|
1360
|
+
* - init: During options initialization
|
|
1361
|
+
* - beforeRequest: Before request is sent
|
|
1362
|
+
* - beforeRedirect: Before following redirects
|
|
1363
|
+
* - beforeRetry: Before retry attempts
|
|
1364
|
+
* - afterResponse: After response is received
|
|
1365
|
+
* - beforeError: Before error is thrown
|
|
1366
|
+
* - beforeCache: Before caching response
|
|
1367
|
+
* - afterHeaders: When headers are received
|
|
1368
|
+
* - afterParse: After body is parsed
|
|
1369
|
+
* - beforeCookie/afterCookie: Cookie lifecycle
|
|
1370
|
+
* - onSocket/onDns/onTls/onTimeout/onAbort: Low-level events
|
|
1371
|
+
*/
|
|
1372
|
+
hooks: Partial<RezoHooks> | null;
|
|
1373
|
+
/** @description Snapshot of the original request configuration */
|
|
1374
|
+
originalRequest: RezoRequestConfig;
|
|
1375
|
+
/** @description Final resolved URL after redirects and processing */
|
|
1376
|
+
finalUrl: string;
|
|
1377
|
+
/** @description HTTP adapter used for the request */
|
|
1378
|
+
adapterUsed: "http" | "https" | "http2" | "fetch" | "xhr" | "curl";
|
|
1379
|
+
/** @description Metadata about the adapter used */
|
|
1380
|
+
adapterMetadata?: {
|
|
1381
|
+
/** @description Adapter version */
|
|
1382
|
+
version?: string;
|
|
1383
|
+
/** @description Supported features */
|
|
1384
|
+
features?: string[];
|
|
1385
|
+
/** @description Adapter capabilities */
|
|
1386
|
+
capabilities?: Record<string, any>;
|
|
1387
|
+
};
|
|
1388
|
+
/** @description Complete redirect chain history */
|
|
1389
|
+
redirectHistory: {
|
|
1390
|
+
/** @description Cookies set in this redirect */
|
|
1391
|
+
cookies: Cookie[];
|
|
1392
|
+
/** @description Redirect URL */
|
|
1393
|
+
url: string;
|
|
1394
|
+
/** @description HTTP status code */
|
|
1395
|
+
statusCode: number;
|
|
1396
|
+
/** @description HTTP status text */
|
|
1397
|
+
statusText: string;
|
|
1398
|
+
/** @description Response headers */
|
|
1399
|
+
headers: RezoHeaders;
|
|
1400
|
+
/** @description Redirect timestamp */
|
|
1401
|
+
duration: number;
|
|
1402
|
+
/** @description Request configuration at this step */
|
|
1403
|
+
request: RezoRequestConfig;
|
|
1404
|
+
/** @description HTTP method used */
|
|
1405
|
+
method: string;
|
|
1406
|
+
}[];
|
|
1407
|
+
/** @description Number of redirects followed */
|
|
1408
|
+
redirectCount: number;
|
|
1409
|
+
/** @description Whether maximum redirects limit was reached */
|
|
1410
|
+
maxRedirectsReached: boolean;
|
|
1411
|
+
/**
|
|
1412
|
+
* @description Cookie jar instance for session management
|
|
1413
|
+
* Full RezoCookieJar class with all methods available:
|
|
1414
|
+
* - cookies(): Get all cookies in the jar
|
|
1415
|
+
* - setCookiesSync(cookies, url): Set cookies from Set-Cookie headers
|
|
1416
|
+
* - getCookiesSync(url): Get cookies for a URL
|
|
1417
|
+
* - removeAllCookiesSync(): Clear all cookies
|
|
1418
|
+
*/
|
|
1419
|
+
cookieJar: RezoCookieJar;
|
|
1420
|
+
/** @description Comprehensive timing information */
|
|
1421
|
+
timing: {
|
|
1422
|
+
/** @description Request start timestamp (absolute performance.now() value) */
|
|
1423
|
+
startTimestamp: number;
|
|
1424
|
+
/** @description Request end timestamp (absolute performance.now() value) */
|
|
1425
|
+
endTimestamp: number;
|
|
1426
|
+
/** @description DNS lookup duration in milliseconds */
|
|
1427
|
+
dnsMs?: number;
|
|
1428
|
+
/** @description TCP connection duration in milliseconds */
|
|
1429
|
+
tcpMs?: number;
|
|
1430
|
+
/** @description TLS handshake duration in milliseconds */
|
|
1431
|
+
tlsMs?: number;
|
|
1432
|
+
/** @description Time to first byte in milliseconds (from start to first response byte) */
|
|
1433
|
+
ttfbMs?: number;
|
|
1434
|
+
/** @description Content transfer duration in milliseconds */
|
|
1435
|
+
transferMs?: number;
|
|
1436
|
+
/** @description Total request duration in milliseconds (endTimestamp - startTimestamp) */
|
|
1437
|
+
durationMs: number;
|
|
1438
|
+
};
|
|
1439
|
+
/** @description Network connection information */
|
|
1440
|
+
network: {
|
|
1441
|
+
/** @description Local IP address */
|
|
1442
|
+
localAddress?: string;
|
|
1443
|
+
/** @description Local port number */
|
|
1444
|
+
localPort?: number;
|
|
1445
|
+
/** @description Remote IP address */
|
|
1446
|
+
remoteAddress?: string;
|
|
1447
|
+
/** @description Remote port number */
|
|
1448
|
+
remotePort?: number;
|
|
1449
|
+
/** @description Protocol used (http/https) */
|
|
1450
|
+
protocol: string;
|
|
1451
|
+
/** @description HTTP version (1.1, 2.0, etc.) */
|
|
1452
|
+
httpVersion?: string;
|
|
1453
|
+
/** @description IP family preference (4 for IPv4, 6 for IPv6) */
|
|
1454
|
+
family?: 4 | 6;
|
|
1455
|
+
/** @description Custom DNS lookup function */
|
|
1456
|
+
lookup?: any;
|
|
1457
|
+
};
|
|
1458
|
+
/** @description Data transfer statistics */
|
|
1459
|
+
transfer: {
|
|
1460
|
+
/** @description Total request size in bytes (headers + body) */
|
|
1461
|
+
requestSize: number;
|
|
1462
|
+
/** @description Request headers size in bytes */
|
|
1463
|
+
requestHeaderSize?: number;
|
|
1464
|
+
/** @description Request body size in bytes */
|
|
1465
|
+
requestBodySize?: number;
|
|
1466
|
+
/** @description Total response size in bytes (headers + body) */
|
|
1467
|
+
responseSize: number;
|
|
1468
|
+
/** @description Response headers size in bytes */
|
|
1469
|
+
headerSize: number;
|
|
1470
|
+
/** @description Response body size in bytes */
|
|
1471
|
+
bodySize: number;
|
|
1472
|
+
/** @description Compression ratio if applicable */
|
|
1473
|
+
compressionRatio?: number;
|
|
1474
|
+
};
|
|
1475
|
+
/** @description Number of retry attempts made */
|
|
1476
|
+
retryAttempts: number;
|
|
1477
|
+
/** @description Error history during request execution */
|
|
1478
|
+
errors: Array<{
|
|
1479
|
+
/** @description Retry attempt number */
|
|
1480
|
+
attempt: number;
|
|
1481
|
+
/** @description Error message */
|
|
1482
|
+
error: RezoError;
|
|
1483
|
+
/** @description Request duration before error */
|
|
1484
|
+
duration: number;
|
|
1485
|
+
}>;
|
|
1486
|
+
/** @description Security and validation information */
|
|
1487
|
+
security: {
|
|
1488
|
+
/** @description TLS version used */
|
|
1489
|
+
tlsVersion?: string;
|
|
1490
|
+
/** @description Cipher suite used */
|
|
1491
|
+
cipher?: string;
|
|
1492
|
+
/** @description Certificate information */
|
|
1493
|
+
certificateInfo?: Record<string, any>;
|
|
1494
|
+
/** @description Validation results */
|
|
1495
|
+
validationResults?: Record<string, boolean>;
|
|
1496
|
+
};
|
|
1497
|
+
/** @description Debug mode flag */
|
|
1498
|
+
debug?: boolean;
|
|
1499
|
+
/** @description Request tracking identifier */
|
|
1500
|
+
requestId: string;
|
|
1501
|
+
/** @description Session identifier */
|
|
1502
|
+
sessionId?: string;
|
|
1503
|
+
/** @description Distributed tracing identifier */
|
|
1504
|
+
traceId?: string;
|
|
1505
|
+
/** @description Request timestamp */
|
|
1506
|
+
timestamp: number;
|
|
1507
|
+
/** @description Additional tracking data */
|
|
1508
|
+
trackingData?: Record<string, unknown>;
|
|
1509
|
+
/**
|
|
1510
|
+
* Callback invoked when a redirect response is received.
|
|
1511
|
+
* Controls redirect behavior including whether to follow, modify URL, or change HTTP method.
|
|
1512
|
+
*
|
|
1513
|
+
* @param options - Redirect response details
|
|
1514
|
+
* @param options.url - Redirect target URL
|
|
1515
|
+
* @param options.status - HTTP status code
|
|
1516
|
+
* @param options.headers - Response headers
|
|
1517
|
+
* @param options.sameDomain - Whether redirect is to same domain
|
|
1518
|
+
* @returns Boolean to follow/reject redirect, or object for granular control
|
|
1519
|
+
*
|
|
1520
|
+
* @example
|
|
1521
|
+
* ```typescript
|
|
1522
|
+
* beforeRedirect: ({ status, url }) => {
|
|
1523
|
+
* if (status === 301 || status === 302) {
|
|
1524
|
+
* return true; // Follow permanent/temporary redirects
|
|
1525
|
+
* } else if (status === 307 || status === 308) {
|
|
1526
|
+
* return { redirect: true, url: url.toString() }; // Preserve method for 307/308
|
|
1527
|
+
* } else if (status === 303) {
|
|
1528
|
+
* return { redirect: true, url: url.toString(), method: 'GET' }; // Force GET for 303
|
|
1529
|
+
* }
|
|
1530
|
+
* return false; // Reject other redirects
|
|
1531
|
+
* }
|
|
1532
|
+
* ```
|
|
1533
|
+
*/
|
|
1534
|
+
beforeRedirect?: RezoRequestConfig["beforeRedirect"];
|
|
1535
|
+
/** Character encoding for request body and response data */
|
|
1536
|
+
encoding?: BufferEncoding;
|
|
1537
|
+
/**
|
|
1538
|
+
* Whether to use cookies for the request
|
|
1539
|
+
*/
|
|
1540
|
+
useCookies: boolean;
|
|
1541
|
+
}
|
|
1542
|
+
declare class RezoError<T = any> extends Error {
|
|
1543
|
+
readonly code?: string;
|
|
1544
|
+
readonly errno?: number;
|
|
1545
|
+
readonly config: RezoConfig;
|
|
1546
|
+
readonly request?: RezoHttpRequest;
|
|
1547
|
+
readonly response?: RezoResponse<T>;
|
|
1548
|
+
readonly isRezoError: boolean;
|
|
1549
|
+
readonly cause?: Error;
|
|
1550
|
+
readonly syscall?: string;
|
|
1551
|
+
readonly hostname?: string;
|
|
1552
|
+
readonly port?: number;
|
|
1553
|
+
readonly address?: string;
|
|
1554
|
+
readonly status?: number;
|
|
1555
|
+
readonly statusText?: string;
|
|
1556
|
+
readonly isTimeout: boolean;
|
|
1557
|
+
readonly isAborted: boolean;
|
|
1558
|
+
readonly isNetworkError: boolean;
|
|
1559
|
+
readonly isHttpError: boolean;
|
|
1560
|
+
readonly isProxyError: boolean;
|
|
1561
|
+
readonly isSocksError: boolean;
|
|
1562
|
+
readonly isTlsError: boolean;
|
|
1563
|
+
readonly isRetryable: boolean;
|
|
1564
|
+
readonly details: string;
|
|
1565
|
+
readonly suggestion: string;
|
|
1566
|
+
constructor(message: string, config: RezoConfig, code?: string, request?: RezoHttpRequest, response?: RezoResponse<T>);
|
|
1567
|
+
static isRezoError(error: unknown): error is RezoError;
|
|
1568
|
+
static fromError<T = any>(error: Error, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1569
|
+
static createNetworkError<T = any>(message: string, code: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>;
|
|
1570
|
+
static createHttpError<T = any>(statusCode: number, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1571
|
+
static createTimeoutError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>;
|
|
1572
|
+
static createAbortError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>;
|
|
1573
|
+
static createParsingError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>;
|
|
1574
|
+
static createEnvironmentError<T = any>(message: string, config: RezoConfig): RezoError<T>;
|
|
1575
|
+
static createDecompressionError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1576
|
+
static createDownloadError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1577
|
+
static createUploadError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1578
|
+
static createStreamError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1579
|
+
static createRedirectError<T = any>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1580
|
+
static createProxyError<T = any>(code: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>;
|
|
1581
|
+
static createSocksError<T = any>(code: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>;
|
|
1582
|
+
static createTlsError<T = any>(code: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>;
|
|
1583
|
+
static createRateLimitError<T = any>(config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>;
|
|
1584
|
+
/**
|
|
1585
|
+
* Convert error to JSON - only includes defined values
|
|
1586
|
+
*/
|
|
1587
|
+
toJSON(): Record<string, unknown>;
|
|
1588
|
+
toString(): string;
|
|
1589
|
+
getFullDetails(): string;
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Supported proxy protocols for network requests
|
|
1593
|
+
*/
|
|
1594
|
+
export type ProxyProtocol = "http" | "https" | "socks4" | "socks5";
|
|
1595
|
+
/**
|
|
1596
|
+
* Configuration options for proxy connections
|
|
1597
|
+
*/
|
|
1598
|
+
export type ProxyOptions = {
|
|
1599
|
+
/** The proxy protocol to use */
|
|
1600
|
+
protocol: ProxyProtocol;
|
|
1601
|
+
/** Proxy server hostname or IP address */
|
|
1602
|
+
host: string;
|
|
1603
|
+
/** Proxy server port number */
|
|
1604
|
+
port: number;
|
|
1605
|
+
/** Optional authentication credentials for the proxy */
|
|
1606
|
+
auth?: {
|
|
1607
|
+
/** Username for proxy authentication */
|
|
1608
|
+
username: string;
|
|
1609
|
+
/** Password for proxy authentication */
|
|
1610
|
+
password: string;
|
|
1611
|
+
};
|
|
1612
|
+
/** Connection timeout in milliseconds */
|
|
1613
|
+
timeout?: number;
|
|
1614
|
+
/** Whether to keep the connection alive */
|
|
1615
|
+
keepAlive?: boolean;
|
|
1616
|
+
/** Keep-alive timeout in milliseconds */
|
|
1617
|
+
keepAliveMsecs?: number;
|
|
1618
|
+
/** Maximum number of sockets to allow per host */
|
|
1619
|
+
maxSockets?: number;
|
|
1620
|
+
/** Maximum number of free sockets to keep open per host */
|
|
1621
|
+
maxFreeSockets?: number;
|
|
1622
|
+
/** Whether to reject unauthorized SSL certificates */
|
|
1623
|
+
rejectUnauthorized?: boolean;
|
|
1624
|
+
};
|
|
1625
|
+
/**
|
|
1626
|
+
* Maximum upload rate in bytes per second
|
|
1627
|
+
*/
|
|
1628
|
+
export type MaxUploadRate = number;
|
|
1629
|
+
/**
|
|
1630
|
+
* Maximum download rate in bytes per second
|
|
1631
|
+
*/
|
|
1632
|
+
export type MaxDownloadRate = number;
|
|
1633
|
+
/**
|
|
1634
|
+
* Custom string type for Rezo-specific string values
|
|
1635
|
+
*/
|
|
1636
|
+
export type RezoString = string;
|
|
1637
|
+
/**
|
|
1638
|
+
* Standard HTTP methods supported by Rezo
|
|
1639
|
+
*/
|
|
1640
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT";
|
|
1641
|
+
type ResponseType$1 = "json" | "text" | "blob" | "arrayBuffer" | "buffer" | "auto";
|
|
1642
|
+
/**
|
|
1643
|
+
* MIME content types for request/response bodies
|
|
1644
|
+
*/
|
|
1645
|
+
export type ContentType = "application/json" | "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain" | "text/html" | "application/xml" | "application/octet-stream" | RezoString;
|
|
1646
|
+
/**
|
|
1647
|
+
* RezoRequestConfig - Clean interface for internal request processing
|
|
1648
|
+
*
|
|
1649
|
+
* @template D - Type of the request body data
|
|
1650
|
+
*/
|
|
1651
|
+
export interface RezoRequestConfig<D = any> {
|
|
1652
|
+
/** The target URL for the request */
|
|
1653
|
+
url: string | URL;
|
|
1654
|
+
/**
|
|
1655
|
+
* The absolute request url
|
|
1656
|
+
*/
|
|
1657
|
+
fullUrl: string;
|
|
1658
|
+
/** Request method to use for the request */
|
|
1659
|
+
method: HttpMethod;
|
|
1660
|
+
/** Request headers as various supported formats */
|
|
1661
|
+
headers?: [
|
|
1662
|
+
string,
|
|
1663
|
+
string
|
|
1664
|
+
][] | Record<string, string> | Headers | RezoHttpHeaders | RezoHeaders | OutgoingHttpHeaders;
|
|
1665
|
+
/** URL query parameters to append to the request */
|
|
1666
|
+
params?: Record<string | number, any>;
|
|
1667
|
+
/**
|
|
1668
|
+
* Queue to use for request execution
|
|
1669
|
+
*/
|
|
1670
|
+
queue?: PQueue | null;
|
|
1671
|
+
/**
|
|
1672
|
+
* Controls how the response body is parsed and returned in `response.data`.
|
|
1673
|
+
*
|
|
1674
|
+
* **Available Types:**
|
|
1675
|
+
* - `'json'` - Parse as JSON object/array. Best for REST APIs.
|
|
1676
|
+
* - `'text'` - Return as string. Best for HTML, XML, plain text.
|
|
1677
|
+
* - `'blob'` - Return as Blob (browser). Best for binary in browsers.
|
|
1678
|
+
* - `'arrayBuffer'` - Return as ArrayBuffer. Best for binary processing.
|
|
1679
|
+
* - `'buffer'` - Return as Buffer (Node.js). Best for binary in Node.
|
|
1680
|
+
* - `'auto'` - Auto-detect from Content-Type header (default).
|
|
1681
|
+
*
|
|
1682
|
+
* **For streaming, use dedicated methods instead:**
|
|
1683
|
+
* - `rezo.stream(url)` - Real-time streaming data
|
|
1684
|
+
* - `rezo.download(url, saveTo)` - Download with progress
|
|
1685
|
+
* - `rezo.upload(url, data)` - Upload with progress
|
|
1686
|
+
*
|
|
1687
|
+
* @default 'auto'
|
|
1688
|
+
* @example
|
|
1689
|
+
* // Get JSON
|
|
1690
|
+
* const { data } = await rezo.get('/api/users', { responseType: 'json' });
|
|
1691
|
+
*
|
|
1692
|
+
* // Get HTML as text
|
|
1693
|
+
* const { data: html } = await rezo.get('/page', { responseType: 'text' });
|
|
1694
|
+
*
|
|
1695
|
+
* // Get image as buffer
|
|
1696
|
+
* const { data: img } = await rezo.get('/image.png', { responseType: 'buffer' });
|
|
1697
|
+
*/
|
|
1698
|
+
responseType?: ResponseType$1;
|
|
1699
|
+
/** Character encoding for the response */
|
|
1700
|
+
responseEncoding?: string;
|
|
1701
|
+
/** Base URL for the request (used with relative URLs) */
|
|
1702
|
+
baseURL?: string;
|
|
1703
|
+
/** Raw request body data */
|
|
1704
|
+
body?: D;
|
|
1705
|
+
/** JSON object to be serialized as request body */
|
|
1706
|
+
json?: Record<string, any>;
|
|
1707
|
+
/** Form data to be URL-encoded */
|
|
1708
|
+
form?: Record<string, any>;
|
|
1709
|
+
/** Form data for multipart/form-data requests */
|
|
1710
|
+
formData?: Record<string, any> | RezoFormData;
|
|
1711
|
+
/** Multipart data (alias for formData) */
|
|
1712
|
+
multipart?: Record<string, any> | RezoFormData;
|
|
1713
|
+
/** Whether to detect and prevent redirect cycles */
|
|
1714
|
+
enableRedirectCycleDetection?: boolean;
|
|
1715
|
+
/** MIME type for the request content */
|
|
1716
|
+
contentType?: ContentType | string;
|
|
1717
|
+
/** Skip setting Content-Type header automatically */
|
|
1718
|
+
withoutContentType?: boolean;
|
|
1719
|
+
/** Basic authentication credentials */
|
|
1720
|
+
auth?: {
|
|
1721
|
+
/** Username for authentication */
|
|
1722
|
+
username: string;
|
|
1723
|
+
/** Password for authentication */
|
|
1724
|
+
password: string;
|
|
1725
|
+
};
|
|
1726
|
+
/** Request timeout in milliseconds */
|
|
1727
|
+
timeout?: number;
|
|
1728
|
+
/** Whether to reject requests with invalid SSL certificates */
|
|
1729
|
+
rejectUnauthorized?: boolean;
|
|
1730
|
+
/** Retry configuration for failed requests */
|
|
1731
|
+
retry?: {
|
|
1732
|
+
/** Maximum number of retry attempts */
|
|
1733
|
+
maxRetries?: number;
|
|
1734
|
+
/** Delay between retries in milliseconds */
|
|
1735
|
+
retryDelay?: number;
|
|
1736
|
+
/** Whether to increment delay on each retry */
|
|
1737
|
+
incrementDelay?: boolean;
|
|
1738
|
+
/** HTTP status codes that should trigger a retry attempt defaults are (408, 429, 500, 502, 503, 504, 425, 520) */
|
|
1739
|
+
statusCodes?: number[];
|
|
1740
|
+
/** Weather to stop or continue retry when certain condition is met*/
|
|
1741
|
+
condition?: (error: RezoError) => boolean | Promise<boolean>;
|
|
1742
|
+
};
|
|
1743
|
+
/** Whether to use a secure context for HTTPS requests */
|
|
1744
|
+
useSecureContext?: boolean;
|
|
1745
|
+
/** Custom secure context for TLS connections */
|
|
1746
|
+
secureContext?: SecureContext;
|
|
1747
|
+
/** Whether to automatically follow HTTP redirects */
|
|
1748
|
+
followRedirects?: boolean;
|
|
1749
|
+
/** Maximum number of redirects to follow */
|
|
1750
|
+
maxRedirects?: number;
|
|
1751
|
+
/** Whether to automatically decompress response data */
|
|
1752
|
+
decompress?: boolean;
|
|
1753
|
+
/** Whether to keep the connection alive for reuse */
|
|
1754
|
+
keepAlive?: boolean;
|
|
1755
|
+
withoutBodyOnRedirect?: boolean;
|
|
1756
|
+
autoSetReferer?: boolean;
|
|
1757
|
+
autoSetOrigin?: boolean;
|
|
1758
|
+
treat302As303?: boolean;
|
|
1759
|
+
startNewRequest?: boolean;
|
|
1760
|
+
/** Whether to use HTTP/2 protocol */
|
|
1761
|
+
http2?: boolean;
|
|
1762
|
+
/** Whether to use cURL adapter */
|
|
1763
|
+
curl?: boolean;
|
|
1764
|
+
/**
|
|
1765
|
+
* DNS cache configuration for faster repeated requests.
|
|
1766
|
+
*
|
|
1767
|
+
* When enabled, DNS lookups are cached to avoid repeated DNS queries
|
|
1768
|
+
* for the same hostname, significantly improving performance for
|
|
1769
|
+
* applications making many requests to the same servers.
|
|
1770
|
+
*
|
|
1771
|
+
* **Options:**
|
|
1772
|
+
* - `true` - Enable with default settings (1 min TTL, 1000 entries max)
|
|
1773
|
+
* - `false` - Disable DNS caching (default)
|
|
1774
|
+
* - `object` - Custom configuration with ttl and maxEntries
|
|
1775
|
+
*
|
|
1776
|
+
* @example
|
|
1777
|
+
* // Enable with defaults
|
|
1778
|
+
* { dnsCache: true }
|
|
1779
|
+
*
|
|
1780
|
+
* // Custom TTL (5 minutes) and max entries
|
|
1781
|
+
* { dnsCache: { ttl: 300000, maxEntries: 500 } }
|
|
1782
|
+
*
|
|
1783
|
+
* @default false
|
|
1784
|
+
*/
|
|
1785
|
+
dnsCache?: boolean | {
|
|
1786
|
+
/** Time-to-live for cached entries in milliseconds */
|
|
1787
|
+
ttl?: number;
|
|
1788
|
+
/** Maximum number of entries to cache */
|
|
1789
|
+
maxEntries?: number;
|
|
1790
|
+
};
|
|
1791
|
+
/**
|
|
1792
|
+
* Response cache configuration for caching HTTP responses.
|
|
1793
|
+
*
|
|
1794
|
+
* When enabled, successful GET/HEAD responses are cached to avoid
|
|
1795
|
+
* repeated network requests. Supports memory-only or file persistence.
|
|
1796
|
+
* Honors Cache-Control headers by default.
|
|
1797
|
+
*
|
|
1798
|
+
* **Options:**
|
|
1799
|
+
* - `true` - Enable memory cache with defaults (5 min TTL, 500 entries)
|
|
1800
|
+
* - `false` - Disable response caching (default)
|
|
1801
|
+
* - `object` - Custom configuration
|
|
1802
|
+
*
|
|
1803
|
+
* **Cache-Control Support:**
|
|
1804
|
+
* - Respects `max-age`, `s-maxage`, `no-store`, `no-cache`
|
|
1805
|
+
* - Sends `If-None-Match` / `If-Modified-Since` for revalidation
|
|
1806
|
+
* - Returns cached response on 304 Not Modified
|
|
1807
|
+
*
|
|
1808
|
+
* @example
|
|
1809
|
+
* // Enable memory-only cache
|
|
1810
|
+
* { cache: true }
|
|
1811
|
+
*
|
|
1812
|
+
* // With file persistence
|
|
1813
|
+
* { cache: { cacheDir: './cache', ttl: 300000 } }
|
|
1814
|
+
*
|
|
1815
|
+
* // Custom settings
|
|
1816
|
+
* { cache: {
|
|
1817
|
+
* ttl: 600000, // 10 minutes
|
|
1818
|
+
* maxEntries: 1000,
|
|
1819
|
+
* methods: ['GET'], // Only cache GET
|
|
1820
|
+
* respectHeaders: true // Honor Cache-Control
|
|
1821
|
+
* }}
|
|
1822
|
+
*
|
|
1823
|
+
* @default false
|
|
1824
|
+
*/
|
|
1825
|
+
cache?: boolean | {
|
|
1826
|
+
/** Directory for persistent cache storage (enables file persistence) */
|
|
1827
|
+
cacheDir?: string;
|
|
1828
|
+
/** Time-to-live for cached entries in milliseconds */
|
|
1829
|
+
ttl?: number;
|
|
1830
|
+
/** Maximum number of entries to cache */
|
|
1831
|
+
maxEntries?: number;
|
|
1832
|
+
/** HTTP methods to cache */
|
|
1833
|
+
methods?: string[];
|
|
1834
|
+
/** Whether to respect Cache-Control headers */
|
|
1835
|
+
respectHeaders?: boolean;
|
|
1836
|
+
};
|
|
1837
|
+
/**
|
|
1838
|
+
* Callback invoked when a redirect response is received.
|
|
1839
|
+
* Controls redirect behavior including whether to follow, modify URL, or change HTTP method.
|
|
1840
|
+
*
|
|
1841
|
+
* @param options - Redirect response details
|
|
1842
|
+
* @param options.url - Redirect target URL
|
|
1843
|
+
* @param options.status - HTTP status code
|
|
1844
|
+
* @param options.headers - Response headers
|
|
1845
|
+
* @param options.sameDomain - Whether redirect is to same domain
|
|
1846
|
+
* @returns Boolean to follow/reject redirect, or object for granular control
|
|
1847
|
+
*
|
|
1848
|
+
* @example
|
|
1849
|
+
* ```typescript
|
|
1850
|
+
* beforeRedirect: ({ status, url }) => {
|
|
1851
|
+
* if (status === 301 || status === 302) {
|
|
1852
|
+
* return true; // Follow permanent/temporary redirects
|
|
1853
|
+
* } else if (status === 307 || status === 308) {
|
|
1854
|
+
* return { redirect: true, url: url.toString() }; // Preserve method for 307/308
|
|
1855
|
+
* } else if (status === 303) {
|
|
1856
|
+
* return { redirect: true, url: url.toString(), method: 'GET' }; // Force GET for 303
|
|
1857
|
+
* }
|
|
1858
|
+
* return false; // Reject other redirects
|
|
1859
|
+
* }
|
|
1860
|
+
* ```
|
|
1861
|
+
*/
|
|
1862
|
+
beforeRedirect?: (options: OnRedirectOptions) => OnRedirectResponse;
|
|
1863
|
+
/** Whether to send cookies and authorization headers with cross-origin requests */
|
|
1864
|
+
withCredentials?: boolean;
|
|
1865
|
+
/** Proxy configuration (URL string or detailed options) */
|
|
1866
|
+
proxy?: string | ProxyOptions;
|
|
1867
|
+
/** Whether to enable automatic cookie handling */
|
|
1868
|
+
useCookies?: boolean;
|
|
1869
|
+
/** Custom cookie jar for managing cookies */
|
|
1870
|
+
cookieJar?: RezoCookieJar;
|
|
1871
|
+
/** Cookies to send with the request in various formats */
|
|
1872
|
+
cookies?: Cookies["array"] | Cookies["netscape"] | Cookies["serialized"] | Cookies["setCookiesString"];
|
|
1873
|
+
/** Callback for upload progress events */
|
|
1874
|
+
onUploadProgress?: (progressEvent: any) => void;
|
|
1875
|
+
/** Callback for download progress events */
|
|
1876
|
+
onDownloadProgress?: (progressEvent: any) => void;
|
|
1877
|
+
/** Maximum allowed size of the request body in bytes */
|
|
1878
|
+
maxBodyLength?: number;
|
|
1879
|
+
/** Maximum transfer rate (single number or [upload, download] tuple) */
|
|
1880
|
+
maxRate?: number | [
|
|
1881
|
+
MaxUploadRate,
|
|
1882
|
+
MaxDownloadRate
|
|
1883
|
+
];
|
|
1884
|
+
/** Array of functions to transform request data */
|
|
1885
|
+
transformRequest?: Array<(data: any, headers: RezoHeaders) => any>;
|
|
1886
|
+
/** Array of functions to transform response data */
|
|
1887
|
+
transformResponse?: Array<(data: any) => any>;
|
|
1888
|
+
/** Adapter to use for the request (name or custom function) */
|
|
1889
|
+
adapter?: string | ((config: RezoRequestConfig) => Promise<any>);
|
|
1890
|
+
/** AbortSignal to cancel the request */
|
|
1891
|
+
signal?: AbortSignal;
|
|
1892
|
+
/** File path to save the response to (for downloads) */
|
|
1893
|
+
saveTo?: string;
|
|
1894
|
+
/** Custom filename for downloaded files */
|
|
1895
|
+
fileName?: string;
|
|
1896
|
+
/** Browser simulation configuration for user agent spoofing */
|
|
1897
|
+
browser?: {
|
|
1898
|
+
/** Browser name to simulate */
|
|
1899
|
+
name: "chrome" | "firefox" | "safari" | "edge" | "opera" | "ie" | "chromium";
|
|
1900
|
+
/** Browser version string */
|
|
1901
|
+
version: string;
|
|
1902
|
+
/** Device platform type */
|
|
1903
|
+
platform: "desktop" | "mobile" | "tablet";
|
|
1904
|
+
/** Operating system details */
|
|
1905
|
+
os: {
|
|
1906
|
+
/** Operating system name */
|
|
1907
|
+
name: "windows" | "macos" | "linux" | "ios" | "android" | "chromeos";
|
|
1908
|
+
/** OS version string */
|
|
1909
|
+
version: string;
|
|
1910
|
+
/** CPU architecture */
|
|
1911
|
+
architecture: "x86" | "x64" | "arm" | "arm64";
|
|
1912
|
+
};
|
|
1913
|
+
/** Browser language preference */
|
|
1914
|
+
language?: string;
|
|
1915
|
+
};
|
|
1916
|
+
/** Enable debug logging for the request */
|
|
1917
|
+
debug?: boolean;
|
|
1918
|
+
/** Enable verbose logging with detailed information */
|
|
1919
|
+
verbose?: boolean;
|
|
1920
|
+
/** Name of the cookie containing XSRF token */
|
|
1921
|
+
xsrfCookieName?: string;
|
|
1922
|
+
/** Name of the header to send XSRF token in */
|
|
1923
|
+
xsrfHeaderName?: string;
|
|
1924
|
+
/** Custom HTTP agent for HTTP requests */
|
|
1925
|
+
httpAgent?: HttpAgent;
|
|
1926
|
+
/** Custom HTTPS agent for HTTPS requests */
|
|
1927
|
+
httpsAgent?: HttpsAgent;
|
|
1928
|
+
/** Transitional options for backward compatibility */
|
|
1929
|
+
transitional?: {
|
|
1930
|
+
/** Silently ignore JSON parsing errors */
|
|
1931
|
+
silentJSONParsing?: boolean;
|
|
1932
|
+
/** Force JSON parsing even for non-JSON responses */
|
|
1933
|
+
forcedJSONParsing?: boolean;
|
|
1934
|
+
/** Provide clearer timeout error messages */
|
|
1935
|
+
clarifyTimeoutError?: boolean;
|
|
1936
|
+
};
|
|
1937
|
+
/** Character encoding for request body and response data */
|
|
1938
|
+
encoding?: BufferEncoding;
|
|
1939
|
+
/**
|
|
1940
|
+
* Request lifecycle hooks for intercepting and modifying request/response behavior.
|
|
1941
|
+
* Optional hooks that will be merged with default hooks during request processing.
|
|
1942
|
+
*/
|
|
1943
|
+
hooks?: Partial<RezoHooks>;
|
|
1944
|
+
}
|
|
1945
|
+
export interface OnRedirectOptions {
|
|
1946
|
+
url: URL;
|
|
1947
|
+
status: number;
|
|
1948
|
+
headers: RezoHeaders;
|
|
1949
|
+
sameDomain: boolean;
|
|
1950
|
+
method: string;
|
|
1951
|
+
}
|
|
1952
|
+
export type OnRedirectResponse = boolean | ToRedirectOptions | undefined;
|
|
1953
|
+
export type ToRedirectOptions = {
|
|
1954
|
+
redirect: false;
|
|
1955
|
+
message?: string;
|
|
1956
|
+
} | {
|
|
1957
|
+
redirect: true;
|
|
1958
|
+
url: string;
|
|
1959
|
+
method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
|
|
1960
|
+
body?: any;
|
|
1961
|
+
withoutBody?: boolean;
|
|
1962
|
+
setHeaders?: RezoHeaders | OutgoingHttpHeaders;
|
|
1963
|
+
setHeadersOnRedirects?: RezoHeaders | OutgoingHttpHeaders;
|
|
1964
|
+
};
|
|
1965
|
+
/**
|
|
1966
|
+
* RezoHttpRequest - Request configuration type for all methods
|
|
1967
|
+
*
|
|
1968
|
+
* This type excludes internal properties and is specifically designed for public API usage.
|
|
1969
|
+
* Use this type when creating reusable request configurations for the all method.
|
|
1970
|
+
*
|
|
1971
|
+
* @public - Use with all methods
|
|
1972
|
+
* @internal - Do not use internally within the library
|
|
1973
|
+
*/
|
|
1974
|
+
export type RezoHttpRequest = Omit<RezoRequestConfig, "body" | "url" | "method" | "form" | "json" | "formData" | "multipart" | "fullUrl" | "responseType">;
|
|
1975
|
+
export interface DNSCacheOptions {
|
|
1976
|
+
enable?: boolean;
|
|
1977
|
+
ttl?: number;
|
|
1978
|
+
maxEntries?: number;
|
|
1979
|
+
}
|
|
1980
|
+
export interface ResponseCacheConfig {
|
|
1981
|
+
enable?: boolean;
|
|
1982
|
+
cacheDir?: string;
|
|
1983
|
+
networkCheck?: boolean;
|
|
1984
|
+
ttl?: number;
|
|
1985
|
+
maxEntries?: number;
|
|
1986
|
+
methods?: string[];
|
|
1987
|
+
respectHeaders?: boolean;
|
|
1988
|
+
}
|
|
1989
|
+
export type queueOptions = Options$1<PriorityQueue, QueueAddOptions>;
|
|
1990
|
+
export interface CacheConfig {
|
|
1991
|
+
/** Response cache configuration */
|
|
1992
|
+
response?: boolean | ResponseCacheConfig;
|
|
1993
|
+
/** DNS cache configuration */
|
|
1994
|
+
dns?: boolean | DNSCacheOptions;
|
|
1995
|
+
}
|
|
1996
|
+
export type CacheOption = boolean | CacheConfig;
|
|
1997
|
+
export interface RezoDefaultOptions {
|
|
1998
|
+
baseURL?: string;
|
|
1999
|
+
/** Hooks for request/response lifecycle */
|
|
2000
|
+
hooks?: Partial<RezoHooks>;
|
|
2001
|
+
/** Whether to enable automatic cookie handling (default: true)*/
|
|
2002
|
+
enableCookieJar?: boolean;
|
|
2003
|
+
/** Custom cookie jar for managing cookies */
|
|
2004
|
+
cookieJar?: RezoHttpRequest["cookieJar"];
|
|
2005
|
+
/** Set default cookies to send with the requests in various formats */
|
|
2006
|
+
cookies?: RezoHttpRequest["cookies"];
|
|
2007
|
+
/**
|
|
2008
|
+
* Path to cookie file for persistence.
|
|
2009
|
+
* - .json files save cookies as serialized JSON
|
|
2010
|
+
* - .txt files save cookies in Netscape format
|
|
2011
|
+
* Cookies are loaded on construction and saved automatically after each request.
|
|
2012
|
+
*/
|
|
2013
|
+
cookieFile?: string;
|
|
2014
|
+
queueOptions?: {
|
|
2015
|
+
enable: boolean;
|
|
2016
|
+
options?: queueOptions;
|
|
2017
|
+
};
|
|
2018
|
+
/** Request headers as various supported formats */
|
|
2019
|
+
headers?: RezoHttpRequest["headers"];
|
|
2020
|
+
/** Expected response data type */
|
|
2021
|
+
responseType?: ResponseType$1;
|
|
2022
|
+
/** Character encoding for the response */
|
|
2023
|
+
responseEncoding?: string;
|
|
2024
|
+
/** Basic authentication credentials */
|
|
2025
|
+
auth?: RezoHttpRequest["auth"];
|
|
2026
|
+
/** Request timeout in milliseconds */
|
|
2027
|
+
timeout?: number;
|
|
2028
|
+
/** @deprecated Use `timeout` instead */
|
|
2029
|
+
requestTimeout?: number;
|
|
2030
|
+
/** Whether to reject requests with invalid SSL certificates */
|
|
2031
|
+
rejectUnauthorized?: boolean;
|
|
2032
|
+
/** Retry configuration for failed requests */
|
|
2033
|
+
retry?: RezoHttpRequest["retry"];
|
|
2034
|
+
/** Whether to use a secure context for HTTPS requests */
|
|
2035
|
+
useSecureContext?: boolean;
|
|
2036
|
+
/** Custom secure context for TLS connections */
|
|
2037
|
+
secureContext?: RezoHttpRequest["secureContext"];
|
|
2038
|
+
/** Whether to automatically follow HTTP redirects */
|
|
2039
|
+
followRedirects?: boolean;
|
|
2040
|
+
/** Maximum number of redirects to follow */
|
|
2041
|
+
maxRedirects?: number;
|
|
2042
|
+
/** Whether to automatically decompress response data */
|
|
2043
|
+
decompress?: boolean;
|
|
2044
|
+
/** Whether to keep the connection alive for reuse */
|
|
2045
|
+
keepAlive?: boolean;
|
|
2046
|
+
/** Whether to detect and prevent redirect cycles */
|
|
2047
|
+
enableRedirectCycleDetection?: boolean;
|
|
2048
|
+
/** Whether to use HTTP/2 protocol */
|
|
2049
|
+
http2?: boolean;
|
|
2050
|
+
/** Whether to use cURL adapter */
|
|
2051
|
+
curl?: boolean;
|
|
2052
|
+
/** Whether to send cookies and authorization headers with cross-origin requests */
|
|
2053
|
+
withCredentials?: boolean;
|
|
2054
|
+
/** Proxy configuration (URL string or detailed options) */
|
|
2055
|
+
proxy?: RezoHttpRequest["proxy"];
|
|
2056
|
+
/** Maximum allowed size of the request body in bytes */
|
|
2057
|
+
maxBodyLength?: number;
|
|
2058
|
+
/** Maximum transfer rate (single number or [upload, download] tuple) */
|
|
2059
|
+
maxRate?: RezoHttpRequest["maxRate"];
|
|
2060
|
+
/**
|
|
2061
|
+
* Callback invoked when a redirect response is received.
|
|
2062
|
+
* Controls redirect behavior including whether to follow, modify URL, or change HTTP method.
|
|
2063
|
+
*
|
|
2064
|
+
* @param options - Redirect response details
|
|
2065
|
+
* @param options.url - Redirect target URL
|
|
2066
|
+
* @param options.status - HTTP status code
|
|
2067
|
+
* @param options.headers - Response headers
|
|
2068
|
+
* @param options.sameDomain - Whether redirect is to same domain
|
|
2069
|
+
* @returns Boolean to follow/reject redirect, or object for granular control
|
|
2070
|
+
*
|
|
2071
|
+
* @example
|
|
2072
|
+
* ```typescript
|
|
2073
|
+
* beforeRedirect: ({ status, url }) => {
|
|
2074
|
+
* if (status === 301 || status === 302) {
|
|
2075
|
+
* return true; // Follow permanent/temporary redirects
|
|
2076
|
+
* } else if (status === 307 || status === 308) {
|
|
2077
|
+
* return { redirect: true, url: url.toString() }; // Preserve method for 307/308
|
|
2078
|
+
* } else if (status === 303) {
|
|
2079
|
+
* return { redirect: true, url: url.toString(), method: 'GET' }; // Force GET for 303
|
|
2080
|
+
* }
|
|
2081
|
+
* return false; // Reject other redirects
|
|
2082
|
+
* }
|
|
2083
|
+
* ```
|
|
2084
|
+
*/
|
|
2085
|
+
beforeRedirect?: RezoHttpRequest["beforeRedirect"];
|
|
2086
|
+
/** Array of functions to transform request data */
|
|
2087
|
+
transformRequest?: RezoHttpRequest["transformRequest"];
|
|
2088
|
+
/** Array of functions to transform response data */
|
|
2089
|
+
transformResponse?: RezoHttpRequest["transformResponse"];
|
|
2090
|
+
/** Adapter to use for the request (name or custom function) */
|
|
2091
|
+
adapter?: RezoHttpRequest["adapter"];
|
|
2092
|
+
/** Browser simulation configuration for user agent spoofing */
|
|
2093
|
+
browser?: RezoHttpRequest["browser"];
|
|
2094
|
+
/** Enable debug logging for the request */
|
|
2095
|
+
debug?: RezoHttpRequest["debug"];
|
|
2096
|
+
/** Enable verbose logging with detailed information */
|
|
2097
|
+
verbose?: RezoHttpRequest["verbose"];
|
|
2098
|
+
/** HTTP agent for HTTP requests */
|
|
2099
|
+
httpAgent?: RezoHttpRequest["httpAgent"];
|
|
2100
|
+
/** HTTPS agent for HTTPS requests */
|
|
2101
|
+
httpsAgent?: RezoHttpRequest["httpsAgent"];
|
|
2102
|
+
/** Transitional options for backward compatibility */
|
|
2103
|
+
transitional?: RezoHttpRequest["transitional"];
|
|
2104
|
+
/** Character encoding for request body and response data */
|
|
2105
|
+
encoding?: BufferEncoding;
|
|
2106
|
+
/**
|
|
2107
|
+
* Cache configuration for response and DNS caching
|
|
2108
|
+
* - `true`: Enable default in-memory cache (fast, sensible defaults)
|
|
2109
|
+
* - `{ response: {...}, dns: {...} }`: Fine-grained control
|
|
2110
|
+
*
|
|
2111
|
+
* Response cache defaults: 30 min TTL, 500 entries, GET/HEAD only
|
|
2112
|
+
* DNS cache defaults: 1 min TTL, 1000 entries
|
|
2113
|
+
*/
|
|
2114
|
+
cache?: CacheOption;
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Execute HTTP/2 request - main adapter entry point
|
|
2118
|
+
* Follows the same pattern as http.ts executeRequest
|
|
2119
|
+
*/
|
|
2120
|
+
declare function executeRequest<T = any>(options: RezoRequestConfig, defaultOptions: RezoDefaultOptions, jar: RezoCookieJar): Promise<RezoResponse<T> | RezoStreamResponse | RezoDownloadResponse | RezoUploadResponse>;
|
|
2121
|
+
/**
|
|
2122
|
+
* Execute HTTP request using Node.js http/https modules
|
|
2123
|
+
*/
|
|
2124
|
+
declare function executeRequest$1<T = any>(options: RezoRequestConfig, defaultOptions: RezoDefaultOptions, jar: RezoCookieJar): Promise<RezoResponse<T> | RezoStreamResponse | RezoDownloadResponse | RezoUploadResponse>;
|
|
2125
|
+
/**
|
|
2126
|
+
* Unified adapter execution function type.
|
|
2127
|
+
* All adapters implement this signature for consistent behavior.
|
|
2128
|
+
*/
|
|
2129
|
+
export type ExecuteRequestFn<T = any> = (options: RezoRequestConfig, defaultOptions: RezoDefaultOptions, jar: RezoCookieJar) => Promise<RezoResponse<T> | RezoStreamResponse | RezoDownloadResponse | RezoUploadResponse>;
|
|
2130
|
+
|
|
2131
|
+
export {
|
|
2132
|
+
executeRequest as executeHttp2Request,
|
|
2133
|
+
executeRequest$1 as executeHttpRequest,
|
|
2134
|
+
};
|
|
2135
|
+
|
|
2136
|
+
export {};
|