import {z} from 'zod' export type AdvAddressDocumentVerificationId = string; export type GetApiAddressDocumentVerificationsAddressDocumentVerificationIdArgs = {address_document_verification_id: AdvAddressDocumentVerificationId}; export type GetApiAddressDocumentVerificationsAddressDocumentVerificationIdOptions = {baseUrl: string, OAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const applicantId = z.string(); export const idvUserJourneyId = z.string(); export const idvDeclaredData = z.object({name: z.string().min(2).max(255), birth_date: z.string().optional()}); export const advAddressDocumentVerificationId = z.string(); export const advVerificationStatuses = z.enum(["created", "quality_checks_in_progress", "checks_in_progress", "approved", "declined", "retry_required", "inconclusive"]); export const advAddress = 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: z.string().max(2).optional()}); export const advAddressDocumentResult = z.object({document_type: z.string().optional(), issuer: z.string().optional(), full_names: z.array(z.string()).optional(), issue_date: z.string().optional(), address: advAddress.optional()}); export const idvResponseCodeCode = z.number().int().gte(10000).lte(69999); export const idvResponseCodeSummary = z.string(); export const idvResponseCode = z.object({code: idvResponseCodeCode, summary: idvResponseCodeSummary}); export const idvResponseCodes = z.array(idvResponseCode); export const idvRiskLabel = z.enum(["multiple_faces_detected", "mcc_not_confident", "risky_document_format"]); export const idvRiskLabels = z.array(idvRiskLabel); export const idvHalLink = z.object({href: z.string()}); export const idvIdentityVerificationLinks = z.object({self: idvHalLink, applicant: idvHalLink}); export const advAddressDocumentVerificationOutput = z.object({created_on: z.string(), modified_on: z.string(), applicant_id: applicantId, user_journey_id: idvUserJourneyId, declared_data: idvDeclaredData.optional(), id: advAddressDocumentVerificationId, status: advVerificationStatuses, address_document: advAddressDocumentResult.optional(), response_codes: idvResponseCodes, risk_labels: idvRiskLabels.optional(), _links: idvIdentityVerificationLinks}); 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 }; /** * Get an address document verification * * GET /address-document-verifications/{address_document_verification_id} * * Also accepts auth: ApiSecretKey */ export const getApiAddressDocumentVerificationsAddressDocumentVerificationId = async (args: GetApiAddressDocumentVerificationsAddressDocumentVerificationIdArgs, options: GetApiAddressDocumentVerificationsAddressDocumentVerificationIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth !== undefined) headers.set('authorization', `Bearer ${OAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/address-document-verifications/${encodeURIComponent(String(args.address_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(advAddressDocumentVerificationOutput, await res.json()) };