import {z} from 'zod' export type GetApiV1ResidualAdditionalLineItemsArgs = {from_date?: string | undefined, to_date?: string | undefined, tsys_mid?: string | undefined, bank_id?: string | undefined, agent_id?: string | undefined, merchant_id?: string | undefined, view_agent_id?: string | undefined}; export type GetApiV1ResidualAdditionalLineItemsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ResidualAdditionalLineItemsResponse = 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.unknown()).optional(), footer_data: z.array(z.object({payarc_calculated_profit: z.number().int().optional(), payarc_final_adjustment: z.number().int().optional()})).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 }; /** * Additional Line Items * * GET /v1/residual-additional-line-items */ export const getApiV1ResidualAdditionalLineItems = async (args: GetApiV1ResidualAdditionalLineItemsArgs, options?: GetApiV1ResidualAdditionalLineItemsOptions) => { 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.tsys_mid != null) query.append("tsys_mid", String(args.tsys_mid)) if (args.bank_id != null) query.append("bank_id", String(args.bank_id)) if (args.agent_id != null) query.append("agent_id", String(args.agent_id)) if (args.merchant_id != null) query.append("merchant_id", String(args.merchant_id)) if (args.view_agent_id != null) query.append("view_agent_id", String(args.view_agent_id)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/residual-additional-line-items${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(getApiV1ResidualAdditionalLineItemsResponse, await res.json()) };