1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Retrieve information about all schemas on a zone |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | zone_id: string, |
13 | page: string | undefined, |
14 | per_page: string | undefined, |
15 | omit_source: string | undefined, |
16 | validation_enabled: string | undefined |
17 | ) { |
18 | const url = new URL( |
19 | `https://api.cloudflare.com/client/v4/zones/${zone_id}/api_gateway/user_schemas` |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["page", page], |
23 | ["per_page", per_page], |
24 | ["omit_source", omit_source], |
25 | ["validation_enabled", validation_enabled], |
26 | ]) { |
27 | if (v !== undefined && v !== "") { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | "X-AUTH-EMAIL": auth.email, |
35 | "X-AUTH-KEY": auth.key, |
36 | Authorization: "Bearer " + auth.token, |
37 | }, |
38 | body: undefined, |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|