Update a WAF package

Updates a WAF package. You can update the sensitivity and the action of an anomaly detection WAF package. **Note:** Applies only to the [previous version of WAF managed rules](https://developers.cloudflare.com/support/firewall/managed-rules-web-application-firewall-waf/understanding-waf-managed-rules-web-application-firewall/).

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Update a WAF package
8
 * Updates a WAF package. You can update the sensitivity and the action of an anomaly detection WAF package.
9

10
**Note:** Applies only to the [previous version of WAF managed rules](https://developers.cloudflare.com/support/firewall/managed-rules-web-application-firewall-waf/understanding-waf-managed-rules-web-application-firewall/).
11
 */
12
export async function main(
13
  auth: Cloudflare,
14
  identifier: string,
15
  zone_identifier: string,
16
  body: {
17
    action_mode?: "simulate" | "block" | "challenge";
18
    sensitivity?: "high" | "medium" | "low" | "off";
19
    [k: string]: unknown;
20
  }
21
) {
22
  const url = new URL(
23
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/firewall/waf/packages/${identifier}`
24
  );
25

26
  const response = await fetch(url, {
27
    method: "PATCH",
28
    headers: {
29
      "X-AUTH-EMAIL": auth.email,
30
      "X-AUTH-KEY": auth.key,
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42