import {z} from 'zod' export type HrisEmail = {email: string, type?: ('WORK' | 'HOME' | 'OTHER') | undefined}; export type PropertyHrisEmployeeEmails = Array; export type HrisTelephone = {telephone: string, type?: ('WORK' | 'HOME' | 'OTHER' | 'FAX' | 'MOBILE') | undefined}; export type PropertyHrisEmployeeTelephones = Array; export type PropertyHrisEmployeeAddress = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, region?: string | undefined, region_code?: string | undefined, postal_code?: string | undefined, country?: string | undefined, country_code?: string | undefined}; export type PropertyHrisEmployeeEmployeeRoles = Array<'ADMIN' | 'MANAGER' | 'RECRUITER' | 'SALESREP' | 'INTERVIEWER' | 'USER' | 'EMPLOYEE'>; export type HrisCompensation = {type?: ('SALARY' | 'BONUS' | 'STOCK_OPTIONS' | 'EQUITY' | 'OTHER' | 'HOURLY' | 'COMMISSION') | undefined, amount?: number | undefined, currency?: string | undefined, frequency?: ('ONE_TIME' | 'DAY' | 'QUARTER' | 'YEAR' | 'HOUR' | 'MONTH' | 'WEEK' | 'BIWEEKLY' | 'SEMIMONTHLY') | undefined, group_id?: string | undefined, notes?: string | undefined}; export type PropertyHrisEmployeeCompensation = Array; export type PropertyHrisGroupUserIds = Array; export type PropertyHrisGroupManagerIds = Array; export type HrisMetadata = {id?: string | undefined, value?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, namespace?: string | undefined, format?: ('TEXT' | 'NUMBER' | 'DATE' | 'BOOLEAN' | 'FILE' | 'TEXTAREA' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'MEASUREMENT' | 'PRICE' | 'YES_NO' | 'CURRENCY' | 'URL') | undefined, extra_data?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, slug?: string | undefined}; export type PropertyHrisGroupMetadata = Array; export type HrisGroup = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, name?: string | undefined, description?: string | undefined, parent_id?: string | undefined, type?: ('TEAM' | 'GROUP' | 'DEPARTMENT' | 'DIVISION' | 'BUSINESS_UNIT' | 'BRANCH' | 'SUB_DEPARTMENT' | 'PAY_GROUP') | undefined, user_ids?: PropertyHrisGroupUserIds | undefined, manager_ids?: PropertyHrisGroupManagerIds | undefined, is_active?: boolean | undefined, company_id?: string | undefined, pay_frequency?: ('ONE_TIME' | 'DAY' | 'QUARTER' | 'YEAR' | 'HOUR' | 'MONTH' | 'WEEK' | 'BIWEEKLY' | 'SEMIMONTHLY') | undefined, next_paid_at?: string | undefined, metadata?: PropertyHrisGroupMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type PropertyHrisEmployeeGroups = Array; export type PropertyHrisLocationAddress = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, region?: string | undefined, region_code?: string | undefined, postal_code?: string | undefined, country?: string | undefined, country_code?: string | undefined}; export type PropertyHrisLocationTelephones = Array; export type PropertyHrisLocationMetadata = Array; export type HrisLocation = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, name?: string | undefined, description?: string | undefined, address?: PropertyHrisLocationAddress | undefined, parent_id?: string | undefined, external_identifier?: string | undefined, telephones?: PropertyHrisLocationTelephones | undefined, timezone?: string | undefined, currency?: string | undefined, language_locale?: string | undefined, is_active?: boolean | undefined, is_hq?: boolean | undefined, company_id?: string | undefined, metadata?: PropertyHrisLocationMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type PropertyHrisEmployeeLocations = Array; export type PropertyHrisEmployeeMetadata = Array; export type PropertyHrisEmployeerelationshipEmails = Array; export type PropertyHrisEmployeerelationshipTelephones = Array; export type PropertyHrisEmployeerelationshipAddress = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, region?: string | undefined, region_code?: string | undefined, postal_code?: string | undefined, country?: string | undefined, country_code?: string | undefined}; export type HrisEmployeerelationship = {name?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, emails?: PropertyHrisEmployeerelationshipEmails | undefined, telephones?: PropertyHrisEmployeerelationshipTelephones | undefined, address?: PropertyHrisEmployeerelationshipAddress | undefined, type?: ('EMERGENCY' | 'SPOUSE' | 'CHILD' | 'PARENT' | 'SIBLING' | 'FRIEND' | 'OTHER') | undefined, is_dependent?: boolean | undefined, is_beneficiary?: boolean | undefined, start_at?: string | undefined, end_at?: string | undefined}; export type PropertyHrisEmployeeRelationships = Array; export type HrisEmployee = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, name?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, emails?: PropertyHrisEmployeeEmails | undefined, title?: string | undefined, job_id?: string | undefined, manager_id?: string | undefined, employment_status?: ('ACTIVE' | 'INACTIVE') | undefined, gender?: ('MALE' | 'FEMALE' | 'INTERSEX' | 'TRANS' | 'NON_BINARY') | undefined, telephones?: PropertyHrisEmployeeTelephones | undefined, date_of_birth?: string | undefined, employee_number?: string | undefined, hired_at?: string | undefined, terminated_at?: string | undefined, termination_reason?: string | undefined, marital_status?: ('MARRIED' | 'SINGLE') | undefined, employment_type?: ('FULL_TIME' | 'PART_TIME' | 'CONTRACTOR' | 'INTERN' | 'CONSULTANT' | 'VOLUNTEER' | 'CASUAL' | 'SEASONAL' | 'FREELANCE' | 'OTHER') | undefined, address?: PropertyHrisEmployeeAddress | undefined, language_locale?: string | undefined, currency?: string | undefined, timezone?: string | undefined, image_url?: string | undefined, company_id?: string | undefined, pronouns?: string | undefined, employee_roles?: PropertyHrisEmployeeEmployeeRoles | undefined, compensation?: PropertyHrisEmployeeCompensation | undefined, salutation?: string | undefined, bio?: string | undefined, ssn_sin?: string | undefined, groups?: PropertyHrisEmployeeGroups | undefined, locations?: PropertyHrisEmployeeLocations | undefined, metadata?: PropertyHrisEmployeeMetadata | undefined, storage_quota_allocated?: number | undefined, storage_quota_used?: number | undefined, storage_quota_available?: number | undefined, relationships?: PropertyHrisEmployeeRelationships | undefined, has_mfa?: boolean | undefined, timeoff_days_total?: number | undefined, timeoff_days_used?: number | undefined, flsa_status?: ('EXEMPT' | 'NON_EXEMPT' | 'SALARIED_NONEXEMPT' | 'OWNER') | undefined, pay_frequency?: ('ONE_TIME' | 'DAY' | 'QUARTER' | 'YEAR' | 'HOUR' | 'MONTH' | 'WEEK' | 'BIWEEKLY' | 'SEMIMONTHLY') | undefined, raw?: {[key: string]: unknown} | undefined}; export type UpdateApiHrisConnectionIdEmployeeIdArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'name' | 'first_name' | 'last_name' | 'emails' | 'title' | 'job_id' | 'manager_id' | 'employment_status' | 'gender' | 'telephones' | 'date_of_birth' | 'employee_number' | 'hired_at' | 'terminated_at' | 'termination_reason' | 'marital_status' | 'employment_type' | 'address' | 'language_locale' | 'currency' | 'timezone' | 'image_url' | 'company_id' | 'pronouns' | 'employee_roles' | 'compensation' | 'salutation' | 'bio' | 'ssn_sin' | 'groups' | 'locations' | 'metadata' | 'storage_quota_allocated' | 'storage_quota_used' | 'storage_quota_available' | 'relationships' | 'has_mfa' | 'timeoff_days_total' | 'timeoff_days_used' | 'flsa_status' | 'pay_frequency' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, id: string, body: HrisEmployee}; export type UpdateApiHrisConnectionIdEmployeeIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const hrisEmail = z.object({email: z.string(), type: z.enum(["WORK", "HOME", "OTHER"]).optional()}); export const propertyHrisEmployeeEmails = z.array(hrisEmail); export const hrisTelephone = z.object({telephone: z.string(), type: z.enum(["WORK", "HOME", "OTHER", "FAX", "MOBILE"]).optional()}); export const propertyHrisEmployeeTelephones = z.array(hrisTelephone); export const propertyHrisEmployeeAddress = z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), region_code: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), country_code: z.string().optional()}); export const propertyHrisEmployeeEmployeeRoles = z.array(z.enum(["ADMIN", "MANAGER", "RECRUITER", "SALESREP", "INTERVIEWER", "USER", "EMPLOYEE"])); export const hrisCompensation = z.object({type: z.enum(["SALARY", "BONUS", "STOCK_OPTIONS", "EQUITY", "OTHER", "HOURLY", "COMMISSION"]).optional(), amount: z.number().optional(), currency: z.string().optional(), frequency: z.enum(["ONE_TIME", "DAY", "QUARTER", "YEAR", "HOUR", "MONTH", "WEEK", "BIWEEKLY", "SEMIMONTHLY"]).optional(), group_id: z.string().optional(), notes: z.string().optional()}); export const propertyHrisEmployeeCompensation = z.array(hrisCompensation); export const propertyHrisGroupUserIds = z.array(z.string()); export const propertyHrisGroupManagerIds = z.array(z.string()); export const hrisMetadata = z.object({id: z.string().optional(), value: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), namespace: z.string().optional(), format: z.enum(["TEXT", "NUMBER", "DATE", "BOOLEAN", "FILE", "TEXTAREA", "SINGLE_SELECT", "MULTIPLE_SELECT", "MEASUREMENT", "PRICE", "YES_NO", "CURRENCY", "URL"]).optional(), extra_data: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), slug: z.string().optional()}); export const propertyHrisGroupMetadata = z.array(hrisMetadata); export const hrisGroup = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), description: z.string().optional(), parent_id: z.string().optional(), type: z.enum(["TEAM", "GROUP", "DEPARTMENT", "DIVISION", "BUSINESS_UNIT", "BRANCH", "SUB_DEPARTMENT", "PAY_GROUP"]).optional(), user_ids: propertyHrisGroupUserIds.optional(), manager_ids: propertyHrisGroupManagerIds.optional(), is_active: z.boolean().optional(), company_id: z.string().optional(), pay_frequency: z.enum(["ONE_TIME", "DAY", "QUARTER", "YEAR", "HOUR", "MONTH", "WEEK", "BIWEEKLY", "SEMIMONTHLY"]).optional(), next_paid_at: z.string().optional(), metadata: propertyHrisGroupMetadata.optional(), raw: z.record(z.string(), z.unknown()).optional()}); export const propertyHrisEmployeeGroups = z.array(hrisGroup); export const propertyHrisLocationAddress = z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), region_code: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), country_code: z.string().optional()}); export const propertyHrisLocationTelephones = z.array(hrisTelephone); export const propertyHrisLocationMetadata = z.array(hrisMetadata); export const hrisLocation = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), description: z.string().optional(), address: propertyHrisLocationAddress.optional(), parent_id: z.string().optional(), external_identifier: z.string().optional(), telephones: propertyHrisLocationTelephones.optional(), timezone: z.string().optional(), currency: z.string().optional(), language_locale: z.string().optional(), is_active: z.boolean().optional(), is_hq: z.boolean().optional(), company_id: z.string().optional(), metadata: propertyHrisLocationMetadata.optional(), raw: z.record(z.string(), z.unknown()).optional()}); export const propertyHrisEmployeeLocations = z.array(hrisLocation); export const propertyHrisEmployeeMetadata = z.array(hrisMetadata); export const propertyHrisEmployeerelationshipEmails = z.array(hrisEmail); export const propertyHrisEmployeerelationshipTelephones = z.array(hrisTelephone); export const propertyHrisEmployeerelationshipAddress = z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), region_code: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), country_code: z.string().optional()}); export const hrisEmployeerelationship = z.object({name: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), emails: propertyHrisEmployeerelationshipEmails.optional(), telephones: propertyHrisEmployeerelationshipTelephones.optional(), address: propertyHrisEmployeerelationshipAddress.optional(), type: z.enum(["EMERGENCY", "SPOUSE", "CHILD", "PARENT", "SIBLING", "FRIEND", "OTHER"]).optional(), is_dependent: z.boolean().optional(), is_beneficiary: z.boolean().optional(), start_at: z.string().optional(), end_at: z.string().optional()}); export const propertyHrisEmployeeRelationships = z.array(hrisEmployeerelationship); export const hrisEmployee = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), emails: propertyHrisEmployeeEmails.optional(), title: z.string().optional(), job_id: z.string().optional(), manager_id: z.string().optional(), employment_status: z.enum(["ACTIVE", "INACTIVE"]).optional(), gender: z.enum(["MALE", "FEMALE", "INTERSEX", "TRANS", "NON_BINARY"]).optional(), telephones: propertyHrisEmployeeTelephones.optional(), date_of_birth: z.string().optional(), employee_number: z.string().optional(), hired_at: z.string().optional(), terminated_at: z.string().optional(), termination_reason: z.string().optional(), marital_status: z.enum(["MARRIED", "SINGLE"]).optional(), employment_type: z.enum(["FULL_TIME", "PART_TIME", "CONTRACTOR", "INTERN", "CONSULTANT", "VOLUNTEER", "CASUAL", "SEASONAL", "FREELANCE", "OTHER"]).optional(), address: propertyHrisEmployeeAddress.optional(), language_locale: z.string().optional(), currency: z.string().optional(), timezone: z.string().optional(), image_url: z.string().optional(), company_id: z.string().optional(), pronouns: z.string().optional(), employee_roles: propertyHrisEmployeeEmployeeRoles.optional(), compensation: propertyHrisEmployeeCompensation.optional(), salutation: z.string().optional(), bio: z.string().optional(), ssn_sin: z.string().optional(), groups: propertyHrisEmployeeGroups.optional(), locations: propertyHrisEmployeeLocations.optional(), metadata: propertyHrisEmployeeMetadata.optional(), storage_quota_allocated: z.number().optional(), storage_quota_used: z.number().optional(), storage_quota_available: z.number().optional(), relationships: propertyHrisEmployeeRelationships.optional(), has_mfa: z.boolean().optional(), timeoff_days_total: z.number().optional(), timeoff_days_used: z.number().optional(), flsa_status: z.enum(["EXEMPT", "NON_EXEMPT", "SALARIED_NONEXEMPT", "OWNER"]).optional(), pay_frequency: z.enum(["ONE_TIME", "DAY", "QUARTER", "YEAR", "HOUR", "MONTH", "WEEK", "BIWEEKLY", "SEMIMONTHLY"]).optional(), raw: z.record(z.string(), 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 an employee * * PUT /hris/{connection_id}/employee/{id} */ export const updateApiHrisConnectionIdEmployeeId = async (args: UpdateApiHrisConnectionIdEmployeeIdArgs, options?: UpdateApiHrisConnectionIdEmployeeIdOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/hris/${encodeURIComponent(String(args.connection_id))}/employee/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(hrisEmployee, await res.json()) };