@fedify/relay 2.1.0 → 2.1.2

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 CHANGED
@@ -1,33 +1,8 @@
1
-
2
- const { Temporal } = require("@js-temporal/polyfill");
3
-
4
- //#region rolldown:runtime
5
- var __create = Object.create;
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, __fedify_fedify.createFederationBuilder)();
23
+ const relayBuilder = (0, _fedify_fedify.createFederationBuilder)();
50
24
  relayBuilder.setActorDispatcher("/users/{identifier}", async (ctx, identifier) => {
51
- if (identifier !== RELAY_SERVER_ACTOR) return null;
25
+ if (identifier !== "relay") return null;
52
26
  const keys = await ctx.getActorKeyPairs(identifier);
53
- return new __fedify_vocab.Application({
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 !== RELAY_SERVER_ACTOR) return [];
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$1 = await (0, __fedify_fedify.generateCryptoKeyPair)("RSASSA-PKCS1-v1_5");
78
- const ed25519Pair$1 = await (0, __fedify_fedify.generateCryptoKeyPair)("Ed25519");
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, __fedify_fedify.exportJwk)(rsaPair$1.privateKey),
85
- publicKey: await (0, __fedify_fedify.exportJwk)(rsaPair$1.publicKey)
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, __fedify_fedify.exportJwk)(ed25519Pair$1.privateKey),
93
- publicKey: await (0, __fedify_fedify.exportJwk)(ed25519Pair$1.publicKey)
66
+ privateKey: await (0, _fedify_fedify.exportJwk)(ed25519Pair.privateKey),
67
+ publicKey: await (0, _fedify_fedify.exportJwk)(ed25519Pair.publicKey)
94
68
  });
95
- return [rsaPair$1, ed25519Pair$1];
69
+ return [rsaPair, ed25519Pair];
96
70
  }
97
- const rsaPair = {
98
- privateKey: await (0, __fedify_fedify.importJwk)(rsaPairJson.privateKey, "private"),
99
- publicKey: await (0, __fedify_fedify.importJwk)(rsaPairJson.publicKey, "public")
100
- };
101
- const ed25519Pair = {
102
- privateKey: await (0, __fedify_fedify.importJwk)(ed25519PairJson.privateKey, "private"),
103
- publicKey: await (0, __fedify_fedify.importJwk)(ed25519PairJson.publicKey, "public")
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 __fedify_vocab.Object.fromJsonLd(value.actor);
113
- if (!(0, __fedify_vocab.isActor)(actor)) continue;
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 !== RELAY_SERVER_ACTOR) return null;
120
- const actors = await getFollowerActors(ctx);
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$1) {
108
+ constructor(options, relayBuilder) {
139
109
  this.options = options;
140
- this.federationBuilder = relayBuilder$1;
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 __fedify_vocab.Object.fromJsonLd(data.actor);
157
- if (!(0, __fedify_vocab.isActor)(actor)) return null;
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
- const context = (await this.#getFederation()).createContext(new URL(this.options.origin), this.options);
238
- return context;
207
+ return (await this.#getFederation()).createContext(new URL(this.options.origin), this.options);
239
208
  }
240
209
  async getActorUri() {
241
- const context = await this.#createContext();
242
- return context.getActorUri(RELAY_SERVER_ACTOR);
210
+ return (await this.#createContext()).getActorUri(RELAY_SERVER_ACTOR);
243
211
  }
244
212
  async getSharedInboxUri() {
245
- const context = await this.#createContext();
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
- const isPublicFollow = follow.objectId.href === "https://www.w3.org/ns/activitystreams#Public";
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 ? __fedify_vocab.Accept : __fedify_vocab.Reject;
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$2) {
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 __fedify_vocab.Follow) {
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$2.warn("Unsupported object type ({type}) for Undo activity: {object}", {
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, __logtape_logtape.getLogger)([
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 __fedify_vocab.Announce({
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: __fedify_vocab.PUBLIC_COLLECTION,
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(__fedify_vocab.Follow, async (ctx, follow) => {
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
- const existingFollow = await ctx.data.kv.get(["follower", follower.id.href]);
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 __fedify_vocab.Follow({
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(__fedify_vocab.Accept, async (ctx, accept) => {
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 __fedify_vocab.Follow)) return;
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, __fedify_vocab.isActor)(followerActor) || !followerActor.id) return;
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(__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));
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, __logtape_logtape.getLogger)([
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(__fedify_vocab.Follow, async (ctx, follow) => {
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(__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));
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,117 @@
1
1
  import { Context, KvStore, MessageQueue } from "@fedify/fedify";
2
2
  import { Actor } from "@fedify/vocab";
3
- import { AuthenticatedDocumentLoaderFactory, DocumentLoaderFactory } from "@fedify/vocab-runtime";
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
+ /**
92
+ * A factory function that creates an authenticated {@link DocumentLoader} for
93
+ * a given identity. This is used for fetching documents that require
94
+ * authentication.
95
+ * @param identity The identity to create the document loader for.
96
+ * The actor's key pair.
97
+ * @param options The options for the document loader.
98
+ * @returns The authenticated document loader.
99
+ * @since 0.4.0
100
+ */
101
+ type AuthenticatedDocumentLoaderFactory = (identity: {
102
+ keyId: URL;
103
+ privateKey: CryptoKey;
104
+ }, options?: DocumentLoaderFactoryOptions) => DocumentLoader;
105
+ /**
106
+ * Gets a {@link RemoteDocument} from the given response.
107
+ * @param url The URL of the document to load.
108
+ * @param response The response to get the document from.
109
+ * @param fetch The function to fetch the document.
110
+ * @returns The loaded remote document.
111
+ * @throws {FetchError} If the response is not OK.
112
+ * @internal
113
+ */
114
+ //#endregion
5
115
  //#region src/types.d.ts
6
116
  declare const RELAY_SERVER_ACTOR = "relay";
7
117
  /**
@@ -53,14 +163,6 @@ interface RelayOptions {
53
163
  */
54
164
  subscriptionHandler: SubscriptionRequestHandler;
55
165
  }
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
166
  /**
65
167
  * A follower of the relay with validated Actor instance.
66
168
  * This is the public API type returned by follower query methods.
@@ -115,14 +217,6 @@ interface Relay {
115
217
  */
116
218
  getSharedInboxUri(): Promise<URL>;
117
219
  }
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
220
  //#endregion
127
221
  //#region src/factory.d.ts
128
222
  /**
@@ -148,4 +242,4 @@ interface Relay {
148
242
  */
149
243
  declare function createRelay(type: RelayType, options: RelayOptions): Relay;
150
244
  //#endregion
151
- export { RELAY_SERVER_ACTOR, Relay, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay };
245
+ export { RELAY_SERVER_ACTOR, type Relay, type RelayFollower, type RelayOptions, type RelayType, type SubscriptionRequestHandler, createRelay };
package/dist/mod.d.ts CHANGED
@@ -1,8 +1,118 @@
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
- import { AuthenticatedDocumentLoaderFactory, DocumentLoaderFactory } from "@fedify/vocab-runtime";
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
+ /**
93
+ * A factory function that creates an authenticated {@link DocumentLoader} for
94
+ * a given identity. This is used for fetching documents that require
95
+ * authentication.
96
+ * @param identity The identity to create the document loader for.
97
+ * The actor's key pair.
98
+ * @param options The options for the document loader.
99
+ * @returns The authenticated document loader.
100
+ * @since 0.4.0
101
+ */
102
+ type AuthenticatedDocumentLoaderFactory = (identity: {
103
+ keyId: URL;
104
+ privateKey: CryptoKey;
105
+ }, options?: DocumentLoaderFactoryOptions) => DocumentLoader;
106
+ /**
107
+ * Gets a {@link RemoteDocument} from the given response.
108
+ * @param url The URL of the document to load.
109
+ * @param response The response to get the document from.
110
+ * @param fetch The function to fetch the document.
111
+ * @returns The loaded remote document.
112
+ * @throws {FetchError} If the response is not OK.
113
+ * @internal
114
+ */
115
+ //#endregion
6
116
  //#region src/types.d.ts
7
117
  declare const RELAY_SERVER_ACTOR = "relay";
8
118
  /**
@@ -54,14 +164,6 @@ interface RelayOptions {
54
164
  */
55
165
  subscriptionHandler: SubscriptionRequestHandler;
56
166
  }
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
167
  /**
66
168
  * A follower of the relay with validated Actor instance.
67
169
  * This is the public API type returned by follower query methods.
@@ -116,14 +218,6 @@ interface Relay {
116
218
  */
117
219
  getSharedInboxUri(): Promise<URL>;
118
220
  }
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
221
  //#endregion
128
222
  //#region src/factory.d.ts
129
223
  /**
@@ -149,4 +243,4 @@ interface Relay {
149
243
  */
150
244
  declare function createRelay(type: RelayType, options: RelayOptions): Relay;
151
245
  //#endregion
152
- export { RELAY_SERVER_ACTOR, Relay, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay };
246
+ export { RELAY_SERVER_ACTOR, type Relay, type RelayFollower, type RelayOptions, type RelayType, type SubscriptionRequestHandler, createRelay };