import {z} from 'zod' export type GetApiV1StablecoinTransactionsArgs = {types?: (Array<'ISSUANCE' | 'REDEMPTION' | 'BRIDGE'>) | undefined, transactionTypes?: (Array<'ISSUANCE' | 'REDEMPTION' | 'BRIDGE'>) | undefined, statuses?: (Array<'PROCESSING' | 'PENDING' | 'COMPLETED' | 'FAILED' | 'CANCELED'>) | undefined, walletRipId?: string | undefined, address?: string | undefined, chain?: string | undefined, transactionHash?: string | undefined, counterpartyAddress?: string | undefined, memo?: string | undefined, fiatInstructionId?: string | undefined, sourceType?: ('FIAT' | 'CRYPTO') | undefined, sourceWalletRipId?: string | undefined, sourceAddress?: string | undefined, sourceChain?: string | undefined, sourceTransactionHash?: string | undefined, sourceCounterpartyAddress?: string | undefined, sourceMemo?: string | undefined, destinationType?: ('FIAT' | 'CRYPTO') | undefined, destinationWalletRipId?: string | undefined, destinationAddress?: string | undefined, destinationChain?: string | undefined, destinationTransactionHash?: string | undefined, destinationCounterpartyAddress?: string | undefined, destinationMemo?: string | undefined, page?: number | undefined, size?: number | undefined, sort?: string | undefined}; export type GetApiV1StablecoinTransactionsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionEndpoint = z.object({type: z.enum(["FIAT", "CRYPTO"]), walletRipId: z.string().nullable().optional(), address: z.string().nullable().optional(), chain: z.string().nullable().optional(), transactionHash: z.string().nullable().optional(), counterpartyAddress: z.string().nullable().optional(), fiatInstructionId: z.string().nullable().optional(), memo: z.string().nullable().optional()}); export const transaction = z.object({id: z.string(), type: z.enum(["ISSUANCE", "REDEMPTION", "BRIDGE"]).nullable().optional(), status: z.enum(["PROCESSING", "PENDING", "COMPLETED", "FAILED", "CANCELED"]), amount: z.string(), token: z.literal("RLUSD"), source: transactionEndpoint, destination: transactionEndpoint.nullable().optional(), createdAt: z.string(), updatedAt: z.string()}); export const transactionListResponse = z.object({content: z.array(transaction).optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), size: z.number().int().optional(), number: 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 }; /** * List transactions * * GET /v1/stablecoin/transactions */ export const getApiV1StablecoinTransactions = async (args: GetApiV1StablecoinTransactionsArgs, options?: GetApiV1StablecoinTransactionsOptions) => { const {baseUrl = "https://api.ripple.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.types ?? []) query.append("types", String(item)) for (const item of args.transactionTypes ?? []) query.append("transactionTypes", String(item)) for (const item of args.statuses ?? []) query.append("statuses", String(item)) if (args.walletRipId != null) query.append("walletRipId", String(args.walletRipId)) if (args.address != null) query.append("address", String(args.address)) if (args.chain != null) query.append("chain", String(args.chain)) if (args.transactionHash != null) query.append("transactionHash", String(args.transactionHash)) if (args.counterpartyAddress != null) query.append("counterpartyAddress", String(args.counterpartyAddress)) if (args.memo != null) query.append("memo", String(args.memo)) if (args.fiatInstructionId != null) query.append("fiatInstructionId", String(args.fiatInstructionId)) if (args.sourceType != null) query.append("sourceType", String(args.sourceType)) if (args.sourceWalletRipId != null) query.append("sourceWalletRipId", String(args.sourceWalletRipId)) if (args.sourceAddress != null) query.append("sourceAddress", String(args.sourceAddress)) if (args.sourceChain != null) query.append("sourceChain", String(args.sourceChain)) if (args.sourceTransactionHash != null) query.append("sourceTransactionHash", String(args.sourceTransactionHash)) if (args.sourceCounterpartyAddress != null) query.append("sourceCounterpartyAddress", String(args.sourceCounterpartyAddress)) if (args.sourceMemo != null) query.append("sourceMemo", String(args.sourceMemo)) if (args.destinationType != null) query.append("destinationType", String(args.destinationType)) if (args.destinationWalletRipId != null) query.append("destinationWalletRipId", String(args.destinationWalletRipId)) if (args.destinationAddress != null) query.append("destinationAddress", String(args.destinationAddress)) if (args.destinationChain != null) query.append("destinationChain", String(args.destinationChain)) if (args.destinationTransactionHash != null) query.append("destinationTransactionHash", String(args.destinationTransactionHash)) if (args.destinationCounterpartyAddress != null) query.append("destinationCounterpartyAddress", String(args.destinationCounterpartyAddress)) if (args.destinationMemo != null) query.append("destinationMemo", String(args.destinationMemo)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.sort != null) query.append("sort", String(args.sort)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stablecoin/transactions${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(transactionListResponse, await res.json()) };