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
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ tied to any HTTP framework, database, auth system or deployment shape. You can u
|
|
|
5
5
|
it for a demo on SQLite, embed it in a monolith next to your existing users, or run
|
|
6
6
|
it as a horizontally scaled chat backend that replaces Slack or Teams.
|
|
7
7
|
|
|
8
|
-
- Node.js **26+**. TypeScript with only erasable syntax (`erasableSyntaxOnly`)
|
|
8
|
+
- Node.js **26+**. TypeScript with only erasable syntax (`erasableSyntaxOnly`), and no runtime dependencies ([zod](https://zod.dev), used for request validation, is bundled).
|
|
9
9
|
- Client-Server API, Server-Server API (federation), end-to-end encryption, sliding sync, VoIP/MatrixRTC and push
|
|
10
10
|
- Runs on `node:http`, Express, Fastify, Hono or any fetch runtime
|
|
11
11
|
- Stores data in SQLite, PostgreSQL, MySQL, memory or your own adapter
|
|
@@ -139,8 +139,10 @@ createHomeserver({
|
|
|
139
139
|
|
|
140
140
|
## Federation
|
|
141
141
|
|
|
142
|
-
Federation is
|
|
143
|
-
|
|
142
|
+
Federation is **off by default**, so a server only joins the Matrix network on purpose.
|
|
143
|
+
Turn it on with `federation: { enabled: true }`. It then needs no configuration beyond a
|
|
144
|
+
reachable port 8448, or `.well-known/matrix/server` delegation (`federationAddress`). The
|
|
145
|
+
implementation includes:
|
|
144
146
|
|
|
145
147
|
- Server discovery (`.well-known` and SRV) and signed requests
|
|
146
148
|
- A persistent outbound queue with retries
|
|
@@ -155,7 +157,8 @@ Federation is on by default and needs no configuration beyond a reachable port
|
|
|
155
157
|
federation: { enabled: true, allowedServers: ["partner.org"], blockedServers: ["spam.example"] },
|
|
156
158
|
```
|
|
157
159
|
|
|
158
|
-
|
|
160
|
+
Without federation, local users can only talk to each other: federation endpoints answer
|
|
161
|
+
`M_UNRECOGNIZED`, and remote users, rooms and media cannot be reached.
|
|
159
162
|
|
|
160
163
|
## VoIP and MatrixRTC
|
|
161
164
|
|
|
@@ -302,9 +305,14 @@ await hs.admin.createUser("alice", { password: "…", admin: true });
|
|
|
302
305
|
await hs.admin.createRegistrationToken({ usesAllowed: 10 });
|
|
303
306
|
await hs.admin.deactivateUser("@spammer:example.com");
|
|
304
307
|
await hs.admin.deleteRoom(roomId, { purge: true });
|
|
305
|
-
await hs.admin.sendServerNotice("@alice:example.com", { msgtype:
|
|
308
|
+
await hs.admin.sendServerNotice("@alice:example.com", { msgtype: M.TEXT, body: "Maintenance tonight" });
|
|
306
309
|
```
|
|
307
310
|
|
|
311
|
+
`M` (exported from the package) holds the Matrix identifiers as one readonly object:
|
|
312
|
+
`M.ROOM.MEMBER` is `"m.room.member"`, `M.LOGIN.PASSWORD` is `"m.login.password"`.
|
|
313
|
+
`UNSTABLE` does the same for unstable and vendor identifiers:
|
|
314
|
+
`UNSTABLE.ORG.MATRIX.CROSS_SIGNING_RESET` is `"org.matrix.cross_signing_reset"`.
|
|
315
|
+
|
|
308
316
|
The same operations are available over HTTP at Synapse-compatible `/_synapse/admin/…`
|
|
309
317
|
paths (server admins only), so existing tools keep working.
|
|
310
318
|
|
|
@@ -319,7 +327,7 @@ paths (server admins only), so existing tools keep working.
|
|
|
319
327
|
| `audit` | `{ enabled, database, sink, actions, retentionDays }`. Disabled by default. |
|
|
320
328
|
| `publicBaseUrl` | Advertised via `/.well-known/matrix/client`. Required for SSO. |
|
|
321
329
|
| `oauth`, `sso` | Delegated OAuth or upstream OIDC SSO. |
|
|
322
|
-
| `federation` | `{ enabled, verifyTls, allowedServers, blockedServers }` |
|
|
330
|
+
| `federation` | `{ enabled, verifyTls, allowedServers, blockedServers, fasterJoins }`. Off unless `enabled: true`. |
|
|
323
331
|
| `rtc` | `{ turn, transports }` |
|
|
324
332
|
| `delayedEvents` | `{ maxDelayMs, maxPerUser }` |
|
|
325
333
|
| `rateLimits` | `false`, or `{ limiter, rules }`. In-memory token buckets by default. Plug in a shared limiter when running a cluster. |
|
|
@@ -363,12 +371,26 @@ npm run build # tsdown → dist/ (what the published package
|
|
|
363
371
|
node examples/node-http.ts # development runs the TypeScript sources directly (type stripping)
|
|
364
372
|
```
|
|
365
373
|
|
|
374
|
+
Endpoints are procedures (`src/http/procedure.ts`): a route declares what it needs and a
|
|
375
|
+
handler, and the procedure checks the request in a fixed order (authentication, rate limit,
|
|
376
|
+
body, then the response) before and after the handler runs:
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
r.client("POST", "/rooms/:roomId/invite", procedure({
|
|
380
|
+
auth: "user", // ctx.session (or "optional", "none")
|
|
381
|
+
rateLimit: "invite",
|
|
382
|
+
input: body({ user_id: lenient(z.string()), reason: lenient(z.string()) }), // ctx.input
|
|
383
|
+
handler: async (ctx) => { /* ctx.hs, ctx.session, ctx.input, ctx.params */ },
|
|
384
|
+
}));
|
|
385
|
+
```
|
|
386
|
+
|
|
366
387
|
Inside `src`, modules import each other through the package's
|
|
367
388
|
[subpath imports](https://nodejs.org/api/packages.html#subpath-imports): `#core/errors.ts` is
|
|
368
389
|
`src/core/errors.ts`. The build turns them back into relative imports.
|
|
369
390
|
|
|
370
391
|
Node does not strip types from files inside `node_modules`, so the package ships `dist/`,
|
|
371
|
-
built by tsdown: one `.js` and one `.d.ts` per source module
|
|
392
|
+
built by tsdown: one `.js` and one `.d.ts` per source module, with zod bundled under
|
|
393
|
+
`dist/vendor/`. `npm pack`, `npm publish` and
|
|
372
394
|
installs from GitHub build it through the `prepare` script. Recent npm versions ask you to
|
|
373
395
|
approve install scripts of git dependencies (`npm install-scripts approve`).
|
|
374
396
|
|