@markvivanco/app-version-checker
Version:
React App version checking and update prompts for React, React Native, and web applications
142 lines (137 loc) • 5 kB
text/typescript
import React, { ReactNode } from 'react';
import { V as VersionInfo, I as IVersionDataProvider, a as VersionCheckOptions, P as Platform } from '../../index-DbGkth70.mjs';
import { I as IStorageProvider } from '../../storage-provider.interface-BSIiOlJN.mjs';
/**
* React Context and Provider for version checking
* Framework-agnostic implementation that works with any data/storage providers
*/
/**
* Version check context value
*/
interface VersionCheckContextValue {
/** Current version information */
versionInfo: VersionInfo | null;
/** Whether an update is available */
isUpdateAvailable: boolean;
/** Current app version */
currentVersion: string | null;
/** Formatted version string */
formattedVersion: string | null;
/** Whether the update dialog should be shown */
showUpdateDialog: boolean;
/** Whether a check is in progress */
isChecking: boolean;
/** Any error that occurred during checking */
error: Error | null;
/** Manually trigger a version check */
checkForUpdates: () => Promise<void>;
/** Handle update now action */
handleUpdateNow: () => Promise<void>;
/** Handle remind later action */
handleRemindLater: () => Promise<void>;
/** Reset version check data */
resetVersionCheck: () => Promise<void>;
/** Get changelog for latest version */
getChangeLog: () => Promise<string | null>;
/** Check if update is mandatory */
isUpdateMandatory: () => Promise<boolean>;
}
/**
* Props for VersionCheckProvider
*/
interface VersionCheckProviderProps {
children: ReactNode;
/** Data provider for version information */
dataProvider: IVersionDataProvider;
/** Storage provider for preferences */
storageProvider: IStorageProvider;
/** Optional version check options */
options?: VersionCheckOptions;
/** Whether to check for updates automatically on mount */
checkOnMount?: boolean;
/** Whether to check for updates when app becomes active (React Native) */
checkOnForeground?: boolean;
/** Custom handler for opening the app store */
onOpenStore?: (url: string) => Promise<void>;
/** Callback when update dialog should be shown */
onShowUpdateDialog?: (versionInfo: VersionInfo) => void;
/** Callback when update dialog should be hidden */
onHideUpdateDialog?: () => void;
/** Whether to render the update dialog internally (set to false if using custom dialog) */
renderDialog?: boolean;
/** Custom update dialog component */
dialogComponent?: React.ComponentType<UpdateDialogProps>;
}
/**
* Props for update dialog components
*/
interface UpdateDialogProps {
visible: boolean;
versionInfo: VersionInfo;
onUpdateNow: () => Promise<void>;
onRemindLater: () => Promise<void>;
isUpdateMandatory?: boolean;
changeLog?: string | null;
}
/**
* Version Check Provider Component
*/
declare const VersionCheckProvider: React.FC<VersionCheckProviderProps>;
/**
* Hook to use version check context
*/
declare const useVersionCheck: () => VersionCheckContextValue;
/**
* Hook for checking app state changes (React Native)
* This is a helper for React Native apps to check on foreground
*/
declare const useAppStateVersionCheck: (appStateModule?: any, // React Native's AppState module
enabled?: boolean) => string;
/**
* Hook for periodic version checking
*/
declare const usePeriodicVersionCheck: (intervalMs?: number, // Default: 1 hour
enabled?: boolean) => void;
/**
* Hook for visibility-based version checking (web)
*/
declare const useVisibilityVersionCheck: (enabled?: boolean) => void;
/**
* Standalone hook for version checking without context
* Useful when you want to manage the version checking logic yourself
*/
declare const useStandaloneVersionChecker: (dataProvider: IVersionDataProvider, storageProvider: IStorageProvider, options?: {
checkOnMount?: boolean;
checkOnFocus?: boolean;
checkInterval?: number;
}) => {
versionInfo: VersionInfo | null;
isChecking: boolean;
error: Error | null;
showUpdatePrompt: boolean;
checkForUpdates: () => Promise<void>;
setRemindMeLater: () => Promise<void>;
isUpdateAvailable: boolean;
};
/**
* Hook to get just the version info
*/
declare const useVersionInfo: () => {
current: string | null;
latest: string | null | undefined;
formatted: string | null;
updateAvailable: boolean;
platform: Platform | undefined;
storeUrl: string | null | undefined;
};
/**
* Hook to get update status
*/
declare const useUpdateStatus: () => {
isUpdateAvailable: boolean;
isChecking: boolean;
hasError: boolean;
error: Error | null;
isDialogVisible: boolean;
};
export { type UpdateDialogProps, type VersionCheckContextValue, VersionCheckProvider, type VersionCheckProviderProps, useAppStateVersionCheck, usePeriodicVersionCheck, useStandaloneVersionChecker, useUpdateStatus, useVersionCheck, useVersionInfo, useVisibilityVersionCheck };