import {z} from 'zod' export type File = {id: number, customer: number, created_at: string, created_by: number | null, created_by_name: string, created_by_email: string, last_modified_at: string, name: string, url: string, s3_content_type?: (string | null) | undefined, s3_content_length?: (number | null) | undefined, s3_path: string, object_id?: (number | null) | undefined, app: string, model: string, is_deleted: boolean, deleted_at: string | null}; export type AmortizationSchedule = {id?: number | undefined, amortization?: number | undefined, accounting_amortization?: number | undefined, journal_entry_order: string, date: string, amount: number, posted?: boolean | undefined, customer: number, transaction?: (number | null) | undefined, bill_line?: (number | null) | undefined, debit_memo_line?: (number | null) | undefined, journal_entry?: (number | null) | undefined}; export type PatchedChartTransaction = {id?: number | undefined, is_deleted?: boolean | undefined, deleted_at?: (string | null) | undefined, entity_name?: string | undefined, entity_currency?: string | undefined, account_name?: (string | null) | undefined, account_number?: string | undefined, vendor_name?: string | undefined, vendor_id?: string | undefined, department_name?: string | undefined, department_code?: string | undefined, parent_department_name?: string | undefined, parent_department?: number | undefined, tags?: Array<{[key: string]: unknown}> | undefined, journal?: number | undefined, journal_order?: string | undefined, journal_memo?: string | undefined, journal_type?: string | undefined, intercompany_journal?: number | undefined, created_automatically?: boolean | undefined, journal_attachments?: Array | undefined, journal_type_name?: (string | null) | undefined, invoice?: (string | null) | undefined, bill?: (string | null) | undefined, date_month?: (string | null) | undefined, date_year?: (string | null) | undefined, balance_after_transaction?: number | undefined, bank_account?: string | undefined, bank_account_name?: string | undefined, account?: (number | null) | undefined, last_modified_by_name?: string | undefined, account_type?: string | undefined, account_subtype?: string | undefined, parent_account_name?: string | undefined, files?: string | undefined, invoice_id?: (number | null) | undefined, invoice_number?: (string | null) | undefined, bill_id?: (number | null) | undefined, bill_number?: (string | null) | undefined, file_names?: string | undefined, has_matches?: boolean | undefined, has_ai?: boolean | undefined, has_rules?: boolean | undefined, has_merges?: boolean | undefined, has_fixed_asset_rule_matches?: boolean | undefined, primary_action_type?: string | undefined, suggested_account?: (number | null) | undefined, suggested_account_name?: (string | null) | undefined, suggested_account_number?: (string | null) | undefined, amount?: number | undefined, amount_native?: number | undefined, amount_book?: number | undefined, amortization_schedule?: Array | undefined, linked_amortizations?: Array<{[key: string]: unknown}> | undefined, created_fixed_assets?: Array<{[key: string]: string}> | undefined, reconciliation_report?: string | undefined, opposing_account_name?: string | undefined, opposing_account_number?: string | undefined, tax_rate?: (number | null) | undefined, apply_both_sides?: boolean | undefined, transaction_match_id?: (number | null) | undefined, transaction_id?: string | undefined, debit_amount?: (number | null) | undefined, credit_amount?: (number | null) | undefined, debit_amount_book?: (number | null) | undefined, credit_amount_book?: (number | null) | undefined, debit_amount_native?: (number | null) | undefined, credit_amount_native?: (number | null) | undefined, currency?: string | undefined, exchange_rate?: (number | null) | undefined, exchange_rate_book?: (number | null) | undefined, posted_at?: (string | null) | undefined, merchant_name?: (string | null) | undefined, bank_description?: (string | null) | undefined, tag_ids?: Array | undefined, tag_group_ids?: Array | undefined, note?: (string | null) | undefined, receipt_url?: (string | null) | undefined, balance_before_transaction?: (number | null) | undefined, created_at?: string | undefined, external_id?: (string | null) | undefined, needs_review?: boolean | undefined, last_modified_at?: string | undefined, draft_matches: unknown, last_lam_prediction_attempt?: (string | null) | undefined, customer?: number | undefined, entity?: number | undefined, source_entity?: (number | null) | undefined, parent_bank_transaction?: (number | null) | undefined, vendor?: (number | null) | undefined, department?: (number | null) | undefined, last_modified_by?: (number | null) | undefined}; export type PatchApiCoaApiTransactionIdArgs = {id: number, body: PatchedChartTransaction}; export type PatchApiCoaApiTransactionIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const file = z.object({id: z.number().int(), customer: z.number().int(), created_at: z.string(), created_by: z.number().int().nullable(), created_by_name: z.string(), created_by_email: z.string(), last_modified_at: z.string(), name: z.string(), url: z.string(), s3_content_type: z.string().nullable().optional(), s3_content_length: z.number().int().gte(0).lte(2147483647).nullable().optional(), s3_path: z.string(), object_id: z.number().int().gte(0).lte(2147483647).nullable().optional(), app: z.string(), model: z.string(), is_deleted: z.boolean(), deleted_at: z.string().nullable()}); export const amortizationSchedule = z.object({id: z.number().int().optional(), amortization: z.number().int().optional(), accounting_amortization: z.number().int().optional(), journal_entry_order: z.string(), date: z.string(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000), posted: z.boolean().optional(), customer: z.number().int(), transaction: z.number().int().nullable().optional(), bill_line: z.number().int().nullable().optional(), debit_memo_line: z.number().int().nullable().optional(), journal_entry: z.number().int().nullable().optional()}); export const chartTransaction = z.object({id: z.number().int(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), entity_name: z.string(), entity_currency: z.string(), account_name: z.string().nullable(), account_number: z.string(), vendor_name: z.string(), vendor_id: z.string(), department_name: z.string(), department_code: z.string(), parent_department_name: z.string(), parent_department: z.number().int(), tags: z.array(z.record(z.string(), z.unknown())), journal: z.number().int(), journal_order: z.string(), journal_memo: z.string(), journal_type: z.string(), intercompany_journal: z.number().int(), created_automatically: z.boolean(), journal_attachments: z.array(file), journal_type_name: z.string().nullable(), invoice: z.string().nullable(), bill: z.string().nullable(), date_month: z.string().nullable(), date_year: z.string().nullable(), balance_after_transaction: z.number(), bank_account: z.string(), bank_account_name: z.string(), account: z.number().int().nullable().optional(), last_modified_by_name: z.string(), account_type: z.string(), account_subtype: z.string(), parent_account_name: z.string(), files: z.string(), invoice_id: z.number().int().nullable(), invoice_number: z.string().nullable(), bill_id: z.number().int().nullable(), bill_number: z.string().nullable(), file_names: z.string(), has_matches: z.boolean(), has_ai: z.boolean(), has_rules: z.boolean(), has_merges: z.boolean(), has_fixed_asset_rule_matches: z.boolean(), primary_action_type: z.string(), suggested_account: z.number().int().nullable(), suggested_account_name: z.string().nullable(), suggested_account_number: z.string().nullable(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000), amount_native: z.number().gt(-1000000000000000000).lt(1000000000000000000), amount_book: z.number().gt(-1000000000000000000).lt(1000000000000000000), amortization_schedule: z.array(amortizationSchedule), linked_amortizations: z.array(z.record(z.string(), z.unknown())), created_fixed_assets: z.array(z.record(z.string(), z.string())), reconciliation_report: z.string(), opposing_account_name: z.string(), opposing_account_number: z.string(), tax_rate: z.number().int().nullable().optional(), apply_both_sides: z.boolean().optional(), transaction_match_id: z.number().int().nullable().optional(), transaction_id: z.string(), debit_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), credit_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), debit_amount_book: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), credit_amount_book: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), debit_amount_native: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), credit_amount_native: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), currency: z.string().max(3).optional(), exchange_rate: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), exchange_rate_book: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), posted_at: z.string().nullable().optional(), merchant_name: z.string().nullable().optional(), bank_description: z.string().nullable().optional(), tag_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), tag_group_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), note: z.string().nullable().optional(), receipt_url: z.string().max(512).nullable().optional(), balance_before_transaction: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable(), created_at: z.string(), external_id: z.string().nullable().optional(), needs_review: z.boolean().optional(), last_modified_at: z.string(), draft_matches: z.unknown(), last_lam_prediction_attempt: z.string().nullable().optional(), customer: z.number().int(), entity: z.number().int(), source_entity: z.number().int().nullable().optional(), parent_bank_transaction: z.number().int().nullable().optional(), vendor: z.number().int().nullable().optional(), department: z.number().int().nullable().optional(), last_modified_by: z.number().int().nullable().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 }; /** * Partial Update Chart Transaction * * PATCH /coa/api/transaction/{id} */ export const patchApiCoaApiTransactionId = async (args: PatchApiCoaApiTransactionIdArgs, options?: PatchApiCoaApiTransactionIdOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/transaction/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(chartTransaction, await res.json()) };