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 V2PersonCreateEntity = {type: 'PERSON', firstName: string, lastName: string, email: string, 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}; export type V2BusinessRegistrationCreateEntity = {type: 'BUSINESS_REGISTRATION', entityName: string, registrationCountry: string, registrationNumber: string, percentageOfOwnership?: unknown | undefined, typeOfOwnership?: ('DIRECT' | 'INDIRECT') | undefined}; export type V2AssociateCreateEntity = V2PersonCreateEntity | V2BusinessRegistrationCreateEntity; export type V2CreateAssociateRequest = {types: Array<'UBO' | 'CONTROL_PERSON' | 'SIGNATORY' | 'DIRECTOR' | 'ACCOUNT_REPRESENTATIVE'>, entity: V2AssociateCreateEntity}; export type CreateApiPlatformV2CustomersCustomerIdAssociatesArgs = {customerId: string, 'Idempotency-Key'?: string | undefined, body: V2CreateAssociateRequest}; export type CreateApiPlatformV2CustomersCustomerIdAssociatesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPlatformV2CustomersCustomerIdAssociatesResponse = z.object({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 customer associate * * POST /platform/v2/customers/{customerId}/associates */ export const createApiPlatformV2CustomersCustomerIdAssociates = async (args: CreateApiPlatformV2CustomersCustomerIdAssociatesArgs, options?: CreateApiPlatformV2CustomersCustomerIdAssociatesOptions) => { 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 (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/platform/v2/customers/${encodeURIComponent(String(args.customerId))}/associates${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(createApiPlatformV2CustomersCustomerIdAssociatesResponse, await res.json()) };