@markvivanco/app-version-checker
Version:
React App version checking and update prompts for React, React Native, and web applications
216 lines (208 loc) • 7.28 kB
text/typescript
import { P as Platform, A as AppStoreConfig, I as IVersionDataProvider, a as VersionCheckOptions, V as VersionInfo, c as VersionCheckResult } from '../index-DbGkth70.mjs';
export { D as DEFAULT_CHECK_INTERVALS, b as VersionCheckTimestamps } from '../index-DbGkth70.mjs';
import { I as IStorageProvider } from '../storage-provider.interface-BSIiOlJN.mjs';
/**
* Core version comparison utilities
* Pure functions with no external dependencies
*/
/**
* Compare two semantic version strings
* Returns: -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2
*/
declare function compareVersions(v1: string, v2: string): number;
/**
* Check if an update is available by comparing versions
*/
declare function isUpdateAvailable(currentVersion: string, latestVersion: string): boolean;
/**
* Parse a version string into its components
*/
declare function parseVersion(version: string): {
major: number;
minor: number;
patch: number;
build?: number;
};
/**
* Format version components back into a string
*/
declare function formatVersion(major: number, minor: number, patch: number, build?: number): string;
/**
* Get the major version from a version string
*/
declare function getMajorVersion(version: string): number;
/**
* Get the minor version from a version string
*/
declare function getMinorVersion(version: string): number;
/**
* Get the patch version from a version string
*/
declare function getPatchVersion(version: string): number;
/**
* Check if version is a valid semantic version string
*/
declare function isValidVersion(version: string): boolean;
/**
* Get the difference between two versions
* Returns an object describing what changed
*/
declare function getVersionDiff(v1: string, v2: string): {
type: 'major' | 'minor' | 'patch' | 'build' | 'none';
fromVersion: string;
toVersion: string;
};
/**
* Version formatting utilities
* Pure functions for formatting version strings
*/
/**
* Format a version with optional build number
* @param platformVersion The platform-specific version (e.g., "1.0.36")
* @param buildNumber Optional build number (e.g., "349")
* @returns Formatted version string (e.g., "1.0.36.349")
*/
declare function formatVersionWithBuild(platformVersion: string, buildNumber?: string | number): string;
/**
* Extract build number from version string
* @param version Version string that may contain build number
* @returns Build number or undefined
*/
declare function extractBuildNumber(version: string): string | undefined;
/**
* Extract base version without build number
* @param version Version string (e.g., "1.0.36.349")
* @returns Base version without build (e.g., "1.0.36")
*/
declare function extractBaseVersion(version: string): string;
/**
* Normalize version string to ensure consistent format
* @param version Version string to normalize
* @param padToLength Minimum number of segments (default: 3)
* @returns Normalized version string
*/
declare function normalizeVersion(version: string, padToLength?: number): string;
/**
* Create a display-friendly version string
* @param version Version string
* @param includePrefix Whether to include "v" prefix
* @returns Display version (e.g., "v1.0.36")
*/
declare function formatDisplayVersion(version: string, includePrefix?: boolean): string;
/**
* Compare version strings for sorting
* @param versions Array of version strings
* @param descending Sort in descending order (latest first)
* @returns Sorted array of versions
*/
declare function sortVersions(versions: string[], descending?: boolean): string[];
/**
* Get the latest version from an array of versions
* @param versions Array of version strings
* @returns Latest version string or null if array is empty
*/
declare function getLatestVersion(versions: string[]): string | null;
/**
* App store utilities
* Functions for generating app store URLs and handling store-specific logic
*/
/**
* Generate iOS App Store URL
* @param appStoreId The iOS App Store ID
* @param customUrl Optional custom URL to override default
*/
declare function getIosStoreUrl(appStoreId?: string, customUrl?: string): string | null;
/**
* Generate Android Play Store URL
* @param packageName The Android package name
* @param customUrl Optional custom URL to override default
*/
declare function getAndroidStoreUrl(packageName?: string, customUrl?: string): string | null;
/**
* Get the appropriate store URL for a platform
*/
declare function getStoreUrl(platform: Platform, config: AppStoreConfig): string | null;
/**
* Validate an iOS App Store ID
*/
declare function isValidIosAppStoreId(appStoreId: string): boolean;
/**
* Validate an Android package name
*/
declare function isValidAndroidPackageName(packageName: string): boolean;
/**
* Extract app ID from store URL
*/
declare function extractAppIdFromUrl(url: string, platform: Platform): string | null;
/**
* Get store name for display
*/
declare function getStoreName(platform: Platform): string;
/**
* Get store badge image URL (for documentation/UI purposes)
*/
declare function getStoreBadgeUrl(platform: Platform, _locale?: string): string | null;
/**
* Main VersionChecker class
* Coordinates version checking using pluggable providers
*/
declare class VersionChecker {
private dataProvider;
private storageProvider;
private options;
private initialized;
constructor(dataProvider: IVersionDataProvider, storageProvider: IStorageProvider, options?: VersionCheckOptions);
/**
* Initialize the version checker
*/
initialize(): Promise<void>;
/**
* Detect the current platform
*/
private detectPlatform;
/**
* Get the current platform
*/
getPlatform(): Platform;
/**
* Get version information
*/
getVersionInfo(): Promise<VersionInfo>;
/**
* Check if an update is available
*/
isUpdateAvailable(): Promise<boolean>;
/**
* Check if we should show the update prompt
*/
shouldShowUpdatePrompt(): Promise<VersionCheckResult>;
/**
* Set "remind me later" for the update prompt
*/
setRemindMeLater(): Promise<void>;
/**
* Clear the "remind me later" setting
*/
clearRemindMeLater(): Promise<void>;
/**
* Check if update is mandatory
*/
isUpdateMandatory(): Promise<boolean>;
/**
* Get changelog for the latest version
*/
getChangeLog(): Promise<string | null>;
/**
* Reset all version check data (useful for testing)
*/
resetVersionCheckData(): Promise<void>;
/**
* Get formatted version string
*/
getFormattedVersion(): Promise<string>;
/**
* Dispose of resources
*/
dispose(): Promise<void>;
}
export { AppStoreConfig, Platform, VersionCheckOptions, VersionCheckResult, VersionChecker, VersionInfo, compareVersions, extractAppIdFromUrl, extractBaseVersion, extractBuildNumber, formatDisplayVersion, formatVersion, formatVersionWithBuild, getAndroidStoreUrl, getIosStoreUrl, getLatestVersion, getMajorVersion, getMinorVersion, getPatchVersion, getStoreBadgeUrl, getStoreName, getStoreUrl, getVersionDiff, isUpdateAvailable, isValidAndroidPackageName, isValidIosAppStoreId, isValidVersion, normalizeVersion, parseVersion, sortVersions };