@fedify/fedify 2.5.0-dev.2844 → 2.5.0-dev.2860

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 (53) hide show
  1. package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
  2. package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
  3. package/dist/compat/mod.cjs +1 -1
  4. package/dist/compat/mod.d.cts +1 -1
  5. package/dist/compat/mod.d.ts +1 -1
  6. package/dist/compat/mod.js +1 -1
  7. package/dist/{context-ZtE85CT_.d.cts → context-BhEcRbHo.d.cts} +32 -15
  8. package/dist/{context-CgIOZfHW.d.ts → context-C96-nSuT.d.ts} +32 -15
  9. package/dist/federation/mod.cjs +1 -1
  10. package/dist/federation/mod.d.cts +3 -3
  11. package/dist/federation/mod.d.ts +3 -3
  12. package/dist/federation/mod.js +1 -1
  13. package/dist/{federation-BQI281O9.cjs → federation-Auvn2nQS.cjs} +525 -196
  14. package/dist/{http-wTHjiJ6Q.js → http-BN8Zo-nG.js} +2639 -2464
  15. package/dist/{http-C0rce83B.cjs → http-DcmM0AwN.cjs} +2643 -2456
  16. package/dist/{key-BZw-YiK5.d.ts → key-2YNB5dUS.d.cts} +5 -5
  17. package/dist/{key-D5fbQkKM.d.cts → key-BV9DK4qb.d.ts} +5 -5
  18. package/dist/{kv-cache-DflBc0cC.cjs → kv-cache-DRJgdRR0.cjs} +1 -1
  19. package/dist/{kv-cache-O6fntSzA.js → kv-cache-Dz6xiM-c.js} +1 -1
  20. package/dist/{ld-DlC78ioJ.d.ts → ld-BKOmKbuX.d.cts} +28 -6
  21. package/dist/{ld-DEi9ERHf.d.cts → ld-BewN9CW6.d.ts} +28 -6
  22. package/dist/{middleware-B8hzxJNs.js → middleware-kGZB_Ab7.js} +457 -129
  23. package/dist/{mod-rDDnkuR8.d.cts → mod-B9UuZYxK.d.cts} +3 -3
  24. package/dist/{mod-BD6xjFNY.d.ts → mod-BMHC9eZs.d.ts} +1 -1
  25. package/dist/{mod-Bl1EEZMj.d.cts → mod-CUXI3ede.d.cts} +1 -1
  26. package/dist/{mod-SgCN1wPF.d.ts → mod-DHjHSPnw.d.ts} +3 -3
  27. package/dist/{mod-BamwZjJx.d.cts → mod-iIOirIJV.d.ts} +3 -3
  28. package/dist/{mod-BJRtsw7l.d.ts → mod-oIp2uo8F.d.cts} +3 -3
  29. package/dist/mod.cjs +6 -6
  30. package/dist/mod.d.cts +9 -9
  31. package/dist/mod.d.ts +9 -9
  32. package/dist/mod.js +6 -6
  33. package/dist/nodeinfo/mod.cjs +1 -1
  34. package/dist/nodeinfo/mod.d.cts +1 -1
  35. package/dist/nodeinfo/mod.d.ts +1 -1
  36. package/dist/nodeinfo/mod.js +1 -1
  37. package/dist/{portable-collection-DbqytYWl.js → portable-collection-BKIPytM_.js} +3 -2
  38. package/dist/{portable-collection-zcu-7ozm.cjs → portable-collection-C5sRy1VN.cjs} +3 -2
  39. package/dist/portable-verifier-CPA86vIP.js +22 -0
  40. package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
  41. package/dist/sig/mod.cjs +2 -2
  42. package/dist/sig/mod.d.cts +4 -4
  43. package/dist/sig/mod.d.ts +4 -4
  44. package/dist/sig/mod.js +2 -2
  45. package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
  46. package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
  47. package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
  48. package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
  49. package/dist/utils/mod.cjs +1 -1
  50. package/dist/utils/mod.d.cts +1 -1
  51. package/dist/utils/mod.d.ts +1 -1
  52. package/dist/utils/mod.js +1 -1
  53. package/package.json +6 -6
@@ -2,7 +2,7 @@ import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  import { getLogger } from "@logtape/logtape";
4
4
  import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
5
- import { openPublicFetch } from "@fedify/vocab-runtime/internal";
5
+ import { detectRuntime, lookupAllAddressesBounded, openPublicFetch } from "@fedify/vocab-runtime/internal";
6
6
  //#region src/utils/body.ts
7
7
  /** Decoded JSON body limit: 16 MiB. @internal */
8
8
  const MAX_BODY_SIZE = 16 * 1024 * 1024;
@@ -24,13 +24,18 @@ function validateBodySizeLimit(maxBytes) {
24
24
  * @param message The response or request to read.
25
25
  * @param maxBytes The maximum number of decoded bytes to read.
26
26
  * @param url The URL to include in errors and logs.
27
+ * @param signal An optional signal for cancelling the body read.
27
28
  * @returns The decoded body text.
28
29
  * @throws {BodyTooLargeError} If the body exceeds the limit.
29
30
  * @internal
30
31
  */
31
- async function readBoundedText(message, maxBytes, url) {
32
+ async function readBoundedText(message, maxBytes, url, signal) {
32
33
  validateBodySizeLimit(maxBytes);
33
34
  const reader = message.body?.getReader();
35
+ const onAbort = () => {
36
+ if (reader != null) reader.cancel(signal?.reason).catch(() => {});
37
+ };
38
+ signal?.addEventListener("abort", onAbort, { once: true });
34
39
  const tooLarge = () => {
35
40
  getLogger([
36
41
  "fedify",
@@ -43,6 +48,7 @@ async function readBoundedText(message, maxBytes, url) {
43
48
  throw new BodyTooLargeError(url, maxBytes);
44
49
  };
45
50
  try {
51
+ signal?.throwIfAborted();
46
52
  const length = message.headers.get("Content-Length");
47
53
  const encoding = message.headers.get("Content-Encoding");
48
54
  if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
@@ -50,6 +56,7 @@ async function readBoundedText(message, maxBytes, url) {
50
56
  let size = 0;
51
57
  const textReader = new ReadableStream({ async pull(controller) {
52
58
  const { done, value } = await reader.read();
59
+ signal?.throwIfAborted();
53
60
  if (done) {
54
61
  controller.close();
55
62
  return;
@@ -62,6 +69,7 @@ async function readBoundedText(message, maxBytes, url) {
62
69
  const chunks = [];
63
70
  while (true) {
64
71
  const { done, value } = await textReader.read();
72
+ signal?.throwIfAborted();
65
73
  if (done) break;
66
74
  chunks.push(value);
67
75
  }
@@ -73,6 +81,7 @@ async function readBoundedText(message, maxBytes, url) {
73
81
  if (reader != null) reader.cancel(error).catch(() => {});
74
82
  throw error;
75
83
  } finally {
84
+ signal?.removeEventListener("abort", onAbort);
76
85
  reader?.releaseLock();
77
86
  }
78
87
  }
@@ -84,6 +93,8 @@ const logger = getLogger([
84
93
  "client"
85
94
  ]);
86
95
  const DEFAULT_MAX_REDIRECTION = 5;
96
+ const DEFAULT_TIMEOUT = 1e4;
97
+ const MAX_TIMEOUT = 2147483647;
87
98
  /**
88
99
  * Fetches a URL while guarding against SSRF. Every request—including each
89
100
  * redirect hop—is made in its own session opened with `openPublicFetch()`,
@@ -100,20 +111,27 @@ const DEFAULT_MAX_REDIRECTION = 5;
100
111
  * @param headers The request headers.
101
112
  * @param consume The function to consume the final response with.
102
113
  * @param deps The dependencies.
114
+ * @param signal The signal for the whole NodeInfo lookup.
103
115
  * @returns The value returned by `consume`, or `null` if the URL is
104
116
  * disallowed, its hostname cannot be resolved, or there are too many
105
117
  * redirects.
106
118
  * @internal
107
119
  */
108
- async function fetchPublicUrl(url, headers, consume, deps = {}) {
109
- const openHop = deps.openHop ?? ((hopUrl) => openPublicFetch(hopUrl));
120
+ async function fetchPublicUrl(url, headers, consume, deps = {}, signal) {
121
+ const openHop = deps.openHop ?? ((hopUrl, signal) => openPublicFetch(hopUrl, detectRuntime() === "node" ? {
122
+ signal,
123
+ lookup: (hostname) => lookupAllAddressesBounded(hostname, signal)
124
+ } : { signal }));
110
125
  let current = url instanceof URL ? url : new URL(url);
111
126
  let redirected = 0;
127
+ const visited = /* @__PURE__ */ new Set([redirectKey(current)]);
112
128
  while (true) {
129
+ signal?.throwIfAborted();
113
130
  let session;
114
131
  try {
115
- session = await openHop(current.href);
132
+ session = await openHop(current.href, signal);
116
133
  } catch (e) {
134
+ signal?.throwIfAborted();
117
135
  if (e instanceof UrlError) {
118
136
  if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
119
137
  url: current.href,
@@ -129,10 +147,16 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
129
147
  }
130
148
  let location;
131
149
  try {
150
+ signal?.throwIfAborted();
132
151
  const response = await session.fetch(current, {
133
152
  headers,
134
- redirect: "manual"
153
+ redirect: "manual",
154
+ signal
135
155
  });
156
+ if (signal?.aborted) {
157
+ cancelBody(response, current);
158
+ signal.throwIfAborted();
159
+ }
136
160
  if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
137
161
  location = response.headers.get("Location");
138
162
  cancelBody(response, current);
@@ -155,9 +179,20 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
155
179
  });
156
180
  return null;
157
181
  }
182
+ const key = redirectKey(next);
183
+ if (visited.has(key)) {
184
+ logger.error("Redirect cycle while fetching NodeInfo: {url}.", { url: next.href });
185
+ return null;
186
+ }
187
+ visited.add(key);
158
188
  current = next;
159
189
  }
160
190
  }
191
+ function redirectKey(url) {
192
+ const withoutFragment = new URL(url);
193
+ withoutFragment.hash = "";
194
+ return withoutFragment.href;
195
+ }
161
196
  /**
162
197
  * Starts cancelling a response body that is not read, without waiting for it
163
198
  * to settle. The cancellation of a branch of a tee (e.g., a body cloned by
@@ -188,6 +223,46 @@ async function getNodeInfo(url, options = {}) {
188
223
  * @internal
189
224
  */
190
225
  async function getNodeInfoInternal(url, options = {}, deps = {}) {
226
+ const timeout = resolveTimeout(options.timeout);
227
+ if (timeout == null && options.signal == null) return await getNodeInfoWithSignal(url, options, deps);
228
+ const controller = new AbortController();
229
+ const timeoutReason = timeout == null ? void 0 : new DOMException(`The NodeInfo lookup timed out after ${timeout} ms.`, "TimeoutError");
230
+ const timer = timeout == null ? void 0 : setTimeout(() => controller.abort(timeoutReason), timeout);
231
+ const onCallerAbort = () => controller.abort(options.signal?.reason);
232
+ options.signal?.addEventListener("abort", onCallerAbort, { once: true });
233
+ if (options.signal?.aborted) onCallerAbort();
234
+ let onAbort;
235
+ const aborted = new Promise((_, reject) => {
236
+ onAbort = () => reject(controller.signal.reason);
237
+ controller.signal.addEventListener("abort", onAbort, { once: true });
238
+ });
239
+ const loading = getNodeInfoWithSignal(url, options, deps, controller.signal);
240
+ loading.catch(() => {});
241
+ try {
242
+ return await Promise.race([loading, aborted]);
243
+ } catch (error) {
244
+ if (!controller.signal.aborted) throw error;
245
+ if (controller.signal.reason === timeoutReason) logger.error("Timed out after {timeout} ms while fetching NodeInfo: {url}", {
246
+ timeout,
247
+ url: url.toString()
248
+ });
249
+ else logger.debug("Cancelled NodeInfo lookup for {url}.", { url: url.toString() });
250
+ return;
251
+ } finally {
252
+ clearTimeout(timer);
253
+ options.signal?.removeEventListener("abort", onCallerAbort);
254
+ if (onAbort != null) controller.signal.removeEventListener("abort", onAbort);
255
+ }
256
+ }
257
+ function resolveTimeout(timeout) {
258
+ if (timeout === void 0) return DEFAULT_TIMEOUT;
259
+ if (timeout === null) return null;
260
+ if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError(`The NodeInfo timeout must be a positive finite number of milliseconds, but got ${String(timeout)}.`);
261
+ const ms = Math.ceil(timeout);
262
+ if (ms > MAX_TIMEOUT) throw new RangeError(`The NodeInfo timeout must not be greater than ${MAX_TIMEOUT} milliseconds, but got ${timeout}.`);
263
+ return ms;
264
+ }
265
+ async function getNodeInfoWithSignal(url, options, deps, signal) {
191
266
  try {
192
267
  const headers = {
193
268
  Accept: "application/json",
@@ -206,8 +281,8 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
206
281
  cancelBody(response, wellKnownUrl);
207
282
  return;
208
283
  }
209
- return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl)) };
210
- }, deps);
284
+ return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
285
+ }, deps, signal);
211
286
  if (wellKnown == null) return void 0;
212
287
  const wellKnownRd = wellKnown.rd;
213
288
  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);
@@ -230,14 +305,14 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
230
305
  cancelBody(response, nodeInfoUrl);
231
306
  return;
232
307
  }
233
- return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl)) };
234
- }, deps);
308
+ return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
309
+ }, deps, signal);
235
310
  if (document == null) return void 0;
236
311
  const { data } = document;
237
312
  if (options.parse === "none") return data;
238
313
  return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
239
314
  } catch (error) {
240
- logger.error("Failed to fetch NodeInfo document from {url}: {error}", {
315
+ logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
241
316
  url: url.toString(),
242
317
  error
243
318
  });
@@ -23,13 +23,18 @@ function validateBodySizeLimit(maxBytes) {
23
23
  * @param message The response or request to read.
24
24
  * @param maxBytes The maximum number of decoded bytes to read.
25
25
  * @param url The URL to include in errors and logs.
26
+ * @param signal An optional signal for cancelling the body read.
26
27
  * @returns The decoded body text.
27
28
  * @throws {BodyTooLargeError} If the body exceeds the limit.
28
29
  * @internal
29
30
  */
30
- async function readBoundedText(message, maxBytes, url) {
31
+ async function readBoundedText(message, maxBytes, url, signal) {
31
32
  validateBodySizeLimit(maxBytes);
32
33
  const reader = message.body?.getReader();
34
+ const onAbort = () => {
35
+ if (reader != null) reader.cancel(signal?.reason).catch(() => {});
36
+ };
37
+ signal?.addEventListener("abort", onAbort, { once: true });
33
38
  const tooLarge = () => {
34
39
  (0, _logtape_logtape.getLogger)([
35
40
  "fedify",
@@ -42,6 +47,7 @@ async function readBoundedText(message, maxBytes, url) {
42
47
  throw new BodyTooLargeError(url, maxBytes);
43
48
  };
44
49
  try {
50
+ signal?.throwIfAborted();
45
51
  const length = message.headers.get("Content-Length");
46
52
  const encoding = message.headers.get("Content-Encoding");
47
53
  if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
@@ -49,6 +55,7 @@ async function readBoundedText(message, maxBytes, url) {
49
55
  let size = 0;
50
56
  const textReader = new ReadableStream({ async pull(controller) {
51
57
  const { done, value } = await reader.read();
58
+ signal?.throwIfAborted();
52
59
  if (done) {
53
60
  controller.close();
54
61
  return;
@@ -61,6 +68,7 @@ async function readBoundedText(message, maxBytes, url) {
61
68
  const chunks = [];
62
69
  while (true) {
63
70
  const { done, value } = await textReader.read();
71
+ signal?.throwIfAborted();
64
72
  if (done) break;
65
73
  chunks.push(value);
66
74
  }
@@ -72,6 +80,7 @@ async function readBoundedText(message, maxBytes, url) {
72
80
  if (reader != null) reader.cancel(error).catch(() => {});
73
81
  throw error;
74
82
  } finally {
83
+ signal?.removeEventListener("abort", onAbort);
75
84
  reader?.releaseLock();
76
85
  }
77
86
  }
@@ -83,6 +92,8 @@ const logger = (0, _logtape_logtape.getLogger)([
83
92
  "client"
84
93
  ]);
85
94
  const DEFAULT_MAX_REDIRECTION = 5;
95
+ const DEFAULT_TIMEOUT = 1e4;
96
+ const MAX_TIMEOUT = 2147483647;
86
97
  /**
87
98
  * Fetches a URL while guarding against SSRF. Every request—including each
88
99
  * redirect hop—is made in its own session opened with `openPublicFetch()`,
@@ -99,20 +110,27 @@ const DEFAULT_MAX_REDIRECTION = 5;
99
110
  * @param headers The request headers.
100
111
  * @param consume The function to consume the final response with.
101
112
  * @param deps The dependencies.
113
+ * @param signal The signal for the whole NodeInfo lookup.
102
114
  * @returns The value returned by `consume`, or `null` if the URL is
103
115
  * disallowed, its hostname cannot be resolved, or there are too many
104
116
  * redirects.
105
117
  * @internal
106
118
  */
107
- async function fetchPublicUrl(url, headers, consume, deps = {}) {
108
- const openHop = deps.openHop ?? ((hopUrl) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(hopUrl));
119
+ async function fetchPublicUrl(url, headers, consume, deps = {}, signal) {
120
+ const openHop = deps.openHop ?? ((hopUrl, signal) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(hopUrl, (0, _fedify_vocab_runtime_internal.detectRuntime)() === "node" ? {
121
+ signal,
122
+ lookup: (hostname) => (0, _fedify_vocab_runtime_internal.lookupAllAddressesBounded)(hostname, signal)
123
+ } : { signal }));
109
124
  let current = url instanceof URL ? url : new URL(url);
110
125
  let redirected = 0;
126
+ const visited = /* @__PURE__ */ new Set([redirectKey(current)]);
111
127
  while (true) {
128
+ signal?.throwIfAborted();
112
129
  let session;
113
130
  try {
114
- session = await openHop(current.href);
131
+ session = await openHop(current.href, signal);
115
132
  } catch (e) {
133
+ signal?.throwIfAborted();
116
134
  if (e instanceof _fedify_vocab_runtime.UrlError) {
117
135
  if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
118
136
  url: current.href,
@@ -128,10 +146,16 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
128
146
  }
129
147
  let location;
130
148
  try {
149
+ signal?.throwIfAborted();
131
150
  const response = await session.fetch(current, {
132
151
  headers,
133
- redirect: "manual"
152
+ redirect: "manual",
153
+ signal
134
154
  });
155
+ if (signal?.aborted) {
156
+ cancelBody(response, current);
157
+ signal.throwIfAborted();
158
+ }
135
159
  if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
136
160
  location = response.headers.get("Location");
137
161
  cancelBody(response, current);
@@ -154,9 +178,20 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
154
178
  });
155
179
  return null;
156
180
  }
181
+ const key = redirectKey(next);
182
+ if (visited.has(key)) {
183
+ logger.error("Redirect cycle while fetching NodeInfo: {url}.", { url: next.href });
184
+ return null;
185
+ }
186
+ visited.add(key);
157
187
  current = next;
158
188
  }
159
189
  }
190
+ function redirectKey(url) {
191
+ const withoutFragment = new URL(url);
192
+ withoutFragment.hash = "";
193
+ return withoutFragment.href;
194
+ }
160
195
  /**
161
196
  * Starts cancelling a response body that is not read, without waiting for it
162
197
  * to settle. The cancellation of a branch of a tee (e.g., a body cloned by
@@ -187,6 +222,46 @@ async function getNodeInfo(url, options = {}) {
187
222
  * @internal
188
223
  */
189
224
  async function getNodeInfoInternal(url, options = {}, deps = {}) {
225
+ const timeout = resolveTimeout(options.timeout);
226
+ if (timeout == null && options.signal == null) return await getNodeInfoWithSignal(url, options, deps);
227
+ const controller = new AbortController();
228
+ const timeoutReason = timeout == null ? void 0 : new DOMException(`The NodeInfo lookup timed out after ${timeout} ms.`, "TimeoutError");
229
+ const timer = timeout == null ? void 0 : setTimeout(() => controller.abort(timeoutReason), timeout);
230
+ const onCallerAbort = () => controller.abort(options.signal?.reason);
231
+ options.signal?.addEventListener("abort", onCallerAbort, { once: true });
232
+ if (options.signal?.aborted) onCallerAbort();
233
+ let onAbort;
234
+ const aborted = new Promise((_, reject) => {
235
+ onAbort = () => reject(controller.signal.reason);
236
+ controller.signal.addEventListener("abort", onAbort, { once: true });
237
+ });
238
+ const loading = getNodeInfoWithSignal(url, options, deps, controller.signal);
239
+ loading.catch(() => {});
240
+ try {
241
+ return await Promise.race([loading, aborted]);
242
+ } catch (error) {
243
+ if (!controller.signal.aborted) throw error;
244
+ if (controller.signal.reason === timeoutReason) logger.error("Timed out after {timeout} ms while fetching NodeInfo: {url}", {
245
+ timeout,
246
+ url: url.toString()
247
+ });
248
+ else logger.debug("Cancelled NodeInfo lookup for {url}.", { url: url.toString() });
249
+ return;
250
+ } finally {
251
+ clearTimeout(timer);
252
+ options.signal?.removeEventListener("abort", onCallerAbort);
253
+ if (onAbort != null) controller.signal.removeEventListener("abort", onAbort);
254
+ }
255
+ }
256
+ function resolveTimeout(timeout) {
257
+ if (timeout === void 0) return DEFAULT_TIMEOUT;
258
+ if (timeout === null) return null;
259
+ if (!Number.isFinite(timeout) || timeout <= 0) throw new RangeError(`The NodeInfo timeout must be a positive finite number of milliseconds, but got ${String(timeout)}.`);
260
+ const ms = Math.ceil(timeout);
261
+ if (ms > MAX_TIMEOUT) throw new RangeError(`The NodeInfo timeout must not be greater than ${MAX_TIMEOUT} milliseconds, but got ${timeout}.`);
262
+ return ms;
263
+ }
264
+ async function getNodeInfoWithSignal(url, options, deps, signal) {
190
265
  try {
191
266
  const headers = {
192
267
  Accept: "application/json",
@@ -205,8 +280,8 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
205
280
  cancelBody(response, wellKnownUrl);
206
281
  return;
207
282
  }
208
- return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl)) };
209
- }, deps);
283
+ return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
284
+ }, deps, signal);
210
285
  if (wellKnown == null) return void 0;
211
286
  const wellKnownRd = wellKnown.rd;
212
287
  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);
@@ -229,14 +304,14 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
229
304
  cancelBody(response, nodeInfoUrl);
230
305
  return;
231
306
  }
232
- return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl)) };
233
- }, deps);
307
+ return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
308
+ }, deps, signal);
234
309
  if (document == null) return void 0;
235
310
  const { data } = document;
236
311
  if (options.parse === "none") return data;
237
312
  return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
238
313
  } catch (error) {
239
- logger.error("Failed to fetch NodeInfo document from {url}: {error}", {
314
+ logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
240
315
  url: url.toString(),
241
316
  error
242
317
  });
@@ -1,5 +1,5 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_kv_cache = require("../kv-cache-DflBc0cC.cjs");
3
+ const require_kv_cache = require("../kv-cache-DRJgdRR0.cjs");
4
4
  exports.getAuthenticatedDocumentLoader = require_kv_cache.getAuthenticatedDocumentLoader;
5
5
  exports.kvCache = require_kv_cache.kvCache;
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-rDDnkuR8.cjs";
2
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-B9UuZYxK.cjs";
3
3
  export { getAuthenticatedDocumentLoader, kvCache };
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-SgCN1wPF.js";
2
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../mod-DHjHSPnw.js";
3
3
  export { getAuthenticatedDocumentLoader, kvCache };
package/dist/utils/mod.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-O6fntSzA.js";
3
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-Dz6xiM-c.js";
4
4
  export { getAuthenticatedDocumentLoader, kvCache };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "2.5.0-dev.2844+3ed9e778",
3
+ "version": "2.5.0-dev.2860+54e6d1c2",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -174,10 +174,10 @@
174
174
  "structured-field-values": "^2.0.4",
175
175
  "temporal-polyfill": "^1.0.1",
176
176
  "urlpattern-polyfill": "^10.1.0",
177
- "@fedify/uri-template": "2.5.0-dev.2844+3ed9e778",
178
- "@fedify/vocab": "2.5.0-dev.2844+3ed9e778",
179
- "@fedify/vocab-runtime": "2.5.0-dev.2844+3ed9e778",
180
- "@fedify/webfinger": "2.5.0-dev.2844+3ed9e778"
177
+ "@fedify/uri-template": "2.5.0-dev.2860+54e6d1c2",
178
+ "@fedify/vocab": "2.5.0-dev.2860+54e6d1c2",
179
+ "@fedify/webfinger": "2.5.0-dev.2860+54e6d1c2",
180
+ "@fedify/vocab-runtime": "2.5.0-dev.2860+54e6d1c2"
181
181
  },
182
182
  "devDependencies": {
183
183
  "@std/assert": "npm:@jsr/std__assert@^0.226.0",
@@ -189,7 +189,7 @@
189
189
  "typescript": "^6.0.3",
190
190
  "wrangler": "^4.17.0",
191
191
  "@fedify/fixture": "2.0.0",
192
- "@fedify/vocab-tools": "^2.5.0-dev.2844+3ed9e778"
192
+ "@fedify/vocab-tools": "^2.5.0-dev.2860+54e6d1c2"
193
193
  },
194
194
  "scripts": {
195
195
  "build:self": "tsdown",