1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Get ARC Validations Summary |
8 | * Percentage distribution of emails classified per ARC validation. |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | name: string | undefined, |
13 | dateRange: string | undefined, |
14 | dateStart: string | undefined, |
15 | dateEnd: string | undefined, |
16 | asn: string | undefined, |
17 | location: string | undefined, |
18 | dkim: string | undefined, |
19 | dmarc: string | undefined, |
20 | spf: string | undefined, |
21 | format: "JSON" | "CSV" | undefined |
22 | ) { |
23 | const url = new URL( |
24 | `https://api.cloudflare.com/client/v4/radar/email/security/summary/arc` |
25 | ); |
26 | for (const [k, v] of [ |
27 | ["name", name], |
28 | ["dateRange", dateRange], |
29 | ["dateStart", dateStart], |
30 | ["dateEnd", dateEnd], |
31 | ["asn", asn], |
32 | ["location", location], |
33 | ["dkim", dkim], |
34 | ["dmarc", dmarc], |
35 | ["spf", spf], |
36 | ["format", format], |
37 | ]) { |
38 | if (v !== undefined && v !== "") { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "GET", |
44 | headers: { |
45 | "X-AUTH-EMAIL": auth.email, |
46 | "X-AUTH-KEY": auth.key, |
47 | Authorization: "Bearer " + auth.token, |
48 | }, |
49 | body: undefined, |
50 | }); |
51 | if (!response.ok) { |
52 | const text = await response.text(); |
53 | throw new Error(`${response.status} ${text}`); |
54 | } |
55 | return await response.json(); |
56 | } |
57 |
|