@ahmadissa/cloudworker-proxy 1.0.24 → 1.0.25

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/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";var hi=Object.create;var Qt=Object.defineProperty;var fi=Object.getOwnPropertyDescriptor;var li=Object.getOwnPropertyNames;var pi=Object.getPrototypeOf,di=Object.prototype.hasOwnProperty;var E=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var yi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of li(e))!di.call(t,i)&&i!==r&&Qt(t,i,{get:()=>e[i],enumerable:!(n=fi(e,i))||n.enumerable});return t};var C=(t,e,r)=>(r=t!=null?hi(pi(t)):{},yi(e||!t||!t.__esModule?Qt(r,"default",{value:t,enumerable:!0}):r,t));var Je=E((Tu,tr)=>{function mi({host:t=".*",path:e=".*",excludePath:r=null,method:n=[".*"],handler:i,protocol:s=".*",handlerName:o,headers:a={},data:u}){let h=[],l=[],f=t.replace(/(:([^.]+))/g,(x,O,_)=>(h.push(_),"([^.]+)")),d=e.replace(/(:([^/]+))/g,(x,O,_)=>_.slice(-1)==="*"?(l.push(_.slice(0,_.length-1)),"(.*)"):(l.push(_),"([^/]*)")),y=new RegExp(`^${f}$`,"i"),g=new RegExp(`^${d}$`,"i"),A=r?new RegExp(`^${r}$`,"i"):null,m=new RegExp(`^${n.join("|")}$`,"i"),w=new RegExp(`^${s}$`,"i");return{hostVariables:h,pathVariables:l,host:y,path:g,excludePath:A,method:m,protocol:w,handler:i,handlerName:o,headers:a,data:u}}function er(t){return[...t].reduce((e,r)=>{let n={};return n[r[0]]=r[1],{...e,...n}},{})}async function gi(t,e=1024*1024){let r=[],n=t.getReader(),i=new TextDecoder,s=0;for(;e&&s<e;){let{done:a,value:u}=await n.read();if(a)break;s+=u.byteLength,r.push(i.decode(u))}let o=r.join("");return e?o.substring(0,e):o}function wi(t){let e=new URL(t.url),r=er(e.searchParams),n=er(t.headers);n.host&&(e.hostname=n.host);let i,s;async function o(a){if(s>=a)return i.substring(0,a);let u=t.clone();return i=await gi(u.body,a),i}return{body:t.body,headers:n,host:e.host,hostname:e.hostname,href:e.href,json:async a=>JSON.parse(o(a)),method:t.method,origin:`${e.protocol}//${e.host}`,path:e.pathname,protocol:e.protocol.slice(0,-1),query:r,querystring:e.search.slice(1),search:e.search,text:async a=>t.headers.get("content-type")==="application/x-www-form-urlencoded"?decodeURIComponent(await o(a)):o(a)}}tr.exports={parseRoute:mi,parseRequest:wi}});var nr=E((Bu,rr)=>{function Ai(t,e){let r={},n=e.host.exec(t.host);e.hostVariables.forEach((s,o)=>{r[s]=n[o+1]});let i=e.path.exec(t.path);return e.pathVariables.forEach((s,o)=>{r[s]=i[o+1]}),r}function Ei(t,e){let r=!0;return Object.keys(t.headers).forEach(n=>{e.headers[n]!==t.headers[n]&&(r=!1)}),r}function Si(t,e){return t.protocol.test(e.protocol)}function bi(t,e){return t.method.test(e.method)&&t.host.test(e.host)&&t.path.test(e.path)&&Ei(t,e)&&Si(t,e)&&(!t.excludePath||!t.excludePath.test(e.path))}async function Ye(t,e){let[r,...n]=e;if(!r)return new Response("NOT_FOUND",{status:404});if(!bi(r,t.request))return Ye(t,n);t.state.handlers=t.state.handlers||[],t.state.handlers.push(r.handlerName||r.handler.name),t.params=Ai(t.request,r);try{return r.handler(t,async i=>Ye(i,n))}catch(i){throw i.route=r.handler.name,i}}rr.exports={recurseRoutes:Ye}});var sr=E((Iu,ir)=>{ir.exports={methods:{DELETE:"DELETE",GET:"GET",HEAD:"HEAD",OPTIONS:"OPTIONS",PATCH:"PATCH",POST:"POST"},statusMessages:{404:"Not found",429:"Rate limited"}}});var ur=E((xu,ar)=>{var Ci=Je();ar.exports=class or{constructor(e){this.request=Ci.parseRequest(e.request),this.event=e,this.state={},this.cloned=!1,this.response={headers:{}},this.body="",this.status=404,this.query=this.request.query}header(e){return this.request.headers[e]}set(e,r){this.response.headers[e]=r}clone(){let e=new or(this.event);return e.cloned=!0,e}}});var hr=E((Fu,cr)=>{var ie=Je(),Ti=nr(),me=sr(),Bi=ur();cr.exports=class{constructor(){this.routes=[]}get(e,r){let n=ie.parseRoute({method:[me.methods.GET,me.methods.HEAD],path:e,handler:r});this.routes.push(n)}post(e,r){let n=ie.parseRoute({method:[me.methods.POST],path:e,handler:r});this.routes.push(n)}patch(e,r){let n=ie.parseRoute({method:[me.methods.PATCH],path:e,handler:r});this.routes.push(n)}del(e,r){let n=ie.parseRoute({method:[me.methods.DELETE],path:e,handler:r});this.routes.push(n)}use(e){let r=ie.parseRoute({handler:e,middleware:!0});this.routes.push(r)}add({host:e,path:r,excludePath:n,method:i,handlerName:s,headers:o,protocol:a},u){let h=ie.parseRoute({method:i,host:e,path:r,excludePath:n,handler:u,headers:o,handlerName:s,protocol:a});this.routes.push(h)}async resolve(e){let r=new Bi(e);try{return await Ti.recurseRoutes(r,this.routes),new Response(r.body,{status:r.status,headers:r.response.headers})}catch(n){return new Response(n.message,{status:500})}}}});var H=E((_u,Cr)=>{var Ii="Expected a function",yr="__lodash_hash_undefined__",mr=1/0,xi="[object Function]",Ui="[object GeneratorFunction]",Fi="[object Symbol]",_i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ri=/^\w*$/,Oi=/^\./,ki=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ni=/[\\^$.*+?()[\]{}|]/g,Pi=/\\(\\)?/g,$i=/^\[object .+?Constructor\]$/,vi=typeof global=="object"&&global&&global.Object===Object&&global,qi=typeof self=="object"&&self&&self.Object===Object&&self,Qe=vi||qi||Function("return this")();function Mi(t,e){return t?.[e]}function Hi(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}var Di=Array.prototype,Li=Function.prototype,gr=Object.prototype,Ze=Qe["__core-js_shared__"],fr=function(){var t=/[^.]+$/.exec(Ze&&Ze.keys&&Ze.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),wr=Li.toString,et=gr.hasOwnProperty,Ar=gr.toString,ji=RegExp("^"+wr.call(et).replace(Ni,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),lr=Qe.Symbol,Ki=Di.splice,Gi=Er(Qe,"Map"),ge=Er(Object,"create"),pr=lr?lr.prototype:void 0,dr=pr?pr.toString:void 0;function V(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function zi(){this.__data__=ge?ge(null):{}}function Wi(t){return this.has(t)&&delete this.__data__[t]}function Vi(t){var e=this.__data__;if(ge){var r=e[t];return r===yr?void 0:r}return et.call(e,t)?e[t]:void 0}function Xi(t){var e=this.__data__;return ge?e[t]!==void 0:et.call(e,t)}function Ji(t,e){var r=this.__data__;return r[t]=ge&&e===void 0?yr:e,this}V.prototype.clear=zi;V.prototype.delete=Wi;V.prototype.get=Vi;V.prototype.has=Xi;V.prototype.set=Ji;function se(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Yi(){this.__data__=[]}function Zi(t){var e=this.__data__,r=Ue(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():Ki.call(e,r,1),!0}function Qi(t){var e=this.__data__,r=Ue(e,t);return r<0?void 0:e[r][1]}function es(t){return Ue(this.__data__,t)>-1}function ts(t,e){var r=this.__data__,n=Ue(r,t);return n<0?r.push([t,e]):r[n][1]=e,this}se.prototype.clear=Yi;se.prototype.delete=Zi;se.prototype.get=Qi;se.prototype.has=es;se.prototype.set=ts;function X(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function rs(){this.__data__={hash:new V,map:new(Gi||se),string:new V}}function ns(t){return Fe(this,t).delete(t)}function is(t){return Fe(this,t).get(t)}function ss(t){return Fe(this,t).has(t)}function os(t,e){return Fe(this,t).set(t,e),this}X.prototype.clear=rs;X.prototype.delete=ns;X.prototype.get=is;X.prototype.has=ss;X.prototype.set=os;function Ue(t,e){for(var r=t.length;r--;)if(gs(t[r][0],e))return r;return-1}function as(t,e){e=fs(e,t)?[e]:hs(e);for(var r=0,n=e.length;t!=null&&r<n;)t=t[ys(e[r++])];return r&&r==n?t:void 0}function us(t){if(!br(t)||ps(t))return!1;var e=ws(t)||Hi(t)?ji:$i;return e.test(ms(t))}function cs(t){if(typeof t=="string")return t;if(rt(t))return dr?dr.call(t):"";var e=t+"";return e=="0"&&1/t==-mr?"-0":e}function hs(t){return Sr(t)?t:ds(t)}function Fe(t,e){var r=t.__data__;return ls(e)?r[typeof e=="string"?"string":"hash"]:r.map}function Er(t,e){var r=Mi(t,e);return us(r)?r:void 0}function fs(t,e){if(Sr(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||rt(t)?!0:Ri.test(t)||!_i.test(t)||e!=null&&t in Object(e)}function ls(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function ps(t){return!!fr&&fr in t}var ds=tt(function(t){t=Es(t);var e=[];return Oi.test(t)&&e.push(""),t.replace(ki,function(r,n,i,s){e.push(i?s.replace(Pi,"$1"):n||r)}),e});function ys(t){if(typeof t=="string"||rt(t))return t;var e=t+"";return e=="0"&&1/t==-mr?"-0":e}function ms(t){if(t!=null){try{return wr.call(t)}catch{}try{return t+""}catch{}}return""}function tt(t,e){if(typeof t!="function"||e&&typeof e!="function")throw new TypeError(Ii);var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],s=r.cache;if(s.has(i))return s.get(i);var o=t.apply(this,n);return r.cache=s.set(i,o),o};return r.cache=new(tt.Cache||X),r}tt.Cache=X;function gs(t,e){return t===e||t!==t&&e!==e}var Sr=Array.isArray;function ws(t){var e=br(t)?Ar.call(t):"";return e==xi||e==Ui}function br(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function As(t){return!!t&&typeof t=="object"}function rt(t){return typeof t=="symbol"||As(t)&&Ar.call(t)==Fi}function Es(t){return t==null?"":cs(t)}function Ss(t,e,r){var n=t==null?void 0:as(t,e);return n===void 0?r:n}Cr.exports=Ss});var Re=E((_e,Fr)=>{(function(t,e){typeof _e=="object"&&typeof Fr<"u"?e(_e):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.aws4fetch={}))})(_e,function(t){"use strict";let e=new TextEncoder,r={appstream2:"appstream",cloudhsmv2:"cloudhsm",email:"ses",marketplace:"aws-marketplace",mobile:"AWSMobileHubService",pinpoint:"mobiletargeting",queue:"sqs","git-codecommit":"codecommit","mturk-requester-sandbox":"mturk-requester","personalize-runtime":"personalize"},n=["authorization","content-type","content-length","user-agent","presigned-expires","expect","x-amzn-trace-id","range","connection"];class i{constructor({accessKeyId:d,secretAccessKey:y,sessionToken:g,service:A,region:m,cache:w,retries:x,initRetryMs:O}){if(d==null)throw new TypeError("accessKeyId is a required option");if(y==null)throw new TypeError("secretAccessKey is a required option");this.accessKeyId=d,this.secretAccessKey=y,this.sessionToken=g,this.service=A,this.region=m,this.cache=w||new Map,this.retries=x??10,this.initRetryMs=O||50}async sign(d,y){if(d instanceof Request){let{method:m,url:w,headers:x,body:O}=d;y=Object.assign({method:m,url:w,headers:x},y),y.body==null&&x.has("Content-Type")&&(y.body=O!=null&&x.has("X-Amz-Content-Sha256")?O:await d.clone().arrayBuffer()),d=w}let g=new s(Object.assign({url:d},y,this,y&&y.aws)),A=Object.assign({},y,await g.sign());return delete A.aws,new Request(A.url.toString(),A)}async fetch(d,y){for(let g=0;g<=this.retries;g++){let A=fetch(await this.sign(d,y));if(g===this.retries)return A;let m=await A;if(m.status<500&&m.status!==429)return m;await new Promise(w=>setTimeout(w,Math.random()*this.initRetryMs*Math.pow(2,g)))}throw new Error("An unknown error occurred, ensure retries is not negative")}}class s{constructor({method:d,url:y,headers:g,body:A,accessKeyId:m,secretAccessKey:w,sessionToken:x,service:O,region:_,cache:z,datetime:le,signQuery:Ge,appendSessionToken:ze,allHeaders:Be,singleEncode:We}){if(y==null)throw new TypeError("url is a required option");if(m==null)throw new TypeError("accessKeyId is a required option");if(w==null)throw new TypeError("secretAccessKey is a required option");this.method=d||(A?"POST":"GET"),this.url=new URL(y),this.headers=new Headers(g||{}),this.body=A,this.accessKeyId=m,this.secretAccessKey=w,this.sessionToken=x;let j,pe;(!O||!_)&&([j,pe]=l(this.url,this.headers)),this.service=O||j||"",this.region=_||pe||"us-east-1",this.cache=z||new Map,this.datetime=le||new Date().toISOString().replace(/[:-]|\.\d{3}/g,""),this.signQuery=Ge,this.appendSessionToken=ze||this.service==="iotdevicegateway",this.headers.delete("Host");let P=this.signQuery?this.url.searchParams:this.headers;if(this.service==="s3"&&!this.headers.has("X-Amz-Content-Sha256")&&this.headers.set("X-Amz-Content-Sha256","UNSIGNED-PAYLOAD"),P.set("X-Amz-Date",this.datetime),this.sessionToken&&!this.appendSessionToken&&P.set("X-Amz-Security-Token",this.sessionToken),this.signableHeaders=["host",...this.headers.keys()].filter(S=>Be||!n.includes(S)).sort(),this.signedHeaders=this.signableHeaders.join(";"),this.canonicalHeaders=this.signableHeaders.map(S=>S+":"+(S==="host"?this.url.host:(this.headers.get(S)||"").replace(/\s+/g," "))).join(`
2
- `),this.credentialString=[this.datetime.slice(0,8),this.region,this.service,"aws4_request"].join("/"),this.signQuery&&(this.service==="s3"&&!P.has("X-Amz-Expires")&&P.set("X-Amz-Expires","86400"),P.set("X-Amz-Algorithm","AWS4-HMAC-SHA256"),P.set("X-Amz-Credential",this.accessKeyId+"/"+this.credentialString),P.set("X-Amz-SignedHeaders",this.signedHeaders)),this.service==="s3")try{this.encodedPath=decodeURIComponent(this.url.pathname.replace(/\+/g," "))}catch{this.encodedPath=this.url.pathname}else this.encodedPath=this.url.pathname.replace(/\/+/g,"/");We||(this.encodedPath=encodeURIComponent(this.encodedPath).replace(/%2F/g,"/")),this.encodedPath=h(this.encodedPath);let Ie=new Set;this.encodedSearch=[...this.url.searchParams].filter(([S])=>{if(!S)return!1;if(this.service==="s3"){if(Ie.has(S))return!1;Ie.add(S)}return!0}).map(S=>S.map(de=>h(encodeURIComponent(de)))).sort(([S,de],[ye,xe])=>S<ye?-1:S>ye?1:de<xe?-1:de>xe?1:0).map(S=>S.join("=")).join("&")}async sign(){return this.signQuery?(this.url.searchParams.set("X-Amz-Signature",await this.signature()),this.sessionToken&&this.appendSessionToken&&this.url.searchParams.set("X-Amz-Security-Token",this.sessionToken)):this.headers.set("Authorization",await this.authHeader()),{method:this.method,url:this.url,headers:this.headers,body:this.body}}async authHeader(){return["AWS4-HMAC-SHA256 Credential="+this.accessKeyId+"/"+this.credentialString,"SignedHeaders="+this.signedHeaders,"Signature="+await this.signature()].join(", ")}async signature(){let d=this.datetime.slice(0,8),y=[this.secretAccessKey,d,this.region,this.service].join(),g=this.cache.get(y);if(!g){let A=await o("AWS4"+this.secretAccessKey,d),m=await o(A,this.region),w=await o(m,this.service);g=await o(w,"aws4_request"),this.cache.set(y,g)}return u(await o(g,await this.stringToSign()))}async stringToSign(){return["AWS4-HMAC-SHA256",this.datetime,this.credentialString,u(await a(await this.canonicalString()))].join(`
1
+ "use strict";var wo=Object.create;var fr=Object.defineProperty;var Ao=Object.getOwnPropertyDescriptor;var So=Object.getOwnPropertyNames;var Eo=Object.getPrototypeOf,bo=Object.prototype.hasOwnProperty;var _=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Co=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of So(t))!bo.call(e,o)&&o!==r&&fr(e,o,{get:()=>t[o],enumerable:!(n=Ao(t,o))||n.enumerable});return e};var v=(e,t,r)=>(r=e!=null?wo(Eo(e)):{},Co(t||!e||!e.__esModule?fr(r,"default",{value:e,enumerable:!0}):r,e));var ht=_((Fc,mr)=>{function _o({host:e=".*",path:t=".*",excludePath:r=null,method:n=[".*"],handler:o,protocol:a=".*",handlerName:s,headers:i={},data:c}){let d=[],h=[],u=e.replace(/(:([^.]+))/g,(K,k,U)=>(d.push(U),"([^.]+)")),l=t.replace(/(:([^/]+))/g,(K,k,U)=>U.slice(-1)==="*"?(h.push(U.slice(0,U.length-1)),"(.*)"):(h.push(U),"([^/]*)")),f=new RegExp(`^${u}$`,"i"),y=new RegExp(`^${l}$`,"i"),w=r?new RegExp(`^${r}$`,"i"):null,m=new RegExp(`^${n.join("|")}$`,"i"),g=new RegExp(`^${a}$`,"i");return{hostVariables:d,pathVariables:h,host:f,path:y,excludePath:w,method:m,protocol:g,handler:o,handlerName:s,headers:i,data:c}}function lr(e){return[...e].reduce((t,r)=>{let n={};return n[r[0]]=r[1],{...t,...n}},{})}async function vo(e,t=1024*1024){let r=[],n=e.getReader(),o=new TextDecoder,a=0;for(;t&&a<t;){let{done:i,value:c}=await n.read();if(i)break;a+=c.byteLength,r.push(o.decode(c))}let s=r.join("");return t?s.substring(0,t):s}function Ho(e){let t=new URL(e.url),r=lr(t.searchParams),n=lr(e.headers);n.host&&(t.hostname=n.host);let o,a;async function s(i){if(a>=i)return o.substring(0,i);let c=e.clone();return o=await vo(c.body,i),o}return{body:e.body,headers:n,host:t.host,hostname:t.hostname,href:t.href,json:async i=>JSON.parse(s(i)),method:e.method,origin:`${t.protocol}//${t.host}`,path:t.pathname,protocol:t.protocol.slice(0,-1),query:r,querystring:t.search.slice(1),search:t.search,text:async i=>e.headers.get("content-type")==="application/x-www-form-urlencoded"?decodeURIComponent(await s(i)):s(i)}}mr.exports={parseRoute:_o,parseRequest:Ho}});var gr=_((Lc,yr)=>{function Po(e,t){let r={},n=t.host.exec(e.host);t.hostVariables.forEach((a,s)=>{r[a]=n[s+1]});let o=t.path.exec(e.path);return t.pathVariables.forEach((a,s)=>{r[a]=o[s+1]}),r}function Ko(e,t){let r=!0;return Object.keys(e.headers).forEach(n=>{t.headers[n]!==e.headers[n]&&(r=!1)}),r}function To(e,t){return e.protocol.test(t.protocol)}function xo(e,t){return e.method.test(t.method)&&e.host.test(t.host)&&e.path.test(t.path)&&Ko(e,t)&&To(e,t)&&(!e.excludePath||!e.excludePath.test(t.path))}async function ft(e,t){let[r,...n]=t;if(!r)return new Response("NOT_FOUND",{status:404});if(!xo(r,e.request))return ft(e,n);e.state.handlers=e.state.handlers||[],e.state.handlers.push(r.handlerName||r.handler.name),e.params=Po(e.request,r);try{return r.handler(e,async o=>ft(o,n))}catch(o){throw o.route=r.handler.name,o}}yr.exports={recurseRoutes:ft}});var Ar=_((Bc,wr)=>{wr.exports={methods:{DELETE:"DELETE",GET:"GET",HEAD:"HEAD",OPTIONS:"OPTIONS",PATCH:"PATCH",POST:"POST"},statusMessages:{404:"Not found",429:"Rate limited"}}});var br=_((Gc,Er)=>{var Oo=ht();Er.exports=class Sr{constructor(t){this.request=Oo.parseRequest(t.request),this.event=t,this.state={},this.cloned=!1,this.response={headers:{}},this.body="",this.status=404,this.query=this.request.query}header(t){return this.request.headers[t]}set(t,r){this.response.headers[t]=r}clone(){let t=new Sr(this.event);return t.cloned=!0,t}}});var _r=_((zc,Cr)=>{var ue=ht(),Ro=gr(),_e=Ar(),Uo=br();Cr.exports=class{constructor(){this.routes=[]}get(t,r){let n=ue.parseRoute({method:[_e.methods.GET,_e.methods.HEAD],path:t,handler:r});this.routes.push(n)}post(t,r){let n=ue.parseRoute({method:[_e.methods.POST],path:t,handler:r});this.routes.push(n)}patch(t,r){let n=ue.parseRoute({method:[_e.methods.PATCH],path:t,handler:r});this.routes.push(n)}del(t,r){let n=ue.parseRoute({method:[_e.methods.DELETE],path:t,handler:r});this.routes.push(n)}use(t){let r=ue.parseRoute({handler:t,middleware:!0});this.routes.push(r)}add({host:t,path:r,excludePath:n,method:o,handlerName:a,headers:s,protocol:i},c){let d=ue.parseRoute({method:o,host:t,path:r,excludePath:n,handler:c,headers:s,handlerName:a,protocol:i});this.routes.push(d)}async resolve(t){let r=new Uo(t);try{return await Ro.recurseRoutes(r,this.routes),new Response(r.body,{status:r.status,headers:r.response.headers})}catch(n){return new Response(n.message,{status:500})}}}});var M=_((Xc,Nr)=>{var Io="Expected a function",Tr="__lodash_hash_undefined__",xr=1/0,Wo="[object Function]",Jo="[object GeneratorFunction]",No="[object Symbol]",ko=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Do=/^\w*$/,Mo=/^\./,$o=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,qo=/[\\^$.*+?()[\]{}|]/g,Fo=/\\(\\)?/g,Lo=/^\[object .+?Constructor\]$/,Bo=typeof global=="object"&&global&&global.Object===Object&&global,Go=typeof self=="object"&&self&&self.Object===Object&&self,mt=Bo||Go||Function("return this")();function Vo(e,t){return e?.[t]}function zo(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch{}return t}var Xo=Array.prototype,jo=Function.prototype,Or=Object.prototype,lt=mt["__core-js_shared__"],vr=function(){var e=/[^.]+$/.exec(lt&&lt.keys&&lt.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Rr=jo.toString,yt=Or.hasOwnProperty,Ur=Or.toString,Yo=RegExp("^"+Rr.call(yt).replace(qo,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Hr=mt.Symbol,Zo=Xo.splice,Qo=Ir(mt,"Map"),ve=Ir(Object,"create"),Pr=Hr?Hr.prototype:void 0,Kr=Pr?Pr.toString:void 0;function re(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function ea(){this.__data__=ve?ve(null):{}}function ta(e){return this.has(e)&&delete this.__data__[e]}function ra(e){var t=this.__data__;if(ve){var r=t[e];return r===Tr?void 0:r}return yt.call(t,e)?t[e]:void 0}function na(e){var t=this.__data__;return ve?t[e]!==void 0:yt.call(t,e)}function oa(e,t){var r=this.__data__;return r[e]=ve&&t===void 0?Tr:t,this}re.prototype.clear=ea;re.prototype.delete=ta;re.prototype.get=ra;re.prototype.has=na;re.prototype.set=oa;function pe(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function aa(){this.__data__=[]}function sa(e){var t=this.__data__,r=Me(t,e);if(r<0)return!1;var n=t.length-1;return r==n?t.pop():Zo.call(t,r,1),!0}function ia(e){var t=this.__data__,r=Me(t,e);return r<0?void 0:t[r][1]}function ca(e){return Me(this.__data__,e)>-1}function da(e,t){var r=this.__data__,n=Me(r,e);return n<0?r.push([e,t]):r[n][1]=t,this}pe.prototype.clear=aa;pe.prototype.delete=sa;pe.prototype.get=ia;pe.prototype.has=ca;pe.prototype.set=da;function ne(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function ua(){this.__data__={hash:new re,map:new(Qo||pe),string:new re}}function pa(e){return $e(this,e).delete(e)}function ha(e){return $e(this,e).get(e)}function fa(e){return $e(this,e).has(e)}function la(e,t){return $e(this,e).set(e,t),this}ne.prototype.clear=ua;ne.prototype.delete=pa;ne.prototype.get=ha;ne.prototype.has=fa;ne.prototype.set=la;function Me(e,t){for(var r=e.length;r--;)if(va(e[r][0],t))return r;return-1}function ma(e,t){t=Aa(t,e)?[t]:wa(t);for(var r=0,n=t.length;e!=null&&r<n;)e=e[Ca(t[r++])];return r&&r==n?e:void 0}function ya(e){if(!Jr(e)||Ea(e))return!1;var t=Ha(e)||zo(e)?Yo:Lo;return t.test(_a(e))}function ga(e){if(typeof e=="string")return e;if(wt(e))return Kr?Kr.call(e):"";var t=e+"";return t=="0"&&1/e==-xr?"-0":t}function wa(e){return Wr(e)?e:ba(e)}function $e(e,t){var r=e.__data__;return Sa(t)?r[typeof t=="string"?"string":"hash"]:r.map}function Ir(e,t){var r=Vo(e,t);return ya(r)?r:void 0}function Aa(e,t){if(Wr(e))return!1;var r=typeof e;return r=="number"||r=="symbol"||r=="boolean"||e==null||wt(e)?!0:Do.test(e)||!ko.test(e)||t!=null&&e in Object(t)}function Sa(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Ea(e){return!!vr&&vr in e}var ba=gt(function(e){e=Ka(e);var t=[];return Mo.test(e)&&t.push(""),e.replace($o,function(r,n,o,a){t.push(o?a.replace(Fo,"$1"):n||r)}),t});function Ca(e){if(typeof e=="string"||wt(e))return e;var t=e+"";return t=="0"&&1/e==-xr?"-0":t}function _a(e){if(e!=null){try{return Rr.call(e)}catch{}try{return e+""}catch{}}return""}function gt(e,t){if(typeof e!="function"||t&&typeof t!="function")throw new TypeError(Io);var r=function(){var n=arguments,o=t?t.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var s=e.apply(this,n);return r.cache=a.set(o,s),s};return r.cache=new(gt.Cache||ne),r}gt.Cache=ne;function va(e,t){return e===t||e!==e&&t!==t}var Wr=Array.isArray;function Ha(e){var t=Jr(e)?Ur.call(e):"";return t==Wo||t==Jo}function Jr(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Pa(e){return!!e&&typeof e=="object"}function wt(e){return typeof e=="symbol"||Pa(e)&&Ur.call(e)==No}function Ka(e){return e==null?"":ga(e)}function Ta(e,t,r){var n=e==null?void 0:ma(e,t);return n===void 0?r:n}Nr.exports=Ta});var Fe=_((qe,Fr)=>{(function(e,t){typeof qe=="object"&&typeof Fr<"u"?t(qe):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.aws4fetch={}))})(qe,function(e){"use strict";let t=new TextEncoder,r={appstream2:"appstream",cloudhsmv2:"cloudhsm",email:"ses",marketplace:"aws-marketplace",mobile:"AWSMobileHubService",pinpoint:"mobiletargeting",queue:"sqs","git-codecommit":"codecommit","mturk-requester-sandbox":"mturk-requester","personalize-runtime":"personalize"},n=["authorization","content-type","content-length","user-agent","presigned-expires","expect","x-amzn-trace-id","range","connection"];class o{constructor({accessKeyId:l,secretAccessKey:f,sessionToken:y,service:w,region:m,cache:g,retries:K,initRetryMs:k}){if(l==null)throw new TypeError("accessKeyId is a required option");if(f==null)throw new TypeError("secretAccessKey is a required option");this.accessKeyId=l,this.secretAccessKey=f,this.sessionToken=y,this.service=w,this.region=m,this.cache=g||new Map,this.retries=K??10,this.initRetryMs=k||50}async sign(l,f){if(l instanceof Request){let{method:m,url:g,headers:K,body:k}=l;f=Object.assign({method:m,url:g,headers:K},f),f.body==null&&K.has("Content-Type")&&(f.body=k!=null&&K.has("X-Amz-Content-Sha256")?k:await l.clone().arrayBuffer()),l=g}let y=new a(Object.assign({url:l},f,this,f&&f.aws)),w=Object.assign({},f,await y.sign());return delete w.aws,new Request(w.url.toString(),w)}async fetch(l,f){for(let y=0;y<=this.retries;y++){let w=fetch(await this.sign(l,f));if(y===this.retries)return w;let m=await w;if(m.status<500&&m.status!==429)return m;await new Promise(g=>setTimeout(g,Math.random()*this.initRetryMs*Math.pow(2,y)))}throw new Error("An unknown error occurred, ensure retries is not negative")}}class a{constructor({method:l,url:f,headers:y,body:w,accessKeyId:m,secretAccessKey:g,sessionToken:K,service:k,region:U,cache:ee,datetime:Se,signQuery:it,appendSessionToken:ct,allHeaders:Ne,singleEncode:dt}){if(f==null)throw new TypeError("url is a required option");if(m==null)throw new TypeError("accessKeyId is a required option");if(g==null)throw new TypeError("secretAccessKey is a required option");this.method=l||(w?"POST":"GET"),this.url=new URL(f),this.headers=new Headers(y||{}),this.body=w,this.accessKeyId=m,this.secretAccessKey=g,this.sessionToken=K;let V,Ee;(!k||!U)&&([V,Ee]=h(this.url,this.headers)),this.service=k||V||"",this.region=U||Ee||"us-east-1",this.cache=ee||new Map,this.datetime=Se||new Date().toISOString().replace(/[:-]|\.\d{3}/g,""),this.signQuery=it,this.appendSessionToken=ct||this.service==="iotdevicegateway",this.headers.delete("Host");let q=this.signQuery?this.url.searchParams:this.headers;if(this.service==="s3"&&!this.headers.has("X-Amz-Content-Sha256")&&this.headers.set("X-Amz-Content-Sha256","UNSIGNED-PAYLOAD"),q.set("X-Amz-Date",this.datetime),this.sessionToken&&!this.appendSessionToken&&q.set("X-Amz-Security-Token",this.sessionToken),this.signableHeaders=["host",...this.headers.keys()].filter(C=>Ne||!n.includes(C)).sort(),this.signedHeaders=this.signableHeaders.join(";"),this.canonicalHeaders=this.signableHeaders.map(C=>C+":"+(C==="host"?this.url.host:(this.headers.get(C)||"").replace(/\s+/g," "))).join(`
2
+ `),this.credentialString=[this.datetime.slice(0,8),this.region,this.service,"aws4_request"].join("/"),this.signQuery&&(this.service==="s3"&&!q.has("X-Amz-Expires")&&q.set("X-Amz-Expires","86400"),q.set("X-Amz-Algorithm","AWS4-HMAC-SHA256"),q.set("X-Amz-Credential",this.accessKeyId+"/"+this.credentialString),q.set("X-Amz-SignedHeaders",this.signedHeaders)),this.service==="s3")try{this.encodedPath=decodeURIComponent(this.url.pathname.replace(/\+/g," "))}catch{this.encodedPath=this.url.pathname}else this.encodedPath=this.url.pathname.replace(/\/+/g,"/");dt||(this.encodedPath=encodeURIComponent(this.encodedPath).replace(/%2F/g,"/")),this.encodedPath=d(this.encodedPath);let ke=new Set;this.encodedSearch=[...this.url.searchParams].filter(([C])=>{if(!C)return!1;if(this.service==="s3"){if(ke.has(C))return!1;ke.add(C)}return!0}).map(C=>C.map(be=>d(encodeURIComponent(be)))).sort(([C,be],[Ce,De])=>C<Ce?-1:C>Ce?1:be<De?-1:be>De?1:0).map(C=>C.join("=")).join("&")}async sign(){return this.signQuery?(this.url.searchParams.set("X-Amz-Signature",await this.signature()),this.sessionToken&&this.appendSessionToken&&this.url.searchParams.set("X-Amz-Security-Token",this.sessionToken)):this.headers.set("Authorization",await this.authHeader()),{method:this.method,url:this.url,headers:this.headers,body:this.body}}async authHeader(){return["AWS4-HMAC-SHA256 Credential="+this.accessKeyId+"/"+this.credentialString,"SignedHeaders="+this.signedHeaders,"Signature="+await this.signature()].join(", ")}async signature(){let l=this.datetime.slice(0,8),f=[this.secretAccessKey,l,this.region,this.service].join(),y=this.cache.get(f);if(!y){let w=await s("AWS4"+this.secretAccessKey,l),m=await s(w,this.region),g=await s(m,this.service);y=await s(g,"aws4_request"),this.cache.set(f,y)}return c(await s(y,await this.stringToSign()))}async stringToSign(){return["AWS4-HMAC-SHA256",this.datetime,this.credentialString,c(await i(await this.canonicalString()))].join(`
3
3
  `)}async canonicalString(){return[this.method.toUpperCase(),this.encodedPath,this.encodedSearch,this.canonicalHeaders+`
4
4
  `,this.signedHeaders,await this.hexBodyHash()].join(`
5
- `)}async hexBodyHash(){let d=this.headers.get("X-Amz-Content-Sha256");if(d==null){if(this.body&&typeof this.body!="string"&&!("byteLength"in this.body))throw new Error("body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header");d=u(await a(this.body||""))}return d}}async function o(f,d){let y=await crypto.subtle.importKey("raw",typeof f=="string"?e.encode(f):f,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return crypto.subtle.sign("HMAC",y,e.encode(d))}async function a(f){return crypto.subtle.digest("SHA-256",typeof f=="string"?e.encode(f):f)}function u(f){return Array.prototype.map.call(new Uint8Array(f),d=>("0"+d.toString(16)).slice(-2)).join("")}function h(f){return f.replace(/[!'()*]/g,d=>"%"+d.charCodeAt(0).toString(16).toUpperCase())}function l(f,d){let{hostname:y,pathname:g}=f,A=y.replace("dualstack.","").match(/([^.]+)\.(?:([^.]*)\.)?amazonaws\.com(?:\.cn)?$/),[m,w]=(A||["",""]).slice(1,3);if(w==="us-gov")w="us-gov-west-1";else if(w==="s3"||w==="s3-accelerate")w="us-east-1",m="s3";else if(m==="iot")y.startsWith("iot.")?m="execute-api":y.startsWith("data.jobs.iot.")?m="iot-jobs-data":m=g==="/mqtt"?"iotdevicegateway":"iotdata";else if(m==="autoscaling"){let x=(d.get("X-Amz-Target")||"").split(".")[0];x==="AnyScaleFrontendService"?m="application-autoscaling":x==="AnyScaleScalingPlannerFrontendService"&&(m="autoscaling-plans")}else w==null&&m.startsWith("s3-")?(w=m.slice(3).replace(/^fips-|^external-1/,""),m="s3"):m.endsWith("-fips")?m=m.slice(0,-5):w&&/-\d$/.test(m)&&!/-\d$/.test(w)&&([m,w]=[w,m]);return[r[m]||m,w]}t.AwsClient=i,t.AwsV4Signer=s,Object.defineProperty(t,"__esModule",{value:!0})})});var $e=E((Qu,jr)=>{var Ls="Expected a function",Pr="__lodash_hash_undefined__",$r=1/0,js=9007199254740991,Ks="[object Function]",Gs="[object GeneratorFunction]",zs="[object Symbol]",Ws=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Vs=/^\w*$/,Xs=/^\./,Js=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ys=/[\\^$.*+?()[\]{}|]/g,Zs=/\\(\\)?/g,Qs=/^\[object .+?Constructor\]$/,eo=/^(?:0|[1-9]\d*)$/,to=typeof global=="object"&&global&&global.Object===Object&&global,ro=typeof self=="object"&&self&&self.Object===Object&&self,mt=to||ro||Function("return this")();function no(t,e){return t?.[e]}function io(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}var so=Array.prototype,oo=Function.prototype,vr=Object.prototype,yt=mt["__core-js_shared__"],Rr=function(){var t=/[^.]+$/.exec(yt&&yt.keys&&yt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),qr=oo.toString,ke=vr.hasOwnProperty,Mr=vr.toString,ao=RegExp("^"+qr.call(ke).replace(Ys,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Or=mt.Symbol,uo=so.splice,co=Hr(mt,"Map"),we=Hr(Object,"create"),kr=Or?Or.prototype:void 0,Nr=kr?kr.toString:void 0;function Y(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function ho(){this.__data__=we?we(null):{}}function fo(t){return this.has(t)&&delete this.__data__[t]}function lo(t){var e=this.__data__;if(we){var r=e[t];return r===Pr?void 0:r}return ke.call(e,t)?e[t]:void 0}function po(t){var e=this.__data__;return we?e[t]!==void 0:ke.call(e,t)}function yo(t,e){var r=this.__data__;return r[t]=we&&e===void 0?Pr:e,this}Y.prototype.clear=ho;Y.prototype.delete=fo;Y.prototype.get=lo;Y.prototype.has=po;Y.prototype.set=yo;function oe(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function mo(){this.__data__=[]}function go(t){var e=this.__data__,r=Ne(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():uo.call(e,r,1),!0}function wo(t){var e=this.__data__,r=Ne(e,t);return r<0?void 0:e[r][1]}function Ao(t){return Ne(this.__data__,t)>-1}function Eo(t,e){var r=this.__data__,n=Ne(r,t);return n<0?r.push([t,e]):r[n][1]=e,this}oe.prototype.clear=mo;oe.prototype.delete=go;oe.prototype.get=wo;oe.prototype.has=Ao;oe.prototype.set=Eo;function Z(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function So(){this.__data__={hash:new Y,map:new(co||oe),string:new Y}}function bo(t){return Pe(this,t).delete(t)}function Co(t){return Pe(this,t).get(t)}function To(t){return Pe(this,t).has(t)}function Bo(t,e){return Pe(this,t).set(t,e),this}Z.prototype.clear=So;Z.prototype.delete=bo;Z.prototype.get=Co;Z.prototype.has=To;Z.prototype.set=Bo;function Io(t,e,r){var n=t[e];(!(ke.call(t,e)&&Dr(n,r))||r===void 0&&!(e in t))&&(t[e]=r)}function Ne(t,e){for(var r=t.length;r--;)if(Dr(t[r][0],e))return r;return-1}function xo(t){if(!Oe(t)||No(t))return!1;var e=qo(t)||io(t)?ao:Qs;return e.test(vo(t))}function Uo(t,e,r,n){if(!Oe(t))return t;e=Oo(e,t)?[e]:_o(e);for(var i=-1,s=e.length,o=s-1,a=t;a!=null&&++i<s;){var u=$o(e[i]),h=r;if(i!=o){var l=a[u];h=n?n(l,u,a):void 0,h===void 0&&(h=Oe(l)?l:Ro(e[i+1])?[]:{})}Io(a,u,h),a=a[u]}return t}function Fo(t){if(typeof t=="string")return t;if(wt(t))return Nr?Nr.call(t):"";var e=t+"";return e=="0"&&1/t==-$r?"-0":e}function _o(t){return Lr(t)?t:Po(t)}function Pe(t,e){var r=t.__data__;return ko(e)?r[typeof e=="string"?"string":"hash"]:r.map}function Hr(t,e){var r=no(t,e);return xo(r)?r:void 0}function Ro(t,e){return e=e??js,!!e&&(typeof t=="number"||eo.test(t))&&t>-1&&t%1==0&&t<e}function Oo(t,e){if(Lr(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||wt(t)?!0:Vs.test(t)||!Ws.test(t)||e!=null&&t in Object(e)}function ko(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function No(t){return!!Rr&&Rr in t}var Po=gt(function(t){t=Ho(t);var e=[];return Xs.test(t)&&e.push(""),t.replace(Js,function(r,n,i,s){e.push(i?s.replace(Zs,"$1"):n||r)}),e});function $o(t){if(typeof t=="string"||wt(t))return t;var e=t+"";return e=="0"&&1/t==-$r?"-0":e}function vo(t){if(t!=null){try{return qr.call(t)}catch{}try{return t+""}catch{}}return""}function gt(t,e){if(typeof t!="function"||e&&typeof e!="function")throw new TypeError(Ls);var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],s=r.cache;if(s.has(i))return s.get(i);var o=t.apply(this,n);return r.cache=s.set(i,o),o};return r.cache=new(gt.Cache||Z),r}gt.Cache=Z;function Dr(t,e){return t===e||t!==t&&e!==e}var Lr=Array.isArray;function qo(t){var e=Oe(t)?Mr.call(t):"";return e==Ks||e==Gs}function Oe(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Mo(t){return!!t&&typeof t=="object"}function wt(t){return typeof t=="symbol"||Mo(t)&&Mr.call(t)==zs}function Ho(t){return t==null?"":Fo(t)}function Do(t,e,r){return t==null?t:Uo(t,e,r)}jr.exports=Do});var Jr=E(bt=>{"use strict";bt.parse=Xo;bt.serialize=Jo;var zo=decodeURIComponent,Wo=encodeURIComponent,Vo=/; */,qe=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function Xo(t,e){if(typeof t!="string")throw new TypeError("argument str must be a string");for(var r={},n=e||{},i=t.split(Vo),s=n.decode||zo,o=0;o<i.length;o++){var a=i[o],u=a.indexOf("=");if(!(u<0)){var h=a.substr(0,u).trim(),l=a.substr(++u,a.length).trim();l[0]=='"'&&(l=l.slice(1,-1)),r[h]==null&&(r[h]=Yo(l,s))}}return r}function Jo(t,e,r){var n=r||{},i=n.encode||Wo;if(typeof i!="function")throw new TypeError("option encode is invalid");if(!qe.test(t))throw new TypeError("argument name is invalid");var s=i(e);if(s&&!qe.test(s))throw new TypeError("argument val is invalid");var o=t+"="+s;if(n.maxAge!=null){var a=n.maxAge-0;if(isNaN(a)||!isFinite(a))throw new TypeError("option maxAge is invalid");o+="; Max-Age="+Math.floor(a)}if(n.domain){if(!qe.test(n.domain))throw new TypeError("option domain is invalid");o+="; Domain="+n.domain}if(n.path){if(!qe.test(n.path))throw new TypeError("option path is invalid");o+="; Path="+n.path}if(n.expires){if(typeof n.expires.toUTCString!="function")throw new TypeError("option expires is invalid");o+="; Expires="+n.expires.toUTCString()}if(n.httpOnly&&(o+="; HttpOnly"),n.secure&&(o+="; Secure"),n.sameSite){var u=typeof n.sameSite=="string"?n.sameSite.toLowerCase():n.sameSite;switch(u){case!0:o+="; SameSite=Strict";break;case"lax":o+="; SameSite=Lax";break;case"strict":o+="; SameSite=Strict";break;case"none":o+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return o}function Yo(t,e){try{return e(t)}catch{return t}}});var Zr=E((gc,Yr)=>{"use strict";var Me=1;function Zo(){return Me=(Me*9301+49297)%233280,Me/233280}function Qo(t){Me=t}Yr.exports={nextValue:Zo,seed:Qo}});var be=E((wc,rn)=>{"use strict";var Ct=Zr(),ee="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-",K,Qr,Se;function Tt(){Se=!1}function en(t){if(!t){K!==ee&&(K=ee,Tt());return}if(t!==K){if(t.length!==ee.length)throw new Error("Custom alphabet for shortid must be "+ee.length+" unique characters. You submitted "+t.length+" characters: "+t);var e=t.split("").filter(function(r,n,i){return n!==i.lastIndexOf(r)});if(e.length)throw new Error("Custom alphabet for shortid must be "+ee.length+" unique characters. These characters were not unique: "+e.join(", "));K=t,Tt()}}function ea(t){return en(t),K}function ta(t){Ct.seed(t),Qr!==t&&(Tt(),Qr=t)}function ra(){K||en(ee);for(var t=K.split(""),e=[],r=Ct.nextValue(),n;t.length>0;)r=Ct.nextValue(),n=Math.floor(r*t.length),e.push(t.splice(n,1)[0]);return e.join("")}function tn(){return Se||(Se=ra(),Se)}function na(t){var e=tn();return e[t]}function ia(){return K||ee}rn.exports={get:ia,characters:ea,seed:ta,lookup:na,shuffled:tn}});var sn=E((Ac,nn)=>{"use strict";var Bt=typeof window=="object"&&(window.crypto||window.msCrypto),It;!Bt||!Bt.getRandomValues?It=function(t){for(var e=[],r=0;r<t;r++)e.push(Math.floor(Math.random()*256));return e}:It=function(t){return Bt.getRandomValues(new Uint8Array(t))};nn.exports=It});var an=E((Ec,on)=>{on.exports=function(t,e,r){for(var n=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*n*r/e.length),s="";;)for(var o=t(i),a=i;a--;)if(s+=e[o[a]&n]||"",s.length===+r)return s}});var cn=E((Sc,un)=>{"use strict";var sa=be(),oa=sn(),aa=an();function ua(t){for(var e=0,r,n="";!r;)n=n+aa(oa,sa.get(),1),r=t<Math.pow(16,e+1),e++;return n}un.exports=ua});var ln=E((Cc,fn)=>{"use strict";var He=cn(),bc=be(),ca=1567752802062,ha=7,De,hn;function fa(t){var e="",r=Math.floor((Date.now()-ca)*.001);return r===hn?De++:(De=0,hn=r),e=e+He(ha),e=e+He(t),De>0&&(e=e+He(De)),e=e+He(r),e}fn.exports=fa});var dn=E((Tc,pn)=>{"use strict";var la=be();function pa(t){if(!t||typeof t!="string"||t.length<6)return!1;var e=new RegExp("[^"+la.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]");return!e.test(t)}pn.exports=pa});var mn=E((Bc,yn)=>{"use strict";yn.exports=0});var An=E((Ic,D)=>{"use strict";var xt=be(),da=ln(),ya=dn(),gn=mn()||0;function ma(t){return xt.seed(t),D.exports}function ga(t){return gn=t,D.exports}function wa(t){return t!==void 0&&xt.characters(t),xt.shuffled()}function wn(){return da(gn)}D.exports=wn;D.exports.generate=wn;D.exports.seed=ma;D.exports.worker=ga;D.exports.characters=wa;D.exports.isValid=ya});var Sn=E((xc,En)=>{"use strict";En.exports=An()});var $n=E(Le=>{"use strict";Le.byteLength=Ha;Le.toByteArray=La;Le.fromByteArray=Ga;var v=[],k=[],Ma=typeof Uint8Array<"u"?Uint8Array:Array,Dt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(re=0,Nn=Dt.length;re<Nn;++re)v[re]=Dt[re],k[Dt.charCodeAt(re)]=re;var re,Nn;k["-".charCodeAt(0)]=62;k["_".charCodeAt(0)]=63;function Pn(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function Ha(t){var e=Pn(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Da(t,e,r){return(e+r)*3/4-r}function La(t){var e,r=Pn(t),n=r[0],i=r[1],s=new Ma(Da(t,n,i)),o=0,a=i>0?n-4:n,u;for(u=0;u<a;u+=4)e=k[t.charCodeAt(u)]<<18|k[t.charCodeAt(u+1)]<<12|k[t.charCodeAt(u+2)]<<6|k[t.charCodeAt(u+3)],s[o++]=e>>16&255,s[o++]=e>>8&255,s[o++]=e&255;return i===2&&(e=k[t.charCodeAt(u)]<<2|k[t.charCodeAt(u+1)]>>4,s[o++]=e&255),i===1&&(e=k[t.charCodeAt(u)]<<10|k[t.charCodeAt(u+1)]<<4|k[t.charCodeAt(u+2)]>>2,s[o++]=e>>8&255,s[o++]=e&255),s}function ja(t){return v[t>>18&63]+v[t>>12&63]+v[t>>6&63]+v[t&63]}function Ka(t,e,r){for(var n,i=[],s=e;s<r;s+=3)n=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(t[s+2]&255),i.push(ja(n));return i.join("")}function Ga(t){for(var e,r=t.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(Ka(t,o,o+s>a?a:o+s));return n===1?(e=t[r-1],i.push(v[e>>2]+v[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(v[e>>10]+v[e>>4&63]+v[e<<2&63]+"=")),i.join("")}});var vn=E(Lt=>{Lt.read=function(t,e,r,n,i){var s,o,a=i*8-n-1,u=(1<<a)-1,h=u>>1,l=-7,f=r?i-1:0,d=r?-1:1,y=t[e+f];for(f+=d,s=y&(1<<-l)-1,y>>=-l,l+=a;l>0;s=s*256+t[e+f],f+=d,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=n;l>0;o=o*256+t[e+f],f+=d,l-=8);if(s===0)s=1-h;else{if(s===u)return o?NaN:(y?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-h}return(y?-1:1)*o*Math.pow(2,s-n)};Lt.write=function(t,e,r,n,i,s){var o,a,u,h=s*8-i-1,l=(1<<h)-1,f=l>>1,d=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=n?0:s-1,g=n?1:-1,A=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),o+f>=1?e+=d/u:e+=d*Math.pow(2,1-f),e*u>=2&&(o++,u/=2),o+f>=l?(a=0,o=l):o+f>=1?(a=(e*u-1)*Math.pow(2,i),o=o+f):(a=e*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;t[r+y]=a&255,y+=g,a/=256,i-=8);for(o=o<<i|a,h+=i;h>0;t[r+y]=o&255,y+=g,o/=256,h-=8);t[r+y-g]|=A*128}});var ei=E(fe=>{"use strict";var jt=$n(),ce=vn(),qn=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;fe.Buffer=c;fe.SlowBuffer=Ya;fe.INSPECT_MAX_BYTES=50;var je=2147483647;fe.kMaxLength=je;c.TYPED_ARRAY_SUPPORT=za();!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function za(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}});Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function L(t){if(t>je)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,c.prototype),e}function c(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Wt(t)}return Ln(t,e,r)}c.poolSize=8192;function Ln(t,e,r){if(typeof t=="string")return Va(t,e);if(ArrayBuffer.isView(t))return Xa(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return Gt(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return c.from(n,e,r);let i=Ja(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return c.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}c.from=function(t,e,r){return Ln(t,e,r)};Object.setPrototypeOf(c.prototype,Uint8Array.prototype);Object.setPrototypeOf(c,Uint8Array);function jn(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function Wa(t,e,r){return jn(t),t<=0?L(t):e!==void 0?typeof r=="string"?L(t).fill(e,r):L(t).fill(e):L(t)}c.alloc=function(t,e,r){return Wa(t,e,r)};function Wt(t){return jn(t),L(t<0?0:Vt(t)|0)}c.allocUnsafe=function(t){return Wt(t)};c.allocUnsafeSlow=function(t){return Wt(t)};function Va(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!c.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Kn(t,e)|0,n=L(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function Kt(t){let e=t.length<0?0:Vt(t.length)|0,r=L(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Xa(t){if(q(t,Uint8Array)){let e=new Uint8Array(t);return Gt(e.buffer,e.byteOffset,e.byteLength)}return Kt(t)}function Gt(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,c.prototype),n}function Ja(t){if(c.isBuffer(t)){let e=Vt(t.length)|0,r=L(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Jt(t.length)?L(0):Kt(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Kt(t.data)}function Vt(t){if(t>=je)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+je.toString(16)+" bytes");return t|0}function Ya(t){return+t!=t&&(t=0),c.alloc(+t)}c.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==c.prototype};c.compare=function(e,r){if(q(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),q(r,Uint8Array)&&(r=c.from(r,r.offset,r.byteLength)),!c.isBuffer(e)||!c.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let s=0,o=Math.min(n,i);s<o;++s)if(e[s]!==r[s]){n=e[s],i=r[s];break}return n<i?-1:i<n?1:0};c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};c.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return c.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=c.allocUnsafe(r),s=0;for(n=0;n<e.length;++n){let o=e[n];if(q(o,Uint8Array))s+o.length>i.length?(c.isBuffer(o)||(o=c.from(o)),o.copy(i,s)):Uint8Array.prototype.set.call(i,o,s);else if(c.isBuffer(o))o.copy(i,s);else throw new TypeError('"list" argument must be an Array of Buffers');s+=o.length}return i};function Kn(t,e){if(c.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return zt(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Qn(t).length;default:if(i)return n?-1:zt(t).length;e=(""+e).toLowerCase(),i=!0}}c.byteLength=Kn;function Za(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return uu(this,e,r);case"utf8":case"utf-8":return zn(this,e,r);case"ascii":return ou(this,e,r);case"latin1":case"binary":return au(this,e,r);case"base64":return iu(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return cu(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}c.prototype._isBuffer=!0;function ne(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}c.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)ne(this,r,r+1);return this};c.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)ne(this,r,r+3),ne(this,r+1,r+2);return this};c.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)ne(this,r,r+7),ne(this,r+1,r+6),ne(this,r+2,r+5),ne(this,r+3,r+4);return this};c.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?zn(this,0,e):Za.apply(this,arguments)};c.prototype.toLocaleString=c.prototype.toString;c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:c.compare(this,e)===0};c.prototype.inspect=function(){let e="",r=fe.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};qn&&(c.prototype[qn]=c.prototype.inspect);c.prototype.compare=function(e,r,n,i,s){if(q(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),s===void 0&&(s=this.length),r<0||n>e.length||i<0||s>this.length)throw new RangeError("out of range index");if(i>=s&&r>=n)return 0;if(i>=s)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,s>>>=0,this===e)return 0;let o=s-i,a=n-r,u=Math.min(o,a),h=this.slice(i,s),l=e.slice(r,n);for(let f=0;f<u;++f)if(h[f]!==l[f]){o=h[f],a=l[f];break}return o<a?-1:a<o?1:0};function Gn(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Jt(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=c.from(e,n)),c.isBuffer(e))return e.length===0?-1:Mn(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):Mn(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Mn(t,e,r,n,i){let s=1,o=t.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;s=2,o/=2,a/=2,r/=2}function u(l,f){return s===1?l[f]:l.readUInt16BE(f*s)}let h;if(i){let l=-1;for(h=r;h<o;h++)if(u(t,h)===u(e,l===-1?0:h-l)){if(l===-1&&(l=h),h-l+1===a)return l*s}else l!==-1&&(h-=h-l),l=-1}else for(r+a>o&&(r=o-a),h=r;h>=0;h--){let l=!0;for(let f=0;f<a;f++)if(u(t,h+f)!==u(e,f)){l=!1;break}if(l)return h}return-1}c.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};c.prototype.indexOf=function(e,r,n){return Gn(this,e,r,n,!0)};c.prototype.lastIndexOf=function(e,r,n){return Gn(this,e,r,n,!1)};function Qa(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let s=e.length;n>s/2&&(n=s/2);let o;for(o=0;o<n;++o){let a=parseInt(e.substr(o*2,2),16);if(Jt(a))return o;t[r+o]=a}return o}function eu(t,e,r,n){return Ke(zt(e,t.length-r),t,r,n)}function tu(t,e,r,n){return Ke(pu(e),t,r,n)}function ru(t,e,r,n){return Ke(Qn(e),t,r,n)}function nu(t,e,r,n){return Ke(du(e,t.length-r),t,r,n)}c.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let s=this.length-r;if((n===void 0||n>s)&&(n=s),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let o=!1;for(;;)switch(i){case"hex":return Qa(this,e,r,n);case"utf8":case"utf-8":return eu(this,e,r,n);case"ascii":case"latin1":case"binary":return tu(this,e,r,n);case"base64":return ru(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return nu(this,e,r,n);default:if(o)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),o=!0}};c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function iu(t,e,r){return e===0&&r===t.length?jt.fromByteArray(t):jt.fromByteArray(t.slice(e,r))}function zn(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let s=t[i],o=null,a=s>239?4:s>223?3:s>191?2:1;if(i+a<=r){let u,h,l,f;switch(a){case 1:s<128&&(o=s);break;case 2:u=t[i+1],(u&192)===128&&(f=(s&31)<<6|u&63,f>127&&(o=f));break;case 3:u=t[i+1],h=t[i+2],(u&192)===128&&(h&192)===128&&(f=(s&15)<<12|(u&63)<<6|h&63,f>2047&&(f<55296||f>57343)&&(o=f));break;case 4:u=t[i+1],h=t[i+2],l=t[i+3],(u&192)===128&&(h&192)===128&&(l&192)===128&&(f=(s&15)<<18|(u&63)<<12|(h&63)<<6|l&63,f>65535&&f<1114112&&(o=f))}}o===null?(o=65533,a=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),i+=a}return su(n)}var Hn=4096;function su(t){let e=t.length;if(e<=Hn)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Hn));return r}function ou(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function au(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function uu(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let s=e;s<r;++s)i+=yu[t[s]];return i}function cu(t,e,r){let n=t.slice(e,r),i="";for(let s=0;s<n.length-1;s+=2)i+=String.fromCharCode(n[s]+n[s+1]*256);return i}c.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,c.prototype),i};function B(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||B(e,r,this.length);let i=this[e],s=1,o=0;for(;++o<r&&(s*=256);)i+=this[e+o]*s;return i};c.prototype.readUintBE=c.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||B(e,r,this.length);let i=this[e+--r],s=1;for(;r>0&&(s*=256);)i+=this[e+--r]*s;return i};c.prototype.readUint8=c.prototype.readUInt8=function(e,r){return e=e>>>0,r||B(e,1,this.length),this[e]};c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||B(e,2,this.length),this[e]|this[e+1]<<8};c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||B(e,2,this.length),this[e]<<8|this[e+1]};c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||B(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||B(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};c.prototype.readBigUInt64LE=G(function(e){e=e>>>0,he(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Te(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,s=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(s)<<BigInt(32))});c.prototype.readBigUInt64BE=G(function(e){e=e>>>0,he(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Te(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],s=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(s)});c.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||B(e,r,this.length);let i=this[e],s=1,o=0;for(;++o<r&&(s*=256);)i+=this[e+o]*s;return s*=128,i>=s&&(i-=Math.pow(2,8*r)),i};c.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||B(e,r,this.length);let i=r,s=1,o=this[e+--i];for(;i>0&&(s*=256);)o+=this[e+--i]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*r)),o};c.prototype.readInt8=function(e,r){return e=e>>>0,r||B(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};c.prototype.readInt16LE=function(e,r){e=e>>>0,r||B(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};c.prototype.readInt16BE=function(e,r){e=e>>>0,r||B(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};c.prototype.readInt32LE=function(e,r){return e=e>>>0,r||B(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};c.prototype.readInt32BE=function(e,r){return e=e>>>0,r||B(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};c.prototype.readBigInt64LE=G(function(e){e=e>>>0,he(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Te(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});c.prototype.readBigInt64BE=G(function(e){e=e>>>0,he(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Te(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});c.prototype.readFloatLE=function(e,r){return e=e>>>0,r||B(e,4,this.length),ce.read(this,e,!0,23,4)};c.prototype.readFloatBE=function(e,r){return e=e>>>0,r||B(e,4,this.length),ce.read(this,e,!1,23,4)};c.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||B(e,8,this.length),ce.read(this,e,!0,52,8)};c.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||B(e,8,this.length),ce.read(this,e,!1,52,8)};function F(t,e,r,n,i,s){if(!c.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<s)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;F(this,e,r,n,a,0)}let s=1,o=0;for(this[r]=e&255;++o<n&&(s*=256);)this[r+o]=e/s&255;return r+n};c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;F(this,e,r,n,a,0)}let s=n-1,o=1;for(this[r+s]=e&255;--s>=0&&(o*=256);)this[r+s]=e/o&255;return r+n};c.prototype.writeUint8=c.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,1,255,0),this[r]=e&255,r+1};c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Wn(t,e,r,n,i){Zn(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,r}function Vn(t,e,r,n,i){Zn(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r+7]=s,s=s>>8,t[r+6]=s,s=s>>8,t[r+5]=s,s=s>>8,t[r+4]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=o,o=o>>8,t[r+2]=o,o=o>>8,t[r+1]=o,o=o>>8,t[r]=o,r+8}c.prototype.writeBigUInt64LE=G(function(e,r=0){return Wn(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeBigUInt64BE=G(function(e,r=0){return Vn(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let u=Math.pow(2,8*n-1);F(this,e,r,n,u-1,-u)}let s=0,o=1,a=0;for(this[r]=e&255;++s<n&&(o*=256);)e<0&&a===0&&this[r+s-1]!==0&&(a=1),this[r+s]=(e/o>>0)-a&255;return r+n};c.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let u=Math.pow(2,8*n-1);F(this,e,r,n,u-1,-u)}let s=n-1,o=1,a=0;for(this[r+s]=e&255;--s>=0&&(o*=256);)e<0&&a===0&&this[r+s+1]!==0&&(a=1),this[r+s]=(e/o>>0)-a&255;return r+n};c.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};c.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};c.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||F(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};c.prototype.writeBigInt64LE=G(function(e,r=0){return Wn(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});c.prototype.writeBigInt64BE=G(function(e,r=0){return Vn(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Xn(t,e,r,n,i,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Jn(t,e,r,n,i){return e=+e,r=r>>>0,i||Xn(t,e,r,4,34028234663852886e22,-34028234663852886e22),ce.write(t,e,r,n,23,4),r+4}c.prototype.writeFloatLE=function(e,r,n){return Jn(this,e,r,!0,n)};c.prototype.writeFloatBE=function(e,r,n){return Jn(this,e,r,!1,n)};function Yn(t,e,r,n,i){return e=+e,r=r>>>0,i||Xn(t,e,r,8,17976931348623157e292,-17976931348623157e292),ce.write(t,e,r,n,52,8),r+8}c.prototype.writeDoubleLE=function(e,r,n){return Yn(this,e,r,!0,n)};c.prototype.writeDoubleBE=function(e,r,n){return Yn(this,e,r,!1,n)};c.prototype.copy=function(e,r,n,i){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let s=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),s};c.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!c.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let o=e.charCodeAt(0);(i==="utf8"&&o<128||i==="latin1")&&(e=o)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let s;if(typeof e=="number")for(s=r;s<n;++s)this[s]=e;else{let o=c.isBuffer(e)?e:c.from(e,i),a=o.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-r;++s)this[s+r]=o[s%a]}return this};var ue={};function Xt(t,e,r){ue[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}Xt("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Xt("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);Xt("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=Dn(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Dn(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Dn(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function hu(t,e,r){he(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Te(e,t.length-(r+1))}function Zn(t,e,r,n,i,s){if(t>r||t<e){let o=typeof e=="bigint"?"n":"",a;throw s>3?e===0||e===BigInt(0)?a=`>= 0${o} and < 2${o} ** ${(s+1)*8}${o}`:a=`>= -(2${o} ** ${(s+1)*8-1}${o}) and < 2 ** ${(s+1)*8-1}${o}`:a=`>= ${e}${o} and <= ${r}${o}`,new ue.ERR_OUT_OF_RANGE("value",a,t)}hu(n,i,s)}function he(t,e){if(typeof t!="number")throw new ue.ERR_INVALID_ARG_TYPE(e,"number",t)}function Te(t,e,r){throw Math.floor(t)!==t?(he(t,r),new ue.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new ue.ERR_BUFFER_OUT_OF_BOUNDS:new ue.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var fu=/[^+/0-9A-Za-z-_]/g;function lu(t){if(t=t.split("=")[0],t=t.trim().replace(fu,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function zt(t,e){e=e||1/0;let r,n=t.length,i=null,s=[];for(let o=0;o<n;++o){if(r=t.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}else if(o+1===n){(e-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return s}function pu(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function du(t,e){let r,n,i,s=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}function Qn(t){return jt.toByteArray(lu(t))}function Ke(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Jt(t){return t!==t}var yu=function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function G(t){return typeof BigInt>"u"?mu:t}function mu(){throw new Error("BigInt not supported")}});var ii=C(hr());var Tr=C(H()),bs={get:Tr.default};function nt(t){t.status=401,t.body="Unauthorized",t.set("WWW-Authenticate","Basic")}function it(t){return async(e,r)=>{if(e.request.path===t.logoutPath)return nt(e);let n=bs.get(e,"request.headers.authorization");if(!n||!n.startsWith("Basic "))return nt(e);let i=t.users.map(a=>a.authToken),s=n.substring(6),o=i.indexOf(s);return o===-1?nt(e):(e.state.user=t.users[o].username,r(e))}}var Br=caches.default;async function Cs(t){return await Br.match(t)}async function Ts(t,e){return Br.put(t.href,e)}var st={get:Cs,set:Ts};async function Bs(t){let e=new TextEncoder().encode(t),r=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(r)).map(s=>s.toString(16).padStart(2,"0")).join("")}var Ir=Bs;function Is(t,e={}){return Object.keys(e).reduce((r,n)=>r.replace(`{${n}}`,e[n]),t)}function ot(t){return[...t].reduce((e,r)=>{let n={};return n[r[0]]=r[1],{...e,...n}},{})}var T={resolveParams:Is,instanceToJson:ot};var xs=["x-ratelimit-count","x-ratelimit-limit","x-ratelimit-reset","x-cache-hit"];async function Us(t){return["POST","PATCH"].indexOf(t.method)===-1?null:t.text()}async function Fs(t,e){if(!e)return t.event.request;let r=e.match(/{.*?}/gi).map(s=>s.slice(1,-1)),n={};for(let s=0;s<r.length;s+=1){let o=r[s],a=o.split(":");switch(a[0]){case"method":n[o]=t.request.method;break;case"path":n[o]=t.request.path;break;case"bodyHash":n[o]=await Ir(await Us(t.request));break;case"header":n[o]=t.request.headers[a[1]]||"";break;default:n[o]=o}}let i=encodeURIComponent(e.replace(/({(.*?)})/gi,(s,o,a)=>n[a]));return new Request(`http://${t.request.hostname}/${i}`)}function at({cacheDuration:t,cacheKeyTemplate:e,headerBlacklist:r=xs}){return async(n,i)=>{let s=await Fs(n,e),o=await st.get(s);if(o){n.body=o.body,n.status=o.status;let a=ot(o.headers);Object.keys(a).forEach(u=>{n.set(u,a[u])}),n.set("X-Cache-Hit",!0)}else{await i(n);let a;n.body.tee?[n.body,a]=n.body.tee():a=n.body;let u=new Response(a,{status:n.status});Object.keys(n.response.headers).forEach(h=>{r.indexOf(h.toLowerCase())===-1&&u.headers.set(h,n.response.headers[h])}),t&&(u.headers.delete("Cache-Control"),u.headers.set("Cache-Control",`max-age=${t}`)),n.event.waitUntil(st.set(s,u))}}}function ut({allowedOrigins:t=["*"],allowedMethods:e=["GET","PUT","POST","PATCH","DELETE","HEAD","OPTIONS"],allowCredentials:r=!0,allowedHeaders:n=["Content-Type"],allowedExposeHeaders:i=["WWW-Authenticate","Server-Authorization"],maxAge:s=600,optionsSuccessStatus:o=204,terminatePreflight:a=!1}){return async(u,h)=>{let{method:l}=u.request,{origin:f}=u.request.headers,d=u.request.headers["access-control-request-headers"];if(_s(u,f,t),Rs(u,r),Ps(u,i),l==="OPTIONS"&&(Os(u,e),ks(u,d,n),Ns(u,s),a)){u.status=o,u.set("Content-Length","0"),u.body="";return}await h(u)}}function _s(t,e,r){Array.isArray(r)&&(r[0]==="*"?t.set("Access-Control-Allow-Origin","*"):r.indexOf(e)!==-1&&(t.set("Access-Control-Allow-Origin",e),t.set("Vary","Origin")))}function Rs(t,e){e&&t.set("Access-Control-Allow-Credentials",e)}function Os(t,e){t.set("Access-Control-Allow-Methods",e.join(","))}function ks(t,e,r){r.length===0&&e?t.set("Access-Control-Allow-Headers",e):r.length&&t.set("Access-Control-Allow-Headers",r.join(","))}function Ns(t,e){e&&t.set("Access-Control-Max-Age",e)}function Ps(t,e){e.length&&t.set("Access-Control-Expose-Headers",e.join(","))}var $s={AF:"AS",AL:"EU",AQ:"AN",DZ:"AF",AS:"OC",AD:"EU",AO:"AF",AG:"NA",AZ:"EU",AR:"SA",AU:"OC",AT:"EU",BS:"NA",BH:"AS",BD:"AS",AM:"EU",BB:"NA",BE:"EU",BM:"NA",BT:"AS",BO:"SA",BA:"EU",BW:"AF",BV:"AN",BR:"SA",BZ:"NA",IO:"AS",SB:"OC",VG:"NA",BN:"AS",BG:"EU",MM:"AS",BI:"AF",BY:"EU",KH:"AS",CM:"AF",CA:"NA",CV:"AF",KY:"NA",CF:"AF",LK:"AS",TD:"AF",CL:"SA",CN:"AS",TW:"AS",CX:"AS",CC:"AS",CO:"SA",KM:"AF",YT:"AF",CG:"AF",CD:"AF",CK:"OC",CR:"NA",HR:"EU",CU:"NA",CY:"EU",CZ:"EU",BJ:"AF",DK:"EU",DM:"NA",DO:"NA",EC:"SA",SV:"NA",GQ:"AF",ET:"AF",ER:"AF",EE:"EU",FO:"EU",FK:"SA",GS:"AN",FJ:"OC",FI:"EU",AX:"EU",FR:"EU",GF:"SA",PF:"OC",TF:"AN",DJ:"AF",GA:"AF",GE:"EU",GM:"AF",PS:"AS",DE:"EU",GH:"AF",GI:"EU",KI:"OC",GR:"EU",GL:"NA",GD:"NA",GP:"NA",GU:"OC",GT:"NA",GN:"AF",GY:"SA",HT:"NA",HM:"AN",VA:"EU",HN:"NA",HK:"AS",HU:"EU",IS:"EU",IN:"AS",ID:"AS",IR:"AS",IQ:"AS",IE:"EU",IL:"AS",IT:"EU",CI:"AF",JM:"NA",JP:"AS",KZ:"EU",JO:"AS",KE:"AF",KP:"AS",KR:"AS",KW:"AS",KG:"AS",LA:"AS",LB:"AS",LS:"AF",LV:"EU",LR:"AF",LY:"AF",LI:"EU",LT:"EU",LU:"EU",MO:"AS",MG:"AF",MW:"AF",MY:"AS",MV:"AS",ML:"AF",MT:"EU",MQ:"NA",MR:"AF",MU:"AF",MX:"NA",MC:"EU",MN:"AS",MD:"EU",ME:"EU",MS:"NA",MA:"AF",MZ:"AF",OM:"AS",NA:"AF",NR:"OC",NP:"AS",NL:"EU",AN:"NA",CW:"NA",AW:"NA",SX:"NA",BQ:"NA",NC:"OC",VU:"OC",NZ:"OC",NI:"NA",NE:"AF",NG:"AF",NU:"OC",NF:"OC",NO:"EU",MP:"OC",UM:"OC",FM:"OC",MH:"OC",PW:"OC",PK:"AS",PA:"NA",PG:"OC",PY:"SA",PE:"SA",PH:"AS",PN:"OC",PL:"EU",PT:"EU",GW:"AF",TL:"AS",PR:"NA",QA:"AS",RE:"AF",RO:"EU",RU:"EU",RW:"AF",BL:"NA",SH:"AF",KN:"NA",AI:"NA",LC:"NA",MF:"NA",PM:"NA",VC:"NA",SM:"EU",ST:"AF",SA:"AS",SN:"AF",RS:"EU",SC:"AF",SL:"AF",SG:"AS",SK:"EU",VN:"AS",SI:"EU",SO:"AF",ZA:"AF",ZW:"AF",ES:"EU",SS:"AF",EH:"AF",SD:"AF",SR:"SA",SJ:"EU",SZ:"AF",SE:"EU",CH:"EU",SY:"AS",TJ:"AS",TH:"AS",TG:"AF",TK:"OC",TO:"OC",TT:"NA",AE:"AS",TN:"AF",TR:"EU",TM:"AS",TC:"NA",TV:"OC",UG:"AF",UA:"EU",MK:"EU",EG:"AF",GB:"EU",GG:"EU",JE:"EU",IM:"EU",TZ:"AF",US:"NA",VI:"NA",BF:"AF",UY:"SA",UZ:"AS",VE:"SA",WF:"OC",WS:"OC",YE:"AS",ZM:"AF",XX:"XX"};function ct(){return async(t,e)=>{let r=t.request.headers["cf-ipcountry"]||"XX";t.request.headers["proxy-continent"]=$s[r],await e(t)}}function vs(t){let e=t.split("."),r=JSON.parse(atob(e[0])),n=JSON.parse(atob(e[1])),i=atob(e[2].replace(/-/g,"+").replace(/_/g,"/"));return{header:r,payload:n,signature:i,raw:{header:e[0],payload:e[1],signature:e[2]}}}function ht({jwksUri:t,allowPublicAccess:e=!1}){async function r(){return(await(await fetch(t)).json()).keys}async function n(s){let a=new TextEncoder().encode([s.raw.header,s.raw.payload].join(".")),u=new Uint8Array(Array.from(s.signature).map(f=>f.charCodeAt(0))),h=await r();return(await Promise.all(h.map(async f=>{let d=await crypto.subtle.importKey("jwk",f,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["verify"]);return crypto.subtle.verify("RSASSA-PKCS1-v1_5",d,u,a)}))).some(f=>f)}async function i(s,o){if(s.request.method==="OPTIONS")return o(s);if((s.request.headers.authorization||"").toLowerCase().startsWith("bearer")){let u=vs(s.request.headers.authorization.slice(7)),h=new Date(u.payload.exp*1e3),l=new Date(Date.now());if(h<=l)return!1;if(await n(u))return s.state.user=u.payload,o(s)}return e?o(s):(s.status=403,s.body="Forbidden",s)}return i}var xr=C(H()),qs={get:xr.default},J=class{constructor({accountId:e,namespace:r,authEmail:n,authKey:i,ttl:s}){this.accountId=e,this.namespace=r,this.authEmail=n,this.authKey=i,this.ttl=s}getNamespaceUrl(){return new URL(`https://api.cloudflare.com/client/v4/accounts/${this.accountId}/storage/kv/namespaces/${this.namespace}`)}getUrlForKey(e){return new URL(`${this.getNamespaceUrl()}/values/${e}`)}async list(e,r=10){let n=`${this.getNamespaceUrl()}/keys?prefix=${e}&limit=${r}`,i=await fetch(n,{headers:{"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey}});return i.ok?i.json():null}async get(e,r){let n=this.getUrlForKey(e),i=await fetch(n,{headers:{"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey}});if(i.ok)switch(r){case"json":return i.json();case"stream":return i;case"arrayBuffer":return i.arrayBuffer();default:return i.text()}return null}async getWithMetadata(e,r){let[n,i]=await Promise.all([this.get(e,r),this.list(e)]),s=qs.get(i,"result.0.metadata",{});return{value:n,metadata:s}}async put(e,r,n={}){let i=this.getUrlForKey(e),s=new URLSearchParams;this.ttl&&s.append("expiration_ttl",this.ttl.toString());let o={"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey};i.search=s.toString();let a=new FormData;return a.append("value",r),a.append("metadata",JSON.stringify(n)),(await fetch(i.toString(),{method:"PUT",headers:o,body:r})).ok}async delete(e){let r=this.getUrlForKey(e);return fetch(r,{method:"DELETE",headers:{"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey}})}};var N={methodsMethodsWithBody:["POST","PUT","PATCH"],http:{statusMessages:{404:"Not Found"}},mime:{css:"text/css",csv:"text/csv",html:"text/html",ico:"image/microsoft.vnd.icon",jpeg:"image/jpeg",js:"application/javascript",json:"application/json",png:"image/png",svg:"image/svg+xml",xml:"application/xml"}};function Ms(t,e,r){if(t==="/"&&r)return r;let n=t.split("/").pop();return n.split(".").pop()!==n?t:`${t}.${e}`}function ft({kvAccountId:t,kvNamespace:e,kvAuthEmail:r,kvAuthKey:n,kvBasePath:i="",kvKey:s="{file}",defaultExtension:o="html",defaultIndexDocument:a,defaultErrorDocument:u,mime:h={},mode:l="rest"}){let f=new J({accountId:t,namespace:e,authEmail:r,authKey:n,mode:l}),d={...N.mime,...h};return async y=>{let g=T.resolveParams(s,y.params),A=g===""&&a?a:Ms(g,o),m=await f.get(i+A);!m&&u&&(m=await f.get(i+u)),m?(y.status=200,y.body=m,y.set("Content-Type",d[A.split(".").pop()]||"text/plain")):(y.status=404,y.body=N.http.statusMessages[404],y.set("Content-Type","text/plain"))}}var Ur=C(H());var lt={get:Ur.default};function Hs(t,e,r){if(t==="/"&&r)return r;let n=t.split("/").pop();return n.split(".").pop()!==n?t:`${t}.${e}`}function Ds(t,e){let r=lt.get(t,"headers.if-none-match"),n=lt.get(e,"metadata.headers.etag");return r?r===n:!1}function pt({kvNamespaceBinding:t,kvBasePath:e="",kvKey:r="{file}",defaultExtension:n="html",defaultIndexDocument:i,defaultErrorDocument:s}){async function o(a){return await global[t].getWithMetadata(a)}return async a=>{let u=T.resolveParams(r,a.params),h=u===""&&i?i:Hs(u,n),l=await o(e+h);if(!l&&s&&(l=await o(e+s)),l)if(Ds(a.request,l))a.status=304;else{a.status=l.status,a.body=l.value;let f=lt.get(l,"metadata.headers",{});Object.keys(f).forEach(d=>{a.set(d,f[d])})}else a.status=404,a.body=N.http.statusMessages[404],a.set("Content-Type","text/plain")}}var _r=C(Re());function dt({accessKeyId:t,secretAccessKey:e,region:r,lambdaName:n}){let i=new _r.AwsClient({accessKeyId:t,secretAccessKey:e});return async s=>{let o=`https://lambda.${r}.amazonaws.com/2015-03-31/functions/${n}/invocations`,a={},u=await i.fetch(o,{body:JSON.stringify(a)});s.status=u.status,s.body=u.body;let h=T.instanceToJson(u.headers);Object.keys(h).forEach(l=>{s.set(l,h[l])})}}var Gr=C(H()),zr=C($e());var Kr={get:Gr.default,set:zr.default};function Lo(t){let e={};return Object.keys(t).forEach(r=>{r.startsWith("cf")||(e[r]=t[r])}),e}function jo(t){return t[Math.floor(Math.random()*t.length)]}function At({sources:t=[]}){return async e=>{let r=jo(t),n={method:e.request.method,headers:Lo(e.request.headers),redirect:"manual",cf:e.request.cf};if(N.methodsMethodsWithBody.indexOf(e.request.method)!==-1&&Kr.get(e,"event.request.body")){let a=e.event.request.clone();n.body=a.body}let i=T.resolveParams(r.url,e.params);if(r.resolveOverride){let a=T.resolveParams(r.resolveOverride,e.request.params);Kr.set(n,"cf.resolveOverride",a)}let s=await fetch(i+e.request.search,n);e.body=s.body,e.status=s.status;let o=T.instanceToJson(s.headers);Object.keys(o).forEach(a=>{e.set(a,o[a])})}}var Xr=C(H());var Et={name:"@ahmadissa/cloudworker-proxy",version:"1.0.24",description:"An api gateway for cloudflare workers",license:"MIT",repository:{type:"git",url:"git+https://github.com/ahmadissa/cloudworker-proxy.git"},bugs:{url:"https://github.com/ahmadissa/cloudworker-proxy/issues"},homepage:"https://github.com/ahmadissa/cloudworker-proxy#readme",author:"Markus Ahlstrand",keywords:["cloudflare","workers","api","gateway","proxy"],main:"dist/index.js",files:["dist/**"],scripts:{build:"esbuild --bundle src/index.ts --format=cjs --outdir=dist --sourcemap --minify",lint:"eslint src",package:"bun install; npm run build",test:"npm run unit && npm run lint","test:integration":"node integration/run.js",unit:"bun test","semantic-release":"semantic-release",prepare:"husky install"},release:{branches:["master"],plugins:["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator",["@semantic-release/npm",{npmPublish:!1}],["@semantic-release/git",{assets:["docs","package.json"],message:"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"}]]},dependencies:{aws4fetch:"1.0.13","cloudworker-router":"1.11.2",cookie:"0.4.1","lodash.get":"4.4.2","lodash.set":"4.3.2",shortid:"2.2.16"},devDependencies:{"@semantic-release/git":"^10.0.1","@types/jest":"^29.5.5","@types/mocha":"^10.0.1","@types/node":"^20.5.9","@typescript-eslint/eslint-plugin":"^6.6.0","@typescript-eslint/parser":"^6.6.0",bun:"1.0.3",dotenv:"8.2.0",esbuild:"^0.19.2",eslint:"7.13.0","eslint-config-airbnb-base":"14.2.1","eslint-config-prettier":"6.15.0","eslint-plugin-import":"2.22.1","eslint-plugin-prettier":"3.1.4","fetch-mock":"9.11.0",husky:"^8.0.3","node-fetch":"2.6.1",prettier:"2.1.2","semantic-release":"^22.0.4",typescript:"^5.2.2",wrangler:"^3.7.0"},directories:{example:"examples",test:"test"}};var Q=class{constructor({maxSize:e=10,maxSeconds:r=10,sink:n}){this.maxSize=e,this.maxSeconds=r,this.queue=[],this.sink=n,this.flushing=!1,this.timer=null}async push(e){return this.queue.push(e),this.queue.length>this.maxSize?this.flush():(this.timer||(this.timer=new Promise((r,n)=>{this.resolveTimer=r,this.rejectTimer=n,this.cancelationToken=setTimeout(async()=>{try{r(await this.flush())}catch(i){n(i)}},this.maxSeconds*1e3)})),this.timer)}async flush(){if(!this.flushing){this.flushing=!0;try{let e=this.queue.join(`
6
- `);this.queue=[];let r=await this.sink(e);this.timer&&(clearTimeout(this.cancelationToken),this.resolveTimer(r))}catch(e){this.timer&&this.rejectTimer(e)}finally{this.timer=null,this.flushing=!1}}}};function Wr(t,e=".",r=""){return t instanceof Object?Object.keys(t).reduce((n,i)=>t[i]==null?n:{...n,...Wr(t[i],e,r+i+e)},{}):r.endsWith(e)?{[r.slice(0,r.length-1)]:t}:{[r]:t}}var ve=Wr;var Ae=class{constructor(e){this.url=e.url,this.contentType=e.contentType,this.delimiter=e.delimiter,this.chunker=new Q({sink:this.sendMessage.bind(this),...e})}async log(e){let r=ve(e,this.delimiter);await this.chunker.push(JSON.stringify(r))}async sendMessage(e){return fetch(this.url,{body:e,method:"POST",headers:{"Content-Type":this.contentType}})}};var Vr=C(Re());var Ee=class{constructor(e){this.delimiter=e.delimiter,this.chunker=new Q({sink:this.sendMessage.bind(this),...e}),this.awsClient=new Vr.AwsClient({accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,region:e.region}),this.streamName=e.streamName,this.region=e.region}async log(e){let r=ve(e,this.delimiter);await this.chunker.push(JSON.stringify(r))}async sendMessage(e){let r=btoa(`${JSON.stringify(e)}
7
- `),n=JSON.stringify({DeliveryStreamName:this.streamName,Record:{Data:r}}),i=`https://firehose.${this.region}.amazonaws.com`,s=new Request(i,{method:"POST",body:n,headers:{"X-Amz-Target":"Firehose_20150804.PutRecord","Content-Type":" application/x-amz-json-1.1"}});return this.awsClient.fetch(s)}};var R={get:Xr.default};async function Go(t){return["POST","PATCH"].indexOf(t.method)===-1?null:t.text()}function St(t){let e;switch(t.type){case"http":e=new Ae(t);break;case"kinesis":e=new Ee(t);break;default:throw new Error(`Log service type not supported: ${t.type}`)}return async(r,n)=>{r.state["logger-startDate"]=new Date;let i=await Go(r.request);try{await n(r);let s={message:"START",requestIp:R.get(r,"request.headers.x-real-ip"),requestId:R.get(r,"request.requestId"),request:{headers:R.get(r,"request.headers"),method:R.get(r,"request.method"),url:R.get(r,"request.href"),protocol:R.get(r,"request.protocol"),body:i},response:{status:r.status,headers:R.get(r,"response.headers")},handlers:R.get(r,"state.handlers",[]).join(","),route:R.get(r,"route.name"),timestamp:new Date().toISOString(),ttfb:new Date-r.state["logger-startDate"],redirectUrl:r.userRedirect,severity:30,proxyVersion:Et.version};r.event.waitUntil(e.log(s))}catch(s){let o={request:{headers:R.get(r,"request.headers"),method:R.get(r,"request.method"),handlers:R.get(r,"state.handlers",[]).join(","),url:R.get(r,"request.href"),body:i},message:"ERROR",stack:s.stack,error:s.message,severity:50,proxyVersion:Et.version};r.event.waitUntil(e.log(o))}}}var Ce=C(Jr()),Bn=C(H()),In=C($e()),xn=C(Sn());async function Ut({refresh_token:t,authDomain:e,clientId:r,clientSecret:n}){let i=`${e}/oauth/token`,s=await fetch(i,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",client_id:r,client_secret:n,refresh_token:t})});if(!s.ok)throw new Error("Authentication failed");let o=await s.json();return{...o,expires:Date.now()+o.expires_in*1e3,refresh_token:t}}var bn="PBKDF2",Ft="AES-GCM",Aa="SHA-256",Ea="raw";function Sa(t){let e=atob(t.replace(/_/g,"/").replace(/-/g,"+")),r=e.length,n=new Uint8Array(r);for(let i=0;i<r;i+=1)n[i]=e.charCodeAt(i);return n.buffer}function Cn(t){let e="",r=new Uint8Array(t),n=r.byteLength;for(let i=0;i<n;i+=1)e+=String.fromCharCode(r[i]);return btoa(e).replace(/\//g,"_").replace(/\+/g,"-")}function ba(t){return String.fromCharCode.apply(null,new Uint16Array(t))}function Ca(t){let e=new ArrayBuffer(t.length*2),r=new Uint16Array(e);for(let n=0,i=t.length;n<i;n+=1)r[n]=t.charCodeAt(n);return e}async function Ta(t){let e=new TextEncoder;return crypto.subtle.importKey(Ea,e.encode(t),{name:bn},!1,["deriveKey"])}async function Ba(t,e){let r=await Ta(t),i=new TextEncoder().encode(e.replace(/_/g,"/").replace(/-/g,"+"));return crypto.subtle.deriveKey({name:bn,salt:i,iterations:1e3,hash:{name:Aa}},r,{name:Ft,length:256},!0,["encrypt","decrypt"])}async function Ia(){let t=crypto.getRandomValues(new Uint8Array(8));return Cn(t)}async function xa(t,e){let r=Sa(e),n=r.slice(0,16),i=r.slice(16),s=await crypto.subtle.decrypt({name:Ft,iv:n},t,i);return ba(s)}async function Ua(t,e){let r=crypto.getRandomValues(new Uint8Array(16)),n=await crypto.subtle.encrypt({name:Ft,iv:r},t,Ca(e)),i=new Uint8Array(n.byteLength+r.byteLength);return i.set(r,0),i.set(new Uint8Array(n),r.byteLength),Cn(i)}var te={decrypt:xa,deriveAesGcmKey:Ba,encrypt:Ua,getSalt:Ia};var ae={get:Bn.default,set:In.default};function Tn({cookieHeader:t="",cookieName:e}){return Ce.default.parse(t)[e]}function Fa(t){return Object.keys(t).map(e=>`${e}=${encodeURIComponent(t[e])}`).join("&")}function _a(t=""){return t.split(",").indexOf("text/html")!==-1}function _t({cookieName:t="proxy",cookieHttpOnly:e=!0,allowPublicAccess:r=!1,kvAccountId:n,kvNamespace:i,kvAuthEmail:s,kvAuthKey:o,kvTtl:a=2592e3,oauth2AuthDomain:u,oauth2ClientId:h,oauth2ClientSecret:l,oauth2Audience:f,oauth2Scopes:d=[],oauth2CallbackPath:y="/callback",oauth2CallbackType:g="cookie",oauth2LogoutPath:A="/logout",oauth2LoginPath:m="/login",oauth2ServerTokenPath:w="/oauth/token",oauth2ServerAuthorizePath:x="",oauth2ServerLogoutPath:O}){let _=new J({accountId:n,namespace:i,authEmail:s,authKey:o,ttl:a}),z=u,le=y,Ge=g,ze=w,Be=x,We=O,j=h,pe=l,P=f,Ie=A,S=m,ye=d.join("%20");async function xe(p,I){let b=`${z}${ze}`,U=await fetch(b,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:Fa({code:p,grant_type:"authorization_code",client_id:j,client_secret:pe,redirect_uri:I})});if(!U.ok)throw new Error("Authentication failed");let $=await U.json();return{...$,expires:Date.now()+$.expires_in*1e3}}async function si(p){if(Tn({cookieHeader:p.request.headers.cookie,cookieName:t})){let U=p.request.hostname.match(/[^.]+\.[^.]+$/i)[0];p.set("Set-Cookie",Ce.default.serialize(t,"",{domain:`.${U}`,path:"/",maxAge:0}))}let b=Zt(p);if(O){let U=encodeURIComponent(`${p.request.protocol}://${p.request.host}${b}`);p.set("Location",`${z}${We}?client_id=${j}&returnTo=${U}`)}else p.set("Location",b);p.status=302}async function oi(p){let I=p.request.href.split("?")[0],b=await xe(p.request.query.code,I),U=xn.default.generate(),$=await te.getSalt(),M=`${U}.${$}`,Ve=await te.deriveAesGcmKey(U,$),W=await te.encrypt(Ve,JSON.stringify(b));await _.put(U,W);let Xe=p.request.hostname.match(/[^.]+\.[^.]+$/i)[0];p.status=302,Ge==="query"?p.set("Location",`${p.request.query.state}?auth=${M}`):(p.set("Set-Cookie",Ce.default.serialize(t,M,{httpOnly:e,domain:`.${Xe}`,path:"/",maxAge:60*60*24*365})),p.set("Location",p.request.query.state))}async function ai(p,I){let[b,U]=I.split("."),$=await _.get(b);if($){let M=await te.deriveAesGcmKey(b,U),Ve=await te.decrypt(M,$),W=JSON.parse(Ve);if(W.expires<Date.now()){W=await Ut({refresh_token:W.refresh_token,clientId:j,authDomain:z,clientSecret:pe});let Xe=await te.encrypt(M,JSON.stringify(W));await _.put(b,Xe)}p.state.accessToken=W.access_token,p.state.accessToken&&(p.request.headers.authorization=`bearer ${p.state.accessToken}`)}else{let M=p.request.hostname.match(/[^.]+\.[^.]+$/i)[0];p.set("Set-Cookie",Ce.default.serialize(t,"",{domain:`.${M}`,maxAge:0}))}}function Zt(p){let I=ae.get(p,"request.query.redirect-to");if(I)return I;let b=ae.get(p,"request.headers.referer");return b||"/"}async function ui(p){if(p.request.method==="OPTIONS")p.status=200;else{let I=Zt(p),b=encodeURIComponent(I||"/"),U=encodeURIComponent(`${p.request.protocol}://${p.request.host}${le}`);p.status=302,p.set("location",`${z}${Be}/authorize?state=${b}&client_id=${j}&response_type=code&scope=${ye}&audience=${P}&redirect_uri=${U}`)}}async function ci(p,I){if(p.request.method==="OPTIONS")await I(p);else if(ae.get(p,"request.headers.authorization","").toLowerCase().startsWith("bearer "))ae.set(p,"state.access_token",p.request.headers.authorization.slice(7)),await I(p);else{let b=ae.get(p,"request.query.auth")||Tn({cookieHeader:p.request.headers.cookie,cookieName:t});if(b&&await ai(p,b),ae.get(p,"state.accessToken")||r)await I(p);else if(_a(p.request.headers.accept)){let $=encodeURIComponent(p.request.href),M=encodeURIComponent(`${p.request.protocol}://${p.request.host}${le}`);p.status=302,p.set("location",`${z}${Be}/authorize?state=${$}&client_id=${j}&response_type=code&scope=${ye}&audience=${P}&redirect_uri=${M}`)}else p.status=403,p.body="Forbidden"}}return async(p,I)=>{switch(p.request.path){case le:await oi(p);break;case Ie:await si(p);break;case S:await ui(p);break;default:await ci(p,I)}}}var Un=C(H());var Ra={get:Un.default};function Oa(t){let e={};return Object.keys(t).forEach(r=>{r.startsWith("cf")||(e[r]=t[r])}),e}function Rt(t){let{localOriginOverride:e,backend:r}=t;return async n=>{let i=process.env.LOCAL?`${e||n.request.origin}${n.request.path}`:`${r}${n.request.path}`,s={headers:Oa(n.request.headers),method:n.request.method,redirect:"manual"};if(N.methodsMethodsWithBody.indexOf(n.request.method)!==-1&&Ra.get(n,"event.request.body")){let u=n.event.request.clone();s.body=u.body}let o=await fetch(i,s);n.body=o.body,n.status=o.status;let a=T.instanceToJson(o.headers);Object.keys(a).forEach(u=>{n.set(u,a[u])})}}function Ot({body:t="",headers:e={},status:r=200}){return async n=>{t instanceof Object?(n.body=JSON.stringify(t),n.set("Content-Type","application/json")):n.body=T.resolveParams(t,n.params),n.status=r,Object.keys(e).forEach(i=>{n.set(i,T.resolveParams(e[i],n.params))})}}var Fn=C(H()),_n=C($e()),kt={get:Fn.default,set:_n.default};function Nt({type:t="IP",scope:e="default",limit:r=1e3}){let n={};function i(o,a){let u=a["x-real-ip"];return t==="IP"?`minute.${o}.${e}.${u}`:`minute.${o}.${e}.account`}function s(o){let a=kt.get(n,"minutes",{});Object.keys(a).forEach(u=>{u!==o&&delete n.minutes.minute})}return async(o,a)=>{let u=Math.trunc(Date.now()/6e4),h=Math.trunc(u*60+60-Date.now()/1e3),l=i(u,o.request.headers),f=kt.get(n,l,0);if(["HEAD","OPTIONS"].indexOf(o.request.method)===-1&&(f+=1),kt.set(n,l,f),r<f){o.status=429;return}s(u),await a(o)}}var Rn=C(Re());function ka(t,e={}){if(t&&e.forcePathStyle){let r=new URL(t);return`${r.protocol}//${r.host}/${e.bucket}`}if(t){let r=new URL(t);return`${r.protocol}//${e.bucket}.${r.host}`}return e.forcePathStyle&&e.region?`https://s3.${e.region}.amazonaws.com/${e.bucket}`:e.forcePathStyle?`https://s3.amazonaws.com/${e.bucket}`:e.region?`https://${e.bucket}.s3.${e.region}.amazonaws.com`:`https://${e.bucket}.s3.amazonaws.com`}function Pt({accessKeyId:t,secretAccessKey:e,bucket:r,region:n,endpoint:i,forcePathStyle:s,enableBucketOperations:o=!1}){let a=new Rn.AwsClient({accessKeyId:t,region:n,secretAccessKey:e}),u=ka(i,{region:n,bucket:r,forcePathStyle:s});return async h=>{if(h.params.file===void 0&&!o){h.status=404,h.body=N.http.statusMessages[404],h.set("Content-Type","text/plain");return}let l=h.params.file?T.resolveParams(`${u}/{file}`,h.params):u,f={};h.request.headers.range&&(f.range=h.request.headers.range);let d=await a.fetch(l,{method:h.method||h.request.method,headers:f});h.status=d.status,h.body=d.body;let y=T.instanceToJson(d.headers);Object.keys(y).forEach(g=>{h.set(g,y[g])})}}var $t;function On(t){return new Uint8Array(t.split("").map(r=>r.charCodeAt(0)))}async function Na(t){return $t||($t=await crypto.subtle.importKey("raw",On(t),{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"])),$t}async function Pa(t,e){let r=await Na(e),n=await crypto.subtle.sign({name:"HMAC"},r,On(t));return btoa(String.fromCharCode.apply(null,new Uint8Array(n))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function vt({secret:t}){return async(e,r)=>{let n=(e.request.path+e.request.search).replace(/([?|&]sign=[\w|-]+)/,"");if(await Pa(n,t)!==e.query.sign){e.status=403;return}await r(e)}}function qt({host:t}){if(!t)throw new Error("Need to specify a host for the split middleware.");return async(e,r)=>{let n=e.clone();n.cloned=!0,n.request={...n.request,href:n.request.href.replace(n.request.href,t),host:t},e.event.waitUntil(r(n)),await r(e)}}async function $a(t,e,r){let n=t.getReader(),i=e.getWriter(),s=new TextDecoder,o=new TextEncoder;for(;;){let{done:a,value:u}=await n.read();if(a)break;let h=s.decode(u),l=kn(h,r),f=o.encode(l);await i.write(f)}await i.close()}function va(t,e){return t.replace(/{{\$(\d)}}/g,(r,n)=>e[parseInt(n,10)])}function kn(t,e){return e.reduce((r,n)=>r.replace(n.regex,(...i)=>va(n.replace,i)),t)}function Mt({transforms:t=[],statusCodes:e=[200]}){let r=t.map(n=>({regex:new RegExp(n.regex,"g"),replace:n.replace}));return async(n,i)=>{await i(n);let{body:s}=n;if(e.indexOf(n.status)!==-1)if(typeof s=="string")n.body=kn(s,r);else{let{readable:o,writable:a}=new TransformStream;$a(s,a,r),n.body=o}}}async function qa({projectID:t="your-project-id",API_KEY:e="GCP_API_KEY",token:r="action-token",siteKey:n="siteKey",expectedAction:i="action-name"}){let o=await(await fetch(`https://recaptchaenterprise.googleapis.com/v1/projects/${t}/assessments?key=${e}`,{body:JSON.stringify({event:{token:r,siteKey:n,expectedAction:i}}),headers:{"Content-Type":"application/json"},method:"POST"})).json();return o.tokenProperties.valid?o.tokenProperties.action===i?(o.riskAnalysis.reasons.forEach(a=>{console.log(a)}),o.riskAnalysis.score):(console.error("The action attribute in your reCAPTCHA tag does not match the action you are expecting to score"),null):(console.error("The CreateAssessment call failed because the token was: "+o.tokenProperties.invalidReason),0)}function Ht({projectID:t,API_KEY:e,siteKey:r}){function n(i){return{token:i["g-recaptcha-token"],expectedAction:i["g-recaptcha-action"]}}return async(i,s)=>{let{token:o,expectedAction:a}=n(i.request.headers);if((await qa({projectID:t,API_KEY:e,token:o,siteKey:r,expectedAction:a})||0)<.5){i.status=409;return}await s(i)}}var ti=C(ei());var gu=t=>{if(typeof t!="string"||t===""||t.trim()==="")return!1;var e=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;return e.test(t)},wu=t=>(gu(t)&&(t=ti.Buffer.from(t,"base64").toString()),!new RegExp("(\b)(onS+)(s*)=|javascript|<(|/|[^/>][^>]+|/[^>][^>]+)>").test(t)),Au=(t,e,r)=>!(!wu(e)||!r[t](e));var Eu=t=>!(t===null||typeof t!="object"||Array.isArray(t)&&(!t[0]||typeof t[0]!="object")),ri=(t,e)=>{let r=Object.keys(t);for(let n of r){if(!e[n]&&isNaN(n))return!1;if(t[n]===null&&(t[n]=""),Eu(t[n])){if(!ri(t[n],e))return!1}else if(!Au(n,t[n],e))return!1}return!0},Su=t=>!(t==null||typeof t!="object"),bu=(t,e)=>{let r=t.query;return Su(r)?ri(r,e):!1};function Yt({allowedKeys:t}){return async(r,n)=>{if(!t){r.status=501;return}if(!bu(r,t)){r.status=422;return}await n(r)}}var ni={basicAuth:it,cache:at,cors:ut,geoDecorator:ct,jwt:ht,kvStorage:ft,kvStorageBinding:pt,lambda:dt,loadbalancer:At,logger:St,oauth2:_t,origin:Rt,rateLimit:Nt,response:Ot,s3:Pt,signature:vt,split:qt,transform:Mt,recaptcha:Ht,userInputValidation:Yt};module.exports=class{constructor(e=[],r={}){this.router=new ii.default,e.forEach(n=>{let i=r[n.handlerName]||ni[n.handlerName];if(!i)throw new Error(`Handler ${n.handlerName} is not supported`);this.router.add(n,i(n.options))})}async resolve(e){return this.router.resolve(e)}};
5
+ `)}async hexBodyHash(){let l=this.headers.get("X-Amz-Content-Sha256");if(l==null){if(this.body&&typeof this.body!="string"&&!("byteLength"in this.body))throw new Error("body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header");l=c(await i(this.body||""))}return l}}async function s(u,l){let f=await crypto.subtle.importKey("raw",typeof u=="string"?t.encode(u):u,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return crypto.subtle.sign("HMAC",f,t.encode(l))}async function i(u){return crypto.subtle.digest("SHA-256",typeof u=="string"?t.encode(u):u)}function c(u){return Array.prototype.map.call(new Uint8Array(u),l=>("0"+l.toString(16)).slice(-2)).join("")}function d(u){return u.replace(/[!'()*]/g,l=>"%"+l.charCodeAt(0).toString(16).toUpperCase())}function h(u,l){let{hostname:f,pathname:y}=u,w=f.replace("dualstack.","").match(/([^.]+)\.(?:([^.]*)\.)?amazonaws\.com(?:\.cn)?$/),[m,g]=(w||["",""]).slice(1,3);if(g==="us-gov")g="us-gov-west-1";else if(g==="s3"||g==="s3-accelerate")g="us-east-1",m="s3";else if(m==="iot")f.startsWith("iot.")?m="execute-api":f.startsWith("data.jobs.iot.")?m="iot-jobs-data":m=y==="/mqtt"?"iotdevicegateway":"iotdata";else if(m==="autoscaling"){let K=(l.get("X-Amz-Target")||"").split(".")[0];K==="AnyScaleFrontendService"?m="application-autoscaling":K==="AnyScaleScalingPlannerFrontendService"&&(m="autoscaling-plans")}else g==null&&m.startsWith("s3-")?(g=m.slice(3).replace(/^fips-|^external-1/,""),m="s3"):m.endsWith("-fips")?m=m.slice(0,-5):g&&/-\d$/.test(m)&&!/-\d$/.test(g)&&([m,g]=[g,m]);return[r[m]||m,g]}e.AwsClient=o,e.AwsV4Signer=a,Object.defineProperty(e,"__esModule",{value:!0})})});var ze=_((wd,nn)=>{var ja="Expected a function",Xr="__lodash_hash_undefined__",jr=1/0,Ya=9007199254740991,Za="[object Function]",Qa="[object GeneratorFunction]",es="[object Symbol]",ts=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,rs=/^\w*$/,ns=/^\./,os=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,as=/[\\^$.*+?()[\]{}|]/g,ss=/\\(\\)?/g,is=/^\[object .+?Constructor\]$/,cs=/^(?:0|[1-9]\d*)$/,ds=typeof global=="object"&&global&&global.Object===Object&&global,us=typeof self=="object"&&self&&self.Object===Object&&self,Rt=ds||us||Function("return this")();function ps(e,t){return e?.[t]}function hs(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch{}return t}var fs=Array.prototype,ls=Function.prototype,Yr=Object.prototype,Ot=Rt["__core-js_shared__"],Br=function(){var e=/[^.]+$/.exec(Ot&&Ot.keys&&Ot.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Zr=ls.toString,Be=Yr.hasOwnProperty,Qr=Yr.toString,ms=RegExp("^"+Zr.call(Be).replace(as,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Gr=Rt.Symbol,ys=fs.splice,gs=en(Rt,"Map"),He=en(Object,"create"),Vr=Gr?Gr.prototype:void 0,zr=Vr?Vr.toString:void 0;function ae(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function ws(){this.__data__=He?He(null):{}}function As(e){return this.has(e)&&delete this.__data__[e]}function Ss(e){var t=this.__data__;if(He){var r=t[e];return r===Xr?void 0:r}return Be.call(t,e)?t[e]:void 0}function Es(e){var t=this.__data__;return He?t[e]!==void 0:Be.call(t,e)}function bs(e,t){var r=this.__data__;return r[e]=He&&t===void 0?Xr:t,this}ae.prototype.clear=ws;ae.prototype.delete=As;ae.prototype.get=Ss;ae.prototype.has=Es;ae.prototype.set=bs;function he(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function Cs(){this.__data__=[]}function _s(e){var t=this.__data__,r=Ge(t,e);if(r<0)return!1;var n=t.length-1;return r==n?t.pop():ys.call(t,r,1),!0}function vs(e){var t=this.__data__,r=Ge(t,e);return r<0?void 0:t[r][1]}function Hs(e){return Ge(this.__data__,e)>-1}function Ps(e,t){var r=this.__data__,n=Ge(r,e);return n<0?r.push([e,t]):r[n][1]=t,this}he.prototype.clear=Cs;he.prototype.delete=_s;he.prototype.get=vs;he.prototype.has=Hs;he.prototype.set=Ps;function se(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function Ks(){this.__data__={hash:new ae,map:new(gs||he),string:new ae}}function Ts(e){return Ve(this,e).delete(e)}function xs(e){return Ve(this,e).get(e)}function Os(e){return Ve(this,e).has(e)}function Rs(e,t){return Ve(this,e).set(e,t),this}se.prototype.clear=Ks;se.prototype.delete=Ts;se.prototype.get=xs;se.prototype.has=Os;se.prototype.set=Rs;function Us(e,t,r){var n=e[t];(!(Be.call(e,t)&&tn(n,r))||r===void 0&&!(t in e))&&(e[t]=r)}function Ge(e,t){for(var r=e.length;r--;)if(tn(e[r][0],t))return r;return-1}function Is(e){if(!Le(e)||$s(e))return!1;var t=Bs(e)||hs(e)?ms:is;return t.test(Ls(e))}function Ws(e,t,r,n){if(!Le(e))return e;t=Ds(t,e)?[t]:Ns(t);for(var o=-1,a=t.length,s=a-1,i=e;i!=null&&++o<a;){var c=Fs(t[o]),d=r;if(o!=s){var h=i[c];d=n?n(h,c,i):void 0,d===void 0&&(d=Le(h)?h:ks(t[o+1])?[]:{})}Us(i,c,d),i=i[c]}return e}function Js(e){if(typeof e=="string")return e;if(It(e))return zr?zr.call(e):"";var t=e+"";return t=="0"&&1/e==-jr?"-0":t}function Ns(e){return rn(e)?e:qs(e)}function Ve(e,t){var r=e.__data__;return Ms(t)?r[typeof t=="string"?"string":"hash"]:r.map}function en(e,t){var r=ps(e,t);return Is(r)?r:void 0}function ks(e,t){return t=t??Ya,!!t&&(typeof e=="number"||cs.test(e))&&e>-1&&e%1==0&&e<t}function Ds(e,t){if(rn(e))return!1;var r=typeof e;return r=="number"||r=="symbol"||r=="boolean"||e==null||It(e)?!0:rs.test(e)||!ts.test(e)||t!=null&&e in Object(t)}function Ms(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function $s(e){return!!Br&&Br in e}var qs=Ut(function(e){e=Vs(e);var t=[];return ns.test(e)&&t.push(""),e.replace(os,function(r,n,o,a){t.push(o?a.replace(ss,"$1"):n||r)}),t});function Fs(e){if(typeof e=="string"||It(e))return e;var t=e+"";return t=="0"&&1/e==-jr?"-0":t}function Ls(e){if(e!=null){try{return Zr.call(e)}catch{}try{return e+""}catch{}}return""}function Ut(e,t){if(typeof e!="function"||t&&typeof t!="function")throw new TypeError(ja);var r=function(){var n=arguments,o=t?t.apply(this,n):n[0],a=r.cache;if(a.has(o))return a.get(o);var s=e.apply(this,n);return r.cache=a.set(o,s),s};return r.cache=new(Ut.Cache||se),r}Ut.Cache=se;function tn(e,t){return e===t||e!==e&&t!==t}var rn=Array.isArray;function Bs(e){var t=Le(e)?Qr.call(e):"";return t==Za||t==Qa}function Le(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Gs(e){return!!e&&typeof e=="object"}function It(e){return typeof e=="symbol"||Gs(e)&&Qr.call(e)==es}function Vs(e){return e==null?"":Js(e)}function zs(e,t,r){return e==null?e:Ws(e,t,r)}nn.exports=zs});var pn=_(kt=>{"use strict";kt.parse=ri;kt.serialize=ni;var Qs=decodeURIComponent,ei=encodeURIComponent,ti=/; */,je=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function ri(e,t){if(typeof e!="string")throw new TypeError("argument str must be a string");for(var r={},n=t||{},o=e.split(ti),a=n.decode||Qs,s=0;s<o.length;s++){var i=o[s],c=i.indexOf("=");if(!(c<0)){var d=i.substr(0,c).trim(),h=i.substr(++c,i.length).trim();h[0]=='"'&&(h=h.slice(1,-1)),r[d]==null&&(r[d]=oi(h,a))}}return r}function ni(e,t,r){var n=r||{},o=n.encode||ei;if(typeof o!="function")throw new TypeError("option encode is invalid");if(!je.test(e))throw new TypeError("argument name is invalid");var a=o(t);if(a&&!je.test(a))throw new TypeError("argument val is invalid");var s=e+"="+a;if(n.maxAge!=null){var i=n.maxAge-0;if(isNaN(i)||!isFinite(i))throw new TypeError("option maxAge is invalid");s+="; Max-Age="+Math.floor(i)}if(n.domain){if(!je.test(n.domain))throw new TypeError("option domain is invalid");s+="; Domain="+n.domain}if(n.path){if(!je.test(n.path))throw new TypeError("option path is invalid");s+="; Path="+n.path}if(n.expires){if(typeof n.expires.toUTCString!="function")throw new TypeError("option expires is invalid");s+="; Expires="+n.expires.toUTCString()}if(n.httpOnly&&(s+="; HttpOnly"),n.secure&&(s+="; Secure"),n.sameSite){var c=typeof n.sameSite=="string"?n.sameSite.toLowerCase():n.sameSite;switch(c){case!0:s+="; SameSite=Strict";break;case"lax":s+="; SameSite=Lax";break;case"strict":s+="; SameSite=Strict";break;case"none":s+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return s}function oi(e,t){try{return t(e)}catch{return e}}});var fn=_((Jd,hn)=>{"use strict";var Ye=1;function ai(){return Ye=(Ye*9301+49297)%233280,Ye/233280}function si(e){Ye=e}hn.exports={nextValue:ai,seed:si}});var xe=_((Nd,gn)=>{"use strict";var Dt=fn(),ce="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-",z,ln,Te;function Mt(){Te=!1}function mn(e){if(!e){z!==ce&&(z=ce,Mt());return}if(e!==z){if(e.length!==ce.length)throw new Error("Custom alphabet for shortid must be "+ce.length+" unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter(function(r,n,o){return n!==o.lastIndexOf(r)});if(t.length)throw new Error("Custom alphabet for shortid must be "+ce.length+" unique characters. These characters were not unique: "+t.join(", "));z=e,Mt()}}function ii(e){return mn(e),z}function ci(e){Dt.seed(e),ln!==e&&(Mt(),ln=e)}function di(){z||mn(ce);for(var e=z.split(""),t=[],r=Dt.nextValue(),n;e.length>0;)r=Dt.nextValue(),n=Math.floor(r*e.length),t.push(e.splice(n,1)[0]);return t.join("")}function yn(){return Te||(Te=di(),Te)}function ui(e){var t=yn();return t[e]}function pi(){return z||ce}gn.exports={get:pi,characters:ii,seed:ci,lookup:ui,shuffled:yn}});var An=_((kd,wn)=>{"use strict";var $t=typeof window=="object"&&(window.crypto||window.msCrypto),qt;!$t||!$t.getRandomValues?qt=function(e){for(var t=[],r=0;r<e;r++)t.push(Math.floor(Math.random()*256));return t}:qt=function(e){return $t.getRandomValues(new Uint8Array(e))};wn.exports=qt});var En=_((Dd,Sn)=>{Sn.exports=function(e,t,r){for(var n=(2<<Math.log(t.length-1)/Math.LN2)-1,o=-~(1.6*n*r/t.length),a="";;)for(var s=e(o),i=o;i--;)if(a+=t[s[i]&n]||"",a.length===+r)return a}});var Cn=_((Md,bn)=>{"use strict";var hi=xe(),fi=An(),li=En();function mi(e){for(var t=0,r,n="";!r;)n=n+li(fi,hi.get(),1),r=e<Math.pow(16,t+1),t++;return n}bn.exports=mi});var Hn=_((qd,vn)=>{"use strict";var Ze=Cn(),$d=xe(),yi=1567752802062,gi=7,Qe,_n;function wi(e){var t="",r=Math.floor((Date.now()-yi)*.001);return r===_n?Qe++:(Qe=0,_n=r),t=t+Ze(gi),t=t+Ze(e),Qe>0&&(t=t+Ze(Qe)),t=t+Ze(r),t}vn.exports=wi});var Kn=_((Fd,Pn)=>{"use strict";var Ai=xe();function Si(e){if(!e||typeof e!="string"||e.length<6)return!1;var t=new RegExp("[^"+Ai.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]");return!t.test(e)}Pn.exports=Si});var xn=_((Ld,Tn)=>{"use strict";Tn.exports=0});var Un=_((Bd,B)=>{"use strict";var Ft=xe(),Ei=Hn(),bi=Kn(),On=xn()||0;function Ci(e){return Ft.seed(e),B.exports}function _i(e){return On=e,B.exports}function vi(e){return e!==void 0&&Ft.characters(e),Ft.shuffled()}function Rn(){return Ei(On)}B.exports=Rn;B.exports.generate=Rn;B.exports.seed=Ci;B.exports.worker=_i;B.exports.characters=vi;B.exports.isValid=bi});var Wn=_((Gd,In)=>{"use strict";In.exports=Un()});var ho=v(_r());var kr=v(M()),xa={get:kr.default};function At(e){e.status=401,e.body="Unauthorized",e.set("WWW-Authenticate","Basic")}function St(e){return async(t,r)=>{if(t.request.path===e.logoutPath)return At(t);let n=xa.get(t,"request.headers.authorization");if(!n||!n.startsWith("Basic "))return At(t);let o=e.users.map(i=>i.authToken),a=n.substring(6),s=o.indexOf(a);return s===-1?At(t):(t.state.user=e.users[s].username,r(t))}}var Dr=caches.default;async function Oa(e){return await Dr.match(e)}async function Ra(e,t){return Dr.put(e.href,t)}var Et={get:Oa,set:Ra};async function Ua(e){let t=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(r)).map(a=>a.toString(16).padStart(2,"0")).join("")}var Mr=Ua;function Ia(e,t={}){return Object.keys(t).reduce((r,n)=>r.replace(`{${n}}`,t[n]),e)}function bt(e){return[...e].reduce((t,r)=>{let n={};return n[r[0]]=r[1],{...t,...n}},{})}var S={resolveParams:Ia,instanceToJson:bt};var Wa=["x-ratelimit-count","x-ratelimit-limit","x-ratelimit-reset","x-cache-hit"];async function Ja(e){return["POST","PATCH"].indexOf(e.method)===-1?null:e.text()}async function Na(e,t){if(!t)return e.event.request;let r=t.match(/{.*?}/gi).map(a=>a.slice(1,-1)),n={};for(let a=0;a<r.length;a+=1){let s=r[a],i=s.split(":");switch(i[0]){case"method":n[s]=e.request.method;break;case"path":n[s]=e.request.path;break;case"bodyHash":n[s]=await Mr(await Ja(e.request));break;case"header":n[s]=e.request.headers[i[1]]||"";break;default:n[s]=s}}let o=encodeURIComponent(t.replace(/({(.*?)})/gi,(a,s,i)=>n[i]));return new Request(`http://${e.request.hostname}/${o}`)}function Ct({cacheDuration:e,cacheKeyTemplate:t,headerBlacklist:r=Wa}){return async(n,o)=>{let a=await Na(n,t),s=await Et.get(a);if(s){n.body=s.body,n.status=s.status;let i=bt(s.headers);Object.keys(i).forEach(c=>{n.set(c,i[c])}),n.set("X-Cache-Hit",!0)}else{await o(n);let i;n.body.tee?[n.body,i]=n.body.tee():i=n.body;let c=new Response(i,{status:n.status});Object.keys(n.response.headers).forEach(d=>{r.indexOf(d.toLowerCase())===-1&&c.headers.set(d,n.response.headers[d])}),e&&(c.headers.delete("Cache-Control"),c.headers.set("Cache-Control",`max-age=${e}`)),n.event.waitUntil(Et.set(a,c))}}}function _t({allowedOrigins:e=["*"],allowedMethods:t=["GET","PUT","POST","PATCH","DELETE","HEAD","OPTIONS"],allowCredentials:r=!0,allowedHeaders:n=["Content-Type"],allowedExposeHeaders:o=["WWW-Authenticate","Server-Authorization"],maxAge:a=600,optionsSuccessStatus:s=204,terminatePreflight:i=!1}){return async(c,d)=>{let{method:h}=c.request,{origin:u}=c.request.headers,l=c.request.headers["access-control-request-headers"];if(ka(c,u,e),Da(c,r),Fa(c,o),h==="OPTIONS"&&(Ma(c,t),$a(c,l,n),qa(c,a),i)){c.status=s,c.set("Content-Length","0"),c.body="";return}await d(c)}}function ka(e,t,r){Array.isArray(r)&&(r[0]==="*"?e.set("Access-Control-Allow-Origin","*"):r.indexOf(t)!==-1&&(e.set("Access-Control-Allow-Origin",t),e.set("Vary","Origin")))}function Da(e,t){t&&e.set("Access-Control-Allow-Credentials",t)}function Ma(e,t){e.set("Access-Control-Allow-Methods",t.join(","))}function $a(e,t,r){r.length===0&&t?e.set("Access-Control-Allow-Headers",t):r.length&&e.set("Access-Control-Allow-Headers",r.join(","))}function qa(e,t){t&&e.set("Access-Control-Max-Age",t)}function Fa(e,t){t.length&&e.set("Access-Control-Expose-Headers",t.join(","))}var La={AF:"AS",AL:"EU",AQ:"AN",DZ:"AF",AS:"OC",AD:"EU",AO:"AF",AG:"NA",AZ:"EU",AR:"SA",AU:"OC",AT:"EU",BS:"NA",BH:"AS",BD:"AS",AM:"EU",BB:"NA",BE:"EU",BM:"NA",BT:"AS",BO:"SA",BA:"EU",BW:"AF",BV:"AN",BR:"SA",BZ:"NA",IO:"AS",SB:"OC",VG:"NA",BN:"AS",BG:"EU",MM:"AS",BI:"AF",BY:"EU",KH:"AS",CM:"AF",CA:"NA",CV:"AF",KY:"NA",CF:"AF",LK:"AS",TD:"AF",CL:"SA",CN:"AS",TW:"AS",CX:"AS",CC:"AS",CO:"SA",KM:"AF",YT:"AF",CG:"AF",CD:"AF",CK:"OC",CR:"NA",HR:"EU",CU:"NA",CY:"EU",CZ:"EU",BJ:"AF",DK:"EU",DM:"NA",DO:"NA",EC:"SA",SV:"NA",GQ:"AF",ET:"AF",ER:"AF",EE:"EU",FO:"EU",FK:"SA",GS:"AN",FJ:"OC",FI:"EU",AX:"EU",FR:"EU",GF:"SA",PF:"OC",TF:"AN",DJ:"AF",GA:"AF",GE:"EU",GM:"AF",PS:"AS",DE:"EU",GH:"AF",GI:"EU",KI:"OC",GR:"EU",GL:"NA",GD:"NA",GP:"NA",GU:"OC",GT:"NA",GN:"AF",GY:"SA",HT:"NA",HM:"AN",VA:"EU",HN:"NA",HK:"AS",HU:"EU",IS:"EU",IN:"AS",ID:"AS",IR:"AS",IQ:"AS",IE:"EU",IL:"AS",IT:"EU",CI:"AF",JM:"NA",JP:"AS",KZ:"EU",JO:"AS",KE:"AF",KP:"AS",KR:"AS",KW:"AS",KG:"AS",LA:"AS",LB:"AS",LS:"AF",LV:"EU",LR:"AF",LY:"AF",LI:"EU",LT:"EU",LU:"EU",MO:"AS",MG:"AF",MW:"AF",MY:"AS",MV:"AS",ML:"AF",MT:"EU",MQ:"NA",MR:"AF",MU:"AF",MX:"NA",MC:"EU",MN:"AS",MD:"EU",ME:"EU",MS:"NA",MA:"AF",MZ:"AF",OM:"AS",NA:"AF",NR:"OC",NP:"AS",NL:"EU",AN:"NA",CW:"NA",AW:"NA",SX:"NA",BQ:"NA",NC:"OC",VU:"OC",NZ:"OC",NI:"NA",NE:"AF",NG:"AF",NU:"OC",NF:"OC",NO:"EU",MP:"OC",UM:"OC",FM:"OC",MH:"OC",PW:"OC",PK:"AS",PA:"NA",PG:"OC",PY:"SA",PE:"SA",PH:"AS",PN:"OC",PL:"EU",PT:"EU",GW:"AF",TL:"AS",PR:"NA",QA:"AS",RE:"AF",RO:"EU",RU:"EU",RW:"AF",BL:"NA",SH:"AF",KN:"NA",AI:"NA",LC:"NA",MF:"NA",PM:"NA",VC:"NA",SM:"EU",ST:"AF",SA:"AS",SN:"AF",RS:"EU",SC:"AF",SL:"AF",SG:"AS",SK:"EU",VN:"AS",SI:"EU",SO:"AF",ZA:"AF",ZW:"AF",ES:"EU",SS:"AF",EH:"AF",SD:"AF",SR:"SA",SJ:"EU",SZ:"AF",SE:"EU",CH:"EU",SY:"AS",TJ:"AS",TH:"AS",TG:"AF",TK:"OC",TO:"OC",TT:"NA",AE:"AS",TN:"AF",TR:"EU",TM:"AS",TC:"NA",TV:"OC",UG:"AF",UA:"EU",MK:"EU",EG:"AF",GB:"EU",GG:"EU",JE:"EU",IM:"EU",TZ:"AF",US:"NA",VI:"NA",BF:"AF",UY:"SA",UZ:"AS",VE:"SA",WF:"OC",WS:"OC",YE:"AS",ZM:"AF",XX:"XX"};function vt(){return async(e,t)=>{let r=e.request.headers["cf-ipcountry"]||"XX";e.request.headers["proxy-continent"]=La[r],await t(e)}}function Ba(e){let t=e.split("."),r=JSON.parse(atob(t[0])),n=JSON.parse(atob(t[1])),o=atob(t[2].replace(/-/g,"+").replace(/_/g,"/"));return{header:r,payload:n,signature:o,raw:{header:t[0],payload:t[1],signature:t[2]}}}function Ht({jwksUri:e,allowPublicAccess:t=!1}){async function r(){return(await(await fetch(e)).json()).keys}async function n(a){let i=new TextEncoder().encode([a.raw.header,a.raw.payload].join(".")),c=new Uint8Array(Array.from(a.signature).map(u=>u.charCodeAt(0))),d=await r();return(await Promise.all(d.map(async u=>{let l=await crypto.subtle.importKey("jwk",u,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["verify"]);return crypto.subtle.verify("RSASSA-PKCS1-v1_5",l,c,i)}))).some(u=>u)}async function o(a,s){if(a.request.method==="OPTIONS")return s(a);if((a.request.headers.authorization||"").toLowerCase().startsWith("bearer")){let c=Ba(a.request.headers.authorization.slice(7)),d=new Date(c.payload.exp*1e3),h=new Date(Date.now());if(d<=h)return!1;if(await n(c))return a.state.user=c.payload,s(a)}return t?s(a):(a.status=403,a.body="Forbidden",a)}return o}var $r=v(M()),Ga={get:$r.default},oe=class{constructor({accountId:t,namespace:r,authEmail:n,authKey:o,ttl:a}){this.accountId=t,this.namespace=r,this.authEmail=n,this.authKey=o,this.ttl=a}getNamespaceUrl(){return new URL(`https://api.cloudflare.com/client/v4/accounts/${this.accountId}/storage/kv/namespaces/${this.namespace}`)}getUrlForKey(t){return new URL(`${this.getNamespaceUrl()}/values/${t}`)}async list(t,r=10){let n=`${this.getNamespaceUrl()}/keys?prefix=${t}&limit=${r}`,o=await fetch(n,{headers:{"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey}});return o.ok?o.json():null}async get(t,r){let n=this.getUrlForKey(t),o=await fetch(n,{headers:{"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey}});if(o.ok)switch(r){case"json":return o.json();case"stream":return o;case"arrayBuffer":return o.arrayBuffer();default:return o.text()}return null}async getWithMetadata(t,r){let[n,o]=await Promise.all([this.get(t,r),this.list(t)]),a=Ga.get(o,"result.0.metadata",{});return{value:n,metadata:a}}async put(t,r,n={}){let o=this.getUrlForKey(t),a=new URLSearchParams;this.ttl&&a.append("expiration_ttl",this.ttl.toString());let s={"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey};o.search=a.toString();let i=new FormData;return i.append("value",r),i.append("metadata",JSON.stringify(n)),(await fetch(o.toString(),{method:"PUT",headers:s,body:r})).ok}async delete(t){let r=this.getUrlForKey(t);return fetch(r,{method:"DELETE",headers:{"X-Auth-Email":this.authEmail,"X-Auth-Key":this.authKey}})}};var x={methodsMethodsWithBody:["POST","PUT","PATCH"],http:{statusMessages:{404:"Not Found"}},mime:{css:"text/css",csv:"text/csv",html:"text/html",ico:"image/microsoft.vnd.icon",jpeg:"image/jpeg",js:"application/javascript",json:"application/json",png:"image/png",svg:"image/svg+xml",xml:"application/xml"}};function Va(e,t,r){if(e==="/"&&r)return r;let n=e.split("/").pop();return n.split(".").pop()!==n?e:`${e}.${t}`}function Pt({kvAccountId:e,kvNamespace:t,kvAuthEmail:r,kvAuthKey:n,kvBasePath:o="",kvKey:a="{file}",defaultExtension:s="html",defaultIndexDocument:i,defaultErrorDocument:c,mime:d={},mode:h="rest"}){let u=new oe({accountId:e,namespace:t,authEmail:r,authKey:n,mode:h}),l={...x.mime,...d};return async f=>{let y=S.resolveParams(a,f.params),w=y===""&&i?i:Va(y,s),m=await u.get(o+w);!m&&c&&(m=await u.get(o+c)),m?(f.status=200,f.body=m,f.set("Content-Type",l[w.split(".").pop()]||"text/plain")):(f.status=404,f.body=x.http.statusMessages[404],f.set("Content-Type","text/plain"))}}var qr=v(M());var Kt={get:qr.default};function za(e,t,r){if(e==="/"&&r)return r;let n=e.split("/").pop();return n.split(".").pop()!==n?e:`${e}.${t}`}function Xa(e,t){let r=Kt.get(e,"headers.if-none-match"),n=Kt.get(t,"metadata.headers.etag");return r?r===n:!1}function Tt({kvNamespaceBinding:e,kvBasePath:t="",kvKey:r="{file}",defaultExtension:n="html",defaultIndexDocument:o,defaultErrorDocument:a}){async function s(i){return await global[e].getWithMetadata(i)}return async i=>{let c=S.resolveParams(r,i.params),d=c===""&&o?o:za(c,n),h=await s(t+d);if(!h&&a&&(h=await s(t+a)),h)if(Xa(i.request,h))i.status=304;else{i.status=h.status,i.body=h.value;let u=Kt.get(h,"metadata.headers",{});Object.keys(u).forEach(l=>{i.set(l,u[l])})}else i.status=404,i.body=x.http.statusMessages[404],i.set("Content-Type","text/plain")}}var Lr=v(Fe());function xt({accessKeyId:e,secretAccessKey:t,region:r,lambdaName:n}){let o=new Lr.AwsClient({accessKeyId:e,secretAccessKey:t});return async a=>{let s=`https://lambda.${r}.amazonaws.com/2015-03-31/functions/${n}/invocations`,i={},c=await o.fetch(s,{body:JSON.stringify(i)});a.status=c.status,a.body=c.body;let d=S.instanceToJson(c.headers);Object.keys(d).forEach(h=>{a.set(h,d[h])})}}var an=v(M()),sn=v(ze());var on={get:an.default,set:sn.default};function Xs(e){let t={};return Object.keys(e).forEach(r=>{r.startsWith("cf")||(t[r]=e[r])}),t}function js(e){return e[Math.floor(Math.random()*e.length)]}function Wt({sources:e=[]}){return async t=>{let r=js(e),n={method:t.request.method,headers:Xs(t.request.headers),redirect:"manual",cf:t.request.cf};if(x.methodsMethodsWithBody.indexOf(t.request.method)!==-1&&on.get(t,"event.request.body")){let i=t.event.request.clone();n.body=i.body}let o=S.resolveParams(r.url,t.params);if(r.resolveOverride){let i=S.resolveParams(r.resolveOverride,t.request.params);on.set(n,"cf.resolveOverride",i)}let a=await fetch(o+t.request.search,n);t.body=a.body,t.status=a.status;let s=S.instanceToJson(a.headers);Object.keys(s).forEach(i=>{t.set(i,s[i])})}}var un=v(M());var Jt={name:"@ahmadissa/cloudworker-proxy",version:"1.0.25",description:"An api gateway for cloudflare workers",license:"MIT",repository:{type:"git",url:"git+https://github.com/ahmadissa/cloudworker-proxy.git"},bugs:{url:"https://github.com/ahmadissa/cloudworker-proxy/issues"},homepage:"https://github.com/ahmadissa/cloudworker-proxy#readme",author:"Markus Ahlstrand",keywords:["cloudflare","workers","api","gateway","proxy"],main:"dist/index.js",files:["dist/**"],scripts:{build:"esbuild --bundle src/index.ts --format=cjs --outdir=dist --sourcemap --minify",lint:"eslint src",package:"bun install; npm run build",test:"npm run unit && npm run lint","test:integration":"node integration/run.js",unit:"bun test","semantic-release":"semantic-release",prepare:"husky install"},release:{branches:["master"],plugins:["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator",["@semantic-release/npm",{npmPublish:!1}],["@semantic-release/git",{assets:["docs","package.json"],message:"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"}]]},dependencies:{aws4fetch:"1.0.13","cloudworker-router":"1.11.2",cookie:"0.4.1",jose:"^5.1.0","lodash.get":"4.4.2","lodash.set":"4.3.2",redaxios:"^0.5.1",shortid:"2.2.16"},devDependencies:{"@semantic-release/git":"^10.0.1","@types/jest":"^29.5.5","@types/mocha":"^10.0.1","@types/node":"^20.5.9","@typescript-eslint/eslint-plugin":"^6.6.0","@typescript-eslint/parser":"^6.6.0",bun:"1.0.3",dotenv:"8.2.0",esbuild:"^0.19.2",eslint:"7.13.0","eslint-config-airbnb-base":"14.2.1","eslint-config-prettier":"6.15.0","eslint-plugin-import":"2.22.1","eslint-plugin-prettier":"3.1.4","fetch-mock":"9.11.0",husky:"^8.0.3","node-fetch":"2.6.1",prettier:"2.1.2","semantic-release":"^22.0.4",typescript:"^5.2.2",wrangler:"^3.7.0"},directories:{example:"examples",test:"test"}};var ie=class{constructor({maxSize:t=10,maxSeconds:r=10,sink:n}){this.maxSize=t,this.maxSeconds=r,this.queue=[],this.sink=n,this.flushing=!1,this.timer=null}async push(t){return this.queue.push(t),this.queue.length>this.maxSize?this.flush():(this.timer||(this.timer=new Promise((r,n)=>{this.resolveTimer=r,this.rejectTimer=n,this.cancelationToken=setTimeout(async()=>{try{r(await this.flush())}catch(o){n(o)}},this.maxSeconds*1e3)})),this.timer)}async flush(){if(!this.flushing){this.flushing=!0;try{let t=this.queue.join(`
6
+ `);this.queue=[];let r=await this.sink(t);this.timer&&(clearTimeout(this.cancelationToken),this.resolveTimer(r))}catch(t){this.timer&&this.rejectTimer(t)}finally{this.timer=null,this.flushing=!1}}}};function cn(e,t=".",r=""){return e instanceof Object?Object.keys(e).reduce((n,o)=>e[o]==null?n:{...n,...cn(e[o],t,r+o+t)},{}):r.endsWith(t)?{[r.slice(0,r.length-1)]:e}:{[r]:e}}var Xe=cn;var Pe=class{constructor(t){this.url=t.url,this.contentType=t.contentType,this.delimiter=t.delimiter,this.chunker=new ie({sink:this.sendMessage.bind(this),...t})}async log(t){let r=Xe(t,this.delimiter);await this.chunker.push(JSON.stringify(r))}async sendMessage(t){return fetch(this.url,{body:t,method:"POST",headers:{"Content-Type":this.contentType}})}};var dn=v(Fe());var Ke=class{constructor(t){this.delimiter=t.delimiter,this.chunker=new ie({sink:this.sendMessage.bind(this),...t}),this.awsClient=new dn.AwsClient({accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,region:t.region}),this.streamName=t.streamName,this.region=t.region}async log(t){let r=Xe(t,this.delimiter);await this.chunker.push(JSON.stringify(r))}async sendMessage(t){let r=btoa(`${JSON.stringify(t)}
7
+ `),n=JSON.stringify({DeliveryStreamName:this.streamName,Record:{Data:r}}),o=`https://firehose.${this.region}.amazonaws.com`,a=new Request(o,{method:"POST",body:n,headers:{"X-Amz-Target":"Firehose_20150804.PutRecord","Content-Type":" application/x-amz-json-1.1"}});return this.awsClient.fetch(a)}};var I={get:un.default};async function Zs(e){return["POST","PATCH"].indexOf(e.method)===-1?null:e.text()}function Nt(e){let t;switch(e.type){case"http":t=new Pe(e);break;case"kinesis":t=new Ke(e);break;default:throw new Error(`Log service type not supported: ${e.type}`)}return async(r,n)=>{r.state["logger-startDate"]=new Date;let o=await Zs(r.request);try{await n(r);let a={message:"START",requestIp:I.get(r,"request.headers.x-real-ip"),requestId:I.get(r,"request.requestId"),request:{headers:I.get(r,"request.headers"),method:I.get(r,"request.method"),url:I.get(r,"request.href"),protocol:I.get(r,"request.protocol"),body:o},response:{status:r.status,headers:I.get(r,"response.headers")},handlers:I.get(r,"state.handlers",[]).join(","),route:I.get(r,"route.name"),timestamp:new Date().toISOString(),ttfb:new Date-r.state["logger-startDate"],redirectUrl:r.userRedirect,severity:30,proxyVersion:Jt.version};r.event.waitUntil(t.log(a))}catch(a){let s={request:{headers:I.get(r,"request.headers"),method:I.get(r,"request.method"),handlers:I.get(r,"state.handlers",[]).join(","),url:I.get(r,"request.href"),body:o},message:"ERROR",stack:a.stack,error:a.message,severity:50,proxyVersion:Jt.version};r.event.waitUntil(t.log(s))}}}var Oe=v(pn()),Dn=v(M()),Mn=v(ze()),$n=v(Wn());async function Lt({refresh_token:e,authDomain:t,clientId:r,clientSecret:n}){let o=`${t}/oauth/token`,a=await fetch(o,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",client_id:r,client_secret:n,refresh_token:e})});if(!a.ok)throw new Error("Authentication failed");let s=await a.json();return{...s,expires:Date.now()+s.expires_in*1e3,refresh_token:e}}var Jn="PBKDF2",Bt="AES-GCM",Hi="SHA-256",Pi="raw";function Ki(e){let t=atob(e.replace(/_/g,"/").replace(/-/g,"+")),r=t.length,n=new Uint8Array(r);for(let o=0;o<r;o+=1)n[o]=t.charCodeAt(o);return n.buffer}function Nn(e){let t="",r=new Uint8Array(e),n=r.byteLength;for(let o=0;o<n;o+=1)t+=String.fromCharCode(r[o]);return btoa(t).replace(/\//g,"_").replace(/\+/g,"-")}function Ti(e){return String.fromCharCode.apply(null,new Uint16Array(e))}function xi(e){let t=new ArrayBuffer(e.length*2),r=new Uint16Array(t);for(let n=0,o=e.length;n<o;n+=1)r[n]=e.charCodeAt(n);return t}async function Oi(e){let t=new TextEncoder;return crypto.subtle.importKey(Pi,t.encode(e),{name:Jn},!1,["deriveKey"])}async function Ri(e,t){let r=await Oi(e),o=new TextEncoder().encode(t.replace(/_/g,"/").replace(/-/g,"+"));return crypto.subtle.deriveKey({name:Jn,salt:o,iterations:1e3,hash:{name:Hi}},r,{name:Bt,length:256},!0,["encrypt","decrypt"])}async function Ui(){let e=crypto.getRandomValues(new Uint8Array(8));return Nn(e)}async function Ii(e,t){let r=Ki(t),n=r.slice(0,16),o=r.slice(16),a=await crypto.subtle.decrypt({name:Bt,iv:n},e,o);return Ti(a)}async function Wi(e,t){let r=crypto.getRandomValues(new Uint8Array(16)),n=await crypto.subtle.encrypt({name:Bt,iv:r},e,xi(t)),o=new Uint8Array(n.byteLength+r.byteLength);return o.set(r,0),o.set(new Uint8Array(n),r.byteLength),Nn(o)}var de={decrypt:Ii,deriveAesGcmKey:Ri,encrypt:Wi,getSalt:Ui};var fe={get:Dn.default,set:Mn.default};function kn({cookieHeader:e="",cookieName:t}){return Oe.default.parse(e)[t]}function Ji(e){return Object.keys(e).map(t=>`${t}=${encodeURIComponent(e[t])}`).join("&")}function Ni(e=""){return e.split(",").indexOf("text/html")!==-1}function Gt({cookieName:e="proxy",cookieHttpOnly:t=!0,allowPublicAccess:r=!1,kvAccountId:n,kvNamespace:o,kvAuthEmail:a,kvAuthKey:s,kvTtl:i=2592e3,oauth2AuthDomain:c,oauth2ClientId:d,oauth2ClientSecret:h,oauth2Audience:u,oauth2Scopes:l=[],oauth2CallbackPath:f="/callback",oauth2CallbackType:y="cookie",oauth2LogoutPath:w="/logout",oauth2LoginPath:m="/login",oauth2ServerTokenPath:g="/oauth/token",oauth2ServerAuthorizePath:K="",oauth2ServerLogoutPath:k}){let U=new oe({accountId:n,namespace:o,authEmail:a,authKey:s,ttl:i}),ee=c,Se=f,it=y,ct=g,Ne=K,dt=k,V=d,Ee=h,q=u,ke=w,C=m,Ce=l.join("%20");async function De(p,P){let H=`${ee}${ct}`,T=await fetch(H,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:Ji({code:p,grant_type:"authorization_code",client_id:V,client_secret:Ee,redirect_uri:P})});if(!T.ok)throw new Error("Authentication failed");let F=await T.json();return{...F,expires:Date.now()+F.expires_in*1e3}}async function fo(p){if(kn({cookieHeader:p.request.headers.cookie,cookieName:e})){let T=p.request.hostname.match(/[^.]+\.[^.]+$/i)[0];p.set("Set-Cookie",Oe.default.serialize(e,"",{domain:`.${T}`,path:"/",maxAge:0}))}let H=hr(p);if(k){let T=encodeURIComponent(`${p.request.protocol}://${p.request.host}${H}`);p.set("Location",`${ee}${dt}?client_id=${V}&returnTo=${T}`)}else p.set("Location",H);p.status=302}async function lo(p){let P=p.request.href.split("?")[0],H=await De(p.request.query.code,P),T=$n.default.generate(),F=await de.getSalt(),L=`${T}.${F}`,ut=await de.deriveAesGcmKey(T,F),te=await de.encrypt(ut,JSON.stringify(H));await U.put(T,te);let pt=p.request.hostname.match(/[^.]+\.[^.]+$/i)[0];p.status=302,it==="query"?p.set("Location",`${p.request.query.state}?auth=${L}`):(p.set("Set-Cookie",Oe.default.serialize(e,L,{httpOnly:t,domain:`.${pt}`,path:"/",maxAge:60*60*24*365})),p.set("Location",p.request.query.state))}async function mo(p,P){let[H,T]=P.split("."),F=await U.get(H);if(F){let L=await de.deriveAesGcmKey(H,T),ut=await de.decrypt(L,F),te=JSON.parse(ut);if(te.expires<Date.now()){te=await Lt({refresh_token:te.refresh_token,clientId:V,authDomain:ee,clientSecret:Ee});let pt=await de.encrypt(L,JSON.stringify(te));await U.put(H,pt)}p.state.accessToken=te.access_token,p.state.accessToken&&(p.request.headers.authorization=`bearer ${p.state.accessToken}`)}else{let L=p.request.hostname.match(/[^.]+\.[^.]+$/i)[0];p.set("Set-Cookie",Oe.default.serialize(e,"",{domain:`.${L}`,maxAge:0}))}}function hr(p){let P=fe.get(p,"request.query.redirect-to");if(P)return P;let H=fe.get(p,"request.headers.referer");return H||"/"}async function yo(p){if(p.request.method==="OPTIONS")p.status=200;else{let P=hr(p),H=encodeURIComponent(P||"/"),T=encodeURIComponent(`${p.request.protocol}://${p.request.host}${Se}`);p.status=302,p.set("location",`${ee}${Ne}/authorize?state=${H}&client_id=${V}&response_type=code&scope=${Ce}&audience=${q}&redirect_uri=${T}`)}}async function go(p,P){if(p.request.method==="OPTIONS")await P(p);else if(fe.get(p,"request.headers.authorization","").toLowerCase().startsWith("bearer "))fe.set(p,"state.access_token",p.request.headers.authorization.slice(7)),await P(p);else{let H=fe.get(p,"request.query.auth")||kn({cookieHeader:p.request.headers.cookie,cookieName:e});if(H&&await mo(p,H),fe.get(p,"state.accessToken")||r)await P(p);else if(Ni(p.request.headers.accept)){let F=encodeURIComponent(p.request.href),L=encodeURIComponent(`${p.request.protocol}://${p.request.host}${Se}`);p.status=302,p.set("location",`${ee}${Ne}/authorize?state=${F}&client_id=${V}&response_type=code&scope=${Ce}&audience=${q}&redirect_uri=${L}`)}else p.status=403,p.body="Forbidden"}}return async(p,P)=>{switch(p.request.path){case Se:await lo(p);break;case ke:await fo(p);break;case C:await yo(p);break;default:await go(p,P)}}}var qn=v(M());var ki={get:qn.default};function Di(e){let t={};return Object.keys(e).forEach(r=>{r.startsWith("cf")||(t[r]=e[r])}),t}function Vt(e){let{localOriginOverride:t,backend:r}=e;return async n=>{let o=process.env.LOCAL?`${t||n.request.origin}${n.request.path}`:`${r}${n.request.path}`,a={headers:Di(n.request.headers),method:n.request.method,redirect:"manual"};if(x.methodsMethodsWithBody.indexOf(n.request.method)!==-1&&ki.get(n,"event.request.body")){let c=n.event.request.clone();a.body=c.body}let s=await fetch(o,a);n.body=s.body,n.status=s.status;let i=S.instanceToJson(s.headers);Object.keys(i).forEach(c=>{n.set(c,i[c])})}}function zt({body:e="",headers:t={},status:r=200}){return async n=>{e instanceof Object?(n.body=JSON.stringify(e),n.set("Content-Type","application/json")):n.body=S.resolveParams(e,n.params),n.status=r,Object.keys(t).forEach(o=>{n.set(o,S.resolveParams(t[o],n.params))})}}var Fn=v(M()),Ln=v(ze()),Xt={get:Fn.default,set:Ln.default};function jt({type:e="IP",scope:t="default",limit:r=1e3}){let n={};function o(s,i){let c=i["x-real-ip"];return e==="IP"?`minute.${s}.${t}.${c}`:`minute.${s}.${t}.account`}function a(s){let i=Xt.get(n,"minutes",{});Object.keys(i).forEach(c=>{c!==s&&delete n.minutes.minute})}return async(s,i)=>{let c=Math.trunc(Date.now()/6e4),d=Math.trunc(c*60+60-Date.now()/1e3),h=o(c,s.request.headers),u=Xt.get(n,h,0);if(["HEAD","OPTIONS"].indexOf(s.request.method)===-1&&(u+=1),Xt.set(n,h,u),r<u){s.status=429;return}a(c),await i(s)}}var Bn=v(Fe());function Mi(e,t={}){if(e&&t.forcePathStyle){let r=new URL(e);return`${r.protocol}//${r.host}/${t.bucket}`}if(e){let r=new URL(e);return`${r.protocol}//${t.bucket}.${r.host}`}return t.forcePathStyle&&t.region?`https://s3.${t.region}.amazonaws.com/${t.bucket}`:t.forcePathStyle?`https://s3.amazonaws.com/${t.bucket}`:t.region?`https://${t.bucket}.s3.${t.region}.amazonaws.com`:`https://${t.bucket}.s3.amazonaws.com`}function Yt({accessKeyId:e,secretAccessKey:t,bucket:r,region:n,endpoint:o,forcePathStyle:a,enableBucketOperations:s=!1}){let i=new Bn.AwsClient({accessKeyId:e,region:n,secretAccessKey:t}),c=Mi(o,{region:n,bucket:r,forcePathStyle:a});return async d=>{if(d.params.file===void 0&&!s){d.status=404,d.body=x.http.statusMessages[404],d.set("Content-Type","text/plain");return}let h=d.params.file?S.resolveParams(`${c}/{file}`,d.params):c,u={};d.request.headers.range&&(u.range=d.request.headers.range);let l=await i.fetch(h,{method:d.method||d.request.method,headers:u});d.status=l.status,d.body=l.body;let f=S.instanceToJson(l.headers);Object.keys(f).forEach(y=>{d.set(y,f[y])})}}var Zt;function Gn(e){return new Uint8Array(e.split("").map(r=>r.charCodeAt(0)))}async function $i(e){return Zt||(Zt=await crypto.subtle.importKey("raw",Gn(e),{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"])),Zt}async function qi(e,t){let r=await $i(t),n=await crypto.subtle.sign({name:"HMAC"},r,Gn(e));return btoa(String.fromCharCode.apply(null,new Uint8Array(n))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Qt({secret:e}){return async(t,r)=>{let n=(t.request.path+t.request.search).replace(/([?|&]sign=[\w|-]+)/,"");if(await qi(n,e)!==t.query.sign){t.status=403;return}await r(t)}}function er({host:e}){if(!e)throw new Error("Need to specify a host for the split middleware.");return async(t,r)=>{let n=t.clone();n.cloned=!0,n.request={...n.request,href:n.request.href.replace(n.request.href,e),host:e},t.event.waitUntil(r(n)),await r(t)}}async function Fi(e,t,r){let n=e.getReader(),o=t.getWriter(),a=new TextDecoder,s=new TextEncoder;for(;;){let{done:i,value:c}=await n.read();if(i)break;let d=a.decode(c),h=Vn(d,r),u=s.encode(h);await o.write(u)}await o.close()}function Li(e,t){return e.replace(/{{\$(\d)}}/g,(r,n)=>t[parseInt(n,10)])}function Vn(e,t){return t.reduce((r,n)=>r.replace(n.regex,(...o)=>Li(n.replace,o)),e)}function tr({transforms:e=[],statusCodes:t=[200]}){let r=e.map(n=>({regex:new RegExp(n.regex,"g"),replace:n.replace}));return async(n,o)=>{await o(n);let{body:a}=n;if(t.indexOf(n.status)!==-1)if(typeof a=="string")n.body=Vn(a,r);else{let{readable:s,writable:i}=new TransformStream;Fi(a,i,r),n.body=s}}}async function Bi({projectID:e="your-project-id",API_KEY:t="GCP_API_KEY",token:r="action-token",siteKey:n="siteKey",expectedAction:o="action-name"}){let s=await(await fetch(`https://recaptchaenterprise.googleapis.com/v1/projects/${e}/assessments?key=${t}`,{body:JSON.stringify({event:{token:r,siteKey:n,expectedAction:o}}),headers:{"Content-Type":"application/json"},method:"POST"})).json();return s.tokenProperties.valid?s.tokenProperties.action===o?(s.riskAnalysis.reasons.forEach(i=>{console.log(i)}),s.riskAnalysis.score):(console.error("The action attribute in your reCAPTCHA tag does not match the action you are expecting to score"),null):(console.error("The CreateAssessment call failed because the token was: "+s.tokenProperties.invalidReason),0)}function rr({projectID:e,API_KEY:t,siteKey:r}){function n(o){return{token:o["g-recaptcha-token"],expectedAction:o["g-recaptcha-action"]}}return async(o,a)=>{let{token:s,expectedAction:i}=n(o.request.headers);if((await Bi({projectID:e,API_KEY:t,token:s,siteKey:r,expectedAction:i})||0)<.5){o.status=409;return}await a(o)}}var Gi=e=>!new RegExp("(\b)(onS+)(s*)=|javascript|<(|/|[^/>][^>]+|/[^>][^>]+)>").test(e),Vi=(e,t,r)=>!(!Gi(t)||!r[e](t)),zi=e=>!(e===null||typeof e!="object"||Array.isArray(e)&&(!e[0]||typeof e[0]!="object")),nr=(e,t)=>{let r=Object.keys(e);for(let n of r){if(!t[n]&&isNaN(n))return!1;if(e[n]===null&&(e[n]=""),zi(e[n])){if(!nr(e[n],t))return!1}else if(!Vi(n,e[n],t))return!1}return!0},Xi=e=>!(e==null||typeof e!="object"),ji=(e,t)=>{let r=e.query;return Xi(r)?nr(r,t):!1};async function Yi(e){if(["POST","PATCH"].indexOf(e.method)===-1)return{};try{let t=await e.text();return JSON.parse(t)}catch{}return{}}function or({allowedKeys:e}){return async(r,n)=>{if(!e){r.status=501;return}if(!ji(r,e)){r.status=422;return}let o=await Yi(r.request);if(!nr(o,e)){r.status=422;return}await n(r)}}var co=v(M());var E=crypto,D=e=>e instanceof CryptoKey;var O=new TextEncoder,W=new TextDecoder,gu=2**32;function X(...e){let t=e.reduce((o,{length:a})=>o+a,0),r=new Uint8Array(t),n=0;return e.forEach(o=>{r.set(o,n),n+=o.length}),r}var zn=e=>{let t=e;typeof t=="string"&&(t=O.encode(t));let r=32768,n=[];for(let o=0;o<t.length;o+=r)n.push(String.fromCharCode.apply(null,t.subarray(o,o+r)));return btoa(n.join(""))},J=e=>zn(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_");var le=class extends Error{static get code(){return"ERR_JOSE_GENERIC"}constructor(t){super(t),this.code="ERR_JOSE_GENERIC",this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}};var A=class extends le{constructor(){super(...arguments),this.code="ERR_JOSE_NOT_SUPPORTED"}static get code(){return"ERR_JOSE_NOT_SUPPORTED"}};var N=class extends le{constructor(){super(...arguments),this.code="ERR_JWS_INVALID"}static get code(){return"ERR_JWS_INVALID"}},j=class extends le{constructor(){super(...arguments),this.code="ERR_JWT_INVALID"}static get code(){return"ERR_JWT_INVALID"}};var et=E.getRandomValues.bind(E);function G(e,t="algorithm.name"){return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`)}function tt(e,t){return e.name===t}function ar(e){return parseInt(e.name.slice(4),10)}function ec(e){switch(e){case"ES256":return"P-256";case"ES384":return"P-384";case"ES512":return"P-521";default:throw new Error("unreachable")}}function tc(e,t){if(t.length&&!t.some(r=>e.usages.includes(r))){let r="CryptoKey does not support this operation, its usages must include ";if(t.length>2){let n=t.pop();r+=`one of ${t.join(", ")}, or ${n}.`}else t.length===2?r+=`one of ${t[0]} or ${t[1]}.`:r+=`${t[0]}.`;throw new TypeError(r)}}function jn(e,t,...r){switch(t){case"HS256":case"HS384":case"HS512":{if(!tt(e.algorithm,"HMAC"))throw G("HMAC");let n=parseInt(t.slice(2),10);if(ar(e.algorithm.hash)!==n)throw G(`SHA-${n}`,"algorithm.hash");break}case"RS256":case"RS384":case"RS512":{if(!tt(e.algorithm,"RSASSA-PKCS1-v1_5"))throw G("RSASSA-PKCS1-v1_5");let n=parseInt(t.slice(2),10);if(ar(e.algorithm.hash)!==n)throw G(`SHA-${n}`,"algorithm.hash");break}case"PS256":case"PS384":case"PS512":{if(!tt(e.algorithm,"RSA-PSS"))throw G("RSA-PSS");let n=parseInt(t.slice(2),10);if(ar(e.algorithm.hash)!==n)throw G(`SHA-${n}`,"algorithm.hash");break}case"EdDSA":{if(e.algorithm.name!=="Ed25519"&&e.algorithm.name!=="Ed448")throw G("Ed25519 or Ed448");break}case"ES256":case"ES384":case"ES512":{if(!tt(e.algorithm,"ECDSA"))throw G("ECDSA");let n=ec(t);if(e.algorithm.namedCurve!==n)throw G(n,"algorithm.namedCurve");break}default:throw new TypeError("CryptoKey does not support this operation")}tc(e,r)}function Yn(e,t,...r){if(r.length>2){let n=r.pop();e+=`one of type ${r.join(", ")}, or ${n}.`}else r.length===2?e+=`one of type ${r[0]} or ${r[1]}.`:e+=`of type ${r[0]}.`;return t==null?e+=` Received ${t}`:typeof t=="function"&&t.name?e+=` Received function ${t.name}`:typeof t=="object"&&t!=null&&t.constructor&&t.constructor.name&&(e+=` Received an instance of ${t.constructor.name}`),e}var $=(e,...t)=>Yn("Key must be ",e,...t);function sr(e,t,...r){return Yn(`Key for the ${e} algorithm must be `,t,...r)}var ir=e=>D(e),b=["CryptoKey"];var sc=(...e)=>{let t=e.filter(Boolean);if(t.length===0||t.length===1)return!0;let r;for(let n of t){let o=Object.keys(n);if(!r||r.size===0){r=new Set(o);continue}for(let a of o){if(r.has(a))return!1;r.add(a)}}return!0},me=sc;function ic(e){return typeof e=="object"&&e!==null}function R(e){if(!ic(e)||Object.prototype.toString.call(e)!=="[object Object]")return!1;if(Object.getPrototypeOf(e)===null)return!0;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}var rt=(e,t)=>{if(e.startsWith("RS")||e.startsWith("PS")){let{modulusLength:r}=t.algorithm;if(typeof r!="number"||r<2048)throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}};var Z=(e,t,r=0)=>{r===0&&(t.unshift(t.length),t.unshift(6));let n=e.indexOf(t[0],r);if(n===-1)return!1;let o=e.subarray(n,n+t.length);return o.length!==t.length?!1:o.every((a,s)=>a===t[s])||Z(e,t,n+1)},Qn=e=>{switch(!0){case Z(e,[42,134,72,206,61,3,1,7]):return"P-256";case Z(e,[43,129,4,0,34]):return"P-384";case Z(e,[43,129,4,0,35]):return"P-521";case Z(e,[43,101,110]):return"X25519";case Z(e,[43,101,111]):return"X448";case Z(e,[43,101,112]):return"Ed25519";case Z(e,[43,101,113]):return"Ed448";default:throw new A("Invalid or unsupported EC Key Curve or OKP Key Sub Type")}},pc=async(e,t,r,n,o)=>{let a,s,i=new Uint8Array(atob(r.replace(e,"")).split("").map(d=>d.charCodeAt(0))),c=t==="spki";switch(n){case"PS256":case"PS384":case"PS512":a={name:"RSA-PSS",hash:`SHA-${n.slice(-3)}`},s=c?["verify"]:["sign"];break;case"RS256":case"RS384":case"RS512":a={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${n.slice(-3)}`},s=c?["verify"]:["sign"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":a={name:"RSA-OAEP",hash:`SHA-${parseInt(n.slice(-3),10)||1}`},s=c?["encrypt","wrapKey"]:["decrypt","unwrapKey"];break;case"ES256":a={name:"ECDSA",namedCurve:"P-256"},s=c?["verify"]:["sign"];break;case"ES384":a={name:"ECDSA",namedCurve:"P-384"},s=c?["verify"]:["sign"];break;case"ES512":a={name:"ECDSA",namedCurve:"P-521"},s=c?["verify"]:["sign"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{let d=Qn(i);a=d.startsWith("P-")?{name:"ECDH",namedCurve:d}:{name:d},s=c?[]:["deriveBits"];break}case"EdDSA":a={name:Qn(i)},s=c?["verify"]:["sign"];break;default:throw new A('Invalid or unsupported "alg" (Algorithm) value')}return E.subtle.importKey(t,i,a,o?.extractable??!1,s)},eo=(e,t,r)=>pc(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g,"pkcs8",e,t,r);async function cr(e,t,r){if(typeof e!="string"||e.indexOf("-----BEGIN PRIVATE KEY-----")!==0)throw new TypeError('"pkcs8" must be PKCS#8 formatted string');return eo(e,t,r)}var hc=(e,t)=>{if(!(t instanceof Uint8Array)){if(!ir(t))throw new TypeError(sr(e,t,...b,"Uint8Array"));if(t.type!=="secret")throw new TypeError(`${b.join(" or ")} instances for symmetric algorithms must be of type "secret"`)}},fc=(e,t,r)=>{if(!ir(t))throw new TypeError(sr(e,t,...b));if(t.type==="secret")throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);if(r==="sign"&&t.type==="public")throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithm signing must be of type "private"`);if(r==="decrypt"&&t.type==="public")throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithm decryption must be of type "private"`);if(t.algorithm&&r==="verify"&&t.type==="private")throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);if(t.algorithm&&r==="encrypt"&&t.type==="private")throw new TypeError(`${b.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`)},lc=(e,t,r)=>{e.startsWith("HS")||e==="dir"||e.startsWith("PBES2")||/^A\d{3}(?:GCM)?KW$/.test(e)?hc(e,t):fc(e,t,r)},Ie=lc;function Ec(e,t,r,n,o){if(o.crit!==void 0&&n.crit===void 0)throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');if(!n||n.crit===void 0)return new Set;if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some(s=>typeof s!="string"||s.length===0))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let a;r!==void 0?a=new Map([...Object.entries(r),...t.entries()]):a=t;for(let s of n.crit){if(!a.has(s))throw new A(`Extension Header Parameter "${s}" is not recognized`);if(o[s]===void 0)throw new e(`Extension Header Parameter "${s}" is missing`);if(a.get(s)&&n[s]===void 0)throw new e(`Extension Header Parameter "${s}" MUST be integrity protected`)}return new Set(n.crit)}var ye=Ec;var Hc=Symbol();function nt(e,t){let r=`SHA-${e.slice(-3)}`;switch(e){case"HS256":case"HS384":case"HS512":return{hash:r,name:"HMAC"};case"PS256":case"PS384":case"PS512":return{hash:r,name:"RSA-PSS",saltLength:e.slice(-3)>>3};case"RS256":case"RS384":case"RS512":return{hash:r,name:"RSASSA-PKCS1-v1_5"};case"ES256":case"ES384":case"ES512":return{hash:r,name:"ECDSA",namedCurve:t.namedCurve};case"EdDSA":return{name:t.name};default:throw new A(`alg ${e} is not supported either by JOSE or your javascript runtime`)}}function ot(e,t,r){if(D(t))return jn(t,e,r),t;if(t instanceof Uint8Array){if(!e.startsWith("HS"))throw new TypeError($(t,...b));return E.subtle.importKey("raw",t,{hash:`SHA-${e.slice(-3)}`,name:"HMAC"},!1,[r])}throw new TypeError($(t,...b,"Uint8Array"))}var Q=e=>Math.floor(e.getTime()/1e3);var Kc=/^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)$/i,at=e=>{let t=Kc.exec(e);if(!t)throw new TypeError("Invalid time period format");let r=parseFloat(t[1]);switch(t[2].toLowerCase()){case"sec":case"secs":case"second":case"seconds":case"s":return Math.round(r);case"minute":case"minutes":case"min":case"mins":case"m":return Math.round(r*60);case"hour":case"hours":case"hr":case"hrs":case"h":return Math.round(r*3600);case"day":case"days":case"d":return Math.round(r*86400);case"week":case"weeks":case"w":return Math.round(r*604800);default:return Math.round(r*31557600)}};var Rc=async(e,t,r)=>{let n=await ot(e,t,"sign");rt(e,n);let o=await E.subtle.sign(nt(e,n.algorithm),n,r);return new Uint8Array(o)},so=Rc;var ge=class{constructor(t){if(!(t instanceof Uint8Array))throw new TypeError("payload must be an instance of Uint8Array");this._payload=t}setProtectedHeader(t){if(this._protectedHeader)throw new TypeError("setProtectedHeader can only be called once");return this._protectedHeader=t,this}setUnprotectedHeader(t){if(this._unprotectedHeader)throw new TypeError("setUnprotectedHeader can only be called once");return this._unprotectedHeader=t,this}async sign(t,r){if(!this._protectedHeader&&!this._unprotectedHeader)throw new N("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!me(this._protectedHeader,this._unprotectedHeader))throw new N("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let n={...this._protectedHeader,...this._unprotectedHeader},o=ye(N,new Map([["b64",!0]]),r?.crit,this._protectedHeader,n),a=!0;if(o.has("b64")&&(a=this._protectedHeader.b64,typeof a!="boolean"))throw new N('The "b64" (base64url-encode payload) Header Parameter must be a boolean');let{alg:s}=n;if(typeof s!="string"||!s)throw new N('JWS "alg" (Algorithm) Header Parameter missing or invalid');Ie(s,t,"sign");let i=this._payload;a&&(i=O.encode(J(i)));let c;this._protectedHeader?c=O.encode(J(JSON.stringify(this._protectedHeader))):c=O.encode("");let d=X(c,O.encode("."),i),h=await so(s,t,d),u={signature:J(h),payload:""};return a&&(u.payload=W.decode(i)),this._unprotectedHeader&&(u.header=this._unprotectedHeader),this._protectedHeader&&(u.protected=W.decode(c)),u}};var We=class{constructor(t){this._flattened=new ge(t)}setProtectedHeader(t){return this._flattened.setProtectedHeader(t),this}async sign(t,r){let n=await this._flattened.sign(t,r);if(n.payload===void 0)throw new TypeError("use the flattened module for creating JWS with b64: false");return`${n.protected}.${n.payload}.${n.signature}`}};function we(e,t){if(!Number.isFinite(t))throw new TypeError(`Invalid ${e} input`);return t}var Ae=class{constructor(t={}){if(!R(t))throw new TypeError("JWT Claims Set MUST be an object");this._payload=t}setIssuer(t){return this._payload={...this._payload,iss:t},this}setSubject(t){return this._payload={...this._payload,sub:t},this}setAudience(t){return this._payload={...this._payload,aud:t},this}setJti(t){return this._payload={...this._payload,jti:t},this}setNotBefore(t){return typeof t=="number"?this._payload={...this._payload,nbf:we("setNotBefore",t)}:t instanceof Date?this._payload={...this._payload,nbf:we("setNotBefore",Q(t))}:this._payload={...this._payload,nbf:Q(new Date)+at(t)},this}setExpirationTime(t){return typeof t=="number"?this._payload={...this._payload,exp:we("setExpirationTime",t)}:t instanceof Date?this._payload={...this._payload,exp:we("setExpirationTime",Q(t))}:this._payload={...this._payload,exp:Q(new Date)+at(t)},this}setIssuedAt(t){return typeof t>"u"?this._payload={...this._payload,iat:Q(new Date)}:t instanceof Date?this._payload={...this._payload,iat:we("setIssuedAt",Q(t))}:this._payload={...this._payload,iat:we("setIssuedAt",t)},this}};var Je=class extends Ae{setProtectedHeader(t){return this._protectedHeader=t,this}async sign(t,r){let n=new We(O.encode(JSON.stringify(this._payload)));if(n.setProtectedHeader(this._protectedHeader),Array.isArray(this._protectedHeader?.crit)&&this._protectedHeader.crit.includes("b64")&&this._protectedHeader.b64===!1)throw new j("JWTs MUST NOT use unencoded payload");return n.sign(t,r)}};var Jc;(typeof navigator>"u"||!navigator.userAgent?.startsWith?.("Mozilla/5.0 "))&&(Jc="jose/v5.1.0");var io=function e(t){function r(o,a,s){var i,c={};if(Array.isArray(o))return o.concat(a);for(i in o)c[s?i.toLowerCase():i]=o[i];for(i in a){var d=s?i.toLowerCase():i,h=a[i];c[d]=d in c&&typeof h=="object"?r(c[d],h,d=="headers"):h}return c}function n(o,a,s,i,c){var d=typeof o!="string"?(a=o).url:o,h={config:a},u=r(t,a),l={};i=i||u.data,(u.transformRequest||[]).map(function(f){i=f(i,u.headers)||i}),u.auth&&(l.authorization=u.auth),i&&typeof i=="object"&&typeof i.append!="function"&&typeof i.text!="function"&&(i=JSON.stringify(i),l["content-type"]="application/json");try{l[u.xsrfHeaderName]=decodeURIComponent(document.cookie.match(RegExp("(^|; )"+u.xsrfCookieName+"=([^;]*)"))[2])}catch{}return u.baseURL&&(d=d.replace(/^(?!.*\/\/)\/?/,u.baseURL+"/")),u.params&&(d+=(~d.indexOf("?")?"&":"?")+(u.paramsSerializer?u.paramsSerializer(u.params):new URLSearchParams(u.params))),(u.fetch||fetch)(d,{method:(s||u.method||"get").toUpperCase(),body:i,headers:r(u.headers,l,!0),credentials:u.withCredentials?"include":c}).then(function(f){for(var y in f)typeof f[y]!="function"&&(h[y]=f[y]);return u.responseType=="stream"?(h.data=f.body,h):f[u.responseType||"text"]().then(function(w){h.data=w,h.data=JSON.parse(w)}).catch(Object).then(function(){return(u.validateStatus?u.validateStatus(f.status):f.ok)?h:Promise.reject(h)})})}return t=t||{},n.request=n,n.get=function(o,a){return n(o,a,"get")},n.delete=function(o,a){return n(o,a,"delete")},n.head=function(o,a){return n(o,a,"head")},n.options=function(o,a){return n(o,a,"options")},n.post=function(o,a,s){return n(o,s,"post",a)},n.put=function(o,a,s){return n(o,s,"put",a)},n.patch=function(o,a,s){return n(o,s,"patch",a)},n.all=Promise.all.bind(Promise),n.spread=function(o){return o.apply.bind(o,o)},n.CancelToken=typeof AbortController=="function"?AbortController:Object,n.defaults=t,n.create=e,n}();var Dc=e=>{if(!e)return!1;let t=JSON.parse(atob(e.split(".")[1])),r=Math.floor(Date.now()/1e3);return t.exp>r-600},st=async(e,t)=>{let r=await GCP_INVOKER_TOKEN.get(t);if(Dc(r))return r;let n=await cr(e.private_key,"RS256"),o=e.client_email,a={iss:o,sub:o,aud:"https://www.googleapis.com/oauth2/v4/token",target_audience:t,iat:Math.floor(Date.now()/1e3),exp:Math.floor(Date.now()/1e3)+3600},s=await new Je(a).setProtectedHeader({alg:"RS256",typ:"JWT"}).sign(n),i=await io.post("https://www.googleapis.com/oauth2/v4/token",{grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:s});return await GCP_INVOKER_TOKEN.put(t,i.data.id_token),i.data.id_token};var Mc={get:co.default};function ur({project_id:e,region:t,functionName:r,serviceAccount:n}){return async o=>{let a=`https://${t}-${e}.cloudfunctions.net/${r}`,s=await st(n,a);o.request.headers.Authorization=`Bearer ${s}`;let i={headers:o.request.headers,method:o.request.method,redirect:"manual"};if(x.methodsMethodsWithBody.indexOf(o.request.method)!==-1&&Mc.get(o,"event.request.body")){let h=o.event.request.clone();i.body=h.body}let c=await fetch(a,i);o.body=c.body,o.status=c.status;let d=S.instanceToJson(c.headers);Object.keys(d).forEach(h=>{o.set(h,d[h])})}}var uo=v(M());var $c={get:uo.default};function pr({domain:e,serviceAccount:t}){return async r=>{let n=`${e}${r.request.path}`,o=await st(t,e);r.request.headers.Authorization=`Bearer ${o}`;let a={headers:r.request.headers,method:r.request.method,redirect:"manual"};if(x.methodsMethodsWithBody.indexOf(r.request.method)!==-1&&$c.get(r,"event.request.body")){let c=r.event.request.clone();a.body=c.body}let s=await fetch(n,a);r.body=s.body,r.status=s.status;let i=S.instanceToJson(s.headers);Object.keys(i).forEach(c=>{r.set(c,i[c])})}}var po={basicAuth:St,cache:Ct,cors:_t,geoDecorator:vt,jwt:Ht,kvStorage:Pt,kvStorageBinding:Tt,lambda:xt,loadbalancer:Wt,logger:Nt,oauth2:Gt,origin:Vt,rateLimit:jt,response:zt,s3:Yt,signature:Qt,split:er,transform:tr,recaptcha:rr,userInputValidation:or,cloudfunction:ur,gcpCloudrun:pr};module.exports=class{constructor(t=[],r={}){this.router=new ho.default,t.forEach(n=>{let o=r[n.handlerName]||po[n.handlerName];if(!o)throw new Error(`Handler ${n.handlerName} is not supported`);this.router.add(n,o(n.options))})}async resolve(t){return this.router.resolve(t)}};
8
8
  /*! Bundled license information:
9
9
 
10
10
  aws4fetch/dist/aws4fetch.umd.js:
@@ -20,16 +20,5 @@ cookie/index.js:
20
20
  * Copyright(c) 2015 Douglas Christopher Wilson
21
21
  * MIT Licensed
22
22
  *)
23
-
24
- ieee754/index.js:
25
- (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
26
-
27
- buffer/index.js:
28
- (*!
29
- * The buffer module from node.js, for the browser.
30
- *
31
- * @author Feross Aboukhadijeh <https://feross.org>
32
- * @license MIT
33
- *)
34
23
  */
35
24
  //# sourceMappingURL=index.js.map