import {z} from 'zod' export type GetApiCoaApiV2ReconciliationIdArgs = {id: number}; export type GetApiCoaApiV2ReconciliationIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const asyncTaskStatusEnum = z.enum(["PENDING", "PROCESSING", "COMPLETED", "FAILED", "CANCELLED"]); export const asyncTask = z.object({id: z.number().int(), created_by_name: z.string(), name: z.string().max(250), created_at: z.string(), status: asyncTaskStatusEnum.optional(), error_message: z.string().nullable().optional(), error_type: z.string().max(255).nullable().optional(), retries: z.number().int().gte(-2147483648).lte(2147483647).optional(), completed_at: z.string().nullable().optional(), started_at: z.string().nullable().optional(), celery_task_id: z.string().max(255).nullable().optional(), root_task_id: z.string().max(255).nullable().optional(), parent_task_id: z.string().max(255).nullable().optional(), trace_id: z.string().max(255).nullable().optional(), span_id: z.string().max(255).nullable().optional(), task_args: z.unknown(), task_kwargs: z.unknown(), result: z.unknown(), content: z.unknown(), customer: z.number().int().nullable(), created_by: z.number().int().nullable()}); 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 status8ecEnum = z.enum(["DRAFT", "PENDING_APPROVAL", "APPROVED", "DELETED"]); export const reconciliationReportV2 = z.object({id: z.number().int(), entity_name: z.string(), account_name: z.string(), account_number: z.string(), account_type: z.string(), account_subtype: z.string(), reconciled_by_name: z.string(), reconciled_by_email: z.string(), approved_by_name: z.string(), approved_by_email: z.string(), async_task: asyncTask, attachments: z.array(file), csv_statements: z.string(), cleared_total_debits: z.string(), cleared_total_credits: z.string(), cleared_activity: z.string(), cleared_item_count: z.string(), matched_total_debits: z.string(), matched_total_credits: z.string(), matched_activity: z.string(), matched_item_count: z.string(), unreconciled_total_debits: z.string(), unreconciled_total_credits: z.string(), unreconciled_activity: z.string(), unreconciled_gl_item_count: z.string(), unreconciled_statement_line_count: z.string(), unreconciled_statement_activity: z.string(), reconciliation_difference: z.string(), open_total_debits: z.string(), open_total_credits: z.string(), open_activity: z.string(), open_gl_item_count: z.string(), open_statement_line_count: z.string(), open_statement_activity: z.string(), statement_activity: z.string(), open_difference: z.string(), currency: z.string().max(3).optional(), statement_starting_date: z.string().nullable().optional(), statement_ending_date: z.string().nullable().optional(), starting_balance: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), ending_balance: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), total_credit_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), total_debit_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), adjustments: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), created_at: z.string(), last_modified_at: z.string(), reconciled_on: z.string().nullable().optional(), approved_on: z.string().nullable(), status: status8ecEnum.optional(), unmatched_statement_transactions: z.unknown(), statement_recognition_cost_usd: z.number().gt(-100000000).lt(100000000).nullable().optional(), statement_recognition_input_tokens: z.number().int().gte(0).lte(2147483647).nullable().optional(), statement_recognition_output_tokens: z.number().int().gte(0).lte(2147483647).nullable().optional(), statement_recognition_token_total: z.number().int().gte(0).lte(9223372036854776000).nullable().optional(), statement_recognition_model_name: z.string().max(128).nullable().optional(), customer: z.number().int(), entity: z.number().int().nullable().optional(), account: z.number().int(), matching_task: z.number().int().nullable().optional(), reconciled_by: z.number().int().nullable().optional(), approved_by: z.number().int().nullable()}); 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 }; /** * Get Bank Reconciliation Report * * GET /coa/api/v2/reconciliation/{id} */ export const getApiCoaApiV2ReconciliationId = async (args: GetApiCoaApiV2ReconciliationIdArgs, options?: GetApiCoaApiV2ReconciliationIdOptions) => { 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 (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/v2/reconciliation/${encodeURIComponent(String(args.id))}${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(reconciliationReportV2, await res.json()) };