1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * List an account entry point ruleset's versions |
8 | * Fetches the versions of an account entry point ruleset. |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | ruleset_phase: |
13 | | "ddos_l4" |
14 | | "ddos_l7" |
15 | | "http_config_settings" |
16 | | "http_custom_errors" |
17 | | "http_log_custom_fields" |
18 | | "http_ratelimit" |
19 | | "http_request_cache_settings" |
20 | | "http_request_dynamic_redirect" |
21 | | "http_request_firewall_custom" |
22 | | "http_request_firewall_managed" |
23 | | "http_request_late_transform" |
24 | | "http_request_origin" |
25 | | "http_request_redirect" |
26 | | "http_request_sanitize" |
27 | | "http_request_sbfm" |
28 | | "http_request_select_configuration" |
29 | | "http_request_transform" |
30 | | "http_response_compression" |
31 | | "http_response_firewall_managed" |
32 | | "http_response_headers_transform" |
33 | | "magic_transit" |
34 | | "magic_transit_ids_managed" |
35 | | "magic_transit_managed", |
36 | account_id: string |
37 | ) { |
38 | const url = new URL( |
39 | `https://api.cloudflare.com/client/v4/accounts/${account_id}/rulesets/phases/${ruleset_phase}/entrypoint/versions` |
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 |
|