type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* List core web vital metrics trend
* Lists the core web vital metrics trend over time for a specific page.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
url: string,
region:
| "asia-east1"
| "asia-northeast1"
| "asia-northeast2"
| "asia-south1"
| "asia-southeast1"
| "australia-southeast1"
| "europe-north1"
| "europe-southwest1"
| "europe-west1"
| "europe-west2"
| "europe-west3"
| "europe-west4"
| "europe-west8"
| "europe-west9"
| "me-west1"
| "southamerica-east1"
| "us-central1"
| "us-east1"
| "us-east4"
| "us-south1"
| "us-west1"
| undefined,
deviceType: "DESKTOP" | "MOBILE" | undefined,
start: string | undefined,
end: string | undefined,
tz: string | undefined,
metrics: string | undefined
) {
const url_ = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/speed_api/pages/${url}/trend`
);
for (const [k, v] of [
["region", region],
["deviceType", deviceType],
["start", start],
["end", end],
["tz", tz],
["metrics", metrics],
]) {
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 core web vital metrics trend
* Lists the core web vital metrics trend over time for a specific page.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
url: string,
region:
| "asia-east1"
| "asia-northeast1"
| "asia-northeast2"
| "asia-south1"
| "asia-southeast1"
| "australia-southeast1"
| "europe-north1"
| "europe-southwest1"
| "europe-west1"
| "europe-west2"
| "europe-west3"
| "europe-west4"
| "europe-west8"
| "europe-west9"
| "me-west1"
| "southamerica-east1"
| "us-central1"
| "us-east1"
| "us-east4"
| "us-south1"
| "us-west1"
| undefined,
deviceType: "DESKTOP" | "MOBILE" | undefined,
start: string | undefined,
end: string | undefined,
tz: string | undefined,
metrics: string | undefined
) {
const url_ = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/speed_api/pages/${url}/trend`
);
for (const [k, v] of [
["region", region],
["deviceType", deviceType],
["start", start],
["end", end],
["tz", tz],
["metrics", metrics],
]) {
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