import { getSearchConsoleClient } from '../client.js';
import { searchconsole_v1 } from 'googleapis';
import { limitConcurrency } from '../../common/concurrency.js';
/**
* Inspects a URL for a site to see its current indexing status in Google Search.
*
* @param siteUrl - The URL of the site as defined in Search Console.
* @param inspectionUrl - The specific URL to inspect.
* @param languageCode - The language used for localized results. Defaults to 'en-US'.
* @returns Comprehensive indexing and status information for the URL.
*/
export async function inspectUrl(
siteUrl: string,
inspectionUrl: string,
languageCode: string = 'en-US'
): Promise<searchconsole_v1.Schema$InspectUrlIndexResponse> {
const client = await getSearchConsoleClient();
const res = await client.urlInspection.index.inspect({
requestBody: {
inspectionUrl,
siteUrl,
languageCode
}
});
return res.data;
}
/**
* Inspects multiple URLs for a site in batch.
*
* @param siteUrl - The URL of the site as defined in Search Console.
* @param inspectionUrls - The list of URLs to inspect.
* @param languageCode - The language used for localized results. Defaults to 'en-US'.
* @returns An array of results, each containing the URL and its inspection result or error.
*/
export async function inspectBatch(
siteUrl: string,
inspectionUrls: string[],
languageCode: string = 'en-US'
): Promise<Array<{ url: string; result?: searchconsole_v1.Schema$InspectUrlIndexResponse; error?: string }>> {
return limitConcurrency(inspectionUrls, 5, async (url) => {
try {
const result = await inspectUrl(siteUrl, url, languageCode);
return { url, result };
} catch (error) {
return { url, error: (error as Error).message };
}
});
}