import axios , { AxiosInstance , AxiosRequestConfig , AxiosResponse , AxiosProxyConfig } from 'axios' ; import { URL } from 'url' ; import { linkedinApiUrl } from '../../config' ; import { paramsSerializer } from '../utils/paramsSerializer' ; const buildUrl = ( url ) => new URL ( url , linkedinApiUrl ) . toString ( ) ; type ConfigFullResponse = AxiosRequestConfig & { fullResponse ? : true ; } ; type ConfigNonFullResponse = AxiosRequestConfig & { fullResponse ? : false ; } ; interface RequestOpts { proxy ? : AxiosProxyConfig ; } export class Request { request : AxiosInstance ; constructor ( { proxy } = { } ) { this . request = axios . create ( { paramsSerializer , withCredentials : true , ... ( proxy && { proxy } ) , } ) ; } setHeaders ( headers ) { this . request . defaults . headers = headers ; } async get < T > ( url , reqConfig ? ) ; async get < T > ( url , reqConfig ? ) ; async get < T > ( url , reqConfig ? ) { const response = await this . request . get < T > ( buildUrl ( url ) , reqConfig ) ; return reqConfig ?. fullResponse ? response : response . data ; } async post < T > ( url , data , reqConfig ? ) ; async post < T > ( url , data , reqConfig ? ) ; async post < T > ( url , data , reqConfig ? ) { const response = await this . request . post < T > ( buildUrl ( url ) , data , reqConfig ) ; return reqConfig ?. fullResponse ? response : response . data ; } }