1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create System Bypass Rule |
7 | * Create new system bypass rules |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | projectId: string | undefined, |
12 | teamId: string | undefined, |
13 | slug: string | undefined, |
14 | body: { |
15 | domain?: string; |
16 | projectScope?: false | true; |
17 | sourceIp?: string; |
18 | allSources?: false | true; |
19 | ttl?: number; |
20 | note?: string; |
21 | } & {}, |
22 | ) { |
23 | const url = new URL(`https://api.vercel.com/v1/security/firewall/bypass`); |
24 | for (const [k, v] of [ |
25 | ["projectId", projectId], |
26 | ["teamId", teamId], |
27 | ["slug", slug], |
28 | ]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "POST", |
35 | headers: { |
36 | "Content-Type": "application/json", |
37 | Authorization: "Bearer " + auth.token, |
38 | }, |
39 | body: JSON.stringify(body), |
40 | }); |
41 | if (!response.ok) { |
42 | const text = await response.text(); |
43 | throw new Error(`${response.status} ${text}`); |
44 | } |
45 | return await response.json(); |
46 | } |
47 |
|