import {z} from 'zod' export type CreateApiAccountsAidReportsGenerationArgs = {aid: unknown, template_id: string, template_data_path: string, template_accept: string, template_accept_language: string, template_accept_timezone?: unknown | undefined, data_from?: string | undefined, data_to?: string | undefined, schedule?: ('monthly' | 'weekly' | 'daily' | 'custom' | 'none') | undefined, save?: boolean | undefined, body: Array<{key: string, path: string, data: Record}>}; export type CreateApiAccountsAidReportsGenerationOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiAccountsAidReportsGenerationResponse = z.string(); 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 }; /** * api_reports_generation_post * * POST /accounts/{aid}/reports/generation */ export const createApiAccountsAidReportsGeneration = async (args: CreateApiAccountsAidReportsGenerationArgs, options?: CreateApiAccountsAidReportsGenerationOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.template_id != null) query.append("template_id", String(args.template_id)) if (args.template_data_path != null) query.append("template_data_path", String(args.template_data_path)) if (args.template_accept != null) query.append("template_accept", String(args.template_accept)) if (args.template_accept_language != null) query.append("template_accept_language", String(args.template_accept_language)) if (args.template_accept_timezone != null) query.append("template_accept_timezone", String(args.template_accept_timezone)) if (args.data_from != null) query.append("data_from", String(args.data_from)) if (args.data_to != null) query.append("data_to", String(args.data_to)) if (args.schedule != null) query.append("schedule", String(args.schedule)) if (args.save != null) query.append("save", String(args.save)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/reports/generation${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 validateResponse(createApiAccountsAidReportsGenerationResponse, await res.json()) };