@onyxsecurity/mcp-gateway 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/mcp-gateway.js +5 -4
- package/dist/bin/mcp-gateway.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/{stdio-BRHpVFf0.js → stdio-DLhH1AFQ.js} +2 -2
- package/dist/stdio-DLhH1AFQ.js.map +1 -0
- package/package.json +1 -1
- package/dist/stdio-BRHpVFf0.js.map +0 -1
package/dist/bin/mcp-gateway.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{AccessControlBlockError as e,Client as t,ConfigurationError as n,ProcessSpawnError as r,ProxyConnectionError as i,ReadBuffer as a,SSEClientTransport as o,Server as s,StdioServerTransport as c,StreamableHTTPClientTransport as l,TransportError as u,__commonJSMin as d,__toESM as f,addBreadcrumbSafe as p,addGlobalTags as m,captureExceptionSafe as h,compressClientInfo as g,config as _,createParser as v,getSessionData as ee,initSentrySafe as y,initializeTrafficMirror as te,logger as b,proxyServer as ne,serializeMessage as x,startHTTPServer as S}from"../stdio-
|
|
2
|
+
import{AccessControlBlockError as e,Client as t,ConfigurationError as n,ProcessSpawnError as r,ProxyConnectionError as i,ReadBuffer as a,SSEClientTransport as o,Server as s,StdioServerTransport as c,StreamableHTTPClientTransport as l,TransportError as u,__commonJSMin as d,__toESM as f,addBreadcrumbSafe as p,addGlobalTags as m,captureExceptionSafe as h,compressClientInfo as g,config as _,createParser as v,getSessionData as ee,initSentrySafe as y,initializeTrafficMirror as te,logger as b,proxyServer as ne,serializeMessage as x,startHTTPServer as S}from"../stdio-DLhH1AFQ.js";import{createRequire as re}from"node:module";import{readFileSync as ie,readdirSync as ae}from"node:fs";import{basename as oe,dirname as se,extname as ce,join as le,normalize as ue,relative as de,resolve as fe}from"path";import{format as pe,inspect as me}from"util";import{fileURLToPath as he}from"url";import{setTimeout as C}from"node:timers";import ge from"node:util";import{notStrictEqual as _e,strictEqual as ve}from"assert";import{readFileSync as ye,readdirSync as be,statSync as xe,writeFile as Se}from"fs";import{spawn as Ce}from"node:child_process";import{PassThrough as we,Transform as Te}from"node:stream";var Ee=class extends Event{constructor(e,t){super(e),this.code=t?.code??void 0,this.message=t?.message??void 0}[Symbol.for(`nodejs.util.inspect.custom`)](e,t,n){return n(ke(this),t)}[Symbol.for(`Deno.customInspect`)](e,t){return e(ke(this),t)}};function De(e){let t=globalThis.DOMException;return typeof t==`function`?new t(e,`SyntaxError`):SyntaxError(e)}function Oe(e){return e instanceof Error?`errors`in e&&Array.isArray(e.errors)?e.errors.map(Oe).join(`, `):`cause`in e&&e.cause instanceof Error?`${e}: ${Oe(e.cause)}`:e.message:`${e}`}function ke(e){return{type:e.type,message:e.message,code:e.code,defaultPrevented:e.defaultPrevented,cancelable:e.cancelable,timeStamp:e.timeStamp}}var Ae=e=>{throw TypeError(e)},je=(e,t,n)=>t.has(e)||Ae(`Cannot `+n),w=(e,t,n)=>(je(e,t,`read from private field`),n?n.call(e):t.get(e)),T=(e,t,n)=>t.has(e)?Ae(`Cannot add the same private member more than once`):t instanceof WeakSet?t.add(e):t.set(e,n),E=(e,t,n,r)=>(je(e,t,`write to private field`),t.set(e,n),n),Me=(e,t,n)=>(je(e,t,`access private method`),n),D,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,O,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et=class extends EventTarget{constructor(e,t){super(),T(this,O),this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,T(this,D),T(this,Ne),T(this,Pe),T(this,Fe),T(this,Ie),T(this,Le),T(this,Re),T(this,ze,null),T(this,Be),T(this,Ve),T(this,He,null),T(this,Ue,null),T(this,We,null),T(this,Ke,async e=>{var t;w(this,Ve).reset();let{body:n,redirected:r,status:i,headers:a}=e;if(i===204){Me(this,O,Ze).call(this,`Server sent HTTP 204, not reconnecting`,204),this.close();return}if(r?E(this,Pe,new URL(e.url)):E(this,Pe,void 0),i!==200){Me(this,O,Ze).call(this,`Non-200 status code (${i})`,i);return}if(!(a.get(`content-type`)||``).startsWith(`text/event-stream`)){Me(this,O,Ze).call(this,`Invalid content type, expected "text/event-stream"`,i);return}if(w(this,D)===this.CLOSED)return;E(this,D,this.OPEN);let o=new Event(`open`);if((t=w(this,We))==null||t.call(this,o),this.dispatchEvent(o),typeof n!=`object`||!n||!(`getReader`in n)){Me(this,O,Ze).call(this,`Invalid response body, expected a web ReadableStream`,i),this.close();return}let s=new TextDecoder,c=n.getReader(),l=!0;do{let{done:e,value:t}=await c.read();t&&w(this,Ve).feed(s.decode(t,{stream:!e})),e&&(l=!1,w(this,Ve).reset(),Me(this,O,Qe).call(this))}while(l)}),T(this,qe,e=>{E(this,Be,void 0),!(e.name===`AbortError`||e.type===`aborted`)&&Me(this,O,Qe).call(this,Oe(e))}),T(this,Ye,e=>{typeof e.id==`string`&&E(this,ze,e.id);let t=new MessageEvent(e.event||`message`,{data:e.data,origin:w(this,Pe)?w(this,Pe).origin:w(this,Ne).origin,lastEventId:e.id||``});w(this,Ue)&&(!e.event||e.event===`message`)&&w(this,Ue).call(this,t),this.dispatchEvent(t)}),T(this,Xe,e=>{E(this,Le,e)}),T(this,$e,()=>{E(this,Re,void 0),w(this,D)===this.CONNECTING&&Me(this,O,Ge).call(this)});try{if(e instanceof URL)E(this,Ne,e);else if(typeof e==`string`)E(this,Ne,new URL(e,tt()));else throw Error(`Invalid URL`)}catch{throw De(`An invalid or illegal string was specified`)}E(this,Ve,v({onEvent:w(this,Ye),onRetry:w(this,Xe)})),E(this,D,this.CONNECTING),E(this,Le,3e3),E(this,Ie,t?.fetch??globalThis.fetch),E(this,Fe,t?.withCredentials??!1),Me(this,O,Ge).call(this)}get readyState(){return w(this,D)}get url(){return w(this,Ne).href}get withCredentials(){return w(this,Fe)}get onerror(){return w(this,He)}set onerror(e){E(this,He,e)}get onmessage(){return w(this,Ue)}set onmessage(e){E(this,Ue,e)}get onopen(){return w(this,We)}set onopen(e){E(this,We,e)}addEventListener(e,t,n){let r=t;super.addEventListener(e,r,n)}removeEventListener(e,t,n){let r=t;super.removeEventListener(e,r,n)}close(){w(this,Re)&&clearTimeout(w(this,Re)),w(this,D)!==this.CLOSED&&(w(this,Be)&&w(this,Be).abort(),E(this,D,this.CLOSED),E(this,Be,void 0))}};D=new WeakMap,Ne=new WeakMap,Pe=new WeakMap,Fe=new WeakMap,Ie=new WeakMap,Le=new WeakMap,Re=new WeakMap,ze=new WeakMap,Be=new WeakMap,Ve=new WeakMap,He=new WeakMap,Ue=new WeakMap,We=new WeakMap,O=new WeakSet,Ge=function(){E(this,D,this.CONNECTING),E(this,Be,new AbortController),w(this,Ie)(w(this,Ne),Me(this,O,Je).call(this)).then(w(this,Ke)).catch(w(this,qe))},Ke=new WeakMap,qe=new WeakMap,Je=function(){let e={mode:`cors`,redirect:`follow`,headers:{Accept:`text/event-stream`,...w(this,ze)?{"Last-Event-ID":w(this,ze)}:void 0},cache:`no-store`,signal:w(this,Be)?.signal};return`window`in globalThis&&(e.credentials=this.withCredentials?`include`:`same-origin`),e},Ye=new WeakMap,Xe=new WeakMap,Ze=function(e,t){var n;w(this,D)!==this.CLOSED&&E(this,D,this.CLOSED);let r=new Ee(`error`,{code:t,message:e});(n=w(this,He))==null||n.call(this,r),this.dispatchEvent(r)},Qe=function(e,t){var n;if(w(this,D)===this.CLOSED)return;E(this,D,this.CONNECTING);let r=new Ee(`error`,{code:t,message:e});(n=w(this,He))==null||n.call(this,r),this.dispatchEvent(r),E(this,Re,setTimeout(w(this,$e),w(this,Le)))},$e=new WeakMap,et.CONNECTING=0,et.OPEN=1,et.CLOSED=2;function tt(){let e=`document`in globalThis?globalThis.document:void 0;return e&&typeof e==`object`&&`baseURI`in e&&typeof e.baseURI==`string`?e.baseURI:void 0}const nt={right:st,center:ct};var rt=class{constructor(e){this.width=e.width,this.wrap=e.wrap??!0,this.rows=[]}span(...e){let t=this.div(...e);t.span=!0}resetOutput(){this.rows=[]}div(...e){if(e.length===0&&this.div(``),this.wrap&&this.shouldApplyLayoutDSL(...e)&&typeof e[0]==`string`)return this.applyLayoutDSL(e[0]);let t=e.map(e=>typeof e==`string`?this.colFromString(e):e);return this.rows.push(t),t}shouldApplyLayoutDSL(...e){return e.length===1&&typeof e[0]==`string`&&/[\t\n]/.test(e[0])}applyLayoutDSL(e){let t=e.split(`
|
|
3
3
|
`).map(e=>e.split(` `)),n=0;return t.forEach(e=>{e.length>1&&k.stringWidth(e[0])>n&&(n=Math.min(Math.floor(this.width*.5),k.stringWidth(e[0])))}),t.forEach(e=>{this.div(...e.map((t,r)=>({text:t.trim(),padding:this.measurePadding(t),width:r===0&&e.length>1?n:void 0})))}),this.rows[this.rows.length-1]}colFromString(e){return{text:e,padding:this.measurePadding(e)}}measurePadding(e){let t=k.stripAnsi(e);return[0,t.match(/\s*$/)[0].length,0,t.match(/^\s*/)[0].length]}toString(){let e=[];return this.rows.forEach(t=>{this.rowToString(t,e)}),e.filter(e=>!e.hidden).map(e=>e.text).join(`
|
|
4
4
|
`)}rowToString(e,t){return this.rasterize(e).forEach((n,r)=>{let i=``;n.forEach((n,a)=>{let{width:o}=e[a],s=this.negatePadding(e[a]),c=n;if(s>k.stringWidth(n)&&(c+=` `.repeat(s-k.stringWidth(n))),e[a].align&&e[a].align!==`left`&&this.wrap){let t=nt[e[a].align];c=t(c,s),k.stringWidth(c)<s&&(c+=` `.repeat((o||0)-k.stringWidth(c)-1))}let l=e[a].padding||[0,0,0,0];l[3]&&(i+=` `.repeat(l[3])),i+=it(e[a],c,`| `),i+=c,i+=it(e[a],c,` |`),l[1]&&(i+=` `.repeat(l[1])),r===0&&t.length>0&&(i=this.renderInline(i,t[t.length-1]))}),t.push({text:i.replace(/ +$/,``),span:e.span})}),t}renderInline(e,t){let n=e.match(/^ */),r=n?n[0].length:0,i=t.text,a=k.stringWidth(i.trimRight());return t.span?this.wrap?r<a?e:(t.hidden=!0,i.trimRight()+` `.repeat(r-a)+e.trimLeft()):(t.hidden=!0,i+e):e}rasterize(e){let t=[],n=this.columnWidths(e),r;return e.forEach((e,i)=>{e.width=n[i],r=this.wrap?k.wrap(e.text,this.negatePadding(e),{hard:!0}).split(`
|
|
5
5
|
`):e.text.split(`
|
|
@@ -89,9 +89,10 @@ complete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name
|
|
|
89
89
|
`)}`:``;t.fail(i(`Missing required argument: %s`,`Missing required arguments: %s`,Object.keys(r).length,Object.keys(r).join(`, `)+n))}},a.unknownArguments=function(n,r,o,s,c=!0){let l=e.getInternalMethods().getCommandInstance().getCommands(),u=[],d=e.getInternalMethods().getContext();if(Object.keys(n).forEach(t=>{!ar.includes(t)&&!Object.prototype.hasOwnProperty.call(o,t)&&!Object.prototype.hasOwnProperty.call(e.getInternalMethods().getParseContext(),t)&&!a.isValidAndSomeAliasIsNotNew(t,r)&&u.push(t)}),c&&(d.commands.length>0||l.length>0||s)&&n._.slice(d.commands.length).forEach(e=>{l.includes(``+e)||u.push(``+e)}),c){let t=e.getDemandedCommands()._?.max||0,r=d.commands.length+t;r<n._.length&&n._.slice(r).forEach(e=>{e=String(e),!d.commands.includes(e)&&!u.includes(e)&&u.push(e)})}u.length&&t.fail(i(`Unknown argument: %s`,`Unknown arguments: %s`,u.length,u.map(e=>e.trim()?e:`"${e}"`).join(`, `)))},a.unknownCommands=function(n){let r=e.getInternalMethods().getCommandInstance().getCommands(),a=[],o=e.getInternalMethods().getContext();return(o.commands.length>0||r.length>0)&&n._.slice(o.commands.length).forEach(e=>{r.includes(``+e)||a.push(``+e)}),a.length>0?(t.fail(i(`Unknown command: %s`,`Unknown commands: %s`,a.length,a.join(`, `))),!0):!1},a.isValidAndSomeAliasIsNotNew=function(t,n){if(!Object.prototype.hasOwnProperty.call(n,t))return!1;let r=e.parsed.newAliases;return[t,...n[t]].some(e=>!Object.prototype.hasOwnProperty.call(r,e)||!r[t])},a.limitedChoices=function(n){let i=e.getOptions(),a={};if(!Object.keys(i.choices).length)return;Object.keys(n).forEach(e=>{ar.indexOf(e)===-1&&Object.prototype.hasOwnProperty.call(i.choices,e)&&[].concat(n[e]).forEach(t=>{i.choices[e].indexOf(t)===-1&&t!==void 0&&(a[e]=(a[e]||[]).concat(t))})});let o=Object.keys(a);if(!o.length)return;let s=r(`Invalid values:`);o.forEach(e=>{s+=`\n ${r(`Argument: %s, Given: %s, Choices: %s`,e,t.stringifiedValues(a[e]),t.stringifiedValues(i.choices[e]))}`}),t.fail(s)};let o={};a.implies=function(t,r){P(`<string|object> [array|number|string]`,[t,r],arguments.length),typeof t==`object`?Object.keys(t).forEach(e=>{a.implies(e,t[e])}):(e.global(t),o[t]||(o[t]=[]),Array.isArray(r)?r.forEach(e=>a.implies(t,e)):(En(r,void 0,n),o[t].push(r)))},a.getImplied=function(){return o};function s(e,t){let n=Number(t);return t=isNaN(n)?t:n,typeof t==`number`?t=e._.length>=t:t.match(/^--no-.+/)?(t=t.match(/^--no-(.+)/)[1],t=!Object.prototype.hasOwnProperty.call(e,t)):t=Object.prototype.hasOwnProperty.call(e,t),t}a.implications=function(e){let n=[];if(Object.keys(o).forEach(t=>{let r=t;(o[t]||[]).forEach(t=>{let i=r,a=t;i=s(e,i),t=s(e,t),i&&!t&&n.push(` ${r} -> ${a}`)})}),n.length){let e=`${r(`Implications failed:`)}\n`;n.forEach(t=>{e+=t}),t.fail(e)}};let c={};a.conflicts=function(t,n){P(`<string|object> [array|string]`,[t,n],arguments.length),typeof t==`object`?Object.keys(t).forEach(e=>{a.conflicts(e,t[e])}):(e.global(t),c[t]||(c[t]=[]),Array.isArray(n)?n.forEach(e=>a.conflicts(t,e)):c[t].push(n))},a.getConflicting=()=>c,a.conflicting=function(i){Object.keys(i).forEach(e=>{c[e]&&c[e].forEach(n=>{n&&i[e]!==void 0&&i[n]!==void 0&&t.fail(r(`Arguments %s and %s are mutually exclusive`,e,n))})}),e.getInternalMethods().getParserConfiguration()[`strip-dashed`]&&Object.keys(c).forEach(e=>{c[e].forEach(a=>{a&&i[n.Parser.camelCase(e)]!==void 0&&i[n.Parser.camelCase(a)]!==void 0&&t.fail(r(`Arguments %s and %s are mutually exclusive`,e,a))})})},a.recommendCommands=function(e,n){n=n.sort((e,t)=>t.length-e.length);let i=null,a=1/0;for(let t=0,r;(r=n[t])!==void 0;t++){let t=ir(e,r);t<=3&&t<a&&(a=t,i=r)}i&&t.fail(r(`Did you mean %s?`,i))},a.reset=function(e){return o=Kn(o,t=>!e[t]),c=Kn(c,t=>!e[t]),a};let l=[];return a.freeze=function(){l.push({implied:o,conflicting:c})},a.unfreeze=function(){let e=l.pop();En(e,void 0,n),{implied:o,conflicting:c}=e},a}let sr=[],cr;function lr(e,t,n,r){cr=r;let i={};if(Object.prototype.hasOwnProperty.call(e,`extends`)){if(typeof e.extends!=`string`)return i;let a=/\.json|\..*rc$/.test(e.extends),o=null;if(a)o=dr(t,e.extends);else try{o=import.meta.resolve(e.extends)}catch{return e}ur(o),sr.push(o),i=a?JSON.parse(cr.readFileSync(o,`utf8`)):r.require(e.extends),delete e.extends,i=lr(i,cr.path.dirname(o),n,cr)}return sr=[],n?fr(i,e):Object.assign({},i,e)}function ur(e){if(sr.indexOf(e)>-1)throw new N(`Circular extended configurations: '${e}'.`)}function dr(e,t){return cr.path.resolve(e,t)}function fr(e,t){let n={};function r(e){return e&&typeof e==`object`&&!Array.isArray(e)}Object.assign(n,e);for(let i of Object.keys(t))r(t[i])&&r(n[i])?n[i]=fr(e[i],t[i]):n[i]=t[i];return n}var F=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},I=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},L,pr,mr,R,z,hr,gr,_r,vr,B,yr,V,br,H,U,xr,Sr,W,G,Cr,wr,K,Tr,Er,Dr,Or,kr,q,Ar,jr,Mr,J,Nr,Pr,Y;function Fr(e){return(t=[],n=e.process.cwd(),r)=>{let i=new vi(t,n,r,e);return Object.defineProperty(i,`argv`,{get:()=>i.parse(),enumerable:!0}),i.help(),i.version(),i}}const Ir=Symbol(`copyDoubleDash`),Lr=Symbol(`copyDoubleDash`),Rr=Symbol(`deleteFromParserHintObject`),zr=Symbol(`emitWarning`),Br=Symbol(`freeze`),Vr=Symbol(`getDollarZero`),Hr=Symbol(`getParserConfiguration`),Ur=Symbol(`getUsageConfiguration`),Wr=Symbol(`guessLocale`),Gr=Symbol(`guessVersion`),Kr=Symbol(`parsePositionalNumbers`),qr=Symbol(`pkgUp`),Jr=Symbol(`populateParserHintArray`),Yr=Symbol(`populateParserHintSingleValueDictionary`),Xr=Symbol(`populateParserHintArrayDictionary`),Zr=Symbol(`populateParserHintDictionary`),Qr=Symbol(`sanitizeKey`),$r=Symbol(`setKey`),ei=Symbol(`unfreeze`),ti=Symbol(`validateAsync`),ni=Symbol(`getCommandInstance`),ri=Symbol(`getContext`),ii=Symbol(`getHasOutput`),ai=Symbol(`getLoggerInstance`),oi=Symbol(`getParseContext`),si=Symbol(`getUsageInstance`),ci=Symbol(`getValidationInstance`),li=Symbol(`hasParseCallback`),ui=Symbol(`isGlobalContext`),di=Symbol(`postProcess`),fi=Symbol(`rebase`),pi=Symbol(`reset`),mi=Symbol(`runYargsParserAndExecuteCommands`),hi=Symbol(`runValidation`),gi=Symbol(`setHasOutput`),_i=Symbol(`kTrackManuallySetKeys`);var vi=class{constructor(e=[],t,n,r){this.customScriptName=!1,this.parsed=!1,L.set(this,void 0),pr.set(this,void 0),mr.set(this,{commands:[],fullCommands:[]}),R.set(this,null),z.set(this,null),hr.set(this,`show-hidden`),gr.set(this,null),_r.set(this,!0),vr.set(this,{}),B.set(this,!0),yr.set(this,[]),V.set(this,void 0),br.set(this,{}),H.set(this,!1),U.set(this,null),xr.set(this,!0),Sr.set(this,void 0),W.set(this,``),G.set(this,void 0),Cr.set(this,void 0),wr.set(this,{}),K.set(this,null),Tr.set(this,null),Er.set(this,{}),Dr.set(this,{}),Or.set(this,void 0),kr.set(this,!1),q.set(this,void 0),Ar.set(this,!1),jr.set(this,!1),Mr.set(this,!1),J.set(this,void 0),Nr.set(this,{}),Pr.set(this,null),Y.set(this,void 0),F(this,q,r,`f`),F(this,Or,e,`f`),F(this,pr,t,`f`),F(this,Cr,n,`f`),F(this,V,new Nn(this),`f`),this.$0=this[Vr](),this[pi](),F(this,L,I(this,L,`f`),`f`),F(this,J,I(this,J,`f`),`f`),F(this,Y,I(this,Y,`f`),`f`),F(this,G,I(this,G,`f`),`f`),I(this,G,`f`).showHiddenOpt=I(this,hr,`f`),F(this,Sr,this[Lr](),`f`),I(this,q,`f`).y18n.setLocale(`en_US`)}addHelpOpt(e,t){return P(`[string|boolean] [string]`,[e,t],arguments.length),I(this,U,`f`)&&(this[Rr](I(this,U,`f`)),F(this,U,null,`f`)),e===!1&&t===void 0?this:(F(this,U,typeof e==`string`?e:`help`,`f`),this.boolean(I(this,U,`f`)),this.describe(I(this,U,`f`),t||I(this,J,`f`).deferY18nLookup(`Show help`)),this)}help(e,t){return this.addHelpOpt(e,t)}addShowHiddenOpt(e,t){if(P(`[string|boolean] [string]`,[e,t],arguments.length),e===!1&&t===void 0)return this;let n=typeof e==`string`?e:I(this,hr,`f`);return this.boolean(n),this.describe(n,t||I(this,J,`f`).deferY18nLookup(`Show hidden options`)),I(this,G,`f`).showHiddenOpt=n,this}showHidden(e,t){return this.addShowHiddenOpt(e,t)}alias(e,t){return P(`<object|string|array> [string|array]`,[e,t],arguments.length),this[Xr](this.alias.bind(this),`alias`,e,t),this}array(e){return P(`<array|string>`,[e],arguments.length),this[Jr](`array`,e),this[_i](e),this}boolean(e){return P(`<array|string>`,[e],arguments.length),this[Jr](`boolean`,e),this[_i](e),this}check(e,t){return P(`<function> [boolean]`,[e,t],arguments.length),this.middleware((t,n)=>In(()=>e(t,n.getOptions()),n=>(n?(typeof n==`string`||n instanceof Error)&&I(this,J,`f`).fail(n.toString(),n):I(this,J,`f`).fail(I(this,q,`f`).y18n.__(`Argument check failed: %s`,e.toString())),t),e=>(I(this,J,`f`).fail(e.message?e.message:e.toString(),e),t)),!1,t),this}choices(e,t){return P(`<object|string|array> [string|array]`,[e,t],arguments.length),this[Xr](this.choices.bind(this),`choices`,e,t),this}coerce(e,t){if(P(`<object|string|array> [function]`,[e,t],arguments.length),Array.isArray(e)){if(!t)throw new N(`coerce callback must be provided`);for(let n of e)this.coerce(n,t);return this}else if(typeof e==`object`){for(let t of Object.keys(e))this.coerce(t,e[t]);return this}if(!t)throw new N(`coerce callback must be provided`);let n=e;return I(this,G,`f`).key[n]=!0,I(this,V,`f`).addCoerceMiddleware((e,r)=>{let i=r.getAliases()[n]??[],a=[n,...i].filter(t=>Object.prototype.hasOwnProperty.call(e,t));return a.length===0?e:In(()=>t(e[a[0]]),t=>(a.forEach(n=>{e[n]=t}),e),e=>{throw new N(e.message)})},n),this}conflicts(e,t){return P(`<string|object> [string|array]`,[e,t],arguments.length),I(this,Y,`f`).conflicts(e,t),this}config(e=`config`,t,n){return P(`[object|string] [string|function] [function]`,[e,t,n],arguments.length),typeof e==`object`&&!Array.isArray(e)?(e=lr(e,I(this,pr,`f`),this[Hr]()[`deep-merge-config`]||!1,I(this,q,`f`)),I(this,G,`f`).configObjects=(I(this,G,`f`).configObjects||[]).concat(e),this):(typeof t==`function`&&(n=t,t=void 0),this.describe(e,t||I(this,J,`f`).deferY18nLookup(`Path to JSON config file`)),(Array.isArray(e)?e:[e]).forEach(e=>{I(this,G,`f`).config[e]=n||!0}),this)}completion(e,t,n){return P(`[string] [string|boolean|function] [function]`,[e,t,n],arguments.length),typeof t==`function`&&(n=t,t=void 0),F(this,z,e||I(this,z,`f`)||`completion`,`f`),!t&&t!==!1&&(t=`generate completion script`),this.command(I(this,z,`f`),t),n&&I(this,R,`f`).registerFunction(n),this}command(e,t,n,r,i,a){return P(`<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]`,[e,t,n,r,i,a],arguments.length),I(this,L,`f`).addHandler(e,t,n,r,i,a),this}commands(e,t,n,r,i,a){return this.command(e,t,n,r,i,a)}commandDir(e,t){P(`<string> [object]`,[e,t],arguments.length);let n=I(this,Cr,`f`)||I(this,q,`f`).require;return I(this,L,`f`).addDirectory(e,n,I(this,q,`f`).getCallerFile(),t),this}count(e){return P(`<array|string>`,[e],arguments.length),this[Jr](`count`,e),this[_i](e),this}default(e,t,n){return P(`<object|string|array> [*] [string]`,[e,t,n],arguments.length),n&&(Dn(e,I(this,q,`f`)),I(this,G,`f`).defaultDescription[e]=n),typeof t==`function`&&(Dn(e,I(this,q,`f`)),I(this,G,`f`).defaultDescription[e]||(I(this,G,`f`).defaultDescription[e]=I(this,J,`f`).functionDescription(t)),t=t.call()),this[Yr](this.default.bind(this),`default`,e,t),this}defaults(e,t,n){return this.default(e,t,n)}demandCommand(e=1,t,n,r){return P(`[number] [number|string] [string|null|undefined] [string|null|undefined]`,[e,t,n,r],arguments.length),typeof t!=`number`&&(n=t,t=1/0),this.global(`_`,!1),I(this,G,`f`).demandedCommands._={min:e,max:t,minMsg:n,maxMsg:r},this}demand(e,t,n){return Array.isArray(t)?(t.forEach(e=>{En(n,!0,I(this,q,`f`)),this.demandOption(e,n)}),t=1/0):typeof t!=`number`&&(n=t,t=1/0),typeof e==`number`?(En(n,!0,I(this,q,`f`)),this.demandCommand(e,t,n,n)):Array.isArray(e)?e.forEach(e=>{En(n,!0,I(this,q,`f`)),this.demandOption(e,n)}):typeof n==`string`?this.demandOption(e,n):(n===!0||n===void 0)&&this.demandOption(e),this}demandOption(e,t){return P(`<object|string|array> [string]`,[e,t],arguments.length),this[Yr](this.demandOption.bind(this),`demandedOptions`,e,t),this}deprecateOption(e,t){return P(`<string> [string|boolean]`,[e,t],arguments.length),I(this,G,`f`).deprecatedOptions[e]=t,this}describe(e,t){return P(`<object|string|array> [string]`,[e,t],arguments.length),this[$r](e,!0),I(this,J,`f`).describe(e,t),this}detectLocale(e){return P(`<boolean>`,[e],arguments.length),F(this,_r,e,`f`),this}env(e){return P(`[string|boolean]`,[e],arguments.length),e===!1?delete I(this,G,`f`).envPrefix:I(this,G,`f`).envPrefix=e||``,this}epilogue(e){return P(`<string>`,[e],arguments.length),I(this,J,`f`).epilog(e),this}epilog(e){return this.epilogue(e)}example(e,t){return P(`<string|array> [string]`,[e,t],arguments.length),Array.isArray(e)?e.forEach(e=>this.example(...e)):I(this,J,`f`).example(e,t),this}exit(e,t){F(this,H,!0,`f`),F(this,gr,t,`f`),I(this,B,`f`)&&I(this,q,`f`).process.exit(e)}exitProcess(e=!0){return P(`[boolean]`,[e],arguments.length),F(this,B,e,`f`),this}fail(e){if(P(`<function|boolean>`,[e],arguments.length),typeof e==`boolean`&&e!==!1)throw new N(`Invalid first argument. Expected function or boolean 'false'`);return I(this,J,`f`).failFn(e),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(e,t){return P(`<array> [function]`,[e,t],arguments.length),t?I(this,R,`f`).getCompletion(e,t):new Promise((t,n)=>{I(this,R,`f`).getCompletion(e,(e,r)=>{e?n(e):t(r)})})}getDemandedOptions(){return P([],0),I(this,G,`f`).demandedOptions}getDemandedCommands(){return P([],0),I(this,G,`f`).demandedCommands}getDeprecatedOptions(){return P([],0),I(this,G,`f`).deprecatedOptions}getDetectLocale(){return I(this,_r,`f`)}getExitProcess(){return I(this,B,`f`)}getGroups(){return Object.assign({},I(this,br,`f`),I(this,Dr,`f`))}getHelp(){if(F(this,H,!0,`f`),!I(this,J,`f`).hasCachedHelpMessage()){if(!this.parsed){let e=this[mi](I(this,Or,`f`),void 0,void 0,0,!0);if(M(e))return e.then(()=>I(this,J,`f`).help())}let e=I(this,L,`f`).runDefaultBuilderOn(this);if(M(e))return e.then(()=>I(this,J,`f`).help())}return Promise.resolve(I(this,J,`f`).help())}getOptions(){return I(this,G,`f`)}getStrict(){return I(this,Ar,`f`)}getStrictCommands(){return I(this,jr,`f`)}getStrictOptions(){return I(this,Mr,`f`)}global(e,t){return P(`<string|array> [boolean]`,[e,t],arguments.length),e=[].concat(e),t===!1?e.forEach(e=>{I(this,G,`f`).local.includes(e)||I(this,G,`f`).local.push(e)}):I(this,G,`f`).local=I(this,G,`f`).local.filter(t=>e.indexOf(t)===-1),this}group(e,t){P(`<string|array> <string>`,[e,t],arguments.length);let n=I(this,Dr,`f`)[t]||I(this,br,`f`)[t];I(this,Dr,`f`)[t]&&delete I(this,Dr,`f`)[t];let r={};return I(this,br,`f`)[t]=(n||[]).concat(e).filter(e=>r[e]?!1:r[e]=!0),this}hide(e){return P(`<string>`,[e],arguments.length),I(this,G,`f`).hiddenOptions.push(e),this}implies(e,t){return P(`<string|object> [number|string|array]`,[e,t],arguments.length),I(this,Y,`f`).implies(e,t),this}locale(e){return P(`[string]`,[e],arguments.length),e===void 0?(this[Wr](),I(this,q,`f`).y18n.getLocale()):(F(this,_r,!1,`f`),I(this,q,`f`).y18n.setLocale(e),this)}middleware(e,t,n){return I(this,V,`f`).addMiddleware(e,!!t,n)}nargs(e,t){return P(`<string|object|array> [number]`,[e,t],arguments.length),this[Yr](this.nargs.bind(this),`narg`,e,t),this}normalize(e){return P(`<array|string>`,[e],arguments.length),this[Jr](`normalize`,e),this}number(e){return P(`<array|string>`,[e],arguments.length),this[Jr](`number`,e),this[_i](e),this}option(e,t){if(P(`<string|object> [object]`,[e,t],arguments.length),typeof e==`object`)Object.keys(e).forEach(t=>{this.options(t,e[t])});else{typeof t!=`object`&&(t={}),this[_i](e),I(this,Pr,`f`)&&(e===`version`||t?.alias===`version`)&&this[zr]([`"version" is a reserved word.`,`Please do one of the following:`,'- Disable version with `yargs.version(false)` if using "version" as an option',"- Use the built-in `yargs.version` method instead (if applicable)",`- Use a different option key`,`https://yargs.js.org/docs/#api-reference-version`].join(`
|
|
90
90
|
`),void 0,`versionWarning`),I(this,G,`f`).key[e]=!0,t.alias&&this.alias(e,t.alias);let n=t.deprecate||t.deprecated;n&&this.deprecateOption(e,n);let r=t.demand||t.required||t.require;r&&this.demand(e,r),t.demandOption&&this.demandOption(e,typeof t.demandOption==`string`?t.demandOption:void 0),t.conflicts&&this.conflicts(e,t.conflicts),`default`in t&&this.default(e,t.default),t.implies!==void 0&&this.implies(e,t.implies),t.nargs!==void 0&&this.nargs(e,t.nargs),t.config&&this.config(e,t.configParser),t.normalize&&this.normalize(e),t.choices&&this.choices(e,t.choices),t.coerce&&this.coerce(e,t.coerce),t.group&&this.group(e,t.group),(t.boolean||t.type===`boolean`)&&(this.boolean(e),t.alias&&this.boolean(t.alias)),(t.array||t.type===`array`)&&(this.array(e),t.alias&&this.array(t.alias)),(t.number||t.type===`number`)&&(this.number(e),t.alias&&this.number(t.alias)),(t.string||t.type===`string`)&&(this.string(e),t.alias&&this.string(t.alias)),(t.count||t.type===`count`)&&this.count(e),typeof t.global==`boolean`&&this.global(e,t.global),t.defaultDescription&&(I(this,G,`f`).defaultDescription[e]=t.defaultDescription),t.skipValidation&&this.skipValidation(e);let i=t.describe||t.description||t.desc,a=I(this,J,`f`).getDescriptions();(!Object.prototype.hasOwnProperty.call(a,e)||typeof i==`string`)&&this.describe(e,i),t.hidden&&this.hide(e),t.requiresArg&&this.requiresArg(e)}return this}options(e,t){return this.option(e,t)}parse(e,t,n){P(`[string|array] [function|boolean|object] [function]`,[e,t,n],arguments.length),this[Br](),e===void 0&&(e=I(this,Or,`f`)),typeof t==`object`&&(F(this,Tr,t,`f`),t=n),typeof t==`function`&&(F(this,K,t,`f`),t=!1),t||F(this,Or,e,`f`),I(this,K,`f`)&&F(this,B,!1,`f`);let r=this[mi](e,!!t),i=this.parsed;return I(this,R,`f`).setParsed(this.parsed),M(r)?r.then(e=>(I(this,K,`f`)&&I(this,K,`f`).call(this,I(this,gr,`f`),e,I(this,W,`f`)),e)).catch(e=>{throw I(this,K,`f`)&&I(this,K,`f`)(e,this.parsed.argv,I(this,W,`f`)),e}).finally(()=>{this[ei](),this.parsed=i}):(I(this,K,`f`)&&I(this,K,`f`).call(this,I(this,gr,`f`),r,I(this,W,`f`)),this[ei](),this.parsed=i,r)}parseAsync(e,t,n){let r=this.parse(e,t,n);return M(r)?r:Promise.resolve(r)}parseSync(e,t,n){let r=this.parse(e,t,n);if(M(r))throw new N(`.parseSync() must not be used with asynchronous builders, handlers, or middleware`);return r}parserConfiguration(e){return P(`<object>`,[e],arguments.length),F(this,wr,e,`f`),this}pkgConf(e,t){P(`<string> [string]`,[e,t],arguments.length);let n=null,r=this[qr](t||I(this,pr,`f`));return r[e]&&typeof r[e]==`object`&&(n=lr(r[e],t||I(this,pr,`f`),this[Hr]()[`deep-merge-config`]||!1,I(this,q,`f`)),I(this,G,`f`).configObjects=(I(this,G,`f`).configObjects||[]).concat(n)),this}positional(e,t){P(`<string> <object>`,[e,t],arguments.length);let n=[`default`,`defaultDescription`,`implies`,`normalize`,`choices`,`conflicts`,`coerce`,`type`,`describe`,`desc`,`description`,`alias`];t=Kn(t,(e,t)=>e===`type`&&![`string`,`number`,`boolean`].includes(t)?!1:n.includes(e));let r=I(this,mr,`f`).fullCommands[I(this,mr,`f`).fullCommands.length-1],i=r?I(this,L,`f`).cmdToParseOptions(r):{array:[],alias:{},default:{},demand:{}};return On(i).forEach(n=>{let r=i[n];Array.isArray(r)?r.indexOf(e)!==-1&&(t[n]=!0):r[e]&&!(n in t)&&(t[n]=r[e])}),this.group(e,I(this,J,`f`).getPositionalGroupName()),this.option(e,t)}recommendCommands(e=!0){return P(`[boolean]`,[e],arguments.length),F(this,kr,e,`f`),this}required(e,t,n){return this.demand(e,t,n)}require(e,t,n){return this.demand(e,t,n)}requiresArg(e){return P(`<array|string|object> [number]`,[e],arguments.length),typeof e==`string`&&I(this,G,`f`).narg[e]||this[Yr](this.requiresArg.bind(this),`narg`,e,NaN),this}showCompletionScript(e,t){return P(`[string] [string]`,[e,t],arguments.length),e||=this.$0,I(this,Sr,`f`).log(I(this,R,`f`).generateCompletionScript(e,t||I(this,z,`f`)||`completion`)),this}showHelp(e){if(P(`[string|function]`,[e],arguments.length),F(this,H,!0,`f`),!I(this,J,`f`).hasCachedHelpMessage()){if(!this.parsed){let t=this[mi](I(this,Or,`f`),void 0,void 0,0,!0);if(M(t))return t.then(()=>{I(this,J,`f`).showHelp(e)}),this}let t=I(this,L,`f`).runDefaultBuilderOn(this);if(M(t))return t.then(()=>{I(this,J,`f`).showHelp(e)}),this}return I(this,J,`f`).showHelp(e),this}scriptName(e){return this.customScriptName=!0,this.$0=e,this}showHelpOnFail(e,t){return P(`[boolean|string] [string]`,[e,t],arguments.length),I(this,J,`f`).showHelpOnFail(e,t),this}showVersion(e){return P(`[string|function]`,[e],arguments.length),I(this,J,`f`).showVersion(e),this}skipValidation(e){return P(`<array|string>`,[e],arguments.length),this[Jr](`skipValidation`,e),this}strict(e){return P(`[boolean]`,[e],arguments.length),F(this,Ar,e!==!1,`f`),this}strictCommands(e){return P(`[boolean]`,[e],arguments.length),F(this,jr,e!==!1,`f`),this}strictOptions(e){return P(`[boolean]`,[e],arguments.length),F(this,Mr,e!==!1,`f`),this}string(e){return P(`<array|string>`,[e],arguments.length),this[Jr](`string`,e),this[_i](e),this}terminalWidth(){return P([],0),I(this,q,`f`).process.stdColumns}updateLocale(e){return this.updateStrings(e)}updateStrings(e){return P(`<object>`,[e],arguments.length),F(this,_r,!1,`f`),I(this,q,`f`).y18n.updateLocale(e),this}usage(e,t,n,r){if(P(`<string|null|undefined> [string|boolean] [function|object] [function]`,[e,t,n,r],arguments.length),t!==void 0){if(En(e,null,I(this,q,`f`)),(e||``).match(/^\$0( |$)/))return this.command(e,t,n,r);throw new N(`.usage() description must start with $0 if being used as alias for .command()`)}else return I(this,J,`f`).usage(e),this}usageConfiguration(e){return P(`<object>`,[e],arguments.length),F(this,Nr,e,`f`),this}version(e,t,n){let r=`version`;if(P(`[boolean|string] [string] [string]`,[e,t,n],arguments.length),I(this,Pr,`f`)&&(this[Rr](I(this,Pr,`f`)),I(this,J,`f`).version(void 0),F(this,Pr,null,`f`)),arguments.length===0)n=this[Gr](),e=r;else if(arguments.length===1){if(e===!1)return this;n=e,e=r}else arguments.length===2&&(n=t,t=void 0);return F(this,Pr,typeof e==`string`?e:r,`f`),t||=I(this,J,`f`).deferY18nLookup(`Show version number`),I(this,J,`f`).version(n||void 0),this.boolean(I(this,Pr,`f`)),this.describe(I(this,Pr,`f`),t),this}wrap(e){return P(`<number|null|undefined>`,[e],arguments.length),I(this,J,`f`).wrap(e),this}[(L=new WeakMap,pr=new WeakMap,mr=new WeakMap,R=new WeakMap,z=new WeakMap,hr=new WeakMap,gr=new WeakMap,_r=new WeakMap,vr=new WeakMap,B=new WeakMap,yr=new WeakMap,V=new WeakMap,br=new WeakMap,H=new WeakMap,U=new WeakMap,xr=new WeakMap,Sr=new WeakMap,W=new WeakMap,G=new WeakMap,Cr=new WeakMap,wr=new WeakMap,K=new WeakMap,Tr=new WeakMap,Er=new WeakMap,Dr=new WeakMap,Or=new WeakMap,kr=new WeakMap,q=new WeakMap,Ar=new WeakMap,jr=new WeakMap,Mr=new WeakMap,J=new WeakMap,Nr=new WeakMap,Pr=new WeakMap,Y=new WeakMap,Ir)](e){if(!e._||!e[`--`])return e;e._.push.apply(e._,e[`--`]);try{delete e[`--`]}catch{}return e}[Lr](){return{log:(...e)=>{this[li]()||console.log(...e),F(this,H,!0,`f`),I(this,W,`f`).length&&F(this,W,I(this,W,`f`)+`
|
|
91
91
|
`,`f`),F(this,W,I(this,W,`f`)+e.join(` `),`f`)},error:(...e)=>{this[li]()||console.error(...e),F(this,H,!0,`f`),I(this,W,`f`).length&&F(this,W,I(this,W,`f`)+`
|
|
92
|
-
`,`f`),F(this,W,I(this,W,`f`)+e.join(` `),`f`)}}}[Rr](e){On(I(this,G,`f`)).forEach(t=>{if((e=>e===`configObjects`)(t))return;let n=I(this,G,`f`)[t];Array.isArray(n)?n.includes(e)&&n.splice(n.indexOf(e),1):typeof n==`object`&&delete n[e]}),delete I(this,J,`f`).getDescriptions()[e]}[zr](e,t,n){I(this,vr,`f`)[n]||(I(this,q,`f`).process.emitWarning(e,t),I(this,vr,`f`)[n]=!0)}[Br](){I(this,yr,`f`).push({options:I(this,G,`f`),configObjects:I(this,G,`f`).configObjects.slice(0),exitProcess:I(this,B,`f`),groups:I(this,br,`f`),strict:I(this,Ar,`f`),strictCommands:I(this,jr,`f`),strictOptions:I(this,Mr,`f`),completionCommand:I(this,z,`f`),output:I(this,W,`f`),exitError:I(this,gr,`f`),hasOutput:I(this,H,`f`),parsed:this.parsed,parseFn:I(this,K,`f`),parseContext:I(this,Tr,`f`)}),I(this,J,`f`).freeze(),I(this,Y,`f`).freeze(),I(this,L,`f`).freeze(),I(this,V,`f`).freeze()}[Vr](){let e=``,t;return t=/\b(node|iojs|electron)(\.exe)?$/.test(I(this,q,`f`).process.argv()[0])?I(this,q,`f`).process.argv().slice(1,2):I(this,q,`f`).process.argv().slice(0,1),e=t.map(e=>{let t=this[fi](I(this,pr,`f`),e);return e.match(/^(\/|([a-zA-Z]:)?\\)/)&&t.length<e.length?t:e}).join(` `).trim(),I(this,q,`f`).getEnv(`_`)&&I(this,q,`f`).getProcessArgvBin()===I(this,q,`f`).getEnv(`_`)&&(e=I(this,q,`f`).getEnv(`_`).replace(`${I(this,q,`f`).path.dirname(I(this,q,`f`).process.execPath())}/`,``)),e}[Hr](){return I(this,wr,`f`)}[Ur](){return I(this,Nr,`f`)}[Wr](){if(!I(this,_r,`f`))return;let e=I(this,q,`f`).getEnv(`LC_ALL`)||I(this,q,`f`).getEnv(`LC_MESSAGES`)||I(this,q,`f`).getEnv(`LANG`)||I(this,q,`f`).getEnv(`LANGUAGE`)||`en_US`;this.locale(e.replace(/[.:].*/,``))}[Gr](){return this[qr]().version||`unknown`}[Kr](e){let t=e[`--`]?e[`--`]:e._;for(let e=0,n;(n=t[e])!==void 0;e++)I(this,q,`f`).Parser.looksLikeNumber(n)&&Number.isSafeInteger(Math.floor(parseFloat(`${n}`)))&&(t[e]=Number(n));return e}[qr](e){let t=e||`*`;if(I(this,Er,`f`)[t])return I(this,Er,`f`)[t];let n={};try{let t=e||I(this,q,`f`).mainFilename;I(this,q,`f`).path.extname(t)&&(t=I(this,q,`f`).path.dirname(t));let r=I(this,q,`f`).findUp(t,(e,t)=>{if(t.includes(`package.json`))return`package.json`});En(r,void 0,I(this,q,`f`)),n=JSON.parse(I(this,q,`f`).readFileSync(r,`utf8`))}catch{}return I(this,Er,`f`)[t]=n||{},I(this,Er,`f`)[t]}[Jr](e,t){t=[].concat(t),t.forEach(t=>{t=this[Qr](t),I(this,G,`f`)[e].push(t)})}[Yr](e,t,n,r){this[Zr](e,t,n,r,(e,t,n)=>{I(this,G,`f`)[e][t]=n})}[Xr](e,t,n,r){this[Zr](e,t,n,r,(e,t,n)=>{I(this,G,`f`)[e][t]=(I(this,G,`f`)[e][t]||[]).concat(n)})}[Zr](e,t,n,r,i){if(Array.isArray(n))n.forEach(t=>{e(t,r)});else if((e=>typeof e==`object`)(n))for(let t of On(n))e(t,n[t]);else i(t,this[Qr](n),r)}[Qr](e){return e===`__proto__`?`___proto___`:e}[$r](e,t){return this[Yr](this[$r].bind(this),`key`,e,t),this}[ei](){var e,t,n,r,i,a,o,s,c,l,u,d;let f=I(this,yr,`f`).pop();En(f,void 0,I(this,q,`f`));let p;e=this,t=this,n=this,r=this,i=this,a=this,o=this,s=this,c=this,l=this,u=this,d=this,{options:{set value(t){F(e,G,t,`f`)}}.value,configObjects:p,exitProcess:{set value(e){F(t,B,e,`f`)}}.value,groups:{set value(e){F(n,br,e,`f`)}}.value,output:{set value(e){F(r,W,e,`f`)}}.value,exitError:{set value(e){F(i,gr,e,`f`)}}.value,hasOutput:{set value(e){F(a,H,e,`f`)}}.value,parsed:this.parsed,strict:{set value(e){F(o,Ar,e,`f`)}}.value,strictCommands:{set value(e){F(s,jr,e,`f`)}}.value,strictOptions:{set value(e){F(c,Mr,e,`f`)}}.value,completionCommand:{set value(e){F(l,z,e,`f`)}}.value,parseFn:{set value(e){F(u,K,e,`f`)}}.value,parseContext:{set value(e){F(d,Tr,e,`f`)}}.value}=f,I(this,G,`f`).configObjects=p,I(this,J,`f`).unfreeze(),I(this,Y,`f`).unfreeze(),I(this,L,`f`).unfreeze(),I(this,V,`f`).unfreeze()}[ti](e,t){return In(t,t=>(e(t),t))}getInternalMethods(){return{getCommandInstance:this[ni].bind(this),getContext:this[ri].bind(this),getHasOutput:this[ii].bind(this),getLoggerInstance:this[ai].bind(this),getParseContext:this[oi].bind(this),getParserConfiguration:this[Hr].bind(this),getUsageConfiguration:this[Ur].bind(this),getUsageInstance:this[si].bind(this),getValidationInstance:this[ci].bind(this),hasParseCallback:this[li].bind(this),isGlobalContext:this[ui].bind(this),postProcess:this[di].bind(this),reset:this[pi].bind(this),runValidation:this[hi].bind(this),runYargsParserAndExecuteCommands:this[mi].bind(this),setHasOutput:this[gi].bind(this)}}[ni](){return I(this,L,`f`)}[ri](){return I(this,mr,`f`)}[ii](){return I(this,H,`f`)}[ai](){return I(this,Sr,`f`)}[oi](){return I(this,Tr,`f`)||{}}[si](){return I(this,J,`f`)}[ci](){return I(this,Y,`f`)}[li](){return!!I(this,K,`f`)}[ui](){return I(this,xr,`f`)}[di](e,t,n,r){return n||M(e)?e:(t||(e=this[Ir](e)),(this[Hr]()[`parse-positional-numbers`]||this[Hr]()[`parse-positional-numbers`]===void 0)&&(e=this[Kr](e)),r&&(e=Fn(e,this,I(this,V,`f`).getMiddleware(),!1)),e)}[pi](e={}){F(this,G,I(this,G,`f`)||{},`f`);let t={};t.local=I(this,G,`f`).local||[],t.configObjects=I(this,G,`f`).configObjects||[];let n={};return t.local.forEach(t=>{n[t]=!0,(e[t]||[]).forEach(e=>{n[e]=!0})}),Object.assign(I(this,Dr,`f`),Object.keys(I(this,br,`f`)).reduce((e,t)=>{let r=I(this,br,`f`)[t].filter(e=>!(e in n));return r.length>0&&(e[t]=r),e},{})),F(this,br,{},`f`),[`array`,`boolean`,`string`,`skipValidation`,`count`,`normalize`,`number`,`hiddenOptions`].forEach(e=>{t[e]=(I(this,G,`f`)[e]||[]).filter(e=>!n[e])}),[`narg`,`key`,`alias`,`default`,`defaultDescription`,`config`,`choices`,`demandedOptions`,`demandedCommands`,`deprecatedOptions`].forEach(e=>{t[e]=Kn(I(this,G,`f`)[e],e=>!n[e])}),t.envPrefix=I(this,G,`f`).envPrefix,F(this,G,t,`f`),F(this,J,I(this,J,`f`)?I(this,J,`f`).reset(n):Yn(this,I(this,q,`f`)),`f`),F(this,Y,I(this,Y,`f`)?I(this,Y,`f`).reset(n):or(this,I(this,J,`f`),I(this,q,`f`)),`f`),F(this,L,I(this,L,`f`)?I(this,L,`f`).reset():Bn(I(this,J,`f`),I(this,Y,`f`),I(this,V,`f`),I(this,q,`f`)),`f`),I(this,R,`f`)||F(this,R,tr(this,I(this,J,`f`),I(this,L,`f`),I(this,q,`f`)),`f`),I(this,V,`f`).reset(),F(this,z,null,`f`),F(this,W,``,`f`),F(this,gr,null,`f`),F(this,H,!1,`f`),this.parsed=!1,this}[fi](e,t){return I(this,q,`f`).path.relative(e,t)}[mi](e,t,n,r=0,i=!1){let a=!!n||i;e||=I(this,Or,`f`),I(this,G,`f`).__=I(this,q,`f`).y18n.__,I(this,G,`f`).configuration=this[Hr]();let o=!!I(this,G,`f`).configuration[`populate--`],s=Object.assign({},I(this,G,`f`).configuration,{"populate--":!0}),c=I(this,q,`f`).Parser.detailed(e,Object.assign({},I(this,G,`f`),{configuration:{"parse-positional-numbers":!1,...s}})),l=Object.assign(c.argv,I(this,Tr,`f`)),u,d=c.aliases,f=!1,p=!1;Object.keys(l).forEach(e=>{e===I(this,U,`f`)&&l[e]?f=!0:e===I(this,Pr,`f`)&&l[e]&&(p=!0)}),l.$0=this.$0,this.parsed=c,r===0&&I(this,J,`f`).clearCachedHelpMessage();try{if(this[Wr](),t)return this[di](l,o,!!n,!1);I(this,U,`f`)&&[I(this,U,`f`)].concat(d[I(this,U,`f`)]||[]).filter(e=>e.length>1).includes(``+l._[l._.length-1])&&(l._.pop(),f=!0),F(this,xr,!1,`f`);let s=I(this,L,`f`).getCommands(),m=I(this,R,`f`)?.completionKey?[I(this,R,`f`)?.completionKey,...this.getAliases()[I(this,R,`f`)?.completionKey]??[]].some(e=>Object.prototype.hasOwnProperty.call(l,e)):!1,h=f||m||i;if(l._.length){if(s.length){let e;for(let t=r||0,a;l._[t]!==void 0;t++)if(a=String(l._[t]),s.includes(a)&&a!==I(this,z,`f`)){let e=I(this,L,`f`).runCommand(a,this,c,t+1,i,f||p||i);return this[di](e,o,!!n,!1)}else if(!e&&a!==I(this,z,`f`)){e=a;break}!I(this,L,`f`).hasDefaultCommand()&&I(this,kr,`f`)&&e&&!h&&I(this,Y,`f`).recommendCommands(e,s)}I(this,z,`f`)&&l._.includes(I(this,z,`f`))&&!m&&(I(this,B,`f`)&&qn(!0),this.showCompletionScript(),this.exit(0))}if(I(this,L,`f`).hasDefaultCommand()&&!h){let e=I(this,L,`f`).runCommand(null,this,c,0,i,f||p||i);return this[di](e,o,!!n,!1)}if(m){I(this,B,`f`)&&qn(!0),e=[].concat(e);let t=e.slice(e.indexOf(`--${I(this,R,`f`).completionKey}`)+1);return I(this,R,`f`).getCompletion(t,(e,t)=>{if(e)throw new N(e.message);(t||[]).forEach(e=>{I(this,Sr,`f`).log(e)}),this.exit(0)}),this[di](l,!o,!!n,!1)}if(I(this,H,`f`)||(f?(I(this,B,`f`)&&qn(!0),a=!0,this.showHelp(e=>{I(this,Sr,`f`).log(e),this.exit(0)})):p&&(I(this,B,`f`)&&qn(!0),a=!0,I(this,J,`f`).showVersion(`log`),this.exit(0))),!a&&I(this,G,`f`).skipValidation.length>0&&(a=Object.keys(l).some(e=>I(this,G,`f`).skipValidation.indexOf(e)>=0&&l[e]===!0)),!a){if(c.error)throw new N(c.error.message);if(!m){let e=this[hi](d,{},c.error);n||(u=Fn(l,this,I(this,V,`f`).getMiddleware(),!0)),u=this[ti](e,u??l),M(u)&&!n&&(u=u.then(()=>Fn(l,this,I(this,V,`f`).getMiddleware(),!1)))}}}catch(e){if(e instanceof N)I(this,J,`f`).fail(e.message,e);else throw e}return this[di](u??l,o,!!n,!0)}[hi](e,t,n,r){let i={...this.getDemandedOptions()};return a=>{if(n)throw new N(n.message);I(this,Y,`f`).nonOptionCount(a),I(this,Y,`f`).requiredArguments(a,i);let o=!1;I(this,jr,`f`)&&(o=I(this,Y,`f`).unknownCommands(a)),I(this,Ar,`f`)&&!o?I(this,Y,`f`).unknownArguments(a,e,t,!!r):I(this,Mr,`f`)&&I(this,Y,`f`).unknownArguments(a,e,{},!1,!1),I(this,Y,`f`).limitedChoices(a),I(this,Y,`f`).implications(a),I(this,Y,`f`).conflicting(a)}}[gi](){F(this,H,!0,`f`)}[_i](e){if(typeof e==`string`)I(this,G,`f`).key[e]=!0;else for(let t of e)I(this,G,`f`).key[t]=!0}};function yi(e){return!!e&&typeof e.getInternalMethods==`function`}var bi=Fr(Tn),xi=class{client;enabled;lastBlockReason;constructor(e){this.enabled=e.enabled,this.client=e.client,b.info(`AccessControlAuthorizer initialized`,{enabled:this.enabled,hasClient:!!this.client})}getBlockReason(){return this.lastBlockReason||`MCP server blocked by access control policy`}async isAllowed(){if(!this.enabled)return!0;if(this.client)try{let e=await this.client.authorize();return e.action===`block`?(this.lastBlockReason=e.reason||`MCP server blocked by access control policy`,!1):!0}catch(e){return b.error(`Access control authorization failed with unexpected error`,{error:String(e)}),!0}return b.warn(`No access control client configured, allowing by default`),!0}},Si=class{clientInfoBase64;config;constructor(e){this.config=e,this.clientInfoBase64=this.getClientInfoBase64(),b.info(`AccessControlClient initialized`,{timeoutMs:e.timeoutMs,url:e.url})}async authorize(){try{let e=await this.sendAuthorizeRequest();return b.debug(`Access control check successful`,{action:e.action}),e}catch(e){return b.warn(`Access control check failed, failing open (allowing by default)`,{error:String(e)}),{action:`allow`}}}getClientInfoBase64(){return g(this.config.sessionData)}async sendAuthorizeRequest(){let e=new AbortController,t=setTimeout(()=>e.abort(),this.config.timeoutMs);try{let t=`${this.config.url}/${this.config.apiKey}/mcp/${this.clientInfoBase64}`,n=await fetch(t,{headers:{...this.config.headers},method:`POST`,signal:e.signal});if(!n.ok)throw Error(`Access control service returned ${n.status}: ${n.statusText}`);let r=await n.json();if(!r.action||![`allow`,`block`].includes(r.action))throw Error(`Invalid access control response format: action="${r.action}"`);return r}catch(e){throw e instanceof Error&&e.name===`AbortError`?Error(`Access control check timed out after ${this.config.timeoutMs}ms`):e}finally{clearTimeout(t)}}},Ci=class extends Te{buffer=``;constructor(){super({objectMode:!1})}_flush(e){this.buffer.trim().startsWith(`{`)?e(null,Buffer.from(this.buffer)):e(null,null)}_transform(e,t,n){this.buffer+=e.toString();let r=this.buffer.split(`
|
|
92
|
+
`,`f`),F(this,W,I(this,W,`f`)+e.join(` `),`f`)}}}[Rr](e){On(I(this,G,`f`)).forEach(t=>{if((e=>e===`configObjects`)(t))return;let n=I(this,G,`f`)[t];Array.isArray(n)?n.includes(e)&&n.splice(n.indexOf(e),1):typeof n==`object`&&delete n[e]}),delete I(this,J,`f`).getDescriptions()[e]}[zr](e,t,n){I(this,vr,`f`)[n]||(I(this,q,`f`).process.emitWarning(e,t),I(this,vr,`f`)[n]=!0)}[Br](){I(this,yr,`f`).push({options:I(this,G,`f`),configObjects:I(this,G,`f`).configObjects.slice(0),exitProcess:I(this,B,`f`),groups:I(this,br,`f`),strict:I(this,Ar,`f`),strictCommands:I(this,jr,`f`),strictOptions:I(this,Mr,`f`),completionCommand:I(this,z,`f`),output:I(this,W,`f`),exitError:I(this,gr,`f`),hasOutput:I(this,H,`f`),parsed:this.parsed,parseFn:I(this,K,`f`),parseContext:I(this,Tr,`f`)}),I(this,J,`f`).freeze(),I(this,Y,`f`).freeze(),I(this,L,`f`).freeze(),I(this,V,`f`).freeze()}[Vr](){let e=``,t;return t=/\b(node|iojs|electron)(\.exe)?$/.test(I(this,q,`f`).process.argv()[0])?I(this,q,`f`).process.argv().slice(1,2):I(this,q,`f`).process.argv().slice(0,1),e=t.map(e=>{let t=this[fi](I(this,pr,`f`),e);return e.match(/^(\/|([a-zA-Z]:)?\\)/)&&t.length<e.length?t:e}).join(` `).trim(),I(this,q,`f`).getEnv(`_`)&&I(this,q,`f`).getProcessArgvBin()===I(this,q,`f`).getEnv(`_`)&&(e=I(this,q,`f`).getEnv(`_`).replace(`${I(this,q,`f`).path.dirname(I(this,q,`f`).process.execPath())}/`,``)),e}[Hr](){return I(this,wr,`f`)}[Ur](){return I(this,Nr,`f`)}[Wr](){if(!I(this,_r,`f`))return;let e=I(this,q,`f`).getEnv(`LC_ALL`)||I(this,q,`f`).getEnv(`LC_MESSAGES`)||I(this,q,`f`).getEnv(`LANG`)||I(this,q,`f`).getEnv(`LANGUAGE`)||`en_US`;this.locale(e.replace(/[.:].*/,``))}[Gr](){return this[qr]().version||`unknown`}[Kr](e){let t=e[`--`]?e[`--`]:e._;for(let e=0,n;(n=t[e])!==void 0;e++)I(this,q,`f`).Parser.looksLikeNumber(n)&&Number.isSafeInteger(Math.floor(parseFloat(`${n}`)))&&(t[e]=Number(n));return e}[qr](e){let t=e||`*`;if(I(this,Er,`f`)[t])return I(this,Er,`f`)[t];let n={};try{let t=e||I(this,q,`f`).mainFilename;I(this,q,`f`).path.extname(t)&&(t=I(this,q,`f`).path.dirname(t));let r=I(this,q,`f`).findUp(t,(e,t)=>{if(t.includes(`package.json`))return`package.json`});En(r,void 0,I(this,q,`f`)),n=JSON.parse(I(this,q,`f`).readFileSync(r,`utf8`))}catch{}return I(this,Er,`f`)[t]=n||{},I(this,Er,`f`)[t]}[Jr](e,t){t=[].concat(t),t.forEach(t=>{t=this[Qr](t),I(this,G,`f`)[e].push(t)})}[Yr](e,t,n,r){this[Zr](e,t,n,r,(e,t,n)=>{I(this,G,`f`)[e][t]=n})}[Xr](e,t,n,r){this[Zr](e,t,n,r,(e,t,n)=>{I(this,G,`f`)[e][t]=(I(this,G,`f`)[e][t]||[]).concat(n)})}[Zr](e,t,n,r,i){if(Array.isArray(n))n.forEach(t=>{e(t,r)});else if((e=>typeof e==`object`)(n))for(let t of On(n))e(t,n[t]);else i(t,this[Qr](n),r)}[Qr](e){return e===`__proto__`?`___proto___`:e}[$r](e,t){return this[Yr](this[$r].bind(this),`key`,e,t),this}[ei](){var e,t,n,r,i,a,o,s,c,l,u,d;let f=I(this,yr,`f`).pop();En(f,void 0,I(this,q,`f`));let p;e=this,t=this,n=this,r=this,i=this,a=this,o=this,s=this,c=this,l=this,u=this,d=this,{options:{set value(t){F(e,G,t,`f`)}}.value,configObjects:p,exitProcess:{set value(e){F(t,B,e,`f`)}}.value,groups:{set value(e){F(n,br,e,`f`)}}.value,output:{set value(e){F(r,W,e,`f`)}}.value,exitError:{set value(e){F(i,gr,e,`f`)}}.value,hasOutput:{set value(e){F(a,H,e,`f`)}}.value,parsed:this.parsed,strict:{set value(e){F(o,Ar,e,`f`)}}.value,strictCommands:{set value(e){F(s,jr,e,`f`)}}.value,strictOptions:{set value(e){F(c,Mr,e,`f`)}}.value,completionCommand:{set value(e){F(l,z,e,`f`)}}.value,parseFn:{set value(e){F(u,K,e,`f`)}}.value,parseContext:{set value(e){F(d,Tr,e,`f`)}}.value}=f,I(this,G,`f`).configObjects=p,I(this,J,`f`).unfreeze(),I(this,Y,`f`).unfreeze(),I(this,L,`f`).unfreeze(),I(this,V,`f`).unfreeze()}[ti](e,t){return In(t,t=>(e(t),t))}getInternalMethods(){return{getCommandInstance:this[ni].bind(this),getContext:this[ri].bind(this),getHasOutput:this[ii].bind(this),getLoggerInstance:this[ai].bind(this),getParseContext:this[oi].bind(this),getParserConfiguration:this[Hr].bind(this),getUsageConfiguration:this[Ur].bind(this),getUsageInstance:this[si].bind(this),getValidationInstance:this[ci].bind(this),hasParseCallback:this[li].bind(this),isGlobalContext:this[ui].bind(this),postProcess:this[di].bind(this),reset:this[pi].bind(this),runValidation:this[hi].bind(this),runYargsParserAndExecuteCommands:this[mi].bind(this),setHasOutput:this[gi].bind(this)}}[ni](){return I(this,L,`f`)}[ri](){return I(this,mr,`f`)}[ii](){return I(this,H,`f`)}[ai](){return I(this,Sr,`f`)}[oi](){return I(this,Tr,`f`)||{}}[si](){return I(this,J,`f`)}[ci](){return I(this,Y,`f`)}[li](){return!!I(this,K,`f`)}[ui](){return I(this,xr,`f`)}[di](e,t,n,r){return n||M(e)?e:(t||(e=this[Ir](e)),(this[Hr]()[`parse-positional-numbers`]||this[Hr]()[`parse-positional-numbers`]===void 0)&&(e=this[Kr](e)),r&&(e=Fn(e,this,I(this,V,`f`).getMiddleware(),!1)),e)}[pi](e={}){F(this,G,I(this,G,`f`)||{},`f`);let t={};t.local=I(this,G,`f`).local||[],t.configObjects=I(this,G,`f`).configObjects||[];let n={};return t.local.forEach(t=>{n[t]=!0,(e[t]||[]).forEach(e=>{n[e]=!0})}),Object.assign(I(this,Dr,`f`),Object.keys(I(this,br,`f`)).reduce((e,t)=>{let r=I(this,br,`f`)[t].filter(e=>!(e in n));return r.length>0&&(e[t]=r),e},{})),F(this,br,{},`f`),[`array`,`boolean`,`string`,`skipValidation`,`count`,`normalize`,`number`,`hiddenOptions`].forEach(e=>{t[e]=(I(this,G,`f`)[e]||[]).filter(e=>!n[e])}),[`narg`,`key`,`alias`,`default`,`defaultDescription`,`config`,`choices`,`demandedOptions`,`demandedCommands`,`deprecatedOptions`].forEach(e=>{t[e]=Kn(I(this,G,`f`)[e],e=>!n[e])}),t.envPrefix=I(this,G,`f`).envPrefix,F(this,G,t,`f`),F(this,J,I(this,J,`f`)?I(this,J,`f`).reset(n):Yn(this,I(this,q,`f`)),`f`),F(this,Y,I(this,Y,`f`)?I(this,Y,`f`).reset(n):or(this,I(this,J,`f`),I(this,q,`f`)),`f`),F(this,L,I(this,L,`f`)?I(this,L,`f`).reset():Bn(I(this,J,`f`),I(this,Y,`f`),I(this,V,`f`),I(this,q,`f`)),`f`),I(this,R,`f`)||F(this,R,tr(this,I(this,J,`f`),I(this,L,`f`),I(this,q,`f`)),`f`),I(this,V,`f`).reset(),F(this,z,null,`f`),F(this,W,``,`f`),F(this,gr,null,`f`),F(this,H,!1,`f`),this.parsed=!1,this}[fi](e,t){return I(this,q,`f`).path.relative(e,t)}[mi](e,t,n,r=0,i=!1){let a=!!n||i;e||=I(this,Or,`f`),I(this,G,`f`).__=I(this,q,`f`).y18n.__,I(this,G,`f`).configuration=this[Hr]();let o=!!I(this,G,`f`).configuration[`populate--`],s=Object.assign({},I(this,G,`f`).configuration,{"populate--":!0}),c=I(this,q,`f`).Parser.detailed(e,Object.assign({},I(this,G,`f`),{configuration:{"parse-positional-numbers":!1,...s}})),l=Object.assign(c.argv,I(this,Tr,`f`)),u,d=c.aliases,f=!1,p=!1;Object.keys(l).forEach(e=>{e===I(this,U,`f`)&&l[e]?f=!0:e===I(this,Pr,`f`)&&l[e]&&(p=!0)}),l.$0=this.$0,this.parsed=c,r===0&&I(this,J,`f`).clearCachedHelpMessage();try{if(this[Wr](),t)return this[di](l,o,!!n,!1);I(this,U,`f`)&&[I(this,U,`f`)].concat(d[I(this,U,`f`)]||[]).filter(e=>e.length>1).includes(``+l._[l._.length-1])&&(l._.pop(),f=!0),F(this,xr,!1,`f`);let s=I(this,L,`f`).getCommands(),m=I(this,R,`f`)?.completionKey?[I(this,R,`f`)?.completionKey,...this.getAliases()[I(this,R,`f`)?.completionKey]??[]].some(e=>Object.prototype.hasOwnProperty.call(l,e)):!1,h=f||m||i;if(l._.length){if(s.length){let e;for(let t=r||0,a;l._[t]!==void 0;t++)if(a=String(l._[t]),s.includes(a)&&a!==I(this,z,`f`)){let e=I(this,L,`f`).runCommand(a,this,c,t+1,i,f||p||i);return this[di](e,o,!!n,!1)}else if(!e&&a!==I(this,z,`f`)){e=a;break}!I(this,L,`f`).hasDefaultCommand()&&I(this,kr,`f`)&&e&&!h&&I(this,Y,`f`).recommendCommands(e,s)}I(this,z,`f`)&&l._.includes(I(this,z,`f`))&&!m&&(I(this,B,`f`)&&qn(!0),this.showCompletionScript(),this.exit(0))}if(I(this,L,`f`).hasDefaultCommand()&&!h){let e=I(this,L,`f`).runCommand(null,this,c,0,i,f||p||i);return this[di](e,o,!!n,!1)}if(m){I(this,B,`f`)&&qn(!0),e=[].concat(e);let t=e.slice(e.indexOf(`--${I(this,R,`f`).completionKey}`)+1);return I(this,R,`f`).getCompletion(t,(e,t)=>{if(e)throw new N(e.message);(t||[]).forEach(e=>{I(this,Sr,`f`).log(e)}),this.exit(0)}),this[di](l,!o,!!n,!1)}if(I(this,H,`f`)||(f?(I(this,B,`f`)&&qn(!0),a=!0,this.showHelp(e=>{I(this,Sr,`f`).log(e),this.exit(0)})):p&&(I(this,B,`f`)&&qn(!0),a=!0,I(this,J,`f`).showVersion(`log`),this.exit(0))),!a&&I(this,G,`f`).skipValidation.length>0&&(a=Object.keys(l).some(e=>I(this,G,`f`).skipValidation.indexOf(e)>=0&&l[e]===!0)),!a){if(c.error)throw new N(c.error.message);if(!m){let e=this[hi](d,{},c.error);n||(u=Fn(l,this,I(this,V,`f`).getMiddleware(),!0)),u=this[ti](e,u??l),M(u)&&!n&&(u=u.then(()=>Fn(l,this,I(this,V,`f`).getMiddleware(),!1)))}}}catch(e){if(e instanceof N)I(this,J,`f`).fail(e.message,e);else throw e}return this[di](u??l,o,!!n,!0)}[hi](e,t,n,r){let i={...this.getDemandedOptions()};return a=>{if(n)throw new N(n.message);I(this,Y,`f`).nonOptionCount(a),I(this,Y,`f`).requiredArguments(a,i);let o=!1;I(this,jr,`f`)&&(o=I(this,Y,`f`).unknownCommands(a)),I(this,Ar,`f`)&&!o?I(this,Y,`f`).unknownArguments(a,e,t,!!r):I(this,Mr,`f`)&&I(this,Y,`f`).unknownArguments(a,e,{},!1,!1),I(this,Y,`f`).limitedChoices(a),I(this,Y,`f`).implications(a),I(this,Y,`f`).conflicting(a)}}[gi](){F(this,H,!0,`f`)}[_i](e){if(typeof e==`string`)I(this,G,`f`).key[e]=!0;else for(let t of e)I(this,G,`f`).key[t]=!0}};function yi(e){return!!e&&typeof e.getInternalMethods==`function`}var bi=Fr(Tn),xi=class{client;enabled;lastBlockReason;serverName;constructor(e){this.enabled=e.enabled,this.client=e.client,this.serverName=e.serverName,b.info(`AccessControlAuthorizer initialized`,{enabled:this.enabled,hasClient:!!this.client,serverName:this.serverName})}getBlockReason(){return this.lastBlockReason?this.lastBlockReason:`MCP server${this.serverName?` '${this.serverName}'`:``} is not authorized for use in your organization and has been blocked by Onyx.`}async isAllowed(){if(!this.enabled)return!0;if(this.client)try{let e=await this.client.authorize();return e.action===`block`?(e.reason?this.lastBlockReason=e.reason:this.lastBlockReason=`MCP server${this.serverName?` '${this.serverName}'`:``} is not authorized for use in your organization and has been blocked by Onyx.`,!1):!0}catch(e){return b.error(`Access control authorization failed with unexpected error`,{error:String(e)}),!0}return b.warn(`No access control client configured, allowing by default`),!0}},Si=class{clientInfoBase64;config;constructor(e){this.config=e,this.clientInfoBase64=this.getClientInfoBase64(),b.info(`AccessControlClient initialized`,{timeoutMs:e.timeoutMs,url:e.url})}async authorize(){try{let e=await this.sendAuthorizeRequest();return b.debug(`Access control check successful`,{action:e.action}),e}catch(e){return b.warn(`Access control check failed, failing open (allowing by default)`,{error:String(e)}),{action:`allow`}}}getClientInfoBase64(){return g(this.config.sessionData)}async sendAuthorizeRequest(){let e=new AbortController,t=setTimeout(()=>e.abort(),this.config.timeoutMs);try{let t=`${this.config.url}/${this.config.apiKey}/mcp/${this.clientInfoBase64}`,n=await fetch(t,{headers:{...this.config.headers},method:`POST`,signal:e.signal});if(!n.ok)throw Error(`Access control service returned ${n.status}: ${n.statusText}`);let r=await n.json();if(!r.action||![`allow`,`block`].includes(r.action))throw Error(`Invalid access control response format: action="${r.action}"`);return r}catch(e){throw e instanceof Error&&e.name===`AbortError`?Error(`Access control check timed out after ${this.config.timeoutMs}ms`):e}finally{clearTimeout(t)}}},Ci=class extends Te{buffer=``;constructor(){super({objectMode:!1})}_flush(e){this.buffer.trim().startsWith(`{`)?e(null,Buffer.from(this.buffer)):e(null,null)}_transform(e,t,n){this.buffer+=e.toString();let r=this.buffer.split(`
|
|
93
93
|
`);this.buffer=r.pop()||``;let i=r.filter(e=>e.trim().startsWith(`{`));if(i.length>0){let e=`${i.join(`
|
|
94
|
-
`)}\n`;n(null,Buffer.from(e))}else n(null,null)}},wi=class{onclose;onerror;onmessage;get pid(){return this._process?.pid??null}get stderr(){return this._stderrStream?this._stderrStream:this._process?.stderr??null}_abortController=new AbortController;_process;_readBuffer=new a;_serverParams;_stderrStream=null;onEvent;constructor(e){this._serverParams=e,(e.stderr===`pipe`||e.stderr===`overlapped`)&&(this._stderrStream=new we),this.onEvent=e.onEvent}async close(){this.onEvent?.({type:`close`}),this._abortController.abort(),this._process=void 0,this._readBuffer.clear()}send(e){return new Promise(t=>{if(!this._process?.stdin)throw Error(`Not connected`);let n=x(e);this._process.stdin.write(n)?t():this._process.stdin.once(`drain`,t)})}async start(){if(this._process)throw Error(`StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.`);return new Promise((e,t)=>{this._process=Ce(this._serverParams.command,this._serverParams.args??[],{cwd:this._serverParams.cwd,env:this._serverParams.env,shell:this._serverParams.shell??!1,signal:this._abortController.signal,stdio:[`pipe`,`pipe`,this._serverParams.stderr??`inherit`]}),this._process.on(`error`,e=>{if(e.name===`AbortError`){this.onclose?.();return}let n=new r(`Process spawn error: ${e.message}`,this._serverParams.command,this._serverParams.args,{cwd:this._serverParams.cwd,errorCode:e.code,errorErrno:e.errno,errorSyscall:e.syscall,shell:this._serverParams.shell});h(n),t(e),this.onerror?.(e)}),this._process.on(`spawn`,()=>{p(`Process spawned successfully`,`transport`,`info`,{argCount:this._serverParams.args?.length,command:this._serverParams.command,pid:this._process?.pid}),e()}),this._process.on(`close`,e=>{this.onEvent?.({type:`close`}),this._process=void 0,this.onclose?.()}),this._process.stdin?.on(`error`,e=>{let t=new u(`Stdin error: ${e.message}`,`stdio`,`write`,{command:this._serverParams.command,pid:this._process?.pid});h(t),this.onEvent?.({error:e,type:`error`}),this.onerror?.(e)});let n=new Ci;this._process.stdout?.pipe(n),n.on(`data`,e=>{this.onEvent?.({chunk:e.toString(),type:`data`}),this._readBuffer.append(e),this.processReadBuffer()}),n.on(`error`,e=>{let t=new u(`JSON filter error: ${e.message}`,`stdio`,`parse`,{command:this._serverParams.command,pid:this._process?.pid});h(t),this.onEvent?.({error:e,type:`error`}),this.onerror?.(e)}),this._stderrStream&&this._process.stderr&&this._process.stderr.pipe(this._stderrStream)})}processReadBuffer(){for(;;)try{let e=this._readBuffer.readMessage();if(e===null)break;this.onEvent?.({message:e,type:`message`}),this.onmessage?.(e)}catch(e){let t=null;try{t=this._readBuffer.readMessage()}catch{}let n=new u(`Message processing error: ${e.message}`,`stdio`,`process`,{command:this._serverParams.command,messageType:t?typeof t:`unknown`,pid:this._process?.pid});h(n),this.onEvent?.({error:e,type:`error`}),this.onerror?.(e)}}};ge.inspect.defaultOptions.depth=8,`EventSource`in global||(global.EventSource=et);const X=await bi(cn(process.argv)).scriptName(`mcp-gateway`).command(`stdio [command] [args...]`,`Run a local command with stdio transport (default)`,e=>e.positional(`command`,{describe:`The command to run`,type:`string`}).positional(`args`,{array:!0,describe:`The arguments to pass to the command`,type:`string`})).command(`remote`,`Connect to a remote MCP server`,e=>e.options({headers:{describe:`Headers for remote authentication (format: key:value)`,string:!0,type:`array`},"remote-transport":{choices:[`sse`,`stream`],default:`sse`,describe:`The transport type for remote connection (sse or stream)`,type:`string`},url:{demandOption:!0,describe:`The URL of the remote MCP server`,type:`string`}})).command(`$0 [command] [args...]`,`Run a command with MCP arguments (backward compatible)`,e=>e.positional(`command`,{describe:`The command to run`,type:`string`}).positional(`args`,{array:!0,describe:`The arguments to pass to the command`,type:`string`})).env(`MCP_GATEWAY`).parserConfiguration({"populate--":!0}).options({debug:{default:!1,describe:`Enable debug logging`,type:`boolean`},env:{describe:`Environment variables to pass to the command (format: KEY=value)`,string:!0,type:`array`},gracefulShutdownTimeout:{default:5e3,describe:`The timeout (in milliseconds) for graceful shutdown`,type:`number`},port:{describe:`Run as HTTP server on the specified port instead of stdio`,type:`number`},shell:{default:!1,describe:`Spawn the server via the user's shell`,type:`boolean`}}).help().parseAsync();let Z,Q,Ti,$,Ei;const Di={};if(X.headers)for(let e of X.headers){let[t,...n]=e.split(`:`);t&&n.length>0&&(Di[t.trim()]=n.join(`:`).trim())}const Oi={..._.scanner.headers};if(b.debug(`Initializing traffic scanner`,{failOpen:_.scanner.failOpen,hasApiKey:!!_.scanner.apiKey,scannerEnabled:_.scanner.enabled,scannerUrl:_.scanner.url,timeoutMs:_.scanner.timeoutMs}),X._[0]===`remote`){if(Z=`remote`,$=X.url,Ei=X[`remote-transport`]||`sse`,!$)throw new n(`Remote URL is required for remote proxy type`,`url`,{transport:Ei})}else{if(Z=`stdio`,X[`--`]&&X[`--`].length>0){let e=X[`--`];Q=e[0],Ti=e.slice(1)}else Q=X.command,Ti=X.args||[];if(!Q)throw new n(`No command specified for stdio proxy`,`command`)}const ki={};if(X.env)for(let e of X.env){let[t,...n]=e.split(`=`);t&&n.length>0&&(ki[t.trim()]=n.join(`=`).trim())}let Ai;if(_.accessControl.url&&_.scanner.apiKey){let e=await ee(),t=Z===`stdio`?{...e,proxyType:`stdio`,stdioCliArgs:{args:Ti,command:Q,proxyType:`stdio`}}:{...e,proxyType:`remote`,remoteCliArgs:{proxyType:`remote`,url:$}};Ai=new Si({apiKey:_.scanner.apiKey,headers:_.accessControl.headers,sessionData:t,timeoutMs:_.accessControl.timeoutMs,url:_.accessControl.url})}const ji=new xi({client:Ai,enabled:_.accessControl.enabled}),
|
|
95
|
-
❌ ACCESS DENIED`),console.error(`━`.repeat(60)),console.error(
|
|
94
|
+
`)}\n`;n(null,Buffer.from(e))}else n(null,null)}},wi=class{onclose;onerror;onmessage;get pid(){return this._process?.pid??null}get stderr(){return this._stderrStream?this._stderrStream:this._process?.stderr??null}_abortController=new AbortController;_process;_readBuffer=new a;_serverParams;_stderrStream=null;onEvent;constructor(e){this._serverParams=e,(e.stderr===`pipe`||e.stderr===`overlapped`)&&(this._stderrStream=new we),this.onEvent=e.onEvent}async close(){this.onEvent?.({type:`close`}),this._abortController.abort(),this._process=void 0,this._readBuffer.clear()}send(e){return new Promise(t=>{if(!this._process?.stdin)throw Error(`Not connected`);let n=x(e);this._process.stdin.write(n)?t():this._process.stdin.once(`drain`,t)})}async start(){if(this._process)throw Error(`StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.`);return new Promise((e,t)=>{this._process=Ce(this._serverParams.command,this._serverParams.args??[],{cwd:this._serverParams.cwd,env:this._serverParams.env,shell:this._serverParams.shell??!1,signal:this._abortController.signal,stdio:[`pipe`,`pipe`,this._serverParams.stderr??`inherit`]}),this._process.on(`error`,e=>{if(e.name===`AbortError`){this.onclose?.();return}let n=new r(`Process spawn error: ${e.message}`,this._serverParams.command,this._serverParams.args,{cwd:this._serverParams.cwd,errorCode:e.code,errorErrno:e.errno,errorSyscall:e.syscall,shell:this._serverParams.shell});h(n),t(e),this.onerror?.(e)}),this._process.on(`spawn`,()=>{p(`Process spawned successfully`,`transport`,`info`,{argCount:this._serverParams.args?.length,command:this._serverParams.command,pid:this._process?.pid}),e()}),this._process.on(`close`,e=>{this.onEvent?.({type:`close`}),this._process=void 0,this.onclose?.()}),this._process.stdin?.on(`error`,e=>{let t=new u(`Stdin error: ${e.message}`,`stdio`,`write`,{command:this._serverParams.command,pid:this._process?.pid});h(t),this.onEvent?.({error:e,type:`error`}),this.onerror?.(e)});let n=new Ci;this._process.stdout?.pipe(n),n.on(`data`,e=>{this.onEvent?.({chunk:e.toString(),type:`data`}),this._readBuffer.append(e),this.processReadBuffer()}),n.on(`error`,e=>{let t=new u(`JSON filter error: ${e.message}`,`stdio`,`parse`,{command:this._serverParams.command,pid:this._process?.pid});h(t),this.onEvent?.({error:e,type:`error`}),this.onerror?.(e)}),this._stderrStream&&this._process.stderr&&this._process.stderr.pipe(this._stderrStream)})}processReadBuffer(){for(;;)try{let e=this._readBuffer.readMessage();if(e===null)break;this.onEvent?.({message:e,type:`message`}),this.onmessage?.(e)}catch(e){let t=null;try{t=this._readBuffer.readMessage()}catch{}let n=new u(`Message processing error: ${e.message}`,`stdio`,`process`,{command:this._serverParams.command,messageType:t?typeof t:`unknown`,pid:this._process?.pid});h(n),this.onEvent?.({error:e,type:`error`}),this.onerror?.(e)}}};ge.inspect.defaultOptions.depth=8,`EventSource`in global||(global.EventSource=et);const X=await bi(cn(process.argv)).scriptName(`mcp-gateway`).command(`stdio [command] [args...]`,`Run a local command with stdio transport (default)`,e=>e.positional(`command`,{describe:`The command to run`,type:`string`}).positional(`args`,{array:!0,describe:`The arguments to pass to the command`,type:`string`})).command(`remote`,`Connect to a remote MCP server`,e=>e.options({headers:{describe:`Headers for remote authentication (format: key:value)`,string:!0,type:`array`},"remote-transport":{choices:[`sse`,`stream`],default:`sse`,describe:`The transport type for remote connection (sse or stream)`,type:`string`},url:{demandOption:!0,describe:`The URL of the remote MCP server`,type:`string`}})).command(`$0 [command] [args...]`,`Run a command with MCP arguments (backward compatible)`,e=>e.positional(`command`,{describe:`The command to run`,type:`string`}).positional(`args`,{array:!0,describe:`The arguments to pass to the command`,type:`string`})).env(`MCP_GATEWAY`).parserConfiguration({"populate--":!0}).options({debug:{default:!1,describe:`Enable debug logging`,type:`boolean`},env:{describe:`Environment variables to pass to the command (format: KEY=value)`,string:!0,type:`array`},gracefulShutdownTimeout:{default:5e3,describe:`The timeout (in milliseconds) for graceful shutdown`,type:`number`},port:{describe:`Run as HTTP server on the specified port instead of stdio`,type:`number`},shell:{default:!1,describe:`Spawn the server via the user's shell`,type:`boolean`}}).help().parseAsync();let Z,Q,Ti,$,Ei;const Di={};if(X.headers)for(let e of X.headers){let[t,...n]=e.split(`:`);t&&n.length>0&&(Di[t.trim()]=n.join(`:`).trim())}const Oi={..._.scanner.headers};if(b.debug(`Initializing traffic scanner`,{failOpen:_.scanner.failOpen,hasApiKey:!!_.scanner.apiKey,scannerEnabled:_.scanner.enabled,scannerUrl:_.scanner.url,timeoutMs:_.scanner.timeoutMs}),X._[0]===`remote`){if(Z=`remote`,$=X.url,Ei=X[`remote-transport`]||`sse`,!$)throw new n(`Remote URL is required for remote proxy type`,`url`,{transport:Ei})}else{if(Z=`stdio`,X[`--`]&&X[`--`].length>0){let e=X[`--`];Q=e[0],Ti=e.slice(1)}else Q=X.command,Ti=X.args||[];if(!Q)throw new n(`No command specified for stdio proxy`,`command`)}const ki={};if(X.env)for(let e of X.env){let[t,...n]=e.split(`=`);t&&n.length>0&&(ki[t.trim()]=n.join(`=`).trim())}let Ai;if(_.accessControl.url&&_.scanner.apiKey){let e=await ee(),t=Z===`stdio`?{...e,proxyType:`stdio`,stdioCliArgs:{args:Ti,command:Q,proxyType:`stdio`}}:{...e,proxyType:`remote`,remoteCliArgs:{proxyType:`remote`,url:$}};Ai=new Si({apiKey:_.scanner.apiKey,headers:_.accessControl.headers,sessionData:t,timeoutMs:_.accessControl.timeoutMs,url:_.accessControl.url})}const ji=Z===`remote`?$:Q,Mi=new xi({client:Ai,enabled:_.accessControl.enabled,serverName:ji}),Ni=async t=>{if(!await Mi.isAllowed()){let t=Mi.getBlockReason();throw b.warn(`MCP server blocked by access control`,{proxyType:Z,reason:t}),new e(t,`policy_block`)}if(b.info(`MCP server allowed by access control`),Z===`stdio`){let e={...process.env,...ki},n=new wi({args:Ti,command:Q,env:e,onEvent:e=>{X.debug&&b.debug(`Transport event`,{event:e})},shell:X.shell,stderr:`inherit`});try{await t.connect(n)}catch(e){throw new i(`Failed to connect to stdio process: ${e}`,void 0,`stdio`,{argCount:Ti?.length,command:Q})}}else if(Z===`remote`){let e,n=Object.keys(Di).length>0?{headers:Di}:void 0;try{e=Ei===`sse`?new o(new URL($),{requestInit:n}):new l(new URL($),{requestInit:n}),await t.connect(e)}catch(e){throw new i(`Failed to connect to remote server: ${e}`,$,Ei,{headerCount:Object.keys(Di).length})}}},Pi=async()=>{if(X.port){await te({cliArgs:Z===`stdio`?{args:Ti,command:Q,proxyType:Z}:{proxyType:Z,url:$},scanApiKey:_.scanner.apiKey,scanEnabled:_.scanner.enabled,scanFailOpen:_.scanner.failOpen,scanHeaders:Oi,scanTimeoutMs:_.scanner.timeoutMs,scanUrl:_.scanner.url||``});let e,n=await S({createServer:async()=>{e=new t({name:`mcp-gateway`,version:_.appVersion},{capabilities:{}}),await Ni(e);let n=e.getServerVersion(),r=e.getServerCapabilities(),i=new s(n,{capabilities:r});return ne({authorizer:Mi,client:e,server:i,serverCapabilities:r}),i},onClose:async t=>{e&&await e.close(),await t.close()},port:X.port});return b.info(`MCP gateway started as HTTP server`,{port:X.port,proxyType:Z}),Z===`stdio`?b.info(`Running command`,{args:Ti?.join(` `)||``,command:Q}):b.info(`Connected to remote server`,{remoteTransport:Ei,remoteUrl:$}),{close:()=>n.close()}}let e=new t({name:`mcp-gateway`,version:_.appVersion},{capabilities:{}});await Ni(e);let n=e.getServerVersion(),r=e.getServerCapabilities(),i=new s(n,{capabilities:r});ne({authorizer:Mi,client:e,server:i,serverCapabilities:r});let a=new c;return await te({cliArgs:Z===`stdio`?{args:Ti,command:Q,proxyType:Z}:{proxyType:Z,url:$},scanApiKey:_.scanner.apiKey,scanEnabled:_.scanner.enabled,scanFailOpen:_.scanner.failOpen,scanHeaders:Oi,scanTimeoutMs:_.scanner.timeoutMs,scanUrl:_.scanner.url||``}),await i.connect(a),b.info(`MCP gateway started`,{proxyType:Z}),Z===`stdio`?b.info(`Running command`,{args:Ti?.join(` `)||``,command:Q}):b.info(`Connected to remote server`,{remoteTransport:Ei,remoteUrl:$}),{close:()=>e.close()}},Fi=({server:e,timeout:t})=>{let n=async()=>{b.info(`Received shutdown signal; shutting down`);try{await e.close(),process.exit(0)}catch(e){let n=`Error during shutdown: ${e}`;b.error(`Error during shutdown`,{error:n}),h(e instanceof Error?e:Error(n),{shutdownTimeout:t},{feature:`shutdown`,module:`cli`,operation:`close`}),process.exit(1)}},r=async()=>{C(()=>{b.error(`Graceful shutdown timeout exceeded, forcing exit`),process.exit(1)},t).unref(),await n()};return process.once(`SIGTERM`,r),process.once(`SIGINT`,r),()=>e.close()};await(async()=>{y(),m({"proxy.mode":Z===`stdio`?`local`:`remote`,"proxy.transport":Z===`remote`?Ei||`unknown`:`stdio`,"proxy.type":Z}),p(`MCP Gateway starting`,`lifecycle`,`info`,{command:Q,proxyType:Z,transport:Ei,url:$});try{let e=await Pi();Fi({server:e,timeout:X.gracefulShutdownTimeout})}catch(t){if(t instanceof e){console.error(`
|
|
95
|
+
❌ ACCESS DENIED`),console.error(`━`.repeat(60)),console.error(`
|
|
96
|
+
This MCP server has been blocked by Onyx because it is not authorized by your organization's access control policy. Please contact your administrator if you believe this is an error.
|
|
96
97
|
`),b.error(`MCP server blocked by access control policy`,{error:t.message,reason:t.reason}),C(()=>{process.exit(1)},1e3);return}let n=`Could not start the proxy: ${t}`;b.error(`Unhandled error occurred`,{error:n}),t instanceof Error?h(t,{args:Ti,command:Q,proxyType:Z,transport:Ei,url:$},{feature:`startup`,module:`cli`,operation:`initialize`,proxyType:Z,transport:Z===`remote`?Ei||`unknown`:`stdio`}):h(Error(n),{command:Q,originalError:String(t),proxyType:Z},{feature:`startup`,module:`cli`,operation:`initialize`}),C(()=>{process.exit(1)},1e3)}})();export{};
|
|
97
98
|
//# sourceMappingURL=mcp-gateway.js.map
|