@fedify/fedify 2.0.0-dev.1641 → 2.0.0-dev.1726
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/{actor-CP03csrm.cjs → actor-Bn2RCpws.cjs} +7263 -2440
- package/dist/{actor-DMgu-ZjT.d.cts → actor-D6K058Tb.d.cts} +1 -1
- package/dist/{actor-C22bXuuC.d.ts → actor-T6RyhRgk.d.ts} +1 -1
- package/dist/{actor-DVpsNXhn.js → actor-dO7jHa6A.js} +1 -1
- package/dist/{actor-DU511yTk.js → actor-menZmmiI.js} +7263 -2440
- package/dist/{assert_rejects-7UF4R_Qs.js → assert_rejects-DiIiJbZn.js} +1 -1
- package/dist/{assert_throws-53_pKeP3.js → assert_throws-BOO88avQ.js} +1 -1
- package/dist/{authdocloader-BnsFSERg.cjs → authdocloader-CEqdZdT7.cjs} +3 -3
- package/dist/{authdocloader-DCgMyo82.js → authdocloader-CZsCIRLV.js} +3 -3
- package/dist/{authdocloader-BkIZCKQv.js → authdocloader-DevmXsTo.js} +3 -3
- package/dist/{builder-E2Icrl_a.js → builder-CGF1vv7G.js} +14 -8
- package/dist/{client-BW4V0OJx.js → client-BfzV3u96.js} +1 -1
- package/dist/compat/mod.d.cts +7 -7
- package/dist/compat/mod.d.ts +7 -7
- package/dist/compat/transformers.test.js +18 -17
- package/dist/{context-CDSZdQHD.d.ts → context-B1X8-X33.d.ts} +185 -98
- package/dist/{context-Dq8aCtMH.d.cts → context-DYCJXr7J.d.cts} +185 -98
- package/dist/{docloader-kae6M-GI.cjs → docloader-Buh0Ah9G.cjs} +2 -2
- package/dist/{docloader-BtqIh1OE.js → docloader-DOmINJ1U.js} +2 -2
- package/dist/{esm-mtx3XJAD.js → esm-BODOj_Oi.js} +1 -1
- package/dist/federation/builder.test.js +10 -10
- package/dist/federation/collection.test.js +8 -8
- package/dist/federation/handler.test.js +26 -145
- package/dist/federation/idempotency.test.d.ts +3 -0
- package/dist/federation/idempotency.test.js +202 -0
- package/dist/federation/inbox.test.js +6 -6
- package/dist/federation/keycache.test.js +4 -4
- package/dist/federation/kv.test.js +8 -8
- package/dist/federation/middleware.test.js +238 -44
- package/dist/federation/mod.cjs +10 -10
- package/dist/federation/mod.d.cts +7 -7
- package/dist/federation/mod.d.ts +7 -7
- package/dist/federation/mod.js +10 -10
- package/dist/federation/mq.test.js +10 -10
- package/dist/federation/negotiation.test.d.ts +3 -0
- package/dist/federation/negotiation.test.js +28 -0
- package/dist/federation/retry.test.js +5 -5
- package/dist/federation/router.test.js +8 -8
- package/dist/federation/send.test.js +15 -15
- package/dist/fixtures/media.example.com/avatars/test-avatar.jpg.json +6 -0
- package/dist/{http-ZhcoaYEa.cjs → http-BmbMWfmh.cjs} +3 -3
- package/dist/{http-BS6766zs.d.cts → http-D-e6AFwR.d.cts} +1 -1
- package/dist/{http-DqSNLFNY.d.ts → http-D6Uj2x2y.d.ts} +1 -1
- package/dist/{http-Cox5GsED.js → http-Danw_xTY.js} +2 -2
- package/dist/{http-C7uYFcBo.js → http-gHyCrTrX.js} +3 -3
- package/dist/{inbox-BDdRbWNI.js → inbox-Blp5F74G.js} +24 -7
- package/dist/{key-CgwCzDC4.js → key-B2cp5-JF.js} +3 -3
- package/dist/{key-HqzOCwDc.cjs → key-BR1W25rw.cjs} +2 -2
- package/dist/{key-Cc0JlcKe.js → key-BnjofJ4e.js} +2 -2
- package/dist/{key-CfiBDu3o.js → key-CIIkeide.js} +2 -2
- package/dist/key-DhflzsBJ.cjs +10 -0
- package/dist/{key-B9Z5ZuX9.js → key-WES6wszI.js} +4 -4
- package/dist/{keycache-CVBjz3xi.js → keycache-Covv8lvK.js} +1 -1
- package/dist/{keys-CBKbYaJA.js → keys-DZ1bqhJz.js} +1 -1
- package/dist/{ld-CxgmnSO3.js → ld-C7KL1MK2.js} +2 -2
- package/dist/{lookup-QHjmy4Og.cjs → lookup-CDOxr8vw.cjs} +1 -1
- package/dist/{lookup-NuT9cCSl.js → lookup-D8tCnUj2.js} +1 -1
- package/dist/{lookup-CiU3QxQz.js → lookup-VSVPBU3J.js} +21 -12
- package/dist/middleware-9KSLASn7.js +17 -0
- package/dist/{middleware-LyCG_YVM.cjs → middleware-C60xXvWx.cjs} +99 -108
- package/dist/middleware-CH0PNtaj.cjs +17 -0
- package/dist/middleware-CrzCnpdt.js +26 -0
- package/dist/{middleware-DXidHY4N.js → middleware-DXOZ6_ST.js} +99 -108
- package/dist/{middleware-ByPnvMMS.js → middleware-HKKY6sAX.js} +69 -165
- package/dist/{mod-Drmz72EK.d.ts → mod-BhUKmBJD.d.ts} +2 -2
- package/dist/{mod-TFoH2Ql8.d.ts → mod-CerN_Sza.d.ts} +1 -1
- package/dist/{mod-Dc_-mf8s.d.cts → mod-Cj1tHXBR.d.cts} +1 -1
- package/dist/{mod-evzlRVZq.d.cts → mod-CxkWO3Mg.d.cts} +19 -1
- package/dist/{mod-RI3-KvUI.d.ts → mod-DcKxhFQ8.d.ts} +2 -2
- package/dist/{mod-BClfg3ej.d.cts → mod-Djzcw2ry.d.cts} +2 -2
- package/dist/{mod-Cxt4Kpf6.d.ts → mod-DlU8ISoa.d.ts} +19 -1
- package/dist/{mod-BhMnAkFX.d.cts → mod-twdvV2hR.d.cts} +2 -2
- package/dist/mod.cjs +10 -10
- package/dist/mod.d.cts +10 -10
- package/dist/mod.d.ts +10 -10
- package/dist/mod.js +10 -10
- package/dist/negotiation-5NPJL6zp.js +71 -0
- package/dist/nodeinfo/client.test.js +10 -10
- package/dist/nodeinfo/handler.test.js +23 -22
- package/dist/nodeinfo/mod.cjs +2 -2
- package/dist/nodeinfo/mod.js +2 -2
- package/dist/nodeinfo/types.test.js +8 -8
- package/dist/{owner-B-7Ptt_m.d.cts → owner-BN_tO3cY.d.cts} +2 -2
- package/dist/{owner-Cxob5_PK.js → owner-COcyel6J.js} +2 -2
- package/dist/{owner-CQPnQVtf.d.ts → owner-hd9lvQcP.d.ts} +2 -2
- package/dist/{proof-2Gcor0_N.cjs → proof-CMJcrQoM.cjs} +3 -3
- package/dist/{proof-BiSQNUmQ.js → proof-Cpk853lc.js} +2 -2
- package/dist/{proof-DkxwMaWE.js → proof-D6pbnNx2.js} +3 -3
- package/dist/runtime/authdocloader.test.js +14 -14
- package/dist/runtime/docloader.test.js +9 -9
- package/dist/runtime/key.test.js +10 -10
- package/dist/runtime/langstr.test.js +8 -8
- package/dist/runtime/link.test.js +3 -3
- package/dist/runtime/mod.cjs +6 -6
- package/dist/runtime/mod.d.cts +3 -3
- package/dist/runtime/mod.d.ts +3 -3
- package/dist/runtime/mod.js +6 -6
- package/dist/runtime/multibase/multibase.test.js +8 -8
- package/dist/runtime/url.test.js +5 -5
- package/dist/{send-DSEhWIYD.js → send-C7A7_big.js} +2 -2
- package/dist/sig/http.test.js +13 -13
- package/dist/sig/key.test.js +11 -11
- package/dist/sig/ld.test.js +10 -10
- package/dist/sig/mod.cjs +6 -6
- package/dist/sig/mod.d.cts +5 -5
- package/dist/sig/mod.d.ts +5 -5
- package/dist/sig/mod.js +6 -6
- package/dist/sig/owner.test.js +12 -12
- package/dist/sig/proof.test.js +12 -12
- package/dist/testing/docloader.test.js +8 -8
- package/dist/testing/mod.d.ts +391 -86
- package/dist/testing/mod.js +3 -3
- package/dist/{testing-ByQmUvf-.js → testing-e8Kpb1uV.js} +2 -2
- package/dist/{type-B4NJkfVg.js → type-D_8QzkEn.js} +6944 -2121
- package/dist/{types-l2uh_ZhP.js → types-Db4ukgX8.js} +1 -1
- package/dist/{types-Bqt2EgP0.cjs → types-LjTL4QMx.cjs} +1 -1
- package/dist/vocab/actor.test.js +10 -10
- package/dist/vocab/lookup.test.js +259 -9
- package/dist/vocab/mod.cjs +4 -4
- package/dist/vocab/mod.d.cts +3 -3
- package/dist/vocab/mod.d.ts +3 -3
- package/dist/vocab/mod.js +4 -4
- package/dist/vocab/type.test.js +3 -3
- package/dist/vocab/vocab.test.js +402 -13
- package/dist/{vocab-SOE1ifCr.d.ts → vocab-BI0Ak5lL.d.ts} +290 -0
- package/dist/{vocab-lBFcVxVF.js → vocab-CJHF7Q71.js} +23 -14
- package/dist/{vocab-B0-5a8pw.cjs → vocab-DLHpZwOW.cjs} +23 -14
- package/dist/{vocab-DJTYMqyU.d.cts → vocab-Dw1-yVGg.d.cts} +290 -0
- package/dist/webfinger/handler.test.js +23 -22
- package/dist/webfinger/lookup.test.js +9 -9
- package/dist/webfinger/mod.cjs +2 -2
- package/dist/webfinger/mod.js +2 -2
- package/dist/x/cfworkers.test.js +8 -8
- package/dist/x/hono.d.cts +6 -6
- package/dist/x/hono.d.ts +6 -6
- package/dist/x/sveltekit.d.cts +6 -6
- package/dist/x/sveltekit.d.ts +6 -6
- package/package.json +1 -1
- package/dist/key-D-7DPHNl.cjs +0 -10
- package/dist/middleware-BHboQ4BE.js +0 -25
- package/dist/middleware-Bp3I9z8r.js +0 -17
- package/dist/middleware-oYqSU5ky.cjs +0 -17
- /package/dist/{assert_is_error-B035L3om.js → assert_is_error-BPGph1Jx.js} +0 -0
- /package/dist/{assert_not_equals-C80BG-_5.js → assert_not_equals-f3m3epl3.js} +0 -0
- /package/dist/{denokv-jZ0Z2h0M.js → denokv-Bv33Xxea.js} +0 -0
- /package/dist/{retry-CfF8Gn4d.js → retry-D4GJ670a.js} +0 -0
- /package/dist/{std__assert-DWivtrGR.js → std__assert-X-_kMxKM.js} +0 -0
@@ -3,15 +3,15 @@
|
|
3
3
|
import { URLPattern } from "urlpattern-polyfill";
|
4
4
|
|
5
5
|
import { getDefaultActivityTransformers } from "./transformers-BFT6d7J5.js";
|
6
|
-
import { deno_default, getDocumentLoader, kvCache } from "./docloader-
|
7
|
-
import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId } from "./actor-
|
8
|
-
import { lookupWebFinger } from "./lookup-
|
9
|
-
import { exportJwk, importJwk, validateCryptoKey } from "./key-
|
10
|
-
import { doubleKnock, verifyRequest } from "./http-
|
11
|
-
import { detachSignature, doesActorOwnKey, getKeyOwner, hasSignature, signJsonLd, signObject, verifyJsonLd, verifyObject } from "./proof-
|
12
|
-
import { getNodeInfo, nodeInfoToJson } from "./types-
|
13
|
-
import { getAuthenticatedDocumentLoader } from "./authdocloader-
|
14
|
-
import { lookupObject, traverseCollection } from "./vocab-
|
6
|
+
import { deno_default, getDocumentLoader, kvCache } from "./docloader-DOmINJ1U.js";
|
7
|
+
import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId } from "./actor-menZmmiI.js";
|
8
|
+
import { lookupWebFinger } from "./lookup-D8tCnUj2.js";
|
9
|
+
import { exportJwk, importJwk, validateCryptoKey } from "./key-BnjofJ4e.js";
|
10
|
+
import { doubleKnock, verifyRequest } from "./http-gHyCrTrX.js";
|
11
|
+
import { detachSignature, doesActorOwnKey, getKeyOwner, hasSignature, signJsonLd, signObject, verifyJsonLd, verifyObject } from "./proof-D6pbnNx2.js";
|
12
|
+
import { getNodeInfo, nodeInfoToJson } from "./types-Db4ukgX8.js";
|
13
|
+
import { getAuthenticatedDocumentLoader } from "./authdocloader-CZsCIRLV.js";
|
14
|
+
import { lookupObject, traverseCollection } from "./vocab-CJHF7Q71.js";
|
15
15
|
import { getLogger, withContext } from "@logtape/logtape";
|
16
16
|
import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
|
17
17
|
import { encodeHex } from "byte-encodings/hex";
|
@@ -55,17 +55,34 @@ var InboxListenerSet = class InboxListenerSet {
|
|
55
55
|
return this.dispatchWithClass(activity)?.listener ?? null;
|
56
56
|
}
|
57
57
|
};
|
58
|
-
async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider }) {
|
58
|
+
async function routeActivity({ context: ctx, json, activity, recipient, inboxListeners, inboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider, idempotencyStrategy }) {
|
59
59
|
const logger$1 = getLogger([
|
60
60
|
"fedify",
|
61
61
|
"federation",
|
62
62
|
"inbox"
|
63
63
|
]);
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
let cacheKey = null;
|
65
|
+
if (activity.id != null) {
|
66
|
+
const inboxContext = inboxContextFactory(recipient, json, activity.id?.href, getTypeId(activity).href);
|
67
|
+
const strategy = idempotencyStrategy ?? "per-inbox";
|
68
|
+
let keyString;
|
69
|
+
if (typeof strategy === "function") {
|
70
|
+
const result = await strategy(inboxContext, activity);
|
71
|
+
keyString = result;
|
72
|
+
} else switch (strategy) {
|
73
|
+
case "global":
|
74
|
+
keyString = activity.id.href;
|
75
|
+
break;
|
76
|
+
case "per-origin":
|
77
|
+
keyString = `${ctx.origin}\n${activity.id.href}`;
|
78
|
+
break;
|
79
|
+
case "per-inbox":
|
80
|
+
keyString = `${ctx.origin}\n${activity.id.href}\n${recipient == null ? "sharedInbox" : `inbox\n${recipient}`}`;
|
81
|
+
break;
|
82
|
+
default: keyString = `${ctx.origin}\n${activity.id.href}`;
|
83
|
+
}
|
84
|
+
if (keyString != null) cacheKey = [...kvPrefixes.activityIdempotence, keyString];
|
85
|
+
}
|
69
86
|
if (cacheKey != null) {
|
70
87
|
const cached = await kv.get(cacheKey);
|
71
88
|
if (cached === true) {
|
@@ -307,6 +324,7 @@ var FederationBuilderImpl = class {
|
|
307
324
|
inboxListeners;
|
308
325
|
inboxErrorHandler;
|
309
326
|
sharedInboxKeyDispatcher;
|
327
|
+
idempotencyStrategy;
|
310
328
|
collectionTypeIds;
|
311
329
|
collectionCallbacks;
|
312
330
|
/**
|
@@ -321,7 +339,7 @@ var FederationBuilderImpl = class {
|
|
321
339
|
this.collectionTypeIds = {};
|
322
340
|
}
|
323
341
|
async build(options) {
|
324
|
-
const { FederationImpl: FederationImpl$1 } = await import("./middleware-
|
342
|
+
const { FederationImpl: FederationImpl$1 } = await import("./middleware-9KSLASn7.js");
|
325
343
|
const f = new FederationImpl$1(options);
|
326
344
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
327
345
|
f.router = this.router.clone();
|
@@ -343,6 +361,7 @@ var FederationBuilderImpl = class {
|
|
343
361
|
f.inboxListeners = this.inboxListeners?.clone();
|
344
362
|
f.inboxErrorHandler = this.inboxErrorHandler;
|
345
363
|
f.sharedInboxKeyDispatcher = this.sharedInboxKeyDispatcher;
|
364
|
+
f.idempotencyStrategy = this.idempotencyStrategy;
|
346
365
|
return f;
|
347
366
|
}
|
348
367
|
_getTracer() {
|
@@ -765,15 +784,19 @@ var FederationBuilderImpl = class {
|
|
765
784
|
setSharedKeyDispatcher: (dispatcher) => {
|
766
785
|
this.sharedInboxKeyDispatcher = dispatcher;
|
767
786
|
return setters;
|
787
|
+
},
|
788
|
+
withIdempotency: (strategy) => {
|
789
|
+
this.idempotencyStrategy = strategy;
|
790
|
+
return setters;
|
768
791
|
}
|
769
792
|
};
|
770
793
|
return setters;
|
771
794
|
}
|
772
|
-
setCollectionDispatcher(name,
|
773
|
-
return this.#setCustomCollectionDispatcher(name, "collection",
|
795
|
+
setCollectionDispatcher(name, itemType, path, dispatcher) {
|
796
|
+
return this.#setCustomCollectionDispatcher(name, "collection", itemType, path, dispatcher);
|
774
797
|
}
|
775
|
-
setOrderedCollectionDispatcher(name,
|
776
|
-
return this.#setCustomCollectionDispatcher(name, "orderedCollection",
|
798
|
+
setOrderedCollectionDispatcher(name, itemType, path, dispatcher) {
|
799
|
+
return this.#setCustomCollectionDispatcher(name, "orderedCollection", itemType, path, dispatcher);
|
777
800
|
}
|
778
801
|
#setCustomCollectionDispatcher(name, collectionType, itemType, path, dispatcher) {
|
779
802
|
const strName = String(name);
|
@@ -979,9 +1002,6 @@ function preferredMediaTypes(accept) {
|
|
979
1002
|
const accepts = parseAccept(accept === void 0 ? "*/*" : accept ?? "");
|
980
1003
|
return accepts.filter(isQuality).sort(compareSpecs).map(getFullType);
|
981
1004
|
}
|
982
|
-
|
983
|
-
//#endregion
|
984
|
-
//#region src/federation/handler.ts
|
985
1005
|
function acceptsJsonLd(request) {
|
986
1006
|
const accept = request.headers.get("Accept");
|
987
1007
|
const types = accept ? preferredMediaTypes(accept) : ["*/*"];
|
@@ -989,6 +1009,9 @@ function acceptsJsonLd(request) {
|
|
989
1009
|
if (types[0] === "text/html" || types[0] === "application/xhtml+xml") return false;
|
990
1010
|
return types.includes("application/activity+json") || types.includes("application/ld+json") || types.includes("application/json");
|
991
1011
|
}
|
1012
|
+
|
1013
|
+
//#endregion
|
1014
|
+
//#region src/federation/handler.ts
|
992
1015
|
/**
|
993
1016
|
* Handles an actor request.
|
994
1017
|
* @template TContextData The context data to pass to the context.
|
@@ -996,7 +1019,7 @@ function acceptsJsonLd(request) {
|
|
996
1019
|
* @param parameters The parameters for handling the actor.
|
997
1020
|
* @returns A promise that resolves to an HTTP response.
|
998
1021
|
*/
|
999
|
-
async function handleActor(request, { identifier, context: context$1, actorDispatcher, authorizePredicate, onNotFound,
|
1022
|
+
async function handleActor(request, { identifier, context: context$1, actorDispatcher, authorizePredicate, onNotFound, onUnauthorized }) {
|
1000
1023
|
const logger$1 = getLogger([
|
1001
1024
|
"fedify",
|
1002
1025
|
"federation",
|
@@ -1011,7 +1034,6 @@ async function handleActor(request, { identifier, context: context$1, actorDispa
|
|
1011
1034
|
logger$1.debug("Actor {identifier} not found.", { identifier });
|
1012
1035
|
return await onNotFound(request);
|
1013
1036
|
}
|
1014
|
-
if (!acceptsJsonLd(request)) return await onNotAcceptable(request);
|
1015
1037
|
if (authorizePredicate != null) {
|
1016
1038
|
let key = await context$1.getSignedKey();
|
1017
1039
|
key = key?.clone({}, { $warning: {
|
@@ -1046,11 +1068,10 @@ async function handleActor(request, { identifier, context: context$1, actorDispa
|
|
1046
1068
|
* @param parameters The parameters for handling the object.
|
1047
1069
|
* @returns A promise that resolves to an HTTP response.
|
1048
1070
|
*/
|
1049
|
-
async function handleObject(request, { values, context: context$1, objectDispatcher, authorizePredicate, onNotFound,
|
1071
|
+
async function handleObject(request, { values, context: context$1, objectDispatcher, authorizePredicate, onNotFound, onUnauthorized }) {
|
1050
1072
|
if (objectDispatcher == null) return await onNotFound(request);
|
1051
1073
|
const object = await objectDispatcher(context$1, values);
|
1052
1074
|
if (object == null) return await onNotFound(request);
|
1053
|
-
if (!acceptsJsonLd(request)) return await onNotAcceptable(request);
|
1054
1075
|
if (authorizePredicate != null) {
|
1055
1076
|
let key = await context$1.getSignedKey();
|
1056
1077
|
key = key?.clone({}, { $warning: {
|
@@ -1088,7 +1109,7 @@ async function handleObject(request, { values, context: context$1, objectDispatc
|
|
1088
1109
|
* @param parameters The parameters for handling the collection.
|
1089
1110
|
* @returns A promise that resolves to an HTTP response.
|
1090
1111
|
*/
|
1091
|
-
async function handleCollection(request, { name, identifier, uriGetter, filter, filterPredicate, context: context$1, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound
|
1112
|
+
async function handleCollection(request, { name, identifier, uriGetter, filter, filterPredicate, context: context$1, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound }) {
|
1092
1113
|
const spanName = name.trim().replace(/\s+/g, "_");
|
1093
1114
|
tracerProvider = tracerProvider ?? trace.getTracerProvider();
|
1094
1115
|
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
@@ -1201,7 +1222,6 @@ async function handleCollection(request, { name, identifier, uriGetter, filter,
|
|
1201
1222
|
partOf
|
1202
1223
|
});
|
1203
1224
|
}
|
1204
|
-
if (!acceptsJsonLd(request)) return await onNotAcceptable(request);
|
1205
1225
|
if (collectionCallbacks.authorizePredicate != null) {
|
1206
1226
|
let key = await context$1.getSignedKey();
|
1207
1227
|
key = key?.clone({}, { $warning: {
|
@@ -1296,7 +1316,8 @@ async function handleInbox(request, options) {
|
|
1296
1316
|
* @param span The OpenTelemetry span for tracing.
|
1297
1317
|
* @returns A promise that resolves to an HTTP response.
|
1298
1318
|
*/
|
1299
|
-
async function handleInboxInternal(request,
|
1319
|
+
async function handleInboxInternal(request, parameters, span) {
|
1320
|
+
const { recipient, context: ctx, inboxContextFactory, kv, kvPrefixes, queue, actorDispatcher, inboxListeners, inboxErrorHandler, onNotFound, signatureTimeWindow, skipSignatureVerification, tracerProvider } = parameters;
|
1300
1321
|
const logger$1 = getLogger([
|
1301
1322
|
"fedify",
|
1302
1323
|
"federation",
|
@@ -1498,7 +1519,8 @@ async function handleInboxInternal(request, { recipient, context: ctx, inboxCont
|
|
1498
1519
|
kvPrefixes,
|
1499
1520
|
queue,
|
1500
1521
|
span,
|
1501
|
-
tracerProvider
|
1522
|
+
tracerProvider,
|
1523
|
+
idempotencyStrategy: parameters.idempotencyStrategy
|
1502
1524
|
});
|
1503
1525
|
if (routeResult === "alreadyProcessed") return new Response(`Activity <${activity.id}> has already been processed.`, {
|
1504
1526
|
status: 202,
|
@@ -1528,7 +1550,7 @@ async function handleInboxInternal(request, { recipient, context: ctx, inboxCont
|
|
1528
1550
|
/**
|
1529
1551
|
* Handles a custom collection request.
|
1530
1552
|
* @template TItem The type of items in the collection.
|
1531
|
-
* @template
|
1553
|
+
* @template TParam The parameter names of the requested URL.
|
1532
1554
|
* @template TContext The type of the context, extending {@link RequestContext}.
|
1533
1555
|
* @template TContextData The context data to pass to the `TContext`.
|
1534
1556
|
* @param request The HTTP request.
|
@@ -1539,7 +1561,6 @@ async function handleInboxInternal(request, { recipient, context: ctx, inboxCont
|
|
1539
1561
|
const handleCustomCollection = exceptWrapper(_handleCustomCollection);
|
1540
1562
|
async function _handleCustomCollection(request, { name, values, context: context$1, tracerProvider, collectionCallbacks: callbacks, filterPredicate }) {
|
1541
1563
|
verifyDefined(callbacks);
|
1542
|
-
verifyJsonLdRequest(request);
|
1543
1564
|
await authIfNeeded(context$1, values, callbacks);
|
1544
1565
|
const cursor = new URL(request.url).searchParams.get("cursor");
|
1545
1566
|
return await new CustomCollectionHandler(name, values, context$1, callbacks, tracerProvider, Collection, CollectionPage, filterPredicate).fetchCollection(cursor).toJsonLd().then(respondAsActivity);
|
@@ -1547,7 +1568,7 @@ async function _handleCustomCollection(request, { name, values, context: context
|
|
1547
1568
|
/**
|
1548
1569
|
* Handles an ordered collection request.
|
1549
1570
|
* @template TItem The type of items in the collection.
|
1550
|
-
* @template
|
1571
|
+
* @template TParam The parameter names of the requested URL.
|
1551
1572
|
* @template TContext The type of the context, extending {@link RequestContext}.
|
1552
1573
|
* @template TContextData The context data to pass to the `TContext`.
|
1553
1574
|
* @param request The HTTP request.
|
@@ -1558,7 +1579,6 @@ async function _handleCustomCollection(request, { name, values, context: context
|
|
1558
1579
|
const handleOrderedCollection = exceptWrapper(_handleOrderedCollection);
|
1559
1580
|
async function _handleOrderedCollection(request, { name, values, context: context$1, tracerProvider, collectionCallbacks: callbacks, filterPredicate }) {
|
1560
1581
|
verifyDefined(callbacks);
|
1561
|
-
verifyJsonLdRequest(request);
|
1562
1582
|
await authIfNeeded(context$1, values, callbacks);
|
1563
1583
|
const cursor = new URL(request.url).searchParams.get("cursor");
|
1564
1584
|
return await new CustomCollectionHandler(name, values, context$1, callbacks, tracerProvider, OrderedCollection, OrderedCollectionPage, filterPredicate).fetchCollection(cursor).toJsonLd().then(respondAsActivity);
|
@@ -1568,7 +1588,7 @@ async function _handleOrderedCollection(request, { name, values, context: contex
|
|
1568
1588
|
* The main flow is on `getCollection`, `dispatch`.
|
1569
1589
|
*
|
1570
1590
|
* @template TItem The type of items in the collection.
|
1571
|
-
* @template
|
1591
|
+
* @template TParam The parameter names of the requested URL.
|
1572
1592
|
* @template TContext The type of the context. {@link Context} or {@link RequestContext}.
|
1573
1593
|
* @template TContextData The context data to pass to the `TContext`.
|
1574
1594
|
* @template TCollection The type of the collection, extending {@link Collection}.
|
@@ -1602,14 +1622,14 @@ var CustomCollectionHandler = class {
|
|
1602
1622
|
#collection = null;
|
1603
1623
|
/**
|
1604
1624
|
* Creates a new CustomCollection instance.
|
1605
|
-
* @param
|
1606
|
-
* @param
|
1607
|
-
* @param
|
1608
|
-
* @param
|
1609
|
-
* @param
|
1610
|
-
* @param
|
1611
|
-
* @param
|
1612
|
-
* @param
|
1625
|
+
* @param name The name of the collection.
|
1626
|
+
* @param values The parameter values for the collection.
|
1627
|
+
* @param context The request context.
|
1628
|
+
* @param callbacks The collection callbacks.
|
1629
|
+
* @param tracerProvider The tracer provider for telemetry.
|
1630
|
+
* @param Collection The Collection constructor.
|
1631
|
+
* @param CollectionPage The CollectionPage constructor.
|
1632
|
+
* @param filterPredicate Optional filter predicate for items.
|
1613
1633
|
*/
|
1614
1634
|
constructor(name, values, context$1, callbacks, tracerProvider = trace.getTracerProvider(), Collection$1, CollectionPage$1, filterPredicate) {
|
1615
1635
|
this.name = name;
|
@@ -1734,7 +1754,7 @@ var CustomCollectionHandler = class {
|
|
1734
1754
|
/**
|
1735
1755
|
* Creates a function to wrap the dispatcher so tracing can be applied.
|
1736
1756
|
* @param params Parameters including cursor and total items.
|
1737
|
-
* @returns
|
1757
|
+
* @returns A function that handles the span operation.
|
1738
1758
|
*/
|
1739
1759
|
spanPages = ({ totalItems = null, cursor = null }) => async (span) => {
|
1740
1760
|
try {
|
@@ -1755,23 +1775,23 @@ var CustomCollectionHandler = class {
|
|
1755
1775
|
};
|
1756
1776
|
/**
|
1757
1777
|
* Dispatches the collection request to get items.
|
1758
|
-
* @param
|
1759
|
-
* @returns
|
1778
|
+
* @param cursor The cursor for pagination, or null for the first page.
|
1779
|
+
* @returns A promise that resolves to the page items.
|
1760
1780
|
*/
|
1761
1781
|
async dispatch(cursor = null) {
|
1762
1782
|
return await this.#dispatcher(this.context, this.values, cursor) ?? new ItemsNotFoundError().throw();
|
1763
1783
|
}
|
1764
1784
|
/**
|
1765
1785
|
* Filters the items in the collection.
|
1766
|
-
* @param
|
1767
|
-
* @returns
|
1786
|
+
* @param items The items to filter.
|
1787
|
+
* @returns The filtered items.
|
1768
1788
|
*/
|
1769
1789
|
filterItems(items) {
|
1770
1790
|
return filterCollectionItems(items, this.name, this.filterPredicate);
|
1771
1791
|
}
|
1772
1792
|
/**
|
1773
1793
|
* Appends a cursor to the URL if it exists.
|
1774
|
-
* @param
|
1794
|
+
* @param cursor The cursor to append, or null/undefined.
|
1775
1795
|
* @returns The URL with cursor appended, or null if cursor is null/undefined.
|
1776
1796
|
*/
|
1777
1797
|
appendToUrl(cursor) {
|
@@ -1779,8 +1799,7 @@ var CustomCollectionHandler = class {
|
|
1779
1799
|
}
|
1780
1800
|
/**
|
1781
1801
|
* Gets the stored collection or collection page.
|
1782
|
-
* @returns
|
1783
|
-
the collection or collection page.
|
1802
|
+
* @returns A promise that resolves to the collection or collection page.
|
1784
1803
|
*/
|
1785
1804
|
get collection() {
|
1786
1805
|
if (this.#collection === null) this.#collection = this.getCollection();
|
@@ -1788,8 +1807,8 @@ var CustomCollectionHandler = class {
|
|
1788
1807
|
}
|
1789
1808
|
/**
|
1790
1809
|
* Gets the total number of items in the collection.
|
1791
|
-
* @returns
|
1792
|
-
|
1810
|
+
* @returns A promise that resolves to the total items count,
|
1811
|
+
* or null if not available.
|
1793
1812
|
*/
|
1794
1813
|
get totalItems() {
|
1795
1814
|
if (this.#totalItems === void 0) this.totalItems = this.callbacks.counter?.(this.context, this.values);
|
@@ -1805,8 +1824,8 @@ var CustomCollectionHandler = class {
|
|
1805
1824
|
}
|
1806
1825
|
/**
|
1807
1826
|
* Gets the first cursor for pagination.
|
1808
|
-
* @returns
|
1809
|
-
or null if not available.
|
1827
|
+
* @returns A promise that resolves to the first cursor,
|
1828
|
+
* or null if not available.
|
1810
1829
|
*/
|
1811
1830
|
get firstCursor() {
|
1812
1831
|
const cursor = this.callbacks.firstCursor?.(this.context, this.values);
|
@@ -1836,10 +1855,9 @@ function exceptWrapper(handler) {
|
|
1836
1855
|
try {
|
1837
1856
|
return await handler(request, handlerParams);
|
1838
1857
|
} catch (error) {
|
1839
|
-
const { onNotFound,
|
1858
|
+
const { onNotFound, onUnauthorized } = handlerParams;
|
1840
1859
|
switch (error?.constructor) {
|
1841
1860
|
case ItemsNotFoundError: return await onNotFound(request);
|
1842
|
-
case NotAcceptableError: return await onNotAcceptable(request);
|
1843
1861
|
case UnauthorizedError: return await onUnauthorized(request);
|
1844
1862
|
default: throw error;
|
1845
1863
|
}
|
@@ -1857,15 +1875,6 @@ const verifyDefined = (callbacks) => {
|
|
1857
1875
|
if (callbacks === void 0) throw new ItemsNotFoundError();
|
1858
1876
|
};
|
1859
1877
|
/**
|
1860
|
-
* Verifies that a request accepts JSON-LD content type.
|
1861
|
-
* @param request The HTTP request to verify.
|
1862
|
-
* @throws {NotAcceptableError} If the request doesn't accept JSON-LD.
|
1863
|
-
* @since 1.8.0
|
1864
|
-
*/
|
1865
|
-
const verifyJsonLdRequest = (request) => {
|
1866
|
-
if (!acceptsJsonLd(request)) throw new NotAcceptableError();
|
1867
|
-
};
|
1868
|
-
/**
|
1869
1878
|
* Performs authorization if needed based on the authorization predicate.
|
1870
1879
|
* @template TContextData The context data type.
|
1871
1880
|
* @param {RequestContext<TContextData>} context The request context.
|
@@ -1949,15 +1958,6 @@ var ItemsNotFoundError = class extends HandlerError {
|
|
1949
1958
|
}
|
1950
1959
|
};
|
1951
1960
|
/**
|
1952
|
-
* Error thrown when the request is not acceptable (e.g., wrong content type).
|
1953
|
-
* @since 1.8.0
|
1954
|
-
*/
|
1955
|
-
var NotAcceptableError = class extends HandlerError {
|
1956
|
-
constructor() {
|
1957
|
-
super("The request is not acceptable.");
|
1958
|
-
}
|
1959
|
-
};
|
1960
|
-
/**
|
1961
1961
|
* Error thrown when access to a collection is unauthorized.
|
1962
1962
|
* @since 1.8.0
|
1963
1963
|
*/
|
@@ -2349,7 +2349,6 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
2349
2349
|
firstKnock;
|
2350
2350
|
constructor(options) {
|
2351
2351
|
super();
|
2352
|
-
const logger$1 = getLogger(["fedify", "federation"]);
|
2353
2352
|
this.kv = options.kv;
|
2354
2353
|
this.kvPrefixes = {
|
2355
2354
|
activityIdempotence: ["_fedify", "activityIdempotence"],
|
@@ -2397,8 +2396,9 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
2397
2396
|
this.router.trailingSlashInsensitive = options.trailingSlashInsensitive ?? false;
|
2398
2397
|
this._initializeRouter();
|
2399
2398
|
if (options.allowPrivateAddress || options.userAgent != null) {
|
2400
|
-
if (options.
|
2401
|
-
|
2399
|
+
if (options.documentLoaderFactory != null) throw new TypeError("Cannot set documentLoaderFactory with allowPrivateAddress or userAgent options.");
|
2400
|
+
if (options.contextLoaderFactory != null) throw new TypeError("Cannot set contextLoaderFactory with allowPrivateAddress or userAgent options.");
|
2401
|
+
if (options.authenticatedDocumentLoaderFactory != null) throw new TypeError("Cannot set authenticatedDocumentLoaderFactory with allowPrivateAddress or userAgent options.");
|
2402
2402
|
}
|
2403
2403
|
const { allowPrivateAddress, userAgent } = options;
|
2404
2404
|
this.allowPrivateAddress = allowPrivateAddress ?? false;
|
@@ -2412,11 +2412,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
2412
2412
|
prefix: this.kvPrefixes.remoteDocument
|
2413
2413
|
});
|
2414
2414
|
});
|
2415
|
-
|
2416
|
-
if (options.contextLoaderFactory != null) throw new TypeError("Cannot set both contextLoader and contextLoaderFactory options at a time; use contextLoaderFactory only.");
|
2417
|
-
this.contextLoaderFactory = () => options.contextLoader;
|
2418
|
-
logger$1.warn("The contextLoader option is deprecated; use contextLoaderFactory option instead.");
|
2419
|
-
} else this.contextLoaderFactory = options.contextLoaderFactory ?? this.documentLoaderFactory;
|
2415
|
+
this.contextLoaderFactory = options.contextLoaderFactory ?? this.documentLoaderFactory;
|
2420
2416
|
this.authenticatedDocumentLoaderFactory = options.authenticatedDocumentLoaderFactory ?? ((identity) => getAuthenticatedDocumentLoader(identity, {
|
2421
2417
|
allowPrivateAddress,
|
2422
2418
|
userAgent,
|
@@ -2955,6 +2951,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
2955
2951
|
span,
|
2956
2952
|
tracer
|
2957
2953
|
});
|
2954
|
+
if (acceptsJsonLd(request)) response.headers.set("Vary", "Accept");
|
2958
2955
|
} catch (error) {
|
2959
2956
|
span.setStatus({
|
2960
2957
|
code: SpanStatusCode.ERROR,
|
@@ -3018,6 +3015,9 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3018
3015
|
context: context$1,
|
3019
3016
|
nodeInfoDispatcher: this.nodeInfoDispatcher
|
3020
3017
|
});
|
3018
|
+
}
|
3019
|
+
if (request.method !== "POST" && !acceptsJsonLd(request)) return await onNotAcceptable(request);
|
3020
|
+
switch (routeName) {
|
3021
3021
|
case "actor":
|
3022
3022
|
context$1 = this.#createContext(request, contextData, { invokedFromActorDispatcher: { identifier: route.values.identifier ?? route.values.handle } });
|
3023
3023
|
return await handleActor(request, {
|
@@ -3026,8 +3026,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3026
3026
|
actorDispatcher: this.actorCallbacks?.dispatcher,
|
3027
3027
|
authorizePredicate: this.actorCallbacks?.authorizePredicate,
|
3028
3028
|
onUnauthorized,
|
3029
|
-
onNotFound
|
3030
|
-
onNotAcceptable
|
3029
|
+
onNotFound
|
3031
3030
|
});
|
3032
3031
|
case "object": {
|
3033
3032
|
const typeId = route.name.replace(/^object:/, "");
|
@@ -3043,8 +3042,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3043
3042
|
objectDispatcher: callbacks?.dispatcher,
|
3044
3043
|
authorizePredicate: callbacks?.authorizePredicate,
|
3045
3044
|
onUnauthorized,
|
3046
|
-
onNotFound
|
3047
|
-
onNotAcceptable
|
3045
|
+
onNotFound
|
3048
3046
|
});
|
3049
3047
|
}
|
3050
3048
|
case "outbox": return await handleCollection(request, {
|
@@ -3055,8 +3053,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3055
3053
|
collectionCallbacks: this.outboxCallbacks,
|
3056
3054
|
tracerProvider: this.tracerProvider,
|
3057
3055
|
onUnauthorized,
|
3058
|
-
onNotFound
|
3059
|
-
onNotAcceptable
|
3056
|
+
onNotFound
|
3060
3057
|
});
|
3061
3058
|
case "inbox":
|
3062
3059
|
if (request.method !== "POST") return await handleCollection(request, {
|
@@ -3067,8 +3064,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3067
3064
|
collectionCallbacks: this.inboxCallbacks,
|
3068
3065
|
tracerProvider: this.tracerProvider,
|
3069
3066
|
onUnauthorized,
|
3070
|
-
onNotFound
|
3071
|
-
onNotAcceptable
|
3067
|
+
onNotFound
|
3072
3068
|
});
|
3073
3069
|
context$1 = this.#createContext(request, contextData, { documentLoader: await context$1.getDocumentLoader({ identifier: route.values.identifier ?? route.values.handle }) });
|
3074
3070
|
case "sharedInbox":
|
@@ -3090,7 +3086,8 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3090
3086
|
onNotFound,
|
3091
3087
|
signatureTimeWindow: this.signatureTimeWindow,
|
3092
3088
|
skipSignatureVerification: this.skipSignatureVerification,
|
3093
|
-
tracerProvider: this.tracerProvider
|
3089
|
+
tracerProvider: this.tracerProvider,
|
3090
|
+
idempotencyStrategy: this.idempotencyStrategy
|
3094
3091
|
});
|
3095
3092
|
case "following": return await handleCollection(request, {
|
3096
3093
|
name: "following",
|
@@ -3100,8 +3097,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3100
3097
|
collectionCallbacks: this.followingCallbacks,
|
3101
3098
|
tracerProvider: this.tracerProvider,
|
3102
3099
|
onUnauthorized,
|
3103
|
-
onNotFound
|
3104
|
-
onNotAcceptable
|
3100
|
+
onNotFound
|
3105
3101
|
});
|
3106
3102
|
case "followers": {
|
3107
3103
|
let baseUrl = url.searchParams.get("base-url");
|
@@ -3124,8 +3120,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3124
3120
|
collectionCallbacks: this.followersCallbacks,
|
3125
3121
|
tracerProvider: this.tracerProvider,
|
3126
3122
|
onUnauthorized,
|
3127
|
-
onNotFound
|
3128
|
-
onNotAcceptable
|
3123
|
+
onNotFound
|
3129
3124
|
});
|
3130
3125
|
}
|
3131
3126
|
case "liked": return await handleCollection(request, {
|
@@ -3136,8 +3131,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3136
3131
|
collectionCallbacks: this.likedCallbacks,
|
3137
3132
|
tracerProvider: this.tracerProvider,
|
3138
3133
|
onUnauthorized,
|
3139
|
-
onNotFound
|
3140
|
-
onNotAcceptable
|
3134
|
+
onNotFound
|
3141
3135
|
});
|
3142
3136
|
case "featured": return await handleCollection(request, {
|
3143
3137
|
name: "featured",
|
@@ -3147,8 +3141,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3147
3141
|
collectionCallbacks: this.featuredCallbacks,
|
3148
3142
|
tracerProvider: this.tracerProvider,
|
3149
3143
|
onUnauthorized,
|
3150
|
-
onNotFound
|
3151
|
-
onNotAcceptable
|
3144
|
+
onNotFound
|
3152
3145
|
});
|
3153
3146
|
case "featuredTags": return await handleCollection(request, {
|
3154
3147
|
name: "featured tags",
|
@@ -3158,8 +3151,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3158
3151
|
collectionCallbacks: this.featuredTagsCallbacks,
|
3159
3152
|
tracerProvider: this.tracerProvider,
|
3160
3153
|
onUnauthorized,
|
3161
|
-
onNotFound
|
3162
|
-
onNotAcceptable
|
3154
|
+
onNotFound
|
3163
3155
|
});
|
3164
3156
|
case "collection": {
|
3165
3157
|
const name = route.name.replace(/^collection:/, "");
|
@@ -3171,8 +3163,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3171
3163
|
collectionCallbacks: callbacks,
|
3172
3164
|
tracerProvider: this.tracerProvider,
|
3173
3165
|
onUnauthorized,
|
3174
|
-
onNotFound
|
3175
|
-
onNotAcceptable
|
3166
|
+
onNotFound
|
3176
3167
|
});
|
3177
3168
|
}
|
3178
3169
|
case "orderedCollection": {
|
@@ -3185,8 +3176,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
3185
3176
|
collectionCallbacks: callbacks,
|
3186
3177
|
tracerProvider: this.tracerProvider,
|
3187
3178
|
onUnauthorized,
|
3188
|
-
onNotFound
|
3189
|
-
onNotAcceptable
|
3179
|
+
onNotFound
|
3190
3180
|
});
|
3191
3181
|
}
|
3192
3182
|
default: {
|
@@ -3840,7 +3830,8 @@ var ContextImpl = class ContextImpl {
|
|
3840
3830
|
kvPrefixes: this.federation.kvPrefixes,
|
3841
3831
|
queue: this.federation.inboxQueue,
|
3842
3832
|
span,
|
3843
|
-
tracerProvider: options.tracerProvider ?? this.tracerProvider
|
3833
|
+
tracerProvider: options.tracerProvider ?? this.tracerProvider,
|
3834
|
+
idempotencyStrategy: this.federation.idempotencyStrategy
|
3844
3835
|
});
|
3845
3836
|
return routeResult === "alreadyProcessed" || routeResult === "enqueued" || routeResult === "unsupportedActivity" || routeResult === "success";
|
3846
3837
|
}
|