import {z} from 'zod' export type GetApiPayoutUserHistoryArgs = {'Idempotency-Key'?: string | undefined, number_of_records?: number | undefined, start_date?: string | undefined, end_date?: string | undefined, page?: number | undefined, type?: ('payout' | 'load' | 'spendback' | 'payin') | undefined, wallet_token?: string | undefined, show_all_clients?: boolean | undefined}; export type GetApiPayoutUserHistoryOptions = {baseUrl?: string | undefined, AUTHORIZERNAME?: string | undefined, fetch?: typeof fetch | undefined}; export const txnHistoryRecordResp = z.object({token: z.string(), type: z.enum(["load", "payout", "spend back", "info", "payin"]), time_of_txn: z.string(), source_amount: z.number(), source_currency_code: z.string().min(3).max(3), destination_amount: z.number(), destination_currency_code: z.string().min(3).max(3), fee: z.number(), status: z.enum(["PENDING", "EXPIRED", "PROCESSING", "COMPLETED", "CANCELLED", "SCHEDULED", "READY_FOR_PICKUP", "HOLD", "ERROR", "CANCELLED_AT_LATER_TIME", "RETURNED"]), notes: z.string().optional(), payer_name: z.string().optional(), pickup_code: z.string().optional(), source_token: z.string().optional(), destination_token: z.string(), delivery_type: z.enum(["CASH_PICKUP", "BANK_DEPOSIT", "HOME_DELIVERY", "MOBILE_WALLET", "MASSPAY_CARD", "PAPER_CHECK", "BILL", "CRYPTOCURRENCY"]).optional(), client_transfer_id: z.string().max(50).optional(), status_reason: z.string().optional(), client_id: z.number().int().optional(), user_token: z.string().optional(), destination_country: z.string().optional(), sender_user_token: z.string().min(40).max(40).optional(), sender_first_name: z.string().optional(), sender_last_name: z.string().optional(), sender_business_name: z.string().optional()}); export const getApiPayoutUserHistoryResponse = z.array(txnHistoryRecordResp); 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 }; /** * All Users' Transactions history * * GET /payout/user/history * * Also accepts auth: api_key */ export const getApiPayoutUserHistory = async (args: GetApiPayoutUserHistoryArgs, options?: GetApiPayoutUserHistoryOptions) => { const {baseUrl = "https://api.masspay.io/v1.0.0", fetch: fetchFn = fetch, AUTHORIZERNAME} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args.number_of_records != null) query.append("number_of_records", String(args.number_of_records)) 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.page != null) query.append("page", String(args.page)) if (args.type != null) query.append("type", String(args.type)) if (args.wallet_token != null) query.append("wallet_token", String(args.wallet_token)) if (args.show_all_clients != null) query.append("show_all_clients", String(args.show_all_clients)) if (AUTHORIZERNAME !== undefined) headers.set("Authorization", AUTHORIZERNAME) const url = `${baseUrl.replace(/\/+$/, '')}/payout/user/history${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(getApiPayoutUserHistoryResponse, await res.json()) };