1 | |
2 | type Vercel = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update an existing DNS record |
7 | * Updates an existing DNS record for a domain name. |
8 | */ |
9 | export async function main( |
10 | auth: Vercel, |
11 | recordId: string, |
12 | teamId: string | undefined, |
13 | slug: string | undefined, |
14 | body: { |
15 | additionalProperties?: never; |
16 | name?: string; |
17 | value?: string; |
18 | type?: |
19 | | "A" |
20 | | "AAAA" |
21 | | "ALIAS" |
22 | | "CAA" |
23 | | "CNAME" |
24 | | "HTTPS" |
25 | | "MX" |
26 | | "SRV" |
27 | | "TXT" |
28 | | "NS"; |
29 | ttl?: number; |
30 | mxPriority?: number; |
31 | srv?: { target: string; weight: number; port: number; priority: number }; |
32 | https?: { priority: number; target: string; params?: string }; |
33 | comment?: string; |
34 | }, |
35 | ) { |
36 | const url = new URL(`https://api.vercel.com/v1/domains/records/${recordId}`); |
37 | for (const [k, v] of [ |
38 | ["teamId", teamId], |
39 | ["slug", slug], |
40 | ]) { |
41 | if (v !== undefined && v !== "" && k !== undefined) { |
42 | url.searchParams.append(k, v); |
43 | } |
44 | } |
45 | const response = await fetch(url, { |
46 | method: "PATCH", |
47 | headers: { |
48 | "Content-Type": "application/json", |
49 | Authorization: "Bearer " + auth.token, |
50 | }, |
51 | body: JSON.stringify(body), |
52 | }); |
53 | if (!response.ok) { |
54 | const text = await response.text(); |
55 | throw new Error(`${response.status} ${text}`); |
56 | } |
57 | return await response.json(); |
58 | } |
59 |
|