rezo 1.0.30 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/adapters/curl.cjs +8 -10
  2. package/dist/adapters/curl.js +8 -10
  3. package/dist/adapters/entries/curl.d.ts +169 -313
  4. package/dist/adapters/entries/fetch.d.ts +169 -313
  5. package/dist/adapters/entries/http.d.ts +169 -313
  6. package/dist/adapters/entries/http2.d.ts +169 -313
  7. package/dist/adapters/entries/react-native.d.ts +169 -313
  8. package/dist/adapters/entries/xhr.d.ts +169 -313
  9. package/dist/adapters/fetch.cjs +10 -7
  10. package/dist/adapters/fetch.js +10 -7
  11. package/dist/adapters/http.cjs +9 -12
  12. package/dist/adapters/http.js +9 -12
  13. package/dist/adapters/http2.cjs +6 -11
  14. package/dist/adapters/http2.js +6 -11
  15. package/dist/adapters/index.cjs +6 -6
  16. package/dist/adapters/react-native.cjs +4 -4
  17. package/dist/adapters/react-native.js +4 -4
  18. package/dist/adapters/xhr.cjs +4 -4
  19. package/dist/adapters/xhr.js +4 -4
  20. package/dist/cache/index.cjs +13 -13
  21. package/dist/cache/universal-response-cache.cjs +165 -0
  22. package/dist/cache/universal-response-cache.js +162 -0
  23. package/dist/core/rezo.cjs +2 -8
  24. package/dist/core/rezo.js +2 -8
  25. package/dist/crawler.d.ts +163 -313
  26. package/dist/entries/crawler.cjs +5 -5
  27. package/dist/index.cjs +24 -24
  28. package/dist/index.d.ts +169 -313
  29. package/dist/platform/browser.d.ts +169 -313
  30. package/dist/platform/bun.d.ts +169 -313
  31. package/dist/platform/deno.d.ts +169 -313
  32. package/dist/platform/node.d.ts +169 -313
  33. package/dist/platform/react-native.d.ts +169 -313
  34. package/dist/platform/worker.d.ts +169 -313
  35. package/dist/plugin/crawler.cjs +1 -1
  36. package/dist/plugin/crawler.js +1 -1
  37. package/dist/plugin/index.cjs +36 -36
  38. package/dist/proxy/index.cjs +4 -4
  39. package/dist/queue/index.cjs +8 -8
  40. package/dist/responses/buildResponse.cjs +15 -15
  41. package/dist/responses/buildResponse.js +15 -15
  42. package/dist/responses/universal/download.cjs +23 -0
  43. package/dist/responses/universal/download.js +22 -0
  44. package/dist/responses/universal/event-emitter.cjs +104 -0
  45. package/dist/responses/universal/event-emitter.js +102 -0
  46. package/dist/responses/universal/index.cjs +11 -0
  47. package/dist/responses/universal/index.js +4 -0
  48. package/dist/responses/universal/stream.cjs +32 -0
  49. package/dist/responses/universal/stream.js +31 -0
  50. package/dist/responses/universal/upload.cjs +23 -0
  51. package/dist/responses/universal/upload.js +22 -0
  52. package/dist/utils/cookies.browser.cjs +63 -0
  53. package/dist/utils/cookies.browser.js +61 -0
  54. package/dist/utils/form-data.cjs +212 -189
  55. package/dist/utils/form-data.js +212 -189
  56. package/dist/utils/http-config.cjs +28 -15
  57. package/dist/utils/http-config.js +28 -15
  58. package/package.json +11 -4
  59. package/dist/types/cookies.cjs +0 -394
  60. package/dist/types/cookies.js +0 -391
@@ -1,391 +0,0 @@
1
- import { CookieJar as TouchCookieJar, Cookie as TouchCookie } from "tough-cookie";
2
-
3
- export class Cookie extends TouchCookie {
4
- constructor(options) {
5
- super(options);
6
- }
7
- getExpires() {
8
- let expires = 0;
9
- if (this.expires && typeof this.expires !== "string") {
10
- expires = Math.round(this.expires.getTime() / 1000);
11
- } else if (this.maxAge) {
12
- if (this.maxAge === "Infinity") {
13
- expires = 2147483647;
14
- } else if (this.maxAge === "-Infinity") {
15
- expires = 0;
16
- } else if (typeof this.maxAge === "number") {
17
- expires = Math.round(Date.now() / 1000 + this.maxAge);
18
- }
19
- }
20
- return expires;
21
- }
22
- toNetscapeFormat() {
23
- const domain = !this.hostOnly ? this.domain.startsWith(".") ? this.domain : "." + this.domain : this.domain;
24
- const secure = this.secure ? "TRUE" : "FALSE";
25
- const expires = this.getExpires();
26
- return `${domain} TRUE ${this.path} ${secure} ${expires} ${this.key} ${this.value}`;
27
- }
28
- toSetCookieString() {
29
- let str = this.cookieString();
30
- if (this.expires instanceof Date) {
31
- str += `; Expires=${this.expires.toUTCString()}`;
32
- }
33
- if (this.maxAge != null) {
34
- str += `; Max-Age=${this.maxAge}`;
35
- }
36
- if (this.domain) {
37
- str += `; Domain=${this.domain}`;
38
- }
39
- if (this.path) {
40
- str += `; Path=${this.path}`;
41
- }
42
- if (this.secure) {
43
- str += "; Secure";
44
- }
45
- if (this.httpOnly) {
46
- str += "; HttpOnly";
47
- }
48
- if (this.sameSite) {
49
- str += `; SameSite=${this.sameSite}`;
50
- }
51
- if (this.extensions) {
52
- str += `; ${this.extensions.join("; ")}`;
53
- }
54
- return str;
55
- }
56
- getURL() {
57
- if (!this.domain) {
58
- return;
59
- }
60
- const protocol = this.secure ? "https://" : "http://";
61
- const domain = this.domain.startsWith(".") ? this.domain.substring(1) : this.domain;
62
- const path = this.path || "/";
63
- return `${protocol}${domain}${path}`;
64
- }
65
- }
66
-
67
- export class CookieJar extends TouchCookieJar {
68
- constructor(store, options) {
69
- super(store, options);
70
- }
71
- generateCookies(data) {
72
- const cookies = !data ? (this.toJSON()?.cookies || []).map((cookie) => new Cookie(cookie)) : data[0] instanceof Cookie ? data : data.map((cookie) => new Cookie(cookie instanceof TouchCookie ? cookie : Cookie.fromJSON(cookie)));
73
- const netscape = cookies.map((cookie) => cookie.toNetscapeFormat());
74
- const cookieString = cookies.map((cookie) => cookie.cookieString());
75
- const setCookiesString = cookies.map((cookie) => cookie.toSetCookieString());
76
- let netscapeString = `# Netscape HTTP Cookie File
77
- `;
78
- netscapeString += `# This file was generated by Rezo HTTP client
79
- `;
80
- netscapeString += `# https://github.com/yuniq-solutions/rezo
81
- `;
82
- netscapeString += netscape.join(`
83
- `) || "";
84
- return {
85
- array: cookies,
86
- serialized: this.toJSON()?.cookies || [],
87
- netscape: netscapeString,
88
- string: cookieString.join("; "),
89
- setCookiesString
90
- };
91
- }
92
- cookies() {
93
- return this.generateCookies();
94
- }
95
- parseResponseCookies(cookies) {
96
- return this.generateCookies(cookies);
97
- }
98
- static toNetscapeCookie(cookies) {
99
- cookies = cookies.map((cookie) => {
100
- return cookie instanceof Cookie ? cookie : new Cookie(Cookie.fromJSON(cookie));
101
- });
102
- let netscapeString = `# Netscape HTTP Cookie File
103
- `;
104
- netscapeString += `# This file was generated by Rezo HTTP client
105
- `;
106
- netscapeString += `# https://github.com/yuniq-solutions/rezo
107
- `;
108
- netscapeString += cookies.map((cookie) => cookie.toNetscapeFormat()).join(`
109
- `) || "";
110
- return netscapeString;
111
- }
112
- static toCookieString(cookies) {
113
- cookies = cookies.map((cookie) => {
114
- return cookie instanceof Cookie ? cookie : new Cookie(Cookie.fromJSON(cookie));
115
- });
116
- return cookies.map((cookie) => cookie.cookieString()).join("; ") || "";
117
- }
118
- toCookieString() {
119
- return this.cookies().string;
120
- }
121
- toNetscapeCookie() {
122
- return this.cookies().netscape;
123
- }
124
- toArray() {
125
- return this.cookies().array;
126
- }
127
- toSetCookies() {
128
- return this.cookies().setCookiesString;
129
- }
130
- toSerializedCookies() {
131
- return this.cookies().serialized;
132
- }
133
- setCookiesSync(cookiesData, url) {
134
- const cookies = [];
135
- if (Array.isArray(cookiesData)) {
136
- cookiesData.forEach((c) => {
137
- const cookie = c instanceof Cookie ? c : typeof c === "string" ? new Cookie(Cookie.parse(c)) : new Cookie(Cookie.fromJSON(c));
138
- let isFailed = 0;
139
- while (isFailed < 2) {
140
- try {
141
- if (cookie) {
142
- const _url = isFailed > 0 ? cookie.getURL() || url || this.getUrlFromCookie(cookie) : url || this.getUrlFromCookie(cookie);
143
- if (_url) {
144
- const __cookie = this.setCookieSync(cookie, _url);
145
- if (__cookie) {
146
- cookies.push(__cookie);
147
- }
148
- }
149
- isFailed = 4;
150
- break;
151
- } else {
152
- isFailed++;
153
- }
154
- } catch (error) {
155
- isFailed++;
156
- if (isFailed > 1) {
157
- break;
158
- }
159
- }
160
- }
161
- });
162
- } else if (typeof cookiesData === "string") {
163
- if (cookiesData.includes(",") && (cookiesData.includes("=") && (cookiesData.includes(";") || cookiesData.includes("expires=") || cookiesData.includes("path=")))) {
164
- const setCookieStrings = this.splitSetCookiesString(cookiesData);
165
- setCookieStrings.forEach((cookieStr) => {
166
- const cookie = new Cookie(Cookie.parse(cookieStr));
167
- let isFailed = 0;
168
- while (isFailed < 2) {
169
- try {
170
- if (cookie) {
171
- const _url = isFailed > 0 ? cookie.getURL() || url || this.getUrlFromCookie(cookie) : url || this.getUrlFromCookie(cookie);
172
- if (_url) {
173
- const __cookie = this.setCookieSync(cookie, _url);
174
- if (__cookie) {
175
- cookies.push(__cookie);
176
- }
177
- }
178
- isFailed = 4;
179
- break;
180
- } else {
181
- isFailed++;
182
- }
183
- } catch (error) {
184
- isFailed++;
185
- if (isFailed > 1) {
186
- break;
187
- }
188
- }
189
- }
190
- });
191
- } else if (cookiesData.includes("=") && cookiesData.includes(";")) {
192
- const cookiePairs = cookiesData.split(";");
193
- cookiePairs.forEach((pair) => {
194
- const trimmedPair = pair.trim();
195
- if (trimmedPair) {
196
- const cookie = new Cookie({ key: trimmedPair.split("=")[0].trim(), value: trimmedPair.split("=")[1]?.trim() || "" });
197
- let isFailed = 0;
198
- while (isFailed < 2) {
199
- try {
200
- if (cookie) {
201
- const _url = isFailed > 0 ? cookie.getURL() || url || this.getUrlFromCookie(cookie) : url || this.getUrlFromCookie(cookie);
202
- if (_url) {
203
- const __cookie = this.setCookieSync(cookie, _url);
204
- if (__cookie) {
205
- cookies.push(__cookie);
206
- }
207
- }
208
- isFailed = 4;
209
- break;
210
- } else {
211
- isFailed++;
212
- }
213
- } catch (error) {
214
- isFailed++;
215
- if (isFailed > 1) {
216
- break;
217
- }
218
- }
219
- }
220
- }
221
- });
222
- } else if (cookiesData.includes("\t") && /^\S+\t/.test(cookiesData)) {
223
- const netscapeCookies = this.parseNetscapeCookies(cookiesData);
224
- netscapeCookies.forEach((c) => {
225
- const cookie = new Cookie(c);
226
- let isFailed = 0;
227
- while (isFailed < 2) {
228
- try {
229
- if (cookie) {
230
- const _url = isFailed > 0 ? cookie.getURL() || url || this.getUrlFromCookie(cookie) : url || this.getUrlFromCookie(cookie);
231
- if (_url) {
232
- const __cookie = this.setCookieSync(cookie, _url);
233
- if (__cookie) {
234
- cookies.push(__cookie);
235
- }
236
- }
237
- isFailed = 4;
238
- break;
239
- } else {
240
- isFailed++;
241
- }
242
- } catch (error) {
243
- isFailed++;
244
- if (isFailed > 1) {
245
- break;
246
- }
247
- }
248
- }
249
- });
250
- } else if (cookiesData.includes("=")) {
251
- const cookie = new Cookie(Cookie.parse(cookiesData));
252
- let isFailed = 0;
253
- while (isFailed < 2) {
254
- try {
255
- if (cookie) {
256
- const _url = isFailed > 0 ? cookie.getURL() || url || this.getUrlFromCookie(cookie) : url || this.getUrlFromCookie(cookie);
257
- if (_url) {
258
- const __cookie = this.setCookieSync(cookie, _url);
259
- if (__cookie) {
260
- cookies.push(__cookie);
261
- }
262
- }
263
- isFailed = 4;
264
- break;
265
- } else {
266
- isFailed++;
267
- }
268
- } catch (error) {
269
- isFailed++;
270
- if (isFailed > 1) {
271
- break;
272
- }
273
- }
274
- }
275
- }
276
- }
277
- return this.generateCookies(cookies);
278
- }
279
- splitSetCookiesString(cookiesString) {
280
- const result = [];
281
- let currentCookie = "";
282
- let withinValue = false;
283
- for (let i = 0;i < cookiesString.length; i++) {
284
- const char = cookiesString[i];
285
- if (char === "," && !withinValue) {
286
- result.push(currentCookie.trim());
287
- currentCookie = "";
288
- continue;
289
- }
290
- if (char === "=") {
291
- withinValue = true;
292
- } else if (char === ";") {
293
- withinValue = false;
294
- }
295
- currentCookie += char;
296
- }
297
- if (currentCookie.trim()) {
298
- result.push(currentCookie.trim());
299
- }
300
- return result;
301
- }
302
- getUrlFromCookie(cookie) {
303
- if (!cookie.domain) {
304
- return;
305
- }
306
- const proto = cookie.secure ? "https://" : "http://";
307
- const domain = cookie.domain.startsWith(".") ? cookie.domain.substring(1) : cookie.domain;
308
- const pathname = cookie.path || "/";
309
- return `${proto}${domain}${pathname}`;
310
- }
311
- parseNetscapeCookies = (cookieText) => {
312
- const lines = cookieText.split(`
313
- `).filter((line) => line.trim() !== "" && !line.startsWith("#"));
314
- return lines.map((line) => {
315
- const parts = line.split("\t");
316
- if (parts.length < 7) {
317
- throw new Error(`Invalid Netscape cookie format: ${line}`);
318
- }
319
- const [domain, _, path, secureStr, expiresStr, name, value] = parts;
320
- let expires = null;
321
- if (expiresStr !== "0" && expiresStr !== "") {
322
- expires = new Date(parseInt(expiresStr, 10) * 1000);
323
- }
324
- return {
325
- domain,
326
- path,
327
- secure: secureStr.toUpperCase() === "TRUE",
328
- expires,
329
- key: name,
330
- value,
331
- httpOnly: false,
332
- sameSite: undefined
333
- };
334
- });
335
- };
336
- static netscapeCookiesToSetCookieArray(netscapeCookieText) {
337
- const parseNetscapeCookies = (cookieText) => {
338
- const lines = cookieText.split(`
339
- `).filter((line) => line.trim() !== "" && !line.startsWith("#"));
340
- return lines.map((line) => {
341
- const parts = line.split("\t");
342
- if (parts.length < 7) {
343
- throw new Error(`Invalid Netscape cookie format: ${line}`);
344
- }
345
- const [domain, _, path, secureStr, expiresStr, name, value] = parts;
346
- let expires = null;
347
- if (expiresStr !== "0" && expiresStr !== "") {
348
- expires = new Date(parseInt(expiresStr, 10) * 1000);
349
- }
350
- return {
351
- domain,
352
- path,
353
- secure: secureStr.toUpperCase() === "TRUE",
354
- expires,
355
- name,
356
- value,
357
- httpOnly: false,
358
- sameSite: undefined
359
- };
360
- });
361
- };
362
- const cookieToSetCookieString = (cookie) => {
363
- let setCookie = `${cookie.name}=${cookie.value}`;
364
- if (cookie.domain) {
365
- setCookie += `; Domain=${cookie.domain}`;
366
- }
367
- if (cookie.path) {
368
- setCookie += `; Path=${cookie.path}`;
369
- }
370
- if (cookie.expires) {
371
- setCookie += `; Expires=${cookie.expires.toUTCString()}`;
372
- }
373
- if (cookie.secure) {
374
- setCookie += "; Secure";
375
- }
376
- if (cookie.httpOnly) {
377
- setCookie += "; HttpOnly";
378
- }
379
- if (cookie.sameSite) {
380
- setCookie += `; SameSite=${cookie.sameSite}`;
381
- }
382
- return setCookie;
383
- };
384
- try {
385
- const cookies = parseNetscapeCookies(netscapeCookieText);
386
- return cookies.map(cookieToSetCookieString);
387
- } catch (error) {
388
- return [];
389
- }
390
- }
391
- }