//native
type Vercel = {
token: string;
};
/**
* Create System Bypass Rule
* Create new system bypass rules
*/
export async function main(
auth: Vercel,
projectId: string | undefined,
teamId: string | undefined,
slug: string | undefined,
body: {
domain?: string;
projectScope?: false | true;
sourceIp?: string;
allSources?: false | true;
ttl?: number;
note?: string;
} & {},
) {
const url = new URL(`https://api.vercel.com/v1/security/firewall/bypass`);
for (const [k, v] of [
["projectId", projectId],
["teamId", teamId],
["slug", slug],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"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.json();
}
Submitted by hugo697 428 days ago