import type { AxiosRequestConfig , AxiosResponse } from 'axios' ; import type { HttpClient , TraceState } from '../http/' ; import type { ChangePassword , Consent , ConsentResults , Delete , Name , Self } from './' ; import type { UserUpdate } from '../user/' ; export class SelfAPI { constructor ( private readonly client ) { } public static readonly URL = { CONSENT : 'consent' , EMAIL : 'email' , HANDLE : 'handle' , LOCALE : 'locale' , NAME : 'name' , PASSWORD : 'password' , PHONE : 'phone' , SELF : '/self' , } ; see https public async deleteEmail ( ) { const config = { method : 'delete' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . EMAIL }` , } ; await this . client . sendJSON ( config ) ; } see https public async deletePhone ( ) { const config = { method : 'delete' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . PHONE }` , } ; await this . client . sendJSON ( config ) ; } see https public async deleteSelf ( deleteData ) { const config = { data : deleteData , method : 'delete' , url : SelfAPI . URL . SELF , } ; await this . client . sendJSON ( config ) ; } see https public async getName ( ) { const config = { method : 'get' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . NAME }` , } ; const response = await this . client . sendJSON < Name > ( config ) ; return response . data ; } see https public async getConsents ( ) { const config = { method : 'get' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . CONSENT }` , } ; const response = await this . client . sendJSON < { results : Consent [ ] ; } > ( config ) ; return response . data ; } see https public async putConsent ( consent ) { const config = { data : consent , method : 'put' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . CONSENT }` , } ; await this . client . sendJSON ( config ) ; } see https public async getSelf ( traceStates = [ ] ) { traceStates . push ( { position : 'SelfAPI.getSelf' , vendor : 'api-client' } ) ; const config = { headers : { tracestate : traceStates . map ( state => `${ state . vendor }=${ state . position }` ) . join ( ',' ) , } , method : 'get' , url : SelfAPI . URL . SELF , } ; const response = await this . client . sendJSON < Self > ( config ) ; return response . data ; } param handleData see https public async putHandle ( handleData ) { const config = { data : handleData , method : 'put' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . HANDLE }` , } ; await this . client . sendJSON ( config ) ; } param localeData see https public async putLocale ( localeData ) { const config = { data : localeData , method : 'put' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . LOCALE }` , } ; await this . client . sendJSON ( config ) ; } param passwordData see https public async putPassword ( passwordData ) { const config = { data : passwordData , method : 'put' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . PASSWORD }` , } ; await this . client . sendJSON ( config ) ; } param phoneData see https public async putPhone ( phoneData ) { const config = { data : phoneData , method : 'put' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . PHONE }` , } ; await this . client . sendJSON ( config ) ; } param profileData see https public async putSelf ( profileData ) { const config = { data : profileData , method : 'put' , url : SelfAPI . URL . SELF , } ; await this . client . sendJSON ( config ) ; } /**
     * Check if password is set.
     */ public headPassword ( ) { const config = { method : 'head' , url : `${ SelfAPI . URL . SELF }/${ SelfAPI . URL . PASSWORD }` , } ; return this . client . sendJSON ( config ) ; } }