diff --git a/.vscode/settings.json b/.vscode/settings.json index 975e9b7d..1158a1a6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,6 @@ "editor.codeActionsOnSave": { "quickfix.biome": "explicit" }, - "cSpell.words": ["displayname", "Elysia", "Unpadded"], + "cSpell.words": ["displayname", "Elysia", "homeserver", "Unpadded"], "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/packages/homeserver/src/errors.ts b/packages/homeserver/src/errors.ts index 3a3e07ad..368713e8 100644 --- a/packages/homeserver/src/errors.ts +++ b/packages/homeserver/src/errors.ts @@ -2,7 +2,7 @@ export class MatrixError extends Error { public readonly status: number = 400; public constructor( - public readonly code: TCode, + public readonly errcode: TCode, message: string, ) { super(message); @@ -10,7 +10,7 @@ export class MatrixError extends Error { public toJSON() { return { - errcode: this.code, + errcode: this.errcode, error: this.message, }; } diff --git a/packages/homeserver/src/makeRequest.ts b/packages/homeserver/src/makeRequest.ts index 3c58745b..9d37e1e1 100644 --- a/packages/homeserver/src/makeRequest.ts +++ b/packages/homeserver/src/makeRequest.ts @@ -39,13 +39,21 @@ export const makeSignedRequest = async < signingName: string; queryString?: string; }) => { - const { address, headers } = await resolveHostAddressByServerName(domain, signingName); + const { address, headers } = await resolveHostAddressByServerName( + domain, + signingName, + ); const url = new URL(`https://${address}${uri}`); if (queryString) { url.search = queryString; } const signedBody = - body && (await signJson(computeHash({ ...body, signatures: {} }), signingKey, signingName)); + body && + (await signJson( + computeHash({ ...body, signatures: {} }), + signingKey, + signingName, + )); console.log("body ->", method, domain, url.toString(), signedBody); @@ -96,7 +104,10 @@ export const makeRequest = async < options?: Record; queryString?: string; }) => { - const { address, headers } = await resolveHostAddressByServerName(domain, signingName); + const { address, headers } = await resolveHostAddressByServerName( + domain, + signingName, + ); const url = new URL(`https://${address}${uri}`); if (queryString) { url.search = queryString; @@ -124,11 +135,12 @@ export const makeUnsignedRequest = async < method, domain, uri, + body, options = {}, signingKey, signingName, queryString, -}: { +}: (B extends Record ? { body: B } : { body?: never }) & { method: M; domain: string; uri: U; @@ -144,17 +156,20 @@ export const makeUnsignedRequest = async < domain, method, uri, - options.body, + body, ); - const { address, headers } = await resolveHostAddressByServerName(domain, signingName); + const { address, headers } = await resolveHostAddressByServerName( + domain, + signingName, + ); const url = new URL(`https://${address}${uri}`); if (queryString) { url.search = queryString; } const response = await fetch(url.toString(), { ...options, - ...(options.body && { body: JSON.stringify(options.body) }), + ...(body && { body: JSON.stringify(body) }), method, headers: { Authorization: auth, diff --git a/packages/homeserver/src/procedures/makeJoin.ts b/packages/homeserver/src/procedures/makeJoin.ts index f8e77c2a..17314a3b 100644 --- a/packages/homeserver/src/procedures/makeJoin.ts +++ b/packages/homeserver/src/procedures/makeJoin.ts @@ -1,5 +1,3 @@ -import { Elysia, t } from "elysia"; - import "@hs/endpoints/src/query"; import "@hs/endpoints/src/server"; import { IncompatibleRoomVersionError, NotFoundError } from "../errors"; @@ -17,10 +15,10 @@ export const makeJoinEventBuilder = async ( roomId: string, userId: string, - roomVersion: string, + roomVersions: string[], origin: string, ) => { - if (roomVersion !== "10") { + if (!roomVersions.includes("10")) { throw new IncompatibleRoomVersionError( "Your homeserver does not support the features required to join this room", { roomVersion: "10" }, diff --git a/packages/homeserver/src/routes/federation/getMissingEvents.ts b/packages/homeserver/src/routes/federation/getMissingEvents.ts index 2750a5c1..144b493d 100644 --- a/packages/homeserver/src/routes/federation/getMissingEvents.ts +++ b/packages/homeserver/src/routes/federation/getMissingEvents.ts @@ -31,9 +31,7 @@ export const getMissingEventsRoute = new Elysia().post( body.limit, ); - return { - events, - }; + return events; }, { params: t.Object( @@ -69,9 +67,11 @@ export const getMissingEventsRoute = new Elysia().post( }, ), detail: { - security: [{ - 'matrixAuth': [] - }], - } + security: [ + { + matrixAuth: [], + }, + ], + }, }, ); diff --git a/packages/homeserver/src/routes/federation/makeJoin.ts b/packages/homeserver/src/routes/federation/makeJoin.ts index 06fa493f..18d5119f 100644 --- a/packages/homeserver/src/routes/federation/makeJoin.ts +++ b/packages/homeserver/src/routes/federation/makeJoin.ts @@ -42,17 +42,19 @@ export const makeJoinRoute = new Elysia().get( description: "The authorization header", }), }), - response: { - 200: t.Object({}), - 400: t.Object({}), - 403: t.Object({}), - 404: t.Object({}), - }, + // response: { + // 200: t.Object({}), + // 400: t.Object({}), + // 403: t.Object({}), + // 404: t.Object({}), + // }, query: t.Object({ - ver: t.String({ - description: - "The version of the room where the user is being invited to.", - }), + ver: t.Array( + t.String({ + description: + "The version of the room where the user is being invited to.", + }), + ), }), params: t.Object( {