import {z} from 'zod' export type ShiftDifferentialUpdateTimeTrackingShiftDifferentialV1 = {name?: string | undefined, rate?: string | undefined, rateType?: ('AMOUNT' | 'PERCENT') | undefined, allowAllEmployees?: boolean | undefined, employeeIds?: Array | undefined, times?: (Array<{startDay: 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY', endDay: 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY', start: string, end: string}>) | undefined, archived?: boolean | undefined}; export type PatchApiApiV1TimeTrackingShiftDifferentialsIdArgs = {id: number, body: ShiftDifferentialUpdateTimeTrackingShiftDifferentialV1}; export type PatchApiApiV1TimeTrackingShiftDifferentialsIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const shiftDifferentialTimeTrackingShiftDifferentialTimeV1 = z.object({id: z.number().int().optional(), startDay: z.enum(["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]).optional(), endDay: z.enum(["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]).optional(), start: z.string().optional(), end: z.string().optional()}); export const shiftDifferentialTimeTrackingShiftDifferentialV1 = z.object({id: z.number().int().optional(), name: z.string().max(50).optional(), rate: z.string().optional(), rateType: z.enum(["AMOUNT", "PERCENT"]).optional(), allowAllEmployees: z.boolean().optional(), times: z.array(shiftDifferentialTimeTrackingShiftDifferentialTimeV1).optional(), employeeIds: z.array(z.number().int()).optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), archivedAt: z.string().nullable().optional(), deletedAt: z.string().nullable().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 Time Tracking Shift Differential * * PATCH /api/v1/time-tracking/shift-differentials/{id} * * Also accepts auth: oauth */ export const patchApiApiV1TimeTrackingShiftDifferentialsId = async (args: PatchApiApiV1TimeTrackingShiftDifferentialsIdArgs, options?: PatchApiApiV1TimeTrackingShiftDifferentialsIdOptions) => { const {baseUrl = "https://companySubDomain.bamboohr.com", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/time-tracking/shift-differentials/${encodeURIComponent(String(args.id))}${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(shiftDifferentialTimeTrackingShiftDifferentialV1, await res.json()) };