import {z} from 'zod' export type CreateApiEmployeesArgs = {Authorization: string, body: {account: {email: string, language?: string | undefined, externalId?: string | undefined}, personal: {firstName: string, lastName: string, displayName?: string | undefined, gender?: string | undefined, birthdate?: string | undefined, nationality?: string | undefined}, work: {companyId: string, officeId?: string | undefined, departmentId?: string | undefined, startDate?: string | undefined, jobTitle?: string | undefined, workPhone?: string | undefined, workMobile?: string | undefined, isAssistant?: boolean | undefined, probationPeriodEnd?: string | undefined, contractEnd?: string | undefined, reportsToId?: string | undefined, weeklyHours: number, weeklyDays?: number | undefined}, workSchedule?: ({mondayWorkingDay?: boolean | undefined, tuesdayWorkingDay?: boolean | undefined, wednesdayWorkingDay?: boolean | undefined, thursdayWorkingDay?: boolean | undefined, fridayWorkingDay?: boolean | undefined, saturdayWorkingDay?: boolean | undefined, sundayWorkingDay?: boolean | undefined, trackAttendance?: boolean | undefined}) | undefined, address?: ({street?: string | undefined, postalCode?: string | undefined, city?: string | undefined, country?: string | undefined, houseNumber?: string | undefined, additionalAddress?: string | undefined}) | undefined, financial?: ({accountHolderName?: string | undefined, bankName?: string | undefined, accountNumber?: string | undefined, iban?: string | undefined, swiftCode?: string | undefined, nationalId?: string | undefined, passport?: string | undefined, nationalInsuranceNumber?: string | undefined, taxCode?: string | undefined, taxIdentificationNumber?: string | undefined}) | undefined, home?: ({maritalStatus?: string | undefined, spouseFirstName?: string | undefined, spouseLastName?: string | undefined, spouseBirthdate?: string | undefined, spouseGender?: string | undefined, personalEmail?: string | undefined, personalPhone?: string | undefined, personalMobile?: string | undefined, children?: Array | undefined}) | undefined, emergency?: ({emergencyFirstName?: string | undefined, emergencyMiddleName?: string | undefined, emergencyLastName?: string | undefined, relation?: string | undefined, emergencyPhoneNumber?: string | undefined, emergencyMobileNumber?: string | undefined}) | undefined}}; export type CreateApiEmployeesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiEmployeesResponse = z.object({account: z.object({_id: z.string().optional(), email: z.string().optional(), externalId: z.string().optional(), isActive: z.string().optional(), language: z.string().optional()}).optional(), personal: z.object({firstName: z.string().optional(), lastName: z.string().optional(), displayName: z.string().optional(), gender: z.string().optional(), birthdate: z.string().optional(), nationality: z.string().optional()}).optional(), work: z.object({companyId: z.string().optional(), officeId: z.string().optional(), departmentId: z.string().optional(), startDate: z.string().optional(), jobTitle: z.string().optional(), workPhone: z.string().optional(), workMobile: z.string().optional(), isAssistant: z.boolean().optional(), probationPeriodEnd: z.string().optional(), contractEnd: z.string().optional(), reportsToId: z.string().optional(), weeklyHours: z.number().optional()}).optional(), workSchedule: z.object({mondayWorkingDay: z.boolean().optional(), tuesdayWorkingDay: z.boolean().optional(), wednesdayWorkingDay: z.boolean().optional(), thursdayWorkingDay: z.boolean().optional(), fridayWorkingDay: z.boolean().optional(), saturdayWorkingDay: z.boolean().optional(), sundayWorkingDay: z.boolean().optional(), trackAttendance: z.boolean().optional()}).optional(), address: z.object({street: z.string().optional(), postalCode: z.string().optional(), city: z.string().optional(), country: z.string().optional(), houseNumber: z.string().optional(), additionalAddress: z.string().optional()}).optional(), financial: z.object({accountHolderName: z.string().optional(), bankName: z.string().optional(), accountNumber: z.string().optional(), iban: z.string().optional(), swiftCode: z.string().optional(), nationalId: z.string().optional(), passport: z.string().optional(), nationalInsuranceNumber: z.string().optional(), taxCode: z.string().optional(), taxIdentificationNumber: z.string().optional()}).optional(), home: z.object({maritalStatus: z.string().optional(), spouseFirstName: z.string().optional(), spouseLastName: z.string().optional(), spouseBirthdate: z.string().optional(), spouseGender: z.string().optional(), personalEmail: z.string().optional(), personalPhone: z.string().optional(), personalMobile: z.string().optional(), children: z.array(z.unknown()).optional()}).optional(), emergency: z.object({emergencyFirstName: z.string().optional(), emergencyMiddleName: z.string().optional(), emergencyLastName: z.string().optional(), relation: z.string().optional(), emergencyPhoneNumber: z.string().optional(), emergencyMobileNumber: z.string().optional()}).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 a new employee. * * POST /employees */ export const createApiEmployees = async (args: CreateApiEmployeesArgs, options?: CreateApiEmployeesOptions) => { const {baseUrl = "https://sandbox-api.kenjo.io/api/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/employees${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(createApiEmployeesResponse, await res.json()) };