@fedify/fedify 2.3.16-dev.2841 → 2.3.16

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