@fedify/fedify 2.2.20 → 2.2.21

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