import {z} from 'zod' export type GetApiWorkersWorkerIdPaycomponentsWorkerComponentIdArgs = {workerId: string, workerComponentId: string, asof?: string | undefined}; export type GetApiWorkersWorkerIdPaycomponentsWorkerComponentIdOptions = {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 getApiWorkersWorkerIdPaycomponentsWorkerComponentIdResponse = 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 Component * * GET /workers/{workerId}/paycomponents/{workerComponentId} */ export const getApiWorkersWorkerIdPaycomponentsWorkerComponentId = async (args: GetApiWorkersWorkerIdPaycomponentsWorkerComponentIdArgs, options?: GetApiWorkersWorkerIdPaycomponentsWorkerComponentIdOptions) => { const {baseUrl = "https://api.paychex.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.asof != null) query.append("asof", String(args.asof)) const url = `${baseUrl.replace(/\/+$/, '')}/workers/${encodeURIComponent(String(args.workerId))}/paycomponents/${encodeURIComponent(String(args.workerComponentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiWorkersWorkerIdPaycomponentsWorkerComponentIdResponse, await res.json()) };