UNPKG

@novo-learning/novo-sdk

Version:

SDK for the Novolanguage Speech Analysis API

63 lines (56 loc) 2.2 kB
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; import { UserDataMapper } from '../../mappers/user-data.mapper'; import { AuthenticationResponseDtoV1 } from './dto/authentication-response.dto'; import { AuthenticateSsoRequestDtoV1, SsoRequestDtoV1 } from './dto/sso-request.dto'; import { AuthApi as GeneratedAuthApi, AuthenticationResponseDtoV1 as GeneratedAuthenticationResponseDtoV1, Configuration, RefreshRequestDtoV1, } from './generated'; export class AuthApi { private readonly authApi: GeneratedAuthApi; private readonly userDataMapper: UserDataMapper; constructor(configuration?: Configuration | undefined, basePath?: string, axios?: AxiosInstance) { this.authApi = new GeneratedAuthApi(configuration, basePath, axios); this.userDataMapper = new UserDataMapper(); } private mapGeneratedAuthenticationReponse( dto: AxiosResponse<GeneratedAuthenticationResponseDtoV1>, ): AxiosResponse<AuthenticationResponseDtoV1> { return { ...dto, data: { ...dto.data, data: { ...dto.data.data, user: this.userDataMapper.mapFromGenerated(dto.data.data.user), }, }, }; } public refresh( refreshRequestDtoV1: RefreshRequestDtoV1, options?: AxiosRequestConfig<unknown> | undefined, ): Promise<AxiosResponse<AuthenticationResponseDtoV1>> { return this.authApi .refresh(refreshRequestDtoV1, options) .then((response) => this.mapGeneratedAuthenticationReponse(response)); } public sso( authenticateSsoRequestDtoV1: AuthenticateSsoRequestDtoV1, options?: AxiosRequestConfig<unknown> | undefined, ): Promise<AxiosResponse<AuthenticationResponseDtoV1>> { return this.authApi .sso(authenticateSsoRequestDtoV1, options) .then((response) => this.mapGeneratedAuthenticationReponse(response)); } public ssoAnonymous( ssoRequestDtoV1: SsoRequestDtoV1, options?: AxiosRequestConfig<unknown> | undefined, ): Promise<AxiosResponse<AuthenticationResponseDtoV1>> { return this.authApi .ssoAnonymous(ssoRequestDtoV1, options) .then((response) => this.mapGeneratedAuthenticationReponse(response)); } }