UNPKG

@airwallex/node-sdk

Version:

Airwallex Node.js SDK

72 lines 3.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpClientImpl = void 0; const tslib_1 = require("tslib"); const axios_1 = tslib_1.__importDefault(require("axios")); const package_json_1 = tslib_1.__importDefault(require("../../package.json")); class HttpClientImpl { constructor(basePath, config) { this.defaultHeaders = { 'Content-Type': 'application/json', 'user-agent': `airwallex-node-sdk/${package_json_1.default.version} (Node.js ${process.version})`, }; this.client = axios_1.default.create({ baseURL: basePath, timeout: config.timeout, headers: this.defaultHeaders, }); } async get(url, options) { const response = await this.client.get(url, { headers: { ...this.defaultHeaders, ...options === null || options === void 0 ? void 0 : options.headers }, timeout: (options === null || options === void 0 ? void 0 : options.timeout) || this.client.defaults.timeout, responseType: (options === null || options === void 0 ? void 0 : options.responseType) || 'json', params: options === null || options === void 0 ? void 0 : options.params, }); return response.data; } async post(url, data, options) { const response = await this.client.post(url, data, { headers: { ...this.defaultHeaders, ...options === null || options === void 0 ? void 0 : options.headers }, timeout: (options === null || options === void 0 ? void 0 : options.timeout) || this.client.defaults.timeout, responseType: (options === null || options === void 0 ? void 0 : options.responseType) || 'json', params: options === null || options === void 0 ? void 0 : options.params, }); return response.data; } async put(url, data, options) { const response = await this.client.put(url, data, { headers: { ...this.defaultHeaders, ...options === null || options === void 0 ? void 0 : options.headers }, timeout: (options === null || options === void 0 ? void 0 : options.timeout) || this.client.defaults.timeout, responseType: (options === null || options === void 0 ? void 0 : options.responseType) || 'json', params: options === null || options === void 0 ? void 0 : options.params, }); return response.data; } async delete(url, options) { const response = await this.client.delete(url, { headers: { ...this.defaultHeaders, ...options === null || options === void 0 ? void 0 : options.headers }, timeout: (options === null || options === void 0 ? void 0 : options.timeout) || this.client.defaults.timeout, responseType: (options === null || options === void 0 ? void 0 : options.responseType) || 'json', params: options === null || options === void 0 ? void 0 : options.params, }); return response.data; } async patch(url, data, options) { const response = await this.client.patch(url, data, { headers: { ...this.defaultHeaders, ...options === null || options === void 0 ? void 0 : options.headers }, timeout: (options === null || options === void 0 ? void 0 : options.timeout) || this.client.defaults.timeout, responseType: (options === null || options === void 0 ? void 0 : options.responseType) || 'json', params: options === null || options === void 0 ? void 0 : options.params, }); return response.data; } setRequestInterceptor(callback, errorCallback) { this.client.interceptors.request.use(callback, errorCallback); } setResponseInterceptor(callback, errorCallback) { this.client.interceptors.response.use(callback, errorCallback); } } exports.HttpClientImpl = HttpClientImpl; //# sourceMappingURL=httpClient.js.map