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 ChartTransaction = {id: number, is_deleted: boolean, deleted_at: string | null, entity_name: string, entity_currency: string, account_name: string | null, account_number: string, vendor_name: string, vendor_id: string, department_name: string, department_code: string, parent_department_name: string, parent_department: number, tags: Array<{[key: string]: unknown}>, journal: number, journal_order: string, journal_memo: string, journal_type: string, intercompany_journal: number, created_automatically: boolean, journal_attachments: Array, journal_type_name: string | null, invoice: string | null, bill: string | null, date_month: string | null, date_year: string | null, balance_after_transaction: number, bank_account: string, bank_account_name: string, account?: (number | null) | undefined, last_modified_by_name: string, account_type: string, account_subtype: string, parent_account_name: string, files: string, invoice_id: number | null, invoice_number: string | null, bill_id: number | null, bill_number: string | null, file_names: string, has_matches: boolean, has_ai: boolean, has_rules: boolean, has_merges: boolean, has_fixed_asset_rule_matches: boolean, primary_action_type: string, suggested_account: number | null, suggested_account_name: string | null, suggested_account_number: string | null, amount: number, amount_native: number, amount_book: number, amortization_schedule: Array, linked_amortizations: Array<{[key: string]: unknown}>, created_fixed_assets: Array<{[key: string]: string}>, reconciliation_report: string, opposing_account_name: string, opposing_account_number: string, tax_rate?: (number | null) | undefined, apply_both_sides?: boolean | undefined, transaction_match_id?: (number | null) | undefined, transaction_id: string, 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, created_at: string, external_id?: (string | null) | undefined, needs_review?: boolean | undefined, last_modified_at: string, draft_matches: unknown, last_lam_prediction_attempt?: (string | null) | undefined, customer: number, entity: number, 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 TypeF19Enum = 'bill' | 'bill_payment' | 'bill_prepayment' | 'check' | 'credit_card' | 'credit_memo' | 'credit_memo_payment' | 'debit_memo' | 'debit_memo_payment' | 'deposit' | 'expense' | 'invoice' | 'intercompany_journal' | 'invoice_payment' | 'journal_entry' | 'lease' | 'payment' | 'receive_payment' | 'refund' | 'revenue_recognition' | 'sales_receipt' | 'transfer' | 'vendor_credit' | 'void_bill' | 'void_bill_payment' | 'void_invoice_payment' | 'void_credit_memo' | 'void_credit_memo_payment' | 'void_debit_memo_payment' | 'void_invoice' | 'elimination' | 'revaluation' | 'asset_reclassification'; export type IntercompanyJournalEntry = {id: number, transactions: Array, attachments: Array, reversal_of_order: string, reversals: Array<{[key: string]: unknown}>, reversal_date?: (string | null) | undefined, order?: string | undefined, journals_to_delete?: Array | undefined, exchange_rates: unknown, source?: (string | null) | undefined, source_file?: (number | null) | undefined, close_task_id?: string | undefined, chat_uuid?: string | undefined, is_deleted: boolean, deleted_at: string | null, type?: TypeF19Enum | undefined, journal_id?: string | undefined, memo?: (string | null) | undefined, currency?: string | undefined, created_automatically?: boolean | undefined, date?: string | undefined, ref_number?: (string | null) | undefined, created_at: string, last_modified_at: string, customer: number, reversal_of?: (number | null) | undefined, entities?: Array | undefined}; export type CreateApiCoaApiIntercompanyJournalEntryArgs = {body: IntercompanyJournalEntry}; export type CreateApiCoaApiIntercompanyJournalEntryOptions = {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 typeF19Enum = z.enum(["bill", "bill_payment", "bill_prepayment", "check", "credit_card", "credit_memo", "credit_memo_payment", "debit_memo", "debit_memo_payment", "deposit", "expense", "invoice", "intercompany_journal", "invoice_payment", "journal_entry", "lease", "payment", "receive_payment", "refund", "revenue_recognition", "sales_receipt", "transfer", "vendor_credit", "void_bill", "void_bill_payment", "void_invoice_payment", "void_credit_memo", "void_credit_memo_payment", "void_debit_memo_payment", "void_invoice", "elimination", "revaluation", "asset_reclassification"]); export const intercompanyJournalEntry = z.object({id: z.number().int(), transactions: z.array(chartTransaction), attachments: z.array(file), reversal_of_order: z.string(), reversals: z.array(z.record(z.string(), z.unknown())), reversal_date: z.string().nullable().optional(), order: z.string().optional(), journals_to_delete: z.array(z.number().int()).optional(), exchange_rates: z.unknown(), source: z.string().nullable().optional(), source_file: z.number().int().nullable().optional(), close_task_id: z.string().optional(), chat_uuid: z.string().optional(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), type: typeF19Enum.optional(), journal_id: z.string().optional(), memo: z.string().max(1024).nullable().optional(), currency: z.string().max(3).optional(), created_automatically: z.boolean().optional(), date: z.string().optional(), ref_number: z.string().max(100).nullable().optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), reversal_of: z.number().int().nullable().optional(), entities: z.array(z.number().int()).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 }; /** * Create Intercompany Journal Entry * * POST /coa/api/intercompany-journal-entry */ export const createApiCoaApiIntercompanyJournalEntry = async (args: CreateApiCoaApiIntercompanyJournalEntryArgs, options?: CreateApiCoaApiIntercompanyJournalEntryOptions) => { 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/intercompany-journal-entry${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(intercompanyJournalEntry, await res.json()) };