UNPKG

@kintone/dts-gen

Version:

Types for kintone js api and Types generating tools

61 lines 1.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VisibleForTesting = exports.AxiosUtils = void 0; const axios_1 = __importDefault(require("axios")); const newAxiosInstance = (input) => { let proxy; // parse the proxy URL like http://admin:pass@localhost:8000 if (input.proxy) { const proxyUrl = new URL(input.proxy); proxy = { host: proxyUrl.hostname, port: parseInt(proxyUrl.port, 10), auth: { username: proxyUrl.username, password: proxyUrl.password, }, }; } let headers; if (input.username && input.password) { headers = { "X-Cybozu-Authorization": Buffer.from(`${input.username}:${input.password}`).toString("base64"), }; } else if (input.apiToken) { headers = { "X-Cybozu-API-Token": input.apiToken, }; } else if (input.oAuthToken) { headers = { Authorization: `Bearer ${input.oAuthToken}`, }; } else { throw new Error("cannot get an authentication input"); } if (input.basicAuthPassword && input.basicAuthPassword) { headers.Authorization = "Basic " + Buffer.from(`${input.basicAuthUsername}:${input.basicAuthPassword}`).toString("base64"); } return exports.VisibleForTesting.newAxiosInstanceInternal({ baseURL: input.baseUrl, headers, proxy, }); }; const newAxiosInstanceInternal = (config) => { return axios_1.default.create(config); }; exports.AxiosUtils = { newAxiosInstance, }; exports.VisibleForTesting = { newAxiosInstanceInternal, }; //# sourceMappingURL=axios-utils.js.map