import {z} from 'zod' export type HrisCompensation = {type?: ('SALARY' | 'BONUS' | 'STOCK_OPTIONS' | 'EQUITY' | 'OTHER' | 'HOURLY' | 'COMMISSION') | undefined, amount?: number | undefined, currency?: string | undefined, frequency?: ('ONE_TIME' | 'DAY' | 'QUARTER' | 'YEAR' | 'HOUR' | 'MONTH' | 'WEEK' | 'BIWEEKLY' | 'SEMIMONTHLY') | undefined, group_id?: string | undefined, notes?: string | undefined}; export type PropertyHrisTimeshiftCompensation = 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 PropertyHrisTimeshiftMetadata = Array; export type HrisTimeshift = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, employee_user_id: string, start_at?: string | undefined, end_at?: string | undefined, location_id?: string | undefined, company_id?: string | undefined, group_id?: string | undefined, compensation?: PropertyHrisTimeshiftCompensation | undefined, approver_user_id?: string | undefined, approved_at?: string | undefined, hours?: number | undefined, is_approved?: boolean | undefined, metadata?: PropertyHrisTimeshiftMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type UpdateApiHrisConnectionIdTimeshiftIdArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'employee_user_id' | 'start_at' | 'end_at' | 'location_id' | 'company_id' | 'group_id' | 'compensation' | 'approver_user_id' | 'approved_at' | 'hours' | 'is_approved' | 'metadata' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, id: string, body: HrisTimeshift}; export type UpdateApiHrisConnectionIdTimeshiftIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const hrisCompensation = z.object({type: z.enum(["SALARY", "BONUS", "STOCK_OPTIONS", "EQUITY", "OTHER", "HOURLY", "COMMISSION"]).optional(), amount: z.number().optional(), currency: z.string().optional(), frequency: z.enum(["ONE_TIME", "DAY", "QUARTER", "YEAR", "HOUR", "MONTH", "WEEK", "BIWEEKLY", "SEMIMONTHLY"]).optional(), group_id: z.string().optional(), notes: z.string().optional()}); export const propertyHrisTimeshiftCompensation = z.array(hrisCompensation); 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 propertyHrisTimeshiftMetadata = z.array(hrisMetadata); export const hrisTimeshift = 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().optional(), end_at: z.string().optional(), location_id: z.string().optional(), company_id: z.string().optional(), group_id: z.string().optional(), compensation: propertyHrisTimeshiftCompensation.optional(), approver_user_id: z.string().optional(), approved_at: z.string().optional(), hours: z.number().optional(), is_approved: z.boolean().optional(), metadata: propertyHrisTimeshiftMetadata.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 a timeshift * * PUT /hris/{connection_id}/timeshift/{id} */ export const updateApiHrisConnectionIdTimeshiftId = async (args: UpdateApiHrisConnectionIdTimeshiftIdArgs, options?: UpdateApiHrisConnectionIdTimeshiftIdOptions) => { 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))}/timeshift/${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(hrisTimeshift, await res.json()) };