matrix-nodejs-homeserver 0.0.0-stage → 0.3.1
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/LICENSE +75 -0
- package/README.md +479 -2
- package/dist/adapters/auth.d.ts +50 -0
- package/dist/adapters/auth.js +18 -0
- package/dist/adapters/cluster.d.ts +55 -0
- package/dist/adapters/cluster.js +249 -0
- package/dist/adapters/media.d.ts +50 -0
- package/dist/adapters/media.js +63 -0
- package/dist/adapters/s3.d.ts +33 -0
- package/dist/adapters/s3.js +95 -0
- package/dist/api/account.js +594 -0
- package/dist/api/admin.js +267 -0
- package/dist/api/appservice.js +45 -0
- package/dist/api/backup.js +280 -0
- package/dist/api/federation.js +826 -0
- package/dist/api/filters.js +88 -0
- package/dist/api/index.js +47 -0
- package/dist/api/legacy.js +183 -0
- package/dist/api/media.js +271 -0
- package/dist/api/misc.js +95 -0
- package/dist/api/preview.js +201 -0
- package/dist/api/profile.js +176 -0
- package/dist/api/push.js +202 -0
- package/dist/api/relationships.js +270 -0
- package/dist/api/rooms.js +1487 -0
- package/dist/api/rtc.d.ts +23 -0
- package/dist/api/rtc.js +66 -0
- package/dist/api/search.js +161 -0
- package/dist/api/slidingsync.js +474 -0
- package/dist/api/spaces.js +177 -0
- package/dist/api/sync.js +609 -0
- package/dist/api/threadsubs.js +140 -0
- package/dist/api/threepid.js +155 -0
- package/dist/api/uia.js +127 -0
- package/dist/api/user.js +329 -0
- package/dist/core/admin.d.ts +84 -0
- package/dist/core/admin.js +308 -0
- package/dist/core/adminroom.d.ts +49 -0
- package/dist/core/adminroom.js +483 -0
- package/dist/core/appservices.d.ts +74 -0
- package/dist/core/appservices.js +369 -0
- package/dist/core/audit.d.ts +50 -0
- package/dist/core/audit.js +86 -0
- package/dist/core/auth.d.ts +48 -0
- package/dist/core/auth.js +237 -0
- package/dist/core/authrules.d.ts +4 -0
- package/dist/core/authrules.js +348 -0
- package/dist/core/cluster.d.ts +66 -0
- package/dist/core/cluster.js +191 -0
- package/dist/core/crypto.d.ts +10 -0
- package/dist/core/crypto.js +100 -0
- package/dist/core/delayed.d.ts +39 -0
- package/dist/core/delayed.js +160 -0
- package/dist/core/errors.d.ts +9 -0
- package/dist/core/errors.js +45 -0
- package/dist/core/events.d.ts +32 -0
- package/dist/core/events.js +186 -0
- package/dist/core/glob.js +66 -0
- package/dist/core/identity.d.ts +24 -0
- package/dist/core/identity.js +96 -0
- package/dist/core/ids.js +36 -0
- package/dist/core/invitefilter.js +36 -0
- package/dist/core/json.js +16 -0
- package/dist/core/keys.d.ts +36 -0
- package/dist/core/keys.js +450 -0
- package/dist/core/m.d.ts +209 -0
- package/dist/core/m.js +182 -0
- package/dist/core/notifier.d.ts +17 -0
- package/dist/core/notifier.js +54 -0
- package/dist/core/oauth.d.ts +38 -0
- package/dist/core/oauth.js +108 -0
- package/dist/core/partialstate.d.ts +32 -0
- package/dist/core/partialstate.js +198 -0
- package/dist/core/phone.js +268 -0
- package/dist/core/policy.d.ts +29 -0
- package/dist/core/policy.js +97 -0
- package/dist/core/profile.js +39 -0
- package/dist/core/push.d.ts +46 -0
- package/dist/core/push.js +307 -0
- package/dist/core/pushrules.js +229 -0
- package/dist/core/ratelimit.d.ts +23 -0
- package/dist/core/ratelimit.js +77 -0
- package/dist/core/rooms.d.ts +215 -0
- package/dist/core/rooms.js +1731 -0
- package/dist/core/settings.d.ts +11 -0
- package/dist/core/settings.js +29 -0
- package/dist/core/sso.d.ts +46 -0
- package/dist/core/sso.js +165 -0
- package/dist/core/stateres.d.ts +4 -0
- package/dist/core/stateres.js +209 -0
- package/dist/core/threepid.d.ts +80 -0
- package/dist/core/threepid.js +275 -0
- package/dist/core/typing.d.ts +16 -0
- package/dist/core/typing.js +60 -0
- package/dist/federation/client.d.ts +51 -0
- package/dist/federation/client.js +279 -0
- package/dist/federation/index.d.ts +153 -0
- package/dist/federation/index.js +1059 -0
- package/dist/federation/keyring.d.ts +26 -0
- package/dist/federation/keyring.js +122 -0
- package/dist/federation/sender.d.ts +26 -0
- package/dist/federation/sender.js +164 -0
- package/dist/homeserver.d.ts +224 -0
- package/dist/homeserver.js +302 -0
- package/dist/http/adapters.d.ts +40 -0
- package/dist/http/adapters.js +130 -0
- package/dist/http/handler.d.ts +8 -0
- package/dist/http/handler.js +181 -0
- package/dist/http/input.js +24 -0
- package/dist/http/procedure.js +25 -0
- package/dist/http/router.d.ts +43 -0
- package/dist/http/router.js +56 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +15 -0
- package/dist/storage/memory.d.ts +5 -0
- package/dist/storage/memory.js +122 -0
- package/dist/storage/schema.d.ts +4 -0
- package/dist/storage/schema.js +664 -0
- package/dist/storage/sql.d.ts +72 -0
- package/dist/storage/sql.js +274 -0
- package/dist/storage/types.d.ts +55 -0
- package/dist/vendor/zod/LICENSE +21 -0
- package/dist/vendor/zod/v4/classic/errors.js +54 -0
- package/dist/vendor/zod/v4/classic/parse.js +17 -0
- package/dist/vendor/zod/v4/classic/schemas.js +865 -0
- package/dist/vendor/zod/v4/core/api.js +512 -0
- package/dist/vendor/zod/v4/core/checks.js +300 -0
- package/dist/vendor/zod/v4/core/core.js +109 -0
- package/dist/vendor/zod/v4/core/doc.js +35 -0
- package/dist/vendor/zod/v4/core/errors.js +118 -0
- package/dist/vendor/zod/v4/core/json-schema-processors.js +428 -0
- package/dist/vendor/zod/v4/core/memoizer.js +255 -0
- package/dist/vendor/zod/v4/core/parse.js +206 -0
- package/dist/vendor/zod/v4/core/regexes.js +73 -0
- package/dist/vendor/zod/v4/core/registries.js +48 -0
- package/dist/vendor/zod/v4/core/schemas.js +1378 -0
- package/dist/vendor/zod/v4/core/to-json-schema.js +448 -0
- package/dist/vendor/zod/v4/core/util.js +537 -0
- package/dist/vendor/zod/v4/core/versions.js +8 -0
- package/dist/vendor/zod/v4/locales/en.js +110 -0
- package/package.json +65 -4
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { ClientEvent, PDU } from "./events.js";
|
|
2
|
+
import { StateMap } from "./authrules.js";
|
|
3
|
+
import { StateIds } from "./stateres.js";
|
|
4
|
+
import { Row } from "../storage/types.js";
|
|
5
|
+
import { Homeserver } from "../homeserver.js";
|
|
6
|
+
//#region src/core/rooms.d.ts
|
|
7
|
+
export interface StoredEvent {
|
|
8
|
+
pdu: PDU;
|
|
9
|
+
stream: number;
|
|
10
|
+
snapshot: number;
|
|
11
|
+
txnId: string | null;
|
|
12
|
+
txnToken: string | null;
|
|
13
|
+
/** Membership of the viewing user at this event (set by `filterVisible`). */
|
|
14
|
+
viewerMembership?: string;
|
|
15
|
+
/** The event's predecessors were not all available when it was persisted. */
|
|
16
|
+
gap?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface EventDraft {
|
|
19
|
+
type: string;
|
|
20
|
+
content: Record<string, any>;
|
|
21
|
+
state_key?: string;
|
|
22
|
+
redacts?: string;
|
|
23
|
+
}
|
|
24
|
+
interface Outlier {
|
|
25
|
+
pdu: PDU;
|
|
26
|
+
snapshot: number | null;
|
|
27
|
+
rejected: string | null;
|
|
28
|
+
softFailed: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface StateBefore {
|
|
31
|
+
ids: StateIds;
|
|
32
|
+
/** Snapshot ID when the state equals an existing snapshot (single predecessor). */
|
|
33
|
+
snapshot: number | null;
|
|
34
|
+
}
|
|
35
|
+
export interface PersistOptions {
|
|
36
|
+
/** Event created by this server (already authorised). */
|
|
37
|
+
local?: boolean;
|
|
38
|
+
txnId?: string;
|
|
39
|
+
deviceId?: string;
|
|
40
|
+
/** Explicit state before the event (e.g. from a send_join response or /state_ids). */
|
|
41
|
+
stateBefore?: StateIds;
|
|
42
|
+
/** Historical event fetched by backfill: placed before existing timeline, no state changes. */
|
|
43
|
+
backfill?: boolean;
|
|
44
|
+
/** For v12 rooms when the create event is not part of the current state yet. */
|
|
45
|
+
createEvent?: PDU;
|
|
46
|
+
/** Result of checking the restricted-join authorising server's signature. */
|
|
47
|
+
joinAuthorisedSignatureValid?: boolean;
|
|
48
|
+
/** Do not send this local event to other servers (they already have it). */
|
|
49
|
+
noFederate?: boolean;
|
|
50
|
+
/** Explicit stream position (used by backfill to preserve ordering). */
|
|
51
|
+
stream?: number;
|
|
52
|
+
/** Some prev_events are unknown (filled from remote state instead). */
|
|
53
|
+
gap?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface PersistResult {
|
|
56
|
+
eventId: string;
|
|
57
|
+
status: "persisted" | "soft_failed" | "rejected";
|
|
58
|
+
reason?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare class RoomService {
|
|
61
|
+
private hs;
|
|
62
|
+
private eventCache;
|
|
63
|
+
private snapshotCache;
|
|
64
|
+
private stateCache;
|
|
65
|
+
private extremityCache;
|
|
66
|
+
private outlierCache;
|
|
67
|
+
private versions;
|
|
68
|
+
private snapshotDepths;
|
|
69
|
+
private sharingCache;
|
|
70
|
+
private localClusterMarker;
|
|
71
|
+
constructor(hs: Homeserver, singleInstance: boolean);
|
|
72
|
+
/** Serialise writes per room (cluster-wide) so forward extremities stay consistent. */
|
|
73
|
+
withLock<T>(roomId: string, fn: () => Promise<T>): Promise<T>;
|
|
74
|
+
/** Drop cached data (for this instance only). */
|
|
75
|
+
private invalidateLocal;
|
|
76
|
+
/** Tell other instances to drop cached data. */
|
|
77
|
+
invalidate(msg: {
|
|
78
|
+
rooms?: string[];
|
|
79
|
+
events?: string[];
|
|
80
|
+
sharing?: boolean;
|
|
81
|
+
}): void;
|
|
82
|
+
forgetEventCache(eventId: string): void;
|
|
83
|
+
/** Drop all cached data for a room (after it was purged). */
|
|
84
|
+
forgetRoom(roomId: string): void;
|
|
85
|
+
roomVersion(roomId: string): Promise<string | null>;
|
|
86
|
+
exists(roomId: string): Promise<boolean>;
|
|
87
|
+
rowToStored(row: Row): StoredEvent;
|
|
88
|
+
getEvent(eventId: string): Promise<StoredEvent | null>;
|
|
89
|
+
getEvents(eventIds: string[]): Promise<Map<string, StoredEvent>>;
|
|
90
|
+
snapshotIds(snapshotId: number): Promise<Record<string, string>>;
|
|
91
|
+
stateAtSnapshot(snapshotId: number): Promise<StateMap>;
|
|
92
|
+
currentState(roomId: string): Promise<StateMap>;
|
|
93
|
+
currentStateIds(roomId: string): Promise<StateIds>;
|
|
94
|
+
/** Forward extremities: the latest events in the room DAG, used as prev_events of new events. */
|
|
95
|
+
extremities(roomId: string): Promise<string[]>;
|
|
96
|
+
getOutlier(eventId: string): Promise<Outlier | null>;
|
|
97
|
+
/** Any known PDU (timeline event or non-rejected outlier). */
|
|
98
|
+
getPdu(eventId: string): Promise<PDU | null>;
|
|
99
|
+
getPdus(eventIds: string[]): Promise<Map<string, PDU>>;
|
|
100
|
+
/** Whether we have seen this event at all (including rejected ones). */
|
|
101
|
+
knowsEvent(eventId: string): Promise<boolean>;
|
|
102
|
+
/** Snapshot ID of the state after an event, or null when the state is unknown. */
|
|
103
|
+
snapshotOf(eventId: string): Promise<number | null>;
|
|
104
|
+
stateIdsToMap(ids: StateIds): Promise<StateMap>;
|
|
105
|
+
createEventOf(roomId: string): Promise<PDU | undefined>;
|
|
106
|
+
/**
|
|
107
|
+
* State before an event with the given prev_events: the snapshot of a single
|
|
108
|
+
* predecessor, or the resolution of several. Throws MissingStateError when a
|
|
109
|
+
* predecessor's state is unknown.
|
|
110
|
+
*/
|
|
111
|
+
stateBefore(roomId: string, version: string, prevIds: string[], createEvent?: PDU): Promise<StateBefore>;
|
|
112
|
+
/** Validate, authorise, sign and persist a new local event. Returns the event ID. */
|
|
113
|
+
sendEvent(roomId: string, sender: string, draft: EventDraft, opts?: {
|
|
114
|
+
txnId?: string;
|
|
115
|
+
deviceId?: string;
|
|
116
|
+
skipAuth?: boolean;
|
|
117
|
+
ts?: number;
|
|
118
|
+
}): Promise<string>;
|
|
119
|
+
/** Build and sign (but do not persist) a local event on top of the current forward extremities. */
|
|
120
|
+
buildLocalEvent(roomId: string, version: string, sender: string, draft: EventDraft, skipAuth?: boolean, ts?: number): Promise<PDU>;
|
|
121
|
+
/**
|
|
122
|
+
* Persist an event (local or remote). Remote events are checked against their auth
|
|
123
|
+
* events, the state before them and the current state (soft failure).
|
|
124
|
+
*/
|
|
125
|
+
persistEvent(roomId: string, version: string, pdu: PDU, opts?: PersistOptions): Promise<PersistResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Finish a partial-state join (MSC3902): `fullBefore` is the complete state before our join
|
|
128
|
+
* event. Recompute the state of the join and of every event received since, re-checking each
|
|
129
|
+
* remote event against its now complete state (events wrongly accepted become rejected), then
|
|
130
|
+
* rebuild the room's current state. Caller holds the room lock.
|
|
131
|
+
*/
|
|
132
|
+
completePartialState(roomId: string, version: string, joinEventId: string, fullBefore: StateIds, notified: Set<string>): Promise<string[]>;
|
|
133
|
+
/** The create event, also when the room's current state is not known yet (v12 joins). */
|
|
134
|
+
private findCreateEvent;
|
|
135
|
+
private store;
|
|
136
|
+
private snapshotDepth;
|
|
137
|
+
membership(roomId: string, userId: string): Promise<string>;
|
|
138
|
+
requireJoined(roomId: string, userId: string): Promise<StateMap>;
|
|
139
|
+
joinedMembers(roomId: string): Promise<string[]>;
|
|
140
|
+
/** Users that should be woken up for events in this room. */
|
|
141
|
+
private interestedUsers;
|
|
142
|
+
roomsForUser(userId: string, membership?: string): Promise<string[]>;
|
|
143
|
+
/** All users sharing at least one joined room with `userId` (including themselves). */
|
|
144
|
+
usersSharingRooms(userId: string): Promise<Set<string>>;
|
|
145
|
+
private prepareRedaction;
|
|
146
|
+
private commitRedaction;
|
|
147
|
+
/** Check whether a redaction would be permitted, before sending it. */
|
|
148
|
+
checkRedactionAllowed(roomId: string, sender: string, targetId: string): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Room state shared with invitees and knockers (MSC4311): full PDUs in federation
|
|
151
|
+
* format, including the create event. Clients receive stripped versions.
|
|
152
|
+
*/
|
|
153
|
+
strippedState(state: StateMap): Record<string, any>[];
|
|
154
|
+
/** Filter events down to those `userId` may see according to history visibility. */
|
|
155
|
+
filterVisible(userId: string | null, roomId: string, events: StoredEvent[]): Promise<StoredEvent[]>;
|
|
156
|
+
/** Whether the user may view the room's current state / history at all (`world_readable` or member). */
|
|
157
|
+
canPeek(roomId: string, userId: string): Promise<{
|
|
158
|
+
joined: boolean;
|
|
159
|
+
worldReadable: boolean;
|
|
160
|
+
membership: string;
|
|
161
|
+
}>;
|
|
162
|
+
/** The state snapshot visible to a user who is no longer joined (state at their leave). */
|
|
163
|
+
membershipEvent(roomId: string, userId: string): Promise<StoredEvent | null>;
|
|
164
|
+
formatEvent(ev: StoredEvent, viewer?: {
|
|
165
|
+
userId: string;
|
|
166
|
+
deviceId: string;
|
|
167
|
+
} | null, opts?: {
|
|
168
|
+
includeRoomId?: boolean;
|
|
169
|
+
}): ClientEvent;
|
|
170
|
+
stateToList(state: StateMap): PDU[];
|
|
171
|
+
createRoom(sender: string, body: Record<string, any>): Promise<{
|
|
172
|
+
room_id: string;
|
|
173
|
+
room_alias?: string;
|
|
174
|
+
}>;
|
|
175
|
+
resolveRoomIdOrAlias(idOrAlias: string): Promise<string>;
|
|
176
|
+
/** Resolve a room ID or alias, including remote aliases; returns candidate servers for joining. */
|
|
177
|
+
resolveRoom(idOrAlias: string): Promise<{
|
|
178
|
+
roomId: string;
|
|
179
|
+
servers: string[];
|
|
180
|
+
}>;
|
|
181
|
+
/** Whether the room was created on this server and we still have its state. */
|
|
182
|
+
isLocallyHosted(roomId: string): Promise<boolean>;
|
|
183
|
+
/** Whether any local user is joined to the room (i.e. this server participates in it). */
|
|
184
|
+
serverIsJoined(roomId: string): Promise<boolean>;
|
|
185
|
+
/** Servers that might help with a remote membership change for `userId` in `roomId`. */
|
|
186
|
+
private remoteServersFor;
|
|
187
|
+
/**
|
|
188
|
+
* Record a membership event for a room this server may not participate in (remote
|
|
189
|
+
* invites, rejections, knocks) so that it shows up in /sync.
|
|
190
|
+
*/
|
|
191
|
+
recordRemoteMembership(pdu: PDU, version: string): Promise<void>;
|
|
192
|
+
join(userId: string, roomId: string, extra?: {
|
|
193
|
+
reason?: string;
|
|
194
|
+
content?: Record<string, any>;
|
|
195
|
+
servers?: string[];
|
|
196
|
+
}): Promise<string>;
|
|
197
|
+
private joinLocal;
|
|
198
|
+
/** Whether an allowed room exists that we can't check (or the user is joined to), so another server might authorise. */
|
|
199
|
+
private mayQualifyRemotely;
|
|
200
|
+
private findRestrictedAuthoriser;
|
|
201
|
+
invite(roomId: string, sender: string, target: string, opts?: {
|
|
202
|
+
reason?: string;
|
|
203
|
+
isDirect?: boolean;
|
|
204
|
+
thirdPartyInvite?: {
|
|
205
|
+
display_name: string;
|
|
206
|
+
signed: Record<string, any>;
|
|
207
|
+
};
|
|
208
|
+
}): Promise<void>;
|
|
209
|
+
setMembership(roomId: string, sender: string, target: string, membership: "leave" | "ban" | "knock", reason?: string, via?: string[]): Promise<void>;
|
|
210
|
+
private remoteMembership;
|
|
211
|
+
/** Update the member event in every joined room after a profile change. */
|
|
212
|
+
propagateProfile(userId: string): Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export {};
|