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 CommunicationResource1 = {communicationId?: string | undefined, type?: ('STREET_ADDRESS' | 'PO_BOX_ADDRESS' | 'PHONE' | 'MOBILE_PHONE' | 'FAX' | 'EMAIL' | 'PAGER') | undefined, usageType?: ('PERSONAL' | 'BUSINESS' | 'HOME' | 'WORK' | 'LOCATION_STREET_ADDRESS' | 'MAILING_ADDRESS') | undefined, dialCountry?: string | undefined, dialArea?: string | undefined, dialNumber?: string | undefined, dialExtension?: string | undefined, uri?: string | undefined, streetLineOne?: string | undefined, streetLineTwo?: string | undefined, postOfficeBox?: string | undefined, city?: string | undefined, postalCode?: string | undefined, postalCodeExtension?: string | undefined, countrySubdivisionCode?: string | undefined, countryCode?: string | undefined, _links?: Links | undefined}; export type CreateApiWorkersWorkerIdCommunicationsArgs = {workerId: string, body: CommunicationResource1}; export type CreateApiWorkersWorkerIdCommunicationsOptions = {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 communicationResource1 = z.object({communicationId: z.string().optional(), type: z.enum(["STREET_ADDRESS", "PO_BOX_ADDRESS", "PHONE", "MOBILE_PHONE", "FAX", "EMAIL", "PAGER"]).optional(), usageType: z.enum(["PERSONAL", "BUSINESS", "HOME", "WORK", "LOCATION_STREET_ADDRESS", "MAILING_ADDRESS"]).optional(), dialCountry: z.string().optional(), dialArea: z.string().optional(), dialNumber: z.string().optional(), dialExtension: z.string().optional(), uri: z.string().optional(), streetLineOne: z.string().optional(), streetLineTwo: z.string().optional(), postOfficeBox: z.string().optional(), city: z.string().optional(), postalCode: z.string().optional(), postalCodeExtension: z.string().optional(), countrySubdivisionCode: z.string().optional(), countryCode: z.string().optional(), _links: links.optional()}); export const createApiWorkersWorkerIdCommunicationsResponse = z.object({content: communicationResource1.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 Communication * * POST /workers/{workerId}/communications */ export const createApiWorkersWorkerIdCommunications = async (args: CreateApiWorkersWorkerIdCommunicationsArgs, options?: CreateApiWorkersWorkerIdCommunicationsOptions) => { 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))}/communications${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiWorkersWorkerIdCommunicationsResponse, await res.json()) };