// ../../adapters/cloudflare/src/cloudflare-purge.ts
var CloudflarePurge = class {
  constructor(config) {
    this.config = config;
    this.fetchFn = config.fetch ?? fetch;
    const base = config.baseUrl ?? "https://api.cloudflare.com/client/v4";
    this.endpoint = `${base}/zones/${config.zoneId}/purge_cache`;
  }
  config;
  fetchFn;
  endpoint;
  async purgeAll() {
    const response = await this.fetchFn(this.endpoint, {
      method: "POST",
      headers: {
        authorization: `Bearer ${this.config.apiToken}`,
        "content-type": "application/json"
      },
      body: JSON.stringify({ purge_everything: true })
    });
    if (!response.ok) {
      throw new Error(`Cloudflare purge failed: HTTP ${response.status} ${response.statusText}`);
    }
    const body = await response.json();
    if (body.success !== true) {
      throw new Error(`Cloudflare purge rejected: ${JSON.stringify(body.errors ?? body)}`);
    }
  }
};
export {
  CloudflarePurge
};
