import {z} from 'zod' export type GetApiApiTransactionsExportArgs = {account_id?: (string | null) | undefined, account_ids?: (Array | null) | undefined, category_id?: (string | null) | undefined, category_ids?: (Array | null) | undefined, payee_id?: (string | null) | undefined, from?: (string | null) | undefined, to?: (string | null) | undefined, q?: (string | null) | undefined, uncategorized?: boolean | undefined, type?: (string | null) | undefined, status?: (string | null) | undefined, exclude_ignored?: boolean | undefined, tags?: (Array | null) | undefined, transaction_ids?: (Array | null) | undefined, 'X-Workspace-Id'?: (string | null) | undefined}; export type GetApiApiTransactionsExportOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiTransactionsExportResponse = z.unknown(); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Export Transactions * * GET /api/transactions/export */ export const getApiApiTransactionsExport = async (args: GetApiApiTransactionsExportArgs, options: GetApiApiTransactionsExportOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.account_id != null) query.append("account_id", String(args.account_id)) for (const item of args.account_ids ?? []) query.append("account_ids", String(item)) if (args.category_id != null) query.append("category_id", String(args.category_id)) for (const item of args.category_ids ?? []) query.append("category_ids", String(item)) if (args.payee_id != null) query.append("payee_id", String(args.payee_id)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.q != null) query.append("q", String(args.q)) if (args.uncategorized != null) query.append("uncategorized", String(args.uncategorized)) if (args.type != null) query.append("type", String(args.type)) if (args.status != null) query.append("status", String(args.status)) if (args.exclude_ignored != null) query.append("exclude_ignored", String(args.exclude_ignored)) for (const item of args.tags ?? []) query.append("tags", String(item)) for (const item of args.transaction_ids ?? []) query.append("transaction_ids", String(item)) if (args['X-Workspace-Id'] != null) headers.set("X-Workspace-Id", String(args['X-Workspace-Id'])) if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/transactions/export${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 validateResponse(getApiApiTransactionsExportResponse, await res.json()) };