//native
type Vercel = {
token: string;
};
/**
* Creates a new Integration Log Drain
* Creates an Integration log drain. This endpoint must be called with an OAuth2 client (integration), since log drains are tied to integrations. If it is called with a different token type it will produce a 400 error.
*/
export async function main(
auth: Vercel,
teamId: string | undefined,
slug: string | undefined,
body: {
name: string;
projectIds?: string[];
secret?: string;
deliveryFormat?: "json" | "ndjson" | "syslog";
url: string;
sources?:
| "static"
| "lambda"
| "build"
| "edge"
| "external"
| "firewall"[];
headers?: {};
environments?: "preview" | "production"[];
},
) {
const url = new URL(`https://api.vercel.com/v2/integrations/log-drains`);
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: {
"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