import {z} from 'zod' export type GetApiApiV1PeopleIdArgs = {id: string}; export type GetApiApiV1PeopleIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PeopleIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable(), middleName: z.string().nullable(), avatarUrl: z.string().nullable(), isContact: z.boolean(), companyContact: z.object({id: z.string(), companyId: z.string(), relationship: z.enum(["client", "prospect", "none"]), title: z.string().nullable()}).nullable(), gender: z.enum(["male", "female", "null"]).nullable(), source: z.object({system: z.string().nullable(), externalId: z.string().nullable()}).nullable(), identities: z.array(z.object({type: z.string(), value: z.string(), isPersonal: z.boolean(), isPrimary: z.boolean()})), headline: z.object({role: z.string().nullable(), company: z.string().nullable(), companyId: z.string().nullable(), roleStartedAt: z.string().nullable()}).nullable(), address: z.object({raw: z.string().nullable(), streetAddress: z.string().nullable(), addressLine2: z.string().nullable(), city: z.string().nullable(), region: z.string().nullable(), postalCode: z.string().nullable(), country: z.string().nullable(), metro: z.string().nullable(), formattedAddress: z.string().nullable(), latitude: z.number().nullable(), longitude: z.number().nullable()}).nullable(), experience: z.array(z.object({companyName: z.string(), companyId: z.string().nullable(), companyLinkedinId: z.string().nullable(), companyDomain: z.string().nullable(), role: z.string(), description: z.string().nullable(), startDate: z.string().nullable(), endDate: z.string().nullable()})), education: z.array(z.object({institutionName: z.string(), degree: z.string().nullable(), fieldOfStudy: z.string().nullable(), grade: z.string().nullable(), description: z.string().nullable(), startDate: z.string().nullable(), endDate: z.string().nullable()})), compensation: z.array(z.object({type: z.enum(["actual", "expected"]), taxMethod: z.string().nullable(), currency: z.string().nullable(), relevantDate: z.string().nullable(), basicSalary: z.number().nullable(), bonusSalary: z.number().nullable(), totalSalary: z.number().nullable(), expectedSalaryMin: z.number().nullable(), expectedSalaryMax: z.number().nullable(), expectedBonusSalaryMin: z.number().nullable(), expectedBonusSalaryMax: z.number().nullable()})), customAttributes: z.array(z.object({attributeId: z.string(), attributeName: z.string().nullable(), attributeType: z.string().nullable(), values: z.array(z.union([z.string(), z.number(), z.object({optionId: z.string(), optionValue: z.string().nullable()})]))})), enrichmentStatus: z.enum(["none", "in_progress", "failed", "completed"]), createdAt: z.string(), updatedAt: z.string(), merged: z.object({fromId: z.string(), toId: 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 a person by ID * * GET /api/v1/people/{id} */ export const getApiApiV1PeopleId = async (args: GetApiApiV1PeopleIdArgs, options: GetApiApiV1PeopleIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/people/${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(getApiApiV1PeopleIdResponse, await res.json()) };