@fedify/fedify 2.0.36-dev.2779 → 2.0.36-dev.2842
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.
- package/dist/{builder-UXDfZSno.mjs → builder-CuQLFOSj.mjs} +3 -3
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{deno-Bwn7hAXr.mjs → deno-USvfGHbR.mjs} +1 -1
- package/dist/{docloader-DSQXpyiJ.mjs → docloader-CDITXM6j.mjs} +2 -2
- package/dist/federation/attachment-responses.test.mjs +2 -2
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +6 -6
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +7 -7
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/federation/send.test.mjs +283 -3
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-aVfiO4CG.cjs → http-BAhackOL.cjs} +1 -1
- package/dist/{http-DuIId6ul.mjs → http-BGjEnY4L.mjs} +2 -2
- package/dist/{http-C-P8JP1h.js → http-ixT5PjBz.js} +1 -1
- package/dist/{inbox-Cq4_-nPi.mjs → inbox-BtfUJZS3.mjs} +1 -1
- package/dist/{key-BMJlknME.mjs → key-BDisDFGv.mjs} +1 -1
- package/dist/{kv-cache-C6BYEp2D.cjs → kv-cache-BKEuedCv.cjs} +1 -1
- package/dist/{kv-cache-PAsTBkxX.js → kv-cache-YdAhdrrh.js} +1 -1
- package/dist/{ld-oemavcUi.mjs → ld-CjHkfxXf.mjs} +2 -2
- package/dist/{middleware-CjwdngG9.cjs → middleware-DjXy4YoB.cjs} +94 -23
- package/dist/{middleware-D8Hh8RSu.mjs → middleware-DkrLbSc2.mjs} +11 -11
- package/dist/{middleware-sDUMisQG.cjs → middleware-HI6aNn_6.cjs} +1 -1
- package/dist/{middleware-BSMUxoX2.js → middleware-X7A94J2d.js} +93 -22
- package/dist/{middleware-Bw59VTh0.mjs → middleware-gr2ldCQw.mjs} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/{owner-CYTWux20.mjs → owner-CyoKKXIR.mjs} +2 -2
- package/dist/{proof-DXp_5fqW.cjs → proof-BOemJGRl.cjs} +1 -1
- package/dist/{proof-DWny6g-g.js → proof-BiTmCpLq.js} +1 -1
- package/dist/{proof-B7pdOJb5.mjs → proof-D8S0HFxt.mjs} +2 -2
- package/dist/{send-7rTXYfE8.mjs → send-speW4h59.mjs} +92 -21
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +2 -2
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +2 -2
- package/dist/{temporal-CxaXuWOi.mjs → temporal-Dlbq-g7z.mjs} +1 -1
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +5 -5
|
@@ -2,10 +2,10 @@ const { Temporal } = require("@js-temporal/polyfill");
|
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
const require_chunk = require("./chunk-DDcVe30Y.cjs");
|
|
4
4
|
const require_transformers = require("./transformers-NeAONrAq.cjs");
|
|
5
|
-
const require_http = require("./http-
|
|
5
|
+
const require_http = require("./http-BAhackOL.cjs");
|
|
6
6
|
const require_types = require("./types-DOvyymM4.cjs");
|
|
7
|
-
const require_proof = require("./proof-
|
|
8
|
-
const require_kv_cache = require("./kv-cache-
|
|
7
|
+
const require_proof = require("./proof-BOemJGRl.cjs");
|
|
8
|
+
const require_kv_cache = require("./kv-cache-BKEuedCv.cjs");
|
|
9
9
|
let _logtape_logtape = require("@logtape/logtape");
|
|
10
10
|
let _fedify_vocab = require("@fedify/vocab");
|
|
11
11
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
@@ -353,7 +353,7 @@ var FederationBuilderImpl = class {
|
|
|
353
353
|
this.collectionTypeIds = {};
|
|
354
354
|
}
|
|
355
355
|
async build(options) {
|
|
356
|
-
const { FederationImpl } = await Promise.resolve().then(() => require("./middleware-
|
|
356
|
+
const { FederationImpl } = await Promise.resolve().then(() => require("./middleware-HI6aNn_6.cjs"));
|
|
357
357
|
const f = new FederationImpl(options);
|
|
358
358
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
|
359
359
|
f.router = this.router.clone();
|
|
@@ -2473,7 +2473,8 @@ function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
|
|
2473
2473
|
* @param parameters The parameters for sending the activity.
|
|
2474
2474
|
* See also {@link SendActivityParameters}.
|
|
2475
2475
|
* @param deps The dependencies, for tests.
|
|
2476
|
-
* @throws {
|
|
2476
|
+
* @throws {FetchError} If the delivery times out before receiving a response.
|
|
2477
|
+
* @throws {SendActivityError} If the inbox returns an unsuccessful response.
|
|
2477
2478
|
*/
|
|
2478
2479
|
function sendActivity(options, deps = {}) {
|
|
2479
2480
|
const tracerProvider = options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
|
|
@@ -2500,7 +2501,25 @@ function sendActivity(options, deps = {}) {
|
|
|
2500
2501
|
});
|
|
2501
2502
|
}
|
|
2502
2503
|
const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
|
|
2503
|
-
|
|
2504
|
+
const SEND_ACTIVITY_TIMEOUT_MS = 3e4;
|
|
2505
|
+
function raceWithAbort(promise, signal) {
|
|
2506
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
2507
|
+
return new Promise((resolve, reject) => {
|
|
2508
|
+
const onAbort = () => {
|
|
2509
|
+
signal.removeEventListener("abort", onAbort);
|
|
2510
|
+
reject(signal.reason);
|
|
2511
|
+
};
|
|
2512
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2513
|
+
promise.then((value) => {
|
|
2514
|
+
signal.removeEventListener("abort", onAbort);
|
|
2515
|
+
resolve(value);
|
|
2516
|
+
}, (error) => {
|
|
2517
|
+
signal.removeEventListener("abort", onAbort);
|
|
2518
|
+
reject(error);
|
|
2519
|
+
});
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
async function readLimitedResponseBody(response, maxBytes, signal) {
|
|
2504
2523
|
if (response.body == null) return "";
|
|
2505
2524
|
const reader = response.body.getReader();
|
|
2506
2525
|
const decoder = new TextDecoder();
|
|
@@ -2509,7 +2528,8 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
2509
2528
|
let truncated = false;
|
|
2510
2529
|
try {
|
|
2511
2530
|
while (true) {
|
|
2512
|
-
|
|
2531
|
+
signal.throwIfAborted();
|
|
2532
|
+
const { done, value } = await raceWithAbort(reader.read(), signal);
|
|
2513
2533
|
if (done) break;
|
|
2514
2534
|
if (totalBytes + value.length > maxBytes) {
|
|
2515
2535
|
const remaining = maxBytes - totalBytes;
|
|
@@ -2521,8 +2541,10 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
2521
2541
|
totalBytes += value.length;
|
|
2522
2542
|
}
|
|
2523
2543
|
} finally {
|
|
2524
|
-
if (truncated) reader.cancel().catch(() => {});
|
|
2525
|
-
|
|
2544
|
+
if (truncated || signal.aborted) reader.cancel().catch(() => {});
|
|
2545
|
+
try {
|
|
2546
|
+
reader.releaseLock();
|
|
2547
|
+
} catch (_) {}
|
|
2526
2548
|
}
|
|
2527
2549
|
let result = chunks.join("");
|
|
2528
2550
|
if (truncated) result += "… (truncated)";
|
|
@@ -2534,12 +2556,24 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2534
2556
|
"federation",
|
|
2535
2557
|
"outbox"
|
|
2536
2558
|
]);
|
|
2537
|
-
const
|
|
2559
|
+
const timeoutMs = deps.timeoutMs ?? SEND_ACTIVITY_TIMEOUT_MS;
|
|
2560
|
+
const controller = new AbortController();
|
|
2561
|
+
const { signal } = controller;
|
|
2562
|
+
const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? _fedify_vocab_runtime_internal.openDirectFetch : (url) => (0, _fedify_vocab_runtime_internal.openPublicFetch)(url, { signal }));
|
|
2538
2563
|
let opened = false;
|
|
2539
2564
|
async function openHop(url) {
|
|
2540
2565
|
let session;
|
|
2541
2566
|
try {
|
|
2542
|
-
|
|
2567
|
+
signal.throwIfAborted();
|
|
2568
|
+
const opening = openUnvalidatedHop(url);
|
|
2569
|
+
opening.then((lateSession) => {
|
|
2570
|
+
if (signal.aborted) closeAfterError(lateSession, logger);
|
|
2571
|
+
}, () => {});
|
|
2572
|
+
session = await raceWithAbort(opening, signal);
|
|
2573
|
+
if (signal.aborted) {
|
|
2574
|
+
closeAfterError(session, logger);
|
|
2575
|
+
signal.throwIfAborted();
|
|
2576
|
+
}
|
|
2543
2577
|
} catch (error) {
|
|
2544
2578
|
if (error instanceof _fedify_vocab_runtime.UrlError && error.reason === "dns") {
|
|
2545
2579
|
logger.error("DNS resolution failed for URL: {url}", {
|
|
@@ -2565,7 +2599,8 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2565
2599
|
method: "POST",
|
|
2566
2600
|
headers,
|
|
2567
2601
|
body: JSON.stringify(activity),
|
|
2568
|
-
redirect: "manual"
|
|
2602
|
+
redirect: "manual",
|
|
2603
|
+
signal
|
|
2569
2604
|
});
|
|
2570
2605
|
let rsaKey = null;
|
|
2571
2606
|
for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
|
@@ -2580,18 +2615,48 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2580
2615
|
}))
|
|
2581
2616
|
});
|
|
2582
2617
|
let outcome;
|
|
2618
|
+
const boundedSpecDeterminer = specDeterminer == null ? void 0 : {
|
|
2619
|
+
determineSpec(origin) {
|
|
2620
|
+
signal.throwIfAborted();
|
|
2621
|
+
return raceWithAbort(Promise.resolve(specDeterminer.determineSpec(origin)), signal);
|
|
2622
|
+
},
|
|
2623
|
+
rememberSpec(origin, spec) {
|
|
2624
|
+
if (signal.aborted) return;
|
|
2625
|
+
try {
|
|
2626
|
+
Promise.resolve(specDeterminer.rememberSpec(origin, spec)).catch((error) => logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
2627
|
+
origin,
|
|
2628
|
+
error
|
|
2629
|
+
}));
|
|
2630
|
+
} catch (error) {
|
|
2631
|
+
logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
2632
|
+
origin,
|
|
2633
|
+
error
|
|
2634
|
+
});
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
};
|
|
2638
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The delivery timed out.", "TimeoutError")), timeoutMs);
|
|
2583
2639
|
try {
|
|
2584
|
-
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openHop, (response) => consumeSendActivityResponse(response, inbox)) : await require_http.doubleKnockScoped(request, rsaKey, {
|
|
2640
|
+
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openHop, (response) => consumeSendActivityResponse(response, inbox, signal), signal) : await require_http.doubleKnockScoped(request, rsaKey, {
|
|
2585
2641
|
tracerProvider,
|
|
2586
|
-
specDeterminer
|
|
2587
|
-
|
|
2642
|
+
specDeterminer: boundedSpecDeterminer,
|
|
2643
|
+
signal
|
|
2644
|
+
}, openHop, (response) => consumeSendActivityResponse(response, inbox, signal));
|
|
2588
2645
|
} catch (error) {
|
|
2589
|
-
|
|
2646
|
+
let failureError = error;
|
|
2647
|
+
if (signal.aborted && !(error instanceof SendActivityError)) {
|
|
2648
|
+
const failure = new _fedify_vocab_runtime.FetchError(inbox.href, `Timed out after ${timeoutMs} ms`);
|
|
2649
|
+
failure.cause = signal.reason;
|
|
2650
|
+
failureError = failure;
|
|
2651
|
+
}
|
|
2652
|
+
if (opened || signal.aborted) logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
2590
2653
|
activityId,
|
|
2591
2654
|
inbox: inbox.href,
|
|
2592
|
-
error
|
|
2655
|
+
error: failureError
|
|
2593
2656
|
});
|
|
2594
|
-
throw
|
|
2657
|
+
throw failureError;
|
|
2658
|
+
} finally {
|
|
2659
|
+
clearTimeout(timer);
|
|
2595
2660
|
}
|
|
2596
2661
|
if (!outcome.ok) {
|
|
2597
2662
|
const { status, statusText, error } = outcome;
|
|
@@ -2633,17 +2698,18 @@ function cancelResponseBody(response, url) {
|
|
|
2633
2698
|
* session is open: the body of a successful response is cancelled, and at
|
|
2634
2699
|
* most 1 KiB of an error response body is read.
|
|
2635
2700
|
*/
|
|
2636
|
-
async function consumeSendActivityResponse(response, inbox) {
|
|
2701
|
+
async function consumeSendActivityResponse(response, inbox, signal) {
|
|
2637
2702
|
if (response.ok) {
|
|
2638
2703
|
cancelResponseBody(response, response.url || inbox.href);
|
|
2639
2704
|
return { ok: true };
|
|
2640
2705
|
}
|
|
2641
2706
|
let error;
|
|
2642
2707
|
try {
|
|
2643
|
-
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
|
|
2708
|
+
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES, signal);
|
|
2644
2709
|
} catch (_) {
|
|
2645
2710
|
error = "";
|
|
2646
2711
|
}
|
|
2712
|
+
if (signal.aborted) error = "(timed out reading response body)";
|
|
2647
2713
|
return {
|
|
2648
2714
|
ok: false,
|
|
2649
2715
|
status: response.status,
|
|
@@ -2662,7 +2728,7 @@ async function consumeSendActivityResponse(response, inbox) {
|
|
|
2662
2728
|
* @param consume The function to consume the final response.
|
|
2663
2729
|
* @returns The value returned by `consume`.
|
|
2664
2730
|
*/
|
|
2665
|
-
async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
2731
|
+
async function fetchWithValidatedRedirects(request, openHop, consume, signal) {
|
|
2666
2732
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
2667
2733
|
"fedify",
|
|
2668
2734
|
"federation",
|
|
@@ -2670,10 +2736,14 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
2670
2736
|
]);
|
|
2671
2737
|
let body = await request.clone().text();
|
|
2672
2738
|
for (let redirects = 0;; redirects++) {
|
|
2739
|
+
signal?.throwIfAborted();
|
|
2673
2740
|
const session = await openHop(request.url);
|
|
2674
2741
|
let response;
|
|
2675
2742
|
try {
|
|
2676
|
-
response = await session.fetch(request, {
|
|
2743
|
+
response = await session.fetch(request, {
|
|
2744
|
+
redirect: "manual",
|
|
2745
|
+
signal
|
|
2746
|
+
});
|
|
2677
2747
|
} catch (error) {
|
|
2678
2748
|
await closeAfterError(session, logger);
|
|
2679
2749
|
throw error;
|
|
@@ -2723,7 +2793,8 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
2723
2793
|
method,
|
|
2724
2794
|
headers,
|
|
2725
2795
|
body,
|
|
2726
|
-
redirect: "manual"
|
|
2796
|
+
redirect: "manual",
|
|
2797
|
+
signal: signal ?? request.signal
|
|
2727
2798
|
});
|
|
2728
2799
|
}
|
|
2729
2800
|
}
|
|
@@ -2,25 +2,25 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { n as RouterError } from "./router-CrMLXoOr.mjs";
|
|
5
|
-
import { n as version, t as name } from "./deno-
|
|
6
|
-
import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-
|
|
7
|
-
import { u as verifyRequest } from "./http-
|
|
8
|
-
import { n as getAuthenticatedDocumentLoader } from "./docloader-
|
|
5
|
+
import { n as version, t as name } from "./deno-USvfGHbR.mjs";
|
|
6
|
+
import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-BDisDFGv.mjs";
|
|
7
|
+
import { u as verifyRequest } from "./http-BGjEnY4L.mjs";
|
|
8
|
+
import { n as getAuthenticatedDocumentLoader } from "./docloader-CDITXM6j.mjs";
|
|
9
9
|
import { n as kvCache } from "./kv-cache-BrjuJue8.mjs";
|
|
10
|
-
import { a as compactJsonLd, c as detachSignature, d as hasVerifiableSignature, f as isClearlyMalformedContextReference, h as verifyCompactJsonLd, l as getNormalizationContextLoader, m as signJsonLd, p as isInvalidUrlTypeError, r as assertSafeJsonLd, s as describeSignatureShape, t as InvalidContextReferenceError, v as wrapContextLoaderForJsonLd } from "./ld-
|
|
11
|
-
import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-
|
|
12
|
-
import { n as signObject, r as verifyObject } from "./proof-
|
|
10
|
+
import { a as compactJsonLd, c as detachSignature, d as hasVerifiableSignature, f as isClearlyMalformedContextReference, h as verifyCompactJsonLd, l as getNormalizationContextLoader, m as signJsonLd, p as isInvalidUrlTypeError, r as assertSafeJsonLd, s as describeSignatureShape, t as InvalidContextReferenceError, v as wrapContextLoaderForJsonLd } from "./ld-CjHkfxXf.mjs";
|
|
11
|
+
import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-CyoKKXIR.mjs";
|
|
12
|
+
import { n as signObject, r as verifyObject } from "./proof-D8S0HFxt.mjs";
|
|
13
13
|
import { d as MAX_BODY_SIZE, f as readBoundedText, t as getNodeInfo, u as BodyTooLargeError } from "./client-DLAWT9ep.mjs";
|
|
14
14
|
import { t as normalizeAttachmentArrays } from "./attachment-arrays-D43igPLB.mjs";
|
|
15
15
|
import { t as nodeInfoToJson } from "./types-DCP0WLdt.mjs";
|
|
16
|
-
import { n as actorsHaveSameOrigin, r as routeActivity } from "./inbox-
|
|
17
|
-
import { t as FederationBuilderImpl } from "./builder-
|
|
16
|
+
import { n as actorsHaveSameOrigin, r as routeActivity } from "./inbox-BtfUJZS3.mjs";
|
|
17
|
+
import { t as FederationBuilderImpl } from "./builder-CuQLFOSj.mjs";
|
|
18
18
|
import { t as buildCollectionSynchronizationHeader } from "./collection-BD6-SZ6O.mjs";
|
|
19
19
|
import { t as KvKeyCache } from "./keycache-BhLorx33.mjs";
|
|
20
20
|
import { t as acceptsJsonLd } from "./negotiation-DnsfFF8I.mjs";
|
|
21
|
-
import { t as hasMalformedKnownTemporalLiteral } from "./temporal-
|
|
21
|
+
import { t as hasMalformedKnownTemporalLiteral } from "./temporal-Dlbq-g7z.mjs";
|
|
22
22
|
import { t as createExponentialBackoffPolicy } from "./retry-CJL0poaU.mjs";
|
|
23
|
-
import { i as sendActivity, n as extractInboxes, t as SendActivityError } from "./send-
|
|
23
|
+
import { i as sendActivity, n as extractInboxes, t as SendActivityError } from "./send-speW4h59.mjs";
|
|
24
24
|
import { Activity, Collection, CollectionPage, CryptographicKey, DataIntegrityProof, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId, lookupObject, traverseCollection } from "@fedify/vocab";
|
|
25
25
|
import { lookupWebFinger } from "@fedify/webfinger";
|
|
26
26
|
import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
|
-
const require_middleware = require("./middleware-
|
|
3
|
+
const require_middleware = require("./middleware-DjXy4YoB.cjs");
|
|
4
4
|
exports.FederationImpl = require_middleware.FederationImpl;
|
|
@@ -2,10 +2,10 @@ import { Temporal } from "@js-temporal/polyfill";
|
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
import { t as __exportAll } from "./chunk-CRNNMoPX.js";
|
|
4
4
|
import { r as getDefaultActivityTransformers } from "./transformers-BGMIq1cs.js";
|
|
5
|
-
import { c as importJwk, d as name, f as version, i as exportJwk, l as validateCryptoKey, r as verifyRequest, t as doubleKnockScoped } from "./http-
|
|
5
|
+
import { c as importJwk, d as name, f as version, i as exportJwk, l as validateCryptoKey, r as verifyRequest, t as doubleKnockScoped } from "./http-ixT5PjBz.js";
|
|
6
6
|
import { a as MAX_BODY_SIZE, i as BodyTooLargeError, n as getNodeInfo, o as readBoundedText, t as nodeInfoToJson } from "./types-B1_pRFE_.js";
|
|
7
|
-
import { S as wrapContextLoaderForJsonLd, _ as isInvalidUrlTypeError, a as doesActorOwnKey, c as assertSafeJsonLd, f as describeSignatureShape, g as isClearlyMalformedContextReference, h as hasVerifiableSignature, m as getNormalizationContextLoader, n as signObject, o as getKeyOwner, p as detachSignature, r as verifyObject, s as InvalidContextReferenceError, u as compactJsonLd, v as signJsonLd, y as verifyCompactJsonLd } from "./proof-
|
|
8
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-
|
|
7
|
+
import { S as wrapContextLoaderForJsonLd, _ as isInvalidUrlTypeError, a as doesActorOwnKey, c as assertSafeJsonLd, f as describeSignatureShape, g as isClearlyMalformedContextReference, h as hasVerifiableSignature, m as getNormalizationContextLoader, n as signObject, o as getKeyOwner, p as detachSignature, r as verifyObject, s as InvalidContextReferenceError, u as compactJsonLd, v as signJsonLd, y as verifyCompactJsonLd } from "./proof-BiTmCpLq.js";
|
|
8
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-YdAhdrrh.js";
|
|
9
9
|
import { getLogger, withContext } from "@logtape/logtape";
|
|
10
10
|
import { Activity, Collection, CollectionPage, CryptographicKey, DataIntegrityProof, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId, lookupObject, traverseCollection } from "@fedify/vocab";
|
|
11
11
|
import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
|
|
@@ -2471,7 +2471,8 @@ function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
|
|
2471
2471
|
* @param parameters The parameters for sending the activity.
|
|
2472
2472
|
* See also {@link SendActivityParameters}.
|
|
2473
2473
|
* @param deps The dependencies, for tests.
|
|
2474
|
-
* @throws {
|
|
2474
|
+
* @throws {FetchError} If the delivery times out before receiving a response.
|
|
2475
|
+
* @throws {SendActivityError} If the inbox returns an unsuccessful response.
|
|
2475
2476
|
*/
|
|
2476
2477
|
function sendActivity(options, deps = {}) {
|
|
2477
2478
|
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
|
@@ -2498,7 +2499,25 @@ function sendActivity(options, deps = {}) {
|
|
|
2498
2499
|
});
|
|
2499
2500
|
}
|
|
2500
2501
|
const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
|
|
2501
|
-
|
|
2502
|
+
const SEND_ACTIVITY_TIMEOUT_MS = 3e4;
|
|
2503
|
+
function raceWithAbort(promise, signal) {
|
|
2504
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
2505
|
+
return new Promise((resolve, reject) => {
|
|
2506
|
+
const onAbort = () => {
|
|
2507
|
+
signal.removeEventListener("abort", onAbort);
|
|
2508
|
+
reject(signal.reason);
|
|
2509
|
+
};
|
|
2510
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2511
|
+
promise.then((value) => {
|
|
2512
|
+
signal.removeEventListener("abort", onAbort);
|
|
2513
|
+
resolve(value);
|
|
2514
|
+
}, (error) => {
|
|
2515
|
+
signal.removeEventListener("abort", onAbort);
|
|
2516
|
+
reject(error);
|
|
2517
|
+
});
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
async function readLimitedResponseBody(response, maxBytes, signal) {
|
|
2502
2521
|
if (response.body == null) return "";
|
|
2503
2522
|
const reader = response.body.getReader();
|
|
2504
2523
|
const decoder = new TextDecoder();
|
|
@@ -2507,7 +2526,8 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
2507
2526
|
let truncated = false;
|
|
2508
2527
|
try {
|
|
2509
2528
|
while (true) {
|
|
2510
|
-
|
|
2529
|
+
signal.throwIfAborted();
|
|
2530
|
+
const { done, value } = await raceWithAbort(reader.read(), signal);
|
|
2511
2531
|
if (done) break;
|
|
2512
2532
|
if (totalBytes + value.length > maxBytes) {
|
|
2513
2533
|
const remaining = maxBytes - totalBytes;
|
|
@@ -2519,8 +2539,10 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
2519
2539
|
totalBytes += value.length;
|
|
2520
2540
|
}
|
|
2521
2541
|
} finally {
|
|
2522
|
-
if (truncated) reader.cancel().catch(() => {});
|
|
2523
|
-
|
|
2542
|
+
if (truncated || signal.aborted) reader.cancel().catch(() => {});
|
|
2543
|
+
try {
|
|
2544
|
+
reader.releaseLock();
|
|
2545
|
+
} catch (_) {}
|
|
2524
2546
|
}
|
|
2525
2547
|
let result = chunks.join("");
|
|
2526
2548
|
if (truncated) result += "… (truncated)";
|
|
@@ -2532,12 +2554,24 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2532
2554
|
"federation",
|
|
2533
2555
|
"outbox"
|
|
2534
2556
|
]);
|
|
2535
|
-
const
|
|
2557
|
+
const timeoutMs = deps.timeoutMs ?? SEND_ACTIVITY_TIMEOUT_MS;
|
|
2558
|
+
const controller = new AbortController();
|
|
2559
|
+
const { signal } = controller;
|
|
2560
|
+
const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? openDirectFetch : (url) => openPublicFetch(url, { signal }));
|
|
2536
2561
|
let opened = false;
|
|
2537
2562
|
async function openHop(url) {
|
|
2538
2563
|
let session;
|
|
2539
2564
|
try {
|
|
2540
|
-
|
|
2565
|
+
signal.throwIfAborted();
|
|
2566
|
+
const opening = openUnvalidatedHop(url);
|
|
2567
|
+
opening.then((lateSession) => {
|
|
2568
|
+
if (signal.aborted) closeAfterError(lateSession, logger);
|
|
2569
|
+
}, () => {});
|
|
2570
|
+
session = await raceWithAbort(opening, signal);
|
|
2571
|
+
if (signal.aborted) {
|
|
2572
|
+
closeAfterError(session, logger);
|
|
2573
|
+
signal.throwIfAborted();
|
|
2574
|
+
}
|
|
2541
2575
|
} catch (error) {
|
|
2542
2576
|
if (error instanceof UrlError && error.reason === "dns") {
|
|
2543
2577
|
logger.error("DNS resolution failed for URL: {url}", {
|
|
@@ -2563,7 +2597,8 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2563
2597
|
method: "POST",
|
|
2564
2598
|
headers,
|
|
2565
2599
|
body: JSON.stringify(activity),
|
|
2566
|
-
redirect: "manual"
|
|
2600
|
+
redirect: "manual",
|
|
2601
|
+
signal
|
|
2567
2602
|
});
|
|
2568
2603
|
let rsaKey = null;
|
|
2569
2604
|
for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
|
@@ -2578,18 +2613,48 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
2578
2613
|
}))
|
|
2579
2614
|
});
|
|
2580
2615
|
let outcome;
|
|
2616
|
+
const boundedSpecDeterminer = specDeterminer == null ? void 0 : {
|
|
2617
|
+
determineSpec(origin) {
|
|
2618
|
+
signal.throwIfAborted();
|
|
2619
|
+
return raceWithAbort(Promise.resolve(specDeterminer.determineSpec(origin)), signal);
|
|
2620
|
+
},
|
|
2621
|
+
rememberSpec(origin, spec) {
|
|
2622
|
+
if (signal.aborted) return;
|
|
2623
|
+
try {
|
|
2624
|
+
Promise.resolve(specDeterminer.rememberSpec(origin, spec)).catch((error) => logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
2625
|
+
origin,
|
|
2626
|
+
error
|
|
2627
|
+
}));
|
|
2628
|
+
} catch (error) {
|
|
2629
|
+
logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
2630
|
+
origin,
|
|
2631
|
+
error
|
|
2632
|
+
});
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
};
|
|
2636
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The delivery timed out.", "TimeoutError")), timeoutMs);
|
|
2581
2637
|
try {
|
|
2582
|
-
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openHop, (response) => consumeSendActivityResponse(response, inbox)) : await doubleKnockScoped(request, rsaKey, {
|
|
2638
|
+
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openHop, (response) => consumeSendActivityResponse(response, inbox, signal), signal) : await doubleKnockScoped(request, rsaKey, {
|
|
2583
2639
|
tracerProvider,
|
|
2584
|
-
specDeterminer
|
|
2585
|
-
|
|
2640
|
+
specDeterminer: boundedSpecDeterminer,
|
|
2641
|
+
signal
|
|
2642
|
+
}, openHop, (response) => consumeSendActivityResponse(response, inbox, signal));
|
|
2586
2643
|
} catch (error) {
|
|
2587
|
-
|
|
2644
|
+
let failureError = error;
|
|
2645
|
+
if (signal.aborted && !(error instanceof SendActivityError)) {
|
|
2646
|
+
const failure = new FetchError(inbox.href, `Timed out after ${timeoutMs} ms`);
|
|
2647
|
+
failure.cause = signal.reason;
|
|
2648
|
+
failureError = failure;
|
|
2649
|
+
}
|
|
2650
|
+
if (opened || signal.aborted) logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
2588
2651
|
activityId,
|
|
2589
2652
|
inbox: inbox.href,
|
|
2590
|
-
error
|
|
2653
|
+
error: failureError
|
|
2591
2654
|
});
|
|
2592
|
-
throw
|
|
2655
|
+
throw failureError;
|
|
2656
|
+
} finally {
|
|
2657
|
+
clearTimeout(timer);
|
|
2593
2658
|
}
|
|
2594
2659
|
if (!outcome.ok) {
|
|
2595
2660
|
const { status, statusText, error } = outcome;
|
|
@@ -2631,17 +2696,18 @@ function cancelResponseBody(response, url) {
|
|
|
2631
2696
|
* session is open: the body of a successful response is cancelled, and at
|
|
2632
2697
|
* most 1 KiB of an error response body is read.
|
|
2633
2698
|
*/
|
|
2634
|
-
async function consumeSendActivityResponse(response, inbox) {
|
|
2699
|
+
async function consumeSendActivityResponse(response, inbox, signal) {
|
|
2635
2700
|
if (response.ok) {
|
|
2636
2701
|
cancelResponseBody(response, response.url || inbox.href);
|
|
2637
2702
|
return { ok: true };
|
|
2638
2703
|
}
|
|
2639
2704
|
let error;
|
|
2640
2705
|
try {
|
|
2641
|
-
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
|
|
2706
|
+
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES, signal);
|
|
2642
2707
|
} catch (_) {
|
|
2643
2708
|
error = "";
|
|
2644
2709
|
}
|
|
2710
|
+
if (signal.aborted) error = "(timed out reading response body)";
|
|
2645
2711
|
return {
|
|
2646
2712
|
ok: false,
|
|
2647
2713
|
status: response.status,
|
|
@@ -2660,7 +2726,7 @@ async function consumeSendActivityResponse(response, inbox) {
|
|
|
2660
2726
|
* @param consume The function to consume the final response.
|
|
2661
2727
|
* @returns The value returned by `consume`.
|
|
2662
2728
|
*/
|
|
2663
|
-
async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
2729
|
+
async function fetchWithValidatedRedirects(request, openHop, consume, signal) {
|
|
2664
2730
|
const logger = getLogger([
|
|
2665
2731
|
"fedify",
|
|
2666
2732
|
"federation",
|
|
@@ -2668,10 +2734,14 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
2668
2734
|
]);
|
|
2669
2735
|
let body = await request.clone().text();
|
|
2670
2736
|
for (let redirects = 0;; redirects++) {
|
|
2737
|
+
signal?.throwIfAborted();
|
|
2671
2738
|
const session = await openHop(request.url);
|
|
2672
2739
|
let response;
|
|
2673
2740
|
try {
|
|
2674
|
-
response = await session.fetch(request, {
|
|
2741
|
+
response = await session.fetch(request, {
|
|
2742
|
+
redirect: "manual",
|
|
2743
|
+
signal
|
|
2744
|
+
});
|
|
2675
2745
|
} catch (error) {
|
|
2676
2746
|
await closeAfterError(session, logger);
|
|
2677
2747
|
throw error;
|
|
@@ -2721,7 +2791,8 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
2721
2791
|
method,
|
|
2722
2792
|
headers,
|
|
2723
2793
|
body,
|
|
2724
|
-
redirect: "manual"
|
|
2794
|
+
redirect: "manual",
|
|
2795
|
+
signal: signal ?? request.signal
|
|
2725
2796
|
});
|
|
2726
2797
|
}
|
|
2727
2798
|
}
|
package/dist/mod.cjs
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
4
4
|
require("./chunk-DDcVe30Y.cjs");
|
|
5
5
|
const require_transformers = require("./transformers-NeAONrAq.cjs");
|
|
6
6
|
require("./compat/mod.cjs");
|
|
7
|
-
const require_http = require("./http-
|
|
8
|
-
const require_middleware = require("./middleware-
|
|
7
|
+
const require_http = require("./http-BAhackOL.cjs");
|
|
8
|
+
const require_middleware = require("./middleware-DjXy4YoB.cjs");
|
|
9
9
|
const require_types = require("./types-DOvyymM4.cjs");
|
|
10
|
-
const require_proof = require("./proof-
|
|
11
|
-
const require_kv_cache = require("./kv-cache-
|
|
10
|
+
const require_proof = require("./proof-BOemJGRl.cjs");
|
|
11
|
+
const require_kv_cache = require("./kv-cache-BKEuedCv.cjs");
|
|
12
12
|
const require_federation_mod = require("./federation/mod.cjs");
|
|
13
13
|
require("./nodeinfo/mod.cjs");
|
|
14
14
|
require("./runtime/mod.cjs");
|
package/dist/mod.js
CHANGED
|
@@ -3,11 +3,11 @@ import { URLPattern } from "urlpattern-polyfill";
|
|
|
3
3
|
import "./chunk-CRNNMoPX.js";
|
|
4
4
|
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-BGMIq1cs.js";
|
|
5
5
|
import "./compat/mod.js";
|
|
6
|
-
import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "./http-
|
|
7
|
-
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-
|
|
6
|
+
import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "./http-ixT5PjBz.js";
|
|
7
|
+
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-X7A94J2d.js";
|
|
8
8
|
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-B1_pRFE_.js";
|
|
9
|
-
import { a as doesActorOwnKey, b as verifyJsonLd, d as createSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, p as detachSignature, r as verifyObject, t as createProof, v as signJsonLd, x as verifySignature } from "./proof-
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-
|
|
9
|
+
import { a as doesActorOwnKey, b as verifyJsonLd, d as createSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, p as detachSignature, r as verifyObject, t as createProof, v as signJsonLd, x as verifySignature } from "./proof-BiTmCpLq.js";
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-YdAhdrrh.js";
|
|
11
11
|
import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "./federation/mod.js";
|
|
12
12
|
import "./nodeinfo/mod.js";
|
|
13
13
|
import "./runtime/mod.js";
|
|
@@ -5,7 +5,7 @@ import { n as createRequestContext } from "../context-Juj6bdHC.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-DflMZha5.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
|
|
8
|
-
import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-
|
|
8
|
+
import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-DkrLbSc2.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
//#region src/nodeinfo/handler.test.ts
|
|
11
11
|
test("handleNodeInfo()", async () => {
|
|
@@ -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-
|
|
5
|
-
import { n as fetchActorDocument, s as verifyKeyOwnership, t as exportJwk } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-USvfGHbR.mjs";
|
|
5
|
+
import { n as fetchActorDocument, s as verifyKeyOwnership, t as exportJwk } from "./key-BDisDFGv.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";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
const require_chunk = require("./chunk-DDcVe30Y.cjs");
|
|
4
|
-
const require_http = require("./http-
|
|
4
|
+
const require_http = require("./http-BAhackOL.cjs");
|
|
5
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
6
6
|
let _fedify_vocab = require("@fedify/vocab");
|
|
7
7
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { a as fetchActorDocument, d as name, f as version, i as exportJwk, l as validateCryptoKey, o as fetchKey, u as verifyKeyOwnership } from "./http-
|
|
3
|
+
import { a as fetchActorDocument, d as name, f as version, i as exportJwk, l as validateCryptoKey, o as fetchKey, u as verifyKeyOwnership } from "./http-ixT5PjBz.js";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
5
|
import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, getTypeId, isActor } from "@fedify/vocab";
|
|
6
6
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { o as validateCryptoKey, r as fetchKey } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-USvfGHbR.mjs";
|
|
5
|
+
import { o as validateCryptoKey, r as fetchKey } from "./key-BDisDFGv.mjs";
|
|
6
6
|
import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
|
|
7
7
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
8
|
import { asCryptoKey } from "@fedify/vocab-runtime/internal";
|