diff --git a/src/account.ts b/src/account.ts index 1b6e2f3..48e7a8b 100644 --- a/src/account.ts +++ b/src/account.ts @@ -28,8 +28,9 @@ import { postApiAccountPasswordResetConfirm, postApiAuthLogout, getApiUploadLimit, + postApiAccountUpdateEmail, } from "./account/generated/index.js"; -import { AxiosResponse } from "axios"; +import { AxiosError, AxiosResponse } from "axios"; export class AccountApi { private apiUrl: string; @@ -111,7 +112,10 @@ export class AccountApi { public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise { let ret: AxiosResponse; try { - ret = await postApiAccountOtpVerify(otpVerifyRequest, this.buildOptions()); + ret = await postApiAccountOtpVerify( + otpVerifyRequest, + this.buildOptions(), + ); } catch (e) { return false; } @@ -226,6 +230,23 @@ export class AccountApi { return this.checkSuccessVal(ret) ? ret.data.limit : 0; } + public async updateEmail( + email: string, + password: string, + ): Promise { + let ret: AxiosResponse; + try { + ret = await postApiAccountUpdateEmail( + { email, password }, + this.buildOptions(), + ); + } catch (e) { + return new Error((e as AxiosError).response.data as string); + } + + return this.checkSuccessBool(ret); + } + private checkSuccessBool(ret: AxiosResponse): boolean { return ret.status === 200; }