import l from"node:path";import{readFile as d,existsSync as h}from"node:fs";import{promisify as A}from"node:util";import{PUBLIC_API_DEFINITIONS_FOLDER as L}from"../../constants/common.js";import{GRAPHQL_SPEC_SLUG as R}from"../../../constants/common";import{canDownloadApiDefinition as w}from"../../utils/rbac.js";const F=A(d);async function q(r,e,i){const{isAuthenticated:n,teams:a,claims:{email:c}}=e.user,o=new URL(r.url),p=decodeURIComponent(o.pathname.replace(R,"")),s=e.config.access??{},m=s.rbac??{},f=s.requiresLogin??!1;if(!w(o.pathname,m,f,{isAuthenticated:n,email:c,teams:a}))return new Response("Unauthorized",{status:n?403:401});const t=l.join(i.props?.outdir??"",L,p);if(!h(t))return new Response("Not found",{status:404});const u=await F(t,"utf-8");return new Response(u,{headers:{"Content-Type":"application/graphql"}})}export{q as default};
