import {z} from 'zod' export type Link = {rel?: string | undefined, href?: string | undefined, hreflang?: string | undefined, media?: string | undefined, title?: string | undefined, type?: string | undefined, deprecation?: string | undefined, profile?: string | undefined, name?: string | undefined}; export type CustomFieldsDropdownResource = {dropdownId?: string | undefined, dropdownValue?: string | undefined, dropdownDefault?: boolean | undefined}; export type CustomFieldsResource = {customFieldId?: string | undefined, customFieldName?: string | undefined, categoryId?: string | undefined, required?: boolean | undefined, checkStub?: boolean | undefined, employeeEditable?: boolean | undefined, type?: ('DROPDOWN' | 'TEXT' | 'BOOLEAN' | 'DATE' | 'NUMERIC, NUMERIC__0_00_ OR NUMERIC__0_0000_') | undefined, booleanValue?: boolean | undefined, links?: Array | undefined, dateValue?: string | undefined, textValue?: string | undefined, maxTextLength?: number | undefined, numericValue?: number | undefined, dropdown?: Array | undefined}; export type PatchApiCompaniesCompanyIdCustomfieldsCustomfieldidArgs = {companyId: string, customfieldid: string, body: CustomFieldsResource}; export type PatchApiCompaniesCompanyIdCustomfieldsCustomfieldidOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({rel: z.string().optional(), href: z.string().optional(), hreflang: z.string().optional(), media: z.string().optional(), title: z.string().optional(), type: z.string().optional(), deprecation: z.string().optional(), profile: z.string().optional(), name: z.string().optional()}); export const customFieldsDropdownResource = z.object({dropdownId: z.string().optional(), dropdownValue: z.string().optional(), dropdownDefault: z.boolean().optional()}); export const customFieldsResource = z.object({customFieldId: z.string().optional(), customFieldName: z.string().optional(), categoryId: z.string().optional(), required: z.boolean().optional(), checkStub: z.boolean().optional(), employeeEditable: z.boolean().optional(), type: z.enum(["DROPDOWN", "TEXT", "BOOLEAN", "DATE", "NUMERIC, NUMERIC__0_00_ OR NUMERIC__0_0000_"]).optional(), booleanValue: z.boolean().optional(), links: z.array(link).optional(), dateValue: z.string().optional(), textValue: z.string().optional(), maxTextLength: z.number().optional(), numericValue: z.number().optional(), dropdown: z.array(customFieldsDropdownResource).optional()}); export const patchApiCompaniesCompanyIdCustomfieldsCustomfieldidResponse = z.object({content: customFieldsResource.optional(), links: z.array(link).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 }; /** * Custom Field * * PATCH /companies/{companyId}/customfields/{customfieldid} */ export const patchApiCompaniesCompanyIdCustomfieldsCustomfieldid = async (args: PatchApiCompaniesCompanyIdCustomfieldsCustomfieldidArgs, options?: PatchApiCompaniesCompanyIdCustomfieldsCustomfieldidOptions) => { const {baseUrl = "https://api.paychex.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.paychex.company.customfield.v1+json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companyId))}/customfields/${encodeURIComponent(String(args.customfieldid))}${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(patchApiCompaniesCompanyIdCustomfieldsCustomfieldidResponse, await res.json()) };