/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; 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 { AccountInfo, AccountInfo$inboundSchema, AccountInfo$Outbound, AccountInfo$outboundSchema, } from "./accountinfo.js"; import { RoutingInfo, RoutingInfo$inboundSchema, RoutingInfo$Outbound, RoutingInfo$outboundSchema, } from "./routinginfo.js"; /** * The type of bank account e.g. checking, savings, loan, creditCard, prepaidCard. */ export const SourceAccountV2AccountType = { Checking: "checking", Savings: "savings", Loan: "loan", CreditCard: "creditCard", PrepaidCard: "prepaidCard", } as const; /** * The type of bank account e.g. checking, savings, loan, creditCard, prepaidCard. */ export type SourceAccountV2AccountType = ClosedEnum< typeof SourceAccountV2AccountType >; /** * Status of the source account. */ export const Status = { Pending: "pending", Connected: "connected", Connecting: "connecting", Disconnected: "disconnected", Unknown: "unknown", } as const; /** * Status of the source account. */ export type Status = ClosedEnum; /** * The target bank account in a supported accounting software for ingestion into a bank feed. */ export type SourceAccountV2 = { /** * Unique ID for the bank account. */ id: string; /** * The bank account name. */ accountName: string; /** * The type of bank account e.g. checking, savings, loan, creditCard, prepaidCard. */ accountType: SourceAccountV2AccountType; /** * The account number. */ accountNumber: string; /** * The sort code. */ sortCode?: string | null | undefined; /** * Routing information for the bank. This does not include account number. */ routingInfo?: RoutingInfo | 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; /** * The latest balance for the bank account. */ balance: Decimal$ | number; accountInfo?: AccountInfo | null | undefined; /** * In Codat's data model, dates and times are represented using the ISO 8601 standard. Date and time fields are formatted as strings; for example: * * @remarks * * ``` * 2020-10-08T22:40:50Z * 2021-01-01T00:00:00 * ``` * * When syncing data that contains `DateTime` fields from Codat, make sure you support the following cases when reading time information: * * - Coordinated Universal Time (UTC): `2021-11-15T06:00:00Z` * - Unqualified local time: `2021-11-15T01:00:00` * - UTC time offsets: `2021-11-15T01:00:00-05:00` * * > Time zones * > * > Not all dates from Codat will contain information about time zones. * > Where it is not available from the underlying platform, Codat will return these as times local to the business whose data has been synced. */ modifiedDate?: string | undefined; /** * Status of the source account. */ status?: Status | null | undefined; /** * In Codat's data model, dates are represented using the ISO 8601 standard. Date fields are formatted as strings; for example: * * @remarks * ``` * 2020-10-08 * ``` */ feedStartDate?: string | null | undefined; }; /** @internal */ export const SourceAccountV2AccountType$inboundSchema: z.ZodNativeEnum< typeof SourceAccountV2AccountType > = z.nativeEnum(SourceAccountV2AccountType); /** @internal */ export const SourceAccountV2AccountType$outboundSchema: z.ZodNativeEnum< typeof SourceAccountV2AccountType > = SourceAccountV2AccountType$inboundSchema; /** @internal */ export const Status$inboundSchema: z.ZodNativeEnum = z .nativeEnum(Status); /** @internal */ export const Status$outboundSchema: z.ZodNativeEnum = Status$inboundSchema; /** @internal */ export const SourceAccountV2$inboundSchema: z.ZodType< SourceAccountV2, z.ZodTypeDef, unknown > = z.object({ id: z.string(), accountName: z.string(), accountType: SourceAccountV2AccountType$inboundSchema, accountNumber: z.string(), sortCode: z.nullable(z.string()).optional(), routingInfo: RoutingInfo$inboundSchema.optional(), currency: z.string(), balance: z.number().transform(v => new Decimal$(v)), accountInfo: z.nullable(AccountInfo$inboundSchema).optional(), modifiedDate: z.string().optional(), status: z.nullable(Status$inboundSchema).optional(), feedStartDate: z.nullable(z.string()).optional(), }); /** @internal */ export type SourceAccountV2$Outbound = { id: string; accountName: string; accountType: string; accountNumber: string; sortCode?: string | null | undefined; routingInfo?: RoutingInfo$Outbound | undefined; currency: string; balance: number; accountInfo?: AccountInfo$Outbound | null | undefined; modifiedDate?: string | undefined; status?: string | null | undefined; feedStartDate?: string | null | undefined; }; /** @internal */ export const SourceAccountV2$outboundSchema: z.ZodType< SourceAccountV2$Outbound, z.ZodTypeDef, SourceAccountV2 > = z.object({ id: z.string(), accountName: z.string(), accountType: SourceAccountV2AccountType$outboundSchema, accountNumber: z.string(), sortCode: z.nullable(z.string()).optional(), routingInfo: RoutingInfo$outboundSchema.optional(), currency: z.string(), balance: z.union([z.instanceof(Decimal$), z.number()]).transform(v => typeof v === "number" ? v : v.toNumber() ), accountInfo: z.nullable(AccountInfo$outboundSchema).optional(), modifiedDate: z.string().optional(), status: z.nullable(Status$outboundSchema).optional(), feedStartDate: z.nullable(z.string()).optional(), }); export function sourceAccountV2ToJSON( sourceAccountV2: SourceAccountV2, ): string { return JSON.stringify(SourceAccountV2$outboundSchema.parse(sourceAccountV2)); } export function sourceAccountV2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SourceAccountV2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SourceAccountV2' from JSON`, ); }