Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Simplify matrix-js-sdk imports #11305

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
52 changes: 50 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,56 @@ module.exports = {
],
patterns: [
{
group: ["matrix-js-sdk/lib", "matrix-js-sdk/lib/", "matrix-js-sdk/lib/**"],
message: "Please use matrix-js-sdk/src/* instead",
group: [
"matrix-js-sdk/src/**",
"!matrix-js-sdk/src/matrix",
// XXX: Temporarily allow
"!matrix-js-sdk/src/browser-index",
"!matrix-js-sdk/src/room-hierarchy",
"!matrix-js-sdk/src/NamespacedValue",
"!matrix-js-sdk/src/logger",
"!matrix-js-sdk/src/utils",
"!matrix-js-sdk/src/feature",
"!matrix-js-sdk/src/content-helpers",
"!matrix-js-sdk/src/autodiscovery",
"!matrix-js-sdk/src/ReEmitter",
"!matrix-js-sdk/src/rendezvous",
"!matrix-js-sdk/src/pushprocessor",
"!matrix-js-sdk/src/webrtc/call",
"!matrix-js-sdk/src/webrtc/callFeed",
"!matrix-js-sdk/src/webrtc/callEventHandler",
"!matrix-js-sdk/src/webrtc/groupCallEventHandler",
"!matrix-js-sdk/src/webrtc/mediaHandler",
"!matrix-js-sdk/src/oidc/error",
"!matrix-js-sdk/src/oidc/authorize",
"!matrix-js-sdk/src/oidc/validate",
"!matrix-js-sdk/src/oidc/register",
"!matrix-js-sdk/src/models/relations-container",
"!matrix-js-sdk/src/randomstring",
"!matrix-js-sdk/src/crypto",
"!matrix-js-sdk/src/crypto/deviceinfo",
"!matrix-js-sdk/src/crypto/CrossSigning",
"!matrix-js-sdk/src/crypto/api",
"!matrix-js-sdk/src/crypto/RoomList",
"!matrix-js-sdk/src/crypto/olmlib",
"!matrix-js-sdk/src/crypto/verification/request/VerificationRequest",
"!matrix-js-sdk/src/@types/global",
"!matrix-js-sdk/src/@types/read_receipts",
"!matrix-js-sdk/src/@types/extensible_events",
"!matrix-js-sdk/src/@types/threepids",
"!matrix-js-sdk/src/@types/location",
"!matrix-js-sdk/src/@types/beacon",
"!matrix-js-sdk/src/@types/local_notifications",
"!matrix-js-sdk/src/@types/crypto",
"!matrix-js-sdk/src/@types/topic",
"!matrix-js-sdk/src/@types/auth",
"!matrix-js-sdk/src/@types/polls",
"!matrix-js-sdk/src/@types/IIdentityServerProvider",
"matrix-js-sdk/lib",
"matrix-js-sdk/lib/",
"matrix-js-sdk/lib/**",
],
message: "Please use matrix-js-sdk/src/matrix instead",
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/composer/composer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

/// <reference types="cypress" />
import { EventType } from "matrix-js-sdk/src/@types/event";
import { EventType } from "matrix-js-sdk/src/matrix";

import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { SettingLevel } from "../../../src/settings/SettingLevel";
Expand Down
5 changes: 2 additions & 3 deletions cypress/e2e/crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { ISendEventResponse, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import type { VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import type { ISendEventResponse, MatrixClient, Room, Crypto } from "matrix-js-sdk/src/matrix";
import type { CypressBot } from "../../support/bot";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { UserCredentials } from "../../support/login";
Expand Down Expand Up @@ -116,7 +115,7 @@ const verify = function (this: CryptoTestContext) {
// this requires creating a DM, so can take a while. Give it a longer timeout.
cy.findByRole("button", { name: "Verify by emoji", timeout: 30000 }).click();

cy.wrap(bobsVerificationRequestPromise).then(async (request: VerificationRequest) => {
cy.wrap(bobsVerificationRequestPromise).then(async (request: Crypto.VerificationRequest) => {
// the bot user races with the Element user to hit the "verify by emoji" button
const verifier = await request.startVerification("m.sas.v1");
doTwoWaySasVerification(verifier);
Expand Down
17 changes: 8 additions & 9 deletions cypress/e2e/crypto/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import type { VerificationRequest, Verifier } from "matrix-js-sdk/src/crypto-api";
import type { MatrixClient, Crypto } from "matrix-js-sdk/src/matrix";
import { ShowSasCallbacks } from "matrix-js-sdk/src/crypto-api/verification";

export type EmojiMapping = [emoji: string, name: string];

Expand All @@ -25,9 +24,9 @@ export type EmojiMapping = [emoji: string, name: string];
*
* @param cli - matrix client we expect to receive a request
*/
export function waitForVerificationRequest(cli: MatrixClient): Promise<VerificationRequest> {
return new Promise<VerificationRequest>((resolve) => {
const onVerificationRequestEvent = async (request: VerificationRequest) => {
export function waitForVerificationRequest(cli: MatrixClient): Promise<Crypto.VerificationRequest> {
return new Promise<Crypto.VerificationRequest>((resolve) => {
const onVerificationRequestEvent = async (request: Crypto.VerificationRequest) => {
await request.accept();
resolve(request);
};
Expand All @@ -45,9 +44,9 @@ export function waitForVerificationRequest(cli: MatrixClient): Promise<Verificat
* @param verifier - verifier
* @returns A promise that resolves, with the emoji list, once we confirm the emojis
*/
export function handleSasVerification(verifier: Verifier): Promise<EmojiMapping[]> {
export function handleSasVerification(verifier: Crypto.Verifier): Promise<EmojiMapping[]> {
return new Promise<EmojiMapping[]>((resolve) => {
const onShowSas = (event: ISasEvent) => {
const onShowSas = (event: Crypto.ShowSasCallbacks) => {
// @ts-ignore VerifierEvent is a pain to get at here as we don't have a reference to matrixcs;
// using the string value here
verifier.off("show_sas", onShowSas);
Expand Down Expand Up @@ -123,7 +122,7 @@ export function logIntoElement(homeserverUrl: string, username: string, password
*
* @param botVerificationRequest - a verification request in a bot client
*/
export function doTwoWaySasVerification(verifier: Verifier): void {
export function doTwoWaySasVerification(verifier: Crypto.Verifier): void {
// on the bot side, wait for the emojis, confirm they match, and return them
const emojiPromise = handleSasVerification(verifier);

Expand Down
26 changes: 14 additions & 12 deletions cypress/e2e/crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import jsQR from "jsqr";

import type { VerificationRequest, Verifier } from "matrix-js-sdk/src/crypto-api/verification";
import type { Crypto } from "matrix-js-sdk/src/matrix";
import { CypressBot } from "../../support/bot";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { emitPromise, skipIfRustCrypto } from "../../support/util";
Expand Down Expand Up @@ -95,13 +95,15 @@ describe("Device verification", () => {

// Handle emoji SAS verification
cy.get(".mx_InfoDialog").within(() => {
cy.get<VerificationRequest>("@verificationRequest").then(async (request: VerificationRequest) => {
// the bot chooses to do an emoji verification
const verifier = await request.startVerification("m.sas.v1");
cy.get<Crypto.VerificationRequest>("@verificationRequest").then(
async (request: Crypto.VerificationRequest) => {
// the bot chooses to do an emoji verification
const verifier = await request.startVerification("m.sas.v1");

// Handle emoji request and check that emojis are matching
doTwoWaySasVerification(verifier);
});
// Handle emoji request and check that emojis are matching
doTwoWaySasVerification(verifier);
},
);

cy.findByRole("button", { name: "They match" }).click();
cy.findByRole("button", { name: "Got it" }).click();
Expand All @@ -120,8 +122,8 @@ describe("Device verification", () => {
cy.get(".mx_InfoDialog").within(() => {
cy.get('[alt="QR Code"]').then((qrCode) => {
/* the bot scans the QR code */
cy.get<VerificationRequest>("@verificationRequest")
.then(async (request: VerificationRequest) => {
cy.get<Crypto.VerificationRequest>("@verificationRequest")
.then(async (request: Crypto.VerificationRequest) => {
// because I don't know how to scrape the imagedata from the cypress browser window,
// we extract the data url and render it to a new canvas.
const imageData = await renderQRCode(qrCode.attr("src"));
Expand All @@ -143,7 +145,7 @@ describe("Device verification", () => {
});

// wait for the bot to see we have finished
cy.get<Verifier>("@verifier").then(async (verifier) => {
cy.get<Crypto.Verifier>("@verifier").then(async (verifier) => {
await verifier.verify();
});

Expand Down Expand Up @@ -222,7 +224,7 @@ describe("Device verification", () => {
});

/* Now initiate a verification request from the *bot* device. */
let botVerificationRequest: VerificationRequest;
let botVerificationRequest: Crypto.VerificationRequest;
cy.then(() => {
async function initVerification() {
botVerificationRequest = await aliceBotClient
Expand Down Expand Up @@ -256,7 +258,7 @@ describe("Device verification", () => {
return botVerificationRequest.verifier;
}

cy.then(() => cy.wrap(awaitVerifier())).then((verifier: Verifier) => {
cy.then(() => cy.wrap(awaitVerifier())).then((verifier: Crypto.Verifier) => {
// ... confirm ...
botVerificationRequest.verifier.verify();

Expand Down
4 changes: 1 addition & 3 deletions cypress/e2e/editing/editing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ limitations under the License.

/// <reference types="cypress" />

import type { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
import type { ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
import type { IContent } from "matrix-js-sdk/src/models/event";
import type { EventType, MsgType, ISendEventResponse, IContent } from "matrix-js-sdk/src/matrix";
import { SettingLevel } from "../../../src/settings/SettingLevel";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import Chainable = Cypress.Chainable;
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/invite/invite-dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";

describe("Invite dialog", function () {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/read-receipts/read-receipts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
/// <reference types="cypress" />

import type { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
import type { ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
import type { ISendEventResponse } from "matrix-js-sdk/src/matrix";
import type { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import { HomeserverInstance } from "../../plugins/utils/homeserver";

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/room/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

/// <reference types="cypress" />

import { EventType } from "matrix-js-sdk/src/@types/event";
import { EventType } from "matrix-js-sdk/src/matrix";

import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { MatrixClient } from "../../global";
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/spaces/spaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ limitations under the License.

/// <reference types="cypress" />

import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { Preset } from "matrix-js-sdk/src/@types/partials";
import type { ICreateRoomOpts } from "matrix-js-sdk/src/@types/requests";
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import type { Preset } from "matrix-js-sdk/src/matrix";
import type { ICreateRoomOpts } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import Chainable = Cypress.Chainable;
import { UserCredentials } from "../../support/login";
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/timeline/timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ limitations under the License.

/// <reference types="cypress" />

import type { ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
import type { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
import type { ISendEventResponse } from "matrix-js-sdk/src/matrix";
import type { EventType, MsgType } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { SettingLevel } from "../../../src/settings/SettingLevel";
import { Layout } from "../../../src/settings/enums/Layout";
Expand Down
1 change: 1 addition & 0 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
import "../src/@types/global";
import "../src/@types/svg";
import "../src/@types/raw-loader";
// eslint-disable-next-line no-restricted-imports
import "matrix-js-sdk/src/@types/global";
import type {
MatrixClient,
Expand Down
12 changes: 7 additions & 5 deletions cypress/support/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ limitations under the License.

/// <reference types="cypress" />

import type { ISendEventResponse, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
import type { AddSecretStorageKeyOpts } from "matrix-js-sdk/src/secret-storage";
import type { ISendEventResponse, MatrixClient, Room, SecretStorage, Crypto } from "matrix-js-sdk/src/matrix";
import { HomeserverInstance } from "../plugins/utils/homeserver";
import { Credentials } from "./homeserver";
import Chainable = Cypress.Chainable;
Expand Down Expand Up @@ -64,7 +62,7 @@ const defaultCreateBotOptions = {

export interface CypressBot extends MatrixClient {
__cypress_password: string;
__cypress_recovery_key: GeneratedSecretStorageKey;
__cypress_recovery_key: Crypto.GeneratedSecretStorageKey;
}

declare global {
Expand Down Expand Up @@ -152,7 +150,11 @@ function setupBotClient(

// Store the cached secret storage key and return it when `getSecretStorageKey` is called
let cachedKey: { keyId: string; key: Uint8Array };
const cacheSecretStorageKey = (keyId: string, keyInfo: AddSecretStorageKeyOpts, key: Uint8Array) => {
const cacheSecretStorageKey = (
keyId: string,
keyInfo: SecretStorage.AddSecretStorageKeyOpts,
key: Uint8Array,
) => {
cachedKey = {
keyId,
key,
Expand Down
10 changes: 5 additions & 5 deletions cypress/support/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ limitations under the License.

/// <reference types="cypress" />

import type { FileType, Upload, UploadOpts } from "matrix-js-sdk/src/http-api";
import type { ICreateRoomOpts, ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { Room } from "matrix-js-sdk/src/models/room";
import type { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event";
import type { FileType, Upload, UploadOpts } from "matrix-js-sdk/src/matrix";
import type { ICreateRoomOpts, ISendEventResponse } from "matrix-js-sdk/src/matrix";
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import type { Room } from "matrix-js-sdk/src/matrix";
import type { IContent, MatrixEvent } from "matrix-js-sdk/src/matrix";
import type { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import Chainable = Cypress.Chainable;
import { UserCredentials } from "./login";
Expand Down
1 change: 1 addition & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// eslint-disable-next-line no-restricted-imports
import "matrix-js-sdk/src/@types/global"; // load matrix-js-sdk's type extensions first
import "@types/modernizr";

Expand Down
8 changes: 4 additions & 4 deletions src/Avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { User } from "matrix-js-sdk/src/models/user";
import { Room } from "matrix-js-sdk/src/models/room";
import { ResizeMethod } from "matrix-js-sdk/src/@types/partials";
import { RoomMember } from "matrix-js-sdk/src/matrix";
import { User } from "matrix-js-sdk/src/matrix";
import { Room } from "matrix-js-sdk/src/matrix";
import { ResizeMethod } from "matrix-js-sdk/src/matrix";

import DMRoomMap from "./utils/DMRoomMap";
import { mediaFromMxc } from "./customisations/Media";
Expand Down
6 changes: 2 additions & 4 deletions src/BasePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { encodeUnpaddedBase64 } from "matrix-js-sdk/src/crypto/olmlib";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { SSOAction } from "matrix-js-sdk/src/@types/auth";
import { SSOAction, Room, MatrixEvent } from "matrix-js-sdk/src/matrix";

import dis from "./dispatcher/dispatcher";
import BaseEventIndexManager from "./indexing/BaseEventIndexManager";
Expand Down
8 changes: 4 additions & 4 deletions src/ContentMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixClient } from "matrix-js-sdk/src/client";
import { MsgType } from "matrix-js-sdk/src/@types/event";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { MsgType } from "matrix-js-sdk/src/matrix";
import encrypt from "matrix-encrypt-attachment";
import extractPngChunks from "png-chunks-extract";
import { IImageInfo } from "matrix-js-sdk/src/@types/partials";
import { IImageInfo } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import {
HTTPError,
Expand All @@ -30,7 +30,7 @@ import {
UploadOpts,
UploadProgress,
} from "matrix-js-sdk/src/matrix";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/matrix";
import { removeElement } from "matrix-js-sdk/src/utils";

import {
Expand Down
2 changes: 1 addition & 1 deletion src/DecryptionFailureTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import { DecryptionError } from "matrix-js-sdk/src/crypto/algorithms";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
import { Error as ErrorEvent } from "@matrix-org/analytics-events/types/typescript/Error";

import { PosthogAnalytics } from "./PosthogAnalytics";
Expand Down
Loading