@oxy.so/federation 3.0.0 → 3.2.0
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/cjs/index.js +17 -30
- package/dist/cjs/network.js +43 -0
- package/dist/cjs/node/delivery.js +16 -1
- package/dist/esm/index.js +2 -11
- package/dist/esm/network.js +22 -0
- package/dist/esm/node/delivery.js +16 -1
- package/dist/types/index.d.ts +2 -11
- package/dist/types/network.d.ts +12 -0
- package/dist/types/node/delivery.d.ts +10 -2
- package/package.json +12 -1
- package/src/__tests__/delivery.test.ts +27 -0
- package/src/__tests__/networkEntry.test.ts +26 -0
- package/src/index.ts +2 -40
- package/src/network.ts +51 -0
- package/src/node/delivery.ts +27 -1
package/dist/cjs/index.js
CHANGED
|
@@ -21,8 +21,22 @@
|
|
|
21
21
|
* the consuming app (Mention passes its `PostContent`). The engine holds no
|
|
22
22
|
* knowledge of any app's post shape.
|
|
23
23
|
*/
|
|
24
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
27
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
28
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
29
|
+
}
|
|
30
|
+
Object.defineProperty(o, k2, desc);
|
|
31
|
+
}) : (function(o, m, k, k2) {
|
|
32
|
+
if (k2 === undefined) k2 = k;
|
|
33
|
+
o[k2] = m[k];
|
|
34
|
+
}));
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
24
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.groupFollowersCollection = exports.groupOutboxCollection = exports.isGroupActorKind = exports.GROUP_OUTBOX_SIZE = exports.LOCAL_ACTOR_TYPE_BY_ACCOUNT_KIND = exports.AP_ACTOR_TYPES = exports.isApActorType = exports.accountKindForActor = exports.localActorTypeForAccountKind = exports.normalizeAlsoKnownAs = exports.createLocalActorBuilder = exports.apDate = exports.isActivityPubMediaType = exports.apMediaTypeBase = exports.apImageUrl = exports.apIriList = exports.apIri = exports.apList = exports.createDomainPolicy = exports.extractActorUriFromActivityId = exports.isSameFederationHost = exports.canonicalFederationHost = exports.AP_CONTEXT = exports.
|
|
39
|
+
exports.groupFollowersCollection = exports.groupOutboxCollection = exports.isGroupActorKind = exports.GROUP_OUTBOX_SIZE = exports.LOCAL_ACTOR_TYPE_BY_ACCOUNT_KIND = exports.AP_ACTOR_TYPES = exports.isApActorType = exports.accountKindForActor = exports.localActorTypeForAccountKind = exports.normalizeAlsoKnownAs = exports.createLocalActorBuilder = exports.apDate = exports.isActivityPubMediaType = exports.apMediaTypeBase = exports.apImageUrl = exports.apIriList = exports.apIri = exports.apList = exports.createDomainPolicy = exports.extractActorUriFromActivityId = exports.isSameFederationHost = exports.canonicalFederationHost = exports.AP_CONTEXT = exports.INSTANCE_ACTOR_USERNAME = exports.normalizeActorUsername = exports.createUrlBuilders = exports.DEFAULT_SIGNED_CONTENT_TYPE = exports.HTTP_SIGNATURE_ALGORITHM = exports.verifyHttpSignature = exports.signRequest = void 0;
|
|
26
40
|
/**
|
|
27
41
|
* HTTP Signatures (draft-cavage) — the pure sign/verify crypto every Oxy app's
|
|
28
42
|
* ActivityPub federation shares. Private-key custody is injected; the key never
|
|
@@ -41,35 +55,8 @@ var urls_1 = require("./urls");
|
|
|
41
55
|
Object.defineProperty(exports, "createUrlBuilders", { enumerable: true, get: function () { return urls_1.createUrlBuilders; } });
|
|
42
56
|
Object.defineProperty(exports, "normalizeActorUsername", { enumerable: true, get: function () { return urls_1.normalizeActorUsername; } });
|
|
43
57
|
Object.defineProperty(exports, "INSTANCE_ACTOR_USERNAME", { enumerable: true, get: function () { return urls_1.INSTANCE_ACTOR_USERNAME; } });
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
* bridge onto the network it actually came from, plus the network vocabulary and
|
|
47
|
-
* the bidirectional upstream-profile-URL rule.
|
|
48
|
-
*
|
|
49
|
-
* The mechanism is here; the ENTRIES are not, and must not be. Which operators
|
|
50
|
-
* may be trusted to re-attribute somebody's account is a moderation judgement an
|
|
51
|
-
* app commits and answers for — `createBridgeRelabeller` takes them as a
|
|
52
|
-
* parameter so no app inherits another's.
|
|
53
|
-
*/
|
|
54
|
-
var networkIdentity_1 = require("./networkIdentity");
|
|
55
|
-
Object.defineProperty(exports, "FEDERATION_NETWORKS", { enumerable: true, get: function () { return networkIdentity_1.FEDERATION_NETWORKS; } });
|
|
56
|
-
Object.defineProperty(exports, "BSKY_NETWORK_DOMAIN", { enumerable: true, get: function () { return networkIdentity_1.BSKY_NETWORK_DOMAIN; } });
|
|
57
|
-
Object.defineProperty(exports, "blueskyUsernameFromHandle", { enumerable: true, get: function () { return networkIdentity_1.blueskyUsernameFromHandle; } });
|
|
58
|
-
Object.defineProperty(exports, "blueskyHandleFromUsername", { enumerable: true, get: function () { return networkIdentity_1.blueskyHandleFromUsername; } });
|
|
59
|
-
Object.defineProperty(exports, "UNRESOLVED_ATPROTO_HANDLE", { enumerable: true, get: function () { return networkIdentity_1.UNRESOLVED_ATPROTO_HANDLE; } });
|
|
60
|
-
Object.defineProperty(exports, "isUnresolvedAtprotoHandle", { enumerable: true, get: function () { return networkIdentity_1.isUnresolvedAtprotoHandle; } });
|
|
61
|
-
Object.defineProperty(exports, "atprotoIdentityHandle", { enumerable: true, get: function () { return networkIdentity_1.atprotoIdentityHandle; } });
|
|
62
|
-
Object.defineProperty(exports, "createBridgeRelabeller", { enumerable: true, get: function () { return networkIdentity_1.createBridgeRelabeller; } });
|
|
63
|
-
Object.defineProperty(exports, "stripBridgeBoilerplate", { enumerable: true, get: function () { return networkIdentity_1.stripBridgeBoilerplate; } });
|
|
64
|
-
Object.defineProperty(exports, "upstreamProfileUrl", { enumerable: true, get: function () { return networkIdentity_1.upstreamProfileUrl; } });
|
|
65
|
-
Object.defineProperty(exports, "parseUpstreamProfileUrl", { enumerable: true, get: function () { return networkIdentity_1.parseUpstreamProfileUrl; } });
|
|
66
|
-
Object.defineProperty(exports, "federatedUsernameFromUpstreamUrl", { enumerable: true, get: function () { return networkIdentity_1.federatedUsernameFromUpstreamUrl; } });
|
|
67
|
-
Object.defineProperty(exports, "upstreamHandleFromProfileField", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromProfileField; } });
|
|
68
|
-
Object.defineProperty(exports, "upstreamHandleFromAlsoKnownAs", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromAlsoKnownAs; } });
|
|
69
|
-
Object.defineProperty(exports, "upstreamHandleFromAutomatedActor", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromAutomatedActor; } });
|
|
70
|
-
Object.defineProperty(exports, "upstreamHandleFromPreferredUsername", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromPreferredUsername; } });
|
|
71
|
-
Object.defineProperty(exports, "upstreamHandleFromProxyOf", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromProxyOf; } });
|
|
72
|
-
Object.defineProperty(exports, "readProxyDeclarations", { enumerable: true, get: function () { return networkIdentity_1.readProxyDeclarations; } });
|
|
58
|
+
/** Network identity — see `./network`, the Node-free entry it is also served from. */
|
|
59
|
+
__exportStar(require("./network"), exports);
|
|
73
60
|
/**
|
|
74
61
|
* The shared JSON-LD `@context` (load-bearing term declarations) and the
|
|
75
62
|
* ActivityPub URI helpers (actor-uri extraction + the per-instance domain policy:
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readProxyDeclarations = exports.upstreamHandleFromProxyOf = exports.upstreamHandleFromPreferredUsername = exports.upstreamHandleFromAutomatedActor = exports.upstreamHandleFromAlsoKnownAs = exports.upstreamHandleFromProfileField = exports.federatedUsernameFromUpstreamUrl = exports.parseUpstreamProfileUrl = exports.upstreamProfileUrl = exports.stripBridgeBoilerplate = exports.createBridgeRelabeller = exports.atprotoIdentityHandle = exports.isUnresolvedAtprotoHandle = exports.UNRESOLVED_ATPROTO_HANDLE = exports.blueskyHandleFromUsername = exports.blueskyUsernameFromHandle = exports.BSKY_NETWORK_DOMAIN = exports.FEDERATION_NETWORKS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `@oxy.so/federation/network` — the network vocabulary and the network-identity
|
|
6
|
+
* rules, with nothing that needs Node.
|
|
7
|
+
*
|
|
8
|
+
* The package root also exports HTTP signatures, which import `node:crypto`, so a
|
|
9
|
+
* web or React Native bundle cannot import the root. A client that has to
|
|
10
|
+
* recognise an upstream profile URL the same way the server does (a composer
|
|
11
|
+
* deciding which links become mentions) imports this entry instead, and reads
|
|
12
|
+
* the same declaration rather than a copy of it. Everything here is also exported
|
|
13
|
+
* from the root.
|
|
14
|
+
*/
|
|
15
|
+
/*
|
|
16
|
+
* Network identity: the MECHANISM for re-labelling an account republished by a
|
|
17
|
+
* bridge onto the network it actually came from, plus the network vocabulary and
|
|
18
|
+
* the bidirectional upstream-profile-URL rule.
|
|
19
|
+
*
|
|
20
|
+
* The mechanism is here; the ENTRIES are not, and must not be. Which operators
|
|
21
|
+
* may be trusted to re-attribute somebody's account is a moderation judgement an
|
|
22
|
+
* app commits and answers for — `createBridgeRelabeller` takes them as a
|
|
23
|
+
* parameter so no app inherits another's.
|
|
24
|
+
*/
|
|
25
|
+
var networkIdentity_1 = require("./networkIdentity");
|
|
26
|
+
Object.defineProperty(exports, "FEDERATION_NETWORKS", { enumerable: true, get: function () { return networkIdentity_1.FEDERATION_NETWORKS; } });
|
|
27
|
+
Object.defineProperty(exports, "BSKY_NETWORK_DOMAIN", { enumerable: true, get: function () { return networkIdentity_1.BSKY_NETWORK_DOMAIN; } });
|
|
28
|
+
Object.defineProperty(exports, "blueskyUsernameFromHandle", { enumerable: true, get: function () { return networkIdentity_1.blueskyUsernameFromHandle; } });
|
|
29
|
+
Object.defineProperty(exports, "blueskyHandleFromUsername", { enumerable: true, get: function () { return networkIdentity_1.blueskyHandleFromUsername; } });
|
|
30
|
+
Object.defineProperty(exports, "UNRESOLVED_ATPROTO_HANDLE", { enumerable: true, get: function () { return networkIdentity_1.UNRESOLVED_ATPROTO_HANDLE; } });
|
|
31
|
+
Object.defineProperty(exports, "isUnresolvedAtprotoHandle", { enumerable: true, get: function () { return networkIdentity_1.isUnresolvedAtprotoHandle; } });
|
|
32
|
+
Object.defineProperty(exports, "atprotoIdentityHandle", { enumerable: true, get: function () { return networkIdentity_1.atprotoIdentityHandle; } });
|
|
33
|
+
Object.defineProperty(exports, "createBridgeRelabeller", { enumerable: true, get: function () { return networkIdentity_1.createBridgeRelabeller; } });
|
|
34
|
+
Object.defineProperty(exports, "stripBridgeBoilerplate", { enumerable: true, get: function () { return networkIdentity_1.stripBridgeBoilerplate; } });
|
|
35
|
+
Object.defineProperty(exports, "upstreamProfileUrl", { enumerable: true, get: function () { return networkIdentity_1.upstreamProfileUrl; } });
|
|
36
|
+
Object.defineProperty(exports, "parseUpstreamProfileUrl", { enumerable: true, get: function () { return networkIdentity_1.parseUpstreamProfileUrl; } });
|
|
37
|
+
Object.defineProperty(exports, "federatedUsernameFromUpstreamUrl", { enumerable: true, get: function () { return networkIdentity_1.federatedUsernameFromUpstreamUrl; } });
|
|
38
|
+
Object.defineProperty(exports, "upstreamHandleFromProfileField", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromProfileField; } });
|
|
39
|
+
Object.defineProperty(exports, "upstreamHandleFromAlsoKnownAs", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromAlsoKnownAs; } });
|
|
40
|
+
Object.defineProperty(exports, "upstreamHandleFromAutomatedActor", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromAutomatedActor; } });
|
|
41
|
+
Object.defineProperty(exports, "upstreamHandleFromPreferredUsername", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromPreferredUsername; } });
|
|
42
|
+
Object.defineProperty(exports, "upstreamHandleFromProxyOf", { enumerable: true, get: function () { return networkIdentity_1.upstreamHandleFromProxyOf; } });
|
|
43
|
+
Object.defineProperty(exports, "readProxyDeclarations", { enumerable: true, get: function () { return networkIdentity_1.readProxyDeclarations; } });
|
|
@@ -257,7 +257,7 @@ function createDeliveryService(config) {
|
|
|
257
257
|
}
|
|
258
258
|
})();
|
|
259
259
|
}
|
|
260
|
-
async function sendFollow(localOxyUserId, localUsername, remoteActorUri) {
|
|
260
|
+
async function sendFollow(localOxyUserId, localUsername, remoteActorUri, options = {}) {
|
|
261
261
|
if (!config.federationEnabled)
|
|
262
262
|
return { success: false, pending: false };
|
|
263
263
|
if (isBlockedUrl(remoteActorUri)) {
|
|
@@ -283,6 +283,21 @@ function createDeliveryService(config) {
|
|
|
283
283
|
};
|
|
284
284
|
// Refuse before committing an outbound follow or reporting success.
|
|
285
285
|
await authorizeDelivery(activity, localOxyUserId);
|
|
286
|
+
if (options.durable) {
|
|
287
|
+
// The caller may exit as soon as this resolves, so nothing is left to the
|
|
288
|
+
// background: the inbox is resolved now, and the Follow is in the delivery
|
|
289
|
+
// queue (whose worker retries it) before the follow is reported.
|
|
290
|
+
const actor = cached?.sharedInboxUrl || cached?.inboxUrl
|
|
291
|
+
? cached
|
|
292
|
+
: await config.actorRefresh.fetchRemoteActor(remoteActorUri);
|
|
293
|
+
const inbox = actor?.sharedInboxUrl ?? actor?.inboxUrl;
|
|
294
|
+
if (!inbox || isBlockedUrl(inbox)) {
|
|
295
|
+
throw new Error(`No inbox to deliver the Follow to ${remoteActorUri}`);
|
|
296
|
+
}
|
|
297
|
+
await config.follows.upsertOutboundPending(localOxyUserId, canonicalUri, activityId);
|
|
298
|
+
await queueDelivery(activity, inbox, localOxyUserId);
|
|
299
|
+
return { success: true, pending: actor?.manuallyApprovesFollowers ?? false };
|
|
300
|
+
}
|
|
286
301
|
// A refused follow must not start remote actor discovery either.
|
|
287
302
|
config.actorRefresh.refreshActorInBackground(remoteActorUri, cached ?? undefined);
|
|
288
303
|
await config.follows.upsertOutboundPending(localOxyUserId, canonicalUri, activityId);
|
package/dist/esm/index.js
CHANGED
|
@@ -31,17 +31,8 @@ export { signRequest, verifyHttpSignature, HTTP_SIGNATURE_ALGORITHM, DEFAULT_SIG
|
|
|
31
31
|
* with its own `FEDERATION_DOMAIN` so every actor stays `@user@its-own-domain`.
|
|
32
32
|
*/
|
|
33
33
|
export { createUrlBuilders, normalizeActorUsername, INSTANCE_ACTOR_USERNAME, } from './urls.js';
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* bridge onto the network it actually came from, plus the network vocabulary and
|
|
37
|
-
* the bidirectional upstream-profile-URL rule.
|
|
38
|
-
*
|
|
39
|
-
* The mechanism is here; the ENTRIES are not, and must not be. Which operators
|
|
40
|
-
* may be trusted to re-attribute somebody's account is a moderation judgement an
|
|
41
|
-
* app commits and answers for — `createBridgeRelabeller` takes them as a
|
|
42
|
-
* parameter so no app inherits another's.
|
|
43
|
-
*/
|
|
44
|
-
export { FEDERATION_NETWORKS, BSKY_NETWORK_DOMAIN, blueskyUsernameFromHandle, blueskyHandleFromUsername, UNRESOLVED_ATPROTO_HANDLE, isUnresolvedAtprotoHandle, atprotoIdentityHandle, createBridgeRelabeller, stripBridgeBoilerplate, upstreamProfileUrl, parseUpstreamProfileUrl, federatedUsernameFromUpstreamUrl, upstreamHandleFromProfileField, upstreamHandleFromAlsoKnownAs, upstreamHandleFromAutomatedActor, upstreamHandleFromPreferredUsername, upstreamHandleFromProxyOf, readProxyDeclarations, } from './networkIdentity.js';
|
|
34
|
+
/** Network identity — see `./network`, the Node-free entry it is also served from. */
|
|
35
|
+
export * from './network.js';
|
|
45
36
|
/**
|
|
46
37
|
* The shared JSON-LD `@context` (load-bearing term declarations) and the
|
|
47
38
|
* ActivityPub URI helpers (actor-uri extraction + the per-instance domain policy:
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@oxy.so/federation/network` — the network vocabulary and the network-identity
|
|
3
|
+
* rules, with nothing that needs Node.
|
|
4
|
+
*
|
|
5
|
+
* The package root also exports HTTP signatures, which import `node:crypto`, so a
|
|
6
|
+
* web or React Native bundle cannot import the root. A client that has to
|
|
7
|
+
* recognise an upstream profile URL the same way the server does (a composer
|
|
8
|
+
* deciding which links become mentions) imports this entry instead, and reads
|
|
9
|
+
* the same declaration rather than a copy of it. Everything here is also exported
|
|
10
|
+
* from the root.
|
|
11
|
+
*/
|
|
12
|
+
/*
|
|
13
|
+
* Network identity: the MECHANISM for re-labelling an account republished by a
|
|
14
|
+
* bridge onto the network it actually came from, plus the network vocabulary and
|
|
15
|
+
* the bidirectional upstream-profile-URL rule.
|
|
16
|
+
*
|
|
17
|
+
* The mechanism is here; the ENTRIES are not, and must not be. Which operators
|
|
18
|
+
* may be trusted to re-attribute somebody's account is a moderation judgement an
|
|
19
|
+
* app commits and answers for — `createBridgeRelabeller` takes them as a
|
|
20
|
+
* parameter so no app inherits another's.
|
|
21
|
+
*/
|
|
22
|
+
export { FEDERATION_NETWORKS, BSKY_NETWORK_DOMAIN, blueskyUsernameFromHandle, blueskyHandleFromUsername, UNRESOLVED_ATPROTO_HANDLE, isUnresolvedAtprotoHandle, atprotoIdentityHandle, createBridgeRelabeller, stripBridgeBoilerplate, upstreamProfileUrl, parseUpstreamProfileUrl, federatedUsernameFromUpstreamUrl, upstreamHandleFromProfileField, upstreamHandleFromAlsoKnownAs, upstreamHandleFromAutomatedActor, upstreamHandleFromPreferredUsername, upstreamHandleFromProxyOf, readProxyDeclarations, } from './networkIdentity.js';
|
|
@@ -252,7 +252,7 @@ export function createDeliveryService(config) {
|
|
|
252
252
|
}
|
|
253
253
|
})();
|
|
254
254
|
}
|
|
255
|
-
async function sendFollow(localOxyUserId, localUsername, remoteActorUri) {
|
|
255
|
+
async function sendFollow(localOxyUserId, localUsername, remoteActorUri, options = {}) {
|
|
256
256
|
if (!config.federationEnabled)
|
|
257
257
|
return { success: false, pending: false };
|
|
258
258
|
if (isBlockedUrl(remoteActorUri)) {
|
|
@@ -278,6 +278,21 @@ export function createDeliveryService(config) {
|
|
|
278
278
|
};
|
|
279
279
|
// Refuse before committing an outbound follow or reporting success.
|
|
280
280
|
await authorizeDelivery(activity, localOxyUserId);
|
|
281
|
+
if (options.durable) {
|
|
282
|
+
// The caller may exit as soon as this resolves, so nothing is left to the
|
|
283
|
+
// background: the inbox is resolved now, and the Follow is in the delivery
|
|
284
|
+
// queue (whose worker retries it) before the follow is reported.
|
|
285
|
+
const actor = cached?.sharedInboxUrl || cached?.inboxUrl
|
|
286
|
+
? cached
|
|
287
|
+
: await config.actorRefresh.fetchRemoteActor(remoteActorUri);
|
|
288
|
+
const inbox = actor?.sharedInboxUrl ?? actor?.inboxUrl;
|
|
289
|
+
if (!inbox || isBlockedUrl(inbox)) {
|
|
290
|
+
throw new Error(`No inbox to deliver the Follow to ${remoteActorUri}`);
|
|
291
|
+
}
|
|
292
|
+
await config.follows.upsertOutboundPending(localOxyUserId, canonicalUri, activityId);
|
|
293
|
+
await queueDelivery(activity, inbox, localOxyUserId);
|
|
294
|
+
return { success: true, pending: actor?.manuallyApprovesFollowers ?? false };
|
|
295
|
+
}
|
|
281
296
|
// A refused follow must not start remote actor discovery either.
|
|
282
297
|
config.actorRefresh.refreshActorInBackground(remoteActorUri, cached ?? undefined);
|
|
283
298
|
await config.follows.upsertOutboundPending(localOxyUserId, canonicalUri, activityId);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -31,17 +31,8 @@ export { signRequest, verifyHttpSignature, HTTP_SIGNATURE_ALGORITHM, DEFAULT_SIG
|
|
|
31
31
|
* with its own `FEDERATION_DOMAIN` so every actor stays `@user@its-own-domain`.
|
|
32
32
|
*/
|
|
33
33
|
export { createUrlBuilders, normalizeActorUsername, INSTANCE_ACTOR_USERNAME, type UrlBuilders, } from './urls';
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* bridge onto the network it actually came from, plus the network vocabulary and
|
|
37
|
-
* the bidirectional upstream-profile-URL rule.
|
|
38
|
-
*
|
|
39
|
-
* The mechanism is here; the ENTRIES are not, and must not be. Which operators
|
|
40
|
-
* may be trusted to re-attribute somebody's account is a moderation judgement an
|
|
41
|
-
* app commits and answers for — `createBridgeRelabeller` takes them as a
|
|
42
|
-
* parameter so no app inherits another's.
|
|
43
|
-
*/
|
|
44
|
-
export { FEDERATION_NETWORKS, BSKY_NETWORK_DOMAIN, blueskyUsernameFromHandle, blueskyHandleFromUsername, UNRESOLVED_ATPROTO_HANDLE, isUnresolvedAtprotoHandle, atprotoIdentityHandle, createBridgeRelabeller, stripBridgeBoilerplate, upstreamProfileUrl, parseUpstreamProfileUrl, federatedUsernameFromUpstreamUrl, upstreamHandleFromProfileField, upstreamHandleFromAlsoKnownAs, upstreamHandleFromAutomatedActor, upstreamHandleFromPreferredUsername, upstreamHandleFromProxyOf, readProxyDeclarations, type FederationNetwork, type FederationBridgeEntry, type BridgeRelabeller, type BridgeConsentModel, type BridgeDerivation, type BridgedActorField, type DeriveNetworkIdentity, type NetworkIdentity, type NetworkIdentityCandidate, type ProxyDeclaration, } from './networkIdentity';
|
|
34
|
+
/** Network identity — see `./network`, the Node-free entry it is also served from. */
|
|
35
|
+
export * from './network';
|
|
45
36
|
/**
|
|
46
37
|
* The shared JSON-LD `@context` (load-bearing term declarations) and the
|
|
47
38
|
* ActivityPub URI helpers (actor-uri extraction + the per-instance domain policy:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@oxy.so/federation/network` — the network vocabulary and the network-identity
|
|
3
|
+
* rules, with nothing that needs Node.
|
|
4
|
+
*
|
|
5
|
+
* The package root also exports HTTP signatures, which import `node:crypto`, so a
|
|
6
|
+
* web or React Native bundle cannot import the root. A client that has to
|
|
7
|
+
* recognise an upstream profile URL the same way the server does (a composer
|
|
8
|
+
* deciding which links become mentions) imports this entry instead, and reads
|
|
9
|
+
* the same declaration rather than a copy of it. Everything here is also exported
|
|
10
|
+
* from the root.
|
|
11
|
+
*/
|
|
12
|
+
export { FEDERATION_NETWORKS, BSKY_NETWORK_DOMAIN, blueskyUsernameFromHandle, blueskyHandleFromUsername, UNRESOLVED_ATPROTO_HANDLE, isUnresolvedAtprotoHandle, atprotoIdentityHandle, createBridgeRelabeller, stripBridgeBoilerplate, upstreamProfileUrl, parseUpstreamProfileUrl, federatedUsernameFromUpstreamUrl, upstreamHandleFromProfileField, upstreamHandleFromAlsoKnownAs, upstreamHandleFromAutomatedActor, upstreamHandleFromPreferredUsername, upstreamHandleFromProxyOf, readProxyDeclarations, type FederationNetwork, type FederationBridgeEntry, type BridgeRelabeller, type BridgeConsentModel, type BridgeDerivation, type BridgedActorField, type DeriveNetworkIdentity, type NetworkIdentity, type NetworkIdentityCandidate, type ProxyDeclaration, } from './networkIdentity';
|
|
@@ -254,8 +254,16 @@ export interface DeliveryService {
|
|
|
254
254
|
deliverToFollowers(activity: Record<string, unknown>, senderOxyUserId: string, senderUsername: string, options?: {
|
|
255
255
|
extraInboxes?: string[];
|
|
256
256
|
}): Promise<void>;
|
|
257
|
-
/**
|
|
258
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Send a Follow activity to a remote actor (records the outbound follow, delivers/queues).
|
|
259
|
+
* By default the delivery runs in the background, so a request never waits on
|
|
260
|
+
* the remote. `durable` hands it to the delivery queue BEFORE resolving
|
|
261
|
+
* (resolving the actor's inbox first, and throwing when it has none), for a
|
|
262
|
+
* caller that may exit right after — a one-shot script.
|
|
263
|
+
*/
|
|
264
|
+
sendFollow(localOxyUserId: string, localUsername: string, remoteActorUri: string, options?: {
|
|
265
|
+
durable?: boolean;
|
|
266
|
+
}): Promise<{
|
|
259
267
|
success: boolean;
|
|
260
268
|
pending: boolean;
|
|
261
269
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/federation",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Oxy Federation — the app-agnostic ActivityPub identity + follow engine substrate: the network-connector contract, normalized cross-network DTOs, HTTP signatures, actor resolution, the outbound delivery transport + follow lifecycle, the inbound dispatcher, and the webfinger/actor/inbox Express routers. Domain-parameterized so every Oxy app backend federates under its own domain.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -29,6 +29,17 @@
|
|
|
29
29
|
},
|
|
30
30
|
"default": "./dist/esm/index.js"
|
|
31
31
|
},
|
|
32
|
+
"./network": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/types/network.d.ts",
|
|
35
|
+
"default": "./dist/esm/network.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/types/network.d.ts",
|
|
39
|
+
"default": "./dist/cjs/network.js"
|
|
40
|
+
},
|
|
41
|
+
"default": "./dist/esm/network.js"
|
|
42
|
+
},
|
|
32
43
|
"./node": {
|
|
33
44
|
"import": {
|
|
34
45
|
"types": "./dist/types/node/index.d.ts",
|
|
@@ -152,6 +152,7 @@ function makeRig(
|
|
|
152
152
|
|
|
153
153
|
return {
|
|
154
154
|
service: createDeliveryService(config),
|
|
155
|
+
config,
|
|
155
156
|
signatures,
|
|
156
157
|
deliveredBodies,
|
|
157
158
|
enqueued,
|
|
@@ -213,6 +214,32 @@ describe('sendFollow', () => {
|
|
|
213
214
|
);
|
|
214
215
|
});
|
|
215
216
|
|
|
217
|
+
it('durable: queues the Follow before resolving, resolving an uncached inbox first', async () => {
|
|
218
|
+
const remote = 'https://remote.example/users/carol';
|
|
219
|
+
const rig = makeRig();
|
|
220
|
+
const fetched = { _id: 'CAROL', uri: remote, inboxUrl: 'https://remote.example/inbox' };
|
|
221
|
+
const service = createDeliveryService({
|
|
222
|
+
...rig.config,
|
|
223
|
+
actorRefresh: { ...rig.config.actorRefresh, fetchRemoteActor: async () => fetched },
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(await service.sendFollow('u-alice', 'alice', remote, { durable: true })).toEqual({
|
|
227
|
+
success: true,
|
|
228
|
+
pending: false,
|
|
229
|
+
});
|
|
230
|
+
// Nothing left to the background: the job is queued when the call returns.
|
|
231
|
+
expect(rig.enqueued).toEqual([
|
|
232
|
+
expect.objectContaining({ targetInbox: 'https://remote.example/inbox' }),
|
|
233
|
+
]);
|
|
234
|
+
expect(rig.upsertedFollows).toHaveLength(1);
|
|
235
|
+
await expect(
|
|
236
|
+
createDeliveryService({
|
|
237
|
+
...rig.config,
|
|
238
|
+
actorRefresh: { ...rig.config.actorRefresh, fetchRemoteActor: async () => null },
|
|
239
|
+
}).sendFollow('u-alice', 'alice', 'https://remote.example/users/nobody', { durable: true }),
|
|
240
|
+
).rejects.toThrow();
|
|
241
|
+
});
|
|
242
|
+
|
|
216
243
|
it('short-circuits when federation is disabled', async () => {
|
|
217
244
|
const rig = makeRig({ federationEnabled: false });
|
|
218
245
|
const result = await rig.service.sendFollow(
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { builtinModules } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
/** Every specifier the module at `file` imports, following relative imports. */
|
|
6
|
+
function importGraph(file: string, seen = new Set<string>()): string[] {
|
|
7
|
+
if (seen.has(file)) return [];
|
|
8
|
+
seen.add(file);
|
|
9
|
+
const source = readFileSync(file, 'utf8');
|
|
10
|
+
const specifiers = [...source.matchAll(/^(?:import|export)[^'"]*from\s+'([^']+)'/gm)].map(
|
|
11
|
+
(match) => match[1],
|
|
12
|
+
);
|
|
13
|
+
return specifiers.flatMap((specifier) =>
|
|
14
|
+
specifier.startsWith('.')
|
|
15
|
+
? importGraph(join(file, '..', `${specifier}.ts`), seen)
|
|
16
|
+
: [specifier],
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('@oxy.so/federation/network', () => {
|
|
21
|
+
it('imports nothing from Node, so a web or React Native bundle can use it', () => {
|
|
22
|
+
const external = importGraph(join(__dirname, '..', 'network.ts'));
|
|
23
|
+
const node = new Set([...builtinModules, ...builtinModules.map((name) => `node:${name}`)]);
|
|
24
|
+
expect(external.filter((specifier) => node.has(specifier))).toEqual([]);
|
|
25
|
+
});
|
|
26
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -51,46 +51,8 @@ export {
|
|
|
51
51
|
type UrlBuilders,
|
|
52
52
|
} from './urls';
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* bridge onto the network it actually came from, plus the network vocabulary and
|
|
57
|
-
* the bidirectional upstream-profile-URL rule.
|
|
58
|
-
*
|
|
59
|
-
* The mechanism is here; the ENTRIES are not, and must not be. Which operators
|
|
60
|
-
* may be trusted to re-attribute somebody's account is a moderation judgement an
|
|
61
|
-
* app commits and answers for — `createBridgeRelabeller` takes them as a
|
|
62
|
-
* parameter so no app inherits another's.
|
|
63
|
-
*/
|
|
64
|
-
export {
|
|
65
|
-
FEDERATION_NETWORKS,
|
|
66
|
-
BSKY_NETWORK_DOMAIN,
|
|
67
|
-
blueskyUsernameFromHandle,
|
|
68
|
-
blueskyHandleFromUsername,
|
|
69
|
-
UNRESOLVED_ATPROTO_HANDLE,
|
|
70
|
-
isUnresolvedAtprotoHandle,
|
|
71
|
-
atprotoIdentityHandle,
|
|
72
|
-
createBridgeRelabeller,
|
|
73
|
-
stripBridgeBoilerplate,
|
|
74
|
-
upstreamProfileUrl,
|
|
75
|
-
parseUpstreamProfileUrl,
|
|
76
|
-
federatedUsernameFromUpstreamUrl,
|
|
77
|
-
upstreamHandleFromProfileField,
|
|
78
|
-
upstreamHandleFromAlsoKnownAs,
|
|
79
|
-
upstreamHandleFromAutomatedActor,
|
|
80
|
-
upstreamHandleFromPreferredUsername,
|
|
81
|
-
upstreamHandleFromProxyOf,
|
|
82
|
-
readProxyDeclarations,
|
|
83
|
-
type FederationNetwork,
|
|
84
|
-
type FederationBridgeEntry,
|
|
85
|
-
type BridgeRelabeller,
|
|
86
|
-
type BridgeConsentModel,
|
|
87
|
-
type BridgeDerivation,
|
|
88
|
-
type BridgedActorField,
|
|
89
|
-
type DeriveNetworkIdentity,
|
|
90
|
-
type NetworkIdentity,
|
|
91
|
-
type NetworkIdentityCandidate,
|
|
92
|
-
type ProxyDeclaration,
|
|
93
|
-
} from './networkIdentity';
|
|
54
|
+
/** Network identity — see `./network`, the Node-free entry it is also served from. */
|
|
55
|
+
export * from './network';
|
|
94
56
|
|
|
95
57
|
/**
|
|
96
58
|
* The shared JSON-LD `@context` (load-bearing term declarations) and the
|
package/src/network.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@oxy.so/federation/network` — the network vocabulary and the network-identity
|
|
3
|
+
* rules, with nothing that needs Node.
|
|
4
|
+
*
|
|
5
|
+
* The package root also exports HTTP signatures, which import `node:crypto`, so a
|
|
6
|
+
* web or React Native bundle cannot import the root. A client that has to
|
|
7
|
+
* recognise an upstream profile URL the same way the server does (a composer
|
|
8
|
+
* deciding which links become mentions) imports this entry instead, and reads
|
|
9
|
+
* the same declaration rather than a copy of it. Everything here is also exported
|
|
10
|
+
* from the root.
|
|
11
|
+
*/
|
|
12
|
+
/*
|
|
13
|
+
* Network identity: the MECHANISM for re-labelling an account republished by a
|
|
14
|
+
* bridge onto the network it actually came from, plus the network vocabulary and
|
|
15
|
+
* the bidirectional upstream-profile-URL rule.
|
|
16
|
+
*
|
|
17
|
+
* The mechanism is here; the ENTRIES are not, and must not be. Which operators
|
|
18
|
+
* may be trusted to re-attribute somebody's account is a moderation judgement an
|
|
19
|
+
* app commits and answers for — `createBridgeRelabeller` takes them as a
|
|
20
|
+
* parameter so no app inherits another's.
|
|
21
|
+
*/
|
|
22
|
+
export {
|
|
23
|
+
FEDERATION_NETWORKS,
|
|
24
|
+
BSKY_NETWORK_DOMAIN,
|
|
25
|
+
blueskyUsernameFromHandle,
|
|
26
|
+
blueskyHandleFromUsername,
|
|
27
|
+
UNRESOLVED_ATPROTO_HANDLE,
|
|
28
|
+
isUnresolvedAtprotoHandle,
|
|
29
|
+
atprotoIdentityHandle,
|
|
30
|
+
createBridgeRelabeller,
|
|
31
|
+
stripBridgeBoilerplate,
|
|
32
|
+
upstreamProfileUrl,
|
|
33
|
+
parseUpstreamProfileUrl,
|
|
34
|
+
federatedUsernameFromUpstreamUrl,
|
|
35
|
+
upstreamHandleFromProfileField,
|
|
36
|
+
upstreamHandleFromAlsoKnownAs,
|
|
37
|
+
upstreamHandleFromAutomatedActor,
|
|
38
|
+
upstreamHandleFromPreferredUsername,
|
|
39
|
+
upstreamHandleFromProxyOf,
|
|
40
|
+
readProxyDeclarations,
|
|
41
|
+
type FederationNetwork,
|
|
42
|
+
type FederationBridgeEntry,
|
|
43
|
+
type BridgeRelabeller,
|
|
44
|
+
type BridgeConsentModel,
|
|
45
|
+
type BridgeDerivation,
|
|
46
|
+
type BridgedActorField,
|
|
47
|
+
type DeriveNetworkIdentity,
|
|
48
|
+
type NetworkIdentity,
|
|
49
|
+
type NetworkIdentityCandidate,
|
|
50
|
+
type ProxyDeclaration,
|
|
51
|
+
} from './networkIdentity';
|
package/src/node/delivery.ts
CHANGED
|
@@ -330,11 +330,18 @@ export interface DeliveryService {
|
|
|
330
330
|
senderUsername: string,
|
|
331
331
|
options?: { extraInboxes?: string[] },
|
|
332
332
|
): Promise<void>;
|
|
333
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* Send a Follow activity to a remote actor (records the outbound follow, delivers/queues).
|
|
335
|
+
* By default the delivery runs in the background, so a request never waits on
|
|
336
|
+
* the remote. `durable` hands it to the delivery queue BEFORE resolving
|
|
337
|
+
* (resolving the actor's inbox first, and throwing when it has none), for a
|
|
338
|
+
* caller that may exit right after — a one-shot script.
|
|
339
|
+
*/
|
|
334
340
|
sendFollow(
|
|
335
341
|
localOxyUserId: string,
|
|
336
342
|
localUsername: string,
|
|
337
343
|
remoteActorUri: string,
|
|
344
|
+
options?: { durable?: boolean },
|
|
338
345
|
): Promise<{ success: boolean; pending: boolean }>;
|
|
339
346
|
/**
|
|
340
347
|
* Remove the local follow and attempt Undo delivery. True means the local
|
|
@@ -619,6 +626,7 @@ export function createDeliveryService<TActor extends DeliveryActorFields>(
|
|
|
619
626
|
localOxyUserId: string,
|
|
620
627
|
localUsername: string,
|
|
621
628
|
remoteActorUri: string,
|
|
629
|
+
options: { durable?: boolean } = {},
|
|
622
630
|
): Promise<{ success: boolean; pending: boolean }> {
|
|
623
631
|
if (!config.federationEnabled) return { success: false, pending: false };
|
|
624
632
|
if (isBlockedUrl(remoteActorUri)) {
|
|
@@ -648,6 +656,24 @@ export function createDeliveryService<TActor extends DeliveryActorFields>(
|
|
|
648
656
|
|
|
649
657
|
// Refuse before committing an outbound follow or reporting success.
|
|
650
658
|
await authorizeDelivery(activity, localOxyUserId);
|
|
659
|
+
|
|
660
|
+
if (options.durable) {
|
|
661
|
+
// The caller may exit as soon as this resolves, so nothing is left to the
|
|
662
|
+
// background: the inbox is resolved now, and the Follow is in the delivery
|
|
663
|
+
// queue (whose worker retries it) before the follow is reported.
|
|
664
|
+
const actor =
|
|
665
|
+
cached?.sharedInboxUrl || cached?.inboxUrl
|
|
666
|
+
? cached
|
|
667
|
+
: await config.actorRefresh.fetchRemoteActor(remoteActorUri);
|
|
668
|
+
const inbox = actor?.sharedInboxUrl ?? actor?.inboxUrl;
|
|
669
|
+
if (!inbox || isBlockedUrl(inbox)) {
|
|
670
|
+
throw new Error(`No inbox to deliver the Follow to ${remoteActorUri}`);
|
|
671
|
+
}
|
|
672
|
+
await config.follows.upsertOutboundPending(localOxyUserId, canonicalUri, activityId);
|
|
673
|
+
await queueDelivery(activity, inbox, localOxyUserId);
|
|
674
|
+
return { success: true, pending: actor?.manuallyApprovesFollowers ?? false };
|
|
675
|
+
}
|
|
676
|
+
|
|
651
677
|
// A refused follow must not start remote actor discovery either.
|
|
652
678
|
config.actorRefresh.refreshActorInBackground(remoteActorUri, cached ?? undefined);
|
|
653
679
|
await config.follows.upsertOutboundPending(localOxyUserId, canonicalUri, activityId);
|