import {z} from 'zod' export type GetApiCustomerAnalyticsPostsArgs = {limit?: number | undefined, cursor?: string | undefined, monitoredProfileId?: string | undefined, monitoredProfileIds?: string | undefined, profileType?: ('TEAMMATE' | 'COMPETITOR' | 'INFLUENCER' | 'INVESTOR' | 'CUSTOM' | 'TARGET_ACCOUNT' | 'CUSTOMER' | 'PARTNER') | undefined, relationshipLabel?: string | undefined, source?: ('MEMBER_ONBOARDING' | 'MANUAL_WATCHLIST') | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, minIcpMatchPercent?: number | undefined, status?: ('any' | 'qualified' | 'unqualified') | undefined, query?: string | undefined, sort?: ('date' | 'engagement' | 'reactions' | 'comments' | 'reposts') | undefined, sortDirection?: ('asc' | 'desc') | undefined}; export type GetApiCustomerAnalyticsPostsOptions = {baseUrl?: string | undefined, CustomerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const pageEnvelope = z.object({data: z.array(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 post analytics, including safe postUrl and contentText. * * GET /customer/analytics/posts */ export const getApiCustomerAnalyticsPosts = async (args: GetApiCustomerAnalyticsPostsArgs, options?: GetApiCustomerAnalyticsPostsOptions) => { 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.monitoredProfileId != null) query.append("monitoredProfileId", String(args.monitoredProfileId)) if (args.monitoredProfileIds != null) query.append("monitoredProfileIds", String(args.monitoredProfileIds)) if (args.profileType != null) query.append("profileType", String(args.profileType)) if (args.relationshipLabel != null) query.append("relationshipLabel", String(args.relationshipLabel)) if (args.source != null) query.append("source", String(args.source)) 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.status != null) query.append("status", String(args.status)) if (args.query != null) query.append("query", String(args.query)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (CustomerApiKey !== undefined) headers.set('authorization', `Bearer ${CustomerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer/analytics/posts${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(pageEnvelope, await res.json()) };