1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Create DNS Firewall Cluster |
8 | * Create a configured DNS Firewall Cluster. |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | account_identifier: string, |
13 | body: { |
14 | attack_mitigation?: { |
15 | enabled?: boolean; |
16 | only_when_origin_unhealthy?: { [k: string]: unknown }; |
17 | only_when_upstream_unhealthy?: boolean; |
18 | [k: string]: unknown; |
19 | }; |
20 | deprecate_any_requests?: boolean; |
21 | ecs_fallback?: boolean; |
22 | maximum_cache_ttl?: number; |
23 | minimum_cache_ttl?: number; |
24 | name: string; |
25 | negative_cache_ttl?: number; |
26 | origin_ips?: { [k: string]: unknown }; |
27 | ratelimit?: number; |
28 | retries?: number; |
29 | upstream_ips: (string | string)[]; |
30 | [k: string]: unknown; |
31 | } |
32 | ) { |
33 | const url = new URL( |
34 | `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dns_firewall` |
35 | ); |
36 |
|
37 | const response = await fetch(url, { |
38 | method: "POST", |
39 | headers: { |
40 | "X-AUTH-EMAIL": auth.email, |
41 | "X-AUTH-KEY": auth.key, |
42 | "Content-Type": "application/json", |
43 | Authorization: "Bearer " + auth.token, |
44 | }, |
45 | body: JSON.stringify(body), |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|