1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Creates a webhook |
7 | * Creates a webhook |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | teamId: string | undefined, |
12 | slug: string | undefined, |
13 | body: { |
14 | url: string; |
15 | events: |
16 | | "budget.reached" |
17 | | "budget.reset" |
18 | | "domain.created" |
19 | | "deployment.created" |
20 | | "deployment.error" |
21 | | "deployment.canceled" |
22 | | "deployment.succeeded" |
23 | | "deployment.ready" |
24 | | "deployment.check-rerequested" |
25 | | "deployment.promoted" |
26 | | "deployment.integration.action.start" |
27 | | "deployment.integration.action.cancel" |
28 | | "deployment.integration.action.cleanup" |
29 | | "edge-config.created" |
30 | | "edge-config.deleted" |
31 | | "edge-config.items.updated" |
32 | | "firewall.attack" |
33 | | "integration-configuration.permission-upgraded" |
34 | | "integration-configuration.removed" |
35 | | "integration-configuration.scope-change-confirmed" |
36 | | "integration-resource.project-connected" |
37 | | "integration-resource.project-disconnected" |
38 | | "project.created" |
39 | | "project.removed" |
40 | | "deployment-checks-completed" |
41 | | "deployment-ready" |
42 | | "deployment-prepared" |
43 | | "deployment-error" |
44 | | "deployment-check-rerequested" |
45 | | "deployment-canceled" |
46 | | "project-created" |
47 | | "project-removed" |
48 | | "domain-created" |
49 | | "deployment" |
50 | | "integration-configuration-permission-updated" |
51 | | "integration-configuration-removed" |
52 | | "integration-configuration-scope-change-confirmed" |
53 | | "marketplace.invoice.created" |
54 | | "marketplace.invoice.paid" |
55 | | "marketplace.invoice.notpaid" |
56 | | "marketplace.invoice.refunded" |
57 | | "observability.anomaly" |
58 | | "test-webhook"[]; |
59 | projectIds?: string[]; |
60 | }, |
61 | ) { |
62 | const url = new URL(`https://api.vercel.com/v1/webhooks`); |
63 | for (const [k, v] of [ |
64 | ["teamId", teamId], |
65 | ["slug", slug], |
66 | ]) { |
67 | if (v !== undefined && v !== "" && k !== undefined) { |
68 | url.searchParams.append(k, v); |
69 | } |
70 | } |
71 | const response = await fetch(url, { |
72 | method: "POST", |
73 | headers: { |
74 | "Content-Type": "application/json", |
75 | Authorization: "Bearer " + auth.token, |
76 | }, |
77 | body: JSON.stringify(body), |
78 | }); |
79 | if (!response.ok) { |
80 | const text = await response.text(); |
81 | throw new Error(`${response.status} ${text}`); |
82 | } |
83 | return await response.json(); |
84 | } |
85 |
|