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.
Files changed (140) 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/flutter-patch.js +107 -0
  30. package/cli/commands/init.js +146 -0
  31. package/cli/commands/keys-generate.js +58 -0
  32. package/cli/commands/monitor.js +89 -0
  33. package/cli/commands/remote-shared.js +264 -0
  34. package/cli/commands/remote.js +634 -0
  35. package/cli/commands/server-start.js +96 -0
  36. package/cli/index.js +625 -0
  37. package/cli/package.json +21 -0
  38. package/dist/esm/app-review/app-review-manager.d.ts +24 -0
  39. package/dist/esm/app-review/app-review-manager.js +194 -0
  40. package/dist/esm/app-review/index.d.ts +5 -0
  41. package/dist/esm/app-review/index.js +5 -0
  42. package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
  43. package/dist/esm/app-review/platform-review-handler.js +137 -0
  44. package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
  45. package/dist/esm/app-review/review-conditions-checker.js +154 -0
  46. package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
  47. package/dist/esm/app-review/review-rate-limiter.js +163 -0
  48. package/dist/esm/app-review/types.d.ts +41 -0
  49. package/dist/esm/app-review/types.js +1 -0
  50. package/dist/esm/app-update/app-update-checker.d.ts +58 -0
  51. package/dist/esm/app-update/app-update-checker.js +227 -0
  52. package/dist/esm/app-update/app-update-installer.d.ts +20 -0
  53. package/dist/esm/app-update/app-update-installer.js +134 -0
  54. package/dist/esm/app-update/app-update-manager.d.ts +28 -0
  55. package/dist/esm/app-update/app-update-manager.js +198 -0
  56. package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
  57. package/dist/esm/app-update/app-update-notifier.js +99 -0
  58. package/dist/esm/app-update/index.d.ts +6 -0
  59. package/dist/esm/app-update/index.js +6 -0
  60. package/dist/esm/app-update/platform-app-update.d.ts +19 -0
  61. package/dist/esm/app-update/platform-app-update.js +138 -0
  62. package/dist/esm/app-update/types.d.ts +58 -0
  63. package/dist/esm/app-update/types.js +11 -0
  64. package/dist/esm/background-update/background-scheduler.d.ts +63 -0
  65. package/dist/esm/background-update/background-scheduler.js +332 -0
  66. package/dist/esm/background-update/index.d.ts +3 -0
  67. package/dist/esm/background-update/index.js +2 -0
  68. package/dist/esm/background-update/notification-manager.d.ts +29 -0
  69. package/dist/esm/background-update/notification-manager.js +88 -0
  70. package/dist/esm/config/support.d.ts +9 -0
  71. package/dist/esm/config/support.js +9 -0
  72. package/dist/esm/core/analytics.d.ts +83 -0
  73. package/dist/esm/core/analytics.js +151 -0
  74. package/dist/esm/core/cache-manager.d.ts +72 -0
  75. package/dist/esm/core/cache-manager.js +274 -0
  76. package/dist/esm/core/config.d.ts +69 -0
  77. package/dist/esm/core/config.js +107 -0
  78. package/dist/esm/core/errors.d.ts +56 -0
  79. package/dist/esm/core/errors.js +85 -0
  80. package/dist/esm/core/event-emitter.d.ts +30 -0
  81. package/dist/esm/core/event-emitter.js +80 -0
  82. package/dist/esm/core/logger.d.ts +21 -0
  83. package/dist/esm/core/logger.js +108 -0
  84. package/dist/esm/core/performance.d.ts +53 -0
  85. package/dist/esm/core/performance.js +153 -0
  86. package/dist/esm/core/plugin-manager.d.ts +88 -0
  87. package/dist/esm/core/plugin-manager.js +224 -0
  88. package/dist/esm/core/security.d.ts +123 -0
  89. package/dist/esm/core/security.js +361 -0
  90. package/dist/esm/core/update-check.d.ts +121 -0
  91. package/dist/esm/core/update-check.js +127 -0
  92. package/dist/esm/definitions.d.ts +872 -0
  93. package/dist/esm/definitions.js +104 -0
  94. package/dist/esm/index.d.ts +14 -0
  95. package/dist/esm/index.js +18 -0
  96. package/dist/esm/live-update/bundle-manager.d.ts +102 -0
  97. package/dist/esm/live-update/bundle-manager.js +344 -0
  98. package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
  99. package/dist/esm/live-update/certificate-pinning.js +77 -0
  100. package/dist/esm/live-update/delta-processor.d.ts +84 -0
  101. package/dist/esm/live-update/delta-processor.js +257 -0
  102. package/dist/esm/live-update/download-manager.d.ts +106 -0
  103. package/dist/esm/live-update/download-manager.js +412 -0
  104. package/dist/esm/live-update/rollout-checker.d.ts +86 -0
  105. package/dist/esm/live-update/rollout-checker.js +304 -0
  106. package/dist/esm/live-update/update-manager.d.ts +63 -0
  107. package/dist/esm/live-update/update-manager.js +321 -0
  108. package/dist/esm/live-update/version-manager.d.ts +93 -0
  109. package/dist/esm/live-update/version-manager.js +390 -0
  110. package/dist/esm/plugin.d.ts +3 -0
  111. package/dist/esm/plugin.js +848 -0
  112. package/dist/esm/security/crypto.d.ts +88 -0
  113. package/dist/esm/security/crypto.js +228 -0
  114. package/dist/esm/security/validator.d.ts +60 -0
  115. package/dist/esm/security/validator.js +142 -0
  116. package/dist/esm/types/app-identity.d.ts +36 -0
  117. package/dist/esm/types/app-identity.js +1 -0
  118. package/dist/esm/types/rollout.d.ts +91 -0
  119. package/dist/esm/types/rollout.js +25 -0
  120. package/dist/esm/web.d.ts +130 -0
  121. package/dist/esm/web.js +981 -0
  122. package/dist/plugin.cjs +1 -0
  123. package/dist/plugin.esm.js +1 -0
  124. package/dist/plugin.js +2 -0
  125. package/docs/CHANGELOG.md +1016 -0
  126. package/docs/KNOWN_LIMITATIONS.md +240 -0
  127. package/docs/MIGRATION.md +391 -0
  128. package/docs/protocol/CLIENT-PROTOCOL.md +199 -0
  129. package/docs/server-requirements.md +211 -0
  130. package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
  131. package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
  132. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
  133. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
  134. package/ios/Plugin/Info.plist +43 -0
  135. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
  136. package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
  137. package/ios/Plugin/NativeUpdatePlugin.m +53 -0
  138. package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
  139. package/ios/Plugin/Security/SecurityManager.swift +289 -0
  140. package/package.json +133 -4
@@ -0,0 +1,578 @@
1
+ # AI Integration Guide - Native Update
2
+
3
+ Quick reference for AI development agents (Claude Code, Cursor, Copilot, etc.) to integrate native-update into Capacitor projects.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ yarn add native-update
9
+ ```
10
+
11
+ ## Core Concepts
12
+
13
+ Native Update provides three main features:
14
+ 1. **Live Updates (OTA)** - Deploy JS/HTML/CSS updates without app store approval
15
+ 2. **App Updates** - Native app store update management (Google Play, App Store)
16
+ 3. **App Reviews** - In-app review prompts
17
+
18
+ ## Quick Start
19
+
20
+ ### Basic Setup
21
+
22
+ ```typescript
23
+ import { NativeUpdate } from 'native-update';
24
+
25
+ // Configure the plugin (nested UpdateConfig — one section per feature)
26
+ await NativeUpdate.configure({
27
+ liveUpdate: {
28
+ appId: 'com.your.app',
29
+ // Canonical rule: serverUrl is the backend base; the plugin appends
30
+ // /v1/updates/check. Hosted backend: https://nativeupdatebe.aoneahsan.com/api
31
+ serverUrl: 'https://nativeupdatebe.aoneahsan.com/api',
32
+ // Sent as X-API-Key on every check. Mint/copy in the dashboard
33
+ // (Apps → your app → API Keys). Supported here since v3.1.3.
34
+ apiKey: 'nu_app_…',
35
+ publicKey: import.meta.env.VITE_NATIVE_UPDATE_PUBLIC_KEY,
36
+ requireSignature: true,
37
+ channel: 'production', // e.g. 'development' | 'staging' | 'production'
38
+ autoUpdate: true,
39
+ updateStrategy: 'background', // 'immediate' | 'background' | 'manual'
40
+ },
41
+ });
42
+ ```
43
+
44
+ ### Live Updates (OTA)
45
+
46
+ ```typescript
47
+ import { NativeUpdate } from 'native-update';
48
+
49
+ // Check and apply updates — sync() reports a status enum
50
+ const result = await NativeUpdate.sync();
51
+ if (result.status === 'UPDATE_INSTALLED') {
52
+ // sync() already downloaded + staged the bundle
53
+ await NativeUpdate.reload();
54
+ }
55
+
56
+ // Manual update flow
57
+ const latest = await NativeUpdate.checkForUpdate();
58
+ if (latest.available) {
59
+ // Fetches the complete signed manifest and uses a compatible NUDELTA/1
60
+ // patch when available, with verified full-bundle fallback.
61
+ await NativeUpdate.downloadUpdate();
62
+ await NativeUpdate.applyUpdate();
63
+ }
64
+
65
+ // Notify app is stable after update (prevents auto-rollback)
66
+ await NativeUpdate.notifyAppReady();
67
+ ```
68
+
69
+ ### App Store Updates
70
+
71
+ ```typescript
72
+ import { NativeUpdate } from 'native-update';
73
+
74
+ // Check for app store updates
75
+ const updateInfo = await NativeUpdate.getAppUpdateInfo();
76
+ if (updateInfo.updateAvailable) {
77
+ if ((updateInfo.updatePriority ?? 0) >= 4) {
78
+ // Critical update - force immediate
79
+ await NativeUpdate.performImmediateUpdate();
80
+ } else {
81
+ // Flexible update - download in background
82
+ await NativeUpdate.startFlexibleUpdate();
83
+ // Later, when ready to install
84
+ await NativeUpdate.completeFlexibleUpdate();
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### App Reviews
90
+
91
+ ```typescript
92
+ import { NativeUpdate } from 'native-update';
93
+
94
+ // Request review at appropriate moment
95
+ const eligibility = await NativeUpdate.canRequestReview();
96
+ if (eligibility.canRequest) {
97
+ const result = await NativeUpdate.requestReview();
98
+ // result.displayed — note: actual review submission not guaranteed (platform controls)
99
+ }
100
+ ```
101
+
102
+ ## API Reference
103
+
104
+ ### Live Update Methods
105
+
106
+ | Method | Description | Returns |
107
+ |--------|-------------|---------|
108
+ | `sync(options?)` | Check and apply updates | `Promise<SyncResult>` |
109
+ | `download(options)` | Download specific version | `Promise<BundleInfo>` |
110
+ | `set(bundle)` | Set active bundle | `Promise<void>` |
111
+ | `reload()` | Reload app with current bundle | `Promise<void>` |
112
+ | `reset()` | Reset to original bundle | `Promise<void>` |
113
+ | `current()` | Get current bundle info | `Promise<BundleInfo>` |
114
+ | `list()` | List all downloaded bundles | `Promise<BundleInfo[]>` |
115
+ | `delete(options)` | Delete bundles | `Promise<void>` |
116
+ | `notifyAppReady()` | Mark update as stable | `Promise<void>` |
117
+ | `getLatest()` | Check for latest version | `Promise<LatestVersion>` |
118
+ | `setChannel(channel)` | Switch update channel | `Promise<void>` |
119
+ | `setUpdateUrl(url)` | Deprecated no-op; use reset + reinitialize | `Promise<void>` |
120
+
121
+ ### App Update Methods
122
+
123
+ | Method | Description | Returns |
124
+ |--------|-------------|---------|
125
+ | `getAppUpdateInfo()` | Get app store update info | `Promise<AppUpdateInfo>` |
126
+ | `performImmediateUpdate()` | Force immediate update | `Promise<void>` |
127
+ | `startFlexibleUpdate()` | Start background download | `Promise<void>` |
128
+ | `completeFlexibleUpdate()` | Install downloaded update | `Promise<void>` |
129
+ | `openAppStore(options?)` | Open app store page | `Promise<void>` |
130
+
131
+ ### App Review Methods
132
+
133
+ | Method | Description | Returns |
134
+ |--------|-------------|---------|
135
+ | `requestReview()` | Request in-app review | `Promise<ReviewResult>` |
136
+ | `canRequestReview()` | Check review eligibility | `Promise<CanRequestReviewResult>` |
137
+
138
+ ## Configuration Options
139
+
140
+ `configure()` takes a nested `UpdateConfig` — one optional section per feature:
141
+
142
+ ```typescript
143
+ interface UpdateConfig {
144
+ liveUpdate?: LiveUpdateConfig; // OTA updates
145
+ appUpdate?: AppUpdateConfig; // app store updates
146
+ appReview?: AppReviewConfig; // in-app reviews
147
+ backgroundUpdate?: BackgroundUpdateConfig; // background checks + notifications
148
+ security?: SecurityConfig; // HTTPS enforcement, cert pinning
149
+ }
150
+
151
+ interface LiveUpdateConfig {
152
+ appId: string; // Your app identifier (required)
153
+ serverUrl?: string; // Backend base URL; checks hit {serverUrl}/v1/updates/check (HTTPS required in production)
154
+ apiKey?: string; // Sent as X-API-Key on every check (dashboard: Apps → your app → API Keys). Since v3.1.3
155
+ channel?: string; // Update channel (default: 'production')
156
+ autoUpdate?: boolean; // Auto-check + apply updates
157
+ updateStrategy?: 'immediate' | 'background' | 'manual';
158
+ publicKey?: string; // RSA public key for RSA-SHA256 verification
159
+ requireSignature?: boolean; // Reject unsigned bundles (default: true)
160
+ allowUnsignedDevelopmentUpdates?: boolean; // Explicit debug-only escape hatch
161
+ enableDeltaUpdates?: boolean; // Use verified NUDELTA/1 patches when available
162
+ maxBundleSize?: number; // Maximum compressed download (default: 100 MiB)
163
+ maxUncompressedBundleSize?: number; // Native extraction cap (default: 500 MiB)
164
+ checksumAlgorithm?: 'SHA-256' | 'SHA-512'; // (default: 'SHA-256')
165
+ checkInterval?: number; // Auto-check interval
166
+ }
167
+ ```
168
+
169
+ See the full field list for every section in `src/definitions.ts` or the
170
+ [Configuration Guide](https://nativeupdate-docs.aoneahsan.com/reference/sdk/core/config).
171
+
172
+ ## Event Listeners
173
+
174
+ Available events (see `src/definitions.ts` for payload types):
175
+
176
+ | Event | Fires when |
177
+ |-------|------------|
178
+ | `downloadProgress` | OTA bundle download progresses (`{ percent, bytesDownloaded, totalBytes, bundleId }`) |
179
+ | `updateStateChanged` | An OTA bundle changes state (pending → downloading → ready → active/failed) |
180
+ | `backgroundUpdateProgress` | A background update advances through its phases |
181
+ | `backgroundUpdateNotification` | A background-update notification is shown/tapped |
182
+ | `appUpdateStateChanged` / `appUpdateProgress` | Native app-store update state/progress changes |
183
+ | `appUpdateAvailable` / `appUpdateReady` / `appUpdateFailed` | App-store update lifecycle |
184
+ | `appUpdateNotificationClicked` / `appUpdateInstallClicked` | User interacted with an app-update notification |
185
+
186
+ ```typescript
187
+ import { NativeUpdate } from 'native-update';
188
+
189
+ const progressListener = await NativeUpdate.addListener('downloadProgress', (progress) => {
190
+ console.log(`Download: ${progress.percent}%`);
191
+ });
192
+
193
+ const stateListener = await NativeUpdate.addListener('updateStateChanged', (event) => {
194
+ console.log('Bundle state:', event.status);
195
+ });
196
+
197
+ // Later: await progressListener.remove(); or await NativeUpdate.removeAllListeners();
198
+ ```
199
+
200
+ ## Update Channels
201
+
202
+ | Channel | Purpose | Auto-Update | Check Interval |
203
+ |---------|---------|-------------|----------------|
204
+ | `development` | Internal testing | Yes | 1 minute |
205
+ | `staging` | QA/Beta testing | Configurable | 1 hour |
206
+ | `production` | Live users | No (consent) | Daily |
207
+
208
+ ## Backend Requirements
209
+
210
+ Easiest path: use the hosted backend at [nativeupdate.aoneahsan.com](https://nativeupdate.aoneahsan.com)
211
+ (free dashboard — register the app, upload bundles, get the `serverUrl` + API key).
212
+ Running your own server instead? It must implement this contract
213
+ (full spec: [server requirements](https://nativeupdate-docs.aoneahsan.com/backend/overview)):
214
+
215
+ ### GET {serverUrl}/v1/updates/check?channel={channel}
216
+
217
+ Request headers sent by the plugin: `X-API-Key`, `X-Device-ID`,
218
+ `X-Current-Version`, `X-Platform` (and `X-App-Version` when known). Native
219
+ builds also send client-identity headers (`X-Android-Package`,
220
+ `X-Android-Cert-Sha256`/`-Sha1`, `X-Ios-Bundle-Id`) — see "Lock your API key to
221
+ your clients" below.
222
+
223
+ Response — `200` with `available: false` when there is no update, `200` with:
224
+
225
+ ```json
226
+ {
227
+ "available": true,
228
+ "version": "1.2.0",
229
+ "bundleId": "bundle-ulid",
230
+ "downloadUrl": "https://cdn.example.com/bundles/1.2.0.zip",
231
+ "checksum": "sha256-hex...",
232
+ "signature": "base64signature...",
233
+ "signatureAlgorithm": "RSA-SHA256",
234
+ "delta": {
235
+ "format": "NUDELTA/1",
236
+ "fromVersion": "1.1.0",
237
+ "patchUrl": "https://cdn.example.com/delta.json",
238
+ "patchSize": 32768,
239
+ "patchChecksum": "sha256-hex...",
240
+ "targetChecksum": "sha256-hex..."
241
+ },
242
+ "size": 1048576,
243
+ "mandatory": false,
244
+ "releaseNotes": "Bug fixes and improvements"
245
+ }
246
+ ```
247
+
248
+ `downloadUrl` must be an HTTPS URL that returns the bundle zip.
249
+
250
+ ## Lock your API key to your clients (restrictions)
251
+
252
+ The `nu_app_…` API key is meant to ship **inside** your app — you do not need
253
+ your own backend just to hide it. In the dashboard (**Apps → API Keys →
254
+ Restrictions**) you can lock each key to the clients that may use it:
255
+
256
+ - **Web** — allowed origins (exact `https://app.example.com` or a
257
+ `https://*.example.com` wildcard). Enforced against the browser's `Origin`
258
+ header, so the update API is safe to call directly from your web app. (The
259
+ `/v1/*` API sends permissive CORS precisely so browsers can call it; the real
260
+ gate is this per-key check, not CORS.)
261
+ - **Android** — allowed apps by package name + signing-cert SHA-256/SHA-1
262
+ (`keytool -list -printcert`; add both your upload key and the Play App
263
+ Signing cert).
264
+ - **iOS** — allowed apps by bundle identifier.
265
+
266
+ A key with **no** restrictions works from anywhere (default). A restricted key
267
+ that a client doesn't satisfy gets `403 { error: { code:
268
+ "API_KEY_RESTRICTED", … } }`.
269
+
270
+ The plugin sends the needed headers automatically on native update checks. If
271
+ you run your **own** fetch, read the identity first and attach the headers:
272
+
273
+ ```typescript
274
+ import { NativeUpdate } from 'native-update';
275
+
276
+ const id = await NativeUpdate.getAppIdentity();
277
+ const headers: Record<string, string> = { 'X-API-Key': apiKey, /* … */ };
278
+ if (id.platform === 'android') {
279
+ if (id.packageName) headers['X-Android-Package'] = id.packageName;
280
+ if (id.certSha256) headers['X-Android-Cert-Sha256'] = id.certSha256;
281
+ if (id.certSha1) headers['X-Android-Cert-Sha1'] = id.certSha1;
282
+ } else if (id.platform === 'ios') {
283
+ if (id.bundleId) headers['X-Ios-Bundle-Id'] = id.bundleId;
284
+ }
285
+ ```
286
+
287
+ **Requirements & honesty:** Android/iOS restrictions only take effect for apps
288
+ built with **native-update ≥ 3.2.0** (older builds send no identity and are
289
+ blocked by an Android/iOS restriction — web restrictions work with any version).
290
+ The native identity headers are **client-attested** (parity with Google Maps
291
+ API-key app restrictions): they stop cross-site/casual key reuse and quota
292
+ abuse, not a determined attacker replaying headers by hand. Only the web
293
+ `Origin` check is browser-enforced.
294
+
295
+ ## CLI Tools
296
+
297
+ ```bash
298
+ # Create a bundle from your build
299
+ npx native-update bundle create ./dist --version 1.2.0 --output ./bundles
300
+
301
+ # Sign a bundle
302
+ npx native-update bundle sign ./bundles/1.2.0.zip --key ./private.key
303
+
304
+ # Verify a bundle
305
+ npx native-update bundle verify ./bundles/1.2.0.zip --key ./public.key
306
+
307
+ # Generate signing keys
308
+ npx native-update keys generate --type rsa --size 4096
309
+ ```
310
+
311
+ Upload the resulting bundle through the dashboard, the public management API, or
312
+ the `deploy` command below.
313
+
314
+ ## Public Management API (access tokens)
315
+
316
+ Everything the dashboard does — create and configure apps, mint and rotate API
317
+ keys, manage a signing key, back up a keystore, upload a bundle, publish,
318
+ promote, adjust rollout — is also an HTTP API. Use it to run an app's whole
319
+ lifecycle from CI, a script, or an agent.
320
+
321
+ **Two token families. They are not interchangeable.**
322
+
323
+ | Token | Prefix | Used by | Where it may live |
324
+ |---|---|---|---|
325
+ | App API key | `nu_app_…` | The plugin in your app (`/api/v1/updates/check`) | Ships in the app. Lock it down with client restrictions. |
326
+ | **Access token** | `nu_pat_…` | **You / CI / an agent** (`/api/public/v1/*`) | **Server or CI secret only — NEVER a browser or a repo.** |
327
+
328
+ An access token is a user-level secret with no origin restrictions. Anyone
329
+ holding it can manage the apps it is scoped to. Treat it like a password.
330
+
331
+ **Create one:** dashboard → **Access Tokens** → *New token*. Tick the specific
332
+ apps it may manage, or turn on **All apps** to cover every app you own (existing
333
+ and any created later). Grant the delete permissions (builds, apps, keys) only
334
+ if you need them. Copy the token anytime from that page.
335
+
336
+ **Access tokens are dashboard-only.** There is no endpoint to create, rotate, or
337
+ delete a token — a leaked token can never mint another token or widen its reach.
338
+ `GET /token` reports `all_apps` and the token's app list.
339
+
340
+ ### Authenticate
341
+
342
+ ```
343
+ Authorization: Bearer nu_pat_…
344
+ ```
345
+
346
+ Base URL: `https://nativeupdatebe.aoneahsan.com/api/public/v1`
347
+ (`X-Access-Token: nu_pat_…` also works if your transport owns `Authorization`.)
348
+
349
+ **Start here.** `GET /token` tells an agent who it is and what it may touch, so
350
+ it never has to guess an app id:
351
+
352
+ ```bash
353
+ curl -H "Authorization: Bearer $NATIVE_UPDATE_TOKEN" \
354
+ https://nativeupdatebe.aoneahsan.com/api/public/v1/token
355
+ ```
356
+
357
+ ```json
358
+ { "data": {
359
+ "name": "GitHub Actions",
360
+ "permissions": ["manage"],
361
+ "apps": [{ "id": 12, "app_id": "com.example.app", "name": "Example" }]
362
+ } }
363
+ ```
364
+
365
+ ### Endpoints
366
+
367
+ `{app}` accepts the numeric id **or** the string `app_id` (`com.example.app`).
368
+
369
+ | Method | Path | Does |
370
+ |---|---|---|
371
+ | GET | `/token` | What this token is, its `all_apps` flag, and which apps it manages |
372
+ | GET · POST | `/apps` | List apps · **create an app** (auto-attached to a scoped token) |
373
+ | GET · PATCH · DELETE | `/apps/{app}` | App details · edit (name/platform/description) · delete (needs `apps.delete`, cascades) |
374
+ | GET · POST | `/apps/{app}/api-keys` | List keys (safe fields) · mint a key (returns `plaintext_key` once; max 3 active) |
375
+ | GET · DELETE | `/apps/{app}/api-keys/{key}` | Key details · delete (needs `keys.delete`) |
376
+ | POST | `/apps/{app}/api-keys/{key}/rotate` · `/reveal` | New secret · re-read plaintext (409 `PLAINTEXT_UNAVAILABLE` for legacy keys) |
377
+ | PATCH | `/apps/{app}/api-keys/{key}/restrictions` | Set origins/android/ios; empty body clears (unrestricted) |
378
+ | POST | `/apps/{app}/api-keys/{key}/revoke` · `/deprecate` | Disable now · mark for retirement |
379
+ | GET · POST | `/apps/{app}/signing-key` | Public key + fingerprint (`{configured:false}` if none) · create (409 `SIGNING_KEY_EXISTS`) |
380
+ | POST | `/apps/{app}/signing-key/rotate` | Rotate (409 `NO_ACTIVE_SIGNING_KEY` if none) |
381
+ | GET · POST · DELETE | `/apps/{app}/keystore` | Backup metadata · upload/replace a `.zip` (≤10 MB, private) · delete |
382
+ | GET | `/apps/{app}/keystore/download` | Stream the `.zip` back (`application/zip`, never a public URL) |
383
+ | GET | `/apps/{app}/builds` | Builds; filter `?channel=` `?status=` |
384
+ | GET | `/apps/{app}/builds/{build}` | Build details |
385
+ | POST | `/apps/{app}/builds` | **Upload a bundle — queued, returns 202** (`mandatory` flag supported) |
386
+ | PATCH | `/apps/{app}/builds/{build}` | Set `status`, `release_notes`, `mandatory` (→active on a not-ready build = 422 `BUILD_NOT_READY`) |
387
+ | POST | `/apps/{app}/builds/{build}/promote` | Copy into another channel (`target_channel`) |
388
+ | PATCH | `/apps/{app}/builds/{build}/rollout` | Set `rollout_percentage` (0 halts) and/or `enabled` (pause/resume) |
389
+ | DELETE | `/apps/{app}/builds/{build}` | Delete — needs the `builds.delete` permission |
390
+ | GET | `/jobs/{jobId}` | Status of queued work |
391
+
392
+ Machine-readable spec (OpenAPI 3.1):
393
+ <https://nativeupdate-docs.aoneahsan.com/openapi/public-api.json>
394
+
395
+ **Raw Markdown for agents.** The public-API, AI-integration, and changelog pages
396
+ are also served front-matter-stripped at `/raw/<name>.md`, indexed by
397
+ <https://nativeupdate-docs.aoneahsan.com/raw/manifest.json> — fetch those to
398
+ implement against the API without scraping rendered HTML.
399
+
400
+ ### Upload: 202 now, live in a moment
401
+
402
+ Signing and storing a bundle takes too long to hold a request open, so an upload
403
+ is **always queued**. You get a job id; poll it until the build goes live.
404
+
405
+ ```bash
406
+ # 1. Upload → 202
407
+ curl -X POST \
408
+ -H "Authorization: Bearer $NATIVE_UPDATE_TOKEN" \
409
+ -F "file=@./bundle.zip" \
410
+ -F "version=1.2.0" \
411
+ -F "channel=production" \
412
+ -F "release_notes=Bug fixes" \
413
+ https://nativeupdatebe.aoneahsan.com/api/public/v1/apps/com.example.app/builds
414
+ ```
415
+
416
+ ```json
417
+ { "data": {
418
+ "job_id": "01hq2xk8...",
419
+ "status_url": "https://nativeupdatebe.aoneahsan.com/api/public/v1/jobs/01hq2xk8...",
420
+ "build": { "id": 42, "version": "1.2.0", "status": "processing" }
421
+ } }
422
+ ```
423
+
424
+ ```bash
425
+ # 2. Poll until status is "completed" or "failed"
426
+ curl -H "Authorization: Bearer $NATIVE_UPDATE_TOKEN" \
427
+ https://nativeupdatebe.aoneahsan.com/api/public/v1/jobs/01hq2xk8...
428
+ ```
429
+
430
+ ```json
431
+ { "data": {
432
+ "status": "completed",
433
+ "result": { "build_id": 42, "version": "1.2.0", "channel": "production" }
434
+ } }
435
+ ```
436
+
437
+ **Agents: poll, don't assume.** A 202 means *accepted*, not *live*. The build
438
+ stays `processing` and devices never see it until the job reports `completed`.
439
+ On `failed`, read `error` — the build never goes live and the owner is emailed.
440
+ Poll every ~5s; processing normally finishes in well under a minute.
441
+
442
+ ### CLI equivalents
443
+
444
+ ```bash
445
+ export NATIVE_UPDATE_TOKEN=nu_pat_… # never pass --token in CI; it leaks into logs
446
+
447
+ npx native-update token info # who am I, which apps?
448
+
449
+ # Apps
450
+ npx native-update apps list
451
+ npx native-update apps create --name "Example" --bundle-id com.example.app --platform both
452
+ npx native-update apps show com.example.app
453
+ npx native-update apps update com.example.app --name "Example (renamed)"
454
+ npx native-update apps delete com.example.app
455
+
456
+ # API keys
457
+ npx native-update apps keys list com.example.app
458
+ npx native-update apps keys create com.example.app --name production # prints the secret once
459
+ npx native-update apps keys show com.example.app 6
460
+ npx native-update apps keys rotate com.example.app 6
461
+ npx native-update apps keys reveal com.example.app 6
462
+ npx native-update apps keys restrict com.example.app 6 --origins https://app.example.com
463
+ npx native-update apps keys revoke com.example.app 6
464
+ npx native-update apps keys deprecate com.example.app 6
465
+ npx native-update apps keys delete com.example.app 6
466
+
467
+ # Signing key (public key + fingerprint only) and keystore backup
468
+ npx native-update apps signing show com.example.app
469
+ npx native-update apps signing create com.example.app --name release
470
+ npx native-update apps signing rotate com.example.app
471
+ npx native-update apps keystore upload com.example.app ./example-release.zip
472
+ npx native-update apps keystore info com.example.app
473
+ npx native-update apps keystore download com.example.app ./keystore.zip
474
+ npx native-update apps keystore delete com.example.app
475
+
476
+ # Builds — deploy: zips the directory, uploads, and (with --wait) blocks until
477
+ # live. Exits non-zero if the release fails, so CI fails too.
478
+ npx native-update deploy ./dist --app com.example.app --version 1.2.0 --wait
479
+
480
+ npx native-update builds list com.example.app
481
+ npx native-update builds promote com.example.app 42 --to production
482
+ npx native-update builds rollout com.example.app 42 --percent 10
483
+ npx native-update builds status com.example.app 42 --set paused
484
+ npx native-update jobs status 01hq2xk8... --wait
485
+ ```
486
+
487
+ ### Errors
488
+
489
+ Every error uses one envelope:
490
+
491
+ ```json
492
+ { "error": { "code": "APP_NOT_FOUND", "message": "…", "details": { } } }
493
+ ```
494
+
495
+ | Status | Code | Meaning |
496
+ |---|---|---|
497
+ | 401 | `MISSING_ACCESS_TOKEN`, `INVALID_ACCESS_TOKEN_FORMAT`, `ACCESS_TOKEN_NOT_FOUND`, `ACCESS_TOKEN_INVALID` | No, malformed, unknown, revoked, or expired token |
498
+ | 403 | `TOKEN_PERMISSION_DENIED` | The token lacks an opt-in delete permission (`builds.delete` / `apps.delete` / `keys.delete`; see `details.required_permission`) |
499
+ | 404 | `APP_NOT_FOUND`, `BUILD_NOT_FOUND`, `KEY_NOT_FOUND`, `KEYSTORE_NOT_FOUND`, `JOB_NOT_FOUND` | Absent **or** outside this token's apps — the two are deliberately indistinguishable |
500
+ | 409 | `VERSION_ALREADY_EXISTS`, `BUNDLE_ID_TAKEN`, `SIGNING_KEY_EXISTS`, `NO_ACTIVE_SIGNING_KEY`, `PLAINTEXT_UNAVAILABLE` | A conflicting or missing precondition |
501
+ | 422 | `VERSION_NOT_NEWER`, `ALREADY_IN_CHANNEL`, `APP_LIMIT_REACHED`, `MAX_KEYS_REACHED`, `BUILD_NOT_READY`, `KEYSTORE_MUST_BE_ZIP` | Semantically refused (bump the version, free a slot, zip the keystore, …) |
502
+ | 429 | `KEY_ACTION_RATE_LIMITED`, — | Rate limited: 120 requests/min; uploads 30/hour; a per-key action cap (`Retry-After`) |
503
+
504
+ **A 404 does not always mean "gone".** Scoping errors answer 404 on purpose, so
505
+ the API cannot be used to discover which apps exist. If an app id you believe in
506
+ returns 404, check the token's app list with `GET /token` before concluding the
507
+ app is missing.
508
+
509
+ ## Platform-Specific Setup
510
+
511
+ ### Android
512
+
513
+ No additional setup required. The plugin's own Gradle config already includes
514
+ the Google Play App Update and Play Review libraries (do NOT add the legacy
515
+ `com.google.android.play:core` artifact — it conflicts with them).
516
+
517
+ ### iOS
518
+
519
+ No additional setup required. Uses native APIs.
520
+
521
+ ### Web (Limited Support)
522
+
523
+ Web platform supports checking for updates only. Actual OTA updates require native platforms.
524
+
525
+ ## Security Best Practices
526
+
527
+ 1. **Always use HTTPS** for update URLs
528
+ 2. **Keep signature verification enabled** with an RSA key (`RSA-SHA256`, PKCS#1 v1.5)
529
+ 3. **Use checksums** to verify bundle integrity
530
+ 4. **Test rollback** scenarios before production
531
+ 5. **Implement `notifyAppReady()`** to prevent auto-rollback on stable updates
532
+
533
+ ## Common Patterns
534
+
535
+ ### Check on App Start
536
+
537
+ ```typescript
538
+ import { App } from '@capacitor/app';
539
+ import { NativeUpdate } from 'native-update';
540
+
541
+ App.addListener('appStateChange', async ({ isActive }) => {
542
+ if (isActive) {
543
+ const result = await NativeUpdate.sync();
544
+ if (result.status === 'UPDATE_INSTALLED') {
545
+ // Show user prompt to reload (NativeUpdate.reload())
546
+ }
547
+ }
548
+ });
549
+ ```
550
+
551
+ ### Review After Positive Action
552
+
553
+ ```typescript
554
+ async function handlePurchaseComplete() {
555
+ // After successful purchase
556
+ const eligibility = await NativeUpdate.canRequestReview();
557
+ if (eligibility.canRequest) {
558
+ await NativeUpdate.requestReview();
559
+ }
560
+ }
561
+ ```
562
+
563
+ ## Troubleshooting
564
+
565
+ | Issue | Solution |
566
+ |-------|----------|
567
+ | Update not applying | Call `notifyAppReady()` after successful update |
568
+ | Rollback on restart | Previous update crashed; check error logs |
569
+ | Download fails | Verify network, check server response format |
570
+ | Signature invalid | Regenerate keys, re-sign bundle |
571
+
572
+ ## Links
573
+
574
+ - [Full Documentation](https://nativeupdate-docs.aoneahsan.com/)
575
+ - [API Reference](https://nativeupdate-docs.aoneahsan.com/reference/sdk/live-update/methods)
576
+ - [Example Apps](https://nativeupdate-docs.aoneahsan.com/tutorials/first-ota-update)
577
+ - [CLI Reference](https://nativeupdate-docs.aoneahsan.com/reference/cli/overview)
578
+ - [Security Guide](https://nativeupdate-docs.aoneahsan.com/concepts/security-model)
package/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Native Update License
2
+
3
+ Copyright (c) 2024-2026 Ahsan Mahmood. All rights reserved.
4
+
5
+ This license applies to the native-update package from version 4.1.2 onward. Versions published before
6
+ 4.1.2 remain available under the license they were published with.
7
+
8
+ 1. Use. You may install the native-update package and use it, without charge, inside applications you
9
+ build and distribute, to receive updates from the Native Update service
10
+ (https://nativeupdate.aoneahsan.com) under a Native Update account and plan, or from a server you
11
+ operate that implements the update contract documented at https://nativeupdate-docs.aoneahsan.com.
12
+
13
+ 2. Restrictions. You may not sell, sublicense, or redistribute the package or any part of it on its own
14
+ or as part of a library, SDK, or service that offers over-the-air update delivery to others; publish
15
+ a modified copy of it; or remove this notice. Shipping the package inside your own application
16
+ binaries and web bundles, as step 1 describes, is not redistribution under this section.
17
+
18
+ 3. The service. Use of the Native Update service, dashboard, API, and CLI is governed by the Terms of
19
+ Service at https://nativeupdate.aoneahsan.com/terms.
20
+
21
+ 4. No warranty. THE PACKAGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
24
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ CONNECTION WITH THE PACKAGE OR THE USE OR OTHER DEALINGS IN THE PACKAGE.
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'NativeUpdate'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '14.0'
15
+ s.dependency 'Capacitor'
16
+ s.dependency 'ZIPFoundation', '~> 0.9.19'
17
+ s.swift_version = '5.9'
18
+ s.frameworks = 'LocalAuthentication', 'Security'
19
+ end