import {z} from 'zod' export type GetAtsScorecardsParameterCursor = string; export type GetAtsScorecardsParameterPageSize = number; export type GetAtsScorecardsParameterUpdatedAfter = string; export type GetAtsScorecardsParameterIncludeDeleted = 'true' | 'false'; export type GetAtsScorecardsParameterIgnoreUnsupportedFilters = 'true' | 'false'; export type GetAtsScorecardsParameterIds = string; export type GetAtsScorecardsParameterRemoteIds = string; export type GetAtsScorecardsParameterCandidateIds = string; export type GetAtsScorecardsParameterApplicationIds = string; export type GetApiAtsScorecardsArgs = {'X-Integration-Id': string, cursor?: GetAtsScorecardsParameterCursor | undefined, page_size?: GetAtsScorecardsParameterPageSize | undefined, updated_after?: GetAtsScorecardsParameterUpdatedAfter | undefined, include_deleted?: GetAtsScorecardsParameterIncludeDeleted | undefined, ignore_unsupported_filters?: GetAtsScorecardsParameterIgnoreUnsupportedFilters | undefined, ids?: GetAtsScorecardsParameterIds | undefined, remote_ids?: GetAtsScorecardsParameterRemoteIds | undefined, candidate_ids?: GetAtsScorecardsParameterCandidateIds | undefined, application_ids?: GetAtsScorecardsParameterApplicationIds | undefined}; export type GetApiAtsScorecardsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getAtsScorecardsPositiveResponse = 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(), candidate_id: z.string().nullable(), application_id: z.string().nullable(), interview_id: z.string().nullable(), author_id: z.string().nullable(), responses: z.array(z.discriminatedUnion("type", [z.object({remote_id: z.string().nullable(), label: z.string(), description: z.string().nullable(), required: z.boolean().nullable(), type: z.literal("TEXT"), answer: z.string().nullable()}), z.object({remote_id: z.string().nullable(), label: z.string(), description: z.string().nullable(), required: z.boolean().nullable(), type: z.literal("SINGLE_SELECT"), options: z.array(z.object({remote_id: z.string().nullable(), label: z.string()})), answer: z.object({remote_id: z.string().nullable(), label: z.string()}).nullable()}), z.object({remote_id: z.string().nullable(), label: z.string(), description: z.string().nullable(), required: z.boolean().nullable(), type: z.literal("MULTI_SELECT"), options: z.array(z.object({remote_id: z.string().nullable(), label: z.string()})), answer: z.array(z.object({remote_id: z.string().nullable(), label: z.string()})).nullable()}), z.object({remote_id: z.string().nullable(), label: z.string(), description: z.string().nullable(), required: z.boolean().nullable(), type: z.literal("BOOLEAN"), answer: z.boolean().nullable()}), z.object({remote_id: z.string().nullable(), label: z.string(), description: z.string().nullable(), required: z.boolean().nullable(), type: z.literal("NUMBER"), answer: z.number().nullable()}), z.object({remote_id: z.string().nullable(), label: z.string(), description: z.string().nullable(), required: z.boolean().nullable(), type: z.literal("DATE"), answer: z.string().nullable()})])).nullable().optional(), 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(), author: z.object({id: z.string(), remote_id: z.string().nullable(), first_name: z.string().nullable(), last_name: z.string().nullable(), email: z.string().nullable().optional()}).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 scorecards * * GET /ats/scorecards */ export const getApiAtsScorecards = async (args: GetApiAtsScorecardsArgs, options?: GetApiAtsScorecardsOptions) => { 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.candidate_ids != null) query.append("candidate_ids", String(args.candidate_ids)) if (args.application_ids != null) query.append("application_ids", String(args.application_ids)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/ats/scorecards${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(getAtsScorecardsPositiveResponse, await res.json()) };