diff --git a/types/matrix-appservice-bridge/index.d.ts b/types/matrix-appservice-bridge/index.d.ts index 8f416f02c6..6c41bd4d7a 100644 --- a/types/matrix-appservice-bridge/index.d.ts +++ b/types/matrix-appservice-bridge/index.d.ts @@ -4,10 +4,6 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.1 -/// - -import { EventEmitter } from 'events'; - import { EventType, MsgType, diff --git a/types/matrix-js-sdk/index.d.ts b/types/matrix-js-sdk/index.d.ts index 5f7a4315a5..8777f8796b 100644 --- a/types/matrix-js-sdk/index.d.ts +++ b/types/matrix-js-sdk/index.d.ts @@ -1,13 +1,16 @@ -// Type definitions for matrix-js-sdk 5.0 +// Type definitions for matrix-js-sdk 5.1 // Project: https://github.com/matrix-org/matrix-js-sdk // Definitions by: Huan LI (李卓桓) +// André Vitor L. Matos // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -/// - import { EventEmitter } from 'events'; +// avoid requiring 'request' type +export function request(r: any): void; +export function getRequest(): any; + export type MatrixCallback = (err: null | object, data: any) => void; export class MatrixError { @@ -64,8 +67,8 @@ export class Room { getJoinedMembers(): RoomMember[]; getLiveTimeline(): EventTimeline; getMember(userId: string): RoomMember; - getMembersWithMembership(membership: string): RoomMember[]; - getMyMembership(myUserId: string): string; + getMembersWithMembership(membership: MembershipType): RoomMember[]; + getMyMembership(): MembershipType | null; getOrCreateFilteredTimelineSet(filter: Filter): EventTimelineSet; getPendingEvents(): MatrixEvent[]; getReceiptsForEvent(event: MatrixEvent): object[]; @@ -135,7 +138,8 @@ export type EventType = never |'m.room.redaction' |'m.room.tombstone' |'m.room.topic' - |'m.sticker'; + |'m.sticker' + |'m.presence'; export type MsgType = never |'m.audio' @@ -150,15 +154,112 @@ export type MsgType = never export type MembershipType = never |'ban' |'invite' - |'joined' |'join' |'leave'; + +export interface MatrixStore { + isNewlyCreated(): Promise; + getSyncToken(): string | null; + setSyncToken(token: string): void; + storeGroup(group: Group): void; + getGroup(groupId: string): Group | null; + getGroups(): Group[]; + storeRoom(room: Room): void; + getRoom(roomId: string): Room | null; + getRooms(): Room[]; + removeRoom(roomId: string): void; + getRoomSummaries(): RoomSummary[]; + storeUser(user: User): void; + getUser(userId: string): User | null; + getUsers(): User[]; + scrollback(room: Room, limit: number): any[]; + storeEvents(room: Room, events: MatrixEvent[], token: string, toStart?: boolean): boolean; + storeFilter(filter: Filter): void; + getFilter(userId: string, filterId: string): Filter | null; + getFilterIdByName(filterName: string): Filter | null; + setFilterIdByName(filterName: string, filterId: string): void; + storeAccountDataEvents(events: MatrixEvent[]): void; + getAccountData(eventType: string): MatrixEvent | undefined; + setSyncData(syncData: any): Promise; + wantsSave(): boolean; + save(force?: boolean): void; + startup(): Promise; + getSavedSync(): Promise; + getSavedSyncToken(): Promise; + deleteAllData(): Promise; + getOutOfBandMembers(roomId: string): Promise; + setOutOfBandMembers(roomId: string, membershipEvents: MatrixEvent[]): Promise; + clearOutOfBandMembers(): Promise; + getClientOptions(): Promise; + storeClientOptions(options: any): Promise; +} + +export class MemoryStore implements MatrixStore { + localStorage?: any; + constructor(opts?: { localStorage?: any }); + isNewlyCreated(): Promise; + getSyncToken(): string | null; + setSyncToken(token: string): void; + storeGroup(group: Group): void; + getGroup(groupId: string): Group | null; + getGroups(): Group[]; + storeRoom(room: Room): void; + getRoom(roomId: string): Room | null; + getRooms(): Room[]; + removeRoom(roomId: string): void; + getRoomSummaries(): RoomSummary[]; + storeUser(user: User): void; + getUser(userId: string): User | null; + getUsers(): User[]; + scrollback(room: Room, limit: number): any[]; + storeEvents(room: Room, events: MatrixEvent[], token: string, toStart?: boolean): boolean; + storeFilter(filter: Filter): void; + getFilter(userId: string, filterId: string): Filter | null; + getFilterIdByName(filterName: string): Filter | null; + setFilterIdByName(filterName: string, filterId: string): void; + storeAccountDataEvents(events: MatrixEvent[]): void; + getAccountData(eventType: string): MatrixEvent | undefined; + setSyncData(syncData: any): Promise; + wantsSave(): boolean; + save(force?: boolean): void; + startup(): Promise; + getSavedSync(): Promise; + getSavedSyncToken(): Promise; + deleteAllData(): Promise; + getOutOfBandMembers(roomId: string): Promise; + setOutOfBandMembers(roomId: string, membershipEvents: MatrixEvent[]): Promise; + clearOutOfBandMembers(): Promise; + getClientOptions(): Promise; + storeClientOptions(options: any): Promise; +} + +export class IndexedDBStore extends MemoryStore { + constructor(opts: { + indexedDB: any, + dbName?: string, + workerScript?: string, + workerApi?: any, + }); +} + +export interface LoginPayload { + user_id: string; + access_token: string; + home_server: string; + device_id: string; +} + /** * Only part of the MatrixClient methods was put here * because they are too many. * @huan 14 June 2019 */ export class MatrixClient extends EventEmitter { + store: MatrixStore; + deviceId: string; + _http: any; + credentials: any; + acceptGroupInvite(groupId: string, opts: object): Promise; addPushRule(scope: string, kind: string, ruleId: string, body: object, callback?: () => void): Promise; addRoomToGroup(groupId: string, roomId: string, isPublic: boolean): Promise; @@ -166,7 +267,7 @@ export class MatrixClient extends EventEmitter { addThreePid(creds: object, bind: boolean, callback?: (err: null | object, data: any) => void): Promise; addUserToGroupSummary(groupId: string, userId: string, roleId?: string): Promise; backPaginateRoomEventsSearch(searchResults: object): Promise; - ban(roomId: string, userId: string, reason: string, callback: (err: null | object, data: any) => void): Promise; + ban(roomId: string, userId: string, reason: string, callback?: (err: null | object, data: any) => void): Promise; beginKeyVerification(method: string, userId: string, deviceId: string): Promise; cancelAndResendEventRoomKeyRequest(event: MatrixEvent): Promise; cancelPendingEvent(event: MatrixEvent): Promise; @@ -174,16 +275,16 @@ export class MatrixClient extends EventEmitter { checkKeyBackup(): object; claimOneTimeKeys(devices: string[], key_algorithm: string): Promise; clearStores(): Promise; - createAlias(alias: string, roomId: string, callback: MatrixCallback): Promise; + createAlias(alias: string, roomId: string, callback?: MatrixCallback): Promise; createFilter(content: object): Promise; createGroup(content: object): Promise<{ [groupId: string]: string }>; createKeyBackupVersion(info: object): Promise; - createRoom(options: CreateRoomOptions, callback: MatrixCallback): Promise<{ + createRoom(options: CreateRoomOptions, callback?: MatrixCallback): Promise<{ room_id: string, room_alias?: string, }>; deactivateAccount(auth: object, erase: boolean): Promise; - deleteAlias(alias: string, callback: MatrixCallback): Promise; + deleteAlias(alias: string, callback?: MatrixCallback): Promise; deleteDevice(device_id: string, auth: object): Promise; deleteMultipleDevices(devices: string, auth: object): Promise; deletePushRule(scope: string, kind: string, ruleId: string, callback?: MatrixCallback): Promise; @@ -197,7 +298,6 @@ export class MatrixClient extends EventEmitter { }>; downloadKeysForUsers(userIds: string[], opts?: object): Promise; dropFromPresenceList(callback: MatrixCallback, userIds: string[]): Promise; - emit(event: string, listener: (...args: any[]) => any): boolean; enableKeyBackup(info: object): void; exportRoomKeys(): Promise; fetchRoomEvent(roomId: string, eventId: string, callback?: MatrixCallback): Promise; @@ -236,16 +336,19 @@ export class MatrixClient extends EventEmitter { getKeyBackupEnabled(): boolean; getKeyBackupVersion(): Promise; getKeyChanges(oldToken: string, newToken: string): Promise; - getMediaConfig(callback: MatrixCallback): Promise; + getMediaConfig(callback?: MatrixCallback): Promise; getNotifTimelineSet(): EventTimelineSet; getOpenIdToken(): Promise; getOrCreateFilter(filterName: string, filter: Filter): Promise; - getPresenceList(callback: MatrixCallback): Promise; - getProfileInfo(userId: string, info: string, callback?: MatrixCallback): Promise; + getPresenceList(callback?: MatrixCallback): Promise; + getProfileInfo(userId: string, info?: string, callback?: MatrixCallback): Promise<{ + displayname?: string; + avatar_url?: string; + }>; getPublicisedGroups(userIds: string[]): Promise; getPushActionsForEvent(event: MatrixEvent): PushAction; - getPushers(callback: MatrixCallback): Promise; - getPushRules(callback: MatrixCallback): Promise; + getPushers(callback?: MatrixCallback): Promise; + getPushRules(callback?: MatrixCallback): Promise; getRoom(roomId: string): null | Room; getRoomDirectoryVisibility(roomId: string, callback?: MatrixCallback): Promise; getRoomIdForAlias(alias: string, callback?: MatrixCallback): Promise; @@ -265,7 +368,7 @@ export class MatrixClient extends EventEmitter { getThirdpartyLocation(protocol: string, params: object): Promise; getThirdpartyProtocols(): Promise; getThirdpartyUser(protocol: string, params: object): Promise; - getThreePids(callback: MatrixCallback): Promise; + getThreePids(callback?: MatrixCallback): Promise; getTurnServers(): object[]; getUrlPreview(url: string, ts: number, callback?: MatrixCallback): Promise; getUser(userId: string): null | User; @@ -289,20 +392,20 @@ export class MatrixClient extends EventEmitter { isUserIgnored(userId: string): boolean; isUsernameAvailable(username: string): Promise; joinGroup(groupId: string): Promise; - joinRoom(roomIdOrAlias: string, opts: { - syncRoom: boolean // True to do a room initial sync on the resulting room. If false, the returned Room object will have no current state. Default: true. - inviteSignUrl: boolean // If the caller has a keypair 3pid invite, the signing URL is passed in this parameter. - viaServers: string[] // The server names to try and join through in addition to those that are automatically chosen. - }, callback: MatrixCallback): Promise; + joinRoom(roomIdOrAlias: string, opts?: { + syncRoom?: boolean // True to do a room initial sync on the resulting room. If false, the returned Room object will have no current state. Default: true. + inviteSignUrl?: boolean // If the caller has a keypair 3pid invite, the signing URL is passed in this parameter. + viaServers?: string[] // The server names to try and join through in addition to those that are automatically chosen. + }, callback?: MatrixCallback): Promise; kick(roomId: string, userId: string, reason?: string, callback?: MatrixCallback): Promise; leave(roomId: string, callback?: MatrixCallback): Promise; leaveGroup(groupId: string): Promise; leaveRoomChain(roomId: string, includeFuture: boolean): Promise; - login(loginType: string, data: object, callback?: MatrixCallback): Promise; - loginFlows(callback?: MatrixCallback): Promise; - loginWithPassword(user: string, password: string, callback?: MatrixCallback): Promise; - loginWithSAML2(relayState: string, callback?: MatrixCallback): Promise; - loginWithToken(token: string, callback?: MatrixCallback): Promise; + login(loginType: string, data: object, callback?: MatrixCallback): Promise; + loginFlows(callback?: MatrixCallback): Promise; + loginWithPassword(user: string, password: string, callback?: MatrixCallback): Promise; + loginWithSAML2(relayState: string, callback?: MatrixCallback): Promise; + loginWithToken(token: string, callback?: MatrixCallback): Promise; logout(callback?: MatrixCallback): Promise; lookupThreePid(medium: string, address: string, callback?: MatrixCallback): Promise; makeTxnId(): string; @@ -320,13 +423,13 @@ export class MatrixClient extends EventEmitter { filter: { // Filter parameters generic_search_term: string // String to search for }, - }, callback: (...args: any[]) => any): Promise; + }, callback?: (...args: any[]) => any): Promise; redactEvent(roomId: string, eventId: string, txnIdopt: string, callback?: MatrixCallback): Promise; register( - username: string, password: string, sessionId: string, - auth: object, bindThreepids: object, guestAccessToken: string, - inhibitLogin: string, callback?: MatrixCallback, - ): Promise; + username: string, password: string, sessionId?: string, + auth?: object, bindThreepids?: object, guestAccessToken?: string, + inhibitLogin?: string, callback?: MatrixCallback, + ): Promise; registerGuest(opts?: object, callback?: MatrixCallback): Promise; registerRequest(data: object, kind?: string, callback?: MatrixCallback): Promise; removeRoomFromGroup(groupId: string, roomId: string): Promise; @@ -383,8 +486,11 @@ export class MatrixClient extends EventEmitter { }): Promise; searchUserDirectory(opts: { term: string // the term with which to search. - limit: number // the maximum number of results to return. The server will apply a limit if unspecified. - }): Promise; + limit?: number // the maximum number of results to return. The server will apply a limit if unspecified. + }): Promise<{ + limited?: boolean; + results: Array<{ user_id: string; display_name?: string | null; avatar_url?: string | null }>; + }>; sendEmoteMessage( roomId: string, body: string, txnId: string, callback?: MatrixCallback, ): Promise; @@ -458,7 +564,7 @@ export class MatrixClient extends EventEmitter { setPresence(opts: { presence: string // One of "online", "offline" or "unavailable" status_msg: string // The status message to attach. - }, callback: (...args: any[]) => any): Promise; + }, callback?: (...args: any[]) => any): Promise; setProfileInfo(info: string, data: object, callback?: MatrixCallback): Promise; setPusher(pusher: object, callback?: MatrixCallback): Promise; setPushRuleActions( @@ -493,7 +599,7 @@ export class MatrixClient extends EventEmitter { filter?: Filter // The filter to apply to /sync calls. This will override the opts.initialSyncLimit, which would normally result in a timeline limit filter. disablePresence?: boolean // True to perform syncing without automatically updating presence. lazyLoadMembers?: boolean // True to not load all membership events during initial sync but fetch them when needed by calling `loadOutOfBandMembers` This will override the filter - }): void; + }): Promise; stopClient(): void; stopPeeking(): void; submitMsisdnToken(sid: string, clientSecret: string, token: string): Promise; @@ -503,12 +609,12 @@ export class MatrixClient extends EventEmitter { unban(roomId: string, userId: string, callback?: MatrixCallback): Promise; updateGroupRoomVisibility(groupId: string, roomId: string, isPublic: boolean): Promise; upgradeRoom(roomId: string, newVersion: string): Promise<{ replacement_room: object }>; - uploadContent(file: Buffer, opts: { + uploadContent(file: any, opts: { includeFilename: boolean // if false will not send the filename, e.g for encrypted file uploads where filename leaks are undesirable. Defaults to true. type: string // Content-type for the upload. Defaults to file.type, or applicaton/octet-stream. rawResponse: boolean // Return the raw body, rather than parsing the JSON. Defaults to false (except on node.js, where it defaults to true for backwards compatibility). onlyContentUri: boolean // Just return the content URI, rather than the whole body. Defaults to false (except on browsers, where it defaults to true for backwards compatibility). - callback: (...args: any[]) => any // Deprecated. Optional. The callback to invoke on success/failure. See the promise return values for more information. + callback?: (...args: any[]) => any // Deprecated. Optional. The callback to invoke on success/failure. See the promise return values for more information. progressHandler: (...args: any[]) => any // Optional. Called when a chunk of data has been uploaded, with an object containing the fields `loaded` (number of bytes transferred) }): Promise; uploadKeys(): object; @@ -529,11 +635,11 @@ export type RoomSummary = any; export type EventStatus = any; export interface CreateRoomOptions { - invite: string[]; // A list of user IDs to invite to this room. - name: string; // The name to give this room. - room_alias_name: string; // The alias localpart to assign to this room. - topic: string; // The topic to give this room. - visibility: string; // Either 'public' or 'private'. + invite?: string[]; // A list of user IDs to invite to this room. + name?: string; // The name to give this room. + room_alias_name?: string; // The alias localpart to assign to this room. + topic?: string; // The topic to give this room. + visibility?: 'public' | 'private'; // Either 'public' or 'private'. } export type FilterComponent = any; @@ -556,7 +662,7 @@ export class Filter { } export class MatrixEvent { - event: object; // The raw (possibly encrypted) event. Do not access this property directly unless you absolutely have to. Prefer the getter methods defined + event: any; // The raw (possibly encrypted) event. Do not access this property directly unless you absolutely have to. Prefer the getter methods defined sender: RoomMember; // The room member who sent this event, or null e.g. this is a presence event. This is only guaranteed to be set for events that appear in target: RoomMember; // The room member who is the target of this event, e.g. the invitee, the person being banned, etc. status: EventStatus; // The sending status of the event. @@ -564,6 +670,8 @@ export class MatrixEvent { forwardLooking: boolean; // True if this event is 'forward looking', meaning that getDirectionalContent() will return event.content and not event.prev_content. constructor(event: object) + getType(): EventType; + getSender(): string; } export class RoomMember { @@ -594,6 +702,8 @@ export class RoomMember { } export class RoomState { + roomId: string; + members: { [userId: string]: RoomMember }; constructor(roomId?: string, oobMemberFlags?: object) clearOutOfBandMembers(): void; @@ -619,20 +729,33 @@ export class RoomState { needsOutOfBandMembers(): boolean; setInvitedMemberCount(count: number): void; setJoinedMemberCount(count: number): void; - setOutOfBandMembers(stateEvents: MatrixEvent): void; - setStateEvents(stateEvents: MatrixEvent): void; + setOutOfBandMembers(stateEvents: MatrixEvent[]): void; + setStateEvents(stateEvents: MatrixEvent[]): void; setTypingEvent(event: MatrixEvent): void; setUnknownStateEvents(events: MatrixEvent): void; } export interface CreateClientOption { - accessToken?: string; baseUrl?: string; + idBaseUrl?: string; request?: any; - store?: any; + accessToken?: string; + userId?: string; + deviceToImport?: any; + identityServer?: { getAccessToken: () => Promise }; + store?: MatrixStore; scheduler?: MatrixScheduler; cryptoStore?: any; - userId?: string; + deviceId?: string; + queryParams?: any; + localTimeoutMs?: number; + useAuthorizationHeader?: boolean; + timelineSupport?: boolean; + unstableClientRelationAggregation?: boolean; + verificationMethods?: string[]; + forceTURN?: boolean; + fallbackICEServerAllowed?: boolean; + cryptoCallbacks?: { [cb: string]: (...any: any[]) => void }; } export function createClient(ops: string | CreateClientOption): MatrixClient;