//native
/**
* Create IP Access Rule
* Block, challenge or allow an IP, IP range, ASN or country across every zone in the account.
*/
export async function main(
auth: RT.Cloudflare,
mode:
"block" | "challenge" | "js_challenge" | "managed_challenge" | "whitelist",
target: "ip" | "ip6" | "ip_range" | "asn" | "country",
value: string,
notes: string | undefined
) {
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${auth.account_id}/firewall/access_rules/rules`,
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
mode,
configuration: { target, value },
notes: notes ?? undefined,
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 4 hours ago