proxy-lib
Version:
Proxy library used in NativeScript tooling. This library gives you methods to get, set and clear proxy settings respected by NativeScript tooling.
1 lines • 1.68 kB
JavaScript
const e=require("path"),r=require("child_process"),s=require("util"),{encodings:n,credentialsManagerExitCodes:t,operations:i,setCredentialsErrors:a,getCredentialsErrors:o,clearCredentialsErrors:l,credentialsManagerErrorFormat:d,credentialsManagerExecutable:c,dirNames:p,dataTypes:u,electronDirs:m}=require("./constants"),{decrypt:g,encrypt:y}=require("./encryption"),w=require("./utils"),E=(r,s)=>e.join(__dirname,p.dotDot,p.bin,r,s,c).replace(m.appAsar,m.appAsarUnpacked),C=(e,{credentialsKey:a,username:o,password:l})=>new Promise((c,p)=>{if(!w.isWindows())return c(null);const u=[a];o&&u.push(o),l&&u.push(y(l));const m=E(process.platform,process.arch),C=r.spawn(m,[e,...u]);let K=!1;C.on("error",e=>{K=!0,p(e)}),C.stdout.setEncoding(n.utf16le);let f="",h="";C.stdout.on("data",e=>{f+=e}),C.stderr.on("data",e=>{h+=e}),C.on("close",(r,n)=>{if(!K){if(r===t.noSuchKey)return c(null);if(r!==t.success){const e=s.format(d,a,r,n,h.toString());return p(new Error(e))}if(e===i.get){const[e,r]=f.trim().split(/\r?\n/),s=g(r.trim());c({credentialsKey:a,username:e.trim(),password:s})}else c()}})});module.exports={getCredentials:e=>new Promise((r,s)=>(typeof e===u.string&&(e={credentialsKey:e}),e&&e.credentialsKey?C(i.get,e).then(r,s):s(new Error(o.missingCredentialsKey)))),clearCredentials:e=>new Promise((r,s)=>(typeof e===u.string&&(e={credentialsKey:e}),e&&e.credentialsKey?C(i.clear,e).then(r,s):s(new Error(l.missingCredentialsKey)))),setCredentials:e=>new Promise((r,s)=>e&&e.credentialsKey?e.username?e.password?C(i.set,e).then(r,s):s(new Error(a.missingPassword)):s(new Error(a.missingUsername)):s(new Error(a.missingCredentialsKey))),getPathToCredentialsManagerExecutable:E};