import {z} from 'zod' export type GetAtsCandidatesParameterCursor = string; export type GetAtsCandidatesParameterPageSize = number; export type GetAtsCandidatesParameterUpdatedAfter = string; export type GetAtsCandidatesParameterIncludeDeleted = 'true' | 'false'; export type GetAtsCandidatesParameterIgnoreUnsupportedFilters = 'true' | 'false'; export type GetAtsCandidatesParameterIds = string; export type GetAtsCandidatesParameterRemoteIds = string; export type GetAtsCandidatesParameterEmail = string; export type GetAtsCandidatesParameterJobIds = string; export type GetAtsCandidatesParameterFirstName = string; export type GetAtsCandidatesParameterLastName = string; export type GetApiAtsCandidatesArgs = {'X-Integration-Id': string, cursor?: GetAtsCandidatesParameterCursor | undefined, page_size?: GetAtsCandidatesParameterPageSize | undefined, updated_after?: GetAtsCandidatesParameterUpdatedAfter | undefined, include_deleted?: GetAtsCandidatesParameterIncludeDeleted | undefined, ignore_unsupported_filters?: GetAtsCandidatesParameterIgnoreUnsupportedFilters | undefined, ids?: GetAtsCandidatesParameterIds | undefined, remote_ids?: GetAtsCandidatesParameterRemoteIds | undefined, email?: GetAtsCandidatesParameterEmail | undefined, job_ids?: GetAtsCandidatesParameterJobIds | undefined, first_name?: GetAtsCandidatesParameterFirstName | undefined, last_name?: GetAtsCandidatesParameterLastName | undefined}; export type GetApiAtsCandidatesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getAtsCandidatesPositiveResponse = 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(), 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()}))}))})}); 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 candidates * * GET /ats/candidates */ export const getApiAtsCandidates = async (args: GetApiAtsCandidatesArgs, options?: GetApiAtsCandidatesOptions) => { 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.email != null) query.append("email", String(args.email)) if (args.job_ids != null) query.append("job_ids", String(args.job_ids)) if (args.first_name != null) query.append("first_name", String(args.first_name)) if (args.last_name != null) query.append("last_name", String(args.last_name)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/ats/candidates${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(getAtsCandidatesPositiveResponse, await res.json()) };