//native
type Vercel = {
token: string;
};
/**
* Creates a webhook
* Creates a webhook
*/
export async function main(
auth: Vercel,
teamId: string | undefined,
slug: string | undefined,
body: {
url: string;
events:
| "budget.reached"
| "budget.reset"
| "domain.created"
| "deployment.created"
| "deployment.error"
| "deployment.canceled"
| "deployment.succeeded"
| "deployment.ready"
| "deployment.check-rerequested"
| "deployment.promoted"
| "deployment.integration.action.start"
| "deployment.integration.action.cancel"
| "deployment.integration.action.cleanup"
| "edge-config.created"
| "edge-config.deleted"
| "edge-config.items.updated"
| "firewall.attack"
| "integration-configuration.permission-upgraded"
| "integration-configuration.removed"
| "integration-configuration.scope-change-confirmed"
| "integration-resource.project-connected"
| "integration-resource.project-disconnected"
| "project.created"
| "project.removed"
| "deployment-checks-completed"
| "deployment-ready"
| "deployment-prepared"
| "deployment-error"
| "deployment-check-rerequested"
| "deployment-canceled"
| "project-created"
| "project-removed"
| "domain-created"
| "deployment"
| "integration-configuration-permission-updated"
| "integration-configuration-removed"
| "integration-configuration-scope-change-confirmed"
| "marketplace.invoice.created"
| "marketplace.invoice.paid"
| "marketplace.invoice.notpaid"
| "marketplace.invoice.refunded"
| "observability.anomaly"
| "test-webhook"[];
projectIds?: string[];
},
) {
const url = new URL(`https://api.vercel.com/v1/webhooks`);
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