type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Retrieve all operations from a schema.
* Retrieves all operations from the schema. Operations that already exist in API Shield Endpoint Management will be returned as full operations.
*/
export async function main(
auth: Cloudflare,
schema_id: string,
zone_id: string,
feature: string | undefined,
host: string | undefined,
method: string | undefined,
endpoint: string | undefined,
page: string | undefined,
per_page: string | undefined,
operation_status: "new" | "existing" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_id}/api_gateway/user_schemas/${schema_id}/operations`
);
for (const [k, v] of [
["feature", feature],
["host", host],
["method", method],
["endpoint", endpoint],
["page", page],
["per_page", per_page],
["operation_status", operation_status],
]) {
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;
};
/**
* Retrieve all operations from a schema.
* Retrieves all operations from the schema. Operations that already exist in API Shield Endpoint Management will be returned as full operations.
*/
export async function main(
auth: Cloudflare,
schema_id: string,
zone_id: string,
feature: string | undefined,
host: string | undefined,
method: string | undefined,
endpoint: string | undefined,
page: string | undefined,
per_page: string | undefined,
operation_status: "new" | "existing" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_id}/api_gateway/user_schemas/${schema_id}/operations`
);
for (const [k, v] of [
["feature", feature],
["host", host],
["method", method],
["endpoint", endpoint],
["page", page],
["per_page", per_page],
["operation_status", operation_status],
]) {
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