native-update-capacitor 0.0.0-stage → 4.4.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.
- package/AI-INTEGRATION-GUIDE.md +578 -0
- package/LICENSE +25 -0
- package/NativeUpdate.podspec +19 -0
- package/README.md +574 -2
- package/android/build.gradle +125 -0
- package/android/consumer-rules.pro +9 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/android/gradle.properties +17 -0
- package/android/manifest-additions.xml +28 -0
- package/android/proguard-rules.pro +26 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +159 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +314 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +406 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +48 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +343 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +236 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/JsonOptional.kt +26 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1249 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +404 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +107 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +240 -0
- package/android/variables.gradle +5 -0
- package/cli/commands/backend-create.js +623 -0
- package/cli/commands/bundle-create.js +145 -0
- package/cli/commands/bundle-sign.js +64 -0
- package/cli/commands/bundle-verify.js +58 -0
- package/cli/commands/flutter-patch.js +107 -0
- package/cli/commands/init.js +146 -0
- package/cli/commands/keys-generate.js +58 -0
- package/cli/commands/monitor.js +89 -0
- package/cli/commands/remote-shared.js +264 -0
- package/cli/commands/remote.js +634 -0
- package/cli/commands/server-start.js +96 -0
- package/cli/index.js +625 -0
- package/cli/package.json +21 -0
- package/dist/esm/app-review/app-review-manager.d.ts +24 -0
- package/dist/esm/app-review/app-review-manager.js +194 -0
- package/dist/esm/app-review/index.d.ts +5 -0
- package/dist/esm/app-review/index.js +5 -0
- package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
- package/dist/esm/app-review/platform-review-handler.js +137 -0
- package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
- package/dist/esm/app-review/review-conditions-checker.js +154 -0
- package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
- package/dist/esm/app-review/review-rate-limiter.js +163 -0
- package/dist/esm/app-review/types.d.ts +41 -0
- package/dist/esm/app-review/types.js +1 -0
- package/dist/esm/app-update/app-update-checker.d.ts +58 -0
- package/dist/esm/app-update/app-update-checker.js +227 -0
- package/dist/esm/app-update/app-update-installer.d.ts +20 -0
- package/dist/esm/app-update/app-update-installer.js +134 -0
- package/dist/esm/app-update/app-update-manager.d.ts +28 -0
- package/dist/esm/app-update/app-update-manager.js +198 -0
- package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
- package/dist/esm/app-update/app-update-notifier.js +99 -0
- package/dist/esm/app-update/index.d.ts +6 -0
- package/dist/esm/app-update/index.js +6 -0
- package/dist/esm/app-update/platform-app-update.d.ts +19 -0
- package/dist/esm/app-update/platform-app-update.js +138 -0
- package/dist/esm/app-update/types.d.ts +58 -0
- package/dist/esm/app-update/types.js +11 -0
- package/dist/esm/background-update/background-scheduler.d.ts +63 -0
- package/dist/esm/background-update/background-scheduler.js +332 -0
- package/dist/esm/background-update/index.d.ts +3 -0
- package/dist/esm/background-update/index.js +2 -0
- package/dist/esm/background-update/notification-manager.d.ts +29 -0
- package/dist/esm/background-update/notification-manager.js +88 -0
- package/dist/esm/config/support.d.ts +9 -0
- package/dist/esm/config/support.js +9 -0
- package/dist/esm/core/analytics.d.ts +83 -0
- package/dist/esm/core/analytics.js +151 -0
- package/dist/esm/core/cache-manager.d.ts +72 -0
- package/dist/esm/core/cache-manager.js +274 -0
- package/dist/esm/core/config.d.ts +69 -0
- package/dist/esm/core/config.js +107 -0
- package/dist/esm/core/errors.d.ts +56 -0
- package/dist/esm/core/errors.js +85 -0
- package/dist/esm/core/event-emitter.d.ts +30 -0
- package/dist/esm/core/event-emitter.js +80 -0
- package/dist/esm/core/logger.d.ts +21 -0
- package/dist/esm/core/logger.js +108 -0
- package/dist/esm/core/performance.d.ts +53 -0
- package/dist/esm/core/performance.js +153 -0
- package/dist/esm/core/plugin-manager.d.ts +88 -0
- package/dist/esm/core/plugin-manager.js +224 -0
- package/dist/esm/core/security.d.ts +123 -0
- package/dist/esm/core/security.js +361 -0
- package/dist/esm/core/update-check.d.ts +121 -0
- package/dist/esm/core/update-check.js +127 -0
- package/dist/esm/definitions.d.ts +872 -0
- package/dist/esm/definitions.js +104 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/live-update/bundle-manager.d.ts +102 -0
- package/dist/esm/live-update/bundle-manager.js +344 -0
- package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
- package/dist/esm/live-update/certificate-pinning.js +77 -0
- package/dist/esm/live-update/delta-processor.d.ts +84 -0
- package/dist/esm/live-update/delta-processor.js +257 -0
- package/dist/esm/live-update/download-manager.d.ts +106 -0
- package/dist/esm/live-update/download-manager.js +412 -0
- package/dist/esm/live-update/rollout-checker.d.ts +86 -0
- package/dist/esm/live-update/rollout-checker.js +304 -0
- package/dist/esm/live-update/update-manager.d.ts +63 -0
- package/dist/esm/live-update/update-manager.js +321 -0
- package/dist/esm/live-update/version-manager.d.ts +93 -0
- package/dist/esm/live-update/version-manager.js +390 -0
- package/dist/esm/plugin.d.ts +3 -0
- package/dist/esm/plugin.js +848 -0
- package/dist/esm/security/crypto.d.ts +88 -0
- package/dist/esm/security/crypto.js +228 -0
- package/dist/esm/security/validator.d.ts +60 -0
- package/dist/esm/security/validator.js +142 -0
- package/dist/esm/types/app-identity.d.ts +36 -0
- package/dist/esm/types/app-identity.js +1 -0
- package/dist/esm/types/rollout.d.ts +91 -0
- package/dist/esm/types/rollout.js +25 -0
- package/dist/esm/web.d.ts +130 -0
- package/dist/esm/web.js +981 -0
- package/dist/plugin.cjs +1 -0
- package/dist/plugin.esm.js +1 -0
- package/dist/plugin.js +2 -0
- package/docs/CHANGELOG.md +1016 -0
- package/docs/KNOWN_LIMITATIONS.md +240 -0
- package/docs/MIGRATION.md +391 -0
- package/docs/protocol/CLIENT-PROTOCOL.md +199 -0
- package/docs/server-requirements.md +211 -0
- package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
- package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
- package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
- package/ios/Plugin/Info.plist +43 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
- package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
- package/ios/Plugin/NativeUpdatePlugin.m +53 -0
- package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
- package/ios/Plugin/Security/SecurityManager.swift +289 -0
- package/package.json +133 -4
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { BackgroundUpdateType, UpdateErrorCode } from '../definitions';
|
|
2
|
+
import { Logger } from '../core/logger';
|
|
3
|
+
import { ConfigManager } from '../core/config';
|
|
4
|
+
import { checkForUpdate } from '../core/update-check';
|
|
5
|
+
export class BackgroundScheduler {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.config = null;
|
|
8
|
+
this.status = {
|
|
9
|
+
enabled: false,
|
|
10
|
+
isRunning: false,
|
|
11
|
+
checkCount: 0,
|
|
12
|
+
failureCount: 0,
|
|
13
|
+
};
|
|
14
|
+
this.deps = {};
|
|
15
|
+
this.logger = Logger.getInstance();
|
|
16
|
+
this.configManager = ConfigManager.getInstance();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Set dependencies for the scheduler
|
|
20
|
+
*/
|
|
21
|
+
setDependencies(deps) {
|
|
22
|
+
this.deps = deps;
|
|
23
|
+
}
|
|
24
|
+
configure(config) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.status.enabled = config.enabled;
|
|
27
|
+
}
|
|
28
|
+
getStatus() {
|
|
29
|
+
return Object.assign({}, this.status);
|
|
30
|
+
}
|
|
31
|
+
async performCheck() {
|
|
32
|
+
var _a;
|
|
33
|
+
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
updatesFound: false,
|
|
37
|
+
notificationSent: false,
|
|
38
|
+
error: {
|
|
39
|
+
code: UpdateErrorCode.INVALID_CONFIG,
|
|
40
|
+
message: 'Background updates not enabled',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
this.status.isRunning = true;
|
|
45
|
+
this.status.checkCount++;
|
|
46
|
+
try {
|
|
47
|
+
const result = await this.checkForUpdates();
|
|
48
|
+
this.status.lastCheckTime = Date.now();
|
|
49
|
+
this.status.isRunning = false;
|
|
50
|
+
this.status.lastError = undefined;
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.status.failureCount++;
|
|
55
|
+
this.status.isRunning = false;
|
|
56
|
+
this.status.lastError = {
|
|
57
|
+
code: UpdateErrorCode.UNKNOWN_ERROR,
|
|
58
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
updatesFound: false,
|
|
63
|
+
notificationSent: false,
|
|
64
|
+
error: this.status.lastError,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async checkForUpdates() {
|
|
69
|
+
var _a, _b, _c, _d, _e, _f;
|
|
70
|
+
const promises = [];
|
|
71
|
+
let appUpdate;
|
|
72
|
+
let liveUpdate;
|
|
73
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.updateTypes.includes(BackgroundUpdateType.APP_UPDATE)) ||
|
|
74
|
+
((_b = this.config) === null || _b === void 0 ? void 0 : _b.updateTypes.includes(BackgroundUpdateType.BOTH))) {
|
|
75
|
+
promises.push(this.checkAppUpdate());
|
|
76
|
+
}
|
|
77
|
+
if (((_c = this.config) === null || _c === void 0 ? void 0 : _c.updateTypes.includes(BackgroundUpdateType.LIVE_UPDATE)) ||
|
|
78
|
+
((_d = this.config) === null || _d === void 0 ? void 0 : _d.updateTypes.includes(BackgroundUpdateType.BOTH))) {
|
|
79
|
+
promises.push(this.checkLiveUpdate());
|
|
80
|
+
}
|
|
81
|
+
const results = await Promise.allSettled(promises);
|
|
82
|
+
if (((_e = results[0]) === null || _e === void 0 ? void 0 : _e.status) === 'fulfilled') {
|
|
83
|
+
appUpdate = results[0].value;
|
|
84
|
+
}
|
|
85
|
+
if (((_f = results[1]) === null || _f === void 0 ? void 0 : _f.status) === 'fulfilled') {
|
|
86
|
+
liveUpdate = results[1].value;
|
|
87
|
+
}
|
|
88
|
+
const updatesFound = (appUpdate === null || appUpdate === void 0 ? void 0 : appUpdate.updateAvailable) || (liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.available) || false;
|
|
89
|
+
let notificationSent = false;
|
|
90
|
+
if (updatesFound) {
|
|
91
|
+
notificationSent = await this.sendNotification(appUpdate, liveUpdate);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
updatesFound,
|
|
96
|
+
appUpdate,
|
|
97
|
+
liveUpdate,
|
|
98
|
+
notificationSent,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check whether a newer NATIVE app-store binary is available.
|
|
103
|
+
*
|
|
104
|
+
* Primary path: the platform `AppUpdateManager` (Play Core / App Store).
|
|
105
|
+
*
|
|
106
|
+
* Fallback path: a GET to `{serverUrl}/app-version`. This is a
|
|
107
|
+
* deliberate **custom-backend extension point**, NOT part of the Native
|
|
108
|
+
* Update (Laravel) backend — that backend ships OTA bundles, it has no
|
|
109
|
+
* concept of the store binary version. A self-hoster who wants
|
|
110
|
+
* server-driven native-update prompts implements this endpoint:
|
|
111
|
+
*
|
|
112
|
+
* ```
|
|
113
|
+
* GET {serverUrl}/app-version
|
|
114
|
+
* X-Current-Version: <installed app version>
|
|
115
|
+
* X-Platform: ios | android | web
|
|
116
|
+
* → 200 { "version": "2.1.0", "priority": 3 } // or { "latestVersion": … }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* If the endpoint is absent the fallback just fails closed
|
|
120
|
+
* (updateAvailable=false). See `docs/api/background-update-api.md`.
|
|
121
|
+
*/
|
|
122
|
+
async checkAppUpdate() {
|
|
123
|
+
// Use AppUpdateManager if available
|
|
124
|
+
if (this.deps.appUpdateManager) {
|
|
125
|
+
try {
|
|
126
|
+
return await this.deps.appUpdateManager.getAppUpdateInfo();
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
this.logger.error('Failed to check app update via manager', error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Fallback: optional custom `/app-version` endpoint (see method JSDoc).
|
|
133
|
+
const serverUrl = this.configManager.get('baseUrl') || this.configManager.get('serverUrl');
|
|
134
|
+
if (serverUrl) {
|
|
135
|
+
try {
|
|
136
|
+
const currentVersion = await this.getCurrentAppVersion();
|
|
137
|
+
const response = await fetch(`${serverUrl}/app-version`, {
|
|
138
|
+
method: 'GET',
|
|
139
|
+
headers: {
|
|
140
|
+
'Content-Type': 'application/json',
|
|
141
|
+
'X-Current-Version': currentVersion,
|
|
142
|
+
'X-Platform': this.getPlatform(),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
if (response.ok) {
|
|
146
|
+
const data = await response.json();
|
|
147
|
+
const availableVersion = data.version || data.latestVersion;
|
|
148
|
+
const updateAvailable = availableVersion &&
|
|
149
|
+
this.compareVersions(currentVersion, availableVersion) < 0;
|
|
150
|
+
return {
|
|
151
|
+
updateAvailable,
|
|
152
|
+
currentVersion,
|
|
153
|
+
availableVersion: updateAvailable ? availableVersion : undefined,
|
|
154
|
+
updatePriority: data.priority,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
this.logger.error('Failed to check app update via server', error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// No update info available
|
|
163
|
+
const currentVersion = await this.getCurrentAppVersion();
|
|
164
|
+
return {
|
|
165
|
+
updateAvailable: false,
|
|
166
|
+
currentVersion,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async checkLiveUpdate() {
|
|
170
|
+
var _a;
|
|
171
|
+
// Get current bundle version
|
|
172
|
+
let currentVersion = '1.0.0';
|
|
173
|
+
if (this.deps.bundleManager) {
|
|
174
|
+
try {
|
|
175
|
+
const activeBundle = await this.deps.bundleManager.getActiveBundle();
|
|
176
|
+
if (activeBundle) {
|
|
177
|
+
currentVersion = activeBundle.version;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (_b) {
|
|
181
|
+
// Use default version
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Use VersionManager if available
|
|
185
|
+
if (this.deps.versionManager) {
|
|
186
|
+
try {
|
|
187
|
+
const serverUrl = this.configManager.get('serverUrl');
|
|
188
|
+
const channel = this.configManager.get('channel') || 'production';
|
|
189
|
+
const appId = this.configManager.get('appId');
|
|
190
|
+
if (serverUrl && appId) {
|
|
191
|
+
const result = await this.deps.versionManager.checkForUpdates(serverUrl, channel, currentVersion, appId);
|
|
192
|
+
if (result) {
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
this.logger.error('Failed to check live update via VersionManager', error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Fallback: check the Native Update backend directly via the shared
|
|
202
|
+
// /v1/updates/check contract (same endpoint plugin.checkForUpdate() and
|
|
203
|
+
// VersionManager use). The old `/updates/latest` path was never served
|
|
204
|
+
// by the backend, so this fallback previously always failed silently.
|
|
205
|
+
const serverUrl = this.configManager.get('baseUrl') || this.configManager.get('serverUrl');
|
|
206
|
+
const apiKey = this.configManager.get('apiKey');
|
|
207
|
+
if (serverUrl && apiKey) {
|
|
208
|
+
try {
|
|
209
|
+
const channel = this.configManager.get('channel') || 'production';
|
|
210
|
+
const data = await checkForUpdate(serverUrl, {
|
|
211
|
+
apiKey,
|
|
212
|
+
channel,
|
|
213
|
+
currentVersion,
|
|
214
|
+
deviceId: 'web-client',
|
|
215
|
+
platform: this.getPlatform(),
|
|
216
|
+
appVersion: currentVersion,
|
|
217
|
+
});
|
|
218
|
+
return {
|
|
219
|
+
available: data.available,
|
|
220
|
+
version: data.version,
|
|
221
|
+
url: data.available ? data.downloadUrl : undefined,
|
|
222
|
+
notes: (_a = data.releaseNotes) !== null && _a !== void 0 ? _a : undefined,
|
|
223
|
+
size: data.size,
|
|
224
|
+
checksum: data.checksum,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
this.logger.error('Failed to check live update via server', error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// No update available
|
|
232
|
+
return {
|
|
233
|
+
available: false,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
async sendNotification(appUpdate, liveUpdate) {
|
|
237
|
+
var _a;
|
|
238
|
+
// Check if notifications are enabled in config
|
|
239
|
+
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.notificationPreferences)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
const prefs = this.config.notificationPreferences;
|
|
243
|
+
let title = prefs.title || 'Update Available';
|
|
244
|
+
let body = prefs.description || '';
|
|
245
|
+
if (appUpdate === null || appUpdate === void 0 ? void 0 : appUpdate.updateAvailable) {
|
|
246
|
+
title = 'App Update Available';
|
|
247
|
+
body = `Version ${appUpdate.availableVersion} is ready to install.`;
|
|
248
|
+
}
|
|
249
|
+
else if (liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.available) {
|
|
250
|
+
title = 'New Update Available';
|
|
251
|
+
body = `Version ${liveUpdate.version} is ready to download. ${liveUpdate.notes || ''}`;
|
|
252
|
+
}
|
|
253
|
+
// Use Web Notifications API in browser
|
|
254
|
+
if (typeof window !== 'undefined' && 'Notification' in window) {
|
|
255
|
+
try {
|
|
256
|
+
if (Notification.permission === 'granted') {
|
|
257
|
+
new Notification(title, { body });
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
this.logger.error('Failed to send notification', error);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Log notification for debugging
|
|
266
|
+
this.logger.info('Background update notification', { title, body });
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get current app version
|
|
271
|
+
*/
|
|
272
|
+
async getCurrentAppVersion() {
|
|
273
|
+
// Try to get version from @capacitor/app if available
|
|
274
|
+
try {
|
|
275
|
+
// Dynamic import to avoid hard dependency
|
|
276
|
+
const { App } = await import('@capacitor/app');
|
|
277
|
+
const info = await App.getInfo();
|
|
278
|
+
return info.version;
|
|
279
|
+
}
|
|
280
|
+
catch (_a) {
|
|
281
|
+
// Fallback to baseUrl config to extract app version or use default
|
|
282
|
+
return '1.0.0';
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get current platform
|
|
287
|
+
*/
|
|
288
|
+
getPlatform() {
|
|
289
|
+
if (typeof window !== 'undefined') {
|
|
290
|
+
const userAgent = window.navigator.userAgent;
|
|
291
|
+
if (/android/i.test(userAgent))
|
|
292
|
+
return 'android';
|
|
293
|
+
if (/iPad|iPhone|iPod/.test(userAgent))
|
|
294
|
+
return 'ios';
|
|
295
|
+
}
|
|
296
|
+
return 'web';
|
|
297
|
+
}
|
|
298
|
+
calculateNextCheckTime() {
|
|
299
|
+
var _a;
|
|
300
|
+
const now = Date.now();
|
|
301
|
+
const interval = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.checkInterval) || 24 * 60 * 60 * 1000; // Default 24 hours
|
|
302
|
+
return now + interval;
|
|
303
|
+
}
|
|
304
|
+
shouldRespectBatteryOptimization() {
|
|
305
|
+
var _a, _b;
|
|
306
|
+
return (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.respectBatteryOptimization) !== null && _b !== void 0 ? _b : true;
|
|
307
|
+
}
|
|
308
|
+
isNetworkConditionMet() {
|
|
309
|
+
// Check network connectivity
|
|
310
|
+
if (typeof navigator !== 'undefined' && 'onLine' in navigator) {
|
|
311
|
+
return navigator.onLine;
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
isBatteryLevelSufficient() {
|
|
316
|
+
// Battery API is deprecated in most browsers, return true by default
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
compareVersions(version1, version2) {
|
|
320
|
+
const v1Parts = version1.split('.').map(Number);
|
|
321
|
+
const v2Parts = version2.split('.').map(Number);
|
|
322
|
+
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
323
|
+
const v1Part = v1Parts[i] || 0;
|
|
324
|
+
const v2Part = v2Parts[i] || 0;
|
|
325
|
+
if (v1Part > v2Part)
|
|
326
|
+
return 1;
|
|
327
|
+
if (v1Part < v2Part)
|
|
328
|
+
return -1;
|
|
329
|
+
}
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { NotificationPreferences, NotificationPermissionStatus, AppUpdateInfo, LatestVersion } from '../definitions';
|
|
2
|
+
import { NotificationPriority } from '../definitions';
|
|
3
|
+
export interface NotificationData {
|
|
4
|
+
title: string;
|
|
5
|
+
body: string;
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
actions?: NotificationAction[];
|
|
8
|
+
}
|
|
9
|
+
export interface NotificationAction {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class NotificationManager {
|
|
15
|
+
protected preferences: NotificationPreferences;
|
|
16
|
+
setPreferences(preferences: NotificationPreferences): void;
|
|
17
|
+
abstract getPermissionStatus(): Promise<NotificationPermissionStatus>;
|
|
18
|
+
abstract requestPermissions(): Promise<boolean>;
|
|
19
|
+
abstract showNotification(data: NotificationData): Promise<boolean>;
|
|
20
|
+
abstract cancelNotification(id: string): Promise<void>;
|
|
21
|
+
abstract setupNotificationChannels(): Promise<void>;
|
|
22
|
+
sendUpdateNotification(appUpdate?: AppUpdateInfo, liveUpdate?: LatestVersion): Promise<boolean>;
|
|
23
|
+
protected createNotificationData(appUpdate?: AppUpdateInfo, liveUpdate?: LatestVersion): NotificationData;
|
|
24
|
+
protected getChannelId(): string;
|
|
25
|
+
protected getChannelName(): string;
|
|
26
|
+
protected getPriority(): NotificationPriority;
|
|
27
|
+
protected shouldPlaySound(): boolean;
|
|
28
|
+
protected shouldVibrate(): boolean;
|
|
29
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { NotificationPriority } from '../definitions';
|
|
2
|
+
export class NotificationManager {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.preferences = {
|
|
5
|
+
title: 'App Update Available',
|
|
6
|
+
description: 'A new version of the app is available',
|
|
7
|
+
soundEnabled: true,
|
|
8
|
+
vibrationEnabled: true,
|
|
9
|
+
showActions: true,
|
|
10
|
+
actionLabels: {
|
|
11
|
+
updateNow: 'Update Now',
|
|
12
|
+
updateLater: 'Later',
|
|
13
|
+
dismiss: 'Dismiss',
|
|
14
|
+
},
|
|
15
|
+
priority: NotificationPriority.DEFAULT,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
setPreferences(preferences) {
|
|
19
|
+
this.preferences = Object.assign(Object.assign({}, this.preferences), preferences);
|
|
20
|
+
}
|
|
21
|
+
async sendUpdateNotification(appUpdate, liveUpdate) {
|
|
22
|
+
const permissions = await this.getPermissionStatus();
|
|
23
|
+
if (!permissions.granted) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const notificationData = this.createNotificationData(appUpdate, liveUpdate);
|
|
27
|
+
return this.showNotification(notificationData);
|
|
28
|
+
}
|
|
29
|
+
createNotificationData(appUpdate, liveUpdate) {
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
let title = this.preferences.title || 'App Update Available';
|
|
32
|
+
let body = this.preferences.description || 'A new version of the app is available';
|
|
33
|
+
if ((appUpdate === null || appUpdate === void 0 ? void 0 : appUpdate.updateAvailable) && (liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.available)) {
|
|
34
|
+
title = 'App Updates Available';
|
|
35
|
+
body = `App version ${appUpdate.availableVersion} and content updates are available`;
|
|
36
|
+
}
|
|
37
|
+
else if (appUpdate === null || appUpdate === void 0 ? void 0 : appUpdate.updateAvailable) {
|
|
38
|
+
title = 'App Update Available';
|
|
39
|
+
body = `Version ${appUpdate.availableVersion} is available`;
|
|
40
|
+
}
|
|
41
|
+
else if (liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.available) {
|
|
42
|
+
title = 'Content Update Available';
|
|
43
|
+
body = `New content version ${liveUpdate.version} is available`;
|
|
44
|
+
}
|
|
45
|
+
const actions = [];
|
|
46
|
+
if (this.preferences.showActions) {
|
|
47
|
+
actions.push({
|
|
48
|
+
id: 'update_now',
|
|
49
|
+
title: ((_a = this.preferences.actionLabels) === null || _a === void 0 ? void 0 : _a.updateNow) || 'Update Now',
|
|
50
|
+
});
|
|
51
|
+
actions.push({
|
|
52
|
+
id: 'update_later',
|
|
53
|
+
title: ((_b = this.preferences.actionLabels) === null || _b === void 0 ? void 0 : _b.updateLater) || 'Later',
|
|
54
|
+
});
|
|
55
|
+
actions.push({
|
|
56
|
+
id: 'dismiss',
|
|
57
|
+
title: ((_c = this.preferences.actionLabels) === null || _c === void 0 ? void 0 : _c.dismiss) || 'Dismiss',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
title,
|
|
62
|
+
body,
|
|
63
|
+
data: {
|
|
64
|
+
type: 'update_available',
|
|
65
|
+
appUpdate,
|
|
66
|
+
liveUpdate,
|
|
67
|
+
},
|
|
68
|
+
actions,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
getChannelId() {
|
|
72
|
+
return this.preferences.channelId || 'capacitor_native_update';
|
|
73
|
+
}
|
|
74
|
+
getChannelName() {
|
|
75
|
+
return this.preferences.channelName || 'App Updates';
|
|
76
|
+
}
|
|
77
|
+
getPriority() {
|
|
78
|
+
return this.preferences.priority || NotificationPriority.DEFAULT;
|
|
79
|
+
}
|
|
80
|
+
shouldPlaySound() {
|
|
81
|
+
var _a;
|
|
82
|
+
return (_a = this.preferences.soundEnabled) !== null && _a !== void 0 ? _a : true;
|
|
83
|
+
}
|
|
84
|
+
shouldVibrate() {
|
|
85
|
+
var _a;
|
|
86
|
+
return (_a = this.preferences.vibrationEnabled) !== null && _a !== void 0 ? _a : true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Support configuration for native-update package
|
|
3
|
+
* Help keep this package free and improving
|
|
4
|
+
*/
|
|
5
|
+
export declare const SUPPORT_CONFIG: {
|
|
6
|
+
readonly url: "https://aoneahsan.com/payment?project-id=native-update&project-identifier=native-update";
|
|
7
|
+
readonly label: "Support the Project";
|
|
8
|
+
readonly description: "Help us keep native-update free and improving";
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Support configuration for native-update package
|
|
3
|
+
* Help keep this package free and improving
|
|
4
|
+
*/
|
|
5
|
+
export const SUPPORT_CONFIG = {
|
|
6
|
+
url: 'https://aoneahsan.com/payment?project-id=native-update&project-identifier=native-update',
|
|
7
|
+
label: 'Support the Project',
|
|
8
|
+
description: 'Help us keep native-update free and improving',
|
|
9
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface UpdateEvent {
|
|
2
|
+
type: 'check' | 'download' | 'install' | 'error' | 'rollback';
|
|
3
|
+
version?: string;
|
|
4
|
+
success: boolean;
|
|
5
|
+
duration?: number;
|
|
6
|
+
error?: string;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface AnalyticsProvider {
|
|
10
|
+
trackEvent(event: UpdateEvent): Promise<void>;
|
|
11
|
+
trackError(error: Error, context?: Record<string, unknown>): Promise<void>;
|
|
12
|
+
setUserId(userId: string): void;
|
|
13
|
+
setProperties(properties: Record<string, unknown>): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class Analytics {
|
|
16
|
+
private static instance;
|
|
17
|
+
private providers;
|
|
18
|
+
private readonly logger;
|
|
19
|
+
private userId?;
|
|
20
|
+
private properties;
|
|
21
|
+
private constructor();
|
|
22
|
+
static getInstance(): Analytics;
|
|
23
|
+
/**
|
|
24
|
+
* Add an analytics provider
|
|
25
|
+
*/
|
|
26
|
+
addProvider(provider: AnalyticsProvider): void;
|
|
27
|
+
/**
|
|
28
|
+
* Track an update event
|
|
29
|
+
*/
|
|
30
|
+
trackEvent(event: UpdateEvent): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Track an error
|
|
33
|
+
*/
|
|
34
|
+
trackError(error: Error, context?: Record<string, unknown>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Set user ID for analytics
|
|
37
|
+
*/
|
|
38
|
+
setUserId(userId: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Set global properties
|
|
41
|
+
*/
|
|
42
|
+
setProperties(properties: Record<string, unknown>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Track update check
|
|
45
|
+
*/
|
|
46
|
+
trackUpdateCheck(available: boolean, version?: string): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Track download progress
|
|
49
|
+
*/
|
|
50
|
+
trackDownload(version: string, success: boolean, error?: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Track installation
|
|
53
|
+
*/
|
|
54
|
+
trackInstall(version: string, success: boolean, error?: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Track rollback
|
|
57
|
+
*/
|
|
58
|
+
trackRollback(fromVersion: string, toVersion: string, reason: string): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Console analytics provider for development
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Default analytics provider that writes events directly to the
|
|
65
|
+
* browser/native console. Production apps should swap this for a real
|
|
66
|
+
* provider (Firebase Analytics, Amplitude, Sentry, …) via
|
|
67
|
+
* `setAnalyticsProvider()`.
|
|
68
|
+
*
|
|
69
|
+
* The two `console.*` calls below are intentional and on-brand for this
|
|
70
|
+
* class — `ConsoleAnalyticsProvider` IS the "send to console" sink. They
|
|
71
|
+
* are NOT a violation of the centralized-logger rule (which targets
|
|
72
|
+
* incidental logging, not analytics dispatch). Do not replace with the
|
|
73
|
+
* Logger — it would create a circular relationship between analytics
|
|
74
|
+
* and logging surfaces.
|
|
75
|
+
*/
|
|
76
|
+
export declare class ConsoleAnalyticsProvider implements AnalyticsProvider {
|
|
77
|
+
private userId?;
|
|
78
|
+
private properties;
|
|
79
|
+
trackEvent(event: UpdateEvent): Promise<void>;
|
|
80
|
+
trackError(error: Error, context?: Record<string, unknown>): Promise<void>;
|
|
81
|
+
setUserId(userId: string): void;
|
|
82
|
+
setProperties(properties: Record<string, unknown>): void;
|
|
83
|
+
}
|