import{logger as e}from"../../logger/index.mjs";import{Octokit as t}from"@octokit/rest";const n=/^(@intlayer\/[\w-]+|intlayer|react-intlayer|next-intlayer|vue-intlayer|svelte-intlayer|express-intlayer|intlayer-editor)$/,r=e=>{try{let t=new URL(e),n=t.pathname.replace(/\.git\/?$/,``).split(`/`).filter(Boolean);return n.length<2?null:{hostname:t.hostname,owner:n[0],repo:n[1]}}catch{return null}},i=e=>{let n=e===`github.com`;return new t({auth:process.env.GITHUB_TOKEN,...n?{}:{baseUrl:`https://${e}/api/v3`}})},a=e=>{let t={};for(let r of[`dependencies`,`devDependencies`,`peerDependencies`]){let i=e[r];if(i&&typeof i==`object`){for(let[e,r]of Object.entries(i))if(n.test(e)){let n=String(r);n===`workspace:*`?t[e]=`latest`:t[e]=n}}}return t},o=async t=>{let n=r(t);if(!n)return e.warn(`[verifyGithubRepo] Could not parse URL: ${t}`),null;let{hostname:o,owner:s,repo:c}=n,l=i(o);try{let t=(await l.rest.repos.get({owner:s,repo:c})).data.default_branch,n=await l.rest.git.getTree({owner:s,repo:c,tree_sha:t,recursive:`1`});n.data.truncated&&e.warn(`[verifyGithubRepo] Tree is truncated for ${s}/${c}`);let r=n.data.tree.filter(e=>e.type===`blob`&&(e.path===`package.json`||e.path?.endsWith(`/package.json`))).map(e=>e.path).slice(0,20);if(r.length===0)return{isValid:!1,packageDetails:{}};let i={};return await Promise.allSettled(r.map(async t=>{try{let e=await l.rest.repos.getContent({owner:s,repo:c,path:t});if(!Array.isArray(e.data)&&`content`in e.data){let t=Buffer.from(e.data.content,`base64`).toString(`utf-8`),n=a(JSON.parse(t));Object.assign(i,n)}}catch(n){e.debug(`[verifyGithubRepo] Could not read ${t}: ${n instanceof Error?n.message:String(n)}`)}})),{isValid:Object.keys(i).length>0,intlayerVersion:i.intlayer,packageDetails:i}}catch(t){return e.error(`[verifyGithubRepo] Error for ${s}/${c}: ${t instanceof Error?t.message:String(t)}`),null}};export{a as extractIntlayerPackages,r as parseGithubUrl,o as verifyGithubRepo};
//# sourceMappingURL=showcaseVerifyGithub.service.mjs.map