import {z} from 'zod' export type GetApiCoaApiJournalEntryArgs = {account?: string | undefined, all_time?: boolean | undefined, end_date?: string | undefined, limit?: number | undefined, offset?: number | undefined, source?: string | undefined, start_date?: string | undefined}; export type GetApiCoaApiJournalEntryOptions = {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 journalEntry = z.object({id: z.number().int(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), transactions: z.array(chartTransaction), attachments: z.array(file), invoice: z.number().int().nullable(), reversal_of_order: z.string(), reversals: z.array(z.record(z.string(), z.unknown())), reversal_date: z.string().nullable().optional(), entity_name: z.string(), entity_currency: z.string(), created_by: z.number().int().nullable(), created_by_name: z.string().nullable(), created_by_source: z.string().nullable(), order: z.string().optional(), revenue_transactions: z.array(z.number().int()).optional(), bulk_upload: z.boolean().optional(), chat_uuid: z.string().nullable().optional(), close_task_id: z.string().optional(), update_reversal: z.boolean().optional(), credit_memos: z.array(z.record(z.string(), z.unknown())), debit_memos: z.array(z.record(z.string(), z.unknown())), journals_to_delete: z.array(z.number().int()).optional(), ramp_use_sandbox: z.string(), navan_region: z.string().nullable(), float_bill_id: z.string().nullable(), search_vector: z.string().nullable(), search_text: z.string().nullable(), type: typeF19Enum.optional(), journal_id: z.string().optional(), memo: z.string().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(), use_average_rate: z.boolean().nullable().optional(), created_automatically: z.boolean().optional(), date: z.string().optional(), ref_number: z.string().max(100).nullable().optional(), created_at: z.string(), source: z.string().max(250).nullable().optional(), source_id: z.string().nullable().optional(), last_modified_at: z.string(), customer: z.number().int(), recurrent_journal_entry: z.number().int().nullable().optional(), entity: z.number().int().nullable().optional(), reversal_of: z.number().int().nullable().optional(), intercompany_journal: z.number().int().nullable().optional(), source_file: z.number().int().nullable().optional(), chat: z.number().int().nullable().optional(), last_draft: z.number().int().nullable()}); export const paginatedJournalEntryList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(journalEntry)}); 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 }; /** * List Journal Entries * * GET /coa/api/journal_entry */ export const getApiCoaApiJournalEntry = async (args: GetApiCoaApiJournalEntryArgs, options?: GetApiCoaApiJournalEntryOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.account != null) query.append("account", String(args.account)) if (args.all_time != null) query.append("all_time", String(args.all_time)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.source != null) query.append("source", String(args.source)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/journal_entry${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedJournalEntryList, await res.json()) };