import {z} from 'zod' export type GetApiV3AiTrackerVisibilityPromptsIdArgs = {teamId?: string | undefined, startDate?: string | undefined, endDate?: string | undefined, id: string}; export type GetApiV3AiTrackerVisibilityPromptsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV3AiTrackerVisibilityPromptsIdResponse = z.object({id: z.string().optional(), prompt: z.string().optional(), status: z.string().optional(), region: z.record(z.string(), z.unknown()).nullable().optional(), isEnabled: z.boolean().optional(), isBranded: z.boolean().optional(), isPinned: z.boolean().optional(), intent: z.string().optional(), isOverdue: z.boolean().optional(), refreshedAt: z.string().nullable().optional(), regionVariants: z.array(z.record(z.string(), z.unknown())).optional(), responseCount: z.number().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), aiVisibilityScoreHistory: z.array(z.record(z.string(), z.unknown())).optional(), userBrandMentionsHistory: z.array(z.record(z.string(), z.unknown())).optional(), allBrandMentionsHistory: 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 }; /** * One tracked prompt in detail * * GET /v3/ai-tracker/visibility/prompts/{id} * * Also accepts auth: apiKey */ export const getApiV3AiTrackerVisibilityPromptsId = async (args: GetApiV3AiTrackerVisibilityPromptsIdArgs, options?: GetApiV3AiTrackerVisibilityPromptsIdOptions) => { 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.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/ai-tracker/visibility/prompts/${encodeURIComponent(String(args.id))}${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(getApiV3AiTrackerVisibilityPromptsIdResponse, await res.json()) };