import {z} from 'zod' export type GetApiQuickbooksDesktopEmployeesIdArgs = {'Conductor-End-User-Id': string, id: string}; export type GetApiQuickbooksDesktopEmployeesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const qbdEmployeeAddress = z.object({line1: z.string().nullable(), line2: z.string().nullable(), line3: z.string().nullable(), line4: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), postalCode: z.string().nullable(), country: z.string().nullable()}); export const qbdCustomContactField = z.object({name: z.string(), value: z.string().nullable()}); export const qbdEmergencyContact = z.object({name: z.string(), value: z.string().nullable(), relation: z.enum(["brother", "daughter", "father", "friend", "mother", "other", "partner", "sister", "son", "spouse"]).nullable()}); export const qbdEmergencyContactSet = z.object({primaryContact: qbdEmergencyContact.nullable(), secondaryContact: qbdEmergencyContact.nullable()}); export const qbdNote = z.object({id: z.number(), date: z.string().nullable(), note: z.string()}); export const qbdEarnings = z.object({payrollWageItem: z.object({id: z.string().nullable(), fullName: z.string().nullable()}), rate: z.string().nullable(), ratePercent: z.string().nullable()}); export const qbdSickHours = z.object({hoursAvailable: z.string().nullable(), accrualPeriod: z.enum(["accrues_annually", "accrues_hourly", "accrues_per_paycheck"]).nullable(), hoursAccruedPerPeriod: z.string().nullable(), maximumHours: z.string().nullable(), resetsHoursEachYear: z.boolean().nullable(), hoursUsed: z.string().nullable(), accrualStartDate: z.string().nullable()}); export const qbdVacationHours = z.object({hoursAvailable: z.string().nullable(), accrualPeriod: z.enum(["accrues_annually", "accrues_hourly", "accrues_per_paycheck"]).nullable(), hoursAccruedPerPeriod: z.string().nullable(), maximumHours: z.string().nullable(), resetsHoursEachYear: z.boolean().nullable(), hoursUsed: z.string().nullable(), accrualStartDate: z.string().nullable()}); export const qbdEmployeePayrollInfo = z.object({payPeriod: z.enum(["biweekly", "daily", "monthly", "quarterly", "semimonthly", "weekly", "yearly"]).nullable(), class: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), earnings: z.array(qbdEarnings), useTimeDataToCreatePaychecks: z.enum(["does_not_use_time_data", "not_set", "uses_time_data"]).nullable(), sickHours: qbdSickHours.nullable(), vacationHours: qbdVacationHours.nullable()}); export const qbdCustomField = z.object({ownerId: z.string(), name: z.string(), type: z.enum(["amount_type", "date_time_type", "integer_type", "percent_type", "price_type", "quantity_type", "string_1024_type", "string_255_type"]), value: z.string()}); export const qbdEmployee = z.object({id: z.string(), objectType: z.literal("qbd_employee"), createdAt: z.string(), updatedAt: z.string(), revisionNumber: z.string(), name: z.string(), isActive: z.boolean(), salutation: z.string().nullable(), firstName: z.string().nullable(), middleName: z.string().nullable(), lastName: z.string().nullable(), jobTitle: z.string().nullable(), supervisor: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), department: z.string().nullable(), description: z.string().nullable(), targetBonus: z.string().nullable(), address: qbdEmployeeAddress.nullable(), printAs: z.string().nullable(), phone: z.string().nullable(), mobile: z.string().nullable(), pager: z.string().nullable(), pagerPin: z.string().nullable(), alternatePhone: z.string().nullable(), fax: z.string().nullable(), ssn: z.string().nullable(), email: z.string().nullable(), customContactFields: z.array(qbdCustomContactField), emergencyContact: qbdEmergencyContactSet.nullable(), employeeType: z.enum(["officer", "owner", "regular", "statutory"]).nullable(), employmentStatus: z.enum(["full_time", "part_time"]).nullable(), overtimeExemptStatus: z.enum(["exempt", "non_exempt"]).nullable(), keyEmployeeStatus: z.enum(["key_employee", "non_key_employee"]).nullable(), gender: z.enum(["male", "female"]).nullable(), hiredDate: z.string().nullable(), originalHireDate: z.string().nullable(), adjustedServiceDate: z.string().nullable(), terminationDate: z.string().nullable(), birthDate: z.string().nullable(), usCitizenshipStatus: z.enum(["citizen", "non_citizen"]).nullable(), ethnicity: z.enum(["american_indian", "asian", "black", "hawaiian", "hispanic", "white", "two_or_more_races"]).nullable(), disabilityStatus: z.enum(["disabled", "non_disabled"]).nullable(), disabilityDescription: z.string().nullable(), i9OnFileStatus: z.enum(["on_file", "not_on_file"]).nullable(), workAuthorizationExpirationDate: z.string().nullable(), usVeteranStatus: z.enum(["veteran", "non_veteran"]).nullable(), militaryStatus: z.enum(["active", "reserve"]).nullable(), accountNumber: z.string().nullable(), note: z.string().nullable(), additionalNotes: z.array(qbdNote), billingRate: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), employeePayroll: qbdEmployeePayrollInfo.nullable(), externalId: z.string().nullable(), customFields: z.array(qbdCustomField)}); 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 an employee * * GET /quickbooks-desktop/employees/{id} */ export const getApiQuickbooksDesktopEmployeesId = async (args: GetApiQuickbooksDesktopEmployeesIdArgs, options?: GetApiQuickbooksDesktopEmployeesIdOptions) => { const {baseUrl = "https://api.conductor.is/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Conductor-End-User-Id'] != null) headers.set("Conductor-End-User-Id", String(args['Conductor-End-User-Id'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/quickbooks-desktop/employees/${encodeURIComponent(String(args.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(qbdEmployee, await res.json()) };