import {z} from 'zod' export type GetHrisEmployeesParameterCursor = string; export type GetHrisEmployeesParameterPageSize = number; export type GetHrisEmployeesParameterUpdatedAfter = string; export type GetHrisEmployeesParameterIncludeDeleted = 'true' | 'false'; export type GetHrisEmployeesParameterIgnoreUnsupportedFilters = 'true' | 'false'; export type GetHrisEmployeesParameterIds = string; export type GetHrisEmployeesParameterRemoteIds = string; export type GetHrisEmployeesParameterEmploymentStatus = 'ACTIVE' | 'PENDING' | 'INACTIVE' | 'LEAVE'; export type GetHrisEmployeesParameterEmploymentStatuses = string; export type GetHrisEmployeesParameterGroupIds = string; export type GetHrisEmployeesParameterLegalEntityIds = string; export type GetHrisEmployeesParameterWorkLocationIds = string; export type GetHrisEmployeesParameterWorkEmails = string; export type GetHrisEmployeesParameterPersonalEmails = string; export type GetHrisEmployeesParameterCustomFields = string; export type GetApiHrisEmployeesArgs = {'X-Integration-Id': string, cursor?: GetHrisEmployeesParameterCursor | undefined, page_size?: GetHrisEmployeesParameterPageSize | undefined, updated_after?: GetHrisEmployeesParameterUpdatedAfter | undefined, include_deleted?: GetHrisEmployeesParameterIncludeDeleted | undefined, ignore_unsupported_filters?: GetHrisEmployeesParameterIgnoreUnsupportedFilters | undefined, ids?: GetHrisEmployeesParameterIds | undefined, remote_ids?: GetHrisEmployeesParameterRemoteIds | undefined, employment_status?: GetHrisEmployeesParameterEmploymentStatus | undefined, employment_statuses?: GetHrisEmployeesParameterEmploymentStatuses | undefined, group_ids?: GetHrisEmployeesParameterGroupIds | undefined, legal_entity_ids?: GetHrisEmployeesParameterLegalEntityIds | undefined, work_location_ids?: GetHrisEmployeesParameterWorkLocationIds | undefined, work_emails?: GetHrisEmployeesParameterWorkEmails | undefined, personal_emails?: GetHrisEmployeesParameterPersonalEmails | undefined, custom_fields?: GetHrisEmployeesParameterCustomFields | undefined}; export type GetApiHrisEmployeesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getHrisEmployeesPositiveResponse = z.object({status: z.literal("success"), data: z.object({next: z.string().nullable(), results: z.array(z.object({id: z.string(), remote_id: z.string(), employee_number: z.string().nullable(), first_name: z.string().nullable(), last_name: z.string().nullable(), nationality: z.string().nullable(), display_full_name: z.string().nullable(), job_title: z.string().nullable(), work_email: z.string().nullable().optional(), personal_email: z.string().nullable().optional(), mobile_phone_number: z.string().nullable(), ssn: z.string().nullable(), tax_id: z.string().nullable(), gender: z.union([z.enum(["MALE", "FEMALE", "NON_BINARY", "NOT_SPECIFIED"]), z.string()]).nullable().optional(), ethnicity: z.union([z.enum(["WHITE", "ASIAN", "HISPANIC_LATINO", "HAWAIIAN", "NATIVE_AMERICAN", "BLACK_AFRICAN_AMERICAN", "MULTIPLE_ETHNICITIES", "DECLINE_TO_SPECIFY"]), z.string()]).nullable().optional(), marital_status: z.union([z.enum(["SINGLE", "MARRIED", "DOMESTIC_PARTNERSHIP", "WIDOWED", "DIVORCED", "SEPARATED", "NOT_MARRIED"]), z.string()]).nullable().optional(), employment_status: z.union([z.enum(["ACTIVE", "PENDING", "INACTIVE", "LEAVE"]), z.string()]).nullable().optional(), employment_type: z.union([z.enum(["FULL_TIME", "PART_TIME", "CONTRACT", "INTERNSHIP", "FREELANCE", "WORKING_STUDENT", "APPRENTICESHIP", "TRAINING"]), z.string()]).nullable().optional(), weekly_hours: z.number().nullable(), avatar: z.string().nullable(), work_location_id: z.string().nullable(), legal_entity_id: z.string().nullable(), manager_id: z.string().nullable(), home_address: z.object({city: z.string().nullable().optional(), country: z.string().nullable().optional(), raw: z.string().nullable().optional(), state: z.string().nullable().optional(), street_1: z.string().nullable().optional(), street_2: z.string().nullable().optional(), zip_code: z.string().nullable().optional()}).nullable().optional(), bank_accounts: z.array(z.object({iban: z.string().nullable().optional(), bic: z.string().nullable().optional(), account_number: z.string().nullable().optional(), holder_name: z.string().nullable().optional(), bank_name: z.string().nullable().optional(), domestic_bank_routing: z.object({number: z.string(), type: z.enum(["GB_SORT_CODE", "DE_BANKLEITZAHL", "US_ABA_ROUTING_TRANSIT_NUMBER", "CA_ROUTING_NUMBER", "AU_BSB_CODE", "FR_RIB", "SG_BANK_BRANCH_CODE"]).nullable()}).nullable().optional()})).nullable().optional(), date_of_birth: z.string().nullable(), start_date: z.string().nullable(), termination_date: z.string().nullable(), remote_created_at: z.string().nullable(), changed_at: z.string(), remote_deleted_at: z.string().nullable(), custom_fields: z.record(z.string(), z.unknown()).nullable(), integration_fields: z.array(z.object({id: z.string(), key: z.string(), type: z.enum(["DEFAULT", "CUSTOM"]), value: z.unknown(), label: z.string().nullable()})), remote_data: z.record(z.string(), z.unknown()).nullable(), employments: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), employee_id: z.string(), job_title: z.string().nullable(), pay_rate: z.number().nullable(), pay_period: z.union([z.enum(["HOUR", "DAY", "WEEK", "TWO_WEEKS", "HALF_MONTH", "MONTH", "TWO_MONTHS", "QUARTER", "HALF_YEAR", "YEAR"]), z.string()]).nullable().optional(), pay_frequency: z.union([z.enum(["DAILY", "WEEKLY", "BIWEEKLY", "MONTHLY", "SEMIMONTHLY", "QUARTERLY", "SEMIANNUALLY", "ANNUALLY", "PRO_RATA"]), z.string()]).nullable().optional(), employment_type: z.union([z.enum(["FULL_TIME", "PART_TIME", "CONTRACT", "INTERNSHIP", "FREELANCE", "WORKING_STUDENT", "APPRENTICESHIP", "TRAINING"]), z.string()]).nullable().optional(), pay_currency: z.string().nullable(), effective_date: z.string().nullable(), changed_at: z.string(), remote_deleted_at: z.string().nullable(), remote_data: z.record(z.string(), z.unknown()).nullable(), custom_fields: z.record(z.string(), z.unknown()).nullable(), integration_fields: z.array(z.object({id: z.string(), key: z.string(), type: z.enum(["DEFAULT", "CUSTOM"]), value: z.unknown(), label: z.string().nullable()}))})), time_off_balances: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), employee_id: z.string(), type_id: z.string(), balance: z.number().nullable(), balance_unit: z.enum(["HOURS", "DAYS"]).nullable(), changed_at: z.string(), remote_deleted_at: z.string().nullable(), used: z.number().nullable(), used_unit: z.enum(["HOURS", "DAYS"]).nullable(), remote_data: z.record(z.string(), z.unknown()).nullable()})), manager: z.object({first_name: z.string().nullable(), last_name: z.string().nullable(), display_full_name: z.string().nullable(), id: z.string(), employee_number: z.string().nullable(), work_email: z.string().nullable().optional(), remote_id: z.string(), employment_status: z.union([z.enum(["ACTIVE", "PENDING", "INACTIVE", "LEAVE"]), z.string()]).nullable().optional(), termination_date: z.string().nullable()}).nullable(), groups: z.array(z.object({id: z.string(), remote_id: z.string(), name: z.string().nullable(), type: z.enum(["DEPARTMENT", "TEAM", "COST_CENTER"]).nullable()})), legal_entity: z.object({id: z.string(), remote_id: z.string().nullable(), name: z.string().nullable(), address: z.object({city: z.string().nullable().optional(), country: z.string().nullable().optional(), raw: z.string().nullable().optional(), state: z.string().nullable().optional(), street_1: z.string().nullable().optional(), street_2: z.string().nullable().optional(), zip_code: z.string().nullable().optional()}).nullable().optional()}).nullable(), teams: z.array(z.object({id: z.string(), remote_id: z.string(), name: z.string().nullable(), type: z.enum(["DEPARTMENT", "TEAM", "COST_CENTER"]).nullable()})), work_location: z.object({id: z.string(), remote_id: z.string().nullable(), name: z.string().nullable(), address: z.object({city: z.string().nullable().optional(), country: z.string().nullable().optional(), raw: z.string().nullable().optional(), state: z.string().nullable().optional(), street_1: z.string().nullable().optional(), street_2: z.string().nullable().optional(), zip_code: z.string().nullable().optional()}).nullable().optional(), type: z.string().nullable(), changed_at: z.string(), remote_deleted_at: z.string().nullable(), remote_data: z.record(z.string(), z.unknown()).nullable(), custom_fields: z.record(z.string(), z.unknown()).nullable(), integration_fields: z.array(z.object({id: z.string(), key: z.string(), type: z.enum(["DEFAULT", "CUSTOM"]), value: z.unknown(), label: z.string().nullable()}))}).nullable()}))})}); 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 }; /** * Get employees * * GET /hris/employees */ export const getApiHrisEmployees = async (args: GetApiHrisEmployeesArgs, options?: GetApiHrisEmployeesOptions) => { const {baseUrl = "https://api.kombo.dev/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Integration-Id'] != null) headers.set("X-Integration-Id", String(args['X-Integration-Id'])) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.ignore_unsupported_filters != null) query.append("ignore_unsupported_filters", String(args.ignore_unsupported_filters)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.remote_ids != null) query.append("remote_ids", String(args.remote_ids)) if (args.employment_status != null) query.append("employment_status", String(args.employment_status)) if (args.employment_statuses != null) query.append("employment_statuses", String(args.employment_statuses)) if (args.group_ids != null) query.append("group_ids", String(args.group_ids)) if (args.legal_entity_ids != null) query.append("legal_entity_ids", String(args.legal_entity_ids)) if (args.work_location_ids != null) query.append("work_location_ids", String(args.work_location_ids)) if (args.work_emails != null) query.append("work_emails", String(args.work_emails)) if (args.personal_emails != null) query.append("personal_emails", String(args.personal_emails)) if (args.custom_fields != null) query.append("custom_fields", String(args.custom_fields)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/hris/employees${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getHrisEmployeesPositiveResponse, await res.json()) };