import {z} from 'zod' export type PostAtsImportTrackedApplicationRequestBody = {erecruiter?: ({id_type: 'application_and_job_remote_ids', application_remote_id: string, job_remote_id: string} | {id_type: 'application_and_candidate_remote_ids', candidate_remote_id: string, application_remote_id: string}) | undefined, successfactors?: {id_type: 'application_remote_id', application_remote_id: string} | undefined, recruitee?: {id_type: 'placement_id', placement_id: string} | undefined, greenhouse?: {id_type: 'application_id', application_id: string} | undefined, greenhousev3?: {id_type: 'application_id', application_id: string} | undefined, onlyfy?: {id_type: 'application_id', application_id: string} | undefined, smartrecruiters?: {id_type: 'candidate_and_job_remote_ids', candidate_remote_id: string, job_remote_id: string} | undefined, tracked_at: string | null}; export type CreateApiAtsImportTrackedApplicationArgs = {'X-Integration-Id': string, body: PostAtsImportTrackedApplicationRequestBody}; export type CreateApiAtsImportTrackedApplicationOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const postAtsImportTrackedApplicationPositiveResponse = z.object({status: z.literal("success"), data: z.object({id: z.string().min(24).max(24), tracked_at: z.string().nullable(), imported_id: z.object({erecruiter: z.discriminatedUnion("id_type", [z.object({id_type: z.literal("application_and_job_remote_ids"), application_remote_id: z.string(), job_remote_id: z.string()}), z.object({id_type: z.literal("application_and_candidate_remote_ids"), candidate_remote_id: z.string(), application_remote_id: z.string()})]).optional(), successfactors: z.object({id_type: z.literal("application_remote_id"), application_remote_id: z.string()}).optional(), recruitee: z.object({id_type: z.literal("placement_id"), placement_id: z.string()}).optional(), greenhouse: z.object({id_type: z.literal("application_id"), application_id: z.string()}).optional(), greenhousev3: z.object({id_type: z.literal("application_id"), application_id: z.string()}).optional(), onlyfy: z.object({id_type: z.literal("application_id"), application_id: z.string()}).optional(), smartrecruiters: z.object({id_type: z.literal("candidate_and_job_remote_ids"), candidate_remote_id: z.string(), job_remote_id: z.string()}).optional()})}), 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 }; /** * Import tracked application * * POST /ats/import-tracked-application */ export const createApiAtsImportTrackedApplication = async (args: CreateApiAtsImportTrackedApplicationArgs, options?: CreateApiAtsImportTrackedApplicationOptions) => { 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/import-tracked-application${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(postAtsImportTrackedApplicationPositiveResponse, await res.json()) };