@fedify/fedify 2.2.19 → 2.2.21

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 (109) hide show
  1. package/dist/attachment-arrays-CalAATqD.mjs +16 -0
  2. package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
  3. package/dist/callback-0KrwzutD.d.mts +2607 -0
  4. package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
  5. package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
  6. package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
  15. package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
  16. package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
  17. package/dist/docloader-Bogpjg4d.mjs +125 -0
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/collection.test.mjs +1 -1
  22. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  23. package/dist/federation/delivery-attachments.test.mjs +288 -0
  24. package/dist/federation/handler.test.mjs +208 -16
  25. package/dist/federation/idempotency.test.mjs +2 -2
  26. package/dist/federation/inbox.test.mjs +2 -2
  27. package/dist/federation/middleware.test.mjs +1567 -30
  28. package/dist/federation/mod.cjs +1 -1
  29. package/dist/federation/mod.d.cts +2 -2
  30. package/dist/federation/mod.d.ts +2 -2
  31. package/dist/federation/mod.js +1 -1
  32. package/dist/federation/negotiation.test.mjs +1 -1
  33. package/dist/federation/retry.test.mjs +1 -1
  34. package/dist/federation/send.test.mjs +723 -68
  35. package/dist/federation/temporal.test.mjs +25 -1
  36. package/dist/federation/webfinger.test.mjs +1 -1
  37. package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
  38. package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
  39. package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
  40. package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
  41. package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
  42. package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
  43. package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
  44. package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
  45. package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
  46. package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
  47. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  48. package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
  49. package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
  50. package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
  51. package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
  52. package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
  53. package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
  54. package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
  55. package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
  56. package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
  57. package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
  58. package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
  59. package/dist/mod.cjs +5 -5
  60. package/dist/mod.d.cts +8 -8
  61. package/dist/mod.d.ts +8 -8
  62. package/dist/mod.js +5 -5
  63. package/dist/nodeinfo/client.test.mjs +764 -18
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/nodeinfo/mod.cjs +1 -1
  66. package/dist/nodeinfo/mod.d.cts +1 -1
  67. package/dist/nodeinfo/mod.d.ts +1 -1
  68. package/dist/nodeinfo/mod.js +1 -1
  69. package/dist/nodeinfo/types.test.mjs +1 -1
  70. package/dist/otel/exporter.test.mjs +292 -30
  71. package/dist/otel/mod.cjs +36 -30
  72. package/dist/otel/mod.d.cts +13 -0
  73. package/dist/otel/mod.d.ts +13 -0
  74. package/dist/otel/mod.js +36 -30
  75. package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
  76. package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
  77. package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
  78. package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
  79. package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
  80. package/dist/send-CAdpwbFX.mjs +416 -0
  81. package/dist/sig/http.test.mjs +528 -2
  82. package/dist/sig/key-types.test.d.mts +218 -0
  83. package/dist/sig/key-types.test.mjs +8 -0
  84. package/dist/sig/key.test.mjs +2 -2
  85. package/dist/sig/ld.test.mjs +573 -8
  86. package/dist/sig/mod.cjs +2 -2
  87. package/dist/sig/mod.d.cts +3 -3
  88. package/dist/sig/mod.d.ts +3 -3
  89. package/dist/sig/mod.js +2 -2
  90. package/dist/sig/owner.test.mjs +1 -1
  91. package/dist/sig/proof.test.mjs +96 -4
  92. package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
  93. package/dist/testing/mod.d.mts +1 -2396
  94. package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
  95. package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
  96. package/dist/utils/docloader.test.mjs +318 -34
  97. package/dist/utils/mod.cjs +1 -1
  98. package/dist/utils/mod.d.cts +1 -1
  99. package/dist/utils/mod.d.ts +1 -1
  100. package/dist/utils/mod.js +1 -1
  101. package/package.json +6 -6
  102. package/dist/docloader-D1ghurDJ.mjs +0 -83
  103. package/dist/send-D35Va72B.mjs +0 -260
  104. /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  105. /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
  106. /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
  107. /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
  108. /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
  109. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -3,6 +3,7 @@ const { URLPattern } = require("urlpattern-polyfill");
3
3
  require("./chunk-DDcVe30Y.cjs");
4
4
  let _logtape_logtape = require("@logtape/logtape");
5
5
  let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
6
+ let _fedify_vocab_runtime_internal = require("@fedify/vocab-runtime/internal");
6
7
  //#region src/utils/body.ts
7
8
  /** Decoded JSON body limit: 16 MiB. @internal */
8
9
  const MAX_BODY_SIZE = 16 * 1024 * 1024;
@@ -24,13 +25,18 @@ function validateBodySizeLimit(maxBytes) {
24
25
  * @param message The response or request to read.
25
26
  * @param maxBytes The maximum number of decoded bytes to read.
26
27
  * @param url The URL to include in errors and logs.
28
+ * @param signal An optional signal for cancelling the body read.
27
29
  * @returns The decoded body text.
28
30
  * @throws {BodyTooLargeError} If the body exceeds the limit.
29
31
  * @internal
30
32
  */
31
- async function readBoundedText(message, maxBytes, url) {
33
+ async function readBoundedText(message, maxBytes, url, signal) {
32
34
  validateBodySizeLimit(maxBytes);
33
35
  const reader = message.body?.getReader();
36
+ const onAbort = () => {
37
+ if (reader != null) reader.cancel(signal?.reason).catch(() => {});
38
+ };
39
+ signal?.addEventListener("abort", onAbort, { once: true });
34
40
  const tooLarge = () => {
35
41
  (0, _logtape_logtape.getLogger)([
36
42
  "fedify",
@@ -43,6 +49,7 @@ async function readBoundedText(message, maxBytes, url) {
43
49
  throw new BodyTooLargeError(url, maxBytes);
44
50
  };
45
51
  try {
52
+ signal?.throwIfAborted();
46
53
  const length = message.headers.get("Content-Length");
47
54
  const encoding = message.headers.get("Content-Encoding");
48
55
  if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
@@ -50,6 +57,7 @@ async function readBoundedText(message, maxBytes, url) {
50
57
  let size = 0;
51
58
  const textReader = new ReadableStream({ async pull(controller) {
52
59
  const { done, value } = await reader.read();
60
+ signal?.throwIfAborted();
53
61
  if (done) {
54
62
  controller.close();
55
63
  return;
@@ -62,6 +70,7 @@ async function readBoundedText(message, maxBytes, url) {
62
70
  const chunks = [];
63
71
  while (true) {
64
72
  const { done, value } = await textReader.read();
73
+ signal?.throwIfAborted();
65
74
  if (done) break;
66
75
  chunks.push(value);
67
76
  }
@@ -73,6 +82,7 @@ async function readBoundedText(message, maxBytes, url) {
73
82
  if (reader != null) reader.cancel(error).catch(() => {});
74
83
  throw error;
75
84
  } finally {
85
+ signal?.removeEventListener("abort", onAbort);
76
86
  reader?.releaseLock();
77
87
  }
78
88
  }
@@ -84,25 +94,45 @@ const logger = (0, _logtape_logtape.getLogger)([
84
94
  "client"
85
95
  ]);
86
96
  const DEFAULT_MAX_REDIRECTION = 5;
97
+ const DEFAULT_TIMEOUT = 1e4;
98
+ const MAX_TIMEOUT = 2147483647;
87
99
  /**
88
- * Fetches a URL while guarding against SSRF. Before every request—including
89
- * each redirect hop—the destination is validated with
90
- * {@link validatePublicUrl}, so that loopback, link-local, and private
91
- * addresses, as well as non-HTTP(S) schemes such as `data:`, are rejected.
92
- * Redirects are followed manually with a cap, so that a public URL cannot
93
- * bounce the request to an internal address.
100
+ * Fetches a URL while guarding against SSRF. Every request—including each
101
+ * redirect hop—is made in its own session opened with `openPublicFetch()`,
102
+ * which rejects loopback, link-local, and private addresses, as well as
103
+ * non-HTTP(S) schemes such as `data:`, and connects only to the validated
104
+ * addresses where the runtime supports it. Redirects are followed manually
105
+ * with a cap, so that a public URL cannot bounce the request to an internal
106
+ * address.
107
+ *
108
+ * The final response is passed to `consume`, which must consume or cancel its
109
+ * body; the session is closed after `consume` settles. The cancellation of
110
+ * redirect response bodies is started before their sessions are closed.
94
111
  * @param url The URL to fetch.
95
112
  * @param headers The request headers.
96
- * @returns The final response, or `null` if the URL is disallowed, its
97
- * hostname cannot be resolved, or there are too many redirects.
113
+ * @param consume The function to consume the final response with.
114
+ * @param deps The dependencies.
115
+ * @param signal The signal for the whole NodeInfo lookup.
116
+ * @returns The value returned by `consume`, or `null` if the URL is
117
+ * disallowed, its hostname cannot be resolved, or there are too many
118
+ * redirects.
119
+ * @internal
98
120
  */
99
- async function fetchPublicUrl(url, headers) {
121
+ async function fetchPublicUrl(url, headers, consume, deps = {}, signal) {
122
+ const openHop = deps.openHop ?? ((hopUrl, signal) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(hopUrl, (0, _fedify_vocab_runtime_internal.detectRuntime)() === "node" ? {
123
+ signal,
124
+ lookup: (hostname) => (0, _fedify_vocab_runtime_internal.lookupAllAddressesBounded)(hostname, signal)
125
+ } : { signal }));
100
126
  let current = url instanceof URL ? url : new URL(url);
101
127
  let redirected = 0;
128
+ const visited = new Set([redirectKey(current)]);
102
129
  while (true) {
130
+ signal?.throwIfAborted();
131
+ let session;
103
132
  try {
104
- await (0, _fedify_vocab_runtime.validatePublicUrl)(current.href);
133
+ session = await openHop(current.href, signal);
105
134
  } catch (e) {
135
+ signal?.throwIfAborted();
106
136
  if (e instanceof _fedify_vocab_runtime.UrlError) {
107
137
  if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
108
138
  url: current.href,
@@ -116,52 +146,146 @@ async function fetchPublicUrl(url, headers) {
116
146
  }
117
147
  throw e;
118
148
  }
119
- const response = await fetch(current, {
120
- headers,
121
- redirect: "manual"
122
- });
123
- if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
124
- redirected++;
125
- if (redirected >= DEFAULT_MAX_REDIRECTION) {
126
- logger.error("Too many redirections ({redirections}) while fetching {url}.", {
127
- redirections: redirected,
128
- url: current.href
129
- });
130
- return null;
131
- }
132
- const next = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? current : response.url);
133
- if (next.protocol !== current.protocol) {
134
- logger.error("Refused a redirect to a different protocol ({protocol} to {redirectedProtocol}) while fetching NodeInfo.", {
135
- protocol: current.protocol,
136
- redirectedProtocol: next.protocol
137
- });
138
- return null;
149
+ let location;
150
+ try {
151
+ signal?.throwIfAborted();
152
+ const response = await session.fetch(current, {
153
+ headers,
154
+ redirect: "manual",
155
+ signal
156
+ });
157
+ if (signal?.aborted) {
158
+ cancelBody(response, current);
159
+ signal.throwIfAborted();
139
160
  }
140
- current = next;
141
- continue;
161
+ if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
162
+ location = response.headers.get("Location");
163
+ cancelBody(response, current);
164
+ } finally {
165
+ await session.close();
166
+ }
167
+ redirected++;
168
+ if (redirected >= DEFAULT_MAX_REDIRECTION) {
169
+ logger.error("Too many redirections ({redirections}) while fetching {url}.", {
170
+ redirections: redirected,
171
+ url: current.href
172
+ });
173
+ return null;
142
174
  }
143
- return response;
175
+ const next = new URL(location, current);
176
+ if (next.protocol !== current.protocol) {
177
+ logger.error("Refused a redirect to a different protocol ({protocol} to {redirectedProtocol}) while fetching NodeInfo.", {
178
+ protocol: current.protocol,
179
+ redirectedProtocol: next.protocol
180
+ });
181
+ return null;
182
+ }
183
+ const key = redirectKey(next);
184
+ if (visited.has(key)) {
185
+ logger.error("Redirect cycle while fetching NodeInfo: {url}.", { url: next.href });
186
+ return null;
187
+ }
188
+ visited.add(key);
189
+ current = next;
144
190
  }
145
191
  }
192
+ function redirectKey(url) {
193
+ const withoutFragment = new URL(url);
194
+ withoutFragment.hash = "";
195
+ return withoutFragment.href;
196
+ }
197
+ /**
198
+ * Starts cancelling a response body that is not read, without waiting for it
199
+ * to settle. The cancellation of a branch of a tee (e.g., a body cloned by
200
+ * a fetch mock) settles only after the other branch is cancelled too, per
201
+ * the Streams standard, so awaiting it could block forever. A failure is
202
+ * only logged.
203
+ */
204
+ function cancelBody(response, url) {
205
+ response.body?.cancel().catch((error) => {
206
+ logger.debug("Failed to cancel the response body from {url}: {error}", {
207
+ url: url.toString(),
208
+ error
209
+ });
210
+ });
211
+ }
146
212
  async function getNodeInfo(url, options = {}) {
213
+ return await getNodeInfoInternal(url, options);
214
+ }
215
+ /**
216
+ * The implementation of {@link getNodeInfo}, which is not exported from any
217
+ * entry point.
218
+ * @param url The base URL of the server, or the URL of the NodeInfo document
219
+ * if `options.direct` is turned on.
220
+ * @param options Options for fetching the NodeInfo document.
221
+ * @param deps The dependencies.
222
+ * @returns The NodeInfo document if it could be fetched successfully.
223
+ * Otherwise, `undefined` is returned.
224
+ * @internal
225
+ */
226
+ async function getNodeInfoInternal(url, options = {}, deps = {}) {
227
+ const timeout = resolveTimeout(options.timeout);
228
+ if (timeout == null && options.signal == null) return await getNodeInfoWithSignal(url, options, deps);
229
+ const controller = new AbortController();
230
+ const timeoutReason = timeout == null ? void 0 : new DOMException(`The NodeInfo lookup timed out after ${timeout} ms.`, "TimeoutError");
231
+ const timer = timeout == null ? void 0 : setTimeout(() => controller.abort(timeoutReason), timeout);
232
+ const onCallerAbort = () => controller.abort(options.signal?.reason);
233
+ options.signal?.addEventListener("abort", onCallerAbort, { once: true });
234
+ if (options.signal?.aborted) onCallerAbort();
235
+ let onAbort;
236
+ const aborted = new Promise((_, reject) => {
237
+ onAbort = () => reject(controller.signal.reason);
238
+ controller.signal.addEventListener("abort", onAbort, { once: true });
239
+ });
240
+ const loading = getNodeInfoWithSignal(url, options, deps, controller.signal);
241
+ loading.catch(() => {});
147
242
  try {
243
+ return await Promise.race([loading, aborted]);
244
+ } catch (error) {
245
+ if (!controller.signal.aborted) throw error;
246
+ if (controller.signal.reason === timeoutReason) logger.error("Timed out after {timeout} ms while fetching NodeInfo: {url}", {
247
+ timeout,
248
+ url: url.toString()
249
+ });
250
+ else logger.debug("Cancelled NodeInfo lookup for {url}.", { url: url.toString() });
251
+ return;
252
+ } finally {
253
+ clearTimeout(timer);
254
+ options.signal?.removeEventListener("abort", onCallerAbort);
255
+ if (onAbort != null) controller.signal.removeEventListener("abort", onAbort);
256
+ }
257
+ }
258
+ function resolveTimeout(timeout) {
259
+ if (timeout === void 0) return DEFAULT_TIMEOUT;
260
+ if (timeout === null) return null;
261
+ if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError(`The NodeInfo timeout must be a positive finite number of milliseconds, but got ${String(timeout)}.`);
262
+ const ms = Math.ceil(timeout);
263
+ if (ms > MAX_TIMEOUT) throw new RangeError(`The NodeInfo timeout must not be greater than ${MAX_TIMEOUT} milliseconds, but got ${timeout}.`);
264
+ return ms;
265
+ }
266
+ async function getNodeInfoWithSignal(url, options, deps, signal) {
267
+ try {
268
+ const headers = {
269
+ Accept: "application/json",
270
+ "User-Agent": typeof options.userAgent === "string" ? options.userAgent : (0, _fedify_vocab_runtime.getUserAgent)(options.userAgent)
271
+ };
148
272
  let nodeInfoUrl = url;
149
273
  if (!options.direct) {
150
274
  const wellKnownUrl = new URL("/.well-known/nodeinfo", url);
151
- const wellKnownResponse = await fetchPublicUrl(wellKnownUrl, {
152
- Accept: "application/json",
153
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : (0, _fedify_vocab_runtime.getUserAgent)(options.userAgent)
154
- });
155
- if (wellKnownResponse == null) return void 0;
156
- if (!wellKnownResponse.ok) {
157
- logger.error("Failed to fetch {url}: {status} {statusText}", {
158
- url: wellKnownUrl.href,
159
- status: wellKnownResponse.status,
160
- statusText: wellKnownResponse.statusText
161
- });
162
- return;
163
- }
164
- const wellKnownRd = JSON.parse(await readBoundedText(wellKnownResponse, MAX_BODY_SIZE, wellKnownUrl));
275
+ const wellKnown = await fetchPublicUrl(wellKnownUrl, headers, async (response) => {
276
+ if (!response.ok) {
277
+ logger.error("Failed to fetch {url}: {status} {statusText}", {
278
+ url: wellKnownUrl.href,
279
+ status: response.status,
280
+ statusText: response.statusText
281
+ });
282
+ cancelBody(response, wellKnownUrl);
283
+ return;
284
+ }
285
+ return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
286
+ }, deps, signal);
287
+ if (wellKnown == null) return void 0;
288
+ const wellKnownRd = wellKnown.rd;
165
289
  const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
166
290
  if (link == null || link.href == null) {
167
291
  logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
@@ -172,24 +296,24 @@ async function getNodeInfo(url, options = {}) {
172
296
  }
173
297
  nodeInfoUrl = link.href;
174
298
  }
175
- const response = await fetchPublicUrl(nodeInfoUrl, {
176
- Accept: "application/json",
177
- "User-Agent": typeof options.userAgent === "string" ? options.userAgent : (0, _fedify_vocab_runtime.getUserAgent)(options.userAgent)
178
- });
179
- if (response == null) return void 0;
180
- if (!response.ok) {
181
- logger.error("Failed to fetch NodeInfo document from {url}: {status} {statusText}", {
182
- url: nodeInfoUrl.toString(),
183
- status: response.status,
184
- statusText: response.statusText
185
- });
186
- return;
187
- }
188
- const data = JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl));
299
+ const document = await fetchPublicUrl(nodeInfoUrl, headers, async (response) => {
300
+ if (!response.ok) {
301
+ logger.error("Failed to fetch NodeInfo document from {url}: {status} {statusText}", {
302
+ url: nodeInfoUrl.toString(),
303
+ status: response.status,
304
+ statusText: response.statusText
305
+ });
306
+ cancelBody(response, nodeInfoUrl);
307
+ return;
308
+ }
309
+ return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
310
+ }, deps, signal);
311
+ if (document == null) return void 0;
312
+ const { data } = document;
189
313
  if (options.parse === "none") return data;
190
314
  return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
191
315
  } catch (error) {
192
- logger.error("Failed to fetch NodeInfo document from {url}: {error}", {
316
+ logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
193
317
  url: url.toString(),
194
318
  error
195
319
  });