import {z} from 'zod' export type Pagination = {limit?: number | undefined, offset?: number | undefined}; export type NumericMetricFilter = {field: string, operator: '>' | '>=' | '<' | '<=' | '=' | '==' | '!=', value: number | number}; export type PathFilter = {field: 'path', operator: 'is' | 'not_is' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'matches' | 'contains_case_insensitive' | 'not_contains_case_insensitive', value: string | Array}; export type BotNameFilter = {field: 'bot_name', operator: 'is' | 'not_is' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'matches' | 'contains_case_insensitive' | 'not_contains_case_insensitive', value: 'Amazonbot' | 'ClaudeBot' | 'Claude-User' | 'Claude-SearchBot' | 'Applebot' | 'Applebot-Extended' | 'Bytespider' | 'DeepSeek' | 'DuckAssistBot' | 'DuckDuckBot' | 'Googlebot' | 'Googlebot-News' | 'Googlebot-Video' | 'Googlebot-Image' | 'Google-Extended' | 'Storebot-Google' | 'Google-CloudVertexBot' | 'meta-externalfetcher' | 'meta-externalagent' | 'bingbot' | 'MicrosoftPreview' | 'ChatGPT-User' | 'GPTBot' | 'OAI-SearchBot' | 'OAI-Operator' | 'PerplexityBot' | 'Perplexity-User' | 'Grok-PageBrowser' | 'YouBot' | 'OpenClaw' | 'baiduspider' | 'CCBot' | 'ERNIEBot' | 'Gemini-Fetch' | 'YandexBot' | 'PetalBot' | 'MistralAI-User' | 'Slurp' | 'Gemini-Deep-Research' | Array<'Amazonbot' | 'ClaudeBot' | 'Claude-User' | 'Claude-SearchBot' | 'Applebot' | 'Applebot-Extended' | 'Bytespider' | 'DeepSeek' | 'DuckAssistBot' | 'DuckDuckBot' | 'Googlebot' | 'Googlebot-News' | 'Googlebot-Video' | 'Googlebot-Image' | 'Google-Extended' | 'Storebot-Google' | 'Google-CloudVertexBot' | 'meta-externalfetcher' | 'meta-externalagent' | 'bingbot' | 'MicrosoftPreview' | 'ChatGPT-User' | 'GPTBot' | 'OAI-SearchBot' | 'OAI-Operator' | 'PerplexityBot' | 'Perplexity-User' | 'Grok-PageBrowser' | 'YouBot' | 'OpenClaw' | 'baiduspider' | 'CCBot' | 'ERNIEBot' | 'Gemini-Fetch' | 'YandexBot' | 'PetalBot' | 'MistralAI-User' | 'Slurp' | 'Gemini-Deep-Research'>}; export type BotProviderFilter = {field: 'bot_provider', operator: 'is' | 'not_is' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'matches' | 'contains_case_insensitive' | 'not_contains_case_insensitive', value: 'openai' | 'anthropic' | 'chatgpt' | 'deepseek' | 'google' | 'microsoft' | 'perplexity' | 'apple' | 'bytedance' | 'amazon' | 'meta' | 'duckduckgo' | 'you' | 'xai' | 'grok' | 'gemini' | 'mistral' | 'huawei' | 'yandex' | 'baidu' | 'yahoo' | 'commoncrawl' | 'openclaw' | Array<'openai' | 'anthropic' | 'chatgpt' | 'deepseek' | 'google' | 'microsoft' | 'perplexity' | 'apple' | 'bytedance' | 'amazon' | 'meta' | 'duckduckgo' | 'you' | 'xai' | 'grok' | 'gemini' | 'mistral' | 'huawei' | 'yandex' | 'baidu' | 'yahoo' | 'commoncrawl' | 'openclaw'>}; export type BotsReportQuery = {date_interval?: ('hour' | 'day' | 'week' | 'month' | 'year' | 'relative_week') | undefined, dimensions?: (Array<'date' | 'path' | 'bot_name' | 'bot_provider'>) | undefined, metrics: Array<'count' | 'citations' | 'indexing' | 'training' | 'last_visit'>, order_by?: ({[key: string]: 'asc' | 'desc'}) | undefined, pagination?: Pagination | undefined, domain: string, start_date: string, end_date?: string | undefined, organization_id?: (string | null) | undefined, metric_filters?: Array | undefined, filters?: (Array) | undefined}; export type CreateApiV1ReportsBotsArgs = {body: BotsReportQuery}; export type CreateApiV1ReportsBotsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const info = z.object({total_rows: z.number().int(), query: z.record(z.string(), z.unknown()).nullable().optional()}); export const result = z.object({metrics: z.array(z.union([z.number().int(), z.number()])), dimensions: z.array(z.union([z.string(), z.string()]))}); export const response = z.object({info: info, data: z.array(result)}); 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 Bots Report V1 * * POST /v1/reports/bots * * Also accepts auth: BearerAuth */ export const createApiV1ReportsBots = async (args: CreateApiV1ReportsBotsArgs, options?: CreateApiV1ReportsBotsOptions) => { 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/bots${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(response, await res.json()) };