export type GetApiV6BatchesArgs = {name?: string | undefined, event_name?: string | undefined, user_id?: string | undefined, tags?: Array | undefined, status?: (Array<'CANCELED' | 'DISPATCHING' | 'DONE' | 'EXPIRED' | 'FAILED' | 'IN_PROGRESS' | 'PENDING' | 'QUEUED'>) | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV6BatchesOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; /** * List batch jobs * * GET /v6/batches * * Also accepts auth: QUERY, COOKIE */ export const getApiV6Batches = async (args: GetApiV6BatchesArgs, options?: GetApiV6BatchesOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.name != null) query.append("name", String(args.name)) if (args.event_name != null) query.append("event_name", String(args.event_name)) if (args.user_id != null) query.append("user_id", String(args.user_id)) for (const item of args.tags ?? []) query.append("tags", String(item)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v6/batches${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 undefined };