import {z} from 'zod' export type AccountTypeEnum = 'us' | 'brazil' | 'colombia' | 'argentina' | 'mexico' | 'africa' | 'brazilGlobalNetwork' | 'nigeriaGlobalNetwork' | 'mexicoGlobalNetwork' | 'hongKongGlobalNetwork' | 'chinaGlobalNetwork' | 'singaporeGlobalNetwork'; export type Address = {addressLine1: string, addressLine2?: string | undefined, city: string, stateProvinceRegion: string, postalCode: string, country: string}; export type AccountHolder = {type: 'individual' | 'business', name: string, email?: string | undefined, phone?: string | undefined, address?: Address | undefined, idType?: ('CC' | 'CE' | 'NIT' | 'PASS' | 'PEP') | undefined, idNumber?: string | undefined}; export type UsAccount = {transferType: 'ach' | 'wire' | 'swift', accountType: 'Checking' | 'Savings', accountNumber?: string | undefined, routingNumber?: string | undefined, iban?: string | undefined, swiftCode?: string | undefined, bankName: string, bankAddress?: Address | undefined, currency: 'usd'}; export type BrazilAccount = {pixKey: string, currency: 'brl'}; export type ColombiaAccount = {bankName?: ('MOVII' | 'Banco de Bogotá' | 'Banco Popular' | 'Banco Corpbanca ITAU' | 'Bancolombia' | 'Citibank' | 'Banco GNB Sudameris' | 'BBVA' | 'ITAU' | 'Scotiabank Colpatria' | 'Banco de Occidente' | 'Bancoldex' | 'Banco Caja Social' | 'Banco Agrario' | 'Jpmorgan Corporacion Financier' | 'BNP PARIBAS' | 'Davivienda' | 'Banco AVVillas' | 'Banco W' | 'Banco Procredit Colombia' | 'Bancamia' | 'Inversora Pichincha S.A.' | 'Bancoomeva' | 'Banco Falabella S.A.' | 'Banco Finandina S.A.' | 'Banco Santander Negocios' | 'Banco Cooperativo Coopcentral' | 'Serfinanza S.A' | 'LULO BANK SA' | 'Banco JP Morgan' | 'Compensar' | 'Gestion y Contacto S.A.' | 'Fedecajas' | 'Simple S.A.' | 'Enlace Operativo' | 'Corp. Financiera Colombiana' | 'Financiera Juriscoop' | 'Rappi' | 'Coop. Financiera de Antioquia' | 'Cotrafa Cooperativa Financiera' | 'Confiar Cooperativa Financiera' | 'Giros y Finanzas' | 'COLTEFINANCIERA' | 'Banco OLD Mutual' | 'NEQUI' | 'DECEVAL' | 'Daviplata' | 'Banco Credifinanciera' | 'Financiera Dann (IRIS)' | 'DGCPTN') | undefined, bankCode?: string | undefined, accountNumber: string, accountType: 'checking' | 'savings', currency: 'cop'}; export type ArgentinaAccount = {accountType: 'CVU' | 'CBU' | 'ALIAS', accountNumber: string, currency: 'ars'}; export type MexicoAccount = {speiProtocol: 'clabe' | 'debitcard' | 'phonenum', speiInstitutionCode?: string | undefined, speiClabe: string, currency: 'mxn'}; export type AfricaAccount = {financialInstitute: string, accountType: 'momo' | 'bank', accountNumber?: string | undefined, currency: string, country: string}; export type BrazilGlobalNetworkAccount = {email?: string | undefined, phone?: string | undefined, pix?: string | undefined, currency: 'brl'}; export type NigeriaGlobalNetworkAccount = {bankName?: string | undefined, accountNumber?: string | undefined, currency: 'ngn'}; export type MexicoGlobalNetworkAccount = {speiClabe?: string | undefined, currency: 'mxn'}; export type HongKongGlobalNetworkAccount = {bankName: string, accountNumber: string, swiftCode: string, currency: 'hkd' | 'usd', bankCode?: string | undefined, transferType?: ('chats' | 'fps' | 'swift') | undefined}; export type SingaporeGlobalNetworkAccount = {bankName?: string | undefined, accountNumber?: string | undefined, swiftCode?: string | undefined, currency: 'usd' | 'sgd'}; export type CreateAccount = {rail: 'onramp' | 'offramp', type: AccountTypeEnum, accountHolder?: AccountHolder | undefined, us?: UsAccount | undefined, brazil?: BrazilAccount | undefined, colombia?: ColombiaAccount | undefined, argentina?: ArgentinaAccount | undefined, mexico?: MexicoAccount | undefined, africa?: AfricaAccount | undefined, brazilGlobalNetwork?: BrazilGlobalNetworkAccount | undefined, nigeriaGlobalNetwork?: NigeriaGlobalNetworkAccount | undefined, mexicoGlobalNetwork?: MexicoGlobalNetworkAccount | undefined, hongKongGlobalNetwork?: HongKongGlobalNetworkAccount | undefined, singaporeGlobalNetwork?: SingaporeGlobalNetworkAccount | undefined}; export type UsAccountHolder = {type: 'individual' | 'business', name: string, address: Address}; export type CreateUsAccount = {rail: 'offramp', type: 'us', accountHolder: UsAccountHolder, us: UsAccount}; export type CreateBrazilAccount = {rail: 'offramp', type: 'brazil', brazil: BrazilAccount}; export type GlobalNetworkIndividualAccountHolder = {name: string, type: 'individual', address: {city: string, country: string, postalCode: string, addressLine1: string, addressLine2?: string | undefined, stateProvinceRegion: string}, dateOfBirth: string, idNumber: string, nationality: string}; export type CreateBrazilGlobalNetworkAccountIndividual = {rail: 'offramp', type: 'brazilGlobalNetwork', accountHolder: GlobalNetworkIndividualAccountHolder, brazilGlobalNetwork: BrazilGlobalNetworkAccount}; export type CreateBrazilGlobalNetworkAccountBusiness = {rail: 'offramp', type: 'brazilGlobalNetwork', accountHolder: GlobalNetworkIndividualAccountHolder, brazilGlobalNetwork: BrazilGlobalNetworkAccount}; export type ColombiaAccountHolder = {type: 'individual' | 'business', name: string, email: string, phone?: string | undefined, address?: Address | undefined, idType: 'CC' | 'CE' | 'NIT' | 'PASS' | 'PEP', idNumber: string}; export type CreateColombiaAccount = {rail: 'offramp', type: 'colombia', accountHolder: ColombiaAccountHolder, colombia: ColombiaAccount}; export type CreateArgentinaAccount = {rail: 'offramp', type: 'argentina', accountHolder: AccountHolder, argentina: ArgentinaAccount}; export type CreateMexicoAccount = {rail: 'offramp', type: 'mexico', accountHolder: AccountHolder, mexico: MexicoAccount}; export type CreateMexicoGlobalNetworkAccountIndividual = {rail: 'offramp', type: 'mexicoGlobalNetwork', accountHolder: GlobalNetworkIndividualAccountHolder, mexicoGlobalNetwork: MexicoGlobalNetworkAccount}; export type GlobalNetworkBusinessAccountHolder = {name: string, type: 'business', address: {city: string, country: string, postalCode: string, addressLine1: string, addressLine2?: string | undefined, stateProvinceRegion: string}, formationDate: string, idNumber: string}; export type CreateMexicoGlobalNetworkAccountBusiness = {rail: 'offramp', type: 'mexicoGlobalNetwork', accountHolder: GlobalNetworkBusinessAccountHolder, mexicoGlobalNetwork: MexicoGlobalNetworkAccount}; export type CreateNigeriaGlobalNetworkAccountIndividual = {rail: 'offramp', type: 'nigeriaGlobalNetwork', accountHolder: GlobalNetworkIndividualAccountHolder, nigeriaGlobalNetwork: NigeriaGlobalNetworkAccount}; export type CreateNigeriaGlobalNetworkAccountBusiness = {rail: 'offramp', type: 'nigeriaGlobalNetwork', accountHolder: GlobalNetworkBusinessAccountHolder, nigeriaGlobalNetwork: NigeriaGlobalNetworkAccount}; export type CreateHongKongGlobalNetworkAccountIndividual = {rail: 'offramp', type: 'hongKongGlobalNetwork', accountHolder: GlobalNetworkIndividualAccountHolder, hongKongGlobalNetwork: HongKongGlobalNetworkAccount}; export type CreateHongKongGlobalNetworkAccountBusiness = {rail: 'offramp', type: 'hongKongGlobalNetwork', accountHolder: GlobalNetworkBusinessAccountHolder, hongKongGlobalNetwork: HongKongGlobalNetworkAccount}; export type ChinaGlobalNetworkAccount = {bankName?: string | undefined, accountNumber?: string | undefined, swiftCode?: string | undefined, currency: 'usd' | 'cny'}; export type CreateChinaGlobalNetworkAccountIndividual = {rail: 'offramp', type: 'chinaGlobalNetwork', accountHolder: GlobalNetworkIndividualAccountHolder, chinaGlobalNetwork: ChinaGlobalNetworkAccount}; export type CreateChinaGlobalNetworkAccountBusiness = {rail: 'offramp', type: 'chinaGlobalNetwork', accountHolder: GlobalNetworkBusinessAccountHolder, chinaGlobalNetwork: ChinaGlobalNetworkAccount}; export type CreateSingaporeGlobalNetworkAccountIndividual = {rail: 'offramp', type: 'singaporeGlobalNetwork', accountHolder: GlobalNetworkIndividualAccountHolder, singaporeGlobalNetwork: SingaporeGlobalNetworkAccount}; export type CreateSingaporeGlobalNetworkAccountBusiness = {rail: 'offramp', type: 'singaporeGlobalNetwork', accountHolder: GlobalNetworkBusinessAccountHolder, singaporeGlobalNetwork: SingaporeGlobalNetworkAccount}; export type CreateAfricaOnrampAccount = {rail: 'onramp', type: 'africa', africa: AfricaAccount}; export type AfricaAccountHolder = {type: 'individual' | 'business', name: string, email?: string | undefined, phone: string, address?: Address | undefined, idType?: ('CC' | 'CE' | 'NIT' | 'PASS' | 'PEP') | undefined, idNumber?: string | undefined}; export type CreateAfricaOfframpAccount = {rail: 'offramp', type: 'africa', accountHolder: AfricaAccountHolder, africa: AfricaAccount}; export type CreateApiV2UsersUserIdAccountsArgs = {userId: string, body: CreateAccount | CreateUsAccount | CreateBrazilAccount | CreateBrazilGlobalNetworkAccountIndividual | CreateBrazilGlobalNetworkAccountBusiness | CreateColombiaAccount | CreateArgentinaAccount | CreateMexicoAccount | CreateMexicoGlobalNetworkAccountIndividual | CreateMexicoGlobalNetworkAccountBusiness | CreateNigeriaGlobalNetworkAccountIndividual | CreateNigeriaGlobalNetworkAccountBusiness | CreateHongKongGlobalNetworkAccountIndividual | CreateHongKongGlobalNetworkAccountBusiness | CreateChinaGlobalNetworkAccountIndividual | CreateChinaGlobalNetworkAccountBusiness | CreateSingaporeGlobalNetworkAccountIndividual | CreateSingaporeGlobalNetworkAccountBusiness | CreateAfricaOnrampAccount | CreateAfricaOfframpAccount}; export type CreateApiV2UsersUserIdAccountsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createAccountObject = z.object({status: z.string().optional(), message: z.string().optional(), id: 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 }; /** * Create an account * * POST /v2/users/{userId}/accounts */ export const createApiV2UsersUserIdAccounts = async (args: CreateApiV2UsersUserIdAccountsArgs, options?: CreateApiV2UsersUserIdAccountsOptions) => { const {baseUrl = "https://production.hifibridge.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createAccountObject, await res.json()) };