Skip to content

Commit

Permalink
Update a few more packages and fixup types
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jan 11, 2024
1 parent 64899b0 commit 2c985a5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 56 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@
"fast-xml-parser": "^3.17.4",
"html-entities": "^2.4.0",
"htmlparser2": "^6.1.0",
"leven": "^3.1.0",
"leven": "^4.0.0",
"marked": "^11.1.1",
"nedb": "^1.8.0",
"matrix-appservice-bridge": "^10.1.0",
"pg": "8.11.3",
"prom-client": "^13.1.0",
"quick-lru": "^5.1.1"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@tsconfig/node20": "20.1.2",
"@types/chai": "^4.3.11",
"@types/mocha": "^9.0.0",
"@types/node": "^20",
Expand All @@ -54,13 +56,12 @@
"@typescript-eslint/eslint-plugin": "^6.18.0",
"@typescript-eslint/eslint-plugin-tslint": "^6.18.0",
"@typescript-eslint/parser": "^6.18.0",
"chai": "^4.3.4",
"chai": "^5.0.0",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.0.2",
"mocha": "^9.0.3",
"mock-require": "^3.0.3",
"nedb": "^1.8.0",
"nyc": "^15.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
Expand Down
5 changes: 3 additions & 2 deletions src/AutoRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ export interface IAutoRegStep {
const ESCAPE_TEMPLATE_REGEX = /[-\/\\^$*+?.()|[\]{}]/g;

export class AutoRegistration {
private nameCache = new QuickLRU<string, {[key: string]: string}>({ maxSize: this.autoRegConfig.registrationNameCacheSize });
private nameCache: QuickLRU<string, {[key: string]: string}>;
constructor(
private autoRegConfig: IConfigAutoReg,
private accessConfig: IConfigAccessControl,
private bridge: Bridge,
private store: IStore,
private protoInstance: IBifrostInstance) {
this.nameCache = new QuickLRU({ maxSize: this.autoRegConfig.registrationNameCacheSize });

Check failure on line 35 in src/AutoRegistration.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 11
}

public isSupported(protocol: string) {
Expand Down Expand Up @@ -212,7 +213,7 @@ export class AutoRegistration {
headers,
body: JSON.stringify(body),
});
const result = await req.json();
const result = await req.json() as {data: Record<string, unknown>};
if (!opts.usernameResult) { // fetch it from the body.
username = result.data;
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/Deduplicator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger } from "matrix-appservice-bridge";
import leven from "leven";
const leven = import("leven");

const log = new Logger("Deduplicator");

Expand Down Expand Up @@ -94,15 +94,15 @@ export class Deduplicator {
}
}

public checkAndRemove(roomName: string, sender: string, body: string) {
const h = Deduplicator.hashMessage(roomName, sender, body);
public async checkAndRemove(roomName: string, sender: string, body: string) {
const levenFn = (await leven).default;
const start = `${sender}/${roomName}/`;
const index = this.expectedMessages.findIndex((hash) => {
if (!hash.startsWith(start)) {
return false;
}
hash = hash.substr(start.length);
const l = leven(hash, body) / hash.length;
hash = hash.slice(start.length);
const l = levenFn(hash, body) / hash.length;
return l <= LEVEN_THRESHOLD;
});
if (index !== -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/MatrixRoomHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export class MatrixRoomHandler {
return;
}
const remoteId = Util.createRemoteId(data.account.protocol_id, data.sender);
if (this.purple.needsDedupe() && this.deduplicator.checkAndRemove(
if (this.purple.needsDedupe() && await this.deduplicator.checkAndRemove(
data.conv.name,
remoteId,
data.message.body,
Expand Down
4 changes: 3 additions & 1 deletion src/purple/PurpleAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { IBifrostAccount } from "../bifrost/Account";

const log = new Logger("PurpleAccount");

export type PurpleAccountHandle = unknown;

export interface IChatJoinOptions {
identifier: string;
label: string;
Expand Down Expand Up @@ -46,7 +48,7 @@ export class PurpleAccount implements IBifrostAccount {

get name(): string { return this.acctData!.username; }

get handle(): External { return this.acctData!.handle; }
get handle(): PurpleAccountHandle { return this.acctData!.handle; }

get isEnabled(): boolean { return this.enabled; }

Expand Down
3 changes: 2 additions & 1 deletion src/xmppjs/XJSInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const SEEN_MESSAGES_SIZE = 16384;

export class XmppJsInstance extends EventEmitter implements IBifrostInstance {
public readonly presenceCache = new PresenceCache();
public readonly serviceHandler = new ServiceHandler(this, this.config.bridge);
public readonly serviceHandler: ServiceHandler;
private xmpp?: any;
private myAddress!: JID;
private accounts = new Map<string, XmppJsAccount>();
Expand All @@ -79,6 +79,7 @@ export class XmppJsInstance extends EventEmitter implements IBifrostInstance {
private jingleHandler?: JingleHandler;
constructor(private config: Config, private readonly bridge: Bridge) {
super();
this.serviceHandler = new ServiceHandler(this, this.config.bridge);
const opts = config.purple.backendOpts as IXJSBackendOpts;
if (opts.jingle) {
this.jingleHandler = new JingleHandler(this, opts.jingle, {
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": ["@tsconfig/node20"],
"compilerOptions": {
"incremental": true,
"target": "ES2019",
"module": "commonjs",
"allowJs": false,
"declaration": false,
"sourceMap": true,
Expand Down
86 changes: 45 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@
resolved "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz"
integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==

"@tsconfig/[email protected]":
version "20.1.2"
resolved "https://registry.yarnpkg.com/@tsconfig/node20/-/node20-20.1.2.tgz#b93128c411d38e9507035255195bc8a6718541e3"
integrity sha512-madaWq2k+LYMEhmcp0fs+OGaLFk0OenpHa4gmI4VEmCKX4PJntQ6fnnGADVFrVkBj0wIdAlQnK/MrlYTHsa1gQ==

"@types/body-parser@*":
version "1.19.0"
resolved "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.0.tgz"
Expand Down Expand Up @@ -1017,10 +1022,10 @@ [email protected], assert-plus@^1.0.0:
resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz"
integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=

assertion-error@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz"
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==
assertion-error@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-2.0.1.tgz#f641a196b335690b1070bf00b6e7593fec190bf7"
integrity sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==

async-lock@^1.4.0:
version "1.4.1"
Expand Down Expand Up @@ -1231,17 +1236,16 @@ caseless@~0.12.0:
resolved "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz"
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=

chai@^4.3.4:
version "4.3.4"
resolved "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz"
integrity sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==
chai@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/chai/-/chai-5.0.0.tgz#da1ae496fdac30e97062cbd59e6e2f7bb4c78cc0"
integrity sha512-HO5p0oEKd5M6HEcwOkNAThAE3j960vIZvVcc0t2tI06Dd0ATu69cEnMB2wOhC5/ZyQ6m67w3ePjU/HzXsSsdBA==
dependencies:
assertion-error "^1.1.0"
check-error "^1.0.2"
deep-eql "^3.0.1"
get-func-name "^2.0.0"
pathval "^1.1.1"
type-detect "^4.0.5"
assertion-error "^2.0.1"
check-error "^2.0.0"
deep-eql "^5.0.1"
loupe "^3.0.0"
pathval "^2.0.0"

chalk@4, chalk@^4.0.0, chalk@^4.1.0:
version "4.1.1"
Expand All @@ -1260,10 +1264,10 @@ chalk@^2.0.0:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

check-error@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz"
integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=
check-error@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-2.0.0.tgz#589a4f201b6256fd93a2d165089fe43d2676d8c6"
integrity sha512-tjLAOBHKVxtPoHe/SA7kNOMvhCRdCJ3vETdeY0RuAc9popf+hyaSV6ZEg9hr4cpWF7jmo/JSWEnLDrnijS9Tog==

[email protected]:
version "3.5.2"
Expand Down Expand Up @@ -1476,12 +1480,10 @@ decamelize@^4.0.0:
resolved "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz"
integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==

deep-eql@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz"
integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==
dependencies:
type-detect "^4.0.0"
deep-eql@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-5.0.1.tgz#21ea2c0d561a4d08cdd99c417ac584e0fb121385"
integrity sha512-nwQCf6ne2gez3o1MxWifqkciwt0zhl0LO1/UwVu4uMBuPmflWM4oQ70XMqHqnBJA+nhzncaqL9HVL6KkHJ28lw==

deep-is@^0.1.3:
version "0.1.4"
Expand Down Expand Up @@ -2260,10 +2262,10 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5:
resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==

get-func-name@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz"
integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=
get-func-name@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41"
integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==

get-intrinsic@^1.0.2, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3, get-intrinsic@^1.2.0, get-intrinsic@^1.2.1, get-intrinsic@^1.2.2:
version "1.2.2"
Expand Down Expand Up @@ -3081,10 +3083,10 @@ leac@^0.6.0:
resolved "https://registry.npmjs.org/leac/-/leac-0.6.0.tgz"
integrity sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg==

leven@^3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz"
integrity sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==
leven@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/leven/-/leven-4.0.0.tgz#b9c39c803f835950fabef9e122a9b47b95708710"
integrity sha512-puehA3YKku3osqPlNuzGDUHq8WpwXupUg1V6NXdV38G+gr+gkBwFC8g1b/+YcIvp8gnqVIus+eJCH/eGsRmJNw==

levn@^0.4.1:
version "0.4.1"
Expand Down Expand Up @@ -3157,6 +3159,13 @@ logform@^2.3.2, logform@^2.4.0:
safe-stable-stringify "^2.3.1"
triple-beam "^1.3.0"

loupe@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/loupe/-/loupe-3.1.0.tgz#46ef1a4ffee73145f5c0a627536d754787c1ea2a"
integrity sha512-qKl+FrLXUhFuHUoDJG7f8P8gEMHq9NFS0c6ghXG1J0rldmZFQZoNVv/vyirE9qwCIhWZDsvEFd1sbFu3GvRQFg==
dependencies:
get-func-name "^2.0.1"

lowdb@1:
version "1.0.0"
resolved "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz"
Expand Down Expand Up @@ -3871,10 +3880,10 @@ path-type@^4.0.0:
resolved "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

pathval@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz"
integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==
pathval@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/pathval/-/pathval-2.0.0.tgz#7e2550b422601d4f6b8e26f1301bc8f15a741a25"
integrity sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==

peberminta@^0.9.0:
version "0.9.0"
Expand Down Expand Up @@ -4821,11 +4830,6 @@ type-check@^0.4.0, type-check@~0.4.0:
dependencies:
prelude-ls "^1.2.1"

type-detect@^4.0.0, type-detect@^4.0.5:
version "4.0.8"
resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz"
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==

type-fest@^0.20.2:
version "0.20.2"
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz"
Expand Down

0 comments on commit 2c985a5

Please sign in to comment.