import {z} from 'zod' export type Object = Record; export type GetApiV1TransferArgs = {page?: number | undefined, limit?: number | undefined, order?: ('ASC' | 'DESC') | undefined, sort?: string | undefined, query?: string | undefined, currency?: Object | undefined, beneficiaryId?: string | undefined, status?: string | undefined}; export type GetApiV1TransferOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const publicTransferBeneficiaryDto = z.object({id: z.string(), accountName: z.string(), accountNumber: z.string(), bankCode: z.string(), bankName: z.string(), providerId: z.string().optional(), description: z.string().optional(), isActive: z.boolean(), mode: z.enum(["test", "live"]), createdAt: z.string(), updatedAt: z.string()}); export const publicTransferTransactionMetaDto = z.object({amount: z.number(), symbol: z.string(), currency: z.string(), fxRate: z.number().nullable().optional(), settlementAmount: z.number().nullable().optional(), settlementCurrency: z.string().nullable().optional(), settlementSymbol: z.string().nullable().optional()}); export const publicTransferFeeBreakdownDto = z.object({fee: z.number(), vat: z.number(), processorFee: z.number(), allInclusiveKyshiFee: z.number(), totalFees: z.number(), others: z.record(z.string(), z.number())}); export const publicTransferTransactionDto = z.object({id: z.string(), amount: z.number(), type: z.enum(["DR", "CR"]), channel: z.string().optional(), processor: z.enum(["PROVIDUS_BANK", "STERLING", "VFD", "PAYSTACK", "FLUTTERWAVE", "CHOICE", "STITCH", "PAGA", "STRIPE", "ASSET_MFB", "MOMENTPAY", "PAWAPAY"]), feeBearer: z.enum(["MERCHANT", "CUSTOMER"]), balanceBefore: z.number(), balanceAfter: z.number(), netAmount: z.number(), meta: publicTransferTransactionMetaDto, feeBreakdown: publicTransferFeeBreakdownDto, status: z.enum(["PENDING", "SUCCESS", "IN_REVIEW", "FAILED", "REVERSAL", "COLLECTED"]), currency: z.string(), reference: z.string(), paymentType: z.string(), createdAt: z.string(), updatedAt: z.string()}); export const publicTransferDto = z.object({id: z.string(), code: z.string(), status: z.enum(["PENDING_APPROVAL", "APPROVED"]), mode: z.enum(["test", "live"]), beneficiary: publicTransferBeneficiaryDto, transaction: publicTransferTransactionDto, createdAt: z.string(), updatedAt: z.string(), approvedAt: z.string().optional()}); export const getApiV1TransferResponse = z.object({status: z.boolean(), message: z.string(), code: z.number(), data: z.object({page: z.number(), limit: z.number(), total: z.number(), pageCount: z.number(), hasPreviousPage: z.boolean(), hasNextPage: z.boolean(), data: z.array(publicTransferDto)})}); 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 transfers * * GET /v1/transfer */ export const getApiV1Transfer = async (args: GetApiV1TransferArgs, options?: GetApiV1TransferOptions) => { const {baseUrl = "https://api.kyshi.co", fetch: fetchFn = fetch, ApiKeyAuth} = 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.order != null) query.append("order", String(args.order)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.query != null) query.append("query", String(args.query)) if (args.currency != null) query.append("currency", JSON.stringify(args.currency)) if (args.beneficiaryId != null) query.append("beneficiaryId", String(args.beneficiaryId)) if (args.status != null) query.append("status", String(args.status)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/transfer${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(getApiV1TransferResponse, await res.json()) };