@dgac/nmb2b-client
Version:
EUROCONTROL Network Manager B2B SOAP client
1 lines • 2.6 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/xsd/index.ts"],"sourcesContent":["import { readdir } from 'node:fs/promises';\nimport lockfile from 'proper-lockfile';\nimport type { Config } from '../../config.js';\nimport { createDebugLogger } from '../debug.js';\nimport { createDir, dirExists } from '../fs.js';\nimport { downloadAndExtractWSDL } from './downloadAndExtractWSDL.js';\nimport { getWSDLDownloadURL } from './getWSDLDownloadURL.js';\nimport { getXSDCacheDirectory } from './paths.js';\n\nconst debug = createDebugLogger('wsdl');\n\nexport async function WSDLExists(\n config: Pick<Config, 'XSD_PATH' | 'xsdEndpoint'>,\n): Promise<boolean> {\n const directory = getXSDCacheDirectory(config);\n\n debug(`Checking if directory ${directory} exists`);\n\n if (!(await dirExists(directory))) {\n return false;\n }\n\n const files = await readdir(directory);\n return files.length > 0;\n}\n\nexport type DownloadOptions = Pick<\n Config,\n 'flavour' | 'security' | 'XSD_PATH'\n> &\n Partial<Pick<Config, 'xsdEndpoint' | 'ignoreWSDLCache'>>;\n\nexport async function download(config: DownloadOptions): Promise<void> {\n const outputDir = getXSDCacheDirectory(config);\n\n if (!(await dirExists(outputDir))) {\n debug(`Creating directory ${outputDir}`);\n await createDir(outputDir);\n }\n\n debug(`Acquiring lock for folder ${outputDir}`);\n const releaseLock = await lockfile.lock(outputDir, {\n retries: 5,\n });\n\n try {\n debug(`Lock acquired. Testing WSDL existence ...`);\n\n const hasWSDL = await WSDLExists(config);\n\n if (!config.ignoreWSDLCache && hasWSDL) {\n debug('WSDL found');\n return;\n }\n\n const url = await getWSDLDownloadURL(config);\n\n debug(`Downloading ${url}`);\n\n await downloadAndExtractWSDL(url, {\n security: config.security,\n outputDir,\n });\n } finally {\n await releaseLock();\n }\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,QAAQ,kBAAkB,OAAO;AAEvC,eAAsB,WACpB,QACkB;CAClB,MAAM,YAAY,qBAAqB,OAAO;AAE9C,OAAM,yBAAyB,UAAU,SAAS;AAElD,KAAI,CAAE,MAAM,UAAU,UAAU,CAC9B,QAAO;AAIT,SADc,MAAM,QAAQ,UAAU,EACzB,SAAS;;AASxB,eAAsB,SAAS,QAAwC;CACrE,MAAM,YAAY,qBAAqB,OAAO;AAE9C,KAAI,CAAE,MAAM,UAAU,UAAU,EAAG;AACjC,QAAM,sBAAsB,YAAY;AACxC,QAAM,UAAU,UAAU;;AAG5B,OAAM,6BAA6B,YAAY;CAC/C,MAAM,cAAc,MAAM,SAAS,KAAK,WAAW,EACjD,SAAS,GACV,CAAC;AAEF,KAAI;AACF,QAAM,4CAA4C;EAElD,MAAM,UAAU,MAAM,WAAW,OAAO;AAExC,MAAI,CAAC,OAAO,mBAAmB,SAAS;AACtC,SAAM,aAAa;AACnB;;EAGF,MAAM,MAAM,MAAM,mBAAmB,OAAO;AAE5C,QAAM,eAAe,MAAM;AAE3B,QAAM,uBAAuB,KAAK;GAChC,UAAU,OAAO;GACjB;GACD,CAAC;WACM;AACR,QAAM,aAAa"}