import {z} from 'zod' export type GetApiV5PersonRetrievePersonIdArgs = {'Content-Type'?: 'application/json' | undefined, person_id: string, titlecase?: boolean | undefined}; export type GetApiV5PersonRetrievePersonIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const profiles = z.object({url: z.string().optional(), id: z.string().optional(), network: z.enum(["aboutme", "angellist", "behance", "crunchbase", "dribbble", "ello", "facebook", "flickr", "foursquare", "github", "gitlab", "google", "gravatar", "indeed", "instagram", "klout", "linkedin", "linkedin_sales_navigator", "medium", "meetup", "myspace", "pinterest", "quora", "reddit", "soundcloud", "stackoverflow", "twitter", "vimeo", "wordpress", "xing", "youtube"]).optional(), username: z.string().optional()}); export const personRetrieve = z.object({status: z.union([z.literal(200), z.literal(400), z.literal(401), z.literal(402), z.literal(404), z.literal(405), z.literal(429)]), data: profiles, billed: z.boolean(), metadata: z.object({}).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 }; /** * /person/retrieve * * GET /v5/person/retrieve/{person_id} */ export const getApiV5PersonRetrievePersonId = async (args: GetApiV5PersonRetrievePersonIdArgs, options?: GetApiV5PersonRetrievePersonIdOptions) => { const {baseUrl = "https://api.peopledatalabs.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.titlecase != null) query.append("titlecase", String(args.titlecase)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v5/person/retrieve/${encodeURIComponent(String(args.person_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(personRetrieve, await res.json()) };