import { Feature, Geometry, FeatureCollection, MultiLineString, LineString } from 'geojson'; import { Topology } from 'topojson-specification'; import { GeoPath, GeoProjection } from 'd3-geo'; import { ZoomTransform } from 'd3-zoom'; type Longitude = number & { __brand: 'longitude'; }; type Latitude = number & { __brand: 'latitude'; }; type Coordinates = [Longitude, Latitude]; type TypeGuard = (value: unknown) => value is T; type GeographyError = Error & { type: 'GEOGRAPHY_LOAD_ERROR' | 'GEOGRAPHY_PARSE_ERROR' | 'PROJECTION_ERROR' | 'VALIDATION_ERROR' | 'SECURITY_ERROR' | 'CONFIGURATION_ERROR' | 'CONTEXT_ERROR'; geography?: string; details?: Record; timestamp?: string; }; interface PreparedFeature extends Feature { svgPath: string; rsmKey: string; } /** * Calculates coordinates from zoom transform * @param w - Width of the map * @param h - Height of the map * @param t - Zoom transform object * @returns Branded coordinates */ declare function getCoords(w: number, h: number, t: ZoomTransform): Coordinates; /** * Fetch geography data with full security validation. * * @deprecated Since v2.1.0 — use {@link fetchGeographiesCache} instead for * cached, secure fetching. This function now delegates to the hardened pipeline * but swallows errors for backward compatibility. * * @param url - The URL to fetch geography data from * @returns Promise resolving to geography data or undefined on error */ declare function fetchGeographies(url: string): Promise; /** * Secure, cached geography fetching with comprehensive validation * This function is cached using React's cache() for optimal performance */ declare const fetchGeographiesCache: (url: string) => Promise; /** * Preloads geography data for better performance * @param url - The URL to preload */ declare function preloadGeography(url: string): void; type MeshGeometry = MultiLineString | LineString; /** * Checks if the input is a string (URL) * @param geo - Geography data or URL * @returns True if input is a string */ declare function isString(geo: string | Topology | FeatureCollection | Feature[]): geo is string; /** * Extracts features from various geography data formats * @param geographies - Geography data (Topology, FeatureCollection, or Feature array) * @param parseGeographies - Optional parser function for features * @returns Array of features */ declare function getFeatures(geographies: Topology | FeatureCollection | Feature[], parseGeographies?: (geographies: Feature[]) => Feature[]): Feature[]; /** * Extracts mesh data from geography data * @param geographies - Geography data (only Topology supports mesh) * @returns Mesh data or null */ declare function getMesh(geographies: Topology | FeatureCollection | Feature[]): { outline: MeshGeometry | null; borders: MeshGeometry | null; } | null; /** * Prepares mesh data by generating SVG paths * @param outline - Outline geometry * @param borders - Borders geometry * @param path - D3 path generator * @returns Object with SVG path strings */ declare function prepareMesh(outline: MeshGeometry | null, borders: MeshGeometry | null, path: GeoPath): { outline?: string; borders?: string; }; /** * Prepares features by generating SVG paths for each feature * @param features - Array of features to prepare * @param path - D3 path generator * @returns Array of prepared features with SVG paths */ declare function prepareFeatures(features: Feature[] | undefined, path: GeoPath): PreparedFeature[]; /** * Creates a connector path between two coordinates * @param start - Starting coordinates [longitude, latitude] * @param end - Ending coordinates [longitude, latitude] * @param curve - D3 curve function for path interpolation * @returns SVG path string */ declare function createConnectorPath(start: [number, number], end: [number, number], curve: unknown): string; interface GeographySecurityConfig { TIMEOUT_MS: number; MAX_RESPONSE_SIZE: number; ALLOWED_CONTENT_TYPES: readonly string[]; ALLOWED_PROTOCOLS: readonly string[]; ALLOW_HTTP_LOCALHOST: boolean; STRICT_HTTPS_ONLY: boolean; } declare const DEFAULT_GEOGRAPHY_FETCH_CONFIG: GeographySecurityConfig; declare const DEVELOPMENT_GEOGRAPHY_FETCH_CONFIG: GeographySecurityConfig; /** * Configure geography fetching security settings * @param config - Security configuration to apply */ /** * Updates the shared module-level geography security configuration. * * This setting is global to the current module instance. In SSR or other * long-lived shared runtimes, changing it affects subsequent consumers that * import the same package instance. */ declare function configureGeographySecurity(config: Partial): void; /** * Enable development mode with relaxed security (use with caution) * @param allowHttpLocalhost - Whether to allow HTTP for localhost */ declare function enableDevelopmentMode(allowHttpLocalhost?: boolean): void; /** * Validates a geography URL for security and format compliance * @param url - The URL to validate * @throws {Error} If the URL is invalid or insecure */ declare function validateGeographyUrl(url: string, config?: GeographySecurityConfig): void; /** * Validates response content type * @param response - The fetch response to validate * @throws {Error} If content type is invalid */ declare function validateContentType(response: Response, config?: GeographySecurityConfig): void; /** * Fast pre-check of Content-Length header to reject obviously oversized responses. * NOTE: This is only a pre-check — the header can be omitted or falsified. * Use {@link readResponseWithSizeLimit} for authoritative enforcement. * @param response - The fetch response to validate * @throws {Error} If Content-Length exceeds the configured maximum */ declare function validateResponseSize(response: Response, config?: GeographySecurityConfig): Promise; /** * Reads the response body as an ArrayBuffer while enforcing a hard byte-count limit. * Protects against responses that omit or falsify Content-Length. * @param response - The fetch response to read * @param maxBytes - Maximum allowed bytes (defaults to GEOGRAPHY_FETCH_CONFIG.MAX_RESPONSE_SIZE) * @returns The response body as ArrayBuffer * @throws {Error} If the body exceeds the byte limit */ declare function readResponseWithSizeLimit(response: Response, maxBytes?: number): Promise; /** * Validates that the parsed data is a valid geography object * @param data - The parsed JSON data to validate * @throws {Error} If data is not a valid geography object */ declare function validateGeographyData(data: unknown): void; /** * Creates a standardized geography fetch error * @param type - Error type * @param message - Error message * @param url - URL that caused the error (optional) * @param originalError - Original error that caused this error (optional) * @returns GeographyError instance */ declare function createGeographyFetchError(type: GeographyError['type'], message: string, url?: string, originalError?: Error): GeographyError; /** * Subresource Integrity (SRI) configuration for external geography data */ interface SRIConfig { algorithm: 'sha256' | 'sha384' | 'sha512'; hash: string; enforceIntegrity: boolean; } /** * Known SRI hashes for common geography data sources * These hashes are automatically generated and verified * Run 'npm run generate-sri' to update these hashes */ declare const KNOWN_GEOGRAPHY_SRI: Record; /** * Configuration for SRI enforcement */ interface SRIEnforcementConfig { enforceForKnownSources: boolean; enforceForAllSources: boolean; allowUnknownSources: boolean; customSRIMap: Record; } declare const DEFAULT_SRI_CONFIG: SRIEnforcementConfig; /** * Configure SRI enforcement settings * @param config - SRI enforcement configuration */ declare function configureSRI(config: Partial): void; /** * Enable strict SRI mode (enforce for all sources) */ declare function enableStrictSRI(): void; /** * Disable SRI enforcement (not recommended for production) */ declare function disableSRI(): void; /** * Validate response integrity using SRI * @param response - Fetch response to validate * @param url - URL of the resource * @param expectedSRI - Expected SRI configuration * @returns Promise resolving to validated response */ declare function validateSRI(response: Response, url: string, expectedSRI: SRIConfig): Promise; /** * Check if SRI validation is required for a URL. * The URL is canonicalized (fragment stripped, host lowercased, default port * removed) before lookup so that trivial URL variants don't bypass known * SRI entries. * * @param url - URL to check * @returns SRI configuration if validation is required, null otherwise */ declare function getSRIForUrl(url: string, config?: SRIEnforcementConfig): SRIConfig | null; /** * Add custom SRI configuration for a URL * @param url - URL to add SRI for * @param sri - SRI configuration */ declare function addCustomSRI(url: string, sri: SRIConfig): void; /** * Generate SRI hash for a given URL (utility for developers) * This function fetches the resource and calculates its hash * @param url - URL to generate SRI for * @param algorithm - Hash algorithm to use * @returns Promise resolving to SRI hash string */ declare function generateSRIHash(url: string, algorithm?: 'sha256' | 'sha384' | 'sha512'): Promise; /** * Validate multiple URLs and generate SRI configuration * Utility function for setting up SRI for multiple geography sources * @param urls - Array of URLs to generate SRI for * @param algorithm - Hash algorithm to use * @returns Promise resolving to SRI configuration map */ declare function generateSRIForUrls(urls: string[], algorithm?: 'sha256' | 'sha384' | 'sha512'): Promise>; declare function isTopology(value: unknown): value is Topology; declare function isFeatureCollection(value: unknown): value is FeatureCollection; declare function isFeature(value: unknown): value is Feature; declare function isValidGeometry(value: unknown): value is Geometry; declare function isValidLongitude(value: unknown): value is Longitude; declare function isValidLatitude(value: unknown): value is Latitude; declare function isValidCoordinates(value: unknown): value is Coordinates; declare function isGeoProjection(value: unknown): value is GeoProjection; declare function isProjectionName(value: unknown): value is string; declare function isGeographyError(error: unknown): error is GeographyError; declare function isValidGeographyUrl(value: unknown): value is string; declare function isValidGeographyData(value: unknown): value is Topology | FeatureCollection; declare function isValidMapDimensions(width: unknown, height: unknown): boolean; declare function createTypeGuard(predicate: (value: unknown) => boolean): TypeGuard; declare function createGeographyError(type: GeographyError['type'], message: string, geography?: string, details?: Record): GeographyError; declare function createValidationError(message: string, geography?: string, details?: Record): GeographyError; declare function createSecurityError(message: string, geography?: string, details?: Record): GeographyError; declare function createProjectionError(message: string, geography?: string, details?: Record): GeographyError; declare function createConfigurationError(message: string, geography?: string, details?: Record): GeographyError; declare function createContextError(message: string, geography?: string, details?: Record): GeographyError; export { DEFAULT_GEOGRAPHY_FETCH_CONFIG, DEFAULT_SRI_CONFIG, DEVELOPMENT_GEOGRAPHY_FETCH_CONFIG, KNOWN_GEOGRAPHY_SRI, addCustomSRI, configureGeographySecurity, configureSRI, createConfigurationError, createConnectorPath, createContextError, createGeographyError, createGeographyFetchError, createProjectionError, createSecurityError, createTypeGuard, createValidationError, disableSRI, enableDevelopmentMode, enableStrictSRI, fetchGeographies, fetchGeographiesCache, generateSRIForUrls, generateSRIHash, getCoords, getFeatures, getMesh, getSRIForUrl, isFeature, isFeatureCollection, isGeoProjection, isGeographyError, isProjectionName, isString, isTopology, isValidCoordinates, isValidGeographyData, isValidGeographyUrl, isValidGeometry, isValidLatitude, isValidLongitude, isValidMapDimensions, preloadGeography, prepareFeatures, prepareMesh, readResponseWithSizeLimit, validateContentType, validateGeographyData, validateGeographyUrl, validateResponseSize, validateSRI }; export type { GeographySecurityConfig, SRIConfig, SRIEnforcementConfig };