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

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