//native
type Vercel = {
token: string;
};
/**
* Record an artifacts cache usage event
* Records an artifacts cache usage event. The body of this request is an array of cache usage events. The supported event types are `HIT` and `MISS`. The source is either `LOCAL` the cache event was on the users filesystem cache or `REMOTE` if the cache event is for a remote cache. When the event is a `HIT` the request also accepts a number `duration` which is the time taken to generate the artifact in the cache.
*/
export async function main(
auth: Vercel,
teamId: string | undefined,
slug: string | undefined,
body: {
sessionId: string;
source: "LOCAL" | "REMOTE";
event: "HIT" | "MISS";
hash: string;
duration?: number;
}[],
x_artifact_client_ci?: string,
x_artifact_client_interactive?: string,
) {
const url = new URL(`https://api.vercel.com/v8/artifacts/events`);
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: "POST",
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 }
: {}),
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago