export type CreateApiOutputModuleExportCsvArgs = {validationEnabled?: boolean | undefined, separator?: string | undefined, quote?: string | undefined, escape?: string | undefined, headerRow?: boolean | undefined, body: string}; export type CreateApiOutputModuleExportCsvOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Exports results in CSV format, returns the results immediately. * * POST /outputModule/export/csv * * Also accepts auth: jwtAuth, oauth2, oauth2 */ export const createApiOutputModuleExportCsv = async (args: CreateApiOutputModuleExportCsvArgs, options: CreateApiOutputModuleExportCsvOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (args.validationEnabled != null) query.append("validationEnabled", String(args.validationEnabled)) if (args.separator != null) query.append("separator", String(args.separator)) if (args.quote != null) query.append("quote", String(args.quote)) if (args.escape != null) query.append("escape", String(args.escape)) if (args.headerRow != null) query.append("headerRow", String(args.headerRow)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/outputModule/export/csv${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };