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,224 @@
1
+ import { Filesystem } from '@capacitor/filesystem';
2
+ import { Preferences } from '@capacitor/preferences';
3
+ import { ConfigManager } from './config';
4
+ import { Logger } from './logger';
5
+ import { SecurityValidator } from './security';
6
+ import { BundleManager } from '../live-update/bundle-manager';
7
+ import { DownloadManager } from '../live-update/download-manager';
8
+ import { VersionManager } from '../live-update/version-manager';
9
+ import { AppUpdateManager } from '../app-update/app-update-manager';
10
+ import { BackgroundScheduler } from '../background-update/background-scheduler';
11
+ import { EventEmitter } from './event-emitter';
12
+ import { NativeUpdateError, ErrorCode } from './errors';
13
+ /**
14
+ * Central manager for all plugin components
15
+ */
16
+ export class PluginManager {
17
+ constructor() {
18
+ this.bundleManager = null;
19
+ this.downloadManager = null;
20
+ this.versionManager = null;
21
+ this.appUpdateManager = null;
22
+ this.backgroundScheduler = null;
23
+ this.initialized = false;
24
+ this.configManager = ConfigManager.getInstance();
25
+ this.logger = Logger.getInstance();
26
+ this.securityValidator = SecurityValidator.getInstance();
27
+ this.eventEmitter = EventEmitter.getInstance();
28
+ }
29
+ static getInstance() {
30
+ if (!PluginManager.instance) {
31
+ PluginManager.instance = new PluginManager();
32
+ }
33
+ return PluginManager.instance;
34
+ }
35
+ /**
36
+ * Initialize the plugin with configuration
37
+ */
38
+ async initialize(config) {
39
+ var _a, _b;
40
+ if (this.initialized) {
41
+ this.logger.warn('Plugin already initialized');
42
+ return;
43
+ }
44
+ try {
45
+ // Use Capacitor plugins directly if not provided
46
+ if (!config.filesystem) {
47
+ config.filesystem = Filesystem;
48
+ }
49
+ if (!config.preferences) {
50
+ config.preferences = Preferences;
51
+ }
52
+ // Configure only after defaults are injected so isConfigured() sees
53
+ // the same complete configuration used by all managers.
54
+ this.configManager.configure(config);
55
+ // Initialize managers
56
+ this.bundleManager = new BundleManager();
57
+ await this.bundleManager.initialize();
58
+ this.downloadManager = new DownloadManager();
59
+ await this.downloadManager.initialize();
60
+ // Bundle manager needs the download manager so deleteBundle can
61
+ // also remove the on-disk blob (otherwise old bundles leak forever).
62
+ this.bundleManager.setDownloadManager(this.downloadManager);
63
+ this.versionManager = new VersionManager();
64
+ await this.versionManager.initialize();
65
+ this.appUpdateManager = new AppUpdateManager({
66
+ serverUrl: config.serverUrl || config.baseUrl || '',
67
+ channel: config.channel || 'production',
68
+ autoCheck: (_a = config.autoCheck) !== null && _a !== void 0 ? _a : true,
69
+ autoUpdate: (_b = config.autoUpdate) !== null && _b !== void 0 ? _b : false,
70
+ updateStrategy: config.updateStrategy,
71
+ publicKey: config.publicKey,
72
+ requireSignature: config.requireSignature,
73
+ checksumAlgorithm: config.checksumAlgorithm,
74
+ checkInterval: config.checkInterval,
75
+ security: config.security,
76
+ });
77
+ // Wire up app update manager events to central event emitter
78
+ this.setupAppUpdateEventBridge();
79
+ // Initialize background scheduler with dependencies
80
+ this.backgroundScheduler = new BackgroundScheduler();
81
+ this.backgroundScheduler.setDependencies({
82
+ appUpdateManager: this.appUpdateManager,
83
+ versionManager: this.versionManager,
84
+ bundleManager: this.bundleManager,
85
+ });
86
+ this.initialized = true;
87
+ this.logger.info('Plugin initialized successfully');
88
+ }
89
+ catch (error) {
90
+ this.logger.error('Failed to initialize plugin', error);
91
+ throw error;
92
+ }
93
+ }
94
+ /**
95
+ * Check if plugin is initialized
96
+ */
97
+ isInitialized() {
98
+ return this.initialized && this.configManager.isConfigured();
99
+ }
100
+ /**
101
+ * Ensure plugin is initialized
102
+ */
103
+ ensureInitialized() {
104
+ if (!this.isInitialized()) {
105
+ throw new NativeUpdateError(ErrorCode.NOT_CONFIGURED, 'Plugin not initialized. Please call initialize() first.');
106
+ }
107
+ }
108
+ /**
109
+ * Get bundle manager
110
+ */
111
+ getBundleManager() {
112
+ this.ensureInitialized();
113
+ return this.bundleManager;
114
+ }
115
+ /**
116
+ * Get download manager
117
+ */
118
+ getDownloadManager() {
119
+ this.ensureInitialized();
120
+ return this.downloadManager;
121
+ }
122
+ /**
123
+ * Get version manager
124
+ */
125
+ getVersionManager() {
126
+ this.ensureInitialized();
127
+ return this.versionManager;
128
+ }
129
+ /**
130
+ * Get configuration manager
131
+ */
132
+ getConfigManager() {
133
+ return this.configManager;
134
+ }
135
+ /**
136
+ * Get logger
137
+ */
138
+ getLogger() {
139
+ return this.logger;
140
+ }
141
+ /**
142
+ * Get security validator
143
+ */
144
+ getSecurityValidator() {
145
+ return this.securityValidator;
146
+ }
147
+ /**
148
+ * Get app update manager
149
+ */
150
+ getAppUpdateManager() {
151
+ this.ensureInitialized();
152
+ return this.appUpdateManager;
153
+ }
154
+ /**
155
+ * Get event emitter
156
+ */
157
+ getEventEmitter() {
158
+ return this.eventEmitter;
159
+ }
160
+ /**
161
+ * Get background scheduler
162
+ */
163
+ getBackgroundScheduler() {
164
+ this.ensureInitialized();
165
+ return this.backgroundScheduler;
166
+ }
167
+ /**
168
+ * Reset plugin state
169
+ */
170
+ async reset() {
171
+ this.logger.info('Resetting plugin state');
172
+ // Clear all data
173
+ if (this.bundleManager) {
174
+ await this.bundleManager.clearAllBundles();
175
+ }
176
+ if (this.versionManager) {
177
+ await this.versionManager.clearVersionCache();
178
+ }
179
+ if (this.downloadManager) {
180
+ this.downloadManager.cancelAllDownloads();
181
+ }
182
+ // Reset initialization state
183
+ this.bundleManager = null;
184
+ this.downloadManager = null;
185
+ this.versionManager = null;
186
+ this.appUpdateManager = null;
187
+ this.backgroundScheduler = null;
188
+ this.initialized = false;
189
+ this.configManager.reset();
190
+ // Clear all event listeners
191
+ this.eventEmitter.removeAllListeners();
192
+ this.logger.info('Plugin reset complete');
193
+ }
194
+ /**
195
+ * Clean up resources
196
+ */
197
+ async cleanup() {
198
+ this.logger.info('Cleaning up plugin resources');
199
+ // Cancel any active downloads
200
+ if (this.downloadManager) {
201
+ this.downloadManager.cancelAllDownloads();
202
+ }
203
+ // Clean expired bundles
204
+ if (this.bundleManager) {
205
+ await this.bundleManager.cleanExpiredBundles();
206
+ }
207
+ this.logger.info('Cleanup complete');
208
+ }
209
+ /**
210
+ * Setup event bridge between AppUpdateManager and central EventEmitter
211
+ */
212
+ setupAppUpdateEventBridge() {
213
+ if (!this.appUpdateManager)
214
+ return;
215
+ // Bridge appUpdateStateChanged events
216
+ this.appUpdateManager.addListener('appUpdateStateChanged', (event) => {
217
+ this.eventEmitter.emit('appUpdateStateChanged', event);
218
+ });
219
+ // Bridge appUpdateProgress events
220
+ this.appUpdateManager.addListener('appUpdateProgress', (event) => {
221
+ this.eventEmitter.emit('appUpdateProgress', event);
222
+ });
223
+ }
224
+ }
@@ -0,0 +1,123 @@
1
+ export declare class SecurityValidator {
2
+ private static instance;
3
+ private readonly configManager;
4
+ private readonly logger;
5
+ private constructor();
6
+ static getInstance(): SecurityValidator;
7
+ /**
8
+ * Validate URL is HTTPS
9
+ */
10
+ static validateUrl(url: string): boolean;
11
+ /**
12
+ * Reject any URL that is not HTTPS (or known native-app schemes
13
+ * `market:` / `itms-apps:` for opening the app store). Throws so
14
+ * callers can't silently fall through to a `javascript:` payload.
15
+ */
16
+ static validateDownloadUrl(url: string): void;
17
+ /**
18
+ * Validate URL whose only acceptable schemes are HTTPS, `market:` (Play
19
+ * Store), or `itms-apps:` (App Store). Used by `openAppStore`.
20
+ */
21
+ static validateStoreUrl(url: string): void;
22
+ /**
23
+ * Validate checksum format
24
+ */
25
+ static validateChecksum(checksum: string): boolean;
26
+ /**
27
+ * Sanitize input string
28
+ */
29
+ static sanitizeInput(input: string): string;
30
+ /**
31
+ * Validate bundle size
32
+ */
33
+ static validateBundleSize(size: number): boolean;
34
+ /**
35
+ * Calculate SHA-256 checksum of data
36
+ */
37
+ calculateChecksum(data: ArrayBuffer): Promise<string>;
38
+ /**
39
+ * Verify checksum matches expected value.
40
+ * Fails closed when a checksum is required but missing. Only a configuration
41
+ * that explicitly disables signature+HTTPS enforcement AND omits the
42
+ * checksum will skip verification — OTA code paths must always pass one.
43
+ */
44
+ verifyChecksum(data: ArrayBuffer, expectedChecksum: string): Promise<boolean>;
45
+ /**
46
+ * Alias for verifyChecksum for backward compatibility
47
+ */
48
+ validateChecksum(data: ArrayBuffer, expectedChecksum: string): Promise<boolean>;
49
+ /**
50
+ * Verify digital signature using Web Crypto API.
51
+ *
52
+ * Fails closed: if signature verification is enabled (the default), any of
53
+ * `publicKey`, `enableSignatureValidation`, or `requireSignature` being set
54
+ * makes a signature mandatory. A missing signature in that state throws —
55
+ * never silently returns true. Silent-pass was a P0 gap in prior releases.
56
+ */
57
+ verifySignature(data: ArrayBuffer, signature: string | null | undefined): Promise<boolean>;
58
+ /**
59
+ * Convert PEM to ArrayBuffer
60
+ */
61
+ private pemToArrayBuffer;
62
+ /**
63
+ * Convert base64 to ArrayBuffer
64
+ */
65
+ private base64ToArrayBuffer;
66
+ /**
67
+ * Sanitize file path to prevent directory traversal
68
+ */
69
+ sanitizePath(path: string): string;
70
+ /**
71
+ * Validate bundle ID format
72
+ */
73
+ validateBundleId(bundleId: string): void;
74
+ /**
75
+ * Validate semantic version format
76
+ */
77
+ validateVersion(version: string): void;
78
+ /**
79
+ * Check if version is a downgrade
80
+ */
81
+ isVersionDowngrade(currentVersion: string, newVersion: string): boolean;
82
+ /**
83
+ * Parse semantic version
84
+ */
85
+ private parseVersion;
86
+ /**
87
+ * Validate URL format and security
88
+ */
89
+ validateUrl(url: string): void;
90
+ /**
91
+ * Validate file size
92
+ */
93
+ validateFileSize(size: number): void;
94
+ /**
95
+ * Generate a secure random ID
96
+ */
97
+ generateSecureId(): string;
98
+ /**
99
+ * Validate certificate pinning for HTTPS connections
100
+ *
101
+ * Web Implementation Note:
102
+ * Certificate pinning at the TLS level is NOT possible in web browsers for security reasons.
103
+ * However, this implementation provides signature verification which serves a similar purpose:
104
+ * - Validates server identity through cryptographic signatures
105
+ * - Prevents MITM attacks via signature validation
106
+ * - Uses SHA-256 certificate fingerprints for validation
107
+ *
108
+ * For native platforms (iOS/Android), full TLS certificate pinning is implemented
109
+ * in the native layers using platform-specific APIs (URLSessionDelegate, OkHttp).
110
+ *
111
+ * This web implementation is production-ready and provides equivalent security
112
+ * through the signature verification system.
113
+ */
114
+ validateCertificatePin(hostname: string, certificate: string): Promise<boolean>;
115
+ /**
116
+ * Calculate SHA-256 hash of certificate
117
+ */
118
+ private calculateCertificateHash;
119
+ /**
120
+ * Validate metadata object
121
+ */
122
+ validateMetadata(metadata: unknown): void;
123
+ }