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 Links = {[key: string]: Link1}; export type PayRateResource = {rateId?: string | undefined, startDate?: string | undefined, rateNumber?: string | undefined, rateType?: ('ANNUAL_SALARY' | 'PER_PAY_PERIOD_SALARY' | 'PIECEWORK_RATE' | 'DAILY_RATE' | 'HOURLY_RATE') | undefined, description?: string | undefined, amount?: string | undefined, standardHours?: string | undefined, standardOvertime?: string | undefined, default?: boolean | undefined, effectiveDate?: string | undefined, _links?: Links | undefined}; export type PatchApiWorkersWorkerIdCompensationPayratesRateIdArgs = {workerId: string, rateId: string, body: PayRateResource}; export type PatchApiWorkersWorkerIdCompensationPayratesRateIdOptions = {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 links = z.record(z.string(), link1); export const payRateResource = z.object({rateId: z.string().optional(), startDate: z.string().optional(), rateNumber: z.string().optional(), rateType: z.enum(["ANNUAL_SALARY", "PER_PAY_PERIOD_SALARY", "PIECEWORK_RATE", "DAILY_RATE", "HOURLY_RATE"]).optional(), description: z.string().optional(), amount: z.string().optional(), standardHours: z.string().optional(), standardOvertime: z.string().optional(), default: z.boolean().optional(), effectiveDate: z.string().optional(), _links: links.optional()}); export const patchApiWorkersWorkerIdCompensationPayratesRateIdResponse = z.object({content: payRateResource.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 Pay Rate * * PATCH /workers/{workerId}/compensation/payrates/{rateId} */ export const patchApiWorkersWorkerIdCompensationPayratesRateId = async (args: PatchApiWorkersWorkerIdCompensationPayratesRateIdArgs, options?: PatchApiWorkersWorkerIdCompensationPayratesRateIdOptions) => { 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))}/compensation/payrates/${encodeURIComponent(String(args.rateId))}${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(patchApiWorkersWorkerIdCompensationPayratesRateIdResponse, await res.json()) };