export type EntityFilterClause = {op: 'is' | 'not_is' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'matches' | 'contains_case_insensitive' | 'not_contains_case_insensitive', value: string | Array}; export type FilterNode = {and?: (Array | null) | undefined, or?: (Array | null) | undefined, not?: (FilterNode | null) | undefined, field?: (string | null) | undefined, op?: (string | null) | undefined, value: unknown}; export type AppRoutesV2AnswerEngineInsightsReportsVisibilitySortSpec = {field?: ('visibility_score' | 'share_of_voice' | 'average_position') | undefined}; export type VisibilityV2Query = {category_id: string, start_date: string, end_date: string, group_by?: (Array<'date' | 'model' | 'topic' | 'region' | 'prompt' | 'persona'>) | undefined, metrics?: (Array<'visibility_score' | 'share_of_voice' | 'average_position'> | null) | undefined, interval?: ('day' | 'week' | 'month') | undefined, scope?: ('owned' | 'all') | undefined, assets?: (string | Array | EntityFilterClause | null) | undefined, filter?: (FilterNode | null) | undefined, sort?: AppRoutesV2AnswerEngineInsightsReportsVisibilitySortSpec | undefined, limit?: (number | null) | undefined, max_results?: (number | null) | undefined, cursor?: (string | null) | undefined}; export type CreateApiV2ReportsVisibilityStreamArgs = {body: VisibilityV2Query}; export type CreateApiV2ReportsVisibilityStreamOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream Visibility V2 * * POST /v2/reports/visibility/stream * * Also accepts auth: BearerAuth */ export const createApiV2ReportsVisibilityStream = async (args: CreateApiV2ReportsVisibilityStreamArgs, options?: CreateApiV2ReportsVisibilityStreamOptions) => { 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', "text/event-stream") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v2/reports/visibility/stream${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 res.text() };