import {z} from 'zod' export type GetApiV2WalletsTransfersArgs = {userId?: string | undefined, limit?: string | undefined, createdBefore?: string | undefined, createdAfter?: string | undefined}; export type GetApiV2WalletsTransfersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const cryptoToCryptoAllRecordsObject = z.object({count: z.number().int().optional(), records: z.array(z.object({transferType: z.string().optional(), transferDetails: z.object({id: z.string().optional(), requestId: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), chain: z.string().optional(), currency: z.string().optional(), contractAddress: z.string().optional(), status: z.string().optional(), failedReason: z.string().optional(), approval: z.object({id: z.string().optional(), status: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), transferId: z.string().optional(), transferType: z.string().optional(), fromDashboard: z.boolean().optional(), initiatorProfileId: z.string().optional(), votes: z.array(z.object({approverId: z.string().optional(), vote: z.enum(["APPROVE", "REJECT"]).optional(), comment: z.string().optional(), createdAt: z.string().optional()})).optional()}).optional(), source: z.object({userId: z.string().optional(), walletAddress: z.string().optional(), walletType: z.string().optional(), user: z.object({email: z.string().optional(), lastName: z.string().optional(), firstName: z.string().optional(), businessName: z.string().optional()}).optional()}).optional(), destination: z.object({userId: z.string().optional(), walletType: z.string().optional(), walletAddress: z.string().optional(), user: z.object({email: z.string().optional(), lastName: z.string().optional(), firstName: z.string().optional(), businessName: z.string().optional()}).optional()}).optional(), amount: z.number().optional(), amountIncludeDeveloperFee: z.number().optional(), receipt: z.object({transactionHash: z.string().optional(), userOpHash: z.string().optional()}).optional(), developerFee: z.object({feeId: z.string().optional(), feeType: z.string().optional(), feeAmount: z.number().optional(), feePercent: z.number().optional(), status: z.string().optional(), transactionHash: z.string().optional(), failedReason: z.string().optional()}).optional()}).optional()})).optional(), nextCursor: z.string().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 all crypto transfers * * GET /v2/wallets/transfers */ export const getApiV2WalletsTransfers = async (args: GetApiV2WalletsTransfersArgs, options?: GetApiV2WalletsTransfersOptions) => { const {baseUrl = "https://production.hifibridge.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.userId != null) query.append("userId", String(args.userId)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/wallets/transfers${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(cryptoToCryptoAllRecordsObject, await res.json()) };