matrix-nodejs-homeserver 0.2.0 → 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/README.md +29 -7
- package/dist/api/account.js +385 -351
- package/dist/api/admin.js +76 -60
- package/dist/api/appservice.js +37 -25
- package/dist/api/backup.js +73 -62
- package/dist/api/federation.js +172 -138
- package/dist/api/filters.js +4 -3
- package/dist/api/legacy.js +91 -78
- package/dist/api/media.js +70 -54
- package/dist/api/misc.js +46 -37
- package/dist/api/preview.js +4 -3
- package/dist/api/profile.js +108 -97
- package/dist/api/push.js +114 -99
- package/dist/api/relationships.js +64 -58
- package/dist/api/rooms.js +703 -580
- package/dist/api/rtc.d.ts +0 -1
- package/dist/api/rtc.js +48 -34
- package/dist/api/search.js +133 -127
- package/dist/api/slidingsync.js +41 -31
- package/dist/api/spaces.js +82 -77
- package/dist/api/sync.js +59 -50
- package/dist/api/threadsubs.js +72 -61
- package/dist/api/threepid.js +99 -66
- package/dist/api/uia.js +17 -16
- package/dist/api/user.js +221 -178
- package/dist/core/admin.d.ts +0 -1
- package/dist/core/admin.js +6 -5
- package/dist/core/adminroom.js +9 -8
- package/dist/core/appservices.d.ts +2 -1
- package/dist/core/appservices.js +5 -4
- package/dist/core/audit.d.ts +0 -1
- package/dist/core/authrules.js +26 -25
- package/dist/core/delayed.js +2 -1
- package/dist/core/events.js +11 -10
- package/dist/core/invitefilter.js +2 -1
- package/dist/core/keys.js +2 -1
- package/dist/core/m.d.ts +209 -0
- package/dist/core/m.js +182 -0
- package/dist/core/partialstate.js +2 -1
- package/dist/core/policy.js +4 -3
- package/dist/core/push.d.ts +0 -1
- package/dist/core/push.js +12 -11
- package/dist/core/pushrules.js +36 -35
- package/dist/core/rooms.js +76 -74
- package/dist/core/stateres.js +7 -6
- package/dist/federation/client.js +2 -1
- package/dist/federation/index.d.ts +1 -1
- package/dist/federation/index.js +30 -29
- package/dist/homeserver.d.ts +2 -1
- package/dist/homeserver.js +1 -0
- package/dist/http/handler.js +2 -23
- package/dist/http/input.js +2 -2
- package/dist/http/procedure.js +25 -0
- package/dist/http/router.d.ts +9 -26
- package/dist/http/router.js +10 -30
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- 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 +3 -5
- package/dist/core/pushrules.d.ts +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { isObject } from "../core/json.js";
|
|
2
|
+
import { M } from "../core/m.js";
|
|
2
3
|
import { toClientEvent } from "../core/events.js";
|
|
3
4
|
import { errors } from "../core/errors.js";
|
|
4
5
|
import { getState } from "../core/authrules.js";
|
|
5
6
|
import { body } from "../http/input.js";
|
|
7
|
+
import { procedure } from "../http/procedure.js";
|
|
6
8
|
import { createHash } from "node:crypto";
|
|
7
9
|
//#region src/api/relationships.ts
|
|
8
10
|
function parseRequest(body) {
|
|
@@ -22,7 +24,7 @@ function parseRequest(body) {
|
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
function relationshipOf(pdu) {
|
|
25
|
-
const rel = pdu.content?.[
|
|
27
|
+
const rel = pdu.content?.[M.RELATIONSHIP];
|
|
26
28
|
return isObject(rel) && typeof rel.event_id === "string" && typeof rel.rel_type === "string" ? {
|
|
27
29
|
event_id: rel.event_id,
|
|
28
30
|
rel_type: rel.rel_type
|
|
@@ -169,71 +171,75 @@ async function fetchRemote(hs, roomId, req, remoteHashes) {
|
|
|
169
171
|
return false;
|
|
170
172
|
}
|
|
171
173
|
function registerRelationshipRoutes(r) {
|
|
172
|
-
r.post("/_matrix/client/unstable/event_relationships",
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const ev = await hs.rooms.getEvent(pdu.event_id);
|
|
185
|
-
if (!ev) return true;
|
|
186
|
-
return (await hs.rooms.filterVisible(s.userId, roomId, [ev])).length > 0;
|
|
187
|
-
};
|
|
188
|
-
const asked = /* @__PURE__ */ new Set();
|
|
189
|
-
const remoteHashes = /* @__PURE__ */ new Map();
|
|
190
|
-
let result = {
|
|
191
|
-
events: [],
|
|
192
|
-
limited: false,
|
|
193
|
-
root: null
|
|
194
|
-
};
|
|
195
|
-
for (let round = 0; round < 4; round++) {
|
|
196
|
-
const missing = /* @__PURE__ */ new Set();
|
|
197
|
-
result = await walk(hs, req, canSee, missing);
|
|
198
|
-
const wanted = [];
|
|
199
|
-
for (const id of missing) {
|
|
200
|
-
if (asked.has(id)) continue;
|
|
201
|
-
asked.add(id);
|
|
202
|
-
wanted.push(id === req.event_id ? req : {
|
|
203
|
-
...req,
|
|
204
|
-
event_id: id,
|
|
205
|
-
direction: "up",
|
|
206
|
-
include_parent: false,
|
|
207
|
-
include_children: false
|
|
208
|
-
});
|
|
174
|
+
r.post("/_matrix/client/unstable/event_relationships", procedure({
|
|
175
|
+
auth: "user",
|
|
176
|
+
input: body({}),
|
|
177
|
+
handler: async (ctx) => {
|
|
178
|
+
const s = ctx.session;
|
|
179
|
+
const hs = ctx.hs;
|
|
180
|
+
const req = parseRequest(ctx.input);
|
|
181
|
+
const roomOf = async () => req.room_id ?? (await hs.rooms.getPdu(req.event_id))?.room_id ?? null;
|
|
182
|
+
const roomId = await roomOf();
|
|
183
|
+
if (!roomId) throw errors.forbidden("Unknown event");
|
|
184
|
+
if (await hs.rooms.membership(roomId, s.userId) !== "join") {
|
|
185
|
+
if (getState(await hs.rooms.currentState(roomId), M.ROOM.HISTORY_VISIBILITY)?.content?.history_visibility !== "world_readable") throw errors.forbidden("You are not in this room");
|
|
209
186
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
187
|
+
const canSee = async (pdu) => {
|
|
188
|
+
if (pdu.room_id !== roomId) return false;
|
|
189
|
+
const ev = await hs.rooms.getEvent(pdu.event_id);
|
|
190
|
+
if (!ev) return true;
|
|
191
|
+
return (await hs.rooms.filterVisible(s.userId, roomId, [ev])).length > 0;
|
|
192
|
+
};
|
|
193
|
+
const asked = /* @__PURE__ */ new Set();
|
|
194
|
+
const remoteHashes = /* @__PURE__ */ new Map();
|
|
195
|
+
let result = {
|
|
196
|
+
events: [],
|
|
197
|
+
limited: false,
|
|
198
|
+
root: null
|
|
199
|
+
};
|
|
200
|
+
for (let round = 0; round < 4; round++) {
|
|
201
|
+
const missing = /* @__PURE__ */ new Set();
|
|
202
|
+
result = await walk(hs, req, canSee, missing);
|
|
203
|
+
const wanted = [];
|
|
204
|
+
for (const id of missing) {
|
|
205
|
+
if (asked.has(id)) continue;
|
|
206
|
+
asked.add(id);
|
|
207
|
+
wanted.push(id === req.event_id ? req : {
|
|
216
208
|
...req,
|
|
217
|
-
event_id:
|
|
218
|
-
direction: "
|
|
219
|
-
max_depth: 1,
|
|
209
|
+
event_id: id,
|
|
210
|
+
direction: "up",
|
|
220
211
|
include_parent: false,
|
|
221
212
|
include_children: false
|
|
222
213
|
});
|
|
223
214
|
}
|
|
215
|
+
for (const pdu of result.events) {
|
|
216
|
+
const remote = remoteHashes.get(pdu.event_id);
|
|
217
|
+
if (!remote || asked.has(`children:${pdu.event_id}`)) continue;
|
|
218
|
+
if (remote !== (await childrenSummary(hs, pdu.event_id)).children_hash) {
|
|
219
|
+
asked.add(`children:${pdu.event_id}`);
|
|
220
|
+
wanted.push({
|
|
221
|
+
...req,
|
|
222
|
+
event_id: pdu.event_id,
|
|
223
|
+
direction: "down",
|
|
224
|
+
max_depth: 1,
|
|
225
|
+
include_parent: false,
|
|
226
|
+
include_children: false
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!wanted.length) break;
|
|
231
|
+
for (const w of wanted) await fetchRemote(hs, roomId, w, remoteHashes);
|
|
224
232
|
}
|
|
225
|
-
if (!
|
|
226
|
-
|
|
233
|
+
if (!result.root) throw errors.notFound("Event not found");
|
|
234
|
+
const events = [];
|
|
235
|
+
for (const pdu of result.events) events.push(toClientEvent(await withChildren(hs, pdu)));
|
|
236
|
+
return {
|
|
237
|
+
events,
|
|
238
|
+
limited: result.limited,
|
|
239
|
+
next_batch: null
|
|
240
|
+
};
|
|
227
241
|
}
|
|
228
|
-
|
|
229
|
-
const events = [];
|
|
230
|
-
for (const pdu of result.events) events.push(toClientEvent(await withChildren(hs, pdu)));
|
|
231
|
-
return {
|
|
232
|
-
events,
|
|
233
|
-
limited: result.limited,
|
|
234
|
-
next_batch: null
|
|
235
|
-
};
|
|
236
|
-
});
|
|
242
|
+
}));
|
|
237
243
|
}
|
|
238
244
|
/** Server side of `/_matrix/federation/unstable/event_relationships`. */
|
|
239
245
|
async function relationshipsForServer(hs, origin, body, authChainOf) {
|