@fedify/fedify 2.1.30 → 2.1.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 (104) hide show
  1. package/dist/attachment-arrays-DZ4JHJD8.mjs +111 -0
  2. package/dist/{builder-CTpfuuVp.mjs → builder--sc-rozj.mjs} +3 -3
  3. package/dist/callback-BARPujV7.d.mts +2388 -0
  4. package/dist/{client-CAM_bQXx.d.cts → client-9DPcy_Yx.d.ts} +16 -1
  5. package/dist/{client-CSddvgWN.d.ts → client-B3ruDgWg.d.cts} +16 -1
  6. package/dist/{client-CjDMsn4a.mjs → client-cpPaW7Ww.mjs} +189 -65
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +254 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/transformers.test.mjs +1 -1
  12. package/dist/{context-DLLaDau8.d.ts → context-DE2YrQwM.d.ts} +56 -13
  13. package/dist/{context-BNwv9Q1v.d.cts → context-y6ZUQCMf.d.cts} +56 -13
  14. package/dist/{deno-BATJ1hq6.mjs → deno-L23b3Hba.mjs} +1 -1
  15. package/dist/docloader-DUXr9k_O.mjs +124 -0
  16. package/dist/federation/attachment-responses.test.d.mts +2 -0
  17. package/dist/federation/attachment-responses.test.mjs +182 -0
  18. package/dist/federation/builder.test.mjs +1 -1
  19. package/dist/federation/collection.test.mjs +1 -1
  20. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  21. package/dist/federation/delivery-attachments.test.mjs +280 -0
  22. package/dist/federation/handler.test.mjs +208 -16
  23. package/dist/federation/idempotency.test.mjs +2 -2
  24. package/dist/federation/inbox.test.mjs +1 -1
  25. package/dist/federation/middleware.test.mjs +1559 -26
  26. package/dist/federation/mod.cjs +1 -1
  27. package/dist/federation/mod.d.cts +2 -2
  28. package/dist/federation/mod.d.ts +2 -2
  29. package/dist/federation/mod.js +1 -1
  30. package/dist/federation/negotiation.test.mjs +1 -1
  31. package/dist/federation/retry.test.mjs +1 -1
  32. package/dist/federation/send.test.mjs +723 -68
  33. package/dist/federation/temporal.test.mjs +25 -1
  34. package/dist/federation/webfinger.test.mjs +1 -1
  35. package/dist/{http-CK3efjgM.js → http-BtbMAgTA.js} +176 -105
  36. package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
  37. package/dist/{http-BoR1M3W7.cjs → http-D5woFKA_.cjs} +177 -106
  38. package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
  39. package/dist/{http-Bjd6I92u.mjs → http-HX6wVyJh.mjs} +198 -98
  40. package/dist/{inbox-9MlBGgs9.mjs → inbox-CL7A0HXT.mjs} +1 -1
  41. package/dist/{key-ClQh9Qqh.mjs → key-Dai3f5yI.mjs} +3 -2
  42. package/dist/{kv-cache-BxSx_Iyp.cjs → kv-cache-B0V_e231.cjs} +59 -17
  43. package/dist/{kv-cache-ImApO425.js → kv-cache-BsDg-cT8.js} +60 -18
  44. package/dist/{ld-Crg0Xmwr.mjs → ld-DN6x1iZ8.mjs} +153 -21
  45. package/dist/ld-signature-DoZcbsZR.mjs +23 -0
  46. package/dist/{middleware-jL9p9V9G.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
  47. package/dist/{middleware-CmD3lpy4.cjs → middleware-CrfRuKCf.cjs} +728 -143
  48. package/dist/{middleware-CE0b69gj.mjs → middleware-DiquMgtt.mjs} +444 -115
  49. package/dist/{middleware-C2AJFk8W.js → middleware-DunNtbo9.js} +727 -143
  50. package/dist/{middleware-Bi5D6DBT.mjs → middleware-SnQS8eIb.mjs} +1 -1
  51. package/dist/{mod-DiuFTYUt.d.cts → mod-CehHJOV4.d.cts} +30 -13
  52. package/dist/{mod-CWJNbyju.d.ts → mod-DLJpnqdw.d.ts} +1 -1
  53. package/dist/{mod-BLDHhuW0.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
  54. package/dist/{mod-DNEgTI8M.d.ts → mod-REfljt0T.d.ts} +4 -9
  55. package/dist/{mod-Cn9GJ5ex.d.cts → mod-UvIGUHqW.d.cts} +4 -9
  56. package/dist/{mod-BmlfRBmU.d.cts → mod-sTa1Zzxk.d.cts} +1 -1
  57. package/dist/mod.cjs +5 -5
  58. package/dist/mod.d.cts +8 -8
  59. package/dist/mod.d.ts +8 -8
  60. package/dist/mod.js +5 -5
  61. package/dist/nodeinfo/client.test.mjs +764 -19
  62. package/dist/nodeinfo/handler.test.mjs +1 -1
  63. package/dist/nodeinfo/mod.cjs +1 -1
  64. package/dist/nodeinfo/mod.d.cts +1 -1
  65. package/dist/nodeinfo/mod.d.ts +1 -1
  66. package/dist/nodeinfo/mod.js +1 -1
  67. package/dist/nodeinfo/types.test.mjs +1 -1
  68. package/dist/otel/exporter.test.mjs +292 -30
  69. package/dist/otel/mod.cjs +36 -30
  70. package/dist/otel/mod.d.cts +13 -0
  71. package/dist/otel/mod.d.ts +13 -0
  72. package/dist/otel/mod.js +36 -30
  73. package/dist/{owner-BRoKojK1.mjs → owner-DwyDorZI.mjs} +2 -2
  74. package/dist/{proof-CHXVlsH_.cjs → proof-Be-4K4jn.cjs} +193 -46
  75. package/dist/{proof-DMIAezxz.mjs → proof-DYjmyrHh.mjs} +38 -13
  76. package/dist/{proof-7R4s10TJ.js → proof-Du4-5SHY.js} +187 -46
  77. package/dist/send-BGSfQkIK.mjs +416 -0
  78. package/dist/sig/http.test.mjs +506 -2
  79. package/dist/sig/key-types.test.d.mts +218 -0
  80. package/dist/sig/key-types.test.mjs +8 -0
  81. package/dist/sig/key.test.mjs +2 -2
  82. package/dist/sig/ld.test.mjs +573 -8
  83. package/dist/sig/mod.cjs +2 -2
  84. package/dist/sig/mod.d.cts +3 -3
  85. package/dist/sig/mod.d.ts +3 -3
  86. package/dist/sig/mod.js +2 -2
  87. package/dist/sig/owner.test.mjs +1 -1
  88. package/dist/sig/proof.test.mjs +95 -3
  89. package/dist/{temporal-DR0JahMu.mjs → temporal-CNCchWly.mjs} +3 -5
  90. package/dist/testing/mod.d.mts +1 -2177
  91. package/dist/{types-DRPjmHVV.cjs → types-B5wRhemi.cjs} +187 -63
  92. package/dist/{types-miAYfiGO.js → types-CXy2lRVU.js} +188 -64
  93. package/dist/utils/docloader.test.mjs +316 -32
  94. package/dist/utils/mod.cjs +1 -1
  95. package/dist/utils/mod.d.cts +1 -1
  96. package/dist/utils/mod.d.ts +1 -1
  97. package/dist/utils/mod.js +1 -1
  98. package/package.json +7 -7
  99. package/dist/docloader-OLWc7P2D.mjs +0 -82
  100. package/dist/send-BHIt_8ia.mjs +0 -260
  101. /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
  102. /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
  103. /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
  104. /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
@@ -1,6 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { GetUserAgentOptions } from "@fedify/vocab-runtime";
3
-
4
3
  //#region src/nodeinfo/types.d.ts
5
4
  /**
6
5
  * The type of the result of parsing JSON.
@@ -166,6 +165,22 @@ interface GetNodeInfoOptions {
166
165
  * @since 1.3.0
167
166
  */
168
167
  userAgent?: GetUserAgentOptions | string;
168
+ /**
169
+ * The timeout in milliseconds for the entire NodeInfo lookup, including
170
+ * discovery, redirects, and reading the document. Defaults to 10 seconds.
171
+ * Set to `null` to disable the timeout. A timeout returns `undefined`.
172
+ * Fractional values are rounded up.
173
+ * @throws {RangeError} If the value is not a positive finite number or is
174
+ * greater than 2,147,483,647.
175
+ * @since 2.0.36
176
+ */
177
+ timeout?: number | null;
178
+ /**
179
+ * A signal to cancel the entire NodeInfo lookup. Cancellation returns
180
+ * `undefined`, including when the timeout is disabled.
181
+ * @since 2.0.36
182
+ */
183
+ signal?: AbortSignal;
169
184
  }
170
185
  /**
171
186
  * Fetches a NodeInfo document from the given URL.
@@ -1,6 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { GetUserAgentOptions } from "@fedify/vocab-runtime";
3
-
4
3
  //#region src/nodeinfo/types.d.ts
5
4
  /**
6
5
  * The type of the result of parsing JSON.
@@ -166,6 +165,22 @@ interface GetNodeInfoOptions {
166
165
  * @since 1.3.0
167
166
  */
168
167
  userAgent?: GetUserAgentOptions | string;
168
+ /**
169
+ * The timeout in milliseconds for the entire NodeInfo lookup, including
170
+ * discovery, redirects, and reading the document. Defaults to 10 seconds.
171
+ * Set to `null` to disable the timeout. A timeout returns `undefined`.
172
+ * Fractional values are rounded up.
173
+ * @throws {RangeError} If the value is not a positive finite number or is
174
+ * greater than 2,147,483,647.
175
+ * @since 2.0.36
176
+ */
177
+ timeout?: number | null;
178
+ /**
179
+ * A signal to cancel the entire NodeInfo lookup. Cancellation returns
180
+ * `undefined`, including when the timeout is disabled.
181
+ * @since 2.0.36
182
+ */
183
+ signal?: AbortSignal;
169
184
  }
170
185
  /**
171
186
  * Fetches a NodeInfo document from the given URL.
@@ -1,7 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { FetchError, UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
4
+ import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
5
+ import { detectRuntime, lookupAllAddressesBounded, openPublicFetch } from "@fedify/vocab-runtime/internal";
5
6
  import { getLogger } from "@logtape/logtape";
6
7
  //#region src/utils/body.ts
7
8
  /** Decoded JSON body limit: 16 MiB. @internal */
@@ -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
  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 = 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) => openPublicFetch(hopUrl, detectRuntime() === "node" ? {
123
+ signal,
124
+ lookup: (hostname) => 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 validatePublicUrl(current.href);
133
+ session = await openHop(current.href, signal);
105
134
  } catch (e) {
135
+ signal?.throwIfAborted();
106
136
  if (e instanceof 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 : 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 : 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 : 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
  });
@@ -389,4 +513,4 @@ function parseUsage(data, options = {}) {
389
513
  };
390
514
  }
391
515
  //#endregion
392
- export { parseProtocol as a, parseUsage as c, readBoundedText as d, parseOutboundService as i, BodyTooLargeError as l, parseInboundService as n, parseServices as o, parseNodeInfo as r, parseSoftware as s, getNodeInfo as t, MAX_BODY_SIZE as u };
516
+ export { parseOutboundService as a, parseSoftware as c, MAX_BODY_SIZE as d, readBoundedText as f, parseNodeInfo as i, parseUsage as l, getNodeInfoInternal as n, parseProtocol as o, parseInboundService as r, parseServices as s, getNodeInfo as t, BodyTooLargeError as u };
@@ -0,0 +1,2 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
@@ -0,0 +1,254 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
+ import { n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
6
+ import { t as normalizeAttachmentArrays } from "../attachment-arrays-DZ4JHJD8.mjs";
7
+ import { test } from "@fedify/fixture";
8
+ import { preloadedContexts } from "@fedify/vocab-runtime";
9
+ //#region src/compat/attachment-arrays.test.ts
10
+ const AS = "https://www.w3.org/ns/activitystreams";
11
+ const SEC = "https://w3id.org/security#";
12
+ test("attachment arrays: singleton, multiple, nested and expanded properties", async () => {
13
+ const document = {
14
+ "@context": AS,
15
+ type: "Collection",
16
+ items: [
17
+ {
18
+ type: "Note",
19
+ attachment: {
20
+ type: "Image",
21
+ url: "https://example.com/a"
22
+ }
23
+ },
24
+ {
25
+ type: "Note",
26
+ attachment: ["https://example.com/b", "https://example.com/c"]
27
+ },
28
+ {
29
+ type: "Note",
30
+ attachment: null
31
+ },
32
+ {
33
+ type: "Note",
34
+ [`${AS}#attachment`]: "https://example.com/d"
35
+ }
36
+ ]
37
+ };
38
+ const before = structuredClone(document);
39
+ const result = await normalizeAttachmentArrays(document);
40
+ assertEquals(result, {
41
+ ...document,
42
+ items: [
43
+ {
44
+ type: "Note",
45
+ attachment: [document.items[0].attachment]
46
+ },
47
+ document.items[1],
48
+ document.items[2],
49
+ {
50
+ type: "Note",
51
+ [`${AS}#attachment`]: ["https://example.com/d"]
52
+ }
53
+ ]
54
+ });
55
+ assertEquals(document, before);
56
+ assertStrictEquals(await normalizeAttachmentArrays(result), result);
57
+ });
58
+ test("attachment arrays: preserve lists, contexts and value objects", async () => {
59
+ for (const document of [{
60
+ "@context": AS,
61
+ attachment: { "@list": ["https://example.com/a"] }
62
+ }, {
63
+ "@context": AS,
64
+ content: {
65
+ "@value": { attachment: 1 },
66
+ "@type": "@json"
67
+ }
68
+ }]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
69
+ });
70
+ test("attachment arrays: inline and remote contexts share one loader snapshot", async () => {
71
+ let loads = 0;
72
+ const loader = (url) => {
73
+ loads++;
74
+ return Promise.resolve({
75
+ documentUrl: url,
76
+ contextUrl: null,
77
+ document: preloadedContexts[AS]
78
+ });
79
+ };
80
+ const document = {
81
+ "@context": "https://example.com/context",
82
+ attachment: "https://example.com/a"
83
+ };
84
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
85
+ assertEquals(await normalizeAttachmentArrays(document, loader), {
86
+ ...document,
87
+ attachment: [document.attachment]
88
+ });
89
+ assertEquals(loads, 1);
90
+ const inline = {
91
+ "@context": [AS, {
92
+ schema: "http://schema.org/",
93
+ value: "schema:value"
94
+ }],
95
+ attachment: { type: "Image" }
96
+ };
97
+ assertEquals(await normalizeAttachmentArrays(inline), {
98
+ ...inline,
99
+ attachment: [inline.attachment]
100
+ });
101
+ });
102
+ test("attachment arrays: JSON literals and context redefinitions remain unchanged", async () => {
103
+ for (const document of [
104
+ {
105
+ "@context": [AS, { attachment: {
106
+ "@id": `${AS}#attachment`,
107
+ "@type": "@json"
108
+ } }],
109
+ attachment: { type: "Image" }
110
+ },
111
+ {
112
+ "@context": [AS, { payload: {
113
+ "@id": "https://example.com/payload",
114
+ "@type": "@json"
115
+ } }],
116
+ attachment: "https://example.com/a",
117
+ payload: { attachment: { proof: "literal" } }
118
+ },
119
+ {
120
+ "@context": [AS, "https://www.w3.org/ns/cid/v1"],
121
+ attachment: "https://example.com/a",
122
+ publicKeyJwk: { attachment: { type: "Image" } }
123
+ },
124
+ {
125
+ "@context": [
126
+ AS,
127
+ null,
128
+ {
129
+ "@vocab": "https://example.com/",
130
+ attachment: {
131
+ "@id": "https://example.com/attachment",
132
+ "@type": "@json"
133
+ }
134
+ }
135
+ ],
136
+ attachment: { type: "Image" }
137
+ }
138
+ ]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
139
+ });
140
+ test("attachment arrays: language and index maps retain their semantics", async () => {
141
+ for (const container of ["@language", "@index"]) {
142
+ const document = {
143
+ "@context": [AS, { attachment: {
144
+ "@id": `${AS}#attachment`,
145
+ "@container": container
146
+ } }],
147
+ attachment: container === "@language" ? { en: "example" } : { sample: { type: "Image" } }
148
+ };
149
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
150
+ }
151
+ });
152
+ test("attachment arrays: scoped contexts cannot change literal payloads", async () => {
153
+ const document = {
154
+ "@context": [AS, { Special: {
155
+ "@id": "https://example.com/Special",
156
+ "@context": { attachment: {
157
+ "@id": `${AS}#attachment`,
158
+ "@type": "@json"
159
+ } }
160
+ } }],
161
+ type: "Special",
162
+ attachment: { type: "Image" }
163
+ };
164
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
165
+ });
166
+ test("attachment arrays: root proofs and signed siblings are immutable", async () => {
167
+ const signed = Object.freeze({
168
+ "@context": [AS, { proof: `${SEC}proof` }],
169
+ attachment: "https://example.com/a",
170
+ proof: Object.freeze({ id: "https://example.com/proof" })
171
+ });
172
+ assertStrictEquals(await normalizeAttachmentArrays(signed), signed);
173
+ const document = {
174
+ "@context": AS,
175
+ type: "Collection",
176
+ items: [signed, {
177
+ type: "Note",
178
+ attachment: "https://example.com/b"
179
+ }]
180
+ };
181
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
182
+ for (const proof of [[], [{ proofValue: "one" }, { proofValue: "two" }]]) {
183
+ const root = {
184
+ "@context": [AS, { proof: `${SEC}proof` }],
185
+ attachment: "https://example.com/a",
186
+ proof
187
+ };
188
+ assertStrictEquals(await normalizeAttachmentArrays(root), root);
189
+ }
190
+ });
191
+ test("attachment arrays: semantic proof aliases preserve the whole document", async () => {
192
+ for (const nested of [false, true]) {
193
+ const document = {
194
+ "@context": [AS, { seal: `${SEC}proof` }],
195
+ attachment: "https://example.com/a",
196
+ ...nested ? { object: { seal: { "@id": "https://example.com/proof" } } } : { seal: { "@id": "https://example.com/proof" } }
197
+ };
198
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
199
+ }
200
+ const literal = {
201
+ "@context": AS,
202
+ content: `<${SEC}proof>`,
203
+ attachment: "https://example.com/a"
204
+ };
205
+ assertEquals(await normalizeAttachmentArrays(literal), {
206
+ ...literal,
207
+ attachment: [literal.attachment]
208
+ });
209
+ });
210
+ test("attachment arrays: excessive depth and failing loaders preserve input", async () => {
211
+ let document = { attachment: "https://example.com/a" };
212
+ for (let i = 0; i < 70; i++) document = { object: document };
213
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
214
+ const custom = {
215
+ "@context": "https://example.com/unavailable",
216
+ attachment: "https://example.com/a"
217
+ };
218
+ assertStrictEquals(await normalizeAttachmentArrays(custom, () => Promise.reject(/* @__PURE__ */ new Error("unavailable"))), custom);
219
+ });
220
+ test("attachment arrays: context-coerced security-shaped JSON is ordinary data", async () => {
221
+ const data = { proof: { signature: "application data" } };
222
+ const document = {
223
+ "@context": [AS, { data: {
224
+ "@id": "https://example.com/data",
225
+ "@type": "@json"
226
+ } }],
227
+ attachment: "https://example.com/a",
228
+ data
229
+ };
230
+ assertEquals(await normalizeAttachmentArrays(document), {
231
+ ...document,
232
+ attachment: [document.attachment]
233
+ });
234
+ assertEquals(document.data, data);
235
+ let deep = { signature: "application data" };
236
+ for (let i = 0; i < 70; i++) deep = { child: deep };
237
+ const large = {
238
+ ...document,
239
+ data: deep
240
+ };
241
+ assertStrictEquals(await normalizeAttachmentArrays(large), large);
242
+ });
243
+ test("attachment arrays: root and nested semantic LD signatures block rewriting", async () => {
244
+ for (const nested of [false, true]) {
245
+ const document = {
246
+ "@context": [AS, { seal: `${SEC}signature` }],
247
+ attachment: "https://example.com/a",
248
+ ...nested ? { object: { seal: { "@id": "https://example.com/sig" } } } : { seal: { "@id": "https://example.com/sig" } }
249
+ };
250
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
251
+ }
252
+ });
253
+ //#endregion
254
+ export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { Ct as ActivityTransformer, n as Context } from "../context-BNwv9Q1v.cjs";
2
+ import { Ct as ActivityTransformer, n as Context } from "../context-y6ZUQCMf.cjs";
3
3
  import { Activity } from "@fedify/vocab";
4
4
 
5
5
  //#region src/compat/transformers.d.ts
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { Ct as ActivityTransformer, n as Context } from "../context-DLLaDau8.js";
2
+ import { Ct as ActivityTransformer, n as Context } from "../context-DE2YrQwM.js";
3
3
  import { Activity } from "@fedify/vocab";
4
4
 
5
5
  //#region src/compat/transformers.d.ts