import{TrieRouter as q}from"hono/router/trie-router";import{REDOCLY_ROUTE_RBAC as c}from"@redocly/config";import{withPathPrefix as C}from"@redocly/theme/core/utils";import{canAccessResource as L}from"../../../utils/rbac.js";import{handleUnauthorizedApiRequest as U}from"../../utils.js";import{handleApiRouteRequest as P}from"../../handle-api-route-request.js";import{sortApiFunctionRoutes as w}from"../../utils/sort-api-function-routes.js";function B(u,t){u.all("*",async(o,a)=>{const{method:m,path:e}=o.req,p=t.getAllApiRoutes(),h=w(p),i=new q;for(const n of h){const A=n.httpMethod?.toUpperCase()||"ALL",g=C(n.slug);i.add(A,g,n)}const s=i.match(m.toUpperCase(),e);if(!s||s[0].length===0)return a();const l=s[0],[r]=l[0],{isAuthenticated:R,claims:{email:f},teams:d}=o.get("auth");return L({...r,slug:e,[c]:{...r[c],slug:e}},{isAuthenticated:R,email:f,teams:d},t.config.rbac,t.config.requiresLogin)?P(r,o,t):U(o)})}export{B as installApiRoutes};
