forked from farhoodlabs/paperclip
d9341795b0
- Add optional authToken to skill import for GitHub private repos
- Store PAT as encrypted company secret (skill-pat:{skillId})
- Thread auth token through ghFetch, fetchText, fetchJson, and all GitHub resolution functions
- Add PATCH /companies/:companyId/skills/:skillId/auth for managing PAT per skill
- Add DELETE /companies/:companyId/skills/by-source for bulk deleting skills from a repo
- Preserve sourceAuthSecretId across skill re-imports/updates
- UI: Add PAT input field in import form for GitHub URLs
- UI: Add SkillAuthSection with ShieldCheck icon for viewing/updating/removing PAT
- UI: Add trash icon next to source label for delete-by-source
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { unprocessable } from "../errors.js";
|
|
|
|
function isGitHubDotCom(hostname: string) {
|
|
const h = hostname.toLowerCase();
|
|
return h === "github.com" || h === "www.github.com";
|
|
}
|
|
|
|
export function gitHubApiBase(hostname: string) {
|
|
return isGitHubDotCom(hostname) ? "https://api.github.com" : `https://${hostname}/api/v3`;
|
|
}
|
|
|
|
export function resolveRawGitHubUrl(hostname: string, owner: string, repo: string, ref: string, filePath: string) {
|
|
const p = filePath.replace(/^\/+/, "");
|
|
return isGitHubDotCom(hostname)
|
|
? `https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${p}`
|
|
: `https://${hostname}/raw/${owner}/${repo}/${ref}/${p}`;
|
|
}
|
|
|
|
export async function ghFetch(url: string, init?: RequestInit, authToken?: string): Promise<Response> {
|
|
const headers = new Headers(init?.headers);
|
|
if (authToken) {
|
|
headers.set("Authorization", `Bearer ${authToken}`);
|
|
}
|
|
try {
|
|
return await fetch(url, { ...init, headers });
|
|
} catch {
|
|
throw unprocessable(`Could not connect to ${new URL(url).hostname} — ensure the URL points to a GitHub or GitHub Enterprise instance`);
|
|
}
|
|
}
|