import {z} from 'zod' export type GetApiApiV1AccountingAccountsAccountIdLedgerArgs = {account_id: string, cursor?: string | undefined, limit?: number | undefined, date_from?: string | undefined, date_to?: string | undefined, source_type?: string | undefined, contact_id?: string | undefined, cost_center_1_ids?: Array | undefined, cost_center_2_ids?: Array | undefined, cost_center_3_ids?: Array | undefined, circuit_id?: string | undefined}; export type GetApiApiV1AccountingAccountsAccountIdLedgerOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSharedObjectbd6833a5e8 = z.object({circuit_id: z.string().nullable(), circuit_name: z.string()}); export const apiSharedObject18d478a65b = z.object({object: z.literal("account"), id: z.string(), code: z.string().nullable(), name: z.string()}); export const apiSharedObject308596969e = z.object({object: z.literal("account_ledger_line"), id: z.string(), date: z.string(), journal_entry_id: z.string(), circuit_id: z.string().nullable(), account_id: z.string(), source_type: z.string().nullable(), source_id: z.string().nullable(), description: z.string(), reference: z.string().nullable(), counterparty_name: z.string().nullable(), contact_id: z.string().nullable(), cost_center1_id: z.string().nullable(), cost_center2_id: z.string().nullable(), cost_center3_id: z.string().nullable(), debit: z.number().int(), credit: z.number().int(), currency: z.string(), balance: z.number().int()}); export const apiAccountLedgerResponse = z.object({request_id: z.string(), effective_scope: z.union([z.literal("all"), apiSharedObjectbd6833a5e8]), data: z.object({object: z.literal("account_ledger"), account: apiSharedObject18d478a65b, opening_balance: z.number().int(), currency: z.string(), lines: z.array(apiSharedObject308596969e), closing_balance: z.number().int(), has_more: z.boolean(), next_cursor: z.string().nullable()})}); 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 }; /** * Obtener mayor de cuenta * * GET /api/v1/accounting/accounts/{account_id}/ledger */ export const getApiApiV1AccountingAccountsAccountIdLedger = async (args: GetApiApiV1AccountingAccountsAccountIdLedgerArgs, options?: GetApiApiV1AccountingAccountsAccountIdLedgerOptions) => { const {baseUrl = "https://api.lapyme.com.ar", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.source_type != null) query.append("source_type", String(args.source_type)) if (args.contact_id != null) query.append("contact_id", String(args.contact_id)) for (const item of args.cost_center_1_ids ?? []) query.append("cost_center_1_ids", String(item)) for (const item of args.cost_center_2_ids ?? []) query.append("cost_center_2_ids", String(item)) for (const item of args.cost_center_3_ids ?? []) query.append("cost_center_3_ids", String(item)) if (args.circuit_id != null) query.append("circuit_id", String(args.circuit_id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/accounting/accounts/${encodeURIComponent(String(args.account_id))}/ledger${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(apiAccountLedgerResponse, await res.json()) };