From e592f60240fa143fff37d4eda0cd0f7a4ebbf4ac Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 18 Oct 2022 12:49:21 +0100 Subject: [PATCH 1/8] Prepare changelog for v21.0.0-rc.1 --- CHANGELOG.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce41de1aa..7cd42c032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,29 @@ +Changes in [21.0.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.0-rc.1) (2022-10-18) +============================================================================================================ + +## 🚨 BREAKING CHANGES + * Changes the `uploadContent` API, kills off `request` and `browser-request` in favour of `fetch`, removed callback support on a lot of the methods, adds a lot of tests. ([\#2719](https://github.com/matrix-org/matrix-js-sdk/pull/2719)). Fixes #2415 and #801. + * Remove deprecated `m.room.aliases` references ([\#2759](https://github.com/matrix-org/matrix-js-sdk/pull/2759)). Fixes vector-im/element-web#12680. + +## ✨ Features + * Remove node-specific crypto bits, use Node 16's WebCrypto ([\#2762](https://github.com/matrix-org/matrix-js-sdk/pull/2762)). Fixes #2760. + * Export types for MatrixEvent and Room emitted events, and make event handler map types stricter ([\#2750](https://github.com/matrix-org/matrix-js-sdk/pull/2750)). Contributed by @stas-demydiuk. + * Use even more stable calls to `/room_keys` ([\#2746](https://github.com/matrix-org/matrix-js-sdk/pull/2746)). + * Upgrade to Olm 3.2.13 which has been repackaged to support Node 18 ([\#2744](https://github.com/matrix-org/matrix-js-sdk/pull/2744)). + * Fix `power_level_content_override` type ([\#2741](https://github.com/matrix-org/matrix-js-sdk/pull/2741)). + * Add custom notification handling for MSC3401 call events ([\#2720](https://github.com/matrix-org/matrix-js-sdk/pull/2720)). + * Add support for unread thread notifications ([\#2726](https://github.com/matrix-org/matrix-js-sdk/pull/2726)). + * Load Thread List with server-side assistance (MSC3856) ([\#2602](https://github.com/matrix-org/matrix-js-sdk/pull/2602)). + * Use stable calls to `/room_keys` ([\#2729](https://github.com/matrix-org/matrix-js-sdk/pull/2729)). Fixes vector-im/element-web#22839. + +## 🐛 Bug Fixes + * Fix IdentityPrefix.V2 containing spurious `/api` ([\#2761](https://github.com/matrix-org/matrix-js-sdk/pull/2761)). Fixes vector-im/element-web#23505. + * Always send back an httpStatus property if one is known ([\#2753](https://github.com/matrix-org/matrix-js-sdk/pull/2753)). + * Check for AbortError, not any generic connection error, to avoid tightlooping ([\#2752](https://github.com/matrix-org/matrix-js-sdk/pull/2752)). + * Correct the dir parameter of MSC3715 ([\#2745](https://github.com/matrix-org/matrix-js-sdk/pull/2745)). Contributed by @dhenneke. + * Fix sync init when thread unread notif is not supported ([\#2739](https://github.com/matrix-org/matrix-js-sdk/pull/2739)). Fixes vector-im/element-web#23435. + * Use the correct sender key when checking shared secret ([\#2730](https://github.com/matrix-org/matrix-js-sdk/pull/2730)). Fixes vector-im/element-web#23374. + Changes in [20.1.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v20.1.0) (2022-10-11) ============================================================================================================ From fc1b03c0bf0ff71d23e1f575314b6fcb7cfc70e9 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 18 Oct 2022 12:49:22 +0100 Subject: [PATCH 2/8] v21.0.0-rc.1 --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 710bb281d..8ec8d5473 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "20.1.0", + "version": "21.0.0-rc.1", "description": "Matrix Client-Server SDK for Javascript", "engines": { "node": ">=16.0.0" @@ -32,7 +32,7 @@ "keywords": [ "matrix-org" ], - "main": "./src/index.ts", + "main": "./lib/index.js", "browser": "./lib/browser-index.js", "matrix_src_main": "./src/index.ts", "matrix_src_browser": "./src/browser-index.js", @@ -129,5 +129,6 @@ "jestSonar": { "reportPath": "coverage", "sonar56x": true - } + }, + "typings": "./lib/index.d.ts" } From 63f4bf571ebdd3147842197e759e8cfd999a9135 Mon Sep 17 00:00:00 2001 From: ElementRobot Date: Tue, 18 Oct 2022 16:03:40 +0100 Subject: [PATCH 3/8] [Backport staging] Fix POST data not being passed for registerWithIdentityServer (#2770) Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- spec/integ/matrix-client-methods.spec.ts | 40 +++++++++++++++++++++++- src/client.ts | 16 +++++----- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/spec/integ/matrix-client-methods.spec.ts b/spec/integ/matrix-client-methods.spec.ts index 954df27fd..273491e70 100644 --- a/spec/integ/matrix-client-methods.spec.ts +++ b/spec/integ/matrix-client-methods.spec.ts @@ -1254,6 +1254,20 @@ describe("MatrixClient", function() { }); }); + describe("agreeToTerms", () => { + it("should send `user_accepts` via body of POST request", async () => { + const terms = ["https://vector.im/notice-1"]; + + httpBackend!.when("POST", "/terms").check(req => { + expect(req.data.user_accepts).toStrictEqual(terms); + }).respond(200, {}); + + const prom = client!.agreeToTerms(SERVICE_TYPES.IS, "https://vector.im", "at", terms); + await httpBackend!.flushAllExpected(); + await prom; + }); + }); + describe("publicRooms", () => { it("should use GET request if no server or filter is specified", () => { httpBackend!.when("GET", "/publicRooms").respond(200, {}); @@ -1263,7 +1277,7 @@ describe("MatrixClient", function() { it("should use GET request if only server is specified", () => { httpBackend!.when("GET", "/publicRooms").check(request => { - expect(request.queryParams.server).toBe("server1"); + expect(request.queryParams?.server).toBe("server1"); }).respond(200, {}); client!.publicRooms({ server: "server1" }); return httpBackend!.flushAllExpected(); @@ -1296,6 +1310,30 @@ describe("MatrixClient", function() { expect(client.http.opts.accessToken).toBe(token); }); }); + + describe("registerWithIdentityServer", () => { + it("should pass data to POST request", async () => { + const token = { + access_token: "access_token", + token_type: "Bearer", + matrix_server_name: "server_name", + expires_in: 12345, + }; + + httpBackend!.when("POST", "/account/register").check(req => { + expect(req.data).toStrictEqual(token); + }).respond(200, { + access_token: "at", + token: "tt", + }); + + const prom = client!.registerWithIdentityServer(token); + await httpBackend!.flushAllExpected(); + const resp = await prom; + expect(resp.access_token).toBe("at"); + expect(resp.token).toBe("tt"); + }); + }); }); function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent { diff --git a/src/client.ts b/src/client.ts index fc049a420..e501f7d20 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8278,13 +8278,16 @@ export class MatrixClient extends TypedEventEmitter { // TODO: Types + public registerWithIdentityServer(hsOpenIdToken: IOpenIDToken): Promise<{ + access_token: string; + token: string; + }> { if (!this.idBaseUrl) { throw new Error("No identity server base URL set"); } const uri = this.http.getUrl("/account/register", undefined, IdentityPrefix.V2, this.idBaseUrl); - return this.http.requestOtherUrl(Method.Post, uri, null, hsOpenIdToken); + return this.http.requestOtherUrl(Method.Post, uri, hsOpenIdToken); } /** @@ -8751,15 +8754,14 @@ export class MatrixClient extends TypedEventEmitter { // TODO: Types + ): Promise<{}> { const url = this.termsUrlForService(serviceType, baseUrl); - utils.encodeParams({ - user_accepts: termsUrls, - }, url.searchParams); const headers = { Authorization: "Bearer " + accessToken, }; - return this.http.requestOtherUrl(Method.Post, url, null, { headers }); + return this.http.requestOtherUrl(Method.Post, url, { + user_accepts: termsUrls, + }, { headers }); } /** From 4ccc52da8e0703b5199a333ae40d23c0b4811d6f Mon Sep 17 00:00:00 2001 From: ElementRobot Date: Mon, 24 Oct 2022 10:12:42 +0100 Subject: [PATCH 4/8] [Backport staging] Improve crypto init code and allow easier shimming (#2792) Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/crypto/crypto.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/crypto/crypto.ts b/src/crypto/crypto.ts index eb8de60e3..704754f0b 100644 --- a/src/crypto/crypto.ts +++ b/src/crypto/crypto.ts @@ -14,18 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { logger } from "../logger"; + export let crypto = global.window?.crypto; export let subtleCrypto = global.window?.crypto?.subtle ?? global.window?.crypto?.webkitSubtle; export let TextEncoder = global.window?.TextEncoder; /* eslint-disable @typescript-eslint/no-var-requires */ if (!crypto) { - crypto = require("crypto").webcrypto; + try { + crypto = require("crypto").webcrypto; + } catch (e) { + logger.error("Failed to load webcrypto", e); + } } if (!subtleCrypto) { subtleCrypto = crypto?.subtle; } if (!TextEncoder) { - TextEncoder = require("util").TextEncoder; + try { + TextEncoder = require("util").TextEncoder; + } catch (e) { + logger.error("Failed to load TextEncoder util", e); + } } /* eslint-enable @typescript-eslint/no-var-requires */ + +export function setCrypto(_crypto: Crypto): void { + crypto = _crypto; + subtleCrypto = _crypto.subtle ?? _crypto.webkitSubtle; +} + +export function setTextEncoder(_TextEncoder: typeof TextEncoder): void { + TextEncoder = _TextEncoder; +} From 7772f855e6fbecbbb050621f2044a84969c15cce Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Mon, 24 Oct 2022 16:19:46 +0100 Subject: [PATCH 5/8] Prepare changelog for v21.0.0-rc.2 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd42c032..02087fb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Changes in [21.0.0-rc.2](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.0-rc.2) (2022-10-24) +============================================================================================================ + + * Fix POST data not being passed for registerWithIdentityServer ([\#2769](https://github.com/matrix-org/matrix-js-sdk/pull/2769)). Fixes matrix-org/element-web-rageshakes#16206. + Changes in [21.0.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.0-rc.1) (2022-10-18) ============================================================================================================ From e7ce1fb9e8e81774233fc2b91ce3196c15f7d27d Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Mon, 24 Oct 2022 16:19:47 +0100 Subject: [PATCH 6/8] v21.0.0-rc.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ec8d5473..0652aaea0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "21.0.0-rc.1", + "version": "21.0.0-rc.2", "description": "Matrix Client-Server SDK for Javascript", "engines": { "node": ">=16.0.0" From c8c7af0ae26ddb863b1d47866a2f62632a97d0db Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 25 Oct 2022 17:04:02 +0100 Subject: [PATCH 7/8] Prepare changelog for v21.0.0 --- CHANGELOG.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02087fb39..d109edd19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,5 @@ -Changes in [21.0.0-rc.2](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.0-rc.2) (2022-10-24) -============================================================================================================ - - * Fix POST data not being passed for registerWithIdentityServer ([\#2769](https://github.com/matrix-org/matrix-js-sdk/pull/2769)). Fixes matrix-org/element-web-rageshakes#16206. - -Changes in [21.0.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.0-rc.1) (2022-10-18) -============================================================================================================ +Changes in [21.0.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v21.0.0) (2022-10-25) +================================================================================================== ## 🚨 BREAKING CHANGES * Changes the `uploadContent` API, kills off `request` and `browser-request` in favour of `fetch`, removed callback support on a lot of the methods, adds a lot of tests. ([\#2719](https://github.com/matrix-org/matrix-js-sdk/pull/2719)). Fixes #2415 and #801. @@ -22,6 +17,7 @@ Changes in [21.0.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/ta * Use stable calls to `/room_keys` ([\#2729](https://github.com/matrix-org/matrix-js-sdk/pull/2729)). Fixes vector-im/element-web#22839. ## 🐛 Bug Fixes + * Fix POST data not being passed for registerWithIdentityServer ([\#2769](https://github.com/matrix-org/matrix-js-sdk/pull/2769)). Fixes matrix-org/element-web-rageshakes#16206. * Fix IdentityPrefix.V2 containing spurious `/api` ([\#2761](https://github.com/matrix-org/matrix-js-sdk/pull/2761)). Fixes vector-im/element-web#23505. * Always send back an httpStatus property if one is known ([\#2753](https://github.com/matrix-org/matrix-js-sdk/pull/2753)). * Check for AbortError, not any generic connection error, to avoid tightlooping ([\#2752](https://github.com/matrix-org/matrix-js-sdk/pull/2752)). From 1842004db2c9a58896fe159d52d489cf6ee3fcf7 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 25 Oct 2022 17:04:02 +0100 Subject: [PATCH 8/8] v21.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0652aaea0..b269d7b14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "21.0.0-rc.2", + "version": "21.0.0", "description": "Matrix Client-Server SDK for Javascript", "engines": { "node": ">=16.0.0"