import{REDOCLY_ROUTE_RBAC as a}from"@redocly/config";import{withPathPrefix as l}from"@redocly/theme/core/utils";import{canAccessResource as f}from"../../utils/rbac.js";import{handleUnauthorizedApiRequest as h}from"../utils.js";import{handleApiRequest as m}from"../handle-api-request.js";import{sortApiFunctionRoutes as d}from"../utils/sort-api-function-routes.js";function R(o){return["get","post","put","delete","patch","all"].includes(o)}function A({route:o,ctx:e,store:i}){const{isAuthenticated:s,claims:{email:r},teams:t}=e.get("auth"),{path:n}=e.req;return f({...o,slug:n,[a]:{...o[a],slug:n}},{isAuthenticated:s,email:r,teams:t},i.config.rbac,i.config.requiresLogin)}function E(o,e,i){const s=e.getAllApiRoutes(),r=d(s);for(const t of r){const n=async c=>{if(!A({route:t,ctx:c,store:e}))return h(c);const p=await i(t);return m(t,c,p||{},e)},u=t.httpMethod?.toLowerCase()||"all";R(u)&&o[u](l(t.slug),n)}}export{E as installApiRoutes};
