import {z} from 'zod' export type PostAtsCandidatesRequestBody = {candidate: {first_name: string, last_name: string, email_address: string, additional_email_addresses?: (Array<{type: 'PERSONAL' | 'WORK' | 'OTHER', email_address: string}>) | undefined, company?: string | undefined, title?: string | undefined, phone_number?: string | undefined, additional_phone_numbers?: (Array<{type: 'PERSONAL' | 'WORK' | 'OTHER', phone_number: string}>) | undefined, location?: ({city?: string | undefined, country: string, state?: string | undefined, street_1?: string | undefined, zip_code?: string | undefined}) | undefined, gender?: ('MALE' | 'FEMALE' | 'OTHER') | undefined, availability_date?: string | undefined, salary_expectations?: ({period: 'MONTH' | 'YEAR', amount: number}) | undefined, social_links?: Array<{url: string}> | undefined}, application: {job_id: string, stage_id?: string | undefined}, screening_question_answers?: (Array<{question_id: string, answer: string | boolean | number | Array | string | {name: string, content_type?: string | undefined, data_url?: string | undefined, data?: string | undefined}}>) | undefined, attachments?: (Array<{name: string, content_type?: string | undefined, data_url?: string | undefined, data?: string | undefined, type: 'CV' | 'COVER_LETTER' | 'OTHER'}>) | undefined, source?: ({name?: string | undefined, unified_key?: string | undefined, id?: string | undefined}) | undefined, sourced_by?: {user_id: string} | undefined, gdpr_consent?: ({expires_at?: string | undefined, given?: boolean | undefined}) | undefined, remote_fields?: ({successfactors?: ({Candidate?: {[key: string]: unknown} | undefined, JobApplication?: {[key: string]: unknown} | undefined, copyJobApplicationAttachments?: boolean | undefined, update_existing_candidate?: (boolean | null) | undefined}) | undefined, personio?: ({application?: {[key: string]: unknown} | undefined}) | undefined, talentsoft?: ({applicant?: {[key: string]: unknown} | undefined, application?: {[key: string]: unknown} | undefined, customFields?: {[key: string]: unknown} | undefined}) | undefined, teamtailor?: ({candidate?: {[key: string]: unknown} | undefined, application?: ({attributes?: {[key: string]: unknown} | undefined}) | undefined}) | undefined, greenhouse?: ({candidate?: {[key: string]: unknown} | undefined, application?: {[key: string]: unknown} | undefined, post_headers?: ({'On-Behalf-Of'?: (string | null) | undefined}) | undefined}) | undefined, greenhousev3?: ({candidate?: {[key: string]: unknown} | undefined, application?: {[key: string]: unknown} | undefined}) | undefined, lever?: ({candidate?: {[key: string]: unknown} | undefined}) | undefined, workable?: ({candidate?: {[key: string]: unknown} | undefined, on_behalf_of_user_remote_id?: string | undefined}) | undefined, workday?: ({Candidate_Data?: ({Name_Detail_Data?: ({Middle_Name?: string | undefined, Social_Suffix_Reference?: {Predefined_Name_Component_ID: string} | undefined}) | undefined, Language_Reference?: {WID: string} | undefined, Job_Application_Data?: ({Job_Applied_To_Data?: ({Global_Personal_Information_Data?: ({Date_of_Birth?: string | undefined}) | undefined}) | undefined, Resume_Data?: ({Education_Data?: (Array<{School_Name?: string | undefined, First_Year_Attended?: number | undefined, Last_Year_Attended?: number | undefined, Field_of_Study_Reference?: {WID: string} | undefined, Degree_Reference?: {WID: string} | undefined, Grade_Average?: string | undefined}>) | undefined, Skill_Data?: (Array<{Skill_Name?: string | undefined}>) | undefined, Language_Data?: (Array<{Language_Reference?: ({WID?: string | undefined}) | undefined, Language?: ({Native?: boolean | undefined, Language_Ability: Array<{Language_Ability_Data?: ({Language_Proficiency_Reference?: {WID: string} | undefined, Language_Ability_Type_Reference?: {WID: string} | undefined}) | undefined}>}) | undefined}>) | undefined, Experience_Data?: (Array<{Company_Name: string, Title: string, Location?: string | undefined, Start_Date: string, End_Date?: string | undefined, Currently_Work_Here?: boolean | undefined, Description?: string | undefined}>) | undefined}) | undefined}) | undefined, Contact_Data?: ({Location_Data?: ({Address_Line_1?: string | undefined, Address_Line_2?: string | undefined, Postal_Code?: string | undefined, Region_Subdivision_1?: string | undefined, Country_Region_Reference?: {Country_Region_ID: string} | undefined, Country_City_Reference?: {WID: string} | undefined}) | undefined}) | undefined, Worker_Reference?: ({WID?: string | undefined, Employee_ID?: string | undefined}) | undefined}) | undefined, Override_Source_Reference_WID?: string | undefined}) | undefined, zohorecruit?: ({candidate?: {[key: string]: unknown} | undefined}) | undefined, bullhorn?: ({candidate?: {[key: string]: unknown} | undefined, job_submission?: {[key: string]: unknown} | undefined, existing_candidate_remote_id?: string | undefined}) | undefined, smartrecruiters?: ({candidate_with_questions?: {[key: string]: unknown} | undefined, candidate_without_questions?: {[key: string]: unknown} | undefined, candidate?: {[key: string]: unknown} | undefined, consent_decisions?: ({SINGLE?: boolean | undefined, SMART_RECRUIT?: boolean | undefined, SMART_CRM?: boolean | undefined, SMART_MESSAGE_SMS?: boolean | undefined, SMART_MESSAGE_WHATSAPP?: boolean | undefined}) | undefined}) | undefined, talentadore?: ({applications?: {[key: string]: unknown} | undefined}) | undefined, guidecom?: ({candidate?: {[key: string]: unknown} | undefined}) | undefined, dvinci?: ({application?: {[key: string]: unknown} | undefined, candidate?: {[key: string]: unknown} | undefined}) | undefined, hrworks?: ({jobApplication?: {[key: string]: unknown} | undefined}) | undefined, jobylon?: ({application?: ({message?: string | undefined}) | undefined}) | undefined, avature?: ({candidate?: {[key: string]: unknown} | undefined, workflow?: ({step?: {id: number} | undefined}) | undefined}) | undefined, recruitee?: ({candidate?: ({cover_letter_text?: string | undefined}) | undefined}) | undefined, rexx?: ({candidate?: {[key: string]: unknown} | undefined}) | undefined, umantis?: ({person?: {[key: string]: unknown} | undefined}) | undefined, piloga?: ({candidate?: ({street?: string | undefined, geburtsdatum?: string | undefined}) | undefined}) | undefined, pinpoint?: ({candidate?: {[key: string]: unknown} | undefined}) | undefined, covetorest?: ({candidate?: ({mandant?: number | undefined, status?: number | undefined, aktiv?: ('Ja' | 'Nein') | undefined}) | undefined}) | undefined, afas?: ({Fields?: {[key: string]: unknown} | undefined}) | undefined, fountain?: ({consent_sms_transactional?: boolean | undefined, consent_sms_marketing?: boolean | undefined, consent_calls_transactional?: boolean | undefined, consent_calls_marketing?: boolean | undefined}) | undefined, recruitcrm?: ({custom_fields?: (Array<{field_id: number, value: string, entity_type?: string | undefined, field_name?: string | undefined, field_type?: string | undefined}>) | undefined}) | undefined, icims?: ({application?: {[key: string]: unknown} | undefined}) | undefined}) | undefined}; export type CreateApiAtsCandidatesArgs = {'X-Integration-Id': string, body: PostAtsCandidatesRequestBody}; export type CreateApiAtsCandidatesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const postAtsCandidatesPositiveResponse = z.object({status: z.literal("success"), data: z.object({id: z.string(), remote_id: z.string(), first_name: z.string().nullable(), last_name: z.string().nullable(), company: z.string().nullable(), title: z.string().nullable(), confidential: z.boolean().nullable(), source: z.string().nullable(), phone_numbers: z.array(z.object({phone_number: z.string(), type: z.string().nullable().optional()})).nullable().optional(), email_addresses: z.array(z.object({email_address: z.string().nullable().optional(), type: z.string().nullable()})).nullable().optional(), social_media: z.array(z.object({link: z.string().nullable().optional(), type: z.string().nullable().optional(), username: z.string().nullable().optional()})).nullable().optional(), location: 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(), 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_url: z.string().nullable(), remote_created_at: z.string().nullable(), remote_updated_at: z.string().nullable(), remote_data: z.record(z.string(), z.unknown()).nullable(), changed_at: z.string(), remote_deleted_at: z.string().nullable(), applications: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), outcome: z.enum(["PENDING", "HIRED", "DECLINED"]).nullable(), rejection_reason_name: z.string().nullable(), rejected_at: z.string().nullable(), remote_url: z.string().nullable(), changed_at: z.string(), remote_created_at: z.string().nullable(), remote_updated_at: z.string().nullable(), current_stage: z.object({id: z.string(), name: z.string().nullable(), remote_id: z.string().nullable(), index: z.number().int().nullable()}).nullable(), job: z.object({id: z.string(), name: z.string().nullable(), remote_id: z.string()}).nullable()})), tags: z.array(z.object({id: z.string(), name: z.string().nullable(), remote_id: z.string().nullable()}))}), warnings: z.array(z.object({message: z.string()}))}); 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 candidate * * POST /ats/candidates */ export const createApiAtsCandidates = async (args: CreateApiAtsCandidatesArgs, options?: CreateApiAtsCandidatesOptions) => { const {baseUrl = "https://api.kombo.dev/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Integration-Id'] != null) headers.set("X-Integration-Id", String(args['X-Integration-Id'])) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/ats/candidates${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(postAtsCandidatesPositiveResponse, await res.json()) };