import {z} from 'zod' export type CreateApiLinkedinSearchJobPostingsArgs = {body: {keywords?: string | undefined, location?: string | undefined, date_posted?: ('Any time' | 'Past 24 hours' | 'Past Week' | 'Past Month') | undefined, salary?: ('$40,000+' | '$60,000+' | '$80,000+' | '$100,000+' | '$120,000+' | '$140,000+' | '$160,000+' | '$180,000+' | '$200,000+') | undefined, job_type?: ('Contract' | 'Full-time' | 'Part-time' | 'Internship') | undefined, work_type?: ('On-site' | 'Remote' | 'Hybrid') | undefined, experience_level?: ('Associate' | 'Director' | 'Entry Level' | 'Executive' | 'Internship' | 'Mid-Senior Level') | undefined, company_uids?: Array | undefined, sort_by?: ('Most Recent' | 'Most Relevant') | undefined, page?: number | undefined}}; export type CreateApiLinkedinSearchJobPostingsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiLinkedinSearchJobPostingsResponse = z.object({job_postings: z.array(z.object({url: z.string().optional(), title: z.string().optional(), location: z.string().optional(), date_posted: z.string().optional(), company_name: z.string().optional(), company_url: z.string().optional()})).optional()}); 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 }; /** * Search for LinkedIn job postings * * POST /linkedin/search-job-postings */ export const createApiLinkedinSearchJobPostings = async (args: CreateApiLinkedinSearchJobPostingsArgs, options?: CreateApiLinkedinSearchJobPostingsOptions) => { const {baseUrl = "https://api.exfunc.dev", 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 (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/linkedin/search-job-postings${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(createApiLinkedinSearchJobPostingsResponse, await res.json()) };