import {z} from 'zod' export type BankDocumentVerificationId = string; export type GetApiV2BankDocumentVerificationsBankDocumentVerificationIdArgs = {bank_document_verification_id: BankDocumentVerificationId}; export type GetApiV2BankDocumentVerificationsBankDocumentVerificationIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bankDocumentVerificationId = z.string(); export const bankDocumentVerificationStatus = z.enum(["created", "quality_checks_in_progress", "checks_in_progress", "approved", "declined", "retry_required", "inconclusive"]); export const responseCode = z.number().int().gte(10000).lte(69999); export const responseSummary = z.string(); export const responseCodes = z.object({code: responseCode, summary: responseSummary}); export const riskLabel = z.enum(["multiple_faces_detected", "mcc_not_confident", "risky_document_format", "no_uk_footprint"]); export const riskLabels = z.array(riskLabel); export const accountTypes = z.enum(["checking", "savings"]); export const bankDocumentType = z.enum(["bank_statement", "bank_letter", "bank_check"]); export const countryCodeIso2 = z.string(); export const address = z.object({address_line1: z.string().max(250).optional(), address_line2: z.string().max(250).optional(), city: z.string().max(50).optional(), state: z.string().max(50).optional(), zip: z.string().max(50).optional(), country: countryCodeIso2.optional()}); export const bankDocument = z.object({bank_account_number: z.string().max(255).optional(), bank_routing_number: z.string().max(255).optional(), account_type: accountTypes.optional(), company_name: z.string().min(2).max(510).optional(), bank_name: z.string().min(2).max(510).optional(), issue_date: z.string().optional(), document_type: bankDocumentType.optional(), company_address: address.optional()}); export const halLink = z.object({href: z.string()}); export const bankDocumentVerificationLinks = z.object({self: halLink}); export const userJourneyId = z.string(); export const businessApplicantId = z.string(); export const bankDocumentVerificationDeclaredData = z.object({registered_name: z.string().min(2).max(255), trading_name: z.string().min(2).max(255)}); export const bankDocumentVerificationOutputGet = z.object({created_on: z.string(), modified_on: z.string(), id: bankDocumentVerificationId, status: bankDocumentVerificationStatus, response_codes: z.array(responseCodes), risk_labels: riskLabels.optional(), bank_document: bankDocument.optional(), _links: bankDocumentVerificationLinks, user_journey_id: userJourneyId, applicant_id: businessApplicantId, webhook_url: z.string().optional(), declared_data: bankDocumentVerificationDeclaredData.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 }; /** * Retrieve a Bank Document Verification * * GET /v2/bank-document-verifications/{bank_document_verification_id} */ export const getApiV2BankDocumentVerificationsBankDocumentVerificationId = async (args: GetApiV2BankDocumentVerificationsBankDocumentVerificationIdArgs, options?: GetApiV2BankDocumentVerificationsBankDocumentVerificationIdOptions) => { const {baseUrl = "https://api.ubble.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/bank-document-verifications/${encodeURIComponent(String(args.bank_document_verification_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(bankDocumentVerificationOutputGet, await res.json()) };