1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Get Top Locations By EDNS Support |
8 | * Get the top locations, by DNS queries EDNS support to AS112. |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | edns: "SUPPORTED" | "NOT_SUPPORTED", |
13 | limit: string | undefined, |
14 | name: string | undefined, |
15 | dateRange: string | undefined, |
16 | dateStart: string | undefined, |
17 | dateEnd: string | undefined, |
18 | asn: string | undefined, |
19 | location: string | undefined, |
20 | format: "JSON" | "CSV" | undefined |
21 | ) { |
22 | const url = new URL( |
23 | `https://api.cloudflare.com/client/v4/radar/as112/top/locations/edns/${edns}` |
24 | ); |
25 | for (const [k, v] of [ |
26 | ["limit", limit], |
27 | ["name", name], |
28 | ["dateRange", dateRange], |
29 | ["dateStart", dateStart], |
30 | ["dateEnd", dateEnd], |
31 | ["asn", asn], |
32 | ["location", location], |
33 | ["format", format], |
34 | ]) { |
35 | if (v !== undefined && v !== "") { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "GET", |
41 | headers: { |
42 | "X-AUTH-EMAIL": auth.email, |
43 | "X-AUTH-KEY": auth.key, |
44 | Authorization: "Bearer " + auth.token, |
45 | }, |
46 | body: undefined, |
47 | }); |
48 | if (!response.ok) { |
49 | const text = await response.text(); |
50 | throw new Error(`${response.status} ${text}`); |
51 | } |
52 | return await response.json(); |
53 | } |
54 |
|