import {z} from 'zod' export type PatchApiEmployeesArgs = {body: {companyID: string, employee: {employeeID: string, first_name?: string | undefined, last_name?: string | undefined, title?: string | undefined, dob?: string | undefined, employment_status?: string | undefined, email?: string | undefined, workLocationID?: string | undefined, address?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, phone_number?: string | undefined, start_date?: string | undefined, default_pay_schedule?: string | undefined, default_wage?: number | undefined, default_ot_wage?: number | undefined, default_dt_wage?: number | undefined, ssn?: string | undefined, term_date?: string | undefined, salary_firstDate?: string | undefined, salary?: number | undefined, autopilot_on?: boolean | undefined, external_id?: string | undefined, metadata?: Record | undefined, soc_code?: string | undefined}}}; export type PatchApiEmployeesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiEmployeesResponse = z.object({success: z.boolean().optional(), data: z.object({employeeID: z.string().optional(), companyID: z.string().optional(), onboarded: z.boolean().optional(), employment_status: z.string().optional(), term_date: z.unknown(), first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), dob: z.string().optional(), start_date: z.string().optional(), title: z.string().optional(), working_state: z.string().optional(), workLocationID: z.string().optional(), address: z.string().optional(), city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), phone_number: z.string().optional(), default_pay_schedule: z.string().optional(), default_wage: z.number().int().optional(), default_ot_wage: z.number().int().optional(), default_dt_wage: z.number().int().optional(), ssn: z.string().optional(), is_943: z.boolean().optional(), is_scheduleH: z.boolean().optional(), is_salary: z.boolean().optional(), salary: z.number().int().optional(), paycard_requested: z.boolean().optional(), paycard_enabled: z.boolean().optional(), kyc_status: z.unknown(), ssn_verification_status: z.unknown()}).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 Employee Information * * PATCH /employees */ export const patchApiEmployees = async (args: PatchApiEmployeesArgs, options?: PatchApiEmployeesOptions) => { 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(/\/+$/, '')}/employees${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(patchApiEmployeesResponse, await res.json()) };