@fedify/fedify 1.9.0-pr.428.1588 → 1.9.0-pr.431.1597
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.
- package/dist/actor-CHOM_AN3.d.cts +128 -0
- package/dist/actor-CfaqWvJb.cjs +37783 -0
- package/dist/{actor-CdM_sJLC.js → actor-Detmisdi.js} +190 -190
- package/dist/{actor-ByOSf9n9.js → actor-Dw7av4Zk.js} +1 -1
- package/dist/{authdocloader-VVd0U8Qg.js → authdocloader-5UJ5Gme-.js} +6 -6
- package/dist/authdocloader-BVYv0Ct8.cjs +58 -0
- package/dist/{authdocloader-CfP6lfxM.js → authdocloader-ZlLoXSxM.js} +3 -3
- package/dist/{builder-mfXmda-W.js → builder-BbKfqPmR.js} +4 -4
- package/dist/chunk-DqRYRqnO.cjs +34 -0
- package/dist/{client-DB8N2RwI.js → client-DgRjF0ha.js} +1 -1
- package/dist/client-DjT_tegg.d.cts +294 -0
- package/dist/compat/mod.cjs +10 -0
- package/dist/compat/mod.d.cts +13 -0
- package/dist/compat/mod.js +5 -5
- package/dist/compat/transformers.test.js +16 -16
- package/dist/compat-DmDDELst.cjs +4 -0
- package/dist/compat-nxUqe4Z-.js +4 -0
- package/dist/context-KXVF2AhH.d.cts +2261 -0
- package/dist/{docloader-XJzCMWY-.js → docloader-BKf9RWX4.js} +4 -4
- package/dist/docloader-D-MrRyHl.d.cts +219 -0
- package/dist/docloader-eqgyMp7h.cjs +4682 -0
- package/dist/{esm-BVYQVacR.js → esm-B_ZjJ1sB.js} +1 -1
- package/dist/federation/builder.test.js +5 -5
- package/dist/federation/collection.test.js +3 -3
- package/dist/federation/handler.test.js +17 -17
- package/dist/federation/inbox.test.js +4 -4
- package/dist/federation/keycache.test.js +4 -4
- package/dist/federation/kv.test.js +3 -3
- package/dist/federation/middleware.test.js +18 -18
- package/dist/federation/mod.cjs +29 -0
- package/dist/federation/mod.d.cts +13 -0
- package/dist/federation/mod.js +15 -15
- package/dist/federation/mq.test.js +3 -3
- package/dist/federation/retry.test.js +3 -3
- package/dist/federation/router.test.js +3 -3
- package/dist/federation/send.test.js +10 -10
- package/dist/{federation-CMX7WzeL.js → federation-D1U8YY9t.js} +3 -3
- package/dist/federation-H2_En3j5.cjs +244 -0
- package/dist/http-B_zBcsai.d.cts +253 -0
- package/dist/{http-B_bBrm6N.js → http-C5XLveZw.js} +2 -2
- package/dist/{http-DYB4M8Pr.js → http-CwlUFNG4.js} +6 -6
- package/dist/http-_vjuGcXn.cjs +826 -0
- package/dist/{inbox-B4k2JQpE.js → inbox-sVXiVBbT.js} +1 -1
- package/dist/key-19P2dWvf.cjs +290 -0
- package/dist/{key-BdBFUTr5.js → key-BCWvPOkD.js} +5 -5
- package/dist/key-CsQ7J8-m.js +10 -0
- package/dist/key-Dt7qJaQT.cjs +10 -0
- package/dist/{key-feGm-IP3.js → key-Jrnr66vx.js} +2 -2
- package/dist/{key-BcVEPl--.js → key-lpATOAE4.js} +3 -3
- package/dist/{keycache-b7FYgzB9.js → keycache-ogQInQck.js} +1 -1
- package/dist/{keys-B7uX1KoX.js → keys-DcGsKtHW.js} +1 -1
- package/dist/kv-63Cil1MD.d.cts +81 -0
- package/dist/{ld-DJCemZO2.js → ld-BSE4jnyK.js} +2 -2
- package/dist/lookup-D96ipStp.cjs +137 -0
- package/dist/{lookup-CIsbr_Qi.js → lookup-D_-F1hLw.js} +4 -4
- package/dist/{lookup-CXaZBmuy.js → lookup-DdxOle8f.js} +1 -1
- package/dist/middleware-B0f850Ei.cjs +17 -0
- package/dist/middleware-B2DFqtJ-.cjs +4240 -0
- package/dist/middleware-COHAbwGs.js +17 -0
- package/dist/{middleware-D5JRdsEc.js → middleware-CuTcPjfP.js} +13 -13
- package/dist/middleware-Dt7C7qpw.js +26 -0
- package/dist/{middleware-e_Gw7sQy.js → middleware-T_y4Bnvw.js} +14 -14
- package/dist/mod-C2tOeRkN.d.cts +1 -0
- package/dist/mod-C3CGxYoF.d.cts +102 -0
- package/dist/mod-COw_caPC.d.cts +266 -0
- package/dist/mod-FZd39qVq.d.cts +1 -0
- package/dist/mod-NKH_G-IY.d.cts +289 -0
- package/dist/mod-YfAcrVbP.d.cts +80 -0
- package/dist/mod-jQ4OODsl.d.cts +113 -0
- package/dist/mod.cjs +152 -0
- package/dist/mod.d.cts +17 -0
- package/dist/mod.js +20 -20
- package/dist/mq-B7R1Q-M5.d.cts +140 -0
- package/dist/nodeinfo/client.test.js +5 -5
- package/dist/nodeinfo/handler.test.js +16 -16
- package/dist/nodeinfo/mod.cjs +13 -0
- package/dist/nodeinfo/mod.d.cts +5 -0
- package/dist/nodeinfo/mod.js +6 -6
- package/dist/nodeinfo/semver.test.js +3 -3
- package/dist/nodeinfo/types.test.js +3 -3
- package/dist/nodeinfo-Co9lJrWl.cjs +4 -0
- package/dist/nodeinfo-DfycQ8Wf.js +4 -0
- package/dist/owner-C9Ry0TOI.d.cts +67 -0
- package/dist/{owner-i9FkgZwa.js → owner-DJtc8evi.js} +2 -2
- package/dist/{proof-Bvtdd-Ul.js → proof-9OMp0o4n.js} +2 -2
- package/dist/{proof-DKGUTtBt.js → proof-BuPk23Er.js} +6 -6
- package/dist/proof-CRHppbRk.cjs +673 -0
- package/dist/runtime/authdocloader.test.js +9 -9
- package/dist/runtime/docloader.test.js +4 -4
- package/dist/runtime/key.test.js +5 -5
- package/dist/runtime/langstr.test.js +3 -3
- package/dist/runtime/mod.cjs +25 -0
- package/dist/runtime/mod.d.cts +6 -0
- package/dist/runtime/mod.js +10 -10
- package/dist/runtime/multibase/multibase.test.js +3 -3
- package/dist/runtime/url.test.js +3 -3
- package/dist/runtime-C58AJWSv.cjs +4 -0
- package/dist/runtime-DPYEDf-o.js +4 -0
- package/dist/{send-Cuw-wTCx.js → send-cXerEJm9.js} +2 -2
- package/dist/sig/http.test.js +8 -8
- package/dist/sig/key.test.js +6 -6
- package/dist/sig/ld.test.js +7 -7
- package/dist/sig/mod.cjs +30 -0
- package/dist/sig/mod.d.cts +8 -0
- package/dist/sig/mod.js +10 -10
- package/dist/sig/owner.test.js +7 -7
- package/dist/sig/proof.test.js +7 -7
- package/dist/sig-ByHXzqUi.cjs +4 -0
- package/dist/sig-Cj3tk-ig.js +4 -0
- package/dist/testing/docloader.test.js +3 -3
- package/dist/testing/mod.js +3 -3
- package/dist/{testing-DUFWSgSt.js → testing-BX6IA3LR.js} +2 -2
- package/dist/{transformers-Dna8Fg7k.js → transformers-BFT6d7J5.js} +3 -3
- package/dist/transformers-CoBS-oFG.cjs +116 -0
- package/dist/{type-DDwsy8fI.js → type-DF9yoIpt.js} +186 -186
- package/dist/types-DcKQIzdO.cjs +488 -0
- package/dist/{types-CuvNqe2X.js → types-Q17QxOOC.js} +4 -4
- package/dist/vocab/actor.test.js +5 -5
- package/dist/vocab/lookup.test.js +4 -4
- package/dist/vocab/mod.cjs +87 -0
- package/dist/vocab/mod.d.cts +6 -0
- package/dist/vocab/mod.js +7 -7
- package/dist/vocab/type.test.js +3 -3
- package/dist/vocab/vocab.test.js +4 -4
- package/dist/{vocab-CEXwobaS.js → vocab-BUc_4ZsW.js} +6 -6
- package/dist/vocab-BzGg7ltX.d.cts +14629 -0
- package/dist/vocab-Du8FV6H1.cjs +282 -0
- package/dist/webfinger/handler.test.js +16 -16
- package/dist/webfinger/lookup.test.js +4 -4
- package/dist/webfinger/mod.cjs +9 -0
- package/dist/webfinger/mod.d.cts +4 -0
- package/dist/webfinger/mod.js +6 -6
- package/dist/webfinger-BjOEdFPs.cjs +4 -0
- package/dist/webfinger-De_bU0iE.js +4 -0
- package/dist/x/cfworkers.cjs +100 -0
- package/dist/x/cfworkers.d.cts +59 -0
- package/dist/x/cfworkers.js +3 -3
- package/dist/x/cfworkers.test.js +3 -3
- package/dist/x/hono.cjs +61 -0
- package/dist/x/hono.d.cts +54 -0
- package/dist/x/hono.js +3 -3
- package/dist/x/sveltekit.cjs +69 -0
- package/dist/x/sveltekit.d.cts +46 -0
- package/dist/x/sveltekit.js +3 -3
- package/package.json +68 -12
- package/dist/compat-Bb5myD13.js +0 -4
- package/dist/key-0hFXQUQz.js +0 -10
- package/dist/middleware-BhQdOVAF.js +0 -17
- package/dist/middleware-DVy3ms0C.js +0 -26
- package/dist/nodeinfo-CyEbLjHs.js +0 -4
- package/dist/runtime-BSkOVUWM.js +0 -4
- package/dist/sig-BXJO--F9.js +0 -4
- package/dist/webfinger-C3GIyXIg.js +0 -4
@@ -0,0 +1,2261 @@
|
|
1
|
+
import { KvKey, KvStore } from "./kv-63Cil1MD.cjs";
|
2
|
+
import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "./docloader-D-MrRyHl.cjs";
|
3
|
+
import { GetNodeInfoOptions, JsonValue, NodeInfo } from "./client-DjT_tegg.cjs";
|
4
|
+
import { Activity, Collection, CryptographicKey, Hashtag, Link, Multikey, Object as Object$1 } from "./vocab-BzGg7ltX.cjs";
|
5
|
+
import { Actor, Recipient } from "./actor-CHOM_AN3.cjs";
|
6
|
+
import { HttpMessageSignaturesSpec } from "./http-B_zBcsai.cjs";
|
7
|
+
import { GetKeyOwnerOptions } from "./owner-C9Ry0TOI.cjs";
|
8
|
+
import { LookupObjectOptions, TraverseCollectionOptions } from "./mod-NKH_G-IY.cjs";
|
9
|
+
import { Link as Link$1, LookupWebFingerOptions, ResourceDescriptor } from "./mod-jQ4OODsl.cjs";
|
10
|
+
import { MessageQueue } from "./mq-B7R1Q-M5.cjs";
|
11
|
+
import { Span, TracerProvider } from "@opentelemetry/api";
|
12
|
+
|
13
|
+
//#region src/compat/types.d.ts
|
14
|
+
/**
|
15
|
+
* A function that transforms an activity object.
|
16
|
+
* @since 1.4.0
|
17
|
+
*/
|
18
|
+
type ActivityTransformer<TContextData> = (activity: Activity, context: Context<TContextData>) => Activity;
|
19
|
+
//#endregion
|
20
|
+
//#region src/federation/collection.d.ts
|
21
|
+
/**
|
22
|
+
* A page of items.
|
23
|
+
*/
|
24
|
+
interface PageItems<TItem> {
|
25
|
+
prevCursor?: string | null;
|
26
|
+
nextCursor?: string | null;
|
27
|
+
items: TItem[];
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Calculates the [partial follower collection digest][1].
|
31
|
+
*
|
32
|
+
* [1]: https://w3id.org/fep/8fcf#partial-follower-collection-digest
|
33
|
+
* @param uris The URIs to calculate the digest. Duplicate URIs are ignored.
|
34
|
+
* @returns The digest.
|
35
|
+
*/
|
36
|
+
declare function digest(uris: Iterable<string | URL>): Promise<Uint8Array>;
|
37
|
+
/**
|
38
|
+
* Builds [`Collection-Synchronization`][1] header content.
|
39
|
+
*
|
40
|
+
* [1]: https://w3id.org/fep/8fcf#the-collection-synchronization-http-header
|
41
|
+
*
|
42
|
+
* @param collectionId The sender's followers collection URI.
|
43
|
+
* @param actorIds The actor URIs to digest.
|
44
|
+
* @returns The header content.
|
45
|
+
*/
|
46
|
+
declare function buildCollectionSynchronizationHeader(collectionId: string | URL, actorIds: Iterable<string | URL>): Promise<string>;
|
47
|
+
//#endregion
|
48
|
+
//#region src/federation/send.d.ts
|
49
|
+
/**
|
50
|
+
* A key pair for an actor who sends an activity.
|
51
|
+
* @since 0.10.0
|
52
|
+
*/
|
53
|
+
interface SenderKeyPair {
|
54
|
+
/**
|
55
|
+
* The actor's private key to sign the request.
|
56
|
+
*/
|
57
|
+
privateKey: CryptoKey;
|
58
|
+
/**
|
59
|
+
* The public key ID that corresponds to the private key.
|
60
|
+
*/
|
61
|
+
keyId: URL;
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* Parameters for {@link sendActivity}.
|
65
|
+
*/
|
66
|
+
//#endregion
|
67
|
+
//#region src/federation/callback.d.ts
|
68
|
+
/**
|
69
|
+
* A callback that dispatches a {@link NodeInfo} object.
|
70
|
+
*
|
71
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
72
|
+
*/
|
73
|
+
type NodeInfoDispatcher<TContextData> = (context: RequestContext<TContextData>) => NodeInfo | Promise<NodeInfo>;
|
74
|
+
/**
|
75
|
+
* A callback that dispatches a array of {@link Link}.
|
76
|
+
*
|
77
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
78
|
+
* @param resource The URL queried via WebFinger.
|
79
|
+
* @returns Links related to the queried resource.
|
80
|
+
*/
|
81
|
+
type WebFingerLinksDispatcher<TContextData> = (context: RequestContext<TContextData>, resource: URL) => readonly Link$1[] | Promise<readonly Link$1[]>;
|
82
|
+
/**
|
83
|
+
* A callback that dispatches an {@link Actor} object.
|
84
|
+
*
|
85
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
86
|
+
* @param context The request context.
|
87
|
+
* @param identifier The actor's internal identifier or username.
|
88
|
+
*/
|
89
|
+
type ActorDispatcher<TContextData> = (context: RequestContext<TContextData>, identifier: string) => Actor | null | Promise<Actor | null>;
|
90
|
+
/**
|
91
|
+
* A callback that dispatches key pairs for an actor.
|
92
|
+
*
|
93
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
94
|
+
* @param context The context.
|
95
|
+
* @param identifier The actor's internal identifier or username.
|
96
|
+
* @returns The key pairs.
|
97
|
+
* @since 0.10.0
|
98
|
+
*/
|
99
|
+
type ActorKeyPairsDispatcher<TContextData> = (context: Context<TContextData>, identifier: string) => CryptoKeyPair[] | Promise<CryptoKeyPair[]>;
|
100
|
+
/**
|
101
|
+
* A callback that maps a WebFinger username to the corresponding actor's
|
102
|
+
* internal identifier, or `null` if the username is not found.
|
103
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
104
|
+
* @param context The context.
|
105
|
+
* @param username The WebFinger username.
|
106
|
+
* @returns The actor's internal identifier, or `null` if the username is not
|
107
|
+
* found.
|
108
|
+
* @since 0.15.0
|
109
|
+
*/
|
110
|
+
type ActorHandleMapper<TContextData> = (context: Context<TContextData>, username: string) => string | null | Promise<string | null>;
|
111
|
+
/**
|
112
|
+
* A callback that maps a WebFinger query to the corresponding actor's
|
113
|
+
* internal identifier or username, or `null` if the query is not found.
|
114
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
115
|
+
* @param context The request context.
|
116
|
+
* @param resource The URL that was queried through WebFinger.
|
117
|
+
* @returns The actor's internal identifier or username, or `null` if the query
|
118
|
+
* is not found.
|
119
|
+
* @since 1.4.0
|
120
|
+
*/
|
121
|
+
type ActorAliasMapper<TContextData> = (context: RequestContext<TContextData>, resource: URL) => {
|
122
|
+
identifier: string;
|
123
|
+
} | {
|
124
|
+
username: string;
|
125
|
+
} | null | Promise<{
|
126
|
+
identifier: string;
|
127
|
+
} | {
|
128
|
+
username: string;
|
129
|
+
} | null>;
|
130
|
+
/**
|
131
|
+
* A callback that dispatches an object.
|
132
|
+
*
|
133
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
134
|
+
* @template TObject The type of object to dispatch.
|
135
|
+
* @template TParam The parameter names of the requested URL.
|
136
|
+
* @since 0.7.0
|
137
|
+
*/
|
138
|
+
type ObjectDispatcher<TContextData, TObject extends Object$1, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>) => TObject | null | Promise<TObject | null>;
|
139
|
+
/**
|
140
|
+
* A callback that dispatches a collection.
|
141
|
+
*
|
142
|
+
* @template TItem The type of items in the collection.
|
143
|
+
* @template TContext The type of the context. {@link Context} or
|
144
|
+
* {@link RequestContext}.
|
145
|
+
* @template TContextData The context data to pass to the `TContext`.
|
146
|
+
* @template TFilter The type of the filter, if any.
|
147
|
+
* @param context The context.
|
148
|
+
* @param identifier The internal identifier or the username of the collection
|
149
|
+
* owner.
|
150
|
+
* @param cursor The cursor to start the collection from, or `null` to dispatch
|
151
|
+
* the entire collection without pagination.
|
152
|
+
* @param filter The filter to apply to the collection, if any.
|
153
|
+
*/
|
154
|
+
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>;
|
155
|
+
/**
|
156
|
+
* A callback that counts the number of items in a collection.
|
157
|
+
*
|
158
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
159
|
+
* @param context The context.
|
160
|
+
* @param identifier The internal identifier or the username of the collection
|
161
|
+
* owner.
|
162
|
+
* @param filter The filter to apply to the collection, if any.
|
163
|
+
*/
|
164
|
+
type CollectionCounter<TContextData, TFilter> = (context: RequestContext<TContextData>, identifier: string, filter?: TFilter) => number | bigint | null | Promise<number | bigint | null>;
|
165
|
+
/**
|
166
|
+
* A callback that returns a cursor for a collection.
|
167
|
+
*
|
168
|
+
* @template TContext The type of the context. {@link Context} or
|
169
|
+
* {@link RequestContext}.
|
170
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
171
|
+
* @template TFilter The type of the filter, if any.
|
172
|
+
* @param context The context.
|
173
|
+
* @param identifier The internal identifier or the username of the collection
|
174
|
+
* owner.
|
175
|
+
* @param filter The filter to apply to the collection, if any.
|
176
|
+
*/
|
177
|
+
type CollectionCursor<TContext extends Context<TContextData>, TContextData, TFilter> = (context: TContext, identifier: string, filter?: TFilter) => string | null | Promise<string | null>;
|
178
|
+
/**
|
179
|
+
* A callback that listens for activities in an inbox.
|
180
|
+
*
|
181
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
182
|
+
* @template TActivity The type of activity to listen for.
|
183
|
+
* @param context The inbox context.
|
184
|
+
* @param activity The activity that was received.
|
185
|
+
*/
|
186
|
+
type InboxListener<TContextData, TActivity extends Activity> = (context: InboxContext<TContextData>, activity: TActivity) => void | Promise<void>;
|
187
|
+
/**
|
188
|
+
* A callback that handles errors in an inbox.
|
189
|
+
*
|
190
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
191
|
+
* @param context The inbox context.
|
192
|
+
*/
|
193
|
+
type InboxErrorHandler<TContextData> = (context: Context<TContextData>, error: Error) => void | Promise<void>;
|
194
|
+
/**
|
195
|
+
* A callback that dispatches the key pair for the authenticated document loader
|
196
|
+
* of the {@link Context} passed to the shared inbox listener.
|
197
|
+
*
|
198
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
199
|
+
* @param context The context.
|
200
|
+
* @returns The username or the internal identifier of the actor or the key pair
|
201
|
+
* for the authenticated document loader of the {@link Context} passed
|
202
|
+
* to the shared inbox listener. If `null` is returned, the request is
|
203
|
+
* not authorized.
|
204
|
+
* @since 0.11.0
|
205
|
+
*/
|
206
|
+
type SharedInboxKeyDispatcher<TContextData> = (context: Context<TContextData>) => SenderKeyPair | {
|
207
|
+
identifier: string;
|
208
|
+
} | {
|
209
|
+
username: string;
|
210
|
+
} | {
|
211
|
+
handle: string;
|
212
|
+
} | null | Promise<SenderKeyPair | {
|
213
|
+
identifier: string;
|
214
|
+
} | {
|
215
|
+
username: string;
|
216
|
+
} | {
|
217
|
+
handle: string;
|
218
|
+
} | null>;
|
219
|
+
/**
|
220
|
+
* A callback that handles errors during outbox processing.
|
221
|
+
*
|
222
|
+
* @param error The error that occurred.
|
223
|
+
* @param activity The activity that caused the error. If it is `null`, the
|
224
|
+
* error occurred during deserializing the activity.
|
225
|
+
* @since 0.6.0
|
226
|
+
*/
|
227
|
+
type OutboxErrorHandler = (error: Error, activity: Activity | null) => void | Promise<void>;
|
228
|
+
/**
|
229
|
+
* A callback that determines if a request is authorized or not.
|
230
|
+
*
|
231
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
232
|
+
* @param context The request context.
|
233
|
+
* @param identifier The internal identifier of the actor that is being requested.
|
234
|
+
* @param signedKey *Deprecated in Fedify 1.5.0 in favor of
|
235
|
+
* {@link RequestContext.getSignedKey} method.*
|
236
|
+
* The key that was used to sign the request, or `null` if
|
237
|
+
* the request was not signed or the signature was invalid.
|
238
|
+
* @param signedKeyOwner *Deprecated in Fedify 1.5.0 in favor of
|
239
|
+
* {@link RequestContext.getSignedKeyOwner} method.*
|
240
|
+
* The actor that owns the key that was used to sign the
|
241
|
+
* request, or `null` if the request was not signed or the
|
242
|
+
* signature was invalid, or if the key is not associated
|
243
|
+
* with an actor.
|
244
|
+
* @returns `true` if the request is authorized, `false` otherwise.
|
245
|
+
* @since 0.7.0
|
246
|
+
*/
|
247
|
+
type AuthorizePredicate<TContextData> = (context: RequestContext<TContextData>, identifier: string, signedKey: CryptographicKey | null, signedKeyOwner: Actor | null) => boolean | Promise<boolean>;
|
248
|
+
/**
|
249
|
+
* A callback that determines if a request is authorized or not.
|
250
|
+
*
|
251
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
252
|
+
* @template TParam The parameter names of the requested URL.
|
253
|
+
* @param context The request context.
|
254
|
+
* @param values The parameters of the requested URL.
|
255
|
+
* @param signedKey *Deprecated in Fedify 1.5.0 in favor of
|
256
|
+
* {@link RequestContext.getSignedKey} method.*
|
257
|
+
* The key that was used to sign the request, or `null` if
|
258
|
+
* the request was not signed or the signature was invalid.
|
259
|
+
* @param signedKeyOwner *Deprecated in Fedify 1.5.0 in favor of
|
260
|
+
* {@link RequestContext.getSignedKeyOwner} method.*
|
261
|
+
* The actor that owns the key that was used to sign the
|
262
|
+
* request, or `null` if the request was not signed or the
|
263
|
+
* signature was invalid, or if the key is not associated
|
264
|
+
* with an actor.
|
265
|
+
* @returns `true` if the request is authorized, `false` otherwise.
|
266
|
+
* @since 0.7.0
|
267
|
+
*/
|
268
|
+
type ObjectAuthorizePredicate<TContextData, TParam extends string> = (context: RequestContext<TContextData>, values: Record<TParam, string>, signedKey: CryptographicKey | null, signedKeyOwner: Actor | null) => boolean | Promise<boolean>;
|
269
|
+
/**
|
270
|
+
* A callback that dispatches a custom collection.
|
271
|
+
*
|
272
|
+
* @template TItem The type of items in the collection.
|
273
|
+
* @template TParams The parameter names of the requested URL.
|
274
|
+
* @template TContext The type of the context. {@link Context} or
|
275
|
+
* {@link RequestContext}.
|
276
|
+
* @template TContextData The context data to pass to the `TContext`.
|
277
|
+
* @template TFilter The type of the filter, if any.
|
278
|
+
* @param context The context.
|
279
|
+
* @param values The parameters of the requested URL.
|
280
|
+
* @param cursor The cursor to start the collection from, or `null` to dispatch
|
281
|
+
* the entire collection without pagination.
|
282
|
+
* @since 1.8.0
|
283
|
+
*/
|
284
|
+
type CustomCollectionDispatcher<TItem, TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: TParams, cursor: string | null) => PageItems<TItem> | null | Promise<PageItems<TItem> | null>;
|
285
|
+
/**
|
286
|
+
* A callback that counts the number of items in a custom collection.
|
287
|
+
*
|
288
|
+
* @template TParams The parameter names of the requested URL.
|
289
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
290
|
+
* @param context The context.
|
291
|
+
* @param values The parameters of the requested URL.
|
292
|
+
* @since 1.8.0
|
293
|
+
*/
|
294
|
+
type CustomCollectionCounter<TParams extends Record<string, string>, TContextData> = (context: RequestContext<TContextData>, values: TParams) => number | bigint | null | Promise<number | bigint | null>;
|
295
|
+
/**
|
296
|
+
* A callback that returns a cursor for a custom collection.
|
297
|
+
*
|
298
|
+
* @template TParams The parameter names of the requested URL.
|
299
|
+
* @template TContext The type of the context. {@link Context} or
|
300
|
+
* {@link RequestContext}.
|
301
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
302
|
+
* @template TFilter The type of the filter, if any.
|
303
|
+
* @param context The context.
|
304
|
+
* @param values The parameters of the requested URL.
|
305
|
+
* @since 1.8.0
|
306
|
+
*/
|
307
|
+
type CustomCollectionCursor<TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> = (context: TContext, values: TParams) => string | null | Promise<string | null>;
|
308
|
+
//#endregion
|
309
|
+
//#region src/federation/handler.d.ts
|
310
|
+
|
311
|
+
/**
|
312
|
+
* Options for the {@link respondWithObject} and
|
313
|
+
* {@link respondWithObjectIfAcceptable} functions.
|
314
|
+
* @since 0.3.0
|
315
|
+
*/
|
316
|
+
interface RespondWithObjectOptions {
|
317
|
+
/**
|
318
|
+
* The document loader to use for compacting JSON-LD.
|
319
|
+
* @since 0.8.0
|
320
|
+
*/
|
321
|
+
contextLoader: DocumentLoader;
|
322
|
+
}
|
323
|
+
/**
|
324
|
+
* Responds with the given object in JSON-LD format.
|
325
|
+
*
|
326
|
+
* @param object The object to respond with.
|
327
|
+
* @param options Options.
|
328
|
+
* @since 0.3.0
|
329
|
+
*/
|
330
|
+
declare function respondWithObject(object: Object$1, options?: RespondWithObjectOptions): Promise<Response>;
|
331
|
+
/**
|
332
|
+
* Responds with the given object in JSON-LD format if the request accepts
|
333
|
+
* JSON-LD.
|
334
|
+
*
|
335
|
+
* @param object The object to respond with.
|
336
|
+
* @param request The request to check for JSON-LD acceptability.
|
337
|
+
* @param options Options.
|
338
|
+
* @since 0.3.0
|
339
|
+
*/
|
340
|
+
declare function respondWithObjectIfAcceptable(object: Object$1, request: Request, options?: RespondWithObjectOptions): Promise<Response | null>;
|
341
|
+
//#endregion
|
342
|
+
//#region src/federation/router.d.ts
|
343
|
+
/**
|
344
|
+
* Options for the {@link Router}.
|
345
|
+
* @since 0.12.0
|
346
|
+
*/
|
347
|
+
interface RouterOptions {
|
348
|
+
/**
|
349
|
+
* Whether to ignore trailing slashes when matching paths.
|
350
|
+
*/
|
351
|
+
trailingSlashInsensitive?: boolean;
|
352
|
+
}
|
353
|
+
/**
|
354
|
+
* The result of {@link Router.route} method.
|
355
|
+
* @since 1.3.0
|
356
|
+
*/
|
357
|
+
interface RouterRouteResult {
|
358
|
+
/**
|
359
|
+
* The matched route name.
|
360
|
+
*/
|
361
|
+
name: string;
|
362
|
+
/**
|
363
|
+
* The URL template of the matched route.
|
364
|
+
*/
|
365
|
+
template: string;
|
366
|
+
/**
|
367
|
+
* The values extracted from the URL.
|
368
|
+
*/
|
369
|
+
values: Record<string, string>;
|
370
|
+
}
|
371
|
+
/**
|
372
|
+
* URL router and constructor based on URI Template
|
373
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
374
|
+
*/
|
375
|
+
declare class Router {
|
376
|
+
#private;
|
377
|
+
/**
|
378
|
+
* Whether to ignore trailing slashes when matching paths.
|
379
|
+
* @since 1.6.0
|
380
|
+
*/
|
381
|
+
trailingSlashInsensitive: boolean;
|
382
|
+
/**
|
383
|
+
* Create a new {@link Router}.
|
384
|
+
* @param options Options for the router.
|
385
|
+
*/
|
386
|
+
constructor(options?: RouterOptions);
|
387
|
+
clone(): Router;
|
388
|
+
/**
|
389
|
+
* Checks if a path name exists in the router.
|
390
|
+
* @param name The name of the path.
|
391
|
+
* @returns `true` if the path name exists, otherwise `false`.
|
392
|
+
*/
|
393
|
+
has(name: string): boolean;
|
394
|
+
/**
|
395
|
+
* Adds a new path rule to the router.
|
396
|
+
* @param template The path pattern.
|
397
|
+
* @param name The name of the path.
|
398
|
+
* @returns The names of the variables in the path pattern.
|
399
|
+
*/
|
400
|
+
add(template: string, name: string): Set<string>;
|
401
|
+
/**
|
402
|
+
* Resolves a path name and values from a URL, if any match.
|
403
|
+
* @param url The URL to resolve.
|
404
|
+
* @returns The name of the path and its values, if any match. Otherwise,
|
405
|
+
* `null`.
|
406
|
+
*/
|
407
|
+
route(url: string): RouterRouteResult | null;
|
408
|
+
/**
|
409
|
+
* Constructs a URL/path from a path name and values.
|
410
|
+
* @param name The name of the path.
|
411
|
+
* @param values The values to expand the path with.
|
412
|
+
* @returns The URL/path, if the name exists. Otherwise, `null`.
|
413
|
+
*/
|
414
|
+
build(name: string, values: Record<string, string>): string | null;
|
415
|
+
}
|
416
|
+
/**
|
417
|
+
* An error thrown by the {@link Router}.
|
418
|
+
*/
|
419
|
+
declare class RouterError extends Error {
|
420
|
+
/**
|
421
|
+
* Create a new {@link RouterError}.
|
422
|
+
* @param message The error message.
|
423
|
+
*/
|
424
|
+
constructor(message: string);
|
425
|
+
}
|
426
|
+
//#endregion
|
427
|
+
//#region src/federation/builder.d.ts
|
428
|
+
/**
|
429
|
+
* Creates a new {@link FederationBuilder} instance.
|
430
|
+
* @returns A new {@link FederationBuilder} instance.
|
431
|
+
* @since 1.6.0
|
432
|
+
*/
|
433
|
+
declare function createFederationBuilder<TContextData>(): FederationBuilder<TContextData>;
|
434
|
+
//#endregion
|
435
|
+
//#region src/federation/queue.d.ts
|
436
|
+
interface SenderKeyJwkPair {
|
437
|
+
keyId: string;
|
438
|
+
privateKey: JsonWebKey;
|
439
|
+
}
|
440
|
+
/**
|
441
|
+
* A message that represents a task to be processed by the background worker.
|
442
|
+
* The concrete type of the message depends on the `type` property.
|
443
|
+
*
|
444
|
+
* Please do not depend on the concrete types of the messages, as they may
|
445
|
+
* change in the future. You should treat the `Message` type as an opaque
|
446
|
+
* type.
|
447
|
+
* @since 1.6.0
|
448
|
+
*/
|
449
|
+
type Message = FanoutMessage | OutboxMessage | InboxMessage;
|
450
|
+
interface FanoutMessage {
|
451
|
+
type: "fanout";
|
452
|
+
id: ReturnType<typeof crypto.randomUUID>;
|
453
|
+
baseUrl: string;
|
454
|
+
keys: SenderKeyJwkPair[];
|
455
|
+
inboxes: Record<string, {
|
456
|
+
actorIds: string[];
|
457
|
+
sharedInbox: boolean;
|
458
|
+
}>;
|
459
|
+
activity: unknown;
|
460
|
+
activityId?: string;
|
461
|
+
activityType: string;
|
462
|
+
collectionSync?: string;
|
463
|
+
traceContext: Record<string, string>;
|
464
|
+
}
|
465
|
+
interface OutboxMessage {
|
466
|
+
type: "outbox";
|
467
|
+
id: ReturnType<typeof crypto.randomUUID>;
|
468
|
+
baseUrl: string;
|
469
|
+
keys: SenderKeyJwkPair[];
|
470
|
+
activity: unknown;
|
471
|
+
activityId?: string;
|
472
|
+
activityType: string;
|
473
|
+
inbox: string;
|
474
|
+
sharedInbox: boolean;
|
475
|
+
started: string;
|
476
|
+
attempt: number;
|
477
|
+
headers: Record<string, string>;
|
478
|
+
traceContext: Record<string, string>;
|
479
|
+
}
|
480
|
+
interface InboxMessage {
|
481
|
+
type: "inbox";
|
482
|
+
id: ReturnType<typeof crypto.randomUUID>;
|
483
|
+
baseUrl: string;
|
484
|
+
activity: unknown;
|
485
|
+
started: string;
|
486
|
+
attempt: number;
|
487
|
+
identifier: string | null;
|
488
|
+
traceContext: Record<string, string>;
|
489
|
+
}
|
490
|
+
//#endregion
|
491
|
+
//#region src/federation/retry.d.ts
|
492
|
+
/**
|
493
|
+
* The context passed to a {@link RetryPolicy} callback.
|
494
|
+
* @since 0.12.0
|
495
|
+
*/
|
496
|
+
interface RetryContext {
|
497
|
+
/**
|
498
|
+
* The elapsed time since the first attempt.
|
499
|
+
*/
|
500
|
+
readonly elapsedTime: Temporal.Duration;
|
501
|
+
/**
|
502
|
+
* The number of attempts so far.
|
503
|
+
*/
|
504
|
+
readonly attempts: number;
|
505
|
+
}
|
506
|
+
/**
|
507
|
+
* A policy that determines the delay before the next retry.
|
508
|
+
* @param context The retry context.
|
509
|
+
* @returns The delay before the next retry, or `null` to stop retrying.
|
510
|
+
* It must not negative.
|
511
|
+
* @since 0.12.0
|
512
|
+
*/
|
513
|
+
type RetryPolicy = (context: RetryContext) => Temporal.Duration | null;
|
514
|
+
/**
|
515
|
+
* Options for {@link createExponentialBackoffPolicy} function.
|
516
|
+
* @since 0.12.0
|
517
|
+
*/
|
518
|
+
interface CreateExponentialBackoffPolicyOptions {
|
519
|
+
/**
|
520
|
+
* The initial delay before the first retry. Defaults to 1 second.
|
521
|
+
*/
|
522
|
+
readonly initialDelay?: Temporal.DurationLike;
|
523
|
+
/**
|
524
|
+
* The maximum delay between retries. Defaults to 12 hours.
|
525
|
+
*/
|
526
|
+
readonly maxDelay?: Temporal.DurationLike;
|
527
|
+
/**
|
528
|
+
* The maximum number of attempts before giving up.
|
529
|
+
* Defaults to 10.
|
530
|
+
*/
|
531
|
+
readonly maxAttempts?: number;
|
532
|
+
/**
|
533
|
+
* The factor to multiply the previous delay by for each retry.
|
534
|
+
* Defaults to 2.
|
535
|
+
*/
|
536
|
+
readonly factor?: number;
|
537
|
+
/**
|
538
|
+
* Whether to add jitter to the delay to avoid synchronization.
|
539
|
+
* Turned on by default.
|
540
|
+
*/
|
541
|
+
readonly jitter?: boolean;
|
542
|
+
}
|
543
|
+
/**
|
544
|
+
* Creates an exponential backoff retry policy. The delay between retries
|
545
|
+
* starts at the `initialDelay` and is multiplied by the `factor` for each
|
546
|
+
* subsequent retry, up to the `maxDelay`. The policy will give up after
|
547
|
+
* `maxAttempts` attempts. The actual delay is randomized to avoid
|
548
|
+
* synchronization (jitter).
|
549
|
+
* @param options The options for the policy.
|
550
|
+
* @returns The retry policy.
|
551
|
+
* @since 0.12.0
|
552
|
+
*/
|
553
|
+
declare function createExponentialBackoffPolicy(options?: CreateExponentialBackoffPolicyOptions): RetryPolicy;
|
554
|
+
//#endregion
|
555
|
+
//#region src/federation/middleware.d.ts
|
556
|
+
/**
|
557
|
+
* Options for {@link createFederation} function.
|
558
|
+
* @template TContextData The type of the context data.
|
559
|
+
* @since 0.10.0
|
560
|
+
* @deprecated Use {@link FederationOptions} instead.
|
561
|
+
*/
|
562
|
+
interface CreateFederationOptions<TContextData> extends FederationOptions<TContextData> {}
|
563
|
+
/**
|
564
|
+
* Configures the task queues for sending and receiving activities.
|
565
|
+
* @since 1.3.0
|
566
|
+
*/
|
567
|
+
interface FederationQueueOptions {
|
568
|
+
/**
|
569
|
+
* The message queue for incoming activities. If not provided, incoming
|
570
|
+
* activities will not be queued and will be processed immediately.
|
571
|
+
*/
|
572
|
+
inbox?: MessageQueue;
|
573
|
+
/**
|
574
|
+
* The message queue for outgoing activities. If not provided, outgoing
|
575
|
+
* activities will not be queued and will be sent immediately.
|
576
|
+
*/
|
577
|
+
outbox?: MessageQueue;
|
578
|
+
/**
|
579
|
+
* The message queue for fanning out outgoing activities. If not provided,
|
580
|
+
* outgoing activities will not be fanned out in the background, but will be
|
581
|
+
* fanned out immediately, which causes slow response times on
|
582
|
+
* {@link Context.sendActivity} calls.
|
583
|
+
*/
|
584
|
+
fanout?: MessageQueue;
|
585
|
+
}
|
586
|
+
/**
|
587
|
+
* Prefixes for namespacing keys in the Deno KV store.
|
588
|
+
*/
|
589
|
+
interface FederationKvPrefixes {
|
590
|
+
/**
|
591
|
+
* The key prefix used for storing whether activities have already been
|
592
|
+
* processed or not.
|
593
|
+
* @default `["_fedify", "activityIdempotence"]`
|
594
|
+
*/
|
595
|
+
activityIdempotence: KvKey;
|
596
|
+
/**
|
597
|
+
* The key prefix used for storing remote JSON-LD documents.
|
598
|
+
* @default `["_fedify", "remoteDocument"]`
|
599
|
+
*/
|
600
|
+
remoteDocument: KvKey;
|
601
|
+
/**
|
602
|
+
* The key prefix used for caching public keys.
|
603
|
+
* @default `["_fedify", "publicKey"]`
|
604
|
+
* @since 0.12.0
|
605
|
+
*/
|
606
|
+
publicKey: KvKey;
|
607
|
+
/**
|
608
|
+
* The key prefix used for caching HTTP Message Signatures specs.
|
609
|
+
* The cached spec is used to reduce the number of requests to make signed
|
610
|
+
* requests ("double-knocking" technique).
|
611
|
+
* @default `["_fedify", "httpMessageSignaturesSpec"]`
|
612
|
+
* @since 1.6.0
|
613
|
+
*/
|
614
|
+
httpMessageSignaturesSpec: KvKey;
|
615
|
+
}
|
616
|
+
/**
|
617
|
+
* Options for {@link CreateFederationOptions.origin} when it is not a string.
|
618
|
+
* @since 1.5.0
|
619
|
+
*/
|
620
|
+
interface FederationOrigin {
|
621
|
+
/**
|
622
|
+
* The canonical hostname for fediverse handles (which are looked up through
|
623
|
+
* WebFinger). This is used for WebFinger lookups. It has to be a valid
|
624
|
+
* hostname, e.g., `"example.com"`.
|
625
|
+
*/
|
626
|
+
handleHost: string;
|
627
|
+
/**
|
628
|
+
* The canonical origin for web URLs. This is used for constructing absolute
|
629
|
+
* URLs. It has to start with either `"http://"` or `"https://"`, and must
|
630
|
+
* not contain a path or query string, e.g., `"https://example.com"`.
|
631
|
+
*/
|
632
|
+
webOrigin: string;
|
633
|
+
}
|
634
|
+
/**
|
635
|
+
* Create a new {@link Federation} instance.
|
636
|
+
* @param parameters Parameters for initializing the instance.
|
637
|
+
* @returns A new {@link Federation} instance.
|
638
|
+
* @since 0.10.0
|
639
|
+
*/
|
640
|
+
declare function createFederation<TContextData>(options: CreateFederationOptions<TContextData>): Federation<TContextData>;
|
641
|
+
//#endregion
|
642
|
+
//#region src/federation/federation.d.ts
|
643
|
+
/**
|
644
|
+
* Options for {@link Federation.startQueue} method.
|
645
|
+
* @since 1.0.0
|
646
|
+
*/
|
647
|
+
interface FederationStartQueueOptions {
|
648
|
+
/**
|
649
|
+
* The signal to abort the task queue.
|
650
|
+
*/
|
651
|
+
signal?: AbortSignal;
|
652
|
+
/**
|
653
|
+
* Starts the task worker only for the specified queue. If unspecified,
|
654
|
+
* which is the default, the task worker starts for all three queues:
|
655
|
+
* inbox, outbox, and fanout.
|
656
|
+
* @since 1.3.0
|
657
|
+
*/
|
658
|
+
queue?: "inbox" | "outbox" | "fanout";
|
659
|
+
}
|
660
|
+
/**
|
661
|
+
* A common interface between {@link Federation} and {@link FederationBuilder}.
|
662
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
663
|
+
* @since 1.6.0
|
664
|
+
*/
|
665
|
+
interface Federatable<TContextData> {
|
666
|
+
/**
|
667
|
+
* Registers a NodeInfo dispatcher.
|
668
|
+
* @param path The URI path pattern for the NodeInfo dispatcher. The syntax
|
669
|
+
* is based on URI Template
|
670
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
671
|
+
* must have no variables.
|
672
|
+
* @param dispatcher A NodeInfo dispatcher callback to register.
|
673
|
+
* @throws {RouterError} Thrown if the path pattern is invalid.
|
674
|
+
*/
|
675
|
+
setNodeInfoDispatcher(path: string, dispatcher: NodeInfoDispatcher<TContextData>): void;
|
676
|
+
/**
|
677
|
+
* Registers a links dispatcher to WebFinger
|
678
|
+
* @param dispatcher A links dispatcher callback to register.
|
679
|
+
*/
|
680
|
+
setWebFingerLinksDispatcher(dispatcher: WebFingerLinksDispatcher<TContextData>): void;
|
681
|
+
/**
|
682
|
+
* Registers an actor dispatcher.
|
683
|
+
*
|
684
|
+
* @example
|
685
|
+
* ``` typescript
|
686
|
+
* federation.setActorDispatcher(
|
687
|
+
* "/users/{identifier}",
|
688
|
+
* async (ctx, identifier) => {
|
689
|
+
* return new Person({
|
690
|
+
* id: ctx.getActorUri(identifier),
|
691
|
+
* // ...
|
692
|
+
* });
|
693
|
+
* }
|
694
|
+
* );
|
695
|
+
* ```
|
696
|
+
*
|
697
|
+
* @param path The URI path pattern for the actor dispatcher. The syntax is
|
698
|
+
* based on URI Template
|
699
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
700
|
+
* must have one variable: `{identifier}`.
|
701
|
+
* @param dispatcher An actor dispatcher callback to register.
|
702
|
+
* @returns An object with methods to set other actor dispatcher callbacks.
|
703
|
+
* @throws {RouterError} Thrown if the path pattern is invalid.
|
704
|
+
*/
|
705
|
+
setActorDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: ActorDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
|
706
|
+
/**
|
707
|
+
* Registers an object dispatcher.
|
708
|
+
*
|
709
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
710
|
+
* @template TObject The type of object to dispatch.
|
711
|
+
* @template TParam The parameter names of the requested URL.
|
712
|
+
* @param cls The Activity Vocabulary class of the object to dispatch.
|
713
|
+
* @param path The URI path pattern for the object dispatcher. The syntax is
|
714
|
+
* based on URI Template
|
715
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
716
|
+
* must have one or more variables.
|
717
|
+
* @param dispatcher An object dispatcher callback to register.
|
718
|
+
*/
|
719
|
+
setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
720
|
+
typeId: URL;
|
721
|
+
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
722
|
+
/**
|
723
|
+
* Registers an object dispatcher.
|
724
|
+
*
|
725
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
726
|
+
* @template TObject The type of object to dispatch.
|
727
|
+
* @template TParam The parameter names of the requested URL.
|
728
|
+
* @param cls The Activity Vocabulary class of the object to dispatch.
|
729
|
+
* @param path The URI path pattern for the object dispatcher. The syntax is
|
730
|
+
* based on URI Template
|
731
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
732
|
+
* must have one or more variables.
|
733
|
+
* @param dispatcher An object dispatcher callback to register.
|
734
|
+
*/
|
735
|
+
setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
736
|
+
typeId: URL;
|
737
|
+
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
738
|
+
/**
|
739
|
+
* Registers an object dispatcher.
|
740
|
+
*
|
741
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
742
|
+
* @template TObject The type of object to dispatch.
|
743
|
+
* @template TParam The parameter names of the requested URL.
|
744
|
+
* @param cls The Activity Vocabulary class of the object to dispatch.
|
745
|
+
* @param path The URI path pattern for the object dispatcher. The syntax is
|
746
|
+
* based on URI Template
|
747
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
748
|
+
* must have one or more variables.
|
749
|
+
* @param dispatcher An object dispatcher callback to register.
|
750
|
+
*/
|
751
|
+
setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
752
|
+
typeId: URL;
|
753
|
+
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}{${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: (new (...args: any[]) => TObject) & {
|
768
|
+
typeId: URL;
|
769
|
+
}, path: `${string}{${TParam}}${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
770
|
+
/**
|
771
|
+
* Registers an object dispatcher.
|
772
|
+
*
|
773
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
774
|
+
* @template TObject The type of object to dispatch.
|
775
|
+
* @template TParam The parameter names of the requested URL.
|
776
|
+
* @param cls The Activity Vocabulary class of the object to dispatch.
|
777
|
+
* @param path The URI path pattern for the object dispatcher. The syntax is
|
778
|
+
* based on URI Template
|
779
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
780
|
+
* must have one or more variables.
|
781
|
+
* @param dispatcher An object dispatcher callback to register.
|
782
|
+
*/
|
783
|
+
setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
784
|
+
typeId: URL;
|
785
|
+
}, path: `${string}{${TParam}}${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
786
|
+
/**
|
787
|
+
* Registers an object dispatcher.
|
788
|
+
*
|
789
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
790
|
+
* @template TObject The type of object to dispatch.
|
791
|
+
* @template TParam The parameter names of the requested URL.
|
792
|
+
* @param cls The Activity Vocabulary class of the object to dispatch.
|
793
|
+
* @param path The URI path pattern for the object dispatcher. The syntax is
|
794
|
+
* based on URI Template
|
795
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
796
|
+
* must have one or more variables.
|
797
|
+
* @param dispatcher An object dispatcher callback to register.
|
798
|
+
*/
|
799
|
+
setObjectDispatcher<TObject extends Object$1, TParam extends string>(cls: (new (...args: any[]) => TObject) & {
|
800
|
+
typeId: URL;
|
801
|
+
}, path: `${string}{${TParam}}${string}`, dispatcher: ObjectDispatcher<TContextData, TObject, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
802
|
+
/**
|
803
|
+
* Registers an inbox dispatcher.
|
804
|
+
*
|
805
|
+
* @param path The URI path pattern for the inbox dispatcher. The syntax is
|
806
|
+
* based on URI Template
|
807
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
808
|
+
* must have one variable: `{identifier}`, and must match
|
809
|
+
* the inbox listener path.
|
810
|
+
* @param dispatcher An inbox dispatcher callback to register.
|
811
|
+
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
812
|
+
*/
|
813
|
+
setInboxDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
814
|
+
/**
|
815
|
+
* Registers an outbox dispatcher.
|
816
|
+
*
|
817
|
+
* @example
|
818
|
+
* ``` typescript
|
819
|
+
* federation.setOutboxDispatcher(
|
820
|
+
* "/users/{identifier}/outbox",
|
821
|
+
* async (ctx, identifier, options) => {
|
822
|
+
* let items: Activity[];
|
823
|
+
* let nextCursor: string;
|
824
|
+
* // ...
|
825
|
+
* return { items, nextCursor };
|
826
|
+
* }
|
827
|
+
* );
|
828
|
+
* ```
|
829
|
+
*
|
830
|
+
* @param path The URI path pattern for the outbox dispatcher. The syntax is
|
831
|
+
* based on URI Template
|
832
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
833
|
+
* must have one variable: `{identifier}`.
|
834
|
+
* @param dispatcher An outbox dispatcher callback to register.
|
835
|
+
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
836
|
+
*/
|
837
|
+
setOutboxDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Activity, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
838
|
+
/**
|
839
|
+
* Registers a following collection dispatcher.
|
840
|
+
* @param path The URI path pattern for the following collection. The syntax
|
841
|
+
* is based on URI Template
|
842
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
843
|
+
* must have one variable: `{identifier}`.
|
844
|
+
* @param dispatcher A following collection callback to register.
|
845
|
+
* @returns An object with methods to set other following collection
|
846
|
+
* callbacks.
|
847
|
+
* @throws {RouterError} Thrown if the path pattern is invalid.
|
848
|
+
*/
|
849
|
+
setFollowingDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Actor | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
850
|
+
/**
|
851
|
+
* Registers a followers collection dispatcher.
|
852
|
+
* @param path The URI path pattern for the followers collection. The syntax
|
853
|
+
* is based on URI Template
|
854
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
855
|
+
* must have one variable: `{identifier}`.
|
856
|
+
* @param dispatcher A followers collection callback to register.
|
857
|
+
* @returns An object with methods to set other followers collection
|
858
|
+
* callbacks.
|
859
|
+
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
860
|
+
*/
|
861
|
+
setFollowersDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Recipient, Context<TContextData>, TContextData, URL>): CollectionCallbackSetters<Context<TContextData>, TContextData, URL>;
|
862
|
+
/**
|
863
|
+
* Registers a liked collection dispatcher.
|
864
|
+
* @param path The URI path pattern for the liked collection. The syntax
|
865
|
+
* is based on URI Template
|
866
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
867
|
+
* must have one variable: `{identifier}`.
|
868
|
+
* @param dispatcher A liked collection callback to register.
|
869
|
+
* @returns An object with methods to set other liked collection
|
870
|
+
* callbacks.
|
871
|
+
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
872
|
+
*/
|
873
|
+
setLikedDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Object$1 | URL, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
874
|
+
/**
|
875
|
+
* Registers a featured collection dispatcher.
|
876
|
+
* @param path The URI path pattern for the featured collection. The syntax
|
877
|
+
* is based on URI Template
|
878
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
879
|
+
* must have one variable: `{identifier}`.
|
880
|
+
* @param dispatcher A featured collection callback to register.
|
881
|
+
* @returns An object with methods to set other featured collection
|
882
|
+
* callbacks.
|
883
|
+
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
884
|
+
*/
|
885
|
+
setFeaturedDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Object$1, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
886
|
+
/**
|
887
|
+
* Registers a featured tags collection dispatcher.
|
888
|
+
* @param path The URI path pattern for the featured tags collection.
|
889
|
+
* The syntax is based on URI Template
|
890
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)). The path
|
891
|
+
* must have one variable: `{identifier}`.
|
892
|
+
* @param dispatcher A featured tags collection callback to register.
|
893
|
+
* @returns An object with methods to set other featured tags collection
|
894
|
+
* callbacks.
|
895
|
+
* @throws {@link RouterError} Thrown if the path pattern is invalid.
|
896
|
+
*/
|
897
|
+
setFeaturedTagsDispatcher(path: `${string}{identifier}${string}` | `${string}{handle}${string}`, dispatcher: CollectionDispatcher<Hashtag, RequestContext<TContextData>, TContextData, void>): CollectionCallbackSetters<RequestContext<TContextData>, TContextData, void>;
|
898
|
+
/**
|
899
|
+
* Assigns the URL path for the inbox and starts setting inbox listeners.
|
900
|
+
*
|
901
|
+
* @example
|
902
|
+
* ``` typescript
|
903
|
+
* federation
|
904
|
+
* .setInboxListeners("/users/{identifier}/inbox", "/inbox")
|
905
|
+
* .on(Follow, async (ctx, follow) => {
|
906
|
+
* const from = await follow.getActor(ctx);
|
907
|
+
* if (!isActor(from)) return;
|
908
|
+
* // ...
|
909
|
+
* })
|
910
|
+
* .on(Undo, async (ctx, undo) => {
|
911
|
+
* // ...
|
912
|
+
* });
|
913
|
+
* ```
|
914
|
+
*
|
915
|
+
* @param inboxPath The URI path pattern for the inbox. The syntax is based
|
916
|
+
* on URI Template
|
917
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
918
|
+
* The path must have one variable: `{identifier}`, and must
|
919
|
+
* match the inbox dispatcher path.
|
920
|
+
* @param sharedInboxPath An optional URI path pattern for the shared inbox.
|
921
|
+
* The syntax is based on URI Template
|
922
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
923
|
+
* The path must have no variables.
|
924
|
+
* @returns An object to register inbox listeners.
|
925
|
+
* @throws {RouteError} Thrown if the path pattern is invalid.
|
926
|
+
*/
|
927
|
+
setInboxListeners(inboxPath: `${string}{identifier}${string}` | `${string}{handle}${string}`, sharedInboxPath?: string): InboxListenerSetters<TContextData>;
|
928
|
+
/**
|
929
|
+
* Registers a collection of objects dispatcher.
|
930
|
+
*
|
931
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
932
|
+
* @template TObject The type of objects to dispatch.
|
933
|
+
* @template TParam The parameter names of the requested URL.
|
934
|
+
* @param name A unique name for the collection dispatcher.
|
935
|
+
* @param itemType The Activity Vocabulary class of the object to dispatch.
|
936
|
+
* @param path The URI path pattern for the collection dispatcher.
|
937
|
+
* The syntax is based on URI Template
|
938
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
939
|
+
* The path must have one or more variables.
|
940
|
+
* @param dispatcher A collection dispatcher callback to register.
|
941
|
+
*/
|
942
|
+
setCollectionDispatcher<TObject extends Object$1, TParams extends Record<string, string>>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: ParamsKeyPath<TParams>, dispatcher: CustomCollectionDispatcher<TObject, TParams, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParams, RequestContext<TContextData>, TContextData>;
|
943
|
+
/**
|
944
|
+
* Registers an ordered collection of objects dispatcher.
|
945
|
+
*
|
946
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
947
|
+
* @template TObject The type of objects to dispatch.
|
948
|
+
* @template TParam The parameter names of the requested URL.
|
949
|
+
* @param name A unique name for the collection dispatcher.
|
950
|
+
* @param itemType The Activity Vocabulary class of the object to dispatch.
|
951
|
+
* @param path The URI path pattern for the collection dispatcher.
|
952
|
+
* The syntax is based on URI Template
|
953
|
+
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
|
954
|
+
* The path must have one or more variables.
|
955
|
+
* @param dispatcher A collection dispatcher callback to register.
|
956
|
+
*/
|
957
|
+
setOrderedCollectionDispatcher<TObject extends Object$1, TParams extends Record<string, string>>(name: string | symbol, itemType: ConstructorWithTypeId<TObject>, path: ParamsKeyPath<TParams>, dispatcher: CustomCollectionDispatcher<TObject, TParams, RequestContext<TContextData>, TContextData>): CustomCollectionCallbackSetters<TParams, RequestContext<TContextData>, TContextData>;
|
958
|
+
}
|
959
|
+
/**
|
960
|
+
* An object that registers federation-related business logic and dispatches
|
961
|
+
* requests to the appropriate handlers.
|
962
|
+
*
|
963
|
+
* It also provides a middleware interface for handling requests before your
|
964
|
+
* web framework's router; see {@link Federation.fetch}.
|
965
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
966
|
+
* @since 0.13.0
|
967
|
+
*/
|
968
|
+
interface Federation<TContextData> extends Federatable<TContextData> {
|
969
|
+
/**
|
970
|
+
* Manually start the task queue.
|
971
|
+
*
|
972
|
+
* This method is useful when you set the `manuallyStartQueue` option to
|
973
|
+
* `true` in the {@link createFederation} function.
|
974
|
+
* @param contextData The context data to pass to the context.
|
975
|
+
* @param options Additional options for starting the queue.
|
976
|
+
*/
|
977
|
+
startQueue(contextData: TContextData, options?: FederationStartQueueOptions): Promise<void>;
|
978
|
+
/**
|
979
|
+
* Processes a queued message task. This method handles different types of
|
980
|
+
* tasks such as fanout, outbox, and inbox messages.
|
981
|
+
*
|
982
|
+
* Note that you usually do not need to call this method directly unless you
|
983
|
+
* are deploying your federated application on a platform that does not
|
984
|
+
* support long-running processing, such as Cloudflare Workers.
|
985
|
+
* @param contextData The context data to pass to the context.
|
986
|
+
* @param message The message that represents the task to be processed.
|
987
|
+
* @returns A promise that resolves when the message has been processed.
|
988
|
+
* @since 1.6.0
|
989
|
+
*/
|
990
|
+
processQueuedTask(contextData: TContextData, message: Message): Promise<void>;
|
991
|
+
/**
|
992
|
+
* Create a new context.
|
993
|
+
* @param baseUrl The base URL of the server. The `pathname` remains root,
|
994
|
+
* and the `search` and `hash` are stripped.
|
995
|
+
* @param contextData The context data to pass to the context.
|
996
|
+
* @returns The new context.
|
997
|
+
*/
|
998
|
+
createContext(baseUrl: URL, contextData: TContextData): Context<TContextData>;
|
999
|
+
/**
|
1000
|
+
* Create a new context for a request.
|
1001
|
+
* @param request The request object.
|
1002
|
+
* @param contextData The context data to pass to the context.
|
1003
|
+
* @returns The new request context.
|
1004
|
+
*/
|
1005
|
+
createContext(request: Request, contextData: TContextData): RequestContext<TContextData>;
|
1006
|
+
/**
|
1007
|
+
* Handles a request related to federation. If a request is not related to
|
1008
|
+
* federation, the `onNotFound` or `onNotAcceptable` callback is called.
|
1009
|
+
*
|
1010
|
+
* Usually, this method is called from a server's request handler or
|
1011
|
+
* a web framework's middleware.
|
1012
|
+
*
|
1013
|
+
* @param request The request object.
|
1014
|
+
* @param parameters The parameters for handling the request.
|
1015
|
+
* @returns The response to the request.
|
1016
|
+
*/
|
1017
|
+
fetch(request: Request, options: FederationFetchOptions<TContextData>): Promise<Response>;
|
1018
|
+
}
|
1019
|
+
/**
|
1020
|
+
* A builder for creating a {@link Federation} object. It defers the actual
|
1021
|
+
* instantiation of the {@link Federation} object until the {@link build}
|
1022
|
+
* method is called so that dispatchers and listeners can be registered
|
1023
|
+
* before the {@link Federation} object is instantiated.
|
1024
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
1025
|
+
* @since 1.6.0
|
1026
|
+
*/
|
1027
|
+
interface FederationBuilder<TContextData> extends Federatable<TContextData> {
|
1028
|
+
/**
|
1029
|
+
* Builds the federation object.
|
1030
|
+
* @returns The federation object.
|
1031
|
+
*/
|
1032
|
+
build(options: FederationOptions<TContextData>): Promise<Federation<TContextData>>;
|
1033
|
+
}
|
1034
|
+
/**
|
1035
|
+
* Options for creating a {@link Federation} object.
|
1036
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
1037
|
+
* @since 1.6.0
|
1038
|
+
*/
|
1039
|
+
interface FederationOptions<TContextData> {
|
1040
|
+
/**
|
1041
|
+
* The key–value store used for caching, outbox queues, and inbox idempotence.
|
1042
|
+
*/
|
1043
|
+
kv: KvStore;
|
1044
|
+
/**
|
1045
|
+
* Prefixes for namespacing keys in the Deno KV store. By default, all keys
|
1046
|
+
* are prefixed with `["_fedify"]`.
|
1047
|
+
*/
|
1048
|
+
kvPrefixes?: Partial<FederationKvPrefixes>;
|
1049
|
+
/**
|
1050
|
+
* The message queue for sending and receiving activities. If not provided,
|
1051
|
+
* activities will not be queued and will be processed immediately.
|
1052
|
+
*
|
1053
|
+
* If a `MessageQueue` is provided, both the `inbox` and `outbox` queues
|
1054
|
+
* will be set to the same queue.
|
1055
|
+
*
|
1056
|
+
* If a `FederationQueueOptions` object is provided, you can set the queues
|
1057
|
+
* separately (since Fedify 1.3.0).
|
1058
|
+
*/
|
1059
|
+
queue?: FederationQueueOptions | MessageQueue;
|
1060
|
+
/**
|
1061
|
+
* Whether to start the task queue manually or automatically.
|
1062
|
+
*
|
1063
|
+
* If `true`, the task queue will not start automatically and you need to
|
1064
|
+
* manually start it by calling the {@link Federation.startQueue} method.
|
1065
|
+
*
|
1066
|
+
* If `false`, the task queue will start automatically as soon as
|
1067
|
+
* the first task is enqueued.
|
1068
|
+
*
|
1069
|
+
* By default, the queue starts automatically.
|
1070
|
+
*
|
1071
|
+
* @since 0.12.0
|
1072
|
+
*/
|
1073
|
+
manuallyStartQueue?: boolean;
|
1074
|
+
/**
|
1075
|
+
* The canonical base URL of the server. This is used for constructing
|
1076
|
+
* absolute URLs and fediverse handles.
|
1077
|
+
* @since 1.5.0
|
1078
|
+
*/
|
1079
|
+
origin?: string | FederationOrigin;
|
1080
|
+
/**
|
1081
|
+
* A custom JSON-LD document loader factory. By default, this uses
|
1082
|
+
* the built-in cache-backed loader that fetches remote documents over
|
1083
|
+
* HTTP(S).
|
1084
|
+
* @since 1.4.0
|
1085
|
+
*/
|
1086
|
+
documentLoaderFactory?: DocumentLoaderFactory;
|
1087
|
+
/**
|
1088
|
+
* A custom JSON-LD context loader factory. By default, this uses the same
|
1089
|
+
* loader as the document loader.
|
1090
|
+
* @since 1.4.0
|
1091
|
+
*/
|
1092
|
+
contextLoaderFactory?: DocumentLoaderFactory;
|
1093
|
+
/**
|
1094
|
+
* A custom JSON-LD document loader. By default, this uses the built-in
|
1095
|
+
* cache-backed loader that fetches remote documents over HTTP(S).
|
1096
|
+
* @deprecated Use {@link documentLoaderFactory} instead.
|
1097
|
+
*/
|
1098
|
+
documentLoader?: DocumentLoader;
|
1099
|
+
/**
|
1100
|
+
* A custom JSON-LD context loader. By default, this uses the same loader
|
1101
|
+
* as the document loader.
|
1102
|
+
* @deprecated Use {@link contextLoaderFactory} instead.
|
1103
|
+
*/
|
1104
|
+
contextLoader?: DocumentLoader;
|
1105
|
+
/**
|
1106
|
+
* A factory function that creates an authenticated document loader for a
|
1107
|
+
* given identity. This is used for fetching documents that require
|
1108
|
+
* authentication.
|
1109
|
+
*/
|
1110
|
+
authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
|
1111
|
+
/**
|
1112
|
+
* Whether to allow fetching private network addresses in the document loader.
|
1113
|
+
*
|
1114
|
+
* If turned on, {@link CreateFederationOptions.documentLoader},
|
1115
|
+
* {@link CreateFederationOptions.contextLoader}, and
|
1116
|
+
* {@link CreateFederationOptions.authenticatedDocumentLoaderFactory}
|
1117
|
+
* cannot be configured.
|
1118
|
+
*
|
1119
|
+
* Mostly useful for testing purposes. *Do not use in production.*
|
1120
|
+
*
|
1121
|
+
* Turned off by default.
|
1122
|
+
* @since 0.15.0
|
1123
|
+
*/
|
1124
|
+
allowPrivateAddress?: boolean;
|
1125
|
+
/**
|
1126
|
+
* Options for making `User-Agent` strings for HTTP requests.
|
1127
|
+
* If a string is provided, it is used as the `User-Agent` header.
|
1128
|
+
* If an object is provided, it is passed to the {@link getUserAgent}
|
1129
|
+
* function.
|
1130
|
+
* @since 1.3.0
|
1131
|
+
*/
|
1132
|
+
userAgent?: GetUserAgentOptions | string;
|
1133
|
+
/**
|
1134
|
+
* A callback that handles errors during outbox processing. Note that this
|
1135
|
+
* callback can be called multiple times for the same activity, because
|
1136
|
+
* the delivery is retried according to the backoff schedule until it
|
1137
|
+
* succeeds or reaches the maximum retry count.
|
1138
|
+
*
|
1139
|
+
* If any errors are thrown in this callback, they are ignored.
|
1140
|
+
*/
|
1141
|
+
onOutboxError?: OutboxErrorHandler;
|
1142
|
+
/**
|
1143
|
+
* The time window for verifying HTTP Signatures of incoming requests. If the
|
1144
|
+
* request is older or newer than this window, it is rejected. Or if it is
|
1145
|
+
* `false`, the request's timestamp is not checked at all.
|
1146
|
+
*
|
1147
|
+
* By default, the window is an hour.
|
1148
|
+
*/
|
1149
|
+
signatureTimeWindow?: Temporal.Duration | Temporal.DurationLike | false;
|
1150
|
+
/**
|
1151
|
+
* Whether to skip HTTP Signatures verification for incoming activities.
|
1152
|
+
* This is useful for testing purposes, but should not be used in production.
|
1153
|
+
*
|
1154
|
+
* By default, this is `false` (i.e., signatures are verified).
|
1155
|
+
* @since 0.13.0
|
1156
|
+
*/
|
1157
|
+
skipSignatureVerification?: boolean;
|
1158
|
+
/**
|
1159
|
+
* The HTTP Signatures specification to use for the first signature
|
1160
|
+
* attempt when communicating with unknown servers. This option affects
|
1161
|
+
* the "double-knocking" mechanism as described in the ActivityPub HTTP
|
1162
|
+
* Signature documentation.
|
1163
|
+
*
|
1164
|
+
* When making HTTP requests to servers that haven't been encountered before,
|
1165
|
+
* Fedify will first attempt to sign the request using the specified
|
1166
|
+
* signature specification. If the request fails, it will retry with the
|
1167
|
+
* alternative specification.
|
1168
|
+
*
|
1169
|
+
* Defaults to `"rfc9421"` (HTTP Message Signatures).
|
1170
|
+
*
|
1171
|
+
* @see {@link https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions}
|
1172
|
+
* @default `"rfc9421"`
|
1173
|
+
* @since 1.7.0
|
1174
|
+
*/
|
1175
|
+
firstKnock?: HttpMessageSignaturesSpec;
|
1176
|
+
/**
|
1177
|
+
* The retry policy for sending activities to recipients' inboxes.
|
1178
|
+
* By default, this uses an exponential backoff strategy with a maximum of
|
1179
|
+
* 10 attempts and a maximum delay of 12 hours.
|
1180
|
+
* @since 0.12.0
|
1181
|
+
*/
|
1182
|
+
outboxRetryPolicy?: RetryPolicy;
|
1183
|
+
/**
|
1184
|
+
* The retry policy for processing incoming activities. By default, this
|
1185
|
+
* uses an exponential backoff strategy with a maximum of 10 attempts and a
|
1186
|
+
* maximum delay of 12 hours.
|
1187
|
+
* @since 0.12.0
|
1188
|
+
*/
|
1189
|
+
inboxRetryPolicy?: RetryPolicy;
|
1190
|
+
/**
|
1191
|
+
* Activity transformers that are applied to outgoing activities. It is
|
1192
|
+
* useful for adjusting outgoing activities to satisfy some ActivityPub
|
1193
|
+
* implementations.
|
1194
|
+
*
|
1195
|
+
* By default, {@link defaultActivityTransformers} are applied.
|
1196
|
+
* @since 1.4.0
|
1197
|
+
*/
|
1198
|
+
activityTransformers?: readonly ActivityTransformer<TContextData>[];
|
1199
|
+
/**
|
1200
|
+
* Whether the router should be insensitive to trailing slashes in the URL
|
1201
|
+
* paths. For example, if this option is `true`, `/foo` and `/foo/` are
|
1202
|
+
* treated as the same path. Turned off by default.
|
1203
|
+
* @since 0.12.0
|
1204
|
+
*/
|
1205
|
+
trailingSlashInsensitive?: boolean;
|
1206
|
+
/**
|
1207
|
+
* The OpenTelemetry tracer provider for tracing operations. If not provided,
|
1208
|
+
* the default global tracer provider is used.
|
1209
|
+
* @since 1.3.0
|
1210
|
+
*/
|
1211
|
+
tracerProvider?: TracerProvider;
|
1212
|
+
}
|
1213
|
+
/**
|
1214
|
+
* Additional settings for the actor dispatcher.
|
1215
|
+
*
|
1216
|
+
* ``` typescript
|
1217
|
+
* const federation = createFederation<void>({ ... });
|
1218
|
+
* federation
|
1219
|
+
* .setActorDispatcher("/users/{identifier}", async (ctx, identifier) => {
|
1220
|
+
* // ...
|
1221
|
+
* })
|
1222
|
+
* .setKeyPairsDispatcher(async (ctxData, identifier) => {
|
1223
|
+
* // ...
|
1224
|
+
* });
|
1225
|
+
* ```
|
1226
|
+
*/
|
1227
|
+
interface ActorCallbackSetters<TContextData> {
|
1228
|
+
/**
|
1229
|
+
* Sets the key pairs dispatcher for actors.
|
1230
|
+
* @param dispatcher A callback that returns the key pairs for an actor.
|
1231
|
+
* @returns The setters object so that settings can be chained.
|
1232
|
+
* @since 0.10.0
|
1233
|
+
*/
|
1234
|
+
setKeyPairsDispatcher(dispatcher: ActorKeyPairsDispatcher<TContextData>): ActorCallbackSetters<TContextData>;
|
1235
|
+
/**
|
1236
|
+
* Sets the callback function that maps a WebFinger username to
|
1237
|
+
* the corresponding actor's identifier. If it's omitted, the identifier
|
1238
|
+
* is assumed to be the same as the WebFinger username, which makes your
|
1239
|
+
* actors have the immutable handles. If you want to let your actors change
|
1240
|
+
* their fediverse handles, you should set this dispatcher.
|
1241
|
+
* @param mapper A callback that maps a WebFinger username to
|
1242
|
+
* the corresponding actor's identifier.
|
1243
|
+
* @returns The setters object so that settings can be chained.
|
1244
|
+
* @since 0.15.0
|
1245
|
+
*/
|
1246
|
+
mapHandle(mapper: ActorHandleMapper<TContextData>): ActorCallbackSetters<TContextData>;
|
1247
|
+
/**
|
1248
|
+
* Sets the callback function that maps a WebFinger query to the corresponding
|
1249
|
+
* actor's identifier or username. If it's omitted, the WebFinger handler
|
1250
|
+
* only supports the actor URIs and `acct:` URIs. If you want to support
|
1251
|
+
* other queries, you should set this dispatcher.
|
1252
|
+
* @param mapper A callback that maps a WebFinger query to the corresponding
|
1253
|
+
* actor's identifier or username.
|
1254
|
+
* @returns The setters object so that settings can be chained.
|
1255
|
+
* @since 1.4.0
|
1256
|
+
*/
|
1257
|
+
mapAlias(mapper: ActorAliasMapper<TContextData>): ActorCallbackSetters<TContextData>;
|
1258
|
+
/**
|
1259
|
+
* Specifies the conditions under which requests are authorized.
|
1260
|
+
* @param predicate A callback that returns whether a request is authorized.
|
1261
|
+
* @returns The setters object so that settings can be chained.
|
1262
|
+
* @since 0.7.0
|
1263
|
+
*/
|
1264
|
+
authorize(predicate: AuthorizePredicate<TContextData>): ActorCallbackSetters<TContextData>;
|
1265
|
+
}
|
1266
|
+
/**
|
1267
|
+
* Additional settings for an object dispatcher.
|
1268
|
+
*/
|
1269
|
+
interface ObjectCallbackSetters<TContextData, TObject extends Object$1, TParam extends string> {
|
1270
|
+
/**
|
1271
|
+
* Specifies the conditions under which requests are authorized.
|
1272
|
+
* @param predicate A callback that returns whether a request is authorized.
|
1273
|
+
* @returns The setters object so that settings can be chained.
|
1274
|
+
* @since 0.7.0
|
1275
|
+
*/
|
1276
|
+
authorize(predicate: ObjectAuthorizePredicate<TContextData, TParam>): ObjectCallbackSetters<TContextData, TObject, TParam>;
|
1277
|
+
}
|
1278
|
+
/**
|
1279
|
+
* Additional settings for a collection dispatcher.
|
1280
|
+
*
|
1281
|
+
* @template TContext The type of the context. {@link Context} or
|
1282
|
+
* {@link RequestContext}.
|
1283
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
1284
|
+
* @template TFilter The type of filter for the collection.
|
1285
|
+
*/
|
1286
|
+
interface CollectionCallbackSetters<TContext extends Context<TContextData>, TContextData, TFilter> {
|
1287
|
+
/**
|
1288
|
+
* Sets the counter for the collection.
|
1289
|
+
* @param counter A callback that returns the number of items in the collection.
|
1290
|
+
* @returns The setters object so that settings can be chained.
|
1291
|
+
*/
|
1292
|
+
setCounter(counter: CollectionCounter<TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
1293
|
+
/**
|
1294
|
+
* Sets the first cursor for the collection.
|
1295
|
+
* @param cursor The cursor for the first item in the collection.
|
1296
|
+
* @returns The setters object so that settings can be chained.
|
1297
|
+
*/
|
1298
|
+
setFirstCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
1299
|
+
/**
|
1300
|
+
* Sets the last cursor for the collection.
|
1301
|
+
* @param cursor The cursor for the last item in the collection.
|
1302
|
+
* @returns The setters object so that settings can be chained.
|
1303
|
+
*/
|
1304
|
+
setLastCursor(cursor: CollectionCursor<TContext, TContextData, TFilter>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
1305
|
+
/**
|
1306
|
+
* Specifies the conditions under which requests are authorized.
|
1307
|
+
* @param predicate A callback that returns whether a request is authorized.
|
1308
|
+
* @returns The setters object so that settings can be chained.
|
1309
|
+
* @since 0.7.0
|
1310
|
+
*/
|
1311
|
+
authorize(predicate: AuthorizePredicate<TContextData>): CollectionCallbackSetters<TContext, TContextData, TFilter>;
|
1312
|
+
}
|
1313
|
+
/**
|
1314
|
+
* Registry for inbox listeners for different activity types.
|
1315
|
+
*/
|
1316
|
+
interface InboxListenerSetters<TContextData> {
|
1317
|
+
/**
|
1318
|
+
* Registers a listener for a specific incoming activity type.
|
1319
|
+
*
|
1320
|
+
* @param type A subclass of {@link Activity} to listen to.
|
1321
|
+
* @param listener A callback to handle an incoming activity.
|
1322
|
+
* @returns The setters object so that settings can be chained.
|
1323
|
+
*/
|
1324
|
+
on<TActivity extends Activity>(type: new (...args: any[]) => TActivity, listener: InboxListener<TContextData, TActivity>): InboxListenerSetters<TContextData>;
|
1325
|
+
/**
|
1326
|
+
* Registers an error handler for inbox listeners. Any exceptions thrown
|
1327
|
+
* from the listeners are caught and passed to this handler.
|
1328
|
+
*
|
1329
|
+
* @param handler A callback to handle an error.
|
1330
|
+
* @returns The setters object so that settings can be chained.
|
1331
|
+
*/
|
1332
|
+
onError(handler: InboxErrorHandler<TContextData>): InboxListenerSetters<TContextData>;
|
1333
|
+
/**
|
1334
|
+
* Configures a callback to dispatch the key pair for the authenticated
|
1335
|
+
* document loader of the {@link Context} passed to the shared inbox listener.
|
1336
|
+
*
|
1337
|
+
* @param dispatcher A callback to dispatch the key pair for the authenticated
|
1338
|
+
* document loader.
|
1339
|
+
* @returns The setters object so that settings can be chained.
|
1340
|
+
* @since 0.11.0
|
1341
|
+
*/
|
1342
|
+
setSharedKeyDispatcher(dispatcher: SharedInboxKeyDispatcher<TContextData>): InboxListenerSetters<TContextData>;
|
1343
|
+
}
|
1344
|
+
/**
|
1345
|
+
* Parameters of {@link Federation.fetch} method.
|
1346
|
+
*
|
1347
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
1348
|
+
* @since 0.6.0
|
1349
|
+
*/
|
1350
|
+
interface FederationFetchOptions<TContextData> {
|
1351
|
+
/**
|
1352
|
+
* The context data to pass to the {@link Context}.
|
1353
|
+
*/
|
1354
|
+
contextData: TContextData;
|
1355
|
+
/**
|
1356
|
+
* A callback to handle a request when the route is not found.
|
1357
|
+
* If not provided, a 404 response is returned.
|
1358
|
+
* @param request The request object.
|
1359
|
+
* @returns The response to the request.
|
1360
|
+
*/
|
1361
|
+
onNotFound?: (request: Request) => Response | Promise<Response>;
|
1362
|
+
/**
|
1363
|
+
* A callback to handle a request when the request's `Accept` header is not
|
1364
|
+
* acceptable. If not provided, a 406 response is returned.
|
1365
|
+
* @param request The request object.
|
1366
|
+
* @returns The response to the request.
|
1367
|
+
*/
|
1368
|
+
onNotAcceptable?: (request: Request) => Response | Promise<Response>;
|
1369
|
+
/**
|
1370
|
+
* A callback to handle a request when the request is unauthorized.
|
1371
|
+
* If not provided, a 401 response is returned.
|
1372
|
+
* @param request The request object.
|
1373
|
+
* @returns The response to the request.
|
1374
|
+
* @since 0.7.0
|
1375
|
+
*/
|
1376
|
+
onUnauthorized?: (request: Request) => Response | Promise<Response>;
|
1377
|
+
}
|
1378
|
+
/**
|
1379
|
+
* Additional settings for a custom collection dispatcher.
|
1380
|
+
*
|
1381
|
+
* @template TParams The type of the parameters in the URL path.
|
1382
|
+
* @template TContext The type of the context. {@link Context} or
|
1383
|
+
* {@link RequestContext}.
|
1384
|
+
* @template TContextData The context data to pass to the {@link Context}.
|
1385
|
+
* @template TFilter The type of filter for the collection.
|
1386
|
+
*/
|
1387
|
+
interface CustomCollectionCallbackSetters<TParams extends Record<string, string>, TContext extends Context<TContextData>, TContextData> {
|
1388
|
+
/**
|
1389
|
+
* Sets the counter for the custom collection.
|
1390
|
+
* @param counter A callback that returns the number of items in the custom collection.
|
1391
|
+
* @returns The setters object so that settings can be chained.
|
1392
|
+
*/
|
1393
|
+
setCounter(counter: CustomCollectionCounter<TParams, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
1394
|
+
/**
|
1395
|
+
* Sets the first cursor for the custom collection.
|
1396
|
+
* @param cursor The cursor for the first item in the custom collection.
|
1397
|
+
* @returns The setters object so that settings can be chained.
|
1398
|
+
*/
|
1399
|
+
setFirstCursor(cursor: CustomCollectionCursor<TParams, TContext, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
1400
|
+
/**
|
1401
|
+
* Sets the last cursor for the custom collection.
|
1402
|
+
* @param cursor The cursor for the last item in the custom collection.
|
1403
|
+
* @returns The setters object so that settings can be chained.
|
1404
|
+
*/
|
1405
|
+
setLastCursor(cursor: CustomCollectionCursor<TParams, TContext, TContextData>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
1406
|
+
/**
|
1407
|
+
* Specifies the conditions under which requests are authorized.
|
1408
|
+
* @param predicate A callback that returns whether a request is authorized.
|
1409
|
+
* @returns The setters object so that settings can be chained.
|
1410
|
+
* @since 0.7.0
|
1411
|
+
*/
|
1412
|
+
authorize(predicate: ObjectAuthorizePredicate<TContextData, string>): CustomCollectionCallbackSetters<TParams, TContext, TContextData>;
|
1413
|
+
}
|
1414
|
+
/**
|
1415
|
+
* Represents an object with a type ID, which is either a constructor or an
|
1416
|
+
* instance of the object.
|
1417
|
+
*
|
1418
|
+
* @template TObject The type of the object.
|
1419
|
+
*/
|
1420
|
+
type ConstructorWithTypeId<TObject extends Object$1> = (new (...args: any[]) => TObject) & {
|
1421
|
+
typeId: URL;
|
1422
|
+
};
|
1423
|
+
/**
|
1424
|
+
* Represents a path from the key of parameter objects.
|
1425
|
+
* @param Params - A record of parameters where keys are parameter names and
|
1426
|
+
* values are their string representations.
|
1427
|
+
* @returns A string representing the path with all parameters.
|
1428
|
+
* @example
|
1429
|
+
* ```ts
|
1430
|
+
* type UserPostPath = ParamsKeyPath<{ userId: string; postId: string }>;
|
1431
|
+
* let userPostPath: UserPostPath;
|
1432
|
+
* // userPostPath = "/posts/{postId}"; // invalid - does not contain `{userId}`
|
1433
|
+
* // userPostPath = "/users/{userId}"; // invalid - does not contain `{postId}`
|
1434
|
+
* userPostPath = "/users/{userId}/posts/{postId}"; // valid
|
1435
|
+
* userPostPath = "/posts/{postId}/users/{userId}"; // valid
|
1436
|
+
* ```
|
1437
|
+
*/
|
1438
|
+
type ParamsKeyPath<Params extends Record<string, string>> = ParamsPath<Extract<keyof Params, string>> & string;
|
1439
|
+
/**
|
1440
|
+
* Represents a path with multiple parameters.
|
1441
|
+
* All permutations of the parameters are included in the union type.
|
1442
|
+
* The path must have all parameters in the form of `{paramName}`.
|
1443
|
+
* @param Params - A union of parameter names.
|
1444
|
+
* @returns A string representing the path with all parameters.
|
1445
|
+
* @example
|
1446
|
+
* ```ts
|
1447
|
+
* type UserPostPath = ParamsPath<"userId" | "postId">;
|
1448
|
+
* // = `${string}{userId}${string}` & `${string}{postId}${string}`
|
1449
|
+
* // =
|
1450
|
+
* // | `${string}{userId}${string}{postId}${string}`
|
1451
|
+
* // | `${string}{postId}${string}{userId}${string}`
|
1452
|
+
* let userPostPath: UserPostPath;
|
1453
|
+
* userPostPath = "/users/posts"; // ❌ invalid
|
1454
|
+
* userPostPath = "/users/{userId}"; // ❌ invalid
|
1455
|
+
* userPostPath = "/posts/{postId}"; // ❌ invalid
|
1456
|
+
* userPostPath = "/users/{userId}/posts/{postId}"; // ✅ valid
|
1457
|
+
* userPostPath = "/posts/{postId}/users/{userId}"; // ✅ valid
|
1458
|
+
*/
|
1459
|
+
type ParamsPath<Params extends string> = UnionToIntersection<ParamPath<Params>>;
|
1460
|
+
/**
|
1461
|
+
* Represents a path with a single parameter.
|
1462
|
+
* The path must have at least one of the parameters in the form of `{paramName}`.
|
1463
|
+
* @param Param - The name of the parameter.
|
1464
|
+
* @returns A string representing the path with the parameter.
|
1465
|
+
* @example
|
1466
|
+
* ```ts
|
1467
|
+
* type UserPostPath = ParamPath<"userId" | "postId">;
|
1468
|
+
* // = `${string}{userId}${string}` | `${string}{postId}${string}`
|
1469
|
+
* let userPostPath: UserPostPath;
|
1470
|
+
* userPostPath = "/users/posts"; // ❌ invalid
|
1471
|
+
* userPostPath = "/users/{userId}"; // ✅ valid
|
1472
|
+
* userPostPath = "/posts/{postId}"; // ✅ valid
|
1473
|
+
* userPostPath = "/users/{userId}/posts/{postId}"; // ✅ valid
|
1474
|
+
* userPostPath = "/posts/{postId}/users/{userId}"; // ✅ valid
|
1475
|
+
*/
|
1476
|
+
type ParamPath<Param extends string> = `${string}{${Param}}${string}`;
|
1477
|
+
/**
|
1478
|
+
* Converts union types to intersection types.
|
1479
|
+
*
|
1480
|
+
* @template U - The union type to convert.
|
1481
|
+
* @returns The intersection type of the union.
|
1482
|
+
* @example
|
1483
|
+
* ```ts
|
1484
|
+
* type A = { a: string };
|
1485
|
+
* type B = { b: number };
|
1486
|
+
* type AorB = A | B;
|
1487
|
+
* type AandB = UnionToIntersection<AorB>;
|
1488
|
+
* // AandB = { a: string; b: number }
|
1489
|
+
*/
|
1490
|
+
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
1491
|
+
//#endregion
|
1492
|
+
//#region src/federation/context.d.ts
|
1493
|
+
/**
|
1494
|
+
* A context.
|
1495
|
+
*/
|
1496
|
+
interface Context<TContextData> {
|
1497
|
+
/**
|
1498
|
+
* The origin of the federated server, including the scheme (`http://` or
|
1499
|
+
* `https://`) and the host (e.g., `example.com:8080`).
|
1500
|
+
* @since 0.12.0
|
1501
|
+
*/
|
1502
|
+
readonly origin: string;
|
1503
|
+
/**
|
1504
|
+
* The canonical origin of the federated server, including the scheme
|
1505
|
+
* (`http://` or `https://`) and the host (e.g., `example.com:8080`).
|
1506
|
+
*
|
1507
|
+
* When the associated {@link Federation} object does not have any explicit
|
1508
|
+
* canonical origin, it is the same as the {@link Context.origin}.
|
1509
|
+
* @since 1.5.0
|
1510
|
+
*/
|
1511
|
+
readonly canonicalOrigin: string;
|
1512
|
+
/**
|
1513
|
+
* The host of the federated server, including the hostname
|
1514
|
+
* (e.g., `example.com`) and the port following a colon (e.g., `:8080`)
|
1515
|
+
* if it is not the default port for the scheme.
|
1516
|
+
* @since 0.12.0
|
1517
|
+
*/
|
1518
|
+
readonly host: string;
|
1519
|
+
/**
|
1520
|
+
* The hostname of the federated server (e.g., `example.com`). This is
|
1521
|
+
* the same as the host without the port.
|
1522
|
+
* @since 0.12.0
|
1523
|
+
*/
|
1524
|
+
readonly hostname: string;
|
1525
|
+
/**
|
1526
|
+
* The user-defined data associated with the context.
|
1527
|
+
*/
|
1528
|
+
readonly data: TContextData;
|
1529
|
+
/**
|
1530
|
+
* The OpenTelemetry tracer provider.
|
1531
|
+
* @since 1.3.0
|
1532
|
+
*/
|
1533
|
+
readonly tracerProvider: TracerProvider;
|
1534
|
+
/**
|
1535
|
+
* The document loader for loading remote JSON-LD documents.
|
1536
|
+
*/
|
1537
|
+
readonly documentLoader: DocumentLoader;
|
1538
|
+
/**
|
1539
|
+
* The context loader for loading remote JSON-LD contexts.
|
1540
|
+
*/
|
1541
|
+
readonly contextLoader: DocumentLoader;
|
1542
|
+
/**
|
1543
|
+
* The federation object that this context belongs to.
|
1544
|
+
* @since 1.6.0
|
1545
|
+
*/
|
1546
|
+
readonly federation: Federation<TContextData>;
|
1547
|
+
/**
|
1548
|
+
* Creates a new context with the same properties as this one,
|
1549
|
+
* but with the given data.
|
1550
|
+
* @param data The new data to associate with the context.
|
1551
|
+
* @returns A new context with the same properties as this one,
|
1552
|
+
* but with the given data.
|
1553
|
+
* @since 1.6.0
|
1554
|
+
*/
|
1555
|
+
clone(data: TContextData): Context<TContextData>;
|
1556
|
+
/**
|
1557
|
+
* Builds the URI of the NodeInfo document.
|
1558
|
+
* @returns The NodeInfo URI.
|
1559
|
+
* @throws {RouterError} If no NodeInfo dispatcher is available.
|
1560
|
+
* @since 0.2.0
|
1561
|
+
*/
|
1562
|
+
getNodeInfoUri(): URL;
|
1563
|
+
/**
|
1564
|
+
* Builds the URI of an actor with the given identifier.
|
1565
|
+
* @param identifier The actor's identifier.
|
1566
|
+
* @returns The actor's URI.
|
1567
|
+
* @throws {RouterError} If no actor dispatcher is available.
|
1568
|
+
*/
|
1569
|
+
getActorUri(identifier: string): URL;
|
1570
|
+
/**
|
1571
|
+
* Builds the URI of an object with the given class and values.
|
1572
|
+
* @param cls The class of the object.
|
1573
|
+
* @param values The values to pass to the object dispatcher.
|
1574
|
+
* @returns The object's URI.
|
1575
|
+
* @throws {RouteError} If no object dispatcher is available for the class.
|
1576
|
+
* @throws {TypeError} If values are invalid.
|
1577
|
+
* @since 0.7.0
|
1578
|
+
*/
|
1579
|
+
getObjectUri<TObject extends Object$1>(cls: (new (...args: any[]) => TObject) & {
|
1580
|
+
typeId: URL;
|
1581
|
+
}, values: Record<string, string>): URL;
|
1582
|
+
/**
|
1583
|
+
* Builds the URI of an actor's outbox with the given identifier.
|
1584
|
+
* @param identifier The actor's identifier.
|
1585
|
+
* @returns The actor's outbox URI.
|
1586
|
+
* @throws {RouterError} If no outbox dispatcher is available.
|
1587
|
+
*/
|
1588
|
+
getOutboxUri(identifier: string): URL;
|
1589
|
+
/**
|
1590
|
+
* Builds the URI of the shared inbox.
|
1591
|
+
* @returns The shared inbox URI.
|
1592
|
+
* @throws {RouterError} If no inbox listener is available.
|
1593
|
+
*/
|
1594
|
+
getInboxUri(): URL;
|
1595
|
+
/**
|
1596
|
+
* Builds the URI of an actor's inbox with the given identifier.
|
1597
|
+
* @param identifier The actor's identifier.
|
1598
|
+
* @returns The actor's inbox URI.
|
1599
|
+
* @throws {RouterError} If no inbox listener is available.
|
1600
|
+
*/
|
1601
|
+
getInboxUri(identifier: string): URL;
|
1602
|
+
/**
|
1603
|
+
* Builds the URI of an actor's following collection with the given
|
1604
|
+
* identifier.
|
1605
|
+
* @param identifier The actor's identifier.
|
1606
|
+
* @returns The actor's following collection URI.
|
1607
|
+
* @throws {RouterError} If no following collection is available.
|
1608
|
+
*/
|
1609
|
+
getFollowingUri(identifier: string): URL;
|
1610
|
+
/**
|
1611
|
+
* Builds the URI of an actor's followers collection with the given
|
1612
|
+
* identifier.
|
1613
|
+
* @param identifier The actor's identifier.
|
1614
|
+
* @returns The actor's followers collection URI.
|
1615
|
+
* @throws {RouterError} If no followers collection is available.
|
1616
|
+
*/
|
1617
|
+
getFollowersUri(identifier: string): URL;
|
1618
|
+
/**
|
1619
|
+
* Builds the URI of an actor's liked collection with the given identifier.
|
1620
|
+
* @param identifier The actor's identifier.
|
1621
|
+
* @returns The actor's liked collection URI.
|
1622
|
+
* @throws {RouterError} If no liked collection is available.
|
1623
|
+
* @since 0.11.0
|
1624
|
+
*/
|
1625
|
+
getLikedUri(identifier: string): URL;
|
1626
|
+
/**
|
1627
|
+
* Builds the URI of an actor's featured collection with the given identifier.
|
1628
|
+
* @param identifier The actor's identifier.
|
1629
|
+
* @returns The actor's featured collection URI.
|
1630
|
+
* @throws {RouterError} If no featured collection is available.
|
1631
|
+
* @since 0.11.0
|
1632
|
+
*/
|
1633
|
+
getFeaturedUri(identifier: string): URL;
|
1634
|
+
/**
|
1635
|
+
* Builds the URI of an actor's featured tags collection with the given
|
1636
|
+
* identifier.
|
1637
|
+
* @param identifier The actor's identifier.
|
1638
|
+
* @returns The actor's featured tags collection URI.
|
1639
|
+
* @throws {RouterError} If no featured tags collection is available.
|
1640
|
+
* @since 0.11.0
|
1641
|
+
*/
|
1642
|
+
getFeaturedTagsUri(identifier: string): URL;
|
1643
|
+
/**
|
1644
|
+
* Determines the type of the URI and extracts the associated data.
|
1645
|
+
* @param uri The URI to parse.
|
1646
|
+
* @returns The result of parsing the URI. If `null` is given or
|
1647
|
+
* the URI is not recognized, `null` is returned.
|
1648
|
+
* @since 0.9.0
|
1649
|
+
*/
|
1650
|
+
parseUri(uri: URL | null): ParseUriResult | null;
|
1651
|
+
/**
|
1652
|
+
* Gets the key pairs for an actor.
|
1653
|
+
* @param identifier The actor's identifier.
|
1654
|
+
* @returns An async iterable of the actor's key pairs. It can be empty.
|
1655
|
+
* @since 0.10.0
|
1656
|
+
*/
|
1657
|
+
getActorKeyPairs(identifier: string): Promise<ActorKeyPair[]>;
|
1658
|
+
/**
|
1659
|
+
* Gets an authenticated {@link DocumentLoader} for the given identity.
|
1660
|
+
* Note that an authenticated document loader intentionally does not cache
|
1661
|
+
* the fetched documents.
|
1662
|
+
* @param identity The identity to get the document loader for.
|
1663
|
+
* The actor's identifier or username.
|
1664
|
+
* @returns The authenticated document loader.
|
1665
|
+
* @throws {Error} If the identity is not valid.
|
1666
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
1667
|
+
* @since 0.4.0
|
1668
|
+
*/
|
1669
|
+
getDocumentLoader(identity: {
|
1670
|
+
identifier: string;
|
1671
|
+
} | {
|
1672
|
+
username: string;
|
1673
|
+
} | {
|
1674
|
+
handle: string;
|
1675
|
+
}): Promise<DocumentLoader>;
|
1676
|
+
/**
|
1677
|
+
* Gets an authenticated {@link DocumentLoader} for the given identity.
|
1678
|
+
* Note that an authenticated document loader intentionally does not cache
|
1679
|
+
* the fetched documents.
|
1680
|
+
* @param identity The identity to get the document loader for.
|
1681
|
+
* The actor's key pair.
|
1682
|
+
* @returns The authenticated document loader.
|
1683
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
1684
|
+
* @since 0.4.0
|
1685
|
+
*/
|
1686
|
+
getDocumentLoader(identity: {
|
1687
|
+
keyId: URL;
|
1688
|
+
privateKey: CryptoKey;
|
1689
|
+
}): DocumentLoader;
|
1690
|
+
/**
|
1691
|
+
* Looks up an ActivityStreams object by its URI (including `acct:` URIs)
|
1692
|
+
* or a fediverse handle (e.g., `@user@server` or `user@server`).
|
1693
|
+
*
|
1694
|
+
* @example
|
1695
|
+
* ``` typescript
|
1696
|
+
* // Look up an actor by its fediverse handle:
|
1697
|
+
* await ctx.lookupObject("@hongminhee@fosstodon.org");
|
1698
|
+
* // returning a `Person` object.
|
1699
|
+
*
|
1700
|
+
* // A fediverse handle can omit the leading '@':
|
1701
|
+
* await ctx.lookupObject("hongminhee@fosstodon.org");
|
1702
|
+
* // returning a `Person` object.
|
1703
|
+
*
|
1704
|
+
* // A `acct:` URI can be used as well:
|
1705
|
+
* await ctx.lookupObject("acct:hongminhee@fosstodon.org");
|
1706
|
+
* // returning a `Person` object.
|
1707
|
+
*
|
1708
|
+
* // Look up an object by its URI:
|
1709
|
+
* await ctx.lookupObject("https://todon.eu/@hongminhee/112060633798771581");
|
1710
|
+
* // returning a `Note` object.
|
1711
|
+
*
|
1712
|
+
* // It can be a `URL` object as well:
|
1713
|
+
* await ctx.lookupObject(
|
1714
|
+
* new URL("https://todon.eu/@hongminhee/112060633798771581")
|
1715
|
+
* );
|
1716
|
+
* // returning a `Note` object.
|
1717
|
+
* ```
|
1718
|
+
*
|
1719
|
+
* It's almost the same as the {@link lookupObject} function, but it uses
|
1720
|
+
* the context's document loader and context loader by default.
|
1721
|
+
*
|
1722
|
+
* @param identifier The URI or fediverse handle to look up.
|
1723
|
+
* @param options Lookup options.
|
1724
|
+
* @returns The object, or `null` if not found.
|
1725
|
+
* @since 0.15.0
|
1726
|
+
*/
|
1727
|
+
lookupObject(identifier: string | URL, options?: LookupObjectOptions): Promise<Object$1 | null>;
|
1728
|
+
/**
|
1729
|
+
* Traverses a collection, yielding each item in the collection.
|
1730
|
+
* If the collection is paginated, it will fetch the next page
|
1731
|
+
* automatically.
|
1732
|
+
*
|
1733
|
+
* @example
|
1734
|
+
* ``` typescript
|
1735
|
+
* const collection = await ctx.lookupObject(collectionUrl);
|
1736
|
+
* if (collection instanceof Collection) {
|
1737
|
+
* for await (const item of ctx.traverseCollection(collection)) {
|
1738
|
+
* console.log(item.id?.href);
|
1739
|
+
* }
|
1740
|
+
* }
|
1741
|
+
* ```
|
1742
|
+
*
|
1743
|
+
* It's almost the same as the {@link traverseCollection} function, but it
|
1744
|
+
* uses the context's document loader and context loader by default.
|
1745
|
+
* @param collection The collection to traverse.
|
1746
|
+
* @param options Options for traversing the collection.
|
1747
|
+
* @returns An async iterable of each item in the collection.
|
1748
|
+
* @since 1.1.0
|
1749
|
+
*/
|
1750
|
+
traverseCollection(collection: Collection, options?: TraverseCollectionOptions): AsyncIterable<Object$1 | Link>;
|
1751
|
+
/**
|
1752
|
+
* Fetches the NodeInfo document from the given URL.
|
1753
|
+
* @param url The base URL of the server. If `options.direct` is turned off
|
1754
|
+
* (default), the NodeInfo document will be fetched from
|
1755
|
+
* the `.well-known` location of this URL (hence the only origin
|
1756
|
+
* of the URL is used). If `options.direct` is turned on,
|
1757
|
+
* the NodeInfo document will be fetched from the given URL.
|
1758
|
+
* @param options Options for fetching the NodeInfo document.
|
1759
|
+
* @returns The NodeInfo document if it could be fetched successfully.
|
1760
|
+
* Otherwise, `undefined` is returned.
|
1761
|
+
* @since 1.4.0
|
1762
|
+
*/
|
1763
|
+
lookupNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
|
1764
|
+
parse?: "strict" | "best-effort";
|
1765
|
+
}): Promise<NodeInfo | undefined>;
|
1766
|
+
/**
|
1767
|
+
* Fetches the NodeInfo document from the given URL.
|
1768
|
+
* @param url The base URL of the server. If `options.direct` is turned off
|
1769
|
+
* (default), the NodeInfo document will be fetched from
|
1770
|
+
* the `.well-known` location of this URL (hence the only origin
|
1771
|
+
* of the URL is used). If `options.direct` is turned on,
|
1772
|
+
* the NodeInfo document will be fetched from the given URL.
|
1773
|
+
* @param options Options for fetching the NodeInfo document.
|
1774
|
+
* @returns The NodeInfo document if it could be fetched successfully.
|
1775
|
+
* Otherwise, `undefined` is returned.
|
1776
|
+
* @since 1.4.0
|
1777
|
+
*/
|
1778
|
+
lookupNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
|
1779
|
+
parse: "none";
|
1780
|
+
}): Promise<JsonValue | undefined>;
|
1781
|
+
/**
|
1782
|
+
* Looks up a WebFinger resource.
|
1783
|
+
*
|
1784
|
+
* It's almost the same as the {@link lookupWebFinger} function, but it uses
|
1785
|
+
* the context's configuration by default.
|
1786
|
+
*
|
1787
|
+
* @param resource The resource URL to look up.
|
1788
|
+
* @param options Extra options for looking up the resource.
|
1789
|
+
* @returns The resource descriptor, or `null` if not found.
|
1790
|
+
* @since 1.6.0
|
1791
|
+
*/
|
1792
|
+
lookupWebFinger(resource: URL | string, options?: LookupWebFingerOptions): Promise<ResourceDescriptor | null>;
|
1793
|
+
/**
|
1794
|
+
* Sends an activity to recipients' inboxes.
|
1795
|
+
* @param sender The sender's identifier or the sender's username or
|
1796
|
+
* the sender's key pair(s).
|
1797
|
+
* @param recipients The recipients of the activity.
|
1798
|
+
* @param activity The activity to send.
|
1799
|
+
* @param options Options for sending the activity.
|
1800
|
+
*/
|
1801
|
+
sendActivity(sender: SenderKeyPair | SenderKeyPair[] | {
|
1802
|
+
identifier: string;
|
1803
|
+
} | {
|
1804
|
+
username: string;
|
1805
|
+
} | {
|
1806
|
+
handle: string;
|
1807
|
+
}, recipients: Recipient | Recipient[], activity: Activity, options?: SendActivityOptions): Promise<void>;
|
1808
|
+
/**
|
1809
|
+
* Sends an activity to the outboxes of the sender's followers.
|
1810
|
+
* @param sender The sender's identifier or the sender's username.
|
1811
|
+
* @param recipients In this case, it must be `"followers"`.
|
1812
|
+
* @param activity The activity to send.
|
1813
|
+
* @param options Options for sending the activity.
|
1814
|
+
* @throws {Error} If no followers collection is registered.
|
1815
|
+
* @since 0.14.0
|
1816
|
+
*/
|
1817
|
+
sendActivity(sender: {
|
1818
|
+
identifier: string;
|
1819
|
+
} | {
|
1820
|
+
username: string;
|
1821
|
+
} | {
|
1822
|
+
handle: string;
|
1823
|
+
}, recipients: "followers", activity: Activity, options?: SendActivityOptionsForCollection): Promise<void>;
|
1824
|
+
/**
|
1825
|
+
* Manually routes an activity to the appropriate inbox listener.
|
1826
|
+
*
|
1827
|
+
* It is useful for routing an activity that is not received from the network,
|
1828
|
+
* or for routing an activity that is enclosed in another activity.
|
1829
|
+
*
|
1830
|
+
* Note that the activity will be verified if it has Object Integrity Proofs
|
1831
|
+
* or is equivalent to the actual remote object. If the activity is not
|
1832
|
+
* verified, it will be rejected.
|
1833
|
+
* @param recipient The recipient of the activity. If it is `null`,
|
1834
|
+
* the activity will be routed to the shared inbox.
|
1835
|
+
* Otherwise, the activity will be routed to the personal
|
1836
|
+
* inbox of the recipient with the given identifier.
|
1837
|
+
* @param activity The activity to route. It must have a proof or
|
1838
|
+
* a dereferenceable `id` to verify the activity.
|
1839
|
+
* @param options Options for routing the activity.
|
1840
|
+
* @returns `true` if the activity is successfully verified and routed.
|
1841
|
+
* Otherwise, `false`.
|
1842
|
+
* @since 1.3.0
|
1843
|
+
*/
|
1844
|
+
routeActivity(recipient: string | null, activity: Activity, options?: RouteActivityOptions): Promise<boolean>;
|
1845
|
+
/**
|
1846
|
+
* Builds the URI of a collection of objects with the given name and values.
|
1847
|
+
* @param name The name of the collection, which can be a string or a symbol.
|
1848
|
+
* @param values The values of the URI parameters.
|
1849
|
+
* @return The URI of the collection.
|
1850
|
+
* @throws {RouteError} If no object dispatcher is available for the name.
|
1851
|
+
* @throws {TypeError} If values are invalid.
|
1852
|
+
* @since 1.8.0
|
1853
|
+
*/
|
1854
|
+
getCollectionUri<TParam extends Record<string, string>>(name: string | symbol, values: TParam): URL;
|
1855
|
+
}
|
1856
|
+
/**
|
1857
|
+
* A context for a request.
|
1858
|
+
*/
|
1859
|
+
interface RequestContext<TContextData> extends Context<TContextData> {
|
1860
|
+
/**
|
1861
|
+
* The request object.
|
1862
|
+
*/
|
1863
|
+
readonly request: Request;
|
1864
|
+
/**
|
1865
|
+
* The URL of the request.
|
1866
|
+
*/
|
1867
|
+
readonly url: URL;
|
1868
|
+
/**
|
1869
|
+
* Creates a new context with the same properties as this one,
|
1870
|
+
* but with the given data.
|
1871
|
+
* @param data The new data to associate with the context.
|
1872
|
+
* @returns A new context with the same properties as this one,
|
1873
|
+
* but with the given data.
|
1874
|
+
* @since 1.6.0
|
1875
|
+
*/
|
1876
|
+
clone(data: TContextData): RequestContext<TContextData>;
|
1877
|
+
/**
|
1878
|
+
* Gets an {@link Actor} object for the given identifier.
|
1879
|
+
* @param identifier The actor's identifier.
|
1880
|
+
* @returns The actor object, or `null` if the actor is not found.
|
1881
|
+
* @throws {Error} If no actor dispatcher is available.
|
1882
|
+
* @since 0.7.0
|
1883
|
+
*/
|
1884
|
+
getActor(identifier: string): Promise<Actor | null>;
|
1885
|
+
/**
|
1886
|
+
* Gets an object of the given class with the given values.
|
1887
|
+
* @param cls The class to instantiate.
|
1888
|
+
* @param values The values to pass to the object dispatcher.
|
1889
|
+
* @returns The object of the given class with the given values, or `null`
|
1890
|
+
* if the object is not found.
|
1891
|
+
* @throws {Error} If no object dispatcher is available for the class.
|
1892
|
+
* @throws {TypeError} If values are invalid.
|
1893
|
+
* @since 0.7.0
|
1894
|
+
*/
|
1895
|
+
getObject<TObject extends Object$1>(cls: (new (...args: any[]) => TObject) & {
|
1896
|
+
typeId: URL;
|
1897
|
+
}, values: Record<string, string>): Promise<TObject | null>;
|
1898
|
+
/**
|
1899
|
+
* Gets the public key of the sender, if any exists and it is verified.
|
1900
|
+
* Otherwise, `null` is returned.
|
1901
|
+
*
|
1902
|
+
* This can be used for implementing [authorized fetch] (also known as
|
1903
|
+
* secure mode) in ActivityPub.
|
1904
|
+
*
|
1905
|
+
* [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
|
1906
|
+
*
|
1907
|
+
* @returns The public key of the sender, or `null` if the sender is not verified.
|
1908
|
+
* @since 0.7.0
|
1909
|
+
*/
|
1910
|
+
getSignedKey(): Promise<CryptographicKey | null>;
|
1911
|
+
/**
|
1912
|
+
* Gets the public key of the sender, if any exists and it is verified.
|
1913
|
+
* Otherwise, `null` is returned.
|
1914
|
+
*
|
1915
|
+
* This can be used for implementing [authorized fetch] (also known as
|
1916
|
+
* secure mode) in ActivityPub.
|
1917
|
+
*
|
1918
|
+
* [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
|
1919
|
+
*
|
1920
|
+
* @param options Options for getting the signed key. You usually may want to
|
1921
|
+
* specify the custom `documentLoader` so that making
|
1922
|
+
* an HTTP request to the sender's server is signed with
|
1923
|
+
* your [instance actor].
|
1924
|
+
* @returns The public key of the sender, or `null` if the sender is not verified.
|
1925
|
+
* @since 1.5.0
|
1926
|
+
*
|
1927
|
+
* [instance actor]: https://swicg.github.io/activitypub-http-signature/#instance-actor
|
1928
|
+
*/
|
1929
|
+
getSignedKey(options: GetSignedKeyOptions): Promise<CryptographicKey | null>;
|
1930
|
+
/**
|
1931
|
+
* Gets the owner of the signed key, if any exists and it is verified.
|
1932
|
+
* Otherwise, `null` is returned.
|
1933
|
+
*
|
1934
|
+
* This can be used for implementing [authorized fetch] (also known as
|
1935
|
+
* secure mode) in ActivityPub.
|
1936
|
+
*
|
1937
|
+
* [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
|
1938
|
+
*
|
1939
|
+
* @returns The owner of the signed key, or `null` if the key is not verified
|
1940
|
+
* or the owner is not found.
|
1941
|
+
* @since 0.7.0
|
1942
|
+
*/
|
1943
|
+
getSignedKeyOwner(): Promise<Actor | null>;
|
1944
|
+
/**
|
1945
|
+
* Gets the owner of the signed key, if any exists and it is verified.
|
1946
|
+
* Otherwise, `null` is returned.
|
1947
|
+
*
|
1948
|
+
* This can be used for implementing [authorized fetch] (also known as
|
1949
|
+
* secure mode) in ActivityPub.
|
1950
|
+
*
|
1951
|
+
* [authorized fetch]: https://swicg.github.io/activitypub-http-signature/#authorized-fetch
|
1952
|
+
*
|
1953
|
+
* @param options Options for getting the key owner. You usually may want to
|
1954
|
+
* specify the custom `documentLoader` so that making
|
1955
|
+
* an HTTP request to the key owner's server is signed with
|
1956
|
+
* your [instance actor].
|
1957
|
+
* @returns The owner of the signed key, or `null` if the key is not verified
|
1958
|
+
* or the owner is not found.
|
1959
|
+
* @since 1.5.0
|
1960
|
+
*
|
1961
|
+
* [instance actor]: https://swicg.github.io/activitypub-http-signature/#instance-actor
|
1962
|
+
*/
|
1963
|
+
getSignedKeyOwner(options: GetKeyOwnerOptions): Promise<Actor | null>;
|
1964
|
+
}
|
1965
|
+
/**
|
1966
|
+
* A context for inbox listeners.
|
1967
|
+
* @since 1.0.0
|
1968
|
+
*/
|
1969
|
+
interface InboxContext<TContextData> extends Context<TContextData> {
|
1970
|
+
/**
|
1971
|
+
* The identifier of the recipient of the inbox. If the inbox is a shared
|
1972
|
+
* inbox, it is `null`.
|
1973
|
+
* @since 1.2.0
|
1974
|
+
*/
|
1975
|
+
recipient: string | null;
|
1976
|
+
/**
|
1977
|
+
* Creates a new context with the same properties as this one,
|
1978
|
+
* but with the given data.
|
1979
|
+
* @param data The new data to associate with the context.
|
1980
|
+
* @returns A new context with the same properties as this one,
|
1981
|
+
* but with the given data.
|
1982
|
+
* @since 1.6.0
|
1983
|
+
*/
|
1984
|
+
clone(data: TContextData): InboxContext<TContextData>;
|
1985
|
+
/**
|
1986
|
+
* Forwards a received activity to the recipients' inboxes. The forwarded
|
1987
|
+
* activity will be signed in HTTP Signatures by the forwarder, but its
|
1988
|
+
* payload will not be modified, i.e., Linked Data Signatures and Object
|
1989
|
+
* Integrity Proofs will not be added. Therefore, if the activity is not
|
1990
|
+
* signed (i.e., it has neither Linked Data Signatures nor Object Integrity
|
1991
|
+
* Proofs), the recipient probably will not trust the activity.
|
1992
|
+
* @param forwarder The forwarder's identifier or the forwarder's username
|
1993
|
+
* or the forwarder's key pair(s).
|
1994
|
+
* @param recipients The recipients of the activity.
|
1995
|
+
* @param options Options for forwarding the activity.
|
1996
|
+
* @since 1.0.0
|
1997
|
+
*/
|
1998
|
+
forwardActivity(forwarder: SenderKeyPair | SenderKeyPair[] | {
|
1999
|
+
identifier: string;
|
2000
|
+
} | {
|
2001
|
+
username: string;
|
2002
|
+
} | {
|
2003
|
+
handle: string;
|
2004
|
+
}, recipients: Recipient | Recipient[], options?: ForwardActivityOptions): Promise<void>;
|
2005
|
+
/**
|
2006
|
+
* Forwards a received activity to the recipients' inboxes. The forwarded
|
2007
|
+
* activity will be signed in HTTP Signatures by the forwarder, but its
|
2008
|
+
* payload will not be modified, i.e., Linked Data Signatures and Object
|
2009
|
+
* Integrity Proofs will not be added. Therefore, if the activity is not
|
2010
|
+
* signed (i.e., it has neither Linked Data Signatures nor Object Integrity
|
2011
|
+
* Proofs), the recipient probably will not trust the activity.
|
2012
|
+
* @param forwarder The forwarder's identifier or the forwarder's username.
|
2013
|
+
* @param recipients In this case, it must be `"followers"`.
|
2014
|
+
* @param options Options for forwarding the activity.
|
2015
|
+
* @since 1.0.0
|
2016
|
+
*/
|
2017
|
+
forwardActivity(forwarder: {
|
2018
|
+
identifier: string;
|
2019
|
+
} | {
|
2020
|
+
username: string;
|
2021
|
+
} | {
|
2022
|
+
handle: string;
|
2023
|
+
}, recipients: "followers", options?: ForwardActivityOptions): Promise<void>;
|
2024
|
+
}
|
2025
|
+
/**
|
2026
|
+
* A result of parsing an URI.
|
2027
|
+
*/
|
2028
|
+
type ParseUriResult =
|
2029
|
+
/**
|
2030
|
+
* The case of an actor URI.
|
2031
|
+
*/
|
2032
|
+
{
|
2033
|
+
readonly type: "actor";
|
2034
|
+
readonly identifier: string;
|
2035
|
+
readonly handle: string;
|
2036
|
+
}
|
2037
|
+
/**
|
2038
|
+
* The case of an object URI.
|
2039
|
+
*/ | {
|
2040
|
+
readonly type: "object";
|
2041
|
+
readonly class: (new (...args: any[]) => Object$1) & {
|
2042
|
+
typeId: URL;
|
2043
|
+
};
|
2044
|
+
readonly typeId: URL;
|
2045
|
+
readonly values: Record<string, string>;
|
2046
|
+
}
|
2047
|
+
/**
|
2048
|
+
* The case of an shared inbox URI.
|
2049
|
+
*/ | {
|
2050
|
+
readonly type: "inbox";
|
2051
|
+
readonly identifier: undefined;
|
2052
|
+
readonly handle: undefined;
|
2053
|
+
}
|
2054
|
+
/**
|
2055
|
+
* The case of an personal inbox URI.
|
2056
|
+
*/ | {
|
2057
|
+
readonly type: "inbox";
|
2058
|
+
readonly identifier: string;
|
2059
|
+
readonly handle: string;
|
2060
|
+
}
|
2061
|
+
/**
|
2062
|
+
* The case of an outbox collection URI.
|
2063
|
+
*/ | {
|
2064
|
+
readonly type: "outbox";
|
2065
|
+
readonly identifier: string;
|
2066
|
+
readonly handle: string;
|
2067
|
+
}
|
2068
|
+
/**
|
2069
|
+
* The case of a following collection URI.
|
2070
|
+
*/ | {
|
2071
|
+
readonly type: "following";
|
2072
|
+
readonly identifier: string;
|
2073
|
+
readonly handle: string;
|
2074
|
+
}
|
2075
|
+
/**
|
2076
|
+
* The case of a followers collection URI.
|
2077
|
+
*/ | {
|
2078
|
+
readonly type: "followers";
|
2079
|
+
readonly identifier: string;
|
2080
|
+
readonly handle: string;
|
2081
|
+
}
|
2082
|
+
/**
|
2083
|
+
* The case of a liked collection URI.
|
2084
|
+
* @since 0.11.0
|
2085
|
+
*/ | {
|
2086
|
+
readonly type: "liked";
|
2087
|
+
readonly identifier: string;
|
2088
|
+
readonly handle: string;
|
2089
|
+
}
|
2090
|
+
/**
|
2091
|
+
* The case of a featured collection URI.
|
2092
|
+
* @since 0.11.0
|
2093
|
+
*/ | {
|
2094
|
+
readonly type: "featured";
|
2095
|
+
readonly identifier: string;
|
2096
|
+
readonly handle: string;
|
2097
|
+
}
|
2098
|
+
/**
|
2099
|
+
* The case of a featured tags collection URI.
|
2100
|
+
* @since 0.11.0
|
2101
|
+
*/ | {
|
2102
|
+
readonly type: "featuredTags";
|
2103
|
+
readonly identifier: string;
|
2104
|
+
readonly handle: string;
|
2105
|
+
}
|
2106
|
+
/**
|
2107
|
+
* The case of a custom collection URI.
|
2108
|
+
* @since 1.8.0
|
2109
|
+
*/ | {
|
2110
|
+
readonly type: "collection";
|
2111
|
+
readonly name: string | symbol;
|
2112
|
+
readonly class: ConstructorWithTypeId<Object$1>;
|
2113
|
+
readonly typeId: URL;
|
2114
|
+
readonly values: Record<string, string>;
|
2115
|
+
}
|
2116
|
+
/**
|
2117
|
+
* The case of a custom ordered collection URI.
|
2118
|
+
* @since 1.8.0
|
2119
|
+
*/ | {
|
2120
|
+
readonly type: "orderedCollection";
|
2121
|
+
readonly name: string | symbol;
|
2122
|
+
readonly class: ConstructorWithTypeId<Object$1>;
|
2123
|
+
readonly typeId: URL;
|
2124
|
+
readonly values: Record<string, string>;
|
2125
|
+
};
|
2126
|
+
/**
|
2127
|
+
* Options for {@link Context.sendActivity} method.
|
2128
|
+
*/
|
2129
|
+
interface SendActivityOptions {
|
2130
|
+
/**
|
2131
|
+
* Whether to prefer the shared inbox for the recipients.
|
2132
|
+
*/
|
2133
|
+
preferSharedInbox?: boolean;
|
2134
|
+
/**
|
2135
|
+
* Whether to send the activity immediately, without enqueuing it.
|
2136
|
+
* If `true`, the activity will be sent immediately and the retrial
|
2137
|
+
* policy will not be applied.
|
2138
|
+
*
|
2139
|
+
* @since 0.3.0
|
2140
|
+
*/
|
2141
|
+
immediate?: boolean;
|
2142
|
+
/**
|
2143
|
+
* Determines how activities are queued when sent to multiple recipients.
|
2144
|
+
*
|
2145
|
+
* - "auto" (default): Automatically chooses optimal strategy based on
|
2146
|
+
* recipient count.
|
2147
|
+
* - "skip": Always enqueues individual messages per recipient,
|
2148
|
+
* bypassing the fanout queue. Use when payload needs to vary per recipient.
|
2149
|
+
* - "force": Always uses fanout queue regardless of recipient count.
|
2150
|
+
* Useful for testing or special cases.
|
2151
|
+
*
|
2152
|
+
* This option is ignored when `immediate: true` is specified, as immediate
|
2153
|
+
* delivery bypasses all queuing mechanisms.
|
2154
|
+
*
|
2155
|
+
* @default `"auto"`
|
2156
|
+
* @since 1.5.0
|
2157
|
+
*/
|
2158
|
+
fanout?: "auto" | "skip" | "force";
|
2159
|
+
/**
|
2160
|
+
* The base URIs to exclude from the recipients' inboxes. It is useful
|
2161
|
+
* for excluding the recipients having the same shared inbox with the sender.
|
2162
|
+
*
|
2163
|
+
* Note that the only `origin` parts of the `URL`s are compared.
|
2164
|
+
*
|
2165
|
+
* @since 0.9.0
|
2166
|
+
*/
|
2167
|
+
excludeBaseUris?: URL[];
|
2168
|
+
}
|
2169
|
+
/**
|
2170
|
+
* Options for {@link Context.sendActivity} method when sending to a collection.
|
2171
|
+
* @since 1.5.0
|
2172
|
+
*/
|
2173
|
+
interface SendActivityOptionsForCollection extends SendActivityOptions {
|
2174
|
+
/**
|
2175
|
+
* Whether to synchronize the collection using `Collection-Synchronization`
|
2176
|
+
* header ([FEP-8fcf]).
|
2177
|
+
*
|
2178
|
+
* [FEP-8fcf]: https://w3id.org/fep/8fcf
|
2179
|
+
*/
|
2180
|
+
syncCollection?: boolean;
|
2181
|
+
}
|
2182
|
+
/**
|
2183
|
+
* Options for {@link InboxContext.forwardActivity} method.
|
2184
|
+
* @since 1.0.0
|
2185
|
+
*/
|
2186
|
+
type ForwardActivityOptions = Omit<SendActivityOptions, "fanout"> & {
|
2187
|
+
/**
|
2188
|
+
* Whether to skip forwarding the activity if it is not signed, i.e., it has
|
2189
|
+
* neither Linked Data Signatures nor Object Integrity Proofs.
|
2190
|
+
*
|
2191
|
+
* If the activity is not signed, the recipient probably will not trust the
|
2192
|
+
* activity. Therefore, it is recommended to skip forwarding the activity
|
2193
|
+
* if it is not signed.
|
2194
|
+
*/
|
2195
|
+
skipIfUnsigned: boolean;
|
2196
|
+
};
|
2197
|
+
/**
|
2198
|
+
* Options for {@link Context.routeActivity} method.
|
2199
|
+
* @since 1.3.0
|
2200
|
+
*/
|
2201
|
+
interface RouteActivityOptions {
|
2202
|
+
/**
|
2203
|
+
* Whether to skip enqueuing the activity and invoke the listener immediately.
|
2204
|
+
* If no inbox queue is available, this option is ignored and the activity
|
2205
|
+
* will be always invoked immediately.
|
2206
|
+
* @default false
|
2207
|
+
*/
|
2208
|
+
immediate?: boolean;
|
2209
|
+
/**
|
2210
|
+
* The document loader for loading remote JSON-LD documents.
|
2211
|
+
*/
|
2212
|
+
documentLoader?: DocumentLoader;
|
2213
|
+
/**
|
2214
|
+
* The context loader for loading remote JSON-LD contexts.
|
2215
|
+
*/
|
2216
|
+
contextLoader?: DocumentLoader;
|
2217
|
+
/**
|
2218
|
+
* The OpenTelemetry tracer provider. If omitted, the global tracer provider
|
2219
|
+
* is used.
|
2220
|
+
*/
|
2221
|
+
tracerProvider?: TracerProvider;
|
2222
|
+
}
|
2223
|
+
/**
|
2224
|
+
* Options for {@link Context.getSignedKey} method.
|
2225
|
+
* @since 1.5.0
|
2226
|
+
*/
|
2227
|
+
interface GetSignedKeyOptions {
|
2228
|
+
/**
|
2229
|
+
* The document loader for loading remote JSON-LD documents.
|
2230
|
+
*/
|
2231
|
+
documentLoader?: DocumentLoader;
|
2232
|
+
/**
|
2233
|
+
* The context loader for loading remote JSON-LD contexts.
|
2234
|
+
*/
|
2235
|
+
contextLoader?: DocumentLoader;
|
2236
|
+
/**
|
2237
|
+
* The OpenTelemetry tracer provider. If omitted, the global tracer provider
|
2238
|
+
* is used.
|
2239
|
+
*/
|
2240
|
+
tracerProvider?: TracerProvider;
|
2241
|
+
}
|
2242
|
+
/**
|
2243
|
+
* A pair of a public key and a private key in various formats.
|
2244
|
+
* @since 0.10.0
|
2245
|
+
*/
|
2246
|
+
interface ActorKeyPair extends CryptoKeyPair {
|
2247
|
+
/**
|
2248
|
+
* The URI of the public key, which is used for verifying HTTP Signatures.
|
2249
|
+
*/
|
2250
|
+
keyId: URL;
|
2251
|
+
/**
|
2252
|
+
* A {@link CryptographicKey} instance of the public key.
|
2253
|
+
*/
|
2254
|
+
cryptographicKey: CryptographicKey;
|
2255
|
+
/**
|
2256
|
+
* A {@link Multikey} instance of the public key.
|
2257
|
+
*/
|
2258
|
+
multikey: Multikey;
|
2259
|
+
}
|
2260
|
+
//#endregion
|
2261
|
+
export { ActivityTransformer, ActorAliasMapper, ActorCallbackSetters, ActorDispatcher, ActorHandleMapper, ActorKeyPair, ActorKeyPairsDispatcher, AuthorizePredicate, CollectionCallbackSetters, CollectionCounter, CollectionCursor, CollectionDispatcher, ConstructorWithTypeId, Context, CreateExponentialBackoffPolicyOptions, CreateFederationOptions, CustomCollectionCallbackSetters, CustomCollectionCounter, CustomCollectionCursor, CustomCollectionDispatcher, Federatable, Federation, FederationBuilder, FederationFetchOptions, FederationKvPrefixes, FederationOptions, FederationOrigin, FederationQueueOptions, FederationStartQueueOptions, ForwardActivityOptions, GetSignedKeyOptions, InboxContext, InboxErrorHandler, InboxListener, InboxListenerSetters, Message, NodeInfoDispatcher, ObjectAuthorizePredicate, ObjectCallbackSetters, ObjectDispatcher, OutboxErrorHandler, PageItems, ParamsKeyPath, ParseUriResult, RequestContext, RespondWithObjectOptions, RetryContext, RetryPolicy, RouteActivityOptions, Router, RouterError, RouterOptions, RouterRouteResult, SendActivityOptions, SendActivityOptionsForCollection, SenderKeyPair, SharedInboxKeyDispatcher, WebFingerLinksDispatcher, buildCollectionSynchronizationHeader, createExponentialBackoffPolicy, createFederation, createFederationBuilder, digest, respondWithObject, respondWithObjectIfAcceptable };
|