import {z} from 'zod' export type StateTaxFieldsDescription = {countrySubdivisionCode?: string | undefined, stateAllocationPercent?: string | undefined, isResidentState?: string | undefined, taxStatusType?: string | undefined, filingStatusType?: string | undefined, additionalAmount?: number | undefined, additionalPercent?: number | undefined, flatDollarOverride?: number | undefined, overridePercent?: number | undefined}; export type PatchApiWorkersWorkerIdStatetaxesArgs = {workerId: string, body: StateTaxFieldsDescription}; export type PatchApiWorkersWorkerIdStatetaxesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const workerTaxDeductionResponse = z.object({workerTaxDeductionId: z.object({}).optional(), workerTaxDeductionName: z.string().optional(), amount: z.number().int().optional(), quantity: z.number().optional()}); export const stateTaxResponse = z.object({workerTaxId: z.string().optional(), countrySubdivisionCode: z.string().optional(), isResidentState: z.boolean().optional(), stateAllocationPercent: z.number().int().optional(), regulationType: z.string().optional(), taxStatusType: z.string().optional(), filingStatusType: z.string().optional(), additionalAmount: z.number().optional(), additionalPercent: z.number().optional(), overridePercent: z.number().optional(), flatDollarOverride: z.number().optional(), exemptionReasonDescription: z.string().optional(), workerTaxDeductions: z.array(workerTaxDeductionResponse).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 patchApiWorkersWorkerIdStatetaxesResponse = z.object({content: stateTaxResponse.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 State Tax * * PATCH /workers/{workerId}/statetaxes */ export const patchApiWorkersWorkerIdStatetaxes = async (args: PatchApiWorkersWorkerIdStatetaxesArgs, options?: PatchApiWorkersWorkerIdStatetaxesOptions) => { const {baseUrl = "https://api.paychex.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json-patch+json") headers.set('accept', "application/json-patch+json") const url = `${baseUrl.replace(/\/+$/, '')}/workers/${encodeURIComponent(String(args.workerId))}/statetaxes${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(patchApiWorkersWorkerIdStatetaxesResponse, await res.json()) };