@oxy.so/federation 3.0.0 → 3.1.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.
|
@@ -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);
|
|
@@ -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);
|
|
@@ -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.1.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",
|
|
@@ -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(
|
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);
|