@zuplo/core 6.63.3 → 6.63.4
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
|
@@ -572,7 +572,7 @@ globstar while`,s,ae,f,Ke,$e),this.matchOne(s.slice(ae),f.slice(Ke),d))return th
|
|
|
572
572
|
`),exitCode:P},"Tar process logs")}}t(qtr,"tarFolder");async function Vtr({tarFilePath:o,outputDir:s,logger:f}){let d=[],y=[],x;try{await new Promise((P,F)=>{let J=yat("sh",["-c",`tar -xvf ${o} -C ${s};`]);J.stdout.on("data",G=>{let Se=G.toString().trim();Se.length>0&&d.push(Se.trim())}),J.stderr.on("data",G=>{let Se=G.toString().trim();Se.length>0&&y.push(Se.trim())}),J.on("close",G=>{x=G,G===0?P():F(new Error(`tar process exited with code ${G}`))}),J.on("error",G=>{F(G)})})}catch(P){throw new Error("Failed to untar file",{cause:P})}finally{f.info({stdout:d.join(`
|
|
573
573
|
`),stderr:y.join(`
|
|
574
574
|
`),exitCode:x},"Untar process logs")}}t(Vtr,"untarFile");async function Htr(o){if(await x6e(o))return await tI.rm(o,{recursive:!0})}t(Htr,"deleteFolder");var tu=E6e;var uT=Sd(T6e(),1);var EO=class extends Error{static{t(this,"CustomResolveError")}},rI=class{static{t(this,"RefParser")}sourceDirectory;logger;constructor(s,f){this.sourceDirectory=s,this.logger=f}dereference(s,f){return rH.$RefParser.dereference(s,{resolve:{json:!0,file:yce(this.sourceDirectory,this.logger),external:!0,http:!1},dereference:{circular:"ignore",onDereference:f?.onDereference}})}bundle(s){return rH.$RefParser.bundle(s,{resolve:{file:yce(this.sourceDirectory,this.logger),external:!0,http:!1}})}parse(s){return rH.$RefParser.parse(s,{resolve:{file:yce(this.sourceDirectory,this.logger),external:!0,http:!1}})}resolve(s){return rH.$RefParser.resolve(s,{resolve:{file:yce(this.sourceDirectory,this.logger),external:!0,http:!1}})}};function yce(o,s){return{order:100,canRead(f){let d=Xtr(f.url);if(!(d===void 0||d==="file"))return!1;let x;try{x=Tat(f.url)}catch(P){throw new EO(`Malformed URI: ${f.url}`,{cause:P})}try{tu.safePath(o).resolve(x)}catch(P){return s?.warn(P),!1}return!0},async read(f){let d;try{d=Tat(f.url)}catch(y){throw new EO(`Malformed URI: ${f.url}`,{cause:y})}try{return await Gtr(d)}catch(y){throw new EO(`Error opening file "${d}"`,{cause:y})}}}}t(yce,"customResolver");var _M=/^win/.test(globalThis.process?globalThis.process.platform:""),Ytr=/\//g,Ktr=/^(\w{2,}):\/\//i,C6e=[/%23/g,"#",/%24/g,"$",/%26/g,"&",/%2C/g,",",/%40/g,"@"];function Xtr(o){let s=Ktr.exec(o);if(s)return s[1].toLowerCase()}t(Xtr,"getProtocol");function Tat(o,s){o=decodeURI(o);for(let d=0;d<C6e.length;d+=2)o=o.replace(C6e[d],C6e[d+1]);let f=o.substr(0,7).toLowerCase()==="file://";if(f&&(o=o[7]==="/"?o.substr(8):o.substr(7),_M&&o[1]==="/"&&(o=`${o[0]}:${o.substr(1)}`),s?o=`file:///${o}`:(f=!1,o=_M?o:`/${o}`)),!f){let d=o.split(_M?"\\":"/"),y=[];for(let x of d)x===".."?y.length&&y[y.length-1]!==""&&y.pop():(x!==""||y.length===0)&&y.push(x);o=y.join(_M?"\\":"/"),!_M&&y[0]===""&&(o=`/${o.substring(1)}`)}return _M&&!f&&(o=o.replace(Ytr,"\\"),o.substr(1,2)===":\\"&&(o=o[0].toUpperCase()+o.substr(1))),o}t(Tat,"toFileSystemPath");var xat="YOUR_KEY_HERE";async function Eat(o){let f=await new rI(o.sourceDirectory,o.logger).bundle(o.openApiDocPath),d=o.openApiDocPath.replace(o.sourceDirectory,"");return Ztr({...o,relativeOpenApiPath:d},f)}t(Eat,"buildPublicOpenApiFile");async function Ztr(o,s){rrr({relativeOpenApiPath:o.relativeOpenApiPath},s);let f=s;return f=err(f),Qtr(f,o.urls?.api?.defaultUrl),f=trr(f,o),Cat(f,"x-zuplo"),f}t(Ztr,"buildRawOpenApiFile");function Qtr(o,s){s?o.servers=[{url:s}]:o.servers=[]}t(Qtr,"addServerHost");function err(o){if(!o.paths)return o;let{components:s}=o,f=s?{...s}:void 0,d=[];f&&f.parameters&&(d=Object.entries(f.parameters).reduce((x,[P,F])=>(M9 in F&&uoe(F[M9])&&(x.push(P),f.parameters&&delete f.parameters[P]),x),[]));let y=Object.entries(o.paths).reduce((x,[P,F])=>{if(!F)return x;let J={...F},G=["delete","get","head","patch","post","put","trace","options"];return G.forEach(Se=>{let de=F[Se];if(!de)return;if(uoe(de[M9])){delete J[Se];return}let{parameters:ae}=de;if(!ae)return;let Ke=ae.filter($e=>{if(M9 in $e&&uoe($e[M9]))return!1;if("$ref"in $e){let Fe=$e.$ref.split("/").pop();return Fe?!d.includes(Fe):!0}return!0});J[Se]={...de,parameters:Ke}}),G.some(Se=>!!J[Se])&&(x[P]=J),x},{});return{...o,paths:y,components:f}}t(err,"removeHiddenRoutesAndParams");function trr(o,{policiesConfig:s}){if(!o.paths)return o;let f=Object.entries(o.paths).reduce((d,[y,x])=>{if(!x)return d;let P={...x};return[P.delete,P.get,P.head,P.patch,P.post,P.put,P.trace,P.options].forEach(F=>{if(!F)return;let J=F["x-zuplo-route"]?.policies?.inbound?.reduce((de,ae)=>{let Ke=s.policies?.find(({name:Gt})=>Gt===ae);if(!Ke)return de;if(!(Ke.handler.export==="CompositeInboundPolicy"))return de.concat(ae);let Fe=Ke.handler.options?.policies;return Fe?de.concat(Fe):de},[]),G=[];if(J&&J.forEach(de=>{s.policies?.forEach(ae=>{ae.name===de&&(ae.handler.export==="ApiAuthKeyInboundPolicy"||ae.handler.export==="ApiKeyInboundPolicy")&&!ae.handler.options?.disableAutomaticallyAddingKeyHeaderToOpenApi&&G.push(ae)})}),G.length>0){let de=G.length>0&&G[0].handler&&G[0].handler.options&&G[0].handler.options.authHeader?G[0].handler.options.authHeader:"Authorization",ae=G.length>0&&G[0].handler&&G[0].handler.options&&(G[0].handler.options.authScheme||G[0].handler.options.authScheme==="")?G[0].handler.options.authScheme:"Bearer",Ke=ae!==""?`${ae} ${xat}`:xat,$e={name:de,in:"header",required:!0,example:Ke,schema:{type:"string"},description:`The \`${de}\` header is used to authenticate with the API using your API key. Value is of the format \`${Ke}\`.`};F.parameters?F.parameters.some(Pr=>"name"in Pr&&Pr.name===$e.name)||F.parameters.unshift($e):F.parameters=[$e];let Fe={type:"http",scheme:ae.toLowerCase()},Gt="api_key";o.components?.securitySchemes?Object.values(o.components?.securitySchemes).some(Pr=>"name"in Pr&&Pr.type==="apiKey"||"type"in Pr&&Pr.type==="http"&&Pr.scheme===ae)||(o.components.securitySchemes={...o.components.securitySchemes,[Gt]:Fe}):(o.components||(o.components={}),o.components.securitySchemes={[Gt]:Fe});let jt={[Gt]:[]};F.security?F.security.some(Pr=>Pr[Gt]!==void 0)||F.security.unshift(jt):F.security=[jt]}let Se=[];if(J&&J.forEach(de=>{s.policies?.forEach(ae=>{ae.name===de&&(ae.handler.export==="RateLimitInboundPolicy"||ae.handler.export==="ComplexRateLimitInboundPolicy")&&Se.push(ae)})}),Se.length>0){let de={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"}}}}}},ae={...de,headers:{"retry-after":{description:"The number of seconds to wait before making a new request.",schema:{type:"integer",example:60}}}};o.components?.responses||o.components||(o.components={}),o.components.responses={...o.components.responses,RateLimitNoRetryAfter:de,RateLimitWithRetryAfter:ae},F.responses||(F.responses={});let Ke=Se.some($e=>$e.handler.options?.headerMode!=="none");F.responses[429]||(F.responses[429]={$ref:Ke?"#/components/responses/RateLimitWithRetryAfter":"#/components/responses/RateLimitNoRetryAfter"})}}),d[y]=P,d},{});return{...o,paths:f}}t(trr,"enrichSpecWithZuploData");function Cat(o,s){for(let f in o)f.startsWith(s)?delete o[f]:typeof o[f]=="object"&&Cat(o[f],s)}t(Cat,"removePropertiesByPrefix");function rrr({relativeOpenApiPath:o},s){if(!s||typeof s!="object")throw new w1({message:"The OpenAPI Document could not be parsed.",severity:"error"});if(!("info"in s)||typeof s.info!="object"||!s.info)throw new w1({message:"The OpenAPI document does not have the required 'info' property.",location:{file:o,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 w1({message:"The OpenAPI document does not have the required 'info.title' property.",location:{file:o,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(rrr,"assertIsZuploOpenApiSpec");import Hle from"node:path";function nrr(o){if(o.length>=255)throw new TypeError("Alphabet too long");let s=new Uint8Array(256);for(let G=0;G<s.length;G++)s[G]=255;for(let G=0;G<o.length;G++){let Se=o.charAt(G),de=Se.charCodeAt(0);if(s[de]!==255)throw new TypeError(Se+" is ambiguous");s[de]=G}let f=o.length,d=o.charAt(0),y=Math.log(f)/Math.log(256),x=Math.log(256)/Math.log(f);function P(G){if(G instanceof Uint8Array||(ArrayBuffer.isView(G)?G=new Uint8Array(G.buffer,G.byteOffset,G.byteLength):Array.isArray(G)&&(G=Uint8Array.from(G))),!(G instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(G.length===0)return"";let Se=0,de=0,ae=0,Ke=G.length;for(;ae!==Ke&&G[ae]===0;)ae++,Se++;let $e=(Ke-ae)*x+1>>>0,Fe=new Uint8Array($e);for(;ae!==Ke;){let Pr=G[ae],Fn=0;for(let sn=$e-1;(Pr!==0||Fn<de)&&sn!==-1;sn--,Fn++)Pr+=256*Fe[sn]>>>0,Fe[sn]=Pr%f>>>0,Pr=Pr/f>>>0;if(Pr!==0)throw new Error("Non-zero carry");de=Fn,ae++}let Gt=$e-de;for(;Gt!==$e&&Fe[Gt]===0;)Gt++;let jt=d.repeat(Se);for(;Gt<$e;++Gt)jt+=o.charAt(Fe[Gt]);return jt}t(P,"encode");function F(G){if(typeof G!="string")throw new TypeError("Expected String");if(G.length===0)return new Uint8Array;let Se=0,de=0,ae=0;for(;G[Se]===d;)de++,Se++;let Ke=(G.length-Se)*y+1>>>0,$e=new Uint8Array(Ke);for(;G[Se];){let Pr=s[G.charCodeAt(Se)];if(Pr===255)return;let Fn=0;for(let sn=Ke-1;(Pr!==0||Fn<ae)&&sn!==-1;sn--,Fn++)Pr+=f*$e[sn]>>>0,$e[sn]=Pr%256>>>0,Pr=Pr/256>>>0;if(Pr!==0)throw new Error("Non-zero carry");ae=Fn,Se++}let Fe=Ke-ae;for(;Fe!==Ke&&$e[Fe]===0;)Fe++;let Gt=new Uint8Array(de+(Ke-Fe)),jt=de;for(;Fe!==Ke;)Gt[jt++]=$e[Fe++];return Gt}t(F,"decodeUnsafe");function J(G){let Se=F(G);if(Se)return Se;throw new Error("Non-base"+f+" character")}return t(J,"decode"),{encode:P,decodeUnsafe:F,decode:J}}t(nrr,"base");var kat=nrr;var irr="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",vce=kat(irr);var srr=!1;function pM(o,s){return{open:`\x1B[${o.join(";")}m`,close:`\x1B[${s}m`,regexp:new RegExp(`\\x1b\\[${s}m`,"g")}}t(pM,"code");function dM(o,s){return srr?`${s.open}${o.replace(s.regexp,s.open)}${s.close}`:o}t(dM,"run");function arr(o){return dM(o,pM([31],39))}t(arr,"red");function orr(o){return dM(o,pM([32],39))}t(orr,"green");function crr(o){return dM(o,pM([33],39))}t(crr,"yellow");function lrr(o){return dM(o,pM([34],39))}t(lrr,"blue");function urr(o){return dM(o,pM([35],39))}t(urr,"magenta");function frr(o){return dM(o,pM([36],39))}t(frr,"cyan");var Qwr=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 wat=[arr,orr,crr,lrr,urr,frr];function _rr(o){let s=0,f=o.length,d=0;if(f>0)for(;d<f;)s=(s<<5)-s+o.charCodeAt(d++)|0;return s}t(_rr,"hashCode");function Dat(o){let s=Math.abs(_rr(o));return wat[s%wat.length]}t(Dat,"generateColor");import{inspect as prr}from"node:util";function Pat(o,s,...f){let d=0,y=f.length,x=String(s).replace(/%[sdjoO%]/g,P=>{if(P==="%%")return"%";if(d>=y)return P;switch(P){case"%s":return String(f[d++]);case"%d":return Number(f[d++]).toString();case"%o":return o(f[d++]).split(`
|
|
575
|
-
`).map(F=>F.trim()).join(" ");case"%O":return o(f[d++]);case"%j":try{return JSON.stringify(f[d++])}catch{return"[Circular]"}default:return P}});for(let P of f.splice(d))P===null||!(typeof P=="object"&&P!==null)?x+=" "+P:x+=" "+o(P);return x}t(Pat,"format");var Aat=t((o,...s)=>Pat(prr,o,s),"format");var k6e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,f){this.manager=s,this.ns=f,this.color=Dat(f),this.last=0,this.enabled=s.enabled.some(d=>d.test(f))}log(...s){if(!this.enabled)return;let f,d=s[0];typeof d=="function"?f=d():f=String(d);let y=Date.now()-(this.last||Date.now());f=Aat(f,...s);let x=`${this.color(this.ns)} ${f} ${this.color(`+${y}ms`)}`;console.log(x),this.last=Date.now()}},w6e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function drr(o){return!o||o.length===0?[]:(o=o.replace(/\s/g,"").replace(/\*/g,".+"),o.split(",").map(s=>new RegExp(`^${s}$`)))}t(drr,"extract");var bce;function Sce(o){bce||(bce=new w6e(drr(process.env.DEBUG)));let s=new k6e(bce,o);return bce.debuggers.set(o,s),Object.assign(s.log.bind(s),{self:s})}t(Sce,"debug");var WP=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,f){typeof s=="string"?super(s,f):(super(s.message,f),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var Nat="zp-local-service";var mDr=Symbol("zuplo_meters"),hDr=Symbol("zuplo_dynamic_meters");var nI=Sce("zuplo:runtime:external-service");function mrr(){let o,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=Em.instance.runtime;if(s&&s!=="undefined")try{let f=atob(s);o=JSON.parse(f)}catch{}return o}t(mrr,"getServiceAuth");async function Iat(o,s){let f=".proxy",d=".tunnel";if(typeof o=="string"){let y=new URL(o),x=y.hostname;if(x.endsWith(f)){let Gt=x.slice(0,-f.length),jt=new URL(`http://${Gt}${y.pathname}${y.search}`);nI(`Routing to proxy: ${jt.toString()}`);let Pr=s??{};return nH(jt.toString(),Pr)}let P=x.endsWith(d),F=x.indexOf(".")===-1;if(!(P||F))throw new WP(`Invalid service hostname suffix: ${x}. Use .proxy for proxy routing, .tunnel for explicit tunnel routing, or no suffix for default tunnel routing.`);let G=P?x.slice(0,-d.length):x,Se=mrr();if(!Se)throw nI("There is no external service auth configured for this zup."),new WP("There are no external services configured for this zup.");nI(`Using external service auth. ClientId: ${Se.clientId})`);let de=s??{},ae=new Headers(de.headers||{});ae.set("CF-Access-Client-Id",Se.clientId),ae.set("CF-Access-Client-Secret",Se.clientSecret),de.headers=ae;let Ke;if(Se.customServiceMapping?.[G])Ke=`https://${Se.customServiceMapping[G]}`;else if(Em.instance.useLegacyServiceRouting)Ke=`https://${G}.zuptunnel.com`;else{nI("Using sha256 service routing");let Gt=Em.instance.build;if(Gt.ACCOUNT_NAME&&Gt.PROJECT_NAME&&Gt.ENVIRONMENT_TYPE){let jt=await hrr(G,Gt.ACCOUNT_NAME,Gt.PROJECT_NAME,Gt.ENVIRONMENT_TYPE),Pr=Fat(Gt.ENVIRONMENT_TYPE),Fn=await D6e(`${Gt.ACCOUNT_NAME}-${Gt.PROJECT_NAME}-${Pr}`);Fn==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Fn==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?Ke=`https://${jt}.zuptunnel.com`:Ke=`https://${jt}.t.zuplo.app`}else throw nI("Cannot use sha256 service routing, missing build variables"),new WP("Failed to generate fully qualified tunnel url.")}let $e=new URL(`${Ke}${y.pathname}${y.search}`);nI(`Calling external service: ${$e.toString()}`);let Fe=await nH($e.toString(),de);if(Fe.status===403&&Fe.headers.get("cf-access-domain")!==null)throw iH.console.error("403 Forbidden when calling external service.",{clientId:Se.clientId,tunnelHost:Ke}),new WP("Could not connect to secure tunnel.");return Fe}else throw nI("Cannot call external service with Request object"),new WP("Currently, we only support fetch(<some_string>, ...).")}t(Iat,"externalServiceHandler");async function Oat(o,s){if(typeof o=="string"){let f=new URL(o),d=f.hostname,y=s??{},x=`http://${d}.zuplo.svc.cluster.local:9000`,P=new URL(`${x}${f.pathname}${f.search}`),F=new Headers(y.headers||{});return F.set(Nat,d),y.headers=F,await nH(P.toString(),y)}else throw new WP("Currently, we only support fetch(<some_string>, ...).")}t(Oat,"clusterServiceHandler");async function hrr(o,s,f,d){let y=o.toLowerCase(),x=s.toLowerCase(),P=f.toLowerCase(),F=Fat(d);nI(`Hashing service name: ${x}-${y}.${x}-${P}-${F}`);let J=await D6e(`${x}-${y}`),G=await D6e(`${x}-${P}-${F}`);return`${J}.${G}`}t(hrr,"hashServiceName");async function D6e(o){let s=new TextEncoder().encode(o),f=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(f)).map(x=>x.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(D6e,"hashSegment");function Fat(o){let s=o.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(Fat,"sanitizeEnvironmentType");var P6e=new Map;P6e.set("service:",Iat);P6e.set("local:",Oat);var nH=globalThis.fetch;function A6e(o,s){let{transformedInit:f,clientCertificate:d}=grr(s);if(typeof o=="string"){let y=new URL(o),x=P6e.get(y.protocol);return x?x(o,f):Lat(o,f,d)}else return Lat(o,f,d)}t(A6e,"internalFetch");globalThis.fetch=A6e;function Lat(o,s,f){if(!f)return nH(o,s);if(Em.instance.isCloudflare){let y=Em.instance.runtime[f];if(!y)throw new Error(`Client certificate binding '${f}' not found. Ensure the certificate is uploaded and properly configured.`);if(typeof y!="object"||typeof y.fetch!="function")throw new Error(`Client certificate binding '${f}' is not a valid mTLS certificate binding. Make sure it's configured as an mTLS certificate, not an environment variable.`);return y.fetch(o,s)}else throw Em.instance.isDeno?new Error("mTLS client certificates are not yet supported in Deno runtime. This will be added in a future update."):new Error("mTLS client certificates are not supported in this runtime environment")}t(Lat,"performFetch");var grr=t(o=>{if(!o||o instanceof Request)return{transformedInit:o,clientCertificate:void 0};let s=o;if(!s.zuplo)return{transformedInit:o,clientCertificate:void 0};let f=s.zuplo.clientCertificate,d=o;return d.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete o.zuplo,{transformedInit:o,clientCertificate:f}},"transformInit");var yrr={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:A6e},iH=yrr;var N6e="2025-02-06",Rat=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 Mat(){return new Em({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:N6e,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:Rat[N6e]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:"",ZUPLO_SERVICE_BUCKET_ID:"mock-bucket-id"}})}t(Mat,"getMockEnvironment");var Em=class o{static{t(this,"Environment")}config;static#e;static#n=!1;static initialize(s){o.#e||(o.#e=new o(s),o.#n=!0)}static get instance(){return o.#n||(iH.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),o.#e=Mat()),o.#e}constructor({build:s,runtime:f}){let d;try{if(f.ZUPLO_SYSTEM_CONFIGURATIONS){let y=new TextDecoder().decode(vce.decode(f.ZUPLO_SYSTEM_CONFIGURATIONS)),x=JSON.parse(y);for(let P of Object.keys(x))f[P]||(f[P]=x[P])}if(f.__ZUPLO_CONFIG){let y=atob(f.__ZUPLO_CONFIG);d=JSON.parse(y)}}catch(y){iH.console.error("Failed to parse runtime configuration",y)}this.config=d??{},this.build=s,this.runtime=f,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=globalThis.Deno?.version?.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,f=this.config.rate_limit_service_timeout_ms,d=s??f;if(!d)return 500;let y=Number(d);return Number.isFinite(y)&&y>0?y:500}};var vrr=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function jat(o){return o.startsWith("__ZUPLO")||o.startsWith("ZUPLO_")?!vrr.includes(o)&&!o.startsWith("ZUPLO_PUBLIC_"):o.startsWith("ZUDOKU_")?!o.startsWith("ZUDOKU_PUBLIC_"):!1}t(jat,"isRestrictedEnvVariableName");function Bat(o){return!!o.startsWith("ZUPLO_")}t(Bat,"isZuploReadableEnvVariableName");var JDr=new Proxy({},{get(o,s){let f=String(s);switch(f){case"ZUPLO_ENVIRONMENT_TYPE":return Em.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return Em.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return Em.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return Em.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return Em.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return Em.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return Em.instance.build.COMPATIBILITY_DATE}if(!(jat(f)&&!Bat(f)))return Em.instance.runtime[f]}});function sH(o,s,f){return`_${qP(`${o}_${s}_${f}`)}`}t(sH,"getRawOperationDataIdentifierName");function I6e(o,s,f,d){return`_${qP(o.toLowerCase())}_${s.toLowerCase()}_${f.toLowerCase()}_${d.toLowerCase()}`}t(I6e,"getIdForParameterSchema");function O6e(o,s,f){return`_${qP(o.toLowerCase())}_${s.toLowerCase()}_rb_${qP(f.toLowerCase())}`}t(O6e,"getIdForRequestBodySchema");function aH(o,s){return`_${qP(o)}_${qP(s)}`}t(aH,"getIdForRefSchema");function qP(o){let s=o.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(qP,"sanitizedIdentifierName");var zft=Sd(act(),1);var vH=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(o,s,f,d,y,x){this.type=o,this.name=s,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},Vir=/[$_\p{ID_Start}]/u,Hir=/[$_\u200C\u200D\p{ID_Continue}]/u,pNe=".*";function Gir(o,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(o)}t(Gir,"Re");function lct(o,s=!1){let f=[],d=0;for(;d<o.length;){let y=o[d],x=t(function(P){if(!s)throw new TypeError(P);f.push({type:"INVALID_CHAR",index:d,value:o[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:o[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:o[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:o[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:o[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:o[d++]});continue}if(y===":"){let P="",F=d+1;for(;F<o.length;){let J=o.substr(F,1);if(F===d+1&&Vir.test(J)||F!==d+1&&Hir.test(J)){P+=o[F++];continue}break}if(!P){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:P}),d=F;continue}if(y==="("){let P=1,F="",J=d+1,G=!1;if(o[J]==="?"){x(`Pattern cannot start with "?" at ${J}`);continue}for(;J<o.length;){if(!Gir(o[J],!1)){x(`Invalid character '${o[J]}' at ${J}.`),G=!0;break}if(o[J]==="\\"){F+=o[J++]+o[J++];continue}if(o[J]===")"){if(P--,P===0){J++;break}}else if(o[J]==="("&&(P++,o[J+1]!=="?")){x(`Capturing groups are not allowed at ${J}`),G=!0;break}F+=o[J++]}if(G)continue;if(P){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=J;continue}f.push({type:"CHAR",index:d,value:o[d++]})}return f.push({type:"END",index:d,value:""}),f}t(lct,"v");function uct(o,s={}){let f=lct(o);s.delimiter??="/#?",s.prefixes??="./";let d=`[^${pT(s.delimiter)}]+?`,y=[],x=0,P=0,F="",J=new Set,G=t(Fn=>{if(P<f.length&&f[P].type===Fn)return f[P++].value},"a"),Se=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(Fn=>{let sn=G(Fn);if(sn!==void 0)return sn;let{type:Un,index:Er}=f[P];throw new TypeError(`Unexpected ${Un} at ${Er}, expected ${Fn}`)},"d"),ae=t(()=>{let Fn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)Fn+=sn;return Fn},"T"),Ke=t(Fn=>Fn,"Se"),$e=s.encodePart||Ke,Fe="",Gt=t(Fn=>{Fe+=Fn},"U"),jt=t(()=>{Fe.length&&(y.push(new vH(3,"","",$e(Fe),"",3)),Fe="")},"$"),Pr=t((Fn,sn,Un,Er,vr)=>{let ls=3;switch(vr){case"?":ls=1;break;case"*":ls=0;break;case"+":ls=2;break}if(!sn&&!Un&&ls===3){Gt(Fn);return}if(jt(),!sn&&!Un){if(!Fn)return;y.push(new vH(3,"","",$e(Fn),"",ls));return}let Ni;Un?Un==="*"?Ni=pNe:Ni=Un:Ni=d;let nc=2;Ni===d?(nc=1,Ni=""):Ni===pNe&&(nc=0,Ni="");let bi;if(sn?bi=sn:Un&&(bi=x++),J.has(bi))throw new TypeError(`Duplicate name '${bi}'.`);J.add(bi),y.push(new vH(nc,bi,$e(Fn),Ni,$e(Er),ls))},"V");for(;P<f.length;){let Fn=G("CHAR"),sn=G("NAME"),Un=G("REGEX");if(!sn&&!Un&&(Un=G("ASTERISK")),sn||Un){let vr=Fn??"";s.prefixes.indexOf(vr)===-1&&(Gt(vr),vr=""),jt();let ls=Se();Pr(vr,sn,Un,"",ls);continue}let Er=Fn??G("ESCAPED_CHAR");if(Er){Gt(Er);continue}if(G("OPEN")){let vr=ae(),ls=G("NAME"),Ni=G("REGEX");!ls&&!Ni&&(Ni=G("ASTERISK"));let nc=ae();de("CLOSE");let bi=Se();Pr(vr,ls,Ni,nc,bi);continue}jt(),de("END")}return y}t(uct,"D");function pT(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(pT,"S");function oct(o){return o&&o.ignoreCase?"ui":"u"}t(oct,"X");function Yir(o,s,f){return fct(uct(o,f),s,f)}t(Yir,"Z");function vM(o){switch(o){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(vM,"k");function fct(o,s,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of o){if(F.type===3){F.modifier===3?d+=pT(F.value):d+=`(?:${pT(F.value)})${vM(F.modifier)}`;continue}s&&s.push(F.name);let J=`[^${pT(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=J:F.type===0&&(G=pNe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${vM(F.modifier)}`:d+=`((?:${G})${vM(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${pT(F.prefix)}(${G})${pT(F.suffix)})`,d+=vM(F.modifier);continue}d+=`(?:${pT(F.prefix)}`,d+=`((?:${G})(?:`,d+=pT(F.suffix),d+=pT(F.prefix),d+=`(?:${G}))*)${pT(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${pT(f.endsWith)}]|$`,x=`[${pT(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,oct(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let P=!1;if(o.length){let F=o[o.length-1];F.type===3&&F.modifier===3&&(P=f.delimiter.indexOf(F)>-1)}return P||(d+=`(?=${x}|${y})`),new RegExp(d,oct(f))}t(fct,"F");var oI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},Kir={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Xir={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Zir(o,s){return o.length?o[0]==="/"?!0:!s||o.length<2?!1:(o[0]=="\\"||o[0]=="{")&&o[1]=="/":!1}t(Zir,"J");function _ct(o,s){return o.startsWith(s)?o.substring(s.length,o.length):o}t(_ct,"Q");function Qir(o,s){return o.endsWith(s)?o.substr(0,o.length-s.length):o}t(Qir,"Ee");function pct(o){return!o||o.length<2?!1:o[0]==="["||(o[0]==="\\"||o[0]==="{")&&o[1]==="["}t(pct,"W");var dct=["ftp","file","http","https","ws","wss"];function mct(o){if(!o)return!0;for(let s of dct)if(o.test(s))return!0;return!1}t(mct,"N");function esr(o,s){if(o=_ct(o,"#"),s||o==="")return o;let f=new URL("https://example.com");return f.hash=o,f.hash?f.hash.substring(1,f.hash.length):""}t(esr,"te");function tsr(o,s){if(o=_ct(o,"?"),s||o==="")return o;let f=new URL("https://example.com");return f.search=o,f.search?f.search.substring(1,f.search.length):""}t(tsr,"re");function rsr(o,s){return s||o===""?o:pct(o)?yct(o):gct(o)}t(rsr,"ne");function nsr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.password=o,f.password}t(nsr,"se");function isr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.username=o,f.username}t(isr,"ie");function ssr(o,s,f){if(f||o==="")return o;if(s&&!dct.includes(s))return new URL(`${s}:${o}`).pathname;let d=o[0]=="/";return o=new URL(d?o:"/-"+o,"https://example.com").pathname,d||(o=o.substring(2,o.length)),o}t(ssr,"ae");function asr(o,s,f){return hct(s)===o&&(o=""),f||o===""?o:vct(o)}t(asr,"oe");function osr(o,s){return o=Qir(o,":"),s||o===""?o:dNe(o)}t(osr,"ce");function hct(o){switch(o){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(hct,"_");function dNe(o){if(o==="")return o;if(/^[-+.A-Za-z0-9]*$/.test(o))return o.toLowerCase();throw new TypeError(`Invalid protocol '${o}'.`)}t(dNe,"y");function csr(o){if(o==="")return o;let s=new URL("https://example.com");return s.username=o,s.username}t(csr,"le");function lsr(o){if(o==="")return o;let s=new URL("https://example.com");return s.password=o,s.password}t(lsr,"fe");function gct(o){if(o==="")return o;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(o))throw new TypeError(`Invalid hostname '${o}'`);let s=new URL("https://example.com");return s.hostname=o,s.hostname}t(gct,"z");function yct(o){if(o==="")return o;if(/[^0-9a-fA-F[\]:]/g.test(o))throw new TypeError(`Invalid IPv6 hostname '${o}'`);return o.toLowerCase()}t(yct,"j");function vct(o){if(o===""||/^[0-9]*$/.test(o)&&parseInt(o)<=65535)return o;throw new TypeError(`Invalid port '${o}'.`)}t(vct,"K");function usr(o){if(o==="")return o;let s=new URL("https://example.com");return s.pathname=o[0]!=="/"?"/-"+o:o,o[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(usr,"he");function fsr(o){return o===""?o:new URL(`data:${o}`).pathname}t(fsr,"ue");function _sr(o){if(o==="")return o;let s=new URL("https://example.com");return s.search=o,s.search.substring(1,s.search.length)}t(_sr,"de");function psr(o){if(o==="")return o;let s=new URL("https://example.com");return s.hash=o,s.hash.substring(1,s.hash.length)}t(psr,"pe");var dsr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#p=0;#o=0;#_=0;#u=0;#c=!1;constructor(o){this.#e=o}get result(){return this.#t}parse(){for(this.#n=lct(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#o===0){this.#h(),this.#x()?this.#i(9,1):this.#v()?this.#i(8,1):this.#i(7,0);continue}else if(this.#o===2){this.#m(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#l())this.#_-=1;else continue;if(this.#A()){this.#_+=1;continue}switch(this.#o){case 0:this.#g()&&this.#m(1);break;case 1:if(this.#g()){this.#P();let o=7,s=1;this.#y()?(o=2,s=3):this.#c&&(o=2),this.#i(o,s)}break;case 2:this.#E()?this.#m(3):(this.#k()||this.#v()||this.#x())&&this.#m(5);break;case 3:this.#T()?this.#i(4,1):this.#E()&&this.#i(5,1);break;case 4:this.#E()&&this.#i(5,1);break;case 5:this.#O()?this.#u+=1:this.#w()&&(this.#u-=1),this.#C()&&!this.#u?this.#i(6,1):this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 6:this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 7:this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 8:this.#x()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#i(o,s){switch(this.#o){case 0:break;case 1:this.#t.protocol=this.#D();break;case 2:break;case 3:this.#t.username=this.#D();break;case 4:this.#t.password=this.#D();break;case 5:this.#t.hostname=this.#D();break;case 6:this.#t.port=this.#D();break;case 7:this.#t.pathname=this.#D();break;case 8:this.#t.search=this.#D();break;case 9:this.#t.hash=this.#D();break;case 10:break}this.#o!==0&&o!==10&&([1,2,3,4].includes(this.#o)&&[6,7,8,9].includes(o)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#o)&&[8,9].includes(o)&&(this.#t.pathname??=this.#c?"/":""),[1,2,3,4,5,6,7].includes(this.#o)&&o===9&&(this.#t.search??="")),this.#a(o,s)}#a(o,s){this.#o=o,this.#p=this.#r+s,this.#r+=s,this.#s=0}#h(){this.#r=this.#p,this.#s=0}#m(o){this.#h(),this.#o=o}#f(o){return o<0&&(o=this.#n.length-o),o<this.#n.length?this.#n[o]:this.#n[this.#n.length-1]}#d(o,s){let f=this.#f(o);return f.value===s&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#g(){return this.#d(this.#r,":")}#y(){return this.#d(this.#r+1,"/")&&this.#d(this.#r+2,"/")}#E(){return this.#d(this.#r,"@")}#T(){return this.#d(this.#r,":")}#C(){return this.#d(this.#r,":")}#k(){return this.#d(this.#r,"/")}#v(){if(this.#d(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let o=this.#f(this.#r-1);return o.type!=="NAME"&&o.type!=="REGEX"&&o.type!=="CLOSE"&&o.type!=="ASTERISK"}#x(){return this.#d(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#d(this.#r,"[")}#w(){return this.#d(this.#r,"]")}#D(){let o=this.#n[this.#r],s=this.#f(this.#p).index;return this.#e.substring(s,o.index)}#P(){let o={};Object.assign(o,oI),o.encodePart=dNe;let s=Yir(this.#D(),void 0,o);this.#c=mct(s)}},_Ne=["protocol","username","password","hostname","port","pathname","search","hash"],aI="*";function cct(o,s){if(typeof o!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(o,s);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(cct,"ge");function YP(o,s){return s?yH(o):o}t(YP,"b");function gH(o,s,f){let d;if(typeof s.baseURL=="string")try{d=new URL(s.baseURL),s.protocol===void 0&&(o.protocol=YP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(o.username=YP(d.username,f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(o.password=YP(d.password,f)),s.protocol===void 0&&s.hostname===void 0&&(o.hostname=YP(d.hostname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(o.port=YP(d.port,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(o.pathname=YP(d.pathname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(o.search=YP(d.search.substring(1,d.search.length),f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(o.hash=YP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(o.protocol=osr(s.protocol,f)),typeof s.username=="string"&&(o.username=isr(s.username,f)),typeof s.password=="string"&&(o.password=nsr(s.password,f)),typeof s.hostname=="string"&&(o.hostname=rsr(s.hostname,f)),typeof s.port=="string"&&(o.port=asr(s.port,o.protocol,f)),typeof s.pathname=="string"){if(o.pathname=s.pathname,d&&!Zir(o.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(o.pathname=YP(d.pathname.substring(0,y+1),f)+o.pathname)}o.pathname=ssr(o.pathname,o.protocol,f)}return typeof s.search=="string"&&(o.search=tsr(s.search,f)),typeof s.hash=="string"&&(o.hash=esr(s.hash,f)),o}t(gH,"w");function yH(o){return o.replace(/([+*?:{}()\\])/g,"\\$1")}t(yH,"C");function msr(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(msr,"Oe");function hsr(o,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let f=".*",d=`[^${msr(s.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let P=0;P<o.length;++P){let F=o[P];if(F.type===3){if(F.modifier===3){x+=yH(F.value);continue}x+=`{${yH(F.value)}}${vM(F.modifier)}`;continue}let J=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!s.prefixes.includes(F.prefix)),Se=P>0?o[P-1]:null,de=P<o.length-1?o[P+1]:null;if(!G&&J&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let ae=de.value.length>0?de.value[0]:"";G=y.test(ae)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&Se&&Se.type===3){let ae=Se.value[Se.value.length-1];G=s.prefixes.includes(ae)}G&&(x+="{"),x+=yH(F.prefix),J&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?J||(x+=`(${d})`):F.type===0&&(!J&&(!Se||Se.type===3||Se.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&J&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=yH(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=vM(F.modifier))}return x}t(hsr,"ke");var bct=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#p=!1;constructor(o={},s,f){try{let d;if(typeof s=="string"?d=s:f=s,typeof o=="string"){let F=new dsr(o);if(F.parse(),o=F.result,d===void 0&&typeof o.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");o.baseURL=d}else{if(!o||typeof o!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:aI,protocol:aI,username:aI,password:aI,hostname:aI,port:aI,search:aI,hash:aI};this.#e=gH(x,o,!0),hct(this.#e.protocol)===this.#e.port&&(this.#e.port="");let P;for(P of _Ne){if(!(P in this.#e))continue;let F={},J=this.#e[P];switch(this.#t[P]=[],P){case"protocol":Object.assign(F,oI),F.encodePart=dNe;break;case"username":Object.assign(F,oI),F.encodePart=csr;break;case"password":Object.assign(F,oI),F.encodePart=lsr;break;case"hostname":Object.assign(F,Kir),pct(J)?F.encodePart=yct:F.encodePart=gct;break;case"port":Object.assign(F,oI),F.encodePart=vct;break;case"pathname":mct(this.#n.protocol)?(Object.assign(F,Xir,y),F.encodePart=usr):(Object.assign(F,oI,y),F.encodePart=fsr);break;case"search":Object.assign(F,oI,y),F.encodePart=_sr;break;case"hash":Object.assign(F,oI,y),F.encodePart=psr;break}try{this.#s[P]=uct(J,F),this.#n[P]=fct(this.#s[P],this.#t[P],F),this.#r[P]=hsr(this.#s[P],F),this.#p=this.#p||this.#s[P].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${P} pattern '${this.#e[P]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return!1;try{typeof o=="object"?f=gH(f,o,!1):f=gH(f,cct(o,s),!1)}catch{return!1}let d;for(d of _Ne)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return;try{typeof o=="object"?f=gH(f,o,!1):f=gH(f,cct(o,s),!1)}catch{return null}let d={};s?d.inputs=[o,s]:d.inputs=[o];let y;for(y of _Ne){let x=this.#n[y].exec(f[y]);if(!x)return null;let P={};for(let[F,J]of this.#t[y].entries())if(typeof J=="string"||typeof J=="number"){let G=x[F+1];P[J]=G}d[y]={input:f[y]??"",groups:P}}return d}static compareComponent(o,s,f){let d=t((F,J)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<J[G])return-1;if(F[G]!==J[G])return 1}return 0},"o"),y=new vH(3,"","","","",3),x=new vH(0,"","","","",3),P=t((F,J)=>{let G=0;for(;G<Math.min(F.length,J.length);++G){let Se=d(F[G],J[G]);if(Se)return Se}return F.length===J.length?0:d(F[G]??y,J[G]??y)},"s");return!s.#r[o]&&!f.#r[o]?0:s.#r[o]&&!f.#r[o]?P(s.#s[o],[x]):!s.#r[o]&&f.#r[o]?P([x],f.#s[o]):P(s.#s[o],f.#s[o])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=bct);import{AssertionError as gsr}from"node:assert";function KP(o,s){if(o===!1)throw new gsr({message:s})}t(KP,"assert");var Ko;(function(o){o.Object="Object",o.Property="Property",o.Array="Array",o.Literal="Literal",o.TemplateString="TemplateString",o.Identifier="Identifier",o.FunctionCall="FunctionCall",o.Raw="Raw"})(Ko||(Ko={}));function bM(o){return o.type===Ko.Object}t(bM,"isAstObject");function XP(o){return o.type===Ko.Property}t(XP,"isAstProperty");function Sct(o){return o.type===Ko.Array}t(Sct,"isAstArray");function SM(o){return o.type===Ko.Literal}t(SM,"isAstLiteral");function cI(o){if(o===void 0)throw new Error("Node is undefined");if(!bM(o))throw new Error("Node is not object")}t(cI,"assertAstObject");import{findNodeAtLocation as ysr,getNodeValue as vsr,printParseErrorCode as bsr,visit as Ssr}from"jsonc-parser";var Tsr={DEFAULT:{allowTrailingComma:!1}};function bH(o,s=[],f=Tsr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(J){d.type==="property"&&(d.length=J-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(J){return d.children?.push(J),J}t(x,"onValue"),Ssr(o,{onObjectBegin:t((J,G,Se)=>{d=x({type:"object",offset:J,length:-1,line:G+1,column:Se+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((J,G,Se,de,ae)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:ae+1,parent:d,children:[]}),d.children?.push({type:"string",value:J,offset:G,length:Se,line:de,column:ae,parent:d})},"onObjectProperty"),onObjectEnd:t((J,G)=>{y(J+G),d.length=J+G-d.offset,d=d.parent,y(J+G)},"onObjectEnd"),onArrayBegin:t((J,G,Se,de)=>{d=x({type:"array",offset:J,length:-1,line:Se+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((J,G)=>{d.length=J+G-d.offset,d=d.parent,y(J+G)},"onArrayEnd"),onLiteralValue:t((J,G,Se,de,ae)=>{x({type:xsr(J),offset:G,length:Se,line:de+1,column:ae+1,parent:d,value:J}),y(G+Se)},"onLiteralValue"),onSeparator:t((J,G)=>{d.type==="property"&&(J===":"?d.colonOffset=G:J===","&&y(G))},"onSeparator"),onError:t((J,G,Se,de,ae)=>{s.push({error:J,offset:G,length:Se,line:de+1,column:ae+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(bH,"parse");function xsr(o){switch(typeof o){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(o){if(Array.isArray(o))return"array"}else return"null";return"object"}default:return"null"}}t(xsr,"getNodeType");function mNe(o,s){return ysr(o,s)}t(mNe,"findNodeAtLocation");function SH(o){return vsr(o)}t(SH,"getNodeValue");function Tct(o){return bsr(o)}t(Tct,"printParseErrorCode");var TH=class{static{t(this,"AstAdapter")}parse(s){let d=bH(s,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,f){switch(s.type){case"object":return this.createObject(s,f);case"array":return this.createArray(s,f);case"property":return this.createProperty(s,f);case"string":return this.createLiteral(s,f);case"number":return this.createLiteral(s,f);case"boolean":return this.createLiteral(s,f);case"null":return this.createLiteral(s,f)}}createLiteral(s,f){return{type:Ko.Literal,location:{line:s.line,column:s.column},parent:f,value:s.type==="null"?null:s.value}}createObject(s,f){let d={type:Ko.Object,children:[],parent:f,location:{line:s.line,column:s.column}};return s.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(s,f){KP(s.children?.length===2,"Invalid property node");let d={type:Ko.Property,location:{line:s.line,column:s.column},parent:f,name:null,value:null};return d.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:Ko.Identifier,parent:d},d.value=this.parseNode(s.children[1],d),d}createArray(s,f){let d={type:Ko.Array,location:{line:s.line,column:s.column},parent:f,children:[]};return s.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var dT={createLiteral:t((o,s)=>({type:Ko.Literal,parent:s,value:o}),"createLiteral"),createTemplateString:t((o,s)=>({type:Ko.TemplateString,parent:s,value:o}),"createTemplateString"),createIdentifier:t((o,s)=>({type:Ko.Identifier,value:o,parent:s}),"createIdentifier"),createProperty:t((o,s,f)=>{let d={type:Ko.Property,parent:f,name:null,value:s};return d.name={value:o,type:Ko.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((o,s)=>{let f={type:Ko.Array,parent:s,children:[]};for(let d of o)f.children.push(dT.createLiteral(d,f));return f},"createArrayOfLiterals")};var Esr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,xH=class{static{t(this,"SourceGenerator")}generate(s){let f=[];return this.generateSource(f,s),f.join("")}generateSource(s,f){switch(f.type){case Ko.Array:return this.generateArray(s,f);case Ko.Object:return this.generateObject(s,f);case Ko.Property:return this.generateProperty(s,f);case Ko.Literal:return this.generateLiteral(s,f);case Ko.FunctionCall:return this.generateFunctionCall(s,f);case Ko.Identifier:return this.generateIdentifier(s,f);case Ko.Raw:return this.generateRaw(s,f);case Ko.TemplateString:return this.generateTemplateString(s,f)}}generateArray(s,f){s.push("["),f.children.map(d=>{this.generateSource(s,d),s.push(",")}),s.push("]")}generateObject(s,f){s.push("{"),f.children.forEach(d=>{this.generateSource(s,d),s.push(",")}),s.push("}")}generateProperty(s,f){this.generateIdentifier(s,f.name),s.push(":"),this.generateSource(s,f.value)}generateFunctionCall(s,f){s.push(f.name.value),s.push("("),f.children.forEach((d,y,x)=>{this.generateSource(s,d),y<x.length&&s.push(",")}),s.push(")")}generateRaw(s,f){s.push(f.value)}generateTemplateString(s,f){s.push("`"),s.push(f.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,f){if(f.value===null)return s.push("null");switch(typeof f.value){case"number":case"boolean":return s.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return s.push(`${y}`)}}}generateIdentifier(s,f){let d=Esr.test(f.value)?f.value:`'${f.value}'`;s.push(d)}};import Csr from"node:fs/promises";import{parse as ksr}from"@swc/core";var xct=t(async o=>{let s=new Set;try{let f=await Csr.readFile(o,"utf-8");(await ksr(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?s.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?s.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&s.add(y.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Ect={$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 hNe={$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 Cct={$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 gNe={$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 yNe={$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 Nft=Sd(tft(),1),Ift=Sd(Mle(),1);var jle=class o{static{t(this,"JsonValidator")}static#e=new o;static get instance(){return o.#e}ajv;constructor(){this.ajv=new Ift.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Nft.default)(this.ajv,{mode:"fast"})}addSchema(s,f){this.ajv.addSchema(s,f)}compile(s){let f=this.ajv.compile(s);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(s,f){let d=[];return s?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},P=y.instancePath.split("/");if(P.length>2){let J=P[1],G=P[2]?parseInt(P[2],10):0,Se=P[3],de=Number.isNaN(G)?void 0:f[J][G][Se];x={details:{property:J,index:G,field:Se,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let J=y.instancePath.split("/"),G=J[J.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var yI=jle.instance;yI.addSchema(yNe,"route-configuration.schema.json");yI.addSchema(Cct,"policy-configuration.schema.json");yI.addSchema(hNe,"policies.schema.json");yI.addSchema(gNe,"open-api-route-configuration.schema.json");yI.addSchema(Ect,"fragments.schema.json");var SIr=yI.compile(yNe),Oft=yI.compile(gNe),O4e=yI.compile(hNe);var Ble=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=O4e(s),this.results}};var Ule=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Oft(s),this.results}};import R_r from"node:path";var F4e=/\$import\((.*)\)/,zle=/\$env\((.*?)\)/g;var rA=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,f,d,y){super(s),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},L_r=t(o=>{let s=[],f=o;for(;f.parent;)s.push(f),f=f.parent;return s.reverse()},"invertTree"),vI=t((o,s)=>{if(!o)return!1;let f=L_r(o);return s.split("/").every((x,P)=>{let F=f[P];return F?x==="*"||XP(F)&&F.name.value===x?!0:x==="{}"?F.type===Ko.Object:x==="[]"?F.type===Ko.Array:!1:!1})},"testPosition");var $le=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),bM(s)?s.children.forEach(f=>{this.visitor(f)}):Sct(s)?s.children.forEach(f=>{this.visitor(f)}):XP(s)&&this.visitor(s.value)}},Fft=t((o,s,f)=>d=>{if(!XP(d)||!SM(d.value)||typeof d.value.value!="string")return;if(!o.some(x=>vI(d,x))){zle.test(d.value.value)&&s.push(new rA("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=new RegExp(zle).exec(d.value.value);if(y?.length===2&&y[0]===d.value.value){let x={type:Ko.Raw,parent:null,value:`environment["${y[1]}"]`};d.value=x}else{let x=d.value.value.replaceAll(new RegExp(zle),(P,F)=>`\${environment["${F}"] ? environment["${F}"] : ""}`);x!==d.value.value&&(d.value=dT.createTemplateString(x,d))}},"getEnvStatementTransformer");var eG="config/routes.json",M_r=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],j_r=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Lft=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],B_r="handler/{}/options/{}/rewritePattern",U_r="handler/{}/options/{}/baseUrl",Jle=class extends $le{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let f=this.addedImports.get(s);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let s=[];return this.addedImports.forEach((f,d)=>{s.push({name:f,path:d})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!XP(s)||!SM(s.value)||typeof s.value.value!="string")&&vI(s,B_r)){if(!s.parent||!bM(s.parent)){this.errors.push(new rA("Invalid node, expected object",eG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Rft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}rewriteForwardFunction(s){if(!(!XP(s)||!SM(s.value)||typeof s.value.value!="string")&&vI(s,U_r)){if(!s.parent||!bM(s.parent)){this.errors.push(new rA("Invalid node, expected object",eG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Rft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}replaceImportStatements(s){if(!XP(s)||!SM(s.value))return;let f=s.value.value;if(typeof f!="string")return;if(!j_r.some(F=>vI(s,F))&&!Lft.some(F=>vI(s,F))){if(F4e.test(f)){if(s.name.value==="$ref")return;this.errors.push(new rA("An $import() statement is not expected at this location.",eG,s.location,f))}return}let d=F4e.exec(f);if(Lft.some(F=>vI(s,F))&&!d)return;if(!d){this.errors.push(new rA("Invalid $import() statement",eG,s.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=R_r.posix.join("..",y));let x=this.getImportName(y),P={type:Ko.Identifier,parent:s.parent,value:x};s.value=P}replaceEnvStatements=Fft(M_r,this.errors,eG)};function Rft(o){return`(request, context) => {
|
|
575
|
+
`).map(F=>F.trim()).join(" ");case"%O":return o(f[d++]);case"%j":try{return JSON.stringify(f[d++])}catch{return"[Circular]"}default:return P}});for(let P of f.splice(d))P===null||!(typeof P=="object"&&P!==null)?x+=" "+P:x+=" "+o(P);return x}t(Pat,"format");var Aat=t((o,...s)=>Pat(prr,o,s),"format");var k6e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,f){this.manager=s,this.ns=f,this.color=Dat(f),this.last=0,this.enabled=s.enabled.some(d=>d.test(f))}log(...s){if(!this.enabled)return;let f,d=s[0];typeof d=="function"?f=d():f=String(d);let y=Date.now()-(this.last||Date.now());f=Aat(f,...s);let x=`${this.color(this.ns)} ${f} ${this.color(`+${y}ms`)}`;console.log(x),this.last=Date.now()}},w6e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function drr(o){return!o||o.length===0?[]:(o=o.replace(/\s/g,"").replace(/\*/g,".+"),o.split(",").map(s=>new RegExp(`^${s}$`)))}t(drr,"extract");var bce;function Sce(o){bce||(bce=new w6e(drr(process.env.DEBUG)));let s=new k6e(bce,o);return bce.debuggers.set(o,s),Object.assign(s.log.bind(s),{self:s})}t(Sce,"debug");var WP=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,f){typeof s=="string"?super(s,f):(super(s.message,f),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var Nat="zp-local-service";var mDr=Symbol("zuplo_meters"),hDr=Symbol("zuplo_dynamic_meters");var nI=Sce("zuplo:runtime:external-service");function mrr(){let o,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=Em.instance.runtime;if(s&&s!=="undefined")try{let f=atob(s);o=JSON.parse(f)}catch{}return o}t(mrr,"getServiceAuth");async function Iat(o,s){let f=".proxy",d=".tunnel";if(typeof o=="string"){let y=new URL(o),x=y.hostname;if(x.endsWith(f)){let Gt=x.slice(0,-f.length),jt=new URL(`http://${Gt}${y.pathname}${y.search}`);nI(`Routing to proxy: ${jt.toString()}`);let Pr=s??{};return nH(jt.toString(),Pr)}let P=x.endsWith(d),F=x.indexOf(".")===-1;if(!(P||F))throw new WP(`Invalid service hostname suffix: ${x}. Use .proxy for proxy routing, .tunnel for explicit tunnel routing, or no suffix for default tunnel routing.`);let G=P?x.slice(0,-d.length):x,Se=mrr();if(!Se)throw nI("There is no external service auth configured for this zup."),new WP("There are no external services configured for this zup.");nI(`Using external service auth. ClientId: ${Se.clientId})`);let de=s??{},ae=new Headers(de.headers||{});ae.set("CF-Access-Client-Id",Se.clientId),ae.set("CF-Access-Client-Secret",Se.clientSecret),de.headers=ae;let Ke;if(Se.customServiceMapping?.[G])Ke=`https://${Se.customServiceMapping[G]}`;else if(Em.instance.useLegacyServiceRouting)Ke=`https://${G}.zuptunnel.com`;else{nI("Using sha256 service routing");let Gt=Em.instance.build;if(Gt.ACCOUNT_NAME&&Gt.PROJECT_NAME&&Gt.ENVIRONMENT_TYPE){let jt=await hrr(G,Gt.ACCOUNT_NAME,Gt.PROJECT_NAME,Gt.ENVIRONMENT_TYPE),Pr=Fat(Gt.ENVIRONMENT_TYPE),Fn=await D6e(`${Gt.ACCOUNT_NAME}-${Gt.PROJECT_NAME}-${Pr}`);Fn==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Fn==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?Ke=`https://${jt}.zuptunnel.com`:Ke=`https://${jt}.t.zuplo.app`}else throw nI("Cannot use sha256 service routing, missing build variables"),new WP("Failed to generate fully qualified tunnel url.")}let $e=new URL(`${Ke}${y.pathname}${y.search}`);nI(`Calling external service: ${$e.toString()}`);let Fe=await nH($e.toString(),de);if(Fe.status===403&&Fe.headers.get("cf-access-domain")!==null)throw iH.console.error("403 Forbidden when calling external service.",{clientId:Se.clientId,tunnelHost:Ke}),new WP("Could not connect to secure tunnel.");return Fe}else throw nI("Cannot call external service with Request object"),new WP("Currently, we only support fetch(<some_string>, ...).")}t(Iat,"externalServiceHandler");async function Oat(o,s){if(typeof o=="string"){let f=new URL(o),d=f.hostname,y=s??{},x=`http://${d}.zuplo.svc.cluster.local:9000`,P=new URL(`${x}${f.pathname}${f.search}`),F=new Headers(y.headers||{});return F.set(Nat,d),y.headers=F,await nH(P.toString(),y)}else throw new WP("Currently, we only support fetch(<some_string>, ...).")}t(Oat,"clusterServiceHandler");async function hrr(o,s,f,d){let y=o.toLowerCase(),x=s.toLowerCase(),P=f.toLowerCase(),F=Fat(d);nI(`Hashing service name: ${x}-${y}.${x}-${P}-${F}`);let J=await D6e(`${x}-${y}`),G=await D6e(`${x}-${P}-${F}`);return`${J}.${G}`}t(hrr,"hashServiceName");async function D6e(o){let s=new TextEncoder().encode(o),f=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(f)).map(x=>x.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(D6e,"hashSegment");function Fat(o){let s=o.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t(Fat,"sanitizeEnvironmentType");var P6e=new Map;P6e.set("service:",Iat);P6e.set("local:",Oat);var nH=globalThis.fetch;function A6e(o,s){let{transformedInit:f,mtlsCertificate:d}=grr(s);if(typeof o=="string"){let y=new URL(o),x=P6e.get(y.protocol);return x?x(o,f):Lat(o,f,d)}else return Lat(o,f,d)}t(A6e,"internalFetch");globalThis.fetch=A6e;function Lat(o,s,f){if(!f)return nH(o,s);if(Em.instance.isCloudflare){let y=Em.instance.runtime[f];if(!y)throw new Error(`mTLS certificate binding '${f}' not found. Ensure the certificate is uploaded and properly configured.`);if(typeof y!="object"||typeof y.fetch!="function")throw new Error(`mTLS certificate binding '${f}' is not a valid mTLS certificate binding. Make sure it's configured as an mTLS certificate, not an environment variable.`);return y.fetch(o,s)}else throw Em.instance.isDeno?new Error("mTLS client certificates are not yet supported in Deno runtime. This will be added in a future update."):new Error("mTLS client certificates are not supported in this runtime environment")}t(Lat,"performFetch");var grr=t(o=>{if(!o||o instanceof Request)return{transformedInit:o,mtlsCertificate:void 0};let s=o;if(!s.zuplo)return{transformedInit:o,mtlsCertificate:void 0};let f=s.zuplo.mtlsCertificate,d=o;return d.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete o.zuplo,{transformedInit:o,mtlsCertificate:f}},"transformInit");var yrr={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:A6e},iH=yrr;var N6e="2025-02-06",Rat=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 Mat(){return new Em({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:N6e,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:Rat[N6e]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:"",ZUPLO_SERVICE_BUCKET_ID:"mock-bucket-id"}})}t(Mat,"getMockEnvironment");var Em=class o{static{t(this,"Environment")}config;static#e;static#n=!1;static initialize(s){o.#e||(o.#e=new o(s),o.#n=!0)}static get instance(){return o.#n||(iH.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),o.#e=Mat()),o.#e}constructor({build:s,runtime:f}){let d;try{if(f.ZUPLO_SYSTEM_CONFIGURATIONS){let y=new TextDecoder().decode(vce.decode(f.ZUPLO_SYSTEM_CONFIGURATIONS)),x=JSON.parse(y);for(let P of Object.keys(x))f[P]||(f[P]=x[P])}if(f.__ZUPLO_CONFIG){let y=atob(f.__ZUPLO_CONFIG);d=JSON.parse(y)}}catch(y){iH.console.error("Failed to parse runtime configuration",y)}this.config=d??{},this.build=s,this.runtime=f,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=globalThis.Deno?.version?.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,f=this.config.rate_limit_service_timeout_ms,d=s??f;if(!d)return 500;let y=Number(d);return Number.isFinite(y)&&y>0?y:500}};var vrr=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function jat(o){return o.startsWith("__ZUPLO")||o.startsWith("ZUPLO_")?!vrr.includes(o)&&!o.startsWith("ZUPLO_PUBLIC_"):o.startsWith("ZUDOKU_")?!o.startsWith("ZUDOKU_PUBLIC_"):!1}t(jat,"isRestrictedEnvVariableName");function Bat(o){return!!o.startsWith("ZUPLO_")}t(Bat,"isZuploReadableEnvVariableName");var JDr=new Proxy({},{get(o,s){let f=String(s);switch(f){case"ZUPLO_ENVIRONMENT_TYPE":return Em.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return Em.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return Em.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return Em.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return Em.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return Em.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return Em.instance.build.COMPATIBILITY_DATE}if(!(jat(f)&&!Bat(f)))return Em.instance.runtime[f]}});function sH(o,s,f){return`_${qP(`${o}_${s}_${f}`)}`}t(sH,"getRawOperationDataIdentifierName");function I6e(o,s,f,d){return`_${qP(o.toLowerCase())}_${s.toLowerCase()}_${f.toLowerCase()}_${d.toLowerCase()}`}t(I6e,"getIdForParameterSchema");function O6e(o,s,f){return`_${qP(o.toLowerCase())}_${s.toLowerCase()}_rb_${qP(f.toLowerCase())}`}t(O6e,"getIdForRequestBodySchema");function aH(o,s){return`_${qP(o)}_${qP(s)}`}t(aH,"getIdForRefSchema");function qP(o){let s=o.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(qP,"sanitizedIdentifierName");var zft=Sd(act(),1);var vH=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(o,s,f,d,y,x){this.type=o,this.name=s,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},Vir=/[$_\p{ID_Start}]/u,Hir=/[$_\u200C\u200D\p{ID_Continue}]/u,pNe=".*";function Gir(o,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(o)}t(Gir,"Re");function lct(o,s=!1){let f=[],d=0;for(;d<o.length;){let y=o[d],x=t(function(P){if(!s)throw new TypeError(P);f.push({type:"INVALID_CHAR",index:d,value:o[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:o[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:o[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:o[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:o[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:o[d++]});continue}if(y===":"){let P="",F=d+1;for(;F<o.length;){let J=o.substr(F,1);if(F===d+1&&Vir.test(J)||F!==d+1&&Hir.test(J)){P+=o[F++];continue}break}if(!P){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:P}),d=F;continue}if(y==="("){let P=1,F="",J=d+1,G=!1;if(o[J]==="?"){x(`Pattern cannot start with "?" at ${J}`);continue}for(;J<o.length;){if(!Gir(o[J],!1)){x(`Invalid character '${o[J]}' at ${J}.`),G=!0;break}if(o[J]==="\\"){F+=o[J++]+o[J++];continue}if(o[J]===")"){if(P--,P===0){J++;break}}else if(o[J]==="("&&(P++,o[J+1]!=="?")){x(`Capturing groups are not allowed at ${J}`),G=!0;break}F+=o[J++]}if(G)continue;if(P){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=J;continue}f.push({type:"CHAR",index:d,value:o[d++]})}return f.push({type:"END",index:d,value:""}),f}t(lct,"v");function uct(o,s={}){let f=lct(o);s.delimiter??="/#?",s.prefixes??="./";let d=`[^${pT(s.delimiter)}]+?`,y=[],x=0,P=0,F="",J=new Set,G=t(Fn=>{if(P<f.length&&f[P].type===Fn)return f[P++].value},"a"),Se=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(Fn=>{let sn=G(Fn);if(sn!==void 0)return sn;let{type:Un,index:Er}=f[P];throw new TypeError(`Unexpected ${Un} at ${Er}, expected ${Fn}`)},"d"),ae=t(()=>{let Fn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)Fn+=sn;return Fn},"T"),Ke=t(Fn=>Fn,"Se"),$e=s.encodePart||Ke,Fe="",Gt=t(Fn=>{Fe+=Fn},"U"),jt=t(()=>{Fe.length&&(y.push(new vH(3,"","",$e(Fe),"",3)),Fe="")},"$"),Pr=t((Fn,sn,Un,Er,vr)=>{let ls=3;switch(vr){case"?":ls=1;break;case"*":ls=0;break;case"+":ls=2;break}if(!sn&&!Un&&ls===3){Gt(Fn);return}if(jt(),!sn&&!Un){if(!Fn)return;y.push(new vH(3,"","",$e(Fn),"",ls));return}let Ni;Un?Un==="*"?Ni=pNe:Ni=Un:Ni=d;let nc=2;Ni===d?(nc=1,Ni=""):Ni===pNe&&(nc=0,Ni="");let bi;if(sn?bi=sn:Un&&(bi=x++),J.has(bi))throw new TypeError(`Duplicate name '${bi}'.`);J.add(bi),y.push(new vH(nc,bi,$e(Fn),Ni,$e(Er),ls))},"V");for(;P<f.length;){let Fn=G("CHAR"),sn=G("NAME"),Un=G("REGEX");if(!sn&&!Un&&(Un=G("ASTERISK")),sn||Un){let vr=Fn??"";s.prefixes.indexOf(vr)===-1&&(Gt(vr),vr=""),jt();let ls=Se();Pr(vr,sn,Un,"",ls);continue}let Er=Fn??G("ESCAPED_CHAR");if(Er){Gt(Er);continue}if(G("OPEN")){let vr=ae(),ls=G("NAME"),Ni=G("REGEX");!ls&&!Ni&&(Ni=G("ASTERISK"));let nc=ae();de("CLOSE");let bi=Se();Pr(vr,ls,Ni,nc,bi);continue}jt(),de("END")}return y}t(uct,"D");function pT(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(pT,"S");function oct(o){return o&&o.ignoreCase?"ui":"u"}t(oct,"X");function Yir(o,s,f){return fct(uct(o,f),s,f)}t(Yir,"Z");function vM(o){switch(o){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(vM,"k");function fct(o,s,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of o){if(F.type===3){F.modifier===3?d+=pT(F.value):d+=`(?:${pT(F.value)})${vM(F.modifier)}`;continue}s&&s.push(F.name);let J=`[^${pT(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=J:F.type===0&&(G=pNe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${vM(F.modifier)}`:d+=`((?:${G})${vM(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${pT(F.prefix)}(${G})${pT(F.suffix)})`,d+=vM(F.modifier);continue}d+=`(?:${pT(F.prefix)}`,d+=`((?:${G})(?:`,d+=pT(F.suffix),d+=pT(F.prefix),d+=`(?:${G}))*)${pT(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${pT(f.endsWith)}]|$`,x=`[${pT(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,oct(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let P=!1;if(o.length){let F=o[o.length-1];F.type===3&&F.modifier===3&&(P=f.delimiter.indexOf(F)>-1)}return P||(d+=`(?=${x}|${y})`),new RegExp(d,oct(f))}t(fct,"F");var oI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},Kir={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Xir={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Zir(o,s){return o.length?o[0]==="/"?!0:!s||o.length<2?!1:(o[0]=="\\"||o[0]=="{")&&o[1]=="/":!1}t(Zir,"J");function _ct(o,s){return o.startsWith(s)?o.substring(s.length,o.length):o}t(_ct,"Q");function Qir(o,s){return o.endsWith(s)?o.substr(0,o.length-s.length):o}t(Qir,"Ee");function pct(o){return!o||o.length<2?!1:o[0]==="["||(o[0]==="\\"||o[0]==="{")&&o[1]==="["}t(pct,"W");var dct=["ftp","file","http","https","ws","wss"];function mct(o){if(!o)return!0;for(let s of dct)if(o.test(s))return!0;return!1}t(mct,"N");function esr(o,s){if(o=_ct(o,"#"),s||o==="")return o;let f=new URL("https://example.com");return f.hash=o,f.hash?f.hash.substring(1,f.hash.length):""}t(esr,"te");function tsr(o,s){if(o=_ct(o,"?"),s||o==="")return o;let f=new URL("https://example.com");return f.search=o,f.search?f.search.substring(1,f.search.length):""}t(tsr,"re");function rsr(o,s){return s||o===""?o:pct(o)?yct(o):gct(o)}t(rsr,"ne");function nsr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.password=o,f.password}t(nsr,"se");function isr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.username=o,f.username}t(isr,"ie");function ssr(o,s,f){if(f||o==="")return o;if(s&&!dct.includes(s))return new URL(`${s}:${o}`).pathname;let d=o[0]=="/";return o=new URL(d?o:"/-"+o,"https://example.com").pathname,d||(o=o.substring(2,o.length)),o}t(ssr,"ae");function asr(o,s,f){return hct(s)===o&&(o=""),f||o===""?o:vct(o)}t(asr,"oe");function osr(o,s){return o=Qir(o,":"),s||o===""?o:dNe(o)}t(osr,"ce");function hct(o){switch(o){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(hct,"_");function dNe(o){if(o==="")return o;if(/^[-+.A-Za-z0-9]*$/.test(o))return o.toLowerCase();throw new TypeError(`Invalid protocol '${o}'.`)}t(dNe,"y");function csr(o){if(o==="")return o;let s=new URL("https://example.com");return s.username=o,s.username}t(csr,"le");function lsr(o){if(o==="")return o;let s=new URL("https://example.com");return s.password=o,s.password}t(lsr,"fe");function gct(o){if(o==="")return o;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(o))throw new TypeError(`Invalid hostname '${o}'`);let s=new URL("https://example.com");return s.hostname=o,s.hostname}t(gct,"z");function yct(o){if(o==="")return o;if(/[^0-9a-fA-F[\]:]/g.test(o))throw new TypeError(`Invalid IPv6 hostname '${o}'`);return o.toLowerCase()}t(yct,"j");function vct(o){if(o===""||/^[0-9]*$/.test(o)&&parseInt(o)<=65535)return o;throw new TypeError(`Invalid port '${o}'.`)}t(vct,"K");function usr(o){if(o==="")return o;let s=new URL("https://example.com");return s.pathname=o[0]!=="/"?"/-"+o:o,o[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(usr,"he");function fsr(o){return o===""?o:new URL(`data:${o}`).pathname}t(fsr,"ue");function _sr(o){if(o==="")return o;let s=new URL("https://example.com");return s.search=o,s.search.substring(1,s.search.length)}t(_sr,"de");function psr(o){if(o==="")return o;let s=new URL("https://example.com");return s.hash=o,s.hash.substring(1,s.hash.length)}t(psr,"pe");var dsr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#p=0;#o=0;#_=0;#u=0;#c=!1;constructor(o){this.#e=o}get result(){return this.#t}parse(){for(this.#n=lct(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#o===0){this.#h(),this.#x()?this.#i(9,1):this.#v()?this.#i(8,1):this.#i(7,0);continue}else if(this.#o===2){this.#m(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#l())this.#_-=1;else continue;if(this.#A()){this.#_+=1;continue}switch(this.#o){case 0:this.#g()&&this.#m(1);break;case 1:if(this.#g()){this.#P();let o=7,s=1;this.#y()?(o=2,s=3):this.#c&&(o=2),this.#i(o,s)}break;case 2:this.#E()?this.#m(3):(this.#k()||this.#v()||this.#x())&&this.#m(5);break;case 3:this.#T()?this.#i(4,1):this.#E()&&this.#i(5,1);break;case 4:this.#E()&&this.#i(5,1);break;case 5:this.#O()?this.#u+=1:this.#w()&&(this.#u-=1),this.#C()&&!this.#u?this.#i(6,1):this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 6:this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 7:this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 8:this.#x()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#i(o,s){switch(this.#o){case 0:break;case 1:this.#t.protocol=this.#D();break;case 2:break;case 3:this.#t.username=this.#D();break;case 4:this.#t.password=this.#D();break;case 5:this.#t.hostname=this.#D();break;case 6:this.#t.port=this.#D();break;case 7:this.#t.pathname=this.#D();break;case 8:this.#t.search=this.#D();break;case 9:this.#t.hash=this.#D();break;case 10:break}this.#o!==0&&o!==10&&([1,2,3,4].includes(this.#o)&&[6,7,8,9].includes(o)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#o)&&[8,9].includes(o)&&(this.#t.pathname??=this.#c?"/":""),[1,2,3,4,5,6,7].includes(this.#o)&&o===9&&(this.#t.search??="")),this.#a(o,s)}#a(o,s){this.#o=o,this.#p=this.#r+s,this.#r+=s,this.#s=0}#h(){this.#r=this.#p,this.#s=0}#m(o){this.#h(),this.#o=o}#f(o){return o<0&&(o=this.#n.length-o),o<this.#n.length?this.#n[o]:this.#n[this.#n.length-1]}#d(o,s){let f=this.#f(o);return f.value===s&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#g(){return this.#d(this.#r,":")}#y(){return this.#d(this.#r+1,"/")&&this.#d(this.#r+2,"/")}#E(){return this.#d(this.#r,"@")}#T(){return this.#d(this.#r,":")}#C(){return this.#d(this.#r,":")}#k(){return this.#d(this.#r,"/")}#v(){if(this.#d(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let o=this.#f(this.#r-1);return o.type!=="NAME"&&o.type!=="REGEX"&&o.type!=="CLOSE"&&o.type!=="ASTERISK"}#x(){return this.#d(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#d(this.#r,"[")}#w(){return this.#d(this.#r,"]")}#D(){let o=this.#n[this.#r],s=this.#f(this.#p).index;return this.#e.substring(s,o.index)}#P(){let o={};Object.assign(o,oI),o.encodePart=dNe;let s=Yir(this.#D(),void 0,o);this.#c=mct(s)}},_Ne=["protocol","username","password","hostname","port","pathname","search","hash"],aI="*";function cct(o,s){if(typeof o!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(o,s);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(cct,"ge");function YP(o,s){return s?yH(o):o}t(YP,"b");function gH(o,s,f){let d;if(typeof s.baseURL=="string")try{d=new URL(s.baseURL),s.protocol===void 0&&(o.protocol=YP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(o.username=YP(d.username,f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(o.password=YP(d.password,f)),s.protocol===void 0&&s.hostname===void 0&&(o.hostname=YP(d.hostname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(o.port=YP(d.port,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(o.pathname=YP(d.pathname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(o.search=YP(d.search.substring(1,d.search.length),f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(o.hash=YP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(o.protocol=osr(s.protocol,f)),typeof s.username=="string"&&(o.username=isr(s.username,f)),typeof s.password=="string"&&(o.password=nsr(s.password,f)),typeof s.hostname=="string"&&(o.hostname=rsr(s.hostname,f)),typeof s.port=="string"&&(o.port=asr(s.port,o.protocol,f)),typeof s.pathname=="string"){if(o.pathname=s.pathname,d&&!Zir(o.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(o.pathname=YP(d.pathname.substring(0,y+1),f)+o.pathname)}o.pathname=ssr(o.pathname,o.protocol,f)}return typeof s.search=="string"&&(o.search=tsr(s.search,f)),typeof s.hash=="string"&&(o.hash=esr(s.hash,f)),o}t(gH,"w");function yH(o){return o.replace(/([+*?:{}()\\])/g,"\\$1")}t(yH,"C");function msr(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(msr,"Oe");function hsr(o,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let f=".*",d=`[^${msr(s.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let P=0;P<o.length;++P){let F=o[P];if(F.type===3){if(F.modifier===3){x+=yH(F.value);continue}x+=`{${yH(F.value)}}${vM(F.modifier)}`;continue}let J=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!s.prefixes.includes(F.prefix)),Se=P>0?o[P-1]:null,de=P<o.length-1?o[P+1]:null;if(!G&&J&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let ae=de.value.length>0?de.value[0]:"";G=y.test(ae)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&Se&&Se.type===3){let ae=Se.value[Se.value.length-1];G=s.prefixes.includes(ae)}G&&(x+="{"),x+=yH(F.prefix),J&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?J||(x+=`(${d})`):F.type===0&&(!J&&(!Se||Se.type===3||Se.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&J&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=yH(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=vM(F.modifier))}return x}t(hsr,"ke");var bct=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#p=!1;constructor(o={},s,f){try{let d;if(typeof s=="string"?d=s:f=s,typeof o=="string"){let F=new dsr(o);if(F.parse(),o=F.result,d===void 0&&typeof o.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");o.baseURL=d}else{if(!o||typeof o!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:aI,protocol:aI,username:aI,password:aI,hostname:aI,port:aI,search:aI,hash:aI};this.#e=gH(x,o,!0),hct(this.#e.protocol)===this.#e.port&&(this.#e.port="");let P;for(P of _Ne){if(!(P in this.#e))continue;let F={},J=this.#e[P];switch(this.#t[P]=[],P){case"protocol":Object.assign(F,oI),F.encodePart=dNe;break;case"username":Object.assign(F,oI),F.encodePart=csr;break;case"password":Object.assign(F,oI),F.encodePart=lsr;break;case"hostname":Object.assign(F,Kir),pct(J)?F.encodePart=yct:F.encodePart=gct;break;case"port":Object.assign(F,oI),F.encodePart=vct;break;case"pathname":mct(this.#n.protocol)?(Object.assign(F,Xir,y),F.encodePart=usr):(Object.assign(F,oI,y),F.encodePart=fsr);break;case"search":Object.assign(F,oI,y),F.encodePart=_sr;break;case"hash":Object.assign(F,oI,y),F.encodePart=psr;break}try{this.#s[P]=uct(J,F),this.#n[P]=fct(this.#s[P],this.#t[P],F),this.#r[P]=hsr(this.#s[P],F),this.#p=this.#p||this.#s[P].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${P} pattern '${this.#e[P]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return!1;try{typeof o=="object"?f=gH(f,o,!1):f=gH(f,cct(o,s),!1)}catch{return!1}let d;for(d of _Ne)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return;try{typeof o=="object"?f=gH(f,o,!1):f=gH(f,cct(o,s),!1)}catch{return null}let d={};s?d.inputs=[o,s]:d.inputs=[o];let y;for(y of _Ne){let x=this.#n[y].exec(f[y]);if(!x)return null;let P={};for(let[F,J]of this.#t[y].entries())if(typeof J=="string"||typeof J=="number"){let G=x[F+1];P[J]=G}d[y]={input:f[y]??"",groups:P}}return d}static compareComponent(o,s,f){let d=t((F,J)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<J[G])return-1;if(F[G]!==J[G])return 1}return 0},"o"),y=new vH(3,"","","","",3),x=new vH(0,"","","","",3),P=t((F,J)=>{let G=0;for(;G<Math.min(F.length,J.length);++G){let Se=d(F[G],J[G]);if(Se)return Se}return F.length===J.length?0:d(F[G]??y,J[G]??y)},"s");return!s.#r[o]&&!f.#r[o]?0:s.#r[o]&&!f.#r[o]?P(s.#s[o],[x]):!s.#r[o]&&f.#r[o]?P([x],f.#s[o]):P(s.#s[o],f.#s[o])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=bct);import{AssertionError as gsr}from"node:assert";function KP(o,s){if(o===!1)throw new gsr({message:s})}t(KP,"assert");var Ko;(function(o){o.Object="Object",o.Property="Property",o.Array="Array",o.Literal="Literal",o.TemplateString="TemplateString",o.Identifier="Identifier",o.FunctionCall="FunctionCall",o.Raw="Raw"})(Ko||(Ko={}));function bM(o){return o.type===Ko.Object}t(bM,"isAstObject");function XP(o){return o.type===Ko.Property}t(XP,"isAstProperty");function Sct(o){return o.type===Ko.Array}t(Sct,"isAstArray");function SM(o){return o.type===Ko.Literal}t(SM,"isAstLiteral");function cI(o){if(o===void 0)throw new Error("Node is undefined");if(!bM(o))throw new Error("Node is not object")}t(cI,"assertAstObject");import{findNodeAtLocation as ysr,getNodeValue as vsr,printParseErrorCode as bsr,visit as Ssr}from"jsonc-parser";var Tsr={DEFAULT:{allowTrailingComma:!1}};function bH(o,s=[],f=Tsr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(J){d.type==="property"&&(d.length=J-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(J){return d.children?.push(J),J}t(x,"onValue"),Ssr(o,{onObjectBegin:t((J,G,Se)=>{d=x({type:"object",offset:J,length:-1,line:G+1,column:Se+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((J,G,Se,de,ae)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:ae+1,parent:d,children:[]}),d.children?.push({type:"string",value:J,offset:G,length:Se,line:de,column:ae,parent:d})},"onObjectProperty"),onObjectEnd:t((J,G)=>{y(J+G),d.length=J+G-d.offset,d=d.parent,y(J+G)},"onObjectEnd"),onArrayBegin:t((J,G,Se,de)=>{d=x({type:"array",offset:J,length:-1,line:Se+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((J,G)=>{d.length=J+G-d.offset,d=d.parent,y(J+G)},"onArrayEnd"),onLiteralValue:t((J,G,Se,de,ae)=>{x({type:xsr(J),offset:G,length:Se,line:de+1,column:ae+1,parent:d,value:J}),y(G+Se)},"onLiteralValue"),onSeparator:t((J,G)=>{d.type==="property"&&(J===":"?d.colonOffset=G:J===","&&y(G))},"onSeparator"),onError:t((J,G,Se,de,ae)=>{s.push({error:J,offset:G,length:Se,line:de+1,column:ae+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(bH,"parse");function xsr(o){switch(typeof o){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(o){if(Array.isArray(o))return"array"}else return"null";return"object"}default:return"null"}}t(xsr,"getNodeType");function mNe(o,s){return ysr(o,s)}t(mNe,"findNodeAtLocation");function SH(o){return vsr(o)}t(SH,"getNodeValue");function Tct(o){return bsr(o)}t(Tct,"printParseErrorCode");var TH=class{static{t(this,"AstAdapter")}parse(s){let d=bH(s,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,f){switch(s.type){case"object":return this.createObject(s,f);case"array":return this.createArray(s,f);case"property":return this.createProperty(s,f);case"string":return this.createLiteral(s,f);case"number":return this.createLiteral(s,f);case"boolean":return this.createLiteral(s,f);case"null":return this.createLiteral(s,f)}}createLiteral(s,f){return{type:Ko.Literal,location:{line:s.line,column:s.column},parent:f,value:s.type==="null"?null:s.value}}createObject(s,f){let d={type:Ko.Object,children:[],parent:f,location:{line:s.line,column:s.column}};return s.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(s,f){KP(s.children?.length===2,"Invalid property node");let d={type:Ko.Property,location:{line:s.line,column:s.column},parent:f,name:null,value:null};return d.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:Ko.Identifier,parent:d},d.value=this.parseNode(s.children[1],d),d}createArray(s,f){let d={type:Ko.Array,location:{line:s.line,column:s.column},parent:f,children:[]};return s.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var dT={createLiteral:t((o,s)=>({type:Ko.Literal,parent:s,value:o}),"createLiteral"),createTemplateString:t((o,s)=>({type:Ko.TemplateString,parent:s,value:o}),"createTemplateString"),createIdentifier:t((o,s)=>({type:Ko.Identifier,value:o,parent:s}),"createIdentifier"),createProperty:t((o,s,f)=>{let d={type:Ko.Property,parent:f,name:null,value:s};return d.name={value:o,type:Ko.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((o,s)=>{let f={type:Ko.Array,parent:s,children:[]};for(let d of o)f.children.push(dT.createLiteral(d,f));return f},"createArrayOfLiterals")};var Esr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,xH=class{static{t(this,"SourceGenerator")}generate(s){let f=[];return this.generateSource(f,s),f.join("")}generateSource(s,f){switch(f.type){case Ko.Array:return this.generateArray(s,f);case Ko.Object:return this.generateObject(s,f);case Ko.Property:return this.generateProperty(s,f);case Ko.Literal:return this.generateLiteral(s,f);case Ko.FunctionCall:return this.generateFunctionCall(s,f);case Ko.Identifier:return this.generateIdentifier(s,f);case Ko.Raw:return this.generateRaw(s,f);case Ko.TemplateString:return this.generateTemplateString(s,f)}}generateArray(s,f){s.push("["),f.children.map(d=>{this.generateSource(s,d),s.push(",")}),s.push("]")}generateObject(s,f){s.push("{"),f.children.forEach(d=>{this.generateSource(s,d),s.push(",")}),s.push("}")}generateProperty(s,f){this.generateIdentifier(s,f.name),s.push(":"),this.generateSource(s,f.value)}generateFunctionCall(s,f){s.push(f.name.value),s.push("("),f.children.forEach((d,y,x)=>{this.generateSource(s,d),y<x.length&&s.push(",")}),s.push(")")}generateRaw(s,f){s.push(f.value)}generateTemplateString(s,f){s.push("`"),s.push(f.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,f){if(f.value===null)return s.push("null");switch(typeof f.value){case"number":case"boolean":return s.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return s.push(`${y}`)}}}generateIdentifier(s,f){let d=Esr.test(f.value)?f.value:`'${f.value}'`;s.push(d)}};import Csr from"node:fs/promises";import{parse as ksr}from"@swc/core";var xct=t(async o=>{let s=new Set;try{let f=await Csr.readFile(o,"utf-8");(await ksr(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?s.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?s.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&s.add(y.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Ect={$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 hNe={$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 Cct={$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 gNe={$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 yNe={$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 Nft=Sd(tft(),1),Ift=Sd(Mle(),1);var jle=class o{static{t(this,"JsonValidator")}static#e=new o;static get instance(){return o.#e}ajv;constructor(){this.ajv=new Ift.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Nft.default)(this.ajv,{mode:"fast"})}addSchema(s,f){this.ajv.addSchema(s,f)}compile(s){let f=this.ajv.compile(s);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(s,f){let d=[];return s?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},P=y.instancePath.split("/");if(P.length>2){let J=P[1],G=P[2]?parseInt(P[2],10):0,Se=P[3],de=Number.isNaN(G)?void 0:f[J][G][Se];x={details:{property:J,index:G,field:Se,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let J=y.instancePath.split("/"),G=J[J.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var yI=jle.instance;yI.addSchema(yNe,"route-configuration.schema.json");yI.addSchema(Cct,"policy-configuration.schema.json");yI.addSchema(hNe,"policies.schema.json");yI.addSchema(gNe,"open-api-route-configuration.schema.json");yI.addSchema(Ect,"fragments.schema.json");var SIr=yI.compile(yNe),Oft=yI.compile(gNe),O4e=yI.compile(hNe);var Ble=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=O4e(s),this.results}};var Ule=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=Oft(s),this.results}};import R_r from"node:path";var F4e=/\$import\((.*)\)/,zle=/\$env\((.*?)\)/g;var rA=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,f,d,y){super(s),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},L_r=t(o=>{let s=[],f=o;for(;f.parent;)s.push(f),f=f.parent;return s.reverse()},"invertTree"),vI=t((o,s)=>{if(!o)return!1;let f=L_r(o);return s.split("/").every((x,P)=>{let F=f[P];return F?x==="*"||XP(F)&&F.name.value===x?!0:x==="{}"?F.type===Ko.Object:x==="[]"?F.type===Ko.Array:!1:!1})},"testPosition");var $le=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),bM(s)?s.children.forEach(f=>{this.visitor(f)}):Sct(s)?s.children.forEach(f=>{this.visitor(f)}):XP(s)&&this.visitor(s.value)}},Fft=t((o,s,f)=>d=>{if(!XP(d)||!SM(d.value)||typeof d.value.value!="string")return;if(!o.some(x=>vI(d,x))){zle.test(d.value.value)&&s.push(new rA("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=new RegExp(zle).exec(d.value.value);if(y?.length===2&&y[0]===d.value.value){let x={type:Ko.Raw,parent:null,value:`environment["${y[1]}"]`};d.value=x}else{let x=d.value.value.replaceAll(new RegExp(zle),(P,F)=>`\${environment["${F}"] ? environment["${F}"] : ""}`);x!==d.value.value&&(d.value=dT.createTemplateString(x,d))}},"getEnvStatementTransformer");var eG="config/routes.json",M_r=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],j_r=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Lft=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],B_r="handler/{}/options/{}/rewritePattern",U_r="handler/{}/options/{}/baseUrl",Jle=class extends $le{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let f=this.addedImports.get(s);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let s=[];return this.addedImports.forEach((f,d)=>{s.push({name:f,path:d})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!XP(s)||!SM(s.value)||typeof s.value.value!="string")&&vI(s,B_r)){if(!s.parent||!bM(s.parent)){this.errors.push(new rA("Invalid node, expected object",eG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Rft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}rewriteForwardFunction(s){if(!(!XP(s)||!SM(s.value)||typeof s.value.value!="string")&&vI(s,U_r)){if(!s.parent||!bM(s.parent)){this.errors.push(new rA("Invalid node, expected object",eG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Rft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}replaceImportStatements(s){if(!XP(s)||!SM(s.value))return;let f=s.value.value;if(typeof f!="string")return;if(!j_r.some(F=>vI(s,F))&&!Lft.some(F=>vI(s,F))){if(F4e.test(f)){if(s.name.value==="$ref")return;this.errors.push(new rA("An $import() statement is not expected at this location.",eG,s.location,f))}return}let d=F4e.exec(f);if(Lft.some(F=>vI(s,F))&&!d)return;if(!d){this.errors.push(new rA("Invalid $import() statement",eG,s.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=R_r.posix.join("..",y));let x=this.getImportName(y),P={type:Ko.Identifier,parent:s.parent,value:x};s.value=P}replaceEnvStatements=Fft(M_r,this.errors,eG)};function Rft(o){return`(request, context) => {
|
|
576
576
|
const { params, url, query, method, headers } = request;
|
|
577
577
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
578
578
|
const e = encodeURIComponent;
|
package/index.minified.js
CHANGED
|
@@ -572,7 +572,7 @@ globstar while`,s,ae,f,Ke,$e),this.matchOne(s.slice(ae),f.slice(Ke),d))return th
|
|
|
572
572
|
`),exitCode:P},"Tar process logs")}}t(mrr,"tarFolder");async function hrr({tarFilePath:o,outputDir:s,logger:f}){let d=[],y=[],x;try{await new Promise((P,F)=>{let J=kat("sh",["-c",`tar -xvf ${o} -C ${s};`]);J.stdout.on("data",G=>{let Se=G.toString().trim();Se.length>0&&d.push(Se.trim())}),J.stderr.on("data",G=>{let Se=G.toString().trim();Se.length>0&&y.push(Se.trim())}),J.on("close",G=>{x=G,G===0?P():F(new Error(`tar process exited with code ${G}`))}),J.on("error",G=>{F(G)})})}catch(P){throw new Error("Failed to untar file",{cause:P})}finally{f.info({stdout:d.join(`
|
|
573
573
|
`),stderr:y.join(`
|
|
574
574
|
`),exitCode:x},"Untar process logs")}}t(hrr,"untarFile");async function grr(o){if(await D6e(o))return await iI.rm(o,{recursive:!0})}t(grr,"deleteFolder");var tu=P6e;var uT=Dp(w6e(),1);var kO=class extends Error{static{t(this,"CustomResolveError")}},sI=class{static{t(this,"RefParser")}sourceDirectory;logger;constructor(s,f){this.sourceDirectory=s,this.logger=f}dereference(s,f){return nH.$RefParser.dereference(s,{resolve:{json:!0,file:yce(this.sourceDirectory,this.logger),external:!0,http:!1},dereference:{circular:"ignore",onDereference:f?.onDereference}})}bundle(s){return nH.$RefParser.bundle(s,{resolve:{file:yce(this.sourceDirectory,this.logger),external:!0,http:!1}})}parse(s){return nH.$RefParser.parse(s,{resolve:{file:yce(this.sourceDirectory,this.logger),external:!0,http:!1}})}resolve(s){return nH.$RefParser.resolve(s,{resolve:{file:yce(this.sourceDirectory,this.logger),external:!0,http:!1}})}};function yce(o,s){return{order:100,canRead(f){let d=Srr(f.url);if(!(d===void 0||d==="file"))return!1;let x;try{x=Aat(f.url)}catch(P){throw new kO(`Malformed URI: ${f.url}`,{cause:P})}try{tu.safePath(o).resolve(x)}catch(P){return s?.warn(P),!1}return!0},async read(f){let d;try{d=Aat(f.url)}catch(y){throw new kO(`Malformed URI: ${f.url}`,{cause:y})}try{return await yrr(d)}catch(y){throw new kO(`Error opening file "${d}"`,{cause:y})}}}}t(yce,"customResolver");var _M=/^win/.test(globalThis.process?globalThis.process.platform:""),vrr=/\//g,brr=/^(\w{2,}):\/\//i,A6e=[/%23/g,"#",/%24/g,"$",/%26/g,"&",/%2C/g,",",/%40/g,"@"];function Srr(o){let s=brr.exec(o);if(s)return s[1].toLowerCase()}t(Srr,"getProtocol");function Aat(o,s){o=decodeURI(o);for(let d=0;d<A6e.length;d+=2)o=o.replace(A6e[d],A6e[d+1]);let f=o.substr(0,7).toLowerCase()==="file://";if(f&&(o=o[7]==="/"?o.substr(8):o.substr(7),_M&&o[1]==="/"&&(o=`${o[0]}:${o.substr(1)}`),s?o=`file:///${o}`:(f=!1,o=_M?o:`/${o}`)),!f){let d=o.split(_M?"\\":"/"),y=[];for(let x of d)x===".."?y.length&&y[y.length-1]!==""&&y.pop():(x!==""||y.length===0)&&y.push(x);o=y.join(_M?"\\":"/"),!_M&&y[0]===""&&(o=`/${o.substring(1)}`)}return _M&&!f&&(o=o.replace(vrr,"\\"),o.substr(1,2)===":\\"&&(o=o[0].toUpperCase()+o.substr(1))),o}t(Aat,"toFileSystemPath");var Nat="YOUR_KEY_HERE";async function Iat(o){let f=await new sI(o.sourceDirectory,o.logger).bundle(o.openApiDocPath),d=o.openApiDocPath.replace(o.sourceDirectory,"");return Trr({...o,relativeOpenApiPath:d},f)}t(Iat,"buildPublicOpenApiFile");async function Trr(o,s){krr({relativeOpenApiPath:o.relativeOpenApiPath},s);let f=s;return f=Err(f),xrr(f,o.urls?.api?.defaultUrl),f=Crr(f,o),Oat(f,"x-zuplo"),f}t(Trr,"buildRawOpenApiFile");function xrr(o,s){s?o.servers=[{url:s}]:o.servers=[]}t(xrr,"addServerHost");function Err(o){if(!o.paths)return o;let{components:s}=o,f=s?{...s}:void 0,d=[];f&&f.parameters&&(d=Object.entries(f.parameters).reduce((x,[P,F])=>(j9 in F&&uoe(F[j9])&&(x.push(P),f.parameters&&delete f.parameters[P]),x),[]));let y=Object.entries(o.paths).reduce((x,[P,F])=>{if(!F)return x;let J={...F},G=["delete","get","head","patch","post","put","trace","options"];return G.forEach(Se=>{let de=F[Se];if(!de)return;if(uoe(de[j9])){delete J[Se];return}let{parameters:ae}=de;if(!ae)return;let Ke=ae.filter($e=>{if(j9 in $e&&uoe($e[j9]))return!1;if("$ref"in $e){let Fe=$e.$ref.split("/").pop();return Fe?!d.includes(Fe):!0}return!0});J[Se]={...de,parameters:Ke}}),G.some(Se=>!!J[Se])&&(x[P]=J),x},{});return{...o,paths:y,components:f}}t(Err,"removeHiddenRoutesAndParams");function Crr(o,{policiesConfig:s}){if(!o.paths)return o;let f=Object.entries(o.paths).reduce((d,[y,x])=>{if(!x)return d;let P={...x};return[P.delete,P.get,P.head,P.patch,P.post,P.put,P.trace,P.options].forEach(F=>{if(!F)return;let J=F["x-zuplo-route"]?.policies?.inbound?.reduce((de,ae)=>{let Ke=s.policies?.find(({name:Gt})=>Gt===ae);if(!Ke)return de;if(!(Ke.handler.export==="CompositeInboundPolicy"))return de.concat(ae);let Fe=Ke.handler.options?.policies;return Fe?de.concat(Fe):de},[]),G=[];if(J&&J.forEach(de=>{s.policies?.forEach(ae=>{ae.name===de&&(ae.handler.export==="ApiAuthKeyInboundPolicy"||ae.handler.export==="ApiKeyInboundPolicy")&&!ae.handler.options?.disableAutomaticallyAddingKeyHeaderToOpenApi&&G.push(ae)})}),G.length>0){let de=G.length>0&&G[0].handler&&G[0].handler.options&&G[0].handler.options.authHeader?G[0].handler.options.authHeader:"Authorization",ae=G.length>0&&G[0].handler&&G[0].handler.options&&(G[0].handler.options.authScheme||G[0].handler.options.authScheme==="")?G[0].handler.options.authScheme:"Bearer",Ke=ae!==""?`${ae} ${Nat}`:Nat,$e={name:de,in:"header",required:!0,example:Ke,schema:{type:"string"},description:`The \`${de}\` header is used to authenticate with the API using your API key. Value is of the format \`${Ke}\`.`};F.parameters?F.parameters.some(Pr=>"name"in Pr&&Pr.name===$e.name)||F.parameters.unshift($e):F.parameters=[$e];let Fe={type:"http",scheme:ae.toLowerCase()},Gt="api_key";o.components?.securitySchemes?Object.values(o.components?.securitySchemes).some(Pr=>"name"in Pr&&Pr.type==="apiKey"||"type"in Pr&&Pr.type==="http"&&Pr.scheme===ae)||(o.components.securitySchemes={...o.components.securitySchemes,[Gt]:Fe}):(o.components||(o.components={}),o.components.securitySchemes={[Gt]:Fe});let jt={[Gt]:[]};F.security?F.security.some(Pr=>Pr[Gt]!==void 0)||F.security.unshift(jt):F.security=[jt]}let Se=[];if(J&&J.forEach(de=>{s.policies?.forEach(ae=>{ae.name===de&&(ae.handler.export==="RateLimitInboundPolicy"||ae.handler.export==="ComplexRateLimitInboundPolicy")&&Se.push(ae)})}),Se.length>0){let de={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"}}}}}},ae={...de,headers:{"retry-after":{description:"The number of seconds to wait before making a new request.",schema:{type:"integer",example:60}}}};o.components?.responses||o.components||(o.components={}),o.components.responses={...o.components.responses,RateLimitNoRetryAfter:de,RateLimitWithRetryAfter:ae},F.responses||(F.responses={});let Ke=Se.some($e=>$e.handler.options?.headerMode!=="none");F.responses[429]||(F.responses[429]={$ref:Ke?"#/components/responses/RateLimitWithRetryAfter":"#/components/responses/RateLimitNoRetryAfter"})}}),d[y]=P,d},{});return{...o,paths:f}}t(Crr,"enrichSpecWithZuploData");function Oat(o,s){for(let f in o)f.startsWith(s)?delete o[f]:typeof o[f]=="object"&&Oat(o[f],s)}t(Oat,"removePropertiesByPrefix");function krr({relativeOpenApiPath:o},s){if(!s||typeof s!="object")throw new D1({message:"The OpenAPI Document could not be parsed.",severity:"error"});if(!("info"in s)||typeof s.info!="object"||!s.info)throw new D1({message:"The OpenAPI document does not have the required 'info' property.",location:{file:o,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 D1({message:"The OpenAPI document does not have the required 'info.title' property.",location:{file:o,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(krr,"assertIsZuploOpenApiSpec");import Hle from"node:path";function wrr(o){if(o.length>=255)throw new TypeError("Alphabet too long");let s=new Uint8Array(256);for(let G=0;G<s.length;G++)s[G]=255;for(let G=0;G<o.length;G++){let Se=o.charAt(G),de=Se.charCodeAt(0);if(s[de]!==255)throw new TypeError(Se+" is ambiguous");s[de]=G}let f=o.length,d=o.charAt(0),y=Math.log(f)/Math.log(256),x=Math.log(256)/Math.log(f);function P(G){if(G instanceof Uint8Array||(ArrayBuffer.isView(G)?G=new Uint8Array(G.buffer,G.byteOffset,G.byteLength):Array.isArray(G)&&(G=Uint8Array.from(G))),!(G instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(G.length===0)return"";let Se=0,de=0,ae=0,Ke=G.length;for(;ae!==Ke&&G[ae]===0;)ae++,Se++;let $e=(Ke-ae)*x+1>>>0,Fe=new Uint8Array($e);for(;ae!==Ke;){let Pr=G[ae],Fn=0;for(let sn=$e-1;(Pr!==0||Fn<de)&&sn!==-1;sn--,Fn++)Pr+=256*Fe[sn]>>>0,Fe[sn]=Pr%f>>>0,Pr=Pr/f>>>0;if(Pr!==0)throw new Error("Non-zero carry");de=Fn,ae++}let Gt=$e-de;for(;Gt!==$e&&Fe[Gt]===0;)Gt++;let jt=d.repeat(Se);for(;Gt<$e;++Gt)jt+=o.charAt(Fe[Gt]);return jt}t(P,"encode");function F(G){if(typeof G!="string")throw new TypeError("Expected String");if(G.length===0)return new Uint8Array;let Se=0,de=0,ae=0;for(;G[Se]===d;)de++,Se++;let Ke=(G.length-Se)*y+1>>>0,$e=new Uint8Array(Ke);for(;G[Se];){let Pr=s[G.charCodeAt(Se)];if(Pr===255)return;let Fn=0;for(let sn=Ke-1;(Pr!==0||Fn<ae)&&sn!==-1;sn--,Fn++)Pr+=f*$e[sn]>>>0,$e[sn]=Pr%256>>>0,Pr=Pr/256>>>0;if(Pr!==0)throw new Error("Non-zero carry");ae=Fn,Se++}let Fe=Ke-ae;for(;Fe!==Ke&&$e[Fe]===0;)Fe++;let Gt=new Uint8Array(de+(Ke-Fe)),jt=de;for(;Fe!==Ke;)Gt[jt++]=$e[Fe++];return Gt}t(F,"decodeUnsafe");function J(G){let Se=F(G);if(Se)return Se;throw new Error("Non-base"+f+" character")}return t(J,"decode"),{encode:P,decodeUnsafe:F,decode:J}}t(wrr,"base");var Fat=wrr;var Drr="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",vce=Fat(Drr);var Prr=!1;function pM(o,s){return{open:`\x1B[${o.join(";")}m`,close:`\x1B[${s}m`,regexp:new RegExp(`\\x1b\\[${s}m`,"g")}}t(pM,"code");function dM(o,s){return Prr?`${s.open}${o.replace(s.regexp,s.open)}${s.close}`:o}t(dM,"run");function Arr(o){return dM(o,pM([31],39))}t(Arr,"red");function Nrr(o){return dM(o,pM([32],39))}t(Nrr,"green");function Irr(o){return dM(o,pM([33],39))}t(Irr,"yellow");function Orr(o){return dM(o,pM([34],39))}t(Orr,"blue");function Frr(o){return dM(o,pM([35],39))}t(Frr,"magenta");function Lrr(o){return dM(o,pM([36],39))}t(Lrr,"cyan");var TDr=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 Lat=[Arr,Nrr,Irr,Orr,Frr,Lrr];function Rrr(o){let s=0,f=o.length,d=0;if(f>0)for(;d<f;)s=(s<<5)-s+o.charCodeAt(d++)|0;return s}t(Rrr,"hashCode");function Rat(o){let s=Math.abs(Rrr(o));return Lat[s%Lat.length]}t(Rat,"generateColor");import{inspect as Mrr}from"node:util";function Mat(o,s,...f){let d=0,y=f.length,x=String(s).replace(/%[sdjoO%]/g,P=>{if(P==="%%")return"%";if(d>=y)return P;switch(P){case"%s":return String(f[d++]);case"%d":return Number(f[d++]).toString();case"%o":return o(f[d++]).split(`
|
|
575
|
-
`).map(F=>F.trim()).join(" ");case"%O":return o(f[d++]);case"%j":try{return JSON.stringify(f[d++])}catch{return"[Circular]"}default:return P}});for(let P of f.splice(d))P===null||!(typeof P=="object"&&P!==null)?x+=" "+P:x+=" "+o(P);return x}t(Mat,"format");var jat=t((o,...s)=>Mat(Mrr,o,s),"format");var N6e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,f){this.manager=s,this.ns=f,this.color=Rat(f),this.last=0,this.enabled=s.enabled.some(d=>d.test(f))}log(...s){if(!this.enabled)return;let f,d=s[0];typeof d=="function"?f=d():f=String(d);let y=Date.now()-(this.last||Date.now());f=jat(f,...s);let x=`${this.color(this.ns)} ${f} ${this.color(`+${y}ms`)}`;console.log(x),this.last=Date.now()}},I6e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function jrr(o){return!o||o.length===0?[]:(o=o.replace(/\s/g,"").replace(/\*/g,".+"),o.split(",").map(s=>new RegExp(`^${s}$`)))}t(jrr,"extract");var bce;function Sce(o){bce||(bce=new I6e(jrr(process.env.DEBUG)));let s=new N6e(bce,o);return bce.debuggers.set(o,s),Object.assign(s.log.bind(s),{self:s})}t(Sce,"debug");var HP=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,f){typeof s=="string"?super(s,f):(super(s.message,f),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var Bat="zp-local-service";var jDr=Symbol("zuplo_meters"),BDr=Symbol("zuplo_dynamic_meters");var aI=Sce("zuplo:runtime:external-service");function Brr(){let o,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=Em.instance.runtime;if(s&&s!=="undefined")try{let f=atob(s);o=JSON.parse(f)}catch{}return o}t(Brr,"getServiceAuth");async function Uat(o,s){let f=".proxy",d=".tunnel";if(typeof o=="string"){let y=new URL(o),x=y.hostname;if(x.endsWith(f)){let Gt=x.slice(0,-f.length),jt=new URL(`http://${Gt}${y.pathname}${y.search}`);aI(`Routing to proxy: ${jt.toString()}`);let Pr=s??{};return iH(jt.toString(),Pr)}let P=x.endsWith(d),F=x.indexOf(".")===-1;if(!(P||F))throw new HP(`Invalid service hostname suffix: ${x}. Use .proxy for proxy routing, .tunnel for explicit tunnel routing, or no suffix for default tunnel routing.`);let G=P?x.slice(0,-d.length):x,Se=Brr();if(!Se)throw aI("There is no external service auth configured for this zup."),new HP("There are no external services configured for this zup.");aI(`Using external service auth. ClientId: ${Se.clientId})`);let de=s??{},ae=new Headers(de.headers||{});ae.set("CF-Access-Client-Id",Se.clientId),ae.set("CF-Access-Client-Secret",Se.clientSecret),de.headers=ae;let Ke;if(Se.customServiceMapping?.[G])Ke=`https://${Se.customServiceMapping[G]}`;else if(Em.instance.useLegacyServiceRouting)Ke=`https://${G}.zuptunnel.com`;else{aI("Using sha256 service routing");let Gt=Em.instance.build;if(Gt.ACCOUNT_NAME&&Gt.PROJECT_NAME&&Gt.ENVIRONMENT_TYPE){let jt=await Urr(G,Gt.ACCOUNT_NAME,Gt.PROJECT_NAME,Gt.ENVIRONMENT_TYPE),Pr=$at(Gt.ENVIRONMENT_TYPE),Fn=await O6e(`${Gt.ACCOUNT_NAME}-${Gt.PROJECT_NAME}-${Pr}`);Fn==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Fn==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?Ke=`https://${jt}.zuptunnel.com`:Ke=`https://${jt}.t.zuplo.app`}else throw aI("Cannot use sha256 service routing, missing build variables"),new HP("Failed to generate fully qualified tunnel url.")}let $e=new URL(`${Ke}${y.pathname}${y.search}`);aI(`Calling external service: ${$e.toString()}`);let Fe=await iH($e.toString(),de);if(Fe.status===403&&Fe.headers.get("cf-access-domain")!==null)throw sH.console.error("403 Forbidden when calling external service.",{clientId:Se.clientId,tunnelHost:Ke}),new HP("Could not connect to secure tunnel.");return Fe}else throw aI("Cannot call external service with Request object"),new HP("Currently, we only support fetch(<some_string>, ...).")}t(Uat,"externalServiceHandler");async function zat(o,s){if(typeof o=="string"){let f=new URL(o),d=f.hostname,y=s??{},x=`http://${d}.zuplo.svc.cluster.local:9000`,P=new URL(`${x}${f.pathname}${f.search}`),F=new Headers(y.headers||{});return F.set(Bat,d),y.headers=F,await iH(P.toString(),y)}else throw new HP("Currently, we only support fetch(<some_string>, ...).")}t(zat,"clusterServiceHandler");async function Urr(o,s,f,d){let y=o.toLowerCase(),x=s.toLowerCase(),P=f.toLowerCase(),F=$at(d);aI(`Hashing service name: ${x}-${y}.${x}-${P}-${F}`);let J=await O6e(`${x}-${y}`),G=await O6e(`${x}-${P}-${F}`);return`${J}.${G}`}t(Urr,"hashServiceName");async function O6e(o){let s=new TextEncoder().encode(o),f=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(f)).map(x=>x.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(O6e,"hashSegment");function $at(o){let s=o.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t($at,"sanitizeEnvironmentType");var F6e=new Map;F6e.set("service:",Uat);F6e.set("local:",zat);var iH=globalThis.fetch;function L6e(o,s){let{transformedInit:f,clientCertificate:d}=zrr(s);if(typeof o=="string"){let y=new URL(o),x=F6e.get(y.protocol);return x?x(o,f):Jat(o,f,d)}else return Jat(o,f,d)}t(L6e,"internalFetch");globalThis.fetch=L6e;function Jat(o,s,f){if(!f)return iH(o,s);if(Em.instance.isCloudflare){let y=Em.instance.runtime[f];if(!y)throw new Error(`Client certificate binding '${f}' not found. Ensure the certificate is uploaded and properly configured.`);if(typeof y!="object"||typeof y.fetch!="function")throw new Error(`Client certificate binding '${f}' is not a valid mTLS certificate binding. Make sure it's configured as an mTLS certificate, not an environment variable.`);return y.fetch(o,s)}else throw Em.instance.isDeno?new Error("mTLS client certificates are not yet supported in Deno runtime. This will be added in a future update."):new Error("mTLS client certificates are not supported in this runtime environment")}t(Jat,"performFetch");var zrr=t(o=>{if(!o||o instanceof Request)return{transformedInit:o,clientCertificate:void 0};let s=o;if(!s.zuplo)return{transformedInit:o,clientCertificate:void 0};let f=s.zuplo.clientCertificate,d=o;return d.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete o.zuplo,{transformedInit:o,clientCertificate:f}},"transformInit");var $rr={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:L6e},sH=$rr;var R6e="2025-02-06",Wat=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 qat(){return new Em({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:R6e,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:Wat[R6e]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:"",ZUPLO_SERVICE_BUCKET_ID:"mock-bucket-id"}})}t(qat,"getMockEnvironment");var Em=class o{static{t(this,"Environment")}config;static#e;static#n=!1;static initialize(s){o.#e||(o.#e=new o(s),o.#n=!0)}static get instance(){return o.#n||(sH.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),o.#e=qat()),o.#e}constructor({build:s,runtime:f}){let d;try{if(f.ZUPLO_SYSTEM_CONFIGURATIONS){let y=new TextDecoder().decode(vce.decode(f.ZUPLO_SYSTEM_CONFIGURATIONS)),x=JSON.parse(y);for(let P of Object.keys(x))f[P]||(f[P]=x[P])}if(f.__ZUPLO_CONFIG){let y=atob(f.__ZUPLO_CONFIG);d=JSON.parse(y)}}catch(y){sH.console.error("Failed to parse runtime configuration",y)}this.config=d??{},this.build=s,this.runtime=f,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=globalThis.Deno?.version?.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,f=this.config.rate_limit_service_timeout_ms,d=s??f;if(!d)return 500;let y=Number(d);return Number.isFinite(y)&&y>0?y:500}};var Jrr=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function Vat(o){return o.startsWith("__ZUPLO")||o.startsWith("ZUPLO_")?!Jrr.includes(o)&&!o.startsWith("ZUPLO_PUBLIC_"):o.startsWith("ZUDOKU_")?!o.startsWith("ZUDOKU_PUBLIC_"):!1}t(Vat,"isRestrictedEnvVariableName");function Hat(o){return!!o.startsWith("ZUPLO_")}t(Hat,"isZuploReadableEnvVariableName");var _Pr=new Proxy({},{get(o,s){let f=String(s);switch(f){case"ZUPLO_ENVIRONMENT_TYPE":return Em.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return Em.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return Em.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return Em.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return Em.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return Em.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return Em.instance.build.COMPATIBILITY_DATE}if(!(Vat(f)&&!Hat(f)))return Em.instance.runtime[f]}});function aH(o,s,f){return`_${GP(`${o}_${s}_${f}`)}`}t(aH,"getRawOperationDataIdentifierName");function M6e(o,s,f,d){return`_${GP(o.toLowerCase())}_${s.toLowerCase()}_${f.toLowerCase()}_${d.toLowerCase()}`}t(M6e,"getIdForParameterSchema");function j6e(o,s,f){return`_${GP(o.toLowerCase())}_${s.toLowerCase()}_rb_${GP(f.toLowerCase())}`}t(j6e,"getIdForRequestBodySchema");function oH(o,s){return`_${GP(o)}_${GP(s)}`}t(oH,"getIdForRefSchema");function GP(o){let s=o.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(GP,"sanitizedIdentifierName");var Yft=Dp(dct(),1);var bH=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(o,s,f,d,y,x){this.type=o,this.name=s,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},hsr=/[$_\p{ID_Start}]/u,gsr=/[$_\u200C\u200D\p{ID_Continue}]/u,yNe=".*";function ysr(o,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(o)}t(ysr,"Re");function gct(o,s=!1){let f=[],d=0;for(;d<o.length;){let y=o[d],x=t(function(P){if(!s)throw new TypeError(P);f.push({type:"INVALID_CHAR",index:d,value:o[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:o[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:o[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:o[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:o[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:o[d++]});continue}if(y===":"){let P="",F=d+1;for(;F<o.length;){let J=o.substr(F,1);if(F===d+1&&hsr.test(J)||F!==d+1&&gsr.test(J)){P+=o[F++];continue}break}if(!P){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:P}),d=F;continue}if(y==="("){let P=1,F="",J=d+1,G=!1;if(o[J]==="?"){x(`Pattern cannot start with "?" at ${J}`);continue}for(;J<o.length;){if(!ysr(o[J],!1)){x(`Invalid character '${o[J]}' at ${J}.`),G=!0;break}if(o[J]==="\\"){F+=o[J++]+o[J++];continue}if(o[J]===")"){if(P--,P===0){J++;break}}else if(o[J]==="("&&(P++,o[J+1]!=="?")){x(`Capturing groups are not allowed at ${J}`),G=!0;break}F+=o[J++]}if(G)continue;if(P){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=J;continue}f.push({type:"CHAR",index:d,value:o[d++]})}return f.push({type:"END",index:d,value:""}),f}t(gct,"v");function yct(o,s={}){let f=gct(o);s.delimiter??="/#?",s.prefixes??="./";let d=`[^${pT(s.delimiter)}]+?`,y=[],x=0,P=0,F="",J=new Set,G=t(Fn=>{if(P<f.length&&f[P].type===Fn)return f[P++].value},"a"),Se=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(Fn=>{let sn=G(Fn);if(sn!==void 0)return sn;let{type:Un,index:Er}=f[P];throw new TypeError(`Unexpected ${Un} at ${Er}, expected ${Fn}`)},"d"),ae=t(()=>{let Fn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)Fn+=sn;return Fn},"T"),Ke=t(Fn=>Fn,"Se"),$e=s.encodePart||Ke,Fe="",Gt=t(Fn=>{Fe+=Fn},"U"),jt=t(()=>{Fe.length&&(y.push(new bH(3,"","",$e(Fe),"",3)),Fe="")},"$"),Pr=t((Fn,sn,Un,Er,vr)=>{let ls=3;switch(vr){case"?":ls=1;break;case"*":ls=0;break;case"+":ls=2;break}if(!sn&&!Un&&ls===3){Gt(Fn);return}if(jt(),!sn&&!Un){if(!Fn)return;y.push(new bH(3,"","",$e(Fn),"",ls));return}let Ni;Un?Un==="*"?Ni=yNe:Ni=Un:Ni=d;let nc=2;Ni===d?(nc=1,Ni=""):Ni===yNe&&(nc=0,Ni="");let bi;if(sn?bi=sn:Un&&(bi=x++),J.has(bi))throw new TypeError(`Duplicate name '${bi}'.`);J.add(bi),y.push(new bH(nc,bi,$e(Fn),Ni,$e(Er),ls))},"V");for(;P<f.length;){let Fn=G("CHAR"),sn=G("NAME"),Un=G("REGEX");if(!sn&&!Un&&(Un=G("ASTERISK")),sn||Un){let vr=Fn??"";s.prefixes.indexOf(vr)===-1&&(Gt(vr),vr=""),jt();let ls=Se();Pr(vr,sn,Un,"",ls);continue}let Er=Fn??G("ESCAPED_CHAR");if(Er){Gt(Er);continue}if(G("OPEN")){let vr=ae(),ls=G("NAME"),Ni=G("REGEX");!ls&&!Ni&&(Ni=G("ASTERISK"));let nc=ae();de("CLOSE");let bi=Se();Pr(vr,ls,Ni,nc,bi);continue}jt(),de("END")}return y}t(yct,"D");function pT(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(pT,"S");function mct(o){return o&&o.ignoreCase?"ui":"u"}t(mct,"X");function vsr(o,s,f){return vct(yct(o,f),s,f)}t(vsr,"Z");function vM(o){switch(o){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(vM,"k");function vct(o,s,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of o){if(F.type===3){F.modifier===3?d+=pT(F.value):d+=`(?:${pT(F.value)})${vM(F.modifier)}`;continue}s&&s.push(F.name);let J=`[^${pT(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=J:F.type===0&&(G=yNe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${vM(F.modifier)}`:d+=`((?:${G})${vM(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${pT(F.prefix)}(${G})${pT(F.suffix)})`,d+=vM(F.modifier);continue}d+=`(?:${pT(F.prefix)}`,d+=`((?:${G})(?:`,d+=pT(F.suffix),d+=pT(F.prefix),d+=`(?:${G}))*)${pT(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${pT(f.endsWith)}]|$`,x=`[${pT(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,mct(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let P=!1;if(o.length){let F=o[o.length-1];F.type===3&&F.modifier===3&&(P=f.delimiter.indexOf(F)>-1)}return P||(d+=`(?=${x}|${y})`),new RegExp(d,mct(f))}t(vct,"F");var uI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},bsr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Ssr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Tsr(o,s){return o.length?o[0]==="/"?!0:!s||o.length<2?!1:(o[0]=="\\"||o[0]=="{")&&o[1]=="/":!1}t(Tsr,"J");function bct(o,s){return o.startsWith(s)?o.substring(s.length,o.length):o}t(bct,"Q");function xsr(o,s){return o.endsWith(s)?o.substr(0,o.length-s.length):o}t(xsr,"Ee");function Sct(o){return!o||o.length<2?!1:o[0]==="["||(o[0]==="\\"||o[0]==="{")&&o[1]==="["}t(Sct,"W");var Tct=["ftp","file","http","https","ws","wss"];function xct(o){if(!o)return!0;for(let s of Tct)if(o.test(s))return!0;return!1}t(xct,"N");function Esr(o,s){if(o=bct(o,"#"),s||o==="")return o;let f=new URL("https://example.com");return f.hash=o,f.hash?f.hash.substring(1,f.hash.length):""}t(Esr,"te");function Csr(o,s){if(o=bct(o,"?"),s||o==="")return o;let f=new URL("https://example.com");return f.search=o,f.search?f.search.substring(1,f.search.length):""}t(Csr,"re");function ksr(o,s){return s||o===""?o:Sct(o)?kct(o):Cct(o)}t(ksr,"ne");function wsr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.password=o,f.password}t(wsr,"se");function Dsr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.username=o,f.username}t(Dsr,"ie");function Psr(o,s,f){if(f||o==="")return o;if(s&&!Tct.includes(s))return new URL(`${s}:${o}`).pathname;let d=o[0]=="/";return o=new URL(d?o:"/-"+o,"https://example.com").pathname,d||(o=o.substring(2,o.length)),o}t(Psr,"ae");function Asr(o,s,f){return Ect(s)===o&&(o=""),f||o===""?o:wct(o)}t(Asr,"oe");function Nsr(o,s){return o=xsr(o,":"),s||o===""?o:vNe(o)}t(Nsr,"ce");function Ect(o){switch(o){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(Ect,"_");function vNe(o){if(o==="")return o;if(/^[-+.A-Za-z0-9]*$/.test(o))return o.toLowerCase();throw new TypeError(`Invalid protocol '${o}'.`)}t(vNe,"y");function Isr(o){if(o==="")return o;let s=new URL("https://example.com");return s.username=o,s.username}t(Isr,"le");function Osr(o){if(o==="")return o;let s=new URL("https://example.com");return s.password=o,s.password}t(Osr,"fe");function Cct(o){if(o==="")return o;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(o))throw new TypeError(`Invalid hostname '${o}'`);let s=new URL("https://example.com");return s.hostname=o,s.hostname}t(Cct,"z");function kct(o){if(o==="")return o;if(/[^0-9a-fA-F[\]:]/g.test(o))throw new TypeError(`Invalid IPv6 hostname '${o}'`);return o.toLowerCase()}t(kct,"j");function wct(o){if(o===""||/^[0-9]*$/.test(o)&&parseInt(o)<=65535)return o;throw new TypeError(`Invalid port '${o}'.`)}t(wct,"K");function Fsr(o){if(o==="")return o;let s=new URL("https://example.com");return s.pathname=o[0]!=="/"?"/-"+o:o,o[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(Fsr,"he");function Lsr(o){return o===""?o:new URL(`data:${o}`).pathname}t(Lsr,"ue");function Rsr(o){if(o==="")return o;let s=new URL("https://example.com");return s.search=o,s.search.substring(1,s.search.length)}t(Rsr,"de");function Msr(o){if(o==="")return o;let s=new URL("https://example.com");return s.hash=o,s.hash.substring(1,s.hash.length)}t(Msr,"pe");var jsr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#p=0;#o=0;#_=0;#u=0;#c=!1;constructor(o){this.#e=o}get result(){return this.#t}parse(){for(this.#n=gct(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#o===0){this.#h(),this.#x()?this.#i(9,1):this.#v()?this.#i(8,1):this.#i(7,0);continue}else if(this.#o===2){this.#m(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#l())this.#_-=1;else continue;if(this.#A()){this.#_+=1;continue}switch(this.#o){case 0:this.#g()&&this.#m(1);break;case 1:if(this.#g()){this.#P();let o=7,s=1;this.#y()?(o=2,s=3):this.#c&&(o=2),this.#i(o,s)}break;case 2:this.#E()?this.#m(3):(this.#k()||this.#v()||this.#x())&&this.#m(5);break;case 3:this.#T()?this.#i(4,1):this.#E()&&this.#i(5,1);break;case 4:this.#E()&&this.#i(5,1);break;case 5:this.#O()?this.#u+=1:this.#w()&&(this.#u-=1),this.#C()&&!this.#u?this.#i(6,1):this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 6:this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 7:this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 8:this.#x()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#i(o,s){switch(this.#o){case 0:break;case 1:this.#t.protocol=this.#D();break;case 2:break;case 3:this.#t.username=this.#D();break;case 4:this.#t.password=this.#D();break;case 5:this.#t.hostname=this.#D();break;case 6:this.#t.port=this.#D();break;case 7:this.#t.pathname=this.#D();break;case 8:this.#t.search=this.#D();break;case 9:this.#t.hash=this.#D();break;case 10:break}this.#o!==0&&o!==10&&([1,2,3,4].includes(this.#o)&&[6,7,8,9].includes(o)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#o)&&[8,9].includes(o)&&(this.#t.pathname??=this.#c?"/":""),[1,2,3,4,5,6,7].includes(this.#o)&&o===9&&(this.#t.search??="")),this.#a(o,s)}#a(o,s){this.#o=o,this.#p=this.#r+s,this.#r+=s,this.#s=0}#h(){this.#r=this.#p,this.#s=0}#m(o){this.#h(),this.#o=o}#f(o){return o<0&&(o=this.#n.length-o),o<this.#n.length?this.#n[o]:this.#n[this.#n.length-1]}#d(o,s){let f=this.#f(o);return f.value===s&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#g(){return this.#d(this.#r,":")}#y(){return this.#d(this.#r+1,"/")&&this.#d(this.#r+2,"/")}#E(){return this.#d(this.#r,"@")}#T(){return this.#d(this.#r,":")}#C(){return this.#d(this.#r,":")}#k(){return this.#d(this.#r,"/")}#v(){if(this.#d(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let o=this.#f(this.#r-1);return o.type!=="NAME"&&o.type!=="REGEX"&&o.type!=="CLOSE"&&o.type!=="ASTERISK"}#x(){return this.#d(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#d(this.#r,"[")}#w(){return this.#d(this.#r,"]")}#D(){let o=this.#n[this.#r],s=this.#f(this.#p).index;return this.#e.substring(s,o.index)}#P(){let o={};Object.assign(o,uI),o.encodePart=vNe;let s=vsr(this.#D(),void 0,o);this.#c=xct(s)}},gNe=["protocol","username","password","hostname","port","pathname","search","hash"],lI="*";function hct(o,s){if(typeof o!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(o,s);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(hct,"ge");function ZP(o,s){return s?vH(o):o}t(ZP,"b");function yH(o,s,f){let d;if(typeof s.baseURL=="string")try{d=new URL(s.baseURL),s.protocol===void 0&&(o.protocol=ZP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(o.username=ZP(d.username,f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(o.password=ZP(d.password,f)),s.protocol===void 0&&s.hostname===void 0&&(o.hostname=ZP(d.hostname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(o.port=ZP(d.port,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(o.pathname=ZP(d.pathname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(o.search=ZP(d.search.substring(1,d.search.length),f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(o.hash=ZP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(o.protocol=Nsr(s.protocol,f)),typeof s.username=="string"&&(o.username=Dsr(s.username,f)),typeof s.password=="string"&&(o.password=wsr(s.password,f)),typeof s.hostname=="string"&&(o.hostname=ksr(s.hostname,f)),typeof s.port=="string"&&(o.port=Asr(s.port,o.protocol,f)),typeof s.pathname=="string"){if(o.pathname=s.pathname,d&&!Tsr(o.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(o.pathname=ZP(d.pathname.substring(0,y+1),f)+o.pathname)}o.pathname=Psr(o.pathname,o.protocol,f)}return typeof s.search=="string"&&(o.search=Csr(s.search,f)),typeof s.hash=="string"&&(o.hash=Esr(s.hash,f)),o}t(yH,"w");function vH(o){return o.replace(/([+*?:{}()\\])/g,"\\$1")}t(vH,"C");function Bsr(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(Bsr,"Oe");function Usr(o,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let f=".*",d=`[^${Bsr(s.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let P=0;P<o.length;++P){let F=o[P];if(F.type===3){if(F.modifier===3){x+=vH(F.value);continue}x+=`{${vH(F.value)}}${vM(F.modifier)}`;continue}let J=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!s.prefixes.includes(F.prefix)),Se=P>0?o[P-1]:null,de=P<o.length-1?o[P+1]:null;if(!G&&J&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let ae=de.value.length>0?de.value[0]:"";G=y.test(ae)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&Se&&Se.type===3){let ae=Se.value[Se.value.length-1];G=s.prefixes.includes(ae)}G&&(x+="{"),x+=vH(F.prefix),J&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?J||(x+=`(${d})`):F.type===0&&(!J&&(!Se||Se.type===3||Se.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&J&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=vH(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=vM(F.modifier))}return x}t(Usr,"ke");var Dct=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#p=!1;constructor(o={},s,f){try{let d;if(typeof s=="string"?d=s:f=s,typeof o=="string"){let F=new jsr(o);if(F.parse(),o=F.result,d===void 0&&typeof o.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");o.baseURL=d}else{if(!o||typeof o!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:lI,protocol:lI,username:lI,password:lI,hostname:lI,port:lI,search:lI,hash:lI};this.#e=yH(x,o,!0),Ect(this.#e.protocol)===this.#e.port&&(this.#e.port="");let P;for(P of gNe){if(!(P in this.#e))continue;let F={},J=this.#e[P];switch(this.#t[P]=[],P){case"protocol":Object.assign(F,uI),F.encodePart=vNe;break;case"username":Object.assign(F,uI),F.encodePart=Isr;break;case"password":Object.assign(F,uI),F.encodePart=Osr;break;case"hostname":Object.assign(F,bsr),Sct(J)?F.encodePart=kct:F.encodePart=Cct;break;case"port":Object.assign(F,uI),F.encodePart=wct;break;case"pathname":xct(this.#n.protocol)?(Object.assign(F,Ssr,y),F.encodePart=Fsr):(Object.assign(F,uI,y),F.encodePart=Lsr);break;case"search":Object.assign(F,uI,y),F.encodePart=Rsr;break;case"hash":Object.assign(F,uI,y),F.encodePart=Msr;break}try{this.#s[P]=yct(J,F),this.#n[P]=vct(this.#s[P],this.#t[P],F),this.#r[P]=Usr(this.#s[P],F),this.#p=this.#p||this.#s[P].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${P} pattern '${this.#e[P]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return!1;try{typeof o=="object"?f=yH(f,o,!1):f=yH(f,hct(o,s),!1)}catch{return!1}let d;for(d of gNe)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return;try{typeof o=="object"?f=yH(f,o,!1):f=yH(f,hct(o,s),!1)}catch{return null}let d={};s?d.inputs=[o,s]:d.inputs=[o];let y;for(y of gNe){let x=this.#n[y].exec(f[y]);if(!x)return null;let P={};for(let[F,J]of this.#t[y].entries())if(typeof J=="string"||typeof J=="number"){let G=x[F+1];P[J]=G}d[y]={input:f[y]??"",groups:P}}return d}static compareComponent(o,s,f){let d=t((F,J)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<J[G])return-1;if(F[G]!==J[G])return 1}return 0},"o"),y=new bH(3,"","","","",3),x=new bH(0,"","","","",3),P=t((F,J)=>{let G=0;for(;G<Math.min(F.length,J.length);++G){let Se=d(F[G],J[G]);if(Se)return Se}return F.length===J.length?0:d(F[G]??y,J[G]??y)},"s");return!s.#r[o]&&!f.#r[o]?0:s.#r[o]&&!f.#r[o]?P(s.#s[o],[x]):!s.#r[o]&&f.#r[o]?P([x],f.#s[o]):P(s.#s[o],f.#s[o])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=Dct);import{AssertionError as zsr}from"node:assert";function QP(o,s){if(o===!1)throw new zsr({message:s})}t(QP,"assert");var Ko;(function(o){o.Object="Object",o.Property="Property",o.Array="Array",o.Literal="Literal",o.TemplateString="TemplateString",o.Identifier="Identifier",o.FunctionCall="FunctionCall",o.Raw="Raw"})(Ko||(Ko={}));function bM(o){return o.type===Ko.Object}t(bM,"isAstObject");function eA(o){return o.type===Ko.Property}t(eA,"isAstProperty");function Pct(o){return o.type===Ko.Array}t(Pct,"isAstArray");function SM(o){return o.type===Ko.Literal}t(SM,"isAstLiteral");function fI(o){if(o===void 0)throw new Error("Node is undefined");if(!bM(o))throw new Error("Node is not object")}t(fI,"assertAstObject");import{findNodeAtLocation as $sr,getNodeValue as Jsr,printParseErrorCode as Wsr,visit as qsr}from"jsonc-parser";var Vsr={DEFAULT:{allowTrailingComma:!1}};function SH(o,s=[],f=Vsr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(J){d.type==="property"&&(d.length=J-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(J){return d.children?.push(J),J}t(x,"onValue"),qsr(o,{onObjectBegin:t((J,G,Se)=>{d=x({type:"object",offset:J,length:-1,line:G+1,column:Se+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((J,G,Se,de,ae)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:ae+1,parent:d,children:[]}),d.children?.push({type:"string",value:J,offset:G,length:Se,line:de,column:ae,parent:d})},"onObjectProperty"),onObjectEnd:t((J,G)=>{y(J+G),d.length=J+G-d.offset,d=d.parent,y(J+G)},"onObjectEnd"),onArrayBegin:t((J,G,Se,de)=>{d=x({type:"array",offset:J,length:-1,line:Se+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((J,G)=>{d.length=J+G-d.offset,d=d.parent,y(J+G)},"onArrayEnd"),onLiteralValue:t((J,G,Se,de,ae)=>{x({type:Hsr(J),offset:G,length:Se,line:de+1,column:ae+1,parent:d,value:J}),y(G+Se)},"onLiteralValue"),onSeparator:t((J,G)=>{d.type==="property"&&(J===":"?d.colonOffset=G:J===","&&y(G))},"onSeparator"),onError:t((J,G,Se,de,ae)=>{s.push({error:J,offset:G,length:Se,line:de+1,column:ae+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(SH,"parse");function Hsr(o){switch(typeof o){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(o){if(Array.isArray(o))return"array"}else return"null";return"object"}default:return"null"}}t(Hsr,"getNodeType");function bNe(o,s){return $sr(o,s)}t(bNe,"findNodeAtLocation");function TH(o){return Jsr(o)}t(TH,"getNodeValue");function Act(o){return Wsr(o)}t(Act,"printParseErrorCode");var xH=class{static{t(this,"AstAdapter")}parse(s){let d=SH(s,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,f){switch(s.type){case"object":return this.createObject(s,f);case"array":return this.createArray(s,f);case"property":return this.createProperty(s,f);case"string":return this.createLiteral(s,f);case"number":return this.createLiteral(s,f);case"boolean":return this.createLiteral(s,f);case"null":return this.createLiteral(s,f)}}createLiteral(s,f){return{type:Ko.Literal,location:{line:s.line,column:s.column},parent:f,value:s.type==="null"?null:s.value}}createObject(s,f){let d={type:Ko.Object,children:[],parent:f,location:{line:s.line,column:s.column}};return s.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(s,f){QP(s.children?.length===2,"Invalid property node");let d={type:Ko.Property,location:{line:s.line,column:s.column},parent:f,name:null,value:null};return d.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:Ko.Identifier,parent:d},d.value=this.parseNode(s.children[1],d),d}createArray(s,f){let d={type:Ko.Array,location:{line:s.line,column:s.column},parent:f,children:[]};return s.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var dT={createLiteral:t((o,s)=>({type:Ko.Literal,parent:s,value:o}),"createLiteral"),createTemplateString:t((o,s)=>({type:Ko.TemplateString,parent:s,value:o}),"createTemplateString"),createIdentifier:t((o,s)=>({type:Ko.Identifier,value:o,parent:s}),"createIdentifier"),createProperty:t((o,s,f)=>{let d={type:Ko.Property,parent:f,name:null,value:s};return d.name={value:o,type:Ko.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((o,s)=>{let f={type:Ko.Array,parent:s,children:[]};for(let d of o)f.children.push(dT.createLiteral(d,f));return f},"createArrayOfLiterals")};var Gsr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,EH=class{static{t(this,"SourceGenerator")}generate(s){let f=[];return this.generateSource(f,s),f.join("")}generateSource(s,f){switch(f.type){case Ko.Array:return this.generateArray(s,f);case Ko.Object:return this.generateObject(s,f);case Ko.Property:return this.generateProperty(s,f);case Ko.Literal:return this.generateLiteral(s,f);case Ko.FunctionCall:return this.generateFunctionCall(s,f);case Ko.Identifier:return this.generateIdentifier(s,f);case Ko.Raw:return this.generateRaw(s,f);case Ko.TemplateString:return this.generateTemplateString(s,f)}}generateArray(s,f){s.push("["),f.children.map(d=>{this.generateSource(s,d),s.push(",")}),s.push("]")}generateObject(s,f){s.push("{"),f.children.forEach(d=>{this.generateSource(s,d),s.push(",")}),s.push("}")}generateProperty(s,f){this.generateIdentifier(s,f.name),s.push(":"),this.generateSource(s,f.value)}generateFunctionCall(s,f){s.push(f.name.value),s.push("("),f.children.forEach((d,y,x)=>{this.generateSource(s,d),y<x.length&&s.push(",")}),s.push(")")}generateRaw(s,f){s.push(f.value)}generateTemplateString(s,f){s.push("`"),s.push(f.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,f){if(f.value===null)return s.push("null");switch(typeof f.value){case"number":case"boolean":return s.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return s.push(`${y}`)}}}generateIdentifier(s,f){let d=Gsr.test(f.value)?f.value:`'${f.value}'`;s.push(d)}};import Ysr from"node:fs/promises";import{parse as Ksr}from"@swc/core";var Nct=t(async o=>{let s=new Set;try{let f=await Ysr.readFile(o,"utf-8");(await Ksr(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?s.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?s.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&s.add(y.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Ict={$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 SNe={$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 Oct={$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 TNe={$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 xNe={$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 Bft=Dp(lft(),1),Uft=Dp(Mle(),1);var jle=class o{static{t(this,"JsonValidator")}static#e=new o;static get instance(){return o.#e}ajv;constructor(){this.ajv=new Uft.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Bft.default)(this.ajv,{mode:"fast"})}addSchema(s,f){this.ajv.addSchema(s,f)}compile(s){let f=this.ajv.compile(s);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(s,f){let d=[];return s?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},P=y.instancePath.split("/");if(P.length>2){let J=P[1],G=P[2]?parseInt(P[2],10):0,Se=P[3],de=Number.isNaN(G)?void 0:f[J][G][Se];x={details:{property:J,index:G,field:Se,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let J=y.instancePath.split("/"),G=J[J.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var SI=jle.instance;SI.addSchema(xNe,"route-configuration.schema.json");SI.addSchema(Oct,"policy-configuration.schema.json");SI.addSchema(SNe,"policies.schema.json");SI.addSchema(TNe,"open-api-route-configuration.schema.json");SI.addSchema(Ict,"fragments.schema.json");var WIr=SI.compile(xNe),zft=SI.compile(TNe),j4e=SI.compile(SNe);var Ble=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=j4e(s),this.results}};var Ule=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=zft(s),this.results}};import apr from"node:path";var B4e=/\$import\((.*)\)/,zle=/\$env\((.*?)\)/g;var sA=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,f,d,y){super(s),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},spr=t(o=>{let s=[],f=o;for(;f.parent;)s.push(f),f=f.parent;return s.reverse()},"invertTree"),TI=t((o,s)=>{if(!o)return!1;let f=spr(o);return s.split("/").every((x,P)=>{let F=f[P];return F?x==="*"||eA(F)&&F.name.value===x?!0:x==="{}"?F.type===Ko.Object:x==="[]"?F.type===Ko.Array:!1:!1})},"testPosition");var $le=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),bM(s)?s.children.forEach(f=>{this.visitor(f)}):Pct(s)?s.children.forEach(f=>{this.visitor(f)}):eA(s)&&this.visitor(s.value)}},$ft=t((o,s,f)=>d=>{if(!eA(d)||!SM(d.value)||typeof d.value.value!="string")return;if(!o.some(x=>TI(d,x))){zle.test(d.value.value)&&s.push(new sA("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=new RegExp(zle).exec(d.value.value);if(y?.length===2&&y[0]===d.value.value){let x={type:Ko.Raw,parent:null,value:`environment["${y[1]}"]`};d.value=x}else{let x=d.value.value.replaceAll(new RegExp(zle),(P,F)=>`\${environment["${F}"] ? environment["${F}"] : ""}`);x!==d.value.value&&(d.value=dT.createTemplateString(x,d))}},"getEnvStatementTransformer");var tG="config/routes.json",opr=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],cpr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Jft=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],lpr="handler/{}/options/{}/rewritePattern",upr="handler/{}/options/{}/baseUrl",Jle=class extends $le{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let f=this.addedImports.get(s);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let s=[];return this.addedImports.forEach((f,d)=>{s.push({name:f,path:d})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!eA(s)||!SM(s.value)||typeof s.value.value!="string")&&TI(s,lpr)){if(!s.parent||!bM(s.parent)){this.errors.push(new sA("Invalid node, expected object",tG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Wft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}rewriteForwardFunction(s){if(!(!eA(s)||!SM(s.value)||typeof s.value.value!="string")&&TI(s,upr)){if(!s.parent||!bM(s.parent)){this.errors.push(new sA("Invalid node, expected object",tG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Wft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}replaceImportStatements(s){if(!eA(s)||!SM(s.value))return;let f=s.value.value;if(typeof f!="string")return;if(!cpr.some(F=>TI(s,F))&&!Jft.some(F=>TI(s,F))){if(B4e.test(f)){if(s.name.value==="$ref")return;this.errors.push(new sA("An $import() statement is not expected at this location.",tG,s.location,f))}return}let d=B4e.exec(f);if(Jft.some(F=>TI(s,F))&&!d)return;if(!d){this.errors.push(new sA("Invalid $import() statement",tG,s.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=apr.posix.join("..",y));let x=this.getImportName(y),P={type:Ko.Identifier,parent:s.parent,value:x};s.value=P}replaceEnvStatements=$ft(opr,this.errors,tG)};function Wft(o){return`(request, context) => {
|
|
575
|
+
`).map(F=>F.trim()).join(" ");case"%O":return o(f[d++]);case"%j":try{return JSON.stringify(f[d++])}catch{return"[Circular]"}default:return P}});for(let P of f.splice(d))P===null||!(typeof P=="object"&&P!==null)?x+=" "+P:x+=" "+o(P);return x}t(Mat,"format");var jat=t((o,...s)=>Mat(Mrr,o,s),"format");var N6e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,f){this.manager=s,this.ns=f,this.color=Rat(f),this.last=0,this.enabled=s.enabled.some(d=>d.test(f))}log(...s){if(!this.enabled)return;let f,d=s[0];typeof d=="function"?f=d():f=String(d);let y=Date.now()-(this.last||Date.now());f=jat(f,...s);let x=`${this.color(this.ns)} ${f} ${this.color(`+${y}ms`)}`;console.log(x),this.last=Date.now()}},I6e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function jrr(o){return!o||o.length===0?[]:(o=o.replace(/\s/g,"").replace(/\*/g,".+"),o.split(",").map(s=>new RegExp(`^${s}$`)))}t(jrr,"extract");var bce;function Sce(o){bce||(bce=new I6e(jrr(process.env.DEBUG)));let s=new N6e(bce,o);return bce.debuggers.set(o,s),Object.assign(s.log.bind(s),{self:s})}t(Sce,"debug");var HP=class extends Error{static{t(this,"RuntimeError")}extensionMembers;constructor(s,f){typeof s=="string"?super(s,f):(super(s.message,f),this.extensionMembers=s.extensionMembers),this.name="RuntimeError"}};var Bat="zp-local-service";var jDr=Symbol("zuplo_meters"),BDr=Symbol("zuplo_dynamic_meters");var aI=Sce("zuplo:runtime:external-service");function Brr(){let o,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:s}=Em.instance.runtime;if(s&&s!=="undefined")try{let f=atob(s);o=JSON.parse(f)}catch{}return o}t(Brr,"getServiceAuth");async function Uat(o,s){let f=".proxy",d=".tunnel";if(typeof o=="string"){let y=new URL(o),x=y.hostname;if(x.endsWith(f)){let Gt=x.slice(0,-f.length),jt=new URL(`http://${Gt}${y.pathname}${y.search}`);aI(`Routing to proxy: ${jt.toString()}`);let Pr=s??{};return iH(jt.toString(),Pr)}let P=x.endsWith(d),F=x.indexOf(".")===-1;if(!(P||F))throw new HP(`Invalid service hostname suffix: ${x}. Use .proxy for proxy routing, .tunnel for explicit tunnel routing, or no suffix for default tunnel routing.`);let G=P?x.slice(0,-d.length):x,Se=Brr();if(!Se)throw aI("There is no external service auth configured for this zup."),new HP("There are no external services configured for this zup.");aI(`Using external service auth. ClientId: ${Se.clientId})`);let de=s??{},ae=new Headers(de.headers||{});ae.set("CF-Access-Client-Id",Se.clientId),ae.set("CF-Access-Client-Secret",Se.clientSecret),de.headers=ae;let Ke;if(Se.customServiceMapping?.[G])Ke=`https://${Se.customServiceMapping[G]}`;else if(Em.instance.useLegacyServiceRouting)Ke=`https://${G}.zuptunnel.com`;else{aI("Using sha256 service routing");let Gt=Em.instance.build;if(Gt.ACCOUNT_NAME&&Gt.PROJECT_NAME&&Gt.ENVIRONMENT_TYPE){let jt=await Urr(G,Gt.ACCOUNT_NAME,Gt.PROJECT_NAME,Gt.ENVIRONMENT_TYPE),Pr=$at(Gt.ENVIRONMENT_TYPE),Fn=await O6e(`${Gt.ACCOUNT_NAME}-${Gt.PROJECT_NAME}-${Pr}`);Fn==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||Fn==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?Ke=`https://${jt}.zuptunnel.com`:Ke=`https://${jt}.t.zuplo.app`}else throw aI("Cannot use sha256 service routing, missing build variables"),new HP("Failed to generate fully qualified tunnel url.")}let $e=new URL(`${Ke}${y.pathname}${y.search}`);aI(`Calling external service: ${$e.toString()}`);let Fe=await iH($e.toString(),de);if(Fe.status===403&&Fe.headers.get("cf-access-domain")!==null)throw sH.console.error("403 Forbidden when calling external service.",{clientId:Se.clientId,tunnelHost:Ke}),new HP("Could not connect to secure tunnel.");return Fe}else throw aI("Cannot call external service with Request object"),new HP("Currently, we only support fetch(<some_string>, ...).")}t(Uat,"externalServiceHandler");async function zat(o,s){if(typeof o=="string"){let f=new URL(o),d=f.hostname,y=s??{},x=`http://${d}.zuplo.svc.cluster.local:9000`,P=new URL(`${x}${f.pathname}${f.search}`),F=new Headers(y.headers||{});return F.set(Bat,d),y.headers=F,await iH(P.toString(),y)}else throw new HP("Currently, we only support fetch(<some_string>, ...).")}t(zat,"clusterServiceHandler");async function Urr(o,s,f,d){let y=o.toLowerCase(),x=s.toLowerCase(),P=f.toLowerCase(),F=$at(d);aI(`Hashing service name: ${x}-${y}.${x}-${P}-${F}`);let J=await O6e(`${x}-${y}`),G=await O6e(`${x}-${P}-${F}`);return`${J}.${G}`}t(Urr,"hashServiceName");async function O6e(o){let s=new TextEncoder().encode(o),f=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(f)).map(x=>x.toString(16).padStart(2,"0")).join("").slice(0,-1)}t(O6e,"hashSegment");function $at(o){let s=o.toLowerCase();switch(s){case"production":case"preview":return s;default:return"working-copy"}}t($at,"sanitizeEnvironmentType");var F6e=new Map;F6e.set("service:",Uat);F6e.set("local:",zat);var iH=globalThis.fetch;function L6e(o,s){let{transformedInit:f,mtlsCertificate:d}=zrr(s);if(typeof o=="string"){let y=new URL(o),x=F6e.get(y.protocol);return x?x(o,f):Jat(o,f,d)}else return Jat(o,f,d)}t(L6e,"internalFetch");globalThis.fetch=L6e;function Jat(o,s,f){if(!f)return iH(o,s);if(Em.instance.isCloudflare){let y=Em.instance.runtime[f];if(!y)throw new Error(`mTLS certificate binding '${f}' not found. Ensure the certificate is uploaded and properly configured.`);if(typeof y!="object"||typeof y.fetch!="function")throw new Error(`mTLS certificate binding '${f}' is not a valid mTLS certificate binding. Make sure it's configured as an mTLS certificate, not an environment variable.`);return y.fetch(o,s)}else throw Em.instance.isDeno?new Error("mTLS client certificates are not yet supported in Deno runtime. This will be added in a future update."):new Error("mTLS client certificates are not supported in this runtime environment")}t(Jat,"performFetch");var zrr=t(o=>{if(!o||o instanceof Request)return{transformedInit:o,mtlsCertificate:void 0};let s=o;if(!s.zuplo)return{transformedInit:o,mtlsCertificate:void 0};let f=s.zuplo.mtlsCertificate,d=o;return d.cf={cacheEverything:s.zuplo?.cacheEverything,cacheTtl:s.zuplo?.cacheTtlSeconds},delete o.zuplo,{transformedInit:o,mtlsCertificate:f}},"transformInit");var $rr={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:L6e},sH=$rr;var R6e="2025-02-06",Wat=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 qat(){return new Em({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:R6e,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:Wat[R6e]},runtime:{RUNTIME_ENV:"test",RUNTIME_STAGE:"test",__ZUPLO_DEPLOYMENT_NAME:"mock-deployment-name",__ZUPLO_LOG_LEVEL:"debug",__ZUPLO_LOG_FORMAT:"pretty",__ZUPLO_MANAGEMENT_API_URL:"",__ZUPLO_RUNTIME_TYPE:"cloudflare",__ZUPLO_AUTH_API_JWT:"",ZUPLO_SERVICE_BUCKET_ID:"mock-bucket-id"}})}t(qat,"getMockEnvironment");var Em=class o{static{t(this,"Environment")}config;static#e;static#n=!1;static initialize(s){o.#e||(o.#e=new o(s),o.#n=!0)}static get instance(){return o.#n||(sH.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),o.#e=qat()),o.#e}constructor({build:s,runtime:f}){let d;try{if(f.ZUPLO_SYSTEM_CONFIGURATIONS){let y=new TextDecoder().decode(vce.decode(f.ZUPLO_SYSTEM_CONFIGURATIONS)),x=JSON.parse(y);for(let P of Object.keys(x))f[P]||(f[P]=x[P])}if(f.__ZUPLO_CONFIG){let y=atob(f.__ZUPLO_CONFIG);d=JSON.parse(y)}}catch(y){sH.console.error("Failed to parse runtime configuration",y)}this.config=d??{},this.build=s,this.runtime=f,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get useLegacyServiceRouting(){return this.config.use_legacy_service_routing??void 0}get useProxyForFetchFromZups(){return this.config.use_proxy_for_fetch_from_zups??void 0}get devPortalBaseUrl(){return this.runtime.__ZUPLO_DEV_PORTAL_URL??this.config.dev_portal_url??"https://dev-portal-v4-1.zuplo.com"}get buildAssetsUrl(){return this.runtime.__ZUPLO_BUILD_ASSETS_URL??this.config.build_assets_url??"https://build-assets.zuplo.com"}get zuploEdgeApiUrl(){return this.config.zuplo_edge_api_url??"https://api.zuploedge.com"}get remoteLogToken(){return this.runtime.__ZUPLO_REMOTE_LOG_TOKEN??this.config.remote_log_token??void 0}get zuploClientAuthBucketId(){return this.config.zuplo_auth_client_bucket_id??"auth_o8PUdhKxSTOiB794GWPwLQCD"}get managementApiURL(){return this.runtime.__ZUPLO_MANAGEMENT_API_URL??this.config.management_api_url??"https://api.zuplo.com"}get developerApiUrl(){return this.config.developer_api_url??"https://dev.zuplo.com"}get cdnURL(){return this.runtime.__ZUPLO_CDN_URL??this.config.cdn_url??"https://cdn.zuplo.com"}get remoteLogURL(){return this.runtime.__ZUPLO_REMOTE_LOG_URL??this.config.log_event_api??"https://ellie.zuploedge.com"}get loggingId(){return this.runtime.__ZUPLO_LOGGING_ID??this.config.logging_id??void 0}get redisURL(){return this.runtime.__ZUPLO_REDIS_URL??this.config.redis_proxy_url??"https://redis-proxy.zuploedge.com"}get apiKeyServiceUrl(){return this.runtime.__ZUPLO_API_KEY_SERVICE_URL??this.config.api_key_service_url??"https://apikey.zuploedge.com"}get meteringServiceUrl(){return this.config.metering_service_url??"https://meters.zuploedge.com"}get authApiJWT(){return this.runtime.__ZUPLO_AUTH_API_JWT??void 0}get authClientId(){return this.config.auth_client_id??this.runtime.__ZUPLO_AUTH_CLIENT_ID}get authClientSecret(){return this.config.auth_client_secret??this.runtime.__ZUPLO_AUTH_CLIENT_SECRET}get authPublicKey(){return this.config.auth_public_key??this.runtime.__ZUPLO_AUTH_PUBLIC_KEY}get authPrivateKey(){return this.config.auth_private_key??this.runtime.__ZUPLO_AUTH_PRIVATE_KEY}get userLogLevel(){return this.runtime.ZUPLO_LOG_LEVEL??this.runtime.__ZUPLO_LOG_LEVEL??this.config.user_log_level??"debug"}get systemLogLevel(){return this.runtime.__ZUPLO_LOG_LEVEL??this.config.system_log_level??"debug"}get logFormat(){return this.runtime.__ZUPLO_LOG_FORMAT??this.config.log_format??"cloudflare"}get isCloudflare(){return this.runtime.__ZUPLO_RUNTIME_TYPE?this.runtime.__ZUPLO_RUNTIME_TYPE==="cloudflare":this.config.runtime_type?this.config.runtime_type==="cloudflare":typeof WebSocketPair=="function"}get isManagedDedicated(){return this.runtime.__ZUPLO_IS_MANAGED_DEDICATED==="true"}get isDeno(){if(this.runtime.__ZUPLO_RUNTIME_TYPE)return this.runtime.__ZUPLO_RUNTIME_TYPE==="deno";if(this.config.runtime_type)return this.config.runtime_type==="deno";{let s=globalThis.Deno?.version?.deno;return typeof WebSocketPair!="function"&&s}}get isLocalDevelopment(){return this.build.IS_LOCAL_DEVELOPMENT}get isTestMode(){return!!this.runtime.__ZUPLO_TEST_MODE}get systemUserAgent(){return`Zuplo/${this.build.ZUPLO_VERSION}`}get loggingEnvironmentType(){return this.isCloudflare?"edge":this.isLocalDevelopment?"local":this.isDeno?"working-copy":"unknown"}get loggingEnvironmentStage(){return this.build.ENVIRONMENT_TYPE==="PRODUCTION"?"production":this.build.ENVIRONMENT_TYPE==="PREVIEW"?"preview":this.isLocalDevelopment?"local":this.isWorkingCopy?"working-copy":"unknown"}get isWorkingCopy(){return this.build.ENVIRONMENT_TYPE==="WORKING_COPY"}get rateLimitServiceTimeoutMs(){let s=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,f=this.config.rate_limit_service_timeout_ms,d=s??f;if(!d)return 500;let y=Number(d);return Number.isFinite(y)&&y>0?y:500}};var Jrr=["ZUPLO_USER_LOGGER_DATA_DOG_API_KEY","ZUPLO_USER_LOGGER_DATA_DOG_URL","ZUPLO_LOG_LEVEL","ZUPLO_HANDLER_WRITE_LOG_LEVEL"];function Vat(o){return o.startsWith("__ZUPLO")||o.startsWith("ZUPLO_")?!Jrr.includes(o)&&!o.startsWith("ZUPLO_PUBLIC_"):o.startsWith("ZUDOKU_")?!o.startsWith("ZUDOKU_PUBLIC_"):!1}t(Vat,"isRestrictedEnvVariableName");function Hat(o){return!!o.startsWith("ZUPLO_")}t(Hat,"isZuploReadableEnvVariableName");var _Pr=new Proxy({},{get(o,s){let f=String(s);switch(f){case"ZUPLO_ENVIRONMENT_TYPE":return Em.instance.loggingEnvironmentType;case"ZUPLO_ENVIRONMENT_STAGE":return Em.instance.loggingEnvironmentStage;case"ZUPLO_ENVIRONMENT_NAME":return Em.instance.runtime.__ZUPLO_DEPLOYMENT_NAME;case"ZUPLO_ACCOUNT_NAME":return Em.instance.build.ACCOUNT_NAME;case"ZUPLO_PROJECT_NAME":return Em.instance.build.PROJECT_NAME;case"ZUPLO_BUILD_ID":return Em.instance.build.BUILD_ID;case"ZUPLO_COMPATIBILITY_DATE":return Em.instance.build.COMPATIBILITY_DATE}if(!(Vat(f)&&!Hat(f)))return Em.instance.runtime[f]}});function aH(o,s,f){return`_${GP(`${o}_${s}_${f}`)}`}t(aH,"getRawOperationDataIdentifierName");function M6e(o,s,f,d){return`_${GP(o.toLowerCase())}_${s.toLowerCase()}_${f.toLowerCase()}_${d.toLowerCase()}`}t(M6e,"getIdForParameterSchema");function j6e(o,s,f){return`_${GP(o.toLowerCase())}_${s.toLowerCase()}_rb_${GP(f.toLowerCase())}`}t(j6e,"getIdForRequestBodySchema");function oH(o,s){return`_${GP(o)}_${GP(s)}`}t(oH,"getIdForRefSchema");function GP(o){let s=o.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(GP,"sanitizedIdentifierName");var Yft=Dp(dct(),1);var bH=class{static{t(this,"R")}type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(o,s,f,d,y,x){this.type=o,this.name=s,this.prefix=f,this.value=d,this.suffix=y,this.modifier=x}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},hsr=/[$_\p{ID_Start}]/u,gsr=/[$_\u200C\u200D\p{ID_Continue}]/u,yNe=".*";function ysr(o,s){return(s?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(o)}t(ysr,"Re");function gct(o,s=!1){let f=[],d=0;for(;d<o.length;){let y=o[d],x=t(function(P){if(!s)throw new TypeError(P);f.push({type:"INVALID_CHAR",index:d,value:o[d++]})},"c");if(y==="*"){f.push({type:"ASTERISK",index:d,value:o[d++]});continue}if(y==="+"||y==="?"){f.push({type:"OTHER_MODIFIER",index:d,value:o[d++]});continue}if(y==="\\"){f.push({type:"ESCAPED_CHAR",index:d++,value:o[d++]});continue}if(y==="{"){f.push({type:"OPEN",index:d,value:o[d++]});continue}if(y==="}"){f.push({type:"CLOSE",index:d,value:o[d++]});continue}if(y===":"){let P="",F=d+1;for(;F<o.length;){let J=o.substr(F,1);if(F===d+1&&hsr.test(J)||F!==d+1&&gsr.test(J)){P+=o[F++];continue}break}if(!P){x(`Missing parameter name at ${d}`);continue}f.push({type:"NAME",index:d,value:P}),d=F;continue}if(y==="("){let P=1,F="",J=d+1,G=!1;if(o[J]==="?"){x(`Pattern cannot start with "?" at ${J}`);continue}for(;J<o.length;){if(!ysr(o[J],!1)){x(`Invalid character '${o[J]}' at ${J}.`),G=!0;break}if(o[J]==="\\"){F+=o[J++]+o[J++];continue}if(o[J]===")"){if(P--,P===0){J++;break}}else if(o[J]==="("&&(P++,o[J+1]!=="?")){x(`Capturing groups are not allowed at ${J}`),G=!0;break}F+=o[J++]}if(G)continue;if(P){x(`Unbalanced pattern at ${d}`);continue}if(!F){x(`Missing pattern at ${d}`);continue}f.push({type:"REGEX",index:d,value:F}),d=J;continue}f.push({type:"CHAR",index:d,value:o[d++]})}return f.push({type:"END",index:d,value:""}),f}t(gct,"v");function yct(o,s={}){let f=gct(o);s.delimiter??="/#?",s.prefixes??="./";let d=`[^${pT(s.delimiter)}]+?`,y=[],x=0,P=0,F="",J=new Set,G=t(Fn=>{if(P<f.length&&f[P].type===Fn)return f[P++].value},"a"),Se=t(()=>G("OTHER_MODIFIER")??G("ASTERISK"),"f"),de=t(Fn=>{let sn=G(Fn);if(sn!==void 0)return sn;let{type:Un,index:Er}=f[P];throw new TypeError(`Unexpected ${Un} at ${Er}, expected ${Fn}`)},"d"),ae=t(()=>{let Fn="",sn;for(;sn=G("CHAR")??G("ESCAPED_CHAR");)Fn+=sn;return Fn},"T"),Ke=t(Fn=>Fn,"Se"),$e=s.encodePart||Ke,Fe="",Gt=t(Fn=>{Fe+=Fn},"U"),jt=t(()=>{Fe.length&&(y.push(new bH(3,"","",$e(Fe),"",3)),Fe="")},"$"),Pr=t((Fn,sn,Un,Er,vr)=>{let ls=3;switch(vr){case"?":ls=1;break;case"*":ls=0;break;case"+":ls=2;break}if(!sn&&!Un&&ls===3){Gt(Fn);return}if(jt(),!sn&&!Un){if(!Fn)return;y.push(new bH(3,"","",$e(Fn),"",ls));return}let Ni;Un?Un==="*"?Ni=yNe:Ni=Un:Ni=d;let nc=2;Ni===d?(nc=1,Ni=""):Ni===yNe&&(nc=0,Ni="");let bi;if(sn?bi=sn:Un&&(bi=x++),J.has(bi))throw new TypeError(`Duplicate name '${bi}'.`);J.add(bi),y.push(new bH(nc,bi,$e(Fn),Ni,$e(Er),ls))},"V");for(;P<f.length;){let Fn=G("CHAR"),sn=G("NAME"),Un=G("REGEX");if(!sn&&!Un&&(Un=G("ASTERISK")),sn||Un){let vr=Fn??"";s.prefixes.indexOf(vr)===-1&&(Gt(vr),vr=""),jt();let ls=Se();Pr(vr,sn,Un,"",ls);continue}let Er=Fn??G("ESCAPED_CHAR");if(Er){Gt(Er);continue}if(G("OPEN")){let vr=ae(),ls=G("NAME"),Ni=G("REGEX");!ls&&!Ni&&(Ni=G("ASTERISK"));let nc=ae();de("CLOSE");let bi=Se();Pr(vr,ls,Ni,nc,bi);continue}jt(),de("END")}return y}t(yct,"D");function pT(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(pT,"S");function mct(o){return o&&o.ignoreCase?"ui":"u"}t(mct,"X");function vsr(o,s,f){return vct(yct(o,f),s,f)}t(vsr,"Z");function vM(o){switch(o){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}}t(vM,"k");function vct(o,s,f={}){f.delimiter??="/#?",f.prefixes??="./",f.sensitive??=!1,f.strict??=!1,f.end??=!0,f.start??=!0,f.endsWith="";let d=f.start?"^":"";for(let F of o){if(F.type===3){F.modifier===3?d+=pT(F.value):d+=`(?:${pT(F.value)})${vM(F.modifier)}`;continue}s&&s.push(F.name);let J=`[^${pT(f.delimiter)}]+?`,G=F.value;if(F.type===1?G=J:F.type===0&&(G=yNe),!F.prefix.length&&!F.suffix.length){F.modifier===3||F.modifier===1?d+=`(${G})${vM(F.modifier)}`:d+=`((?:${G})${vM(F.modifier)})`;continue}if(F.modifier===3||F.modifier===1){d+=`(?:${pT(F.prefix)}(${G})${pT(F.suffix)})`,d+=vM(F.modifier);continue}d+=`(?:${pT(F.prefix)}`,d+=`((?:${G})(?:`,d+=pT(F.suffix),d+=pT(F.prefix),d+=`(?:${G}))*)${pT(F.suffix)})`,F.modifier===0&&(d+="?")}let y=`[${pT(f.endsWith)}]|$`,x=`[${pT(f.delimiter)}]`;if(f.end)return f.strict||(d+=`${x}?`),f.endsWith.length?d+=`(?=${y})`:d+="$",new RegExp(d,mct(f));f.strict||(d+=`(?:${x}(?=${y}))?`);let P=!1;if(o.length){let F=o[o.length-1];F.type===3&&F.modifier===3&&(P=f.delimiter.indexOf(F)>-1)}return P||(d+=`(?=${x}|${y})`),new RegExp(d,mct(f))}t(vct,"F");var uI={delimiter:"",prefixes:"",sensitive:!0,strict:!0},bsr={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Ssr={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function Tsr(o,s){return o.length?o[0]==="/"?!0:!s||o.length<2?!1:(o[0]=="\\"||o[0]=="{")&&o[1]=="/":!1}t(Tsr,"J");function bct(o,s){return o.startsWith(s)?o.substring(s.length,o.length):o}t(bct,"Q");function xsr(o,s){return o.endsWith(s)?o.substr(0,o.length-s.length):o}t(xsr,"Ee");function Sct(o){return!o||o.length<2?!1:o[0]==="["||(o[0]==="\\"||o[0]==="{")&&o[1]==="["}t(Sct,"W");var Tct=["ftp","file","http","https","ws","wss"];function xct(o){if(!o)return!0;for(let s of Tct)if(o.test(s))return!0;return!1}t(xct,"N");function Esr(o,s){if(o=bct(o,"#"),s||o==="")return o;let f=new URL("https://example.com");return f.hash=o,f.hash?f.hash.substring(1,f.hash.length):""}t(Esr,"te");function Csr(o,s){if(o=bct(o,"?"),s||o==="")return o;let f=new URL("https://example.com");return f.search=o,f.search?f.search.substring(1,f.search.length):""}t(Csr,"re");function ksr(o,s){return s||o===""?o:Sct(o)?kct(o):Cct(o)}t(ksr,"ne");function wsr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.password=o,f.password}t(wsr,"se");function Dsr(o,s){if(s||o==="")return o;let f=new URL("https://example.com");return f.username=o,f.username}t(Dsr,"ie");function Psr(o,s,f){if(f||o==="")return o;if(s&&!Tct.includes(s))return new URL(`${s}:${o}`).pathname;let d=o[0]=="/";return o=new URL(d?o:"/-"+o,"https://example.com").pathname,d||(o=o.substring(2,o.length)),o}t(Psr,"ae");function Asr(o,s,f){return Ect(s)===o&&(o=""),f||o===""?o:wct(o)}t(Asr,"oe");function Nsr(o,s){return o=xsr(o,":"),s||o===""?o:vNe(o)}t(Nsr,"ce");function Ect(o){switch(o){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}}t(Ect,"_");function vNe(o){if(o==="")return o;if(/^[-+.A-Za-z0-9]*$/.test(o))return o.toLowerCase();throw new TypeError(`Invalid protocol '${o}'.`)}t(vNe,"y");function Isr(o){if(o==="")return o;let s=new URL("https://example.com");return s.username=o,s.username}t(Isr,"le");function Osr(o){if(o==="")return o;let s=new URL("https://example.com");return s.password=o,s.password}t(Osr,"fe");function Cct(o){if(o==="")return o;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(o))throw new TypeError(`Invalid hostname '${o}'`);let s=new URL("https://example.com");return s.hostname=o,s.hostname}t(Cct,"z");function kct(o){if(o==="")return o;if(/[^0-9a-fA-F[\]:]/g.test(o))throw new TypeError(`Invalid IPv6 hostname '${o}'`);return o.toLowerCase()}t(kct,"j");function wct(o){if(o===""||/^[0-9]*$/.test(o)&&parseInt(o)<=65535)return o;throw new TypeError(`Invalid port '${o}'.`)}t(wct,"K");function Fsr(o){if(o==="")return o;let s=new URL("https://example.com");return s.pathname=o[0]!=="/"?"/-"+o:o,o[0]!=="/"?s.pathname.substring(2,s.pathname.length):s.pathname}t(Fsr,"he");function Lsr(o){return o===""?o:new URL(`data:${o}`).pathname}t(Lsr,"ue");function Rsr(o){if(o==="")return o;let s=new URL("https://example.com");return s.search=o,s.search.substring(1,s.search.length)}t(Rsr,"de");function Msr(o){if(o==="")return o;let s=new URL("https://example.com");return s.hash=o,s.hash.substring(1,s.hash.length)}t(Msr,"pe");var jsr=class{static{t(this,"H")}#e;#n=[];#t={};#r=0;#s=1;#p=0;#o=0;#_=0;#u=0;#c=!1;constructor(o){this.#e=o}get result(){return this.#t}parse(){for(this.#n=gct(this.#e,!0);this.#r<this.#n.length;this.#r+=this.#s){if(this.#s=1,this.#n[this.#r].type==="END"){if(this.#o===0){this.#h(),this.#x()?this.#i(9,1):this.#v()?this.#i(8,1):this.#i(7,0);continue}else if(this.#o===2){this.#m(5);continue}this.#i(10,0);break}if(this.#_>0)if(this.#l())this.#_-=1;else continue;if(this.#A()){this.#_+=1;continue}switch(this.#o){case 0:this.#g()&&this.#m(1);break;case 1:if(this.#g()){this.#P();let o=7,s=1;this.#y()?(o=2,s=3):this.#c&&(o=2),this.#i(o,s)}break;case 2:this.#E()?this.#m(3):(this.#k()||this.#v()||this.#x())&&this.#m(5);break;case 3:this.#T()?this.#i(4,1):this.#E()&&this.#i(5,1);break;case 4:this.#E()&&this.#i(5,1);break;case 5:this.#O()?this.#u+=1:this.#w()&&(this.#u-=1),this.#C()&&!this.#u?this.#i(6,1):this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 6:this.#k()?this.#i(7,0):this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 7:this.#v()?this.#i(8,1):this.#x()&&this.#i(9,1);break;case 8:this.#x()&&this.#i(9,1);break;case 9:break;case 10:break}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="")}#i(o,s){switch(this.#o){case 0:break;case 1:this.#t.protocol=this.#D();break;case 2:break;case 3:this.#t.username=this.#D();break;case 4:this.#t.password=this.#D();break;case 5:this.#t.hostname=this.#D();break;case 6:this.#t.port=this.#D();break;case 7:this.#t.pathname=this.#D();break;case 8:this.#t.search=this.#D();break;case 9:this.#t.hash=this.#D();break;case 10:break}this.#o!==0&&o!==10&&([1,2,3,4].includes(this.#o)&&[6,7,8,9].includes(o)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#o)&&[8,9].includes(o)&&(this.#t.pathname??=this.#c?"/":""),[1,2,3,4,5,6,7].includes(this.#o)&&o===9&&(this.#t.search??="")),this.#a(o,s)}#a(o,s){this.#o=o,this.#p=this.#r+s,this.#r+=s,this.#s=0}#h(){this.#r=this.#p,this.#s=0}#m(o){this.#h(),this.#o=o}#f(o){return o<0&&(o=this.#n.length-o),o<this.#n.length?this.#n[o]:this.#n[this.#n.length-1]}#d(o,s){let f=this.#f(o);return f.value===s&&(f.type==="CHAR"||f.type==="ESCAPED_CHAR"||f.type==="INVALID_CHAR")}#g(){return this.#d(this.#r,":")}#y(){return this.#d(this.#r+1,"/")&&this.#d(this.#r+2,"/")}#E(){return this.#d(this.#r,"@")}#T(){return this.#d(this.#r,":")}#C(){return this.#d(this.#r,":")}#k(){return this.#d(this.#r,"/")}#v(){if(this.#d(this.#r,"?"))return!0;if(this.#n[this.#r].value!=="?")return!1;let o=this.#f(this.#r-1);return o.type!=="NAME"&&o.type!=="REGEX"&&o.type!=="CLOSE"&&o.type!=="ASTERISK"}#x(){return this.#d(this.#r,"#")}#A(){return this.#n[this.#r].type=="OPEN"}#l(){return this.#n[this.#r].type=="CLOSE"}#O(){return this.#d(this.#r,"[")}#w(){return this.#d(this.#r,"]")}#D(){let o=this.#n[this.#r],s=this.#f(this.#p).index;return this.#e.substring(s,o.index)}#P(){let o={};Object.assign(o,uI),o.encodePart=vNe;let s=vsr(this.#D(),void 0,o);this.#c=xct(s)}},gNe=["protocol","username","password","hostname","port","pathname","search","hash"],lI="*";function hct(o,s){if(typeof o!="string")throw new TypeError("parameter 1 is not of type 'string'.");let f=new URL(o,s);return{protocol:f.protocol.substring(0,f.protocol.length-1),username:f.username,password:f.password,hostname:f.hostname,port:f.port,pathname:f.pathname,search:f.search!==""?f.search.substring(1,f.search.length):void 0,hash:f.hash!==""?f.hash.substring(1,f.hash.length):void 0}}t(hct,"ge");function ZP(o,s){return s?vH(o):o}t(ZP,"b");function yH(o,s,f){let d;if(typeof s.baseURL=="string")try{d=new URL(s.baseURL),s.protocol===void 0&&(o.protocol=ZP(d.protocol.substring(0,d.protocol.length-1),f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&(o.username=ZP(d.username,f)),!f&&s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.username===void 0&&s.password===void 0&&(o.password=ZP(d.password,f)),s.protocol===void 0&&s.hostname===void 0&&(o.hostname=ZP(d.hostname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&(o.port=ZP(d.port,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&(o.pathname=ZP(d.pathname,f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&(o.search=ZP(d.search.substring(1,d.search.length),f)),s.protocol===void 0&&s.hostname===void 0&&s.port===void 0&&s.pathname===void 0&&s.search===void 0&&s.hash===void 0&&(o.hash=ZP(d.hash.substring(1,d.hash.length),f))}catch{throw new TypeError(`invalid baseURL '${s.baseURL}'.`)}if(typeof s.protocol=="string"&&(o.protocol=Nsr(s.protocol,f)),typeof s.username=="string"&&(o.username=Dsr(s.username,f)),typeof s.password=="string"&&(o.password=wsr(s.password,f)),typeof s.hostname=="string"&&(o.hostname=ksr(s.hostname,f)),typeof s.port=="string"&&(o.port=Asr(s.port,o.protocol,f)),typeof s.pathname=="string"){if(o.pathname=s.pathname,d&&!Tsr(o.pathname,f)){let y=d.pathname.lastIndexOf("/");y>=0&&(o.pathname=ZP(d.pathname.substring(0,y+1),f)+o.pathname)}o.pathname=Psr(o.pathname,o.protocol,f)}return typeof s.search=="string"&&(o.search=Csr(s.search,f)),typeof s.hash=="string"&&(o.hash=Esr(s.hash,f)),o}t(yH,"w");function vH(o){return o.replace(/([+*?:{}()\\])/g,"\\$1")}t(vH,"C");function Bsr(o){return o.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}t(Bsr,"Oe");function Usr(o,s){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let f=".*",d=`[^${Bsr(s.delimiter)}]+?`,y=/[$_\u200C\u200D\p{ID_Continue}]/u,x="";for(let P=0;P<o.length;++P){let F=o[P];if(F.type===3){if(F.modifier===3){x+=vH(F.value);continue}x+=`{${vH(F.value)}}${vM(F.modifier)}`;continue}let J=F.hasCustomName(),G=!!F.suffix.length||!!F.prefix.length&&(F.prefix.length!==1||!s.prefixes.includes(F.prefix)),Se=P>0?o[P-1]:null,de=P<o.length-1?o[P+1]:null;if(!G&&J&&F.type===1&&F.modifier===3&&de&&!de.prefix.length&&!de.suffix.length)if(de.type===3){let ae=de.value.length>0?de.value[0]:"";G=y.test(ae)}else G=!de.hasCustomName();if(!G&&!F.prefix.length&&Se&&Se.type===3){let ae=Se.value[Se.value.length-1];G=s.prefixes.includes(ae)}G&&(x+="{"),x+=vH(F.prefix),J&&(x+=`:${F.name}`),F.type===2?x+=`(${F.value})`:F.type===1?J||(x+=`(${d})`):F.type===0&&(!J&&(!Se||Se.type===3||Se.modifier!==3||G||F.prefix!=="")?x+="*":x+=`(${f})`),F.type===1&&J&&F.suffix.length&&y.test(F.suffix[0])&&(x+="\\"),x+=vH(F.suffix),G&&(x+="}"),F.modifier!==3&&(x+=vM(F.modifier))}return x}t(Usr,"ke");var Dct=class{static{t(this,"me")}#e;#n={};#t={};#r={};#s={};#p=!1;constructor(o={},s,f){try{let d;if(typeof s=="string"?d=s:f=s,typeof o=="string"){let F=new jsr(o);if(F.parse(),o=F.result,d===void 0&&typeof o.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");o.baseURL=d}else{if(!o||typeof o!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(d)throw new TypeError("parameter 1 is not of type 'string'.")}typeof f>"u"&&(f={ignoreCase:!1});let y={ignoreCase:f.ignoreCase===!0},x={pathname:lI,protocol:lI,username:lI,password:lI,hostname:lI,port:lI,search:lI,hash:lI};this.#e=yH(x,o,!0),Ect(this.#e.protocol)===this.#e.port&&(this.#e.port="");let P;for(P of gNe){if(!(P in this.#e))continue;let F={},J=this.#e[P];switch(this.#t[P]=[],P){case"protocol":Object.assign(F,uI),F.encodePart=vNe;break;case"username":Object.assign(F,uI),F.encodePart=Isr;break;case"password":Object.assign(F,uI),F.encodePart=Osr;break;case"hostname":Object.assign(F,bsr),Sct(J)?F.encodePart=kct:F.encodePart=Cct;break;case"port":Object.assign(F,uI),F.encodePart=wct;break;case"pathname":xct(this.#n.protocol)?(Object.assign(F,Ssr,y),F.encodePart=Fsr):(Object.assign(F,uI,y),F.encodePart=Lsr);break;case"search":Object.assign(F,uI,y),F.encodePart=Rsr;break;case"hash":Object.assign(F,uI,y),F.encodePart=Msr;break}try{this.#s[P]=yct(J,F),this.#n[P]=vct(this.#s[P],this.#t[P],F),this.#r[P]=Usr(this.#s[P],F),this.#p=this.#p||this.#s[P].some(G=>G.type===2)}catch{throw new TypeError(`invalid ${P} pattern '${this.#e[P]}'.`)}}}catch(d){throw new TypeError(`Failed to construct 'URLPattern': ${d.message}`)}}test(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return!1;try{typeof o=="object"?f=yH(f,o,!1):f=yH(f,hct(o,s),!1)}catch{return!1}let d;for(d of gNe)if(!this.#n[d].exec(f[d]))return!1;return!0}exec(o={},s){let f={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof o!="string"&&s)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof o>"u")return;try{typeof o=="object"?f=yH(f,o,!1):f=yH(f,hct(o,s),!1)}catch{return null}let d={};s?d.inputs=[o,s]:d.inputs=[o];let y;for(y of gNe){let x=this.#n[y].exec(f[y]);if(!x)return null;let P={};for(let[F,J]of this.#t[y].entries())if(typeof J=="string"||typeof J=="number"){let G=x[F+1];P[J]=G}d[y]={input:f[y]??"",groups:P}}return d}static compareComponent(o,s,f){let d=t((F,J)=>{for(let G of["type","modifier","prefix","value","suffix"]){if(F[G]<J[G])return-1;if(F[G]!==J[G])return 1}return 0},"o"),y=new bH(3,"","","","",3),x=new bH(0,"","","","",3),P=t((F,J)=>{let G=0;for(;G<Math.min(F.length,J.length);++G){let Se=d(F[G],J[G]);if(Se)return Se}return F.length===J.length?0:d(F[G]??y,J[G]??y)},"s");return!s.#r[o]&&!f.#r[o]?0:s.#r[o]&&!f.#r[o]?P(s.#s[o],[x]):!s.#r[o]&&f.#r[o]?P([x],f.#s[o]):P(s.#s[o],f.#s[o])}get protocol(){return this.#r.protocol}get username(){return this.#r.username}get password(){return this.#r.password}get hostname(){return this.#r.hostname}get port(){return this.#r.port}get pathname(){return this.#r.pathname}get search(){return this.#r.search}get hash(){return this.#r.hash}get hasRegExpGroups(){return this.#p}};globalThis.URLPattern||(globalThis.URLPattern=Dct);import{AssertionError as zsr}from"node:assert";function QP(o,s){if(o===!1)throw new zsr({message:s})}t(QP,"assert");var Ko;(function(o){o.Object="Object",o.Property="Property",o.Array="Array",o.Literal="Literal",o.TemplateString="TemplateString",o.Identifier="Identifier",o.FunctionCall="FunctionCall",o.Raw="Raw"})(Ko||(Ko={}));function bM(o){return o.type===Ko.Object}t(bM,"isAstObject");function eA(o){return o.type===Ko.Property}t(eA,"isAstProperty");function Pct(o){return o.type===Ko.Array}t(Pct,"isAstArray");function SM(o){return o.type===Ko.Literal}t(SM,"isAstLiteral");function fI(o){if(o===void 0)throw new Error("Node is undefined");if(!bM(o))throw new Error("Node is not object")}t(fI,"assertAstObject");import{findNodeAtLocation as $sr,getNodeValue as Jsr,printParseErrorCode as Wsr,visit as qsr}from"jsonc-parser";var Vsr={DEFAULT:{allowTrailingComma:!1}};function SH(o,s=[],f=Vsr.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(J){d.type==="property"&&(d.length=J-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function x(J){return d.children?.push(J),J}t(x,"onValue"),qsr(o,{onObjectBegin:t((J,G,Se)=>{d=x({type:"object",offset:J,length:-1,line:G+1,column:Se+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((J,G,Se,de,ae)=>{d=x({type:"property",offset:G,length:-1,line:de+1,column:ae+1,parent:d,children:[]}),d.children?.push({type:"string",value:J,offset:G,length:Se,line:de,column:ae,parent:d})},"onObjectProperty"),onObjectEnd:t((J,G)=>{y(J+G),d.length=J+G-d.offset,d=d.parent,y(J+G)},"onObjectEnd"),onArrayBegin:t((J,G,Se,de)=>{d=x({type:"array",offset:J,length:-1,line:Se+1,column:de+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((J,G)=>{d.length=J+G-d.offset,d=d.parent,y(J+G)},"onArrayEnd"),onLiteralValue:t((J,G,Se,de,ae)=>{x({type:Hsr(J),offset:G,length:Se,line:de+1,column:ae+1,parent:d,value:J}),y(G+Se)},"onLiteralValue"),onSeparator:t((J,G)=>{d.type==="property"&&(J===":"?d.colonOffset=G:J===","&&y(G))},"onSeparator"),onError:t((J,G,Se,de,ae)=>{s.push({error:J,offset:G,length:Se,line:de+1,column:ae+1})},"onError")},f);let F=d.children?.[0];return F&&delete F.parent,F}t(SH,"parse");function Hsr(o){switch(typeof o){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(o){if(Array.isArray(o))return"array"}else return"null";return"object"}default:return"null"}}t(Hsr,"getNodeType");function bNe(o,s){return $sr(o,s)}t(bNe,"findNodeAtLocation");function TH(o){return Jsr(o)}t(TH,"getNodeValue");function Act(o){return Wsr(o)}t(Act,"printParseErrorCode");var xH=class{static{t(this,"AstAdapter")}parse(s){let d=SH(s,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(s){return this.parseNode(s,void 0)}parseNode(s,f){switch(s.type){case"object":return this.createObject(s,f);case"array":return this.createArray(s,f);case"property":return this.createProperty(s,f);case"string":return this.createLiteral(s,f);case"number":return this.createLiteral(s,f);case"boolean":return this.createLiteral(s,f);case"null":return this.createLiteral(s,f)}}createLiteral(s,f){return{type:Ko.Literal,location:{line:s.line,column:s.column},parent:f,value:s.type==="null"?null:s.value}}createObject(s,f){let d={type:Ko.Object,children:[],parent:f,location:{line:s.line,column:s.column}};return s.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(s,f){QP(s.children?.length===2,"Invalid property node");let d={type:Ko.Property,location:{line:s.line,column:s.column},parent:f,name:null,value:null};return d.name={value:s.children[0].value,location:{line:s.line,column:s.column},type:Ko.Identifier,parent:d},d.value=this.parseNode(s.children[1],d),d}createArray(s,f){let d={type:Ko.Array,location:{line:s.line,column:s.column},parent:f,children:[]};return s.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var dT={createLiteral:t((o,s)=>({type:Ko.Literal,parent:s,value:o}),"createLiteral"),createTemplateString:t((o,s)=>({type:Ko.TemplateString,parent:s,value:o}),"createTemplateString"),createIdentifier:t((o,s)=>({type:Ko.Identifier,value:o,parent:s}),"createIdentifier"),createProperty:t((o,s,f)=>{let d={type:Ko.Property,parent:f,name:null,value:s};return d.name={value:o,type:Ko.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((o,s)=>{let f={type:Ko.Array,parent:s,children:[]};for(let d of o)f.children.push(dT.createLiteral(d,f));return f},"createArrayOfLiterals")};var Gsr=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,EH=class{static{t(this,"SourceGenerator")}generate(s){let f=[];return this.generateSource(f,s),f.join("")}generateSource(s,f){switch(f.type){case Ko.Array:return this.generateArray(s,f);case Ko.Object:return this.generateObject(s,f);case Ko.Property:return this.generateProperty(s,f);case Ko.Literal:return this.generateLiteral(s,f);case Ko.FunctionCall:return this.generateFunctionCall(s,f);case Ko.Identifier:return this.generateIdentifier(s,f);case Ko.Raw:return this.generateRaw(s,f);case Ko.TemplateString:return this.generateTemplateString(s,f)}}generateArray(s,f){s.push("["),f.children.map(d=>{this.generateSource(s,d),s.push(",")}),s.push("]")}generateObject(s,f){s.push("{"),f.children.forEach(d=>{this.generateSource(s,d),s.push(",")}),s.push("}")}generateProperty(s,f){this.generateIdentifier(s,f.name),s.push(":"),this.generateSource(s,f.value)}generateFunctionCall(s,f){s.push(f.name.value),s.push("("),f.children.forEach((d,y,x)=>{this.generateSource(s,d),y<x.length&&s.push(",")}),s.push(")")}generateRaw(s,f){s.push(f.value)}generateTemplateString(s,f){s.push("`"),s.push(f.value.replaceAll("`","\\`")),s.push("`")}generateLiteral(s,f){if(f.value===null)return s.push("null");switch(typeof f.value){case"number":case"boolean":return s.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return s.push(`${y}`)}}}generateIdentifier(s,f){let d=Gsr.test(f.value)?f.value:`'${f.value}'`;s.push(d)}};import Ysr from"node:fs/promises";import{parse as Ksr}from"@swc/core";var Nct=t(async o=>{let s=new Set;try{let f=await Ysr.readFile(o,"utf-8");(await Ksr(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?s.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?s.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&s.add(y.declaration.declarations[0].id.value)})}catch{return null}return s},"getJSFileExports");var Ict={$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 SNe={$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 Oct={$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 TNe={$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 xNe={$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 Bft=Dp(lft(),1),Uft=Dp(Mle(),1);var jle=class o{static{t(this,"JsonValidator")}static#e=new o;static get instance(){return o.#e}ajv;constructor(){this.ajv=new Uft.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Bft.default)(this.ajv,{mode:"fast"})}addSchema(s,f){this.ajv.addSchema(s,f)}compile(s){let f=this.ajv.compile(s);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(s,f){let d=[];return s?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let x={details:{}},P=y.instancePath.split("/");if(P.length>2){let J=P[1],G=P[2]?parseInt(P[2],10):0,Se=P[3],de=Number.isNaN(G)?void 0:f[J][G][Se];x={details:{property:J,index:G,field:Se,fieldValue:de}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let J=y.instancePath.split("/"),G=J[J.length-1];y.message=`Value of property '${G}' must be '${y.params.type}'`}let F=Object.assign(y,x);d.push(F)}),d}};var SI=jle.instance;SI.addSchema(xNe,"route-configuration.schema.json");SI.addSchema(Oct,"policy-configuration.schema.json");SI.addSchema(SNe,"policies.schema.json");SI.addSchema(TNe,"open-api-route-configuration.schema.json");SI.addSchema(Ict,"fragments.schema.json");var WIr=SI.compile(xNe),zft=SI.compile(TNe),j4e=SI.compile(SNe);var Ble=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(s){return this.results=j4e(s),this.results}};var Ule=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(s){return this.results=zft(s),this.results}};import apr from"node:path";var B4e=/\$import\((.*)\)/,zle=/\$env\((.*?)\)/g;var sA=class extends Error{static{t(this,"CodeGenError")}location;constructor(s,f,d,y){super(s),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},spr=t(o=>{let s=[],f=o;for(;f.parent;)s.push(f),f=f.parent;return s.reverse()},"invertTree"),TI=t((o,s)=>{if(!o)return!1;let f=spr(o);return s.split("/").every((x,P)=>{let F=f[P];return F?x==="*"||eA(F)&&F.name.value===x?!0:x==="{}"?F.type===Ko.Object:x==="[]"?F.type===Ko.Array:!1:!1})},"testPosition");var $le=class{static{t(this,"AstTransformer")}errors=[];transform(s){return this.visitor(s),s}visitor(s){this.visit(s),bM(s)?s.children.forEach(f=>{this.visitor(f)}):Pct(s)?s.children.forEach(f=>{this.visitor(f)}):eA(s)&&this.visitor(s.value)}},$ft=t((o,s,f)=>d=>{if(!eA(d)||!SM(d.value)||typeof d.value.value!="string")return;if(!o.some(x=>TI(d,x))){zle.test(d.value.value)&&s.push(new sA("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=new RegExp(zle).exec(d.value.value);if(y?.length===2&&y[0]===d.value.value){let x={type:Ko.Raw,parent:null,value:`environment["${y[1]}"]`};d.value=x}else{let x=d.value.value.replaceAll(new RegExp(zle),(P,F)=>`\${environment["${F}"] ? environment["${F}"] : ""}`);x!==d.value.value&&(d.value=dT.createTemplateString(x,d))}},"getEnvStatementTransformer");var tG="config/routes.json",opr=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*","corsPolicies/[]/{}/*"],cpr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Jft=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],lpr="handler/{}/options/{}/rewritePattern",upr="handler/{}/options/{}/baseUrl",Jle=class extends $le{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(s){this.addedImports.has(s)||this.addedImports.set(s,`__import${this.importCount++}`);let f=this.addedImports.get(s);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let s=[];return this.addedImports.forEach((f,d)=>{s.push({name:f,path:d})}),s}visit(s){this.rewriteHandlerFunction(s),this.rewriteForwardFunction(s),this.replaceImportStatements(s),this.replaceEnvStatements(s)}rewriteHandlerFunction(s){if(!(!eA(s)||!SM(s.value)||typeof s.value.value!="string")&&TI(s,lpr)){if(!s.parent||!bM(s.parent)){this.errors.push(new sA("Invalid node, expected object",tG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Wft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}rewriteForwardFunction(s){if(!(!eA(s)||!SM(s.value)||typeof s.value.value!="string")&&TI(s,upr)){if(!s.parent||!bM(s.parent)){this.errors.push(new sA("Invalid node, expected object",tG,s.parent?s.parent.location:s.location,void 0));return}let f=s.value.value,d={type:Ko.Raw,parent:null,value:Wft(f)},y=dT.createProperty("__rewriteFunction",d,s);s.parent.children.push(y)}}replaceImportStatements(s){if(!eA(s)||!SM(s.value))return;let f=s.value.value;if(typeof f!="string")return;if(!cpr.some(F=>TI(s,F))&&!Jft.some(F=>TI(s,F))){if(B4e.test(f)){if(s.name.value==="$ref")return;this.errors.push(new sA("An $import() statement is not expected at this location.",tG,s.location,f))}return}let d=B4e.exec(f);if(Jft.some(F=>TI(s,F))&&!d)return;if(!d){this.errors.push(new sA("Invalid $import() statement",tG,s.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=apr.posix.join("..",y));let x=this.getImportName(y),P={type:Ko.Identifier,parent:s.parent,value:x};s.value=P}replaceEnvStatements=$ft(opr,this.errors,tG)};function Wft(o){return`(request, context) => {
|
|
576
576
|
const { params, url, query, method, headers } = request;
|
|
577
577
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
578
578
|
const e = encodeURIComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/core",
|
|
3
|
-
"version": "6.63.
|
|
3
|
+
"version": "6.63.4",
|
|
4
4
|
"repository": "https://github.com/zuplo/zuplo",
|
|
5
5
|
"author": "Zuplo, Inc.",
|
|
6
6
|
"type": "module",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"source-map": "^0.7.4"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@zuplo/graphql": "6.63.
|
|
44
|
-
"@zuplo/otel": "6.63.
|
|
45
|
-
"@zuplo/runtime": "6.63.
|
|
43
|
+
"@zuplo/graphql": "6.63.4",
|
|
44
|
+
"@zuplo/otel": "6.63.4",
|
|
45
|
+
"@zuplo/runtime": "6.63.4",
|
|
46
46
|
"deno": "2.3.1"
|
|
47
47
|
}
|
|
48
48
|
}
|