@zuplo/cli 6.73.28 → 6.73.29
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/node_modules/@zuplo/core/customer.cli.minified.js +1 -1
- package/node_modules/@zuplo/core/index.minified.js +1 -1
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-KO2ULO4I.js +405 -0
- package/node_modules/@zuplo/runtime/out/esm/chunk-KO2ULO4I.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/types/index.d.ts +144 -1
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/package.json +6 -6
- package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js +0 -405
- package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js.map +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-GWEFPK3R.js.LEGAL.txt → chunk-KO2ULO4I.js.LEGAL.txt} +0 -0
|
@@ -572,7 +572,7 @@ globstar while`,s,de,o,se,Xe),this.matchOne(s.slice(de),o.slice(se),f))return th
|
|
|
572
572
|
`),stderr:x.join(`
|
|
573
573
|
`),exitCode:A},"Tar process logs")}}t(_Zt,"tarFolder");async function pZt({tarFilePath:s,outputDir:o,logger:f}){let d=[],y=[],x;try{await new Promise((A,F)=>{let W=hit("sh",["-c",`tar -xvf ${s} -C ${o};`]);W.stdout.on("data",G=>{let be=G.toString().trim();be.length>0&&d.push(be.trim())}),W.stderr.on("data",G=>{let be=G.toString().trim();be.length>0&&y.push(be.trim())}),W.on("close",G=>{x=G,G===0?A():F(new Error(`tar process exited with code ${G}`))}),W.on("error",G=>{F(G)})})}catch(A){throw new Error("Failed to untar file",{cause:A})}finally{f.info({stdout:d.join(`
|
|
574
574
|
`),stderr:y.join(`
|
|
575
|
-
`),exitCode:x},"Untar process logs")}}t(pZt,"untarFile");async function dZt(s){if(await sAe(s))return await XN.rm(s,{recursive:!0})}t(dZt,"deleteFolder");var eu=aAe;var Tlt=Pp(Ust(),1);var zst=["ai-gateway-auth-v2","ai-gateway-configuration-executor-v2","ai-gateway-fallback-model-v2","ai-gateway-model-filtering-v2","ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2","akamai-ai-firewall","akamai-ai-firewall-v2","akamai-firewall-for-ai","comet-opik-tracing-v2","galileo-tracing-v2","prompt-injection","semantic-cache"];var HV=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(s,o,f,d,y,x){this.type=s,this.name=o,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},zer=/[$_\p{ID_Start}]/u,$er=/[$_\u200C\u200D\p{ID_Continue}]/u,UAe=".*";function Jer(s,o){return(o?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(s)}t(Jer,"Re");function Wst(s,o=!1){let f=[],d=0;for(;d<s.length;){let y=s[d],x=t(function(A){if(!o)throw new TypeError(A);f.push({type:"INVALID_CHAR",index:d,value:s[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:s[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:s[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:s[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:s[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:s[d++]});continue}if(y===":"){let A="",F=d+1;for(;F<s.length;){let W=s.substr(F,1);if(F===d+1&&zer.test(W)||F!==d+1&&$er.test(W)){A+=s[F++];continue}break}if(!A){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:A}),d=F;continue}if(y==="("){let A=1,F="",W=d+1,G=!1;if(s[W]==="?"){x(`Pattern cannot start with "?" at ${W}`);continue}for(;W<s.length;){if(!Jer(s[W],!1)){x(`Invalid character '${s[W]}' at ${W}.`),G=!0;break}if(s[W]==="\\"){F+=s[W++]+s[W++];continue}if(s[W]===")"){if(A--,A===0){W++;break}}else if(s[W]==="("&&(A++,s[W+1]!=="?")){x(`Capturing groups are not allowed at ${W}`),G=!0;break}F+=s[W++]}if(G)continue;if(A){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=W;continue}f.push({type:"CHAR",index:d,value:s[d++]})}return f.push({type:"END",index:d,value:""}),f}t(Wst,"v");function qst(s,o={}){let f=Wst(s);o.delimiter??="/#?",o.prefixes??="./";let d=`[^${fT(o.delimiter)}]+?`,y=[],x=0,A=0,F="",W=new Set,G=t(wn=>{if(A<f.length&&f[A].type===wn)return f[A++].value},"a"),be=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(wn=>{let sn=G(wn);if(sn!==void 0)return sn;let{type:Jn,index:kr}=f[A];throw new TypeError(`Unexpected ${Jn} at ${kr}, expected ${wn}`)},"d"),se=t(()=>{let wn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)wn+=sn;return wn},"T"),Xe=t(wn=>wn,"Se"),Ue=o.encodePart||Xe,je="",Vt=t(wn=>{je+=wn},"U"),Ut=t(()=>{je.length&&(y.push(new HV(3,"","",Ue(je),"",3)),je="")},"$"),Ir=t((wn,sn,Jn,kr,yr)=>{let xs=3;switch(yr){case"?":xs=1;break;case"*":xs=0;break;case"+":xs=2;break}if(!sn&&!Jn&&xs===3){Vt(wn);return}if(Ut(),!sn&&!Jn){if(!wn)return;y.push(new HV(3,"","",Ue(wn),"",xs));return}let bi;Jn?Jn==="*"?bi=UAe:bi=Jn:bi=d;let fc=2;bi===d?(fc=1,bi=""):bi===UAe&&(fc=0,bi="");let Ci;if(sn?Ci=sn:Jn&&(Ci=x++),W.has(Ci))throw new TypeError(`Duplicate name '${Ci}'.`);W.add(Ci),y.push(new HV(fc,Ci,Ue(wn),bi,Ue(kr),xs))},"V");for(;A<f.length;){let wn=G("CHAR"),sn=G("NAME"),Jn=G("REGEX");if(!sn&&!Jn&&(Jn=G("ASTERISK")),sn||Jn){let yr=wn??"";o.prefixes.indexOf(yr)===-1&&(Vt(yr),yr=""),Ut();let xs=be();Ir(yr,sn,Jn,"",xs);continue}let kr=wn??G("ESCAPED_CHAR");if(kr){Vt(kr);continue}if(G("OPEN")){let yr=se(),xs=G("NAME"),bi=G("REGEX");!xs&&!bi&&(bi=G("ASTERISK"));let fc=se();de("CLOSE");let Ci=be();Ir(yr,xs,bi,fc,Ci);continue}Ut(),de("END")}return y}t(qst,"D");function fT(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(fT,"S");function $st(s){return s&&s.ignoreCase?"ui":"u"}t($st,"X");function Wer(s,o,f){return Vst(qst(s,f),o,f)}t(Wer,"Z");function Q9(s){switch(s){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(Q9,"k");function Vst(s,o,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of s){if(F.type===3){F.modifier===3?d+=fT(F.value):d+=`(?:${fT(F.value)})${Q9(F.modifier)}`;continue}o&&o.push(F.name);let W=`[^${fT(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=W:F.type===0&&(G=UAe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${Q9(F.modifier)}`:d+=`((?:${G})${Q9(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${fT(F.prefix)}(${G})${fT(F.suffix)})`,d+=Q9(F.modifier);continue}d+=`(?:${fT(F.prefix)}`,d+=`((?:${G})(?:`,d+=fT(F.suffix),d+=fT(F.prefix),d+=`(?:${G}))*)${fT(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${fT(f.endsWith)}]|$`,x=`[${fT(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,$st(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let A=!1;if(s.length){let F=s[s.length-1];F.type===3&&F.modifier===3&&(A=f.delimiter.indexOf(F)>-1)}return A||(d+=`(?=${x}|${y})`),new RegExp(d,$st(f))}t(Vst,"F");var tI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},qer={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Ver={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Her(s,o){return s.length?s[0]==="/"?!0:!o||s.length<2?!1:(s[0]=="\\"||s[0]=="{")&&s[1]=="/":!1}t(Her,"J");function Hst(s,o){return s.startsWith(o)?s.substring(o.length,s.length):s}t(Hst,"Q");function Ger(s,o){return s.endsWith(o)?s.substr(0,s.length-o.length):s}t(Ger,"Ee");function Gst(s){return!s||s.length<2?!1:s[0]==="["||(s[0]==="\\"||s[0]==="{")&&s[1]==="["}t(Gst,"W");var Yst=["ftp","file","http","https","ws","wss"];function Kst(s){if(!s)return!0;for(let o of Yst)if(s.test(o))return!0;return!1}t(Kst,"N");function Yer(s,o){if(s=Hst(s,"#"),o||s==="")return s;let f=new URL("https://example.com");return f.hash=s,f.hash?f.hash.substring(1,f.hash.length):""}t(Yer,"te");function Ker(s,o){if(s=Hst(s,"?"),o||s==="")return s;let f=new URL("https://example.com");return f.search=s,f.search?f.search.substring(1,f.search.length):""}t(Ker,"re");function Xer(s,o){return o||s===""?s:Gst(s)?Qst(s):Zst(s)}t(Xer,"ne");function Zer(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.password=s,f.password}t(Zer,"se");function Qer(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.username=s,f.username}t(Qer,"ie");function etr(s,o,f){if(f||s==="")return s;if(o&&!Yst.includes(o))return new URL(`${o}:${s}`).pathname;let d=s[0]=="/";return s=new URL(d?s:"/-"+s,"https://example.com").pathname,d||(s=s.substring(2,s.length)),s}t(etr,"ae");function ttr(s,o,f){return Xst(o)===s&&(s=""),f||s===""?s:eat(s)}t(ttr,"oe");function rtr(s,o){return s=Ger(s,":"),o||s===""?s:zAe(s)}t(rtr,"ce");function Xst(s){switch(s){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(Xst,"_");function zAe(s){if(s==="")return s;if(/^[-+.A-Za-z0-9]*$/.test(s))return s.toLowerCase();throw new TypeError(`Invalid protocol '${s}'.`)}t(zAe,"y");function ntr(s){if(s==="")return s;let o=new URL("https://example.com");return o.username=s,o.username}t(ntr,"le");function itr(s){if(s==="")return s;let o=new URL("https://example.com");return o.password=s,o.password}t(itr,"fe");function Zst(s){if(s==="")return s;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(s))throw new TypeError(`Invalid hostname '${s}'`);let o=new URL("https://example.com");return o.hostname=s,o.hostname}t(Zst,"z");function Qst(s){if(s==="")return s;if(/[^0-9a-fA-F[\]:]/g.test(s))throw new TypeError(`Invalid IPv6 hostname '${s}'`);return s.toLowerCase()}t(Qst,"j");function eat(s){if(s===""||/^[0-9]*$/.test(s)&&parseInt(s)<=65535)return s;throw new TypeError(`Invalid port '${s}'.`)}t(eat,"K");function str(s){if(s==="")return s;let o=new URL("https://example.com");return o.pathname=s[0]!=="/"?"/-"+s:s,s[0]!=="/"?o.pathname.substring(2,o.pathname.length):o.pathname}t(str,"he");function atr(s){return s===""?s:new URL(`data:${s}`).pathname}t(atr,"ue");function otr(s){if(s==="")return s;let o=new URL("https://example.com");return o.search=s,o.search.substring(1,o.search.length)}t(otr,"de");function ctr(s){if(s==="")return s;let o=new URL("https://example.com");return o.hash=s,o.hash.substring(1,o.hash.length)}t(ctr,"pe");var ltr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#m=0;#c=0;#u=0;#f=0;#p=!1;constructor(s){this.#e=s}get result(){return this.#t}parse(){for(this.#n=Wst(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#c===0){this.#o(),this.#g()?this.#a(9,1):this.#E()?this.#a(8,1):this.#a(7,0);continue}else if(this.#c===2){this.#h(5);continue}this.#a(10,0);break}if(this.#u>0)if(this.#l())this.#u-=1;else continue;if(this.#A()){this.#u+=1;continue}switch(this.#c){case 0:this.#y()&&this.#h(1);break;case 1:if(this.#y()){this.#D();let s=7,o=1;this.#b()?(s=2,o=3):this.#p&&(s=2),this.#a(s,o)}break;case 2:this.#v()?this.#h(3):(this.#S()||this.#E()||this.#g())&&this.#h(5);break;case 3:this.#C()?this.#a(4,1):this.#v()&&this.#a(5,1);break;case 4:this.#v()&&this.#a(5,1);break;case 5:this.#O()?this.#f+=1:this.#N()&&(this.#f-=1),this.#k()&&!this.#f?this.#a(6,1):this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 6:this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 7:this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 8:this.#g()&&this.#a(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#a(s,o){switch(this.#c){case 0:break;case 1:this.#t.protocol=this.#w();break;case 2:break;case 3:this.#t.username=this.#w();break;case 4:this.#t.password=this.#w();break;case 5:this.#t.hostname=this.#w();break;case 6:this.#t.port=this.#w();break;case 7:this.#t.pathname=this.#w();break;case 8:this.#t.search=this.#w();break;case 9:this.#t.hash=this.#w();break;case 10:break}this.#c!==0&&s!==10&&([1,2,3,4].includes(this.#c)&&[6,7,8,9].includes(s)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#c)&&[8,9].includes(s)&&(this.#t.pathname??=this.#p?"/":""),[1,2,3,4,5,6,7].includes(this.#c)&&s===9&&(this.#t.search??="")),this.#i(s,o)}#i(s,o){this.#c=s,this.#m=this.#r+o,this.#r+=o,this.#s=0}#o(){this.#r=this.#m,this.#s=0}#h(s){this.#o(),this.#c=s}#d(s){return s<0&&(s=this.#n.length-s),s<this.#n.length?this.#n[s]:this.#n[this.#n.length-1]}#_(s,o){let f=this.#d(s);return f.value===o&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#y(){return this.#_(this.#r,":")}#b(){return this.#_(this.#r+1,"/")&&this.#_(this.#r+2,"/")}#v(){return this.#_(this.#r,"@")}#C(){return this.#_(this.#r,":")}#k(){return this.#_(this.#r,":")}#S(){return this.#_(this.#r,"/")}#E(){if(this.#_(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let s=this.#d(this.#r-1);return s.type!=="NAME"&&s.type!=="REGEX"&&s.type!=="CLOSE"&&s.type!=="ASTERISK"}#g(){return this.#_(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#_(this.#r,"[")}#N(){return this.#_(this.#r,"]")}#w(){let s=this.#n[this.#r],o=this.#d(this.#m).index;return this.#e.substring(o,s.index)}#D(){let s={};Object.assign(s,tI),s.encodePart=zAe;let o=Wer(this.#w(),void 0,s);this.#p=Kst(o)}},BAe=["protocol","username","password","hostname","port","pathname","search","hash"],eI="*";function Jst(s,o){if(typeof s!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(s,o);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(Jst,"ge");function qP(s,o){return o?VV(s):s}t(qP,"b");function qV(s,o,f){let d;if(typeof o.baseURL=="string")try{d=new URL(o.baseURL),o.protocol===void 0&&(s.protocol=qP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&(s.username=qP(d.username,f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&o.password===void 0&&(s.password=qP(d.password,f)),o.protocol===void 0&&o.hostname===void 0&&(s.hostname=qP(d.hostname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&(s.port=qP(d.port,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&(s.pathname=qP(d.pathname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&(s.search=qP(d.search.substring(1,d.search.length),f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&o.hash===void 0&&(s.hash=qP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${o.baseURL}'.`)}if(typeof o.protocol=="string"&&(s.protocol=rtr(o.protocol,f)),typeof o.username=="string"&&(s.username=Qer(o.username,f)),typeof o.password=="string"&&(s.password=Zer(o.password,f)),typeof o.hostname=="string"&&(s.hostname=Xer(o.hostname,f)),typeof o.port=="string"&&(s.port=ttr(o.port,s.protocol,f)),typeof o.pathname=="string"){if(s.pathname=o.pathname,d&&!Her(s.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(s.pathname=qP(d.pathname.substring(0,y+1),f)+s.pathname)}s.pathname=etr(s.pathname,s.protocol,f)}return typeof o.search=="string"&&(s.search=Ker(o.search,f)),typeof o.hash=="string"&&(s.hash=Yer(o.hash,f)),s}t(qV,"w");function VV(s){return s.replace(/([+*?:{}()\\])/g,"\\$1")}t(VV,"C");function utr(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(utr,"Oe");function ftr(s,o){o.delimiter??="/#?",o.prefixes??="./",o.sensitive??=!1,o.strict??=!1,o.end??=!0,o.start??=!0,o.endsWith="";let f=".*",d=`[^${utr(o.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let A=0;A<s.length;++A){let F=s[A];if(F.type===3){if(F.modifier===3){x+=VV(F.value);continue}x+=`{${VV(F.value)}}${Q9(F.modifier)}`;continue}let W=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!o.prefixes.includes(F.prefix)),be=A>0?s[A-1]:null,de=A<s.length-1?s[A+1]:null;if(!G&&W&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let se=de.value.length>0?de.value[0]:"";G=y.test(se)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&be&&be.type===3){let se=be.value[be.value.length-1];G=o.prefixes.includes(se)}G&&(x+="{"),x+=VV(F.prefix),W&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?W||(x+=`(${d})`):F.type===0&&(!W&&(!be||be.type===3||be.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&W&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=VV(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=Q9(F.modifier))}return x}t(ftr,"ke");var tat=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#m=!1;constructor(s={},o,f){try{let d;if(typeof o=="string"?d=o:f=o,typeof s=="string"){let F=new ltr(s);if(F.parse(),s=F.result,d===void 0&&typeof s.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");s.baseURL=d}else{if(!s||typeof s!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:eI,protocol:eI,username:eI,password:eI,hostname:eI,port:eI,search:eI,hash:eI};this.#e=qV(x,s,!0),Xst(this.#e.protocol)===this.#e.port&&(this.#e.port="");let A;for(A of BAe){if(!(A in this.#e))continue;let F={},W=this.#e[A];switch(this.#t[A]=[],A){case"protocol":Object.assign(F,tI),F.encodePart=zAe;break;case"username":Object.assign(F,tI),F.encodePart=ntr;break;case"password":Object.assign(F,tI),F.encodePart=itr;break;case"hostname":Object.assign(F,qer),Gst(W)?F.encodePart=Qst:F.encodePart=Zst;break;case"port":Object.assign(F,tI),F.encodePart=eat;break;case"pathname":Kst(this.#n.protocol)?(Object.assign(F,Ver,y),F.encodePart=str):(Object.assign(F,tI,y),F.encodePart=atr);break;case"search":Object.assign(F,tI,y),F.encodePart=otr;break;case"hash":Object.assign(F,tI,y),F.encodePart=ctr;break}try{this.#s[A]=qst(W,F),this.#n[A]=Vst(this.#s[A],this.#t[A],F),this.#r[A]=ftr(this.#s[A],F),this.#m=this.#m||this.#s[A].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${A} pattern '${this.#e[A]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return!1;try{typeof s=="object"?f=qV(f,s,!1):f=qV(f,Jst(s,o),!1)}catch{return!1}let d;for(d of BAe)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return;try{typeof s=="object"?f=qV(f,s,!1):f=qV(f,Jst(s,o),!1)}catch{return null}let d={};o?d.inputs=[s,o]:d.inputs=[s];let y;for(y of BAe){let x=this.#n[y].exec(f[y]);if(!x)return null;let A={};for(let[F,W]of this.#t[y].entries())if(typeof W=="string"||typeof W=="number"){let G=x[F+1];A[W]=G}d[y]={input:f[y]??"",groups:A}}return d}static compareComponent(s,o,f){let d=t((F,W)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<W[G])return-1;if(F[G]!==W[G])return 1}return 0},"o"),y=new HV(3,"","","","",3),x=new HV(0,"","","","",3),A=t((F,W)=>{let G=0;for(;G<Math.min(F.length,W.length);++G){let be=d(F[G],W[G]);if(be)return be}return F.length===W.length?0:d(F[G]??y,W[G]??y)},"s");return!o.#r[s]&&!f.#r[s]?0:o.#r[s]&&!f.#r[s]?A(o.#s[s],[x]):!o.#r[s]&&f.#r[s]?A([x],f.#s[s]):A(o.#s[s],f.#s[s])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#m}};globalThis.URLPattern||(globalThis.URLPattern=tat);import{AssertionError as _tr}from"node:assert";function VP(s,o){if(s===!1)throw new _tr({message:o})}t(VP,"assert");var Wo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(Wo||(Wo={}));function eM(s){return s.type===Wo.Object}t(eM,"isAstObject");function HP(s){return s.type===Wo.Property}t(HP,"isAstProperty");function $Ae(s){return s.type===Wo.Array}t($Ae,"isAstArray");function SO(s){return s.type===Wo.Literal}t(SO,"isAstLiteral");function rI(s){if(s===void 0)throw new Error("Node is undefined");if(!eM(s))throw new Error("Node is not object")}t(rI,"assertAstObject");import{findNodeAtLocation as ptr,getNodeValue as dtr,printParseErrorCode as mtr,visit as htr}from"jsonc-parser";var gtr={DEFAULT:{allowTrailingComma:!1}};function GV(s,o=[],f=gtr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(W){d.type==="property"&&(d.length=W-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(W){return d.children?.push(W),W}t(x,"onValue"),htr(s,{onObjectBegin:t((W,G,be)=>{d=x({type:"object",offset:W,length:-1,line:G+1,column:be+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((W,G,be,de,se)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:W,offset:G,length:be,line:de,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((W,G)=>{y(W+G),d.length=W+G-d.offset,d=d.parent,y(W+G)},"onObjectEnd"),onArrayBegin:t((W,G,be,de)=>{d=x({type:"array",offset:W,length:-1,line:be+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((W,G)=>{d.length=W+G-d.offset,d=d.parent,y(W+G)},"onArrayEnd"),onLiteralValue:t((W,G,be,de,se)=>{x({type:ytr(W),offset:G,length:be,line:de+1,column:se+1,parent:d,value:W}),y(G+be)},"onLiteralValue"),onSeparator:t((W,G)=>{d.type==="property"&&(W===":"?d.colonOffset=G:W===","&&y(G))},"onSeparator"),onError:t((W,G,be,de,se)=>{o.push({error:W,offset:G,length:be,line:de+1,column:se+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(GV,"parse");function ytr(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t(ytr,"getNodeType");function JAe(s,o){return ptr(s,o)}t(JAe,"findNodeAtLocation");function YV(s){return dtr(s)}t(YV,"getNodeValue");function rat(s){return mtr(s)}t(rat,"printParseErrorCode");var KV=class{static{t(this,"AstAdapter")}parse(o){let d=GV(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:Wo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:Wo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){VP(o.children?.length===2,"Invalid property node");let d={type:Wo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:Wo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:Wo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var DS={createLiteral:t((s,o)=>({type:Wo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:Wo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:Wo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:Wo.Property,parent:f,name:null,value:o};return d.name={value:s,type:Wo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:Wo.Array,parent:o,children:[]};for(let d of s)f.children.push(DS.createLiteral(d,f));return f},"createArrayOfLiterals")};var vtr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,XV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case Wo.Array:return this.generateArray(o,f);case Wo.Object:return this.generateObject(o,f);case Wo.Property:return this.generateProperty(o,f);case Wo.Literal:return this.generateLiteral(o,f);case Wo.FunctionCall:return this.generateFunctionCall(o,f);case Wo.Identifier:return this.generateIdentifier(o,f);case Wo.Raw:return this.generateRaw(o,f);case Wo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,x)=>{this.generateSource(o,d),y<x.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=vtr.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import btr from"node:fs/promises";import{parse as Str}from"@swc/core";var nat=t(async s=>{let o=new Set;try{let f=await btr.readFile(s,"utf-8");(await Str(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var iat={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var WAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var sat={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var qAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var VAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var flt=Pp(tle(),1),_lt=Pp(ult(),1);var ile=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new flt.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,_lt.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},A=y.instancePath.split("/");if(A.length>2){let W=A[1],G=A[2]?parseInt(A[2],10):0,be=A[3],de=Number.isNaN(G)?void 0:f[W][G][be];x={details:{property:W,index:G,field:be,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let W=y.instancePath.split("/"),G=W[W.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var _I=ile.instance;_I.addSchema(qAe,"route-configuration.schema.json");_I.addSchema(sat,"policy-configuration.schema.json");_I.addSchema(WAe,"policies.schema.json");_I.addSchema(VAe,"open-api-route-configuration.schema.json");_I.addSchema(iat,"fragments.schema.json");var M6r=_I.compile(qAe),plt=_I.compile(VAe),oIe=_I.compile(WAe);var sle=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=oIe(o),this.results}};var ale=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=plt(o),this.results}};import Ncr from"node:path";var cIe=/\$import\((.*)\)/,PH=/\$env\((.*?)\)/g;var Uk=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},Acr=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),ZP=t((s,o)=>{if(!s)return!1;let f=Acr(s);return o.split("/").every((x,A)=>{let F=f[A];return F?x==="*"||HP(F)&&F.name.value===x?!0:x==="{}"?F.type===Wo.Object:x==="[]"?F.type===Wo.Array:!1:!1})},"testPosition");var ole=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),eM(o)?o.children.forEach(f=>{this.visitor(f)}):$Ae(o)?o.children.forEach(f=>{this.visitor(f)}):HP(o)&&this.visitor(o.value)}},dlt=t(s=>{let o=new RegExp(PH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(PH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),mlt=t((s,o,f)=>d=>{if(SO(d)&&typeof d.value=="string"&&d.parent&&$Ae(d.parent)){if(!s.some(A=>ZP(d.parent,A))){PH.test(d.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value));return}let x=dlt(d.value);if(x){let A=d.parent,F=A.children.indexOf(d);if(F!==-1)if(x.type==="raw"){let W={type:Wo.Raw,parent:A,value:x.value};A.children[F]=W}else A.children[F]=DS.createTemplateString(x.value,d)}return}if(!HP(d)||!SO(d.value)||typeof d.value.value!="string")return;if(!s.some(x=>ZP(d,x))){PH.test(d.value.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=dlt(d.value.value);if(y)if(y.type==="raw"){let x={type:Wo.Raw,parent:null,value:y.value};d.value=x}else d.value=DS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var AH="config/routes.json",Icr=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],Ocr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],hlt=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Fcr="handler/{}/options/{}/rewritePattern",Lcr="handler/{}/options/{}/baseUrl",cle=class extends ole{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!HP(o)||!SO(o.value)||typeof o.value.value!="string")&&ZP(o,Fcr)){if(!o.parent||!eM(o.parent)){this.errors.push(new Uk("Invalid node, expected object",AH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:glt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!HP(o)||!SO(o.value)||typeof o.value.value!="string")&&ZP(o,Lcr)){if(!o.parent||!eM(o.parent)){this.errors.push(new Uk("Invalid node, expected object",AH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:glt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!HP(o)||!SO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!Ocr.some(F=>ZP(o,F))&&!hlt.some(F=>ZP(o,F))){if(cIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new Uk("An $import() statement is not expected at this location.",AH,o.location,f))}return}let d=cIe.exec(f);if(hlt.some(F=>ZP(o,F))&&!d)return;if(!d){this.errors.push(new Uk("Invalid $import() statement",AH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=Ncr.posix.join("..",y));let x=this.getImportName(y),A={type:Wo.Identifier,parent:o.parent,value:x};o.value=A}replaceEnvStatements=mlt(Icr,this.errors,AH)};function glt(s){return`(request, context) => {
|
|
575
|
+
`),exitCode:x},"Untar process logs")}}t(pZt,"untarFile");async function dZt(s){if(await sAe(s))return await XN.rm(s,{recursive:!0})}t(dZt,"deleteFolder");var eu=aAe;var Tlt=Pp(Ust(),1);var zst=["ai-gateway-auth-v2","ai-gateway-configuration-executor-v2","ai-gateway-fallback-model-v2","ai-gateway-metering-v2","ai-gateway-model-filtering-v2","ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2","akamai-ai-firewall","akamai-ai-firewall-v2","akamai-firewall-for-ai","comet-opik-tracing-v2","galileo-tracing-v2","prompt-injection","semantic-cache"];var HV=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(s,o,f,d,y,x){this.type=s,this.name=o,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},zer=/[$_\p{ID_Start}]/u,$er=/[$_\u200C\u200D\p{ID_Continue}]/u,UAe=".*";function Jer(s,o){return(o?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(s)}t(Jer,"Re");function Wst(s,o=!1){let f=[],d=0;for(;d<s.length;){let y=s[d],x=t(function(A){if(!o)throw new TypeError(A);f.push({type:"INVALID_CHAR",index:d,value:s[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:s[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:s[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:s[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:s[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:s[d++]});continue}if(y===":"){let A="",F=d+1;for(;F<s.length;){let W=s.substr(F,1);if(F===d+1&&zer.test(W)||F!==d+1&&$er.test(W)){A+=s[F++];continue}break}if(!A){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:A}),d=F;continue}if(y==="("){let A=1,F="",W=d+1,G=!1;if(s[W]==="?"){x(`Pattern cannot start with "?" at ${W}`);continue}for(;W<s.length;){if(!Jer(s[W],!1)){x(`Invalid character '${s[W]}' at ${W}.`),G=!0;break}if(s[W]==="\\"){F+=s[W++]+s[W++];continue}if(s[W]===")"){if(A--,A===0){W++;break}}else if(s[W]==="("&&(A++,s[W+1]!=="?")){x(`Capturing groups are not allowed at ${W}`),G=!0;break}F+=s[W++]}if(G)continue;if(A){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=W;continue}f.push({type:"CHAR",index:d,value:s[d++]})}return f.push({type:"END",index:d,value:""}),f}t(Wst,"v");function qst(s,o={}){let f=Wst(s);o.delimiter??="/#?",o.prefixes??="./";let d=`[^${fT(o.delimiter)}]+?`,y=[],x=0,A=0,F="",W=new Set,G=t(wn=>{if(A<f.length&&f[A].type===wn)return f[A++].value},"a"),be=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(wn=>{let sn=G(wn);if(sn!==void 0)return sn;let{type:Jn,index:kr}=f[A];throw new TypeError(`Unexpected ${Jn} at ${kr}, expected ${wn}`)},"d"),se=t(()=>{let wn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)wn+=sn;return wn},"T"),Xe=t(wn=>wn,"Se"),Ue=o.encodePart||Xe,je="",Vt=t(wn=>{je+=wn},"U"),Ut=t(()=>{je.length&&(y.push(new HV(3,"","",Ue(je),"",3)),je="")},"$"),Ir=t((wn,sn,Jn,kr,yr)=>{let xs=3;switch(yr){case"?":xs=1;break;case"*":xs=0;break;case"+":xs=2;break}if(!sn&&!Jn&&xs===3){Vt(wn);return}if(Ut(),!sn&&!Jn){if(!wn)return;y.push(new HV(3,"","",Ue(wn),"",xs));return}let bi;Jn?Jn==="*"?bi=UAe:bi=Jn:bi=d;let fc=2;bi===d?(fc=1,bi=""):bi===UAe&&(fc=0,bi="");let Ci;if(sn?Ci=sn:Jn&&(Ci=x++),W.has(Ci))throw new TypeError(`Duplicate name '${Ci}'.`);W.add(Ci),y.push(new HV(fc,Ci,Ue(wn),bi,Ue(kr),xs))},"V");for(;A<f.length;){let wn=G("CHAR"),sn=G("NAME"),Jn=G("REGEX");if(!sn&&!Jn&&(Jn=G("ASTERISK")),sn||Jn){let yr=wn??"";o.prefixes.indexOf(yr)===-1&&(Vt(yr),yr=""),Ut();let xs=be();Ir(yr,sn,Jn,"",xs);continue}let kr=wn??G("ESCAPED_CHAR");if(kr){Vt(kr);continue}if(G("OPEN")){let yr=se(),xs=G("NAME"),bi=G("REGEX");!xs&&!bi&&(bi=G("ASTERISK"));let fc=se();de("CLOSE");let Ci=be();Ir(yr,xs,bi,fc,Ci);continue}Ut(),de("END")}return y}t(qst,"D");function fT(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(fT,"S");function $st(s){return s&&s.ignoreCase?"ui":"u"}t($st,"X");function Wer(s,o,f){return Vst(qst(s,f),o,f)}t(Wer,"Z");function Q9(s){switch(s){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(Q9,"k");function Vst(s,o,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of s){if(F.type===3){F.modifier===3?d+=fT(F.value):d+=`(?:${fT(F.value)})${Q9(F.modifier)}`;continue}o&&o.push(F.name);let W=`[^${fT(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=W:F.type===0&&(G=UAe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${Q9(F.modifier)}`:d+=`((?:${G})${Q9(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${fT(F.prefix)}(${G})${fT(F.suffix)})`,d+=Q9(F.modifier);continue}d+=`(?:${fT(F.prefix)}`,d+=`((?:${G})(?:`,d+=fT(F.suffix),d+=fT(F.prefix),d+=`(?:${G}))*)${fT(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${fT(f.endsWith)}]|$`,x=`[${fT(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,$st(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let A=!1;if(s.length){let F=s[s.length-1];F.type===3&&F.modifier===3&&(A=f.delimiter.indexOf(F)>-1)}return A||(d+=`(?=${x}|${y})`),new RegExp(d,$st(f))}t(Vst,"F");var tI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},qer={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Ver={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Her(s,o){return s.length?s[0]==="/"?!0:!o||s.length<2?!1:(s[0]=="\\"||s[0]=="{")&&s[1]=="/":!1}t(Her,"J");function Hst(s,o){return s.startsWith(o)?s.substring(o.length,s.length):s}t(Hst,"Q");function Ger(s,o){return s.endsWith(o)?s.substr(0,s.length-o.length):s}t(Ger,"Ee");function Gst(s){return!s||s.length<2?!1:s[0]==="["||(s[0]==="\\"||s[0]==="{")&&s[1]==="["}t(Gst,"W");var Yst=["ftp","file","http","https","ws","wss"];function Kst(s){if(!s)return!0;for(let o of Yst)if(s.test(o))return!0;return!1}t(Kst,"N");function Yer(s,o){if(s=Hst(s,"#"),o||s==="")return s;let f=new URL("https://example.com");return f.hash=s,f.hash?f.hash.substring(1,f.hash.length):""}t(Yer,"te");function Ker(s,o){if(s=Hst(s,"?"),o||s==="")return s;let f=new URL("https://example.com");return f.search=s,f.search?f.search.substring(1,f.search.length):""}t(Ker,"re");function Xer(s,o){return o||s===""?s:Gst(s)?Qst(s):Zst(s)}t(Xer,"ne");function Zer(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.password=s,f.password}t(Zer,"se");function Qer(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.username=s,f.username}t(Qer,"ie");function etr(s,o,f){if(f||s==="")return s;if(o&&!Yst.includes(o))return new URL(`${o}:${s}`).pathname;let d=s[0]=="/";return s=new URL(d?s:"/-"+s,"https://example.com").pathname,d||(s=s.substring(2,s.length)),s}t(etr,"ae");function ttr(s,o,f){return Xst(o)===s&&(s=""),f||s===""?s:eat(s)}t(ttr,"oe");function rtr(s,o){return s=Ger(s,":"),o||s===""?s:zAe(s)}t(rtr,"ce");function Xst(s){switch(s){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(Xst,"_");function zAe(s){if(s==="")return s;if(/^[-+.A-Za-z0-9]*$/.test(s))return s.toLowerCase();throw new TypeError(`Invalid protocol '${s}'.`)}t(zAe,"y");function ntr(s){if(s==="")return s;let o=new URL("https://example.com");return o.username=s,o.username}t(ntr,"le");function itr(s){if(s==="")return s;let o=new URL("https://example.com");return o.password=s,o.password}t(itr,"fe");function Zst(s){if(s==="")return s;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(s))throw new TypeError(`Invalid hostname '${s}'`);let o=new URL("https://example.com");return o.hostname=s,o.hostname}t(Zst,"z");function Qst(s){if(s==="")return s;if(/[^0-9a-fA-F[\]:]/g.test(s))throw new TypeError(`Invalid IPv6 hostname '${s}'`);return s.toLowerCase()}t(Qst,"j");function eat(s){if(s===""||/^[0-9]*$/.test(s)&&parseInt(s)<=65535)return s;throw new TypeError(`Invalid port '${s}'.`)}t(eat,"K");function str(s){if(s==="")return s;let o=new URL("https://example.com");return o.pathname=s[0]!=="/"?"/-"+s:s,s[0]!=="/"?o.pathname.substring(2,o.pathname.length):o.pathname}t(str,"he");function atr(s){return s===""?s:new URL(`data:${s}`).pathname}t(atr,"ue");function otr(s){if(s==="")return s;let o=new URL("https://example.com");return o.search=s,o.search.substring(1,o.search.length)}t(otr,"de");function ctr(s){if(s==="")return s;let o=new URL("https://example.com");return o.hash=s,o.hash.substring(1,o.hash.length)}t(ctr,"pe");var ltr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#m=0;#c=0;#u=0;#f=0;#p=!1;constructor(s){this.#e=s}get result(){return this.#t}parse(){for(this.#n=Wst(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#c===0){this.#o(),this.#g()?this.#a(9,1):this.#E()?this.#a(8,1):this.#a(7,0);continue}else if(this.#c===2){this.#h(5);continue}this.#a(10,0);break}if(this.#u>0)if(this.#l())this.#u-=1;else continue;if(this.#A()){this.#u+=1;continue}switch(this.#c){case 0:this.#y()&&this.#h(1);break;case 1:if(this.#y()){this.#D();let s=7,o=1;this.#b()?(s=2,o=3):this.#p&&(s=2),this.#a(s,o)}break;case 2:this.#v()?this.#h(3):(this.#S()||this.#E()||this.#g())&&this.#h(5);break;case 3:this.#C()?this.#a(4,1):this.#v()&&this.#a(5,1);break;case 4:this.#v()&&this.#a(5,1);break;case 5:this.#O()?this.#f+=1:this.#N()&&(this.#f-=1),this.#k()&&!this.#f?this.#a(6,1):this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 6:this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 7:this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 8:this.#g()&&this.#a(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#a(s,o){switch(this.#c){case 0:break;case 1:this.#t.protocol=this.#w();break;case 2:break;case 3:this.#t.username=this.#w();break;case 4:this.#t.password=this.#w();break;case 5:this.#t.hostname=this.#w();break;case 6:this.#t.port=this.#w();break;case 7:this.#t.pathname=this.#w();break;case 8:this.#t.search=this.#w();break;case 9:this.#t.hash=this.#w();break;case 10:break}this.#c!==0&&s!==10&&([1,2,3,4].includes(this.#c)&&[6,7,8,9].includes(s)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#c)&&[8,9].includes(s)&&(this.#t.pathname??=this.#p?"/":""),[1,2,3,4,5,6,7].includes(this.#c)&&s===9&&(this.#t.search??="")),this.#i(s,o)}#i(s,o){this.#c=s,this.#m=this.#r+o,this.#r+=o,this.#s=0}#o(){this.#r=this.#m,this.#s=0}#h(s){this.#o(),this.#c=s}#d(s){return s<0&&(s=this.#n.length-s),s<this.#n.length?this.#n[s]:this.#n[this.#n.length-1]}#_(s,o){let f=this.#d(s);return f.value===o&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#y(){return this.#_(this.#r,":")}#b(){return this.#_(this.#r+1,"/")&&this.#_(this.#r+2,"/")}#v(){return this.#_(this.#r,"@")}#C(){return this.#_(this.#r,":")}#k(){return this.#_(this.#r,":")}#S(){return this.#_(this.#r,"/")}#E(){if(this.#_(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let s=this.#d(this.#r-1);return s.type!=="NAME"&&s.type!=="REGEX"&&s.type!=="CLOSE"&&s.type!=="ASTERISK"}#g(){return this.#_(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#_(this.#r,"[")}#N(){return this.#_(this.#r,"]")}#w(){let s=this.#n[this.#r],o=this.#d(this.#m).index;return this.#e.substring(o,s.index)}#D(){let s={};Object.assign(s,tI),s.encodePart=zAe;let o=Wer(this.#w(),void 0,s);this.#p=Kst(o)}},BAe=["protocol","username","password","hostname","port","pathname","search","hash"],eI="*";function Jst(s,o){if(typeof s!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(s,o);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(Jst,"ge");function qP(s,o){return o?VV(s):s}t(qP,"b");function qV(s,o,f){let d;if(typeof o.baseURL=="string")try{d=new URL(o.baseURL),o.protocol===void 0&&(s.protocol=qP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&(s.username=qP(d.username,f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&o.password===void 0&&(s.password=qP(d.password,f)),o.protocol===void 0&&o.hostname===void 0&&(s.hostname=qP(d.hostname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&(s.port=qP(d.port,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&(s.pathname=qP(d.pathname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&(s.search=qP(d.search.substring(1,d.search.length),f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&o.hash===void 0&&(s.hash=qP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${o.baseURL}'.`)}if(typeof o.protocol=="string"&&(s.protocol=rtr(o.protocol,f)),typeof o.username=="string"&&(s.username=Qer(o.username,f)),typeof o.password=="string"&&(s.password=Zer(o.password,f)),typeof o.hostname=="string"&&(s.hostname=Xer(o.hostname,f)),typeof o.port=="string"&&(s.port=ttr(o.port,s.protocol,f)),typeof o.pathname=="string"){if(s.pathname=o.pathname,d&&!Her(s.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(s.pathname=qP(d.pathname.substring(0,y+1),f)+s.pathname)}s.pathname=etr(s.pathname,s.protocol,f)}return typeof o.search=="string"&&(s.search=Ker(o.search,f)),typeof o.hash=="string"&&(s.hash=Yer(o.hash,f)),s}t(qV,"w");function VV(s){return s.replace(/([+*?:{}()\\])/g,"\\$1")}t(VV,"C");function utr(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(utr,"Oe");function ftr(s,o){o.delimiter??="/#?",o.prefixes??="./",o.sensitive??=!1,o.strict??=!1,o.end??=!0,o.start??=!0,o.endsWith="";let f=".*",d=`[^${utr(o.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let A=0;A<s.length;++A){let F=s[A];if(F.type===3){if(F.modifier===3){x+=VV(F.value);continue}x+=`{${VV(F.value)}}${Q9(F.modifier)}`;continue}let W=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!o.prefixes.includes(F.prefix)),be=A>0?s[A-1]:null,de=A<s.length-1?s[A+1]:null;if(!G&&W&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let se=de.value.length>0?de.value[0]:"";G=y.test(se)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&be&&be.type===3){let se=be.value[be.value.length-1];G=o.prefixes.includes(se)}G&&(x+="{"),x+=VV(F.prefix),W&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?W||(x+=`(${d})`):F.type===0&&(!W&&(!be||be.type===3||be.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&W&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=VV(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=Q9(F.modifier))}return x}t(ftr,"ke");var tat=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#m=!1;constructor(s={},o,f){try{let d;if(typeof o=="string"?d=o:f=o,typeof s=="string"){let F=new ltr(s);if(F.parse(),s=F.result,d===void 0&&typeof s.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");s.baseURL=d}else{if(!s||typeof s!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:eI,protocol:eI,username:eI,password:eI,hostname:eI,port:eI,search:eI,hash:eI};this.#e=qV(x,s,!0),Xst(this.#e.protocol)===this.#e.port&&(this.#e.port="");let A;for(A of BAe){if(!(A in this.#e))continue;let F={},W=this.#e[A];switch(this.#t[A]=[],A){case"protocol":Object.assign(F,tI),F.encodePart=zAe;break;case"username":Object.assign(F,tI),F.encodePart=ntr;break;case"password":Object.assign(F,tI),F.encodePart=itr;break;case"hostname":Object.assign(F,qer),Gst(W)?F.encodePart=Qst:F.encodePart=Zst;break;case"port":Object.assign(F,tI),F.encodePart=eat;break;case"pathname":Kst(this.#n.protocol)?(Object.assign(F,Ver,y),F.encodePart=str):(Object.assign(F,tI,y),F.encodePart=atr);break;case"search":Object.assign(F,tI,y),F.encodePart=otr;break;case"hash":Object.assign(F,tI,y),F.encodePart=ctr;break}try{this.#s[A]=qst(W,F),this.#n[A]=Vst(this.#s[A],this.#t[A],F),this.#r[A]=ftr(this.#s[A],F),this.#m=this.#m||this.#s[A].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${A} pattern '${this.#e[A]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return!1;try{typeof s=="object"?f=qV(f,s,!1):f=qV(f,Jst(s,o),!1)}catch{return!1}let d;for(d of BAe)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return;try{typeof s=="object"?f=qV(f,s,!1):f=qV(f,Jst(s,o),!1)}catch{return null}let d={};o?d.inputs=[s,o]:d.inputs=[s];let y;for(y of BAe){let x=this.#n[y].exec(f[y]);if(!x)return null;let A={};for(let[F,W]of this.#t[y].entries())if(typeof W=="string"||typeof W=="number"){let G=x[F+1];A[W]=G}d[y]={input:f[y]??"",groups:A}}return d}static compareComponent(s,o,f){let d=t((F,W)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<W[G])return-1;if(F[G]!==W[G])return 1}return 0},"o"),y=new HV(3,"","","","",3),x=new HV(0,"","","","",3),A=t((F,W)=>{let G=0;for(;G<Math.min(F.length,W.length);++G){let be=d(F[G],W[G]);if(be)return be}return F.length===W.length?0:d(F[G]??y,W[G]??y)},"s");return!o.#r[s]&&!f.#r[s]?0:o.#r[s]&&!f.#r[s]?A(o.#s[s],[x]):!o.#r[s]&&f.#r[s]?A([x],f.#s[s]):A(o.#s[s],f.#s[s])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#m}};globalThis.URLPattern||(globalThis.URLPattern=tat);import{AssertionError as _tr}from"node:assert";function VP(s,o){if(s===!1)throw new _tr({message:o})}t(VP,"assert");var Wo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(Wo||(Wo={}));function eM(s){return s.type===Wo.Object}t(eM,"isAstObject");function HP(s){return s.type===Wo.Property}t(HP,"isAstProperty");function $Ae(s){return s.type===Wo.Array}t($Ae,"isAstArray");function SO(s){return s.type===Wo.Literal}t(SO,"isAstLiteral");function rI(s){if(s===void 0)throw new Error("Node is undefined");if(!eM(s))throw new Error("Node is not object")}t(rI,"assertAstObject");import{findNodeAtLocation as ptr,getNodeValue as dtr,printParseErrorCode as mtr,visit as htr}from"jsonc-parser";var gtr={DEFAULT:{allowTrailingComma:!1}};function GV(s,o=[],f=gtr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(W){d.type==="property"&&(d.length=W-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(W){return d.children?.push(W),W}t(x,"onValue"),htr(s,{onObjectBegin:t((W,G,be)=>{d=x({type:"object",offset:W,length:-1,line:G+1,column:be+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((W,G,be,de,se)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:W,offset:G,length:be,line:de,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((W,G)=>{y(W+G),d.length=W+G-d.offset,d=d.parent,y(W+G)},"onObjectEnd"),onArrayBegin:t((W,G,be,de)=>{d=x({type:"array",offset:W,length:-1,line:be+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((W,G)=>{d.length=W+G-d.offset,d=d.parent,y(W+G)},"onArrayEnd"),onLiteralValue:t((W,G,be,de,se)=>{x({type:ytr(W),offset:G,length:be,line:de+1,column:se+1,parent:d,value:W}),y(G+be)},"onLiteralValue"),onSeparator:t((W,G)=>{d.type==="property"&&(W===":"?d.colonOffset=G:W===","&&y(G))},"onSeparator"),onError:t((W,G,be,de,se)=>{o.push({error:W,offset:G,length:be,line:de+1,column:se+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(GV,"parse");function ytr(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t(ytr,"getNodeType");function JAe(s,o){return ptr(s,o)}t(JAe,"findNodeAtLocation");function YV(s){return dtr(s)}t(YV,"getNodeValue");function rat(s){return mtr(s)}t(rat,"printParseErrorCode");var KV=class{static{t(this,"AstAdapter")}parse(o){let d=GV(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:Wo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:Wo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){VP(o.children?.length===2,"Invalid property node");let d={type:Wo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:Wo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:Wo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var DS={createLiteral:t((s,o)=>({type:Wo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:Wo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:Wo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:Wo.Property,parent:f,name:null,value:o};return d.name={value:s,type:Wo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:Wo.Array,parent:o,children:[]};for(let d of s)f.children.push(DS.createLiteral(d,f));return f},"createArrayOfLiterals")};var vtr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,XV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case Wo.Array:return this.generateArray(o,f);case Wo.Object:return this.generateObject(o,f);case Wo.Property:return this.generateProperty(o,f);case Wo.Literal:return this.generateLiteral(o,f);case Wo.FunctionCall:return this.generateFunctionCall(o,f);case Wo.Identifier:return this.generateIdentifier(o,f);case Wo.Raw:return this.generateRaw(o,f);case Wo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,x)=>{this.generateSource(o,d),y<x.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=vtr.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import btr from"node:fs/promises";import{parse as Str}from"@swc/core";var nat=t(async s=>{let o=new Set;try{let f=await btr.readFile(s,"utf-8");(await Str(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var iat={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var WAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var sat={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var qAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var VAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var flt=Pp(tle(),1),_lt=Pp(ult(),1);var ile=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new flt.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,_lt.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},A=y.instancePath.split("/");if(A.length>2){let W=A[1],G=A[2]?parseInt(A[2],10):0,be=A[3],de=Number.isNaN(G)?void 0:f[W][G][be];x={details:{property:W,index:G,field:be,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let W=y.instancePath.split("/"),G=W[W.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var _I=ile.instance;_I.addSchema(qAe,"route-configuration.schema.json");_I.addSchema(sat,"policy-configuration.schema.json");_I.addSchema(WAe,"policies.schema.json");_I.addSchema(VAe,"open-api-route-configuration.schema.json");_I.addSchema(iat,"fragments.schema.json");var M6r=_I.compile(qAe),plt=_I.compile(VAe),oIe=_I.compile(WAe);var sle=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=oIe(o),this.results}};var ale=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=plt(o),this.results}};import Ncr from"node:path";var cIe=/\$import\((.*)\)/,PH=/\$env\((.*?)\)/g;var Uk=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},Acr=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),ZP=t((s,o)=>{if(!s)return!1;let f=Acr(s);return o.split("/").every((x,A)=>{let F=f[A];return F?x==="*"||HP(F)&&F.name.value===x?!0:x==="{}"?F.type===Wo.Object:x==="[]"?F.type===Wo.Array:!1:!1})},"testPosition");var ole=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),eM(o)?o.children.forEach(f=>{this.visitor(f)}):$Ae(o)?o.children.forEach(f=>{this.visitor(f)}):HP(o)&&this.visitor(o.value)}},dlt=t(s=>{let o=new RegExp(PH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(PH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),mlt=t((s,o,f)=>d=>{if(SO(d)&&typeof d.value=="string"&&d.parent&&$Ae(d.parent)){if(!s.some(A=>ZP(d.parent,A))){PH.test(d.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value));return}let x=dlt(d.value);if(x){let A=d.parent,F=A.children.indexOf(d);if(F!==-1)if(x.type==="raw"){let W={type:Wo.Raw,parent:A,value:x.value};A.children[F]=W}else A.children[F]=DS.createTemplateString(x.value,d)}return}if(!HP(d)||!SO(d.value)||typeof d.value.value!="string")return;if(!s.some(x=>ZP(d,x))){PH.test(d.value.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=dlt(d.value.value);if(y)if(y.type==="raw"){let x={type:Wo.Raw,parent:null,value:y.value};d.value=x}else d.value=DS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var AH="config/routes.json",Icr=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],Ocr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],hlt=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Fcr="handler/{}/options/{}/rewritePattern",Lcr="handler/{}/options/{}/baseUrl",cle=class extends ole{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!HP(o)||!SO(o.value)||typeof o.value.value!="string")&&ZP(o,Fcr)){if(!o.parent||!eM(o.parent)){this.errors.push(new Uk("Invalid node, expected object",AH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:glt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!HP(o)||!SO(o.value)||typeof o.value.value!="string")&&ZP(o,Lcr)){if(!o.parent||!eM(o.parent)){this.errors.push(new Uk("Invalid node, expected object",AH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:glt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!HP(o)||!SO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!Ocr.some(F=>ZP(o,F))&&!hlt.some(F=>ZP(o,F))){if(cIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new Uk("An $import() statement is not expected at this location.",AH,o.location,f))}return}let d=cIe.exec(f);if(hlt.some(F=>ZP(o,F))&&!d)return;if(!d){this.errors.push(new Uk("Invalid $import() statement",AH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=Ncr.posix.join("..",y));let x=this.getImportName(y),A={type:Wo.Identifier,parent:o.parent,value:x};o.value=A}replaceEnvStatements=mlt(Icr,this.errors,AH)};function glt(s){return`(request, context) => {
|
|
576
576
|
const { params, url, query, method, headers } = request;
|
|
577
577
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
578
578
|
const e = encodeURIComponent;
|
|
@@ -572,7 +572,7 @@ globstar while`,s,de,o,se,Xe),this.matchOne(s.slice(de),o.slice(se),f))return th
|
|
|
572
572
|
`),stderr:x.join(`
|
|
573
573
|
`),exitCode:P},"Tar process logs")}}t(RZt,"tarFolder");async function MZt({tarFilePath:s,outputDir:o,logger:f}){let d=[],y=[],x;try{await new Promise((P,F)=>{let W=xit("sh",["-c",`tar -xvf ${s} -C ${o};`]);W.stdout.on("data",G=>{let be=G.toString().trim();be.length>0&&d.push(be.trim())}),W.stderr.on("data",G=>{let be=G.toString().trim();be.length>0&&y.push(be.trim())}),W.on("close",G=>{x=G,G===0?P():F(new Error(`tar process exited with code ${G}`))}),W.on("error",G=>{F(G)})})}catch(P){throw new Error("Failed to untar file",{cause:P})}finally{f.info({stdout:d.join(`
|
|
574
574
|
`),stderr:y.join(`
|
|
575
|
-
`),exitCode:x},"Untar process logs")}}t(MZt,"untarFile");async function jZt(s){if(await uAe(s))return await eI.rm(s,{recursive:!0})}t(jZt,"deleteFolder");var eu=fAe;var Plt=B_(Hst(),1);var Gst=["ai-gateway-auth-v2","ai-gateway-configuration-executor-v2","ai-gateway-fallback-model-v2","ai-gateway-model-filtering-v2","ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2","akamai-ai-firewall","akamai-ai-firewall-v2","akamai-firewall-for-ai","comet-opik-tracing-v2","galileo-tracing-v2","prompt-injection","semantic-cache"];var GV=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(s,o,f,d,y,x){this.type=s,this.name=o,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},ftr=/[$_\p{ID_Start}]/u,_tr=/[$_\u200C\u200D\p{ID_Continue}]/u,qAe=".*";function ptr(s,o){return(o?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(s)}t(ptr,"Re");function Xst(s,o=!1){let f=[],d=0;for(;d<s.length;){let y=s[d],x=t(function(P){if(!o)throw new TypeError(P);f.push({type:"INVALID_CHAR",index:d,value:s[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:s[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:s[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:s[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:s[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:s[d++]});continue}if(y===":"){let P="",F=d+1;for(;F<s.length;){let W=s.substr(F,1);if(F===d+1&&ftr.test(W)||F!==d+1&&_tr.test(W)){P+=s[F++];continue}break}if(!P){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:P}),d=F;continue}if(y==="("){let P=1,F="",W=d+1,G=!1;if(s[W]==="?"){x(`Pattern cannot start with "?" at ${W}`);continue}for(;W<s.length;){if(!ptr(s[W],!1)){x(`Invalid character '${s[W]}' at ${W}.`),G=!0;break}if(s[W]==="\\"){F+=s[W++]+s[W++];continue}if(s[W]===")"){if(P--,P===0){W++;break}}else if(s[W]==="("&&(P++,s[W+1]!=="?")){x(`Capturing groups are not allowed at ${W}`),G=!0;break}F+=s[W++]}if(G)continue;if(P){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=W;continue}f.push({type:"CHAR",index:d,value:s[d++]})}return f.push({type:"END",index:d,value:""}),f}t(Xst,"v");function Zst(s,o={}){let f=Xst(s);o.delimiter??="/#?",o.prefixes??="./";let d=`[^${_T(o.delimiter)}]+?`,y=[],x=0,P=0,F="",W=new Set,G=t(wn=>{if(P<f.length&&f[P].type===wn)return f[P++].value},"a"),be=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(wn=>{let sn=G(wn);if(sn!==void 0)return sn;let{type:Jn,index:kr}=f[P];throw new TypeError(`Unexpected ${Jn} at ${kr}, expected ${wn}`)},"d"),se=t(()=>{let wn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)wn+=sn;return wn},"T"),Xe=t(wn=>wn,"Se"),Ue=o.encodePart||Xe,je="",Vt=t(wn=>{je+=wn},"U"),Ut=t(()=>{je.length&&(y.push(new GV(3,"","",Ue(je),"",3)),je="")},"$"),Ir=t((wn,sn,Jn,kr,yr)=>{let xs=3;switch(yr){case"?":xs=1;break;case"*":xs=0;break;case"+":xs=2;break}if(!sn&&!Jn&&xs===3){Vt(wn);return}if(Ut(),!sn&&!Jn){if(!wn)return;y.push(new GV(3,"","",Ue(wn),"",xs));return}let bi;Jn?Jn==="*"?bi=qAe:bi=Jn:bi=d;let fc=2;bi===d?(fc=1,bi=""):bi===qAe&&(fc=0,bi="");let Ci;if(sn?Ci=sn:Jn&&(Ci=x++),W.has(Ci))throw new TypeError(`Duplicate name '${Ci}'.`);W.add(Ci),y.push(new GV(fc,Ci,Ue(wn),bi,Ue(kr),xs))},"V");for(;P<f.length;){let wn=G("CHAR"),sn=G("NAME"),Jn=G("REGEX");if(!sn&&!Jn&&(Jn=G("ASTERISK")),sn||Jn){let yr=wn??"";o.prefixes.indexOf(yr)===-1&&(Vt(yr),yr=""),Ut();let xs=be();Ir(yr,sn,Jn,"",xs);continue}let kr=wn??G("ESCAPED_CHAR");if(kr){Vt(kr);continue}if(G("OPEN")){let yr=se(),xs=G("NAME"),bi=G("REGEX");!xs&&!bi&&(bi=G("ASTERISK"));let fc=se();de("CLOSE");let Ci=be();Ir(yr,xs,bi,fc,Ci);continue}Ut(),de("END")}return y}t(Zst,"D");function _T(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(_T,"S");function Yst(s){return s&&s.ignoreCase?"ui":"u"}t(Yst,"X");function dtr(s,o,f){return Qst(Zst(s,f),o,f)}t(dtr,"Z");function Q9(s){switch(s){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(Q9,"k");function Qst(s,o,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of s){if(F.type===3){F.modifier===3?d+=_T(F.value):d+=`(?:${_T(F.value)})${Q9(F.modifier)}`;continue}o&&o.push(F.name);let W=`[^${_T(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=W:F.type===0&&(G=qAe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${Q9(F.modifier)}`:d+=`((?:${G})${Q9(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${_T(F.prefix)}(${G})${_T(F.suffix)})`,d+=Q9(F.modifier);continue}d+=`(?:${_T(F.prefix)}`,d+=`((?:${G})(?:`,d+=_T(F.suffix),d+=_T(F.prefix),d+=`(?:${G}))*)${_T(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${_T(f.endsWith)}]|$`,x=`[${_T(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,Yst(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let P=!1;if(s.length){let F=s[s.length-1];F.type===3&&F.modifier===3&&(P=f.delimiter.indexOf(F)>-1)}return P||(d+=`(?=${x}|${y})`),new RegExp(d,Yst(f))}t(Qst,"F");var iI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},mtr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},htr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function gtr(s,o){return s.length?s[0]==="/"?!0:!o||s.length<2?!1:(s[0]=="\\"||s[0]=="{")&&s[1]=="/":!1}t(gtr,"J");function eat(s,o){return s.startsWith(o)?s.substring(o.length,s.length):s}t(eat,"Q");function ytr(s,o){return s.endsWith(o)?s.substr(0,s.length-o.length):s}t(ytr,"Ee");function tat(s){return!s||s.length<2?!1:s[0]==="["||(s[0]==="\\"||s[0]==="{")&&s[1]==="["}t(tat,"W");var rat=["ftp","file","http","https","ws","wss"];function nat(s){if(!s)return!0;for(let o of rat)if(s.test(o))return!0;return!1}t(nat,"N");function vtr(s,o){if(s=eat(s,"#"),o||s==="")return s;let f=new URL("https://example.com");return f.hash=s,f.hash?f.hash.substring(1,f.hash.length):""}t(vtr,"te");function btr(s,o){if(s=eat(s,"?"),o||s==="")return s;let f=new URL("https://example.com");return f.search=s,f.search?f.search.substring(1,f.search.length):""}t(btr,"re");function Str(s,o){return o||s===""?s:tat(s)?aat(s):sat(s)}t(Str,"ne");function Ttr(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.password=s,f.password}t(Ttr,"se");function xtr(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.username=s,f.username}t(xtr,"ie");function Etr(s,o,f){if(f||s==="")return s;if(o&&!rat.includes(o))return new URL(`${o}:${s}`).pathname;let d=s[0]=="/";return s=new URL(d?s:"/-"+s,"https://example.com").pathname,d||(s=s.substring(2,s.length)),s}t(Etr,"ae");function Ctr(s,o,f){return iat(o)===s&&(s=""),f||s===""?s:oat(s)}t(Ctr,"oe");function ktr(s,o){return s=ytr(s,":"),o||s===""?s:VAe(s)}t(ktr,"ce");function iat(s){switch(s){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(iat,"_");function VAe(s){if(s==="")return s;if(/^[-+.A-Za-z0-9]*$/.test(s))return s.toLowerCase();throw new TypeError(`Invalid protocol '${s}'.`)}t(VAe,"y");function wtr(s){if(s==="")return s;let o=new URL("https://example.com");return o.username=s,o.username}t(wtr,"le");function Dtr(s){if(s==="")return s;let o=new URL("https://example.com");return o.password=s,o.password}t(Dtr,"fe");function sat(s){if(s==="")return s;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(s))throw new TypeError(`Invalid hostname '${s}'`);let o=new URL("https://example.com");return o.hostname=s,o.hostname}t(sat,"z");function aat(s){if(s==="")return s;if(/[^0-9a-fA-F[\]:]/g.test(s))throw new TypeError(`Invalid IPv6 hostname '${s}'`);return s.toLowerCase()}t(aat,"j");function oat(s){if(s===""||/^[0-9]*$/.test(s)&&parseInt(s)<=65535)return s;throw new TypeError(`Invalid port '${s}'.`)}t(oat,"K");function Ptr(s){if(s==="")return s;let o=new URL("https://example.com");return o.pathname=s[0]!=="/"?"/-"+s:s,s[0]!=="/"?o.pathname.substring(2,o.pathname.length):o.pathname}t(Ptr,"he");function Atr(s){return s===""?s:new URL(`data:${s}`).pathname}t(Atr,"ue");function Ntr(s){if(s==="")return s;let o=new URL("https://example.com");return o.search=s,o.search.substring(1,o.search.length)}t(Ntr,"de");function Itr(s){if(s==="")return s;let o=new URL("https://example.com");return o.hash=s,o.hash.substring(1,o.hash.length)}t(Itr,"pe");var Otr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#m=0;#c=0;#u=0;#f=0;#p=!1;constructor(s){this.#e=s}get result(){return this.#t}parse(){for(this.#n=Xst(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#c===0){this.#o(),this.#g()?this.#a(9,1):this.#E()?this.#a(8,1):this.#a(7,0);continue}else if(this.#c===2){this.#h(5);continue}this.#a(10,0);break}if(this.#u>0)if(this.#l())this.#u-=1;else continue;if(this.#A()){this.#u+=1;continue}switch(this.#c){case 0:this.#y()&&this.#h(1);break;case 1:if(this.#y()){this.#D();let s=7,o=1;this.#b()?(s=2,o=3):this.#p&&(s=2),this.#a(s,o)}break;case 2:this.#v()?this.#h(3):(this.#S()||this.#E()||this.#g())&&this.#h(5);break;case 3:this.#C()?this.#a(4,1):this.#v()&&this.#a(5,1);break;case 4:this.#v()&&this.#a(5,1);break;case 5:this.#O()?this.#f+=1:this.#N()&&(this.#f-=1),this.#k()&&!this.#f?this.#a(6,1):this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 6:this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 7:this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 8:this.#g()&&this.#a(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#a(s,o){switch(this.#c){case 0:break;case 1:this.#t.protocol=this.#w();break;case 2:break;case 3:this.#t.username=this.#w();break;case 4:this.#t.password=this.#w();break;case 5:this.#t.hostname=this.#w();break;case 6:this.#t.port=this.#w();break;case 7:this.#t.pathname=this.#w();break;case 8:this.#t.search=this.#w();break;case 9:this.#t.hash=this.#w();break;case 10:break}this.#c!==0&&s!==10&&([1,2,3,4].includes(this.#c)&&[6,7,8,9].includes(s)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#c)&&[8,9].includes(s)&&(this.#t.pathname??=this.#p?"/":""),[1,2,3,4,5,6,7].includes(this.#c)&&s===9&&(this.#t.search??="")),this.#i(s,o)}#i(s,o){this.#c=s,this.#m=this.#r+o,this.#r+=o,this.#s=0}#o(){this.#r=this.#m,this.#s=0}#h(s){this.#o(),this.#c=s}#d(s){return s<0&&(s=this.#n.length-s),s<this.#n.length?this.#n[s]:this.#n[this.#n.length-1]}#_(s,o){let f=this.#d(s);return f.value===o&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#y(){return this.#_(this.#r,":")}#b(){return this.#_(this.#r+1,"/")&&this.#_(this.#r+2,"/")}#v(){return this.#_(this.#r,"@")}#C(){return this.#_(this.#r,":")}#k(){return this.#_(this.#r,":")}#S(){return this.#_(this.#r,"/")}#E(){if(this.#_(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let s=this.#d(this.#r-1);return s.type!=="NAME"&&s.type!=="REGEX"&&s.type!=="CLOSE"&&s.type!=="ASTERISK"}#g(){return this.#_(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#_(this.#r,"[")}#N(){return this.#_(this.#r,"]")}#w(){let s=this.#n[this.#r],o=this.#d(this.#m).index;return this.#e.substring(o,s.index)}#D(){let s={};Object.assign(s,iI),s.encodePart=VAe;let o=dtr(this.#w(),void 0,s);this.#p=nat(o)}},WAe=["protocol","username","password","hostname","port","pathname","search","hash"],nI="*";function Kst(s,o){if(typeof s!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(s,o);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(Kst,"ge");function GP(s,o){return o?HV(s):s}t(GP,"b");function VV(s,o,f){let d;if(typeof o.baseURL=="string")try{d=new URL(o.baseURL),o.protocol===void 0&&(s.protocol=GP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&(s.username=GP(d.username,f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&o.password===void 0&&(s.password=GP(d.password,f)),o.protocol===void 0&&o.hostname===void 0&&(s.hostname=GP(d.hostname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&(s.port=GP(d.port,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&(s.pathname=GP(d.pathname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&(s.search=GP(d.search.substring(1,d.search.length),f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&o.hash===void 0&&(s.hash=GP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${o.baseURL}'.`)}if(typeof o.protocol=="string"&&(s.protocol=ktr(o.protocol,f)),typeof o.username=="string"&&(s.username=xtr(o.username,f)),typeof o.password=="string"&&(s.password=Ttr(o.password,f)),typeof o.hostname=="string"&&(s.hostname=Str(o.hostname,f)),typeof o.port=="string"&&(s.port=Ctr(o.port,s.protocol,f)),typeof o.pathname=="string"){if(s.pathname=o.pathname,d&&!gtr(s.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(s.pathname=GP(d.pathname.substring(0,y+1),f)+s.pathname)}s.pathname=Etr(s.pathname,s.protocol,f)}return typeof o.search=="string"&&(s.search=btr(o.search,f)),typeof o.hash=="string"&&(s.hash=vtr(o.hash,f)),s}t(VV,"w");function HV(s){return s.replace(/([+*?:{}()\\])/g,"\\$1")}t(HV,"C");function Ftr(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(Ftr,"Oe");function Ltr(s,o){o.delimiter??="/#?",o.prefixes??="./",o.sensitive??=!1,o.strict??=!1,o.end??=!0,o.start??=!0,o.endsWith="";let f=".*",d=`[^${Ftr(o.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let P=0;P<s.length;++P){let F=s[P];if(F.type===3){if(F.modifier===3){x+=HV(F.value);continue}x+=`{${HV(F.value)}}${Q9(F.modifier)}`;continue}let W=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!o.prefixes.includes(F.prefix)),be=P>0?s[P-1]:null,de=P<s.length-1?s[P+1]:null;if(!G&&W&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let se=de.value.length>0?de.value[0]:"";G=y.test(se)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&be&&be.type===3){let se=be.value[be.value.length-1];G=o.prefixes.includes(se)}G&&(x+="{"),x+=HV(F.prefix),W&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?W||(x+=`(${d})`):F.type===0&&(!W&&(!be||be.type===3||be.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&W&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=HV(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=Q9(F.modifier))}return x}t(Ltr,"ke");var cat=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#m=!1;constructor(s={},o,f){try{let d;if(typeof o=="string"?d=o:f=o,typeof s=="string"){let F=new Otr(s);if(F.parse(),s=F.result,d===void 0&&typeof s.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");s.baseURL=d}else{if(!s||typeof s!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:nI,protocol:nI,username:nI,password:nI,hostname:nI,port:nI,search:nI,hash:nI};this.#e=VV(x,s,!0),iat(this.#e.protocol)===this.#e.port&&(this.#e.port="");let P;for(P of WAe){if(!(P in this.#e))continue;let F={},W=this.#e[P];switch(this.#t[P]=[],P){case"protocol":Object.assign(F,iI),F.encodePart=VAe;break;case"username":Object.assign(F,iI),F.encodePart=wtr;break;case"password":Object.assign(F,iI),F.encodePart=Dtr;break;case"hostname":Object.assign(F,mtr),tat(W)?F.encodePart=aat:F.encodePart=sat;break;case"port":Object.assign(F,iI),F.encodePart=oat;break;case"pathname":nat(this.#n.protocol)?(Object.assign(F,htr,y),F.encodePart=Ptr):(Object.assign(F,iI,y),F.encodePart=Atr);break;case"search":Object.assign(F,iI,y),F.encodePart=Ntr;break;case"hash":Object.assign(F,iI,y),F.encodePart=Itr;break}try{this.#s[P]=Zst(W,F),this.#n[P]=Qst(this.#s[P],this.#t[P],F),this.#r[P]=Ltr(this.#s[P],F),this.#m=this.#m||this.#s[P].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${P} pattern '${this.#e[P]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return!1;try{typeof s=="object"?f=VV(f,s,!1):f=VV(f,Kst(s,o),!1)}catch{return!1}let d;for(d of WAe)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return;try{typeof s=="object"?f=VV(f,s,!1):f=VV(f,Kst(s,o),!1)}catch{return null}let d={};o?d.inputs=[s,o]:d.inputs=[s];let y;for(y of WAe){let x=this.#n[y].exec(f[y]);if(!x)return null;let P={};for(let[F,W]of this.#t[y].entries())if(typeof W=="string"||typeof W=="number"){let G=x[F+1];P[W]=G}d[y]={input:f[y]??"",groups:P}}return d}static compareComponent(s,o,f){let d=t((F,W)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<W[G])return-1;if(F[G]!==W[G])return 1}return 0},"o"),y=new GV(3,"","","","",3),x=new GV(0,"","","","",3),P=t((F,W)=>{let G=0;for(;G<Math.min(F.length,W.length);++G){let be=d(F[G],W[G]);if(be)return be}return F.length===W.length?0:d(F[G]??y,W[G]??y)},"s");return!o.#r[s]&&!f.#r[s]?0:o.#r[s]&&!f.#r[s]?P(o.#s[s],[x]):!o.#r[s]&&f.#r[s]?P([x],f.#s[s]):P(o.#s[s],f.#s[s])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#m}};globalThis.URLPattern||(globalThis.URLPattern=cat);import{AssertionError as Rtr}from"node:assert";function YP(s,o){if(s===!1)throw new Rtr({message:o})}t(YP,"assert");var Wo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(Wo||(Wo={}));function eM(s){return s.type===Wo.Object}t(eM,"isAstObject");function KP(s){return s.type===Wo.Property}t(KP,"isAstProperty");function HAe(s){return s.type===Wo.Array}t(HAe,"isAstArray");function xO(s){return s.type===Wo.Literal}t(xO,"isAstLiteral");function sI(s){if(s===void 0)throw new Error("Node is undefined");if(!eM(s))throw new Error("Node is not object")}t(sI,"assertAstObject");import{findNodeAtLocation as Mtr,getNodeValue as jtr,printParseErrorCode as Btr,visit as Utr}from"jsonc-parser";var ztr={DEFAULT:{allowTrailingComma:!1}};function YV(s,o=[],f=ztr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(W){d.type==="property"&&(d.length=W-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(W){return d.children?.push(W),W}t(x,"onValue"),Utr(s,{onObjectBegin:t((W,G,be)=>{d=x({type:"object",offset:W,length:-1,line:G+1,column:be+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((W,G,be,de,se)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:W,offset:G,length:be,line:de,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((W,G)=>{y(W+G),d.length=W+G-d.offset,d=d.parent,y(W+G)},"onObjectEnd"),onArrayBegin:t((W,G,be,de)=>{d=x({type:"array",offset:W,length:-1,line:be+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((W,G)=>{d.length=W+G-d.offset,d=d.parent,y(W+G)},"onArrayEnd"),onLiteralValue:t((W,G,be,de,se)=>{x({type:$tr(W),offset:G,length:be,line:de+1,column:se+1,parent:d,value:W}),y(G+be)},"onLiteralValue"),onSeparator:t((W,G)=>{d.type==="property"&&(W===":"?d.colonOffset=G:W===","&&y(G))},"onSeparator"),onError:t((W,G,be,de,se)=>{o.push({error:W,offset:G,length:be,line:de+1,column:se+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(YV,"parse");function $tr(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t($tr,"getNodeType");function GAe(s,o){return Mtr(s,o)}t(GAe,"findNodeAtLocation");function KV(s){return jtr(s)}t(KV,"getNodeValue");function lat(s){return Btr(s)}t(lat,"printParseErrorCode");var XV=class{static{t(this,"AstAdapter")}parse(o){let d=YV(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:Wo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:Wo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){YP(o.children?.length===2,"Invalid property node");let d={type:Wo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:Wo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:Wo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var DS={createLiteral:t((s,o)=>({type:Wo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:Wo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:Wo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:Wo.Property,parent:f,name:null,value:o};return d.name={value:s,type:Wo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:Wo.Array,parent:o,children:[]};for(let d of s)f.children.push(DS.createLiteral(d,f));return f},"createArrayOfLiterals")};var Jtr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,ZV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case Wo.Array:return this.generateArray(o,f);case Wo.Object:return this.generateObject(o,f);case Wo.Property:return this.generateProperty(o,f);case Wo.Literal:return this.generateLiteral(o,f);case Wo.FunctionCall:return this.generateFunctionCall(o,f);case Wo.Identifier:return this.generateIdentifier(o,f);case Wo.Raw:return this.generateRaw(o,f);case Wo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,x)=>{this.generateSource(o,d),y<x.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=Jtr.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import Wtr from"node:fs/promises";import{parse as qtr}from"@swc/core";var uat=t(async s=>{let o=new Set;try{let f=await Wtr.readFile(s,"utf-8");(await qtr(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var fat={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var YAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var _at={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var KAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var XAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var ylt=B_(rle(),1),vlt=B_(glt(),1);var sle=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new ylt.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,vlt.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},P=y.instancePath.split("/");if(P.length>2){let W=P[1],G=P[2]?parseInt(P[2],10):0,be=P[3],de=Number.isNaN(G)?void 0:f[W][G][be];x={details:{property:W,index:G,field:be,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let W=y.instancePath.split("/"),G=W[W.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var mI=sle.instance;mI.addSchema(KAe,"route-configuration.schema.json");mI.addSchema(_at,"policy-configuration.schema.json");mI.addSchema(YAe,"policies.schema.json");mI.addSchema(XAe,"open-api-route-configuration.schema.json");mI.addSchema(fat,"fragments.schema.json");var oNr=mI.compile(KAe),blt=mI.compile(XAe),_Ie=mI.compile(YAe);var ale=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=_Ie(o),this.results}};var ole=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=blt(o),this.results}};import tlr from"node:path";var pIe=/\$import\((.*)\)/,AH=/\$env\((.*?)\)/g;var $k=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},elr=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),tA=t((s,o)=>{if(!s)return!1;let f=elr(s);return o.split("/").every((x,P)=>{let F=f[P];return F?x==="*"||KP(F)&&F.name.value===x?!0:x==="{}"?F.type===Wo.Object:x==="[]"?F.type===Wo.Array:!1:!1})},"testPosition");var cle=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),eM(o)?o.children.forEach(f=>{this.visitor(f)}):HAe(o)?o.children.forEach(f=>{this.visitor(f)}):KP(o)&&this.visitor(o.value)}},Slt=t(s=>{let o=new RegExp(AH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(AH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),Tlt=t((s,o,f)=>d=>{if(xO(d)&&typeof d.value=="string"&&d.parent&&HAe(d.parent)){if(!s.some(P=>tA(d.parent,P))){AH.test(d.value)&&o.push(new $k("An $env() statement is not expected at this location.",f,d.location,d.value));return}let x=Slt(d.value);if(x){let P=d.parent,F=P.children.indexOf(d);if(F!==-1)if(x.type==="raw"){let W={type:Wo.Raw,parent:P,value:x.value};P.children[F]=W}else P.children[F]=DS.createTemplateString(x.value,d)}return}if(!KP(d)||!xO(d.value)||typeof d.value.value!="string")return;if(!s.some(x=>tA(d,x))){AH.test(d.value.value)&&o.push(new $k("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=Slt(d.value.value);if(y)if(y.type==="raw"){let x={type:Wo.Raw,parent:null,value:y.value};d.value=x}else d.value=DS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var NH="config/routes.json",rlr=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],nlr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],xlt=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],ilr="handler/{}/options/{}/rewritePattern",slr="handler/{}/options/{}/baseUrl",lle=class extends cle{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!KP(o)||!xO(o.value)||typeof o.value.value!="string")&&tA(o,ilr)){if(!o.parent||!eM(o.parent)){this.errors.push(new $k("Invalid node, expected object",NH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:Elt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!KP(o)||!xO(o.value)||typeof o.value.value!="string")&&tA(o,slr)){if(!o.parent||!eM(o.parent)){this.errors.push(new $k("Invalid node, expected object",NH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:Elt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!KP(o)||!xO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!nlr.some(F=>tA(o,F))&&!xlt.some(F=>tA(o,F))){if(pIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new $k("An $import() statement is not expected at this location.",NH,o.location,f))}return}let d=pIe.exec(f);if(xlt.some(F=>tA(o,F))&&!d)return;if(!d){this.errors.push(new $k("Invalid $import() statement",NH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=tlr.posix.join("..",y));let x=this.getImportName(y),P={type:Wo.Identifier,parent:o.parent,value:x};o.value=P}replaceEnvStatements=Tlt(rlr,this.errors,NH)};function Elt(s){return`(request, context) => {
|
|
575
|
+
`),exitCode:x},"Untar process logs")}}t(MZt,"untarFile");async function jZt(s){if(await uAe(s))return await eI.rm(s,{recursive:!0})}t(jZt,"deleteFolder");var eu=fAe;var Plt=B_(Hst(),1);var Gst=["ai-gateway-auth-v2","ai-gateway-configuration-executor-v2","ai-gateway-fallback-model-v2","ai-gateway-metering-v2","ai-gateway-model-filtering-v2","ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2","akamai-ai-firewall","akamai-ai-firewall-v2","akamai-firewall-for-ai","comet-opik-tracing-v2","galileo-tracing-v2","prompt-injection","semantic-cache"];var GV=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(s,o,f,d,y,x){this.type=s,this.name=o,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},ftr=/[$_\p{ID_Start}]/u,_tr=/[$_\u200C\u200D\p{ID_Continue}]/u,qAe=".*";function ptr(s,o){return(o?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(s)}t(ptr,"Re");function Xst(s,o=!1){let f=[],d=0;for(;d<s.length;){let y=s[d],x=t(function(P){if(!o)throw new TypeError(P);f.push({type:"INVALID_CHAR",index:d,value:s[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:s[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:s[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:s[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:s[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:s[d++]});continue}if(y===":"){let P="",F=d+1;for(;F<s.length;){let W=s.substr(F,1);if(F===d+1&&ftr.test(W)||F!==d+1&&_tr.test(W)){P+=s[F++];continue}break}if(!P){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:P}),d=F;continue}if(y==="("){let P=1,F="",W=d+1,G=!1;if(s[W]==="?"){x(`Pattern cannot start with "?" at ${W}`);continue}for(;W<s.length;){if(!ptr(s[W],!1)){x(`Invalid character '${s[W]}' at ${W}.`),G=!0;break}if(s[W]==="\\"){F+=s[W++]+s[W++];continue}if(s[W]===")"){if(P--,P===0){W++;break}}else if(s[W]==="("&&(P++,s[W+1]!=="?")){x(`Capturing groups are not allowed at ${W}`),G=!0;break}F+=s[W++]}if(G)continue;if(P){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=W;continue}f.push({type:"CHAR",index:d,value:s[d++]})}return f.push({type:"END",index:d,value:""}),f}t(Xst,"v");function Zst(s,o={}){let f=Xst(s);o.delimiter??="/#?",o.prefixes??="./";let d=`[^${_T(o.delimiter)}]+?`,y=[],x=0,P=0,F="",W=new Set,G=t(wn=>{if(P<f.length&&f[P].type===wn)return f[P++].value},"a"),be=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(wn=>{let sn=G(wn);if(sn!==void 0)return sn;let{type:Jn,index:kr}=f[P];throw new TypeError(`Unexpected ${Jn} at ${kr}, expected ${wn}`)},"d"),se=t(()=>{let wn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)wn+=sn;return wn},"T"),Xe=t(wn=>wn,"Se"),Ue=o.encodePart||Xe,je="",Vt=t(wn=>{je+=wn},"U"),Ut=t(()=>{je.length&&(y.push(new GV(3,"","",Ue(je),"",3)),je="")},"$"),Ir=t((wn,sn,Jn,kr,yr)=>{let xs=3;switch(yr){case"?":xs=1;break;case"*":xs=0;break;case"+":xs=2;break}if(!sn&&!Jn&&xs===3){Vt(wn);return}if(Ut(),!sn&&!Jn){if(!wn)return;y.push(new GV(3,"","",Ue(wn),"",xs));return}let bi;Jn?Jn==="*"?bi=qAe:bi=Jn:bi=d;let fc=2;bi===d?(fc=1,bi=""):bi===qAe&&(fc=0,bi="");let Ci;if(sn?Ci=sn:Jn&&(Ci=x++),W.has(Ci))throw new TypeError(`Duplicate name '${Ci}'.`);W.add(Ci),y.push(new GV(fc,Ci,Ue(wn),bi,Ue(kr),xs))},"V");for(;P<f.length;){let wn=G("CHAR"),sn=G("NAME"),Jn=G("REGEX");if(!sn&&!Jn&&(Jn=G("ASTERISK")),sn||Jn){let yr=wn??"";o.prefixes.indexOf(yr)===-1&&(Vt(yr),yr=""),Ut();let xs=be();Ir(yr,sn,Jn,"",xs);continue}let kr=wn??G("ESCAPED_CHAR");if(kr){Vt(kr);continue}if(G("OPEN")){let yr=se(),xs=G("NAME"),bi=G("REGEX");!xs&&!bi&&(bi=G("ASTERISK"));let fc=se();de("CLOSE");let Ci=be();Ir(yr,xs,bi,fc,Ci);continue}Ut(),de("END")}return y}t(Zst,"D");function _T(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(_T,"S");function Yst(s){return s&&s.ignoreCase?"ui":"u"}t(Yst,"X");function dtr(s,o,f){return Qst(Zst(s,f),o,f)}t(dtr,"Z");function Q9(s){switch(s){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(Q9,"k");function Qst(s,o,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of s){if(F.type===3){F.modifier===3?d+=_T(F.value):d+=`(?:${_T(F.value)})${Q9(F.modifier)}`;continue}o&&o.push(F.name);let W=`[^${_T(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=W:F.type===0&&(G=qAe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${Q9(F.modifier)}`:d+=`((?:${G})${Q9(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${_T(F.prefix)}(${G})${_T(F.suffix)})`,d+=Q9(F.modifier);continue}d+=`(?:${_T(F.prefix)}`,d+=`((?:${G})(?:`,d+=_T(F.suffix),d+=_T(F.prefix),d+=`(?:${G}))*)${_T(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${_T(f.endsWith)}]|$`,x=`[${_T(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,Yst(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let P=!1;if(s.length){let F=s[s.length-1];F.type===3&&F.modifier===3&&(P=f.delimiter.indexOf(F)>-1)}return P||(d+=`(?=${x}|${y})`),new RegExp(d,Yst(f))}t(Qst,"F");var iI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},mtr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},htr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function gtr(s,o){return s.length?s[0]==="/"?!0:!o||s.length<2?!1:(s[0]=="\\"||s[0]=="{")&&s[1]=="/":!1}t(gtr,"J");function eat(s,o){return s.startsWith(o)?s.substring(o.length,s.length):s}t(eat,"Q");function ytr(s,o){return s.endsWith(o)?s.substr(0,s.length-o.length):s}t(ytr,"Ee");function tat(s){return!s||s.length<2?!1:s[0]==="["||(s[0]==="\\"||s[0]==="{")&&s[1]==="["}t(tat,"W");var rat=["ftp","file","http","https","ws","wss"];function nat(s){if(!s)return!0;for(let o of rat)if(s.test(o))return!0;return!1}t(nat,"N");function vtr(s,o){if(s=eat(s,"#"),o||s==="")return s;let f=new URL("https://example.com");return f.hash=s,f.hash?f.hash.substring(1,f.hash.length):""}t(vtr,"te");function btr(s,o){if(s=eat(s,"?"),o||s==="")return s;let f=new URL("https://example.com");return f.search=s,f.search?f.search.substring(1,f.search.length):""}t(btr,"re");function Str(s,o){return o||s===""?s:tat(s)?aat(s):sat(s)}t(Str,"ne");function Ttr(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.password=s,f.password}t(Ttr,"se");function xtr(s,o){if(o||s==="")return s;let f=new URL("https://example.com");return f.username=s,f.username}t(xtr,"ie");function Etr(s,o,f){if(f||s==="")return s;if(o&&!rat.includes(o))return new URL(`${o}:${s}`).pathname;let d=s[0]=="/";return s=new URL(d?s:"/-"+s,"https://example.com").pathname,d||(s=s.substring(2,s.length)),s}t(Etr,"ae");function Ctr(s,o,f){return iat(o)===s&&(s=""),f||s===""?s:oat(s)}t(Ctr,"oe");function ktr(s,o){return s=ytr(s,":"),o||s===""?s:VAe(s)}t(ktr,"ce");function iat(s){switch(s){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(iat,"_");function VAe(s){if(s==="")return s;if(/^[-+.A-Za-z0-9]*$/.test(s))return s.toLowerCase();throw new TypeError(`Invalid protocol '${s}'.`)}t(VAe,"y");function wtr(s){if(s==="")return s;let o=new URL("https://example.com");return o.username=s,o.username}t(wtr,"le");function Dtr(s){if(s==="")return s;let o=new URL("https://example.com");return o.password=s,o.password}t(Dtr,"fe");function sat(s){if(s==="")return s;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(s))throw new TypeError(`Invalid hostname '${s}'`);let o=new URL("https://example.com");return o.hostname=s,o.hostname}t(sat,"z");function aat(s){if(s==="")return s;if(/[^0-9a-fA-F[\]:]/g.test(s))throw new TypeError(`Invalid IPv6 hostname '${s}'`);return s.toLowerCase()}t(aat,"j");function oat(s){if(s===""||/^[0-9]*$/.test(s)&&parseInt(s)<=65535)return s;throw new TypeError(`Invalid port '${s}'.`)}t(oat,"K");function Ptr(s){if(s==="")return s;let o=new URL("https://example.com");return o.pathname=s[0]!=="/"?"/-"+s:s,s[0]!=="/"?o.pathname.substring(2,o.pathname.length):o.pathname}t(Ptr,"he");function Atr(s){return s===""?s:new URL(`data:${s}`).pathname}t(Atr,"ue");function Ntr(s){if(s==="")return s;let o=new URL("https://example.com");return o.search=s,o.search.substring(1,o.search.length)}t(Ntr,"de");function Itr(s){if(s==="")return s;let o=new URL("https://example.com");return o.hash=s,o.hash.substring(1,o.hash.length)}t(Itr,"pe");var Otr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#m=0;#c=0;#u=0;#f=0;#p=!1;constructor(s){this.#e=s}get result(){return this.#t}parse(){for(this.#n=Xst(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#c===0){this.#o(),this.#g()?this.#a(9,1):this.#E()?this.#a(8,1):this.#a(7,0);continue}else if(this.#c===2){this.#h(5);continue}this.#a(10,0);break}if(this.#u>0)if(this.#l())this.#u-=1;else continue;if(this.#A()){this.#u+=1;continue}switch(this.#c){case 0:this.#y()&&this.#h(1);break;case 1:if(this.#y()){this.#D();let s=7,o=1;this.#b()?(s=2,o=3):this.#p&&(s=2),this.#a(s,o)}break;case 2:this.#v()?this.#h(3):(this.#S()||this.#E()||this.#g())&&this.#h(5);break;case 3:this.#C()?this.#a(4,1):this.#v()&&this.#a(5,1);break;case 4:this.#v()&&this.#a(5,1);break;case 5:this.#O()?this.#f+=1:this.#N()&&(this.#f-=1),this.#k()&&!this.#f?this.#a(6,1):this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 6:this.#S()?this.#a(7,0):this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 7:this.#E()?this.#a(8,1):this.#g()&&this.#a(9,1);break;case 8:this.#g()&&this.#a(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#a(s,o){switch(this.#c){case 0:break;case 1:this.#t.protocol=this.#w();break;case 2:break;case 3:this.#t.username=this.#w();break;case 4:this.#t.password=this.#w();break;case 5:this.#t.hostname=this.#w();break;case 6:this.#t.port=this.#w();break;case 7:this.#t.pathname=this.#w();break;case 8:this.#t.search=this.#w();break;case 9:this.#t.hash=this.#w();break;case 10:break}this.#c!==0&&s!==10&&([1,2,3,4].includes(this.#c)&&[6,7,8,9].includes(s)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#c)&&[8,9].includes(s)&&(this.#t.pathname??=this.#p?"/":""),[1,2,3,4,5,6,7].includes(this.#c)&&s===9&&(this.#t.search??="")),this.#i(s,o)}#i(s,o){this.#c=s,this.#m=this.#r+o,this.#r+=o,this.#s=0}#o(){this.#r=this.#m,this.#s=0}#h(s){this.#o(),this.#c=s}#d(s){return s<0&&(s=this.#n.length-s),s<this.#n.length?this.#n[s]:this.#n[this.#n.length-1]}#_(s,o){let f=this.#d(s);return f.value===o&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#y(){return this.#_(this.#r,":")}#b(){return this.#_(this.#r+1,"/")&&this.#_(this.#r+2,"/")}#v(){return this.#_(this.#r,"@")}#C(){return this.#_(this.#r,":")}#k(){return this.#_(this.#r,":")}#S(){return this.#_(this.#r,"/")}#E(){if(this.#_(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let s=this.#d(this.#r-1);return s.type!=="NAME"&&s.type!=="REGEX"&&s.type!=="CLOSE"&&s.type!=="ASTERISK"}#g(){return this.#_(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#_(this.#r,"[")}#N(){return this.#_(this.#r,"]")}#w(){let s=this.#n[this.#r],o=this.#d(this.#m).index;return this.#e.substring(o,s.index)}#D(){let s={};Object.assign(s,iI),s.encodePart=VAe;let o=dtr(this.#w(),void 0,s);this.#p=nat(o)}},WAe=["protocol","username","password","hostname","port","pathname","search","hash"],nI="*";function Kst(s,o){if(typeof s!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(s,o);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(Kst,"ge");function GP(s,o){return o?HV(s):s}t(GP,"b");function VV(s,o,f){let d;if(typeof o.baseURL=="string")try{d=new URL(o.baseURL),o.protocol===void 0&&(s.protocol=GP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&(s.username=GP(d.username,f)),!f&&o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.username===void 0&&o.password===void 0&&(s.password=GP(d.password,f)),o.protocol===void 0&&o.hostname===void 0&&(s.hostname=GP(d.hostname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&(s.port=GP(d.port,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&(s.pathname=GP(d.pathname,f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&(s.search=GP(d.search.substring(1,d.search.length),f)),o.protocol===void 0&&o.hostname===void 0&&o.port===void 0&&o.pathname===void 0&&o.search===void 0&&o.hash===void 0&&(s.hash=GP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${o.baseURL}'.`)}if(typeof o.protocol=="string"&&(s.protocol=ktr(o.protocol,f)),typeof o.username=="string"&&(s.username=xtr(o.username,f)),typeof o.password=="string"&&(s.password=Ttr(o.password,f)),typeof o.hostname=="string"&&(s.hostname=Str(o.hostname,f)),typeof o.port=="string"&&(s.port=Ctr(o.port,s.protocol,f)),typeof o.pathname=="string"){if(s.pathname=o.pathname,d&&!gtr(s.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(s.pathname=GP(d.pathname.substring(0,y+1),f)+s.pathname)}s.pathname=Etr(s.pathname,s.protocol,f)}return typeof o.search=="string"&&(s.search=btr(o.search,f)),typeof o.hash=="string"&&(s.hash=vtr(o.hash,f)),s}t(VV,"w");function HV(s){return s.replace(/([+*?:{}()\\])/g,"\\$1")}t(HV,"C");function Ftr(s){return s.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(Ftr,"Oe");function Ltr(s,o){o.delimiter??="/#?",o.prefixes??="./",o.sensitive??=!1,o.strict??=!1,o.end??=!0,o.start??=!0,o.endsWith="";let f=".*",d=`[^${Ftr(o.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let P=0;P<s.length;++P){let F=s[P];if(F.type===3){if(F.modifier===3){x+=HV(F.value);continue}x+=`{${HV(F.value)}}${Q9(F.modifier)}`;continue}let W=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!o.prefixes.includes(F.prefix)),be=P>0?s[P-1]:null,de=P<s.length-1?s[P+1]:null;if(!G&&W&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let se=de.value.length>0?de.value[0]:"";G=y.test(se)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&be&&be.type===3){let se=be.value[be.value.length-1];G=o.prefixes.includes(se)}G&&(x+="{"),x+=HV(F.prefix),W&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?W||(x+=`(${d})`):F.type===0&&(!W&&(!be||be.type===3||be.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&W&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=HV(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=Q9(F.modifier))}return x}t(Ltr,"ke");var cat=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#m=!1;constructor(s={},o,f){try{let d;if(typeof o=="string"?d=o:f=o,typeof s=="string"){let F=new Otr(s);if(F.parse(),s=F.result,d===void 0&&typeof s.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");s.baseURL=d}else{if(!s||typeof s!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:nI,protocol:nI,username:nI,password:nI,hostname:nI,port:nI,search:nI,hash:nI};this.#e=VV(x,s,!0),iat(this.#e.protocol)===this.#e.port&&(this.#e.port="");let P;for(P of WAe){if(!(P in this.#e))continue;let F={},W=this.#e[P];switch(this.#t[P]=[],P){case"protocol":Object.assign(F,iI),F.encodePart=VAe;break;case"username":Object.assign(F,iI),F.encodePart=wtr;break;case"password":Object.assign(F,iI),F.encodePart=Dtr;break;case"hostname":Object.assign(F,mtr),tat(W)?F.encodePart=aat:F.encodePart=sat;break;case"port":Object.assign(F,iI),F.encodePart=oat;break;case"pathname":nat(this.#n.protocol)?(Object.assign(F,htr,y),F.encodePart=Ptr):(Object.assign(F,iI,y),F.encodePart=Atr);break;case"search":Object.assign(F,iI,y),F.encodePart=Ntr;break;case"hash":Object.assign(F,iI,y),F.encodePart=Itr;break}try{this.#s[P]=Zst(W,F),this.#n[P]=Qst(this.#s[P],this.#t[P],F),this.#r[P]=Ltr(this.#s[P],F),this.#m=this.#m||this.#s[P].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${P} pattern '${this.#e[P]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return!1;try{typeof s=="object"?f=VV(f,s,!1):f=VV(f,Kst(s,o),!1)}catch{return!1}let d;for(d of WAe)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(s={},o){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof s!="string"&&o)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof s>"u")return;try{typeof s=="object"?f=VV(f,s,!1):f=VV(f,Kst(s,o),!1)}catch{return null}let d={};o?d.inputs=[s,o]:d.inputs=[s];let y;for(y of WAe){let x=this.#n[y].exec(f[y]);if(!x)return null;let P={};for(let[F,W]of this.#t[y].entries())if(typeof W=="string"||typeof W=="number"){let G=x[F+1];P[W]=G}d[y]={input:f[y]??"",groups:P}}return d}static compareComponent(s,o,f){let d=t((F,W)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<W[G])return-1;if(F[G]!==W[G])return 1}return 0},"o"),y=new GV(3,"","","","",3),x=new GV(0,"","","","",3),P=t((F,W)=>{let G=0;for(;G<Math.min(F.length,W.length);++G){let be=d(F[G],W[G]);if(be)return be}return F.length===W.length?0:d(F[G]??y,W[G]??y)},"s");return!o.#r[s]&&!f.#r[s]?0:o.#r[s]&&!f.#r[s]?P(o.#s[s],[x]):!o.#r[s]&&f.#r[s]?P([x],f.#s[s]):P(o.#s[s],f.#s[s])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#m}};globalThis.URLPattern||(globalThis.URLPattern=cat);import{AssertionError as Rtr}from"node:assert";function YP(s,o){if(s===!1)throw new Rtr({message:o})}t(YP,"assert");var Wo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(Wo||(Wo={}));function eM(s){return s.type===Wo.Object}t(eM,"isAstObject");function KP(s){return s.type===Wo.Property}t(KP,"isAstProperty");function HAe(s){return s.type===Wo.Array}t(HAe,"isAstArray");function xO(s){return s.type===Wo.Literal}t(xO,"isAstLiteral");function sI(s){if(s===void 0)throw new Error("Node is undefined");if(!eM(s))throw new Error("Node is not object")}t(sI,"assertAstObject");import{findNodeAtLocation as Mtr,getNodeValue as jtr,printParseErrorCode as Btr,visit as Utr}from"jsonc-parser";var ztr={DEFAULT:{allowTrailingComma:!1}};function YV(s,o=[],f=ztr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(W){d.type==="property"&&(d.length=W-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(W){return d.children?.push(W),W}t(x,"onValue"),Utr(s,{onObjectBegin:t((W,G,be)=>{d=x({type:"object",offset:W,length:-1,line:G+1,column:be+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((W,G,be,de,se)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:W,offset:G,length:be,line:de,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((W,G)=>{y(W+G),d.length=W+G-d.offset,d=d.parent,y(W+G)},"onObjectEnd"),onArrayBegin:t((W,G,be,de)=>{d=x({type:"array",offset:W,length:-1,line:be+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((W,G)=>{d.length=W+G-d.offset,d=d.parent,y(W+G)},"onArrayEnd"),onLiteralValue:t((W,G,be,de,se)=>{x({type:$tr(W),offset:G,length:be,line:de+1,column:se+1,parent:d,value:W}),y(G+be)},"onLiteralValue"),onSeparator:t((W,G)=>{d.type==="property"&&(W===":"?d.colonOffset=G:W===","&&y(G))},"onSeparator"),onError:t((W,G,be,de,se)=>{o.push({error:W,offset:G,length:be,line:de+1,column:se+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(YV,"parse");function $tr(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t($tr,"getNodeType");function GAe(s,o){return Mtr(s,o)}t(GAe,"findNodeAtLocation");function KV(s){return jtr(s)}t(KV,"getNodeValue");function lat(s){return Btr(s)}t(lat,"printParseErrorCode");var XV=class{static{t(this,"AstAdapter")}parse(o){let d=YV(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:Wo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:Wo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){YP(o.children?.length===2,"Invalid property node");let d={type:Wo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:Wo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:Wo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var DS={createLiteral:t((s,o)=>({type:Wo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:Wo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:Wo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:Wo.Property,parent:f,name:null,value:o};return d.name={value:s,type:Wo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:Wo.Array,parent:o,children:[]};for(let d of s)f.children.push(DS.createLiteral(d,f));return f},"createArrayOfLiterals")};var Jtr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,ZV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case Wo.Array:return this.generateArray(o,f);case Wo.Object:return this.generateObject(o,f);case Wo.Property:return this.generateProperty(o,f);case Wo.Literal:return this.generateLiteral(o,f);case Wo.FunctionCall:return this.generateFunctionCall(o,f);case Wo.Identifier:return this.generateIdentifier(o,f);case Wo.Raw:return this.generateRaw(o,f);case Wo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,x)=>{this.generateSource(o,d),y<x.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=Jtr.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import Wtr from"node:fs/promises";import{parse as qtr}from"@swc/core";var uat=t(async s=>{let o=new Set;try{let f=await Wtr.readFile(s,"utf-8");(await qtr(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var fat={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var YAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var _at={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var KAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var XAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var ylt=B_(rle(),1),vlt=B_(glt(),1);var sle=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new ylt.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,vlt.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},P=y.instancePath.split("/");if(P.length>2){let W=P[1],G=P[2]?parseInt(P[2],10):0,be=P[3],de=Number.isNaN(G)?void 0:f[W][G][be];x={details:{property:W,index:G,field:be,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let W=y.instancePath.split("/"),G=W[W.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var mI=sle.instance;mI.addSchema(KAe,"route-configuration.schema.json");mI.addSchema(_at,"policy-configuration.schema.json");mI.addSchema(YAe,"policies.schema.json");mI.addSchema(XAe,"open-api-route-configuration.schema.json");mI.addSchema(fat,"fragments.schema.json");var oNr=mI.compile(KAe),blt=mI.compile(XAe),_Ie=mI.compile(YAe);var ale=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=_Ie(o),this.results}};var ole=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=blt(o),this.results}};import tlr from"node:path";var pIe=/\$import\((.*)\)/,AH=/\$env\((.*?)\)/g;var $k=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},elr=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),tA=t((s,o)=>{if(!s)return!1;let f=elr(s);return o.split("/").every((x,P)=>{let F=f[P];return F?x==="*"||KP(F)&&F.name.value===x?!0:x==="{}"?F.type===Wo.Object:x==="[]"?F.type===Wo.Array:!1:!1})},"testPosition");var cle=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),eM(o)?o.children.forEach(f=>{this.visitor(f)}):HAe(o)?o.children.forEach(f=>{this.visitor(f)}):KP(o)&&this.visitor(o.value)}},Slt=t(s=>{let o=new RegExp(AH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(AH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),Tlt=t((s,o,f)=>d=>{if(xO(d)&&typeof d.value=="string"&&d.parent&&HAe(d.parent)){if(!s.some(P=>tA(d.parent,P))){AH.test(d.value)&&o.push(new $k("An $env() statement is not expected at this location.",f,d.location,d.value));return}let x=Slt(d.value);if(x){let P=d.parent,F=P.children.indexOf(d);if(F!==-1)if(x.type==="raw"){let W={type:Wo.Raw,parent:P,value:x.value};P.children[F]=W}else P.children[F]=DS.createTemplateString(x.value,d)}return}if(!KP(d)||!xO(d.value)||typeof d.value.value!="string")return;if(!s.some(x=>tA(d,x))){AH.test(d.value.value)&&o.push(new $k("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=Slt(d.value.value);if(y)if(y.type==="raw"){let x={type:Wo.Raw,parent:null,value:y.value};d.value=x}else d.value=DS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var NH="config/routes.json",rlr=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],nlr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],xlt=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],ilr="handler/{}/options/{}/rewritePattern",slr="handler/{}/options/{}/baseUrl",lle=class extends cle{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!KP(o)||!xO(o.value)||typeof o.value.value!="string")&&tA(o,ilr)){if(!o.parent||!eM(o.parent)){this.errors.push(new $k("Invalid node, expected object",NH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:Elt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!KP(o)||!xO(o.value)||typeof o.value.value!="string")&&tA(o,slr)){if(!o.parent||!eM(o.parent)){this.errors.push(new $k("Invalid node, expected object",NH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:Wo.Raw,parent:null,value:Elt(f)},y=DS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!KP(o)||!xO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!nlr.some(F=>tA(o,F))&&!xlt.some(F=>tA(o,F))){if(pIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new $k("An $import() statement is not expected at this location.",NH,o.location,f))}return}let d=pIe.exec(f);if(xlt.some(F=>tA(o,F))&&!d)return;if(!d){this.errors.push(new $k("Invalid $import() statement",NH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=tlr.posix.join("..",y));let x=this.getImportName(y),P={type:Wo.Identifier,parent:o.parent,value:x};o.value=P}replaceEnvStatements=Tlt(rlr,this.errors,NH)};function Elt(s){return`(request, context) => {
|
|
576
576
|
const { params, url, query, method, headers } = request;
|
|
577
577
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
578
578
|
const e = encodeURIComponent;
|