UNPKG

indexnow

Version:

An IndexNow wrapper for TypeScript/JavaScript.

83 lines (82 loc) 2.8 kB
/** * The default TypeScript libs do not include `crypto.randomUUID`. * So we explicitly declare it here. * @see {@link https://github.com/denoland/deno/issues/12754#issuecomment-968170353 | TypeScript issue} */ declare global { interface Crypto { randomUUID: () => string; } } /** * The body of the request being sent to the search engine. */ export interface IndexNowBody { host: string; key: string; keyLocation?: string; urlList: string[]; } /** * The key verifies ownership of the host. */ export interface Ownership { key: string; /** Optional value for key file location */ keyLocation?: string; } /** * Currently, only the following search engines are supported: * - Bing * - Yandex * @see {@link https://www.indexnow.org/faq | Supported search engines} */ export declare const SEARCH_ENGINES: { BING: string; YANDEX: string; }; /** * Generate a key to be used for IndexNow. * @returns A random string of characters to be used as a key. */ export declare function generateKey(): string; /** * The IndexNow class is used to access the IndexNow API. */ export default class IndexNow { readonly engine: string; private ownership; /** * Create a new IndexNow instance. * @param engine The search engine's IndexNow url. * @param key The key to be used for IndexNow. * @param keyLocation Optional value for key file location. */ constructor(engine: string, key: string, keyLocation?: string); /** * Submit a url to the search engine. * @param url The url to be indexed. * @returns A promise that resolves if the url was successfully submitted. * @throws {Error} If the request fails. */ submitUrl(url: string): Promise<void>; /** * Submit a list of urls to the search engine IndexNow API. * @param host The host to be indexed. * @param urlList The list of urls to be indexed. * @returns A promise that resolves if the urls were successfully submitted. * @throws {Error} If no urls were supplied. * @throws {Error} If more than 10,000 urls were supplied. * @throws {Error} If the request fails. */ submitUrls(host: string, urlList: string[]): Promise<void>; } /** * Perform an IndexNow request. * @param toIndex The url or list of urls to be indexed. If a list of urls is supplied, the first url will be used as the host and not submitted. * @param engine The search engine IndexNow url. * @param key The key to be used for IndexNow. * @param keyLocation Optional value for key file location. * @returns A promise that resolves if the urls were successfully submitted. */ export declare function indexNow(toIndex: string | string[], engine: string, key: string, keyLocation?: string): Promise<void>;