import {z} from 'zod' export type CreateApiPlatformV1CustomersCustomerReferenceDocumentsArgs = {customerReference: string, body: Array<{customerPersonReference?: string | undefined, type: 'COMPANY_DOC' | 'TRANSPARENCY_REGISTRY_EXTRACT' | 'POWER_OF_ATTORNEY', subType?: ('CAPITALISATION_OWNERSHIP_STRUCTURE' | 'DIRECTORS_REGISTRY' | 'GOOD_STANDING_CERT' | 'INCORPORATION_ARTICLES' | 'INCORPORATION_CERT' | 'INCUMBENCY_CERT' | 'INFORMATION_STATEMENT' | 'MEMORANDUM' | 'PARTNERSHIP_AGREEMENT' | 'POWER_OF_ATTORNEY' | 'PROOF_OF_ADDRESS' | 'PROOF_OF_NATURE_OF_BUSINESS' | 'REGULATORY_LICENSE' | 'SELF_DECLARATION_FORM' | 'SHAREHOLDER_REGISTRY' | 'SOURCE_OF_FUNDS' | 'STATE_REGISTRY' | 'TRADE_LICENSE' | 'TRUST_AGREEMENT' | 'OTHER') | undefined, name: string, description?: string | undefined, countryCode: string, externalReference: string, content: string} | {type: 'AGREEMENT' | 'ARBITRARY_DOC' | 'BANK_CARD' | 'CONTRACT' | 'COVID_VACCINATION_FORM' | 'DRIVERS' | 'DRIVERS_TRANSLATION' | 'FILE_ATTACHMENT' | 'ID_CARD' | 'ID_DOC_PHOTO' | 'INCOME_SOURCE' | 'INVESTOR_DOC' | 'OTHER' | 'PASSPORT' | 'PAYMENT_SOURCE' | 'PROFILE_IMAGE' | 'RESIDENCE_PERMIT' | 'SELFIE' | 'UTILITY_BILL' | 'UTILITY_BILL2' | 'VEHICLE_REGISTRATION_CERTIFICATE' | 'VIDEO_SELFIE', subType?: ('FRONT_SIDE' | 'BACK_SIDE') | undefined, name: string, description?: string | undefined, countryCode: string, externalReference: string, content: string}>}; export type CreateApiPlatformV1CustomersCustomerReferenceDocumentsOptions = {baseUrl?: string | undefined, Hawk?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPlatformV1CustomersCustomerReferenceDocumentsResponse = z.object({reference: z.string().optional(), externalReference: z.string().optional(), status: z.literal("INIT").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 }; /** * Upload documents to customer * * POST /platform/v1/customers/{customerReference}/documents */ export const createApiPlatformV1CustomersCustomerReferenceDocuments = async (args: CreateApiPlatformV1CustomersCustomerReferenceDocumentsArgs, options?: CreateApiPlatformV1CustomersCustomerReferenceDocumentsOptions) => { const {baseUrl = "https://api.sandbox.bvnk.com", fetch: fetchFn = fetch, Hawk} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Hawk !== undefined) headers.set("Authorization", Hawk) const url = `${baseUrl.replace(/\/+$/, '')}/platform/v1/customers/${encodeURIComponent(String(args.customerReference))}/documents${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(createApiPlatformV1CustomersCustomerReferenceDocumentsResponse, await res.json()) };