import {z} from 'zod' export type IndividualDocumentAdd = Array<{type: 'DRIVERS' | 'ID_CARD' | 'PASSPORT' | 'INCOME_SOURCE' | 'INVESTOR_DOC' | 'PAYMENT_SOURCE' | 'RESIDENCE_PERMIT' | 'SELFIE' | 'PROOF_OF_ADDRESS' | 'AUTH_LETTER' | 'OTHER', subType: 'FRONT_SIDE' | 'BACK_SIDE' | 'SINGLE_SIDE', issuedCountry: string, issuedDate?: string | undefined, expiryDate?: string | undefined, number?: string | undefined, description?: string | undefined, url?: string | undefined, fileId?: string | undefined, uboId?: string | undefined}>; export type BusinessDocumentAdd = Array<{type: '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' | 'SOURCE_OF_FUNDS' | 'FORMATION_CERT' | 'REGISTRATION_CERT' | 'PROOF_OF_OWNERSHIP' | 'CONSTITUTION_OR_ANNUAL_REPORT' | 'ARTICLES_OF_ASSOCIATION' | 'UBO_DECLARATION' | 'PARTNERSHIP_MINS_OF_MEETING' | 'PARTNERSHIP_DEED' | 'FLOW_OF_FUNDS' | 'SOURCE_OF_FUNDS' | 'ORGANIZATION_STRUCTURE' | 'SHARE_STRUCTURE' | 'BUSINESS_REGISTRATION' | 'OTHER', subType: 'SINGLE_SIDE', issuedCountry: string, issuedDate?: string | undefined, expiryDate?: string | undefined, number?: string | undefined, description?: string | undefined, url?: string | undefined, fileId?: string | undefined, uboId?: string | undefined}>; export type CreateApiV2UsersUserIdKycDocumentsArgs = {userId: string, body: IndividualDocumentAdd | BusinessDocumentAdd}; export type CreateApiV2UsersUserIdKycDocumentsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const documentObject = z.object({type: z.string().optional(), subType: z.string().optional(), issuedCountry: z.string().optional(), issuedDate: z.string().optional(), expiryDate: z.string().optional(), number: z.string().optional(), description: z.string().optional(), url: z.string().optional(), fileId: z.string().optional(), uboId: z.string().optional()}); export const documentObjectList = z.object({count: z.number().int().optional(), data: z.array(documentObject).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 }; /** * Add documents * * POST /v2/users/{userId}/kyc/documents */ export const createApiV2UsersUserIdKycDocuments = async (args: CreateApiV2UsersUserIdKycDocumentsArgs, options?: CreateApiV2UsersUserIdKycDocumentsOptions) => { 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/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(documentObjectList, await res.json()) };