@fedify/relay 2.0.0-pr.471.1909 → 2.0.0-pr.471.1920
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/mod.cjs +47 -24
- package/dist/mod.js +47 -24
- package/package.json +4 -4
package/dist/mod.cjs
CHANGED
|
@@ -120,21 +120,21 @@ var MastodonRelay = class {
|
|
|
120
120
|
const isPublicFollow = follow.objectId.href === "https://www.w3.org/ns/activitystreams#Public";
|
|
121
121
|
if (!isPublicFollow && parsed?.type !== "actor") return;
|
|
122
122
|
const relayActorUri = ctx.getActorUri(RELAY_SERVER_ACTOR);
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
123
|
+
const follower = await follow.getActor(ctx);
|
|
124
|
+
if (follower == null || follower.id == null || follower.preferredUsername == null || follower.inboxId == null) return;
|
|
125
125
|
let approved = false;
|
|
126
|
-
if (this.#subscriptionHandler) approved = await this.#subscriptionHandler(ctx,
|
|
126
|
+
if (this.#subscriptionHandler) approved = await this.#subscriptionHandler(ctx, follower);
|
|
127
127
|
if (approved) {
|
|
128
128
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
129
129
|
followers.push(follow.id.href);
|
|
130
130
|
await options.kv.set(["followers"], followers);
|
|
131
|
-
await options.kv.set(["follower", follow.id.href], await
|
|
132
|
-
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
131
|
+
await options.kv.set(["follower", follow.id.href], await follower.toJsonLd());
|
|
132
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new __fedify_fedify_vocab.Accept({
|
|
133
133
|
id: new URL(`#accepts`, relayActorUri),
|
|
134
134
|
actor: relayActorUri,
|
|
135
135
|
object: follow
|
|
136
136
|
}));
|
|
137
|
-
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
137
|
+
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new __fedify_fedify_vocab.Reject({
|
|
138
138
|
id: new URL(`#rejects`, relayActorUri),
|
|
139
139
|
actor: relayActorUri,
|
|
140
140
|
object: follow
|
|
@@ -226,6 +226,7 @@ var LitePubRelay = class {
|
|
|
226
226
|
summary: "LitePub-compatible ActivityPub relay server",
|
|
227
227
|
inbox: ctx.getInboxUri(),
|
|
228
228
|
followers: ctx.getFollowersUri(identifier),
|
|
229
|
+
following: ctx.getFollowingUri(identifier),
|
|
229
230
|
url: ctx.getActorUri(identifier),
|
|
230
231
|
publicKey: keys[0].cryptographicKey,
|
|
231
232
|
assertionMethods: keys.map((k) => k.multikey)
|
|
@@ -273,6 +274,9 @@ var LitePubRelay = class {
|
|
|
273
274
|
};
|
|
274
275
|
return [rsaPair, ed25519Pair];
|
|
275
276
|
});
|
|
277
|
+
this.#federation.setFollowingDispatcher("/users/{identifier}/following", (_ctx, _identifier) => {
|
|
278
|
+
return { items: [] };
|
|
279
|
+
}).setCounter((_ctx, _identifier) => 0);
|
|
276
280
|
this.#federation.setFollowersDispatcher("/users/{identifier}/followers", async (_ctx, identifier) => {
|
|
277
281
|
if (identifier !== RELAY_SERVER_ACTOR) return null;
|
|
278
282
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
@@ -292,53 +296,59 @@ var LitePubRelay = class {
|
|
|
292
296
|
const isPublicFollow = follow.objectId.href === "https://www.w3.org/ns/activitystreams#Public";
|
|
293
297
|
if (!isPublicFollow && parsed?.type !== "actor") return;
|
|
294
298
|
const relayActorUri = ctx.getActorUri(RELAY_SERVER_ACTOR);
|
|
295
|
-
const
|
|
296
|
-
if (
|
|
297
|
-
const existingFollow = await options.kv.get(["follower",
|
|
299
|
+
const follower = await follow.getActor(ctx);
|
|
300
|
+
if (follower == null || follower.id == null || follower.preferredUsername == null || follower.inboxId == null) return;
|
|
301
|
+
const existingFollow = await options.kv.get(["follower", follower.id.href]);
|
|
298
302
|
if (existingFollow?.state === "pending") return;
|
|
299
303
|
let subscriptionApproved = false;
|
|
300
|
-
if (this.#subscriptionHandler) subscriptionApproved = await this.#subscriptionHandler(ctx,
|
|
304
|
+
if (this.#subscriptionHandler) subscriptionApproved = await this.#subscriptionHandler(ctx, follower);
|
|
301
305
|
if (subscriptionApproved) {
|
|
302
|
-
await options.kv.set(["follower",
|
|
303
|
-
"actor": await
|
|
306
|
+
await options.kv.set(["follower", follower.id.href], {
|
|
307
|
+
"actor": await follower.toJsonLd(),
|
|
304
308
|
"state": "pending"
|
|
305
309
|
});
|
|
306
|
-
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
310
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new __fedify_fedify_vocab.Accept({
|
|
307
311
|
id: new URL(`#accepts`, relayActorUri),
|
|
308
312
|
actor: relayActorUri,
|
|
309
313
|
object: follow
|
|
310
314
|
}));
|
|
311
|
-
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
315
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new __fedify_fedify_vocab.Follow({
|
|
312
316
|
actor: relayActorUri,
|
|
313
|
-
object:
|
|
314
|
-
to:
|
|
317
|
+
object: follower.id,
|
|
318
|
+
to: follower.id
|
|
315
319
|
}));
|
|
316
|
-
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
320
|
+
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new __fedify_fedify_vocab.Reject({
|
|
317
321
|
id: new URL(`#rejects`, relayActorUri),
|
|
318
322
|
actor: relayActorUri,
|
|
319
323
|
object: follow
|
|
320
324
|
}));
|
|
321
325
|
}).on(__fedify_fedify_vocab.Accept, async (ctx, accept) => {
|
|
322
|
-
const follow = await accept.getObject(
|
|
326
|
+
const follow = await accept.getObject({
|
|
327
|
+
crossOrigin: "trust",
|
|
328
|
+
...ctx
|
|
329
|
+
});
|
|
323
330
|
if (!(follow instanceof __fedify_fedify_vocab.Follow)) return;
|
|
324
|
-
const following = await accept.getActor();
|
|
325
|
-
if (!(0, __fedify_fedify_vocab.isActor)(following)) return;
|
|
326
331
|
const follower = follow.actorId;
|
|
327
332
|
if (follower == null) return;
|
|
333
|
+
const following = await accept.getActor();
|
|
334
|
+
if (!(0, __fedify_fedify_vocab.isActor)(following) || !following.id) return;
|
|
328
335
|
const parsed = ctx.parseUri(follower);
|
|
329
336
|
if (parsed == null || parsed.type !== "actor") return;
|
|
330
|
-
const followerData = await options.kv.get(["follower",
|
|
337
|
+
const followerData = await options.kv.get(["follower", following.id.href]);
|
|
331
338
|
if (followerData == null) return;
|
|
332
339
|
const updatedFollowerData = {
|
|
333
340
|
...followerData,
|
|
334
341
|
status: "accepted"
|
|
335
342
|
};
|
|
336
|
-
await options.kv.set(["follower",
|
|
343
|
+
await options.kv.set(["follower", following.id.href], updatedFollowerData);
|
|
337
344
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
338
|
-
followers.push(
|
|
345
|
+
followers.push(following.id.href);
|
|
339
346
|
await options.kv.set(["followers"], followers);
|
|
340
347
|
}).on(__fedify_fedify_vocab.Undo, async (ctx, undo) => {
|
|
341
|
-
const activity = await undo.getObject(
|
|
348
|
+
const activity = await undo.getObject({
|
|
349
|
+
crossOrigin: "trust",
|
|
350
|
+
...ctx
|
|
351
|
+
});
|
|
342
352
|
if (activity instanceof __fedify_fedify_vocab.Follow) {
|
|
343
353
|
if (activity.id == null || activity.actorId == null) return;
|
|
344
354
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
@@ -402,6 +412,19 @@ var LitePubRelay = class {
|
|
|
402
412
|
excludeBaseUris,
|
|
403
413
|
preferSharedInbox: true
|
|
404
414
|
});
|
|
415
|
+
}).on(__fedify_fedify_vocab.Announce, async (ctx, announceActivity) => {
|
|
416
|
+
const sender = await announceActivity.getActor(ctx);
|
|
417
|
+
const excludeBaseUris = sender?.id ? [new URL(sender.id)] : [];
|
|
418
|
+
const announce = new __fedify_fedify_vocab.Announce({
|
|
419
|
+
id: new URL(`/announce#${crypto.randomUUID()}`, ctx.origin),
|
|
420
|
+
actor: ctx.getActorUri(RELAY_SERVER_ACTOR),
|
|
421
|
+
object: announceActivity.objectId,
|
|
422
|
+
to: __fedify_fedify_vocab.PUBLIC_COLLECTION
|
|
423
|
+
});
|
|
424
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, "followers", announce, {
|
|
425
|
+
excludeBaseUris,
|
|
426
|
+
preferSharedInbox: true
|
|
427
|
+
});
|
|
405
428
|
});
|
|
406
429
|
}
|
|
407
430
|
get domain() {
|
package/dist/mod.js
CHANGED
|
@@ -97,21 +97,21 @@ var MastodonRelay = class {
|
|
|
97
97
|
const isPublicFollow = follow.objectId.href === "https://www.w3.org/ns/activitystreams#Public";
|
|
98
98
|
if (!isPublicFollow && parsed?.type !== "actor") return;
|
|
99
99
|
const relayActorUri = ctx.getActorUri(RELAY_SERVER_ACTOR);
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
100
|
+
const follower = await follow.getActor(ctx);
|
|
101
|
+
if (follower == null || follower.id == null || follower.preferredUsername == null || follower.inboxId == null) return;
|
|
102
102
|
let approved = false;
|
|
103
|
-
if (this.#subscriptionHandler) approved = await this.#subscriptionHandler(ctx,
|
|
103
|
+
if (this.#subscriptionHandler) approved = await this.#subscriptionHandler(ctx, follower);
|
|
104
104
|
if (approved) {
|
|
105
105
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
106
106
|
followers.push(follow.id.href);
|
|
107
107
|
await options.kv.set(["followers"], followers);
|
|
108
|
-
await options.kv.set(["follower", follow.id.href], await
|
|
109
|
-
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
108
|
+
await options.kv.set(["follower", follow.id.href], await follower.toJsonLd());
|
|
109
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new Accept({
|
|
110
110
|
id: new URL(`#accepts`, relayActorUri),
|
|
111
111
|
actor: relayActorUri,
|
|
112
112
|
object: follow
|
|
113
113
|
}));
|
|
114
|
-
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
114
|
+
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new Reject({
|
|
115
115
|
id: new URL(`#rejects`, relayActorUri),
|
|
116
116
|
actor: relayActorUri,
|
|
117
117
|
object: follow
|
|
@@ -203,6 +203,7 @@ var LitePubRelay = class {
|
|
|
203
203
|
summary: "LitePub-compatible ActivityPub relay server",
|
|
204
204
|
inbox: ctx.getInboxUri(),
|
|
205
205
|
followers: ctx.getFollowersUri(identifier),
|
|
206
|
+
following: ctx.getFollowingUri(identifier),
|
|
206
207
|
url: ctx.getActorUri(identifier),
|
|
207
208
|
publicKey: keys[0].cryptographicKey,
|
|
208
209
|
assertionMethods: keys.map((k) => k.multikey)
|
|
@@ -250,6 +251,9 @@ var LitePubRelay = class {
|
|
|
250
251
|
};
|
|
251
252
|
return [rsaPair, ed25519Pair];
|
|
252
253
|
});
|
|
254
|
+
this.#federation.setFollowingDispatcher("/users/{identifier}/following", (_ctx, _identifier) => {
|
|
255
|
+
return { items: [] };
|
|
256
|
+
}).setCounter((_ctx, _identifier) => 0);
|
|
253
257
|
this.#federation.setFollowersDispatcher("/users/{identifier}/followers", async (_ctx, identifier) => {
|
|
254
258
|
if (identifier !== RELAY_SERVER_ACTOR) return null;
|
|
255
259
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
@@ -269,53 +273,59 @@ var LitePubRelay = class {
|
|
|
269
273
|
const isPublicFollow = follow.objectId.href === "https://www.w3.org/ns/activitystreams#Public";
|
|
270
274
|
if (!isPublicFollow && parsed?.type !== "actor") return;
|
|
271
275
|
const relayActorUri = ctx.getActorUri(RELAY_SERVER_ACTOR);
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
const existingFollow = await options.kv.get(["follower",
|
|
276
|
+
const follower = await follow.getActor(ctx);
|
|
277
|
+
if (follower == null || follower.id == null || follower.preferredUsername == null || follower.inboxId == null) return;
|
|
278
|
+
const existingFollow = await options.kv.get(["follower", follower.id.href]);
|
|
275
279
|
if (existingFollow?.state === "pending") return;
|
|
276
280
|
let subscriptionApproved = false;
|
|
277
|
-
if (this.#subscriptionHandler) subscriptionApproved = await this.#subscriptionHandler(ctx,
|
|
281
|
+
if (this.#subscriptionHandler) subscriptionApproved = await this.#subscriptionHandler(ctx, follower);
|
|
278
282
|
if (subscriptionApproved) {
|
|
279
|
-
await options.kv.set(["follower",
|
|
280
|
-
"actor": await
|
|
283
|
+
await options.kv.set(["follower", follower.id.href], {
|
|
284
|
+
"actor": await follower.toJsonLd(),
|
|
281
285
|
"state": "pending"
|
|
282
286
|
});
|
|
283
|
-
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
287
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new Accept({
|
|
284
288
|
id: new URL(`#accepts`, relayActorUri),
|
|
285
289
|
actor: relayActorUri,
|
|
286
290
|
object: follow
|
|
287
291
|
}));
|
|
288
|
-
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
292
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new Follow({
|
|
289
293
|
actor: relayActorUri,
|
|
290
|
-
object:
|
|
291
|
-
to:
|
|
294
|
+
object: follower.id,
|
|
295
|
+
to: follower.id
|
|
292
296
|
}));
|
|
293
|
-
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR },
|
|
297
|
+
} else await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, follower, new Reject({
|
|
294
298
|
id: new URL(`#rejects`, relayActorUri),
|
|
295
299
|
actor: relayActorUri,
|
|
296
300
|
object: follow
|
|
297
301
|
}));
|
|
298
302
|
}).on(Accept, async (ctx, accept) => {
|
|
299
|
-
const follow = await accept.getObject(
|
|
303
|
+
const follow = await accept.getObject({
|
|
304
|
+
crossOrigin: "trust",
|
|
305
|
+
...ctx
|
|
306
|
+
});
|
|
300
307
|
if (!(follow instanceof Follow)) return;
|
|
301
|
-
const following = await accept.getActor();
|
|
302
|
-
if (!isActor(following)) return;
|
|
303
308
|
const follower = follow.actorId;
|
|
304
309
|
if (follower == null) return;
|
|
310
|
+
const following = await accept.getActor();
|
|
311
|
+
if (!isActor(following) || !following.id) return;
|
|
305
312
|
const parsed = ctx.parseUri(follower);
|
|
306
313
|
if (parsed == null || parsed.type !== "actor") return;
|
|
307
|
-
const followerData = await options.kv.get(["follower",
|
|
314
|
+
const followerData = await options.kv.get(["follower", following.id.href]);
|
|
308
315
|
if (followerData == null) return;
|
|
309
316
|
const updatedFollowerData = {
|
|
310
317
|
...followerData,
|
|
311
318
|
status: "accepted"
|
|
312
319
|
};
|
|
313
|
-
await options.kv.set(["follower",
|
|
320
|
+
await options.kv.set(["follower", following.id.href], updatedFollowerData);
|
|
314
321
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
315
|
-
followers.push(
|
|
322
|
+
followers.push(following.id.href);
|
|
316
323
|
await options.kv.set(["followers"], followers);
|
|
317
324
|
}).on(Undo, async (ctx, undo) => {
|
|
318
|
-
const activity = await undo.getObject(
|
|
325
|
+
const activity = await undo.getObject({
|
|
326
|
+
crossOrigin: "trust",
|
|
327
|
+
...ctx
|
|
328
|
+
});
|
|
319
329
|
if (activity instanceof Follow) {
|
|
320
330
|
if (activity.id == null || activity.actorId == null) return;
|
|
321
331
|
const followers = await options.kv.get(["followers"]) ?? [];
|
|
@@ -379,6 +389,19 @@ var LitePubRelay = class {
|
|
|
379
389
|
excludeBaseUris,
|
|
380
390
|
preferSharedInbox: true
|
|
381
391
|
});
|
|
392
|
+
}).on(Announce, async (ctx, announceActivity) => {
|
|
393
|
+
const sender = await announceActivity.getActor(ctx);
|
|
394
|
+
const excludeBaseUris = sender?.id ? [new URL(sender.id)] : [];
|
|
395
|
+
const announce = new Announce({
|
|
396
|
+
id: new URL(`/announce#${crypto.randomUUID()}`, ctx.origin),
|
|
397
|
+
actor: ctx.getActorUri(RELAY_SERVER_ACTOR),
|
|
398
|
+
object: announceActivity.objectId,
|
|
399
|
+
to: PUBLIC_COLLECTION
|
|
400
|
+
});
|
|
401
|
+
await ctx.sendActivity({ identifier: RELAY_SERVER_ACTOR }, "followers", announce, {
|
|
402
|
+
excludeBaseUris,
|
|
403
|
+
preferSharedInbox: true
|
|
404
|
+
});
|
|
382
405
|
});
|
|
383
406
|
}
|
|
384
407
|
get domain() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/relay",
|
|
3
|
-
"version": "2.0.0-pr.471.
|
|
3
|
+
"version": "2.0.0-pr.471.1920+38258210",
|
|
4
4
|
"description": "ActivityPub relay support for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
"package.json"
|
|
49
49
|
],
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@fedify/fedify": "^2.0.0-pr.471.
|
|
51
|
+
"@fedify/fedify": "^2.0.0-pr.471.1920+38258210"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsdown": "^0.12.9",
|
|
55
55
|
"typescript": "^5.9.3",
|
|
56
|
-
"@fedify/testing": "^2.0.0-pr.471.
|
|
57
|
-
"@fedify/vocab-runtime": "^2.0.0-pr.471.
|
|
56
|
+
"@fedify/testing": "^2.0.0-pr.471.1920+38258210",
|
|
57
|
+
"@fedify/vocab-runtime": "^2.0.0-pr.471.1920+38258210"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "deno task codegen && tsdown",
|