qualiteer/dist/bundles/qualiteer-executor.mjs

15 lines
75 KiB
JavaScript
Raw Normal View History

2022-10-15 11:47:47 +00:00
import e from"node:path";import t from"fs";import s from"url";import r from"child_process";import i from"http";import n from"https";import o from"stream";import a from"zlib";import h from"net";import c from"tls";import l from"crypto";import d from"events";function p(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(s){if("default"!==s&&!(s in e)){var r=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,r.get?r:{enumerable:!0,get:function(){return t[s]}})}}))})),Object.freeze(e)}const u=Object.create(null);u.open="0",u.close="1",u.ping="2",u.pong="3",u.message="4",u.upgrade="5",u.noop="6";const f=Object.create(null);Object.keys(u).forEach((e=>{f[u[e]]=e}));const m={type:"error",data:"parser error"},_=({type:e,data:t},s,r)=>{if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)){const e=y(t);return r(g(e,s))}return r(u[e]+(t||""))},y=e=>Buffer.isBuffer(e)?e:e instanceof ArrayBuffer?Buffer.from(e):Buffer.from(e.buffer,e.byteOffset,e.byteLength),g=(e,t)=>t?e:"b"+e.toString("base64"),b=(e,t)=>{if("string"!=typeof e)return{type:"message",data:v(e,t)};const s=e.charAt(0);if("b"===s){const s=Buffer.from(e.substring(1),"base64");return{type:"message",data:v(s,t)}}return f[s]?e.length>1?{type:f[s],data:e.substring(1)}:{type:f[s]}:m},v=(e,t)=>{const s=Buffer.isBuffer(e);return"arraybuffer"===t&&s?E(e):e},E=e=>{const t=new ArrayBuffer(e.length),s=new Uint8Array(t);for(let t=0;t<e.length;t++)s[t]=e[t];return t},w=String.fromCharCode(30);function S(e){if(e)return function(e){for(var t in S.prototype)e[t]=S.prototype[t];return e}(e)}S.prototype.on=S.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},S.prototype.once=function(e,t){function s(){this.off(e,s),t.apply(this,arguments)}return s.fn=t,this.on(e,s),this},S.prototype.off=S.prototype.removeListener=S.prototype.removeAllListeners=S.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var s,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<r.length;i++)if((s=r[i])===t||s.fn===t){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},S.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),s=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(s){r=0;for(var i=(s=s.slice(0)).length;r<i;++r)s[r].apply(this,t)}return this},S.prototype.emitReserved=S.prototype.emit,S.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},S.prototype.hasListeners=function(e){return!!this.listeners(e).length};const k=global;function x(e,...t){return t.reduce(((t,s)=>(e.hasOwnProperty(s)&&(t[s]=e[s]),t)),{})}const O=setTimeout,T=clearTimeout;function N(e,t){t.useNativeTimers?(e.setTimeoutFn=O.bind(k),e.clearTimeoutFn=T.bind(k)):(e.setTimeoutFn=setTimeout.bind(k),e.clearTimeoutFn=clearTimeout.bind(k))}class R extends Error{constructor(e,t,s){super(e),this.description=t,this.context=s,this.type="TransportError"}}class C extends S{constructor(e){super(),this.writable=!1,N(this,e),this.opts=e,this.query=e.query,this.readyState="",this.socket=e.socket}onError(e,t,s){return super.emitReserved("error",new R(e,t,s)),this}open(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(e){"open"===this.readyState&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=b(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}}const L="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),A={};let B,P=0,I=0;function D(e){let t="";do{t=L[e%64]+
2022-07-18 19:52:02 +00:00
/**
* Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
*
* This can be used with JS designed for browsers to improve reuse of code and
* allow the use of existing libraries.
*
* Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs.
*
* @author Dan DeFelippi <dan@driverdan.com>
* @contributor David Ellis <d.f.ellis@ieee.org>
* @license MIT
*/
2022-10-15 11:47:47 +00:00
var F=t,M=s,q=r.spawn,W=V;function V(e){e=e||{};var t,s,r=this,o=i,a=n,h={},c=!1,l={"User-Agent":"node-XMLHttpRequest",Accept:"*/*"},d=Object.assign({},l),p=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","content-transfer-encoding","cookie","cookie2","date","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","via"],u=["TRACE","TRACK","CONNECT"],f=!1,m=!1,_=!1,y={};this.UNSENT=0,this.OPENED=1,this.HEADERS_RECEIVED=2,this.LOADING=3,this.DONE=4,this.readyState=this.UNSENT,this.onreadystatechange=null,this.responseText="",this.responseXML="",this.status=null,this.statusText=null;this.open=function(e,t,s,r,i){if(this.abort(),m=!1,_=!1,!function(e){return e&&-1===u.indexOf(e)}(e))throw new Error("SecurityError: Request method not allowed");h={method:e,url:t.toString(),async:"boolean"!=typeof s||s,user:r||null,password:i||null},g(this.OPENED)},this.setDisableHeaderCheck=function(e){c=e},this.setRequestHeader=function(e,t){if(this.readyState!=this.OPENED)throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");if(!function(e){return c||e&&-1===p.indexOf(e.toLowerCase())}(e))return console.warn('Refused to set unsafe header "'+e+'"'),!1;if(f)throw new Error("INVALID_STATE_ERR: send flag is true");return d[e]=t,!0},this.getResponseHeader=function(e){return"string"==typeof e&&this.readyState>this.OPENED&&s.headers[e.toLowerCase()]&&!m?s.headers[e.toLowerCase()]:null},this.getAllResponseHeaders=function(){if(this.readyState<this.HEADERS_RECEIVED||m)return"";var e="";for(var t in s.headers)"set-cookie"!==t&&"set-cookie2"!==t&&(e+=t+": "+s.headers[t]+"\r\n");return e.substr(0,e.length-2)},this.getRequestHeader=function(e){return"string"==typeof e&&d[e]?d[e]:""},this.send=function(i){if(this.readyState!=this.OPENED)throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called");if(f)throw new Error("INVALID_STATE_ERR: send has already been called");var n,c=!1,l=!1,p=M.parse(h.url);switch(p.protocol){case"https:":c=!0;case"http:":n=p.hostname;break;case"file:":l=!0;break;case void 0:case"":n="localhost";break;default:throw new Error("Protocol not supported.")}if(l){if("GET"!==h.method)throw new Error("XMLHttpRequest: Only GET method is supported");if(h.async)F.readFile(unescape(p.pathname),"utf8",(function(e,t){e?r.handleError(e,e.errno||-1):(r.status=200,r.responseText=t,g(r.DONE))}));else try{this.responseText=F.readFileSync(unescape(p.pathname),"utf8"),this.status=200,g(r.DONE)}catch(e){this.handleError(e,e.errno||-1)}}else{var u=p.port||(c?443:80),_=p.pathname+(p.search?p.search:"");if(d.Host=n,c&&443===u||80===u||(d.Host+=":"+p.port),h.user){void 0===h.password&&(h.password="");var y=new Buffer(h.user+":"+h.password);d.Authorization="Basic "+y.toString("base64")}"GET"===h.method||"HEAD"===h.method?i=null:i?(d["Content-Length"]=Buffer.isBuffer(i)?i.length:Buffer.byteLength(i),d["Content-Type"]||(d["Content-Type"]="text/plain;charset=UTF-8")):"POST"===h.method&&(d["Content-Length"]=0);var b=e.agent||!1,v={host:n,port:u,path:_,method:h.method,headers:d,agent:b};if(c&&(v.pfx=e.pfx,v.key=e.key,v.passphrase=e.passphrase,v.cert=e.cert,v.ca=e.ca,v.ciphers=e.ciphers,v.rejectUnauthorized=!1!==e.rejectUnauthorized),m=!1,h.async){var E=c?a.request:o.request;f=!0,r.dispatchEvent("readystatechange");var w=function(i){if(302===(s=i).statusCode||303===s.statusCode||307===s.statusCode){h.url=s.headers.location;var o=M.parse(h.url);n=o.hostname;var a={hostname:o.hostname,port:o.port,path:o.path,method:303===s.statusCode?"GET":h.method,headers:d};return c&&(a.pfx=e.pfx,a.key=e.key,a.passphrase=e.passphrase,a.cert=e.cert,a.ca=e.ca,a.ciphers=e.ciphers,a.rejectUnauthorized=!1!==e.rejectUnauthorized),void(t=E(a,w).on("error",S)).end()}s&&s.setEncoding&&s.setEncoding("utf8"),g(r.HEADERS_RECEIVED),r.status=s.statusCode,s.on("data",(function(e){e&&(r.responseText+=e),f&&g(r.LOADING)})),s.on("end",(function(){f&&(f=!1,g(r.DONE))})),s.on("error",(function(e){r.handleError(e)})