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.
- 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/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 +262 -0
- package/cli/commands/remote.js +622 -0
- package/cli/commands/server-start.js +96 -0
- package/cli/index.js +605 -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 +993 -0
- package/docs/KNOWN_LIMITATIONS.md +235 -0
- package/docs/MIGRATION.md +391 -0
- package/docs/protocol/CLIENT-PROTOCOL.md +178 -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 +135 -4
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Logger } from './logger';
|
|
2
|
+
export class Analytics {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.providers = [];
|
|
5
|
+
this.properties = {};
|
|
6
|
+
this.logger = Logger.getInstance();
|
|
7
|
+
}
|
|
8
|
+
static getInstance() {
|
|
9
|
+
if (!Analytics.instance) {
|
|
10
|
+
Analytics.instance = new Analytics();
|
|
11
|
+
}
|
|
12
|
+
return Analytics.instance;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Add an analytics provider
|
|
16
|
+
*/
|
|
17
|
+
addProvider(provider) {
|
|
18
|
+
this.providers.push(provider);
|
|
19
|
+
// Set existing user ID and properties
|
|
20
|
+
if (this.userId) {
|
|
21
|
+
provider.setUserId(this.userId);
|
|
22
|
+
}
|
|
23
|
+
if (Object.keys(this.properties).length > 0) {
|
|
24
|
+
provider.setProperties(this.properties);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Track an update event
|
|
29
|
+
*/
|
|
30
|
+
async trackEvent(event) {
|
|
31
|
+
this.logger.debug('Analytics event', event);
|
|
32
|
+
const promises = this.providers.map((provider) => provider
|
|
33
|
+
.trackEvent(event)
|
|
34
|
+
.catch((error) => this.logger.error('Analytics provider error', error)));
|
|
35
|
+
await Promise.all(promises);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Track an error
|
|
39
|
+
*/
|
|
40
|
+
async trackError(error, context) {
|
|
41
|
+
this.logger.error('Analytics error', { error, context });
|
|
42
|
+
const promises = this.providers.map((provider) => provider
|
|
43
|
+
.trackError(error, context)
|
|
44
|
+
.catch((err) => this.logger.error('Analytics provider error', err)));
|
|
45
|
+
await Promise.all(promises);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set user ID for analytics
|
|
49
|
+
*/
|
|
50
|
+
setUserId(userId) {
|
|
51
|
+
this.userId = userId;
|
|
52
|
+
this.providers.forEach((provider) => provider.setUserId(userId));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Set global properties
|
|
56
|
+
*/
|
|
57
|
+
setProperties(properties) {
|
|
58
|
+
this.properties = Object.assign(Object.assign({}, this.properties), properties);
|
|
59
|
+
this.providers.forEach((provider) => provider.setProperties(this.properties));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Track update check
|
|
63
|
+
*/
|
|
64
|
+
async trackUpdateCheck(available, version) {
|
|
65
|
+
const startTime = Date.now();
|
|
66
|
+
await this.trackEvent({
|
|
67
|
+
type: 'check',
|
|
68
|
+
version,
|
|
69
|
+
success: true,
|
|
70
|
+
metadata: { updateAvailable: available },
|
|
71
|
+
duration: Date.now() - startTime,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Track download progress
|
|
76
|
+
*/
|
|
77
|
+
async trackDownload(version, success, error) {
|
|
78
|
+
await this.trackEvent({
|
|
79
|
+
type: 'download',
|
|
80
|
+
version,
|
|
81
|
+
success,
|
|
82
|
+
error,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Track installation
|
|
87
|
+
*/
|
|
88
|
+
async trackInstall(version, success, error) {
|
|
89
|
+
await this.trackEvent({
|
|
90
|
+
type: 'install',
|
|
91
|
+
version,
|
|
92
|
+
success,
|
|
93
|
+
error,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Track rollback
|
|
98
|
+
*/
|
|
99
|
+
async trackRollback(fromVersion, toVersion, reason) {
|
|
100
|
+
await this.trackEvent({
|
|
101
|
+
type: 'rollback',
|
|
102
|
+
success: true,
|
|
103
|
+
metadata: {
|
|
104
|
+
fromVersion,
|
|
105
|
+
toVersion,
|
|
106
|
+
reason,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Console analytics provider for development
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Default analytics provider that writes events directly to the
|
|
116
|
+
* browser/native console. Production apps should swap this for a real
|
|
117
|
+
* provider (Firebase Analytics, Amplitude, Sentry, …) via
|
|
118
|
+
* `setAnalyticsProvider()`.
|
|
119
|
+
*
|
|
120
|
+
* The two `console.*` calls below are intentional and on-brand for this
|
|
121
|
+
* class — `ConsoleAnalyticsProvider` IS the "send to console" sink. They
|
|
122
|
+
* are NOT a violation of the centralized-logger rule (which targets
|
|
123
|
+
* incidental logging, not analytics dispatch). Do not replace with the
|
|
124
|
+
* Logger — it would create a circular relationship between analytics
|
|
125
|
+
* and logging surfaces.
|
|
126
|
+
*/
|
|
127
|
+
export class ConsoleAnalyticsProvider {
|
|
128
|
+
constructor() {
|
|
129
|
+
this.properties = {};
|
|
130
|
+
}
|
|
131
|
+
async trackEvent(event) {
|
|
132
|
+
// ConsoleAnalyticsProvider intentionally writes to console — see class header.
|
|
133
|
+
console.log('[Analytics]', event.type, Object.assign(Object.assign({}, event), { userId: this.userId, properties: this.properties }));
|
|
134
|
+
}
|
|
135
|
+
async trackError(error, context) {
|
|
136
|
+
// ConsoleAnalyticsProvider intentionally writes to console — see class header.
|
|
137
|
+
console.error('[Analytics Error]', {
|
|
138
|
+
error: error.message,
|
|
139
|
+
stack: error.stack,
|
|
140
|
+
context,
|
|
141
|
+
userId: this.userId,
|
|
142
|
+
properties: this.properties,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
setUserId(userId) {
|
|
146
|
+
this.userId = userId;
|
|
147
|
+
}
|
|
148
|
+
setProperties(properties) {
|
|
149
|
+
this.properties = Object.assign(Object.assign({}, this.properties), properties);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { BundleInfo } from '../definitions';
|
|
2
|
+
/**
|
|
3
|
+
* Manages caching with expiration for various data types
|
|
4
|
+
*/
|
|
5
|
+
export declare class CacheManager {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly configManager;
|
|
8
|
+
private filesystem;
|
|
9
|
+
private memoryCache;
|
|
10
|
+
private readonly CACHE_DIR;
|
|
11
|
+
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Initialize cache manager
|
|
14
|
+
*/
|
|
15
|
+
initialize(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Set cache entry with expiration
|
|
18
|
+
*/
|
|
19
|
+
set<T>(key: string, data: T, ttlMs?: number): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get cache entry
|
|
22
|
+
*/
|
|
23
|
+
get<T>(key: string): Promise<T | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Check if cache entry exists and is valid
|
|
26
|
+
*/
|
|
27
|
+
has(key: string): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Remove cache entry
|
|
30
|
+
*/
|
|
31
|
+
remove(key: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Clear all cache
|
|
34
|
+
*/
|
|
35
|
+
clear(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Clean expired cache entries
|
|
38
|
+
*/
|
|
39
|
+
cleanExpiredCache(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Get cache statistics
|
|
42
|
+
*/
|
|
43
|
+
getStats(): Promise<{
|
|
44
|
+
memoryEntries: number;
|
|
45
|
+
fileEntries: number;
|
|
46
|
+
totalSize: number;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Cache bundle metadata
|
|
50
|
+
*/
|
|
51
|
+
cacheBundleMetadata(bundle: BundleInfo): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get cached bundle metadata
|
|
54
|
+
*/
|
|
55
|
+
getCachedBundleMetadata(bundleId: string): Promise<BundleInfo | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Check if data should be persisted to filesystem
|
|
58
|
+
*/
|
|
59
|
+
private shouldPersist;
|
|
60
|
+
/**
|
|
61
|
+
* Persist cache entry to file
|
|
62
|
+
*/
|
|
63
|
+
private persistToFile;
|
|
64
|
+
/**
|
|
65
|
+
* Load cache entry from file
|
|
66
|
+
*/
|
|
67
|
+
private loadFromFile;
|
|
68
|
+
/**
|
|
69
|
+
* Remove cache file
|
|
70
|
+
*/
|
|
71
|
+
private removeFile;
|
|
72
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { ConfigManager } from './config';
|
|
2
|
+
import { Logger } from './logger';
|
|
3
|
+
import { Directory, Encoding } from '@capacitor/filesystem';
|
|
4
|
+
/**
|
|
5
|
+
* Manages caching with expiration for various data types
|
|
6
|
+
*/
|
|
7
|
+
export class CacheManager {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.filesystem = null;
|
|
10
|
+
this.memoryCache = new Map();
|
|
11
|
+
this.CACHE_DIR = 'cache';
|
|
12
|
+
this.logger = Logger.getInstance();
|
|
13
|
+
this.configManager = ConfigManager.getInstance();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Initialize cache manager
|
|
17
|
+
*/
|
|
18
|
+
async initialize() {
|
|
19
|
+
this.filesystem = this.configManager.get('filesystem');
|
|
20
|
+
if (!this.filesystem) {
|
|
21
|
+
throw new Error('Filesystem not configured');
|
|
22
|
+
}
|
|
23
|
+
// Create cache directory if it doesn't exist
|
|
24
|
+
try {
|
|
25
|
+
await this.filesystem.mkdir({
|
|
26
|
+
path: this.CACHE_DIR,
|
|
27
|
+
directory: Directory.Data,
|
|
28
|
+
recursive: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
this.logger.debug('Cache directory may already exist', error);
|
|
33
|
+
}
|
|
34
|
+
// Clean expired cache on initialization
|
|
35
|
+
await this.cleanExpiredCache();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set cache entry with expiration
|
|
39
|
+
*/
|
|
40
|
+
async set(key, data, ttlMs) {
|
|
41
|
+
const expiry = Date.now() + (ttlMs || this.configManager.get('cacheExpiration'));
|
|
42
|
+
const entry = {
|
|
43
|
+
data,
|
|
44
|
+
timestamp: Date.now(),
|
|
45
|
+
expiry,
|
|
46
|
+
};
|
|
47
|
+
// Update memory cache
|
|
48
|
+
this.memoryCache.set(key, entry);
|
|
49
|
+
// Persist to filesystem for larger data
|
|
50
|
+
if (this.shouldPersist(data)) {
|
|
51
|
+
await this.persistToFile(key, entry);
|
|
52
|
+
}
|
|
53
|
+
this.logger.debug('Cache entry set', { key, expiry: new Date(expiry) });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get cache entry
|
|
57
|
+
*/
|
|
58
|
+
async get(key) {
|
|
59
|
+
// Check memory cache first
|
|
60
|
+
const memEntry = this.memoryCache.get(key);
|
|
61
|
+
if (memEntry) {
|
|
62
|
+
if (Date.now() < memEntry.expiry) {
|
|
63
|
+
return memEntry.data;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// Expired - remove from memory
|
|
67
|
+
this.memoryCache.delete(key);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Check filesystem cache
|
|
71
|
+
const fileEntry = await this.loadFromFile(key);
|
|
72
|
+
if (fileEntry) {
|
|
73
|
+
if (Date.now() < fileEntry.expiry) {
|
|
74
|
+
// Update memory cache
|
|
75
|
+
this.memoryCache.set(key, fileEntry);
|
|
76
|
+
return fileEntry.data;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Expired - remove file
|
|
80
|
+
await this.removeFile(key);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if cache entry exists and is valid
|
|
87
|
+
*/
|
|
88
|
+
async has(key) {
|
|
89
|
+
const value = await this.get(key);
|
|
90
|
+
return value !== null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Remove cache entry
|
|
94
|
+
*/
|
|
95
|
+
async remove(key) {
|
|
96
|
+
this.memoryCache.delete(key);
|
|
97
|
+
await this.removeFile(key);
|
|
98
|
+
this.logger.debug('Cache entry removed', { key });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Clear all cache
|
|
102
|
+
*/
|
|
103
|
+
async clear() {
|
|
104
|
+
this.memoryCache.clear();
|
|
105
|
+
// Remove cache directory
|
|
106
|
+
try {
|
|
107
|
+
await this.filesystem.rmdir({
|
|
108
|
+
path: this.CACHE_DIR,
|
|
109
|
+
directory: Directory.Data,
|
|
110
|
+
recursive: true,
|
|
111
|
+
});
|
|
112
|
+
// Recreate empty cache directory
|
|
113
|
+
await this.filesystem.mkdir({
|
|
114
|
+
path: this.CACHE_DIR,
|
|
115
|
+
directory: Directory.Data,
|
|
116
|
+
recursive: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
this.logger.warn('Failed to clear cache directory', error);
|
|
121
|
+
}
|
|
122
|
+
this.logger.info('Cache cleared');
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Clean expired cache entries
|
|
126
|
+
*/
|
|
127
|
+
async cleanExpiredCache() {
|
|
128
|
+
const now = Date.now();
|
|
129
|
+
let cleanedCount = 0;
|
|
130
|
+
// Clean memory cache
|
|
131
|
+
for (const [key, entry] of this.memoryCache) {
|
|
132
|
+
if (now >= entry.expiry) {
|
|
133
|
+
this.memoryCache.delete(key);
|
|
134
|
+
cleanedCount++;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Clean filesystem cache
|
|
138
|
+
try {
|
|
139
|
+
const files = await this.filesystem.readdir({
|
|
140
|
+
path: this.CACHE_DIR,
|
|
141
|
+
directory: Directory.Data,
|
|
142
|
+
});
|
|
143
|
+
for (const file of files.files) {
|
|
144
|
+
const key = file.name.replace('.json', '');
|
|
145
|
+
const entry = await this.loadFromFile(key);
|
|
146
|
+
if (!entry || now >= entry.expiry) {
|
|
147
|
+
await this.removeFile(key);
|
|
148
|
+
cleanedCount++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
this.logger.debug('Failed to clean filesystem cache', error);
|
|
154
|
+
}
|
|
155
|
+
if (cleanedCount > 0) {
|
|
156
|
+
this.logger.info('Cleaned expired cache entries', {
|
|
157
|
+
count: cleanedCount,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get cache statistics
|
|
163
|
+
*/
|
|
164
|
+
async getStats() {
|
|
165
|
+
let fileEntries = 0;
|
|
166
|
+
let totalSize = 0;
|
|
167
|
+
try {
|
|
168
|
+
const files = await this.filesystem.readdir({
|
|
169
|
+
path: this.CACHE_DIR,
|
|
170
|
+
directory: Directory.Data,
|
|
171
|
+
});
|
|
172
|
+
fileEntries = files.files.length;
|
|
173
|
+
// Estimate size (this is approximate)
|
|
174
|
+
for (const file of files.files) {
|
|
175
|
+
const stat = await this.filesystem.stat({
|
|
176
|
+
path: `${this.CACHE_DIR}/${file.name}`,
|
|
177
|
+
directory: Directory.Data,
|
|
178
|
+
});
|
|
179
|
+
totalSize += stat.size || 0;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
this.logger.debug('Failed to get cache stats', error);
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
memoryEntries: this.memoryCache.size,
|
|
187
|
+
fileEntries,
|
|
188
|
+
totalSize,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Cache bundle metadata
|
|
193
|
+
*/
|
|
194
|
+
async cacheBundleMetadata(bundle) {
|
|
195
|
+
const key = `bundle_meta_${bundle.bundleId}`;
|
|
196
|
+
await this.set(key, bundle, 24 * 60 * 60 * 1000); // 24 hours
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get cached bundle metadata
|
|
200
|
+
*/
|
|
201
|
+
async getCachedBundleMetadata(bundleId) {
|
|
202
|
+
const key = `bundle_meta_${bundleId}`;
|
|
203
|
+
return this.get(key);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Check if data should be persisted to filesystem
|
|
207
|
+
*/
|
|
208
|
+
shouldPersist(data) {
|
|
209
|
+
// Persist objects and large strings
|
|
210
|
+
if (typeof data === 'object')
|
|
211
|
+
return true;
|
|
212
|
+
if (typeof data === 'string' && data.length > 1024)
|
|
213
|
+
return true;
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Persist cache entry to file
|
|
218
|
+
*/
|
|
219
|
+
async persistToFile(key, entry) {
|
|
220
|
+
if (!this.filesystem)
|
|
221
|
+
return;
|
|
222
|
+
try {
|
|
223
|
+
const path = `${this.CACHE_DIR}/${key}.json`;
|
|
224
|
+
const data = JSON.stringify(entry);
|
|
225
|
+
await this.filesystem.writeFile({
|
|
226
|
+
path,
|
|
227
|
+
data,
|
|
228
|
+
directory: Directory.Data,
|
|
229
|
+
encoding: Encoding.UTF8,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
this.logger.warn('Failed to persist cache to file', { key, error });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Load cache entry from file
|
|
238
|
+
*/
|
|
239
|
+
async loadFromFile(key) {
|
|
240
|
+
if (!this.filesystem)
|
|
241
|
+
return null;
|
|
242
|
+
try {
|
|
243
|
+
const path = `${this.CACHE_DIR}/${key}.json`;
|
|
244
|
+
const result = await this.filesystem.readFile({
|
|
245
|
+
path,
|
|
246
|
+
directory: Directory.Data,
|
|
247
|
+
encoding: Encoding.UTF8,
|
|
248
|
+
});
|
|
249
|
+
return JSON.parse(result.data);
|
|
250
|
+
}
|
|
251
|
+
catch (_a) {
|
|
252
|
+
// File doesn't exist or is corrupted
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Remove cache file
|
|
258
|
+
*/
|
|
259
|
+
async removeFile(key) {
|
|
260
|
+
if (!this.filesystem)
|
|
261
|
+
return;
|
|
262
|
+
try {
|
|
263
|
+
const path = `${this.CACHE_DIR}/${key}.json`;
|
|
264
|
+
await this.filesystem.deleteFile({
|
|
265
|
+
path,
|
|
266
|
+
directory: Directory.Data,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
// File may not exist
|
|
271
|
+
this.logger.debug('Failed to remove cache file', { key, error });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Filesystem } from '@capacitor/filesystem';
|
|
2
|
+
import type { Preferences } from '@capacitor/preferences';
|
|
3
|
+
import type { UpdateStrategy, ChecksumAlgorithm, SecurityConfig } from '../definitions';
|
|
4
|
+
export interface PluginConfig {
|
|
5
|
+
filesystem?: typeof Filesystem;
|
|
6
|
+
preferences?: typeof Preferences;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
allowedHosts?: string[];
|
|
9
|
+
maxBundleSize?: number;
|
|
10
|
+
maxUncompressedBundleSize?: number;
|
|
11
|
+
downloadTimeout?: number;
|
|
12
|
+
retryAttempts?: number;
|
|
13
|
+
retryDelay?: number;
|
|
14
|
+
enableSignatureValidation?: boolean;
|
|
15
|
+
publicKey?: string;
|
|
16
|
+
cacheExpiration?: number;
|
|
17
|
+
enableLogging?: boolean;
|
|
18
|
+
serverUrl?: string;
|
|
19
|
+
channel?: string;
|
|
20
|
+
appId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* API key for authentication with the Native Update backend
|
|
23
|
+
* Get this from the Native Update dashboard after creating your app
|
|
24
|
+
* Format: nu_app_… (the device update plane). This is NOT an nu_pat_…
|
|
25
|
+
* access token — those authenticate the management API, not the plugin.
|
|
26
|
+
*/
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
autoCheck?: boolean;
|
|
29
|
+
autoUpdate?: boolean;
|
|
30
|
+
updateStrategy?: UpdateStrategy;
|
|
31
|
+
requireSignature?: boolean;
|
|
32
|
+
checksumAlgorithm?: ChecksumAlgorithm;
|
|
33
|
+
checkInterval?: number;
|
|
34
|
+
security?: SecurityConfig;
|
|
35
|
+
allowUnsignedDevelopmentUpdates?: boolean;
|
|
36
|
+
promptAfterPositiveEvents?: boolean;
|
|
37
|
+
maxPromptsPerVersion?: number;
|
|
38
|
+
minimumDaysSinceLastPrompt?: number;
|
|
39
|
+
isPremiumUser?: boolean;
|
|
40
|
+
appStoreId?: string;
|
|
41
|
+
iosAppId?: string;
|
|
42
|
+
packageName?: string;
|
|
43
|
+
webReviewUrl?: string;
|
|
44
|
+
minimumVersion?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Enable delta updates (binary patching)
|
|
47
|
+
* Reduces download size by 50-90%
|
|
48
|
+
*/
|
|
49
|
+
enableDeltaUpdates?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Enable staged rollouts
|
|
52
|
+
* Allows gradual deployment to a percentage of users
|
|
53
|
+
*/
|
|
54
|
+
enableStagedRollouts?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export declare class ConfigManager {
|
|
57
|
+
private static instance;
|
|
58
|
+
private config;
|
|
59
|
+
private constructor();
|
|
60
|
+
static getInstance(): ConfigManager;
|
|
61
|
+
private getDefaultConfig;
|
|
62
|
+
configure(config: PluginConfig): void;
|
|
63
|
+
reset(): void;
|
|
64
|
+
private validateConfig;
|
|
65
|
+
get<K extends keyof Required<PluginConfig>>(key: K): Required<PluginConfig>[K];
|
|
66
|
+
set<K extends keyof Required<PluginConfig>>(key: K, value: Required<PluginConfig>[K]): void;
|
|
67
|
+
getAll(): Required<PluginConfig>;
|
|
68
|
+
isConfigured(): boolean;
|
|
69
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export class ConfigManager {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.config = this.getDefaultConfig();
|
|
4
|
+
}
|
|
5
|
+
static getInstance() {
|
|
6
|
+
if (!ConfigManager.instance) {
|
|
7
|
+
ConfigManager.instance = new ConfigManager();
|
|
8
|
+
}
|
|
9
|
+
return ConfigManager.instance;
|
|
10
|
+
}
|
|
11
|
+
getDefaultConfig() {
|
|
12
|
+
return {
|
|
13
|
+
filesystem: null,
|
|
14
|
+
preferences: null,
|
|
15
|
+
baseUrl: '',
|
|
16
|
+
allowedHosts: [],
|
|
17
|
+
maxBundleSize: 100 * 1024 * 1024, // 100MB
|
|
18
|
+
maxUncompressedBundleSize: 500 * 1024 * 1024, // 500MB
|
|
19
|
+
downloadTimeout: 30000, // 30 seconds
|
|
20
|
+
retryAttempts: 3,
|
|
21
|
+
retryDelay: 1000, // 1 second
|
|
22
|
+
enableSignatureValidation: true,
|
|
23
|
+
publicKey: '',
|
|
24
|
+
cacheExpiration: 24 * 60 * 60 * 1000, // 24 hours
|
|
25
|
+
enableLogging: false,
|
|
26
|
+
serverUrl: '',
|
|
27
|
+
channel: 'production',
|
|
28
|
+
appId: '',
|
|
29
|
+
apiKey: '',
|
|
30
|
+
autoCheck: true,
|
|
31
|
+
autoUpdate: false,
|
|
32
|
+
updateStrategy: 'background',
|
|
33
|
+
requireSignature: true,
|
|
34
|
+
checksumAlgorithm: 'SHA-256',
|
|
35
|
+
checkInterval: 24 * 60 * 60 * 1000, // 24 hours
|
|
36
|
+
security: {
|
|
37
|
+
enforceHttps: true,
|
|
38
|
+
validateInputs: true,
|
|
39
|
+
secureStorage: true,
|
|
40
|
+
logSecurityEvents: false,
|
|
41
|
+
},
|
|
42
|
+
allowUnsignedDevelopmentUpdates: false,
|
|
43
|
+
// App review config
|
|
44
|
+
promptAfterPositiveEvents: false,
|
|
45
|
+
maxPromptsPerVersion: 1,
|
|
46
|
+
minimumDaysSinceLastPrompt: 7,
|
|
47
|
+
isPremiumUser: false,
|
|
48
|
+
// Platform-specific config
|
|
49
|
+
appStoreId: '',
|
|
50
|
+
iosAppId: '',
|
|
51
|
+
packageName: '',
|
|
52
|
+
webReviewUrl: '',
|
|
53
|
+
minimumVersion: '1.0.0',
|
|
54
|
+
enableDeltaUpdates: true,
|
|
55
|
+
enableStagedRollouts: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
configure(config) {
|
|
59
|
+
this.config = Object.assign(Object.assign({}, this.config), config);
|
|
60
|
+
this.validateConfig();
|
|
61
|
+
}
|
|
62
|
+
reset() {
|
|
63
|
+
this.config = this.getDefaultConfig();
|
|
64
|
+
}
|
|
65
|
+
validateConfig() {
|
|
66
|
+
// Validate HTTPS for baseUrl (security requirement)
|
|
67
|
+
if (this.config.baseUrl && !this.config.baseUrl.startsWith('https://')) {
|
|
68
|
+
throw new Error('baseUrl must use HTTPS protocol for security');
|
|
69
|
+
}
|
|
70
|
+
if (this.config.maxBundleSize <= 0) {
|
|
71
|
+
throw new Error('maxBundleSize must be greater than 0');
|
|
72
|
+
}
|
|
73
|
+
if (this.config.maxUncompressedBundleSize <= 0) {
|
|
74
|
+
throw new Error('maxUncompressedBundleSize must be greater than 0');
|
|
75
|
+
}
|
|
76
|
+
if (this.config.downloadTimeout <= 0) {
|
|
77
|
+
throw new Error('downloadTimeout must be greater than 0');
|
|
78
|
+
}
|
|
79
|
+
if (this.config.retryAttempts < 0) {
|
|
80
|
+
throw new Error('retryAttempts must be non-negative');
|
|
81
|
+
}
|
|
82
|
+
if (this.config.retryDelay < 0) {
|
|
83
|
+
throw new Error('retryDelay must be non-negative');
|
|
84
|
+
}
|
|
85
|
+
if (this.config.security.enforceHttps === false) {
|
|
86
|
+
throw new Error('HTTPS enforcement cannot be disabled');
|
|
87
|
+
}
|
|
88
|
+
if ((this.config.serverUrl || this.config.apiKey) && this.config.requireSignature && !this.config.publicKey) {
|
|
89
|
+
throw new Error('publicKey is required when requireSignature is enabled');
|
|
90
|
+
}
|
|
91
|
+
if (!this.config.requireSignature && !this.config.allowUnsignedDevelopmentUpdates) {
|
|
92
|
+
throw new Error('Disabling signatures requires allowUnsignedDevelopmentUpdates for an explicit development-only setup');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
get(key) {
|
|
96
|
+
return this.config[key];
|
|
97
|
+
}
|
|
98
|
+
set(key, value) {
|
|
99
|
+
this.config[key] = value;
|
|
100
|
+
}
|
|
101
|
+
getAll() {
|
|
102
|
+
return Object.assign({}, this.config);
|
|
103
|
+
}
|
|
104
|
+
isConfigured() {
|
|
105
|
+
return !!(this.config.filesystem && this.config.preferences);
|
|
106
|
+
}
|
|
107
|
+
}
|