|
import { HUB_URL } from "../consts"; |
|
|
|
import { createApiError, type HubApiError } from "../error"; |
|
import type { CredentialsParams, RepoDesignation } from "../types/public"; |
|
import { checkCredentials } from "../utils/checkCredentials"; |
|
import { toRepoId } from "../utils/toRepoId"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function checkRepoAccess( |
|
params: { |
|
repo: RepoDesignation; |
|
hubUrl?: string; |
|
fetch?: typeof fetch; |
|
} & Partial<CredentialsParams> |
|
): Promise<void> { |
|
const accessToken = params && checkCredentials(params); |
|
const repoId = toRepoId(params.repo); |
|
|
|
const response = await (params.fetch || fetch)(`${params?.hubUrl || HUB_URL}/api/${repoId.type}s/${repoId.name}`, { |
|
headers: { |
|
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}), |
|
}, |
|
}); |
|
|
|
if (!response.ok) { |
|
throw await createApiError(response); |
|
} |
|
} |
|
|