@fedify/fedify 2.0.36-dev.2653 → 2.0.36-dev.2734

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