import {z} from 'zod' export type GetApiV2WalletsTransfersBatchesArgs = {userId?: string | undefined, limit?: string | undefined, createdBefore?: string | undefined, createdAfter?: string | undefined}; export type GetApiV2WalletsTransfersBatchesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const batchCryptoTransferListObject = z.object({count: z.number().int(), records: z.array(z.object({transferType: z.string(), transferDetails: z.object({id: z.string(), requestId: z.string(), createdAt: z.string(), updatedAt: z.string(), chain: z.literal("POLYGON"), currency: z.literal("usdc"), contractAddress: z.string(), status: z.enum(["NOT_INITIATED", "CREATED", "INITIATED", "PENDING", "COMPLETED", "FAILED", "UNKNOWN"]), failedReason: z.string().nullable().optional(), source: z.object({userId: z.string(), walletAddress: z.string(), walletType: z.enum(["INDIVIDUAL", "BUSINESS"])}), destination: z.object({batch: z.array(z.object({amount: z.string(), userId: z.string().optional(), walletAddress: z.string().optional()}))}), receipt: z.object({transactionHash: z.string(), userOpHash: 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()})})})), nextCursor: z.string()}); 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 batch crypto transfers * * GET /v2/wallets/transfers/batches */ export const getApiV2WalletsTransfersBatches = async (args: GetApiV2WalletsTransfersBatchesArgs, options?: GetApiV2WalletsTransfersBatchesOptions) => { 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/batches${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(batchCryptoTransferListObject, await res.json()) };