native-update-react-native 0.0.0-stage → 1.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 +25 -0
- package/README.md +82 -2
- package/android/build.gradle +40 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/Errors.kt +20 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/NativeUpdate.kt +309 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/NativeUpdateConfig.kt +92 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/PlayAppUpdate.kt +153 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/PlayReview.kt +68 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/UpdateTypes.kt +50 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/internal/AppInfo.kt +56 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/internal/BundleStore.kt +210 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/internal/BundleVerifier.kt +66 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/internal/UpdateClient.kt +179 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/internal/Versions.kt +34 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/android/internal/ZipExtractor.kt +55 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/reactnative/NativeUpdateModule.kt +155 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/reactnative/NativeUpdatePackage.kt +30 -0
- package/android/src/main/java/com/aoneahsan/nativeupdate/reactnative/NativeUpdateReactNative.kt +41 -0
- package/lib/NativeNativeUpdate.d.ts +16 -0
- package/lib/NativeNativeUpdate.js +4 -0
- package/lib/index.d.ts +72 -0
- package/lib/index.js +76 -0
- package/package.json +56 -4
- package/react-native.config.js +11 -0
- package/src/NativeNativeUpdate.ts +18 -0
- package/src/index.ts +111 -0
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-update-react-native",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Signed over-the-air JavaScript bundle updates, Play in-app update and in-app review for React Native apps, on Native Update.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"react-native": "src/index.ts",
|
|
8
|
+
"source": "src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"lib",
|
|
12
|
+
"android/build.gradle",
|
|
13
|
+
"android/src/main",
|
|
14
|
+
"react-native.config.js",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.build.json",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
21
|
+
"prepack": "yarn build"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"react-native",
|
|
25
|
+
"ota",
|
|
26
|
+
"over-the-air",
|
|
27
|
+
"code-push",
|
|
28
|
+
"in-app-update",
|
|
29
|
+
"in-app-review"
|
|
30
|
+
],
|
|
31
|
+
"homepage": "https://nativeupdate.aoneahsan.com",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://nativeupdate.aoneahsan.com/support"
|
|
34
|
+
},
|
|
35
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
36
|
+
"author": "Ahsan Mahmood <aoneahsan@gmail.com>",
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": ">=19",
|
|
39
|
+
"react-native": ">=0.80"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/react": "^19.1.1",
|
|
43
|
+
"react": "19.3.0",
|
|
44
|
+
"react-native": "0.88.1",
|
|
45
|
+
"typescript": "^6.0.0"
|
|
46
|
+
},
|
|
47
|
+
"codegenConfig": {
|
|
48
|
+
"name": "NativeUpdateSpec",
|
|
49
|
+
"type": "modules",
|
|
50
|
+
"jsSrcsDir": "src",
|
|
51
|
+
"android": {
|
|
52
|
+
"javaPackageName": "com.aoneahsan.nativeupdate.reactnative"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=24"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** Codegen spec for the native module. App code uses the wrappers in `index.ts`. */
|
|
5
|
+
export interface Spec extends TurboModule {
|
|
6
|
+
checkForUpdate(): Promise<Object>;
|
|
7
|
+
download(info: Object, activation: string): Promise<string>;
|
|
8
|
+
notifyAppReady(): Promise<void>;
|
|
9
|
+
currentVersion(): Promise<string>;
|
|
10
|
+
lastDroppedReason(): Promise<string | null>;
|
|
11
|
+
restart(): void;
|
|
12
|
+
isPlayInstall(): Promise<boolean>;
|
|
13
|
+
startPlayImmediateUpdate(): Promise<string>;
|
|
14
|
+
resumePlayUpdate(): Promise<boolean>;
|
|
15
|
+
requestPlayReview(): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('NativeUpdate');
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signed over-the-air JavaScript bundle updates, Google Play in-app update and in-app review for React Native,
|
|
3
|
+
* on the Native Update service.
|
|
4
|
+
*
|
|
5
|
+
* The SDK starts natively, in `MainApplication.onCreate`, before React loads (see the README), so a bundle that
|
|
6
|
+
* breaks the app can still be rolled back. JavaScript only checks, downloads and confirms.
|
|
7
|
+
*/
|
|
8
|
+
import NativeModule from './NativeNativeUpdate';
|
|
9
|
+
|
|
10
|
+
/** One available bundle, as the server described it. */
|
|
11
|
+
export interface UpdateInfo {
|
|
12
|
+
version: string;
|
|
13
|
+
bundleId: string;
|
|
14
|
+
downloadUrl: string;
|
|
15
|
+
checksum: string;
|
|
16
|
+
signature?: string | null;
|
|
17
|
+
signatureAlgorithm?: string | null;
|
|
18
|
+
payloadType: string;
|
|
19
|
+
size: number;
|
|
20
|
+
mandatory: boolean;
|
|
21
|
+
releaseNotes?: string | null;
|
|
22
|
+
minNativeVersion?: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The answer to {@link checkForUpdate}. */
|
|
26
|
+
export type UpdateCheckResult =
|
|
27
|
+
| { type: 'upToDate'; message?: string | null; code?: string | null }
|
|
28
|
+
| { type: 'available'; info: UpdateInfo }
|
|
29
|
+
| { type: 'nativeUpdateRequired'; minNativeVersion: string }
|
|
30
|
+
| { type: 'held'; version?: string | null; message?: string | null };
|
|
31
|
+
|
|
32
|
+
/** When a downloaded bundle runs: at the next cold start (default), or after {@link restart}. */
|
|
33
|
+
export type Activation = 'nextStart' | 'now';
|
|
34
|
+
|
|
35
|
+
export type PlayUpdateOutcome = 'STARTED' | 'NOT_AVAILABLE' | 'NOT_ALLOWED' | 'NOT_PLAY_INSTALL' | 'FAILED';
|
|
36
|
+
export type PlayReviewOutcome = 'REQUESTED' | 'NOT_PLAY_INSTALL' | 'FAILED';
|
|
37
|
+
|
|
38
|
+
/** A failure from the native side carries one of the protocol's error codes in `code`. */
|
|
39
|
+
export interface NativeUpdateError extends Error {
|
|
40
|
+
code: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Asks the server whether a newer JavaScript bundle exists for this device. */
|
|
44
|
+
export function checkForUpdate(): Promise<UpdateCheckResult> {
|
|
45
|
+
return NativeModule.checkForUpdate() as Promise<UpdateCheckResult>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Downloads, verifies (SHA-256 + RSA-SHA256) and unpacks a bundle; returns the version that will run. With
|
|
50
|
+
* `activation: 'now'` it runs after {@link restart}; otherwise at the next cold start.
|
|
51
|
+
*/
|
|
52
|
+
export function download(info: UpdateInfo, activation: Activation = 'nextStart'): Promise<string> {
|
|
53
|
+
return NativeModule.download(info, activation);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Call once the app has rendered and works, on every start. A new bundle that never gets here within two cold
|
|
58
|
+
* starts is rolled back and never offered to this device again.
|
|
59
|
+
*/
|
|
60
|
+
export function notifyAppReady(): Promise<void> {
|
|
61
|
+
return NativeModule.notifyAppReady();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Version of the JavaScript running now: the active bundle's, or the one built into the app. */
|
|
65
|
+
export function currentVersion(): Promise<string> {
|
|
66
|
+
return NativeModule.currentVersion();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Why the last cold start set a bundle aside (rollback, failed check, new binary), or null. */
|
|
70
|
+
export function lastDroppedReason(): Promise<string | null> {
|
|
71
|
+
return NativeModule.lastDroppedReason();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Relaunches the app so a downloaded bundle runs now. Only call it when the person expects a restart. */
|
|
75
|
+
export function restart(): void {
|
|
76
|
+
NativeModule.restart();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** True when Google Play installed the running build. */
|
|
80
|
+
export function isPlayInstall(): Promise<boolean> {
|
|
81
|
+
return NativeModule.isPlayInstall();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Play's immediate in-app update. A sideloaded build answers `NOT_PLAY_INSTALL`. */
|
|
85
|
+
export function startPlayImmediateUpdate(): Promise<PlayUpdateOutcome> {
|
|
86
|
+
return NativeModule.startPlayImmediateUpdate() as Promise<PlayUpdateOutcome>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Brings back an immediate update the person left; call it when the app returns to the foreground. */
|
|
90
|
+
export function resumePlayUpdate(): Promise<boolean> {
|
|
91
|
+
return NativeModule.resumePlayUpdate();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Play's in-app review sheet. Play never says whether it showed; pair it with {@link shouldAskForReview}. */
|
|
95
|
+
export function requestPlayReview(): Promise<PlayReviewOutcome> {
|
|
96
|
+
return NativeModule.requestPlayReview() as Promise<PlayReviewOutcome>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const DAY_MS = 86_400_000;
|
|
100
|
+
|
|
101
|
+
/** True after at least `minSuccesses` good moments, and never twice within `minDaysBetween` days. */
|
|
102
|
+
export function shouldAskForReview(options: {
|
|
103
|
+
successes: number;
|
|
104
|
+
lastAskedMs: number | null;
|
|
105
|
+
nowMs: number;
|
|
106
|
+
minSuccesses?: number;
|
|
107
|
+
minDaysBetween?: number;
|
|
108
|
+
}): boolean {
|
|
109
|
+
const { successes, lastAskedMs, nowMs, minSuccesses = 3, minDaysBetween = 90 } = options;
|
|
110
|
+
return successes >= minSuccesses && (lastAskedMs === null || nowMs - lastAskedMs >= minDaysBetween * DAY_MS);
|
|
111
|
+
}
|