@fedify/fedify 1.0.0-dev.396 → 1.0.0-dev.398
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGES.md +17 -0
- package/esm/federation/federation.js +1 -0
- package/esm/federation/handler.js +3 -3
- package/esm/federation/middleware.js +222 -42
- package/esm/federation/mod.js +2 -1
- package/esm/federation/send.js +9 -63
- package/esm/sig/ld.js +7 -1
- package/esm/sig/mod.js +1 -1
- package/esm/webfinger/handler.js +11 -0
- package/package.json +1 -1
- package/types/federation/callback.d.ts +5 -2
- package/types/federation/callback.d.ts.map +1 -1
- package/types/federation/context.d.ts +52 -2
- package/types/federation/context.d.ts.map +1 -1
- package/types/federation/federation.d.ts +462 -0
- package/types/federation/federation.d.ts.map +1 -0
- package/types/federation/handler.d.ts +3 -2
- package/types/federation/handler.d.ts.map +1 -1
- package/types/federation/middleware.d.ts +125 -426
- package/types/federation/middleware.d.ts.map +1 -1
- package/types/federation/mod.d.ts +2 -1
- package/types/federation/mod.d.ts.map +1 -1
- package/types/federation/queue.d.ts +1 -0
- package/types/federation/queue.d.ts.map +1 -1
- package/types/federation/send.d.ts +7 -14
- package/types/federation/send.d.ts.map +1 -1
- package/types/sig/ld.d.ts +11 -0
- package/types/sig/ld.d.ts.map +1 -1
- package/types/sig/mod.d.ts +1 -1
- package/types/sig/mod.d.ts.map +1 -1
- package/types/webfinger/handler.d.ts.map +1 -1
- package/types/x/hono.d.ts +1 -1
@@ -3,12 +3,18 @@
|
|
3
3
|
import * as dntShim from "../_dnt.shims.js";
|
4
4
|
import { type AuthenticatedDocumentLoaderFactory, type DocumentLoader } from "../runtime/docloader.js";
|
5
5
|
import type { Actor, Recipient } from "../vocab/actor.js";
|
6
|
-
import {
|
7
|
-
import
|
8
|
-
import type {
|
6
|
+
import { type LookupObjectOptions } from "../vocab/lookup.js";
|
7
|
+
import { Activity, type Hashtag, type Like, type Object } from "../vocab/vocab.js";
|
8
|
+
import type { ActorDispatcher, ActorHandleMapper, ActorKeyPairsDispatcher, AuthorizePredicate, CollectionDispatcher, InboxErrorHandler, NodeInfoDispatcher, ObjectAuthorizePredicate, ObjectDispatcher, OutboxErrorHandler, SharedInboxKeyDispatcher } from "./callback.js";
|
9
|
+
import type { ActorKeyPair, Context, ForwardActivityOptions, InboxContext, ParseUriResult, RequestContext, SendActivityOptions } from "./context.js";
|
10
|
+
import type { ActorCallbackSetters, CollectionCallbackSetters, Federation, FederationFetchOptions, InboxListenerSetters, ObjectCallbackSetters } from "./federation.js";
|
11
|
+
import { type CollectionCallbacks } from "./handler.js";
|
12
|
+
import { InboxListenerSet } from "./inbox.js";
|
9
13
|
import type { KvKey, KvStore } from "./kv.js";
|
10
14
|
import type { MessageQueue } from "./mq.js";
|
11
15
|
import { type RetryPolicy } from "./retry.js";
|
16
|
+
import { Router } from "./router.js";
|
17
|
+
import { type SenderKeyPair } from "./send.js";
|
12
18
|
/**
|
13
19
|
* Options for {@link createFederation} function.
|
14
20
|
* @since 0.10.0
|
@@ -141,465 +147,158 @@ export interface FederationKvPrefixes {
|
|
141
147
|
publicKey: KvKey;
|
142
148
|
}
|
143
149
|
/**
|
144
|
-
*
|
145
|
-
*
|
146
|
-
*
|
147
|
-
*
|
148
|
-
* web framework's router; see {@link Federation.fetch}.
|
149
|
-
*
|
150
|
-
* @since 0.13.0
|
150
|
+
* Create a new {@link Federation} instance.
|
151
|
+
* @param parameters Parameters for initializing the instance.
|
152
|
+
* @returns A new {@link Federation} instance.
|
153
|
+
* @since 0.10.0
|
151
154
|
*/
|
152
|
-
export
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
155
|
+
export declare function createFederation<TContextData>(options: CreateFederationOptions): Federation<TContextData>;
|
156
|
+
export declare class FederationImpl<TContextData> implements Federation<TContextData> {
|
157
|
+
#private;
|
158
|
+
kv: KvStore;
|
159
|
+
kvPrefixes: FederationKvPrefixes;
|
160
|
+
queue?: MessageQueue;
|
161
|
+
queueStarted: boolean;
|
162
|
+
manuallyStartQueue: boolean;
|
163
|
+
router: Router;
|
164
|
+
nodeInfoDispatcher?: NodeInfoDispatcher<TContextData>;
|
165
|
+
actorCallbacks?: ActorCallbacks<TContextData>;
|
166
|
+
objectCallbacks: Record<string, ObjectCallbacks<TContextData, string>>;
|
167
|
+
objectTypeIds: Record<string, (new (...args: any[]) => Object) & {
|
168
|
+
typeId: URL;
|
169
|
+
}>;
|
170
|
+
inboxPath?: string;
|
171
|
+
inboxCallbacks?: CollectionCallbacks<Activity, RequestContext<TContextData>, TContextData, void>;
|
172
|
+
outboxCallbacks?: CollectionCallbacks<Activity, RequestContext<TContextData>, TContextData, void>;
|
173
|
+
followingCallbacks?: CollectionCallbacks<Actor | URL, RequestContext<TContextData>, TContextData, void>;
|
174
|
+
followersCallbacks?: CollectionCallbacks<Recipient, Context<TContextData>, TContextData, URL>;
|
175
|
+
likedCallbacks?: CollectionCallbacks<Like, RequestContext<TContextData>, TContextData, void>;
|
176
|
+
featuredCallbacks?: CollectionCallbacks<Object, RequestContext<TContextData>, TContextData, void>;
|
177
|
+
featuredTagsCallbacks?: CollectionCallbacks<Hashtag, RequestContext<TContextData>, TContextData, void>;
|
178
|
+
inboxListeners?: InboxListenerSet<TContextData>;
|
179
|
+
inboxErrorHandler?: InboxErrorHandler<TContextData>;
|
180
|
+
sharedInboxKeyDispatcher?: SharedInboxKeyDispatcher<TContextData>;
|
181
|
+
documentLoader: DocumentLoader;
|
182
|
+
contextLoader: DocumentLoader;
|
183
|
+
authenticatedDocumentLoaderFactory: AuthenticatedDocumentLoaderFactory;
|
184
|
+
onOutboxError?: OutboxErrorHandler;
|
185
|
+
signatureTimeWindow: dntShim.Temporal.DurationLike | false;
|
186
|
+
skipSignatureVerification: boolean;
|
187
|
+
outboxRetryPolicy: RetryPolicy;
|
188
|
+
inboxRetryPolicy: RetryPolicy;
|
189
|
+
constructor(options: CreateFederationOptions);
|
160
190
|
startQueue(contextData: TContextData): Promise<void>;
|
161
|
-
/**
|
162
|
-
* Create a new context.
|
163
|
-
* @param baseUrl The base URL of the server. The `pathname` remains root,
|
164
|
-
* and the `search` and `hash` are stripped.
|
165
|
-
* @param contextData The context data to pass to the context.
|
166
|
-
* @returns The new context.
|
167
|
-
*/
|
168
191
|
createContext(baseUrl: URL, contextData: TContextData): Context<TContextData>;
|
169
|
-
/**
|
170
|
-
* Create a new context for a request.
|
171
|
-
* @param request The request object.
|
172
|
-
* @param contextData The context data to pass to the context.
|
173
|
-
* @returns The new request context.
|
174
|
-
*/
|
175
192
|
createContext(request: Request, contextData: TContextData): RequestContext<TContextData>;
|
176
|
-
/**
|
177
|
-
* Registers a NodeInfo dispatcher.
|
178
|
-
* @param path The URI path pattern for the NodeInfo dispatcher. The syntax
|
179
|
-
* is based on URI Template
|
180
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
181
|
-
* must have no variables.
|
182
|
-
* @param dispatcher A NodeInfo dispatcher callback to register.
|
183
|
-
* @throws {RouterError} Thrown if the path pattern is invalid.
|
184
|
-
*/
|
185
193
|
setNodeInfoDispatcher(path: string, dispatcher: NodeInfoDispatcher<TContextData>): void;
|
186
|
-
/**
|
187
|
-
* Registers an actor dispatcher.
|
188
|
-
*
|
189
|
-
* @example
|
190
|
-
* ``` typescript
|
191
|
-
* federation.setActorDispatcher(
|
192
|
-
* "/users/{handle}",
|
193
|
-
* async (ctx, handle) => {
|
194
|
-
* return new Person({
|
195
|
-
* id: ctx.getActorUri(handle),
|
196
|
-
* preferredUsername: handle,
|
197
|
-
* // ...
|
198
|
-
* });
|
199
|
-
* }
|
200
|
-
* );
|
201
|
-
* ```
|
202
|
-
*
|
203
|
-
* @param path The URI path pattern for the actor dispatcher. The syntax is
|
204
|
-
* based on URI Template
|
205
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
206
|
-
* must have one variable: `{handle}`.
|
207
|
-
* @param dispatcher An actor dispatcher callback to register.
|
208
|
-
* @returns An object with methods to set other actor dispatcher callbacks.
|
209
|
-
* @throws {RouterError} Thrown if the path pattern is invalid.
|
210
|
-
*/
|
211
194
|
setActorDispatcher(path: `${string}{handle}${string}`, dispatcher: ActorDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
|
212
|
-
/**
|
213
|
-
* Registers an object dispatcher.
|
214
|
-
*
|
215
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
216
|
-
* @typeParam TObject The type of object to dispatch.
|
217
|
-
* @typeParam TParam The parameter names of the requested URL.
|
218
|
-
* @param cls The Activity Vocabulary class of the object to dispatch.
|
219
|
-
* @param path The URI path pattern for the object dispatcher. The syntax is
|
220
|
-
* based on URI Template
|
221
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
222
|
-
* must have one or more variables.
|
223
|
-
* @param dispatcher An object dispatcher callback to register.
|
224
|
-
*/
|
225
195
|
setObjectDispatcher<TObject extends Object, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
226
196
|
typeId: URL;
|
227
197
|
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
228
|
-
/**
|
229
|
-
* Registers an object dispatcher.
|
230
|
-
*
|
231
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
232
|
-
* @typeParam TObject The type of object to dispatch.
|
233
|
-
* @typeParam TParam The parameter names of the requested URL.
|
234
|
-
* @param cls The Activity Vocabulary class of the object to dispatch.
|
235
|
-
* @param path The URI path pattern for the object dispatcher. The syntax is
|
236
|
-
* based on URI Template
|
237
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
238
|
-
* must have one or more variables.
|
239
|
-
* @param dispatcher An object dispatcher callback to register.
|
240
|
-
*/
|
241
198
|
setObjectDispatcher<TObject extends Object, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
242
199
|
typeId: URL;
|
243
200
|
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
244
|
-
/**
|
245
|
-
* Registers an object dispatcher.
|
246
|
-
*
|
247
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
248
|
-
* @typeParam TObject The type of object to dispatch.
|
249
|
-
* @typeParam TParam The parameter names of the requested URL.
|
250
|
-
* @param cls The Activity Vocabulary class of the object to dispatch.
|
251
|
-
* @param path The URI path pattern for the object dispatcher. The syntax is
|
252
|
-
* based on URI Template
|
253
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
254
|
-
* must have one or more variables.
|
255
|
-
* @param dispatcher An object dispatcher callback to register.
|
256
|
-
*/
|
257
201
|
setObjectDispatcher<TObject extends Object, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
258
202
|
typeId: URL;
|
259
203
|
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
260
|
-
/**
|
261
|
-
* Registers an object dispatcher.
|
262
|
-
*
|
263
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
264
|
-
* @typeParam TObject The type of object to dispatch.
|
265
|
-
* @typeParam TParam The parameter names of the requested URL.
|
266
|
-
* @param cls The Activity Vocabulary class of the object to dispatch.
|
267
|
-
* @param path The URI path pattern for the object dispatcher. The syntax is
|
268
|
-
* based on URI Template
|
269
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
270
|
-
* must have one or more variables.
|
271
|
-
* @param dispatcher An object dispatcher callback to register.
|
272
|
-
*/
|
273
204
|
setObjectDispatcher<TObject extends Object, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
274
205
|
typeId: URL;
|
275
206
|
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
276
|
-
/**
|
277
|
-
* Registers an object dispatcher.
|
278
|
-
*
|
279
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
280
|
-
* @typeParam TObject The type of object to dispatch.
|
281
|
-
* @typeParam TParam The parameter names of the requested URL.
|
282
|
-
* @param cls The Activity Vocabulary class of the object to dispatch.
|
283
|
-
* @param path The URI path pattern for the object dispatcher. The syntax is
|
284
|
-
* based on URI Template
|
285
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
286
|
-
* must have one or more variables.
|
287
|
-
* @param dispatcher An object dispatcher callback to register.
|
288
|
-
*/
|
289
207
|
setObjectDispatcher<TObject extends Object, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
290
208
|
typeId: URL;
|
291
209
|
}, path: `${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
292
|
-
/**
|
293
|
-
* Registers an object dispatcher.
|
294
|
-
*
|
295
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
296
|
-
* @typeParam TObject The type of object to dispatch.
|
297
|
-
* @typeParam TParam The parameter names of the requested URL.
|
298
|
-
* @param cls The Activity Vocabulary class of the object to dispatch.
|
299
|
-
* @param path The URI path pattern for the object dispatcher. The syntax is
|
300
|
-
* based on URI Template
|
301
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
302
|
-
* must have one or more variables.
|
303
|
-
* @param dispatcher An object dispatcher callback to register.
|
304
|
-
*/
|
305
210
|
setObjectDispatcher<TObject extends Object, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
306
211
|
typeId: URL;
|
307
212
|
}, path: `${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
308
|
-
/**
|
309
|
-
* Registers an inbox dispatcher.
|
310
|
-
*
|
311
|
-
* @param path The URI path pattern for the outbox dispatcher. The syntax is
|
312
|
-
* based on URI Template
|
313
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
314
|
-
* must have one variable: `{handle}`, and must match the inbox
|
315
|
-
* listener path.
|
316
|
-
* @param dispatcher An inbox dispatcher callback to register.
|
317
|
-
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
318
|
-
*/
|
319
213
|
setInboxDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
320
|
-
/**
|
321
|
-
* Registers an outbox dispatcher.
|
322
|
-
*
|
323
|
-
* @example
|
324
|
-
* ``` typescript
|
325
|
-
* federation.setOutboxDispatcher(
|
326
|
-
* "/users/{handle}/outbox",
|
327
|
-
* async (ctx, handle, options) => {
|
328
|
-
* let items: Activity[];
|
329
|
-
* let nextCursor: string;
|
330
|
-
* // ...
|
331
|
-
* return { items, nextCursor };
|
332
|
-
* }
|
333
|
-
* );
|
334
|
-
* ```
|
335
|
-
*
|
336
|
-
* @param path The URI path pattern for the outbox dispatcher. The syntax is
|
337
|
-
* based on URI Template
|
338
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
339
|
-
* must have one variable: `{handle}`.
|
340
|
-
* @param dispatcher An outbox dispatcher callback to register.
|
341
|
-
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
342
|
-
*/
|
343
214
|
setOutboxDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
344
|
-
/**
|
345
|
-
* Registers a following collection dispatcher.
|
346
|
-
* @param path The URI path pattern for the following collection. The syntax
|
347
|
-
* is based on URI Template
|
348
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
349
|
-
* must have one variable: `{handle}`.
|
350
|
-
* @param dispatcher A following collection callback to register.
|
351
|
-
* @returns An object with methods to set other following collection
|
352
|
-
* callbacks.
|
353
|
-
* @throws {RouterError} Thrown if the path pattern is invalid.
|
354
|
-
*/
|
355
215
|
setFollowingDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Actor | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
356
|
-
/**
|
357
|
-
* Registers a followers collection dispatcher.
|
358
|
-
* @param path The URI path pattern for the followers collection. The syntax
|
359
|
-
* is based on URI Template
|
360
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
361
|
-
* must have one variable: `{handle}`.
|
362
|
-
* @param dispatcher A followers collection callback to register.
|
363
|
-
* @returns An object with methods to set other followers collection
|
364
|
-
* callbacks.
|
365
|
-
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
366
|
-
*/
|
367
216
|
setFollowersDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Recipient, Context<TContextData>, TContextData, URL>): CollectionCallbackSetters<Context<TContextData>, TContextData, URL>;
|
368
|
-
|
369
|
-
* Registers a liked collection dispatcher.
|
370
|
-
* @param path The URI path pattern for the liked collection. The syntax
|
371
|
-
* is based on URI Template
|
372
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
373
|
-
* must have one variable: `{handle}`.
|
374
|
-
* @param dispatcher A liked collection callback to register.
|
375
|
-
* @returns An object with methods to set other liked collection
|
376
|
-
* callbacks.
|
377
|
-
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
378
|
-
*/
|
379
|
-
setLikedDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Object | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
380
|
-
/**
|
381
|
-
* Registers a featured collection dispatcher.
|
382
|
-
* @param path The URI path pattern for the featured collection. The syntax
|
383
|
-
* is based on URI Template
|
384
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
385
|
-
* must have one variable: `{handle}`.
|
386
|
-
* @param dispatcher A featured collection callback to register.
|
387
|
-
* @returns An object with methods to set other featured collection
|
388
|
-
* callbacks.
|
389
|
-
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
390
|
-
*/
|
217
|
+
setLikedDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Like, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
391
218
|
setFeaturedDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Object, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
392
|
-
/**
|
393
|
-
* Registers a featured tags collection dispatcher.
|
394
|
-
* @param path The URI path pattern for the featured tags collection.
|
395
|
-
* The syntax is based on URI Template
|
396
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
397
|
-
* must have one variable: `{handle}`.
|
398
|
-
* @param dispatcher A featured tags collection callback to register.
|
399
|
-
* @returns An object with methods to set other featured tags collection
|
400
|
-
* callbacks.
|
401
|
-
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
402
|
-
*/
|
403
219
|
setFeaturedTagsDispatcher(path: `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Hashtag, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
404
|
-
/**
|
405
|
-
* Assigns the URL path for the inbox and starts setting inbox listeners.
|
406
|
-
*
|
407
|
-
* @example
|
408
|
-
* ``` typescript
|
409
|
-
* federation
|
410
|
-
* .setInboxListeners("/users/{handle/inbox", "/inbox")
|
411
|
-
* .on(Follow, async (ctx, follow) => {
|
412
|
-
* const from = await follow.getActor(ctx);
|
413
|
-
* if (!isActor(from)) return;
|
414
|
-
* // ...
|
415
|
-
* await ctx.sendActivity({ })
|
416
|
-
* })
|
417
|
-
* .on(Undo, async (ctx, undo) => {
|
418
|
-
* // ...
|
419
|
-
* });
|
420
|
-
* ```
|
421
|
-
*
|
422
|
-
* @param inboxPath The URI path pattern for the inbox. The syntax is based
|
423
|
-
* on URI Template
|
424
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
425
|
-
* The path must have one variable: `{handle}`, and must
|
426
|
-
* match the inbox dispatcher path.
|
427
|
-
* @param sharedInboxPath An optional URI path pattern for the shared inbox.
|
428
|
-
* The syntax is based on URI Template
|
429
|
-
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
430
|
-
* The path must have no variables.
|
431
|
-
* @returns An object to register inbox listeners.
|
432
|
-
* @throws {RouteError} Thrown if the path pattern is invalid.
|
433
|
-
*/
|
434
220
|
setInboxListeners(inboxPath: `${string}{handle}${string}`, sharedInboxPath?: string): InboxListenerSetters<TContextData>;
|
435
|
-
|
436
|
-
* Handles a request related to federation. If a request is not related to
|
437
|
-
* federation, the `onNotFound` or `onNotAcceptable` callback is called.
|
438
|
-
*
|
439
|
-
* Usually, this method is called from a server's request handler or
|
440
|
-
* a web framework's middleware.
|
441
|
-
*
|
442
|
-
* @param request The request object.
|
443
|
-
* @param parameters The parameters for handling the request.
|
444
|
-
* @returns The response to the request.
|
445
|
-
*/
|
221
|
+
sendActivity(keys: SenderKeyPair[], recipients: Recipient | Recipient[], activity: Activity, options: SendActivityInternalOptions<TContextData>): Promise<void>;
|
446
222
|
fetch(request: Request, options: FederationFetchOptions<TContextData>): Promise<Response>;
|
447
223
|
}
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
* Parameters of {@link Federation.fetch} method.
|
457
|
-
*
|
458
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
459
|
-
* @since 0.6.0
|
460
|
-
*/
|
461
|
-
export interface FederationFetchOptions<TContextData> {
|
462
|
-
/**
|
463
|
-
* The context data to pass to the {@link Context}.
|
464
|
-
*/
|
465
|
-
contextData: TContextData;
|
466
|
-
/**
|
467
|
-
* A callback to handle a request when the route is not found.
|
468
|
-
* If not provided, a 404 response is returned.
|
469
|
-
* @param request The request object.
|
470
|
-
* @returns The response to the request.
|
471
|
-
*/
|
472
|
-
onNotFound?: (request: Request) => Response | Promise<Response>;
|
473
|
-
/**
|
474
|
-
* A callback to handle a request when the request's `Accept` header is not
|
475
|
-
* acceptable. If not provided, a 406 response is returned.
|
476
|
-
* @param request The request object.
|
477
|
-
* @returns The response to the request.
|
478
|
-
*/
|
479
|
-
onNotAcceptable?: (request: Request) => Response | Promise<Response>;
|
480
|
-
/**
|
481
|
-
* A callback to handle a request when the request is unauthorized.
|
482
|
-
* If not provided, a 401 response is returned.
|
483
|
-
* @param request The request object.
|
484
|
-
* @returns The response to the request.
|
485
|
-
* @since 0.7.0
|
486
|
-
*/
|
487
|
-
onUnauthorized?: (request: Request) => Response | Promise<Response>;
|
224
|
+
interface ContextOptions<TContextData> {
|
225
|
+
url: URL;
|
226
|
+
federation: FederationImpl<TContextData>;
|
227
|
+
data: TContextData;
|
228
|
+
documentLoader: DocumentLoader;
|
229
|
+
invokedFromActorKeyPairsDispatcher?: {
|
230
|
+
handle: string;
|
231
|
+
};
|
488
232
|
}
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
233
|
+
declare class ContextImpl<TContextData> implements Context<TContextData> {
|
234
|
+
readonly url: URL;
|
235
|
+
readonly federation: FederationImpl<TContextData>;
|
236
|
+
readonly data: TContextData;
|
237
|
+
readonly documentLoader: DocumentLoader;
|
238
|
+
readonly invokedFromActorKeyPairsDispatcher?: {
|
239
|
+
handle: string;
|
240
|
+
};
|
241
|
+
constructor({ url, federation, data, documentLoader, invokedFromActorKeyPairsDispatcher, }: ContextOptions<TContextData>);
|
242
|
+
toInboxContext(activity: unknown): InboxContextImpl<TContextData>;
|
243
|
+
get hostname(): string;
|
244
|
+
get host(): string;
|
245
|
+
get origin(): string;
|
246
|
+
get contextLoader(): DocumentLoader;
|
247
|
+
getNodeInfoUri(): URL;
|
248
|
+
getActorUri(handle: string): URL;
|
249
|
+
getObjectUri<TObject extends Object>(cls: (new (...args: any[]) => TObject) & {
|
250
|
+
typeId: URL;
|
251
|
+
}, values: Record<string, string>): URL;
|
252
|
+
getOutboxUri(handle: string): URL;
|
253
|
+
getInboxUri(): URL;
|
254
|
+
getInboxUri(handle: string): URL;
|
255
|
+
getFollowingUri(handle: string): URL;
|
256
|
+
getFollowersUri(handle: string): URL;
|
257
|
+
getLikedUri(handle: string): URL;
|
258
|
+
getFeaturedUri(handle: string): URL;
|
259
|
+
getFeaturedTagsUri(handle: string): URL;
|
260
|
+
parseUri(uri: URL): ParseUriResult | null;
|
261
|
+
getActorKeyPairs(handle: string): Promise<ActorKeyPair[]>;
|
262
|
+
protected getKeyPairsFromHandle(handle: string): Promise<(dntShim.CryptoKeyPair & {
|
263
|
+
keyId: URL;
|
264
|
+
})[]>;
|
265
|
+
protected getRsaKeyPairFromHandle(handle: string): Promise<dntShim.CryptoKeyPair & {
|
266
|
+
keyId: URL;
|
267
|
+
} | null>;
|
268
|
+
getDocumentLoader(identity: {
|
269
|
+
handle: string;
|
270
|
+
}): Promise<DocumentLoader>;
|
271
|
+
getDocumentLoader(identity: SenderKeyPair): DocumentLoader;
|
272
|
+
lookupObject(identifier: string | URL, options?: LookupObjectOptions): Promise<Object | null>;
|
273
|
+
sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
|
274
|
+
handle: string;
|
275
|
+
}, recipients: Recipient | Recipient[] | "followers", activity: Activity, options?: SendActivityOptions): Promise<void>;
|
276
|
+
getFollowers(handle: string): AsyncIterable<Recipient>;
|
526
277
|
}
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
*/
|
537
|
-
authorize(predicate: ObjectAuthorizePredicate<TContextData, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
278
|
+
export declare class InboxContextImpl<TContextData> extends ContextImpl<TContextData> implements InboxContext<TContextData> {
|
279
|
+
readonly activity: unknown;
|
280
|
+
constructor(activity: unknown, options: ContextOptions<TContextData>);
|
281
|
+
forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
|
282
|
+
handle: string;
|
283
|
+
}, recipients: Recipient | Recipient[], options?: ForwardActivityOptions): Promise<void>;
|
284
|
+
forwardActivity(forwarder: {
|
285
|
+
handle: string;
|
286
|
+
}, recipients: "followers", options?: ForwardActivityOptions): Promise<void>;
|
538
287
|
}
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
* @typeParam TContextData The context data to pass to the {@link Context}.
|
545
|
-
* @typeParam TFilter The type of filter for the collection.
|
546
|
-
*/
|
547
|
-
export interface CollectionCallbackSetters<TContext extends Context<TContextData>, TContextData, TFilter> {
|
548
|
-
/**
|
549
|
-
* Sets the counter for the collection.
|
550
|
-
* @param counter A callback that returns the number of items in the collection.
|
551
|
-
* @returns The setters object so that settings can be chained.
|
552
|
-
*/
|
553
|
-
setCounter(counter: CollectionCounter<TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
554
|
-
/**
|
555
|
-
* Sets the first cursor for the collection.
|
556
|
-
* @param cursor The cursor for the first item in the collection.
|
557
|
-
* @returns The setters object so that settings can be chained.
|
558
|
-
*/
|
559
|
-
setFirstCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
560
|
-
/**
|
561
|
-
* Sets the last cursor for the collection.
|
562
|
-
* @param cursor The cursor for the last item in the collection.
|
563
|
-
* @returns The setters object so that settings can be chained.
|
564
|
-
*/
|
565
|
-
setLastCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
566
|
-
/**
|
567
|
-
* Specifies the conditions under which requests are authorized.
|
568
|
-
* @param predicate A callback that returns whether a request is authorized.
|
569
|
-
* @returns The setters object so that settings can be chained.
|
570
|
-
* @since 0.7.0
|
571
|
-
*/
|
572
|
-
authorize(predicate: AuthorizePredicate<TContextData>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
288
|
+
interface ActorCallbacks<TContextData> {
|
289
|
+
dispatcher?: ActorDispatcher<TContextData>;
|
290
|
+
keyPairsDispatcher?: ActorKeyPairsDispatcher<TContextData>;
|
291
|
+
handleMapper?: ActorHandleMapper<TContextData>;
|
292
|
+
authorizePredicate?: AuthorizePredicate<TContextData>;
|
573
293
|
}
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
* @param listener A callback to handle an incoming activity.
|
583
|
-
* @returns The setters object so that settings can be chained.
|
584
|
-
*/
|
585
|
-
on<TActivity extends Activity>(type: new (...args: any[]) => TActivity, listener: InboxListener<TContextData, TActivity>): InboxListenerSetters<TContextData>;
|
586
|
-
/**
|
587
|
-
* Registers an error handler for inbox listeners. Any exceptions thrown
|
588
|
-
* from the listeners are caught and passed to this handler.
|
589
|
-
*
|
590
|
-
* @param handler A callback to handle an error.
|
591
|
-
* @returns The setters object so that settings can be chained.
|
592
|
-
*/
|
593
|
-
onError(handler: InboxErrorHandler<TContextData>): InboxListenerSetters<TContextData>;
|
594
|
-
/**
|
595
|
-
* Configures a callback to dispatch the key pair for the authenticated
|
596
|
-
* document loader of the {@link Context} passed to the shared inbox listener.
|
597
|
-
*
|
598
|
-
* @param dispatcher A callback to dispatch the key pair for the authenticated
|
599
|
-
* document loader.
|
600
|
-
* @returns The setters object so that settings can be chained.
|
601
|
-
* @since 0.11.0
|
602
|
-
*/
|
603
|
-
setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
|
294
|
+
interface ObjectCallbacks<TContextData, TParam extends string> {
|
295
|
+
dispatcher: ObjectDispatcher<TContextData, Object, string>;
|
296
|
+
parameters: Set<TParam>;
|
297
|
+
authorizePredicate?: ObjectAuthorizePredicate<TContextData, TParam>;
|
298
|
+
}
|
299
|
+
interface SendActivityInternalOptions<TContextData> extends SendActivityOptions {
|
300
|
+
collectionSync?: string;
|
301
|
+
contextData: TContextData;
|
604
302
|
}
|
303
|
+
export {};
|
605
304
|
//# sourceMappingURL=middleware.d.ts.map
|