export type GetApiApiV2EmailsArgs = {Authorization?: string | undefined, output?: string | undefined, type?: string | undefined, start_date?: string | undefined, end_date?: string | undefined, status?: string | undefined}; export type GetApiApiV2EmailsOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Exportar E-mails (CSV) * * GET /api/v2/emails */ export const getApiApiV2Emails = async (args: GetApiApiV2EmailsArgs, options?: GetApiApiV2EmailsOptions) => { const {baseUrl = "https://cloud-hom.bry.com.br", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.output != null) query.append("output", String(args.output)) if (args.type != null) query.append("type", String(args.type)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.status != null) query.append("status", String(args.status)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/emails${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 (await res.json()) as unknown };