@fedify/fedify 2.0.0-dev.1561 → 2.0.0-dev.158

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 (297) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +40 -18
  3. package/dist/{assert_rejects-DiIiJbZn.js → assert_rejects-Ce45JcFg.js} +1 -1
  4. package/dist/{assert_is_error-BPGph1Jx.js → assert_throws-BNXdRGWP.js} +31 -1
  5. package/dist/{builder-C8mpxJD3.js → builder-BnWso6VP.js} +15 -8
  6. package/dist/chunk-DqRYRqnO.cjs +34 -0
  7. package/dist/client-94iWEfQa.d.cts +222 -0
  8. package/dist/{client-DF8anIB5.d.ts → client-BivSNrEg.d.ts} +3 -75
  9. package/dist/{client-DI0GS_3p.js → client-CgMTXmAD.js} +3 -22
  10. package/dist/compat/mod.cjs +10 -0
  11. package/dist/compat/mod.d.cts +7 -0
  12. package/dist/compat/mod.d.ts +6 -12
  13. package/dist/compat/mod.js +5 -5
  14. package/dist/compat/transformers.test.js +21 -20
  15. package/dist/compat-DmDDELst.cjs +4 -0
  16. package/dist/compat-nxUqe4Z-.js +4 -0
  17. package/dist/context-Bns6uTJq.js +109 -0
  18. package/dist/{context-9gCpIkiz.d.ts → context-CYZ2i00R.d.ts} +321 -129
  19. package/dist/context-D2MrtLch.d.cts +2447 -0
  20. package/dist/deno-CQV858ip.js +117 -0
  21. package/dist/{testing-DsuOHyiF.js → dist-B5f6a8Tt.js} +90 -111
  22. package/dist/{authdocloader-CN-tWO4K.js → docloader-Csc8gQux.js} +17 -8
  23. package/dist/{esm-CtgLSZwm.js → esm-DGl7uK1r.js} +32 -17
  24. package/dist/federation/builder.test.js +12 -13
  25. package/dist/federation/collection.test.js +6 -9
  26. package/dist/federation/handler.test.js +115 -148
  27. package/dist/federation/idempotency.test.js +202 -0
  28. package/dist/federation/inbox.test.js +5 -6
  29. package/dist/federation/keycache.test.js +4 -5
  30. package/dist/federation/kv.test.js +61 -9
  31. package/dist/federation/middleware.test.js +311 -131
  32. package/dist/federation/mod.cjs +25 -0
  33. package/dist/federation/mod.d.cts +7 -0
  34. package/dist/federation/mod.d.ts +7 -13
  35. package/dist/federation/mod.js +11 -16
  36. package/dist/federation/mq.test.js +9 -10
  37. package/dist/federation/negotiation.test.js +25 -0
  38. package/dist/federation/retry.test.js +2 -4
  39. package/dist/federation/router.test.js +6 -8
  40. package/dist/federation/send.test.js +55 -15
  41. package/dist/{webfinger/handler.test.js → federation/webfinger.test.js} +27 -26
  42. package/dist/federation-B431K2gm.cjs +266 -0
  43. package/dist/{federation-CMX7WzeL.js → federation-BbZwNNWj.js} +31 -9
  44. package/dist/{http-B_tXwHIe.js → http-BizGfAHd.js} +375 -15
  45. package/dist/{http-DTJgsmYR.js → http-CXG5ZFqn.js} +4 -3
  46. package/dist/http-ClB3pLcL.d.cts +253 -0
  47. package/dist/{http-DqSNLFNY.d.ts → http-DLBDPal9.d.ts} +2 -2
  48. package/dist/http-DbACqYyq.cjs +1222 -0
  49. package/dist/{inbox-Dx8EjUbq.js → inbox-B7ybw6fk.js} +25 -7
  50. package/dist/{key-olV6hEgm.js → key-C27c_yHR.js} +3 -2
  51. package/dist/{keycache-CExtp4Yl.js → keycache-DRxpZ5r9.js} +1 -1
  52. package/dist/{keys-O0-r0NpJ.js → keys-ZbcByPg9.js} +2 -1
  53. package/dist/{kv-C7sopW2E.d.ts → kv-CtOmTRNc.d.ts} +30 -1
  54. package/dist/kv-D8q9fLkA.d.cts +110 -0
  55. package/dist/{kv-CRZrzyXm.js → kv-QzKcOQgP.js} +22 -0
  56. package/dist/kv-cache-B7dwGQFA.js +122 -0
  57. package/dist/kv-cache-BEeqyGER.js +107 -0
  58. package/dist/kv-cache-rPOPQdj9.cjs +134 -0
  59. package/dist/{ld-DR6b11xZ.js → ld-D_Jn1aGa.js} +6 -4
  60. package/dist/middleware-BVqYHBWm.cjs +12 -0
  61. package/dist/{middleware-GT7W03qw.js → middleware-BjS6_zkf.js} +272 -271
  62. package/dist/middleware-CAJR7KGo.cjs +4242 -0
  63. package/dist/{middleware-CUw3Ys9y.js → middleware-ClkhKNXU.js} +230 -327
  64. package/dist/middleware-DSz6sI16.js +26 -0
  65. package/dist/middleware-OcaFHSk8.js +12 -0
  66. package/dist/mod-BrS8tiad.d.cts +266 -0
  67. package/dist/mod-C81L6_lQ.d.cts +1 -0
  68. package/dist/mod-CJgbdSqb.d.ts +109 -0
  69. package/dist/mod-CNNTHyBC.d.cts +80 -0
  70. package/dist/mod-CS-MS7gZ.d.cts +62 -0
  71. package/dist/{mod-Bqxcp7eN.d.ts → mod-D_cmv2il.d.ts} +4 -4
  72. package/dist/mod-DcPRcifg.d.cts +107 -0
  73. package/dist/mod-DqFSzJA0.d.ts +64 -0
  74. package/dist/{mod-Drmz72EK.d.ts → mod-jOa7W503.d.ts} +3 -3
  75. package/dist/mod.cjs +55 -0
  76. package/dist/mod.d.cts +11 -0
  77. package/dist/mod.d.ts +11 -17
  78. package/dist/mod.js +15 -21
  79. package/dist/negotiation-5NPJL6zp.js +71 -0
  80. package/dist/nodeinfo/client.test.js +29 -111
  81. package/dist/nodeinfo/handler.test.js +26 -26
  82. package/dist/nodeinfo/mod.cjs +10 -0
  83. package/dist/nodeinfo/mod.d.cts +3 -0
  84. package/dist/nodeinfo/mod.d.ts +3 -5
  85. package/dist/nodeinfo/mod.js +6 -7
  86. package/dist/nodeinfo/types.test.js +7 -15
  87. package/dist/nodeinfo-BlLsRSiT.js +4 -0
  88. package/dist/nodeinfo-DuMYTpbZ.cjs +4 -0
  89. package/dist/otel/exporter.test.js +899 -0
  90. package/dist/otel/mod.cjs +262 -0
  91. package/dist/otel/mod.d.cts +230 -0
  92. package/dist/otel/mod.d.ts +232 -0
  93. package/dist/otel/mod.js +261 -0
  94. package/dist/{owner-CQPnQVtf.d.ts → owner-BgI8C-VY.d.ts} +2 -3
  95. package/dist/owner-C-zfmVAD.d.cts +66 -0
  96. package/dist/{owner-BtFz-dZ-.js → owner-Dc8rUE-H.js} +45 -8
  97. package/dist/{proof-DsZjVJ0G.js → proof-BdNM3iSl.js} +4 -3
  98. package/dist/proof-Bx2JqJ-D.cjs +709 -0
  99. package/dist/{proof-DKDM7T5F.js → proof-CTYnbjx5.js} +53 -17
  100. package/dist/router-D9eI0s4b.js +118 -0
  101. package/dist/{send-s0_EjVhZ.js → send-DBRRqVMa.js} +9 -4
  102. package/dist/sig/http.test.js +12 -14
  103. package/dist/sig/key.test.js +9 -11
  104. package/dist/sig/ld.test.js +8 -10
  105. package/dist/sig/mod.cjs +26 -0
  106. package/dist/sig/mod.d.cts +4 -0
  107. package/dist/sig/mod.d.ts +3 -7
  108. package/dist/sig/mod.js +6 -10
  109. package/dist/sig/owner.test.js +33 -12
  110. package/dist/sig/proof.test.js +13 -14
  111. package/dist/sig-CwuONEzF.js +4 -0
  112. package/dist/sig-DeXX2xnj.cjs +4 -0
  113. package/dist/testing/mod.d.ts +180 -6946
  114. package/dist/testing/mod.js +4 -4
  115. package/dist/transformers-BjBg6Lag.cjs +116 -0
  116. package/dist/{transformers-Dna8Fg7k.js → transformers-N_ip_y4P.js} +5 -5
  117. package/dist/{types-BIgY6c-l.js → types-BEdCLHqP.js} +1 -3
  118. package/dist/types-Q-qkJXBV.cjs +315 -0
  119. package/dist/{types-CGB4mJU6.js → types-hKTi53FO.js} +8 -169
  120. package/dist/{runtime/authdocloader.test.js → utils/docloader.test.js} +13 -15
  121. package/dist/utils/kv-cache.test.js +211 -0
  122. package/dist/utils/mod.cjs +10 -0
  123. package/dist/utils/mod.d.cts +4 -0
  124. package/dist/utils/mod.d.ts +6 -0
  125. package/dist/utils/mod.js +9 -0
  126. package/dist/utils-Db0ZmjcD.cjs +4 -0
  127. package/dist/utils-Wranxuoe.js +4 -0
  128. package/package.json +69 -55
  129. package/dist/actor-C22bXuuC.d.ts +0 -130
  130. package/dist/actor-Qc3Ee6k1.js +0 -37311
  131. package/dist/actor-mhluotIb.js +0 -146
  132. package/dist/assert_throws-BOO88avQ.js +0 -39
  133. package/dist/authdocloader-Dp9WS-1G.js +0 -52
  134. package/dist/compat-Bb5myD13.js +0 -4
  135. package/dist/denokv-Bv33Xxea.js +0 -57
  136. package/dist/docloader-CxWcuWqQ.d.ts +0 -221
  137. package/dist/docloader-DIjo5mkd.js +0 -4615
  138. package/dist/fixtures/activitypub.academy/users/brauca_darradiul.json +0 -83
  139. package/dist/fixtures/example.com/announce.json +0 -6
  140. package/dist/fixtures/example.com/collection.json +0 -19
  141. package/dist/fixtures/example.com/create.json +0 -6
  142. package/dist/fixtures/example.com/cross-origin-actor.json +0 -6
  143. package/dist/fixtures/example.com/hong-gildong.json +0 -11
  144. package/dist/fixtures/example.com/invite.json +0 -7
  145. package/dist/fixtures/example.com/key.json +0 -7
  146. package/dist/fixtures/example.com/key2.json +0 -6
  147. package/dist/fixtures/example.com/object.json +0 -6
  148. package/dist/fixtures/example.com/orderedcollectionpage.json +0 -24
  149. package/dist/fixtures/example.com/paged/a.json +0 -13
  150. package/dist/fixtures/example.com/paged/b.json +0 -16
  151. package/dist/fixtures/example.com/paged-collection.json +0 -6
  152. package/dist/fixtures/example.com/person.json +0 -22
  153. package/dist/fixtures/example.com/person2.json +0 -40
  154. package/dist/fixtures/example.com/test.json +0 -5
  155. package/dist/fixtures/example.com/users/handle.json +0 -16
  156. package/dist/fixtures/example.com/wrong-type.json +0 -3
  157. package/dist/fixtures/oeee.cafe/ap/users/3609fd4e-d51d-4db8-9f04-4189815864dd.json +0 -24
  158. package/dist/fixtures/remote.domain/users/bob.json +0 -20
  159. package/dist/fixtures/server.example/users/alice.json +0 -20
  160. package/dist/fixtures/w3id.org/identity/v1.json +0 -152
  161. package/dist/fixtures/w3id.org/security/data-integrity/v1.json +0 -74
  162. package/dist/fixtures/w3id.org/security/multikey/v1.json +0 -35
  163. package/dist/fixtures/w3id.org/security/v1.json +0 -50
  164. package/dist/fixtures/wizard.casa/users/hongminhee.json +0 -69
  165. package/dist/fixtures/www.w3.org/ns/activitystreams.json +0 -379
  166. package/dist/fixtures/www.w3.org/ns/did/v1.json +0 -58
  167. package/dist/key-CGjkGPkw.js +0 -260
  168. package/dist/key-CaFAQSic.js +0 -10
  169. package/dist/key-DcnCet42.js +0 -10
  170. package/dist/lookup-B8Ld9P9G.js +0 -131
  171. package/dist/lookup-IyAhz9I6.js +0 -322
  172. package/dist/middleware-Bx6Sgkth.js +0 -26
  173. package/dist/middleware-DdRB1d4s.js +0 -17
  174. package/dist/mod-Cxt4Kpf6.d.ts +0 -291
  175. package/dist/mod-DBzN0aCM.d.ts +0 -115
  176. package/dist/mod-TFoH2Ql8.d.ts +0 -104
  177. package/dist/mod-g0xFzAP9.d.ts +0 -2
  178. package/dist/mq-CRGm1e_F.d.ts +0 -143
  179. package/dist/nodeinfo/semver.test.js +0 -143
  180. package/dist/nodeinfo-CyEbLjHs.js +0 -4
  181. package/dist/runtime/docloader.test.js +0 -522
  182. package/dist/runtime/key.test.js +0 -103
  183. package/dist/runtime/langstr.test.js +0 -39
  184. package/dist/runtime/mod.d.ts +0 -8
  185. package/dist/runtime/mod.js +0 -13
  186. package/dist/runtime/multibase/multibase.test.d.ts +0 -3
  187. package/dist/runtime/multibase/multibase.test.js +0 -358
  188. package/dist/runtime/url.test.d.ts +0 -3
  189. package/dist/runtime/url.test.js +0 -45
  190. package/dist/runtime-BSkOVUWM.js +0 -4
  191. package/dist/semver-dArNLkR9.js +0 -149
  192. package/dist/sig-BXJO--F9.js +0 -4
  193. package/dist/src/vocab/accept.yaml +0 -15
  194. package/dist/src/vocab/activity.yaml +0 -98
  195. package/dist/src/vocab/add.yaml +0 -16
  196. package/dist/src/vocab/announce.yaml +0 -30
  197. package/dist/src/vocab/application.yaml +0 -324
  198. package/dist/src/vocab/arrive.yaml +0 -15
  199. package/dist/src/vocab/article.yaml +0 -46
  200. package/dist/src/vocab/audio.yaml +0 -11
  201. package/dist/src/vocab/block.yaml +0 -16
  202. package/dist/src/vocab/chatmessage.yaml +0 -50
  203. package/dist/src/vocab/collection.yaml +0 -154
  204. package/dist/src/vocab/collectionpage.yaml +0 -55
  205. package/dist/src/vocab/create.yaml +0 -28
  206. package/dist/src/vocab/dataintegrityproof.yaml +0 -56
  207. package/dist/src/vocab/delete.yaml +0 -27
  208. package/dist/src/vocab/didservice.yaml +0 -22
  209. package/dist/src/vocab/dislike.yaml +0 -14
  210. package/dist/src/vocab/document.yaml +0 -31
  211. package/dist/src/vocab/emoji.yaml +0 -12
  212. package/dist/src/vocab/emojireact.yaml +0 -17
  213. package/dist/src/vocab/endpoints.yaml +0 -85
  214. package/dist/src/vocab/event.yaml +0 -11
  215. package/dist/src/vocab/export.yaml +0 -9
  216. package/dist/src/vocab/flag.yaml +0 -15
  217. package/dist/src/vocab/follow.yaml +0 -19
  218. package/dist/src/vocab/group.yaml +0 -324
  219. package/dist/src/vocab/hashtag.yaml +0 -14
  220. package/dist/src/vocab/ignore.yaml +0 -14
  221. package/dist/src/vocab/image.yaml +0 -9
  222. package/dist/src/vocab/intransitiveactivity.yaml +0 -15
  223. package/dist/src/vocab/invite.yaml +0 -14
  224. package/dist/src/vocab/join.yaml +0 -14
  225. package/dist/src/vocab/key.yaml +0 -28
  226. package/dist/src/vocab/leave.yaml +0 -14
  227. package/dist/src/vocab/like.yaml +0 -16
  228. package/dist/src/vocab/link.yaml +0 -101
  229. package/dist/src/vocab/listen.yaml +0 -12
  230. package/dist/src/vocab/mention.yaml +0 -9
  231. package/dist/src/vocab/move.yaml +0 -15
  232. package/dist/src/vocab/multikey.yaml +0 -36
  233. package/dist/src/vocab/note.yaml +0 -48
  234. package/dist/src/vocab/object.yaml +0 -404
  235. package/dist/src/vocab/offer.yaml +0 -15
  236. package/dist/src/vocab/orderedcollection.yaml +0 -39
  237. package/dist/src/vocab/orderedcollectionpage.yaml +0 -50
  238. package/dist/src/vocab/organization.yaml +0 -324
  239. package/dist/src/vocab/page.yaml +0 -11
  240. package/dist/src/vocab/person.yaml +0 -324
  241. package/dist/src/vocab/place.yaml +0 -75
  242. package/dist/src/vocab/profile.yaml +0 -26
  243. package/dist/src/vocab/propertyvalue.yaml +0 -32
  244. package/dist/src/vocab/question.yaml +0 -103
  245. package/dist/src/vocab/read.yaml +0 -13
  246. package/dist/src/vocab/reject.yaml +0 -14
  247. package/dist/src/vocab/relationship.yaml +0 -52
  248. package/dist/src/vocab/remove.yaml +0 -14
  249. package/dist/src/vocab/service.yaml +0 -324
  250. package/dist/src/vocab/source.yaml +0 -26
  251. package/dist/src/vocab/tentativeaccept.yaml +0 -14
  252. package/dist/src/vocab/tentativereject.yaml +0 -14
  253. package/dist/src/vocab/tombstone.yaml +0 -24
  254. package/dist/src/vocab/travel.yaml +0 -16
  255. package/dist/src/vocab/undo.yaml +0 -26
  256. package/dist/src/vocab/update.yaml +0 -58
  257. package/dist/src/vocab/video.yaml +0 -11
  258. package/dist/src/vocab/view.yaml +0 -13
  259. package/dist/testing/docloader.test.js +0 -24
  260. package/dist/type-BMGxK0zE.js +0 -42006
  261. package/dist/vocab/actor.test.d.ts +0 -3
  262. package/dist/vocab/actor.test.js +0 -5965
  263. package/dist/vocab/lookup.test.d.ts +0 -3
  264. package/dist/vocab/lookup.test.js +0 -206
  265. package/dist/vocab/mod.d.ts +0 -8
  266. package/dist/vocab/mod.js +0 -10
  267. package/dist/vocab/schema.yaml +0 -247
  268. package/dist/vocab/type.test.d.ts +0 -3
  269. package/dist/vocab/type.test.js +0 -25
  270. package/dist/vocab/vocab.test.d.ts +0 -3
  271. package/dist/vocab/vocab.test.js +0 -3363
  272. package/dist/vocab-CXuKLJjd.js +0 -246
  273. package/dist/vocab-SOE1ifCr.d.ts +0 -14634
  274. package/dist/webfinger/handler.test.d.ts +0 -3
  275. package/dist/webfinger/lookup.test.d.ts +0 -3
  276. package/dist/webfinger/lookup.test.js +0 -195
  277. package/dist/webfinger/mod.d.ts +0 -6
  278. package/dist/webfinger/mod.js +0 -9
  279. package/dist/webfinger-C3GIyXIg.js +0 -4
  280. package/dist/x/cfworkers.d.ts +0 -61
  281. package/dist/x/cfworkers.js +0 -98
  282. package/dist/x/cfworkers.test.d.ts +0 -3
  283. package/dist/x/cfworkers.test.js +0 -179
  284. package/dist/x/hono.d.ts +0 -56
  285. package/dist/x/hono.js +0 -60
  286. package/dist/x/sveltekit.d.ts +0 -48
  287. package/dist/x/sveltekit.js +0 -68
  288. /package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals-C80BG-_5.js} +0 -0
  289. /package/dist/{collection-CSzG2j1P.js → collection-CcnIw1qY.js} +0 -0
  290. /package/dist/{nodeinfo/semver.test.d.ts → federation/idempotency.test.d.ts} +0 -0
  291. /package/dist/{runtime/authdocloader.test.d.ts → federation/negotiation.test.d.ts} +0 -0
  292. /package/dist/{runtime/docloader.test.d.ts → federation/webfinger.test.d.ts} +0 -0
  293. /package/dist/{mod-1pDWKvUL.d.ts → mod-1E3W847c.d.ts} +0 -0
  294. /package/dist/{runtime/key.test.d.ts → otel/exporter.test.d.ts} +0 -0
  295. /package/dist/{std__assert-X-_kMxKM.js → std__assert-DWivtrGR.js} +0 -0
  296. /package/dist/{testing → utils}/docloader.test.d.ts +0 -0
  297. /package/dist/{runtime/langstr.test.d.ts → utils/kv-cache.test.d.ts} +0 -0
@@ -0,0 +1,2447 @@
1
+ import { GetNodeInfoOptions, JsonValue, NodeInfo } from "./client-94iWEfQa.cjs";
2
+ import { HttpMessageSignaturesSpec } from "./http-ClB3pLcL.cjs";
3
+ import { GetKeyOwnerOptions } from "./owner-C-zfmVAD.cjs";
4
+ import { KvKey, KvStore } from "./kv-D8q9fLkA.cjs";
5
+ import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, TraverseCollectionOptions } from "@fedify/vocab";
6
+ import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
7
+ import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
8
+ import { Span, Tracer, TracerProvider } from "@opentelemetry/api";
9
+
10
+ //#region src/compat/types.d.ts
11
+ /**
12
+ * A function that transforms an activity object.
13
+ * @since 1.4.0
14
+ */
15
+ type ActivityTransformer<TContextData> = (activity: Activity, context: Context<TContextData>) => Activity;
16
+ //#endregion
17
+ //#region src/federation/collection.d.ts
18
+ /**
19
+ * A page of items.
20
+ */
21
+ interface PageItems<TItem> {
22
+ prevCursor?: string | null;
23
+ nextCursor?: string | null;
24
+ items: TItem[];
25
+ }
26
+ /**
27
+ * Calculates the [partial follower collection digest][1].
28
+ *
29
+ * [1]: https://w3id.org/fep/8fcf#partial-follower-collection-digest
30
+ * @param uris The URIs to calculate the digest. Duplicate URIs are ignored.
31
+ * @returns The digest.
32
+ */
33
+ declare function digest(uris: Iterable<string | URL>): Promise<Uint8Array>;
34
+ /**
35
+ * Builds [`Collection-Synchronization`][1] header content.
36
+ *
37
+ * [1]: https://w3id.org/fep/8fcf#the-collection-synchronization-http-header
38
+ *
39
+ * @param collectionId The sender's followers collection URI.
40
+ * @param actorIds The actor URIs to digest.
41
+ * @returns The header content.
42
+ */
43
+ declare function buildCollectionSynchronizationHeader(collectionId: string | URL, actorIds: Iterable<string | URL>): Promise<string>;
44
+ //#endregion
45
+ //#region src/federation/send.d.ts
46
+ /**
47
+ * A key pair for an actor who sends an activity.
48
+ * @since 0.10.0
49
+ */
50
+ interface SenderKeyPair {
51
+ /**
52
+ * The actor's private key to sign the request.
53
+ */
54
+ privateKey: CryptoKey;
55
+ /**
56
+ * The public key ID that corresponds to the private key.
57
+ */
58
+ keyId: URL;
59
+ }
60
+ /**
61
+ * Parameters for {@link sendActivity}.
62
+ */
63
+ //#endregion
64
+ //#region src/federation/callback.d.ts
65
+ /**
66
+ * A callback that dispatches a {@link NodeInfo} object.
67
+ *
68
+ * @template TContextData The context data to pass to the {@link Context}.
69
+ */
70
+ type NodeInfoDispatcher<TContextData> = (context: RequestContext<TContextData>) => NodeInfo | Promise<NodeInfo>;
71
+ /**
72
+ * A callback that dispatches a array of {@link Link}.
73
+ *
74
+ * @template TContextData The context data to pass to the {@link Context}.
75
+ * @param resource The URL queried via WebFinger.
76
+ * @returns Links related to the queried resource.
77
+ */
78
+ type WebFingerLinksDispatcher<TContextData> = (context: RequestContext<TContextData>, resource: URL) => readonly Link$1[] | Promise<readonly Link$1[]>;
79
+ /**
80
+ * A callback that dispatches an {@link Actor} object.
81
+ *
82
+ * @template TContextData The context data to pass to the {@link Context}.
83
+ * @param context The request context.
84
+ * @param identifier The actor's internal identifier or username.
85
+ */
86
+ type ActorDispatcher<TContextData> = (context: RequestContext<TContextData>, identifier: string) => Actor | null | Promise<Actor | null>;
87
+ /**
88
+ * A callback that dispatches key pairs for an actor.
89
+ *
90
+ * @template TContextData The context data to pass to the {@link Context}.
91
+ * @param context The context.
92
+ * @param identifier The actor's internal identifier or username.
93
+ * @returns The key pairs.
94
+ * @since 0.10.0
95
+ */
96
+ type ActorKeyPairsDispatcher<TContextData> = (context: Context<TContextData>, identifier: string) => CryptoKeyPair[] | Promise<CryptoKeyPair[]>;
97
+ /**
98
+ * A callback that maps a WebFinger username to the corresponding actor's
99
+ * internal identifier, or `null` if the username is not found.
100
+ * @template TContextData The context data to pass to the {@link Context}.
101
+ * @param context The context.
102
+ * @param username The WebFinger username.
103
+ * @returns The actor's internal identifier, or `null` if the username is not
104
+ * found.
105
+ * @since 0.15.0
106
+ */
107
+ type ActorHandleMapper<TContextData> = (context: Context<TContextData>, username: string) => string | null | Promise<string | null>;
108
+ /**
109
+ * A callback that maps a WebFinger query to the corresponding actor's
110
+ * internal identifier or username, or `null` if the query is not found.
111
+ * @template TContextData The context data to pass to the {@link Context}.
112
+ * @param context The request context.
113
+ * @param resource The URL that was queried through WebFinger.
114
+ * @returns The actor's internal identifier or username, or `null` if the query
115
+ * is not found.
116
+ * @since 1.4.0
117
+ */
118
+ type ActorAliasMapper<TContextData> = (context: RequestContext<TContextData>, resource: URL) => {
119
+ identifier: string;
120
+ } | {
121
+ username: string;
122
+ } | null | Promise<{
123
+ identifier: string;
124
+ } | {
125
+ username: string;
126
+ } | null>;
127
+ /**
128
+ * A callback that dispatches an object.
129
+ *
130
+ * @template TContextData The context data to pass to the {@link Context}.
131
+ * @template TObject The type of object to dispatch.
132
+ * @template TParam The parameter names of the requested URL.
133
+ * @since 0.7.0
134
+ */
135
+ type ObjectDispatcher<TContextData, TObject extends Object$1, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => TObject | null | Promise<TObject | null>;
136
+ /**
137
+ * A callback that dispatches a collection.
138
+ *
139
+ * @template TItem The type of items in the collection.
140
+ * @template TContext The type of the context. {@link Context} or
141
+ * {@link RequestContext}.
142
+ * @template TContextData The context data to pass to the `TContext`.
143
+ * @template TFilter The type of the filter, if any.
144
+ * @param context The context.
145
+ * @param identifier The internal identifier or the username of the collection
146
+ * owner.
147
+ * @param cursor The cursor to start the collection from, or `null` to dispatch
148
+ * the entire collection without pagination.
149
+ * @param filter The filter to apply to the collection, if any.
150
+ */
151
+ type CollectionDispatcher<TItem, TContext extends Context<TContextData>, TContextData, TFilter> = (context: TContext, identifier: string, cursor: string | null, filter?: TFilter) => PageItems<TItem> | null | Promise<PageItems<TItem> | null>;
152
+ /**
153
+ * A callback that counts the number of items in a collection.
154
+ *
155
+ * @template TContextData The context data to pass to the {@link Context}.
156
+ * @param context The context.
157
+ * @param identifier The internal identifier or the username of the collection
158
+ * owner.
159
+ * @param filter The filter to apply to the collection, if any.
160
+ */
161
+ type CollectionCounter<TContextData, TFilter> = (context: RequestContext<TContextData>, identifier: string, filter?: TFilter) => number | bigint | null | Promise<number | bigint | null>;
162
+ /**
163
+ * A callback that returns a cursor for a collection.
164
+ *
165
+ * @template TContext The type of the context. {@link Context} or
166
+ * {@link RequestContext}.
167
+ * @template TContextData The context data to pass to the {@link Context}.
168
+ * @template TFilter The type of the filter, if any.
169
+ * @param context The context.
170
+ * @param identifier The internal identifier or the username of the collection
171
+ * owner.
172
+ * @param filter The filter to apply to the collection, if any.
173
+ */
174
+ type CollectionCursor<TContext extends Context<TContextData>, TContextData, TFilter> = (context: TContext, identifier: string, filter?: TFilter) => string | null | Promise<string | null>;
175
+ /**
176
+ * A callback that listens for activities in an inbox.
177
+ *
178
+ * @template TContextData The context data to pass to the {@link Context}.
179
+ * @template TActivity The type of activity to listen for.
180
+ * @param context The inbox context.
181
+ * @param activity The activity that was received.
182
+ */
183
+ type InboxListener<TContextData, TActivity extends Activity> = (context: InboxContext<TContextData>, activity: TActivity) => void | Promise<void>;
184
+ /**
185
+ * A callback that handles errors in an inbox.
186
+ *
187
+ * @template TContextData The context data to pass to the {@link Context}.
188
+ * @param context The inbox context.
189
+ */
190
+ type InboxErrorHandler<TContextData> = (context: Context<TContextData>, error: Error) => void | Promise<void>;
191
+ /**
192
+ * A callback that dispatches the key pair for the authenticated document loader
193
+ * of the {@link Context} passed to the shared inbox listener.
194
+ *
195
+ * @template TContextData The context data to pass to the {@link Context}.
196
+ * @param context The context.
197
+ * @returns The username or the internal identifier of the actor or the key pair
198
+ * for the authenticated document loader of the {@link Context} passed
199
+ * to the shared inbox listener. If `null` is returned, the request is
200
+ * not authorized.
201
+ * @since 0.11.0
202
+ */
203
+ type SharedInboxKeyDispatcher<TContextData> = (context: Context<TContextData>) => SenderKeyPair | {
204
+ identifier: string;
205
+ } | {
206
+ username: string;
207
+ } | {
208
+ handle: string;
209
+ } | null | Promise<SenderKeyPair | {
210
+ identifier: string;
211
+ } | {
212
+ username: string;
213
+ } | {
214
+ handle: string;
215
+ } | null>;
216
+ /**
217
+ * A callback that handles errors during outbox processing.
218
+ *
219
+ * @param error The error that occurred.
220
+ * @param activity The activity that caused the error. If it is `null`, the
221
+ * error occurred during deserializing the activity.
222
+ * @since 0.6.0
223
+ */
224
+ type OutboxErrorHandler = (error: Error, activity: Activity | null) => void | Promise<void>;
225
+ /**
226
+ * A callback that determines if a request is authorized or not.
227
+ *
228
+ * @template TContextData The context data to pass to the {@link Context}.
229
+ * @param context The request context.
230
+ * @param identifier The internal identifier of the actor that is being requested.
231
+ * @param signedKey *Deprecated in Fedify 1.5.0 in favor of
232
+ * {@link RequestContext.getSignedKey} method.*
233
+ * The key that was used to sign the request, or `null` if
234
+ * the request was not signed or the signature was invalid.
235
+ * @param signedKeyOwner *Deprecated in Fedify 1.5.0 in favor of
236
+ * {@link RequestContext.getSignedKeyOwner} method.*
237
+ * The actor that owns the key that was used to sign the
238
+ * request, or `null` if the request was not signed or the
239
+ * signature was invalid, or if the key is not associated
240
+ * with an actor.
241
+ * @returns `true` if the request is authorized, `false` otherwise.
242
+ * @since 0.7.0
243
+ */
244
+ type AuthorizePredicate<TContextData> = (context: RequestContext<TContextData>, identifier: string, signedKey: CryptographicKey | null, signedKeyOwner: Actor | null) => boolean | Promise<boolean>;
245
+ /**
246
+ * A callback that determines if a request is authorized or not.
247
+ *
248
+ * @template TContextData The context data to pass to the {@link Context}.
249
+ * @template TParam The parameter names of the requested URL.
250
+ * @param context The request context.
251
+ * @param values The parameters of the requested URL.
252
+ * @param signedKey *Deprecated in Fedify 1.5.0 in favor of
253
+ * {@link RequestContext.getSignedKey} method.*
254
+ * The key that was used to sign the request, or `null` if
255
+ * the request was not signed or the signature was invalid.
256
+ * @param signedKeyOwner *Deprecated in Fedify 1.5.0 in favor of
257
+ * {@link RequestContext.getSignedKeyOwner} method.*
258
+ * The actor that owns the key that was used to sign the
259
+ * request, or `null` if the request was not signed or the
260
+ * signature was invalid, or if the key is not associated
261
+ * with an actor.
262
+ * @returns `true` if the request is authorized, `false` otherwise.
263
+ * @since 0.7.0
264
+ */
265
+ type ObjectAuthorizePredicate<TContextData, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>, signedKey: CryptographicKey | null, signedKeyOwner: Actor | null) => boolean | Promise<boolean>;
266
+ /**
267
+ * A callback that dispatches a custom collection.
268
+ *
269
+ * @template TItem The type of items in the collection.
270
+ * @template TParams The parameter names of the requested URL.
271
+ * @template TContext The type of the context. {@link Context} or
272
+ * {@link RequestContext}.
273
+ * @template TContextData The context data to pass to the `TContext`.
274
+ * @template TFilter The type of the filter, if any.
275
+ * @param context The context.
276
+ * @param values The parameters of the requested URL.
277
+ * @param cursor The cursor to start the collection from, or `null` to dispatch
278
+ * the entire collection without pagination.
279
+ * @since 1.8.0
280
+ */
281
+ type CustomCollectionDispatcher<TItem, TParam extends string, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: Record<TParam, string>, cursor: string | null) => PageItems<TItem> | null | Promise<PageItems<TItem> | null>;
282
+ /**
283
+ * A callback that counts the number of items in a custom collection.
284
+ *
285
+ * @template TParams The parameter names of the requested URL.
286
+ * @template TContextData The context data to pass to the {@link Context}.
287
+ * @param context The context.
288
+ * @param values The parameters of the requested URL.
289
+ * @since 1.8.0
290
+ */
291
+ type CustomCollectionCounter<TParam extends string, TContextData> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => number | bigint | null | Promise<number | bigint | null>;
292
+ /**
293
+ * A callback that returns a cursor for a custom collection.
294
+ *
295
+ * @template TParams The parameter names of the requested URL.
296
+ * @template TContext The type of the context. {@link Context} or
297
+ * {@link RequestContext}.
298
+ * @template TContextData The context data to pass to the {@link Context}.
299
+ * @template TFilter The type of the filter, if any.
300
+ * @param context The context.
301
+ * @param values The parameters of the requested URL.
302
+ * @since 1.8.0
303
+ */
304
+ type CustomCollectionCursor<TParam extends string, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: Record<TParam, string>) => string | null | Promise<string | null>;
305
+ //#endregion
306
+ //#region src/federation/mq.d.ts
307
+ /**
308
+ * Additional options for enqueuing a message in a queue.
309
+ *
310
+ * @since 0.5.0
311
+ */
312
+ interface MessageQueueEnqueueOptions {
313
+ /**
314
+ * The delay before the message is enqueued. No delay by default.
315
+ *
316
+ * It must not be negative.
317
+ */
318
+ delay?: Temporal.Duration;
319
+ }
320
+ /**
321
+ * Additional options for listening to a message queue.
322
+ *
323
+ * @since 1.0.0
324
+ */
325
+ interface MessageQueueListenOptions {
326
+ /**
327
+ * The signal to abort listening to the message queue.
328
+ */
329
+ signal?: AbortSignal;
330
+ }
331
+ /**
332
+ * An abstract interface for a message queue.
333
+ *
334
+ * @since 0.5.0
335
+ */
336
+ interface MessageQueue {
337
+ /**
338
+ * Whether the message queue backend provides native retry mechanisms.
339
+ * When `true`, Fedify will skip its own retry logic and rely on the backend
340
+ * to handle retries. When `false` or omitted, Fedify will handle retries
341
+ * using its own retry policies.
342
+ *
343
+ * @default `false`
344
+ * @since 1.7.0
345
+ */
346
+ readonly nativeRetrial?: boolean;
347
+ /**
348
+ * Enqueues a message in the queue.
349
+ * @param message The message to enqueue.
350
+ * @param options Additional options for enqueuing the message.
351
+ */
352
+ enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
353
+ /**
354
+ * Enqueues multiple messages in the queue. This operation is optional,
355
+ * and may not be supported by all implementations. If not supported,
356
+ * Fedify will invoke {@link enqueue} for each message.
357
+ *
358
+ * @param messages The messages to enqueue.
359
+ * @param options Additional options for enqueuing the messages.
360
+ */
361
+ enqueueMany?: (messages: any[], options?: MessageQueueEnqueueOptions) => Promise<void>;
362
+ /**
363
+ * Listens for messages in the queue.
364
+ * @param handler The handler for messages in the queue.
365
+ * @param options Additional options for listening to the message queue.
366
+ * @returns A promise that resolves when the listening is done. It never
367
+ * rejects, and is resolved when the signal is aborted. If no
368
+ * signal is provided, it never resolves.
369
+ */
370
+ listen(handler: (message: any) => Promise<void> | void, options?: MessageQueueListenOptions): Promise<void>;
371
+ }
372
+ /**
373
+ * Additional options for {@link InProcessMessageQueue}.
374
+ * @since 1.0.0
375
+ */
376
+ interface InProcessMessageQueueOptions {
377
+ /**
378
+ * The interval to poll for messages in the queue. 5 seconds by default.
379
+ * @default `{ seconds: 5 }`
380
+ */
381
+ pollInterval?: Temporal.Duration | Temporal.DurationLike;
382
+ }
383
+ /**
384
+ * A message queue that processes messages in the same process.
385
+ * Do not use this in production as it does neither persist messages nor
386
+ * distribute them across multiple processes.
387
+ *
388
+ * @since 0.5.0
389
+ */
390
+ declare class InProcessMessageQueue implements MessageQueue {
391
+ #private;
392
+ /**
393
+ * In-process message queue does not provide native retry mechanisms.
394
+ * @since 1.7.0
395
+ */
396
+ readonly nativeRetrial = false;
397
+ /**
398
+ * Constructs a new {@link InProcessMessageQueue} with the given options.
399
+ * @param options Additional options for the in-process message queue.
400
+ */
401
+ constructor(options?: InProcessMessageQueueOptions);
402
+ enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
403
+ enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
404
+ listen(handler: (message: any) => Promise<void> | void, options?: MessageQueueListenOptions): Promise<void>;
405
+ }
406
+ /**
407
+ * A message queue that processes messages in parallel. It takes another
408
+ * {@link MessageQueue}, and processes messages in parallel up to a certain
409
+ * number of workers.
410
+ *
411
+ * Actually, it's rather a decorator than a queue itself.
412
+ *
413
+ * Note that the workers do not run in truly parallel, in the sense that they
414
+ * are not running in separate threads or processes. They are running in the
415
+ * same process, but are scheduled to run in parallel. Hence, this is useful
416
+ * for I/O-bound tasks, but not for CPU-bound tasks, which is okay for Fedify's
417
+ * workloads.
418
+ *
419
+ * @since 1.0.0
420
+ */
421
+ declare class ParallelMessageQueue implements MessageQueue {
422
+ #private;
423
+ readonly queue: MessageQueue;
424
+ readonly workers: number;
425
+ /**
426
+ * Inherits the native retry capability from the wrapped queue.
427
+ * @since 1.7.0
428
+ */
429
+ readonly nativeRetrial?: boolean;
430
+ /**
431
+ * Constructs a new {@link ParallelMessageQueue} with the given queue and
432
+ * number of workers.
433
+ * @param queue The message queue to use under the hood. Note that
434
+ * {@link ParallelMessageQueue} cannot be nested.
435
+ * @param workers The number of workers to process messages in parallel.
436
+ * @throws {TypeError} If the given queue is an instance of
437
+ * {@link ParallelMessageQueue}.
438
+ */
439
+ constructor(queue: MessageQueue, workers: number);
440
+ enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
441
+ enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
442
+ listen(handler: (message: any) => Promise<void> | void, options?: MessageQueueListenOptions): Promise<void>;
443
+ }
444
+ //#endregion
445
+ //#region src/federation/handler.d.ts
446
+ /**
447
+ * Options for the {@link respondWithObject} and
448
+ * {@link respondWithObjectIfAcceptable} functions.
449
+ * @since 0.3.0
450
+ */
451
+ interface RespondWithObjectOptions {
452
+ /**
453
+ * The document loader to use for compacting JSON-LD.
454
+ * @since 0.8.0
455
+ */
456
+ contextLoader: DocumentLoader;
457
+ }
458
+ /**
459
+ * Responds with the given object in JSON-LD format.
460
+ *
461
+ * @param object The object to respond with.
462
+ * @param options Options.
463
+ * @since 0.3.0
464
+ */
465
+ declare function respondWithObject(object: Object$1, options?: RespondWithObjectOptions): Promise<Response>;
466
+ /**
467
+ * Responds with the given object in JSON-LD format if the request accepts
468
+ * JSON-LD.
469
+ *
470
+ * @param object The object to respond with.
471
+ * @param request The request to check for JSON-LD acceptability.
472
+ * @param options Options.
473
+ * @since 0.3.0
474
+ */
475
+ declare function respondWithObjectIfAcceptable(object: Object$1, request: Request, options?: RespondWithObjectOptions): Promise<Response | null>;
476
+ //#endregion
477
+ //#region src/federation/router.d.ts
478
+ /**
479
+ * Options for the {@link Router}.
480
+ * @since 0.12.0
481
+ */
482
+ interface RouterOptions {
483
+ /**
484
+ * Whether to ignore trailing slashes when matching paths.
485
+ */
486
+ trailingSlashInsensitive?: boolean;
487
+ }
488
+ /**
489
+ * The result of {@link Router.route} method.
490
+ * @since 1.3.0
491
+ */
492
+ interface RouterRouteResult {
493
+ /**
494
+ * The matched route name.
495
+ */
496
+ name: string;
497
+ /**
498
+ * The URL template of the matched route.
499
+ */
500
+ template: string;
501
+ /**
502
+ * The values extracted from the URL.
503
+ */
504
+ values: Record<string, string>;
505
+ }
506
+ /**
507
+ * URL router and constructor based on URI Template
508
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
509
+ */
510
+ declare class Router {
511
+ #private;
512
+ /**
513
+ * Whether to ignore trailing slashes when matching paths.
514
+ * @since 1.6.0
515
+ */
516
+ trailingSlashInsensitive: boolean;
517
+ /**
518
+ * Create a new {@link Router}.
519
+ * @param options Options for the router.
520
+ */
521
+ constructor(options?: RouterOptions);
522
+ clone(): Router;
523
+ /**
524
+ * Checks if a path name exists in the router.
525
+ * @param name The name of the path.
526
+ * @returns `true` if the path name exists, otherwise `false`.
527
+ */
528
+ has(name: string): boolean;
529
+ /**
530
+ * Adds a new path rule to the router.
531
+ * @param template The path pattern.
532
+ * @param name The name of the path.
533
+ * @returns The names of the variables in the path pattern.
534
+ */
535
+ add(template: string, name: string): Set<string>;
536
+ /**
537
+ * Resolves a path name and values from a URL, if any match.
538
+ * @param url The URL to resolve.
539
+ * @returns The name of the path and its values, if any match. Otherwise,
540
+ * `null`.
541
+ */
542
+ route(url: string): RouterRouteResult | null;
543
+ /**
544
+ * Constructs a URL/path from a path name and values.
545
+ * @param name The name of the path.
546
+ * @param values The values to expand the path with.
547
+ * @returns The URL/path, if the name exists. Otherwise, `null`.
548
+ */
549
+ build(name: string, values: Record<string, string>): string | null;
550
+ }
551
+ /**
552
+ * An error thrown by the {@link Router}.
553
+ */
554
+ declare class RouterError extends Error {
555
+ /**
556
+ * Create a new {@link RouterError}.
557
+ * @param message The error message.
558
+ */
559
+ constructor(message: string);
560
+ }
561
+ //#endregion
562
+ //#region src/federation/builder.d.ts
563
+ /**
564
+ * Creates a new {@link FederationBuilder} instance.
565
+ * @returns A new {@link FederationBuilder} instance.
566
+ * @since 1.6.0
567
+ */
568
+ declare function createFederationBuilder<TContextData>(): FederationBuilder<TContextData>;
569
+ //#endregion
570
+ //#region src/federation/queue.d.ts
571
+ interface SenderKeyJwkPair {
572
+ keyId: string;
573
+ privateKey: JsonWebKey;
574
+ }
575
+ /**
576
+ * A message that represents a task to be processed by the background worker.
577
+ * The concrete type of the message depends on the `type` property.
578
+ *
579
+ * Please do not depend on the concrete types of the messages, as they may
580
+ * change in the future. You should treat the `Message` type as an opaque
581
+ * type.
582
+ * @since 1.6.0
583
+ */
584
+ type Message = FanoutMessage | OutboxMessage | InboxMessage;
585
+ interface FanoutMessage {
586
+ type: "fanout";
587
+ id: ReturnType<typeof crypto.randomUUID>;
588
+ baseUrl: string;
589
+ keys: SenderKeyJwkPair[];
590
+ inboxes: Record<string, {
591
+ actorIds: string[];
592
+ sharedInbox: boolean;
593
+ }>;
594
+ activity: unknown;
595
+ activityId?: string;
596
+ activityType: string;
597
+ collectionSync?: string;
598
+ traceContext: Record<string, string>;
599
+ }
600
+ interface OutboxMessage {
601
+ type: "outbox";
602
+ id: ReturnType<typeof crypto.randomUUID>;
603
+ baseUrl: string;
604
+ keys: SenderKeyJwkPair[];
605
+ activity: unknown;
606
+ activityId?: string;
607
+ activityType: string;
608
+ inbox: string;
609
+ sharedInbox: boolean;
610
+ started: string;
611
+ attempt: number;
612
+ headers: Record<string, string>;
613
+ traceContext: Record<string, string>;
614
+ }
615
+ interface InboxMessage {
616
+ type: "inbox";
617
+ id: ReturnType<typeof crypto.randomUUID>;
618
+ baseUrl: string;
619
+ activity: unknown;
620
+ started: string;
621
+ attempt: number;
622
+ identifier: string | null;
623
+ traceContext: Record<string, string>;
624
+ }
625
+ //#endregion
626
+ //#region src/federation/retry.d.ts
627
+ /**
628
+ * The context passed to a {@link RetryPolicy} callback.
629
+ * @since 0.12.0
630
+ */
631
+ interface RetryContext {
632
+ /**
633
+ * The elapsed time since the first attempt.
634
+ */
635
+ readonly elapsedTime: Temporal.Duration;
636
+ /**
637
+ * The number of attempts so far.
638
+ */
639
+ readonly attempts: number;
640
+ }
641
+ /**
642
+ * A policy that determines the delay before the next retry.
643
+ * @param context The retry context.
644
+ * @returns The delay before the next retry, or `null` to stop retrying.
645
+ * It must not negative.
646
+ * @since 0.12.0
647
+ */
648
+ type RetryPolicy = (context: RetryContext) => Temporal.Duration | null;
649
+ /**
650
+ * Options for {@link createExponentialBackoffPolicy} function.
651
+ * @since 0.12.0
652
+ */
653
+ interface CreateExponentialBackoffPolicyOptions {
654
+ /**
655
+ * The initial delay before the first retry. Defaults to 1 second.
656
+ */
657
+ readonly initialDelay?: Temporal.DurationLike;
658
+ /**
659
+ * The maximum delay between retries. Defaults to 12 hours.
660
+ */
661
+ readonly maxDelay?: Temporal.DurationLike;
662
+ /**
663
+ * The maximum number of attempts before giving up.
664
+ * Defaults to 10.
665
+ */
666
+ readonly maxAttempts?: number;
667
+ /**
668
+ * The factor to multiply the previous delay by for each retry.
669
+ * Defaults to 2.
670
+ */
671
+ readonly factor?: number;
672
+ /**
673
+ * Whether to add jitter to the delay to avoid synchronization.
674
+ * Turned on by default.
675
+ */
676
+ readonly jitter?: boolean;
677
+ }
678
+ /**
679
+ * Creates an exponential backoff retry policy. The delay between retries
680
+ * starts at the `initialDelay` and is multiplied by the `factor` for each
681
+ * subsequent retry, up to the `maxDelay`. The policy will give up after
682
+ * `maxAttempts` attempts. The actual delay is randomized to avoid
683
+ * synchronization (jitter).
684
+ * @param options The options for the policy.
685
+ * @returns The retry policy.
686
+ * @since 0.12.0
687
+ */
688
+ declare function createExponentialBackoffPolicy(options?: CreateExponentialBackoffPolicyOptions): RetryPolicy;
689
+ //#endregion
690
+ //#region src/federation/middleware.d.ts
691
+ /**
692
+ * Options for {@link createFederation} function.
693
+ * @template TContextData The type of the context data.
694
+ * @since 0.10.0
695
+ * @deprecated Use {@link FederationOptions} instead.
696
+ */
697
+ interface CreateFederationOptions<TContextData> extends FederationOptions<TContextData> {}
698
+ /**
699
+ * Configures the task queues for sending and receiving activities.
700
+ * @since 1.3.0
701
+ */
702
+ interface FederationQueueOptions {
703
+ /**
704
+ * The message queue for incoming activities. If not provided, incoming
705
+ * activities will not be queued and will be processed immediately.
706
+ */
707
+ inbox?: MessageQueue;
708
+ /**
709
+ * The message queue for outgoing activities. If not provided, outgoing
710
+ * activities will not be queued and will be sent immediately.
711
+ */
712
+ outbox?: MessageQueue;
713
+ /**
714
+ * The message queue for fanning out outgoing activities. If not provided,
715
+ * outgoing activities will not be fanned out in the background, but will be
716
+ * fanned out immediately, which causes slow response times on
717
+ * {@link Context.sendActivity} calls.
718
+ */
719
+ fanout?: MessageQueue;
720
+ }
721
+ /**
722
+ * Prefixes for namespacing keys in the Deno KV store.
723
+ */
724
+ interface FederationKvPrefixes {
725
+ /**
726
+ * The key prefix used for storing whether activities have already been
727
+ * processed or not.
728
+ * @default `["_fedify", "activityIdempotence"]`
729
+ */
730
+ activityIdempotence: KvKey;
731
+ /**
732
+ * The key prefix used for storing remote JSON-LD documents.
733
+ * @default `["_fedify", "remoteDocument"]`
734
+ */
735
+ remoteDocument: KvKey;
736
+ /**
737
+ * The key prefix used for caching public keys.
738
+ * @default `["_fedify", "publicKey"]`
739
+ * @since 0.12.0
740
+ */
741
+ publicKey: KvKey;
742
+ /**
743
+ * The key prefix used for caching HTTP Message Signatures specs.
744
+ * The cached spec is used to reduce the number of requests to make signed
745
+ * requests ("double-knocking" technique).
746
+ * @default `["_fedify", "httpMessageSignaturesSpec"]`
747
+ * @since 1.6.0
748
+ */
749
+ httpMessageSignaturesSpec: KvKey;
750
+ }
751
+ /**
752
+ * Options for {@link CreateFederationOptions.origin} when it is not a string.
753
+ * @since 1.5.0
754
+ */
755
+ interface FederationOrigin {
756
+ /**
757
+ * The canonical hostname for fediverse handles (which are looked up through
758
+ * WebFinger). This is used for WebFinger lookups. It has to be a valid
759
+ * hostname, e.g., `"example.com"`.
760
+ */
761
+ handleHost: string;
762
+ /**
763
+ * The canonical origin for web URLs. This is used for constructing absolute
764
+ * URLs. It has to start with either `"http://"` or `"https://"`, and must
765
+ * not contain a path or query string, e.g., `"https://example.com"`.
766
+ */
767
+ webOrigin: string;
768
+ }
769
+ /**
770
+ * Create a new {@link Federation} instance.
771
+ * @param parameters Parameters for initializing the instance.
772
+ * @returns A new {@link Federation} instance.
773
+ * @since 0.10.0
774
+ */
775
+ declare function createFederation<TContextData>(options: CreateFederationOptions<TContextData>): Federation<TContextData>;
776
+ //#endregion
777
+ //#region src/federation/federation.d.ts
778
+ /**
779
+ * Options for {@link Federation.startQueue} method.
780
+ * @since 1.0.0
781
+ */
782
+ interface FederationStartQueueOptions {
783
+ /**
784
+ * The signal to abort the task queue.
785
+ */
786
+ signal?: AbortSignal;
787
+ /**
788
+ * Starts the task worker only for the specified queue. If unspecified,
789
+ * which is the default, the task worker starts for all three queues:
790
+ * inbox, outbox, and fanout.
791
+ * @since 1.3.0
792
+ */
793
+ queue?: "inbox" | "outbox" | "fanout";
794
+ }
795
+ /**
796
+ * A common interface between {@link Federation} and {@link FederationBuilder}.
797
+ * @template TContextData The context data to pass to the {@link Context}.
798
+ * @since 1.6.0
799
+ */
800
+ interface Federatable<TContextData> {
801
+ /**
802
+ * Registers a NodeInfo dispatcher.
803
+ * @param path The URI path pattern for the NodeInfo dispatcher. The syntax
804
+ * is based on URI Template
805
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
806
+ * must have no variables.
807
+ * @param dispatcher A NodeInfo dispatcher callback to register.
808
+ * @throws {RouterError} Thrown if the path pattern is invalid.
809
+ */
810
+ setNodeInfoDispatcher(path: string, dispatcher: NodeInfoDispatcher<TContextData>): void;
811
+ /**
812
+ * Registers a links dispatcher to WebFinger
813
+ * @param dispatcher A links dispatcher callback to register.
814
+ */
815
+ setWebFingerLinksDispatcher(dispatcher: WebFingerLinksDispatcher<TContextData>): void;
816
+ /**
817
+ * Registers an actor dispatcher.
818
+ *
819
+ * @example
820
+ * ``` typescript
821
+ * federation.setActorDispatcher(
822
+ * "/users/{identifier}",
823
+ * async (ctx, identifier) => {
824
+ * return new Person({
825
+ * id: ctx.getActorUri(identifier),
826
+ * // ...
827
+ * });
828
+ * }
829
+ * );
830
+ * ```
831
+ *
832
+ * @param path The URI path pattern for the actor dispatcher. The syntax is
833
+ * based on URI Template
834
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
835
+ * must have one variable: `{identifier}`.
836
+ * @param dispatcher An actor dispatcher callback to register.
837
+ * @returns An object with methods to set other actor dispatcher callbacks.
838
+ * @throws {RouterError} Thrown if the path pattern is invalid.
839
+ */
840
+ setActorDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: ActorDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
841
+ /**
842
+ * Registers an object dispatcher.
843
+ *
844
+ * @template TContextData The context data to pass to the {@link Context}.
845
+ * @template TObject The type of object to dispatch.
846
+ * @template TParam The parameter names of the requested URL.
847
+ * @param cls The Activity Vocabulary class of the object to dispatch.
848
+ * @param path The URI path pattern for the object dispatcher. The syntax is
849
+ * based on URI Template
850
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
851
+ * must have one or more variables.
852
+ * @param dispatcher An object dispatcher callback to register.
853
+ */
854
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
855
+ /**
856
+ * Registers an object dispatcher.
857
+ *
858
+ * @template TContextData The context data to pass to the {@link Context}.
859
+ * @template TObject The type of object to dispatch.
860
+ * @template TParam The parameter names of the requested URL.
861
+ * @param cls The Activity Vocabulary class of the object to dispatch.
862
+ * @param path The URI path pattern for the object dispatcher. The syntax is
863
+ * based on URI Template
864
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
865
+ * must have one or more variables.
866
+ * @param dispatcher An object dispatcher callback to register.
867
+ */
868
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
869
+ /**
870
+ * Registers an object dispatcher.
871
+ *
872
+ * @template TContextData The context data to pass to the {@link Context}.
873
+ * @template TObject The type of object to dispatch.
874
+ * @template TParam The parameter names of the requested URL.
875
+ * @param cls The Activity Vocabulary class of the object to dispatch.
876
+ * @param path The URI path pattern for the object dispatcher. The syntax is
877
+ * based on URI Template
878
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
879
+ * must have one or more variables.
880
+ * @param dispatcher An object dispatcher callback to register.
881
+ */
882
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
883
+ /**
884
+ * Registers an object dispatcher.
885
+ *
886
+ * @template TContextData The context data to pass to the {@link Context}.
887
+ * @template TObject The type of object to dispatch.
888
+ * @template TParam The parameter names of the requested URL.
889
+ * @param cls The Activity Vocabulary class of the object to dispatch.
890
+ * @param path The URI path pattern for the object dispatcher. The syntax is
891
+ * based on URI Template
892
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
893
+ * must have one or more variables.
894
+ * @param dispatcher An object dispatcher callback to register.
895
+ */
896
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
897
+ /**
898
+ * Registers an object dispatcher.
899
+ *
900
+ * @template TContextData The context data to pass to the {@link Context}.
901
+ * @template TObject The type of object to dispatch.
902
+ * @template TParam The parameter names of the requested URL.
903
+ * @param cls The Activity Vocabulary class of the object to dispatch.
904
+ * @param path The URI path pattern for the object dispatcher. The syntax is
905
+ * based on URI Template
906
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
907
+ * must have one or more variables.
908
+ * @param dispatcher An object dispatcher callback to register.
909
+ */
910
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
911
+ /**
912
+ * Registers an object dispatcher.
913
+ *
914
+ * @template TContextData The context data to pass to the {@link Context}.
915
+ * @template TObject The type of object to dispatch.
916
+ * @template TParam The parameter names of the requested URL.
917
+ * @param cls The Activity Vocabulary class of the object to dispatch.
918
+ * @param path The URI path pattern for the object dispatcher. The syntax is
919
+ * based on URI Template
920
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
921
+ * must have one or more variables.
922
+ * @param dispatcher An object dispatcher callback to register.
923
+ */
924
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
925
+ /**
926
+ * Registers an inbox dispatcher.
927
+ *
928
+ * @param path The URI path pattern for the inbox dispatcher. The syntax is
929
+ * based on URI Template
930
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
931
+ * must have one variable: `{identifier}`, and must match
932
+ * the inbox listener path.
933
+ * @param dispatcher An inbox dispatcher callback to register.
934
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
935
+ */
936
+ setInboxDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
937
+ /**
938
+ * Registers an outbox dispatcher.
939
+ *
940
+ * @example
941
+ * ``` typescript
942
+ * federation.setOutboxDispatcher(
943
+ * "/users/{identifier}/outbox",
944
+ * async (ctx, identifier, options) => {
945
+ * let items: Activity[];
946
+ * let nextCursor: string;
947
+ * // ...
948
+ * return { items, nextCursor };
949
+ * }
950
+ * );
951
+ * ```
952
+ *
953
+ * @param path The URI path pattern for the outbox dispatcher. The syntax is
954
+ * based on URI Template
955
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
956
+ * must have one variable: `{identifier}`.
957
+ * @param dispatcher An outbox dispatcher callback to register.
958
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
959
+ */
960
+ setOutboxDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
961
+ /**
962
+ * Registers a following collection dispatcher.
963
+ * @param path The URI path pattern for the following collection. The syntax
964
+ * is based on URI Template
965
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
966
+ * must have one variable: `{identifier}`.
967
+ * @param dispatcher A following collection callback to register.
968
+ * @returns An object with methods to set other following collection
969
+ * callbacks.
970
+ * @throws {RouterError} Thrown if the path pattern is invalid.
971
+ */
972
+ setFollowingDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: CollectionDispatcher<Actor | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
973
+ /**
974
+ * Registers a followers collection dispatcher.
975
+ * @param path The URI path pattern for the followers collection. The syntax
976
+ * is based on URI Template
977
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
978
+ * must have one variable: `{identifier}`.
979
+ * @param dispatcher A followers collection callback to register.
980
+ * @returns An object with methods to set other followers collection
981
+ * callbacks.
982
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
983
+ */
984
+ setFollowersDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: CollectionDispatcher<Recipient, Context<TContextData>, TContextData, URL>): CollectionCallbackSetters<Context<TContextData>, TContextData, URL>;
985
+ /**
986
+ * Registers a liked collection dispatcher.
987
+ * @param path The URI path pattern for the liked collection. The syntax
988
+ * is based on URI Template
989
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
990
+ * must have one variable: `{identifier}`.
991
+ * @param dispatcher A liked collection callback to register.
992
+ * @returns An object with methods to set other liked collection
993
+ * callbacks.
994
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
995
+ */
996
+ setLikedDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: CollectionDispatcher<Object$1 | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
997
+ /**
998
+ * Registers a featured collection dispatcher.
999
+ * @param path The URI path pattern for the featured collection. The syntax
1000
+ * is based on URI Template
1001
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
1002
+ * must have one variable: `{identifier}`.
1003
+ * @param dispatcher A featured collection callback to register.
1004
+ * @returns An object with methods to set other featured collection
1005
+ * callbacks.
1006
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
1007
+ */
1008
+ setFeaturedDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: CollectionDispatcher<Object$1, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
1009
+ /**
1010
+ * Registers a featured tags collection dispatcher.
1011
+ * @param path The URI path pattern for the featured tags collection.
1012
+ * The syntax is based on URI Template
1013
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
1014
+ * must have one variable: `{identifier}`.
1015
+ * @param dispatcher A featured tags collection callback to register.
1016
+ * @returns An object with methods to set other featured tags collection
1017
+ * callbacks.
1018
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
1019
+ */
1020
+ setFeaturedTagsDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, dispatcher: CollectionDispatcher<Hashtag, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
1021
+ /**
1022
+ * Assigns the URL path for the inbox and starts setting inbox listeners.
1023
+ *
1024
+ * @example
1025
+ * ``` typescript
1026
+ * federation
1027
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
1028
+ * .on(Follow, async (ctx, follow) => {
1029
+ * const from = await follow.getActor(ctx);
1030
+ * if (!isActor(from)) return;
1031
+ * // ...
1032
+ * })
1033
+ * .on(Undo, async (ctx, undo) => {
1034
+ * // ...
1035
+ * });
1036
+ * ```
1037
+ *
1038
+ * @param inboxPath The URI path pattern for the inbox. The syntax is based
1039
+ * on URI Template
1040
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1041
+ * The path must have one variable: `{identifier}`, and must
1042
+ * match the inbox dispatcher path.
1043
+ * @param sharedInboxPath An optional URI path pattern for the shared inbox.
1044
+ * The syntax is based on URI Template
1045
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1046
+ * The path must have no variables.
1047
+ * @returns An object to register inbox listeners.
1048
+ * @throws {RouteError} Thrown if the path pattern is invalid.
1049
+ */
1050
+ setInboxListeners(inboxPath: `${string}${Rfc6570Expression<"identifier">}${string}` | `${string}${Rfc6570Expression<"handle">}${string}`, sharedInboxPath?: string): InboxListenerSetters<TContextData>;
1051
+ /**
1052
+ * Registers a collection of objects dispatcher.
1053
+ *
1054
+ * @template TContextData The context data to pass to the {@link Context}.
1055
+ * @template TObject The type of objects to dispatch.
1056
+ * @template TParam The parameter names of the requested URL.
1057
+ * @param name A unique name for the collection dispatcher.
1058
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
1059
+ * @param path The URI path pattern for the collection dispatcher.
1060
+ * The syntax is based on URI Template
1061
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1062
+ * The path must have one or more variables.
1063
+ * @param dispatcher A collection dispatcher callback to register.
1064
+ */
1065
+ setCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
1066
+ /**
1067
+ * Registers a collection of objects dispatcher.
1068
+ *
1069
+ * @template TContextData The context data to pass to the {@link Context}.
1070
+ * @template TObject The type of objects to dispatch.
1071
+ * @template TParam The parameter names of the requested URL.
1072
+ * @param name A unique name for the collection dispatcher.
1073
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
1074
+ * @param path The URI path pattern for the collection dispatcher.
1075
+ * The syntax is based on URI Template
1076
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1077
+ * The path must have one or more variables.
1078
+ * @param dispatcher A collection dispatcher callback to register.
1079
+ */
1080
+ setCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
1081
+ /**
1082
+ * Registers a collection of objects dispatcher.
1083
+ *
1084
+ * @template TContextData The context data to pass to the {@link Context}.
1085
+ * @template TObject The type of objects to dispatch.
1086
+ * @template TParam The parameter names of the requested URL.
1087
+ * @param name A unique name for the collection dispatcher.
1088
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
1089
+ * @param path The URI path pattern for the collection dispatcher.
1090
+ * The syntax is based on URI Template
1091
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1092
+ * The path must have one or more variables.
1093
+ * @param dispatcher A collection dispatcher callback to register.
1094
+ */
1095
+ setCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
1096
+ /**
1097
+ * Registers an ordered collection of objects dispatcher.
1098
+ *
1099
+ * @template TContextData The context data to pass to the {@link Context}.
1100
+ * @template TObject The type of objects to dispatch.
1101
+ * @template TParam The parameter names of the requested URL.
1102
+ * @param name A unique name for the collection dispatcher.
1103
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
1104
+ * @param path The URI path pattern for the collection dispatcher.
1105
+ * The syntax is based on URI Template
1106
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1107
+ * The path must have one or more variables.
1108
+ * @param dispatcher A collection dispatcher callback to register.
1109
+ */
1110
+ setOrderedCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
1111
+ /**
1112
+ * Registers an ordered collection of objects dispatcher.
1113
+ *
1114
+ * @template TContextData The context data to pass to the {@link Context}.
1115
+ * @template TObject The type of objects to dispatch.
1116
+ * @template TParam The parameter names of the requested URL.
1117
+ * @param name A unique name for the collection dispatcher.
1118
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
1119
+ * @param path The URI path pattern for the collection dispatcher.
1120
+ * The syntax is based on URI Template
1121
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1122
+ * The path must have one or more variables.
1123
+ * @param dispatcher A collection dispatcher callback to register.
1124
+ */
1125
+ setOrderedCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
1126
+ /**
1127
+ * Registers an ordered collection of objects dispatcher.
1128
+ *
1129
+ * @template TContextData The context data to pass to the {@link Context}.
1130
+ * @template TObject The type of objects to dispatch.
1131
+ * @template TParam The parameter names of the requested URL.
1132
+ * @param name A unique name for the collection dispatcher.
1133
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
1134
+ * @param path The URI path pattern for the collection dispatcher.
1135
+ * The syntax is based on URI Template
1136
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
1137
+ * The path must have one or more variables.
1138
+ * @param dispatcher A collection dispatcher callback to register.
1139
+ */
1140
+ setOrderedCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
1141
+ }
1142
+ /**
1143
+ * An object that registers federation-related business logic and dispatches
1144
+ * requests to the appropriate handlers.
1145
+ *
1146
+ * It also provides a middleware interface for handling requests before your
1147
+ * web framework's router; see {@link Federation.fetch}.
1148
+ * @template TContextData The context data to pass to the {@link Context}.
1149
+ * @since 0.13.0
1150
+ */
1151
+ interface Federation<TContextData> extends Federatable<TContextData> {
1152
+ /**
1153
+ * Manually start the task queue.
1154
+ *
1155
+ * This method is useful when you set the `manuallyStartQueue` option to
1156
+ * `true` in the {@link createFederation} function.
1157
+ * @param contextData The context data to pass to the context.
1158
+ * @param options Additional options for starting the queue.
1159
+ */
1160
+ startQueue(contextData: TContextData, options?: FederationStartQueueOptions): Promise<void>;
1161
+ /**
1162
+ * Processes a queued message task. This method handles different types of
1163
+ * tasks such as fanout, outbox, and inbox messages.
1164
+ *
1165
+ * Note that you usually do not need to call this method directly unless you
1166
+ * are deploying your federated application on a platform that does not
1167
+ * support long-running processing, such as Cloudflare Workers.
1168
+ * @param contextData The context data to pass to the context.
1169
+ * @param message The message that represents the task to be processed.
1170
+ * @returns A promise that resolves when the message has been processed.
1171
+ * @since 1.6.0
1172
+ */
1173
+ processQueuedTask(contextData: TContextData, message: Message): Promise<void>;
1174
+ /**
1175
+ * Create a new context.
1176
+ * @param baseUrl The base URL of the server. The `pathname` remains root,
1177
+ * and the `search` and `hash` are stripped.
1178
+ * @param contextData The context data to pass to the context.
1179
+ * @returns The new context.
1180
+ */
1181
+ createContext(baseUrl: URL, contextData: TContextData): Context<TContextData>;
1182
+ /**
1183
+ * Create a new context for a request.
1184
+ * @param request The request object.
1185
+ * @param contextData The context data to pass to the context.
1186
+ * @returns The new request context.
1187
+ */
1188
+ createContext(request: Request, contextData: TContextData): RequestContext<TContextData>;
1189
+ /**
1190
+ * Handles a request related to federation. If a request is not related to
1191
+ * federation, the `onNotFound` or `onNotAcceptable` callback is called.
1192
+ *
1193
+ * Usually, this method is called from a server's request handler or
1194
+ * a web framework's middleware.
1195
+ *
1196
+ * @param request The request object.
1197
+ * @param parameters The parameters for handling the request.
1198
+ * @returns The response to the request.
1199
+ */
1200
+ fetch(request: Request, options: FederationFetchOptions<TContextData>): Promise<Response>;
1201
+ }
1202
+ /**
1203
+ * A builder for creating a {@link Federation} object. It defers the actual
1204
+ * instantiation of the {@link Federation} object until the {@link build}
1205
+ * method is called so that dispatchers and listeners can be registered
1206
+ * before the {@link Federation} object is instantiated.
1207
+ * @template TContextData The context data to pass to the {@link Context}.
1208
+ * @since 1.6.0
1209
+ */
1210
+ interface FederationBuilder<TContextData> extends Federatable<TContextData> {
1211
+ /**
1212
+ * Builds the federation object.
1213
+ * @returns The federation object.
1214
+ */
1215
+ build(options: FederationOptions<TContextData>): Promise<Federation<TContextData>>;
1216
+ }
1217
+ /**
1218
+ * Options for creating a {@link Federation} object.
1219
+ * @template TContextData The context data to pass to the {@link Context}.
1220
+ * @since 1.6.0
1221
+ */
1222
+ interface FederationOptions<TContextData> {
1223
+ /**
1224
+ * The key–value store used for caching, outbox queues, and inbox idempotence.
1225
+ */
1226
+ kv: KvStore;
1227
+ /**
1228
+ * Prefixes for namespacing keys in the Deno KV store. By default, all keys
1229
+ * are prefixed with `["_fedify"]`.
1230
+ */
1231
+ kvPrefixes?: Partial<FederationKvPrefixes>;
1232
+ /**
1233
+ * The message queue for sending and receiving activities. If not provided,
1234
+ * activities will not be queued and will be processed immediately.
1235
+ *
1236
+ * If a `MessageQueue` is provided, both the `inbox` and `outbox` queues
1237
+ * will be set to the same queue.
1238
+ *
1239
+ * If a `FederationQueueOptions` object is provided, you can set the queues
1240
+ * separately (since Fedify 1.3.0).
1241
+ */
1242
+ queue?: FederationQueueOptions | MessageQueue;
1243
+ /**
1244
+ * Whether to start the task queue manually or automatically.
1245
+ *
1246
+ * If `true`, the task queue will not start automatically and you need to
1247
+ * manually start it by calling the {@link Federation.startQueue} method.
1248
+ *
1249
+ * If `false`, the task queue will start automatically as soon as
1250
+ * the first task is enqueued.
1251
+ *
1252
+ * By default, the queue starts automatically.
1253
+ *
1254
+ * @since 0.12.0
1255
+ */
1256
+ manuallyStartQueue?: boolean;
1257
+ /**
1258
+ * The canonical base URL of the server. This is used for constructing
1259
+ * absolute URLs and fediverse handles.
1260
+ * @since 1.5.0
1261
+ */
1262
+ origin?: string | FederationOrigin;
1263
+ /**
1264
+ * A custom JSON-LD document loader factory. By default, this uses
1265
+ * the built-in cache-backed loader that fetches remote documents over
1266
+ * HTTP(S).
1267
+ * @since 1.4.0
1268
+ */
1269
+ documentLoaderFactory?: DocumentLoaderFactory;
1270
+ /**
1271
+ * A custom JSON-LD context loader factory. By default, this uses the same
1272
+ * loader as the document loader.
1273
+ * @since 1.4.0
1274
+ */
1275
+ contextLoaderFactory?: DocumentLoaderFactory;
1276
+ /**
1277
+ * A factory function that creates an authenticated document loader for a
1278
+ * given identity. This is used for fetching documents that require
1279
+ * authentication.
1280
+ */
1281
+ authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
1282
+ /**
1283
+ * Whether to allow fetching private network addresses in the document loader.
1284
+ *
1285
+ * If turned on, {@link CreateFederationOptions.documentLoader},
1286
+ * {@link CreateFederationOptions.contextLoader}, and
1287
+ * {@link CreateFederationOptions.authenticatedDocumentLoaderFactory}
1288
+ * cannot be configured.
1289
+ *
1290
+ * Mostly useful for testing purposes. *Do not use in production.*
1291
+ *
1292
+ * Turned off by default.
1293
+ * @since 0.15.0
1294
+ */
1295
+ allowPrivateAddress?: boolean;
1296
+ /**
1297
+ * Options for making `User-Agent` strings for HTTP requests.
1298
+ * If a string is provided, it is used as the `User-Agent` header.
1299
+ * If an object is provided, it is passed to the {@link getUserAgent}
1300
+ * function.
1301
+ * @since 1.3.0
1302
+ */
1303
+ userAgent?: GetUserAgentOptions | string;
1304
+ /**
1305
+ * A callback that handles errors during outbox processing. Note that this
1306
+ * callback can be called multiple times for the same activity, because
1307
+ * the delivery is retried according to the backoff schedule until it
1308
+ * succeeds or reaches the maximum retry count.
1309
+ *
1310
+ * If any errors are thrown in this callback, they are ignored.
1311
+ */
1312
+ onOutboxError?: OutboxErrorHandler;
1313
+ /**
1314
+ * The time window for verifying HTTP Signatures of incoming requests. If the
1315
+ * request is older or newer than this window, it is rejected. Or if it is
1316
+ * `false`, the request's timestamp is not checked at all.
1317
+ *
1318
+ * By default, the window is an hour.
1319
+ */
1320
+ signatureTimeWindow?: Temporal.Duration | Temporal.DurationLike | false;
1321
+ /**
1322
+ * Whether to skip HTTP Signatures verification for incoming activities.
1323
+ * This is useful for testing purposes, but should not be used in production.
1324
+ *
1325
+ * By default, this is `false` (i.e., signatures are verified).
1326
+ * @since 0.13.0
1327
+ */
1328
+ skipSignatureVerification?: boolean;
1329
+ /**
1330
+ * The HTTP Signatures specification to use for the first signature
1331
+ * attempt when communicating with unknown servers. This option affects
1332
+ * the "double-knocking" mechanism as described in the ActivityPub HTTP
1333
+ * Signature documentation.
1334
+ *
1335
+ * When making HTTP requests to servers that haven't been encountered before,
1336
+ * Fedify will first attempt to sign the request using the specified
1337
+ * signature specification. If the request fails, it will retry with the
1338
+ * alternative specification.
1339
+ *
1340
+ * Defaults to `"rfc9421"` (HTTP Message Signatures).
1341
+ *
1342
+ * @see {@link https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions}
1343
+ * @default `"rfc9421"`
1344
+ * @since 1.7.0
1345
+ */
1346
+ firstKnock?: HttpMessageSignaturesSpec;
1347
+ /**
1348
+ * The retry policy for sending activities to recipients' inboxes.
1349
+ * By default, this uses an exponential backoff strategy with a maximum of
1350
+ * 10 attempts and a maximum delay of 12 hours.
1351
+ * @since 0.12.0
1352
+ */
1353
+ outboxRetryPolicy?: RetryPolicy;
1354
+ /**
1355
+ * The retry policy for processing incoming activities. By default, this
1356
+ * uses an exponential backoff strategy with a maximum of 10 attempts and a
1357
+ * maximum delay of 12 hours.
1358
+ * @since 0.12.0
1359
+ */
1360
+ inboxRetryPolicy?: RetryPolicy;
1361
+ /**
1362
+ * Activity transformers that are applied to outgoing activities. It is
1363
+ * useful for adjusting outgoing activities to satisfy some ActivityPub
1364
+ * implementations.
1365
+ *
1366
+ * By default, {@link defaultActivityTransformers} are applied.
1367
+ * @since 1.4.0
1368
+ */
1369
+ activityTransformers?: readonly ActivityTransformer<TContextData>[];
1370
+ /**
1371
+ * Whether the router should be insensitive to trailing slashes in the URL
1372
+ * paths. For example, if this option is `true`, `/foo` and `/foo/` are
1373
+ * treated as the same path. Turned off by default.
1374
+ * @since 0.12.0
1375
+ */
1376
+ trailingSlashInsensitive?: boolean;
1377
+ /**
1378
+ * The OpenTelemetry tracer provider for tracing operations. If not provided,
1379
+ * the default global tracer provider is used.
1380
+ * @since 1.3.0
1381
+ */
1382
+ tracerProvider?: TracerProvider;
1383
+ }
1384
+ /**
1385
+ * Additional settings for the actor dispatcher.
1386
+ *
1387
+ * ``` typescript
1388
+ * const federation = createFederation<void>({ ... });
1389
+ * federation
1390
+ * .setActorDispatcher("/users/{identifier}", async (ctx, identifier) => {
1391
+ * // ...
1392
+ * })
1393
+ * .setKeyPairsDispatcher(async (ctxData, identifier) => {
1394
+ * // ...
1395
+ * });
1396
+ * ```
1397
+ */
1398
+ interface ActorCallbackSetters<TContextData> {
1399
+ /**
1400
+ * Sets the key pairs dispatcher for actors.
1401
+ * @param dispatcher A callback that returns the key pairs for an actor.
1402
+ * @returns The setters object so that settings can be chained.
1403
+ * @since 0.10.0
1404
+ */
1405
+ setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
1406
+ /**
1407
+ * Sets the callback function that maps a WebFinger username to
1408
+ * the corresponding actor's identifier. If it's omitted, the identifier
1409
+ * is assumed to be the same as the WebFinger username, which makes your
1410
+ * actors have the immutable handles. If you want to let your actors change
1411
+ * their fediverse handles, you should set this dispatcher.
1412
+ * @param mapper A callback that maps a WebFinger username to
1413
+ * the corresponding actor's identifier.
1414
+ * @returns The setters object so that settings can be chained.
1415
+ * @since 0.15.0
1416
+ */
1417
+ mapHandle(mapper: ActorHandleMapper<TContextData>): ActorCallbackSetters<TContextData>;
1418
+ /**
1419
+ * Sets the callback function that maps a WebFinger query to the corresponding
1420
+ * actor's identifier or username. If it's omitted, the WebFinger handler
1421
+ * only supports the actor URIs and `acct:` URIs. If you want to support
1422
+ * other queries, you should set this dispatcher.
1423
+ * @param mapper A callback that maps a WebFinger query to the corresponding
1424
+ * actor's identifier or username.
1425
+ * @returns The setters object so that settings can be chained.
1426
+ * @since 1.4.0
1427
+ */
1428
+ mapAlias(mapper: ActorAliasMapper<TContextData>): ActorCallbackSetters<TContextData>;
1429
+ /**
1430
+ * Specifies the conditions under which requests are authorized.
1431
+ * @param predicate A callback that returns whether a request is authorized.
1432
+ * @returns The setters object so that settings can be chained.
1433
+ * @since 0.7.0
1434
+ */
1435
+ authorize(predicate: AuthorizePredicate<TContextData>): ActorCallbackSetters<TContextData>;
1436
+ }
1437
+ /**
1438
+ * Additional settings for an object dispatcher.
1439
+ */
1440
+ interface ObjectCallbackSetters<TContextData, TObject extends Object$1, TParam extends string> {
1441
+ /**
1442
+ * Specifies the conditions under which requests are authorized.
1443
+ * @param predicate A callback that returns whether a request is authorized.
1444
+ * @returns The setters object so that settings can be chained.
1445
+ * @since 0.7.0
1446
+ */
1447
+ authorize(predicate: ObjectAuthorizePredicate<TContextData, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
1448
+ }
1449
+ /**
1450
+ * Additional settings for a collection dispatcher.
1451
+ *
1452
+ * @template TContext The type of the context. {@link Context} or
1453
+ * {@link RequestContext}.
1454
+ * @template TContextData The context data to pass to the {@link Context}.
1455
+ * @template TFilter The type of filter for the collection.
1456
+ */
1457
+ interface CollectionCallbackSetters<TContext extends Context<TContextData>, TContextData, TFilter> {
1458
+ /**
1459
+ * Sets the counter for the collection.
1460
+ * @param counter A callback that returns the number of items in the collection.
1461
+ * @returns The setters object so that settings can be chained.
1462
+ */
1463
+ setCounter(counter: CollectionCounter<TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1464
+ /**
1465
+ * Sets the first cursor for the collection.
1466
+ * @param cursor The cursor for the first item in the collection.
1467
+ * @returns The setters object so that settings can be chained.
1468
+ */
1469
+ setFirstCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1470
+ /**
1471
+ * Sets the last cursor for the collection.
1472
+ * @param cursor The cursor for the last item in the collection.
1473
+ * @returns The setters object so that settings can be chained.
1474
+ */
1475
+ setLastCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1476
+ /**
1477
+ * Specifies the conditions under which requests are authorized.
1478
+ * @param predicate A callback that returns whether a request is authorized.
1479
+ * @returns The setters object so that settings can be chained.
1480
+ * @since 0.7.0
1481
+ */
1482
+ authorize(predicate: AuthorizePredicate<TContextData>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1483
+ }
1484
+ /**
1485
+ * The strategy for handling activity idempotency in inbox processing.
1486
+ *
1487
+ * - `"global"`: Activities are deduplicated globally across all inboxes and
1488
+ * origins. The same activity ID will be processed only once, regardless
1489
+ * of which inbox receives it or which server sent it.
1490
+ *
1491
+ * - `"per-origin"`: Activities are deduplicated per receiving server's origin.
1492
+ * The same activity ID will be processed only once on each receiving server,
1493
+ * but can be processed separately on different receiving servers. This had
1494
+ * been the default behavior in Fedify 1.x versions.
1495
+ *
1496
+ * - `"per-inbox"`: Activities are deduplicated per inbox. The same activity
1497
+ * ID can be processed once per inbox, allowing the same activity to be
1498
+ * delivered to multiple inboxes independently. This follows standard
1499
+ * ActivityPub behavior and is the default strategy since Fedify 2.0.0.
1500
+ *
1501
+ * @since 1.9.0
1502
+ */
1503
+ type IdempotencyStrategy = "global" | "per-origin" | "per-inbox";
1504
+ /**
1505
+ * A callback to generate a custom idempotency key for an activity.
1506
+ * Returns the cache key to use, or null to skip idempotency checking.
1507
+ * @template TContextData The context data to pass to the {@link InboxContext}.
1508
+ * @param ctx The inbox context.
1509
+ * @param activity The activity being processed.
1510
+ * @returns The idempotency key to use for caching, or null to skip caching.
1511
+ * @since 1.9.0
1512
+ */
1513
+ type IdempotencyKeyCallback<TContextData> = (ctx: InboxContext<TContextData>, activity: Activity) => string | null | Promise<string | null>;
1514
+ /**
1515
+ * Registry for inbox listeners for different activity types.
1516
+ */
1517
+ interface InboxListenerSetters<TContextData> {
1518
+ /**
1519
+ * Registers a listener for a specific incoming activity type.
1520
+ *
1521
+ * @param type A subclass of {@link Activity} to listen to.
1522
+ * @param listener A callback to handle an incoming activity.
1523
+ * @returns The setters object so that settings can be chained.
1524
+ */
1525
+ on<TActivity extends Activity>(type: new (...args: any[]) => TActivity, listener: InboxListener<TContextData, TActivity>): InboxListenerSetters<TContextData>;
1526
+ /**
1527
+ * Registers an error handler for inbox listeners. Any exceptions thrown
1528
+ * from the listeners are caught and passed to this handler.
1529
+ *
1530
+ * @param handler A callback to handle an error.
1531
+ * @returns The setters object so that settings can be chained.
1532
+ */
1533
+ onError(handler: InboxErrorHandler<TContextData>): InboxListenerSetters<TContextData>;
1534
+ /**
1535
+ * Configures a callback to dispatch the key pair for the authenticated
1536
+ * document loader of the {@link Context} passed to the shared inbox listener.
1537
+ *
1538
+ * @param dispatcher A callback to dispatch the key pair for the authenticated
1539
+ * document loader.
1540
+ * @returns The setters object so that settings can be chained.
1541
+ * @since 0.11.0
1542
+ */
1543
+ setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
1544
+ /**
1545
+ * Configures the strategy for handling activity idempotency in inbox processing.
1546
+ *
1547
+ * @example
1548
+ * Use per-inbox strategy (standard ActivityPub behavior):
1549
+ * ```
1550
+ * federation
1551
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
1552
+ * .withIdempotency("per-inbox");
1553
+ * ```
1554
+ *
1555
+ * Use custom strategy:
1556
+ * ```
1557
+ * federation
1558
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
1559
+ * .withIdempotency((ctx, activity) => {
1560
+ * // Return null to skip idempotency
1561
+ * return `${ctx.origin}:${activity.id?.href}:${ctx.recipient}`;
1562
+ * });
1563
+ * ```
1564
+ *
1565
+ * @param strategy The idempotency strategy to use. Can be:
1566
+ * - `"global"`: Activities are deduplicated across all inboxes and origins
1567
+ * - `"per-origin"`: Activities are deduplicated per inbox origin
1568
+ * - `"per-inbox"`: Activities are deduplicated per inbox
1569
+ * - A custom callback function that returns the cache key to use
1570
+ * @returns The setters object so that settings can be chained.
1571
+ * @since 1.9.0
1572
+ */
1573
+ withIdempotency(strategy: IdempotencyStrategy | IdempotencyKeyCallback<TContextData>): InboxListenerSetters<TContextData>;
1574
+ }
1575
+ /**
1576
+ * Parameters of {@link Federation.fetch} method.
1577
+ *
1578
+ * @template TContextData The context data to pass to the {@link Context}.
1579
+ * @since 0.6.0
1580
+ */
1581
+ interface FederationFetchOptions<TContextData> {
1582
+ /**
1583
+ * The context data to pass to the {@link Context}.
1584
+ */
1585
+ contextData: TContextData;
1586
+ /**
1587
+ * A callback to handle a request when the route is not found.
1588
+ * If not provided, a 404 response is returned.
1589
+ * @param request The request object.
1590
+ * @returns The response to the request.
1591
+ */
1592
+ onNotFound?: (request: Request) => Response | Promise<Response>;
1593
+ /**
1594
+ * A callback to handle a request when the request's `Accept` header is not
1595
+ * acceptable. If not provided, a 406 response is returned.
1596
+ * @param request The request object.
1597
+ * @returns The response to the request.
1598
+ */
1599
+ onNotAcceptable?: (request: Request) => Response | Promise<Response>;
1600
+ /**
1601
+ * A callback to handle a request when the request is unauthorized.
1602
+ * If not provided, a 401 response is returned.
1603
+ * @param request The request object.
1604
+ * @returns The response to the request.
1605
+ * @since 0.7.0
1606
+ */
1607
+ onUnauthorized?: (request: Request) => Response | Promise<Response>;
1608
+ }
1609
+ /**
1610
+ * Additional settings for a custom collection dispatcher.
1611
+ *
1612
+ * @template TParam The type of the parameters in the URL path.
1613
+ * @template TContext The type of the context. {@link Context} or
1614
+ * {@link RequestContext}.
1615
+ * @template TContextData The context data to pass to the {@link Context}.
1616
+ * @template TFilter The type of filter for the collection.
1617
+ */
1618
+ interface CustomCollectionCallbackSetters<TParam extends string, TContext extends Context<TContextData>, TContextData> {
1619
+ /**
1620
+ * Sets the counter for the custom collection.
1621
+ * @param counter A callback that returns the number of items in the custom collection.
1622
+ * @returns The setters object so that settings can be chained.
1623
+ */
1624
+ setCounter(counter: CustomCollectionCounter<TParam, TContextData>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1625
+ /**
1626
+ * Sets the first cursor for the custom collection.
1627
+ * @param cursor The cursor for the first item in the custom collection.
1628
+ * @returns The setters object so that settings can be chained.
1629
+ */
1630
+ setFirstCursor(cursor: CustomCollectionCursor<TParam, TContext, TContextData>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1631
+ /**
1632
+ * Sets the last cursor for the custom collection.
1633
+ * @param cursor The cursor for the last item in the custom collection.
1634
+ * @returns The setters object so that settings can be chained.
1635
+ */
1636
+ setLastCursor(cursor: CustomCollectionCursor<TParam, TContext, TContextData>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1637
+ /**
1638
+ * Specifies the conditions under which requests are authorized.
1639
+ * @param predicate A callback that returns whether a request is authorized.
1640
+ * @returns The setters object so that settings can be chained.
1641
+ * @since 0.7.0
1642
+ */
1643
+ authorize(predicate: ObjectAuthorizePredicate<TContextData, string>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1644
+ }
1645
+ /**
1646
+ * Represents an object with a type ID, which is either a constructor or an
1647
+ * instance of the object.
1648
+ *
1649
+ * @template TObject The type of the object.
1650
+ */
1651
+ type ConstructorWithTypeId<TObject extends Object$1> = (new (...args: any[]) => TObject) & {
1652
+ typeId: URL;
1653
+ };
1654
+ /**
1655
+ * Defines a union of all valid RFC 6570 URI Template expressions for a given
1656
+ * parameter name.
1657
+ *
1658
+ * RFC 6570 specifies a syntax for URI templates, allowing for variable
1659
+ * expansion. This type captures all Level 1-4 operator expressions for a
1660
+ * single, named variable.
1661
+ *
1662
+ * The supported expression types are:
1663
+ * - `{Param}`: Simple string expansion
1664
+ * - `+{Param}`: Reserved string expansion
1665
+ * - `#{Param}`: Fragment expansion
1666
+ * - `{.Param}`: Label expansion with a dot-prefix
1667
+ * - `{/Param}`: Path segment expansion
1668
+ * - `{;Param}`: Path-style parameter expansion
1669
+ * - `{?Param}`: Query component expansion
1670
+ * - `{&Param}`: Query continuation expansion
1671
+ *
1672
+ * @template Param The name of the parameter to be used in the expressions.
1673
+ * @example
1674
+ * ```ts
1675
+ * type UserIdExpression = Rfc6570Expression<"userId">;
1676
+ *
1677
+ * // The variable `userPath` can be assigned any of the valid expressions.
1678
+ * const userPath: UserIdExpression = "{/userId}";
1679
+ * ```
1680
+ * @see {@link https://tools.ietf.org/html/rfc6570} for the full specification.
1681
+ */
1682
+ type Rfc6570Expression<Param extends string> = `{${Param}}` | `{+${Param}}` | `{#${Param}}` | `{.${Param}}` | `{/${Param}}` | `{;${Param}}` | `{?${Param}}` | `{&${Param}}`;
1683
+ //#endregion
1684
+ //#region src/federation/context.d.ts
1685
+ /**
1686
+ * A context.
1687
+ */
1688
+ interface Context<TContextData> {
1689
+ /**
1690
+ * The origin of the federated server, including the scheme (`http://` or
1691
+ * `https://`) and the host (e.g., `example.com:8080`).
1692
+ * @since 0.12.0
1693
+ */
1694
+ readonly origin: string;
1695
+ /**
1696
+ * The canonical origin of the federated server, including the scheme
1697
+ * (`http://` or `https://`) and the host (e.g., `example.com:8080`).
1698
+ *
1699
+ * When the associated {@link Federation} object does not have any explicit
1700
+ * canonical origin, it is the same as the {@link Context.origin}.
1701
+ * @since 1.5.0
1702
+ */
1703
+ readonly canonicalOrigin: string;
1704
+ /**
1705
+ * The host of the federated server, including the hostname
1706
+ * (e.g., `example.com`) and the port following a colon (e.g., `:8080`)
1707
+ * if it is not the default port for the scheme.
1708
+ * @since 0.12.0
1709
+ */
1710
+ readonly host: string;
1711
+ /**
1712
+ * The hostname of the federated server (e.g., `example.com`). This is
1713
+ * the same as the host without the port.
1714
+ * @since 0.12.0
1715
+ */
1716
+ readonly hostname: string;
1717
+ /**
1718
+ * The user-defined data associated with the context.
1719
+ */
1720
+ readonly data: TContextData;
1721
+ /**
1722
+ * The OpenTelemetry tracer provider.
1723
+ * @since 1.3.0
1724
+ */
1725
+ readonly tracerProvider: TracerProvider;
1726
+ /**
1727
+ * The document loader for loading remote JSON-LD documents.
1728
+ */
1729
+ readonly documentLoader: DocumentLoader;
1730
+ /**
1731
+ * The context loader for loading remote JSON-LD contexts.
1732
+ */
1733
+ readonly contextLoader: DocumentLoader;
1734
+ /**
1735
+ * The federation object that this context belongs to.
1736
+ * @since 1.6.0
1737
+ */
1738
+ readonly federation: Federation<TContextData>;
1739
+ /**
1740
+ * Creates a new context with the same properties as this one,
1741
+ * but with the given data.
1742
+ * @param data The new data to associate with the context.
1743
+ * @returns A new context with the same properties as this one,
1744
+ * but with the given data.
1745
+ * @since 1.6.0
1746
+ */
1747
+ clone(data: TContextData): Context<TContextData>;
1748
+ /**
1749
+ * Builds the URI of the NodeInfo document.
1750
+ * @returns The NodeInfo URI.
1751
+ * @throws {RouterError} If no NodeInfo dispatcher is available.
1752
+ * @since 0.2.0
1753
+ */
1754
+ getNodeInfoUri(): URL;
1755
+ /**
1756
+ * Builds the URI of an actor with the given identifier.
1757
+ * @param identifier The actor's identifier.
1758
+ * @returns The actor's URI.
1759
+ * @throws {RouterError} If no actor dispatcher is available.
1760
+ */
1761
+ getActorUri(identifier: string): URL;
1762
+ /**
1763
+ * Builds the URI of an object with the given class and values.
1764
+ * @param cls The class of the object.
1765
+ * @param values The values to pass to the object dispatcher.
1766
+ * @returns The object's URI.
1767
+ * @throws {RouteError} If no object dispatcher is available for the class.
1768
+ * @throws {TypeError} If values are invalid.
1769
+ * @since 0.7.0
1770
+ */
1771
+ getObjectUri<TObject extends Object$1>(cls: ConstructorWithTypeId<TObject>, values: Record<string, string>): URL;
1772
+ /**
1773
+ * Builds the URI of an actor's outbox with the given identifier.
1774
+ * @param identifier The actor's identifier.
1775
+ * @returns The actor's outbox URI.
1776
+ * @throws {RouterError} If no outbox dispatcher is available.
1777
+ */
1778
+ getOutboxUri(identifier: string): URL;
1779
+ /**
1780
+ * Builds the URI of the shared inbox.
1781
+ * @returns The shared inbox URI.
1782
+ * @throws {RouterError} If no inbox listener is available.
1783
+ */
1784
+ getInboxUri(): URL;
1785
+ /**
1786
+ * Builds the URI of an actor's inbox with the given identifier.
1787
+ * @param identifier The actor's identifier.
1788
+ * @returns The actor's inbox URI.
1789
+ * @throws {RouterError} If no inbox listener is available.
1790
+ */
1791
+ getInboxUri(identifier: string): URL;
1792
+ /**
1793
+ * Builds the URI of an actor's following collection with the given
1794
+ * identifier.
1795
+ * @param identifier The actor's identifier.
1796
+ * @returns The actor's following collection URI.
1797
+ * @throws {RouterError} If no following collection is available.
1798
+ */
1799
+ getFollowingUri(identifier: string): URL;
1800
+ /**
1801
+ * Builds the URI of an actor's followers collection with the given
1802
+ * identifier.
1803
+ * @param identifier The actor's identifier.
1804
+ * @returns The actor's followers collection URI.
1805
+ * @throws {RouterError} If no followers collection is available.
1806
+ */
1807
+ getFollowersUri(identifier: string): URL;
1808
+ /**
1809
+ * Builds the URI of an actor's liked collection with the given identifier.
1810
+ * @param identifier The actor's identifier.
1811
+ * @returns The actor's liked collection URI.
1812
+ * @throws {RouterError} If no liked collection is available.
1813
+ * @since 0.11.0
1814
+ */
1815
+ getLikedUri(identifier: string): URL;
1816
+ /**
1817
+ * Builds the URI of an actor's featured collection with the given identifier.
1818
+ * @param identifier The actor's identifier.
1819
+ * @returns The actor's featured collection URI.
1820
+ * @throws {RouterError} If no featured collection is available.
1821
+ * @since 0.11.0
1822
+ */
1823
+ getFeaturedUri(identifier: string): URL;
1824
+ /**
1825
+ * Builds the URI of an actor's featured tags collection with the given
1826
+ * identifier.
1827
+ * @param identifier The actor's identifier.
1828
+ * @returns The actor's featured tags collection URI.
1829
+ * @throws {RouterError} If no featured tags collection is available.
1830
+ * @since 0.11.0
1831
+ */
1832
+ getFeaturedTagsUri(identifier: string): URL;
1833
+ /**
1834
+ * Determines the type of the URI and extracts the associated data.
1835
+ * @param uri The URI to parse.
1836
+ * @returns The result of parsing the URI. If `null` is given or
1837
+ * the URI is not recognized, `null` is returned.
1838
+ * @since 0.9.0
1839
+ */
1840
+ parseUri(uri: URL | null): ParseUriResult | null;
1841
+ /**
1842
+ * Gets the key pairs for an actor.
1843
+ * @param identifier The actor's identifier.
1844
+ * @returns An async iterable of the actor's key pairs. It can be empty.
1845
+ * @since 0.10.0
1846
+ */
1847
+ getActorKeyPairs(identifier: string): Promise<ActorKeyPair[]>;
1848
+ /**
1849
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
1850
+ * Note that an authenticated document loader intentionally does not cache
1851
+ * the fetched documents.
1852
+ * @param identity The identity to get the document loader for.
1853
+ * The actor's identifier or username.
1854
+ * @returns The authenticated document loader.
1855
+ * @throws {Error} If the identity is not valid.
1856
+ * @throws {TypeError} If the key is invalid or unsupported.
1857
+ * @since 0.4.0
1858
+ */
1859
+ getDocumentLoader(identity: {
1860
+ identifier: string;
1861
+ } | {
1862
+ username: string;
1863
+ } | {
1864
+ handle: string;
1865
+ }): Promise<DocumentLoader>;
1866
+ /**
1867
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
1868
+ * Note that an authenticated document loader intentionally does not cache
1869
+ * the fetched documents.
1870
+ * @param identity The identity to get the document loader for.
1871
+ * The actor's key pair.
1872
+ * @returns The authenticated document loader.
1873
+ * @throws {TypeError} If the key is invalid or unsupported.
1874
+ * @since 0.4.0
1875
+ */
1876
+ getDocumentLoader(identity: {
1877
+ keyId: URL;
1878
+ privateKey: CryptoKey;
1879
+ }): DocumentLoader;
1880
+ /**
1881
+ * Looks up an ActivityStreams object by its URI (including `acct:` URIs)
1882
+ * or a fediverse handle (e.g., `@user@server` or `user@server`).
1883
+ *
1884
+ * @example
1885
+ * ``` typescript
1886
+ * // Look up an actor by its fediverse handle:
1887
+ * await ctx.lookupObject("@hongminhee@fosstodon.org");
1888
+ * // returning a `Person` object.
1889
+ *
1890
+ * // A fediverse handle can omit the leading '@':
1891
+ * await ctx.lookupObject("hongminhee@fosstodon.org");
1892
+ * // returning a `Person` object.
1893
+ *
1894
+ * // A `acct:` URI can be used as well:
1895
+ * await ctx.lookupObject("acct:hongminhee@fosstodon.org");
1896
+ * // returning a `Person` object.
1897
+ *
1898
+ * // Look up an object by its URI:
1899
+ * await ctx.lookupObject("https://todon.eu/@hongminhee/112060633798771581");
1900
+ * // returning a `Note` object.
1901
+ *
1902
+ * // It can be a `URL` object as well:
1903
+ * await ctx.lookupObject(
1904
+ * new URL("https://todon.eu/@hongminhee/112060633798771581")
1905
+ * );
1906
+ * // returning a `Note` object.
1907
+ * ```
1908
+ *
1909
+ * It's almost the same as the {@link lookupObject} function, but it uses
1910
+ * the context's document loader and context loader by default.
1911
+ *
1912
+ * @param identifier The URI or fediverse handle to look up.
1913
+ * @param options Lookup options.
1914
+ * @returns The object, or `null` if not found.
1915
+ * @since 0.15.0
1916
+ */
1917
+ lookupObject(identifier: string | URL, options?: LookupObjectOptions): Promise<Object$1 | null>;
1918
+ /**
1919
+ * Traverses a collection, yielding each item in the collection.
1920
+ * If the collection is paginated, it will fetch the next page
1921
+ * automatically.
1922
+ *
1923
+ * @example
1924
+ * ``` typescript
1925
+ * const collection = await ctx.lookupObject(collectionUrl);
1926
+ * if (collection instanceof Collection) {
1927
+ * for await (const item of ctx.traverseCollection(collection)) {
1928
+ * console.log(item.id?.href);
1929
+ * }
1930
+ * }
1931
+ * ```
1932
+ *
1933
+ * It's almost the same as the {@link traverseCollection} function, but it
1934
+ * uses the context's document loader and context loader by default.
1935
+ * @param collection The collection to traverse.
1936
+ * @param options Options for traversing the collection.
1937
+ * @returns An async iterable of each item in the collection.
1938
+ * @since 1.1.0
1939
+ */
1940
+ traverseCollection(collection: Collection, options?: TraverseCollectionOptions): AsyncIterable<Object$1 | Link>;
1941
+ /**
1942
+ * Fetches the NodeInfo document from the given URL.
1943
+ * @param url The base URL of the server. If `options.direct` is turned off
1944
+ * (default), the NodeInfo document will be fetched from
1945
+ * the `.well-known` location of this URL (hence the only origin
1946
+ * of the URL is used). If `options.direct` is turned on,
1947
+ * the NodeInfo document will be fetched from the given URL.
1948
+ * @param options Options for fetching the NodeInfo document.
1949
+ * @returns The NodeInfo document if it could be fetched successfully.
1950
+ * Otherwise, `undefined` is returned.
1951
+ * @since 1.4.0
1952
+ */
1953
+ lookupNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
1954
+ parse?: "strict" | "best-effort";
1955
+ }): Promise<NodeInfo | undefined>;
1956
+ /**
1957
+ * Fetches the NodeInfo document from the given URL.
1958
+ * @param url The base URL of the server. If `options.direct` is turned off
1959
+ * (default), the NodeInfo document will be fetched from
1960
+ * the `.well-known` location of this URL (hence the only origin
1961
+ * of the URL is used). If `options.direct` is turned on,
1962
+ * the NodeInfo document will be fetched from the given URL.
1963
+ * @param options Options for fetching the NodeInfo document.
1964
+ * @returns The NodeInfo document if it could be fetched successfully.
1965
+ * Otherwise, `undefined` is returned.
1966
+ * @since 1.4.0
1967
+ */
1968
+ lookupNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
1969
+ parse: "none";
1970
+ }): Promise<JsonValue | undefined>;
1971
+ /**
1972
+ * Looks up a WebFinger resource.
1973
+ *
1974
+ * It's almost the same as the {@link lookupWebFinger} function, but it uses
1975
+ * the context's configuration by default.
1976
+ *
1977
+ * @param resource The resource URL to look up.
1978
+ * @param options Extra options for looking up the resource.
1979
+ * @returns The resource descriptor, or `null` if not found.
1980
+ * @since 1.6.0
1981
+ */
1982
+ lookupWebFinger(resource: URL | string, options?: LookupWebFingerOptions): Promise<ResourceDescriptor | null>;
1983
+ /**
1984
+ * Sends an activity to recipients' inboxes.
1985
+ * @param sender The sender's identifier or the sender's username or
1986
+ * the sender's key pair(s).
1987
+ * @param recipients The recipients of the activity.
1988
+ * @param activity The activity to send.
1989
+ * @param options Options for sending the activity.
1990
+ */
1991
+ sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
1992
+ identifier: string;
1993
+ } | {
1994
+ username: string;
1995
+ } | {
1996
+ handle: string;
1997
+ }, recipients: Recipient | Recipient[], activity: Activity, options?: SendActivityOptions): Promise<void>;
1998
+ /**
1999
+ * Sends an activity to the outboxes of the sender's followers.
2000
+ * @param sender The sender's identifier or the sender's username.
2001
+ * @param recipients In this case, it must be `"followers"`.
2002
+ * @param activity The activity to send.
2003
+ * @param options Options for sending the activity.
2004
+ * @throws {Error} If no followers collection is registered.
2005
+ * @since 0.14.0
2006
+ */
2007
+ sendActivity(sender: {
2008
+ identifier: string;
2009
+ } | {
2010
+ username: string;
2011
+ } | {
2012
+ handle: string;
2013
+ }, recipients: "followers", activity: Activity, options?: SendActivityOptionsForCollection): Promise<void>;
2014
+ /**
2015
+ * Manually routes an activity to the appropriate inbox listener.
2016
+ *
2017
+ * It is useful for routing an activity that is not received from the network,
2018
+ * or for routing an activity that is enclosed in another activity.
2019
+ *
2020
+ * Note that the activity will be verified if it has Object Integrity Proofs
2021
+ * or is equivalent to the actual remote object. If the activity is not
2022
+ * verified, it will be rejected.
2023
+ * @param recipient The recipient of the activity. If it is `null`,
2024
+ * the activity will be routed to the shared inbox.
2025
+ * Otherwise, the activity will be routed to the personal
2026
+ * inbox of the recipient with the given identifier.
2027
+ * @param activity The activity to route. It must have a proof or
2028
+ * a dereferenceable `id` to verify the activity.
2029
+ * @param options Options for routing the activity.
2030
+ * @returns `true` if the activity is successfully verified and routed.
2031
+ * Otherwise, `false`.
2032
+ * @since 1.3.0
2033
+ */
2034
+ routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
2035
+ /**
2036
+ * Builds the URI of a collection of objects with the given name and values.
2037
+ * @param name The name of the collection, which can be a string or a symbol.
2038
+ * @param values The values of the URI parameters.
2039
+ * @return The URI of the collection.
2040
+ * @throws {RouteError} If no object dispatcher is available for the name.
2041
+ * @throws {TypeError} If values are invalid.
2042
+ * @since 1.8.0
2043
+ */
2044
+ getCollectionUri<TParam extends Record<string, string>>(name: string | symbol, values: TParam): URL;
2045
+ }
2046
+ /**
2047
+ * A context for a request.
2048
+ */
2049
+ interface RequestContext<TContextData> extends Context<TContextData> {
2050
+ /**
2051
+ * The request object.
2052
+ */
2053
+ readonly request: Request;
2054
+ /**
2055
+ * The URL of the request.
2056
+ */
2057
+ readonly url: URL;
2058
+ /**
2059
+ * Creates a new context with the same properties as this one,
2060
+ * but with the given data.
2061
+ * @param data The new data to associate with the context.
2062
+ * @returns A new context with the same properties as this one,
2063
+ * but with the given data.
2064
+ * @since 1.6.0
2065
+ */
2066
+ clone(data: TContextData): RequestContext<TContextData>;
2067
+ /**
2068
+ * Gets an {@link Actor} object for the given identifier.
2069
+ * @param identifier The actor's identifier.
2070
+ * @returns The actor object, or `null` if the actor is not found.
2071
+ * @throws {Error} If no actor dispatcher is available.
2072
+ * @since 0.7.0
2073
+ */
2074
+ getActor(identifier: string): Promise<Actor | null>;
2075
+ /**
2076
+ * Gets an object of the given class with the given values.
2077
+ * @param cls The class to instantiate.
2078
+ * @param values The values to pass to the object dispatcher.
2079
+ * @returns The object of the given class with the given values, or `null`
2080
+ * if the object is not found.
2081
+ * @throws {Error} If no object dispatcher is available for the class.
2082
+ * @throws {TypeError} If values are invalid.
2083
+ * @since 0.7.0
2084
+ */
2085
+ getObject<TObject extends Object$1>(cls: ConstructorWithTypeId<TObject>, values: Record<string, string>): Promise<TObject | null>;
2086
+ /**
2087
+ * Gets the public key of the sender, if any exists and it is verified.
2088
+ * Otherwise, `null` is returned.
2089
+ *
2090
+ * This can be used for implementing [authorized fetch] (also known as
2091
+ * secure mode) in ActivityPub.
2092
+ *
2093
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
2094
+ *
2095
+ * @returns The public key of the sender, or `null` if the sender is not verified.
2096
+ * @since 0.7.0
2097
+ */
2098
+ getSignedKey(): Promise<CryptographicKey | null>;
2099
+ /**
2100
+ * Gets the public key of the sender, if any exists and it is verified.
2101
+ * Otherwise, `null` is returned.
2102
+ *
2103
+ * This can be used for implementing [authorized fetch] (also known as
2104
+ * secure mode) in ActivityPub.
2105
+ *
2106
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
2107
+ *
2108
+ * @param options Options for getting the signed key. You usually may want to
2109
+ * specify the custom `documentLoader` so that making
2110
+ * an HTTP request to the sender's server is signed with
2111
+ * your [instance actor].
2112
+ * @returns The public key of the sender, or `null` if the sender is not verified.
2113
+ * @since 1.5.0
2114
+ *
2115
+ * [instance actor]: https://swicg.github.io/activitypub-http-signature/#instance-actor
2116
+ */
2117
+ getSignedKey(options: GetSignedKeyOptions): Promise<CryptographicKey | null>;
2118
+ /**
2119
+ * Gets the owner of the signed key, if any exists and it is verified.
2120
+ * Otherwise, `null` is returned.
2121
+ *
2122
+ * This can be used for implementing [authorized fetch] (also known as
2123
+ * secure mode) in ActivityPub.
2124
+ *
2125
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
2126
+ *
2127
+ * @returns The owner of the signed key, or `null` if the key is not verified
2128
+ * or the owner is not found.
2129
+ * @since 0.7.0
2130
+ */
2131
+ getSignedKeyOwner(): Promise<Actor | null>;
2132
+ /**
2133
+ * Gets the owner of the signed key, if any exists and it is verified.
2134
+ * Otherwise, `null` is returned.
2135
+ *
2136
+ * This can be used for implementing [authorized fetch] (also known as
2137
+ * secure mode) in ActivityPub.
2138
+ *
2139
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
2140
+ *
2141
+ * @param options Options for getting the key owner. You usually may want to
2142
+ * specify the custom `documentLoader` so that making
2143
+ * an HTTP request to the key owner's server is signed with
2144
+ * your [instance actor].
2145
+ * @returns The owner of the signed key, or `null` if the key is not verified
2146
+ * or the owner is not found.
2147
+ * @since 1.5.0
2148
+ *
2149
+ * [instance actor]: https://swicg.github.io/activitypub-http-signature/#instance-actor
2150
+ */
2151
+ getSignedKeyOwner(options: GetKeyOwnerOptions): Promise<Actor | null>;
2152
+ }
2153
+ /**
2154
+ * A context for inbox listeners.
2155
+ * @since 1.0.0
2156
+ */
2157
+ interface InboxContext<TContextData> extends Context<TContextData> {
2158
+ /**
2159
+ * The identifier of the recipient of the inbox. If the inbox is a shared
2160
+ * inbox, it is `null`.
2161
+ * @since 1.2.0
2162
+ */
2163
+ recipient: string | null;
2164
+ /**
2165
+ * Creates a new context with the same properties as this one,
2166
+ * but with the given data.
2167
+ * @param data The new data to associate with the context.
2168
+ * @returns A new context with the same properties as this one,
2169
+ * but with the given data.
2170
+ * @since 1.6.0
2171
+ */
2172
+ clone(data: TContextData): InboxContext<TContextData>;
2173
+ /**
2174
+ * Forwards a received activity to the recipients' inboxes. The forwarded
2175
+ * activity will be signed in HTTP Signatures by the forwarder, but its
2176
+ * payload will not be modified, i.e., Linked Data Signatures and Object
2177
+ * Integrity Proofs will not be added. Therefore, if the activity is not
2178
+ * signed (i.e., it has neither Linked Data Signatures nor Object Integrity
2179
+ * Proofs), the recipient probably will not trust the activity.
2180
+ * @param forwarder The forwarder's identifier or the forwarder's username
2181
+ * or the forwarder's key pair(s).
2182
+ * @param recipients The recipients of the activity.
2183
+ * @param options Options for forwarding the activity.
2184
+ * @since 1.0.0
2185
+ */
2186
+ forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
2187
+ identifier: string;
2188
+ } | {
2189
+ username: string;
2190
+ } | {
2191
+ handle: string;
2192
+ }, recipients: Recipient | Recipient[], options?: ForwardActivityOptions): Promise<void>;
2193
+ /**
2194
+ * Forwards a received activity to the recipients' inboxes. The forwarded
2195
+ * activity will be signed in HTTP Signatures by the forwarder, but its
2196
+ * payload will not be modified, i.e., Linked Data Signatures and Object
2197
+ * Integrity Proofs will not be added. Therefore, if the activity is not
2198
+ * signed (i.e., it has neither Linked Data Signatures nor Object Integrity
2199
+ * Proofs), the recipient probably will not trust the activity.
2200
+ * @param forwarder The forwarder's identifier or the forwarder's username.
2201
+ * @param recipients In this case, it must be `"followers"`.
2202
+ * @param options Options for forwarding the activity.
2203
+ * @since 1.0.0
2204
+ */
2205
+ forwardActivity(forwarder: {
2206
+ identifier: string;
2207
+ } | {
2208
+ username: string;
2209
+ } | {
2210
+ handle: string;
2211
+ }, recipients: "followers", options?: ForwardActivityOptions): Promise<void>;
2212
+ }
2213
+ /**
2214
+ * A result of parsing an URI.
2215
+ */
2216
+ type ParseUriResult =
2217
+ /**
2218
+ * The case of an actor URI.
2219
+ */
2220
+ {
2221
+ readonly type: "actor";
2222
+ readonly identifier: string;
2223
+ readonly handle: string;
2224
+ }
2225
+ /**
2226
+ * The case of an object URI.
2227
+ */ | {
2228
+ readonly type: "object";
2229
+ readonly class: ConstructorWithTypeId<Object$1>;
2230
+ readonly typeId: URL;
2231
+ readonly values: Record<string, string>;
2232
+ }
2233
+ /**
2234
+ * The case of an shared inbox URI.
2235
+ */ | {
2236
+ readonly type: "inbox";
2237
+ readonly identifier: undefined;
2238
+ readonly handle: undefined;
2239
+ }
2240
+ /**
2241
+ * The case of an personal inbox URI.
2242
+ */ | {
2243
+ readonly type: "inbox";
2244
+ readonly identifier: string;
2245
+ readonly handle: string;
2246
+ }
2247
+ /**
2248
+ * The case of an outbox collection URI.
2249
+ */ | {
2250
+ readonly type: "outbox";
2251
+ readonly identifier: string;
2252
+ readonly handle: string;
2253
+ }
2254
+ /**
2255
+ * The case of a following collection URI.
2256
+ */ | {
2257
+ readonly type: "following";
2258
+ readonly identifier: string;
2259
+ readonly handle: string;
2260
+ }
2261
+ /**
2262
+ * The case of a followers collection URI.
2263
+ */ | {
2264
+ readonly type: "followers";
2265
+ readonly identifier: string;
2266
+ readonly handle: string;
2267
+ }
2268
+ /**
2269
+ * The case of a liked collection URI.
2270
+ * @since 0.11.0
2271
+ */ | {
2272
+ readonly type: "liked";
2273
+ readonly identifier: string;
2274
+ readonly handle: string;
2275
+ }
2276
+ /**
2277
+ * The case of a featured collection URI.
2278
+ * @since 0.11.0
2279
+ */ | {
2280
+ readonly type: "featured";
2281
+ readonly identifier: string;
2282
+ readonly handle: string;
2283
+ }
2284
+ /**
2285
+ * The case of a featured tags collection URI.
2286
+ * @since 0.11.0
2287
+ */ | {
2288
+ readonly type: "featuredTags";
2289
+ readonly identifier: string;
2290
+ readonly handle: string;
2291
+ }
2292
+ /**
2293
+ * The case of a custom collection URI.
2294
+ * @since 1.8.0
2295
+ */ | {
2296
+ readonly type: "collection";
2297
+ readonly name: string | symbol;
2298
+ readonly class: ConstructorWithTypeId<Object$1>;
2299
+ readonly typeId: URL;
2300
+ readonly values: Record<string, string>;
2301
+ }
2302
+ /**
2303
+ * The case of a custom ordered collection URI.
2304
+ * @since 1.8.0
2305
+ */ | {
2306
+ readonly type: "orderedCollection";
2307
+ readonly name: string | symbol;
2308
+ readonly class: ConstructorWithTypeId<Object$1>;
2309
+ readonly typeId: URL;
2310
+ readonly values: Record<string, string>;
2311
+ };
2312
+ /**
2313
+ * Options for {@link Context.sendActivity} method.
2314
+ */
2315
+ interface SendActivityOptions {
2316
+ /**
2317
+ * Whether to prefer the shared inbox for the recipients.
2318
+ */
2319
+ preferSharedInbox?: boolean;
2320
+ /**
2321
+ * Whether to send the activity immediately, without enqueuing it.
2322
+ * If `true`, the activity will be sent immediately and the retrial
2323
+ * policy will not be applied.
2324
+ *
2325
+ * @since 0.3.0
2326
+ */
2327
+ immediate?: boolean;
2328
+ /**
2329
+ * Determines how activities are queued when sent to multiple recipients.
2330
+ *
2331
+ * - "auto" (default): Automatically chooses optimal strategy based on
2332
+ * recipient count.
2333
+ * - "skip": Always enqueues individual messages per recipient,
2334
+ * bypassing the fanout queue. Use when payload needs to vary per recipient.
2335
+ * - "force": Always uses fanout queue regardless of recipient count.
2336
+ * Useful for testing or special cases.
2337
+ *
2338
+ * This option is ignored when `immediate: true` is specified, as immediate
2339
+ * delivery bypasses all queuing mechanisms.
2340
+ *
2341
+ * @default `"auto"`
2342
+ * @since 1.5.0
2343
+ */
2344
+ fanout?: "auto" | "skip" | "force";
2345
+ /**
2346
+ * The base URIs to exclude from the recipients' inboxes. It is useful
2347
+ * for excluding the recipients having the same shared inbox with the sender.
2348
+ *
2349
+ * Note that the only `origin` parts of the `URL`s are compared.
2350
+ *
2351
+ * @since 0.9.0
2352
+ */
2353
+ excludeBaseUris?: URL[];
2354
+ }
2355
+ /**
2356
+ * Options for {@link Context.sendActivity} method when sending to a collection.
2357
+ * @since 1.5.0
2358
+ */
2359
+ interface SendActivityOptionsForCollection extends SendActivityOptions {
2360
+ /**
2361
+ * Whether to synchronize the collection using `Collection-Synchronization`
2362
+ * header ([FEP-8fcf]).
2363
+ *
2364
+ * [FEP-8fcf]: https://w3id.org/fep/8fcf
2365
+ */
2366
+ syncCollection?: boolean;
2367
+ }
2368
+ /**
2369
+ * Options for {@link InboxContext.forwardActivity} method.
2370
+ * @since 1.0.0
2371
+ */
2372
+ type ForwardActivityOptions = Omit<SendActivityOptions, "fanout"> & {
2373
+ /**
2374
+ * Whether to skip forwarding the activity if it is not signed, i.e., it has
2375
+ * neither Linked Data Signatures nor Object Integrity Proofs.
2376
+ *
2377
+ * If the activity is not signed, the recipient probably will not trust the
2378
+ * activity. Therefore, it is recommended to skip forwarding the activity
2379
+ * if it is not signed.
2380
+ */
2381
+ skipIfUnsigned: boolean;
2382
+ };
2383
+ /**
2384
+ * Options for {@link Context.routeActivity} method.
2385
+ * @since 1.3.0
2386
+ */
2387
+ interface RouteActivityOptions {
2388
+ /**
2389
+ * Whether to skip enqueuing the activity and invoke the listener immediately.
2390
+ * If no inbox queue is available, this option is ignored and the activity
2391
+ * will be always invoked immediately.
2392
+ * @default false
2393
+ */
2394
+ immediate?: boolean;
2395
+ /**
2396
+ * The document loader for loading remote JSON-LD documents.
2397
+ */
2398
+ documentLoader?: DocumentLoader;
2399
+ /**
2400
+ * The context loader for loading remote JSON-LD contexts.
2401
+ */
2402
+ contextLoader?: DocumentLoader;
2403
+ /**
2404
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
2405
+ * is used.
2406
+ */
2407
+ tracerProvider?: TracerProvider;
2408
+ }
2409
+ /**
2410
+ * Options for {@link Context.getSignedKey} method.
2411
+ * @since 1.5.0
2412
+ */
2413
+ interface GetSignedKeyOptions {
2414
+ /**
2415
+ * The document loader for loading remote JSON-LD documents.
2416
+ */
2417
+ documentLoader?: DocumentLoader;
2418
+ /**
2419
+ * The context loader for loading remote JSON-LD contexts.
2420
+ */
2421
+ contextLoader?: DocumentLoader;
2422
+ /**
2423
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
2424
+ * is used.
2425
+ */
2426
+ tracerProvider?: TracerProvider;
2427
+ }
2428
+ /**
2429
+ * A pair of a public key and a private key in various formats.
2430
+ * @since 0.10.0
2431
+ */
2432
+ interface ActorKeyPair extends CryptoKeyPair {
2433
+ /**
2434
+ * The URI of the public key, which is used for verifying HTTP Signatures.
2435
+ */
2436
+ keyId: URL;
2437
+ /**
2438
+ * A {@link CryptographicKey} instance of the public key.
2439
+ */
2440
+ cryptographicKey: CryptographicKey;
2441
+ /**
2442
+ * A {@link Multikey} instance of the public key.
2443
+ */
2444
+ multikey: Multikey;
2445
+ }
2446
+ //#endregion
2447
+ export { ActivityTransformer, ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CreateFederationOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetSignedKeyOptions, IdempotencyKeyCallback, IdempotencyStrategy, InProcessMessageQueue, InProcessMessageQueueOptions, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, Message, MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions, NodeInfoDispatcher, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxErrorHandler, PageItems, ParallelMessageQueue, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, Rfc6570Expression, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher, WebFingerLinksDispatcher, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, respondWithObject, respondWithObjectIfAcceptable };