import {z} from 'zod' export type GetApiApiFinancialStatementsArgs = {link?: string | undefined, page_size?: number | undefined, page?: number | undefined, omit?: string | undefined, fields?: string | undefined, link__in?: Array | undefined, id?: string | undefined, id__in?: Array | undefined, created_at?: string | undefined, created_at__gt?: string | undefined, created_at__gte?: string | undefined, created_at__lt?: string | undefined, created_at__lte?: string | undefined, created_at__range?: Array | undefined}; export type GetApiApiFinancialStatementsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const id = z.string(); export const link = z.string().nullable(); export const collectedAt = z.string(); export const createdAt = z.string(); export const financialStatementBalanceSheetCurrentAssets = z.object({cash_and_equivalents: z.number().nullable(), short_term_investments: z.number().nullable(), accounts_receivable: z.number().nullable(), notes_receivable: z.number().nullable(), other_debtors: z.number().nullable(), bad_debt_provision: z.number().nullable(), tax_recoverable: z.number().nullable(), inventory: z.number().nullable(), prepaid_expenses: z.number().nullable(), assets_available_for_sale: z.number().nullable(), total: z.number().nullable()}); export const financialStatementBalanceSheetNonCurrentAssets = z.object({property_plant_and_equipment: z.number().nullable(), accumulated_depreciation_and_amortization: z.number().nullable(), long_term_accounts_receivable: z.number().nullable(), prepayment_to_suppliers: z.number().nullable(), goodwill: z.number().nullable(), intangible_assets: z.number().nullable(), investments_in_associates: z.number().nullable(), long_term_financial_instruments: z.number().nullable(), total: z.number().nullable()}); export const financialStatementBalanceSheetCurrentLiabilities = z.object({bank_loans: z.number().nullable(), accounts_payable: z.number().nullable(), notes_payable: z.number().nullable(), financial_instruments: z.number().nullable(), other_creditors: z.number().nullable(), income_tax_payable: z.number().nullable(), customer_advances: z.number().nullable(), provisions: z.number().nullable(), taxes_payable: z.number().nullable(), total: z.number().nullable()}); export const financialStatementBalanceSheetNonCurrentLiabilities = z.object({long_term_accounts_payable: z.number().nullable(), long_term_financial_instruments: z.number().nullable(), deferred_revenue: z.number().nullable(), contributions_for_future_capital_increases: z.number().nullable(), deferred_income_tax: z.number().nullable(), employee_benefits: z.number().nullable(), long_term_provisions: z.number().nullable(), total: z.number().nullable()}); export const financialStatementBalanceSheetEquity = z.object({stockholders_equity: z.number().nullable(), future_capital_contributions: z.number().nullable(), legal_reserve: z.number().nullable(), capital_update_excess: z.number().nullable(), capital_update_insufficiency: z.number().nullable(), capital_reserve: z.number().nullable(), share_premium_on_stock_sales: z.number().nullable(), retained_earnings: z.number().nullable(), other_comprehensive_income: z.number().nullable(), controlling_interest: z.number().nullable(), non_controlling_interest: z.number().nullable(), total: z.number().nullable()}); export const financialStatementBalanceSheet = z.object({current_assets: financialStatementBalanceSheetCurrentAssets.optional(), non_current_assets: financialStatementBalanceSheetNonCurrentAssets.optional(), current_liabilities: financialStatementBalanceSheetCurrentLiabilities.optional(), non_current_liabilities: financialStatementBalanceSheetNonCurrentLiabilities.optional(), equity: financialStatementBalanceSheetEquity.optional()}); export const financialStatementIncomeStatement = z.object({net_revenue: z.number().nullable(), domestic_sales: z.number().nullable(), foreign_sales: z.number().nullable(), materials_used: z.number().nullable(), cost_of_goods_sold: z.number().nullable(), cost_of_services_sold: z.number().nullable(), gross_profit: z.number().nullable(), gross_loss: z.number().nullable(), operating_expenses: z.number().nullable(), operating_income: z.number().nullable(), operating_loss: z.number().nullable(), financial_result: z.number().nullable(), income_statement_financial_gains: z.number().gte(0).nullable(), income_statement_financial_costs: z.number().lte(0).nullable(), equity_in_earnings_of_affiliates: z.number().nullable(), income_before_taxes: z.number().nullable(), loss_before_taxes: z.number().nullable(), income_taxes: z.number().nullable(), income_from_continuing_operations: z.number().nullable(), loss_from_continuing_operations: z.number().nullable(), discontinued_operations: z.number().nullable(), net_income: z.number().nullable(), net_loss: z.number().nullable()}); export const financialStatement = z.object({id: id, link: link, collected_at: collectedAt, created_at: createdAt, error: z.string().nullable(), year: z.string(), currency: z.string(), balance_sheet: financialStatementBalanceSheet, income_statement: financialStatementIncomeStatement}); export const getApiApiFinancialStatementsResponse = z.object({count: z.number().int().optional(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(financialStatement).optional()}); 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 }; /** * List Financial Statements * * GET /api/financial-statements/ */ export const getApiApiFinancialStatements = async (args: GetApiApiFinancialStatementsArgs, options?: GetApiApiFinancialStatementsOptions) => { const {baseUrl = "https://sandbox.belvo.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.link != null) query.append("link", String(args.link)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page != null) query.append("page", String(args.page)) if (args.omit != null) query.append("omit", String(args.omit)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.link__in != null) query.append("link__in", args.link__in.join(',')) if (args.id != null) query.append("id", String(args.id)) if (args.id__in != null) query.append("id__in", args.id__in.join(',')) if (args.created_at != null) query.append("created_at", String(args.created_at)) if (args.created_at__gt != null) query.append("created_at__gt", String(args.created_at__gt)) if (args.created_at__gte != null) query.append("created_at__gte", String(args.created_at__gte)) if (args.created_at__lt != null) query.append("created_at__lt", String(args.created_at__lt)) if (args.created_at__lte != null) query.append("created_at__lte", String(args.created_at__lte)) if (args.created_at__range != null) query.append("created_at__range", args.created_at__range.join(',')) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/financial-statements/${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(getApiApiFinancialStatementsResponse, await res.json()) };