@fedify/fedify 2.2.20 → 2.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/attachment-arrays-CalAATqD.mjs +16 -0
  2. package/dist/{builder-BolQ56ab.mjs → builder-4ImvtjG4.mjs} +3 -3
  3. package/dist/callback-0KrwzutD.d.mts +2607 -0
  4. package/dist/{client-jE7oGvRh.d.ts → client-9DPcy_Yx.d.ts} +16 -0
  5. package/dist/{client-BIBzqEIp.d.cts → client-B3ruDgWg.d.cts} +16 -0
  6. package/dist/{client-DhxaVgOv.mjs → client-XYMC0Mmk.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-CFQGaq5x.d.cts → context-CjWuov0g.d.cts} +31 -14
  15. package/dist/{context-DdbLVV_k.d.ts → context-DZqI2LJD.d.ts} +31 -14
  16. package/dist/{deno-BUj4roJc.mjs → deno-AWk3S2Ug.mjs} +1 -1
  17. package/dist/{docloader-CbtF_0cD.mjs → docloader-Bogpjg4d.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/collection.test.mjs +1 -1
  22. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  23. package/dist/federation/delivery-attachments.test.mjs +288 -0
  24. package/dist/federation/handler.test.mjs +208 -16
  25. package/dist/federation/idempotency.test.mjs +2 -2
  26. package/dist/federation/inbox.test.mjs +2 -2
  27. package/dist/federation/middleware.test.mjs +1184 -8
  28. package/dist/federation/mod.cjs +1 -1
  29. package/dist/federation/mod.d.cts +2 -2
  30. package/dist/federation/mod.d.ts +2 -2
  31. package/dist/federation/mod.js +1 -1
  32. package/dist/federation/negotiation.test.mjs +1 -1
  33. package/dist/federation/retry.test.mjs +1 -1
  34. package/dist/federation/send.test.mjs +283 -3
  35. package/dist/federation/temporal.test.mjs +25 -1
  36. package/dist/federation/webfinger.test.mjs +1 -1
  37. package/dist/{http-CQMVisM0.mjs → http-B3wCvgu8.mjs} +6 -4
  38. package/dist/{http-D8I7LBfx.cjs → http-BNaPJVnF.cjs} +6 -4
  39. package/dist/{http-C5g_VrA_.js → http-BpdLaGy8.js} +6 -4
  40. package/dist/{http-9IFUxdkp.d.cts → http-C8qLHs_Z.d.cts} +3 -3
  41. package/dist/{http-SbfezERn.d.ts → http-D8WmcRAF.d.ts} +3 -3
  42. package/dist/{inbox-CD8IDILN.mjs → inbox-DLy6WBXU.mjs} +1 -1
  43. package/dist/{key-C3o3DGap.mjs → key-Bhc8cQC7.mjs} +3 -2
  44. package/dist/{kv-cache-DC9LcfoC.cjs → kv-cache-Bj3CY9Jo.cjs} +1 -1
  45. package/dist/{kv-cache-CSKXXleR.js → kv-cache-CvjLUQTf.js} +1 -1
  46. package/dist/{ld-ijSr-0AB.mjs → ld-DTeykI0e.mjs} +153 -21
  47. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  48. package/dist/{middleware-DNueR0GD.cjs → middleware-BSQP4d9p.cjs} +475 -107
  49. package/dist/{middleware-DmcY2TWS.cjs → middleware-CWOzxb3o.cjs} +1 -1
  50. package/dist/{middleware-yqqfI7oJ.mjs → middleware-DkMsC5mQ.mjs} +1 -1
  51. package/dist/{middleware-sjhz30sm.js → middleware-Dx1iwFk8.js} +474 -107
  52. package/dist/{middleware-CYAaUTi5.mjs → middleware-dlGvSrXl.mjs} +386 -96
  53. package/dist/{mod-BYWp77-z.d.cts → mod-BmxqcEnU.d.ts} +30 -13
  54. package/dist/{mod-CVSKw-5H.d.cts → mod-DWEx2D4q.d.cts} +1 -1
  55. package/dist/{mod-BuRRdsfD.d.ts → mod-DnPmz3-S.d.ts} +1 -1
  56. package/dist/{mod-CM5_J_cx.d.ts → mod-INjDw-m0.d.cts} +30 -13
  57. package/dist/{mod-BRnwh2oy.d.ts → mod-REfljt0T.d.ts} +3 -3
  58. package/dist/{mod-Co7LEK9X.d.cts → mod-UvIGUHqW.d.cts} +3 -3
  59. package/dist/mod.cjs +5 -5
  60. package/dist/mod.d.cts +8 -8
  61. package/dist/mod.d.ts +8 -8
  62. package/dist/mod.js +5 -5
  63. package/dist/nodeinfo/client.test.mjs +432 -4
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/nodeinfo/mod.cjs +1 -1
  66. package/dist/nodeinfo/mod.d.cts +1 -1
  67. package/dist/nodeinfo/mod.d.ts +1 -1
  68. package/dist/nodeinfo/mod.js +1 -1
  69. package/dist/nodeinfo/types.test.mjs +1 -1
  70. package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
  71. package/dist/{owner-B8kXzD0q.mjs → owner-BsA7qMHB.mjs} +2 -2
  72. package/dist/{proof-CBQOjOgA.mjs → proof-C63Hqt9N.mjs} +40 -15
  73. package/dist/{proof-qiuGJCD7.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
  74. package/dist/{proof-DKX6nASL.js → proof-QV_o5ZqS.js} +1174 -1003
  75. package/dist/{send-DRpisX_f.mjs → send-CAdpwbFX.mjs} +92 -21
  76. package/dist/sig/http.test.mjs +2 -2
  77. package/dist/sig/key-types.test.d.mts +218 -0
  78. package/dist/sig/key-types.test.mjs +8 -0
  79. package/dist/sig/key.test.mjs +2 -2
  80. package/dist/sig/ld.test.mjs +573 -8
  81. package/dist/sig/mod.cjs +2 -2
  82. package/dist/sig/mod.d.cts +3 -3
  83. package/dist/sig/mod.d.ts +3 -3
  84. package/dist/sig/mod.js +2 -2
  85. package/dist/sig/owner.test.mjs +1 -1
  86. package/dist/sig/proof.test.mjs +96 -4
  87. package/dist/{temporal-BQGEINad.mjs → temporal-B3JGkVgk.mjs} +3 -5
  88. package/dist/testing/mod.d.mts +2 -2422
  89. package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
  90. package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
  91. package/dist/utils/docloader.test.mjs +2 -2
  92. package/dist/utils/mod.cjs +1 -1
  93. package/dist/utils/mod.d.cts +1 -1
  94. package/dist/utils/mod.d.ts +1 -1
  95. package/dist/utils/mod.js +1 -1
  96. package/package.json +5 -5
  97. /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  98. /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
  99. /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
  100. /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
  101. /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
  102. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -5,11 +5,15 @@ import { t as esm_default } from "../esm-DVILvP5e.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
6
  import "../std__assert-DNZ4Liil.mjs";
7
7
  import { n as assertInstanceOf } from "../assert-BhQd8QHP.mjs";
8
- import { a as parseOutboundService, c as parseSoftware, i as parseNodeInfo, l as parseUsage, n as getNodeInfoInternal, o as parseProtocol, r as parseInboundService, s as parseServices, t as getNodeInfo } from "../client-DhxaVgOv.mjs";
8
+ import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
9
+ import { t as assertStrictEquals } from "../assert_strict_equals-Dmjbg-bA.mjs";
10
+ import { a as parseOutboundService, c as parseSoftware, i as parseNodeInfo, l as parseUsage, n as getNodeInfoInternal, o as parseProtocol, r as parseInboundService, s as parseServices, t as getNodeInfo } from "../client-XYMC0Mmk.mjs";
9
11
  import { test } from "@fedify/fixture";
10
12
  import { UrlError } from "@fedify/vocab-runtime";
11
- import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
13
+ import { detectRuntime, openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
12
14
  import { configure, reset } from "@logtape/logtape";
15
+ import dns from "node:dns/promises";
16
+ import { createServer } from "node:http";
13
17
  //#region src/nodeinfo/client.test.ts
14
18
  function getNodeInfoDirect(url, options) {
15
19
  return getNodeInfoInternal(url, options, { openHop: openDirectFetch });
@@ -1049,6 +1053,64 @@ test("getNodeInfo() logs DNS failures as such", async (t) => {
1049
1053
  }
1050
1054
  });
1051
1055
  });
1056
+ test("getNodeInfo() bounds and cancels default Node.js DNS lookups", { ignore: detectRuntime() !== "node" }, async () => {
1057
+ const originalLookup = dns.lookup;
1058
+ const pending = [];
1059
+ const hostnames = [];
1060
+ const twoStarted = deferred();
1061
+ const records = [];
1062
+ dns.lookup = ((hostname) => {
1063
+ hostnames.push(hostname);
1064
+ const lookup = deferred();
1065
+ pending.push(lookup);
1066
+ if (hostnames.length === 2) twoStarted.resolve();
1067
+ return lookup.promise;
1068
+ });
1069
+ try {
1070
+ await configure({
1071
+ sinks: { buffer: (record) => records.push(record) },
1072
+ loggers: [{
1073
+ category: "fedify",
1074
+ sinks: ["buffer"],
1075
+ lowestLevel: "debug"
1076
+ }, {
1077
+ category: ["logtape", "meta"],
1078
+ sinks: []
1079
+ }],
1080
+ reset: true
1081
+ });
1082
+ const first = getNodeInfo("https://first.example/nodeinfo", {
1083
+ direct: true,
1084
+ timeout: 50
1085
+ });
1086
+ const second = getNodeInfo("https://second.example/nodeinfo", {
1087
+ direct: true,
1088
+ timeout: 50
1089
+ });
1090
+ await settleWithin(twoStarted.promise, 1e3);
1091
+ assertEquals(await settleWithin(getNodeInfo("https://third.example/nodeinfo", {
1092
+ direct: true,
1093
+ timeout: 20
1094
+ }), 1e3), void 0);
1095
+ assertEquals(await settleWithin(first, 1e3), void 0);
1096
+ assertEquals(await settleWithin(second, 1e3), void 0);
1097
+ assertEquals(hostnames, ["first.example", "second.example"]);
1098
+ for (const lookup of pending) lookup.resolve([{
1099
+ address: "93.184.215.14",
1100
+ family: 4
1101
+ }]);
1102
+ await new Promise((resolve) => setTimeout(resolve, 0));
1103
+ assertEquals(hostnames, ["first.example", "second.example"]);
1104
+ assertEquals(records.some((record) => String(record.rawMessage).includes("DNS lookup failed")), false);
1105
+ } finally {
1106
+ dns.lookup = originalLookup;
1107
+ for (const lookup of pending) lookup.resolve([{
1108
+ address: "93.184.215.14",
1109
+ family: 4
1110
+ }]);
1111
+ await reset();
1112
+ }
1113
+ });
1052
1114
  function recordHops(respond) {
1053
1115
  const events = [];
1054
1116
  const unsettled = [];
@@ -1116,6 +1178,347 @@ function recordHops(respond) {
1116
1178
  }
1117
1179
  };
1118
1180
  }
1181
+ function deferred() {
1182
+ let resolve;
1183
+ return {
1184
+ promise: new Promise((done) => resolve = done),
1185
+ resolve
1186
+ };
1187
+ }
1188
+ function waitForAbort(signal) {
1189
+ return new Promise((_, reject) => {
1190
+ if (signal?.aborted) {
1191
+ reject(signal.reason);
1192
+ return;
1193
+ }
1194
+ signal?.addEventListener("abort", () => reject(signal.reason), { once: true });
1195
+ });
1196
+ }
1197
+ test("getNodeInfo() times out while waiting for response headers", async () => {
1198
+ const closed = deferred();
1199
+ let fetches = 0;
1200
+ let closes = 0;
1201
+ let signal;
1202
+ const records = [];
1203
+ await configure({
1204
+ sinks: { buffer: (record) => records.push(record) },
1205
+ loggers: [{
1206
+ category: "fedify",
1207
+ sinks: ["buffer"],
1208
+ lowestLevel: "debug"
1209
+ }, {
1210
+ category: ["logtape", "meta"],
1211
+ sinks: []
1212
+ }],
1213
+ reset: true
1214
+ });
1215
+ try {
1216
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1217
+ direct: true,
1218
+ timeout: 30
1219
+ }, { openHop: async (url, hopSignal) => {
1220
+ signal = hopSignal;
1221
+ return {
1222
+ url: new URL(url),
1223
+ fetch(_input, init) {
1224
+ fetches++;
1225
+ assertEquals(init?.signal, hopSignal);
1226
+ return waitForAbort(init?.signal);
1227
+ },
1228
+ async close() {
1229
+ closes++;
1230
+ closed.resolve();
1231
+ }
1232
+ };
1233
+ } }), 1e3), void 0);
1234
+ await settleWithin(closed.promise, 1e3);
1235
+ assertEquals(fetches, 1);
1236
+ assertEquals(closes, 1);
1237
+ assertEquals(signal?.aborted, true);
1238
+ assertEquals(records.filter((record) => record.level === "error").length, 1);
1239
+ await new Promise((resolve) => setTimeout(resolve, 0));
1240
+ assertEquals(records.filter((record) => record.level === "error").length, 1);
1241
+ } finally {
1242
+ await reset();
1243
+ }
1244
+ });
1245
+ test("getNodeInfo() times out while a small response body stalls", async () => {
1246
+ const closed = deferred();
1247
+ let bodyCancelled = false;
1248
+ let signal;
1249
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1250
+ direct: true,
1251
+ timeout: 30
1252
+ }, { async openHop(url, hopSignal) {
1253
+ signal = hopSignal;
1254
+ return {
1255
+ url: new URL(url),
1256
+ async fetch(_input, init) {
1257
+ assertEquals(init?.signal, hopSignal);
1258
+ return new Response(new ReadableStream({
1259
+ start(controller) {
1260
+ controller.enqueue(new TextEncoder().encode("{\"software\":"));
1261
+ },
1262
+ cancel() {
1263
+ bodyCancelled = true;
1264
+ }
1265
+ }));
1266
+ },
1267
+ async close() {
1268
+ closed.resolve();
1269
+ }
1270
+ };
1271
+ } }), 1e3), void 0);
1272
+ await settleWithin(closed.promise, 1e3);
1273
+ assertEquals(signal?.aborted, true);
1274
+ assertEquals(bodyCancelled, true);
1275
+ });
1276
+ test({
1277
+ name: "getNodeInfo() aborts stalled HTTP responses",
1278
+ ignore: "navigator" in globalThis && navigator.userAgent === "Cloudflare-Workers" || "Deno" in globalThis && (await Deno.permissions.query({ name: "net" })).state !== "granted",
1279
+ async fn(t) {
1280
+ for (const stage of ["headers", "body"]) await t.step(stage, async () => {
1281
+ const disconnected = deferred();
1282
+ const server = createServer((request, response) => {
1283
+ response.on("close", () => disconnected.resolve());
1284
+ request.socket.on("close", () => disconnected.resolve());
1285
+ if (stage === "body") {
1286
+ response.writeHead(200, { "Content-Type": "application/json" });
1287
+ response.write("{\"software\":");
1288
+ }
1289
+ });
1290
+ try {
1291
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
1292
+ const address = server.address();
1293
+ if (address == null || typeof address === "string") throw new Error("Expected a TCP server address.");
1294
+ assertEquals(await settleWithin(getNodeInfoInternal(`http://127.0.0.1:${address.port}/nodeinfo`, {
1295
+ direct: true,
1296
+ timeout: 200
1297
+ }, { openHop: openDirectFetch }), 2e3).catch((error) => {
1298
+ throw new Error(`${stage} lookup did not finish`, { cause: error });
1299
+ }), void 0);
1300
+ await settleWithin(disconnected.promise, 2e3).catch((error) => {
1301
+ throw new Error(`${stage} connection did not close`, { cause: error });
1302
+ });
1303
+ } finally {
1304
+ server.closeAllConnections();
1305
+ await new Promise((resolve) => server.close(() => resolve()));
1306
+ }
1307
+ });
1308
+ }
1309
+ });
1310
+ test("getNodeInfo() shares one timeout across discovery and document", async () => {
1311
+ const documentRequested = deferred();
1312
+ const documentClosed = deferred();
1313
+ let discoverySignal;
1314
+ let documentSignal;
1315
+ const descriptor = JSON.stringify({ links: [{
1316
+ rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
1317
+ href: "https://example.com/nodeinfo/2.1"
1318
+ }] });
1319
+ const result = getNodeInfoInternal("https://example.com/", { timeout: 200 }, { async openHop(url) {
1320
+ const isDocument = url.endsWith("/nodeinfo/2.1");
1321
+ return {
1322
+ url: new URL(url),
1323
+ async fetch(_input, init) {
1324
+ if (isDocument) {
1325
+ documentSignal = init?.signal ?? void 0;
1326
+ documentRequested.resolve();
1327
+ return await waitForAbort(init?.signal);
1328
+ }
1329
+ discoverySignal = init?.signal ?? void 0;
1330
+ return new Response(descriptor);
1331
+ },
1332
+ async close() {
1333
+ if (isDocument) documentClosed.resolve();
1334
+ }
1335
+ };
1336
+ } });
1337
+ await settleWithin(documentRequested.promise, 1e3);
1338
+ assertStrictEquals(documentSignal, discoverySignal);
1339
+ assertEquals(await settleWithin(result, 1e3), void 0);
1340
+ await settleWithin(documentClosed.promise, 1e3);
1341
+ assertEquals(discoverySignal?.aborted, true);
1342
+ });
1343
+ test("getNodeInfo() honors caller cancellation without a timeout", async () => {
1344
+ const caller = new AbortController();
1345
+ const closed = deferred();
1346
+ let requestSignal;
1347
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1348
+ direct: true,
1349
+ timeout: null,
1350
+ signal: caller.signal
1351
+ }, { async openHop(url, signal) {
1352
+ requestSignal = signal;
1353
+ return {
1354
+ url: new URL(url),
1355
+ fetch(_input, init) {
1356
+ assertStrictEquals(init?.signal, signal);
1357
+ caller.abort(/* @__PURE__ */ new Error("Caller stopped waiting"));
1358
+ return waitForAbort(init?.signal);
1359
+ },
1360
+ async close() {
1361
+ closed.resolve();
1362
+ }
1363
+ };
1364
+ } }), 1e3), void 0);
1365
+ await settleWithin(closed.promise, 1e3);
1366
+ assertEquals(requestSignal?.aborted, true);
1367
+ });
1368
+ test("getNodeInfo() stops before fetching when caller already aborted", async () => {
1369
+ const caller = new AbortController();
1370
+ caller.abort();
1371
+ let opened = false;
1372
+ assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
1373
+ direct: true,
1374
+ signal: caller.signal
1375
+ }, { async openHop() {
1376
+ opened = true;
1377
+ throw new Error("Unexpected fetch");
1378
+ } }), void 0);
1379
+ assertEquals(opened, false);
1380
+ });
1381
+ test("getNodeInfo() closes a session opened just after its timeout", async () => {
1382
+ const closed = deferred();
1383
+ let fetches = 0;
1384
+ let closes = 0;
1385
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1386
+ direct: true,
1387
+ timeout: 25
1388
+ }, { async openHop(url) {
1389
+ await new Promise((resolve) => setTimeout(resolve, 55));
1390
+ return {
1391
+ url: new URL(url),
1392
+ async fetch() {
1393
+ fetches++;
1394
+ return Response.json({ software: {
1395
+ name: "x",
1396
+ version: "1"
1397
+ } });
1398
+ },
1399
+ async close() {
1400
+ closes++;
1401
+ closed.resolve();
1402
+ }
1403
+ };
1404
+ } }), 1e3), void 0);
1405
+ await settleWithin(closed.promise, 1e3);
1406
+ assertEquals(fetches, 0);
1407
+ assertEquals(closes, 1);
1408
+ });
1409
+ test("getNodeInfo() does not log a late DNS failure as another error", async () => {
1410
+ const records = [];
1411
+ const finished = deferred();
1412
+ await configure({
1413
+ sinks: { buffer: (record) => records.push(record) },
1414
+ loggers: [{
1415
+ category: "fedify",
1416
+ sinks: ["buffer"],
1417
+ lowestLevel: "debug"
1418
+ }, {
1419
+ category: ["logtape", "meta"],
1420
+ sinks: []
1421
+ }],
1422
+ reset: true
1423
+ });
1424
+ try {
1425
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1426
+ direct: true,
1427
+ timeout: 25
1428
+ }, { async openHop() {
1429
+ try {
1430
+ await new Promise((resolve) => setTimeout(resolve, 55));
1431
+ throw new UrlError("DNS lookup failed", { reason: "dns" });
1432
+ } finally {
1433
+ finished.resolve();
1434
+ }
1435
+ } }), 1e3), void 0);
1436
+ await settleWithin(finished.promise, 1e3);
1437
+ await new Promise((resolve) => setTimeout(resolve, 0));
1438
+ assertEquals(records.filter((record) => record.level === "error").length, 1);
1439
+ } finally {
1440
+ await reset();
1441
+ }
1442
+ });
1443
+ test("getNodeInfo() cancels a response returned after timeout", async () => {
1444
+ const closed = deferred();
1445
+ let bodyCancelled = false;
1446
+ let closes = 0;
1447
+ assertEquals(await settleWithin(getNodeInfoInternal("https://example.com/nodeinfo", {
1448
+ direct: true,
1449
+ timeout: 25
1450
+ }, { async openHop(url) {
1451
+ return {
1452
+ url: new URL(url),
1453
+ async fetch() {
1454
+ await new Promise((resolve) => setTimeout(resolve, 55));
1455
+ return new Response(new ReadableStream({ cancel() {
1456
+ bodyCancelled = true;
1457
+ } }));
1458
+ },
1459
+ async close() {
1460
+ closes++;
1461
+ closed.resolve();
1462
+ }
1463
+ };
1464
+ } }), 1e3), void 0);
1465
+ await settleWithin(closed.promise, 1e3);
1466
+ assertEquals(closes, 1);
1467
+ assertEquals(bodyCancelled, true);
1468
+ });
1469
+ test("getNodeInfo() validates its timeout", async () => {
1470
+ for (const timeout of [
1471
+ 0,
1472
+ -1,
1473
+ NaN,
1474
+ Infinity,
1475
+ 2147483648
1476
+ ]) await assertRejects(() => getNodeInfoInternal("https://example.com/", { timeout }), RangeError);
1477
+ });
1478
+ test("getNodeInfo() can disable its timeout", async () => {
1479
+ const value = { software: {
1480
+ name: "x",
1481
+ version: "1"
1482
+ } };
1483
+ assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
1484
+ direct: true,
1485
+ parse: "none",
1486
+ timeout: null
1487
+ }, { async openHop(url, signal) {
1488
+ assertEquals(signal, void 0);
1489
+ return {
1490
+ url: new URL(url),
1491
+ async fetch(_input, init) {
1492
+ assertEquals(init?.signal, void 0);
1493
+ return Response.json(value);
1494
+ },
1495
+ async close() {}
1496
+ };
1497
+ } }), value);
1498
+ });
1499
+ test("getNodeInfo() clears its timer after a successful fetch", async () => {
1500
+ let signal;
1501
+ const value = { software: {
1502
+ name: "x",
1503
+ version: "1"
1504
+ } };
1505
+ assertEquals(await getNodeInfoInternal("https://example.com/nodeinfo", {
1506
+ direct: true,
1507
+ parse: "none",
1508
+ timeout: 100
1509
+ }, { async openHop(url, hopSignal) {
1510
+ signal = hopSignal;
1511
+ return {
1512
+ url: new URL(url),
1513
+ async fetch() {
1514
+ return Response.json(value);
1515
+ },
1516
+ async close() {}
1517
+ };
1518
+ } }), value);
1519
+ await new Promise((resolve) => setTimeout(resolve, 120));
1520
+ assertEquals(signal?.aborted, false);
1521
+ });
1119
1522
  test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
1120
1523
  const wellKnown = "https://example.com/.well-known/nodeinfo";
1121
1524
  const wellKnown2 = "https://example.com/.well-known/nodeinfo2";
@@ -1186,9 +1589,9 @@ test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
1186
1589
  recorder.assertInvariants();
1187
1590
  });
1188
1591
  await t.step("too many redirections", async () => {
1189
- const recorder = recordHops(() => ({
1592
+ const recorder = recordHops((url) => ({
1190
1593
  status: 302,
1191
- headers: { Location: "/.well-known/nodeinfo" },
1594
+ headers: { Location: `?hop=${Number(url.searchParams.get("hop") ?? 0) + 1}` },
1192
1595
  body: "redirecting"
1193
1596
  }));
1194
1597
  assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
@@ -1196,6 +1599,31 @@ test("getNodeInfo() closes each hop after cleaning up its body", async (t) => {
1196
1599
  assertEquals(recorder.events.filter((e) => e.startsWith("cancel ")).length, 5);
1197
1600
  recorder.assertInvariants();
1198
1601
  });
1602
+ await t.step("self-redirect cycle", async () => {
1603
+ const recorder = recordHops(() => ({
1604
+ status: 302,
1605
+ headers: { Location: "/.well-known/nodeinfo#another-fragment" },
1606
+ body: "redirecting"
1607
+ }));
1608
+ assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1609
+ assertEquals(recorder.events, [
1610
+ `open ${wellKnown}`,
1611
+ `fetch ${wellKnown} #1`,
1612
+ "cancel #1",
1613
+ `close ${wellKnown}`
1614
+ ]);
1615
+ recorder.assertInvariants();
1616
+ });
1617
+ await t.step("two-URL redirect cycle", async () => {
1618
+ const recorder = recordHops((url) => ({
1619
+ status: 302,
1620
+ headers: { Location: url.href === wellKnown ? "/.well-known/nodeinfo2" : "/.well-known/nodeinfo" },
1621
+ body: "redirecting"
1622
+ }));
1623
+ assertEquals(await getNodeInfoInternal("https://example.com/", {}, { openHop: recorder.openHop }), void 0);
1624
+ assertEquals(recorder.events.filter((e) => e.startsWith("open ")), [`open ${wellKnown}`, `open ${wellKnown2}`]);
1625
+ recorder.assertInvariants();
1626
+ });
1199
1627
  await t.step("failed redirect body cancellation", async () => {
1200
1628
  const recorder = recordHops((url) => {
1201
1629
  switch (url.href) {
@@ -5,7 +5,7 @@ import { r as createRequestContext } from "../context-Dk_tacqz.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
6
  import "../std__assert-DNZ4Liil.mjs";
7
7
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
8
- import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-CYAaUTi5.mjs";
8
+ import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-dlGvSrXl.mjs";
9
9
  import { test } from "@fedify/fixture";
10
10
  //#region src/nodeinfo/handler.test.ts
11
11
  test("handleNodeInfo()", async () => {
@@ -1,7 +1,7 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const require_types = require("../types-DOvyymM4.cjs");
4
+ const require_types = require("../types-BWx7zw3Y.cjs");
5
5
  exports.getNodeInfo = require_types.getNodeInfo;
6
6
  exports.nodeInfoToJson = require_types.nodeInfoToJson;
7
7
  exports.parseNodeInfo = require_types.parseNodeInfo;
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-BIBzqEIp.cjs";
2
+ import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-B3ruDgWg.cjs";
3
3
  export { type GetNodeInfoOptions, InboundService, JsonValue, NodeInfo, OutboundService, type ParseNodeInfoOptions, Protocol, Services, Software, Usage, getNodeInfo, nodeInfoToJson, parseNodeInfo };
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-jE7oGvRh.js";
2
+ import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "../client-9DPcy_Yx.js";
3
3
  export { type GetNodeInfoOptions, InboundService, JsonValue, NodeInfo, OutboundService, type ParseNodeInfoOptions, Protocol, Services, Software, Usage, getNodeInfo, nodeInfoToJson, parseNodeInfo };
@@ -1,4 +1,4 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-B1_pRFE_.js";
3
+ import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "../types-Dx_w2JSM.js";
4
4
  export { getNodeInfo, nodeInfoToJson, parseNodeInfo };
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import "../std__assert-DNZ4Liil.mjs";
6
6
  import { t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
7
- import { t as nodeInfoToJson } from "../types-J53Kw7so.mjs";
7
+ import { t as nodeInfoToJson } from "../types-BFowWFTT.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/nodeinfo/types.test.ts
10
10
  test("nodeInfoToJson()", () => {
@@ -1,7 +1,7 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as preloadedOnlyDocumentLoader, t as normalizePublicAudience } from "./public-audience-DpJqzPuh.mjs";
4
+ import { n as preloadedOnlyDocumentLoader, t as normalizePublicAudience } from "./public-audience-4g3_Ze4y.mjs";
5
5
  import { preloadedContexts } from "@fedify/vocab-runtime";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import jsonld from "@fedify/vocab-runtime/jsonld";
@@ -166,38 +166,68 @@ function getLogSafeJsonLdMetadata(jsonLd) {
166
166
  * the semantic-preservation check to succeed; otherwise canonicalization
167
167
  * failures leave the original document unchanged.
168
168
  */
169
- async function normalizeAttachmentArrays(jsonLd, contextLoader) {
169
+ async function normalizeAttachmentArrays(jsonLd, contextLoader, preserveSecured = false) {
170
170
  const normalized = wrapScalarAttachments(jsonLd);
171
171
  if (normalized === jsonLd) return jsonLd;
172
172
  if (exceedsTraversalDepth(jsonLd)) {
173
173
  logger.debug("Skipping attachment array normalization because the JSON-LD document exceeds the safe traversal depth; leaving it unchanged.");
174
174
  return jsonLd;
175
175
  }
176
- if (hasKnownSafeContext(jsonLd)) return normalized;
177
- const loader = contextLoader ?? preloadedOnlyDocumentLoader;
176
+ const sourceLoader = contextLoader ?? preloadedOnlyDocumentLoader;
177
+ const pending = /* @__PURE__ */ new Map();
178
+ const loader = (url, options) => {
179
+ let result = pending.get(url);
180
+ if (result == null) {
181
+ result = sourceLoader(url, options);
182
+ pending.set(url, result);
183
+ }
184
+ return result;
185
+ };
178
186
  try {
179
- const [before, after] = await Promise.all([jsonld.canonize(jsonLd, {
187
+ if (preserveSecured) {
188
+ if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: loader }))) return jsonLd;
189
+ }
190
+ if (!preserveSecured && hasKnownSafeContext(jsonLd)) return normalized;
191
+ const [before, after] = await Promise.allSettled([jsonld.canonize(jsonLd, {
180
192
  format: "application/n-quads",
181
193
  documentLoader: loader
182
194
  }), jsonld.canonize(normalized, {
183
195
  format: "application/n-quads",
184
196
  documentLoader: loader
185
197
  })]);
186
- if (before === after) return normalized;
198
+ if (before.status === "rejected") throw before.reason;
199
+ if (after.status === "rejected") throw after.reason;
200
+ if (before.value === after.value) return normalized;
187
201
  logger.warn("Wrapping scalar attachment values in arrays would change the canonical form of the JSON-LD document; leaving it unchanged. This usually means the active JSON-LD context redefines the `attachment` term. Document: {id}; type: {type}; context: {context}.", getLogSafeJsonLdMetadata(jsonLd));
188
202
  } catch (error) {
189
203
  logger.debug("Failed to verify attachment array normalization equivalence via JSON-LD canonicalization; leaving the JSON-LD document unchanged.\n{error}", { error });
190
204
  }
191
205
  return jsonLd;
192
206
  }
207
+ function hasSecurityPredicate(value) {
208
+ if (Array.isArray(value)) return value.some(hasSecurityPredicate);
209
+ if (typeof value !== "object" || value == null) return false;
210
+ const record = value;
211
+ if (Object.hasOwn(record, "@value")) return false;
212
+ for (const [key, child] of Object.entries(record)) {
213
+ if (key === "https://w3id.org/security#proof" || key === "https://w3id.org/security#signature") return true;
214
+ if (hasSecurityPredicate(child)) return true;
215
+ }
216
+ return false;
217
+ }
193
218
  /**
194
219
  * Applies Fedify's internal JSON-LD wire-format interoperability workarounds
195
220
  * to locally generated outgoing activities before they are signed, enqueued,
196
221
  * or sent.
197
222
  */
198
- async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader) {
223
+ async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, preserveSecured = false) {
224
+ if (preserveSecured) try {
225
+ if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: contextLoader ?? preloadedOnlyDocumentLoader }))) return jsonLd;
226
+ } catch {
227
+ return jsonLd;
228
+ }
199
229
  jsonLd = await normalizePublicAudience(jsonLd, contextLoader);
200
- return await normalizeAttachmentArrays(jsonLd, contextLoader);
230
+ return await normalizeAttachmentArrays(jsonLd, contextLoader, preserveSecured);
201
231
  }
202
232
  //#endregion
203
233
  export { normalizeAttachmentArrays as n, normalizeOutgoingActivityJsonLd as r, isPreloadedContextAttachmentSafe as t };
@@ -1,8 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-BUj4roJc.mjs";
5
- import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-C3o3DGap.mjs";
4
+ import { n as version, t as name } from "./deno-AWk3S2Ug.mjs";
5
+ import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-Bhc8cQC7.mjs";
6
6
  import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
7
7
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
8
8
  import { getDocumentLoader } from "@fedify/vocab-runtime";