import {z} from 'zod' export type PutV2AttendanceSchedulesAttendanceScheduleId = {start_date?: string | undefined, start_time?: string | undefined, use_time_zone?: ('organization' | 'user') | undefined, duration?: number | undefined, minimum_time?: number | undefined, repeat_schedule?: ('never' | 'weekly' | 'bi_weekly') | undefined, repeat_until?: string | undefined, weekdays?: (Array<'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'>) | undefined, excluded_dates?: Array | undefined, add_excluded_dates?: Array | undefined, remove_excluded_dates?: Array | undefined}; export type UpdateApiV2AttendanceSchedulesAttendanceScheduleIdArgs = {attendance_schedule_id: number, body: PutV2AttendanceSchedulesAttendanceScheduleId}; export type UpdateApiV2AttendanceSchedulesAttendanceScheduleIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const attendanceSchedule = z.object({id: z.number().int(), user_id: z.number().int(), organization_id: z.number().int(), created_at: z.string(), updated_at: z.string(), start_date: z.string(), use_time_zone: z.string(), start_time: z.string(), duration: z.number().int(), minimum_time: z.number().int(), repeat_schedule: z.string(), repeat_until: z.string().optional(), weekdays: z.array(z.string()).optional(), excluded_dates: z.array(z.string()).optional()}); export const updateApiV2AttendanceSchedulesAttendanceScheduleIdResponse = z.object({attendance_schedule: attendanceSchedule.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 attendance schedule * * PUT /v2/attendance_schedules/{attendance_schedule_id} */ export const updateApiV2AttendanceSchedulesAttendanceScheduleId = async (args: UpdateApiV2AttendanceSchedulesAttendanceScheduleIdArgs, options?: UpdateApiV2AttendanceSchedulesAttendanceScheduleIdOptions) => { const {baseUrl = "https://api.hubstaff.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/attendance_schedules/${encodeURIComponent(String(args.attendance_schedule_id))}${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(updateApiV2AttendanceSchedulesAttendanceScheduleIdResponse, await res.json()) };