import {z} from 'zod' export type Address = {addressLine1: string, addressLine2?: string | undefined, city: string, stateProvinceRegion: string, postalCode: string, country: string}; export type UboAdd = {role?: ('OWNER_OR_OPERATOR' | 'PARTNER' | 'UBO' | 'DIRECTOR_CONTROL_PERSON_OR_LEGAL_REP' | 'AGENT_OR_AUTHORISED_PERSON') | undefined, roles?: (Array<'UBO' | 'DIRECTOR' | 'REPRESENTATIVE' | 'SHAREHOLDER'>) | undefined, businessTitle?: string | undefined, firstName?: string | undefined, firstNameLocal?: string | undefined, middleName?: string | undefined, middleNameLocal?: string | undefined, lastName?: string | undefined, lastNameLocal?: string | undefined, nationality?: string | undefined, email?: string | undefined, phone?: string | undefined, address?: Address | undefined, dateOfBirth?: string | undefined, countryOfBirth?: string | undefined, stateOfBirth?: string | undefined, placeOfBirth?: string | undefined, gender?: ('M' | 'F') | undefined, taxIdentificationNumber?: string | undefined, taxResidenceCountry?: string | undefined, govIdType?: ('PASSPORT' | 'ID_CARD' | 'DRIVERS') | undefined, govIdCountry?: string | undefined, govIdNumber?: string | undefined, govIdFrontUrl?: string | undefined, govIdBackUrl?: string | undefined, govIdIssuanceDate?: string | undefined, govIdExpirationDate?: string | undefined, govIdIssuanceAuthority?: string | undefined, proofOfAddressType?: ('UTILITY_BILL' | 'BANK_STATEMENT' | 'RENTAL_AGREEMENT' | 'TAX_DOCUMENT') | undefined, proofOfAddressUrl?: string | undefined, authLetterUrl?: string | undefined, shareProportion?: number | undefined, hasOwnership?: boolean | undefined, hasControl?: boolean | undefined, isSigner?: boolean | undefined, relationshipEstablishedAt?: string | undefined, supplementaryInfo?: string | undefined, supplementaryUrl?: string | undefined}; export type CreateApiV2UsersUserIdKycUbosArgs = {userId: string, body: UboAdd}; export type CreateApiV2UsersUserIdKycUbosOptions = {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 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 }; /** * Add a UBO * * POST /v2/users/{userId}/kyc/ubos */ export const createApiV2UsersUserIdKycUbos = async (args: CreateApiV2UsersUserIdKycUbosArgs, options?: CreateApiV2UsersUserIdKycUbosOptions) => { 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))}/kyc/ubos${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(uboObject, await res.json()) };