import {z} from 'zod' export type UpdateApiApiV1CompensationBenchmarksArgs = {body: {id: string, currencyCode: string, mjlJobCode?: string | undefined, benchmarkValue: number, benchmarkMin: number, benchmarkMax: number, benchmarkSource?: string | undefined, externalJobTitle?: string | undefined, externalLocation?: string | undefined, externalLevel?: string | undefined, externalJobDescription?: string | undefined, companiesSurveyed?: number | undefined, employeesSurveyed?: number | undefined, sourceId?: string | undefined, sourceDate?: string | undefined, dataYear?: string | undefined, externalCountry?: string | undefined, externalSecondaryLocation?: string | undefined, externalCompanySize?: string | undefined, externalIndustry?: string | undefined}}; export type UpdateApiApiV1CompensationBenchmarksOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiV1CompensationBenchmarksResponse = z.object({savedBenchmark: z.object({id: z.string().optional(), jobTitleId: z.string().optional(), jobLocationId: z.string().nullable().optional(), mercerJobCode: z.string().nullable().optional(), benchmarkSource: z.string().nullable().optional(), currencyCode: z.string().nullable().optional(), benchmarkValue: z.number().nullable().optional(), benchmarkMin: z.number().nullable().optional(), benchmarkMax: z.number().nullable().optional(), externalJobTitle: z.string().nullable().optional(), externalLocation: z.string().nullable().optional(), externalLevel: z.string().nullable().optional(), externalJobDescription: z.string().nullable().optional(), companiesSurveyed: z.number().int().nullable().optional(), employeesSurveyed: z.number().int().nullable().optional(), sourceId: z.string().nullable().optional(), sourceDate: z.string().nullable().optional(), dataYear: z.string().nullable().optional(), externalCountry: z.string().nullable().optional(), externalSecondaryLocation: z.string().nullable().optional(), externalCompanySize: z.string().nullable().optional(), externalIndustry: z.string().nullable().optional()}).optional(), message: z.string().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 }; /** * Update Compensation Benchmark * * PUT /api/v1/compensation/benchmarks */ export const updateApiApiV1CompensationBenchmarks = async (args: UpdateApiApiV1CompensationBenchmarksArgs, options?: UpdateApiApiV1CompensationBenchmarksOptions) => { const {baseUrl = "https://companySubDomain.bamboohr.com", fetch: fetchFn = fetch, oauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth !== undefined) headers.set('authorization', `Bearer ${oauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/compensation/benchmarks${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV1CompensationBenchmarksResponse, await res.json()) };