export type GetApiV1StatsArgs = {domains?: string | undefined, provider?: string | undefined, past_days?: number | undefined, 'x-api-key': string, body: {tags?: Array | undefined}}; export type GetApiV1StatsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get stats * * GET /v1/stats */ export const getApiV1Stats = async (args: GetApiV1StatsArgs, options?: GetApiV1StatsOptions) => { const {baseUrl = "https://api.mailreach.co/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") if (args.domains != null) query.append("domains", String(args.domains)) if (args.provider != null) query.append("provider", String(args.provider)) if (args.past_days != null) query.append("past_days", String(args.past_days)) if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stats${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };