import {z} from 'zod' export type GetApiApiV1CompensationPlanningCyclesIdChangeCommArgs = {id: number}; export type GetApiApiV1CompensationPlanningCyclesIdChangeCommOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1CompensationPlanningCyclesIdChangeCommResponse = z.object({changeCommunicationMessageText: z.string().nullable().optional(), changeCommunicationSubjectText: z.string().nullable().optional(), cycleStatus: z.string().nullable().optional(), variablePlaceholders: z.record(z.string(), z.object({name: z.string().optional(), example: z.string().optional()})).optional(), hasSections: z.boolean().optional(), sections: z.array(z.object({sectionKey: z.enum(["introduction", "salary", "bonus", "equity", "closing"]).optional(), body: z.string().optional(), sortOrder: z.number().int().optional(), audience: z.enum(["all", "eligible"]).optional(), isActive: z.boolean().optional()})).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 }; /** * Get change communication letter details * * GET /api/v1/compensation/planning_cycles/{id}/change_comm */ export const getApiApiV1CompensationPlanningCyclesIdChangeComm = async (args: GetApiApiV1CompensationPlanningCyclesIdChangeCommArgs, options?: GetApiApiV1CompensationPlanningCyclesIdChangeCommOptions) => { const {baseUrl = "https://companySubDomain.bamboohr.com", fetch: fetchFn = fetch, oauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (oauth !== undefined) headers.set('authorization', `Bearer ${oauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/compensation/planning_cycles/${encodeURIComponent(String(args.id))}/change_comm${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1CompensationPlanningCyclesIdChangeCommResponse, await res.json()) };