@wtfalch/chat 0.8.0 → 0.10.0
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 +32 -5
- package/dist/chat/admin/index.js +11 -2
- package/dist/chat/client.d.ts +13 -0
- package/dist/chat/client.js +333 -8
- package/dist/chat/exchange.js +10 -1
- package/dist/chat/index.d.ts +2 -2
- package/dist/chat/index.js +1 -1
- package/dist/chat/types.d.ts +61 -2
- package/package.json +3 -7
- package/dist/chat/fake/index.d.ts +0 -27
- package/dist/chat/fake/index.js +0 -48
- package/dist/chat/fake/intercept.d.ts +0 -21
- package/dist/chat/fake/intercept.js +0 -57
- package/dist/chat/fake/sample.d.ts +0 -4
- package/dist/chat/fake/sample.js +0 -6
- package/dist/chat/fake/server.d.ts +0 -355
- package/dist/chat/fake/server.js +0 -1739
- package/dist/chat/fake/xhr.d.ts +0 -3
- package/dist/chat/fake/xhr.js +0 -104
package/dist/chat/types.d.ts
CHANGED
|
@@ -109,6 +109,33 @@ export type ChatRoomSummary = {
|
|
|
109
109
|
* `m.favourite` room tag, synced across every device on the account
|
|
110
110
|
* the same way `hideDirectMessage`'s tag is (agora#27). */
|
|
111
111
|
readonly starred: boolean;
|
|
112
|
+
/** The room's `m.room.topic`, as plain text: trimmed and capped (see
|
|
113
|
+
* `normaliseTopic`), because a topic is whatever its setter wrote.
|
|
114
|
+
* Absent when the room has none. */
|
|
115
|
+
readonly topic?: string;
|
|
116
|
+
/** Whether the signed-in person's power level lets them change this
|
|
117
|
+
* room's topic with `setRoomTopic`. A list or room header shows its
|
|
118
|
+
* edit control off this instead of letting the write fail. */
|
|
119
|
+
readonly canSetTopic: boolean;
|
|
120
|
+
};
|
|
121
|
+
/** A room of this company the person is not in yet and may join: a child
|
|
122
|
+
* of the company space with a `public` or `restricted` join rule. Name and
|
|
123
|
+
* topic are plain text, normalised like `ChatRoomSummary.topic`. */
|
|
124
|
+
export type ChatBrowsableRoom = {
|
|
125
|
+
readonly id: string;
|
|
126
|
+
readonly name: string;
|
|
127
|
+
readonly topic?: string;
|
|
128
|
+
/** Joined members, as the homeserver counts them. */
|
|
129
|
+
readonly memberCount: number;
|
|
130
|
+
};
|
|
131
|
+
/** What `createRoom` takes. */
|
|
132
|
+
export type ChatNewRoom = {
|
|
133
|
+
/** Trimmed; must not be empty. */
|
|
134
|
+
name: string;
|
|
135
|
+
topic?: string;
|
|
136
|
+
/** `public`: any member of the company may find and join it (the admin
|
|
137
|
+
* API's own word for it). `private`: invite only. */
|
|
138
|
+
visibility: 'public' | 'private';
|
|
112
139
|
};
|
|
113
140
|
/** Someone this person can start a direct message with: a member of the
|
|
114
141
|
* company space, or a guest sharing a room with them (docs/guests.md,
|
|
@@ -340,8 +367,11 @@ export type ChatClient = {
|
|
|
340
367
|
* it again while already started is a no-op. */
|
|
341
368
|
start: () => Promise<void>;
|
|
342
369
|
/** Stops syncing and releases the underlying Matrix client. Safe to call
|
|
343
|
-
* more than once, and before `start()` ever resolves.
|
|
344
|
-
|
|
370
|
+
* more than once, and before `start()` ever resolves. The state change is
|
|
371
|
+
* immediate; the promise settles once any in-flight store startup has
|
|
372
|
+
* finished and the store is destroyed. It never rejects. A `start()` that
|
|
373
|
+
* this overtakes rejects with `ChatStartCancelledError`. */
|
|
374
|
+
stop: () => Promise<void>;
|
|
345
375
|
/** The rooms the person is currently in. Empty before `start()` resolves. */
|
|
346
376
|
rooms: () => ChatRoomSummary[];
|
|
347
377
|
/** Called with the current room list whenever it changes. Returns a
|
|
@@ -804,6 +834,35 @@ export type ChatClient = {
|
|
|
804
834
|
* safe against another client writing to the same room's pinned list
|
|
805
835
|
* at once. */
|
|
806
836
|
unpinMessage: (roomId: string, eventId: string) => Promise<void>;
|
|
837
|
+
/** Sets `roomId`'s topic. `topic` is trimmed and capped to
|
|
838
|
+
* `MAX_TOPIC_LENGTH` characters, control characters removed; an empty
|
|
839
|
+
* result clears the topic. Rejects, with nothing sent, when the room is
|
|
840
|
+
* unknown or this person's power level cannot send `m.room.topic`
|
|
841
|
+
* (`ChatRoomSummary.canSetTopic` is false). The homeserver stays the
|
|
842
|
+
* authority: a refusal from it rejects too. */
|
|
843
|
+
setRoomTopic: (roomId: string, topic: string) => Promise<void>;
|
|
844
|
+
/** Creates a company channel and resolves with its room id once it is in
|
|
845
|
+
* `rooms()`. Goes through `apps/chat-service` (`POST /_chat/rooms`),
|
|
846
|
+
* because the homeserver refuses a named room from a member; the
|
|
847
|
+
* service applies the admin API's rules (join rule, power levels,
|
|
848
|
+
* encryption default, the link to the company space) and makes the
|
|
849
|
+
* creator an admin (power level 100) of the new room. `name` is trimmed
|
|
850
|
+
* and must be non-empty and at most `MAX_ROOM_NAME_LENGTH` characters;
|
|
851
|
+
* `topic` is normalised and capped like `setRoomTopic`'s. Rejects, with
|
|
852
|
+
* nothing made, on a bad name or visibility, or when the service
|
|
853
|
+
* refuses. */
|
|
854
|
+
createRoom: (input: ChatNewRoom) => Promise<string>;
|
|
855
|
+
/** The company's rooms this person is not in and may join, name order:
|
|
856
|
+
* the children of the company space (the joined `m.space` on this
|
|
857
|
+
* homeserver) whose join rule is `public` or `restricted`, minus rooms
|
|
858
|
+
* already joined or invited, minus rooms hosted on another server and
|
|
859
|
+
* minus sub-spaces. A room federated in from elsewhere never appears,
|
|
860
|
+
* whatever the space lists. Empty before `start()` resolves. */
|
|
861
|
+
browseRooms: () => Promise<ChatBrowsableRoom[]>;
|
|
862
|
+
/** Joins one room `browseRooms` lists. Rejects for any other room id,
|
|
863
|
+
* without calling the homeserver's join -- this is not a way to join
|
|
864
|
+
* an arbitrary room. */
|
|
865
|
+
joinBrowsableRoom: (roomId: string) => Promise<void>;
|
|
807
866
|
/** `roomId`'s currently pinned messages, in the order `m.room.pinned_
|
|
808
867
|
* events` lists them, each reduced the same way `timeline()` reduces a
|
|
809
868
|
* message. A pinned id this client cannot find an event for -- paginated
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtfalch/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A Matrix chat client behind the agora's token exchange.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,10 +21,6 @@
|
|
|
21
21
|
"types": "./dist/chat/react/index.d.ts",
|
|
22
22
|
"default": "./dist/chat/react/index.js"
|
|
23
23
|
},
|
|
24
|
-
"./fake": {
|
|
25
|
-
"types": "./dist/chat/fake/index.d.ts",
|
|
26
|
-
"default": "./dist/chat/fake/index.js"
|
|
27
|
-
},
|
|
28
24
|
"./chat.css": "./dist/chat/chat.css",
|
|
29
25
|
"./package.json": "./package.json",
|
|
30
26
|
"./admin": {
|
|
@@ -48,7 +44,7 @@
|
|
|
48
44
|
"test:acceptance": "vitest run --config vitest.acceptance.config.ts"
|
|
49
45
|
},
|
|
50
46
|
"peerDependencies": {
|
|
51
|
-
"@wtfalch/design": ">=0.
|
|
47
|
+
"@wtfalch/design": ">=0.30.0 <0.32.0",
|
|
52
48
|
"react": "^19.0.0",
|
|
53
49
|
"react-dom": "^19.0.0"
|
|
54
50
|
},
|
|
@@ -69,7 +65,7 @@
|
|
|
69
65
|
"@types/node": "22.20.2",
|
|
70
66
|
"@types/react": "19.3.0",
|
|
71
67
|
"@types/react-dom": "19.3.0",
|
|
72
|
-
"@wtfalch/design": "0.
|
|
68
|
+
"@wtfalch/design": "0.31.0",
|
|
73
69
|
"fake-indexeddb": "6.2.5",
|
|
74
70
|
"jsdom": "30.0.1",
|
|
75
71
|
"react": "19.2.4",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ChatClient } from '../types.ts';
|
|
2
|
-
import { FakeChatServer, type FakeChatServerOptions } from './server.ts';
|
|
3
|
-
export { FakeChatServer } from './server.ts';
|
|
4
|
-
export type { FakeChatServerOptions, FakeMember, FakeMessageSeed, FakeRoomSeed, } from './server.ts';
|
|
5
|
-
export { SAMPLE_ROOMS } from './sample.ts';
|
|
6
|
-
export type FakeChatOptions = FakeChatServerOptions & {
|
|
7
|
-
storeName?: string;
|
|
8
|
-
deviceId?: string;
|
|
9
|
-
};
|
|
10
|
-
export type FakeChat = {
|
|
11
|
-
/** A real `ChatClient`. Everything this package exports works against it
|
|
12
|
-
* unchanged, through the real `createChatClient`. */
|
|
13
|
-
client: ChatClient;
|
|
14
|
-
/** The homeserver behind it, to drive more rooms or a token refusal, or
|
|
15
|
-
* to assert on how many times the exchange was called. */
|
|
16
|
-
server: FakeChatServer;
|
|
17
|
-
/** Stops the client and uninstalls the fake. Call it when a story or a
|
|
18
|
-
* test is done. */
|
|
19
|
-
dispose: () => void;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* A client and the fake exchange/homeserver behind it.
|
|
23
|
-
*
|
|
24
|
-
* Seeded with `SAMPLE_ROOMS` unless told otherwise, because a fake with no
|
|
25
|
-
* rooms demonstrates the empty state and nothing else.
|
|
26
|
-
*/
|
|
27
|
-
export declare function fakeChat(options?: FakeChatOptions): FakeChat;
|
package/dist/chat/fake/index.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@wtfalch/chat/fake` -- a real `createChatClient`, wired to a
|
|
3
|
-
* fake exchange and a fake homeserver instead of the network, for stories
|
|
4
|
-
* and tests. See `server.ts`'s module comment for why it fakes the
|
|
5
|
-
* transport rather than the client.
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { fakeChat } from '@wtfalch/chat/fake'
|
|
9
|
-
*
|
|
10
|
-
* const { client, dispose } = fakeChat()
|
|
11
|
-
* await client.start()
|
|
12
|
-
* client.rooms() // SAMPLE_ROOMS, joined
|
|
13
|
-
* dispose()
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
import { createChatClient } from "../client.js";
|
|
17
|
-
import { SAMPLE_ROOMS } from "./sample.js";
|
|
18
|
-
import { FakeChatServer } from "./server.js";
|
|
19
|
-
export { FakeChatServer } from "./server.js";
|
|
20
|
-
export { SAMPLE_ROOMS } from "./sample.js";
|
|
21
|
-
/**
|
|
22
|
-
* A client and the fake exchange/homeserver behind it.
|
|
23
|
-
*
|
|
24
|
-
* Seeded with `SAMPLE_ROOMS` unless told otherwise, because a fake with no
|
|
25
|
-
* rooms demonstrates the empty state and nothing else.
|
|
26
|
-
*/
|
|
27
|
-
export function fakeChat(options = {}) {
|
|
28
|
-
const { storeName, deviceId, ...serverOptions } = options;
|
|
29
|
-
const server = new FakeChatServer({ rooms: SAMPLE_ROOMS, ...serverOptions });
|
|
30
|
-
const client = createChatClient({
|
|
31
|
-
exchangeUrl: server.exchangeUrl,
|
|
32
|
-
getAccessToken: () => 'fake-zitadel-token',
|
|
33
|
-
deviceId: deviceId ?? 'fake-device',
|
|
34
|
-
storeName: storeName ?? 'fake',
|
|
35
|
-
});
|
|
36
|
-
let disposed = false;
|
|
37
|
-
return {
|
|
38
|
-
client,
|
|
39
|
-
server,
|
|
40
|
-
dispose: () => {
|
|
41
|
-
if (disposed)
|
|
42
|
-
return;
|
|
43
|
-
disposed = true;
|
|
44
|
-
client.stop();
|
|
45
|
-
server.dispose();
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global `fetch` interception, shared by every `FakeChatServer`.
|
|
3
|
-
*
|
|
4
|
-
* **A fake transport, not a fake API** -- the same choice `@wtfalch/email`'s
|
|
5
|
-
* `fakeMail()` makes. `createChatClient` and matrix-js-sdk run unchanged; only
|
|
6
|
-
* the network is answered by memory instead of a real homeserver.
|
|
7
|
-
*
|
|
8
|
-
* Unlike a single captured `route` callback, this keeps a list: two fakes --
|
|
9
|
-
* two companies' homeservers -- can be installed at once, each answering only
|
|
10
|
-
* its own origin and falling through to the next. The real `fetch` is
|
|
11
|
-
* restored once the last one is disposed.
|
|
12
|
-
*/
|
|
13
|
-
export type FetchRoute = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response> | null;
|
|
14
|
-
/** Registers `route`. Returns a function that unregisters it.
|
|
15
|
-
*
|
|
16
|
-
* `globalThis.fetch` stays patched once the first route is installed, and
|
|
17
|
-
* is never put back: a request made to a disposed fake is still in flight
|
|
18
|
-
* when its route goes, and restoring the real `fetch` underneath it sends
|
|
19
|
-
* that request to DNS. Everything but a `.example.test` host goes straight
|
|
20
|
-
* through to the real `fetch` either way, so nothing else is affected. */
|
|
21
|
-
export declare function installFetchRoute(route: FetchRoute): () => void;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { installFakeUploads } from "./xhr.js";
|
|
2
|
-
let original;
|
|
3
|
-
const routes = [];
|
|
4
|
-
/** `.example.test` is reserved: no such host can ever exist, so a request
|
|
5
|
-
* to one is always meant for a fake. It only reaches the fallthrough when
|
|
6
|
-
* the fake that would have answered it has already been disposed -- a
|
|
7
|
-
* request still in flight when a test ended. Such a request is left
|
|
8
|
-
* hanging rather than answered: a client nobody is using any more has no
|
|
9
|
-
* business succeeding, and any answer at all -- a real DNS failure, or a
|
|
10
|
-
* 404 -- comes back as a rejection inside matrix-js-sdk that no test can
|
|
11
|
-
* reach and vitest reports as an unhandled error. */
|
|
12
|
-
function isFakeHost(input) {
|
|
13
|
-
try {
|
|
14
|
-
const url = input instanceof Request ? input.url : String(input);
|
|
15
|
-
return new URL(url).hostname.endsWith('.example.test');
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function patched(input, init) {
|
|
22
|
-
for (const route of routes) {
|
|
23
|
-
const answered = route(input, init);
|
|
24
|
-
if (answered)
|
|
25
|
-
return answered;
|
|
26
|
-
}
|
|
27
|
-
if (isFakeHost(input))
|
|
28
|
-
return new Promise(() => { });
|
|
29
|
-
if (!original) {
|
|
30
|
-
throw new Error('fake chat: no route matched and the real fetch was not captured');
|
|
31
|
-
}
|
|
32
|
-
return original(input, init);
|
|
33
|
-
}
|
|
34
|
-
/** Registers `route`. Returns a function that unregisters it.
|
|
35
|
-
*
|
|
36
|
-
* `globalThis.fetch` stays patched once the first route is installed, and
|
|
37
|
-
* is never put back: a request made to a disposed fake is still in flight
|
|
38
|
-
* when its route goes, and restoring the real `fetch` underneath it sends
|
|
39
|
-
* that request to DNS. Everything but a `.example.test` host goes straight
|
|
40
|
-
* through to the real `fetch` either way, so nothing else is affected. */
|
|
41
|
-
export function installFetchRoute(route) {
|
|
42
|
-
installFakeUploads();
|
|
43
|
-
if (!original) {
|
|
44
|
-
original = globalThis.fetch;
|
|
45
|
-
globalThis.fetch = patched;
|
|
46
|
-
}
|
|
47
|
-
routes.push(route);
|
|
48
|
-
let removed = false;
|
|
49
|
-
return () => {
|
|
50
|
-
if (removed)
|
|
51
|
-
return;
|
|
52
|
-
removed = true;
|
|
53
|
-
const index = routes.indexOf(route);
|
|
54
|
-
if (index >= 0)
|
|
55
|
-
routes.splice(index, 1);
|
|
56
|
-
};
|
|
57
|
-
}
|
package/dist/chat/fake/sample.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** A couple of rooms, for a story or a test that wants something to look
|
|
2
|
-
* at without seeding its own. */
|
|
3
|
-
export const SAMPLE_ROOMS = [
|
|
4
|
-
{ id: '!general:chat.example.test', name: 'general', isDirect: false },
|
|
5
|
-
{ id: '!ada:chat.example.test', name: 'Ada Lovelace', isDirect: true },
|
|
6
|
-
];
|
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
export type FakeRoomSeed = {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
/** Defaults to `false`. Seeds the account's `m.direct` data, keyed by the
|
|
5
|
-
* fake peer, unless `members` says who the room is with. */
|
|
6
|
-
isDirect?: boolean;
|
|
7
|
-
/** Seeds `unread_notifications.notification_count`. Defaults to `0`. */
|
|
8
|
-
notificationCount?: number;
|
|
9
|
-
/** Seeds `unread_notifications.highlight_count` -- the subset of
|
|
10
|
-
* `notificationCount` that mentions this account. Defaults to `0`. */
|
|
11
|
-
highlightCount?: number;
|
|
12
|
-
/** An `m.space` rather than a room -- the company space. Its `members`
|
|
13
|
-
* are what `client.people()` reads. Defaults to `false`. */
|
|
14
|
-
isSpace?: boolean;
|
|
15
|
-
/** Who else is joined, beyond the fake account itself. Defaults to none
|
|
16
|
-
* for a channel; a direct room with no `members` is recorded against
|
|
17
|
-
* the fake peer. */
|
|
18
|
-
members?: FakeMember[];
|
|
19
|
-
/** Who else is invited but has not joined -- a DM whose other side has
|
|
20
|
-
* not accepted yet. Defaults to none. */
|
|
21
|
-
invited?: FakeMember[];
|
|
22
|
-
/** Messages already in the room when the first sync lands, oldest first.
|
|
23
|
-
* Defaults to none. */
|
|
24
|
-
messages?: FakeMessageSeed[];
|
|
25
|
-
/** Seeds an `m.room.encryption` state event -- the one thing `search`
|
|
26
|
-
* reads to report a room unsearchable (agora#252). Defaults to
|
|
27
|
-
* `false`. */
|
|
28
|
-
encrypted?: boolean;
|
|
29
|
-
/** Seeds an `m.room.power_levels` state event with `events_default: 100`
|
|
30
|
-
* -- the one thing `ChatRoomSummary.archived` and `AdminChannel.archived`
|
|
31
|
-
* both read to report a room's member writes locked. Defaults to
|
|
32
|
-
* `false`, which seeds no such event (an unset `events_default`
|
|
33
|
-
* defaults to `0` in real Matrix, same as the client and admin reads
|
|
34
|
-
* treat it). */
|
|
35
|
-
archived?: boolean;
|
|
36
|
-
/** Seeds this room as an unanswered invitation to the fake account
|
|
37
|
-
* itself, rather than a room it has joined -- a `rooms.invite` entry
|
|
38
|
-
* with the stripped state real Matrix delivers one in, the one shape
|
|
39
|
-
* `membership: 'invite'` ever comes from. `messages` is ignored: a real
|
|
40
|
-
* invitee's client has no timeline to read before joining. Defaults to
|
|
41
|
-
* `undefined` (the room is joined, as every other seed is). */
|
|
42
|
-
invitedAccount?: {
|
|
43
|
-
inviter?: string;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
export type FakeMessageSeed = {
|
|
47
|
-
/** Defaults to a minted `$seeded-<n>`. Give one to reply to it. */
|
|
48
|
-
id?: string;
|
|
49
|
-
body: string;
|
|
50
|
-
/** Defaults to the fake peer. */
|
|
51
|
-
sender?: string;
|
|
52
|
-
/** The id of the message this replies to, making it a `m.thread` reply.
|
|
53
|
-
* Matrix threads are one level, so this is always the root's id. */
|
|
54
|
-
threadRootId?: string;
|
|
55
|
-
/** Seeds an `m.file`/`m.image` in one step, without a real upload round
|
|
56
|
-
* trip -- what `roomFiles` (#9) reads `content.url`/`content.info` off
|
|
57
|
-
* of. `body` is still the file's name, matching what a real client
|
|
58
|
-
* sends. Cheap enough to seed the hundreds of messages a pagination
|
|
59
|
-
* test needs. */
|
|
60
|
-
attachment?: {
|
|
61
|
-
mxcUri: string;
|
|
62
|
-
mimeType: string;
|
|
63
|
-
size: number;
|
|
64
|
-
isImage?: boolean;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
export type FakeMember = {
|
|
68
|
-
userId: string;
|
|
69
|
-
/** Their `m.room.member` display name. Defaults to the user id. */
|
|
70
|
-
name?: string;
|
|
71
|
-
/** Marks this member a guest, carrying `GUEST_MARKER_KEY` on their
|
|
72
|
-
* `m.room.member` content with `{ until: guestUntil }` -- what
|
|
73
|
-
* `client.ts`'s `readGuest` reads into `ChatPerson.guest`. Omitted for
|
|
74
|
-
* an ordinary member. */
|
|
75
|
-
guestUntil?: string;
|
|
76
|
-
};
|
|
77
|
-
export type FakeChatServerOptions = {
|
|
78
|
-
/** Defaults to a distinct `https://chat.<random>.example.test`, so two
|
|
79
|
-
* servers in one test never collide even if their callers forget to set
|
|
80
|
-
* one. */
|
|
81
|
-
homeserver?: string;
|
|
82
|
-
userId?: string;
|
|
83
|
-
rooms?: FakeRoomSeed[];
|
|
84
|
-
/** How long a minted Matrix token lasts, in ms. Long enough that a test
|
|
85
|
-
* which does not care about refresh timing never trips it by accident. */
|
|
86
|
-
tokenLifetimeMs?: number;
|
|
87
|
-
now?: () => number;
|
|
88
|
-
/** Whether `/versions` advertises MSC4133 extended profiles. Defaults to
|
|
89
|
-
* `true`; a test simulating production before
|
|
90
|
-
* wtfalch/foundry#41 turns it on passes `false`, the same "off" every
|
|
91
|
-
* company's Synapse ships with today (`docs/status.md`). */
|
|
92
|
-
extendedProfilesEnabled?: boolean;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* A fake exchange endpoint and a fake homeserver, both answered by
|
|
96
|
-
* intercepting `fetch` -- so `createChatClient`'s real wire code, and the
|
|
97
|
-
* real matrix-js-sdk underneath it, run exactly as they would against
|
|
98
|
-
* `apps/chat-service` and Synapse. See `intercept.ts`'s module comment.
|
|
99
|
-
*
|
|
100
|
-
* It implements only what `createChatClient`'s startup needs: `/versions`,
|
|
101
|
-
* `/pushrules/`, filter creation, and `/sync`. Anything else falls through
|
|
102
|
-
* to whatever else is installed, or the real network.
|
|
103
|
-
*
|
|
104
|
-
* `/sync` beyond the first request is a manual long-poll: it never answers
|
|
105
|
-
* on its own. A test drives it explicitly with `addRoom` and
|
|
106
|
-
* `invalidateCurrentToken`, after confirming the request has arrived with
|
|
107
|
-
* `waitForParkedPoll()`.
|
|
108
|
-
*/
|
|
109
|
-
export declare class FakeChatServer {
|
|
110
|
-
#private;
|
|
111
|
-
readonly homeserver: string;
|
|
112
|
-
readonly exchangeUrl: string;
|
|
113
|
-
/** Controls for upload failure and in-flight UI scenarios. */
|
|
114
|
-
uploadBarrier: Promise<void> | null;
|
|
115
|
-
uploadStatus: number;
|
|
116
|
-
/** What `PUT .../state/m.room.pinned_events/` answers with -- 403 models
|
|
117
|
-
* the power-level refusal a room whose power levels predate ticket #8
|
|
118
|
-
* gives a member, which `pinMessage`/`unpinMessage` must reject on
|
|
119
|
-
* rather than resolve quietly. */
|
|
120
|
-
pinStatus: number;
|
|
121
|
-
/** What `PUT .../send/...` answers with -- anything but 200 fails the
|
|
122
|
-
* send, with nothing stored. */
|
|
123
|
-
sendStatus: number;
|
|
124
|
-
/** Holds every thread follow `GET` until it resolves -- for a test of a
|
|
125
|
-
* read that is still in flight when the person clicks. */
|
|
126
|
-
threadFollowReadBarrier: Promise<void> | null;
|
|
127
|
-
/** What a thread follow `GET` answers with. */
|
|
128
|
-
threadFollowReadStatus: number;
|
|
129
|
-
/** What a thread follow `PUT`/`DELETE` answers with -- anything but 200
|
|
130
|
-
* fails the follow or unfollow, with nothing stored. */
|
|
131
|
-
threadFollowWriteStatus: number;
|
|
132
|
-
/** Every call to the thread follow route, in arrival order. */
|
|
133
|
-
readonly threadFollowRequests: Array<{
|
|
134
|
-
method: string;
|
|
135
|
-
roomId: string;
|
|
136
|
-
rootId: string;
|
|
137
|
-
}>;
|
|
138
|
-
readonly userId: string;
|
|
139
|
-
/** The Matrix server name, as `userId` gives it -- what an `mxc://`
|
|
140
|
-
* reference from this homeserver names. */
|
|
141
|
-
readonly serverName: string;
|
|
142
|
-
/** How many times `/_chat/exchange` has been called. */
|
|
143
|
-
exchangeCount: number;
|
|
144
|
-
/** Every Matrix access token this server has ever minted, oldest first --
|
|
145
|
-
* for a test that asserts one was never logged. */
|
|
146
|
-
readonly mintedTokens: string[];
|
|
147
|
-
/** Every `m.read` receipt this server has answered, in arrival order --
|
|
148
|
-
* for a test that asserts `markRoomRead` actually called the wire. */
|
|
149
|
-
readonly receipts: Array<{
|
|
150
|
-
roomId: string;
|
|
151
|
-
eventId: string;
|
|
152
|
-
}>;
|
|
153
|
-
/** Every content report the client filed (#29), with the exact body it
|
|
154
|
-
* sent. */
|
|
155
|
-
readonly reports: Array<{
|
|
156
|
-
roomId: string;
|
|
157
|
-
eventId: string;
|
|
158
|
-
body: unknown;
|
|
159
|
-
}>;
|
|
160
|
-
/** Every room `/createRoom` has made, in order -- for a test that asserts
|
|
161
|
-
* what shape a DM was created in. */
|
|
162
|
-
readonly createdRooms: Array<{
|
|
163
|
-
id: string;
|
|
164
|
-
isDirect: boolean;
|
|
165
|
-
invite: string[];
|
|
166
|
-
}>;
|
|
167
|
-
/** Every event this server has accepted from the client, in order -- for
|
|
168
|
-
* a test that asserts what relation a reply was sent with. */
|
|
169
|
-
readonly sent: Array<{
|
|
170
|
-
roomId: string;
|
|
171
|
-
eventId: string;
|
|
172
|
-
type: string;
|
|
173
|
-
content: Record<string, unknown>;
|
|
174
|
-
}>;
|
|
175
|
-
/** Every file the client has uploaded, by media id -- so a test can
|
|
176
|
-
* assert what went up, and so the download route has something to
|
|
177
|
-
* answer with. */
|
|
178
|
-
readonly media: Map<string, {
|
|
179
|
-
bytes: ArrayBuffer;
|
|
180
|
-
contentType: string;
|
|
181
|
-
}>;
|
|
182
|
-
/** Every media download this server has answered, with the header the
|
|
183
|
-
* request carried -- for a test that asserts nothing reaches the
|
|
184
|
-
* legacy unauthenticated endpoints, and that the token was sent. */
|
|
185
|
-
readonly mediaRequests: Array<{
|
|
186
|
-
path: string;
|
|
187
|
-
authorised: boolean;
|
|
188
|
-
}>;
|
|
189
|
-
/** Who follows which thread, as `apps/chat-service`'s thread follow
|
|
190
|
-
* route keeps it: `roomId rootId` -> whether the person unfollowed. A
|
|
191
|
-
* thread with no entry is not followed. */
|
|
192
|
-
readonly threadFollows: Map<string, {
|
|
193
|
-
muted: boolean;
|
|
194
|
-
}>;
|
|
195
|
-
/** What `apps/chat-service`'s `GET /_chat/status/{userId}` holds per
|
|
196
|
-
* person: the automatic `meeting` overlay a call pushed. No entry reads
|
|
197
|
-
* as `{ kind: null, sequence: 0 }`, as the real route does. */
|
|
198
|
-
readonly automaticStatuses: Map<string, {
|
|
199
|
-
kind: "meeting" | null;
|
|
200
|
-
sequence: number;
|
|
201
|
-
}>;
|
|
202
|
-
/** Every `PUT .../typing/...` this server has answered, in order -- for a
|
|
203
|
-
* test that asserts `sendTyping` actually reached the wire, with what
|
|
204
|
-
* it sent. */
|
|
205
|
-
readonly sentTyping: Array<{
|
|
206
|
-
roomId: string;
|
|
207
|
-
userId: string;
|
|
208
|
-
typing: boolean;
|
|
209
|
-
timeoutMs?: number;
|
|
210
|
-
}>;
|
|
211
|
-
/** Every `PUT .../presence/{userId}/status` this server has answered, in
|
|
212
|
-
* order -- the immediate half of `announcePresence`. */
|
|
213
|
-
readonly sentPresence: Array<{
|
|
214
|
-
userId: string;
|
|
215
|
-
presence: string;
|
|
216
|
-
}>;
|
|
217
|
-
/** Set to refuse the next presence `PUT` with `M_LIMIT_EXCEEDED`, the
|
|
218
|
-
* way a real Synapse refuses a second presence change inside ten
|
|
219
|
-
* seconds (`rc_presence.per_user`). Clears itself after one refusal. */
|
|
220
|
-
refuseNextPresence: boolean;
|
|
221
|
-
/** The `set_presence` query parameter every `/sync` has carried, in
|
|
222
|
-
* order, `undefined` where the client omitted it. This is the half that
|
|
223
|
-
* actually makes an announcement survive, so a test that only checked
|
|
224
|
-
* `sentPresence` would pass against a client that cannot hold anybody
|
|
225
|
-
* away for longer than one poll. */
|
|
226
|
-
readonly syncPresence: Array<string | undefined>;
|
|
227
|
-
/** Every `PUT`/`DELETE` on an MSC4133 extended-profile property this
|
|
228
|
-
* server has answered, in order -- what `ChatClient.setOwnStatus`
|
|
229
|
-
* writes. `value: undefined` records a delete. */
|
|
230
|
-
readonly extendedProfileWrites: Array<{
|
|
231
|
-
userId: string;
|
|
232
|
-
key: string;
|
|
233
|
-
value: unknown;
|
|
234
|
-
}>;
|
|
235
|
-
/** Every `PUT .../sendToDevice/...` this server has answered, in order --
|
|
236
|
-
* what a `CryptoApi` verification request (chat#69) sends on its way
|
|
237
|
-
* out. Recorded rather than delivered to another device: the methods
|
|
238
|
-
* this fake exists for (`getVerificationRequestsToDeviceInProgress`)
|
|
239
|
-
* read the sender's own `OlmMachine` state, which only needs the send to
|
|
240
|
-
* succeed, not to be received. */
|
|
241
|
-
readonly sentToDevice: Array<{
|
|
242
|
-
eventType: string;
|
|
243
|
-
body: unknown;
|
|
244
|
-
}>;
|
|
245
|
-
/** Rooms currently carrying the room-scoped `dont_notify` push rule, for
|
|
246
|
-
* a test that wants to assert on the server's own state rather than
|
|
247
|
-
* only through the client's `rooms()`. */
|
|
248
|
-
get mutedRoomIds(): string[];
|
|
249
|
-
/** Rooms currently carrying MSC2867's marked-unread flag, for a test that
|
|
250
|
-
* wants to assert on the server's own state rather than only through the
|
|
251
|
-
* client's `rooms()`. */
|
|
252
|
-
get markedUnreadRoomIds(): string[];
|
|
253
|
-
constructor(options?: FakeChatServerOptions);
|
|
254
|
-
/** Sets `userId`'s MSC4133 extended-profile `key` directly, for a test
|
|
255
|
-
* simulating "somebody else already has this set on the server" --
|
|
256
|
-
* `ChatClient.status`'s background fetch then reads it exactly as it
|
|
257
|
-
* would a real peer's. Real Matrix never lets a client PUT anyone's
|
|
258
|
-
* profile but its own, which is why this exists as a server-side seed
|
|
259
|
-
* rather than something `setOwnStatus` could reach. */
|
|
260
|
-
seedExtendedProfile(userId: string, key: string, value: unknown): void;
|
|
261
|
-
dispose(): void;
|
|
262
|
-
/** Resolves once a `/sync` request is parked waiting for a test to drive
|
|
263
|
-
* it -- immediately if one already is. */
|
|
264
|
-
waitForParkedPoll(): Promise<void>;
|
|
265
|
-
/** Delivers a parked poll as if another of this account's own devices
|
|
266
|
-
* had just written `type` room account data for `roomId` -- a draft,
|
|
267
|
-
* most likely -- the way a real incremental `/sync` carries a change
|
|
268
|
-
* made from elsewhere. Throws if nothing is parked -- await
|
|
269
|
-
* `waitForParkedPoll()` first. */
|
|
270
|
-
receiveRoomAccountData(roomId: string, type: string, content: Record<string, unknown>): void;
|
|
271
|
-
/** Adds a room and, if a poll is parked, delivers it now. Throws if
|
|
272
|
-
* nothing is parked -- await `waitForParkedPoll()` first. */
|
|
273
|
-
addRoom(seed: FakeRoomSeed): void;
|
|
274
|
-
/** Answers a parked poll with nothing new -- proving the connection is
|
|
275
|
-
* healthy (a real incremental sync, just an empty one) without adding a
|
|
276
|
-
* room. Throws if nothing is parked. */
|
|
277
|
-
respondEmpty(): void;
|
|
278
|
-
/** Ends every currently-minted token, as if the person's session had been
|
|
279
|
-
* revoked or the token had simply expired server-side. If a poll is
|
|
280
|
-
* parked, it is answered with `M_UNKNOWN_TOKEN` immediately; otherwise
|
|
281
|
-
* the next request to arrive gets it. */
|
|
282
|
-
invalidateCurrentToken(): void;
|
|
283
|
-
/** Answers a parked poll with a `400`, as Synapse does when it refuses
|
|
284
|
-
* the client's stored `since` position (confirmed live after a long
|
|
285
|
-
* enough time offline). Throws if nothing is parked. */
|
|
286
|
-
refuseCurrentPoll(): void;
|
|
287
|
-
/** Delivers a parked poll as an existing, already-known room receiving
|
|
288
|
-
* one new message from the fake peer -- a timeline event and a bumped
|
|
289
|
-
* notification count together, the way a real incremental `/sync`
|
|
290
|
-
* carries both at once. `highlightCount` defaults to `0`: an ordinary
|
|
291
|
-
* message that does not mention this account, same as Matrix would
|
|
292
|
-
* report. Pass it to simulate a mention arriving. Returns the minted
|
|
293
|
-
* event id, for a test that then calls `markRoomRead` against it.
|
|
294
|
-
* Throws if nothing is parked. */
|
|
295
|
-
receiveMessage(roomId: string, notificationCount?: number, highlightCount?: number): string;
|
|
296
|
-
/** Delivers a parked poll renaming an already-known room -- an
|
|
297
|
-
* `m.room.name` state event, the way a real incremental `/sync` carries
|
|
298
|
-
* a rename. Throws if nothing is parked. */
|
|
299
|
-
renameRoom(roomId: string, name: string): void;
|
|
300
|
-
/** Delivers a parked poll with the fake account leaving `roomId` -- a
|
|
301
|
-
* `rooms.leave` block, the way a real incremental `/sync` reports a kick
|
|
302
|
-
* or a self-leave. Throws if nothing is parked. */
|
|
303
|
-
leaveRoom(roomId: string): void;
|
|
304
|
-
/** Delivers a parked poll as `m.typing` for `roomId` -- Matrix's own
|
|
305
|
-
* shape: an EDU with no sender of its own, always the room's complete
|
|
306
|
-
* current set of typing user ids, never a diff against the last one.
|
|
307
|
-
* Pass an empty list for what Matrix does on its own once a typing
|
|
308
|
-
* state's timeout elapses server-side; this fake never does that by
|
|
309
|
-
* itself, so a test drives both halves explicitly. Throws if nothing is
|
|
310
|
-
* parked. */
|
|
311
|
-
receiveTyping(roomId: string, userIds: string[]): void;
|
|
312
|
-
/** Delivers a parked poll as `userId`'s public read receipt on
|
|
313
|
-
* `eventId` in `roomId` -- the `m.receipt` EDU another person's client
|
|
314
|
-
* causes by reading. Throws if nothing is parked. */
|
|
315
|
-
receiveReceipt(roomId: string, eventId: string, userId: string): void;
|
|
316
|
-
/** Delivers a parked poll as an `m.presence` EDU for somebody else --
|
|
317
|
-
* Matrix's own three states (`online`/`unavailable`/`offline`), or
|
|
318
|
-
* MSC3026's unstable `org.matrix.msc3026.busy` -- for a test that drives
|
|
319
|
-
* `presence()`/`onPresenceChanged` without a live homeserver. Presence
|
|
320
|
-
* EDUs are account-wide, not room-scoped, so this carries no room id --
|
|
321
|
-
* see `#answerParked`'s own `presence.events`. Throws if nothing is
|
|
322
|
-
* parked. */
|
|
323
|
-
receivePresence(userId: string, presence: string): void;
|
|
324
|
-
/** Delivers a parked poll as somebody else reacting to a message.
|
|
325
|
-
* Returns the minted event id, so a test can then redact it. Throws if
|
|
326
|
-
* nothing is parked. */
|
|
327
|
-
receiveReaction(roomId: string, targetId: string, key: string, sender?: string): string;
|
|
328
|
-
/** Delivers a parked poll as one more message arriving in an existing
|
|
329
|
-
* room -- threaded, when `threadRootId` is given. Returns the minted
|
|
330
|
-
* event id. Throws if nothing is parked. */
|
|
331
|
-
receiveThreadReply(roomId: string, threadRootId: string, body?: string): string;
|
|
332
|
-
/** Delivers a parked poll as somebody else editing one of their own
|
|
333
|
-
* messages: an `m.replace` carrying `m.new_content`, which is the whole
|
|
334
|
-
* of how Matrix edits a message. Returns the edit's own event id.
|
|
335
|
-
* Throws if nothing is parked. */
|
|
336
|
-
receiveEdit(roomId: string, targetId: string, body: string, sender?: string): string;
|
|
337
|
-
/** Delivers a parked poll as a message being redacted. The target keeps
|
|
338
|
-
* its place in the room's record with its content emptied, exactly as
|
|
339
|
-
* `#route`'s own redact endpoint does and as Synapse does -- a redacted
|
|
340
|
-
* event is still an event. Throws if nothing is parked. */
|
|
341
|
-
receiveRedaction(roomId: string, targetId: string, sender?: string): string;
|
|
342
|
-
/** The device ids that have uploaded `device_keys` so far. */
|
|
343
|
-
uploadedDeviceIds(): string[];
|
|
344
|
-
/** Delivers to-device events (a verification request, say) to the one
|
|
345
|
-
* client this fake serves, on its next `/sync` -- straight away if a poll
|
|
346
|
-
* is parked. Each event is `{ type, sender, content }`. Only one client
|
|
347
|
-
* can be answered at a time: this fake has a single parked poll, so it
|
|
348
|
-
* cannot route a to-device message from one live client to another, and
|
|
349
|
-
* `sendToDevice` writes stay recorded in `sentToDevice` only. */
|
|
350
|
-
deliverToDevice(events: Array<{
|
|
351
|
-
type: string;
|
|
352
|
-
sender: string;
|
|
353
|
-
content: unknown;
|
|
354
|
-
}>): void;
|
|
355
|
-
}
|