/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../../lib/primitives.js"; import { safeParse } from "../../../lib/schemas.js"; import { Decimal as Decimal$ } from "../../types/decimal.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { BankAccountStatus, BankAccountStatus$inboundSchema, } from "./bankaccountstatus.js"; import { Links, Links$inboundSchema } from "./links.js"; /** * The type of transactions and balances on the account. * * @remarks * For Credit accounts, positive balances are liabilities, and positive transactions **reduce** liabilities. * For Debit accounts, positive balances are assets, and positive transactions **increase** assets. */ export const BankAccountsBankAccountType = { Unknown: "Unknown", Credit: "Credit", Debit: "Debit", } as const; /** * The type of transactions and balances on the account. * * @remarks * For Credit accounts, positive balances are liabilities, and positive transactions **reduce** liabilities. * For Debit accounts, positive balances are assets, and positive transactions **increase** assets. */ export type BankAccountsBankAccountType = ClosedEnum< typeof BankAccountsBankAccountType >; export type Metadata = { /** * Indicates whether the record has been deleted in the third-party system this record originated from. */ isDeleted?: boolean | null | undefined; }; /** * Supplemental data is additional data you can include in our standard data types. * * @remarks * * It is referenced as a configured dynamic key value pair that is unique to the accounting software. [Learn more](https://docs.codat.io/using-the-api/supplemental-data/overview) about supplemental data. */ export type SupplementalData = { content?: { [k: string]: { [k: string]: any } } | null | undefined; }; /** * > **Accessing Bank Accounts through Banking API** * * @remarks * > * > This datatype was originally used for accessing bank account data both in accounting integrations and open banking aggregators. * > * > To view bank account data through the Banking API, please refer to the new [Banking: Account](https://docs.codat.io/bank-feeds-api#/schemas/Account) data type. * * ## Overview * * A list of bank accounts associated with a company and a specific data connection. * * Bank accounts data includes: * * The name and ID of the account in the accounting software. * * The currency and balance of the account. * * The sort code and account number. */ export type AccountingBankAccount = { modifiedDate?: string | undefined; sourceModifiedDate?: string | undefined; /** * Identifier for the account, unique for the company in the accounting software. */ id?: string | undefined; /** * Name of the bank account in the accounting software. */ accountName?: string | null | undefined; /** * The type of transactions and balances on the account. * * @remarks * For Credit accounts, positive balances are liabilities, and positive transactions **reduce** liabilities. * For Debit accounts, positive balances are assets, and positive transactions **increase** assets. */ accountType?: BankAccountsBankAccountType | undefined; /** * Code used to identify each nominal account for a business. */ nominalCode?: string | null | undefined; /** * Sort code for the bank account. * * @remarks * * Xero integrations * The sort code is only displayed when the currency = GBP and the sort code and account number sum to 14 digits. For non-GBP accounts, this field is not populated. */ sortCode?: string | null | undefined; /** * Account number for the bank account. * * @remarks * * Xero integrations * Only a UK account number shows for bank accounts with GBP currency and a combined total of sort code and account number that equals 14 digits, For non-GBP accounts, the full bank account number is populated. * * FreeAgent integrations * For Credit accounts, only the last four digits are required. For other types, the field is optional. */ accountNumber?: string | null | undefined; /** * International bank account number of the account. Often used when making or receiving international payments. */ iBan?: string | null | undefined; /** * The currency data type in Codat is the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code, e.g. _GBP_. * * @remarks * * ## Unknown currencies * * In line with the ISO 4217 specification, the code _XXX_ is used when the data source does not return a currency for a transaction. * * There are only a very small number of edge cases where this currency code is returned by the Codat system. */ currency?: string | undefined; /** * Balance of the bank account. */ balance?: Decimal$ | number | null | undefined; /** * The institution of the bank account. */ institution?: string | null | undefined; /** * Total available balance of the bank account as reported by the underlying data source. This may take into account overdrafts or pending transactions for example. */ availableBalance?: Decimal$ | number | null | undefined; /** * Pre-arranged overdraft limit of the account. * * @remarks * * The value is always positive. For example, an overdraftLimit of `1000` means that the balance of the account can go down to `-1000`. */ overdraftLimit?: Decimal$ | number | null | undefined; /** * Status of the bank account. */ status?: BankAccountStatus | undefined; metadata?: Metadata | undefined; /** * Supplemental data is additional data you can include in our standard data types. * * @remarks * * It is referenced as a configured dynamic key value pair that is unique to the accounting software. [Learn more](https://docs.codat.io/using-the-api/supplemental-data/overview) about supplemental data. */ supplementalData?: SupplementalData | undefined; }; export type BankAccounts = { results?: Array | undefined; /** * Current page number. */ pageNumber: number; /** * Number of items to return in results array. */ pageSize: number; /** * Total number of items. */ totalResults: number; links: Links; }; /** @internal */ export const BankAccountsBankAccountType$inboundSchema: z.ZodNativeEnum< typeof BankAccountsBankAccountType > = z.nativeEnum(BankAccountsBankAccountType); /** @internal */ export const Metadata$inboundSchema: z.ZodType< Metadata, z.ZodTypeDef, unknown > = z.object({ isDeleted: z.nullable(z.boolean()).optional(), }); export function metadataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Metadata$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Metadata' from JSON`, ); } /** @internal */ export const SupplementalData$inboundSchema: z.ZodType< SupplementalData, z.ZodTypeDef, unknown > = z.object({ content: z.nullable(z.record(z.record(z.any()))).optional(), }); export function supplementalDataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SupplementalData$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SupplementalData' from JSON`, ); } /** @internal */ export const AccountingBankAccount$inboundSchema: z.ZodType< AccountingBankAccount, z.ZodTypeDef, unknown > = z.object({ modifiedDate: z.string().optional(), sourceModifiedDate: z.string().optional(), id: z.string().optional(), accountName: z.nullable(z.string()).optional(), accountType: BankAccountsBankAccountType$inboundSchema.optional(), nominalCode: z.nullable(z.string()).optional(), sortCode: z.nullable(z.string()).optional(), accountNumber: z.nullable(z.string()).optional(), iBan: z.nullable(z.string()).optional(), currency: z.string().optional(), balance: z.nullable(z.number().transform(v => new Decimal$(v))).optional(), institution: z.nullable(z.string()).optional(), availableBalance: z.nullable(z.number().transform(v => new Decimal$(v))) .optional(), overdraftLimit: z.nullable(z.number().transform(v => new Decimal$(v))) .optional(), status: BankAccountStatus$inboundSchema.optional(), metadata: z.lazy(() => Metadata$inboundSchema).optional(), supplementalData: z.lazy(() => SupplementalData$inboundSchema).optional(), }); export function accountingBankAccountFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => AccountingBankAccount$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AccountingBankAccount' from JSON`, ); } /** @internal */ export const BankAccounts$inboundSchema: z.ZodType< BankAccounts, z.ZodTypeDef, unknown > = z.object({ results: z.array( z.nullable(z.lazy(() => AccountingBankAccount$inboundSchema)), ).optional(), pageNumber: z.number().int(), pageSize: z.number().int(), totalResults: z.number().int(), _links: Links$inboundSchema, }).transform((v) => { return remap$(v, { "_links": "links", }); }); export function bankAccountsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => BankAccounts$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BankAccounts' from JSON`, ); }