import {z} from 'zod' export type TransactionsSvcTransactionType = 'ONRAMP' | 'OFFRAMP'; export type TransactionOrderStatus = 'INITIATED' | 'DEPOSITED' | 'CONFIRMED' | 'COMPLETED' | 'PENDING' | 'CANCELLED' | 'IN_DISPUTE' | 'AWAITING_ACCEPTANCE'; export type GetApiTransactionsCustomersIdHistoryArgs = {id: string, transactionType?: TransactionsSvcTransactionType | undefined, from?: string | undefined, to?: string | undefined, size?: number | undefined, page?: number | undefined, statuses?: Array | undefined, token?: string | undefined, fiat?: string | undefined, network?: string | undefined, paymentChannel?: string | undefined, reference?: string | undefined, otherPartyId?: string | undefined, tradeRequestBroadcastId?: string | undefined, isTradeRequestBroadcast?: boolean | undefined}; export type GetApiTransactionsCustomersIdHistoryOptions = {baseUrl?: string | undefined, HMACAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionsSvcTransactionType = z.enum(["ONRAMP", "OFFRAMP"]); export const transactionsSvcTradeMode = z.enum(["P2P", "IP", "OTC"]); export const transactionsSvcOfferDTO = z.object({offerId: z.string().optional(), partnerId: z.string(), transactionType: transactionsSvcTransactionType, rate: z.number(), networkId: z.string(), fiatSymbol: z.string().optional(), fiatAmount: z.number().optional(), token: z.string(), tokenAmount: z.number(), usdAmount: z.number().optional(), partnerDisplayName: z.string().optional(), adNote: z.string().optional(), instantPayEnabled: z.boolean(), instantPayPaymentAccountId: z.string().optional(), customPayinProvider: z.string().optional(), tradeMode: transactionsSvcTradeMode.optional()}); export const transactionsSvcWalletDTO = z.object({walletAddress: z.string().optional(), networkId: z.string().optional(), walletName: z.string().optional()}); export const transactionOrderStatus = z.enum(["INITIATED", "DEPOSITED", "CONFIRMED", "COMPLETED", "PENDING", "CANCELLED", "IN_DISPUTE", "AWAITING_ACCEPTANCE"]); export const timeoutDTO = z.object({name: z.enum(["APPROVE_TRANSACTION", "MAKE_DEPOSIT", "CONFIRM_DEPOSIT", "FLAG_DISPUTE", "ACKNOWLEDGE_TRANSACTION"]).optional(), startTime: z.string().optional(), duration: z.number().optional(), timeLeft: z.number().int().optional()}); export const userType = z.enum(["CUSTOMER", "PARTNER"]); export const fee = z.object({asToken: z.string(), asFiat: z.number()}); export const instantPayProcessingStatus = z.enum(["PENDING_IP_REPORT", "IN_PROGRESS", "FAILURE", "SUCCESS"]); export const thirdpartyOrderInfoDTO = z.object({businessId: z.string(), tradeId: z.string().optional(), product: z.string().optional(), blockchainOrderId: z.number().int().optional(), externalOrderReference: z.string().optional()}); export const tradeContext = z.enum(["STANDARD_TRADE", "INTERNAL_RAIL"]); export const transactionDTO = z.object({id: z.string(), reference: z.string(), customerId: z.string(), customerName: z.string().optional(), offer: transactionsSvcOfferDTO.optional(), escrowAddress: z.string().optional(), paymentChannelId: z.string().optional(), paymentMethod: z.object({}).optional(), buyerPaymentMethod: z.object({}).optional(), customerWallet: transactionsSvcWalletDTO.optional(), tokenAddress: z.string().optional(), status: transactionOrderStatus, createdAt: z.string().optional(), initiatedAt: z.string().optional(), depositedAt: z.string().optional(), confirmedAt: z.string().optional(), completedAt: z.string().optional(), cancelledAt: z.string().optional(), cancellationReason: z.string().optional(), disputeId: z.string().optional(), timeout: timeoutDTO.optional(), lockHash: z.string().optional(), confirmationHash: z.string().optional(), cancellationHash: z.string().optional(), isPartnerAcknowledged: z.boolean().optional(), defaultingParty: userType.optional(), rating: z.number().optional(), isCexOrder: z.boolean().optional(), fee: fee, instantPayProcessingStatus: instantPayProcessingStatus.optional(), tradeValue: z.number().optional(), merchantTokenValue: z.number().optional(), customerTokenValue: z.number().optional(), payableAmount: z.number().optional(), thirdpartyOrderInfo: thirdpartyOrderInfoDTO.optional(), isNoKyc: z.boolean().optional(), paymentReceiptUploadId: z.string().optional(), suppressCustomerNotifications: z.boolean().optional(), chatUnavailable: z.boolean().optional(), tradeContext: tradeContext.optional()}); export const transactionsResponse = z.object({transactions: z.array(transactionDTO).optional(), pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), totalPages: z.number().int().optional(), totalTransactions: z.number().int().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 }; /** * Retrieve list of customer transactions * * GET /transactions/customers/{id}/history */ export const getApiTransactionsCustomersIdHistory = async (args: GetApiTransactionsCustomersIdHistoryArgs, options?: GetApiTransactionsCustomersIdHistoryOptions) => { const {baseUrl = "https://external.dev.onboardpay.co", fetch: fetchFn = fetch, HMACAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.transactionType != null) query.append("transactionType", String(args.transactionType)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.size != null) query.append("size", String(args.size)) if (args.page != null) query.append("page", String(args.page)) if (args.statuses != null) query.append("statuses", args.statuses.join(',')) if (args.token != null) query.append("token", String(args.token)) if (args.fiat != null) query.append("fiat", String(args.fiat)) if (args.network != null) query.append("network", String(args.network)) if (args.paymentChannel != null) query.append("paymentChannel", String(args.paymentChannel)) if (args.reference != null) query.append("reference", String(args.reference)) if (args.otherPartyId != null) query.append("otherPartyId", String(args.otherPartyId)) if (args.tradeRequestBroadcastId != null) query.append("tradeRequestBroadcastId", String(args.tradeRequestBroadcastId)) if (args.isTradeRequestBroadcast != null) query.append("isTradeRequestBroadcast", String(args.isTradeRequestBroadcast)) if (HMACAuth !== undefined) headers.set("x-api-key", HMACAuth) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/customers/${encodeURIComponent(String(args.id))}/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(transactionsResponse, await res.json()) };