/** * Represents a version file containing metadata about an update. * This interface defines the structure of the version.json file that * contains version information and cryptographic verification data. */ export interface IVersionFile { /** The version string identifier */ version: string; /** Base64-encoded RSA signature for verification */ signature: string; /** Base64-encoded SHA-256 hash of the update file */ hash: string; } /** * Extends IVersionFile with the actual update file data. * This interface represents the complete storage data that includes * both metadata and the binary update content. */ export interface ICacheData extends IVersionFile { /** The binary update file as a Blob */ file: Blob; } /** * Represents a key-value pair for storage operations. * Used for storing the current version and update file in IndexedDB, * as well as making config data available to the service worker. */ export interface IStorageData { key: string; value: string | Blob; } /** * Represents a cached file record in IndexedDB. * Each record contains a file path and its corresponding binary data. */ export interface ICacheRecord { /** The file path used as the cache key */ path: string; /** The file content as a Blob */ blob: Blob; } /** * Configuration object for API endpoints. * Defines the URLs used to fetch version information and update files. * **Note: Some servers or cdn's like to cache small static json files, this results in * hash mismatches. To prevent this, we recommend adding a query parameter with a timestamp or * random string to the versionJson and updateBin urls. For example: https://example.com/version.json?t=1234567890** */ export interface IApiUrls { /** URL to the version.json endpoint */ versionJson: string; /** URL to the update.bin endpoint */ updateBin: string; } /** * Represents a chunk of downloaded data. * Each chunk contains an optional identifier and the binary data as a Uint8Array. */ export interface IDownloadChunk { id?: number; data: Uint8Array; } /** * Defines the method used to reload the application after an update. * - 'document.write': Replaces the entire document content with fresh index.html * - 'location.update': Triggers a standard navigation to the current URL */ export type ReloadMethod = 'document.write' | 'location.update'; /** The name of the IndexedDB database used by WALU */ export const DB_NAME = "walu"; /** The name of the object store used for caching files */ export const CACHE_STORE = "cache"; /** The name of the object store used for temporary download chunks */ export const DOWNLOAD_STORE = "download"; /** The name of the object store used for storing the current version and config values */ export const STORAGE_STORE = "storage"; /** The current version of the IndexedDB database schema */ export const DB_VERSION = 2; /** * Opens a connection to the IndexedDB database and creates necessary object stores. * This function implements a singleton pattern to ensure only one database connection * is active at a time. It also handles database version upgrades automatically. * * @returns Promise that resolves to the opened IndexedDB database instance * @throws {string} If the database cannot be opened or an error occurs */ export function openDb(): Promise; export function isDbReady(): boolean; /** * Clears all data from the specified IndexedDB object store. * * @param storeName - The name of the object store to clear * @returns Promise that resolves when the store is cleared * @throws {any} If the clear operation fails */ export function clearStore(storeName: string): Promise; /** * Writes data to the specified IndexedDB object store. * * @template T - The type of data to write * @param storeName - The name of the object store to write to * @param data - The data object to store * @returns Promise that resolves when the data is written * @throws {any} If the write operation fails */ export function writeToStore(storeName: string, data: T): Promise; /** * Reads a single record from the specified IndexedDB object store by key. * * @template T - The type of data to read * @param storeName - The name of the object store to read from * @param key - The key of the record to retrieve * @returns Promise that resolves to the stored data or undefined if not found * @throws {any} If the read operation fails */ export function readFromStore(storeName: string, key: IDBValidKey): Promise; /** * Reads all records from the specified IndexedDB object store. * * @template T - The type of data to read * @param storeName - The name of the object store to read from * @returns Promise that resolves to an array of all stored records * @throws {any} If the read operation fails */ export function readAllFromStore(storeName: string): Promise; /** * Logging levels for WALU */ export type LogLevel = 'NONE' | 'ERROR' | 'WARN' | 'INFO'; /** * Sets the logging level for WALU and stores it in sessionStorage * @param level - The log level to set: "NONE", "ERROR", "WARN", or "INFO" */ export function setLogging(level: LogLevel): Promise; /** * WALU logger with configurable log levels */ export const logger: { /** * Logs an error message * @param message - The message to log * @param args - Additional arguments */ error: (message: string, ...args: any[]) => Promise; /** * Logs a warning message * @param message - The message to log * @param args - Additional arguments */ warn: (message: string, ...args: any[]) => Promise; /** * Logs an info message * @param message - The message to log * @param args - Additional arguments */ info: (message: string, ...args: any[]) => Promise; }; /** * Configuration class for WALU. * Manages API URLs, storage functions, and cryptographic verification settings. * Provides a centralized configuration interface for all WALU operations. */ export class WaluConfig { protected readonly config: { workerPath: typeof WaluConfig.prototype.workerPath; publicKey: typeof WaluConfig.prototype.publicKey; apiUrls: typeof WaluConfig.prototype.apiUrls | string; storageReadFunction?: typeof WaluConfig.prototype.storageReadFunction; storageWriteFunction?: typeof WaluConfig.prototype.storageWriteFunction; downloadStatusFunction?: typeof WaluConfig.prototype.downloadStatusFunction; reloadMethod?: ReloadMethod; cacheMissDocument?: string; }; protected readonly workerPath: string; protected readonly publicKey: string; protected readonly apiUrls: IApiUrls; protected readonly storageReadFunction: () => Promise; protected readonly storageWriteFunction: (data: ICacheData) => Promise; protected readonly downloadStatusFunction: (msg: string, progress: number) => Promise; protected readonly reloadMethod: ReloadMethod; protected readonly cacheMissDocument?: string; /** * Creates a new WaluConfig instance with the specified configuration options. * * @param config - Configuration object containing all necessary settings * @param config.workerPath - Path to the service worker script * @param config.publicKey - RSA public key in PEM format for signature verification * @param config.apiUrls - API URLs object or base URL string for version and update endpoints * @param config.storageReadFunction - Optional custom function to read storage data * @param config.storageWriteFunction - Optional custom function to write storage data * @param config.downloadStatusFunction - Optional callback for download progress updates */ constructor(config: { workerPath: typeof WaluConfig.prototype.workerPath; publicKey: typeof WaluConfig.prototype.publicKey; apiUrls: typeof WaluConfig.prototype.apiUrls | string; storageReadFunction?: typeof WaluConfig.prototype.storageReadFunction; storageWriteFunction?: typeof WaluConfig.prototype.storageWriteFunction; downloadStatusFunction?: typeof WaluConfig.prototype.downloadStatusFunction; reloadMethod?: ReloadMethod; cacheMissDocument?: string; }); /** * Gets the path to the service worker script. * * @returns The worker path as a string */ getWorkerPath(): string; /** * Gets the RSA public key used for signature verification. * * @returns The public key in PEM format */ getPublicKey(): string; /** * Gets the API URLs configuration. * * @returns The API URLs object containing version and update endpoints */ getApiUrls(): IApiUrls; /** * Reads storage data using the configured storage read function. * * @returns Promise resolving to the stored data or null if no data exists */ storageRead(): Promise; /** * Writes storage data using the configured storage write function. * * @param data - The storage data to write * @returns Promise that resolves when the data is written */ storageWrite(data: ICacheData): Promise; /** * Reports download status using the configured status function. * * @param msg - Status message to display * @param progress - Progress value between 0 and 1 */ downloadStatus(msg: string, progress: number): Promise; /** * Gets the reload method used after updates. * * @returns The reload method as a 'document.write' or 'location.update' string literal */ getReloadMethod(): ReloadMethod; /** * Gets the optional document to serve when a cache miss occurs. * * @returns The path to the cache miss document, if configured */ getCacheMissDocument(): string | undefined; } /** * Prepares the cache by extracting files from a ZIP archive and storing them in IndexedDB. * This function clears the existing cache, extracts all files from the provided ZIP data, * and stores each file as a blob in the cache store with progress tracking. * * @param cfg - The WALU configuration object containing download status callback * @param data - The storage data containing the ZIP file to be cached * @returns A promise that resolves when the cache preparation is complete * @throws {Error} If the ZIP file cannot be loaded or processed */ export function prepareCache(cfg: WaluConfig, data: ICacheData): Promise; /** * Verifies the cryptographic signature of a version file using RSA-PKCS1-v1.5 with SHA-256. * This function ensures the integrity and authenticity of the version information by * validating the digital signature against the provided public key. * * @param cfg - The WALU configuration containing the RSA public key * @param version - The version file object containing hash, version, and signature * @returns Promise that resolves if the signature is valid * @throws {Error} If signature verification fails or any cryptographic operation fails */ export function checkIfValidSignature(cfg: WaluConfig, version: IVersionFile): Promise; /** * Registers a Service Worker that intercepts HTTP requests and serves cached files from IndexedDB. * This function creates a Service Worker from the inline worker code, registers it with the browser, * and returns the registration. If a Service Worker is already active, it returns the existing registration. * * @param cfg - The WALU configuration object * @returns Promise that resolves to the Service Worker registration * @throws {Error} If Service Workers are not supported, registration fails, or existing registration cannot be retrieved */ export function registerCacheInterceptor(cfg: WaluConfig): Promise; /** * The source code of the Service Worker as a string. */ export const SERVICE_WORKER_SOURCE: string; /** * Reloads the application using the method specified in the configuration. * * @param cfg - The optional WALU configuration object * @returns Promise that resolves if the reload is initiated (or if document.write finish) */ export function reloadApp(cfg?: WaluConfig): Promise; /** * Shows a file dialog to allow users to manually install a WALU update bundle. * This function prompts the user to select a .bundle file, validates its contents, * verifies the signature, stores the update, and prepares the cache. * * @param cfg - The WALU configuration object * @returns Promise that resolves when the installation is complete * @throws {Error} If no file is selected, the bundle is invalid, signature verification fails, or installation fails */ export function showInstallDialog(cfg: WaluConfig): Promise; /** * Downloads and parses the version.json file from the configured API endpoint. * This function retrieves the version information including hash and signature * that are needed for update verification. * * @param cfg - The WALU configuration containing API URLs and status callback * @returns Promise that resolves to the parsed version file object * @throws {Error} If the download fails or the JSON cannot be parsed */ export function downloadVersionJson(cfg: WaluConfig): Promise; /** * Downloads the update.bin file from the configured API endpoint with integrity verification. * This function downloads the binary update file in chunks, verifies its hash matches * the expected value from the version file, and stores it for installation. * * @param cfg - The WALU configuration containing API URLs and storage functions * @param version - The version file object containing the expected hash for verification * @returns Promise that resolves when the download and verification are complete * @throws {Error} If the download fails, hash verification fails, or storage fails */ export function downloadUpdateBin(cfg: WaluConfig, version: IVersionFile): Promise; /** * Installs WALU by registering the cache interceptor, updating to the latest version, * and preparing the cache with the downloaded files. This is the main entry point * for setting up WALU in a web application. * * @param cfg - The WALU configuration object * @returns Promise that resolves when the installation is complete * @throws {Error} If service worker registration, update, or cache preparation fails */ export function installWalu(cfg: WaluConfig): Promise; //# sourceMappingURL=index.d.ts.map