import {z} from 'zod' export type PropertyHrisAttendanceAddress = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, region?: string | undefined, region_code?: string | undefined, postal_code?: string | undefined, country?: string | undefined, country_code?: string | undefined}; export type HrisAttendanceBreak = {id?: string | undefined, start_at?: string | undefined, end_at?: string | undefined, is_paid?: boolean | undefined, duration_minutes?: number | undefined, name?: string | undefined}; export type PropertyHrisAttendanceBreaks = Array; export type HrisMetadata = {id?: string | undefined, value?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, namespace?: string | undefined, format?: ('TEXT' | 'NUMBER' | 'DATE' | 'BOOLEAN' | 'FILE' | 'TEXTAREA' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'MEASUREMENT' | 'PRICE' | 'YES_NO' | 'CURRENCY' | 'URL') | undefined, extra_data?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, slug?: string | undefined}; export type PropertyHrisAttendanceMetadata = Array; export type HrisAttendance = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, employee_user_id: string, start_at: string, end_at: string, timeshift_id?: string | undefined, location_id?: string | undefined, company_id?: string | undefined, group_id?: string | undefined, timezone?: string | undefined, address?: PropertyHrisAttendanceAddress | undefined, hours?: number | undefined, currency?: string | undefined, status?: ('OPEN' | 'CLOSED' | 'APPROVED') | undefined, breaks?: PropertyHrisAttendanceBreaks | undefined, declared_tips_amount?: number | undefined, non_cash_tips_amount?: number | undefined, job_name?: string | undefined, hourly_rate?: number | undefined, approver_user_id?: string | undefined, approved_at?: string | undefined, metadata?: PropertyHrisAttendanceMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type UpdateApiHrisConnectionIdAttendanceIdArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'employee_user_id' | 'start_at' | 'end_at' | 'timeshift_id' | 'location_id' | 'company_id' | 'group_id' | 'timezone' | 'address' | 'hours' | 'currency' | 'status' | 'breaks' | 'declared_tips_amount' | 'non_cash_tips_amount' | 'job_name' | 'hourly_rate' | 'approver_user_id' | 'approved_at' | 'metadata' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, id: string, body: HrisAttendance}; export type UpdateApiHrisConnectionIdAttendanceIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const propertyHrisAttendanceAddress = z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), region_code: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), country_code: z.string().optional()}); export const hrisAttendanceBreak = z.object({id: z.string().optional(), start_at: z.string().optional(), end_at: z.string().optional(), is_paid: z.boolean().optional(), duration_minutes: z.number().optional(), name: z.string().optional()}); export const propertyHrisAttendanceBreaks = z.array(hrisAttendanceBreak); export const hrisMetadata = z.object({id: z.string().optional(), value: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), namespace: z.string().optional(), format: z.enum(["TEXT", "NUMBER", "DATE", "BOOLEAN", "FILE", "TEXTAREA", "SINGLE_SELECT", "MULTIPLE_SELECT", "MEASUREMENT", "PRICE", "YES_NO", "CURRENCY", "URL"]).optional(), extra_data: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), slug: z.string().optional()}); export const propertyHrisAttendanceMetadata = z.array(hrisMetadata); export const hrisAttendance = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), employee_user_id: z.string(), start_at: z.string(), end_at: z.string(), timeshift_id: z.string().optional(), location_id: z.string().optional(), company_id: z.string().optional(), group_id: z.string().optional(), timezone: z.string().optional(), address: propertyHrisAttendanceAddress.optional(), hours: z.number().optional(), currency: z.string().optional(), status: z.enum(["OPEN", "CLOSED", "APPROVED"]).optional(), breaks: propertyHrisAttendanceBreaks.optional(), declared_tips_amount: z.number().optional(), non_cash_tips_amount: z.number().optional(), job_name: z.string().optional(), hourly_rate: z.number().optional(), approver_user_id: z.string().optional(), approved_at: z.string().optional(), metadata: propertyHrisAttendanceMetadata.optional(), raw: z.record(z.string(), z.unknown()).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 an attendance * * PUT /hris/{connection_id}/attendance/{id} */ export const updateApiHrisConnectionIdAttendanceId = async (args: UpdateApiHrisConnectionIdAttendanceIdArgs, options?: UpdateApiHrisConnectionIdAttendanceIdOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/hris/${encodeURIComponent(String(args.connection_id))}/attendance/${encodeURIComponent(String(args.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(hrisAttendance, await res.json()) };