import {z} from 'zod' export type GetApiCustomerLeadsSignalsArgs = {limit?: number | undefined, cursor?: string | undefined, leadId?: string | undefined, monitoredProfileId?: string | undefined, monitoredProfileIds?: string | undefined, postId?: string | undefined, engagementType?: ('LIKE' | 'COMMENT' | 'REPOST' | 'POST_AUTHOR') | undefined, engagementTypes?: string | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, minIcpMatchPercent?: number | undefined, maxIcpMatchPercent?: number | undefined, disposition?: ('ACTIVE' | 'CLIENT' | 'BAD_LEAD') | undefined, query?: string | undefined, companyNames?: string | undefined, profileType?: ('TEAMMATE' | 'COMPETITOR' | 'INFLUENCER' | 'INVESTOR' | 'CUSTOM' | 'TARGET_ACCOUNT' | 'CUSTOMER' | 'PARTNER') | undefined, relationshipLabel?: string | undefined, origin?: ('agent' | 'watchlist' | 'all') | undefined}; export type GetApiCustomerLeadsSignalsOptions = {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 leadSignalPage = z.object({data: z.array(z.object({id: z.string(), engagementType: z.enum(["LIKE", "COMMENT", "REPOST", "POST_AUTHOR"]), reactionType: z.string().nullable(), engagedAt: z.string(), capturedAt: z.string(), signal: leadSignal.nullable(), lead: lead, primarySignal: z.record(z.string(), z.unknown()), engagedWith: z.record(z.string(), z.unknown()), post: z.record(z.string(), z.unknown())}).and(z.record(z.string(), z.unknown()))), page: z.object({limit: z.number().int(), cursor: z.string().nullable().optional(), nextCursor: 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 }; /** * List visible lead signals with safe lead, post, and watched-profile context. * * GET /customer/leads/signals */ export const getApiCustomerLeadsSignals = async (args: GetApiCustomerLeadsSignalsArgs, options?: GetApiCustomerLeadsSignalsOptions) => { 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 (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.leadId != null) query.append("leadId", String(args.leadId)) if (args.monitoredProfileId != null) query.append("monitoredProfileId", String(args.monitoredProfileId)) if (args.monitoredProfileIds != null) query.append("monitoredProfileIds", String(args.monitoredProfileIds)) if (args.postId != null) query.append("postId", String(args.postId)) if (args.engagementType != null) query.append("engagementType", String(args.engagementType)) if (args.engagementTypes != null) query.append("engagementTypes", String(args.engagementTypes)) if (args.dateFrom != null) query.append("dateFrom", String(args.dateFrom)) if (args.dateTo != null) query.append("dateTo", String(args.dateTo)) if (args.minIcpMatchPercent != null) query.append("minIcpMatchPercent", String(args.minIcpMatchPercent)) if (args.maxIcpMatchPercent != null) query.append("maxIcpMatchPercent", String(args.maxIcpMatchPercent)) if (args.disposition != null) query.append("disposition", String(args.disposition)) if (args.query != null) query.append("query", String(args.query)) if (args.companyNames != null) query.append("companyNames", String(args.companyNames)) if (args.profileType != null) query.append("profileType", String(args.profileType)) if (args.relationshipLabel != null) query.append("relationshipLabel", String(args.relationshipLabel)) if (args.origin != null) query.append("origin", String(args.origin)) if (CustomerApiKey !== undefined) headers.set('authorization', `Bearer ${CustomerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer/leads/signals${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(leadSignalPage, await res.json()) };