@fedify/relay 2.2.0-dev.613 → 2.2.0-dev.628
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/litepub.test.d.ts +1 -2
- package/dist/litepub.test.js +22 -41
- package/dist/mastodon.test.d.ts +1 -2
- package/dist/mastodon.test.js +26 -49
- package/dist/mod.cjs +53 -93
- package/dist/mod.d.cts +119 -19
- package/dist/mod.d.ts +119 -19
- package/dist/mod.js +25 -43
- package/dist/{types-B94EmP_a.js → types-C8ez1e8g.js} +1759 -1932
- package/package.json +6 -6
package/dist/mod.cjs
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
-
key = keys[i];
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
-
value: mod,
|
|
23
|
-
enumerable: true
|
|
24
|
-
}) : target, mod));
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
const __fedify_fedify = __toESM(require("@fedify/fedify"));
|
|
28
|
-
const __fedify_vocab = __toESM(require("@fedify/vocab"));
|
|
29
|
-
const __logtape_logtape = __toESM(require("@logtape/logtape"));
|
|
30
|
-
|
|
1
|
+
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
let _fedify_fedify = require("@fedify/fedify");
|
|
4
|
+
let _fedify_vocab = require("@fedify/vocab");
|
|
5
|
+
let _logtape_logtape = require("@logtape/logtape");
|
|
31
6
|
//#region src/types.ts
|
|
32
7
|
const RELAY_SERVER_ACTOR = "relay";
|
|
33
8
|
/**
|
|
@@ -43,14 +18,13 @@ function isRelayFollowerData(value) {
|
|
|
43
18
|
const obj = value;
|
|
44
19
|
return "actor" in obj && "state" in obj && typeof obj.state === "string" && (obj.state === "pending" || obj.state === "accepted");
|
|
45
20
|
}
|
|
46
|
-
|
|
47
21
|
//#endregion
|
|
48
22
|
//#region src/builder.ts
|
|
49
|
-
const relayBuilder = (0,
|
|
23
|
+
const relayBuilder = (0, _fedify_fedify.createFederationBuilder)();
|
|
50
24
|
relayBuilder.setActorDispatcher("/users/{identifier}", async (ctx, identifier) => {
|
|
51
|
-
if (identifier !==
|
|
25
|
+
if (identifier !== "relay") return null;
|
|
52
26
|
const keys = await ctx.getActorKeyPairs(identifier);
|
|
53
|
-
return new
|
|
27
|
+
return new _fedify_vocab.Application({
|
|
54
28
|
id: ctx.getActorUri(identifier),
|
|
55
29
|
preferredUsername: identifier,
|
|
56
30
|
name: ctx.data.name ?? "ActivityPub Relay",
|
|
@@ -62,7 +36,7 @@ relayBuilder.setActorDispatcher("/users/{identifier}", async (ctx, identifier) =
|
|
|
62
36
|
assertionMethods: keys.map((k) => k.multikey)
|
|
63
37
|
});
|
|
64
38
|
}).setKeyPairsDispatcher(async (ctx, identifier) => {
|
|
65
|
-
if (identifier !==
|
|
39
|
+
if (identifier !== "relay") return [];
|
|
66
40
|
const rsaPairJson = await ctx.data.kv.get([
|
|
67
41
|
"keypair",
|
|
68
42
|
"rsa",
|
|
@@ -74,55 +48,51 @@ relayBuilder.setActorDispatcher("/users/{identifier}", async (ctx, identifier) =
|
|
|
74
48
|
identifier
|
|
75
49
|
]);
|
|
76
50
|
if (rsaPairJson == null || ed25519PairJson == null) {
|
|
77
|
-
const rsaPair
|
|
78
|
-
const ed25519Pair
|
|
51
|
+
const rsaPair = await (0, _fedify_fedify.generateCryptoKeyPair)("RSASSA-PKCS1-v1_5");
|
|
52
|
+
const ed25519Pair = await (0, _fedify_fedify.generateCryptoKeyPair)("Ed25519");
|
|
79
53
|
await ctx.data.kv.set([
|
|
80
54
|
"keypair",
|
|
81
55
|
"rsa",
|
|
82
56
|
identifier
|
|
83
57
|
], {
|
|
84
|
-
privateKey: await (0,
|
|
85
|
-
publicKey: await (0,
|
|
58
|
+
privateKey: await (0, _fedify_fedify.exportJwk)(rsaPair.privateKey),
|
|
59
|
+
publicKey: await (0, _fedify_fedify.exportJwk)(rsaPair.publicKey)
|
|
86
60
|
});
|
|
87
61
|
await ctx.data.kv.set([
|
|
88
62
|
"keypair",
|
|
89
63
|
"ed25519",
|
|
90
64
|
identifier
|
|
91
65
|
], {
|
|
92
|
-
privateKey: await (0,
|
|
93
|
-
publicKey: await (0,
|
|
66
|
+
privateKey: await (0, _fedify_fedify.exportJwk)(ed25519Pair.privateKey),
|
|
67
|
+
publicKey: await (0, _fedify_fedify.exportJwk)(ed25519Pair.publicKey)
|
|
94
68
|
});
|
|
95
|
-
return [rsaPair
|
|
69
|
+
return [rsaPair, ed25519Pair];
|
|
96
70
|
}
|
|
97
|
-
|
|
98
|
-
privateKey: await (0,
|
|
99
|
-
publicKey: await (0,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
return [rsaPair, ed25519Pair];
|
|
71
|
+
return [{
|
|
72
|
+
privateKey: await (0, _fedify_fedify.importJwk)(rsaPairJson.privateKey, "private"),
|
|
73
|
+
publicKey: await (0, _fedify_fedify.importJwk)(rsaPairJson.publicKey, "public")
|
|
74
|
+
}, {
|
|
75
|
+
privateKey: await (0, _fedify_fedify.importJwk)(ed25519PairJson.privateKey, "private"),
|
|
76
|
+
publicKey: await (0, _fedify_fedify.importJwk)(ed25519PairJson.publicKey, "public")
|
|
77
|
+
}];
|
|
106
78
|
});
|
|
107
79
|
async function getFollowerActors(ctx) {
|
|
108
80
|
const actors = [];
|
|
109
81
|
for await (const { value } of ctx.data.kv.list(["follower"])) {
|
|
110
82
|
if (!isRelayFollowerData(value)) continue;
|
|
111
83
|
if (value.state !== "accepted") continue;
|
|
112
|
-
const actor = await
|
|
113
|
-
if (!(0,
|
|
84
|
+
const actor = await _fedify_vocab.Object.fromJsonLd(value.actor);
|
|
85
|
+
if (!(0, _fedify_vocab.isActor)(actor)) continue;
|
|
114
86
|
actors.push(actor);
|
|
115
87
|
}
|
|
116
88
|
return actors;
|
|
117
89
|
}
|
|
118
90
|
async function dispatchRelayActors(ctx, identifier) {
|
|
119
|
-
if (identifier !==
|
|
120
|
-
|
|
121
|
-
return { items: actors };
|
|
91
|
+
if (identifier !== "relay") return null;
|
|
92
|
+
return { items: await getFollowerActors(ctx) };
|
|
122
93
|
}
|
|
123
94
|
relayBuilder.setFollowersDispatcher("/users/{identifier}/followers", dispatchRelayActors);
|
|
124
95
|
relayBuilder.setFollowingDispatcher("/users/{identifier}/following", dispatchRelayActors);
|
|
125
|
-
|
|
126
96
|
//#endregion
|
|
127
97
|
//#region src/base.ts
|
|
128
98
|
/**
|
|
@@ -135,9 +105,9 @@ var BaseRelay = class {
|
|
|
135
105
|
federationBuilder;
|
|
136
106
|
options;
|
|
137
107
|
federation;
|
|
138
|
-
constructor(options, relayBuilder
|
|
108
|
+
constructor(options, relayBuilder) {
|
|
139
109
|
this.options = options;
|
|
140
|
-
this.federationBuilder = relayBuilder
|
|
110
|
+
this.federationBuilder = relayBuilder;
|
|
141
111
|
}
|
|
142
112
|
async fetch(request) {
|
|
143
113
|
return await (await this.#getFederation()).fetch(request, { contextData: this.options });
|
|
@@ -153,8 +123,8 @@ var BaseRelay = class {
|
|
|
153
123
|
*/
|
|
154
124
|
async parseFollowerData(actorId, data) {
|
|
155
125
|
if (!isRelayFollowerData(data)) return null;
|
|
156
|
-
const actor = await
|
|
157
|
-
if (!(0,
|
|
126
|
+
const actor = await _fedify_vocab.Object.fromJsonLd(data.actor);
|
|
127
|
+
if (!(0, _fedify_vocab.isActor)(actor)) return null;
|
|
158
128
|
return {
|
|
159
129
|
actorId,
|
|
160
130
|
actor,
|
|
@@ -234,19 +204,15 @@ var BaseRelay = class {
|
|
|
234
204
|
return this.federation;
|
|
235
205
|
}
|
|
236
206
|
async #createContext() {
|
|
237
|
-
|
|
238
|
-
return context;
|
|
207
|
+
return (await this.#getFederation()).createContext(new URL(this.options.origin), this.options);
|
|
239
208
|
}
|
|
240
209
|
async getActorUri() {
|
|
241
|
-
|
|
242
|
-
return context.getActorUri(RELAY_SERVER_ACTOR);
|
|
210
|
+
return (await this.#createContext()).getActorUri(RELAY_SERVER_ACTOR);
|
|
243
211
|
}
|
|
244
212
|
async getSharedInboxUri() {
|
|
245
|
-
|
|
246
|
-
return context.getInboxUri();
|
|
213
|
+
return (await this.#createContext()).getInboxUri();
|
|
247
214
|
}
|
|
248
215
|
};
|
|
249
|
-
|
|
250
216
|
//#endregion
|
|
251
217
|
//#region src/follow.ts
|
|
252
218
|
/**
|
|
@@ -260,8 +226,7 @@ var BaseRelay = class {
|
|
|
260
226
|
async function validateFollowActivity(ctx, follow) {
|
|
261
227
|
if (follow.id == null || follow.objectId == null) return null;
|
|
262
228
|
const parsed = ctx.parseUri(follow.objectId);
|
|
263
|
-
|
|
264
|
-
if (!isPublicFollow && parsed?.type !== "actor") return null;
|
|
229
|
+
if (!(follow.objectId.href === "https://www.w3.org/ns/activitystreams#Public") && parsed?.type !== "actor") return null;
|
|
265
230
|
const follower = await follow.getActor(ctx);
|
|
266
231
|
if (follower == null || follower.id == null || follower.preferredUsername == null || follower.inboxId == null) return null;
|
|
267
232
|
return follower;
|
|
@@ -277,7 +242,7 @@ async function validateFollowActivity(ctx, follow) {
|
|
|
277
242
|
*/
|
|
278
243
|
async function sendFollowResponse(ctx, follow, follower, approved) {
|
|
279
244
|
const relayActorUri = ctx.getActorUri(RELAY_SERVER_ACTOR);
|
|
280
|
-
const Activity = approved ?
|
|
245
|
+
const Activity = approved ? _fedify_vocab.Accept : _fedify_vocab.Reject;
|
|
281
246
|
const action = approved ? "accepts" : "rejects";
|
|
282
247
|
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new Activity({
|
|
283
248
|
id: new URL(`#${action}`, relayActorUri),
|
|
@@ -293,23 +258,22 @@ async function sendFollowResponse(ctx, follow, follower, approved) {
|
|
|
293
258
|
* @param undo The Undo activity to handle
|
|
294
259
|
* @param logger The logger instance to use for warnings
|
|
295
260
|
*/
|
|
296
|
-
async function handleUndoFollow(ctx, undo, logger
|
|
261
|
+
async function handleUndoFollow(ctx, undo, logger) {
|
|
297
262
|
const activity = await undo.getObject({
|
|
298
263
|
crossOrigin: "trust",
|
|
299
264
|
...ctx
|
|
300
265
|
});
|
|
301
|
-
if (activity instanceof
|
|
266
|
+
if (activity instanceof _fedify_vocab.Follow) {
|
|
302
267
|
if (activity.id == null || activity.actorId == null) return;
|
|
303
268
|
await ctx.data.kv.delete(["follower", activity.actorId.href]);
|
|
304
|
-
} else logger
|
|
269
|
+
} else logger.warn("Unsupported object type ({type}) for Undo activity: {object}", {
|
|
305
270
|
type: activity?.constructor.name,
|
|
306
271
|
object: activity
|
|
307
272
|
});
|
|
308
273
|
}
|
|
309
|
-
|
|
310
274
|
//#endregion
|
|
311
275
|
//#region src/litepub.ts
|
|
312
|
-
const logger$1 = (0,
|
|
276
|
+
const logger$1 = (0, _logtape_logtape.getLogger)([
|
|
313
277
|
"fedify",
|
|
314
278
|
"relay",
|
|
315
279
|
"litepub"
|
|
@@ -325,11 +289,11 @@ var LitePubRelay = class extends BaseRelay {
|
|
|
325
289
|
async #announceToFollowers(ctx, activity) {
|
|
326
290
|
const sender = await activity.getActor(ctx);
|
|
327
291
|
const excludeBaseUris = sender?.id ? [new URL(sender.id)] : [];
|
|
328
|
-
const announce = new
|
|
292
|
+
const announce = new _fedify_vocab.Announce({
|
|
329
293
|
id: new URL(`/announce#${crypto.randomUUID()}`, ctx.origin),
|
|
330
294
|
actor: ctx.getActorUri(RELAY_SERVER_ACTOR),
|
|
331
295
|
object: activity.objectId,
|
|
332
|
-
to:
|
|
296
|
+
to: _fedify_vocab.PUBLIC_COLLECTION,
|
|
333
297
|
published: Temporal.Now.instant()
|
|
334
298
|
});
|
|
335
299
|
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, "followers", announce, {
|
|
@@ -338,11 +302,10 @@ var LitePubRelay = class extends BaseRelay {
|
|
|
338
302
|
});
|
|
339
303
|
}
|
|
340
304
|
setupInboxListeners() {
|
|
341
|
-
if (this.federation != null) this.federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(
|
|
305
|
+
if (this.federation != null) this.federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(_fedify_vocab.Follow, async (ctx, follow) => {
|
|
342
306
|
const follower = await validateFollowActivity(ctx, follow);
|
|
343
307
|
if (!follower || !follower.id) return;
|
|
344
|
-
|
|
345
|
-
if (existingFollow?.state === "pending") return;
|
|
308
|
+
if ((await ctx.data.kv.get(["follower", follower.id.href]))?.state === "pending") return;
|
|
346
309
|
const approved = await this.options.subscriptionHandler(ctx, follower);
|
|
347
310
|
if (approved) {
|
|
348
311
|
await ctx.data.kv.set(["follower", follower.id.href], {
|
|
@@ -351,22 +314,22 @@ var LitePubRelay = class extends BaseRelay {
|
|
|
351
314
|
});
|
|
352
315
|
await sendFollowResponse(ctx, follow, follower, approved);
|
|
353
316
|
const relayActorUri = ctx.getActorUri(RELAY_SERVER_ACTOR);
|
|
354
|
-
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new
|
|
317
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new _fedify_vocab.Follow({
|
|
355
318
|
actor: relayActorUri,
|
|
356
319
|
object: follower.id,
|
|
357
320
|
to: follower.id
|
|
358
321
|
}));
|
|
359
322
|
} else await sendFollowResponse(ctx, follow, follower, approved);
|
|
360
|
-
}).on(
|
|
323
|
+
}).on(_fedify_vocab.Accept, async (ctx, accept) => {
|
|
361
324
|
const follow = await accept.getObject({
|
|
362
325
|
crossOrigin: "trust",
|
|
363
326
|
...ctx
|
|
364
327
|
});
|
|
365
|
-
if (!(follow instanceof
|
|
328
|
+
if (!(follow instanceof _fedify_vocab.Follow)) return;
|
|
366
329
|
const relayActorId = follow.actorId;
|
|
367
330
|
if (relayActorId == null) return;
|
|
368
331
|
const followerActor = await accept.getActor();
|
|
369
|
-
if (!(0,
|
|
332
|
+
if (!(0, _fedify_vocab.isActor)(followerActor) || !followerActor.id) return;
|
|
370
333
|
const parsed = ctx.parseUri(relayActorId);
|
|
371
334
|
if (parsed == null || parsed.type !== "actor") return;
|
|
372
335
|
const followerData = await ctx.data.kv.get(["follower", followerActor.id.href]);
|
|
@@ -376,13 +339,12 @@ var LitePubRelay = class extends BaseRelay {
|
|
|
376
339
|
state: "accepted"
|
|
377
340
|
};
|
|
378
341
|
await ctx.data.kv.set(["follower", followerActor.id.href], updatedFollowerData);
|
|
379
|
-
}).on(
|
|
342
|
+
}).on(_fedify_vocab.Undo, async (ctx, undo) => await handleUndoFollow(ctx, undo, logger$1)).on(_fedify_vocab.Create, async (ctx, create) => await this.#announceToFollowers(ctx, create)).on(_fedify_vocab.Update, async (ctx, update) => await this.#announceToFollowers(ctx, update)).on(_fedify_vocab.Move, async (ctx, move) => await this.#announceToFollowers(ctx, move)).on(_fedify_vocab.Delete, async (ctx, deleteActivity) => await this.#announceToFollowers(ctx, deleteActivity)).on(_fedify_vocab.Announce, async (ctx, announce) => await this.#announceToFollowers(ctx, announce));
|
|
380
343
|
}
|
|
381
344
|
};
|
|
382
|
-
|
|
383
345
|
//#endregion
|
|
384
346
|
//#region src/mastodon.ts
|
|
385
|
-
const logger = (0,
|
|
347
|
+
const logger = (0, _logtape_logtape.getLogger)([
|
|
386
348
|
"fedify",
|
|
387
349
|
"relay",
|
|
388
350
|
"mastodon"
|
|
@@ -405,7 +367,7 @@ var MastodonRelay = class extends BaseRelay {
|
|
|
405
367
|
});
|
|
406
368
|
}
|
|
407
369
|
setupInboxListeners() {
|
|
408
|
-
if (this.federation != null) this.federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(
|
|
370
|
+
if (this.federation != null) this.federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(_fedify_vocab.Follow, async (ctx, follow) => {
|
|
409
371
|
const follower = await validateFollowActivity(ctx, follow);
|
|
410
372
|
if (!follower || !follower.id) return;
|
|
411
373
|
const approved = await this.options.subscriptionHandler(ctx, follower);
|
|
@@ -414,10 +376,9 @@ var MastodonRelay = class extends BaseRelay {
|
|
|
414
376
|
state: "accepted"
|
|
415
377
|
});
|
|
416
378
|
await sendFollowResponse(ctx, follow, follower, approved);
|
|
417
|
-
}).on(
|
|
379
|
+
}).on(_fedify_vocab.Undo, async (ctx, undo) => await handleUndoFollow(ctx, undo, logger)).on(_fedify_vocab.Create, async (ctx, create) => await this.#forwardToFollowers(ctx, create)).on(_fedify_vocab.Delete, async (ctx, deleteActivity) => await this.#forwardToFollowers(ctx, deleteActivity)).on(_fedify_vocab.Move, async (ctx, move) => await this.#forwardToFollowers(ctx, move)).on(_fedify_vocab.Update, async (ctx, update) => await this.#forwardToFollowers(ctx, update)).on(_fedify_vocab.Announce, async (ctx, announce) => await this.#forwardToFollowers(ctx, announce));
|
|
418
380
|
}
|
|
419
381
|
};
|
|
420
|
-
|
|
421
382
|
//#endregion
|
|
422
383
|
//#region src/factory.ts
|
|
423
384
|
/**
|
|
@@ -447,7 +408,6 @@ function createRelay(type, options) {
|
|
|
447
408
|
case "litepub": return new LitePubRelay(options, relayBuilder);
|
|
448
409
|
}
|
|
449
410
|
}
|
|
450
|
-
|
|
451
411
|
//#endregion
|
|
452
412
|
exports.RELAY_SERVER_ACTOR = RELAY_SERVER_ACTOR;
|
|
453
|
-
exports.createRelay = createRelay;
|
|
413
|
+
exports.createRelay = createRelay;
|
package/dist/mod.d.cts
CHANGED
|
@@ -1,7 +1,123 @@
|
|
|
1
1
|
import { Context, KvStore, MessageQueue } from "@fedify/fedify";
|
|
2
2
|
import { Actor } from "@fedify/vocab";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
//#region ../vocab-runtime/dist/mod.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options for making `User-Agent` string.
|
|
6
|
+
* @see {@link getUserAgent}
|
|
7
|
+
* @since 1.3.0
|
|
8
|
+
*/
|
|
9
|
+
interface GetUserAgentOptions {
|
|
10
|
+
/**
|
|
11
|
+
* An optional software name and version, e.g., `"Hollo/1.0.0"`.
|
|
12
|
+
*/
|
|
13
|
+
software?: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* An optional URL to append to the user agent string.
|
|
16
|
+
* Usually the URL of the ActivityPub instance.
|
|
17
|
+
*/
|
|
18
|
+
url?: string | URL | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the user agent string for the given application and URL.
|
|
22
|
+
* @param options The options for making the user agent string.
|
|
23
|
+
* @returns The user agent string.
|
|
24
|
+
* @since 1.3.0
|
|
25
|
+
*/
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/docloader.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* A remote JSON-LD document and its context fetched by
|
|
30
|
+
* a {@link DocumentLoader}.
|
|
31
|
+
*/
|
|
32
|
+
interface RemoteDocument {
|
|
33
|
+
/**
|
|
34
|
+
* The URL of the context document.
|
|
35
|
+
*/
|
|
36
|
+
contextUrl: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* The fetched JSON-LD document.
|
|
39
|
+
*/
|
|
40
|
+
document: unknown;
|
|
41
|
+
/**
|
|
42
|
+
* The URL of the fetched document.
|
|
43
|
+
*/
|
|
44
|
+
documentUrl: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Options for {@link DocumentLoader}.
|
|
48
|
+
* @since 1.8.0
|
|
49
|
+
*/
|
|
50
|
+
interface DocumentLoaderOptions {
|
|
51
|
+
/**
|
|
52
|
+
* An `AbortSignal` for cancellation.
|
|
53
|
+
* @since 1.8.0
|
|
54
|
+
*/
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A JSON-LD document loader that fetches documents from the Web.
|
|
59
|
+
* @param url The URL of the document to load.
|
|
60
|
+
* @param options The options for the document loader.
|
|
61
|
+
* @returns The loaded remote document.
|
|
62
|
+
*/
|
|
63
|
+
type DocumentLoader = (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument>;
|
|
64
|
+
/**
|
|
65
|
+
* A factory function that creates a {@link DocumentLoader} with options.
|
|
66
|
+
* @param options The options for the document loader.
|
|
67
|
+
* @returns The document loader.
|
|
68
|
+
* @since 1.4.0
|
|
69
|
+
*/
|
|
70
|
+
type DocumentLoaderFactory = (options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
71
|
+
/**
|
|
72
|
+
* Options for {@link DocumentLoaderFactory}.
|
|
73
|
+
* @see {@link DocumentLoaderFactory}
|
|
74
|
+
* @see {@link AuthenticatedDocumentLoaderFactory}
|
|
75
|
+
* @since 1.4.0
|
|
76
|
+
*/
|
|
77
|
+
interface DocumentLoaderFactoryOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Whether to allow fetching private network addresses.
|
|
80
|
+
* Turned off by default.
|
|
81
|
+
* @default `false``
|
|
82
|
+
*/
|
|
83
|
+
allowPrivateAddress?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Options for making `User-Agent` string.
|
|
86
|
+
* If a string is given, it is used as the `User-Agent` header value.
|
|
87
|
+
* If an object is given, it is passed to {@link getUserAgent} function.
|
|
88
|
+
*/
|
|
89
|
+
userAgent?: GetUserAgentOptions | string;
|
|
90
|
+
/**
|
|
91
|
+
* The maximum number of redirections to follow.
|
|
92
|
+
* @default `20`
|
|
93
|
+
* @since 2.2.0
|
|
94
|
+
*/
|
|
95
|
+
maxRedirection?: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A factory function that creates an authenticated {@link DocumentLoader} for
|
|
99
|
+
* a given identity. This is used for fetching documents that require
|
|
100
|
+
* authentication.
|
|
101
|
+
* @param identity The identity to create the document loader for.
|
|
102
|
+
* The actor's key pair.
|
|
103
|
+
* @param options The options for the document loader.
|
|
104
|
+
* @returns The authenticated document loader.
|
|
105
|
+
* @since 0.4.0
|
|
106
|
+
*/
|
|
107
|
+
type AuthenticatedDocumentLoaderFactory = (identity: {
|
|
108
|
+
keyId: URL;
|
|
109
|
+
privateKey: CryptoKey;
|
|
110
|
+
}, options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
111
|
+
/**
|
|
112
|
+
* Gets a {@link RemoteDocument} from the given response.
|
|
113
|
+
* @param url The URL of the document to load.
|
|
114
|
+
* @param response The response to get the document from.
|
|
115
|
+
* @param fetch The function to fetch the document.
|
|
116
|
+
* @returns The loaded remote document.
|
|
117
|
+
* @throws {FetchError} If the response is not OK.
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
//#endregion
|
|
5
121
|
//#region src/types.d.ts
|
|
6
122
|
declare const RELAY_SERVER_ACTOR = "relay";
|
|
7
123
|
/**
|
|
@@ -53,14 +169,6 @@ interface RelayOptions {
|
|
|
53
169
|
*/
|
|
54
170
|
subscriptionHandler: SubscriptionRequestHandler;
|
|
55
171
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Internal storage format for follower data in KV store.
|
|
58
|
-
* Contains JSON-LD representation of the actor.
|
|
59
|
-
* Exported for internal package use but not re-exported from mod.ts.
|
|
60
|
-
*
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
172
|
/**
|
|
65
173
|
* A follower of the relay with validated Actor instance.
|
|
66
174
|
* This is the public API type returned by follower query methods.
|
|
@@ -115,14 +223,6 @@ interface Relay {
|
|
|
115
223
|
*/
|
|
116
224
|
getSharedInboxUri(): Promise<URL>;
|
|
117
225
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Type predicate to check if a value is valid RelayFollowerData from KV store.
|
|
120
|
-
* Validates the storage format (JSON-LD), not the deserialized Actor instance.
|
|
121
|
-
*
|
|
122
|
-
* @param value The value to check
|
|
123
|
-
* @returns true if the value is a RelayFollowerData
|
|
124
|
-
* @internal
|
|
125
|
-
*/
|
|
126
226
|
//#endregion
|
|
127
227
|
//#region src/factory.d.ts
|
|
128
228
|
/**
|
|
@@ -148,4 +248,4 @@ interface Relay {
|
|
|
148
248
|
*/
|
|
149
249
|
declare function createRelay(type: RelayType, options: RelayOptions): Relay;
|
|
150
250
|
//#endregion
|
|
151
|
-
export { RELAY_SERVER_ACTOR, Relay, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay };
|
|
251
|
+
export { RELAY_SERVER_ACTOR, type Relay, type RelayFollower, type RelayOptions, type RelayType, type SubscriptionRequestHandler, createRelay };
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,8 +1,124 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { Context, KvStore, MessageQueue } from "@fedify/fedify";
|
|
3
3
|
import { Actor } from "@fedify/vocab";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
//#region ../vocab-runtime/dist/mod.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for making `User-Agent` string.
|
|
7
|
+
* @see {@link getUserAgent}
|
|
8
|
+
* @since 1.3.0
|
|
9
|
+
*/
|
|
10
|
+
interface GetUserAgentOptions {
|
|
11
|
+
/**
|
|
12
|
+
* An optional software name and version, e.g., `"Hollo/1.0.0"`.
|
|
13
|
+
*/
|
|
14
|
+
software?: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* An optional URL to append to the user agent string.
|
|
17
|
+
* Usually the URL of the ActivityPub instance.
|
|
18
|
+
*/
|
|
19
|
+
url?: string | URL | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets the user agent string for the given application and URL.
|
|
23
|
+
* @param options The options for making the user agent string.
|
|
24
|
+
* @returns The user agent string.
|
|
25
|
+
* @since 1.3.0
|
|
26
|
+
*/
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/docloader.d.ts
|
|
29
|
+
/**
|
|
30
|
+
* A remote JSON-LD document and its context fetched by
|
|
31
|
+
* a {@link DocumentLoader}.
|
|
32
|
+
*/
|
|
33
|
+
interface RemoteDocument {
|
|
34
|
+
/**
|
|
35
|
+
* The URL of the context document.
|
|
36
|
+
*/
|
|
37
|
+
contextUrl: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* The fetched JSON-LD document.
|
|
40
|
+
*/
|
|
41
|
+
document: unknown;
|
|
42
|
+
/**
|
|
43
|
+
* The URL of the fetched document.
|
|
44
|
+
*/
|
|
45
|
+
documentUrl: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for {@link DocumentLoader}.
|
|
49
|
+
* @since 1.8.0
|
|
50
|
+
*/
|
|
51
|
+
interface DocumentLoaderOptions {
|
|
52
|
+
/**
|
|
53
|
+
* An `AbortSignal` for cancellation.
|
|
54
|
+
* @since 1.8.0
|
|
55
|
+
*/
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A JSON-LD document loader that fetches documents from the Web.
|
|
60
|
+
* @param url The URL of the document to load.
|
|
61
|
+
* @param options The options for the document loader.
|
|
62
|
+
* @returns The loaded remote document.
|
|
63
|
+
*/
|
|
64
|
+
type DocumentLoader = (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument>;
|
|
65
|
+
/**
|
|
66
|
+
* A factory function that creates a {@link DocumentLoader} with options.
|
|
67
|
+
* @param options The options for the document loader.
|
|
68
|
+
* @returns The document loader.
|
|
69
|
+
* @since 1.4.0
|
|
70
|
+
*/
|
|
71
|
+
type DocumentLoaderFactory = (options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
72
|
+
/**
|
|
73
|
+
* Options for {@link DocumentLoaderFactory}.
|
|
74
|
+
* @see {@link DocumentLoaderFactory}
|
|
75
|
+
* @see {@link AuthenticatedDocumentLoaderFactory}
|
|
76
|
+
* @since 1.4.0
|
|
77
|
+
*/
|
|
78
|
+
interface DocumentLoaderFactoryOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Whether to allow fetching private network addresses.
|
|
81
|
+
* Turned off by default.
|
|
82
|
+
* @default `false``
|
|
83
|
+
*/
|
|
84
|
+
allowPrivateAddress?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Options for making `User-Agent` string.
|
|
87
|
+
* If a string is given, it is used as the `User-Agent` header value.
|
|
88
|
+
* If an object is given, it is passed to {@link getUserAgent} function.
|
|
89
|
+
*/
|
|
90
|
+
userAgent?: GetUserAgentOptions | string;
|
|
91
|
+
/**
|
|
92
|
+
* The maximum number of redirections to follow.
|
|
93
|
+
* @default `20`
|
|
94
|
+
* @since 2.2.0
|
|
95
|
+
*/
|
|
96
|
+
maxRedirection?: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A factory function that creates an authenticated {@link DocumentLoader} for
|
|
100
|
+
* a given identity. This is used for fetching documents that require
|
|
101
|
+
* authentication.
|
|
102
|
+
* @param identity The identity to create the document loader for.
|
|
103
|
+
* The actor's key pair.
|
|
104
|
+
* @param options The options for the document loader.
|
|
105
|
+
* @returns The authenticated document loader.
|
|
106
|
+
* @since 0.4.0
|
|
107
|
+
*/
|
|
108
|
+
type AuthenticatedDocumentLoaderFactory = (identity: {
|
|
109
|
+
keyId: URL;
|
|
110
|
+
privateKey: CryptoKey;
|
|
111
|
+
}, options?: DocumentLoaderFactoryOptions) => DocumentLoader;
|
|
112
|
+
/**
|
|
113
|
+
* Gets a {@link RemoteDocument} from the given response.
|
|
114
|
+
* @param url The URL of the document to load.
|
|
115
|
+
* @param response The response to get the document from.
|
|
116
|
+
* @param fetch The function to fetch the document.
|
|
117
|
+
* @returns The loaded remote document.
|
|
118
|
+
* @throws {FetchError} If the response is not OK.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
//#endregion
|
|
6
122
|
//#region src/types.d.ts
|
|
7
123
|
declare const RELAY_SERVER_ACTOR = "relay";
|
|
8
124
|
/**
|
|
@@ -54,14 +170,6 @@ interface RelayOptions {
|
|
|
54
170
|
*/
|
|
55
171
|
subscriptionHandler: SubscriptionRequestHandler;
|
|
56
172
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Internal storage format for follower data in KV store.
|
|
59
|
-
* Contains JSON-LD representation of the actor.
|
|
60
|
-
* Exported for internal package use but not re-exported from mod.ts.
|
|
61
|
-
*
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
173
|
/**
|
|
66
174
|
* A follower of the relay with validated Actor instance.
|
|
67
175
|
* This is the public API type returned by follower query methods.
|
|
@@ -116,14 +224,6 @@ interface Relay {
|
|
|
116
224
|
*/
|
|
117
225
|
getSharedInboxUri(): Promise<URL>;
|
|
118
226
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Type predicate to check if a value is valid RelayFollowerData from KV store.
|
|
121
|
-
* Validates the storage format (JSON-LD), not the deserialized Actor instance.
|
|
122
|
-
*
|
|
123
|
-
* @param value The value to check
|
|
124
|
-
* @returns true if the value is a RelayFollowerData
|
|
125
|
-
* @internal
|
|
126
|
-
*/
|
|
127
227
|
//#endregion
|
|
128
228
|
//#region src/factory.d.ts
|
|
129
229
|
/**
|
|
@@ -149,4 +249,4 @@ interface Relay {
|
|
|
149
249
|
*/
|
|
150
250
|
declare function createRelay(type: RelayType, options: RelayOptions): Relay;
|
|
151
251
|
//#endregion
|
|
152
|
-
export { RELAY_SERVER_ACTOR, Relay, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay };
|
|
252
|
+
export { RELAY_SERVER_ACTOR, type Relay, type RelayFollower, type RelayOptions, type RelayType, type SubscriptionRequestHandler, createRelay };
|