1 | type Resend = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Create a new domain |
6 | * |
7 | */ |
8 | export async function main( |
9 | auth: Resend, |
10 | body: { |
11 | name: string; |
12 | region?: "us-east-1" | "eu-west-1" | "sa-east-1"; |
13 | [k: string]: unknown; |
14 | } |
15 | ) { |
16 | const url = new URL(`https://api.resend.com/domains`); |
17 |
|
18 | const response = await fetch(url, { |
19 | method: "POST", |
20 | headers: { |
21 | "Content-Type": "application/json", |
22 | Authorization: "Bearer " + auth.token, |
23 | }, |
24 | body: JSON.stringify(body), |
25 | }); |
26 | if (!response.ok) { |
27 | const text = await response.text(); |
28 | throw new Error(`${response.status} ${text}`); |
29 | } |
30 | return await response.json(); |
31 | } |
32 |
|