import {z} from 'zod' export type NameResource = {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 LegalIdResource = {legalIdType?: ('SSN' | 'FEIN') | undefined, legalIdValue?: string | undefined}; export type Link = {rel?: string | undefined, href?: string | undefined, hreflang?: string | undefined, media?: string | undefined, title?: string | undefined, type?: string | undefined, deprecation?: string | undefined, profile?: string | undefined, name?: string | undefined}; export type JobTitleResource = {jobTitleId?: string | undefined, title?: string | undefined, startDate?: string | undefined, endDate?: string | undefined, links?: Array | undefined}; export type OrganizationResource = {organizationId?: string | undefined, name?: string | undefined, number?: string | undefined, level?: string | undefined, links?: Array | undefined}; export type SupervisorResource = {workerId?: string | undefined, name?: NameResource | undefined}; export type Status = {workerStatusId?: string | undefined, statusType?: ('ACTIVE' | 'INACTIVE' | 'TERMINATED' | 'PENDING' | 'IN_PROGRESS') | undefined, statusReason?: string | undefined}; export type CommunicationResource = {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}; export type WorkerResource = {workerId?: string | undefined, employeeId?: string | undefined, workerType?: ('EMPLOYEE' | 'CONTRACTOR' | 'INDEPENDENT_CONTRACTOR') | undefined, employmentType?: ('FULL_TIME' | 'PART_TIME') | undefined, exemptionType?: ('EXEMPT' | 'NON_EXEMPT') | undefined, birthDate?: string | undefined, sex?: ('MALE' | 'FEMALE' | 'NOT_SPECIFIED') | undefined, ethnicityCode?: ('(blank)' | 'HISPANIC_OR_LATINO' | 'WHITE_NOT_OF_HISPANIC_ORIGIN' | 'BLACK_OR_AFRICAN_AMERICAN' | 'NATIVE_HAWAIIAN_OR_OTHER_PACIFIC_ISLAND' | 'ASIAN' | 'AMERICAN_INDIAN_OR_ALASKAN_NATIVE' | 'TWO_OR_MORE_RACES' | 'PREFER_NOT_TO_ANSWER') | undefined, hireDate?: string | undefined, clockId?: string | undefined, name?: NameResource | undefined, seniorityDate?: string | undefined, profileImageURL?: string | undefined, legalId?: LegalIdResource | undefined, laborAssignmentId?: string | undefined, jobId?: string | undefined, locationId?: string | undefined, job?: JobTitleResource | undefined, organization?: OrganizationResource | undefined, supervisor?: SupervisorResource | undefined, currentStatus?: Status | undefined, communications?: Array | undefined, workerCorrelationId?: string | undefined}; export type CreateApiCompaniesCompanyIdWorkersArgs = {companyId: string, body: WorkerResource}; export type CreateApiCompaniesCompanyIdWorkersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const nameResource = 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 legalIdResource = z.object({legalIdType: z.enum(["SSN", "FEIN"]).optional(), legalIdValue: z.string().optional()}); export const link = z.object({rel: z.string().optional(), href: z.string().optional(), hreflang: z.string().optional(), media: z.string().optional(), title: z.string().optional(), type: z.string().optional(), deprecation: z.string().optional(), profile: z.string().optional(), name: z.string().optional()}); export const jobTitleResource = z.object({jobTitleId: z.string().optional(), title: z.string().optional(), startDate: z.string().optional(), endDate: z.string().optional(), links: z.array(link).optional()}); export const organizationResource = z.object({organizationId: z.string().optional(), name: z.string().optional(), number: z.string().optional(), level: z.string().optional(), links: z.array(link).optional()}); export const supervisorResource = z.object({workerId: z.string().optional(), name: nameResource.optional()}); export const status = z.object({workerStatusId: z.string().optional(), statusType: z.enum(["ACTIVE", "INACTIVE", "TERMINATED", "PENDING", "IN_PROGRESS"]).optional(), statusReason: z.string().optional()}); export const communicationResource = 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()}); export const workerResource = 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(), exemptionType: z.enum(["EXEMPT", "NON_EXEMPT"]).optional(), birthDate: z.string().optional(), sex: z.enum(["MALE", "FEMALE", "NOT_SPECIFIED"]).optional(), ethnicityCode: z.enum(["(blank)", "HISPANIC_OR_LATINO", "WHITE_NOT_OF_HISPANIC_ORIGIN", "BLACK_OR_AFRICAN_AMERICAN", "NATIVE_HAWAIIAN_OR_OTHER_PACIFIC_ISLAND", "ASIAN", "AMERICAN_INDIAN_OR_ALASKAN_NATIVE", "TWO_OR_MORE_RACES", "PREFER_NOT_TO_ANSWER"]).optional(), hireDate: z.string().optional(), clockId: z.string().optional(), name: nameResource.optional(), seniorityDate: z.string().optional(), profileImageURL: z.string().optional(), legalId: legalIdResource.optional(), laborAssignmentId: z.string().optional(), jobId: z.string().optional(), locationId: z.string().optional(), job: jobTitleResource.optional(), organization: organizationResource.optional(), supervisor: supervisorResource.optional(), currentStatus: status.optional(), communications: z.array(communicationResource).optional(), workerCorrelationId: z.string().optional()}); export const createApiCompaniesCompanyIdWorkersResponse = z.object({content: workerResource.optional(), links: z.array(link).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 }; /** * In Progress Workers * * POST /companies/{companyId}/workers */ export const createApiCompaniesCompanyIdWorkers = async (args: CreateApiCompaniesCompanyIdWorkersArgs, options?: CreateApiCompaniesCompanyIdWorkersOptions) => { const {baseUrl = "https://api.paychex.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.paychex.workers.v1+json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companyId))}/workers${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiCompaniesCompanyIdWorkersResponse, await res.json()) };