import {z} from 'zod' export type GetApiV1BankaccountsIdTransactionsArgs = {id: number, PageIndex?: number | undefined, PageSize?: number | undefined, OrderBy?: string | undefined, From?: string | undefined, To?: string | undefined, SearchTerm?: string | undefined, HideExcluded?: boolean | undefined, HideReconciliated?: boolean | undefined}; export type GetApiV1BankaccountsIdTransactionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bankTransactionNature = z.enum(["Transfer", "Order", "Check", "CashDeposit", "Payback", "Withdrawal", "Loan", "BankFees", "Card", "CardSummary", "Interest", "Dividend", "Other"]); export const paymentMethod = z.enum(["Transfer", "Order", "Check", "Cash", "Card", "Bill", "Usec", "Other"]); export const bankTransaction = z.object({bankAccountId: z.number().int().optional(), category: z.string().nullable().optional(), coming: z.boolean().optional(), date: z.string().optional(), fullLabel: z.string().nullable().optional(), id: z.number().int().optional(), includedExternalFeesAmount: z.number().optional(), isExcluded: z.boolean().optional(), isImported: z.boolean().optional(), isReconciliated: z.boolean().optional(), label: z.string().nullable().optional(), metadata: z.record(z.string(), z.string().nullable()).nullable().optional(), nature: bankTransactionNature.optional(), notes: z.string().nullable().optional(), paymentMethod: paymentMethod.optional(), transactionId: z.string().nullable().optional(), value: z.number().optional(), valueDate: z.string().nullable().optional()}); export const getApiV1BankaccountsIdTransactionsResponse = z.array(bankTransaction); 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 a bank account's transactions * * GET /v1/bankaccounts/{id}/transactions */ export const getApiV1BankaccountsIdTransactions = async (args: GetApiV1BankaccountsIdTransactionsArgs, options?: GetApiV1BankaccountsIdTransactionsOptions) => { const {baseUrl = "https://api.altoviz.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.PageIndex != null) query.append("PageIndex", String(args.PageIndex)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.OrderBy != null) query.append("OrderBy", String(args.OrderBy)) if (args.From != null) query.append("From", String(args.From)) if (args.To != null) query.append("To", String(args.To)) if (args.SearchTerm != null) query.append("SearchTerm", String(args.SearchTerm)) if (args.HideExcluded != null) query.append("HideExcluded", String(args.HideExcluded)) if (args.HideReconciliated != null) query.append("HideReconciliated", String(args.HideReconciliated)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/bankaccounts/${encodeURIComponent(String(args.id))}/transactions${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(getApiV1BankaccountsIdTransactionsResponse, await res.json()) };