@fedify/fedify 0.11.0-dev.229 → 0.11.0-dev.234
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGES.md +6 -0
- package/esm/federation/middleware.js +80 -8
- package/esm/vocab/vocab.js +3385 -394
- package/package.json +1 -1
- package/types/codegen/type.d.ts.map +1 -1
- package/types/federation/middleware.d.ts +15 -1
- package/types/federation/middleware.d.ts.map +1 -1
- package/types/vocab/vocab.d.ts +381 -381
- package/types/vocab/vocab.d.ts.map +1 -1
package/CHANGES.md
CHANGED
@@ -8,6 +8,10 @@ Version 0.11.0
|
|
8
8
|
|
9
9
|
To be released.
|
10
10
|
|
11
|
+
- Improved runtime type error messages for Activity Vocabulary API. [[#79]]
|
12
|
+
|
13
|
+
- Added `Federation.setInboxDispatcher()` method. [[#71]]
|
14
|
+
|
11
15
|
- Frequently used JSON-LD contexts are now preloaded. [[74]]
|
12
16
|
|
13
17
|
- The `fetchDocumentLoader()` function now preloads the following JSON-LD
|
@@ -25,8 +29,10 @@ To be released.
|
|
25
29
|
- Added `Offer` class to Activity Vocabulary API.
|
26
30
|
[[#65], [#76] by Lee Dogeon]
|
27
31
|
|
32
|
+
[#71]: https://github.com/dahlia/fedify/issues/71
|
28
33
|
[#74]: https://github.com/dahlia/fedify/issues/74
|
29
34
|
[#76]: https://github.com/dahlia/fedify/pull/76
|
35
|
+
[#79]: https://github.com/dahlia/fedify/issues/79
|
30
36
|
|
31
37
|
|
32
38
|
Version 0.10.0
|
@@ -42,6 +42,8 @@ export class Federation {
|
|
42
42
|
#actorCallbacks;
|
43
43
|
#objectCallbacks;
|
44
44
|
#objectTypeIds;
|
45
|
+
#inboxPath;
|
46
|
+
#inboxCallbacks;
|
45
47
|
#outboxCallbacks;
|
46
48
|
#followingCallbacks;
|
47
49
|
#followersCallbacks;
|
@@ -79,7 +81,6 @@ export class Federation {
|
|
79
81
|
this.#router = new Router();
|
80
82
|
this.#router.add("/.well-known/webfinger", "webfinger");
|
81
83
|
this.#router.add("/.well-known/nodeinfo", "nodeInfoJrd");
|
82
|
-
this.#inboxListeners = new Map();
|
83
84
|
this.#objectCallbacks = {};
|
84
85
|
this.#objectTypeIds = {};
|
85
86
|
this.#documentLoader = options.documentLoader ?? kvCache({
|
@@ -405,6 +406,58 @@ export class Federation {
|
|
405
406
|
};
|
406
407
|
return setters;
|
407
408
|
}
|
409
|
+
/**
|
410
|
+
* Registers an inbox dispatcher.
|
411
|
+
*
|
412
|
+
* @param path The URI path pattern for the outbox dispatcher. The syntax is
|
413
|
+
* based on URI Template
|
414
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
415
|
+
* must have one variable: `{handle}`, and must match the inbox
|
416
|
+
* listener path.
|
417
|
+
* @param dispatcher An inbox dispatcher callback to register.
|
418
|
+
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
419
|
+
* @since 0.11.0
|
420
|
+
*/
|
421
|
+
setInboxDispatcher(path, dispatcher) {
|
422
|
+
if (this.#inboxCallbacks != null) {
|
423
|
+
throw new RouterError("Inbox dispatcher already set.");
|
424
|
+
}
|
425
|
+
if (this.#router.has("inbox")) {
|
426
|
+
if (this.#inboxPath !== path) {
|
427
|
+
throw new RouterError("Inbox dispatcher path must match inbox listener path.");
|
428
|
+
}
|
429
|
+
}
|
430
|
+
else {
|
431
|
+
const variables = this.#router.add(path, "inbox");
|
432
|
+
if (variables.size !== 1 || !variables.has("handle")) {
|
433
|
+
throw new RouterError("Path for inbox dispatcher must have one variable: {handle}");
|
434
|
+
}
|
435
|
+
this.#inboxPath = path;
|
436
|
+
}
|
437
|
+
const callbacks = {
|
438
|
+
dispatcher,
|
439
|
+
};
|
440
|
+
this.#inboxCallbacks = callbacks;
|
441
|
+
const setters = {
|
442
|
+
setCounter(counter) {
|
443
|
+
callbacks.counter = counter;
|
444
|
+
return setters;
|
445
|
+
},
|
446
|
+
setFirstCursor(cursor) {
|
447
|
+
callbacks.firstCursor = cursor;
|
448
|
+
return setters;
|
449
|
+
},
|
450
|
+
setLastCursor(cursor) {
|
451
|
+
callbacks.lastCursor = cursor;
|
452
|
+
return setters;
|
453
|
+
},
|
454
|
+
authorize(predicate) {
|
455
|
+
callbacks.authorizePredicate = predicate;
|
456
|
+
return setters;
|
457
|
+
},
|
458
|
+
};
|
459
|
+
return setters;
|
460
|
+
}
|
408
461
|
/**
|
409
462
|
* Registers an outbox dispatcher.
|
410
463
|
*
|
@@ -567,7 +620,8 @@ export class Federation {
|
|
567
620
|
* @param inboxPath The URI path pattern for the inbox. The syntax is based
|
568
621
|
* on URI Template
|
569
622
|
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
570
|
-
* The path must have one variable: `{handle}
|
623
|
+
* The path must have one variable: `{handle}`, and must
|
624
|
+
* match the inbox dispatcher path.
|
571
625
|
* @param sharedInboxPath An optional URI path pattern for the shared inbox.
|
572
626
|
* The syntax is based on URI Template
|
573
627
|
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
@@ -576,12 +630,19 @@ export class Federation {
|
|
576
630
|
* @throws {RouteError} Thrown if the path pattern is invalid.
|
577
631
|
*/
|
578
632
|
setInboxListeners(inboxPath, sharedInboxPath) {
|
633
|
+
if (this.#inboxListeners != null) {
|
634
|
+
throw new RouterError("Inbox listeners already set.");
|
635
|
+
}
|
579
636
|
if (this.#router.has("inbox")) {
|
580
|
-
|
637
|
+
if (this.#inboxPath !== inboxPath) {
|
638
|
+
throw new RouterError("Inbox listener path must match inbox dispatcher path.");
|
639
|
+
}
|
581
640
|
}
|
582
|
-
|
583
|
-
|
584
|
-
|
641
|
+
else {
|
642
|
+
const variables = this.#router.add(inboxPath, "inbox");
|
643
|
+
if (variables.size !== 1 || !variables.has("handle")) {
|
644
|
+
throw new RouterError("Path for inbox must have one variable: {handle}");
|
645
|
+
}
|
585
646
|
}
|
586
647
|
if (sharedInboxPath != null) {
|
587
648
|
const siVars = this.#router.add(sharedInboxPath, "sharedInbox");
|
@@ -589,7 +650,7 @@ export class Federation {
|
|
589
650
|
throw new RouterError("Path for shared inbox must have no variables.");
|
590
651
|
}
|
591
652
|
}
|
592
|
-
const listeners = this.#inboxListeners;
|
653
|
+
const listeners = this.#inboxListeners = new Map();
|
593
654
|
const setter = {
|
594
655
|
on(
|
595
656
|
// deno-lint-ignore no-explicit-any
|
@@ -790,6 +851,17 @@ export class Federation {
|
|
790
851
|
onNotAcceptable,
|
791
852
|
});
|
792
853
|
case "inbox":
|
854
|
+
if (request.method !== "POST") {
|
855
|
+
return await handleCollection(request, {
|
856
|
+
name: "inbox",
|
857
|
+
handle: route.values.handle,
|
858
|
+
context,
|
859
|
+
collectionCallbacks: this.#inboxCallbacks,
|
860
|
+
onUnauthorized,
|
861
|
+
onNotFound,
|
862
|
+
onNotAcceptable,
|
863
|
+
});
|
864
|
+
}
|
793
865
|
context = this.#createContext(request, contextData, {
|
794
866
|
documentLoader: await context.getDocumentLoader({
|
795
867
|
handle: route.values.handle,
|
@@ -803,7 +875,7 @@ export class Federation {
|
|
803
875
|
kv: this.#kv,
|
804
876
|
kvPrefix: this.#kvPrefixes.activityIdempotence,
|
805
877
|
actorDispatcher: this.#actorCallbacks?.dispatcher,
|
806
|
-
inboxListeners: this.#inboxListeners,
|
878
|
+
inboxListeners: this.#inboxListeners ?? new Map(),
|
807
879
|
inboxErrorHandler: this.#inboxErrorHandler,
|
808
880
|
onNotFound,
|
809
881
|
signatureTimeWindow: this.#signatureTimeWindow,
|