import {z} from 'zod' export type GetApiCustomerLeadsLeadIdArgs = {leadId: string}; export type GetApiCustomerLeadsLeadIdOptions = {baseUrl?: string | undefined, CustomerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const leadSignal = z.object({summary: z.string().max(300), whyRelevant: z.string().max(500), topic: z.string().max(160).nullable(), type: z.enum(["COMPETITOR", "PAIN", "TRIGGER", "TOPIC", "CATEGORY_INTEREST", "CUSTOM", "GENERAL_ENGAGEMENT"]), strength: z.enum(["DIRECT", "CONTEXTUAL", "ACTIVITY"]), sentiment: z.enum(["NEGATIVE", "POSITIVE", "MIXED", "NEUTRAL", "UNKNOWN"]), occurredAt: z.string(), source: z.object({name: z.string().nullable(), title: z.string().nullable(), url: z.string().nullable()})}); export const lead = z.object({id: z.string(), icpMatchPercent: z.number().int().nullable().optional(), intentScore: z.number().optional(), leadTier: z.string().nullable().optional(), profile: z.object({displayName: z.string().nullable(), headline: z.string().nullable(), location: z.string().nullable(), currentCompany: z.string().nullable(), profileUrl: z.string().nullable()}), contact: z.object({workEmail: z.string().nullable(), workEmailStatus: z.string().nullable(), personalEmail: z.string().nullable(), personalEmailStatus: z.string().nullable(), contactPhone: z.string().nullable(), contactPhoneStatus: z.string().nullable()}).nullable(), signal: leadSignal.nullable()}); export const getApiCustomerLeadsLeadIdResponse = z.object({data: lead}); 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 one API-visible lead. * * GET /customer/leads/{leadId} */ export const getApiCustomerLeadsLeadId = async (args: GetApiCustomerLeadsLeadIdArgs, options?: GetApiCustomerLeadsLeadIdOptions) => { const {baseUrl = "https://api.traxy.ai/api/v1", fetch: fetchFn = fetch, CustomerApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (CustomerApiKey !== undefined) headers.set('authorization', `Bearer ${CustomerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer/leads/${encodeURIComponent(String(args.leadId))}${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(getApiCustomerLeadsLeadIdResponse, await res.json()) };