import {z} from 'zod' export type GetApiApiV1AccountingAccountsAccountIdArgs = {account_id: string}; export type GetApiApiV1AccountingAccountsAccountIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSharedEnum5433445ffc = z.enum(["asset", "liability", "equity", "revenue", "expense"]); export const apiSharedEnum1d20f1f7e9 = z.enum(["debit", "credit"]); export const apiSharedEnum87e38e3147 = z.enum(["ar", "ap", "vat_credit", "vat_debit", "revenue", "cogs", "merchandise", "values_to_deposit", "cash_in_transit", "deferred_checks_payable", "bounced_checks", "check_discount_expense", "card_pending", "card_commission", "cash_differences", "customer_advances", "supplier_advances", "wh_vat_suffered", "iibb_credits_suffered", "wh_income_tax_suffered", "wh_suss_suffered", "wh_stamps_suffered", "wh_vat_payable", "wh_iibb_payable", "wh_income_tax_payable", "wh_suss_payable", "perc_vat_suffered", "perc_vat_payable", "perc_iibb_payable", "purchases_non_taxable", "sales_non_taxable", "discounts_received", "taxes_expense", "misc_expense", "stock_adjustment_positive", "stock_adjustment_negative", "exchange_difference", "recpam", "fiscal_year_result", "capital_adjustment"]); export const apiSharedEnuma6084829bf = z.enum(["revenue", "cogs", "operating_expense", "depreciation_amortization", "other_operating_income", "other_operating_expense", "financial_income", "financial_expense", "income_tax"]); export const apiAccountingAccount = z.object({object: z.literal("account"), id: z.string(), code: z.string().nullable(), name: z.string(), description: z.string().nullable(), type: apiSharedEnum5433445ffc, normal_balance: apiSharedEnum1d20f1f7e9, system_role: apiSharedEnum87e38e3147.nullable(), is_active: z.boolean(), is_postable: z.boolean(), parent_id: z.string().nullable(), income_statement_category: apiSharedEnuma6084829bf.nullable(), is_inflation_adjustable: z.boolean()}); export const getApiApiV1AccountingAccountsAccountIdResponse = z.object({request_id: z.string().optional(), data: apiAccountingAccount.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 }; /** * Obtener cuenta contable * * GET /api/v1/accounting/accounts/{account_id} */ export const getApiApiV1AccountingAccountsAccountId = async (args: GetApiApiV1AccountingAccountsAccountIdArgs, options?: GetApiApiV1AccountingAccountsAccountIdOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/accounting/accounts/${encodeURIComponent(String(args.account_id))}${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(getApiApiV1AccountingAccountsAccountIdResponse, await res.json()) };