import TinyURLSecurityVerifier from './TinyURLSecurityVerifier.mjs'; export type SitemapNamespace = { /** * - Defines if it's a namespace declaration or a raw root attribute. Defaults to 'xmlns'. */ type?: 'xmlns' | 'attribute'; /** * - The namespace prefix (e.g., 'example'). Used only if type is 'xmlns'. */ prefix?: string; /** * - The exact attribute name (e.g., 'xsi:schemaLocation'). Required if type is 'attribute'. */ name?: string; /** * - The namespace URI. Used if type is 'xmlns'. */ uri?: string; /** * - The attribute value. Used if type is 'attribute' (acts as an alias to 'uri' for flexibility). */ value?: string; }; export type NamespaceStrategy = (instance: TinySiteMap) => SitemapNamespace[]; export type CustomTagMap = { /** * - The tag name (key in the object, e.g., 'example:tag'). */ tag?: string; /** * - The content of the tag (value in the object). */ value?: string; }; export type SitemapEntry = { /** * - The absolute URL of the page (or relative path). */ loc: string; /** * - The last modified date in ISO 8601 format (e.g., '2023-10-27T10:00:00Z'). */ lastmod?: string; /** * - Frequency of change. */ changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never'; /** * - Importance of the URL (0.0 to 1.0). */ priority?: number; /** * - Custom XML tags to include in this entry. */ customTags?: CustomTagMap; }; export type SitemapIndexEntry = { /** * - The absolute URL of the sitemap file. */ loc: string; /** * - The last modified date in ISO 8601 format. */ lastmod?: string; }; export type SitemapConfig = { /** * - URL to XSL stylesheet. */ xslUrl?: string; xslUrlPathnameOnly?: boolean; /** * - Format lastmod as date only (YYYY-MM-DD). */ lastmodDateOnly?: boolean; /** * - The type of sitemap to generate. Defaults to 'normal'. */ type?: 'normal' | 'index'; /** * - The base URL of the website. */ baseUrl: string; /** * - Initial manual namespaces or root attributes. */ namespaces?: SitemapNamespace[]; /** * - Dynamic logic to provide namespaces. */ namespaceStrategy?: NamespaceStrategy; /** * - Array of entries. */ entries: SitemapEntry[] | SitemapIndexEntry[]; }; /** * @typedef {Object} SitemapNamespace * @property {'xmlns'|'attribute'} [type] - Defines if it's a namespace declaration or a raw root attribute. Defaults to 'xmlns'. * @property {string} [prefix] - The namespace prefix (e.g., 'example'). Used only if type is 'xmlns'. * @property {string} [name] - The exact attribute name (e.g., 'xsi:schemaLocation'). Required if type is 'attribute'. * @property {string} [uri] - The namespace URI. Used if type is 'xmlns'. * @property {string} [value] - The attribute value. Used if type is 'attribute' (acts as an alias to 'uri' for flexibility). */ /** * @typedef {(instance: TinySiteMap) => SitemapNamespace[]} NamespaceStrategy * A function that receives the TinySiteMap instance and returns an array of namespaces. */ /** * A map where keys are the XML tag names and values are the tag contents. * @typedef {Object} CustomTagMap * @property {string} [tag] - The tag name (key in the object, e.g., 'example:tag'). * @property {string} [value] - The content of the tag (value in the object). */ /** * @typedef {Object} SitemapEntry * @property {string} loc - The absolute URL of the page (or relative path). * @property {string} [lastmod] - The last modified date in ISO 8601 format (e.g., '2023-10-27T10:00:00Z'). * @property {'always'|'hourly'|'daily'|'weekly'|'monthly'|'yearly'|'never'} [changefreq] - Frequency of change. * @property {number} [priority] - Importance of the URL (0.0 to 1.0). * @property {CustomTagMap} [customTags] - Custom XML tags to include in this entry. */ /** * @typedef {Object} SitemapIndexEntry * @property {string} loc - The absolute URL of the sitemap file. * @property {string} [lastmod] - The last modified date in ISO 8601 format. */ /** * @typedef {Object} SitemapConfig * @property {string} [xslUrl] - URL to XSL stylesheet. * @property {boolean} [xslUrlPathnameOnly=true] * @property {boolean} [lastmodDateOnly] - Format lastmod as date only (YYYY-MM-DD). * @property {'normal'|'index'} [type] - The type of sitemap to generate. Defaults to 'normal'. * @property {string} baseUrl - The base URL of the website. * @property {SitemapNamespace[]} [namespaces] - Initial manual namespaces or root attributes. * @property {NamespaceStrategy} [namespaceStrategy] - Dynamic logic to provide namespaces. * @property {SitemapEntry[] | SitemapIndexEntry[]} entries - Array of entries. */ /** * A service to manage and generate secure XML sitemaps or sitemap indexes. * This class handles URL resolution, root attributes management, and XML escaping to prevent injection. */ declare class TinySiteMap { #private; /** * Gets the maximum number of URLs allowed in a single sitemap. * @returns {number} */ static get maxUrls(): number; /** * Sets the maximum number of URLs allowed in a single sitemap. * @param {number} value * @throws {TypeError} If the value is not a number. */ static set maxUrls(value: number); /** * @type {RegExp} Regex to validate XML Names/Prefixes. * * From package "sitemap.js" by Eugene Kalinin. * @reference https://github.com/ekalinin/sitemap.js/blob/1a782cf41e0d391299029c9e00c8bfa8cdaad212/lib/sitemap-xml.ts * */ static get xmlNameRegex(): RegExp; /** * Retrieves the URI for a specific namespace ID. * @param {string} id - The namespace identifier. * @returns {string|undefined} The namespace URI or undefined if not found. */ static getAttrVal(id: string): string | undefined; /** * Sets or updates a namespace URI for a specific ID. * @param {string} id - The namespace identifier. * @param {string} value - The namespace URI. * @throws {TypeError} If the ID or value are not strings. */ static setAttrVal(id: string, value: string): void; /** * Checks if a namespace ID exists. * @param {string} id - The namespace identifier. * @returns {boolean} True if it exists, false otherwise. */ static hasAttrVal(id: string): boolean; /** * Gets all namespaces as a plain object. * @returns {Record} A map of IDs to URIs. */ static get attrValues(): Record; /** * Replaces all current namespaces with a new set. * @param {Record} obj - The new namespace mapping. * @throws {TypeError} If the input is not a valid object or contains non-string values. */ static set attrValues(obj: Record); /** * Gets the total number of registered namespaces. * @returns {number} The count of namespaces. */ static get attrValuesSize(): number; /** * Clears all registered namespaces in the static attribute map. * Note: This affects all instances of TinySiteMap globally. */ static clearAttrValues(): void; /** * Initializes a new instance of the TinySiteMap class with the provided configuration. * @param {SitemapConfig} config - The configuration object. * @throws {TypeError} If the configuration is invalid. */ constructor(config: SitemapConfig); /** * Escapes special XML characters to prevent XML injection. * @param {string} str - The raw string to be escaped. * @param {boolean} isOtag * @reference https://github.com/ekalinin/sitemap.js/blob/1a782cf41e0d391299029c9e00c8bfa8cdaad212/lib/sitemap-xml.ts * @returns {string} The escaped string with characters like <, >, &, ", and ' replaced by entities. */ static escapeXml(str: string, isOtag: boolean): string; /** * Resolves relative URLs, validates all fields, and returns a new normalized object. * @param {SitemapEntry | SitemapIndexEntry} entry - The entry object to process. * @param {URL} baseUrl * @param {'normal'|'index'} type * @param {number} maxUrlSize * @param {RegExp} regex * @param {TinyURLSecurityVerifier} urlVerifier * @returns {SitemapEntry | SitemapIndexEntry} A new, normalized, and validated entry object. * @throws {TypeError} If the entry is invalid, if loc is not a string, if origin doesn't match, or if field values are invalid. * @throws {RangeError} If the resolved URL exceeds maxResolvedUrlSize or if priority is outside [0.0, 1.0]. */ static resolveAndValidate(entry: SitemapEntry | SitemapIndexEntry, baseUrl: URL, type: 'normal' | 'index', maxUrlSize: number, regex: RegExp, urlVerifier: TinyURLSecurityVerifier): SitemapEntry | SitemapIndexEntry; /** * Adds a namespace to the sitemap, preventing duplicate prefixes or attribute names. * @param {SitemapNamespace} ns - The namespace to add. * @throws {TypeError} If the namespace format is invalid. */ addNamespace(ns: SitemapNamespace): void; /** * Removes a namespace from the sitemap list by its identifier (prefix or name). * @param {string} identifier - The identifier to remove. */ removeNamespace(identifier: string): void; /** * Clears all manually added namespaces. */ clearNamespaces(): void; /** * Adds a new entry to the sitemap. * @param {SitemapEntry | SitemapIndexEntry} entry - The entry to add. * @param {number} [index] - The optional index at which to insert the entry. * @returns {number} The new length of the entries array. */ addEntry(entry: SitemapEntry | SitemapIndexEntry, index?: number): number; /** * Removes an entry from the sitemap by its index. * @param {number} index - The index of the entry to remove. * @returns {boolean} True if an element was removed, false otherwise. * @throws {RangeError} If the index is out of bounds. */ removeEntry(index: number): boolean; /** * Updates an existing entry with new data. * @param {number} index - The index of the entry to update. * @param {Partial} entryData - The partial data to merge into the existing entry. * @throws {RangeError} If the index is out of bounds. */ updateEntry(index: number, entryData: Partial): void; /** * Changes the position of an entry within the list. * @param {number} fromIndex - The index of the entry to move. * @param {number} toIndex - The index to move the entry to. * @throws {RangeError} If either index is out of bounds. */ moveEntry(fromIndex: number, toIndex: number): void; /** * Clears all manually added entries. */ clearEntries(): void; /** * Gets the URL security verifier. * @returns {TinyURLSecurityVerifier} */ get urlVerifier(): TinyURLSecurityVerifier; /** * Sets a dynamic strategy to provide namespaces based on the instance state. * @param {NamespaceStrategy} strategy - The strategy function. * @throws {TypeError} If the strategy is not a function. */ set namespaceStrategy(strategy: NamespaceStrategy); /** * Returns a copy of the manually added namespaces. * @returns {SitemapNamespace[]} */ get namespaces(): SitemapNamespace[]; /** * Sets the manual namespaces for the sitemap. * @param {SitemapNamespace[]} nss - The array of namespaces to set. * @throws {TypeError} If the namespaces array is invalid. */ set namespaces(nss: SitemapNamespace[]); /** * Gets the sitemap type. * @returns {'normal'|'index'} The type of sitemap. */ get type(): 'normal' | 'index'; /** * Gets the base URL. * @returns {URL} The copy of the base URL instance. */ get baseUrl(): URL; /** * Gets a shallow copy of the current entries. * @returns {SitemapEntry[] | SitemapIndexEntry[]} A copy of the entries array. */ get entries(): SitemapEntry[] | SitemapIndexEntry[]; /** * Sets the sitemap entries, validating each one via the addEntry method. * @param {SitemapEntry[] | SitemapIndexEntry[]} entries - The entries to set. * @throws {TypeError} If the entries is not an array. */ set entries(entries: SitemapEntry[] | SitemapIndexEntry[]); /** * Gets the maximum allowed URL size. * @returns {number} The current maximum size. */ get maxResolvedUrlSize(): number; /** * Sets the maximum allowed URL size. * @param {number} value - The new maximum size. * @throws {TypeError} If the provided value is not a non-negative number. */ set maxResolvedUrlSize(value: number); /** * Gets the current configuration state for 'lastmod' date formatting. * @returns {boolean} True if date-only formatting is enabled, false otherwise. */ get lastmodDateOnly(): boolean; /** * Sets whether the 'lastmod' field should be formatted as a simple date (YYYY-MM-DD) instead of full ISO 8601. * @param {boolean} value - True to use YYYY-MM-DD format, false to use full ISO 8601. * @throws {TypeError} If the provided value is not a boolean. */ set lastmodDateOnly(value: boolean); /** * Gets the URL of the XSL stylesheet used to style the XML output. * @returns {string|null} The XSL stylesheet URL or null. */ get xslUrl(): string | null; /** * Sets the URL of the XSL stylesheet used to style the XML output. * @param {string|null} value - The URL of the XSL stylesheet used to style the XML output. * @throws {TypeError} If the value is not a string or null. */ set xslUrl(value: string | null); /** * Gets whether the XSL URL is treated as a pathname only. * @returns {boolean} */ get xslUrlPathnameOnly(): boolean; /** * Sets whether the XSL URL is treated as a pathname only. * @param {boolean} value - Sets whether the XSL URL is treated as a pathname only. * @throws {TypeError} If the value is not a boolean. */ set xslUrlPathnameOnly(value: boolean); /** * Gets the total number of entries in the sitemap. * @returns {number} */ get entriesSize(): number; /** * Gets the total number of namespaces in the sitemap. * @returns {number} */ get namespacesSize(): number; /** * Resets the instance by clearing all entries and namespaces. */ clearAll(): void; /** * Generates the XML header. * @param {SitemapNamespace[]} namespaces * @param {string} [xslUrl] * @param {'normal'|'index'} [type] * @returns {string} */ static _generateHeader(namespaces: SitemapNamespace[], xslUrl?: string, type?: 'normal' | 'index'): string; /** * Generates the XML fragment for a single entry. * @param {SitemapEntry} entry * @param {'normal'|'index'} type * @param {boolean} [lastmodDateOnly=false] * @returns {string} */ static _generateEntry(entry: SitemapEntry, type: 'normal' | 'index', lastmodDateOnly?: boolean): string; /** * Generates the XML footer. * @param {'normal'|'index'} type * @returns {string} */ static _generateFooter(type: 'normal' | 'index'): string; /** * Generates the sitemap or sitemap index as a valid XML string. * @returns {string} The generated XML content. */ generateXml(): string; /** * Returns a namespace strategy that includes standard Google sitemaps namespaces (news, xhtml, image, and video). * * The function name is a fun reference to name of Eugene Kalinin. This strategy is inspired in the original "sitemap.js" package. * @reference https://github.com/ekalinin/sitemap.js/blob/1a782cf41e0d391299029c9e00c8bfa8cdaad212/lib/sitemap-stream.ts * @type {NamespaceStrategy} */ static kaliStrategy(): SitemapNamespace[]; /** * Returns a basic namespace strategy that only includes the default XML sitemap ROOT namespace. * @type {NamespaceStrategy} */ static simpleStrategy(): SitemapNamespace[]; /** * Returns a comprehensive namespace strategy that includes the ROOT, XSI, and schemaLocation namespaces, * and conditionally includes custom namespaces based on the sitemap instance state. * @reference https://www.sitemaps.org/protocol.html * @type {NamespaceStrategy} */ static protocolStrategy(instance: TinySiteMap): SitemapNamespace[]; } export default TinySiteMap; //# sourceMappingURL=TinySiteMap.d.mts.map