{"version":3,"file":"downloadAndExtractWSDL.mjs","names":[],"sources":["../../../src/utils/xsd/downloadAndExtractWSDL.ts"],"sourcesContent":["import axios, { AxiosHeaders } from 'axios';\nimport { extract } from 'tar';\nimport type { Security } from '../../security.js';\nimport { createDebugLogger } from '../debug.js';\nimport { createAxiosConfig } from './createAxiosConfig.js';\nimport type { Readable } from 'stream';\nimport { assert } from '../assert.js';\nconst debug = createDebugLogger('wsdl-downloader');\n\nexport async function downloadAndExtractWSDL(\n  url: string,\n  {\n    security,\n    outputDir,\n  }: {\n    security?: Security;\n    outputDir: string;\n  },\n): Promise<void> {\n  const options = createAxiosConfig({ security });\n\n  debug(`Downloading ${url}`);\n  try {\n    const res = await axios.get<Readable>(url, {\n      timeout: 15 * 1000,\n      responseType: 'stream',\n      ...options,\n    });\n\n    assert(\n      res.headers instanceof AxiosHeaders,\n      'Axios response.headers is not an instance of AxiosHeaders class.',\n    );\n\n    const contentType = res.headers.get('content-type');\n\n    if (\n      contentType &&\n      typeof contentType === 'string' &&\n      /**\n       * Check for valid binary formats to avoid parsing HTML/Text errors as TAR.\n       * - gzip: Standard for .tar.gz\n       * - octet-stream: Generic binary (common in proxies)\n       * - x-tar: Uncompressed tar fallback\n       */\n      !contentType.includes('gzip') &&\n      !contentType.includes('octet-stream') &&\n      !contentType.includes('x-tar')\n    ) {\n      throw new Error(`Invalid Content-Type: ${contentType}`);\n    }\n\n    await new Promise<void>((resolve, reject) => {\n      res.data\n        .pipe(extract({ cwd: outputDir, strip: 1 }))\n        .on('error', reject)\n        .on('close', () => {\n          debug('Downloaded and extracted WSDL files');\n          resolve();\n        });\n    });\n  } catch (err) {\n    const message = err instanceof Error ? err.message : 'Unknown error';\n    throw new Error(`Unable to download WSDL: ${message}`, { cause: err });\n  }\n}\n"],"mappings":";;;;;;AAOA,MAAM,QAAQ,kBAAkB,kBAAkB;AAElD,eAAsB,uBACpB,KACA,EACE,UACA,aAKa;CACf,MAAM,UAAU,kBAAkB,EAAE,UAAU,CAAC;AAE/C,OAAM,eAAe,MAAM;AAC3B,KAAI;EACF,MAAM,MAAM,MAAM,MAAM,IAAc,KAAK;GACzC,SAAS,KAAK;GACd,cAAc;GACd,GAAG;GACJ,CAAC;AAEF,SACE,IAAI,mBAAmB,cACvB,mEACD;EAED,MAAM,cAAc,IAAI,QAAQ,IAAI,eAAe;AAEnD,MACE,eACA,OAAO,gBAAgB,YAOvB,CAAC,YAAY,SAAS,OAAO,IAC7B,CAAC,YAAY,SAAS,eAAe,IACrC,CAAC,YAAY,SAAS,QAAQ,CAE9B,OAAM,IAAI,MAAM,yBAAyB,cAAc;AAGzD,QAAM,IAAI,SAAe,SAAS,WAAW;AAC3C,OAAI,KACD,KAAK,QAAQ;IAAE,KAAK;IAAW,OAAO;IAAG,CAAC,CAAC,CAC3C,GAAG,SAAS,OAAO,CACnB,GAAG,eAAe;AACjB,UAAM,sCAAsC;AAC5C,aAAS;KACT;IACJ;UACK,KAAK;EACZ,MAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,QAAM,IAAI,MAAM,4BAA4B,WAAW,EAAE,OAAO,KAAK,CAAC"}