@botpress/messaging-client
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,2 +0,2 @@ | ||
import { AxiosInstance } from 'axios'; | ||
import { AxiosInstance, AxiosRequestConfig } from 'axios'; | ||
import { ConversationClient } from './conversations'; | ||
@@ -18,3 +18,2 @@ import { HealthClient } from './health'; | ||
authenticate(clientId: string, clientToken: string): void; | ||
private configureHttpClient; | ||
private getAxiosConfig; | ||
@@ -27,4 +26,4 @@ } | ||
auth?: MessagingAuth; | ||
/** A custom axios instance giving more control over the HTTP client used internally. Optional */ | ||
client?: AxiosInstance; | ||
/** A custom axios config giving more control over the HTTP client used internally. Optional */ | ||
config?: Omit<AxiosRequestConfig, 'baseURL'>; | ||
} | ||
@@ -31,0 +30,0 @@ export interface MessagingAuth { |
@@ -15,5 +15,6 @@ "use strict"; | ||
constructor(options) { | ||
const { url, auth, client } = options; | ||
this.http = this.configureHttpClient(client, this.getAxiosConfig({ url })); | ||
this.authHttp = this.configureHttpClient(client, this.getAxiosConfig({ url, auth })); | ||
const { auth } = options; | ||
const config = this.getAxiosConfig(options); | ||
this.http = axios_1.default.create(config); | ||
this.authHttp = axios_1.default.create(config); | ||
if (auth) { | ||
@@ -33,17 +34,7 @@ this.authenticate(auth.clientId, auth.clientToken); | ||
} | ||
configureHttpClient(client, config) { | ||
if (client) { | ||
client.interceptors.request.use((value) => { | ||
return Object.assign(Object.assign({}, value), config); | ||
}); | ||
return client; | ||
} | ||
else { | ||
return axios_1.default.create(config); | ||
} | ||
getAxiosConfig({ url, config }) { | ||
const defaultConfig = { baseURL: `${url}/api` }; | ||
return Object.assign(Object.assign({}, config), defaultConfig); | ||
} | ||
getAxiosConfig({ url }) { | ||
return { baseURL: `${url}/api` }; | ||
} | ||
} | ||
exports.MessagingClient = MessagingClient; |
{ | ||
"name": "@botpress/messaging-client", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
51849
395