import {z} from 'zod' export type GetApiReportsReconciliationsArgs = {'Company-Id'?: string | undefined, Mid?: string | undefined, offset?: number | undefined, limit?: number | undefined, filter?: string | undefined, start_date?: string | undefined, end_date?: string | undefined, bank?: ('trust_payments' | 'cashflows' | 'shift4' | 'acquired') | undefined, type?: ('card' | 'account_to_account') | undefined}; export type GetApiReportsReconciliationsOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const reconciliationReport = z.object({id: z.string().optional(), date: z.string().optional(), mid: z.string().optional(), total: z.number().optional(), link: z.string().optional(), type: z.enum(["card", "account_to_account"]).optional(), bank: z.string().optional()}); export const reconciliationListPaged = z.object({meta: z.object({count: z.number().int().optional(), offset: z.number().int().optional(), limit: z.number().int().optional(), total: z.number().int().optional(), links: z.array(z.object({rel: z.enum(["self", "first", "last", "prev", "next"]).optional(), href: z.string().optional(), title: z.string().optional()})).optional()}).optional(), data: z.array(reconciliationReport).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 }; /** * List all Reconciliation Reports * * GET /reports/reconciliations */ export const getApiReportsReconciliations = async (args: GetApiReportsReconciliationsArgs, options?: GetApiReportsReconciliationsOptions) => { const {baseUrl = "https://test-api.acquired.com/v1", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Company-Id'] != null) headers.set("Company-Id", String(args['Company-Id'])) if (args.Mid != null) headers.set("Mid", String(args.Mid)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.bank != null) query.append("bank", String(args.bank)) if (args.type != null) query.append("type", String(args.type)) if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/reports/reconciliations${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(reconciliationListPaged, await res.json()) };