import {z} from 'zod' export type GetAiApplyPostingsParameterCursor = string; export type GetAiApplyPostingsParameterPageSize = number; export type GetAiApplyPostingsParameterIds = string; export type GetAiApplyPostingsParameterCareerSiteIds = string; export type GetAiApplyPostingsParameterJobCodes = string; export type GetAiApplyPostingsParameterUpdatedAfter = string; export type GetApiAiApplyPostingsArgs = {cursor?: GetAiApplyPostingsParameterCursor | undefined, page_size?: GetAiApplyPostingsParameterPageSize | undefined, ids?: GetAiApplyPostingsParameterIds | undefined, career_site_ids?: GetAiApplyPostingsParameterCareerSiteIds | undefined, job_codes?: GetAiApplyPostingsParameterJobCodes | undefined, updated_after?: GetAiApplyPostingsParameterUpdatedAfter | undefined}; export type GetApiAiApplyPostingsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getAiApplyPostingsPositiveResponse = z.object({status: z.literal("success"), data: z.object({results: z.array(z.object({id: z.string(), career_site: z.object({id: z.string(), label: z.string()}), url: z.string(), job_code: z.string().nullable(), created_at: z.string(), updated_at: z.string(), archived_at: z.string().nullable(), archived_reason: z.enum(["JOB_POSTING_TAKEN_OFFLINE", "MANUAL_ARCHIVE", "REMOVED_FROM_JOB_FEED"]).nullable(), availability: z.enum(["APPLYABLE", "PENDING", "ARCHIVED", "UNAVAILABLE"])})), next: 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 job postings * * GET /ai-apply/postings */ export const getApiAiApplyPostings = async (args: GetApiAiApplyPostingsArgs, options?: GetApiAiApplyPostingsOptions) => { 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.cursor != null) query.append("cursor", String(args.cursor)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.career_site_ids != null) query.append("career_site_ids", String(args.career_site_ids)) if (args.job_codes != null) query.append("job_codes", String(args.job_codes)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/ai-apply/postings${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(getAiApplyPostingsPositiveResponse, await res.json()) };