export type CreateApiPurgeArgs = {url: string | null, async?: boolean | undefined, exactPath?: boolean | undefined}; export type CreateApiPurgeOptions = {baseUrl?: string | undefined, AccessKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Purge URL * * POST /purge */ export const createApiPurge = async (args: CreateApiPurgeArgs, options?: CreateApiPurgeOptions) => { const {baseUrl = "https://api.bunny.net", fetch: fetchFn = fetch, AccessKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.url != null) query.append("url", String(args.url)) if (args.async != null) query.append("async", String(args.async)) if (args.exactPath != null) query.append("exactPath", String(args.exactPath)) if (AccessKey !== undefined) headers.set("AccessKey", AccessKey) const url = `${baseUrl.replace(/\/+$/, '')}/purge${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };