@aramiworks/app-updates 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +118 -2
- package/android/build.gradle +27 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/so/arami/appupdates/AppUpdatesModule.kt +123 -0
- package/app.plugin.js +1 -0
- package/build/cache.d.ts +12 -0
- package/build/cache.js +104 -0
- package/build/env.d.ts +3 -0
- package/build/env.js +53 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +13 -0
- package/build/native.d.ts +56 -0
- package/build/native.js +159 -0
- package/build/openStore.d.ts +20 -0
- package/build/openStore.js +49 -0
- package/build/ota.d.ts +33 -0
- package/build/ota.js +102 -0
- package/build/sources/appStore.d.ts +15 -0
- package/build/sources/appStore.js +26 -0
- package/build/storeCheck.d.ts +40 -0
- package/build/storeCheck.js +112 -0
- package/build/tester.d.ts +22 -0
- package/build/tester.js +78 -0
- package/build/throttle.d.ts +3 -0
- package/build/throttle.js +11 -0
- package/build/types.d.ts +7 -0
- package/build/types.js +2 -0
- package/build/useAppUpdate.d.ts +3 -0
- package/build/useAppUpdate.js +7 -0
- package/build/useAppUpdateCore.d.ts +43 -0
- package/build/useAppUpdateCore.js +209 -0
- package/build/version.d.ts +13 -0
- package/build/version.js +32 -0
- package/expo-module.config.json +6 -0
- package/package.json +61 -4
- package/plugin/build/gradle.d.ts +16 -0
- package/plugin/build/gradle.js +172 -0
- package/plugin/build/index.d.ts +16 -0
- package/plugin/build/index.js +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arami
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @aramiworks/app-updates
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Update checks and OTA flow for Expo apps: store version lookups, a verified-decision cache, and a
|
|
4
|
+
`useAppUpdate()` hook. Includes an Android native module and an Expo config plugin.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npx expo install @aramiworks/app-updates
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Requires Expo's Metro config (`allowOptionalDependencies`).
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
Install the peers:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npx expo install expo-updates expo-application expo-localization expo-secure-store
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Firebase tester builds are optional:
|
|
21
|
+
|
|
22
|
+
- iOS develop: `@react-native-firebase/app` and `@react-native-firebase/app-distribution`, plus
|
|
23
|
+
`GoogleService-Info.plist`. Without them there is no tester prompt and the check resolves "unknown".
|
|
24
|
+
- Android: the config plugin's `firebase` flavor needs `google-services.json`.
|
|
25
|
+
|
|
26
|
+
## Wiring
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
// app/_layout.tsx
|
|
30
|
+
import { useAppUpdate } from '@aramiworks/app-updates';
|
|
31
|
+
import { NoticeTemplate, SnackbarProvider, useSnackbar } from '@aramiworks/design-app';
|
|
32
|
+
import { Slot } from 'expo-router';
|
|
33
|
+
import { useEffect } from 'react';
|
|
34
|
+
|
|
35
|
+
export default function RootLayout() {
|
|
36
|
+
// useSnackbar() needs a SnackbarProvider above it, so the gate lives in a child.
|
|
37
|
+
return (
|
|
38
|
+
<SnackbarProvider>
|
|
39
|
+
<UpdateGate />
|
|
40
|
+
</SnackbarProvider>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function UpdateGate() {
|
|
45
|
+
const u = useAppUpdate({ enabled: !__DEV__ });
|
|
46
|
+
const snackbar = useSnackbar();
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (u.otaReady) {
|
|
50
|
+
snackbar.show({
|
|
51
|
+
message: 'Update ready',
|
|
52
|
+
duration: null,
|
|
53
|
+
action: { label: 'Restart', onPress: () => void u.restart() },
|
|
54
|
+
onDismiss: u.dismissOta,
|
|
55
|
+
});
|
|
56
|
+
} else if (u.tester.promptVisible) {
|
|
57
|
+
snackbar.show({
|
|
58
|
+
message: 'Sign in to get new test builds',
|
|
59
|
+
duration: null,
|
|
60
|
+
action: { label: 'Sign in', onPress: () => void u.tester.signIn() },
|
|
61
|
+
onDismiss: u.tester.dismissPrompt,
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
snackbar.hide();
|
|
65
|
+
}
|
|
66
|
+
}, [u.otaReady, u.tester.promptVisible]);
|
|
67
|
+
|
|
68
|
+
if (u.storeUpdate) {
|
|
69
|
+
return (
|
|
70
|
+
<NoticeTemplate
|
|
71
|
+
icon="cloud-download-outline"
|
|
72
|
+
title="Update required"
|
|
73
|
+
description="Please update to keep using the app."
|
|
74
|
+
primaryAction={{ label: 'Update', onPress: () => void u.openStore() }}
|
|
75
|
+
footnote={`Installed ${u.storeUpdate.installed} · New ${u.storeUpdate.available}`}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (u.coldStartUpdating) {
|
|
80
|
+
return <NoticeTemplate title="Updating…" loading loadingLabel="Updating" />;
|
|
81
|
+
}
|
|
82
|
+
return <Slot />;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Priority: `storeUpdate` (blocking) > `coldStartUpdating` > snackbars (`otaReady`, then
|
|
87
|
+
`tester.promptVisible`).
|
|
88
|
+
|
|
89
|
+
## Versioning and store checks
|
|
90
|
+
|
|
91
|
+
- The native version must be `major.minor.0`; only major.minor is compared.
|
|
92
|
+
- Android `versionCode` is `major × 1,000,000 + minor × 1,000 + build`. Play checks decode the
|
|
93
|
+
available code with this scheme, so it must hold for every Play build.
|
|
94
|
+
- The App Store lookup uses the device region. An app with no listing there is not gated.
|
|
95
|
+
- A null update channel (dev client) with no store listing is not gated.
|
|
96
|
+
- A check that can't answer (network error, timeout, signed-out tester) keeps the current state.
|
|
97
|
+
Only a definitive "nothing newer" lifts a cached gate.
|
|
98
|
+
|
|
99
|
+
## Config plugin
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
["@aramiworks/app-updates", { "firebaseVersion": "16.0.0-beta21" }]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`firebaseVersion` is optional. On Android the plugin changes `android/app/build.gradle`:
|
|
106
|
+
|
|
107
|
+
- adds product flavors `play` and `firebase` in the `distribution` dimension, each writing the
|
|
108
|
+
`app_updates_distribution` string resource
|
|
109
|
+
- adds the full Firebase App Distribution SDK to the `firebase` flavor only (`firebaseImplementation`)
|
|
110
|
+
- sets `react { debuggableVariants = ["playDebug", "firebaseDebug"] }` so debug builds still load JS
|
|
111
|
+
from Metro
|
|
112
|
+
|
|
113
|
+
Build tasks are renamed by the flavors, so set `android.gradleCommand` per profile in `eas.json`:
|
|
114
|
+
|
|
115
|
+
- store `.aab`: `:app:bundlePlayRelease`
|
|
116
|
+
- Firebase tester APK (develop and master-apk): `:app:assembleFirebaseRelease`
|
|
117
|
+
|
|
118
|
+
iOS needs nothing from the plugin. iOS develop builds detect Firebase releases only if the app
|
|
119
|
+
installs `@react-native-firebase/app-distribution`.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
plugins {
|
|
2
|
+
id 'com.android.library'
|
|
3
|
+
id 'expo-module-gradle-plugin'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
group = 'so.arami.appupdates'
|
|
7
|
+
version = '0.0.0'
|
|
8
|
+
|
|
9
|
+
android {
|
|
10
|
+
namespace "so.arami.appupdates"
|
|
11
|
+
defaultConfig {
|
|
12
|
+
versionCode 1
|
|
13
|
+
versionName "0.0.0"
|
|
14
|
+
}
|
|
15
|
+
lintOptions {
|
|
16
|
+
abortOnError false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
dependencies {
|
|
21
|
+
implementation 'com.google.android.play:app-update:2.1.0'
|
|
22
|
+
// API-only artifact. Without the full firebase-appdistribution SDK (the config
|
|
23
|
+
// plugin adds it for the firebase flavor only) isTesterSignedIn is false and the
|
|
24
|
+
// other calls REJECT ("API not implemented"). Callers must use the Firebase
|
|
25
|
+
// calls only on the firebase distribution.
|
|
26
|
+
implementation 'com.google.firebase:firebase-appdistribution-api:16.0.0-beta21'
|
|
27
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
package so.arami.appupdates
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.google.android.gms.tasks.Task
|
|
5
|
+
import com.google.android.play.core.appupdate.AppUpdateInfo
|
|
6
|
+
import com.google.android.play.core.appupdate.AppUpdateManager
|
|
7
|
+
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
|
|
8
|
+
import com.google.android.play.core.appupdate.AppUpdateOptions
|
|
9
|
+
import com.google.android.play.core.install.model.AppUpdateType
|
|
10
|
+
import com.google.android.play.core.install.model.UpdateAvailability
|
|
11
|
+
import com.google.firebase.appdistribution.FirebaseAppDistribution
|
|
12
|
+
import expo.modules.kotlin.Promise
|
|
13
|
+
import expo.modules.kotlin.exception.Exceptions
|
|
14
|
+
import expo.modules.kotlin.modules.Module
|
|
15
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
16
|
+
|
|
17
|
+
private const val DISTRIBUTION_RESOURCE = "app_updates_distribution"
|
|
18
|
+
private const val DEFAULT_DISTRIBUTION = "play"
|
|
19
|
+
private const val PLAY_UPDATE_REQUEST_CODE = 0x4155
|
|
20
|
+
|
|
21
|
+
class AppUpdatesModule : Module() {
|
|
22
|
+
private val context: Context
|
|
23
|
+
get() = appContext.reactContext ?: throw Exceptions.ReactContextLost()
|
|
24
|
+
|
|
25
|
+
private val appUpdateManager: AppUpdateManager by lazy {
|
|
26
|
+
AppUpdateManagerFactory.create(context)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override fun definition() = ModuleDefinition {
|
|
30
|
+
Name("AppUpdates")
|
|
31
|
+
|
|
32
|
+
// "play" | "firebase", written per Gradle flavor by the config plugin.
|
|
33
|
+
Function("getDistribution") {
|
|
34
|
+
val ctx = context
|
|
35
|
+
val id = ctx.resources.getIdentifier(DISTRIBUTION_RESOURCE, "string", ctx.packageName)
|
|
36
|
+
if (id == 0) DEFAULT_DISTRIBUTION else ctx.getString(id)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
AsyncFunction("getPlayUpdateInfo") { promise: Promise ->
|
|
40
|
+
appUpdateManager.appUpdateInfo.settle(promise, "ERR_PLAY_UPDATE_INFO") { info ->
|
|
41
|
+
mapOf(
|
|
42
|
+
"updateAvailable" to isUpdateAvailable(info),
|
|
43
|
+
"availableVersionCode" to info.availableVersionCode(),
|
|
44
|
+
"immediateAllowed" to info.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Resolves false (never rejects) when the flow can't start.
|
|
50
|
+
AsyncFunction("startPlayImmediateUpdate") { promise: Promise ->
|
|
51
|
+
appUpdateManager.appUpdateInfo
|
|
52
|
+
.addOnSuccessListener { info ->
|
|
53
|
+
val activity = appContext.currentActivity
|
|
54
|
+
if (activity == null ||
|
|
55
|
+
!isUpdateAvailable(info) ||
|
|
56
|
+
!info.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
|
|
57
|
+
) {
|
|
58
|
+
promise.resolve(false)
|
|
59
|
+
return@addOnSuccessListener
|
|
60
|
+
}
|
|
61
|
+
val started = try {
|
|
62
|
+
appUpdateManager.startUpdateFlowForResult(
|
|
63
|
+
info,
|
|
64
|
+
activity,
|
|
65
|
+
AppUpdateOptions.defaultOptions(AppUpdateType.IMMEDIATE),
|
|
66
|
+
PLAY_UPDATE_REQUEST_CODE
|
|
67
|
+
)
|
|
68
|
+
} catch (e: Exception) {
|
|
69
|
+
false
|
|
70
|
+
}
|
|
71
|
+
promise.resolve(started)
|
|
72
|
+
}
|
|
73
|
+
.addOnFailureListener { promise.resolve(false) }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
AsyncFunction("isTesterSignedIn") { promise: Promise ->
|
|
77
|
+
val distribution = firebaseOrReject(promise) ?: return@AsyncFunction
|
|
78
|
+
promise.resolve(distribution.isTesterSignedIn)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
AsyncFunction("signInTester") { promise: Promise ->
|
|
82
|
+
val distribution = firebaseOrReject(promise) ?: return@AsyncFunction
|
|
83
|
+
distribution.signInTester().settle(promise, "ERR_FIREBASE_SIGN_IN") { null }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Callers must check isTesterSignedIn first: checkForNewRelease opens the
|
|
87
|
+
// sign-in flow on its own when no tester is signed in.
|
|
88
|
+
AsyncFunction("checkFirebaseRelease") { promise: Promise ->
|
|
89
|
+
val distribution = firebaseOrReject(promise) ?: return@AsyncFunction
|
|
90
|
+
distribution.checkForNewRelease().settle(promise, "ERR_FIREBASE_CHECK") { release ->
|
|
91
|
+
release?.let { mapOf("displayVersion" to it.displayVersion) }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
AsyncFunction("installFirebaseRelease") { promise: Promise ->
|
|
96
|
+
val distribution = firebaseOrReject(promise) ?: return@AsyncFunction
|
|
97
|
+
distribution.updateApp().settle(promise, "ERR_FIREBASE_INSTALL") { null }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS is an interrupted immediate update;
|
|
102
|
+
// Play's guidance is to resume it, so it counts as available.
|
|
103
|
+
private fun isUpdateAvailable(info: AppUpdateInfo): Boolean =
|
|
104
|
+
when (info.updateAvailability()) {
|
|
105
|
+
UpdateAvailability.UPDATE_AVAILABLE,
|
|
106
|
+
UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS -> true
|
|
107
|
+
else -> false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// getInstance throws when FirebaseApp isn't initialized (no google-services.json).
|
|
111
|
+
private fun firebaseOrReject(promise: Promise): FirebaseAppDistribution? =
|
|
112
|
+
try {
|
|
113
|
+
FirebaseAppDistribution.getInstance()
|
|
114
|
+
} catch (e: Exception) {
|
|
115
|
+
promise.reject("ERR_FIREBASE_UNAVAILABLE", "Firebase App Distribution is unavailable", e)
|
|
116
|
+
null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private fun <T> Task<T>.settle(promise: Promise, code: String, map: (T) -> Any?) {
|
|
120
|
+
addOnSuccessListener { result -> promise.resolve(map(result)) }
|
|
121
|
+
addOnFailureListener { e -> promise.reject(code, e.message, e) }
|
|
122
|
+
}
|
|
123
|
+
}
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./plugin/build').default;
|
package/build/cache.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StoreUpdate } from './types';
|
|
2
|
+
/** How long a cached verified store update keeps gating the app (7 days). */
|
|
3
|
+
export declare const VERIFIED_TTL_MS: number;
|
|
4
|
+
export interface KeyValueStore {
|
|
5
|
+
getItem(k: string): Promise<string | null>;
|
|
6
|
+
setItem(k: string, v: string): Promise<void>;
|
|
7
|
+
deleteItem(k: string): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const secureStore: KeyValueStore;
|
|
10
|
+
export declare function readVerified(store: KeyValueStore, installed: string, now: number): Promise<StoreUpdate | null>;
|
|
11
|
+
export declare function writeVerified(store: KeyValueStore, update: StoreUpdate, now: number): Promise<void>;
|
|
12
|
+
export declare function clearVerified(store: KeyValueStore): Promise<void>;
|
package/build/cache.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.secureStore = exports.VERIFIED_TTL_MS = void 0;
|
|
37
|
+
exports.readVerified = readVerified;
|
|
38
|
+
exports.writeVerified = writeVerified;
|
|
39
|
+
exports.clearVerified = clearVerified;
|
|
40
|
+
const SecureStore = __importStar(require("expo-secure-store"));
|
|
41
|
+
const version_1 = require("./version");
|
|
42
|
+
/** How long a cached verified store update keeps gating the app (7 days). */
|
|
43
|
+
exports.VERIFIED_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
44
|
+
const KEY = 'aramiworks.app-updates.verified';
|
|
45
|
+
exports.secureStore = {
|
|
46
|
+
getItem: (k) => SecureStore.getItemAsync(k),
|
|
47
|
+
setItem: (k, v) => SecureStore.setItemAsync(k, v),
|
|
48
|
+
deleteItem: (k) => SecureStore.deleteItemAsync(k),
|
|
49
|
+
};
|
|
50
|
+
function isStored(value) {
|
|
51
|
+
if (typeof value !== 'object' || value === null)
|
|
52
|
+
return false;
|
|
53
|
+
const { update, verifiedAt } = value;
|
|
54
|
+
if (typeof verifiedAt !== 'number' || !Number.isFinite(verifiedAt))
|
|
55
|
+
return false;
|
|
56
|
+
if (typeof update !== 'object' || update === null)
|
|
57
|
+
return false;
|
|
58
|
+
const u = update;
|
|
59
|
+
return (typeof u.installed === 'string' &&
|
|
60
|
+
typeof u.available === 'string' &&
|
|
61
|
+
(u.source === 'app-store' || u.source === 'play' || u.source === 'firebase') &&
|
|
62
|
+
(typeof u.url === 'string' || u.url === null));
|
|
63
|
+
}
|
|
64
|
+
async function readVerified(store, installed, now) {
|
|
65
|
+
try {
|
|
66
|
+
const raw = await store.getItem(KEY);
|
|
67
|
+
if (raw === null)
|
|
68
|
+
return null;
|
|
69
|
+
const parsed = JSON.parse(raw);
|
|
70
|
+
if (!isStored(parsed))
|
|
71
|
+
return null;
|
|
72
|
+
const age = now - parsed.verifiedAt;
|
|
73
|
+
if (age < 0 || age >= exports.VERIFIED_TTL_MS)
|
|
74
|
+
return null;
|
|
75
|
+
const installedV = (0, version_1.parseMajorMinor)(installed);
|
|
76
|
+
const availableV = (0, version_1.parseMajorMinor)(parsed.update.available);
|
|
77
|
+
if (!installedV || !availableV)
|
|
78
|
+
return null;
|
|
79
|
+
if (!(0, version_1.isNewerMajorMinor)(installedV, availableV)) {
|
|
80
|
+
await clearVerified(store);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return { ...parsed.update, installed };
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function writeVerified(store, update, now) {
|
|
90
|
+
try {
|
|
91
|
+
await store.setItem(KEY, JSON.stringify({ update, verifiedAt: now }));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// fail open: a missed cache write must never break the caller
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function clearVerified(store) {
|
|
98
|
+
try {
|
|
99
|
+
await store.deleteItem(KEY);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// fail open
|
|
103
|
+
}
|
|
104
|
+
}
|
package/build/env.d.ts
ADDED
package/build/env.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getEnv = getEnv;
|
|
37
|
+
const Application = __importStar(require("expo-application"));
|
|
38
|
+
const expo_localization_1 = require("expo-localization");
|
|
39
|
+
const Updates = __importStar(require("expo-updates"));
|
|
40
|
+
const react_native_1 = require("react-native");
|
|
41
|
+
const native_1 = require("./native");
|
|
42
|
+
/** Reads the runtime environment the store check needs. Called once per hook mount. */
|
|
43
|
+
function getEnv() {
|
|
44
|
+
const os = react_native_1.Platform.OS;
|
|
45
|
+
return {
|
|
46
|
+
platform: os === 'ios' || os === 'android' ? os : 'web',
|
|
47
|
+
channel: Updates.channel ?? null,
|
|
48
|
+
installed: Application.nativeApplicationVersion ?? null,
|
|
49
|
+
bundleId: Application.applicationId ?? null,
|
|
50
|
+
country: (0, expo_localization_1.getLocales)()[0]?.regionCode ?? null,
|
|
51
|
+
distribution: (0, native_1.getDistribution)(),
|
|
52
|
+
};
|
|
53
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useAppUpdate } from './useAppUpdate';
|
|
2
|
+
export type { AppUpdateState, UseAppUpdateOptions } from './useAppUpdate';
|
|
3
|
+
export type { Distribution, StoreUpdate } from './types';
|
|
4
|
+
export type { TesterState } from './tester';
|
|
5
|
+
export { CHECK_INTERVAL_MS } from './throttle';
|
|
6
|
+
export { COLD_START_OTA_LIMIT_MS } from './ota';
|
|
7
|
+
export { STORE_CHECK_TIMEOUT_MS } from './storeCheck';
|
|
8
|
+
export { VERIFIED_TTL_MS } from './cache';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERIFIED_TTL_MS = exports.STORE_CHECK_TIMEOUT_MS = exports.COLD_START_OTA_LIMIT_MS = exports.CHECK_INTERVAL_MS = exports.useAppUpdate = void 0;
|
|
4
|
+
var useAppUpdate_1 = require("./useAppUpdate");
|
|
5
|
+
Object.defineProperty(exports, "useAppUpdate", { enumerable: true, get: function () { return useAppUpdate_1.useAppUpdate; } });
|
|
6
|
+
var throttle_1 = require("./throttle");
|
|
7
|
+
Object.defineProperty(exports, "CHECK_INTERVAL_MS", { enumerable: true, get: function () { return throttle_1.CHECK_INTERVAL_MS; } });
|
|
8
|
+
var ota_1 = require("./ota");
|
|
9
|
+
Object.defineProperty(exports, "COLD_START_OTA_LIMIT_MS", { enumerable: true, get: function () { return ota_1.COLD_START_OTA_LIMIT_MS; } });
|
|
10
|
+
var storeCheck_1 = require("./storeCheck");
|
|
11
|
+
Object.defineProperty(exports, "STORE_CHECK_TIMEOUT_MS", { enumerable: true, get: function () { return storeCheck_1.STORE_CHECK_TIMEOUT_MS; } });
|
|
12
|
+
var cache_1 = require("./cache");
|
|
13
|
+
Object.defineProperty(exports, "VERIFIED_TTL_MS", { enumerable: true, get: function () { return cache_1.VERIFIED_TTL_MS; } });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Which Android channel this build was distributed through ("none" off Android). */
|
|
2
|
+
export type NativeDistribution = 'play' | 'firebase' | 'none';
|
|
3
|
+
export interface PlayUpdateInfo {
|
|
4
|
+
updateAvailable: boolean;
|
|
5
|
+
availableVersionCode: number;
|
|
6
|
+
immediateAllowed: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface FirebaseRelease {
|
|
9
|
+
displayVersion: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether Firebase App Distribution can work in this build: the Android native
|
|
13
|
+
* module is linked, or on iOS the app installed `@react-native-firebase/app-distribution`.
|
|
14
|
+
* False on web and in Expo Go.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isFirebaseAvailable(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The distribution channel from the `app_updates_distribution` string resource
|
|
19
|
+
* the config plugin writes per Gradle flavor. Defaults to "play" on Android
|
|
20
|
+
* (resource absent or unknown) and is "none" on iOS and web.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getDistribution(): NativeDistribution;
|
|
23
|
+
/** Google Play in-app update availability. Nothing available off Android. */
|
|
24
|
+
export declare function getPlayUpdateInfo(): Promise<PlayUpdateInfo>;
|
|
25
|
+
/**
|
|
26
|
+
* Starts Play's immediate (full-screen) update flow from the current activity.
|
|
27
|
+
* Resolves false when it couldn't start (no activity, no update, or immediate
|
|
28
|
+
* updates not allowed).
|
|
29
|
+
*/
|
|
30
|
+
export declare function startPlayImmediateUpdate(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Firebase calls are meaningful only on the `firebase` distribution. In the
|
|
33
|
+
* `play` flavor the Android API-only artifact reports `isTesterSignedIn` false
|
|
34
|
+
* and the other calls reject ("API not implemented"), so callers must use
|
|
35
|
+
* them only when `getDistribution()` is `firebase` (or on iOS). On iOS they use
|
|
36
|
+
* the app's optional `@react-native-firebase/app-distribution` install and
|
|
37
|
+
* return "nothing" values when it is absent. Errors propagate.
|
|
38
|
+
*/
|
|
39
|
+
/** Whether a Firebase App Distribution tester is signed in on this device. */
|
|
40
|
+
export declare function isTesterSignedIn(): Promise<boolean>;
|
|
41
|
+
/** Opens the Firebase App Distribution tester sign-in flow. */
|
|
42
|
+
export declare function signInTester(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* The newest Firebase App Distribution release, or null when this build is the newest.
|
|
45
|
+
* Only meaningful on the `firebase` distribution (see above).
|
|
46
|
+
*
|
|
47
|
+
* Call this only after `isTesterSignedIn()` resolves true: when no tester is
|
|
48
|
+
* signed in, the native `checkForNewRelease` opens the sign-in flow on its own.
|
|
49
|
+
* This wrapper does not guard against that; callers must.
|
|
50
|
+
*/
|
|
51
|
+
export declare function checkFirebaseRelease(): Promise<FirebaseRelease | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Installs the newest Firebase App Distribution release: downloads it on Android,
|
|
54
|
+
* opens its download URL on iOS. Only meaningful on the `firebase` distribution.
|
|
55
|
+
*/
|
|
56
|
+
export declare function installFirebaseRelease(): Promise<void>;
|