import { GscResponseAggregationType, GscSearchAnalyticsMetadata } from "../contracts.mjs"; import { Dimension, GSCRow } from "../query/types.mjs"; import { GSCQueryBuilder } from "../query/builder.mjs"; import { ApiSite, ApiSitemap, InspectUrlIndexResponse, PublishUrlNotificationResponse, SearchAnalyticsQuery, SearchAnalyticsResponse, UrlNotificationMetadata } from "./types.mjs"; import { $Fetch, FetchOptions } from "ofetch"; /** Default deadline for each direct Google API request. */ declare const DEFAULT_GSC_REQUEST_TIMEOUT_MS = 30000; type VerificationMethod = 'META' | 'FILE' | 'DNS_TXT' | 'DNS_CNAME' | 'ANALYTICS' | 'TAG_MANAGER'; type VerificationSiteType = 'SITE' | 'INET_DOMAIN' | 'ANDROID_APP'; interface VerificationSite { type: VerificationSiteType; identifier: string; } interface VerificationToken { method: string; token: string; } interface VerificationWebResource { id?: string; site: VerificationSite; owners?: string[]; } /** * Compatible interface with OAuth2Client from google-auth-library */ interface AuthClient { credentials?: { access_token?: string | null; refresh_token?: string | null; expiry_date?: number | null; }; getAccessToken: () => Promise<{ token?: string | null; }>; } interface AuthOptions { clientId: string; clientSecret: string; refreshToken: string; } declare function createAuth(options: AuthOptions): AuthClient; /** Auth can be a token string, object with accessToken, or OAuth2Client-like object with credentials */ type Auth = string | { accessToken: string; } | AuthClient | AuthOptions; declare function createFetch(auth: Auth, options?: FetchOptions): $Fetch; /** Per-call options. `signal` cancels the in-flight request (and, for `query`, the next page too). */ interface CallOptions { signal?: AbortSignal; } /** Generator return value for `client.query` — exposes API response metadata plus the resolved aggregation type Google actually used (may differ from the requested `aggregationType: 'auto'`). */ interface QueryReturn { metadata?: GscSearchAnalyticsMetadata; /** Aggregation type Google actually used. Useful when requesting `auto` to know if rows were aggregated `byPage` vs `byProperty`. */ responseAggregationType?: GscResponseAggregationType; } interface GoogleSearchConsoleClient { /** Query search analytics with builder, returns async generator yielding typed row batches */ query: (siteUrl: string, builder: GSCQueryBuilder, opts?: CallOptions) => AsyncGenerator[], QueryReturn>; /** * List all sites. Also exposes write ops as `client.sites.add(siteUrl)` and * `client.sites.delete(siteUrl)`. Calling `client.sites()` is equivalent to * `client.sites.list()`. */ sites: ((opts?: CallOptions) => Promise) & { list: (opts?: CallOptions) => Promise; /** Retrieve a single property (with permission level). 404 if not in the user's account. */ get: (siteUrl: string, opts?: CallOptions) => Promise; /** Add a property in unverified state. Caller must verify ownership separately. */ add: (siteUrl: string, opts?: CallOptions) => Promise; /** Remove a property from the user's account. */ delete: (siteUrl: string, opts?: CallOptions) => Promise; }; /** Site Verification API (siteverification.googleapis.com). Required to flip a property from unverified to verified. */ verification: { /** Returns the token to place on the site/DNS, plus the resolved method. */ getToken: (params: { site: VerificationSite; verificationMethod: VerificationMethod; }, opts?: CallOptions) => Promise; /** Triggers Google to fetch + validate; returns the verified WebResource. */ insert: (params: { site: VerificationSite; verificationMethod: VerificationMethod; }, opts?: CallOptions) => Promise; list: (opts?: CallOptions) => Promise; get: (id: string, opts?: CallOptions) => Promise; delete: (id: string, opts?: CallOptions) => Promise; }; /** Inspect a URL. `languageCode` is a BCP-47 tag for translating result strings; omit to let Google pick. */ inspect: (siteUrl: string, url: string, opts?: CallOptions & { languageCode?: string; }) => Promise; /** Sitemap operations */ sitemaps: { /** List sitemaps. Pass `sitemapIndex` to list children of a sitemap-index file. */ list: (siteUrl: string, opts?: CallOptions & { sitemapIndex?: string; }) => Promise; get: (siteUrl: string, feedpath: string, opts?: CallOptions) => Promise; submit: (siteUrl: string, feedpath: string, opts?: CallOptions) => Promise; delete: (siteUrl: string, feedpath: string, opts?: CallOptions) => Promise; }; /** Indexing API operations */ indexing: { publish: (url: string, type: 'URL_UPDATED' | 'URL_DELETED', opts?: CallOptions) => Promise; getMetadata: (url: string, opts?: CallOptions) => Promise; }; /** Direct Search Analytics API operations for callers that already have a request body. */ searchAnalytics: { query: (siteUrl: string, body: SearchAnalyticsQuery, opts?: CallOptions) => Promise; }; } interface GoogleSearchConsoleClientOptions { fetchOptions?: FetchOptions; fetch?: $Fetch; onRateLimited?: (context: { response: Response; }) => void | Promise; } declare function googleSearchConsole(auth: Auth, options?: GoogleSearchConsoleClientOptions): GoogleSearchConsoleClient; export { Auth, AuthClient, AuthOptions, CallOptions, DEFAULT_GSC_REQUEST_TIMEOUT_MS, GoogleSearchConsoleClient, GoogleSearchConsoleClientOptions, QueryReturn, VerificationMethod, VerificationSite, VerificationSiteType, VerificationToken, VerificationWebResource, createAuth, createFetch, googleSearchConsole };