UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

33 lines (31 loc) 1.1 kB
import debug_default from "../debug.js"; import { getFileUrl } from "../../config.js"; import { createAxiosConfig } from "./createAxiosConfig.js"; import axios from "axios"; import { extract } from "tar"; //#region src/utils/xsd/downloadFile.ts const debug = debug_default("wsdl-downloader"); async function downloadFile(filePath, { flavour, security, XSD_PATH: outputDir, xsdEndpoint }) { const options = createAxiosConfig({ security }); const url = xsdEndpoint || getFileUrl(filePath, { flavour }); debug(`Downloading ${url}`); try { const res = await axios.get(url, { timeout: 15 * 1e3, responseType: "stream", ...options }); return new Promise((resolve, reject) => { res.data.pipe(extract({ cwd: outputDir })).on("error", reject).on("close", () => { debug("Downloaded and extracted WSDL files"); resolve(); }); }); } catch (err) { const message = err instanceof Error ? err.message : "Unknown error"; throw new Error(`Unable to download WSDL: ${message}`, { cause: err }); } } //#endregion export { downloadFile }; //# sourceMappingURL=downloadFile.js.map