decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 1.99 kB
JavaScript
const u={contents:"write",metadata:"read",pull_requests:"write",issues:"write",checks:"read",deployments:"read",statuses:"read"},p=["statuses","deployments","checks"];function f(t){if(!t)return!1;const e=p.join("|");return new RegExp(`permission\\s+"?(?:${e})"?\\s+is not allowed`,"i").test(t)||/permissions exceed what the github app|permissions requested are not granted to this installation/i.test(t)}async function y(t,e){let n={...e};for(;;){const o=await t(n);if(!o.isError)return{result:o,grantedPermissions:n};const s=o.content?.find(a=>a.type==="text")?.text,r=p.find(a=>a in n);if(!r||!f(s))return{result:o,grantedPermissions:n};const{[r]:i,...d}=n;n=d}}function m(t){if(!t||typeof t!="object"||Array.isArray(t))return u;const e=t;return Object.values(e).some(n=>typeof n!="string")?u:e}function I(t){if(!(typeof t!="number"||!Number.isFinite(t)||!Number.isInteger(t)||t<=0))return t}function l(t){const e=t.metadata?.repoScope;if(!e||typeof e.installationId!="number"||!Number.isFinite(e.installationId)||!Number.isInteger(e.installationId)||e.installationId<=0||typeof e.owner!="string"||typeof e.repo!="string"||e.owner.length===0||e.repo.length===0)return null;const n=I(e.repositoryId);return{sourceConnectionId:typeof e.sourceConnectionId=="string"?e.sourceConnectionId:void 0,installationId:e.installationId,repositoryId:n,owner:e.owner,repo:e.repo,permissions:m(e.permissions),grantProvider:e.grantProvider==="github-mcp"?"github-mcp":void 0}}function g(t){return t.metadata?.orgShared===!0}const c=(t,e)=>`${t}/${e}`.toLowerCase();function b(t){const e=new Set,n=[];for(const o of t??[]){if(o.status!=="active")continue;const s=l(o);if(s===null)continue;const r=c(s.owner,s.repo);e.has(r)||(e.add(r),n.push(`${s.owner}/${s.repo}`))}return n}function h(t,e,n){const o=c(e,n),s=(t??[]).filter(r=>{if(r.status&&r.status!=="active")return!1;const i=l(r);return i!==null&&c(i.owner,i.repo)===o});return s.find(g)??s[0]??null}export{u as G,h as f,l as g,g as i,b as l,y as m};