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,88 @@
1
+ /**
2
+ * Cryptographic utilities for bundle verification and encryption
3
+ */
4
+ /**
5
+ * Configuration for bundle encryption
6
+ */
7
+ export interface EncryptionConfig {
8
+ algorithm: 'AES-GCM';
9
+ keyLength: 128 | 192 | 256;
10
+ ivLength: number;
11
+ tagLength: number;
12
+ }
13
+ /**
14
+ * Encrypted bundle structure
15
+ */
16
+ export interface EncryptedBundle {
17
+ iv: string;
18
+ data: string;
19
+ tag?: string;
20
+ algorithm: string;
21
+ keyId?: string;
22
+ }
23
+ export declare class CryptoUtils {
24
+ /**
25
+ * Calculate SHA-256 checksum of data
26
+ */
27
+ static calculateChecksum(data: ArrayBuffer | string): Promise<string>;
28
+ /**
29
+ * Verify signature using public key
30
+ */
31
+ static verifySignature(data: ArrayBuffer | string, signature: string, publicKey: string): Promise<boolean>;
32
+ /**
33
+ * Convert base64 string to ArrayBuffer
34
+ */
35
+ private static base64ToArrayBuffer;
36
+ /**
37
+ * Generate a random nonce
38
+ */
39
+ static generateNonce(length?: number): string;
40
+ /**
41
+ * Validate checksum format
42
+ */
43
+ static isValidChecksum(checksum: string, algorithm?: 'SHA-256' | 'SHA-512'): boolean;
44
+ /**
45
+ * Derive an encryption key from a password/secret
46
+ * Uses PBKDF2 for secure key derivation
47
+ */
48
+ static deriveKey(password: string, salt: ArrayBuffer, keyLength?: 128 | 192 | 256): Promise<CryptoKey>;
49
+ /**
50
+ * Import a raw encryption key
51
+ */
52
+ static importKey(keyData: ArrayBuffer | string, keyLength?: 128 | 192 | 256): Promise<CryptoKey>;
53
+ /**
54
+ * Encrypt data using AES-256-GCM
55
+ */
56
+ static encrypt(data: ArrayBuffer | Uint8Array, key: CryptoKey, config?: Partial<EncryptionConfig>): Promise<EncryptedBundle>;
57
+ /**
58
+ * Decrypt data using AES-256-GCM
59
+ */
60
+ static decrypt(encryptedBundle: EncryptedBundle, key: CryptoKey, config?: Partial<EncryptionConfig>): Promise<ArrayBuffer>;
61
+ /**
62
+ * Encrypt a bundle file (convenience method for typical use case)
63
+ */
64
+ static encryptBundle(bundleData: ArrayBuffer, encryptionKey: string, salt?: ArrayBuffer): Promise<{
65
+ encrypted: EncryptedBundle;
66
+ salt: string;
67
+ }>;
68
+ /**
69
+ * Decrypt a bundle file (convenience method for typical use case)
70
+ */
71
+ static decryptBundle(encryptedBundle: EncryptedBundle, encryptionKey: string, salt: string): Promise<ArrayBuffer>;
72
+ /**
73
+ * Check if a bundle is encrypted
74
+ */
75
+ static isEncryptedBundle(data: unknown): data is EncryptedBundle;
76
+ /**
77
+ * Generate a random encryption key
78
+ */
79
+ static generateEncryptionKey(length?: 128 | 192 | 256): string;
80
+ /**
81
+ * Generate a random salt
82
+ */
83
+ static generateSalt(length?: number): string;
84
+ /**
85
+ * Convert ArrayBuffer to base64 string
86
+ */
87
+ static arrayBufferToBase64(buffer: ArrayBuffer): string;
88
+ }
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Cryptographic utilities for bundle verification and encryption
3
+ */
4
+ /**
5
+ * Default encryption configuration
6
+ */
7
+ const DEFAULT_ENCRYPTION_CONFIG = {
8
+ algorithm: 'AES-GCM',
9
+ keyLength: 256,
10
+ ivLength: 12, // Recommended for GCM
11
+ tagLength: 128, // 128-bit authentication tag
12
+ };
13
+ export class CryptoUtils {
14
+ /**
15
+ * Calculate SHA-256 checksum of data
16
+ */
17
+ static async calculateChecksum(data) {
18
+ const encoder = new TextEncoder();
19
+ const dataBuffer = typeof data === 'string' ? encoder.encode(data) : data;
20
+ const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);
21
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
22
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
23
+ }
24
+ /**
25
+ * Verify signature using public key
26
+ */
27
+ static async verifySignature(data, signature, publicKey) {
28
+ try {
29
+ // Accept either PEM (`-----BEGIN PUBLIC KEY-----...`) or raw base64
30
+ // SPKI. Two callers existed historically and they passed different
31
+ // formats; standardize on PEM-aware parsing here so both work.
32
+ const pemBody = publicKey
33
+ .replace(/-----BEGIN PUBLIC KEY-----/g, '')
34
+ .replace(/-----END PUBLIC KEY-----/g, '')
35
+ .replace(/\s+/g, '');
36
+ const signatureBuffer = this.base64ToArrayBuffer(signature);
37
+ const publicKeyBuffer = this.base64ToArrayBuffer(pemBody);
38
+ const key = await crypto.subtle.importKey('spki', publicKeyBuffer, {
39
+ name: 'RSASSA-PKCS1-v1_5',
40
+ hash: 'SHA-256',
41
+ }, false, ['verify']);
42
+ const encoder = new TextEncoder();
43
+ const dataBuffer = typeof data === 'string' ? encoder.encode(data) : data;
44
+ return await crypto.subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, key, signatureBuffer, dataBuffer);
45
+ }
46
+ catch (error) {
47
+ // Verification failure must NOT throw — we want a clean false so
48
+ // upstream code can refuse the bundle without crashing.
49
+ void error;
50
+ return false;
51
+ }
52
+ }
53
+ /**
54
+ * Convert base64 string to ArrayBuffer
55
+ */
56
+ static base64ToArrayBuffer(base64) {
57
+ const binaryString = atob(base64);
58
+ const bytes = new Uint8Array(binaryString.length);
59
+ for (let i = 0; i < binaryString.length; i++) {
60
+ bytes[i] = binaryString.charCodeAt(i);
61
+ }
62
+ return bytes.buffer;
63
+ }
64
+ /**
65
+ * Generate a random nonce
66
+ */
67
+ static generateNonce(length = 16) {
68
+ const array = new Uint8Array(length);
69
+ crypto.getRandomValues(array);
70
+ return Array.from(array, (byte) => byte.toString(16).padStart(2, '0')).join('');
71
+ }
72
+ /**
73
+ * Validate checksum format
74
+ */
75
+ static isValidChecksum(checksum, algorithm = 'SHA-256') {
76
+ const expectedLength = algorithm === 'SHA-256' ? 64 : 128;
77
+ const hexPattern = /^[a-f0-9]+$/i;
78
+ return checksum.length === expectedLength && hexPattern.test(checksum);
79
+ }
80
+ // ============================================
81
+ // AES-256-GCM Encryption/Decryption
82
+ // ============================================
83
+ /**
84
+ * Derive an encryption key from a password/secret
85
+ * Uses PBKDF2 for secure key derivation
86
+ */
87
+ static async deriveKey(password, salt, keyLength = 256) {
88
+ const encoder = new TextEncoder();
89
+ const passwordBuffer = encoder.encode(password);
90
+ // Import password as raw key material
91
+ const passwordKey = await crypto.subtle.importKey('raw', passwordBuffer, 'PBKDF2', false, ['deriveKey']);
92
+ // Derive AES key using PBKDF2
93
+ return crypto.subtle.deriveKey({
94
+ name: 'PBKDF2',
95
+ salt,
96
+ iterations: 100000, // High iteration count for security
97
+ hash: 'SHA-256',
98
+ }, passwordKey, {
99
+ name: 'AES-GCM',
100
+ length: keyLength,
101
+ }, false, // Not extractable
102
+ ['encrypt', 'decrypt']);
103
+ }
104
+ /**
105
+ * Import a raw encryption key
106
+ */
107
+ static async importKey(keyData, keyLength = 256) {
108
+ const keyBuffer = typeof keyData === 'string'
109
+ ? this.base64ToArrayBuffer(keyData)
110
+ : keyData;
111
+ return crypto.subtle.importKey('raw', keyBuffer, {
112
+ name: 'AES-GCM',
113
+ length: keyLength,
114
+ }, false, ['encrypt', 'decrypt']);
115
+ }
116
+ /**
117
+ * Encrypt data using AES-256-GCM
118
+ */
119
+ static async encrypt(data, key, config = {}) {
120
+ const finalConfig = Object.assign(Object.assign({}, DEFAULT_ENCRYPTION_CONFIG), config);
121
+ // Generate random IV
122
+ const iv = crypto.getRandomValues(new Uint8Array(finalConfig.ivLength));
123
+ // Convert to Uint8Array view for consistent handling
124
+ let dataArray;
125
+ if (data instanceof Uint8Array) {
126
+ dataArray = data;
127
+ }
128
+ else {
129
+ dataArray = new Uint8Array(data);
130
+ }
131
+ // Encrypt the data (cast to BufferSource to satisfy TypeScript)
132
+ const ciphertext = await crypto.subtle.encrypt({
133
+ name: 'AES-GCM',
134
+ iv,
135
+ tagLength: finalConfig.tagLength,
136
+ }, key, dataArray);
137
+ // Convert IV buffer to proper ArrayBuffer
138
+ const ivArray = new Uint8Array(iv);
139
+ const ivBuffer = new ArrayBuffer(ivArray.length);
140
+ new Uint8Array(ivBuffer).set(ivArray);
141
+ return {
142
+ iv: this.arrayBufferToBase64(ivBuffer),
143
+ data: this.arrayBufferToBase64(ciphertext),
144
+ algorithm: `AES-${finalConfig.keyLength}-GCM`,
145
+ };
146
+ }
147
+ /**
148
+ * Decrypt data using AES-256-GCM
149
+ */
150
+ static async decrypt(encryptedBundle, key, config = {}) {
151
+ const finalConfig = Object.assign(Object.assign({}, DEFAULT_ENCRYPTION_CONFIG), config);
152
+ // Decode IV and ciphertext
153
+ const iv = new Uint8Array(this.base64ToArrayBuffer(encryptedBundle.iv));
154
+ const ciphertext = this.base64ToArrayBuffer(encryptedBundle.data);
155
+ // Decrypt the data
156
+ return crypto.subtle.decrypt({
157
+ name: 'AES-GCM',
158
+ iv,
159
+ tagLength: finalConfig.tagLength,
160
+ }, key, ciphertext);
161
+ }
162
+ /**
163
+ * Encrypt a bundle file (convenience method for typical use case)
164
+ */
165
+ static async encryptBundle(bundleData, encryptionKey, salt) {
166
+ // Generate salt if not provided
167
+ const saltArray = salt ? new Uint8Array(salt) : crypto.getRandomValues(new Uint8Array(16));
168
+ const actualSalt = saltArray.buffer.slice(saltArray.byteOffset, saltArray.byteOffset + saltArray.byteLength);
169
+ // Derive key from password
170
+ const key = await this.deriveKey(encryptionKey, actualSalt);
171
+ // Encrypt the bundle
172
+ const encrypted = await this.encrypt(bundleData, key);
173
+ return {
174
+ encrypted,
175
+ salt: this.arrayBufferToBase64(actualSalt),
176
+ };
177
+ }
178
+ /**
179
+ * Decrypt a bundle file (convenience method for typical use case)
180
+ */
181
+ static async decryptBundle(encryptedBundle, encryptionKey, salt) {
182
+ // Decode salt
183
+ const saltBuffer = this.base64ToArrayBuffer(salt);
184
+ // Derive key from password
185
+ const key = await this.deriveKey(encryptionKey, saltBuffer);
186
+ // Decrypt the bundle
187
+ return this.decrypt(encryptedBundle, key);
188
+ }
189
+ /**
190
+ * Check if a bundle is encrypted
191
+ */
192
+ static isEncryptedBundle(data) {
193
+ return (typeof data === 'object' &&
194
+ data !== null &&
195
+ 'iv' in data &&
196
+ 'data' in data &&
197
+ 'algorithm' in data &&
198
+ typeof data.iv === 'string' &&
199
+ typeof data.data === 'string' &&
200
+ typeof data.algorithm === 'string');
201
+ }
202
+ /**
203
+ * Generate a random encryption key
204
+ */
205
+ static generateEncryptionKey(length = 256) {
206
+ const keyBytes = length / 8;
207
+ const key = crypto.getRandomValues(new Uint8Array(keyBytes));
208
+ return this.arrayBufferToBase64(key.buffer);
209
+ }
210
+ /**
211
+ * Generate a random salt
212
+ */
213
+ static generateSalt(length = 16) {
214
+ const salt = crypto.getRandomValues(new Uint8Array(length));
215
+ return this.arrayBufferToBase64(salt.buffer);
216
+ }
217
+ /**
218
+ * Convert ArrayBuffer to base64 string
219
+ */
220
+ static arrayBufferToBase64(buffer) {
221
+ const bytes = new Uint8Array(buffer);
222
+ let binary = '';
223
+ for (let i = 0; i < bytes.length; i++) {
224
+ binary += String.fromCharCode(bytes[i]);
225
+ }
226
+ return btoa(binary);
227
+ }
228
+ }
@@ -0,0 +1,60 @@
1
+ import type { LiveUpdateConfig } from '../definitions';
2
+ /**
3
+ * Input validation utilities
4
+ */
5
+ export declare class Validator {
6
+ /**
7
+ * Validate URL
8
+ */
9
+ static validateUrl(url: string, enforceHttps?: boolean): {
10
+ valid: boolean;
11
+ error?: string;
12
+ };
13
+ /**
14
+ * Validate version string
15
+ */
16
+ static validateVersion(version: string): {
17
+ valid: boolean;
18
+ error?: string;
19
+ };
20
+ /**
21
+ * Compare versions
22
+ */
23
+ static compareVersions(version1: string, version2: string): number;
24
+ /**
25
+ * Validate bundle ID
26
+ */
27
+ static validateBundleId(bundleId: string): {
28
+ valid: boolean;
29
+ error?: string;
30
+ };
31
+ /**
32
+ * Validate file size
33
+ */
34
+ static validateFileSize(size: number, maxSize: number): {
35
+ valid: boolean;
36
+ error?: string;
37
+ };
38
+ /**
39
+ * Validate configuration
40
+ */
41
+ static validateLiveUpdateConfig(config: LiveUpdateConfig): {
42
+ valid: boolean;
43
+ errors: string[];
44
+ };
45
+ /**
46
+ * Validate host
47
+ */
48
+ static isValidHost(host: string): boolean;
49
+ /**
50
+ * Sanitize input string
51
+ */
52
+ static sanitizeInput(input: string): string;
53
+ /**
54
+ * Validate path (prevent directory traversal)
55
+ */
56
+ static validatePath(path: string): {
57
+ valid: boolean;
58
+ error?: string;
59
+ };
60
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Input validation utilities
3
+ */
4
+ export class Validator {
5
+ /**
6
+ * Validate URL
7
+ */
8
+ static validateUrl(url, enforceHttps = true) {
9
+ try {
10
+ const parsed = new URL(url);
11
+ if (enforceHttps && parsed.protocol !== 'https:') {
12
+ return { valid: false, error: 'URL must use HTTPS protocol' };
13
+ }
14
+ return { valid: true };
15
+ }
16
+ catch (_a) {
17
+ return { valid: false, error: 'Invalid URL format' };
18
+ }
19
+ }
20
+ /**
21
+ * Validate version string
22
+ */
23
+ static validateVersion(version) {
24
+ // Semantic versioning pattern
25
+ const semverPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
26
+ if (!semverPattern.test(version)) {
27
+ return { valid: false, error: 'Invalid semantic version format' };
28
+ }
29
+ return { valid: true };
30
+ }
31
+ /**
32
+ * Compare versions
33
+ */
34
+ static compareVersions(version1, version2) {
35
+ const v1Parts = version1.split('.').map(Number);
36
+ const v2Parts = version2.split('.').map(Number);
37
+ for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
38
+ const v1 = v1Parts[i] || 0;
39
+ const v2 = v2Parts[i] || 0;
40
+ if (v1 > v2)
41
+ return 1;
42
+ if (v1 < v2)
43
+ return -1;
44
+ }
45
+ return 0;
46
+ }
47
+ /**
48
+ * Validate bundle ID
49
+ */
50
+ static validateBundleId(bundleId) {
51
+ const pattern = /^[a-zA-Z0-9._-]+$/;
52
+ if (!pattern.test(bundleId)) {
53
+ return { valid: false, error: 'Bundle ID contains invalid characters' };
54
+ }
55
+ if (bundleId.length > 255) {
56
+ return { valid: false, error: 'Bundle ID is too long' };
57
+ }
58
+ return { valid: true };
59
+ }
60
+ /**
61
+ * Validate file size
62
+ */
63
+ static validateFileSize(size, maxSize) {
64
+ if (size <= 0) {
65
+ return { valid: false, error: 'Invalid file size' };
66
+ }
67
+ if (size > maxSize) {
68
+ const maxSizeMB = Math.round(maxSize / (1024 * 1024));
69
+ return {
70
+ valid: false,
71
+ error: `File size exceeds maximum allowed size of ${maxSizeMB}MB`,
72
+ };
73
+ }
74
+ return { valid: true };
75
+ }
76
+ /**
77
+ * Validate configuration
78
+ */
79
+ static validateLiveUpdateConfig(config) {
80
+ const errors = [];
81
+ // Required fields
82
+ if (!config.appId) {
83
+ errors.push('App ID is required');
84
+ }
85
+ if (!config.serverUrl) {
86
+ errors.push('Server URL is required');
87
+ }
88
+ else {
89
+ const urlValidation = this.validateUrl(config.serverUrl);
90
+ if (!urlValidation.valid) {
91
+ errors.push(urlValidation.error);
92
+ }
93
+ }
94
+ // Optional fields validation
95
+ if (config.maxBundleSize && config.maxBundleSize <= 0) {
96
+ errors.push('Max bundle size must be positive');
97
+ }
98
+ if (config.checkInterval && config.checkInterval < 60000) {
99
+ errors.push('Check interval must be at least 60 seconds');
100
+ }
101
+ if (config.allowedHosts) {
102
+ for (const host of config.allowedHosts) {
103
+ if (!this.isValidHost(host)) {
104
+ errors.push(`Invalid host: ${host}`);
105
+ }
106
+ }
107
+ }
108
+ return {
109
+ valid: errors.length === 0,
110
+ errors,
111
+ };
112
+ }
113
+ /**
114
+ * Validate host
115
+ */
116
+ static isValidHost(host) {
117
+ // Basic hostname validation
118
+ const hostPattern = /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;
119
+ return hostPattern.test(host);
120
+ }
121
+ /**
122
+ * Sanitize input string
123
+ */
124
+ static sanitizeInput(input) {
125
+ // Remove potentially dangerous characters
126
+ return input.replace(/[^\w\s.-]/gi, '');
127
+ }
128
+ /**
129
+ * Validate path (prevent directory traversal)
130
+ */
131
+ static validatePath(path) {
132
+ if (path.includes('..') || path.includes('//')) {
133
+ return { valid: false, error: 'Path contains invalid sequences' };
134
+ }
135
+ // Check for absolute paths on web
136
+ if (typeof window !== 'undefined' &&
137
+ (path.startsWith('/') || path.includes(':'))) {
138
+ return { valid: false, error: 'Absolute paths are not allowed' };
139
+ }
140
+ return { valid: true };
141
+ }
142
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The app's client identity, used for API-key client restrictions
3
+ * (dashboard → API Keys → Restrictions). It answers "which app/site is this?"
4
+ * so the backend can enforce a per-key allowlist of clients.
5
+ *
6
+ * - **android**: `packageName` (applicationId) + signing-cert `certSha256` /
7
+ * `certSha1` (lowercase hex, no colons).
8
+ * - **ios**: `bundleId` (`teamId` reserved; currently unset).
9
+ * - **web**: `{ platform: 'web' }` — browsers identify via the Origin header
10
+ * (browser-enforced), so no fields are needed.
11
+ *
12
+ * A consuming app that performs its OWN update-check fetch should call
13
+ * `NativeUpdate.getAppIdentity()` and attach the matching headers
14
+ * (`X-Android-Package`, `X-Android-Cert-Sha256`, `X-Android-Cert-Sha1`,
15
+ * `X-Ios-Bundle-Id`). The plugin's own native update-check path attaches them
16
+ * automatically.
17
+ *
18
+ * Honest note: the native identity headers are CLIENT-ATTESTED (parity with
19
+ * Google Maps API-key app restrictions) — they stop casual key reuse and quota
20
+ * abuse, not a determined attacker replaying headers by hand. Only the web
21
+ * Origin check is browser-enforced.
22
+ */
23
+ export interface AppIdentity {
24
+ /** The platform this identity was computed on. */
25
+ platform: 'web' | 'android' | 'ios';
26
+ /** Android applicationId (e.g. `com.acme.app`). */
27
+ packageName?: string;
28
+ /** Android signing certificate SHA-256, lowercase hex, no separators. */
29
+ certSha256?: string;
30
+ /** Android signing certificate SHA-1, lowercase hex, no separators. */
31
+ certSha1?: string;
32
+ /** iOS bundle identifier (e.g. `com.acme.app`). */
33
+ bundleId?: string;
34
+ /** iOS team id — reserved; the plugin does not currently populate it. */
35
+ teamId?: string;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Rollout + update-check types.
3
+ *
4
+ * These types describe staged-rollout configuration and the response
5
+ * shape the Laravel backend returns from `GET /v1/updates/check`.
6
+ * They were previously co-located with the Firestore schema; v3 of the
7
+ * plugin dropped Firestore as a backend, so the types live here in a
8
+ * backend-neutral location.
9
+ */
10
+ /**
11
+ * A point in time in a rollout config. Accepts ISO-8601 strings (what
12
+ * the Laravel backend returns), epoch milliseconds, or a `Date` for
13
+ * convenience when constructing config in code.
14
+ */
15
+ export type RolloutTimestamp = number | string | Date;
16
+ /**
17
+ * Convert a `RolloutTimestamp` to epoch milliseconds. Throws on a
18
+ * value that doesn't parse — callers are expected to validate before
19
+ * persisting rollout config.
20
+ */
21
+ export declare function toEpochMs(value: RolloutTimestamp): number;
22
+ /**
23
+ * Staged rollout configuration returned by the backend on update checks.
24
+ */
25
+ export interface RolloutConfig {
26
+ enabled: boolean;
27
+ percentage: number;
28
+ startTime: RolloutTimestamp;
29
+ endTime: RolloutTimestamp | null;
30
+ targetSegments?: RolloutTargetSegments;
31
+ schedule?: RolloutSchedule;
32
+ }
33
+ export interface RolloutTargetSegments {
34
+ platforms?: ('ios' | 'android' | 'web')[];
35
+ minAppVersion?: string;
36
+ maxAppVersion?: string;
37
+ deviceIds?: string[];
38
+ regions?: string[];
39
+ }
40
+ export interface RolloutSchedule {
41
+ type: 'immediate' | 'gradual' | 'scheduled';
42
+ gradualSteps?: number[];
43
+ gradualInterval?: number;
44
+ scheduledTime?: RolloutTimestamp;
45
+ }
46
+ /**
47
+ * Device information used for rollout eligibility checks. Sent to the
48
+ * backend on `/v1/updates/check` via `X-Device-ID`, `X-Platform`,
49
+ * `X-App-Version` headers and used locally by `RolloutChecker` for
50
+ * deterministic percentile bucketing.
51
+ */
52
+ export interface DeviceInfo {
53
+ deviceId: string;
54
+ platform: 'ios' | 'android' | 'web';
55
+ appVersion: string;
56
+ bundleVersion: string;
57
+ osVersion: string;
58
+ region?: string;
59
+ locale: string;
60
+ }
61
+ /**
62
+ * Extended, delta-aware LOCAL model of an update check, used by the
63
+ * delta-update pipeline (`delta-processor.ts`).
64
+ *
65
+ * NOTE: this is NOT the raw wire shape. The backend `GET /v1/updates/check`
66
+ * returns `available` / `downloadUrl` / `releaseNotes` (see
67
+ * {@link BackendUpdateCheckResponse} in `core/update-check.ts`), whereas
68
+ * this interface uses `updateAvailable` / `bundleUrl` and adds the
69
+ * client-computed `delta` / `rolloutEligible` fields. Map from the wire
70
+ * response into this shape when driving a delta update.
71
+ */
72
+ export interface UpdateCheckResponse {
73
+ updateAvailable: boolean;
74
+ version?: string;
75
+ bundleUrl?: string;
76
+ minNativeVersion?: string;
77
+ releaseNotes?: string;
78
+ signature?: string;
79
+ checksum?: string;
80
+ mandatory?: boolean;
81
+ size?: number;
82
+ delta?: {
83
+ available: boolean;
84
+ patchUrl?: string;
85
+ patchSize?: number;
86
+ patchChecksum?: string;
87
+ targetChecksum?: string;
88
+ };
89
+ rolloutEligible?: boolean;
90
+ rolloutReason?: string;
91
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Rollout + update-check types.
3
+ *
4
+ * These types describe staged-rollout configuration and the response
5
+ * shape the Laravel backend returns from `GET /v1/updates/check`.
6
+ * They were previously co-located with the Firestore schema; v3 of the
7
+ * plugin dropped Firestore as a backend, so the types live here in a
8
+ * backend-neutral location.
9
+ */
10
+ /**
11
+ * Convert a `RolloutTimestamp` to epoch milliseconds. Throws on a
12
+ * value that doesn't parse — callers are expected to validate before
13
+ * persisting rollout config.
14
+ */
15
+ export function toEpochMs(value) {
16
+ if (typeof value === 'number')
17
+ return value;
18
+ if (value instanceof Date)
19
+ return value.getTime();
20
+ const parsed = new Date(value).getTime();
21
+ if (Number.isNaN(parsed)) {
22
+ throw new Error(`Invalid rollout timestamp: ${String(value)}`);
23
+ }
24
+ return parsed;
25
+ }