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 DirectDepositResourceV2 = {directDepositId?: string | undefined, startDate?: string | undefined, paymentType?: ('FLAT_DOLLAR_AMOUNT' | 'PERCENTAGE' | 'REMAINDER') | undefined, accountType?: ('CHECKING' | 'SAVINGS') | undefined, value?: number | undefined, routingNumber?: string | undefined, accountNumber?: string | undefined, priority?: string | undefined, _links?: Links | undefined}; export type PatchApiWorkersWorkerIdDirectdepositsArgs = {workerId: string, effectivitydate?: string | undefined, body: Array}; export type PatchApiWorkersWorkerIdDirectdepositsOptions = {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 directDepositResourceV2 = z.object({directDepositId: z.string().optional(), startDate: z.string().optional(), paymentType: z.enum(["FLAT_DOLLAR_AMOUNT", "PERCENTAGE", "REMAINDER"]).optional(), accountType: z.enum(["CHECKING", "SAVINGS"]).optional(), value: z.number().optional(), routingNumber: z.string().optional(), accountNumber: z.string().optional(), priority: z.string().optional(), _links: links.optional()}); export const patchApiWorkersWorkerIdDirectdepositsResponse = z.object({content: directDepositResourceV2.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 Direct Deposits * * PATCH /workers/{workerId}/directdeposits */ export const patchApiWorkersWorkerIdDirectdeposits = async (args: PatchApiWorkersWorkerIdDirectdepositsArgs, options?: PatchApiWorkersWorkerIdDirectdepositsOptions) => { 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") if (args.effectivitydate != null) query.append("effectivitydate", String(args.effectivitydate)) const url = `${baseUrl.replace(/\/+$/, '')}/workers/${encodeURIComponent(String(args.workerId))}/directdeposits${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(patchApiWorkersWorkerIdDirectdepositsResponse, await res.json()) };