import axios, { AxiosInstance } from 'axios' import { WyreAPIOptions } from './WyreAPIOptions' // tslint:disable: no-console export class WyreAxiosInstance { private axiosInstance: AxiosInstance private constructor( private options: WyreAPIOptions, private secretKey?: string, ) { } public static newInstance( options: WyreAPIOptions, secretKey?: string, ) { const instance = new WyreAxiosInstance(options, secretKey) instance.initialize() return instance } public getAxiosInstance(): AxiosInstance { return this.axiosInstance } private initialize() { const headers = {} if (this.secretKey) { // tslint:disable-next-line: no-string-literal headers['Authorization'] = `Bearer ${this.secretKey}` // console.log('headers:', headers) } this.axiosInstance = axios.create({ baseURL: `${this.options.baseUrl}`, // timeout: 1000, headers, }) } public setSecretKey(secretKey: string) { this.secretKey = secretKey this.initialize() } }