import {z} from 'zod' export type CreateApiApiV1StatementsArgs = {'Idempotency-Key': string, body: {bank_account_id: string, period_start: string, period_end: string, opening_balance: number, closing_balance: number, lines: Array<{external_id: string, date: string, description: string, amount: number, reference?: (string | null) | undefined, running_balance?: (number | null) | undefined}>, source?: 'normalized' | undefined} | {source: 'mercadopago_release', bank_account_id: string, period_start: string, period_end: string}}; export type CreateApiApiV1StatementsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSharedEnumffb4886f2b = z.enum(["ARS", "USD"]); export const apiSharedEnum6527b55801 = z.enum(["spreadsheet", "normalized", "mercadopago_release"]); export const apiSharedObjectadb8c61c7c = z.object({object: z.literal("statement"), id: z.string(), bank_account_id: z.string(), period_start: z.string(), period_end: z.string(), opening_balance: z.number().int(), closing_balance: z.number().int(), currency: apiSharedEnumffb4886f2b, source: apiSharedEnum6527b55801, created_at: z.string(), updated_at: z.string()}); export const apiSharedObject11052f1fc2 = z.object({request_id: z.string(), data: apiSharedObjectadb8c61c7c}); 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 }; /** * Import statement * * POST /api/v1/statements */ export const createApiApiV1Statements = async (args: CreateApiApiV1StatementsArgs, options?: CreateApiApiV1StatementsOptions) => { const {baseUrl = "https://api.lapyme.com.ar", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/statements${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(apiSharedObject11052f1fc2, await res.json()) };