import {z} from 'zod' export type InvoiceRecurrencePostDto = {updateType?: ('SINGLE_RECURRENCE' | 'FUTURE_ONLY' | 'ALL_IN_SERIES') | undefined, frequency?: ('ONE_TIME' | 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY') | undefined, interval?: number | undefined, endDate?: string | undefined}; export type JsonNode = {empty?: boolean | undefined, array?: boolean | undefined, null?: boolean | undefined, object?: boolean | undefined, float?: boolean | undefined, string?: boolean | undefined, number?: boolean | undefined, missingNode?: boolean | undefined, valueNode?: boolean | undefined, nodeType?: ('ARRAY' | 'BINARY' | 'BOOLEAN' | 'MISSING' | 'NULL' | 'NUMBER' | 'OBJECT' | 'POJO' | 'STRING') | undefined, pojo?: boolean | undefined, integralNumber?: boolean | undefined, floatingPointNumber?: boolean | undefined, short?: boolean | undefined, int?: boolean | undefined, long?: boolean | undefined, double?: boolean | undefined, bigDecimal?: boolean | undefined, bigInteger?: boolean | undefined, textual?: boolean | undefined, boolean?: boolean | undefined, binary?: boolean | undefined, container?: boolean | undefined, embeddedValue?: boolean | undefined} | null; export type ManualJournalEntryPostDto = {id?: string | undefined, status?: ('ACTIVE' | 'INACTIVE' | 'REMOVED') | undefined, description?: string | undefined, recurrence?: InvoiceRecurrencePostDto | undefined, apiName?: ('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') | undefined, apiSourceId?: string | undefined, children?: (Array<{glAccountId?: string | undefined, crAmount?: number | undefined, drAmount?: number | undefined}>) | undefined, customData?: JsonNode | undefined}; export type MultiParamManualJournalEntryPostDto = {data: Array}; export type CreateApiV6AccountingManualJournalEntriesArgs = {body: MultiParamManualJournalEntryPostDto}; export type CreateApiV6AccountingManualJournalEntriesOptions = {baseUrl?: string | undefined, EmbedToken?: string | undefined, fetch?: typeof fetch | undefined}; export const httpStatus = z.union([z.literal(200), z.literal(400), z.literal(401), z.literal(403), z.literal(404), z.literal(500)]); export const invoiceRecurrenceGetDto = z.object({frequency: z.enum(["ONE_TIME", "DAILY", "WEEKLY", "MONTHLY", "YEARLY"]).nullable(), interval: z.number().int().nullable(), endDate: z.string().nullable()}).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 manualJournalEntryChildGetDto = z.object({glAccount: glAccountExpanded, amount: z.number().int(), crAmount: z.number().int(), drAmount: z.number().int()}); 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 manualJournalEntryGetDto = z.object({id: z.string(), status: z.enum(["ACTIVE", "INACTIVE", "REMOVED"]), date: z.string(), description: z.string().nullable(), amount: z.number().int(), recurrence: invoiceRecurrenceGetDto, 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"]).nullable(), apiSourceId: z.string().nullable(), children: z.array(manualJournalEntryChildGetDto), customData: jsonNode.optional()}); export const errorItem = z.object({type: z.enum(["UNKNOWN_ERROR", "INVALID_TOKEN", "EXPIRED_TOKEN", "FORBIDDEN", "BAD_REQUEST", "JSON_ERROR", "DUPLICATE", "REQUIRED", "INVALID_VALUE", "NOT_MODIFIABLE", "INVALID_FORMAT", "NOT_FOUND"]).optional(), message: z.string().optional(), param: z.string().optional()}); export const multiResponseManualJournalEntryGetDto = z.object({result: z.enum(["SUCCESS", "FAILURE"]).optional(), statusCode: httpStatus.optional(), data: manualJournalEntryGetDto.optional(), error: z.array(errorItem).optional()}); export const responseListMultiResponseManualJournalEntryGetDto = z.object({result: z.enum(["SUCCESS", "FAILURE"]).optional(), data: z.array(multiResponseManualJournalEntryGetDto).optional(), error: z.array(errorItem).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 }; /** * Save manual journal entries * * POST /v6/accounting/manualJournalEntries */ export const createApiV6AccountingManualJournalEntries = async (args: CreateApiV6AccountingManualJournalEntriesArgs, options?: CreateApiV6AccountingManualJournalEntriesOptions) => { 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 (EmbedToken !== undefined) headers.set('authorization', `Bearer ${EmbedToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v6/accounting/manualJournalEntries${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(responseListMultiResponseManualJournalEntryGetDto, await res.json()) };