import {z} from 'zod' export type GetApiApiV1AdminPostProcessorLogsArgs = {page?: number | undefined, limit?: number | undefined, sort?: string | undefined, merchant_id?: string | undefined, action?: ('FEE_TRANSFER' | 'CURRENCY_CONVERSION' | 'PAYOUT' | 'REFUND_RETENTION' | 'MANUAL') | undefined, status?: ('INITIATED' | 'COMPLETED' | 'FAILED') | undefined, from_date?: string | undefined, to_date?: string | undefined}; export type GetApiApiV1AdminPostProcessorLogsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const adminPostProcessorLogListResponse = z.object({success: z.boolean(), data: z.array(z.object({id: z.string(), transaction_id: z.string().nullable(), merchant_id: z.string(), action: z.union([z.literal("FEE_TRANSFER"), z.literal("CURRENCY_CONVERSION"), z.literal("PAYOUT"), z.literal("REFUND_RETENTION"), z.literal("MANUAL")]), status: z.union([z.literal("INITIATED"), z.literal("COMPLETED"), z.literal("FAILED")]), from_currency: z.string(), to_currency: z.string().nullable(), amount: z.string(), converted_amount: z.string().nullable(), exchange_rate: z.string().nullable(), tm_transaction_id: z.string().nullable(), reference: z.string().nullable(), error_message: z.string().nullable(), source_account_id: z.string().nullable(), source_account_type: z.union([z.literal("MERCHANT_BANK_ACCOUNT"), z.literal("FEE_ACCOUNT")]).nullable(), destination_account_id: z.string().nullable(), destination_account_type: z.union([z.literal("MERCHANT_BANK_ACCOUNT"), z.literal("FEE_ACCOUNT"), z.literal("CUSTOMER_BANK_ACCOUNT")]).nullable(), reason: z.string().nullable(), performed_by_user_id: z.string().nullable(), created_at: z.string()})), pagination: z.object({total: z.number().int(), page: z.number().int(), limit: z.number().int(), totalPages: z.number().int(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean()})}); 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 post-processor log entries with optional filters (admin only) * * GET /api/v1/admin/post-processor-logs */ export const getApiApiV1AdminPostProcessorLogs = async (args: GetApiApiV1AdminPostProcessorLogsArgs, options?: GetApiApiV1AdminPostProcessorLogsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.merchant_id != null) query.append("merchant_id", String(args.merchant_id)) if (args.action != null) query.append("action", String(args.action)) if (args.status != null) query.append("status", String(args.status)) 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/post-processor-logs${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(adminPostProcessorLogListResponse, await res.json()) };