@dgac/nmb2b-client
Version:
EUROCONTROL Network Manager B2B SOAP client
38 lines (36 loc) • 1.48 kB
JavaScript
import { assert } from "../assert.mjs";
import { createDebugLogger } from "../debug.mjs";
import { createAxiosConfig } from "./createAxiosConfig.mjs";
import axios, { AxiosHeaders } from "axios";
import { extract } from "tar";
//#region src/utils/xsd/downloadAndExtractWSDL.ts
const debug = createDebugLogger("wsdl-downloader");
async function downloadAndExtractWSDL(url, { security, outputDir }) {
const options = createAxiosConfig({ security });
debug(`Downloading ${url}`);
try {
const res = await axios.get(url, {
timeout: 15 * 1e3,
responseType: "stream",
...options
});
assert(res.headers instanceof AxiosHeaders, "Axios response.headers is not an instance of AxiosHeaders class.");
const contentType = res.headers.get("content-type");
if (contentType && typeof contentType === "string" && !contentType.includes("gzip") && !contentType.includes("octet-stream") && !contentType.includes("x-tar")) throw new Error(`Invalid Content-Type: ${contentType}`);
await new Promise((resolve, reject) => {
res.data.pipe(extract({
cwd: outputDir,
strip: 1
})).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 { downloadAndExtractWSDL };
//# sourceMappingURL=downloadAndExtractWSDL.mjs.map