native-update 3.1.5 → 3.2.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 +49 -1
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +67 -1
- package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +5 -0
- package/dist/esm/core/update-check.d.ts +23 -5
- package/dist/esm/core/update-check.js +32 -5
- package/dist/esm/definitions.d.ts +14 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/plugin.js +23 -0
- package/dist/esm/types/app-identity.d.ts +36 -0
- package/dist/esm/types/app-identity.js +1 -0
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +5 -0
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +32 -0
- package/docs/KNOWN_LIMITATIONS.md +23 -0
- package/docs/server-requirements.md +15 -0
- package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +18 -1
- package/ios/Plugin/NativeUpdatePlugin.m +1 -0
- package/ios/Plugin/NativeUpdatePlugin.swift +5 -1
- package/package.json +1 -1
package/AI-INTEGRATION-GUIDE.md
CHANGED
|
@@ -214,7 +214,10 @@ Self-hosting instead? Your server must implement this contract
|
|
|
214
214
|
### GET {serverUrl}/v1/updates/check?channel={channel}
|
|
215
215
|
|
|
216
216
|
Request headers sent by the plugin: `X-API-Key`, `X-Device-ID`,
|
|
217
|
-
`X-Current-Version`, `X-Platform` (and `X-App-Version` when known).
|
|
217
|
+
`X-Current-Version`, `X-Platform` (and `X-App-Version` when known). Native
|
|
218
|
+
builds also send client-identity headers (`X-Android-Package`,
|
|
219
|
+
`X-Android-Cert-Sha256`/`-Sha1`, `X-Ios-Bundle-Id`) — see "Lock your API key to
|
|
220
|
+
your clients" below.
|
|
218
221
|
|
|
219
222
|
Response — `200` with `available: false` when there is no update, `200` with:
|
|
220
223
|
|
|
@@ -234,6 +237,51 @@ Response — `200` with `available: false` when there is no update, `200` with:
|
|
|
234
237
|
|
|
235
238
|
`downloadUrl` must be an HTTPS URL that returns the bundle zip.
|
|
236
239
|
|
|
240
|
+
## Lock your API key to your clients (restrictions)
|
|
241
|
+
|
|
242
|
+
The `nu_app_…` API key is meant to ship **inside** your app — you do not need
|
|
243
|
+
your own backend just to hide it. In the dashboard (**Apps → API Keys →
|
|
244
|
+
Restrictions**) you can lock each key to the clients that may use it:
|
|
245
|
+
|
|
246
|
+
- **Web** — allowed origins (exact `https://app.example.com` or a
|
|
247
|
+
`https://*.example.com` wildcard). Enforced against the browser's `Origin`
|
|
248
|
+
header, so the update API is safe to call directly from your web app. (The
|
|
249
|
+
`/v1/*` API sends permissive CORS precisely so browsers can call it; the real
|
|
250
|
+
gate is this per-key check, not CORS.)
|
|
251
|
+
- **Android** — allowed apps by package name + signing-cert SHA-256/SHA-1
|
|
252
|
+
(`keytool -list -printcert`; add both your upload key and the Play App
|
|
253
|
+
Signing cert).
|
|
254
|
+
- **iOS** — allowed apps by bundle identifier.
|
|
255
|
+
|
|
256
|
+
A key with **no** restrictions works from anywhere (default). A restricted key
|
|
257
|
+
that a client doesn't satisfy gets `403 { error: { code:
|
|
258
|
+
"API_KEY_RESTRICTED", … } }`.
|
|
259
|
+
|
|
260
|
+
The plugin sends the needed headers automatically on native update checks. If
|
|
261
|
+
you run your **own** fetch, read the identity first and attach the headers:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { NativeUpdate } from 'native-update';
|
|
265
|
+
|
|
266
|
+
const id = await NativeUpdate.getAppIdentity();
|
|
267
|
+
const headers: Record<string, string> = { 'X-API-Key': apiKey, /* … */ };
|
|
268
|
+
if (id.platform === 'android') {
|
|
269
|
+
if (id.packageName) headers['X-Android-Package'] = id.packageName;
|
|
270
|
+
if (id.certSha256) headers['X-Android-Cert-Sha256'] = id.certSha256;
|
|
271
|
+
if (id.certSha1) headers['X-Android-Cert-Sha1'] = id.certSha1;
|
|
272
|
+
} else if (id.platform === 'ios') {
|
|
273
|
+
if (id.bundleId) headers['X-Ios-Bundle-Id'] = id.bundleId;
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Requirements & honesty:** Android/iOS restrictions only take effect for apps
|
|
278
|
+
built with **native-update ≥ 3.2.0** (older builds send no identity and are
|
|
279
|
+
blocked by an Android/iOS restriction — web restrictions work with any version).
|
|
280
|
+
The native identity headers are **client-attested** (parity with Google Maps
|
|
281
|
+
API-key app restrictions): they stop cross-site/casual key reuse and quota
|
|
282
|
+
abuse, not a determined attacker replaying headers by hand. Only the web
|
|
283
|
+
`Origin` check is browser-enforced.
|
|
284
|
+
|
|
237
285
|
## CLI Tools
|
|
238
286
|
|
|
239
287
|
```bash
|
|
@@ -37,6 +37,16 @@ class LiveUpdatePlugin(
|
|
|
37
37
|
/** Hard cap on uncompressed bundle size (zip-bomb defense). */
|
|
38
38
|
private val maxUncompressedBundleBytes: Long = 500L * 1024 * 1024
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The app's signing-certificate fingerprints (SHA-256, SHA-1) as lowercase
|
|
42
|
+
* hex with no separators, computed once. Used for API-key client
|
|
43
|
+
* restrictions (the X-Android-Cert-* headers + getAppIdentity()). Null on
|
|
44
|
+
* any failure — identity is best-effort and must NEVER break an update check.
|
|
45
|
+
*/
|
|
46
|
+
private val signingCertFingerprints: Pair<String?, String?> by lazy { computeSigningCertFingerprints() }
|
|
47
|
+
private val appSigningSha256: String? get() = signingCertFingerprints.first
|
|
48
|
+
private val appSigningSha1: String? get() = signingCertFingerprints.second
|
|
49
|
+
|
|
40
50
|
companion object {
|
|
41
51
|
// SharedPreferences keys. Kept as constants so A2 (boot-time
|
|
42
52
|
// re-verification) and A3 (crash-loop auto-rollback) stay in sync
|
|
@@ -424,8 +434,59 @@ class LiveUpdatePlugin(
|
|
|
424
434
|
}
|
|
425
435
|
}
|
|
426
436
|
|
|
437
|
+
/**
|
|
438
|
+
* The app's client identity for API-key client restrictions: applicationId
|
|
439
|
+
* + signing-cert SHA-256/SHA-1. Consumed by the dashboard "Restrictions"
|
|
440
|
+
* UI and attached as X-Android-* headers on native update checks.
|
|
441
|
+
*/
|
|
442
|
+
fun getAppIdentity(call: PluginCall) {
|
|
443
|
+
val result = JSObject()
|
|
444
|
+
result.put("platform", "android")
|
|
445
|
+
result.put("packageName", context.packageName)
|
|
446
|
+
appSigningSha256?.let { result.put("certSha256", it) }
|
|
447
|
+
appSigningSha1?.let { result.put("certSha1", it) }
|
|
448
|
+
call.resolve(result)
|
|
449
|
+
}
|
|
450
|
+
|
|
427
451
|
// Private helper methods
|
|
428
|
-
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Read the app's first signing certificate and return (SHA-256, SHA-1) as
|
|
455
|
+
* lowercase hex, no separators. Uses GET_SIGNING_CERTIFICATES on API 28+
|
|
456
|
+
* (v2/v3 signing) and falls back to the deprecated GET_SIGNATURES on API
|
|
457
|
+
* 22–27. Any failure yields (null, null) — never throws.
|
|
458
|
+
*/
|
|
459
|
+
private fun computeSigningCertFingerprints(): Pair<String?, String?> {
|
|
460
|
+
return try {
|
|
461
|
+
val pm = context.packageManager
|
|
462
|
+
val pkg = context.packageName
|
|
463
|
+
val certBytes: ByteArray? = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
|
464
|
+
val info = pm.getPackageInfo(pkg, android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES)
|
|
465
|
+
info.signingInfo?.apkContentsSigners?.firstOrNull()?.toByteArray()
|
|
466
|
+
} else {
|
|
467
|
+
@Suppress("DEPRECATION")
|
|
468
|
+
val info = pm.getPackageInfo(pkg, android.content.pm.PackageManager.GET_SIGNATURES)
|
|
469
|
+
@Suppress("DEPRECATION")
|
|
470
|
+
info.signatures?.firstOrNull()?.toByteArray()
|
|
471
|
+
}
|
|
472
|
+
if (certBytes == null) {
|
|
473
|
+
Pair(null, null)
|
|
474
|
+
} else {
|
|
475
|
+
Pair(hashHex(certBytes, "SHA-256"), hashHex(certBytes, "SHA-1"))
|
|
476
|
+
}
|
|
477
|
+
} catch (e: Exception) {
|
|
478
|
+
Pair(null, null)
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
private fun hashHex(bytes: ByteArray, algorithm: String): String {
|
|
483
|
+
// `it.toInt() and 0xFF` is REQUIRED: a bare Byte sign-extends in
|
|
484
|
+
// "%02x".format (e.g. 0xFF → "ffffffff"), which would corrupt the
|
|
485
|
+
// fingerprint and break cert matching.
|
|
486
|
+
return MessageDigest.getInstance(algorithm).digest(bytes)
|
|
487
|
+
.joinToString("") { "%02x".format(it.toInt() and 0xFF) }
|
|
488
|
+
}
|
|
489
|
+
|
|
429
490
|
/**
|
|
430
491
|
* v3 wire contract (mirrors src/core/update-check.ts):
|
|
431
492
|
* GET {serverUrl}/v1/updates/check?channel={channel}
|
|
@@ -456,7 +517,12 @@ class LiveUpdatePlugin(
|
|
|
456
517
|
.header("X-Device-ID", getOrCreateDeviceId())
|
|
457
518
|
.header("X-Current-Version", getCurrentVersion())
|
|
458
519
|
.header("X-Platform", "android")
|
|
520
|
+
.header("X-Android-Package", context.packageName)
|
|
459
521
|
getBinaryVersion()?.let { requestBuilder.header("X-App-Version", it) }
|
|
522
|
+
// App-identity headers for API-key client restrictions. Best-effort:
|
|
523
|
+
// null fingerprints (e.g. odd signing setup) simply omit the header.
|
|
524
|
+
appSigningSha256?.let { requestBuilder.header("X-Android-Cert-Sha256", it) }
|
|
525
|
+
appSigningSha1?.let { requestBuilder.header("X-Android-Cert-Sha1", it) }
|
|
460
526
|
|
|
461
527
|
val response = okHttpClient.newCall(requestBuilder.build()).execute()
|
|
462
528
|
if (response.isSuccessful) {
|
|
@@ -240,6 +240,11 @@ class NativeUpdatePlugin : Plugin() {
|
|
|
240
240
|
fun getLatest(call: PluginCall) {
|
|
241
241
|
liveUpdatePlugin.getLatest(call)
|
|
242
242
|
}
|
|
243
|
+
|
|
244
|
+
@PluginMethod
|
|
245
|
+
fun getAppIdentity(call: PluginCall) {
|
|
246
|
+
liveUpdatePlugin.getAppIdentity(call)
|
|
247
|
+
}
|
|
243
248
|
|
|
244
249
|
@PluginMethod
|
|
245
250
|
fun setChannel(call: PluginCall) {
|
|
@@ -13,13 +13,23 @@
|
|
|
13
13
|
*
|
|
14
14
|
* ```
|
|
15
15
|
* GET {baseUrl}/v1/updates/check?channel={channel}
|
|
16
|
-
* X-API-Key:
|
|
17
|
-
* X-Device-ID:
|
|
18
|
-
* X-Current-Version:
|
|
19
|
-
* X-Platform:
|
|
20
|
-
* X-App-Version:
|
|
16
|
+
* X-API-Key: nu_app_… (required; ValidateApiKey middleware → 401 without it)
|
|
17
|
+
* X-Device-ID: stable per-device hash (required; 400 without it)
|
|
18
|
+
* X-Current-Version: the currently-installed bundle version
|
|
19
|
+
* X-Platform: ios | android | web
|
|
20
|
+
* X-App-Version: native app version (optional)
|
|
21
|
+
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
22
|
+
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
23
|
+
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
24
|
+
* X-Ios-Bundle-Id: bundle identifier (optional; sent when identity.platform === 'ios')
|
|
25
|
+
* X-Ios-Team-Id: team id (optional; currently never populated)
|
|
21
26
|
* ```
|
|
22
27
|
*
|
|
28
|
+
* The X-Android-* / X-Ios-* headers carry the app's client identity for
|
|
29
|
+
* per-key client restrictions (see AppIdentity + `getAppIdentity()`). They are
|
|
30
|
+
* only attached when a matching `identity` is supplied; web clients identify
|
|
31
|
+
* via the browser-enforced Origin header instead.
|
|
32
|
+
*
|
|
23
33
|
* Response (200):
|
|
24
34
|
* ```jsonc
|
|
25
35
|
* // no update:
|
|
@@ -43,6 +53,7 @@
|
|
|
43
53
|
* Custom backends must return these exact field names — see
|
|
44
54
|
* `docs/server-requirements.md`.
|
|
45
55
|
*/
|
|
56
|
+
import type { AppIdentity } from '../types/app-identity';
|
|
46
57
|
/** Request inputs for a single backend update check. */
|
|
47
58
|
export interface UpdateCheckRequest {
|
|
48
59
|
/** API key issued by the dashboard; sent as `X-API-Key`. Required. */
|
|
@@ -57,6 +68,13 @@ export interface UpdateCheckRequest {
|
|
|
57
68
|
platform: string;
|
|
58
69
|
/** Native app version; sent as `X-App-Version` when present. */
|
|
59
70
|
appVersion?: string;
|
|
71
|
+
/**
|
|
72
|
+
* App client identity for API-key client restrictions. When present and its
|
|
73
|
+
* `platform` is `android`/`ios`, the matching `X-Android-*` / `X-Ios-*`
|
|
74
|
+
* headers are attached. Web clients omit it (the Origin header identifies
|
|
75
|
+
* them). Obtain it from `NativeUpdate.getAppIdentity()`.
|
|
76
|
+
*/
|
|
77
|
+
identity?: AppIdentity;
|
|
60
78
|
/** Optional abort signal so callers can time the request out. */
|
|
61
79
|
signal?: AbortSignal;
|
|
62
80
|
}
|
|
@@ -13,13 +13,23 @@
|
|
|
13
13
|
*
|
|
14
14
|
* ```
|
|
15
15
|
* GET {baseUrl}/v1/updates/check?channel={channel}
|
|
16
|
-
* X-API-Key:
|
|
17
|
-
* X-Device-ID:
|
|
18
|
-
* X-Current-Version:
|
|
19
|
-
* X-Platform:
|
|
20
|
-
* X-App-Version:
|
|
16
|
+
* X-API-Key: nu_app_… (required; ValidateApiKey middleware → 401 without it)
|
|
17
|
+
* X-Device-ID: stable per-device hash (required; 400 without it)
|
|
18
|
+
* X-Current-Version: the currently-installed bundle version
|
|
19
|
+
* X-Platform: ios | android | web
|
|
20
|
+
* X-App-Version: native app version (optional)
|
|
21
|
+
* X-Android-Package: applicationId (optional; sent when identity.platform === 'android')
|
|
22
|
+
* X-Android-Cert-Sha256: signing cert SHA-256, hex (optional)
|
|
23
|
+
* X-Android-Cert-Sha1: signing cert SHA-1, hex (optional)
|
|
24
|
+
* X-Ios-Bundle-Id: bundle identifier (optional; sent when identity.platform === 'ios')
|
|
25
|
+
* X-Ios-Team-Id: team id (optional; currently never populated)
|
|
21
26
|
* ```
|
|
22
27
|
*
|
|
28
|
+
* The X-Android-* / X-Ios-* headers carry the app's client identity for
|
|
29
|
+
* per-key client restrictions (see AppIdentity + `getAppIdentity()`). They are
|
|
30
|
+
* only attached when a matching `identity` is supplied; web clients identify
|
|
31
|
+
* via the browser-enforced Origin header instead.
|
|
32
|
+
*
|
|
23
33
|
* Response (200):
|
|
24
34
|
* ```jsonc
|
|
25
35
|
* // no update:
|
|
@@ -64,6 +74,23 @@ export async function checkForUpdate(baseUrl, req) {
|
|
|
64
74
|
if (req.appVersion) {
|
|
65
75
|
headers['X-App-Version'] = req.appVersion;
|
|
66
76
|
}
|
|
77
|
+
// App client-identity headers for per-key client restrictions. Only attached
|
|
78
|
+
// for native platforms; web clients identify via the browser Origin header.
|
|
79
|
+
const identity = req.identity;
|
|
80
|
+
if ((identity === null || identity === void 0 ? void 0 : identity.platform) === 'android') {
|
|
81
|
+
if (identity.packageName)
|
|
82
|
+
headers['X-Android-Package'] = identity.packageName;
|
|
83
|
+
if (identity.certSha256)
|
|
84
|
+
headers['X-Android-Cert-Sha256'] = identity.certSha256;
|
|
85
|
+
if (identity.certSha1)
|
|
86
|
+
headers['X-Android-Cert-Sha1'] = identity.certSha1;
|
|
87
|
+
}
|
|
88
|
+
else if ((identity === null || identity === void 0 ? void 0 : identity.platform) === 'ios') {
|
|
89
|
+
if (identity.bundleId)
|
|
90
|
+
headers['X-Ios-Bundle-Id'] = identity.bundleId;
|
|
91
|
+
if (identity.teamId)
|
|
92
|
+
headers['X-Ios-Team-Id'] = identity.teamId;
|
|
93
|
+
}
|
|
67
94
|
const response = await fetch(url, { method: 'GET', headers, signal: req.signal });
|
|
68
95
|
if (!response.ok) {
|
|
69
96
|
return { available: false };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AppIdentity } from './types/app-identity';
|
|
2
|
+
export type { AppIdentity } from './types/app-identity';
|
|
1
3
|
/**
|
|
2
4
|
* Live Update Plugin Interface
|
|
3
5
|
*/
|
|
@@ -42,6 +44,18 @@ export interface LiveUpdatePlugin {
|
|
|
42
44
|
* Check for latest version
|
|
43
45
|
*/
|
|
44
46
|
getLatest(): Promise<LatestVersion>;
|
|
47
|
+
/**
|
|
48
|
+
* The app's client identity for API-key client restrictions (dashboard →
|
|
49
|
+
* API Keys → Restrictions). On Android it is the applicationId + signing-cert
|
|
50
|
+
* SHA-256/SHA-1; on iOS the bundle identifier; on web `{ platform: 'web' }`
|
|
51
|
+
* (browsers identify via the Origin header). Call this when performing your
|
|
52
|
+
* OWN update-check fetch and attach the matching `X-Android-*` / `X-Ios-*`
|
|
53
|
+
* headers; the plugin's native update-check attaches them automatically.
|
|
54
|
+
*
|
|
55
|
+
* Headers are client-attested (parity with Google API-key restrictions):
|
|
56
|
+
* they stop cross-site/casual key reuse, not a forged native client.
|
|
57
|
+
*/
|
|
58
|
+
getAppIdentity(): Promise<AppIdentity>;
|
|
45
59
|
/**
|
|
46
60
|
* Switch update channel
|
|
47
61
|
*/
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { NativeUpdate } from './plugin';
|
|
2
2
|
export { BackgroundUpdateType, NotificationPriority, UpdateStrategy, UpdateMode, InstallMode, ChecksumAlgorithm, SyncStatus, BundleStatus, InstallStatus, UpdateErrorCode, } from './definitions';
|
|
3
|
-
export type { NativeUpdatePlugin, NativeUpdateCombinedPlugin, NativeUpdateListeners, LiveUpdatePlugin, AppUpdatePlugin, AppReviewPlugin, PluginConfig, UpdateConfig, LiveUpdateConfig, AppUpdateConfig, AppReviewConfig, BundleInfo, DownloadOptions, DownloadProgressEvent, SyncOptions, SyncResult, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, CheckForUpdateResult, DownloadUpdateOptions, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, UpdateStateChangedEvent, AppUpdateStateChangedEvent, AppUpdateProgressEvent, AppUpdateAvailableEvent, AppUpdateReadyEvent, AppUpdateFailedEvent, AppUpdateNotificationClickedEvent, AppUpdateInstallClickedEvent, BackgroundUpdateProgressEvent, BackgroundUpdateNotificationEvent, UpdateError, BackgroundUpdatePlugin, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, SecurityConfig, SecurityInfo, CertificatePinning, CertificatePin, PluginInitConfig, PluginListenerHandle, } from './definitions';
|
|
3
|
+
export type { NativeUpdatePlugin, NativeUpdateCombinedPlugin, NativeUpdateListeners, LiveUpdatePlugin, AppUpdatePlugin, AppReviewPlugin, PluginConfig, UpdateConfig, LiveUpdateConfig, AppUpdateConfig, AppReviewConfig, BundleInfo, DownloadOptions, DownloadProgressEvent, SyncOptions, SyncResult, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, UpdateStateChangedEvent, AppUpdateStateChangedEvent, AppUpdateProgressEvent, AppUpdateAvailableEvent, AppUpdateReadyEvent, AppUpdateFailedEvent, AppUpdateNotificationClickedEvent, AppUpdateInstallClickedEvent, BackgroundUpdateProgressEvent, BackgroundUpdateNotificationEvent, UpdateError, BackgroundUpdatePlugin, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, SecurityConfig, SecurityInfo, CertificatePinning, CertificatePin, PluginInitConfig, PluginListenerHandle, } from './definitions';
|
|
4
4
|
export type { RolloutConfig, RolloutTargetSegments, RolloutSchedule, RolloutTimestamp, DeviceInfo, UpdateCheckResponse, } from './types/rollout';
|
|
5
5
|
export { ErrorCode, NativeUpdateError, ConfigurationError, DownloadError, ValidationError, StorageError, UpdateError as UpdateErrorClass, } from './core/errors';
|
|
6
6
|
export { ConfigManager } from './core/config';
|
package/dist/esm/plugin.js
CHANGED
|
@@ -286,6 +286,28 @@ class NativeUpdatePluginWeb {
|
|
|
286
286
|
// ============================================
|
|
287
287
|
// Convenience Methods (Aliases)
|
|
288
288
|
// ============================================
|
|
289
|
+
/**
|
|
290
|
+
* The app's client identity for API-key client restrictions. On web this is
|
|
291
|
+
* `{ platform: 'web' }` — browsers identify via the Origin header. On native
|
|
292
|
+
* platforms this method is served by the native layer (Android: applicationId
|
|
293
|
+
* + signing-cert SHA-256/SHA-1; iOS: bundle identifier).
|
|
294
|
+
*/
|
|
295
|
+
async getAppIdentity() {
|
|
296
|
+
return { platform: 'web' };
|
|
297
|
+
}
|
|
298
|
+
/** Session-cached identity; never throws (falls back to `{ platform: 'web' }`). */
|
|
299
|
+
async resolveAppIdentity() {
|
|
300
|
+
if (this.appIdentity) {
|
|
301
|
+
return this.appIdentity;
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
this.appIdentity = await this.getAppIdentity();
|
|
305
|
+
}
|
|
306
|
+
catch (_a) {
|
|
307
|
+
this.appIdentity = { platform: 'web' };
|
|
308
|
+
}
|
|
309
|
+
return this.appIdentity;
|
|
310
|
+
}
|
|
289
311
|
/**
|
|
290
312
|
* Check for available updates (convenience wrapper around getLatest + current version)
|
|
291
313
|
*/
|
|
@@ -323,6 +345,7 @@ class NativeUpdatePluginWeb {
|
|
|
323
345
|
deviceId: deviceInfo.deviceId,
|
|
324
346
|
platform: deviceInfo.platform,
|
|
325
347
|
appVersion: deviceInfo.appVersion,
|
|
348
|
+
identity: await this.resolveAppIdentity(),
|
|
326
349
|
});
|
|
327
350
|
if (!data.available) {
|
|
328
351
|
return {
|
|
@@ -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 {};
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { NativeUpdateCombinedPlugin, SecurityInfo, SyncOptions, SyncResult, DownloadOptions, BundleInfo, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, CheckForUpdateResult, DownloadUpdateOptions } from './definitions';
|
|
2
|
+
import type { NativeUpdateCombinedPlugin, SecurityInfo, SyncOptions, SyncResult, DownloadOptions, BundleInfo, DeleteOptions, LatestVersion, ValidateOptions, ValidationResult, AppUpdateInfo, OpenAppStoreOptions, ReviewResult, CanRequestReviewResult, BackgroundUpdateConfig, BackgroundUpdateStatus, BackgroundCheckResult, NotificationPreferences, NotificationPermissionStatus, CheckForUpdateResult, DownloadUpdateOptions, AppIdentity } from './definitions';
|
|
3
3
|
import type { PluginInitConfig } from './definitions';
|
|
4
4
|
export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCombinedPlugin {
|
|
5
5
|
private config;
|
|
@@ -33,6 +33,7 @@ export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCo
|
|
|
33
33
|
delete(options: DeleteOptions): Promise<void>;
|
|
34
34
|
notifyAppReady(): Promise<void>;
|
|
35
35
|
getLatest(): Promise<LatestVersion>;
|
|
36
|
+
getAppIdentity(): Promise<AppIdentity>;
|
|
36
37
|
setChannel(channel: string): Promise<void>;
|
|
37
38
|
/**
|
|
38
39
|
* @deprecated since v2. See NativeUpdatePluginWeb.setUpdateUrl in plugin.ts.
|
package/dist/esm/web.js
CHANGED
|
@@ -265,6 +265,11 @@ export class NativeUpdateWeb extends WebPlugin {
|
|
|
265
265
|
available: false,
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
|
+
async getAppIdentity() {
|
|
269
|
+
// Web clients identify to the update backend via the browser-enforced
|
|
270
|
+
// Origin header, so no identity fields are needed here.
|
|
271
|
+
return { platform: 'web' };
|
|
272
|
+
}
|
|
268
273
|
async setChannel(channel) {
|
|
269
274
|
if (!this.config.liveUpdate) {
|
|
270
275
|
this.config.liveUpdate = {};
|