import {z} from 'zod' export type TimeTrackingCreateTimeTrackingConfigurationV1 = {name: string, timesheetType: 'CLOCK' | 'SINGLE' | 'MULTIPLE' | 'HOUR', workWeekStartsOn: 'SUNDAY' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY', approverType: 'REPORTS_TO' | 'SPECIFIC_PERSON', approverUserId?: (number | null) | undefined, approvalCutoff: string, approvalCutoffDays: number, clockInSchedulePolicy?: ('ANYTIME' | 'SHIFT_REQUIRED') | undefined, restrictWebClockActions?: boolean | undefined, mobileEnabled?: boolean | undefined, geolocationEnabled?: boolean | undefined, customOvertimeEnabled?: boolean | undefined, overtimeDailyHours?: (string | null) | undefined, overtimeDailyDoubleHours?: (string | null) | undefined, overtimeWeeklyHours?: (string | null) | undefined}; export type CreateApiApiV1TimeTrackingConfigurationsArgs = {'Idempotency-Key'?: string | undefined, body: TimeTrackingCreateTimeTrackingConfigurationV1}; export type CreateApiApiV1TimeTrackingConfigurationsOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const timeTrackingTimeTrackingConfigurationV1 = z.object({id: z.number().int().optional(), name: z.string().max(255).optional(), type: z.enum(["GLOBAL", "GROUP"]).optional(), timesheetType: z.enum(["CLOCK", "SINGLE", "MULTIPLE", "HOUR"]).optional(), workWeekStartsOn: z.enum(["SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"]).optional(), approverType: z.enum(["REPORTS_TO", "SPECIFIC_PERSON"]).nullable().optional(), approverUserId: z.number().int().nullable().optional(), approvalCutoff: z.string().optional(), approvalCutoffDays: z.number().int().optional(), clockInSchedulePolicy: z.enum(["ANYTIME", "SHIFT_REQUIRED"]).optional(), restrictWebClockActions: z.boolean().optional(), mobileEnabled: z.boolean().optional(), geolocationEnabled: z.boolean().optional(), customOvertimeEnabled: z.boolean().optional(), overtimeDailyHours: z.string().nullable().optional(), overtimeDailyDoubleHours: z.string().nullable().optional(), overtimeWeeklyHours: z.string().nullable().optional(), employeeIds: z.array(z.number().int()).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 }; /** * Create Configuration * * POST /api/v1/time-tracking/configurations * * Also accepts auth: oauth */ export const createApiApiV1TimeTrackingConfigurations = async (args: CreateApiApiV1TimeTrackingConfigurationsArgs, options?: CreateApiApiV1TimeTrackingConfigurationsOptions) => { 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 (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/time-tracking/configurations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(timeTrackingTimeTrackingConfigurationV1, await res.json()) };