type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* List Zones
* Lists, searches, sorts, and filters your zones.
*/
export async function main(
auth: Cloudflare,
name: string | undefined,
status: "initializing" | "pending" | "active" | "moved" | undefined,
account_id: string | undefined,
account_name: string | undefined,
page: string | undefined,
per_page: string | undefined,
order: "name" | "status" | "account.id" | "account.name" | undefined,
direction: "asc" | "desc" | undefined,
match: "any" | "all" | undefined
) {
const url = new URL(`https://api.cloudflare.com/client/v4/zones`);
for (const [k, v] of [
["name", name],
["status", status],
["account.id", account_id],
["account.name", account_name],
["page", page],
["per_page", per_page],
["order", order],
["direction", direction],
["match", match],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* List Zones
* Lists, searches, sorts, and filters your zones.
*/
export async function main(
auth: Cloudflare,
name: string | undefined,
status: "initializing" | "pending" | "active" | "moved" | undefined,
account_id: string | undefined,
account_name: string | undefined,
page: string | undefined,
per_page: string | undefined,
order: "name" | "status" | "account.id" | "account.name" | undefined,
direction: "asc" | "desc" | undefined,
match: "any" | "all" | undefined
) {
const url = new URL(`https://api.cloudflare.com/client/v4/zones`);
for (const [k, v] of [
["name", name],
["status", status],
["account.id", account_id],
["account.name", account_name],
["page", page],
["per_page", per_page],
["order", order],
["direction", direction],
["match", match],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago