1 | |
2 |
|
3 | export type DynSelect_zone_id = string |
4 |
|
5 | |
6 | |
7 | export async function zone_id(auth: RT.Cloudflare) { |
8 | const response = await fetch( |
9 | "https://api.cloudflare.com/client/v4/zones?per_page=50", |
10 | { |
11 | headers: { |
12 | Authorization: `Bearer ${auth.token}`, |
13 | Accept: "application/json", |
14 | }, |
15 | } |
16 | ) |
17 | if (!response.ok) { |
18 | throw new Error(`${response.status} ${await response.text()}`) |
19 | } |
20 | const { result } = (await response.json()) as { |
21 | result: { id: string; name: string }[] |
22 | } |
23 | return result.map((z) => ({ value: z.id, label: z.name })) |
24 | } |
25 |
|
26 | |
27 | * List Origin CA Certificates |
28 | * List the Origin CA certificates issued for a zone. |
29 | */ |
30 | export async function main(auth: RT.Cloudflare, zone_id: DynSelect_zone_id) { |
31 | const url = new URL("https://api.cloudflare.com/client/v4/certificates") |
32 | url.searchParams.append("zone_id", zone_id) |
33 |
|
34 | const response = await fetch(url, { |
35 | headers: { |
36 | Authorization: `Bearer ${auth.token}`, |
37 | Accept: "application/json", |
38 | }, |
39 | }) |
40 |
|
41 | if (!response.ok) { |
42 | throw new Error(`${response.status} ${await response.text()}`) |
43 | } |
44 |
|
45 | return await response.json() |
46 | } |
47 |
|