import {z} from 'zod' export type GetApiApiV1LinkedinProjectsIdArgs = {account_id: string, id: string}; export type GetApiApiV1LinkedinProjectsIdOptions = {baseUrl?: string | undefined, AccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1LinkedinProjectsIdResponse = z.object({object: z.literal("RecruiterHiringProject"), id: z.string(), name: z.string(), archived: z.boolean(), owner_name: z.string(), owner_id: z.string(), created_at: z.string(), job_posting: z.object({id: z.string(), state: z.enum(["active", "draft", "review", "closed", "paused"]), title: z.string(), description: z.string().optional(), company: z.string().optional(), company_id: z.string().optional(), location: z.string(), applicants_counter: z.number(), views_counter: z.number().optional(), cost: z.number(), created_at: z.number().optional(), published_at: z.number().optional(), closed_at: z.number().optional(), apply_url: z.string().optional(), screening_questions: z.array(z.object({question: z.string(), favorableAnswers: z.array(z.string())})).optional(), hiring_team: z.array(z.object({name: z.string(), provider_id: z.union([z.string(), z.unknown()]), public_identifier: z.union([z.string(), z.unknown()]), profile_url: z.string(), can_send_free_inmail: z.boolean()})).optional(), salary: z.string().optional(), workplace: z.string().optional(), seniority: z.string().optional(), skills: z.array(z.string()).optional(), functions: z.array(z.string()).optional(), industries: z.array(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 }; /** * Retrieve Recruiter hiring project from ID * * GET /api/v1/linkedin/projects/{id} */ export const getApiApiV1LinkedinProjectsId = async (args: GetApiApiV1LinkedinProjectsIdArgs, options?: GetApiApiV1LinkedinProjectsIdOptions) => { const {baseUrl = "https://api1.unipile.com:13111", fetch: fetchFn = fetch, AccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.account_id != null) query.append("account_id", String(args.account_id)) if (AccessToken !== undefined) headers.set("X-API-KEY", AccessToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/linkedin/projects/${encodeURIComponent(String(args.id))}${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(getApiApiV1LinkedinProjectsIdResponse, await res.json()) };