import {z} from 'zod' export type CustomEmploymentTypeResource1 = {customEmploymentTypeId?: string | undefined, customEmploymentTypeName?: string | undefined}; export type NameResource1 = {familyName?: string | undefined, middleName?: string | undefined, givenName?: string | undefined, preferredName?: string | undefined, preferredLastName?: string | undefined, pronoun?: string | undefined, qualificationAffixCode?: string | undefined, titleAffixCode?: string | undefined}; export type LegalIdResource1 = {legalIdType?: ('SSN' | 'FEIN') | undefined, legalIdValue?: string | undefined}; export type JobTitleResource1 = {jobTitleId?: string | undefined, title?: string | undefined}; export type Link1 = {href?: string | undefined, hreflang?: string | undefined, title?: string | undefined, type?: string | undefined, deprecation?: string | undefined, profile?: string | undefined, name?: string | undefined, templated?: boolean | undefined}; export type OrganizationResource1 = {organizationId?: string | undefined, name?: string | undefined, number?: string | undefined, level?: string | undefined, _links?: Array | undefined}; export type SupervisorResource1 = {workerId?: string | undefined, name?: NameResource1 | undefined}; export type Links = {[key: string]: Link1}; export type Status1 = {workerStatusId?: string | undefined, statusType?: ('ACTIVE' | 'INACTIVE' | 'TERMINATED' | 'PENDING' | 'IN_PROGRESS') | undefined, statusReason?: string | undefined, effectiveDate?: string | undefined, order?: number | undefined, _links?: Links | undefined}; export type CommunicationResource1 = {communicationId?: string | undefined, type?: ('STREET_ADDRESS' | 'PO_BOX_ADDRESS' | 'PHONE' | 'MOBILE_PHONE' | 'FAX' | 'EMAIL' | 'PAGER') | undefined, usageType?: ('PERSONAL' | 'BUSINESS' | 'HOME' | 'WORK' | 'LOCATION_STREET_ADDRESS' | 'MAILING_ADDRESS') | undefined, dialCountry?: string | undefined, dialArea?: string | undefined, dialNumber?: string | undefined, dialExtension?: string | undefined, uri?: string | undefined, streetLineOne?: string | undefined, streetLineTwo?: string | undefined, postOfficeBox?: string | undefined, city?: string | undefined, postalCode?: string | undefined, postalCodeExtension?: string | undefined, countrySubdivisionCode?: string | undefined, countryCode?: string | undefined, _links?: Links | undefined}; export type WorkerResourceV2 = {workerId?: string | undefined, employeeId?: string | undefined, workerType?: ('EMPLOYEE' | 'CONTRACTOR' | 'INDEPENDENT_CONTRACTOR') | undefined, employmentType?: ('FULL_TIME' | 'PART_TIME') | undefined, customEmploymentType?: CustomEmploymentTypeResource1 | undefined, exemptionType?: ('EXEMPT' | 'NON_EXEMPT') | undefined, workState?: string | undefined, birthDate?: string | undefined, sex?: ('MALE' | 'FEMALE' | 'NOT_SPECIFIED') | undefined, ethnicityCode?: string | undefined, hireDate?: string | undefined, clockId?: string | undefined, name?: NameResource1 | undefined, seniorityDate?: string | undefined, profileImageURL?: string | undefined, legalId?: LegalIdResource1 | undefined, laborAssignmentId?: string | undefined, locationId?: string | undefined, jobId?: string | undefined, job?: JobTitleResource1 | undefined, organization?: OrganizationResource1 | undefined, supervisor?: SupervisorResource1 | undefined, currentStatus?: Status1 | undefined, communications?: Array | undefined, _links?: Links | undefined, workerCorrelationId?: string | undefined}; export type PatchApiWorkersWorkerIdArgs = {workerId: string, body: WorkerResourceV2}; export type PatchApiWorkersWorkerIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const customEmploymentTypeResource1 = z.object({customEmploymentTypeId: z.string().optional(), customEmploymentTypeName: z.string().optional()}); export const nameResource1 = z.object({familyName: z.string().optional(), middleName: z.string().optional(), givenName: z.string().optional(), preferredName: z.string().optional(), preferredLastName: z.string().optional(), pronoun: z.string().optional(), qualificationAffixCode: z.string().optional(), titleAffixCode: z.string().optional()}); export const legalIdResource1 = z.object({legalIdType: z.enum(["SSN", "FEIN"]).optional(), legalIdValue: z.string().optional()}); export const jobTitleResource1 = z.object({jobTitleId: z.string().optional(), title: z.string().optional()}); export const link1 = z.object({href: z.string().optional(), hreflang: z.string().optional(), title: z.string().optional(), type: z.string().optional(), deprecation: z.string().optional(), profile: z.string().optional(), name: z.string().optional(), templated: z.boolean().optional()}); export const organizationResource1 = z.object({organizationId: z.string().optional(), name: z.string().optional(), number: z.string().optional(), level: z.string().optional(), _links: z.array(link1).optional()}); export const supervisorResource1 = z.object({workerId: z.string().optional(), name: nameResource1.optional()}); export const links = z.record(z.string(), link1); export const status1 = z.object({workerStatusId: z.string().optional(), statusType: z.enum(["ACTIVE", "INACTIVE", "TERMINATED", "PENDING", "IN_PROGRESS"]).optional(), statusReason: z.string().optional(), effectiveDate: z.string().optional(), order: z.number().int().optional(), _links: links.optional()}); export const communicationResource1 = z.object({communicationId: z.string().optional(), type: z.enum(["STREET_ADDRESS", "PO_BOX_ADDRESS", "PHONE", "MOBILE_PHONE", "FAX", "EMAIL", "PAGER"]).optional(), usageType: z.enum(["PERSONAL", "BUSINESS", "HOME", "WORK", "LOCATION_STREET_ADDRESS", "MAILING_ADDRESS"]).optional(), dialCountry: z.string().optional(), dialArea: z.string().optional(), dialNumber: z.string().optional(), dialExtension: z.string().optional(), uri: z.string().optional(), streetLineOne: z.string().optional(), streetLineTwo: z.string().optional(), postOfficeBox: z.string().optional(), city: z.string().optional(), postalCode: z.string().optional(), postalCodeExtension: z.string().optional(), countrySubdivisionCode: z.string().optional(), countryCode: z.string().optional(), _links: links.optional()}); export const workerResourceV2 = z.object({workerId: z.string().optional(), employeeId: z.string().optional(), workerType: z.enum(["EMPLOYEE", "CONTRACTOR", "INDEPENDENT_CONTRACTOR"]).optional(), employmentType: z.enum(["FULL_TIME", "PART_TIME"]).optional(), customEmploymentType: customEmploymentTypeResource1.optional(), exemptionType: z.enum(["EXEMPT", "NON_EXEMPT"]).optional(), workState: z.string().optional(), birthDate: z.string().optional(), sex: z.enum(["MALE", "FEMALE", "NOT_SPECIFIED"]).optional(), ethnicityCode: z.string().optional(), hireDate: z.string().optional(), clockId: z.string().optional(), name: nameResource1.optional(), seniorityDate: z.string().optional(), profileImageURL: z.string().optional(), legalId: legalIdResource1.optional(), laborAssignmentId: z.string().optional(), locationId: z.string().optional(), jobId: z.string().optional(), job: jobTitleResource1.optional(), organization: organizationResource1.optional(), supervisor: supervisorResource1.optional(), currentStatus: status1.optional(), communications: z.array(communicationResource1).optional(), _links: links.optional(), workerCorrelationId: z.string().optional()}); export const patchApiWorkersWorkerIdResponse = z.object({content: workerResourceV2.optional(), links: z.array(link1).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 }; /** * Worker * * PATCH /workers/{workerId} */ export const patchApiWorkersWorkerId = async (args: PatchApiWorkersWorkerIdArgs, options?: PatchApiWorkersWorkerIdOptions) => { const {baseUrl = "https://api.paychex.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/workers/${encodeURIComponent(String(args.workerId))}${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(patchApiWorkersWorkerIdResponse, await res.json()) };