0

Update Protection Bypass for Automation

by
Published Apr 8, 2025

Update the deployment protection automation bypass for a project

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Update Protection Bypass for Automation
7
 * Update the deployment protection automation bypass for a project
8
 */
9
export async function main(
10
  auth: Vercel,
11
  idOrName: string,
12
  teamId: string | undefined,
13
  slug: string | undefined,
14
  body: {
15
    revoke?: { secret: string; regenerate: false | true };
16
    generate?: { secret?: string };
17
  },
18
) {
19
  const url = new URL(
20
    `https://api.vercel.com/v1/projects/${idOrName}/protection-bypass`,
21
  );
22
  for (const [k, v] of [
23
    ["teamId", teamId],
24
    ["slug", slug],
25
  ]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "PATCH",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44