import {z} from 'zod' export type GetApiV3AiTrackerVisibilityBrandsNameArgs = {teamId?: string | undefined, platform?: string | undefined, competitor?: string | undefined, country?: string | undefined, startDate?: string | undefined, endDate?: string | undefined, days?: number | undefined, promptBrand?: string | undefined, tracking?: string | undefined, intent?: string | undefined, promptLimit?: string | undefined, includeResponseText?: string | undefined, name: string}; export type GetApiV3AiTrackerVisibilityBrandsNameOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV3AiTrackerVisibilityBrandsNameResponse = z.object({name: z.string().optional(), website: z.string().optional(), brandColor: z.string().optional(), mentions: z.number().optional(), mentionedPromptCount: z.number().optional(), trackedMentionedPromptCount: z.number().optional(), trackedPromptCount: z.number().optional(), promptCount: z.number().optional(), visibility: z.number().optional(), shareOfVoice: z.number().optional(), sentiment: z.number().optional(), citations: z.number().optional(), segment: z.string().optional(), history: z.array(z.record(z.string(), z.unknown())).optional(), sentimentBreakdown: z.record(z.string(), z.unknown()).optional(), isYou: z.boolean().optional(), prompts: z.array(z.record(z.string(), z.unknown())).optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Single brand summary across the filtered dataset * * GET /v3/ai-tracker/visibility/brands/{name} * * Also accepts auth: apiKey */ export const getApiV3AiTrackerVisibilityBrandsName = async (args: GetApiV3AiTrackerVisibilityBrandsNameArgs, options?: GetApiV3AiTrackerVisibilityBrandsNameOptions) => { const {baseUrl = "https://api.snowseo.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.platform != null) query.append("platform", String(args.platform)) if (args.competitor != null) query.append("competitor", String(args.competitor)) if (args.country != null) query.append("country", String(args.country)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.days != null) query.append("days", String(args.days)) if (args.promptBrand != null) query.append("promptBrand", String(args.promptBrand)) if (args.tracking != null) query.append("tracking", String(args.tracking)) if (args.intent != null) query.append("intent", String(args.intent)) if (args.promptLimit != null) query.append("promptLimit", String(args.promptLimit)) if (args.includeResponseText != null) query.append("includeResponseText", String(args.includeResponseText)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/ai-tracker/visibility/brands/${encodeURIComponent(String(args.name))}${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(getApiV3AiTrackerVisibilityBrandsNameResponse, await res.json()) };