diff --git a/api/package-lock.json b/api/package-lock.json index dcbb75d1b..53088d5db 100644 Binary files a/api/package-lock.json and b/api/package-lock.json differ diff --git a/api/package.json b/api/package.json index ce5bcdf9f..530310716 100644 --- a/api/package.json +++ b/api/package.json @@ -46,6 +46,7 @@ "@types/express": "^4.17.9", "@types/i18next-node-fs-backend": "^2.1.0", "@types/jest": "^27.0.1", + "@types/jest-expect-message": "^1.0.3", "@types/jsonwebtoken": "^8.5.0", "@types/mongodb": "^3.6.9", "@types/mongoose": "^5.10.5", @@ -61,6 +62,8 @@ "caxa": "^2.1.0", "image-size": "^1.0.0", "jest": "^26.6.3", + "jest-expect-message": "^1.0.2", + "jest-runtime": "^27.2.1", "saslprep": "^1.0.3", "ts-node": "^9.1.1", "ts-node-dev": "^1.1.6", @@ -85,7 +88,7 @@ "express": "^4.17.1", "express-validator": "^6.9.2", "form-data": "^3.0.0", - "i18next": "^19.8.5", + "i18next": "^19.9.2", "i18next-http-middleware": "^3.1.3", "i18next-node-fs-backend": "^2.1.3", "jsonwebtoken": "^8.5.1", @@ -106,6 +109,9 @@ "setupFiles": [ "/jest/setup.js" ], + "setupFilesAfterEnv": [ + "jest-expect-message" + ], "globalSetup": "/jest/globalSetup.js", "verbose": true } diff --git a/bundle/package-lock.json b/bundle/package-lock.json index 6a6588427..0ed6b03a8 100644 Binary files a/bundle/package-lock.json and b/bundle/package-lock.json differ diff --git a/bundle/package.json b/bundle/package.json index 72b245689..4b4e82868 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -45,6 +45,7 @@ "@types/ws": "^7.4.0", "@zerollup/ts-transform-paths": "^1.7.18", "ts-node": "^10.2.1", + "ts-patch": "^1.4.4", "typescript": "^4.3.5" }, "dependencies": { diff --git a/cdn/package-lock.json b/cdn/package-lock.json index 8a70844c3..b6faa0e4f 100644 Binary files a/cdn/package-lock.json and b/cdn/package-lock.json differ diff --git a/cdn/package.json b/cdn/package.json index 71211d677..9d4fa942b 100644 --- a/cdn/package.json +++ b/cdn/package.json @@ -36,6 +36,7 @@ "@types/node": "^14.17.0", "@types/node-fetch": "^2.5.7", "@types/uuid": "^8.3.0", + "@zerollup/ts-transform-paths": "^1.7.18", "ts-patch": "^1.4.4" }, "dependencies": { diff --git a/cdn/tsconfig.json b/cdn/tsconfig.json index f893869f1..f2f378e19 100644 --- a/cdn/tsconfig.json +++ b/cdn/tsconfig.json @@ -68,7 +68,7 @@ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, "baseUrl": ".", "paths": { - "@fosscord/cdn/": ["src/index.ts"], + "@fosscord/cdn/": ["src/index"], "@fosscord/cdn/*": ["src/*"] }, "plugins": [{ "transform": "@zerollup/ts-transform-paths" }] diff --git a/gateway/package-lock.json b/gateway/package-lock.json index df97d8588..7b9c8d3a1 100644 Binary files a/gateway/package-lock.json and b/gateway/package-lock.json differ diff --git a/gateway/package.json b/gateway/package.json index f5e66a9a0..595d0205b 100644 --- a/gateway/package.json +++ b/gateway/package.json @@ -23,6 +23,7 @@ "@types/node-fetch": "^2.5.12", "@types/uuid": "^8.3.0", "@types/ws": "^7.4.0", + "@zerollup/ts-transform-paths": "^1.7.18", "ts-node-dev": "^1.1.6", "ts-patch": "^1.4.4", "typescript": "^4.2.3" diff --git a/gateway/src/events/Close.ts b/gateway/src/events/Close.ts index 4afe8352c..1299ad5c5 100644 --- a/gateway/src/events/Close.ts +++ b/gateway/src/events/Close.ts @@ -1,4 +1,4 @@ -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { WebSocket } from "@fosscord/gateway"; import { Message } from "./Message"; import { Session } from "@fosscord/util"; diff --git a/gateway/src/events/Connection.ts b/gateway/src/events/Connection.ts index b9d2d6a1c..cb4fc85a8 100644 --- a/gateway/src/events/Connection.ts +++ b/gateway/src/events/Connection.ts @@ -1,11 +1,14 @@ import WS from "ws"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { + setHeartbeat, + Send, + CLOSECODES, + OPCODES, + WebSocket, +} from "@fosscord/gateway"; import { IncomingMessage } from "http"; import { Close } from "./Close"; import { Message } from "./Message"; -import { setHeartbeat } from "@fosscord/gateway/util/setHeartbeat"; -import { Send } from "@fosscord/gateway/util/Send"; -import { CLOSECODES, OPCODES } from "@fosscord/gateway/util/Constants"; import { createDeflate } from "zlib"; import { URL } from "url"; import { Session } from "@fosscord/util"; diff --git a/gateway/src/events/Message.ts b/gateway/src/events/Message.ts index 66f98f1cb..be95bd159 100644 --- a/gateway/src/events/Message.ts +++ b/gateway/src/events/Message.ts @@ -1,10 +1,9 @@ -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { WebSocket, Payload, CLOSECODES, OPCODES } from "@fosscord/gateway"; var erlpack: any; try { erlpack = require("erlpack"); } catch (error) {} import OPCodeHandlers from "../opcodes"; -import { Payload, CLOSECODES, OPCODES } from "@fosscord/gateway/util/Constants"; import { instanceOf, Tuple } from "lambert-server"; import { check } from "../opcodes/instanceOf"; import WS from "ws"; diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts index ae13cca7e..0fa6bb08c 100644 --- a/gateway/src/listener/listener.ts +++ b/gateway/src/listener/listener.ts @@ -9,12 +9,9 @@ import { ListenEventOpts, Member, } from "@fosscord/util"; -import { OPCODES } from "@fosscord/gateway/util/Constants"; -import { Send } from "@fosscord/gateway/util/Send"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { OPCODES, WebSocket, Send } from "@fosscord/gateway"; import "missing-native-js-functions"; import { Channel as AMQChannel } from "amqplib"; -import { In, Like } from "typeorm"; import { Recipient } from "@fosscord/util"; // TODO: close connection on Invalidated Token @@ -116,7 +113,7 @@ async function consume(this: WebSocket, opts: EventOpts) { .has("VIEW_CHANNEL") ) return; - //No break needed here, we need to call the listenEvent function below + //No break needed here, we need to call the listenEvent function below case "GUILD_CREATE": this.events[id] = await listenEvent(id, consumer, listenOpts); break; diff --git a/gateway/src/opcodes/Heartbeat.ts b/gateway/src/opcodes/Heartbeat.ts index 34d8ca741..46caee563 100644 --- a/gateway/src/opcodes/Heartbeat.ts +++ b/gateway/src/opcodes/Heartbeat.ts @@ -1,7 +1,4 @@ -import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants"; -import { Send } from "@fosscord/gateway/util/Send"; -import { setHeartbeat } from "@fosscord/gateway/util/setHeartbeat"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { Payload, Send, setHeartbeat, WebSocket } from "@fosscord/gateway"; export async function onHeartbeat(this: WebSocket, data: Payload) { // TODO: validate payload diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index d91cd7f2b..a58583ee0 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -1,5 +1,10 @@ -import { CLOSECODES, Payload, OPCODES } from "@fosscord/gateway/util/Constants"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { + WebSocket, + CLOSECODES, + Payload, + OPCODES, + genSessionId, +} from "@fosscord/gateway"; import { Channel, checkToken, @@ -24,7 +29,6 @@ import { Send } from "@fosscord/gateway/util/Send"; const experiments: any = []; import { check } from "./instanceOf"; import { Recipient } from "@fosscord/util"; -import { genSessionId } from "@fosscord/gateway/util/SessionUtils"; // TODO: bot sharding // TODO: check priviliged intents @@ -98,7 +102,9 @@ export async function onIdentify(this: WebSocket, data: Payload) { //TODO is this needed? check if users in group dm that are not friends are sent in the READY event //users = users.concat(x.channel.recipients); if (x.channel.isDm()) { - x.channel.recipients = x.channel.recipients!.filter((x) => x.id !== this.user_id); + x.channel.recipients = x.channel.recipients!.filter( + (x) => x.id !== this.user_id + ); } return x.channel; }); @@ -109,7 +115,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { if (!user) return this.close(CLOSECODES.Authentication_failed); for (let relation of user.relationships) { - const related_user = relation.to + const related_user = relation.to; const public_related_user = { username: related_user.username, discriminator: related_user.discriminator, diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts index 41ec34462..db00157fd 100644 --- a/gateway/src/opcodes/LazyRequest.ts +++ b/gateway/src/opcodes/LazyRequest.ts @@ -2,13 +2,10 @@ import { getPermission, Member, PublicMemberProjection, - PublicUserProjection, Role, } from "@fosscord/util"; import { LazyRequest } from "../schema/LazyRequest"; -import { OPCODES, Payload } from "@fosscord/gateway/util/Constants"; -import { Send } from "@fosscord/gateway/util/Send"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { WebSocket, Send, OPCODES, Payload } from "@fosscord/gateway"; import { check } from "./instanceOf"; import "missing-native-js-functions"; diff --git a/gateway/src/opcodes/PresenceUpdate.ts b/gateway/src/opcodes/PresenceUpdate.ts index 4febbfcb6..53d7b9d27 100644 --- a/gateway/src/opcodes/PresenceUpdate.ts +++ b/gateway/src/opcodes/PresenceUpdate.ts @@ -1,5 +1,4 @@ -import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { WebSocket, Payload } from "@fosscord/gateway"; export function onPresenceUpdate(this: WebSocket, data: Payload) { // return this.close(CLOSECODES.Unknown_error); diff --git a/gateway/src/opcodes/RequestGuildMembers.ts b/gateway/src/opcodes/RequestGuildMembers.ts index 9c1654fa7..b80721dcb 100644 --- a/gateway/src/opcodes/RequestGuildMembers.ts +++ b/gateway/src/opcodes/RequestGuildMembers.ts @@ -1,6 +1,4 @@ -import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants"; - -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { Payload, WebSocket } from "@fosscord/gateway"; export function onRequestGuildMembers(this: WebSocket, data: Payload) { // return this.close(CLOSECODES.Unknown_error); diff --git a/gateway/src/opcodes/Resume.ts b/gateway/src/opcodes/Resume.ts index e155c1397..398cce256 100644 --- a/gateway/src/opcodes/Resume.ts +++ b/gateway/src/opcodes/Resume.ts @@ -1,7 +1,4 @@ -import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants"; -import { Send } from "@fosscord/gateway/util/Send"; - -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { WebSocket, Payload, Send } from "@fosscord/gateway"; export async function onResume(this: WebSocket, data: Payload) { console.log("Got Resume -> cancel not implemented"); diff --git a/gateway/src/opcodes/VoiceStateUpdate.ts b/gateway/src/opcodes/VoiceStateUpdate.ts index 60803ec3f..084c57664 100644 --- a/gateway/src/opcodes/VoiceStateUpdate.ts +++ b/gateway/src/opcodes/VoiceStateUpdate.ts @@ -1,6 +1,5 @@ import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdateSchema"; -import { Payload } from "@fosscord/gateway/util/Constants"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { Payload, WebSocket, genVoiceToken } from "@fosscord/gateway"; import { check } from "./instanceOf"; import { Config, @@ -12,7 +11,6 @@ import { VoiceState, VoiceStateUpdateEvent, } from "@fosscord/util"; -import { genVoiceToken } from "@fosscord/gateway/util/SessionUtils"; // TODO: check if a voice server is setup // Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not. diff --git a/gateway/src/opcodes/index.ts b/gateway/src/opcodes/index.ts index c40695898..027739db9 100644 --- a/gateway/src/opcodes/index.ts +++ b/gateway/src/opcodes/index.ts @@ -1,5 +1,4 @@ -import { Payload } from "@fosscord/gateway/util/Constants"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { WebSocket, Payload } from "@fosscord/gateway"; import { onHeartbeat } from "./Heartbeat"; import { onIdentify } from "./Identify"; import { onLazyRequest } from "./LazyRequest"; diff --git a/gateway/src/opcodes/instanceOf.ts b/gateway/src/opcodes/instanceOf.ts index 6d84ac21d..37d513adf 100644 --- a/gateway/src/opcodes/instanceOf.ts +++ b/gateway/src/opcodes/instanceOf.ts @@ -1,6 +1,5 @@ import { instanceOf } from "lambert-server"; -import { CLOSECODES } from "@fosscord/gateway/util/Constants"; -import WebSocket from "@fosscord/gateway/util/WebSocket"; +import { WebSocket, CLOSECODES } from "@fosscord/gateway"; export function check(this: WebSocket, schema: any, data: any) { try { diff --git a/gateway/src/util/Send.ts b/gateway/src/util/Send.ts index 1b00e361c..ff8aefc9e 100644 --- a/gateway/src/util/Send.ts +++ b/gateway/src/util/Send.ts @@ -2,9 +2,7 @@ var erlpack: any; try { erlpack = require("erlpack"); } catch (error) {} -import { Payload } from "@fosscord/gateway/util/Constants"; - -import WebSocket from "./WebSocket"; +import { Payload, WebSocket } from "@fosscord/gateway"; export async function Send(socket: WebSocket, data: Payload) { let buffer: Buffer | string; @@ -20,7 +18,7 @@ export async function Send(socket: WebSocket, data: Payload) { } return new Promise((res, rej) => { - socket.send(buffer, (err) => { + socket.send(buffer, (err: any) => { if (err) return rej(err); return res(null); }); diff --git a/gateway/src/util/WebSocket.ts b/gateway/src/util/WebSocket.ts index 15d1549fd..b80265a7a 100644 --- a/gateway/src/util/WebSocket.ts +++ b/gateway/src/util/WebSocket.ts @@ -3,7 +3,7 @@ import WS from "ws"; import { Deflate } from "zlib"; import { Channel } from "amqplib"; -interface WebSocket extends WS { +export interface WebSocket extends WS { version: number; user_id: string; session_id: string; @@ -19,5 +19,3 @@ interface WebSocket extends WS { permissions: Record; events: Record; } - -export default WebSocket; diff --git a/gateway/src/util/setHeartbeat.ts b/gateway/src/util/setHeartbeat.ts index 9f88b4817..f6871cfe9 100644 --- a/gateway/src/util/setHeartbeat.ts +++ b/gateway/src/util/setHeartbeat.ts @@ -1,5 +1,5 @@ import { CLOSECODES } from "./Constants"; -import WebSocket from "./WebSocket"; +import { WebSocket } from "./WebSocket"; // TODO: make heartbeat timeout configurable export function setHeartbeat(socket: WebSocket) { diff --git a/gateway/tsconfig.json b/gateway/tsconfig.json index c50bd77ad..dd0663837 100644 --- a/gateway/tsconfig.json +++ b/gateway/tsconfig.json @@ -70,6 +70,7 @@ "resolveJsonModule": true, "baseUrl": ".", "paths": { + "@fosscord/gateway": ["src/index"], "@fosscord/gateway/*": ["src/*"], "@fosscord/util/*": ["../util/src/*"] },