@zuplo/core 6.55.5 → 6.55.6
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(Ear,"tarFolder");async function Car({tarFilePath:a,outputDir:s,logger:l}){let _=[],h=[],b;try{await new Promise((D,N)=>{let M=Kut("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(Car,"untarFile");async function Dar(a){if(await H3e(a))return await j3.rm(a,{recursive:!0})}t(Dar,"deleteFolder");var ou=G3e;var OT=ap(W3e(),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 _=Aar(l.url);if(!(_===void 0||_==="file"))return!1;let b;try{b=Zut(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{_=Zut(l.url)}catch(h){throw new cF(`Malformed URI: ${l.url}`,{cause:h})}try{return await kar(_)}catch(h){throw new cF(`Error opening file "${_}"`,{cause:h})}}}}t(due,"customResolver");var sj=/^win/.test(globalThis.process?globalThis.process.platform:""),war=/\//g,Par=/^(\w{2,}):\/\//i,K3e=[/%23/g,"#",/%24/g,"$",/%26/g,"&",/%2C/g,",",/%40/g,"@"];function Aar(a){let s=Par.exec(a);if(s)return s[1].toLowerCase()}t(Aar,"getProtocol");function Zut(a,s){a=decodeURI(a);for(let _=0;_<K3e.length;_+=2)a=a.replace(K3e[_],K3e[_+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(war,"\\"),a.substr(1,2)===":\\"&&(a=a[0].toUpperCase()+a.substr(1))),a}t(Zut,"toFileSystemPath");var eft="YOUR_KEY_HERE";async function tft(a){let l=await new B3(a.sourceDirectory,a.logger).bundle(a.openApiDocPath),_=a.openApiDocPath.replace(a.sourceDirectory,"");return Nar({...a,relativeOpenApiPath:_},l)}t(tft,"buildPublicOpenApiFile");async function Nar(a,s){Lar({relativeOpenApiPath:a.relativeOpenApiPath},s);let l=s;return l=Oar(l),Iar(l,a.urls?.api?.defaultUrl),l=Far(l,a),rft(l,"x-zuplo"),l}t(Nar,"buildRawOpenApiFile");function Iar(a,s){s?a.servers=[{url:s}]:a.servers=[]}t(Iar,"addServerHost");function Oar(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(Oar,"removeHiddenRoutesAndParams");function Far(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:wt})=>wt===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} ${eft}`:eft,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(Tr=>"name"in Tr&&Tr.name===Ie.name)||N.parameters.unshift(Ie):N.parameters=[Ie];let we={type:"http",scheme:Q.toLowerCase()},wt="api_key";a.components?.securitySchemes?Object.values(a.components?.securitySchemes).some(Tr=>"name"in Tr&&Tr.type==="apiKey"||"type"in Tr&&Tr.type==="http"&&Tr.scheme===Q)||(a.components.securitySchemes={...a.components.securitySchemes,[wt]:we}):(a.components||(a.components={}),a.components.securitySchemes={[wt]:we});let xt={[wt]:[]};N.security?N.security.some(Tr=>Tr[wt]!==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(Far,"enrichSpecWithZuploData");function rft(a,s){for(let l in a)l.startsWith(s)?delete a[l]:typeof a[l]=="object"&&rft(a[l],s)}t(rft,"removePropertiesByPrefix");function Lar({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(Lar,"assertIsZuploOpenApiSpec");import DK from"node:path";function Rar(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 Tr=z[Q],fn=0;for(let tn=Ie-1;(Tr!==0||fn<ie)&&tn!==-1;tn--,fn++)Tr+=256*we[tn]>>>0,we[tn]=Tr%l>>>0,Tr=Tr/l>>>0;if(Tr!==0)throw new Error("Non-zero carry");ie=fn,Q++}let wt=Ie-ie;for(;wt!==Ie&&we[wt]===0;)wt++;let xt=_.repeat(re);for(;wt<Ie;++wt)xt+=a.charAt(we[wt]);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 Tr=s[z.charCodeAt(re)];if(Tr===255)return;let fn=0;for(let tn=Re-1;(Tr!==0||fn<Q)&&tn!==-1;tn--,fn++)Tr+=l*Ie[tn]>>>0,Ie[tn]=Tr%256>>>0,Tr=Tr/256>>>0;if(Tr!==0)throw new Error("Non-zero carry");Q=fn,re++}let we=Re-Q;for(;we!==Re&&Ie[we]===0;)we++;let wt=new Uint8Array(ie+(Re-we)),xt=ie;for(;we!==Re;)wt[xt++]=Ie[we++];return wt}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(Rar,"base");var nft=Rar;var Mar="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",mue=nft(Mar);var jar=!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 jar?`${s.open}${a.replace(s.regexp,s.open)}${s.close}`:a}t(oj,"run");function Bar(a){return oj(a,aj([31],39))}t(Bar,"red");function Uar(a){return oj(a,aj([32],39))}t(Uar,"green");function $ar(a){return oj(a,aj([33],39))}t($ar,"yellow");function zar(a){return oj(a,aj([34],39))}t(zar,"blue");function Jar(a){return oj(a,aj([35],39))}t(Jar,"magenta");function qar(a){return oj(a,aj([36],39))}t(qar,"cyan");var Q8r=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 ift=[Bar,Uar,$ar,zar,Jar,qar];function Var(a){let s=0,l=a.length,_=0;if(l>0)for(;_<l;)s=(s<<5)-s+a.charCodeAt(_++)|0;return s}t(Var,"hashCode");function sft(a){let s=Math.abs(Var(a));return ift[s%ift.length]}t(sft,"generateColor");import{inspect as War}from"node:util";function aft(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(aft,"format");var oft=t((a,...s)=>aft(War,a,s),"format");var Y3e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=sft(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=oft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},X3e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function Har(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(Har,"extract");var hue;function gue(a){hue||(hue=new X3e(Har(process.env.DEBUG)));let s=new Y3e(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 cft="zp-local-service";var dOr=Symbol("zuplo_meters"),mOr=Symbol("zuplo_dynamic_meters");var lF=gue("zuplo:runtime:external-service");function Gar(){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(Gar,"getServiceAuth");async function lft(a,s){let l=Gar();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 Kar(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=fft(re.ENVIRONMENT_TYPE),Re=await Q3e(`${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(lft,"externalServiceHandler");async function uft(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(cft,_),h.headers=N,await xG(D.toString(),h)}else throw new U3("Currently, we only support fetch(<some_string>, ...).")}t(uft,"clusterServiceHandler");async function Kar(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),N=fft(_);lF(`Hashing service name: ${b}-${h}.${b}-${D}-${N}`);let M=await Q3e(`${b}-${h}`),z=await Q3e(`${b}-${D}-${N}`);return`${M}.${z}`}t(Kar,"hashServiceName");async function Q3e(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(Q3e,"hashSegment");function fft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(fft,"sanitizeEnvironmentType");var Z3e=new Map;Z3e.set("service:",lft);Z3e.set("local:",uft);var xG=globalThis.fetch;function eNe(a,s){let l=Yar(s);if(typeof a=="string"){let _=new URL(a),h=Z3e.get(_.protocol);return h?h(a,l):xG(a,l)}else return xG(a,l)}t(eNe,"internalFetch");globalThis.fetch=eNe;var Yar=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 Xar={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:eNe},EG=Xar;var tNe="2025-02-06",_ft=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 pft(){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:tNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:_ft[tNe]},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(pft,"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=pft()),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(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="deno":this.config.runtime_type?this.config.runtime_type==="deno":typeof WebSocketPair!="function"}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"}};var Qar=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function dft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!Qar.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):!1}t(dft,"isRestrictedEnvVariableName");function mft(a){return!!a.startsWith("ZUPLO_")}t(mft,"isZuploReadableEnvVariableName");var $Or=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(!(dft(l)&&!mft(l)))return F0.instance.runtime[l]}});function CG(a,s,l){return`_${DA(`${a}_${s}_${l}`)}`}t(CG,"getRawOperationDataIdentifierName");function rNe(a,s,l,_){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(rNe,"getIdForParameterSchema");function nNe(a,s,l){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_rb_${DA(l.toLowerCase())}`}t(nNe,"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 Hht=ap(spt(),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"}},Vlr=/[$_\p{ID_Start}]/u,Wlr=/[$_\u200C\u200D\p{ID_Continue}]/u,XNe=".*";function Hlr(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(Hlr,"Re");function cpt(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&&Vlr.test(M)||N!==_+1&&Wlr.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(!Hlr(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(cpt,"v");function lpt(a,s={}){let l=cpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,N="",M=new Set,z=t(fn=>{if(D<l.length&&l[D].type===fn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(fn=>{let tn=z(fn);if(tn!==void 0)return tn;let{type:cn,index:Er}=l[D];throw new TypeError(`Unexpected ${cn} at ${Er}, expected ${fn}`)},"d"),Q=t(()=>{let fn="",tn;for(;tn=z("CHAR")??z("ESCAPED_CHAR");)fn+=tn;return fn},"T"),Re=t(fn=>fn,"Se"),Ie=s.encodePart||Re,we="",wt=t(fn=>{we+=fn},"U"),xt=t(()=>{we.length&&(h.push(new zG(3,"","",Ie(we),"",3)),we="")},"$"),Tr=t((fn,tn,cn,Er,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!tn&&!cn&&fs===3){wt(fn);return}if(xt(),!tn&&!cn){if(!fn)return;h.push(new zG(3,"","",Ie(fn),"",fs));return}let Oi;cn?cn==="*"?Oi=XNe:Oi=cn:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===XNe&&(Ho=0,Oi="");let di;if(tn?di=tn:cn&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new zG(Ho,di,Ie(fn),Oi,Ie(Er),fs))},"V");for(;D<l.length;){let fn=z("CHAR"),tn=z("NAME"),cn=z("REGEX");if(!tn&&!cn&&(cn=z("ASTERISK")),tn||cn){let vr=fn??"";s.prefixes.indexOf(vr)===-1&&(wt(vr),vr=""),xt();let fs=re();Tr(vr,tn,cn,"",fs);continue}let Er=fn??z("ESCAPED_CHAR");if(Er){wt(Er);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();Tr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(lpt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function apt(a){return a&&a.ignoreCase?"ui":"u"}t(apt,"X");function Glr(a,s,l){return upt(lpt(a,l),s,l)}t(Glr,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function upt(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=XNe),!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(_,apt(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(_,apt(l))}t(upt,"F");var q3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},Klr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Ylr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Xlr(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Xlr,"J");function fpt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(fpt,"Q");function Qlr(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(Qlr,"Ee");function _pt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(_pt,"W");var ppt=["ftp","file","http","https","ws","wss"];function dpt(a){if(!a)return!0;for(let s of ppt)if(a.test(s))return!0;return!1}t(dpt,"N");function Zlr(a,s){if(a=fpt(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(Zlr,"te");function eur(a,s){if(a=fpt(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(eur,"re");function tur(a,s){return s||a===""?a:_pt(a)?gpt(a):hpt(a)}t(tur,"ne");function rur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(rur,"se");function nur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(nur,"ie");function iur(a,s,l){if(l||a==="")return a;if(s&&!ppt.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(iur,"ae");function sur(a,s,l){return mpt(s)===a&&(a=""),l||a===""?a:ypt(a)}t(sur,"oe");function aur(a,s){return a=Qlr(a,":"),s||a===""?a:QNe(a)}t(aur,"ce");function mpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(mpt,"_");function QNe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(QNe,"y");function our(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(our,"le");function cur(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(cur,"fe");function hpt(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(hpt,"z");function gpt(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(gpt,"j");function ypt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(ypt,"K");function lur(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(lur,"he");function uur(a){return a===""?a:new URL(`data:${a}`).pathname}t(uur,"ue");function fur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(fur,"de");function _ur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(_ur,"pe");var pur=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=cpt(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=QNe;let s=Glr(this.#T(),void 0,a);this.#l=dpt(s)}},YNe=["protocol","username","password","hostname","port","pathname","search","hash"],J3="*";function opt(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(opt,"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=aur(s.protocol,l)),typeof s.username=="string"&&(a.username=nur(s.username,l)),typeof s.password=="string"&&(a.password=rur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=tur(s.hostname,l)),typeof s.port=="string"&&(a.port=sur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Xlr(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=NA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=iur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=eur(s.search,l)),typeof s.hash=="string"&&(a.hash=Zlr(s.hash,l)),a}t(UG,"w");function $G(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t($G,"C");function dur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(dur,"Oe");function mur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${dur(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(mur,"ke");var vpt=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 pur(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),mpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of YNe){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=QNe;break;case"username":Object.assign(N,q3),N.encodePart=our;break;case"password":Object.assign(N,q3),N.encodePart=cur;break;case"hostname":Object.assign(N,Klr),_pt(M)?N.encodePart=gpt:N.encodePart=hpt;break;case"port":Object.assign(N,q3),N.encodePart=ypt;break;case"pathname":dpt(this.#n.protocol)?(Object.assign(N,Ylr,h),N.encodePart=lur):(Object.assign(N,q3,h),N.encodePart=uur);break;case"search":Object.assign(N,q3,h),N.encodePart=fur;break;case"hash":Object.assign(N,q3,h),N.encodePart=_ur;break}try{this.#s[D]=lpt(M,N),this.#n[D]=upt(this.#s[D],this.#e[D],N),this.#t[D]=mur(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,opt(a,s),!1)}catch{return!1}let _;for(_ of YNe)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,opt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of YNe){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=vpt);import{AssertionError as hur}from"node:assert";function IA(a,s){if(a===!1)throw new hur({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 bpt(a){return a.type===ec.Array}t(bpt,"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 gur,getNodeValue as yur,printParseErrorCode as vur,visit as bur}from"jsonc-parser";var Sur={DEFAULT:{allowTrailingComma:!1}};function JG(a,s=[],l=Sur.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"),bur(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:Tur(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 Tur(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(Tur,"getNodeType");function ZNe(a,s){return gur(a,s)}t(ZNe,"findNodeAtLocation");function qG(a){return yur(a)}t(qG,"getNodeValue");function Spt(a){return vur(a)}t(Spt,"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 xur=/^[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 _=xur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Eur from"node:fs/promises";import{parse as Cur}from"@swc/core";var Tpt=t(async a=>{let s=new Set;try{let l=await Eur.readFile(a,"utf-8");(await Cur(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 xpt={$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 eIe={$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 Ept={$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 tIe={$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 rIe={$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 Mht=ap(aht(),1),jht=ap(Rht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new jht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Mht.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(rIe,"route-configuration.schema.json");tN.addSchema(Ept,"policy-configuration.schema.json");tN.addSchema(eIe,"policies.schema.json");tN.addSchema(tIe,"open-api-route-configuration.schema.json");tN.addSchema(xpt,"fragments.schema.json");var ULr=tN.compile(rIe),Bht=tN.compile(tIe),gOe=tN.compile(eIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=gOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Bht(s),this.results}};import Igr from"node:path";var yOe=/\$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:""}}},Ngr=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=Ngr(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)}):bpt(s)?s.children.forEach(l=>{this.visitor(l)}):OA(s)&&this.visitor(s.value)}},Uht=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",Ogr=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],Fgr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],$ht=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Lgr="handler/{}/options/{}/rewritePattern",Rgr="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,Lgr)){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:zht(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,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:zht(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(!Fgr.some(N=>rN(s,N))&&!$ht.some(N=>rN(s,N))){if(yOe.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 _=yOe.exec(l);if($ht.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=Igr.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=Uht(Ogr,this.errors,CK)};function zht(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(aft,"format");var oft=t((a,...s)=>aft(War,a,s),"format");var Y3e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=sft(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=oft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},X3e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function Har(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(Har,"extract");var hue;function gue(a){hue||(hue=new X3e(Har(process.env.DEBUG)));let s=new Y3e(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 cft="zp-local-service";var dOr=Symbol("zuplo_meters"),mOr=Symbol("zuplo_dynamic_meters");var lF=gue("zuplo:runtime:external-service");function Gar(){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(Gar,"getServiceAuth");async function lft(a,s){let l=Gar();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 Kar(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=fft(re.ENVIRONMENT_TYPE),Re=await Q3e(`${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(lft,"externalServiceHandler");async function uft(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(cft,_),h.headers=N,await xG(D.toString(),h)}else throw new U3("Currently, we only support fetch(<some_string>, ...).")}t(uft,"clusterServiceHandler");async function Kar(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),N=fft(_);lF(`Hashing service name: ${b}-${h}.${b}-${D}-${N}`);let M=await Q3e(`${b}-${h}`),z=await Q3e(`${b}-${D}-${N}`);return`${M}.${z}`}t(Kar,"hashServiceName");async function Q3e(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(Q3e,"hashSegment");function fft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(fft,"sanitizeEnvironmentType");var Z3e=new Map;Z3e.set("service:",lft);Z3e.set("local:",uft);var xG=globalThis.fetch;function eNe(a,s){let l=Yar(s);if(typeof a=="string"){let _=new URL(a),h=Z3e.get(_.protocol);return h?h(a,l):xG(a,l)}else return xG(a,l)}t(eNe,"internalFetch");globalThis.fetch=eNe;var Yar=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 Xar={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:eNe},EG=Xar;var tNe="2025-02-06",_ft=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 pft(){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:tNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:_ft[tNe]},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(pft,"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=pft()),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(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="deno":this.config.runtime_type?this.config.runtime_type==="deno":typeof WebSocketPair!="function"}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"}};var Qar=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function dft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!Qar.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):a.startsWith("ZUDOKU_")?!a.startsWith("ZUDOKU_PUBLIC_"):!1}t(dft,"isRestrictedEnvVariableName");function mft(a){return!!a.startsWith("ZUPLO_")}t(mft,"isZuploReadableEnvVariableName");var $Or=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(!(dft(l)&&!mft(l)))return F0.instance.runtime[l]}});function CG(a,s,l){return`_${DA(`${a}_${s}_${l}`)}`}t(CG,"getRawOperationDataIdentifierName");function rNe(a,s,l,_){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(rNe,"getIdForParameterSchema");function nNe(a,s,l){return`_${DA(a.toLowerCase())}_${s.toLowerCase()}_rb_${DA(l.toLowerCase())}`}t(nNe,"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 Hht=ap(spt(),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"}},Vlr=/[$_\p{ID_Start}]/u,Wlr=/[$_\u200C\u200D\p{ID_Continue}]/u,XNe=".*";function Hlr(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(Hlr,"Re");function cpt(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&&Vlr.test(M)||N!==_+1&&Wlr.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(!Hlr(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(cpt,"v");function lpt(a,s={}){let l=cpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,N="",M=new Set,z=t(fn=>{if(D<l.length&&l[D].type===fn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(fn=>{let tn=z(fn);if(tn!==void 0)return tn;let{type:cn,index:Er}=l[D];throw new TypeError(`Unexpected ${cn} at ${Er}, expected ${fn}`)},"d"),Q=t(()=>{let fn="",tn;for(;tn=z("CHAR")??z("ESCAPED_CHAR");)fn+=tn;return fn},"T"),Re=t(fn=>fn,"Se"),Ie=s.encodePart||Re,we="",wt=t(fn=>{we+=fn},"U"),xt=t(()=>{we.length&&(h.push(new zG(3,"","",Ie(we),"",3)),we="")},"$"),Tr=t((fn,tn,cn,Er,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!tn&&!cn&&fs===3){wt(fn);return}if(xt(),!tn&&!cn){if(!fn)return;h.push(new zG(3,"","",Ie(fn),"",fs));return}let Oi;cn?cn==="*"?Oi=XNe:Oi=cn:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===XNe&&(Ho=0,Oi="");let di;if(tn?di=tn:cn&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new zG(Ho,di,Ie(fn),Oi,Ie(Er),fs))},"V");for(;D<l.length;){let fn=z("CHAR"),tn=z("NAME"),cn=z("REGEX");if(!tn&&!cn&&(cn=z("ASTERISK")),tn||cn){let vr=fn??"";s.prefixes.indexOf(vr)===-1&&(wt(vr),vr=""),xt();let fs=re();Tr(vr,tn,cn,"",fs);continue}let Er=fn??z("ESCAPED_CHAR");if(Er){wt(Er);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();Tr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(lpt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function apt(a){return a&&a.ignoreCase?"ui":"u"}t(apt,"X");function Glr(a,s,l){return upt(lpt(a,l),s,l)}t(Glr,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function upt(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=XNe),!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(_,apt(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(_,apt(l))}t(upt,"F");var q3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},Klr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Ylr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Xlr(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Xlr,"J");function fpt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(fpt,"Q");function Qlr(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(Qlr,"Ee");function _pt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(_pt,"W");var ppt=["ftp","file","http","https","ws","wss"];function dpt(a){if(!a)return!0;for(let s of ppt)if(a.test(s))return!0;return!1}t(dpt,"N");function Zlr(a,s){if(a=fpt(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(Zlr,"te");function eur(a,s){if(a=fpt(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(eur,"re");function tur(a,s){return s||a===""?a:_pt(a)?gpt(a):hpt(a)}t(tur,"ne");function rur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(rur,"se");function nur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(nur,"ie");function iur(a,s,l){if(l||a==="")return a;if(s&&!ppt.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(iur,"ae");function sur(a,s,l){return mpt(s)===a&&(a=""),l||a===""?a:ypt(a)}t(sur,"oe");function aur(a,s){return a=Qlr(a,":"),s||a===""?a:QNe(a)}t(aur,"ce");function mpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(mpt,"_");function QNe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(QNe,"y");function our(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(our,"le");function cur(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(cur,"fe");function hpt(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(hpt,"z");function gpt(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(gpt,"j");function ypt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(ypt,"K");function lur(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(lur,"he");function uur(a){return a===""?a:new URL(`data:${a}`).pathname}t(uur,"ue");function fur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(fur,"de");function _ur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(_ur,"pe");var pur=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=cpt(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=QNe;let s=Glr(this.#T(),void 0,a);this.#l=dpt(s)}},YNe=["protocol","username","password","hostname","port","pathname","search","hash"],J3="*";function opt(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(opt,"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=aur(s.protocol,l)),typeof s.username=="string"&&(a.username=nur(s.username,l)),typeof s.password=="string"&&(a.password=rur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=tur(s.hostname,l)),typeof s.port=="string"&&(a.port=sur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Xlr(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=NA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=iur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=eur(s.search,l)),typeof s.hash=="string"&&(a.hash=Zlr(s.hash,l)),a}t(UG,"w");function $G(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t($G,"C");function dur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(dur,"Oe");function mur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${dur(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(mur,"ke");var vpt=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 pur(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),mpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of YNe){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=QNe;break;case"username":Object.assign(N,q3),N.encodePart=our;break;case"password":Object.assign(N,q3),N.encodePart=cur;break;case"hostname":Object.assign(N,Klr),_pt(M)?N.encodePart=gpt:N.encodePart=hpt;break;case"port":Object.assign(N,q3),N.encodePart=ypt;break;case"pathname":dpt(this.#n.protocol)?(Object.assign(N,Ylr,h),N.encodePart=lur):(Object.assign(N,q3,h),N.encodePart=uur);break;case"search":Object.assign(N,q3,h),N.encodePart=fur;break;case"hash":Object.assign(N,q3,h),N.encodePart=_ur;break}try{this.#s[D]=lpt(M,N),this.#n[D]=upt(this.#s[D],this.#e[D],N),this.#t[D]=mur(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,opt(a,s),!1)}catch{return!1}let _;for(_ of YNe)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,opt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of YNe){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=vpt);import{AssertionError as hur}from"node:assert";function IA(a,s){if(a===!1)throw new hur({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 bpt(a){return a.type===ec.Array}t(bpt,"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 gur,getNodeValue as yur,printParseErrorCode as vur,visit as bur}from"jsonc-parser";var Sur={DEFAULT:{allowTrailingComma:!1}};function JG(a,s=[],l=Sur.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"),bur(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:Tur(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 Tur(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(Tur,"getNodeType");function ZNe(a,s){return gur(a,s)}t(ZNe,"findNodeAtLocation");function qG(a){return yur(a)}t(qG,"getNodeValue");function Spt(a){return vur(a)}t(Spt,"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 xur=/^[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 _=xur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Eur from"node:fs/promises";import{parse as Cur}from"@swc/core";var Tpt=t(async a=>{let s=new Set;try{let l=await Eur.readFile(a,"utf-8");(await Cur(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 xpt={$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 eIe={$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 Ept={$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 tIe={$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 rIe={$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 Mht=ap(aht(),1),jht=ap(Rht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new jht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Mht.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(rIe,"route-configuration.schema.json");tN.addSchema(Ept,"policy-configuration.schema.json");tN.addSchema(eIe,"policies.schema.json");tN.addSchema(tIe,"open-api-route-configuration.schema.json");tN.addSchema(xpt,"fragments.schema.json");var ULr=tN.compile(rIe),Bht=tN.compile(tIe),gOe=tN.compile(eIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=gOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Bht(s),this.results}};import Igr from"node:path";var yOe=/\$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:""}}},Ngr=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=Ngr(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)}):bpt(s)?s.children.forEach(l=>{this.visitor(l)}):OA(s)&&this.visitor(s.value)}},Uht=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",Ogr=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],Fgr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],$ht=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Lgr="handler/{}/options/{}/rewritePattern",Rgr="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,Lgr)){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:zht(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,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:zht(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(!Fgr.some(N=>rN(s,N))&&!$ht.some(N=>rN(s,N))){if(yOe.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 _=yOe.exec(l);if($ht.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=Igr.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=Uht(Ogr,this.errors,CK)};function zht(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(Gar,"tarFolder");async function Kar({tarFilePath:a,outputDir:s,logger:l}){let _=[],h=[],b;try{await new Promise((D,A)=>{let M=rft("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(Kar,"untarFile");async function Yar(a){if(await Q3e(a))return await $3.rm(a,{recursive:!0})}t(Yar,"deleteFolder");var ou=Z3e;var OT=x_(X3e(),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 _=eor(l.url);if(!(_===void 0||_==="file"))return!1;let b;try{b=aft(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{_=aft(l.url)}catch(h){throw new uF(`Malformed URI: ${l.url}`,{cause:h})}try{return await Xar(_)}catch(h){throw new uF(`Error opening file "${_}"`,{cause:h})}}}}t(due,"customResolver");var sj=/^win/.test(globalThis.process?globalThis.process.platform:""),Qar=/\//g,Zar=/^(\w{2,}):\/\//i,eNe=[/%23/g,"#",/%24/g,"$",/%26/g,"&",/%2C/g,",",/%40/g,"@"];function eor(a){let s=Zar.exec(a);if(s)return s[1].toLowerCase()}t(eor,"getProtocol");function aft(a,s){a=decodeURI(a);for(let _=0;_<eNe.length;_+=2)a=a.replace(eNe[_],eNe[_+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(Qar,"\\"),a.substr(1,2)===":\\"&&(a=a[0].toUpperCase()+a.substr(1))),a}t(aft,"toFileSystemPath");var oft="YOUR_KEY_HERE";async function cft(a){let l=await new z3(a.sourceDirectory,a.logger).bundle(a.openApiDocPath),_=a.openApiDocPath.replace(a.sourceDirectory,"");return tor({...a,relativeOpenApiPath:_},l)}t(cft,"buildPublicOpenApiFile");async function tor(a,s){sor({relativeOpenApiPath:a.relativeOpenApiPath},s);let l=s;return l=nor(l),ror(l,a.urls?.api?.defaultUrl),l=ior(l,a),lft(l,"x-zuplo"),l}t(tor,"buildRawOpenApiFile");function ror(a,s){s?a.servers=[{url:s}]:a.servers=[]}t(ror,"addServerHost");function nor(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(nor,"removeHiddenRoutesAndParams");function ior(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:wt})=>wt===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} ${oft}`:oft,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(Tr=>"name"in Tr&&Tr.name===Ie.name)||A.parameters.unshift(Ie):A.parameters=[Ie];let we={type:"http",scheme:Q.toLowerCase()},wt="api_key";a.components?.securitySchemes?Object.values(a.components?.securitySchemes).some(Tr=>"name"in Tr&&Tr.type==="apiKey"||"type"in Tr&&Tr.type==="http"&&Tr.scheme===Q)||(a.components.securitySchemes={...a.components.securitySchemes,[wt]:we}):(a.components||(a.components={}),a.components.securitySchemes={[wt]:we});let xt={[wt]:[]};A.security?A.security.some(Tr=>Tr[wt]!==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(ior,"enrichSpecWithZuploData");function lft(a,s){for(let l in a)l.startsWith(s)?delete a[l]:typeof a[l]=="object"&&lft(a[l],s)}t(lft,"removePropertiesByPrefix");function sor({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(sor,"assertIsZuploOpenApiSpec");import kK from"node:path";function aor(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 Tr=z[Q],fn=0;for(let tn=Ie-1;(Tr!==0||fn<ie)&&tn!==-1;tn--,fn++)Tr+=256*we[tn]>>>0,we[tn]=Tr%l>>>0,Tr=Tr/l>>>0;if(Tr!==0)throw new Error("Non-zero carry");ie=fn,Q++}let wt=Ie-ie;for(;wt!==Ie&&we[wt]===0;)wt++;let xt=_.repeat(re);for(;wt<Ie;++wt)xt+=a.charAt(we[wt]);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 Tr=s[z.charCodeAt(re)];if(Tr===255)return;let fn=0;for(let tn=Re-1;(Tr!==0||fn<Q)&&tn!==-1;tn--,fn++)Tr+=l*Ie[tn]>>>0,Ie[tn]=Tr%256>>>0,Tr=Tr/256>>>0;if(Tr!==0)throw new Error("Non-zero carry");Q=fn,re++}let we=Re-Q;for(;we!==Re&&Ie[we]===0;)we++;let wt=new Uint8Array(ie+(Re-we)),xt=ie;for(;we!==Re;)wt[xt++]=Ie[we++];return wt}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(aor,"base");var uft=aor;var oor="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",mue=uft(oor);var cor=!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 cor?`${s.open}${a.replace(s.regexp,s.open)}${s.close}`:a}t(oj,"run");function lor(a){return oj(a,aj([31],39))}t(lor,"red");function uor(a){return oj(a,aj([32],39))}t(uor,"green");function _or(a){return oj(a,aj([33],39))}t(_or,"yellow");function por(a){return oj(a,aj([34],39))}t(por,"blue");function dor(a){return oj(a,aj([35],39))}t(dor,"magenta");function mor(a){return oj(a,aj([36],39))}t(mor,"cyan");var SOr=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 fft=[lor,uor,_or,por,dor,mor];function hor(a){let s=0,l=a.length,_=0;if(l>0)for(;_<l;)s=(s<<5)-s+a.charCodeAt(_++)|0;return s}t(hor,"hashCode");function _ft(a){let s=Math.abs(hor(a));return fft[s%fft.length]}t(_ft,"generateColor");import{inspect as gor}from"node:util";function pft(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(pft,"format");var dft=t((a,...s)=>pft(gor,a,s),"format");var tNe=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=_ft(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=dft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},rNe=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function yor(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(yor,"extract");var hue;function gue(a){hue||(hue=new rNe(yor(process.env.DEBUG)));let s=new tNe(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 mft="zp-local-service";var MOr=Symbol("zuplo_meters"),jOr=Symbol("zuplo_dynamic_meters");var fF=gue("zuplo:runtime:external-service");function vor(){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(vor,"getServiceAuth");async function hft(a,s){let l=vor();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 bor(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=yft(re.ENVIRONMENT_TYPE),Re=await nNe(`${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(hft,"externalServiceHandler");async function gft(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(mft,_),h.headers=A,await EG(D.toString(),h)}else throw new J3("Currently, we only support fetch(<some_string>, ...).")}t(gft,"clusterServiceHandler");async function bor(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),A=yft(_);fF(`Hashing service name: ${b}-${h}.${b}-${D}-${A}`);let M=await nNe(`${b}-${h}`),z=await nNe(`${b}-${D}-${A}`);return`${M}.${z}`}t(bor,"hashServiceName");async function nNe(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(nNe,"hashSegment");function yft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(yft,"sanitizeEnvironmentType");var iNe=new Map;iNe.set("service:",hft);iNe.set("local:",gft);var EG=globalThis.fetch;function sNe(a,s){let l=Sor(s);if(typeof a=="string"){let _=new URL(a),h=iNe.get(_.protocol);return h?h(a,l):EG(a,l)}else return EG(a,l)}t(sNe,"internalFetch");globalThis.fetch=sNe;var Sor=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 Tor={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:sNe},CG=Tor;var aNe="2025-02-06",vft=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 bft(){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:aNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:vft[aNe]},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(bft,"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=bft()),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(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="deno":this.config.runtime_type?this.config.runtime_type==="deno":typeof WebSocketPair!="function"}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"}};var xor=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function Sft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!xor.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):!1}t(Sft,"isRestrictedEnvVariableName");function Tft(a){return!!a.startsWith("ZUPLO_")}t(Tft,"isZuploReadableEnvVariableName");var uFr=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(!(Sft(l)&&!Tft(l)))return F0.instance.runtime[l]}});function DG(a,s,l){return`_${PA(`${a}_${s}_${l}`)}`}t(DG,"getRawOperationDataIdentifierName");function oNe(a,s,l,_){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(oNe,"getIdForParameterSchema");function cNe(a,s,l){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_rb_${PA(l.toLowerCase())}`}t(cNe,"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 egt=x_(_pt(),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"}},mur=/[$_\p{ID_Start}]/u,hur=/[$_\u200C\u200D\p{ID_Continue}]/u,rIe=".*";function gur(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(gur,"Re");function mpt(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&&mur.test(M)||A!==_+1&&hur.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(!gur(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(mpt,"v");function hpt(a,s={}){let l=mpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,A="",M=new Set,z=t(fn=>{if(D<l.length&&l[D].type===fn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(fn=>{let tn=z(fn);if(tn!==void 0)return tn;let{type:cn,index:Er}=l[D];throw new TypeError(`Unexpected ${cn} at ${Er}, expected ${fn}`)},"d"),Q=t(()=>{let fn="",tn;for(;tn=z("CHAR")??z("ESCAPED_CHAR");)fn+=tn;return fn},"T"),Re=t(fn=>fn,"Se"),Ie=s.encodePart||Re,we="",wt=t(fn=>{we+=fn},"U"),xt=t(()=>{we.length&&(h.push(new JG(3,"","",Ie(we),"",3)),we="")},"$"),Tr=t((fn,tn,cn,Er,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!tn&&!cn&&fs===3){wt(fn);return}if(xt(),!tn&&!cn){if(!fn)return;h.push(new JG(3,"","",Ie(fn),"",fs));return}let Oi;cn?cn==="*"?Oi=rIe:Oi=cn:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===rIe&&(Ho=0,Oi="");let di;if(tn?di=tn:cn&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new JG(Ho,di,Ie(fn),Oi,Ie(Er),fs))},"V");for(;D<l.length;){let fn=z("CHAR"),tn=z("NAME"),cn=z("REGEX");if(!tn&&!cn&&(cn=z("ASTERISK")),tn||cn){let vr=fn??"";s.prefixes.indexOf(vr)===-1&&(wt(vr),vr=""),xt();let fs=re();Tr(vr,tn,cn,"",fs);continue}let Er=fn??z("ESCAPED_CHAR");if(Er){wt(Er);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();Tr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(hpt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function ppt(a){return a&&a.ignoreCase?"ui":"u"}t(ppt,"X");function yur(a,s,l){return gpt(hpt(a,l),s,l)}t(yur,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function gpt(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=rIe),!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(_,ppt(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(_,ppt(l))}t(gpt,"F");var H3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},vur={delimiter:".",prefixes:"",sensitive:!0,strict:!0},bur={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Sur(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Sur,"J");function ypt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(ypt,"Q");function Tur(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(Tur,"Ee");function vpt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(vpt,"W");var bpt=["ftp","file","http","https","ws","wss"];function Spt(a){if(!a)return!0;for(let s of bpt)if(a.test(s))return!0;return!1}t(Spt,"N");function xur(a,s){if(a=ypt(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(xur,"te");function Eur(a,s){if(a=ypt(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(Eur,"re");function Cur(a,s){return s||a===""?a:vpt(a)?Ept(a):xpt(a)}t(Cur,"ne");function Dur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(Dur,"se");function kur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(kur,"ie");function wur(a,s,l){if(l||a==="")return a;if(s&&!bpt.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(wur,"ae");function Pur(a,s,l){return Tpt(s)===a&&(a=""),l||a===""?a:Cpt(a)}t(Pur,"oe");function Aur(a,s){return a=Tur(a,":"),s||a===""?a:nIe(a)}t(Aur,"ce");function Tpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(Tpt,"_");function nIe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(nIe,"y");function Nur(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(Nur,"le");function Iur(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(Iur,"fe");function xpt(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(xpt,"z");function Ept(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(Ept,"j");function Cpt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(Cpt,"K");function Our(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(Our,"he");function Fur(a){return a===""?a:new URL(`data:${a}`).pathname}t(Fur,"ue");function Lur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(Lur,"de");function Rur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(Rur,"pe");var Mur=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=mpt(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=nIe;let s=yur(this.#T(),void 0,a);this.#l=Spt(s)}},tIe=["protocol","username","password","hostname","port","pathname","search","hash"],W3="*";function dpt(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(dpt,"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=Aur(s.protocol,l)),typeof s.username=="string"&&(a.username=kur(s.username,l)),typeof s.password=="string"&&(a.password=Dur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=Cur(s.hostname,l)),typeof s.port=="string"&&(a.port=Pur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Sur(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=FA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=wur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=Eur(s.search,l)),typeof s.hash=="string"&&(a.hash=xur(s.hash,l)),a}t($G,"w");function zG(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t(zG,"C");function jur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(jur,"Oe");function Bur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${jur(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(Bur,"ke");var Dpt=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 Mur(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),Tpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of tIe){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=nIe;break;case"username":Object.assign(A,H3),A.encodePart=Nur;break;case"password":Object.assign(A,H3),A.encodePart=Iur;break;case"hostname":Object.assign(A,vur),vpt(M)?A.encodePart=Ept:A.encodePart=xpt;break;case"port":Object.assign(A,H3),A.encodePart=Cpt;break;case"pathname":Spt(this.#n.protocol)?(Object.assign(A,bur,h),A.encodePart=Our):(Object.assign(A,H3,h),A.encodePart=Fur);break;case"search":Object.assign(A,H3,h),A.encodePart=Lur;break;case"hash":Object.assign(A,H3,h),A.encodePart=Rur;break}try{this.#s[D]=hpt(M,A),this.#n[D]=gpt(this.#s[D],this.#e[D],A),this.#t[D]=Bur(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,dpt(a,s),!1)}catch{return!1}let _;for(_ of tIe)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,dpt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of tIe){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=Dpt);import{AssertionError as Uur}from"node:assert";function LA(a,s){if(a===!1)throw new Uur({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 kpt(a){return a.type===ec.Array}t(kpt,"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 $ur,getNodeValue as zur,printParseErrorCode as Jur,visit as qur}from"jsonc-parser";var Vur={DEFAULT:{allowTrailingComma:!1}};function qG(a,s=[],l=Vur.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"),qur(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:Wur(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 Wur(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(Wur,"getNodeType");function iIe(a,s){return $ur(a,s)}t(iIe,"findNodeAtLocation");function VG(a){return zur(a)}t(VG,"getNodeValue");function wpt(a){return Jur(a)}t(wpt,"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 Hur=/^[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 _=Hur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Gur from"node:fs/promises";import{parse as Kur}from"@swc/core";var Ppt=t(async a=>{let s=new Set;try{let l=await Gur.readFile(a,"utf-8");(await Kur(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 Apt={$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 sIe={$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 Npt={$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 aIe={$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 oIe={$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 qht=x_(pht(),1),Vht=x_(Jht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new Vht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,qht.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(oIe,"route-configuration.schema.json");iN.addSchema(Npt,"policy-configuration.schema.json");iN.addSchema(sIe,"policies.schema.json");iN.addSchema(aIe,"open-api-route-configuration.schema.json");iN.addSchema(Apt,"fragments.schema.json");var lRr=iN.compile(oIe),Wht=iN.compile(aIe),TOe=iN.compile(sIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=TOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Wht(s),this.results}};import r0r from"node:path";var xOe=/\$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:""}}},t0r=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=t0r(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)}):kpt(s)?s.children.forEach(l=>{this.visitor(l)}):RA(s)&&this.visitor(s.value)}},Hht=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",n0r=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],i0r=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Ght=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],s0r="handler/{}/options/{}/rewritePattern",a0r="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,s0r)){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:Kht(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,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:Kht(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(!i0r.some(A=>sN(s,A))&&!Ght.some(A=>sN(s,A))){if(xOe.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 _=xOe.exec(l);if(Ght.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=r0r.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=Hht(n0r,this.errors,DK)};function Kht(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(pft,"format");var dft=t((a,...s)=>pft(gor,a,s),"format");var tNe=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=_ft(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=dft(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${h}ms`)}`;console.log(b),this.last=Date.now()}},rNe=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function yor(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(yor,"extract");var hue;function gue(a){hue||(hue=new rNe(yor(process.env.DEBUG)));let s=new tNe(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 mft="zp-local-service";var MOr=Symbol("zuplo_meters"),jOr=Symbol("zuplo_dynamic_meters");var fF=gue("zuplo:runtime:external-service");function vor(){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(vor,"getServiceAuth");async function hft(a,s){let l=vor();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 bor(h,re.ACCOUNT_NAME,re.PROJECT_NAME,re.ENVIRONMENT_TYPE),Q=yft(re.ENVIRONMENT_TYPE),Re=await nNe(`${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(hft,"externalServiceHandler");async function gft(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(mft,_),h.headers=A,await EG(D.toString(),h)}else throw new J3("Currently, we only support fetch(<some_string>, ...).")}t(gft,"clusterServiceHandler");async function bor(a,s,l,_){let h=a.toLowerCase(),b=s.toLowerCase(),D=l.toLowerCase(),A=yft(_);fF(`Hashing service name: ${b}-${h}.${b}-${D}-${A}`);let M=await nNe(`${b}-${h}`),z=await nNe(`${b}-${D}-${A}`);return`${M}.${z}`}t(bor,"hashServiceName");async function nNe(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(nNe,"hashSegment");function yft(a){let s=a.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(yft,"sanitizeEnvironmentType");var iNe=new Map;iNe.set("service:",hft);iNe.set("local:",gft);var EG=globalThis.fetch;function sNe(a,s){let l=Sor(s);if(typeof a=="string"){let _=new URL(a),h=iNe.get(_.protocol);return h?h(a,l):EG(a,l)}else return EG(a,l)}t(sNe,"internalFetch");globalThis.fetch=sNe;var Sor=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 Tor={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:sNe},CG=Tor;var aNe="2025-02-06",vft=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 bft(){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:aNe,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:vft[aNe]},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(bft,"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=bft()),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(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="deno":this.config.runtime_type?this.config.runtime_type==="deno":typeof WebSocketPair!="function"}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"}};var xor=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function Sft(a){return a.startsWith("__ZUPLO")||a.startsWith("ZUPLO_")?!xor.includes(a)&&!a.startsWith("ZUPLO_PUBLIC_"):a.startsWith("ZUDOKU_")?!a.startsWith("ZUDOKU_PUBLIC_"):!1}t(Sft,"isRestrictedEnvVariableName");function Tft(a){return!!a.startsWith("ZUPLO_")}t(Tft,"isZuploReadableEnvVariableName");var uFr=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(!(Sft(l)&&!Tft(l)))return F0.instance.runtime[l]}});function DG(a,s,l){return`_${PA(`${a}_${s}_${l}`)}`}t(DG,"getRawOperationDataIdentifierName");function oNe(a,s,l,_){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_${l.toLowerCase()}_${_.toLowerCase()}`}t(oNe,"getIdForParameterSchema");function cNe(a,s,l){return`_${PA(a.toLowerCase())}_${s.toLowerCase()}_rb_${PA(l.toLowerCase())}`}t(cNe,"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 egt=x_(_pt(),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"}},mur=/[$_\p{ID_Start}]/u,hur=/[$_\u200C\u200D\p{ID_Continue}]/u,rIe=".*";function gur(a,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(a)}t(gur,"Re");function mpt(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&&mur.test(M)||A!==_+1&&hur.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(!gur(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(mpt,"v");function hpt(a,s={}){let l=mpt(a);s.delimiter??="/#?",s.prefixes??="./";let _=`[^${MT(s.delimiter)}]+?`,h=[],b=0,D=0,A="",M=new Set,z=t(fn=>{if(D<l.length&&l[D].type===fn)return l[D++].value},"a"),re=t(()=>z("OTHER_MODIFIER")??z("ASTERISK"),"f"),ie=t(fn=>{let tn=z(fn);if(tn!==void 0)return tn;let{type:cn,index:Er}=l[D];throw new TypeError(`Unexpected ${cn} at ${Er}, expected ${fn}`)},"d"),Q=t(()=>{let fn="",tn;for(;tn=z("CHAR")??z("ESCAPED_CHAR");)fn+=tn;return fn},"T"),Re=t(fn=>fn,"Se"),Ie=s.encodePart||Re,we="",wt=t(fn=>{we+=fn},"U"),xt=t(()=>{we.length&&(h.push(new JG(3,"","",Ie(we),"",3)),we="")},"$"),Tr=t((fn,tn,cn,Er,vr)=>{let fs=3;switch(vr){case"?":fs=1;break;case"*":fs=0;break;case"+":fs=2;break}if(!tn&&!cn&&fs===3){wt(fn);return}if(xt(),!tn&&!cn){if(!fn)return;h.push(new JG(3,"","",Ie(fn),"",fs));return}let Oi;cn?cn==="*"?Oi=rIe:Oi=cn:Oi=_;let Ho=2;Oi===_?(Ho=1,Oi=""):Oi===rIe&&(Ho=0,Oi="");let di;if(tn?di=tn:cn&&(di=b++),M.has(di))throw new TypeError(`Duplicate name '${di}'.`);M.add(di),h.push(new JG(Ho,di,Ie(fn),Oi,Ie(Er),fs))},"V");for(;D<l.length;){let fn=z("CHAR"),tn=z("NAME"),cn=z("REGEX");if(!tn&&!cn&&(cn=z("ASTERISK")),tn||cn){let vr=fn??"";s.prefixes.indexOf(vr)===-1&&(wt(vr),vr=""),xt();let fs=re();Tr(vr,tn,cn,"",fs);continue}let Er=fn??z("ESCAPED_CHAR");if(Er){wt(Er);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();Tr(vr,fs,Oi,Ho,di);continue}xt(),ie("END")}return h}t(hpt,"D");function MT(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(MT,"S");function ppt(a){return a&&a.ignoreCase?"ui":"u"}t(ppt,"X");function yur(a,s,l){return gpt(hpt(a,l),s,l)}t(yur,"Z");function gj(a){switch(a){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(gj,"k");function gpt(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=rIe),!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(_,ppt(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(_,ppt(l))}t(gpt,"F");var H3={delimiter:"",prefixes:"",sensitive:!0,strict:!0},vur={delimiter:".",prefixes:"",sensitive:!0,strict:!0},bur={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Sur(a,s){return a.length?a[0]==="/"?!0:!s||a.length<2?!1:(a[0]=="\\"||a[0]=="{")&&a[1]=="/":!1}t(Sur,"J");function ypt(a,s){return a.startsWith(s)?a.substring(s.length,a.length):a}t(ypt,"Q");function Tur(a,s){return a.endsWith(s)?a.substr(0,a.length-s.length):a}t(Tur,"Ee");function vpt(a){return!a||a.length<2?!1:a[0]==="["||(a[0]==="\\"||a[0]==="{")&&a[1]==="["}t(vpt,"W");var bpt=["ftp","file","http","https","ws","wss"];function Spt(a){if(!a)return!0;for(let s of bpt)if(a.test(s))return!0;return!1}t(Spt,"N");function xur(a,s){if(a=ypt(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(xur,"te");function Eur(a,s){if(a=ypt(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(Eur,"re");function Cur(a,s){return s||a===""?a:vpt(a)?Ept(a):xpt(a)}t(Cur,"ne");function Dur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.password=a,l.password}t(Dur,"se");function kur(a,s){if(s||a==="")return a;let l=new URL("https://example.com");return l.username=a,l.username}t(kur,"ie");function wur(a,s,l){if(l||a==="")return a;if(s&&!bpt.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(wur,"ae");function Pur(a,s,l){return Tpt(s)===a&&(a=""),l||a===""?a:Cpt(a)}t(Pur,"oe");function Aur(a,s){return a=Tur(a,":"),s||a===""?a:nIe(a)}t(Aur,"ce");function Tpt(a){switch(a){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(Tpt,"_");function nIe(a){if(a==="")return a;if(/^[-+.A-Za-z0-9]*$/.test(a))return a.toLowerCase();throw new TypeError(`Invalid protocol '${a}'.`)}t(nIe,"y");function Nur(a){if(a==="")return a;let s=new URL("https://example.com");return s.username=a,s.username}t(Nur,"le");function Iur(a){if(a==="")return a;let s=new URL("https://example.com");return s.password=a,s.password}t(Iur,"fe");function xpt(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(xpt,"z");function Ept(a){if(a==="")return a;if(/[^0-9a-fA-F[\]:]/g.test(a))throw new TypeError(`Invalid IPv6 hostname '${a}'`);return a.toLowerCase()}t(Ept,"j");function Cpt(a){if(a===""||/^[0-9]*$/.test(a)&&parseInt(a)<=65535)return a;throw new TypeError(`Invalid port '${a}'.`)}t(Cpt,"K");function Our(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(Our,"he");function Fur(a){return a===""?a:new URL(`data:${a}`).pathname}t(Fur,"ue");function Lur(a){if(a==="")return a;let s=new URL("https://example.com");return s.search=a,s.search.substring(1,s.search.length)}t(Lur,"de");function Rur(a){if(a==="")return a;let s=new URL("https://example.com");return s.hash=a,s.hash.substring(1,s.hash.length)}t(Rur,"pe");var Mur=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=mpt(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=nIe;let s=yur(this.#T(),void 0,a);this.#l=Spt(s)}},tIe=["protocol","username","password","hostname","port","pathname","search","hash"],W3="*";function dpt(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(dpt,"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=Aur(s.protocol,l)),typeof s.username=="string"&&(a.username=kur(s.username,l)),typeof s.password=="string"&&(a.password=Dur(s.password,l)),typeof s.hostname=="string"&&(a.hostname=Cur(s.hostname,l)),typeof s.port=="string"&&(a.port=Pur(s.port,a.protocol,l)),typeof s.pathname=="string"){if(a.pathname=s.pathname,_&&!Sur(a.pathname,l)){let h=_.pathname.lastIndexOf("/");h>=0&&(a.pathname=FA(_.pathname.substring(0,h+1),l)+a.pathname)}a.pathname=wur(a.pathname,a.protocol,l)}return typeof s.search=="string"&&(a.search=Eur(s.search,l)),typeof s.hash=="string"&&(a.hash=xur(s.hash,l)),a}t($G,"w");function zG(a){return a.replace(/([+*?:{}()\\])/g,"\\$1")}t(zG,"C");function jur(a){return a.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(jur,"Oe");function Bur(a,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let l=".*",_=`[^${jur(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(Bur,"ke");var Dpt=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 Mur(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),Tpt(this.#r.protocol)===this.#r.port&&(this.#r.port="");let D;for(D of tIe){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=nIe;break;case"username":Object.assign(A,H3),A.encodePart=Nur;break;case"password":Object.assign(A,H3),A.encodePart=Iur;break;case"hostname":Object.assign(A,vur),vpt(M)?A.encodePart=Ept:A.encodePart=xpt;break;case"port":Object.assign(A,H3),A.encodePart=Cpt;break;case"pathname":Spt(this.#n.protocol)?(Object.assign(A,bur,h),A.encodePart=Our):(Object.assign(A,H3,h),A.encodePart=Fur);break;case"search":Object.assign(A,H3,h),A.encodePart=Lur;break;case"hash":Object.assign(A,H3,h),A.encodePart=Rur;break}try{this.#s[D]=hpt(M,A),this.#n[D]=gpt(this.#s[D],this.#e[D],A),this.#t[D]=Bur(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,dpt(a,s),!1)}catch{return!1}let _;for(_ of tIe)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,dpt(a,s),!1)}catch{return null}let _={};s?_.inputs=[a,s]:_.inputs=[a];let h;for(h of tIe){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=Dpt);import{AssertionError as Uur}from"node:assert";function LA(a,s){if(a===!1)throw new Uur({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 kpt(a){return a.type===ec.Array}t(kpt,"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 $ur,getNodeValue as zur,printParseErrorCode as Jur,visit as qur}from"jsonc-parser";var Vur={DEFAULT:{allowTrailingComma:!1}};function qG(a,s=[],l=Vur.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"),qur(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:Wur(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 Wur(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(Wur,"getNodeType");function iIe(a,s){return $ur(a,s)}t(iIe,"findNodeAtLocation");function VG(a){return zur(a)}t(VG,"getNodeValue");function wpt(a){return Jur(a)}t(wpt,"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 Hur=/^[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 _=Hur.test(l.value)?l.value:`'${l.value}'`;s.push(_)}};import Gur from"node:fs/promises";import{parse as Kur}from"@swc/core";var Ppt=t(async a=>{let s=new Set;try{let l=await Gur.readFile(a,"utf-8");(await Kur(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 Apt={$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 sIe={$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 Npt={$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 aIe={$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 oIe={$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 qht=x_(pht(),1),Vht=x_(Jht(),1);var Lfe=class a{static{t(this,"JsonValidator")}static#r=new a;static get instance(){return a.#r}ajv;constructor(){this.ajv=new Vht.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,qht.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(oIe,"route-configuration.schema.json");iN.addSchema(Npt,"policy-configuration.schema.json");iN.addSchema(sIe,"policies.schema.json");iN.addSchema(aIe,"open-api-route-configuration.schema.json");iN.addSchema(Apt,"fragments.schema.json");var lRr=iN.compile(oIe),Wht=iN.compile(aIe),TOe=iN.compile(sIe);var Rfe=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=TOe(s),this.results}};var Mfe=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Wht(s),this.results}};import r0r from"node:path";var xOe=/\$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:""}}},t0r=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=t0r(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)}):kpt(s)?s.children.forEach(l=>{this.visitor(l)}):RA(s)&&this.visitor(s.value)}},Hht=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",n0r=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],i0r=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Ght=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],s0r="handler/{}/options/{}/rewritePattern",a0r="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,s0r)){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:Kht(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,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:Kht(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(!i0r.some(A=>sN(s,A))&&!Ght.some(A=>sN(s,A))){if(xOe.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 _=xOe.exec(l);if(Ght.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=r0r.posix.join("..",h));let b=this.getImportName(h),D={type:ec.Identifier,parent:s.parent,value:b};s.value=D}replaceEnvStatements=Hht(n0r,this.errors,DK)};function Kht(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.55.
|
|
3
|
+
"version": "6.55.6",
|
|
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.55.
|
|
45
|
-
"@zuplo/otel": "6.55.
|
|
46
|
-
"@zuplo/runtime": "6.55.
|
|
44
|
+
"@zuplo/graphql": "6.55.6",
|
|
45
|
+
"@zuplo/otel": "6.55.6",
|
|
46
|
+
"@zuplo/runtime": "6.55.6",
|
|
47
47
|
"deno": "2.3.1"
|
|
48
48
|
}
|
|
49
49
|
}
|