import {z} from 'zod' export type CreateApiApiV1LinkedinJobsArgs = {body: {account_id: string, job_title: {id?: string | undefined, text?: string | undefined}, company: {id?: string | undefined, text?: string | undefined}, workplace: 'ON_SITE' | 'HYBRID' | 'REMOTE', location: string, employment_status?: ('FULL_TIME' | 'PART_TIME' | 'CONTRACT' | 'TEMPORARY' | 'OTHER' | 'VOLUNTEER' | 'INTERNSHIP') | undefined, description: string, auto_rejection_template?: string | undefined, screening_questions?: (Array<{question: string, position?: number | undefined, must_match?: boolean | undefined, answer_type: 'numeric', min_expectation?: number | undefined, max_expectation?: number | undefined} | {question: string, position?: number | undefined, must_match?: boolean | undefined, answer_type: 'multiple_choices', choices: Array, expected_choices: Array}>) | undefined, apply_method?: ({type: 'linkedin', notification_email: string} | {type: 'external', url: string}) | undefined, recruiter?: ({project: {id: string} | {name: string}, functions: Array, industries: Array, skills?: Array | undefined, seniority: 'INTERNSHIP' | 'ENTRY_LEVEL' | 'ASSOCIATE' | 'MID_SENIOR_LEVEL' | 'DIRECTOR' | 'EXECUTIVE' | 'NOT_APPLICABLE', include_poster_info?: boolean | undefined, tracking_pixel_url?: string | undefined, company_job_id?: string | undefined, apply_method: {type: 'linkedin', notification_email: string, resume_required: boolean} | {type: 'external', url: string}, salary?: ({currency: string, min: number, max: number, pay_frequency: 'YEARLY' | 'MONTHLY' | 'HOURLY'}) | undefined, additional_compensation?: ({currency: string, min: number, max: number, pay_frequency: 'YEARLY' | 'MONTHLY' | 'HOURLY'}) | undefined, auto_archive_applicants?: ({screening_questions?: boolean | undefined, outside_of_country?: boolean | undefined}) | undefined, send_rejection_notification?: boolean | undefined}) | undefined}}; export type CreateApiApiV1LinkedinJobsOptions = {baseUrl?: string | undefined, AccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1LinkedinJobsResponse = z.object({object: z.literal("LinkedinJobPostingDraftCreated"), job_id: z.string(), project_id: z.string().optional(), publish_options: z.object({free: z.object({eligible: z.boolean(), ineligible_reason: z.union([z.string(), z.unknown()]), estimated_monthly_applicants: z.number()}), promoted: z.object({estimated_monthly_applicants: z.number(), currency: z.string(), daily_budget: z.object({min: z.number(), max: z.number(), recommended: z.number()}), monthly_budget: z.object({min: z.number(), max: z.number(), recommended: z.number()})})})}); 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 }; /** * Create a job posting * * POST /api/v1/linkedin/jobs */ export const createApiApiV1LinkedinJobs = async (args: CreateApiApiV1LinkedinJobsArgs, options?: CreateApiApiV1LinkedinJobsOptions) => { const {baseUrl = "https://api1.unipile.com:13111", fetch: fetchFn = fetch, AccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AccessToken !== undefined) headers.set("X-API-KEY", AccessToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/linkedin/jobs${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(createApiApiV1LinkedinJobsResponse, await res.json()) };