Skip to content

Commit

Permalink
Update matrix-bot-sdk and other packages (#415)
Browse files Browse the repository at this point in the history
* Update to matrix-bot-sdk 0.6.0

* Update packages

* changelog

* Bump min required version to Node 16

* Drop uploadContent

* Update to 0.6.1

* ensure strict semver check

* Update various components to support v3 of Matrix

* Update tests

* remove bogus tests

* Explicitly mention dropping support for Node 14
  • Loading branch information
Half-Shot authored Jul 25, 2022
1 parent fe54a32 commit 3dceff7
Show file tree
Hide file tree
Showing 13 changed files with 1,126 additions and 1,475 deletions.
29 changes: 1 addition & 28 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
pull_request:

jobs:

changelog:
if: ${{ github.base_ref == 'develop' || contains(github.base_ref, 'release-') }}
runs-on: ubuntu-latest
Expand All @@ -17,30 +16,4 @@ jobs:
- run: pip install towncrier==19.2.0
- run: scripts/check-newsfragment
env:
PULL_REQUEST_NUMBER: ${{ github.event.number }}



test-14:
runs-on: ubuntu-20.04
container: node:14
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- run: yarn --frozen-lockfile
- run: yarn build && yarn test

test-16:
runs-on: ubuntu-20.04
container: node:16
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16
- run: yarn --frozen-lockfile
- run: yarn build && yarn test
PULL_REQUEST_NUMBER: ${{ github.event.number }}
25 changes: 8 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: 16
- run: yarn --frozen-lockfile
- run: yarn --strict-semver --frozen-lockfile
- run: yarn lint

test-14:
test:
strategy:
matrix:
node-version: [16, 18]
runs-on: ubuntu-20.04
container: node:14
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- run: yarn --frozen-lockfile
- run: yarn build && yarn test

test-16:
runs-on: ubuntu-20.04
container: node:16
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: "${{ matrix.node-version }}"
- run: yarn --frozen-lockfile
- run: yarn build && yarn test
- run: yarn build && yarn test
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
examples/encryption
examples/
.typedoc
.nyc_output
yarn-error.log
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/415.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Drop support for Node 14. Support Node 16+.
`Intent.uploadContent` no longer accepts a `ReadStream` `content` parameter. Convert your stream to a buffer before beginning an upload.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"matrix-org"
],
"engines": {
"node": ">=14"
"node": ">=16 <=18"
},
"author": "Matrix.org",
"license": "Apache-2.0",
Expand All @@ -31,15 +31,16 @@
"homepage": "https://github.com/matrix-org/matrix-appservice-bridge#readme",
"dependencies": {
"@alloc/quick-lru": "^5.2.0",
"axios": "^0.23.0",
"chalk": "^4.1.0",
"axios": "^0.27.2",
"express-rate-limit": "^6.2.0",
"express": "^4.18.1",
"extend": "^3.0.2",
"ip-cidr": "^3.0.4",
"is-my-json-valid": "^2.20.5",
"js-yaml": "^4.0.0",
"matrix-appservice": "^1.0.0",
"matrix-bot-sdk": "0.6.0-beta.2",
"matrix-bot-sdk": "^0.6.1",
"nedb": "^1.8.0",
"nopt": "^5.0.0",
"p-queue": "^6.6.2",
Expand All @@ -52,20 +53,20 @@
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/extend": "^3.0.1",
"@types/jasmine": "^3.8.2",
"@types/jasmine": "^4.0.3",
"@types/js-yaml": "^4.0.0",
"@types/nedb": "^1.8.11",
"@types/node": "^12",
"@types/node": "^14",
"@types/nopt": "^3.0.29",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"eslint": "^8.1.5",
"jasmine": "^3.7.0",
"jasmine": "^4.2.1",
"jasmine-spec-reporter": "^7.0.0",
"nyc": "^15.1.0",
"ts-node": "^10.2.1",
"typedoc": "^0.22.9",
"typedoc": "^0.23.7",
"typescript": "^4.4.3",
"winston-transport": "^4.4.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
"use strict";
var Datastore = require("nedb");
var fs = require("fs");
import Datastore from "nedb";
import * as fs from "fs";
import { UserBridgeStore, MatrixUser, RemoteUser } from "../../src/index";

var UserBridgeStore = require("../..").UserBridgeStore;
var MatrixUser = require("../..").MatrixUser;
var RemoteUser = require("../..").RemoteUser;
var TEST_DB_PATH = __dirname + "/test.db";
const TEST_DB_PATH = __dirname + "/test.db";

describe("UserBridgeStore", function() {
var store, db;
let store: UserBridgeStore;
let db: Datastore;

beforeEach(
/** @this TestCase */
async function(done) {
function(done) {
db = new Datastore({
filename: TEST_DB_PATH,
autoload: true,
Expand Down Expand Up @@ -45,8 +43,8 @@ describe("UserBridgeStore", function() {
const userFromStore = await store.setMatrixUser(user).then(function() {
return store.getMatrixUser(userId);
});
expect(userFromStore.getId()).toEqual(userId);
expect(userFromStore.getDisplayName()).toEqual("Foo");
expect(userFromStore?.getId()).toEqual(userId);
expect(userFromStore?.getDisplayName()).toEqual("Foo");
});
});

Expand All @@ -58,7 +56,7 @@ describe("UserBridgeStore", function() {
const userFromStore = await store.setRemoteUser(user).then(function() {
return store.getRemoteUser(remoteId);
});
expect(userFromStore.getId()).toEqual(remoteId);
expect(userFromStore?.getId()).toEqual(remoteId);
});

it("should fully persist all types of primitive data", async function() {
Expand All @@ -76,11 +74,11 @@ describe("UserBridgeStore", function() {
const userFromStore = await store.setRemoteUser(user).then(function() {
return store.getRemoteUser(remoteId);
});
expect(userFromStore.getId()).toEqual(remoteId);
expect(userFromStore.get("int")).toEqual(42);
expect(userFromStore.get("str")).toEqual("the answer");
expect(userFromStore.get("bool")).toEqual(true);
expect(userFromStore.get("obj")).toEqual({
expect(userFromStore?.getId()).toEqual(remoteId);
expect(userFromStore?.get<number>("int")).toEqual(42);
expect(userFromStore?.get<string>("str")).toEqual("the answer");
expect(userFromStore?.get<boolean>("bool")).toEqual(true);
expect(userFromStore?.get<object>("obj")).toEqual({
foo: "bar",
baz: {
buzz: true
Expand All @@ -91,14 +89,14 @@ describe("UserBridgeStore", function() {
it("should not persist functions", async function() {
var remoteId = "some_unique_id";
var user = new RemoteUser(remoteId);
user.set("fn", function(foo) {
user.set("fn", function() {
return 42;
});
const userFromStore = await store.setRemoteUser(user).then(function() {
return store.getRemoteUser(remoteId);
});
expect(userFromStore.getId()).toEqual(remoteId);
expect(userFromStore.get("fn")).toBeUndefined();
expect(userFromStore?.getId()).toEqual(remoteId);
expect(userFromStore?.get("fn")).toBeUndefined();
});
});

Expand Down Expand Up @@ -157,7 +155,7 @@ describe("UserBridgeStore", function() {

it("should throw if the data query isn't an object", function() {
expect(function() {
store.getByRemoteData("nested.key");
store.getByRemoteData("nested.key" as any);
}).toThrow();
});
});
Expand Down Expand Up @@ -201,7 +199,7 @@ describe("UserBridgeStore", function() {
const mx = new MatrixUser("@foo:bar");
await store.setMatrixUser(mx);
const m = await store.getByMatrixLocalpart("foo");
expect(m.getId()).toEqual("@foo:bar");
expect(m?.getId()).toEqual("@foo:bar");
});
});

Expand Down Expand Up @@ -262,8 +260,8 @@ describe("UserBridgeStore", function() {
it("should return a single element list for a single match",
async function() {
const res = await store.getMatrixLinks("a_1");
expect(res.length).toEqual(1);
expect(res[0]).toEqual("@a:bar");
expect(res?.length).toEqual(1);
expect(res?.[0]).toEqual("@a:bar");
});
});
});
Expand Down Expand Up @@ -317,8 +315,8 @@ describe("UserBridgeStore", function() {
it("should return a single element list for a single match",
async function() {
const res = await store.getRemoteLinks("@b:bar");
expect(res.length).toEqual(1);
expect(res[0]).toEqual("b_1");
expect(res?.length).toEqual(1);
expect(res?.[0]).toEqual("b_1");
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/activity-tracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function createTracker(canUseWhois: boolean = false, presence?: PresenceEventCon
}
throw {statusCode: 403}; // 403 - not an admin
}
if (method === "GET" && path.startsWith("/_matrix/client/r0/presence/")) {
if (method === "GET" && path.startsWith("/_matrix/client/v3/presence/")) {
if (!presence) {
throw Error("Presence is disabled");
}
return presence;
}
if (method === "GET" && path.startsWith("/_matrix/client/r0/admin/whois")) {
if (method === "GET" && path.startsWith("/_matrix/client/v3/admin/whois")) {
if (!whois) {
throw Error("Whois is disabled");
}
Expand Down
9 changes: 5 additions & 4 deletions spec/unit/room-upgrade-handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,22 @@ describe("RoomUpgradeHandler", () => {
room_id: "!abc:def",
})).toEqual(false);
});
it("should handle a expected invite", async (done) => {
it("should handle a expected invite", async () => {
const ruh = new RoomUpgradeHandler({}, {});
let newRoomId = false;
ruh.waitingForInvite.set("!new:def", "!abc:def");
ruh.joinNewRoom = (_newRoomId) => {
newRoomId = _newRoomId;
return Promise.resolve();
}
ruh.onJoinedNewRoom = () => {
const p = new Promise(r => ruh.onJoinedNewRoom = () => {
expect(newRoomId).toEqual("!new:def");
done();
}
r();
});
expect(await ruh.onInvite({
room_id: "!new:def",
})).toEqual(true);
await p;
});
});
});
2 changes: 1 addition & 1 deletion src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ export class Bridge {
if (this.opts.bridgeEncryption) {
// Ensure that we have support for /login
const loginFlows: {flows: {type: string}[]} =
await this.botSdkAS.botClient.doRequest("GET", "/_matrix/client/r0/login");
await this.botSdkAS.botClient.doRequest("GET", "/_matrix/client/v3/login");
if (!EncryptedEventBroker.supportsLoginFlow(loginFlows)) {
throw Error(
'To enable support for encryption, your homeserver must support m.login.application_service.' +
Expand Down
4 changes: 2 additions & 2 deletions src/components/encrypted-intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class EncryptedIntent extends Intent {
* @param opts Additional options for the upload.
* @returns A MXC URL pointing to the uploaded data.
*/
public async uploadContent(content: Buffer|string|ReadStream, opts: FileUploadOpts = {}): Promise<string> {
public async uploadContent(content: Buffer|string, opts: FileUploadOpts = {}): Promise<string> {
await this.ensureRegistered();
// Media is encrypted, since we don't know the destination room assume this media will be encrypted.
await this.encryptionOpts.ensureClientSyncingCallback();
Expand All @@ -65,7 +65,7 @@ export class EncryptedIntent extends Intent {
const userId: string = this.userId;
const res = await this.botSdkIntent.underlyingClient.doRequest(
"POST",
"/_matrix/client/r0/login",
"/_matrix/client/v3/login",
undefined,
{
type: APPSERVICE_LOGIN_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion src/components/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class EncryptedEventBroker {
// eslint-disable-next-line camelcase
const { filter_id } = await matrixClient.doRequest(
"POST",
`/_matrix/client/r0/user/${encodeURIComponent(userId)}/filter`,
`/_matrix/client/v3/user/${encodeURIComponent(userId)}/filter`,
null,
SYNC_FILTER
);
Expand Down
5 changes: 1 addition & 4 deletions src/components/intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,12 @@ export class Intent {
* @param opts Additional options for the upload.
* @returns A MXC URL pointing to the uploaded data.
*/
public async uploadContent(content: Buffer|string|ReadStream, opts: FileUploadOpts = {}): Promise<string> {
public async uploadContent(content: Buffer|string, opts: FileUploadOpts = {}): Promise<string> {
await this.ensureRegistered();
let buffer: Buffer;
if (typeof content === "string") {
buffer = Buffer.from(content, "utf8");
}
else if (content instanceof ReadStream) {
buffer = Buffer.from(content);
}
else {
buffer = content;
}
Expand Down
Loading

0 comments on commit 3dceff7

Please sign in to comment.