import {z} from 'zod' export type GetApiApiV1LinkedinSearchParametersArgs = {limit?: number | undefined, keywords?: string | undefined, service?: ('CLASSIC' | 'RECRUITER' | 'SALES_NAVIGATOR') | undefined, type: 'LOCATION' | 'REGION' | 'PEOPLE' | 'CONNECTIONS' | 'COMPANY' | 'SCHOOL' | 'INDUSTRY' | 'SERVICE' | 'JOB_FUNCTION' | 'JOB_TITLE' | 'EMPLOYMENT_TYPE' | 'SKILL' | 'LANGUAGE' | 'POST_JOB_FUNCTION' | 'SENIORITY' | 'GROUPS' | 'SALES_INDUSTRY' | 'DEPARTMENT' | 'PERSONA' | 'ACCOUNT_LISTS' | 'LEAD_LISTS' | 'TECHNOLOGIES' | 'SAVED_ACCOUNTS' | 'SAVED_SEARCHES' | 'RECENT_SEARCHES' | 'REGION' | 'POSTAL_CODE' | 'GROUPS' | 'DEPARTMENT' | 'HIRING_PROJECTS' | 'SAVED_SEARCHES' | 'SAVED_FILTERS' | 'DEGREE' | 'SEATS', account_id: string}; export type GetApiApiV1LinkedinSearchParametersOptions = {baseUrl?: string | undefined, AccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1LinkedinSearchParametersResponse = z.object({object: z.literal("LinkedinSearchParametersList"), items: z.array(z.object({object: z.literal("LinkedinSearchParameter"), id: z.string().min(1), title: z.string(), picture_url: z.string().optional(), additional_data: z.record(z.string(), z.unknown()).optional()})), paging: z.object({page_count: 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 }; /** * Retrieve LinkedIn search parameters * * GET /api/v1/linkedin/search/parameters */ export const getApiApiV1LinkedinSearchParameters = async (args: GetApiApiV1LinkedinSearchParametersArgs, options?: GetApiApiV1LinkedinSearchParametersOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.keywords != null) query.append("keywords", String(args.keywords)) if (args.service != null) query.append("service", String(args.service)) if (args.type != null) query.append("type", String(args.type)) 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/search/parameters${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(getApiApiV1LinkedinSearchParametersResponse, await res.json()) };