import {z} from 'zod' 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 PayComponentResource1 = {componentId?: string | undefined, checkComponentId?: string | undefined, name?: string | undefined, classificationType?: string | undefined, description?: string | undefined, effectOnPay?: ('ADDITION' | 'ADDITION_WITH_IN_OUT' | 'EMPLOYER_INFORMATIONAL' | 'REDUCTION') | undefined, startDate?: string | undefined, endDate?: string | undefined, jobId?: string | undefined, laborAssignmentId?: string | undefined, payRateId?: string | undefined, payRate?: string | undefined, payHours?: string | undefined, payUnits?: string | undefined, payAmount?: string | undefined, organization?: OrganizationResource1 | undefined, lineDate?: string | undefined, memoed?: boolean | undefined}; export type CheckResource1 = {workerId?: string | undefined, paycheckId?: string | undefined, payPeriodId?: string | undefined, checkCorrelationId?: string | undefined, blockAutoDistribution?: boolean | undefined, earnings?: Array | undefined, deductions?: Array | undefined, informational?: Array | undefined, taxes?: Array | undefined}; export type CreateApiWorkersWorkerIdChecksArgs = {workerId: string, body: CheckResource1}; export type CreateApiWorkersWorkerIdChecksOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; 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 payComponentResource1 = z.object({componentId: z.string().optional(), checkComponentId: z.string().optional(), name: z.string().optional(), classificationType: z.string().optional(), description: z.string().optional(), effectOnPay: z.enum(["ADDITION", "ADDITION_WITH_IN_OUT", "EMPLOYER_INFORMATIONAL", "REDUCTION"]).optional(), startDate: z.string().optional(), endDate: z.string().optional(), jobId: z.string().optional(), laborAssignmentId: z.string().optional(), payRateId: z.string().optional(), payRate: z.string().optional(), payHours: z.string().optional(), payUnits: z.string().optional(), payAmount: z.string().optional(), organization: organizationResource1.optional(), lineDate: z.string().optional(), memoed: z.boolean().optional()}); export const checkResource1 = z.object({workerId: z.string().optional(), paycheckId: z.string().optional(), payPeriodId: z.string().optional(), checkCorrelationId: z.string().optional(), blockAutoDistribution: z.boolean().optional(), earnings: z.array(payComponentResource1).optional(), deductions: z.array(payComponentResource1).optional(), informational: z.array(payComponentResource1).optional(), taxes: z.array(payComponentResource1).optional()}); export const createApiWorkersWorkerIdChecksResponse = z.object({content: checkResource1.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 Check * * POST /workers/{workerId}/checks */ export const createApiWorkersWorkerIdChecks = async (args: CreateApiWorkersWorkerIdChecksArgs, options?: CreateApiWorkersWorkerIdChecksOptions) => { 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))}/checks${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(createApiWorkersWorkerIdChecksResponse, await res.json()) };