@fedify/fedify 2.3.16-dev.2841 → 2.3.16

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 (108) hide show
  1. package/dist/attachment-arrays-BlfpZlWF.mjs +16 -0
  2. package/dist/{builder-G4wSHQX-.mjs → builder-D4GE1Gmi.mjs} +3 -3
  3. package/dist/callback-kR_sx2zZ.d.mts +2661 -0
  4. package/dist/{client-BIBzqEIp.d.cts → client-9DPcy_Yx.d.ts} +16 -0
  5. package/dist/{client-jE7oGvRh.d.ts → client-B3ruDgWg.d.cts} +16 -0
  6. package/dist/{client-DpUNYKla.mjs → client-DFgYVbUA.mjs} +86 -11
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-CE_Tj_Oc.d.cts → context-CEE8vl-b.d.cts} +31 -14
  15. package/dist/{context-H_5tZXg-.d.ts → context-CTJwXHRu.d.ts} +31 -14
  16. package/dist/{deno-DmDVx5sE.mjs → deno-FtdqgHJA.mjs} +1 -1
  17. package/dist/{docloader-0fjyUmvI.mjs → docloader-B9iU4DP2.mjs} +2 -2
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/circuit-breaker.test.mjs +2 -2
  22. package/dist/federation/collection.test.mjs +1 -1
  23. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  24. package/dist/federation/delivery-attachments.test.mjs +288 -0
  25. package/dist/federation/handler.test.mjs +208 -16
  26. package/dist/federation/idempotency.test.mjs +2 -2
  27. package/dist/federation/inbox.test.mjs +2 -2
  28. package/dist/federation/metrics.test.mjs +1 -1
  29. package/dist/federation/middleware.test.mjs +1191 -16
  30. package/dist/federation/mod.cjs +1 -1
  31. package/dist/federation/mod.d.cts +2 -2
  32. package/dist/federation/mod.d.ts +2 -2
  33. package/dist/federation/mod.js +1 -1
  34. package/dist/federation/negotiation.test.mjs +1 -1
  35. package/dist/federation/retry.test.mjs +1 -1
  36. package/dist/federation/send.test.mjs +293 -3
  37. package/dist/federation/temporal.test.mjs +25 -1
  38. package/dist/federation/webfinger.test.mjs +1 -1
  39. package/dist/{http-CKX94hfh.cjs → http-2RyDQ0tE.cjs} +6 -4
  40. package/dist/{http-DmP0sr2l.d.ts → http-Bs5mXWlH.d.ts} +3 -3
  41. package/dist/{http-CZPYFK3b.d.cts → http-D8DgRhHU.d.cts} +3 -3
  42. package/dist/{http-DCK-QQfE.mjs → http-D8tiOrZf.mjs} +7 -5
  43. package/dist/{http-DwIMsxu9.js → http-mLeLYFj-.js} +6 -4
  44. package/dist/{inbox-Bx6PCMeE.mjs → inbox-Dy8awbi8.mjs} +2 -2
  45. package/dist/{key-SkLDUmPM.mjs → key-o1SmN5s0.mjs} +4 -3
  46. package/dist/{kv-cache-BaJOO6O3.mjs → kv-cache-BwUrzCVO.mjs} +1 -1
  47. package/dist/{kv-cache-BnZ4KLMY.cjs → kv-cache-CI6Z0WiS.cjs} +1 -1
  48. package/dist/{kv-cache-xIexNacM.js → kv-cache-Dsq8C8D8.js} +1 -1
  49. package/dist/{ld-DUG6cq9q.mjs → ld-DCKrqj9y.mjs} +155 -22
  50. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  51. package/dist/{metrics-D3OnAgfj.mjs → metrics-CaoYRhNH.mjs} +1 -1
  52. package/dist/{middleware-CUwjLKp3.mjs → middleware-4p3opEMT.mjs} +1 -1
  53. package/dist/{middleware-C9RexCTx.cjs → middleware-CP-8P7kk.cjs} +492 -117
  54. package/dist/{middleware-DU2jy5eY.js → middleware-Cce0nLDw.js} +491 -117
  55. package/dist/{middleware-zEy-wJYI.mjs → middleware-D31fNcY4.mjs} +399 -109
  56. package/dist/{mod-C_gFmeNq.d.cts → mod-BD0-_vya.d.ts} +31 -13
  57. package/dist/{mod-HQXFvOHs.d.ts → mod-BMX6nsHP.d.cts} +31 -13
  58. package/dist/{mod-CDFFESfL.d.ts → mod-BTvP5Hva.d.ts} +1 -1
  59. package/dist/{mod-DMjhnFbg.d.ts → mod-DgMTlwUO.d.ts} +3 -3
  60. package/dist/{mod-DDVkmZ_h.d.cts → mod-Q1Fo3FJk.d.cts} +3 -3
  61. package/dist/{mod-DDjtbkZO.d.cts → mod-n51LED4J.d.cts} +1 -1
  62. package/dist/mod.cjs +5 -5
  63. package/dist/mod.d.cts +8 -8
  64. package/dist/mod.d.ts +8 -8
  65. package/dist/mod.js +5 -5
  66. package/dist/nodeinfo/client.test.mjs +432 -4
  67. package/dist/nodeinfo/handler.test.mjs +1 -1
  68. package/dist/nodeinfo/mod.cjs +1 -1
  69. package/dist/nodeinfo/mod.d.cts +1 -1
  70. package/dist/nodeinfo/mod.d.ts +1 -1
  71. package/dist/nodeinfo/mod.js +1 -1
  72. package/dist/nodeinfo/types.test.mjs +1 -1
  73. package/dist/{outgoing-jsonld-D4iTv7uM.mjs → outgoing-jsonld-BZEAVK_Q.mjs} +38 -8
  74. package/dist/{owner-Baf_LRb2.mjs → owner-Bdj0nHhf.mjs} +2 -2
  75. package/dist/{proof-CNGy7TJL.js → proof-B9XJiyz-.js} +1030 -858
  76. package/dist/{proof-BdAFbOFg.cjs → proof-CmcP8yqP.cjs} +1243 -1059
  77. package/dist/{proof-LTsbjXnQ.mjs → proof-DrbjYma9.mjs} +41 -16
  78. package/dist/{send-DOf5y1nB.mjs → send-VD_WG3dN.mjs} +100 -22
  79. package/dist/sig/http.test.mjs +2 -2
  80. package/dist/sig/key-types.test.d.mts +218 -0
  81. package/dist/sig/key-types.test.mjs +8 -0
  82. package/dist/sig/key.test.mjs +2 -2
  83. package/dist/sig/ld.test.mjs +573 -8
  84. package/dist/sig/mod.cjs +2 -2
  85. package/dist/sig/mod.d.cts +3 -3
  86. package/dist/sig/mod.d.ts +3 -3
  87. package/dist/sig/mod.js +2 -2
  88. package/dist/sig/owner.test.mjs +1 -1
  89. package/dist/sig/proof.test.mjs +96 -4
  90. package/dist/{temporal-fl4sM1Gs.mjs → temporal-CMvoB-vD.mjs} +3 -5
  91. package/dist/testing/mod.d.mts +2 -2476
  92. package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
  93. package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
  94. package/dist/utils/docloader.test.mjs +2 -2
  95. package/dist/utils/kv-cache.test.mjs +1 -1
  96. package/dist/utils/mod.cjs +1 -1
  97. package/dist/utils/mod.d.cts +1 -1
  98. package/dist/utils/mod.d.ts +1 -1
  99. package/dist/utils/mod.js +1 -1
  100. package/package.json +7 -7
  101. /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
  102. /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-B1fLHmg2.mjs} +0 -0
  103. /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-BGHm_MsT.mjs} +0 -0
  104. /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
  105. /package/dist/{negotiation-DDstyBvc.mjs → negotiation-DC8nG6J_.mjs} +0 -0
  106. /package/dist/{public-audience-Dp4ZScSr.mjs → public-audience-rnYUGj8a.mjs} +0 -0
  107. /package/dist/{retry-CXg_MBI-.mjs → retry-C4G_vIgv.mjs} +0 -0
  108. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -0,0 +1,2661 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
3
+ import { Router } from "@fedify/uri-template";
4
+ import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
5
+ import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "@fedify/webfinger";
6
+ import { MeterProvider, TracerProvider } from "@opentelemetry/api";
7
+ import { AuthenticatedDocumentLoaderFactory, CryptoKeyLike, CryptoKeyPairLike, DocumentLoader, GetUserAgentOptions } from "@fedify/vocab-runtime";
8
+ import { MeterProvider as MeterProvider$1, MetricReader } from "@opentelemetry/sdk-metrics";
9
+
10
+ //#region src/sig/accept.d.ts
11
+ /**
12
+ * A single covered component identifier from an `Accept-Signature` inner list,
13
+ * as defined in [RFC 9421 §2.1](https://www.rfc-editor.org/rfc/rfc9421#section-2.1)
14
+ * and [§5.1](https://www.rfc-editor.org/rfc/rfc9421#section-5.1).
15
+ *
16
+ * RFC 9421 §5.1 requires that the list of component identifiers includes
17
+ * *all applicable component parameters*. Parameters such as `;sf`, `;bs`,
18
+ * `;req`, `;tr`, `;name`, and `;key` narrow the meaning of a component
19
+ * identifier and MUST be preserved exactly as received so that the signer
20
+ * can cover the same components the verifier requested.
21
+ *
22
+ * Examples:
23
+ * - `{ value: "@method", params: {} }`
24
+ * - `{ value: "content-type", params: { sf: true } }`
25
+ * - `{ value: "@query-param", params: { name: "foo" } }`
26
+ *
27
+ * @since 2.1.0
28
+ */
29
+ interface AcceptSignatureComponent {
30
+ /**
31
+ * The component identifier name (e.g., `"@method"`, `"content-digest"`,
32
+ * `"@query-param"`).
33
+ */
34
+ value: string;
35
+ /**
36
+ * Component parameters attached to this identifier (e.g., `{ sf: true }`,
37
+ * `{ name: "foo" }`). An empty object means no parameters were present.
38
+ * Parameters MUST NOT be dropped; doing so would cause the signer to cover
39
+ * a different component than the verifier requested.
40
+ */
41
+ params: Record<string, unknown>;
42
+ }
43
+ //#endregion
44
+ //#region src/sig/key.d.ts
45
+ /**
46
+ * Exports a key in JWK format.
47
+ * @param key The key to export. Either public or private key.
48
+ * @returns The exported key in JWK format. The key is suitable for
49
+ * serialization and storage.
50
+ * @throws {TypeError} If the key is invalid or unsupported.
51
+ */
52
+ declare function exportJwk(key: CryptoKeyLike): Promise<JsonWebKey>;
53
+ /**
54
+ * Detailed fetch failure information from {@link fetchKeyDetailed}.
55
+ * @since 2.1.0
56
+ */
57
+ type FetchKeyErrorResult = {
58
+ readonly status: number;
59
+ readonly response: Response;
60
+ } | {
61
+ readonly error: Error;
62
+ };
63
+ //#endregion
64
+ //#region src/sig/http.d.ts
65
+ /**
66
+ * The standard to use for signing and verifying HTTP signatures.
67
+ * @since 1.6.0
68
+ */
69
+ type HttpMessageSignaturesSpec =
70
+ /**
71
+ * The Signing HTTP Messages (draft-cavage-http-signatures-12) specification,
72
+ * which is widely adopted and used in the fediverse (as of May 2025).
73
+ */
74
+ "draft-cavage-http-signatures-12"
75
+ /**
76
+ * The HTTP Message Signatures (RFC 9421) specification, which is the
77
+ * finalized standard but not widely adopted yet (as of May 2025).
78
+ */
79
+ | "rfc9421";
80
+ /**
81
+ * Options for {@link signRequest}.
82
+ * @since 1.3.0
83
+ */
84
+ interface SignRequestOptions {
85
+ /**
86
+ * The HTTP message signatures specification to use for signing.
87
+ * @default `"draft-cavage-http-signatures-12"`
88
+ * @since 1.6.0
89
+ */
90
+ spec?: HttpMessageSignaturesSpec;
91
+ /**
92
+ * The current time. If not specified, the current time is used. This is
93
+ * useful for testing.
94
+ * @since 1.6.0
95
+ */
96
+ currentTime?: Temporal.Instant;
97
+ /**
98
+ * The request body as ArrayBuffer. If provided, avoids cloning the request body.
99
+ * @since 1.7.7
100
+ */
101
+ body?: ArrayBuffer | null;
102
+ /**
103
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
104
+ * is used.
105
+ */
106
+ tracerProvider?: TracerProvider;
107
+ /**
108
+ * Options specific to the RFC 9421 signing path. These options are
109
+ * ignored when `spec` is `"draft-cavage-http-signatures-12"`.
110
+ * @since 2.1.0
111
+ */
112
+ rfc9421?: Rfc9421SignRequestOptions;
113
+ }
114
+ /**
115
+ * Options for customizing the RFC 9421 signature label, covered components,
116
+ * and metadata parameters. These are typically derived from an
117
+ * `Accept-Signature` challenge.
118
+ * @since 2.1.0
119
+ */
120
+ interface Rfc9421SignRequestOptions {
121
+ /**
122
+ * The label for the signature in `Signature-Input` and `Signature` headers.
123
+ * @default `"sig1"`
124
+ */
125
+ label?: string;
126
+ /**
127
+ * The covered component identifiers. When omitted, the default set
128
+ * `["@method", "@target-uri", "@authority", "host", "date"]`
129
+ * (plus `"content-digest"` when a body is present) is used.
130
+ */
131
+ components?: AcceptSignatureComponent[];
132
+ /**
133
+ * A nonce value to include in the signature parameters.
134
+ */
135
+ nonce?: string;
136
+ /**
137
+ * A tag value to include in the signature parameters.
138
+ */
139
+ tag?: string;
140
+ /**
141
+ * If `true`, an expiration timestamp is generated and included in the
142
+ * signature parameters. The expiration time defaults to one hour after
143
+ * the signature creation time.
144
+ */
145
+ expires?: true;
146
+ }
147
+ /**
148
+ * Signs a request using the given private key.
149
+ * @param request The request to sign.
150
+ * @param privateKey The private key to use for signing.
151
+ * @param keyId The key ID to use for the signature. It will be used by the
152
+ * verifier.
153
+ * @returns The signed request.
154
+ * @throws {TypeError} If the private key is invalid or unsupported.
155
+ */
156
+ declare function signRequest(request: Request, privateKey: CryptoKeyLike, keyId: URL, options?: SignRequestOptions): Promise<Request>;
157
+ /**
158
+ * The reason why {@link verifyRequestDetailed} could not verify a request.
159
+ * @since 2.1.0
160
+ */
161
+ type VerifyRequestFailureReason = {
162
+ readonly type: "keyFetchError";
163
+ readonly keyId: URL;
164
+ readonly result: FetchKeyErrorResult;
165
+ } | {
166
+ readonly type: "invalidSignature";
167
+ readonly keyId?: URL;
168
+ } | {
169
+ readonly type: "noSignature";
170
+ };
171
+ /**
172
+ * A spec determiner for HTTP Message Signatures.
173
+ * It determines the spec to use for signing requests.
174
+ * It is used for double-knocking
175
+ * (see <https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions>).
176
+ * @since 1.6.0
177
+ */
178
+ interface HttpMessageSignaturesSpecDeterminer {
179
+ /**
180
+ * Determines the spec to use for signing requests.
181
+ * @param origin The origin of the URL to make the request to.
182
+ * @returns The spec to use for signing requests.
183
+ */
184
+ determineSpec(origin: string): HttpMessageSignaturesSpec | Promise<HttpMessageSignaturesSpec>;
185
+ /**
186
+ * Remembers the successfully used spec for the given origin.
187
+ * @param origin The origin of the URL that was requested.
188
+ * @param spec The spec to remember.
189
+ */
190
+ rememberSpec(origin: string, spec: HttpMessageSignaturesSpec): void | Promise<void>;
191
+ }
192
+ //#endregion
193
+ //#region src/nodeinfo/types.d.ts
194
+ /**
195
+ * The type of the result of parsing JSON.
196
+ */
197
+ type JsonValue = {
198
+ [key: string]: JsonValue | undefined;
199
+ } | JsonValue[] | string | number | boolean | null;
200
+ /**
201
+ * A NodeInfo object as defined in the NodeInfo 2.1 schema.
202
+ */
203
+ interface NodeInfo {
204
+ /**
205
+ * Metadata about server software in use.
206
+ */
207
+ readonly software: Software;
208
+ /**
209
+ * The protocols supported on this server. At least one protocol must be
210
+ * supported.
211
+ */
212
+ readonly protocols: readonly Protocol[];
213
+ /**
214
+ * The third party sites this server can connect to via their application API.
215
+ */
216
+ readonly services?: Services;
217
+ /**
218
+ * Whether this server allows open self-registration. Defaults to `false`.
219
+ */
220
+ readonly openRegistrations?: boolean;
221
+ /**
222
+ * Usage statistics for this server.
223
+ */
224
+ readonly usage: Usage;
225
+ /**
226
+ * Free form key value pairs for software specific values.
227
+ * Clients should not rely on any specific key present.
228
+ */
229
+ readonly metadata?: Readonly<Record<string, JsonValue>>;
230
+ }
231
+ /**
232
+ * Metadata about server software in use.
233
+ */
234
+ interface Software {
235
+ /**
236
+ * The canonical name of this server software. This must comply with
237
+ * pattern `/^[a-z0-9-]+$/`.
238
+ */
239
+ readonly name: string;
240
+ /**
241
+ * The version of this server software.
242
+ */
243
+ readonly version: string;
244
+ /**
245
+ * The URL of the source code repository of this server software.
246
+ */
247
+ readonly repository?: URL;
248
+ /**
249
+ * The URL of the homepage of this server software.
250
+ */
251
+ readonly homepage?: URL;
252
+ }
253
+ /**
254
+ * The protocols supported on this server.
255
+ */
256
+ type Protocol = "activitypub" | "buddycloud" | "dfrn" | "diaspora" | "libertree" | "ostatus" | "pumpio" | "tent" | "xmpp" | "zot";
257
+ /**
258
+ * The third party sites this server can connect to via their application API.
259
+ */
260
+ interface Services {
261
+ /**
262
+ * The third party sites this server can retrieve messages from for combined
263
+ * display with regular traffic.
264
+ */
265
+ readonly inbound?: readonly InboundService[];
266
+ /**
267
+ * The third party sites this server can publish messages to on the behalf
268
+ * of a user.
269
+ */
270
+ readonly outbound?: readonly OutboundService[];
271
+ }
272
+ /**
273
+ * The third party sites this server can retrieve messages from for combined
274
+ * display with regular traffic.
275
+ */
276
+ type InboundService = "atom1.0" | "gnusocial" | "imap" | "pnut" | "pop3" | "pumpio" | "rss2.0" | "twitter";
277
+ /**
278
+ * The third party sites this server can publish messages to on the behalf
279
+ * of a user.
280
+ */
281
+ type OutboundService = "atom1.0" | "blogger" | "buddycloud" | "diaspora" | "dreamwidth" | "drupal" | "facebook" | "friendica" | "gnusocial" | "google" | "insanejournal" | "libertree" | "linkedin" | "livejournal" | "mediagoblin" | "myspace" | "pinterest" | "pnut" | "posterous" | "pumpio" | "redmatrix" | "rss2.0" | "smtp" | "tent" | "tumblr" | "twitter" | "wordpress" | "xmpp";
282
+ /**
283
+ * Usage statistics for this server.
284
+ */
285
+ interface Usage {
286
+ /**
287
+ * Statistics about the users of this server.
288
+ */
289
+ readonly users: {
290
+ /**
291
+ * The total amount of on this server registered users. This number
292
+ * has to be an integer greater than or equal to zero.
293
+ */
294
+ readonly total?: number;
295
+ /**
296
+ * The amount of users that signed in at least once in the last 180 days.
297
+ * This number has to be an integer greater than or equal to zero.
298
+ */
299
+ readonly activeHalfyear?: number;
300
+ /**
301
+ * The amount of users that signed in at least once in the last 30 days.
302
+ * This number has to be an integer greater than or equal to zero.
303
+ */
304
+ readonly activeMonth?: number;
305
+ };
306
+ /**
307
+ * The amount of posts that were made by users that are registered on this
308
+ * server. This number has to be an integer greater than or equal to zero.
309
+ */
310
+ readonly localPosts: number;
311
+ /**
312
+ * The amount of comments that were made by users that are registered on this
313
+ * server. This number has to be an integer greater than or equal to zero.
314
+ */
315
+ readonly localComments: number;
316
+ }
317
+ //#endregion
318
+ //#region src/federation/collection.d.ts
319
+ /**
320
+ * A page of items.
321
+ */
322
+ interface PageItems<TItem> {
323
+ readonly prevCursor?: string | null;
324
+ readonly nextCursor?: string | null;
325
+ readonly items: readonly TItem[];
326
+ }
327
+ //#endregion
328
+ //#region src/nodeinfo/client.d.ts
329
+ /**
330
+ * Options for {@link getNodeInfo} function.
331
+ * @since 1.2.0
332
+ */
333
+ interface GetNodeInfoOptions {
334
+ /**
335
+ * Whether to directly fetch the NodeInfo document from the given URL.
336
+ * Otherwise, the NodeInfo document will be fetched from the `.well-known`
337
+ * location of the given URL.
338
+ *
339
+ * Turned off by default.
340
+ */
341
+ direct?: boolean;
342
+ /**
343
+ * How strictly to parse the NodeInfo document.
344
+ *
345
+ * - `"strict"`: Parse the NodeInfo document strictly. If the document is
346
+ * invalid, `undefined` is returned. This is the default.
347
+ * - `"best-effort"`: Try to parse the NodeInfo document even if it is
348
+ * invalid.
349
+ * - `"none"`: Do not parse the NodeInfo document. The function will return
350
+ * the raw JSON value.
351
+ */
352
+ parse?: "strict" | "best-effort" | "none";
353
+ /**
354
+ * The options for making `User-Agent` header.
355
+ * If a string is given, it is used as the `User-Agent` header value.
356
+ * If an object is given, it is passed to {@link getUserAgent} to generate
357
+ * the `User-Agent` header value.
358
+ * @since 1.3.0
359
+ */
360
+ userAgent?: GetUserAgentOptions | string;
361
+ /**
362
+ * The timeout in milliseconds for the entire NodeInfo lookup, including
363
+ * discovery, redirects, and reading the document. Defaults to 10 seconds.
364
+ * Set to `null` to disable the timeout. A timeout returns `undefined`.
365
+ * Fractional values are rounded up.
366
+ * @throws {RangeError} If the value is not a positive finite number or is
367
+ * greater than 2,147,483,647.
368
+ * @since 2.0.36
369
+ */
370
+ timeout?: number | null;
371
+ /**
372
+ * A signal to cancel the entire NodeInfo lookup. Cancellation returns
373
+ * `undefined`, including when the timeout is disabled.
374
+ * @since 2.0.36
375
+ */
376
+ signal?: AbortSignal;
377
+ }
378
+ //#endregion
379
+ //#region src/sig/owner.d.ts
380
+ /**
381
+ * Options for {@link getKeyOwner}.
382
+ * @since 0.8.0
383
+ */
384
+ interface GetKeyOwnerOptions {
385
+ /**
386
+ * The document loader to use for fetching the key and its owner.
387
+ */
388
+ documentLoader?: DocumentLoader;
389
+ /**
390
+ * The context loader to use for JSON-LD context retrieval.
391
+ */
392
+ contextLoader?: DocumentLoader;
393
+ /**
394
+ * The OpenTelemetry tracer provider to use for tracing. If omitted,
395
+ * the global tracer provider is used.
396
+ * @since 1.3.0
397
+ */
398
+ tracerProvider?: TracerProvider;
399
+ }
400
+ //#endregion
401
+ //#region src/federation/queue.d.ts
402
+ interface SenderKeyJwkPair {
403
+ readonly keyId: string;
404
+ readonly privateKey: JsonWebKey;
405
+ }
406
+ /**
407
+ * A message that represents a task to be processed by the background worker.
408
+ * The concrete type of the message depends on the `type` property.
409
+ *
410
+ * Please do not depend on the concrete types of the messages, as they may
411
+ * change in the future. You should treat the `Message` type as an opaque
412
+ * type.
413
+ * @since 1.6.0
414
+ */
415
+ type Message = FanoutMessage | OutboxMessage | InboxMessage;
416
+ interface FanoutMessage {
417
+ readonly type: "fanout";
418
+ readonly id: ReturnType<typeof crypto.randomUUID>;
419
+ readonly baseUrl: string;
420
+ readonly keys: readonly SenderKeyJwkPair[];
421
+ readonly inboxes: Readonly<Record<string, {
422
+ readonly actorIds: readonly string[];
423
+ readonly sharedInbox: boolean;
424
+ }>>;
425
+ readonly activity: unknown;
426
+ readonly activityId?: string;
427
+ readonly activityType: string;
428
+ readonly collectionSync?: string;
429
+ readonly orderingKey?: string;
430
+ /**
431
+ * Whether to apply outgoing JSON-LD wire-format normalization to queued
432
+ * activities that already carry Object Integrity Proofs.
433
+ *
434
+ * `true` is used for proofs Fedify created before fanout, or when callers
435
+ * explicitly request normalization for locally pre-signed activities.
436
+ * `false`/`undefined` preserves existing proofs as-is.
437
+ */
438
+ readonly normalizeExistingProofs?: boolean;
439
+ readonly traceContext: Readonly<Record<string, string>>;
440
+ }
441
+ interface OutboxMessage {
442
+ readonly type: "outbox";
443
+ readonly id: ReturnType<typeof crypto.randomUUID>;
444
+ readonly baseUrl: string;
445
+ readonly keys: readonly SenderKeyJwkPair[];
446
+ readonly activity: unknown;
447
+ readonly activityId?: string;
448
+ readonly activityType: string;
449
+ readonly inbox: string;
450
+ readonly sharedInbox: boolean;
451
+ readonly actorIds?: readonly string[];
452
+ readonly started: string;
453
+ readonly attempt: number;
454
+ readonly headers: Readonly<Record<string, string>>;
455
+ readonly orderingKey?: string;
456
+ /**
457
+ * Whether this message is currently held by the outbound circuit breaker.
458
+ * @internal
459
+ */
460
+ readonly circuitHeld?: true;
461
+ /**
462
+ * When Fedify first held this message because the remote host circuit was
463
+ * open.
464
+ * @internal
465
+ */
466
+ readonly circuitHeldSince?: string;
467
+ readonly traceContext: Readonly<Record<string, string>>;
468
+ }
469
+ interface InboxMessage {
470
+ readonly type: "inbox";
471
+ readonly id: ReturnType<typeof crypto.randomUUID>;
472
+ readonly baseUrl: string;
473
+ readonly activity: unknown;
474
+ /**
475
+ * The normalized JSON-LD representation of a signed inbox activity that
476
+ * Fedify already compacted successfully while accepting the request. Queue
477
+ * workers can reuse this producer-side parse cache under stricter loader or
478
+ * network constraints without changing the raw payload preserved for
479
+ * forwarding.
480
+ *
481
+ * This may exist even when {@link ldSignatureVerified} is `false`, because
482
+ * fallback-authenticated traffic and already-queued backlog items can still
483
+ * depend on the cached normalized form to avoid re-fetching remote custom
484
+ * contexts during worker processing.
485
+ *
486
+ * This is optional for backward compatibility with messages that were
487
+ * queued by older Fedify versions or that were already in a queue before
488
+ * upgrading.
489
+ *
490
+ * Fedify keeps this on the queued message itself instead of an external
491
+ * sidecar because generic queue backends do not provide reliable lifecycle
492
+ * guarantees for auxiliary storage across retries and redeliveries.
493
+ *
494
+ * @internal
495
+ */
496
+ readonly normalizedActivity?: unknown;
497
+ /**
498
+ * Whether the producer actually verified the Linked Data Signature before
499
+ * queueing this message. This lets workers distinguish verified LDS replay
500
+ * from other authenticated inbox traffic that merely happened to include a
501
+ * signature block. This provenance marker is separate from the optional
502
+ * normalizedActivity parse cache.
503
+ *
504
+ * `undefined` preserves backward compatibility with older queued messages
505
+ * that predate this marker.
506
+ *
507
+ * @internal
508
+ */
509
+ readonly ldSignatureVerified?: boolean;
510
+ readonly started: string;
511
+ readonly attempt: number;
512
+ readonly identifier: string | null;
513
+ readonly traceContext: Readonly<Record<string, string>>;
514
+ }
515
+ //#endregion
516
+ //#region src/federation/send.d.ts
517
+ /**
518
+ * A key pair for an actor who sends an activity.
519
+ *
520
+ * The private key type is parameterized so that Fedify can accept keys from
521
+ * `node:crypto` at its input boundaries while `SenderKeyPair` still exposes the
522
+ * ambient `CryptoKey` type by default.
523
+ * @template TKey The type of the private key.
524
+ * @since 0.10.0
525
+ */
526
+ interface SenderKeyPair<TKey extends CryptoKeyLike = CryptoKey> {
527
+ /**
528
+ * The actor's private key to sign the request.
529
+ */
530
+ readonly privateKey: TKey;
531
+ /**
532
+ * The public key ID that corresponds to the private key.
533
+ */
534
+ readonly keyId: URL;
535
+ }
536
+ /**
537
+ * An error that is thrown when an activity fails to send to a remote inbox.
538
+ * It contains structured information about the failure, including the HTTP
539
+ * status code, the inbox URL, and the response body.
540
+ * @since 2.0.0
541
+ */
542
+ declare class SendActivityError extends Error {
543
+ /**
544
+ * The inbox URL that the activity was being sent to.
545
+ */
546
+ readonly inbox: URL;
547
+ /**
548
+ * The HTTP status code returned by the inbox.
549
+ */
550
+ readonly statusCode: number;
551
+ /**
552
+ * The response body from the inbox, if any. Note that this may be
553
+ * truncated to a maximum of 1 KiB to prevent excessive memory consumption
554
+ * when remote servers return large error pages (e.g., Cloudflare error pages).
555
+ * If truncated, the string will end with `"… (truncated)"`.
556
+ */
557
+ readonly responseBody: string;
558
+ /**
559
+ * The response headers from the inbox.
560
+ * @since 2.3.0
561
+ */
562
+ readonly responseHeaders: Headers;
563
+ /**
564
+ * Creates a new {@link SendActivityError}.
565
+ * @param inbox The inbox URL.
566
+ * @param statusCode The HTTP status code.
567
+ * @param message The error message.
568
+ * @param responseBody The response body.
569
+ * @param responseHeaders The response headers.
570
+ */
571
+ constructor(inbox: URL, statusCode: number, message: string, responseBody: string, responseHeaders?: HeadersInit);
572
+ }
573
+ //#endregion
574
+ //#region src/federation/federation.d.ts
575
+ /**
576
+ * Options for {@link Federation.startQueue} method.
577
+ * @since 1.0.0
578
+ */
579
+ interface FederationStartQueueOptions {
580
+ /**
581
+ * The signal to abort the task queue.
582
+ */
583
+ signal?: AbortSignal;
584
+ /**
585
+ * Starts the task worker only for the specified queue. If unspecified,
586
+ * which is the default, the task worker starts for all three queues:
587
+ * inbox, outbox, and fanout.
588
+ * @since 1.3.0
589
+ */
590
+ queue?: "inbox" | "outbox" | "fanout";
591
+ }
592
+ /**
593
+ * A common interface between {@link Federation} and {@link FederationBuilder}.
594
+ * @template TContextData The context data to pass to the {@link Context}.
595
+ * @since 1.6.0
596
+ */
597
+ interface Federatable<TContextData> {
598
+ /**
599
+ * Registers a NodeInfo dispatcher.
600
+ * @param path The URI path pattern for the NodeInfo dispatcher. The syntax
601
+ * is based on URI Template
602
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
603
+ * must have no variables.
604
+ * @param dispatcher A NodeInfo dispatcher callback to register.
605
+ * @throws {RouterError} Thrown if the path pattern is invalid.
606
+ */
607
+ setNodeInfoDispatcher(path: string, dispatcher: NodeInfoDispatcher<TContextData>): void;
608
+ /**
609
+ * Registers a links dispatcher to WebFinger
610
+ * @param dispatcher A links dispatcher callback to register.
611
+ */
612
+ setWebFingerLinksDispatcher(dispatcher: WebFingerLinksDispatcher<TContextData>): void;
613
+ /**
614
+ * Registers an actor dispatcher.
615
+ *
616
+ * @example
617
+ * ``` typescript
618
+ * federation.setActorDispatcher(
619
+ * "/users/{identifier}",
620
+ * async (ctx, identifier) => {
621
+ * return new Person({
622
+ * id: ctx.getActorUri(identifier),
623
+ * // ...
624
+ * });
625
+ * }
626
+ * );
627
+ * ```
628
+ *
629
+ * @param path The URI path pattern for the actor dispatcher. The syntax is
630
+ * based on URI Template
631
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
632
+ * must have one variable: `{identifier}`.
633
+ * @param dispatcher An actor dispatcher callback to register. It may return
634
+ * an actor, a `Tombstone`, or `null` if the actor is not
635
+ * found.
636
+ * @returns An object with methods to set other actor dispatcher callbacks.
637
+ * @throws {RouterError} Thrown if the path pattern is invalid.
638
+ */
639
+ setActorDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: ActorDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
640
+ /**
641
+ * Registers an object dispatcher.
642
+ *
643
+ * @template TContextData The context data to pass to the {@link Context}.
644
+ * @template TObject The type of object to dispatch.
645
+ * @template TParam The parameter names of the requested URL.
646
+ * @param cls The Activity Vocabulary class of the object to dispatch.
647
+ * @param path The URI path pattern for the object dispatcher. The syntax is
648
+ * based on URI Template
649
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
650
+ * must have one or more variables.
651
+ * @param dispatcher An object dispatcher callback to register.
652
+ */
653
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
654
+ /**
655
+ * Registers an object dispatcher.
656
+ *
657
+ * @template TContextData The context data to pass to the {@link Context}.
658
+ * @template TObject The type of object to dispatch.
659
+ * @template TParam The parameter names of the requested URL.
660
+ * @param cls The Activity Vocabulary class of the object to dispatch.
661
+ * @param path The URI path pattern for the object dispatcher. The syntax is
662
+ * based on URI Template
663
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
664
+ * must have one or more variables.
665
+ * @param dispatcher An object dispatcher callback to register.
666
+ */
667
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
668
+ /**
669
+ * Registers an object dispatcher.
670
+ *
671
+ * @template TContextData The context data to pass to the {@link Context}.
672
+ * @template TObject The type of object to dispatch.
673
+ * @template TParam The parameter names of the requested URL.
674
+ * @param cls The Activity Vocabulary class of the object to dispatch.
675
+ * @param path The URI path pattern for the object dispatcher. The syntax is
676
+ * based on URI Template
677
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
678
+ * must have one or more variables.
679
+ * @param dispatcher An object dispatcher callback to register.
680
+ */
681
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
682
+ /**
683
+ * Registers an object dispatcher.
684
+ *
685
+ * @template TContextData The context data to pass to the {@link Context}.
686
+ * @template TObject The type of object to dispatch.
687
+ * @template TParam The parameter names of the requested URL.
688
+ * @param cls The Activity Vocabulary class of the object to dispatch.
689
+ * @param path The URI path pattern for the object dispatcher. The syntax is
690
+ * based on URI Template
691
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
692
+ * must have one or more variables.
693
+ * @param dispatcher An object dispatcher callback to register.
694
+ */
695
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
696
+ /**
697
+ * Registers an object dispatcher.
698
+ *
699
+ * @template TContextData The context data to pass to the {@link Context}.
700
+ * @template TObject The type of object to dispatch.
701
+ * @template TParam The parameter names of the requested URL.
702
+ * @param cls The Activity Vocabulary class of the object to dispatch.
703
+ * @param path The URI path pattern for the object dispatcher. The syntax is
704
+ * based on URI Template
705
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
706
+ * must have one or more variables.
707
+ * @param dispatcher An object dispatcher callback to register.
708
+ */
709
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
710
+ /**
711
+ * Registers an object dispatcher.
712
+ *
713
+ * @template TContextData The context data to pass to the {@link Context}.
714
+ * @template TObject The type of object to dispatch.
715
+ * @template TParam The parameter names of the requested URL.
716
+ * @param cls The Activity Vocabulary class of the object to dispatch.
717
+ * @param path The URI path pattern for the object dispatcher. The syntax is
718
+ * based on URI Template
719
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
720
+ * must have one or more variables.
721
+ * @param dispatcher An object dispatcher callback to register.
722
+ */
723
+ setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
724
+ /**
725
+ * Registers an inbox dispatcher.
726
+ *
727
+ * @param path The URI path pattern for the inbox dispatcher. The syntax is
728
+ * based on URI Template
729
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
730
+ * must have one variable: `{identifier}`, and must match
731
+ * the inbox listener path.
732
+ * @param dispatcher An inbox dispatcher callback to register.
733
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
734
+ */
735
+ setInboxDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
736
+ /**
737
+ * Registers an outbox dispatcher.
738
+ *
739
+ * @example
740
+ * ``` typescript
741
+ * federation.setOutboxDispatcher(
742
+ * "/users/{identifier}/outbox",
743
+ * async (ctx, identifier, options) => {
744
+ * let items: Activity[];
745
+ * let nextCursor: string;
746
+ * // ...
747
+ * return { items, nextCursor };
748
+ * }
749
+ * );
750
+ * ```
751
+ *
752
+ * @param path The URI path pattern for the outbox dispatcher. The syntax is
753
+ * based on URI Template
754
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
755
+ * must have one variable: `{identifier}`.
756
+ * @param dispatcher An outbox dispatcher callback to register.
757
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
758
+ */
759
+ setOutboxDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
760
+ /**
761
+ * Assigns the URL path for the outbox and starts setting outbox listeners.
762
+ *
763
+ * @example
764
+ * ``` typescript
765
+ * federation
766
+ * .setOutboxListeners("/users/{identifier}/outbox")
767
+ * .on(Activity, async (ctx, activity) => {
768
+ * await ctx.sendActivity({ identifier: ctx.identifier }, "followers", activity);
769
+ * })
770
+ * .authorize(async (ctx, identifier) => {
771
+ * return ctx.request.headers.get("authorization") === `Bearer ${identifier}`;
772
+ * });
773
+ * ```
774
+ *
775
+ * @param outboxPath The URI path pattern for the outbox. The syntax is based
776
+ * on URI Template
777
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The
778
+ * path must have one variable: `{identifier}`. If an
779
+ * outbox dispatcher is configured, this path must match
780
+ * the outbox dispatcher path.
781
+ * @returns An object to register outbox listeners.
782
+ * @throws {RouterError} Thrown if the path pattern is invalid.
783
+ * @since 2.2.0
784
+ */
785
+ setOutboxListeners(outboxPath: `${string}${Rfc6570Expression<"identifier">}${string}`): OutboxListenerSetters<TContextData>;
786
+ /**
787
+ * Registers a following collection dispatcher.
788
+ * @param path The URI path pattern for the following collection. The syntax
789
+ * is based on URI Template
790
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
791
+ * must have one variable: `{identifier}`.
792
+ * @param dispatcher A following collection callback to register.
793
+ * @returns An object with methods to set other following collection
794
+ * callbacks.
795
+ * @throws {RouterError} Thrown if the path pattern is invalid.
796
+ */
797
+ setFollowingDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: CollectionDispatcher<Actor | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
798
+ /**
799
+ * Registers a followers collection dispatcher.
800
+ * @param path The URI path pattern for the followers collection. The syntax
801
+ * is based on URI Template
802
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
803
+ * must have one variable: `{identifier}`.
804
+ * @param dispatcher A followers collection callback to register.
805
+ * @returns An object with methods to set other followers collection
806
+ * callbacks.
807
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
808
+ */
809
+ setFollowersDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: CollectionDispatcher<Recipient, Context<TContextData>, TContextData, URL>): CollectionCallbackSetters<Context<TContextData>, TContextData, URL>;
810
+ /**
811
+ * Registers a liked collection dispatcher.
812
+ * @param path The URI path pattern for the liked collection. The syntax
813
+ * is based on URI Template
814
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
815
+ * must have one variable: `{identifier}`.
816
+ * @param dispatcher A liked collection callback to register.
817
+ * @returns An object with methods to set other liked collection
818
+ * callbacks.
819
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
820
+ */
821
+ setLikedDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: CollectionDispatcher<Object$1 | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
822
+ /**
823
+ * Registers a featured collection dispatcher.
824
+ * @param path The URI path pattern for the featured collection. The syntax
825
+ * is based on URI Template
826
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
827
+ * must have one variable: `{identifier}`.
828
+ * @param dispatcher A featured collection callback to register.
829
+ * @returns An object with methods to set other featured collection
830
+ * callbacks.
831
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
832
+ */
833
+ setFeaturedDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: CollectionDispatcher<Object$1, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
834
+ /**
835
+ * Registers a featured tags collection dispatcher.
836
+ * @param path The URI path pattern for the featured tags collection.
837
+ * The syntax is based on URI Template
838
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
839
+ * must have one variable: `{identifier}`.
840
+ * @param dispatcher A featured tags collection callback to register.
841
+ * @returns An object with methods to set other featured tags collection
842
+ * callbacks.
843
+ * @throws {@link RouterError} Thrown if the path pattern is invalid.
844
+ */
845
+ setFeaturedTagsDispatcher(path: `${string}${Rfc6570Expression<"identifier">}${string}`, dispatcher: CollectionDispatcher<Hashtag, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
846
+ /**
847
+ * Assigns the URL path for the inbox and starts setting inbox listeners.
848
+ *
849
+ * @example
850
+ * ``` typescript
851
+ * federation
852
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
853
+ * .on(Follow, async (ctx, follow) => {
854
+ * const from = await follow.getActor(ctx);
855
+ * if (!isActor(from)) return;
856
+ * // ...
857
+ * })
858
+ * .on(Undo, async (ctx, undo) => {
859
+ * // ...
860
+ * });
861
+ * ```
862
+ *
863
+ * @param inboxPath The URI path pattern for the inbox. The syntax is based
864
+ * on URI Template
865
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
866
+ * The path must have one variable: `{identifier}`, and must
867
+ * match the inbox dispatcher path.
868
+ * @param sharedInboxPath An optional URI path pattern for the shared inbox.
869
+ * The syntax is based on URI Template
870
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
871
+ * The path must have no variables.
872
+ * @returns An object to register inbox listeners.
873
+ * @throws {RouterError} Thrown if the path pattern is invalid.
874
+ */
875
+ setInboxListeners(inboxPath: `${string}${Rfc6570Expression<"identifier">}${string}`, sharedInboxPath?: string): InboxListenerSetters<TContextData>;
876
+ /**
877
+ * Registers a collection of objects dispatcher.
878
+ *
879
+ * @template TContextData The context data to pass to the {@link Context}.
880
+ * @template TObject The type of objects to dispatch.
881
+ * @template TParam The parameter names of the requested URL.
882
+ * @param name A unique name for the collection dispatcher.
883
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
884
+ * @param path The URI path pattern for the collection dispatcher.
885
+ * The syntax is based on URI Template
886
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
887
+ * The path must have one or more variables.
888
+ * @param dispatcher A collection dispatcher callback to register.
889
+ */
890
+ setCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
891
+ /**
892
+ * Registers a collection of objects dispatcher.
893
+ *
894
+ * @template TContextData The context data to pass to the {@link Context}.
895
+ * @template TObject The type of objects to dispatch.
896
+ * @template TParam The parameter names of the requested URL.
897
+ * @param name A unique name for the collection dispatcher.
898
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
899
+ * @param path The URI path pattern for the collection dispatcher.
900
+ * The syntax is based on URI Template
901
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
902
+ * The path must have one or more variables.
903
+ * @param dispatcher A collection dispatcher callback to register.
904
+ */
905
+ setCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
906
+ /**
907
+ * Registers a collection of objects dispatcher.
908
+ *
909
+ * @template TContextData The context data to pass to the {@link Context}.
910
+ * @template TObject The type of objects to dispatch.
911
+ * @template TParam The parameter names of the requested URL.
912
+ * @param name A unique name for the collection dispatcher.
913
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
914
+ * @param path The URI path pattern for the collection dispatcher.
915
+ * The syntax is based on URI Template
916
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
917
+ * The path must have one or more variables.
918
+ * @param dispatcher A collection dispatcher callback to register.
919
+ */
920
+ setCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
921
+ /**
922
+ * Registers an ordered collection of objects dispatcher.
923
+ *
924
+ * @template TContextData The context data to pass to the {@link Context}.
925
+ * @template TObject The type of objects to dispatch.
926
+ * @template TParam The parameter names of the requested URL.
927
+ * @param name A unique name for the collection dispatcher.
928
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
929
+ * @param path The URI path pattern for the collection dispatcher.
930
+ * The syntax is based on URI Template
931
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
932
+ * The path must have one or more variables.
933
+ * @param dispatcher A collection dispatcher callback to register.
934
+ */
935
+ setOrderedCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
936
+ /**
937
+ * Registers an ordered collection of objects dispatcher.
938
+ *
939
+ * @template TContextData The context data to pass to the {@link Context}.
940
+ * @template TObject The type of objects to dispatch.
941
+ * @template TParam The parameter names of the requested URL.
942
+ * @param name A unique name for the collection dispatcher.
943
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
944
+ * @param path The URI path pattern for the collection dispatcher.
945
+ * The syntax is based on URI Template
946
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
947
+ * The path must have one or more variables.
948
+ * @param dispatcher A collection dispatcher callback to register.
949
+ */
950
+ setOrderedCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
951
+ /**
952
+ * Registers an ordered collection of objects dispatcher.
953
+ *
954
+ * @template TContextData The context data to pass to the {@link Context}.
955
+ * @template TObject The type of objects to dispatch.
956
+ * @template TParam The parameter names of the requested URL.
957
+ * @param name A unique name for the collection dispatcher.
958
+ * @param itemType The Activity Vocabulary class of the object to dispatch.
959
+ * @param path The URI path pattern for the collection dispatcher.
960
+ * The syntax is based on URI Template
961
+ * ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
962
+ * The path must have one or more variables.
963
+ * @param dispatcher A collection dispatcher callback to register.
964
+ */
965
+ setOrderedCollectionDispatcher<TObject extends Object$1, TParam extends string>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: `${string}${Rfc6570Expression<TParam>}${string}`, dispatcher: CustomCollectionDispatcher<TObject, TParam, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParam, RequestContext<TContextData>, TContextData>;
966
+ /**
967
+ * Registers a handler for permanent delivery failures.
968
+ *
969
+ * This handler is called when an inbox returns an HTTP status code
970
+ * that indicates permanent failure (`410 Gone`, `404 Not Found`, etc.),
971
+ * allowing the application to clean up followers that are no longer
972
+ * reachable.
973
+ *
974
+ * Unlike `onOutboxError`, which is called for every delivery failure
975
+ * (including retries), this handler is called only once for permanent
976
+ * failures, after which delivery is not retried.
977
+ *
978
+ * @param handler A callback to handle permanent failures.
979
+ * @since 2.0.0
980
+ */
981
+ setOutboxPermanentFailureHandler(handler: OutboxPermanentFailureHandler<TContextData>): void;
982
+ }
983
+ /**
984
+ * An object that registers federation-related business logic and dispatches
985
+ * requests to the appropriate handlers.
986
+ *
987
+ * It also provides a middleware interface for handling requests before your
988
+ * web framework's router; see {@link Federation.fetch}.
989
+ * @template TContextData The context data to pass to the {@link Context}.
990
+ * @since 0.13.0
991
+ */
992
+ interface Federation<TContextData> extends Federatable<TContextData> {
993
+ /**
994
+ * Manually start the task queue.
995
+ *
996
+ * This method is useful when you set the `manuallyStartQueue` option to
997
+ * `true` in the {@link createFederation} function.
998
+ * @param contextData The context data to pass to the context.
999
+ * @param options Additional options for starting the queue.
1000
+ */
1001
+ startQueue(contextData: TContextData, options?: FederationStartQueueOptions): Promise<void>;
1002
+ /**
1003
+ * Processes a queued message task. This method handles different types of
1004
+ * tasks such as fanout, outbox, and inbox messages.
1005
+ *
1006
+ * Note that you usually do not need to call this method directly unless you
1007
+ * are deploying your federated application on a platform that does not
1008
+ * support long-running processing, such as Cloudflare Workers.
1009
+ * @param contextData The context data to pass to the context.
1010
+ * @param message The message that represents the task to be processed.
1011
+ * @returns A promise that resolves when the message has been processed.
1012
+ * @since 1.6.0
1013
+ */
1014
+ processQueuedTask(contextData: TContextData, message: Message): Promise<void>;
1015
+ /**
1016
+ * Create a new context.
1017
+ * @param baseUrl The base URL of the server. The `pathname` remains root,
1018
+ * and the `search` and `hash` are stripped.
1019
+ * @param contextData The context data to pass to the context.
1020
+ * @returns The new context.
1021
+ */
1022
+ createContext(baseUrl: URL, contextData: TContextData): Context<TContextData>;
1023
+ /**
1024
+ * Create a new context for a request.
1025
+ * @param request The request object.
1026
+ * @param contextData The context data to pass to the context.
1027
+ * @returns The new request context.
1028
+ */
1029
+ createContext(request: Request, contextData: TContextData): RequestContext<TContextData>;
1030
+ /**
1031
+ * Handles a request related to federation. If a request is not related to
1032
+ * federation, the `onNotFound` or `onNotAcceptable` callback is called.
1033
+ *
1034
+ * Usually, this method is called from a server's request handler or
1035
+ * a web framework's middleware.
1036
+ *
1037
+ * @param request The request object.
1038
+ * @param parameters The parameters for handling the request.
1039
+ * @returns The response to the request.
1040
+ */
1041
+ fetch(request: Request, options: FederationFetchOptions<TContextData>): Promise<Response>;
1042
+ }
1043
+ /**
1044
+ * Additional settings for the actor dispatcher.
1045
+ *
1046
+ * ``` typescript
1047
+ * const federation = createFederation<void>({ ... });
1048
+ * federation
1049
+ * .setActorDispatcher("/users/{identifier}", async (ctx, identifier) => {
1050
+ * // ...
1051
+ * })
1052
+ * .setKeyPairsDispatcher(async (ctxData, identifier) => {
1053
+ * // ...
1054
+ * });
1055
+ * ```
1056
+ */
1057
+ interface ActorCallbackSetters<TContextData> {
1058
+ /**
1059
+ * Sets the key pairs dispatcher for actors.
1060
+ * @param dispatcher A callback that returns the key pairs for an actor.
1061
+ * @returns The setters object so that settings can be chained.
1062
+ * @since 0.10.0
1063
+ */
1064
+ setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData, CryptoKeyPairLike>): ActorCallbackSetters<TContextData>;
1065
+ /**
1066
+ * Sets the callback function that maps a WebFinger username to
1067
+ * the corresponding actor's identifier. If it's omitted, the identifier
1068
+ * is assumed to be the same as the WebFinger username, which makes your
1069
+ * actors have the immutable handles. If you want to let your actors change
1070
+ * their fediverse handles, you should set this dispatcher.
1071
+ * @param mapper A callback that maps a WebFinger username to
1072
+ * the corresponding actor's identifier.
1073
+ * @returns The setters object so that settings can be chained.
1074
+ * @since 0.15.0
1075
+ */
1076
+ mapHandle(mapper: ActorHandleMapper<TContextData>): ActorCallbackSetters<TContextData>;
1077
+ /**
1078
+ * Sets the callback function that maps a WebFinger query to the corresponding
1079
+ * actor's identifier or username. If it's omitted, the WebFinger handler
1080
+ * only supports the actor URIs and `acct:` URIs. If you want to support
1081
+ * other queries, you should set this dispatcher.
1082
+ * @param mapper A callback that maps a WebFinger query to the corresponding
1083
+ * actor's identifier or username.
1084
+ * @returns The setters object so that settings can be chained.
1085
+ * @since 1.4.0
1086
+ */
1087
+ mapAlias(mapper: ActorAliasMapper<TContextData>): ActorCallbackSetters<TContextData>;
1088
+ /**
1089
+ * Maps a fixed path to a sentinel identifier. It is useful for exposing
1090
+ * a single, instance-level actor at a fixed path, such as `/actor` for
1091
+ * a relay or `/bot` for a bot.
1092
+ * @param path The fixed path to map to the identifier.
1093
+ * @param identifier The sentinel identifier to map the path to.
1094
+ * @returns The setters object so that settings can be chained.
1095
+ * @throws {RouterError} If the provided path or identifier is invalid or fails
1096
+ * runtime validation.
1097
+ * @since 2.3.0
1098
+ */
1099
+ mapActorAlias(path: `/${string}`, identifier: string): ActorCallbackSetters<TContextData>;
1100
+ /**
1101
+ * Specifies the conditions under which requests are authorized.
1102
+ * @param predicate A callback that returns whether a request is authorized.
1103
+ * @returns The setters object so that settings can be chained.
1104
+ * @since 0.7.0
1105
+ */
1106
+ authorize(predicate: AuthorizePredicate<TContextData>): ActorCallbackSetters<TContextData>;
1107
+ }
1108
+ /**
1109
+ * Additional settings for an object dispatcher.
1110
+ */
1111
+ interface ObjectCallbackSetters<TContextData, TObject extends Object$1, TParam extends string> {
1112
+ /**
1113
+ * Specifies the conditions under which requests are authorized.
1114
+ * @param predicate A callback that returns whether a request is authorized.
1115
+ * @returns The setters object so that settings can be chained.
1116
+ * @since 0.7.0
1117
+ */
1118
+ authorize(predicate: ObjectAuthorizePredicate<TContextData, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
1119
+ }
1120
+ /**
1121
+ * Additional settings for a collection dispatcher.
1122
+ *
1123
+ * @template TContext The type of the context. {@link Context} or
1124
+ * {@link RequestContext}.
1125
+ * @template TContextData The context data to pass to the {@link Context}.
1126
+ * @template TFilter The type of filter for the collection.
1127
+ */
1128
+ interface CollectionCallbackSetters<TContext extends Context<TContextData>, TContextData, TFilter> {
1129
+ /**
1130
+ * Sets the counter for the collection.
1131
+ * @param counter A callback that returns the number of items in the collection.
1132
+ * @returns The setters object so that settings can be chained.
1133
+ */
1134
+ setCounter(counter: CollectionCounter<TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1135
+ /**
1136
+ * Sets the first cursor for the collection.
1137
+ * @param cursor The cursor for the first item in the collection.
1138
+ * @returns The setters object so that settings can be chained.
1139
+ */
1140
+ setFirstCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1141
+ /**
1142
+ * Sets the last cursor for the collection.
1143
+ * @param cursor The cursor for the last item in the collection.
1144
+ * @returns The setters object so that settings can be chained.
1145
+ */
1146
+ setLastCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1147
+ /**
1148
+ * Specifies the conditions under which requests are authorized.
1149
+ * @param predicate A callback that returns whether a request is authorized.
1150
+ * @returns The setters object so that settings can be chained.
1151
+ * @since 0.7.0
1152
+ */
1153
+ authorize(predicate: AuthorizePredicate<TContextData>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
1154
+ }
1155
+ /**
1156
+ * The strategy for handling activity idempotency in inbox processing.
1157
+ *
1158
+ * - `"global"`: Activities are deduplicated globally across all inboxes and
1159
+ * origins. The same activity ID will be processed only once, regardless
1160
+ * of which inbox receives it or which server sent it.
1161
+ *
1162
+ * - `"per-origin"`: Activities are deduplicated per receiving server's origin.
1163
+ * The same activity ID will be processed only once on each receiving server,
1164
+ * but can be processed separately on different receiving servers. This had
1165
+ * been the default behavior in Fedify 1.x versions.
1166
+ *
1167
+ * - `"per-inbox"`: Activities are deduplicated per inbox. The same activity
1168
+ * ID can be processed once per inbox, allowing the same activity to be
1169
+ * delivered to multiple inboxes independently. This follows standard
1170
+ * ActivityPub behavior and is the default strategy since Fedify 2.0.0.
1171
+ *
1172
+ * @since 1.9.0
1173
+ */
1174
+ type IdempotencyStrategy = "global" | "per-origin" | "per-inbox";
1175
+ /**
1176
+ * A callback to generate a custom idempotency key for an activity.
1177
+ * Returns the cache key to use, or null to skip idempotency checking.
1178
+ * @template TContextData The context data to pass to the {@link InboxContext}.
1179
+ * @param ctx The inbox context.
1180
+ * @param activity The activity being processed.
1181
+ * @returns The idempotency key to use for caching, or null to skip caching.
1182
+ * @since 1.9.0
1183
+ */
1184
+ type IdempotencyKeyCallback<TContextData> = (ctx: InboxContext<TContextData>, activity: Activity) => string | null | Promise<string | null>;
1185
+ /**
1186
+ * Registry for outbox listeners for different activity types.
1187
+ * @since 2.2.0
1188
+ */
1189
+ interface OutboxListenerSetters<TContextData> {
1190
+ /**
1191
+ * Registers a listener for a specific incoming activity type.
1192
+ *
1193
+ * @param type A subclass of {@link Activity} to listen to.
1194
+ * @param listener A callback to handle an incoming activity.
1195
+ * @returns The setters object so that settings can be chained.
1196
+ * @since 2.2.0
1197
+ */
1198
+ on<TActivity extends Activity>(type: new (...args: any[]) => TActivity, listener: OutboxListener<TContextData, TActivity>): OutboxListenerSetters<TContextData>;
1199
+ /**
1200
+ * Registers an error handler for outbox listeners. Any exceptions thrown
1201
+ * from the listeners are caught and passed to this handler.
1202
+ *
1203
+ * @param handler A callback to handle an error.
1204
+ * @returns The setters object so that settings can be chained.
1205
+ * @since 2.2.0
1206
+ */
1207
+ onError(handler: OutboxListenerErrorHandler<TContextData>): OutboxListenerSetters<TContextData>;
1208
+ /**
1209
+ * Registers a callback to authorize POST requests to the outbox.
1210
+ *
1211
+ * @param predicate A callback to authorize the request.
1212
+ * @returns The setters object so that settings can be chained.
1213
+ * @since 2.2.0
1214
+ */
1215
+ authorize(predicate: AuthorizePredicate<TContextData>): OutboxListenerSetters<TContextData>;
1216
+ }
1217
+ /**
1218
+ * Registry for inbox listeners for different activity types.
1219
+ */
1220
+ interface InboxListenerSetters<TContextData> {
1221
+ /**
1222
+ * Registers a listener for a specific incoming activity type.
1223
+ *
1224
+ * @param type A subclass of {@link Activity} to listen to.
1225
+ * @param listener A callback to handle an incoming activity.
1226
+ * @returns The setters object so that settings can be chained.
1227
+ */
1228
+ on<TActivity extends Activity>(type: new (...args: any[]) => TActivity, listener: InboxListener<TContextData, TActivity>): InboxListenerSetters<TContextData>;
1229
+ /**
1230
+ * Registers an error handler for inbox listeners. Any exceptions thrown
1231
+ * from the listeners are caught and passed to this handler.
1232
+ *
1233
+ * @param handler A callback to handle an error.
1234
+ * @returns The setters object so that settings can be chained.
1235
+ */
1236
+ onError(handler: InboxErrorHandler<TContextData>): InboxListenerSetters<TContextData>;
1237
+ /**
1238
+ * Registers a callback for incoming activities whose HTTP signatures could
1239
+ * not be verified.
1240
+ *
1241
+ * The regular inbox listeners registered through {@link on} continue to
1242
+ * receive only verified activities. This hook is an opt-in escape hatch for
1243
+ * applications that need to inspect unverified deliveries and optionally
1244
+ * override the default `401 Unauthorized` response.
1245
+ *
1246
+ * @example
1247
+ * ``` typescript
1248
+ * federation
1249
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
1250
+ * .onUnverifiedActivity((ctx, activity, reason) => {
1251
+ * if (
1252
+ * reason.type === "keyFetchError" &&
1253
+ * "status" in reason.result &&
1254
+ * reason.result.status === 410
1255
+ * ) {
1256
+ * return new Response(null, { status: 202 });
1257
+ * }
1258
+ * });
1259
+ * ```
1260
+ *
1261
+ * @param handler A callback to handle an unverified activity.
1262
+ * @returns The setters object so that settings can be chained.
1263
+ * @since 2.1.0
1264
+ */
1265
+ onUnverifiedActivity(handler: UnverifiedActivityHandler<TContextData>): InboxListenerSetters<TContextData>;
1266
+ /**
1267
+ * Configures a callback to dispatch the key pair for the authenticated
1268
+ * document loader of the {@link Context} passed to the shared inbox listener.
1269
+ *
1270
+ * @param dispatcher A callback to dispatch the key pair for the authenticated
1271
+ * document loader.
1272
+ * @returns The setters object so that settings can be chained.
1273
+ * @since 0.11.0
1274
+ */
1275
+ setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData, CryptoKeyLike>): InboxListenerSetters<TContextData>;
1276
+ /**
1277
+ * Configures the strategy for handling activity idempotency in inbox processing.
1278
+ *
1279
+ * @example
1280
+ * Use per-inbox strategy (standard ActivityPub behavior):
1281
+ * ```
1282
+ * federation
1283
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
1284
+ * .withIdempotency("per-inbox");
1285
+ * ```
1286
+ *
1287
+ * Use custom strategy:
1288
+ * ```
1289
+ * federation
1290
+ * .setInboxListeners("/users/{identifier}/inbox", "/inbox")
1291
+ * .withIdempotency((ctx, activity) => {
1292
+ * // Return null to skip idempotency
1293
+ * return `${ctx.origin}:${activity.id?.href}:${ctx.recipient}`;
1294
+ * });
1295
+ * ```
1296
+ *
1297
+ * @param strategy The idempotency strategy to use. Can be:
1298
+ * - `"global"`: Activities are deduplicated across all inboxes and origins
1299
+ * - `"per-origin"`: Activities are deduplicated per inbox origin
1300
+ * - `"per-inbox"`: Activities are deduplicated per inbox
1301
+ * - A custom callback function that returns the cache key to use
1302
+ * @returns The setters object so that settings can be chained.
1303
+ * @since 1.9.0
1304
+ */
1305
+ withIdempotency(strategy: IdempotencyStrategy | IdempotencyKeyCallback<TContextData>): InboxListenerSetters<TContextData>;
1306
+ }
1307
+ /**
1308
+ * Parameters of {@link Federation.fetch} method.
1309
+ *
1310
+ * @template TContextData The context data to pass to the {@link Context}.
1311
+ * @since 0.6.0
1312
+ */
1313
+ interface FederationFetchOptions<TContextData> {
1314
+ /**
1315
+ * The context data to pass to the {@link Context}.
1316
+ */
1317
+ contextData: TContextData;
1318
+ /**
1319
+ * A callback to handle a request when the route is not found.
1320
+ * If not provided, a 404 response is returned.
1321
+ * @param request The request object.
1322
+ * @returns The response to the request.
1323
+ */
1324
+ onNotFound?: (request: Request) => Response | Promise<Response>;
1325
+ /**
1326
+ * A callback to handle a request when the request's `Accept` header is not
1327
+ * acceptable. If not provided, a 406 response is returned.
1328
+ * @param request The request object.
1329
+ * @returns The response to the request.
1330
+ */
1331
+ onNotAcceptable?: (request: Request) => Response | Promise<Response>;
1332
+ /**
1333
+ * A callback to handle a request when the request is unauthorized.
1334
+ * If not provided, a 401 response is returned.
1335
+ * @param request The request object.
1336
+ * @returns The response to the request.
1337
+ * @since 0.7.0
1338
+ */
1339
+ onUnauthorized?: (request: Request) => Response | Promise<Response>;
1340
+ }
1341
+ /**
1342
+ * Additional settings for a custom collection dispatcher.
1343
+ *
1344
+ * @template TParam The type of the parameters in the URL path.
1345
+ * @template TContext The type of the context. {@link Context} or
1346
+ * {@link RequestContext}.
1347
+ * @template TContextData The context data to pass to the {@link Context}.
1348
+ * @template TFilter The type of filter for the collection.
1349
+ */
1350
+ interface CustomCollectionCallbackSetters<TParam extends string, TContext extends Context<TContextData>, TContextData> {
1351
+ /**
1352
+ * Sets the counter for the custom collection.
1353
+ * @param counter A callback that returns the number of items in the custom collection.
1354
+ * @returns The setters object so that settings can be chained.
1355
+ */
1356
+ setCounter(counter: CustomCollectionCounter<TParam, TContextData>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1357
+ /**
1358
+ * Sets the first cursor for the custom collection.
1359
+ * @param cursor The cursor for the first item in the custom collection.
1360
+ * @returns The setters object so that settings can be chained.
1361
+ */
1362
+ setFirstCursor(cursor: CustomCollectionCursor<TParam, TContext, TContextData>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1363
+ /**
1364
+ * Sets the last cursor for the custom collection.
1365
+ * @param cursor The cursor for the last item in the custom collection.
1366
+ * @returns The setters object so that settings can be chained.
1367
+ */
1368
+ setLastCursor(cursor: CustomCollectionCursor<TParam, TContext, TContextData>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1369
+ /**
1370
+ * Specifies the conditions under which requests are authorized.
1371
+ * @param predicate A callback that returns whether a request is authorized.
1372
+ * @returns The setters object so that settings can be chained.
1373
+ * @since 0.7.0
1374
+ */
1375
+ authorize(predicate: ObjectAuthorizePredicate<TContextData, string>): CustomCollectionCallbackSetters<TParam, TContext, TContextData>;
1376
+ }
1377
+ /**
1378
+ * Represents an object with a type ID, which is either a constructor or an
1379
+ * instance of the object.
1380
+ *
1381
+ * @template TObject The type of the object.
1382
+ */
1383
+ type ConstructorWithTypeId<TObject extends Object$1> = (new (...args: any[]) => TObject) & {
1384
+ typeId: URL;
1385
+ };
1386
+ /**
1387
+ * Defines a union of all valid RFC 6570 URI Template expressions for a given
1388
+ * parameter name.
1389
+ *
1390
+ * RFC 6570 specifies a syntax for URI templates, allowing for variable
1391
+ * expansion. This type captures all Level 1-4 operator expressions for a
1392
+ * single, named variable.
1393
+ *
1394
+ * The supported expression types are:
1395
+ * - `{Param}`: Simple string expansion
1396
+ * - `+{Param}`: Reserved string expansion
1397
+ * - `#{Param}`: Fragment expansion
1398
+ * - `{.Param}`: Label expansion with a dot-prefix
1399
+ * - `{/Param}`: Path segment expansion
1400
+ * - `{;Param}`: Path-style parameter expansion
1401
+ * - `{?Param}`: Query component expansion
1402
+ * - `{&Param}`: Query continuation expansion
1403
+ *
1404
+ * @template Param The name of the parameter to be used in the expressions.
1405
+ * @example
1406
+ * ```ts
1407
+ * type UserIdExpression = Rfc6570Expression<"userId">;
1408
+ *
1409
+ * // The variable `userPath` can be assigned any of the valid expressions.
1410
+ * const userPath: UserIdExpression = "{/userId}";
1411
+ * ```
1412
+ * @see {@link https://tools.ietf.org/html/rfc6570} for the full specification.
1413
+ */
1414
+ type Rfc6570Expression<Param extends string> = `{${Param}}` | `{+${Param}}` | `{#${Param}}` | `{.${Param}}` | `{/${Param}}` | `{;${Param}}` | `{?${Param}}` | `{&${Param}}`;
1415
+ //#endregion
1416
+ //#region src/federation/context.d.ts
1417
+ /**
1418
+ * A context.
1419
+ */
1420
+ interface Context<TContextData> {
1421
+ /**
1422
+ * The origin of the federated server, including the scheme (`http://` or
1423
+ * `https://`) and the host (e.g., `example.com:8080`).
1424
+ * @since 0.12.0
1425
+ */
1426
+ readonly origin: string;
1427
+ /**
1428
+ * The canonical origin of the federated server, including the scheme
1429
+ * (`http://` or `https://`) and the host (e.g., `example.com:8080`).
1430
+ *
1431
+ * When the associated {@link Federation} object does not have any explicit
1432
+ * canonical origin, it is the same as the {@link Context.origin}.
1433
+ * @since 1.5.0
1434
+ */
1435
+ readonly canonicalOrigin: string;
1436
+ /**
1437
+ * The host of the federated server, including the hostname
1438
+ * (e.g., `example.com`) and the port following a colon (e.g., `:8080`)
1439
+ * if it is not the default port for the scheme.
1440
+ * @since 0.12.0
1441
+ */
1442
+ readonly host: string;
1443
+ /**
1444
+ * The hostname of the federated server (e.g., `example.com`). This is
1445
+ * the same as the host without the port.
1446
+ * @since 0.12.0
1447
+ */
1448
+ readonly hostname: string;
1449
+ /**
1450
+ * The user-defined data associated with the context.
1451
+ */
1452
+ readonly data: TContextData;
1453
+ /**
1454
+ * The OpenTelemetry tracer provider.
1455
+ * @since 1.3.0
1456
+ */
1457
+ readonly tracerProvider: TracerProvider;
1458
+ /**
1459
+ * The OpenTelemetry meter provider.
1460
+ * @since 2.3.0
1461
+ */
1462
+ readonly meterProvider?: MeterProvider;
1463
+ /**
1464
+ * The document loader for loading remote JSON-LD documents.
1465
+ */
1466
+ readonly documentLoader: DocumentLoader;
1467
+ /**
1468
+ * The context loader for loading remote JSON-LD contexts.
1469
+ */
1470
+ readonly contextLoader: DocumentLoader;
1471
+ /**
1472
+ * The federation object that this context belongs to.
1473
+ * @since 1.6.0
1474
+ */
1475
+ readonly federation: Federation<TContextData>;
1476
+ /**
1477
+ * Creates a new context with the same properties as this one,
1478
+ * but with the given data.
1479
+ * @param data The new data to associate with the context.
1480
+ * @returns A new context with the same properties as this one,
1481
+ * but with the given data.
1482
+ * @since 1.6.0
1483
+ */
1484
+ clone(data: TContextData): Context<TContextData>;
1485
+ /**
1486
+ * Builds the URI of the NodeInfo document.
1487
+ * @returns The NodeInfo URI.
1488
+ * @throws {RouterError} If no NodeInfo dispatcher is available.
1489
+ * @since 0.2.0
1490
+ */
1491
+ getNodeInfoUri(): URL;
1492
+ /**
1493
+ * Builds the URI of an actor with the given identifier.
1494
+ * @param identifier The actor's identifier.
1495
+ * @returns The actor's URI.
1496
+ * @throws {RouterError} If no actor dispatcher is available.
1497
+ */
1498
+ getActorUri(identifier: string): URL;
1499
+ /**
1500
+ * Builds the URI of an object with the given class and values.
1501
+ * @param cls The class of the object.
1502
+ * @param values The values to pass to the object dispatcher.
1503
+ * @returns The object's URI.
1504
+ * @throws {RouterError} If no object dispatcher is available for the class.
1505
+ * @throws {TypeError} If values are invalid.
1506
+ * @since 0.7.0
1507
+ */
1508
+ getObjectUri<TObject extends Object$1>(cls: ConstructorWithTypeId<TObject>, values: Record<string, string>): URL;
1509
+ /**
1510
+ * Builds the URI of an actor's outbox with the given identifier.
1511
+ * @param identifier The actor's identifier.
1512
+ * @returns The actor's outbox URI.
1513
+ * @throws {RouterError} If no outbox dispatcher is available.
1514
+ */
1515
+ getOutboxUri(identifier: string): URL;
1516
+ /**
1517
+ * Builds the URI of the shared inbox.
1518
+ * @returns The shared inbox URI.
1519
+ * @throws {RouterError} If no inbox listener is available.
1520
+ */
1521
+ getInboxUri(): URL;
1522
+ /**
1523
+ * Builds the URI of an actor's inbox with the given identifier.
1524
+ * @param identifier The actor's identifier.
1525
+ * @returns The actor's inbox URI.
1526
+ * @throws {RouterError} If no inbox listener is available.
1527
+ */
1528
+ getInboxUri(identifier: string): URL;
1529
+ /**
1530
+ * Builds the URI of an actor's following collection with the given
1531
+ * identifier.
1532
+ * @param identifier The actor's identifier.
1533
+ * @returns The actor's following collection URI.
1534
+ * @throws {RouterError} If no following collection is available.
1535
+ */
1536
+ getFollowingUri(identifier: string): URL;
1537
+ /**
1538
+ * Builds the URI of an actor's followers collection with the given
1539
+ * identifier.
1540
+ * @param identifier The actor's identifier.
1541
+ * @returns The actor's followers collection URI.
1542
+ * @throws {RouterError} If no followers collection is available.
1543
+ */
1544
+ getFollowersUri(identifier: string): URL;
1545
+ /**
1546
+ * Builds the URI of an actor's liked collection with the given identifier.
1547
+ * @param identifier The actor's identifier.
1548
+ * @returns The actor's liked collection URI.
1549
+ * @throws {RouterError} If no liked collection is available.
1550
+ * @since 0.11.0
1551
+ */
1552
+ getLikedUri(identifier: string): URL;
1553
+ /**
1554
+ * Builds the URI of an actor's featured collection with the given identifier.
1555
+ * @param identifier The actor's identifier.
1556
+ * @returns The actor's featured collection URI.
1557
+ * @throws {RouterError} If no featured collection is available.
1558
+ * @since 0.11.0
1559
+ */
1560
+ getFeaturedUri(identifier: string): URL;
1561
+ /**
1562
+ * Builds the URI of an actor's featured tags collection with the given
1563
+ * identifier.
1564
+ * @param identifier The actor's identifier.
1565
+ * @returns The actor's featured tags collection URI.
1566
+ * @throws {RouterError} If no featured tags collection is available.
1567
+ * @since 0.11.0
1568
+ */
1569
+ getFeaturedTagsUri(identifier: string): URL;
1570
+ /**
1571
+ * Determines the type of the URI and extracts the associated data.
1572
+ * @param uri The URI to parse.
1573
+ * @returns The result of parsing the URI. If `null` is given or
1574
+ * the URI is not recognized, `null` is returned.
1575
+ * @since 0.9.0
1576
+ */
1577
+ parseUri(uri: URL | null): ParseUriResult | null;
1578
+ /**
1579
+ * Gets the key pairs for an actor.
1580
+ * @param identifier The actor's identifier.
1581
+ * @returns An async iterable of the actor's key pairs. It can be empty.
1582
+ * @since 0.10.0
1583
+ */
1584
+ getActorKeyPairs(identifier: string): Promise<ActorKeyPair[]>;
1585
+ /**
1586
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
1587
+ * Note that an authenticated document loader intentionally does not cache
1588
+ * the fetched documents.
1589
+ * @param identity The identity to get the document loader for.
1590
+ * The actor's identifier or username.
1591
+ * @returns The authenticated document loader.
1592
+ * @throws {Error} If the identity is not valid.
1593
+ * @throws {TypeError} If the key is invalid or unsupported.
1594
+ * @since 0.4.0
1595
+ */
1596
+ getDocumentLoader(identity: {
1597
+ identifier: string;
1598
+ } | {
1599
+ username: string;
1600
+ }): Promise<DocumentLoader>;
1601
+ /**
1602
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
1603
+ * Note that an authenticated document loader intentionally does not cache
1604
+ * the fetched documents.
1605
+ * @param identity The identity to get the document loader for.
1606
+ * The actor's key pair.
1607
+ * @returns The authenticated document loader.
1608
+ * @throws {TypeError} If the key is invalid or unsupported.
1609
+ * @since 0.4.0
1610
+ */
1611
+ getDocumentLoader(identity: {
1612
+ keyId: URL;
1613
+ privateKey: CryptoKeyLike;
1614
+ }): DocumentLoader;
1615
+ /**
1616
+ * Looks up an ActivityStreams object by its URI (including `acct:` URIs)
1617
+ * or a fediverse handle (e.g., `@user@server` or `user@server`).
1618
+ *
1619
+ * @example
1620
+ * ``` typescript
1621
+ * // Look up an actor by its fediverse handle:
1622
+ * await ctx.lookupObject("@hongminhee@fosstodon.org");
1623
+ * // returning a `Person` object.
1624
+ *
1625
+ * // A fediverse handle can omit the leading '@':
1626
+ * await ctx.lookupObject("hongminhee@fosstodon.org");
1627
+ * // returning a `Person` object.
1628
+ *
1629
+ * // A `acct:` URI can be used as well:
1630
+ * await ctx.lookupObject("acct:hongminhee@fosstodon.org");
1631
+ * // returning a `Person` object.
1632
+ *
1633
+ * // Look up an object by its URI:
1634
+ * await ctx.lookupObject("https://todon.eu/@hongminhee/112060633798771581");
1635
+ * // returning a `Note` object.
1636
+ *
1637
+ * // It can be a `URL` object as well:
1638
+ * await ctx.lookupObject(
1639
+ * new URL("https://todon.eu/@hongminhee/112060633798771581")
1640
+ * );
1641
+ * // returning a `Note` object.
1642
+ * ```
1643
+ *
1644
+ * It's almost the same as the {@link lookupObject} function, but it uses
1645
+ * the context's document loader and context loader by default.
1646
+ *
1647
+ * @param identifier The URI or fediverse handle to look up.
1648
+ * @param options Lookup options.
1649
+ * @returns The object, or `null` if not found.
1650
+ * @since 0.15.0
1651
+ */
1652
+ lookupObject(identifier: string | URL, options?: LookupObjectOptions): Promise<Object$1 | null>;
1653
+ /**
1654
+ * Traverses a collection, yielding each item in the collection.
1655
+ * If the collection is paginated, it will fetch the next page
1656
+ * automatically.
1657
+ *
1658
+ * @example
1659
+ * ``` typescript
1660
+ * const collection = await ctx.lookupObject(collectionUrl);
1661
+ * if (collection instanceof Collection) {
1662
+ * for await (const item of ctx.traverseCollection(collection)) {
1663
+ * console.log(item.id?.href);
1664
+ * }
1665
+ * }
1666
+ * ```
1667
+ *
1668
+ * It's almost the same as the {@link traverseCollection} function, but it
1669
+ * uses the context's document loader and context loader by default.
1670
+ * @param collection The collection to traverse.
1671
+ * @param options Options for traversing the collection.
1672
+ * @returns An async iterable of each item in the collection.
1673
+ * @since 1.1.0
1674
+ */
1675
+ traverseCollection(collection: Collection, options?: TraverseCollectionOptions): AsyncIterable<Object$1 | Link>;
1676
+ /**
1677
+ * Fetches the NodeInfo document from the given URL.
1678
+ * @param url The base URL of the server. If `options.direct` is turned off
1679
+ * (default), the NodeInfo document will be fetched from
1680
+ * the `.well-known` location of this URL (hence the only origin
1681
+ * of the URL is used). If `options.direct` is turned on,
1682
+ * the NodeInfo document will be fetched from the given URL.
1683
+ * @param options Options for fetching the NodeInfo document.
1684
+ * @returns The NodeInfo document if it could be fetched successfully.
1685
+ * Otherwise, `undefined` is returned.
1686
+ * @since 1.4.0
1687
+ */
1688
+ lookupNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
1689
+ parse?: "strict" | "best-effort";
1690
+ }): Promise<NodeInfo | undefined>;
1691
+ /**
1692
+ * Fetches the NodeInfo document from the given URL.
1693
+ * @param url The base URL of the server. If `options.direct` is turned off
1694
+ * (default), the NodeInfo document will be fetched from
1695
+ * the `.well-known` location of this URL (hence the only origin
1696
+ * of the URL is used). If `options.direct` is turned on,
1697
+ * the NodeInfo document will be fetched from the given URL.
1698
+ * @param options Options for fetching the NodeInfo document.
1699
+ * @returns The NodeInfo document if it could be fetched successfully.
1700
+ * Otherwise, `undefined` is returned.
1701
+ * @since 1.4.0
1702
+ */
1703
+ lookupNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
1704
+ parse: "none";
1705
+ }): Promise<JsonValue | undefined>;
1706
+ /**
1707
+ * Looks up a WebFinger resource.
1708
+ *
1709
+ * It's almost the same as the {@link lookupWebFinger} function, but it uses
1710
+ * the context's configuration by default.
1711
+ *
1712
+ * @param resource The resource URL to look up.
1713
+ * @param options Extra options for looking up the resource.
1714
+ * @returns The resource descriptor, or `null` if not found.
1715
+ * @since 1.6.0
1716
+ */
1717
+ lookupWebFinger(resource: URL | string, options?: LookupWebFingerOptions): Promise<ResourceDescriptor | null>;
1718
+ /**
1719
+ * Sends an activity to recipients' inboxes.
1720
+ * @param sender The sender's identifier or the sender's username or
1721
+ * the sender's key pair(s).
1722
+ * @param recipients The recipients of the activity.
1723
+ * @param activity The activity to send.
1724
+ * @param options Options for sending the activity.
1725
+ */
1726
+ sendActivity(sender: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
1727
+ identifier: string;
1728
+ } | {
1729
+ username: string;
1730
+ }, recipients: Recipient | Recipient[], activity: Activity, options?: SendActivityOptions): Promise<void>;
1731
+ /**
1732
+ * Sends an activity to the inboxes of the sender's followers.
1733
+ * @param sender The sender's identifier or the sender's username.
1734
+ * @param recipients In this case, it must be `"followers"`.
1735
+ * @param activity The activity to send.
1736
+ * @param options Options for sending the activity.
1737
+ * @throws {Error} If no followers collection is registered.
1738
+ * @since 0.14.0
1739
+ */
1740
+ sendActivity(sender: {
1741
+ identifier: string;
1742
+ } | {
1743
+ username: string;
1744
+ }, recipients: "followers", activity: Activity, options?: SendActivityOptionsForCollection): Promise<void>;
1745
+ /**
1746
+ * Manually routes an activity to the appropriate inbox listener.
1747
+ *
1748
+ * It is useful for routing an activity that is not received from the network,
1749
+ * or for routing an activity that is enclosed in another activity.
1750
+ *
1751
+ * Note that the activity will be verified if it has Object Integrity Proofs
1752
+ * or is equivalent to the actual remote object. If the activity is not
1753
+ * verified, it will be rejected.
1754
+ * @param recipient The recipient of the activity. If it is `null`,
1755
+ * the activity will be routed to the shared inbox.
1756
+ * Otherwise, the activity will be routed to the personal
1757
+ * inbox of the recipient with the given identifier.
1758
+ * @param activity The activity to route. It must have a proof or
1759
+ * a dereferenceable `id` to verify the activity.
1760
+ * @param options Options for routing the activity.
1761
+ * @returns `true` if the activity is successfully verified and routed.
1762
+ * Otherwise, `false`.
1763
+ * @since 1.3.0
1764
+ */
1765
+ routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
1766
+ /**
1767
+ * Builds the URI of a collection of objects with the given name and values.
1768
+ * @param name The name of the collection, which can be a string or a symbol.
1769
+ * @param values The values of the URI parameters.
1770
+ * @return The URI of the collection.
1771
+ * @throws {RouterError} If no object dispatcher is available for the name.
1772
+ * @throws {TypeError} If values are invalid.
1773
+ * @since 1.8.0
1774
+ */
1775
+ getCollectionUri<TParam extends Record<string, string>>(name: string | symbol, values: TParam): URL;
1776
+ }
1777
+ /**
1778
+ * Options for {@link RequestContext.getActor}.
1779
+ * @since 2.2.0
1780
+ */
1781
+ interface GetActorOptions {
1782
+ /**
1783
+ * Controls how tombstoned actors are returned.
1784
+ *
1785
+ * By default, tombstones are suppressed and returned as `null`. Set this to
1786
+ * `"passthrough"` to receive a {@link Tombstone} result instead.
1787
+ */
1788
+ readonly tombstone?: "suppress" | "passthrough";
1789
+ }
1790
+ /**
1791
+ * A context for a request.
1792
+ */
1793
+ interface RequestContext<TContextData> extends Context<TContextData> {
1794
+ /**
1795
+ * The request object.
1796
+ */
1797
+ readonly request: Request;
1798
+ /**
1799
+ * The URL of the request.
1800
+ */
1801
+ readonly url: URL;
1802
+ /**
1803
+ * Creates a new context with the same properties as this one,
1804
+ * but with the given data.
1805
+ * @param data The new data to associate with the context.
1806
+ * @returns A new context with the same properties as this one,
1807
+ * but with the given data.
1808
+ * @since 1.6.0
1809
+ */
1810
+ clone(data: TContextData): RequestContext<TContextData>;
1811
+ /**
1812
+ * Gets an {@link Actor} object for the given identifier.
1813
+ * @param identifier The actor's identifier.
1814
+ * @returns The actor object, or `null` if the actor is not found.
1815
+ * @throws {Error} If no actor dispatcher is available.
1816
+ * @since 0.7.0
1817
+ */
1818
+ getActor(identifier: string): Promise<Actor | null>;
1819
+ /**
1820
+ * Gets an {@link Actor} object or {@link Tombstone} for the given
1821
+ * identifier.
1822
+ * @param identifier The actor's identifier.
1823
+ * @param options Options for getting the actor. Set
1824
+ * `options.tombstone` to `"passthrough"` to receive
1825
+ * tombstoned actors instead of `null`.
1826
+ * @returns The actor object, a tombstone, or `null` if the actor is not
1827
+ * found.
1828
+ * @throws {Error} If no actor dispatcher is available.
1829
+ * @since 2.2.0
1830
+ */
1831
+ getActor(identifier: string, options: GetActorOptions & {
1832
+ readonly tombstone: "passthrough";
1833
+ }): Promise<Actor | Tombstone | null>;
1834
+ /**
1835
+ * Gets an {@link Actor} object for the given identifier.
1836
+ * @param identifier The actor's identifier.
1837
+ * @param options Options for getting the actor.
1838
+ * @returns The actor object, or `null` if the actor is not found.
1839
+ * Tombstoned actors are suppressed unless `options.tombstone` is
1840
+ * `"passthrough"`.
1841
+ * @throws {Error} If no actor dispatcher is available.
1842
+ * @since 2.2.0
1843
+ */
1844
+ getActor(identifier: string, options: GetActorOptions & {
1845
+ readonly tombstone?: "suppress" | undefined;
1846
+ }): Promise<Actor | null>;
1847
+ /**
1848
+ * Gets an {@link Actor} object or {@link Tombstone} for the given
1849
+ * identifier.
1850
+ * @param identifier The actor's identifier.
1851
+ * @param options Options for getting the actor.
1852
+ * @returns The actor object, a tombstone, or `null` if the actor is not
1853
+ * found. This broad overload is used when the caller passes an
1854
+ * options value whose `tombstone` mode is not known statically.
1855
+ * @throws {Error} If no actor dispatcher is available.
1856
+ * @since 2.2.0
1857
+ */
1858
+ getActor(identifier: string, options: GetActorOptions): Promise<Actor | Tombstone | null>;
1859
+ /**
1860
+ * Gets an object of the given class with the given values.
1861
+ * @param cls The class to instantiate.
1862
+ * @param values The values to pass to the object dispatcher.
1863
+ * @returns The object of the given class with the given values, or `null`
1864
+ * if the object is not found.
1865
+ * @throws {Error} If no object dispatcher is available for the class.
1866
+ * @throws {TypeError} If values are invalid.
1867
+ * @since 0.7.0
1868
+ */
1869
+ getObject<TObject extends Object$1>(cls: ConstructorWithTypeId<TObject>, values: Record<string, string>): Promise<TObject | null>;
1870
+ /**
1871
+ * Gets the public key of the sender, if any exists and it is verified.
1872
+ * Otherwise, `null` is returned.
1873
+ *
1874
+ * Successful results are reused for this request regardless of the options.
1875
+ * Pending checks and `null` results are reused for the same effective
1876
+ * document and context loaders, including failed lookups. Rejected checks
1877
+ * can be retried. Shared work uses the first caller's tracer provider.
1878
+ *
1879
+ * This can be used for implementing [authorized fetch] (also known as
1880
+ * secure mode) in ActivityPub.
1881
+ *
1882
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
1883
+ *
1884
+ * @returns The public key of the sender, or `null` if the sender is not verified.
1885
+ * @since 0.7.0
1886
+ */
1887
+ getSignedKey(): Promise<CryptographicKey | null>;
1888
+ /**
1889
+ * Gets the public key of the sender, if any exists and it is verified.
1890
+ * Otherwise, `null` is returned.
1891
+ *
1892
+ * Successful results are reused for this request regardless of the options.
1893
+ * Pending checks and `null` results are reused for the same effective
1894
+ * document and context loaders, including failed lookups. Rejected checks
1895
+ * can be retried. Shared work uses the first caller's tracer provider.
1896
+ *
1897
+ * This can be used for implementing [authorized fetch] (also known as
1898
+ * secure mode) in ActivityPub.
1899
+ *
1900
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
1901
+ *
1902
+ * @param options Options for getting the signed key. You usually may want to
1903
+ * specify the custom `documentLoader` so that making
1904
+ * an HTTP request to the sender's server is signed with
1905
+ * your [instance actor].
1906
+ * @returns The public key of the sender, or `null` if the sender is not verified.
1907
+ * @since 1.5.0
1908
+ *
1909
+ * [instance actor]: https://swicg.github.io/activitypub-http-signature/#instance-actor
1910
+ */
1911
+ getSignedKey(options: GetSignedKeyOptions): Promise<CryptographicKey | null>;
1912
+ /**
1913
+ * Gets the owner of the signed key, if any exists and it is verified.
1914
+ * Otherwise, `null` is returned.
1915
+ *
1916
+ * Verified keys and owners are reused for this request regardless of the
1917
+ * options. Pending checks are shared for the same effective document and
1918
+ * context loaders. A `null` result from an owner lookup after key
1919
+ * verification is retained for those loaders. A `null` result caused by
1920
+ * an unverified key is not retained, allowing an owner lookup after another
1921
+ * loader verifies the key. Rejected checks can be retried. Shared work
1922
+ * uses the first caller's tracer provider.
1923
+ *
1924
+ * This can be used for implementing [authorized fetch] (also known as
1925
+ * secure mode) in ActivityPub.
1926
+ *
1927
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
1928
+ *
1929
+ * @returns The owner of the signed key, or `null` if the key is not verified
1930
+ * or the owner is not found.
1931
+ * @since 0.7.0
1932
+ */
1933
+ getSignedKeyOwner(): Promise<Actor | null>;
1934
+ /**
1935
+ * Gets the owner of the signed key, if any exists and it is verified.
1936
+ * Otherwise, `null` is returned.
1937
+ *
1938
+ * Verified keys and owners are reused for this request regardless of the
1939
+ * options. Pending checks are shared for the same effective document and
1940
+ * context loaders. A `null` result from an owner lookup after key
1941
+ * verification is retained for those loaders. A `null` result caused by
1942
+ * an unverified key is not retained, allowing an owner lookup after another
1943
+ * loader verifies the key. Rejected checks can be retried. Shared work
1944
+ * uses the first caller's tracer provider.
1945
+ *
1946
+ * This can be used for implementing [authorized fetch] (also known as
1947
+ * secure mode) in ActivityPub.
1948
+ *
1949
+ * [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
1950
+ *
1951
+ * @param options Options for getting the key owner. You usually may want to
1952
+ * specify the custom `documentLoader` so that making
1953
+ * an HTTP request to the key owner's server is signed with
1954
+ * your [instance actor].
1955
+ * @returns The owner of the signed key, or `null` if the key is not verified
1956
+ * or the owner is not found.
1957
+ * @since 1.5.0
1958
+ *
1959
+ * [instance actor]: https://swicg.github.io/activitypub-http-signature/#instance-actor
1960
+ */
1961
+ getSignedKeyOwner(options: GetKeyOwnerOptions): Promise<Actor | null>;
1962
+ }
1963
+ /**
1964
+ * A context for inbox listeners.
1965
+ * @since 1.0.0
1966
+ */
1967
+ interface InboxContext<TContextData> extends Context<TContextData> {
1968
+ /**
1969
+ * The identifier of the recipient of the inbox. If the inbox is a shared
1970
+ * inbox, it is `null`.
1971
+ * @since 1.2.0
1972
+ */
1973
+ readonly recipient: string | null;
1974
+ /**
1975
+ * Creates a new context with the same properties as this one,
1976
+ * but with the given data.
1977
+ * @param data The new data to associate with the context.
1978
+ * @returns A new context with the same properties as this one,
1979
+ * but with the given data.
1980
+ * @since 1.6.0
1981
+ */
1982
+ clone(data: TContextData): InboxContext<TContextData>;
1983
+ /**
1984
+ * Forwards a received activity to the recipients' inboxes. The forwarded
1985
+ * activity will be signed in HTTP Signatures by the forwarder, but its
1986
+ * payload will not be modified, i.e., Linked Data Signatures and Object
1987
+ * Integrity Proofs will not be added. Even when Fedify internally
1988
+ * normalizes a Linked Data Signature activity for parsing, this method still
1989
+ * forwards the original received payload so the sender's signatures/proofs
1990
+ * are preserved as-is. Therefore, if the activity is not signed (i.e., it
1991
+ * has neither Linked Data Signatures nor Object Integrity Proofs), the
1992
+ * recipient probably will not trust the activity.
1993
+ * @param forwarder The forwarder's identifier or the forwarder's username
1994
+ * or the forwarder's key pair(s).
1995
+ * @param recipients The recipients of the activity.
1996
+ * @param options Options for forwarding the activity.
1997
+ * @since 1.0.0
1998
+ */
1999
+ forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2000
+ identifier: string;
2001
+ } | {
2002
+ username: string;
2003
+ }, recipients: Recipient | Recipient[], options?: ForwardActivityOptions): Promise<void>;
2004
+ /**
2005
+ * Forwards a received activity to the recipients' inboxes. The forwarded
2006
+ * activity will be signed in HTTP Signatures by the forwarder, but its
2007
+ * payload will not be modified, i.e., Linked Data Signatures and Object
2008
+ * Integrity Proofs will not be added. Even when Fedify internally
2009
+ * normalizes a Linked Data Signature activity for parsing, this method still
2010
+ * forwards the original received payload so the sender's signatures/proofs
2011
+ * are preserved as-is. Therefore, if the activity is not signed (i.e., it
2012
+ * has neither Linked Data Signatures nor Object Integrity Proofs), the
2013
+ * recipient probably will not trust the activity.
2014
+ * @param forwarder The forwarder's identifier or the forwarder's username.
2015
+ * @param recipients In this case, it must be `"followers"`.
2016
+ * @param options Options for forwarding the activity.
2017
+ * @since 1.0.0
2018
+ */
2019
+ forwardActivity(forwarder: {
2020
+ identifier: string;
2021
+ } | {
2022
+ username: string;
2023
+ }, recipients: "followers", options?: ForwardActivityOptions): Promise<void>;
2024
+ }
2025
+ /**
2026
+ * A context for outbox listeners.
2027
+ * @since 2.2.0
2028
+ */
2029
+ interface OutboxContext<TContextData> extends Context<TContextData> {
2030
+ /**
2031
+ * The identifier of the actor whose outbox received the POST.
2032
+ * @since 2.2.0
2033
+ */
2034
+ readonly identifier: string;
2035
+ /**
2036
+ * Indicates whether the posted activity has been delivered during the
2037
+ * current outbox listener invocation.
2038
+ * @returns `true` if the posted activity has been delivered; `false`
2039
+ * otherwise.
2040
+ * @since 2.2.0
2041
+ */
2042
+ hasDeliveredActivity(): boolean;
2043
+ /**
2044
+ * Forwards a posted activity to the recipients' inboxes without
2045
+ * re-serializing the original payload. The forwarded activity will be
2046
+ * signed in HTTP Signatures by the forwarder, but its payload will not be
2047
+ * modified, i.e., Linked Data Signatures and Object Integrity Proofs will
2048
+ * not be added. Therefore, if the posted activity is not signed (i.e., it
2049
+ * has neither Linked Data Signatures nor Object Integrity Proofs), the
2050
+ * recipients probably will not trust the activity.
2051
+ * @param forwarder The forwarder's identifier or the forwarder's username
2052
+ * or the forwarder's key pair(s).
2053
+ * @param recipients The recipients of the activity.
2054
+ * @param options Options for forwarding the activity.
2055
+ * @since 2.2.0
2056
+ */
2057
+ forwardActivity(forwarder: SenderKeyPair<CryptoKeyLike> | SenderKeyPair<CryptoKeyLike>[] | {
2058
+ identifier: string;
2059
+ } | {
2060
+ username: string;
2061
+ }, recipients: Recipient | Recipient[], options?: ForwardActivityOptions): Promise<void>;
2062
+ /**
2063
+ * Forwards a posted activity to the recipients' inboxes without
2064
+ * re-serializing the original payload. The forwarded activity will be
2065
+ * signed in HTTP Signatures by the forwarder, but its payload will not be
2066
+ * modified, i.e., Linked Data Signatures and Object Integrity Proofs will
2067
+ * not be added. Therefore, if the posted activity is not signed (i.e., it
2068
+ * has neither Linked Data Signatures nor Object Integrity Proofs), the
2069
+ * recipients probably will not trust the activity.
2070
+ * @param forwarder The forwarder's identifier or the forwarder's username.
2071
+ * @param recipients In this case, it must be `"followers"`.
2072
+ * @param options Options for forwarding the activity.
2073
+ * @since 2.2.0
2074
+ */
2075
+ forwardActivity(forwarder: {
2076
+ identifier: string;
2077
+ } | {
2078
+ username: string;
2079
+ }, recipients: "followers", options?: ForwardActivityOptions): Promise<void>;
2080
+ /**
2081
+ * Creates a new context with the same properties as this one,
2082
+ * but with the given data.
2083
+ * @param data The new data to associate with the context.
2084
+ * @returns A new context with the same properties as this one,
2085
+ * but with the given data.
2086
+ * @since 2.2.0
2087
+ */
2088
+ clone(data: TContextData): OutboxContext<TContextData>;
2089
+ }
2090
+ /**
2091
+ * A result of parsing an URI.
2092
+ */
2093
+ type ParseUriResult =
2094
+ /**
2095
+ * The case of an actor URI.
2096
+ */
2097
+ {
2098
+ readonly type: "actor";
2099
+ readonly identifier: string;
2100
+ }
2101
+ /**
2102
+ * The case of an object URI.
2103
+ */
2104
+ | {
2105
+ readonly type: "object";
2106
+ readonly class: ConstructorWithTypeId<Object$1>;
2107
+ readonly typeId: URL;
2108
+ readonly values: Record<string, string>;
2109
+ }
2110
+ /**
2111
+ * The case of an shared inbox URI.
2112
+ */
2113
+ | {
2114
+ readonly type: "inbox";
2115
+ readonly identifier: undefined;
2116
+ }
2117
+ /**
2118
+ * The case of an personal inbox URI.
2119
+ */
2120
+ | {
2121
+ readonly type: "inbox";
2122
+ readonly identifier: string;
2123
+ }
2124
+ /**
2125
+ * The case of an outbox collection URI.
2126
+ */
2127
+ | {
2128
+ readonly type: "outbox";
2129
+ readonly identifier: string;
2130
+ }
2131
+ /**
2132
+ * The case of a following collection URI.
2133
+ */
2134
+ | {
2135
+ readonly type: "following";
2136
+ readonly identifier: string;
2137
+ }
2138
+ /**
2139
+ * The case of a followers collection URI.
2140
+ */
2141
+ | {
2142
+ readonly type: "followers";
2143
+ readonly identifier: string;
2144
+ }
2145
+ /**
2146
+ * The case of a liked collection URI.
2147
+ * @since 0.11.0
2148
+ */
2149
+ | {
2150
+ readonly type: "liked";
2151
+ readonly identifier: string;
2152
+ }
2153
+ /**
2154
+ * The case of a featured collection URI.
2155
+ * @since 0.11.0
2156
+ */
2157
+ | {
2158
+ readonly type: "featured";
2159
+ readonly identifier: string;
2160
+ }
2161
+ /**
2162
+ * The case of a featured tags collection URI.
2163
+ * @since 0.11.0
2164
+ */
2165
+ | {
2166
+ readonly type: "featuredTags";
2167
+ readonly identifier: string;
2168
+ }
2169
+ /**
2170
+ * The case of a custom collection URI.
2171
+ * @since 1.8.0
2172
+ */
2173
+ | {
2174
+ readonly type: "collection";
2175
+ readonly name: string | symbol;
2176
+ readonly class: ConstructorWithTypeId<Object$1>;
2177
+ readonly typeId: URL;
2178
+ readonly values: Record<string, string>;
2179
+ }
2180
+ /**
2181
+ * The case of a custom ordered collection URI.
2182
+ * @since 1.8.0
2183
+ */
2184
+ | {
2185
+ readonly type: "orderedCollection";
2186
+ readonly name: string | symbol;
2187
+ readonly class: ConstructorWithTypeId<Object$1>;
2188
+ readonly typeId: URL;
2189
+ readonly values: Record<string, string>;
2190
+ };
2191
+ /**
2192
+ * Options for {@link Context.sendActivity} method.
2193
+ */
2194
+ interface SendActivityOptions {
2195
+ /**
2196
+ * Whether to prefer the shared inbox for the recipients.
2197
+ */
2198
+ readonly preferSharedInbox?: boolean;
2199
+ /**
2200
+ * Whether to send the activity immediately, without enqueuing it.
2201
+ * If `true`, the activity will be sent immediately and the retrial
2202
+ * policy will not be applied.
2203
+ *
2204
+ * @since 0.3.0
2205
+ */
2206
+ readonly immediate?: boolean;
2207
+ /**
2208
+ * Determines how activities are queued when sent to multiple recipients.
2209
+ *
2210
+ * - "auto" (default): Automatically chooses optimal strategy based on
2211
+ * recipient count.
2212
+ * - "skip": Always enqueues individual messages per recipient,
2213
+ * bypassing the fanout queue. Use when payload needs to vary per recipient.
2214
+ * - "force": Always uses fanout queue regardless of recipient count.
2215
+ * Useful for testing or special cases.
2216
+ *
2217
+ * This option is ignored when `immediate: true` is specified, as immediate
2218
+ * delivery bypasses all queuing mechanisms.
2219
+ *
2220
+ * @default `"auto"`
2221
+ * @since 1.5.0
2222
+ */
2223
+ readonly fanout?: "auto" | "skip" | "force";
2224
+ /**
2225
+ * Whether to apply Fedify's outgoing JSON-LD wire-format compatibility fixes
2226
+ * to activities that already carry Object Integrity Proofs.
2227
+ *
2228
+ * By default, Fedify preserves existing proofs byte-for-byte because it
2229
+ * cannot know whether they were created for the normalized outgoing wire
2230
+ * form. Set this to `true` when sending an activity that was pre-signed
2231
+ * locally with `signObject()` or `createProof()`, so the emitted
2232
+ * compact JSON-LD matches the bytes covered by the proof.
2233
+ *
2234
+ * @since 2.2.0
2235
+ */
2236
+ readonly normalizeExistingProofs?: boolean;
2237
+ /**
2238
+ * The base URIs to exclude from the recipients' inboxes. It is useful
2239
+ * for excluding the recipients having the same shared inbox with the sender.
2240
+ *
2241
+ * Note that the only `origin` parts of the `URL`s are compared.
2242
+ *
2243
+ * @since 0.9.0
2244
+ */
2245
+ readonly excludeBaseUris?: readonly URL[];
2246
+ /**
2247
+ * An optional key to ensure ordered delivery of activities. Activities with
2248
+ * the same `orderingKey` are guaranteed to be delivered in the order they
2249
+ * were enqueued, per recipient server.
2250
+ *
2251
+ * Typical use case: pass the object ID (e.g., `Note` ID) to ensure that
2252
+ * `Create`, `Update`, and `Delete` activities for the same object are
2253
+ * delivered in order.
2254
+ *
2255
+ * When omitted, no ordering is guaranteed (maximum parallelism).
2256
+ *
2257
+ * @since 2.0.0
2258
+ */
2259
+ readonly orderingKey?: string;
2260
+ }
2261
+ /**
2262
+ * Options for {@link Context.sendActivity} method when sending to a collection.
2263
+ * @since 1.5.0
2264
+ */
2265
+ interface SendActivityOptionsForCollection extends SendActivityOptions {
2266
+ /**
2267
+ * Whether to synchronize the collection using `Collection-Synchronization`
2268
+ * header ([FEP-8fcf]).
2269
+ *
2270
+ * [FEP-8fcf]: https://w3id.org/fep/8fcf
2271
+ */
2272
+ syncCollection?: boolean;
2273
+ }
2274
+ /**
2275
+ * Options for {@link InboxContext.forwardActivity} method.
2276
+ * @since 1.0.0
2277
+ */
2278
+ type ForwardActivityOptions = Omit<SendActivityOptions, "fanout"> & {
2279
+ /**
2280
+ * Whether to skip forwarding the activity if it is not signed, i.e., it has
2281
+ * neither Linked Data Signatures nor Object Integrity Proofs.
2282
+ *
2283
+ * If the activity is not signed, the recipient probably will not trust the
2284
+ * activity. Therefore, it is recommended to skip forwarding the activity
2285
+ * if it is not signed.
2286
+ */
2287
+ skipIfUnsigned: boolean;
2288
+ };
2289
+ /**
2290
+ * Options for {@link Context.routeActivity} method.
2291
+ * @since 1.3.0
2292
+ */
2293
+ interface RouteActivityOptions {
2294
+ /**
2295
+ * Whether to skip enqueuing the activity and invoke the listener immediately.
2296
+ * If no inbox queue is available, this option is ignored and the activity
2297
+ * will be always invoked immediately.
2298
+ * @default false
2299
+ */
2300
+ immediate?: boolean;
2301
+ /**
2302
+ * The document loader for loading remote JSON-LD documents.
2303
+ */
2304
+ documentLoader?: DocumentLoader;
2305
+ /**
2306
+ * The context loader for loading remote JSON-LD contexts.
2307
+ */
2308
+ contextLoader?: DocumentLoader;
2309
+ /**
2310
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
2311
+ * is used.
2312
+ */
2313
+ tracerProvider?: TracerProvider;
2314
+ }
2315
+ /**
2316
+ * Options for {@link Context.getSignedKey} method.
2317
+ * @since 1.5.0
2318
+ */
2319
+ interface GetSignedKeyOptions {
2320
+ /**
2321
+ * The document loader for loading remote JSON-LD documents.
2322
+ */
2323
+ documentLoader?: DocumentLoader;
2324
+ /**
2325
+ * The context loader for loading remote JSON-LD contexts.
2326
+ */
2327
+ contextLoader?: DocumentLoader;
2328
+ /**
2329
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
2330
+ * is used.
2331
+ */
2332
+ tracerProvider?: TracerProvider;
2333
+ }
2334
+ /**
2335
+ * A pair of a public key and a private key in various formats.
2336
+ * @since 0.10.0
2337
+ */
2338
+ interface ActorKeyPair extends CryptoKeyPair {
2339
+ /**
2340
+ * The URI of the public key for {@link CryptographicKey}, which is used for
2341
+ * verifying HTTP Signatures and Linked Data Signatures. Note that this is
2342
+ * the ID of the {@link cryptographicKey}, not of the {@link multikey};
2343
+ * the {@link Multikey} instance has a distinct ID of its own.
2344
+ */
2345
+ readonly keyId: URL;
2346
+ /**
2347
+ * A {@link CryptographicKey} instance of the public key.
2348
+ */
2349
+ readonly cryptographicKey: CryptographicKey;
2350
+ /**
2351
+ * A {@link Multikey} instance of the public key.
2352
+ */
2353
+ readonly multikey: Multikey;
2354
+ }
2355
+ //#endregion
2356
+ //#region src/federation/callback.d.ts
2357
+ /**
2358
+ * A callback that dispatches a {@link NodeInfo} object.
2359
+ *
2360
+ * @template TContextData The context data to pass to the {@link Context}.
2361
+ */
2362
+ type NodeInfoDispatcher<TContextData> = (context: RequestContext<TContextData>) => NodeInfo | Promise<NodeInfo>;
2363
+ /**
2364
+ * A callback that dispatches a array of {@link Link}.
2365
+ *
2366
+ * @template TContextData The context data to pass to the {@link Context}.
2367
+ * @param resource The URL queried via WebFinger.
2368
+ * @returns Links related to the queried resource.
2369
+ */
2370
+ type WebFingerLinksDispatcher<TContextData> = (context: RequestContext<TContextData>, resource: URL) => readonly Link$1[] | Promise<readonly Link$1[]>;
2371
+ /**
2372
+ * A callback that dispatches an {@link Actor} object or a {@link Tombstone}.
2373
+ *
2374
+ * @template TContextData The context data to pass to the {@link Context}.
2375
+ * @param context The request context.
2376
+ * @param identifier The actor's internal identifier or username.
2377
+ */
2378
+ type ActorDispatcher<TContextData> = (context: RequestContext<TContextData>, identifier: string) => Actor | Tombstone | null | Promise<Actor | Tombstone | null>;
2379
+ /**
2380
+ * A callback that dispatches key pairs for an actor.
2381
+ *
2382
+ * The returned key pairs may come from any supported runtime, including keys
2383
+ * obtained from `node:crypto`'s Web Crypto API, so the key pair type is
2384
+ * parameterized. It defaults to the ambient `CryptoKeyPair` type for
2385
+ * compatibility with code that calls a dispatcher directly.
2386
+ *
2387
+ * @template TContextData The context data to pass to the {@link Context}.
2388
+ * @template TKeyPair The type of the key pairs the dispatcher returns.
2389
+ * @param context The context.
2390
+ * @param identifier The actor's internal identifier or username.
2391
+ * @returns The key pairs.
2392
+ * @since 0.10.0
2393
+ */
2394
+ type ActorKeyPairsDispatcher<TContextData, TKeyPair extends CryptoKeyPairLike = CryptoKeyPair> = (context: Context<TContextData>, identifier: string) => TKeyPair[] | Promise<TKeyPair[]>;
2395
+ /**
2396
+ * A callback that maps a WebFinger username to the corresponding actor's
2397
+ * internal identifier, or `null` if the username is not found.
2398
+ * @template TContextData The context data to pass to the {@link Context}.
2399
+ * @param context The context.
2400
+ * @param username The WebFinger username.
2401
+ * @returns The actor's internal identifier, or `null` if the username is not
2402
+ * found.
2403
+ * @since 0.15.0
2404
+ */
2405
+ type ActorHandleMapper<TContextData> = (context: Context<TContextData>, username: string) => string | null | Promise<string | null>;
2406
+ /**
2407
+ * A callback that maps a WebFinger query to the corresponding actor's
2408
+ * internal identifier or username, or `null` if the query is not found.
2409
+ * @template TContextData The context data to pass to the {@link Context}.
2410
+ * @param context The request context.
2411
+ * @param resource The URL that was queried through WebFinger.
2412
+ * @returns The actor's internal identifier or username, or `null` if the query
2413
+ * is not found.
2414
+ * @since 1.4.0
2415
+ */
2416
+ type ActorAliasMapper<TContextData> = (context: RequestContext<TContextData>, resource: URL) => {
2417
+ identifier: string;
2418
+ } | {
2419
+ username: string;
2420
+ } | null | Promise<{
2421
+ identifier: string;
2422
+ } | {
2423
+ username: string;
2424
+ } | null>;
2425
+ /**
2426
+ * A callback that dispatches an object.
2427
+ *
2428
+ * @template TContextData The context data to pass to the {@link Context}.
2429
+ * @template TObject The type of object to dispatch.
2430
+ * @template TParam The parameter names of the requested URL.
2431
+ * @since 0.7.0
2432
+ */
2433
+ type ObjectDispatcher<TContextData, TObject extends Object$1, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => TObject | null | Promise<TObject | null>;
2434
+ /**
2435
+ * A callback that dispatches a collection.
2436
+ *
2437
+ * @template TItem The type of items in the collection.
2438
+ * @template TContext The type of the context. {@link Context} or
2439
+ * {@link RequestContext}.
2440
+ * @template TContextData The context data to pass to the `TContext`.
2441
+ * @template TFilter The type of the filter, if any.
2442
+ * @param context The context.
2443
+ * @param identifier The internal identifier or the username of the collection
2444
+ * owner.
2445
+ * @param cursor The cursor to start the collection from, or `null` to dispatch
2446
+ * the entire collection without pagination.
2447
+ * @param filter The filter to apply to the collection, if any.
2448
+ */
2449
+ 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>;
2450
+ /**
2451
+ * A callback that counts the number of items in a collection.
2452
+ *
2453
+ * @template TContextData The context data to pass to the {@link Context}.
2454
+ * @param context The context.
2455
+ * @param identifier The internal identifier or the username of the collection
2456
+ * owner.
2457
+ * @param filter The filter to apply to the collection, if any.
2458
+ */
2459
+ type CollectionCounter<TContextData, TFilter> = (context: RequestContext<TContextData>, identifier: string, filter?: TFilter) => number | bigint | null | Promise<number | bigint | null>;
2460
+ /**
2461
+ * A callback that returns a cursor for a collection.
2462
+ *
2463
+ * @template TContext The type of the context. {@link Context} or
2464
+ * {@link RequestContext}.
2465
+ * @template TContextData The context data to pass to the {@link Context}.
2466
+ * @template TFilter The type of the filter, if any.
2467
+ * @param context The context.
2468
+ * @param identifier The internal identifier or the username of the collection
2469
+ * owner.
2470
+ * @param filter The filter to apply to the collection, if any.
2471
+ */
2472
+ type CollectionCursor<TContext extends Context<TContextData>, TContextData, TFilter> = (context: TContext, identifier: string, filter?: TFilter) => string | null | Promise<string | null>;
2473
+ /**
2474
+ * A callback that listens for activities in an inbox.
2475
+ *
2476
+ * @template TContextData The context data to pass to the {@link Context}.
2477
+ * @template TActivity The type of activity to listen for.
2478
+ * @param context The inbox context.
2479
+ * @param activity The activity that was received.
2480
+ */
2481
+ type InboxListener<TContextData, TActivity extends Activity> = (context: InboxContext<TContextData>, activity: TActivity) => void | Promise<void>;
2482
+ /**
2483
+ * A callback that listens for activities in an outbox.
2484
+ *
2485
+ * @template TContextData The context data to pass to the {@link Context}.
2486
+ * @template TActivity The type of activity to listen for.
2487
+ * @param context The outbox context.
2488
+ * @param activity The activity that was received.
2489
+ * @since 2.2.0
2490
+ */
2491
+ type OutboxListener<TContextData, TActivity extends Activity> = (context: OutboxContext<TContextData>, activity: TActivity) => void | Promise<void>;
2492
+ /**
2493
+ * The reason why an incoming activity could not be verified.
2494
+ *
2495
+ * Unlike inbox listeners registered through {@link InboxListenerSetters.on},
2496
+ * unverified activity handlers are called only when the activity payload could
2497
+ * be parsed but its HTTP signatures could not be verified.
2498
+ *
2499
+ * @since 2.1.0
2500
+ */
2501
+ type UnverifiedActivityReason = VerifyRequestFailureReason;
2502
+ /**
2503
+ * A callback that handles activities whose signatures could not be verified.
2504
+ *
2505
+ * Returning a {@link Response} overrides Fedify's default `401 Unauthorized`
2506
+ * response. Returning `void` keeps the default behavior.
2507
+ *
2508
+ * @template TContextData The context data to pass to the {@link Context}.
2509
+ * @param context The request context.
2510
+ * @param activity The incoming activity that could be parsed.
2511
+ * @param reason The reason why signature verification failed.
2512
+ * @since 2.1.0
2513
+ */
2514
+ type UnverifiedActivityHandler<TContextData> = (context: RequestContext<TContextData>, activity: Activity, reason: UnverifiedActivityReason) => void | Response | Promise<void | Response>;
2515
+ /**
2516
+ * A callback that handles errors in an inbox.
2517
+ *
2518
+ * @template TContextData The context data to pass to the {@link Context}.
2519
+ * @param context The inbox context.
2520
+ */
2521
+ type InboxErrorHandler<TContextData> = (context: Context<TContextData>, error: Error) => void | Promise<void>;
2522
+ /**
2523
+ * A callback that handles errors in an outbox listener.
2524
+ *
2525
+ * @template TContextData The context data to pass to the {@link Context}.
2526
+ * @param context The outbox context.
2527
+ * @param error The error that occurred.
2528
+ * @since 2.2.0
2529
+ */
2530
+ type OutboxListenerErrorHandler<TContextData> = (context: OutboxContext<TContextData>, error: Error) => void | Promise<void>;
2531
+ /**
2532
+ * A callback that dispatches the key pair for the authenticated document loader
2533
+ * of the {@link Context} passed to the shared inbox listener.
2534
+ *
2535
+ * @template TContextData The context data to pass to the {@link Context}.
2536
+ * @param context The context.
2537
+ * @returns The username or the internal identifier of the actor or the key pair
2538
+ * for the authenticated document loader of the {@link Context} passed
2539
+ * to the shared inbox listener. If `null` is returned, the request is
2540
+ * not authorized.
2541
+ * @since 0.11.0
2542
+ */
2543
+ type SharedInboxKeyDispatcher<TContextData, TKeyPair extends CryptoKeyLike = CryptoKey> = (context: Context<TContextData>) => SenderKeyPair<TKeyPair> | {
2544
+ identifier: string;
2545
+ } | {
2546
+ username: string;
2547
+ } | null | Promise<SenderKeyPair<TKeyPair> | {
2548
+ identifier: string;
2549
+ } | {
2550
+ username: string;
2551
+ } | null>;
2552
+ /**
2553
+ * A callback that handles permanent delivery failures when sending activities
2554
+ * to remote inboxes.
2555
+ *
2556
+ * This handler is called when an inbox returns an HTTP status code that
2557
+ * indicates permanent failure (such as `410 Gone` or `404 Not Found`),
2558
+ * allowing the application to clean up followers that are no longer reachable.
2559
+ *
2560
+ * Unlike {@link OutboxErrorHandler}, which is called for every delivery failure
2561
+ * (including retries), this handler is called only once for permanent failures,
2562
+ * after which delivery is not retried.
2563
+ *
2564
+ * If any errors are thrown in this callback, they are caught, logged,
2565
+ * and ignored.
2566
+ *
2567
+ * @template TContextData The context data to pass to the {@link Context}.
2568
+ * @param context The context.
2569
+ * @param values The delivery failure information.
2570
+ * @since 2.0.0
2571
+ */
2572
+ type OutboxPermanentFailureHandler<TContextData> = (context: Context<TContextData>, values: {
2573
+ /**
2574
+ * Why Fedify is giving up on delivery.
2575
+ *
2576
+ * `"http"` means the inbox returned a configured permanent-failure HTTP
2577
+ * status. `"circuit-breaker-ttl"` means the outbound circuit breaker held
2578
+ * the activity until its retention period expired.
2579
+ *
2580
+ * @since 2.3.0
2581
+ */
2582
+ readonly reason: "http" | "circuit-breaker-ttl"; /** The inbox URL that failed. */
2583
+ readonly inbox: URL; /** The activity that failed to deliver. */
2584
+ readonly activity: Activity; /** The error that occurred. */
2585
+ readonly error: SendActivityError; /** The HTTP status code returned by the inbox. */
2586
+ readonly statusCode: number;
2587
+ /**
2588
+ * The time when the circuit breaker first held the activity, if
2589
+ * {@link reason} is `"circuit-breaker-ttl"`.
2590
+ *
2591
+ * @since 2.3.0
2592
+ */
2593
+ readonly circuitHeldSince?: Temporal.Instant;
2594
+ /**
2595
+ * The actor IDs that were supposed to receive the activity at this inbox.
2596
+ */
2597
+ readonly actorIds: readonly URL[];
2598
+ }) => void | Promise<void>;
2599
+ /**
2600
+ * A callback that determines if a request is authorized or not.
2601
+ *
2602
+ * @template TContextData The context data to pass to the {@link Context}.
2603
+ * @param context The request context.
2604
+ * @param identifier The internal identifier of the actor that is being
2605
+ * requested.
2606
+ * @returns `true` if the request is authorized, `false` otherwise.
2607
+ * @since 0.7.0
2608
+ */
2609
+ type AuthorizePredicate<TContextData> = (context: RequestContext<TContextData>, identifier: string) => boolean | Promise<boolean>;
2610
+ /**
2611
+ * A callback that determines if a request is authorized or not.
2612
+ *
2613
+ * @template TContextData The context data to pass to the {@link Context}.
2614
+ * @template TParam The parameter names of the requested URL.
2615
+ * @param context The request context.
2616
+ * @param values The parameters of the requested URL.
2617
+ * @returns `true` if the request is authorized, `false` otherwise.
2618
+ * @since 0.7.0
2619
+ */
2620
+ type ObjectAuthorizePredicate<TContextData, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => boolean | Promise<boolean>;
2621
+ /**
2622
+ * A callback that dispatches a custom collection.
2623
+ *
2624
+ * @template TItem The type of items in the collection.
2625
+ * @template TParams The parameter names of the requested URL.
2626
+ * @template TContext The type of the context. {@link Context} or
2627
+ * {@link RequestContext}.
2628
+ * @template TContextData The context data to pass to the `TContext`.
2629
+ * @template TFilter The type of the filter, if any.
2630
+ * @param context The context.
2631
+ * @param values The parameters of the requested URL.
2632
+ * @param cursor The cursor to start the collection from, or `null` to dispatch
2633
+ * the entire collection without pagination.
2634
+ * @since 1.8.0
2635
+ */
2636
+ type CustomCollectionDispatcher<TItem, TParam extends string, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: Record<TParam, string>, cursor: string | null) => PageItems<TItem> | null | Promise<PageItems<TItem> | null>;
2637
+ /**
2638
+ * A callback that counts the number of items in a custom collection.
2639
+ *
2640
+ * @template TParams The parameter names of the requested URL.
2641
+ * @template TContextData The context data to pass to the {@link Context}.
2642
+ * @param context The context.
2643
+ * @param values The parameters of the requested URL.
2644
+ * @since 1.8.0
2645
+ */
2646
+ type CustomCollectionCounter<TParam extends string, TContextData> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => number | bigint | null | Promise<number | bigint | null>;
2647
+ /**
2648
+ * A callback that returns a cursor for a custom collection.
2649
+ *
2650
+ * @template TParams The parameter names of the requested URL.
2651
+ * @template TContext The type of the context. {@link Context} or
2652
+ * {@link RequestContext}.
2653
+ * @template TContextData The context data to pass to the {@link Context}.
2654
+ * @template TFilter The type of the filter, if any.
2655
+ * @param context The context.
2656
+ * @param values The parameters of the requested URL.
2657
+ * @since 1.8.0
2658
+ */
2659
+ type CustomCollectionCursor<TParam extends string, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: Record<TParam, string>) => string | null | Promise<string | null>;
2660
+ //#endregion
2661
+ export { RequestContext as a, InboxListenerSetters as c, signRequest as d, exportJwk as f, OutboxContext as i, SenderKeyPair as l, Context as n, ActorCallbackSetters as o, InboxContext as r, Federation as s, ActorKeyPairsDispatcher as t, HttpMessageSignaturesSpecDeterminer as u };