@npy/fetch 0.1.0 → 0.1.1

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 (98) hide show
  1. package/_internal/consts.cjs +4 -0
  2. package/_internal/consts.js +4 -0
  3. package/_internal/error-adapters.cjs +146 -0
  4. package/_internal/error-adapters.js +142 -0
  5. package/_internal/guards.cjs +24 -0
  6. package/_internal/guards.js +17 -0
  7. package/_internal/net.cjs +95 -0
  8. package/_internal/net.js +92 -0
  9. package/_internal/promises.cjs +18 -0
  10. package/_internal/promises.js +18 -0
  11. package/_internal/streams.cjs +37 -0
  12. package/_internal/streams.js +36 -0
  13. package/_virtual/_rolldown/runtime.cjs +23 -0
  14. package/agent-pool.cjs +78 -0
  15. package/agent-pool.js +77 -0
  16. package/agent.cjs +257 -0
  17. package/agent.js +256 -0
  18. package/body.cjs +154 -0
  19. package/body.js +151 -0
  20. package/dialers/proxy.cjs +49 -0
  21. package/dialers/proxy.js +48 -0
  22. package/dialers/tcp.cjs +70 -0
  23. package/dialers/tcp.js +67 -0
  24. package/encoding.cjs +95 -0
  25. package/encoding.js +91 -0
  26. package/errors.cjs +275 -0
  27. package/errors.js +259 -0
  28. package/fetch.cjs +117 -0
  29. package/fetch.js +115 -0
  30. package/http-client.cjs +33 -0
  31. package/http-client.js +33 -0
  32. package/index.cjs +45 -0
  33. package/index.d.cts +1 -0
  34. package/index.d.ts +1 -0
  35. package/index.js +9 -0
  36. package/io/_utils.cjs +56 -0
  37. package/io/_utils.js +51 -0
  38. package/io/buf-writer.cjs +149 -0
  39. package/io/buf-writer.js +148 -0
  40. package/io/io.cjs +135 -0
  41. package/io/io.js +134 -0
  42. package/io/readers.cjs +377 -0
  43. package/io/readers.js +373 -0
  44. package/io/writers.cjs +191 -0
  45. package/io/writers.js +190 -0
  46. package/package.json +7 -10
  47. package/src/_internal/consts.d.cts +3 -0
  48. package/src/_internal/consts.d.ts +3 -0
  49. package/src/_internal/error-adapters.d.cts +22 -0
  50. package/src/_internal/error-adapters.d.ts +22 -0
  51. package/src/_internal/guards.d.cts +13 -0
  52. package/src/_internal/guards.d.ts +13 -0
  53. package/src/_internal/net.d.cts +12 -0
  54. package/src/_internal/net.d.ts +12 -0
  55. package/src/_internal/promises.d.cts +1 -0
  56. package/src/_internal/promises.d.ts +1 -0
  57. package/src/_internal/streams.d.cts +21 -0
  58. package/src/_internal/streams.d.ts +21 -0
  59. package/src/agent-pool.d.cts +2 -0
  60. package/src/agent-pool.d.ts +2 -0
  61. package/src/agent.d.cts +3 -0
  62. package/src/agent.d.ts +3 -0
  63. package/src/body.d.cts +23 -0
  64. package/src/body.d.ts +23 -0
  65. package/src/dialers/index.d.cts +3 -0
  66. package/src/dialers/index.d.ts +3 -0
  67. package/src/dialers/proxy.d.cts +19 -0
  68. package/src/dialers/proxy.d.ts +19 -0
  69. package/src/dialers/tcp.d.cts +36 -0
  70. package/src/dialers/tcp.d.ts +36 -0
  71. package/src/encoding.d.cts +24 -0
  72. package/src/encoding.d.ts +24 -0
  73. package/src/errors.d.cts +110 -0
  74. package/src/errors.d.ts +110 -0
  75. package/src/fetch.d.cts +36 -0
  76. package/src/fetch.d.ts +36 -0
  77. package/src/http-client.d.cts +23 -0
  78. package/src/http-client.d.ts +23 -0
  79. package/src/index.d.cts +7 -0
  80. package/src/index.d.ts +7 -0
  81. package/src/io/_utils.d.cts +10 -0
  82. package/src/io/_utils.d.ts +10 -0
  83. package/src/io/buf-writer.d.cts +13 -0
  84. package/src/io/buf-writer.d.ts +13 -0
  85. package/src/io/io.d.cts +5 -0
  86. package/src/io/io.d.ts +5 -0
  87. package/src/io/readers.d.cts +199 -0
  88. package/src/io/readers.d.ts +199 -0
  89. package/src/io/writers.d.cts +22 -0
  90. package/src/io/writers.d.ts +22 -0
  91. package/src/types/agent.d.cts +128 -0
  92. package/src/types/agent.d.ts +128 -0
  93. package/src/types/dialer.d.cts +27 -0
  94. package/src/types/dialer.d.ts +27 -0
  95. package/src/types/index.d.cts +2 -0
  96. package/src/types/index.d.ts +2 -0
  97. package/tests/test-utils.d.cts +8 -0
  98. package/tests/test-utils.d.ts +8 -0
package/encoding.js ADDED
@@ -0,0 +1,91 @@
1
+ import { nodeReadableToWeb } from "@fuman/node";
2
+ import { Readable } from "node:stream";
3
+ //#region src/encoding.ts
4
+ function applyTransforms(stream, contentEncoding, factory) {
5
+ const transforms = factory(contentEncoding);
6
+ if (transforms.length === 0) return stream;
7
+ let result;
8
+ if (stream instanceof ReadableStream) result = stream;
9
+ else result = nodeReadableToWeb(Readable.from(stream));
10
+ for (const t of transforms) result = result.pipeThrough(t);
11
+ return result;
12
+ }
13
+ function decodeStream(stream, contentEncoding) {
14
+ return applyTransforms(stream, contentEncoding, createDecoders);
15
+ }
16
+ function encodeStream(stream, contentEncoding) {
17
+ return applyTransforms(stream, contentEncoding, createEncoders);
18
+ }
19
+ /**
20
+ * Create a series of decoding streams based on the content-encoding header. The
21
+ * resulting streams should be piped together to decode the content.
22
+ *
23
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}
24
+ */
25
+ function createDecoders(contentEncoding) {
26
+ const decoders = [];
27
+ if (contentEncoding?.length) {
28
+ const encodings = Array.isArray(contentEncoding) ? contentEncoding.flatMap(commaSplit) : contentEncoding.split(",");
29
+ for (const encoding of encodings) {
30
+ const normalizedEncoding = normalizeEncoding(encoding);
31
+ if (normalizedEncoding === "identity") continue;
32
+ decoders.push(createDecoder(normalizedEncoding));
33
+ }
34
+ }
35
+ return decoders.reverse();
36
+ }
37
+ /**
38
+ * Create a series of encoding streams based on the content-encoding header (or
39
+ * transfer-coding list).
40
+ *
41
+ * The resulting streams should be piped together to apply the encoding in the
42
+ * declared order.
43
+ *
44
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}
45
+ */
46
+ function createEncoders(contentEncoding) {
47
+ const encoders = [];
48
+ if (contentEncoding?.length) {
49
+ const encodings = Array.isArray(contentEncoding) ? contentEncoding.flatMap(commaSplit) : contentEncoding.split(",");
50
+ for (const encoding of encodings) {
51
+ const normalizedEncoding = normalizeEncoding(encoding);
52
+ if (normalizedEncoding === "identity") continue;
53
+ encoders.push(createEncoder(normalizedEncoding));
54
+ }
55
+ }
56
+ return encoders;
57
+ }
58
+ function commaSplit(header) {
59
+ return header.split(",");
60
+ }
61
+ function normalizeEncoding(encoding) {
62
+ return encoding.trim().toLowerCase();
63
+ }
64
+ function createDecoder(normalizedEncoding) {
65
+ switch (normalizedEncoding) {
66
+ case "gzip":
67
+ case "x-gzip": return new DecompressionStream("gzip");
68
+ case "deflate":
69
+ case "x-deflate": return new DecompressionStream("deflate");
70
+ case "zstd":
71
+ case "x-zstd": return new DecompressionStream("zstd");
72
+ case "br": return new DecompressionStream("brotli");
73
+ case "identity": return new TransformStream();
74
+ default: throw new TypeError(`Unsupported content-encoding: "${normalizedEncoding}"`);
75
+ }
76
+ }
77
+ function createEncoder(normalizedEncoding) {
78
+ switch (normalizedEncoding) {
79
+ case "gzip":
80
+ case "x-gzip": return new CompressionStream("gzip");
81
+ case "deflate":
82
+ case "x-deflate": return new CompressionStream("deflate");
83
+ case "zstd":
84
+ case "x-zstd": return new CompressionStream("zstd");
85
+ case "br": return new CompressionStream("brotli");
86
+ case "identity": return new TransformStream();
87
+ default: throw new TypeError(`Unsupported content-encoding: "${normalizedEncoding}"`);
88
+ }
89
+ }
90
+ //#endregion
91
+ export { createDecoders, createEncoders, decodeStream, encodeStream };
package/errors.cjs ADDED
@@ -0,0 +1,275 @@
1
+ //#region src/errors.ts
2
+ var ErrorType = {
3
+ ABORTED: "ABORTED",
4
+ NETWORK: "NETWORK",
5
+ TIMEOUT: "TIMEOUT",
6
+ HTTP_CLIENT_ERROR: "HTTP_CLIENT_ERROR",
7
+ HTTP_SERVER_ERROR: "HTTP_SERVER_ERROR"
8
+ };
9
+ var FetchErrorCode = {
10
+ ABORTED: "ERR_FETCH_ABORTED",
11
+ TIMEOUT: "ERR_FETCH_TIMEOUT",
12
+ CONNECTION: "ERR_FETCH_CONNECTION",
13
+ AGENT_CLOSED: "ERR_FETCH_AGENT_CLOSED",
14
+ AGENT_BUSY: "ERR_FETCH_AGENT_BUSY",
15
+ ORIGIN_MISMATCH: "ERR_FETCH_ORIGIN_MISMATCH",
16
+ UNSUPPORTED_PROTOCOL: "ERR_FETCH_UNSUPPORTED_PROTOCOL",
17
+ UNSUPPORTED_METHOD: "ERR_FETCH_UNSUPPORTED_METHOD",
18
+ TLS_ALPN: "ERR_FETCH_TLS_ALPN",
19
+ REQUEST_WRITE: "ERR_FETCH_REQUEST_WRITE",
20
+ RESPONSE_HEADERS: "ERR_FETCH_RESPONSE_HEADERS",
21
+ RESPONSE_BODY: "ERR_FETCH_RESPONSE_BODY",
22
+ RESPONSE_DECODE: "ERR_FETCH_RESPONSE_DECODE",
23
+ HTTP_STATUS: "ERR_FETCH_HTTP_STATUS"
24
+ };
25
+ var FetchError = class extends Error {
26
+ code;
27
+ phase;
28
+ context;
29
+ retryable;
30
+ type;
31
+ cause;
32
+ constructor(options) {
33
+ super(options.message, { cause: options.cause });
34
+ this.code = options.code;
35
+ this.phase = options.phase;
36
+ this.context = options.context;
37
+ this.retryable = options.retryable ?? false;
38
+ this.type = options.type;
39
+ this.cause = options.cause;
40
+ Object.setPrototypeOf(this, new.target.prototype);
41
+ }
42
+ get name() {
43
+ return this.constructor.name;
44
+ }
45
+ get [Symbol.toStringTag]() {
46
+ return this.name;
47
+ }
48
+ toJSON() {
49
+ return {
50
+ name: this.name,
51
+ message: this.message,
52
+ code: this.code,
53
+ phase: this.phase,
54
+ retryable: this.retryable,
55
+ type: this.type,
56
+ context: this.context,
57
+ cause: this.cause instanceof Error ? {
58
+ name: this.cause.name,
59
+ message: this.cause.message
60
+ } : this.cause
61
+ };
62
+ }
63
+ };
64
+ var RequestAbortedError = class extends FetchError {
65
+ constructor(cause, context, message) {
66
+ super({
67
+ message: message ?? "The request was aborted",
68
+ code: FetchErrorCode.ABORTED,
69
+ phase: "request",
70
+ cause,
71
+ context,
72
+ retryable: false,
73
+ type: ErrorType.ABORTED
74
+ });
75
+ }
76
+ };
77
+ var ConnectTimeoutError = class extends FetchError {
78
+ constructor(cause, context, message) {
79
+ super({
80
+ message: message ?? "Connection timed out",
81
+ code: FetchErrorCode.TIMEOUT,
82
+ phase: "connect",
83
+ cause,
84
+ context,
85
+ retryable: true,
86
+ type: ErrorType.TIMEOUT
87
+ });
88
+ }
89
+ };
90
+ var ConnectionError = class extends FetchError {
91
+ constructor(cause, context, message) {
92
+ super({
93
+ message: message ?? "Network connection failed",
94
+ code: FetchErrorCode.CONNECTION,
95
+ phase: "connect",
96
+ cause,
97
+ context,
98
+ retryable: true,
99
+ type: ErrorType.NETWORK
100
+ });
101
+ }
102
+ };
103
+ var AgentClosedError = class extends FetchError {
104
+ constructor(context, cause) {
105
+ super({
106
+ message: "Agent is closed",
107
+ code: FetchErrorCode.AGENT_CLOSED,
108
+ phase: "agent",
109
+ cause,
110
+ context,
111
+ retryable: false,
112
+ type: ErrorType.NETWORK
113
+ });
114
+ }
115
+ };
116
+ var AgentBusyError = class extends FetchError {
117
+ constructor(context, cause) {
118
+ super({
119
+ message: "Agent is busy",
120
+ code: FetchErrorCode.AGENT_BUSY,
121
+ phase: "agent",
122
+ cause,
123
+ context,
124
+ retryable: true,
125
+ type: ErrorType.NETWORK
126
+ });
127
+ }
128
+ };
129
+ var OriginMismatchError = class extends FetchError {
130
+ constructor(expectedOrigin, actualOrigin, context) {
131
+ super({
132
+ message: `Agent origin mismatch: expected ${expectedOrigin}, got ${actualOrigin}`,
133
+ code: FetchErrorCode.ORIGIN_MISMATCH,
134
+ phase: "policy",
135
+ context: {
136
+ ...context,
137
+ details: {
138
+ ...context?.details ?? {},
139
+ expectedOrigin,
140
+ actualOrigin
141
+ }
142
+ },
143
+ retryable: false,
144
+ type: ErrorType.NETWORK
145
+ });
146
+ }
147
+ };
148
+ var UnsupportedProtocolError = class extends FetchError {
149
+ constructor(protocol, context) {
150
+ super({
151
+ message: `Unsupported protocol: ${protocol}`,
152
+ code: FetchErrorCode.UNSUPPORTED_PROTOCOL,
153
+ phase: "policy",
154
+ context,
155
+ retryable: false,
156
+ type: ErrorType.NETWORK
157
+ });
158
+ }
159
+ };
160
+ var UnsupportedMethodError = class extends FetchError {
161
+ constructor(method, context) {
162
+ super({
163
+ message: `Unsupported method: ${method}`,
164
+ code: FetchErrorCode.UNSUPPORTED_METHOD,
165
+ phase: "policy",
166
+ context,
167
+ retryable: false,
168
+ type: ErrorType.NETWORK
169
+ });
170
+ }
171
+ };
172
+ var UnsupportedAlpnProtocolError = class extends FetchError {
173
+ constructor(alpn, context, cause) {
174
+ super({
175
+ message: `Unsupported ALPN protocol negotiated: ${alpn}`,
176
+ code: FetchErrorCode.TLS_ALPN,
177
+ phase: "connect",
178
+ cause,
179
+ context: {
180
+ ...context,
181
+ alpn
182
+ },
183
+ retryable: false,
184
+ type: ErrorType.NETWORK
185
+ });
186
+ }
187
+ };
188
+ var RequestWriteError = class extends FetchError {
189
+ constructor(cause, context, message) {
190
+ super({
191
+ message: message ?? "Failed to write HTTP request",
192
+ code: FetchErrorCode.REQUEST_WRITE,
193
+ phase: "request",
194
+ cause,
195
+ context,
196
+ retryable: true,
197
+ type: ErrorType.NETWORK
198
+ });
199
+ }
200
+ };
201
+ var ResponseHeaderError = class extends FetchError {
202
+ constructor(cause, context, message) {
203
+ super({
204
+ message: message ?? "Failed while reading response headers",
205
+ code: FetchErrorCode.RESPONSE_HEADERS,
206
+ phase: "response",
207
+ cause,
208
+ context,
209
+ retryable: true,
210
+ type: ErrorType.NETWORK
211
+ });
212
+ }
213
+ };
214
+ var ResponseBodyError = class extends FetchError {
215
+ constructor(cause, context, message) {
216
+ super({
217
+ message: message ?? "Failed while reading response body",
218
+ code: FetchErrorCode.RESPONSE_BODY,
219
+ phase: "body",
220
+ cause,
221
+ context,
222
+ retryable: true,
223
+ type: ErrorType.NETWORK
224
+ });
225
+ }
226
+ };
227
+ var ResponseDecodeError = class extends FetchError {
228
+ constructor(cause, context, message) {
229
+ super({
230
+ message: message ?? "Failed while decoding response body",
231
+ code: FetchErrorCode.RESPONSE_DECODE,
232
+ phase: "decode",
233
+ cause,
234
+ context,
235
+ retryable: false,
236
+ type: ErrorType.NETWORK
237
+ });
238
+ }
239
+ };
240
+ var HttpStatusError = class extends FetchError {
241
+ statusCode;
242
+ constructor(statusCode, context, cause, message) {
243
+ super({
244
+ message: message ?? `HTTP ${statusCode}`,
245
+ code: FetchErrorCode.HTTP_STATUS,
246
+ phase: "response",
247
+ cause,
248
+ context: {
249
+ ...context,
250
+ status: statusCode
251
+ },
252
+ retryable: statusCode >= 500,
253
+ type: statusCode < 500 ? ErrorType.HTTP_CLIENT_ERROR : ErrorType.HTTP_SERVER_ERROR
254
+ });
255
+ this.statusCode = statusCode;
256
+ }
257
+ };
258
+ //#endregion
259
+ exports.AgentBusyError = AgentBusyError;
260
+ exports.AgentClosedError = AgentClosedError;
261
+ exports.ConnectTimeoutError = ConnectTimeoutError;
262
+ exports.ConnectionError = ConnectionError;
263
+ exports.ErrorType = ErrorType;
264
+ exports.FetchError = FetchError;
265
+ exports.FetchErrorCode = FetchErrorCode;
266
+ exports.HttpStatusError = HttpStatusError;
267
+ exports.OriginMismatchError = OriginMismatchError;
268
+ exports.RequestAbortedError = RequestAbortedError;
269
+ exports.RequestWriteError = RequestWriteError;
270
+ exports.ResponseBodyError = ResponseBodyError;
271
+ exports.ResponseDecodeError = ResponseDecodeError;
272
+ exports.ResponseHeaderError = ResponseHeaderError;
273
+ exports.UnsupportedAlpnProtocolError = UnsupportedAlpnProtocolError;
274
+ exports.UnsupportedMethodError = UnsupportedMethodError;
275
+ exports.UnsupportedProtocolError = UnsupportedProtocolError;
package/errors.js ADDED
@@ -0,0 +1,259 @@
1
+ //#region src/errors.ts
2
+ var ErrorType = {
3
+ ABORTED: "ABORTED",
4
+ NETWORK: "NETWORK",
5
+ TIMEOUT: "TIMEOUT",
6
+ HTTP_CLIENT_ERROR: "HTTP_CLIENT_ERROR",
7
+ HTTP_SERVER_ERROR: "HTTP_SERVER_ERROR"
8
+ };
9
+ var FetchErrorCode = {
10
+ ABORTED: "ERR_FETCH_ABORTED",
11
+ TIMEOUT: "ERR_FETCH_TIMEOUT",
12
+ CONNECTION: "ERR_FETCH_CONNECTION",
13
+ AGENT_CLOSED: "ERR_FETCH_AGENT_CLOSED",
14
+ AGENT_BUSY: "ERR_FETCH_AGENT_BUSY",
15
+ ORIGIN_MISMATCH: "ERR_FETCH_ORIGIN_MISMATCH",
16
+ UNSUPPORTED_PROTOCOL: "ERR_FETCH_UNSUPPORTED_PROTOCOL",
17
+ UNSUPPORTED_METHOD: "ERR_FETCH_UNSUPPORTED_METHOD",
18
+ TLS_ALPN: "ERR_FETCH_TLS_ALPN",
19
+ REQUEST_WRITE: "ERR_FETCH_REQUEST_WRITE",
20
+ RESPONSE_HEADERS: "ERR_FETCH_RESPONSE_HEADERS",
21
+ RESPONSE_BODY: "ERR_FETCH_RESPONSE_BODY",
22
+ RESPONSE_DECODE: "ERR_FETCH_RESPONSE_DECODE",
23
+ HTTP_STATUS: "ERR_FETCH_HTTP_STATUS"
24
+ };
25
+ var FetchError = class extends Error {
26
+ code;
27
+ phase;
28
+ context;
29
+ retryable;
30
+ type;
31
+ cause;
32
+ constructor(options) {
33
+ super(options.message, { cause: options.cause });
34
+ this.code = options.code;
35
+ this.phase = options.phase;
36
+ this.context = options.context;
37
+ this.retryable = options.retryable ?? false;
38
+ this.type = options.type;
39
+ this.cause = options.cause;
40
+ Object.setPrototypeOf(this, new.target.prototype);
41
+ }
42
+ get name() {
43
+ return this.constructor.name;
44
+ }
45
+ get [Symbol.toStringTag]() {
46
+ return this.name;
47
+ }
48
+ toJSON() {
49
+ return {
50
+ name: this.name,
51
+ message: this.message,
52
+ code: this.code,
53
+ phase: this.phase,
54
+ retryable: this.retryable,
55
+ type: this.type,
56
+ context: this.context,
57
+ cause: this.cause instanceof Error ? {
58
+ name: this.cause.name,
59
+ message: this.cause.message
60
+ } : this.cause
61
+ };
62
+ }
63
+ };
64
+ var RequestAbortedError = class extends FetchError {
65
+ constructor(cause, context, message) {
66
+ super({
67
+ message: message ?? "The request was aborted",
68
+ code: FetchErrorCode.ABORTED,
69
+ phase: "request",
70
+ cause,
71
+ context,
72
+ retryable: false,
73
+ type: ErrorType.ABORTED
74
+ });
75
+ }
76
+ };
77
+ var ConnectTimeoutError = class extends FetchError {
78
+ constructor(cause, context, message) {
79
+ super({
80
+ message: message ?? "Connection timed out",
81
+ code: FetchErrorCode.TIMEOUT,
82
+ phase: "connect",
83
+ cause,
84
+ context,
85
+ retryable: true,
86
+ type: ErrorType.TIMEOUT
87
+ });
88
+ }
89
+ };
90
+ var ConnectionError = class extends FetchError {
91
+ constructor(cause, context, message) {
92
+ super({
93
+ message: message ?? "Network connection failed",
94
+ code: FetchErrorCode.CONNECTION,
95
+ phase: "connect",
96
+ cause,
97
+ context,
98
+ retryable: true,
99
+ type: ErrorType.NETWORK
100
+ });
101
+ }
102
+ };
103
+ var AgentClosedError = class extends FetchError {
104
+ constructor(context, cause) {
105
+ super({
106
+ message: "Agent is closed",
107
+ code: FetchErrorCode.AGENT_CLOSED,
108
+ phase: "agent",
109
+ cause,
110
+ context,
111
+ retryable: false,
112
+ type: ErrorType.NETWORK
113
+ });
114
+ }
115
+ };
116
+ var AgentBusyError = class extends FetchError {
117
+ constructor(context, cause) {
118
+ super({
119
+ message: "Agent is busy",
120
+ code: FetchErrorCode.AGENT_BUSY,
121
+ phase: "agent",
122
+ cause,
123
+ context,
124
+ retryable: true,
125
+ type: ErrorType.NETWORK
126
+ });
127
+ }
128
+ };
129
+ var OriginMismatchError = class extends FetchError {
130
+ constructor(expectedOrigin, actualOrigin, context) {
131
+ super({
132
+ message: `Agent origin mismatch: expected ${expectedOrigin}, got ${actualOrigin}`,
133
+ code: FetchErrorCode.ORIGIN_MISMATCH,
134
+ phase: "policy",
135
+ context: {
136
+ ...context,
137
+ details: {
138
+ ...context?.details ?? {},
139
+ expectedOrigin,
140
+ actualOrigin
141
+ }
142
+ },
143
+ retryable: false,
144
+ type: ErrorType.NETWORK
145
+ });
146
+ }
147
+ };
148
+ var UnsupportedProtocolError = class extends FetchError {
149
+ constructor(protocol, context) {
150
+ super({
151
+ message: `Unsupported protocol: ${protocol}`,
152
+ code: FetchErrorCode.UNSUPPORTED_PROTOCOL,
153
+ phase: "policy",
154
+ context,
155
+ retryable: false,
156
+ type: ErrorType.NETWORK
157
+ });
158
+ }
159
+ };
160
+ var UnsupportedMethodError = class extends FetchError {
161
+ constructor(method, context) {
162
+ super({
163
+ message: `Unsupported method: ${method}`,
164
+ code: FetchErrorCode.UNSUPPORTED_METHOD,
165
+ phase: "policy",
166
+ context,
167
+ retryable: false,
168
+ type: ErrorType.NETWORK
169
+ });
170
+ }
171
+ };
172
+ var UnsupportedAlpnProtocolError = class extends FetchError {
173
+ constructor(alpn, context, cause) {
174
+ super({
175
+ message: `Unsupported ALPN protocol negotiated: ${alpn}`,
176
+ code: FetchErrorCode.TLS_ALPN,
177
+ phase: "connect",
178
+ cause,
179
+ context: {
180
+ ...context,
181
+ alpn
182
+ },
183
+ retryable: false,
184
+ type: ErrorType.NETWORK
185
+ });
186
+ }
187
+ };
188
+ var RequestWriteError = class extends FetchError {
189
+ constructor(cause, context, message) {
190
+ super({
191
+ message: message ?? "Failed to write HTTP request",
192
+ code: FetchErrorCode.REQUEST_WRITE,
193
+ phase: "request",
194
+ cause,
195
+ context,
196
+ retryable: true,
197
+ type: ErrorType.NETWORK
198
+ });
199
+ }
200
+ };
201
+ var ResponseHeaderError = class extends FetchError {
202
+ constructor(cause, context, message) {
203
+ super({
204
+ message: message ?? "Failed while reading response headers",
205
+ code: FetchErrorCode.RESPONSE_HEADERS,
206
+ phase: "response",
207
+ cause,
208
+ context,
209
+ retryable: true,
210
+ type: ErrorType.NETWORK
211
+ });
212
+ }
213
+ };
214
+ var ResponseBodyError = class extends FetchError {
215
+ constructor(cause, context, message) {
216
+ super({
217
+ message: message ?? "Failed while reading response body",
218
+ code: FetchErrorCode.RESPONSE_BODY,
219
+ phase: "body",
220
+ cause,
221
+ context,
222
+ retryable: true,
223
+ type: ErrorType.NETWORK
224
+ });
225
+ }
226
+ };
227
+ var ResponseDecodeError = class extends FetchError {
228
+ constructor(cause, context, message) {
229
+ super({
230
+ message: message ?? "Failed while decoding response body",
231
+ code: FetchErrorCode.RESPONSE_DECODE,
232
+ phase: "decode",
233
+ cause,
234
+ context,
235
+ retryable: false,
236
+ type: ErrorType.NETWORK
237
+ });
238
+ }
239
+ };
240
+ var HttpStatusError = class extends FetchError {
241
+ statusCode;
242
+ constructor(statusCode, context, cause, message) {
243
+ super({
244
+ message: message ?? `HTTP ${statusCode}`,
245
+ code: FetchErrorCode.HTTP_STATUS,
246
+ phase: "response",
247
+ cause,
248
+ context: {
249
+ ...context,
250
+ status: statusCode
251
+ },
252
+ retryable: statusCode >= 500,
253
+ type: statusCode < 500 ? ErrorType.HTTP_CLIENT_ERROR : ErrorType.HTTP_SERVER_ERROR
254
+ });
255
+ this.statusCode = statusCode;
256
+ }
257
+ };
258
+ //#endregion
259
+ export { AgentBusyError, AgentClosedError, ConnectTimeoutError, ConnectionError, ErrorType, FetchError, FetchErrorCode, HttpStatusError, OriginMismatchError, RequestAbortedError, RequestWriteError, ResponseBodyError, ResponseDecodeError, ResponseHeaderError, UnsupportedAlpnProtocolError, UnsupportedMethodError, UnsupportedProtocolError };