import {z} from 'zod' export type ClaimBreakdownQuery = {start_date: string, end_date: string, comparison_start_date?: (string | null) | undefined, comparison_end_date?: (string | null) | undefined, category_id: string, topic_ids?: (Array | null) | undefined, exclude_topic_ids?: boolean | undefined, tag_ids?: (Array | null) | undefined, tag_filter_type?: ('all' | 'any') | undefined, include_no_tag?: boolean | undefined, region_ids?: (Array | null) | undefined, platform_ids?: (Array | null) | undefined, persona_ids?: (Array | null) | undefined, include_no_persona?: boolean | undefined, prompt_ids?: (Array | null) | undefined, citation_categories?: (Array | null) | undefined, cluster_id: string}; export type CreateApiV1ReportsAccuracyClaimBreakdownArgs = {body: ClaimBreakdownQuery}; export type CreateApiV1ReportsAccuracyClaimBreakdownOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const claimBreakdownRow = z.object({id: z.string(), label: z.string(), responseCount: z.number().int(), totalResponseCount: z.number().int(), responseShare: z.number(), responseShareDelta: z.number().nullable().optional(), prevResponseCount: z.number().int(), prevTotalResponseCount: z.number().int()}); export const claimPromptBreakdownRow = z.object({id: z.string(), label: z.string(), responseCount: z.number().int(), totalResponseCount: z.number().int(), responseShare: z.number(), responseShareDelta: z.number().nullable().optional(), prevResponseCount: z.number().int(), prevTotalResponseCount: z.number().int(), promptId: z.string(), promptText: z.string(), topicId: z.string(), hasCurrent: z.boolean()}); export const claimBreakdownResponse = z.object({platform: z.array(claimBreakdownRow), prompt: z.array(claimPromptBreakdownRow)}); 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 }; /** * Accuracy Claim Breakdown * * POST /v1/reports/accuracy/claim-breakdown * * Also accepts auth: BearerAuth */ export const createApiV1ReportsAccuracyClaimBreakdown = async (args: CreateApiV1ReportsAccuracyClaimBreakdownArgs, options?: CreateApiV1ReportsAccuracyClaimBreakdownOptions) => { const {baseUrl = "https://api.tryprofound.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/reports/accuracy/claim-breakdown${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(claimBreakdownResponse, await res.json()) };