matrix-nodejs-homeserver 0.2.0 → 0.3.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.
Files changed (99) hide show
  1. package/README.md +89 -11
  2. package/dist/adapters/cluster.d.ts +1 -26
  3. package/dist/adapters/cluster.js +50 -103
  4. package/dist/api/account.js +407 -354
  5. package/dist/api/admin.js +82 -61
  6. package/dist/api/appservice.js +37 -25
  7. package/dist/api/backup.js +73 -62
  8. package/dist/api/federation.js +172 -138
  9. package/dist/api/filters.js +4 -3
  10. package/dist/api/legacy.js +91 -78
  11. package/dist/api/media.js +71 -55
  12. package/dist/api/misc.js +46 -37
  13. package/dist/api/preview.js +37 -73
  14. package/dist/api/profile.js +108 -97
  15. package/dist/api/push.js +114 -99
  16. package/dist/api/relationships.js +64 -58
  17. package/dist/api/rooms.js +703 -580
  18. package/dist/api/rtc.d.ts +0 -1
  19. package/dist/api/rtc.js +48 -34
  20. package/dist/api/search.js +133 -127
  21. package/dist/api/slidingsync.js +41 -31
  22. package/dist/api/spaces.js +82 -77
  23. package/dist/api/sync.js +325 -135
  24. package/dist/api/threadsubs.js +72 -61
  25. package/dist/api/threepid.js +99 -66
  26. package/dist/api/uia.js +17 -16
  27. package/dist/api/user.js +221 -178
  28. package/dist/core/admin.d.ts +0 -1
  29. package/dist/core/admin.js +6 -5
  30. package/dist/core/adminroom.js +9 -8
  31. package/dist/core/appservices.d.ts +2 -1
  32. package/dist/core/appservices.js +5 -4
  33. package/dist/core/audit.d.ts +0 -1
  34. package/dist/core/authrules.js +26 -25
  35. package/dist/core/cluster.d.ts +12 -5
  36. package/dist/core/cluster.js +46 -29
  37. package/dist/core/delayed.js +2 -1
  38. package/dist/core/events.js +11 -10
  39. package/dist/core/html.js +13 -0
  40. package/dist/core/identity.js +1 -1
  41. package/dist/core/invitefilter.js +2 -1
  42. package/dist/core/json.js +10 -1
  43. package/dist/core/keys.d.ts +10 -1
  44. package/dist/core/keys.js +62 -42
  45. package/dist/core/m.d.ts +209 -0
  46. package/dist/core/m.js +182 -0
  47. package/dist/core/outbound.d.ts +16 -0
  48. package/dist/core/outbound.js +172 -0
  49. package/dist/core/partialstate.js +2 -1
  50. package/dist/core/policy.js +4 -3
  51. package/dist/core/push.d.ts +0 -1
  52. package/dist/core/push.js +41 -28
  53. package/dist/core/pushrules.js +36 -35
  54. package/dist/core/ratelimit.d.ts +1 -1
  55. package/dist/core/rooms.d.ts +10 -1
  56. package/dist/core/rooms.js +101 -74
  57. package/dist/core/semaphore.js +23 -0
  58. package/dist/core/sso.d.ts +15 -1
  59. package/dist/core/sso.js +38 -2
  60. package/dist/core/stateres.js +7 -6
  61. package/dist/core/threepid.js +1 -9
  62. package/dist/federation/client.js +9 -1
  63. package/dist/federation/index.d.ts +2 -2
  64. package/dist/federation/index.js +43 -35
  65. package/dist/homeserver.d.ts +23 -4
  66. package/dist/homeserver.js +12 -3
  67. package/dist/http/handler.js +2 -23
  68. package/dist/http/input.js +2 -2
  69. package/dist/http/procedure.js +25 -0
  70. package/dist/http/router.d.ts +9 -26
  71. package/dist/http/router.js +10 -30
  72. package/dist/index.d.ts +4 -3
  73. package/dist/index.js +3 -2
  74. package/dist/storage/batch.js +11 -0
  75. package/dist/storage/memory.js +1 -0
  76. package/dist/storage/schema.js +1 -1
  77. package/dist/storage/sql.js +20 -1
  78. package/dist/storage/types.d.ts +16 -0
  79. package/dist/vendor/zod/LICENSE +21 -0
  80. package/dist/vendor/zod/v4/classic/errors.js +54 -0
  81. package/dist/vendor/zod/v4/classic/parse.js +17 -0
  82. package/dist/vendor/zod/v4/classic/schemas.js +865 -0
  83. package/dist/vendor/zod/v4/core/api.js +512 -0
  84. package/dist/vendor/zod/v4/core/checks.js +300 -0
  85. package/dist/vendor/zod/v4/core/core.js +109 -0
  86. package/dist/vendor/zod/v4/core/doc.js +35 -0
  87. package/dist/vendor/zod/v4/core/errors.js +118 -0
  88. package/dist/vendor/zod/v4/core/json-schema-processors.js +428 -0
  89. package/dist/vendor/zod/v4/core/memoizer.js +255 -0
  90. package/dist/vendor/zod/v4/core/parse.js +206 -0
  91. package/dist/vendor/zod/v4/core/regexes.js +73 -0
  92. package/dist/vendor/zod/v4/core/registries.js +48 -0
  93. package/dist/vendor/zod/v4/core/schemas.js +1378 -0
  94. package/dist/vendor/zod/v4/core/to-json-schema.js +448 -0
  95. package/dist/vendor/zod/v4/core/util.js +537 -0
  96. package/dist/vendor/zod/v4/core/versions.js +8 -0
  97. package/dist/vendor/zod/v4/locales/en.js +110 -0
  98. package/package.json +8 -6
  99. 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?.["m.relationship"];
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", { input: body({}) }, async (ctx) => {
173
- const s = await ctx.auth();
174
- const hs = ctx.hs;
175
- const req = parseRequest(ctx.input);
176
- const roomOf = async () => req.room_id ?? (await hs.rooms.getPdu(req.event_id))?.room_id ?? null;
177
- const roomId = await roomOf();
178
- if (!roomId) throw errors.forbidden("Unknown event");
179
- if (await hs.rooms.membership(roomId, s.userId) !== "join") {
180
- 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");
181
- }
182
- const canSee = async (pdu) => {
183
- if (pdu.room_id !== roomId) return false;
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
- for (const pdu of result.events) {
211
- const remote = remoteHashes.get(pdu.event_id);
212
- if (!remote || asked.has(`children:${pdu.event_id}`)) continue;
213
- if (remote !== (await childrenSummary(hs, pdu.event_id)).children_hash) {
214
- asked.add(`children:${pdu.event_id}`);
215
- wanted.push({
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: pdu.event_id,
218
- direction: "down",
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 (!wanted.length) break;
226
- for (const w of wanted) await fetchRemote(hs, roomId, w, remoteHashes);
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
- if (!result.root) throw errors.notFound("Event not found");
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) {