export type GetApiRateLimitOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Query quota and rate limit info * * GET /rate_limit */ export const getApiRateLimit = async (options?: GetApiRateLimitOptions) => { const {baseUrl = "https://api.dnsdb.info/dnsdb/v2", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/x-ndjson") if (apikey !== undefined) headers.set("X-API-KEY", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/rate_limit${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };