import { LocalStorage } from '../../public/node/local-storage.js'; interface CacheValue { value: T; timestamp: number; } export type PackageVersionKey = `npm-package-${string}`; export type NotificationsKey = `notifications-${string}`; export type NotificationKey = `notification-${string}`; export type GraphQLRequestKey = `q-${string}-${string}-${string}`; type MostRecentOccurrenceKey = `most-recent-occurrence-${string}`; type RateLimitKey = `rate-limited-occurrences-${string}`; type ExportedKey = PackageVersionKey | NotificationsKey | NotificationKey | GraphQLRequestKey; interface Cache { [packageVersionKey: PackageVersionKey]: CacheValue; [notifications: NotificationsKey]: CacheValue; [notification: NotificationKey]: CacheValue; [graphQLRequestKey: GraphQLRequestKey]: CacheValue; [mostRecentOccurrenceKey: MostRecentOccurrenceKey]: CacheValue; [rateLimitKey: RateLimitKey]: CacheValue; } export interface ConfSchema { sessionStore: string; currentSessionId?: string; devSessionStore?: string; currentDevSessionId?: string; cache?: Cache; autoUpgradeEnabled?: boolean; } /** * Get session. * * @returns Session. */ export declare function getSessions(config?: LocalStorage): string | undefined; /** * Set session. * * @param session - Session. */ export declare function setSessions(session: string, config?: LocalStorage): void; /** * Remove session. */ export declare function removeSessions(config?: LocalStorage): void; /** * Get current session ID. * * @returns Current session ID. */ export declare function getCurrentSessionId(config?: LocalStorage): string | undefined; /** * Set current session ID. * * @param sessionId - Session ID. */ export declare function setCurrentSessionId(sessionId: string, config?: LocalStorage): void; /** * Remove current session ID. */ export declare function removeCurrentSessionId(config?: LocalStorage): void; type CacheValueForKey = NonNullable['value']; /** * Fetch from cache, or run the provided function to get the value, and cache it * before returning it. * @param key - The key to use for the cache. * @param fn - The function to run to get the value to cache, if a cache miss occurs. * @param timeout - The maximum valid age of a cached value, in milliseconds. * If the cached value is older than this, it will be refreshed. * @returns The value from the cache or the result of the function. */ export declare function cacheRetrieveOrRepopulate(key: ExportedKey, fn: () => Promise>, timeout?: number, config?: LocalStorage): Promise>; export declare function cacheStore(key: ExportedKey, value: string, config?: LocalStorage): void; /** * Fetch from cache if already populated, otherwise return undefined. * @param key - The key to use for the cache. * @returns The chache element. */ export declare function cacheRetrieve(key: ExportedKey, config?: LocalStorage): CacheValue | undefined; export declare function cacheClear(config?: LocalStorage): void; export interface TimeInterval { days?: number; hours?: number; minutes?: number; seconds?: number; } export declare function timeIntervalToMilliseconds({ days, hours, minutes, seconds }: TimeInterval): number; /** * Execute a task only if the most recent occurrence of the task is older than the specified timeout. * @param key - The key to use for the cache. * @param timeout - The maximum valid age of the most recent occurrence, expressed as an object with * days, hours, minutes, and seconds properties. * If the most recent occurrence is older than this, the task will be executed. * @param task - The task to run if the most recent occurrence is older than the timeout. * @returns true if the task was run, or false if the task was not run. */ export declare function runAtMinimumInterval(key: string, timeout: TimeInterval, task: () => Promise, config?: LocalStorage): Promise; interface RunWithRateLimitOptions { /** * The key to use for the cache. */ key: string; /** * The number of times the task can be run within the limit */ limit: number; /** * The window of time after which the rate limit is refreshed, * expressed as an object with days, hours, minutes, and seconds properties. * If the most recent occurrence is older than this, the task will be executed. */ timeout: TimeInterval; /** * The task to run if the most recent occurrence is older than the timeout. */ task: () => Promise; } /** * Execute a task with a time-based rate limit. The rate limit is enforced by * checking how many times that task has been executed in a window of time ending * at the current time. If the task has been executed more than the allowed number * of times in that window, the task will not be executed. * * Note that this function has side effects, as it will also remove events prior * to the window of time that is being checked. * @param options - The options for the rate limiting. * @returns true, or undefined if the task was not run. */ export declare function runWithRateLimit(options: RunWithRateLimitOptions, config?: LocalStorage): Promise; /** * Get auto-upgrade preference. * * @returns Whether auto-upgrade is enabled, or undefined if never set. */ export declare function getAutoUpgradeEnabled(config?: LocalStorage): boolean | undefined; /** * Set auto-upgrade preference. * * @param enabled - Whether auto-upgrade should be enabled. */ export declare function setAutoUpgradeEnabled(enabled: boolean, config?: LocalStorage): void; export declare function getConfigStoreForPartnerStatus(): LocalStorage>; export declare function getCachedPartnerAccountStatus(partnersToken: string): true | null; export declare function setCachedPartnerAccountStatus(partnersToken: string): void; export {};