UNPKG

mysterium-vpn-js

Version:
48 lines (47 loc) 1.7 kB
"use strict"; /** * Copyright (c) 2020 BlockDev AG * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AxiosAdapter = void 0; const timeouts_1 = require("./timeouts"); class AxiosAdapter { constructor(axiosInstance, defaultTimeout = timeouts_1.TIMEOUT_DEFAULT) { this._axios = axiosInstance; this._timeout = defaultTimeout; } setHeaders(headers) { this._axios.defaults.headers.common = headers; } setAuthHeader(token) { this._axios.defaults.headers.common['Authorization'] = 'Bearer ' + token; } get(path, query, timeout) { const options = this._decorateOptions(timeout); options.params = query; return this._axios.get(path, options).then((res) => res.data); } getFile(path, query, timeout) { const options = this._decorateOptions(timeout); options.responseType = 'arraybuffer'; return this._axios.get(path, options).then((res) => res.data); } post(path, data, timeout) { return this._axios.post(path, data, this._decorateOptions(timeout)).then((res) => res.data); } delete(path, timeout) { return this._axios.delete(path, this._decorateOptions(timeout)).then((res) => res.data); } put(path, data, timeout) { return this._axios.put(path, data, this._decorateOptions(timeout)).then((res) => res.data); } _decorateOptions(timeout) { return { timeout: timeout !== undefined ? timeout : this._timeout, }; } } exports.AxiosAdapter = AxiosAdapter;