//native
type Vercel = {
token: string;
};
/**
* Points all production domains for a project to the given deploy
* Allows users to promote a deployment to production. Note: This does NOT rebuild the deployment. If you need that, then call create-deployments endpoint.
*/
export async function main(
auth: Vercel,
projectId: string,
deploymentId: string,
teamId: string | undefined,
slug: string | undefined,
) {
const url = new URL(
`https://api.vercel.com/v10/projects/${projectId}/promote/${deploymentId}`,
);
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: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago