@fedify/fedify 2.1.30 → 2.1.32

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