import {z} from 'zod' export type PatchApiCompaniesArgs = {body: {companyID: string, first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, business_name?: string | undefined, business_phone?: string | undefined, business_address?: string | undefined, business_city?: string | undefined, business_state?: string | undefined, business_zip?: string | undefined, mail_address?: string | undefined, mail_city?: string | undefined, mail_state?: string | undefined, mail_zip?: string | undefined, ssn?: string | undefined, ownership_percentage?: number | undefined, legal_structure?: ('ccorp' | 'corp' | 'estate' | 'foreign_entity' | 'llc' | 'llp' | 'lp' | 'nonprofit' | 'partnership' | 'scheme' | 'scorp' | 'soleprop' | 'trust') | undefined, job_title?: string | undefined, dob?: string | undefined, address?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, payroll_schedule?: ('daily' | 'weekly' | 'biweekly' | 'semimonthly' | 'monthly') | undefined, payroll_firstDate?: string | undefined, payroll_firstPayPeriodID?: string | undefined}}; export type PatchApiCompaniesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiCompaniesResponse = z.object({success: z.boolean().optional(), data: z.object({companyID: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), business_name: z.string().optional(), business_address: z.string().optional(), business_city: z.string().optional(), business_state: z.string().optional(), business_zip: z.string().optional(), business_phone: z.string().optional(), mail_address: z.string().optional(), mail_city: z.string().optional(), mail_state: z.string().optional(), mail_zip: z.string().optional(), ssn: z.string().optional(), ownership_percentage: z.number().int().optional(), dob: z.string().optional(), legal_structure: z.string().optional(), job_title: z.string().optional(), address: z.string().optional(), city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), payroll_firstCheckDate: z.string().optional(), payroll_schedule: z.string().optional(), payroll_firstPayPeriodID: z.string().optional()}).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 }; /** * Update Company Information * * PATCH /companies */ export const patchApiCompanies = async (args: PatchApiCompaniesArgs, options?: PatchApiCompaniesOptions) => { const {baseUrl = "https://api.zeal.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/companies${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiCompaniesResponse, await res.json()) };