From c60eef3b2e71c21ad82c7f886f45b00ef645bd36 Mon Sep 17 00:00:00 2001 From: Bryce Zuccaro Date: Fri, 14 Aug 2026 10:34:31 -0600 Subject: [PATCH] fix: use tsx test runner discovery and ignore build output --- .gitignore | 1 + com.bryce.llamawatch.sdPlugin/bin/package.json | 1 - com.bryce.llamawatch.sdPlugin/bin/plugin.js | 1 - package.json | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 com.bryce.llamawatch.sdPlugin/bin/package.json delete mode 100644 com.bryce.llamawatch.sdPlugin/bin/plugin.js diff --git a/.gitignore b/.gitignore index 7828a10..21aae6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ *.streamDeckPlugin .DS_Store +com.bryce.llamawatch.sdPlugin/bin/ diff --git a/com.bryce.llamawatch.sdPlugin/bin/package.json b/com.bryce.llamawatch.sdPlugin/bin/package.json deleted file mode 100644 index bb34440..0000000 --- a/com.bryce.llamawatch.sdPlugin/bin/package.json +++ /dev/null @@ -1 +0,0 @@ -{ "type": "module" } \ No newline at end of file diff --git a/com.bryce.llamawatch.sdPlugin/bin/plugin.js b/com.bryce.llamawatch.sdPlugin/bin/plugin.js deleted file mode 100644 index 9d1c470..0000000 --- a/com.bryce.llamawatch.sdPlugin/bin/plugin.js +++ /dev/null @@ -1 +0,0 @@ -import e from"events";import t from"https";import s from"http";import n from"net";import i from"tls";import r from"crypto";import o from"stream";import a from"url";import c from"zlib";import l from"buffer";import h from"util";import d,{existsSync as u,readFileSync as f}from"node:fs";import p,{join as m}from"node:path";import{cwd as _}from"node:process";import{randomUUID as g}from"node:crypto";class v{events=new Map;addListener(e,t){return this.add(e,t,e=>e.push({listener:t}))}disposableOn(e,t){return this.add(e,t,e=>e.push({listener:t})),function(e){let t=!1;const s=()=>{t||(e(),t=!0)};return{[Symbol.dispose]:s,dispose:s}}(()=>this.removeListener(e,t))}emit(e,...t){const s=this.events.get(e);if(void 0===s)return!1;for(let n=0;n{e.listener===t&&n++}),n}listeners(e){return Array.from(this.events.get(e)||[]).map(({listener:e})=>e)}off(e,t){const s=this.events.get(e)??[];for(let n=s.length-1;n>=0;n--)s[n].listener===t&&this.remove(e,s,n);return this}on(e,t){return this.add(e,t,e=>e.push({listener:t}))}once(e,t){return this.add(e,t,e=>e.push({listener:t,once:!0}))}prependListener(e,t){return this.add(e,t,e=>e.splice(0,0,{listener:t}))}prependOnceListener(e,t){return this.add(e,t,e=>e.splice(0,0,{listener:t,once:!0}))}removeAllListeners(e){const t=this.events.get(e)??[];for(;t.length>0;)this.remove(e,t,0);return this.events.delete(e),this}removeListener(e,t){return this.off(e,t)}add(e,t,s){let n=this.events.get(e);if(void 0===n&&(n=[],this.events.set(e,n)),s(n),"newListener"!==e){const s=[e,t];this.emit("newListener",...s)}return this}remove(e,t,s){const[{listener:n}]=t.splice(s,1);if("removeListener"!==e){const t=[e,n];this.emit("removeListener",...t)}}}function y(e){null==e||"object"!=typeof e||Object.isFrozen(e)||(Object.freeze(e),Object.values(e).forEach(y))}function b(e,t){return t.split(".").reduce((e,t)=>e&&e[t],e)}class w{#e;#t=new Map;#s;#n=new v;constructor(e,t){this.#e=e,this.#s=t}get language(){return this.#e}set language(e){this.#e!==e&&(this.#e=e,this.#n.emit("languageChange",e))}onLanguageChange(e){return this.#n.disposableOn("languageChange",e)}t(e,t=this.language){return this.translate(e,t)}translate(e,t=this.language){const s=new Set([t,t.replaceAll("_","-").split("-").at(0),"en"]);for(const t of s){const s=b(this.getTranslations(t),e);if(s)return s.toString()}return e}getTranslations(e){let t=this.#t.get(e);return void 0===t&&(t=this.#s(e),y(t),this.#t.set(e,t)),t}}class S{#i;#r;#o;constructor(e){e instanceof S?(this.#i=e.#i,this.#r=e.#r):Array.isArray(e)?(this.#i=()=>e.values(),this.#r=()=>e.length):e instanceof Map||e instanceof Set?(this.#i=()=>e.values(),this.#r=()=>e.size):(this.#i=e,this.#r=()=>{let e=0;for(const t of this)e++;return e})}get length(){return this.#r()}*[Symbol.iterator](){for(const e of this.#i())yield e}asIndexedPairs(){return new S(function*(){let e=0;for(const t of this)yield[e++,t]}.bind(this))}drop(e){if(isNaN(e)||e<0)throw new RangeError("limit must be 0, or a positive number");return new S(function*(){let t=0;for(const s of this)t++>=e&&(yield s)}.bind(this))}every(e){for(const t of this)if(!e(t))return!1;return!0}filter(e){return new S(function*(){for(const t of this)e(t)&&(yield t)}.bind(this))}find(e){for(const t of this)if(e(t))return t}findLast(e){let t;for(const s of this)e(s)&&(t=s);return t}flatMap(e){return new S(function*(){for(const t of this)for(const s of e(t))yield s}.bind(this))}forEach(e){for(const t of this)e(t)}includes(e){return this.some(t=>t===e)}map(e){return new S(function*(){for(const t of this)yield e(t)}.bind(this))}next(...e){this.#o??=this.#i();const t=this.#o.next(...e);return t.done&&(this.#o=void 0),t}reduce(e,t){if(0===this.length){if(void 0===t)throw new TypeError("Reduce of empty enumerable with no initial value.");return t}let s=t;for(const t of this)s=void 0===s?t:e(s,t);return s}return(e){return this.#o=void 0,{done:!0,value:e}}some(e){for(const t of this)if(e(t))return!0;return!1}take(e){if(isNaN(e)||e<0)throw new RangeError("limit must be 0, or a positive number");return new S(function*(){let t=0;for(const s of this)t++{e=s,t=n}),resolve:e,reject:t}}function k(e,t,s){function n(s,n){var i;Object.defineProperty(s,"_zod",{value:s._zod??{},enumerable:!1}),(i=s._zod).traits??(i.traits=new Set),s._zod.traits.add(e),t(s,n);for(const e in o.prototype)e in s||Object.defineProperty(s,e,{value:o.prototype[e].bind(s)});s._zod.constr=o,s._zod.def=n}const i=s?.Parent??Object;class r extends i{}function o(e){var t;const i=s?.Parent?new r:this;n(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(r,"name",{value:e}),Object.defineProperty(o,"init",{value:n}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>!!(s?.Parent&&t instanceof s.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}class O extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const T={};function P(e){return T}function D(e,t){return"bigint"==typeof t?t.toString():t}function C(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function I(e){const t=e.startsWith("^")?1:0,s=e.endsWith("$")?e.length-1:e.length;return e.slice(t,s)}function N(e,t,s){Object.defineProperty(e,t,{get(){{const n=s();return e[t]=n,n}},set(s){Object.defineProperty(e,t,{value:s})},configurable:!0})}function L(e){return JSON.stringify(e)}const R=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function U(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const B=C(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function z(e,t=0){for(let s=t;s{var s;return(s=t).path??(s.path=[]),t.path.unshift(e),t})}function A(e){return"string"==typeof e?e:e?.message}function M(e,t,s){const n={...e,path:e.path??[]};if(!e.message){const i=A(e.inst?._zod.def?.error?.(e))??A(t?.error?.(e))??A(s.customError?.(e))??A(s.localeError?.(e))??"Invalid input";n.message=i}return delete n.inst,delete n.continue,t?.reportInput||delete n.input,n}const j=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),Object.defineProperty(e,"message",{get:()=>JSON.stringify(t,D,2),enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},F=k("$ZodError",j),W=k("$ZodError",j,{Parent:Error}),G=(e=>(t,s,n,i)=>{const r=n?Object.assign(n,{async:!1}):{async:!1},o=t._zod.run({value:s,issues:[]},r);if(o instanceof Promise)throw new O;if(o.issues.length){const t=new(i?.Err??e)(o.issues.map(e=>M(e,r,P())));throw R(t,i?.callee),t}return o.value})(W),V=(e=>async(t,s,n,i)=>{const r=n?Object.assign(n,{async:!0}):{async:!0};let o=t._zod.run({value:s,issues:[]},r);if(o instanceof Promise&&(o=await o),o.issues.length){const t=new(i?.Err??e)(o.issues.map(e=>M(e,r,P())));throw R(t,i?.callee),t}return o.value})(W),q=(e=>(t,s,n)=>{const i=n?{...n,async:!1}:{async:!1},r=t._zod.run({value:s,issues:[]},i);if(r instanceof Promise)throw new O;return r.issues.length?{success:!1,error:new(e??F)(r.issues.map(e=>M(e,i,P())))}:{success:!0,data:r.value}})(W),Z=(e=>async(t,s,n)=>{const i=n?Object.assign(n,{async:!0}):{async:!0};let r=t._zod.run({value:s,issues:[]},i);return r instanceof Promise&&(r=await r),r.issues.length?{success:!1,error:new e(r.issues.map(e=>M(e,i,P())))}:{success:!0,data:r.value}})(W),K=/^-?\d+(?:\.\d+)?/i,H=/true|false/i;class J{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),s=Math.min(...t.map(e=>e.length-e.trimStart().length)),n=t.map(e=>e.slice(s)).map(e=>" ".repeat(2*this.indent)+e);for(const e of n)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Y={major:4,minor:0,patch:0},X=k("$ZodType",(e,t)=>{var s;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Y;const n=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&n.unshift(e);for(const t of n)for(const s of t._zod.onattach)s(e);if(0===n.length)(s=e._zod).deferred??(s.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,s)=>{let n,i=z(e);for(const r of t){if(r._zod.def.when){if(!r._zod.def.when(e))continue}else if(i)continue;const t=e.issues.length,o=r._zod.check(e);if(o instanceof Promise&&!1===s?.async)throw new O;if(n||o instanceof Promise)n=(n??Promise.resolve()).then(async()=>{await o;e.issues.length!==t&&(i||(i=z(e,t)))});else{if(e.issues.length===t)continue;i||(i=z(e,t))}}return n?n.then(()=>e):e};e._zod.run=(s,i)=>{const r=e._zod.parse(s,i);if(r instanceof Promise){if(!1===i.async)throw new O;return r.then(e=>t(e,n,i))}return t(r,n,i)}}e["~standard"]={validate:t=>{try{const s=q(e,t);return s.success?{value:s.data}:{issues:s.error?.issues}}catch(s){return Z(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}}),Q=k("$ZodString",(e,t)=>{var s;X.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(s=e._zod.bag,new RegExp(`^${s?`[\\s\\S]{${s?.minimum??0},${s?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(s,n)=>{if(t.coerce)try{s.value=String(s.value)}catch(n){}return"string"==typeof s.value||s.issues.push({expected:"string",code:"invalid_type",input:s.value,inst:e}),s}}),ee=k("$ZodNumber",(e,t)=>{X.init(e,t),e._zod.pattern=e._zod.bag.pattern??K,e._zod.parse=(s,n)=>{if(t.coerce)try{s.value=Number(s.value)}catch(e){}const i=s.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return s;const r="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return s.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...r?{received:r}:{}}),s}}),te=k("$ZodBoolean",(e,t)=>{X.init(e,t),e._zod.pattern=H,e._zod.parse=(s,n)=>{if(t.coerce)try{s.value=Boolean(s.value)}catch(e){}const i=s.value;return"boolean"==typeof i||s.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),s}});function se(e,t,s){e.issues.length&&t.issues.push(...$(s,e.issues)),t.value[s]=e.value}const ne=k("$ZodArray",(e,t)=>{X.init(e,t),e._zod.parse=(s,n)=>{const i=s.value;if(!Array.isArray(i))return s.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),s;s.value=Array(i.length);const r=[];for(let e=0;ese(t,s,e))):se(a,s,e)}return r.length?Promise.all(r).then(()=>s):s}});function ie(e,t,s){e.issues.length&&t.issues.push(...$(s,e.issues)),t.value[s]=e.value}function re(e,t,s,n){e.issues.length?void 0===n[s]?t.value[s]=s in n?void 0:e.value:t.issues.push(...$(s,e.issues)):void 0===e.value?s in n&&(t.value[s]=void 0):t.value[s]=e.value}const oe=k("$ZodObject",(e,t)=>{X.init(e,t);const s=C(()=>{const e=Object.keys(t.shape);for(const s of e)if(!(t.shape[s]instanceof X))throw new Error(`Invalid element at key "${s}": expected a Zod schema`);const s=(n=t.shape,Object.keys(n).filter(e=>"optional"===n[e]._zod.optin&&"optional"===n[e]._zod.optout));var n;return{shape:t.shape,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(s)}});N(e._zod,"propValues",()=>{const e=t.shape,s={};for(const t in e){const n=e[t]._zod;if(n.values){s[t]??(s[t]=new Set);for(const e of n.values)s[t].add(e)}}return s});let n;const i=U,r=!T.jitless,o=r&&B.value,a=t.catchall;let c;e._zod.parse=(l,h)=>{c??(c=s.value);const d=l.value;if(!i(d))return l.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),l;const u=[];if(r&&o&&!1===h?.async&&!0!==h.jitless)n||(n=(e=>{const t=new J(["shape","payload","ctx"]),n=s.value,i=e=>{const t=L(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const r=Object.create(null);let o=0;for(const e of n.keys)r[e]="key_"+o++;t.write("const newResult = {}");for(const e of n.keys)if(n.optionalKeys.has(e)){const s=r[e];t.write(`const ${s} = ${i(e)};`);const n=L(e);t.write(`\n if (${s}.issues.length) {\n if (input[${n}] === undefined) {\n if (${n} in input) {\n newResult[${n}] = undefined;\n }\n } else {\n payload.issues = payload.issues.concat(\n ${s}.issues.map((iss) => ({\n ...iss,\n path: iss.path ? [${n}, ...iss.path] : [${n}],\n }))\n );\n }\n } else if (${s}.value === undefined) {\n if (${n} in input) newResult[${n}] = undefined;\n } else {\n newResult[${n}] = ${s}.value;\n }\n `)}else{const s=r[e];t.write(`const ${s} = ${i(e)};`),t.write(`\n if (${s}.issues.length) payload.issues = payload.issues.concat(${s}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${L(e)}, ...iss.path] : [${L(e)}]\n })));`),t.write(`newResult[${L(e)}] = ${s}.value`)}t.write("payload.value = newResult;"),t.write("return payload;");const a=t.compile();return(t,s)=>a(e,t,s)})(t.shape)),l=n(l,h);else{l.value={};const e=c.shape;for(const t of c.keys){const s=e[t],n=s._zod.run({value:d[t],issues:[]},h),i="optional"===s._zod.optin&&"optional"===s._zod.optout;n instanceof Promise?u.push(n.then(e=>i?re(e,l,t,d):ie(e,l,t))):i?re(n,l,t,d):ie(n,l,t)}}if(!a)return u.length?Promise.all(u).then(()=>l):l;const f=[],p=c.keySet,m=a._zod,_=m.def.type;for(const e of Object.keys(d)){if(p.has(e))continue;if("never"===_){f.push(e);continue}const t=m.run({value:d[e],issues:[]},h);t instanceof Promise?u.push(t.then(t=>ie(t,l,e))):ie(t,l,e)}return f.length&&l.issues.push({code:"unrecognized_keys",keys:f,input:d,inst:e}),u.length?Promise.all(u).then(()=>l):l}});function ae(e,t,s,n){for(const s of e)if(0===s.issues.length)return t.value=s.value,t;return t.issues.push({code:"invalid_union",input:t.value,inst:s,errors:e.map(e=>e.issues.map(e=>M(e,n,P())))}),t}const ce=k("$ZodUnion",(e,t)=>{X.init(e,t),N(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),N(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),N(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),N(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>I(e.source)).join("|")})$`)}}),e._zod.parse=(s,n)=>{let i=!1;const r=[];for(const e of t.options){const t=e._zod.run({value:s.value,issues:[]},n);if(t instanceof Promise)r.push(t),i=!0;else{if(0===t.issues.length)return t;r.push(t)}}return i?Promise.all(r).then(t=>ae(t,s,e,n)):ae(r,s,e,n)}}),le=k("$ZodLiteral",(e,t)=>{X.init(e,t),e._zod.values=new Set(t.values),e._zod.pattern=new RegExp(`^(${t.values.map(e=>"string"==typeof e?e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):e?e.toString():String(e)).join("|")})$`),e._zod.parse=(s,n)=>{const i=s.value;return e._zod.values.has(i)||s.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),s}}),he=k("$ZodOptional",(e,t)=>{X.init(e,t),e._zod.optin="optional",e._zod.optout="optional",N(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),N(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${I(e.source)})?$`):void 0}),e._zod.parse=(e,s)=>"optional"===t.innerType._zod.optin?t.innerType._zod.run(e,s):void 0===e.value?e:t.innerType._zod.run(e,s)}),de=k("$ZodLazy",(e,t)=>{X.init(e,t),N(e._zod,"innerType",()=>t.getter()),N(e._zod,"pattern",()=>e._zod.innerType._zod.pattern),N(e._zod,"propValues",()=>e._zod.innerType._zod.propValues),N(e._zod,"optin",()=>e._zod.innerType._zod.optin),N(e._zod,"optout",()=>e._zod.innerType._zod.optout),e._zod.parse=(t,s)=>e._zod.innerType._zod.run(t,s)});const ue=k("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");X.init(e,t),e.def=t,e.parse=(t,s)=>G(e,t,s,{callee:e.parse}),e.safeParse=(t,s)=>q(e,t,s),e.parseAsync=async(t,s)=>V(e,t,s,{callee:e.parseAsync}),e.safeParseAsync=async(t,s)=>Z(e,t,s),e.check=(...s)=>e.clone({...t,checks:[...t.checks??[],...s.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),e.clone=(t,s)=>function(e,t,s){const n=new e._zod.constr(t??e._zod.def);return t&&!s?.parent||(n._zod.parent=e),n}(e,t,s),e.brand=()=>e,e.register=(t,s)=>(t.add(e,s),e)}),fe=k("ZodMiniString",(e,t)=>{Q.init(e,t),ue.init(e,t)});function pe(e){return new fe({type:"string"})}const me=k("ZodMiniNumber",(e,t)=>{ee.init(e,t),ue.init(e,t)});const _e=k("ZodMiniBoolean",(e,t)=>{te.init(e,t),ue.init(e,t)});function ge(e){return new _e({type:"boolean"})}const ve=k("ZodMiniArray",(e,t)=>{ne.init(e,t),ue.init(e,t)});const ye=k("ZodMiniObject",(e,t)=>{oe.init(e,t),ue.init(e,t),N(e,"shape",()=>t.shape)});function be(e,t){return new ye({type:"object",get shape(){var t,s,n;return t=this,s="shape",n={...e},Object.defineProperty(t,s,{value:n,writable:!0,enumerable:!0,configurable:!0}),this.shape}})}const we=k("ZodMiniUnion",(e,t)=>{ce.init(e,t),ue.init(e,t)});function Se(e,t){return new we({type:"union",options:e})}const Ee=k("ZodMiniLiteral",(e,t)=>{le.init(e,t),ue.init(e,t)});function xe(e,t){return new Ee({type:"literal",values:Array.isArray(e)?e:[e]})}const ke=k("ZodMiniOptional",(e,t)=>{he.init(e,t),ue.init(e,t)});function Oe(e){return new ke({type:"optional",innerType:e})}const Te=k("ZodMiniLazy",(e,t)=>{de.init(e,t),ue.init(e,t)});const Pe=be({type:xe("option"),disabled:Oe(ge()),label:pe(),value:Se([ge(),new me({type:"number",checks:[]}),pe()])}),De=be({type:xe("option-group"),disabled:Oe(ge()),options:(Ce=()=>{return e=Se([Pe,De]),new ve({type:"array",element:e});var e},new Te({type:"lazy",getter:Ce})),label:pe()});var Ce;function Ie(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ne,Le,Re,Ue,Be,ze,$e,Ae={exports:{}};function Me(){if(Le)return Ne;Le=1;const e=["nodebuffer","arraybuffer","fragments"],t="undefined"!=typeof Blob;return t&&e.push("blob"),Ne={BINARY_TYPES:e,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:t,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}}function je(){if(Re)return Ae.exports;Re=1;const{EMPTY_BUFFER:e}=Me(),t=Buffer[Symbol.species];function s(e,t,s,n,i){for(let r=0;r{this.pending--,this[t]()},this.concurrency=s||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[t]()}[t](){if(this.pending!==this.concurrency&&this.jobs.length){const t=this.jobs.shift();this.pending++,t(this[e])}}}}(),{kStatusCode:n}=Me(),i=Buffer[Symbol.species],r=Buffer.from([0,0,255,255]),o=Symbol("permessage-deflate"),a=Symbol("total-length"),l=Symbol("callback"),h=Symbol("buffers"),d=Symbol("error");let u;function f(e){this[h].push(e),this[a]+=e.length}function p(e){this[a]+=e.length,this[o]._maxPayload<1||this[a]<=this[o]._maxPayload?this[h].push(e):(this[d]=new RangeError("Max payload size exceeded"),this[d].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[d][n]=1009,this.removeListener("data",p),this.reset())}function m(e){this[o]._inflate=null,this[d]?this[l](this[d]):(e[n]=1007,this[l](e))}return ze=class{constructor(e){if(this._options=e||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._maxPayload=0|this._options.maxPayload,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!u){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;u=new s(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:null==this._options.clientMaxWindowBits&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){const e=this._deflate[l];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){const t=this._options,s=e.find(e=>!(!1===t.serverNoContextTakeover&&e.server_no_context_takeover||e.server_max_window_bits&&(!1===t.serverMaxWindowBits||"number"==typeof t.serverMaxWindowBits&&t.serverMaxWindowBits>e.server_max_window_bits)||"number"==typeof t.clientMaxWindowBits&&("number"==typeof e.client_max_window_bits?t.clientMaxWindowBits>e.client_max_window_bits:!e.client_max_window_bits)));if(!s)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(s.server_no_context_takeover=!0),t.clientNoContextTakeover&&(s.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(s.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?s.client_max_window_bits=t.clientMaxWindowBits:!0!==s.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete s.client_max_window_bits,s}acceptAsClient(e){const t=e[0];if(!1===this._options.clientNoContextTakeover&&t.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(t.client_max_window_bits){if(!1===this._options.clientMaxWindowBits||"number"==typeof this._options.clientMaxWindowBits&&t.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}else"number"==typeof this._options.clientMaxWindowBits&&(t.client_max_window_bits=this._options.clientMaxWindowBits);return t}normalizeParams(e){return e.forEach(e=>{Object.keys(e).forEach(t=>{let s=e[t];if(s.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(s=s[0],"client_max_window_bits"===t){if(!0!==s){const e=+s;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${s}`);s=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}else if("server_max_window_bits"===t){const e=+s;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${s}`);s=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==s)throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}e[t]=s})}),e}decompress(e,t,s){u.add(n=>{this._decompress(e,t,(e,t)=>{n(),s(e,t)})})}compress(e,t,s){u.add(n=>{this._compress(e,t,(e,t)=>{n(),s(e,t)})})}_decompress(s,n,i){const c=this._isServer?"client":"server";if(!this._inflate){const t=`${c}_max_window_bits`,s="number"!=typeof this.params[t]?e.Z_DEFAULT_WINDOWBITS:this.params[t];this._inflate=e.createInflateRaw({...this._options.zlibInflateOptions,windowBits:s}),this._inflate[o]=this,this._inflate[a]=0,this._inflate[h]=[],this._inflate.on("error",m),this._inflate.on("data",p)}this._inflate[l]=i,this._inflate.write(s),n&&this._inflate.write(r),this._inflate.flush(()=>{const e=this._inflate[d];if(e)return this._inflate.close(),this._inflate=null,void i(e);const s=t.concat(this._inflate[h],this._inflate[a]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[a]=0,this._inflate[h]=[],n&&this.params[`${c}_no_context_takeover`]&&this._inflate.reset()),i(null,s)})}_compress(s,n,r){const o=this._isServer?"server":"client";if(!this._deflate){const t=`${o}_max_window_bits`,s="number"!=typeof this.params[t]?e.Z_DEFAULT_WINDOWBITS:this.params[t];this._deflate=e.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:s}),this._deflate[a]=0,this._deflate[h]=[],this._deflate.on("data",f)}this._deflate[l]=r,this._deflate.write(s),this._deflate.flush(e.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let e=t.concat(this._deflate[h],this._deflate[a]);n&&(e=new i(e.buffer,e.byteOffset,e.length-4)),this._deflate[l]=null,this._deflate[a]=0,this._deflate[h]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),r(null,e)})}}}var We,Ge,Ve,qe,Ze,Ke,He,Je,Ye,Xe,Qe,et,tt,st,nt,it={exports:{}};function rt(){if(We)return it.exports;We=1;const{isUtf8:e}=l,{hasBlob:t}=Me();function s(e){const t=e.length;let s=0;for(;s=t||128!=(192&e[s+1])||128!=(192&e[s+2])||224===e[s]&&128==(224&e[s+1])||237===e[s]&&160==(224&e[s+1]))return!1;s+=3}else{if(240!=(248&e[s]))return!1;if(s+3>=t||128!=(192&e[s+1])||128!=(192&e[s+2])||128!=(192&e[s+3])||240===e[s]&&128==(240&e[s+1])||244===e[s]&&e[s+1]>143||e[s]>244)return!1;s+=4}else s++;return!0}if(it.exports={isBlob:function(e){return t&&"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&("Blob"===e[Symbol.toStringTag]||"File"===e[Symbol.toStringTag])},isValidStatusCode:function(e){return e>=1e3&&e<=1014&&1004!==e&&1005!==e&&1006!==e||e>=3e3&&e<=4999},isValidUTF8:s,tokenChars:[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]},e)it.exports.isValidUTF8=function(t){return t.length<24?s(t):e(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const e=require("utf-8-validate");it.exports.isValidUTF8=function(t){return t.length<32?s(t):e(t)}}catch(e){}return it.exports}function ot(){if(Ve)return Ge;Ve=1;const{Writable:e}=o,t=Fe(),{BINARY_TYPES:s,EMPTY_BUFFER:n,kStatusCode:i,kWebSocket:r}=Me(),{concat:a,toArrayBuffer:c,unmask:l}=je(),{isValidStatusCode:h,isValidUTF8:d}=rt(),u=Buffer[Symbol.species];return Ge=class extends e{constructor(e={}){super(),this._allowSynchronousEvents=void 0===e.allowSynchronousEvents||e.allowSynchronousEvents,this._binaryType=e.binaryType||s[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=0|e.maxBufferedChunks,this._maxFragments=0|e.maxFragments,this._maxPayload=0|e.maxPayload,this._skipUTF8Validation=!!e.skipUTF8Validation,this[r]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._numFragments=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=0}_write(e,t,s){if(8===this._opcode&&0==this._state)return s();this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks?s(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS")):(this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(s))}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e=s.length?t.set(this._buffers.shift(),n):(t.set(new Uint8Array(s.buffer,s.byteOffset,e),n),this._buffers[0]=new u(s.buffer,s.byteOffset+e,s.length-e)),e-=s.length}while(e>0);return t}startLoop(e){this._loop=!0;do{switch(this._state){case 0:this.getInfo(e);break;case 1:this.getPayloadLength16(e);break;case 2:this.getPayloadLength64(e);break;case 3:this.getMask();break;case 4:this.getData(e);break;case 5:case 6:return void(this._loop=!1)}}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2)return void(this._loop=!1);const s=this.consume(2);if(48&s[0]){return void e(this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3"))}const n=!(64&~s[0]);if(n&&!this._extensions[t.extensionName]){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(this._fin=!(128&~s[0]),this._opcode=15&s[0],this._payloadLength=127&s[1],0===this._opcode){if(n){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(!this._fragmented){return void e(this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE"))}this._opcode=this._fragmented}else if(1===this._opcode||2===this._opcode){if(this._fragmented){return void e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}this._compressed=n}else{if(!(this._opcode>7&&this._opcode<11)){return void e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}if(!this._fin){return void e(this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN"))}if(n){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(this._payloadLength>125||8===this._opcode&&1===this._payloadLength){return void e(this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"))}}if(this._fin||this._fragmented||(this._fragmented=this._opcode),this._masked=!(128&~s[1]),this._isServer){if(!this._masked){return void e(this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK"))}}else if(this._masked){return void e(this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK"))}126===this._payloadLength?this._state=1:127===this._payloadLength?this._state=2:this.haveLength(e)}getPayloadLength16(e){this._bufferedBytes<2?this._loop=!1:(this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e))}getPayloadLength64(e){if(this._bufferedBytes<8)return void(this._loop=!1);const t=this.consume(8),s=t.readUInt32BE(0);if(s>Math.pow(2,21)-1){return void e(this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"))}this._payloadLength=s*Math.pow(2,32)+t.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){return void e(this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"))}this._masked?this._state=3:this._state=4}getMask(){this._bufferedBytes<4?this._loop=!1:(this._mask=this.consume(4),this._state=4)}getData(e){let t=n;if(this._payloadLength){if(this._bufferedBytes7)this.controlMessage(t,e);else{if(this._maxFragments>0&&++this._numFragments>this._maxFragments){return void e(this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"))}if(this._compressed)return this._state=5,void this.decompress(t,e);t.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(t)),this.dataMessage(e)}}decompress(e,s){this._extensions[t.extensionName].decompress(e,this._fin,(e,t)=>{if(e)return s(e);if(t.length){if(this._messageLength+=t.length,this._messageLength>this._maxPayload&&this._maxPayload>0){const e=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");return void s(e)}this._fragments.push(t)}this.dataMessage(s),0===this._state&&this.startLoop(s)})}dataMessage(e){if(!this._fin)return void(this._state=0);const t=this._messageLength,s=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._numFragments=0,this._fragments=[],2===this._opcode){let n;n="nodebuffer"===this._binaryType?a(s,t):"arraybuffer"===this._binaryType?c(a(s,t)):"blob"===this._binaryType?new Blob(s):s,this._allowSynchronousEvents?(this.emit("message",n,!0),this._state=0):(this._state=6,setImmediate(()=>{this.emit("message",n,!0),this._state=0,this.startLoop(e)}))}else{const n=a(s,t);if(!this._skipUTF8Validation&&!d(n)){const t=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void e(t)}5===this._state||this._allowSynchronousEvents?(this.emit("message",n,!1),this._state=0):(this._state=6,setImmediate(()=>{this.emit("message",n,!1),this._state=0,this.startLoop(e)}))}}controlMessage(e,t){if(8!==this._opcode)this._allowSynchronousEvents?(this.emit(9===this._opcode?"ping":"pong",e),this._state=0):(this._state=6,setImmediate(()=>{this.emit(9===this._opcode?"ping":"pong",e),this._state=0,this.startLoop(t)}));else{if(0===e.length)this._loop=!1,this.emit("conclude",1005,n),this.end();else{const s=e.readUInt16BE(0);if(!h(s)){const e=this.createError(RangeError,`invalid status code ${s}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void t(e)}const n=new u(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!d(n)){const e=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void t(e)}this._loop=!1,this.emit("conclude",s,n),this.end()}this._state=0}}createError(e,t,s,n,r){this._loop=!1,this._errored=!0;const o=new e(s?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(o,this.createError),o.code=r,o[i]=n,o}}}function at(){if(Ze)return qe;Ze=1;const{Duplex:e}=o,{randomFillSync:t}=r,{types:{isUint8Array:s}}=h,n=Fe(),{EMPTY_BUFFER:i,kWebSocket:a,NOOP:c}=Me(),{isBlob:l,isValidStatusCode:d}=rt(),{mask:u,toBuffer:f}=je(),p=Symbol("kByteLength"),m=Buffer.alloc(4),_=8192;let g,v=_;class y{constructor(e,t,s){this._extensions=t||{},s&&(this._generateMask=s,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=0,this.onerror=c,this[a]=void 0}static frame(e,s){let n,i,r=!1,o=2,a=!1;s.mask&&(n=s.maskBuffer||m,s.generateMask?s.generateMask(n):(v===_&&(void 0===g&&(g=Buffer.alloc(_)),t(g,0,_),v=0),n[0]=g[v++],n[1]=g[v++],n[2]=g[v++],n[3]=g[v++]),a=0===(n[0]|n[1]|n[2]|n[3]),o=6),"string"==typeof e?i=s.mask&&!a||void 0===s[p]?(e=Buffer.from(e)).length:s[p]:(i=e.length,r=s.mask&&s.readOnly&&!a);let c=i;i>=65536?(o+=8,c=127):i>125&&(o+=2,c=126);const l=Buffer.allocUnsafe(r?i+o:o);return l[0]=s.fin?128|s.opcode:s.opcode,s.rsv1&&(l[0]|=64),l[1]=c,126===c?l.writeUInt16BE(i,2):127===c&&(l[2]=l[3]=0,l.writeUIntBE(i,4,6)),s.mask?(l[1]|=128,l[o-4]=n[0],l[o-3]=n[1],l[o-2]=n[2],l[o-1]=n[3],a?[l,e]:r?(u(e,n,l,o,i),[l]):(u(e,n,e,0,i),[l,e])):[l,e]}close(e,t,n,r){let o;if(void 0===e)o=i;else{if("number"!=typeof e||!d(e))throw new TypeError("First argument must be a valid error code number");if(void 0!==t&&t.length){const n=Buffer.byteLength(t);if(n>123)throw new RangeError("The message must not be greater than 123 bytes");if(o=Buffer.allocUnsafe(2+n),o.writeUInt16BE(e,0),"string"==typeof t)o.write(t,2);else{if(!s(t))throw new TypeError("Second argument must be a string or a Uint8Array");o.set(t,2)}}else o=Buffer.allocUnsafe(2),o.writeUInt16BE(e,0)}const a={[p]:o.length,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};0!==this._state?this.enqueue([this.dispatch,o,!1,a,r]):this.sendFrame(y.frame(o,a),r)}ping(e,t,s){let n,i;if("string"==typeof e?(n=Buffer.byteLength(e),i=!1):l(e)?(n=e.size,i=!1):(n=(e=f(e)).length,i=f.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");const r={[p]:n,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:9,readOnly:i,rsv1:!1};l(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,r,s]):this.getBlobData(e,!1,r,s):0!==this._state?this.enqueue([this.dispatch,e,!1,r,s]):this.sendFrame(y.frame(e,r),s)}pong(e,t,s){let n,i;if("string"==typeof e?(n=Buffer.byteLength(e),i=!1):l(e)?(n=e.size,i=!1):(n=(e=f(e)).length,i=f.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");const r={[p]:n,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:10,readOnly:i,rsv1:!1};l(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,r,s]):this.getBlobData(e,!1,r,s):0!==this._state?this.enqueue([this.dispatch,e,!1,r,s]):this.sendFrame(y.frame(e,r),s)}send(e,t,s){const i=this._extensions[n.extensionName];let r,o,a=t.binary?2:1,c=t.compress;"string"==typeof e?(r=Buffer.byteLength(e),o=!1):l(e)?(r=e.size,o=!1):(r=(e=f(e)).length,o=f.readOnly),this._firstFragment?(this._firstFragment=!1,c&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(c=r>=i._threshold),this._compress=c):(c=!1,a=0),t.fin&&(this._firstFragment=!0);const h={[p]:r,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:a,readOnly:o,rsv1:c};l(e)?0!==this._state?this.enqueue([this.getBlobData,e,this._compress,h,s]):this.getBlobData(e,this._compress,h,s):0!==this._state?this.enqueue([this.dispatch,e,this._compress,h,s]):this.dispatch(e,this._compress,h,s)}getBlobData(e,t,s,n){this._bufferedBytes+=s[p],this._state=2,e.arrayBuffer().then(e=>{if(this._socket.destroyed){const e=new Error("The socket was closed while the blob was being read");return void process.nextTick(b,this,e,n)}this._bufferedBytes-=s[p];const i=f(e);t?this.dispatch(i,t,s,n):(this._state=0,this.sendFrame(y.frame(i,s),n),this.dequeue())}).catch(e=>{process.nextTick(w,this,e,n)})}dispatch(e,t,s,i){if(!t)return void this.sendFrame(y.frame(e,s),i);const r=this._extensions[n.extensionName];this._bufferedBytes+=s[p],this._state=1,r.compress(e,s.fin,(e,t)=>{if(this._socket.destroyed){return void b(this,new Error("The socket was closed while data was being compressed"),i)}this._bufferedBytes-=s[p],this._state=0,s.readOnly=!1,this.sendFrame(y.frame(t,s),i),this.dequeue()})}dequeue(){for(;0===this._state&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[3][p],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][p],this._queue.push(e)}sendFrame(e,t){2===e.length?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],t),this._socket.uncork()):this._socket.write(e[0],t)}}function b(e,t,s){"function"==typeof s&&s(t);for(let s=0;s{let s=e[t];return Array.isArray(s)||(s=[s]),s.map(e=>[t].concat(Object.keys(e).map(t=>{let s=e[t];return Array.isArray(s)||(s=[s]),s.map(e=>!0===e?t:`${t}=${e}`).join("; ")})).join("; ")).join(", ")}).join(", ")},parse:function(s){const n=Object.create(null);let i,r,o=Object.create(null),a=!1,c=!1,l=!1,h=-1,d=-1,u=-1,f=0;for(;f0&&e.unshift(t),e.on("close",ne),e.on("data",ie),e.on("end",re),e.on("error",oe),this._readyState=M.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=M.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[v.extensionName]&&this._extensions[v.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=M.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState!==M.CLOSED){if(this.readyState===M.CONNECTING){const e="WebSocket was closed before the connection was established";return void V(this,this._req,e)}this.readyState!==M.CLOSING?(this._readyState=M.CLOSING,this._sender.close(e,t,!this._isServer,e=>{e||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),se(this)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end()}}pause(){this.readyState!==M.CONNECTING&&this.readyState!==M.CLOSED&&(this._paused=!0,this._socket.pause())}ping(e,t,s){if(this.readyState===M.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(s=e,e=t=void 0):"function"==typeof t&&(s=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===M.OPEN?(void 0===t&&(t=!this._isServer),this._sender.ping(e||x,t,s)):q(this,e,s)}pong(e,t,s){if(this.readyState===M.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(s=e,e=t=void 0):"function"==typeof t&&(s=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===M.OPEN?(void 0===t&&(t=!this._isServer),this._sender.pong(e||x,t,s)):q(this,e,s)}resume(){this.readyState!==M.CONNECTING&&this.readyState!==M.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,t,s){if(this.readyState===M.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof t&&(s=t,t={}),"number"==typeof e&&(e=e.toString()),this.readyState!==M.OPEN)return void q(this,e,s);const n={binary:"string"!=typeof e,mask:!this._isServer,compress:!0,fin:!0,...t};this._extensions[v.extensionName]||(n.compress=!1),this._sender.send(e||x,n,s)}terminate(){if(this.readyState!==M.CLOSED){if(this.readyState===M.CONNECTING){const e="WebSocket was closed before the connection was established";return void V(this,this._req,e)}this._socket&&(this._readyState=M.CLOSING,this._socket.destroy())}}}function j(e,t,s,n){const i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:E,protocolVersion:z[1],maxBufferedChunks:262144,maxFragments:16384,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...n,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(e._autoPong=i.autoPong,e._closeTimeout=i.closeTimeout,!z.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${z.join(", ")})`);let r;if(t instanceof g)r=t;else try{r=new g(t)}catch{throw new SyntaxError(`Invalid URL: ${t}`)}"http:"===r.protocol?r.protocol="ws:":"https:"===r.protocol&&(r.protocol="wss:"),e._url=r.href;const o="wss:"===r.protocol,a="ws+unix:"===r.protocol;let c;if("ws:"===r.protocol||o||a?a&&!r.pathname?c="The URL's pathname is empty":r.hash&&(c="The URL contains a fragment identifier"):c='The URL\'s protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"',c){const t=new SyntaxError(c);if(0===e._redirects)throw t;return void F(e,t)}const d=o?443:80,u=f(16).toString("base64"),m=o?l.request:h.request,_=new Set;let y,b;if(i.createConnection=i.createConnection||(o?G:W),i.defaultPort=i.defaultPort||d,i.port=r.port||d,i.host=r.hostname.startsWith("[")?r.hostname.slice(1,-1):r.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":u,Connection:"Upgrade",Upgrade:"websocket"},i.path=r.pathname+r.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(y=new v({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=L({[v.extensionName]:y.offer()})),s.length){for(const e of s){if("string"!=typeof e||!A.test(e)||_.has(e))throw new SyntaxError("An invalid or duplicated subprotocol was specified");_.add(e)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(r.username||r.password)&&(i.auth=`${r.username}:${r.password}`),a){const e=i.path.split(":");i.socketPath=e[0],i.path=e[1]}if(i.followRedirects){if(0===e._redirects){e._originalIpc=a,e._originalSecure=o,e._originalHostOrSocketPath=a?i.socketPath:r.host;const t=n&&n.headers;if(n={...n,headers:{}},t)for(const[e,s]of Object.entries(t))n.headers[e.toLowerCase()]=s}else if(0===e.listenerCount("redirect")){const t=a?!!e._originalIpc&&i.socketPath===e._originalHostOrSocketPath:!e._originalIpc&&r.host===e._originalHostOrSocketPath;(!t||e._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,t||delete i.headers.host,i.auth=void 0)}i.auth&&!n.headers.authorization&&(n.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),b=e._req=m(i),e._redirects&&e.emit("redirect",e.url,b)}else b=e._req=m(i);i.timeout&&b.on("timeout",()=>{V(e,b,"Opening handshake has timed out")}),b.on("error",t=>{null===b||b[B]||(b=e._req=null,F(e,t))}),b.on("response",r=>{const o=r.headers.location,a=r.statusCode;if(o&&i.followRedirects&&a>=300&&a<400){if(++e._redirects>i.maxRedirects)return void V(e,b,"Maximum redirects exceeded");let r;b.abort();try{r=new g(o,t)}catch(t){const s=new SyntaxError(`Invalid URL: ${o}`);return void F(e,s)}j(e,r,s,n)}else e.emit("unexpected-response",b,r)||V(e,b,`Unexpected server response: ${r.statusCode}`)}),b.on("upgrade",(t,s,n)=>{if(e.emit("upgrade",t),e.readyState!==M.CONNECTING)return;b=e._req=null;const r=t.headers.upgrade;if(void 0===r||"websocket"!==r.toLowerCase())return void V(e,s,"Invalid Upgrade header");const o=p("sha1").update(u+k).digest("base64");if(t.headers["sec-websocket-accept"]!==o)return void V(e,s,"Invalid Sec-WebSocket-Accept header");const a=t.headers["sec-websocket-protocol"];let c;if(void 0!==a?_.size?_.has(a)||(c="Server sent an invalid subprotocol"):c="Server sent a subprotocol but none was requested":_.size&&(c="Server sent no subprotocol"),c)return void V(e,s,c);a&&(e._protocol=a);const l=t.headers["sec-websocket-extensions"];if(void 0!==l){if(!y){return void V(e,s,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let t;try{t=R(l)}catch(t){return void V(e,s,"Invalid Sec-WebSocket-Extensions header")}const n=Object.keys(t);if(1!==n.length||n[0]!==v.extensionName){return void V(e,s,"Server indicated an extension that was not requested")}try{y.accept(t[v.extensionName])}catch(t){return void V(e,s,"Invalid Sec-WebSocket-Extensions header")}e._extensions[v.extensionName]=y}e.setSocket(s,n,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(b,e):b.end()}function F(e,t){e._readyState=M.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function W(e){return e.path=e.socketPath,d.connect(e)}function G(e){return e.path=void 0,e.servername||""===e.servername||(e.servername=d.isIP(e.host)?"":e.host),u.connect(e)}function V(e,t,s){e._readyState=M.CLOSING;const n=new Error(s);Error.captureStackTrace(n,V),t.setHeader?(t[B]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(F,e,n)):(t.destroy(n),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function q(e,t,s){if(t){const s=w(t)?t.size:U(t).length;e._socket?e._sender._bufferedBytes+=s:e._bufferedAmount+=s}if(s){const t=new Error(`WebSocket is not open: readyState ${e.readyState} (${$[e.readyState]})`);process.nextTick(s,t)}}function Z(e,t){const s=this[D];s._closeFrameReceived=!0,s._closeMessage=t,s._closeCode=e,void 0!==s._socket[D]&&(s._socket.removeListener("data",ie),process.nextTick(ee,s._socket),1005===e?s.close():s.close(e,t))}function K(){const e=this[D];e.isPaused||e._socket.resume()}function H(e){const t=this[D];void 0!==t._socket[D]&&(t._socket.removeListener("data",ie),process.nextTick(ee,t._socket),t.close(e[P])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function J(){this[D].emitClose()}function Y(e,t){this[D].emit("message",e,t)}function X(e){const t=this[D];t._autoPong&&t.pong(e,!this._isServer,C),t.emit("ping",e)}function Q(e){this[D].emit("pong",e)}function ee(e){e.resume()}function te(e){const t=this[D];t.readyState!==M.CLOSED&&(t.readyState===M.OPEN&&(t._readyState=M.CLOSING,se(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function se(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),e._closeTimeout)}function ne(){const e=this[D];if(this.removeListener("close",ne),this.removeListener("data",ie),this.removeListener("end",re),e._readyState=M.CLOSING,!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&0!==this._readableState.length){const t=this.read(this._readableState.length);e._receiver.write(t)}e._receiver.end(),this[D]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",J),e._receiver.on("finish",J))}function ie(e){this[D]._receiver.write(e)||this.pause()}function re(){const e=this[D];e._readyState=M.CLOSING,e._receiver.end(),this.end()}function oe(){const e=this[D];this.removeListener("error",oe),this.on("error",C),e&&(e._readyState=M.CLOSING,this.destroy())}return Object.defineProperty(M,"CONNECTING",{enumerable:!0,value:$.indexOf("CONNECTING")}),Object.defineProperty(M.prototype,"CONNECTING",{enumerable:!0,value:$.indexOf("CONNECTING")}),Object.defineProperty(M,"OPEN",{enumerable:!0,value:$.indexOf("OPEN")}),Object.defineProperty(M.prototype,"OPEN",{enumerable:!0,value:$.indexOf("OPEN")}),Object.defineProperty(M,"CLOSING",{enumerable:!0,value:$.indexOf("CLOSING")}),Object.defineProperty(M.prototype,"CLOSING",{enumerable:!0,value:$.indexOf("CLOSING")}),Object.defineProperty(M,"CLOSED",{enumerable:!0,value:$.indexOf("CLOSED")}),Object.defineProperty(M.prototype,"CLOSED",{enumerable:!0,value:$.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(e=>{Object.defineProperty(M.prototype,e,{enumerable:!0})}),["open","error","close","message"].forEach(e=>{Object.defineProperty(M.prototype,`on${e}`,{enumerable:!0,get(){for(const t of this.listeners(e))if(t[O])return t[T];return null},set(t){for(const t of this.listeners(e))if(t[O]){this.removeListener(e,t);break}"function"==typeof t&&this.addEventListener(e,t,{[O]:!0})}})}),M.prototype.addEventListener=I,M.prototype.removeEventListener=N,Xe=M}function ht(){if(nt)return st;nt=1;const{tokenChars:e}=rt();return st={parse:function(t){const s=new Set;let n=-1,i=-1,r=0;for(;r`${e}: ${i[e]}`).join("\r\n")+"\r\n\r\n"+s)}function y(e,t,s,n,i,r){if(e.listenerCount("wsClientError")){const n=new Error(i);Error.captureStackTrace(n,y),e.emit("wsClientError",n,s,t)}else v(s,n,i,r)}dt=class extends t{constructor(e,t){if(super(),null==(e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:262144,maxFragments:16384,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:u,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:d,...e}).port&&!e.server&&!e.noServer||null!=e.port&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(null!=e.port?(this._server=n.createServer((e,t)=>{const s=n.STATUS_CODES[426];t.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"}),t.end(s)}),this._server.listen(e.port,e.host,e.backlog,t)):e.server&&(this._server=e.server),this._server){const e=this.emit.bind(this,"connection");this._removeListeners=function(e,t){for(const s of Object.keys(t))e.on(s,t[s]);return function(){for(const s of Object.keys(t))e.removeListener(s,t[s])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,s,n)=>{this.handleUpgrade(t,s,n,e)}})}!0===e.perMessageDeflate&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=0}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(2===this._state)return e&&this.once("close",()=>{e(new Error("The server is not running"))}),void process.nextTick(_,this);if(e&&this.once("close",e),1!==this._state)if(this._state=1,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients&&this.clients.size?this._shouldEmitClose=!0:process.nextTick(_,this);else{const e=this._server;this._removeListeners(),this._removeListeners=this._server=null,e.close(()=>{_(this)})}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");if((-1!==t?e.url.slice(0,t):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,t,s,n){t.on("error",g);const i=e.headers["sec-websocket-key"],r=e.headers.upgrade,o=+e.headers["sec-websocket-version"];if("GET"!==e.method){return void y(this,e,t,405,"Invalid HTTP method")}if(void 0===r||"websocket"!==r.toLowerCase()){return void y(this,e,t,400,"Invalid Upgrade header")}if(void 0===i||!m.test(i)){return void y(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header")}if(13!==o&&8!==o){return void y(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"})}if(!this.shouldHandle(e))return void v(t,400);const a=e.headers["sec-websocket-protocol"];let d=new Set;if(void 0!==a)try{d=h.parse(a)}catch(s){return void y(this,e,t,400,"Invalid Sec-WebSocket-Protocol header")}const u=e.headers["sec-websocket-extensions"],f={};if(this.options.perMessageDeflate&&void 0!==u){const s=new l({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{const e=c.parse(u);e[l.extensionName]&&(s.accept(e[l.extensionName]),f[l.extensionName]=s)}catch(s){return void y(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const r={origin:e.headers[""+(8===o?"sec-websocket-origin":"origin")],secure:!(!e.socket.authorized&&!e.socket.encrypted),req:e};if(2===this.options.verifyClient.length)return void this.options.verifyClient(r,(r,o,a,c)=>{if(!r)return v(t,o||401,a,c);this.completeUpgrade(f,i,d,e,t,s,n)});if(!this.options.verifyClient(r))return v(t,401)}this.completeUpgrade(f,i,d,e,t,s,n)}completeUpgrade(e,t,s,n,i,r,o){if(!i.readable||!i.writable)return i.destroy();if(i[p])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return v(i,503);const h=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${a("sha1").update(t+f).digest("base64")}`],d=new this.options.WebSocket(null,void 0,this.options);if(s.size){const e=this.options.handleProtocols?this.options.handleProtocols(s,n):s.values().next().value;e&&(h.push(`Sec-WebSocket-Protocol: ${e}`),d._protocol=e)}if(e[l.extensionName]){const t=e[l.extensionName].params,s=c.format({[l.extensionName]:[t]});h.push(`Sec-WebSocket-Extensions: ${s}`),d._extensions=e}this.emit("headers",h,n),i.write(h.concat("\r\n").join("\r\n")),i.removeListener("error",g),d.setSocket(i,r,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(d),d.on("close",()=>{this.clients.delete(d),this._shouldEmitClose&&!this.clients.size&&process.nextTick(_,this)})),o(d,n)}}}(),function(e){e[e.StreamDeck=0]="StreamDeck",e[e.StreamDeckMini=1]="StreamDeckMini",e[e.StreamDeckXL=2]="StreamDeckXL",e[e.StreamDeckMobile=3]="StreamDeckMobile",e[e.CorsairGKeys=4]="CorsairGKeys",e[e.StreamDeckPedal=5]="StreamDeckPedal",e[e.CorsairVoyager=6]="CorsairVoyager",e[e.StreamDeckPlus=7]="StreamDeckPlus",e[e.SCUFController=8]="SCUFController",e[e.StreamDeckNeo=9]="StreamDeckNeo",e[e.StreamDeckStudio=10]="StreamDeckStudio",e[e.VirtualStreamDeck=11]="VirtualStreamDeck",e[e.Galleon100SD=12]="Galleon100SD",e[e.StreamDeckPlusXL=13]="StreamDeckPlusXL"}(ft||(ft={})),function(e){e[e.Rectangle=0]="Rectangle",e[e.DoubleRectangle=1]="DoubleRectangle",e[e.Trapezoid=2]="Trapezoid",e[e.DoubleTrapezoid=3]="DoubleTrapezoid",e[e.Groove=4]="Groove"}(pt||(pt={})),function(e){e.Port="-port",e.Info="-info",e.PluginUUID="-pluginUUID",e.RegisterEvent="-registerEvent"}(mt||(mt={})),function(e){e[e.HardwareAndSoftware=0]="HardwareAndSoftware",e[e.Hardware=1]="Hardware",e[e.Software=2]="Software"}(_t||(_t={}));class vt{build;major;minor;patch;constructor(e){const t=e.match(/^(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?$/);if(null===t)throw new Error(`Invalid format; expected "{major}[.{minor}[.{patch}[.{build}]]]" but was "${e}"`);[,this.major,this.minor,this.patch,this.build]=[...t.map(e=>parseInt(e)||0)]}compareTo(e){const t=({major:e,minor:t,build:s,patch:n})=>[e,t,s,n],s=t(this),n=t(e);for(let e=0;e<4;e++){if(s[e]n[e])return 1}return 0}toString(){return`${this.major}.${this.minor}`}}class yt{write(e){switch(e.level){case"error":console.error(...e.data);break;case"warn":console.warn(...e.data);break;default:console.log(...e.data)}}}const bt="\n";function wt(e){switch(e){case"error":return 0;case"warn":return 1;case"info":return 2;case"debug":return 3;default:return 4}}class St{#l;#h;#d;constructor(e){this.#h={minimumLevel:"trace",...e},this.#d=void 0===this.#h.scope||""===this.#h.scope.trim()?"":this.#h.scope,"function"!=typeof this.#h.level&&this.setLevel(this.#h.level)}get level(){return void 0!==this.#l?this.#l:"function"==typeof this.#h.level?this.#h.level():this.#h.level}createScope(e){return""===(e=e.trim())?this:new St({...this.#h,level:()=>this.level,scope:this.#h.scope?`${this.#h.scope}->${e}`:e})}debug(...e){return this.write({level:"debug",data:e,scope:this.#d})}error(...e){return this.write({level:"error",data:e,scope:this.#d})}info(...e){return this.write({level:"info",data:e,scope:this.#d})}setLevel(e){return void 0!==e&&wt(e)>wt(this.#h.minimumLevel)?this.#l="info":this.#l=e,this}trace(...e){return this.write({level:"trace",data:e,scope:this.#d})}warn(...e){return this.write({level:"warn",data:e,scope:this.#d})}write(e){return wt(e.level)<=wt(this.level)&&this.#h.targets.forEach(t=>t.write(e)),this}}let Et;function xt(){return void 0===Et&&(Et=process.execArgv.some(e=>{const t=e.split("=")[0];return"--inspect"===t||"--inspect-brk"===t||"--inspect-port"===t})),Et}const kt=[new class{#u;#h;#f=0;constructor(e){this.#h=e,this.#u=this.getLogFilePath(),this.reIndex()}write(e){const t=d.openSync(this.#u,"a");try{const s=this.#h.format(e);d.writeSync(t,s+"\n"),this.#f+=s.length}finally{d.closeSync(t)}this.#f>=this.#h.maxSize&&(this.reIndex(),this.#f=0)}getLogFilePath(e=0){return p.join(this.#h.dest,`${this.#h.fileName}.${e}.log`)}getLogFiles(){const e=/^\.(\d+)\.log$/;return d.readdirSync(this.#h.dest,{withFileTypes:!0}).reduce((t,s)=>{if(s.isDirectory()||s.name.indexOf(this.#h.fileName)<0)return t;const n=s.name.substring(this.#h.fileName.length).match(e);return 2!==n?.length||t.push({path:p.join(this.#h.dest,s.name),index:parseInt(n[1])}),t},[]).sort(({index:e},{index:t})=>et?1:0)}reIndex(){if(!d.existsSync(this.#h.dest))return void d.mkdirSync(this.#h.dest,{recursive:!0});const e=this.getLogFiles();for(let t=e.length-1;t>=0;t--){const s=e[t];t>=this.#h.maxFileCount-1?d.rmSync(s.path):d.renameSync(s.path,this.getLogFilePath(t+1))}}}({dest:p.join(_(),"logs"),fileName:function(){const e=p.basename(process.cwd()),t=e.lastIndexOf(".sdPlugin");return t<0?e:e.substring(0,t)}(),format:e=>{const{data:t,level:s,scope:n}=e;let i=`${(new Date).toISOString()} ${s.toUpperCase().padEnd(5)} `;return n&&(i+=`${n}: `),`${i}${function(e){let t="",s=!1;for(const n of e)"object"==typeof n&&n instanceof Error?(t+=`${bt}${n.stack}`,s=!0):(s&&(t+=bt,s=!1),t+="object"==typeof n?JSON.stringify(n):n,t+=" ");return t.trimEnd()}(t)}`},maxFileCount:10,maxSize:52428800})];xt()&&kt.splice(0,0,new yt);const Ot=new St({level:xt()?"debug":"info",minimumLevel:xt()?"trace":"debug",targets:kt});process.once("uncaughtException",e=>Ot.error("Process encountered uncaught exception",e));const Tt=new class extends v{_registrationParameters;_version;canConnect=!0;connection=x();logger=Ot.createScope("Connection");get registrationParameters(){return this._registrationParameters??=this.getRegistrationParameters()}get version(){return this._version??=new vt(this.registrationParameters.info.application.version)}async connect(){if(this.canConnect){this.canConnect=!1;const e=new gt(`ws://127.0.0.1:${this.registrationParameters.port}`);e.onmessage=e=>this.tryEmit(e),e.onopen=()=>{e.send(JSON.stringify({event:this.registrationParameters.registerEvent,uuid:this.registrationParameters.pluginUUID})),this.connection.resolve(e),this.emit("connected",this.registrationParameters.info)}}await this.connection.promise}async send(e){const t=await this.connection.promise,s=JSON.stringify(e);this.logger.trace(s),t.send(s)}getRegistrationParameters(){const e={port:void 0,info:void 0,pluginUUID:void 0,registerEvent:void 0},t=Ot.createScope("RegistrationParameters");for(let s=0;s{void 0===t&&s.push(e)};if(n(mt.Port,e.port),n(mt.PluginUUID,e.pluginUUID),n(mt.RegisterEvent,e.registerEvent),n(mt.Info,e.info),s.length>0)throw new Error(`Unable to establish a connection with Stream Deck, missing command line arguments: ${s.join(", ")}`);return e}tryEmit(e){try{const t=JSON.parse(e.data.toString());t.event?(this.logger.trace(e.data.toString()),this.emit(t.event,t)):this.logger.warn(`Received unknown message: ${e.data}`)}catch(t){this.logger.error(`Failed to parse message: ${e.data}`,t)}}};class Pt{type;constructor(e){this.type=e.event}}class Dt extends Pt{action;constructor(e,t){super(t),this.action=e}}class Ct extends Dt{payload;constructor(e,t){super(e,t),this.payload=t.payload}}const It=new E(()=>{const e=m(process.cwd(),"manifest.json");if(!u(e))throw new Error("Failed to read manifest.json as the file does not exist.");try{return JSON.parse(f(e,{encoding:"utf-8",flag:"r"}).toString())}catch(e){if(e instanceof SyntaxError)return null;throw e}}),Nt=new E(()=>null===It.value?null:new vt(It.value.Software.MinimumVersion));function Lt(){return Nt.value}const Rt={useExperimentalMessageIdentifiers:!1},Ut=new Map;class Bt extends S{constructor(){super(Ut)}getActionById(e){return Ut.get(e)}}const zt=new class extends Bt{delete(e){Ut.delete(e)}set(e){Ut.set(e.id,e)}};class $t extends Pt{application;constructor(e){super(e),this.application=e.payload.application}}class At extends Pt{device;constructor(e,t){super(e),this.device=t}}class Mt extends Pt{url;constructor(e){super(e),this.url=new Ft(e.payload.url)}}const jt="streamdeck://";class Ft{fragment;href;path;query;queryParameters;constructor(e){const t=new URL(`${jt}${e}`);this.fragment=t.hash.substring(1),this.href=t.href.substring(13),this.path=Ft.parsePath(this.href),this.query=t.search.substring(1),this.queryParameters=t.searchParams}static parsePath(e){const t=t=>{const s=e.indexOf(t);return s>=0?s:e.length};return e.substring(0,Math.min(t("?"),t("#")))}}class Wt extends Pt{settings;constructor(e){super(e),this.settings=e.payload.settings}}class Gt extends Pt{action;payload;constructor(e,t){super(t),this.action=e,this.payload=t.payload}}function Vt(e,t){const s=It.value?.SDKVersion??null;if(null!==s&&e>s)throw new Error(`[ERR_NOT_SUPPORTED]: ${t} requires manifest SDK version ${e} or higher, but found version ${s}; please update the "SDKVersion" in the plugin's manifest to ${e} or higher.`)}function qt(e,t,s){const n={major:Math.floor(e),minor:Number(e.toString().split(".").at(1)??0),patch:0,build:0};if(-1===t.compareTo(n))throw new Error(`[ERR_NOT_SUPPORTED]: ${s} requires Stream Deck version ${n.major}.${n.minor} or higher, but current version is ${t.major}.${t.minor}; please update Stream Deck and the "Software.MinimumVersion" in the plugin's manifest to "${n.major}.${n.minor}" or higher.`);const i=Lt();if(null!==i&&-1===i.compareTo(n))throw new Error(`[ERR_NOT_SUPPORTED]: ${s} requires Stream Deck version ${n.major}.${n.minor} or higher; please update the "Software.MinimumVersion" in the plugin's manifest to "${n.major}.${n.minor}" or higher.`)}const Zt={get useExperimentalMessageIdentifiers(){return Rt.useExperimentalMessageIdentifiers},set useExperimentalMessageIdentifiers(e){qt(7.1,Tt.version,"Message identifiers"),Rt.useExperimentalMessageIdentifiers=e},getGlobalSettings:()=>new Promise(e=>{Tt.once("didReceiveGlobalSettings",t=>e(t.payload.settings)),Tt.send({event:"getGlobalSettings",context:Tt.registrationParameters.pluginUUID,id:g()})}),onDidReceiveGlobalSettings:e=>Tt.disposableOn("didReceiveGlobalSettings",t=>{Zt.useExperimentalMessageIdentifiers&&t.id||e(new Wt(t))}),onDidReceiveSettings:e=>Tt.disposableOn("didReceiveSettings",t=>{if(Zt.useExperimentalMessageIdentifiers&&t.id)return;const s=zt.getActionById(t.context);s&&e(new Ct(s,t))}),setGlobalSettings:async e=>{await Tt.send({event:"setGlobalSettings",context:Tt.registrationParameters.pluginUUID,payload:e})}};const Kt=new class{#p;#m=0;constructor(){this.onDidAppear(e=>{this.#_(e.action)?this.#m++:(this.#m=1,this.#p=e.action)}),this.onDidDisappear(e=>{this.#_(e.action)&&(this.#m--,this.#m<=0&&(this.#p=void 0))})}get action(){return this.#p}onDidAppear(e){return Tt.disposableOn("propertyInspectorDidAppear",t=>{const s=zt.getActionById(t.context);s&&e(new Dt(s,t))})}onDidDisappear(e){return Tt.disposableOn("propertyInspectorDidDisappear",t=>{const s=zt.getActionById(t.context);s&&e(new Dt(s,t))})}onSendToPlugin(e){return Tt.disposableOn("sendToPlugin",t=>{const s=zt.getActionById(t.context);s&&e(new Gt(s,t))})}async sendToPropertyInspector(e){this.#p&&await Tt.send({event:"sendToPropertyInspector",context:this.#p.id,payload:e})}#_(e){return this.#p?.id===e.id&&this.#p?.manifestId===e.manifestId&&this.#p?.device?.id===e.device.id}};const Ht=new class{#g=new Map;delete(e){this.#g.delete(e)}get(e){const t=this.#g.get(e);return void 0!==t?structuredClone(t):void 0}set(e,t){this.#g.set(e,structuredClone(t))}},Jt=new Map;class Yt extends S{constructor(){super(Jt)}getDeviceById(e){return Jt.get(e)}}const Xt=new class extends Yt{set(e){Jt.set(e.id,e)}};class Qt{#v;#y;constructor(e){this.#y=e;const t=Xt.getDeviceById(e.device);if(!t)throw new Error(`Failed to initialize action; device ${e.device} not found`);this.#v=t}get controllerType(){return this.#y.payload.controller}get device(){return this.#v}get id(){return this.#y.context}get manifestId(){return this.#y.action}toJSON(){return{controllerType:this.controllerType,device:this.device,id:this.id,manifestId:this.manifestId}}}class es extends Qt{async getResources(){qt(7.1,Tt.version,"getResources");return(await this.#b("getResources","didReceiveResources")).payload.resources}async getSettings(){if(Rt.useExperimentalMessageIdentifiers){const e=Ht.get(this.id);if(void 0!==e)return Ot.trace(JSON.stringify({event:"getSettings",context:this.id,source:"cache",settings:e})),e}return(await this.#b("getSettings","didReceiveSettings")).payload.settings}isDial(){return"Encoder"===this.controllerType}isKey(){return"Keypad"===this.controllerType}setResources(e){return qt(7.1,Tt.version,"setResources"),Tt.send({event:"setResources",context:this.id,payload:e})}setSettings(e){return Ht.delete(this.id),Tt.send({event:"setSettings",context:this.id,payload:e})}showAlert(){return Tt.send({event:"showAlert",context:this.id})}async#b(e,t){const{resolve:s,reject:n,promise:i}=x(),r=setTimeout(()=>{o.dispose(),n("The request timed out")},15e3),o=Tt.disposableOn(t,e=>{e.context==this.id&&(clearTimeout(r),o.dispose(),s(e))});return await Tt.send({event:e,context:this.id,id:g()}),i}}class ts extends es{#w;constructor(e){if(super(e),"Encoder"!==e.payload.controller)throw new Error("Unable to create DialAction; source event is not a Encoder");this.#w=Object.freeze(e.payload.coordinates)}get coordinates(){return this.#w}setFeedback(e){return Tt.send({event:"setFeedback",context:this.id,payload:e})}setFeedbackLayout(e){return Tt.send({event:"setFeedbackLayout",context:this.id,payload:{layout:e}})}setImage(e){return Tt.send({event:"setImage",context:this.id,payload:{image:e}})}setTitle(e){return this.setFeedback({title:e})}setTriggerDescription(e){return Tt.send({event:"setTriggerDescription",context:this.id,payload:e||{}})}toJSON(){return{...super.toJSON(),coordinates:this.coordinates}}}class ss extends es{#w;#y;constructor(e){if(super(e),"Keypad"!==e.payload.controller)throw new Error("Unable to create KeyAction; source event is not a Keypad");this.#w=e.payload.isInMultiAction?void 0:Object.freeze(e.payload.coordinates),this.#y=e}get coordinates(){return this.#w}isInMultiAction(){return this.#y.payload.isInMultiAction}setImage(e,t){return Tt.send({event:"setImage",context:this.id,payload:{image:e,...t}})}setState(e){return Tt.send({event:"setState",context:this.id,payload:{state:e}})}setTitle(e,t){return Tt.send({event:"setTitle",context:this.id,payload:{title:e,...t}})}showOk(){return Tt.send({event:"showOk",context:this.id})}toJSON(){return{...super.toJSON(),coordinates:this.coordinates,isInMultiAction:this.isInMultiAction()}}}const ns=new E(()=>It.value);const is=new class extends Bt{constructor(){super(),Tt.prependListener("willAppear",e=>{const t="Encoder"===e.payload.controller?new ts(e):new ss(e);zt.set(t),Rt.useExperimentalMessageIdentifiers&&Ht.set(e.context,e.payload.settings)}),Tt.prependListener("didReceiveSettings",e=>{Rt.useExperimentalMessageIdentifiers&&Ht.set(e.context,e.payload.settings)}),Tt.prependListener("willDisappear",e=>{zt.delete(e.context),Ht.delete(e.context)})}onDialDown(e){return Tt.disposableOn("dialDown",t=>{const s=zt.getActionById(t.context);s?.isDial()&&e(new Ct(s,t))})}onDialRotate(e){return Tt.disposableOn("dialRotate",t=>{const s=zt.getActionById(t.context);s?.isDial()&&e(new Ct(s,t))})}onDialUp(e){return Tt.disposableOn("dialUp",t=>{const s=zt.getActionById(t.context);s?.isDial()&&e(new Ct(s,t))})}onDidReceiveResources(e){return Tt.disposableOn("didReceiveResources",t=>{if(void 0!==t.id)return;const s=zt.getActionById(t.context);s&&e(new Ct(s,t))})}onKeyDown(e){return Tt.disposableOn("keyDown",t=>{const s=zt.getActionById(t.context);s?.isKey()&&e(new Ct(s,t))})}onKeyUp(e){return Tt.disposableOn("keyUp",t=>{const s=zt.getActionById(t.context);s?.isKey()&&e(new Ct(s,t))})}onTitleParametersDidChange(e){return Tt.disposableOn("titleParametersDidChange",t=>{const s=zt.getActionById(t.context);s&&e(new Ct(s,t))})}onTouchTap(e){return Tt.disposableOn("touchTap",t=>{const s=zt.getActionById(t.context);s?.isDial()&&e(new Ct(s,t))})}onWillAppear(e){return Tt.disposableOn("willAppear",t=>{const s=zt.getActionById(t.context);s&&e(new Ct(s,t))})}onWillDisappear(e){return Tt.disposableOn("willDisappear",t=>e(new Ct(new Qt(t),t)))}registerAction(e){if(void 0===e.manifestId)throw new Error("The action's manifestId cannot be undefined.");if(null!==ns.value&&!ns.value.Actions.some(t=>t.UUID===e.manifestId))throw new Error(`The action's manifestId was not found within the manifest: ${e.manifestId}`);const{manifestId:t}=e,s=(s,n)=>{const i=n?.bind(e);void 0!==i&&s.bind(e)(async e=>{e.action.manifestId==t&&await i(e)})};s(this.onDialDown,e.onDialDown),s(this.onDialUp,e.onDialUp),s(this.onDialRotate,e.onDialRotate),s(Kt.onSendToPlugin,e.onSendToPlugin),s(this.onDidReceiveResources,e.onDidReceiveResources),s(Zt.onDidReceiveSettings,e.onDidReceiveSettings),s(this.onKeyDown,e.onKeyDown),s(this.onKeyUp,e.onKeyUp),s(Kt.onDidAppear,e.onPropertyInspectorDidAppear),s(Kt.onDidDisappear,e.onPropertyInspectorDidDisappear),s(this.onTitleParametersDidChange,e.onTitleParametersDidChange),s(this.onTouchTap,e.onTouchTap),s(this.onWillAppear,e.onWillAppear),s(this.onWillDisappear,e.onWillDisappear)}};class rs{#S=!1;#E;id;constructor(e,t,s){this.id=e,this.#E=t,this.#S=s,Tt.prependListener("deviceDidConnect",e=>{e.device===this.id&&(this.#E=e.deviceInfo,this.#S=!0)}),Tt.prependListener("deviceDidChange",e=>{e.device===this.id&&(this.#E=e.deviceInfo)}),Tt.prependListener("deviceDidDisconnect",e=>{e.device===this.id&&(this.#S=!1)})}get actions(){return zt.filter(e=>e.device.id===this.id)}get isConnected(){return this.#S}get name(){return this.#E.name}get size(){return this.#E.size}get type(){return this.#E.type}}const os=new class extends Yt{constructor(){super(),Tt.once("connected",e=>{e.devices.forEach(e=>Xt.set(new rs(e.id,e,!1)))}),Tt.on("deviceDidConnect",({device:e,deviceInfo:t})=>{Xt.getDeviceById(e)||Xt.set(new rs(e,t,!0))}),Tt.on("deviceDidChange",({device:e,deviceInfo:t})=>{Xt.getDeviceById(e)||Xt.set(new rs(e,t,!1))})}onDeviceDidChange(e){return qt(7,Tt.version,"onDeviceDidChange"),Tt.disposableOn("deviceDidChange",t=>e(new At(t,this.getDeviceById(t.device))))}onDeviceDidConnect(e){return Tt.disposableOn("deviceDidConnect",t=>e(new At(t,this.getDeviceById(t.device))))}onDeviceDidDisconnect(e){return Tt.disposableOn("deviceDidDisconnect",t=>e(new At(t,this.getDeviceById(t.device))))}};function as(e){const t=p.join(process.cwd(),`${e}.json`);if(!d.existsSync(t))return null;try{const e=d.readFileSync(t,{flag:"r"})?.toString();return function(e){const t=JSON.parse(e);if(null!=t&&"object"==typeof t&&"Localization"in t)return t.Localization;throw new TypeError('Translations must be a JSON object nested under a property named "Localization"')}(e)}catch(e){return Ot.error(`Failed to load translations from ${t}`,e),null}}var cs=Object.freeze({__proto__:null,switchToProfile:function(e,t,s){return void 0!==s&&qt(6.5,Tt.version,"Switching to a profile page"),Tt.send({event:"switchToProfile",context:Tt.registrationParameters.pluginUUID,device:e,payload:{page:s,profile:t}})}});var ls=Object.freeze({__proto__:null,getSecrets:function(){return qt(6.9,Tt.version,"Secrets"),Vt(3,"Secrets"),new Promise(e=>{Tt.once("didReceiveSecrets",t=>e(t.payload.secrets)),Tt.send({event:"getSecrets",context:Tt.registrationParameters.pluginUUID})})},onApplicationDidLaunch:function(e){return Tt.disposableOn("applicationDidLaunch",t=>e(new $t(t)))},onApplicationDidTerminate:function(e){return Tt.disposableOn("applicationDidTerminate",t=>e(new $t(t)))},onDidReceiveDeepLink:function(e){return qt(6.5,Tt.version,"Receiving deep-link messages"),Tt.disposableOn("didReceiveDeepLink",t=>e(new Mt(t)))},onSystemDidWakeUp:function(e){return Tt.disposableOn("systemDidWakeUp",t=>e(new Pt(t)))},openUrl:function(e){return Tt.send({event:"openUrl",payload:{url:e}})}});let hs;({get actions(){return is},get devices(){return os},get i18n(){return hs??=new w(this.info.application.language,as)},get info(){return Tt.registrationParameters.info},get logger(){return Ot},get profiles(){return cs},get settings(){return Zt},get system(){return ls},get ui(){return Kt},connect:()=>Tt.connect()}).connect(); diff --git a/package.json b/package.json index 79fd379..d78d09f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "rollup -c", "watch": "rollup -c -w --watch.onEnd=\"streamdeck restart com.bryce.llamawatch\"", - "test": "tsx --test tests/" + "test": "tsx --test" }, "devDependencies": { "@elgato/cli": "^1.8.1",