1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a check |
7 | * Update an existing check. This endpoint must be called with an OAuth2 or it will produce a 400 error. |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | deploymentId: string, |
12 | checkId: string, |
13 | teamId: string | undefined, |
14 | slug: string | undefined, |
15 | body: { |
16 | name?: string; |
17 | path?: string; |
18 | status?: "running" | "completed"; |
19 | conclusion?: "canceled" | "failed" | "neutral" | "succeeded" | "skipped"; |
20 | detailsUrl?: string; |
21 | output?: { |
22 | metrics?: { |
23 | FCP: { value: number; previousValue?: number; source: "web-vitals" }; |
24 | LCP: { value: number; previousValue?: number; source: "web-vitals" }; |
25 | CLS: { value: number; previousValue?: number; source: "web-vitals" }; |
26 | TBT: { value: number; previousValue?: number; source: "web-vitals" }; |
27 | virtualExperienceScore?: { |
28 | value: number; |
29 | previousValue?: number; |
30 | source: "web-vitals"; |
31 | }; |
32 | }; |
33 | }; |
34 | externalId?: string; |
35 | }, |
36 | ) { |
37 | const url = new URL( |
38 | `https://api.vercel.com/v1/deployments/${deploymentId}/checks/${checkId}`, |
39 | ); |
40 | for (const [k, v] of [ |
41 | ["teamId", teamId], |
42 | ["slug", slug], |
43 | ]) { |
44 | if (v !== undefined && v !== "" && k !== undefined) { |
45 | url.searchParams.append(k, v); |
46 | } |
47 | } |
48 | const response = await fetch(url, { |
49 | method: "PATCH", |
50 | headers: { |
51 | "Content-Type": "application/json", |
52 | Authorization: "Bearer " + auth.token, |
53 | }, |
54 | body: JSON.stringify(body), |
55 | }); |
56 | if (!response.ok) { |
57 | const text = await response.text(); |
58 | throw new Error(`${response.status} ${text}`); |
59 | } |
60 | return await response.json(); |
61 | } |
62 |
|