@fedify/fedify 2.1.31 → 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 (97) hide show
  1. package/dist/attachment-arrays-DZ4JHJD8.mjs +111 -0
  2. package/dist/{builder-isMRh_I6.mjs → builder--sc-rozj.mjs} +3 -3
  3. package/dist/callback-BARPujV7.d.mts +2388 -0
  4. package/dist/{client-BIBzqEIp.d.cts → client-9DPcy_Yx.d.ts} +16 -0
  5. package/dist/{client-jE7oGvRh.d.ts → client-B3ruDgWg.d.cts} +16 -0
  6. package/dist/{client-BZr7TGyu.mjs → client-cpPaW7Ww.mjs} +86 -11
  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-C0uGVzgk.d.ts → context-DE2YrQwM.d.ts} +30 -13
  13. package/dist/{context-CLaLxi49.d.cts → context-y6ZUQCMf.d.cts} +30 -13
  14. package/dist/{deno-CiaJqTcu.mjs → deno-L23b3Hba.mjs} +1 -1
  15. package/dist/{docloader-DOrwedT7.mjs → docloader-DUXr9k_O.mjs} +2 -2
  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 +1185 -8
  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 +283 -3
  33. package/dist/federation/temporal.test.mjs +25 -1
  34. package/dist/federation/webfinger.test.mjs +1 -1
  35. package/dist/{http-Crml3gei.js → http-BtbMAgTA.js} +6 -4
  36. package/dist/{http-9IFUxdkp.d.cts → http-C8qLHs_Z.d.cts} +3 -3
  37. package/dist/{http-CRiVlZd5.cjs → http-D5woFKA_.cjs} +6 -4
  38. package/dist/{http-SbfezERn.d.ts → http-D8WmcRAF.d.ts} +3 -3
  39. package/dist/{http-A9mP2uM7.mjs → http-HX6wVyJh.mjs} +6 -4
  40. package/dist/{inbox-KESLudq4.mjs → inbox-CL7A0HXT.mjs} +1 -1
  41. package/dist/{key-Dg6-DV_O.mjs → key-Dai3f5yI.mjs} +3 -2
  42. package/dist/{kv-cache-Cqmm-yQa.cjs → kv-cache-B0V_e231.cjs} +1 -1
  43. package/dist/{kv-cache-DQcyZL5T.js → kv-cache-BsDg-cT8.js} +1 -1
  44. package/dist/{ld-COjDN6Nb.mjs → ld-DN6x1iZ8.mjs} +153 -21
  45. package/dist/ld-signature-DoZcbsZR.mjs +23 -0
  46. package/dist/{middleware-BtDQUCcz.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
  47. package/dist/{middleware-BbgR7xOI.cjs → middleware-CrfRuKCf.cjs} +561 -101
  48. package/dist/{middleware-COFlKeYn.mjs → middleware-DiquMgtt.mjs} +378 -89
  49. package/dist/{middleware-DIW5S_5L.js → middleware-DunNtbo9.js} +560 -101
  50. package/dist/{middleware-CuQvczZd.mjs → middleware-SnQS8eIb.mjs} +1 -1
  51. package/dist/{mod-LOEOKbYd.d.cts → mod-CehHJOV4.d.cts} +30 -13
  52. package/dist/{mod-CFRocFeQ.d.ts → mod-DLJpnqdw.d.ts} +1 -1
  53. package/dist/{mod-C7w-QVUv.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
  54. package/dist/{mod-BRnwh2oy.d.ts → mod-REfljt0T.d.ts} +3 -3
  55. package/dist/{mod-Co7LEK9X.d.cts → mod-UvIGUHqW.d.cts} +3 -3
  56. package/dist/{mod-CGUH8Ujp.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 +432 -5
  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/{owner-CFHq61cq.mjs → owner-DwyDorZI.mjs} +2 -2
  69. package/dist/{proof-0JkSC_pT.cjs → proof-Be-4K4jn.cjs} +193 -46
  70. package/dist/{proof-KSHlbPCG.mjs → proof-DYjmyrHh.mjs} +38 -13
  71. package/dist/{proof-DzksJFK7.js → proof-Du4-5SHY.js} +187 -46
  72. package/dist/{send-DaDe2YCb.mjs → send-BGSfQkIK.mjs} +92 -21
  73. package/dist/sig/http.test.mjs +2 -2
  74. package/dist/sig/key-types.test.d.mts +218 -0
  75. package/dist/sig/key-types.test.mjs +8 -0
  76. package/dist/sig/key.test.mjs +2 -2
  77. package/dist/sig/ld.test.mjs +573 -8
  78. package/dist/sig/mod.cjs +2 -2
  79. package/dist/sig/mod.d.cts +3 -3
  80. package/dist/sig/mod.d.ts +3 -3
  81. package/dist/sig/mod.js +2 -2
  82. package/dist/sig/owner.test.mjs +1 -1
  83. package/dist/sig/proof.test.mjs +95 -3
  84. package/dist/{temporal-DNGH8o2E.mjs → temporal-CNCchWly.mjs} +3 -5
  85. package/dist/testing/mod.d.mts +2 -2203
  86. package/dist/{types-DOvyymM4.cjs → types-B5wRhemi.cjs} +85 -10
  87. package/dist/{types-B1_pRFE_.js → types-CXy2lRVU.js} +86 -11
  88. package/dist/utils/docloader.test.mjs +2 -2
  89. package/dist/utils/mod.cjs +1 -1
  90. package/dist/utils/mod.d.cts +1 -1
  91. package/dist/utils/mod.d.ts +1 -1
  92. package/dist/utils/mod.js +1 -1
  93. package/package.json +6 -6
  94. /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
  95. /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
  96. /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
  97. /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
@@ -165,6 +165,22 @@ interface GetNodeInfoOptions {
165
165
  * @since 1.3.0
166
166
  */
167
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;
168
184
  }
169
185
  /**
170
186
  * Fetches a NodeInfo document from the given URL.
@@ -165,6 +165,22 @@ interface GetNodeInfoOptions {
165
165
  * @since 1.3.0
166
166
  */
167
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;
168
184
  }
169
185
  /**
170
186
  * Fetches a NodeInfo document from the given URL.
@@ -2,7 +2,7 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
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
  import { getLogger } from "@logtape/logtape";
7
7
  //#region src/utils/body.ts
8
8
  /** Decoded JSON body limit: 16 MiB. @internal */
@@ -25,13 +25,18 @@ function validateBodySizeLimit(maxBytes) {
25
25
  * @param message The response or request to read.
26
26
  * @param maxBytes The maximum number of decoded bytes to read.
27
27
  * @param url The URL to include in errors and logs.
28
+ * @param signal An optional signal for cancelling the body read.
28
29
  * @returns The decoded body text.
29
30
  * @throws {BodyTooLargeError} If the body exceeds the limit.
30
31
  * @internal
31
32
  */
32
- async function readBoundedText(message, maxBytes, url) {
33
+ async function readBoundedText(message, maxBytes, url, signal) {
33
34
  validateBodySizeLimit(maxBytes);
34
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 });
35
40
  const tooLarge = () => {
36
41
  getLogger([
37
42
  "fedify",
@@ -44,6 +49,7 @@ async function readBoundedText(message, maxBytes, url) {
44
49
  throw new BodyTooLargeError(url, maxBytes);
45
50
  };
46
51
  try {
52
+ signal?.throwIfAborted();
47
53
  const length = message.headers.get("Content-Length");
48
54
  const encoding = message.headers.get("Content-Encoding");
49
55
  if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
@@ -51,6 +57,7 @@ async function readBoundedText(message, maxBytes, url) {
51
57
  let size = 0;
52
58
  const textReader = new ReadableStream({ async pull(controller) {
53
59
  const { done, value } = await reader.read();
60
+ signal?.throwIfAborted();
54
61
  if (done) {
55
62
  controller.close();
56
63
  return;
@@ -63,6 +70,7 @@ async function readBoundedText(message, maxBytes, url) {
63
70
  const chunks = [];
64
71
  while (true) {
65
72
  const { done, value } = await textReader.read();
73
+ signal?.throwIfAborted();
66
74
  if (done) break;
67
75
  chunks.push(value);
68
76
  }
@@ -74,6 +82,7 @@ async function readBoundedText(message, maxBytes, url) {
74
82
  if (reader != null) reader.cancel(error).catch(() => {});
75
83
  throw error;
76
84
  } finally {
85
+ signal?.removeEventListener("abort", onAbort);
77
86
  reader?.releaseLock();
78
87
  }
79
88
  }
@@ -85,6 +94,8 @@ const logger = getLogger([
85
94
  "client"
86
95
  ]);
87
96
  const DEFAULT_MAX_REDIRECTION = 5;
97
+ const DEFAULT_TIMEOUT = 1e4;
98
+ const MAX_TIMEOUT = 2147483647;
88
99
  /**
89
100
  * Fetches a URL while guarding against SSRF. Every request—including each
90
101
  * redirect hop—is made in its own session opened with `openPublicFetch()`,
@@ -101,20 +112,27 @@ const DEFAULT_MAX_REDIRECTION = 5;
101
112
  * @param headers The request headers.
102
113
  * @param consume The function to consume the final response with.
103
114
  * @param deps The dependencies.
115
+ * @param signal The signal for the whole NodeInfo lookup.
104
116
  * @returns The value returned by `consume`, or `null` if the URL is
105
117
  * disallowed, its hostname cannot be resolved, or there are too many
106
118
  * redirects.
107
119
  * @internal
108
120
  */
109
- async function fetchPublicUrl(url, headers, consume, deps = {}) {
110
- const openHop = deps.openHop ?? ((hopUrl) => openPublicFetch(hopUrl));
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 }));
111
126
  let current = url instanceof URL ? url : new URL(url);
112
127
  let redirected = 0;
128
+ const visited = new Set([redirectKey(current)]);
113
129
  while (true) {
130
+ signal?.throwIfAborted();
114
131
  let session;
115
132
  try {
116
- session = await openHop(current.href);
133
+ session = await openHop(current.href, signal);
117
134
  } catch (e) {
135
+ signal?.throwIfAborted();
118
136
  if (e instanceof UrlError) {
119
137
  if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
120
138
  url: current.href,
@@ -130,10 +148,16 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
130
148
  }
131
149
  let location;
132
150
  try {
151
+ signal?.throwIfAborted();
133
152
  const response = await session.fetch(current, {
134
153
  headers,
135
- redirect: "manual"
154
+ redirect: "manual",
155
+ signal
136
156
  });
157
+ if (signal?.aborted) {
158
+ cancelBody(response, current);
159
+ signal.throwIfAborted();
160
+ }
137
161
  if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
138
162
  location = response.headers.get("Location");
139
163
  cancelBody(response, current);
@@ -156,9 +180,20 @@ async function fetchPublicUrl(url, headers, consume, deps = {}) {
156
180
  });
157
181
  return null;
158
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);
159
189
  current = next;
160
190
  }
161
191
  }
192
+ function redirectKey(url) {
193
+ const withoutFragment = new URL(url);
194
+ withoutFragment.hash = "";
195
+ return withoutFragment.href;
196
+ }
162
197
  /**
163
198
  * Starts cancelling a response body that is not read, without waiting for it
164
199
  * to settle. The cancellation of a branch of a tee (e.g., a body cloned by
@@ -189,6 +224,46 @@ async function getNodeInfo(url, options = {}) {
189
224
  * @internal
190
225
  */
191
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(() => {});
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) {
192
267
  try {
193
268
  const headers = {
194
269
  Accept: "application/json",
@@ -207,8 +282,8 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
207
282
  cancelBody(response, wellKnownUrl);
208
283
  return;
209
284
  }
210
- return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl)) };
211
- }, deps);
285
+ return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl, signal)) };
286
+ }, deps, signal);
212
287
  if (wellKnown == null) return void 0;
213
288
  const wellKnownRd = wellKnown.rd;
214
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);
@@ -231,14 +306,14 @@ async function getNodeInfoInternal(url, options = {}, deps = {}) {
231
306
  cancelBody(response, nodeInfoUrl);
232
307
  return;
233
308
  }
234
- return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl)) };
235
- }, deps);
309
+ return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl, signal)) };
310
+ }, deps, signal);
236
311
  if (document == null) return void 0;
237
312
  const { data } = document;
238
313
  if (options.parse === "none") return data;
239
314
  return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
240
315
  } catch (error) {
241
- logger.error("Failed to fetch NodeInfo document from {url}: {error}", {
316
+ logger[signal?.aborted ? "debug" : "error"]("Failed to fetch NodeInfo document from {url}: {error}", {
242
317
  url: url.toString(),
243
318
  error
244
319
  });
@@ -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-CLaLxi49.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-C0uGVzgk.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
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
6
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
7
- import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-COFlKeYn.mjs";
7
+ import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-DiquMgtt.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  import { Follow, Person } from "@fedify/vocab";
10
10
  //#region src/compat/transformers.test.ts
@@ -1,11 +1,11 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-jE7oGvRh.js";
3
- import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-SbfezERn.js";
2
+ import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-9DPcy_Yx.js";
3
+ import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-D8WmcRAF.js";
4
4
  import { n as GetKeyOwnerOptions } from "./owner-CiBPcC6F.js";
5
5
  import { n as KvStore, t as KvKey } from "./kv-CxaI4eGo.js";
6
6
  import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, TraverseCollectionOptions } from "@fedify/vocab";
7
7
  import { Span, Tracer, TracerProvider } from "@opentelemetry/api";
8
- import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
8
+ import { AuthenticatedDocumentLoaderFactory, CryptoKeyLike, CryptoKeyPairLike, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
9
9
  import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
10
10
 
11
11
  //#region src/compat/types.d.ts
@@ -46,13 +46,18 @@ declare function buildCollectionSynchronizationHeader(collectionId: string | URL
46
46
  //#region src/federation/send.d.ts
47
47
  /**
48
48
  * A key pair for an actor who sends an activity.
49
+ *
50
+ * The private key type is parameterized so that Fedify can accept keys from
51
+ * `node:crypto` at its input boundaries while `SenderKeyPair` still exposes the
52
+ * ambient `CryptoKey` type by default.
53
+ * @template TKey The type of the private key.
49
54
  * @since 0.10.0
50
55
  */
51
- interface SenderKeyPair {
56
+ interface SenderKeyPair<TKey extends CryptoKeyLike = CryptoKey> {
52
57
  /**
53
58
  * The actor's private key to sign the request.
54
59
  */
55
- readonly privateKey: CryptoKey;
60
+ readonly privateKey: TKey;
56
61
  /**
57
62
  * The public key ID that corresponds to the private key.
58
63
  */
@@ -116,13 +121,19 @@ type ActorDispatcher<TContextData> = (context: RequestContext<TContextData>, ide
116
121
  /**
117
122
  * A callback that dispatches key pairs for an actor.
118
123
  *
124
+ * The returned key pairs may come from any supported runtime, including keys
125
+ * obtained from `node:crypto`'s Web Crypto API, so the key pair type is
126
+ * parameterized. It defaults to the ambient `CryptoKeyPair` type for
127
+ * compatibility with code that calls a dispatcher directly.
128
+ *
119
129
  * @template TContextData The context data to pass to the {@link Context}.
130
+ * @template TKeyPair The type of the key pairs the dispatcher returns.
120
131
  * @param context The context.
121
132
  * @param identifier The actor's internal identifier or username.
122
133
  * @returns The key pairs.
123
134
  * @since 0.10.0
124
135
  */
125
- type ActorKeyPairsDispatcher<TContextData> = (context: Context<TContextData>, identifier: string) => CryptoKeyPair[] | Promise<CryptoKeyPair[]>;
136
+ type ActorKeyPairsDispatcher<TContextData, TKeyPair extends CryptoKeyPairLike = CryptoKeyPair> = (context: Context<TContextData>, identifier: string) => TKeyPair[] | Promise<TKeyPair[]>;
126
137
  /**
127
138
  * A callback that maps a WebFinger username to the corresponding actor's
128
139
  * internal identifier, or `null` if the username is not found.
@@ -252,11 +263,11 @@ type InboxErrorHandler<TContextData> = (context: Context<TContextData>, error: E
252
263
  * not authorized.
253
264
  * @since 0.11.0
254
265
  */
255
- type SharedInboxKeyDispatcher<TContextData> = (context: Context<TContextData>) => SenderKeyPair | {
266
+ type SharedInboxKeyDispatcher<TContextData, TKeyPair extends CryptoKeyLike = CryptoKey> = (context: Context<TContextData>) => SenderKeyPair<TKeyPair> | {
256
267
  identifier: string;
257
268
  } | {
258
269
  username: string;
259
- } | null | Promise<SenderKeyPair | {
270
+ } | null | Promise<SenderKeyPair<TKeyPair> | {
260
271
  identifier: string;
261
272
  } | {
262
273
  username: string;
@@ -1425,6 +1436,12 @@ interface FederationOptions<TContextData> {
1425
1436
  *
1426
1437
  * By default, the queue starts automatically.
1427
1438
  *
1439
+ * Automatic startup is best-effort: if a queue cannot start listening,
1440
+ * a warning is logged once per federation instance and the failed worker is
1441
+ * not retried, while an explicit {@link Federation.startQueue} call rejects.
1442
+ * Runtimes that consume the queue elsewhere, such as Cloudflare Workers with
1443
+ * {@link Federation.processQueuedTask}, should set this to `true`.
1444
+ *
1428
1445
  * @since 0.12.0
1429
1446
  */
1430
1447
  manuallyStartQueue?: boolean;
@@ -1598,7 +1615,7 @@ interface ActorCallbackSetters<TContextData> {
1598
1615
  * @returns The setters object so that settings can be chained.
1599
1616
  * @since 0.10.0
1600
1617
  */
1601
- setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
1618
+ setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData, CryptoKeyPairLike>): ActorCallbackSetters<TContextData>;
1602
1619
  /**
1603
1620
  * Sets the callback function that maps a WebFinger username to
1604
1621
  * the corresponding actor's identifier. If it's omitted, the identifier
@@ -1765,7 +1782,7 @@ interface InboxListenerSetters<TContextData> {
1765
1782
  * @returns The setters object so that settings can be chained.
1766
1783
  * @since 0.11.0
1767
1784
  */
1768
- setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
1785
+ setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData, CryptoKeyLike>): InboxListenerSetters<TContextData>;
1769
1786
  /**
1770
1787
  * Configures the strategy for handling activity idempotency in inbox processing.
1771
1788
  *
@@ -2098,7 +2115,7 @@ interface Context<TContextData> {
2098
2115
  */
2099
2116
  getDocumentLoader(identity: {
2100
2117
  keyId: URL;
2101
- privateKey: CryptoKey;
2118
+ privateKey: CryptoKeyLike;
2102
2119
  }): DocumentLoader;
2103
2120
  /**
2104
2121
  * Looks up an ActivityStreams object by its URI (including `acct:` URIs)
@@ -2211,7 +2228,7 @@ interface Context<TContextData> {
2211
2228
  * @param activity The activity to send.
2212
2229
  * @param options Options for sending the activity.
2213
2230
  */
2214
- sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
2231
+ sendActivity(sender: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2215
2232
  identifier: string;
2216
2233
  } | {
2217
2234
  username: string;
@@ -2431,7 +2448,7 @@ interface InboxContext<TContextData> extends Context<TContextData> {
2431
2448
  * @param options Options for forwarding the activity.
2432
2449
  * @since 1.0.0
2433
2450
  */
2434
- forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
2451
+ forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2435
2452
  identifier: string;
2436
2453
  } | {
2437
2454
  username: string;