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/dist/core/policy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { publicKeyFromBase64, verifyJsonSignature } from "./crypto.js";
|
|
2
|
+
import { M } from "./m.js";
|
|
2
3
|
import { redact } from "./events.js";
|
|
3
4
|
import { MatrixError } from "./errors.js";
|
|
4
5
|
import { getState } from "./authrules.js";
|
|
@@ -13,7 +14,7 @@ var PolicyServers = class {
|
|
|
13
14
|
/** The room's policy server, if the room uses one (valid `m.room.policy` and a joined user on `via`). */
|
|
14
15
|
async policyOf(roomId) {
|
|
15
16
|
const state = await this.hs.rooms.currentState(roomId);
|
|
16
|
-
const content = getState(state,
|
|
17
|
+
const content = getState(state, M.ROOM.POLICY, "")?.content;
|
|
17
18
|
const via = content?.via;
|
|
18
19
|
const ed25519 = content?.public_keys?.ed25519;
|
|
19
20
|
if (typeof via !== "string" || typeof ed25519 !== "string") return null;
|
|
@@ -23,7 +24,7 @@ var PolicyServers = class {
|
|
|
23
24
|
} catch {
|
|
24
25
|
return null;
|
|
25
26
|
}
|
|
26
|
-
for (const ev of state.values()) if (ev.type ===
|
|
27
|
+
for (const ev of state.values()) if (ev.type === M.ROOM.MEMBER && ev.content?.membership === "join" && typeof ev.state_key === "string" && domainOf(ev.state_key) === via) return {
|
|
27
28
|
via,
|
|
28
29
|
key
|
|
29
30
|
};
|
|
@@ -31,7 +32,7 @@ var PolicyServers = class {
|
|
|
31
32
|
}
|
|
32
33
|
/** The policy state event itself is never sent to the policy server. */
|
|
33
34
|
exempt(pdu) {
|
|
34
|
-
return pdu.type ===
|
|
35
|
+
return pdu.type === M.ROOM.POLICY && pdu.state_key === "";
|
|
35
36
|
}
|
|
36
37
|
validSignature(pdu, version, policy) {
|
|
37
38
|
const wire = this.hs.federation.toFederationPdu(pdu, version);
|
package/dist/core/push.d.ts
CHANGED
package/dist/core/push.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isObject } from "./json.js";
|
|
2
|
+
import { M, UNSTABLE } from "./m.js";
|
|
2
3
|
import { splitStateKey, toClientEvent } from "./events.js";
|
|
3
4
|
import { getState, powerLevels, userLevel } from "./authrules.js";
|
|
4
5
|
import { globMatch, globSearchWords } from "./glob.js";
|
|
@@ -47,7 +48,7 @@ function conditionMatches(cond, ctx) {
|
|
|
47
48
|
}
|
|
48
49
|
return false;
|
|
49
50
|
}
|
|
50
|
-
case
|
|
51
|
+
case UNSTABLE.IO.ELEMENT.MSC4306.THREAD_SUBSCRIPTION: return ctx.threadSubscribed !== void 0 && ctx.threadSubscribed !== null && ctx.threadSubscribed === cond.subscribed;
|
|
51
52
|
case "sender_notification_permission": return typeof cond.key === "string" && ctx.senderLevel >= (ctx.notificationLevels[cond.key] ?? 50);
|
|
52
53
|
default: return false;
|
|
53
54
|
}
|
|
@@ -80,8 +81,8 @@ function tweaksOf(actions) {
|
|
|
80
81
|
}
|
|
81
82
|
/** Thread an event belongs to for notification purposes ("main" for the main timeline). */
|
|
82
83
|
function threadIdOf(event) {
|
|
83
|
-
const rel = event.content?.[
|
|
84
|
-
return isObject(rel) && rel.rel_type ===
|
|
84
|
+
const rel = event.content?.[M.RELATES_TO];
|
|
85
|
+
return isObject(rel) && rel.rel_type === M.THREAD && typeof rel.event_id === "string" ? rel.event_id : "main";
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
88
|
* Push rule evaluation and push gateway delivery. Every new event is evaluated for
|
|
@@ -97,11 +98,11 @@ var PushService = class {
|
|
|
97
98
|
const members = [];
|
|
98
99
|
for (const [key, member] of state) {
|
|
99
100
|
const [type, userId] = splitStateKey(key);
|
|
100
|
-
if (type !==
|
|
101
|
+
if (type !== M.ROOM.MEMBER) continue;
|
|
101
102
|
const m = member.content?.membership;
|
|
102
|
-
if (m === "join" || m === "invite" && event.type ===
|
|
103
|
+
if (m === "join" || m === "invite" && event.type === M.ROOM.MEMBER && event.state_key === userId) members.push(userId);
|
|
103
104
|
}
|
|
104
|
-
const joined = members.filter((u) => getState(state,
|
|
105
|
+
const joined = members.filter((u) => getState(state, M.ROOM.MEMBER, u)?.content?.membership === "join");
|
|
105
106
|
const pl = powerLevels(state, version);
|
|
106
107
|
const senderLevel = userLevel(pl, event.sender);
|
|
107
108
|
const thread = threadIdOf(event);
|
|
@@ -110,7 +111,7 @@ var PushService = class {
|
|
|
110
111
|
const actions = evaluateRules(await loadRules(this.hs, userId), {
|
|
111
112
|
event,
|
|
112
113
|
userId,
|
|
113
|
-
displayName: getState(state,
|
|
114
|
+
displayName: getState(state, M.ROOM.MEMBER, userId)?.content?.displayname ?? null,
|
|
114
115
|
memberCount: joined.length,
|
|
115
116
|
senderLevel: Number.isFinite(senderLevel) ? senderLevel : Number.MAX_SAFE_INTEGER,
|
|
116
117
|
notificationLevels: pl.notifications,
|
|
@@ -144,7 +145,7 @@ var PushService = class {
|
|
|
144
145
|
let unthreaded = 0;
|
|
145
146
|
const threadRead = /* @__PURE__ */ new Map();
|
|
146
147
|
for (const r of receipts) {
|
|
147
|
-
if (r.receipt_type !==
|
|
148
|
+
if (r.receipt_type !== M.READ._ && r.receipt_type !== M.READ.PRIVATE) continue;
|
|
148
149
|
const target = await this.hs.rooms.getEvent(r.event_id);
|
|
149
150
|
if (!target) continue;
|
|
150
151
|
if (r.thread_id === "") unthreaded = Math.max(unthreaded, target.stream);
|
|
@@ -224,11 +225,11 @@ var PushService = class {
|
|
|
224
225
|
notification.type = event.type;
|
|
225
226
|
notification.sender = event.sender;
|
|
226
227
|
notification.content = event.content;
|
|
227
|
-
const name = getState(state,
|
|
228
|
+
const name = getState(state, M.ROOM.NAME)?.content?.name;
|
|
228
229
|
if (typeof name === "string") notification.room_name = name;
|
|
229
|
-
const senderName = getState(state,
|
|
230
|
+
const senderName = getState(state, M.ROOM.MEMBER, event.sender)?.content?.displayname;
|
|
230
231
|
if (typeof senderName === "string") notification.sender_display_name = senderName;
|
|
231
|
-
if (event.type ===
|
|
232
|
+
if (event.type === M.ROOM.MEMBER) {
|
|
232
233
|
notification.membership = event.content?.membership;
|
|
233
234
|
notification.user_is_target = event.state_key === userId;
|
|
234
235
|
}
|
package/dist/core/pushrules.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isObject } from "./json.js";
|
|
2
|
+
import { M, UNSTABLE } from "./m.js";
|
|
2
3
|
//#region src/core/pushrules.ts
|
|
3
4
|
const KINDS = [
|
|
4
5
|
"override",
|
|
@@ -36,15 +37,15 @@ function defaultRules(userId) {
|
|
|
36
37
|
});
|
|
37
38
|
return {
|
|
38
39
|
override: [
|
|
39
|
-
r(
|
|
40
|
-
r(
|
|
41
|
-
r(
|
|
42
|
-
em("type",
|
|
40
|
+
r(M.RULE.MASTER, [], [], { enabled: false }),
|
|
41
|
+
r(M.RULE.SUPPRESS_NOTICES, [em("content.msgtype", M.NOTICE)], []),
|
|
42
|
+
r(M.RULE.INVITE_FOR_ME, [
|
|
43
|
+
em("type", M.ROOM.MEMBER),
|
|
43
44
|
em("content.membership", "invite"),
|
|
44
45
|
em("state_key", userId)
|
|
45
46
|
], [...notify, sound("default")]),
|
|
46
|
-
r(
|
|
47
|
-
r(
|
|
47
|
+
r(M.RULE.MEMBER_EVENT, [em("type", M.ROOM.MEMBER)], []),
|
|
48
|
+
r(M.RULE.IS_USER_MENTION, [{
|
|
48
49
|
kind: "event_property_contains",
|
|
49
50
|
key: "content.m\\.mentions.user_ids",
|
|
50
51
|
value: userId
|
|
@@ -53,61 +54,61 @@ function defaultRules(userId) {
|
|
|
53
54
|
sound("default"),
|
|
54
55
|
highlight
|
|
55
56
|
]),
|
|
56
|
-
r(
|
|
57
|
+
r(M.RULE.CONTAINS_DISPLAY_NAME, [{ kind: "contains_display_name" }], [
|
|
57
58
|
...notify,
|
|
58
59
|
sound("default"),
|
|
59
60
|
highlight
|
|
60
61
|
]),
|
|
61
|
-
r(
|
|
62
|
+
r(M.RULE.IS_ROOM_MENTION, [ep("content.m\\.mentions.room", true), {
|
|
62
63
|
kind: "sender_notification_permission",
|
|
63
64
|
key: "room"
|
|
64
65
|
}], [...notify, highlight]),
|
|
65
|
-
r(
|
|
66
|
+
r(M.RULE.ROOMNOTIF, [em("content.body", "@room"), {
|
|
66
67
|
kind: "sender_notification_permission",
|
|
67
68
|
key: "room"
|
|
68
69
|
}], [...notify, highlight]),
|
|
69
|
-
r(
|
|
70
|
-
r(
|
|
71
|
-
r(
|
|
72
|
-
r(
|
|
73
|
-
r(
|
|
70
|
+
r(M.RULE.TOMBSTONE, [em("type", M.ROOM.TOMBSTONE), em("state_key", "")], [...notify, highlight]),
|
|
71
|
+
r(M.RULE.REACTION, [em("type", M.REACTION)], []),
|
|
72
|
+
r(M.RULE.ROOM.SERVER_ACL, [em("type", M.ROOM.SERVER_ACL), em("state_key", "")], []),
|
|
73
|
+
r(M.RULE.SUPPRESS_EDITS, [ep("content.m\\.relates_to.rel_type", M.REPLACE)], []),
|
|
74
|
+
r(UNSTABLE.ORG.MATRIX.MSC3930.RULE.POLL_RESPONSE, [em("type", UNSTABLE.ORG.MATRIX.MSC3381.POLL.RESPONSE)], [])
|
|
74
75
|
],
|
|
75
|
-
content: [r(
|
|
76
|
+
content: [r(M.RULE.CONTAINS_USER_NAME, void 0, [
|
|
76
77
|
...notify,
|
|
77
78
|
sound("default"),
|
|
78
79
|
highlight
|
|
79
80
|
], { pattern: localpart })],
|
|
80
|
-
postcontent: [r(
|
|
81
|
-
kind:
|
|
81
|
+
postcontent: [r(UNSTABLE.IO.ELEMENT.MSC4306.RULE.UNSUBSCRIBED_THREAD, [{
|
|
82
|
+
kind: UNSTABLE.IO.ELEMENT.MSC4306.THREAD_SUBSCRIPTION,
|
|
82
83
|
subscribed: false
|
|
83
|
-
}], []), r(
|
|
84
|
-
kind:
|
|
84
|
+
}], []), r(UNSTABLE.IO.ELEMENT.MSC4306.RULE.SUBSCRIBED_THREAD, [{
|
|
85
|
+
kind: UNSTABLE.IO.ELEMENT.MSC4306.THREAD_SUBSCRIPTION,
|
|
85
86
|
subscribed: true
|
|
86
87
|
}], [...notify, sound("default")])],
|
|
87
88
|
room: [],
|
|
88
89
|
sender: [],
|
|
89
90
|
underride: [
|
|
90
|
-
r(
|
|
91
|
-
r(
|
|
91
|
+
r(M.RULE.CALL, [em("type", M.CALL.INVITE)], [...notify, sound("ring")]),
|
|
92
|
+
r(M.RULE.ENCRYPTED_ROOM_ONE_TO_ONE, [{
|
|
92
93
|
kind: "room_member_count",
|
|
93
94
|
is: "2"
|
|
94
|
-
}, em("type",
|
|
95
|
-
r(
|
|
95
|
+
}, em("type", M.ROOM.ENCRYPTED)], [...notify, sound("default")]),
|
|
96
|
+
r(M.RULE.ROOM_ONE_TO_ONE, [{
|
|
96
97
|
kind: "room_member_count",
|
|
97
98
|
is: "2"
|
|
98
|
-
}, em("type",
|
|
99
|
-
r(
|
|
100
|
-
r(
|
|
99
|
+
}, em("type", M.ROOM.MESSAGE)], [...notify, sound("default")]),
|
|
100
|
+
r(M.RULE.MESSAGE, [em("type", M.ROOM.MESSAGE)], notify),
|
|
101
|
+
r(UNSTABLE.ORG.MATRIX.MSC3930.RULE.POLL_START_ONE_TO_ONE, [{
|
|
101
102
|
kind: "room_member_count",
|
|
102
103
|
is: "2"
|
|
103
|
-
}, em("type",
|
|
104
|
-
r(
|
|
104
|
+
}, em("type", UNSTABLE.ORG.MATRIX.MSC3381.POLL.START)], [...notify, sound("default")]),
|
|
105
|
+
r(UNSTABLE.ORG.MATRIX.MSC3930.RULE.POLL_END_ONE_TO_ONE, [{
|
|
105
106
|
kind: "room_member_count",
|
|
106
107
|
is: "2"
|
|
107
|
-
}, em("type",
|
|
108
|
-
r(
|
|
109
|
-
r(
|
|
110
|
-
r(
|
|
108
|
+
}, em("type", UNSTABLE.ORG.MATRIX.MSC3381.POLL.END)], [...notify, sound("default")]),
|
|
109
|
+
r(UNSTABLE.ORG.MATRIX.MSC3930.RULE.POLL_START, [em("type", UNSTABLE.ORG.MATRIX.MSC3381.POLL.START)], notify),
|
|
110
|
+
r(UNSTABLE.ORG.MATRIX.MSC3930.RULE.POLL_END, [em("type", UNSTABLE.ORG.MATRIX.MSC3381.POLL.END)], notify),
|
|
111
|
+
r(M.RULE.ENCRYPTED, [em("type", M.ROOM.ENCRYPTED)], notify)
|
|
111
112
|
]
|
|
112
113
|
};
|
|
113
114
|
}
|
|
@@ -151,7 +152,7 @@ async function readRules(hs, userId) {
|
|
|
151
152
|
},
|
|
152
153
|
{
|
|
153
154
|
field: "type",
|
|
154
|
-
value:
|
|
155
|
+
value: M.PUSH_RULES
|
|
155
156
|
}
|
|
156
157
|
]);
|
|
157
158
|
if (!isObject(row?.content?.global)) return defaultRules(userId);
|
|
@@ -169,7 +170,7 @@ async function saveRules(hs, userId, rules) {
|
|
|
169
170
|
await hs.streams.write((stream) => hs.db.upsert("account_data", {
|
|
170
171
|
user_id: userId,
|
|
171
172
|
room_id: "",
|
|
172
|
-
type:
|
|
173
|
+
type: M.PUSH_RULES,
|
|
173
174
|
content: { global: rules },
|
|
174
175
|
stream
|
|
175
176
|
}));
|
|
@@ -191,7 +192,7 @@ async function copyRules(hs, userId, oldRoomId, newRoomId) {
|
|
|
191
192
|
},
|
|
192
193
|
{
|
|
193
194
|
field: "type",
|
|
194
|
-
value:
|
|
195
|
+
value: M.PUSH_RULES
|
|
195
196
|
}
|
|
196
197
|
]);
|
|
197
198
|
if (!isObject(row?.content?.global)) return;
|