@fedify/fedify 2.3.16-dev.2845 → 2.3.16

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 (108) hide show
  1. package/dist/attachment-arrays-BlfpZlWF.mjs +16 -0
  2. package/dist/{builder-B9apzaoK.mjs → builder-D4GE1Gmi.mjs} +3 -3
  3. package/dist/callback-kR_sx2zZ.d.mts +2661 -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-DpUNYKla.mjs → client-DFgYVbUA.mjs} +86 -11
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-CE_Tj_Oc.d.cts → context-CEE8vl-b.d.cts} +31 -14
  15. package/dist/{context-H_5tZXg-.d.ts → context-CTJwXHRu.d.ts} +31 -14
  16. package/dist/{deno-CgHxPWA-.mjs → deno-FtdqgHJA.mjs} +1 -1
  17. package/dist/{docloader-CYscMv4m.mjs → docloader-B9iU4DP2.mjs} +2 -2
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/circuit-breaker.test.mjs +2 -2
  22. package/dist/federation/collection.test.mjs +1 -1
  23. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  24. package/dist/federation/delivery-attachments.test.mjs +288 -0
  25. package/dist/federation/handler.test.mjs +208 -16
  26. package/dist/federation/idempotency.test.mjs +2 -2
  27. package/dist/federation/inbox.test.mjs +2 -2
  28. package/dist/federation/metrics.test.mjs +1 -1
  29. package/dist/federation/middleware.test.mjs +1191 -16
  30. package/dist/federation/mod.cjs +1 -1
  31. package/dist/federation/mod.d.cts +2 -2
  32. package/dist/federation/mod.d.ts +2 -2
  33. package/dist/federation/mod.js +1 -1
  34. package/dist/federation/negotiation.test.mjs +1 -1
  35. package/dist/federation/retry.test.mjs +1 -1
  36. package/dist/federation/send.test.mjs +293 -3
  37. package/dist/federation/temporal.test.mjs +25 -1
  38. package/dist/federation/webfinger.test.mjs +1 -1
  39. package/dist/{http-CfxAK-RL.cjs → http-2RyDQ0tE.cjs} +6 -4
  40. package/dist/{http-DmP0sr2l.d.ts → http-Bs5mXWlH.d.ts} +3 -3
  41. package/dist/{http-CZPYFK3b.d.cts → http-D8DgRhHU.d.cts} +3 -3
  42. package/dist/{http-dzXtCtOp.mjs → http-D8tiOrZf.mjs} +7 -5
  43. package/dist/{http-BzIb8Gk0.js → http-mLeLYFj-.js} +6 -4
  44. package/dist/{inbox-BMytDl21.mjs → inbox-Dy8awbi8.mjs} +2 -2
  45. package/dist/{key-fdTPEBhG.mjs → key-o1SmN5s0.mjs} +4 -3
  46. package/dist/{kv-cache-ShxnSuNt.mjs → kv-cache-BwUrzCVO.mjs} +1 -1
  47. package/dist/{kv-cache-dQUFD_pa.cjs → kv-cache-CI6Z0WiS.cjs} +1 -1
  48. package/dist/{kv-cache-CwqJUNNd.js → kv-cache-Dsq8C8D8.js} +1 -1
  49. package/dist/{ld-B8mU49Dg.mjs → ld-DCKrqj9y.mjs} +155 -22
  50. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  51. package/dist/{metrics-C0ZYkgVy.mjs → metrics-CaoYRhNH.mjs} +1 -1
  52. package/dist/{middleware-DK_kGeMl.mjs → middleware-4p3opEMT.mjs} +1 -1
  53. package/dist/{middleware-9mBkHYci.cjs → middleware-CP-8P7kk.cjs} +492 -117
  54. package/dist/{middleware-D0GPqg_7.js → middleware-Cce0nLDw.js} +491 -117
  55. package/dist/{middleware-Hr9ci9uD.mjs → middleware-D31fNcY4.mjs} +399 -109
  56. package/dist/{mod-C_gFmeNq.d.cts → mod-BD0-_vya.d.ts} +31 -13
  57. package/dist/{mod-HQXFvOHs.d.ts → mod-BMX6nsHP.d.cts} +31 -13
  58. package/dist/{mod-CDFFESfL.d.ts → mod-BTvP5Hva.d.ts} +1 -1
  59. package/dist/{mod-DMjhnFbg.d.ts → mod-DgMTlwUO.d.ts} +3 -3
  60. package/dist/{mod-DDVkmZ_h.d.cts → mod-Q1Fo3FJk.d.cts} +3 -3
  61. package/dist/{mod-DDjtbkZO.d.cts → mod-n51LED4J.d.cts} +1 -1
  62. package/dist/mod.cjs +5 -5
  63. package/dist/mod.d.cts +8 -8
  64. package/dist/mod.d.ts +8 -8
  65. package/dist/mod.js +5 -5
  66. package/dist/nodeinfo/client.test.mjs +432 -4
  67. package/dist/nodeinfo/handler.test.mjs +1 -1
  68. package/dist/nodeinfo/mod.cjs +1 -1
  69. package/dist/nodeinfo/mod.d.cts +1 -1
  70. package/dist/nodeinfo/mod.d.ts +1 -1
  71. package/dist/nodeinfo/mod.js +1 -1
  72. package/dist/nodeinfo/types.test.mjs +1 -1
  73. package/dist/{outgoing-jsonld-D4iTv7uM.mjs → outgoing-jsonld-BZEAVK_Q.mjs} +38 -8
  74. package/dist/{owner-BqnaV4zl.mjs → owner-Bdj0nHhf.mjs} +2 -2
  75. package/dist/{proof-BSRF2hIP.js → proof-B9XJiyz-.js} +1030 -858
  76. package/dist/{proof-D9VX-J1n.cjs → proof-CmcP8yqP.cjs} +1243 -1059
  77. package/dist/{proof-BvpOtXRD.mjs → proof-DrbjYma9.mjs} +41 -16
  78. package/dist/{send-BPel6SCW.mjs → send-VD_WG3dN.mjs} +100 -22
  79. package/dist/sig/http.test.mjs +2 -2
  80. package/dist/sig/key-types.test.d.mts +218 -0
  81. package/dist/sig/key-types.test.mjs +8 -0
  82. package/dist/sig/key.test.mjs +2 -2
  83. package/dist/sig/ld.test.mjs +573 -8
  84. package/dist/sig/mod.cjs +2 -2
  85. package/dist/sig/mod.d.cts +3 -3
  86. package/dist/sig/mod.d.ts +3 -3
  87. package/dist/sig/mod.js +2 -2
  88. package/dist/sig/owner.test.mjs +1 -1
  89. package/dist/sig/proof.test.mjs +96 -4
  90. package/dist/{temporal-CaD1O1QX.mjs → temporal-CMvoB-vD.mjs} +3 -5
  91. package/dist/testing/mod.d.mts +2 -2476
  92. package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
  93. package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
  94. package/dist/utils/docloader.test.mjs +2 -2
  95. package/dist/utils/kv-cache.test.mjs +1 -1
  96. package/dist/utils/mod.cjs +1 -1
  97. package/dist/utils/mod.d.cts +1 -1
  98. package/dist/utils/mod.d.ts +1 -1
  99. package/dist/utils/mod.js +1 -1
  100. package/package.json +6 -6
  101. /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
  102. /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-B1fLHmg2.mjs} +0 -0
  103. /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-BGHm_MsT.mjs} +0 -0
  104. /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
  105. /package/dist/{negotiation-DDstyBvc.mjs → negotiation-DC8nG6J_.mjs} +0 -0
  106. /package/dist/{public-audience-Dp4ZScSr.mjs → public-audience-rnYUGj8a.mjs} +0 -0
  107. /package/dist/{retry-CXg_MBI-.mjs → retry-C4G_vIgv.mjs} +0 -0
  108. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.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.
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { getLogger } from "@logtape/logtape";
5
5
  import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
6
- import { openPublicFetch } from "@fedify/vocab-runtime/internal";
6
+ import { detectRuntime, lookupAllAddressesBounded, openPublicFetch } from "@fedify/vocab-runtime/internal";
7
7
  //#region src/utils/body.ts
8
8
  /** Decoded JSON body limit: 16 MiB. @internal */
9
9
  const MAX_BODY_SIZE = 16 * 1024 * 1024;
@@ -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,255 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
+ import "../std__assert-BjJn2daJ.mjs";
6
+ import { t as assertStrictEquals } from "../assert_strict_equals-XEgZAlrj.mjs";
7
+ import { t as normalizeAttachmentArrays } from "../attachment-arrays-BlfpZlWF.mjs";
8
+ import { test } from "@fedify/fixture";
9
+ import { preloadedContexts } from "@fedify/vocab-runtime";
10
+ //#region src/compat/attachment-arrays.test.ts
11
+ const AS = "https://www.w3.org/ns/activitystreams";
12
+ const SEC = "https://w3id.org/security#";
13
+ test("attachment arrays: singleton, multiple, nested and expanded properties", async () => {
14
+ const document = {
15
+ "@context": AS,
16
+ type: "Collection",
17
+ items: [
18
+ {
19
+ type: "Note",
20
+ attachment: {
21
+ type: "Image",
22
+ url: "https://example.com/a"
23
+ }
24
+ },
25
+ {
26
+ type: "Note",
27
+ attachment: ["https://example.com/b", "https://example.com/c"]
28
+ },
29
+ {
30
+ type: "Note",
31
+ attachment: null
32
+ },
33
+ {
34
+ type: "Note",
35
+ [`${AS}#attachment`]: "https://example.com/d"
36
+ }
37
+ ]
38
+ };
39
+ const before = structuredClone(document);
40
+ const result = await normalizeAttachmentArrays(document);
41
+ assertEquals(result, {
42
+ ...document,
43
+ items: [
44
+ {
45
+ type: "Note",
46
+ attachment: [document.items[0].attachment]
47
+ },
48
+ document.items[1],
49
+ document.items[2],
50
+ {
51
+ type: "Note",
52
+ [`${AS}#attachment`]: ["https://example.com/d"]
53
+ }
54
+ ]
55
+ });
56
+ assertEquals(document, before);
57
+ assertStrictEquals(await normalizeAttachmentArrays(result), result);
58
+ });
59
+ test("attachment arrays: preserve lists, contexts and value objects", async () => {
60
+ for (const document of [{
61
+ "@context": AS,
62
+ attachment: { "@list": ["https://example.com/a"] }
63
+ }, {
64
+ "@context": AS,
65
+ content: {
66
+ "@value": { attachment: 1 },
67
+ "@type": "@json"
68
+ }
69
+ }]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
70
+ });
71
+ test("attachment arrays: inline and remote contexts share one loader snapshot", async () => {
72
+ let loads = 0;
73
+ const loader = (url) => {
74
+ loads++;
75
+ return Promise.resolve({
76
+ documentUrl: url,
77
+ contextUrl: null,
78
+ document: preloadedContexts[AS]
79
+ });
80
+ };
81
+ const document = {
82
+ "@context": "https://example.com/context",
83
+ attachment: "https://example.com/a"
84
+ };
85
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
86
+ assertEquals(await normalizeAttachmentArrays(document, loader), {
87
+ ...document,
88
+ attachment: [document.attachment]
89
+ });
90
+ assertEquals(loads, 1);
91
+ const inline = {
92
+ "@context": [AS, {
93
+ schema: "http://schema.org/",
94
+ value: "schema:value"
95
+ }],
96
+ attachment: { type: "Image" }
97
+ };
98
+ assertEquals(await normalizeAttachmentArrays(inline), {
99
+ ...inline,
100
+ attachment: [inline.attachment]
101
+ });
102
+ });
103
+ test("attachment arrays: JSON literals and context redefinitions remain unchanged", async () => {
104
+ for (const document of [
105
+ {
106
+ "@context": [AS, { attachment: {
107
+ "@id": `${AS}#attachment`,
108
+ "@type": "@json"
109
+ } }],
110
+ attachment: { type: "Image" }
111
+ },
112
+ {
113
+ "@context": [AS, { payload: {
114
+ "@id": "https://example.com/payload",
115
+ "@type": "@json"
116
+ } }],
117
+ attachment: "https://example.com/a",
118
+ payload: { attachment: { proof: "literal" } }
119
+ },
120
+ {
121
+ "@context": [AS, "https://www.w3.org/ns/cid/v1"],
122
+ attachment: "https://example.com/a",
123
+ publicKeyJwk: { attachment: { type: "Image" } }
124
+ },
125
+ {
126
+ "@context": [
127
+ AS,
128
+ null,
129
+ {
130
+ "@vocab": "https://example.com/",
131
+ attachment: {
132
+ "@id": "https://example.com/attachment",
133
+ "@type": "@json"
134
+ }
135
+ }
136
+ ],
137
+ attachment: { type: "Image" }
138
+ }
139
+ ]) assertStrictEquals(await normalizeAttachmentArrays(document), document);
140
+ });
141
+ test("attachment arrays: language and index maps retain their semantics", async () => {
142
+ for (const container of ["@language", "@index"]) {
143
+ const document = {
144
+ "@context": [AS, { attachment: {
145
+ "@id": `${AS}#attachment`,
146
+ "@container": container
147
+ } }],
148
+ attachment: container === "@language" ? { en: "example" } : { sample: { type: "Image" } }
149
+ };
150
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
151
+ }
152
+ });
153
+ test("attachment arrays: scoped contexts cannot change literal payloads", async () => {
154
+ const document = {
155
+ "@context": [AS, { Special: {
156
+ "@id": "https://example.com/Special",
157
+ "@context": { attachment: {
158
+ "@id": `${AS}#attachment`,
159
+ "@type": "@json"
160
+ } }
161
+ } }],
162
+ type: "Special",
163
+ attachment: { type: "Image" }
164
+ };
165
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
166
+ });
167
+ test("attachment arrays: root proofs and signed siblings are immutable", async () => {
168
+ const signed = Object.freeze({
169
+ "@context": [AS, { proof: `${SEC}proof` }],
170
+ attachment: "https://example.com/a",
171
+ proof: Object.freeze({ id: "https://example.com/proof" })
172
+ });
173
+ assertStrictEquals(await normalizeAttachmentArrays(signed), signed);
174
+ const document = {
175
+ "@context": AS,
176
+ type: "Collection",
177
+ items: [signed, {
178
+ type: "Note",
179
+ attachment: "https://example.com/b"
180
+ }]
181
+ };
182
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
183
+ for (const proof of [[], [{ proofValue: "one" }, { proofValue: "two" }]]) {
184
+ const root = {
185
+ "@context": [AS, { proof: `${SEC}proof` }],
186
+ attachment: "https://example.com/a",
187
+ proof
188
+ };
189
+ assertStrictEquals(await normalizeAttachmentArrays(root), root);
190
+ }
191
+ });
192
+ test("attachment arrays: semantic proof aliases preserve the whole document", async () => {
193
+ for (const nested of [false, true]) {
194
+ const document = {
195
+ "@context": [AS, { seal: `${SEC}proof` }],
196
+ attachment: "https://example.com/a",
197
+ ...nested ? { object: { seal: { "@id": "https://example.com/proof" } } } : { seal: { "@id": "https://example.com/proof" } }
198
+ };
199
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
200
+ }
201
+ const literal = {
202
+ "@context": AS,
203
+ content: `<${SEC}proof>`,
204
+ attachment: "https://example.com/a"
205
+ };
206
+ assertEquals(await normalizeAttachmentArrays(literal), {
207
+ ...literal,
208
+ attachment: [literal.attachment]
209
+ });
210
+ });
211
+ test("attachment arrays: excessive depth and failing loaders preserve input", async () => {
212
+ let document = { attachment: "https://example.com/a" };
213
+ for (let i = 0; i < 70; i++) document = { object: document };
214
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
215
+ const custom = {
216
+ "@context": "https://example.com/unavailable",
217
+ attachment: "https://example.com/a"
218
+ };
219
+ assertStrictEquals(await normalizeAttachmentArrays(custom, () => Promise.reject(/* @__PURE__ */ new Error("unavailable"))), custom);
220
+ });
221
+ test("attachment arrays: context-coerced security-shaped JSON is ordinary data", async () => {
222
+ const data = { proof: { signature: "application data" } };
223
+ const document = {
224
+ "@context": [AS, { data: {
225
+ "@id": "https://example.com/data",
226
+ "@type": "@json"
227
+ } }],
228
+ attachment: "https://example.com/a",
229
+ data
230
+ };
231
+ assertEquals(await normalizeAttachmentArrays(document), {
232
+ ...document,
233
+ attachment: [document.attachment]
234
+ });
235
+ assertEquals(document.data, data);
236
+ let deep = { signature: "application data" };
237
+ for (let i = 0; i < 70; i++) deep = { child: deep };
238
+ const large = {
239
+ ...document,
240
+ data: deep
241
+ };
242
+ assertStrictEquals(await normalizeAttachmentArrays(large), large);
243
+ });
244
+ test("attachment arrays: root and nested semantic LD signatures block rewriting", async () => {
245
+ for (const nested of [false, true]) {
246
+ const document = {
247
+ "@context": [AS, { seal: `${SEC}signature` }],
248
+ attachment: "https://example.com/a",
249
+ ...nested ? { object: { seal: { "@id": "https://example.com/sig" } } } : { seal: { "@id": "https://example.com/sig" } }
250
+ };
251
+ assertStrictEquals(await normalizeAttachmentArrays(document), document);
252
+ }
253
+ });
254
+ //#endregion
255
+ export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { jt as ActivityTransformer, n as Context } from "../context-CE_Tj_Oc.cjs";
2
+ import { jt as ActivityTransformer, n as Context } from "../context-CEE8vl-b.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 { jt as ActivityTransformer, n as Context } from "../context-H_5tZXg-.js";
2
+ import { jt as ActivityTransformer, n as Context } from "../context-CTJwXHRu.js";
3
3
  import { Activity } from "@fedify/vocab";
4
4
 
5
5
  //#region src/compat/transformers.d.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { t as assertStrictEquals } from "../assert_strict_equals-XEgZAlrj.mjs";
6
- import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-D4iTv7uM.mjs";
6
+ import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-BZEAVK_Q.mjs";
7
7
  import { Create, Document, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
8
8
  import { mockDocumentLoader, test } from "@fedify/fixture";
9
9
  //#region src/compat/outgoing-jsonld.test.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { t as assertNotEquals } from "../assert_not_equals-DkVK8oqV.mjs";
6
- import { t as normalizePublicAudience } from "../public-audience-Dp4ZScSr.mjs";
6
+ import { t as normalizePublicAudience } from "../public-audience-rnYUGj8a.mjs";
7
7
  import { Create, Follow, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
8
8
  import { test } from "@fedify/fixture";
9
9
  import { getDocumentLoader, preloadedContexts } from "@fedify/vocab-runtime";
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { n as assertInstanceOf, t as assert } from "../assert-CEO06XCw.mjs";
6
6
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
7
- import { b as autoIdAssigner, n as FederationImpl, y as actorDehydrator } from "../middleware-Hr9ci9uD.mjs";
7
+ import { b as autoIdAssigner, n as FederationImpl, y as actorDehydrator } from "../middleware-D31fNcY4.mjs";
8
8
  import { Follow, Person } from "@fedify/vocab";
9
9
  import { test } from "@fedify/fixture";
10
10
  //#region src/compat/transformers.test.ts