@fedify/relay 2.0.0-dev.12 → 2.0.0-dev.85
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/README.md +99 -40
- package/dist/mod.cjs +288 -385
- package/dist/mod.d.cts +79 -25
- package/dist/mod.d.ts +80 -25
- package/dist/mod.js +283 -384
- package/package.json +10 -7
package/dist/mod.d.cts
CHANGED
|
@@ -1,46 +1,90 @@
|
|
|
1
|
-
import { Context, Federation, KvStore, MessageQueue } from "@fedify/fedify";
|
|
1
|
+
import { Context, Federation, FederationBuilder, KvStore, MessageQueue } from "@fedify/fedify";
|
|
2
2
|
import { Actor } from "@fedify/fedify/vocab";
|
|
3
3
|
import { AuthenticatedDocumentLoaderFactory, DocumentLoaderFactory } from "@fedify/vocab-runtime";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
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<
|
|
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 {
|
|
15
19
|
kv: KvStore;
|
|
16
20
|
domain?: string;
|
|
21
|
+
name?: string;
|
|
17
22
|
documentLoaderFactory?: DocumentLoaderFactory;
|
|
18
23
|
authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
|
|
19
|
-
federation?: Federation<void>;
|
|
20
24
|
queue?: MessageQueue;
|
|
25
|
+
subscriptionHandler: SubscriptionRequestHandler;
|
|
26
|
+
}
|
|
27
|
+
interface RelayFollower {
|
|
28
|
+
readonly actor: unknown;
|
|
29
|
+
readonly state: "pending" | "accepted";
|
|
21
30
|
}
|
|
22
31
|
/**
|
|
23
|
-
*
|
|
32
|
+
* Type predicate to check if a value is a valid RelayFollower.
|
|
33
|
+
* Provides both runtime validation and compile-time type narrowing.
|
|
34
|
+
*
|
|
35
|
+
* @param value The value to check
|
|
36
|
+
* @returns true if the value is a RelayFollower
|
|
24
37
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
declare function isRelayFollower(value: unknown): value is RelayFollower;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/builder.d.ts
|
|
41
|
+
declare const relayBuilder: FederationBuilder<RelayOptions>;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/base.d.ts
|
|
30
44
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* with Mastodon instances.
|
|
45
|
+
* Abstract base class for relay implementations.
|
|
46
|
+
* Provides common infrastructure for both Mastodon and LitePub relays.
|
|
34
47
|
*
|
|
35
48
|
* @since 2.0.0
|
|
36
49
|
*/
|
|
37
|
-
declare class
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
declare abstract class BaseRelay {
|
|
51
|
+
protected federationBuilder: FederationBuilder<RelayOptions>;
|
|
52
|
+
protected options: RelayOptions;
|
|
53
|
+
protected federation?: Federation<RelayOptions>;
|
|
54
|
+
constructor(options: RelayOptions, relayBuilder: FederationBuilder<RelayOptions>);
|
|
41
55
|
fetch(request: Request): Promise<Response>;
|
|
42
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Set up inbox listeners for handling ActivityPub activities.
|
|
58
|
+
* Each relay type implements this method with protocol-specific logic.
|
|
59
|
+
*/
|
|
60
|
+
protected abstract setupInboxListeners(): void;
|
|
43
61
|
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/factory.d.ts
|
|
64
|
+
/**
|
|
65
|
+
* Factory function to create a relay instance.
|
|
66
|
+
*
|
|
67
|
+
* @param type The type of relay to create ("mastodon" or "litepub")
|
|
68
|
+
* @param options Configuration options for the relay
|
|
69
|
+
* @returns A relay instance
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { createRelay } from "@fedify/relay";
|
|
74
|
+
* import { MemoryKvStore } from "@fedify/fedify";
|
|
75
|
+
*
|
|
76
|
+
* const relay = createRelay("mastodon", {
|
|
77
|
+
* kv: new MemoryKvStore(),
|
|
78
|
+
* domain: "relay.example.com",
|
|
79
|
+
* subscriptionHandler: async (ctx, actor) => true,
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @since 2.0.0
|
|
84
|
+
*/
|
|
85
|
+
declare function createRelay(type: RelayType, options: RelayOptions): BaseRelay;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/litepub.d.ts
|
|
44
88
|
/**
|
|
45
89
|
* A LitePub-compatible ActivityPub relay implementation.
|
|
46
90
|
* This relay follows LitePub's relay protocol and extensions for
|
|
@@ -48,12 +92,22 @@ declare class MastodonRelay implements Relay {
|
|
|
48
92
|
*
|
|
49
93
|
* @since 2.0.0
|
|
50
94
|
*/
|
|
51
|
-
declare class LitePubRelay
|
|
95
|
+
declare class LitePubRelay extends BaseRelay {
|
|
52
96
|
#private;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
97
|
+
protected setupInboxListeners(): void;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/mastodon.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* A Mastodon-compatible ActivityPub relay implementation.
|
|
103
|
+
* This relay follows Mastodon's relay protocol for compatibility
|
|
104
|
+
* with Mastodon instances.
|
|
105
|
+
*
|
|
106
|
+
* @since 2.0.0
|
|
107
|
+
*/
|
|
108
|
+
declare class MastodonRelay extends BaseRelay {
|
|
109
|
+
#private;
|
|
110
|
+
protected setupInboxListeners(): void;
|
|
57
111
|
}
|
|
58
112
|
//#endregion
|
|
59
|
-
export { LitePubRelay, MastodonRelay,
|
|
113
|
+
export { LitePubRelay, MastodonRelay, RELAY_SERVER_ACTOR, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay, isRelayFollower, relayBuilder };
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,46 +1,91 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { Context, Federation, FederationBuilder, KvStore, MessageQueue } from "@fedify/fedify";
|
|
2
3
|
import { Actor } from "@fedify/fedify/vocab";
|
|
3
4
|
import { AuthenticatedDocumentLoaderFactory, DocumentLoaderFactory } from "@fedify/vocab-runtime";
|
|
4
5
|
|
|
5
|
-
//#region src/
|
|
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<
|
|
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 {
|
|
15
20
|
kv: KvStore;
|
|
16
21
|
domain?: string;
|
|
22
|
+
name?: string;
|
|
17
23
|
documentLoaderFactory?: DocumentLoaderFactory;
|
|
18
24
|
authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
|
|
19
|
-
federation?: Federation<void>;
|
|
20
25
|
queue?: MessageQueue;
|
|
26
|
+
subscriptionHandler: SubscriptionRequestHandler;
|
|
27
|
+
}
|
|
28
|
+
interface RelayFollower {
|
|
29
|
+
readonly actor: unknown;
|
|
30
|
+
readonly state: "pending" | "accepted";
|
|
21
31
|
}
|
|
22
32
|
/**
|
|
23
|
-
*
|
|
33
|
+
* Type predicate to check if a value is a valid RelayFollower.
|
|
34
|
+
* Provides both runtime validation and compile-time type narrowing.
|
|
35
|
+
*
|
|
36
|
+
* @param value The value to check
|
|
37
|
+
* @returns true if the value is a RelayFollower
|
|
24
38
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
declare function isRelayFollower(value: unknown): value is RelayFollower;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/builder.d.ts
|
|
42
|
+
declare const relayBuilder: FederationBuilder<RelayOptions>;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/base.d.ts
|
|
30
45
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* with Mastodon instances.
|
|
46
|
+
* Abstract base class for relay implementations.
|
|
47
|
+
* Provides common infrastructure for both Mastodon and LitePub relays.
|
|
34
48
|
*
|
|
35
49
|
* @since 2.0.0
|
|
36
50
|
*/
|
|
37
|
-
declare class
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
declare abstract class BaseRelay {
|
|
52
|
+
protected federationBuilder: FederationBuilder<RelayOptions>;
|
|
53
|
+
protected options: RelayOptions;
|
|
54
|
+
protected federation?: Federation<RelayOptions>;
|
|
55
|
+
constructor(options: RelayOptions, relayBuilder: FederationBuilder<RelayOptions>);
|
|
41
56
|
fetch(request: Request): Promise<Response>;
|
|
42
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Set up inbox listeners for handling ActivityPub activities.
|
|
59
|
+
* Each relay type implements this method with protocol-specific logic.
|
|
60
|
+
*/
|
|
61
|
+
protected abstract setupInboxListeners(): void;
|
|
43
62
|
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/factory.d.ts
|
|
65
|
+
/**
|
|
66
|
+
* Factory function to create a relay instance.
|
|
67
|
+
*
|
|
68
|
+
* @param type The type of relay to create ("mastodon" or "litepub")
|
|
69
|
+
* @param options Configuration options for the relay
|
|
70
|
+
* @returns A relay instance
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { createRelay } from "@fedify/relay";
|
|
75
|
+
* import { MemoryKvStore } from "@fedify/fedify";
|
|
76
|
+
*
|
|
77
|
+
* const relay = createRelay("mastodon", {
|
|
78
|
+
* kv: new MemoryKvStore(),
|
|
79
|
+
* domain: "relay.example.com",
|
|
80
|
+
* subscriptionHandler: async (ctx, actor) => true,
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @since 2.0.0
|
|
85
|
+
*/
|
|
86
|
+
declare function createRelay(type: RelayType, options: RelayOptions): BaseRelay;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/litepub.d.ts
|
|
44
89
|
/**
|
|
45
90
|
* A LitePub-compatible ActivityPub relay implementation.
|
|
46
91
|
* This relay follows LitePub's relay protocol and extensions for
|
|
@@ -48,12 +93,22 @@ declare class MastodonRelay implements Relay {
|
|
|
48
93
|
*
|
|
49
94
|
* @since 2.0.0
|
|
50
95
|
*/
|
|
51
|
-
declare class LitePubRelay
|
|
96
|
+
declare class LitePubRelay extends BaseRelay {
|
|
52
97
|
#private;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
98
|
+
protected setupInboxListeners(): void;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/mastodon.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* A Mastodon-compatible ActivityPub relay implementation.
|
|
104
|
+
* This relay follows Mastodon's relay protocol for compatibility
|
|
105
|
+
* with Mastodon instances.
|
|
106
|
+
*
|
|
107
|
+
* @since 2.0.0
|
|
108
|
+
*/
|
|
109
|
+
declare class MastodonRelay extends BaseRelay {
|
|
110
|
+
#private;
|
|
111
|
+
protected setupInboxListeners(): void;
|
|
57
112
|
}
|
|
58
113
|
//#endregion
|
|
59
|
-
export { LitePubRelay, MastodonRelay,
|
|
114
|
+
export { LitePubRelay, MastodonRelay, RELAY_SERVER_ACTOR, RelayFollower, RelayOptions, RelayType, SubscriptionRequestHandler, createRelay, isRelayFollower, relayBuilder };
|