import {z} from 'zod' export type V2PersonControlOptions = {canAppointDirectors: boolean, hasSignificantControl: boolean, controlsManagement: boolean, controlsCorporateBody: boolean}; export type V2PersonAddress = {addressLine1?: string | undefined, addressLine2?: string | undefined, city?: string | undefined, postalCode?: string | undefined, stateCode?: string | undefined, countryCode?: string | undefined}; export type V2PersonRelianceUpdateMetadata = {identityDocumentMetadata?: ({type: 'PASSPORT' | 'ID_CARD' | 'DRIVERS' | 'RESIDENCE_PERMIT' | 'OTHER', number: string, issueDate?: string | undefined, expiryDate?: string | undefined, issuingCountryCode: string, kycTimestamp: string}) | undefined, biometricLiveness?: {livenessTimestamp: string} | undefined, addressVerification?: ({type: 'DOC' | 'NON_DOC'}) | undefined}; export type V2PersonUpdateEntity = {type: 'PERSON', firstName?: string | undefined, lastName?: string | undefined, email?: string | undefined, phoneNumber?: string | undefined, dateOfBirth?: string | undefined, nationality?: string | undefined, secondNationality?: string | undefined, birthCountryCode?: string | undefined, taxIdentificationNumber?: string | undefined, taxResidence?: string | undefined, position?: string | undefined, isPoliticallyExposedPerson?: boolean | undefined, percentageOfOwnership?: unknown | undefined, ownershipType?: ('DIRECT' | 'INDIRECT') | undefined, controlOptions?: V2PersonControlOptions | undefined, address?: V2PersonAddress | undefined, estimatedYearlyIncome?: ('INCOME_0_TO_50K' | 'INCOME_50K_TO_100K' | 'INCOME_100K_TO_250K' | 'INCOME_250K_TO_500K' | 'INCOME_500K_TO_750K' | 'INCOME_750K_TO_1M' | 'INCOME_ABOVE_1M') | undefined, reliance?: V2PersonRelianceUpdateMetadata | undefined}; export type V2BusinessRegistrationUpdateEntity = {type: 'BUSINESS_REGISTRATION', entityName?: string | undefined, registrationCountry?: string | undefined, registrationNumber?: string | undefined, percentageOfOwnership?: unknown | undefined, typeOfOwnership?: ('DIRECT' | 'INDIRECT') | undefined}; export type V2AssociateUpdateEntity = V2PersonUpdateEntity | V2BusinessRegistrationUpdateEntity; export type V2UpdateAssociateRequest = {types?: (Array<'UBO' | 'CONTROL_PERSON' | 'SIGNATORY' | 'DIRECTOR' | 'ACCOUNT_REPRESENTATIVE'>) | undefined, entity?: V2AssociateUpdateEntity | undefined}; export type PatchApiPlatformV2CustomersCustomerIdAssociatesAssociateIdArgs = {customerId: string, associateId: string, body: V2UpdateAssociateRequest}; export type PatchApiPlatformV2CustomersCustomerIdAssociatesAssociateIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v2PersonControlOptions = z.object({canAppointDirectors: z.boolean(), hasSignificantControl: z.boolean(), controlsManagement: z.boolean(), controlsCorporateBody: z.boolean()}); export const v2PersonAddress = z.object({addressLine1: z.string().max(255).optional(), addressLine2: z.string().max(255).optional(), city: z.string().max(255).optional(), postalCode: z.string().max(255).optional(), stateCode: z.string().min(2).max(2).optional(), countryCode: z.string().min(2).max(2).optional()}); export const v2IdentificationDocument = z.object({type: z.enum(["PASSPORT", "NATIONAL_ID", "DRIVING_LICENSE", "RESIDENCE_PERMIT", "UTILITY_BILL", "TAX_DOCUMENT", "SELFIE", "OTHER"]).optional(), country: z.string().optional(), documentNumber: z.string().optional(), firstName: z.string().optional(), firstNameEn: z.string().optional(), lastName: z.string().optional(), lastNameEn: z.string().optional(), middleName: z.string().optional(), middleNameEn: z.string().optional(), gender: z.string().optional(), dateOfBirth: z.string().optional(), address: v2PersonAddress.optional(), issueAuthority: z.string().optional(), issuedDate: z.string().optional(), validUntil: z.string().optional(), termless: z.boolean().optional()}); export const v2ProofOfAddress = z.object({documentType: z.string().optional(), address: v2PersonAddress.optional()}); export const v2AssociateDocument = z.object({id: z.string().optional(), externalId: z.string().optional(), type: z.enum(["AGREEMENT", "ARBITRARY_DOC", "BANK_CARD", "CONTRACT", "COVID_VACCINATION_FORM", "DRIVERS", "DRIVERS_TRANSLATION", "ID_CARD", "ID_DOC_PHOTO", "INCOME_SOURCE", "INVESTOR_DOC", "PASSPORT", "PAYMENT_SOURCE", "PROFILE_IMAGE", "RESIDENCE_PERMIT", "SELFIE", "UTILITY_BILL", "UTILITY_BILL2", "VEHICLE_REGISTRATION_CERTIFICATE", "VIDEO_SELFIE", "OTHER"]).optional(), subType: z.enum(["FRONT_SIDE", "BACK_SIDE", "DIRECTORS_REGISTRY", "GOOD_STANDING_CERT", "INCORPORATION_ARTICLES", "INCORPORATION_CERT", "INCUMBENCY_CERT", "INFORMATION_STATEMENT", "POWER_OF_ATTORNEY", "PROOF_OF_ADDRESS", "SHAREHOLDER_REGISTRY", "STATE_REGISTRY", "TRUST_AGREEMENT", "OTHER"]).optional(), deactivated: z.boolean().optional()}); export const v2IdentityVerification = z.object({link: z.string().optional(), status: z.enum(["PENDING", "COMPLETE", "RESUBMISSION_REQUESTED"]).optional()}); export const v2PersonAssociateEntity = z.object({type: z.literal("PERSON").optional(), firstName: z.string().optional(), lastName: z.string().optional(), middleName: z.string().optional(), gender: z.string().optional(), email: z.string().optional(), phoneNumber: z.string().optional(), dateOfBirth: z.string().optional(), nationality: z.string().optional(), secondNationality: z.string().optional(), birthCountryCode: z.string().optional(), taxIdentificationNumber: z.string().optional(), taxResidence: z.string().optional(), position: z.string().optional(), isPoliticallyExposedPerson: z.boolean().optional(), percentageOfOwnership: z.string().optional(), ownershipType: z.enum(["DIRECT", "INDIRECT"]).optional(), estimatedYearlyIncome: z.enum(["INCOME_0_TO_50K", "INCOME_50K_TO_100K", "INCOME_100K_TO_250K", "INCOME_250K_TO_500K", "INCOME_500K_TO_750K", "INCOME_750K_TO_1M", "INCOME_ABOVE_1M"]).optional(), controlOptions: v2PersonControlOptions.optional(), address: v2PersonAddress.optional(), identificationDocuments: z.array(v2IdentificationDocument).optional(), proofOfAddresses: z.array(v2ProofOfAddress).optional(), documents: z.array(v2AssociateDocument).optional(), identityVerification: v2IdentityVerification.optional()}); export const v2BusinessRegistrationAssociateEntity = z.object({type: z.literal("BUSINESS_REGISTRATION").optional(), name: z.string(), tradingName: z.string().optional(), registrationNumber: z.string(), registrationCountry: z.string(), percentageOfOwnership: z.string().optional(), typeOfOwnership: z.enum(["DIRECT", "INDIRECT"]).optional()}); export const v2AssociateEntity = z.discriminatedUnion("type", [v2PersonAssociateEntity, v2BusinessRegistrationAssociateEntity]); export const v2ValidationIssue = z.object({field: z.string().optional(), message: z.string().optional()}); export const v2ValidationStatus = z.object({status: z.enum(["COMPLETE", "INCOMPLETE"]).optional(), issues: z.array(v2ValidationIssue).optional()}); export const v2AssociateResponse = z.object({id: z.string().optional(), types: z.array(z.enum(["UBO", "CONTROL_PERSON", "SIGNATORY", "DIRECTOR", "ACCOUNT_REPRESENTATIVE"])).optional(), entity: v2AssociateEntity.optional(), validation: v2ValidationStatus.optional(), createdAt: z.string().optional(), updatedAt: 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 }; /** * Update customer associate * * PATCH /platform/v2/customers/{customerId}/associates/{associateId} */ export const patchApiPlatformV2CustomersCustomerIdAssociatesAssociateId = async (args: PatchApiPlatformV2CustomersCustomerIdAssociatesAssociateIdArgs, options?: PatchApiPlatformV2CustomersCustomerIdAssociatesAssociateIdOptions) => { const {baseUrl = "https://api.sandbox.bvnk.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(/\/+$/, '')}/platform/v2/customers/${encodeURIComponent(String(args.customerId))}/associates/${encodeURIComponent(String(args.associateId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(v2AssociateResponse, await res.json()) };