@fedify/fedify 2.0.0-pr.433.1603 → 2.0.0-pr.434.1662

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