import {z} from 'zod' export type GetHrisStaffingEntitiesParameterCursor = string; export type GetHrisStaffingEntitiesParameterPageSize = number; export type GetHrisStaffingEntitiesParameterUpdatedAfter = string; export type GetHrisStaffingEntitiesParameterIncludeDeleted = 'true' | 'false'; export type GetHrisStaffingEntitiesParameterIgnoreUnsupportedFilters = 'true' | 'false'; export type GetHrisStaffingEntitiesParameterIds = string; export type GetHrisStaffingEntitiesParameterRemoteIds = string; export type GetHrisStaffingEntitiesParameterModelTypes = string; export type GetHrisStaffingEntitiesParameterStatuses = string; export type GetApiHrisStaffingEntitiesArgs = {'X-Integration-Id': string, cursor?: GetHrisStaffingEntitiesParameterCursor | undefined, page_size?: GetHrisStaffingEntitiesParameterPageSize | undefined, updated_after?: GetHrisStaffingEntitiesParameterUpdatedAfter | undefined, include_deleted?: GetHrisStaffingEntitiesParameterIncludeDeleted | undefined, ignore_unsupported_filters?: GetHrisStaffingEntitiesParameterIgnoreUnsupportedFilters | undefined, ids?: GetHrisStaffingEntitiesParameterIds | undefined, remote_ids?: GetHrisStaffingEntitiesParameterRemoteIds | undefined, model_types?: GetHrisStaffingEntitiesParameterModelTypes | undefined, statuses?: GetHrisStaffingEntitiesParameterStatuses | undefined}; export type GetApiHrisStaffingEntitiesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getHrisStaffingEntitiesPositiveResponse = 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(), name: z.string().nullable(), model_type: z.enum(["JOB", "POSITION", "REQUISITION"]).nullable(), description: z.string().nullable(), status: z.enum(["OPEN_LIMITED", "OPEN_UNLIMITED", "PENDING", "FROZEN", "FILLED", "CLOSED"]).nullable(), employment_types: z.array(z.object({remote_label: z.string(), unified_type: z.enum(["FULL_TIME", "PART_TIME", "CONTRACT", "INTERNSHIP", "FREELANCE", "WORKING_STUDENT", "APPRENTICESHIP", "TRAINING"]).nullable()})).nullable().optional(), number_of_openings: z.number().nullable(), parent_id: z.string().nullable(), remote_url: z.string().nullable(), remote_created_at: z.string().nullable(), remote_updated_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(), locations: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), name: z.string().nullable(), type: z.string().nullable()})), legal_entities: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), name: z.string().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()})), skills: z.array(z.object({skill_id: z.string(), skill: z.object({id: z.string(), remote_id: z.string(), name: z.string().nullable(), proficiency_scale: z.discriminatedUnion("type", [z.object({id: z.string(), remote_id: z.string(), type: z.literal("NUMERIC"), min: z.number().nullable(), max: z.number().nullable(), step: z.number().nullable()}), z.object({id: z.string(), remote_id: z.string(), type: z.literal("SINGLE_SELECT"), ordered_options: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), name: z.string()}))})]).nullable()}), expected_proficiency: z.discriminatedUnion("type", [z.object({type: z.literal("NUMERIC"), value: z.number()}), z.object({type: z.literal("SINGLE_SELECT"), selected_option_id: 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 }; /** * Get staffing entities * * GET /hris/staffing-entities */ export const getApiHrisStaffingEntities = async (args: GetApiHrisStaffingEntitiesArgs, options?: GetApiHrisStaffingEntitiesOptions) => { 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.model_types != null) query.append("model_types", String(args.model_types)) if (args.statuses != null) query.append("statuses", String(args.statuses)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/hris/staffing-entities${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(getHrisStaffingEntitiesPositiveResponse, await res.json()) };