diff --git a/README.md b/README.md index b1881d7c..b539bae5 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,16 @@ TypeScript/JavaScript SDK for Matrix bots. For help and support, visit [#matrix- # Documentation Documentation for the project is available [here](https://turt2live.github.io/matrix-bot-sdk/index.html). + +# Matrix version support + +The Matrix protocol is [versioned](https://spec.matrix.org/latest/#specification-versions) to ensure endpoints and +functionality can safely rotate in and out of the ecosystem. The bot-sdk will assume it is connected to a homeserver +with support for at least one of the last 2 versions, at the time of the bot-sdk's release. This means that if you +connect the bot-sdk to a homeserver which is 3 or more Matrix versions out of date, things might not work for you. + +It is recommended to update the bot-sdk as frequently as spec releases themselves (or faster) to avoid this situation, +and watch the repo for updates in the event a release is delayed. + +**Note**: Currently the bot-sdk does not throw an error if the server appears to be incompatible, however this might +change in the future. diff --git a/src/AdminApis.ts b/src/AdminApis.ts index 1e6c343c..af615f6d 100644 --- a/src/AdminApis.ts +++ b/src/AdminApis.ts @@ -55,6 +55,6 @@ export class AdminApis { * @returns {Promise} resolves to the whois information */ public whoisUser(userId: string): Promise { - return this.client.doRequest("GET", "/_matrix/client/r0/admin/whois/" + encodeURIComponent(userId)); + return this.client.doRequest("GET", "/_matrix/client/v3/admin/whois/" + encodeURIComponent(userId)); } } diff --git a/src/MatrixAuth.ts b/src/MatrixAuth.ts index 2ea8e126..6aed23e6 100644 --- a/src/MatrixAuth.ts +++ b/src/MatrixAuth.ts @@ -48,7 +48,7 @@ export class MatrixAuth { let response; try { - response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/r0/register", null, body); + response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/v3/register", null, body); } catch (e) { if (e.statusCode === 401) { if (typeof (e.body) === "string") e.body = JSON.parse(e.body); @@ -83,7 +83,7 @@ export class MatrixAuth { type: expectedFlow[0], // HACK: We assume we only have one entry here session: sessionId, }; - response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/r0/register", null, body); + response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/v3/register", null, body); } } @@ -115,7 +115,7 @@ export class MatrixAuth { initial_device_display_name: deviceName, }; - const response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/r0/login", null, body); + const response = await this.createTemplateClient().doRequest("POST", "/_matrix/client/v3/login", null, body); const accessToken = response["access_token"]; if (!accessToken) throw new Error("Expected access token in response - got nothing"); diff --git a/src/MatrixClient.ts b/src/MatrixClient.ts index 58afe24d..f2bfcf98 100644 --- a/src/MatrixClient.ts +++ b/src/MatrixClient.ts @@ -44,9 +44,11 @@ import { EncryptedRoomEvent } from "./models/events/EncryptedRoomEvent"; import { IWhoAmI } from "./models/Account"; import { RustSdkCryptoStorageProvider } from "./storage/RustSdkCryptoStorageProvider"; import { DMs } from "./DMs"; +import { ServerVersions } from "./models/ServerVersions"; const SYNC_BACKOFF_MIN_MS = 5000; const SYNC_BACKOFF_MAX_MS = 15000; +const VERSIONS_CACHE_MS = 7200000; // 2 hours /** * A client that is capable of interacting with a matrix homeserver. @@ -92,6 +94,8 @@ export class MatrixClient extends EventEmitter { private stopSyncing = false; private metricsInstance: Metrics = new Metrics(); private unstableApisInstance = new UnstableApis(this); + private cachedVersions: ServerVersions; + private versionsLastFetched = 0; /** * Set this to true to have the client only persist the sync token after the sync @@ -250,6 +254,53 @@ export class MatrixClient extends EventEmitter { return event; } + /** + * Retrieves the server's supported specification versions and unstable features. + * @returns {Promise} Resolves to the server's supported versions. + */ + @timedMatrixClientFunctionCall() + public async getServerVersions(): Promise { + if (!this.cachedVersions || (Date.now() - this.versionsLastFetched) >= VERSIONS_CACHE_MS) { + this.cachedVersions = await this.doRequest("GET", "/_matrix/client/versions"); + this.versionsLastFetched = Date.now(); + } + + return this.cachedVersions; + } + + /** + * Determines if the server supports a given unstable feature flag. Useful for determining + * if the server can support an unstable MSC. + * @param {string} feature The feature name to look for. + * @returns {Promise} Resolves to true if the server supports the flag, false otherwise. + */ + public async doesServerSupportUnstableFeature(feature: string): Promise { + return !!(await this.getServerVersions()).unstable_features?.[feature]; + } + + /** + * Determines if the server supports a given version of the specification or not. + * @param {string} version The version to look for. Eg: "v1.1" + * @returns {Promise} Resolves to true if the server supports the version, false otherwise. + */ + public async doesServerSupportVersion(version: string): Promise { + return (await this.getServerVersions()).versions.includes(version); + } + + /** + * Determines if the server supports at least one of the given specification versions or not. + * @param {string[]} versions The versions to look for. Eg: ["v1.1"] + * @returns {Promise} Resolves to true if the server supports any of the versions, false otherwise. + */ + public async doesServerSupportAnyOneVersion(versions: string[]): Promise { + for (const version of versions) { + if (await this.doesServerSupportVersion(version)) { + return true; + } + } + return false; + } + /** * Retrieves an OpenID Connect token from the homeserver for the current user. * @returns {Promise} Resolves to the token. @@ -257,7 +308,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public async getOpenIDConnectToken(): Promise { const userId = encodeURIComponent(await this.getUserId()); - return this.doRequest("POST", "/_matrix/client/r0/user/" + userId + "/openid/request_token", null, {}); + return this.doRequest("POST", "/_matrix/client/v3/user/" + userId + "/openid/request_token", null, {}); } /** @@ -269,7 +320,7 @@ export class MatrixClient extends EventEmitter { public async getAccountData(eventType: string): Promise { const userId = encodeURIComponent(await this.getUserId()); eventType = encodeURIComponent(eventType); - return this.doRequest("GET", "/_matrix/client/r0/user/" + userId + "/account_data/" + eventType); + return this.doRequest("GET", "/_matrix/client/v3/user/" + userId + "/account_data/" + eventType); } /** @@ -283,7 +334,7 @@ export class MatrixClient extends EventEmitter { const userId = encodeURIComponent(await this.getUserId()); eventType = encodeURIComponent(eventType); roomId = encodeURIComponent(roomId); - return this.doRequest("GET", "/_matrix/client/r0/user/" + userId + "/rooms/" + roomId + "/account_data/" + eventType); + return this.doRequest("GET", "/_matrix/client/v3/user/" + userId + "/rooms/" + roomId + "/account_data/" + eventType); } /** @@ -331,7 +382,7 @@ export class MatrixClient extends EventEmitter { public async setAccountData(eventType: string, content: any): Promise { const userId = encodeURIComponent(await this.getUserId()); eventType = encodeURIComponent(eventType); - return this.doRequest("PUT", "/_matrix/client/r0/user/" + userId + "/account_data/" + eventType, null, content); + return this.doRequest("PUT", "/_matrix/client/v3/user/" + userId + "/account_data/" + eventType, null, content); } /** @@ -346,7 +397,7 @@ export class MatrixClient extends EventEmitter { const userId = encodeURIComponent(await this.getUserId()); eventType = encodeURIComponent(eventType); roomId = encodeURIComponent(roomId); - return this.doRequest("PUT", "/_matrix/client/r0/user/" + userId + "/rooms/" + roomId + "/account_data/" + eventType, null, content); + return this.doRequest("PUT", "/_matrix/client/v3/user/" + userId + "/rooms/" + roomId + "/account_data/" + eventType, null, content); } /** @@ -365,7 +416,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public async getPresenceStatusFor(userId: string): Promise { - return this.doRequest("GET", "/_matrix/client/r0/presence/" + encodeURIComponent(userId) + "/status").then(r => new Presence(r)); + return this.doRequest("GET", "/_matrix/client/v3/presence/" + encodeURIComponent(userId) + "/status").then(r => new Presence(r)); } /** @@ -376,7 +427,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public async setPresenceStatus(presence: "online" | "offline" | "unavailable", statusMessage: string | undefined = undefined): Promise { - return this.doRequest("PUT", "/_matrix/client/r0/presence/" + encodeURIComponent(await this.getUserId()) + "/status", null, { + return this.doRequest("PUT", "/_matrix/client/v3/presence/" + encodeURIComponent(await this.getUserId()) + "/status", null, { presence: presence, status_msg: statusMessage, }); @@ -415,7 +466,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public createRoomAlias(alias: string, roomId: string): Promise { alias = encodeURIComponent(alias); - return this.doRequest("PUT", "/_matrix/client/r0/directory/room/" + alias, null, { + return this.doRequest("PUT", "/_matrix/client/v3/directory/room/" + alias, null, { "room_id": roomId, }); } @@ -428,7 +479,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public deleteRoomAlias(alias: string): Promise { alias = encodeURIComponent(alias); - return this.doRequest("DELETE", "/_matrix/client/r0/directory/room/" + alias); + return this.doRequest("DELETE", "/_matrix/client/v3/directory/room/" + alias); } /** @@ -440,7 +491,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public setDirectoryVisibility(roomId: string, visibility: "public" | "private"): Promise { roomId = encodeURIComponent(roomId); - return this.doRequest("PUT", "/_matrix/client/r0/directory/list/room/" + roomId, null, { + return this.doRequest("PUT", "/_matrix/client/v3/directory/list/room/" + roomId, null, { "visibility": visibility, }); } @@ -453,7 +504,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public getDirectoryVisibility(roomId: string): Promise<"public" | "private"> { roomId = encodeURIComponent(roomId); - return this.doRequest("GET", "/_matrix/client/r0/directory/list/room/" + roomId).then(response => { + return this.doRequest("GET", "/_matrix/client/v3/directory/list/room/" + roomId).then(response => { return response["visibility"]; }); } @@ -480,7 +531,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public lookupRoomAlias(roomAlias: string): Promise { - return this.doRequest("GET", "/_matrix/client/r0/directory/room/" + encodeURIComponent(roomAlias)).then(response => { + return this.doRequest("GET", "/_matrix/client/v3/directory/room/" + encodeURIComponent(roomAlias)).then(response => { return { roomId: response["room_id"], residentServers: response["servers"], @@ -496,7 +547,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public inviteUser(userId, roomId) { - return this.doRequest("POST", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/invite", null, { + return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/invite", null, { user_id: userId, }); } @@ -510,7 +561,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public kickUser(userId, roomId, reason = null) { - return this.doRequest("POST", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/kick", null, { + return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/kick", null, { user_id: userId, reason: reason, }); @@ -525,7 +576,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public banUser(userId, roomId, reason = null) { - return this.doRequest("POST", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/ban", null, { + return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/ban", null, { user_id: userId, reason: reason, }); @@ -539,7 +590,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public unbanUser(userId, roomId) { - return this.doRequest("POST", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/unban", null, { + return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/unban", null, { user_id: userId, }); } @@ -563,7 +614,7 @@ export class MatrixClient extends EventEmitter { * @returns {Promise} The "who am I" response. */ public async getWhoAmI(): Promise { - const whoami = await this.doRequest("GET", "/_matrix/client/r0/account/whoami"); + const whoami = await this.doRequest("GET", "/_matrix/client/v3/account/whoami"); this.userId = whoami["user_id"]; return whoami; } @@ -618,7 +669,7 @@ export class MatrixClient extends EventEmitter { if (createFilter && filter) { LogService.trace("MatrixClientLite", "Creating new filter"); - return this.doRequest("POST", "/_matrix/client/r0/user/" + encodeURIComponent(userId) + "/filter", null, filter).then(async response => { + return this.doRequest("POST", "/_matrix/client/v3/user/" + encodeURIComponent(userId) + "/filter", null, filter).then(async response => { this.filterId = response["filter_id"]; // noinspection ES6RedundantAwait await Promise.resolve(this.storage.setSyncToken(null)); @@ -688,7 +739,7 @@ export class MatrixClient extends EventEmitter { if (this.syncingPresence) conf['presence'] = this.syncingPresence; // timeout is 40s if we have a token, otherwise 10min - return this.doRequest("GET", "/_matrix/client/r0/sync", conf, null, (token ? 40000 : 600000)); + return this.doRequest("GET", "/_matrix/client/v3/sync", conf, null, (token ? 40000 : 600000)); } @timedMatrixClientFunctionCall() @@ -879,7 +930,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public getRawEvent(roomId: string, eventId: string): Promise { - return this.doRequest("GET", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/event/" + encodeURIComponent(eventId)) + return this.doRequest("GET", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/event/" + encodeURIComponent(eventId)) .then(ev => this.processEvent(ev)); } @@ -890,7 +941,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public getRoomState(roomId: string): Promise { - return this.doRequest("GET", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/state") + return this.doRequest("GET", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/state") .then(state => Promise.all(state.map(ev => this.processEvent(ev)))); } @@ -916,7 +967,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public getRoomStateEvent(roomId, type, stateKey): Promise { - const path = "/_matrix/client/r0/rooms/" + const path = "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/state/" + encodeURIComponent(type) + "/" + encodeURIComponent(stateKey ? stateKey : ''); @@ -933,7 +984,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public async getEventContext(roomId: string, eventId: string, limit = 10): Promise { - const res = await this.doRequest("GET", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/context/" + encodeURIComponent(eventId), { limit }); + const res = await this.doRequest("GET", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/context/" + encodeURIComponent(eventId), { limit }); return { event: new RoomEvent(res['event']), before: res['events_before'].map(e => new RoomEvent(e)), @@ -949,7 +1000,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public getUserProfile(userId: string): Promise { - return this.doRequest("GET", "/_matrix/client/r0/profile/" + encodeURIComponent(userId)); + return this.doRequest("GET", "/_matrix/client/v3/profile/" + encodeURIComponent(userId)); } /** @@ -960,7 +1011,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public async setDisplayName(displayName: string): Promise { const userId = encodeURIComponent(await this.getUserId()); - return this.doRequest("PUT", "/_matrix/client/r0/profile/" + userId + "/displayname", null, { + return this.doRequest("PUT", "/_matrix/client/v3/profile/" + userId + "/displayname", null, { displayname: displayName, }); } @@ -973,7 +1024,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public async setAvatarUrl(avatarUrl: string): Promise { const userId = encodeURIComponent(await this.getUserId()); - return this.doRequest("PUT", "/_matrix/client/r0/profile/" + userId + "/avatar_url", null, { + return this.doRequest("PUT", "/_matrix/client/v3/profile/" + userId + "/avatar_url", null, { avatar_url: avatarUrl, }); } @@ -990,7 +1041,7 @@ export class MatrixClient extends EventEmitter { targetIdOrAlias = encodeURIComponent(targetIdOrAlias); const qs = {}; if (viaServers.length > 0) qs['server_name'] = viaServers; - return this.doRequest("POST", "/_matrix/client/r0/join/" + targetIdOrAlias, qs).then(response => { + return this.doRequest("POST", "/_matrix/client/v3/join/" + targetIdOrAlias, qs).then(response => { return response['room_id']; }); }; @@ -1006,7 +1057,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public getJoinedRooms(): Promise { - return this.doRequest("GET", "/_matrix/client/r0/joined_rooms").then(response => response['joined_rooms']); + return this.doRequest("GET", "/_matrix/client/v3/joined_rooms").then(response => response['joined_rooms']); } /** @@ -1016,7 +1067,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public getJoinedRoomMembers(roomId: string): Promise { - return this.doRequest("GET", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/joined_members").then(response => { + return this.doRequest("GET", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/joined_members").then(response => { return Object.keys(response['joined']); }); } @@ -1028,7 +1079,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public async getJoinedRoomMembersWithProfiles(roomId: string): Promise<{ [userId: string]: { display_name?: string, avatar_url?: string } }> { - return (await this.doRequest("GET", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/joined_members")).joined; + return (await this.doRequest("GET", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/joined_members")).joined; } /** @@ -1047,7 +1098,7 @@ export class MatrixClient extends EventEmitter { if (membership) qs["membership"] = membership; if (notMembership) qs["not_membership"] = notMembership; - return this.doRequest("GET", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/members", qs).then(r => { + return this.doRequest("GET", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/members", qs).then(r => { return r['chunk'].map(e => new MembershipEvent(e)); }); } @@ -1059,7 +1110,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public leaveRoom(roomId: string): Promise { - return this.doRequest("POST", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/leave"); + return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave"); } /** @@ -1070,7 +1121,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public sendReadReceipt(roomId: string, eventId: string): Promise { - return this.doRequest("POST", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/receipt/m.read/" + encodeURIComponent(eventId), null, {}); + return this.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/receipt/m.read/" + encodeURIComponent(eventId), null, {}); } /** @@ -1083,7 +1134,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public async setTyping(roomId: string, typing: boolean, timeout = 30000): Promise { const userId = await this.getUserId(); - return this.doRequest("PUT", "/_matrix/client/r0/rooms/" + encodeURIComponent(roomId) + "/typing/" + encodeURIComponent(userId), null, { + return this.doRequest("PUT", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/typing/" + encodeURIComponent(userId), null, { typing, timeout, }); @@ -1258,7 +1309,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public async sendRawEvent(roomId: string, eventType: string, content: any): Promise { const txnId = (new Date().getTime()) + "__inc" + (++this.requestId); - const path = "/_matrix/client/r0/rooms/" + const path = "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/send/" + encodeURIComponent(eventType) + "/" + encodeURIComponent(txnId); @@ -1277,7 +1328,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public sendStateEvent(roomId: string, type: string, stateKey: string, content: any): Promise { - const path = "/_matrix/client/r0/rooms/" + const path = "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/state/" + encodeURIComponent(type) + "/" + encodeURIComponent(stateKey); @@ -1297,7 +1348,7 @@ export class MatrixClient extends EventEmitter { public redactEvent(roomId: string, eventId: string, reason: string | null = null): Promise { const txnId = (new Date().getTime()) + "__inc" + (++this.requestId); const content = reason !== null ? { reason } : {}; - return this.doRequest("PUT", `/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}/${txnId}`, null, content).then(response => { + return this.doRequest("PUT", `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}/${txnId}`, null, content).then(response => { return response['event_id']; }); } @@ -1312,7 +1363,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public createRoom(properties: any = {}): Promise { - return this.doRequest("POST", "/_matrix/client/r0/createRoom", null, properties).then(response => { + return this.doRequest("POST", "/_matrix/client/v3/createRoom", null, properties).then(response => { return response['room_id']; }); } @@ -1449,7 +1500,7 @@ export class MatrixClient extends EventEmitter { const parts = mxc.substring("mxc://".length).split('/'); const originHomeserver = parts[0]; const mediaId = parts.slice(1, parts.length).join('/'); - return `${this.homeserverUrl}/_matrix/media/r0/download/${encodeURIComponent(originHomeserver)}/${encodeURIComponent(mediaId)}`; + return `${this.homeserverUrl}/_matrix/media/v3/download/${encodeURIComponent(originHomeserver)}/${encodeURIComponent(mediaId)}`; } /** @@ -1462,7 +1513,7 @@ export class MatrixClient extends EventEmitter { */ public mxcToHttpThumbnail(mxc: string, width: number, height: number, method: "crop" | "scale"): string { const downloadUri = this.mxcToHttp(mxc); - return downloadUri.replace("/_matrix/media/r0/download", "/_matrix/media/r0/thumbnail") + return downloadUri.replace("/_matrix/media/v3/download", "/_matrix/media/v3/thumbnail") + `?width=${width}&height=${height}&method=${encodeURIComponent(method)}`; } @@ -1477,7 +1528,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public uploadContent(data: Buffer, contentType = "application/octet-stream", filename: string = null): Promise { // TODO: Make doRequest take an object for options - return this.doRequest("POST", "/_matrix/media/r0/upload", { filename: filename }, data, 60000, false, contentType) + return this.doRequest("POST", "/_matrix/media/v3/upload", { filename: filename }, data, 60000, false, contentType) .then(response => response["content_uri"]); } @@ -1497,7 +1548,7 @@ export class MatrixClient extends EventEmitter { const urlParts = mxcUrl.substr("mxc://".length).split("/"); const domain = encodeURIComponent(urlParts[0]); const mediaId = encodeURIComponent(urlParts[1].split("/")[0]); - const path = `/_matrix/media/r0/download/${domain}/${mediaId}`; + const path = `/_matrix/media/v3/download/${domain}/${mediaId}`; const res = await this.doRequest("GET", path, { allow_remote: allowRemote }, null, null, true, null, true); return { data: res.body, @@ -1742,7 +1793,7 @@ export class MatrixClient extends EventEmitter { keys: keys, }; obj['signatures'] = await this.crypto.sign(obj); - return this.doRequest("POST", "/_matrix/client/r0/keys/upload", null, { + return this.doRequest("POST", "/_matrix/client/v3/keys/upload", null, { device_keys: obj, }).then(r => r['one_time_key_counts']); } @@ -1755,7 +1806,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() @requiresCrypto() public async uploadDeviceOneTimeKeys(keys: OTKs): Promise { - return this.doRequest("POST", "/_matrix/client/r0/keys/upload", null, { + return this.doRequest("POST", "/_matrix/client/v3/keys/upload", null, { one_time_keys: keys, }).then(r => r['one_time_key_counts']); } @@ -1767,7 +1818,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() @requiresCrypto() public async checkOneTimeKeyCounts(): Promise { - return this.doRequest("POST", "/_matrix/client/r0/keys/upload", null, {}) + return this.doRequest("POST", "/_matrix/client/v3/keys/upload", null, {}) .then(r => r['one_time_key_counts']); } @@ -1783,7 +1834,7 @@ export class MatrixClient extends EventEmitter { const keyObj = { [`${OTKAlgorithm.Signed}:${fallbackKey.keyId}`]: fallbackKey.key, }; - return this.doRequest("POST", "/_matrix/client/r0/keys/upload", null, { + return this.doRequest("POST", "/_matrix/client/v3/keys/upload", null, { "org.matrix.msc2732.fallback_keys": keyObj, "fallback_keys": keyObj, }).then(r => r['one_time_key_counts']); @@ -1809,7 +1860,7 @@ export class MatrixClient extends EventEmitter { for (const userId of userIds) { req[userId] = []; } - return this.doRequest("POST", "/_matrix/client/r0/keys/query", {}, { + return this.doRequest("POST", "/_matrix/client/v3/keys/query", {}, { timeout: federationTimeoutMs, device_keys: req, }); @@ -1822,7 +1873,7 @@ export class MatrixClient extends EventEmitter { */ @timedMatrixClientFunctionCall() public async getOwnDevices(): Promise { - return this.doRequest("GET", "/_matrix/client/r0/devices").then(r => { + return this.doRequest("GET", "/_matrix/client/v3/devices").then(r => { return r['devices']; }); } @@ -1840,7 +1891,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() @requiresCrypto() public async claimOneTimeKeys(userDeviceMap: Record>, federationTimeoutMs = 10000): Promise { - return this.doRequest("POST", "/_matrix/client/r0/keys/claim", {}, { + return this.doRequest("POST", "/_matrix/client/v3/keys/claim", {}, { timeout: federationTimeoutMs, one_time_keys: userDeviceMap, }); @@ -1856,7 +1907,7 @@ export class MatrixClient extends EventEmitter { @timedMatrixClientFunctionCall() public async sendToDevices(type: string, messages: Record>): Promise { const txnId = (new Date().getTime()) + "_TDEV__inc" + (++this.requestId); - return this.doRequest("PUT", `/_matrix/client/r0/sendToDevice/${encodeURIComponent(type)}/${encodeURIComponent(txnId)}`, null, { + return this.doRequest("PUT", `/_matrix/client/v3/sendToDevice/${encodeURIComponent(type)}/${encodeURIComponent(txnId)}`, null, { messages: messages, }); } @@ -1865,7 +1916,7 @@ export class MatrixClient extends EventEmitter { * Performs a web request to the homeserver, applying appropriate authorization headers for * this client. * @param {"GET"|"POST"|"PUT"|"DELETE"} method The HTTP method to use in the request - * @param {string} endpoint The endpoint to call. For example: "/_matrix/client/r0/account/whoami" + * @param {string} endpoint The endpoint to call. For example: "/_matrix/client/v3/account/whoami" * @param {any} qs The query string to send. Optional. * @param {any} body The request body to send. Optional. Will be converted to JSON unless the type is a Buffer. * @param {number} timeout The number of milliseconds to wait before timing out. diff --git a/src/appservice/Appservice.ts b/src/appservice/Appservice.ts index f7153e38..04ea83dc 100644 --- a/src/appservice/Appservice.ts +++ b/src/appservice/Appservice.ts @@ -578,7 +578,7 @@ export class Appservice extends EventEmitter { public setRoomDirectoryVisibility(networkId: string, roomId: string, visibility: "public" | "private") { roomId = encodeURIComponent(roomId); networkId = encodeURIComponent(networkId); - return this.botClient.doRequest("PUT", `/_matrix/client/r0/directory/list/appservice/${networkId}/${roomId}`, null, { + return this.botClient.doRequest("PUT", `/_matrix/client/v3/directory/list/appservice/${networkId}/${roomId}`, null, { visibility, }); } diff --git a/src/appservice/Intent.ts b/src/appservice/Intent.ts index 32766cfc..aec86e36 100644 --- a/src/appservice/Intent.ts +++ b/src/appservice/Intent.ts @@ -154,7 +154,7 @@ export class Intent { }, }; this.client.impersonateUserId(null); // avoid confusing homeserver - const res = await this.client.doRequest("POST", "/_matrix/client/r0/login", {}, loginBody); + const res = await this.client.doRequest("POST", "/_matrix/client/v3/login", {}, loginBody); this.makeClient(true, res['access_token']); storage.storeValue("accessToken", this.client.accessToken); prepared = true; @@ -299,7 +299,7 @@ export class Intent { public async ensureRegistered() { if (!(await Promise.resolve(this.storage.isUserRegistered(this.userId)))) { try { - const result = await this.client.doRequest("POST", "/_matrix/client/r0/register", null, { + const result = await this.client.doRequest("POST", "/_matrix/client/v3/register", null, { type: "m.login.application_service", username: this.userId.substring(1).split(":")[0], }); diff --git a/src/appservice/UnstableAppserviceApis.ts b/src/appservice/UnstableAppserviceApis.ts index 0a66c366..51481782 100644 --- a/src/appservice/UnstableAppserviceApis.ts +++ b/src/appservice/UnstableAppserviceApis.ts @@ -41,7 +41,7 @@ export class UnstableAppserviceApis { */ public async sendEventWithTimestamp(roomId: string, eventType: string, content: any, ts: number) { const txnId = `${(new Date().getTime())}__inc_appts${++this.requestId}`; - const path = `/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/${encodeURIComponent(txnId)}`; + const path = `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/${encodeURIComponent(txnId)}`; const response = await this.client.doRequest("PUT", path, { ts }, content); return response.event_id; } @@ -56,7 +56,7 @@ export class UnstableAppserviceApis { * @returns {Promise} resolves to the event ID that represents the message */ public async sendStateEventWithTimestamp(roomId: string, type: string, stateKey: string, content: any, ts: number): Promise { - const path = `/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(type)}/${encodeURIComponent(stateKey)}`; + const path = `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(type)}/${encodeURIComponent(stateKey)}`; const response = await this.client.doRequest("PUT", path, { ts }, content); return response.event_id; } diff --git a/src/e2ee/SdkOlmEngine.ts b/src/e2ee/SdkOlmEngine.ts index bc838d22..0153279a 100644 --- a/src/e2ee/SdkOlmEngine.ts +++ b/src/e2ee/SdkOlmEngine.ts @@ -38,7 +38,7 @@ export class SdkOlmEngine implements OlmEngine { } public uploadOneTimeKeys(body: { device_keys?: DeviceKeys, one_time_keys?: GenericKeys }): Promise { - return this.client.doRequest("POST", "/_matrix/client/r0/keys/upload", null, body); + return this.client.doRequest("POST", "/_matrix/client/v3/keys/upload", null, body); } public getEffectiveJoinedUsersInRoom(roomId: string): Promise { diff --git a/src/http.ts b/src/http.ts index 789aa2e5..951807b6 100644 --- a/src/http.ts +++ b/src/http.ts @@ -9,7 +9,7 @@ let lastRequestId = 0; * @category Unit testing * @param {string} baseUrl The base URL to apply to the call. * @param {"GET"|"POST"|"PUT"|"DELETE"} method The HTTP method to use in the request - * @param {string} endpoint The endpoint to call. For example: "/_matrix/client/r0/account/whoami" + * @param {string} endpoint The endpoint to call. For example: "/_matrix/client/v3/account/whoami" * @param {any} qs The query string to send. Optional. * @param {any} body The request body to send. Optional. Will be converted to JSON unless the type is a Buffer. * @param {any} headers Additional headers to send in the request. diff --git a/src/index.ts b/src/index.ts index 794603f4..a1a38074 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,7 @@ export * from "./models/Crypto"; export * from "./models/MSC2176"; export * from "./models/Account"; export * from "./models/PowerLevelAction"; +export * from "./models/ServerVersions"; // Unstable models export * from "./models/unstable/MediaInfo"; diff --git a/src/models/ServerVersions.ts b/src/models/ServerVersions.ts new file mode 100644 index 00000000..387925cd --- /dev/null +++ b/src/models/ServerVersions.ts @@ -0,0 +1,8 @@ +/** + * Representation of the server's supported specification versions and unstable feature flags. + * @category Models + */ +export type ServerVersions = { + unstable_features?: Record; + versions: string[]; +}; diff --git a/test/AdminApisTest.ts b/test/AdminApisTest.ts index cd4b2d51..c58a6dfe 100644 --- a/test/AdminApisTest.ts +++ b/test/AdminApisTest.ts @@ -34,8 +34,8 @@ describe('AdminApis', () => { }, }; - http.when("GET", "/_matrix/client/r0/admin/whois").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/admin/whois/${encodeURIComponent(userId)}`); + http.when("GET", "/_matrix/client/v3/admin/whois").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/admin/whois/${encodeURIComponent(userId)}`); return response; }); diff --git a/test/MatrixAuthTest.ts b/test/MatrixAuthTest.ts index 9a1bcaba..a1ddf721 100644 --- a/test/MatrixAuthTest.ts +++ b/test/MatrixAuthTest.ts @@ -28,7 +28,7 @@ describe('MatrixAuth', () => { const password = "P@ssw0rd"; const accessToken = "1234"; - http.when("POST", "/_matrix/client/r0/register").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/register").respond(200, (path, content) => { expect(content).toMatchObject({ username, password }); return { access_token: accessToken }; }); @@ -51,7 +51,7 @@ describe('MatrixAuth', () => { const sessionId = "5678"; // First is UIA - http.when("POST", "/_matrix/client/r0/register").respond(401, (path, content) => { + http.when("POST", "/_matrix/client/v3/register").respond(401, (path, content) => { expect(content).toMatchObject({ username, password }); return { session: sessionId, @@ -61,7 +61,7 @@ describe('MatrixAuth', () => { params: {}, }; }); - http.when("POST", "/_matrix/client/r0/register").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/register").respond(200, (path, content) => { expect(content).toMatchObject({ username, password, @@ -87,7 +87,7 @@ describe('MatrixAuth', () => { const password = "P@ssw0rd"; const accessToken = "1234"; - http.when("POST", "/_matrix/client/r0/login").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/login").respond(200, (path, content) => { expect(content).toMatchObject({ type: "m.login.password", identifier: { diff --git a/test/MatrixClientTest.ts b/test/MatrixClientTest.ts index d90287b3..a4991ca7 100644 --- a/test/MatrixClientTest.ts +++ b/test/MatrixClientTest.ts @@ -21,6 +21,7 @@ import { RoomDirectoryLookupResponse, RoomEvent, RustSdkCryptoStorageProvider, + ServerVersions, setRequestFn, } from "../src"; import { createTestClient, expectArrayEquals, TEST_DEVICE_ID } from "./TestUtils"; @@ -310,6 +311,113 @@ describe('MatrixClient', () => { }); }); + describe('getServerVersions', () => { + it('should call the right endpoint', async () => { + const { client, http } = createTestClient(); + + const versionsResponse: ServerVersions = { + unstable_features: { + "org.example.feature1": true, + "org.example.feature2": false, + }, + versions: ["r0.6.1", "r0.5.0", "v1.1", "v1.2"], + }; + + http.when("GET", "/_matrix/client/versions").respond(200, versionsResponse); + + const [result] = await Promise.all([client.getServerVersions(), http.flushAllExpected()]); + expect(result).toEqual(versionsResponse); + }); + + it('should cache the response', async () => { + const { client, http } = createTestClient(); + + const versionsResponse: ServerVersions = { + unstable_features: { + "org.example.feature1": true, + "org.example.feature2": false, + }, + versions: ["r0.6.1", "r0.5.0", "v1.1", "v1.2"], + }; + + http.when("GET", "/_matrix/client/versions").respond(200, versionsResponse); + + const [result] = await Promise.all([client.getServerVersions(), http.flushAllExpected()]); + expect(result).toEqual(versionsResponse); + const result2 = await client.getServerVersions(); + expect(result2).toBe(result); // looking for same pointer + + // clear the timer with private member access + (client).versionsLastFetched = 0; + http.when("GET", "/_matrix/client/versions").respond(200, versionsResponse); + + const [result3] = await Promise.all([client.getServerVersions(), http.flushAllExpected()]); + expect(result3).toEqual(versionsResponse); + }); + }); + + describe('doesServerSupportUnstableFeature', () => { + test.each(<[ServerVersions["unstable_features"], string, boolean][]>[ + [null, "org.example.feature", false], + [undefined, "org.example.feature", false], + [{}, "org.example.feature", false], + [{ "org.example.feature": true }, "org.example.feature", true], + [{ "org.example.feature": false }, "org.example.feature", false], + [{ "org.example.wrong": true }, "org.example.feature", false], + [{ "org.example.wrong": false }, "org.example.feature", false], + ])("should find that %p has %p as %p", async (versions, flag, target) => { + const { client, http } = createTestClient(); + + const versionsResponse: ServerVersions = { + versions: ["v1.1"], + unstable_features: versions, + }; + + http.when("GET", "/_matrix/client/versions").respond(200, versionsResponse); + + const [result] = await Promise.all([client.doesServerSupportUnstableFeature(flag), http.flushAllExpected()]); + expect(result).toEqual(target); + }); + }); + + describe('doesServerSupportVersion', () => { + test.each(<[ServerVersions["versions"], string, boolean][]>[ + [[], "v1.1", false], + [["v1.2"], "v1.1", false], + [["v1.1", "v1.2", "v1.3"], "v1.2", true], + ])("should find that %p has %p as %p", async (versions, version, target) => { + const { client, http } = createTestClient(); + + const versionsResponse: ServerVersions = { + versions: versions, + }; + + http.when("GET", "/_matrix/client/versions").respond(200, versionsResponse); + + const [result] = await Promise.all([client.doesServerSupportVersion(version), http.flushAllExpected()]); + expect(result).toEqual(target); + }); + }); + + describe('doesServerSupportAnyOneVersion', () => { + test.each(<[ServerVersions["versions"], string[], boolean][]>[ + [[], ["v1.1", "v1.2"], false], + [["v1.3"], ["v1.1", "v1.2"], false], + [["v1.1", "v1.2", "v1.3"], ["v1.2", "v1.3"], true], + ])("should find that %p has %p as %p", async (versions, searchVersions, target) => { + const { client, http } = createTestClient(); + + const versionsResponse: ServerVersions = { + versions: versions, + }; + + http.when("GET", "/_matrix/client/versions").respond(200, versionsResponse); + + const [result] = await Promise.all([client.doesServerSupportAnyOneVersion(searchVersions), http.flushAllExpected()]); + expect(result).toEqual(target); + }); + }); + describe('getOpenIDConnectToken', () => { it('should call the right endpoint', async () => { const { client, http, hsUrl } = createTestClient(); @@ -325,8 +433,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/user").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/openid/request_token`); + http.when("POST", "/_matrix/client/v3/user").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/openid/request_token`); return testToken; }); @@ -374,8 +482,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/user").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/account_data/${encodeURIComponent(eventType)}`); + http.when("GET", "/_matrix/client/v3/user").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/account_data/${encodeURIComponent(eventType)}`); return {}; }); @@ -393,8 +501,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/user").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/account_data/${encodeURIComponent(eventType)}`); + http.when("GET", "/_matrix/client/v3/user").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/account_data/${encodeURIComponent(eventType)}`); return {}; }); @@ -411,7 +519,7 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/user").respond(404, {}); + http.when("GET", "/_matrix/client/v3/user").respond(404, {}); const [ret] = await Promise.all([client.getSafeAccountData(eventType, defaultContent), http.flushAllExpected()]); expect(ret).toBe(defaultContent); @@ -433,8 +541,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/presence").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/presence/${encodeURIComponent(userId)}/status`); + http.when("GET", "/_matrix/client/v3/presence").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/presence/${encodeURIComponent(userId)}/status`); return presenceObj; }); @@ -456,8 +564,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/presence").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/presence/${encodeURIComponent(userId)}/status`); + http.when("GET", "/_matrix/client/v3/presence").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/presence/${encodeURIComponent(userId)}/status`); return presenceObj; }); @@ -477,8 +585,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/presence").respond(200, (path, obj) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/presence/${encodeURIComponent(userId)}/status`); + http.when("PUT", "/_matrix/client/v3/presence").respond(200, (path, obj) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/presence/${encodeURIComponent(userId)}/status`); expect(obj).toMatchObject({ presence: presence, status_msg: message, @@ -498,8 +606,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/presence").respond(200, (path, obj) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/presence/${encodeURIComponent(userId)}/status`); + http.when("PUT", "/_matrix/client/v3/presence").respond(200, (path, obj) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/presence/${encodeURIComponent(userId)}/status`); expect(obj).toEqual({ presence: presence, }); @@ -521,9 +629,9 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/user").respond(200, (path) => { + http.when("GET", "/_matrix/client/v3/user").respond(200, (path) => { // eslint-disable-next-line max-len - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(eventType)}`); + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(eventType)}`); return {}; }); @@ -542,9 +650,9 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/user").respond(200, (path) => { + http.when("GET", "/_matrix/client/v3/user").respond(200, (path) => { // eslint-disable-next-line max-len - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(eventType)}`); + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(eventType)}`); return {}; }); @@ -562,7 +670,7 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/user").respond(404, {}); + http.when("GET", "/_matrix/client/v3/user").respond(404, {}); const [ret] = await Promise.all([client.getSafeRoomAccountData(eventType, roomId, defaultContent), http.flushAllExpected()]); expect(ret).toBe(defaultContent); @@ -580,8 +688,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/user").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/account_data/${encodeURIComponent(eventType)}`); + http.when("PUT", "/_matrix/client/v3/user").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/account_data/${encodeURIComponent(eventType)}`); expect(content).toMatchObject(eventContent); return {}; }); @@ -602,9 +710,9 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/user").respond(200, (path, content) => { + http.when("PUT", "/_matrix/client/v3/user").respond(200, (path, content) => { // eslint-disable-next-line max-len - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(eventType)}`); + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent(roomId)}/account_data/${encodeURIComponent(eventType)}`); expect(content).toMatchObject(eventContent); return {}; }); @@ -620,7 +728,7 @@ describe('MatrixClient', () => { const roomId = "!abc:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms/").respond(404, {}); + http.when("GET", "/_matrix/client/v3/rooms/").respond(404, {}); const [published] = await Promise.all([client.getPublishedAlias(roomId), http.flushAllExpected()]); expect(published).toBeFalsy(); @@ -632,7 +740,7 @@ describe('MatrixClient', () => { const roomId = "!abc:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms/").respond(200, {}); + http.when("GET", "/_matrix/client/v3/rooms/").respond(200, {}); const [published] = await Promise.all([client.getPublishedAlias(roomId), http.flushAllExpected()]); expect(published).toBeFalsy(); @@ -646,7 +754,7 @@ describe('MatrixClient', () => { const alias2 = "#test2:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms/").respond(200, { + http.when("GET", "/_matrix/client/v3/rooms/").respond(200, { alias: alias1, alt_aliases: [alias2], }); @@ -663,7 +771,7 @@ describe('MatrixClient', () => { const alias2 = "#test2:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms/").respond(200, { + http.when("GET", "/_matrix/client/v3/rooms/").respond(200, { alt_aliases: [alias2, alias1], }); @@ -680,8 +788,8 @@ describe('MatrixClient', () => { const roomId = "!abc:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/directory/room/").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/directory/room/${encodeURIComponent(alias)}`); + http.when("PUT", "/_matrix/client/v3/directory/room/").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/directory/room/${encodeURIComponent(alias)}`); expect(content).toMatchObject({ room_id: roomId }); return {}; }); @@ -697,8 +805,8 @@ describe('MatrixClient', () => { const alias = "#test:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("DELETE", "/_matrix/client/r0/directory/room/").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/directory/room/${encodeURIComponent(alias)}`); + http.when("DELETE", "/_matrix/client/v3/directory/room/").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/directory/room/${encodeURIComponent(alias)}`); return {}; }); @@ -714,8 +822,8 @@ describe('MatrixClient', () => { const visibility = "public"; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/directory/list/room/").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/directory/list/room/${encodeURIComponent(roomId)}`); + http.when("PUT", "/_matrix/client/v3/directory/list/room/").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/directory/list/room/${encodeURIComponent(roomId)}`); expect(content).toMatchObject({ visibility: visibility }); return {}; }); @@ -731,8 +839,8 @@ describe('MatrixClient', () => { const roomId = "!test:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/directory/list/room/").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/directory/list/room/${encodeURIComponent(roomId)}`); + http.when("GET", "/_matrix/client/v3/directory/list/room/").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/directory/list/room/${encodeURIComponent(roomId)}`); return {}; }); @@ -746,7 +854,7 @@ describe('MatrixClient', () => { const visibility = "public"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/directory/list/room/").respond(200, { visibility: visibility }); + http.when("GET", "/_matrix/client/v3/directory/list/room/").respond(200, { visibility: visibility }); const [result] = await Promise.all([client.getDirectoryVisibility(roomId), http.flushAllExpected()]); expect(result).toEqual(visibility); @@ -802,8 +910,8 @@ describe('MatrixClient', () => { const servers = ["example.org", "localhost"]; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/directory/room/").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/directory/room/${encodeURIComponent(alias)}`); + http.when("GET", "/_matrix/client/v3/directory/room/").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/directory/room/${encodeURIComponent(alias)}`); return { room_id: roomId, servers: servers }; }); @@ -818,7 +926,7 @@ describe('MatrixClient', () => { const servers = ["example.org", "localhost"]; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/directory/room/").respond(200, { room_id: roomId, servers: servers }); + http.when("GET", "/_matrix/client/v3/directory/room/").respond(200, { room_id: roomId, servers: servers }); const [result] = await Promise.all([client.lookupRoomAlias(alias), http.flushAllExpected()]); expect(result).toMatchObject({ roomId: roomId, residentServers: servers }); @@ -833,8 +941,8 @@ describe('MatrixClient', () => { const userId = "@example:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/invite`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/invite`); expect(content).toMatchObject({ user_id: userId }); return {}; }); @@ -851,8 +959,8 @@ describe('MatrixClient', () => { const userId = "@example:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/kick`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/kick`); expect(content).toMatchObject({ user_id: userId }); return {}; }); @@ -868,8 +976,8 @@ describe('MatrixClient', () => { const reason = "Excessive unit testing"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/kick`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/kick`); expect(content).toMatchObject({ user_id: userId, reason: reason }); return {}; }); @@ -886,8 +994,8 @@ describe('MatrixClient', () => { const userId = "@example:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/ban`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/ban`); expect(content).toMatchObject({ user_id: userId }); return {}; }); @@ -903,8 +1011,8 @@ describe('MatrixClient', () => { const reason = "Excessive unit testing"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/ban`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/ban`); expect(content).toMatchObject({ user_id: userId, reason: reason }); return {}; }); @@ -921,8 +1029,8 @@ describe('MatrixClient', () => { const userId = "@example:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/unban`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/unban`); expect(content).toMatchObject({ user_id: userId }); return {}; }); @@ -952,7 +1060,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/account/whoami").respond(200, response); + http.when("GET", "/_matrix/client/v3/account/whoami").respond(200, response); const [result] = await Promise.all([client.getUserId(), http.flushAllExpected()]); expect(result).toEqual(userId); @@ -969,7 +1077,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/account/whoami").respond(200, response); + http.when("GET", "/_matrix/client/v3/account/whoami").respond(200, response); const [result] = await Promise.all([client.getWhoAmI(), http.flushAllExpected()]); expect(result).toMatchObject(response); @@ -990,12 +1098,12 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); const waitPromise = new Promise((resolve) => { for (let i = 0; i <= max * 2; i++) { // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, () => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, () => { expect(count).toBeLessThan(max + 1); count++; if (count === max) { @@ -1036,10 +1144,10 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, () => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, () => { client.stop(); return { next_batch: "123" }; }); @@ -1071,11 +1179,11 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/user").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/filter`); + http.when("POST", "/_matrix/client/v3/user").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/filter`); expect(content).toMatchObject(filter); client.stop(); // avoid a sync early return { filter_id: filterId }; @@ -1109,11 +1217,11 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/user").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/user/${encodeURIComponent(userId)}/filter`); + http.when("POST", "/_matrix/client/v3/user").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/user/${encodeURIComponent(userId)}/filter`); expect(content).toMatchObject(filter); client.stop(); // avoid a sync early return { filter_id: filterId }; @@ -1142,10 +1250,10 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, (path, content, req) => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, (path, content, req) => { expect(req).toBeDefined(); expect(req.opts.qs.filter).toEqual(filterId); client.stop(); @@ -1180,16 +1288,16 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, (path, content, req) => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, (path, content, req) => { expect(req).toBeDefined(); expect(req.opts.qs.since).toBeUndefined(); return { next_batch: secondToken }; }); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, (path, content, req) => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, (path, content, req) => { expect(req).toBeDefined(); expect(req.opts.qs.since).toEqual(secondToken); client.stop(); @@ -1226,10 +1334,10 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, (path, content, req) => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, (path, content, req) => { expect(req).toBeDefined(); expect(req.opts.qs.since).toEqual(syncToken); @@ -1262,17 +1370,17 @@ describe('MatrixClient', () => { // The sync handler checks which rooms it should ignore // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, { joined_rooms: [] }); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, { joined_rooms: [] }); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, (path, content, req) => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, (path, content, req) => { expect(req).toBeDefined(); expect(req.opts.qs.presence).toBeUndefined(); client.syncingPresence = presence; return { next_batch: "testing" }; }); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/sync").respond(200, (path, content, req) => { + http.when("GET", "/_matrix/client/v3/sync").respond(200, (path, content, req) => { expect(req).toBeDefined(); expect(req.opts.qs.presence).toEqual(presence); client.stop(); @@ -2237,8 +2345,8 @@ describe('MatrixClient', () => { const event = { type: "m.room.message" }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); return event; }); @@ -2263,8 +2371,8 @@ describe('MatrixClient', () => { client.addPreprocessor(processor); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); return event; }); @@ -2305,8 +2413,8 @@ describe('MatrixClient', () => { (client).processEvent = processSpy; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); return event; }); @@ -2349,8 +2457,8 @@ describe('MatrixClient', () => { (client).processEvent = processSpy; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); return event; }); @@ -2371,8 +2479,8 @@ describe('MatrixClient', () => { const event = { type: "m.room.message" }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); return event; }); @@ -2397,8 +2505,8 @@ describe('MatrixClient', () => { client.addPreprocessor(processor); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); return event; }); @@ -2439,8 +2547,8 @@ describe('MatrixClient', () => { (client).processEvent = processSpy; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/event/${encodeURIComponent(eventId)}`); return event; }); @@ -2460,8 +2568,8 @@ describe('MatrixClient', () => { const events = [{ type: "m.room.message" }, { type: "m.room.not_message" }]; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state`); return events; }); @@ -2489,8 +2597,8 @@ describe('MatrixClient', () => { client.addPreprocessor(processor); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state`); return events; }); @@ -2517,8 +2625,8 @@ describe('MatrixClient', () => { const event = { type: "m.room.message" }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); return event; }); @@ -2535,8 +2643,8 @@ describe('MatrixClient', () => { const stateKey = "testing"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/${stateKey}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/${stateKey}`); return event; }); @@ -2561,8 +2669,8 @@ describe('MatrixClient', () => { client.addPreprocessor(processor); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); return event; }); @@ -2589,8 +2697,8 @@ describe('MatrixClient', () => { client.addPreprocessor(processor); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/${stateKey}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/${stateKey}`); return event; }); @@ -2626,8 +2734,8 @@ describe('MatrixClient', () => { const limit = 2; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path, content, req) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/context/${encodeURIComponent(targetEvent.eventId)}`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path, content, req) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/context/${encodeURIComponent(targetEvent.eventId)}`); expect(req.opts.qs['limit']).toEqual(limit); return { event: targetEvent, @@ -2670,8 +2778,8 @@ describe('MatrixClient', () => { const profile = { displayname: "testing", avatar_url: "testing", extra: "testing" }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/profile").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/profile/${encodeURIComponent(userId)}`); + http.when("GET", "/_matrix/client/v3/profile").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/profile/${encodeURIComponent(userId)}`); return profile; }); @@ -2687,7 +2795,7 @@ describe('MatrixClient', () => { const roomId = "!something:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/createRoom").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/createRoom").respond(200, (path, content) => { expect(content).toMatchObject({}); return { room_id: roomId }; }); @@ -2706,7 +2814,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/createRoom").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/createRoom").respond(200, (path, content) => { expect(content).toMatchObject(properties); return { room_id: roomId }; }); @@ -2726,8 +2834,8 @@ describe('MatrixClient', () => { (client).userId = userId; // avoid /whoami lookup // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/profile").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/profile/${encodeURIComponent(userId)}/displayname`); + http.when("PUT", "/_matrix/client/v3/profile").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/profile/${encodeURIComponent(userId)}/displayname`); expect(content).toMatchObject({ displayname: displayName }); return {}; }); @@ -2746,8 +2854,8 @@ describe('MatrixClient', () => { (client).userId = userId; // avoid /whoami lookup // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/profile").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/profile/${encodeURIComponent(userId)}/avatar_url`); + http.when("PUT", "/_matrix/client/v3/profile").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/profile/${encodeURIComponent(userId)}/avatar_url`); expect(content).toMatchObject({ avatar_url: displayName }); return {}; }); @@ -2765,8 +2873,8 @@ describe('MatrixClient', () => { (client).userId = "@joins:example.org"; // avoid /whoami lookup // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/join").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/join/${encodeURIComponent(roomId)}`); + http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`); return { room_id: roomId }; }); @@ -2783,8 +2891,8 @@ describe('MatrixClient', () => { (client).userId = "@joins:example.org"; // avoid /whoami lookup // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/join").respond(200, (path, content, req) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/join/${encodeURIComponent(roomId)}`); + http.when("POST", "/_matrix/client/v3/join").respond(200, (path, content, req) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`); expect(req.opts.qs['server_name'].length).toEqual(serverNames.length); for (let i = 0; i < serverNames.length; i++) { expect(req.opts.qs['server_name'][i]).toEqual(serverNames[i]); @@ -2805,8 +2913,8 @@ describe('MatrixClient', () => { (client).userId = "@joins:example.org"; // avoid /whoami lookup // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/join").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/join/${encodeURIComponent(roomAlias)}`); + http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomAlias)}`); return { room_id: roomId }; }); @@ -2833,8 +2941,8 @@ describe('MatrixClient', () => { const strategySpy = simple.mock(strategy, "joinRoom").callOriginal(); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/join").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/join/${encodeURIComponent(roomId)}`); + http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`); return { room_id: roomId }; }); @@ -2863,8 +2971,8 @@ describe('MatrixClient', () => { const strategySpy = simple.mock(strategy, "joinRoom").callOriginal(); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/join").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/join/${encodeURIComponent(roomId)}`); + http.when("POST", "/_matrix/client/v3/join").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/join/${encodeURIComponent(roomId)}`); return { room_id: roomId }; }); @@ -2881,8 +2989,8 @@ describe('MatrixClient', () => { const roomIds = ["!abc:example.org", "!123:example.org"]; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/joined_rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/joined_rooms`); + http.when("GET", "/_matrix/client/v3/joined_rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/joined_rooms`); return { joined_rooms: roomIds }; }); @@ -2899,8 +3007,8 @@ describe('MatrixClient', () => { const members = ["@alice:example.org", "@bob:example.org"]; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/joined_members`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/joined_members`); const obj = {}; for (const member of members) obj[member] = { membership: "join" }; return { joined: obj }; @@ -2927,8 +3035,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, path => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/joined_members`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, path => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/joined_members`); return { joined: members }; }); @@ -2961,8 +3069,8 @@ describe('MatrixClient', () => { ]; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/members`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/members`); return { chunk: memberEvents }; }); @@ -2999,8 +3107,8 @@ describe('MatrixClient', () => { const atToken = "test_token"; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path, content, req) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/members`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path, content, req) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/members`); expect(req.opts.qs.at).toEqual(atToken); return { chunk: memberEvents }; }); @@ -3039,8 +3147,8 @@ describe('MatrixClient', () => { const forNotMemberships: Membership[] = ['ban']; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/rooms").respond(200, (path, content, req) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/members`); + http.when("GET", "/_matrix/client/v3/rooms").respond(200, (path, content, req) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/members`); expectArrayEquals(forMemberships, req.opts.qs.membership); expectArrayEquals(forNotMemberships, req.opts.qs.not_membership); return { chunk: memberEvents }; @@ -3063,8 +3171,8 @@ describe('MatrixClient', () => { const roomId = "!testing:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/leave`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/leave`); return {}; }); @@ -3080,8 +3188,8 @@ describe('MatrixClient', () => { const eventId = "$something:example.org"; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/rooms").respond(200, (path) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/receipt/m.read/${encodeURIComponent(eventId)}`); + http.when("POST", "/_matrix/client/v3/rooms").respond(200, (path) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/receipt/m.read/${encodeURIComponent(eventId)}`); return {}; }); @@ -3101,8 +3209,8 @@ describe('MatrixClient', () => { client.getUserId = () => Promise.resolve(userId); // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/typing/${encodeURIComponent(userId)}`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/typing/${encodeURIComponent(userId)}`); expect(content).toMatchObject({ typing: typing, timeout: timeout }); return {}; }); @@ -3142,8 +3250,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3195,8 +3303,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3238,8 +3346,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3279,8 +3387,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3322,8 +3430,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3375,8 +3483,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3418,8 +3526,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3461,8 +3569,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3514,8 +3622,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3557,8 +3665,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3598,8 +3706,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3641,8 +3749,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3694,8 +3802,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3737,8 +3845,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedContent); return { event_id: eventId }; @@ -3761,8 +3869,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3796,8 +3904,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3820,8 +3928,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3846,8 +3954,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3883,8 +3991,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3909,8 +4017,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3933,8 +4041,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3968,8 +4076,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -3992,8 +4100,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4018,8 +4126,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4055,8 +4163,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4081,8 +4189,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4106,8 +4214,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4142,8 +4250,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.encrypted/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4167,8 +4275,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4192,8 +4300,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4229,8 +4337,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(sEventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(sEventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4254,8 +4362,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => false; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4279,8 +4387,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4304,8 +4412,8 @@ describe('MatrixClient', () => { client.crypto.isRoomEncrypted = async () => true; // for this test // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4331,8 +4439,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4356,8 +4464,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); return { event_id: eventId }; @@ -4377,8 +4485,8 @@ describe('MatrixClient', () => { const reason = "Zvarri!"; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}/`); expect(idx).toBe(0); expect(content).toMatchObject({ reason }); return { event_id: eventId }; @@ -5263,7 +5371,7 @@ describe('MatrixClient', () => { const mxc = `mxc://${domain}/${mediaId}`; const http = client.mxcToHttp(mxc); - expect(http).toBe(`${hsUrl}/_matrix/media/r0/download/${encodeURIComponent(domain)}/${encodeURIComponent(mediaId)}`); + expect(http).toBe(`${hsUrl}/_matrix/media/v3/download/${encodeURIComponent(domain)}/${encodeURIComponent(mediaId)}`); }); it('should error for non-MXC URIs', async () => { @@ -5297,7 +5405,7 @@ describe('MatrixClient', () => { const http = client.mxcToHttpThumbnail(mxc, width, height, method); // eslint-disable-next-line max-len - expect(http).toBe(`${hsUrl}/_matrix/media/r0/thumbnail/${encodeURIComponent(domain)}/${encodeURIComponent(mediaId)}?width=${width}&height=${height}&method=${encodeURIComponent(method)}`); + expect(http).toBe(`${hsUrl}/_matrix/media/v3/thumbnail/${encodeURIComponent(domain)}/${encodeURIComponent(mediaId)}?width=${width}&height=${height}&method=${encodeURIComponent(method)}`); }); it('should error for non-MXC URIs', async () => { @@ -5333,7 +5441,7 @@ describe('MatrixClient', () => { Buffer.isBuffer = (i => i === data); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/media/r0/upload").respond(200, (path, content, req) => { + http.when("POST", "/_matrix/media/v3/upload").respond(200, (path, content, req) => { expect(content).toBeDefined(); expect(req.opts.qs.filename).toEqual(filename); expect(req.opts.headers["Content-Type"]).toEqual(contentType); @@ -5356,7 +5464,7 @@ describe('MatrixClient', () => { Buffer.isBuffer = (i => i === data); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/media/r0/upload").respond(200, (path, content, req) => { + http.when("POST", "/_matrix/media/v3/upload").respond(200, (path, content, req) => { expect(content).toBeDefined(); expect(req.opts.qs.filename).toEqual(filename); expect(req.opts.headers["Content-Type"]).toEqual(contentType); @@ -5377,8 +5485,8 @@ describe('MatrixClient', () => { // const fileContents = new Buffer("12345"); // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/media/r0/download/").respond(200, (path, _, req) => { - expect(path).toContain("/_matrix/media/r0/download/" + urlPart); + http.when("GET", "/_matrix/media/v3/download/").respond(200, (path, _, req) => { + expect(path).toContain("/_matrix/media/v3/download/" + urlPart); expect(req.opts.encoding).toEqual(null); // TODO: Honestly, I have no idea how to coerce the mock library to return headers or buffers, // so this is left as a fun activity. @@ -5414,7 +5522,7 @@ describe('MatrixClient', () => { }); // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/media/r0/upload").respond(200, (path, content, req) => { + http.when("POST", "/_matrix/media/v3/upload").respond(200, (path, content, req) => { expect(content).toBeDefined(); // HACK: We know the mock library will return JSON expect(req.opts.headers["Content-Type"]).toEqual("application/json"); @@ -6230,7 +6338,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/createRoom").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/createRoom").respond(200, (path, content) => { expect(content).toMatchObject(expectedRequest); return { room_id: roomId }; }); @@ -6278,7 +6386,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/createRoom").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/createRoom").respond(200, (path, content) => { expect(content).toMatchObject(expectedRequest); return { room_id: roomId }; }); @@ -6403,7 +6511,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/keys/upload").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/keys/upload").respond(200, (path, content) => { expect(content).toMatchObject({ device_keys: { user_id: userId, @@ -6460,7 +6568,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/keys/upload").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/keys/upload").respond(200, (path, content) => { expect(content).toMatchObject({ one_time_keys: keys, }); @@ -6495,7 +6603,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/keys/upload").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/keys/upload").respond(200, (path, content) => { expect(content).toMatchObject({}); return { one_time_key_counts: counts }; }); @@ -6530,7 +6638,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/keys/query").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/keys/query").respond(200, (path, content) => { expect(content).toMatchObject({ timeout, device_keys: requestBody }); return response; }); @@ -6563,7 +6671,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/keys/query").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/keys/query").respond(200, (path, content) => { expect(content).toMatchObject({ timeout: 10000, device_keys: requestBody }); return response; }); @@ -6614,7 +6722,7 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/keys/claim").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/keys/claim").respond(200, (path, content) => { expect(content).toMatchObject({ timeout: 10000, one_time_keys: request, @@ -6656,7 +6764,7 @@ describe('MatrixClient', () => { const timeout = 60; // noinspection TypeScriptValidateJSTypes - http.when("POST", "/_matrix/client/r0/keys/claim").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/keys/claim").respond(200, (path, content) => { expect(content).toMatchObject({ timeout: timeout, one_time_keys: request, @@ -6689,8 +6797,8 @@ describe('MatrixClient', () => { }; // noinspection TypeScriptValidateJSTypes - http.when("PUT", "/_matrix/client/r0/sendToDevice").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/sendToDevice/${encodeURIComponent(type)}/`); + http.when("PUT", "/_matrix/client/v3/sendToDevice").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/sendToDevice/${encodeURIComponent(type)}/`); expect(idx).toBe(0); expect(content).toMatchObject({ messages }); return {}; @@ -6708,7 +6816,7 @@ describe('MatrixClient', () => { const devices = ["schema not followed for simplicity"]; // noinspection TypeScriptValidateJSTypes - http.when("GET", "/_matrix/client/r0/devices").respond(200, () => { + http.when("GET", "/_matrix/client/v3/devices").respond(200, () => { return { devices }; }); diff --git a/test/SynapseAdminApisTest.ts b/test/SynapseAdminApisTest.ts index 0465bb92..d48b8451 100644 --- a/test/SynapseAdminApisTest.ts +++ b/test/SynapseAdminApisTest.ts @@ -73,7 +73,7 @@ describe('SynapseAdminApis', () => { const userId = "@someone:example.org"; const response = { admin: true }; - http.when("GET", "/_matrix/client/r0/account/whoami").respond(200, (path, content) => { + http.when("GET", "/_matrix/client/v3/account/whoami").respond(200, (path, content) => { return { user_id: userId }; }); http.when("GET", "/_synapse/admin/v1/users").respond(200, (path, content) => { @@ -90,7 +90,7 @@ describe('SynapseAdminApis', () => { const userId = "@someone:example.org"; - http.when("GET", "/_matrix/client/r0/account/whoami").respond(200, (path, content) => { + http.when("GET", "/_matrix/client/v3/account/whoami").respond(200, (path, content) => { return { user_id: userId }; }); http.when("GET", "/_synapse/admin/v1/users").respond(200, (path, content) => { diff --git a/test/UnstableApisTest.ts b/test/UnstableApisTest.ts index 335f09bd..f8a046aa 100644 --- a/test/UnstableApisTest.ts +++ b/test/UnstableApisTest.ts @@ -416,8 +416,8 @@ describe('UnstableApis', () => { }, }; - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/m.reaction/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.reaction/`); expect(idx).toBe(0); expect(content).toMatchObject(expectedReaction); return { event_id: newEventId }; diff --git a/test/appservice/AppserviceTest.ts b/test/appservice/AppserviceTest.ts index 94a6c02e..a804f6e4 100644 --- a/test/appservice/AppserviceTest.ts +++ b/test/appservice/AppserviceTest.ts @@ -1774,13 +1774,13 @@ describe('Appservice', () => { // eslint-disable-next-line no-inner-declarations async function doCall(route: string, opts: any = {}) { - http.when("PUT", "/_matrix/client/r0/profile").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/profile/${encodeURIComponent(userId)}/displayname`); + http.when("PUT", "/_matrix/client/v3/profile").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/profile/${encodeURIComponent(userId)}/displayname`); expect(content).toMatchObject({ displayname: displayName }); return {}; }); - http.when("PUT", "/_matrix/client/r0/profile").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/profile/${encodeURIComponent(userId)}/avatar_url`); + http.when("PUT", "/_matrix/client/v3/profile").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/profile/${encodeURIComponent(userId)}/avatar_url`); expect(content).toMatchObject({ avatar_url: avatarUrl }); return {}; }); @@ -1858,13 +1858,13 @@ describe('Appservice', () => { // eslint-disable-next-line no-inner-declarations async function doCall(route: string, opts: any = {}) { - http.when("PUT", "/_matrix/client/r0/profile").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/profile/${encodeURIComponent(userId)}/displayname`); + http.when("PUT", "/_matrix/client/v3/profile").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/profile/${encodeURIComponent(userId)}/displayname`); expect(content).toMatchObject({ displayname: displayName }); return {}; }); - http.when("PUT", "/_matrix/client/r0/profile").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/profile/${encodeURIComponent(userId)}/avatar_url`); + http.when("PUT", "/_matrix/client/v3/profile").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/profile/${encodeURIComponent(userId)}/avatar_url`); expect(content).toMatchObject({ avatar_url: avatarUrl }); return {}; }); @@ -2727,8 +2727,8 @@ describe('Appservice', () => { const http = new MockHttpBackend(); setRequestFn(http.requestFn); - http.when("PUT", "/_matrix/client/r0/directory/list/appservice").respond(200, (path, content) => { - expect(path).toEqual(`${hsUrl}/_matrix/client/r0/directory/list/appservice/${encodeURIComponent(networkId)}/${encodeURIComponent(roomId)}`); + http.when("PUT", "/_matrix/client/v3/directory/list/appservice").respond(200, (path, content) => { + expect(path).toEqual(`${hsUrl}/_matrix/client/v3/directory/list/appservice/${encodeURIComponent(networkId)}/${encodeURIComponent(roomId)}`); expect(content).toMatchObject({ visibility: "public" }); return {}; }); diff --git a/test/appservice/IntentTest.ts b/test/appservice/IntentTest.ts index 32ef9ce6..eacf37d5 100644 --- a/test/appservice/IntentTest.ts +++ b/test/appservice/IntentTest.ts @@ -166,7 +166,7 @@ describe('Intent', () => { }, }; - http.when("POST", "/_matrix/client/r0/register").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/register").respond(200, (path, content) => { expect(content).toMatchObject({ type: "m.login.application_service", username: "someone" }); return {}; }); @@ -206,7 +206,7 @@ describe('Intent', () => { }; // HACK: 200 OK because the mock lib can't handle 400+response body - http.when("POST", "/_matrix/client/r0/register").respond(200, (path, content) => { + http.when("POST", "/_matrix/client/v3/register").respond(200, (path, content) => { expect(content).toMatchObject({ type: "m.login.application_service", username: "someone" }); return { errcode: "M_USER_IN_USE", error: "User ID already in use" }; }); @@ -245,7 +245,7 @@ describe('Intent', () => { }, }; - http.when("POST", "/_matrix/client/r0/register").respond(500, (path, content) => { + http.when("POST", "/_matrix/client/v3/register").respond(500, (path, content) => { expect(content).toMatchObject({ type: "m.login.application_service", username: "someone" }); return { errcode: "M_UNKNOWN", error: "It broke" }; }); diff --git a/test/appservice/UnstableAppserviceApisTest.ts b/test/appservice/UnstableAppserviceApisTest.ts index 3f4d0cf5..49062296 100644 --- a/test/appservice/UnstableAppserviceApisTest.ts +++ b/test/appservice/UnstableAppserviceApisTest.ts @@ -72,8 +72,8 @@ describe('UnstableAppserviceApis', () => { }; const ts = 5000; - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content, { opts }) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content, { opts }) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); expect(opts.qs).toMatchObject({ ts }); @@ -100,8 +100,8 @@ describe('UnstableAppserviceApis', () => { }; const ts = 5000; - http.when("PUT", "/_matrix/client/r0/rooms").respond(200, (path, content, { opts }) => { - const idx = path.indexOf(`${hsUrl}/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); + http.when("PUT", "/_matrix/client/v3/rooms").respond(200, (path, content, { opts }) => { + const idx = path.indexOf(`${hsUrl}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/${encodeURIComponent(eventType)}/`); expect(idx).toBe(0); expect(content).toMatchObject(eventContent); expect(opts.qs).toMatchObject({ ts });