Skip to content

Commit

Permalink
types: improve types for registration calls (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed May 20, 2022
1 parent e81d845 commit a9516d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,19 @@ interface IJoinedMembersResponse {
};
}

export interface IRegisterRequestParams {
auth?: IAuthData;
username?: string;
password?: string;
refresh_token?: boolean;
guest_access_token?: string;
x_show_msisdn?: boolean;
bind_msisdn?: boolean;
bind_email?: boolean;
inhibit_login?: boolean;
initial_device_display_name?: string;
}

export interface IPublicRoomsChunkRoom {
room_id: string;
name?: string;
Expand Down Expand Up @@ -6846,7 +6859,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
guestAccessToken?: string,
inhibitLogin?: boolean,
callback?: Callback,
): Promise<any> { // TODO: Types (many)
): Promise<IAuthData> {
// backwards compat
if (bindThreepids === true) {
bindThreepids = { email: true };
Expand All @@ -6862,7 +6875,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
auth.session = sessionId;
}

const params: any = {
const params: IRegisterRequestParams = {
auth: auth,
refresh_token: true, // always ask for a refresh token - does nothing if unsupported
};
Expand Down Expand Up @@ -6933,8 +6946,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @return {Promise} Resolves: to the /register response
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public registerRequest(data: any, kind?: string, callback?: Callback): Promise<any> { // TODO: Types
const params: any = {};
public registerRequest(data: IRegisterRequestParams, kind?: string, callback?: Callback): Promise<IAuthData> {
const params: { kind?: string } = {};
if (kind) {
params.kind = kind;
}
Expand Down
7 changes: 7 additions & 0 deletions src/interactive-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ export interface IAuthData {
session?: string;
completed?: string[];
flows?: IFlow[];
available_flows?: IFlow[];
stages?: string[];
required_stages?: AuthType[];
params?: Record<string, Record<string, any>>;
data?: Record<string, string>;
errcode?: string;
error?: string;
user_id?: string;
device_id?: string;
access_token?: string;
}

export enum AuthType {
Expand Down

0 comments on commit a9516d0

Please sign in to comment.