1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Update Logpush job |
8 | * Updates a Logpush job. |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | job_identifier: string, |
13 | account_identifier: string, |
14 | body: { |
15 | destination_conf?: string; |
16 | enabled?: boolean; |
17 | frequency?: "high" | "low"; |
18 | logpull_options?: string; |
19 | ownership_challenge?: string; |
20 | [k: string]: unknown; |
21 | } |
22 | ) { |
23 | const url = new URL( |
24 | `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/logpush/jobs/${job_identifier}` |
25 | ); |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "PUT", |
29 | headers: { |
30 | "X-AUTH-EMAIL": auth.email, |
31 | "X-AUTH-KEY": auth.key, |
32 | "Content-Type": "application/json", |
33 | Authorization: "Bearer " + auth.token, |
34 | }, |
35 | body: JSON.stringify(body), |
36 | }); |
37 | if (!response.ok) { |
38 | const text = await response.text(); |
39 | throw new Error(`${response.status} ${text}`); |
40 | } |
41 | return await response.json(); |
42 | } |
43 |
|