native-update-capacitor 0.0.0-stage → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/AI-INTEGRATION-GUIDE.md +578 -0
  2. package/LICENSE +25 -0
  3. package/NativeUpdate.podspec +19 -0
  4. package/README.md +574 -2
  5. package/android/build.gradle +125 -0
  6. package/android/consumer-rules.pro +9 -0
  7. package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
  8. package/android/gradle.properties +17 -0
  9. package/android/manifest-additions.xml +28 -0
  10. package/android/proguard-rules.pro +26 -0
  11. package/android/settings.gradle +2 -0
  12. package/android/src/main/AndroidManifest.xml +13 -0
  13. package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +159 -0
  14. package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +314 -0
  15. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +406 -0
  16. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +48 -0
  17. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +343 -0
  18. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +236 -0
  19. package/android/src/main/java/com/aoneahsan/nativeupdate/JsonOptional.kt +26 -0
  20. package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1249 -0
  21. package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +404 -0
  22. package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +107 -0
  23. package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +240 -0
  24. package/android/variables.gradle +5 -0
  25. package/cli/commands/backend-create.js +623 -0
  26. package/cli/commands/bundle-create.js +145 -0
  27. package/cli/commands/bundle-sign.js +64 -0
  28. package/cli/commands/bundle-verify.js +58 -0
  29. package/cli/commands/init.js +146 -0
  30. package/cli/commands/keys-generate.js +58 -0
  31. package/cli/commands/monitor.js +89 -0
  32. package/cli/commands/remote-shared.js +262 -0
  33. package/cli/commands/remote.js +622 -0
  34. package/cli/commands/server-start.js +96 -0
  35. package/cli/index.js +605 -0
  36. package/cli/package.json +21 -0
  37. package/dist/esm/app-review/app-review-manager.d.ts +24 -0
  38. package/dist/esm/app-review/app-review-manager.js +194 -0
  39. package/dist/esm/app-review/index.d.ts +5 -0
  40. package/dist/esm/app-review/index.js +5 -0
  41. package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
  42. package/dist/esm/app-review/platform-review-handler.js +137 -0
  43. package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
  44. package/dist/esm/app-review/review-conditions-checker.js +154 -0
  45. package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
  46. package/dist/esm/app-review/review-rate-limiter.js +163 -0
  47. package/dist/esm/app-review/types.d.ts +41 -0
  48. package/dist/esm/app-review/types.js +1 -0
  49. package/dist/esm/app-update/app-update-checker.d.ts +58 -0
  50. package/dist/esm/app-update/app-update-checker.js +227 -0
  51. package/dist/esm/app-update/app-update-installer.d.ts +20 -0
  52. package/dist/esm/app-update/app-update-installer.js +134 -0
  53. package/dist/esm/app-update/app-update-manager.d.ts +28 -0
  54. package/dist/esm/app-update/app-update-manager.js +198 -0
  55. package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
  56. package/dist/esm/app-update/app-update-notifier.js +99 -0
  57. package/dist/esm/app-update/index.d.ts +6 -0
  58. package/dist/esm/app-update/index.js +6 -0
  59. package/dist/esm/app-update/platform-app-update.d.ts +19 -0
  60. package/dist/esm/app-update/platform-app-update.js +138 -0
  61. package/dist/esm/app-update/types.d.ts +58 -0
  62. package/dist/esm/app-update/types.js +11 -0
  63. package/dist/esm/background-update/background-scheduler.d.ts +63 -0
  64. package/dist/esm/background-update/background-scheduler.js +332 -0
  65. package/dist/esm/background-update/index.d.ts +3 -0
  66. package/dist/esm/background-update/index.js +2 -0
  67. package/dist/esm/background-update/notification-manager.d.ts +29 -0
  68. package/dist/esm/background-update/notification-manager.js +88 -0
  69. package/dist/esm/config/support.d.ts +9 -0
  70. package/dist/esm/config/support.js +9 -0
  71. package/dist/esm/core/analytics.d.ts +83 -0
  72. package/dist/esm/core/analytics.js +151 -0
  73. package/dist/esm/core/cache-manager.d.ts +72 -0
  74. package/dist/esm/core/cache-manager.js +274 -0
  75. package/dist/esm/core/config.d.ts +69 -0
  76. package/dist/esm/core/config.js +107 -0
  77. package/dist/esm/core/errors.d.ts +56 -0
  78. package/dist/esm/core/errors.js +85 -0
  79. package/dist/esm/core/event-emitter.d.ts +30 -0
  80. package/dist/esm/core/event-emitter.js +80 -0
  81. package/dist/esm/core/logger.d.ts +21 -0
  82. package/dist/esm/core/logger.js +108 -0
  83. package/dist/esm/core/performance.d.ts +53 -0
  84. package/dist/esm/core/performance.js +153 -0
  85. package/dist/esm/core/plugin-manager.d.ts +88 -0
  86. package/dist/esm/core/plugin-manager.js +224 -0
  87. package/dist/esm/core/security.d.ts +123 -0
  88. package/dist/esm/core/security.js +361 -0
  89. package/dist/esm/core/update-check.d.ts +121 -0
  90. package/dist/esm/core/update-check.js +127 -0
  91. package/dist/esm/definitions.d.ts +872 -0
  92. package/dist/esm/definitions.js +104 -0
  93. package/dist/esm/index.d.ts +14 -0
  94. package/dist/esm/index.js +18 -0
  95. package/dist/esm/live-update/bundle-manager.d.ts +102 -0
  96. package/dist/esm/live-update/bundle-manager.js +344 -0
  97. package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
  98. package/dist/esm/live-update/certificate-pinning.js +77 -0
  99. package/dist/esm/live-update/delta-processor.d.ts +84 -0
  100. package/dist/esm/live-update/delta-processor.js +257 -0
  101. package/dist/esm/live-update/download-manager.d.ts +106 -0
  102. package/dist/esm/live-update/download-manager.js +412 -0
  103. package/dist/esm/live-update/rollout-checker.d.ts +86 -0
  104. package/dist/esm/live-update/rollout-checker.js +304 -0
  105. package/dist/esm/live-update/update-manager.d.ts +63 -0
  106. package/dist/esm/live-update/update-manager.js +321 -0
  107. package/dist/esm/live-update/version-manager.d.ts +93 -0
  108. package/dist/esm/live-update/version-manager.js +390 -0
  109. package/dist/esm/plugin.d.ts +3 -0
  110. package/dist/esm/plugin.js +848 -0
  111. package/dist/esm/security/crypto.d.ts +88 -0
  112. package/dist/esm/security/crypto.js +228 -0
  113. package/dist/esm/security/validator.d.ts +60 -0
  114. package/dist/esm/security/validator.js +142 -0
  115. package/dist/esm/types/app-identity.d.ts +36 -0
  116. package/dist/esm/types/app-identity.js +1 -0
  117. package/dist/esm/types/rollout.d.ts +91 -0
  118. package/dist/esm/types/rollout.js +25 -0
  119. package/dist/esm/web.d.ts +130 -0
  120. package/dist/esm/web.js +981 -0
  121. package/dist/plugin.cjs +1 -0
  122. package/dist/plugin.esm.js +1 -0
  123. package/dist/plugin.js +2 -0
  124. package/docs/CHANGELOG.md +993 -0
  125. package/docs/KNOWN_LIMITATIONS.md +235 -0
  126. package/docs/MIGRATION.md +391 -0
  127. package/docs/protocol/CLIENT-PROTOCOL.md +178 -0
  128. package/docs/server-requirements.md +211 -0
  129. package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
  130. package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
  131. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
  132. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
  133. package/ios/Plugin/Info.plist +43 -0
  134. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
  135. package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
  136. package/ios/Plugin/NativeUpdatePlugin.m +53 -0
  137. package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
  138. package/ios/Plugin/Security/SecurityManager.swift +289 -0
  139. package/package.json +135 -4
@@ -0,0 +1,198 @@
1
+ import { Logger } from '../core/logger';
2
+ import { AppUpdateChecker } from './app-update-checker';
3
+ import { AppUpdateInstaller } from './app-update-installer';
4
+ import { PlatformAppUpdate } from './platform-app-update';
5
+ export class AppUpdateManager {
6
+ constructor(config) {
7
+ this.listeners = new Map();
8
+ this.config = config;
9
+ this.logger = new Logger('AppUpdateManager');
10
+ this.checker = new AppUpdateChecker(config);
11
+ this.installer = new AppUpdateInstaller(config);
12
+ this.platformUpdate = new PlatformAppUpdate(config);
13
+ }
14
+ async checkAppUpdate(options) {
15
+ try {
16
+ this.logger.log('Checking for app updates', options);
17
+ // Check with native platform
18
+ const nativeInfo = await this.platformUpdate.checkForUpdate(options);
19
+ // If no native info, check with server
20
+ if (!nativeInfo.updateAvailable && this.config.updateUrl) {
21
+ const serverInfo = await this.checker.checkServerVersion(options);
22
+ return this.mergeUpdateInfo(nativeInfo, serverInfo);
23
+ }
24
+ return nativeInfo;
25
+ }
26
+ catch (error) {
27
+ this.logger.error('Failed to check app update', error);
28
+ throw error;
29
+ }
30
+ }
31
+ async startImmediateUpdate() {
32
+ try {
33
+ this.logger.log('Starting immediate update');
34
+ // Check if immediate update is allowed
35
+ const updateInfo = await this.checkAppUpdate();
36
+ if (!updateInfo.immediateUpdateAllowed) {
37
+ throw new Error('Immediate update not allowed');
38
+ }
39
+ // Start the update
40
+ await this.installer.startImmediateUpdate();
41
+ // Notify listeners
42
+ this.emit('appUpdateStateChanged', {
43
+ installStatus: 1, // PENDING
44
+ packageName: this.config.packageName || '',
45
+ availableVersion: updateInfo.availableVersion || '',
46
+ });
47
+ }
48
+ catch (error) {
49
+ this.logger.error('Failed to start immediate update', error);
50
+ throw error;
51
+ }
52
+ }
53
+ async startFlexibleUpdate() {
54
+ try {
55
+ this.logger.log('Starting flexible update');
56
+ // Check if flexible update is allowed
57
+ const updateInfo = await this.checkAppUpdate();
58
+ if (!updateInfo.flexibleUpdateAllowed) {
59
+ throw new Error('Flexible update not allowed');
60
+ }
61
+ // Start the update
62
+ await this.installer.startFlexibleUpdate();
63
+ // Set up progress monitoring
64
+ this.installer.onProgress((progress) => {
65
+ this.emit('appUpdateProgress', progress);
66
+ });
67
+ // Notify listeners
68
+ this.emit('appUpdateStateChanged', {
69
+ installStatus: 2, // DOWNLOADING
70
+ packageName: this.config.packageName || '',
71
+ availableVersion: updateInfo.availableVersion || '',
72
+ });
73
+ }
74
+ catch (error) {
75
+ this.logger.error('Failed to start flexible update', error);
76
+ throw error;
77
+ }
78
+ }
79
+ async completeFlexibleUpdate() {
80
+ try {
81
+ this.logger.log('Completing flexible update');
82
+ await this.installer.completeFlexibleUpdate();
83
+ // App will restart after this
84
+ this.emit('appUpdateStateChanged', {
85
+ installStatus: 3, // INSTALLING
86
+ packageName: this.config.packageName || '',
87
+ availableVersion: '',
88
+ });
89
+ }
90
+ catch (error) {
91
+ this.logger.error('Failed to complete flexible update', error);
92
+ throw error;
93
+ }
94
+ }
95
+ async getVersionInfo() {
96
+ try {
97
+ this.logger.log('Getting version info');
98
+ return await this.platformUpdate.getVersionInfo();
99
+ }
100
+ catch (error) {
101
+ this.logger.error('Failed to get version info', error);
102
+ throw error;
103
+ }
104
+ }
105
+ async isMinimumVersionMet() {
106
+ try {
107
+ this.logger.log('Checking minimum version');
108
+ const versionInfo = await this.getVersionInfo();
109
+ const minimumVersion = this.config.minimumVersion || '0.0.0';
110
+ const isMet = this.checker.compareVersions(versionInfo.currentVersion, minimumVersion) >= 0;
111
+ return {
112
+ isMet,
113
+ currentVersion: versionInfo.currentVersion,
114
+ minimumVersion,
115
+ updateRequired: !isMet && this.config.enforceMinVersion === true,
116
+ };
117
+ }
118
+ catch (error) {
119
+ this.logger.error('Failed to check minimum version', error);
120
+ throw error;
121
+ }
122
+ }
123
+ async getAppUpdateInfo() {
124
+ return this.checkAppUpdate();
125
+ }
126
+ async performImmediateUpdate() {
127
+ return this.startImmediateUpdate();
128
+ }
129
+ async openAppStore(_options) {
130
+ try {
131
+ this.logger.log('Opening app store');
132
+ const storeInfo = await this.getAppStoreUrl();
133
+ await this.platformUpdate.openUrl(storeInfo.url);
134
+ }
135
+ catch (error) {
136
+ this.logger.error('Failed to open app store', error);
137
+ throw error;
138
+ }
139
+ }
140
+ async getAppStoreUrl() {
141
+ try {
142
+ this.logger.log('Getting app store URL');
143
+ return await this.platformUpdate.getAppStoreUrl();
144
+ }
145
+ catch (error) {
146
+ this.logger.error('Failed to get app store URL', error);
147
+ throw error;
148
+ }
149
+ }
150
+ async getUpdateInstallState() {
151
+ try {
152
+ this.logger.log('Getting update install state');
153
+ return await this.installer.getInstallState();
154
+ }
155
+ catch (error) {
156
+ this.logger.error('Failed to get update install state', error);
157
+ throw error;
158
+ }
159
+ }
160
+ addListener(eventName, listenerFunc) {
161
+ if (!this.listeners.has(eventName)) {
162
+ this.listeners.set(eventName, new Set());
163
+ }
164
+ this.listeners.get(eventName).add(listenerFunc);
165
+ return {
166
+ remove: async () => {
167
+ const listeners = this.listeners.get(eventName);
168
+ if (listeners) {
169
+ listeners.delete(listenerFunc);
170
+ }
171
+ },
172
+ };
173
+ }
174
+ async removeAllListeners(eventName) {
175
+ if (eventName) {
176
+ this.listeners.delete(eventName);
177
+ }
178
+ else {
179
+ this.listeners.clear();
180
+ }
181
+ }
182
+ emit(eventName, data) {
183
+ const listeners = this.listeners.get(eventName);
184
+ if (listeners) {
185
+ listeners.forEach((listener) => {
186
+ try {
187
+ listener(data);
188
+ }
189
+ catch (error) {
190
+ this.logger.error(`Error in ${eventName} listener`, error);
191
+ }
192
+ });
193
+ }
194
+ }
195
+ mergeUpdateInfo(nativeInfo, serverInfo) {
196
+ return Object.assign(Object.assign(Object.assign({}, nativeInfo), serverInfo), { updateAvailable: nativeInfo.updateAvailable || !!serverInfo.availableVersion, availableVersion: serverInfo.availableVersion || nativeInfo.availableVersion });
197
+ }
198
+ }
@@ -0,0 +1,14 @@
1
+ import { PluginConfig } from '../core/config';
2
+ import { AppUpdateInfo } from './types';
3
+ export declare class AppUpdateNotifier {
4
+ private config;
5
+ private logger;
6
+ constructor(config: PluginConfig);
7
+ notifyUpdateAvailable(updateInfo: AppUpdateInfo): Promise<void>;
8
+ notifyUpdateDownloading(progress: number): Promise<void>;
9
+ notifyUpdateReady(): Promise<void>;
10
+ notifyUpdateFailed(error: Error): Promise<void>;
11
+ private showNotification;
12
+ private showReadyNotification;
13
+ private emitUpdateEvent;
14
+ }
@@ -0,0 +1,99 @@
1
+ import { Logger } from '../core/logger';
2
+ export class AppUpdateNotifier {
3
+ constructor(config) {
4
+ this.config = config;
5
+ this.logger = new Logger('AppUpdateNotifier');
6
+ }
7
+ async notifyUpdateAvailable(updateInfo) {
8
+ this.logger.log('Notifying update available', updateInfo);
9
+ // Emit event for update availability
10
+ this.emitUpdateEvent('appUpdateAvailable', {
11
+ currentVersion: updateInfo.currentVersion,
12
+ availableVersion: updateInfo.availableVersion,
13
+ updatePriority: updateInfo.updatePriority,
14
+ updateSize: updateInfo.updateSize,
15
+ releaseNotes: updateInfo.releaseNotes,
16
+ storeUrl: updateInfo.updateURL,
17
+ });
18
+ // Show notification if configured
19
+ if (this.config.showUpdateNotification !== false) {
20
+ await this.showNotification(updateInfo);
21
+ }
22
+ }
23
+ async notifyUpdateDownloading(progress) {
24
+ this.logger.log('Update download progress', progress);
25
+ // Emit progress event
26
+ this.emitUpdateEvent('appUpdateProgress', {
27
+ percentComplete: progress,
28
+ });
29
+ }
30
+ async notifyUpdateReady() {
31
+ this.logger.log('Update ready for installation');
32
+ // Emit ready event
33
+ this.emitUpdateEvent('appUpdateReady', {
34
+ message: 'Update downloaded and ready to install',
35
+ });
36
+ // Show notification
37
+ if (this.config.showUpdateNotification !== false) {
38
+ await this.showReadyNotification();
39
+ }
40
+ }
41
+ async notifyUpdateFailed(error) {
42
+ this.logger.error('Update failed', error);
43
+ // Emit error event
44
+ this.emitUpdateEvent('appUpdateFailed', {
45
+ error: error.message,
46
+ code: error.code || 'UNKNOWN_ERROR',
47
+ });
48
+ }
49
+ async showNotification(updateInfo) {
50
+ if (!('Notification' in window)) {
51
+ return;
52
+ }
53
+ // Request permission if needed
54
+ if (Notification.permission === 'default') {
55
+ await Notification.requestPermission();
56
+ }
57
+ if (Notification.permission === 'granted') {
58
+ const notification = new Notification('App Update Available', {
59
+ body: `Version ${updateInfo.availableVersion} is available. ${updateInfo.releaseNotes || ''}`,
60
+ icon: '/icon.png',
61
+ tag: 'app-update',
62
+ requireInteraction: updateInfo.updatePriority === 5, // Priority 5 = IMMEDIATE
63
+ });
64
+ notification.onclick = () => {
65
+ // Trigger update action
66
+ this.emitUpdateEvent('appUpdateNotificationClicked', {});
67
+ notification.close();
68
+ };
69
+ }
70
+ }
71
+ async showReadyNotification() {
72
+ if (!('Notification' in window) || Notification.permission !== 'granted') {
73
+ return;
74
+ }
75
+ const notificationOptions = {
76
+ body: 'App update has been downloaded and is ready to install.',
77
+ icon: '/icon.png',
78
+ tag: 'app-update-ready',
79
+ };
80
+ // Actions are not supported in standard NotificationOptions
81
+ notificationOptions.actions = [
82
+ { action: 'install', title: 'Install Now' },
83
+ { action: 'later', title: 'Later' },
84
+ ];
85
+ const notification = new Notification('Update Ready', notificationOptions);
86
+ notification.onclick = (event) => {
87
+ if (event.action === 'install') {
88
+ this.emitUpdateEvent('appUpdateInstallClicked', {});
89
+ }
90
+ notification.close();
91
+ };
92
+ }
93
+ emitUpdateEvent(eventName, data) {
94
+ // Emit custom event
95
+ if (typeof window !== 'undefined') {
96
+ window.dispatchEvent(new CustomEvent(eventName, { detail: data }));
97
+ }
98
+ }
99
+ }
@@ -0,0 +1,6 @@
1
+ export { AppUpdateManager } from './app-update-manager';
2
+ export { AppUpdateChecker } from './app-update-checker';
3
+ export { AppUpdateInstaller } from './app-update-installer';
4
+ export { AppUpdateNotifier } from './app-update-notifier';
5
+ export { PlatformAppUpdate } from './platform-app-update';
6
+ export * from './types';
@@ -0,0 +1,6 @@
1
+ export { AppUpdateManager } from './app-update-manager';
2
+ export { AppUpdateChecker } from './app-update-checker';
3
+ export { AppUpdateInstaller } from './app-update-installer';
4
+ export { AppUpdateNotifier } from './app-update-notifier';
5
+ export { PlatformAppUpdate } from './platform-app-update';
6
+ export * from './types';
@@ -0,0 +1,19 @@
1
+ import { PluginConfig } from '../core/config';
2
+ import { AppUpdateInfo, AppUpdateOptions, VersionInfo, AppStoreInfo } from './types';
3
+ export declare class PlatformAppUpdate {
4
+ private config;
5
+ private logger;
6
+ private platform;
7
+ constructor(config: PluginConfig);
8
+ checkForUpdate(_?: AppUpdateOptions): Promise<AppUpdateInfo>;
9
+ getVersionInfo(): Promise<VersionInfo>;
10
+ getAppStoreUrl(): Promise<AppStoreInfo>;
11
+ openUrl(url: string): Promise<void>;
12
+ isUpdateSupported(): boolean;
13
+ getUpdateCapabilities(): {
14
+ immediateUpdate: boolean;
15
+ flexibleUpdate: boolean;
16
+ backgroundDownload: boolean;
17
+ inAppReview: boolean;
18
+ };
19
+ }
@@ -0,0 +1,138 @@
1
+ import { Logger } from '../core/logger';
2
+ import { Capacitor } from '@capacitor/core';
3
+ import { SecurityValidator } from '../core/security';
4
+ export class PlatformAppUpdate {
5
+ constructor(config) {
6
+ this.config = config;
7
+ this.logger = new Logger('PlatformAppUpdate');
8
+ this.platform = Capacitor.getPlatform();
9
+ }
10
+ async checkForUpdate(_) {
11
+ // options parameter is kept for future use
12
+ this.logger.log('Checking for platform update: ' + this.platform);
13
+ const versionInfo = await this.getVersionInfo();
14
+ // Default response
15
+ const updateInfo = {
16
+ updateAvailable: false,
17
+ currentVersion: versionInfo.currentVersion,
18
+ availableVersion: versionInfo.currentVersion,
19
+ };
20
+ // Platform-specific checks
21
+ if (this.platform === 'android') {
22
+ // Android would check Play Store via Play Core Library
23
+ // This is handled by native implementation
24
+ return updateInfo;
25
+ }
26
+ else if (this.platform === 'ios') {
27
+ // iOS would check App Store via iTunes API
28
+ // This is handled by native implementation
29
+ return updateInfo;
30
+ }
31
+ else {
32
+ // Web platform - check configured update URL
33
+ if (this.config.webUpdateUrl) {
34
+ try {
35
+ SecurityValidator.validateDownloadUrl(this.config.webUpdateUrl);
36
+ const response = await fetch(this.config.webUpdateUrl);
37
+ const data = await response.json();
38
+ if (data.version && data.version !== versionInfo.currentVersion) {
39
+ updateInfo.updateAvailable = true;
40
+ updateInfo.availableVersion = data.version;
41
+ updateInfo.releaseNotes = data.releaseNotes;
42
+ // Validate downloadUrl scheme — server-controlled value, must
43
+ // not be allowed to smuggle javascript: into a later openUrl.
44
+ if (data.downloadUrl) {
45
+ SecurityValidator.validateStoreUrl(data.downloadUrl);
46
+ updateInfo.updateURL = data.downloadUrl;
47
+ }
48
+ }
49
+ }
50
+ catch (error) {
51
+ this.logger.error('Failed to check web update', error);
52
+ }
53
+ }
54
+ }
55
+ return updateInfo;
56
+ }
57
+ async getVersionInfo() {
58
+ // getAppInfo is not available in standard Capacitor, using default values
59
+ const appInfo = {
60
+ version: '1.0.0',
61
+ build: '1',
62
+ id: 'com.example.app',
63
+ };
64
+ return {
65
+ currentVersion: appInfo.version,
66
+ buildNumber: appInfo.build,
67
+ packageName: appInfo.id,
68
+ platform: this.platform,
69
+ minimumVersion: this.config.minimumVersion,
70
+ };
71
+ }
72
+ async getAppStoreUrl() {
73
+ const platform = this.platform;
74
+ let url = '';
75
+ if (platform === 'ios') {
76
+ // iOS App Store URL
77
+ const appStoreId = this.config.appStoreId || this.config.iosAppId;
78
+ if (!appStoreId) {
79
+ throw new Error('App Store ID not configured');
80
+ }
81
+ url = `https://apps.apple.com/app/id${appStoreId}`;
82
+ }
83
+ else if (platform === 'android') {
84
+ // Google Play Store URL
85
+ const packageName = this.config.packageName || (await this.getVersionInfo()).packageName;
86
+ url = `https://play.google.com/store/apps/details?id=${packageName}`;
87
+ }
88
+ else {
89
+ // Web URL
90
+ url = this.config.webUpdateUrl || window.location.origin;
91
+ }
92
+ return { url, platform: platform };
93
+ }
94
+ async openUrl(url) {
95
+ // Reject any non-HTTPS / non-store URL — protects against
96
+ // `javascript:` payloads handed back from a compromised server.
97
+ SecurityValidator.validateStoreUrl(url);
98
+ if (typeof window !== 'undefined' && window.open) {
99
+ window.open(url, '_blank', 'noopener,noreferrer');
100
+ }
101
+ else {
102
+ throw new Error('Cannot open URL on this platform');
103
+ }
104
+ }
105
+ isUpdateSupported() {
106
+ // Check if platform supports in-app updates
107
+ if (this.platform === 'android') {
108
+ // Android supports in-app updates via Play Core
109
+ return true;
110
+ }
111
+ else if (this.platform === 'ios') {
112
+ // iOS only supports opening App Store
113
+ return false;
114
+ }
115
+ else {
116
+ // Web can redirect to update URL
117
+ return true;
118
+ }
119
+ }
120
+ getUpdateCapabilities() {
121
+ const capabilities = {
122
+ immediateUpdate: false,
123
+ flexibleUpdate: false,
124
+ backgroundDownload: false,
125
+ inAppReview: false,
126
+ };
127
+ if (this.platform === 'android') {
128
+ capabilities.immediateUpdate = true;
129
+ capabilities.flexibleUpdate = true;
130
+ capabilities.backgroundDownload = true;
131
+ capabilities.inAppReview = true;
132
+ }
133
+ else if (this.platform === 'ios') {
134
+ capabilities.inAppReview = true;
135
+ }
136
+ return capabilities;
137
+ }
138
+ }
@@ -0,0 +1,58 @@
1
+ export interface AppUpdateInfo {
2
+ updateAvailable: boolean;
3
+ currentVersion: string;
4
+ availableVersion?: string;
5
+ updatePriority?: number;
6
+ releaseNotes?: string;
7
+ updateSize?: number;
8
+ immediateUpdateAllowed?: boolean;
9
+ flexibleUpdateAllowed?: boolean;
10
+ clientVersionStalenessDays?: number;
11
+ updateURL?: string;
12
+ }
13
+ export interface AppUpdateProgress {
14
+ bytesDownloaded: number;
15
+ totalBytesToDownload: number;
16
+ percentComplete: number;
17
+ downloadSpeed: number;
18
+ estimatedTime: number;
19
+ }
20
+ export interface AppUpdateState {
21
+ installStatus: AppUpdateInstallStatus;
22
+ installErrorCode?: number;
23
+ packageName: string;
24
+ availableVersion: string;
25
+ }
26
+ export declare enum AppUpdateInstallStatus {
27
+ UNKNOWN = 0,
28
+ PENDING = 1,
29
+ DOWNLOADING = 2,
30
+ INSTALLING = 3,
31
+ INSTALLED = 4,
32
+ FAILED = 5,
33
+ CANCELED = 6,
34
+ DOWNLOADED = 11
35
+ }
36
+ export interface AppUpdateOptions {
37
+ allowedUpdateTypes?: ('immediate' | 'flexible')[];
38
+ stalenessDays?: number;
39
+ priority?: number;
40
+ }
41
+ export interface VersionInfo {
42
+ currentVersion: string;
43
+ buildNumber: string;
44
+ packageName: string;
45
+ platform: 'ios' | 'android' | 'web';
46
+ availableVersion?: string;
47
+ minimumVersion?: string;
48
+ }
49
+ export interface MinimumVersionCheck {
50
+ isMet: boolean;
51
+ currentVersion: string;
52
+ minimumVersion: string;
53
+ updateRequired: boolean;
54
+ }
55
+ export interface AppStoreInfo {
56
+ url: string;
57
+ platform: 'ios' | 'android' | 'web';
58
+ }
@@ -0,0 +1,11 @@
1
+ export var AppUpdateInstallStatus;
2
+ (function (AppUpdateInstallStatus) {
3
+ AppUpdateInstallStatus[AppUpdateInstallStatus["UNKNOWN"] = 0] = "UNKNOWN";
4
+ AppUpdateInstallStatus[AppUpdateInstallStatus["PENDING"] = 1] = "PENDING";
5
+ AppUpdateInstallStatus[AppUpdateInstallStatus["DOWNLOADING"] = 2] = "DOWNLOADING";
6
+ AppUpdateInstallStatus[AppUpdateInstallStatus["INSTALLING"] = 3] = "INSTALLING";
7
+ AppUpdateInstallStatus[AppUpdateInstallStatus["INSTALLED"] = 4] = "INSTALLED";
8
+ AppUpdateInstallStatus[AppUpdateInstallStatus["FAILED"] = 5] = "FAILED";
9
+ AppUpdateInstallStatus[AppUpdateInstallStatus["CANCELED"] = 6] = "CANCELED";
10
+ AppUpdateInstallStatus[AppUpdateInstallStatus["DOWNLOADED"] = 11] = "DOWNLOADED";
11
+ })(AppUpdateInstallStatus || (AppUpdateInstallStatus = {}));
@@ -0,0 +1,63 @@
1
+ import type { BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult } from '../definitions';
2
+ import type { AppUpdateManager } from '../app-update/app-update-manager';
3
+ import type { VersionManager } from '../live-update/version-manager';
4
+ import type { BundleManager } from '../live-update/bundle-manager';
5
+ interface BackgroundSchedulerDeps {
6
+ appUpdateManager?: AppUpdateManager;
7
+ versionManager?: VersionManager;
8
+ bundleManager?: BundleManager;
9
+ }
10
+ export declare class BackgroundScheduler {
11
+ private config;
12
+ private status;
13
+ private readonly logger;
14
+ private readonly configManager;
15
+ private deps;
16
+ constructor();
17
+ /**
18
+ * Set dependencies for the scheduler
19
+ */
20
+ setDependencies(deps: BackgroundSchedulerDeps): void;
21
+ configure(config: BackgroundUpdateConfig): void;
22
+ getStatus(): BackgroundUpdateStatus;
23
+ performCheck(): Promise<BackgroundCheckResult>;
24
+ private checkForUpdates;
25
+ /**
26
+ * Check whether a newer NATIVE app-store binary is available.
27
+ *
28
+ * Primary path: the platform `AppUpdateManager` (Play Core / App Store).
29
+ *
30
+ * Fallback path: a GET to `{serverUrl}/app-version`. This is a
31
+ * deliberate **custom-backend extension point**, NOT part of the Native
32
+ * Update (Laravel) backend — that backend ships OTA bundles, it has no
33
+ * concept of the store binary version. A self-hoster who wants
34
+ * server-driven native-update prompts implements this endpoint:
35
+ *
36
+ * ```
37
+ * GET {serverUrl}/app-version
38
+ * X-Current-Version: <installed app version>
39
+ * X-Platform: ios | android | web
40
+ * → 200 { "version": "2.1.0", "priority": 3 } // or { "latestVersion": … }
41
+ * ```
42
+ *
43
+ * If the endpoint is absent the fallback just fails closed
44
+ * (updateAvailable=false). See `docs/api/background-update-api.md`.
45
+ */
46
+ private checkAppUpdate;
47
+ private checkLiveUpdate;
48
+ private sendNotification;
49
+ /**
50
+ * Get current app version
51
+ */
52
+ private getCurrentAppVersion;
53
+ /**
54
+ * Get current platform
55
+ */
56
+ private getPlatform;
57
+ protected calculateNextCheckTime(): number;
58
+ protected shouldRespectBatteryOptimization(): boolean;
59
+ protected isNetworkConditionMet(): boolean;
60
+ protected isBatteryLevelSufficient(): boolean;
61
+ private compareVersions;
62
+ }
63
+ export {};