1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 |
|
7 | * Get WHOIS Record |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | account_identifier: string, |
13 | domain: string | undefined |
14 | ) { |
15 | const url = new URL( |
16 | `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/intel/whois` |
17 | ); |
18 | for (const [k, v] of [["domain", domain]]) { |
19 | if (v !== undefined && v !== "") { |
20 | url.searchParams.append(k, v); |
21 | } |
22 | } |
23 | const response = await fetch(url, { |
24 | method: "GET", |
25 | headers: { |
26 | "X-AUTH-EMAIL": auth.email, |
27 | "X-AUTH-KEY": auth.key, |
28 | Authorization: "Bearer " + auth.token, |
29 | }, |
30 | body: undefined, |
31 | }); |
32 | if (!response.ok) { |
33 | const text = await response.text(); |
34 | throw new Error(`${response.status} ${text}`); |
35 | } |
36 | return await response.json(); |
37 | } |
38 |
|