import {z} from 'zod' export type GetApiV1LinksLinkIdPllReportArgs = {show_fraud_reasons?: boolean | undefined}; export type GetApiV1LinksLinkIdPllReportOptions = {baseUrl?: string | undefined, ClientID?: string | undefined, AccessKey?: string | undefined, fetch?: typeof fetch | undefined}; export const fraudReason = z.object({code: z.enum(["editing_software_detected", "screenshot", "design_software_detected", "document_from_online_generator", "office_software_detected", "scanned_document", "suspicious_producer", "blocked_text_content", "document_type_mismatch", "ai_generated_content", "invalid_content_credentials", "malware_detected", "modified_before_creation_date", "future_date", "modified_after_creation", "anomalous_pdf_structure", "invalid_date", "has_only_images", "insufficient_text", "content_tampering_suspected", "content_diff_between_versions", "ssn_mismatch_between_documents", "ssn_mismatch_with_applicant", "inconsistent_payroll_taxes"]), message: z.string(), severity: z.enum(["high", "medium", "low"]), document_ids: z.array(z.string()), uploaded_file_ids: z.array(z.string()), details: z.record(z.string(), z.unknown()), task_id: z.string().nullable(), created_at: z.string()}); export const pLLDetail = z.object({id: z.string().max(32), status: z.string(), finished_at: z.string().optional(), completed_at: z.string(), access_token: z.string().max(32), tracking_info: z.string().max(255).nullable(), is_suspicious: z.boolean().optional(), fraud_reasons: z.array(fraudReason).optional(), deposit_details: z.object({account_number: z.string().min(4).max(20).optional(), account_type: z.enum(["checking", "savings"]).optional(), routing_number: z.string().min(8).max(12).optional(), bank_name: z.string().max(128).optional(), deposit_type: z.string().optional(), deposit_value: z.string().optional()}), initial_accounts: z.array(z.object({account_number: z.string().min(4).max(20), routing_number: z.string().min(8).max(12), account_type: z.enum(["checking", "savings"]).optional(), account_name: z.string().max(128).optional(), bank_name: z.string().max(128).optional(), deposit_type: z.enum(["entire", "percent", "amount"]).optional(), deposit_value: z.string().optional()})).nullable().optional(), pdf_report: z.string().optional(), employer: z.object({id: z.string().max(64), name: z.string().max(128), logo_url: z.string().nullable().optional()}).nullable().optional(), provider: z.object({id: z.string().max(64), name: z.string().max(128), logo_url: 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 }; /** * Retrieve a paycheck linked loan report * * GET /v1/links/{link_id}/pll/report/ */ export const getApiV1LinksLinkIdPllReport = async (args: GetApiV1LinksLinkIdPllReportArgs, options?: GetApiV1LinksLinkIdPllReportOptions) => { const {baseUrl = "https://prod.truv.com", fetch: fetchFn = fetch, ClientID, AccessKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.show_fraud_reasons != null) query.append("show_fraud_reasons", String(args.show_fraud_reasons)) if (ClientID !== undefined) headers.set("X-Access-Client-Id", ClientID) if (AccessKey !== undefined) headers.set("X-Access-Secret", AccessKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/links/${encodeURIComponent(String(args.link_id))}/pll/report/${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(pLLDetail, await res.json()) };