import {z} from 'zod' export type TimeTrackingUpdateTimeTrackingImportRowV1 = {employeeNumber?: string | undefined, dateWorked?: string | undefined, hoursWorked?: string | undefined, rateType?: ('REGULAR' | 'OVERTIME' | 'DOUBLE_TIME') | undefined, payRate?: (string | null) | undefined, payCode?: (string | null) | undefined, projectName?: (string | null) | undefined, taskName?: (string | null) | undefined, shiftDifferentialName?: (string | null) | undefined, holidayName?: (string | null) | undefined, qualifiedOvertimeHours?: (string | null) | undefined}; export type PatchApiApiV1TimeTrackingImportsIdRowsRowIdArgs = {id: number, rowId: number, body: TimeTrackingUpdateTimeTrackingImportRowV1}; export type PatchApiApiV1TimeTrackingImportsIdRowsRowIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const timeTrackingTimeTrackingImportRowV1 = z.object({id: z.number().int().optional(), importId: z.number().int().optional(), rowNumber: z.number().int().optional(), employeeNumber: z.string().optional(), dateWorked: z.string().optional(), hoursWorked: z.string().optional(), rateType: z.enum(["REGULAR", "OVERTIME", "DOUBLE_TIME"]).nullable().optional(), payRate: z.string().nullable().optional(), payCode: z.string().nullable().optional(), projectName: z.string().nullable().optional(), taskName: z.string().nullable().optional(), shiftDifferentialName: z.string().nullable().optional(), holidayName: z.string().nullable().optional(), qualifiedOvertimeHours: z.string().nullable().optional(), errors: z.record(z.string(), z.string()).nullable().optional(), corrections: z.record(z.string(), z.object({original: z.string().nullable(), corrections: z.array(z.string())})).nullable().optional(), timeTrackingId: 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 Import Row * * PATCH /api/v1/time-tracking/imports/{id}/rows/{rowId} * * Also accepts auth: oauth */ export const patchApiApiV1TimeTrackingImportsIdRowsRowId = async (args: PatchApiApiV1TimeTrackingImportsIdRowsRowIdArgs, options?: PatchApiApiV1TimeTrackingImportsIdRowsRowIdOptions) => { 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/imports/${encodeURIComponent(String(args.id))}/rows/${encodeURIComponent(String(args.rowId))}${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(timeTrackingTimeTrackingImportRowV1, await res.json()) };