@aramiworks/app-updates 0.0.0-stage → 0.1.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 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
- # Temporary Holding Version
1
+ # @aramiworks/app-updates
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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,2 @@
1
+ <manifest>
2
+ </manifest>
@@ -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;
@@ -0,0 +1,6 @@
1
+ {
2
+ "platforms": ["android"],
3
+ "android": {
4
+ "modules": ["so.arami.appupdates.AppUpdatesModule"]
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@aramiworks/app-updates",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Native app update checks and OTA flow for Expo apps",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "files": [
8
+ "build",
9
+ "plugin/build",
10
+ "app.plugin.js",
11
+ "android",
12
+ "!android/build",
13
+ "expo-module.config.json"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.build.json && tsc -p plugin/tsconfig.build.json",
17
+ "clean": "node -e \"for (const d of ['build','plugin/build']) require('fs').rmSync(d,{recursive:true,force:true})\"",
18
+ "lint": "eslint src/ plugin/src/",
19
+ "test": "jest --passWithNoTests",
20
+ "typecheck": "tsc --noEmit && tsc --noEmit -p plugin/tsconfig.json"
21
+ },
22
+ "keywords": [
23
+ "react-native",
24
+ "expo",
25
+ "app-updates"
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/arami-works/foundation.git",
30
+ "directory": "packages/app-updates"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/arami-works/foundation/issues"
34
+ },
35
+ "author": "Arami <jaemin@arami.so> (https://github.com/arami-works)",
36
+ "license": "MIT",
37
+ "homepage": "https://github.com/arami-works/foundation/tree/main/packages/app-updates#readme",
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "jest": {
42
+ "preset": "jest-expo",
43
+ "roots": [
44
+ "<rootDir>/src",
45
+ "<rootDir>/plugin/src"
46
+ ]
47
+ },
48
+ "peerDependencies": {
49
+ "@react-native-firebase/app-distribution": ">=27",
50
+ "expo": ">=57",
51
+ "expo-application": ">=57",
52
+ "expo-localization": ">=57",
53
+ "expo-secure-store": ">=57",
54
+ "expo-updates": ">=57",
55
+ "react": ">=19",
56
+ "react-native": ">=0.86"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "@react-native-firebase/app-distribution": {
60
+ "optional": true
61
+ }
62
+ }
63
+ }