@fedify/relay 2.0.0-dev.1908 → 2.0.0-dev.196

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.d.cts CHANGED
@@ -1,59 +1,151 @@
1
- import { Context, Federation, KvStore, MessageQueue } from "@fedify/fedify";
2
- import { Actor } from "@fedify/fedify/vocab";
1
+ import { Context, KvStore, MessageQueue } from "@fedify/fedify";
2
+ import { Actor } from "@fedify/vocab";
3
3
  import { AuthenticatedDocumentLoaderFactory, DocumentLoaderFactory } from "@fedify/vocab-runtime";
4
4
 
5
- //#region src/relay.d.ts
6
-
5
+ //#region src/types.d.ts
6
+ declare const RELAY_SERVER_ACTOR = "relay";
7
+ /**
8
+ * Supported relay types.
9
+ */
10
+ type RelayType = "mastodon" | "litepub";
7
11
  /**
8
12
  * Handler for subscription requests (Follow/Undo activities).
9
13
  */
10
- type SubscriptionRequestHandler = (ctx: Context<void>, clientActor: Actor) => Promise<boolean>;
14
+ type SubscriptionRequestHandler = (ctx: Context<RelayOptions>, clientActor: Actor) => Promise<boolean>;
11
15
  /**
12
16
  * Configuration options for the ActivityPub relay.
13
17
  */
14
18
  interface RelayOptions {
19
+ /**
20
+ * Key-value store for persisting relay data such as follower information
21
+ * and cryptographic keys.
22
+ */
15
23
  kv: KvStore;
16
- domain?: string;
24
+ /**
25
+ * The origin URL where the relay is hosted.
26
+ * Must be a full URL including the protocol (e.g., `"https://relay.example.com"`).
27
+ */
28
+ origin: string;
29
+ /**
30
+ * Display name for the relay actor.
31
+ * Defaults to `"ActivityPub Relay"`.
32
+ */
33
+ name?: string;
34
+ /**
35
+ * Factory function for creating a document loader to fetch remote
36
+ * ActivityPub objects.
37
+ */
17
38
  documentLoaderFactory?: DocumentLoaderFactory;
39
+ /**
40
+ * Factory function for creating an authenticated document loader
41
+ * that signs HTTP requests when fetching remote objects.
42
+ */
18
43
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
19
- federation?: Federation<void>;
44
+ /**
45
+ * Message queue for background activity processing.
46
+ * Recommended for production to handle activity forwarding asynchronously.
47
+ */
20
48
  queue?: MessageQueue;
49
+ /**
50
+ * Handler function that determines whether to approve or reject
51
+ * subscription requests from remote actors.
52
+ * Return `true` to approve or `false` to reject.
53
+ */
54
+ subscriptionHandler: SubscriptionRequestHandler;
21
55
  }
22
56
  /**
23
- * Base interface for ActivityPub relay implementations.
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
24
62
  */
25
- interface Relay {
26
- readonly domain: string;
27
- fetch(request: Request): Promise<Response>;
28
- setSubscriptionHandler(handler: SubscriptionRequestHandler): this;
29
- }
63
+
30
64
  /**
31
- * A Mastodon-compatible ActivityPub relay implementation.
32
- * This relay follows Mastodon's relay protocol for maximum compatibility
33
- * with Mastodon instances.
65
+ * A follower of the relay with validated Actor instance.
66
+ * This is the public API type returned by follower query methods.
34
67
  *
35
68
  * @since 2.0.0
36
69
  */
37
- declare class MastodonRelay implements Relay {
38
- #private;
39
- constructor(options: RelayOptions);
40
- get domain(): string;
41
- fetch(request: Request): Promise<Response>;
42
- setSubscriptionHandler(handler: SubscriptionRequestHandler): this;
70
+ interface RelayFollower {
71
+ /** The actor ID (URL) of the follower. */
72
+ readonly actorId: string;
73
+ /** The validated Actor object. */
74
+ readonly actor: Actor;
75
+ /** The follower's state. */
76
+ readonly state: "pending" | "accepted";
43
77
  }
44
78
  /**
45
- * A LitePub-compatible ActivityPub relay implementation.
46
- * This relay follows LitePub's relay protocol and extensions for
47
- * enhanced federation capabilities.
79
+ * Public interface for ActivityPub relay implementations.
80
+ * Use {@link createRelay} to create a relay instance.
48
81
  *
49
82
  * @since 2.0.0
50
83
  */
51
- declare class LitePubRelay implements Relay {
52
- #private;
53
- constructor(options: RelayOptions);
54
- get domain(): string;
84
+ interface Relay {
85
+ /**
86
+ * Handle incoming HTTP requests.
87
+ *
88
+ * @param request The incoming HTTP request
89
+ * @returns The HTTP response
90
+ */
55
91
  fetch(request: Request): Promise<Response>;
56
- setSubscriptionHandler(handler: SubscriptionRequestHandler): this;
92
+ /**
93
+ * Lists all followers of the relay.
94
+ *
95
+ * @returns An async iterator of follower entries
96
+ */
97
+ listFollowers(): AsyncIterableIterator<RelayFollower>;
98
+ /**
99
+ * Gets a specific follower by actor ID.
100
+ *
101
+ * @param actorId The actor ID (URL) of the follower to retrieve
102
+ * @returns The follower entry if found, null otherwise
103
+ */
104
+ getFollower(actorId: string): Promise<RelayFollower | null>;
105
+ /**
106
+ * Gets the URI of the relay actor.
107
+ *
108
+ * @returns The URI of the relay actor
109
+ */
110
+ getActorUri(): Promise<URL>;
111
+ /**
112
+ * Gets the shared inbox URI of the relay.
113
+ *
114
+ * @returns The shared inbox URI
115
+ */
116
+ getSharedInboxUri(): Promise<URL>;
57
117
  }
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
+ //#endregion
127
+ //#region src/factory.d.ts
128
+ /**
129
+ * Factory function to create a relay instance.
130
+ *
131
+ * @param type The type of relay to create ("mastodon" or "litepub")
132
+ * @param options Configuration options for the relay
133
+ * @returns A relay instance
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { createRelay } from "@fedify/relay";
138
+ * import { MemoryKvStore } from "@fedify/fedify";
139
+ *
140
+ * const relay = createRelay("mastodon", {
141
+ * kv: new MemoryKvStore(),
142
+ * origin: "https://relay.example.com",
143
+ * subscriptionHandler: async (ctx, actor) => true,
144
+ * });
145
+ * ```
146
+ *
147
+ * @since 2.0.0
148
+ */
149
+ declare function createRelay(type: RelayType, options: RelayOptions): Relay;
58
150
  //#endregion
59
- export { LitePubRelay, MastodonRelay, Relay, RelayOptions };
151
+ export { RELAY_SERVER_ACTOR, Relay, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay };
package/dist/mod.d.ts CHANGED
@@ -1,59 +1,152 @@
1
- import { Context, Federation, KvStore, MessageQueue } from "@fedify/fedify";
2
- import { Actor } from "@fedify/fedify/vocab";
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { Context, KvStore, MessageQueue } from "@fedify/fedify";
3
+ import { Actor } from "@fedify/vocab";
3
4
  import { AuthenticatedDocumentLoaderFactory, DocumentLoaderFactory } from "@fedify/vocab-runtime";
4
5
 
5
- //#region src/relay.d.ts
6
-
6
+ //#region src/types.d.ts
7
+ declare const RELAY_SERVER_ACTOR = "relay";
8
+ /**
9
+ * Supported relay types.
10
+ */
11
+ type RelayType = "mastodon" | "litepub";
7
12
  /**
8
13
  * Handler for subscription requests (Follow/Undo activities).
9
14
  */
10
- type SubscriptionRequestHandler = (ctx: Context<void>, clientActor: Actor) => Promise<boolean>;
15
+ type SubscriptionRequestHandler = (ctx: Context<RelayOptions>, clientActor: Actor) => Promise<boolean>;
11
16
  /**
12
17
  * Configuration options for the ActivityPub relay.
13
18
  */
14
19
  interface RelayOptions {
20
+ /**
21
+ * Key-value store for persisting relay data such as follower information
22
+ * and cryptographic keys.
23
+ */
15
24
  kv: KvStore;
16
- domain?: string;
25
+ /**
26
+ * The origin URL where the relay is hosted.
27
+ * Must be a full URL including the protocol (e.g., `"https://relay.example.com"`).
28
+ */
29
+ origin: string;
30
+ /**
31
+ * Display name for the relay actor.
32
+ * Defaults to `"ActivityPub Relay"`.
33
+ */
34
+ name?: string;
35
+ /**
36
+ * Factory function for creating a document loader to fetch remote
37
+ * ActivityPub objects.
38
+ */
17
39
  documentLoaderFactory?: DocumentLoaderFactory;
40
+ /**
41
+ * Factory function for creating an authenticated document loader
42
+ * that signs HTTP requests when fetching remote objects.
43
+ */
18
44
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
19
- federation?: Federation<void>;
45
+ /**
46
+ * Message queue for background activity processing.
47
+ * Recommended for production to handle activity forwarding asynchronously.
48
+ */
20
49
  queue?: MessageQueue;
50
+ /**
51
+ * Handler function that determines whether to approve or reject
52
+ * subscription requests from remote actors.
53
+ * Return `true` to approve or `false` to reject.
54
+ */
55
+ subscriptionHandler: SubscriptionRequestHandler;
21
56
  }
22
57
  /**
23
- * Base interface for ActivityPub relay implementations.
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
24
63
  */
25
- interface Relay {
26
- readonly domain: string;
27
- fetch(request: Request): Promise<Response>;
28
- setSubscriptionHandler(handler: SubscriptionRequestHandler): this;
29
- }
64
+
30
65
  /**
31
- * A Mastodon-compatible ActivityPub relay implementation.
32
- * This relay follows Mastodon's relay protocol for maximum compatibility
33
- * with Mastodon instances.
66
+ * A follower of the relay with validated Actor instance.
67
+ * This is the public API type returned by follower query methods.
34
68
  *
35
69
  * @since 2.0.0
36
70
  */
37
- declare class MastodonRelay implements Relay {
38
- #private;
39
- constructor(options: RelayOptions);
40
- get domain(): string;
41
- fetch(request: Request): Promise<Response>;
42
- setSubscriptionHandler(handler: SubscriptionRequestHandler): this;
71
+ interface RelayFollower {
72
+ /** The actor ID (URL) of the follower. */
73
+ readonly actorId: string;
74
+ /** The validated Actor object. */
75
+ readonly actor: Actor;
76
+ /** The follower's state. */
77
+ readonly state: "pending" | "accepted";
43
78
  }
44
79
  /**
45
- * A LitePub-compatible ActivityPub relay implementation.
46
- * This relay follows LitePub's relay protocol and extensions for
47
- * enhanced federation capabilities.
80
+ * Public interface for ActivityPub relay implementations.
81
+ * Use {@link createRelay} to create a relay instance.
48
82
  *
49
83
  * @since 2.0.0
50
84
  */
51
- declare class LitePubRelay implements Relay {
52
- #private;
53
- constructor(options: RelayOptions);
54
- get domain(): string;
85
+ interface Relay {
86
+ /**
87
+ * Handle incoming HTTP requests.
88
+ *
89
+ * @param request The incoming HTTP request
90
+ * @returns The HTTP response
91
+ */
55
92
  fetch(request: Request): Promise<Response>;
56
- setSubscriptionHandler(handler: SubscriptionRequestHandler): this;
93
+ /**
94
+ * Lists all followers of the relay.
95
+ *
96
+ * @returns An async iterator of follower entries
97
+ */
98
+ listFollowers(): AsyncIterableIterator<RelayFollower>;
99
+ /**
100
+ * Gets a specific follower by actor ID.
101
+ *
102
+ * @param actorId The actor ID (URL) of the follower to retrieve
103
+ * @returns The follower entry if found, null otherwise
104
+ */
105
+ getFollower(actorId: string): Promise<RelayFollower | null>;
106
+ /**
107
+ * Gets the URI of the relay actor.
108
+ *
109
+ * @returns The URI of the relay actor
110
+ */
111
+ getActorUri(): Promise<URL>;
112
+ /**
113
+ * Gets the shared inbox URI of the relay.
114
+ *
115
+ * @returns The shared inbox URI
116
+ */
117
+ getSharedInboxUri(): Promise<URL>;
57
118
  }
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
+ //#endregion
128
+ //#region src/factory.d.ts
129
+ /**
130
+ * Factory function to create a relay instance.
131
+ *
132
+ * @param type The type of relay to create ("mastodon" or "litepub")
133
+ * @param options Configuration options for the relay
134
+ * @returns A relay instance
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * import { createRelay } from "@fedify/relay";
139
+ * import { MemoryKvStore } from "@fedify/fedify";
140
+ *
141
+ * const relay = createRelay("mastodon", {
142
+ * kv: new MemoryKvStore(),
143
+ * origin: "https://relay.example.com",
144
+ * subscriptionHandler: async (ctx, actor) => true,
145
+ * });
146
+ * ```
147
+ *
148
+ * @since 2.0.0
149
+ */
150
+ declare function createRelay(type: RelayType, options: RelayOptions): Relay;
58
151
  //#endregion
59
- export { LitePubRelay, MastodonRelay, Relay, RelayOptions };
152
+ export { RELAY_SERVER_ACTOR, Relay, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay };