import {z} from 'zod' export type Address = {city?: (string | null) | undefined, line_1?: (string | null) | undefined, line_2?: (string | null) | undefined, state?: (string | null) | undefined, zip?: (string | null) | undefined}; export type Owner = {credit_score?: (number | null) | undefined, date_of_birth?: (string | null) | undefined, email_address?: (string | null) | undefined, first_name?: (string | null) | undefined, has_signed?: (boolean | null) | undefined, home_address?: Address | undefined, home_phone?: (string | null) | undefined, last_name?: (string | null) | undefined, middle_name?: (string | null) | undefined, mobile_phone?: (string | null) | undefined, ownership_percentage?: (number | null) | undefined, prefix?: (string | null) | undefined, signed_date?: (string | null) | undefined, social_security_number?: (string | null) | undefined, suffix?: (string | null) | undefined}; export type EndUserInformationPatchSchema = {amount_requested?: (number | null) | undefined, annual_revenue?: (number | null) | undefined, business_start_date?: (string | null) | undefined, company_billing_address?: Address | undefined, company_email?: (string | null) | undefined, company_legal_business_name?: (string | null) | undefined, company_phone_number?: (string | null) | undefined, company_physical_address?: Address | undefined, company_website?: (string | null) | undefined, dba?: (string | null) | undefined, federal_tax_id?: (string | null) | undefined, industry_type?: (string | null) | undefined, loan_purpose?: (string | null) | undefined, monthly_revenue?: (number | null) | undefined, naics?: (string | null) | undefined, owner_1?: Owner | undefined, owner_2?: Owner | undefined, predicted_industry_probability?: (number | null) | undefined, source_email_address?: (string | null) | undefined, source_name?: (string | null) | undefined, source_notes?: (string | null) | undefined, state_of_incorporation?: (string | null) | undefined, type_of_business_entity?: (string | null) | undefined}; export type CreateApiApiBrokerSubmissionsSubmissionHeronIdUpdateInformationArgs = {submission_heron_id: string, body: EndUserInformationPatchSchema}; export type CreateApiApiBrokerSubmissionsSubmissionHeronIdUpdateInformationOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({city: z.string().nullable().optional(), line_1: z.string().nullable().optional(), line_2: z.string().nullable().optional(), state: z.string().nullable().optional(), zip: z.string().nullable().optional()}); export const owner = z.object({credit_score: z.number().int().nullable().optional(), date_of_birth: z.string().nullable().optional(), email_address: z.string().nullable().optional(), first_name: z.string().nullable().optional(), has_signed: z.boolean().nullable().optional(), home_address: address.optional(), home_phone: z.string().nullable().optional(), last_name: z.string().nullable().optional(), middle_name: z.string().nullable().optional(), mobile_phone: z.string().nullable().optional(), ownership_percentage: z.number().nullable().optional(), prefix: z.string().nullable().optional(), signed_date: z.string().nullable().optional(), social_security_number: z.string().nullable().optional(), suffix: z.string().nullable().optional()}); export const endUserInformationSchema = z.object({amount_requested: z.number().nullable().optional(), annual_revenue: z.number().nullable().optional(), business_start_date: z.string().nullable().optional(), company_billing_address: address.optional(), company_email: z.string().nullable().optional(), company_legal_business_name: z.string().nullable().optional(), company_phone_number: z.string().nullable().optional(), company_physical_address: address.optional(), company_website: z.string().nullable().optional(), dba: z.string().nullable().optional(), federal_tax_id: z.string().nullable().optional(), industry_type: z.string().nullable().optional(), loan_purpose: z.string().nullable().optional(), monthly_revenue: z.number().nullable().optional(), naics: z.string().nullable().optional(), owner_1: owner.optional(), owner_2: owner.optional(), predicted_industry_probability: z.number().nullable().optional(), source_email_address: z.string().nullable().optional(), source_name: z.string().nullable().optional(), source_notes: z.string().nullable().optional(), source_type: z.enum(["api", "iso_application_form", "heron_industry_classifier", "rel6_industry_classifier", "email", "end_user_entities"]).optional(), state_of_incorporation: z.string().nullable().optional(), type_of_business_entity: z.string().nullable().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 details to broker submission * * POST /api/broker_submissions/{submission_heron_id}/update_information */ export const createApiApiBrokerSubmissionsSubmissionHeronIdUpdateInformation = async (args: CreateApiApiBrokerSubmissionsSubmissionHeronIdUpdateInformationArgs, options?: CreateApiApiBrokerSubmissionsSubmissionHeronIdUpdateInformationOptions) => { const {baseUrl = "https://app.herondata.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/broker_submissions/${encodeURIComponent(String(args.submission_heron_id))}/update_information${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(endUserInformationSchema, await res.json()) };