import {z} from 'zod' export type AsyncTaskStatusEnum = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | 'CANCELLED'; export type AsyncTask = {id: number, created_by_name: string, name: string, created_at: string, status?: AsyncTaskStatusEnum | undefined, error_message?: (string | null) | undefined, error_type?: (string | null) | undefined, retries?: number | undefined, completed_at?: (string | null) | undefined, started_at?: (string | null) | undefined, celery_task_id?: (string | null) | undefined, root_task_id?: (string | null) | undefined, parent_task_id?: (string | null) | undefined, trace_id?: (string | null) | undefined, span_id?: (string | null) | undefined, task_args: unknown, task_kwargs: unknown, result: unknown, content: unknown, customer: number | null, created_by: number | null}; 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 Status8ecEnum = 'DRAFT' | 'PENDING_APPROVAL' | 'APPROVED' | 'DELETED'; export type PatchedReconciliationReportV2 = {id?: number | undefined, entity_name?: string | undefined, account_name?: string | undefined, account_number?: string | undefined, account_type?: string | undefined, account_subtype?: string | undefined, reconciled_by_name?: string | undefined, reconciled_by_email?: string | undefined, approved_by_name?: string | undefined, approved_by_email?: string | undefined, async_task?: AsyncTask | undefined, attachments?: Array | undefined, csv_statements?: string | undefined, cleared_total_debits?: string | undefined, cleared_total_credits?: string | undefined, cleared_activity?: string | undefined, cleared_item_count?: string | undefined, matched_total_debits?: string | undefined, matched_total_credits?: string | undefined, matched_activity?: string | undefined, matched_item_count?: string | undefined, unreconciled_total_debits?: string | undefined, unreconciled_total_credits?: string | undefined, unreconciled_activity?: string | undefined, unreconciled_gl_item_count?: string | undefined, unreconciled_statement_line_count?: string | undefined, unreconciled_statement_activity?: string | undefined, reconciliation_difference?: string | undefined, open_total_debits?: string | undefined, open_total_credits?: string | undefined, open_activity?: string | undefined, open_gl_item_count?: string | undefined, open_statement_line_count?: string | undefined, open_statement_activity?: string | undefined, statement_activity?: string | undefined, open_difference?: string | undefined, currency?: string | undefined, statement_starting_date?: (string | null) | undefined, statement_ending_date?: (string | null) | undefined, starting_balance?: number | undefined, ending_balance?: number | undefined, total_credit_amount?: (number | null) | undefined, total_debit_amount?: (number | null) | undefined, adjustments?: (number | null) | undefined, created_at?: string | undefined, last_modified_at?: string | undefined, reconciled_on?: (string | null) | undefined, approved_on?: (string | null) | undefined, status?: Status8ecEnum | undefined, unmatched_statement_transactions: unknown, statement_recognition_cost_usd?: (number | null) | undefined, statement_recognition_input_tokens?: (number | null) | undefined, statement_recognition_output_tokens?: (number | null) | undefined, statement_recognition_token_total?: (number | null) | undefined, statement_recognition_model_name?: (string | null) | undefined, customer?: number | undefined, entity?: (number | null) | undefined, account?: number | undefined, matching_task?: (number | null) | undefined, reconciled_by?: (number | null) | undefined, approved_by?: (number | null) | undefined}; export type PatchApiCoaApiV2ReconciliationIdArgs = {id: number, body: PatchedReconciliationReportV2}; export type PatchApiCoaApiV2ReconciliationIdOptions = {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 }; /** * Partial Update Bank Reconciliation Report * * PATCH /coa/api/v2/reconciliation/{id} */ export const patchApiCoaApiV2ReconciliationId = async (args: PatchApiCoaApiV2ReconciliationIdArgs, options?: PatchApiCoaApiV2ReconciliationIdOptions) => { 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/v2/reconciliation/${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(reconciliationReportV2, await res.json()) };