@fedify/fedify 0.11.0-dev.236 → 0.11.0-dev.238

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGES.md CHANGED
@@ -10,7 +10,13 @@ To be released.
10
10
 
11
11
  - Improved runtime type error messages for Activity Vocabulary API. [[#79]]
12
12
 
13
- - Added `Federation.setInboxDispatcher()` method. [[#71]]
13
+ - Added `suppressError` option to dereferencing accessors of Activity
14
+ Vocabulary classes.
15
+
16
+ - Added more collection dispatchers. [[#78]]
17
+
18
+ - Added `Federation.setInboxDispatcher()` method. [[#71]]
19
+ - Added `Federation.setLikedDispatcher()` method.
14
20
 
15
21
  - Frequently used JSON-LD contexts are now preloaded. [[74]]
16
22
 
@@ -41,6 +47,7 @@ To be released.
41
47
  [#71]: https://github.com/dahlia/fedify/issues/71
42
48
  [#74]: https://github.com/dahlia/fedify/issues/74
43
49
  [#76]: https://github.com/dahlia/fedify/pull/76
50
+ [#78]: https://github.com/dahlia/fedify/issues/78
44
51
  [#79]: https://github.com/dahlia/fedify/issues/79
45
52
 
46
53
 
@@ -5,7 +5,7 @@ import { fetchDocumentLoader, getAuthenticatedDocumentLoader, kvCache, } from ".
5
5
  import { verifyRequest } from "../sig/http.js";
6
6
  import { exportJwk, importJwk, validateCryptoKey } from "../sig/key.js";
7
7
  import { getKeyOwner } from "../sig/owner.js";
8
- import { Activity, CryptographicKey, Multikey, } from "../vocab/mod.js";
8
+ import { Activity, CryptographicKey, Multikey, } from "../vocab/vocab.js";
9
9
  import { handleWebFinger } from "../webfinger/handler.js";
10
10
  import { buildCollectionSynchronizationHeader } from "./collection.js";
11
11
  import { handleActor, handleCollection, handleInbox, handleObject, } from "./handler.js";
@@ -47,6 +47,7 @@ export class Federation {
47
47
  #outboxCallbacks;
48
48
  #followingCallbacks;
49
49
  #followersCallbacks;
50
+ #likedCallbacks;
50
51
  #inboxListeners;
51
52
  #inboxErrorHandler;
52
53
  #sharedInboxKeyDispatcher;
@@ -600,6 +601,50 @@ export class Federation {
600
601
  };
601
602
  return setters;
602
603
  }
604
+ /**
605
+ * Registers a liked collection dispatcher.
606
+ * @param path The URI path pattern for the liked collection. The syntax
607
+ * is based on URI Template
608
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
609
+ * must have one variable: `{handle}`.
610
+ * @param dispatcher A liked collection callback to register.
611
+ * @returns An object with methods to set other liked collection
612
+ * callbacks.
613
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
614
+ * @since 0.11.0
615
+ */
616
+ setLikedDispatcher(path, dispatcher) {
617
+ if (this.#router.has("liked")) {
618
+ throw new RouterError("Liked collection dispatcher already set.");
619
+ }
620
+ const variables = this.#router.add(path, "liked");
621
+ if (variables.size !== 1 || !variables.has("handle")) {
622
+ throw new RouterError("Path for liked collection dispatcher must have one variable: {handle}");
623
+ }
624
+ const callbacks = {
625
+ dispatcher,
626
+ };
627
+ this.#likedCallbacks = callbacks;
628
+ const setters = {
629
+ setCounter(counter) {
630
+ callbacks.counter = counter;
631
+ return setters;
632
+ },
633
+ setFirstCursor(cursor) {
634
+ callbacks.firstCursor = cursor;
635
+ return setters;
636
+ },
637
+ setLastCursor(cursor) {
638
+ callbacks.lastCursor = cursor;
639
+ return setters;
640
+ },
641
+ authorize(predicate) {
642
+ callbacks.authorizePredicate = predicate;
643
+ return setters;
644
+ },
645
+ };
646
+ return setters;
647
+ }
603
648
  /**
604
649
  * Assigns the URL path for the inbox and starts setting inbox listeners.
605
650
  *
@@ -926,6 +971,16 @@ export class Federation {
926
971
  onNotAcceptable,
927
972
  });
928
973
  }
974
+ case "liked":
975
+ return await handleCollection(request, {
976
+ name: "liked",
977
+ handle: route.values.handle,
978
+ context,
979
+ collectionCallbacks: this.#likedCallbacks,
980
+ onUnauthorized,
981
+ onNotFound,
982
+ onNotAcceptable,
983
+ });
929
984
  default: {
930
985
  const response = onNotFound(request);
931
986
  return response instanceof Promise ? await response : response;
@@ -1024,6 +1079,13 @@ class ContextImpl {
1024
1079
  }
1025
1080
  return new URL(path, this.#url);
1026
1081
  }
1082
+ getLikedUri(handle) {
1083
+ const path = this.#router.build("liked", { handle });
1084
+ if (path == null) {
1085
+ throw new RouterError("No liked collection path registered.");
1086
+ }
1087
+ return new URL(path, this.#url);
1088
+ }
1027
1089
  parseUri(uri) {
1028
1090
  if (uri.origin !== this.#url.origin)
1029
1091
  return null;
@@ -1057,6 +1119,9 @@ class ContextImpl {
1057
1119
  else if (route.name === "followers") {
1058
1120
  return { type: "followers", handle: route.values.handle };
1059
1121
  }
1122
+ else if (route.name === "liked") {
1123
+ return { type: "liked", handle: route.values.handle };
1124
+ }
1060
1125
  return null;
1061
1126
  }
1062
1127
  getHandleFromActorUri(actorUri) {