serverless/lib/plugins/aws/dev/shim.min.js
Eslam λ Hefnawy 8df959c95c
feat(dev): Improve dev command developer experience (#12426)
* feat(dev): added ping to dev session

* feat(dev): improve dev command logging

* chore(dev): rebuild the shim
2024-04-15 10:54:35 -07:00

95 lines
262 KiB
JavaScript

var ih=Object.create;var Ar=Object.defineProperty;var nh=Object.getOwnPropertyDescriptor;var sh=Object.getOwnPropertyNames;var oh=Object.getPrototypeOf,ah=Object.prototype.hasOwnProperty;var b=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),fh=(e,t)=>{for(var r in t)Ar(e,r,{get:t[r],enumerable:!0})},wo=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of sh(t))!ah.call(e,n)&&n!==r&&Ar(e,n,{get:()=>t[n],enumerable:!(i=nh(t,n))||i.enumerable});return e};var lh=(e,t,r)=>(r=e!=null?ih(oh(e)):{},wo(t||!e||!e.__esModule?Ar(r,"default",{value:e,enumerable:!0}):r,e)),uh=e=>wo(Ar({},"__esModule",{value:!0}),e);var Nr=b((Rm,So)=>{So.exports=hh;var ch=Object.prototype.hasOwnProperty;function hh(){for(var e={},t=0;t<arguments.length;t++){var r=arguments[t];for(var i in r)ch.call(r,i)&&(e[i]=r[i])}return e}});var Xi=b((Pm,Eo)=>{Eo.exports=require("stream")});var ko=b((Bm,Oo)=>{"use strict";function xo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),r.push.apply(r,i)}return r}function Co(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?xo(Object(r),!0).forEach(function(i){dh(e,i,r[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):xo(Object(r)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(r,i))})}return e}function dh(e,t,r){return t=Io(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ph(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function To(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,Io(i.key),i)}}function _h(e,t,r){return t&&To(e.prototype,t),r&&To(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Io(e){var t=gh(e,"string");return typeof t=="symbol"?t:String(t)}function gh(e,t){if(typeof e!="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var bh=require("buffer"),Mr=bh.Buffer,yh=require("util"),Zi=yh.inspect,vh=Zi&&Zi.custom||"inspect";function mh(e,t,r){Mr.prototype.copy.call(e,t,r)}Oo.exports=function(){function e(){ph(this,e),this.head=null,this.tail=null,this.length=0}return _h(e,[{key:"push",value:function(r){var i={data:r,next:null};this.length>0?this.tail.next=i:this.head=i,this.tail=i,++this.length}},{key:"unshift",value:function(r){var i={data:r,next:this.head};this.length===0&&(this.tail=i),this.head=i,++this.length}},{key:"shift",value:function(){if(this.length!==0){var r=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,r}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(r){if(this.length===0)return"";for(var i=this.head,n=""+i.data;i=i.next;)n+=r+i.data;return n}},{key:"concat",value:function(r){if(this.length===0)return Mr.alloc(0);for(var i=Mr.allocUnsafe(r>>>0),n=this.head,s=0;n;)mh(n.data,i,s),s+=n.data.length,n=n.next;return i}},{key:"consume",value:function(r,i){var n;return r<this.head.data.length?(n=this.head.data.slice(0,r),this.head.data=this.head.data.slice(r)):r===this.head.data.length?n=this.shift():n=i?this._getString(r):this._getBuffer(r),n}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(r){var i=this.head,n=1,s=i.data;for(r-=s.length;i=i.next;){var o=i.data,f=r>o.length?o.length:r;if(f===o.length?s+=o:s+=o.slice(0,r),r-=f,r===0){f===o.length?(++n,i.next?this.head=i.next:this.head=this.tail=null):(this.head=i,i.data=o.slice(f));break}++n}return this.length-=n,s}},{key:"_getBuffer",value:function(r){var i=Mr.allocUnsafe(r),n=this.head,s=1;for(n.data.copy(i),r-=n.data.length;n=n.next;){var o=n.data,f=r>o.length?o.length:r;if(o.copy(i,i.length-r,0,f),r-=f,r===0){f===o.length?(++s,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=o.slice(f));break}++s}return this.length-=s,i}},{key:vh,value:function(r,i){return Zi(this,Co(Co({},i),{},{depth:0,customInspect:!1}))}}]),e}()});var tn=b((Am,Po)=>{"use strict";function wh(e,t){var r=this,i=this._readableState&&this._readableState.destroyed,n=this._writableState&&this._writableState.destroyed;return i||n?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,process.nextTick(en,this,e)):process.nextTick(en,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(s){!t&&s?r._writableState?r._writableState.errorEmitted?process.nextTick(Lr,r):(r._writableState.errorEmitted=!0,process.nextTick(Ro,r,s)):process.nextTick(Ro,r,s):t?(process.nextTick(Lr,r),t(s)):process.nextTick(Lr,r)}),this)}function Ro(e,t){en(e,t),Lr(e)}function Lr(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function Sh(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function en(e,t){e.emit("error",t)}function Eh(e,t){var r=e._readableState,i=e._writableState;r&&r.autoDestroy||i&&i.autoDestroy?e.destroy(t):e.emit("error",t)}Po.exports={destroy:wh,undestroy:Sh,errorOrDestroy:Eh}});var Ue=b((Nm,No)=>{"use strict";var Ao={};function he(e,t,r){r||(r=Error);function i(s,o,f){return typeof t=="string"?t:t(s,o,f)}class n extends r{constructor(o,f,a){super(i(o,f,a))}}n.prototype.name=r.name,n.prototype.code=e,Ao[e]=n}function Bo(e,t){if(Array.isArray(e)){let r=e.length;return e=e.map(i=>String(i)),r>2?`one of ${t} ${e.slice(0,r-1).join(", ")}, or `+e[r-1]:r===2?`one of ${t} ${e[0]} or ${e[1]}`:`of ${t} ${e[0]}`}else return`of ${t} ${String(e)}`}function xh(e,t,r){return e.substr(!r||r<0?0:+r,t.length)===t}function Ch(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function Th(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}he("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);he("ERR_INVALID_ARG_TYPE",function(e,t,r){let i;typeof t=="string"&&xh(t,"not ")?(i="must not be",t=t.replace(/^not /,"")):i="must be";let n;if(Ch(e," argument"))n=`The ${e} ${i} ${Bo(t,"type")}`;else{let s=Th(e,".")?"property":"argument";n=`The "${e}" ${s} ${i} ${Bo(t,"type")}`}return n+=`. Received type ${typeof r}`,n},TypeError);he("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");he("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});he("ERR_STREAM_PREMATURE_CLOSE","Premature close");he("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});he("ERR_MULTIPLE_CALLBACK","Callback called multiple times");he("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");he("ERR_STREAM_WRITE_AFTER_END","write after end");he("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);he("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);he("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");No.exports.codes=Ao});var rn=b((Mm,Mo)=>{"use strict";var Ih=Ue().codes.ERR_INVALID_OPT_VALUE;function Oh(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function kh(e,t,r,i){var n=Oh(t,i,r);if(n!=null){if(!(isFinite(n)&&Math.floor(n)===n)||n<0){var s=i?r:"highWaterMark";throw new Ih(s,n)}return Math.floor(n)}return e.objectMode?16:16*1024}Mo.exports={getHighWaterMark:kh}});var Lo=b((Lm,nn)=>{typeof Object.create=="function"?nn.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:nn.exports=function(t,r){if(r){t.super_=r;var i=function(){};i.prototype=r.prototype,t.prototype=new i,t.prototype.constructor=t}}});var ie=b((qm,on)=>{try{if(sn=require("util"),typeof sn.inherits!="function")throw"";on.exports=sn.inherits}catch{on.exports=Lo()}var sn});var an=b((Dm,qo)=>{qo.exports=require("util").deprecate});var un=b((Um,Vo)=>{"use strict";Vo.exports=$;function Uo(e){var t=this;this.next=null,this.entry=null,this.finish=function(){rd(t,e)}}var mt;$.WritableState=jt;var Rh={deprecate:an()},jo=Xi(),Dr=require("buffer").Buffer,Ph=(typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function Bh(e){return Dr.from(e)}function Ah(e){return Dr.isBuffer(e)||e instanceof Ph}var ln=tn(),Nh=rn(),Mh=Nh.getHighWaterMark,je=Ue().codes,Lh=je.ERR_INVALID_ARG_TYPE,qh=je.ERR_METHOD_NOT_IMPLEMENTED,Dh=je.ERR_MULTIPLE_CALLBACK,Uh=je.ERR_STREAM_CANNOT_PIPE,jh=je.ERR_STREAM_DESTROYED,Fh=je.ERR_STREAM_NULL_VALUES,Wh=je.ERR_STREAM_WRITE_AFTER_END,Vh=je.ERR_UNKNOWN_ENCODING,wt=ln.errorOrDestroy;ie()($,jo);function Hh(){}function jt(e,t,r){mt=mt||it(),e=e||{},typeof r!="boolean"&&(r=t instanceof mt),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=Mh(this,e,"writableHighWaterMark",r),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var i=e.decodeStrings===!1;this.decodeStrings=!i,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(n){Jh(t,n)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=e.emitClose!==!1,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new Uo(this)}jt.prototype.getBuffer=function(){for(var t=this.bufferedRequest,r=[];t;)r.push(t),t=t.next;return r};(function(){try{Object.defineProperty(jt.prototype,"buffer",{get:Rh.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}})();var qr;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(qr=Function.prototype[Symbol.hasInstance],Object.defineProperty($,Symbol.hasInstance,{value:function(t){return qr.call(this,t)?!0:this!==$?!1:t&&t._writableState instanceof jt}})):qr=function(t){return t instanceof this};function $(e){mt=mt||it();var t=this instanceof mt;if(!t&&!qr.call($,this))return new $(e);this._writableState=new jt(e,this,t),this.writable=!0,e&&(typeof e.write=="function"&&(this._write=e.write),typeof e.writev=="function"&&(this._writev=e.writev),typeof e.destroy=="function"&&(this._destroy=e.destroy),typeof e.final=="function"&&(this._final=e.final)),jo.call(this)}$.prototype.pipe=function(){wt(this,new Uh)};function $h(e,t){var r=new Wh;wt(e,r),process.nextTick(t,r)}function Gh(e,t,r,i){var n;return r===null?n=new Fh:typeof r!="string"&&!t.objectMode&&(n=new Lh("chunk",["string","Buffer"],r)),n?(wt(e,n),process.nextTick(i,n),!1):!0}$.prototype.write=function(e,t,r){var i=this._writableState,n=!1,s=!i.objectMode&&Ah(e);return s&&!Dr.isBuffer(e)&&(e=Bh(e)),typeof t=="function"&&(r=t,t=null),s?t="buffer":t||(t=i.defaultEncoding),typeof r!="function"&&(r=Hh),i.ending?$h(this,r):(s||Gh(this,i,e,r))&&(i.pendingcb++,n=Kh(this,i,s,e,t,r)),n};$.prototype.cork=function(){this._writableState.corked++};$.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.bufferProcessing&&e.bufferedRequest&&Fo(this,e))};$.prototype.setDefaultEncoding=function(t){if(typeof t=="string"&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new Vh(t);return this._writableState.defaultEncoding=t,this};Object.defineProperty($.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function zh(e,t,r){return!e.objectMode&&e.decodeStrings!==!1&&typeof t=="string"&&(t=Dr.from(t,r)),t}Object.defineProperty($.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function Kh(e,t,r,i,n,s){if(!r){var o=zh(t,i,n);i!==o&&(r=!0,n="buffer",i=o)}var f=t.objectMode?1:i.length;t.length+=f;var a=t.length<t.highWaterMark;if(a||(t.needDrain=!0),t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:i,encoding:n,isBuf:r,callback:s,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else fn(e,t,!1,f,i,n,s);return a}function fn(e,t,r,i,n,s,o){t.writelen=i,t.writecb=o,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new jh("write")):r?e._writev(n,t.onwrite):e._write(n,s,t.onwrite),t.sync=!1}function Yh(e,t,r,i,n){--t.pendingcb,r?(process.nextTick(n,i),process.nextTick(Ut,e,t),e._writableState.errorEmitted=!0,wt(e,i)):(n(i),e._writableState.errorEmitted=!0,wt(e,i),Ut(e,t))}function Qh(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function Jh(e,t){var r=e._writableState,i=r.sync,n=r.writecb;if(typeof n!="function")throw new Dh;if(Qh(r),t)Yh(e,r,i,t,n);else{var s=Wo(r)||e.destroyed;!s&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest&&Fo(e,r),i?process.nextTick(Do,e,r,s,n):Do(e,r,s,n)}}function Do(e,t,r,i){r||Xh(e,t),t.pendingcb--,i(),Ut(e,t)}function Xh(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function Fo(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var i=t.bufferedRequestCount,n=new Array(i),s=t.corkedRequestsFree;s.entry=r;for(var o=0,f=!0;r;)n[o]=r,r.isBuf||(f=!1),r=r.next,o+=1;n.allBuffers=f,fn(e,t,!0,t.length,n,"",s.finish),t.pendingcb++,t.lastBufferedRequest=null,s.next?(t.corkedRequestsFree=s.next,s.next=null):t.corkedRequestsFree=new Uo(t),t.bufferedRequestCount=0}else{for(;r;){var a=r.chunk,l=r.encoding,u=r.callback,h=t.objectMode?1:a.length;if(fn(e,t,!1,h,a,l,u),r=r.next,t.bufferedRequestCount--,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}$.prototype._write=function(e,t,r){r(new qh("_write()"))};$.prototype._writev=null;$.prototype.end=function(e,t,r){var i=this._writableState;return typeof e=="function"?(r=e,e=null,t=null):typeof t=="function"&&(r=t,t=null),e!=null&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||td(this,i,r),this};Object.defineProperty($.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function Wo(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function Zh(e,t){e._final(function(r){t.pendingcb--,r&&wt(e,r),t.prefinished=!0,e.emit("prefinish"),Ut(e,t)})}function ed(e,t){!t.prefinished&&!t.finalCalled&&(typeof e._final=="function"&&!t.destroyed?(t.pendingcb++,t.finalCalled=!0,process.nextTick(Zh,e,t)):(t.prefinished=!0,e.emit("prefinish")))}function Ut(e,t){var r=Wo(t);if(r&&(ed(e,t),t.pendingcb===0&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var i=e._readableState;(!i||i.autoDestroy&&i.endEmitted)&&e.destroy()}return r}function td(e,t,r){t.ending=!0,Ut(e,t),r&&(t.finished?process.nextTick(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function rd(e,t,r){var i=e.entry;for(e.entry=null;i;){var n=i.callback;t.pendingcb--,n(r),i=i.next}t.corkedRequestsFree.next=e}Object.defineProperty($.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}});$.prototype.destroy=ln.destroy;$.prototype._undestroy=ln.undestroy;$.prototype._destroy=function(e,t){t(e)}});var it=b((jm,$o)=>{"use strict";var id=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};$o.exports=Ee;var Ho=dn(),hn=un();ie()(Ee,Ho);for(cn=id(hn.prototype),Ur=0;Ur<cn.length;Ur++)jr=cn[Ur],Ee.prototype[jr]||(Ee.prototype[jr]=hn.prototype[jr]);var cn,jr,Ur;function Ee(e){if(!(this instanceof Ee))return new Ee(e);Ho.call(this,e),hn.call(this,e),this.allowHalfOpen=!0,e&&(e.readable===!1&&(this.readable=!1),e.writable===!1&&(this.writable=!1),e.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",nd)))}Object.defineProperty(Ee.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});Object.defineProperty(Ee.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});Object.defineProperty(Ee.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function nd(){this._writableState.ended||process.nextTick(sd,this)}function sd(e){e.end()}Object.defineProperty(Ee.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(t){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=t,this._writableState.destroyed=t)}})});var Ko=b((pn,zo)=>{var Fr=require("buffer"),xe=Fr.Buffer;function Go(e,t){for(var r in e)t[r]=e[r]}xe.from&&xe.alloc&&xe.allocUnsafe&&xe.allocUnsafeSlow?zo.exports=Fr:(Go(Fr,pn),pn.Buffer=nt);function nt(e,t,r){return xe(e,t,r)}nt.prototype=Object.create(xe.prototype);Go(xe,nt);nt.from=function(e,t,r){if(typeof e=="number")throw new TypeError("Argument must not be a number");return xe(e,t,r)};nt.alloc=function(e,t,r){if(typeof e!="number")throw new TypeError("Argument must be a number");var i=xe(e);return t!==void 0?typeof r=="string"?i.fill(t,r):i.fill(t):i.fill(0),i};nt.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return xe(e)};nt.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return Fr.SlowBuffer(e)}});var bn=b(Qo=>{"use strict";var gn=Ko().Buffer,Yo=gn.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function od(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function ad(e){var t=od(e);if(typeof t!="string"&&(gn.isEncoding===Yo||!Yo(e)))throw new Error("Unknown encoding: "+e);return t||e}Qo.StringDecoder=Ft;function Ft(e){this.encoding=ad(e);var t;switch(this.encoding){case"utf16le":this.text=dd,this.end=pd,t=4;break;case"utf8":this.fillLast=ud,t=4;break;case"base64":this.text=_d,this.end=gd,t=3;break;default:this.write=bd,this.end=yd;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=gn.allocUnsafe(t)}Ft.prototype.write=function(e){if(e.length===0)return"";var t,r;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""};Ft.prototype.end=hd;Ft.prototype.text=cd;Ft.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function _n(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function fd(e,t,r){var i=t.length-1;if(i<r)return 0;var n=_n(t[i]);return n>=0?(n>0&&(e.lastNeed=n-1),n):--i<r||n===-2?0:(n=_n(t[i]),n>=0?(n>0&&(e.lastNeed=n-2),n):--i<r||n===-2?0:(n=_n(t[i]),n>=0?(n>0&&(n===2?n=0:e.lastNeed=n-3),n):0))}function ld(e,t,r){if((t[0]&192)!==128)return e.lastNeed=0,"\uFFFD";if(e.lastNeed>1&&t.length>1){if((t[1]&192)!==128)return e.lastNeed=1,"\uFFFD";if(e.lastNeed>2&&t.length>2&&(t[2]&192)!==128)return e.lastNeed=2,"\uFFFD"}}function ud(e){var t=this.lastTotal-this.lastNeed,r=ld(this,e,t);if(r!==void 0)return r;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function cd(e,t){var r=fd(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var i=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,i),e.toString("utf8",t,i)}function hd(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"\uFFFD":t}function dd(e,t){if((e.length-t)%2===0){var r=e.toString("utf16le",t);if(r){var i=r.charCodeAt(r.length-1);if(i>=55296&&i<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function pd(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function _d(e,t){var r=(e.length-t)%3;return r===0?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function gd(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function bd(e){return e.toString(this.encoding)}function yd(e){return e&&e.length?this.write(e):""}});var Wr=b((Wm,Zo)=>{"use strict";var Jo=Ue().codes.ERR_STREAM_PREMATURE_CLOSE;function vd(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,i=new Array(r),n=0;n<r;n++)i[n]=arguments[n];e.apply(this,i)}}}function md(){}function wd(e){return e.setHeader&&typeof e.abort=="function"}function Xo(e,t,r){if(typeof t=="function")return Xo(e,null,t);t||(t={}),r=vd(r||md);var i=t.readable||t.readable!==!1&&e.readable,n=t.writable||t.writable!==!1&&e.writable,s=function(){e.writable||f()},o=e._writableState&&e._writableState.finished,f=function(){n=!1,o=!0,i||r.call(e)},a=e._readableState&&e._readableState.endEmitted,l=function(){i=!1,a=!0,n||r.call(e)},u=function(_){r.call(e,_)},h=function(){var _;if(i&&!a)return(!e._readableState||!e._readableState.ended)&&(_=new Jo),r.call(e,_);if(n&&!o)return(!e._writableState||!e._writableState.ended)&&(_=new Jo),r.call(e,_)},c=function(){e.req.on("finish",f)};return wd(e)?(e.on("complete",f),e.on("abort",h),e.req?c():e.on("request",c)):n&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",l),e.on("finish",f),t.error!==!1&&e.on("error",u),e.on("close",h),function(){e.removeListener("complete",f),e.removeListener("abort",h),e.removeListener("request",c),e.req&&e.req.removeListener("finish",f),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",f),e.removeListener("end",l),e.removeListener("error",u),e.removeListener("close",h)}}Zo.exports=Xo});var ta=b((Vm,ea)=>{"use strict";var Vr;function Fe(e,t,r){return t=Sd(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Sd(e){var t=Ed(e,"string");return typeof t=="symbol"?t:String(t)}function Ed(e,t){if(typeof e!="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var xd=Wr(),We=Symbol("lastResolve"),st=Symbol("lastReject"),Wt=Symbol("error"),Hr=Symbol("ended"),ot=Symbol("lastPromise"),yn=Symbol("handlePromise"),at=Symbol("stream");function Ve(e,t){return{value:e,done:t}}function Cd(e){var t=e[We];if(t!==null){var r=e[at].read();r!==null&&(e[ot]=null,e[We]=null,e[st]=null,t(Ve(r,!1)))}}function Td(e){process.nextTick(Cd,e)}function Id(e,t){return function(r,i){e.then(function(){if(t[Hr]){r(Ve(void 0,!0));return}t[yn](r,i)},i)}}var Od=Object.getPrototypeOf(function(){}),kd=Object.setPrototypeOf((Vr={get stream(){return this[at]},next:function(){var t=this,r=this[Wt];if(r!==null)return Promise.reject(r);if(this[Hr])return Promise.resolve(Ve(void 0,!0));if(this[at].destroyed)return new Promise(function(o,f){process.nextTick(function(){t[Wt]?f(t[Wt]):o(Ve(void 0,!0))})});var i=this[ot],n;if(i)n=new Promise(Id(i,this));else{var s=this[at].read();if(s!==null)return Promise.resolve(Ve(s,!1));n=new Promise(this[yn])}return this[ot]=n,n}},Fe(Vr,Symbol.asyncIterator,function(){return this}),Fe(Vr,"return",function(){var t=this;return new Promise(function(r,i){t[at].destroy(null,function(n){if(n){i(n);return}r(Ve(void 0,!0))})})}),Vr),Od),Rd=function(t){var r,i=Object.create(kd,(r={},Fe(r,at,{value:t,writable:!0}),Fe(r,We,{value:null,writable:!0}),Fe(r,st,{value:null,writable:!0}),Fe(r,Wt,{value:null,writable:!0}),Fe(r,Hr,{value:t._readableState.endEmitted,writable:!0}),Fe(r,yn,{value:function(s,o){var f=i[at].read();f?(i[ot]=null,i[We]=null,i[st]=null,s(Ve(f,!1))):(i[We]=s,i[st]=o)},writable:!0}),r));return i[ot]=null,xd(t,function(n){if(n&&n.code!=="ERR_STREAM_PREMATURE_CLOSE"){var s=i[st];s!==null&&(i[ot]=null,i[We]=null,i[st]=null,s(n)),i[Wt]=n;return}var o=i[We];o!==null&&(i[ot]=null,i[We]=null,i[st]=null,o(Ve(void 0,!0))),i[Hr]=!0}),t.on("readable",Td.bind(null,i)),i};ea.exports=Rd});var sa=b((Hm,na)=>{"use strict";function ra(e,t,r,i,n,s,o){try{var f=e[s](o),a=f.value}catch(l){r(l);return}f.done?t(a):Promise.resolve(a).then(i,n)}function Pd(e){return function(){var t=this,r=arguments;return new Promise(function(i,n){var s=e.apply(t,r);function o(a){ra(s,i,n,o,f,"next",a)}function f(a){ra(s,i,n,o,f,"throw",a)}o(void 0)})}}function ia(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),r.push.apply(r,i)}return r}function Bd(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ia(Object(r),!0).forEach(function(i){Ad(e,i,r[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ia(Object(r)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(r,i))})}return e}function Ad(e,t,r){return t=Nd(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Nd(e){var t=Md(e,"string");return typeof t=="symbol"?t:String(t)}function Md(e,t){if(typeof e!="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var Ld=Ue().codes.ERR_INVALID_ARG_TYPE;function qd(e,t,r){var i;if(t&&typeof t.next=="function")i=t;else if(t&&t[Symbol.asyncIterator])i=t[Symbol.asyncIterator]();else if(t&&t[Symbol.iterator])i=t[Symbol.iterator]();else throw new Ld("iterable",["Iterable"],t);var n=new e(Bd({objectMode:!0},r)),s=!1;n._read=function(){s||(s=!0,o())};function o(){return f.apply(this,arguments)}function f(){return f=Pd(function*(){try{var a=yield i.next(),l=a.value,u=a.done;u?n.push(null):n.push(yield l)?o():s=!1}catch(h){n.destroy(h)}}),f.apply(this,arguments)}return n}na.exports=qd});var dn=b((Gm,_a)=>{"use strict";_a.exports=A;var St;A.ReadableState=la;var $m=require("events").EventEmitter,fa=function(t,r){return t.listeners(r).length},Ht=Xi(),$r=require("buffer").Buffer,Dd=(typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function Ud(e){return $r.from(e)}function jd(e){return $r.isBuffer(e)||e instanceof Dd}var vn=require("util"),P;vn&&vn.debuglog?P=vn.debuglog("stream"):P=function(){};var Fd=ko(),Tn=tn(),Wd=rn(),Vd=Wd.getHighWaterMark,Gr=Ue().codes,Hd=Gr.ERR_INVALID_ARG_TYPE,$d=Gr.ERR_STREAM_PUSH_AFTER_EOF,Gd=Gr.ERR_METHOD_NOT_IMPLEMENTED,zd=Gr.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,Et,mn,wn;ie()(A,Ht);var Vt=Tn.errorOrDestroy,Sn=["error","close","destroy","pause","resume"];function Kd(e,t,r){if(typeof e.prependListener=="function")return e.prependListener(t,r);!e._events||!e._events[t]?e.on(t,r):Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]}function la(e,t,r){St=St||it(),e=e||{},typeof r!="boolean"&&(r=t instanceof St),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=Vd(this,e,"readableHighWaterMark",r),this.buffer=new Fd,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=e.emitClose!==!1,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(Et||(Et=bn().StringDecoder),this.decoder=new Et(e.encoding),this.encoding=e.encoding)}function A(e){if(St=St||it(),!(this instanceof A))return new A(e);var t=this instanceof St;this._readableState=new la(e,this,t),this.readable=!0,e&&(typeof e.read=="function"&&(this._read=e.read),typeof e.destroy=="function"&&(this._destroy=e.destroy)),Ht.call(this)}Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(t){this._readableState&&(this._readableState.destroyed=t)}});A.prototype.destroy=Tn.destroy;A.prototype._undestroy=Tn.undestroy;A.prototype._destroy=function(e,t){t(e)};A.prototype.push=function(e,t){var r=this._readableState,i;return r.objectMode?i=!0:typeof e=="string"&&(t=t||r.defaultEncoding,t!==r.encoding&&(e=$r.from(e,t),t=""),i=!0),ua(this,e,t,!1,i)};A.prototype.unshift=function(e){return ua(this,e,null,!0,!1)};function ua(e,t,r,i,n){P("readableAddChunk",t);var s=e._readableState;if(t===null)s.reading=!1,Jd(e,s);else{var o;if(n||(o=Yd(s,t)),o)Vt(e,o);else if(s.objectMode||t&&t.length>0)if(typeof t!="string"&&!s.objectMode&&Object.getPrototypeOf(t)!==$r.prototype&&(t=Ud(t)),i)s.endEmitted?Vt(e,new zd):En(e,s,t,!0);else if(s.ended)Vt(e,new $d);else{if(s.destroyed)return!1;s.reading=!1,s.decoder&&!r?(t=s.decoder.write(t),s.objectMode||t.length!==0?En(e,s,t,!1):Cn(e,s)):En(e,s,t,!1)}else i||(s.reading=!1,Cn(e,s))}return!s.ended&&(s.length<s.highWaterMark||s.length===0)}function En(e,t,r,i){t.flowing&&t.length===0&&!t.sync?(t.awaitDrain=0,e.emit("data",r)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&zr(e)),Cn(e,t)}function Yd(e,t){var r;return!jd(t)&&typeof t!="string"&&t!==void 0&&!e.objectMode&&(r=new Hd("chunk",["string","Buffer","Uint8Array"],t)),r}A.prototype.isPaused=function(){return this._readableState.flowing===!1};A.prototype.setEncoding=function(e){Et||(Et=bn().StringDecoder);var t=new Et(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var r=this._readableState.buffer.head,i="";r!==null;)i+=t.write(r.data),r=r.next;return this._readableState.buffer.clear(),i!==""&&this._readableState.buffer.push(i),this._readableState.length=i.length,this};var oa=1073741824;function Qd(e){return e>=oa?e=oa:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function aa(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=Qd(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}A.prototype.read=function(e){P("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&((t.highWaterMark!==0?t.length>=t.highWaterMark:t.length>0)||t.ended))return P("read: emitReadable",t.length,t.ended),t.length===0&&t.ended?xn(this):zr(this),null;if(e=aa(e,t),e===0&&t.ended)return t.length===0&&xn(this),null;var i=t.needReadable;P("need readable",i),(t.length===0||t.length-e<t.highWaterMark)&&(i=!0,P("length less than watermark",i)),t.ended||t.reading?(i=!1,P("reading or ended",i)):i&&(P("do read"),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=aa(r,t)));var n;return e>0?n=da(e,t):n=null,n===null?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),t.length===0&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&xn(this)),n!==null&&this.emit("data",n),n};function Jd(e,t){if(P("onEofChunk"),!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,t.sync?zr(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,ca(e)))}}function zr(e){var t=e._readableState;P("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(P("emitReadable",t.flowing),t.emittedReadable=!0,process.nextTick(ca,e))}function ca(e){var t=e._readableState;P("emitReadable_",t.destroyed,t.length,t.ended),!t.destroyed&&(t.length||t.ended)&&(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,In(e)}function Cn(e,t){t.readingMore||(t.readingMore=!0,process.nextTick(Xd,e,t))}function Xd(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&t.length===0);){var r=t.length;if(P("maybeReadMore read 0"),e.read(0),r===t.length)break}t.readingMore=!1}A.prototype._read=function(e){Vt(this,new Gd("_read()"))};A.prototype.pipe=function(e,t){var r=this,i=this._readableState;switch(i.pipesCount){case 0:i.pipes=e;break;case 1:i.pipes=[i.pipes,e];break;default:i.pipes.push(e);break}i.pipesCount+=1,P("pipe count=%d opts=%j",i.pipesCount,t);var n=(!t||t.end!==!1)&&e!==process.stdout&&e!==process.stderr,s=n?f:v;i.endEmitted?process.nextTick(s):r.once("end",s),e.on("unpipe",o);function o(m,p){P("onunpipe"),m===r&&p&&p.hasUnpiped===!1&&(p.hasUnpiped=!0,u())}function f(){P("onend"),e.end()}var a=Zd(r);e.on("drain",a);var l=!1;function u(){P("cleanup"),e.removeListener("close",d),e.removeListener("finish",_),e.removeListener("drain",a),e.removeListener("error",c),e.removeListener("unpipe",o),r.removeListener("end",f),r.removeListener("end",v),r.removeListener("data",h),l=!0,i.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&a()}r.on("data",h);function h(m){P("ondata");var p=e.write(m);P("dest.write",p),p===!1&&((i.pipesCount===1&&i.pipes===e||i.pipesCount>1&&pa(i.pipes,e)!==-1)&&!l&&(P("false write response, pause",i.awaitDrain),i.awaitDrain++),r.pause())}function c(m){P("onerror",m),v(),e.removeListener("error",c),fa(e,"error")===0&&Vt(e,m)}Kd(e,"error",c);function d(){e.removeListener("finish",_),v()}e.once("close",d);function _(){P("onfinish"),e.removeListener("close",d),v()}e.once("finish",_);function v(){P("unpipe"),r.unpipe(e)}return e.emit("pipe",r),i.flowing||(P("pipe resume"),r.resume()),e};function Zd(e){return function(){var r=e._readableState;P("pipeOnDrain",r.awaitDrain),r.awaitDrain&&r.awaitDrain--,r.awaitDrain===0&&fa(e,"data")&&(r.flowing=!0,In(e))}}A.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r),this);if(!e){var i=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var s=0;s<n;s++)i[s].emit("unpipe",this,{hasUnpiped:!1});return this}var o=pa(t.pipes,e);return o===-1?this:(t.pipes.splice(o,1),t.pipesCount-=1,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,r),this)};A.prototype.on=function(e,t){var r=Ht.prototype.on.call(this,e,t),i=this._readableState;return e==="data"?(i.readableListening=this.listenerCount("readable")>0,i.flowing!==!1&&this.resume()):e==="readable"&&!i.endEmitted&&!i.readableListening&&(i.readableListening=i.needReadable=!0,i.flowing=!1,i.emittedReadable=!1,P("on readable",i.length,i.reading),i.length?zr(this):i.reading||process.nextTick(ep,this)),r};A.prototype.addListener=A.prototype.on;A.prototype.removeListener=function(e,t){var r=Ht.prototype.removeListener.call(this,e,t);return e==="readable"&&process.nextTick(ha,this),r};A.prototype.removeAllListeners=function(e){var t=Ht.prototype.removeAllListeners.apply(this,arguments);return(e==="readable"||e===void 0)&&process.nextTick(ha,this),t};function ha(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function ep(e){P("readable nexttick read 0"),e.read(0)}A.prototype.resume=function(){var e=this._readableState;return e.flowing||(P("resume"),e.flowing=!e.readableListening,tp(this,e)),e.paused=!1,this};function tp(e,t){t.resumeScheduled||(t.resumeScheduled=!0,process.nextTick(rp,e,t))}function rp(e,t){P("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),In(e),t.flowing&&!t.reading&&e.read(0)}A.prototype.pause=function(){return P("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(P("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function In(e){var t=e._readableState;for(P("flow",t.flowing);t.flowing&&e.read()!==null;);}A.prototype.wrap=function(e){var t=this,r=this._readableState,i=!1;e.on("end",function(){if(P("wrapped end"),r.decoder&&!r.ended){var o=r.decoder.end();o&&o.length&&t.push(o)}t.push(null)}),e.on("data",function(o){if(P("wrapped data"),r.decoder&&(o=r.decoder.write(o)),!(r.objectMode&&o==null)&&!(!r.objectMode&&(!o||!o.length))){var f=t.push(o);f||(i=!0,e.pause())}});for(var n in e)this[n]===void 0&&typeof e[n]=="function"&&(this[n]=function(f){return function(){return e[f].apply(e,arguments)}}(n));for(var s=0;s<Sn.length;s++)e.on(Sn[s],this.emit.bind(this,Sn[s]));return this._read=function(o){P("wrapped _read",o),i&&(i=!1,e.resume())},this};typeof Symbol=="function"&&(A.prototype[Symbol.asyncIterator]=function(){return mn===void 0&&(mn=ta()),mn(this)});Object.defineProperty(A.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}});Object.defineProperty(A.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}});Object.defineProperty(A.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(t){this._readableState&&(this._readableState.flowing=t)}});A._fromList=da;Object.defineProperty(A.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function da(e,t){if(t.length===0)return null;var r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(t.decoder?r=t.buffer.join(""):t.buffer.length===1?r=t.buffer.first():r=t.buffer.concat(t.length),t.buffer.clear()):r=t.buffer.consume(e,t.decoder),r}function xn(e){var t=e._readableState;P("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,process.nextTick(ip,t,e))}function ip(e,t){if(P("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var r=t._writableState;(!r||r.autoDestroy&&r.finished)&&t.destroy()}}typeof Symbol=="function"&&(A.from=function(e,t){return wn===void 0&&(wn=sa()),wn(A,e,t)});function pa(e,t){for(var r=0,i=e.length;r<i;r++)if(e[r]===t)return r;return-1}});var On=b((zm,ba)=>{"use strict";ba.exports=ke;var Kr=Ue().codes,np=Kr.ERR_METHOD_NOT_IMPLEMENTED,sp=Kr.ERR_MULTIPLE_CALLBACK,op=Kr.ERR_TRANSFORM_ALREADY_TRANSFORMING,ap=Kr.ERR_TRANSFORM_WITH_LENGTH_0,Yr=it();ie()(ke,Yr);function fp(e,t){var r=this._transformState;r.transforming=!1;var i=r.writecb;if(i===null)return this.emit("error",new sp);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),i(e);var n=this._readableState;n.reading=!1,(n.needReadable||n.length<n.highWaterMark)&&this._read(n.highWaterMark)}function ke(e){if(!(this instanceof ke))return new ke(e);Yr.call(this,e),this._transformState={afterTransform:fp.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.on("prefinish",lp)}function lp(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){ga(e,t,r)}):ga(this,null,null)}ke.prototype.push=function(e,t){return this._transformState.needTransform=!1,Yr.prototype.push.call(this,e,t)};ke.prototype._transform=function(e,t,r){r(new np("_transform()"))};ke.prototype._write=function(e,t,r){var i=this._transformState;if(i.writecb=r,i.writechunk=e,i.writeencoding=t,!i.transforming){var n=this._readableState;(i.needTransform||n.needReadable||n.length<n.highWaterMark)&&this._read(n.highWaterMark)}};ke.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};ke.prototype._destroy=function(e,t){Yr.prototype._destroy.call(this,e,function(r){t(r)})};function ga(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new ap;if(e._transformState.transforming)throw new op;return e.push(null)}});var ma=b((Km,va)=>{"use strict";va.exports=$t;var ya=On();ie()($t,ya);function $t(e){if(!(this instanceof $t))return new $t(e);ya.call(this,e)}$t.prototype._transform=function(e,t,r){r(null,e)}});var Ca=b((Ym,xa)=>{"use strict";var kn;function up(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var Ea=Ue().codes,cp=Ea.ERR_MISSING_ARGS,hp=Ea.ERR_STREAM_DESTROYED;function wa(e){if(e)throw e}function dp(e){return e.setHeader&&typeof e.abort=="function"}function pp(e,t,r,i){i=up(i);var n=!1;e.on("close",function(){n=!0}),kn===void 0&&(kn=Wr()),kn(e,{readable:t,writable:r},function(o){if(o)return i(o);n=!0,i()});var s=!1;return function(o){if(!n&&!s){if(s=!0,dp(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();i(o||new hp("pipe"))}}}function Sa(e){e()}function _p(e,t){return e.pipe(t)}function gp(e){return!e.length||typeof e[e.length-1]!="function"?wa:e.pop()}function bp(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var i=gp(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new cp("streams");var n,s=t.map(function(o,f){var a=f<t.length-1,l=f>0;return pp(o,a,l,function(u){n||(n=u),u&&s.forEach(Sa),!a&&(s.forEach(Sa),i(n))})});return t.reduce(_p)}xa.exports=bp});var He=b((de,zt)=>{var Gt=require("stream");process.env.READABLE_STREAM==="disable"&&Gt?(zt.exports=Gt.Readable,Object.assign(zt.exports,Gt),zt.exports.Stream=Gt):(de=zt.exports=dn(),de.Stream=Gt||de,de.Readable=de,de.Writable=un(),de.Duplex=it(),de.Transform=On(),de.PassThrough=ma(),de.finished=Wr(),de.pipeline=Ca())});var Qr=b((Qm,Ta)=>{"use strict";var yp=Nr(),vp=He().Readable,mp={objectMode:!0},wp={clean:!0};function $e(e){if(!(this instanceof $e))return new $e(e);this.options=e||{},this.options=yp(wp,e),this._inflights=new Map}$e.prototype.put=function(e,t){return this._inflights.set(e.messageId,e),t&&t(),this};$e.prototype.createStream=function(){var e=new vp(mp),t=!1,r=[],i=0;return this._inflights.forEach(function(n,s){r.push(n)}),e._read=function(){!t&&i<r.length?this.push(r[i++]):this.push(null)},e.destroy=function(){if(!t){var n=this;t=!0,setTimeout(function(){n.emit("close")},0)}},e};$e.prototype.del=function(e,t){return e=this._inflights.get(e.messageId),e?(this._inflights.delete(e.messageId),t(null,e)):t&&t(new Error("missing packet")),this};$e.prototype.get=function(e,t){return e=this._inflights.get(e.messageId),e?t(null,e):t&&t(new Error("missing packet")),this};$e.prototype.close=function(e){this.options.clean&&(this._inflights=null),e&&e()};Ta.exports=$e});var ka=b((Jm,Oa)=>{"use strict";var{Buffer:me}=require("buffer"),Ia=Symbol.for("BufferList");function W(e){if(!(this instanceof W))return new W(e);W._init.call(this,e)}W._init=function(t){Object.defineProperty(this,Ia,{value:!0}),this._bufs=[],this.length=0,t&&this.append(t)};W.prototype._new=function(t){return new W(t)};W.prototype._offset=function(t){if(t===0)return[0,0];let r=0;for(let i=0;i<this._bufs.length;i++){let n=r+this._bufs[i].length;if(t<n||i===this._bufs.length-1)return[i,t-r];r=n}};W.prototype._reverseOffset=function(e){let t=e[0],r=e[1];for(let i=0;i<t;i++)r+=this._bufs[i].length;return r};W.prototype.get=function(t){if(t>this.length||t<0)return;let r=this._offset(t);return this._bufs[r[0]][r[1]]};W.prototype.slice=function(t,r){return typeof t=="number"&&t<0&&(t+=this.length),typeof r=="number"&&r<0&&(r+=this.length),this.copy(null,0,t,r)};W.prototype.copy=function(t,r,i,n){if((typeof i!="number"||i<0)&&(i=0),(typeof n!="number"||n>this.length)&&(n=this.length),i>=this.length||n<=0)return t||me.alloc(0);let s=!!t,o=this._offset(i),f=n-i,a=f,l=s&&r||0,u=o[1];if(i===0&&n===this.length){if(!s)return this._bufs.length===1?this._bufs[0]:me.concat(this._bufs,this.length);for(let h=0;h<this._bufs.length;h++)this._bufs[h].copy(t,l),l+=this._bufs[h].length;return t}if(a<=this._bufs[o[0]].length-u)return s?this._bufs[o[0]].copy(t,r,u,u+a):this._bufs[o[0]].slice(u,u+a);s||(t=me.allocUnsafe(f));for(let h=o[0];h<this._bufs.length;h++){let c=this._bufs[h].length-u;if(a>c)this._bufs[h].copy(t,l,u),l+=c;else{this._bufs[h].copy(t,l,u,u+a),l+=c;break}a-=c,u&&(u=0)}return t.length>l?t.slice(0,l):t};W.prototype.shallowSlice=function(t,r){if(t=t||0,r=typeof r!="number"?this.length:r,t<0&&(t+=this.length),r<0&&(r+=this.length),t===r)return this._new();let i=this._offset(t),n=this._offset(r),s=this._bufs.slice(i[0],n[0]+1);return n[1]===0?s.pop():s[s.length-1]=s[s.length-1].slice(0,n[1]),i[1]!==0&&(s[0]=s[0].slice(i[1])),this._new(s)};W.prototype.toString=function(t,r,i){return this.slice(r,i).toString(t)};W.prototype.consume=function(t){if(t=Math.trunc(t),Number.isNaN(t)||t<=0)return this;for(;this._bufs.length;)if(t>=this._bufs[0].length)t-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift();else{this._bufs[0]=this._bufs[0].slice(t),this.length-=t;break}return this};W.prototype.duplicate=function(){let t=this._new();for(let r=0;r<this._bufs.length;r++)t.append(this._bufs[r]);return t};W.prototype.append=function(t){if(t==null)return this;if(t.buffer)this._appendBuffer(me.from(t.buffer,t.byteOffset,t.byteLength));else if(Array.isArray(t))for(let r=0;r<t.length;r++)this.append(t[r]);else if(this._isBufferList(t))for(let r=0;r<t._bufs.length;r++)this.append(t._bufs[r]);else typeof t=="number"&&(t=t.toString()),this._appendBuffer(me.from(t));return this};W.prototype._appendBuffer=function(t){this._bufs.push(t),this.length+=t.length};W.prototype.indexOf=function(e,t,r){if(r===void 0&&typeof t=="string"&&(r=t,t=void 0),typeof e=="function"||Array.isArray(e))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if(typeof e=="number"?e=me.from([e]):typeof e=="string"?e=me.from(e,r):this._isBufferList(e)?e=e.slice():Array.isArray(e.buffer)?e=me.from(e.buffer,e.byteOffset,e.byteLength):me.isBuffer(e)||(e=me.from(e)),t=Number(t||0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let i=this._offset(t),n=i[0],s=i[1];for(;n<this._bufs.length;n++){let o=this._bufs[n];for(;s<o.length;)if(o.length-s>=e.length){let a=o.indexOf(e,s);if(a!==-1)return this._reverseOffset([n,a]);s=o.length-e.length+1}else{let a=this._reverseOffset([n,s]);if(this._match(a,e))return a;s++}s=0}return-1};W.prototype._match=function(e,t){if(this.length-e<t.length)return!1;for(let r=0;r<t.length;r++)if(this.get(e+r)!==t[r])return!1;return!0};(function(){let e={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(let t in e)(function(r){e[r]===null?W.prototype[r]=function(i,n){return this.slice(i,i+n)[r](0,n)}:W.prototype[r]=function(i=0){return this.slice(i,i+e[r])[r](0)}})(t)})();W.prototype._isBufferList=function(t){return t instanceof W||W.isBufferList(t)};W.isBufferList=function(t){return t!=null&&t[Ia]};Oa.exports=W});var Ra=b((Xm,Jr)=>{"use strict";var Rn=He().Duplex,Sp=ie(),Kt=ka();function ee(e){if(!(this instanceof ee))return new ee(e);if(typeof e=="function"){this._callback=e;let t=function(i){this._callback&&(this._callback(i),this._callback=null)}.bind(this);this.on("pipe",function(i){i.on("error",t)}),this.on("unpipe",function(i){i.removeListener("error",t)}),e=null}Kt._init.call(this,e),Rn.call(this)}Sp(ee,Rn);Object.assign(ee.prototype,Kt.prototype);ee.prototype._new=function(t){return new ee(t)};ee.prototype._write=function(t,r,i){this._appendBuffer(t),typeof i=="function"&&i()};ee.prototype._read=function(t){if(!this.length)return this.push(null);t=Math.min(t,this.length),this.push(this.slice(0,t)),this.consume(t)};ee.prototype.end=function(t){Rn.prototype.end.call(this,t),this._callback&&(this._callback(null,this.slice()),this._callback=null)};ee.prototype._destroy=function(t,r){this._bufs.length=0,this.length=0,r(t)};ee.prototype._isBufferList=function(t){return t instanceof ee||t instanceof Kt||ee.isBufferList(t)};ee.isBufferList=Kt.isBufferList;Jr.exports=ee;Jr.exports.BufferListStream=ee;Jr.exports.BufferList=Kt});var Ba=b((Zm,Pa)=>{var Pn=class{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}};Pa.exports=Pn});var Bn=b((ew,Aa)=>{var E=Aa.exports;E.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"};E.codes={};for(let e in E.types){let t=E.types[e];E.codes[t]=e}E.CMD_SHIFT=4;E.CMD_MASK=240;E.DUP_MASK=8;E.QOS_MASK=3;E.QOS_SHIFT=1;E.RETAIN_MASK=1;E.VARBYTEINT_MASK=127;E.VARBYTEINT_FIN_MASK=128;E.VARBYTEINT_MAX=268435455;E.SESSIONPRESENT_MASK=1;E.SESSIONPRESENT_HEADER=Buffer.from([E.SESSIONPRESENT_MASK]);E.CONNACK_HEADER=Buffer.from([E.codes.connack<<E.CMD_SHIFT]);E.USERNAME_MASK=128;E.PASSWORD_MASK=64;E.WILL_RETAIN_MASK=32;E.WILL_QOS_MASK=24;E.WILL_QOS_SHIFT=3;E.WILL_FLAG_MASK=4;E.CLEAN_SESSION_MASK=2;E.CONNECT_HEADER=Buffer.from([E.codes.connect<<E.CMD_SHIFT]);E.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11};E.propertiesCodes={};for(let e in E.properties){let t=E.properties[e];E.propertiesCodes[t]=e}E.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"};function Ge(e){return[0,1,2].map(t=>[0,1].map(r=>[0,1].map(i=>{let n=Buffer.alloc(1);return n.writeUInt8(E.codes[e]<<E.CMD_SHIFT|(r?E.DUP_MASK:0)|t<<E.QOS_SHIFT|i,0,!0),n})))}E.PUBLISH_HEADER=Ge("publish");E.SUBSCRIBE_HEADER=Ge("subscribe");E.SUBSCRIBE_OPTIONS_QOS_MASK=3;E.SUBSCRIBE_OPTIONS_NL_MASK=1;E.SUBSCRIBE_OPTIONS_NL_SHIFT=2;E.SUBSCRIBE_OPTIONS_RAP_MASK=1;E.SUBSCRIBE_OPTIONS_RAP_SHIFT=3;E.SUBSCRIBE_OPTIONS_RH_MASK=3;E.SUBSCRIBE_OPTIONS_RH_SHIFT=4;E.SUBSCRIBE_OPTIONS_RH=[0,16,32];E.SUBSCRIBE_OPTIONS_NL=4;E.SUBSCRIBE_OPTIONS_RAP=8;E.SUBSCRIBE_OPTIONS_QOS=[0,1,2];E.UNSUBSCRIBE_HEADER=Ge("unsubscribe");E.ACKS={unsuback:Ge("unsuback"),puback:Ge("puback"),pubcomp:Ge("pubcomp"),pubrel:Ge("pubrel"),pubrec:Ge("pubrec")};E.SUBACK_HEADER=Buffer.from([E.codes.suback<<E.CMD_SHIFT]);E.VERSION3=Buffer.from([3]);E.VERSION4=Buffer.from([4]);E.VERSION5=Buffer.from([5]);E.VERSION131=Buffer.from([131]);E.VERSION132=Buffer.from([132]);E.QOS=[0,1,2].map(e=>Buffer.from([e]));E.EMPTY={pingreq:Buffer.from([E.codes.pingreq<<4,0]),pingresp:Buffer.from([E.codes.pingresp<<4,0]),disconnect:Buffer.from([E.codes.disconnect<<4,0])}});var Ma=b((tw,Na)=>{var xt=1e3,Ct=xt*60,Tt=Ct*60,ft=Tt*24,Ep=ft*7,xp=ft*365.25;Na.exports=function(e,t){t=t||{};var r=typeof e;if(r==="string"&&e.length>0)return Cp(e);if(r==="number"&&isFinite(e))return t.long?Ip(e):Tp(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Cp(e){if(e=String(e),!(e.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]),i=(t[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return r*xp;case"weeks":case"week":case"w":return r*Ep;case"days":case"day":case"d":return r*ft;case"hours":case"hour":case"hrs":case"hr":case"h":return r*Tt;case"minutes":case"minute":case"mins":case"min":case"m":return r*Ct;case"seconds":case"second":case"secs":case"sec":case"s":return r*xt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function Tp(e){var t=Math.abs(e);return t>=ft?Math.round(e/ft)+"d":t>=Tt?Math.round(e/Tt)+"h":t>=Ct?Math.round(e/Ct)+"m":t>=xt?Math.round(e/xt)+"s":e+"ms"}function Ip(e){var t=Math.abs(e);return t>=ft?Xr(e,t,ft,"day"):t>=Tt?Xr(e,t,Tt,"hour"):t>=Ct?Xr(e,t,Ct,"minute"):t>=xt?Xr(e,t,xt,"second"):e+" ms"}function Xr(e,t,r,i){var n=t>=r*1.5;return Math.round(e/r)+" "+i+(n?"s":"")}});var An=b((rw,La)=>{function Op(e){r.debug=r,r.default=r,r.coerce=a,r.disable=s,r.enable=n,r.enabled=o,r.humanize=Ma(),r.destroy=l,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let h=0;for(let c=0;c<u.length;c++)h=(h<<5)-h+u.charCodeAt(c),h|=0;return r.colors[Math.abs(h)%r.colors.length]}r.selectColor=t;function r(u){let h,c=null,d,_;function v(...m){if(!v.enabled)return;let p=v,g=Number(new Date),S=g-(h||g);p.diff=S,p.prev=h,p.curr=g,h=g,m[0]=r.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let x=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(w,B)=>{if(w==="%%")return"%";x++;let M=r.formatters[B];if(typeof M=="function"){let H=m[x];w=M.call(p,H),m.splice(x,1),x--}return w}),r.formatArgs.call(p,m),(p.log||r.log).apply(p,m)}return v.namespace=u,v.useColors=r.useColors(),v.color=r.selectColor(u),v.extend=i,v.destroy=r.destroy,Object.defineProperty(v,"enabled",{enumerable:!0,configurable:!1,get:()=>c!==null?c:(d!==r.namespaces&&(d=r.namespaces,_=r.enabled(u)),_),set:m=>{c=m}}),typeof r.init=="function"&&r.init(v),v}function i(u,h){let c=r(this.namespace+(typeof h>"u"?":":h)+u);return c.log=this.log,c}function n(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let h,c=(typeof u=="string"?u:"").split(/[\s,]+/),d=c.length;for(h=0;h<d;h++)c[h]&&(u=c[h].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.slice(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function s(){let u=[...r.names.map(f),...r.skips.map(f).map(h=>"-"+h)].join(",");return r.enable(""),u}function o(u){if(u[u.length-1]==="*")return!0;let h,c;for(h=0,c=r.skips.length;h<c;h++)if(r.skips[h].test(u))return!1;for(h=0,c=r.names.length;h<c;h++)if(r.names[h].test(u))return!0;return!1}function f(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function a(u){return u instanceof Error?u.stack||u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}La.exports=Op});var qa=b((fe,Zr)=>{fe.formatArgs=Rp;fe.save=Pp;fe.load=Bp;fe.useColors=kp;fe.storage=Ap();fe.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();fe.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function kp(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Rp(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Zr.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,i=0;e[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(r++,n==="%c"&&(i=r))}),e.splice(i,0,t)}fe.log=console.debug||console.log||(()=>{});function Pp(e){try{e?fe.storage.setItem("debug",e):fe.storage.removeItem("debug")}catch{}}function Bp(){let e;try{e=fe.storage.getItem("debug")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function Ap(){try{return localStorage}catch{}}Zr.exports=An()(fe);var{formatters:Np}=Zr.exports;Np.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var Ua=b((iw,Da)=>{"use strict";Da.exports=(e,t=process.argv)=>{let r=e.startsWith("-")?"":e.length===1?"-":"--",i=t.indexOf(r+e),n=t.indexOf("--");return i!==-1&&(n===-1||i<n)}});var Wa=b((nw,Fa)=>{"use strict";var Mp=require("os"),ja=require("tty"),pe=Ua(),{env:Y}=process,ei;pe("no-color")||pe("no-colors")||pe("color=false")||pe("color=never")?ei=0:(pe("color")||pe("colors")||pe("color=true")||pe("color=always"))&&(ei=1);function Lp(){if("FORCE_COLOR"in Y)return Y.FORCE_COLOR==="true"?1:Y.FORCE_COLOR==="false"?0:Y.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(Y.FORCE_COLOR,10),3)}function qp(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function Dp(e,{streamIsTTY:t,sniffFlags:r=!0}={}){let i=Lp();i!==void 0&&(ei=i);let n=r?ei:i;if(n===0)return 0;if(r){if(pe("color=16m")||pe("color=full")||pe("color=truecolor"))return 3;if(pe("color=256"))return 2}if(e&&!t&&n===void 0)return 0;let s=n||0;if(Y.TERM==="dumb")return s;if(process.platform==="win32"){let o=Mp.release().split(".");return Number(o[0])>=10&&Number(o[2])>=10586?Number(o[2])>=14931?3:2:1}if("CI"in Y)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE","DRONE"].some(o=>o in Y)||Y.CI_NAME==="codeship"?1:s;if("TEAMCITY_VERSION"in Y)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(Y.TEAMCITY_VERSION)?1:0;if(Y.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in Y){let o=Number.parseInt((Y.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(Y.TERM_PROGRAM){case"iTerm.app":return o>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(Y.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(Y.TERM)||"COLORTERM"in Y?1:s}function Nn(e,t={}){let r=Dp(e,{streamIsTTY:e&&e.isTTY,...t});return qp(r)}Fa.exports={supportsColor:Nn,stdout:Nn({isTTY:ja.isatty(1)}),stderr:Nn({isTTY:ja.isatty(2)})}});var Ha=b((Q,ri)=>{var Up=require("tty"),ti=require("util");Q.init=Gp;Q.log=Vp;Q.formatArgs=Fp;Q.save=Hp;Q.load=$p;Q.useColors=jp;Q.destroy=ti.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");Q.colors=[6,2,3,4,5,1];try{let e=Wa();e&&(e.stderr||e).level>=2&&(Q.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}Q.inspectOpts=Object.keys(process.env).filter(e=>/^debug_/i.test(e)).reduce((e,t)=>{let r=t.substring(6).toLowerCase().replace(/_([a-z])/g,(n,s)=>s.toUpperCase()),i=process.env[t];return/^(yes|on|true|enabled)$/i.test(i)?i=!0:/^(no|off|false|disabled)$/i.test(i)?i=!1:i==="null"?i=null:i=Number(i),e[r]=i,e},{});function jp(){return"colors"in Q.inspectOpts?!!Q.inspectOpts.colors:Up.isatty(process.stderr.fd)}function Fp(e){let{namespace:t,useColors:r}=this;if(r){let i=this.color,n="\x1B[3"+(i<8?i:"8;5;"+i),s=` ${n};1m${t} \x1B[0m`;e[0]=s+e[0].split(`
`).join(`
`+s),e.push(n+"m+"+ri.exports.humanize(this.diff)+"\x1B[0m")}else e[0]=Wp()+t+" "+e[0]}function Wp(){return Q.inspectOpts.hideDate?"":new Date().toISOString()+" "}function Vp(...e){return process.stderr.write(ti.format(...e)+`
`)}function Hp(e){e?process.env.DEBUG=e:delete process.env.DEBUG}function $p(){return process.env.DEBUG}function Gp(e){e.inspectOpts={};let t=Object.keys(Q.inspectOpts);for(let r=0;r<t.length;r++)e.inspectOpts[t[r]]=Q.inspectOpts[t[r]]}ri.exports=An()(Q);var{formatters:Va}=ri.exports;Va.o=function(e){return this.inspectOpts.colors=this.useColors,ti.inspect(e,this.inspectOpts).split(`
`).map(t=>t.trim()).join(" ")};Va.O=function(e){return this.inspectOpts.colors=this.useColors,ti.inspect(e,this.inspectOpts)}});var ze=b((sw,Mn)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?Mn.exports=qa():Mn.exports=Ha()});var za=b((ow,Ga)=>{var zp=Ra(),Kp=require("events"),$a=Ba(),j=Bn(),I=ze()("mqtt-packet:parser"),Ln=class e extends Kp{constructor(){super(),this.parser=this.constructor.parser}static parser(t){return this instanceof e?(this.settings=t||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):new e().parser(t)}_resetState(){I("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new $a,this.error=null,this._list=zp(),this._stateCounter=0}parse(t){for(this.error&&this._resetState(),this._list.append(t),I("parse: current state: %s",this._states[this._stateCounter]);(this.packet.length!==-1||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,I("parse: state complete. _stateCounter is now: %d",this._stateCounter),I("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return I("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){let t=this._list.readUInt8(0);return this.packet.cmd=j.types[t>>j.CMD_SHIFT],this.packet.retain=(t&j.RETAIN_MASK)!==0,this.packet.qos=t>>j.QOS_SHIFT&j.QOS_MASK,this.packet.dup=(t&j.DUP_MASK)!==0,I("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){let t=this._parseVarByteNum(!0);return t&&(this.packet.length=t.value,this._list.consume(t.bytes)),I("_parseLength %d",t.value),!!t}_parsePayload(){I("_parsePayload: payload %O",this._list);let t=!1;if(this.packet.length===0||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseConfirmation();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":break;case"disconnect":this._parseDisconnect();break;case"auth":this._parseAuth();break;default:this._emitError(new Error("Not supported"))}t=!0}return I("_parsePayload complete result: %s",t),t}_parseConnect(){I("_parseConnect");let t,r,i,n,s={},o=this.packet,f=this._parseString();if(f===null)return this._emitError(new Error("Cannot parse protocolId"));if(f!=="MQTT"&&f!=="MQIsdp")return this._emitError(new Error("Invalid protocolId"));if(o.protocolId=f,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(o.protocolVersion=this._list.readUInt8(this._pos),o.protocolVersion>=128&&(o.bridgeMode=!0,o.protocolVersion=o.protocolVersion-128),o.protocolVersion!==3&&o.protocolVersion!==4&&o.protocolVersion!==5)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(s.username=this._list.readUInt8(this._pos)&j.USERNAME_MASK,s.password=this._list.readUInt8(this._pos)&j.PASSWORD_MASK,s.will=this._list.readUInt8(this._pos)&j.WILL_FLAG_MASK,s.will&&(o.will={},o.will.retain=(this._list.readUInt8(this._pos)&j.WILL_RETAIN_MASK)!==0,o.will.qos=(this._list.readUInt8(this._pos)&j.WILL_QOS_MASK)>>j.WILL_QOS_SHIFT),o.clean=(this._list.readUInt8(this._pos)&j.CLEAN_SESSION_MASK)!==0,this._pos++,o.keepalive=this._parseNum(),o.keepalive===-1)return this._emitError(new Error("Packet too short"));if(o.protocolVersion===5){let l=this._parseProperties();Object.getOwnPropertyNames(l).length&&(o.properties=l)}let a=this._parseString();if(a===null)return this._emitError(new Error("Packet too short"));if(o.clientId=a,I("_parseConnect: packet.clientId: %s",o.clientId),s.will){if(o.protocolVersion===5){let l=this._parseProperties();Object.getOwnPropertyNames(l).length&&(o.will.properties=l)}if(t=this._parseString(),t===null)return this._emitError(new Error("Cannot parse will topic"));if(o.will.topic=t,I("_parseConnect: packet.will.topic: %s",o.will.topic),r=this._parseBuffer(),r===null)return this._emitError(new Error("Cannot parse will payload"));o.will.payload=r,I("_parseConnect: packet.will.paylaod: %s",o.will.payload)}if(s.username){if(n=this._parseString(),n===null)return this._emitError(new Error("Cannot parse username"));o.username=n,I("_parseConnect: packet.username: %s",o.username)}if(s.password){if(i=this._parseBuffer(),i===null)return this._emitError(new Error("Cannot parse password"));o.password=i}return this.settings=o,I("_parseConnect: complete"),o}_parseConnack(){I("_parseConnack");let t=this.packet;if(this._list.length<1)return null;if(t.sessionPresent=!!(this._list.readUInt8(this._pos++)&j.SESSIONPRESENT_MASK),this.settings.protocolVersion===5)this._list.length>=2?t.reasonCode=this._list.readUInt8(this._pos++):t.reasonCode=0;else{if(this._list.length<2)return null;t.returnCode=this._list.readUInt8(this._pos++)}if(t.returnCode===-1||t.reasonCode===-1)return this._emitError(new Error("Cannot parse return code"));if(this.settings.protocolVersion===5){let r=this._parseProperties();Object.getOwnPropertyNames(r).length&&(t.properties=r)}I("_parseConnack: complete")}_parsePublish(){I("_parsePublish");let t=this.packet;if(t.topic=this._parseString(),t.topic===null)return this._emitError(new Error("Cannot parse topic"));if(!(t.qos>0&&!this._parseMessageId())){if(this.settings.protocolVersion===5){let r=this._parseProperties();Object.getOwnPropertyNames(r).length&&(t.properties=r)}t.payload=this._list.slice(this._pos,t.length),I("_parsePublish: payload from buffer list: %o",t.payload)}}_parseSubscribe(){I("_parseSubscribe");let t=this.packet,r,i,n,s,o,f,a;if(t.qos!==1)return this._emitError(new Error("Wrong subscribe header"));if(t.subscriptions=[],!!this._parseMessageId()){if(this.settings.protocolVersion===5){let l=this._parseProperties();Object.getOwnPropertyNames(l).length&&(t.properties=l)}for(;this._pos<t.length;){if(r=this._parseString(),r===null)return this._emitError(new Error("Cannot parse topic"));if(this._pos>=t.length)return this._emitError(new Error("Malformed Subscribe Payload"));i=this._parseByte(),n=i&j.SUBSCRIBE_OPTIONS_QOS_MASK,f=(i>>j.SUBSCRIBE_OPTIONS_NL_SHIFT&j.SUBSCRIBE_OPTIONS_NL_MASK)!==0,o=(i>>j.SUBSCRIBE_OPTIONS_RAP_SHIFT&j.SUBSCRIBE_OPTIONS_RAP_MASK)!==0,s=i>>j.SUBSCRIBE_OPTIONS_RH_SHIFT&j.SUBSCRIBE_OPTIONS_RH_MASK,a={topic:r,qos:n},this.settings.protocolVersion===5?(a.nl=f,a.rap=o,a.rh=s):this.settings.bridgeMode&&(a.rh=0,a.rap=!0,a.nl=!0),I("_parseSubscribe: push subscription `%s` to subscription",a),t.subscriptions.push(a)}}}_parseSuback(){I("_parseSuback");let t=this.packet;if(this.packet.granted=[],!!this._parseMessageId()){if(this.settings.protocolVersion===5){let r=this._parseProperties();Object.getOwnPropertyNames(r).length&&(t.properties=r)}for(;this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){I("_parseUnsubscribe");let t=this.packet;if(t.unsubscriptions=[],!!this._parseMessageId()){if(this.settings.protocolVersion===5){let r=this._parseProperties();Object.getOwnPropertyNames(r).length&&(t.properties=r)}for(;this._pos<t.length;){let r=this._parseString();if(r===null)return this._emitError(new Error("Cannot parse topic"));I("_parseUnsubscribe: push topic `%s` to unsubscriptions",r),t.unsubscriptions.push(r)}}}_parseUnsuback(){I("_parseUnsuback");let t=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(this.settings.protocolVersion===5){let r=this._parseProperties();for(Object.getOwnPropertyNames(r).length&&(t.properties=r),t.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){I("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);let t=this.packet;if(this._parseMessageId(),this.settings.protocolVersion===5&&(t.length>2?(t.reasonCode=this._parseByte(),I("_parseConfirmation: packet.reasonCode `%d`",t.reasonCode)):t.reasonCode=0,t.length>3)){let r=this._parseProperties();Object.getOwnPropertyNames(r).length&&(t.properties=r)}return!0}_parseDisconnect(){let t=this.packet;if(I("_parseDisconnect"),this.settings.protocolVersion===5){this._list.length>0?t.reasonCode=this._parseByte():t.reasonCode=0;let r=this._parseProperties();Object.getOwnPropertyNames(r).length&&(t.properties=r)}return I("_parseDisconnect result: true"),!0}_parseAuth(){I("_parseAuth");let t=this.packet;if(this.settings.protocolVersion!==5)return this._emitError(new Error("Not supported auth packet for this version MQTT"));t.reasonCode=this._parseByte();let r=this._parseProperties();return Object.getOwnPropertyNames(r).length&&(t.properties=r),I("_parseAuth: result: true"),!0}_parseMessageId(){let t=this.packet;return t.messageId=this._parseNum(),t.messageId===null?(this._emitError(new Error("Cannot parse messageId")),!1):(I("_parseMessageId: packet.messageId %d",t.messageId),!0)}_parseString(t){let r=this._parseNum(),i=r+this._pos;if(r===-1||i>this._list.length||i>this.packet.length)return null;let n=this._list.toString("utf8",this._pos,i);return this._pos+=r,I("_parseString: result: %s",n),n}_parseStringPair(){return I("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){let t=this._parseNum(),r=t+this._pos;if(t===-1||r>this._list.length||r>this.packet.length)return null;let i=this._list.slice(this._pos,r);return this._pos+=t,I("_parseBuffer: result: %o",i),i}_parseNum(){if(this._list.length-this._pos<2)return-1;let t=this._list.readUInt16BE(this._pos);return this._pos+=2,I("_parseNum: result: %s",t),t}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;let t=this._list.readUInt32BE(this._pos);return this._pos+=4,I("_parse4ByteNum: result: %s",t),t}_parseVarByteNum(t){I("_parseVarByteNum");let r=4,i=0,n=1,s=0,o=!1,f,a=this._pos?this._pos:0;for(;i<r&&a+i<this._list.length;){if(f=this._list.readUInt8(a+i++),s+=n*(f&j.VARBYTEINT_MASK),n*=128,!(f&j.VARBYTEINT_FIN_MASK)){o=!0;break}if(this._list.length<=i)break}return!o&&i===r&&this._list.length>=i&&this._emitError(new Error("Invalid variable byte integer")),a&&(this._pos+=i),o=o?t?{bytes:i,value:s}:s:!1,I("_parseVarByteNum: result: %o",o),o}_parseByte(){let t;return this._pos<this._list.length&&(t=this._list.readUInt8(this._pos),this._pos++),I("_parseByte: result: %o",t),t}_parseByType(t){switch(I("_parseByType: type: %s",t),t){case"byte":return this._parseByte()!==0;case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){I("_parseProperties");let t=this._parseVarByteNum(),i=this._pos+t,n={};for(;this._pos<i;){let s=this._parseByte();if(!s)return this._emitError(new Error("Cannot parse property code type")),!1;let o=j.propertiesCodes[s];if(!o)return this._emitError(new Error("Unknown property")),!1;if(o==="userProperties"){n[o]||(n[o]=Object.create(null));let f=this._parseByType(j.propertiesTypes[o]);if(n[o][f.name])if(Array.isArray(n[o][f.name]))n[o][f.name].push(f.value);else{let a=n[o][f.name];n[o][f.name]=[a],n[o][f.name].push(f.value)}else n[o][f.name]=f.value;continue}n[o]?Array.isArray(n[o])?n[o].push(this._parseByType(j.propertiesTypes[o])):(n[o]=[n[o]],n[o].push(this._parseByType(j.propertiesTypes[o]))):n[o]=this._parseByType(j.propertiesTypes[o])}return n}_newPacket(){return I("_newPacket"),this.packet&&(this._list.consume(this.packet.length),I("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),I("_newPacket: new packet"),this.packet=new $a,this._pos=0,!0}_emitError(t){I("_emitError"),this.error=t,this.emit("error",t)}};Ga.exports=Ln});var Ja=b((aw,Qa)=>{var Ka={},Yp=Buffer.isBuffer(Buffer.from([1,2]).subarray(0,1));function Ya(e){let t=Buffer.allocUnsafe(2);return t.writeUInt8(e>>8,0),t.writeUInt8(e&255,1),t}function Qp(){for(let e=0;e<65536;e++)Ka[e]=Ya(e)}function Jp(e){let r=0,i=0,n=Buffer.allocUnsafe(4);do r=e%128|0,e=e/128|0,e>0&&(r=r|128),n.writeUInt8(r,i++);while(e>0&&i<4);return e>0&&(i=0),Yp?n.subarray(0,i):n.slice(0,i)}function Xp(e){let t=Buffer.allocUnsafe(4);return t.writeUInt32BE(e,0),t}Qa.exports={cache:Ka,generateCache:Qp,generateNumber:Ya,genBufVariableByteInt:Jp,generate4ByteBuffer:Xp}});var It=b((fw,qn)=>{"use strict";typeof process>"u"||!process.version||process.version.indexOf("v0.")===0||process.version.indexOf("v1.")===0&&process.version.indexOf("v1.8.")!==0?qn.exports={nextTick:Zp}:qn.exports=process;function Zp(e,t,r,i){if(typeof e!="function")throw new TypeError('"callback" argument must be a function');var n=arguments.length,s,o;switch(n){case 0:case 1:return process.nextTick(e);case 2:return process.nextTick(function(){e.call(null,t)});case 3:return process.nextTick(function(){e.call(null,t,r)});case 4:return process.nextTick(function(){e.call(null,t,r,i)});default:for(s=new Array(n-1),o=0;o<s.length;)s[o++]=arguments[o];return process.nextTick(function(){e.apply(null,s)})}}});var jn=b((lw,of)=>{var k=Bn(),e_=Buffer.allocUnsafe(0),t_=Buffer.from([0]),Yt=Ja(),r_=It().nextTick,_e=ze()("mqtt-packet:writeToStream"),ii=Yt.cache,i_=Yt.generateNumber,n_=Yt.generateCache,Dn=Yt.genBufVariableByteInt,s_=Yt.generate4ByteBuffer,ne=Un,ni=!0;function nf(e,t,r){switch(_e("generate called"),t.cork&&(t.cork(),r_(o_,t)),ni&&(ni=!1,n_()),_e("generate: packet.cmd: %s",e.cmd),e.cmd){case"connect":return a_(e,t,r);case"connack":return f_(e,t,r);case"publish":return l_(e,t,r);case"puback":case"pubrec":case"pubrel":case"pubcomp":return u_(e,t,r);case"subscribe":return c_(e,t,r);case"suback":return h_(e,t,r);case"unsubscribe":return d_(e,t,r);case"unsuback":return p_(e,t,r);case"pingreq":case"pingresp":return __(e,t,r);case"disconnect":return g_(e,t,r);case"auth":return b_(e,t,r);default:return t.emit("error",new Error("Unknown command")),!1}}Object.defineProperty(nf,"cacheNumbers",{get(){return ne===Un},set(e){e?((!ii||Object.keys(ii).length===0)&&(ni=!0),ne=Un):(ni=!1,ne=y_)}});function o_(e){e.uncork()}function a_(e,t,r){let i=e||{},n=i.protocolId||"MQTT",s=i.protocolVersion||4,o=i.will,f=i.clean,a=i.keepalive||0,l=i.clientId||"",u=i.username,h=i.password,c=i.properties;f===void 0&&(f=!0);let d=0;if(!n||typeof n!="string"&&!Buffer.isBuffer(n))return t.emit("error",new Error("Invalid protocolId")),!1;if(d+=n.length+2,s!==3&&s!==4&&s!==5)return t.emit("error",new Error("Invalid protocol version")),!1;if(d+=1,(typeof l=="string"||Buffer.isBuffer(l))&&(l||s>=4)&&(l||f))d+=Buffer.byteLength(l)+2;else{if(s<4)return t.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(f*1===0)return t.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if(typeof a!="number"||a<0||a>65535||a%1!==0)return t.emit("error",new Error("Invalid keepalive")),!1;if(d+=2,d+=1,s===5){var _=Ke(t,c);if(!_)return!1;d+=_.length}if(o){if(typeof o!="object")return t.emit("error",new Error("Invalid will")),!1;if(!o.topic||typeof o.topic!="string")return t.emit("error",new Error("Invalid will topic")),!1;if(d+=Buffer.byteLength(o.topic)+2,d+=2,o.payload)if(o.payload.length>=0)typeof o.payload=="string"?d+=Buffer.byteLength(o.payload):d+=o.payload.length;else return t.emit("error",new Error("Invalid will payload")),!1;var v={};if(s===5){if(v=Ke(t,o.properties),!v)return!1;d+=v.length}}let m=!1;if(u!=null)if(rf(u))m=!0,d+=Buffer.byteLength(u)+2;else return t.emit("error",new Error("Invalid username")),!1;if(h!=null){if(!m)return t.emit("error",new Error("Username is required to use password")),!1;if(rf(h))d+=sf(h)+2;else return t.emit("error",new Error("Invalid password")),!1}t.write(k.CONNECT_HEADER),ge(t,d),Ot(t,n),i.bridgeMode&&(s+=128),t.write(s===131?k.VERSION131:s===132?k.VERSION132:s===4?k.VERSION4:s===5?k.VERSION5:k.VERSION3);let p=0;return p|=u!=null?k.USERNAME_MASK:0,p|=h!=null?k.PASSWORD_MASK:0,p|=o&&o.retain?k.WILL_RETAIN_MASK:0,p|=o&&o.qos?o.qos<<k.WILL_QOS_SHIFT:0,p|=o?k.WILL_FLAG_MASK:0,p|=f?k.CLEAN_SESSION_MASK:0,t.write(Buffer.from([p])),ne(t,a),s===5&&_.write(),Ot(t,l),o&&(s===5&&v.write(),lt(t,o.topic),Ot(t,o.payload)),u!=null&&Ot(t,u),h!=null&&Ot(t,h),!0}function f_(e,t,r){let i=r?r.protocolVersion:4,n=e||{},s=i===5?n.reasonCode:n.returnCode,o=n.properties,f=2;if(typeof s!="number")return t.emit("error",new Error("Invalid return code")),!1;let a=null;if(i===5){if(a=Ke(t,o),!a)return!1;f+=a.length}return t.write(k.CONNACK_HEADER),ge(t,f),t.write(n.sessionPresent?k.SESSIONPRESENT_HEADER:t_),t.write(Buffer.from([s])),a?.write(),!0}function l_(e,t,r){_e("publish: packet: %o",e);let i=r?r.protocolVersion:4,n=e||{},s=n.qos||0,o=n.retain?k.RETAIN_MASK:0,f=n.topic,a=n.payload||e_,l=n.messageId,u=n.properties,h=0;if(typeof f=="string")h+=Buffer.byteLength(f)+2;else if(Buffer.isBuffer(f))h+=f.length+2;else return t.emit("error",new Error("Invalid topic")),!1;if(Buffer.isBuffer(a)?h+=a.length:h+=Buffer.byteLength(a),s&&typeof l!="number")return t.emit("error",new Error("Invalid messageId")),!1;s&&(h+=2);let c=null;if(i===5){if(c=Ke(t,u),!c)return!1;h+=c.length}return t.write(k.PUBLISH_HEADER[s][n.dup?1:0][o?1:0]),ge(t,h),ne(t,sf(f)),t.write(f),s>0&&ne(t,l),c?.write(),_e("publish: payload: %o",a),t.write(a)}function u_(e,t,r){let i=r?r.protocolVersion:4,n=e||{},s=n.cmd||"puback",o=n.messageId,f=n.dup&&s==="pubrel"?k.DUP_MASK:0,a=0,l=n.reasonCode,u=n.properties,h=i===5?3:2;if(s==="pubrel"&&(a=1),typeof o!="number")return t.emit("error",new Error("Invalid messageId")),!1;let c=null;if(i===5&&typeof u=="object"){if(c=Qt(t,u,r,h),!c)return!1;h+=c.length}return t.write(k.ACKS[s][a][f][0]),ge(t,h),ne(t,o),i===5&&t.write(Buffer.from([l])),c!==null&&c.write(),!0}function c_(e,t,r){_e("subscribe: packet: ");let i=r?r.protocolVersion:4,n=e||{},s=n.dup?k.DUP_MASK:0,o=n.messageId,f=n.subscriptions,a=n.properties,l=0;if(typeof o!="number")return t.emit("error",new Error("Invalid messageId")),!1;l+=2;let u=null;if(i===5){if(u=Ke(t,a),!u)return!1;l+=u.length}if(typeof f=="object"&&f.length)for(let c=0;c<f.length;c+=1){let d=f[c].topic,_=f[c].qos;if(typeof d!="string")return t.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if(typeof _!="number")return t.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if(i===5){if(typeof(f[c].nl||!1)!="boolean")return t.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if(typeof(f[c].rap||!1)!="boolean")return t.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;let p=f[c].rh||0;if(typeof p!="number"||p>2)return t.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}l+=Buffer.byteLength(d)+2+1}else return t.emit("error",new Error("Invalid subscriptions")),!1;_e("subscribe: writing to stream: %o",k.SUBSCRIBE_HEADER),t.write(k.SUBSCRIBE_HEADER[1][s?1:0][0]),ge(t,l),ne(t,o),u!==null&&u.write();let h=!0;for(let c of f){let d=c.topic,_=c.qos,v=+c.nl,m=+c.rap,p=c.rh,g;lt(t,d),g=k.SUBSCRIBE_OPTIONS_QOS[_],i===5&&(g|=v?k.SUBSCRIBE_OPTIONS_NL:0,g|=m?k.SUBSCRIBE_OPTIONS_RAP:0,g|=p?k.SUBSCRIBE_OPTIONS_RH[p]:0),h=t.write(Buffer.from([g]))}return h}function h_(e,t,r){let i=r?r.protocolVersion:4,n=e||{},s=n.messageId,o=n.granted,f=n.properties,a=0;if(typeof s!="number")return t.emit("error",new Error("Invalid messageId")),!1;if(a+=2,typeof o=="object"&&o.length)for(let u=0;u<o.length;u+=1){if(typeof o[u]!="number")return t.emit("error",new Error("Invalid qos vector")),!1;a+=1}else return t.emit("error",new Error("Invalid qos vector")),!1;let l=null;if(i===5){if(l=Qt(t,f,r,a),!l)return!1;a+=l.length}return t.write(k.SUBACK_HEADER),ge(t,a),ne(t,s),l!==null&&l.write(),t.write(Buffer.from(o))}function d_(e,t,r){let i=r?r.protocolVersion:4,n=e||{},s=n.messageId,o=n.dup?k.DUP_MASK:0,f=n.unsubscriptions,a=n.properties,l=0;if(typeof s!="number")return t.emit("error",new Error("Invalid messageId")),!1;if(l+=2,typeof f=="object"&&f.length)for(let c=0;c<f.length;c+=1){if(typeof f[c]!="string")return t.emit("error",new Error("Invalid unsubscriptions")),!1;l+=Buffer.byteLength(f[c])+2}else return t.emit("error",new Error("Invalid unsubscriptions")),!1;let u=null;if(i===5){if(u=Ke(t,a),!u)return!1;l+=u.length}t.write(k.UNSUBSCRIBE_HEADER[1][o?1:0][0]),ge(t,l),ne(t,s),u!==null&&u.write();let h=!0;for(let c=0;c<f.length;c++)h=lt(t,f[c]);return h}function p_(e,t,r){let i=r?r.protocolVersion:4,n=e||{},s=n.messageId,o=n.dup?k.DUP_MASK:0,f=n.granted,a=n.properties,l=n.cmd,u=0,h=2;if(typeof s!="number")return t.emit("error",new Error("Invalid messageId")),!1;if(i===5)if(typeof f=="object"&&f.length)for(let d=0;d<f.length;d+=1){if(typeof f[d]!="number")return t.emit("error",new Error("Invalid qos vector")),!1;h+=1}else return t.emit("error",new Error("Invalid qos vector")),!1;let c=null;if(i===5){if(c=Qt(t,a,r,h),!c)return!1;h+=c.length}return t.write(k.ACKS[l][u][o][0]),ge(t,h),ne(t,s),c!==null&&c.write(),i===5&&t.write(Buffer.from(f)),!0}function __(e,t,r){return t.write(k.EMPTY[e.cmd])}function g_(e,t,r){let i=r?r.protocolVersion:4,n=e||{},s=n.reasonCode,o=n.properties,f=i===5?1:0,a=null;if(i===5){if(a=Qt(t,o,r,f),!a)return!1;f+=a.length}return t.write(Buffer.from([k.codes.disconnect<<4])),ge(t,f),i===5&&t.write(Buffer.from([s])),a!==null&&a.write(),!0}function b_(e,t,r){let i=r?r.protocolVersion:4,n=e||{},s=n.reasonCode,o=n.properties,f=i===5?1:0;i!==5&&t.emit("error",new Error("Invalid mqtt version for auth packet"));let a=Qt(t,o,r,f);return a?(f+=a.length,t.write(Buffer.from([k.codes.auth<<4])),ge(t,f),t.write(Buffer.from([s])),a!==null&&a.write(),!0):!1}var Xa={};function ge(e,t){if(t>k.VARBYTEINT_MAX)return e.emit("error",new Error(`Invalid variable byte integer: ${t}`)),!1;let r=Xa[t];return r||(r=Dn(t),t<16384&&(Xa[t]=r)),_e("writeVarByteInt: writing to stream: %o",r),e.write(r)}function lt(e,t){let r=Buffer.byteLength(t);return ne(e,r),_e("writeString: %s",t),e.write(t,"utf8")}function Za(e,t,r){lt(e,t),lt(e,r)}function Un(e,t){return _e("writeNumberCached: number: %d",t),_e("writeNumberCached: %o",ii[t]),e.write(ii[t])}function y_(e,t){let r=i_(t);return _e("writeNumberGenerated: %o",r),e.write(r)}function v_(e,t){let r=s_(t);return _e("write4ByteNumber: %o",r),e.write(r)}function Ot(e,t){typeof t=="string"?lt(e,t):t?(ne(e,t.length),e.write(t)):ne(e,0)}function Ke(e,t){if(typeof t!="object"||t.length!=null)return{length:1,write(){tf(e,{},0)}};let r=0;function i(s,o){let f=k.propertiesTypes[s],a=0;switch(f){case"byte":{if(typeof o!="boolean")return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=2;break}case"int8":{if(typeof o!="number"||o<0||o>255)return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=2;break}case"binary":{if(o&&o===null)return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=1+Buffer.byteLength(o)+2;break}case"int16":{if(typeof o!="number"||o<0||o>65535)return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=3;break}case"int32":{if(typeof o!="number"||o<0||o>4294967295)return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=5;break}case"var":{if(typeof o!="number"||o<0||o>268435455)return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=1+Buffer.byteLength(Dn(o));break}case"string":{if(typeof o!="string")return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=3+Buffer.byteLength(o.toString());break}case"pair":{if(typeof o!="object")return e.emit("error",new Error(`Invalid ${s}: ${o}`)),!1;a+=Object.getOwnPropertyNames(o).reduce((l,u)=>{let h=o[u];return Array.isArray(h)?l+=h.reduce((c,d)=>(c+=3+Buffer.byteLength(u.toString())+2+Buffer.byteLength(d.toString()),c),0):l+=3+Buffer.byteLength(u.toString())+2+Buffer.byteLength(o[u].toString()),l},0);break}default:return e.emit("error",new Error(`Invalid property ${s}: ${o}`)),!1}return a}if(t)for(let s in t){let o=0,f=0,a=t[s];if(Array.isArray(a))for(let l=0;l<a.length;l++){if(f=i(s,a[l]),!f)return!1;o+=f}else{if(f=i(s,a),!f)return!1;o=f}if(!o)return!1;r+=o}return{length:Buffer.byteLength(Dn(r))+r,write(){tf(e,t,r)}}}function Qt(e,t,r,i){let n=["reasonString","userProperties"],s=r&&r.properties&&r.properties.maximumPacketSize?r.properties.maximumPacketSize:0,o=Ke(e,t);if(s)for(;i+o.length>s;){let f=n.shift();if(f&&t[f])delete t[f],o=Ke(e,t);else return!1}return o}function ef(e,t,r){switch(k.propertiesTypes[t]){case"byte":{e.write(Buffer.from([k.properties[t]])),e.write(Buffer.from([+r]));break}case"int8":{e.write(Buffer.from([k.properties[t]])),e.write(Buffer.from([r]));break}case"binary":{e.write(Buffer.from([k.properties[t]])),Ot(e,r);break}case"int16":{e.write(Buffer.from([k.properties[t]])),ne(e,r);break}case"int32":{e.write(Buffer.from([k.properties[t]])),v_(e,r);break}case"var":{e.write(Buffer.from([k.properties[t]])),ge(e,r);break}case"string":{e.write(Buffer.from([k.properties[t]])),lt(e,r);break}case"pair":{Object.getOwnPropertyNames(r).forEach(n=>{let s=r[n];Array.isArray(s)?s.forEach(o=>{e.write(Buffer.from([k.properties[t]])),Za(e,n.toString(),o.toString())}):(e.write(Buffer.from([k.properties[t]])),Za(e,n.toString(),s.toString()))});break}default:return e.emit("error",new Error(`Invalid property ${t} value: ${r}`)),!1}}function tf(e,t,r){ge(e,r);for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)&&t[i]!==null){let n=t[i];if(Array.isArray(n))for(let s=0;s<n.length;s++)ef(e,i,n[s]);else ef(e,i,n)}}function sf(e){return e?e instanceof Buffer?e.length:Buffer.byteLength(e):0}function rf(e){return typeof e=="string"||e instanceof Buffer}of.exports=nf});var ff=b((uw,af)=>{var m_=jn(),w_=require("events");function S_(e,t){let r=new Fn;return m_(e,r,t),r.concat()}var Fn=class extends w_{constructor(){super(),this._array=new Array(20),this._i=0}write(t){return this._array[this._i++]=t,!0}concat(){let t=0,r=new Array(this._array.length),i=this._array,n=0,s;for(s=0;s<i.length&&i[s]!==void 0;s++)typeof i[s]!="string"?r[s]=i[s].length:r[s]=Buffer.byteLength(i[s]),t+=r[s];let o=Buffer.allocUnsafe(t);for(s=0;s<i.length&&i[s]!==void 0;s++)typeof i[s]!="string"?(i[s].copy(o,n),n+=r[s]):(o.write(i[s],n),n+=r[s]);return o}};af.exports=S_});var lf=b(si=>{si.parser=za().parser;si.generate=ff();si.writeToStream=jn()});var cf=b((hw,uf)=>{"use strict";function E_(e,t,r){var i=this;this._callback=e,this._args=r,this._interval=setInterval(e,t,this._args),this.reschedule=function(n){n||(n=i._interval),i._interval&&clearInterval(i._interval),i._interval=setInterval(i._callback,n,i._args)},this.clear=function(){i._interval&&(clearInterval(i._interval),i._interval=void 0)},this.destroy=function(){i._interval&&clearInterval(i._interval),i._callback=void 0,i._interval=void 0,i._args=void 0}}function x_(){if(typeof arguments[0]!="function")throw new Error("callback needed");if(typeof arguments[1]!="number")throw new Error("interval needed");var e;if(arguments.length>0){e=new Array(arguments.length-2);for(var t=0;t<e.length;t++)e[t]=arguments[t+2]}return new E_(arguments[0],arguments[1],e)}uf.exports=x_});var df=b((dw,hf)=>{"use strict";function C_(e){for(var t=e.split("/"),r=0;r<t.length;r++)if(t[r]!=="+"){if(t[r]==="#")return r===t.length-1;if(t[r].indexOf("+")!==-1||t[r].indexOf("#")!==-1)return!1}return!0}function T_(e){if(e.length===0)return"empty_topic_list";for(var t=0;t<e.length;t++)if(!C_(e[t]))return e[t];return null}hf.exports={validateTopics:T_}});var Hn=b((pw,vf)=>{"use strict";var gf=require("events").EventEmitter,oi=Qr(),bf=lf(),I_=He().Writable,O_=ie(),k_=cf(),R_=df(),ai=Nr(),y=ze()("mqttjs:client"),Vn=process?process.nextTick:function(e){setTimeout(e,0)},yf=global.setImmediate||function(e){Vn(e)},pf={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:30*1e3,clean:!0,resubscribe:!0},P_=["ECONNREFUSED","EADDRINUSE","ECONNRESET","ENOTFOUND"],Wn={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};function B_(){return"mqttjs_"+Math.random().toString(16).substr(2,8)}function Jt(e,t,r){y("sendPacket :: packet: %O",t),y("sendPacket :: emitting `packetsend`"),e.emit("packetsend",t),y("sendPacket :: writing to stream");var i=bf.writeToStream(t,e.stream,e.options);y("sendPacket :: writeToStream result %s",i),!i&&r?(y("sendPacket :: handle events on `drain` once through callback."),e.stream.once("drain",r)):r&&(y("sendPacket :: invoking cb"),r())}function A_(e){e&&(y("flush: queue exists? %b",!!e),Object.keys(e).forEach(function(t){typeof e[t].cb=="function"&&(e[t].cb(new Error("Connection closed")),delete e[t])}))}function N_(e){e&&(y("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(e).forEach(function(t){e[t].volatile&&typeof e[t].cb=="function"&&(e[t].cb(new Error("Connection closed")),delete e[t])}))}function _f(e,t,r,i){y("storeAndSend :: store packet with cmd %s to outgoingStore",t.cmd),e.outgoingStore.put(t,function(s){if(s)return r&&r(s);i(),Jt(e,t,r)})}function se(e){y("nop ::",e)}function N(e,t){var r,i=this;if(!(this instanceof N))return new N(e,t);this.options=t||{};for(r in pf)typeof this.options[r]>"u"?this.options[r]=pf[r]:this.options[r]=t[r];y("MqttClient :: options.protocol",t.protocol),y("MqttClient :: options.protocolVersion",t.protocolVersion),y("MqttClient :: options.username",t.username),y("MqttClient :: options.keepalive",t.keepalive),y("MqttClient :: options.reconnectPeriod",t.reconnectPeriod),y("MqttClient :: options.rejectUnauthorized",t.rejectUnauthorized),this.options.clientId=typeof t.clientId=="string"?t.clientId:B_(),y("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=t.protocolVersion===5&&t.customHandleAcks?t.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=e,this.outgoingStore=t.outgoingStore||new oi,this.incomingStore=t.incomingStore||new oi,this.queueQoSZero=t.queueQoSZero===void 0?!0:t.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this.nextId=Math.max(1,Math.floor(Math.random()*65535)),this.outgoing={},this._firstConnection=!0,this.on("connect",function(){var n=this.queue;function s(){var o=n.shift();y("deliver :: entry %o",o);var f=null;o&&(f=o.packet,y("deliver :: call _sendPacket for %o",f),i._sendPacket(f,function(a){o.cb&&o.cb(a),s()}))}y("connect :: sending queued packets"),s()}),this.on("close",function(){y("close :: connected set to `false`"),this.connected=!1,y("close :: clearing connackTimer"),clearTimeout(this.connackTimer),y("close :: clearing ping timer"),i.pingTimer!==null&&(i.pingTimer.clear(),i.pingTimer=null),y("close :: calling _setupReconnect"),this._setupReconnect()}),gf.call(this),y("MqttClient :: setting up stream"),this._setupStream()}O_(N,gf);N.prototype._setupStream=function(){var e,t=this,r=new I_,i=bf.parser(this.options),n=null,s=[];y("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),y("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),i.on("packet",function(u){y("parser :: on packet push to packets array."),s.push(u)});function o(){if(s.length)Vn(f);else{var u=n;n=null,u()}}function f(){y("work :: getting next packet in queue");var u=s.shift();if(u)y("work :: packet pulled from queue"),t._handlePacket(u,o);else{y("work :: no packets in queue");var h=n;n=null,y("work :: done flag is %s",!!h),h&&h()}}r._write=function(u,h,c){n=c,y("writable stream :: parsing buffer"),i.parse(u),f()};function a(u){y("streamErrorHandler :: error",u.message),P_.includes(u.code)?(y("streamErrorHandler :: emitting error"),t.emit("error",u)):se(u)}if(y("_setupStream :: pipe stream to writable stream"),this.stream.pipe(r),this.stream.on("error",a),this.stream.on("close",function(){y("(%s)stream :: on close",t.options.clientId),N_(t.outgoing),y("stream: emit close to MqttClient"),t.emit("close")}),y("_setupStream: sending packet `connect`"),e=Object.create(this.options),e.cmd="connect",Jt(this,e),i.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return t.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;if(this.options.properties.authenticationMethod&&this.options.authPacket&&typeof this.options.authPacket=="object"){var l=ai({cmd:"auth",reasonCode:0},this.options.authPacket);Jt(this,l)}}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(function(){y("!!connectTimeout hit!! Calling _cleanUp with force `true`"),t._cleanUp(!0)},this.options.connectTimeout)};N.prototype._handlePacket=function(e,t){var r=this.options;if(r.protocolVersion===5&&r.properties&&r.properties.maximumPacketSize&&r.properties.maximumPacketSize<e.length)return this.emit("error",new Error("exceeding packets size "+e.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(y("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",e),e.cmd){case"publish":this._handlePublish(e,t);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(e),t();break;case"pubrel":this._handlePubrel(e,t);break;case"connack":this._handleConnack(e),t();break;case"pingresp":this._handlePingresp(e),t();break;case"disconnect":this._handleDisconnect(e),t();break;default:break}};N.prototype._checkDisconnecting=function(e){return this.disconnecting&&(e?e(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting};N.prototype.publish=function(e,t,r,i){y("publish :: message `%s` to topic `%s`",t,e);var n,s=this.options;typeof r=="function"&&(i=r,r=null);var o={qos:0,retain:!1,dup:!1};if(r=ai(o,r),this._checkDisconnecting(i))return this;switch(n={cmd:"publish",topic:e,payload:t,qos:r.qos,retain:r.retain,messageId:this._nextId(),dup:r.dup},s.protocolVersion===5&&(n.properties=r.properties,(!s.properties&&n.properties&&n.properties.topicAlias||r.properties&&s.properties&&(r.properties.topicAlias&&s.properties.topicAliasMaximum&&r.properties.topicAlias>s.properties.topicAliasMaximum||!s.properties.topicAliasMaximum&&r.properties.topicAlias))&&delete n.properties.topicAlias),y("publish :: qos",r.qos),r.qos){case 1:case 2:this.outgoing[n.messageId]={volatile:!1,cb:i||se},this._storeProcessing?(y("_storeProcessing enabled"),this._packetIdsDuringStoreProcessing[n.messageId]=!1,this._storePacket(n,void 0,r.cbStorePut)):(y("MqttClient:publish: packet cmd: %s",n.cmd),this._sendPacket(n,void 0,r.cbStorePut));break;default:this._storeProcessing?(y("_storeProcessing enabled"),this._storePacket(n,i,r.cbStorePut)):(y("MqttClient:publish: packet cmd: %s",n.cmd),this._sendPacket(n,i,r.cbStorePut));break}return this};N.prototype.subscribe=function(){for(var e,t=new Array(arguments.length),r=0;r<arguments.length;r++)t[r]=arguments[r];var i=[],n=t.shift(),s=n.resubscribe,o=t.pop()||se,f=t.pop(),a,l=this,u=this.options.protocolVersion;if(delete n.resubscribe,typeof n=="string"&&(n=[n]),typeof o!="function"&&(f=o,o=se),a=R_.validateTopics(n),a!==null)return yf(o,new Error("Invalid topic "+a)),this;if(this._checkDisconnecting(o))return y("subscribe: discconecting true"),this;var h={qos:0};if(u===5&&(h.nl=!1,h.rap=!1,h.rh=0),f=ai(h,f),Array.isArray(n)?n.forEach(function(d){if(y("subscribe: array topic %s",d),!l._resubscribeTopics.hasOwnProperty(d)||l._resubscribeTopics[d].qos<f.qos||s){var _={topic:d,qos:f.qos};u===5&&(_.nl=f.nl,_.rap=f.rap,_.rh=f.rh,_.properties=f.properties),y("subscribe: pushing topic `%s` and qos `%s` to subs list",_.topic,_.qos),i.push(_)}}):Object.keys(n).forEach(function(d){if(y("subscribe: object topic %s",d),!l._resubscribeTopics.hasOwnProperty(d)||l._resubscribeTopics[d].qos<n[d].qos||s){var _={topic:d,qos:n[d].qos};u===5&&(_.nl=n[d].nl,_.rap=n[d].rap,_.rh=n[d].rh,_.properties=f.properties),y("subscribe: pushing `%s` to subs list",_),i.push(_)}}),e={cmd:"subscribe",subscriptions:i,qos:1,retain:!1,dup:!1,messageId:this._nextId()},f.properties&&(e.properties=f.properties),!i.length){o(null,[]);return}if(this.options.resubscribe){y("subscribe :: resubscribe true");var c=[];i.forEach(function(d){if(l.options.reconnectPeriod>0){var _={qos:d.qos};u===5&&(_.nl=d.nl||!1,_.rap=d.rap||!1,_.rh=d.rh||0,_.properties=d.properties),l._resubscribeTopics[d.topic]=_,c.push(d.topic)}}),l.messageIdToTopic[e.messageId]=c}return this.outgoing[e.messageId]={volatile:!0,cb:function(d,_){if(!d)for(var v=_.granted,m=0;m<v.length;m+=1)i[m].qos=v[m];o(d,i)}},y("subscribe :: call _sendPacket"),this._sendPacket(e),this};N.prototype.unsubscribe=function(){for(var e={cmd:"unsubscribe",qos:1,messageId:this._nextId()},t=this,r=new Array(arguments.length),i=0;i<arguments.length;i++)r[i]=arguments[i];var n=r.shift(),s=r.pop()||se,o=r.pop();return typeof n=="string"&&(n=[n]),typeof s!="function"&&(o=s,s=se),this._checkDisconnecting(s)?this:(typeof n=="string"?e.unsubscriptions=[n]:Array.isArray(n)&&(e.unsubscriptions=n),this.options.resubscribe&&e.unsubscriptions.forEach(function(f){delete t._resubscribeTopics[f]}),typeof o=="object"&&o.properties&&(e.properties=o.properties),this.outgoing[e.messageId]={volatile:!0,cb:s},y("unsubscribe: call _sendPacket"),this._sendPacket(e),this)};N.prototype.end=function(e,t,r){var i=this;y("end :: (%s)",this.options.clientId),(e==null||typeof e!="boolean")&&(r=t||se,t=e,e=!1,typeof t!="object"&&(r=t,t=null,typeof r!="function"&&(r=se))),typeof t!="object"&&(r=t,t=null),y("end :: cb? %s",!!r),r=r||se;function n(){y("end :: closeStores: closing incoming and outgoing stores"),i.disconnected=!0,i.incomingStore.close(function(o){i.outgoingStore.close(function(f){if(y("end :: closeStores: emitting end"),i.emit("end"),r){let a=o||f;y("end :: closeStores: invoking callback with args"),r(a)}})}),i._deferredReconnect&&i._deferredReconnect()}function s(){y("end :: (%s) :: finish :: calling _cleanUp with force %s",i.options.clientId,e),i._cleanUp(e,()=>{y("end :: finish :: calling process.nextTick on closeStores"),Vn(n.bind(i))},t)}return this.disconnecting?(r(),this):(this._clearReconnect(),this.disconnecting=!0,!e&&Object.keys(this.outgoing).length>0?(y("end :: (%s) :: calling finish in 10ms once outgoing is empty",i.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,s,10))):(y("end :: (%s) :: immediately calling finish",i.options.clientId),s()),this)};N.prototype.removeOutgoingMessage=function(e){var t=this.outgoing[e]?this.outgoing[e].cb:null;return delete this.outgoing[e],this.outgoingStore.del({messageId:e},function(){t(new Error("Message removed"))}),this};N.prototype.reconnect=function(e){y("client reconnect");var t=this,r=function(){e?(t.options.incomingStore=e.incomingStore,t.options.outgoingStore=e.outgoingStore):(t.options.incomingStore=null,t.options.outgoingStore=null),t.incomingStore=t.options.incomingStore||new oi,t.outgoingStore=t.options.outgoingStore||new oi,t.disconnecting=!1,t.disconnected=!1,t._deferredReconnect=null,t._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=r:r(),this};N.prototype._reconnect=function(){y("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this._setupStream()}),y("client already connected. disconnecting first.")):(y("_reconnect: calling _setupStream"),this._setupStream())};N.prototype._setupReconnect=function(){var e=this;!e.disconnecting&&!e.reconnectTimer&&e.options.reconnectPeriod>0?(this.reconnecting||(y("_setupReconnect :: emit `offline` state"),this.emit("offline"),y("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),y("_setupReconnect :: setting reconnectTimer for %d ms",e.options.reconnectPeriod),e.reconnectTimer=setInterval(function(){y("reconnectTimer :: reconnect triggered!"),e._reconnect()},e.options.reconnectPeriod)):y("_setupReconnect :: doing nothing...")};N.prototype._clearReconnect=function(){y("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)};N.prototype._cleanUp=function(e,t){var r=arguments[2];if(t&&(y("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",t)),y("_cleanUp :: forced? %s",e),e)this.options.reconnectPeriod===0&&this.options.clean&&A_(this.outgoing),y("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{var i=ai({cmd:"disconnect"},r);y("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(i,yf.bind(null,this.stream.end.bind(this.stream)))}this.disconnecting||(y("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),this.pingTimer!==null&&(y("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),t&&!this.connected&&(y("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",t),t())};N.prototype._sendPacket=function(e,t,r){if(y("_sendPacket :: (%s) :: start",this.options.clientId),r=r||se,!this.connected){y("_sendPacket :: client not connected. Storing packet offline."),this._storePacket(e,t,r);return}switch(this._shiftPingInterval(),e.cmd){case"publish":break;case"pubrel":_f(this,e,t,r);return;default:Jt(this,e,t);return}switch(e.qos){case 2:case 1:_f(this,e,t,r);break;case 0:default:Jt(this,e,t);break}y("_sendPacket :: (%s) :: end",this.options.clientId)};N.prototype._storePacket=function(e,t,r){y("_storePacket :: packet: %o",e),y("_storePacket :: cb? %s",!!t),r=r||se,(e.qos||0)===0&&this.queueQoSZero||e.cmd!=="publish"?this.queue.push({packet:e,cb:t}):e.qos>0?(t=this.outgoing[e.messageId]?this.outgoing[e.messageId].cb:null,this.outgoingStore.put(e,function(i){if(i)return t&&t(i);r()})):t&&t(new Error("No connection to broker"))};N.prototype._setupPingTimer=function(){y("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);var e=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=k_(function(){e._checkPing()},this.options.keepalive*1e3))};N.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(this.options.keepalive*1e3)};N.prototype._checkPing=function(){y("_checkPing :: checking ping..."),this.pingResp?(y("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(y("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))};N.prototype._handlePingresp=function(){this.pingResp=!0};N.prototype._handleConnack=function(e){y("_handleConnack");var t=this.options,r=t.protocolVersion,i=r===5?e.reasonCode:e.returnCode;if(clearTimeout(this.connackTimer),e.properties&&(e.properties.topicAliasMaximum&&(t.properties||(t.properties={}),t.properties.topicAliasMaximum=e.properties.topicAliasMaximum),e.properties.serverKeepAlive&&t.keepalive&&(t.keepalive=e.properties.serverKeepAlive,this._shiftPingInterval()),e.properties.maximumPacketSize&&(t.properties||(t.properties={}),t.properties.maximumPacketSize=e.properties.maximumPacketSize)),i===0)this.reconnecting=!1,this._onConnect(e);else if(i>0){var n=new Error("Connection refused: "+Wn[i]);n.code=i,this.emit("error",n)}};N.prototype._handlePublish=function(e,t){y("_handlePublish: packet %o",e),t=typeof t<"u"?t:se;var r=e.topic.toString(),i=e.payload,n=e.qos,s=e.messageId,o=this,f=this.options,a=[0,16,128,131,135,144,145,151,153];switch(y("_handlePublish: qos %d",n),n){case 2:{f.customHandleAcks(r,i,e,function(l,u){if(l instanceof Error||(u=l,l=null),l)return o.emit("error",l);if(a.indexOf(u)===-1)return o.emit("error",new Error("Wrong reason code for pubrec"));u?o._sendPacket({cmd:"pubrec",messageId:s,reasonCode:u},t):o.incomingStore.put(e,function(){o._sendPacket({cmd:"pubrec",messageId:s},t)})});break}case 1:{f.customHandleAcks(r,i,e,function(l,u){if(l instanceof Error||(u=l,l=null),l)return o.emit("error",l);if(a.indexOf(u)===-1)return o.emit("error",new Error("Wrong reason code for puback"));u||o.emit("message",r,i,e),o.handleMessage(e,function(h){if(h)return t&&t(h);o._sendPacket({cmd:"puback",messageId:s,reasonCode:u},t)})});break}case 0:this.emit("message",r,i,e),this.handleMessage(e,t);break;default:y("_handlePublish: unknown QoS. Doing nothing.");break}};N.prototype.handleMessage=function(e,t){t()};N.prototype._handleAck=function(e){var t=e.messageId,r=e.cmd,i=null,n=this.outgoing[t]?this.outgoing[t].cb:null,s=this,o;if(!n){y("_handleAck :: Server sent an ack in error. Ignoring.");return}switch(y("_handleAck :: packet type",r),r){case"pubcomp":case"puback":var f=e.reasonCode;f&&f>0&&f!==16&&(o=new Error("Publish error: "+Wn[f]),o.code=f,n(o,e)),delete this.outgoing[t],this.outgoingStore.del(e,n);break;case"pubrec":i={cmd:"pubrel",qos:2,messageId:t};var a=e.reasonCode;a&&a>0&&a!==16?(o=new Error("Publish error: "+Wn[a]),o.code=a,n(o,e)):this._sendPacket(i);break;case"suback":delete this.outgoing[t];for(var l=0;l<e.granted.length;l++)if(e.granted[l]&128){var u=this.messageIdToTopic[t];u&&u.forEach(function(h){delete s._resubscribeTopics[h]})}n(null,e);break;case"unsuback":delete this.outgoing[t],n(null);break;default:s.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&Object.keys(this.outgoing).length===0&&this.emit("outgoingEmpty")};N.prototype._handlePubrel=function(e,t){y("handling pubrel packet"),t=typeof t<"u"?t:se;var r=e.messageId,i=this,n={cmd:"pubcomp",messageId:r};i.incomingStore.get(e,function(s,o){s?i._sendPacket(n,t):(i.emit("message",o.topic,o.payload,o),i.handleMessage(o,function(f){if(f)return t(f);i.incomingStore.del(o,se),i._sendPacket(n,t)}))})};N.prototype._handleDisconnect=function(e){this.emit("disconnect",e)};N.prototype._nextId=function(){var e=this.nextId++;return this.nextId===65536&&(this.nextId=1),e};N.prototype.getLastMessageId=function(){return this.nextId===1?65535:this.nextId-1};N.prototype._resubscribe=function(e){y("_resubscribe");var t=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||this.options.protocolVersion===5&&!e.sessionPresent)&&t.length>0)if(this.options.resubscribe)if(this.options.protocolVersion===5){y("_resubscribe: protocolVersion 5");for(var r=0;r<t.length;r++){var i={};i[t[r]]=this._resubscribeTopics[t[r]],i.resubscribe=!0,this.subscribe(i,{properties:i[t[r]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1};N.prototype._onConnect=function(e){if(this.disconnected){this.emit("connect",e);return}var t=this;this._setupPingTimer(),this._resubscribe(e),this.connected=!0;function r(){var i=t.outgoingStore.createStream();function n(){t._storeProcessing=!1,t._packetIdsDuringStoreProcessing={}}t.once("close",s),i.on("error",function(f){n(),t.removeListener("close",s),t.emit("error",f)});function s(){i.destroy(),i=null,n()}function o(){if(i){t._storeProcessing=!0;var f=i.read(1),a;if(!f){i.once("readable",o);return}if(t._packetIdsDuringStoreProcessing[f.messageId]){o();return}!t.disconnecting&&!t.reconnectTimer?(a=t.outgoing[f.messageId]?t.outgoing[f.messageId].cb:null,t.outgoing[f.messageId]={volatile:!1,cb:function(l,u){a&&a(l,u),o()}},t._packetIdsDuringStoreProcessing[f.messageId]=!0,t._sendPacket(f)):i.destroy&&i.destroy()}}i.on("end",function(){var f=!0;for(var a in t._packetIdsDuringStoreProcessing)if(!t._packetIdsDuringStoreProcessing[a]){f=!1;break}f?(n(),t.removeListener("close",s),t.emit("connect",e)):r()}),o()}r()};vf.exports=N});var $n=b((_w,mf)=>{"use strict";var M_=require("net"),L_=ze()("mqttjs:tcp");function q_(e,t){var r,i;return t.port=t.port||1883,t.hostname=t.hostname||t.host||"localhost",r=t.port,i=t.hostname,L_("port %d and host %s",r,i),M_.createConnection(r,i)}mf.exports=q_});var fi=b((gw,wf)=>{"use strict";var D_=require("tls"),U_=ze()("mqttjs:tls");function j_(e,t){var r;t.port=t.port||8883,t.host=t.hostname||t.host||"localhost",t.servername=t.host,t.rejectUnauthorized=t.rejectUnauthorized!==!1,delete t.path,U_("port %d host %s rejectUnauthorized %b",t.port,t.host,t.rejectUnauthorized),r=D_.connect(t),r.on("secureConnect",function(){t.rejectUnauthorized&&!r.authorized?r.emit("error",new Error("TLS not authorized")):r.removeListener("error",i)});function i(n){t.rejectUnauthorized&&e.emit("error",n),r.end()}return r.on("error",i),r}wf.exports=j_});var xf=b((bw,Ef)=>{Ef.exports=Sf;function Sf(e,t){if(e&&t)return Sf(e)(t);if(typeof e!="function")throw new TypeError("need wrapper function");return Object.keys(e).forEach(function(i){r[i]=e[i]}),r;function r(){for(var i=new Array(arguments.length),n=0;n<i.length;n++)i[n]=arguments[n];var s=e.apply(this,i),o=i[i.length-1];return typeof s=="function"&&s!==o&&Object.keys(o).forEach(function(f){s[f]=o[f]}),s}}});var If=b((yw,Gn)=>{var Cf=xf();Gn.exports=Cf(li);Gn.exports.strict=Cf(Tf);li.proto=li(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return li(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return Tf(this)},configurable:!0})});function li(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}function Tf(e){var t=function(){if(t.called)throw new Error(t.onceError);return t.called=!0,t.value=e.apply(this,arguments)},r=e.name||"Function wrapped with `once`";return t.onceError=r+" shouldn't be called more than once",t.called=!1,t}});var zn=b((vw,kf)=>{var F_=If(),W_=function(){},V_=function(e){return e.setHeader&&typeof e.abort=="function"},H_=function(e){return e.stdio&&Array.isArray(e.stdio)&&e.stdio.length===3},Of=function(e,t,r){if(typeof t=="function")return Of(e,null,t);t||(t={}),r=F_(r||W_);var i=e._writableState,n=e._readableState,s=t.readable||t.readable!==!1&&e.readable,o=t.writable||t.writable!==!1&&e.writable,f=!1,a=function(){e.writable||l()},l=function(){o=!1,s||r.call(e)},u=function(){s=!1,o||r.call(e)},h=function(m){r.call(e,m?new Error("exited with error code: "+m):null)},c=function(m){r.call(e,m)},d=function(){process.nextTick(_)},_=function(){if(!f){if(s&&!(n&&n.ended&&!n.destroyed))return r.call(e,new Error("premature close"));if(o&&!(i&&i.ended&&!i.destroyed))return r.call(e,new Error("premature close"))}},v=function(){e.req.on("finish",l)};return V_(e)?(e.on("complete",l),e.on("abort",d),e.req?v():e.on("request",v)):o&&!i&&(e.on("end",a),e.on("close",a)),H_(e)&&e.on("exit",h),e.on("end",u),e.on("finish",l),t.error!==!1&&e.on("error",c),e.on("close",d),function(){f=!0,e.removeListener("complete",l),e.removeListener("abort",d),e.removeListener("request",v),e.req&&e.req.removeListener("finish",l),e.removeListener("end",a),e.removeListener("close",a),e.removeListener("finish",l),e.removeListener("exit",h),e.removeListener("end",u),e.removeListener("error",c),e.removeListener("close",d)}};kf.exports=Of});var Kn=b((mw,Rf)=>{Rf.exports=$_;function $_(e){var t=e._readableState;return t?t.objectMode||typeof e._duplexState=="number"?e.read():e.read(G_(t)):null}function G_(e){if(e.buffer.length){var t=e.bufferIndex||0;if(e.buffer.head)return e.buffer.head.data.length;if(e.buffer.length-t>0&&e.buffer[t])return e.buffer[t].length}return e.length}});var ci=b((ww,Nf)=>{var ui=He(),Pf=zn(),z_=ie(),K_=Kn(),Bf=Buffer.from&&Buffer.from!==Uint8Array.from?Buffer.from([0]):new Buffer([0]),Yn=function(e,t){e._corked?e.once("uncork",t):t()},Y_=function(e,t){e._autoDestroy&&e.destroy(t)},Af=function(e,t){return function(r){r?Y_(e,r.message==="premature close"?null:r):t&&!e._ended&&e.end()}},Q_=function(e,t){if(!e||e._writableState&&e._writableState.finished)return t();if(e._writableState)return e.end(t);e.end(),t()},J_=function(){},X_=function(e){return new ui.Readable({objectMode:!0,highWaterMark:16}).wrap(e)},J=function(e,t,r){if(!(this instanceof J))return new J(e,t,r);ui.Duplex.call(this,r),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!r||r.autoDestroy!==!1,this._forwardDestroy=!r||r.destroy!==!1,this._forwardEnd=!r||r.end!==!1,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,e&&this.setWritable(e),t&&this.setReadable(t)};z_(J,ui.Duplex);J.obj=function(e,t,r){return r||(r={}),r.objectMode=!0,r.highWaterMark=16,new J(e,t,r)};J.prototype.cork=function(){++this._corked===1&&this.emit("cork")};J.prototype.uncork=function(){this._corked&&--this._corked===0&&this.emit("uncork")};J.prototype.setWritable=function(e){if(this._unwrite&&this._unwrite(),this.destroyed){e&&e.destroy&&e.destroy();return}if(e===null||e===!1){this.end();return}var t=this,r=Pf(e,{writable:!0,readable:!1},Af(this,this._forwardEnd)),i=function(){var s=t._ondrain;t._ondrain=null,s&&s()},n=function(){t._writable.removeListener("drain",i),r()};this._unwrite&&process.nextTick(i),this._writable=e,this._writable.on("drain",i),this._unwrite=n,this.uncork()};J.prototype.setReadable=function(e){if(this._unread&&this._unread(),this.destroyed){e&&e.destroy&&e.destroy();return}if(e===null||e===!1){this.push(null),this.resume();return}var t=this,r=Pf(e,{writable:!1,readable:!0},Af(this)),i=function(){t._forward()},n=function(){t.push(null)},s=function(){t._readable2.removeListener("readable",i),t._readable2.removeListener("end",n),r()};this._drained=!0,this._readable=e,this._readable2=e._readableState?e:X_(e),this._readable2.on("readable",i),this._readable2.on("end",n),this._unread=s,this._forward()};J.prototype._read=function(){this._drained=!0,this._forward()};J.prototype._forward=function(){if(!(this._forwarding||!this._readable2||!this._drained)){this._forwarding=!0;for(var e;this._drained&&(e=K_(this._readable2))!==null;)this.destroyed||(this._drained=this.push(e));this._forwarding=!1}};J.prototype.destroy=function(e,t){if(t||(t=J_),this.destroyed)return t(null);this.destroyed=!0;var r=this;process.nextTick(function(){r._destroy(e),t(null)})};J.prototype._destroy=function(e){if(e){var t=this._ondrain;this._ondrain=null,t?t(e):this.emit("error",e)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")};J.prototype._write=function(e,t,r){if(!this.destroyed){if(this._corked)return Yn(this,this._write.bind(this,e,t,r));if(e===Bf)return this._finish(r);if(!this._writable)return r();this._writable.write(e)===!1?this._ondrain=r:this.destroyed||r()}};J.prototype._finish=function(e){var t=this;this.emit("preend"),Yn(this,function(){Q_(t._forwardEnd&&t._writable,function(){t._writableState.prefinished===!1&&(t._writableState.prefinished=!0),t.emit("prefinish"),Yn(t,e)})})};J.prototype.end=function(e,t,r){return typeof e=="function"?this.end(null,null,e):typeof t=="function"?this.end(e,null,t):(this._ended=!0,e&&this.write(e),!this._writableState.ending&&!this._writableState.destroyed&&this.write(Bf),ui.Writable.prototype.end.call(this,r))};Nf.exports=J});var Qn=b((Sw,Mf)=>{"use strict";var Z_=He().Transform,eg=ci(),Re,hi,le;function tg(){var e=new Z_;return e._write=function(t,r,i){Re.send({data:t.buffer,success:function(){i()},fail:function(n){i(new Error(n))}})},e._flush=function(r){Re.close({success:function(){r()}})},e}function rg(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}function ig(e,t){var r=e.protocol==="wxs"?"wss":"ws",i=r+"://"+e.hostname+e.path;return e.port&&e.port!==80&&e.port!==443&&(i=r+"://"+e.hostname+":"+e.port+e.path),typeof e.transformWsUrl=="function"&&(i=e.transformWsUrl(i,e,t)),i}function ng(){Re.onOpen(function(){le.setReadable(hi),le.setWritable(hi),le.emit("connect")}),Re.onMessage(function(e){var t=e.data;t instanceof ArrayBuffer?t=Buffer.from(t):t=Buffer.from(t,"utf8"),hi.push(t)}),Re.onClose(function(){le.end(),le.destroy()}),Re.onError(function(e){le.destroy(new Error(e.errMsg))})}function sg(e,t){if(t.hostname=t.hostname||t.host,!t.hostname)throw new Error("Could not determine host. Specify host manually.");var r=t.protocolId==="MQIsdp"&&t.protocolVersion===3?"mqttv3.1":"mqtt";rg(t);var i=ig(t,e);Re=wx.connectSocket({url:i,protocols:[r]}),hi=tg(),le=eg.obj(),le._destroy=function(s,o){Re.close({success:function(){o&&o(s)}})};var n=le.destroy;return le.destroy=function(){le.destroy=n;var s=this;setTimeout(function(){Re.close({fail:function(){s._destroy(new Error)}})},0)}.bind(le),ng(),le}Mf.exports=sg});var Jn=b((Ew,qf)=>{"use strict";var og=He().Transform,ag=ci(),Qe,Xt,Ye,Lf=!1;function fg(){var e=new og;return e._write=function(t,r,i){Qe.sendSocketMessage({data:t.buffer,success:function(){i()},fail:function(){i(new Error)}})},e._flush=function(r){Qe.closeSocket({success:function(){r()}})},e}function lg(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}function ug(e,t){var r=e.protocol==="alis"?"wss":"ws",i=r+"://"+e.hostname+e.path;return e.port&&e.port!==80&&e.port!==443&&(i=r+"://"+e.hostname+":"+e.port+e.path),typeof e.transformWsUrl=="function"&&(i=e.transformWsUrl(i,e,t)),i}function cg(){Lf||(Lf=!0,Qe.onSocketOpen(function(){Ye.setReadable(Xt),Ye.setWritable(Xt),Ye.emit("connect")}),Qe.onSocketMessage(function(e){if(typeof e.data=="string"){var t=Buffer.from(e.data,"base64");Xt.push(t)}else{var r=new FileReader;r.addEventListener("load",function(){var i=r.result;i instanceof ArrayBuffer?i=Buffer.from(i):i=Buffer.from(i,"utf8"),Xt.push(i)}),r.readAsArrayBuffer(e.data)}}),Qe.onSocketClose(function(){Ye.end(),Ye.destroy()}),Qe.onSocketError(function(e){Ye.destroy(e)}))}function hg(e,t){if(t.hostname=t.hostname||t.host,!t.hostname)throw new Error("Could not determine host. Specify host manually.");var r=t.protocolId==="MQIsdp"&&t.protocolVersion===3?"mqttv3.1":"mqtt";lg(t);var i=ug(t,e);return Qe=t.my,Qe.connectSocket({url:i,protocols:r}),Xt=fg(),Ye=ag.obj(),cg(),Ye}qf.exports=hg});var ut=b((xw,Df)=>{"use strict";Df.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),EMPTY_BUFFER:Buffer.alloc(0),NOOP:()=>{}}});var Zt=b((Cw,Xn)=>{"use strict";var{EMPTY_BUFFER:dg}=ut();function Uf(e,t){if(e.length===0)return dg;if(e.length===1)return e[0];let r=Buffer.allocUnsafe(t),i=0;for(let n=0;n<e.length;n++){let s=e[n];r.set(s,i),i+=s.length}return i<t?r.slice(0,i):r}function jf(e,t,r,i,n){for(let s=0;s<n;s++)r[i+s]=e[s]^t[s&3]}function Ff(e,t){let r=e.length;for(let i=0;i<r;i++)e[i]^=t[i&3]}function Wf(e){return e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function di(e){if(di.readOnly=!0,Buffer.isBuffer(e))return e;let t;return e instanceof ArrayBuffer?t=Buffer.from(e):ArrayBuffer.isView(e)?t=Buffer.from(e.buffer,e.byteOffset,e.byteLength):(t=Buffer.from(e),di.readOnly=!1),t}try{let e=require("bufferutil"),t=e.BufferUtil||e;Xn.exports={concat:Uf,mask(r,i,n,s,o){o<48?jf(r,i,n,s,o):t.mask(r,i,n,s,o)},toArrayBuffer:Wf,toBuffer:di,unmask(r,i){r.length<32?Ff(r,i):t.unmask(r,i)}}}catch{Xn.exports={concat:Uf,mask:jf,toArrayBuffer:Wf,toBuffer:di,unmask:Ff}}});var $f=b((Tw,Hf)=>{"use strict";var Vf=Symbol("kDone"),Zn=Symbol("kRun"),es=class{constructor(t){this[Vf]=()=>{this.pending--,this[Zn]()},this.concurrency=t||1/0,this.jobs=[],this.pending=0}add(t){this.jobs.push(t),this[Zn]()}[Zn](){if(this.pending!==this.concurrency&&this.jobs.length){let t=this.jobs.shift();this.pending++,t(this[Vf])}}};Hf.exports=es});var rr=b((Iw,Yf)=>{"use strict";var er=require("zlib"),Gf=Zt(),pg=$f(),{kStatusCode:zf,NOOP:_g}=ut(),gg=Buffer.from([0,0,255,255]),gi=Symbol("permessage-deflate"),Pe=Symbol("total-length"),tr=Symbol("callback"),Je=Symbol("buffers"),_i=Symbol("error"),pi,ts=class{constructor(t,r,i){if(this._maxPayload=i|0,this._options=t||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!pi){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;pi=new pg(n)}}static get extensionName(){return"permessage-deflate"}offer(){let t={};return this._options.serverNoContextTakeover&&(t.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(t.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(t.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?t.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(t.client_max_window_bits=!0),t}accept(t){return t=this.normalizeParams(t),this.params=this._isServer?this.acceptAsServer(t):this.acceptAsClient(t),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let t=this._deflate[tr];this._deflate.close(),this._deflate=null,t&&t(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(t){let r=this._options,i=t.find(n=>!(r.serverNoContextTakeover===!1&&n.server_no_context_takeover||n.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>n.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!n.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(t){let r=t[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(t){return t.forEach(r=>{Object.keys(r).forEach(i=>{let n=r[i];if(n.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(n=n[0],i==="client_max_window_bits"){if(n!==!0){let s=+n;if(!Number.isInteger(s)||s<8||s>15)throw new TypeError(`Invalid value for parameter "${i}": ${n}`);n=s}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${n}`)}else if(i==="server_max_window_bits"){let s=+n;if(!Number.isInteger(s)||s<8||s>15)throw new TypeError(`Invalid value for parameter "${i}": ${n}`);n=s}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(n!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${n}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=n})}),t}decompress(t,r,i){pi.add(n=>{this._decompress(t,r,(s,o)=>{n(),i(s,o)})})}compress(t,r,i){pi.add(n=>{this._compress(t,r,(s,o)=>{n(),i(s,o)})})}_decompress(t,r,i){let n=this._isServer?"client":"server";if(!this._inflate){let s=`${n}_max_window_bits`,o=typeof this.params[s]!="number"?er.Z_DEFAULT_WINDOWBITS:this.params[s];this._inflate=er.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[gi]=this,this._inflate[Pe]=0,this._inflate[Je]=[],this._inflate.on("error",yg),this._inflate.on("data",Kf)}this._inflate[tr]=i,this._inflate.write(t),r&&this._inflate.write(gg),this._inflate.flush(()=>{let s=this._inflate[_i];if(s){this._inflate.close(),this._inflate=null,i(s);return}let o=Gf.concat(this._inflate[Je],this._inflate[Pe]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Pe]=0,this._inflate[Je]=[],r&&this.params[`${n}_no_context_takeover`]&&this._inflate.reset()),i(null,o)})}_compress(t,r,i){let n=this._isServer?"server":"client";if(!this._deflate){let s=`${n}_max_window_bits`,o=typeof this.params[s]!="number"?er.Z_DEFAULT_WINDOWBITS:this.params[s];this._deflate=er.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[Pe]=0,this._deflate[Je]=[],this._deflate.on("error",_g),this._deflate.on("data",bg)}this._deflate[tr]=i,this._deflate.write(t),this._deflate.flush(er.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let s=Gf.concat(this._deflate[Je],this._deflate[Pe]);r&&(s=s.slice(0,s.length-4)),this._deflate[tr]=null,this._deflate[Pe]=0,this._deflate[Je]=[],r&&this.params[`${n}_no_context_takeover`]&&this._deflate.reset(),i(null,s)})}};Yf.exports=ts;function bg(e){this[Je].push(e),this[Pe]+=e.length}function Kf(e){if(this[Pe]+=e.length,this[gi]._maxPayload<1||this[Pe]<=this[gi]._maxPayload){this[Je].push(e);return}this[_i]=new RangeError("Max payload size exceeded"),this[_i].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[_i][zf]=1009,this.removeListener("data",Kf),this.reset()}function yg(e){this[gi]._inflate=null,e[zf]=1007,this[tr](e)}});var is=b((Ow,rs)=>{"use strict";function Qf(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function Jf(e){let t=e.length,r=0;for(;r<t;)if(!(e[r]&128))r++;else if((e[r]&224)===192){if(r+1===t||(e[r+1]&192)!==128||(e[r]&254)===192)return!1;r+=2}else if((e[r]&240)===224){if(r+2>=t||(e[r+1]&192)!==128||(e[r+2]&192)!==128||e[r]===224&&(e[r+1]&224)===128||e[r]===237&&(e[r+1]&224)===160)return!1;r+=3}else if((e[r]&248)===240){if(r+3>=t||(e[r+1]&192)!==128||(e[r+2]&192)!==128||(e[r+3]&192)!==128||e[r]===240&&(e[r+1]&240)===128||e[r]===244&&e[r+1]>143||e[r]>244)return!1;r+=4}else return!1;return!0}try{let e=require("utf-8-validate");typeof e=="object"&&(e=e.Validation.isValidUTF8),rs.exports={isValidStatusCode:Qf,isValidUTF8(t){return t.length<150?Jf(t):e(t)}}}catch{rs.exports={isValidStatusCode:Qf,isValidUTF8:Jf}}});var as=b((kw,il)=>{"use strict";var{Writable:vg}=require("stream"),Xf=rr(),{BINARY_TYPES:mg,EMPTY_BUFFER:wg,kStatusCode:Sg,kWebSocket:Eg}=ut(),{concat:ns,toArrayBuffer:xg,unmask:Cg}=Zt(),{isValidStatusCode:Tg,isValidUTF8:Zf}=is(),ir=0,el=1,tl=2,rl=3,ss=4,Ig=5,os=class extends vg{constructor(t,r,i,n){super(),this._binaryType=t||mg[0],this[Eg]=void 0,this._extensions=r||{},this._isServer=!!i,this._maxPayload=n|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._state=ir,this._loop=!1}_write(t,r,i){if(this._opcode===8&&this._state==ir)return i();this._bufferedBytes+=t.length,this._buffers.push(t),this.startLoop(i)}consume(t){if(this._bufferedBytes-=t,t===this._buffers[0].length)return this._buffers.shift();if(t<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=i.slice(t),i.slice(0,t)}let r=Buffer.allocUnsafe(t);do{let i=this._buffers[0],n=r.length-t;t>=i.length?r.set(this._buffers.shift(),n):(r.set(new Uint8Array(i.buffer,i.byteOffset,t),n),this._buffers[0]=i.slice(t)),t-=i.length}while(t>0);return r}startLoop(t){let r;this._loop=!0;do switch(this._state){case ir:r=this.getInfo();break;case el:r=this.getPayloadLength16();break;case tl:r=this.getPayloadLength64();break;case rl:this.getMask();break;case ss:r=this.getData(t);break;default:this._loop=!1;return}while(this._loop);t(r)}getInfo(){if(this._bufferedBytes<2){this._loop=!1;return}let t=this.consume(2);if(t[0]&48)return this._loop=!1,K(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");let r=(t[0]&64)===64;if(r&&!this._extensions[Xf.extensionName])return this._loop=!1,K(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");if(this._fin=(t[0]&128)===128,this._opcode=t[0]&15,this._payloadLength=t[1]&127,this._opcode===0){if(r)return this._loop=!1,K(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");if(!this._fragmented)return this._loop=!1,K(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented)return this._loop=!1,K(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin)return this._loop=!1,K(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");if(r)return this._loop=!1,K(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");if(this._payloadLength>125)return this._loop=!1,K(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH")}else return this._loop=!1,K(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(t[1]&128)===128,this._isServer){if(!this._masked)return this._loop=!1,K(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK")}else if(this._masked)return this._loop=!1,K(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");if(this._payloadLength===126)this._state=el;else if(this._payloadLength===127)this._state=tl;else return this.haveLength()}getPayloadLength16(){if(this._bufferedBytes<2){this._loop=!1;return}return this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength()}getPayloadLength64(){if(this._bufferedBytes<8){this._loop=!1;return}let t=this.consume(8),r=t.readUInt32BE(0);return r>Math.pow(2,21)-1?(this._loop=!1,K(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH")):(this._payloadLength=r*Math.pow(2,32)+t.readUInt32BE(4),this.haveLength())}haveLength(){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0))return this._loop=!1,K(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");this._masked?this._state=rl:this._state=ss}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=ss}getData(t){let r=wg;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&Cg(r,this._mask)}if(this._opcode>7)return this.controlMessage(r);if(this._compressed){this._state=Ig,this.decompress(r,t);return}return r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage()}decompress(t,r){this._extensions[Xf.extensionName].decompress(t,this._fin,(n,s)=>{if(n)return r(n);if(s.length){if(this._messageLength+=s.length,this._messageLength>this._maxPayload&&this._maxPayload>0)return r(K(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));this._fragments.push(s)}let o=this.dataMessage();if(o)return r(o);this.startLoop(r)})}dataMessage(){if(this._fin){let t=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=ns(r,t):this._binaryType==="arraybuffer"?i=xg(ns(r,t)):i=r,this.emit("message",i)}else{let i=ns(r,t);if(!Zf(i))return this._loop=!1,K(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");this.emit("message",i.toString())}}this._state=ir}controlMessage(t){if(this._opcode===8)if(this._loop=!1,t.length===0)this.emit("conclude",1005,""),this.end();else{if(t.length===1)return K(RangeError,"invalid payload length 1",!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");{let r=t.readUInt16BE(0);if(!Tg(r))return K(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");let i=t.slice(2);if(!Zf(i))return K(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");this.emit("conclude",r,i.toString()),this.end()}}else this._opcode===9?this.emit("ping",t):this.emit("pong",t);this._state=ir}};il.exports=os;function K(e,t,r,i,n){let s=new e(r?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(s,K),s.code=n,s[Sg]=i,s}});var ls=b((Bw,ol)=>{"use strict";var Rw=require("net"),Pw=require("tls"),{randomFillSync:Og}=require("crypto"),nl=rr(),{EMPTY_BUFFER:kg}=ut(),{isValidStatusCode:Rg}=is(),{mask:sl,toBuffer:Be}=Zt(),ct=Buffer.alloc(4),fs=class e{constructor(t,r){this._extensions=r||{},this._socket=t,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(t,r){let i=r.mask&&r.readOnly,n=r.mask?6:2,s=t.length;t.length>=65536?(n+=8,s=127):t.length>125&&(n+=2,s=126);let o=Buffer.allocUnsafe(i?t.length+n:n);return o[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(o[0]|=64),o[1]=s,s===126?o.writeUInt16BE(t.length,2):s===127&&(o.writeUInt32BE(0,2),o.writeUInt32BE(t.length,6)),r.mask?(Og(ct,0,4),o[1]|=128,o[n-4]=ct[0],o[n-3]=ct[1],o[n-2]=ct[2],o[n-1]=ct[3],i?(sl(t,ct,o,n,t.length),[o]):(sl(t,ct,t,0,t.length),[o,t])):[o,t]}close(t,r,i,n){let s;if(t===void 0)s=kg;else{if(typeof t!="number"||!Rg(t))throw new TypeError("First argument must be a valid error code number");if(r===void 0||r==="")s=Buffer.allocUnsafe(2),s.writeUInt16BE(t,0);else{let o=Buffer.byteLength(r);if(o>123)throw new RangeError("The message must not be greater than 123 bytes");s=Buffer.allocUnsafe(2+o),s.writeUInt16BE(t,0),s.write(r,2)}}this._deflating?this.enqueue([this.doClose,s,i,n]):this.doClose(s,i,n)}doClose(t,r,i){this.sendFrame(e.frame(t,{fin:!0,rsv1:!1,opcode:8,mask:r,readOnly:!1}),i)}ping(t,r,i){let n=Be(t);if(n.length>125)throw new RangeError("The data size must not be greater than 125 bytes");this._deflating?this.enqueue([this.doPing,n,r,Be.readOnly,i]):this.doPing(n,r,Be.readOnly,i)}doPing(t,r,i,n){this.sendFrame(e.frame(t,{fin:!0,rsv1:!1,opcode:9,mask:r,readOnly:i}),n)}pong(t,r,i){let n=Be(t);if(n.length>125)throw new RangeError("The data size must not be greater than 125 bytes");this._deflating?this.enqueue([this.doPong,n,r,Be.readOnly,i]):this.doPong(n,r,Be.readOnly,i)}doPong(t,r,i,n){this.sendFrame(e.frame(t,{fin:!0,rsv1:!1,opcode:10,mask:r,readOnly:i}),n)}send(t,r,i){let n=Be(t),s=this._extensions[nl.extensionName],o=r.binary?2:1,f=r.compress;if(this._firstFragment?(this._firstFragment=!1,f&&s&&(f=n.length>=s._threshold),this._compress=f):(f=!1,o=0),r.fin&&(this._firstFragment=!0),s){let a={fin:r.fin,rsv1:f,opcode:o,mask:r.mask,readOnly:Be.readOnly};this._deflating?this.enqueue([this.dispatch,n,this._compress,a,i]):this.dispatch(n,this._compress,a,i)}else this.sendFrame(e.frame(n,{fin:r.fin,rsv1:!1,opcode:o,mask:r.mask,readOnly:Be.readOnly}),i)}dispatch(t,r,i,n){if(!r){this.sendFrame(e.frame(t,i),n);return}let s=this._extensions[nl.extensionName];this._bufferedBytes+=t.length,this._deflating=!0,s.compress(t,i.fin,(o,f)=>{if(this._socket.destroyed){let a=new Error("The socket was closed while data was being compressed");typeof n=="function"&&n(a);for(let l=0;l<this._queue.length;l++){let u=this._queue[l][4];typeof u=="function"&&u(a)}return}this._bufferedBytes-=t.length,this._deflating=!1,i.readOnly=!1,this.sendFrame(e.frame(f,i),n),this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){let t=this._queue.shift();this._bufferedBytes-=t[1].length,Reflect.apply(t[0],this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[1].length,this._queue.push(t)}sendFrame(t,r){t.length===2?(this._socket.cork(),this._socket.write(t[0]),this._socket.write(t[1],r),this._socket.uncork()):this._socket.write(t[0],r)}};ol.exports=fs});var fl=b((Aw,al)=>{"use strict";var kt=class{constructor(t,r){this.target=r,this.type=t}},us=class extends kt{constructor(t,r){super("message",r),this.data=t}},cs=class extends kt{constructor(t,r,i){super("close",i),this.wasClean=i._closeFrameReceived&&i._closeFrameSent,this.reason=r,this.code=t}},hs=class extends kt{constructor(t){super("open",t)}},ds=class extends kt{constructor(t,r){super("error",r),this.message=t.message,this.error=t}},Pg={addEventListener(e,t,r){if(typeof t!="function")return;function i(a){t.call(this,new us(a,this))}function n(a,l){t.call(this,new cs(a,l,this))}function s(a){t.call(this,new ds(a,this))}function o(){t.call(this,new hs(this))}let f=r&&r.once?"once":"on";e==="message"?(i._listener=t,this[f](e,i)):e==="close"?(n._listener=t,this[f](e,n)):e==="error"?(s._listener=t,this[f](e,s)):e==="open"?(o._listener=t,this[f](e,o)):this[f](e,t)},removeEventListener(e,t){let r=this.listeners(e);for(let i=0;i<r.length;i++)(r[i]===t||r[i]._listener===t)&&this.removeListener(e,r[i])}};al.exports=Pg});var ps=b((Nw,ll)=>{"use strict";var nr=[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 Ce(e,t,r){e[t]===void 0?e[t]=[r]:e[t].push(r)}function Bg(e){let t=Object.create(null);if(e===void 0||e==="")return t;let r=Object.create(null),i=!1,n=!1,s=!1,o,f,a=-1,l=-1,u=0;for(;u<e.length;u++){let c=e.charCodeAt(u);if(o===void 0)if(l===-1&&nr[c]===1)a===-1&&(a=u);else if(c===32||c===9)l===-1&&a!==-1&&(l=u);else if(c===59||c===44){if(a===-1)throw new SyntaxError(`Unexpected character at index ${u}`);l===-1&&(l=u);let d=e.slice(a,l);c===44?(Ce(t,d,r),r=Object.create(null)):o=d,a=l=-1}else throw new SyntaxError(`Unexpected character at index ${u}`);else if(f===void 0)if(l===-1&&nr[c]===1)a===-1&&(a=u);else if(c===32||c===9)l===-1&&a!==-1&&(l=u);else if(c===59||c===44){if(a===-1)throw new SyntaxError(`Unexpected character at index ${u}`);l===-1&&(l=u),Ce(r,e.slice(a,l),!0),c===44&&(Ce(t,o,r),r=Object.create(null),o=void 0),a=l=-1}else if(c===61&&a!==-1&&l===-1)f=e.slice(a,u),a=l=-1;else throw new SyntaxError(`Unexpected character at index ${u}`);else if(n){if(nr[c]!==1)throw new SyntaxError(`Unexpected character at index ${u}`);a===-1?a=u:i||(i=!0),n=!1}else if(s)if(nr[c]===1)a===-1&&(a=u);else if(c===34&&a!==-1)s=!1,l=u;else if(c===92)n=!0;else throw new SyntaxError(`Unexpected character at index ${u}`);else if(c===34&&e.charCodeAt(u-1)===61)s=!0;else if(l===-1&&nr[c]===1)a===-1&&(a=u);else if(a!==-1&&(c===32||c===9))l===-1&&(l=u);else if(c===59||c===44){if(a===-1)throw new SyntaxError(`Unexpected character at index ${u}`);l===-1&&(l=u);let d=e.slice(a,l);i&&(d=d.replace(/\\/g,""),i=!1),Ce(r,f,d),c===44&&(Ce(t,o,r),r=Object.create(null),o=void 0),f=void 0,a=l=-1}else throw new SyntaxError(`Unexpected character at index ${u}`)}if(a===-1||s)throw new SyntaxError("Unexpected end of input");l===-1&&(l=u);let h=e.slice(a,l);return o===void 0?Ce(t,h,r):(f===void 0?Ce(r,h,!0):i?Ce(r,f,h.replace(/\\/g,"")):Ce(r,f,h),Ce(t,o,r)),t}function Ag(e){return Object.keys(e).map(t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map(i=>[t].concat(Object.keys(i).map(n=>{let s=i[n];return Array.isArray(s)||(s=[s]),s.map(o=>o===!0?n:`${n}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}ll.exports={format:Ag,parse:Bg}});var ms=b((Lw,vl)=>{"use strict";var Ng=require("events"),Mg=require("https"),Lg=require("http"),hl=require("net"),qg=require("tls"),{randomBytes:Dg,createHash:Ug}=require("crypto"),{Readable:Mw}=require("stream"),{URL:_s}=require("url"),Xe=rr(),jg=as(),Fg=ls(),{BINARY_TYPES:ul,EMPTY_BUFFER:gs,GUID:Wg,kStatusCode:Vg,kWebSocket:te,NOOP:dl}=ut(),{addEventListener:Hg,removeEventListener:$g}=fl(),{format:Gg,parse:zg}=ps(),{toBuffer:Kg}=Zt(),Ae=["CONNECTING","OPEN","CLOSING","CLOSED"],bs=[8,13],Yg=30*1e3,G=class e extends Ng{constructor(t,r,i){super(),this._binaryType=ul[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage="",this._closeTimer=null,this._extensions={},this._protocol="",this._readyState=e.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,t!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,Array.isArray(r)?r=r.join(", "):typeof r=="object"&&r!==null&&(i=r,r=void 0),pl(this,t,r,i)):this._isServer=!0}get binaryType(){return this._binaryType}set binaryType(t){ul.includes(t)&&(this._binaryType=t,this._receiver&&(this._receiver._binaryType=t))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get onclose(){}set onclose(t){}get onerror(){}set onerror(t){}get onopen(){}set onopen(t){}get onmessage(){}set onmessage(t){}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(t,r,i){let n=new jg(this.binaryType,this._extensions,this._isServer,i);this._sender=new Fg(t,this._extensions),this._receiver=n,this._socket=t,n[te]=this,t[te]=this,n.on("conclude",Xg),n.on("drain",Zg),n.on("error",eb),n.on("message",tb),n.on("ping",rb),n.on("pong",ib),t.setTimeout(0),t.setNoDelay(),r.length>0&&t.unshift(r),t.on("close",gl),t.on("data",bi),t.on("end",bl),t.on("error",yl),this._readyState=e.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[Xe.extensionName]&&this._extensions[Xe.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(t,r){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING)return ue(this,this._req,"WebSocket was closed before the connection was established");if(this.readyState===e.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=e.CLOSING,this._sender.close(t,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),Yg)}}ping(t,r,i){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof t=="function"?(i=t,t=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){vs(this,t,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(t||gs,r,i)}pong(t,r,i){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof t=="function"?(i=t,t=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){vs(this,t,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(t||gs,r,i)}send(t,r,i){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){vs(this,t,i);return}let n={binary:typeof t!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Xe.extensionName]||(n.compress=!1),this._sender.send(t||gs,n,i)}terminate(){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING)return ue(this,this._req,"WebSocket was closed before the connection was established");this._socket&&(this._readyState=e.CLOSING,this._socket.destroy())}}};Object.defineProperty(G,"CONNECTING",{enumerable:!0,value:Ae.indexOf("CONNECTING")});Object.defineProperty(G.prototype,"CONNECTING",{enumerable:!0,value:Ae.indexOf("CONNECTING")});Object.defineProperty(G,"OPEN",{enumerable:!0,value:Ae.indexOf("OPEN")});Object.defineProperty(G.prototype,"OPEN",{enumerable:!0,value:Ae.indexOf("OPEN")});Object.defineProperty(G,"CLOSING",{enumerable:!0,value:Ae.indexOf("CLOSING")});Object.defineProperty(G.prototype,"CLOSING",{enumerable:!0,value:Ae.indexOf("CLOSING")});Object.defineProperty(G,"CLOSED",{enumerable:!0,value:Ae.indexOf("CLOSED")});Object.defineProperty(G.prototype,"CLOSED",{enumerable:!0,value:Ae.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","protocol","readyState","url"].forEach(e=>{Object.defineProperty(G.prototype,e,{enumerable:!0})});["open","error","close","message"].forEach(e=>{Object.defineProperty(G.prototype,`on${e}`,{enumerable:!0,get(){let t=this.listeners(e);for(let r=0;r<t.length;r++)if(t[r]._listener)return t[r]._listener},set(t){let r=this.listeners(e);for(let i=0;i<r.length;i++)r[i]._listener&&this.removeListener(e,r[i]);this.addEventListener(e,t)}})});G.prototype.addEventListener=Hg;G.prototype.removeEventListener=$g;vl.exports=G;function pl(e,t,r,i){let n={protocolVersion:bs[1],maxPayload:104857600,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,createConnection:void 0,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:void 0,host:void 0,path:void 0,port:void 0};if(!bs.includes(n.protocolVersion))throw new RangeError(`Unsupported protocol version: ${n.protocolVersion} (supported versions: ${bs.join(", ")})`);let s;t instanceof _s?(s=t,e._url=t.href):(s=new _s(t),e._url=t);let o=s.protocol==="ws+unix:";if(!s.host&&(!o||!s.pathname)){let d=new Error(`Invalid URL: ${e.url}`);if(e._redirects===0)throw d;ys(e,d);return}let f=s.protocol==="wss:"||s.protocol==="https:",a=f?443:80,l=Dg(16).toString("base64"),u=f?Mg.get:Lg.get,h;if(n.createConnection=f?Jg:Qg,n.defaultPort=n.defaultPort||a,n.port=s.port||a,n.host=s.hostname.startsWith("[")?s.hostname.slice(1,-1):s.hostname,n.headers={"Sec-WebSocket-Version":n.protocolVersion,"Sec-WebSocket-Key":l,Connection:"Upgrade",Upgrade:"websocket",...n.headers},n.path=s.pathname+s.search,n.timeout=n.handshakeTimeout,n.perMessageDeflate&&(h=new Xe(n.perMessageDeflate!==!0?n.perMessageDeflate:{},!1,n.maxPayload),n.headers["Sec-WebSocket-Extensions"]=Gg({[Xe.extensionName]:h.offer()})),r&&(n.headers["Sec-WebSocket-Protocol"]=r),n.origin&&(n.protocolVersion<13?n.headers["Sec-WebSocket-Origin"]=n.origin:n.headers.Origin=n.origin),(s.username||s.password)&&(n.auth=`${s.username}:${s.password}`),o){let d=n.path.split(":");n.socketPath=d[0],n.path=d[1]}if(n.followRedirects){if(e._redirects===0){e._originalUnixSocket=o,e._originalSecure=f,e._originalHostOrSocketPath=o?n.socketPath:s.host;let d=i&&i.headers;if(i={...i,headers:{}},d)for(let[_,v]of Object.entries(d))i.headers[_.toLowerCase()]=v}else{let d=o?e._originalUnixSocket?n.socketPath===e._originalHostOrSocketPath:!1:e._originalUnixSocket?!1:s.host===e._originalHostOrSocketPath;(!d||e._originalSecure&&!f)&&(delete n.headers.authorization,delete n.headers.cookie,d||delete n.headers.host,n.auth=void 0)}n.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(n.auth).toString("base64"))}let c=e._req=u(n);n.timeout&&c.on("timeout",()=>{ue(e,c,"Opening handshake has timed out")}),c.on("error",d=>{c===null||c.aborted||(c=e._req=null,ys(e,d))}),c.on("response",d=>{let _=d.headers.location,v=d.statusCode;if(_&&n.followRedirects&&v>=300&&v<400){if(++e._redirects>n.maxRedirects){ue(e,c,"Maximum redirects exceeded");return}c.abort();let m;try{m=new _s(_,t)}catch(p){ys(e,p);return}pl(e,m,r,i)}else e.emit("unexpected-response",c,d)||ue(e,c,`Unexpected server response: ${d.statusCode}`)}),c.on("upgrade",(d,_,v)=>{if(e.emit("upgrade",d),e.readyState!==G.CONNECTING)return;if(c=e._req=null,d.headers.upgrade.toLowerCase()!=="websocket"){ue(e,_,"Invalid Upgrade header");return}let m=Ug("sha1").update(l+Wg).digest("base64");if(d.headers["sec-websocket-accept"]!==m){ue(e,_,"Invalid Sec-WebSocket-Accept header");return}let p=d.headers["sec-websocket-protocol"],g=(r||"").split(/, */),S;if(!r&&p?S="Server sent a subprotocol but none was requested":r&&!p?S="Server sent no subprotocol":p&&!g.includes(p)&&(S="Server sent an invalid subprotocol"),S){ue(e,_,S);return}p&&(e._protocol=p);let x=d.headers["sec-websocket-extensions"];if(x!==void 0){if(!h){ue(e,_,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let C;try{C=zg(x)}catch{ue(e,_,"Invalid Sec-WebSocket-Extensions header");return}let w=Object.keys(C);if(w.length){if(w.length!==1||w[0]!==Xe.extensionName){ue(e,_,"Server indicated an extension that was not requested");return}try{h.accept(C[Xe.extensionName])}catch{ue(e,_,"Invalid Sec-WebSocket-Extensions header");return}e._extensions[Xe.extensionName]=h}}e.setSocket(_,v,n.maxPayload)})}function ys(e,t){e._readyState=G.CLOSING,e.emit("error",t),e.emitClose()}function Qg(e){return e.path=e.socketPath,hl.connect(e)}function Jg(e){return e.path=void 0,!e.servername&&e.servername!==""&&(e.servername=hl.isIP(e.host)?"":e.host),qg.connect(e)}function ue(e,t,r){e._readyState=G.CLOSING;let i=new Error(r);Error.captureStackTrace(i,ue),t.setHeader?(t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),t.once("abort",e.emitClose.bind(e)),e.emit("error",i)):(t.destroy(i),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function vs(e,t,r){if(t){let i=Kg(t).length;e._socket?e._sender._bufferedBytes+=i:e._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${e.readyState} (${Ae[e.readyState]})`);r(i)}}function Xg(e,t){let r=this[te];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,r._socket[te]!==void 0&&(r._socket.removeListener("data",bi),process.nextTick(_l,r._socket),e===1005?r.close():r.close(e,t))}function Zg(){this[te]._socket.resume()}function eb(e){let t=this[te];t._socket[te]!==void 0&&(t._socket.removeListener("data",bi),process.nextTick(_l,t._socket),t.close(e[Vg])),t.emit("error",e)}function cl(){this[te].emitClose()}function tb(e){this[te].emit("message",e)}function rb(e){let t=this[te];t.pong(e,!t._isServer,dl),t.emit("ping",e)}function ib(e){this[te].emit("pong",e)}function _l(e){e.resume()}function gl(){let e=this[te];this.removeListener("close",gl),this.removeListener("data",bi),this.removeListener("end",bl),e._readyState=G.CLOSING;let t;!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&(t=e._socket.read())!==null&&e._receiver.write(t),e._receiver.end(),this[te]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",cl),e._receiver.on("finish",cl))}function bi(e){this[te]._receiver.write(e)||this.pause()}function bl(){let e=this[te];e._readyState=G.CLOSING,e._receiver.end(),this.end()}function yl(){let e=this[te];this.removeListener("error",yl),this.on("error",dl),e&&(e._readyState=G.CLOSING,this.destroy())}});var El=b((qw,Sl)=>{"use strict";var{Duplex:nb}=require("stream");function ml(e){e.emit("close")}function sb(){!this.destroyed&&this._writableState.finished&&this.destroy()}function wl(e){this.removeListener("error",wl),this.destroy(),this.listenerCount("error")===0&&this.emit("error",e)}function ob(e,t){let r=!0,i=!0;function n(){r&&e._socket.resume()}e.readyState===e.CONNECTING?e.once("open",function(){e._receiver.removeAllListeners("drain"),e._receiver.on("drain",n)}):(e._receiver.removeAllListeners("drain"),e._receiver.on("drain",n));let s=new nb({...t,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return e.on("message",function(f){s.push(f)||(r=!1,e._socket.pause())}),e.once("error",function(f){s.destroyed||(i=!1,s.destroy(f))}),e.once("close",function(){s.destroyed||s.push(null)}),s._destroy=function(o,f){if(e.readyState===e.CLOSED){f(o),process.nextTick(ml,s);return}let a=!1;e.once("error",function(u){a=!0,f(u)}),e.once("close",function(){a||f(o),process.nextTick(ml,s)}),i&&e.terminate()},s._final=function(o){if(e.readyState===e.CONNECTING){e.once("open",function(){s._final(o)});return}e._socket!==null&&(e._socket._writableState.finished?(o(),s._readableState.endEmitted&&s.destroy()):(e._socket.once("finish",function(){o()}),e.close()))},s._read=function(){(e.readyState===e.OPEN||e.readyState===e.CLOSING)&&!r&&(r=!0,e._receiver._writableState.needDrain||e._socket.resume())},s._write=function(o,f,a){if(e.readyState===e.CONNECTING){e.once("open",function(){s._write(o,f,a)});return}e.send(o,a)},s.on("end",sb),s.on("error",wl),s}Sl.exports=ob});var Ol=b((Fw,Il)=>{"use strict";var ab=require("events"),yi=require("http"),Dw=require("https"),Uw=require("net"),jw=require("tls"),{createHash:fb}=require("crypto"),ht=rr(),lb=ms(),{format:ub,parse:cb}=ps(),{GUID:hb,kWebSocket:db}=ut(),pb=/^[+/0-9A-Za-z]{22}==$/,xl=0,Cl=1,Tl=2,Ss=class extends ab{constructor(t,r){if(super(),t={maxPayload:100*1024*1024,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,...t},t.port==null&&!t.server&&!t.noServer||t.port!=null&&(t.server||t.noServer)||t.server&&t.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(t.port!=null?(this._server=yi.createServer((i,n)=>{let s=yi.STATUS_CODES[426];n.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"}),n.end(s)}),this._server.listen(t.port,t.host,t.backlog,r)):t.server&&(this._server=t.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=_b(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(n,s,o)=>{this.handleUpgrade(n,s,o,i)}})}t.perMessageDeflate===!0&&(t.perMessageDeflate={}),t.clientTracking&&(this.clients=new Set),this.options=t,this._state=xl}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(t){if(t&&this.once("close",t),this._state===Tl){process.nextTick(ws,this);return}if(this._state===Cl)return;if(this._state=Cl,this.clients)for(let i of this.clients)i.terminate();let r=this._server;if(r&&(this._removeListeners(),this._removeListeners=this._server=null,this.options.port!=null)){r.close(ws.bind(void 0,this));return}process.nextTick(ws,this)}shouldHandle(t){if(this.options.path){let r=t.url.indexOf("?");if((r!==-1?t.url.slice(0,r):t.url)!==this.options.path)return!1}return!0}handleUpgrade(t,r,i,n){r.on("error",Es);let s=t.headers["sec-websocket-key"]!==void 0?t.headers["sec-websocket-key"].trim():!1,o=+t.headers["sec-websocket-version"],f={};if(t.method!=="GET"||t.headers.upgrade.toLowerCase()!=="websocket"||!s||!pb.test(s)||o!==8&&o!==13||!this.shouldHandle(t))return sr(r,400);if(this.options.perMessageDeflate){let a=new ht(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let l=cb(t.headers["sec-websocket-extensions"]);l[ht.extensionName]&&(a.accept(l[ht.extensionName]),f[ht.extensionName]=a)}catch{return sr(r,400)}}if(this.options.verifyClient){let a={origin:t.headers[`${o===8?"sec-websocket-origin":"origin"}`],secure:!!(t.socket.authorized||t.socket.encrypted),req:t};if(this.options.verifyClient.length===2){this.options.verifyClient(a,(l,u,h,c)=>{if(!l)return sr(r,u||401,h,c);this.completeUpgrade(s,f,t,r,i,n)});return}if(!this.options.verifyClient(a))return sr(r,401)}this.completeUpgrade(s,f,t,r,i,n)}completeUpgrade(t,r,i,n,s,o){if(!n.readable||!n.writable)return n.destroy();if(n[db])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>xl)return sr(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${fb("sha1").update(t+hb).digest("base64")}`],l=new lb(null),u=i.headers["sec-websocket-protocol"];if(u&&(u=u.split(",").map(gb),this.options.handleProtocols?u=this.options.handleProtocols(u,i):u=u[0],u&&(a.push(`Sec-WebSocket-Protocol: ${u}`),l._protocol=u)),r[ht.extensionName]){let h=r[ht.extensionName].params,c=ub({[ht.extensionName]:[h]});a.push(`Sec-WebSocket-Extensions: ${c}`),l._extensions=r}this.emit("headers",a,i),n.write(a.concat(`\r
`).join(`\r
`)),n.removeListener("error",Es),l.setSocket(n,s,this.options.maxPayload),this.clients&&(this.clients.add(l),l.on("close",()=>this.clients.delete(l))),o(l,i)}};Il.exports=Ss;function _b(e,t){for(let r of Object.keys(t))e.on(r,t[r]);return function(){for(let i of Object.keys(t))e.removeListener(i,t[i])}}function ws(e){e._state=Tl,e.emit("close")}function Es(){this.destroy()}function sr(e,t,r,i){e.writable&&(r=r||yi.STATUS_CODES[t],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},e.write(`HTTP/1.1 ${t} ${yi.STATUS_CODES[t]}\r
`+Object.keys(i).map(n=>`${n}: ${i[n]}`).join(`\r
`)+`\r
\r
`+r)),e.removeListener("error",Es),e.destroy()}function gb(e){return e.trim()}});var Rl=b((Ww,kl)=>{"use strict";var or=ms();or.createWebSocketStream=El();or.Server=Ol();or.Receiver=as();or.Sender=ls();kl.exports=or});var Cs=b((Vw,xs)=>{"use strict";var Pl=Rl(),ar=ze()("mqttjs:ws"),bb=ci(),yb=He().Transform,vb=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],Bl=typeof process<"u"&&process.title==="browser"||typeof __webpack_require__=="function";function Al(e,t){let r=e.protocol+"://"+e.hostname+":"+e.port+e.path;return typeof e.transformWsUrl=="function"&&(r=e.transformWsUrl(r,e,t)),r}function Nl(e){let t=e;return e.hostname||(t.hostname="localhost"),e.port||(e.protocol==="wss"?t.port=443:t.port=80),e.path||(t.path="/"),e.wsOptions||(t.wsOptions={}),!Bl&&e.protocol==="wss"&&vb.forEach(function(r){e.hasOwnProperty(r)&&!e.wsOptions.hasOwnProperty(r)&&(t.wsOptions[r]=e[r])}),t}function mb(e){let t=Nl(e);if(t.hostname||(t.hostname=t.host),!t.hostname){if(typeof document>"u")throw new Error("Could not determine host. Specify host manually.");let r=new URL(document.URL);t.hostname=r.hostname,t.port||(t.port=r.port)}return t.objectMode===void 0&&(t.objectMode=!(t.binary===!0||t.binary===void 0)),t}function wb(e,t,r){ar("createWebSocket"),ar("protocol: "+r.protocolId+" "+r.protocolVersion);let i=r.protocolId==="MQIsdp"&&r.protocolVersion===3?"mqttv3.1":"mqtt";return ar("creating new Websocket for url: "+t+" and protocol: "+i),new Pl(t,[i],r.wsOptions)}function Sb(e,t){let r=t.protocolId==="MQIsdp"&&t.protocolVersion===3?"mqttv3.1":"mqtt",i=Al(t,e),n=new WebSocket(i,[r]);return n.binaryType="arraybuffer",n}function Eb(e,t){ar("streamBuilder");let r=Nl(t),i=Al(r,e),n=wb(e,i,r),s=Pl.createWebSocketStream(n,r.wsOptions);return s.url=i,n.on("close",()=>{s.destroy()}),s}function xb(e,t){ar("browserStreamBuilder");let r,n=mb(t).browserBufferSize||1024*512,s=t.browserBufferTimeout||1e3,o=!t.objectMode,f=Sb(e,t),a=u(t,m,p);t.objectMode||(a._writev=v),a.on("close",()=>{f.close()});let l=typeof f.addEventListener<"u";f.readyState===f.OPEN?r=a:(r=r=bb(void 0,void 0,t),t.objectMode||(r._writev=v),l?f.addEventListener("open",h):f.onopen=h),r.socket=f,l?(f.addEventListener("close",c),f.addEventListener("error",d),f.addEventListener("message",_)):(f.onclose=c,f.onerror=d,f.onmessage=_);function u(g,S,x){let C=new yb({objectModeMode:g.objectMode});return C._write=S,C._flush=x,C}function h(){r.setReadable(a),r.setWritable(a),r.emit("connect")}function c(){r.end(),r.destroy()}function d(g){r.destroy(g)}function _(g){let S=g.data;S instanceof ArrayBuffer?S=Buffer.from(S):S=Buffer.from(S,"utf8"),a.push(S)}function v(g,S){let x=new Array(g.length);for(let C=0;C<g.length;C++)typeof g[C].chunk=="string"?x[C]=Buffer.from(g[C],"utf8"):x[C]=g[C].chunk;this._write(Buffer.concat(x),"binary",S)}function m(g,S,x){f.bufferedAmount>n&&setTimeout(m,s,g,S,x),o&&typeof g=="string"&&(g=Buffer.from(g,"utf8"));try{f.send(g)}catch(C){return x(C)}x()}function p(g){f.close(),g()}return r}Bl?xs.exports=xb:xs.exports=Eb});var Dl=b((Hw,fr)=>{"use strict";var Ll=Hn(),Cb=Qr(),Tb=require("url"),Ib=Nr(),Ml=ze()("mqttjs"),oe={};typeof process<"u"&&process.title!=="browser"||typeof __webpack_require__!="function"?(oe.mqtt=$n(),oe.tcp=$n(),oe.ssl=fi(),oe.tls=fi(),oe.mqtts=fi()):(oe.wx=Qn(),oe.wxs=Qn(),oe.ali=Jn(),oe.alis=Jn());oe.ws=Cs();oe.wss=Cs();function Ob(e){var t;e.auth&&(t=e.auth.match(/^(.+):(.+)$/),t?(e.username=t[1],e.password=t[2]):e.username=e.auth)}function ql(e,t){if(Ml("connecting to an MQTT broker..."),typeof e=="object"&&!t&&(t=e,e=null),t=t||{},e){var r=Tb.parse(e,!0);if(r.port!=null&&(r.port=Number(r.port)),t=Ib(r,t),t.protocol===null)throw new Error("Missing protocol");t.protocol=t.protocol.replace(/:$/,"")}if(Ob(t),t.query&&typeof t.query.clientId=="string"&&(t.clientId=t.query.clientId),t.cert&&t.key)if(t.protocol){if(["mqtts","wss","wxs","alis"].indexOf(t.protocol)===-1)switch(t.protocol){case"mqtt":t.protocol="mqtts";break;case"ws":t.protocol="wss";break;case"wx":t.protocol="wxs";break;case"ali":t.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+t.protocol+'"!')}}else throw new Error("Missing secure protocol key");if(!oe[t.protocol]){var i=["mqtts","wss"].indexOf(t.protocol)!==-1;t.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter(function(o,f){return i&&f%2===0?!1:typeof oe[o]=="function"})[0]}if(t.clean===!1&&!t.clientId)throw new Error("Missing clientId for unclean clients");t.protocol&&(t.defaultProtocol=t.protocol);function n(o){return t.servers&&((!o._reconnectCount||o._reconnectCount===t.servers.length)&&(o._reconnectCount=0),t.host=t.servers[o._reconnectCount].host,t.port=t.servers[o._reconnectCount].port,t.protocol=t.servers[o._reconnectCount].protocol?t.servers[o._reconnectCount].protocol:t.defaultProtocol,t.hostname=t.host,o._reconnectCount++),Ml("calling streambuilder for",t.protocol),oe[t.protocol](o,t)}var s=new Ll(n,t);return s.on("error",function(){}),s}fr.exports=ql;fr.exports.connect=ql;fr.exports.MqttClient=Ll;fr.exports.Store=Cb});var jl=b(($w,lr)=>{var Ul=Hn(),kb=Dl(),Rb=Qr();lr.exports.connect=kb;lr.exports.MqttClient=Ul;lr.exports.Client=Ul;lr.exports.Store=Rb});var mi=b((vi,Fl)=>{(function(e,t){typeof vi=="object"?Fl.exports=vi=t():typeof define=="function"&&define.amd?define([],t):e.CryptoJS=t()})(vi,function(){var e=e||function(t,r){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof global<"u"&&global.crypto&&(i=global.crypto),!i&&typeof require=="function")try{i=require("crypto")}catch{}var n=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||function(){function p(){}return function(g){var S;return p.prototype=g,S=new p,p.prototype=null,S}}(),o={},f=o.lib={},a=f.Base=function(){return{extend:function(p){var g=s(this);return p&&g.mixIn(p),(!g.hasOwnProperty("init")||this.init===g.init)&&(g.init=function(){g.$super.init.apply(this,arguments)}),g.init.prototype=g,g.$super=this,g},create:function(){var p=this.extend();return p.init.apply(p,arguments),p},init:function(){},mixIn:function(p){for(var g in p)p.hasOwnProperty(g)&&(this[g]=p[g]);p.hasOwnProperty("toString")&&(this.toString=p.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),l=f.WordArray=a.extend({init:function(p,g){p=this.words=p||[],g!=r?this.sigBytes=g:this.sigBytes=p.length*4},toString:function(p){return(p||h).stringify(this)},concat:function(p){var g=this.words,S=p.words,x=this.sigBytes,C=p.sigBytes;if(this.clamp(),x%4)for(var w=0;w<C;w++){var B=S[w>>>2]>>>24-w%4*8&255;g[x+w>>>2]|=B<<24-(x+w)%4*8}else for(var M=0;M<C;M+=4)g[x+M>>>2]=S[M>>>2];return this.sigBytes+=C,this},clamp:function(){var p=this.words,g=this.sigBytes;p[g>>>2]&=4294967295<<32-g%4*8,p.length=t.ceil(g/4)},clone:function(){var p=a.clone.call(this);return p.words=this.words.slice(0),p},random:function(p){for(var g=[],S=0;S<p;S+=4)g.push(n());return new l.init(g,p)}}),u=o.enc={},h=u.Hex={stringify:function(p){for(var g=p.words,S=p.sigBytes,x=[],C=0;C<S;C++){var w=g[C>>>2]>>>24-C%4*8&255;x.push((w>>>4).toString(16)),x.push((w&15).toString(16))}return x.join("")},parse:function(p){for(var g=p.length,S=[],x=0;x<g;x+=2)S[x>>>3]|=parseInt(p.substr(x,2),16)<<24-x%8*4;return new l.init(S,g/2)}},c=u.Latin1={stringify:function(p){for(var g=p.words,S=p.sigBytes,x=[],C=0;C<S;C++){var w=g[C>>>2]>>>24-C%4*8&255;x.push(String.fromCharCode(w))}return x.join("")},parse:function(p){for(var g=p.length,S=[],x=0;x<g;x++)S[x>>>2]|=(p.charCodeAt(x)&255)<<24-x%4*8;return new l.init(S,g)}},d=u.Utf8={stringify:function(p){try{return decodeURIComponent(escape(c.stringify(p)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(p){return c.parse(unescape(encodeURIComponent(p)))}},_=f.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new l.init,this._nDataBytes=0},_append:function(p){typeof p=="string"&&(p=d.parse(p)),this._data.concat(p),this._nDataBytes+=p.sigBytes},_process:function(p){var g,S=this._data,x=S.words,C=S.sigBytes,w=this.blockSize,B=w*4,M=C/B;p?M=t.ceil(M):M=t.max((M|0)-this._minBufferSize,0);var H=M*w,rt=t.min(H*4,C);if(H){for(var Se=0;Se<H;Se+=w)this._doProcessBlock(x,Se);g=x.splice(0,H),S.sigBytes-=rt}return new l.init(g,rt)},clone:function(){var p=a.clone.call(this);return p._data=this._data.clone(),p},_minBufferSize:0}),v=f.Hasher=_.extend({cfg:a.extend(),init:function(p){this.cfg=this.cfg.extend(p),this.reset()},reset:function(){_.reset.call(this),this._doReset()},update:function(p){return this._append(p),this._process(),this},finalize:function(p){p&&this._append(p);var g=this._doFinalize();return g},blockSize:512/32,_createHelper:function(p){return function(g,S){return new p.init(S).finalize(g)}},_createHmacHelper:function(p){return function(g,S){return new m.HMAC.init(p,S).finalize(g)}}}),m=o.algo={};return o}(Math);return e})});var Ts=b((wi,Wl)=>{(function(e,t){typeof wi=="object"?Wl.exports=wi=t(mi()):typeof define=="function"&&define.amd?define(["./core"],t):t(e.CryptoJS)})(wi,function(e){return function(t){var r=e,i=r.lib,n=i.WordArray,s=i.Hasher,o=r.algo,f=[],a=[];(function(){function h(v){for(var m=t.sqrt(v),p=2;p<=m;p++)if(!(v%p))return!1;return!0}function c(v){return(v-(v|0))*4294967296|0}for(var d=2,_=0;_<64;)h(d)&&(_<8&&(f[_]=c(t.pow(d,1/2))),a[_]=c(t.pow(d,1/3)),_++),d++})();var l=[],u=o.SHA256=s.extend({_doReset:function(){this._hash=new n.init(f.slice(0))},_doProcessBlock:function(h,c){for(var d=this._hash.words,_=d[0],v=d[1],m=d[2],p=d[3],g=d[4],S=d[5],x=d[6],C=d[7],w=0;w<64;w++){if(w<16)l[w]=h[c+w]|0;else{var B=l[w-15],M=(B<<25|B>>>7)^(B<<14|B>>>18)^B>>>3,H=l[w-2],rt=(H<<15|H>>>17)^(H<<13|H>>>19)^H>>>10;l[w]=M+l[w-7]+rt+l[w-16]}var Se=g&S^~g&x,kr=_&v^_&m^v&m,Yi=(_<<30|_>>>2)^(_<<19|_>>>13)^(_<<10|_>>>22),Dt=(g<<26|g>>>6)^(g<<21|g>>>11)^(g<<7|g>>>25),Rr=C+Dt+Se+a[w]+l[w],Pr=Yi+kr;C=x,x=S,S=g,g=p+Rr|0,p=m,m=v,v=_,_=Rr+Pr|0}d[0]=d[0]+_|0,d[1]=d[1]+v|0,d[2]=d[2]+m|0,d[3]=d[3]+p|0,d[4]=d[4]+g|0,d[5]=d[5]+S|0,d[6]=d[6]+x|0,d[7]=d[7]+C|0},_doFinalize:function(){var h=this._data,c=h.words,d=this._nDataBytes*8,_=h.sigBytes*8;return c[_>>>5]|=128<<24-_%32,c[(_+64>>>9<<4)+14]=t.floor(d/4294967296),c[(_+64>>>9<<4)+15]=d,h.sigBytes=c.length*4,this._process(),this._hash},clone:function(){var h=s.clone.call(this);return h._hash=this._hash.clone(),h}});r.SHA256=s._createHelper(u),r.HmacSHA256=s._createHmacHelper(u)}(Math),e.SHA256})});var Hl=b((Si,Vl)=>{(function(e,t){typeof Si=="object"?Vl.exports=Si=t(mi()):typeof define=="function"&&define.amd?define(["./core"],t):t(e.CryptoJS)})(Si,function(e){(function(){var t=e,r=t.lib,i=r.Base,n=t.enc,s=n.Utf8,o=t.algo,f=o.HMAC=i.extend({init:function(a,l){a=this._hasher=new a.init,typeof l=="string"&&(l=s.parse(l));var u=a.blockSize,h=u*4;l.sigBytes>h&&(l=a.finalize(l)),l.clamp();for(var c=this._oKey=l.clone(),d=this._iKey=l.clone(),_=c.words,v=d.words,m=0;m<u;m++)_[m]^=1549556828,v[m]^=909522486;c.sigBytes=d.sigBytes=h,this.reset()},reset:function(){var a=this._hasher;a.reset(),a.update(this._iKey)},update:function(a){return this._hasher.update(a),this},finalize:function(a){var l=this._hasher,u=l.finalize(a);l.reset();var h=l.finalize(this._oKey.clone().concat(u));return h}})})()})});var Gl=b((Ei,$l)=>{(function(e,t,r){typeof Ei=="object"?$l.exports=Ei=t(mi(),Ts(),Hl()):typeof define=="function"&&define.amd?define(["./core","./sha256","./hmac"],t):t(e.CryptoJS)})(Ei,function(e){return e.HmacSHA256})});var Kl=b((Gw,zl)=>{zl.exports={INVALID_CONNECT_OPTIONS:"Invalid connect options supplied.",INVALID_CLIENT_ID_OPTION:'Invalid "clientId" (mqtt client id) option supplied.',INVALID_RECONNECT_TIMING:"Invalid reconnect timing options supplied.",INVALID_OFFLINE_QUEUEING_PARAMETERS:"Invalid offline queueing options supplied."}});var ur=b((zw,Yl)=>{Yl.exports=function(e){return typeof e>"u"||e===null}});var Jl=b((Kw,Ql)=>{Ql.exports={NO_KEY_OPTION:'No "keyPath" or "privateKey" option supplied.',NO_CERT_OPTION:'No "certPath" or "clientCert" option supplied.',NO_CA_OPTION:'No "caPath" or "caCert" option supplied.',INVALID_KEY_PATH_OPTION:'Invalid "keyPath" option supplied.',INVALID_CERT_PATH_OPTION:'Invalid "certPath" option supplied.',INVALID_CA_PATH_OPTION:'Invalid "caPath" option supplied.',INVALID_CLIENT_CERT_OPTION:'Invalid "clientCert" option supplied.',INVALID_PRIVATE_KEY_OPTION:'Invalid "privateKey" option supplied.',INVALID_CA_CERT_OPTION:'Invalid "caCert" option supplied.'}});var Zl=b((Yw,Xl)=>{var be=require("fs"),ye=ur(),Ne=Jl();Xl.exports=function(e){if(ye(e.keyPath)&&ye(e.privateKey))throw new Error(Ne.NO_KEY_OPTION);if(ye(e.certPath)&&ye(e.clientCert))throw new Error(Ne.NO_CERT_OPTION);if(ye(e.caPath)&&ye(e.caCert))throw new Error(Ne.NO_CA_OPTION);if(!ye(e.caCert))if(Buffer.isBuffer(e.caCert))e.ca=e.caCert;else if(be.existsSync(e.caCert))e.ca=be.readFileSync(e.caCert);else throw new Error(Ne.INVALID_CA_CERT_OPTION);if(!ye(e.privateKey))if(Buffer.isBuffer(e.privateKey))e.key=e.privateKey;else if(be.existsSync(e.privateKey))e.key=be.readFileSync(e.privateKey);else throw new Error(Ne.INVALID_PRIVATE_KEY_OPTION);if(!ye(e.clientCert))if(Buffer.isBuffer(e.clientCert))e.cert=e.clientCert;else if(be.existsSync(e.clientCert))e.cert=be.readFileSync(e.clientCert);else throw new Error(Ne.INVALID_CLIENT_CERT_OPTION);if(be.existsSync(e.keyPath))e.key=be.readFileSync(e.keyPath);else if(!ye(e.keyPath))throw new Error(Ne.INVALID_KEY_PATH_OPTION);if(be.existsSync(e.certPath))e.cert=be.readFileSync(e.certPath);else if(!ye(e.certPath))throw new Error(Ne.INVALID_CERT_PATH_OPTION);if(be.existsSync(e.caPath))e.ca=be.readFileSync(e.caPath);else if(!ye(e.caPath))throw new Error(Ne.INVALID_CA_PATH_OPTION);e.requestCert=!0,e.rejectUnauthorized=!0}});var eu=b((Qw,Pb)=>{Pb.exports={name:"aws-iot-device-sdk",description:"AWS IoT Node.js SDK for Embedded Devices",version:"2.2.13",author:{name:"Amazon Web Services",email:"",url:"http://aws.amazon.com"},homepage:"https://github.com/aws/aws-iot-device-sdk-js",main:"index.js",engines:{node:">=4.0.0"},repository:{type:"git",url:"git://github.com/aws/aws-iot-device-sdk-js"},bugs:{url:"http://github.com/aws/aws-iot-device-sdk-js/issues"},license:"Apache-2.0",keywords:["api","amazon","aws","iot","mqtt"],dependencies:{"crypto-js":"4.2.0",minimist:"1.2.6",mqtt:"4.2.8","websocket-stream":"^5.5.2"},devDependencies:{gulp:"^3.9.0","gulp-beautify":"^2.0.0","gulp-concat":"^2.6.0","gulp-coverage":"^0.3.38","gulp-jscs":"^4.0.0","gulp-jshint":"^2.0.0","gulp-mocha":"^3.0.1",jshint:"^2.9.1","jshint-stylish":"^2.2.1",rewire:"^2.5.1",sinon:"^1.17.3"},scripts:{test:"node ./node_modules/gulp/bin/gulp.js test --verbose",browserize:"./scripts/browserize.sh",beautify:"node ./node_modules/gulp/bin/gulp.js beautify"}}});var ru=b((Jw,tu)=>{var Bb=require("tls");function Ab(e,t){var r;r=Bb.connect(t);function i(n){e.emit("error",n),r.end()}return r.on("secureConnect",function(){r.authorized?r.removeListener("error",i):r.emit("error",new Error("TLS not authorized"))}),r.on("error",i),r}tu.exports=Ab});var Is=b((Xw,iu)=>{"use strict";var Nb=Object.prototype.hasOwnProperty,Mb=0;function dt(e){if(!(this instanceof dt))return new dt(e);this.id=Mb++,this.ee=e}dt.prototype.on=function(t,r,i){return r.__ultron=this.id,this.ee.on(t,r,i),this};dt.prototype.once=function(t,r,i){return r.__ultron=this.id,this.ee.once(t,r,i),this};dt.prototype.remove=function(){var t=arguments,r=this.ee,i;if(t.length===1&&typeof t[0]=="string")t=t[0].split(/[, ]+/);else if(!t.length){if(r.eventNames)t=r.eventNames();else if(r._events){t=[];for(i in r._events)Nb.call(r._events,i)&&t.push(i);Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(r._events)))}}for(var n=0;n<t.length;n++)for(var s=r.listeners(t[n]),o=0;o<s.length;o++){if(i=s[o],i.listener){if(i.listener.__ultron!==this.id)continue}else if(i.__ultron!==this.id)continue;r.removeListener(t[n],i)}return this};dt.prototype.destroy=function(){return this.ee?(this.remove(),this.ee=null,!0):!1};iu.exports=dt});var ve=b((Os,su)=>{var xi=require("buffer"),Me=xi.Buffer;function nu(e,t){for(var r in e)t[r]=e[r]}Me.from&&Me.alloc&&Me.allocUnsafe&&Me.allocUnsafeSlow?su.exports=xi:(nu(xi,Os),Os.Buffer=Rt);function Rt(e,t,r){return Me(e,t,r)}nu(Me,Rt);Rt.from=function(e,t,r){if(typeof e=="number")throw new TypeError("Argument must not be a number");return Me(e,t,r)};Rt.alloc=function(e,t,r){if(typeof e!="number")throw new TypeError("Argument must be a number");var i=Me(e);return t!==void 0?typeof r=="string"?i.fill(t,r):i.fill(t):i.fill(0),i};Rt.allocUnsafe=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return Me(e)};Rt.allocUnsafeSlow=function(e){if(typeof e!="number")throw new TypeError("Argument must be a number");return xi.SlowBuffer(e)}});var au=b((Zw,ou)=>{"use strict";function pt(e){if(!(this instanceof pt))return new pt(e);e=e||{},this.concurrency=e.concurrency||1/0,this.pending=0,this.jobs=[],this.cbs=[],this._done=qb.bind(this)}var Lb=["push","unshift","splice"];Lb.forEach(function(e){pt.prototype[e]=function(){var t=Array.prototype[e].apply(this.jobs,arguments);return this._run(),t}});Object.defineProperty(pt.prototype,"length",{get:function(){return this.pending+this.jobs.length}});pt.prototype._run=function(){if(this.pending!==this.concurrency){if(this.jobs.length){var e=this.jobs.shift();this.pending++,e(this._done),this._run()}if(this.pending===0)for(;this.cbs.length!==0;){var t=this.cbs.pop();process.nextTick(t)}}};pt.prototype.onDone=function(e){typeof e=="function"&&(this.cbs.push(e),this._run())};function qb(){this.pending--,this._run()}ou.exports=pt});var Ci=b((e0,ks)=>{"use strict";var Db=ve(),Ub=Db.Buffer,fu=(e,t)=>{let r=Ub.allocUnsafe(t);for(var i=0,n=0;n<e.length;n++){let s=e[n];s.copy(r,i),i+=s.length}return r};try{let e=require("bufferutil");ks.exports=Object.assign({concat:fu},e.BufferUtil||e)}catch{let t=(i,n,s,o,f)=>{for(var a=0;a<f;a++)s[o+a]=i[a]^n[a&3]},r=(i,n)=>{let s=i.length;for(var o=0;o<s;o++)i[o]^=n[o&3]};ks.exports={concat:fu,mask:t,unmask:r}}});var cr=b((t0,du)=>{"use strict";var jb=ve(),Fb=au(),Ze=require("zlib"),lu=Ci(),uu=jb.Buffer,Wb=uu.from([0,0,255,255]),Vb=uu.from([0]),Pt=Symbol("write-in-progress"),Ti=Symbol("pending-close"),Le=Symbol("total-length"),cu=Symbol("callback"),et=Symbol("buffers"),Rs=Symbol("error"),Oi=Symbol("owner"),Ii,Ps=class{constructor(t,r,i){if(this._maxPayload=i|0,this._options=t||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!Ii){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ii=new Fb({concurrency:n})}}static get extensionName(){return"permessage-deflate"}offer(){let t={};return this._options.serverNoContextTakeover&&(t.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(t.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(t.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?t.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(t.client_max_window_bits=!0),t}accept(t){t=this.normalizeParams(t);var r;return this._isServer?r=this.acceptAsServer(t):r=this.acceptAsClient(t),this.params=r,r}cleanup(){this._inflate&&(this._inflate[Pt]?this._inflate[Ti]=!0:(this._inflate.close(),this._inflate=null)),this._deflate&&(this._deflate[Pt]?this._deflate[Ti]=!0:(this._deflate.close(),this._deflate=null))}acceptAsServer(t){let r={};if(!t.some(n=>{if(!(this._options.serverNoContextTakeover===!1&&n.server_no_context_takeover||this._options.serverMaxWindowBits===!1&&n.server_max_window_bits||typeof this._options.serverMaxWindowBits=="number"&&typeof n.server_max_window_bits=="number"&&this._options.serverMaxWindowBits>n.server_max_window_bits||typeof this._options.clientMaxWindowBits=="number"&&!n.client_max_window_bits))return(this._options.serverNoContextTakeover||n.server_no_context_takeover)&&(r.server_no_context_takeover=!0),(this._options.clientNoContextTakeover||this._options.clientNoContextTakeover!==!1&&n.client_no_context_takeover)&&(r.client_no_context_takeover=!0),typeof this._options.serverMaxWindowBits=="number"?r.server_max_window_bits=this._options.serverMaxWindowBits:typeof n.server_max_window_bits=="number"&&(r.server_max_window_bits=n.server_max_window_bits),typeof this._options.clientMaxWindowBits=="number"?r.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits!==!1&&typeof n.client_max_window_bits=="number"&&(r.client_max_window_bits=n.client_max_window_bits),!0}))throw new Error("Doesn't support the offered configuration");return r}acceptAsClient(t){let r=t[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Invalid value for "client_no_context_takeover"');if(typeof this._options.clientMaxWindowBits=="number"&&(!r.client_max_window_bits||r.client_max_window_bits>this._options.clientMaxWindowBits)||this._options.clientMaxWindowBits===!1&&r.client_max_window_bits)throw new Error('Invalid value for "client_max_window_bits"');return r}normalizeParams(t){return t.map(r=>(Object.keys(r).forEach(i=>{var n=r[i];if(n.length>1)throw new Error(`Multiple extension parameters for ${i}`);switch(n=n[0],i){case"server_no_context_takeover":case"client_no_context_takeover":if(n!==!0)throw new Error(`invalid extension parameter value for ${i} (${n})`);r[i]=!0;break;case"server_max_window_bits":case"client_max_window_bits":if(typeof n=="string"&&(n=parseInt(n,10),Number.isNaN(n)||n<Ze.Z_MIN_WINDOWBITS||n>Ze.Z_MAX_WINDOWBITS))throw new Error(`invalid extension parameter value for ${i} (${n})`);if(!this._isServer&&n===!0)throw new Error(`Missing extension parameter value for ${i}`);r[i]=n;break;default:throw new Error(`Not defined extension parameter (${i})`)}}),r))}decompress(t,r,i){Ii.push(n=>{this._decompress(t,r,(s,o)=>{n(),i(s,o)})})}compress(t,r,i){Ii.push(n=>{this._compress(t,r,(s,o)=>{n(),i(s,o)})})}_decompress(t,r,i){let n=this._isServer?"client":"server";if(!this._inflate){let s=`${n}_max_window_bits`,o=typeof this.params[s]!="number"?Ze.Z_DEFAULT_WINDOWBITS:this.params[s];this._inflate=Ze.createInflateRaw({windowBits:o}),this._inflate[Le]=0,this._inflate[et]=[],this._inflate[Oi]=this,this._inflate.on("error",$b),this._inflate.on("data",hu)}this._inflate[cu]=i,this._inflate[Pt]=!0,this._inflate.write(t),r&&this._inflate.write(Wb),this._inflate.flush(()=>{let s=this._inflate[Rs];if(s){this._inflate.close(),this._inflate=null,i(s);return}let o=lu.concat(this._inflate[et],this._inflate[Le]);r&&this.params[`${n}_no_context_takeover`]||this._inflate[Ti]?(this._inflate.close(),this._inflate=null):(this._inflate[Pt]=!1,this._inflate[Le]=0,this._inflate[et]=[]),i(null,o)})}_compress(t,r,i){if(!t||t.length===0){process.nextTick(i,null,Vb);return}let n=this._isServer?"server":"client";if(!this._deflate){let s=`${n}_max_window_bits`,o=typeof this.params[s]!="number"?Ze.Z_DEFAULT_WINDOWBITS:this.params[s];this._deflate=Ze.createDeflateRaw({memLevel:this._options.memLevel,level:this._options.level,flush:Ze.Z_SYNC_FLUSH,windowBits:o}),this._deflate[Le]=0,this._deflate[et]=[],this._deflate.on("data",Hb)}this._deflate[Pt]=!0,this._deflate.write(t),this._deflate.flush(Ze.Z_SYNC_FLUSH,()=>{var s=lu.concat(this._deflate[et],this._deflate[Le]);r&&(s=s.slice(0,s.length-4)),r&&this.params[`${n}_no_context_takeover`]||this._deflate[Ti]?(this._deflate.close(),this._deflate=null):(this._deflate[Pt]=!1,this._deflate[Le]=0,this._deflate[et]=[]),i(null,s)})}};du.exports=Ps;function Hb(e){this[et].push(e),this[Le]+=e.length}function hu(e){if(this[Le]+=e.length,this[Oi]._maxPayload<1||this[Le]<=this[Oi]._maxPayload){this[et].push(e);return}this[Rs]=new Error("max payload size exceeded"),this[Rs].closeCode=1009,this.removeListener("data",hu),this.reset()}function $b(e){this[Oi]._inflate=null,this[cu](e)}});var _u=b((r0,pu)=>{"use strict";var hr=class{constructor(t,r){this.target=r,this.type=t}},Bs=class extends hr{constructor(t,r){super("message",r),this.data=t}},As=class extends hr{constructor(t,r,i){super("close",i),this.wasClean=i._closeFrameReceived&&i._closeFrameSent,this.reason=r,this.code=t}},Ns=class extends hr{constructor(t){super("open",t)}},Gb={addEventListener(e,t){if(typeof t!="function")return;function r(o){t.call(this,new Bs(o,this))}function i(o,f){t.call(this,new As(o,f,this))}function n(o){o.type="error",o.target=this,t.call(this,o)}function s(){t.call(this,new Ns(this))}e==="message"?(r._listener=t,this.on(e,r)):e==="close"?(i._listener=t,this.on(e,i)):e==="error"?(n._listener=t,this.on(e,n)):e==="open"?(s._listener=t,this.on(e,s)):this.on(e,t)},removeEventListener(e,t){let r=this.listeners(e);for(var i=0;i<r.length;i++)(r[i]===t||r[i]._listener===t)&&this.removeListener(e,r[i])}};pu.exports=Gb});var Ms=b((i0,gu)=>{"use strict";var dr=[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 Te(e,t,r){Object.prototype.hasOwnProperty.call(e,t)?e[t].push(r):e[t]=[r]}function zb(e){let t={};if(e===void 0||e==="")return t;for(var r={},i=!1,n=!1,s=!1,o,f,a=-1,l=-1,u=0;u<e.length;u++){let d=e.charCodeAt(u);if(o===void 0)if(l===-1&&dr[d]===1)a===-1&&(a=u);else if(d===32||d===9)l===-1&&a!==-1&&(l=u);else if(d===59||d===44){if(a===-1)throw new Error(`unexpected character at index ${u}`);l===-1&&(l=u);let _=e.slice(a,l);d===44?(Te(t,_,r),r={}):o=_,a=l=-1}else throw new Error(`unexpected character at index ${u}`);else if(f===void 0)if(l===-1&&dr[d]===1)a===-1&&(a=u);else if(d===32||d===9)l===-1&&a!==-1&&(l=u);else if(d===59||d===44){if(a===-1)throw new Error(`unexpected character at index ${u}`);l===-1&&(l=u),Te(r,e.slice(a,l),!0),d===44&&(Te(t,o,r),r={},o=void 0),a=l=-1}else if(d===61&&a!==-1&&l===-1)f=e.slice(a,u),a=l=-1;else throw new Error(`unexpected character at index ${u}`);else if(n){if(dr[d]!==1)throw new Error(`unexpected character at index ${u}`);a===-1?a=u:i||(i=!0),n=!1}else if(s)if(dr[d]===1)a===-1&&(a=u);else if(d===34&&a!==-1)s=!1,l=u;else if(d===92)n=!0;else throw new Error(`unexpected character at index ${u}`);else if(d===34&&e.charCodeAt(u-1)===61)s=!0;else if(l===-1&&dr[d]===1)a===-1&&(a=u);else if(a!==-1&&(d===32||d===9))l===-1&&(l=u);else if(d===59||d===44){if(a===-1)throw new Error(`unexpected character at index ${u}`);l===-1&&(l=u);var h=e.slice(a,l);i&&(h=h.replace(/\\/g,""),i=!1),Te(r,f,h),d===44&&(Te(t,o,r),r={},o=void 0),f=void 0,a=l=-1}else throw new Error(`unexpected character at index ${u}`)}if(a===-1||s)throw new Error("unexpected end of input");l===-1&&(l=u);let c=e.slice(a,l);return o===void 0?Te(t,c,{}):(f===void 0?Te(r,c,!0):i?Te(r,f,c.replace(/\\/g,"")):Te(r,f,c),Te(t,o,r)),t}function Kb(e){return Object.keys(e).map(t=>{var r=e[t];return Array.isArray(r)||(r=[r]),r.map(i=>[t].concat(Object.keys(i).map(n=>{var s=i[n];return Array.isArray(s)||(s=[s]),s.map(o=>o===!0?n:`${n}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}gu.exports={format:Kb,parse:zb}});var _r=b(pr=>{"use strict";var Yb=ve(),Qb=Yb.Buffer;pr.BINARY_TYPES=["nodebuffer","arraybuffer","fragments"];pr.GUID="258EAFA5-E914-47DA-95CA-C5AB0DC85B11";pr.EMPTY_BUFFER=Qb.alloc(0);pr.NOOP=()=>{}});var bu=b((s0,Ls)=>{"use strict";try{let e=require("utf-8-validate");Ls.exports=typeof e=="object"?e.Validation.isValidUTF8:e}catch{Ls.exports=()=>!0}});var qs=b((o0,yu)=>{"use strict";yu.exports={isValidErrorCode:function(e){return e>=1e3&&e<=1013&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999},1e3:"normal",1001:"going away",1002:"protocol error",1003:"unsupported data",1004:"reserved",1005:"reserved for extensions",1006:"reserved for extensions",1007:"inconsistent or invalid data",1008:"policy violation",1009:"message too big",1010:"extension handshake missing",1011:"an unexpected condition prevented the request from being fulfilled",1012:"service restart",1013:"try again later"}});var Ws=b((a0,Tu)=>{"use strict";var Jb=ve(),vu=cr(),mu=bu(),Cu=Ci(),Xb=qs(),js=_r(),Zb=Jb.Buffer,ki=0,wu=1,Su=2,Eu=3,Ds=4,xu=5,Fs=class{constructor(t,r,i){this._binaryType=i||js.BINARY_TYPES[0],this._extensions=t||{},this._maxPayload=r|0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._fragmented=0,this._masked=!1,this._fin=!1,this._mask=null,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._cleanupCallback=null,this._hadError=!1,this._dead=!1,this._loop=!1,this.onmessage=null,this.onclose=null,this.onerror=null,this.onping=null,this.onpong=null,this._state=ki}readBuffer(t){var r=0,i,n;if(this._bufferedBytes-=t,t===this._buffers[0].length)return this._buffers.shift();if(t<this._buffers[0].length)return i=this._buffers[0].slice(0,t),this._buffers[0]=this._buffers[0].slice(t),i;for(i=Zb.allocUnsafe(t);t>0;)n=this._buffers[0].length,t>=n?(this._buffers[0].copy(i,r),r+=n,this._buffers.shift()):(this._buffers[0].copy(i,r,0,t),this._buffers[0]=this._buffers[0].slice(t)),t-=n;return i}hasBufferedBytes(t){return this._bufferedBytes>=t?!0:(this._loop=!1,this._dead&&this.cleanup(this._cleanupCallback),!1)}add(t){this._dead||(this._bufferedBytes+=t.length,this._buffers.push(t),this.startLoop())}startLoop(){for(this._loop=!0;this._loop;)switch(this._state){case ki:this.getInfo();break;case wu:this.getPayloadLength16();break;case Su:this.getPayloadLength64();break;case Eu:this.getMask();break;case Ds:this.getData();break;default:this._loop=!1}}getInfo(){if(!this.hasBufferedBytes(2))return;let t=this.readBuffer(2);if(t[0]&48){this.error(new Error("RSV2 and RSV3 must be clear"),1002);return}let r=(t[0]&64)===64;if(r&&!this._extensions[vu.extensionName]){this.error(new Error("RSV1 must be clear"),1002);return}if(this._fin=(t[0]&128)===128,this._opcode=t[0]&15,this._payloadLength=t[1]&127,this._opcode===0){if(r){this.error(new Error("RSV1 must be clear"),1002);return}if(this._fragmented)this._opcode=this._fragmented;else{this.error(new Error(`invalid opcode: ${this._opcode}`),1002);return}}else if(this._opcode===1||this._opcode===2){if(this._fragmented){this.error(new Error(`invalid opcode: ${this._opcode}`),1002);return}this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin){this.error(new Error("FIN must be set"),1002);return}if(r){this.error(new Error("RSV1 must be clear"),1002);return}if(this._payloadLength>125){this.error(new Error("invalid payload length"),1002);return}}else{this.error(new Error(`invalid opcode: ${this._opcode}`),1002);return}!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(t[1]&128)===128,this._payloadLength===126?this._state=wu:this._payloadLength===127?this._state=Su:this.haveLength()}getPayloadLength16(){this.hasBufferedBytes(2)&&(this._payloadLength=this.readBuffer(2).readUInt16BE(0,!0),this.haveLength())}getPayloadLength64(){if(!this.hasBufferedBytes(8))return;let t=this.readBuffer(8),r=t.readUInt32BE(0,!0);if(r>Math.pow(2,21)-1){this.error(new Error("max payload size exceeded"),1009);return}this._payloadLength=r*Math.pow(2,32)+t.readUInt32BE(4,!0),this.haveLength()}haveLength(){this._opcode<8&&this.maxPayloadExceeded(this._payloadLength)||(this._masked?this._state=Eu:this._state=Ds)}getMask(){this.hasBufferedBytes(4)&&(this._mask=this.readBuffer(4),this._state=Ds)}getData(){var t=js.EMPTY_BUFFER;if(this._payloadLength){if(!this.hasBufferedBytes(this._payloadLength))return;t=this.readBuffer(this._payloadLength),this._masked&&Cu.unmask(t,this._mask)}this._opcode>7?this.controlMessage(t):this._compressed?(this._state=xu,this.decompress(t)):this.pushFragment(t)&&this.dataMessage()}decompress(t){this._extensions[vu.extensionName].decompress(t,this._fin,(i,n)=>{if(i){this.error(i,i.closeCode===1009?1009:1007);return}this.pushFragment(n)&&this.dataMessage(),this.startLoop()})}dataMessage(){if(this._fin){let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){var t;this._binaryType==="nodebuffer"?t=Us(i,r):this._binaryType==="arraybuffer"?t=ey(Us(i,r)):t=i,this.onmessage(t)}else{let n=Us(i,r);if(!mu(n)){this.error(new Error("invalid utf8 sequence"),1007);return}this.onmessage(n.toString())}}this._state=ki}controlMessage(t){if(this._opcode===8){if(t.length===0)this.onclose(1e3,""),this._loop=!1,this.cleanup(this._cleanupCallback);else if(t.length===1)this.error(new Error("invalid payload length"),1002);else{let r=t.readUInt16BE(0,!0);if(!Xb.isValidErrorCode(r)){this.error(new Error(`invalid status code: ${r}`),1002);return}let i=t.slice(2);if(!mu(i)){this.error(new Error("invalid utf8 sequence"),1007);return}this.onclose(r,i.toString()),this._loop=!1,this.cleanup(this._cleanupCallback)}return}this._opcode===9?this.onping(t):this.onpong(t),this._state=ki}error(t,r){this.onerror(t,r),this._hadError=!0,this._loop=!1,this.cleanup(this._cleanupCallback)}maxPayloadExceeded(t){if(t===0||this._maxPayload<1)return!1;let r=this._totalPayloadLength+t;return r<=this._maxPayload?(this._totalPayloadLength=r,!1):(this.error(new Error("max payload size exceeded"),1009),!0)}pushFragment(t){if(t.length===0)return!0;let r=this._messageLength+t.length;return this._maxPayload<1||r<=this._maxPayload?(this._messageLength=r,this._fragments.push(t),!0):(this.error(new Error("max payload size exceeded"),1009),!1)}cleanup(t){this._dead=!0,!this._hadError&&(this._loop||this._state===xu)?this._cleanupCallback=t:(this._extensions=null,this._fragments=null,this._buffers=null,this._mask=null,this._cleanupCallback=null,this.onmessage=null,this.onclose=null,this.onerror=null,this.onping=null,this.onpong=null,t&&t())}};Tu.exports=Fs;function Us(e,t){return e.length===1?e[0]:e.length>1?Cu.concat(e,t):js.EMPTY_BUFFER}function ey(e){return e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}});var $s=b((f0,ku)=>{"use strict";var ty=ve(),ry=require("crypto"),Iu=cr(),Ou=Ci(),iy=qs(),ny=_r(),ae=ty.Buffer,Hs=class e{constructor(t,r){this._extensions=r||{},this._socket=t,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(t,r){let i=t.length<1024||r.mask&&r.readOnly;var n=r.mask?6:2,s=t.length;t.length>=65536?(n+=8,s=127):t.length>125&&(n+=2,s=126);let o=ae.allocUnsafe(i?t.length+n:n);if(o[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(o[0]|=64),s===126?o.writeUInt16BE(t.length,2,!0):s===127&&(o.writeUInt32BE(0,2,!0),o.writeUInt32BE(t.length,6,!0)),!r.mask)return o[1]=s,i?(t.copy(o,n),[o]):[o,t];let f=ry.randomBytes(4);return o[1]=s|128,o[n-4]=f[0],o[n-3]=f[1],o[n-2]=f[2],o[n-1]=f[3],i?(Ou.mask(t,f,o,n,t.length),[o]):(Ou.mask(t,f,t,0,t.length),[o,t])}close(t,r,i,n){var s;if(t===void 0)t=1e3;else if(typeof t!="number"||!iy.isValidErrorCode(t))throw new Error("first argument must be a valid error code number");r===void 0||r===""?t===1e3?s=ny.EMPTY_BUFFER:(s=ae.allocUnsafe(2),s.writeUInt16BE(t,0,!0)):(s=ae.allocUnsafe(2+ae.byteLength(r)),s.writeUInt16BE(t,0,!0),s.write(r,2)),this._deflating?this.enqueue([this.doClose,s,i,n]):this.doClose(s,i,n)}doClose(t,r,i){this.sendFrame(e.frame(t,{fin:!0,rsv1:!1,opcode:8,mask:r,readOnly:!1}),i)}ping(t,r){var i=!0;ae.isBuffer(t)||(t instanceof ArrayBuffer?t=ae.from(t):ArrayBuffer.isView(t)?t=Vs(t):(t=ae.from(t),i=!1)),this._deflating?this.enqueue([this.doPing,t,r,i]):this.doPing(t,r,i)}doPing(t,r,i){this.sendFrame(e.frame(t,{fin:!0,rsv1:!1,opcode:9,mask:r,readOnly:i}))}pong(t,r){var i=!0;ae.isBuffer(t)||(t instanceof ArrayBuffer?t=ae.from(t):ArrayBuffer.isView(t)?t=Vs(t):(t=ae.from(t),i=!1)),this._deflating?this.enqueue([this.doPong,t,r,i]):this.doPong(t,r,i)}doPong(t,r,i){this.sendFrame(e.frame(t,{fin:!0,rsv1:!1,opcode:10,mask:r,readOnly:i}))}send(t,r,i){var n=r.binary?2:1,s=r.compress,o=!0;ae.isBuffer(t)||(t instanceof ArrayBuffer?t=ae.from(t):ArrayBuffer.isView(t)?t=Vs(t):(t=ae.from(t),o=!1));let f=this._extensions[Iu.extensionName];if(this._firstFragment?(this._firstFragment=!1,s&&f&&(s=t.length>=f._threshold),this._compress=s):(s=!1,n=0),r.fin&&(this._firstFragment=!0),f){let a={fin:r.fin,rsv1:s,opcode:n,mask:r.mask,readOnly:o};this._deflating?this.enqueue([this.dispatch,t,this._compress,a,i]):this.dispatch(t,this._compress,a,i)}else this.sendFrame(e.frame(t,{fin:r.fin,rsv1:!1,opcode:n,mask:r.mask,readOnly:o}),i)}dispatch(t,r,i,n){if(!r){this.sendFrame(e.frame(t,i),n);return}let s=this._extensions[Iu.extensionName];this._deflating=!0,s.compress(t,i.fin,(o,f)=>{i.readOnly=!1,this.sendFrame(e.frame(f,i),n),this._deflating=!1,this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){let t=this._queue.shift();this._bufferedBytes-=t[1].length,t[0].apply(this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[1].length,this._queue.push(t)}sendFrame(t,r){t.length===2?(this._socket.write(t[0]),this._socket.write(t[1],r)):this._socket.write(t[0],r)}};ku.exports=Hs;function Vs(e){let t=ae.from(e.buffer);return e.byteLength!==e.buffer.byteLength?t.slice(e.byteOffset,e.byteOffset+e.byteLength):t}});var zs=b((l0,Au)=>{"use strict";var sy=require("events"),Ru=require("crypto"),oy=Is(),ay=require("https"),fy=require("http"),ly=require("url"),tt=cr(),Bu=_u(),Pu=Ms(),_t=_r(),uy=Ws(),cy=$s(),Gs=[8,13],hy=30*1e3,we=class e extends sy{constructor(t,r,i){super(),r?typeof r=="string"?r=[r]:Array.isArray(r)||(i=r,r=[]):r=[],this.readyState=e.CONNECTING,this.bytesReceived=0,this.extensions={},this.protocol="",this._binaryType=_t.BINARY_TYPES[0],this._finalize=this.finalize.bind(this),this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage="",this._closeTimer=null,this._finalized=!1,this._closeCode=1006,this._receiver=null,this._sender=null,this._socket=null,this._ultron=null,Array.isArray(t)?dy.call(this,t[0],t[1],i):py.call(this,t,r,i)}get CONNECTING(){return e.CONNECTING}get CLOSING(){return e.CLOSING}get CLOSED(){return e.CLOSED}get OPEN(){return e.OPEN}get bufferedAmount(){var t=0;return this._socket&&(t=this._socket.bufferSize+this._sender._bufferedBytes),t}get binaryType(){return this._binaryType}set binaryType(t){_t.BINARY_TYPES.indexOf(t)<0||(this._binaryType=t,this._receiver&&(this._receiver._binaryType=t))}setSocket(t,r){t.setTimeout(0),t.setNoDelay(),this._receiver=new uy(this.extensions,this._maxPayload,this.binaryType),this._sender=new cy(t,this.extensions),this._ultron=new oy(t),this._socket=t,this._ultron.on("close",this._finalize),this._ultron.on("error",this._finalize),this._ultron.on("end",this._finalize),r.length>0&&t.unshift(r),this._ultron.on("data",i=>{this.bytesReceived+=i.length,this._receiver.add(i)}),this._receiver.onmessage=i=>this.emit("message",i),this._receiver.onping=i=>{this.pong(i,!this._isServer,!0),this.emit("ping",i)},this._receiver.onpong=i=>this.emit("pong",i),this._receiver.onclose=(i,n)=>{this._closeFrameReceived=!0,this._closeMessage=n,this._closeCode=i,this._finalized||this.close(i,n)},this._receiver.onerror=(i,n)=>{this._closeMessage="",this._closeCode=n,this.readyState=e.CLOSING,this.emit("error",i),this.finalize(!0)},this.readyState=e.OPEN,this.emit("open")}finalize(t){if(!this._finalized){if(this.readyState=e.CLOSING,this._finalized=!0,typeof t=="object"&&this.emit("error",t),!this._socket)return this.emitClose();clearTimeout(this._closeTimer),this._closeTimer=null,this._ultron.destroy(),this._ultron=null,this._socket.on("error",_t.NOOP),t?this._socket.destroy():this._socket.end(),this._socket=null,this._sender=null,this._receiver.cleanup(()=>this.emitClose()),this._receiver=null}}emitClose(){this.readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage),this.extensions[tt.extensionName]&&this.extensions[tt.extensionName].cleanup(),this.extensions=null,this.removeAllListeners()}pause(){if(this.readyState!==e.OPEN)throw new Error("not opened");this._socket.pause()}resume(){if(this.readyState!==e.OPEN)throw new Error("not opened");this._socket.resume()}close(t,r){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){this._req.abort(),this.finalize(new Error("closed before the connection is established"));return}if(this.readyState===e.CLOSING){this._closeFrameSent&&this._closeFrameReceived&&this._socket.end();return}this.readyState=e.CLOSING,this._sender.close(t,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,this._finalized||(this._closeFrameReceived&&this._socket.end(),this._closeTimer=setTimeout(this._finalize,hy,!0)))})}}ping(t,r,i){if(this.readyState!==e.OPEN){if(i)return;throw new Error("not opened")}typeof t=="number"&&(t=t.toString()),r===void 0&&(r=!this._isServer),this._sender.ping(t||_t.EMPTY_BUFFER,r)}pong(t,r,i){if(this.readyState!==e.OPEN){if(i)return;throw new Error("not opened")}typeof t=="number"&&(t=t.toString()),r===void 0&&(r=!this._isServer),this._sender.pong(t||_t.EMPTY_BUFFER,r)}send(t,r,i){if(typeof r=="function"&&(i=r,r={}),this.readyState!==e.OPEN){if(i)i(new Error("not opened"));else throw new Error("not opened");return}typeof t=="number"&&(t=t.toString());let n=Object.assign({binary:typeof t!="string",mask:!this._isServer,compress:!0,fin:!0},r);this.extensions[tt.extensionName]||(n.compress=!1),this._sender.send(t||_t.EMPTY_BUFFER,n,i)}terminate(){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){this._req.abort(),this.finalize(new Error("closed before the connection is established"));return}this.finalize(!0)}}};we.CONNECTING=0;we.OPEN=1;we.CLOSING=2;we.CLOSED=3;["open","error","close","message"].forEach(e=>{Object.defineProperty(we.prototype,`on${e}`,{get(){let t=this.listeners(e);for(var r=0;r<t.length;r++)if(t[r]._listener)return t[r]._listener},set(t){let r=this.listeners(e);for(var i=0;i<r.length;i++)r[i]._listener&&this.removeListener(e,r[i]);this.addEventListener(e,t)}})});we.prototype.addEventListener=Bu.addEventListener;we.prototype.removeEventListener=Bu.removeEventListener;Au.exports=we;function dy(e,t,r){this.protocolVersion=r.protocolVersion,this._maxPayload=r.maxPayload,this.extensions=r.extensions,this.protocol=r.protocol,this._isServer=!0,this.setSocket(e,t)}function py(e,t,r){if(r=Object.assign({protocolVersion:Gs[1],protocol:t.join(","),perMessageDeflate:!0,handshakeTimeout:null,localAddress:null,headers:null,family:null,origin:null,agent:null,host:null,checkServerIdentity:null,rejectUnauthorized:null,passphrase:null,ciphers:null,ecdhCurve:null,cert:null,key:null,pfx:null,ca:null},r),Gs.indexOf(r.protocolVersion)===-1)throw new Error(`unsupported protocol version: ${r.protocolVersion} (supported versions: ${Gs.join(", ")})`);this.protocolVersion=r.protocolVersion,this._isServer=!1,this.url=e;let i=ly.parse(e),n=i.protocol==="ws+unix:";if(!i.host&&(!n||!i.path))throw new Error("invalid url");let s=i.protocol==="wss:"||i.protocol==="https:",o=Ru.randomBytes(16).toString("base64"),f=s?ay:fy;var a;let l={port:i.port||(s?443:80),host:i.hostname,path:"/",headers:{"Sec-WebSocket-Version":r.protocolVersion,"Sec-WebSocket-Key":o,Connection:"Upgrade",Upgrade:"websocket"}};if(r.headers&&Object.assign(l.headers,r.headers),r.perMessageDeflate&&(a=new tt(r.perMessageDeflate!==!0?r.perMessageDeflate:{},!1),l.headers["Sec-WebSocket-Extensions"]=Pu.format({[tt.extensionName]:a.offer()})),r.protocol&&(l.headers["Sec-WebSocket-Protocol"]=r.protocol),r.origin&&(r.protocolVersion<13?l.headers["Sec-WebSocket-Origin"]=r.origin:l.headers.Origin=r.origin),r.host&&(l.headers.Host=r.host),i.auth&&(l.auth=i.auth),r.localAddress&&(l.localAddress=r.localAddress),r.family&&(l.family=r.family),n){let h=i.path.split(":");l.socketPath=h[0],l.path=h[1]}else i.path&&(i.path.charAt(0)!=="/"?l.path=`/${i.path}`:l.path=i.path);var u=r.agent;(r.rejectUnauthorized!=null||r.checkServerIdentity||r.passphrase||r.ciphers||r.ecdhCurve||r.cert||r.key||r.pfx||r.ca)&&(r.passphrase&&(l.passphrase=r.passphrase),r.ciphers&&(l.ciphers=r.ciphers),r.ecdhCurve&&(l.ecdhCurve=r.ecdhCurve),r.cert&&(l.cert=r.cert),r.key&&(l.key=r.key),r.pfx&&(l.pfx=r.pfx),r.ca&&(l.ca=r.ca),r.checkServerIdentity&&(l.checkServerIdentity=r.checkServerIdentity),r.rejectUnauthorized!=null&&(l.rejectUnauthorized=r.rejectUnauthorized),u||(u=new f.Agent(l))),u&&(l.agent=u),this._req=f.get(l),r.handshakeTimeout&&this._req.setTimeout(r.handshakeTimeout,()=>{this._req.abort(),this.finalize(new Error("opening handshake has timed out"))}),this._req.on("error",h=>{this._req.aborted||(this._req=null,this.finalize(h))}),this._req.on("response",h=>{this.emit("unexpected-response",this._req,h)||(this._req.abort(),this.finalize(new Error(`unexpected server response (${h.statusCode})`)))}),this._req.on("upgrade",(h,c,d)=>{if(this.emit("headers",h.headers,h),this.readyState!==we.CONNECTING)return;this._req=null;let _=Ru.createHash("sha1").update(o+_t.GUID,"binary").digest("base64");if(h.headers["sec-websocket-accept"]!==_)return c.destroy(),this.finalize(new Error("invalid server key"));let v=h.headers["sec-websocket-protocol"],m=(r.protocol||"").split(/, */);var p;if(!r.protocol&&v?p="server sent a subprotocol even though none requested":r.protocol&&!v?p="server sent no subprotocol even though requested":v&&m.indexOf(v)===-1&&(p="server responded with an invalid protocol"),p)return c.destroy(),this.finalize(new Error(p));if(v&&(this.protocol=v),a)try{let g=Pu.parse(h.headers["sec-websocket-extensions"]);g[tt.extensionName]&&(a.accept(g[tt.extensionName]),this.extensions[tt.extensionName]=a)}catch{c.destroy(),this.finalize(new Error("invalid Sec-WebSocket-Extensions header"));return}this.setSocket(c,d)})}});var Lu=b((u0,Mu)=>{"use strict";var _y=ve(),gy=require("events"),by=require("crypto"),yy=Is(),Ri=require("http"),vy=require("url"),gt=cr(),Nu=Ms(),my=_r(),wy=zs(),Sy=_y.Buffer,Ks=class extends gy{constructor(t,r){if(super(),t=Object.assign({maxPayload:100*1024*1024,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null},t),t.port==null&&!t.server&&!t.noServer)throw new TypeError("missing or invalid options");t.port!=null?(this._server=Ri.createServer((i,n)=>{let s=Ri.STATUS_CODES[426];n.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"}),n.end(s)}),this._server.listen(t.port,t.host,t.backlog,r)):t.server&&(this._server=t.server),this._server&&(this._ultron=new yy(this._server),this._ultron.on("listening",()=>this.emit("listening")),this._ultron.on("error",i=>this.emit("error",i)),this._ultron.on("upgrade",(i,n,s)=>{this.handleUpgrade(i,n,s,o=>{this.emit("connection",o,i)})})),t.perMessageDeflate===!0&&(t.perMessageDeflate={}),t.clientTracking&&(this.clients=new Set),this.options=t}close(t){if(this.clients)for(let i of this.clients)i.terminate();let r=this._server;if(r&&(this._ultron.destroy(),this._ultron=this._server=null,this.options.port!=null))return r.close(t);t&&t()}shouldHandle(t){return!(this.options.path&&vy.parse(t.url).pathname!==this.options.path)}handleUpgrade(t,r,i,n){r.on("error",Ys);let s=+t.headers["sec-websocket-version"],o={};if(t.method!=="GET"||t.headers.upgrade.toLowerCase()!=="websocket"||!t.headers["sec-websocket-key"]||s!==8&&s!==13||!this.shouldHandle(t))return gr(r,400);if(this.options.perMessageDeflate){let a=new gt(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let l=Nu.parse(t.headers["sec-websocket-extensions"]);l[gt.extensionName]&&(a.accept(l[gt.extensionName]),o[gt.extensionName]=a)}catch{return gr(r,400)}}var f=(t.headers["sec-websocket-protocol"]||"").split(/, */);if(this.options.handleProtocols){if(f=this.options.handleProtocols(f,t),f===!1)return gr(r,401)}else f=f[0];if(this.options.verifyClient){let a={origin:t.headers[`${s===8?"sec-websocket-origin":"origin"}`],secure:!!(t.connection.authorized||t.connection.encrypted),req:t};if(this.options.verifyClient.length===2){this.options.verifyClient(a,(l,u,h)=>{if(!l)return gr(r,u||401,h);this.completeUpgrade(f,o,s,t,r,i,n)});return}if(!this.options.verifyClient(a))return gr(r,401)}this.completeUpgrade(f,o,s,t,r,i,n)}completeUpgrade(t,r,i,n,s,o,f){if(!s.readable||!s.writable)return s.destroy();let l=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${by.createHash("sha1").update(n.headers["sec-websocket-key"]+my.GUID,"binary").digest("base64")}`];if(t&&l.push(`Sec-WebSocket-Protocol: ${t}`),r[gt.extensionName]){let h=r[gt.extensionName].params,c=Nu.format({[gt.extensionName]:[h]});l.push(`Sec-WebSocket-Extensions: ${c}`)}this.emit("headers",l,n),s.write(l.concat(`\r
`).join(`\r
`));let u=new wy([s,o],null,{maxPayload:this.options.maxPayload,protocolVersion:i,extensions:r,protocol:t});this.clients&&(this.clients.add(u),u.on("close",()=>this.clients.delete(u))),s.removeListener("error",Ys),f(u)}};Mu.exports=Ks;function Ys(){this.destroy()}function gr(e,t,r){e.writable&&(r=r||Ri.STATUS_CODES[t],e.write(`HTTP/1.1 ${t} ${Ri.STATUS_CODES[t]}\r
Connection: close\r
Content-type: text/html\r
Content-Length: ${Sy.byteLength(r)}\r
\r
`+r)),e.removeListener("error",Ys),e.destroy()}});var Qs=b((c0,qu)=>{"use strict";var Pi=zs();Pi.Server=Lu();Pi.Receiver=Ws();Pi.Sender=$s();qu.exports=Pi});var Uu=b((h0,Du)=>{var Ey={}.toString;Du.exports=Array.isArray||function(e){return Ey.call(e)=="[object Array]"}});var Js=b((d0,ju)=>{ju.exports=require("stream")});var Bt=b(re=>{function xy(e){return Array.isArray?Array.isArray(e):Bi(e)==="[object Array]"}re.isArray=xy;function Cy(e){return typeof e=="boolean"}re.isBoolean=Cy;function Ty(e){return e===null}re.isNull=Ty;function Iy(e){return e==null}re.isNullOrUndefined=Iy;function Oy(e){return typeof e=="number"}re.isNumber=Oy;function ky(e){return typeof e=="string"}re.isString=ky;function Ry(e){return typeof e=="symbol"}re.isSymbol=Ry;function Py(e){return e===void 0}re.isUndefined=Py;function By(e){return Bi(e)==="[object RegExp]"}re.isRegExp=By;function Ay(e){return typeof e=="object"&&e!==null}re.isObject=Ay;function Ny(e){return Bi(e)==="[object Date]"}re.isDate=Ny;function My(e){return Bi(e)==="[object Error]"||e instanceof Error}re.isError=My;function Ly(e){return typeof e=="function"}re.isFunction=Ly;function qy(e){return e===null||typeof e=="boolean"||typeof e=="number"||typeof e=="string"||typeof e=="symbol"||typeof e>"u"}re.isPrimitive=qy;re.isBuffer=Buffer.isBuffer;function Bi(e){return Object.prototype.toString.call(e)}});var Wu=b((_0,Xs)=>{"use strict";function Dy(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var Fu=ve().Buffer,br=require("util");function Uy(e,t,r){e.copy(t,r)}Xs.exports=function(){function e(){Dy(this,e),this.head=null,this.tail=null,this.length=0}return e.prototype.push=function(r){var i={data:r,next:null};this.length>0?this.tail.next=i:this.head=i,this.tail=i,++this.length},e.prototype.unshift=function(r){var i={data:r,next:this.head};this.length===0&&(this.tail=i),this.head=i,++this.length},e.prototype.shift=function(){if(this.length!==0){var r=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,r}},e.prototype.clear=function(){this.head=this.tail=null,this.length=0},e.prototype.join=function(r){if(this.length===0)return"";for(var i=this.head,n=""+i.data;i=i.next;)n+=r+i.data;return n},e.prototype.concat=function(r){if(this.length===0)return Fu.alloc(0);for(var i=Fu.allocUnsafe(r>>>0),n=this.head,s=0;n;)Uy(n.data,i,s),s+=n.data.length,n=n.next;return i},e}();br&&br.inspect&&br.inspect.custom&&(Xs.exports.prototype[br.inspect.custom]=function(){var e=br.inspect({length:this.length});return this.constructor.name+" "+e})});var Zs=b((g0,Vu)=>{"use strict";var Ai=It();function jy(e,t){var r=this,i=this._readableState&&this._readableState.destroyed,n=this._writableState&&this._writableState.destroyed;return i||n?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,Ai.nextTick(Ni,this,e)):Ai.nextTick(Ni,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(s){!t&&s?r._writableState?r._writableState.errorEmitted||(r._writableState.errorEmitted=!0,Ai.nextTick(Ni,r,s)):Ai.nextTick(Ni,r,s):t&&t(s)}),this)}function Fy(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function Ni(e,t){e.emit("error",t)}Vu.exports={destroy:jy,undestroy:Fy}});var to=b((b0,Ju)=>{"use strict";var bt=It();Ju.exports=z;function $u(e){var t=this;this.next=null,this.entry=null,this.finish=function(){sv(t,e)}}var Wy=!process.browser&&["v0.10","v0.9."].indexOf(process.version.slice(0,5))>-1?setImmediate:bt.nextTick,At;z.WritableState=vr;var Gu=Object.create(Bt());Gu.inherits=ie();var Vy={deprecate:an()},zu=Js(),Li=ve().Buffer,Hy=(typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function $y(e){return Li.from(e)}function Gy(e){return Li.isBuffer(e)||e instanceof Hy}var Ku=Zs();Gu.inherits(z,zu);function zy(){}function vr(e,t){At=At||yt(),e=e||{};var r=t instanceof At;this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var i=e.highWaterMark,n=e.writableHighWaterMark,s=this.objectMode?16:16*1024;i||i===0?this.highWaterMark=i:r&&(n||n===0)?this.highWaterMark=n:this.highWaterMark=s,this.highWaterMark=Math.floor(this.highWaterMark),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var o=e.decodeStrings===!1;this.decodeStrings=!o,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(f){ev(t,f)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new $u(this)}vr.prototype.getBuffer=function(){for(var t=this.bufferedRequest,r=[];t;)r.push(t),t=t.next;return r};(function(){try{Object.defineProperty(vr.prototype,"buffer",{get:Vy.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}})();var Mi;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(Mi=Function.prototype[Symbol.hasInstance],Object.defineProperty(z,Symbol.hasInstance,{value:function(e){return Mi.call(this,e)?!0:this!==z?!1:e&&e._writableState instanceof vr}})):Mi=function(e){return e instanceof this};function z(e){if(At=At||yt(),!Mi.call(z,this)&&!(this instanceof At))return new z(e);this._writableState=new vr(e,this),this.writable=!0,e&&(typeof e.write=="function"&&(this._write=e.write),typeof e.writev=="function"&&(this._writev=e.writev),typeof e.destroy=="function"&&(this._destroy=e.destroy),typeof e.final=="function"&&(this._final=e.final)),zu.call(this)}z.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))};function Ky(e,t){var r=new Error("write after end");e.emit("error",r),bt.nextTick(t,r)}function Yy(e,t,r,i){var n=!0,s=!1;return r===null?s=new TypeError("May not write null values to stream"):typeof r!="string"&&r!==void 0&&!t.objectMode&&(s=new TypeError("Invalid non-string/buffer chunk")),s&&(e.emit("error",s),bt.nextTick(i,s),n=!1),n}z.prototype.write=function(e,t,r){var i=this._writableState,n=!1,s=!i.objectMode&&Gy(e);return s&&!Li.isBuffer(e)&&(e=$y(e)),typeof t=="function"&&(r=t,t=null),s?t="buffer":t||(t=i.defaultEncoding),typeof r!="function"&&(r=zy),i.ended?Ky(this,r):(s||Yy(this,i,e,r))&&(i.pendingcb++,n=Jy(this,i,s,e,t,r)),n};z.prototype.cork=function(){var e=this._writableState;e.corked++};z.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.bufferProcessing&&e.bufferedRequest&&Yu(this,e))};z.prototype.setDefaultEncoding=function(t){if(typeof t=="string"&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this};function Qy(e,t,r){return!e.objectMode&&e.decodeStrings!==!1&&typeof t=="string"&&(t=Li.from(t,r)),t}Object.defineProperty(z.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function Jy(e,t,r,i,n,s){if(!r){var o=Qy(t,i,n);i!==o&&(r=!0,n="buffer",i=o)}var f=t.objectMode?1:i.length;t.length+=f;var a=t.length<t.highWaterMark;if(a||(t.needDrain=!0),t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:i,encoding:n,isBuf:r,callback:s,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else eo(e,t,!1,f,i,n,s);return a}function eo(e,t,r,i,n,s,o){t.writelen=i,t.writecb=o,t.writing=!0,t.sync=!0,r?e._writev(n,t.onwrite):e._write(n,s,t.onwrite),t.sync=!1}function Xy(e,t,r,i,n){--t.pendingcb,r?(bt.nextTick(n,i),bt.nextTick(yr,e,t),e._writableState.errorEmitted=!0,e.emit("error",i)):(n(i),e._writableState.errorEmitted=!0,e.emit("error",i),yr(e,t))}function Zy(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function ev(e,t){var r=e._writableState,i=r.sync,n=r.writecb;if(Zy(r),t)Xy(e,r,i,t,n);else{var s=Qu(r);!s&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest&&Yu(e,r),i?Wy(Hu,e,r,s,n):Hu(e,r,s,n)}}function Hu(e,t,r,i){r||tv(e,t),t.pendingcb--,i(),yr(e,t)}function tv(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function Yu(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var i=t.bufferedRequestCount,n=new Array(i),s=t.corkedRequestsFree;s.entry=r;for(var o=0,f=!0;r;)n[o]=r,r.isBuf||(f=!1),r=r.next,o+=1;n.allBuffers=f,eo(e,t,!0,t.length,n,"",s.finish),t.pendingcb++,t.lastBufferedRequest=null,s.next?(t.corkedRequestsFree=s.next,s.next=null):t.corkedRequestsFree=new $u(t),t.bufferedRequestCount=0}else{for(;r;){var a=r.chunk,l=r.encoding,u=r.callback,h=t.objectMode?1:a.length;if(eo(e,t,!1,h,a,l,u),r=r.next,t.bufferedRequestCount--,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}z.prototype._write=function(e,t,r){r(new Error("_write() is not implemented"))};z.prototype._writev=null;z.prototype.end=function(e,t,r){var i=this._writableState;typeof e=="function"?(r=e,e=null,t=null):typeof t=="function"&&(r=t,t=null),e!=null&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||nv(this,i,r)};function Qu(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function rv(e,t){e._final(function(r){t.pendingcb--,r&&e.emit("error",r),t.prefinished=!0,e.emit("prefinish"),yr(e,t)})}function iv(e,t){!t.prefinished&&!t.finalCalled&&(typeof e._final=="function"?(t.pendingcb++,t.finalCalled=!0,bt.nextTick(rv,e,t)):(t.prefinished=!0,e.emit("prefinish")))}function yr(e,t){var r=Qu(t);return r&&(iv(e,t),t.pendingcb===0&&(t.finished=!0,e.emit("finish"))),r}function nv(e,t,r){t.ending=!0,yr(e,t),r&&(t.finished?bt.nextTick(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function sv(e,t,r){var i=e.entry;for(e.entry=null;i;){var n=i.callback;t.pendingcb--,n(r),i=i.next}t.corkedRequestsFree.next=e}Object.defineProperty(z.prototype,"destroyed",{get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}});z.prototype.destroy=Ku.destroy;z.prototype._undestroy=Ku.undestroy;z.prototype._destroy=function(e,t){this.end(),t(e)}});var yt=b((y0,tc)=>{"use strict";var Xu=It(),ov=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};tc.exports=qe;var Zu=Object.create(Bt());Zu.inherits=ie();var ec=no(),io=to();Zu.inherits(qe,ec);for(ro=ov(io.prototype),qi=0;qi<ro.length;qi++)Di=ro[qi],qe.prototype[Di]||(qe.prototype[Di]=io.prototype[Di]);var ro,Di,qi;function qe(e){if(!(this instanceof qe))return new qe(e);ec.call(this,e),io.call(this,e),e&&e.readable===!1&&(this.readable=!1),e&&e.writable===!1&&(this.writable=!1),this.allowHalfOpen=!0,e&&e.allowHalfOpen===!1&&(this.allowHalfOpen=!1),this.once("end",av)}Object.defineProperty(qe.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function av(){this.allowHalfOpen||this._writableState.ended||Xu.nextTick(fv,this)}function fv(e){e.end()}Object.defineProperty(qe.prototype,"destroyed",{get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(e){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=e,this._writableState.destroyed=e)}});qe.prototype._destroy=function(e,t){this.push(null),this.end(),Xu.nextTick(t,e)}});var ao=b(ic=>{"use strict";var oo=ve().Buffer,rc=oo.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function lv(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function uv(e){var t=lv(e);if(typeof t!="string"&&(oo.isEncoding===rc||!rc(e)))throw new Error("Unknown encoding: "+e);return t||e}ic.StringDecoder=mr;function mr(e){this.encoding=uv(e);var t;switch(this.encoding){case"utf16le":this.text=gv,this.end=bv,t=4;break;case"utf8":this.fillLast=dv,t=4;break;case"base64":this.text=yv,this.end=vv,t=3;break;default:this.write=mv,this.end=wv;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=oo.allocUnsafe(t)}mr.prototype.write=function(e){if(e.length===0)return"";var t,r;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""};mr.prototype.end=_v;mr.prototype.text=pv;mr.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function so(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function cv(e,t,r){var i=t.length-1;if(i<r)return 0;var n=so(t[i]);return n>=0?(n>0&&(e.lastNeed=n-1),n):--i<r||n===-2?0:(n=so(t[i]),n>=0?(n>0&&(e.lastNeed=n-2),n):--i<r||n===-2?0:(n=so(t[i]),n>=0?(n>0&&(n===2?n=0:e.lastNeed=n-3),n):0))}function hv(e,t,r){if((t[0]&192)!==128)return e.lastNeed=0,"\uFFFD";if(e.lastNeed>1&&t.length>1){if((t[1]&192)!==128)return e.lastNeed=1,"\uFFFD";if(e.lastNeed>2&&t.length>2&&(t[2]&192)!==128)return e.lastNeed=2,"\uFFFD"}}function dv(e){var t=this.lastTotal-this.lastNeed,r=hv(this,e,t);if(r!==void 0)return r;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function pv(e,t){var r=cv(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var i=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,i),e.toString("utf8",t,i)}function _v(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"\uFFFD":t}function gv(e,t){if((e.length-t)%2===0){var r=e.toString("utf16le",t);if(r){var i=r.charCodeAt(r.length-1);if(i>=55296&&i<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function bv(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function yv(e,t){var r=(e.length-t)%3;return r===0?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function vv(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function mv(e){return e.toString(this.encoding)}function wv(e){return e&&e.length?this.write(e):""}});var no=b((w0,_c)=>{"use strict";var Mt=It();_c.exports=V;var Sv=Uu(),wr;V.ReadableState=uc;var m0=require("events").EventEmitter,ac=function(e,t){return e.listeners(t).length},ho=Js(),Sr=ve().Buffer,Ev=(typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function xv(e){return Sr.from(e)}function Cv(e){return Sr.isBuffer(e)||e instanceof Ev}var fc=Object.create(Bt());fc.inherits=ie();var fo=require("util"),L=void 0;fo&&fo.debuglog?L=fo.debuglog("stream"):L=function(){};var Tv=Wu(),lc=Zs(),Nt;fc.inherits(V,ho);var lo=["error","close","destroy","pause","resume"];function Iv(e,t,r){if(typeof e.prependListener=="function")return e.prependListener(t,r);!e._events||!e._events[t]?e.on(t,r):Sv(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]}function uc(e,t){wr=wr||yt(),e=e||{};var r=t instanceof wr;this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var i=e.highWaterMark,n=e.readableHighWaterMark,s=this.objectMode?16:16*1024;i||i===0?this.highWaterMark=i:r&&(n||n===0)?this.highWaterMark=n:this.highWaterMark=s,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new Tv,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(Nt||(Nt=ao().StringDecoder),this.decoder=new Nt(e.encoding),this.encoding=e.encoding)}function V(e){if(wr=wr||yt(),!(this instanceof V))return new V(e);this._readableState=new uc(e,this),this.readable=!0,e&&(typeof e.read=="function"&&(this._read=e.read),typeof e.destroy=="function"&&(this._destroy=e.destroy)),ho.call(this)}Object.defineProperty(V.prototype,"destroyed",{get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}});V.prototype.destroy=lc.destroy;V.prototype._undestroy=lc.undestroy;V.prototype._destroy=function(e,t){this.push(null),t(e)};V.prototype.push=function(e,t){var r=this._readableState,i;return r.objectMode?i=!0:typeof e=="string"&&(t=t||r.defaultEncoding,t!==r.encoding&&(e=Sr.from(e,t),t=""),i=!0),cc(this,e,t,!1,i)};V.prototype.unshift=function(e){return cc(this,e,null,!0,!1)};function cc(e,t,r,i,n){var s=e._readableState;if(t===null)s.reading=!1,Pv(e,s);else{var o;n||(o=Ov(s,t)),o?e.emit("error",o):s.objectMode||t&&t.length>0?(typeof t!="string"&&!s.objectMode&&Object.getPrototypeOf(t)!==Sr.prototype&&(t=xv(t)),i?s.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):uo(e,s,t,!0):s.ended?e.emit("error",new Error("stream.push() after EOF")):(s.reading=!1,s.decoder&&!r?(t=s.decoder.write(t),s.objectMode||t.length!==0?uo(e,s,t,!1):hc(e,s)):uo(e,s,t,!1))):i||(s.reading=!1)}return kv(s)}function uo(e,t,r,i){t.flowing&&t.length===0&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&Ui(e)),hc(e,t)}function Ov(e,t){var r;return!Cv(t)&&typeof t!="string"&&t!==void 0&&!e.objectMode&&(r=new TypeError("Invalid non-string/buffer chunk")),r}function kv(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}V.prototype.isPaused=function(){return this._readableState.flowing===!1};V.prototype.setEncoding=function(e){return Nt||(Nt=ao().StringDecoder),this._readableState.decoder=new Nt(e),this._readableState.encoding=e,this};var nc=8388608;function Rv(e){return e>=nc?e=nc:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function sc(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=Rv(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}V.prototype.read=function(e){L("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return L("read: emitReadable",t.length,t.ended),t.length===0&&t.ended?co(this):Ui(this),null;if(e=sc(e,t),e===0&&t.ended)return t.length===0&&co(this),null;var i=t.needReadable;L("need readable",i),(t.length===0||t.length-e<t.highWaterMark)&&(i=!0,L("length less than watermark",i)),t.ended||t.reading?(i=!1,L("reading or ended",i)):i&&(L("do read"),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=sc(r,t)));var n;return e>0?n=dc(e,t):n=null,n===null?(t.needReadable=!0,e=0):t.length-=e,t.length===0&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&co(this)),n!==null&&this.emit("data",n),n};function Pv(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,Ui(e)}}function Ui(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(L("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?Mt.nextTick(oc,e):oc(e))}function oc(e){L("emit readable"),e.emit("readable"),po(e)}function hc(e,t){t.readingMore||(t.readingMore=!0,Mt.nextTick(Bv,e,t))}function Bv(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(L("maybeReadMore read 0"),e.read(0),r!==t.length);)r=t.length;t.readingMore=!1}V.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))};V.prototype.pipe=function(e,t){var r=this,i=this._readableState;switch(i.pipesCount){case 0:i.pipes=e;break;case 1:i.pipes=[i.pipes,e];break;default:i.pipes.push(e);break}i.pipesCount+=1,L("pipe count=%d opts=%j",i.pipesCount,t);var n=(!t||t.end!==!1)&&e!==process.stdout&&e!==process.stderr,s=n?f:m;i.endEmitted?Mt.nextTick(s):r.once("end",s),e.on("unpipe",o);function o(p,g){L("onunpipe"),p===r&&g&&g.hasUnpiped===!1&&(g.hasUnpiped=!0,u())}function f(){L("onend"),e.end()}var a=Av(r);e.on("drain",a);var l=!1;function u(){L("cleanup"),e.removeListener("close",_),e.removeListener("finish",v),e.removeListener("drain",a),e.removeListener("error",d),e.removeListener("unpipe",o),r.removeListener("end",f),r.removeListener("end",m),r.removeListener("data",c),l=!0,i.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&a()}var h=!1;r.on("data",c);function c(p){L("ondata"),h=!1;var g=e.write(p);g===!1&&!h&&((i.pipesCount===1&&i.pipes===e||i.pipesCount>1&&pc(i.pipes,e)!==-1)&&!l&&(L("false write response, pause",i.awaitDrain),i.awaitDrain++,h=!0),r.pause())}function d(p){L("onerror",p),m(),e.removeListener("error",d),ac(e,"error")===0&&e.emit("error",p)}Iv(e,"error",d);function _(){e.removeListener("finish",v),m()}e.once("close",_);function v(){L("onfinish"),e.removeListener("close",_),m()}e.once("finish",v);function m(){L("unpipe"),r.unpipe(e)}return e.emit("pipe",r),i.flowing||(L("pipe resume"),r.resume()),e};function Av(e){return function(){var t=e._readableState;L("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&ac(e,"data")&&(t.flowing=!0,po(e))}}V.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r),this);if(!e){var i=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var s=0;s<n;s++)i[s].emit("unpipe",this,{hasUnpiped:!1});return this}var o=pc(t.pipes,e);return o===-1?this:(t.pipes.splice(o,1),t.pipesCount-=1,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,r),this)};V.prototype.on=function(e,t){var r=ho.prototype.on.call(this,e,t);if(e==="data")this._readableState.flowing!==!1&&this.resume();else if(e==="readable"){var i=this._readableState;!i.endEmitted&&!i.readableListening&&(i.readableListening=i.needReadable=!0,i.emittedReadable=!1,i.reading?i.length&&Ui(this):Mt.nextTick(Nv,this))}return r};V.prototype.addListener=V.prototype.on;function Nv(e){L("readable nexttick read 0"),e.read(0)}V.prototype.resume=function(){var e=this._readableState;return e.flowing||(L("resume"),e.flowing=!0,Mv(this,e)),this};function Mv(e,t){t.resumeScheduled||(t.resumeScheduled=!0,Mt.nextTick(Lv,e,t))}function Lv(e,t){t.reading||(L("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),po(e),t.flowing&&!t.reading&&e.read(0)}V.prototype.pause=function(){return L("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(L("pause"),this._readableState.flowing=!1,this.emit("pause")),this};function po(e){var t=e._readableState;for(L("flow",t.flowing);t.flowing&&e.read()!==null;);}V.prototype.wrap=function(e){var t=this,r=this._readableState,i=!1;e.on("end",function(){if(L("wrapped end"),r.decoder&&!r.ended){var o=r.decoder.end();o&&o.length&&t.push(o)}t.push(null)}),e.on("data",function(o){if(L("wrapped data"),r.decoder&&(o=r.decoder.write(o)),!(r.objectMode&&o==null)&&!(!r.objectMode&&(!o||!o.length))){var f=t.push(o);f||(i=!0,e.pause())}});for(var n in e)this[n]===void 0&&typeof e[n]=="function"&&(this[n]=function(o){return function(){return e[o].apply(e,arguments)}}(n));for(var s=0;s<lo.length;s++)e.on(lo[s],this.emit.bind(this,lo[s]));return this._read=function(o){L("wrapped _read",o),i&&(i=!1,e.resume())},this};Object.defineProperty(V.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}});V._fromList=dc;function dc(e,t){if(t.length===0)return null;var r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(t.decoder?r=t.buffer.join(""):t.buffer.length===1?r=t.buffer.head.data:r=t.buffer.concat(t.length),t.buffer.clear()):r=qv(e,t.buffer,t.decoder),r}function qv(e,t,r){var i;return e<t.head.data.length?(i=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):e===t.head.data.length?i=t.shift():i=r?Dv(e,t):Uv(e,t),i}function Dv(e,t){var r=t.head,i=1,n=r.data;for(e-=n.length;r=r.next;){var s=r.data,o=e>s.length?s.length:e;if(o===s.length?n+=s:n+=s.slice(0,e),e-=o,e===0){o===s.length?(++i,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=s.slice(o));break}++i}return t.length-=i,n}function Uv(e,t){var r=Sr.allocUnsafe(e),i=t.head,n=1;for(i.data.copy(r),e-=i.data.length;i=i.next;){var s=i.data,o=e>s.length?s.length:e;if(s.copy(r,r.length-e,0,o),e-=o,e===0){o===s.length?(++n,i.next?t.head=i.next:t.head=t.tail=null):(t.head=i,i.data=s.slice(o));break}++n}return t.length-=n,r}function co(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,Mt.nextTick(jv,t,e))}function jv(e,t){!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function pc(e,t){for(var r=0,i=e.length;r<i;r++)if(e[r]===t)return r;return-1}});var _o=b((S0,yc)=>{"use strict";yc.exports=De;var ji=yt(),bc=Object.create(Bt());bc.inherits=ie();bc.inherits(De,ji);function Fv(e,t){var r=this._transformState;r.transforming=!1;var i=r.writecb;if(!i)return this.emit("error",new Error("write callback called multiple times"));r.writechunk=null,r.writecb=null,t!=null&&this.push(t),i(e);var n=this._readableState;n.reading=!1,(n.needReadable||n.length<n.highWaterMark)&&this._read(n.highWaterMark)}function De(e){if(!(this instanceof De))return new De(e);ji.call(this,e),this._transformState={afterTransform:Fv.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.on("prefinish",Wv)}function Wv(){var e=this;typeof this._flush=="function"?this._flush(function(t,r){gc(e,t,r)}):gc(this,null,null)}De.prototype.push=function(e,t){return this._transformState.needTransform=!1,ji.prototype.push.call(this,e,t)};De.prototype._transform=function(e,t,r){throw new Error("_transform() is not implemented")};De.prototype._write=function(e,t,r){var i=this._transformState;if(i.writecb=r,i.writechunk=e,i.writeencoding=t,!i.transforming){var n=this._readableState;(i.needTransform||n.needReadable||n.length<n.highWaterMark)&&this._read(n.highWaterMark)}};De.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};De.prototype._destroy=function(e,t){var r=this;ji.prototype._destroy.call(this,e,function(i){t(i),r.emit("close")})};function gc(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new Error("Calling transform done when ws.length != 0");if(e._transformState.transforming)throw new Error("Calling transform done when still transforming");return e.push(null)}});var Sc=b((E0,wc)=>{"use strict";wc.exports=Er;var vc=_o(),mc=Object.create(Bt());mc.inherits=ie();mc.inherits(Er,vc);function Er(e){if(!(this instanceof Er))return new Er(e);vc.call(this,e)}Er.prototype._transform=function(e,t,r){r(null,e)}});var go=b((X,Fi)=>{var Ie=require("stream");process.env.READABLE_STREAM==="disable"&&Ie?(Fi.exports=Ie,X=Fi.exports=Ie.Readable,X.Readable=Ie.Readable,X.Writable=Ie.Writable,X.Duplex=Ie.Duplex,X.Transform=Ie.Transform,X.PassThrough=Ie.PassThrough,X.Stream=Ie):(X=Fi.exports=no(),X.Stream=Ie||X,X.Readable=X,X.Writable=to(),X.Duplex=yt(),X.Transform=_o(),X.PassThrough=Sc())});var Ic=b((x0,Tc)=>{var Wi=go(),Ec=zn(),Vv=ie(),Hv=Kn(),xc=Buffer.from&&Buffer.from!==Uint8Array.from?Buffer.from([0]):new Buffer([0]),bo=function(e,t){e._corked?e.once("uncork",t):t()},$v=function(e,t){e._autoDestroy&&e.destroy(t)},Cc=function(e,t){return function(r){r?$v(e,r.message==="premature close"?null:r):t&&!e._ended&&e.end()}},Gv=function(e,t){if(!e||e._writableState&&e._writableState.finished)return t();if(e._writableState)return e.end(t);e.end(),t()},zv=function(e){return new Wi.Readable({objectMode:!0,highWaterMark:16}).wrap(e)},Z=function(e,t,r){if(!(this instanceof Z))return new Z(e,t,r);Wi.Duplex.call(this,r),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!r||r.autoDestroy!==!1,this._forwardDestroy=!r||r.destroy!==!1,this._forwardEnd=!r||r.end!==!1,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,e&&this.setWritable(e),t&&this.setReadable(t)};Vv(Z,Wi.Duplex);Z.obj=function(e,t,r){return r||(r={}),r.objectMode=!0,r.highWaterMark=16,new Z(e,t,r)};Z.prototype.cork=function(){++this._corked===1&&this.emit("cork")};Z.prototype.uncork=function(){this._corked&&--this._corked===0&&this.emit("uncork")};Z.prototype.setWritable=function(e){if(this._unwrite&&this._unwrite(),this.destroyed){e&&e.destroy&&e.destroy();return}if(e===null||e===!1){this.end();return}var t=this,r=Ec(e,{writable:!0,readable:!1},Cc(this,this._forwardEnd)),i=function(){var s=t._ondrain;t._ondrain=null,s&&s()},n=function(){t._writable.removeListener("drain",i),r()};this._unwrite&&process.nextTick(i),this._writable=e,this._writable.on("drain",i),this._unwrite=n,this.uncork()};Z.prototype.setReadable=function(e){if(this._unread&&this._unread(),this.destroyed){e&&e.destroy&&e.destroy();return}if(e===null||e===!1){this.push(null),this.resume();return}var t=this,r=Ec(e,{writable:!1,readable:!0},Cc(this)),i=function(){t._forward()},n=function(){t.push(null)},s=function(){t._readable2.removeListener("readable",i),t._readable2.removeListener("end",n),r()};this._drained=!0,this._readable=e,this._readable2=e._readableState?e:zv(e),this._readable2.on("readable",i),this._readable2.on("end",n),this._unread=s,this._forward()};Z.prototype._read=function(){this._drained=!0,this._forward()};Z.prototype._forward=function(){if(!(this._forwarding||!this._readable2||!this._drained)){this._forwarding=!0;for(var e;this._drained&&(e=Hv(this._readable2))!==null;)this.destroyed||(this._drained=this.push(e));this._forwarding=!1}};Z.prototype.destroy=function(e){if(!this.destroyed){this.destroyed=!0;var t=this;process.nextTick(function(){t._destroy(e)})}};Z.prototype._destroy=function(e){if(e){var t=this._ondrain;this._ondrain=null,t?t(e):this.emit("error",e)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")};Z.prototype._write=function(e,t,r){if(this.destroyed)return r();if(this._corked)return bo(this,this._write.bind(this,e,t,r));if(e===xc)return this._finish(r);if(!this._writable)return r();this._writable.write(e)===!1?this._ondrain=r:r()};Z.prototype._finish=function(e){var t=this;this.emit("preend"),bo(this,function(){Gv(t._forwardEnd&&t._writable,function(){t._writableState.prefinished===!1&&(t._writableState.prefinished=!0),t.emit("prefinish"),bo(t,e)})})};Z.prototype.end=function(e,t,r){return typeof e=="function"?this.end(null,null,e):typeof t=="function"?this.end(e,null,t):(this._ended=!0,e&&this.write(e),this._writableState.ending||this.write(xc),Wi.Writable.prototype.end.call(this,r))};Tc.exports=Z});var yo=b((C0,kc)=>{"use strict";var Kv=go().Transform,Yv=Ic(),Oc=Qs(),Lt=ve().Buffer;kc.exports=Jv;function Qv(e,t,r){var i=new Kv({objectMode:e.objectMode});return i._write=t,i._flush=r,i}function Jv(e,t,r){var i,n,s=process.title==="browser",o=!!global.WebSocket,f=s?_:d;t&&!Array.isArray(t)&&typeof t=="object"&&(r=t,t=null,(typeof r.protocol=="string"||Array.isArray(r.protocol))&&(t=r.protocol)),r||(r={}),r.objectMode===void 0&&(r.objectMode=!(r.binary===!0||r.binary===void 0));var a=Qv(r,f,v);r.objectMode||(a._writev=C);var l=r.browserBufferSize||1024*512,u=r.browserBufferTimeout||1e3;typeof e=="object"?n=e:(o&&s?n=new Oc(e,t):n=new Oc(e,t,r),n.binaryType="arraybuffer");var h=typeof n.addEventListener>"u";n.readyState===n.OPEN?i=a:(i=i=Yv(void 0,void 0,r),r.objectMode||(i._writev=C),h?n.addEventListener("open",m):n.onopen=m),i.socket=n,h?(n.addEventListener("close",p),n.addEventListener("error",g),n.addEventListener("message",S)):(n.onclose=p,n.onerror=g,n.onmessage=S),a.on("close",x);var c=!r.objectMode;function d(w,B,M){if(n.readyState!==n.OPEN){M();return}c&&typeof w=="string"&&(w=Lt.from(w,"utf8")),n.send(w,M)}function _(w,B,M){if(n.bufferedAmount>l){setTimeout(_,u,w,B,M);return}c&&typeof w=="string"&&(w=Lt.from(w,"utf8"));try{n.send(w)}catch(H){return M(H)}M()}function v(w){n.close(),w()}function m(){i.setReadable(a),i.setWritable(a),i.emit("connect")}function p(){i.end(),i.destroy()}function g(w){i.destroy(w)}function S(w){var B=w.data;B instanceof ArrayBuffer?B=Lt.from(B):B=Lt.from(B,"utf8"),a.push(B)}function x(){n.close()}function C(w,B){for(var M=new Array(w.length),H=0;H<w.length;H++)typeof w[H].chunk=="string"?M[H]=Lt.from(w[H],"utf8"):M[H]=w[H].chunk;this._write(Lt.concat(M),"binary",B)}return i}});var Rc=b((T0,vo)=>{"use strict";var Xv=Qs().Server,Zv=yo(),Vi=class extends Xv{constructor(t,r){super(t);var i=!1;this.on("newListener",function(n){!i&&n==="stream"&&(i=!0,this.on("connection",function(s,o){this.emit("stream",Zv(s,t),o)}))}),r&&this.on("stream",r)}};vo.exports.Server=Vi;vo.exports.createServer=function(e,t){return new Vi(e,t)}});var Bc=b((I0,Hi)=>{var Pc=Rc();Hi.exports=yo();Hi.exports.Server=Pc.Server;Hi.exports.createServer=Pc.createServer});var Nc=b((O0,Ac)=>{var em=Bc();function tm(e,t){return em(t.url,["mqttv3.1"],t.websocketOptions)}Ac.exports=tm});var $i=b((k0,Ir)=>{var rm=require("events"),im=require("util").inherits,nm=jl(),Cr=Gl(),Mc=Ts(),Oe=Kl(),R=ur(),sm=Zl(),om=require("path"),am=require("fs");function xr(e){return e>9?e:"0"+e}function fm(){var e=new Date;return e.getUTCFullYear()+""+xr(e.getUTCMonth()+1)+xr(e.getUTCDate())+"T"+xr(e.getUTCHours())+xr(e.getUTCMinutes())+xr(e.getUTCSeconds())+"Z"}function lm(e){return e.substring(0,e.indexOf("T"))}function um(e,t,r,i){var n=Cr(t,"AWS4"+e,{asBytes:!0}),s=Cr(r,n,{asBytes:!0}),o=Cr(i,s,{asBytes:!0}),f=Cr("aws4_request",o,{asBytes:!0});return f}function cm(e,t,r,i,n,s,o,f,a,l,u,h,c,d){var _="host",v="host:"+r.toLowerCase()+`
`,m=e+`
`+i+`
`+n+`
`+v+`
`+_+`
`+Mc(l,{asBytes:!0});c===!0&&console.log("canonical request: "+m+`
`);var p=Mc(m,{asBytes:!0});c===!0&&console.log("hashed canonical request: "+p+`
`);var g=`AWS4-HMAC-SHA256
`+h+`
`+u+"/"+f+"/"+a+`/aws4_request
`+p;c===!0&&console.log("string to sign: "+g+`
`);var S=um(o,u,f,a);c===!0&&console.log("signing key: "+S+`
`);var x=Cr(g,S,{asBytes:!0});c===!0&&console.log("signature: "+x+`
`);var C=n+"&X-Amz-Signature="+x;R(d)||(C+="&X-Amz-Security-Token="+encodeURIComponent(d));var w=t+r+i+"?"+C;return c===!0&&console.log("url: "+w+`
`),w}function Lc(e,t,r,i){var n=fm(),s=lm(n),o="/mqtt",f="iotdevicegateway",a="X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential="+t+"%2F"+s+"%2F"+e.region+"%2F"+f+"%2Faws4_request&X-Amz-Date="+n+"&X-Amz-SignedHeaders=host",l=e.host;return!R(e.port)&&e.port!==443&&(l=e.host+":"+e.port),cm("GET","wss://",l,o,a,t,r,e.region,f,"",s,n,e.debug,i)}function qc(e){var t="/mqtt",r=e.host;return!R(e.port)&&e.port!==443&&(r=e.host+":"+e.port),"wss://"+r+t+(e.customAuthQueryString||"")}function hm(e,t){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.call(this,e[r],parseInt(r,10))}function dm(e){var t={},r={};return hm(e.split(/\r?\n/),function(i){i=i.split(/(^|\s)[;#]/)[0];var n=i.match(/^\s*\[([^\[\]]+)\]\s*$/);if(n)r=n[1];else if(r){var s=i.match(/^\s*(.+?)\s*=\s*(.+?)\s*$/);s&&(t[r]=t[r]||{},t[r][s[1]]=s[2])}}),t}function Tr(e){if(!(this instanceof Tr))return new Tr(e);var t=this,r=[],i=!0,n=0,s="oldest";r.length=0;var o=[],f=50;o.length=0;var a=[],l=!0;a.length=0;var u=[];u.length=0;var h="inactive",c=null,d=250,_=300,v=1e3,m=2e4,p=128e3,g,S=null,x,C,w,B="?SDK=JavaScript&Version=",M=eu(),H=M.version,rt=B+H;if(R(e)||Object.keys(e).length===0)throw new Error(Oe.INVALID_CONNECT_OPTIONS);if(R(e.keepalive)&&(e.keepalive=_),(R(e.enableMetrics)||e.enableMetrics===!0)&&(R(e.username)?e.username=rt:e.username+=rt),R(e.baseReconnectTimeMs)||(v=e.baseReconnectTimeMs),R(e.minimumConnectionTimeMs)||(m=e.minimumConnectionTimeMs),R(e.maximumReconnectTimeMs)||(p=e.maximumReconnectTimeMs),R(e.drainTimeMs)||(d=e.drainTimeMs),R(e.autoResubscribe)||(l=e.autoResubscribe),R(e.offlineQueueing)||(i=e.offlineQueueing),R(e.offlineQueueMaxSize)||(n=e.offlineQueueMaxSize),R(e.offlineQueueDropBehavior)||(s=e.offlineQueueDropBehavior),g=v,e.reconnectPeriod=g,e.fastDisconnectDetection=!0,e.resubscribe=!1,e.baseReconnectTimeMs<=0)throw new Error(Oe.INVALID_RECONNECT_TIMING);if(p<v)throw new Error(Oe.INVALID_RECONNECT_TIMING);if(m<v)throw new Error(Oe.INVALID_RECONNECT_TIMING);if(s!=="newest"&&s!=="oldest")throw new Error(Oe.INVALID_OFFLINE_QUEUEING_PARAMETERS);if(n<0)throw new Error(Oe.INVALID_OFFLINE_QUEUEING_PARAMETERS);if(R(e.protocol)&&(e.protocol="mqtts"),R(e.host))throw new Error(Oe.INVALID_CONNECT_OPTIONS);if(R(e.servername)&&(e.servername=e.host.split(":")[0]),e.protocol==="mqtts")R(e.port)&&(e.port=8883),sm(e);else if(e.protocol==="wss"||e.protocol==="wss-custom-auth"){if(e.protocol==="wss"){if(R(e.accessKeyId)?x=process.env.AWS_ACCESS_KEY_ID:x=e.accessKeyId,R(e.secretKey)?C=process.env.AWS_SECRET_ACCESS_KEY:C=e.secretKey,R(e.sessionToken)?w=process.env.AWS_SESSION_TOKEN:w=e.sessionToken,R(x)||R(C)){var Se,kr=e.profile||process.env.AWS_PROFILE||"default";try{R(e.filename)?Se=Yc():Se=e.filename;var Yi=dm(am.readFileSync(Se,"utf-8")),Dt=Yi[kr];x=Dt.aws_access_key_id,C=Dt.aws_secret_access_key,w=Dt.aws_session_token}catch(T){console.log(T),console.log("Failed to read credentials for AWS_PROFILE "+kr+" from "+Se)}}if(R(x)||R(C))throw console.log("To connect via WebSocket/SigV4, AWS Access Key ID and AWS Secret Key must be passed either in options or as environment variables; see README.md"),new Error(Oe.INVALID_CONNECT_OPTIONS)}else if(R(e.customAuthHeaders)&&R(e.customAuthQueryString))throw console.log("To authenticate with a custom authorizer, you must provide the required HTTP headers or queryString; see README.md"),new Error(Oe.INVALID_CONNECT_OPTIONS);if(!R(e.host)&&R(e.region)){var Rr=/[a-zA-Z0-9]+\.iot\.([a-z]+-[a-z]+-[0-9]+)\.amazonaws\..+/,Pr=Rr.exec(e.host);if(Pr===null)throw console.log("Host endpoint is not valid"),new Error(Oe.INVALID_CONNECT_OPTIONS);e.region=Pr[1]}R(e.port)&&(e.port=443),R(e.websocketOptions)?e.websocketOptions={protocol:"mqttv3.1"}:e.websocketOptions.protocol="mqttv3.1",e.protocol==="wss-custom-auth"&&(e.websocketOptions.headers=e.customAuthHeaders)}!R(e)&&e.debug===!0&&(console.log(e),console.log("attempting new mqtt connection..."));var Qi={};Qi.mqtts=ru(),Qi.wss=Nc();function Yc(){var T=process.env.HOME||process.env.USERPROFILE||(process.env.HOMEPATH?(process.env.HOMEDRIVE||"C:/")+process.env.HOMEPATH:null);return om.join(T,".aws","credentials")}function Qc(T,O){var U=a.filter(function(ce){return ce.topic===T});U.length===0&&a.push({topic:T,options:O})}function Jc(T,O){var U=a.filter(function(ce){return ce.topic!==T});a=U}function Ji(T,O,U){var ce=null;l!==!1&&(T==="subscribe"?ce=Qc:T==="unsubscribe"&&(ce=Jc),Object.prototype.toString.call(O)==="[object Array]"?O.forEach(function(rh,Im,Om){ce(rh,U)}):ce(O,U))}function Br(){return h==="inactive"}function Xc(T){var O=e.protocol;if(O==="wss"){var U;x===""||C===""?U="wss://no-credentials-available":U=Lc(e,x,C,w),e.debug===!0&&console.log("using websockets, will connect to '"+U+"'..."),e.url=U}else O==="wss-custom-auth"&&(e.url=qc(e),e.debug===!0&&console.log("using websockets custom auth, will connect to '"+e.url+"'..."),O="wss");return Qi[O](T,e)}var D=new nm.MqttClient(Xc,e);function Zc(){g=v,D.options.reconnectPeriod=g,S=null,h="stable"}function eh(){var T=!0;return n>0&&r.length>=n&&(s==="oldest"?r.shift():T=!1),T}function th(){var T=u.shift();if(!R(T))R(T.callback)?D.subscribe(T.topic,T.options):D.subscribe(T.topic,T.options,T.callback);else{var O=o.shift();if(!R(O))Ji(O.type,O.topics,O.options),O.type==="subscribe"?R(O.callback)?D.subscribe(O.topics,O.options):D.subscribe(O.topics,O.options,O.callback):O.type==="unsubscribe"&&D.unsubscribe(O.topics,O.callback);else{var U=r.shift();R(U)||D.publish(U.topic,U.message,U.options,U.callback),r.length===0&&(clearInterval(c),c=null)}}}D.on("connect",function(T){S===null&&(S=setTimeout(Zc,m)),h="established",c===null&&(u=a.slice(0),c=setInterval(th,d)),t.emit("connect",T)}),D.on("close",function(T){R(T)||t.emit("error",T),!R(e)&&e.debug===!0&&console.log("connection lost - will attempt reconnection in "+D.options.reconnectPeriod/1e3+" seconds..."),clearTimeout(S),S=null,clearInterval(c),c=null,h="inactive",t.emit("close")}),D.on("reconnect",function(){g=g*2,g=Math.min(p,g),D.options.reconnectPeriod=g,t.emit("reconnect")}),D.on("end",function(){t.emit("end")}),D.on("offline",function(){t.emit("offline")}),D.on("error",function(T){t.emit("error",T)}),D.on("packetsend",function(T){t.emit("packetsend",T)}),D.on("packetreceive",function(T){t.emit("packetreceive",T)}),D.on("message",function(T,O,U){t.emit("message",T,O,U)}),this.publish=function(T,O,U,ce){i===!0&&(Br()||c!==null)?eh()&&r.push({topic:T,message:O,options:U,callback:ce}):(i===!0||!Br())&&D.publish(T,O,U,ce)},this.subscribe=function(T,O,U){!Br()||l===!1?(Ji("subscribe",T,O),R(U)?D.subscribe(T,O):D.subscribe(T,O,U)):o.length<f?o.push({type:"subscribe",topics:T,options:O,callback:U}):t.emit("error",new Error("Maximum queued offline subscription reached"))},this.unsubscribe=function(T,O){!Br()||l===!1?(Ji("unsubscribe",T),D.unsubscribe(T,O)):o.length<f&&o.push({type:"unsubscribe",topics:T,options:e,callback:O})},this.end=function(T,O){D.end(T,O)},this.handleMessage=D.handleMessage.bind(D),D.handleMessage=function(T,O){t.handleMessage(T,O)},this.updateWebSocketCredentials=function(T,O,U,ce){x=T,C=O,w=U},this.getWebsocketHeaders=function(){return e.websocketOptions.headers},this.updateCustomAuthHeaders=function(T){e.websocketOptions.headers=T},this.simulateNetworkFailure=function(){D.stream.emit("error",new Error("simulated connection error")),D.stream.end()}}im(Tr,rm.EventEmitter);Ir.exports=Tr;Ir.exports.DeviceClient=Tr;Ir.exports.prepareWebSocketUrl=Lc;Ir.exports.prepareWebSocketCustomAuthUrl=qc});var Fc=b((R0,jc)=>{var Uc=require("events"),pm=require("util").inherits,_m=$i(),q=ur();function Dc(e,t,r){return q(r)?"$aws/things/"+e+"/shadow/"+t:"$aws/things/"+e+"/shadow/"+t+"/"+r}function gm(e,t){var r=!1;return e[0]==="$aws"&&e[1]==="things"&&e[3]==="shadow"&&(e[4]==="update"||e[4]==="get"||e[4]==="delete")&&(t==="subscribe"?(e[5]==="accepted"||e[5]==="rejected"||e[5]==="delta")&&e.length===6&&(r=!0):e.length===5&&(r=!0)),r}function Gi(e,t){if(!(this instanceof Gi))return new Gi(e,t);var r=this,i=[{}],n=0,s=1e4,o=!0,f=_m.DeviceClient(e);q(t)||q(t.operationTimeout)||(s=t.operationTimeout),this._handleSubscriptions=function(a,l,u,h){for(var c=[],d=0,_=l.length;d<_;d++)for(var v=0,m=l[d].operations.length;v<m;v++)for(var p=0,g=l[d].statii.length;p<g;p++)c.push(Dc(a,l[d].operations[v],l[d].statii[p]));i[a].debug===!0&&console.log(u+" on "+c);var S=[];S.push(c),u==="subscribe"?(S.push({qos:i[a].qos}),S.push(function(x,C){if(!q(h)){if(x){h(x);return}for(var w=[],B=0,M=C.length;B<M;B++)C[B].qos===128&&w.push(C[B]);if(w.length>0){h("Not all subscriptions were granted",w);return}h()}})):q(h)||S.push(h),f[u].apply(f,S)},this._handleMessages=function(a,l,u,h){var c={};try{c=JSON.parse(h.toString())}catch(v){e.debug===!0&&console.error("failed parsing JSON '"+h.toString()+"', "+v);return}var d=c.clientToken,_=c.version;if(delete c.clientToken,!q(_)&&u!=="rejected"){if(q(i[a].version)||_>=i[a].version)i[a].version=_;else if(l!=="delete"&&i[a].discardStale===!0){e.debug===!0&&console.warn("out-of-date version '"+_+"' on '"+a+"' (local version '"+i[a].version+"')");return}}if(u==="delta"){this.emit("delta",a,c);return}if(q(i[a].clientToken)||i[a].clientToken!==d){u==="accepted"&&l!=="get"&&this.emit("foreignStateChange",a,l,c);return}clearTimeout(i[a].timeout),delete i[a].timeout,delete i[a].clientToken,i[a].pending=!1,i[a].persistentSubscribe===!1&&this._handleSubscriptions(a,[{operations:[l],statii:["accepted","rejected"]}],"unsubscribe"),this.emit("status",a,u,d,c)},f.on("connect",function(){r.emit("connect")}),f.on("close",function(){r.emit("close")}),f.on("reconnect",function(){r.emit("reconnect")}),f.on("offline",function(){r.emit("offline")}),f.on("error",function(a){r.emit("error",a)}),f.on("packetsend",function(a){r.emit("packetsend",a)}),f.on("packetreceive",function(a){r.emit("packetreceive",a)}),f.on("message",function(a,l){if(o===!0){var u=a.split("/");gm(u,"subscribe")?i.hasOwnProperty(u[2])&&r._handleMessages(u[2],u[4],u[5],l):r.emit("message",a,l)}}),this._thingOperation=function(a,l,u){var h=null;if(i.hasOwnProperty(a))if(i[a].pending===!1){i[a].pending=!0;var c;if(q(u.clientToken)){var d=e.clientId.length;d>48?c=e.clientId.substr(d-48)+"-"+n++:c=e.clientId+"-"+n++}else c=u.clientToken;i[a].clientToken=c;var _=Dc(a,l);i[a].timeout=setTimeout(function(v,m){i[v].persistentSubscribe===!1&&r._handleSubscriptions(v,[{operations:[l],statii:["accepted","rejected"]}],"unsubscribe"),i[v].pending=!1,delete i[v].timeout,delete i[v].clientToken,r.emit("timeout",v,m)},s,a,c),i[a].persistentSubscribe===!1?this._handleSubscriptions(a,[{operations:[l],statii:["accepted","rejected"]}],"subscribe",function(v,m){if(!q(v)||!q(m)){console.warn("failed subscription to accepted/rejected topics");return}q(u)||(!q(i[a].version)&&i[a].enableVersioning&&(u.version=i[a].version),u.clientToken=c,f.publish(_,JSON.stringify(u),{qos:i[a].qos}),!q(i[a])&&i[a].debug===!0&&console.log("publishing '"+JSON.stringify(u)+" on '"+_+"'"))}):(!q(i[a].version)&&i[a].enableVersioning&&(u.version=i[a].version),u.clientToken=c,f.publish(_,JSON.stringify(u),{qos:i[a].qos}),i[a].debug===!0&&console.log("publishing '"+JSON.stringify(u)+" on '"+_+"'")),h=c}else e.debug===!0&&console.error(l+" still in progress on thing: ",a);else e.debug===!0&&console.error("attempting to "+l+" unknown thing: ",a);return h},this.register=function(a,l,u){if(i.hasOwnProperty(a))e.debug===!0&&console.error("thing already registered: ",a);else{var h=!1,c=[];i[a]={persistentSubscribe:!0,debug:!1,discardStale:!0,enableVersioning:!0,qos:0,pending:!0},typeof l=="function"&&(u=l,l=null),q(l)||(q(l.ignoreDeltas)||(h=l.ignoreDeltas),q(l.persistentSubscribe)||(i[a].persistentSubscribe=l.persistentSubscribe),q(l.debug)||(i[a].debug=l.debug),q(l.discardStale)||(i[a].discardStale=l.discardStale),q(l.enableVersioning)||(i[a].enableVersioning=l.enableVersioning),q(l.qos)||(i[a].qos=l.qos)),h===!1&&c.push({operations:["update"],statii:["delta"]}),i[a].persistentSubscribe===!0&&c.push({operations:["update","get","delete"],statii:["accepted","rejected"]}),c.length>0?this._handleSubscriptions(a,c,"subscribe",function(d,_){q(d)&&q(_)&&(i[a].pending=!1),q(u)||u(d,_)}):(i[a].pending=!1,q(u)||u())}},this.unregister=function(a){if(i.hasOwnProperty(a)){var l=[];l.push({operations:["update"],statii:["delta"]}),i[a].persistentSubscribe===!0&&l.push({operations:["update","get","delete"],statii:["accepted","rejected"]}),this._handleSubscriptions(a,l,"unsubscribe"),q(i[a].timeout)||clearTimeout(i[a].timeout),delete i[a]}else e.debug===!0&&console.error("attempting to unregister unknown thing: ",a)},this.update=function(a,l){var u=null;return q(l.version)?u=r._thingOperation(a,"update",l):console.error("message can't contain 'version' property"),u},this.get=function(a,l){var u={};return q(l)||(u.clientToken=l),r._thingOperation(a,"get",u)},this.delete=function(a,l){var u={};return q(l)||(u.clientToken=l),r._thingOperation(a,"delete",u)},this.publish=function(a,l,u,h){f.publish(a,l,u,h)},this.subscribe=function(a,l,u){var h=[];typeof a=="string"?h.push(a):typeof a=="object"&&a.length&&(h=a),f.subscribe(h,l,u)},this.unsubscribe=function(a,l){var u=[];typeof a=="string"?u.push(a):typeof a=="object"&&a.length&&(u=a),f.unsubscribe(u,l)},this.end=function(a,l){f.end(a,l)},this.updateWebSocketCredentials=function(a,l,u,h){f.updateWebSocketCredentials(a,l,u,h)},this.updateCustomAuthHeaders=function(a){f.updateCustomAuthHeaders(a)},this.setConnectionStatus=function(a){o=a},Uc.EventEmitter.call(this)}pm(Gi,Uc.EventEmitter);jc.exports=Gi});var Vc=b((P0,Wc)=>{var bm=require("events"),ym=require("util").inherits,vm=$i(),F=ur();function mm(e){return e[0]==="$aws"&&e[1]==="things"&&e[3]==="jobs"}function qt(e,t,r){var i="$aws/things/"+e+"/jobs/";return F(r)?r=t:i+=t.toString()+"/",i+=r,i}function zi(e){if(!(this instanceof zi))return new zi(e);var t=this,r=[],i=vm.DeviceClient(e);this._updateJobStatus=function(n,s,o,f,a){typeof f=="function"&&(a=f,f=void 0),!F(e)&&e.debug===!0&&console.log("updateJobStatus:",{thingName:n,jobId:s.id,status:o,statusDetails:f}),i.publish(qt(n,s.id,"update"),JSON.stringify({status:o,statusDetails:f}),null,function(l){F(l)&&(s.status={status:o,statusDetails:f}),F(a)||a(l)})},this._buildJobObject=function(n,s){if(F(s)||F(s.jobId))return null;var o={};return o.id=s.jobId,o.document=s.jobDocument,o.operation=o.document.operation,o.status={status:s.status,statusDetails:s.statusDetails},o.inProgress=function(f,a){t._updateJobStatus(n,o,"IN_PROGRESS",f,a)},o.failed=function(f,a){t._updateJobStatus(n,o,"FAILED",f,a)},o.succeeded=function(f,a){t._updateJobStatus(n,o,"SUCCEEDED",f,a)},o},this._handleMessages=function(n,s){var o=n.split("/");if(!mm(o)){t.emit("message",n,s);return}var f=o[2],a=r.find(function(c){return c.thingName===f});if(!F(a)){var l={};try{l=JSON.parse(s.toString())}catch(c){e.debug===!0&&console.error("failed parsing JSON '"+s.toString()+"', "+c);return}if(!(F(l.execution)||F(l.execution.jobId)||F(l.execution.jobDocument))){var u=l.execution.jobDocument.operation,h=a.operations.find(function(c){return F(u)?F(c.operationName):u===c.operationName});F(h)&&(h=a.operations.find(function(c){return F(c.operationName)}),F(h))||h.callback(null,t._buildJobObject(f,l.execution))}}},this.subscribeToJobs=function(n,s,o){F(o)&&(o=s,s=null),!F(e)&&e.debug===!0&&console.log("subscribeToJobs:",{thingName:n,operationName:s});var f=r.find(function(l){return l.thingName===n});F(f)&&(f={thingName:n,operations:[]},r.push(f),i.subscribe([qt(n,"$next/get/accepted"),qt(n,"notify-next")],function(l,u){F(l)||o(l)}));var a=f.operations.find(function(l){return F(s)?F(l.operationName):s===l.operationName});F(a)?(a={operationName:s,callback:o},f.operations.push(a)):a.callback=o},this.unsubscribeFromJobs=function(n,s,o){F(o)&&(o=s,s=null),!F(e)&&e.debug===!0&&console.log("unsubscribeFromJobs:",{thingName:n,operationName:s});var f=r.findIndex(function(u){return u.thingName===n}),a=new Error("subscription not found for given thing");if(f<0){o(a);return}var l=r[f].operations.findIndex(function(u){return F(s)?F(u.operationName):s===u.operationName});if(l<0){o(a);return}if(r[f].operations.splice(l,1),r[f].operations.length===0){r.splice(f,1),i.unsubscribe([qt(n,"$next/get/accepted"),qt(n,"notify-next")],o);return}o()},this.startJobNotifications=function(n,s){!F(e)&&e.debug===!0&&console.log("startJobNotifications:",{thingName:n}),i.publish(qt(n,"$next","get"),"{}",s)},i.on("connect",function(){t.emit("connect")}),i.on("close",function(){t.emit("close")}),i.on("reconnect",function(){t.emit("reconnect")}),i.on("offline",function(){t.emit("offline")}),i.on("error",function(n){t.emit("error",n)}),i.on("message",t._handleMessages),this.publish=i.publish,this.subscribe=i.subscribe,this.unsubscribe=i.unsubscribe,this.end=i.end,this.handleMessage=i.handleMessage,this.updateWebSocketCredentials=i.updateWebSocketCredentials,this.simulateNetworkFailure=i.simulateNetworkFailure}ym(zi,bm.EventEmitter);Wc.exports=zi});var Hc=b((B0,Ki)=>{Ki.exports.device=$i();Ki.exports.thingShadow=Fc();Ki.exports.jobs=Vc()});var Tm={};fh(Tm,{handler:()=>Cm});module.exports=uh(Tm);var Gc=lh(Hc()),wm=["PATH","NODE_PATH","LD_LIBRARY_PATH","PWD","SHLVL"],Sm=Object.fromEntries(Object.entries(process.env).filter(([e])=>!wm.includes(e))),mo=e=>{let t=process.env.AWS_REGION,r=process.env.SLS_SERVICE,i=process.env.SLS_STAGE,n=`sls/${t}/${r}/${i}`;return e&&(n+=`/${e}`),n},Or={invocation:mo(`${process.env.SLS_FUNCTION}/invocation`),response:mo(`${process.env.SLS_FUNCTION}/response`),heartbeat:mo("_heartbeat")},vt=new Gc.default.device({protocol:"wss",host:process.env.SLS_IOT_ENDPOINT});vt.on("connect",()=>{console.log("Successfully connected to AWS IoT")});vt.on("close",(...e)=>{console.log("AWS IoT connection closed"),console.log(e)});vt.on("error",(...e)=>{console.error("AWS IoT connection error occurred"),console.error(e)});vt.subscribe(Or.response,{qos:1});vt.subscribe(Or.heartbeat,{qos:1});var $c=(e=1e3)=>new Promise(t=>{setTimeout(()=>t(),e)}),zc=async()=>await Promise.race([Kc(Or.heartbeat),$c(4e3)])?(await $c(2e3),await zc()):"Disconnected. Please run `serverless dev` to reconnect, or `serverless deploy` to deploy your code.",Em=async()=>{let{response:e,error:t}=await Kc(Or.response);if(t){console.error("Error occurred during lambda invocation on the local machine:");let r=new Error(t.message);throw r.stack=t.stack,r.name=t.name,r}return e},Kc=async e=>new Promise(t=>{vt.on("message",async(r,i)=>{r===e&&(i&&t(JSON.parse(i.toString())),t())})}),xm=async(e,t)=>new Promise((r,i)=>{vt.publish(e,t?JSON.stringify(t):"{}",{qos:1},n=>{n?(console.error(`Failed to publish message to AWS IoT: ${n.message}`),i(n)):(console.log("Message successfully published to AWS IoT topic:"),console.log(e),r(t))})}),Cm=async(e,t)=>{let{functionName:r,functionVersion:i,memoryLimitInMB:n,logGroupName:s,logStreamName:o,clientContext:f,identity:a,invokedFunctionArn:l,awsRequestId:u,callbackWaitsForEmptyEventLoop:h}=t;return await xm(Or.invocation,{event:e,environment:Sm,context:{functionName:r,functionVersion:i,memoryLimitInMB:n,logGroupName:s,logStreamName:o,clientContext:f,identity:a,invokedFunctionArn:l,awsRequestId:u,callbackWaitsForEmptyEventLoop:h}}),await Promise.race([Em(),zc()])};0&&(module.exports={handler});
/*! Bundled license information:
safe-buffer/index.js:
(*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
ws/lib/BufferUtil.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
ws/lib/Validation.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
ws/lib/ErrorCodes.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
ws/lib/Receiver.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
ws/lib/Sender.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
ws/lib/WebSocket.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
ws/lib/WebSocketServer.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
ws/index.js:
(*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*)
*/