1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update or move apex domain |
7 | * Update or move apex domain. |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | domain: string, |
12 | teamId: string | undefined, |
13 | slug: string | undefined, |
14 | body: |
15 | | { |
16 | op?: string; |
17 | renew?: false | true; |
18 | customNameservers?: string[]; |
19 | zone?: false | true; |
20 | } |
21 | | { op?: string; destination?: string }, |
22 | ) { |
23 | const url = new URL(`https://api.vercel.com/v3/domains/${domain}`); |
24 | for (const [k, v] of [ |
25 | ["teamId", teamId], |
26 | ["slug", slug], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "PATCH", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: "Bearer " + auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|