import {z} from 'zod' export type CheckLimitResource = {type?: ('NONE:This is the default when no check limits exist' | 'STOPS_AT:This is used to stop when a specific amount is reached' | 'STOPS_AT_NEW_AMOUNT:This is the latest amount that is used to stop when a specific amount is reached' | 'BASED_ON_YTD_CASH_WAGES:This is used to stop when a specific amount is reached within the year against cash wages' | 'AMOUNT_PER_CHECK:This is used to stop when a specific amount is reached on a check') | undefined, startsAt?: string | undefined, stopsAt?: string | undefined, amount?: string | undefined}; export type FrequencyIntervalsResource1 = {interval1?: string | undefined, interval2?: string | undefined}; export type PayComponentFrequencyTypeResource1 = {applied?: string | undefined, occurrence?: string | undefined, occurrenceIntervals?: FrequencyIntervalsResource1 | undefined, effectedChecks?: string | undefined}; export type WorkerPayComponentTransactionsDetails = {transactionId?: string | undefined, date?: string | undefined, amount?: number | undefined}; export type WorkerPayComponentScheduledEntryTransactionsData = {scheduledEntryId?: number | undefined, earliestTransactionDate?: string | undefined, latestTransactionDate?: string | undefined, transactions?: Array | undefined}; export type WorkerPayComponentScheduledEntryData = {id?: number | undefined, workerCalcMethodId?: number | undefined, clientPayrollId?: number | undefined, checkDate?: string | undefined, scheduledAmount?: number | undefined, processedAmount?: number | undefined, sequenceId?: number | undefined, transactionDetails?: WorkerPayComponentScheduledEntryTransactionsData | 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 Links = {[key: string]: Link1}; export type RecurringResource = {workerComponentId?: string | undefined, componentId?: string | undefined, name?: string | undefined, calculationType?: ('FLAT_DOLLAR_AMOUNT:This is used for a specific dollar amount' | 'PERCENTAGE:This is used for when a Percentage will be used to calculate the amount and will need a calculationBaseId to specify what to apply against' | 'RATE_X_UNITS:This is used for apply the rate against units and will need a calculationBaseId to specify what to apply against' | 'RATE_X_HOURS:This is used for apply the rate against hours and will need a calculationBaseId to specify what to apply against.') | undefined, calculationBaseId?: string | undefined, value?: number | undefined, startDate?: string | undefined, effectiveDate?: string | undefined, endDate?: string | undefined, effectOnPay?: string | undefined, classificationType?: string | undefined, checkLimit?: CheckLimitResource | undefined, frequency?: PayComponentFrequencyTypeResource1 | undefined, workerPayCompScheduledEntries?: Array | undefined, transactions?: Array | undefined, _links?: Links | undefined}; export type PatchApiWorkersWorkerIdPaycomponentsArgs = {workerId: string, body: RecurringResource}; export type PatchApiWorkersWorkerIdPaycomponentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const checkLimitResource = z.object({type: z.enum(["NONE:This is the default when no check limits exist", "STOPS_AT:This is used to stop when a specific amount is reached", "STOPS_AT_NEW_AMOUNT:This is the latest amount that is used to stop when a specific amount is reached", "BASED_ON_YTD_CASH_WAGES:This is used to stop when a specific amount is reached within the year against cash wages", "AMOUNT_PER_CHECK:This is used to stop when a specific amount is reached on a check"]).optional(), startsAt: z.string().optional(), stopsAt: z.string().optional(), amount: z.string().optional()}); export const frequencyIntervalsResource1 = z.object({interval1: z.string().optional(), interval2: z.string().optional()}); export const payComponentFrequencyTypeResource1 = z.object({applied: z.string().optional(), occurrence: z.string().optional(), occurrenceIntervals: frequencyIntervalsResource1.optional(), effectedChecks: z.string().optional()}); export const workerPayComponentTransactionsDetails = z.object({transactionId: z.string().optional(), date: z.string().optional(), amount: z.number().optional()}); export const workerPayComponentScheduledEntryTransactionsData = z.object({scheduledEntryId: z.number().int().optional(), earliestTransactionDate: z.string().optional(), latestTransactionDate: z.string().optional(), transactions: z.array(workerPayComponentTransactionsDetails).optional()}); export const workerPayComponentScheduledEntryData = z.object({id: z.number().int().optional(), workerCalcMethodId: z.number().int().optional(), clientPayrollId: z.number().int().optional(), checkDate: z.string().optional(), scheduledAmount: z.number().optional(), processedAmount: z.number().optional(), sequenceId: z.number().int().optional(), transactionDetails: workerPayComponentScheduledEntryTransactionsData.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 links = z.record(z.string(), link1); export const recurringResource = z.object({workerComponentId: z.string().optional(), componentId: z.string().optional(), name: z.string().optional(), calculationType: z.enum(["FLAT_DOLLAR_AMOUNT:This is used for a specific dollar amount", "PERCENTAGE:This is used for when a Percentage will be used to calculate the amount and will need a calculationBaseId to specify what to apply against", "RATE_X_UNITS:This is used for apply the rate against units and will need a calculationBaseId to specify what to apply against", "RATE_X_HOURS:This is used for apply the rate against hours and will need a calculationBaseId to specify what to apply against."]).optional(), calculationBaseId: z.string().optional(), value: z.number().optional(), startDate: z.string().optional(), effectiveDate: z.string().optional(), endDate: z.string().optional(), effectOnPay: z.string().optional(), classificationType: z.string().optional(), checkLimit: checkLimitResource.optional(), frequency: payComponentFrequencyTypeResource1.optional(), workerPayCompScheduledEntries: z.array(workerPayComponentScheduledEntryData).optional(), transactions: z.array(workerPayComponentTransactionsDetails).optional(), _links: links.optional()}); export const patchApiWorkersWorkerIdPaycomponentsResponse = z.object({content: recurringResource.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 Components * * PATCH /workers/{workerId}/paycomponents */ export const patchApiWorkersWorkerIdPaycomponents = async (args: PatchApiWorkersWorkerIdPaycomponentsArgs, options?: PatchApiWorkersWorkerIdPaycomponentsOptions) => { 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))}/paycomponents${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(patchApiWorkersWorkerIdPaycomponentsResponse, await res.json()) };