From f839c08bbb0f5c889ab3dd7e6e728e756e310bc7 Mon Sep 17 00:00:00 2001 From: Leonard Broman Date: Sun, 20 Jun 2021 16:43:10 +0200 Subject: [PATCH] #100 Added configuration property for setting axios instance --- index.d.ts | 3 +++ index.mjs | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index f107eb7..e1621e3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,5 @@ import * as OAuth from 'oauth-1.0a' +import {AxiosInstance} from "axios"; export declare type WooCommerceRestApiVersion = | 'wc/v3' @@ -36,6 +37,8 @@ export interface IWooCommerceRestApiOptions { timeout?: number /* Define the custom Axios config, also override this library options */ axiosConfig?: any + /* Define own axios instance which will be used, instead of use the default global static instance */ + axiosInstance?: AxiosInstance } export interface IWooCommerceRestApiQuery { diff --git a/index.mjs b/index.mjs index e42f229..3b4a63a 100644 --- a/index.mjs +++ b/index.mjs @@ -56,6 +56,7 @@ export default class WooCommerceRestApi { this.port = opt.port || ""; this.timeout = opt.timeout; this.axiosConfig = opt.axiosConfig || {}; + this.axiosInstance = opt.axiosInstance || axios; } /** @@ -238,7 +239,7 @@ export default class WooCommerceRestApi { // Allow set and override Axios options. options = { ...options, ...this.axiosConfig }; - return axios(options); + return this.axiosInstance.request(options); } /**