import {z} from 'zod' export type GetApiV1ReportsBankBilletsArgs = {'User-Agent'?: string | undefined, expire_from?: string | undefined, expire_to?: string | undefined, paid_from?: string | undefined, paid_to?: string | undefined, registered_from?: string | undefined, registered_to?: string | undefined, created_from?: string | undefined, created_to?: string | undefined, status?: ('generating' | 'opened' | 'paid' | 'overdue' | 'canceled' | 'draft' | 'generation_failed' | 'validation_failed' | 'blocked' | 'chargeback') | undefined}; export type GetApiV1ReportsBankBilletsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bankBilletReportObject = z.object({bank_billet_account_id: z.number().int().nullable().optional(), bank_billet_count: z.number().int().nullable().optional(), bank_billet_amount: z.number().nullable().optional()}); export const getApiV1ReportsBankBilletsResponse = z.array(bankBilletReportObject); 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 }; /** * Contagem de Boletos. * * GET /v1/reports/bank_billets */ export const getApiV1ReportsBankBillets = async (args: GetApiV1ReportsBankBilletsArgs, options?: GetApiV1ReportsBankBilletsOptions) => { const {baseUrl = "https://api-sandbox.kobana.com.br", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (args.expire_from != null) query.append("expire_from", String(args.expire_from)) if (args.expire_to != null) query.append("expire_to", String(args.expire_to)) if (args.paid_from != null) query.append("paid_from", String(args.paid_from)) if (args.paid_to != null) query.append("paid_to", String(args.paid_to)) if (args.registered_from != null) query.append("registered_from", String(args.registered_from)) if (args.registered_to != null) query.append("registered_to", String(args.registered_to)) if (args.created_from != null) query.append("created_from", String(args.created_from)) if (args.created_to != null) query.append("created_to", String(args.created_to)) if (args.status != null) query.append("status", String(args.status)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/reports/bank_billets${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(getApiV1ReportsBankBilletsResponse, await res.json()) };