@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
84 lines (83 loc) • 3.08 kB
TypeScript
export type SwState = {
storeVersion: number;
dbCacheName: string;
tilesStoreName: string;
logLevel: string;
audience: string[];
audienceExcludedPaths: string[];
accessToken?: string;
loginState?: string;
authMode?: 'token' | 'cookie';
alwaysSendCookies: boolean;
refererPolicy?: ReferrerPolicy;
};
export declare function swLog(state: SwState, str: string, error?: Error): void;
export declare class SwHelper {
private state;
private readonly indexedDbHelper;
get State(): SwState;
private database;
private audienceExcludedPathPatterns;
private readonly stateDbName;
private readonly stateStoreName;
private readonly stateKey;
private initialized;
initialize(defaultState: SwState): Promise<void>;
isOriginAllowed(eventOrigin: string, origin: string): boolean;
private isLoggedIn;
updateState(data: any): void;
getRequest(request: Request): Request;
private log;
private refreshAudienceExcludedPathPatterns;
/**
* Saves the service worker state
*/
saveState(): Promise<void>;
/**
* Reloads the service worker state from indexDB
*/
loadState(): Promise<SwState | null>;
private upgradeIndexedDb;
}
type indexedDbUpgradeFunction = (db: IDBDatabase) => void;
export declare class IndexedDbHelper {
private readonly timeout;
private readonly databases;
openDb(name: string, version: number, upgradeFunction?: indexedDbUpgradeFunction): Promise<IDBDatabase>;
private openDbInternal;
/**
* Try to load this request from indexedDB.
* Returns null if unsuccessful
*/
loadFromIndexedDB(state: SwState, request: Request): Promise<Response | null>;
}
export declare class CacheHelper {
/**
* To allow offline mode, the first 300 queries made by the application will be cached.
* We could have implemented a more specific cache with file extensions for example
* But then we should define exactly what should be cached.
* This can be quite complex, because we cannot just cache all images,
* as some of them are WMTS or WMS results and others are icons.
* So a simple solution here is to cache all the first queries that are done
* by the application when it starts. With this we should have all the necessary
* cache to be able to start the application in offline mode
*
* The WMTS tiles and other results coming from OGC-Services will be cached on demand
* with the OfflineManager component of the application.
*/
private readonly appCacheName;
private readonly maxCacheCount;
private cacheCount;
/**
* Execute a fetch for the query, and cache the result if successful
* Returns null if unsuccessful
*/
fetchAndCache(state: SwState, request: Request): Promise<Response | null>;
/**
* Try to load this request from local cache.
* Returns null if unsuccessful
*/
loadFromCache(request: Request): Promise<Response | null>;
isCacheAllowed(request: Request): boolean;
}
export {};