import {z} from 'zod' export type GetAtsApplicationsParameterCursor = string; export type GetAtsApplicationsParameterPageSize = number; export type GetAtsApplicationsParameterUpdatedAfter = string; export type GetAtsApplicationsParameterIncludeDeleted = 'true' | 'false'; export type GetAtsApplicationsParameterIgnoreUnsupportedFilters = 'true' | 'false'; export type GetAtsApplicationsParameterIds = string; export type GetAtsApplicationsParameterRemoteIds = string; export type GetAtsApplicationsParameterOutcome = 'PENDING' | 'HIRED' | 'DECLINED'; export type GetAtsApplicationsParameterOutcomes = string; export type GetAtsApplicationsParameterJobIds = string; export type GetAtsApplicationsParameterJobRemoteIds = string; export type GetAtsApplicationsParameterCurrentStageIds = string; export type GetAtsApplicationsParameterRemoteCreatedAfter = string; export type GetApiAtsApplicationsArgs = {'X-Integration-Id': string, cursor?: GetAtsApplicationsParameterCursor | undefined, page_size?: GetAtsApplicationsParameterPageSize | undefined, updated_after?: GetAtsApplicationsParameterUpdatedAfter | undefined, include_deleted?: GetAtsApplicationsParameterIncludeDeleted | undefined, ignore_unsupported_filters?: GetAtsApplicationsParameterIgnoreUnsupportedFilters | undefined, ids?: GetAtsApplicationsParameterIds | undefined, remote_ids?: GetAtsApplicationsParameterRemoteIds | undefined, outcome?: GetAtsApplicationsParameterOutcome | undefined, outcomes?: GetAtsApplicationsParameterOutcomes | undefined, job_ids?: GetAtsApplicationsParameterJobIds | undefined, job_remote_ids?: GetAtsApplicationsParameterJobRemoteIds | undefined, current_stage_ids?: GetAtsApplicationsParameterCurrentStageIds | undefined, remote_created_after?: GetAtsApplicationsParameterRemoteCreatedAfter | undefined}; export type GetApiAtsApplicationsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getAtsApplicationsPositiveResponse = 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().nullable(), outcome: z.enum(["PENDING", "HIRED", "DECLINED"]).nullable(), rejection_reason_name: z.string().nullable(), rejected_at: z.string().nullable(), current_stage_id: z.string().nullable(), job_id: z.string().nullable(), candidate_id: z.string().nullable(), screening_question_answers: z.array(z.union([z.object({answer: z.object({content: z.string().nullable()}), question: z.object({remote_id: z.string().nullable(), title: z.string(), type: z.literal("TEXT")})}), z.object({answer: z.object({choice: z.string().nullable()}), question: z.object({remote_id: z.string().nullable(), title: z.string(), type: z.literal("SINGLE_SELECT")})}), z.object({answer: z.object({choices: z.array(z.string()).optional()}), question: z.object({remote_id: z.string().nullable(), title: z.string(), type: z.literal("MULTI_SELECT")})}), z.object({answer: z.object({checked: z.boolean().nullable()}), question: z.object({remote_id: z.string().nullable(), title: z.string(), type: z.literal("BOOLEAN")})}), z.object({answer: z.object({number: z.number().nullable()}), question: z.object({remote_id: z.string().nullable(), title: z.string(), type: z.literal("NUMBER")})}), z.object({answer: z.object({date: z.string().nullable()}), question: z.object({remote_id: z.string().nullable(), title: z.string(), type: z.literal("DATE")})}), z.object({answer: z.object({raw: z.unknown()}), question: z.object({remote_id: z.string().nullable(), title: z.string(), type: z.literal("UNKNOWN")})})])).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(), changed_at: z.string(), remote_deleted_at: z.string().nullable(), remote_created_at: z.string().nullable(), remote_updated_at: z.string().nullable(), remote_data: z.record(z.string(), z.unknown()).nullable(), candidate: z.object({id: z.string(), remote_id: z.string(), first_name: z.string().nullable(), last_name: z.string().nullable(), email_addresses: z.array(z.object({email_address: z.string().nullable().optional(), type: z.string().nullable()})).nullable().optional(), phone_numbers: z.array(z.object({phone_number: z.string(), type: z.string().nullable().optional()})).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(), source: z.string().nullable(), remote_url: z.string().nullable(), tags: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), name: z.string().nullable()}))}).nullable(), current_stage: z.object({id: z.string(), remote_id: z.string().nullable(), name: z.string().nullable(), status: z.enum(["ACTIVE", "INACTIVE"]).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()})), index: z.number().int().nullable()}).nullable(), job: z.object({id: z.string(), remote_id: z.string(), name: z.string().nullable()}).nullable(), interviews: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), title: z.string().nullable(), starting_at: z.string().nullable(), ending_at: z.string().nullable(), 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(), canceled: z.boolean().nullable()})), offers: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), status: z.enum(["ACCEPTED", "DECLINED", "SENT", "APPROVED", "DRAFT", "ABANDONED"]).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 applications * * GET /ats/applications */ export const getApiAtsApplications = async (args: GetApiAtsApplicationsArgs, options?: GetApiAtsApplicationsOptions) => { 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.outcome != null) query.append("outcome", String(args.outcome)) if (args.outcomes != null) query.append("outcomes", String(args.outcomes)) if (args.job_ids != null) query.append("job_ids", String(args.job_ids)) if (args.job_remote_ids != null) query.append("job_remote_ids", String(args.job_remote_ids)) if (args.current_stage_ids != null) query.append("current_stage_ids", String(args.current_stage_ids)) if (args.remote_created_after != null) query.append("remote_created_after", String(args.remote_created_after)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/ats/applications${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(getAtsApplicationsPositiveResponse, await res.json()) };