import {z} from 'zod' export type GetApiV1ResidualTableSummariesArgs = {from_date: string, to_date: string, year_month?: boolean | undefined, classification_type?: string | undefined, audit?: boolean | undefined, w_p?: boolean | undefined, tsys_mid?: string | undefined, agent_id?: string | undefined, bank?: ('5670' | '6719' | '9267') | undefined, view_agent_id?: string | undefined, merchant_id?: string | undefined}; export type GetApiV1ResidualTableSummariesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ResidualTableSummariesResponse = z.object({header_data: z.array(z.object({column_name: z.string().optional(), sortable: z.boolean().optional(), column_id: z.string().optional(), type: z.string().optional()})).optional(), row_data: z.array(z.object({boarded_date: z.string().optional(), dba_name: z.string().optional(), agent_name: z.string().optional(), mid: z.string().optional(), s_am: z.number().int().optional(), txn: z.number().int().optional(), inc: z.number().int().optional(), exp: z.number().int().optional(), net: z.number().int().optional(), ag_net: z.number().int().optional(), bps: z.number().int().optional(), perc: z.number().int().optional(), auth: z.number().int().optional(), template_id: z.string().optional(), template_name: z.string().optional(), calculation_type: z.string().optional(), bank: z.string().optional(), residual_date: z.string().optional(), hash: z.string().optional(), reviewed: z.unknown(), note: z.unknown(), ppm_id: z.unknown(), residual_category: z.string().optional(), agent_id: z.number().int().optional(), account_id: z.number().int().optional(), hashed_agent_id: z.string().optional(), hashed_account_id: z.string().optional()})).optional(), footer_data: z.array(z.object({ag_net: z.unknown(), s_am: z.unknown(), txn: z.unknown(), inc: z.unknown(), exp: z.unknown(), net: z.unknown(), bps: z.unknown(), perc: z.unknown(), auth: z.unknown(), payarc_gr_profit: z.unknown(), agent_gr_profit: z.unknown(), profit_difference: z.unknown()})).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 }; /** * Residual Summaries * * GET /v1/residual_table_summaries */ export const getApiV1ResidualTableSummaries = async (args: GetApiV1ResidualTableSummariesArgs, options?: GetApiV1ResidualTableSummariesOptions) => { const {baseUrl = "https://testapi.payarc.net", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from_date != null) query.append("from_date", String(args.from_date)) if (args.to_date != null) query.append("to_date", String(args.to_date)) if (args.year_month != null) query.append("year_month", String(args.year_month)) if (args.classification_type != null) query.append("classification_type", String(args.classification_type)) if (args.audit != null) query.append("audit", String(args.audit)) if (args.w_p != null) query.append("w_p", String(args.w_p)) if (args.tsys_mid != null) query.append("tsys_mid", String(args.tsys_mid)) if (args.agent_id != null) query.append("agent_id", String(args.agent_id)) if (args.bank != null) query.append("bank", String(args.bank)) if (args.view_agent_id != null) query.append("view_agent_id", String(args.view_agent_id)) if (args.merchant_id != null) query.append("merchant_id", String(args.merchant_id)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/residual_table_summaries${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(getApiV1ResidualTableSummariesResponse, await res.json()) };