{"version":3,"sources":["../src/httpRequest.ts","../src/version.ts"],"sourcesContent":["import { fetch, ProxyAgent } from 'undici'\n\nimport { URL } from 'node:url'\nimport { SDK_VERSION } from './version'\n\nfunction getProxyAgent(envVar: string) {\n  const proxyURI = process.env[envVar] || process.env[envVar.toUpperCase()]\n  return proxyURI ? new ProxyAgent(proxyURI) : false\n}\n\nconst httpProxy =\n  getProxyAgent('http_proxy_license_server') || getProxyAgent('http_proxy')\n\nconst httpsProxy =\n  getProxyAgent('https_proxy_license_server') || getProxyAgent('https_proxy')\n\nconst proxyAgents = {\n  ...(httpProxy ? { 'http:': httpProxy } : {}),\n  ...(httpsProxy ? { 'https:': httpsProxy } : {}),\n}\n\nconst noProxyRules = (\n  (process.env['no_proxy'] || process.env['NO_PROXY']) ??\n  ''\n)\n  .split(',')\n  .map((rule) => rule.trim())\n  .filter((rule) => rule.length > 0)\n\nconst shouldUseProxy = (url: URL) => {\n  const { host, protocol } = url\n\n  if (protocol === 'http:' && !httpProxy) {\n    return false\n  }\n\n  if (protocol === 'https:' && !httpsProxy) {\n    return false\n  }\n\n  if (noProxyRules.some((rule) => host.endsWith(rule))) {\n    return false\n  }\n\n  return true\n}\n\nexport async function postRequest<T>(\n  url: string,\n  data: Record<string, unknown>,\n  options: {\n    timeoutInMs?: number\n    productIdentifier?: string\n  } = {}\n) {\n  const targetUrl = new URL(url)\n\n  let proxyAgent: ProxyAgent | undefined\n\n  if (shouldUseProxy(targetUrl)) {\n    proxyAgent = proxyAgents[targetUrl.protocol as 'http:' | 'https:']\n  }\n\n  try {\n    const response = await fetch(url, {\n      method: 'POST',\n      body: JSON.stringify(data),\n      headers: {\n        'Content-Type': 'application/json',\n        'User-Agent': `License-SDK/${SDK_VERSION} (Node.js ${\n          process.version\n        }; ${process.platform}) ${options.productIdentifier ?? ''}`,\n      },\n      signal: AbortSignal.timeout(options.timeoutInMs ?? 30_000),\n      ...(proxyAgent ? { dispatcher: proxyAgent } : {}),\n    })\n\n    return {\n      status: response.status,\n      data: (await response.json()) as T,\n    }\n  } catch (err) {\n    const error = new Error('Connection Error: ' + (err as any).message)\n    ;(error as any).cause = err\n    throw error\n  }\n}\n\nexport default {\n  postRequest,\n}\n","// '2.25.0' is replaced before publishing to npm at .github/workflows/publish_sdk.yml\nexport const SDK_VERSION = '2.25.0'\n"],"mappings":"AAAA,OAAS,SAAAA,EAAO,cAAAC,MAAkB,SAElC,OAAS,OAAAC,MAAW,WCDb,IAAMC,EAAc,SDI3B,SAASC,EAAcC,EAAgB,CACrC,IAAMC,EAAW,QAAQ,IAAID,CAAM,GAAK,QAAQ,IAAIA,EAAO,YAAY,CAAC,EACxE,OAAOC,EAAW,IAAIC,EAAWD,CAAQ,EAAI,EAC/C,CAEA,IAAME,EACJJ,EAAc,2BAA2B,GAAKA,EAAc,YAAY,EAEpEK,EACJL,EAAc,4BAA4B,GAAKA,EAAc,aAAa,EAEtEM,EAAc,CAClB,GAAIF,EAAY,CAAE,QAASA,CAAU,EAAI,CAAC,EAC1C,GAAIC,EAAa,CAAE,SAAUA,CAAW,EAAI,CAAC,CAC/C,EAEME,IACH,QAAQ,IAAI,UAAe,QAAQ,IAAI,WACxC,IAEC,MAAM,GAAG,EACT,IAAKC,GAASA,EAAK,KAAK,CAAC,EACzB,OAAQA,GAASA,EAAK,OAAS,CAAC,EAE7BC,EAAkBC,GAAa,CACnC,GAAM,CAAE,KAAAC,EAAM,SAAAC,CAAS,EAAIF,EAU3B,MARI,EAAAE,IAAa,SAAW,CAACR,GAIzBQ,IAAa,UAAY,CAACP,GAI1BE,EAAa,KAAMC,GAASG,EAAK,SAASH,CAAI,CAAC,EAKrD,EAEA,eAAsBK,EACpBH,EACAI,EACAC,EAGI,CAAC,EACL,CACA,IAAMC,EAAY,IAAIC,EAAIP,CAAG,EAEzBQ,EAEAT,EAAeO,CAAS,IAC1BE,EAAaZ,EAAYU,EAAU,QAA8B,GAGnE,GAAI,CACF,IAAMG,EAAW,MAAMC,EAAMV,EAAK,CAChC,OAAQ,OACR,KAAM,KAAK,UAAUI,CAAI,EACzB,QAAS,CACP,eAAgB,mBAChB,aAAc,eAAeO,CAAW,aACtC,QAAQ,OACV,KAAK,QAAQ,QAAQ,KAAKN,EAAQ,mBAAqB,EAAE,EAC3D,EACA,OAAQ,YAAY,QAAQA,EAAQ,aAAe,GAAM,EACzD,GAAIG,EAAa,CAAE,WAAYA,CAAW,EAAI,CAAC,CACjD,CAAC,EAED,MAAO,CACL,OAAQC,EAAS,OACjB,KAAO,MAAMA,EAAS,KAAK,CAC7B,CACF,OAASG,EAAK,CACZ,IAAMC,EAAQ,IAAI,MAAM,qBAAwBD,EAAY,OAAO,EAClE,MAACC,EAAc,MAAQD,EAClBC,CACR,CACF,CAEA,IAAOC,EAAQ,CACb,YAAAX,CACF","names":["fetch","ProxyAgent","URL","SDK_VERSION","getProxyAgent","envVar","proxyURI","ProxyAgent","httpProxy","httpsProxy","proxyAgents","noProxyRules","rule","shouldUseProxy","url","host","protocol","postRequest","data","options","targetUrl","URL","proxyAgent","response","fetch","SDK_VERSION","err","error","httpRequest_default"]}