import {z} from 'zod' export type AccountTypeEnum = 'us' | 'brazil' | 'colombia' | 'argentina' | 'mexico' | 'africa' | 'brazilGlobalNetwork' | 'nigeriaGlobalNetwork' | 'mexicoGlobalNetwork' | 'hongKongGlobalNetwork' | 'chinaGlobalNetwork' | 'singaporeGlobalNetwork'; export type GetApiV2UsersUserIdAccountsArgs = {userId: string, rail?: ('onramp' | 'offramp') | undefined, type?: AccountTypeEnum | undefined, currency?: string | undefined, limit?: string | undefined, createdBefore?: string | undefined, createdAfter?: string | undefined}; export type GetApiV2UsersUserIdAccountsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const allAccountObjects = z.object({count: z.number().int().optional(), banks: z.array(z.object({accountId: z.string().optional(), createdAt: z.string().optional(), status: z.string().optional(), accountType: z.string().optional(), businessIdentifierCode: z.string().optional(), accountNumber: z.string().optional(), routingNumber: z.string().optional(), accountHolderName: z.string().optional(), accountHolderCity: z.string().optional(), accountHolderCountry: z.string().optional(), accountHolderStreetLine1: z.string().optional(), accountHolderStateProvinceRegion: z.string().optional(), accountHolderPostalCode: z.string().optional(), bankCountry: z.string().optional(), userId: z.string().optional(), rail: z.object({currency: z.string().optional(), railType: z.string().optional(), paymentRail: z.string().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 accounts * * GET /v2/users/{userId}/accounts */ export const getApiV2UsersUserIdAccounts = async (args: GetApiV2UsersUserIdAccountsArgs, options?: GetApiV2UsersUserIdAccountsOptions) => { 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.rail != null) query.append("rail", String(args.rail)) if (args.type != null) query.append("type", String(args.type)) if (args.currency != null) query.append("currency", String(args.currency)) 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/users/${encodeURIComponent(String(args.userId))}/accounts${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(allAccountObjects, await res.json()) };