@markvivanco/app-version-checker
Version:
React App version checking and update prompts for React, React Native, and web applications
1 lines • 9.72 kB
Source Map (JSON)
{"version":3,"sources":["../../src/providers/data-provider.interface.ts","../../src/providers/storage-provider.interface.ts"],"names":[],"mappings":";AAkFO,IAAe,0BAAf,MAAuE;AAAA,EAK5E,kBAAA,GAAgC;AAE9B,IAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,EAAE,wBAAwB,MAAA,CAAA,EAAS;AACtE,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,OAAO,KAAA;AAAA,EACT;AAAA,EAEA,MAAM,UAAA,GAA4B;AAAA,EAElC;AAAA,EAEA,MAAM,OAAA,GAAyB;AAAA,EAE/B;AACF;;;ACXO,IAAe,sBAAf,MAA+D;AAAA,EAOpE,MAAM,eAAA,GAAmC;AACvC,IAAA,OAAO,CAAA;AAAA,EACT;AAAA,EAEA,MAAM,qBAAA,GAAuC;AAAA,EAE7C;AAAA,EAEA,MAAM,UAAA,GAA4B;AAAA,EAElC;AAAA,EAEA,MAAM,OAAA,GAAyB;AAAA,EAE/B;AACF;AAKO,IAAM,uBAAA,GAAN,cAAsC,mBAAA,CAAoB;AAAA,EAA1D,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AACL,IAAA,IAAA,CAAQ,OAAA,uBAAgC,GAAA,EAAI;AAAA,EAAA;AAAA,EAE5C,MAAM,gBAAA,GAA2C;AAC/C,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,eAAe,CAAA,IAAK,IAAA;AAAA,EAC9C;AAAA,EAEA,MAAM,iBAAiB,SAAA,EAAkC;AACvD,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,eAAA,EAAiB,SAAS,CAAA;AAAA,EAC7C;AAAA,EAEA,MAAM,kBAAA,GAA6C;AACjD,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,iBAAiB,CAAA,IAAK,IAAA;AAAA,EAChD;AAAA,EAEA,MAAM,mBAAmB,SAAA,EAAkC;AACzD,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,iBAAA,EAAmB,SAAS,CAAA;AAAA,EAC/C;AAAA,EAEA,MAAM,oBAAA,GAAsC;AAC1C,IAAA,IAAA,CAAK,OAAA,CAAQ,OAAO,iBAAiB,CAAA;AAAA,EACvC;AAAA,EAEA,MAAM,eAAA,GAAmC;AACvC,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,cAAc,CAAA,IAAK,CAAA;AAAA,EAC7C;AAAA,EAEA,MAAM,qBAAA,GAAuC;AAC3C,IAAA,MAAM,OAAA,GAAU,MAAM,IAAA,CAAK,eAAA,EAAgB;AAC3C,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,cAAA,EAAgB,OAAA,GAAU,CAAC,CAAA;AAAA,EAC9C;AAAA,EAEA,MAAM,mBAAA,GAA8C;AAClD,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,kBAAkB,CAAA,IAAK,IAAA;AAAA,EACjD;AAAA,EAEA,MAAM,oBAAoB,OAAA,EAAgC;AACxD,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,kBAAA,EAAoB,OAAO,CAAA;AAAA,EAC9C;AAAA,EAEA,MAAM,QAAA,GAA0B;AAC9B,IAAA,IAAA,CAAK,QAAQ,KAAA,EAAM;AAAA,EACrB;AAAA,EAEA,MAAM,iBAAA,GAAkD;AACtD,IAAA,MAAM,cAAmC,EAAC;AAC1C,IAAA,IAAA,CAAK,OAAA,CAAQ,OAAA,CAAQ,CAAC,KAAA,EAAO,GAAA,KAAQ;AACnC,MAAA,WAAA,CAAY,GAAG,CAAA,GAAI,KAAA;AAAA,IACrB,CAAC,CAAA;AACD,IAAA,OAAO,WAAA;AAAA,EACT;AACF","file":"index.mjs","sourcesContent":["/**\n * Data provider interface for version checking\n * Implement this interface to provide version data from any source\n */\n\nimport { Platform, AppStoreConfig } from '../core/types';\n\n/**\n * Interface for providing version data from any source\n * (REST API, GraphQL, Firebase, Supabase, local storage, etc.)\n */\nexport interface IVersionDataProvider {\n /**\n * Get the current version of the app\n * This could be from package.json, environment variables, or app constants\n */\n getCurrentVersion(): Promise<string> | string;\n\n /**\n * Get the latest available version for a specific platform\n * This is typically fetched from a backend service or configuration\n */\n getLatestVersion(platform: Platform): Promise<string | null>;\n\n /**\n * Get app store configuration\n * Returns IDs and URLs needed to generate store links\n */\n getAppStoreConfig(): Promise<AppStoreConfig> | AppStoreConfig;\n\n /**\n * Optional: Get the current platform\n * If not implemented, the version checker will use its own detection\n */\n getCurrentPlatform?(): Platform;\n\n /**\n * Optional: Get formatted version string\n * Can include build numbers or other formatting\n */\n getFormattedVersion?(): Promise<string> | string;\n\n /**\n * Optional: Check if updates should be forced\n * Some critical updates might require mandatory installation\n */\n isUpdateMandatory?(currentVersion: string, latestVersion: string): Promise<boolean> | boolean;\n\n /**\n * Optional: Get changelog or release notes for the latest version\n */\n getChangeLog?(version: string): Promise<string | null>;\n\n /**\n * Optional: Get minimum supported version\n * Apps older than this version might not work properly\n */\n getMinimumSupportedVersion?(platform: Platform): Promise<string | null>;\n\n /**\n * Optional: Custom validation for version availability\n * Can be used to implement staged rollouts or regional restrictions\n */\n isVersionAvailableForUser?(version: string, platform: Platform): Promise<boolean>;\n\n /**\n * Optional: Initialize the provider\n * Called once when the version checker is initialized\n */\n initialize?(): Promise<void>;\n\n /**\n * Optional: Clean up resources\n * Called when the version checker is disposed\n */\n dispose?(): Promise<void>;\n}\n\n/**\n * Abstract base class for data providers\n * Provides default implementations for optional methods\n */\nexport abstract class BaseVersionDataProvider implements IVersionDataProvider {\n abstract getCurrentVersion(): Promise<string> | string;\n abstract getLatestVersion(platform: Platform): Promise<string | null>;\n abstract getAppStoreConfig(): Promise<AppStoreConfig> | AppStoreConfig;\n\n getCurrentPlatform?(): Platform {\n // Default implementation can be overridden\n if (typeof window !== 'undefined' && !('ReactNativeWebView' in window)) {\n return 'web';\n }\n // Platform detection would be handled by the specific implementation\n return 'web';\n }\n\n async initialize(): Promise<void> {\n // Default no-op implementation\n }\n\n async dispose(): Promise<void> {\n // Default no-op implementation\n }\n}","/**\n * Storage provider interface for version check preferences\n * Implement this interface to store timestamps and preferences in any storage system\n */\n\n/**\n * Interface for storing version check timestamps and preferences\n * Can be implemented using localStorage, AsyncStorage, database, etc.\n */\nexport interface IStorageProvider {\n /**\n * Get the timestamp of the last version check\n */\n getLastCheckTime(): Promise<number | null>;\n\n /**\n * Set the timestamp of the last version check\n */\n setLastCheckTime(timestamp: number): Promise<void>;\n\n /**\n * Get the \"remind me later\" timestamp\n * Returns when the reminder period expires\n */\n getRemindLaterTime(): Promise<number | null>;\n\n /**\n * Set the \"remind me later\" timestamp\n */\n setRemindLaterTime(timestamp: number): Promise<void>;\n\n /**\n * Clear the \"remind me later\" timestamp\n */\n clearRemindLaterTime(): Promise<void>;\n\n /**\n * Optional: Get the number of times update was dismissed\n */\n getDismissCount?(): Promise<number>;\n\n /**\n * Optional: Increment the dismiss count\n */\n incrementDismissCount?(): Promise<void>;\n\n /**\n * Optional: Get the last shown version\n * Useful to avoid showing the same update multiple times\n */\n getLastShownVersion?(): Promise<string | null>;\n\n /**\n * Optional: Set the last shown version\n */\n setLastShownVersion?(version: string): Promise<void>;\n\n /**\n * Optional: Get user preference for auto-updates\n */\n getAutoUpdateEnabled?(): Promise<boolean>;\n\n /**\n * Optional: Set user preference for auto-updates\n */\n setAutoUpdateEnabled?(enabled: boolean): Promise<void>;\n\n /**\n * Optional: Get all stored preferences as an object\n */\n getAllPreferences?(): Promise<Record<string, any>>;\n\n /**\n * Optional: Clear all stored data\n */\n clearAll?(): Promise<void>;\n\n /**\n * Optional: Initialize the storage provider\n */\n initialize?(): Promise<void>;\n\n /**\n * Optional: Dispose of resources\n */\n dispose?(): Promise<void>;\n}\n\n/**\n * Abstract base class for storage providers\n * Provides default implementations for optional methods\n */\nexport abstract class BaseStorageProvider implements IStorageProvider {\n abstract getLastCheckTime(): Promise<number | null>;\n abstract setLastCheckTime(timestamp: number): Promise<void>;\n abstract getRemindLaterTime(): Promise<number | null>;\n abstract setRemindLaterTime(timestamp: number): Promise<void>;\n abstract clearRemindLaterTime(): Promise<void>;\n\n async getDismissCount(): Promise<number> {\n return 0;\n }\n\n async incrementDismissCount(): Promise<void> {\n // Default no-op\n }\n\n async initialize(): Promise<void> {\n // Default no-op\n }\n\n async dispose(): Promise<void> {\n // Default no-op\n }\n}\n\n/**\n * In-memory storage provider for testing\n */\nexport class InMemoryStorageProvider extends BaseStorageProvider {\n private storage: Map<string, any> = new Map();\n\n async getLastCheckTime(): Promise<number | null> {\n return this.storage.get('lastCheckTime') || null;\n }\n\n async setLastCheckTime(timestamp: number): Promise<void> {\n this.storage.set('lastCheckTime', timestamp);\n }\n\n async getRemindLaterTime(): Promise<number | null> {\n return this.storage.get('remindLaterTime') || null;\n }\n\n async setRemindLaterTime(timestamp: number): Promise<void> {\n this.storage.set('remindLaterTime', timestamp);\n }\n\n async clearRemindLaterTime(): Promise<void> {\n this.storage.delete('remindLaterTime');\n }\n\n async getDismissCount(): Promise<number> {\n return this.storage.get('dismissCount') || 0;\n }\n\n async incrementDismissCount(): Promise<void> {\n const current = await this.getDismissCount();\n this.storage.set('dismissCount', current + 1);\n }\n\n async getLastShownVersion(): Promise<string | null> {\n return this.storage.get('lastShownVersion') || null;\n }\n\n async setLastShownVersion(version: string): Promise<void> {\n this.storage.set('lastShownVersion', version);\n }\n\n async clearAll(): Promise<void> {\n this.storage.clear();\n }\n\n async getAllPreferences(): Promise<Record<string, any>> {\n const preferences: Record<string, any> = {};\n this.storage.forEach((value, key) => {\n preferences[key] = value;\n });\n return preferences;\n }\n}"]}