//native
type Vercel = {
token: string;
};
/**
* Download a cache artifact
* Downloads a cache artifact indentified by its `hash` specified on the request path. The artifact is downloaded as an octet-stream. The client should verify the content-length header and response body.
*/
export async function main(
auth: Vercel,
hash: string,
teamId: string | undefined,
slug: string | undefined,
x_artifact_client_ci?: string,
x_artifact_client_interactive?: string,
) {
const url = new URL(`https://api.vercel.com/v8/artifacts/${hash}`);
for (const [k, v] of [
["teamId", teamId],
["slug", slug],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
...(x_artifact_client_ci
? { "x-artifact-client-ci": x_artifact_client_ci }
: {}),
...(x_artifact_client_interactive
? { "x-artifact-client-interactive": x_artifact_client_interactive }
: {}),
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago