@markvivanco/app-version-checker
Version:
React App version checking and update prompts for React, React Native, and web applications
131 lines (126 loc) • 4.68 kB
text/typescript
import './storage-provider.interface-BSIiOlJN.mjs';
/**
* Core types for version checking
*/
type Platform = 'ios' | 'android' | 'web';
interface VersionInfo {
currentVersion: string;
latestVersion: string | null;
updateAvailable: boolean;
storeUrl: string | null;
platform: Platform;
}
interface VersionCheckOptions {
/** Minimum time between version checks in milliseconds */
minCheckInterval?: number;
/** Duration to wait after user selects "Remind Me Later" in milliseconds */
remindLaterDuration?: number;
/** Whether to skip version checking on web platform */
skipWebPlatform?: boolean;
/** Custom platform detection function */
getPlatform?: () => Platform;
}
interface VersionCheckTimestamps {
lastCheckTime: number | null;
remindLaterTime: number | null;
}
interface AppStoreConfig {
/** iOS App Store ID */
iosAppStoreId?: string;
/** Android package name */
androidPackageName?: string;
/** Custom iOS App Store URL */
iosStoreUrl?: string;
/** Custom Android Play Store URL */
androidStoreUrl?: string;
}
interface VersionCheckResult {
/** Whether an update is available */
shouldShowPrompt: boolean;
/** Version information */
versionInfo: VersionInfo;
/** Reason for not showing prompt (if applicable) */
skipReason?: 'no_update' | 'web_platform' | 'remind_later' | 'too_soon' | 'error';
}
/** Version check intervals (in milliseconds) */
declare const DEFAULT_CHECK_INTERVALS: {
readonly MIN_CHECK_INTERVAL: number;
readonly REMIND_LATER_DURATION: number;
};
/**
* Data provider interface for version checking
* Implement this interface to provide version data from any source
*/
/**
* Interface for providing version data from any source
* (REST API, GraphQL, Firebase, Supabase, local storage, etc.)
*/
interface IVersionDataProvider {
/**
* Get the current version of the app
* This could be from package.json, environment variables, or app constants
*/
getCurrentVersion(): Promise<string> | string;
/**
* Get the latest available version for a specific platform
* This is typically fetched from a backend service or configuration
*/
getLatestVersion(platform: Platform): Promise<string | null>;
/**
* Get app store configuration
* Returns IDs and URLs needed to generate store links
*/
getAppStoreConfig(): Promise<AppStoreConfig> | AppStoreConfig;
/**
* Optional: Get the current platform
* If not implemented, the version checker will use its own detection
*/
getCurrentPlatform?(): Platform;
/**
* Optional: Get formatted version string
* Can include build numbers or other formatting
*/
getFormattedVersion?(): Promise<string> | string;
/**
* Optional: Check if updates should be forced
* Some critical updates might require mandatory installation
*/
isUpdateMandatory?(currentVersion: string, latestVersion: string): Promise<boolean> | boolean;
/**
* Optional: Get changelog or release notes for the latest version
*/
getChangeLog?(version: string): Promise<string | null>;
/**
* Optional: Get minimum supported version
* Apps older than this version might not work properly
*/
getMinimumSupportedVersion?(platform: Platform): Promise<string | null>;
/**
* Optional: Custom validation for version availability
* Can be used to implement staged rollouts or regional restrictions
*/
isVersionAvailableForUser?(version: string, platform: Platform): Promise<boolean>;
/**
* Optional: Initialize the provider
* Called once when the version checker is initialized
*/
initialize?(): Promise<void>;
/**
* Optional: Clean up resources
* Called when the version checker is disposed
*/
dispose?(): Promise<void>;
}
/**
* Abstract base class for data providers
* Provides default implementations for optional methods
*/
declare abstract class BaseVersionDataProvider implements IVersionDataProvider {
abstract getCurrentVersion(): Promise<string> | string;
abstract getLatestVersion(platform: Platform): Promise<string | null>;
abstract getAppStoreConfig(): Promise<AppStoreConfig> | AppStoreConfig;
getCurrentPlatform?(): Platform;
initialize(): Promise<void>;
dispose(): Promise<void>;
}
export { type AppStoreConfig as A, BaseVersionDataProvider as B, DEFAULT_CHECK_INTERVALS as D, type IVersionDataProvider as I, type Platform as P, type VersionInfo as V, type VersionCheckOptions as a, type VersionCheckTimestamps as b, type VersionCheckResult as c };