import { isEmpty , pickBy } from 'lodash' ; import { RequestResult } from './types' ; export abstract class NuclearService { protected _token : string ; constructor ( protected baseUrl ) { } public set token ( token ) { this . _token = token ; } getHeaders ( ) { return { 'Content-type' : 'application/json' } ; } prepareBody < TRequestBody extends object > ( body ) { return pickBy ( body , value => ! isEmpty ( value ) ) ; } async getJson < TResponseBody , TErrorBody > ( request ) { const result = await request ; const body = await result . json ( ) ; if ( result . ok ) { return { body : body as TResponseBody , status : result . status , ok : result . ok } ; } else { return { body : body as TErrorBody , status : result . status , ok : result . ok } ; } } }