Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve types for registration calls #2390

Merged
merged 2 commits into from
May 20, 2022
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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