diff --git a/package.json b/package.json index 20c7bdb5..d5a473dd 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "@sentry/node": "^7.17.2", "@sentry/tracing": "^7.17.2", "@sinclair/typebox": "0.32.34", + "@the-draupnir-project/matrix-basic-types": "^0.1.1", "await-lock": "^2.2.2", "better-sqlite3": "^9.4.3", "body-parser": "^1.20.2", @@ -64,8 +65,8 @@ "js-yaml": "^4.1.0", "jsdom": "^24.0.0", "matrix-appservice-bridge": "^9.0.1", - "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@0.23.4", - "matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.23.4", + "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@1.0.0", + "matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@1.0.0", "parse-duration": "^1.0.2", "pg": "^8.8.0", "shell-quote": "^1.7.3", diff --git a/src/Draupnir.ts b/src/Draupnir.ts index 90bb75f3..232adc2c 100644 --- a/src/Draupnir.ts +++ b/src/Draupnir.ts @@ -16,8 +16,6 @@ import { EventReport, LoggableConfigTracker, Logger, - MatrixRoomID, - MatrixRoomReference, MembershipEvent, Ok, PolicyRoomManager, @@ -27,16 +25,10 @@ import { RoomMembershipRevisionIssuer, RoomMessage, RoomStateManager, - StringRoomID, - StringUserID, Task, TextMessageContent, Value, isError, - isStringRoomAlias, - isStringRoomID, - serverName, - userLocalpart, } from "matrix-protection-suite"; import { UnlistedUserRedactionQueue } from "./queues/UnlistedUserRedactionQueue"; import { findCommandTable } from "./commands/interface-manager/InterfaceCommand"; @@ -69,6 +61,16 @@ import { renderProtectionFailedToStart } from "./protections/ProtectedRoomsSetRe import { draupnirStatusInfo, renderStatusInfo } from "./commands/StatusCommand"; import { renderMatrixAndSend } from "./commands/interface-manager/DeadDocumentMatrix"; import { isInvitationForUser } from "./protections/invitation/inviteCore"; +import { + StringRoomID, + StringUserID, + MatrixRoomID, + isStringRoomID, + isStringRoomAlias, + MatrixRoomReference, + userLocalpart, + userServerName, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("Draupnir"); @@ -403,7 +405,7 @@ export class Draupnir implements Client { } public createRoomReference(roomID: StringRoomID): MatrixRoomID { - return new MatrixRoomID(roomID, [serverName(this.clientUserID)]); + return new MatrixRoomID(roomID, [userServerName(this.clientUserID)]); } public handleEventReport(report: EventReport): void { this.protectedRoomsSet.handleEventReport(report); diff --git a/src/DraupnirBotMode.ts b/src/DraupnirBotMode.ts index 57b84d4f..11016fb1 100644 --- a/src/DraupnirBotMode.ts +++ b/src/DraupnirBotMode.ts @@ -10,11 +10,6 @@ import { isError, - StringUserID, - MatrixRoomReference, - isStringUserID, - isStringRoomAlias, - isStringRoomID, StandardClientsInRoomMap, DefaultEventDecoder, setGlobalLoggerProvider, @@ -32,6 +27,13 @@ import { IConfig } from "./config"; import { Draupnir } from "./Draupnir"; import { DraupnirFactory } from "./draupnirfactory/DraupnirFactory"; import { WebAPIs } from "./webapis/WebAPIs"; +import { + isStringUserID, + isStringRoomAlias, + isStringRoomID, + MatrixRoomReference, + StringUserID, +} from "@the-draupnir-project/matrix-basic-types"; setGlobalLoggerProvider(new BotSDKLogServiceLogger()); diff --git a/src/ManagementRoomOutput.ts b/src/ManagementRoomOutput.ts index 9907d584..7aa68575 100644 --- a/src/ManagementRoomOutput.ts +++ b/src/ManagementRoomOutput.ts @@ -19,12 +19,12 @@ import { IConfig } from "./config"; import { htmlEscape } from "./utils"; import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; import { - Permalinks, - StringRoomAlias, StringRoomID, StringUserID, - serverName, -} from "matrix-protection-suite"; + Permalinks, + StringRoomAlias, + userServerName, +} from "@the-draupnir-project/matrix-basic-types"; const levelToFn = { [LogLevel.DEBUG.toString()]: LogService.debug, @@ -73,7 +73,7 @@ export default class ManagementRoomOutput { return v.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); }; - const viaServers = [serverName(this.clientUserID)]; + const viaServers = [userServerName(this.clientUserID)]; for (const roomId of roomIds) { let alias = roomId; try { diff --git a/src/appservice/AccessControl.ts b/src/appservice/AccessControl.ts index 1f708334..76adc16d 100644 --- a/src/appservice/AccessControl.ts +++ b/src/appservice/AccessControl.ts @@ -8,14 +8,16 @@ // https://github.com/matrix-org/mjolnir // +import { + MatrixRoomID, + StringUserID, +} from "@the-draupnir-project/matrix-basic-types"; import { ActionResult, EntityAccess, - MatrixRoomID, Ok, PolicyListRevisionIssuer, PolicyRoomManager, - StringUserID, isError, AccessControl as MPSAccess, PolicyRoomEditor, diff --git a/src/appservice/Api.ts b/src/appservice/Api.ts index ad0fde35..4944492b 100644 --- a/src/appservice/Api.ts +++ b/src/appservice/Api.ts @@ -14,7 +14,8 @@ import * as bodyParser from "body-parser"; import * as http from "http"; import { Logger } from "matrix-appservice-bridge"; import { AppServiceDraupnirManager } from "./AppServiceDraupnirManager"; -import { isError, isStringUserID } from "matrix-protection-suite"; +import { isError } from "matrix-protection-suite"; +import { isStringUserID } from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("Api"); /** diff --git a/src/appservice/AppService.ts b/src/appservice/AppService.ts index 7241d840..68f392c4 100644 --- a/src/appservice/AppService.ts +++ b/src/appservice/AppService.ts @@ -36,16 +36,18 @@ import { ClientsInRoomMap, DefaultEventDecoder, EventDecoder, - MatrixRoomReference, StandardClientsInRoomMap, - StringRoomID, - StringUserID, Task, isError, - isStringRoomAlias, - isStringRoomID, } from "matrix-protection-suite"; import { AppServiceDraupnirManager } from "./AppServiceDraupnirManager"; +import { + MatrixRoomReference, + StringRoomID, + StringUserID, + isStringRoomAlias, + isStringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("AppService"); /** diff --git a/src/appservice/AppServiceDraupnirManager.ts b/src/appservice/AppServiceDraupnirManager.ts index c64eaf8c..de37c2fe 100644 --- a/src/appservice/AppServiceDraupnirManager.ts +++ b/src/appservice/AppServiceDraupnirManager.ts @@ -22,15 +22,10 @@ import { ActionException, ActionExceptionKind, ActionResult, - MatrixRoomReference, Ok, PropagationType, - StringRoomID, - StringUserID, Task, isError, - isStringRoomID, - userLocalpart, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; import { @@ -44,6 +39,13 @@ import { UnstartedDraupnir, } from "../draupnirfactory/StandardDraupnirManager"; import { DraupnirFactory } from "../draupnirfactory/DraupnirFactory"; +import { + StringUserID, + StringRoomID, + MatrixRoomReference, + userLocalpart, + isStringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("AppServiceDraupnirManager"); diff --git a/src/appservice/bot/AccessCommands.tsx b/src/appservice/bot/AccessCommands.tsx index ee0c8f31..866799b0 100644 --- a/src/appservice/bot/AccessCommands.tsx +++ b/src/appservice/bot/AccessCommands.tsx @@ -12,9 +12,10 @@ import { ParsedKeywords, } from "../../commands/interface-manager/ParameterParsing"; import { AppserviceContext } from "./AppserviceCommandHandler"; -import { UserID, ActionResult } from "matrix-protection-suite"; +import { ActionResult } from "matrix-protection-suite"; import { defineMatrixInterfaceAdaptor } from "../../commands/interface-manager/MatrixInterfaceAdaptor"; import { tickCrossRenderer } from "../../commands/interface-manager/MatrixHelpRenderer"; +import { MatrixUserID } from "@the-draupnir-project/matrix-basic-types"; defineInterfaceCommand({ designator: ["allow"], @@ -22,14 +23,14 @@ defineInterfaceCommand({ parameters: parameters([ { name: "user", - acceptor: findPresentationType("UserID"), + acceptor: findPresentationType("MatrixUserID"), description: "The user that should be allowed to provision a bot", }, ]), command: async function ( this: AppserviceContext, _keywords: ParsedKeywords, - user: UserID + user: MatrixUserID ): Promise> { return await this.appservice.accessControl.allow(user.toString()); }, @@ -48,7 +49,7 @@ defineInterfaceCommand({ parameters: parameters([ { name: "user", - acceptor: findPresentationType("UserID"), + acceptor: findPresentationType("MatrixUserID"), description: "The user which shall not be allowed to provision bots anymore", }, @@ -56,7 +57,7 @@ defineInterfaceCommand({ command: async function ( this: AppserviceContext, _keywords: ParsedKeywords, - user: UserID + user: MatrixUserID ): Promise> { return await this.appservice.accessControl.remove(user.toString()); }, diff --git a/src/appservice/bot/AppserviceCommandHandler.ts b/src/appservice/bot/AppserviceCommandHandler.ts index a1180bec..8dee38cc 100644 --- a/src/appservice/bot/AppserviceCommandHandler.ts +++ b/src/appservice/bot/AppserviceCommandHandler.ts @@ -28,8 +28,6 @@ import { ClientPlatform, Ok, RoomMessage, - StringRoomID, - StringUserID, Task, Value, isError, @@ -57,6 +55,10 @@ export type AppserviceBaseExecutor = ( import "../../commands/interface-manager/MatrixPresentations"; import "./ListCommand"; import "./AccessCommands"; +import { + StringUserID, + StringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; defineInterfaceCommand({ parameters: parameters( diff --git a/src/appservice/bot/ListCommand.tsx b/src/appservice/bot/ListCommand.tsx index 131f7fc2..6e8ff5bc 100644 --- a/src/appservice/bot/ListCommand.tsx +++ b/src/appservice/bot/ListCommand.tsx @@ -22,10 +22,10 @@ import { isError, Ok, RoomEvent, - UserID, } from "matrix-protection-suite"; import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; import { UnstartedDraupnir } from "../../draupnirfactory/StandardDraupnirManager"; +import { MatrixUserID } from "@the-draupnir-project/matrix-basic-types"; /** * There is ovbiously something we're doing very wrong here, @@ -95,14 +95,14 @@ const restart = defineInterfaceCommand({ parameters: parameters([ { name: "draupnir", - acceptor: findPresentationType("UserID"), + acceptor: findPresentationType("MatrixUserID"), description: "The userid of the draupnir to restart", }, ]), command: async function ( this, _keywords, - draupnirUser: UserID + draupnirUser: MatrixUserID ): Promise> { const draupnirManager = this.appservice.draupnirManager; const draupnir = draupnirManager.findUnstartedDraupnir( diff --git a/src/appservice/datastore.ts b/src/appservice/datastore.ts index 62904c5e..2b432193 100644 --- a/src/appservice/datastore.ts +++ b/src/appservice/datastore.ts @@ -8,7 +8,10 @@ // https://github.com/matrix-org/mjolnir // -import { StringRoomID, StringUserID } from "matrix-protection-suite"; +import { + StringUserID, + StringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; export interface MjolnirRecord { local_part: string; diff --git a/src/backingstore/better-sqlite3/SqliteRoomStateBackingStore.ts b/src/backingstore/better-sqlite3/SqliteRoomStateBackingStore.ts index c3ba37c5..8770fc93 100644 --- a/src/backingstore/better-sqlite3/SqliteRoomStateBackingStore.ts +++ b/src/backingstore/better-sqlite3/SqliteRoomStateBackingStore.ts @@ -13,11 +13,11 @@ import { RoomStateRevision, StateChange, StateEvent, - StringRoomID, isError, } from "matrix-protection-suite"; import { BetterSqliteStore } from "./BetterSqliteStore"; import { jsonReviver } from "../../utils"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("SqliteRoomStateBackingStore"); diff --git a/src/capabilities/CommonRenderers.tsx b/src/capabilities/CommonRenderers.tsx index cab27416..688c6b63 100644 --- a/src/capabilities/CommonRenderers.tsx +++ b/src/capabilities/CommonRenderers.tsx @@ -13,11 +13,8 @@ import { ActionException, ActionResult, DescriptionMeta, - MatrixRoomReference, ResultForUsersInRoom, RoomSetResult, - StringRoomID, - StringUserID, isOk, } from "matrix-protection-suite"; import { DocumentNode } from "../commands/interface-manager/DeadDocument"; @@ -26,6 +23,11 @@ import { renderMentionPill, renderRoomPill, } from "../commands/interface-manager/MatrixHelpRenderer"; +import { + StringRoomID, + MatrixRoomReference, + StringUserID, +} from "@the-draupnir-project/matrix-basic-types"; export function renderElaborationTrail(error: ActionError): DocumentNode { return ( diff --git a/src/capabilities/DraupnirRendererMessageCollector.tsx b/src/capabilities/DraupnirRendererMessageCollector.tsx index e59c6d08..01211954 100644 --- a/src/capabilities/DraupnirRendererMessageCollector.tsx +++ b/src/capabilities/DraupnirRendererMessageCollector.tsx @@ -7,10 +7,11 @@ import { RendererMessage, RendererMessageCollector, } from "./RendererMessageCollector"; -import { DescriptionMeta, StringRoomID, Task } from "matrix-protection-suite"; +import { DescriptionMeta, Task } from "matrix-protection-suite"; import { DocumentNode } from "../commands/interface-manager/DeadDocument"; import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix"; import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; export class DraupnirRendererMessageCollector implements RendererMessageCollector diff --git a/src/capabilities/ServerACLConsequencesRenderer.tsx b/src/capabilities/ServerACLConsequencesRenderer.tsx index 8597c823..d09dbb55 100644 --- a/src/capabilities/ServerACLConsequencesRenderer.tsx +++ b/src/capabilities/ServerACLConsequencesRenderer.tsx @@ -13,12 +13,10 @@ import { Capability, DescriptionMeta, Ok, - Permalinks, PolicyListRevision, RoomSetResult, ServerACLConsequencesContext, ServerConsequences, - StringRoomID, describeCapabilityContextGlue, describeCapabilityRenderer, isError, @@ -30,6 +28,10 @@ import { } from "./CommonRenderers"; import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory"; import { Draupnir } from "../Draupnir"; +import { + StringRoomID, + Permalinks, +} from "@the-draupnir-project/matrix-basic-types"; class StandardServerConsequencesRenderer implements ServerConsequences { constructor( diff --git a/src/capabilities/StandardEventConsequencesRenderer.tsx b/src/capabilities/StandardEventConsequencesRenderer.tsx index 5b63828b..ce46f27f 100644 --- a/src/capabilities/StandardEventConsequencesRenderer.tsx +++ b/src/capabilities/StandardEventConsequencesRenderer.tsx @@ -13,10 +13,7 @@ import { Capability, DescriptionMeta, EventConsequences, - Permalinks, RoomEventRedacter, - StringEventID, - StringRoomID, describeCapabilityContextGlue, describeCapabilityRenderer, isError, @@ -25,6 +22,11 @@ import { RendererMessageCollector } from "./RendererMessageCollector"; import { renderFailedSingularConsequence } from "./CommonRenderers"; import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory"; import { Draupnir } from "../Draupnir"; +import { + Permalinks, + StringEventID, + StringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; class StandardEventConsequencesRenderer implements EventConsequences { constructor( diff --git a/src/capabilities/StandardUserConsequencesRenderer.tsx b/src/capabilities/StandardUserConsequencesRenderer.tsx index 224ee5ab..77c3a105 100644 --- a/src/capabilities/StandardUserConsequencesRenderer.tsx +++ b/src/capabilities/StandardUserConsequencesRenderer.tsx @@ -13,16 +13,12 @@ import { ActionResult, Capability, DescriptionMeta, - MatrixRoomReference, Ok, - Permalinks, PolicyListRevision, ResultForUsersInRoom, ResultForUsersInSet, RoomSetResult, StandardUserConsequencesContext, - StringRoomID, - StringUserID, UserConsequences, describeCapabilityContextGlue, describeCapabilityRenderer, @@ -38,6 +34,12 @@ import { import { DocumentNode } from "../commands/interface-manager/DeadDocument"; import { Draupnir } from "../Draupnir"; import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer"; +import { + StringUserID, + StringRoomID, + Permalinks, + MatrixRoomReference, +} from "@the-draupnir-project/matrix-basic-types"; // yeah i know this is a bit insane but whatever, it can be our secret. function renderResultForUserInSetMap( diff --git a/src/commands/AliasCommands.ts b/src/commands/AliasCommands.ts index 64364acd..8c3b5734 100644 --- a/src/commands/AliasCommands.ts +++ b/src/commands/AliasCommands.ts @@ -24,11 +24,13 @@ import { ActionError, ActionResult, isError, - MatrixRoomAlias, - MatrixRoomReference, Ok, } from "matrix-protection-suite"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; +import { + MatrixRoomAlias, + MatrixRoomReference, +} from "@the-draupnir-project/matrix-basic-types"; // TODO: we should probably add an --admin keyword to these commands // since they don't actually need admin. Mjolnir had them as admin though. diff --git a/src/commands/Ban.tsx b/src/commands/Ban.tsx index 9d5ae571..2a73f0f9 100644 --- a/src/commands/Ban.tsx +++ b/src/commands/Ban.tsx @@ -28,15 +28,17 @@ import { PromptOptions } from "./interface-manager/PromptForAccept"; import { Draupnir } from "../Draupnir"; import { ActionResult, - MatrixRoomReference, PolicyRoomEditor, PolicyRuleType, isError, - UserID, Ok, } from "matrix-protection-suite"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; import { findPolicyRoomIDFromShortcode } from "./CreateBanListCommand"; +import { + MatrixRoomReference, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; export async function findPolicyRoomEditorFromRoomReference( draupnir: Draupnir, @@ -55,7 +57,7 @@ export async function findPolicyRoomEditorFromRoomReference( async function ban( this: DraupnirContext, _keywords: ParsedKeywords, - entity: UserID | MatrixRoomReference | string, + entity: MatrixUserID | MatrixRoomReference | string, policyRoomDesignator: MatrixRoomReference | string, ...reasonParts: string[] ): Promise> { @@ -75,7 +77,7 @@ async function ban( } const policyListEditor = policyListEditorResult.ok; const reason = reasonParts.join(" "); - if (entity instanceof UserID) { + if (entity instanceof MatrixUserID) { return await policyListEditor.banEntity( PolicyRuleType.User, entity.toString(), @@ -111,7 +113,7 @@ defineInterfaceCommand({ { name: "entity", acceptor: union( - findPresentationType("UserID"), + findPresentationType("MatrixUserID"), findPresentationType("MatrixRoomReference"), findPresentationType("string") ), diff --git a/src/commands/CommandHandler.ts b/src/commands/CommandHandler.ts index 6201d2f7..0f870a3c 100644 --- a/src/commands/CommandHandler.ts +++ b/src/commands/CommandHandler.ts @@ -29,9 +29,9 @@ import { ActionResult, ResultError, RoomMessage, - StringRoomID, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; export interface DraupnirContext extends MatrixContext { draupnir: Draupnir; diff --git a/src/commands/CreateBanListCommand.ts b/src/commands/CreateBanListCommand.ts index 4fe5aa35..b94f567a 100644 --- a/src/commands/CreateBanListCommand.ts +++ b/src/commands/CreateBanListCommand.ts @@ -11,7 +11,6 @@ import { ActionError, ActionResult, - MatrixRoomID, Ok, PolicyRuleType, PropagationType, @@ -31,6 +30,7 @@ import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfac import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer"; import { listInfo } from "./StatusCommand"; import { Draupnir } from "../Draupnir"; +import { MatrixRoomID } from "@the-draupnir-project/matrix-basic-types"; export async function createList( this: DraupnirContext, diff --git a/src/commands/DeactivateCommand.ts b/src/commands/DeactivateCommand.ts index 2e5bade3..ada956be 100644 --- a/src/commands/DeactivateCommand.ts +++ b/src/commands/DeactivateCommand.ts @@ -24,9 +24,9 @@ import { ActionError, ActionResult, Ok, - UserID, isError, } from "matrix-protection-suite"; +import { MatrixUserID } from "@the-draupnir-project/matrix-basic-types"; defineInterfaceCommand({ table: "synapse admin", @@ -36,13 +36,13 @@ defineInterfaceCommand({ parameters: parameters([ { name: "user", - acceptor: findPresentationType("UserID"), + acceptor: findPresentationType("MatrixUserID"), }, ]), command: async function ( this: DraupnirContext, _keywords: ParsedKeywords, - targetUser: UserID + targetUser: MatrixUserID ): Promise> { const isAdmin = await this.draupnir.synapseAdminClient?.isSynapseAdmin(); if (isAdmin === undefined || isError(isAdmin) || !isAdmin.ok) { diff --git a/src/commands/HijackRoomCommand.ts b/src/commands/HijackRoomCommand.ts index 0dae2516..5a628f7b 100644 --- a/src/commands/HijackRoomCommand.ts +++ b/src/commands/HijackRoomCommand.ts @@ -23,18 +23,20 @@ import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfac import { ActionError, ActionResult, - MatrixRoomReference, Ok, - UserID, isError, } from "matrix-protection-suite"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; +import { + MatrixRoomReference, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; async function hijackRoomCommand( this: DraupnirContext, _keywords: ParsedKeywords, room: MatrixRoomReference, - user: UserID + user: MatrixUserID ): Promise> { const isAdmin = await this.draupnir.synapseAdminClient?.isSynapseAdmin(); if ( @@ -71,7 +73,7 @@ defineInterfaceCommand({ }, { name: "user", - acceptor: findPresentationType("UserID"), + acceptor: findPresentationType("MatrixUserID"), }, ]), command: hijackRoomCommand, diff --git a/src/commands/ImportCommand.ts b/src/commands/ImportCommand.ts index 8f5a104c..942fde42 100644 --- a/src/commands/ImportCommand.ts +++ b/src/commands/ImportCommand.ts @@ -11,7 +11,6 @@ import { DraupnirBaseExecutor, DraupnirContext } from "./CommandHandler"; import { ActionResult, - MatrixRoomReference, MultipleErrors, PolicyRuleType, RoomActionError, @@ -30,6 +29,7 @@ import { } from "./interface-manager/ParameterParsing"; import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor"; import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer"; +import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types"; export async function importCommand( this: DraupnirContext, diff --git a/src/commands/KickCommand.tsx b/src/commands/KickCommand.tsx index 9871db74..ae21254a 100644 --- a/src/commands/KickCommand.tsx +++ b/src/commands/KickCommand.tsx @@ -13,11 +13,7 @@ import { DraupnirContext } from "./CommandHandler"; import { ActionError, ActionResult, - MatrixRoomReference, Ok, - StringRoomID, - StringUserID, - UserID, isError, } from "matrix-protection-suite"; import { @@ -36,6 +32,12 @@ import { import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor"; import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix"; import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer"; +import { + StringUserID, + StringRoomID, + MatrixRoomReference, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; type UsersToKick = Map; @@ -77,7 +79,7 @@ function renderUsersToKick(usersToKick: UsersToKick): DocumentNode { export async function kickCommand( this: DraupnirContext, keywords: ParsedKeywords, - user: UserID, + user: MatrixUserID, ...reasonParts: string[] ): Promise> { const restrictToRoomReference = keywords.getKeyword( @@ -143,7 +145,7 @@ defineInterfaceCommand({ [ { name: "user", - acceptor: findPresentationType("string"), + acceptor: findPresentationType("MatrixUserID"), }, ], undefined, diff --git a/src/commands/ProtectionsCommands.tsx b/src/commands/ProtectionsCommands.tsx index 81abbe6b..2db86a9a 100644 --- a/src/commands/ProtectionsCommands.tsx +++ b/src/commands/ProtectionsCommands.tsx @@ -27,7 +27,6 @@ import { ProtectionSetting, ProtectionSettings, RoomEvent, - StringRoomID, UnknownSettings, findProtection, getAllProtections, @@ -41,6 +40,7 @@ import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; import { DeadDocumentJSX } from "./interface-manager/JSXFactory"; import { DocumentNode } from "./interface-manager/DeadDocument"; import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; defineInterfaceCommand({ designator: ["protections", "enable"], diff --git a/src/commands/RedactCommand.ts b/src/commands/RedactCommand.ts index 62eb0776..8b970ab1 100644 --- a/src/commands/RedactCommand.ts +++ b/src/commands/RedactCommand.ts @@ -8,16 +8,7 @@ // https://github.com/matrix-org/mjolnir // -import { - ActionResult, - MatrixEventReference, - MatrixEventViaAlias, - MatrixEventViaRoomID, - MatrixRoomReference, - Ok, - UserID, - isError, -} from "matrix-protection-suite"; +import { ActionResult, Ok, isError } from "matrix-protection-suite"; import { redactUserMessagesIn } from "../utils"; import { KeywordsDescription, @@ -36,6 +27,13 @@ import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot import { Draupnir } from "../Draupnir"; import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor"; import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer"; +import { + MatrixEventReference, + MatrixEventViaAlias, + MatrixEventViaRoomID, + MatrixRoomReference, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; export async function redactEvent( draupnir: Draupnir, @@ -60,7 +58,7 @@ export async function redactEvent( export async function redactCommand( this: DraupnirContext, keywords: ParsedKeywords, - reference: UserID | MatrixEventReference, + reference: MatrixUserID | MatrixEventReference, ...reasonParts: string[] ): Promise> { const reason = reasonParts.join(" "); @@ -106,7 +104,7 @@ defineInterfaceCommand({ { name: "entity", acceptor: union( - findPresentationType("UserID"), + findPresentationType("MatrixUserID"), findPresentationType("MatrixEventReference") ), }, diff --git a/src/commands/ResolveAlias.tsx b/src/commands/ResolveAlias.tsx index 3d8361a4..4dcd0d42 100644 --- a/src/commands/ResolveAlias.tsx +++ b/src/commands/ResolveAlias.tsx @@ -8,12 +8,7 @@ // https://github.com/matrix-org/mjolnir // -import { - ActionResult, - MatrixRoomAlias, - MatrixRoomID, - isError, -} from "matrix-protection-suite"; +import { ActionResult, isError } from "matrix-protection-suite"; import { DraupnirContext } from "./CommandHandler"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; import { @@ -32,6 +27,10 @@ import { } from "./interface-manager/MatrixHelpRenderer"; import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix"; import { DeadDocumentJSX } from "./interface-manager/JSXFactory"; +import { + MatrixRoomAlias, + MatrixRoomID, +} from "@the-draupnir-project/matrix-basic-types"; async function resolveAliasCommand( this: DraupnirContext, diff --git a/src/commands/Rooms.tsx b/src/commands/Rooms.tsx index 74bec84f..3b058532 100644 --- a/src/commands/Rooms.tsx +++ b/src/commands/Rooms.tsx @@ -26,12 +26,14 @@ import { ActionException, ActionExceptionKind, ActionResult, - MatrixRoomID, - MatrixRoomReference, Ok, isError, } from "matrix-protection-suite"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; +import { + MatrixRoomID, + MatrixRoomReference, +} from "@the-draupnir-project/matrix-basic-types"; defineInterfaceCommand({ table: "draupnir", diff --git a/src/commands/Rules.tsx b/src/commands/Rules.tsx index 63824012..394acfc7 100644 --- a/src/commands/Rules.tsx +++ b/src/commands/Rules.tsx @@ -29,17 +29,19 @@ import { } from "./interface-manager/ParameterParsing"; import { ActionResult, - MatrixRoomID, - MatrixRoomReference, Ok, PolicyRoomWatchProfile, PolicyRule, - StringRoomID, isError, - UserID, RoomEvent, } from "matrix-protection-suite"; import { listInfo } from "./StatusCommand"; +import { + StringRoomID, + MatrixRoomID, + MatrixRoomReference, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; async function renderListMatches( this: MatrixInterfaceAdaptor, @@ -144,7 +146,7 @@ defineInterfaceCommand({ { name: "entity", acceptor: union( - findPresentationType("UserID"), + findPresentationType("MatrixUserID"), findPresentationType("MatrixRoomReference"), findPresentationType("string") ), @@ -153,7 +155,7 @@ defineInterfaceCommand({ command: async function ( this: DraupnirContext, _keywords, - entity: string | UserID | MatrixRoomReference + entity: string | MatrixUserID | MatrixRoomReference ): Promise> { const policyRooms = await listInfo(this.draupnir); return Ok( diff --git a/src/commands/SetPowerLevelCommand.ts b/src/commands/SetPowerLevelCommand.ts index 4e7a4900..0ac9b9e9 100644 --- a/src/commands/SetPowerLevelCommand.ts +++ b/src/commands/SetPowerLevelCommand.ts @@ -8,14 +8,7 @@ // https://github.com/matrix-org/mjolnir // -import { - ActionResult, - MatrixRoomID, - MatrixRoomReference, - Ok, - UserID, - isError, -} from "matrix-protection-suite"; +import { ActionResult, Ok, isError } from "matrix-protection-suite"; import { DraupnirContext } from "./CommandHandler"; import { ParsedKeywords, @@ -25,11 +18,16 @@ import { } from "./interface-manager/ParameterParsing"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; import { defineInterfaceCommand } from "./interface-manager/InterfaceCommand"; +import { + MatrixRoomID, + MatrixRoomReference, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; async function setPowerLevelCommand( this: DraupnirContext, _keywords: ParsedKeywords, - user: UserID, + user: MatrixUserID, powerLevel: string, ...givenRooms: MatrixRoomReference[] ): Promise> { @@ -64,7 +62,7 @@ defineInterfaceCommand({ [ { name: "user", - acceptor: findPresentationType("UserID"), + acceptor: findPresentationType("MatrixUserID"), }, { name: "power level", diff --git a/src/commands/ShutdownRoomCommand.ts b/src/commands/ShutdownRoomCommand.ts index bd34fb0f..5e1d76f2 100644 --- a/src/commands/ShutdownRoomCommand.ts +++ b/src/commands/ShutdownRoomCommand.ts @@ -24,11 +24,11 @@ import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer"; import { ActionError, ActionResult, - MatrixRoomReference, Ok, isError, } from "matrix-protection-suite"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; +import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types"; defineInterfaceCommand({ table: "synapse admin", diff --git a/src/commands/Unban.ts b/src/commands/Unban.ts index 58afa781..58e4181c 100644 --- a/src/commands/Unban.ts +++ b/src/commands/Unban.ts @@ -27,14 +27,16 @@ import { Draupnir } from "../Draupnir"; import { ActionResult, isError, - isStringUserID, - MatrixRoomReference, Ok, PolicyRuleType, - UserID, } from "matrix-protection-suite"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; import { findPolicyRoomIDFromShortcode } from "./CreateBanListCommand"; +import { + isStringUserID, + MatrixRoomReference, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; async function unbanUserFromRooms(draupnir: Draupnir, rule: MatrixGlob) { await draupnir.managementRoomOutput.logMessage( @@ -75,7 +77,7 @@ async function unbanUserFromRooms(draupnir: Draupnir, rule: MatrixGlob) { async function unban( this: DraupnirContext, keywords: ParsedKeywords, - entity: UserID | MatrixRoomReference | string, + entity: MatrixUserID | MatrixRoomReference | string, policyRoomDesignator: MatrixRoomReference | string ): Promise> { const policyRoomReference = @@ -98,7 +100,7 @@ async function unban( return policyRoomEditor; } const policyRoomUnban = - entity instanceof UserID + entity instanceof MatrixUserID ? await policyRoomEditor.ok.unbanEntity( PolicyRuleType.User, entity.toString() @@ -121,7 +123,7 @@ async function unban( if (isError(policyRoomUnban)) { return policyRoomUnban; } - if (typeof entity === "string" || entity instanceof UserID) { + if (typeof entity === "string" || entity instanceof MatrixUserID) { const rawEnttiy = typeof entity === "string" ? entity : entity.toString(); const isGlob = (string: string) => string.includes("*") ? true : string.includes("?"); @@ -154,7 +156,7 @@ defineInterfaceCommand({ { name: "entity", acceptor: union( - findPresentationType("UserID"), + findPresentationType("MatrixUserID"), findPresentationType("MatrixRoomReference"), findPresentationType("string") ), diff --git a/src/commands/WatchUnwatchCommand.ts b/src/commands/WatchUnwatchCommand.ts index df1e3199..a3c98d15 100644 --- a/src/commands/WatchUnwatchCommand.ts +++ b/src/commands/WatchUnwatchCommand.ts @@ -22,11 +22,11 @@ import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer"; import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor"; import { ActionResult, - MatrixRoomReference, PropagationType, isError, } from "matrix-protection-suite"; import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; +import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types"; defineInterfaceCommand({ table: "draupnir", diff --git a/src/commands/interface-manager/CommandReader.ts b/src/commands/interface-manager/CommandReader.ts index e94be53e..4c5249d5 100644 --- a/src/commands/interface-manager/CommandReader.ts +++ b/src/commands/interface-manager/CommandReader.ts @@ -10,12 +10,14 @@ import { MatrixEventReference, MatrixRoomReference, + MatrixUserID, Permalinks, - UserID, - isError, isStringRoomAlias, isStringRoomID, -} from "matrix-protection-suite"; + isStringUserID, +} from "@the-draupnir-project/matrix-basic-types"; +import { isError } from "matrix-protection-suite"; + export interface SuperCoolStream { readonly source: Sequence; peekItem(eof?: EOF): Item | EOF; @@ -189,7 +191,7 @@ const WORD_DISPATCH_CHARACTERS = new Map(); export type ReadItem = | string | MatrixRoomReference - | UserID + | MatrixUserID | Keyword | MatrixEventReference; @@ -292,7 +294,7 @@ defineReadItem("!", readRoomIDOrAlias); /** * Read the word as a UserID, otherwise return a string if what has been read doesn not represent a user. */ -defineReadItem("@", (stream: StringStream): UserID | string => { +defineReadItem("@", (stream: StringStream): MatrixUserID | string => { const word: string[] = [stream.readChar()]; readUntil(/[:\s]/, stream, word); if ( @@ -302,7 +304,11 @@ defineReadItem("@", (stream: StringStream): UserID | string => { return word.join(""); } readUntil(/\s/, stream, word); - return new UserID(word.join("")); + const protoUserID = word.join(""); + if (!isStringUserID(protoUserID)) { + return protoUserID; + } + return new MatrixUserID(protoUserID); }); /** @@ -353,7 +359,7 @@ definePostReadReplace(/^https:\/\/matrix\.to/, (input) => { return eventResult.ok; } } else if (url.userID !== undefined) { - return new UserID(url.userID); + return new MatrixUserID(url.userID); } else { const roomResult = MatrixRoomReference.fromPermalink(input); if (isError(roomResult)) { diff --git a/src/commands/interface-manager/DeadDocumentPresentation.ts b/src/commands/interface-manager/DeadDocumentPresentation.ts index 9c25d650..27f559fd 100644 --- a/src/commands/interface-manager/DeadDocumentPresentation.ts +++ b/src/commands/interface-manager/DeadDocumentPresentation.ts @@ -2,7 +2,10 @@ // // SPDX-License-Identifier: Apache-2.0 -import { MatrixRoomAlias, MatrixRoomID } from "matrix-protection-suite"; +import { + MatrixRoomID, + MatrixRoomAlias, +} from "@the-draupnir-project/matrix-basic-types"; import { DocumentNode } from "./DeadDocument"; import { PresentationType, diff --git a/src/commands/interface-manager/MatrixHelpRenderer.tsx b/src/commands/interface-manager/MatrixHelpRenderer.tsx index 4978b5b6..77080733 100644 --- a/src/commands/interface-manager/MatrixHelpRenderer.tsx +++ b/src/commands/interface-manager/MatrixHelpRenderer.tsx @@ -27,10 +27,8 @@ import { ActionException, ActionExceptionKind, ActionResult, - MatrixRoomReference, Ok, RoomEvent, - StringRoomID, Task, isError, isOk, @@ -41,6 +39,10 @@ import { renderExceptionTrail, } from "../../capabilities/CommonRenderers"; import { printReadably } from "./PrintReadably"; +import { + MatrixRoomReference, + StringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; function requiredArgument(argumentName: string): string { return `<${argumentName}>`; diff --git a/src/commands/interface-manager/MatrixInterfaceAdaptor.ts b/src/commands/interface-manager/MatrixInterfaceAdaptor.ts index d5cd52ec..620a525d 100644 --- a/src/commands/interface-manager/MatrixInterfaceAdaptor.ts +++ b/src/commands/interface-manager/MatrixInterfaceAdaptor.ts @@ -31,12 +31,12 @@ import { ClientPlatform, ResultError, RoomEvent, - StringRoomID, Task, isError, } from "matrix-protection-suite"; import { MatrixReactionHandler } from "./MatrixReactionHandler"; import { PromptRequiredError } from "./PromptRequiredError"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; export interface MatrixContext { reactionHandler: MatrixReactionHandler; diff --git a/src/commands/interface-manager/MatrixPresentations.tsx b/src/commands/interface-manager/MatrixPresentations.tsx index bb5e5be5..3b86a226 100644 --- a/src/commands/interface-manager/MatrixPresentations.tsx +++ b/src/commands/interface-manager/MatrixPresentations.tsx @@ -17,14 +17,14 @@ import { MatrixRoomAlias, MatrixRoomID, MatrixRoomReference, - UserID, -} from "matrix-protection-suite"; + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; makePresentationType({ - name: "UserID", + name: "MatrixUserID", validator: simpleTypeValidator( - "UserID", - (item: ReadItem) => item instanceof UserID + "MatrixUserID", + (item: ReadItem) => item instanceof MatrixUserID ), }); @@ -64,8 +64,8 @@ makePresentationType({ // Wouldn't this be better as a custom document node so that we could render the plain text version differently? definePresentationRenderer( - findPresentationType("UserID"), - function (presentation: UserID): DocumentNode { + findPresentationType("MatrixUserID"), + function (presentation: MatrixUserID): DocumentNode { return ( {presentation.toString()} diff --git a/src/commands/interface-manager/MatrixPromptForAccept.tsx b/src/commands/interface-manager/MatrixPromptForAccept.tsx index b9fa5635..1666fbbd 100644 --- a/src/commands/interface-manager/MatrixPromptForAccept.tsx +++ b/src/commands/interface-manager/MatrixPromptForAccept.tsx @@ -6,7 +6,6 @@ import { ClientPlatform, Logger, RoomEvent, - StringRoomID, Task, Value, isError, @@ -28,6 +27,7 @@ import { StaticDecode, Type } from "@sinclair/typebox"; import { ReadItem, readCommand } from "./CommandReader"; import { printReadably } from "./PrintReadably"; import { DeadDocumentPresentationMirror } from "./DeadDocumentPresentation"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("MatrixPromptForAccept"); diff --git a/src/commands/interface-manager/MatrixReactionHandler.ts b/src/commands/interface-manager/MatrixReactionHandler.ts index bcf8e476..78e380c1 100644 --- a/src/commands/interface-manager/MatrixReactionHandler.ts +++ b/src/commands/interface-manager/MatrixReactionHandler.ts @@ -10,13 +10,15 @@ import { Logger, ReactionEvent, RoomEvent, - StringEventID, - StringRoomID, - StringUserID, Task, Value, isError, } from "matrix-protection-suite"; +import { + StringRoomID, + StringUserID, + StringEventID, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("MatrixReactionHandler"); diff --git a/src/commands/interface-manager/PrintReadably.ts b/src/commands/interface-manager/PrintReadably.ts index 4e968c74..a500942b 100644 --- a/src/commands/interface-manager/PrintReadably.ts +++ b/src/commands/interface-manager/PrintReadably.ts @@ -3,19 +3,19 @@ // SPDX-License-Identifier: AFL-3.0 import { + MatrixRoomID, + MatrixRoomAlias, MatrixEventViaAlias, MatrixEventViaRoomID, - MatrixRoomAlias, - MatrixRoomID, Permalinks, - UserID, -} from "matrix-protection-suite"; + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; import { ReadItem } from "./CommandReader"; export function printReadably(item: ReadItem): string { if (item instanceof MatrixRoomID || item instanceof MatrixRoomAlias) { return item.toPermalink(); - } else if (item instanceof UserID) { + } else if (item instanceof MatrixUserID) { return item.toString(); } else if ( item instanceof MatrixEventViaAlias || diff --git a/src/draupnirfactory/DraupnirFactory.ts b/src/draupnirfactory/DraupnirFactory.ts index 40698e9f..a18dcb3e 100644 --- a/src/draupnirfactory/DraupnirFactory.ts +++ b/src/draupnirfactory/DraupnirFactory.ts @@ -5,9 +5,7 @@ import { ActionResult, ClientsInRoomMap, - MatrixRoomID, StandardLoggableConfigTracker, - StringUserID, isError, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; @@ -19,6 +17,10 @@ import { } from "matrix-protection-suite-for-matrix-bot-sdk"; import { IConfig } from "../config"; import { makeProtectedRoomsSet } from "./DraupnirProtectedRoomsSet"; +import { + StringUserID, + MatrixRoomID, +} from "@the-draupnir-project/matrix-basic-types"; export class DraupnirFactory { public constructor( diff --git a/src/draupnirfactory/DraupnirProtectedRoomsSet.ts b/src/draupnirfactory/DraupnirProtectedRoomsSet.ts index f4992b5f..3fbf16b6 100644 --- a/src/draupnirfactory/DraupnirProtectedRoomsSet.ts +++ b/src/draupnirfactory/DraupnirProtectedRoomsSet.ts @@ -15,7 +15,6 @@ import { Logger, MJOLNIR_PROTECTED_ROOMS_EVENT_TYPE, MJOLNIR_WATCHED_POLICY_ROOMS_EVENT_TYPE, - MatrixRoomID, MissingProtectionCB, MjolnirEnabledProtectionsEvent, MjolnirEnabledProtectionsEventType, @@ -40,7 +39,6 @@ import { StandardProtectionsManager, StandardSetMembership, StandardSetRoomState, - StringUserID, isError, } from "matrix-protection-suite"; import { @@ -53,6 +51,10 @@ import "../protections/DraupnirProtectionsIndex"; import { IConfig } from "../config"; import { runProtectionConfigHooks } from "../protections/ConfigHooks"; import { makeHandleMissingProtectionPermissions } from "../protections/MissingProtectionPermissions"; +import { + MatrixRoomID, + StringUserID, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("DraupnirProtectedRoomsSet"); diff --git a/src/draupnirfactory/StandardDraupnirManager.ts b/src/draupnirfactory/StandardDraupnirManager.ts index 502972a4..2c76f99f 100644 --- a/src/draupnirfactory/StandardDraupnirManager.ts +++ b/src/draupnirfactory/StandardDraupnirManager.ts @@ -11,14 +11,16 @@ import { ActionError, ActionResult, - MatrixRoomID, - StringUserID, Task, isError, } from "matrix-protection-suite"; import { IConfig } from "../config"; import { DraupnirFactory } from "./DraupnirFactory"; import { Draupnir } from "../Draupnir"; +import { + StringUserID, + MatrixRoomID, +} from "@the-draupnir-project/matrix-basic-types"; export class StandardDraupnirManager { private readonly readyDraupnirs = new Map(); diff --git a/src/models/RoomUpdateError.tsx b/src/models/RoomUpdateError.tsx index 31177a7c..858f8e43 100644 --- a/src/models/RoomUpdateError.tsx +++ b/src/models/RoomUpdateError.tsx @@ -8,6 +8,7 @@ // https://github.com/matrix-org/mjolnir // +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; import { DocumentNode } from "../commands/interface-manager/DeadDocument"; import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix"; import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory"; @@ -17,7 +18,6 @@ import { ActionResult, Ok, RoomUpdateError, - StringRoomID, } from "matrix-protection-suite"; import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; diff --git a/src/protections/BanPropagation.tsx b/src/protections/BanPropagation.tsx index 65b17514..9ff6c90c 100644 --- a/src/protections/BanPropagation.tsx +++ b/src/protections/BanPropagation.tsx @@ -20,8 +20,6 @@ import { AbstractProtection, ActionResult, Logger, - MatrixRoomID, - MatrixRoomReference, MembershipChange, MembershipChangeType, Ok, @@ -34,12 +32,9 @@ import { RoomActionError, RoomMembershipRevision, RoomUpdateError, - StringRoomID, - StringUserID, Task, describeProtection, isError, - serverName, UnknownSettings, UserConsequences, Membership, @@ -49,6 +44,13 @@ import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot import { DraupnirProtection } from "./Protection"; import { listInfo } from "../commands/StatusCommand"; import { MatrixReactionHandler } from "../commands/interface-manager/MatrixReactionHandler"; +import { + MatrixRoomID, + StringRoomID, + MatrixRoomReference, + StringUserID, + userServerName, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("BanPropagationProtection"); @@ -410,7 +412,7 @@ export class BanPropagationProtection ); if (editablePolicyRoom === undefined) { const roomID = MatrixRoomReference.fromRoomID(roomIDWithPolicy, [ - serverName(this.draupnir.clientUserID), + userServerName(this.draupnir.clientUserID), ]); errors.push( new PermissionError( diff --git a/src/protections/BasicFlooding.ts b/src/protections/BasicFlooding.ts index 527501a7..2c216025 100644 --- a/src/protections/BasicFlooding.ts +++ b/src/protections/BasicFlooding.ts @@ -8,6 +8,12 @@ // https://github.com/matrix-org/mjolnir // +import { + StringEventID, + StringUserID, + StringRoomID, + MatrixRoomID, +} from "@the-draupnir-project/matrix-basic-types"; import { Draupnir } from "../Draupnir"; import { DraupnirProtection } from "./Protection"; import { LogLevel } from "matrix-bot-sdk"; @@ -16,16 +22,12 @@ import { ActionResult, EventConsequences, Logger, - MatrixRoomID, Ok, ProtectedRoomsSet, ProtectionDescription, RoomEvent, SafeIntegerProtectionSetting, StandardProtectionSettings, - StringEventID, - StringRoomID, - StringUserID, UserConsequences, describeProtection, isError, diff --git a/src/protections/FirstMessageIsImage.ts b/src/protections/FirstMessageIsImage.ts index dc7a917a..fcafab83 100644 --- a/src/protections/FirstMessageIsImage.ts +++ b/src/protections/FirstMessageIsImage.ts @@ -13,7 +13,6 @@ import { AbstractProtection, ActionResult, EventConsequences, - MatrixRoomID, MembershipChange, MembershipChangeType, Ok, @@ -23,13 +22,16 @@ import { RoomEvent, RoomMembershipRevision, RoomMessage, - StringRoomID, - StringUserID, UserConsequences, Value, describeProtection, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; +import { + MatrixRoomID, + StringRoomID, + StringUserID, +} from "@the-draupnir-project/matrix-basic-types"; type FirstMessageIsImageProtectionSettings = Record; @@ -83,8 +85,7 @@ export class FirstMessageIsImageProtection extends AbstractProtection implements Protection { - private justJoined: { [roomID: StringRoomID]: StringUserID[] | undefined } = - {}; + private justJoined: { [roomID: StringRoomID]: StringUserID[] } = {}; private recentlyBanned: StringUserID[] = []; private readonly userConsequences: UserConsequences; diff --git a/src/protections/JoinWaveShortCircuit.tsx b/src/protections/JoinWaveShortCircuit.tsx index 0f4ebd7b..53306ee3 100644 --- a/src/protections/JoinWaveShortCircuit.tsx +++ b/src/protections/JoinWaveShortCircuit.tsx @@ -21,13 +21,13 @@ import { RoomMembershipRevision, SafeIntegerProtectionSetting, StandardProtectionSettings, - StringRoomID, describeProtection, isError, } from "matrix-protection-suite"; import { LogLevel } from "matrix-bot-sdk"; import { Draupnir } from "../Draupnir"; import { DraupnirProtection } from "./Protection"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("JoinWaveShortCircuitProtection"); diff --git a/src/protections/MessageIsMedia.ts b/src/protections/MessageIsMedia.ts index 4b056a44..43456510 100644 --- a/src/protections/MessageIsMedia.ts +++ b/src/protections/MessageIsMedia.ts @@ -13,9 +13,7 @@ import { AbstractProtection, ActionResult, EventConsequences, - MatrixRoomID, Ok, - Permalinks, ProtectedRoomsSet, Protection, ProtectionDescription, @@ -23,9 +21,13 @@ import { RoomMessage, Value, describeProtection, - serverName, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; +import { + MatrixRoomID, + Permalinks, + userServerName, +} from "@the-draupnir-project/matrix-basic-types"; type MessageIsMediaProtectionSettings = Record; @@ -108,7 +110,7 @@ export class MessageIsMediaProtection await this.draupnir.managementRoomOutput.logMessage( LogLevel.WARN, "MessageIsMedia", - `Redacting event from ${event["sender"]} for posting an image/video. ${Permalinks.forEvent(roomID, event["event_id"], [serverName(this.draupnir.clientUserID)])}` + `Redacting event from ${event["sender"]} for posting an image/video. ${Permalinks.forEvent(roomID, event["event_id"], [userServerName(this.draupnir.clientUserID)])}` ); // Redact the event if (this.draupnir.config.noop) { diff --git a/src/protections/MessageIsVoice.ts b/src/protections/MessageIsVoice.ts index 9f63f3cf..1e4546dc 100644 --- a/src/protections/MessageIsVoice.ts +++ b/src/protections/MessageIsVoice.ts @@ -14,9 +14,7 @@ import { ActionResult, CapabilitySet, EventConsequences, - MatrixRoomID, Ok, - Permalinks, ProtectedRoomsSet, Protection, ProtectionDescription, @@ -24,9 +22,13 @@ import { RoomMessage, Value, describeProtection, - serverName, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; +import { + MatrixRoomID, + Permalinks, + userServerName, +} from "@the-draupnir-project/matrix-basic-types"; type MessageIsVoiceCapabilities = { eventConsequences: EventConsequences; @@ -100,7 +102,7 @@ export class MessageIsVoiceProtection await this.draupnir.managementRoomOutput.logMessage( LogLevel.INFO, "MessageIsVoice", - `Redacting event from ${event["sender"]} for posting a voice message. ${Permalinks.forEvent(roomID, event["event_id"], [serverName(this.draupnir.clientUserID)])}` + `Redacting event from ${event["sender"]} for posting a voice message. ${Permalinks.forEvent(roomID, event["event_id"], [userServerName(this.draupnir.clientUserID)])}` ); // Redact the event if (!this.draupnir.config.noop) { diff --git a/src/protections/MissingProtectionPermissions.tsx b/src/protections/MissingProtectionPermissions.tsx index e95eac0e..8c9ccb2a 100644 --- a/src/protections/MissingProtectionPermissions.tsx +++ b/src/protections/MissingProtectionPermissions.tsx @@ -4,9 +4,7 @@ import { HandleMissingProtectionPermissions, - MatrixRoomReference, ProtectionPermissionsChange, - StringRoomID, Task, } from "matrix-protection-suite"; import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix"; @@ -14,6 +12,10 @@ import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory"; import { DocumentNode } from "../commands/interface-manager/DeadDocument"; import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer"; +import { + StringRoomID, + MatrixRoomReference, +} from "@the-draupnir-project/matrix-basic-types"; function renderPermissions( title: DocumentNode, diff --git a/src/protections/NewJoinerProtection.ts b/src/protections/NewJoinerProtection.ts index 001a94b3..105ebe23 100644 --- a/src/protections/NewJoinerProtection.ts +++ b/src/protections/NewJoinerProtection.ts @@ -18,10 +18,10 @@ import { UserConsequences, describeProtection, isError, - serverName, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; import { IConfig } from "../config"; +import { userServerName } from "@the-draupnir-project/matrix-basic-types"; export type NewJoinerProtectionDescription = ProtectionDescription< unknown, @@ -57,7 +57,7 @@ export class NewJoinerProtection const errors: ActionError[] = []; for (const change of changes) { if (change.membershipChangeType === MembershipChangeType.Joined) { - if (this.bannedServers.has(serverName(change.userID))) { + if (this.bannedServers.has(userServerName(change.userID))) { const banResult = await this.userConsequences.consequenceForUserInRoom( revision.room.toRoomIDOrAlias(), diff --git a/src/protections/PolicyChangeNotification.tsx b/src/protections/PolicyChangeNotification.tsx index 4a640870..ec8f2330 100644 --- a/src/protections/PolicyChangeNotification.tsx +++ b/src/protections/PolicyChangeNotification.tsx @@ -12,7 +12,6 @@ import { AbstractProtection, ActionResult, Logger, - MatrixRoomReference, Ok, PolicyListRevision, PolicyRoomManager, @@ -20,7 +19,6 @@ import { PolicyRuleChange, ProtectedRoomsSet, ProtectionDescription, - StringRoomID, UnknownSettings, describeProtection, isError, @@ -34,6 +32,10 @@ import { renderRoomPill, } from "../commands/interface-manager/MatrixHelpRenderer"; import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix"; +import { + StringRoomID, + MatrixRoomReference, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("PolicyChangeNotification"); diff --git a/src/protections/ProtectedRoomsSetRenderers.tsx b/src/protections/ProtectedRoomsSetRenderers.tsx index 6d08a95d..d1b4cab9 100644 --- a/src/protections/ProtectedRoomsSetRenderers.tsx +++ b/src/protections/ProtectedRoomsSetRenderers.tsx @@ -8,14 +8,11 @@ // https://github.com/matrix-org/mjolnir // -import { - ActionError, - ProtectionDescription, - StringRoomID, -} from "matrix-protection-suite"; +import { ActionError, ProtectionDescription } from "matrix-protection-suite"; import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix"; import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; export async function renderProtectionFailedToStart( client: MatrixSendClient, diff --git a/src/protections/RedactionSynchronisation.ts b/src/protections/RedactionSynchronisation.ts index 7d8c6239..add028aa 100644 --- a/src/protections/RedactionSynchronisation.ts +++ b/src/protections/RedactionSynchronisation.ts @@ -11,7 +11,6 @@ import { AbstractProtection, ActionResult, CapabilitySet, - MatrixGlob, MembershipChange, MembershipChangeType, Ok, @@ -26,13 +25,16 @@ import { Recommendation, RoomMembershipRevision, SimpleChangeType, - StringRoomID, - StringUserID, Task, describeProtection, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; import { redactUserMessagesIn } from "../utils"; +import { + MatrixGlob, + StringRoomID, + StringUserID, +} from "@the-draupnir-project/matrix-basic-types"; type RedactionSynchronisationProtectionDescription = ProtectionDescription; diff --git a/src/protections/TrustedReporters.ts b/src/protections/TrustedReporters.ts index 6c78df8e..40ff2143 100644 --- a/src/protections/TrustedReporters.ts +++ b/src/protections/TrustedReporters.ts @@ -19,14 +19,16 @@ import { ProtectionDescription, SafeIntegerProtectionSetting, StandardProtectionSettings, - StringEventID, - StringUserID, StringUserIDSetProtectionSettings, UserConsequences, describeProtection, isError, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; +import { + StringUserID, + StringEventID, +} from "@the-draupnir-project/matrix-basic-types"; const MAX_REPORTED_EVENT_BACKLOG = 20; diff --git a/src/protections/WordList.ts b/src/protections/WordList.ts index c21270c0..e23be6f7 100644 --- a/src/protections/WordList.ts +++ b/src/protections/WordList.ts @@ -13,7 +13,6 @@ import { ActionResult, EventConsequences, Logger, - MatrixRoomID, MembershipChange, MembershipChangeType, Ok, @@ -23,13 +22,16 @@ import { RoomEvent, RoomMembershipRevision, RoomMessage, - StringRoomID, - StringUserID, UserConsequences, Value, describeProtection, } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; +import { + StringUserID, + StringRoomID, + MatrixRoomID, +} from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("WordList"); diff --git a/src/protections/invitation/JoinRoomsOnInviteProtection.tsx b/src/protections/invitation/JoinRoomsOnInviteProtection.tsx index f21937be..283aa41a 100644 --- a/src/protections/invitation/JoinRoomsOnInviteProtection.tsx +++ b/src/protections/invitation/JoinRoomsOnInviteProtection.tsx @@ -12,17 +12,14 @@ import { AbstractProtection, ActionError, ActionResult, - MatrixRoomReference, MembershipEvent, Ok, ProtectedRoomsSet, ProtectionDescription, StandardDeduplicator, - StringRoomID, Task, describeProtection, isError, - serverName, } from "matrix-protection-suite"; import { Draupnir } from "../../Draupnir"; import { DraupnirProtection } from "../Protection"; @@ -37,6 +34,11 @@ import { import { renderFailedSingularConsequence } from "../../capabilities/CommonRenderers"; import { ProtectroomsOnInvite } from "./ProtectRoomsOnInvite"; import { WatchRoomsOnInvite } from "./WatchRoomsOnInvite"; +import { + StringRoomID, + MatrixRoomReference, + userServerName, +} from "@the-draupnir-project/matrix-basic-types"; export type JoinRoomsOnInviteProtectionCapabilities = Record; export type JoinRoomsOnInviteProtectionSettings = Record; @@ -165,8 +167,8 @@ export class JoinRoomsOnInviteProtection event: MembershipEvent ): Promise> { const invitedRoomReference = MatrixRoomReference.fromRoomID(event.room_id, [ - serverName(event.sender), - serverName(event.state_key), + userServerName(event.sender), + userServerName(event.state_key), ]); const joinResult = await this.joinInvitedRoom(event, invitedRoomReference); if (isError(joinResult)) { diff --git a/src/protections/invitation/ProtectRoomsOnInvite.tsx b/src/protections/invitation/ProtectRoomsOnInvite.tsx index da17af06..0a0a9e2b 100644 --- a/src/protections/invitation/ProtectRoomsOnInvite.tsx +++ b/src/protections/invitation/ProtectRoomsOnInvite.tsx @@ -10,15 +10,14 @@ import { Logger, - MatrixRoomID, MembershipEvent, Ok, - Permalink, ProtectedRoomsSet, RoomEvent, Task, Value, isError, + PermalinkSchema, } from "matrix-protection-suite"; import { DocumentNode } from "../../commands/interface-manager/DeadDocument"; import { @@ -30,6 +29,7 @@ import { DeadDocumentJSX } from "../../commands/interface-manager/JSXFactory"; import { renderMatrixAndSend } from "../../commands/interface-manager/DeadDocumentMatrix"; import { StaticDecode, Type } from "@sinclair/typebox"; import { Draupnir } from "../../Draupnir"; +import { MatrixRoomID } from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("ProtectRoomsOnInvite"); @@ -38,7 +38,7 @@ const PROTECT_ROOMS_ON_INVITE_PROMPT_LISTENER = // would be nice to be able to use presentation types here idk. const ProtectRoomsOnInvitePromptContext = Type.Object({ - invited_room: Permalink, + invited_room: PermalinkSchema, }); // this rule is stupid. diff --git a/src/protections/invitation/WatchRoomsOnInvite.tsx b/src/protections/invitation/WatchRoomsOnInvite.tsx index 7c311480..d81b7f40 100644 --- a/src/protections/invitation/WatchRoomsOnInvite.tsx +++ b/src/protections/invitation/WatchRoomsOnInvite.tsx @@ -12,10 +12,9 @@ import { ALL_RULE_TYPES, Logger, MJOLNIR_SHORTCODE_EVENT_TYPE, - MatrixRoomID, MembershipEvent, Ok, - Permalink, + PermalinkSchema, PropagationType, ProtectedRoomsSet, RoomEvent, @@ -34,6 +33,7 @@ import { } from "../../commands/interface-manager/MatrixHelpRenderer"; import { renderMatrixAndSend } from "../../commands/interface-manager/DeadDocumentMatrix"; import { StaticDecode, Type } from "@sinclair/typebox"; +import { MatrixRoomID } from "@the-draupnir-project/matrix-basic-types"; const log = new Logger("WatchRoomsOnInvite"); @@ -42,7 +42,7 @@ const WATCH_LISTS_ON_INVITE_PROMPT_LISTENER = // would be nice to be able to use presentation types here idk. const WatchRoomsOnInvitePromptContext = Type.Object({ - invited_room: Permalink, + invited_room: PermalinkSchema, }); // this rule is stupid. diff --git a/src/protections/invitation/inviteCore.ts b/src/protections/invitation/inviteCore.ts index 3ab626e5..ef4bf3f1 100644 --- a/src/protections/invitation/inviteCore.ts +++ b/src/protections/invitation/inviteCore.ts @@ -2,11 +2,11 @@ // // SPDX-License-Identifier: AFL-3.0 +import { StringUserID } from "@the-draupnir-project/matrix-basic-types"; import { Membership, MembershipEvent, RoomMembershipRevision, - StringUserID, } from "matrix-protection-suite"; export function isInvitationForUser( diff --git a/src/queues/EventRedactionQueue.ts b/src/queues/EventRedactionQueue.ts index 3a8a9602..30fdddc7 100644 --- a/src/queues/EventRedactionQueue.ts +++ b/src/queues/EventRedactionQueue.ts @@ -14,12 +14,14 @@ import ManagementRoomOutput from "../ManagementRoomOutput"; import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; import { ActionExceptionKind, - MatrixRoomReference, RoomUpdateError, RoomUpdateException, +} from "matrix-protection-suite"; +import { StringRoomID, StringUserID, -} from "matrix-protection-suite"; + MatrixRoomReference, +} from "@the-draupnir-project/matrix-basic-types"; export interface QueuedRedaction { /** The room which the redaction will take place in. */ diff --git a/src/queues/ProtectedRoomActivityTracker.ts b/src/queues/ProtectedRoomActivityTracker.ts index 94222410..6fa67615 100644 --- a/src/queues/ProtectedRoomActivityTracker.ts +++ b/src/queues/ProtectedRoomActivityTracker.ts @@ -8,7 +8,8 @@ // https://github.com/matrix-org/mjolnir // -import { RoomEvent, StringRoomID } from "matrix-protection-suite"; +import { StringRoomID } from "@the-draupnir-project/matrix-basic-types"; +import { RoomEvent } from "matrix-protection-suite"; /** * Used to keep track of protected rooms so they are always ordered for activity. diff --git a/src/queues/UnlistedUserRedactionQueue.ts b/src/queues/UnlistedUserRedactionQueue.ts index 7eb029c1..58fa8152 100644 --- a/src/queues/UnlistedUserRedactionQueue.ts +++ b/src/queues/UnlistedUserRedactionQueue.ts @@ -8,13 +8,13 @@ // https://github.com/matrix-org/mjolnir // import { LogLevel, LogService } from "matrix-bot-sdk"; -import { - Permalinks, - RoomEvent, - StringRoomID, - StringUserID, -} from "matrix-protection-suite"; +import { RoomEvent } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; +import { + StringUserID, + StringRoomID, + Permalinks, +} from "@the-draupnir-project/matrix-basic-types"; /** * A queue of users who have been flagged for redaction typically by the flooding or image protection. diff --git a/src/report/ReportManager.ts b/src/report/ReportManager.ts index d75e3959..096a4931 100644 --- a/src/report/ReportManager.ts +++ b/src/report/ReportManager.ts @@ -15,19 +15,21 @@ import { htmlEscape } from "../utils"; import { JSDOM } from "jsdom"; import { Draupnir } from "../Draupnir"; import { - MatrixRoomReference, ReactionContent, RoomEvent, RoomMessage, - StringEventID, - StringRoomID, - StringUserID, Task, TextMessageContent, Value, isError, - serverName, } from "matrix-protection-suite"; +import { + StringRoomID, + StringUserID, + StringEventID, + MatrixRoomReference, + userServerName, +} from "@the-draupnir-project/matrix-basic-types"; /// Regexp, used to extract the action label from an action reaction /// such as `⚽ Kick user @foobar:localhost from room [kick-user]`. @@ -967,7 +969,7 @@ class DisplayManager { const roomID = event["room_id"]; const room = MatrixRoomReference.fromRoomID(roomID, [ - serverName(this.owner.draupnir.clientUserID), + userServerName(this.owner.draupnir.clientUserID), ]); const eventId = event["event_id"]; const MAX_EVENT_CONTENT_LENGTH = 2048; diff --git a/src/webapis/WebAPIs.ts b/src/webapis/WebAPIs.ts index f6609739..1a309f32 100644 --- a/src/webapis/WebAPIs.ts +++ b/src/webapis/WebAPIs.ts @@ -13,7 +13,11 @@ import express from "express"; import { MatrixClient } from "matrix-bot-sdk"; import { ReportManager } from "../report/ReportManager"; import { IConfig } from "../config"; -import { StringEventID, StringRoomID, Task } from "matrix-protection-suite"; +import { + StringRoomID, + StringEventID, +} from "@the-draupnir-project/matrix-basic-types"; +import { Task } from "matrix-protection-suite"; /** * A common prefix for all web-exposed APIs. diff --git a/test/commands/CommandReaderTest.ts b/test/commands/CommandReaderTest.ts index 9eb81433..3b678f02 100644 --- a/test/commands/CommandReaderTest.ts +++ b/test/commands/CommandReaderTest.ts @@ -7,7 +7,11 @@ import { Keyword, readCommand, } from "../../src/commands/interface-manager/CommandReader"; -import { MatrixRoomAlias, MatrixRoomID, UserID } from "matrix-protection-suite"; +import { + MatrixRoomAlias, + MatrixRoomID, + MatrixUserID, +} from "@the-draupnir-project/matrix-basic-types"; describe("Can read", function () { it("Can read a simple command with only strings", function () { @@ -56,8 +60,8 @@ describe("Can read", function () { it("Can parse userID's", function () { const command = "@spam:example.com"; const readItems = readCommand(command); - expect(readItems.at(0)).toBeInstanceOf(UserID); - const user = readItems.at(0) as UserID; + expect(readItems.at(0)).toBeInstanceOf(MatrixUserID); + const user = readItems.at(0) as MatrixUserID; expect(user.localpart).toBe("spam"); }); }); diff --git a/test/commands/ParseTest.ts b/test/commands/ParseTest.ts index 3ecb88fe..75677090 100644 --- a/test/commands/ParseTest.ts +++ b/test/commands/ParseTest.ts @@ -17,7 +17,7 @@ import { import { readCommand } from "../../src/commands/interface-manager/CommandReader"; import "../../src/commands/interface-manager/MatrixPresentations"; -it("A command that fookin parses mxids", async function () { +it("A command that parses mxids", async function () { const tableName = Symbol("ParseTest"); defineCommandTable(tableName); defineInterfaceCommand({ @@ -28,7 +28,7 @@ it("A command that fookin parses mxids", async function () { { name: "entity", acceptor: union( - findPresentationType("UserID"), + findPresentationType("MatrixUserID"), findPresentationType("MatrixRoomReference"), findPresentationType("string") ), diff --git a/test/integration/abuseReportTest.ts b/test/integration/abuseReportTest.ts index 6b6d3ce9..ff7b208e 100644 --- a/test/integration/abuseReportTest.ts +++ b/test/integration/abuseReportTest.ts @@ -17,9 +17,9 @@ import { ReactionContent, ReactionEvent, RoomMessage, - StringEventID, Value, } from "matrix-protection-suite"; +import { StringEventID } from "@the-draupnir-project/matrix-basic-types"; /** * Test the ability to turn abuse reports into room messages. diff --git a/test/integration/banPropagationTest.ts b/test/integration/banPropagationTest.ts index 09120976..fa996c84 100644 --- a/test/integration/banPropagationTest.ts +++ b/test/integration/banPropagationTest.ts @@ -7,15 +7,17 @@ import { newTestUser } from "./clientHelper"; import { getFirstEventMatching } from "./commands/commandUtils"; import { DraupnirTestContext, draupnirClient } from "./mjolnirSetupUtils"; import { - MatrixRoomReference, NoticeMessageContent, PolicyRuleType, PropagationType, RoomMessage, - StringRoomID, Value, findProtection, } from "matrix-protection-suite"; +import { + MatrixRoomReference, + StringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; // We will need to disable this in tests that are banning people otherwise it will cause // mocha to hang for awhile until it times out waiting for a response to a prompt. diff --git a/test/integration/commands/commandUtils.ts b/test/integration/commands/commandUtils.ts index fbeb4195..99032419 100644 --- a/test/integration/commands/commandUtils.ts +++ b/test/integration/commands/commandUtils.ts @@ -16,9 +16,9 @@ import { NoticeMessageContent, ReactionEvent, RoomEvent, - StringEventID, TextMessageContent, Value, + StringEventIDSchema, } from "matrix-protection-suite"; import { Type } from "@sinclair/typebox"; @@ -26,7 +26,7 @@ export const ReplyContent = Type.Intersect([ Type.Object({ "m.relates_to": Type.Object({ "m.in_reply_to": Type.Object({ - event_id: StringEventID, + event_id: StringEventIDSchema, }), }), }), diff --git a/test/integration/fixtures.ts b/test/integration/fixtures.ts index baf5db93..efaca9a5 100644 --- a/test/integration/fixtures.ts +++ b/test/integration/fixtures.ts @@ -9,7 +9,6 @@ // import { - MatrixRoomReference, MJOLNIR_PROTECTED_ROOMS_EVENT_TYPE, MJOLNIR_WATCHED_POLICY_ROOMS_EVENT_TYPE, } from "matrix-protection-suite"; @@ -22,6 +21,7 @@ import { makeMjolnir, teardownManagementRoom, } from "./mjolnirSetupUtils"; +import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types"; patchMatrixClient(); diff --git a/test/integration/reportPollingTest.ts b/test/integration/reportPollingTest.ts index 761d208b..a2dcfc72 100644 --- a/test/integration/reportPollingTest.ts +++ b/test/integration/reportPollingTest.ts @@ -13,14 +13,16 @@ import { newTestUser } from "./clientHelper"; import { DraupnirTestContext } from "./mjolnirSetupUtils"; import { ActionResult, - MatrixRoomReference, Ok, Protection, ProtectionDescription, StandardProtectionSettings, - StringRoomID, Task, } from "matrix-protection-suite"; +import { + MatrixRoomReference, + StringRoomID, +} from "@the-draupnir-project/matrix-basic-types"; describe("Test: Report polling", function () { let client: MatrixClient; diff --git a/yarn.lock b/yarn.lock index d70a1db5..afdcbd2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -93,6 +93,11 @@ resolved "https://registry.yarnpkg.com/@eslint/object-schema/-/object-schema-2.1.4.tgz#9e69f8bb4031e11df79e03db09f9dbbae1740843" integrity sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ== +"@gnuxie/typescript-result@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@gnuxie/typescript-result/-/typescript-result-0.2.0.tgz#870e29d079341c32a7cae7e0ee77ffdd09aad60f" + integrity sha512-V5VZUpl21fRNTBHqdigWVkkXhoue/6MVfpWLBOMVgi5unR4ePoXjzNXc9diNmnmDe+mrQfXGPT8LiB18Cc+0Ig== + "@humanwhocodes/module-importer@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz#af5b2691a22b44be847b0ca81641c5fb6ad0172c" @@ -221,6 +226,14 @@ resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA== +"@the-draupnir-project/matrix-basic-types@^0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@the-draupnir-project/matrix-basic-types/-/matrix-basic-types-0.1.1.tgz#27a131e2f92d6d25b377f7339177d8ac204d95a2" + integrity sha512-g5CDAdQMe1dxbVlzPvrrPPluZCFKaBqJ2iAarspGHkr0V3YBBCdz9v3Yb6TY8e2d/eXz5gSWDKzeZElWD33oeA== + dependencies: + "@gnuxie/typescript-result" "^0.2.0" + glob-to-regexp "^0.4.1" + "@types/better-sqlite3@^7.6.9": version "7.6.9" resolved "https://registry.yarnpkg.com/@types/better-sqlite3/-/better-sqlite3-7.6.9.tgz#4bff3eb7c5eaaae26f8099606c69279146561c50" @@ -2405,16 +2418,17 @@ matrix-appservice@^2.0.0: request-promise "^4.2.6" sanitize-html "^2.8.0" -"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.23.4": - version "0.23.4" - resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-0.23.4.tgz#7c5bafa045382a4d4c27f1c30a4420a32f05859e" - integrity sha512-P9jIj17aunodVZ7AghszKxR7zH+fLDaWZdWyFnKR9YRLIG5trMBh5rcCKPUpLnhTCe4apSFHyLXDnmb4zZW08w== +"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-1.0.0.tgz#7d303359cd1d2a676c4968b7de4e5d9993405159" + integrity sha512-/vY0TjQEcupFqOZplLMCCwY24XRmkIYOEaYKrQeLmjj1aN1nniXwaLWwCd3aQHBDzcxsw8agRQuy46JcAhTPpw== -"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@0.23.4": - version "0.23.4" - resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-0.23.4.tgz#1f4b1089888ad9d512b3eca8c4b9cb4c4111ec58" - integrity sha512-hC2DVGwgZLpYjKtPHCTxqap/8QeZ3W3KyHoic/9oWnlAx0FLaz7WLNGUqtTuFpmU+NWX6H0TmX2szaMHoTTqXw== +"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-1.0.0.tgz#7e1eb2cd5df818c736d83b217998b77dc9667160" + integrity sha512-XoNRzJnRgU0qgdHhId2IMvrnvaW7jx884DEh/3NssKv0Bmyccbr0DBAq7aNbXWO2T0L88aYyPENYL+j9oZKmuQ== dependencies: + "@gnuxie/typescript-result" "^0.2.0" await-lock "^2.2.2" crypto-js "^4.2.0" glob-to-regexp "^0.4.1"