@merkur/cli 0.36.3 → 0.36.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/server.cjs +1 -1
- package/lib/server.mjs +1 -1
- package/package.json +2 -2
- package/src/devServer.mjs +6 -1
- package/src/merkurConfig.mjs +14 -2
- package/src/templates/body.ejs +1 -1
- package/src/templates/head.ejs +3 -3
- package/src/websocket.mjs +1 -0
- package/types.d.ts +5 -0
package/lib/server.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Vt=Object.create;var J=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var Yt=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var S=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xt=(t,e)=>{for(var r in e)J(t,r,{get:e[r],enumerable:!0})},We=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of zt(e))!Kt.call(t,s)&&s!==r&&J(t,s,{get:()=>e[s],enumerable:!(i=Ht(e,s))||i.enumerable});return t};var M=(t,e,r)=>(r=t!=null?Vt(Yt(t)):{},We(e||!t||!t.__esModule?J(r,"default",{value:t,enumerable:!0}):r,t)),Zt=t=>We(J({},"__esModule",{value:!0}),t);var $e=S((_s,Ge)=>{"use strict";var{Duplex:Jt}=require("stream");function Ae(t){t.emit("close")}function Qt(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Fe(t){this.removeListener("error",Fe),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function er(t,e){let r=!0,i=new Jt({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let f=!o&&i._readableState.objectMode?n.toString():n;i.push(f)||t.pause()}),t.once("error",function(n){i.destroyed||(r=!1,i.destroy(n))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(s,n){if(t.readyState===t.CLOSED){n(s),process.nextTick(Ae,i);return}let o=!1;t.once("error",function(l){o=!0,n(l)}),t.once("close",function(){o||n(s),process.nextTick(Ae,i)}),r&&t.terminate()},i._final=function(s){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(s)});return}t._socket!==null&&(t._socket._writableState.finished?(s(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){s()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(s,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(s,n,o)});return}t.send(s,o)},i.on("end",Qt),i.on("error",Fe),i}Ge.exports=er});var T=S((ps,qe)=>{"use strict";qe.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var G=S((ms,Q)=>{"use strict";var{EMPTY_BUFFER:tr}=T(),de=Buffer[Symbol.species];function rr(t,e){if(t.length===0)return tr;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let s=0;s<t.length;s++){let n=t[s];r.set(n,i),i+=n.length}return i<e?new de(r.buffer,r.byteOffset,i):r}function je(t,e,r,i,s){for(let n=0;n<s;n++)r[i+n]=t[n]^e[n&3]}function Ve(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function sr(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function _e(t){if(_e.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new de(t):ArrayBuffer.isView(t)?e=new de(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),_e.readOnly=!1),e}Q.exports={concat:rr,mask:je,toArrayBuffer:sr,toBuffer:_e,unmask:Ve};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=require("bufferutil");Q.exports.mask=function(e,r,i,s,n){n<48?je(e,r,i,s,n):t.mask(e,r,i,s,n)},Q.exports.unmask=function(e,r){e.length<32?Ve(e,r):t.unmask(e,r)}}catch{}});var Ye=S((gs,ze)=>{"use strict";var He=Symbol("kDone"),pe=Symbol("kRun"),me=class{constructor(e){this[He]=()=>{this.pending--,this[pe]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[pe]()}[pe](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[He])}}};ze.exports=me});var j=S((ys,Je)=>{"use strict";var $=require("zlib"),Ke=G(),ir=Ye(),{kStatusCode:Xe}=T(),nr=Buffer[Symbol.species],or=Buffer.from([0,0,255,255]),re=Symbol("permessage-deflate"),O=Symbol("total-length"),q=Symbol("callback"),N=Symbol("buffers"),te=Symbol("error"),ee,ge=class{constructor(e,r,i){if(this._maxPayload=i|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!ee){let s=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ee=new ir(s)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[q];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(s=>!(r.serverNoContextTakeover===!1&&s.server_no_context_takeover||s.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>s.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!s.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let s=r[i];if(s.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(s=s[0],i==="client_max_window_bits"){if(s!==!0){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else if(i==="server_max_window_bits"){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(s!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=s})}),e}decompress(e,r,i){ee.add(s=>{this._decompress(e,r,(n,o)=>{s(),i(n,o)})})}compress(e,r,i){ee.add(s=>{this._compress(e,r,(n,o)=>{s(),i(n,o)})})}_decompress(e,r,i){let s=this._isServer?"client":"server";if(!this._inflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?$.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=$.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[re]=this,this._inflate[O]=0,this._inflate[N]=[],this._inflate.on("error",fr),this._inflate.on("data",Ze)}this._inflate[q]=i,this._inflate.write(e),r&&this._inflate.write(or),this._inflate.flush(()=>{let n=this._inflate[te];if(n){this._inflate.close(),this._inflate=null,i(n);return}let o=Ke.concat(this._inflate[N],this._inflate[O]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[O]=0,this._inflate[N]=[],r&&this.params[`${s}_no_context_takeover`]&&this._inflate.reset()),i(null,o)})}_compress(e,r,i){let s=this._isServer?"server":"client";if(!this._deflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?$.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=$.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[O]=0,this._deflate[N]=[],this._deflate.on("data",ar)}this._deflate[q]=i,this._deflate.write(e),this._deflate.flush($.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Ke.concat(this._deflate[N],this._deflate[O]);r&&(n=new nr(n.buffer,n.byteOffset,n.length-4)),this._deflate[q]=null,this._deflate[O]=0,this._deflate[N]=[],r&&this.params[`${s}_no_context_takeover`]&&this._deflate.reset(),i(null,n)})}};Je.exports=ge;function ar(t){this[N].push(t),this[O]+=t.length}function Ze(t){if(this[O]+=t.length,this[re]._maxPayload<1||this[O]<=this[re]._maxPayload){this[N].push(t);return}this[te]=new RangeError("Max payload size exceeded"),this[te].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[te][Xe]=1009,this.removeListener("data",Ze),this.reset()}function fr(t){this[re]._inflate=null,t[Xe]=1007,this[q](t)}});var V=S((Ss,se)=>{"use strict";var{isUtf8:Qe}=require("buffer"),lr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function cr(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ye(t){let e=t.length,r=0;for(;r<e;)if(!(t[r]&128))r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}se.exports={isValidStatusCode:cr,isValidUTF8:ye,tokenChars:lr};if(Qe)se.exports.isValidUTF8=function(t){return t.length<24?ye(t):Qe(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=require("utf-8-validate");se.exports.isValidUTF8=function(e){return e.length<32?ye(e):t(e)}}catch{}});var be=S((xs,ot)=>{"use strict";var{Writable:hr}=require("stream"),et=j(),{BINARY_TYPES:ur,EMPTY_BUFFER:tt,kStatusCode:dr,kWebSocket:_r}=T(),{concat:Se,toArrayBuffer:pr,unmask:mr}=G(),{isValidStatusCode:gr,isValidUTF8:rt}=V(),ie=Buffer[Symbol.species],E=0,st=1,it=2,nt=3,xe=4,Ee=5,ne=6,ve=class extends hr{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||ur[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[_r]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=E}_write(e,r,i){if(this._opcode===8&&this._state==E)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e),new ie(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],s=r.length-e;e>=i.length?r.set(this._buffers.shift(),s):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),s),this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case E:this.getInfo(e);break;case st:this.getPayloadLength16(e);break;case it:this.getPayloadLength64(e);break;case nt:this.getMask();break;case xe:this.getData(e);break;case Ee:case ne:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if(r[0]&48){let s=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(s);return}let i=(r[0]&64)===64;if(i&&!this._extensions[et.extensionName]){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(!this._fragmented){let s=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let s=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(s);return}if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let s=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(s);return}}else{let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let s=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(s);return}}else if(this._masked){let s=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(s);return}this._payloadLength===126?this._state=st:this._payloadLength===127?this._state=it:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),i=r.readUInt32BE(0);if(i>Math.pow(2,21)-1){let s=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(s);return}this._payloadLength=i*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=nt:this._state=xe}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=xe}getData(e){let r=tt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&mr(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Ee,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[et.extensionName].decompress(e,this._fin,(s,n)=>{if(s)return r(s);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(n)}this.dataMessage(r),this._state===E&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=E;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let s;this._binaryType==="nodebuffer"?s=Se(i,r):this._binaryType==="arraybuffer"?s=pr(Se(i,r)):s=i,this._allowSynchronousEvents?(this.emit("message",s,!0),this._state=E):(this._state=ne,setImmediate(()=>{this.emit("message",s,!0),this._state=E,this.startLoop(e)}))}else{let s=Se(i,r);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===Ee||this._allowSynchronousEvents?(this.emit("message",s,!1),this._state=E):(this._state=ne,setImmediate(()=>{this.emit("message",s,!1),this._state=E,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,tt),this.end();else{let i=e.readUInt16BE(0);if(!gr(i)){let n=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(n);return}let s=new ie(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(n);return}this._loop=!1,this.emit("conclude",i,s),this.end()}this._state=E;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=E):(this._state=ne,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=E,this.startLoop(r)}))}createError(e,r,i,s,n){this._loop=!1,this._errored=!0;let o=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=n,o[dr]=s,o}};ot.exports=ve});var Oe=S((vs,lt)=>{"use strict";var{Duplex:Es}=require("stream"),{randomFillSync:yr}=require("crypto"),at=j(),{EMPTY_BUFFER:Sr}=T(),{isValidStatusCode:xr}=V(),{mask:ft,toBuffer:D}=G(),v=Symbol("kByteLength"),Er=Buffer.alloc(4),we=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(e,r){let i,s=!1,n=2,o=!1;r.mask&&(i=r.maskBuffer||Er,r.generateMask?r.generateMask(i):yr(i,0,4),o=(i[0]|i[1]|i[2]|i[3])===0,n=6);let f;typeof e=="string"?(!r.mask||o)&&r[v]!==void 0?f=r[v]:(e=Buffer.from(e),f=e.length):(f=e.length,s=r.mask&&r.readOnly&&!o);let l=f;f>=65536?(n+=8,l=127):f>125&&(n+=2,l=126);let a=Buffer.allocUnsafe(s?f+n:n);return a[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(a[0]|=64),a[1]=l,l===126?a.writeUInt16BE(f,2):l===127&&(a[2]=a[3]=0,a.writeUIntBE(f,4,6)),r.mask?(a[1]|=128,a[n-4]=i[0],a[n-3]=i[1],a[n-2]=i[2],a[n-1]=i[3],o?[a,e]:s?(ft(e,i,a,n,f),[a]):(ft(e,i,e,0,f),[a,e])):[a,e]}close(e,r,i,s){let n;if(e===void 0)n=Sr;else{if(typeof e!="number"||!xr(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");n=Buffer.allocUnsafe(2+f),n.writeUInt16BE(e,0),typeof r=="string"?n.write(r,2):n.set(r,2)}}let o={[v]:n.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._deflating?this.enqueue([this.dispatch,n,!1,o,s]):this.sendFrame(t.frame(n,o),s)}ping(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[v]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}pong(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[v]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}send(e,r,i){let s=this._extensions[at.extensionName],n=r.binary?2:1,o=r.compress,f,l;if(typeof e=="string"?(f=Buffer.byteLength(e),l=!1):(e=D(e),f=e.length,l=D.readOnly),this._firstFragment?(this._firstFragment=!1,o&&s&&s.params[s._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=f>=s._threshold),this._compress=o):(o=!1,n=0),r.fin&&(this._firstFragment=!0),s){let a={[v]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:o};this._deflating?this.enqueue([this.dispatch,e,this._compress,a,i]):this.dispatch(e,this._compress,a,i)}else this.sendFrame(t.frame(e,{[v]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:!1}),i)}dispatch(e,r,i,s){if(!r){this.sendFrame(t.frame(e,i),s);return}let n=this._extensions[at.extensionName];this._bufferedBytes+=i[v],this._deflating=!0,n.compress(e,i.fin,(o,f)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");typeof s=="function"&&s(l);for(let a=0;a<this._queue.length;a++){let h=this._queue[a],c=h[h.length-1];typeof c=="function"&&c(l)}return}this._bufferedBytes-=i[v],this._deflating=!1,i.readOnly=!1,this.sendFrame(t.frame(f,i),s),this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][v],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][v],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};lt.exports=we});var yt=S((bs,gt)=>{"use strict";var{kForOnEventAttribute:H,kListener:ke}=T(),ct=Symbol("kCode"),ht=Symbol("kData"),ut=Symbol("kError"),dt=Symbol("kMessage"),_t=Symbol("kReason"),W=Symbol("kTarget"),pt=Symbol("kType"),mt=Symbol("kWasClean"),k=class{constructor(e){this[W]=null,this[pt]=e}get target(){return this[W]}get type(){return this[pt]}};Object.defineProperty(k.prototype,"target",{enumerable:!0});Object.defineProperty(k.prototype,"type",{enumerable:!0});var R=class extends k{constructor(e,r={}){super(e),this[ct]=r.code===void 0?0:r.code,this[_t]=r.reason===void 0?"":r.reason,this[mt]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[ct]}get reason(){return this[_t]}get wasClean(){return this[mt]}};Object.defineProperty(R.prototype,"code",{enumerable:!0});Object.defineProperty(R.prototype,"reason",{enumerable:!0});Object.defineProperty(R.prototype,"wasClean",{enumerable:!0});var A=class extends k{constructor(e,r={}){super(e),this[ut]=r.error===void 0?null:r.error,this[dt]=r.message===void 0?"":r.message}get error(){return this[ut]}get message(){return this[dt]}};Object.defineProperty(A.prototype,"error",{enumerable:!0});Object.defineProperty(A.prototype,"message",{enumerable:!0});var z=class extends k{constructor(e,r={}){super(e),this[ht]=r.data===void 0?null:r.data}get data(){return this[ht]}};Object.defineProperty(z.prototype,"data",{enumerable:!0});var vr={addEventListener(t,e,r={}){for(let s of this.listeners(t))if(!r[H]&&s[ke]===e&&!s[H])return;let i;if(t==="message")i=function(n,o){let f=new z("message",{data:o?n:n.toString()});f[W]=this,oe(e,this,f)};else if(t==="close")i=function(n,o){let f=new R("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[W]=this,oe(e,this,f)};else if(t==="error")i=function(n){let o=new A("error",{error:n,message:n.message});o[W]=this,oe(e,this,o)};else if(t==="open")i=function(){let n=new k("open");n[W]=this,oe(e,this,n)};else return;i[H]=!!r[H],i[ke]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[ke]===e&&!r[H]){this.removeListener(t,r);break}}};gt.exports={CloseEvent:R,ErrorEvent:A,Event:k,EventTarget:vr,MessageEvent:z};function oe(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Ce=S((ws,St)=>{"use strict";var{tokenChars:Y}=V();function w(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function br(t){let e=Object.create(null),r=Object.create(null),i=!1,s=!1,n=!1,o,f,l=-1,a=-1,h=-1,c=0;for(;c<t.length;c++)if(a=t.charCodeAt(c),o===void 0)if(h===-1&&Y[a]===1)l===-1&&(l=c);else if(c!==0&&(a===32||a===9))h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);a===44?(w(e,g,r),r=Object.create(null)):o=g,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(f===void 0)if(h===-1&&Y[a]===1)l===-1&&(l=c);else if(a===32||a===9)h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),w(r,t.slice(l,h),!0),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),l=h=-1}else if(a===61&&l!==-1&&h===-1)f=t.slice(l,c),l=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(s){if(Y[a]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);l===-1?l=c:i||(i=!0),s=!1}else if(n)if(Y[a]===1)l===-1&&(l=c);else if(a===34&&l!==-1)n=!1,h=c;else if(a===92)s=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&Y[a]===1)l===-1&&(l=c);else if(l!==-1&&(a===32||a===9))h===-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);i&&(g=g.replace(/\\/g,""),i=!1),w(r,f,g),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),f=void 0,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(l===-1||n||a===32||a===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let p=t.slice(l,h);return o===void 0?w(e,p,r):(f===void 0?w(r,p,!0):i?w(r,f,p.replace(/\\/g,"")):w(r,f,p),w(e,o,r)),e}function wr(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(s=>{let n=i[s];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?s:`${s}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}St.exports={format:wr,parse:br}});var Re=S((Cs,Lt)=>{"use strict";var Or=require("events"),kr=require("https"),Cr=require("http"),vt=require("net"),Tr=require("tls"),{randomBytes:Nr,createHash:Lr}=require("crypto"),{Duplex:Os,Readable:ks}=require("stream"),{URL:Te}=require("url"),L=j(),Pr=be(),Rr=Oe(),{BINARY_TYPES:xt,EMPTY_BUFFER:ae,GUID:Ir,kForOnEventAttribute:Ne,kListener:Ur,kStatusCode:Br,kWebSocket:m,NOOP:bt}=T(),{EventTarget:{addEventListener:Mr,removeEventListener:Dr}}=yt(),{format:Wr,parse:Ar}=Ce(),{toBuffer:Fr}=G(),Gr=30*1e3,wt=Symbol("kAborted"),Le=[8,13],C=["CONNECTING","OPEN","CLOSING","CLOSED"],$r=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends Or{constructor(e,r,i){super(),this._binaryType=xt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ae,this._closeTimer=null,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Ot(this,e,r,i)):(this._autoPong=i.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){xt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,i){let s=new Pr({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation});this._sender=new Rr(e,this._extensions,i.generateMask),this._receiver=s,this._socket=e,s[m]=this,e[m]=this,s.on("conclude",Vr),s.on("drain",Hr),s.on("error",zr),s.on("message",Yr),s.on("ping",Kr),s.on("pong",Xr),e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Ct),e.on("data",le),e.on("end",Tt),e.on("error",Nt),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[L.extensionName]&&this._extensions[L.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){x(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),Gr)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||ae,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||ae,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}let s={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[L.extensionName]||(s.compress=!1),this._sender.send(e||ae,s,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){x(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:C.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:C.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:C.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:C.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:C.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:C.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:C.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:C.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ne])return e[Ur];return null},set(e){for(let r of this.listeners(t))if(r[Ne]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Ne]:!0})}})});d.prototype.addEventListener=Mr;d.prototype.removeEventListener=Dr;Lt.exports=d;function Ot(t,e,r,i){let s={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Le[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=s.autoPong,!Le.includes(s.protocolVersion))throw new RangeError(`Unsupported protocol version: ${s.protocolVersion} (supported versions: ${Le.join(", ")})`);let n;if(e instanceof Te)n=e;else try{n=new Te(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",f=n.protocol==="ws+unix:",l;if(n.protocol!=="ws:"&&!o&&!f?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"`:f&&!n.pathname?l="The URL's pathname is empty":n.hash&&(l="The URL contains a fragment identifier"),l){let u=new SyntaxError(l);if(t._redirects===0)throw u;fe(t,u);return}let a=o?443:80,h=Nr(16).toString("base64"),c=o?kr.request:Cr.request,p=new Set,g;if(s.createConnection=s.createConnection||(o?jr:qr),s.defaultPort=s.defaultPort||a,s.port=n.port||a,s.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,s.headers={...s.headers,"Sec-WebSocket-Version":s.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},s.path=n.pathname+n.search,s.timeout=s.handshakeTimeout,s.perMessageDeflate&&(g=new L(s.perMessageDeflate!==!0?s.perMessageDeflate:{},!1,s.maxPayload),s.headers["Sec-WebSocket-Extensions"]=Wr({[L.extensionName]:g.offer()})),r.length){for(let u of r){if(typeof u!="string"||!$r.test(u)||p.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");p.add(u)}s.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(s.origin&&(s.protocolVersion<13?s.headers["Sec-WebSocket-Origin"]=s.origin:s.headers.Origin=s.origin),(n.username||n.password)&&(s.auth=`${n.username}:${n.password}`),f){let u=s.path.split(":");s.socketPath=u[0],s.path=u[1]}let _;if(s.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=o,t._originalHostOrSocketPath=f?s.socketPath:n.host;let u=i&&i.headers;if(i={...i,headers:{}},u)for(let[y,B]of Object.entries(u))i.headers[y.toLowerCase()]=B}else if(t.listenerCount("redirect")===0){let u=f?t._originalIpc?s.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete s.headers.authorization,delete s.headers.cookie,u||delete s.headers.host,s.auth=void 0)}s.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(s.auth).toString("base64")),_=t._req=c(s),t._redirects&&t.emit("redirect",t.url,_)}else _=t._req=c(s);s.timeout&&_.on("timeout",()=>{x(t,_,"Opening handshake has timed out")}),_.on("error",u=>{_===null||_[wt]||(_=t._req=null,fe(t,u))}),_.on("response",u=>{let y=u.headers.location,B=u.statusCode;if(y&&s.followRedirects&&B>=300&&B<400){if(++t._redirects>s.maxRedirects){x(t,_,"Maximum redirects exceeded");return}_.abort();let Z;try{Z=new Te(y,e)}catch{let P=new SyntaxError(`Invalid URL: ${y}`);fe(t,P);return}Ot(t,Z,r,i)}else t.emit("unexpected-response",_,u)||x(t,_,`Unexpected server response: ${u.statusCode}`)}),_.on("upgrade",(u,y,B)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;if(_=t._req=null,u.headers.upgrade.toLowerCase()!=="websocket"){x(t,y,"Invalid Upgrade header");return}let Z=Lr("sha1").update(h+Ir).digest("base64");if(u.headers["sec-websocket-accept"]!==Z){x(t,y,"Invalid Sec-WebSocket-Accept header");return}let F=u.headers["sec-websocket-protocol"],P;if(F!==void 0?p.size?p.has(F)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":p.size&&(P="Server sent no subprotocol"),P){x(t,y,P);return}F&&(t._protocol=F);let Me=u.headers["sec-websocket-extensions"];if(Me!==void 0){if(!g){x(t,y,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let he;try{he=Ar(Me)}catch{x(t,y,"Invalid Sec-WebSocket-Extensions header");return}let De=Object.keys(he);if(De.length!==1||De[0]!==L.extensionName){x(t,y,"Server indicated an extension that was not requested");return}try{g.accept(he[L.extensionName])}catch{x(t,y,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[L.extensionName]=g}t.setSocket(y,B,{allowSynchronousEvents:s.allowSynchronousEvents,generateMask:s.generateMask,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation})}),s.finishRequest?s.finishRequest(_,t):_.end()}function fe(t,e){t._readyState=d.CLOSING,t.emit("error",e),t.emitClose()}function qr(t){return t.path=t.socketPath,vt.connect(t)}function jr(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=vt.isIP(t.host)?"":t.host),Tr.connect(t)}function x(t,e,r){t._readyState=d.CLOSING;let i=new Error(r);Error.captureStackTrace(i,x),e.setHeader?(e[wt]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(fe,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Pe(t,e,r){if(e){let i=Fr(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${C[t.readyState]})`);process.nextTick(r,i)}}function Vr(t,e){let r=this[m];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[m]!==void 0&&(r._socket.removeListener("data",le),process.nextTick(kt,r._socket),t===1005?r.close():r.close(t,e))}function Hr(){let t=this[m];t.isPaused||t._socket.resume()}function zr(t){let e=this[m];e._socket[m]!==void 0&&(e._socket.removeListener("data",le),process.nextTick(kt,e._socket),e.close(t[Br])),e.emit("error",t)}function Et(){this[m].emitClose()}function Yr(t,e){this[m].emit("message",t,e)}function Kr(t){let e=this[m];e._autoPong&&e.pong(t,!this._isServer,bt),e.emit("ping",t)}function Xr(t){this[m].emit("pong",t)}function kt(t){t.resume()}function Ct(){let t=this[m];this.removeListener("close",Ct),this.removeListener("data",le),this.removeListener("end",Tt),t._readyState=d.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[m]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Et),t._receiver.on("finish",Et))}function le(t){this[m]._receiver.write(t)||this.pause()}function Tt(){let t=this[m];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Nt(){let t=this[m];this.removeListener("error",Nt),this.on("error",bt),t&&(t._readyState=d.CLOSING,this.destroy())}});var Rt=S((Ts,Pt)=>{"use strict";var{tokenChars:Zr}=V();function Jr(t){let e=new Set,r=-1,i=-1,s=0;for(s;s<t.length;s++){let o=t.charCodeAt(s);if(i===-1&&Zr[o]===1)r===-1&&(r=s);else if(s!==0&&(o===32||o===9))i===-1&&r!==-1&&(i=s);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${s}`);i===-1&&(i=s);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${s}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(r,s);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}Pt.exports={parse:Jr}});var At=S((Ls,Wt)=>{"use strict";var Qr=require("events"),ce=require("http"),{Duplex:Ns}=require("stream"),{createHash:es}=require("crypto"),It=Ce(),I=j(),ts=Rt(),rs=Re(),{GUID:ss,kWebSocket:is}=T(),ns=/^[+/0-9A-Za-z]{22}==$/,Ut=0,Bt=1,Dt=2,Ie=class extends Qr{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:rs,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=ce.createServer((i,s)=>{let n=ce.STATUS_CODES[426];s.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),s.end(n)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=os(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(s,n,o)=>{this.handleUpgrade(s,n,o,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Ut}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Dt){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(K,this);return}if(e&&this.once("close",e),this._state!==Bt)if(this._state=Bt,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(K,this):process.nextTick(K,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{K(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,s){r.on("error",Mt);let n=e.headers["sec-websocket-key"],o=+e.headers["sec-websocket-version"];if(e.method!=="GET"){U(this,e,r,405,"Invalid HTTP method");return}if(e.headers.upgrade.toLowerCase()!=="websocket"){U(this,e,r,400,"Invalid Upgrade header");return}if(!n||!ns.test(n)){U(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(o!==8&&o!==13){U(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header");return}if(!this.shouldHandle(e)){X(r,400);return}let f=e.headers["sec-websocket-protocol"],l=new Set;if(f!==void 0)try{l=ts.parse(f)}catch{U(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let a=e.headers["sec-websocket-extensions"],h={};if(this.options.perMessageDeflate&&a!==void 0){let c=new I(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let p=It.parse(a);p[I.extensionName]&&(c.accept(p[I.extensionName]),h[I.extensionName]=c)}catch{U(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let c={origin:e.headers[`${o===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(c,(p,g,_,u)=>{if(!p)return X(r,g||401,_,u);this.completeUpgrade(h,n,l,e,r,i,s)});return}if(!this.options.verifyClient(c))return X(r,401)}this.completeUpgrade(h,n,l,e,r,i,s)}completeUpgrade(e,r,i,s,n,o,f){if(!n.readable||!n.writable)return n.destroy();if(n[is])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Ut)return X(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${es("sha1").update(r+ss).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(i.size){let c=this.options.handleProtocols?this.options.handleProtocols(i,s):i.values().next().value;c&&(a.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[I.extensionName]){let c=e[I.extensionName].params,p=It.format({[I.extensionName]:[c]});a.push(`Sec-WebSocket-Extensions: ${p}`),h._extensions=e}this.emit("headers",a,s),n.write(a.concat(`\r
|
|
1
|
+
"use strict";var Vt=Object.create;var J=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var Yt=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var S=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xt=(t,e)=>{for(var r in e)J(t,r,{get:e[r],enumerable:!0})},We=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of zt(e))!Kt.call(t,s)&&s!==r&&J(t,s,{get:()=>e[s],enumerable:!(i=Ht(e,s))||i.enumerable});return t};var M=(t,e,r)=>(r=t!=null?Vt(Yt(t)):{},We(e||!t||!t.__esModule?J(r,"default",{value:t,enumerable:!0}):r,t)),Zt=t=>We(J({},"__esModule",{value:!0}),t);var $e=S((_s,Ge)=>{"use strict";var{Duplex:Jt}=require("stream");function Ae(t){t.emit("close")}function Qt(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Fe(t){this.removeListener("error",Fe),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function er(t,e){let r=!0,i=new Jt({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let f=!o&&i._readableState.objectMode?n.toString():n;i.push(f)||t.pause()}),t.once("error",function(n){i.destroyed||(r=!1,i.destroy(n))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(s,n){if(t.readyState===t.CLOSED){n(s),process.nextTick(Ae,i);return}let o=!1;t.once("error",function(l){o=!0,n(l)}),t.once("close",function(){o||n(s),process.nextTick(Ae,i)}),r&&t.terminate()},i._final=function(s){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(s)});return}t._socket!==null&&(t._socket._writableState.finished?(s(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){s()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(s,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(s,n,o)});return}t.send(s,o)},i.on("end",Qt),i.on("error",Fe),i}Ge.exports=er});var C=S((ps,qe)=>{"use strict";qe.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var G=S((ms,Q)=>{"use strict";var{EMPTY_BUFFER:tr}=C(),de=Buffer[Symbol.species];function rr(t,e){if(t.length===0)return tr;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let s=0;s<t.length;s++){let n=t[s];r.set(n,i),i+=n.length}return i<e?new de(r.buffer,r.byteOffset,i):r}function je(t,e,r,i,s){for(let n=0;n<s;n++)r[i+n]=t[n]^e[n&3]}function Ve(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function sr(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function _e(t){if(_e.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new de(t):ArrayBuffer.isView(t)?e=new de(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),_e.readOnly=!1),e}Q.exports={concat:rr,mask:je,toArrayBuffer:sr,toBuffer:_e,unmask:Ve};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=require("bufferutil");Q.exports.mask=function(e,r,i,s,n){n<48?je(e,r,i,s,n):t.mask(e,r,i,s,n)},Q.exports.unmask=function(e,r){e.length<32?Ve(e,r):t.unmask(e,r)}}catch{}});var Ye=S((gs,ze)=>{"use strict";var He=Symbol("kDone"),pe=Symbol("kRun"),me=class{constructor(e){this[He]=()=>{this.pending--,this[pe]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[pe]()}[pe](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[He])}}};ze.exports=me});var j=S((ys,Je)=>{"use strict";var $=require("zlib"),Ke=G(),ir=Ye(),{kStatusCode:Xe}=C(),nr=Buffer[Symbol.species],or=Buffer.from([0,0,255,255]),re=Symbol("permessage-deflate"),O=Symbol("total-length"),q=Symbol("callback"),N=Symbol("buffers"),te=Symbol("error"),ee,ge=class{constructor(e,r,i){if(this._maxPayload=i|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!ee){let s=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ee=new ir(s)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[q];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(s=>!(r.serverNoContextTakeover===!1&&s.server_no_context_takeover||s.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>s.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!s.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let s=r[i];if(s.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(s=s[0],i==="client_max_window_bits"){if(s!==!0){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else if(i==="server_max_window_bits"){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(s!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=s})}),e}decompress(e,r,i){ee.add(s=>{this._decompress(e,r,(n,o)=>{s(),i(n,o)})})}compress(e,r,i){ee.add(s=>{this._compress(e,r,(n,o)=>{s(),i(n,o)})})}_decompress(e,r,i){let s=this._isServer?"client":"server";if(!this._inflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?$.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=$.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[re]=this,this._inflate[O]=0,this._inflate[N]=[],this._inflate.on("error",fr),this._inflate.on("data",Ze)}this._inflate[q]=i,this._inflate.write(e),r&&this._inflate.write(or),this._inflate.flush(()=>{let n=this._inflate[te];if(n){this._inflate.close(),this._inflate=null,i(n);return}let o=Ke.concat(this._inflate[N],this._inflate[O]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[O]=0,this._inflate[N]=[],r&&this.params[`${s}_no_context_takeover`]&&this._inflate.reset()),i(null,o)})}_compress(e,r,i){let s=this._isServer?"server":"client";if(!this._deflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?$.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=$.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[O]=0,this._deflate[N]=[],this._deflate.on("data",ar)}this._deflate[q]=i,this._deflate.write(e),this._deflate.flush($.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Ke.concat(this._deflate[N],this._deflate[O]);r&&(n=new nr(n.buffer,n.byteOffset,n.length-4)),this._deflate[q]=null,this._deflate[O]=0,this._deflate[N]=[],r&&this.params[`${s}_no_context_takeover`]&&this._deflate.reset(),i(null,n)})}};Je.exports=ge;function ar(t){this[N].push(t),this[O]+=t.length}function Ze(t){if(this[O]+=t.length,this[re]._maxPayload<1||this[O]<=this[re]._maxPayload){this[N].push(t);return}this[te]=new RangeError("Max payload size exceeded"),this[te].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[te][Xe]=1009,this.removeListener("data",Ze),this.reset()}function fr(t){this[re]._inflate=null,t[Xe]=1007,this[q](t)}});var V=S((Ss,se)=>{"use strict";var{isUtf8:Qe}=require("buffer"),lr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function cr(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ye(t){let e=t.length,r=0;for(;r<e;)if(!(t[r]&128))r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}se.exports={isValidStatusCode:cr,isValidUTF8:ye,tokenChars:lr};if(Qe)se.exports.isValidUTF8=function(t){return t.length<24?ye(t):Qe(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=require("utf-8-validate");se.exports.isValidUTF8=function(e){return e.length<32?ye(e):t(e)}}catch{}});var be=S((xs,ot)=>{"use strict";var{Writable:hr}=require("stream"),et=j(),{BINARY_TYPES:ur,EMPTY_BUFFER:tt,kStatusCode:dr,kWebSocket:_r}=C(),{concat:Se,toArrayBuffer:pr,unmask:mr}=G(),{isValidStatusCode:gr,isValidUTF8:rt}=V(),ie=Buffer[Symbol.species],E=0,st=1,it=2,nt=3,xe=4,Ee=5,ne=6,ve=class extends hr{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||ur[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[_r]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=E}_write(e,r,i){if(this._opcode===8&&this._state==E)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e),new ie(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],s=r.length-e;e>=i.length?r.set(this._buffers.shift(),s):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),s),this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case E:this.getInfo(e);break;case st:this.getPayloadLength16(e);break;case it:this.getPayloadLength64(e);break;case nt:this.getMask();break;case xe:this.getData(e);break;case Ee:case ne:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if(r[0]&48){let s=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(s);return}let i=(r[0]&64)===64;if(i&&!this._extensions[et.extensionName]){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(!this._fragmented){let s=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let s=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(s);return}if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let s=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(s);return}}else{let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let s=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(s);return}}else if(this._masked){let s=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(s);return}this._payloadLength===126?this._state=st:this._payloadLength===127?this._state=it:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),i=r.readUInt32BE(0);if(i>Math.pow(2,21)-1){let s=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(s);return}this._payloadLength=i*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=nt:this._state=xe}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=xe}getData(e){let r=tt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&mr(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Ee,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[et.extensionName].decompress(e,this._fin,(s,n)=>{if(s)return r(s);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(n)}this.dataMessage(r),this._state===E&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=E;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let s;this._binaryType==="nodebuffer"?s=Se(i,r):this._binaryType==="arraybuffer"?s=pr(Se(i,r)):s=i,this._allowSynchronousEvents?(this.emit("message",s,!0),this._state=E):(this._state=ne,setImmediate(()=>{this.emit("message",s,!0),this._state=E,this.startLoop(e)}))}else{let s=Se(i,r);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===Ee||this._allowSynchronousEvents?(this.emit("message",s,!1),this._state=E):(this._state=ne,setImmediate(()=>{this.emit("message",s,!1),this._state=E,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,tt),this.end();else{let i=e.readUInt16BE(0);if(!gr(i)){let n=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(n);return}let s=new ie(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(n);return}this._loop=!1,this.emit("conclude",i,s),this.end()}this._state=E;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=E):(this._state=ne,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=E,this.startLoop(r)}))}createError(e,r,i,s,n){this._loop=!1,this._errored=!0;let o=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=n,o[dr]=s,o}};ot.exports=ve});var Oe=S((vs,lt)=>{"use strict";var{Duplex:Es}=require("stream"),{randomFillSync:yr}=require("crypto"),at=j(),{EMPTY_BUFFER:Sr}=C(),{isValidStatusCode:xr}=V(),{mask:ft,toBuffer:D}=G(),v=Symbol("kByteLength"),Er=Buffer.alloc(4),we=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(e,r){let i,s=!1,n=2,o=!1;r.mask&&(i=r.maskBuffer||Er,r.generateMask?r.generateMask(i):yr(i,0,4),o=(i[0]|i[1]|i[2]|i[3])===0,n=6);let f;typeof e=="string"?(!r.mask||o)&&r[v]!==void 0?f=r[v]:(e=Buffer.from(e),f=e.length):(f=e.length,s=r.mask&&r.readOnly&&!o);let l=f;f>=65536?(n+=8,l=127):f>125&&(n+=2,l=126);let a=Buffer.allocUnsafe(s?f+n:n);return a[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(a[0]|=64),a[1]=l,l===126?a.writeUInt16BE(f,2):l===127&&(a[2]=a[3]=0,a.writeUIntBE(f,4,6)),r.mask?(a[1]|=128,a[n-4]=i[0],a[n-3]=i[1],a[n-2]=i[2],a[n-1]=i[3],o?[a,e]:s?(ft(e,i,a,n,f),[a]):(ft(e,i,e,0,f),[a,e])):[a,e]}close(e,r,i,s){let n;if(e===void 0)n=Sr;else{if(typeof e!="number"||!xr(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");n=Buffer.allocUnsafe(2+f),n.writeUInt16BE(e,0),typeof r=="string"?n.write(r,2):n.set(r,2)}}let o={[v]:n.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._deflating?this.enqueue([this.dispatch,n,!1,o,s]):this.sendFrame(t.frame(n,o),s)}ping(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[v]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}pong(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[v]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}send(e,r,i){let s=this._extensions[at.extensionName],n=r.binary?2:1,o=r.compress,f,l;if(typeof e=="string"?(f=Buffer.byteLength(e),l=!1):(e=D(e),f=e.length,l=D.readOnly),this._firstFragment?(this._firstFragment=!1,o&&s&&s.params[s._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=f>=s._threshold),this._compress=o):(o=!1,n=0),r.fin&&(this._firstFragment=!0),s){let a={[v]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:o};this._deflating?this.enqueue([this.dispatch,e,this._compress,a,i]):this.dispatch(e,this._compress,a,i)}else this.sendFrame(t.frame(e,{[v]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:!1}),i)}dispatch(e,r,i,s){if(!r){this.sendFrame(t.frame(e,i),s);return}let n=this._extensions[at.extensionName];this._bufferedBytes+=i[v],this._deflating=!0,n.compress(e,i.fin,(o,f)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");typeof s=="function"&&s(l);for(let a=0;a<this._queue.length;a++){let h=this._queue[a],c=h[h.length-1];typeof c=="function"&&c(l)}return}this._bufferedBytes-=i[v],this._deflating=!1,i.readOnly=!1,this.sendFrame(t.frame(f,i),s),this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][v],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][v],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};lt.exports=we});var yt=S((bs,gt)=>{"use strict";var{kForOnEventAttribute:H,kListener:ke}=C(),ct=Symbol("kCode"),ht=Symbol("kData"),ut=Symbol("kError"),dt=Symbol("kMessage"),_t=Symbol("kReason"),W=Symbol("kTarget"),pt=Symbol("kType"),mt=Symbol("kWasClean"),k=class{constructor(e){this[W]=null,this[pt]=e}get target(){return this[W]}get type(){return this[pt]}};Object.defineProperty(k.prototype,"target",{enumerable:!0});Object.defineProperty(k.prototype,"type",{enumerable:!0});var R=class extends k{constructor(e,r={}){super(e),this[ct]=r.code===void 0?0:r.code,this[_t]=r.reason===void 0?"":r.reason,this[mt]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[ct]}get reason(){return this[_t]}get wasClean(){return this[mt]}};Object.defineProperty(R.prototype,"code",{enumerable:!0});Object.defineProperty(R.prototype,"reason",{enumerable:!0});Object.defineProperty(R.prototype,"wasClean",{enumerable:!0});var A=class extends k{constructor(e,r={}){super(e),this[ut]=r.error===void 0?null:r.error,this[dt]=r.message===void 0?"":r.message}get error(){return this[ut]}get message(){return this[dt]}};Object.defineProperty(A.prototype,"error",{enumerable:!0});Object.defineProperty(A.prototype,"message",{enumerable:!0});var z=class extends k{constructor(e,r={}){super(e),this[ht]=r.data===void 0?null:r.data}get data(){return this[ht]}};Object.defineProperty(z.prototype,"data",{enumerable:!0});var vr={addEventListener(t,e,r={}){for(let s of this.listeners(t))if(!r[H]&&s[ke]===e&&!s[H])return;let i;if(t==="message")i=function(n,o){let f=new z("message",{data:o?n:n.toString()});f[W]=this,oe(e,this,f)};else if(t==="close")i=function(n,o){let f=new R("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[W]=this,oe(e,this,f)};else if(t==="error")i=function(n){let o=new A("error",{error:n,message:n.message});o[W]=this,oe(e,this,o)};else if(t==="open")i=function(){let n=new k("open");n[W]=this,oe(e,this,n)};else return;i[H]=!!r[H],i[ke]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[ke]===e&&!r[H]){this.removeListener(t,r);break}}};gt.exports={CloseEvent:R,ErrorEvent:A,Event:k,EventTarget:vr,MessageEvent:z};function oe(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Te=S((ws,St)=>{"use strict";var{tokenChars:Y}=V();function w(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function br(t){let e=Object.create(null),r=Object.create(null),i=!1,s=!1,n=!1,o,f,l=-1,a=-1,h=-1,c=0;for(;c<t.length;c++)if(a=t.charCodeAt(c),o===void 0)if(h===-1&&Y[a]===1)l===-1&&(l=c);else if(c!==0&&(a===32||a===9))h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);a===44?(w(e,g,r),r=Object.create(null)):o=g,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(f===void 0)if(h===-1&&Y[a]===1)l===-1&&(l=c);else if(a===32||a===9)h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),w(r,t.slice(l,h),!0),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),l=h=-1}else if(a===61&&l!==-1&&h===-1)f=t.slice(l,c),l=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(s){if(Y[a]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);l===-1?l=c:i||(i=!0),s=!1}else if(n)if(Y[a]===1)l===-1&&(l=c);else if(a===34&&l!==-1)n=!1,h=c;else if(a===92)s=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&Y[a]===1)l===-1&&(l=c);else if(l!==-1&&(a===32||a===9))h===-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);i&&(g=g.replace(/\\/g,""),i=!1),w(r,f,g),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),f=void 0,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(l===-1||n||a===32||a===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let p=t.slice(l,h);return o===void 0?w(e,p,r):(f===void 0?w(r,p,!0):i?w(r,f,p.replace(/\\/g,"")):w(r,f,p),w(e,o,r)),e}function wr(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(s=>{let n=i[s];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?s:`${s}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}St.exports={format:wr,parse:br}});var Re=S((Ts,Lt)=>{"use strict";var Or=require("events"),kr=require("https"),Tr=require("http"),vt=require("net"),Cr=require("tls"),{randomBytes:Nr,createHash:Lr}=require("crypto"),{Duplex:Os,Readable:ks}=require("stream"),{URL:Ce}=require("url"),L=j(),Pr=be(),Rr=Oe(),{BINARY_TYPES:xt,EMPTY_BUFFER:ae,GUID:Ir,kForOnEventAttribute:Ne,kListener:Ur,kStatusCode:Br,kWebSocket:m,NOOP:bt}=C(),{EventTarget:{addEventListener:Mr,removeEventListener:Dr}}=yt(),{format:Wr,parse:Ar}=Te(),{toBuffer:Fr}=G(),Gr=30*1e3,wt=Symbol("kAborted"),Le=[8,13],T=["CONNECTING","OPEN","CLOSING","CLOSED"],$r=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends Or{constructor(e,r,i){super(),this._binaryType=xt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ae,this._closeTimer=null,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Ot(this,e,r,i)):(this._autoPong=i.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){xt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,i){let s=new Pr({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation});this._sender=new Rr(e,this._extensions,i.generateMask),this._receiver=s,this._socket=e,s[m]=this,e[m]=this,s.on("conclude",Vr),s.on("drain",Hr),s.on("error",zr),s.on("message",Yr),s.on("ping",Kr),s.on("pong",Xr),e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Tt),e.on("data",le),e.on("end",Ct),e.on("error",Nt),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[L.extensionName]&&this._extensions[L.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){x(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),Gr)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||ae,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||ae,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}let s={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[L.extensionName]||(s.compress=!1),this._sender.send(e||ae,s,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){x(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:T.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:T.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:T.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:T.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:T.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:T.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:T.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:T.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ne])return e[Ur];return null},set(e){for(let r of this.listeners(t))if(r[Ne]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Ne]:!0})}})});d.prototype.addEventListener=Mr;d.prototype.removeEventListener=Dr;Lt.exports=d;function Ot(t,e,r,i){let s={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Le[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=s.autoPong,!Le.includes(s.protocolVersion))throw new RangeError(`Unsupported protocol version: ${s.protocolVersion} (supported versions: ${Le.join(", ")})`);let n;if(e instanceof Ce)n=e;else try{n=new Ce(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",f=n.protocol==="ws+unix:",l;if(n.protocol!=="ws:"&&!o&&!f?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"`:f&&!n.pathname?l="The URL's pathname is empty":n.hash&&(l="The URL contains a fragment identifier"),l){let u=new SyntaxError(l);if(t._redirects===0)throw u;fe(t,u);return}let a=o?443:80,h=Nr(16).toString("base64"),c=o?kr.request:Tr.request,p=new Set,g;if(s.createConnection=s.createConnection||(o?jr:qr),s.defaultPort=s.defaultPort||a,s.port=n.port||a,s.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,s.headers={...s.headers,"Sec-WebSocket-Version":s.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},s.path=n.pathname+n.search,s.timeout=s.handshakeTimeout,s.perMessageDeflate&&(g=new L(s.perMessageDeflate!==!0?s.perMessageDeflate:{},!1,s.maxPayload),s.headers["Sec-WebSocket-Extensions"]=Wr({[L.extensionName]:g.offer()})),r.length){for(let u of r){if(typeof u!="string"||!$r.test(u)||p.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");p.add(u)}s.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(s.origin&&(s.protocolVersion<13?s.headers["Sec-WebSocket-Origin"]=s.origin:s.headers.Origin=s.origin),(n.username||n.password)&&(s.auth=`${n.username}:${n.password}`),f){let u=s.path.split(":");s.socketPath=u[0],s.path=u[1]}let _;if(s.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=o,t._originalHostOrSocketPath=f?s.socketPath:n.host;let u=i&&i.headers;if(i={...i,headers:{}},u)for(let[y,B]of Object.entries(u))i.headers[y.toLowerCase()]=B}else if(t.listenerCount("redirect")===0){let u=f?t._originalIpc?s.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete s.headers.authorization,delete s.headers.cookie,u||delete s.headers.host,s.auth=void 0)}s.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(s.auth).toString("base64")),_=t._req=c(s),t._redirects&&t.emit("redirect",t.url,_)}else _=t._req=c(s);s.timeout&&_.on("timeout",()=>{x(t,_,"Opening handshake has timed out")}),_.on("error",u=>{_===null||_[wt]||(_=t._req=null,fe(t,u))}),_.on("response",u=>{let y=u.headers.location,B=u.statusCode;if(y&&s.followRedirects&&B>=300&&B<400){if(++t._redirects>s.maxRedirects){x(t,_,"Maximum redirects exceeded");return}_.abort();let Z;try{Z=new Ce(y,e)}catch{let P=new SyntaxError(`Invalid URL: ${y}`);fe(t,P);return}Ot(t,Z,r,i)}else t.emit("unexpected-response",_,u)||x(t,_,`Unexpected server response: ${u.statusCode}`)}),_.on("upgrade",(u,y,B)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;if(_=t._req=null,u.headers.upgrade.toLowerCase()!=="websocket"){x(t,y,"Invalid Upgrade header");return}let Z=Lr("sha1").update(h+Ir).digest("base64");if(u.headers["sec-websocket-accept"]!==Z){x(t,y,"Invalid Sec-WebSocket-Accept header");return}let F=u.headers["sec-websocket-protocol"],P;if(F!==void 0?p.size?p.has(F)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":p.size&&(P="Server sent no subprotocol"),P){x(t,y,P);return}F&&(t._protocol=F);let Me=u.headers["sec-websocket-extensions"];if(Me!==void 0){if(!g){x(t,y,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let he;try{he=Ar(Me)}catch{x(t,y,"Invalid Sec-WebSocket-Extensions header");return}let De=Object.keys(he);if(De.length!==1||De[0]!==L.extensionName){x(t,y,"Server indicated an extension that was not requested");return}try{g.accept(he[L.extensionName])}catch{x(t,y,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[L.extensionName]=g}t.setSocket(y,B,{allowSynchronousEvents:s.allowSynchronousEvents,generateMask:s.generateMask,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation})}),s.finishRequest?s.finishRequest(_,t):_.end()}function fe(t,e){t._readyState=d.CLOSING,t.emit("error",e),t.emitClose()}function qr(t){return t.path=t.socketPath,vt.connect(t)}function jr(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=vt.isIP(t.host)?"":t.host),Cr.connect(t)}function x(t,e,r){t._readyState=d.CLOSING;let i=new Error(r);Error.captureStackTrace(i,x),e.setHeader?(e[wt]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(fe,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Pe(t,e,r){if(e){let i=Fr(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${T[t.readyState]})`);process.nextTick(r,i)}}function Vr(t,e){let r=this[m];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[m]!==void 0&&(r._socket.removeListener("data",le),process.nextTick(kt,r._socket),t===1005?r.close():r.close(t,e))}function Hr(){let t=this[m];t.isPaused||t._socket.resume()}function zr(t){let e=this[m];e._socket[m]!==void 0&&(e._socket.removeListener("data",le),process.nextTick(kt,e._socket),e.close(t[Br])),e.emit("error",t)}function Et(){this[m].emitClose()}function Yr(t,e){this[m].emit("message",t,e)}function Kr(t){let e=this[m];e._autoPong&&e.pong(t,!this._isServer,bt),e.emit("ping",t)}function Xr(t){this[m].emit("pong",t)}function kt(t){t.resume()}function Tt(){let t=this[m];this.removeListener("close",Tt),this.removeListener("data",le),this.removeListener("end",Ct),t._readyState=d.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[m]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Et),t._receiver.on("finish",Et))}function le(t){this[m]._receiver.write(t)||this.pause()}function Ct(){let t=this[m];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Nt(){let t=this[m];this.removeListener("error",Nt),this.on("error",bt),t&&(t._readyState=d.CLOSING,this.destroy())}});var Rt=S((Cs,Pt)=>{"use strict";var{tokenChars:Zr}=V();function Jr(t){let e=new Set,r=-1,i=-1,s=0;for(s;s<t.length;s++){let o=t.charCodeAt(s);if(i===-1&&Zr[o]===1)r===-1&&(r=s);else if(s!==0&&(o===32||o===9))i===-1&&r!==-1&&(i=s);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${s}`);i===-1&&(i=s);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${s}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(r,s);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}Pt.exports={parse:Jr}});var At=S((Ls,Wt)=>{"use strict";var Qr=require("events"),ce=require("http"),{Duplex:Ns}=require("stream"),{createHash:es}=require("crypto"),It=Te(),I=j(),ts=Rt(),rs=Re(),{GUID:ss,kWebSocket:is}=C(),ns=/^[+/0-9A-Za-z]{22}==$/,Ut=0,Bt=1,Dt=2,Ie=class extends Qr{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:rs,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=ce.createServer((i,s)=>{let n=ce.STATUS_CODES[426];s.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),s.end(n)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=os(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(s,n,o)=>{this.handleUpgrade(s,n,o,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Ut}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Dt){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(K,this);return}if(e&&this.once("close",e),this._state!==Bt)if(this._state=Bt,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(K,this):process.nextTick(K,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{K(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,s){r.on("error",Mt);let n=e.headers["sec-websocket-key"],o=+e.headers["sec-websocket-version"];if(e.method!=="GET"){U(this,e,r,405,"Invalid HTTP method");return}if(e.headers.upgrade.toLowerCase()!=="websocket"){U(this,e,r,400,"Invalid Upgrade header");return}if(!n||!ns.test(n)){U(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(o!==8&&o!==13){U(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header");return}if(!this.shouldHandle(e)){X(r,400);return}let f=e.headers["sec-websocket-protocol"],l=new Set;if(f!==void 0)try{l=ts.parse(f)}catch{U(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let a=e.headers["sec-websocket-extensions"],h={};if(this.options.perMessageDeflate&&a!==void 0){let c=new I(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let p=It.parse(a);p[I.extensionName]&&(c.accept(p[I.extensionName]),h[I.extensionName]=c)}catch{U(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let c={origin:e.headers[`${o===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(c,(p,g,_,u)=>{if(!p)return X(r,g||401,_,u);this.completeUpgrade(h,n,l,e,r,i,s)});return}if(!this.options.verifyClient(c))return X(r,401)}this.completeUpgrade(h,n,l,e,r,i,s)}completeUpgrade(e,r,i,s,n,o,f){if(!n.readable||!n.writable)return n.destroy();if(n[is])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Ut)return X(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${es("sha1").update(r+ss).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(i.size){let c=this.options.handleProtocols?this.options.handleProtocols(i,s):i.values().next().value;c&&(a.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[I.extensionName]){let c=e[I.extensionName].params,p=It.format({[I.extensionName]:[c]});a.push(`Sec-WebSocket-Extensions: ${p}`),h._extensions=e}this.emit("headers",a,s),n.write(a.concat(`\r
|
|
2
2
|
`).join(`\r
|
|
3
3
|
`)),n.removeListener("error",Mt),h.setSocket(n,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(h),h.on("close",()=>{this.clients.delete(h),this._shouldEmitClose&&!this.clients.size&&process.nextTick(K,this)})),f(h,s)}};Wt.exports=Ie;function os(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function K(t){t._state=Dt,t.emit("close")}function Mt(){this.destroy()}function X(t,e,r,i){r=r||ce.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${ce.STATUS_CODES[e]}\r
|
|
4
4
|
`+Object.keys(i).map(s=>`${s}: ${i[s]}`).join(`\r
|
package/lib/server.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Vt=Object.create;var We=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var Yt=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var p=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var x=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Xt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of zt(e))!Kt.call(t,s)&&s!==r&&We(t,s,{get:()=>e[s],enumerable:!(i=Ht(e,s))||i.enumerable});return t};var G=(t,e,r)=>(r=t!=null?Vt(Yt(t)):{},Xt(e||!t||!t.__esModule?We(r,"default",{value:t,enumerable:!0}):r,t));var $e=x((cs,Ge)=>{"use strict";var{Duplex:Zt}=p("stream");function Ae(t){t.emit("close")}function Jt(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Fe(t){this.removeListener("error",Fe),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Qt(t,e){let r=!0,i=new Zt({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let f=!o&&i._readableState.objectMode?n.toString():n;i.push(f)||t.pause()}),t.once("error",function(n){i.destroyed||(r=!1,i.destroy(n))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(s,n){if(t.readyState===t.CLOSED){n(s),process.nextTick(Ae,i);return}let o=!1;t.once("error",function(l){o=!0,n(l)}),t.once("close",function(){o||n(s),process.nextTick(Ae,i)}),r&&t.terminate()},i._final=function(s){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(s)});return}t._socket!==null&&(t._socket._writableState.finished?(s(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){s()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(s,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(s,n,o)});return}t.send(s,o)},i.on("end",Jt),i.on("error",Fe),i}Ge.exports=Qt});var N=x((hs,qe)=>{"use strict";qe.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var $=x((us,Q)=>{"use strict";var{EMPTY_BUFFER:er}=N(),de=Buffer[Symbol.species];function tr(t,e){if(t.length===0)return er;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let s=0;s<t.length;s++){let n=t[s];r.set(n,i),i+=n.length}return i<e?new de(r.buffer,r.byteOffset,i):r}function je(t,e,r,i,s){for(let n=0;n<s;n++)r[i+n]=t[n]^e[n&3]}function Ve(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function rr(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function _e(t){if(_e.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new de(t):ArrayBuffer.isView(t)?e=new de(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),_e.readOnly=!1),e}Q.exports={concat:tr,mask:je,toArrayBuffer:rr,toBuffer:_e,unmask:Ve};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=p("bufferutil");Q.exports.mask=function(e,r,i,s,n){n<48?je(e,r,i,s,n):t.mask(e,r,i,s,n)},Q.exports.unmask=function(e,r){e.length<32?Ve(e,r):t.unmask(e,r)}}catch{}});var Ye=x((ds,ze)=>{"use strict";var He=Symbol("kDone"),pe=Symbol("kRun"),me=class{constructor(e){this[He]=()=>{this.pending--,this[pe]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[pe]()}[pe](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[He])}}};ze.exports=me});var V=x((_s,Je)=>{"use strict";var q=p("zlib"),Ke=$(),sr=Ye(),{kStatusCode:Xe}=N(),ir=Buffer[Symbol.species],nr=Buffer.from([0,0,255,255]),re=Symbol("permessage-deflate"),k=Symbol("total-length"),j=Symbol("callback"),L=Symbol("buffers"),te=Symbol("error"),ee,ge=class{constructor(e,r,i){if(this._maxPayload=i|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!ee){let s=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ee=new sr(s)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[j];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(s=>!(r.serverNoContextTakeover===!1&&s.server_no_context_takeover||s.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>s.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!s.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let s=r[i];if(s.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(s=s[0],i==="client_max_window_bits"){if(s!==!0){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else if(i==="server_max_window_bits"){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(s!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=s})}),e}decompress(e,r,i){ee.add(s=>{this._decompress(e,r,(n,o)=>{s(),i(n,o)})})}compress(e,r,i){ee.add(s=>{this._compress(e,r,(n,o)=>{s(),i(n,o)})})}_decompress(e,r,i){let s=this._isServer?"client":"server";if(!this._inflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?q.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=q.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[re]=this,this._inflate[k]=0,this._inflate[L]=[],this._inflate.on("error",ar),this._inflate.on("data",Ze)}this._inflate[j]=i,this._inflate.write(e),r&&this._inflate.write(nr),this._inflate.flush(()=>{let n=this._inflate[te];if(n){this._inflate.close(),this._inflate=null,i(n);return}let o=Ke.concat(this._inflate[L],this._inflate[k]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[k]=0,this._inflate[L]=[],r&&this.params[`${s}_no_context_takeover`]&&this._inflate.reset()),i(null,o)})}_compress(e,r,i){let s=this._isServer?"server":"client";if(!this._deflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?q.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=q.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[k]=0,this._deflate[L]=[],this._deflate.on("data",or)}this._deflate[j]=i,this._deflate.write(e),this._deflate.flush(q.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Ke.concat(this._deflate[L],this._deflate[k]);r&&(n=new ir(n.buffer,n.byteOffset,n.length-4)),this._deflate[j]=null,this._deflate[k]=0,this._deflate[L]=[],r&&this.params[`${s}_no_context_takeover`]&&this._deflate.reset(),i(null,n)})}};Je.exports=ge;function or(t){this[L].push(t),this[k]+=t.length}function Ze(t){if(this[k]+=t.length,this[re]._maxPayload<1||this[k]<=this[re]._maxPayload){this[L].push(t);return}this[te]=new RangeError("Max payload size exceeded"),this[te].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[te][Xe]=1009,this.removeListener("data",Ze),this.reset()}function ar(t){this[re]._inflate=null,t[Xe]=1007,this[j](t)}});var H=x((ps,se)=>{"use strict";var{isUtf8:Qe}=p("buffer"),fr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function lr(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ye(t){let e=t.length,r=0;for(;r<e;)if(!(t[r]&128))r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}se.exports={isValidStatusCode:lr,isValidUTF8:ye,tokenChars:fr};if(Qe)se.exports.isValidUTF8=function(t){return t.length<24?ye(t):Qe(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=p("utf-8-validate");se.exports.isValidUTF8=function(e){return e.length<32?ye(e):t(e)}}catch{}});var be=x((ms,ot)=>{"use strict";var{Writable:cr}=p("stream"),et=V(),{BINARY_TYPES:hr,EMPTY_BUFFER:tt,kStatusCode:ur,kWebSocket:dr}=N(),{concat:Se,toArrayBuffer:_r,unmask:pr}=$(),{isValidStatusCode:mr,isValidUTF8:rt}=H(),ie=Buffer[Symbol.species],v=0,st=1,it=2,nt=3,xe=4,Ee=5,ne=6,ve=class extends cr{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hr[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[dr]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=v}_write(e,r,i){if(this._opcode===8&&this._state==v)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e),new ie(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],s=r.length-e;e>=i.length?r.set(this._buffers.shift(),s):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),s),this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case v:this.getInfo(e);break;case st:this.getPayloadLength16(e);break;case it:this.getPayloadLength64(e);break;case nt:this.getMask();break;case xe:this.getData(e);break;case Ee:case ne:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if(r[0]&48){let s=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(s);return}let i=(r[0]&64)===64;if(i&&!this._extensions[et.extensionName]){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(!this._fragmented){let s=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let s=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(s);return}if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let s=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(s);return}}else{let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let s=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(s);return}}else if(this._masked){let s=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(s);return}this._payloadLength===126?this._state=st:this._payloadLength===127?this._state=it:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),i=r.readUInt32BE(0);if(i>Math.pow(2,21)-1){let s=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(s);return}this._payloadLength=i*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=nt:this._state=xe}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=xe}getData(e){let r=tt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&pr(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Ee,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[et.extensionName].decompress(e,this._fin,(s,n)=>{if(s)return r(s);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(n)}this.dataMessage(r),this._state===v&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=v;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let s;this._binaryType==="nodebuffer"?s=Se(i,r):this._binaryType==="arraybuffer"?s=_r(Se(i,r)):s=i,this._allowSynchronousEvents?(this.emit("message",s,!0),this._state=v):(this._state=ne,setImmediate(()=>{this.emit("message",s,!0),this._state=v,this.startLoop(e)}))}else{let s=Se(i,r);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===Ee||this._allowSynchronousEvents?(this.emit("message",s,!1),this._state=v):(this._state=ne,setImmediate(()=>{this.emit("message",s,!1),this._state=v,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,tt),this.end();else{let i=e.readUInt16BE(0);if(!mr(i)){let n=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(n);return}let s=new ie(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(n);return}this._loop=!1,this.emit("conclude",i,s),this.end()}this._state=v;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=v):(this._state=ne,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=v,this.startLoop(r)}))}createError(e,r,i,s,n){this._loop=!1,this._errored=!0;let o=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=n,o[ur]=s,o}};ot.exports=ve});var Oe=x((ys,lt)=>{"use strict";var{Duplex:gs}=p("stream"),{randomFillSync:gr}=p("crypto"),at=V(),{EMPTY_BUFFER:yr}=N(),{isValidStatusCode:Sr}=H(),{mask:ft,toBuffer:D}=$(),b=Symbol("kByteLength"),xr=Buffer.alloc(4),we=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(e,r){let i,s=!1,n=2,o=!1;r.mask&&(i=r.maskBuffer||xr,r.generateMask?r.generateMask(i):gr(i,0,4),o=(i[0]|i[1]|i[2]|i[3])===0,n=6);let f;typeof e=="string"?(!r.mask||o)&&r[b]!==void 0?f=r[b]:(e=Buffer.from(e),f=e.length):(f=e.length,s=r.mask&&r.readOnly&&!o);let l=f;f>=65536?(n+=8,l=127):f>125&&(n+=2,l=126);let a=Buffer.allocUnsafe(s?f+n:n);return a[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(a[0]|=64),a[1]=l,l===126?a.writeUInt16BE(f,2):l===127&&(a[2]=a[3]=0,a.writeUIntBE(f,4,6)),r.mask?(a[1]|=128,a[n-4]=i[0],a[n-3]=i[1],a[n-2]=i[2],a[n-1]=i[3],o?[a,e]:s?(ft(e,i,a,n,f),[a]):(ft(e,i,e,0,f),[a,e])):[a,e]}close(e,r,i,s){let n;if(e===void 0)n=yr;else{if(typeof e!="number"||!Sr(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");n=Buffer.allocUnsafe(2+f),n.writeUInt16BE(e,0),typeof r=="string"?n.write(r,2):n.set(r,2)}}let o={[b]:n.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._deflating?this.enqueue([this.dispatch,n,!1,o,s]):this.sendFrame(t.frame(n,o),s)}ping(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}pong(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}send(e,r,i){let s=this._extensions[at.extensionName],n=r.binary?2:1,o=r.compress,f,l;if(typeof e=="string"?(f=Buffer.byteLength(e),l=!1):(e=D(e),f=e.length,l=D.readOnly),this._firstFragment?(this._firstFragment=!1,o&&s&&s.params[s._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=f>=s._threshold),this._compress=o):(o=!1,n=0),r.fin&&(this._firstFragment=!0),s){let a={[b]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:o};this._deflating?this.enqueue([this.dispatch,e,this._compress,a,i]):this.dispatch(e,this._compress,a,i)}else this.sendFrame(t.frame(e,{[b]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:!1}),i)}dispatch(e,r,i,s){if(!r){this.sendFrame(t.frame(e,i),s);return}let n=this._extensions[at.extensionName];this._bufferedBytes+=i[b],this._deflating=!0,n.compress(e,i.fin,(o,f)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");typeof s=="function"&&s(l);for(let a=0;a<this._queue.length;a++){let h=this._queue[a],c=h[h.length-1];typeof c=="function"&&c(l)}return}this._bufferedBytes-=i[b],this._deflating=!1,i.readOnly=!1,this.sendFrame(t.frame(f,i),s),this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};lt.exports=we});var yt=x((Ss,gt)=>{"use strict";var{kForOnEventAttribute:z,kListener:ke}=N(),ct=Symbol("kCode"),ht=Symbol("kData"),ut=Symbol("kError"),dt=Symbol("kMessage"),_t=Symbol("kReason"),W=Symbol("kTarget"),pt=Symbol("kType"),mt=Symbol("kWasClean"),C=class{constructor(e){this[W]=null,this[pt]=e}get target(){return this[W]}get type(){return this[pt]}};Object.defineProperty(C.prototype,"target",{enumerable:!0});Object.defineProperty(C.prototype,"type",{enumerable:!0});var I=class extends C{constructor(e,r={}){super(e),this[ct]=r.code===void 0?0:r.code,this[_t]=r.reason===void 0?"":r.reason,this[mt]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[ct]}get reason(){return this[_t]}get wasClean(){return this[mt]}};Object.defineProperty(I.prototype,"code",{enumerable:!0});Object.defineProperty(I.prototype,"reason",{enumerable:!0});Object.defineProperty(I.prototype,"wasClean",{enumerable:!0});var A=class extends C{constructor(e,r={}){super(e),this[ut]=r.error===void 0?null:r.error,this[dt]=r.message===void 0?"":r.message}get error(){return this[ut]}get message(){return this[dt]}};Object.defineProperty(A.prototype,"error",{enumerable:!0});Object.defineProperty(A.prototype,"message",{enumerable:!0});var Y=class extends C{constructor(e,r={}){super(e),this[ht]=r.data===void 0?null:r.data}get data(){return this[ht]}};Object.defineProperty(Y.prototype,"data",{enumerable:!0});var Er={addEventListener(t,e,r={}){for(let s of this.listeners(t))if(!r[z]&&s[ke]===e&&!s[z])return;let i;if(t==="message")i=function(n,o){let f=new Y("message",{data:o?n:n.toString()});f[W]=this,oe(e,this,f)};else if(t==="close")i=function(n,o){let f=new I("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[W]=this,oe(e,this,f)};else if(t==="error")i=function(n){let o=new A("error",{error:n,message:n.message});o[W]=this,oe(e,this,o)};else if(t==="open")i=function(){let n=new C("open");n[W]=this,oe(e,this,n)};else return;i[z]=!!r[z],i[ke]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[ke]===e&&!r[z]){this.removeListener(t,r);break}}};gt.exports={CloseEvent:I,ErrorEvent:A,Event:C,EventTarget:Er,MessageEvent:Y};function oe(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Ce=x((xs,St)=>{"use strict";var{tokenChars:K}=H();function w(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function vr(t){let e=Object.create(null),r=Object.create(null),i=!1,s=!1,n=!1,o,f,l=-1,a=-1,h=-1,c=0;for(;c<t.length;c++)if(a=t.charCodeAt(c),o===void 0)if(h===-1&&K[a]===1)l===-1&&(l=c);else if(c!==0&&(a===32||a===9))h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let y=t.slice(l,h);a===44?(w(e,y,r),r=Object.create(null)):o=y,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(f===void 0)if(h===-1&&K[a]===1)l===-1&&(l=c);else if(a===32||a===9)h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),w(r,t.slice(l,h),!0),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),l=h=-1}else if(a===61&&l!==-1&&h===-1)f=t.slice(l,c),l=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(s){if(K[a]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);l===-1?l=c:i||(i=!0),s=!1}else if(n)if(K[a]===1)l===-1&&(l=c);else if(a===34&&l!==-1)n=!1,h=c;else if(a===92)s=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&K[a]===1)l===-1&&(l=c);else if(l!==-1&&(a===32||a===9))h===-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let y=t.slice(l,h);i&&(y=y.replace(/\\/g,""),i=!1),w(r,f,y),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),f=void 0,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(l===-1||n||a===32||a===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let m=t.slice(l,h);return o===void 0?w(e,m,r):(f===void 0?w(r,m,!0):i?w(r,f,m.replace(/\\/g,"")):w(r,f,m),w(e,o,r)),e}function br(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(s=>{let n=i[s];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?s:`${s}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}St.exports={format:br,parse:vr}});var Re=x((bs,Lt)=>{"use strict";var wr=p("events"),Or=p("https"),kr=p("http"),vt=p("net"),Cr=p("tls"),{randomBytes:Tr,createHash:Nr}=p("crypto"),{Duplex:Es,Readable:vs}=p("stream"),{URL:Te}=p("url"),P=V(),Lr=be(),Pr=Oe(),{BINARY_TYPES:xt,EMPTY_BUFFER:ae,GUID:Rr,kForOnEventAttribute:Ne,kListener:Ir,kStatusCode:Ur,kWebSocket:g,NOOP:bt}=N(),{EventTarget:{addEventListener:Br,removeEventListener:Mr}}=yt(),{format:Dr,parse:Wr}=Ce(),{toBuffer:Ar}=$(),Fr=30*1e3,wt=Symbol("kAborted"),Le=[8,13],T=["CONNECTING","OPEN","CLOSING","CLOSED"],Gr=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends wr{constructor(e,r,i){super(),this._binaryType=xt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ae,this._closeTimer=null,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Ot(this,e,r,i)):(this._autoPong=i.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){xt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,i){let s=new Lr({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation});this._sender=new Pr(e,this._extensions,i.generateMask),this._receiver=s,this._socket=e,s[g]=this,e[g]=this,s.on("conclude",jr),s.on("drain",Vr),s.on("error",Hr),s.on("message",zr),s.on("ping",Yr),s.on("pong",Kr),e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Ct),e.on("data",le),e.on("end",Tt),e.on("error",Nt),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[P.extensionName]&&this._extensions[P.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),Fr)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||ae,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||ae,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}let s={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[P.extensionName]||(s.compress=!1),this._sender.send(e||ae,s,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:T.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:T.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:T.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:T.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:T.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:T.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:T.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:T.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ne])return e[Ir];return null},set(e){for(let r of this.listeners(t))if(r[Ne]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Ne]:!0})}})});d.prototype.addEventListener=Br;d.prototype.removeEventListener=Mr;Lt.exports=d;function Ot(t,e,r,i){let s={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Le[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=s.autoPong,!Le.includes(s.protocolVersion))throw new RangeError(`Unsupported protocol version: ${s.protocolVersion} (supported versions: ${Le.join(", ")})`);let n;if(e instanceof Te)n=e;else try{n=new Te(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",f=n.protocol==="ws+unix:",l;if(n.protocol!=="ws:"&&!o&&!f?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"`:f&&!n.pathname?l="The URL's pathname is empty":n.hash&&(l="The URL contains a fragment identifier"),l){let u=new SyntaxError(l);if(t._redirects===0)throw u;fe(t,u);return}let a=o?443:80,h=Tr(16).toString("base64"),c=o?Or.request:kr.request,m=new Set,y;if(s.createConnection=s.createConnection||(o?qr:$r),s.defaultPort=s.defaultPort||a,s.port=n.port||a,s.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,s.headers={...s.headers,"Sec-WebSocket-Version":s.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},s.path=n.pathname+n.search,s.timeout=s.handshakeTimeout,s.perMessageDeflate&&(y=new P(s.perMessageDeflate!==!0?s.perMessageDeflate:{},!1,s.maxPayload),s.headers["Sec-WebSocket-Extensions"]=Dr({[P.extensionName]:y.offer()})),r.length){for(let u of r){if(typeof u!="string"||!Gr.test(u)||m.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");m.add(u)}s.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(s.origin&&(s.protocolVersion<13?s.headers["Sec-WebSocket-Origin"]=s.origin:s.headers.Origin=s.origin),(n.username||n.password)&&(s.auth=`${n.username}:${n.password}`),f){let u=s.path.split(":");s.socketPath=u[0],s.path=u[1]}let _;if(s.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=o,t._originalHostOrSocketPath=f?s.socketPath:n.host;let u=i&&i.headers;if(i={...i,headers:{}},u)for(let[S,M]of Object.entries(u))i.headers[S.toLowerCase()]=M}else if(t.listenerCount("redirect")===0){let u=f?t._originalIpc?s.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete s.headers.authorization,delete s.headers.cookie,u||delete s.headers.host,s.auth=void 0)}s.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(s.auth).toString("base64")),_=t._req=c(s),t._redirects&&t.emit("redirect",t.url,_)}else _=t._req=c(s);s.timeout&&_.on("timeout",()=>{E(t,_,"Opening handshake has timed out")}),_.on("error",u=>{_===null||_[wt]||(_=t._req=null,fe(t,u))}),_.on("response",u=>{let S=u.headers.location,M=u.statusCode;if(S&&s.followRedirects&&M>=300&&M<400){if(++t._redirects>s.maxRedirects){E(t,_,"Maximum redirects exceeded");return}_.abort();let J;try{J=new Te(S,e)}catch{let R=new SyntaxError(`Invalid URL: ${S}`);fe(t,R);return}Ot(t,J,r,i)}else t.emit("unexpected-response",_,u)||E(t,_,`Unexpected server response: ${u.statusCode}`)}),_.on("upgrade",(u,S,M)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;if(_=t._req=null,u.headers.upgrade.toLowerCase()!=="websocket"){E(t,S,"Invalid Upgrade header");return}let J=Nr("sha1").update(h+Rr).digest("base64");if(u.headers["sec-websocket-accept"]!==J){E(t,S,"Invalid Sec-WebSocket-Accept header");return}let F=u.headers["sec-websocket-protocol"],R;if(F!==void 0?m.size?m.has(F)||(R="Server sent an invalid subprotocol"):R="Server sent a subprotocol but none was requested":m.size&&(R="Server sent no subprotocol"),R){E(t,S,R);return}F&&(t._protocol=F);let Me=u.headers["sec-websocket-extensions"];if(Me!==void 0){if(!y){E(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let he;try{he=Wr(Me)}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}let De=Object.keys(he);if(De.length!==1||De[0]!==P.extensionName){E(t,S,"Server indicated an extension that was not requested");return}try{y.accept(he[P.extensionName])}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[P.extensionName]=y}t.setSocket(S,M,{allowSynchronousEvents:s.allowSynchronousEvents,generateMask:s.generateMask,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation})}),s.finishRequest?s.finishRequest(_,t):_.end()}function fe(t,e){t._readyState=d.CLOSING,t.emit("error",e),t.emitClose()}function $r(t){return t.path=t.socketPath,vt.connect(t)}function qr(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=vt.isIP(t.host)?"":t.host),Cr.connect(t)}function E(t,e,r){t._readyState=d.CLOSING;let i=new Error(r);Error.captureStackTrace(i,E),e.setHeader?(e[wt]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(fe,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Pe(t,e,r){if(e){let i=Ar(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${T[t.readyState]})`);process.nextTick(r,i)}}function jr(t,e){let r=this[g];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[g]!==void 0&&(r._socket.removeListener("data",le),process.nextTick(kt,r._socket),t===1005?r.close():r.close(t,e))}function Vr(){let t=this[g];t.isPaused||t._socket.resume()}function Hr(t){let e=this[g];e._socket[g]!==void 0&&(e._socket.removeListener("data",le),process.nextTick(kt,e._socket),e.close(t[Ur])),e.emit("error",t)}function Et(){this[g].emitClose()}function zr(t,e){this[g].emit("message",t,e)}function Yr(t){let e=this[g];e._autoPong&&e.pong(t,!this._isServer,bt),e.emit("ping",t)}function Kr(t){this[g].emit("pong",t)}function kt(t){t.resume()}function Ct(){let t=this[g];this.removeListener("close",Ct),this.removeListener("data",le),this.removeListener("end",Tt),t._readyState=d.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[g]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Et),t._receiver.on("finish",Et))}function le(t){this[g]._receiver.write(t)||this.pause()}function Tt(){let t=this[g];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Nt(){let t=this[g];this.removeListener("error",Nt),this.on("error",bt),t&&(t._readyState=d.CLOSING,this.destroy())}});var Rt=x((ws,Pt)=>{"use strict";var{tokenChars:Xr}=H();function Zr(t){let e=new Set,r=-1,i=-1,s=0;for(s;s<t.length;s++){let o=t.charCodeAt(s);if(i===-1&&Xr[o]===1)r===-1&&(r=s);else if(s!==0&&(o===32||o===9))i===-1&&r!==-1&&(i=s);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${s}`);i===-1&&(i=s);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${s}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(r,s);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}Pt.exports={parse:Zr}});var At=x((ks,Wt)=>{"use strict";var Jr=p("events"),ce=p("http"),{Duplex:Os}=p("stream"),{createHash:Qr}=p("crypto"),It=Ce(),U=V(),es=Rt(),ts=Re(),{GUID:rs,kWebSocket:ss}=N(),is=/^[+/0-9A-Za-z]{22}==$/,Ut=0,Bt=1,Dt=2,Ie=class extends Jr{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:ts,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=ce.createServer((i,s)=>{let n=ce.STATUS_CODES[426];s.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),s.end(n)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=ns(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(s,n,o)=>{this.handleUpgrade(s,n,o,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Ut}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Dt){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(X,this);return}if(e&&this.once("close",e),this._state!==Bt)if(this._state=Bt,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(X,this):process.nextTick(X,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{X(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,s){r.on("error",Mt);let n=e.headers["sec-websocket-key"],o=+e.headers["sec-websocket-version"];if(e.method!=="GET"){B(this,e,r,405,"Invalid HTTP method");return}if(e.headers.upgrade.toLowerCase()!=="websocket"){B(this,e,r,400,"Invalid Upgrade header");return}if(!n||!is.test(n)){B(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(o!==8&&o!==13){B(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header");return}if(!this.shouldHandle(e)){Z(r,400);return}let f=e.headers["sec-websocket-protocol"],l=new Set;if(f!==void 0)try{l=es.parse(f)}catch{B(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let a=e.headers["sec-websocket-extensions"],h={};if(this.options.perMessageDeflate&&a!==void 0){let c=new U(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let m=It.parse(a);m[U.extensionName]&&(c.accept(m[U.extensionName]),h[U.extensionName]=c)}catch{B(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let c={origin:e.headers[`${o===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(c,(m,y,_,u)=>{if(!m)return Z(r,y||401,_,u);this.completeUpgrade(h,n,l,e,r,i,s)});return}if(!this.options.verifyClient(c))return Z(r,401)}this.completeUpgrade(h,n,l,e,r,i,s)}completeUpgrade(e,r,i,s,n,o,f){if(!n.readable||!n.writable)return n.destroy();if(n[ss])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Ut)return Z(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Qr("sha1").update(r+rs).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(i.size){let c=this.options.handleProtocols?this.options.handleProtocols(i,s):i.values().next().value;c&&(a.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[U.extensionName]){let c=e[U.extensionName].params,m=It.format({[U.extensionName]:[c]});a.push(`Sec-WebSocket-Extensions: ${m}`),h._extensions=e}this.emit("headers",a,s),n.write(a.concat(`\r
|
|
1
|
+
var Vt=Object.create;var We=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var Yt=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var p=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var x=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Xt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of zt(e))!Kt.call(t,s)&&s!==r&&We(t,s,{get:()=>e[s],enumerable:!(i=Ht(e,s))||i.enumerable});return t};var G=(t,e,r)=>(r=t!=null?Vt(Yt(t)):{},Xt(e||!t||!t.__esModule?We(r,"default",{value:t,enumerable:!0}):r,t));var $e=x((cs,Ge)=>{"use strict";var{Duplex:Zt}=p("stream");function Ae(t){t.emit("close")}function Jt(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Fe(t){this.removeListener("error",Fe),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Qt(t,e){let r=!0,i=new Zt({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let f=!o&&i._readableState.objectMode?n.toString():n;i.push(f)||t.pause()}),t.once("error",function(n){i.destroyed||(r=!1,i.destroy(n))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(s,n){if(t.readyState===t.CLOSED){n(s),process.nextTick(Ae,i);return}let o=!1;t.once("error",function(l){o=!0,n(l)}),t.once("close",function(){o||n(s),process.nextTick(Ae,i)}),r&&t.terminate()},i._final=function(s){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(s)});return}t._socket!==null&&(t._socket._writableState.finished?(s(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){s()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(s,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(s,n,o)});return}t.send(s,o)},i.on("end",Jt),i.on("error",Fe),i}Ge.exports=Qt});var N=x((hs,qe)=>{"use strict";qe.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var $=x((us,Q)=>{"use strict";var{EMPTY_BUFFER:er}=N(),de=Buffer[Symbol.species];function tr(t,e){if(t.length===0)return er;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let s=0;s<t.length;s++){let n=t[s];r.set(n,i),i+=n.length}return i<e?new de(r.buffer,r.byteOffset,i):r}function je(t,e,r,i,s){for(let n=0;n<s;n++)r[i+n]=t[n]^e[n&3]}function Ve(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function rr(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function _e(t){if(_e.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new de(t):ArrayBuffer.isView(t)?e=new de(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),_e.readOnly=!1),e}Q.exports={concat:tr,mask:je,toArrayBuffer:rr,toBuffer:_e,unmask:Ve};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=p("bufferutil");Q.exports.mask=function(e,r,i,s,n){n<48?je(e,r,i,s,n):t.mask(e,r,i,s,n)},Q.exports.unmask=function(e,r){e.length<32?Ve(e,r):t.unmask(e,r)}}catch{}});var Ye=x((ds,ze)=>{"use strict";var He=Symbol("kDone"),pe=Symbol("kRun"),me=class{constructor(e){this[He]=()=>{this.pending--,this[pe]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[pe]()}[pe](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[He])}}};ze.exports=me});var V=x((_s,Je)=>{"use strict";var q=p("zlib"),Ke=$(),sr=Ye(),{kStatusCode:Xe}=N(),ir=Buffer[Symbol.species],nr=Buffer.from([0,0,255,255]),re=Symbol("permessage-deflate"),k=Symbol("total-length"),j=Symbol("callback"),L=Symbol("buffers"),te=Symbol("error"),ee,ge=class{constructor(e,r,i){if(this._maxPayload=i|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!ee){let s=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ee=new sr(s)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[j];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(s=>!(r.serverNoContextTakeover===!1&&s.server_no_context_takeover||s.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>s.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!s.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let s=r[i];if(s.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(s=s[0],i==="client_max_window_bits"){if(s!==!0){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else if(i==="server_max_window_bits"){let n=+s;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${i}": ${s}`);s=n}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(s!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${s}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=s})}),e}decompress(e,r,i){ee.add(s=>{this._decompress(e,r,(n,o)=>{s(),i(n,o)})})}compress(e,r,i){ee.add(s=>{this._compress(e,r,(n,o)=>{s(),i(n,o)})})}_decompress(e,r,i){let s=this._isServer?"client":"server";if(!this._inflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?q.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=q.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[re]=this,this._inflate[k]=0,this._inflate[L]=[],this._inflate.on("error",ar),this._inflate.on("data",Ze)}this._inflate[j]=i,this._inflate.write(e),r&&this._inflate.write(nr),this._inflate.flush(()=>{let n=this._inflate[te];if(n){this._inflate.close(),this._inflate=null,i(n);return}let o=Ke.concat(this._inflate[L],this._inflate[k]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[k]=0,this._inflate[L]=[],r&&this.params[`${s}_no_context_takeover`]&&this._inflate.reset()),i(null,o)})}_compress(e,r,i){let s=this._isServer?"server":"client";if(!this._deflate){let n=`${s}_max_window_bits`,o=typeof this.params[n]!="number"?q.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=q.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[k]=0,this._deflate[L]=[],this._deflate.on("data",or)}this._deflate[j]=i,this._deflate.write(e),this._deflate.flush(q.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Ke.concat(this._deflate[L],this._deflate[k]);r&&(n=new ir(n.buffer,n.byteOffset,n.length-4)),this._deflate[j]=null,this._deflate[k]=0,this._deflate[L]=[],r&&this.params[`${s}_no_context_takeover`]&&this._deflate.reset(),i(null,n)})}};Je.exports=ge;function or(t){this[L].push(t),this[k]+=t.length}function Ze(t){if(this[k]+=t.length,this[re]._maxPayload<1||this[k]<=this[re]._maxPayload){this[L].push(t);return}this[te]=new RangeError("Max payload size exceeded"),this[te].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[te][Xe]=1009,this.removeListener("data",Ze),this.reset()}function ar(t){this[re]._inflate=null,t[Xe]=1007,this[j](t)}});var H=x((ps,se)=>{"use strict";var{isUtf8:Qe}=p("buffer"),fr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function lr(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ye(t){let e=t.length,r=0;for(;r<e;)if(!(t[r]&128))r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}se.exports={isValidStatusCode:lr,isValidUTF8:ye,tokenChars:fr};if(Qe)se.exports.isValidUTF8=function(t){return t.length<24?ye(t):Qe(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=p("utf-8-validate");se.exports.isValidUTF8=function(e){return e.length<32?ye(e):t(e)}}catch{}});var be=x((ms,ot)=>{"use strict";var{Writable:cr}=p("stream"),et=V(),{BINARY_TYPES:hr,EMPTY_BUFFER:tt,kStatusCode:ur,kWebSocket:dr}=N(),{concat:Se,toArrayBuffer:_r,unmask:pr}=$(),{isValidStatusCode:mr,isValidUTF8:rt}=H(),ie=Buffer[Symbol.species],v=0,st=1,it=2,nt=3,xe=4,Ee=5,ne=6,ve=class extends cr{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hr[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[dr]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=v}_write(e,r,i){if(this._opcode===8&&this._state==v)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e),new ie(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],s=r.length-e;e>=i.length?r.set(this._buffers.shift(),s):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),s),this._buffers[0]=new ie(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case v:this.getInfo(e);break;case st:this.getPayloadLength16(e);break;case it:this.getPayloadLength64(e);break;case nt:this.getMask();break;case xe:this.getData(e);break;case Ee:case ne:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if(r[0]&48){let s=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(s);return}let i=(r[0]&64)===64;if(i&&!this._extensions[et.extensionName]){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(!this._fragmented){let s=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let s=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(s);return}if(i){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let s=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(s);return}}else{let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let s=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(s);return}}else if(this._masked){let s=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(s);return}this._payloadLength===126?this._state=st:this._payloadLength===127?this._state=it:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),i=r.readUInt32BE(0);if(i>Math.pow(2,21)-1){let s=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(s);return}this._payloadLength=i*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=nt:this._state=xe}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=xe}getData(e){let r=tt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&pr(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Ee,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[et.extensionName].decompress(e,this._fin,(s,n)=>{if(s)return r(s);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(n)}this.dataMessage(r),this._state===v&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=v;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let s;this._binaryType==="nodebuffer"?s=Se(i,r):this._binaryType==="arraybuffer"?s=_r(Se(i,r)):s=i,this._allowSynchronousEvents?(this.emit("message",s,!0),this._state=v):(this._state=ne,setImmediate(()=>{this.emit("message",s,!0),this._state=v,this.startLoop(e)}))}else{let s=Se(i,r);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===Ee||this._allowSynchronousEvents?(this.emit("message",s,!1),this._state=v):(this._state=ne,setImmediate(()=>{this.emit("message",s,!1),this._state=v,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,tt),this.end();else{let i=e.readUInt16BE(0);if(!mr(i)){let n=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(n);return}let s=new ie(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!rt(s)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(n);return}this._loop=!1,this.emit("conclude",i,s),this.end()}this._state=v;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=v):(this._state=ne,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=v,this.startLoop(r)}))}createError(e,r,i,s,n){this._loop=!1,this._errored=!0;let o=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=n,o[ur]=s,o}};ot.exports=ve});var Oe=x((ys,lt)=>{"use strict";var{Duplex:gs}=p("stream"),{randomFillSync:gr}=p("crypto"),at=V(),{EMPTY_BUFFER:yr}=N(),{isValidStatusCode:Sr}=H(),{mask:ft,toBuffer:D}=$(),b=Symbol("kByteLength"),xr=Buffer.alloc(4),we=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(e,r){let i,s=!1,n=2,o=!1;r.mask&&(i=r.maskBuffer||xr,r.generateMask?r.generateMask(i):gr(i,0,4),o=(i[0]|i[1]|i[2]|i[3])===0,n=6);let f;typeof e=="string"?(!r.mask||o)&&r[b]!==void 0?f=r[b]:(e=Buffer.from(e),f=e.length):(f=e.length,s=r.mask&&r.readOnly&&!o);let l=f;f>=65536?(n+=8,l=127):f>125&&(n+=2,l=126);let a=Buffer.allocUnsafe(s?f+n:n);return a[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(a[0]|=64),a[1]=l,l===126?a.writeUInt16BE(f,2):l===127&&(a[2]=a[3]=0,a.writeUIntBE(f,4,6)),r.mask?(a[1]|=128,a[n-4]=i[0],a[n-3]=i[1],a[n-2]=i[2],a[n-1]=i[3],o?[a,e]:s?(ft(e,i,a,n,f),[a]):(ft(e,i,e,0,f),[a,e])):[a,e]}close(e,r,i,s){let n;if(e===void 0)n=yr;else{if(typeof e!="number"||!Sr(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");n=Buffer.allocUnsafe(2+f),n.writeUInt16BE(e,0),typeof r=="string"?n.write(r,2):n.set(r,2)}}let o={[b]:n.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._deflating?this.enqueue([this.dispatch,n,!1,o,s]):this.sendFrame(t.frame(n,o),s)}ping(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}pong(e,r,i){let s,n;if(typeof e=="string"?(s=Buffer.byteLength(e),n=!1):(e=D(e),s=e.length,n=D.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:s,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,i]):this.sendFrame(t.frame(e,o),i)}send(e,r,i){let s=this._extensions[at.extensionName],n=r.binary?2:1,o=r.compress,f,l;if(typeof e=="string"?(f=Buffer.byteLength(e),l=!1):(e=D(e),f=e.length,l=D.readOnly),this._firstFragment?(this._firstFragment=!1,o&&s&&s.params[s._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=f>=s._threshold),this._compress=o):(o=!1,n=0),r.fin&&(this._firstFragment=!0),s){let a={[b]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:o};this._deflating?this.enqueue([this.dispatch,e,this._compress,a,i]):this.dispatch(e,this._compress,a,i)}else this.sendFrame(t.frame(e,{[b]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:!1}),i)}dispatch(e,r,i,s){if(!r){this.sendFrame(t.frame(e,i),s);return}let n=this._extensions[at.extensionName];this._bufferedBytes+=i[b],this._deflating=!0,n.compress(e,i.fin,(o,f)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");typeof s=="function"&&s(l);for(let a=0;a<this._queue.length;a++){let h=this._queue[a],c=h[h.length-1];typeof c=="function"&&c(l)}return}this._bufferedBytes-=i[b],this._deflating=!1,i.readOnly=!1,this.sendFrame(t.frame(f,i),s),this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};lt.exports=we});var yt=x((Ss,gt)=>{"use strict";var{kForOnEventAttribute:z,kListener:ke}=N(),ct=Symbol("kCode"),ht=Symbol("kData"),ut=Symbol("kError"),dt=Symbol("kMessage"),_t=Symbol("kReason"),W=Symbol("kTarget"),pt=Symbol("kType"),mt=Symbol("kWasClean"),T=class{constructor(e){this[W]=null,this[pt]=e}get target(){return this[W]}get type(){return this[pt]}};Object.defineProperty(T.prototype,"target",{enumerable:!0});Object.defineProperty(T.prototype,"type",{enumerable:!0});var I=class extends T{constructor(e,r={}){super(e),this[ct]=r.code===void 0?0:r.code,this[_t]=r.reason===void 0?"":r.reason,this[mt]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[ct]}get reason(){return this[_t]}get wasClean(){return this[mt]}};Object.defineProperty(I.prototype,"code",{enumerable:!0});Object.defineProperty(I.prototype,"reason",{enumerable:!0});Object.defineProperty(I.prototype,"wasClean",{enumerable:!0});var A=class extends T{constructor(e,r={}){super(e),this[ut]=r.error===void 0?null:r.error,this[dt]=r.message===void 0?"":r.message}get error(){return this[ut]}get message(){return this[dt]}};Object.defineProperty(A.prototype,"error",{enumerable:!0});Object.defineProperty(A.prototype,"message",{enumerable:!0});var Y=class extends T{constructor(e,r={}){super(e),this[ht]=r.data===void 0?null:r.data}get data(){return this[ht]}};Object.defineProperty(Y.prototype,"data",{enumerable:!0});var Er={addEventListener(t,e,r={}){for(let s of this.listeners(t))if(!r[z]&&s[ke]===e&&!s[z])return;let i;if(t==="message")i=function(n,o){let f=new Y("message",{data:o?n:n.toString()});f[W]=this,oe(e,this,f)};else if(t==="close")i=function(n,o){let f=new I("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[W]=this,oe(e,this,f)};else if(t==="error")i=function(n){let o=new A("error",{error:n,message:n.message});o[W]=this,oe(e,this,o)};else if(t==="open")i=function(){let n=new T("open");n[W]=this,oe(e,this,n)};else return;i[z]=!!r[z],i[ke]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[ke]===e&&!r[z]){this.removeListener(t,r);break}}};gt.exports={CloseEvent:I,ErrorEvent:A,Event:T,EventTarget:Er,MessageEvent:Y};function oe(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Te=x((xs,St)=>{"use strict";var{tokenChars:K}=H();function w(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function vr(t){let e=Object.create(null),r=Object.create(null),i=!1,s=!1,n=!1,o,f,l=-1,a=-1,h=-1,c=0;for(;c<t.length;c++)if(a=t.charCodeAt(c),o===void 0)if(h===-1&&K[a]===1)l===-1&&(l=c);else if(c!==0&&(a===32||a===9))h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let y=t.slice(l,h);a===44?(w(e,y,r),r=Object.create(null)):o=y,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(f===void 0)if(h===-1&&K[a]===1)l===-1&&(l=c);else if(a===32||a===9)h===-1&&l!==-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),w(r,t.slice(l,h),!0),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),l=h=-1}else if(a===61&&l!==-1&&h===-1)f=t.slice(l,c),l=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(s){if(K[a]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);l===-1?l=c:i||(i=!0),s=!1}else if(n)if(K[a]===1)l===-1&&(l=c);else if(a===34&&l!==-1)n=!1,h=c;else if(a===92)s=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&K[a]===1)l===-1&&(l=c);else if(l!==-1&&(a===32||a===9))h===-1&&(h=c);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let y=t.slice(l,h);i&&(y=y.replace(/\\/g,""),i=!1),w(r,f,y),a===44&&(w(e,o,r),r=Object.create(null),o=void 0),f=void 0,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(l===-1||n||a===32||a===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let m=t.slice(l,h);return o===void 0?w(e,m,r):(f===void 0?w(r,m,!0):i?w(r,f,m.replace(/\\/g,"")):w(r,f,m),w(e,o,r)),e}function br(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(s=>{let n=i[s];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?s:`${s}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}St.exports={format:br,parse:vr}});var Re=x((bs,Lt)=>{"use strict";var wr=p("events"),Or=p("https"),kr=p("http"),vt=p("net"),Tr=p("tls"),{randomBytes:Cr,createHash:Nr}=p("crypto"),{Duplex:Es,Readable:vs}=p("stream"),{URL:Ce}=p("url"),P=V(),Lr=be(),Pr=Oe(),{BINARY_TYPES:xt,EMPTY_BUFFER:ae,GUID:Rr,kForOnEventAttribute:Ne,kListener:Ir,kStatusCode:Ur,kWebSocket:g,NOOP:bt}=N(),{EventTarget:{addEventListener:Br,removeEventListener:Mr}}=yt(),{format:Dr,parse:Wr}=Te(),{toBuffer:Ar}=$(),Fr=30*1e3,wt=Symbol("kAborted"),Le=[8,13],C=["CONNECTING","OPEN","CLOSING","CLOSED"],Gr=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends wr{constructor(e,r,i){super(),this._binaryType=xt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ae,this._closeTimer=null,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Ot(this,e,r,i)):(this._autoPong=i.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){xt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,i){let s=new Lr({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation});this._sender=new Pr(e,this._extensions,i.generateMask),this._receiver=s,this._socket=e,s[g]=this,e[g]=this,s.on("conclude",jr),s.on("drain",Vr),s.on("error",Hr),s.on("message",zr),s.on("ping",Yr),s.on("pong",Kr),e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Tt),e.on("data",le),e.on("end",Ct),e.on("error",Nt),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[P.extensionName]&&this._extensions[P.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),Fr)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||ae,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||ae,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pe(this,e,i);return}let s={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[P.extensionName]||(s.compress=!1),this._sender.send(e||ae,s,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:C.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:C.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:C.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:C.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:C.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:C.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:C.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:C.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ne])return e[Ir];return null},set(e){for(let r of this.listeners(t))if(r[Ne]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Ne]:!0})}})});d.prototype.addEventListener=Br;d.prototype.removeEventListener=Mr;Lt.exports=d;function Ot(t,e,r,i){let s={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Le[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=s.autoPong,!Le.includes(s.protocolVersion))throw new RangeError(`Unsupported protocol version: ${s.protocolVersion} (supported versions: ${Le.join(", ")})`);let n;if(e instanceof Ce)n=e;else try{n=new Ce(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",f=n.protocol==="ws+unix:",l;if(n.protocol!=="ws:"&&!o&&!f?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"`:f&&!n.pathname?l="The URL's pathname is empty":n.hash&&(l="The URL contains a fragment identifier"),l){let u=new SyntaxError(l);if(t._redirects===0)throw u;fe(t,u);return}let a=o?443:80,h=Cr(16).toString("base64"),c=o?Or.request:kr.request,m=new Set,y;if(s.createConnection=s.createConnection||(o?qr:$r),s.defaultPort=s.defaultPort||a,s.port=n.port||a,s.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,s.headers={...s.headers,"Sec-WebSocket-Version":s.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},s.path=n.pathname+n.search,s.timeout=s.handshakeTimeout,s.perMessageDeflate&&(y=new P(s.perMessageDeflate!==!0?s.perMessageDeflate:{},!1,s.maxPayload),s.headers["Sec-WebSocket-Extensions"]=Dr({[P.extensionName]:y.offer()})),r.length){for(let u of r){if(typeof u!="string"||!Gr.test(u)||m.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");m.add(u)}s.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(s.origin&&(s.protocolVersion<13?s.headers["Sec-WebSocket-Origin"]=s.origin:s.headers.Origin=s.origin),(n.username||n.password)&&(s.auth=`${n.username}:${n.password}`),f){let u=s.path.split(":");s.socketPath=u[0],s.path=u[1]}let _;if(s.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=o,t._originalHostOrSocketPath=f?s.socketPath:n.host;let u=i&&i.headers;if(i={...i,headers:{}},u)for(let[S,M]of Object.entries(u))i.headers[S.toLowerCase()]=M}else if(t.listenerCount("redirect")===0){let u=f?t._originalIpc?s.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete s.headers.authorization,delete s.headers.cookie,u||delete s.headers.host,s.auth=void 0)}s.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(s.auth).toString("base64")),_=t._req=c(s),t._redirects&&t.emit("redirect",t.url,_)}else _=t._req=c(s);s.timeout&&_.on("timeout",()=>{E(t,_,"Opening handshake has timed out")}),_.on("error",u=>{_===null||_[wt]||(_=t._req=null,fe(t,u))}),_.on("response",u=>{let S=u.headers.location,M=u.statusCode;if(S&&s.followRedirects&&M>=300&&M<400){if(++t._redirects>s.maxRedirects){E(t,_,"Maximum redirects exceeded");return}_.abort();let J;try{J=new Ce(S,e)}catch{let R=new SyntaxError(`Invalid URL: ${S}`);fe(t,R);return}Ot(t,J,r,i)}else t.emit("unexpected-response",_,u)||E(t,_,`Unexpected server response: ${u.statusCode}`)}),_.on("upgrade",(u,S,M)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;if(_=t._req=null,u.headers.upgrade.toLowerCase()!=="websocket"){E(t,S,"Invalid Upgrade header");return}let J=Nr("sha1").update(h+Rr).digest("base64");if(u.headers["sec-websocket-accept"]!==J){E(t,S,"Invalid Sec-WebSocket-Accept header");return}let F=u.headers["sec-websocket-protocol"],R;if(F!==void 0?m.size?m.has(F)||(R="Server sent an invalid subprotocol"):R="Server sent a subprotocol but none was requested":m.size&&(R="Server sent no subprotocol"),R){E(t,S,R);return}F&&(t._protocol=F);let Me=u.headers["sec-websocket-extensions"];if(Me!==void 0){if(!y){E(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let he;try{he=Wr(Me)}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}let De=Object.keys(he);if(De.length!==1||De[0]!==P.extensionName){E(t,S,"Server indicated an extension that was not requested");return}try{y.accept(he[P.extensionName])}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[P.extensionName]=y}t.setSocket(S,M,{allowSynchronousEvents:s.allowSynchronousEvents,generateMask:s.generateMask,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation})}),s.finishRequest?s.finishRequest(_,t):_.end()}function fe(t,e){t._readyState=d.CLOSING,t.emit("error",e),t.emitClose()}function $r(t){return t.path=t.socketPath,vt.connect(t)}function qr(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=vt.isIP(t.host)?"":t.host),Tr.connect(t)}function E(t,e,r){t._readyState=d.CLOSING;let i=new Error(r);Error.captureStackTrace(i,E),e.setHeader?(e[wt]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(fe,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Pe(t,e,r){if(e){let i=Ar(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${C[t.readyState]})`);process.nextTick(r,i)}}function jr(t,e){let r=this[g];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[g]!==void 0&&(r._socket.removeListener("data",le),process.nextTick(kt,r._socket),t===1005?r.close():r.close(t,e))}function Vr(){let t=this[g];t.isPaused||t._socket.resume()}function Hr(t){let e=this[g];e._socket[g]!==void 0&&(e._socket.removeListener("data",le),process.nextTick(kt,e._socket),e.close(t[Ur])),e.emit("error",t)}function Et(){this[g].emitClose()}function zr(t,e){this[g].emit("message",t,e)}function Yr(t){let e=this[g];e._autoPong&&e.pong(t,!this._isServer,bt),e.emit("ping",t)}function Kr(t){this[g].emit("pong",t)}function kt(t){t.resume()}function Tt(){let t=this[g];this.removeListener("close",Tt),this.removeListener("data",le),this.removeListener("end",Ct),t._readyState=d.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[g]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Et),t._receiver.on("finish",Et))}function le(t){this[g]._receiver.write(t)||this.pause()}function Ct(){let t=this[g];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Nt(){let t=this[g];this.removeListener("error",Nt),this.on("error",bt),t&&(t._readyState=d.CLOSING,this.destroy())}});var Rt=x((ws,Pt)=>{"use strict";var{tokenChars:Xr}=H();function Zr(t){let e=new Set,r=-1,i=-1,s=0;for(s;s<t.length;s++){let o=t.charCodeAt(s);if(i===-1&&Xr[o]===1)r===-1&&(r=s);else if(s!==0&&(o===32||o===9))i===-1&&r!==-1&&(i=s);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${s}`);i===-1&&(i=s);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${s}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(r,s);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}Pt.exports={parse:Zr}});var At=x((ks,Wt)=>{"use strict";var Jr=p("events"),ce=p("http"),{Duplex:Os}=p("stream"),{createHash:Qr}=p("crypto"),It=Te(),U=V(),es=Rt(),ts=Re(),{GUID:rs,kWebSocket:ss}=N(),is=/^[+/0-9A-Za-z]{22}==$/,Ut=0,Bt=1,Dt=2,Ie=class extends Jr{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:ts,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=ce.createServer((i,s)=>{let n=ce.STATUS_CODES[426];s.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),s.end(n)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=ns(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(s,n,o)=>{this.handleUpgrade(s,n,o,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Ut}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Dt){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(X,this);return}if(e&&this.once("close",e),this._state!==Bt)if(this._state=Bt,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(X,this):process.nextTick(X,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{X(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,s){r.on("error",Mt);let n=e.headers["sec-websocket-key"],o=+e.headers["sec-websocket-version"];if(e.method!=="GET"){B(this,e,r,405,"Invalid HTTP method");return}if(e.headers.upgrade.toLowerCase()!=="websocket"){B(this,e,r,400,"Invalid Upgrade header");return}if(!n||!is.test(n)){B(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(o!==8&&o!==13){B(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header");return}if(!this.shouldHandle(e)){Z(r,400);return}let f=e.headers["sec-websocket-protocol"],l=new Set;if(f!==void 0)try{l=es.parse(f)}catch{B(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let a=e.headers["sec-websocket-extensions"],h={};if(this.options.perMessageDeflate&&a!==void 0){let c=new U(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let m=It.parse(a);m[U.extensionName]&&(c.accept(m[U.extensionName]),h[U.extensionName]=c)}catch{B(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let c={origin:e.headers[`${o===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(c,(m,y,_,u)=>{if(!m)return Z(r,y||401,_,u);this.completeUpgrade(h,n,l,e,r,i,s)});return}if(!this.options.verifyClient(c))return Z(r,401)}this.completeUpgrade(h,n,l,e,r,i,s)}completeUpgrade(e,r,i,s,n,o,f){if(!n.readable||!n.writable)return n.destroy();if(n[ss])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Ut)return Z(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Qr("sha1").update(r+rs).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(i.size){let c=this.options.handleProtocols?this.options.handleProtocols(i,s):i.values().next().value;c&&(a.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[U.extensionName]){let c=e[U.extensionName].params,m=It.format({[U.extensionName]:[c]});a.push(`Sec-WebSocket-Extensions: ${m}`),h._extensions=e}this.emit("headers",a,s),n.write(a.concat(`\r
|
|
2
2
|
`).join(`\r
|
|
3
3
|
`)),n.removeListener("error",Mt),h.setSocket(n,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(h),h.on("close",()=>{this.clients.delete(h),this._shouldEmitClose&&!this.clients.size&&process.nextTick(X,this)})),f(h,s)}};Wt.exports=Ie;function ns(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function X(t){t._state=Dt,t.emit("close")}function Mt(){this.destroy()}function Z(t,e,r,i){r=r||ce.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${ce.STATUS_CODES[e]}\r
|
|
4
4
|
`+Object.keys(i).map(s=>`${s}: ${i[s]}`).join(`\r
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/cli",
|
|
3
|
-
"version": "0.36.
|
|
3
|
+
"version": "0.36.4",
|
|
4
4
|
"description": "Merkur is tiny and extensible library for creating front-end microservices.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"merkur": "./bin/merkur.mjs"
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=20"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "d980d225d1aea2186663940f0a984dafa1232c21"
|
|
70
70
|
}
|
package/src/devServer.mjs
CHANGED
|
@@ -9,6 +9,10 @@ import express from 'express';
|
|
|
9
9
|
import { createLogger } from './logger.mjs';
|
|
10
10
|
import { COMMAND_NAME } from './commands/constant.mjs';
|
|
11
11
|
|
|
12
|
+
function escapeToJSON(object) {
|
|
13
|
+
return JSON.stringify(object).replace(/<\/script/gi, '<\\/script');
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
function asyncMiddleware(fn) {
|
|
13
17
|
return (req, res, next) => {
|
|
14
18
|
Promise.resolve(fn(req, res, next)).catch(next);
|
|
@@ -135,6 +139,7 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
|
|
|
135
139
|
merkurConfig,
|
|
136
140
|
devClient,
|
|
137
141
|
html,
|
|
142
|
+
escapeToJSON,
|
|
138
143
|
}),
|
|
139
144
|
);
|
|
140
145
|
}),
|
|
@@ -167,7 +172,7 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
|
|
|
167
172
|
},
|
|
168
173
|
});
|
|
169
174
|
})
|
|
170
|
-
.listen(port, () => {
|
|
175
|
+
.listen({ port, host: merkurConfig.constant.HOST }, () => {
|
|
171
176
|
logger.info(`Playground: ${chalk.green(`${protocol}//${host}`)}`);
|
|
172
177
|
resolve(app);
|
|
173
178
|
});
|
package/src/merkurConfig.mjs
CHANGED
|
@@ -253,8 +253,20 @@ emitter.on(
|
|
|
253
253
|
return merkurConfig;
|
|
254
254
|
},
|
|
255
255
|
);
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
|
|
257
|
+
emitter.on(EMITTER_EVENTS.MERKUR_CONFIG, function hmr({ merkurConfig }) {
|
|
258
|
+
merkurConfig.HMR = merkurConfig.HMR ?? true;
|
|
259
|
+
|
|
260
|
+
return merkurConfig;
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
emitter.on(EMITTER_EVENTS.MERKUR_CONFIG, function constant({ merkurConfig }) {
|
|
264
|
+
merkurConfig.constant = {
|
|
265
|
+
...{
|
|
266
|
+
HOST: 'localhost',
|
|
267
|
+
},
|
|
268
|
+
...merkurConfig.constant,
|
|
269
|
+
};
|
|
258
270
|
|
|
259
271
|
return merkurConfig;
|
|
260
272
|
});
|
package/src/templates/body.ejs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<div class="merkur-view"><%- html %></div>
|
|
6
6
|
<script>
|
|
7
7
|
window.addEventListener('load', function () {
|
|
8
|
-
__merkur__.create(<%-
|
|
8
|
+
__merkur__.create(<%- escapeToJSON(widgetProperties) %>)
|
|
9
9
|
.then(function (widget) {
|
|
10
10
|
widget.containerSelector = '.merkur-view';
|
|
11
11
|
if (widget?.slot?.headline) {
|
package/src/templates/head.ejs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
window.__merkur_dev__ = window.__merkur_dev__ || {};
|
|
3
|
-
window.__merkur_dev__.merkurConfig = <%-
|
|
4
|
-
window.__merkur_dev__.assets = <%-
|
|
5
|
-
window.__merkur_dev__.widgetProperties = <%-
|
|
3
|
+
window.__merkur_dev__.merkurConfig = <%- escapeToJSON(merkurConfig) %>;
|
|
4
|
+
window.__merkur_dev__.assets = <%- escapeToJSON(assets) %>;
|
|
5
|
+
window.__merkur_dev__.widgetProperties = <%- escapeToJSON(widgetProperties) %>;
|
|
6
6
|
<%- devClient %>
|
|
7
7
|
</script>
|
|
8
8
|
<% assets.forEach((asset)=> { %>
|
package/src/websocket.mjs
CHANGED
package/types.d.ts
CHANGED
|
@@ -68,8 +68,13 @@ export interface WidgetServer {
|
|
|
68
68
|
clusters: number;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
export interface Constant {
|
|
72
|
+
HOST: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
71
75
|
export interface MerkurConfig {
|
|
72
76
|
HMR: boolean;
|
|
77
|
+
constant: Constant;
|
|
73
78
|
cliConfig: CLIConfig;
|
|
74
79
|
extends: Extend[];
|
|
75
80
|
task: {
|