import {z} from 'zod' export type GetApiV2UsersUserIdKycUbosArgs = {userId: string}; export type GetApiV2UsersUserIdKycUbosOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({addressLine1: z.string(), addressLine2: z.string().optional(), city: z.string(), stateProvinceRegion: z.string(), postalCode: z.string(), country: z.string()}); export const ultimateBeneficialOwner = z.object({role: z.enum(["OWNER_OR_OPERATOR", "PARTNER", "UBO", "DIRECTOR_CONTROL_PERSON_OR_LEGAL_REP", "AGENT_OR_AUTHORISED_PERSON"]).optional(), roles: z.array(z.enum(["UBO", "DIRECTOR", "REPRESENTATIVE", "SHAREHOLDER"])).optional(), businessTitle: z.string().optional(), firstName: z.string().optional(), firstNameLocal: z.string().optional(), middleName: z.string().optional(), middleNameLocal: z.string().optional(), lastName: z.string().optional(), lastNameLocal: z.string().optional(), nationality: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), address: address.optional(), dateOfBirth: z.string().optional(), countryOfBirth: z.string().optional(), stateOfBirth: z.string().optional(), placeOfBirth: z.string().optional(), gender: z.enum(["M", "F"]).optional(), taxIdentificationNumber: z.string().optional(), taxResidenceCountry: z.string().optional(), govIdType: z.enum(["PASSPORT", "ID_CARD", "DRIVERS"]).optional(), govIdCountry: z.string().optional(), govIdNumber: z.string().optional(), govIdFrontUrl: z.string().optional(), govIdBackUrl: z.string().optional(), govIdIssuanceDate: z.string().optional(), govIdExpirationDate: z.string().optional(), govIdIssuanceAuthority: z.string().optional(), proofOfAddressType: z.enum(["UTILITY_BILL", "BANK_STATEMENT", "RENTAL_AGREEMENT", "TAX_DOCUMENT"]).optional(), proofOfAddressUrl: z.string().optional(), authLetterUrl: z.string().optional(), shareProportion: z.number().optional(), hasOwnership: z.boolean().optional(), hasControl: z.boolean().optional(), isSigner: z.boolean().optional(), relationshipEstablishedAt: z.string().optional(), supplementaryInfo: z.string().optional(), supplementaryUrl: z.string().optional()}); export const uboObject = ultimateBeneficialOwner; export const uboObjectList = z.object({count: z.number().int().optional(), data: z.array(uboObject).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 UBOs * * GET /v2/users/{userId}/kyc/ubos */ export const getApiV2UsersUserIdKycUbos = async (args: GetApiV2UsersUserIdKycUbosArgs, options?: GetApiV2UsersUserIdKycUbosOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/users/${encodeURIComponent(String(args.userId))}/kyc/ubos${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(uboObjectList, await res.json()) };