rezo 1.0.35 → 1.0.37

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 (43) hide show
  1. package/dist/adapters/curl.cjs +320 -9
  2. package/dist/adapters/curl.js +320 -9
  3. package/dist/adapters/entries/curl.d.ts +20 -2
  4. package/dist/adapters/entries/fetch.d.ts +20 -2
  5. package/dist/adapters/entries/http.d.ts +20 -2
  6. package/dist/adapters/entries/http2.d.ts +20 -2
  7. package/dist/adapters/entries/react-native.d.ts +20 -2
  8. package/dist/adapters/entries/xhr.d.ts +20 -2
  9. package/dist/adapters/fetch.cjs +10 -2
  10. package/dist/adapters/fetch.js +10 -2
  11. package/dist/adapters/http.cjs +204 -35
  12. package/dist/adapters/http.js +204 -35
  13. package/dist/adapters/http2.cjs +10 -2
  14. package/dist/adapters/http2.js +10 -2
  15. package/dist/adapters/index.cjs +6 -6
  16. package/dist/adapters/react-native.cjs +10 -2
  17. package/dist/adapters/react-native.js +10 -2
  18. package/dist/adapters/xhr.cjs +9 -1
  19. package/dist/adapters/xhr.js +9 -1
  20. package/dist/cache/index.cjs +13 -13
  21. package/dist/crawler.d.ts +20 -2
  22. package/dist/entries/crawler.cjs +5 -5
  23. package/dist/index.cjs +24 -24
  24. package/dist/index.d.ts +20 -2
  25. package/dist/platform/browser.d.ts +20 -2
  26. package/dist/platform/bun.d.ts +20 -2
  27. package/dist/platform/deno.d.ts +20 -2
  28. package/dist/platform/node.d.ts +20 -2
  29. package/dist/platform/react-native.d.ts +20 -2
  30. package/dist/platform/worker.d.ts +20 -2
  31. package/dist/plugin/index.cjs +36 -36
  32. package/dist/proxy/index.cjs +4 -4
  33. package/dist/queue/index.cjs +8 -8
  34. package/dist/responses/universal/index.cjs +11 -11
  35. package/dist/utils/agent-pool.cjs +204 -0
  36. package/dist/utils/agent-pool.js +201 -0
  37. package/dist/utils/http-config.cjs +24 -7
  38. package/dist/utils/http-config.js +24 -7
  39. package/dist/utils/index.cjs +2 -0
  40. package/dist/utils/index.js +2 -0
  41. package/dist/utils/staged-timeout.cjs +143 -0
  42. package/dist/utils/staged-timeout.js +139 -0
  43. package/package.json +1 -1
@@ -0,0 +1,139 @@
1
+ import { RezoError } from '../errors/rezo-error.js';
2
+
3
+ export class StagedTimeoutManager {
4
+ phases = new Map;
5
+ socket = null;
6
+ request = null;
7
+ abortController = null;
8
+ config = null;
9
+ requestConfig = null;
10
+ onTimeout = null;
11
+ constructor(timeoutConfig, config, requestConfig) {
12
+ this.config = config || null;
13
+ this.requestConfig = requestConfig || null;
14
+ if (timeoutConfig.connect) {
15
+ this.phases.set("connect", {
16
+ name: "connect",
17
+ timeout: timeoutConfig.connect,
18
+ timer: null,
19
+ startTime: 0
20
+ });
21
+ }
22
+ if (timeoutConfig.headers) {
23
+ this.phases.set("headers", {
24
+ name: "headers",
25
+ timeout: timeoutConfig.headers,
26
+ timer: null,
27
+ startTime: 0
28
+ });
29
+ }
30
+ if (timeoutConfig.body) {
31
+ this.phases.set("body", {
32
+ name: "body",
33
+ timeout: timeoutConfig.body,
34
+ timer: null,
35
+ startTime: 0
36
+ });
37
+ }
38
+ if (timeoutConfig.total) {
39
+ this.phases.set("total", {
40
+ name: "total",
41
+ timeout: timeoutConfig.total,
42
+ timer: null,
43
+ startTime: 0
44
+ });
45
+ }
46
+ }
47
+ setSocket(socket) {
48
+ this.socket = socket;
49
+ }
50
+ setRequest(request) {
51
+ this.request = request;
52
+ }
53
+ setAbortController(controller) {
54
+ this.abortController = controller;
55
+ }
56
+ setTimeoutCallback(callback) {
57
+ this.onTimeout = callback;
58
+ }
59
+ startPhase(phaseName) {
60
+ const phase = this.phases.get(phaseName);
61
+ if (!phase)
62
+ return;
63
+ this.clearPhase(phaseName);
64
+ phase.startTime = Date.now();
65
+ phase.timer = setTimeout(() => {
66
+ this.handleTimeout(phaseName);
67
+ }, phase.timeout);
68
+ }
69
+ clearPhase(phaseName) {
70
+ const phase = this.phases.get(phaseName);
71
+ if (phase?.timer) {
72
+ clearTimeout(phase.timer);
73
+ phase.timer = null;
74
+ }
75
+ }
76
+ clearAll() {
77
+ for (const phaseName of this.phases.keys()) {
78
+ this.clearPhase(phaseName);
79
+ }
80
+ }
81
+ handleTimeout(phaseName) {
82
+ const phase = this.phases.get(phaseName);
83
+ if (!phase)
84
+ return;
85
+ const elapsed = Date.now() - phase.startTime;
86
+ if (this.socket) {
87
+ try {
88
+ this.socket.destroy();
89
+ } catch {}
90
+ }
91
+ if (this.request) {
92
+ try {
93
+ this.request.destroy();
94
+ } catch {}
95
+ }
96
+ if (this.abortController) {
97
+ try {
98
+ this.abortController.abort();
99
+ } catch {}
100
+ }
101
+ if (this.onTimeout) {
102
+ this.onTimeout(phaseName, elapsed);
103
+ }
104
+ }
105
+ createTimeoutError(phaseName, elapsed) {
106
+ const phaseMessages = {
107
+ connect: `Connection timeout: Failed to establish TCP connection within ${elapsed}ms`,
108
+ headers: `Headers timeout: Server did not send response headers within ${elapsed}ms`,
109
+ body: `Body timeout: Response body transfer stalled for ${elapsed}ms`,
110
+ total: `Total timeout: Request exceeded maximum duration of ${elapsed}ms`
111
+ };
112
+ const message = phaseMessages[phaseName] || `Timeout in ${phaseName} phase after ${elapsed}ms`;
113
+ const error = new RezoError(message, this.config || {}, phaseName === "connect" ? "ETIMEDOUT" : phaseName === "headers" ? "ESOCKETTIMEDOUT" : "ECONNRESET", this.requestConfig || undefined);
114
+ error.phase = phaseName;
115
+ error.elapsed = elapsed;
116
+ error.isRetryable = phaseName === "connect" || phaseName === "headers";
117
+ return error;
118
+ }
119
+ getPhaseTimeout(phaseName) {
120
+ return this.phases.get(phaseName)?.timeout;
121
+ }
122
+ hasPhase(phaseName) {
123
+ return this.phases.has(phaseName);
124
+ }
125
+ }
126
+ export function parseStagedTimeouts(timeout) {
127
+ if (!timeout) {
128
+ return {};
129
+ }
130
+ if (typeof timeout === "number") {
131
+ return {
132
+ total: timeout,
133
+ connect: Math.min(timeout, 1e4),
134
+ headers: Math.min(timeout, 30000)
135
+ };
136
+ }
137
+ return timeout;
138
+ }
139
+ export default StagedTimeoutManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rezo",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "Lightning-fast, enterprise-grade HTTP client for modern JavaScript. Full HTTP/2 support, intelligent cookie management, multiple adapters (HTTP, Fetch, cURL, XHR), streaming, proxy support (HTTP/HTTPS/SOCKS), and cross-environment compatibility.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",