import type { AxiosRequestConfig } from 'axios' ; import { CustomBackendNotFoundError } from './AccountError' ; import { HttpClient , BackendErrorLabel , BackendError } from '../http' ; import type { BackendConfigData } from './BackendConfigData' ; import type { CallConfigData } from './CallConfigData' ; import type { DomainData } from './DomainData' ; import type { SSOSettings } from './SSOSettings' ; export class AccountAPI { constructor ( private readonly client ) { } public static readonly URL = { ACTIVATE : '/activate' , BACKEND_CONFIG : '/config.json' , BY_DOMAIN : 'by-domain' , CALLS : '/calls' , CALLS_CONFIG : 'config' , CALLS_CONFIG_V2 : 'v2' , CUSTOM_BACKEND : '/custom-backend' , DELETE : '/delete' , PASSWORD_RESET : '/password-reset' , PASSWORD_RESET_COMPLETE : 'complete' , PROVIDER : '/provider' , SETTINGS : 'settings' , SSO : '/sso' , } ; see https public async postDeleteAccount ( key , code ) { const config = { data : { code , key , } , method : 'post' , url : AccountAPI . URL . DELETE , } ; await this . client . sendJSON ( config ) ; } see https public async postPasswordReset ( email ) { const config = { data : { email , } , method : 'post' , url : AccountAPI . URL . PASSWORD_RESET , } ; await this . client . sendJSON ( config ) ; } see https public async postBotPasswordReset ( email ) { const config = { data : { email , } , method : 'post' , url : `${ AccountAPI . URL . PROVIDER }${ AccountAPI . URL . PASSWORD_RESET }` , } ; await this . client . sendJSON ( config ) ; } see https public async postPasswordResetComplete ( password , key , code ) { const config = { data : { code , key , password , } , method : 'post' , url : `${ AccountAPI . URL . PASSWORD_RESET }/${ AccountAPI . URL . PASSWORD_RESET_COMPLETE }` , } ; await this . client . sendJSON ( config ) ; } see https public async postBotPasswordResetComplete ( password , key , code ) { const config = { data : { code , key , password , } , method : 'post' , url : `${ AccountAPI . URL . PROVIDER }${ AccountAPI . URL . PASSWORD_RESET }/${ AccountAPI . URL . PASSWORD_RESET_COMPLETE }` , } ; await this . client . sendJSON ( config ) ; } see https public async getVerifyEmail ( key , code ) { const config = { method : 'get' , params : { code , key , } , url : AccountAPI . URL . ACTIVATE , } ; await this . client . sendJSON ( config ) ; } see https public async getVerifyBot ( key , code ) { const config = { method : 'get' , params : { code , key , } , url : `${ AccountAPI . URL . PROVIDER }${ AccountAPI . URL . ACTIVATE }` , } ; await this . client . sendJSON ( config ) ; } public async getDomain ( domain ) { const config = { method : 'get' , url : `${ AccountAPI . URL . CUSTOM_BACKEND }/${ AccountAPI . URL . BY_DOMAIN }/${ domain }` , } ; try { const response = await this . client . sendJSON < DomainData > ( config ) ; return response . data ; } catch ( error ) { const backendError = error as BackendError ; switch ( backendError . label ) { case BackendErrorLabel . CUSTOM_BACKEND_NOT_FOUND : { throw new CustomBackendNotFoundError ( backendError . message ) ; } } throw error ; } } public async getSSOSettings ( ) { const config = { method : 'get' , url : `${ AccountAPI . URL . SSO }/${ AccountAPI . URL . SETTINGS }` , } ; const response = await this . client . sendJSON < SSOSettings > ( config ) ; return response . data ; } param limit public async getCallConfig ( limit ? ) { const config = { method : 'get' , params : { limit , } , url : `${ AccountAPI . URL . CALLS }/${ AccountAPI . URL . CALLS_CONFIG }/${ AccountAPI . URL . CALLS_CONFIG_V2 }` , } ; const response = await this . client . sendJSON < CallConfigData > ( config ) ; return response . data ; } public async getConfig ( ) { const config = { method : 'get' , url : `${ AccountAPI . URL . BACKEND_CONFIG }` , } ; const response = await this . client . sendJSON < BackendConfigData > ( config ) ; return response . data ; } }