import {z} from 'zod' export type GetApiCoaApiV2ReconciliationIdSourceTransactionsArgs = {bank?: number | undefined, currency?: string | undefined, department?: number | undefined, end_date?: string | undefined, group?: number | undefined, id: number, limit?: number | undefined, matched?: string | undefined, offset?: number | undefined, q?: string | undefined, reconciled_only?: string | undefined, sort?: string | undefined, start_date?: string | undefined, tag?: number | undefined, unreconciled?: string | undefined, vendor?: number | undefined}; export type GetApiCoaApiV2ReconciliationIdSourceTransactionsOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const reconciliationReportV2SourceReconciliationTransactionStatusEnum = z.enum(["DRAFT", "RECONCILED"]); export const reconciliationReportV2StatementTransaction = z.object({id: z.number().int(), page_number: z.number().int(), reconciliation_transaction_id: z.string(), source_transaction_id: z.string(), is_matched: z.string(), date: z.string(), deposit: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), withdrawal: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), description: z.string().nullable().optional(), is_cleared: z.boolean().optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), reconciliation_report: z.number().int(), page: z.number().int()}); export const reconciliationReportV2SourceReconciliationTransaction = z.object({id: z.number().int(), status: reconciliationReportV2SourceReconciliationTransactionStatusEnum.optional(), suggestion_id: z.number().int().nullable(), suggestion: reconciliationReportV2StatementTransaction}); export const reconciliationReportV2SourceTransactionList = z.object({id: z.number().int(), currency: z.string(), posted_at: z.string().nullable().optional(), debit_amount_in_currency: z.string(), credit_amount_in_currency: z.string(), bank_description: z.string().nullable().optional(), reconciliation_transaction: z.array(reconciliationReportV2SourceReconciliationTransaction), is_cleared: z.string(), is_matched: z.string(), journal_id: z.number().int(), journal_order: z.string()}); export const paginatedReconciliationReportV2SourceTransactionListList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(reconciliationReportV2SourceTransactionList)}); 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 GL Transactions for Reconciliation * * GET /coa/api/v2/reconciliation/{id}/source-transactions */ export const getApiCoaApiV2ReconciliationIdSourceTransactions = async (args: GetApiCoaApiV2ReconciliationIdSourceTransactionsArgs, options?: GetApiCoaApiV2ReconciliationIdSourceTransactionsOptions) => { 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.bank != null) query.append("bank", String(args.bank)) if (args.currency != null) query.append("currency", String(args.currency)) if (args.department != null) query.append("department", String(args.department)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.group != null) query.append("group", String(args.group)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.matched != null) query.append("matched", String(args.matched)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.q != null) query.append("q", String(args.q)) if (args.reconciled_only != null) query.append("reconciled_only", String(args.reconciled_only)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.tag != null) query.append("tag", String(args.tag)) if (args.unreconciled != null) query.append("unreconciled", String(args.unreconciled)) if (args.vendor != null) query.append("vendor", String(args.vendor)) if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/v2/reconciliation/${encodeURIComponent(String(args.id))}/source-transactions${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(paginatedReconciliationReportV2SourceTransactionListList, await res.json()) };