//native
type Netlify = {
token: string;
};
/**
* Purge cache
* Purges cached content from Netlify's CDN. Supports purging by Cache-Tag.
*/
export async function main(
auth: Netlify,
body: { site_id?: string; site_slug?: string; cache_tags?: string[] },
) {
const url = new URL(`https://api.netlify.com/api/v1/purge`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 235 days ago