@oxy.so/federation 2.6.0 → 2.7.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.
@@ -353,27 +353,28 @@ function createDeliveryService(config) {
353
353
  }
354
354
  return true;
355
355
  }
356
- async function sendAccept(localOxyUserId, localUsername, followActivityId, remoteActorUri) {
356
+ /** Answer a remote Follow: `Accept` or `Reject`, one envelope for both. */
357
+ async function sendFollowResponse(type, localOxyUserId, localUsername, followActivityId, remoteActorUri) {
357
358
  const actor = await config.store.findActorByUri(remoteActorUri);
358
359
  if (!actor)
359
360
  return;
360
361
  // `inboxUrl` is schema-optional (atproto actors have none); an AP actor we
361
- // are sending Accept(Follow) to always has one. When neither inbox is known the
362
- // local follow is already removed — just skip the outbound delivery.
362
+ // are answering always has one. When neither inbox is known, skip the
363
+ // outbound delivery.
363
364
  const targetInbox = actor.sharedInboxUrl ?? actor.inboxUrl;
364
365
  if (!targetInbox) {
365
- logger.warn(`[FedSync] cannot send Accept(Follow) to ${remoteActorUri}: actor has no inbox`);
366
+ logger.warn(`[FedSync] cannot send ${type}(Follow) to ${remoteActorUri}: actor has no inbox`);
366
367
  return;
367
368
  }
368
369
  if (isBlockedUrl(targetInbox) || isBlockedUrl(remoteActorUri)) {
369
- logger.warn(`[FedDeliver] refusing Accept(Follow) delivery to blocked origin ${remoteActorUri}`);
370
+ logger.warn(`[FedDeliver] refusing ${type}(Follow) delivery to blocked origin ${remoteActorUri}`);
370
371
  return;
371
372
  }
372
373
  const localActorUri = urls.actor(localUsername);
373
374
  const activity = {
374
375
  '@context': apContext_1.AP_CONTEXT,
375
- id: `${localActorUri}/accepts/${Date.now()}`,
376
- type: 'Accept',
376
+ id: `${localActorUri}/${type === 'Accept' ? 'accepts' : 'rejects'}/${Date.now()}`,
377
+ type,
377
378
  actor: localActorUri,
378
379
  object: {
379
380
  id: followActivityId,
@@ -387,6 +388,12 @@ function createDeliveryService(config) {
387
388
  await queueDelivery(activity, targetInbox, localOxyUserId);
388
389
  }
389
390
  }
391
+ function sendAccept(localOxyUserId, localUsername, followActivityId, remoteActorUri) {
392
+ return sendFollowResponse('Accept', localOxyUserId, localUsername, followActivityId, remoteActorUri);
393
+ }
394
+ function sendReject(localOxyUserId, localUsername, followActivityId, remoteActorUri) {
395
+ return sendFollowResponse('Reject', localOxyUserId, localUsername, followActivityId, remoteActorUri);
396
+ }
390
397
  async function federateActorUpdate(actorOxyUserId, username) {
391
398
  if (!config.federationEnabled)
392
399
  return;
@@ -440,6 +447,7 @@ function createDeliveryService(config) {
440
447
  sendFollow,
441
448
  sendUndoFollow,
442
449
  sendAccept,
450
+ sendReject,
443
451
  federateActorUpdate,
444
452
  };
445
453
  }
@@ -150,6 +150,14 @@ function createInboundDispatcher(config) {
150
150
  logger.debug(`[Federation] ignoring self-follow from ${actorUri} to ${username}`);
151
151
  return;
152
152
  }
153
+ if (config.refusesFollower && (await config.refusesFollower(localUserId, followerOxyUserId))) {
154
+ if (!config.delivery.sendReject) {
155
+ throw new Error('refusesFollower is wired without delivery.sendReject');
156
+ }
157
+ await config.delivery.sendReject(localUserId, username, String(activity.id), actorUri);
158
+ logger.info(`Rejected follow from ${actorUri} to ${username}`);
159
+ return;
160
+ }
153
161
  // Create the Oxy follow edge BEFORE sending Accept so a retry never spams
154
162
  // Accepts: the bridge is idempotent (safe to re-run), but an Accept delivered
155
163
  // before the edge was committed could be re-sent on every retry. On failure
@@ -348,27 +348,28 @@ export function createDeliveryService(config) {
348
348
  }
349
349
  return true;
350
350
  }
351
- async function sendAccept(localOxyUserId, localUsername, followActivityId, remoteActorUri) {
351
+ /** Answer a remote Follow: `Accept` or `Reject`, one envelope for both. */
352
+ async function sendFollowResponse(type, localOxyUserId, localUsername, followActivityId, remoteActorUri) {
352
353
  const actor = await config.store.findActorByUri(remoteActorUri);
353
354
  if (!actor)
354
355
  return;
355
356
  // `inboxUrl` is schema-optional (atproto actors have none); an AP actor we
356
- // are sending Accept(Follow) to always has one. When neither inbox is known the
357
- // local follow is already removed — just skip the outbound delivery.
357
+ // are answering always has one. When neither inbox is known, skip the
358
+ // outbound delivery.
358
359
  const targetInbox = actor.sharedInboxUrl ?? actor.inboxUrl;
359
360
  if (!targetInbox) {
360
- logger.warn(`[FedSync] cannot send Accept(Follow) to ${remoteActorUri}: actor has no inbox`);
361
+ logger.warn(`[FedSync] cannot send ${type}(Follow) to ${remoteActorUri}: actor has no inbox`);
361
362
  return;
362
363
  }
363
364
  if (isBlockedUrl(targetInbox) || isBlockedUrl(remoteActorUri)) {
364
- logger.warn(`[FedDeliver] refusing Accept(Follow) delivery to blocked origin ${remoteActorUri}`);
365
+ logger.warn(`[FedDeliver] refusing ${type}(Follow) delivery to blocked origin ${remoteActorUri}`);
365
366
  return;
366
367
  }
367
368
  const localActorUri = urls.actor(localUsername);
368
369
  const activity = {
369
370
  '@context': AP_CONTEXT,
370
- id: `${localActorUri}/accepts/${Date.now()}`,
371
- type: 'Accept',
371
+ id: `${localActorUri}/${type === 'Accept' ? 'accepts' : 'rejects'}/${Date.now()}`,
372
+ type,
372
373
  actor: localActorUri,
373
374
  object: {
374
375
  id: followActivityId,
@@ -382,6 +383,12 @@ export function createDeliveryService(config) {
382
383
  await queueDelivery(activity, targetInbox, localOxyUserId);
383
384
  }
384
385
  }
386
+ function sendAccept(localOxyUserId, localUsername, followActivityId, remoteActorUri) {
387
+ return sendFollowResponse('Accept', localOxyUserId, localUsername, followActivityId, remoteActorUri);
388
+ }
389
+ function sendReject(localOxyUserId, localUsername, followActivityId, remoteActorUri) {
390
+ return sendFollowResponse('Reject', localOxyUserId, localUsername, followActivityId, remoteActorUri);
391
+ }
385
392
  async function federateActorUpdate(actorOxyUserId, username) {
386
393
  if (!config.federationEnabled)
387
394
  return;
@@ -435,6 +442,7 @@ export function createDeliveryService(config) {
435
442
  sendFollow,
436
443
  sendUndoFollow,
437
444
  sendAccept,
445
+ sendReject,
438
446
  federateActorUpdate,
439
447
  };
440
448
  }
@@ -145,6 +145,14 @@ export function createInboundDispatcher(config) {
145
145
  logger.debug(`[Federation] ignoring self-follow from ${actorUri} to ${username}`);
146
146
  return;
147
147
  }
148
+ if (config.refusesFollower && (await config.refusesFollower(localUserId, followerOxyUserId))) {
149
+ if (!config.delivery.sendReject) {
150
+ throw new Error('refusesFollower is wired without delivery.sendReject');
151
+ }
152
+ await config.delivery.sendReject(localUserId, username, String(activity.id), actorUri);
153
+ logger.info(`Rejected follow from ${actorUri} to ${username}`);
154
+ return;
155
+ }
148
156
  // Create the Oxy follow edge BEFORE sending Accept so a retry never spams
149
157
  // Accepts: the bridge is idempotent (safe to re-run), but an Accept delivered
150
158
  // before the edge was committed could be re-sent on every retry. On failure
@@ -266,6 +266,8 @@ export interface DeliveryService {
266
266
  sendUndoFollow(localOxyUserId: string, localUsername: string, remoteActorUri: string): Promise<boolean>;
267
267
  /** Send an Accept(Follow) back to a remote actor. */
268
268
  sendAccept(localOxyUserId: string, localUsername: string, followActivityId: string, remoteActorUri: string): Promise<void>;
269
+ /** Send a Reject(Follow) back to a remote actor — the same envelope as the Accept. */
270
+ sendReject(localOxyUserId: string, localUsername: string, followActivityId: string, remoteActorUri: string): Promise<void>;
269
271
  /** Rebroadcast the FULL actor document as an Update(Person) to remote followers. */
270
272
  federateActorUpdate(actorOxyUserId: string, username: string): Promise<void>;
271
273
  }
@@ -108,6 +108,8 @@ export interface InboundFollowStore {
108
108
  /** The delivery subset the inbound Follow uses (send the Accept back). */
109
109
  export interface InboundDelivery {
110
110
  sendAccept(localOxyUserId: string, localUsername: string, followActivityId: string, remoteActorUri: string): Promise<void>;
111
+ /** Send a Reject(Follow) back — required when {@link InboundDispatcherConfig.refusesFollower} is wired. */
112
+ sendReject?(localOxyUserId: string, localUsername: string, followActivityId: string, remoteActorUri: string): Promise<void>;
111
113
  }
112
114
  /** Adapters + hooks an {@link InboundDispatcher} is built from. */
113
115
  export interface InboundDispatcherConfig {
@@ -132,8 +134,16 @@ export interface InboundDispatcherConfig {
132
134
  actorResolver: InboundActorResolver;
133
135
  /** The AP follow-record store. */
134
136
  follows: InboundFollowStore;
135
- /** The delivery service (send the Accept). */
137
+ /** The delivery service (send the Accept, or the Reject). */
136
138
  delivery: InboundDelivery;
139
+ /**
140
+ * Whether the local account REFUSES this follower — a community that banned
141
+ * them. A refused Follow is answered with a `Reject` (the account exists and is
142
+ * public, so saying no reveals nothing), and no edge or follow row is written.
143
+ * Asked after the follower resolves, so the app answers by Oxy id. Absent ⇒
144
+ * every Follow is accepted, as before.
145
+ */
146
+ refusesFollower?(localUserId: string, followerOxyUserId: string): Promise<boolean>;
137
147
  /**
138
148
  * Best-effort: notify the local user of a newly-accepted inbound follow.
139
149
  * NEVER throws (it handles its own errors); a failure must not fail (and thus
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/federation",
3
- "version": "2.6.0",
3
+ "version": "2.7.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",
@@ -31,11 +31,13 @@ function makeRig(
31
31
  validate?: (activity: Record<string, unknown>) => InboundActivityValidation;
32
32
  blockedHosts?: string[];
33
33
  withMoveHandler?: boolean;
34
+ refusedFollowers?: string[];
34
35
  } = {},
35
36
  ) {
36
37
  const moves: Array<{ activityId: string; oldActorUri: string; targetActorUri: string }> = [];
37
38
  const bridgeFollowCalls: Array<[string, string]> = [];
38
39
  const bridgeUnfollowCalls: Array<[string, string]> = [];
40
+ const rejectsSent: string[] = [];
39
41
  const acceptsSent: Array<{
40
42
  localOxyUserId: string;
41
43
  localUsername: string;
@@ -109,7 +111,16 @@ function makeRig(
109
111
  sendAccept: async (localOxyUserId, localUsername, followActivityId, remoteActorUri) => {
110
112
  acceptsSent.push({ localOxyUserId, localUsername, followActivityId, remoteActorUri });
111
113
  },
114
+ sendReject: async (_localOxyUserId, _localUsername, followActivityId) => {
115
+ rejectsSent.push(followActivityId);
116
+ },
112
117
  },
118
+ ...(overrides.refusedFollowers
119
+ ? {
120
+ refusesFollower: async (_localUserId: string, followerOxyUserId: string) =>
121
+ overrides.refusedFollowers?.includes(followerOxyUserId) ?? false,
122
+ }
123
+ : {}),
113
124
  onInboundFollowAccepted: async (localUserId, followerOxyUserId, actorUri) => {
114
125
  onInboundFollowAcceptedCalls.push([localUserId, followerOxyUserId, actorUri]);
115
126
  },
@@ -140,6 +151,7 @@ function makeRig(
140
151
  bridgeFollowCalls,
141
152
  bridgeUnfollowCalls,
142
153
  acceptsSent,
154
+ rejectsSent,
143
155
  inboundAcceptedUpserts,
144
156
  deletedFollowIds,
145
157
  contentActivities,
@@ -174,6 +186,18 @@ describe('inbound Follow', () => {
174
186
  expect(rig.onInboundFollowAcceptedCalls).toEqual([['u-alice', 'u-bob', REMOTE_ACTOR]]);
175
187
  });
176
188
 
189
+ it('answers a refused follower with Reject, writing nothing', async () => {
190
+ const rig = makeRig({ refusedFollowers: ['u-bob'] });
191
+ await rig.dispatcher.processInboxActivity(
192
+ { type: 'Follow', id: 'f9', actor: REMOTE_ACTOR, object: LOCAL_ACTOR },
193
+ REMOTE_ACTOR,
194
+ );
195
+ expect(rig.rejectsSent).toEqual(['f9']);
196
+ expect(rig.acceptsSent).toEqual([]);
197
+ expect(rig.bridgeFollowCalls).toEqual([]);
198
+ expect(rig.inboundAcceptedUpserts).toEqual([]);
199
+ });
200
+
177
201
  it('drops the Follow (no bridge/accept) when the target has sharing OFF', async () => {
178
202
  const rig = makeRig({ sharingEnabled: false });
179
203
  await rig.dispatcher.processInboxActivity(
@@ -351,6 +351,13 @@ export interface DeliveryService {
351
351
  followActivityId: string,
352
352
  remoteActorUri: string,
353
353
  ): Promise<void>;
354
+ /** Send a Reject(Follow) back to a remote actor — the same envelope as the Accept. */
355
+ sendReject(
356
+ localOxyUserId: string,
357
+ localUsername: string,
358
+ followActivityId: string,
359
+ remoteActorUri: string,
360
+ ): Promise<void>;
354
361
  /** Rebroadcast the FULL actor document as an Update(Person) to remote followers. */
355
362
  federateActorUpdate(actorOxyUserId: string, username: string): Promise<void>;
356
363
  }
@@ -716,7 +723,9 @@ export function createDeliveryService<TActor extends DeliveryActorFields>(
716
723
  return true;
717
724
  }
718
725
 
719
- async function sendAccept(
726
+ /** Answer a remote Follow: `Accept` or `Reject`, one envelope for both. */
727
+ async function sendFollowResponse(
728
+ type: 'Accept' | 'Reject',
720
729
  localOxyUserId: string,
721
730
  localUsername: string,
722
731
  followActivityId: string,
@@ -725,16 +734,16 @@ export function createDeliveryService<TActor extends DeliveryActorFields>(
725
734
  const actor = await config.store.findActorByUri(remoteActorUri);
726
735
  if (!actor) return;
727
736
  // `inboxUrl` is schema-optional (atproto actors have none); an AP actor we
728
- // are sending Accept(Follow) to always has one. When neither inbox is known the
729
- // local follow is already removed — just skip the outbound delivery.
737
+ // are answering always has one. When neither inbox is known, skip the
738
+ // outbound delivery.
730
739
  const targetInbox = actor.sharedInboxUrl ?? actor.inboxUrl;
731
740
  if (!targetInbox) {
732
- logger.warn(`[FedSync] cannot send Accept(Follow) to ${remoteActorUri}: actor has no inbox`);
741
+ logger.warn(`[FedSync] cannot send ${type}(Follow) to ${remoteActorUri}: actor has no inbox`);
733
742
  return;
734
743
  }
735
744
  if (isBlockedUrl(targetInbox) || isBlockedUrl(remoteActorUri)) {
736
745
  logger.warn(
737
- `[FedDeliver] refusing Accept(Follow) delivery to blocked origin ${remoteActorUri}`,
746
+ `[FedDeliver] refusing ${type}(Follow) delivery to blocked origin ${remoteActorUri}`,
738
747
  );
739
748
  return;
740
749
  }
@@ -743,8 +752,8 @@ export function createDeliveryService<TActor extends DeliveryActorFields>(
743
752
 
744
753
  const activity: Record<string, unknown> = {
745
754
  '@context': AP_CONTEXT,
746
- id: `${localActorUri}/accepts/${Date.now()}`,
747
- type: 'Accept',
755
+ id: `${localActorUri}/${type === 'Accept' ? 'accepts' : 'rejects'}/${Date.now()}`,
756
+ type,
748
757
  actor: localActorUri,
749
758
  object: {
750
759
  id: followActivityId,
@@ -760,6 +769,36 @@ export function createDeliveryService<TActor extends DeliveryActorFields>(
760
769
  }
761
770
  }
762
771
 
772
+ function sendAccept(
773
+ localOxyUserId: string,
774
+ localUsername: string,
775
+ followActivityId: string,
776
+ remoteActorUri: string,
777
+ ): Promise<void> {
778
+ return sendFollowResponse(
779
+ 'Accept',
780
+ localOxyUserId,
781
+ localUsername,
782
+ followActivityId,
783
+ remoteActorUri,
784
+ );
785
+ }
786
+
787
+ function sendReject(
788
+ localOxyUserId: string,
789
+ localUsername: string,
790
+ followActivityId: string,
791
+ remoteActorUri: string,
792
+ ): Promise<void> {
793
+ return sendFollowResponse(
794
+ 'Reject',
795
+ localOxyUserId,
796
+ localUsername,
797
+ followActivityId,
798
+ remoteActorUri,
799
+ );
800
+ }
801
+
763
802
  async function federateActorUpdate(actorOxyUserId: string, username: string): Promise<void> {
764
803
  if (!config.federationEnabled) return;
765
804
  if (!(await config.consent.isSharingEnabled(actorOxyUserId))) return;
@@ -819,6 +858,7 @@ export function createDeliveryService<TActor extends DeliveryActorFields>(
819
858
  sendFollow,
820
859
  sendUndoFollow,
821
860
  sendAccept,
861
+ sendReject,
822
862
  federateActorUpdate,
823
863
  };
824
864
  }
@@ -127,6 +127,13 @@ export interface InboundDelivery {
127
127
  followActivityId: string,
128
128
  remoteActorUri: string,
129
129
  ): Promise<void>;
130
+ /** Send a Reject(Follow) back — required when {@link InboundDispatcherConfig.refusesFollower} is wired. */
131
+ sendReject?(
132
+ localOxyUserId: string,
133
+ localUsername: string,
134
+ followActivityId: string,
135
+ remoteActorUri: string,
136
+ ): Promise<void>;
130
137
  }
131
138
 
132
139
  /** Adapters + hooks an {@link InboundDispatcher} is built from. */
@@ -152,8 +159,16 @@ export interface InboundDispatcherConfig {
152
159
  actorResolver: InboundActorResolver;
153
160
  /** The AP follow-record store. */
154
161
  follows: InboundFollowStore;
155
- /** The delivery service (send the Accept). */
162
+ /** The delivery service (send the Accept, or the Reject). */
156
163
  delivery: InboundDelivery;
164
+ /**
165
+ * Whether the local account REFUSES this follower — a community that banned
166
+ * them. A refused Follow is answered with a `Reject` (the account exists and is
167
+ * public, so saying no reveals nothing), and no edge or follow row is written.
168
+ * Asked after the follower resolves, so the app answers by Oxy id. Absent ⇒
169
+ * every Follow is accepted, as before.
170
+ */
171
+ refusesFollower?(localUserId: string, followerOxyUserId: string): Promise<boolean>;
157
172
  /**
158
173
  * Best-effort: notify the local user of a newly-accepted inbound follow.
159
174
  * NEVER throws (it handles its own errors); a failure must not fail (and thus
@@ -306,6 +321,15 @@ export function createInboundDispatcher(config: InboundDispatcherConfig): Inboun
306
321
  return;
307
322
  }
308
323
 
324
+ if (config.refusesFollower && (await config.refusesFollower(localUserId, followerOxyUserId))) {
325
+ if (!config.delivery.sendReject) {
326
+ throw new Error('refusesFollower is wired without delivery.sendReject');
327
+ }
328
+ await config.delivery.sendReject(localUserId, username, String(activity.id), actorUri);
329
+ logger.info(`Rejected follow from ${actorUri} to ${username}`);
330
+ return;
331
+ }
332
+
309
333
  // Create the Oxy follow edge BEFORE sending Accept so a retry never spams
310
334
  // Accepts: the bridge is idempotent (safe to re-run), but an Accept delivered
311
335
  // before the edge was committed could be re-sent on every retry. On failure