import {z} from 'zod' export type BankTransactionsSort = {orderBy?: ('DATE' | 'AMOUNT' | 'DESCRIPTION' | 'STATUS' | 'REVIEW_STATUS') | undefined, direction?: ('ASC' | 'DESC') | undefined, start?: string | undefined}; export type DateFilter = {equal?: string | undefined, notEqual?: string | undefined, greaterThan?: string | undefined, greaterThanEqual?: string | undefined, lessThan?: string | undefined, lessThanEqual?: string | undefined}; export type AmountFilter = {equal?: number | undefined, notEqual?: number | undefined, greaterThan?: number | undefined, greaterThanEqual?: number | undefined, lessThan?: number | undefined, lessThanEqual?: number | undefined}; export type StringFilter = {equal?: string | undefined, notEqual?: string | undefined, greaterThan?: string | undefined, greaterThanEqual?: string | undefined, lessThan?: string | undefined, lessThanEqual?: string | undefined, contain?: string | undefined}; export type EnumStatusListFilter = {in?: (Array<'ACTIVE' | 'INACTIVE' | 'REMOVED'>) | undefined, notIn?: (Array<'ACTIVE' | 'INACTIVE' | 'REMOVED'>) | undefined, equal?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, notEqual?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, greaterThan?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, greaterThanEqual?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, lessThan?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, lessThanEqual?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined}; export type ReviewStatusListFilter = {in?: (Array<'RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED'>) | undefined, notIn?: (Array<'RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED'>) | undefined, equal?: ('RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED') | undefined, notEqual?: ('RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED') | undefined, greaterThan?: ('RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED') | undefined, greaterThanEqual?: ('RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED') | undefined, lessThan?: ('RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED') | undefined, lessThanEqual?: ('RECONCILIATION_DISCREPANCY' | 'USER_REVIEW_REQUIRED' | 'ACCOUNTANT_REVIEW_REQUIRED' | 'PARTNER_REVIEW_REQUIRED' | 'AWAITING_MATCH' | 'STAGED' | 'RECONCILED') | undefined}; export type BankTransactionTypeFilter = {in?: (Array<'EXPENSE' | 'REVENUE' | 'TRANSFER_IN' | 'TRANSFER_OUT'>) | undefined, notIn?: (Array<'EXPENSE' | 'REVENUE' | 'TRANSFER_IN' | 'TRANSFER_OUT'>) | undefined}; export type BankAccountIds = {in?: Array | undefined, notIn?: Array | undefined}; export type BankAccountExpandFilter = {expand?: boolean | undefined, id?: BankAccountIds | undefined}; export type VendorIds = {in?: Array | undefined}; export type VendorExpandFilter = {expand?: boolean | undefined, id?: VendorIds | undefined}; export type DimensionValueIds = {in?: Array | undefined}; export type DimensionValueExpandFilter = {expand?: boolean | undefined, id?: DimensionValueIds | undefined}; export type CustomerIds = {in?: Array | undefined}; export type CustomerExpandFilter = {expand?: boolean | undefined, id?: CustomerIds | undefined}; export type CategoryIds = {in?: Array | undefined}; export type CategoryExpandFilter = {expand?: boolean | undefined, id?: CategoryIds | undefined}; export type GlAccountIds = {in?: Array | undefined}; export type GlAccountExpandFilter = {expand?: boolean | undefined, id?: GlAccountIds | undefined}; export type MatchingBankTransactionIds = {equal?: (string | null) | undefined}; export type MatchingBankTransactionFilter = {expand?: boolean | undefined, id?: MatchingBankTransactionIds | undefined}; export type ConversationFilter = {expand?: boolean | undefined}; export type InvoiceLineItemFilter = {expand?: boolean | undefined}; export type InvoiceFilter = {expand?: boolean | undefined, lineItems?: InvoiceLineItemFilter | undefined}; export type BillLineItemFilter = {expand?: boolean | undefined}; export type BillFilter = {expand?: boolean | undefined, lineItems?: BillLineItemFilter | undefined}; export type PayrollLineItemFilter = {expand?: boolean | undefined}; export type PayrollFilter = {expand?: boolean | undefined, lineItems?: PayrollLineItemFilter | undefined}; export type CompanyIdFilter = {in?: Array | undefined}; export type BankTransactionsFilterParam = {search?: string | undefined, date?: DateFilter | undefined, amount?: AmountFilter | undefined, description?: StringFilter | undefined, notes?: StringFilter | undefined, status?: EnumStatusListFilter | undefined, reviewStatus?: ReviewStatusListFilter | undefined, type?: BankTransactionTypeFilter | undefined, bankAccount?: BankAccountExpandFilter | undefined, vendor?: VendorExpandFilter | undefined, dimensionValues?: DimensionValueExpandFilter | undefined, customer?: CustomerExpandFilter | undefined, category?: CategoryExpandFilter | undefined, glAccount?: GlAccountExpandFilter | undefined, reconciliationMatch?: MatchingBankTransactionFilter | undefined, conversation?: ConversationFilter | undefined, invoice?: InvoiceFilter | undefined, bill?: BillFilter | undefined, payroll?: PayrollFilter | undefined, company?: CompanyIdFilter | undefined, lastUpdatedDateTime?: string | undefined}; export type BankTransactionsGetParam = {cursor?: (string | null) | undefined, limit?: number | undefined, sort?: BankTransactionsSort | undefined, filter?: BankTransactionsFilterParam | undefined}; export type CreateApiV6BanksTransactionsQueryArgs = {'Tight-Version'?: '6' | undefined, body: BankTransactionsGetParam}; export type CreateApiV6BanksTransactionsQueryOptions = {baseUrl?: string | undefined, EmbedToken?: string | undefined, fetch?: typeof fetch | undefined}; export const currencyInfo = z.object({originalCurrency: z.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "UYI", "UYU", "UYW", "UZS", "VED", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX", "YER", "ZAR", "ZMW", "ZWL"]).optional(), originalAmount: z.number().int().optional(), exchangeDate: z.string().optional()}); export const bankAccountExpanded = z.object({id: z.string(), name: z.string().optional(), displayName: z.string().optional()}); export const dimensionExpanded = z.object({id: z.string(), name: z.string().optional(), requiredness: z.enum(["REQUIRED", "NOT_REQUIRED"]).optional()}); export const childDimensionValue: z.ZodType = z.object({id: z.string(), dimension: dimensionExpanded.optional(), name: z.string().optional(), child: z.lazy(() => childDimensionValue.optional())}); export const dimensionValueExpanded = z.object({id: z.string(), dimension: dimensionExpanded.optional(), name: z.string().optional(), child: childDimensionValue.optional()}); export const customerExpanded = z.object({id: z.string(), name: z.string().optional(), email: z.string().optional()}).nullable(); export const vendorExpanded = z.object({id: z.string(), name: z.string().optional()}).nullable(); export const categoryExpanded = z.object({id: z.string(), name: z.string().optional(), iconUrl: z.string().optional()}).nullable(); export const glAccountExpanded = z.object({id: z.string(), name: z.string().optional(), accountNo: z.string().optional(), type: z.enum(["ASSET", "LIABILITY", "EQUITY", "INCOME", "COGS", "EXPENSE", "OTHER_INCOME", "OTHER_EXPENSE", "SUSPENSE"]).optional(), iconUrl: z.string().optional(), displayName: z.string().optional()}); export const matchingBankTransactionExpanded = z.object({id: z.string().optional(), apiSourceId: z.string().nullable().optional(), amount: z.number().int().optional(), date: z.string().optional(), description: z.string().optional(), apiName: z.enum(["BOX", "CLOVER", "STRIPE", "PLAID", "KNOX", "UBER", "FRESHBOOKS", "HARVEST", "KW", "FRESHBOOKS2", "CAPITAL_ONE", "SQUARE", "DOTLOOP", "REALOGY", "UPWORK", "SHOPIFY", "DEDUCTR", "ENTERPRISE", "MOXIWORKS", "APPDIRECT", "LONEWOLF", "LONEWOLF_TRANSACTIONDESK", "SAMPLE_BANK", "TAXBOT", "GUSTO", "XERO", "UNIT", "MOOV", "QBO", "QUALPAY", "BENCH", "PARTNER_IMPLEMENTATION", "CHECK", "RUTTER", "WAVE", "MANUAL_ENTRY", "CSV_IMPORT", "ADYEN", "PAYABLI"]).optional(), apiInstitutionId: z.string().nullable().optional(), bankAccount: bankAccountExpanded.optional()}).nullable(); export const conversationExpanded = z.object({id: z.string(), readStatus: z.enum(["READ", "UNREAD"]).optional()}).nullable(); export const companyExpanded = z.object({id: z.string(), name: z.string().optional()}); export const bankTransactionAttachmentExpanded = z.object({id: z.string(), url: z.string().optional(), fileName: z.string().optional(), fileSize: z.string().optional(), createdDateTime: z.string().optional(), iconUrl: z.string().optional()}); export const taxPaymentFields = z.object({region: z.enum(["FEDERAL", "STATE", "SALES"]).optional(), year: z.number().int().optional(), quarter: z.enum(["Q1", "Q2", "Q3", "Q4"]).optional()}).nullable(); export const taxData = z.object({paymentInfo: taxPaymentFields.optional()}); export const invoiceLineItem = z.object({id: z.string().optional(), amount: z.number().int().optional()}); export const invoiceExpanded = z.object({id: z.string(), name: z.string().optional(), date: z.string().optional(), lineItems: z.array(invoiceLineItem).optional()}).nullable(); export const billLineItem = z.object({id: z.string().optional(), amount: z.number().int().optional()}); export const billExpanded = z.object({id: z.string(), name: z.string().optional(), lineItems: z.array(billLineItem).optional()}).nullable(); export const payrollLineItem = z.object({id: z.string().optional(), amount: z.number().int().optional()}); export const payrollExpanded = z.object({id: z.string(), date: z.string().optional(), checkDate: z.string().optional(), description: z.string().optional(), lineItems: z.array(payrollLineItem).optional()}).nullable(); export const bankTransactionChildGetDto = z.object({id: z.string(), type: z.enum(["EXPENSE", "REVENUE", "TRANSFER_IN", "TRANSFER_OUT"]), date: z.string(), amount: z.number().int(), displayName: z.string(), description: z.string(), notes: z.string().nullable(), reviewStatus: z.enum(["RECONCILIATION_DISCREPANCY", "USER_REVIEW_REQUIRED", "ACCOUNTANT_REVIEW_REQUIRED", "PARTNER_REVIEW_REQUIRED", "AWAITING_MATCH", "STAGED", "RECONCILED"]), apiName: z.enum(["PLAID", "UNIT", "STRIPE", "SHOPIFY", "SQUARE", "RUTTER", "UBER", "MOOV", "QUALPAY", "MANUAL_ENTRY", "CSV_IMPORT", "PARTNER_IMPLEMENTATION", "QBO", "XERO", "BENCH", "WAVE"]), iconUrl: z.string(), apiSourceId: z.string().nullable(), bankAccount: bankAccountExpanded, dimensionValues: z.array(dimensionValueExpanded), customer: customerExpanded.nullable(), vendor: vendorExpanded.nullable(), category: categoryExpanded.nullable(), glAccount: glAccountExpanded, invoice: invoiceExpanded.nullable(), bill: billExpanded.nullable(), payroll: payrollExpanded.nullable(), paymentId: z.string().nullable(), apiItemId: z.string().nullable().optional()}); export const jsonNode = z.object({empty: z.boolean().optional(), array: z.boolean().optional(), null: z.boolean().optional(), object: z.boolean().optional(), float: z.boolean().optional(), string: z.boolean().optional(), number: z.boolean().optional(), missingNode: z.boolean().optional(), valueNode: z.boolean().optional(), nodeType: z.enum(["ARRAY", "BINARY", "BOOLEAN", "MISSING", "NULL", "NUMBER", "OBJECT", "POJO", "STRING"]).optional(), pojo: z.boolean().optional(), integralNumber: z.boolean().optional(), floatingPointNumber: z.boolean().optional(), short: z.boolean().optional(), int: z.boolean().optional(), long: z.boolean().optional(), double: z.boolean().optional(), bigDecimal: z.boolean().optional(), bigInteger: z.boolean().optional(), textual: z.boolean().optional(), boolean: z.boolean().optional(), binary: z.boolean().optional(), container: z.boolean().optional(), embeddedValue: z.boolean().optional()}).nullable(); export const bankTransactionGetDto = z.object({id: z.string(), type: z.enum(["EXPENSE", "REVENUE", "TRANSFER_IN", "TRANSFER_OUT"]), date: z.string(), amount: z.number().int(), currencyInfo: currencyInfo, displayName: z.string(), description: z.string(), notes: z.string().nullable(), status: z.enum(["ACTIVE", "INACTIVE", "REMOVED"]), reviewStatus: z.enum(["RECONCILIATION_DISCREPANCY", "USER_REVIEW_REQUIRED", "ACCOUNTANT_REVIEW_REQUIRED", "PARTNER_REVIEW_REQUIRED", "AWAITING_MATCH", "STAGED", "RECONCILED"]), apiName: z.enum(["PLAID", "UNIT", "STRIPE", "SHOPIFY", "SQUARE", "RUTTER", "UBER", "MOOV", "QUALPAY", "MANUAL_ENTRY", "CSV_IMPORT", "PARTNER_IMPLEMENTATION", "QBO", "XERO", "BENCH", "WAVE"]), iconUrl: z.string(), apiSourceId: z.string().nullable(), bankAccount: bankAccountExpanded, dimensionValues: z.array(dimensionValueExpanded), customer: customerExpanded.nullable(), vendor: vendorExpanded.nullable(), category: categoryExpanded.nullable(), suggestedCategories: z.array(categoryExpanded), glAccount: glAccountExpanded.nullable(), reconciliationMatch: matchingBankTransactionExpanded.nullable(), conversation: conversationExpanded, company: companyExpanded, attachments: z.array(bankTransactionAttachmentExpanded), tax: taxData, children: z.array(bankTransactionChildGetDto), lastUpdatedDateTime: z.string(), customData: jsonNode.optional()}); export const responseCursor = z.object({after: z.string().optional(), before: z.string().optional()}); export const paginatedResponseBankTransactionGetDto = z.object({result: z.enum(["SUCCESS", "FAILURE"]).optional(), data: z.array(bankTransactionGetDto).optional(), cursor: responseCursor.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 }; /** * Query transactions * * POST /v6/banks/transactions/query */ export const createApiV6BanksTransactionsQuery = async (args: CreateApiV6BanksTransactionsQueryArgs, options?: CreateApiV6BanksTransactionsQueryOptions) => { const {baseUrl = "https://sandbox.tight.com", fetch: fetchFn = fetch, EmbedToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Tight-Version'] != null) headers.set("Tight-Version", String(args['Tight-Version'])) if (EmbedToken !== undefined) headers.set('authorization', `Bearer ${EmbedToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v6/banks/transactions/query${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedResponseBankTransactionGetDto, await res.json()) };