
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Zuplo, Inc. All rights reserved.
 *
 *  This software and associated documentation files (the "Software") is intended to be used
 *  only by Zuplo customers solely to develop and test applications that will be deployed
 *  to Zuplo hosted services. You and others in your organization may use these files on your
 *  Development Devices solely for the above stated purpose.
 *
 *  Outside of uses stated above, no license is granted for any other purpose including
 *  without limitation the rights to use, copy, modify, merge, publish, distribute,
 *  sublicense, host, and/or sell copies of the Software.
 *
 *  The software may include third party components with separate legal notices or governed by
 *  other agreements, as described in licenses either embedded in or accompanying the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 *  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 *  PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
 *  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 *  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 *  DEALINGS IN THE SOFTWARE.
 *--------------------------------------------------------------------------------------------*/
    
var ge=Object.create;var P=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var r=(e,t)=>P(e,"name",{value:t,configurable:!0});var dt=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(i){throw n=[i],i}};var gt=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(n){throw t=0,n}},_t=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},j=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ee(t))!me.call(e,o)&&o!==n&&P(e,o,{get:()=>t[o],enumerable:!(i=_e(t,o))||i.enumerable});return e};var Et=(e,t,n)=>(n=e!=null?ge(he(e)):{},j(t||!e||!e.__esModule?P(n,"default",{value:e,enumerable:!0}):n,e)),ht=e=>j(P({},"__esModule",{value:!0}),e);var Rt="zuplo-request-id",Re="zp-rid",Oe="zp-body-removed",ye="cf-ray",Ot="x-forwarded-scheme",yt="x-forwarded-proto",bt="x-scheme",be="cf-ipcity",Ae="cf-ipcontinent",Te="cf-ipcountry",xe="cf-iplongitude",Le="cf-iplatitude",At="cf-region",Tt="cf-region-code",xt="cf-metro-code",Lt="cf-postal-code",St="cf-timezone",Pt="zp-ipcity",It="zp-ipcontinent",Ct="zp-ipcountry",Ut="zp-iplongitude",wt="zp-iplatitude",Se="zp-client-cert",Pe="zp-mtls-status",Ie="zp-mtls-failure-reason",Ce="zp-mtls-cert-fingerprint-sha256",Ue="zp-mtls-cert-not-before",we="zp-mtls-cert-not-after",Ne="zp-mtls-cert-issuer-dn",De="zp-mtls-cert-subject-dn",He="zp-asn",Me="zp-asorg",ve="zp-colo",ze="zp-postalcode",Fe="zp-metrocode",Ze="zp-region",$e="zp-regioncode",ke="zp-timezone",Nt="zp-http-protocol",N="zp-local-service",Ge="x-akamai-edgescape",Dt=[Se,Pe,Ie,Ce,Ue,we,Ne,De,Ge,N],Ht=[be,Ae,Te,xe,Le,He,Me,ve,ze,Fe,Ze,$e,ke],Mt=["zp-","cf-"],vt=[Re,ye,Oe];var zt="system-logger";var q=class extends Error{static{r(this,"SystemError")}constructor(t,n){super(t,n),this.name="InternalError"}},b=class extends Error{static{r(this,"RuntimeError")}extensionMembers;constructor(t,n){typeof t=="string"?super(t,n):(super(t.message,n),this.extensionMembers=t.extensionMembers),this.name="RuntimeError"}},W=class extends b{static{r(this,"ConfigurationError")}constructor(t,n){super(t,n),this.name="ConfigurationError"}};var Be=!1;function L(e,t){return{open:`\x1B[${e.join(";")}m`,close:`\x1B[${t}m`,regexp:new RegExp(`\\x1b\\[${t}m`,"g")}}r(L,"code");function S(e,t){return Be?`${t.open}${e.replace(t.regexp,t.open)}${t.close}`:e}r(S,"run");function Ve(e){return S(e,L([31],39))}r(Ve,"red");function Ye(e){return S(e,L([32],39))}r(Ye,"green");function je(e){return S(e,L([33],39))}r(je,"yellow");function qe(e){return S(e,L([34],39))}r(qe,"blue");function We(e){return S(e,L([35],39))}r(We,"magenta");function Je(e){return S(e,L([36],39))}r(Je,"cyan");var kt=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 J=[Ve,Ye,je,qe,We,Je];function Ke(e){let t=0,n=e.length,i=0;if(n>0)for(;i<n;)t=(t<<5)-t+e.charCodeAt(i++)|0;return t}r(Ke,"hashCode");function K(e){let t=Math.abs(Ke(e));return J[t%J.length]}r(K,"generateColor");function X(e,t,...n){let i=0,o=n.length,u=String(t).replace(/%[sdjoO%]/g,s=>{if(s==="%%")return"%";if(i>=o)return s;switch(s){case"%s":return String(n[i++]);case"%d":return Number(n[i++]).toString();case"%o":return e(n[i++]).split(`
`).map(l=>l.trim()).join(" ");case"%O":return e(n[i++]);case"%j":try{return JSON.stringify(n[i++])}catch{return"[Circular]"}default:return s}});for(let s of n.splice(i))s===null||!(typeof s=="object"&&s!==null)?u+=" "+s:u+=" "+e(s);return u}r(X,"format");function T(e,t,n,i){let o={seen:[],stylize:Xe,showHidden:t??!1,depth:n??2,colors:i??!1,customInspect:!0};return o.colors&&(o.stylize=et),U(o,e,o.depth)}r(T,"inspect");T.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};T.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function Xe(e,t){return e}r(Xe,"stylizeNoColor");function Qe(e){return typeof e=="boolean"}r(Qe,"isBoolean");function ee(e){return e===void 0}r(ee,"isUndefined");function et(e,t){let n=T.styles[t];return n?"\x1B["+T.colors[n][0]+"m"+e+"\x1B["+T.colors[n][1]+"m":e}r(et,"stylizeWithColor");function D(e){return typeof e=="function"}r(D,"isFunction");function te(e){return typeof e=="string"}r(te,"isString");function tt(e){return typeof e=="number"}r(tt,"isNumber");function ne(e){return e===null}r(ne,"isNull");function re(e,t){return Object.hasOwn(e,t)}r(re,"hasOwn");function H(e){return F(e)&&Z(e)==="[object RegExp]"}r(H,"isRegExp");function F(e){return typeof e=="object"&&e!==null}r(F,"isObject");function M(e){return F(e)&&(Z(e)==="[object Error]"||e instanceof Error)}r(M,"isError");function Q(e){return F(e)&&Z(e)==="[object Date]"}r(Q,"isDate");function Z(e){return Object.prototype.toString.call(e)}r(Z,"objectToString");function nt(e){let t={};return e.forEach(function(n,i){t[n]=!0}),t}r(nt,"arrayToHash");function rt(e,t,n,i,o){let u=[];for(let s=0,l=t.length;s<l;++s)re(t,String(s))?u.push(z(e,t,n,i,String(s),!0)):u.push("");return o.forEach(function(s){s.match(/^\d+$/)||u.push(z(e,t,n,i,s,!0))}),u}r(rt,"formatArray");function v(e){return"["+Error.prototype.toString.call(e)+"]"}r(v,"formatError");function U(e,t,n){if(e.customInspect&&t&&D(t.inspect)&&t.inspect!==T&&!(t.constructor&&t.constructor.prototype===t)){let a=t.inspect(n,e);return te(a)||(a=U(e,a,n)),a}let i=ot(e,t);if(i)return i;let o=Object.keys(t),u=nt(o);try{e.showHidden&&Object.getOwnPropertyNames&&(o=Object.getOwnPropertyNames(t))}catch{}if(M(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return v(t);if(o.length===0){if(D(t)){let a=t.name?": "+t.name:"";return e.stylize("[Function"+a+"]","special")}if(H(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(Q(t))return e.stylize(Date.prototype.toString.call(t),"date");if(M(t))return v(t)}let s="",l=!1,f=["{","}"];if(Array.isArray(t)&&(l=!0,f=["[","]"]),D(t)&&(s=" [Function"+(t.name?": "+t.name:"")+"]"),H(t)&&(s=" "+RegExp.prototype.toString.call(t)),Q(t)&&(s=" "+Date.prototype.toUTCString.call(t)),M(t)&&(s=" "+v(t)),o.length===0&&(!l||t.length==0))return f[0]+s+f[1];if(n<0)return H(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);let c;return l?c=rt(e,t,n,u,o):c=o.map(function(a){return z(e,t,n,u,a,l)}),e.seen.pop(),it(c,s,f)}r(U,"formatValue");function z(e,t,n,i,o,u){let s,l,f;f={value:void 0};try{f.value=t[o]}catch{}try{Object.getOwnPropertyDescriptor&&(f=Object.getOwnPropertyDescriptor(t,o)||f)}catch{}if(f.get?f.set?l=e.stylize("[Getter/Setter]","special"):l=e.stylize("[Getter]","special"):f.set&&(l=e.stylize("[Setter]","special")),re(i,o)||(s="["+o+"]"),l||(e.seen.indexOf(f.value)<0?(ne(n)?l=U(e,f.value,null):l=U(e,f.value,n-1),l.indexOf(`
`)>-1&&(u?l=l.split(`
`).map(function(c){return"  "+c}).join(`
`).substr(2):l=`
`+l.split(`
`).map(function(c){return"   "+c}).join(`
`))):l=e.stylize("[Circular]","special")),ee(s)){if(u&&o.match(/^\d+$/))return l;s=JSON.stringify(""+o),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+l}r(z,"formatProperty");function ot(e,t){if(ee(t))return e.stylize("undefined","undefined");if(te(t)){let n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}if(tt(t))return e.stylize(""+t,"number");if(Qe(t))return e.stylize(""+t,"boolean");if(ne(t))return e.stylize("null","null")}r(ot,"formatPrimitive");function it(e,t,n){let i=0;return e.reduce(function(u,s){return i++,s.indexOf(`
`)>=0&&i++,u+s.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60?n[0]+(t===""?"":t+`
 `)+" "+e.join(`,
  `)+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}r(it,"reduceToSingleString");var oe=r((e,...t)=>X(T,e,t),"format");var $=class{static{r(this,"Debugger")}manager;ns;color;last;enabled;constructor(t,n){this.manager=t,this.ns=n,this.color=K(n),this.last=0,this.enabled=t.enabled.some(i=>i.test(n))}log(...t){if(!this.enabled)return;let n,i=t[0];typeof i=="function"?n=i():n=String(i);let o=Date.now()-(this.last||Date.now());n=oe(n,...t);let u=`${this.color(this.ns)} ${n} ${this.color(`+${o}ms`)}`;console.log(u),this.last=Date.now()}},k=class{static{r(this,"DebugManager")}debuggers;enabled;constructor(t){this.debuggers=new Map,this.enabled=t??[]}};function st(e){return!e||e.length===0?[]:(e=e.replace(/\s/g,"").replace(/\*/g,".+"),e.split(",").map(t=>new RegExp(`^${t}$`)))}r(st,"extract");var w;function ie(e){let t=globalThis.DEBUG;w||(w=new k(st(t)));let n=new $(w,e);return w.debuggers.set(e,n),Object.assign(n.log.bind(n),{self:n})}r(ie,"debug");function ct(e){if(e.length>=255)throw new TypeError("Alphabet too long");let t=new Uint8Array(256);for(let c=0;c<t.length;c++)t[c]=255;for(let c=0;c<e.length;c++){let a=e.charAt(c),h=a.charCodeAt(0);if(t[h]!==255)throw new TypeError(a+" is ambiguous");t[h]=c}let n=e.length,i=e.charAt(0),o=Math.log(n)/Math.log(256),u=Math.log(256)/Math.log(n);function s(c){if(c instanceof Uint8Array||(ArrayBuffer.isView(c)?c=new Uint8Array(c.buffer,c.byteOffset,c.byteLength):Array.isArray(c)&&(c=Uint8Array.from(c))),!(c instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(c.length===0)return"";let a=0,h=0,_=0,g=c.length;for(;_!==g&&c[_]===0;)_++,a++;let m=(g-_)*u+1>>>0,E=new Uint8Array(m);for(;_!==g;){let d=c[_],y=0;for(let A=m-1;(d!==0||y<h)&&A!==-1;A--,y++)d+=256*E[A]>>>0,E[A]=d%n>>>0,d=d/n>>>0;if(d!==0)throw new Error("Non-zero carry");h=y,_++}let p=m-h;for(;p!==m&&E[p]===0;)p++;let O=i.repeat(a);for(;p<m;++p)O+=e.charAt(E[p]);return O}r(s,"encode");function l(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;let a=0,h=0,_=0;for(;c[a]===i;)h++,a++;let g=(c.length-a)*o+1>>>0,m=new Uint8Array(g);for(;c[a];){let d=t[c.charCodeAt(a)];if(d===255)return;let y=0;for(let A=g-1;(d!==0||y<_)&&A!==-1;A--,y++)d+=n*m[A]>>>0,m[A]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");_=y,a++}let E=g-_;for(;E!==g&&m[E]===0;)E++;let p=new Uint8Array(h+(g-E)),O=h;for(;E!==g;)p[O++]=m[E++];return p}r(l,"decodeUnsafe");function f(c){let a=l(c);if(a)return a;throw new Error("Non-base"+n+" character")}return r(f,"decode"),{encode:s,decodeUnsafe:l,decode:f}}r(ct,"base");var se=ct;var ut="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",ce=se(ut);var x=ie("zuplo:runtime:external-service");function lt(){let e,{__ZUPLO_EXTERNAL_SERVICE_TOKEN:t}=R.instance.runtime;if(t&&t!=="undefined")try{let n=atob(t);e=JSON.parse(n)}catch{}return e}r(lt,"getServiceAuth");async function ue(e,t){let n=".proxy",i=".tunnel";if(typeof e=="string"){let o=new URL(e),u=o.hostname;if(u.endsWith(n)){let p=u.slice(0,-n.length),O=new URL(`http://${p}${o.pathname}${o.search}`);x(`Routing to proxy: ${O.toString()}`);let d=t??{};return I(O.toString(),d)}let s=u.endsWith(i),l=u.indexOf(".")===-1;if(!(s||l))throw new b(`Invalid service hostname suffix: ${u}. Use .proxy for proxy routing, .tunnel for explicit tunnel routing, or no suffix for default tunnel routing.`);let c=s?u.slice(0,-i.length):u,a=lt();if(!a)throw x("There is no external service auth configured for this zup."),new b("There are no external services configured for this zup.");x(`Using external service auth. ClientId: ${a.clientId})`);let h=t??{},_=new Headers(h.headers||{});_.set("CF-Access-Client-Id",a.clientId),_.set("CF-Access-Client-Secret",a.clientSecret),h.headers=_;let g;if(a.customServiceMapping?.[c])g=`https://${a.customServiceMapping[c]}`;else if(R.instance.useLegacyServiceRouting)g=`https://${c}.zuptunnel.com`;else{x("Using sha256 service routing");let p=R.instance.build;if(p.ACCOUNT_NAME&&p.PROJECT_NAME&&p.ENVIRONMENT_TYPE){let O=await at(c,p.ACCOUNT_NAME,p.PROJECT_NAME,p.ENVIRONMENT_TYPE),d=ae(p.ENVIRONMENT_TYPE),y=await G(`${p.ACCOUNT_NAME}-${p.PROJECT_NAME}-${d}`);y==="40d7ad502f5d743997999594c177184a00161a77865423511f3a1ea21eb5a5e"||y==="d05bffe8fa91a300187d2cf43e8aa4a56bd809c442ae10d1ee49af7d29a5a11"?g=`https://${O}.zuptunnel.com`:g=`https://${O}.t.zuplo.app`}else throw x("Cannot use sha256 service routing, missing build variables"),new b("Failed to generate fully qualified tunnel url.")}let m=new URL(`${g}${o.pathname}${o.search}`);x(`Calling external service: ${m.toString()}`);let E=await I(m.toString(),h);if(E.status===403&&E.headers.get("cf-access-domain")!==null)throw C.console.error("403 Forbidden when calling external service.",{clientId:a.clientId,tunnelHost:g}),new b("Could not connect to secure tunnel.");return E}else throw x("Cannot call external service with Request object"),new b("Currently, we only support fetch(<some_string>, ...).")}r(ue,"externalServiceHandler");async function le(e,t){if(typeof e=="string"){let n=new URL(e),i=n.hostname,o=t??{},u=`http://${i}.zuplo.svc.cluster.local:9000`,s=new URL(`${u}${n.pathname}${n.search}`),l=new Headers(o.headers||{});return l.set(N,i),o.headers=l,await I(s.toString(),o)}else throw new b("Currently, we only support fetch(<some_string>, ...).")}r(le,"clusterServiceHandler");async function at(e,t,n,i){let o=e.toLowerCase(),u=t.toLowerCase(),s=n.toLowerCase(),l=ae(i);x(`Hashing service name: ${u}-${o}.${u}-${s}-${l}`);let f=await G(`${u}-${o}`),c=await G(`${u}-${s}-${l}`);return`${f}.${c}`}r(at,"hashServiceName");async function G(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(u=>u.toString(16).padStart(2,"0")).join("").slice(0,-1)}r(G,"hashSegment");function ae(e){let t=e.toLowerCase();switch(t){case"production":case"preview":return t;default:return"working-copy"}}r(ae,"sanitizeEnvironmentType");var B=new Map;B.set("service:",ue);B.set("local:",le);var I=globalThis.fetch;function V(e,t){let{transformedInit:n,mtlsCertificate:i}=ft(t);if(typeof e=="string"){let o=new URL(e),u=B.get(o.protocol);return u?u(e,n):fe(e,n,i)}else return fe(e,n,i)}r(V,"internalFetch");globalThis.fetch=V;function fe(e,t,n){if(!n)return I(e,t);if(R.instance.isCloudflare){let o=R.instance.runtime[n];if(!o)throw new Error(`mTLS certificate binding '${n}' not found. Ensure the certificate is uploaded and properly configured.`);if(typeof o!="object"||typeof o.fetch!="function")throw new Error(`mTLS certificate binding '${n}' is not a valid mTLS certificate binding. Make sure it's configured as an mTLS certificate, not an environment variable.`);return o.fetch(e,t)}else if(R.instance.isDeno){let i=globalThis.managedDedicatedMtlsBindings?.[n];if(!i)throw new Error(`mTLS certificate binding '${n}' not found. Ensure the certificate is uploaded and properly configured.`);if(typeof i.fetch!="function")throw new Error(`mTLS certificate binding '${n}' is not a valid mTLS certificate binding.`);return i.fetch(e,t)}else throw new Error("mTLS client certificates are not supported in this runtime environment")}r(fe,"performFetch");var ft=r(e=>{if(!e||e instanceof Request)return{transformedInit:e,mtlsCertificate:void 0};let t=e;if(!t.zuplo)return{transformedInit:e,mtlsCertificate:void 0};let n=t.zuplo.mtlsCertificate,i=e;return i.cf={cacheEverything:t.zuplo?.cacheEverything,cacheTtl:t.zuplo?.cacheTtlSeconds},delete e.zuplo,{transformedInit:e,mtlsCertificate:n}},"transformInit");var pt={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:V},C=pt;var Y="2025-02-06",pe=Object.freeze({none:{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1,chainResponseSendingHooks:!1,return501ForUnsupportedHttpMethods:!1},"2023-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!1,doNotRunHooksOnSystemRoutes:!1,removeAllVendorHeadersExceptListed:!1,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1,chainResponseSendingHooks:!1,return501ForUnsupportedHttpMethods:!1},"2024-01-15":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1,chainResponseSendingHooks:!1,return501ForUnsupportedHttpMethods:!1},"2024-03-14":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!1,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1,chainResponseSendingHooks:!1,return501ForUnsupportedHttpMethods:!1},"2024-09-02":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!1,useForwardRedirectsPropOnUrlForwardHandler:!1,chainResponseSendingHooks:!1,return501ForUnsupportedHttpMethods:!1},"2025-02-06":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!0,useForwardRedirectsPropOnUrlForwardHandler:!0,chainResponseSendingHooks:!1,return501ForUnsupportedHttpMethods:!1},"2026-03-01":{runOutboundPoliciesOnHandlerOnAllStatuses:!0,doNotRunHooksOnSystemRoutes:!0,removeAllVendorHeadersExceptListed:!0,allowCustomPorts:!0,removeLegacyLogInitialization:!0,useForwardRedirectsPropOnUrlForwardHandler:!0,chainResponseSendingHooks:!0,return501ForUnsupportedHttpMethods:!0}});function de(){return new R({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:Y,ENVIRONMENT_TYPE:"mock-environment-type",GIT_SHA:void 0,IS_LOCAL_DEVELOPMENT:!1,COMPATIBILITY_FLAGS:pe[Y]},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:"bckt_mock"}})}r(de,"getMockEnvironment");var R=class e{static{r(this,"Environment")}config;static#e;static#t=!1;static initialize(t){e.#e||(e.#e=new e(t),e.#t=!0)}static get instance(){return e.#t||(C.console.debug("Environment has not been initialized. This is okay when running tests, a mock environment will be used."),e.#e??=de()),e.#e}constructor({build:t,runtime:n}){let i;try{if(n.ZUPLO_SYSTEM_CONFIGURATIONS){let o=new TextDecoder().decode(ce.decode(n.ZUPLO_SYSTEM_CONFIGURATIONS)),u=JSON.parse(o);for(let s of Object.keys(u))n[s]||(n[s]=u[s])}if(n.__ZUPLO_CONFIG){let o=atob(n.__ZUPLO_CONFIG);i=JSON.parse(o)}}catch(o){C.console.error("Failed to parse runtime configuration",o)}this.config=i??{},this.build=t,this.runtime=n,this.instanceId=crypto.randomUUID()}build;runtime;instanceId;get deploymentName(){return this.runtime.__ZUPLO_DEPLOYMENT_NAME??this.config.deployment_name??void 0}get accountName(){return this.build.ACCOUNT_NAME??this.runtime.ZUPLO_ACCOUNT_NAME??void 0}get projectName(){return this.build.PROJECT_NAME??this.runtime.ZUPLO_PROJECT_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 t=globalThis.Deno?.version?.deno;return typeof WebSocketPair!="function"&&t}}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 t=this.runtime.__ZUPLO_RATE_LIMIT_TIMEOUT_MS,n=this.config.rate_limit_service_timeout_ms,i=t??n;if(!i)return 500;let o=Number(i);return Number.isFinite(o)&&o>0?o:500}};export{r as a,dt as b,gt as c,_t as d,Et as e,ht as f,ie as g,Rt as h,Re as i,Oe as j,ye as k,Ot as l,yt as m,bt as n,be as o,Ae as p,Te as q,xe as r,Le as s,At as t,Tt as u,xt as v,Lt as w,St as x,Pt as y,It as z,Ct as A,Ut as B,wt as C,Se as D,Pe as E,Ie as F,Ce as G,Ue as H,we as I,Ne as J,De as K,He as L,Me as M,ve as N,ze as O,Fe as P,Ze as Q,$e as R,ke as S,Nt as T,N as U,Ge as V,Dt as W,Ht as X,Mt as Y,vt as Z,zt as _,q as $,b as aa,W as ba,R as ca,C as da};
/*! For license information please see chunk-DSZS6PZJ.js.LEGAL.txt */
//# sourceMappingURL=chunk-DSZS6PZJ.js.map
