import {z} from 'zod' export type UpdateApiApiV1CompensationEquitySettingsArgs = {body: {calculationType?: string | undefined, companyValuation?: (number | null) | undefined, outstandingShares?: (number | null) | undefined, pricePerShare?: (number | null) | undefined, currencyCode?: string | undefined, sliderMin?: (number | null) | undefined, sliderMax?: (number | null) | undefined, vestingConditions?: (string | null) | undefined, disclaimers?: (string | null) | undefined} | {[key: string]: unknown}}; export type UpdateApiApiV1CompensationEquitySettingsOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiV1CompensationEquitySettingsResponse = z.object({calculationType: z.string().optional(), companyValuation: z.number().nullable().optional(), outstandingShares: z.number().int().nullable().optional(), pricePerShare: z.number().nullable().optional(), currencyCode: z.string().optional(), sliderMin: z.number().int().nullable().optional(), sliderMax: z.number().int().nullable().optional(), vestingConditions: z.string().nullable().optional(), disclaimers: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); 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 company equity settings * * PUT /api/v1/compensation/equity/settings */ export const updateApiApiV1CompensationEquitySettings = async (args: UpdateApiApiV1CompensationEquitySettingsArgs, options?: UpdateApiApiV1CompensationEquitySettingsOptions) => { 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/equity/settings${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(updateApiApiV1CompensationEquitySettingsResponse, await res.json()) };