import {z} from 'zod' export type TimeTrackingUpdateTimeTrackingBreakV1 = {name?: string | undefined, policyId?: string | undefined, paid?: boolean | undefined, duration?: number | undefined, availabilityType?: ('anytime' | 'hours_worked' | 'time_of_day') | undefined, availabilityMinHoursWorked?: (number | null) | undefined, availabilityMaxHoursWorked?: (number | null) | undefined, availabilityStartTime?: (string | null) | undefined, availabilityEndTime?: (string | null) | undefined}; export type PatchApiApiV1TimeTrackingBreaksIdArgs = {id: string, body: TimeTrackingUpdateTimeTrackingBreakV1}; export type PatchApiApiV1TimeTrackingBreaksIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const timeTrackingTimeTrackingBreakV1 = z.object({id: z.string().optional(), name: z.string().optional(), policyId: z.string().optional(), paid: z.boolean().optional(), duration: z.number().int().optional(), availabilityType: z.enum(["anytime", "hours_worked", "time_of_day"]).optional(), availabilityMinHoursWorked: z.number().nullable().optional(), availabilityMaxHoursWorked: z.number().nullable().optional(), availabilityStartTime: z.string().nullable().optional(), availabilityEndTime: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: 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 Break * * PATCH /api/v1/time-tracking/breaks/{id} * * Also accepts auth: oauth */ export const patchApiApiV1TimeTrackingBreaksId = async (args: PatchApiApiV1TimeTrackingBreaksIdArgs, options?: PatchApiApiV1TimeTrackingBreaksIdOptions) => { 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/breaks/${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(timeTrackingTimeTrackingBreakV1, await res.json()) };