@zuplo/core 6.59.8 → 6.59.9
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/customer.cli.minified.js +1 -1
- package/index.minified.js +1 -1
- package/package.json +4 -4
package/customer.cli.minified.js
CHANGED
|
@@ -580,7 +580,7 @@ globstar while`,s,Q,l,Re,Ie),this.matchOne(s.slice(Q),l.slice(Re),_))return this
|
|
|
580
580
|
`),exitCode:D},"Tar process logs")}}t(Car,"tarFolder");async function Dar({tarFilePath:a,outputDir:s,logger:l}){let _=[],h=[],b;try{await new Promise((D,N)=>{let M=Yut("sh",["-c",`tar -xvf ${a} -C ${s};`]);M.stdout.on("data",z=>{let re=z.toString().trim();re.length>0&&_.push(re.trim())}),M.stderr.on("data",z=>{let re=z.toString().trim();re.length>0&&h.push(re.trim())}),M.on("close",z=>{b=z,z===0?D():N(new Error(`tar process exited with code ${z}`))}),M.on("error",z=>{N(z)})})}catch(D){throw new Error("Failed to untar file",{cause:D})}finally{l.info({stdout:_.join(`
|
|
581
581
|
`),stderr:h.join(`
|
|
582
582
|
`),exitCode:b},"Untar process logs")}}t(Dar,"untarFile");async function kar(a){if(await G3e(a))return await j3.rm(a,{recursive:!0})}t(kar,"deleteFolder");var ou=K3e;var OT=ap(H3e(),1);var cF=class extends Error{static{t(this,"CustomResolveError")}},B3=class{static{t(this,"RefParser")}sourceDirectory;logger;constructor(s,l){this.sourceDirectory=s,this.logger=l}dereference(s,l){return TG.$RefParser.dereference(s,{resolve:{json:!0,file:due(this.sourceDirectory,this.logger),external:!0,http:!1},dereference:{circular:"ignore",onDereference:l?.onDereference}})}bundle(s){return TG.$RefParser.bundle(s,{resolve:{file:due(this.sourceDirectory,this.logger),external:!0,http:!1}})}parse(s){return TG.$RefParser.parse(s,{resolve:{file:due(this.sourceDirectory,this.logger),external:!0,http:!1}})}resolve(s){return TG.$RefParser.resolve(s,{resolve:{file:due(this.sourceDirectory,this.logger),external:!0,http:!1}})}};function due(a,s){return{order:100,canRead(l){let _=Nar(l.url);if(!(_===void 0||_==="file"))return!1;let b;try{b=eft(l.url)}catch(D){throw new cF(`Malformed URI: ${l.url}`,{cause:D})}try{ou.safePath(a).resolve(b)}catch(D){return s?.warn(D),!1}return!0},async read(l){let _;try{_=eft(l.url)}catch(h){throw new cF(`Malformed URI: ${l.url}`,{cause:h})}try{return await war(_)}catch(h){throw new cF(`Error opening file "${_}"`,{cause:h})}}}}t(due,"customResolver");var sj=/^win/.test(globalThis.process?globalThis.process.platform:""),Par=/\//g,Aar=/^(\w{2,}):\/\//i,Y3e=[/%23/g,"#",/%24/g,"$",/%26/g,"&",/%2C/g,",",/%40/g,"@"];function Nar(a){let s=Aar.exec(a);if(s)return s[1].toLowerCase()}t(Nar,"getProtocol");function eft(a,s){a=decodeURI(a);for(let _=0;_<Y3e.length;_+=2)a=a.replace(Y3e[_],Y3e[_+1]);let l=a.substr(0,7).toLowerCase()==="file://";if(l&&(a=a[7]==="/"?a.substr(8):a.substr(7),sj&&a[1]==="/"&&(a=a[0]+":"+a.substr(1)),s?a="file:///"+a:(l=!1,a=sj?a:"/"+a)),!l){let _=a.split(sj?"\\":"/"),h=[];for(let b of _)b===".."?h.length&&h[h.length-1]!==""&&h.pop():(b!==""||h.length===0)&&h.push(b);a=h.join(sj?"\\":"/"),!sj&&h[0]===""&&(a="/"+a.substring(1))}return sj&&!l&&(a=a.replace(Par,"\\"),a.substr(1,2)===":\\"&&(a=a[0].toUpperCase()+a.substr(1))),a}t(eft,"toFileSystemPath");var tft="YOUR_KEY_HERE";async function rft(a){let l=await new B3(a.sourceDirectory,a.logger).bundle(a.openApiDocPath),_=a.openApiDocPath.replace(a.sourceDirectory,"");return Iar({...a,relativeOpenApiPath:_},l)}t(rft,"buildPublicOpenApiFile");async function Iar(a,s){Rar({relativeOpenApiPath:a.relativeOpenApiPath},s);let l=s;return l=Far(l),Oar(l,a.urls?.api?.defaultUrl),l=Lar(l,a),nft(l,"x-zuplo"),l}t(Iar,"buildRawOpenApiFile");function Oar(a,s){s?a.servers=[{url:s}]:a.servers=[]}t(Oar,"addServerHost");function Far(a){if(!a.paths)return a;let{components:s}=a,l=s?{...s}:void 0,_=[];l&&l.parameters&&(_=Object.entries(l.parameters).reduce((b,[D,N])=>(AM in N&&ale(N[AM])&&(b.push(D),l.parameters&&delete l.parameters[D]),b),[]));let h=Object.entries(a.paths).reduce((b,[D,N])=>{if(!N)return b;let M={...N},z=["delete","get","head","patch","post","put","trace","options"];return z.forEach(re=>{let ie=N[re];if(!ie)return;if(ale(ie[AM])){delete M[re];return}let{parameters:Q}=ie;if(!Q)return;let Re=Q.filter(Ie=>{if(AM in Ie&&ale(Ie[AM]))return!1;if("$ref"in Ie){let we=Ie.$ref.split("/").pop();return we?!_.includes(we):!0}return!0});M[re]={...ie,parameters:Re}}),z.some(re=>!!M[re])&&(b[D]=M),b},{});return{...a,paths:h,components:l}}t(Far,"removeHiddenRoutesAndParams");function Lar(a,{policiesConfig:s}){if(!a.paths)return a;let l=Object.entries(a.paths).reduce((_,[h,b])=>{if(!b)return _;let D={...b};return[D.delete,D.get,D.head,D.patch,D.post,D.put,D.trace,D.options].forEach(N=>{if(!N)return;let M=N["x-zuplo-route"]?.policies?.inbound?.reduce((ie,Q)=>{let Re=s.policies?.find(({name:Ct})=>Ct===Q);if(!Re)return ie;if(!(Re.handler.export==="CompositeInboundPolicy"))return ie.concat(Q);let we=Re.handler.options?.policies;return we?ie.concat(we):ie},[]),z=[];if(M&&M.forEach(ie=>{s.policies?.forEach(Q=>{Q.name===ie&&(Q.handler.export==="ApiAuthKeyInboundPolicy"||Q.handler.export==="ApiKeyInboundPolicy")&&!Q.handler.options?.disableAutomaticallyAddingKeyHeaderToOpenApi&&z.push(Q)})}),z.length>0){let ie=z.length>0&&z[0].handler&&z[0].handler.options&&z[0].handler.options.authHeader?z[0].handler.options.authHeader:"Authorization",Q=z.length>0&&z[0].handler&&z[0].handler.options&&(z[0].handler.options.authScheme||z[0].handler.options.authScheme==="")?z[0].handler.options.authScheme:"Bearer",Re=Q!==""?`${Q} ${tft}`:tft,Ie={name:ie,in:"header",required:!0,example:Re,schema:{type:"string"},description:`The \`${ie}\` header is used to authenticate with the API using your API key. Value is of the format \`${Re}\`.`};N.parameters?N.parameters.some(Sr=>"name"in Sr&&Sr.name===Ie.name)||N.parameters.unshift(Ie):N.parameters=[Ie];let we={type:"http",scheme:Q.toLowerCase()},Ct="api_key";a.components?.securitySchemes?Object.values(a.components?.securitySchemes).some(Sr=>"name"in Sr&&Sr.type==="apiKey"||"type"in Sr&&Sr.type==="http"&&Sr.scheme===Q)||(a.components.securitySchemes={...a.components.securitySchemes,[Ct]:we}):(a.components||(a.components={}),a.components.securitySchemes={[Ct]:we});let xt={[Ct]:[]};N.security?N.security.some(Sr=>Sr[Ct]!==void 0)||N.security.unshift(xt):N.security=[xt]}let re=[];if(M&&M.forEach(ie=>{s.policies?.forEach(Q=>{Q.name===ie&&(Q.handler.export==="RateLimitInboundPolicy"||Q.handler.export==="ComplexRateLimitInboundPolicy")&&re.push(Q)})}),re.length>0){let ie={description:"Rate Limiting Response",content:{"application/json":{schema:{type:"object",required:["type","title","status"],examples:[{type:"https://httpproblems.com/http-status/429",title:"Too Many Requests",status:429,instance:"/foo/bar"}],properties:{type:{type:"string",example:"https://httpproblems.com/http-status/429",description:"A URI reference that identifies the problem."},title:{type:"string",example:"Too Many Requests",description:"A short, human-readable summary of the problem."},status:{type:"number",example:429,description:"The HTTP status code."},instance:{type:"string",example:"/foo/bar"}}}}}},Q={...ie,headers:{"retry-after":{description:"The number of seconds to wait before making a new request.",schema:{type:"integer",example:60}}}};a.components?.responses||a.components||(a.components={}),a.components.responses={...a.components.responses,RateLimitNoRetryAfter:ie,RateLimitWithRetryAfter:Q},N.responses||(N.responses={});let Re=re.some(Ie=>Ie.handler.options?.headerMode!=="none");N.responses[429]||(N.responses[429]={$ref:Re?"#/components/responses/RateLimitWithRetryAfter":"#/components/responses/RateLimitNoRetryAfter"})}}),_[h]=D,_},{});return{...a,paths:l}}t(Lar,"enrichSpecWithZuploData");function nft(a,s){for(let l in a)l.startsWith(s)?delete a[l]:typeof a[l]=="object"&&nft(a[l],s)}t(nft,"removePropertiesByPrefix");function Rar({relativeOpenApiPath:a},s){if(!s||typeof s!="object")throw new q1({message:"The OpenAPI Document could not be parsed.",severity:"error"});if(!("info"in s)||typeof s.info!="object"||!s.info)throw new q1({message:"The OpenAPI document does not have the required 'info' property.",location:{file:a,column:0,length:0,line:0,lineText:"",namespace:"",suggestion:"Add the required 'info' property. https://spec.openapis.org/oas/v3.1.0#info-object"},severity:"error"});if(!("title"in s.info)||typeof s.info.title!="string")throw new q1({message:"The OpenAPI document does not have the required 'info.title' property.",location:{file:a,column:0,length:0,line:0,lineText:"",namespace:"",suggestion:"Add the required 'info.title' property. https://spec.openapis.org/oas/v3.1.0#info-object"},severity:"error"})}t(Rar,"assertIsZuploOpenApiSpec");import DK from"node:path";function Mar(a){if(a.length>=255)throw new TypeError("Alphabet too long");let s=new Uint8Array(256);for(let z=0;z<s.length;z++)s[z]=255;for(let z=0;z<a.length;z++){let re=a.charAt(z),ie=re.charCodeAt(0);if(s[ie]!==255)throw new TypeError(re+" is ambiguous");s[ie]=z}let l=a.length,_=a.charAt(0),h=Math.log(l)/Math.log(256),b=Math.log(256)/Math.log(l);function D(z){if(z instanceof Uint8Array||(ArrayBuffer.isView(z)?z=new Uint8Array(z.buffer,z.byteOffset,z.byteLength):Array.isArray(z)&&(z=Uint8Array.from(z))),!(z instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(z.length===0)return"";let re=0,ie=0,Q=0,Re=z.length;for(;Q!==Re&&z[Q]===0;)Q++,re++;let Ie=(Re-Q)*b+1>>>0,we=new Uint8Array(Ie);for(;Q!==Re;){let Sr=z[Q],cn=0;for(let en=Ie-1;(Sr!==0||cn<ie)&&en!==-1;en--,cn++)Sr+=256*we[en]>>>0,we[en]=Sr%l>>>0,Sr=Sr/l>>>0;if(Sr!==0)throw new Error("Non-zero carry");ie=cn,Q++}let Ct=Ie-ie;for(;Ct!==Ie&&we[Ct]===0;)Ct++;let xt=_.repeat(re);for(;Ct<Ie;++Ct)xt+=a.charAt(we[Ct]);return xt}t(D,"encode");function N(z){if(typeof z!="string")throw new TypeError("Expected String");if(z.length===0)return new Uint8Array;let re=0,ie=0,Q=0;for(;z[re]===_;)ie++,re++;let Re=(z.length-re)*h+1>>>0,Ie=new Uint8Array(Re);for(;z[re];){let Sr=s[z.charCodeAt(re)];if(Sr===255)return;let cn=0;for(let en=Re-1;(Sr!==0||cn<Q)&&en!==-1;en--,cn++)Sr+=l*Ie[en]>>>0,Ie[en]=Sr%256>>>0,Sr=Sr/256>>>0;if(Sr!==0)throw new Error("Non-zero carry");Q=cn,re++}let we=Re-Q;for(;we!==Re&&Ie[we]===0;)we++;let Ct=new Uint8Array(ie+(Re-we)),xt=ie;for(;we!==Re;)Ct[xt++]=Ie[we++];return Ct}t(N,"decodeUnsafe");function M(z){let re=N(z);if(re)return re;throw new Error("Non-base"+l+" character")}return t(M,"decode"),{encode:D,decodeUnsafe:N,decode:M}}t(Mar,"base");var ift=Mar;var jar="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",mue=ift(jar);var Bar=!1;function aj(a,s){return{open:`\x1B[${a.join(";")}m`,close:`\x1B[${s}m`,regexp:new RegExp(`\\x1b\\[${s}m`,"g")}}t(aj,"code");function oj(a,s){return Bar?`${s.open}${a.replace(s.regexp,s.open)}${s.close}`:a}t(oj,"run");function Uar(a){return oj(a,aj([31],39))}t(Uar,"red");function $ar(a){return oj(a,aj([32],39))}t($ar,"green");function zar(a){return oj(a,aj([33],39))}t(zar,"yellow");function Jar(a){return oj(a,aj([34],39))}t(Jar,"blue");function qar(a){return oj(a,aj([35],39))}t(qar,"magenta");function Var(a){return oj(a,aj([36],39))}t(Var,"cyan");var eOr=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|"),"g");var sft=[Uar,$ar,zar,Jar,qar,Var];function War(a){let s=0,l=a.length,_=0;if(l>0)for(;_<l;)s=(s<<5)-s+a.charCodeAt(_++)|0;return s}t(War,"hashCode");function aft(a){let s=Math.abs(War(a));return sft[s%sft.length]}t(aft,"generateColor");import{inspect as Har}from"node:util";function oft(a,s,...l){let _=0,h=l.length,b=String(s).replace(/%[sdjoO%]/g,D=>{if(D==="%%")return"%";if(_>=h)return D;switch(D){case"%s":return String(l[_++]);case"%d":return Number(l[_++]).toString();case"%o":return a(l[_++]).split(`
|
|
583
|
-
`).map(N=>N.trim()).join(" ");case"%O":return a(l[_++]);case"%j":try{return JSON.stringify(l[_++])}catch{return"[Circular]"}default:return D}});for(let D of l.splice(_))D===null||!(typeof D=="object"&&D!==null)?b+=" "+D:b+=" "+a(D);return b}t(oft,"format");var cft=t((a,...s)=>oft(Har,a,s),"format");var X3e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=aft(l),this.last=0,this.enabled=s.enabled.some(_=>_.test(l))}log(...s){if(!this.enabled)return;let l,_=s[0];typeof _=="function"?l=_():l=String(_);let h=Date.now()-(this.last||Date.now());l=cft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},Q3e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function Gar(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(Gar,"extract");var hue;function gue(a){hue||(hue=new Q3e(Gar(process.env.DEBUG)));let s=new X3e(hue,a);return hue.debuggers.set(a,s),Object.assign(s.log.bind(s),{self:s})}t(gue,"debug");var U3=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,l){typeof s=="string"?super(s,l):(super(s.message,l),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var lft="zp-local-service";var hOr=Symbol("zuplo_meters"),gOr=Symbol("zuplo_dynamic_meters");var lF=gue("zuplo:runtime:external-service");function Kar(){let a,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=F0.instance.runtime;if(s&&s!=="undefined")try{let l=atob(s);a=JSON.parse(l)}catch{}return a}t(Kar,"getServiceAuth");async function uft(a,s){let l=Kar();if(l)if(lF(`Using external service auth. ClientId: ${l.clientId})`),typeof a=="string"){let _=new URL(a),h=_.hostname,b=s??{},D=new Headers(b.headers||{});D.set("CF-Access-Client-Id",l.clientId),D.set("CF-Access-Client-Secret",l.clientSecret),b.headers=D;let N;if(l.customServiceMapping&&l.customServiceMapping[h])N=`https://${l.customServiceMapping[h]}`;else if(F0.instance.useLegacyServiceRouting)N=`https://${h}.zuptunnel.com`;else{lF("Using sha256 service routing");let re=F0.instance.build;if(re.ACCOUNT_NAME&&re.PROJECT_NAME&&re.ENVIRONMENT_TYPE){let ie=await Yar(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=_ft(re.ENVIRONMENT_TYPE),Re=await Z3e(`${re.ACCOUNT_NAME}-${re.PROJECT_NAME}-${Q}`);Re==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Re==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?N=`https://${ie}.zuptunnel.com`:N=`https://${ie}.t.zuplo.app`}else throw lF("Cannot use sha256 service routing, missing build variables"),new U3("Failed to generate fully qualified tunnel url.")}let M=new URL(`${N}${_.pathname}${_.search}`);lF(`Calling external service: ${M.toString()}`);let z=await xG(M.toString(),b);if(z.status===403&&z.headers.get("cf-access-domain")!==null)throw EG.console.error("403 Forbidden when calling external service.",{clientId:l.clientId,tunnelHost:N}),new U3("Could not connect to secure tunnel.");return z}else throw lF("Cannot call external service with Request object"),new U3("Currently, we only support fetch(<some_string>, ...).");else throw lF("There is no external service auth configured for this zup."),new U3("There are no external services configured for this zup.")}t(uft,"externalServiceHandler");async function fft(a,s){if(typeof a=="string"){let l=new URL(a),_=l.hostname,h=s??{},b=`http://${_}.zuplo.svc.cluster.local:9000`,D=new URL(`${b}${l.pathname}${l.search}`),N=new Headers(h.headers||{});return N.set(lft,_),h.headers=N,await xG(D.toString(),h)}else throw new U3("Currently, we only support fetch(<some_string>, ...).")}t(fft,"clusterServiceHandler");async function Yar(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),N=_ft(_);lF(`Hashing service name: ${b}-${h}.${b}-${D}-${N}`);let M=await Z3e(`${b}-${h}`),z=await Z3e(`${b}-${D}-${N}`);return`${M}.${z}`}t(Yar,"hashServiceName");async function Z3e(a){let s=new TextEncoder().encode(a),l=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(l)).map(b=>b.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(Z3e,"hashSegment");function _ft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(_ft,"sanitizeEnvironmentType");var eNe=new Map;eNe.set("service:",uft);eNe.set("local:",fft);var xG=globalThis.fetch;function tNe(a,s){let l=Xar(s);if(typeof a=="string"){let _=new URL(a),h=eNe.get(_.protocol);return h?h(a,l):xG(a,l)}else return xG(a,l)}t(tNe,"internalFetch");globalThis.fetch=tNe;var Xar=t(a=>{if(!a||a instanceof Request)return a;let s=a;if(!s.zuplo)return a;let l=a;return l.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete a.zuplo,a},"transformInit");var Qar={console:{log:console.log.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),debug:console.debug.bind(console),assert:console.assert.bind(console),clear:console.clear.bind(console),count:console.count.bind(console),countReset:console.countReset.bind(console),dir:console.dir.bind(console),dirxml:console.dirxml.bind(console),group:console.group.bind(console),groupCollapsed:console.groupCollapsed.bind(console),groupEnd:console.groupEnd.bind(console),table:console.table.bind(console),time:console.time.bind(console),timeEnd:console.timeEnd.bind(console),timeLog:console.timeLog.bind(console),timeStamp:console.timeStamp.bind(console),trace:console.trace.bind(console),profile:console.profile.bind(console),profileEnd:console.profileEnd.bind(console)},fetch:tNe},EG=Qar;var rNe="2025-02-06",pft=Object.freeze({none:{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2023-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-01-15":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-09-02":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2025-02-06":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!0,useForwardRedirectsPropOnUrlForwardHandler:!0}});function dft(){return new F0({build:{ACCOUNT_NAME:"mock-account-name",PROJECT_NAME:"mock-project-name",API_VERSION:"0.0.0",BUILD_ID:crypto.randomUUID(),TIMESTAMP:new Date().toISOString(),BUILD_ENV:"test",ZUPLO_VERSION:"0.0.0",COMPATIBILITY_DATE:rNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:pft[rNe]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:""}})}t(dft,"getMockEnvironment");var F0=class a{static{t(this,"Environment")}config;static#r;static#n=!1;static initialize(s){this.#r||(this.#r=new a(s),this.#n=!0)}static get instance(){return this.#n||(EG.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),this.#r=dft()),this.#r}constructor({build:s,runtime:l}){let _;try{if(l.ZUPLO_SYSTEM_CONFIGURATIONS){let h=new TextDecoder().decode(mue.decode(l.ZUPLO_SYSTEM_CONFIGURATIONS)),b=JSON.parse(h);for(let D of Object.keys(b))l[D]||(l[D]=b[D])}if(l.__ZUPLO_CONFIG){let h=atob(l.__ZUPLO_CONFIG);_=JSON.parse(h)}}catch(h){EG.console.error("Failed to parse runtime configuration",h)}this.config=_??{},this.build=s,this.runtime=l,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=typeof globalThis.Deno<"u"&&globalThis.Deno.version&&globalThis.Deno.version.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,l=this.config.rate_limit_service_timeout_ms,_=s??l;if(!_)return 500;let h=Number(_);return Number.isFinite(h)&&h>0?h:500}};var Zar=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function mft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!Zar.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):a.startsWith("ZUDOKU_")?!a.startsWith("ZUDOKU_PUBLIC_"):!1}t(mft,"isRestrictedEnvVariableName");function hft(a){return!!a.startsWith("ZUPLO_")}t(hft,"isZuploReadableEnvVariableName");var JOr=new Proxy({},{get(a,s){let l=String(s);switch(l){case"ZUPLO_ENVIRONMENT_TYPE":return F0.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return F0.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return F0.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return F0.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return F0.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return F0.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return F0.instance.build.COMPATIBILITY_DATE}if(!(mft(l)&&!hft(l)))return F0.instance.runtime[l]}});function CG(a,s,l){return`_${DA(`${a}_${s}_${l}`)}`}t(CG,"getRawOperationDataIdentifierName");function nNe(a,s,l,_){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(nNe,"getIdForParameterSchema");function iNe(a,s,l){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_rb_${DA(l.toLowerCase())}`}t(iNe,"getIdForRequestBodySchema");function DG(a,s){return`_${DA(a)}_${DA(s)}`}t(DG,"getIdForRefSchema");function DA(a){let s=a.replace(/\[/g,"_LBRACKET_").replace(/\]/g,"_RBRACKET_").replace(/\{/g,"_LCURLY_").replace(/\}/g,"_RCURLY_").replace(/\//g,"_SLASH_").replace(/-/g,"_DASH_").replace(/\./g,"_DOT_").replace(/\+/g,"_PLUS_").replace(/:/g,"_COLON_").replace(/@/g,"_AT_").replace(/\$/g,"_DOLLAR_").replace(/[^a-zA-Z0-9_]/g,"_");return/^[a-zA-Z_]/.test(s)||(s="_"+s),s}t(DA,"sanitizedIdentifierName");var Ght=ap(apt(),1);var zG=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(a,s,l,_,h,b){this.type=a,this.name=s,this.prefix=l,this.value=_,this.suffix=h,this.modifier=b}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},Wlr=/[$_\p{ID_Start}]/u,Hlr=/[$_\u200C\u200D\p{ID_Continue}]/u,QNe=".*";function Glr(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(Glr,"Re");function lpt(a,s=!1){let l=[],_=0;for(;_<a.length;){let h=a[_],b=t(function(D){if(!s)throw new TypeError(D);l.push({type:"INVALID_CHAR",index:_,value:a[_++]})},"c");if(h==="*"){l.push({type:"ASTERISK",index:_,value:a[_++]});continue}if(h==="+"||h==="?"){l.push({type:"OTHER_MODIFIER",index:_,value:a[_++]});continue}if(h==="\\"){l.push({type:"ESCAPED_CHAR",index:_++,value:a[_++]});continue}if(h==="{"){l.push({type:"OPEN",index:_,value:a[_++]});continue}if(h==="}"){l.push({type:"CLOSE",index:_,value:a[_++]});continue}if(h===":"){let D="",N=_+1;for(;N<a.length;){let M=a.substr(N,1);if(N===_+1&&Wlr.test(M)||N!==_+1&&Hlr.test(M)){D+=a[N++];continue}break}if(!D){b(`Missing parameter name at ${_}`);continue}l.push({type:"NAME",index:_,value:D}),_=N;continue}if(h==="("){let D=1,N="",M=_+1,z=!1;if(a[M]==="?"){b(`Pattern cannot start with "?" at ${M}`);continue}for(;M<a.length;){if(!Glr(a[M],!1)){b(`Invalid character '${a[M]}' at ${M}.`),z=!0;break}if(a[M]==="\\"){N+=a[M++]+a[M++];continue}if(a[M]===")"){if(D--,D===0){M++;break}}else if(a[M]==="("&&(D++,a[M+1]!=="?")){b(`Capturing groups are not allowed at ${M}`),z=!0;break}N+=a[M++]}if(z)continue;if(D){b(`Unbalanced pattern at ${_}`);continue}if(!N){b(`Missing pattern at ${_}`);continue}l.push({type:"REGEX",index:_,value:N}),_=M;continue}l.push({type:"CHAR",index:_,value:a[_++]})}return l.push({type:"END",index:_,value:""}),l}t(lpt,"v");function upt(a,s={}){let l=lpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,N="",M=new Set,z=t(cn=>{if(D<l.length&&l[D].type===cn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(cn=>{let en=z(cn);if(en!==void 0)return en;let{type:an,index:xr}=l[D];throw new TypeError(`Unexpected ${an} at ${xr}, expected ${cn}`)},"d"),Q=t(()=>{let cn="",en;for(;en=z("CHAR")??z("ESCAPED_CHAR");)cn+=en;return cn},"T"),Re=t(cn=>cn,"Se"),Ie=s.encodePart||Re,we="",Ct=t(cn=>{we+=cn},"U"),xt=t(()=>{we.length&&(h.push(new zG(3,"","",Ie(we),"",3)),we="")},"$"),Sr=t((cn,en,an,xr,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!en&&!an&&fs===3){Ct(cn);return}if(xt(),!en&&!an){if(!cn)return;h.push(new zG(3,"","",Ie(cn),"",fs));return}let Oi;an?an==="*"?Oi=QNe:Oi=an:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===QNe&&(Ho=0,Oi="");let di;if(en?di=en:an&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new zG(Ho,di,Ie(cn),Oi,Ie(xr),fs))},"V");for(;D<l.length;){let cn=z("CHAR"),en=z("NAME"),an=z("REGEX");if(!en&&!an&&(an=z("ASTERISK")),en||an){let vr=cn??"";s.prefixes.indexOf(vr)===-1&&(Ct(vr),vr=""),xt();let fs=re();Sr(vr,en,an,"",fs);continue}let xr=cn??z("ESCAPED_CHAR");if(xr){Ct(xr);continue}if(z("OPEN")){let vr=Q(),fs=z("NAME"),Oi=z("REGEX");!fs&&!Oi&&(Oi=z("ASTERISK"));let Ho=Q();ie("CLOSE");let di=re();Sr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(upt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function opt(a){return a&&a.ignoreCase?"ui":"u"}t(opt,"X");function Klr(a,s,l){return fpt(upt(a,l),s,l)}t(Klr,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function fpt(a,s,l={}){l.delimiter??="/#?",l.prefixes??="./",l.sensitive??=!1,l.strict??=!1,l.end??=!0,l.start??=!0,l.endsWith="";let _=l.start?"^":"";for(let N of a){if(N.type===3){N.modifier===3?_+=MT(N.value):_+=`(?:${MT(N.value)})${gj(N.modifier)}`;continue}s&&s.push(N.name);let M=`[^${MT(l.delimiter)}]+?`,z=N.value;if(N.type===1?z=M:N.type===0&&(z=QNe),!N.prefix.length&&!N.suffix.length){N.modifier===3||N.modifier===1?_+=`(${z})${gj(N.modifier)}`:_+=`((?:${z})${gj(N.modifier)})`;continue}if(N.modifier===3||N.modifier===1){_+=`(?:${MT(N.prefix)}(${z})${MT(N.suffix)})`,_+=gj(N.modifier);continue}_+=`(?:${MT(N.prefix)}`,_+=`((?:${z})(?:`,_+=MT(N.suffix),_+=MT(N.prefix),_+=`(?:${z}))*)${MT(N.suffix)})`,N.modifier===0&&(_+="?")}let h=`[${MT(l.endsWith)}]|$`,b=`[${MT(l.delimiter)}]`;if(l.end)return l.strict||(_+=`${b}?`),l.endsWith.length?_+=`(?=${h})`:_+="$",new RegExp(_,opt(l));l.strict||(_+=`(?:${b}(?=${h}))?`);let D=!1;if(a.length){let N=a[a.length-1];N.type===3&&N.modifier===3&&(D=l.delimiter.indexOf(N)>-1)}return D||(_+=`(?=${b}|${h})`),new RegExp(_,opt(l))}t(fpt,"F");var q3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},Ylr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Xlr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Qlr(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Qlr,"J");function _pt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(_pt,"Q");function Zlr(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(Zlr,"Ee");function ppt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(ppt,"W");var dpt=["ftp","file","http","https","ws","wss"];function mpt(a){if(!a)return!0;for(let s of dpt)if(a.test(s))return!0;return!1}t(mpt,"N");function eur(a,s){if(a=_pt(a,"#"),s||a==="")return a;let l=new URL("https://example.com");return l.hash=a,l.hash?l.hash.substring(1,l.hash.length):""}t(eur,"te");function tur(a,s){if(a=_pt(a,"?"),s||a==="")return a;let l=new URL("https://example.com");return l.search=a,l.search?l.search.substring(1,l.search.length):""}t(tur,"re");function rur(a,s){return s||a===""?a:ppt(a)?ypt(a):gpt(a)}t(rur,"ne");function nur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(nur,"se");function iur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(iur,"ie");function sur(a,s,l){if(l||a==="")return a;if(s&&!dpt.includes(s))return new URL(`${s}:${a}`).pathname;let _=a[0]=="/";return a=new URL(_?a:"/-"+a,"https://example.com").pathname,_||(a=a.substring(2,a.length)),a}t(sur,"ae");function aur(a,s,l){return hpt(s)===a&&(a=""),l||a===""?a:vpt(a)}t(aur,"oe");function our(a,s){return a=Zlr(a,":"),s||a===""?a:ZNe(a)}t(our,"ce");function hpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(hpt,"_");function ZNe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(ZNe,"y");function cur(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(cur,"le");function lur(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(lur,"fe");function gpt(a){if(a==="")return a;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(a))throw new TypeError(`Invalid hostname '${a}'`);let s=new URL("https://example.com");return s.hostname=a,s.hostname}t(gpt,"z");function ypt(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(ypt,"j");function vpt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(vpt,"K");function uur(a){if(a==="")return a;let s=new URL("https://example.com");return s.pathname=a[0]!=="/"?"/-"+a:a,a[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(uur,"he");function fur(a){return a===""?a:new URL(`data:${a}`).pathname}t(fur,"ue");function _ur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(_ur,"de");function pur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(pur,"pe");var dur=class{static{t(this,"H")}#r;#n=[];#e={};#t=0;#s=1;#p=0;#a=0;#_=0;#c=0;#l=!1;constructor(a){this.#r=a}get result(){return this.#e}parse(){for(this.#n=lpt(this.#r,!0);this.#t<this.#n.length;this.#t+=this.#s){if(this.#s=1,this.#n[this.#t].type==="END"){if(this.#a===0){this.#v(),this.#D()?this.#i(9,1):this.#y()?this.#i(8,1):this.#i(7,0);continue}else if(this.#a===2){this.#d(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#o())this.#_-=1;else continue;if(this.#w()){this.#_+=1;continue}switch(this.#a){case 0:this.#g()&&this.#d(1);break;case 1:if(this.#g()){this.#I();let a=7,s=1;this.#C()?(a=2,s=3):this.#l&&(a=2),this.#i(a,s)}break;case 2:this.#x()?this.#d(3):(this.#E()||this.#y()||this.#D())&&this.#d(5);break;case 3:this.#b()?this.#i(4,1):this.#x()&&this.#i(5,1);break;case 4:this.#x()&&this.#i(5,1);break;case 5:this.#N()?this.#c+=1:this.#S()&&(this.#c-=1),this.#k()&&!this.#c?this.#i(6,1):this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 6:this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 7:this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 8:this.#D()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#e.hostname!==void 0&&this.#e.port===void 0&&(this.#e.port="")}#i(a,s){switch(this.#a){case 0:break;case 1:this.#e.protocol=this.#T();break;case 2:break;case 3:this.#e.username=this.#T();break;case 4:this.#e.password=this.#T();break;case 5:this.#e.hostname=this.#T();break;case 6:this.#e.port=this.#T();break;case 7:this.#e.pathname=this.#T();break;case 8:this.#e.search=this.#T();break;case 9:this.#e.hash=this.#T();break;case 10:break}this.#a!==0&&a!==10&&([1,2,3,4].includes(this.#a)&&[6,7,8,9].includes(a)&&(this.#e.hostname??=""),[1,2,3,4,5,6].includes(this.#a)&&[8,9].includes(a)&&(this.#e.pathname??=this.#l?"/":""),[1,2,3,4,5,6,7].includes(this.#a)&&a===9&&(this.#e.search??="")),this.#f(a,s)}#f(a,s){this.#a=a,this.#p=this.#t+s,this.#t+=s,this.#s=0}#v(){this.#t=this.#p,this.#s=0}#d(a){this.#v(),this.#a=a}#u(a){return a<0&&(a=this.#n.length-a),a<this.#n.length?this.#n[a]:this.#n[this.#n.length-1]}#m(a,s){let l=this.#u(a);return l.value===s&&(l.type==="CHAR"||l.type==="ESCAPED_CHAR"||l.type==="INVALID_CHAR")}#g(){return this.#m(this.#t,":")}#C(){return this.#m(this.#t+1,"/")&&this.#m(this.#t+2,"/")}#x(){return this.#m(this.#t,"@")}#b(){return this.#m(this.#t,":")}#k(){return this.#m(this.#t,":")}#E(){return this.#m(this.#t,"/")}#y(){if(this.#m(this.#t,"?"))return!0;if(this.#n[this.#t].value!=="?")return!1;let a=this.#u(this.#t-1);return a.type!=="NAME"&&a.type!=="REGEX"&&a.type!=="CLOSE"&&a.type!=="ASTERISK"}#D(){return this.#m(this.#t,"#")}#w(){return this.#n[this.#t].type=="OPEN"}#o(){return this.#n[this.#t].type=="CLOSE"}#N(){return this.#m(this.#t,"[")}#S(){return this.#m(this.#t,"]")}#T(){let a=this.#n[this.#t],s=this.#u(this.#p).index;return this.#r.substring(s,a.index)}#I(){let a={};Object.assign(a,q3),a.encodePart=ZNe;let s=Klr(this.#T(),void 0,a);this.#l=mpt(s)}},XNe=["protocol","username","password","hostname","port","pathname","search","hash"],J3="*";function cpt(a,s){if(typeof a!="string")throw new TypeError("parameter 1 is not of type 'string'.");let l=new URL(a,s);return{protocol:l.protocol.substring(0,l.protocol.length-1),username:l.username,password:l.password,hostname:l.hostname,port:l.port,pathname:l.pathname,search:l.search!==""?l.search.substring(1,l.search.length):void 0,hash:l.hash!==""?l.hash.substring(1,l.hash.length):void 0}}t(cpt,"ge");function NA(a,s){return s?$G(a):a}t(NA,"b");function UG(a,s,l){let _;if(typeof s.baseURL=="string")try{_=new URL(s.baseURL),s.protocol===void 0&&(a.protocol=NA(_.protocol.substring(0,_.protocol.length-1),l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(a.username=NA(_.username,l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(a.password=NA(_.password,l)),s.protocol===void 0&&s.hostname===void 0&&(a.hostname=NA(_.hostname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(a.port=NA(_.port,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(a.pathname=NA(_.pathname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(a.search=NA(_.search.substring(1,_.search.length),l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(a.hash=NA(_.hash.substring(1,_.hash.length),l))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(a.protocol=our(s.protocol,l)),typeof s.username=="string"&&(a.username=iur(s.username,l)),typeof s.password=="string"&&(a.password=nur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=rur(s.hostname,l)),typeof s.port=="string"&&(a.port=aur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Qlr(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=NA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=sur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=tur(s.search,l)),typeof s.hash=="string"&&(a.hash=eur(s.hash,l)),a}t(UG,"w");function $G(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t($G,"C");function mur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(mur,"Oe");function hur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${mur(s.delimiter)}]+?`,h=/[$_\u200C\u200D\p{ID_Continue}]/u,b="";for(let D=0;D<a.length;++D){let N=a[D];if(N.type===3){if(N.modifier===3){b+=$G(N.value);continue}b+=`{${$G(N.value)}}${gj(N.modifier)}`;continue}let M=N.hasCustomName(),z=!!N.suffix.length||!!N.prefix.length&&(N.prefix.length!==1||!s.prefixes.includes(N.prefix)),re=D>0?a[D-1]:null,ie=D<a.length-1?a[D+1]:null;if(!z&&M&&N.type===1&&N.modifier===3&&ie&&!ie.prefix.length&&!ie.suffix.length)if(ie.type===3){let Q=ie.value.length>0?ie.value[0]:"";z=h.test(Q)}else z=!ie.hasCustomName();if(!z&&!N.prefix.length&&re&&re.type===3){let Q=re.value[re.value.length-1];z=s.prefixes.includes(Q)}z&&(b+="{"),b+=$G(N.prefix),M&&(b+=`:${N.name}`),N.type===2?b+=`(${N.value})`:N.type===1?M||(b+=`(${_})`):N.type===0&&(!M&&(!re||re.type===3||re.modifier!==3||z||N.prefix!=="")?b+="*":b+=`(${l})`),N.type===1&&M&&N.suffix.length&&h.test(N.suffix[0])&&(b+="\\"),b+=$G(N.suffix),z&&(b+="}"),N.modifier!==3&&(b+=gj(N.modifier))}return b}t(hur,"ke");var bpt=class{static{t(this,"me")}#r;#n={};#e={};#t={};#s={};#p=!1;constructor(a={},s,l){try{let _;if(typeof s=="string"?_=s:l=s,typeof a=="string"){let N=new dur(a);if(N.parse(),a=N.result,_===void 0&&typeof a.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");a.baseURL=_}else{if(!a||typeof a!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(_)throw new TypeError("parameter 1 is not of type 'string'.")}typeof l>"u"&&(l={ignoreCase:!1});let h={ignoreCase:l.ignoreCase===!0},b={pathname:J3,protocol:J3,username:J3,password:J3,hostname:J3,port:J3,search:J3,hash:J3};this.#r=UG(b,a,!0),hpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of XNe){if(!(D in this.#r))continue;let N={},M=this.#r[D];switch(this.#e[D]=[],D){case"protocol":Object.assign(N,q3),N.encodePart=ZNe;break;case"username":Object.assign(N,q3),N.encodePart=cur;break;case"password":Object.assign(N,q3),N.encodePart=lur;break;case"hostname":Object.assign(N,Ylr),ppt(M)?N.encodePart=ypt:N.encodePart=gpt;break;case"port":Object.assign(N,q3),N.encodePart=vpt;break;case"pathname":mpt(this.#n.protocol)?(Object.assign(N,Xlr,h),N.encodePart=uur):(Object.assign(N,q3,h),N.encodePart=fur);break;case"search":Object.assign(N,q3,h),N.encodePart=_ur;break;case"hash":Object.assign(N,q3,h),N.encodePart=pur;break}try{this.#s[D]=upt(M,N),this.#n[D]=fpt(this.#s[D],this.#e[D],N),this.#t[D]=hur(this.#s[D],N),this.#p=this.#p||this.#s[D].some(z=>z.type===2)}catch{throw new TypeError(`invalid ${D} pattern '${this.#r[D]}'.`)}}}catch(_){throw new TypeError(`Failed to construct 'URLPattern': ${_.message}`)}}test(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return!1;try{typeof a=="object"?l=UG(l,a,!1):l=UG(l,cpt(a,s),!1)}catch{return!1}let _;for(_ of XNe)if(!this.#n[_].exec(l[_]))return!1;return!0}exec(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return;try{typeof a=="object"?l=UG(l,a,!1):l=UG(l,cpt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of XNe){let b=this.#n[h].exec(l[h]);if(!b)return null;let D={};for(let[N,M]of this.#e[h].entries())if(typeof M=="string"||typeof M=="number"){let z=b[N+1];D[M]=z}_[h]={input:l[h]??"",groups:D}}return _}static compareComponent(a,s,l){let _=t((N,M)=>{for(let z of["type","modifier","prefix","value","suffix"]){if(N[z]<M[z])return-1;if(N[z]!==M[z])return 1}return 0},"o"),h=new zG(3,"","","","",3),b=new zG(0,"","","","",3),D=t((N,M)=>{let z=0;for(;z<Math.min(N.length,M.length);++z){let re=_(N[z],M[z]);if(re)return re}return N.length===M.length?0:_(N[z]??h,M[z]??h)},"s");return!s.#t[a]&&!l.#t[a]?0:s.#t[a]&&!l.#t[a]?D(s.#s[a],[b]):!s.#t[a]&&l.#t[a]?D([b],l.#s[a]):D(s.#s[a],l.#s[a])}get protocol(){return this.#t.protocol}get username(){return this.#t.username}get password(){return this.#t.password}get hostname(){return this.#t.hostname}get port(){return this.#t.port}get pathname(){return this.#t.pathname}get search(){return this.#t.search}get hash(){return this.#t.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=bpt);import{AssertionError as gur}from"node:assert";function IA(a,s){if(a===!1)throw new gur({message:s})}t(IA,"assert");var ec;(function(a){a.Object="Object",a.Property="Property",a.Array="Array",a.Literal="Literal",a.TemplateString="TemplateString",a.Identifier="Identifier",a.FunctionCall="FunctionCall",a.Raw="Raw"})(ec||(ec={}));function yj(a){return a.type===ec.Object}t(yj,"isAstObject");function OA(a){return a.type===ec.Property}t(OA,"isAstProperty");function Spt(a){return a.type===ec.Array}t(Spt,"isAstArray");function vj(a){return a.type===ec.Literal}t(vj,"isAstLiteral");function V3(a){if(a===void 0)throw new Error("Node is undefined");if(!yj(a))throw new Error("Node is not object")}t(V3,"assertAstObject");import{findNodeAtLocation as yur,getNodeValue as vur,printParseErrorCode as bur,visit as Sur}from"jsonc-parser";var Tur={DEFAULT:{allowTrailingComma:!1}};function JG(a,s=[],l=Tur.DEFAULT){let _={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function h(M){_.type==="property"&&(_.length=M-_.offset,_=_.parent)}t(h,"ensurePropertyComplete");function b(M){return _.children?.push(M),M}t(b,"onValue"),Sur(a,{onObjectBegin:t((M,z,re)=>{_=b({type:"object",offset:M,length:-1,line:z+1,column:re+1,parent:_,children:[]})},"onObjectBegin"),onObjectProperty:t((M,z,re,ie,Q)=>{_=b({type:"property",offset:z,length:-1,line:ie+1,column:Q+1,parent:_,children:[]}),_.children?.push({type:"string",value:M,offset:z,length:re,line:ie,column:Q,parent:_})},"onObjectProperty"),onObjectEnd:t((M,z)=>{h(M+z),_.length=M+z-_.offset,_=_.parent,h(M+z)},"onObjectEnd"),onArrayBegin:t((M,z,re,ie)=>{_=b({type:"array",offset:M,length:-1,line:re+1,column:ie+1,parent:_,children:[]})},"onArrayBegin"),onArrayEnd:t((M,z)=>{_.length=M+z-_.offset,_=_.parent,h(M+z)},"onArrayEnd"),onLiteralValue:t((M,z,re,ie,Q)=>{b({type:xur(M),offset:z,length:re,line:ie+1,column:Q+1,parent:_,value:M}),h(z+re)},"onLiteralValue"),onSeparator:t((M,z)=>{_.type==="property"&&(M===":"?_.colonOffset=z:M===","&&h(z))},"onSeparator"),onError:t((M,z,re,ie,Q)=>{s.push({error:M,offset:z,length:re,line:ie+1,column:Q+1})},"onError")},l);let N=_.children[0];return N&&delete N.parent,N}t(JG,"parse");function xur(a){switch(typeof a){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(a){if(Array.isArray(a))return"array"}else return"null";return"object"}default:return"null"}}t(xur,"getNodeType");function eIe(a,s){return yur(a,s)}t(eIe,"findNodeAtLocation");function qG(a){return vur(a)}t(qG,"getNodeValue");function Tpt(a){return bur(a)}t(Tpt,"printParseErrorCode");var VG=class{static{t(this,"AstAdapter")}parse(s){let _=JG(s,[]);if(_)return this.parseNode(_,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,l){switch(s.type){case"object":return this.createObject(s,l);case"array":return this.createArray(s,l);case"property":return this.createProperty(s,l);case"string":return this.createLiteral(s,l);case"number":return this.createLiteral(s,l);case"boolean":return this.createLiteral(s,l);case"null":return this.createLiteral(s,l)}}createLiteral(s,l){return{type:ec.Literal,location:{line:s.line,column:s.column},parent:l,value:s.type==="null"?null:s.value}}createObject(s,l){let _={type:ec.Object,children:[],parent:l,location:{line:s.line,column:s.column}};return s.children?.forEach(h=>{_.children.push(this.parseNode(h,_))}),_}createProperty(s,l){IA(s.children?.length===2,"Invalid property node");let _={type:ec.Property,location:{line:s.line,column:s.column},parent:l,name:null,value:null};return _.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:ec.Identifier,parent:_},_.value=this.parseNode(s.children[1],_),_}createArray(s,l){let _={type:ec.Array,location:{line:s.line,column:s.column},parent:l,children:[]};return s.children?.forEach(h=>_.children.push(this.parseNode(h,_))),_}};var jT={createLiteral:t((a,s)=>({type:ec.Literal,parent:s,value:a}),"createLiteral"),createTemplateString:t((a,s)=>({type:ec.TemplateString,parent:s,value:a}),"createTemplateString"),createIdentifier:t((a,s)=>({type:ec.Identifier,value:a,parent:s}),"createIdentifier"),createProperty:t((a,s,l)=>{let _={type:ec.Property,parent:l,name:null,value:s};return _.name={value:a,type:ec.Identifier,parent:_},_.value.parent=_,_},"createProperty"),createArrayOfLiterals:t((a,s)=>{let l={type:ec.Array,parent:s,children:[]};for(let _ of a)l.children.push(jT.createLiteral(_,l));return l},"createArrayOfLiterals")};var Eur=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,WG=class{static{t(this,"SourceGenerator")}generate(s){let l=[];return this.generateSource(l,s),l.join("")}generateSource(s,l){switch(l.type){case ec.Array:return this.generateArray(s,l);case ec.Object:return this.generateObject(s,l);case ec.Property:return this.generateProperty(s,l);case ec.Literal:return this.generateLiteral(s,l);case ec.FunctionCall:return this.generateFunctionCall(s,l);case ec.Identifier:return this.generateIdentifier(s,l);case ec.Raw:return this.generateRaw(s,l);case ec.TemplateString:return this.generateTemplateString(s,l)}}generateArray(s,l){s.push("["),l.children.map(_=>{this.generateSource(s,_),s.push(",")}),s.push("]")}generateObject(s,l){s.push("{"),l.children.forEach(_=>{this.generateSource(s,_),s.push(",")}),s.push("}")}generateProperty(s,l){this.generateIdentifier(s,l.name),s.push(":"),this.generateSource(s,l.value)}generateFunctionCall(s,l){s.push(l.name.value),s.push("("),l.children.forEach((_,h,b)=>{this.generateSource(s,_),h<b.length&&s.push(",")}),s.push(")")}generateRaw(s,l){s.push(l.value)}generateTemplateString(s,l){s.push("`"),s.push(l.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,l){if(l.value===null)return s.push("null");switch(typeof l.value){case"number":case"boolean":return s.push(`${l.value}`);case"string":{let _=l.value,h=JSON.stringify(_);return s.push(`${h}`)}}}generateIdentifier(s,l){let _=Eur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Cur from"node:fs/promises";import{parse as Dur}from"@swc/core";var xpt=t(async a=>{let s=new Set;try{let l=await Cur.readFile(a,"utf-8");(await Dur(l,{syntax:"typescript"})).body.forEach(h=>{h.type==="ExportDefaultDeclaration"||h.type==="ExportDefaultExpression"?s.add("default"):h.type==="ExportDeclaration"&&h.declaration.type==="FunctionDeclaration"?s.add(h.declaration.identifier.value):h.type==="ExportDeclaration"&&h.declaration.type==="VariableDeclaration"&&h.declaration.declarations[0].id.type==="Identifier"&&s.add(h.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Ept={$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 tIe={$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 Cpt={$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 rIe={$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:{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-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var nIe={$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 jht=ap(oht(),1),Bht=ap(Mht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new Bht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,jht.default)(this.ajv,{mode:"fast"})}addSchema(s,l){this.ajv.addSchema(s,l)}compile(s){let l=this.ajv.compile(s);return t(h=>({isValid:l(h),errors:this.toSimpleErrors(l.errors,h),warnings:[]}),"validator")}toSimpleErrors(s,l){let _=[];return s?.forEach(h=>{h.keyword==="enum"&&h.params.allowedValues&&Array.isArray(h.params.allowedValues)&&(h.message+=`; ${h.params.allowedValues.join(", ")}`),h.instancePath&&(h.instancePath=h.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let b={details:{}},D=h.instancePath.split("/");if(D.length>2){let M=D[1],z=D[2]?parseInt(D[2]):0,re=D[3],ie=isNaN(z)?void 0:l[M][z][re];b={details:{property:M,index:z,field:re,fieldValue:ie}}}if(h.keyword==="required"&&h.params.missingProperty&&h.instancePath&&(h.message=`A 'path' is missing required property '${h.params.missingProperty}'`),h.keyword==="additionalProperties"&&h.params.additionalProperty&&h.instancePath&&(h.message=`A 'path' should NOT include property '${h.params.additionalProperty}'`),h.keyword==="type"&&h.params.type&&h.instancePath){let M=h.instancePath.split("/"),z=M[M.length-1];h.message=`Value of property '${z}' must be '${h.params.type}'`}let N=Object.assign(h,b);_.push(N)}),_}};var tN=Lfe.instance;tN.addSchema(nIe,"route-configuration.schema.json");tN.addSchema(Cpt,"policy-configuration.schema.json");tN.addSchema(tIe,"policies.schema.json");tN.addSchema(rIe,"open-api-route-configuration.schema.json");tN.addSchema(Ept,"fragments.schema.json");var zLr=tN.compile(nIe),Uht=tN.compile(rIe),yOe=tN.compile(tIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=yOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Uht(s),this.results}};import Ogr from"node:path";var vOe=/\$import\((.*)\)/,jfe=/\$env\((.*?)\)/g;var jA=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,l,_,h){super(s),this.location={file:l,namespace:"",line:_?_.line:0,column:_?_.column:0,length:0,lineText:h??"",suggestion:""}}},Igr=t(a=>{let s=[],l=a;for(;l.parent;)s.push(l),l=l.parent;return s.reverse()},"invertTree"),rN=t((a,s)=>{if(!a)return!1;let l=Igr(a);return s.split("/").every((b,D)=>{let N=l[D];return N?b==="*"||OA(N)&&N.name.value===b?!0:b==="{}"?N.type===ec.Object:b==="[]"?N.type===ec.Array:!1:!1})},"testPosition");var Bfe=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),yj(s)?s.children.forEach(l=>{this.visitor(l)}):Spt(s)?s.children.forEach(l=>{this.visitor(l)}):OA(s)&&this.visitor(s.value)}},$ht=t((a,s,l)=>_=>{if(!OA(_)||!vj(_.value)||typeof _.value.value!="string")return;if(!a.some(b=>rN(_,b))){jfe.test(_.value.value)&&s.push(new jA("An $env() statement is not expected at this location.",l,_.location,_.value.value));return}let h=new RegExp(jfe).exec(_.value.value);if(h?.length===2&&h[0]===_.value.value){let b={type:ec.Raw,parent:null,value:`environment["${h[1]}"]`};_.value=b}else{let b=_.value.value.replaceAll(new RegExp(jfe),(D,N)=>`\${environment["${N}"] ? environment["${N}"] : ""}`);b!==_.value.value&&(_.value=jT.createTemplateString(b,_))}},"getEnvStatementTransformer");var CK="config/routes.json",Fgr=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],Lgr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],zht=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Rgr="handler/{}/options/{}/rewritePattern",Mgr="handler/{}/options/{}/baseUrl",Ufe=class extends Bfe{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let l=this.addedImports.get(s);if(!l)throw new Error("Import name is undefined. This should not happen.");return l}getImports(){let s=[];return this.addedImports.forEach((l,_)=>{s.push({name:l,path:_})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!OA(s)||!vj(s.value)||typeof s.value.value!="string")&&rN(s,Rgr)){if(!s.parent||!yj(s.parent)){this.errors.push(new jA("Invalid node, expected object",CK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Jht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}rewriteForwardFunction(s){if(!(!OA(s)||!vj(s.value)||typeof s.value.value!="string")&&rN(s,Mgr)){if(!s.parent||!yj(s.parent)){this.errors.push(new jA("Invalid node, expected object",CK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Jht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}replaceImportStatements(s){if(!OA(s)||!vj(s.value))return;let l=s.value.value;if(typeof l!="string")return;if(!Lgr.some(N=>rN(s,N))&&!zht.some(N=>rN(s,N))){if(vOe.test(l)){if(s.name.value==="$ref")return;this.errors.push(new jA("An $import() statement is not expected at this location.",CK,s.location,l))}return}let _=vOe.exec(l);if(zht.some(N=>rN(s,N))&&!_)return;if(!_){this.errors.push(new jA("Invalid $import() statement",CK,s.location,l));return}let h=_[1];h=h.replace(/\\/g,"/"),h.startsWith(".")&&(h=Ogr.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=$ht(Fgr,this.errors,CK)};function Jht(a){return`(request, context) => {
|
|
583
|
+
`).map(N=>N.trim()).join(" ");case"%O":return a(l[_++]);case"%j":try{return JSON.stringify(l[_++])}catch{return"[Circular]"}default:return D}});for(let D of l.splice(_))D===null||!(typeof D=="object"&&D!==null)?b+=" "+D:b+=" "+a(D);return b}t(oft,"format");var cft=t((a,...s)=>oft(Har,a,s),"format");var X3e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=aft(l),this.last=0,this.enabled=s.enabled.some(_=>_.test(l))}log(...s){if(!this.enabled)return;let l,_=s[0];typeof _=="function"?l=_():l=String(_);let h=Date.now()-(this.last||Date.now());l=cft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},Q3e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function Gar(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(Gar,"extract");var hue;function gue(a){hue||(hue=new Q3e(Gar(process.env.DEBUG)));let s=new X3e(hue,a);return hue.debuggers.set(a,s),Object.assign(s.log.bind(s),{self:s})}t(gue,"debug");var U3=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,l){typeof s=="string"?super(s,l):(super(s.message,l),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var lft="zp-local-service";var hOr=Symbol("zuplo_meters"),gOr=Symbol("zuplo_dynamic_meters");var lF=gue("zuplo:runtime:external-service");function Kar(){let a,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=F0.instance.runtime;if(s&&s!=="undefined")try{let l=atob(s);a=JSON.parse(l)}catch{}return a}t(Kar,"getServiceAuth");async function uft(a,s){let l=Kar();if(l)if(lF(`Using external service auth. ClientId: ${l.clientId})`),typeof a=="string"){let _=new URL(a),h=_.hostname,b=s??{},D=new Headers(b.headers||{});D.set("CF-Access-Client-Id",l.clientId),D.set("CF-Access-Client-Secret",l.clientSecret),b.headers=D;let N;if(l.customServiceMapping&&l.customServiceMapping[h])N=`https://${l.customServiceMapping[h]}`;else if(F0.instance.useLegacyServiceRouting)N=`https://${h}.zuptunnel.com`;else{lF("Using sha256 service routing");let re=F0.instance.build;if(re.ACCOUNT_NAME&&re.PROJECT_NAME&&re.ENVIRONMENT_TYPE){let ie=await Yar(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=_ft(re.ENVIRONMENT_TYPE),Re=await Z3e(`${re.ACCOUNT_NAME}-${re.PROJECT_NAME}-${Q}`);Re==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Re==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?N=`https://${ie}.zuptunnel.com`:N=`https://${ie}.t.zuplo.app`}else throw lF("Cannot use sha256 service routing, missing build variables"),new U3("Failed to generate fully qualified tunnel url.")}let M=new URL(`${N}${_.pathname}${_.search}`);lF(`Calling external service: ${M.toString()}`);let z=await xG(M.toString(),b);if(z.status===403&&z.headers.get("cf-access-domain")!==null)throw EG.console.error("403 Forbidden when calling external service.",{clientId:l.clientId,tunnelHost:N}),new U3("Could not connect to secure tunnel.");return z}else throw lF("Cannot call external service with Request object"),new U3("Currently, we only support fetch(<some_string>, ...).");else throw lF("There is no external service auth configured for this zup."),new U3("There are no external services configured for this zup.")}t(uft,"externalServiceHandler");async function fft(a,s){if(typeof a=="string"){let l=new URL(a),_=l.hostname,h=s??{},b=`http://${_}.zuplo.svc.cluster.local:9000`,D=new URL(`${b}${l.pathname}${l.search}`),N=new Headers(h.headers||{});return N.set(lft,_),h.headers=N,await xG(D.toString(),h)}else throw new U3("Currently, we only support fetch(<some_string>, ...).")}t(fft,"clusterServiceHandler");async function Yar(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),N=_ft(_);lF(`Hashing service name: ${b}-${h}.${b}-${D}-${N}`);let M=await Z3e(`${b}-${h}`),z=await Z3e(`${b}-${D}-${N}`);return`${M}.${z}`}t(Yar,"hashServiceName");async function Z3e(a){let s=new TextEncoder().encode(a),l=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(l)).map(b=>b.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(Z3e,"hashSegment");function _ft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(_ft,"sanitizeEnvironmentType");var eNe=new Map;eNe.set("service:",uft);eNe.set("local:",fft);var xG=globalThis.fetch;function tNe(a,s){let l=Xar(s);if(typeof a=="string"){let _=new URL(a),h=eNe.get(_.protocol);return h?h(a,l):xG(a,l)}else return xG(a,l)}t(tNe,"internalFetch");globalThis.fetch=tNe;var Xar=t(a=>{if(!a||a instanceof Request)return a;let s=a;if(!s.zuplo)return a;let l=a;return l.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete a.zuplo,a},"transformInit");var Qar={console:{log:console.log.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),debug:console.debug.bind(console),assert:console.assert.bind(console),clear:console.clear.bind(console),count:console.count.bind(console),countReset:console.countReset.bind(console),dir:console.dir.bind(console),dirxml:console.dirxml.bind(console),group:console.group.bind(console),groupCollapsed:console.groupCollapsed.bind(console),groupEnd:console.groupEnd.bind(console),table:console.table.bind(console),time:console.time.bind(console),timeEnd:console.timeEnd.bind(console),timeLog:console.timeLog.bind(console),timeStamp:console.timeStamp.bind(console),trace:console.trace.bind(console),profile:console.profile.bind(console),profileEnd:console.profileEnd.bind(console)},fetch:tNe},EG=Qar;var rNe="2025-02-06",pft=Object.freeze({none:{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2023-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-01-15":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-09-02":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2025-02-06":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!0,useForwardRedirectsPropOnUrlForwardHandler:!0}});function dft(){return new F0({build:{ACCOUNT_NAME:"mock-account-name",PROJECT_NAME:"mock-project-name",API_VERSION:"0.0.0",BUILD_ID:crypto.randomUUID(),TIMESTAMP:new Date().toISOString(),BUILD_ENV:"test",ZUPLO_VERSION:"0.0.0",COMPATIBILITY_DATE:rNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:pft[rNe]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:"",ZUPLO_SERVICE_BUCKET_ID:"mock-bucket-id"}})}t(dft,"getMockEnvironment");var F0=class a{static{t(this,"Environment")}config;static#r;static#n=!1;static initialize(s){this.#r||(this.#r=new a(s),this.#n=!0)}static get instance(){return this.#n||(EG.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),this.#r=dft()),this.#r}constructor({build:s,runtime:l}){let _;try{if(l.ZUPLO_SYSTEM_CONFIGURATIONS){let h=new TextDecoder().decode(mue.decode(l.ZUPLO_SYSTEM_CONFIGURATIONS)),b=JSON.parse(h);for(let D of Object.keys(b))l[D]||(l[D]=b[D])}if(l.__ZUPLO_CONFIG){let h=atob(l.__ZUPLO_CONFIG);_=JSON.parse(h)}}catch(h){EG.console.error("Failed to parse runtime configuration",h)}this.config=_??{},this.build=s,this.runtime=l,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=typeof globalThis.Deno<"u"&&globalThis.Deno.version&&globalThis.Deno.version.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,l=this.config.rate_limit_service_timeout_ms,_=s??l;if(!_)return 500;let h=Number(_);return Number.isFinite(h)&&h>0?h:500}};var Zar=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function mft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!Zar.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):a.startsWith("ZUDOKU_")?!a.startsWith("ZUDOKU_PUBLIC_"):!1}t(mft,"isRestrictedEnvVariableName");function hft(a){return!!a.startsWith("ZUPLO_")}t(hft,"isZuploReadableEnvVariableName");var JOr=new Proxy({},{get(a,s){let l=String(s);switch(l){case"ZUPLO_ENVIRONMENT_TYPE":return F0.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return F0.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return F0.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return F0.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return F0.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return F0.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return F0.instance.build.COMPATIBILITY_DATE}if(!(mft(l)&&!hft(l)))return F0.instance.runtime[l]}});function CG(a,s,l){return`_${DA(`${a}_${s}_${l}`)}`}t(CG,"getRawOperationDataIdentifierName");function nNe(a,s,l,_){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(nNe,"getIdForParameterSchema");function iNe(a,s,l){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_rb_${DA(l.toLowerCase())}`}t(iNe,"getIdForRequestBodySchema");function DG(a,s){return`_${DA(a)}_${DA(s)}`}t(DG,"getIdForRefSchema");function DA(a){let s=a.replace(/\[/g,"_LBRACKET_").replace(/\]/g,"_RBRACKET_").replace(/\{/g,"_LCURLY_").replace(/\}/g,"_RCURLY_").replace(/\//g,"_SLASH_").replace(/-/g,"_DASH_").replace(/\./g,"_DOT_").replace(/\+/g,"_PLUS_").replace(/:/g,"_COLON_").replace(/@/g,"_AT_").replace(/\$/g,"_DOLLAR_").replace(/[^a-zA-Z0-9_]/g,"_");return/^[a-zA-Z_]/.test(s)||(s="_"+s),s}t(DA,"sanitizedIdentifierName");var Ght=ap(apt(),1);var zG=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(a,s,l,_,h,b){this.type=a,this.name=s,this.prefix=l,this.value=_,this.suffix=h,this.modifier=b}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},Wlr=/[$_\p{ID_Start}]/u,Hlr=/[$_\u200C\u200D\p{ID_Continue}]/u,QNe=".*";function Glr(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(Glr,"Re");function lpt(a,s=!1){let l=[],_=0;for(;_<a.length;){let h=a[_],b=t(function(D){if(!s)throw new TypeError(D);l.push({type:"INVALID_CHAR",index:_,value:a[_++]})},"c");if(h==="*"){l.push({type:"ASTERISK",index:_,value:a[_++]});continue}if(h==="+"||h==="?"){l.push({type:"OTHER_MODIFIER",index:_,value:a[_++]});continue}if(h==="\\"){l.push({type:"ESCAPED_CHAR",index:_++,value:a[_++]});continue}if(h==="{"){l.push({type:"OPEN",index:_,value:a[_++]});continue}if(h==="}"){l.push({type:"CLOSE",index:_,value:a[_++]});continue}if(h===":"){let D="",N=_+1;for(;N<a.length;){let M=a.substr(N,1);if(N===_+1&&Wlr.test(M)||N!==_+1&&Hlr.test(M)){D+=a[N++];continue}break}if(!D){b(`Missing parameter name at ${_}`);continue}l.push({type:"NAME",index:_,value:D}),_=N;continue}if(h==="("){let D=1,N="",M=_+1,z=!1;if(a[M]==="?"){b(`Pattern cannot start with "?" at ${M}`);continue}for(;M<a.length;){if(!Glr(a[M],!1)){b(`Invalid character '${a[M]}' at ${M}.`),z=!0;break}if(a[M]==="\\"){N+=a[M++]+a[M++];continue}if(a[M]===")"){if(D--,D===0){M++;break}}else if(a[M]==="("&&(D++,a[M+1]!=="?")){b(`Capturing groups are not allowed at ${M}`),z=!0;break}N+=a[M++]}if(z)continue;if(D){b(`Unbalanced pattern at ${_}`);continue}if(!N){b(`Missing pattern at ${_}`);continue}l.push({type:"REGEX",index:_,value:N}),_=M;continue}l.push({type:"CHAR",index:_,value:a[_++]})}return l.push({type:"END",index:_,value:""}),l}t(lpt,"v");function upt(a,s={}){let l=lpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,N="",M=new Set,z=t(cn=>{if(D<l.length&&l[D].type===cn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(cn=>{let en=z(cn);if(en!==void 0)return en;let{type:an,index:xr}=l[D];throw new TypeError(`Unexpected ${an} at ${xr}, expected ${cn}`)},"d"),Q=t(()=>{let cn="",en;for(;en=z("CHAR")??z("ESCAPED_CHAR");)cn+=en;return cn},"T"),Re=t(cn=>cn,"Se"),Ie=s.encodePart||Re,we="",Ct=t(cn=>{we+=cn},"U"),xt=t(()=>{we.length&&(h.push(new zG(3,"","",Ie(we),"",3)),we="")},"$"),Sr=t((cn,en,an,xr,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!en&&!an&&fs===3){Ct(cn);return}if(xt(),!en&&!an){if(!cn)return;h.push(new zG(3,"","",Ie(cn),"",fs));return}let Oi;an?an==="*"?Oi=QNe:Oi=an:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===QNe&&(Ho=0,Oi="");let di;if(en?di=en:an&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new zG(Ho,di,Ie(cn),Oi,Ie(xr),fs))},"V");for(;D<l.length;){let cn=z("CHAR"),en=z("NAME"),an=z("REGEX");if(!en&&!an&&(an=z("ASTERISK")),en||an){let vr=cn??"";s.prefixes.indexOf(vr)===-1&&(Ct(vr),vr=""),xt();let fs=re();Sr(vr,en,an,"",fs);continue}let xr=cn??z("ESCAPED_CHAR");if(xr){Ct(xr);continue}if(z("OPEN")){let vr=Q(),fs=z("NAME"),Oi=z("REGEX");!fs&&!Oi&&(Oi=z("ASTERISK"));let Ho=Q();ie("CLOSE");let di=re();Sr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(upt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function opt(a){return a&&a.ignoreCase?"ui":"u"}t(opt,"X");function Klr(a,s,l){return fpt(upt(a,l),s,l)}t(Klr,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function fpt(a,s,l={}){l.delimiter??="/#?",l.prefixes??="./",l.sensitive??=!1,l.strict??=!1,l.end??=!0,l.start??=!0,l.endsWith="";let _=l.start?"^":"";for(let N of a){if(N.type===3){N.modifier===3?_+=MT(N.value):_+=`(?:${MT(N.value)})${gj(N.modifier)}`;continue}s&&s.push(N.name);let M=`[^${MT(l.delimiter)}]+?`,z=N.value;if(N.type===1?z=M:N.type===0&&(z=QNe),!N.prefix.length&&!N.suffix.length){N.modifier===3||N.modifier===1?_+=`(${z})${gj(N.modifier)}`:_+=`((?:${z})${gj(N.modifier)})`;continue}if(N.modifier===3||N.modifier===1){_+=`(?:${MT(N.prefix)}(${z})${MT(N.suffix)})`,_+=gj(N.modifier);continue}_+=`(?:${MT(N.prefix)}`,_+=`((?:${z})(?:`,_+=MT(N.suffix),_+=MT(N.prefix),_+=`(?:${z}))*)${MT(N.suffix)})`,N.modifier===0&&(_+="?")}let h=`[${MT(l.endsWith)}]|$`,b=`[${MT(l.delimiter)}]`;if(l.end)return l.strict||(_+=`${b}?`),l.endsWith.length?_+=`(?=${h})`:_+="$",new RegExp(_,opt(l));l.strict||(_+=`(?:${b}(?=${h}))?`);let D=!1;if(a.length){let N=a[a.length-1];N.type===3&&N.modifier===3&&(D=l.delimiter.indexOf(N)>-1)}return D||(_+=`(?=${b}|${h})`),new RegExp(_,opt(l))}t(fpt,"F");var q3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},Ylr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Xlr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Qlr(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Qlr,"J");function _pt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(_pt,"Q");function Zlr(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(Zlr,"Ee");function ppt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(ppt,"W");var dpt=["ftp","file","http","https","ws","wss"];function mpt(a){if(!a)return!0;for(let s of dpt)if(a.test(s))return!0;return!1}t(mpt,"N");function eur(a,s){if(a=_pt(a,"#"),s||a==="")return a;let l=new URL("https://example.com");return l.hash=a,l.hash?l.hash.substring(1,l.hash.length):""}t(eur,"te");function tur(a,s){if(a=_pt(a,"?"),s||a==="")return a;let l=new URL("https://example.com");return l.search=a,l.search?l.search.substring(1,l.search.length):""}t(tur,"re");function rur(a,s){return s||a===""?a:ppt(a)?ypt(a):gpt(a)}t(rur,"ne");function nur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(nur,"se");function iur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(iur,"ie");function sur(a,s,l){if(l||a==="")return a;if(s&&!dpt.includes(s))return new URL(`${s}:${a}`).pathname;let _=a[0]=="/";return a=new URL(_?a:"/-"+a,"https://example.com").pathname,_||(a=a.substring(2,a.length)),a}t(sur,"ae");function aur(a,s,l){return hpt(s)===a&&(a=""),l||a===""?a:vpt(a)}t(aur,"oe");function our(a,s){return a=Zlr(a,":"),s||a===""?a:ZNe(a)}t(our,"ce");function hpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(hpt,"_");function ZNe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(ZNe,"y");function cur(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(cur,"le");function lur(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(lur,"fe");function gpt(a){if(a==="")return a;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(a))throw new TypeError(`Invalid hostname '${a}'`);let s=new URL("https://example.com");return s.hostname=a,s.hostname}t(gpt,"z");function ypt(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(ypt,"j");function vpt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(vpt,"K");function uur(a){if(a==="")return a;let s=new URL("https://example.com");return s.pathname=a[0]!=="/"?"/-"+a:a,a[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(uur,"he");function fur(a){return a===""?a:new URL(`data:${a}`).pathname}t(fur,"ue");function _ur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(_ur,"de");function pur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(pur,"pe");var dur=class{static{t(this,"H")}#r;#n=[];#e={};#t=0;#s=1;#p=0;#a=0;#_=0;#c=0;#l=!1;constructor(a){this.#r=a}get result(){return this.#e}parse(){for(this.#n=lpt(this.#r,!0);this.#t<this.#n.length;this.#t+=this.#s){if(this.#s=1,this.#n[this.#t].type==="END"){if(this.#a===0){this.#v(),this.#D()?this.#i(9,1):this.#y()?this.#i(8,1):this.#i(7,0);continue}else if(this.#a===2){this.#d(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#o())this.#_-=1;else continue;if(this.#w()){this.#_+=1;continue}switch(this.#a){case 0:this.#g()&&this.#d(1);break;case 1:if(this.#g()){this.#I();let a=7,s=1;this.#C()?(a=2,s=3):this.#l&&(a=2),this.#i(a,s)}break;case 2:this.#x()?this.#d(3):(this.#E()||this.#y()||this.#D())&&this.#d(5);break;case 3:this.#b()?this.#i(4,1):this.#x()&&this.#i(5,1);break;case 4:this.#x()&&this.#i(5,1);break;case 5:this.#N()?this.#c+=1:this.#S()&&(this.#c-=1),this.#k()&&!this.#c?this.#i(6,1):this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 6:this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 7:this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 8:this.#D()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#e.hostname!==void 0&&this.#e.port===void 0&&(this.#e.port="")}#i(a,s){switch(this.#a){case 0:break;case 1:this.#e.protocol=this.#T();break;case 2:break;case 3:this.#e.username=this.#T();break;case 4:this.#e.password=this.#T();break;case 5:this.#e.hostname=this.#T();break;case 6:this.#e.port=this.#T();break;case 7:this.#e.pathname=this.#T();break;case 8:this.#e.search=this.#T();break;case 9:this.#e.hash=this.#T();break;case 10:break}this.#a!==0&&a!==10&&([1,2,3,4].includes(this.#a)&&[6,7,8,9].includes(a)&&(this.#e.hostname??=""),[1,2,3,4,5,6].includes(this.#a)&&[8,9].includes(a)&&(this.#e.pathname??=this.#l?"/":""),[1,2,3,4,5,6,7].includes(this.#a)&&a===9&&(this.#e.search??="")),this.#f(a,s)}#f(a,s){this.#a=a,this.#p=this.#t+s,this.#t+=s,this.#s=0}#v(){this.#t=this.#p,this.#s=0}#d(a){this.#v(),this.#a=a}#u(a){return a<0&&(a=this.#n.length-a),a<this.#n.length?this.#n[a]:this.#n[this.#n.length-1]}#m(a,s){let l=this.#u(a);return l.value===s&&(l.type==="CHAR"||l.type==="ESCAPED_CHAR"||l.type==="INVALID_CHAR")}#g(){return this.#m(this.#t,":")}#C(){return this.#m(this.#t+1,"/")&&this.#m(this.#t+2,"/")}#x(){return this.#m(this.#t,"@")}#b(){return this.#m(this.#t,":")}#k(){return this.#m(this.#t,":")}#E(){return this.#m(this.#t,"/")}#y(){if(this.#m(this.#t,"?"))return!0;if(this.#n[this.#t].value!=="?")return!1;let a=this.#u(this.#t-1);return a.type!=="NAME"&&a.type!=="REGEX"&&a.type!=="CLOSE"&&a.type!=="ASTERISK"}#D(){return this.#m(this.#t,"#")}#w(){return this.#n[this.#t].type=="OPEN"}#o(){return this.#n[this.#t].type=="CLOSE"}#N(){return this.#m(this.#t,"[")}#S(){return this.#m(this.#t,"]")}#T(){let a=this.#n[this.#t],s=this.#u(this.#p).index;return this.#r.substring(s,a.index)}#I(){let a={};Object.assign(a,q3),a.encodePart=ZNe;let s=Klr(this.#T(),void 0,a);this.#l=mpt(s)}},XNe=["protocol","username","password","hostname","port","pathname","search","hash"],J3="*";function cpt(a,s){if(typeof a!="string")throw new TypeError("parameter 1 is not of type 'string'.");let l=new URL(a,s);return{protocol:l.protocol.substring(0,l.protocol.length-1),username:l.username,password:l.password,hostname:l.hostname,port:l.port,pathname:l.pathname,search:l.search!==""?l.search.substring(1,l.search.length):void 0,hash:l.hash!==""?l.hash.substring(1,l.hash.length):void 0}}t(cpt,"ge");function NA(a,s){return s?$G(a):a}t(NA,"b");function UG(a,s,l){let _;if(typeof s.baseURL=="string")try{_=new URL(s.baseURL),s.protocol===void 0&&(a.protocol=NA(_.protocol.substring(0,_.protocol.length-1),l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(a.username=NA(_.username,l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(a.password=NA(_.password,l)),s.protocol===void 0&&s.hostname===void 0&&(a.hostname=NA(_.hostname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(a.port=NA(_.port,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(a.pathname=NA(_.pathname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(a.search=NA(_.search.substring(1,_.search.length),l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(a.hash=NA(_.hash.substring(1,_.hash.length),l))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(a.protocol=our(s.protocol,l)),typeof s.username=="string"&&(a.username=iur(s.username,l)),typeof s.password=="string"&&(a.password=nur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=rur(s.hostname,l)),typeof s.port=="string"&&(a.port=aur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Qlr(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=NA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=sur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=tur(s.search,l)),typeof s.hash=="string"&&(a.hash=eur(s.hash,l)),a}t(UG,"w");function $G(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t($G,"C");function mur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(mur,"Oe");function hur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${mur(s.delimiter)}]+?`,h=/[$_\u200C\u200D\p{ID_Continue}]/u,b="";for(let D=0;D<a.length;++D){let N=a[D];if(N.type===3){if(N.modifier===3){b+=$G(N.value);continue}b+=`{${$G(N.value)}}${gj(N.modifier)}`;continue}let M=N.hasCustomName(),z=!!N.suffix.length||!!N.prefix.length&&(N.prefix.length!==1||!s.prefixes.includes(N.prefix)),re=D>0?a[D-1]:null,ie=D<a.length-1?a[D+1]:null;if(!z&&M&&N.type===1&&N.modifier===3&&ie&&!ie.prefix.length&&!ie.suffix.length)if(ie.type===3){let Q=ie.value.length>0?ie.value[0]:"";z=h.test(Q)}else z=!ie.hasCustomName();if(!z&&!N.prefix.length&&re&&re.type===3){let Q=re.value[re.value.length-1];z=s.prefixes.includes(Q)}z&&(b+="{"),b+=$G(N.prefix),M&&(b+=`:${N.name}`),N.type===2?b+=`(${N.value})`:N.type===1?M||(b+=`(${_})`):N.type===0&&(!M&&(!re||re.type===3||re.modifier!==3||z||N.prefix!=="")?b+="*":b+=`(${l})`),N.type===1&&M&&N.suffix.length&&h.test(N.suffix[0])&&(b+="\\"),b+=$G(N.suffix),z&&(b+="}"),N.modifier!==3&&(b+=gj(N.modifier))}return b}t(hur,"ke");var bpt=class{static{t(this,"me")}#r;#n={};#e={};#t={};#s={};#p=!1;constructor(a={},s,l){try{let _;if(typeof s=="string"?_=s:l=s,typeof a=="string"){let N=new dur(a);if(N.parse(),a=N.result,_===void 0&&typeof a.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");a.baseURL=_}else{if(!a||typeof a!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(_)throw new TypeError("parameter 1 is not of type 'string'.")}typeof l>"u"&&(l={ignoreCase:!1});let h={ignoreCase:l.ignoreCase===!0},b={pathname:J3,protocol:J3,username:J3,password:J3,hostname:J3,port:J3,search:J3,hash:J3};this.#r=UG(b,a,!0),hpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of XNe){if(!(D in this.#r))continue;let N={},M=this.#r[D];switch(this.#e[D]=[],D){case"protocol":Object.assign(N,q3),N.encodePart=ZNe;break;case"username":Object.assign(N,q3),N.encodePart=cur;break;case"password":Object.assign(N,q3),N.encodePart=lur;break;case"hostname":Object.assign(N,Ylr),ppt(M)?N.encodePart=ypt:N.encodePart=gpt;break;case"port":Object.assign(N,q3),N.encodePart=vpt;break;case"pathname":mpt(this.#n.protocol)?(Object.assign(N,Xlr,h),N.encodePart=uur):(Object.assign(N,q3,h),N.encodePart=fur);break;case"search":Object.assign(N,q3,h),N.encodePart=_ur;break;case"hash":Object.assign(N,q3,h),N.encodePart=pur;break}try{this.#s[D]=upt(M,N),this.#n[D]=fpt(this.#s[D],this.#e[D],N),this.#t[D]=hur(this.#s[D],N),this.#p=this.#p||this.#s[D].some(z=>z.type===2)}catch{throw new TypeError(`invalid ${D} pattern '${this.#r[D]}'.`)}}}catch(_){throw new TypeError(`Failed to construct 'URLPattern': ${_.message}`)}}test(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return!1;try{typeof a=="object"?l=UG(l,a,!1):l=UG(l,cpt(a,s),!1)}catch{return!1}let _;for(_ of XNe)if(!this.#n[_].exec(l[_]))return!1;return!0}exec(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return;try{typeof a=="object"?l=UG(l,a,!1):l=UG(l,cpt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of XNe){let b=this.#n[h].exec(l[h]);if(!b)return null;let D={};for(let[N,M]of this.#e[h].entries())if(typeof M=="string"||typeof M=="number"){let z=b[N+1];D[M]=z}_[h]={input:l[h]??"",groups:D}}return _}static compareComponent(a,s,l){let _=t((N,M)=>{for(let z of["type","modifier","prefix","value","suffix"]){if(N[z]<M[z])return-1;if(N[z]!==M[z])return 1}return 0},"o"),h=new zG(3,"","","","",3),b=new zG(0,"","","","",3),D=t((N,M)=>{let z=0;for(;z<Math.min(N.length,M.length);++z){let re=_(N[z],M[z]);if(re)return re}return N.length===M.length?0:_(N[z]??h,M[z]??h)},"s");return!s.#t[a]&&!l.#t[a]?0:s.#t[a]&&!l.#t[a]?D(s.#s[a],[b]):!s.#t[a]&&l.#t[a]?D([b],l.#s[a]):D(s.#s[a],l.#s[a])}get protocol(){return this.#t.protocol}get username(){return this.#t.username}get password(){return this.#t.password}get hostname(){return this.#t.hostname}get port(){return this.#t.port}get pathname(){return this.#t.pathname}get search(){return this.#t.search}get hash(){return this.#t.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=bpt);import{AssertionError as gur}from"node:assert";function IA(a,s){if(a===!1)throw new gur({message:s})}t(IA,"assert");var ec;(function(a){a.Object="Object",a.Property="Property",a.Array="Array",a.Literal="Literal",a.TemplateString="TemplateString",a.Identifier="Identifier",a.FunctionCall="FunctionCall",a.Raw="Raw"})(ec||(ec={}));function yj(a){return a.type===ec.Object}t(yj,"isAstObject");function OA(a){return a.type===ec.Property}t(OA,"isAstProperty");function Spt(a){return a.type===ec.Array}t(Spt,"isAstArray");function vj(a){return a.type===ec.Literal}t(vj,"isAstLiteral");function V3(a){if(a===void 0)throw new Error("Node is undefined");if(!yj(a))throw new Error("Node is not object")}t(V3,"assertAstObject");import{findNodeAtLocation as yur,getNodeValue as vur,printParseErrorCode as bur,visit as Sur}from"jsonc-parser";var Tur={DEFAULT:{allowTrailingComma:!1}};function JG(a,s=[],l=Tur.DEFAULT){let _={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function h(M){_.type==="property"&&(_.length=M-_.offset,_=_.parent)}t(h,"ensurePropertyComplete");function b(M){return _.children?.push(M),M}t(b,"onValue"),Sur(a,{onObjectBegin:t((M,z,re)=>{_=b({type:"object",offset:M,length:-1,line:z+1,column:re+1,parent:_,children:[]})},"onObjectBegin"),onObjectProperty:t((M,z,re,ie,Q)=>{_=b({type:"property",offset:z,length:-1,line:ie+1,column:Q+1,parent:_,children:[]}),_.children?.push({type:"string",value:M,offset:z,length:re,line:ie,column:Q,parent:_})},"onObjectProperty"),onObjectEnd:t((M,z)=>{h(M+z),_.length=M+z-_.offset,_=_.parent,h(M+z)},"onObjectEnd"),onArrayBegin:t((M,z,re,ie)=>{_=b({type:"array",offset:M,length:-1,line:re+1,column:ie+1,parent:_,children:[]})},"onArrayBegin"),onArrayEnd:t((M,z)=>{_.length=M+z-_.offset,_=_.parent,h(M+z)},"onArrayEnd"),onLiteralValue:t((M,z,re,ie,Q)=>{b({type:xur(M),offset:z,length:re,line:ie+1,column:Q+1,parent:_,value:M}),h(z+re)},"onLiteralValue"),onSeparator:t((M,z)=>{_.type==="property"&&(M===":"?_.colonOffset=z:M===","&&h(z))},"onSeparator"),onError:t((M,z,re,ie,Q)=>{s.push({error:M,offset:z,length:re,line:ie+1,column:Q+1})},"onError")},l);let N=_.children[0];return N&&delete N.parent,N}t(JG,"parse");function xur(a){switch(typeof a){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(a){if(Array.isArray(a))return"array"}else return"null";return"object"}default:return"null"}}t(xur,"getNodeType");function eIe(a,s){return yur(a,s)}t(eIe,"findNodeAtLocation");function qG(a){return vur(a)}t(qG,"getNodeValue");function Tpt(a){return bur(a)}t(Tpt,"printParseErrorCode");var VG=class{static{t(this,"AstAdapter")}parse(s){let _=JG(s,[]);if(_)return this.parseNode(_,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,l){switch(s.type){case"object":return this.createObject(s,l);case"array":return this.createArray(s,l);case"property":return this.createProperty(s,l);case"string":return this.createLiteral(s,l);case"number":return this.createLiteral(s,l);case"boolean":return this.createLiteral(s,l);case"null":return this.createLiteral(s,l)}}createLiteral(s,l){return{type:ec.Literal,location:{line:s.line,column:s.column},parent:l,value:s.type==="null"?null:s.value}}createObject(s,l){let _={type:ec.Object,children:[],parent:l,location:{line:s.line,column:s.column}};return s.children?.forEach(h=>{_.children.push(this.parseNode(h,_))}),_}createProperty(s,l){IA(s.children?.length===2,"Invalid property node");let _={type:ec.Property,location:{line:s.line,column:s.column},parent:l,name:null,value:null};return _.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:ec.Identifier,parent:_},_.value=this.parseNode(s.children[1],_),_}createArray(s,l){let _={type:ec.Array,location:{line:s.line,column:s.column},parent:l,children:[]};return s.children?.forEach(h=>_.children.push(this.parseNode(h,_))),_}};var jT={createLiteral:t((a,s)=>({type:ec.Literal,parent:s,value:a}),"createLiteral"),createTemplateString:t((a,s)=>({type:ec.TemplateString,parent:s,value:a}),"createTemplateString"),createIdentifier:t((a,s)=>({type:ec.Identifier,value:a,parent:s}),"createIdentifier"),createProperty:t((a,s,l)=>{let _={type:ec.Property,parent:l,name:null,value:s};return _.name={value:a,type:ec.Identifier,parent:_},_.value.parent=_,_},"createProperty"),createArrayOfLiterals:t((a,s)=>{let l={type:ec.Array,parent:s,children:[]};for(let _ of a)l.children.push(jT.createLiteral(_,l));return l},"createArrayOfLiterals")};var Eur=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,WG=class{static{t(this,"SourceGenerator")}generate(s){let l=[];return this.generateSource(l,s),l.join("")}generateSource(s,l){switch(l.type){case ec.Array:return this.generateArray(s,l);case ec.Object:return this.generateObject(s,l);case ec.Property:return this.generateProperty(s,l);case ec.Literal:return this.generateLiteral(s,l);case ec.FunctionCall:return this.generateFunctionCall(s,l);case ec.Identifier:return this.generateIdentifier(s,l);case ec.Raw:return this.generateRaw(s,l);case ec.TemplateString:return this.generateTemplateString(s,l)}}generateArray(s,l){s.push("["),l.children.map(_=>{this.generateSource(s,_),s.push(",")}),s.push("]")}generateObject(s,l){s.push("{"),l.children.forEach(_=>{this.generateSource(s,_),s.push(",")}),s.push("}")}generateProperty(s,l){this.generateIdentifier(s,l.name),s.push(":"),this.generateSource(s,l.value)}generateFunctionCall(s,l){s.push(l.name.value),s.push("("),l.children.forEach((_,h,b)=>{this.generateSource(s,_),h<b.length&&s.push(",")}),s.push(")")}generateRaw(s,l){s.push(l.value)}generateTemplateString(s,l){s.push("`"),s.push(l.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,l){if(l.value===null)return s.push("null");switch(typeof l.value){case"number":case"boolean":return s.push(`${l.value}`);case"string":{let _=l.value,h=JSON.stringify(_);return s.push(`${h}`)}}}generateIdentifier(s,l){let _=Eur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Cur from"node:fs/promises";import{parse as Dur}from"@swc/core";var xpt=t(async a=>{let s=new Set;try{let l=await Cur.readFile(a,"utf-8");(await Dur(l,{syntax:"typescript"})).body.forEach(h=>{h.type==="ExportDefaultDeclaration"||h.type==="ExportDefaultExpression"?s.add("default"):h.type==="ExportDeclaration"&&h.declaration.type==="FunctionDeclaration"?s.add(h.declaration.identifier.value):h.type==="ExportDeclaration"&&h.declaration.type==="VariableDeclaration"&&h.declaration.declarations[0].id.type==="Identifier"&&s.add(h.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Ept={$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 tIe={$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 Cpt={$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 rIe={$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:{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-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var nIe={$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 jht=ap(oht(),1),Bht=ap(Mht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new Bht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,jht.default)(this.ajv,{mode:"fast"})}addSchema(s,l){this.ajv.addSchema(s,l)}compile(s){let l=this.ajv.compile(s);return t(h=>({isValid:l(h),errors:this.toSimpleErrors(l.errors,h),warnings:[]}),"validator")}toSimpleErrors(s,l){let _=[];return s?.forEach(h=>{h.keyword==="enum"&&h.params.allowedValues&&Array.isArray(h.params.allowedValues)&&(h.message+=`; ${h.params.allowedValues.join(", ")}`),h.instancePath&&(h.instancePath=h.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let b={details:{}},D=h.instancePath.split("/");if(D.length>2){let M=D[1],z=D[2]?parseInt(D[2]):0,re=D[3],ie=isNaN(z)?void 0:l[M][z][re];b={details:{property:M,index:z,field:re,fieldValue:ie}}}if(h.keyword==="required"&&h.params.missingProperty&&h.instancePath&&(h.message=`A 'path' is missing required property '${h.params.missingProperty}'`),h.keyword==="additionalProperties"&&h.params.additionalProperty&&h.instancePath&&(h.message=`A 'path' should NOT include property '${h.params.additionalProperty}'`),h.keyword==="type"&&h.params.type&&h.instancePath){let M=h.instancePath.split("/"),z=M[M.length-1];h.message=`Value of property '${z}' must be '${h.params.type}'`}let N=Object.assign(h,b);_.push(N)}),_}};var tN=Lfe.instance;tN.addSchema(nIe,"route-configuration.schema.json");tN.addSchema(Cpt,"policy-configuration.schema.json");tN.addSchema(tIe,"policies.schema.json");tN.addSchema(rIe,"open-api-route-configuration.schema.json");tN.addSchema(Ept,"fragments.schema.json");var zLr=tN.compile(nIe),Uht=tN.compile(rIe),yOe=tN.compile(tIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=yOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Uht(s),this.results}};import Ogr from"node:path";var vOe=/\$import\((.*)\)/,jfe=/\$env\((.*?)\)/g;var jA=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,l,_,h){super(s),this.location={file:l,namespace:"",line:_?_.line:0,column:_?_.column:0,length:0,lineText:h??"",suggestion:""}}},Igr=t(a=>{let s=[],l=a;for(;l.parent;)s.push(l),l=l.parent;return s.reverse()},"invertTree"),rN=t((a,s)=>{if(!a)return!1;let l=Igr(a);return s.split("/").every((b,D)=>{let N=l[D];return N?b==="*"||OA(N)&&N.name.value===b?!0:b==="{}"?N.type===ec.Object:b==="[]"?N.type===ec.Array:!1:!1})},"testPosition");var Bfe=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),yj(s)?s.children.forEach(l=>{this.visitor(l)}):Spt(s)?s.children.forEach(l=>{this.visitor(l)}):OA(s)&&this.visitor(s.value)}},$ht=t((a,s,l)=>_=>{if(!OA(_)||!vj(_.value)||typeof _.value.value!="string")return;if(!a.some(b=>rN(_,b))){jfe.test(_.value.value)&&s.push(new jA("An $env() statement is not expected at this location.",l,_.location,_.value.value));return}let h=new RegExp(jfe).exec(_.value.value);if(h?.length===2&&h[0]===_.value.value){let b={type:ec.Raw,parent:null,value:`environment["${h[1]}"]`};_.value=b}else{let b=_.value.value.replaceAll(new RegExp(jfe),(D,N)=>`\${environment["${N}"] ? environment["${N}"] : ""}`);b!==_.value.value&&(_.value=jT.createTemplateString(b,_))}},"getEnvStatementTransformer");var CK="config/routes.json",Fgr=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],Lgr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],zht=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Rgr="handler/{}/options/{}/rewritePattern",Mgr="handler/{}/options/{}/baseUrl",Ufe=class extends Bfe{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let l=this.addedImports.get(s);if(!l)throw new Error("Import name is undefined. This should not happen.");return l}getImports(){let s=[];return this.addedImports.forEach((l,_)=>{s.push({name:l,path:_})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!OA(s)||!vj(s.value)||typeof s.value.value!="string")&&rN(s,Rgr)){if(!s.parent||!yj(s.parent)){this.errors.push(new jA("Invalid node, expected object",CK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Jht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}rewriteForwardFunction(s){if(!(!OA(s)||!vj(s.value)||typeof s.value.value!="string")&&rN(s,Mgr)){if(!s.parent||!yj(s.parent)){this.errors.push(new jA("Invalid node, expected object",CK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Jht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}replaceImportStatements(s){if(!OA(s)||!vj(s.value))return;let l=s.value.value;if(typeof l!="string")return;if(!Lgr.some(N=>rN(s,N))&&!zht.some(N=>rN(s,N))){if(vOe.test(l)){if(s.name.value==="$ref")return;this.errors.push(new jA("An $import() statement is not expected at this location.",CK,s.location,l))}return}let _=vOe.exec(l);if(zht.some(N=>rN(s,N))&&!_)return;if(!_){this.errors.push(new jA("Invalid $import() statement",CK,s.location,l));return}let h=_[1];h=h.replace(/\\/g,"/"),h.startsWith(".")&&(h=Ogr.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=$ht(Fgr,this.errors,CK)};function Jht(a){return`(request, context) => {
|
|
584
584
|
const { params, url, query, method, headers } = request;
|
|
585
585
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
586
586
|
const e = encodeURIComponent;
|
package/index.minified.js
CHANGED
|
@@ -580,7 +580,7 @@ globstar while`,s,Q,l,Re,Ie),this.matchOne(s.slice(Q),l.slice(Re),_))return this
|
|
|
580
580
|
`),exitCode:D},"Tar process logs")}}t(Kar,"tarFolder");async function Yar({tarFilePath:a,outputDir:s,logger:l}){let _=[],h=[],b;try{await new Promise((D,A)=>{let M=nft("sh",["-c",`tar -xvf ${a} -C ${s};`]);M.stdout.on("data",z=>{let re=z.toString().trim();re.length>0&&_.push(re.trim())}),M.stderr.on("data",z=>{let re=z.toString().trim();re.length>0&&h.push(re.trim())}),M.on("close",z=>{b=z,z===0?D():A(new Error(`tar process exited with code ${z}`))}),M.on("error",z=>{A(z)})})}catch(D){throw new Error("Failed to untar file",{cause:D})}finally{l.info({stdout:_.join(`
|
|
581
581
|
`),stderr:h.join(`
|
|
582
582
|
`),exitCode:b},"Untar process logs")}}t(Yar,"untarFile");async function Xar(a){if(await Z3e(a))return await $3.rm(a,{recursive:!0})}t(Xar,"deleteFolder");var ou=eNe;var OT=x_(Q3e(),1);var uF=class extends Error{static{t(this,"CustomResolveError")}},z3=class{static{t(this,"RefParser")}sourceDirectory;logger;constructor(s,l){this.sourceDirectory=s,this.logger=l}dereference(s,l){return xG.$RefParser.dereference(s,{resolve:{json:!0,file:due(this.sourceDirectory,this.logger),external:!0,http:!1},dereference:{circular:"ignore",onDereference:l?.onDereference}})}bundle(s){return xG.$RefParser.bundle(s,{resolve:{file:due(this.sourceDirectory,this.logger),external:!0,http:!1}})}parse(s){return xG.$RefParser.parse(s,{resolve:{file:due(this.sourceDirectory,this.logger),external:!0,http:!1}})}resolve(s){return xG.$RefParser.resolve(s,{resolve:{file:due(this.sourceDirectory,this.logger),external:!0,http:!1}})}};function due(a,s){return{order:100,canRead(l){let _=tor(l.url);if(!(_===void 0||_==="file"))return!1;let b;try{b=oft(l.url)}catch(D){throw new uF(`Malformed URI: ${l.url}`,{cause:D})}try{ou.safePath(a).resolve(b)}catch(D){return s?.warn(D),!1}return!0},async read(l){let _;try{_=oft(l.url)}catch(h){throw new uF(`Malformed URI: ${l.url}`,{cause:h})}try{return await Qar(_)}catch(h){throw new uF(`Error opening file "${_}"`,{cause:h})}}}}t(due,"customResolver");var sj=/^win/.test(globalThis.process?globalThis.process.platform:""),Zar=/\//g,eor=/^(\w{2,}):\/\//i,tNe=[/%23/g,"#",/%24/g,"$",/%26/g,"&",/%2C/g,",",/%40/g,"@"];function tor(a){let s=eor.exec(a);if(s)return s[1].toLowerCase()}t(tor,"getProtocol");function oft(a,s){a=decodeURI(a);for(let _=0;_<tNe.length;_+=2)a=a.replace(tNe[_],tNe[_+1]);let l=a.substr(0,7).toLowerCase()==="file://";if(l&&(a=a[7]==="/"?a.substr(8):a.substr(7),sj&&a[1]==="/"&&(a=a[0]+":"+a.substr(1)),s?a="file:///"+a:(l=!1,a=sj?a:"/"+a)),!l){let _=a.split(sj?"\\":"/"),h=[];for(let b of _)b===".."?h.length&&h[h.length-1]!==""&&h.pop():(b!==""||h.length===0)&&h.push(b);a=h.join(sj?"\\":"/"),!sj&&h[0]===""&&(a="/"+a.substring(1))}return sj&&!l&&(a=a.replace(Zar,"\\"),a.substr(1,2)===":\\"&&(a=a[0].toUpperCase()+a.substr(1))),a}t(oft,"toFileSystemPath");var cft="YOUR_KEY_HERE";async function lft(a){let l=await new z3(a.sourceDirectory,a.logger).bundle(a.openApiDocPath),_=a.openApiDocPath.replace(a.sourceDirectory,"");return ror({...a,relativeOpenApiPath:_},l)}t(lft,"buildPublicOpenApiFile");async function ror(a,s){aor({relativeOpenApiPath:a.relativeOpenApiPath},s);let l=s;return l=ior(l),nor(l,a.urls?.api?.defaultUrl),l=sor(l,a),uft(l,"x-zuplo"),l}t(ror,"buildRawOpenApiFile");function nor(a,s){s?a.servers=[{url:s}]:a.servers=[]}t(nor,"addServerHost");function ior(a){if(!a.paths)return a;let{components:s}=a,l=s?{...s}:void 0,_=[];l&&l.parameters&&(_=Object.entries(l.parameters).reduce((b,[D,A])=>(NM in A&&ale(A[NM])&&(b.push(D),l.parameters&&delete l.parameters[D]),b),[]));let h=Object.entries(a.paths).reduce((b,[D,A])=>{if(!A)return b;let M={...A},z=["delete","get","head","patch","post","put","trace","options"];return z.forEach(re=>{let ie=A[re];if(!ie)return;if(ale(ie[NM])){delete M[re];return}let{parameters:Q}=ie;if(!Q)return;let Re=Q.filter(Ie=>{if(NM in Ie&&ale(Ie[NM]))return!1;if("$ref"in Ie){let we=Ie.$ref.split("/").pop();return we?!_.includes(we):!0}return!0});M[re]={...ie,parameters:Re}}),z.some(re=>!!M[re])&&(b[D]=M),b},{});return{...a,paths:h,components:l}}t(ior,"removeHiddenRoutesAndParams");function sor(a,{policiesConfig:s}){if(!a.paths)return a;let l=Object.entries(a.paths).reduce((_,[h,b])=>{if(!b)return _;let D={...b};return[D.delete,D.get,D.head,D.patch,D.post,D.put,D.trace,D.options].forEach(A=>{if(!A)return;let M=A["x-zuplo-route"]?.policies?.inbound?.reduce((ie,Q)=>{let Re=s.policies?.find(({name:Ct})=>Ct===Q);if(!Re)return ie;if(!(Re.handler.export==="CompositeInboundPolicy"))return ie.concat(Q);let we=Re.handler.options?.policies;return we?ie.concat(we):ie},[]),z=[];if(M&&M.forEach(ie=>{s.policies?.forEach(Q=>{Q.name===ie&&(Q.handler.export==="ApiAuthKeyInboundPolicy"||Q.handler.export==="ApiKeyInboundPolicy")&&!Q.handler.options?.disableAutomaticallyAddingKeyHeaderToOpenApi&&z.push(Q)})}),z.length>0){let ie=z.length>0&&z[0].handler&&z[0].handler.options&&z[0].handler.options.authHeader?z[0].handler.options.authHeader:"Authorization",Q=z.length>0&&z[0].handler&&z[0].handler.options&&(z[0].handler.options.authScheme||z[0].handler.options.authScheme==="")?z[0].handler.options.authScheme:"Bearer",Re=Q!==""?`${Q} ${cft}`:cft,Ie={name:ie,in:"header",required:!0,example:Re,schema:{type:"string"},description:`The \`${ie}\` header is used to authenticate with the API using your API key. Value is of the format \`${Re}\`.`};A.parameters?A.parameters.some(Sr=>"name"in Sr&&Sr.name===Ie.name)||A.parameters.unshift(Ie):A.parameters=[Ie];let we={type:"http",scheme:Q.toLowerCase()},Ct="api_key";a.components?.securitySchemes?Object.values(a.components?.securitySchemes).some(Sr=>"name"in Sr&&Sr.type==="apiKey"||"type"in Sr&&Sr.type==="http"&&Sr.scheme===Q)||(a.components.securitySchemes={...a.components.securitySchemes,[Ct]:we}):(a.components||(a.components={}),a.components.securitySchemes={[Ct]:we});let xt={[Ct]:[]};A.security?A.security.some(Sr=>Sr[Ct]!==void 0)||A.security.unshift(xt):A.security=[xt]}let re=[];if(M&&M.forEach(ie=>{s.policies?.forEach(Q=>{Q.name===ie&&(Q.handler.export==="RateLimitInboundPolicy"||Q.handler.export==="ComplexRateLimitInboundPolicy")&&re.push(Q)})}),re.length>0){let ie={description:"Rate Limiting Response",content:{"application/json":{schema:{type:"object",required:["type","title","status"],examples:[{type:"https://httpproblems.com/http-status/429",title:"Too Many Requests",status:429,instance:"/foo/bar"}],properties:{type:{type:"string",example:"https://httpproblems.com/http-status/429",description:"A URI reference that identifies the problem."},title:{type:"string",example:"Too Many Requests",description:"A short, human-readable summary of the problem."},status:{type:"number",example:429,description:"The HTTP status code."},instance:{type:"string",example:"/foo/bar"}}}}}},Q={...ie,headers:{"retry-after":{description:"The number of seconds to wait before making a new request.",schema:{type:"integer",example:60}}}};a.components?.responses||a.components||(a.components={}),a.components.responses={...a.components.responses,RateLimitNoRetryAfter:ie,RateLimitWithRetryAfter:Q},A.responses||(A.responses={});let Re=re.some(Ie=>Ie.handler.options?.headerMode!=="none");A.responses[429]||(A.responses[429]={$ref:Re?"#/components/responses/RateLimitWithRetryAfter":"#/components/responses/RateLimitNoRetryAfter"})}}),_[h]=D,_},{});return{...a,paths:l}}t(sor,"enrichSpecWithZuploData");function uft(a,s){for(let l in a)l.startsWith(s)?delete a[l]:typeof a[l]=="object"&&uft(a[l],s)}t(uft,"removePropertiesByPrefix");function aor({relativeOpenApiPath:a},s){if(!s||typeof s!="object")throw new V1({message:"The OpenAPI Document could not be parsed.",severity:"error"});if(!("info"in s)||typeof s.info!="object"||!s.info)throw new V1({message:"The OpenAPI document does not have the required 'info' property.",location:{file:a,column:0,length:0,line:0,lineText:"",namespace:"",suggestion:"Add the required 'info' property. https://spec.openapis.org/oas/v3.1.0#info-object"},severity:"error"});if(!("title"in s.info)||typeof s.info.title!="string")throw new V1({message:"The OpenAPI document does not have the required 'info.title' property.",location:{file:a,column:0,length:0,line:0,lineText:"",namespace:"",suggestion:"Add the required 'info.title' property. https://spec.openapis.org/oas/v3.1.0#info-object"},severity:"error"})}t(aor,"assertIsZuploOpenApiSpec");import kK from"node:path";function oor(a){if(a.length>=255)throw new TypeError("Alphabet too long");let s=new Uint8Array(256);for(let z=0;z<s.length;z++)s[z]=255;for(let z=0;z<a.length;z++){let re=a.charAt(z),ie=re.charCodeAt(0);if(s[ie]!==255)throw new TypeError(re+" is ambiguous");s[ie]=z}let l=a.length,_=a.charAt(0),h=Math.log(l)/Math.log(256),b=Math.log(256)/Math.log(l);function D(z){if(z instanceof Uint8Array||(ArrayBuffer.isView(z)?z=new Uint8Array(z.buffer,z.byteOffset,z.byteLength):Array.isArray(z)&&(z=Uint8Array.from(z))),!(z instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(z.length===0)return"";let re=0,ie=0,Q=0,Re=z.length;for(;Q!==Re&&z[Q]===0;)Q++,re++;let Ie=(Re-Q)*b+1>>>0,we=new Uint8Array(Ie);for(;Q!==Re;){let Sr=z[Q],cn=0;for(let en=Ie-1;(Sr!==0||cn<ie)&&en!==-1;en--,cn++)Sr+=256*we[en]>>>0,we[en]=Sr%l>>>0,Sr=Sr/l>>>0;if(Sr!==0)throw new Error("Non-zero carry");ie=cn,Q++}let Ct=Ie-ie;for(;Ct!==Ie&&we[Ct]===0;)Ct++;let xt=_.repeat(re);for(;Ct<Ie;++Ct)xt+=a.charAt(we[Ct]);return xt}t(D,"encode");function A(z){if(typeof z!="string")throw new TypeError("Expected String");if(z.length===0)return new Uint8Array;let re=0,ie=0,Q=0;for(;z[re]===_;)ie++,re++;let Re=(z.length-re)*h+1>>>0,Ie=new Uint8Array(Re);for(;z[re];){let Sr=s[z.charCodeAt(re)];if(Sr===255)return;let cn=0;for(let en=Re-1;(Sr!==0||cn<Q)&&en!==-1;en--,cn++)Sr+=l*Ie[en]>>>0,Ie[en]=Sr%256>>>0,Sr=Sr/256>>>0;if(Sr!==0)throw new Error("Non-zero carry");Q=cn,re++}let we=Re-Q;for(;we!==Re&&Ie[we]===0;)we++;let Ct=new Uint8Array(ie+(Re-we)),xt=ie;for(;we!==Re;)Ct[xt++]=Ie[we++];return Ct}t(A,"decodeUnsafe");function M(z){let re=A(z);if(re)return re;throw new Error("Non-base"+l+" character")}return t(M,"decode"),{encode:D,decodeUnsafe:A,decode:M}}t(oor,"base");var fft=oor;var cor="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",mue=fft(cor);var lor=!1;function aj(a,s){return{open:`\x1B[${a.join(";")}m`,close:`\x1B[${s}m`,regexp:new RegExp(`\\x1b\\[${s}m`,"g")}}t(aj,"code");function oj(a,s){return lor?`${s.open}${a.replace(s.regexp,s.open)}${s.close}`:a}t(oj,"run");function uor(a){return oj(a,aj([31],39))}t(uor,"red");function _or(a){return oj(a,aj([32],39))}t(_or,"green");function por(a){return oj(a,aj([33],39))}t(por,"yellow");function dor(a){return oj(a,aj([34],39))}t(dor,"blue");function mor(a){return oj(a,aj([35],39))}t(mor,"magenta");function hor(a){return oj(a,aj([36],39))}t(hor,"cyan");var xOr=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|"),"g");var _ft=[uor,_or,por,dor,mor,hor];function gor(a){let s=0,l=a.length,_=0;if(l>0)for(;_<l;)s=(s<<5)-s+a.charCodeAt(_++)|0;return s}t(gor,"hashCode");function pft(a){let s=Math.abs(gor(a));return _ft[s%_ft.length]}t(pft,"generateColor");import{inspect as yor}from"node:util";function dft(a,s,...l){let _=0,h=l.length,b=String(s).replace(/%[sdjoO%]/g,D=>{if(D==="%%")return"%";if(_>=h)return D;switch(D){case"%s":return String(l[_++]);case"%d":return Number(l[_++]).toString();case"%o":return a(l[_++]).split(`
|
|
583
|
-
`).map(A=>A.trim()).join(" ");case"%O":return a(l[_++]);case"%j":try{return JSON.stringify(l[_++])}catch{return"[Circular]"}default:return D}});for(let D of l.splice(_))D===null||!(typeof D=="object"&&D!==null)?b+=" "+D:b+=" "+a(D);return b}t(dft,"format");var mft=t((a,...s)=>dft(yor,a,s),"format");var rNe=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=pft(l),this.last=0,this.enabled=s.enabled.some(_=>_.test(l))}log(...s){if(!this.enabled)return;let l,_=s[0];typeof _=="function"?l=_():l=String(_);let h=Date.now()-(this.last||Date.now());l=mft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},nNe=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function vor(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(vor,"extract");var hue;function gue(a){hue||(hue=new nNe(vor(process.env.DEBUG)));let s=new rNe(hue,a);return hue.debuggers.set(a,s),Object.assign(s.log.bind(s),{self:s})}t(gue,"debug");var J3=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,l){typeof s=="string"?super(s,l):(super(s.message,l),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var hft="zp-local-service";var BOr=Symbol("zuplo_meters"),UOr=Symbol("zuplo_dynamic_meters");var fF=gue("zuplo:runtime:external-service");function bor(){let a,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=F0.instance.runtime;if(s&&s!=="undefined")try{let l=atob(s);a=JSON.parse(l)}catch{}return a}t(bor,"getServiceAuth");async function gft(a,s){let l=bor();if(l)if(fF(`Using external service auth. ClientId: ${l.clientId})`),typeof a=="string"){let _=new URL(a),h=_.hostname,b=s??{},D=new Headers(b.headers||{});D.set("CF-Access-Client-Id",l.clientId),D.set("CF-Access-Client-Secret",l.clientSecret),b.headers=D;let A;if(l.customServiceMapping&&l.customServiceMapping[h])A=`https://${l.customServiceMapping[h]}`;else if(F0.instance.useLegacyServiceRouting)A=`https://${h}.zuptunnel.com`;else{fF("Using sha256 service routing");let re=F0.instance.build;if(re.ACCOUNT_NAME&&re.PROJECT_NAME&&re.ENVIRONMENT_TYPE){let ie=await Sor(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=vft(re.ENVIRONMENT_TYPE),Re=await iNe(`${re.ACCOUNT_NAME}-${re.PROJECT_NAME}-${Q}`);Re==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Re==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?A=`https://${ie}.zuptunnel.com`:A=`https://${ie}.t.zuplo.app`}else throw fF("Cannot use sha256 service routing, missing build variables"),new J3("Failed to generate fully qualified tunnel url.")}let M=new URL(`${A}${_.pathname}${_.search}`);fF(`Calling external service: ${M.toString()}`);let z=await EG(M.toString(),b);if(z.status===403&&z.headers.get("cf-access-domain")!==null)throw CG.console.error("403 Forbidden when calling external service.",{clientId:l.clientId,tunnelHost:A}),new J3("Could not connect to secure tunnel.");return z}else throw fF("Cannot call external service with Request object"),new J3("Currently, we only support fetch(<some_string>, ...).");else throw fF("There is no external service auth configured for this zup."),new J3("There are no external services configured for this zup.")}t(gft,"externalServiceHandler");async function yft(a,s){if(typeof a=="string"){let l=new URL(a),_=l.hostname,h=s??{},b=`http://${_}.zuplo.svc.cluster.local:9000`,D=new URL(`${b}${l.pathname}${l.search}`),A=new Headers(h.headers||{});return A.set(hft,_),h.headers=A,await EG(D.toString(),h)}else throw new J3("Currently, we only support fetch(<some_string>, ...).")}t(yft,"clusterServiceHandler");async function Sor(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),A=vft(_);fF(`Hashing service name: ${b}-${h}.${b}-${D}-${A}`);let M=await iNe(`${b}-${h}`),z=await iNe(`${b}-${D}-${A}`);return`${M}.${z}`}t(Sor,"hashServiceName");async function iNe(a){let s=new TextEncoder().encode(a),l=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(l)).map(b=>b.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(iNe,"hashSegment");function vft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(vft,"sanitizeEnvironmentType");var sNe=new Map;sNe.set("service:",gft);sNe.set("local:",yft);var EG=globalThis.fetch;function aNe(a,s){let l=Tor(s);if(typeof a=="string"){let _=new URL(a),h=sNe.get(_.protocol);return h?h(a,l):EG(a,l)}else return EG(a,l)}t(aNe,"internalFetch");globalThis.fetch=aNe;var Tor=t(a=>{if(!a||a instanceof Request)return a;let s=a;if(!s.zuplo)return a;let l=a;return l.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete a.zuplo,a},"transformInit");var xor={console:{log:console.log.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),debug:console.debug.bind(console),assert:console.assert.bind(console),clear:console.clear.bind(console),count:console.count.bind(console),countReset:console.countReset.bind(console),dir:console.dir.bind(console),dirxml:console.dirxml.bind(console),group:console.group.bind(console),groupCollapsed:console.groupCollapsed.bind(console),groupEnd:console.groupEnd.bind(console),table:console.table.bind(console),time:console.time.bind(console),timeEnd:console.timeEnd.bind(console),timeLog:console.timeLog.bind(console),timeStamp:console.timeStamp.bind(console),trace:console.trace.bind(console),profile:console.profile.bind(console),profileEnd:console.profileEnd.bind(console)},fetch:aNe},CG=xor;var oNe="2025-02-06",bft=Object.freeze({none:{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2023-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-01-15":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-09-02":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2025-02-06":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!0,useForwardRedirectsPropOnUrlForwardHandler:!0}});function Sft(){return new F0({build:{ACCOUNT_NAME:"mock-account-name",PROJECT_NAME:"mock-project-name",API_VERSION:"0.0.0",BUILD_ID:crypto.randomUUID(),TIMESTAMP:new Date().toISOString(),BUILD_ENV:"test",ZUPLO_VERSION:"0.0.0",COMPATIBILITY_DATE:oNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:bft[oNe]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:""}})}t(Sft,"getMockEnvironment");var F0=class a{static{t(this,"Environment")}config;static#r;static#n=!1;static initialize(s){this.#r||(this.#r=new a(s),this.#n=!0)}static get instance(){return this.#n||(CG.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),this.#r=Sft()),this.#r}constructor({build:s,runtime:l}){let _;try{if(l.ZUPLO_SYSTEM_CONFIGURATIONS){let h=new TextDecoder().decode(mue.decode(l.ZUPLO_SYSTEM_CONFIGURATIONS)),b=JSON.parse(h);for(let D of Object.keys(b))l[D]||(l[D]=b[D])}if(l.__ZUPLO_CONFIG){let h=atob(l.__ZUPLO_CONFIG);_=JSON.parse(h)}}catch(h){CG.console.error("Failed to parse runtime configuration",h)}this.config=_??{},this.build=s,this.runtime=l,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=typeof globalThis.Deno<"u"&&globalThis.Deno.version&&globalThis.Deno.version.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,l=this.config.rate_limit_service_timeout_ms,_=s??l;if(!_)return 500;let h=Number(_);return Number.isFinite(h)&&h>0?h:500}};var Eor=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function Tft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!Eor.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):a.startsWith("ZUDOKU_")?!a.startsWith("ZUDOKU_PUBLIC_"):!1}t(Tft,"isRestrictedEnvVariableName");function xft(a){return!!a.startsWith("ZUPLO_")}t(xft,"isZuploReadableEnvVariableName");var _Fr=new Proxy({},{get(a,s){let l=String(s);switch(l){case"ZUPLO_ENVIRONMENT_TYPE":return F0.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return F0.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return F0.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return F0.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return F0.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return F0.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return F0.instance.build.COMPATIBILITY_DATE}if(!(Tft(l)&&!xft(l)))return F0.instance.runtime[l]}});function DG(a,s,l){return`_${PA(`${a}_${s}_${l}`)}`}t(DG,"getRawOperationDataIdentifierName");function cNe(a,s,l,_){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(cNe,"getIdForParameterSchema");function lNe(a,s,l){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_rb_${PA(l.toLowerCase())}`}t(lNe,"getIdForRequestBodySchema");function kG(a,s){return`_${PA(a)}_${PA(s)}`}t(kG,"getIdForRefSchema");function PA(a){let s=a.replace(/\[/g,"_LBRACKET_").replace(/\]/g,"_RBRACKET_").replace(/\{/g,"_LCURLY_").replace(/\}/g,"_RCURLY_").replace(/\//g,"_SLASH_").replace(/-/g,"_DASH_").replace(/\./g,"_DOT_").replace(/\+/g,"_PLUS_").replace(/:/g,"_COLON_").replace(/@/g,"_AT_").replace(/\$/g,"_DOLLAR_").replace(/[^a-zA-Z0-9_]/g,"_");return/^[a-zA-Z_]/.test(s)||(s="_"+s),s}t(PA,"sanitizedIdentifierName");var tgt=x_(ppt(),1);var JG=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(a,s,l,_,h,b){this.type=a,this.name=s,this.prefix=l,this.value=_,this.suffix=h,this.modifier=b}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},hur=/[$_\p{ID_Start}]/u,gur=/[$_\u200C\u200D\p{ID_Continue}]/u,nIe=".*";function yur(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(yur,"Re");function hpt(a,s=!1){let l=[],_=0;for(;_<a.length;){let h=a[_],b=t(function(D){if(!s)throw new TypeError(D);l.push({type:"INVALID_CHAR",index:_,value:a[_++]})},"c");if(h==="*"){l.push({type:"ASTERISK",index:_,value:a[_++]});continue}if(h==="+"||h==="?"){l.push({type:"OTHER_MODIFIER",index:_,value:a[_++]});continue}if(h==="\\"){l.push({type:"ESCAPED_CHAR",index:_++,value:a[_++]});continue}if(h==="{"){l.push({type:"OPEN",index:_,value:a[_++]});continue}if(h==="}"){l.push({type:"CLOSE",index:_,value:a[_++]});continue}if(h===":"){let D="",A=_+1;for(;A<a.length;){let M=a.substr(A,1);if(A===_+1&&hur.test(M)||A!==_+1&&gur.test(M)){D+=a[A++];continue}break}if(!D){b(`Missing parameter name at ${_}`);continue}l.push({type:"NAME",index:_,value:D}),_=A;continue}if(h==="("){let D=1,A="",M=_+1,z=!1;if(a[M]==="?"){b(`Pattern cannot start with "?" at ${M}`);continue}for(;M<a.length;){if(!yur(a[M],!1)){b(`Invalid character '${a[M]}' at ${M}.`),z=!0;break}if(a[M]==="\\"){A+=a[M++]+a[M++];continue}if(a[M]===")"){if(D--,D===0){M++;break}}else if(a[M]==="("&&(D++,a[M+1]!=="?")){b(`Capturing groups are not allowed at ${M}`),z=!0;break}A+=a[M++]}if(z)continue;if(D){b(`Unbalanced pattern at ${_}`);continue}if(!A){b(`Missing pattern at ${_}`);continue}l.push({type:"REGEX",index:_,value:A}),_=M;continue}l.push({type:"CHAR",index:_,value:a[_++]})}return l.push({type:"END",index:_,value:""}),l}t(hpt,"v");function gpt(a,s={}){let l=hpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,A="",M=new Set,z=t(cn=>{if(D<l.length&&l[D].type===cn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(cn=>{let en=z(cn);if(en!==void 0)return en;let{type:an,index:xr}=l[D];throw new TypeError(`Unexpected ${an} at ${xr}, expected ${cn}`)},"d"),Q=t(()=>{let cn="",en;for(;en=z("CHAR")??z("ESCAPED_CHAR");)cn+=en;return cn},"T"),Re=t(cn=>cn,"Se"),Ie=s.encodePart||Re,we="",Ct=t(cn=>{we+=cn},"U"),xt=t(()=>{we.length&&(h.push(new JG(3,"","",Ie(we),"",3)),we="")},"$"),Sr=t((cn,en,an,xr,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!en&&!an&&fs===3){Ct(cn);return}if(xt(),!en&&!an){if(!cn)return;h.push(new JG(3,"","",Ie(cn),"",fs));return}let Oi;an?an==="*"?Oi=nIe:Oi=an:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===nIe&&(Ho=0,Oi="");let di;if(en?di=en:an&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new JG(Ho,di,Ie(cn),Oi,Ie(xr),fs))},"V");for(;D<l.length;){let cn=z("CHAR"),en=z("NAME"),an=z("REGEX");if(!en&&!an&&(an=z("ASTERISK")),en||an){let vr=cn??"";s.prefixes.indexOf(vr)===-1&&(Ct(vr),vr=""),xt();let fs=re();Sr(vr,en,an,"",fs);continue}let xr=cn??z("ESCAPED_CHAR");if(xr){Ct(xr);continue}if(z("OPEN")){let vr=Q(),fs=z("NAME"),Oi=z("REGEX");!fs&&!Oi&&(Oi=z("ASTERISK"));let Ho=Q();ie("CLOSE");let di=re();Sr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(gpt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function dpt(a){return a&&a.ignoreCase?"ui":"u"}t(dpt,"X");function vur(a,s,l){return ypt(gpt(a,l),s,l)}t(vur,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function ypt(a,s,l={}){l.delimiter??="/#?",l.prefixes??="./",l.sensitive??=!1,l.strict??=!1,l.end??=!0,l.start??=!0,l.endsWith="";let _=l.start?"^":"";for(let A of a){if(A.type===3){A.modifier===3?_+=MT(A.value):_+=`(?:${MT(A.value)})${gj(A.modifier)}`;continue}s&&s.push(A.name);let M=`[^${MT(l.delimiter)}]+?`,z=A.value;if(A.type===1?z=M:A.type===0&&(z=nIe),!A.prefix.length&&!A.suffix.length){A.modifier===3||A.modifier===1?_+=`(${z})${gj(A.modifier)}`:_+=`((?:${z})${gj(A.modifier)})`;continue}if(A.modifier===3||A.modifier===1){_+=`(?:${MT(A.prefix)}(${z})${MT(A.suffix)})`,_+=gj(A.modifier);continue}_+=`(?:${MT(A.prefix)}`,_+=`((?:${z})(?:`,_+=MT(A.suffix),_+=MT(A.prefix),_+=`(?:${z}))*)${MT(A.suffix)})`,A.modifier===0&&(_+="?")}let h=`[${MT(l.endsWith)}]|$`,b=`[${MT(l.delimiter)}]`;if(l.end)return l.strict||(_+=`${b}?`),l.endsWith.length?_+=`(?=${h})`:_+="$",new RegExp(_,dpt(l));l.strict||(_+=`(?:${b}(?=${h}))?`);let D=!1;if(a.length){let A=a[a.length-1];A.type===3&&A.modifier===3&&(D=l.delimiter.indexOf(A)>-1)}return D||(_+=`(?=${b}|${h})`),new RegExp(_,dpt(l))}t(ypt,"F");var H3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},bur={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Sur={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Tur(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Tur,"J");function vpt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(vpt,"Q");function xur(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(xur,"Ee");function bpt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(bpt,"W");var Spt=["ftp","file","http","https","ws","wss"];function Tpt(a){if(!a)return!0;for(let s of Spt)if(a.test(s))return!0;return!1}t(Tpt,"N");function Eur(a,s){if(a=vpt(a,"#"),s||a==="")return a;let l=new URL("https://example.com");return l.hash=a,l.hash?l.hash.substring(1,l.hash.length):""}t(Eur,"te");function Cur(a,s){if(a=vpt(a,"?"),s||a==="")return a;let l=new URL("https://example.com");return l.search=a,l.search?l.search.substring(1,l.search.length):""}t(Cur,"re");function Dur(a,s){return s||a===""?a:bpt(a)?Cpt(a):Ept(a)}t(Dur,"ne");function kur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(kur,"se");function wur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(wur,"ie");function Pur(a,s,l){if(l||a==="")return a;if(s&&!Spt.includes(s))return new URL(`${s}:${a}`).pathname;let _=a[0]=="/";return a=new URL(_?a:"/-"+a,"https://example.com").pathname,_||(a=a.substring(2,a.length)),a}t(Pur,"ae");function Aur(a,s,l){return xpt(s)===a&&(a=""),l||a===""?a:Dpt(a)}t(Aur,"oe");function Nur(a,s){return a=xur(a,":"),s||a===""?a:iIe(a)}t(Nur,"ce");function xpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(xpt,"_");function iIe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(iIe,"y");function Iur(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(Iur,"le");function Our(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(Our,"fe");function Ept(a){if(a==="")return a;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(a))throw new TypeError(`Invalid hostname '${a}'`);let s=new URL("https://example.com");return s.hostname=a,s.hostname}t(Ept,"z");function Cpt(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(Cpt,"j");function Dpt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(Dpt,"K");function Fur(a){if(a==="")return a;let s=new URL("https://example.com");return s.pathname=a[0]!=="/"?"/-"+a:a,a[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(Fur,"he");function Lur(a){return a===""?a:new URL(`data:${a}`).pathname}t(Lur,"ue");function Rur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(Rur,"de");function Mur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(Mur,"pe");var jur=class{static{t(this,"H")}#r;#n=[];#e={};#t=0;#s=1;#p=0;#a=0;#_=0;#c=0;#l=!1;constructor(a){this.#r=a}get result(){return this.#e}parse(){for(this.#n=hpt(this.#r,!0);this.#t<this.#n.length;this.#t+=this.#s){if(this.#s=1,this.#n[this.#t].type==="END"){if(this.#a===0){this.#v(),this.#D()?this.#i(9,1):this.#y()?this.#i(8,1):this.#i(7,0);continue}else if(this.#a===2){this.#d(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#o())this.#_-=1;else continue;if(this.#w()){this.#_+=1;continue}switch(this.#a){case 0:this.#g()&&this.#d(1);break;case 1:if(this.#g()){this.#I();let a=7,s=1;this.#C()?(a=2,s=3):this.#l&&(a=2),this.#i(a,s)}break;case 2:this.#x()?this.#d(3):(this.#E()||this.#y()||this.#D())&&this.#d(5);break;case 3:this.#b()?this.#i(4,1):this.#x()&&this.#i(5,1);break;case 4:this.#x()&&this.#i(5,1);break;case 5:this.#N()?this.#c+=1:this.#S()&&(this.#c-=1),this.#k()&&!this.#c?this.#i(6,1):this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 6:this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 7:this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 8:this.#D()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#e.hostname!==void 0&&this.#e.port===void 0&&(this.#e.port="")}#i(a,s){switch(this.#a){case 0:break;case 1:this.#e.protocol=this.#T();break;case 2:break;case 3:this.#e.username=this.#T();break;case 4:this.#e.password=this.#T();break;case 5:this.#e.hostname=this.#T();break;case 6:this.#e.port=this.#T();break;case 7:this.#e.pathname=this.#T();break;case 8:this.#e.search=this.#T();break;case 9:this.#e.hash=this.#T();break;case 10:break}this.#a!==0&&a!==10&&([1,2,3,4].includes(this.#a)&&[6,7,8,9].includes(a)&&(this.#e.hostname??=""),[1,2,3,4,5,6].includes(this.#a)&&[8,9].includes(a)&&(this.#e.pathname??=this.#l?"/":""),[1,2,3,4,5,6,7].includes(this.#a)&&a===9&&(this.#e.search??="")),this.#f(a,s)}#f(a,s){this.#a=a,this.#p=this.#t+s,this.#t+=s,this.#s=0}#v(){this.#t=this.#p,this.#s=0}#d(a){this.#v(),this.#a=a}#u(a){return a<0&&(a=this.#n.length-a),a<this.#n.length?this.#n[a]:this.#n[this.#n.length-1]}#m(a,s){let l=this.#u(a);return l.value===s&&(l.type==="CHAR"||l.type==="ESCAPED_CHAR"||l.type==="INVALID_CHAR")}#g(){return this.#m(this.#t,":")}#C(){return this.#m(this.#t+1,"/")&&this.#m(this.#t+2,"/")}#x(){return this.#m(this.#t,"@")}#b(){return this.#m(this.#t,":")}#k(){return this.#m(this.#t,":")}#E(){return this.#m(this.#t,"/")}#y(){if(this.#m(this.#t,"?"))return!0;if(this.#n[this.#t].value!=="?")return!1;let a=this.#u(this.#t-1);return a.type!=="NAME"&&a.type!=="REGEX"&&a.type!=="CLOSE"&&a.type!=="ASTERISK"}#D(){return this.#m(this.#t,"#")}#w(){return this.#n[this.#t].type=="OPEN"}#o(){return this.#n[this.#t].type=="CLOSE"}#N(){return this.#m(this.#t,"[")}#S(){return this.#m(this.#t,"]")}#T(){let a=this.#n[this.#t],s=this.#u(this.#p).index;return this.#r.substring(s,a.index)}#I(){let a={};Object.assign(a,H3),a.encodePart=iIe;let s=vur(this.#T(),void 0,a);this.#l=Tpt(s)}},rIe=["protocol","username","password","hostname","port","pathname","search","hash"],W3="*";function mpt(a,s){if(typeof a!="string")throw new TypeError("parameter 1 is not of type 'string'.");let l=new URL(a,s);return{protocol:l.protocol.substring(0,l.protocol.length-1),username:l.username,password:l.password,hostname:l.hostname,port:l.port,pathname:l.pathname,search:l.search!==""?l.search.substring(1,l.search.length):void 0,hash:l.hash!==""?l.hash.substring(1,l.hash.length):void 0}}t(mpt,"ge");function FA(a,s){return s?zG(a):a}t(FA,"b");function $G(a,s,l){let _;if(typeof s.baseURL=="string")try{_=new URL(s.baseURL),s.protocol===void 0&&(a.protocol=FA(_.protocol.substring(0,_.protocol.length-1),l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(a.username=FA(_.username,l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(a.password=FA(_.password,l)),s.protocol===void 0&&s.hostname===void 0&&(a.hostname=FA(_.hostname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(a.port=FA(_.port,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(a.pathname=FA(_.pathname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(a.search=FA(_.search.substring(1,_.search.length),l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(a.hash=FA(_.hash.substring(1,_.hash.length),l))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(a.protocol=Nur(s.protocol,l)),typeof s.username=="string"&&(a.username=wur(s.username,l)),typeof s.password=="string"&&(a.password=kur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=Dur(s.hostname,l)),typeof s.port=="string"&&(a.port=Aur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Tur(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=FA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=Pur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=Cur(s.search,l)),typeof s.hash=="string"&&(a.hash=Eur(s.hash,l)),a}t($G,"w");function zG(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t(zG,"C");function Bur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(Bur,"Oe");function Uur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${Bur(s.delimiter)}]+?`,h=/[$_\u200C\u200D\p{ID_Continue}]/u,b="";for(let D=0;D<a.length;++D){let A=a[D];if(A.type===3){if(A.modifier===3){b+=zG(A.value);continue}b+=`{${zG(A.value)}}${gj(A.modifier)}`;continue}let M=A.hasCustomName(),z=!!A.suffix.length||!!A.prefix.length&&(A.prefix.length!==1||!s.prefixes.includes(A.prefix)),re=D>0?a[D-1]:null,ie=D<a.length-1?a[D+1]:null;if(!z&&M&&A.type===1&&A.modifier===3&&ie&&!ie.prefix.length&&!ie.suffix.length)if(ie.type===3){let Q=ie.value.length>0?ie.value[0]:"";z=h.test(Q)}else z=!ie.hasCustomName();if(!z&&!A.prefix.length&&re&&re.type===3){let Q=re.value[re.value.length-1];z=s.prefixes.includes(Q)}z&&(b+="{"),b+=zG(A.prefix),M&&(b+=`:${A.name}`),A.type===2?b+=`(${A.value})`:A.type===1?M||(b+=`(${_})`):A.type===0&&(!M&&(!re||re.type===3||re.modifier!==3||z||A.prefix!=="")?b+="*":b+=`(${l})`),A.type===1&&M&&A.suffix.length&&h.test(A.suffix[0])&&(b+="\\"),b+=zG(A.suffix),z&&(b+="}"),A.modifier!==3&&(b+=gj(A.modifier))}return b}t(Uur,"ke");var kpt=class{static{t(this,"me")}#r;#n={};#e={};#t={};#s={};#p=!1;constructor(a={},s,l){try{let _;if(typeof s=="string"?_=s:l=s,typeof a=="string"){let A=new jur(a);if(A.parse(),a=A.result,_===void 0&&typeof a.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");a.baseURL=_}else{if(!a||typeof a!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(_)throw new TypeError("parameter 1 is not of type 'string'.")}typeof l>"u"&&(l={ignoreCase:!1});let h={ignoreCase:l.ignoreCase===!0},b={pathname:W3,protocol:W3,username:W3,password:W3,hostname:W3,port:W3,search:W3,hash:W3};this.#r=$G(b,a,!0),xpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of rIe){if(!(D in this.#r))continue;let A={},M=this.#r[D];switch(this.#e[D]=[],D){case"protocol":Object.assign(A,H3),A.encodePart=iIe;break;case"username":Object.assign(A,H3),A.encodePart=Iur;break;case"password":Object.assign(A,H3),A.encodePart=Our;break;case"hostname":Object.assign(A,bur),bpt(M)?A.encodePart=Cpt:A.encodePart=Ept;break;case"port":Object.assign(A,H3),A.encodePart=Dpt;break;case"pathname":Tpt(this.#n.protocol)?(Object.assign(A,Sur,h),A.encodePart=Fur):(Object.assign(A,H3,h),A.encodePart=Lur);break;case"search":Object.assign(A,H3,h),A.encodePart=Rur;break;case"hash":Object.assign(A,H3,h),A.encodePart=Mur;break}try{this.#s[D]=gpt(M,A),this.#n[D]=ypt(this.#s[D],this.#e[D],A),this.#t[D]=Uur(this.#s[D],A),this.#p=this.#p||this.#s[D].some(z=>z.type===2)}catch{throw new TypeError(`invalid ${D} pattern '${this.#r[D]}'.`)}}}catch(_){throw new TypeError(`Failed to construct 'URLPattern': ${_.message}`)}}test(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return!1;try{typeof a=="object"?l=$G(l,a,!1):l=$G(l,mpt(a,s),!1)}catch{return!1}let _;for(_ of rIe)if(!this.#n[_].exec(l[_]))return!1;return!0}exec(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return;try{typeof a=="object"?l=$G(l,a,!1):l=$G(l,mpt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of rIe){let b=this.#n[h].exec(l[h]);if(!b)return null;let D={};for(let[A,M]of this.#e[h].entries())if(typeof M=="string"||typeof M=="number"){let z=b[A+1];D[M]=z}_[h]={input:l[h]??"",groups:D}}return _}static compareComponent(a,s,l){let _=t((A,M)=>{for(let z of["type","modifier","prefix","value","suffix"]){if(A[z]<M[z])return-1;if(A[z]!==M[z])return 1}return 0},"o"),h=new JG(3,"","","","",3),b=new JG(0,"","","","",3),D=t((A,M)=>{let z=0;for(;z<Math.min(A.length,M.length);++z){let re=_(A[z],M[z]);if(re)return re}return A.length===M.length?0:_(A[z]??h,M[z]??h)},"s");return!s.#t[a]&&!l.#t[a]?0:s.#t[a]&&!l.#t[a]?D(s.#s[a],[b]):!s.#t[a]&&l.#t[a]?D([b],l.#s[a]):D(s.#s[a],l.#s[a])}get protocol(){return this.#t.protocol}get username(){return this.#t.username}get password(){return this.#t.password}get hostname(){return this.#t.hostname}get port(){return this.#t.port}get pathname(){return this.#t.pathname}get search(){return this.#t.search}get hash(){return this.#t.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=kpt);import{AssertionError as $ur}from"node:assert";function LA(a,s){if(a===!1)throw new $ur({message:s})}t(LA,"assert");var ec;(function(a){a.Object="Object",a.Property="Property",a.Array="Array",a.Literal="Literal",a.TemplateString="TemplateString",a.Identifier="Identifier",a.FunctionCall="FunctionCall",a.Raw="Raw"})(ec||(ec={}));function yj(a){return a.type===ec.Object}t(yj,"isAstObject");function RA(a){return a.type===ec.Property}t(RA,"isAstProperty");function wpt(a){return a.type===ec.Array}t(wpt,"isAstArray");function vj(a){return a.type===ec.Literal}t(vj,"isAstLiteral");function G3(a){if(a===void 0)throw new Error("Node is undefined");if(!yj(a))throw new Error("Node is not object")}t(G3,"assertAstObject");import{findNodeAtLocation as zur,getNodeValue as Jur,printParseErrorCode as qur,visit as Vur}from"jsonc-parser";var Wur={DEFAULT:{allowTrailingComma:!1}};function qG(a,s=[],l=Wur.DEFAULT){let _={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function h(M){_.type==="property"&&(_.length=M-_.offset,_=_.parent)}t(h,"ensurePropertyComplete");function b(M){return _.children?.push(M),M}t(b,"onValue"),Vur(a,{onObjectBegin:t((M,z,re)=>{_=b({type:"object",offset:M,length:-1,line:z+1,column:re+1,parent:_,children:[]})},"onObjectBegin"),onObjectProperty:t((M,z,re,ie,Q)=>{_=b({type:"property",offset:z,length:-1,line:ie+1,column:Q+1,parent:_,children:[]}),_.children?.push({type:"string",value:M,offset:z,length:re,line:ie,column:Q,parent:_})},"onObjectProperty"),onObjectEnd:t((M,z)=>{h(M+z),_.length=M+z-_.offset,_=_.parent,h(M+z)},"onObjectEnd"),onArrayBegin:t((M,z,re,ie)=>{_=b({type:"array",offset:M,length:-1,line:re+1,column:ie+1,parent:_,children:[]})},"onArrayBegin"),onArrayEnd:t((M,z)=>{_.length=M+z-_.offset,_=_.parent,h(M+z)},"onArrayEnd"),onLiteralValue:t((M,z,re,ie,Q)=>{b({type:Hur(M),offset:z,length:re,line:ie+1,column:Q+1,parent:_,value:M}),h(z+re)},"onLiteralValue"),onSeparator:t((M,z)=>{_.type==="property"&&(M===":"?_.colonOffset=z:M===","&&h(z))},"onSeparator"),onError:t((M,z,re,ie,Q)=>{s.push({error:M,offset:z,length:re,line:ie+1,column:Q+1})},"onError")},l);let A=_.children[0];return A&&delete A.parent,A}t(qG,"parse");function Hur(a){switch(typeof a){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(a){if(Array.isArray(a))return"array"}else return"null";return"object"}default:return"null"}}t(Hur,"getNodeType");function sIe(a,s){return zur(a,s)}t(sIe,"findNodeAtLocation");function VG(a){return Jur(a)}t(VG,"getNodeValue");function Ppt(a){return qur(a)}t(Ppt,"printParseErrorCode");var WG=class{static{t(this,"AstAdapter")}parse(s){let _=qG(s,[]);if(_)return this.parseNode(_,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,l){switch(s.type){case"object":return this.createObject(s,l);case"array":return this.createArray(s,l);case"property":return this.createProperty(s,l);case"string":return this.createLiteral(s,l);case"number":return this.createLiteral(s,l);case"boolean":return this.createLiteral(s,l);case"null":return this.createLiteral(s,l)}}createLiteral(s,l){return{type:ec.Literal,location:{line:s.line,column:s.column},parent:l,value:s.type==="null"?null:s.value}}createObject(s,l){let _={type:ec.Object,children:[],parent:l,location:{line:s.line,column:s.column}};return s.children?.forEach(h=>{_.children.push(this.parseNode(h,_))}),_}createProperty(s,l){LA(s.children?.length===2,"Invalid property node");let _={type:ec.Property,location:{line:s.line,column:s.column},parent:l,name:null,value:null};return _.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:ec.Identifier,parent:_},_.value=this.parseNode(s.children[1],_),_}createArray(s,l){let _={type:ec.Array,location:{line:s.line,column:s.column},parent:l,children:[]};return s.children?.forEach(h=>_.children.push(this.parseNode(h,_))),_}};var jT={createLiteral:t((a,s)=>({type:ec.Literal,parent:s,value:a}),"createLiteral"),createTemplateString:t((a,s)=>({type:ec.TemplateString,parent:s,value:a}),"createTemplateString"),createIdentifier:t((a,s)=>({type:ec.Identifier,value:a,parent:s}),"createIdentifier"),createProperty:t((a,s,l)=>{let _={type:ec.Property,parent:l,name:null,value:s};return _.name={value:a,type:ec.Identifier,parent:_},_.value.parent=_,_},"createProperty"),createArrayOfLiterals:t((a,s)=>{let l={type:ec.Array,parent:s,children:[]};for(let _ of a)l.children.push(jT.createLiteral(_,l));return l},"createArrayOfLiterals")};var Gur=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,HG=class{static{t(this,"SourceGenerator")}generate(s){let l=[];return this.generateSource(l,s),l.join("")}generateSource(s,l){switch(l.type){case ec.Array:return this.generateArray(s,l);case ec.Object:return this.generateObject(s,l);case ec.Property:return this.generateProperty(s,l);case ec.Literal:return this.generateLiteral(s,l);case ec.FunctionCall:return this.generateFunctionCall(s,l);case ec.Identifier:return this.generateIdentifier(s,l);case ec.Raw:return this.generateRaw(s,l);case ec.TemplateString:return this.generateTemplateString(s,l)}}generateArray(s,l){s.push("["),l.children.map(_=>{this.generateSource(s,_),s.push(",")}),s.push("]")}generateObject(s,l){s.push("{"),l.children.forEach(_=>{this.generateSource(s,_),s.push(",")}),s.push("}")}generateProperty(s,l){this.generateIdentifier(s,l.name),s.push(":"),this.generateSource(s,l.value)}generateFunctionCall(s,l){s.push(l.name.value),s.push("("),l.children.forEach((_,h,b)=>{this.generateSource(s,_),h<b.length&&s.push(",")}),s.push(")")}generateRaw(s,l){s.push(l.value)}generateTemplateString(s,l){s.push("`"),s.push(l.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,l){if(l.value===null)return s.push("null");switch(typeof l.value){case"number":case"boolean":return s.push(`${l.value}`);case"string":{let _=l.value,h=JSON.stringify(_);return s.push(`${h}`)}}}generateIdentifier(s,l){let _=Gur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Kur from"node:fs/promises";import{parse as Yur}from"@swc/core";var Apt=t(async a=>{let s=new Set;try{let l=await Kur.readFile(a,"utf-8");(await Yur(l,{syntax:"typescript"})).body.forEach(h=>{h.type==="ExportDefaultDeclaration"||h.type==="ExportDefaultExpression"?s.add("default"):h.type==="ExportDeclaration"&&h.declaration.type==="FunctionDeclaration"?s.add(h.declaration.identifier.value):h.type==="ExportDeclaration"&&h.declaration.type==="VariableDeclaration"&&h.declaration.declarations[0].id.type==="Identifier"&&s.add(h.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Npt={$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 aIe={$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 Ipt={$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 oIe={$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:{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-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var cIe={$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 Vht=x_(dht(),1),Wht=x_(qht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new Wht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Vht.default)(this.ajv,{mode:"fast"})}addSchema(s,l){this.ajv.addSchema(s,l)}compile(s){let l=this.ajv.compile(s);return t(h=>({isValid:l(h),errors:this.toSimpleErrors(l.errors,h),warnings:[]}),"validator")}toSimpleErrors(s,l){let _=[];return s?.forEach(h=>{h.keyword==="enum"&&h.params.allowedValues&&Array.isArray(h.params.allowedValues)&&(h.message+=`; ${h.params.allowedValues.join(", ")}`),h.instancePath&&(h.instancePath=h.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let b={details:{}},D=h.instancePath.split("/");if(D.length>2){let M=D[1],z=D[2]?parseInt(D[2]):0,re=D[3],ie=isNaN(z)?void 0:l[M][z][re];b={details:{property:M,index:z,field:re,fieldValue:ie}}}if(h.keyword==="required"&&h.params.missingProperty&&h.instancePath&&(h.message=`A 'path' is missing required property '${h.params.missingProperty}'`),h.keyword==="additionalProperties"&&h.params.additionalProperty&&h.instancePath&&(h.message=`A 'path' should NOT include property '${h.params.additionalProperty}'`),h.keyword==="type"&&h.params.type&&h.instancePath){let M=h.instancePath.split("/"),z=M[M.length-1];h.message=`Value of property '${z}' must be '${h.params.type}'`}let A=Object.assign(h,b);_.push(A)}),_}};var iN=Lfe.instance;iN.addSchema(cIe,"route-configuration.schema.json");iN.addSchema(Ipt,"policy-configuration.schema.json");iN.addSchema(aIe,"policies.schema.json");iN.addSchema(oIe,"open-api-route-configuration.schema.json");iN.addSchema(Npt,"fragments.schema.json");var fRr=iN.compile(cIe),Hht=iN.compile(oIe),xOe=iN.compile(aIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=xOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Hht(s),this.results}};import n0r from"node:path";var EOe=/\$import\((.*)\)/,jfe=/\$env\((.*?)\)/g;var $A=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,l,_,h){super(s),this.location={file:l,namespace:"",line:_?_.line:0,column:_?_.column:0,length:0,lineText:h??"",suggestion:""}}},r0r=t(a=>{let s=[],l=a;for(;l.parent;)s.push(l),l=l.parent;return s.reverse()},"invertTree"),sN=t((a,s)=>{if(!a)return!1;let l=r0r(a);return s.split("/").every((b,D)=>{let A=l[D];return A?b==="*"||RA(A)&&A.name.value===b?!0:b==="{}"?A.type===ec.Object:b==="[]"?A.type===ec.Array:!1:!1})},"testPosition");var Bfe=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),yj(s)?s.children.forEach(l=>{this.visitor(l)}):wpt(s)?s.children.forEach(l=>{this.visitor(l)}):RA(s)&&this.visitor(s.value)}},Ght=t((a,s,l)=>_=>{if(!RA(_)||!vj(_.value)||typeof _.value.value!="string")return;if(!a.some(b=>sN(_,b))){jfe.test(_.value.value)&&s.push(new $A("An $env() statement is not expected at this location.",l,_.location,_.value.value));return}let h=new RegExp(jfe).exec(_.value.value);if(h?.length===2&&h[0]===_.value.value){let b={type:ec.Raw,parent:null,value:`environment["${h[1]}"]`};_.value=b}else{let b=_.value.value.replaceAll(new RegExp(jfe),(D,A)=>`\${environment["${A}"] ? environment["${A}"] : ""}`);b!==_.value.value&&(_.value=jT.createTemplateString(b,_))}},"getEnvStatementTransformer");var DK="config/routes.json",i0r=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],s0r=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Kht=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],a0r="handler/{}/options/{}/rewritePattern",o0r="handler/{}/options/{}/baseUrl",Ufe=class extends Bfe{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let l=this.addedImports.get(s);if(!l)throw new Error("Import name is undefined. This should not happen.");return l}getImports(){let s=[];return this.addedImports.forEach((l,_)=>{s.push({name:l,path:_})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!RA(s)||!vj(s.value)||typeof s.value.value!="string")&&sN(s,a0r)){if(!s.parent||!yj(s.parent)){this.errors.push(new $A("Invalid node, expected object",DK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Yht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}rewriteForwardFunction(s){if(!(!RA(s)||!vj(s.value)||typeof s.value.value!="string")&&sN(s,o0r)){if(!s.parent||!yj(s.parent)){this.errors.push(new $A("Invalid node, expected object",DK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Yht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}replaceImportStatements(s){if(!RA(s)||!vj(s.value))return;let l=s.value.value;if(typeof l!="string")return;if(!s0r.some(A=>sN(s,A))&&!Kht.some(A=>sN(s,A))){if(EOe.test(l)){if(s.name.value==="$ref")return;this.errors.push(new $A("An $import() statement is not expected at this location.",DK,s.location,l))}return}let _=EOe.exec(l);if(Kht.some(A=>sN(s,A))&&!_)return;if(!_){this.errors.push(new $A("Invalid $import() statement",DK,s.location,l));return}let h=_[1];h=h.replace(/\\/g,"/"),h.startsWith(".")&&(h=n0r.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=Ght(i0r,this.errors,DK)};function Yht(a){return`(request, context) => {
|
|
583
|
+
`).map(A=>A.trim()).join(" ");case"%O":return a(l[_++]);case"%j":try{return JSON.stringify(l[_++])}catch{return"[Circular]"}default:return D}});for(let D of l.splice(_))D===null||!(typeof D=="object"&&D!==null)?b+=" "+D:b+=" "+a(D);return b}t(dft,"format");var mft=t((a,...s)=>dft(yor,a,s),"format");var rNe=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=pft(l),this.last=0,this.enabled=s.enabled.some(_=>_.test(l))}log(...s){if(!this.enabled)return;let l,_=s[0];typeof _=="function"?l=_():l=String(_);let h=Date.now()-(this.last||Date.now());l=mft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},nNe=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function vor(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(vor,"extract");var hue;function gue(a){hue||(hue=new nNe(vor(process.env.DEBUG)));let s=new rNe(hue,a);return hue.debuggers.set(a,s),Object.assign(s.log.bind(s),{self:s})}t(gue,"debug");var J3=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,l){typeof s=="string"?super(s,l):(super(s.message,l),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var hft="zp-local-service";var BOr=Symbol("zuplo_meters"),UOr=Symbol("zuplo_dynamic_meters");var fF=gue("zuplo:runtime:external-service");function bor(){let a,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=F0.instance.runtime;if(s&&s!=="undefined")try{let l=atob(s);a=JSON.parse(l)}catch{}return a}t(bor,"getServiceAuth");async function gft(a,s){let l=bor();if(l)if(fF(`Using external service auth. ClientId: ${l.clientId})`),typeof a=="string"){let _=new URL(a),h=_.hostname,b=s??{},D=new Headers(b.headers||{});D.set("CF-Access-Client-Id",l.clientId),D.set("CF-Access-Client-Secret",l.clientSecret),b.headers=D;let A;if(l.customServiceMapping&&l.customServiceMapping[h])A=`https://${l.customServiceMapping[h]}`;else if(F0.instance.useLegacyServiceRouting)A=`https://${h}.zuptunnel.com`;else{fF("Using sha256 service routing");let re=F0.instance.build;if(re.ACCOUNT_NAME&&re.PROJECT_NAME&&re.ENVIRONMENT_TYPE){let ie=await Sor(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=vft(re.ENVIRONMENT_TYPE),Re=await iNe(`${re.ACCOUNT_NAME}-${re.PROJECT_NAME}-${Q}`);Re==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Re==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?A=`https://${ie}.zuptunnel.com`:A=`https://${ie}.t.zuplo.app`}else throw fF("Cannot use sha256 service routing, missing build variables"),new J3("Failed to generate fully qualified tunnel url.")}let M=new URL(`${A}${_.pathname}${_.search}`);fF(`Calling external service: ${M.toString()}`);let z=await EG(M.toString(),b);if(z.status===403&&z.headers.get("cf-access-domain")!==null)throw CG.console.error("403 Forbidden when calling external service.",{clientId:l.clientId,tunnelHost:A}),new J3("Could not connect to secure tunnel.");return z}else throw fF("Cannot call external service with Request object"),new J3("Currently, we only support fetch(<some_string>, ...).");else throw fF("There is no external service auth configured for this zup."),new J3("There are no external services configured for this zup.")}t(gft,"externalServiceHandler");async function yft(a,s){if(typeof a=="string"){let l=new URL(a),_=l.hostname,h=s??{},b=`http://${_}.zuplo.svc.cluster.local:9000`,D=new URL(`${b}${l.pathname}${l.search}`),A=new Headers(h.headers||{});return A.set(hft,_),h.headers=A,await EG(D.toString(),h)}else throw new J3("Currently, we only support fetch(<some_string>, ...).")}t(yft,"clusterServiceHandler");async function Sor(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),A=vft(_);fF(`Hashing service name: ${b}-${h}.${b}-${D}-${A}`);let M=await iNe(`${b}-${h}`),z=await iNe(`${b}-${D}-${A}`);return`${M}.${z}`}t(Sor,"hashServiceName");async function iNe(a){let s=new TextEncoder().encode(a),l=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(l)).map(b=>b.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(iNe,"hashSegment");function vft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(vft,"sanitizeEnvironmentType");var sNe=new Map;sNe.set("service:",gft);sNe.set("local:",yft);var EG=globalThis.fetch;function aNe(a,s){let l=Tor(s);if(typeof a=="string"){let _=new URL(a),h=sNe.get(_.protocol);return h?h(a,l):EG(a,l)}else return EG(a,l)}t(aNe,"internalFetch");globalThis.fetch=aNe;var Tor=t(a=>{if(!a||a instanceof Request)return a;let s=a;if(!s.zuplo)return a;let l=a;return l.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete a.zuplo,a},"transformInit");var xor={console:{log:console.log.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),debug:console.debug.bind(console),assert:console.assert.bind(console),clear:console.clear.bind(console),count:console.count.bind(console),countReset:console.countReset.bind(console),dir:console.dir.bind(console),dirxml:console.dirxml.bind(console),group:console.group.bind(console),groupCollapsed:console.groupCollapsed.bind(console),groupEnd:console.groupEnd.bind(console),table:console.table.bind(console),time:console.time.bind(console),timeEnd:console.timeEnd.bind(console),timeLog:console.timeLog.bind(console),timeStamp:console.timeStamp.bind(console),trace:console.trace.bind(console),profile:console.profile.bind(console),profileEnd:console.profileEnd.bind(console)},fetch:aNe},CG=xor;var oNe="2025-02-06",bft=Object.freeze({none:{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2023-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-01-15":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2024-09-02":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1},"2025-02-06":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!0,useForwardRedirectsPropOnUrlForwardHandler:!0}});function Sft(){return new F0({build:{ACCOUNT_NAME:"mock-account-name",PROJECT_NAME:"mock-project-name",API_VERSION:"0.0.0",BUILD_ID:crypto.randomUUID(),TIMESTAMP:new Date().toISOString(),BUILD_ENV:"test",ZUPLO_VERSION:"0.0.0",COMPATIBILITY_DATE:oNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:bft[oNe]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:"",ZUPLO_SERVICE_BUCKET_ID:"mock-bucket-id"}})}t(Sft,"getMockEnvironment");var F0=class a{static{t(this,"Environment")}config;static#r;static#n=!1;static initialize(s){this.#r||(this.#r=new a(s),this.#n=!0)}static get instance(){return this.#n||(CG.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),this.#r=Sft()),this.#r}constructor({build:s,runtime:l}){let _;try{if(l.ZUPLO_SYSTEM_CONFIGURATIONS){let h=new TextDecoder().decode(mue.decode(l.ZUPLO_SYSTEM_CONFIGURATIONS)),b=JSON.parse(h);for(let D of Object.keys(b))l[D]||(l[D]=b[D])}if(l.__ZUPLO_CONFIG){let h=atob(l.__ZUPLO_CONFIG);_=JSON.parse(h)}}catch(h){CG.console.error("Failed to parse runtime configuration",h)}this.config=_??{},this.build=s,this.runtime=l,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=typeof globalThis.Deno<"u"&&globalThis.Deno.version&&globalThis.Deno.version.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,l=this.config.rate_limit_service_timeout_ms,_=s??l;if(!_)return 500;let h=Number(_);return Number.isFinite(h)&&h>0?h:500}};var Eor=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function Tft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!Eor.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):a.startsWith("ZUDOKU_")?!a.startsWith("ZUDOKU_PUBLIC_"):!1}t(Tft,"isRestrictedEnvVariableName");function xft(a){return!!a.startsWith("ZUPLO_")}t(xft,"isZuploReadableEnvVariableName");var _Fr=new Proxy({},{get(a,s){let l=String(s);switch(l){case"ZUPLO_ENVIRONMENT_TYPE":return F0.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return F0.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return F0.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return F0.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return F0.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return F0.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return F0.instance.build.COMPATIBILITY_DATE}if(!(Tft(l)&&!xft(l)))return F0.instance.runtime[l]}});function DG(a,s,l){return`_${PA(`${a}_${s}_${l}`)}`}t(DG,"getRawOperationDataIdentifierName");function cNe(a,s,l,_){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(cNe,"getIdForParameterSchema");function lNe(a,s,l){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_rb_${PA(l.toLowerCase())}`}t(lNe,"getIdForRequestBodySchema");function kG(a,s){return`_${PA(a)}_${PA(s)}`}t(kG,"getIdForRefSchema");function PA(a){let s=a.replace(/\[/g,"_LBRACKET_").replace(/\]/g,"_RBRACKET_").replace(/\{/g,"_LCURLY_").replace(/\}/g,"_RCURLY_").replace(/\//g,"_SLASH_").replace(/-/g,"_DASH_").replace(/\./g,"_DOT_").replace(/\+/g,"_PLUS_").replace(/:/g,"_COLON_").replace(/@/g,"_AT_").replace(/\$/g,"_DOLLAR_").replace(/[^a-zA-Z0-9_]/g,"_");return/^[a-zA-Z_]/.test(s)||(s="_"+s),s}t(PA,"sanitizedIdentifierName");var tgt=x_(ppt(),1);var JG=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(a,s,l,_,h,b){this.type=a,this.name=s,this.prefix=l,this.value=_,this.suffix=h,this.modifier=b}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},hur=/[$_\p{ID_Start}]/u,gur=/[$_\u200C\u200D\p{ID_Continue}]/u,nIe=".*";function yur(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(yur,"Re");function hpt(a,s=!1){let l=[],_=0;for(;_<a.length;){let h=a[_],b=t(function(D){if(!s)throw new TypeError(D);l.push({type:"INVALID_CHAR",index:_,value:a[_++]})},"c");if(h==="*"){l.push({type:"ASTERISK",index:_,value:a[_++]});continue}if(h==="+"||h==="?"){l.push({type:"OTHER_MODIFIER",index:_,value:a[_++]});continue}if(h==="\\"){l.push({type:"ESCAPED_CHAR",index:_++,value:a[_++]});continue}if(h==="{"){l.push({type:"OPEN",index:_,value:a[_++]});continue}if(h==="}"){l.push({type:"CLOSE",index:_,value:a[_++]});continue}if(h===":"){let D="",A=_+1;for(;A<a.length;){let M=a.substr(A,1);if(A===_+1&&hur.test(M)||A!==_+1&&gur.test(M)){D+=a[A++];continue}break}if(!D){b(`Missing parameter name at ${_}`);continue}l.push({type:"NAME",index:_,value:D}),_=A;continue}if(h==="("){let D=1,A="",M=_+1,z=!1;if(a[M]==="?"){b(`Pattern cannot start with "?" at ${M}`);continue}for(;M<a.length;){if(!yur(a[M],!1)){b(`Invalid character '${a[M]}' at ${M}.`),z=!0;break}if(a[M]==="\\"){A+=a[M++]+a[M++];continue}if(a[M]===")"){if(D--,D===0){M++;break}}else if(a[M]==="("&&(D++,a[M+1]!=="?")){b(`Capturing groups are not allowed at ${M}`),z=!0;break}A+=a[M++]}if(z)continue;if(D){b(`Unbalanced pattern at ${_}`);continue}if(!A){b(`Missing pattern at ${_}`);continue}l.push({type:"REGEX",index:_,value:A}),_=M;continue}l.push({type:"CHAR",index:_,value:a[_++]})}return l.push({type:"END",index:_,value:""}),l}t(hpt,"v");function gpt(a,s={}){let l=hpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,A="",M=new Set,z=t(cn=>{if(D<l.length&&l[D].type===cn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(cn=>{let en=z(cn);if(en!==void 0)return en;let{type:an,index:xr}=l[D];throw new TypeError(`Unexpected ${an} at ${xr}, expected ${cn}`)},"d"),Q=t(()=>{let cn="",en;for(;en=z("CHAR")??z("ESCAPED_CHAR");)cn+=en;return cn},"T"),Re=t(cn=>cn,"Se"),Ie=s.encodePart||Re,we="",Ct=t(cn=>{we+=cn},"U"),xt=t(()=>{we.length&&(h.push(new JG(3,"","",Ie(we),"",3)),we="")},"$"),Sr=t((cn,en,an,xr,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!en&&!an&&fs===3){Ct(cn);return}if(xt(),!en&&!an){if(!cn)return;h.push(new JG(3,"","",Ie(cn),"",fs));return}let Oi;an?an==="*"?Oi=nIe:Oi=an:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===nIe&&(Ho=0,Oi="");let di;if(en?di=en:an&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new JG(Ho,di,Ie(cn),Oi,Ie(xr),fs))},"V");for(;D<l.length;){let cn=z("CHAR"),en=z("NAME"),an=z("REGEX");if(!en&&!an&&(an=z("ASTERISK")),en||an){let vr=cn??"";s.prefixes.indexOf(vr)===-1&&(Ct(vr),vr=""),xt();let fs=re();Sr(vr,en,an,"",fs);continue}let xr=cn??z("ESCAPED_CHAR");if(xr){Ct(xr);continue}if(z("OPEN")){let vr=Q(),fs=z("NAME"),Oi=z("REGEX");!fs&&!Oi&&(Oi=z("ASTERISK"));let Ho=Q();ie("CLOSE");let di=re();Sr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(gpt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function dpt(a){return a&&a.ignoreCase?"ui":"u"}t(dpt,"X");function vur(a,s,l){return ypt(gpt(a,l),s,l)}t(vur,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function ypt(a,s,l={}){l.delimiter??="/#?",l.prefixes??="./",l.sensitive??=!1,l.strict??=!1,l.end??=!0,l.start??=!0,l.endsWith="";let _=l.start?"^":"";for(let A of a){if(A.type===3){A.modifier===3?_+=MT(A.value):_+=`(?:${MT(A.value)})${gj(A.modifier)}`;continue}s&&s.push(A.name);let M=`[^${MT(l.delimiter)}]+?`,z=A.value;if(A.type===1?z=M:A.type===0&&(z=nIe),!A.prefix.length&&!A.suffix.length){A.modifier===3||A.modifier===1?_+=`(${z})${gj(A.modifier)}`:_+=`((?:${z})${gj(A.modifier)})`;continue}if(A.modifier===3||A.modifier===1){_+=`(?:${MT(A.prefix)}(${z})${MT(A.suffix)})`,_+=gj(A.modifier);continue}_+=`(?:${MT(A.prefix)}`,_+=`((?:${z})(?:`,_+=MT(A.suffix),_+=MT(A.prefix),_+=`(?:${z}))*)${MT(A.suffix)})`,A.modifier===0&&(_+="?")}let h=`[${MT(l.endsWith)}]|$`,b=`[${MT(l.delimiter)}]`;if(l.end)return l.strict||(_+=`${b}?`),l.endsWith.length?_+=`(?=${h})`:_+="$",new RegExp(_,dpt(l));l.strict||(_+=`(?:${b}(?=${h}))?`);let D=!1;if(a.length){let A=a[a.length-1];A.type===3&&A.modifier===3&&(D=l.delimiter.indexOf(A)>-1)}return D||(_+=`(?=${b}|${h})`),new RegExp(_,dpt(l))}t(ypt,"F");var H3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},bur={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Sur={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Tur(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Tur,"J");function vpt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(vpt,"Q");function xur(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(xur,"Ee");function bpt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(bpt,"W");var Spt=["ftp","file","http","https","ws","wss"];function Tpt(a){if(!a)return!0;for(let s of Spt)if(a.test(s))return!0;return!1}t(Tpt,"N");function Eur(a,s){if(a=vpt(a,"#"),s||a==="")return a;let l=new URL("https://example.com");return l.hash=a,l.hash?l.hash.substring(1,l.hash.length):""}t(Eur,"te");function Cur(a,s){if(a=vpt(a,"?"),s||a==="")return a;let l=new URL("https://example.com");return l.search=a,l.search?l.search.substring(1,l.search.length):""}t(Cur,"re");function Dur(a,s){return s||a===""?a:bpt(a)?Cpt(a):Ept(a)}t(Dur,"ne");function kur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(kur,"se");function wur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(wur,"ie");function Pur(a,s,l){if(l||a==="")return a;if(s&&!Spt.includes(s))return new URL(`${s}:${a}`).pathname;let _=a[0]=="/";return a=new URL(_?a:"/-"+a,"https://example.com").pathname,_||(a=a.substring(2,a.length)),a}t(Pur,"ae");function Aur(a,s,l){return xpt(s)===a&&(a=""),l||a===""?a:Dpt(a)}t(Aur,"oe");function Nur(a,s){return a=xur(a,":"),s||a===""?a:iIe(a)}t(Nur,"ce");function xpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(xpt,"_");function iIe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(iIe,"y");function Iur(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(Iur,"le");function Our(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(Our,"fe");function Ept(a){if(a==="")return a;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(a))throw new TypeError(`Invalid hostname '${a}'`);let s=new URL("https://example.com");return s.hostname=a,s.hostname}t(Ept,"z");function Cpt(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(Cpt,"j");function Dpt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(Dpt,"K");function Fur(a){if(a==="")return a;let s=new URL("https://example.com");return s.pathname=a[0]!=="/"?"/-"+a:a,a[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(Fur,"he");function Lur(a){return a===""?a:new URL(`data:${a}`).pathname}t(Lur,"ue");function Rur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(Rur,"de");function Mur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(Mur,"pe");var jur=class{static{t(this,"H")}#r;#n=[];#e={};#t=0;#s=1;#p=0;#a=0;#_=0;#c=0;#l=!1;constructor(a){this.#r=a}get result(){return this.#e}parse(){for(this.#n=hpt(this.#r,!0);this.#t<this.#n.length;this.#t+=this.#s){if(this.#s=1,this.#n[this.#t].type==="END"){if(this.#a===0){this.#v(),this.#D()?this.#i(9,1):this.#y()?this.#i(8,1):this.#i(7,0);continue}else if(this.#a===2){this.#d(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#o())this.#_-=1;else continue;if(this.#w()){this.#_+=1;continue}switch(this.#a){case 0:this.#g()&&this.#d(1);break;case 1:if(this.#g()){this.#I();let a=7,s=1;this.#C()?(a=2,s=3):this.#l&&(a=2),this.#i(a,s)}break;case 2:this.#x()?this.#d(3):(this.#E()||this.#y()||this.#D())&&this.#d(5);break;case 3:this.#b()?this.#i(4,1):this.#x()&&this.#i(5,1);break;case 4:this.#x()&&this.#i(5,1);break;case 5:this.#N()?this.#c+=1:this.#S()&&(this.#c-=1),this.#k()&&!this.#c?this.#i(6,1):this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 6:this.#E()?this.#i(7,0):this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 7:this.#y()?this.#i(8,1):this.#D()&&this.#i(9,1);break;case 8:this.#D()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#e.hostname!==void 0&&this.#e.port===void 0&&(this.#e.port="")}#i(a,s){switch(this.#a){case 0:break;case 1:this.#e.protocol=this.#T();break;case 2:break;case 3:this.#e.username=this.#T();break;case 4:this.#e.password=this.#T();break;case 5:this.#e.hostname=this.#T();break;case 6:this.#e.port=this.#T();break;case 7:this.#e.pathname=this.#T();break;case 8:this.#e.search=this.#T();break;case 9:this.#e.hash=this.#T();break;case 10:break}this.#a!==0&&a!==10&&([1,2,3,4].includes(this.#a)&&[6,7,8,9].includes(a)&&(this.#e.hostname??=""),[1,2,3,4,5,6].includes(this.#a)&&[8,9].includes(a)&&(this.#e.pathname??=this.#l?"/":""),[1,2,3,4,5,6,7].includes(this.#a)&&a===9&&(this.#e.search??="")),this.#f(a,s)}#f(a,s){this.#a=a,this.#p=this.#t+s,this.#t+=s,this.#s=0}#v(){this.#t=this.#p,this.#s=0}#d(a){this.#v(),this.#a=a}#u(a){return a<0&&(a=this.#n.length-a),a<this.#n.length?this.#n[a]:this.#n[this.#n.length-1]}#m(a,s){let l=this.#u(a);return l.value===s&&(l.type==="CHAR"||l.type==="ESCAPED_CHAR"||l.type==="INVALID_CHAR")}#g(){return this.#m(this.#t,":")}#C(){return this.#m(this.#t+1,"/")&&this.#m(this.#t+2,"/")}#x(){return this.#m(this.#t,"@")}#b(){return this.#m(this.#t,":")}#k(){return this.#m(this.#t,":")}#E(){return this.#m(this.#t,"/")}#y(){if(this.#m(this.#t,"?"))return!0;if(this.#n[this.#t].value!=="?")return!1;let a=this.#u(this.#t-1);return a.type!=="NAME"&&a.type!=="REGEX"&&a.type!=="CLOSE"&&a.type!=="ASTERISK"}#D(){return this.#m(this.#t,"#")}#w(){return this.#n[this.#t].type=="OPEN"}#o(){return this.#n[this.#t].type=="CLOSE"}#N(){return this.#m(this.#t,"[")}#S(){return this.#m(this.#t,"]")}#T(){let a=this.#n[this.#t],s=this.#u(this.#p).index;return this.#r.substring(s,a.index)}#I(){let a={};Object.assign(a,H3),a.encodePart=iIe;let s=vur(this.#T(),void 0,a);this.#l=Tpt(s)}},rIe=["protocol","username","password","hostname","port","pathname","search","hash"],W3="*";function mpt(a,s){if(typeof a!="string")throw new TypeError("parameter 1 is not of type 'string'.");let l=new URL(a,s);return{protocol:l.protocol.substring(0,l.protocol.length-1),username:l.username,password:l.password,hostname:l.hostname,port:l.port,pathname:l.pathname,search:l.search!==""?l.search.substring(1,l.search.length):void 0,hash:l.hash!==""?l.hash.substring(1,l.hash.length):void 0}}t(mpt,"ge");function FA(a,s){return s?zG(a):a}t(FA,"b");function $G(a,s,l){let _;if(typeof s.baseURL=="string")try{_=new URL(s.baseURL),s.protocol===void 0&&(a.protocol=FA(_.protocol.substring(0,_.protocol.length-1),l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(a.username=FA(_.username,l)),!l&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(a.password=FA(_.password,l)),s.protocol===void 0&&s.hostname===void 0&&(a.hostname=FA(_.hostname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(a.port=FA(_.port,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(a.pathname=FA(_.pathname,l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(a.search=FA(_.search.substring(1,_.search.length),l)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(a.hash=FA(_.hash.substring(1,_.hash.length),l))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(a.protocol=Nur(s.protocol,l)),typeof s.username=="string"&&(a.username=wur(s.username,l)),typeof s.password=="string"&&(a.password=kur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=Dur(s.hostname,l)),typeof s.port=="string"&&(a.port=Aur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Tur(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=FA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=Pur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=Cur(s.search,l)),typeof s.hash=="string"&&(a.hash=Eur(s.hash,l)),a}t($G,"w");function zG(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t(zG,"C");function Bur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(Bur,"Oe");function Uur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${Bur(s.delimiter)}]+?`,h=/[$_\u200C\u200D\p{ID_Continue}]/u,b="";for(let D=0;D<a.length;++D){let A=a[D];if(A.type===3){if(A.modifier===3){b+=zG(A.value);continue}b+=`{${zG(A.value)}}${gj(A.modifier)}`;continue}let M=A.hasCustomName(),z=!!A.suffix.length||!!A.prefix.length&&(A.prefix.length!==1||!s.prefixes.includes(A.prefix)),re=D>0?a[D-1]:null,ie=D<a.length-1?a[D+1]:null;if(!z&&M&&A.type===1&&A.modifier===3&&ie&&!ie.prefix.length&&!ie.suffix.length)if(ie.type===3){let Q=ie.value.length>0?ie.value[0]:"";z=h.test(Q)}else z=!ie.hasCustomName();if(!z&&!A.prefix.length&&re&&re.type===3){let Q=re.value[re.value.length-1];z=s.prefixes.includes(Q)}z&&(b+="{"),b+=zG(A.prefix),M&&(b+=`:${A.name}`),A.type===2?b+=`(${A.value})`:A.type===1?M||(b+=`(${_})`):A.type===0&&(!M&&(!re||re.type===3||re.modifier!==3||z||A.prefix!=="")?b+="*":b+=`(${l})`),A.type===1&&M&&A.suffix.length&&h.test(A.suffix[0])&&(b+="\\"),b+=zG(A.suffix),z&&(b+="}"),A.modifier!==3&&(b+=gj(A.modifier))}return b}t(Uur,"ke");var kpt=class{static{t(this,"me")}#r;#n={};#e={};#t={};#s={};#p=!1;constructor(a={},s,l){try{let _;if(typeof s=="string"?_=s:l=s,typeof a=="string"){let A=new jur(a);if(A.parse(),a=A.result,_===void 0&&typeof a.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");a.baseURL=_}else{if(!a||typeof a!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(_)throw new TypeError("parameter 1 is not of type 'string'.")}typeof l>"u"&&(l={ignoreCase:!1});let h={ignoreCase:l.ignoreCase===!0},b={pathname:W3,protocol:W3,username:W3,password:W3,hostname:W3,port:W3,search:W3,hash:W3};this.#r=$G(b,a,!0),xpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of rIe){if(!(D in this.#r))continue;let A={},M=this.#r[D];switch(this.#e[D]=[],D){case"protocol":Object.assign(A,H3),A.encodePart=iIe;break;case"username":Object.assign(A,H3),A.encodePart=Iur;break;case"password":Object.assign(A,H3),A.encodePart=Our;break;case"hostname":Object.assign(A,bur),bpt(M)?A.encodePart=Cpt:A.encodePart=Ept;break;case"port":Object.assign(A,H3),A.encodePart=Dpt;break;case"pathname":Tpt(this.#n.protocol)?(Object.assign(A,Sur,h),A.encodePart=Fur):(Object.assign(A,H3,h),A.encodePart=Lur);break;case"search":Object.assign(A,H3,h),A.encodePart=Rur;break;case"hash":Object.assign(A,H3,h),A.encodePart=Mur;break}try{this.#s[D]=gpt(M,A),this.#n[D]=ypt(this.#s[D],this.#e[D],A),this.#t[D]=Uur(this.#s[D],A),this.#p=this.#p||this.#s[D].some(z=>z.type===2)}catch{throw new TypeError(`invalid ${D} pattern '${this.#r[D]}'.`)}}}catch(_){throw new TypeError(`Failed to construct 'URLPattern': ${_.message}`)}}test(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return!1;try{typeof a=="object"?l=$G(l,a,!1):l=$G(l,mpt(a,s),!1)}catch{return!1}let _;for(_ of rIe)if(!this.#n[_].exec(l[_]))return!1;return!0}exec(a={},s){let l={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof a!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof a>"u")return;try{typeof a=="object"?l=$G(l,a,!1):l=$G(l,mpt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of rIe){let b=this.#n[h].exec(l[h]);if(!b)return null;let D={};for(let[A,M]of this.#e[h].entries())if(typeof M=="string"||typeof M=="number"){let z=b[A+1];D[M]=z}_[h]={input:l[h]??"",groups:D}}return _}static compareComponent(a,s,l){let _=t((A,M)=>{for(let z of["type","modifier","prefix","value","suffix"]){if(A[z]<M[z])return-1;if(A[z]!==M[z])return 1}return 0},"o"),h=new JG(3,"","","","",3),b=new JG(0,"","","","",3),D=t((A,M)=>{let z=0;for(;z<Math.min(A.length,M.length);++z){let re=_(A[z],M[z]);if(re)return re}return A.length===M.length?0:_(A[z]??h,M[z]??h)},"s");return!s.#t[a]&&!l.#t[a]?0:s.#t[a]&&!l.#t[a]?D(s.#s[a],[b]):!s.#t[a]&&l.#t[a]?D([b],l.#s[a]):D(s.#s[a],l.#s[a])}get protocol(){return this.#t.protocol}get username(){return this.#t.username}get password(){return this.#t.password}get hostname(){return this.#t.hostname}get port(){return this.#t.port}get pathname(){return this.#t.pathname}get search(){return this.#t.search}get hash(){return this.#t.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=kpt);import{AssertionError as $ur}from"node:assert";function LA(a,s){if(a===!1)throw new $ur({message:s})}t(LA,"assert");var ec;(function(a){a.Object="Object",a.Property="Property",a.Array="Array",a.Literal="Literal",a.TemplateString="TemplateString",a.Identifier="Identifier",a.FunctionCall="FunctionCall",a.Raw="Raw"})(ec||(ec={}));function yj(a){return a.type===ec.Object}t(yj,"isAstObject");function RA(a){return a.type===ec.Property}t(RA,"isAstProperty");function wpt(a){return a.type===ec.Array}t(wpt,"isAstArray");function vj(a){return a.type===ec.Literal}t(vj,"isAstLiteral");function G3(a){if(a===void 0)throw new Error("Node is undefined");if(!yj(a))throw new Error("Node is not object")}t(G3,"assertAstObject");import{findNodeAtLocation as zur,getNodeValue as Jur,printParseErrorCode as qur,visit as Vur}from"jsonc-parser";var Wur={DEFAULT:{allowTrailingComma:!1}};function qG(a,s=[],l=Wur.DEFAULT){let _={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function h(M){_.type==="property"&&(_.length=M-_.offset,_=_.parent)}t(h,"ensurePropertyComplete");function b(M){return _.children?.push(M),M}t(b,"onValue"),Vur(a,{onObjectBegin:t((M,z,re)=>{_=b({type:"object",offset:M,length:-1,line:z+1,column:re+1,parent:_,children:[]})},"onObjectBegin"),onObjectProperty:t((M,z,re,ie,Q)=>{_=b({type:"property",offset:z,length:-1,line:ie+1,column:Q+1,parent:_,children:[]}),_.children?.push({type:"string",value:M,offset:z,length:re,line:ie,column:Q,parent:_})},"onObjectProperty"),onObjectEnd:t((M,z)=>{h(M+z),_.length=M+z-_.offset,_=_.parent,h(M+z)},"onObjectEnd"),onArrayBegin:t((M,z,re,ie)=>{_=b({type:"array",offset:M,length:-1,line:re+1,column:ie+1,parent:_,children:[]})},"onArrayBegin"),onArrayEnd:t((M,z)=>{_.length=M+z-_.offset,_=_.parent,h(M+z)},"onArrayEnd"),onLiteralValue:t((M,z,re,ie,Q)=>{b({type:Hur(M),offset:z,length:re,line:ie+1,column:Q+1,parent:_,value:M}),h(z+re)},"onLiteralValue"),onSeparator:t((M,z)=>{_.type==="property"&&(M===":"?_.colonOffset=z:M===","&&h(z))},"onSeparator"),onError:t((M,z,re,ie,Q)=>{s.push({error:M,offset:z,length:re,line:ie+1,column:Q+1})},"onError")},l);let A=_.children[0];return A&&delete A.parent,A}t(qG,"parse");function Hur(a){switch(typeof a){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(a){if(Array.isArray(a))return"array"}else return"null";return"object"}default:return"null"}}t(Hur,"getNodeType");function sIe(a,s){return zur(a,s)}t(sIe,"findNodeAtLocation");function VG(a){return Jur(a)}t(VG,"getNodeValue");function Ppt(a){return qur(a)}t(Ppt,"printParseErrorCode");var WG=class{static{t(this,"AstAdapter")}parse(s){let _=qG(s,[]);if(_)return this.parseNode(_,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,l){switch(s.type){case"object":return this.createObject(s,l);case"array":return this.createArray(s,l);case"property":return this.createProperty(s,l);case"string":return this.createLiteral(s,l);case"number":return this.createLiteral(s,l);case"boolean":return this.createLiteral(s,l);case"null":return this.createLiteral(s,l)}}createLiteral(s,l){return{type:ec.Literal,location:{line:s.line,column:s.column},parent:l,value:s.type==="null"?null:s.value}}createObject(s,l){let _={type:ec.Object,children:[],parent:l,location:{line:s.line,column:s.column}};return s.children?.forEach(h=>{_.children.push(this.parseNode(h,_))}),_}createProperty(s,l){LA(s.children?.length===2,"Invalid property node");let _={type:ec.Property,location:{line:s.line,column:s.column},parent:l,name:null,value:null};return _.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:ec.Identifier,parent:_},_.value=this.parseNode(s.children[1],_),_}createArray(s,l){let _={type:ec.Array,location:{line:s.line,column:s.column},parent:l,children:[]};return s.children?.forEach(h=>_.children.push(this.parseNode(h,_))),_}};var jT={createLiteral:t((a,s)=>({type:ec.Literal,parent:s,value:a}),"createLiteral"),createTemplateString:t((a,s)=>({type:ec.TemplateString,parent:s,value:a}),"createTemplateString"),createIdentifier:t((a,s)=>({type:ec.Identifier,value:a,parent:s}),"createIdentifier"),createProperty:t((a,s,l)=>{let _={type:ec.Property,parent:l,name:null,value:s};return _.name={value:a,type:ec.Identifier,parent:_},_.value.parent=_,_},"createProperty"),createArrayOfLiterals:t((a,s)=>{let l={type:ec.Array,parent:s,children:[]};for(let _ of a)l.children.push(jT.createLiteral(_,l));return l},"createArrayOfLiterals")};var Gur=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,HG=class{static{t(this,"SourceGenerator")}generate(s){let l=[];return this.generateSource(l,s),l.join("")}generateSource(s,l){switch(l.type){case ec.Array:return this.generateArray(s,l);case ec.Object:return this.generateObject(s,l);case ec.Property:return this.generateProperty(s,l);case ec.Literal:return this.generateLiteral(s,l);case ec.FunctionCall:return this.generateFunctionCall(s,l);case ec.Identifier:return this.generateIdentifier(s,l);case ec.Raw:return this.generateRaw(s,l);case ec.TemplateString:return this.generateTemplateString(s,l)}}generateArray(s,l){s.push("["),l.children.map(_=>{this.generateSource(s,_),s.push(",")}),s.push("]")}generateObject(s,l){s.push("{"),l.children.forEach(_=>{this.generateSource(s,_),s.push(",")}),s.push("}")}generateProperty(s,l){this.generateIdentifier(s,l.name),s.push(":"),this.generateSource(s,l.value)}generateFunctionCall(s,l){s.push(l.name.value),s.push("("),l.children.forEach((_,h,b)=>{this.generateSource(s,_),h<b.length&&s.push(",")}),s.push(")")}generateRaw(s,l){s.push(l.value)}generateTemplateString(s,l){s.push("`"),s.push(l.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,l){if(l.value===null)return s.push("null");switch(typeof l.value){case"number":case"boolean":return s.push(`${l.value}`);case"string":{let _=l.value,h=JSON.stringify(_);return s.push(`${h}`)}}}generateIdentifier(s,l){let _=Gur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Kur from"node:fs/promises";import{parse as Yur}from"@swc/core";var Apt=t(async a=>{let s=new Set;try{let l=await Kur.readFile(a,"utf-8");(await Yur(l,{syntax:"typescript"})).body.forEach(h=>{h.type==="ExportDefaultDeclaration"||h.type==="ExportDefaultExpression"?s.add("default"):h.type==="ExportDeclaration"&&h.declaration.type==="FunctionDeclaration"?s.add(h.declaration.identifier.value):h.type==="ExportDeclaration"&&h.declaration.type==="VariableDeclaration"&&h.declaration.declarations[0].id.type==="Identifier"&&s.add(h.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Npt={$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 aIe={$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 Ipt={$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 oIe={$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:{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-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var cIe={$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 Vht=x_(dht(),1),Wht=x_(qht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new Wht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Vht.default)(this.ajv,{mode:"fast"})}addSchema(s,l){this.ajv.addSchema(s,l)}compile(s){let l=this.ajv.compile(s);return t(h=>({isValid:l(h),errors:this.toSimpleErrors(l.errors,h),warnings:[]}),"validator")}toSimpleErrors(s,l){let _=[];return s?.forEach(h=>{h.keyword==="enum"&&h.params.allowedValues&&Array.isArray(h.params.allowedValues)&&(h.message+=`; ${h.params.allowedValues.join(", ")}`),h.instancePath&&(h.instancePath=h.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let b={details:{}},D=h.instancePath.split("/");if(D.length>2){let M=D[1],z=D[2]?parseInt(D[2]):0,re=D[3],ie=isNaN(z)?void 0:l[M][z][re];b={details:{property:M,index:z,field:re,fieldValue:ie}}}if(h.keyword==="required"&&h.params.missingProperty&&h.instancePath&&(h.message=`A 'path' is missing required property '${h.params.missingProperty}'`),h.keyword==="additionalProperties"&&h.params.additionalProperty&&h.instancePath&&(h.message=`A 'path' should NOT include property '${h.params.additionalProperty}'`),h.keyword==="type"&&h.params.type&&h.instancePath){let M=h.instancePath.split("/"),z=M[M.length-1];h.message=`Value of property '${z}' must be '${h.params.type}'`}let A=Object.assign(h,b);_.push(A)}),_}};var iN=Lfe.instance;iN.addSchema(cIe,"route-configuration.schema.json");iN.addSchema(Ipt,"policy-configuration.schema.json");iN.addSchema(aIe,"policies.schema.json");iN.addSchema(oIe,"open-api-route-configuration.schema.json");iN.addSchema(Npt,"fragments.schema.json");var fRr=iN.compile(cIe),Hht=iN.compile(oIe),xOe=iN.compile(aIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=xOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Hht(s),this.results}};import n0r from"node:path";var EOe=/\$import\((.*)\)/,jfe=/\$env\((.*?)\)/g;var $A=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,l,_,h){super(s),this.location={file:l,namespace:"",line:_?_.line:0,column:_?_.column:0,length:0,lineText:h??"",suggestion:""}}},r0r=t(a=>{let s=[],l=a;for(;l.parent;)s.push(l),l=l.parent;return s.reverse()},"invertTree"),sN=t((a,s)=>{if(!a)return!1;let l=r0r(a);return s.split("/").every((b,D)=>{let A=l[D];return A?b==="*"||RA(A)&&A.name.value===b?!0:b==="{}"?A.type===ec.Object:b==="[]"?A.type===ec.Array:!1:!1})},"testPosition");var Bfe=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),yj(s)?s.children.forEach(l=>{this.visitor(l)}):wpt(s)?s.children.forEach(l=>{this.visitor(l)}):RA(s)&&this.visitor(s.value)}},Ght=t((a,s,l)=>_=>{if(!RA(_)||!vj(_.value)||typeof _.value.value!="string")return;if(!a.some(b=>sN(_,b))){jfe.test(_.value.value)&&s.push(new $A("An $env() statement is not expected at this location.",l,_.location,_.value.value));return}let h=new RegExp(jfe).exec(_.value.value);if(h?.length===2&&h[0]===_.value.value){let b={type:ec.Raw,parent:null,value:`environment["${h[1]}"]`};_.value=b}else{let b=_.value.value.replaceAll(new RegExp(jfe),(D,A)=>`\${environment["${A}"] ? environment["${A}"] : ""}`);b!==_.value.value&&(_.value=jT.createTemplateString(b,_))}},"getEnvStatementTransformer");var DK="config/routes.json",i0r=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],s0r=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Kht=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],a0r="handler/{}/options/{}/rewritePattern",o0r="handler/{}/options/{}/baseUrl",Ufe=class extends Bfe{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let l=this.addedImports.get(s);if(!l)throw new Error("Import name is undefined. This should not happen.");return l}getImports(){let s=[];return this.addedImports.forEach((l,_)=>{s.push({name:l,path:_})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!RA(s)||!vj(s.value)||typeof s.value.value!="string")&&sN(s,a0r)){if(!s.parent||!yj(s.parent)){this.errors.push(new $A("Invalid node, expected object",DK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Yht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}rewriteForwardFunction(s){if(!(!RA(s)||!vj(s.value)||typeof s.value.value!="string")&&sN(s,o0r)){if(!s.parent||!yj(s.parent)){this.errors.push(new $A("Invalid node, expected object",DK,s.parent?s.parent.location:s.location,void 0));return}let l=s.value.value,_={type:ec.Raw,parent:null,value:Yht(l)},h=jT.createProperty("__rewriteFunction",_,s);s.parent.children.push(h)}}replaceImportStatements(s){if(!RA(s)||!vj(s.value))return;let l=s.value.value;if(typeof l!="string")return;if(!s0r.some(A=>sN(s,A))&&!Kht.some(A=>sN(s,A))){if(EOe.test(l)){if(s.name.value==="$ref")return;this.errors.push(new $A("An $import() statement is not expected at this location.",DK,s.location,l))}return}let _=EOe.exec(l);if(Kht.some(A=>sN(s,A))&&!_)return;if(!_){this.errors.push(new $A("Invalid $import() statement",DK,s.location,l));return}let h=_[1];h=h.replace(/\\/g,"/"),h.startsWith(".")&&(h=n0r.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=Ght(i0r,this.errors,DK)};function Yht(a){return`(request, context) => {
|
|
584
584
|
const { params, url, query, method, headers } = request;
|
|
585
585
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
586
586
|
const e = encodeURIComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/core",
|
|
3
|
-
"version": "6.59.
|
|
3
|
+
"version": "6.59.9",
|
|
4
4
|
"repository": "https://github.com/zuplo/zuplo",
|
|
5
5
|
"author": "Zuplo, Inc.",
|
|
6
6
|
"type": "module",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"prettier": "^3.5.3"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@zuplo/graphql": "6.59.
|
|
45
|
-
"@zuplo/otel": "6.59.
|
|
46
|
-
"@zuplo/runtime": "6.59.
|
|
44
|
+
"@zuplo/graphql": "6.59.9",
|
|
45
|
+
"@zuplo/otel": "6.59.9",
|
|
46
|
+
"@zuplo/runtime": "6.59.9",
|
|
47
47
|
"deno": "2.3.1"
|
|
48
48
|
}
|
|
49
49
|
}
|